kt-forpro-tools 1.0.1 → 1.0.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.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "",
5
5
  "author": "Miguel de Mendoza",
6
6
  "main": "src/index.ts",
package/src/slides.ts CHANGED
@@ -32,6 +32,7 @@ export type KT_SlidesOptions = {
32
32
  inDuration?: number;
33
33
  comp?: CompItem;
34
34
  slideMultiplier?: number;
35
+ slideDistance?: number;
35
36
  };
36
37
 
37
38
  class KT_Slides {
@@ -47,6 +48,7 @@ class KT_Slides {
47
48
  width: number = 1920;
48
49
  height: number = 1080;
49
50
  segments: number = 6;
51
+ slideDistance: number = 50;
50
52
  slides: Layer[] = [];
51
53
  inDuration: number = 1;
52
54
  name: string = "Slides";
@@ -55,7 +57,7 @@ class KT_Slides {
55
57
  private getNextColor = colorSelector();
56
58
 
57
59
  constructor(options: KT_SlidesOptions = {}) {
58
- const { name, duration, width, height, segments, inDuration, comp, slideMultiplier } = options;
60
+ const { name, duration, width, height, segments, inDuration, comp, slideMultiplier, slideDistance } = options;
59
61
  this.name = name || this.name;
60
62
  this.duration = duration || this.duration;
61
63
  this.width = width || this.width;
@@ -63,8 +65,9 @@ class KT_Slides {
63
65
  this.segments = segments || this.segments;
64
66
  this.inDuration = inDuration || this.inDuration;
65
67
  this.slideMultiplier = slideMultiplier || this.slideMultiplier;
68
+ this.slideDistance = slideDistance || this.slideDistance;
66
69
  this.initFolders();
67
- const compExists = KT_Project.find.comps({ name: this.name + "Master" });
70
+ const compExists = KT_Project.find.comps({ name: this.name });
68
71
  if (compExists && compExists.length > 0) {
69
72
  this.masterComp = compExists[0] as CompItem;
70
73
  return;
@@ -161,9 +164,9 @@ class KT_Slides {
161
164
  flat: true,
162
165
  toComp: true,
163
166
  compFolder: this.compedSlidesFolder,
167
+ returnAs: "comps",
164
168
  });
165
169
 
166
- footage = KT_Project.find.comps({ root: this.compedSlidesFolder });
167
170
  for (const f of footage) {
168
171
  $.writeln("Imported comp: " + f.name);
169
172
  }
@@ -179,15 +182,7 @@ class KT_Slides {
179
182
  footage.forEach((item, index) => {
180
183
  const randomColorIndex = this.getNextColor();
181
184
  for (let i = 0; i < this.slideMultiplier; i++) {
182
- if (item.name === this.name) $.bp();
183
- const subCompName = ((item as FootageItem).name.split(".")[0] + "-" + (i + 1)).replace(
184
- "Artboard ",
185
- "slide"
186
- );
187
- const subComp = KT_Project.add.compFromFootage(item as FootageItem, {
188
- name: (item as FootageItem).name.split(".")[0] + "-" + (i + 1),
189
- parentFolder: this.compedSlidesFolder,
190
- });
185
+ const subComp = this.precompSlide(item as FootageItem, i);
191
186
 
192
187
  const layer = this.addSlide(
193
188
  subComp as AVItem,
@@ -198,6 +193,10 @@ class KT_Slides {
198
193
  this.enableTimeRemap(layer as AVLayer);
199
194
  layer.outPoint = this.masterComp.duration;
200
195
  layer.label = randomColorIndex;
196
+ if (i === 0) {
197
+ const backgroundlayer = layer.source.layers.add(this.backgroundComp);
198
+ backgroundlayer.moveToEnd();
199
+ }
201
200
  this.slides.push(layer);
202
201
  }
203
202
  });
@@ -256,7 +255,7 @@ class KT_Slides {
256
255
  layers.forEach((pivotLayer, index, collection) => {
257
256
  pivotLayer = pivotLayer as AVLayer;
258
257
  const invertedIndex = collection.length - index;
259
- const slideName = pivotLayer.name.split("-")[0] + "_Slide_" + invertedIndex;
258
+ const slideName = this.getSlideName(pivotLayer, invertedIndex - 1, "_Slide_");
260
259
  let precomp = foundComps[slideName];
261
260
  if (precomp instanceof CompItem) {
262
261
  const layersToRemove = KT_Layers.find.layers({ comps: precomp });
@@ -273,8 +272,6 @@ class KT_Slides {
273
272
 
274
273
  // Obtener todas las capas
275
274
 
276
- // Eliminar todas las capas posteriores a la capa pivote
277
-
278
275
  for (let i = collection.length - 1; i >= 0; i--) {
279
276
  const layer = collection[i];
280
277
 
@@ -301,6 +298,28 @@ class KT_Slides {
301
298
  });
302
299
  };
303
300
 
301
+ cleanUp = () => {
302
+ const layers = this.masterComp.layers;
303
+ const comps = this.compsFolder.items;
304
+ const compsToKeep: string[] = [];
305
+ for (let i = layers.length; i >= 1; i--) {
306
+ const layer = layers[i];
307
+ const nameSplit = layer.name.split("-");
308
+ const slideIndex = parseInt(nameSplit[nameSplit.length - 1]);
309
+ const slideName = this.getSlideName(layer, slideIndex, "_Slide_");
310
+ compsToKeep.push(slideName);
311
+ }
312
+
313
+ for (let i = 1; i <= comps.length; i++) {
314
+ const item = comps[i];
315
+ if (is.comp(item)) {
316
+ if (compsToKeep.indexOf(item.name) < 0) {
317
+ item.remove();
318
+ }
319
+ }
320
+ }
321
+ };
322
+
304
323
  private addSlide(
305
324
  source: AVItem,
306
325
  duration: number,
@@ -316,6 +335,18 @@ class KT_Slides {
316
335
  return layer;
317
336
  }
318
337
 
338
+ private precompSlide = (item: FootageItem, i: number): CompItem => {
339
+ const subCompName = this.getSlideName(item, i);
340
+ const subComp = KT_Project.add.compFromFootage(item as FootageItem, {
341
+ name: subCompName,
342
+ parentFolder: this.compedSlidesFolder,
343
+ });
344
+ return subComp as CompItem;
345
+ };
346
+
347
+ private getSlideName = (item: _ItemClasses | Layer, index: number, infix: string = "-"): string => {
348
+ return item.name.split(".")[0] + infix + (index + 1);
349
+ };
319
350
  private disolveIn = (layer: Layer) => {
320
351
  layer.opacity.setValueAtTime(layer.startTime, 0);
321
352
  layer.opacity.setValueAtTime(layer.startTime + this.inDuration, 100);
@@ -327,7 +358,7 @@ class KT_Slides {
327
358
 
328
359
  private slideUp = (layer: Layer) => {
329
360
  const finalPosition = layer.position.value;
330
- layer.position.setValueAtTime(layer.startTime, [finalPosition[0], finalPosition[1] + 100]);
361
+ layer.position.setValueAtTime(layer.startTime, [finalPosition[0], finalPosition[1] + this.slideDistance]);
331
362
  layer.position.setValueAtTime(layer.startTime + this.inDuration, finalPosition);
332
363
  let easeIn = new KeyframeEase(0, 20);
333
364
  let easeOut = new KeyframeEase(0, 50);
@@ -365,11 +396,13 @@ class __KT_SlidesAPI {
365
396
  return slides;
366
397
  };
367
398
 
368
- static refreshAll = (slidesInstance: KT_Slides) => {
399
+ static refreshAll = (options: KT_SlidesOptions) => {
400
+ const slidesInstance = new KT_Slides(options);
369
401
  slidesInstance.batchSplitSlides();
370
402
  };
371
403
 
372
- static refreshSelected = (slidesInstance: KT_Slides) => {
404
+ static refreshSelected = (options: KT_SlidesOptions) => {
405
+ const slidesInstance = new KT_Slides(options);
373
406
  slidesInstance.splitSlides();
374
407
  };
375
408
  }
@@ -16,20 +16,22 @@ describe("KtForproTools Tests", () => {
16
16
  comp: app.project.activeItem as CompItem,
17
17
  slideMultiplier: slideMultiplier,
18
18
  });
19
+
20
+ slides.cleanUp();
19
21
  // slides.import();
20
- // slides.splitSlides();
21
- const startTime = new Date().getTime();
22
+ // // slides.splitSlides();
23
+ // const startTime = new Date().getTime();
22
24
  // slides.batchSplitSlides();
23
- slides.splitSlides();
25
+ // // slides.splitSlides();
24
26
 
25
- const endTime = new Date().getTime();
26
- const timeTaken = endTime - startTime;
27
- //display time taken in minutes and seconds format mm:ss
28
- $.writeln(
29
- "Time taken: "
30
- .concat(Math.floor(timeTaken / 60000).toFixed(0), ":")
31
- .concat(((timeTaken % 60000) / 1000).toFixed(0), "s")
32
- );
27
+ // const endTime = new Date().getTime();
28
+ // const timeTaken = endTime - startTime;
29
+ // //display time taken in minutes and seconds format mm:ss
30
+ // $.writeln(
31
+ // "Time taken: "
32
+ // .concat(Math.floor(timeTaken / 60000).toFixed(0), ":")
33
+ // .concat(((timeTaken % 60000) / 1000).toFixed(0), "s")
34
+ // );
33
35
  });
34
36
  });
35
37