kt-forpro-tools 1.1.1 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kt-forpro-tools",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "",
5
5
  "author": "Miguel de Mendoza",
6
6
  "main": "src/index.ts",
package/src/slides.ts CHANGED
@@ -3,6 +3,8 @@ import { KT_Layers } from "kt-ae-tools-layers";
3
3
  import { KT_AeIs as is } from "kt-ae-is-checkers";
4
4
  import { IO } from "kt-io";
5
5
 
6
+ const BACKGROUND_LABEL = 13;
7
+
6
8
  const colorSelector = () => {
7
9
  let lastColorIndex = -1;
8
10
  const numColors = 16;
@@ -10,6 +12,9 @@ const colorSelector = () => {
10
12
 
11
13
  // ✅ Pre-generar pool de colores disponibles
12
14
  for (let i = 0; i < numColors; i++) {
15
+ if (i === BACKGROUND_LABEL) {
16
+ continue;
17
+ }
13
18
  colorPool.push(i);
14
19
  }
15
20
 
@@ -33,6 +38,7 @@ export type KT_SlidesOptions = {
33
38
  comp?: CompItem;
34
39
  slideMultiplier?: number;
35
40
  slideDistance?: number;
41
+ lazyInit?: boolean;
36
42
  };
37
43
 
38
44
  class KT_Slides {
@@ -43,7 +49,7 @@ class KT_Slides {
43
49
  backgroundComp!: CompItem;
44
50
  compedSlidesFolder!: FolderItem;
45
51
  duration: number = 30;
46
- masterComp: CompItem;
52
+ masterComp!: CompItem;
47
53
  slidesFootage: FootageItem[] = [];
48
54
  width: number = 1920;
49
55
  height: number = 1080;
@@ -55,6 +61,8 @@ class KT_Slides {
55
61
  slideMultiplier: number = 1;
56
62
  backgroundColor: [number, number, number] = [1, 1, 1];
57
63
  backgroundPivotPrefix: string = "_BG_";
64
+ private initialized: boolean = false;
65
+ private initialComp?: CompItem;
58
66
  private getNextColor = colorSelector();
59
67
 
60
68
  constructor(options: KT_SlidesOptions = {}) {
@@ -68,6 +76,7 @@ class KT_Slides {
68
76
  comp,
69
77
  slideMultiplier,
70
78
  slideDistance,
79
+ lazyInit = true,
71
80
  } = options;
72
81
  this.name = name || this.name;
73
82
  this.duration = duration || this.duration;
@@ -77,14 +86,27 @@ class KT_Slides {
77
86
  this.inDuration = inDuration || this.inDuration;
78
87
  this.slideMultiplier = slideMultiplier || this.slideMultiplier;
79
88
  this.slideDistance = slideDistance || this.slideDistance;
89
+
90
+ this.initialComp = comp;
91
+ if (lazyInit === false) {
92
+ this.ensureInitialized();
93
+ }
94
+ }
95
+
96
+ private ensureInitialized = () => {
97
+ if (this.initialized) {
98
+ return;
99
+ }
100
+
80
101
  this.initFolders();
81
102
  const compExists = KT_Project.find.comps({ name: this.name + " Master" });
82
103
  if (compExists && compExists.length > 0) {
83
104
  this.masterComp = compExists[0] as CompItem;
105
+ this.initialized = true;
84
106
  return;
85
107
  }
86
108
  this.masterComp =
87
- comp ||
109
+ this.initialComp ||
88
110
  (KT_Project.add.comp({
89
111
  name: this.name + " Master",
90
112
  width: this.width,
@@ -92,7 +114,8 @@ class KT_Slides {
92
114
  duration: this.duration,
93
115
  parentFolder: this.rootFolder,
94
116
  }) as CompItem);
95
- }
117
+ this.initialized = true;
118
+ };
96
119
 
97
120
  initFolders = (options: KT_SlidesOptions = {}): void => {
98
121
  const rootFolder = KT_Project.find.folders({ name: this.name + " Project" });
@@ -170,10 +193,6 @@ class KT_Slides {
170
193
  };
171
194
 
172
195
  import = (slideMultiplier?: number) => {
173
- if (!this.masterComp) {
174
- $.writeln("Master comp not found");
175
- return;
176
- }
177
196
  this.slideMultiplier = slideMultiplier || this.slideMultiplier;
178
197
  const path = IO.fs.openFolderDialog("Select Slides Folder");
179
198
  if (!path) {
@@ -181,6 +200,13 @@ class KT_Slides {
181
200
  return;
182
201
  }
183
202
 
203
+ this.ensureInitialized();
204
+
205
+ if (!this.masterComp) {
206
+ $.writeln("Master comp not found");
207
+ return;
208
+ }
209
+
184
210
  let footage = KT_Project.import.images({
185
211
  path: path.fsName,
186
212
  footageFolder: this.footageFolder,
@@ -217,6 +243,7 @@ class KT_Slides {
217
243
  this.inDuration * 2,
218
244
  this.masterComp,
219
245
  (index * this.slideMultiplier + i) * this.inDuration * 2,
246
+ i !== 0,
220
247
  );
221
248
  this.enableTimeRemap(layer as AVLayer);
222
249
  layer.outPoint = this.masterComp.duration;
@@ -233,7 +260,7 @@ class KT_Slides {
233
260
  bgPivot.name = this.backgroundPivotPrefix + item.name.split("-")[0];
234
261
  bgPivot.startTime = groupStartTime;
235
262
  bgPivot.outPoint = this.masterComp.duration;
236
- bgPivot.label = randomColorIndex;
263
+ bgPivot.label = BACKGROUND_LABEL;
237
264
  this.enableTimeRemap(bgPivot as AVLayer);
238
265
  if (lowerGroupLayer) {
239
266
  bgPivot.moveAfter(lowerGroupLayer);
@@ -304,7 +331,7 @@ class KT_Slides {
304
331
  bgPivot.name = this.backgroundPivotPrefix + firstLayer.name.split("-")[0];
305
332
  bgPivot.startTime = firstLayer.startTime;
306
333
  bgPivot.outPoint = this.masterComp.duration;
307
- bgPivot.label = firstLayer.label;
334
+ bgPivot.label = BACKGROUND_LABEL;
308
335
  this.enableTimeRemap(bgPivot as AVLayer);
309
336
  bgPivot.moveAfter(lowerGroupLayer);
310
337
  addedPivots += 1;
@@ -473,13 +500,16 @@ class KT_Slides {
473
500
  duration: number,
474
501
  comp: CompItem = app.project.activeItem as CompItem,
475
502
  startTime?: number,
503
+ animate: boolean = true,
476
504
  ) {
477
505
  const layer = comp.layers.add(source);
478
506
  layer.startTime = 0;
479
507
  layer.outPoint = duration;
480
508
  this.fitLayerToComp(layer, comp);
481
- this.slideUp(layer);
482
- this.disolveIn(layer);
509
+ if (animate) {
510
+ this.slideUp(layer);
511
+ this.disolveIn(layer);
512
+ }
483
513
  layer.startTime = startTime || 0;
484
514
  return layer;
485
515
  }
@@ -541,11 +571,11 @@ class KT_Slides {
541
571
  const currentScale = layer.scale.value as number[];
542
572
  const newScale: number[] = [scalePercent, scalePercent];
543
573
  if (currentScale.length > 2) newScale.push(currentScale[2]);
544
- layer.scale.setValue(newScale);
574
+ layer.scale.setValue(newScale as any);
545
575
  const center: number[] = [comp.width / 2, comp.height / 2];
546
576
  const currentPos = layer.position.value as number[];
547
577
  if (currentPos.length > 2) center.push(currentPos[2]);
548
- layer.position.setValue(center);
578
+ layer.position.setValue(center as any);
549
579
  return layer;
550
580
  };
551
581
 
@@ -568,27 +598,42 @@ export { KT_Slides };
568
598
  class __KT_SlidesAPI {
569
599
  private slidesInstance: KT_Slides | null = null;
570
600
  static import = (options: KT_SlidesOptions = {}) => {
571
- const slides = new KT_Slides(options);
601
+ const slides = new KT_Slides({
602
+ ...options,
603
+ lazyInit: true,
604
+ });
572
605
  slides.import(options.slideMultiplier);
573
606
  return slides;
574
607
  };
575
608
 
576
609
  static refreshAll = (options: KT_SlidesOptions) => {
577
- const slidesInstance = new KT_Slides(options);
610
+ const slidesInstance = new KT_Slides({
611
+ ...options,
612
+ lazyInit: false,
613
+ });
578
614
  slidesInstance.batchSplitSlides();
579
615
  };
580
616
 
581
617
  static refreshSelected = (options: KT_SlidesOptions) => {
582
- const slidesInstance = new KT_Slides(options);
618
+ const slidesInstance = new KT_Slides({
619
+ ...options,
620
+ lazyInit: false,
621
+ });
583
622
  slidesInstance.splitSlides();
584
623
  };
585
624
  static cleanUp = (options: KT_SlidesOptions) => {
586
- const slidesInstance = new KT_Slides(options);
625
+ const slidesInstance = new KT_Slides({
626
+ ...options,
627
+ lazyInit: false,
628
+ });
587
629
  slidesInstance.cleanUp();
588
630
  };
589
631
 
590
632
  static migrate = (options: KT_SlidesOptions) => {
591
- const slidesInstance = new KT_Slides(options);
633
+ const slidesInstance = new KT_Slides({
634
+ ...options,
635
+ lazyInit: false,
636
+ });
592
637
  return slidesInstance.migrateBackgroundPivots();
593
638
  };
594
639
  }
@@ -10,9 +10,9 @@ import {
10
10
  } from "kt-testing-suite-core";
11
11
  import { KT_Slides, KT_ForproTools, KT_SlidesFreeze } from "../index";
12
12
  // import "./freezer.test";
13
- // import "./slides.test";
13
+ import "./slides.test";
14
14
  // import "./batchSplitSlides.test";
15
- import "./splitSlides.test";
15
+ // import "./splitSlides.test";
16
16
 
17
17
  // describe("KtForproTools Tests", () => {
18
18
  // it("should import the slides module", () => {