11import { Slide } from './classes/slide' ;
22import { FileHelper } from './helper/file-helper' ;
3- import { AutomizerParams , AutomizerSummary , SourceSlideIdentifier } from './types/types' ;
3+ import {
4+ AutomizerParams ,
5+ AutomizerSummary ,
6+ SourceSlideIdentifier ,
7+ StatusTracker ,
8+ } from './types/types' ;
49import { IPresentationProps } from './interfaces/ipresentation-props' ;
510import { PresTemplate } from './interfaces/pres-template' ;
611import { RootPresTemplate } from './interfaces/root-pres-template' ;
712import { Template } from './classes/template' ;
813import { TemplateInfo } from './types/xml-types' ;
914import { vd } from './helper/general-helper' ;
10- import { Master } from './classes/master' ;
15+ import { Master } from './classes/master' ;
1116
1217/**
1318 * Automizer
@@ -30,6 +35,7 @@ export default class Automizer implements IPresentationProps {
3035 */
3136 timer : number ;
3237 params : AutomizerParams ;
38+ status : StatusTracker ;
3339
3440 /**
3541 * Creates an instance of `pptx-automizer`.
@@ -43,6 +49,7 @@ export default class Automizer implements IPresentationProps {
4349 this . outputDir = params ?. outputDir ? params . outputDir + '/' : '' ;
4450
4551 this . timer = Date . now ( ) ;
52+ this . setStatusTracker ( params ?. statusTracker ) ;
4653
4754 if ( params . rootTemplate ) {
4855 const location = this . getLocation ( params . rootTemplate , 'template' ) ;
@@ -58,6 +65,32 @@ export default class Automizer implements IPresentationProps {
5865 }
5966 }
6067
68+ setStatusTracker ( statusTracker : StatusTracker [ 'next' ] ) : void {
69+ const defaultStatusTracker = ( status : StatusTracker ) => {
70+ console . log ( status . info + '(' + status . share + '%)' ) ;
71+ } ;
72+
73+ this . status = {
74+ current : 0 ,
75+ max : 0 ,
76+ share : 0 ,
77+ info : undefined ,
78+ increment : ( ) => {
79+ this . status . current ++ ;
80+ const nextShare =
81+ this . status . max > 0
82+ ? Math . round ( ( this . status . current / this . status . max ) * 100 )
83+ : 0 ;
84+
85+ if ( this . status . share !== nextShare ) {
86+ this . status . share = nextShare ;
87+ this . status . next ( this . status ) ;
88+ }
89+ } ,
90+ next : statusTracker || defaultStatusTracker ,
91+ } ;
92+ }
93+
6194 /**
6295
6396 */
@@ -98,9 +131,11 @@ export default class Automizer implements IPresentationProps {
98131 private loadTemplate ( location : string , name ?: string ) : this {
99132 location = this . getLocation ( location , 'template' ) ;
100133
101- const alreadyLoaded = this . templates . find ( template => template . name === name )
102- if ( alreadyLoaded ) {
103- return this
134+ const alreadyLoaded = this . templates . find (
135+ ( template ) => template . name === name ,
136+ ) ;
137+ if ( alreadyLoaded ) {
138+ return this ;
104139 }
105140
106141 const newTemplate = Template . import ( location , name ) ;
@@ -123,7 +158,8 @@ export default class Automizer implements IPresentationProps {
123158 public async setCreationIds ( ) : Promise < TemplateInfo [ ] > {
124159 const templateCreationId = [ ] ;
125160 for ( const template of this . templates ) {
126- const creationIds = template . creationIds || await template . setCreationIds ( )
161+ const creationIds =
162+ template . creationIds || ( await template . setCreationIds ( ) ) ;
127163 templateCreationId . push ( {
128164 name : template . name ,
129165 slides : creationIds ,
@@ -177,12 +213,17 @@ export default class Automizer implements IPresentationProps {
177213 return this ;
178214 }
179215
216+ /**
217+ * WIP: copy and modify a master from template to output
218+ * @param name
219+ * @param masterNumber
220+ * @param callback
221+ */
180222 public addMaster (
181223 name : string ,
182224 masterNumber : number ,
183225 callback ?: ( slide : Slide ) => void ,
184226 ) : this {
185-
186227 const template = this . getTemplate ( name ) ;
187228
188229 const newMaster = new Master ( {
@@ -218,6 +259,7 @@ export default class Automizer implements IPresentationProps {
218259 public async write ( location : string ) : Promise < AutomizerSummary > {
219260 const rootArchive = await this . rootTemplate . archive ;
220261
262+ this . status . max = this . rootTemplate . slides . length ;
221263 for ( const slide of this . rootTemplate . slides ) {
222264 await this . rootTemplate . appendSlide ( slide ) ;
223265 }
0 commit comments