kt-forpro-tools 1.1.1 → 1.1.2

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.2",
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,
@@ -233,7 +259,7 @@ class KT_Slides {
233
259
  bgPivot.name = this.backgroundPivotPrefix + item.name.split("-")[0];
234
260
  bgPivot.startTime = groupStartTime;
235
261
  bgPivot.outPoint = this.masterComp.duration;
236
- bgPivot.label = randomColorIndex;
262
+ bgPivot.label = BACKGROUND_LABEL;
237
263
  this.enableTimeRemap(bgPivot as AVLayer);
238
264
  if (lowerGroupLayer) {
239
265
  bgPivot.moveAfter(lowerGroupLayer);
@@ -304,7 +330,7 @@ class KT_Slides {
304
330
  bgPivot.name = this.backgroundPivotPrefix + firstLayer.name.split("-")[0];
305
331
  bgPivot.startTime = firstLayer.startTime;
306
332
  bgPivot.outPoint = this.masterComp.duration;
307
- bgPivot.label = firstLayer.label;
333
+ bgPivot.label = BACKGROUND_LABEL;
308
334
  this.enableTimeRemap(bgPivot as AVLayer);
309
335
  bgPivot.moveAfter(lowerGroupLayer);
310
336
  addedPivots += 1;
@@ -541,11 +567,11 @@ class KT_Slides {
541
567
  const currentScale = layer.scale.value as number[];
542
568
  const newScale: number[] = [scalePercent, scalePercent];
543
569
  if (currentScale.length > 2) newScale.push(currentScale[2]);
544
- layer.scale.setValue(newScale);
570
+ layer.scale.setValue(newScale as any);
545
571
  const center: number[] = [comp.width / 2, comp.height / 2];
546
572
  const currentPos = layer.position.value as number[];
547
573
  if (currentPos.length > 2) center.push(currentPos[2]);
548
- layer.position.setValue(center);
574
+ layer.position.setValue(center as any);
549
575
  return layer;
550
576
  };
551
577
 
@@ -568,27 +594,42 @@ export { KT_Slides };
568
594
  class __KT_SlidesAPI {
569
595
  private slidesInstance: KT_Slides | null = null;
570
596
  static import = (options: KT_SlidesOptions = {}) => {
571
- const slides = new KT_Slides(options);
597
+ const slides = new KT_Slides({
598
+ ...options,
599
+ lazyInit: true,
600
+ });
572
601
  slides.import(options.slideMultiplier);
573
602
  return slides;
574
603
  };
575
604
 
576
605
  static refreshAll = (options: KT_SlidesOptions) => {
577
- const slidesInstance = new KT_Slides(options);
606
+ const slidesInstance = new KT_Slides({
607
+ ...options,
608
+ lazyInit: false,
609
+ });
578
610
  slidesInstance.batchSplitSlides();
579
611
  };
580
612
 
581
613
  static refreshSelected = (options: KT_SlidesOptions) => {
582
- const slidesInstance = new KT_Slides(options);
614
+ const slidesInstance = new KT_Slides({
615
+ ...options,
616
+ lazyInit: false,
617
+ });
583
618
  slidesInstance.splitSlides();
584
619
  };
585
620
  static cleanUp = (options: KT_SlidesOptions) => {
586
- const slidesInstance = new KT_Slides(options);
621
+ const slidesInstance = new KT_Slides({
622
+ ...options,
623
+ lazyInit: false,
624
+ });
587
625
  slidesInstance.cleanUp();
588
626
  };
589
627
 
590
628
  static migrate = (options: KT_SlidesOptions) => {
591
- const slidesInstance = new KT_Slides(options);
629
+ const slidesInstance = new KT_Slides({
630
+ ...options,
631
+ lazyInit: false,
632
+ });
592
633
  return slidesInstance.migrateBackgroundPivots();
593
634
  };
594
635
  }
@@ -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", () => {