@clypra-studio/engine 1.3.0 → 1.5.0

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.
Files changed (60) hide show
  1. package/README.md +1 -1
  2. package/dist/{chunk-Y4FMAOTW.js → chunk-7ORA5BPW.js} +279 -1302
  3. package/dist/chunk-7ORA5BPW.js.map +1 -0
  4. package/dist/chunk-NG4F55V7.js +300 -0
  5. package/dist/chunk-NG4F55V7.js.map +1 -0
  6. package/dist/chunk-PU3Q4QI7.js +833 -0
  7. package/dist/chunk-PU3Q4QI7.js.map +1 -0
  8. package/dist/chunk-Q7XYDP4X.js +1898 -0
  9. package/dist/chunk-Q7XYDP4X.js.map +1 -0
  10. package/dist/{chunk-LT3HTJ3X.js → chunk-SH7HOGVX.js} +5 -829
  11. package/dist/chunk-SH7HOGVX.js.map +1 -0
  12. package/dist/index-B1lFl4p2.d.ts +122 -0
  13. package/dist/index-Cpps1DKP.d.ts +489 -0
  14. package/dist/index-DrzRbR7G.d.cts +122 -0
  15. package/dist/index-WsvrOpAy.d.cts +489 -0
  16. package/dist/index.cjs +14360 -24090
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +2187 -7852
  19. package/dist/index.d.ts +2187 -7852
  20. package/dist/index.js +11128 -18233
  21. package/dist/index.js.map +1 -1
  22. package/dist/rendering/index.cjs +3694 -0
  23. package/dist/rendering/index.cjs.map +1 -0
  24. package/dist/rendering/index.d.cts +2 -0
  25. package/dist/rendering/index.d.ts +2 -0
  26. package/dist/rendering/index.js +21 -0
  27. package/dist/textEffects/index.cjs +270 -974
  28. package/dist/textEffects/index.cjs.map +1 -1
  29. package/dist/textEffects/index.d.cts +2 -1
  30. package/dist/textEffects/index.d.ts +2 -1
  31. package/dist/textEffects/index.js +6 -4
  32. package/dist/transitions/index.cjs +18 -2199
  33. package/dist/transitions/index.cjs.map +1 -1
  34. package/dist/transitions/index.d.cts +37 -53
  35. package/dist/transitions/index.d.ts +37 -53
  36. package/dist/transitions/index.js +3 -51
  37. package/dist/{index-D6GAXDBy.d.cts → types-IYwXGYkB.d.cts} +300 -154
  38. package/dist/{index-D6GAXDBy.d.ts → types-IYwXGYkB.d.ts} +300 -154
  39. package/dist/videoEffects/index.cjs +4 -835
  40. package/dist/videoEffects/index.cjs.map +1 -1
  41. package/dist/videoEffects/index.d.cts +9 -138
  42. package/dist/videoEffects/index.d.ts +9 -138
  43. package/dist/videoEffects/index.js +1 -15
  44. package/package.json +18 -16
  45. package/dist/TransitionDefinition-CQoSb4ZB.d.cts +0 -158
  46. package/dist/TransitionDefinition-CQoSb4ZB.d.ts +0 -158
  47. package/dist/chunk-FIJBB3MH.js +0 -2990
  48. package/dist/chunk-FIJBB3MH.js.map +0 -1
  49. package/dist/chunk-LT3HTJ3X.js.map +0 -1
  50. package/dist/chunk-RYA4KGDB.js +0 -690
  51. package/dist/chunk-RYA4KGDB.js.map +0 -1
  52. package/dist/chunk-Y4FMAOTW.js.map +0 -1
  53. package/dist/index-BdQ3oRT4.d.cts +0 -139
  54. package/dist/index-BdQ3oRT4.d.ts +0 -139
  55. package/dist/v2/backends/index.cjs +0 -693
  56. package/dist/v2/backends/index.cjs.map +0 -1
  57. package/dist/v2/backends/index.d.cts +0 -3
  58. package/dist/v2/backends/index.d.ts +0 -3
  59. package/dist/v2/backends/index.js +0 -8
  60. /package/dist/{v2/backends → rendering}/index.js.map +0 -0
@@ -38,12 +38,6 @@ module.exports = __toCommonJS(textEffects_exports);
38
38
  var DEFAULT_CANVAS_WIDTH = 800;
39
39
  var DEFAULT_CANVAS_HEIGHT = 200;
40
40
  var DEFAULT_FONT_SIZE = 80;
41
- var LEGACY_RENDERER_MAP = {
42
- InkBrushEngine: "ink"
43
- };
44
- var ENGINE_ID_TO_LEGACY = {
45
- ink: "InkBrushEngine"
46
- };
47
41
  function newLayerId() {
48
42
  return `layer-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 7)}`;
49
43
  }
@@ -237,19 +231,43 @@ function drawPerCharText(ctx, opts) {
237
231
  ctx.restore();
238
232
  }
239
233
  function shouldUsePerCharFill(cfg) {
240
- return !!cfg.perCharFillEnabled && cfg.fillType === "solid" && !cfg.customRenderer && (cfg.charFillColors?.length ?? 0) > 0;
234
+ return !!cfg.perCharFillEnabled && cfg.fillType === "solid" && (cfg.charFillColors?.length ?? 0) > 0;
241
235
  }
242
236
 
243
237
  // src/platform.ts
238
+ var _ctxFilter = null;
244
239
  var _roundRect = null;
245
240
  var _offscreenCanvas = null;
246
241
  function probe2d() {
247
- if (typeof document === "undefined") return null;
242
+ if (typeof OffscreenCanvas !== "undefined") {
243
+ try {
244
+ return new OffscreenCanvas(1, 1).getContext("2d");
245
+ } catch {
246
+ }
247
+ }
248
+ if (typeof document !== "undefined") {
249
+ try {
250
+ return document.createElement("canvas").getContext("2d");
251
+ } catch {
252
+ return null;
253
+ }
254
+ }
255
+ return null;
256
+ }
257
+ function supportsCtxFilter() {
258
+ if (_ctxFilter !== null) return _ctxFilter;
259
+ const ctx = probe2d();
260
+ if (!ctx) {
261
+ _ctxFilter = false;
262
+ return false;
263
+ }
248
264
  try {
249
- return document.createElement("canvas").getContext("2d");
265
+ ctx.filter = "blur(4px)";
266
+ _ctxFilter = typeof ctx.filter === "string" && ctx.filter.includes("blur");
250
267
  } catch {
251
- return null;
268
+ _ctxFilter = false;
252
269
  }
270
+ return _ctxFilter;
253
271
  }
254
272
  function supportsRoundRect() {
255
273
  if (_roundRect !== null) return _roundRect;
@@ -283,7 +301,7 @@ function createCanvas(width, height) {
283
301
  }
284
302
  }
285
303
  function releaseCanvas(canvas) {
286
- if (canvas instanceof OffscreenCanvas) return;
304
+ if (typeof OffscreenCanvas !== "undefined" && canvas instanceof OffscreenCanvas) return;
287
305
  canvas.width = 0;
288
306
  canvas.height = 0;
289
307
  }
@@ -328,363 +346,6 @@ var CanvasDevice = class {
328
346
  }
329
347
  };
330
348
 
331
- // src/engine/procedural/utils.ts
332
- function getCanvas2DContext(canvas) {
333
- return canvas.getContext("2d");
334
- }
335
- function seededRandom(seed) {
336
- let s = seed;
337
- return function() {
338
- s = s * 16807 % 2147483647;
339
- return (s - 1) / 2147483646;
340
- };
341
- }
342
- function textSeed(text) {
343
- return text.split("").reduce((acc, c) => acc + c.charCodeAt(0), 0) * 9301 % 49297;
344
- }
345
- function hexToRgb(hex) {
346
- const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
347
- const fullHex = hex.replace(shorthandRegex, (m, r, g, b) => r + r + g + g + b + b);
348
- const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(fullHex);
349
- return result ? {
350
- r: parseInt(result[1], 16),
351
- g: parseInt(result[2], 16),
352
- b: parseInt(result[3], 16)
353
- } : { r: 255, g: 255, b: 255 };
354
- }
355
-
356
- // src/engine/procedural/InkBrushEngine.ts
357
- var InkBrushEngine = class {
358
- cfg;
359
- bristleLines = [];
360
- grainDots = [];
361
- drips = [];
362
- constructor(config) {
363
- const defaults = {
364
- text: "INK",
365
- effectName: "InkBrush",
366
- fontFamily: "Bebas Neue",
367
- fontWeight: 900,
368
- fontStyle: "italic",
369
- fontSize: 96,
370
- letterSpacing: 2,
371
- lineHeight: 1.1,
372
- wrapText: true,
373
- autoFitText: false,
374
- perCharFillEnabled: false,
375
- charFillColors: [],
376
- fillType: "solid",
377
- fillColor: "#FFFFFF",
378
- fillGradientAngle: 90,
379
- fillGradientStops: [],
380
- patternType: "chalk",
381
- strokeEnabled: false,
382
- strokeColor: "#000000",
383
- strokeWidth: 0,
384
- strokePosition: "outside",
385
- strokeOpacity: 100,
386
- strokeLineJoin: "round",
387
- strokeBlur: 0,
388
- strokeType: "single",
389
- strokeColorSecondary: "#FFFFFF",
390
- strokeWidthSecondary: 4,
391
- strokeFadeRange: 0,
392
- glowLayers: [],
393
- shadowEnabled: false,
394
- shadowColor: "#000000",
395
- shadowBlur: 10,
396
- shadowOffsetX: 5,
397
- shadowOffsetY: 5,
398
- shadowOpacity: 80,
399
- shadowType: "drop",
400
- bevelEnabled: false,
401
- bevelDepth: 5,
402
- bevelHighlight: "#FFFFFF",
403
- bevelShadow: "#000000",
404
- bevelDirection: "bottom-right",
405
- bevelCoreColor: "#000000",
406
- bevelEdgeColor: "#2A2A38",
407
- bevelEdgeWidth: 0,
408
- bevelBlur: 0,
409
- bevelBlurColor: "#000000",
410
- bevelPerspectiveEnabled: false,
411
- bevelVanishingPointX: 40,
412
- bevelVanishingPointY: 80,
413
- bevelFocalLength: 400,
414
- stackEnabled: false,
415
- stackCount: 3,
416
- stackOffsetX: 10,
417
- stackOffsetY: -10,
418
- stackOpacityDecay: 20,
419
- stackColor1: "#FF7C00",
420
- stackColor2: "#00FFDD",
421
- stackColor3: "#FF00AA",
422
- stackColor4: "#AA00FF",
423
- panelEnabled: false,
424
- panelColor: "#1E1E26",
425
- panelOpacity: 80,
426
- panelRadius: 12,
427
- panelPaddingX: 40,
428
- panelPaddingY: 20,
429
- panelStrokeEnabled: false,
430
- panelStrokeColor: "#2A2A38",
431
- panelStrokeWidth: 2,
432
- canvasWidth: DEFAULT_CANVAS_WIDTH,
433
- canvasHeight: DEFAULT_CANVAS_HEIGHT,
434
- textPosX: "center",
435
- textPosY: "middle",
436
- inkColor: "#FFFFFF",
437
- bristleDensity: 0.8,
438
- bristleSkipRate: 0.2,
439
- dripRate: 0.3,
440
- dripMaxLength: 40,
441
- grainDensity: 0.15,
442
- skewX: -0.2,
443
- customRenderer: "InkBrushEngine"
444
- };
445
- this.cfg = {
446
- ...defaults,
447
- ...config
448
- };
449
- this.precomputeData();
450
- }
451
- precomputeData() {
452
- const { text, fontFamily, fontWeight, fontStyle, fontSize, letterSpacing, lineHeight, canvasWidth, canvasHeight, textPosX, textPosY, bristleDensity, bristleSkipRate, dripRate, dripMaxLength, grainDensity, skewX } = this.cfg;
453
- const width = canvasWidth;
454
- const height = canvasHeight;
455
- const rand = seededRandom(textSeed(text));
456
- let canvas = createCanvas(width, height);
457
- canvas.width = width;
458
- canvas.height = height;
459
- const ctx = getCanvas2DContext(canvas);
460
- if (!ctx) return;
461
- const lines = text.split("\n");
462
- const numLines = lines.length;
463
- const textBlockHeight = fontSize + (numLines - 1) * fontSize * lineHeight;
464
- let startX = width / 2;
465
- let align = "center";
466
- if (textPosX === "left") {
467
- startX = 50;
468
- align = "left";
469
- } else if (textPosX === "right") {
470
- startX = width - 50;
471
- align = "right";
472
- }
473
- ctx.textAlign = align;
474
- ctx.textBaseline = "alphabetic";
475
- const fontStr = `${fontStyle} ${fontWeight} ${fontSize}px "${fontFamily}"`;
476
- ctx.font = fontStr;
477
- if (letterSpacing !== 0) {
478
- ctx.letterSpacing = `${letterSpacing}px`;
479
- }
480
- let startY = (height - textBlockHeight) / 2 + fontSize * 0.85;
481
- if (textPosY === "top") {
482
- startY = 40 + fontSize * 0.85;
483
- } else if (textPosY === "bottom") {
484
- startY = height - 40 - textBlockHeight + fontSize * 0.85;
485
- }
486
- ctx.save();
487
- if (skewX !== 0) {
488
- ctx.transform(1, 0, skewX, 1, 0, 0);
489
- }
490
- ctx.fillStyle = "#FFFFFF";
491
- lines.forEach((line, index) => {
492
- const py = startY + index * fontSize * lineHeight;
493
- ctx.fillText(line, startX, py);
494
- });
495
- ctx.restore();
496
- const imgData = ctx.getImageData(0, 0, width, height);
497
- const pixels = imgData.data;
498
- let minY = height;
499
- let maxY = 0;
500
- for (let y = 0; y < height; y++) {
501
- for (let x = 0; x < width; x++) {
502
- const idx = (y * width + x) * 4;
503
- if (pixels[idx + 3] > 128) {
504
- if (y < minY) minY = y;
505
- if (y > maxY) maxY = y;
506
- }
507
- }
508
- }
509
- if (minY >= maxY) return;
510
- const step = Math.max(1, Math.min(3, 1 / bristleDensity));
511
- for (let y = minY; y <= maxY; y += step) {
512
- const segments = [];
513
- let inSegment = false;
514
- let xStart = 0;
515
- const targetY = Math.floor(y);
516
- for (let x = 0; x < width; x++) {
517
- const idx = (targetY * width + x) * 4;
518
- const isInside = pixels[idx + 3] > 128;
519
- if (isInside && !inSegment) {
520
- inSegment = true;
521
- xStart = x;
522
- } else if (!isInside && inSegment) {
523
- inSegment = false;
524
- segments.push({ xStart, xEnd: x - 1 });
525
- }
526
- }
527
- if (inSegment) {
528
- segments.push({ xStart, xEnd: width - 1 });
529
- }
530
- for (const seg of segments) {
531
- if (rand() < bristleSkipRate) continue;
532
- const segW = seg.xEnd - seg.xStart;
533
- const startLimit = seg.xStart + rand() * Math.min(15, segW * 0.2);
534
- const endLimit = seg.xEnd - rand() * Math.min(15, segW * 0.2);
535
- if (startLimit >= endLimit) continue;
536
- const opacity = 0.4 + rand() * 0.6;
537
- const lw = 0.5 + rand() * 1.5;
538
- const hasGap = rand() < 0.1;
539
- if (hasGap) {
540
- const gapPct = 0.3 + rand() * 0.4;
541
- const gapLen = 5 + rand() * 15;
542
- const midX = startLimit + (endLimit - startLimit) * gapPct;
543
- const p1Start = startLimit;
544
- const p1End = Math.max(startLimit, midX - gapLen / 2);
545
- const p2Start = Math.min(endLimit, midX + gapLen / 2);
546
- const p2End = endLimit;
547
- if (p1End > p1Start) {
548
- this.bristleLines.push({ y: targetY, x0: p1Start, x1: p1End, opacity, lineWidth: lw });
549
- }
550
- if (p2End > p2Start) {
551
- this.bristleLines.push({ y: targetY, x0: p2Start, x1: p2End, opacity, lineWidth: lw });
552
- }
553
- } else {
554
- this.bristleLines.push({ y: targetY, x0: startLimit, x1: endLimit, opacity, lineWidth: lw });
555
- }
556
- }
557
- }
558
- for (let y = minY; y <= maxY; y++) {
559
- for (let x = 0; x < width; x++) {
560
- const idx = (y * width + x) * 4;
561
- if (pixels[idx + 3] > 128) {
562
- if (rand() < grainDensity) {
563
- this.grainDots.push({
564
- x,
565
- y,
566
- opacity: 0.2 + rand() * 0.3
567
- });
568
- }
569
- }
570
- }
571
- }
572
- const bottomRowForCol = new Array(width).fill(-1);
573
- for (let x = 0; x < width; x++) {
574
- for (let y = height - 1; y >= 0; y--) {
575
- const idx = (y * width + x) * 4;
576
- if (pixels[idx + 3] > 128) {
577
- bottomRowForCol[x] = y;
578
- break;
579
- }
580
- }
581
- }
582
- for (let x = 0; x < width; x++) {
583
- const sY = bottomRowForCol[x];
584
- if (sY === -1) continue;
585
- if (rand() < dripRate) {
586
- const length = 8 + rand() * (dripMaxLength - 8);
587
- const startWidth = 1 + rand() * 1;
588
- const endWidth = rand() < 0.5 ? startWidth : 0.5;
589
- const startOpacity = 0.6 + rand() * 0.3;
590
- const hasBlob = rand() < 0.6;
591
- const blobRadius = 1.5 + rand() * 1.5;
592
- this.drips.push({
593
- x,
594
- startY: sY,
595
- length,
596
- startWidth,
597
- endWidth,
598
- startOpacity,
599
- hasBlob,
600
- blobRadius
601
- });
602
- }
603
- }
604
- }
605
- advanceSteps(steps) {
606
- }
607
- drawFrame(ctx) {
608
- const { text, fontFamily, fontWeight, fontStyle, fontSize, letterSpacing, lineHeight, canvasWidth, canvasHeight, textPosX, textPosY, skewX, inkColor } = this.cfg;
609
- const width = canvasWidth;
610
- const height = canvasHeight;
611
- ctx.clearRect(0, 0, width, height);
612
- ctx.imageSmoothingEnabled = true;
613
- const lines = text.split("\n");
614
- const numLines = lines.length;
615
- const textBlockHeight = fontSize + (numLines - 1) * fontSize * lineHeight;
616
- let startX = width / 2;
617
- let align = "center";
618
- if (textPosX === "left") {
619
- startX = 50;
620
- align = "left";
621
- } else if (textPosX === "right") {
622
- startX = width - 50;
623
- align = "right";
624
- }
625
- ctx.textAlign = align;
626
- ctx.textBaseline = "alphabetic";
627
- const fontStr = `${fontStyle} ${fontWeight} ${fontSize}px "${fontFamily}"`;
628
- ctx.font = fontStr;
629
- if (letterSpacing !== 0) {
630
- ctx.letterSpacing = `${letterSpacing}px`;
631
- }
632
- let startY = (height - textBlockHeight) / 2 + fontSize * 0.85;
633
- if (textPosY === "top") {
634
- startY = 40 + fontSize * 0.85;
635
- } else if (textPosY === "bottom") {
636
- startY = height - 40 - textBlockHeight + fontSize * 0.85;
637
- }
638
- ctx.save();
639
- if (skewX !== 0) {
640
- ctx.transform(1, 0, skewX, 1, 0, 0);
641
- }
642
- ctx.fillStyle = inkColor;
643
- lines.forEach((line, index) => {
644
- const py = startY + index * fontSize * lineHeight;
645
- ctx.fillText(line, startX, py);
646
- });
647
- ctx.restore();
648
- ctx.save();
649
- ctx.globalCompositeOperation = "source-in";
650
- ctx.strokeStyle = inkColor;
651
- this.bristleLines.forEach((line) => {
652
- ctx.globalAlpha = line.opacity;
653
- ctx.lineWidth = line.lineWidth;
654
- ctx.beginPath();
655
- ctx.moveTo(line.x0, line.y);
656
- ctx.lineTo(line.x1, line.y);
657
- ctx.stroke();
658
- });
659
- ctx.fillStyle = inkColor;
660
- this.grainDots.forEach((dot) => {
661
- ctx.globalAlpha = dot.opacity;
662
- ctx.fillRect(dot.x, dot.y, 1, 1);
663
- });
664
- ctx.restore();
665
- const inkRgb = hexToRgb(inkColor);
666
- ctx.save();
667
- this.drips.forEach((drip) => {
668
- const grad = ctx.createLinearGradient(drip.x, drip.startY, drip.x, drip.startY + drip.length);
669
- grad.addColorStop(0, `rgba(${inkRgb.r}, ${inkRgb.g}, ${inkRgb.b}, ${drip.startOpacity})`);
670
- grad.addColorStop(1, `rgba(${inkRgb.r}, ${inkRgb.g}, ${inkRgb.b}, 0)`);
671
- ctx.strokeStyle = grad;
672
- ctx.lineWidth = drip.startWidth;
673
- ctx.beginPath();
674
- ctx.moveTo(drip.x, drip.startY);
675
- ctx.lineTo(drip.x, drip.startY + drip.length);
676
- ctx.stroke();
677
- if (drip.hasBlob) {
678
- ctx.fillStyle = `rgba(${inkRgb.r}, ${inkRgb.g}, ${inkRgb.b}, ${drip.startOpacity * 0.5})`;
679
- ctx.beginPath();
680
- ctx.arc(drip.x, drip.startY + drip.length, drip.blobRadius, 0, Math.PI * 2);
681
- ctx.fill();
682
- }
683
- });
684
- ctx.restore();
685
- }
686
- };
687
-
688
349
  // src/canvas-utils.ts
689
350
  function drawRoundedRect(ctx, x, y, w, h, r) {
690
351
  const radius = Math.max(0, Math.min(r, Math.min(w, h) / 2));
@@ -704,8 +365,20 @@ function drawRoundedRect(ctx, x, y, w, h, r) {
704
365
  }
705
366
  }
706
367
 
368
+ // src/engine/procedural/utils.ts
369
+ function hexToRgb(hex) {
370
+ const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
371
+ const fullHex = hex.replace(shorthandRegex, (m, r, g, b) => r + r + g + g + b + b);
372
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(fullHex);
373
+ return result ? {
374
+ r: parseInt(result[1], 16),
375
+ g: parseInt(result[2], 16),
376
+ b: parseInt(result[3], 16)
377
+ } : { r: 255, g: 255, b: 255 };
378
+ }
379
+
707
380
  // src/renderer.ts
708
- function getCanvas2DContext2(canvas) {
381
+ function getCanvas2DContext(canvas) {
709
382
  return canvas.getContext("2d");
710
383
  }
711
384
  function ctxSupportsFilter(ctx) {
@@ -720,11 +393,6 @@ function ctxSupportsFilter(ctx) {
720
393
  }
721
394
  }
722
395
  function renderTextEffectCore(ctx, cfg) {
723
- if (cfg.customRenderer === "InkBrushEngine") {
724
- const engine = new InkBrushEngine(cfg);
725
- engine.drawFrame(ctx);
726
- return;
727
- }
728
396
  const { text, fontFamily, fontWeight, fontStyle, fontSize, letterSpacing, lineHeight, fillType, fillColor, fillGradientAngle, fillGradientStops, patternType, strokeEnabled, strokeColor, strokeWidth, strokePosition, strokeOpacity, strokeLineJoin, strokeBlur, strokeType, strokeColorSecondary, strokeWidthSecondary, strokeFadeRange, glowLayers, shadowEnabled, shadowColor, shadowBlur, shadowOffsetX, shadowOffsetY, shadowOpacity, shadowType, bevelEnabled, bevelDepth, bevelHighlight, bevelShadow, bevelDirection, bevelCoreColor, bevelEdgeColor, bevelEdgeWidth, bevelBlur, bevelBlurColor, bevelPerspectiveEnabled, bevelVanishingPointX, bevelVanishingPointY, bevelFocalLength, stackEnabled, stackCount, stackOffsetX, stackOffsetY, stackOpacityDecay, stackColor1, stackColor2, stackColor3, stackColor4, panelEnabled, panelColor, panelOpacity, panelRadius, panelPaddingX, panelPaddingY, panelStrokeEnabled, panelStrokeColor, panelStrokeWidth, canvasWidth, canvasHeight, textPosX, textPosY } = cfg;
729
397
  ctx.imageSmoothingEnabled = true;
730
398
  ctx.lineJoin = strokeLineJoin;
@@ -910,6 +578,68 @@ function renderTextEffectCore(ctx, cfg) {
910
578
  }
911
579
  ctx.restore();
912
580
  };
581
+ const renderGlowLayer = (layer2) => {
582
+ let glowCanvas = null;
583
+ try {
584
+ glowCanvas = createCanvas(Math.max(1, Math.ceil(cWidth)), Math.max(1, Math.ceil(cHeight)));
585
+ const glowCtx = getCanvas2DContext(glowCanvas);
586
+ if (!glowCtx) return false;
587
+ glowCtx.clearRect(0, 0, cWidth, cHeight);
588
+ glowCtx.save();
589
+ glowCtx.font = fontStr;
590
+ glowCtx.textAlign = align;
591
+ glowCtx.textBaseline = "alphabetic";
592
+ if (letterSpacing !== 0) glowCtx.letterSpacing = `${letterSpacing}px`;
593
+ glowCtx.globalAlpha = Math.max(0, Math.min(100, layer2.opacity)) / 100;
594
+ glowCtx.fillStyle = layer2.color;
595
+ glowCtx.strokeStyle = layer2.color;
596
+ const spread = Math.max(0, layer2.spread ?? 0);
597
+ if (spread > 0) {
598
+ glowCtx.lineWidth = spread * 2;
599
+ glowCtx.lineJoin = strokeLineJoin;
600
+ }
601
+ const drawSource = () => {
602
+ lines.forEach((line, index) => {
603
+ const py = startY + index * lineAdvance;
604
+ if (spread > 0) glowCtx.strokeText(line, startX, py);
605
+ glowCtx.fillText(line, startX, py);
606
+ });
607
+ };
608
+ const useFilter = ctxSupportsFilter(glowCtx);
609
+ if (useFilter) {
610
+ glowCtx.filter = `blur(${Math.max(0, layer2.blur)}px)`;
611
+ drawSource();
612
+ glowCtx.filter = "none";
613
+ } else {
614
+ glowCtx.shadowColor = layer2.color;
615
+ glowCtx.shadowBlur = Math.max(0, layer2.blur);
616
+ glowCtx.shadowOffsetX = 0;
617
+ glowCtx.shadowOffsetY = 0;
618
+ drawSource();
619
+ glowCtx.shadowColor = "transparent";
620
+ glowCtx.shadowBlur = 0;
621
+ }
622
+ glowCtx.globalCompositeOperation = "destination-out";
623
+ glowCtx.globalAlpha = 1;
624
+ drawSource();
625
+ glowCtx.restore();
626
+ ctx.save();
627
+ if (layer2.type === "inner") {
628
+ ctx.globalCompositeOperation = "source-atop";
629
+ }
630
+ ctx.globalAlpha = 1;
631
+ const passes = Math.max(1, Math.min(20, layer2.strength ?? 1));
632
+ for (let pass = 0; pass < passes; pass += 1) {
633
+ ctx.drawImage(glowCanvas, 0, 0);
634
+ }
635
+ ctx.restore();
636
+ return true;
637
+ } catch {
638
+ return false;
639
+ } finally {
640
+ if (glowCanvas) releaseCanvas(glowCanvas);
641
+ }
642
+ };
913
643
  if (panelEnabled) {
914
644
  ctx.save();
915
645
  ctx.globalAlpha = panelOpacity / 100;
@@ -959,9 +689,11 @@ function renderTextEffectCore(ctx, cfg) {
959
689
  }
960
690
  glowLayers.forEach((layer2) => {
961
691
  if (layer2.enabled && layer2.type === "outer" && layer2.opacity > 0) {
962
- const renderCount = Math.max(1, Math.min(20, layer2.strength ?? 1));
963
- for (let i = 0; i < renderCount; i++) {
964
- renderWithShadowTrick("fill", layer2.color, layer2.blur, 0, 0, layer2.opacity, "#000", layer2.spread ?? 0);
692
+ if (!renderGlowLayer(layer2)) {
693
+ const renderCount = Math.max(1, Math.min(20, layer2.strength ?? 1));
694
+ for (let i = 0; i < renderCount; i += 1) {
695
+ renderWithShadowTrick("fill", layer2.color, layer2.blur, 0, 0, layer2.opacity, "#000", layer2.spread ?? 0);
696
+ }
965
697
  }
966
698
  }
967
699
  });
@@ -1319,7 +1051,7 @@ function renderTextEffectCore(ctx, cfg) {
1319
1051
  patCanvas.width = 120;
1320
1052
  patCanvas.height = 120;
1321
1053
  }
1322
- const patCtx = getCanvas2DContext2(patCanvas);
1054
+ const patCtx = getCanvas2DContext(patCanvas);
1323
1055
  const seedRandom = (initSeed) => {
1324
1056
  let currentSeed = initSeed;
1325
1057
  return () => {
@@ -1733,7 +1465,7 @@ function renderTextEffectCore(ctx, cfg) {
1733
1465
  const tCanvas = createCanvas(cWidth, cHeight);
1734
1466
  tCanvas.width = cWidth;
1735
1467
  tCanvas.height = cHeight;
1736
- const tCtx = getCanvas2DContext2(tCanvas);
1468
+ const tCtx = getCanvas2DContext(tCanvas);
1737
1469
  if (tCtx) {
1738
1470
  tCtx.font = fontStr;
1739
1471
  tCtx.textAlign = align;
@@ -1862,7 +1594,7 @@ function renderTextEffectCore(ctx, cfg) {
1862
1594
  const tintCanvas = createCanvas(cWidth, cHeight);
1863
1595
  tintCanvas.width = cWidth;
1864
1596
  tintCanvas.height = cHeight;
1865
- const tintCtx = getCanvas2DContext2(tintCanvas);
1597
+ const tintCtx = getCanvas2DContext(tintCanvas);
1866
1598
  if (tintCtx) {
1867
1599
  tintCtx.drawImage(tCanvas, 0, 0);
1868
1600
  tintCtx.globalCompositeOperation = "source-in";
@@ -1889,10 +1621,12 @@ function renderTextEffectCore(ctx, cfg) {
1889
1621
  glowLayers.forEach((layer2) => {
1890
1622
  if (layer2.enabled && layer2.type === "inner" && layer2.opacity > 0) {
1891
1623
  ctx.save();
1892
- ctx.globalCompositeOperation = "source-atop";
1893
- const renderCount = Math.max(1, Math.min(20, layer2.strength ?? 1));
1894
- for (let i = 0; i < renderCount; i++) {
1895
- renderWithShadowTrick("fill", layer2.color, layer2.blur, 0, 0, layer2.opacity, "#000000", layer2.spread ?? 0);
1624
+ if (!renderGlowLayer(layer2)) {
1625
+ ctx.globalCompositeOperation = "source-atop";
1626
+ const renderCount = Math.max(1, Math.min(20, layer2.strength ?? 1));
1627
+ for (let i = 0; i < renderCount; i += 1) {
1628
+ renderWithShadowTrick("fill", layer2.color, layer2.blur, 0, 0, layer2.opacity, "#000000", layer2.spread ?? 0);
1629
+ }
1896
1630
  }
1897
1631
  ctx.restore();
1898
1632
  }
@@ -1990,245 +1724,9 @@ var defaultConfig = {
1990
1724
  textPosX: "center",
1991
1725
  textPosY: "middle",
1992
1726
  wrapText: true,
1993
- autoFitText: false,
1994
- // Ink Brush custom properties
1995
- inkColor: "#FFFFFF",
1996
- bristleDensity: 0.8,
1997
- bristleSkipRate: 0.2,
1998
- dripRate: 0.3,
1999
- dripMaxLength: 40,
2000
- grainDensity: 0.15,
2001
- skewX: -0.2
1727
+ autoFitText: false
2002
1728
  };
2003
- var builtInPresets = [
2004
- {
2005
- id: "premium-sticker",
2006
- name: "STICKER",
2007
- category: "Classic",
2008
- config: {
2009
- ...defaultConfig,
2010
- text: "TEXT",
2011
- effectName: "StickerEffect",
2012
- fontFamily: "Arial Rounded MT Bold",
2013
- fontWeight: 900,
2014
- fontStyle: "normal",
2015
- fontSize: 88,
2016
- letterSpacing: 2,
2017
- lineHeight: 1.2,
2018
- fillType: "linear",
2019
- fillGradientAngle: 90,
2020
- fillGradientStops: [
2021
- { color: "#FFCE00", offset: 0 },
2022
- { color: "#E05300", offset: 100 }
2023
- ],
2024
- strokeEnabled: true,
2025
- strokeColor: "#FFFFFF",
2026
- strokeWidth: 15,
2027
- strokePosition: "outside",
2028
- strokeType: "single",
2029
- strokeLineJoin: "round",
2030
- strokeOpacity: 100,
2031
- bevelEnabled: true,
2032
- bevelDepth: 8,
2033
- bevelDirection: "bottom-right",
2034
- bevelHighlight: "#FFCE00",
2035
- bevelCoreColor: "#4E1901",
2036
- bevelShadow: "#1D0A00",
2037
- shadowEnabled: true,
2038
- shadowColor: "#000000",
2039
- shadowBlur: 14,
2040
- shadowOffsetX: 6,
2041
- shadowOffsetY: 8,
2042
- shadowOpacity: 65,
2043
- shadowType: "drop"
2044
- }
2045
- },
2046
- {
2047
- id: "premium-holo",
2048
- name: "HOLOGRAPHIC",
2049
- category: "Classic",
2050
- config: {
2051
- ...defaultConfig,
2052
- text: "TEXT",
2053
- effectName: "HolographicEffect",
2054
- fontFamily: "Impact",
2055
- fontWeight: 900,
2056
- fontStyle: "normal",
2057
- fontSize: 100,
2058
- letterSpacing: 2,
2059
- lineHeight: 1.2,
2060
- fillType: "linear",
2061
- fillGradientAngle: 125,
2062
- fillGradientStops: [
2063
- { color: "#6FE3FF", offset: 0 },
2064
- { color: "#D196FF", offset: 25 },
2065
- { color: "#FF9CEE", offset: 50 },
2066
- { color: "#FFE49E", offset: 75 },
2067
- { color: "#D4FFF1", offset: 100 }
2068
- ],
2069
- strokeEnabled: true,
2070
- strokeColor: "#FFFFFF",
2071
- strokeWidth: 2,
2072
- strokePosition: "outside",
2073
- strokeType: "single",
2074
- strokeOpacity: 100,
2075
- glowLayers: [{ enabled: true, color: "#D196FF", blur: 15, opacity: 50, type: "outer" }],
2076
- bevelEnabled: true,
2077
- bevelDepth: 4,
2078
- bevelDirection: "bottom-right",
2079
- bevelHighlight: "#FFFFFF",
2080
- bevelCoreColor: "#2A3540",
2081
- bevelShadow: "#0E151D",
2082
- shadowEnabled: true,
2083
- shadowColor: "#000000",
2084
- shadowBlur: 20,
2085
- shadowOffsetX: 6,
2086
- shadowOffsetY: 10,
2087
- shadowOpacity: 90,
2088
- shadowType: "drop"
2089
- }
2090
- },
2091
- {
2092
- id: "classic-ink",
2093
- name: "Classic Ink",
2094
- category: "Classic",
2095
- config: {
2096
- ...defaultConfig,
2097
- text: "Classic Ink",
2098
- effectName: "ClassicInk",
2099
- fontFamily: "Playfair Display",
2100
- fontWeight: 700,
2101
- fontStyle: "normal",
2102
- fontSize: 85,
2103
- letterSpacing: 1,
2104
- lineHeight: 1.2,
2105
- fillType: "linear",
2106
- fillGradientAngle: 90,
2107
- fillGradientStops: [
2108
- { color: "#FDFBF7", offset: 0 },
2109
- { color: "#EAE5D9", offset: 100 }
2110
- ],
2111
- strokeEnabled: true,
2112
- strokeColor: "#1E1E26",
2113
- strokeWidth: 2,
2114
- strokePosition: "outside",
2115
- strokeOpacity: 100,
2116
- strokeLineJoin: "round",
2117
- shadowEnabled: true,
2118
- shadowColor: "#3D2B1F",
2119
- shadowBlur: 14,
2120
- shadowOffsetX: 6,
2121
- shadowOffsetY: 6,
2122
- shadowOpacity: 90,
2123
- shadowType: "drop"
2124
- }
2125
- },
2126
- {
2127
- id: "neon-crimson",
2128
- name: "Neon Crimson",
2129
- category: "Neon",
2130
- config: {
2131
- ...defaultConfig,
2132
- text: "NEON",
2133
- effectName: "NeonCrimson",
2134
- fontFamily: "Bebas Neue",
2135
- fontWeight: 700,
2136
- fontStyle: "normal",
2137
- fontSize: 100,
2138
- letterSpacing: 6,
2139
- lineHeight: 1.2,
2140
- fillType: "none",
2141
- strokeEnabled: true,
2142
- strokeColor: "#FFFFFF",
2143
- strokeWidth: 3,
2144
- strokePosition: "center",
2145
- strokeOpacity: 100,
2146
- strokeLineJoin: "round",
2147
- glowLayers: [
2148
- { enabled: true, color: "#FF003C", blur: 12, opacity: 100, type: "outer" },
2149
- { enabled: true, color: "#FF003C", blur: 35, opacity: 80, type: "outer" },
2150
- { enabled: true, color: "#FF003C", blur: 80, opacity: 60, type: "outer" }
2151
- ],
2152
- shadowEnabled: false
2153
- }
2154
- },
2155
- {
2156
- id: "cyberpunk-yellow",
2157
- name: "Cyberpunk Yellow",
2158
- category: "Neon",
2159
- config: {
2160
- ...defaultConfig,
2161
- text: "CYBER",
2162
- effectName: "CyberpunkYellow",
2163
- fontFamily: "Anton",
2164
- fontWeight: 900,
2165
- fontStyle: "normal",
2166
- fontSize: 90,
2167
- letterSpacing: 2,
2168
- lineHeight: 1.2,
2169
- fillType: "solid",
2170
- fillColor: "#FFE600",
2171
- strokeEnabled: true,
2172
- strokeColor: "#000000",
2173
- strokeWidth: 6,
2174
- strokePosition: "outside",
2175
- strokeOpacity: 100,
2176
- strokeLineJoin: "round",
2177
- shadowEnabled: true,
2178
- shadowColor: "#FFE600",
2179
- shadowBlur: 15,
2180
- shadowOffsetX: 4,
2181
- shadowOffsetY: 4,
2182
- shadowOpacity: 95,
2183
- shadowType: "drop"
2184
- }
2185
- },
2186
- {
2187
- id: "retro-comic",
2188
- name: "Retro Comic",
2189
- category: "Experimental",
2190
- config: {
2191
- ...defaultConfig,
2192
- text: "BOOM!",
2193
- effectName: "RetroComic",
2194
- fontFamily: "Arial Black",
2195
- fontWeight: 900,
2196
- fontStyle: "normal",
2197
- fontSize: 85,
2198
- letterSpacing: 3,
2199
- lineHeight: 1.1,
2200
- fillType: "solid",
2201
- fillColor: "#000000",
2202
- strokeEnabled: true,
2203
- strokeColor: "#FFFFFF",
2204
- strokeWidth: 6,
2205
- strokePosition: "outside",
2206
- strokeOpacity: 100,
2207
- strokeLineJoin: "round",
2208
- glowLayers: [
2209
- { enabled: true, color: "#000000", blur: 0, opacity: 100, type: "outer", strength: 1, spread: 3 },
2210
- { enabled: false, color: "#FF007C", blur: 40, opacity: 60, type: "outer" },
2211
- { enabled: false, color: "#00F0FF", blur: 60, opacity: 40, type: "outer" }
2212
- ],
2213
- // panelEnabled: true,
2214
- // panelColor: "#FFE100",
2215
- // panelOpacity: 100,
2216
- // panelRadius: 10,
2217
- // panelPaddingX: 55,
2218
- // panelPaddingY: 35,
2219
- // panelStrokeEnabled: true,
2220
- // panelStrokeColor: "#000000",
2221
- // panelStrokeWidth: 4,
2222
- shadowEnabled: true,
2223
- shadowColor: "#000000",
2224
- shadowBlur: 0,
2225
- shadowOffsetX: 8,
2226
- shadowOffsetY: 8,
2227
- shadowOpacity: 100,
2228
- shadowType: "drop"
2229
- }
2230
- }
2231
- ];
1729
+ var builtInPresets = [];
2232
1730
 
2233
1731
  // src/engine/timelineDefaults.ts
2234
1732
  function ensureDefaultTimeline(doc) {
@@ -2276,7 +1774,7 @@ function ensureDefaultTimeline(doc) {
2276
1774
  // src/engine/migrate.ts
2277
1775
  function layer(type, name, params, extra) {
2278
1776
  return {
2279
- id: newLayerId(),
1777
+ id: extra?.id ?? newLayerId(),
2280
1778
  type,
2281
1779
  name,
2282
1780
  enabled: true,
@@ -2287,72 +1785,61 @@ function layer(type, name, params, extra) {
2287
1785
  ...extra
2288
1786
  };
2289
1787
  }
2290
- function resolveCustomEngineId(cfg) {
2291
- if (!cfg.customRenderer) return null;
2292
- return LEGACY_RENDERER_MAP[cfg.customRenderer] ?? null;
1788
+ var REMOVED_INK_FIELDS = [
1789
+ "customRenderer",
1790
+ "inkColor",
1791
+ "bristleDensity",
1792
+ "bristleSkipRate",
1793
+ "dripRate",
1794
+ "dripMaxLength",
1795
+ "grainDensity",
1796
+ "skewX"
1797
+ ];
1798
+ function stripRemovedRendererFields(value) {
1799
+ const out = { ...value };
1800
+ for (const key of REMOVED_INK_FIELDS) delete out[key];
1801
+ return out;
2293
1802
  }
2294
1803
  function textEffectConfigToScene(cfg) {
2295
- const engineId = resolveCustomEngineId(cfg);
1804
+ const safeConfig = stripRemovedRendererFields(cfg);
2296
1805
  const layers = [];
2297
- if (engineId) {
2298
- layers.push(
2299
- layer(
2300
- "customEngine",
2301
- "Custom Engine",
2302
- { engineId },
2303
- {
2304
- enabled: true,
2305
- target: "scene"
2306
- }
2307
- )
2308
- );
2309
- layers.push(
2310
- layer(
2311
- "customEngine",
2312
- "Engine Params",
2313
- { ...collectEngineParams(cfg, engineId) },
2314
- {
2315
- enabled: true,
2316
- target: "text"
2317
- }
2318
- )
2319
- );
2320
- }
2321
1806
  layers.push(
2322
1807
  layer(
2323
1808
  "panel",
2324
1809
  "Background Panel",
2325
1810
  {
2326
- panelEnabled: cfg.panelEnabled,
2327
- panelColor: cfg.panelColor,
2328
- panelOpacity: cfg.panelOpacity,
2329
- panelRadius: cfg.panelRadius,
2330
- panelPaddingX: cfg.panelPaddingX,
2331
- panelPaddingY: cfg.panelPaddingY,
2332
- panelStrokeEnabled: cfg.panelStrokeEnabled,
2333
- panelStrokeColor: cfg.panelStrokeColor,
2334
- panelStrokeWidth: cfg.panelStrokeWidth
1811
+ enabled: safeConfig.panelEnabled,
1812
+ panelEnabled: safeConfig.panelEnabled,
1813
+ panelColor: safeConfig.panelColor,
1814
+ panelOpacity: safeConfig.panelOpacity,
1815
+ panelRadius: safeConfig.panelRadius,
1816
+ panelPaddingX: safeConfig.panelPaddingX,
1817
+ panelPaddingY: safeConfig.panelPaddingY,
1818
+ panelStrokeEnabled: safeConfig.panelStrokeEnabled,
1819
+ panelStrokeColor: safeConfig.panelStrokeColor,
1820
+ panelStrokeWidth: safeConfig.panelStrokeWidth
2335
1821
  },
2336
- { enabled: cfg.panelEnabled }
1822
+ { enabled: safeConfig.panelEnabled, id: "panel" }
2337
1823
  )
2338
1824
  );
2339
- (cfg.glowLayers || []).forEach((g, i) => {
2340
- layers.push(layer("glow", `Glow ${i + 1}`, { ...g }, { enabled: g.enabled, opacity: (g.opacity ?? 100) / 100 }));
1825
+ (safeConfig.glowLayers || []).forEach((g, i) => {
1826
+ layers.push(layer("glow", `Glow ${i + 1}`, { ...g, enabled: g.enabled }, { id: `glow-${i + 1}`, enabled: g.enabled, opacity: (g.opacity ?? 100) / 100 }));
2341
1827
  });
2342
1828
  layers.push(
2343
1829
  layer(
2344
1830
  "shadow",
2345
1831
  "Shadow",
2346
1832
  {
2347
- shadowEnabled: cfg.shadowEnabled,
2348
- shadowColor: cfg.shadowColor,
2349
- shadowBlur: cfg.shadowBlur,
2350
- shadowOffsetX: cfg.shadowOffsetX,
2351
- shadowOffsetY: cfg.shadowOffsetY,
2352
- shadowOpacity: cfg.shadowOpacity,
2353
- shadowType: cfg.shadowType
1833
+ enabled: safeConfig.shadowEnabled,
1834
+ shadowEnabled: safeConfig.shadowEnabled,
1835
+ shadowColor: safeConfig.shadowColor,
1836
+ shadowBlur: safeConfig.shadowBlur,
1837
+ shadowOffsetX: safeConfig.shadowOffsetX,
1838
+ shadowOffsetY: safeConfig.shadowOffsetY,
1839
+ shadowOpacity: safeConfig.shadowOpacity,
1840
+ shadowType: safeConfig.shadowType
2354
1841
  },
2355
- { enabled: cfg.shadowEnabled }
1842
+ { enabled: safeConfig.shadowEnabled, id: "shadow" }
2356
1843
  )
2357
1844
  );
2358
1845
  layers.push(
@@ -2360,22 +1847,23 @@ function textEffectConfigToScene(cfg) {
2360
1847
  "extrusion",
2361
1848
  "Bevel / Extrusion",
2362
1849
  {
2363
- bevelEnabled: cfg.bevelEnabled,
2364
- bevelDepth: cfg.bevelDepth,
2365
- bevelHighlight: cfg.bevelHighlight,
2366
- bevelShadow: cfg.bevelShadow,
2367
- bevelDirection: cfg.bevelDirection,
2368
- bevelCoreColor: cfg.bevelCoreColor,
2369
- bevelEdgeColor: cfg.bevelEdgeColor,
2370
- bevelEdgeWidth: cfg.bevelEdgeWidth,
2371
- bevelBlur: cfg.bevelBlur,
2372
- bevelBlurColor: cfg.bevelBlurColor,
2373
- bevelPerspectiveEnabled: cfg.bevelPerspectiveEnabled,
2374
- bevelVanishingPointX: cfg.bevelVanishingPointX,
2375
- bevelVanishingPointY: cfg.bevelVanishingPointY,
2376
- bevelFocalLength: cfg.bevelFocalLength
1850
+ enabled: safeConfig.bevelEnabled,
1851
+ bevelEnabled: safeConfig.bevelEnabled,
1852
+ bevelDepth: safeConfig.bevelDepth,
1853
+ bevelHighlight: safeConfig.bevelHighlight,
1854
+ bevelShadow: safeConfig.bevelShadow,
1855
+ bevelDirection: safeConfig.bevelDirection,
1856
+ bevelCoreColor: safeConfig.bevelCoreColor,
1857
+ bevelEdgeColor: safeConfig.bevelEdgeColor,
1858
+ bevelEdgeWidth: safeConfig.bevelEdgeWidth,
1859
+ bevelBlur: safeConfig.bevelBlur,
1860
+ bevelBlurColor: safeConfig.bevelBlurColor,
1861
+ bevelPerspectiveEnabled: safeConfig.bevelPerspectiveEnabled,
1862
+ bevelVanishingPointX: safeConfig.bevelVanishingPointX,
1863
+ bevelVanishingPointY: safeConfig.bevelVanishingPointY,
1864
+ bevelFocalLength: safeConfig.bevelFocalLength
2377
1865
  },
2378
- { enabled: cfg.bevelEnabled }
1866
+ { enabled: safeConfig.bevelEnabled, id: "extrusion" }
2379
1867
  )
2380
1868
  );
2381
1869
  layers.push(
@@ -2383,17 +1871,18 @@ function textEffectConfigToScene(cfg) {
2383
1871
  "duplicateStack",
2384
1872
  "Stack Extrusion",
2385
1873
  {
2386
- stackEnabled: cfg.stackEnabled,
2387
- stackCount: cfg.stackCount,
2388
- stackOffsetX: cfg.stackOffsetX,
2389
- stackOffsetY: cfg.stackOffsetY,
2390
- stackOpacityDecay: cfg.stackOpacityDecay,
2391
- stackColor1: cfg.stackColor1,
2392
- stackColor2: cfg.stackColor2,
2393
- stackColor3: cfg.stackColor3,
2394
- stackColor4: cfg.stackColor4
1874
+ enabled: !!safeConfig.stackEnabled,
1875
+ stackEnabled: safeConfig.stackEnabled,
1876
+ stackCount: safeConfig.stackCount,
1877
+ stackOffsetX: safeConfig.stackOffsetX,
1878
+ stackOffsetY: safeConfig.stackOffsetY,
1879
+ stackOpacityDecay: safeConfig.stackOpacityDecay,
1880
+ stackColor1: safeConfig.stackColor1,
1881
+ stackColor2: safeConfig.stackColor2,
1882
+ stackColor3: safeConfig.stackColor3,
1883
+ stackColor4: safeConfig.stackColor4
2395
1884
  },
2396
- { enabled: !!cfg.stackEnabled }
1885
+ { enabled: !!safeConfig.stackEnabled, id: "duplicate-stack" }
2397
1886
  )
2398
1887
  );
2399
1888
  layers.push(
@@ -2401,19 +1890,20 @@ function textEffectConfigToScene(cfg) {
2401
1890
  "stroke",
2402
1891
  "Stroke",
2403
1892
  {
2404
- strokeEnabled: cfg.strokeEnabled,
2405
- strokeColor: cfg.strokeColor,
2406
- strokeWidth: cfg.strokeWidth,
2407
- strokePosition: cfg.strokePosition,
2408
- strokeOpacity: cfg.strokeOpacity,
2409
- strokeLineJoin: cfg.strokeLineJoin,
2410
- strokeBlur: cfg.strokeBlur,
2411
- strokeType: cfg.strokeType,
2412
- strokeColorSecondary: cfg.strokeColorSecondary,
2413
- strokeWidthSecondary: cfg.strokeWidthSecondary,
2414
- strokeFadeRange: cfg.strokeFadeRange
1893
+ enabled: safeConfig.strokeEnabled,
1894
+ strokeEnabled: safeConfig.strokeEnabled,
1895
+ strokeColor: safeConfig.strokeColor,
1896
+ strokeWidth: safeConfig.strokeWidth,
1897
+ strokePosition: safeConfig.strokePosition,
1898
+ strokeOpacity: safeConfig.strokeOpacity,
1899
+ strokeLineJoin: safeConfig.strokeLineJoin,
1900
+ strokeBlur: safeConfig.strokeBlur,
1901
+ strokeType: safeConfig.strokeType,
1902
+ strokeColorSecondary: safeConfig.strokeColorSecondary,
1903
+ strokeWidthSecondary: safeConfig.strokeWidthSecondary,
1904
+ strokeFadeRange: safeConfig.strokeFadeRange
2415
1905
  },
2416
- { enabled: cfg.strokeEnabled }
1906
+ { enabled: safeConfig.strokeEnabled, id: "stroke" }
2417
1907
  )
2418
1908
  );
2419
1909
  layers.push(
@@ -2421,73 +1911,57 @@ function textEffectConfigToScene(cfg) {
2421
1911
  "fill",
2422
1912
  "Fill",
2423
1913
  {
2424
- fillType: cfg.fillType,
2425
- fillColor: cfg.fillColor,
2426
- fillGradientAngle: cfg.fillGradientAngle,
2427
- fillGradientStops: cfg.fillGradientStops,
2428
- patternType: cfg.patternType,
2429
- perCharFillEnabled: cfg.perCharFillEnabled,
2430
- charFillColors: cfg.charFillColors
1914
+ enabled: safeConfig.fillType !== "none",
1915
+ fillType: safeConfig.fillType,
1916
+ fillColor: safeConfig.fillColor,
1917
+ fillGradientAngle: safeConfig.fillGradientAngle,
1918
+ fillGradientStops: safeConfig.fillGradientStops,
1919
+ patternType: safeConfig.patternType,
1920
+ perCharFillEnabled: safeConfig.perCharFillEnabled,
1921
+ charFillColors: safeConfig.charFillColors
2431
1922
  },
2432
- { enabled: cfg.fillType !== "none" }
1923
+ { enabled: safeConfig.fillType !== "none", id: "fill" }
2433
1924
  )
2434
1925
  );
2435
- layers.push(layer("mask", "Text Alpha Mask", { maskType: "alphaText", revealProgress: 1 }, { enabled: false }));
2436
- layers.push(layer("filter", "Compositor FX", { blur: 0, bloom: 0 }, { enabled: false, target: "previous" }));
1926
+ layers.push(layer("mask", "Text Alpha Mask", { maskType: "alphaText", revealProgress: 1 }, { enabled: false, id: "mask" }));
1927
+ layers.push(layer("filter", "Compositor FX", { blur: 0, bloom: 0 }, { enabled: false, target: "previous", id: "compositor" }));
2437
1928
  const doc = {
2438
1929
  version: 1,
2439
- effectName: cfg.effectName,
1930
+ schemaVersion: 2,
1931
+ effectName: safeConfig.effectName,
2440
1932
  canvas: {
2441
- width: cfg.canvasWidth,
2442
- height: cfg.canvasHeight,
1933
+ width: safeConfig.canvasWidth,
1934
+ height: safeConfig.canvasHeight,
2443
1935
  background: "transparent"
2444
1936
  },
2445
1937
  text: {
2446
- content: cfg.text,
2447
- fontFamily: cfg.fontFamily,
2448
- fontWeight: cfg.fontWeight,
2449
- fontStyle: cfg.fontStyle,
2450
- fontSize: cfg.fontSize,
2451
- letterSpacing: cfg.letterSpacing,
2452
- lineHeight: cfg.lineHeight,
2453
- textPosX: cfg.textPosX,
2454
- textPosY: cfg.textPosY,
2455
- wrapText: cfg.wrapText !== false,
2456
- autoFitText: !!cfg.autoFitText,
2457
- perCharFillEnabled: cfg.perCharFillEnabled,
2458
- charFillColors: cfg.charFillColors
1938
+ content: safeConfig.text,
1939
+ fontFamily: safeConfig.fontFamily,
1940
+ fontWeight: safeConfig.fontWeight,
1941
+ fontStyle: safeConfig.fontStyle,
1942
+ fontSize: safeConfig.fontSize,
1943
+ letterSpacing: safeConfig.letterSpacing,
1944
+ lineHeight: safeConfig.lineHeight,
1945
+ textPosX: safeConfig.textPosX,
1946
+ textPosY: safeConfig.textPosY,
1947
+ wrapText: safeConfig.wrapText !== false,
1948
+ autoFitText: !!safeConfig.autoFitText,
1949
+ perCharFillEnabled: safeConfig.perCharFillEnabled,
1950
+ charFillColors: safeConfig.charFillColors
2459
1951
  },
2460
1952
  effectLayers: layers,
2461
- customEngineId: engineId,
2462
- engineParams: engineId ? collectEngineParams(cfg, engineId) : void 0,
2463
1953
  compositor: { blur: 0, bloom: 0, bloomThreshold: 0.6 },
2464
1954
  timeline: { duration: 2, fps: 30, loop: true, tracks: [] },
2465
- legacyConfig: { ...cfg }
1955
+ legacyConfig: { ...safeConfig }
2466
1956
  };
2467
1957
  return ensureDefaultTimeline(doc);
2468
1958
  }
2469
- function collectEngineParams(cfg, id) {
2470
- switch (id) {
2471
- case "ink":
2472
- return {
2473
- inkColor: cfg.inkColor,
2474
- bristleDensity: cfg.bristleDensity,
2475
- bristleSkipRate: cfg.bristleSkipRate,
2476
- dripRate: cfg.dripRate,
2477
- dripMaxLength: cfg.dripMaxLength,
2478
- grainDensity: cfg.grainDensity,
2479
- skewX: cfg.skewX
2480
- };
2481
- default:
2482
- return {};
2483
- }
2484
- }
2485
1959
  function getLayerParams(doc, type, index = 0) {
2486
1960
  const found = doc.effectLayers.filter((l) => l.type === type);
2487
1961
  return found[index]?.params;
2488
1962
  }
2489
1963
  function sceneToConfig(doc) {
2490
- const base = doc.legacyConfig ? { ...doc.legacyConfig } : {
1964
+ const base = doc.legacyConfig ? stripRemovedRendererFields(doc.legacyConfig) : {
2491
1965
  ...createDefaultFromScene(doc)
2492
1966
  };
2493
1967
  base.effectName = doc.effectName;
@@ -2504,11 +1978,15 @@ function sceneToConfig(doc) {
2504
1978
  base.autoFitText = !!doc.text.autoFitText;
2505
1979
  base.canvasWidth = doc.canvas.width;
2506
1980
  base.canvasHeight = doc.canvas.height;
1981
+ const withoutLayerEnabled = (params) => {
1982
+ const { enabled: _enabled, ...visualParams } = params;
1983
+ return visualParams;
1984
+ };
2507
1985
  const panel = getLayerParams(doc, "panel");
2508
1986
  if (panel) {
2509
1987
  Object.assign(base, {
2510
- panelEnabled: panel.panelEnabled,
2511
- panelColor: panel.panelColor,
1988
+ panelEnabled: !!doc.effectLayers.find((l) => l.type === "panel")?.enabled && panel.enabled !== false && panel.panelEnabled !== false,
1989
+ ...withoutLayerEnabled(panel),
2512
1990
  panelOpacity: panel.panelOpacity,
2513
1991
  panelRadius: panel.panelRadius,
2514
1992
  panelPaddingX: panel.panelPaddingX,
@@ -2522,7 +2000,7 @@ function sceneToConfig(doc) {
2522
2000
  base.glowLayers = glows.map((l) => {
2523
2001
  const p = l.params;
2524
2002
  return {
2525
- enabled: l.enabled && (p.enabled ?? true),
2003
+ enabled: l.enabled && (p.enabled ?? true) && (l.opacity ?? 1) > 0,
2526
2004
  color: p.color ?? "#7C6FFF",
2527
2005
  blur: p.blur ?? 20,
2528
2006
  opacity: Math.round((p.opacity ?? 80) * (l.opacity ?? 1)),
@@ -2541,23 +2019,17 @@ function sceneToConfig(doc) {
2541
2019
  });
2542
2020
  }
2543
2021
  const shadow = getLayerParams(doc, "shadow");
2544
- if (shadow) Object.assign(base, shadow);
2022
+ if (shadow) Object.assign(base, { ...withoutLayerEnabled(shadow), shadowEnabled: !!doc.effectLayers.find((l) => l.type === "shadow")?.enabled && shadow.enabled !== false && shadow.shadowEnabled !== false });
2545
2023
  const extrusion = getLayerParams(doc, "extrusion");
2546
- if (extrusion) Object.assign(base, extrusion);
2024
+ if (extrusion) Object.assign(base, { ...withoutLayerEnabled(extrusion), bevelEnabled: !!doc.effectLayers.find((l) => l.type === "extrusion")?.enabled && extrusion.enabled !== false && extrusion.bevelEnabled !== false });
2547
2025
  const stack = getLayerParams(doc, "duplicateStack");
2548
- if (stack) Object.assign(base, stack);
2026
+ if (stack) Object.assign(base, { ...withoutLayerEnabled(stack), stackEnabled: !!doc.effectLayers.find((l) => l.type === "duplicateStack")?.enabled && stack.enabled !== false && stack.stackEnabled !== false });
2549
2027
  const stroke = getLayerParams(doc, "stroke");
2550
- if (stroke) Object.assign(base, stroke);
2028
+ if (stroke) Object.assign(base, { ...withoutLayerEnabled(stroke), strokeEnabled: !!doc.effectLayers.find((l) => l.type === "stroke")?.enabled && stroke.enabled !== false && stroke.strokeEnabled !== false });
2551
2029
  const fill = getLayerParams(doc, "fill");
2552
- if (fill) Object.assign(base, fill);
2030
+ if (fill) Object.assign(base, withoutLayerEnabled(fill));
2553
2031
  base.perCharFillEnabled = doc.text.perCharFillEnabled ?? fill?.perCharFillEnabled;
2554
2032
  base.charFillColors = doc.text.charFillColors ?? fill?.charFillColors;
2555
- if (doc.customEngineId) {
2556
- base.customRenderer = ENGINE_ID_TO_LEGACY[doc.customEngineId];
2557
- Object.assign(base, doc.engineParams || {});
2558
- } else {
2559
- base.customRenderer = void 0;
2560
- }
2561
2033
  base.glowLayers = base.glowLayers.slice(0, 6);
2562
2034
  const filterLayers = doc.effectLayers.filter((l) => l.type === "filter" && l.enabled);
2563
2035
  const filter = filterLayers[filterLayers.length - 1]?.params;
@@ -2627,7 +2099,7 @@ function _buildConfig(effect, text, fontSize, canvasWidth, canvasHeight, time, c
2627
2099
  if (effect.animation) {
2628
2100
  config.animation = effect.animation;
2629
2101
  }
2630
- if (fill) {
2102
+ if (fill && fill.enabled !== false) {
2631
2103
  if (fill.type !== void 0) config.fillType = fill.type;
2632
2104
  if (fill.color !== void 0) config.fillColor = fill.color;
2633
2105
  if (fill.gradient?.angle !== void 0) config.fillGradientAngle = fill.gradient.angle;
@@ -2638,7 +2110,7 @@ function _buildConfig(effect, text, fontSize, canvasWidth, canvasHeight, time, c
2638
2110
  } else {
2639
2111
  config.fillType = "none";
2640
2112
  }
2641
- config.strokeEnabled = !!stroke;
2113
+ config.strokeEnabled = !!stroke && stroke.enabled !== false;
2642
2114
  if (stroke) {
2643
2115
  if (stroke.color !== void 0) config.strokeColor = stroke.color;
2644
2116
  if (stroke.width !== void 0) config.strokeWidth = stroke.width * ratio;
@@ -2651,7 +2123,7 @@ function _buildConfig(effect, text, fontSize, canvasWidth, canvasHeight, time, c
2651
2123
  if (stroke.widthSecondary !== void 0) config.strokeWidthSecondary = stroke.widthSecondary * ratio;
2652
2124
  if (stroke.fadeRange !== void 0) config.strokeFadeRange = stroke.fadeRange;
2653
2125
  }
2654
- config.shadowEnabled = !!shadow;
2126
+ config.shadowEnabled = !!shadow && shadow.enabled !== false;
2655
2127
  if (shadow) {
2656
2128
  if (shadow.color !== void 0) config.shadowColor = shadow.color;
2657
2129
  if (shadow.blur !== void 0) config.shadowBlur = shadow.blur * ratio;
@@ -2662,7 +2134,7 @@ function _buildConfig(effect, text, fontSize, canvasWidth, canvasHeight, time, c
2662
2134
  if (shadow.opacity !== void 0) config.shadowOpacity = shadow.opacity;
2663
2135
  if (shadow.type !== void 0) config.shadowType = shadow.type;
2664
2136
  }
2665
- config.bevelEnabled = !!bevel;
2137
+ config.bevelEnabled = !!bevel && bevel.enabled !== false;
2666
2138
  if (bevel) {
2667
2139
  if (bevel.depth !== void 0) config.bevelDepth = Math.round(bevel.depth * ratio);
2668
2140
  if (bevel.highlight !== void 0) config.bevelHighlight = bevel.highlight;
@@ -2681,17 +2153,19 @@ function _buildConfig(effect, text, fontSize, canvasWidth, canvasHeight, time, c
2681
2153
  if (bevel.focalLength !== void 0) config.bevelFocalLength = bevel.focalLength;
2682
2154
  }
2683
2155
  if (effect.stack) {
2684
- config.stackEnabled = !!effect.stack.count;
2156
+ config.stackEnabled = effect.stack.enabled !== false && !!effect.stack.count;
2685
2157
  if (effect.stack.count !== void 0) config.stackCount = effect.stack.count;
2686
2158
  if (effect.stack.offsetX !== void 0) config.stackOffsetX = effect.stack.offsetX * ratio;
2687
2159
  if (effect.stack.offsetY !== void 0) config.stackOffsetY = effect.stack.offsetY * ratio;
2688
- if (effect.stack.opacityDecay !== void 0) config.stackOpacityDecay = effect.stack.opacityDecay;
2160
+ if (effect.stack.opacityDecay !== void 0) {
2161
+ config.stackOpacityDecay = effect.stack.opacityDecay <= 1 ? effect.stack.opacityDecay * 100 : effect.stack.opacityDecay;
2162
+ }
2689
2163
  if (effect.stack.color1 !== void 0) config.stackColor1 = effect.stack.color1;
2690
2164
  if (effect.stack.color2 !== void 0) config.stackColor2 = effect.stack.color2;
2691
2165
  if (effect.stack.color3 !== void 0) config.stackColor3 = effect.stack.color3;
2692
2166
  if (effect.stack.color4 !== void 0) config.stackColor4 = effect.stack.color4;
2693
2167
  }
2694
- config.panelEnabled = !!panel;
2168
+ config.panelEnabled = !!panel && panel.enabled !== false;
2695
2169
  if (panel) {
2696
2170
  if (panel.color !== void 0) config.panelColor = panel.color;
2697
2171
  if (panel.opacity !== void 0) config.panelOpacity = panel.opacity;
@@ -2700,16 +2174,17 @@ function _buildConfig(effect, text, fontSize, canvasWidth, canvasHeight, time, c
2700
2174
  else if (panel.paddingX !== void 0) config.panelPaddingX = panel.paddingX * ratio;
2701
2175
  if (panel.padding?.y !== void 0) config.panelPaddingY = panel.padding.y * ratio;
2702
2176
  else if (panel.paddingY !== void 0) config.panelPaddingY = panel.paddingY * ratio;
2703
- if (panel.stroke !== void 0) {
2704
- config.panelStrokeEnabled = !!panel.stroke;
2177
+ if (panel.stroke) {
2178
+ config.panelStrokeEnabled = panel.stroke.enabled !== false;
2705
2179
  if (panel.stroke.color !== void 0) config.panelStrokeColor = panel.stroke.color;
2706
2180
  if (panel.stroke.width !== void 0) config.panelStrokeWidth = panel.stroke.width * ratio;
2707
2181
  }
2708
2182
  }
2709
- if (effect.glows) {
2710
- config.glowLayers = effect.glows.map((g) => {
2183
+ if (effect.glows || effect.glow) {
2184
+ const sourceGlows = effect.glows ?? [effect.glow];
2185
+ config.glowLayers = sourceGlows.map((g) => {
2711
2186
  const mappedGlow = {
2712
- enabled: true,
2187
+ enabled: g.enabled !== false,
2713
2188
  color: g.color,
2714
2189
  blur: typeof g.blur === "number" ? g.blur * ratio : g.blur ?? 0,
2715
2190
  opacity: g.opacity,
@@ -2720,15 +2195,6 @@ function _buildConfig(effect, text, fontSize, canvasWidth, canvasHeight, time, c
2720
2195
  return mappedGlow;
2721
2196
  });
2722
2197
  }
2723
- const rawEffect = effect;
2724
- if (rawEffect.customRenderer !== void 0) config.customRenderer = rawEffect.customRenderer;
2725
- if (rawEffect.inkColor !== void 0) config.inkColor = rawEffect.inkColor;
2726
- if (rawEffect.bristleDensity !== void 0) config.bristleDensity = rawEffect.bristleDensity;
2727
- if (rawEffect.bristleSkipRate !== void 0) config.bristleSkipRate = rawEffect.bristleSkipRate;
2728
- if (rawEffect.dripRate !== void 0) config.dripRate = rawEffect.dripRate;
2729
- if (rawEffect.dripMaxLength !== void 0) config.dripMaxLength = rawEffect.dripMaxLength;
2730
- if (rawEffect.grainDensity !== void 0) config.grainDensity = rawEffect.grainDensity;
2731
- if (rawEffect.skewX !== void 0) config.skewX = rawEffect.skewX;
2732
2198
  const standardKeys = /* @__PURE__ */ new Set([
2733
2199
  "id",
2734
2200
  "name",
@@ -2821,15 +2287,7 @@ function _buildConfig(effect, text, fontSize, canvasWidth, canvasHeight, time, c
2821
2287
  "textPosX",
2822
2288
  "textPosY",
2823
2289
  "autoFitText",
2824
- "wrapText",
2825
- "customRenderer",
2826
- "inkColor",
2827
- "bristleDensity",
2828
- "bristleSkipRate",
2829
- "dripRate",
2830
- "dripMaxLength",
2831
- "grainDensity",
2832
- "skewX"
2290
+ "wrapText"
2833
2291
  ]);
2834
2292
  for (const key of Object.keys(effect)) {
2835
2293
  if (!standardKeys.has(key)) {
@@ -2903,170 +2361,6 @@ function applyTimelineAtTime(doc, time) {
2903
2361
  return { ...doc, effectLayers: layers };
2904
2362
  }
2905
2363
 
2906
- // src/compositor/index.ts
2907
- var VERTEX_SRC = `#version 300 es
2908
- in vec2 a_pos;
2909
- in vec2 a_uv;
2910
- out vec2 v_uv;
2911
- void main() {
2912
- v_uv = a_uv;
2913
- gl_Position = vec4(a_pos, 0.0, 1.0);
2914
- }
2915
- `;
2916
- var FRAGMENT_SRC = `#version 300 es
2917
- precision highp float;
2918
- in vec2 v_uv;
2919
- uniform sampler2D u_tex;
2920
- uniform vec2 u_texel;
2921
- uniform float u_blur;
2922
- uniform float u_bloom;
2923
- uniform float u_bloomThreshold;
2924
- out vec4 outColor;
2925
-
2926
- void main() {
2927
- vec4 c = texture(u_tex, v_uv);
2928
- if (u_blur < 0.5 && u_bloom < 0.01) {
2929
- outColor = c;
2930
- return;
2931
- }
2932
- vec4 sum = c;
2933
- float w = 0.0;
2934
- if (u_blur >= 0.5) {
2935
- sum = vec4(0.0);
2936
- w = 0.0;
2937
- for (int x = -2; x <= 2; x++) {
2938
- for (int y = -2; y <= 2; y++) {
2939
- vec2 off = vec2(float(x), float(y)) * u_texel * u_blur;
2940
- vec4 s = texture(u_tex, v_uv + off);
2941
- float weight = 1.0 / (1.0 + float(x*x + y*y));
2942
- sum += s * weight;
2943
- w += weight;
2944
- }
2945
- }
2946
- sum /= w;
2947
- }
2948
- vec3 bloom = vec3(0.0);
2949
- if (u_bloom > 0.01) {
2950
- float lum = dot(sum.rgb, vec3(0.299, 0.587, 0.114));
2951
- if (lum > u_bloomThreshold) {
2952
- bloom = sum.rgb * u_bloom * (lum - u_bloomThreshold);
2953
- }
2954
- }
2955
- outColor = vec4(clamp(sum.rgb + bloom, 0.0, 1.0), c.a);
2956
- }
2957
- `;
2958
- var WebGLCompositor = class {
2959
- gl = null;
2960
- program = null;
2961
- vao = null;
2962
- texture = null;
2963
- isSupported;
2964
- constructor() {
2965
- if (typeof document === "undefined") {
2966
- this.isSupported = false;
2967
- return;
2968
- }
2969
- const canvas = document.createElement("canvas");
2970
- canvas.width = 2;
2971
- canvas.height = 2;
2972
- const gl = canvas.getContext("webgl2", { premultipliedAlpha: true, alpha: true });
2973
- if (!gl) {
2974
- this.isSupported = false;
2975
- return;
2976
- }
2977
- this.gl = gl;
2978
- this.isSupported = this.initProgram(gl);
2979
- }
2980
- initProgram(gl) {
2981
- const vs = this.compileShader(gl, gl.VERTEX_SHADER, VERTEX_SRC);
2982
- const fs = this.compileShader(gl, gl.FRAGMENT_SHADER, FRAGMENT_SRC);
2983
- if (!vs || !fs) return false;
2984
- const program = gl.createProgram();
2985
- if (!program) return false;
2986
- gl.attachShader(program, vs);
2987
- gl.attachShader(program, fs);
2988
- gl.linkProgram(program);
2989
- if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
2990
- console.warn("Compositor program link failed", gl.getProgramInfoLog(program));
2991
- return false;
2992
- }
2993
- this.program = program;
2994
- const positions = new Float32Array([-1, -1, 0, 1, 1, -1, 1, 1, -1, 1, 0, 0, 1, 1, 1, 0]);
2995
- const vao = gl.createVertexArray();
2996
- const vbo = gl.createBuffer();
2997
- gl.bindVertexArray(vao);
2998
- gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
2999
- gl.bufferData(gl.ARRAY_BUFFER, positions, gl.STATIC_DRAW);
3000
- const locPos = gl.getAttribLocation(program, "a_pos");
3001
- const locUv = gl.getAttribLocation(program, "a_uv");
3002
- gl.enableVertexAttribArray(locPos);
3003
- gl.vertexAttribPointer(locPos, 2, gl.FLOAT, false, 16, 0);
3004
- gl.enableVertexAttribArray(locUv);
3005
- gl.vertexAttribPointer(locUv, 2, gl.FLOAT, false, 16, 8);
3006
- gl.bindVertexArray(null);
3007
- this.vao = vao;
3008
- this.texture = gl.createTexture();
3009
- return true;
3010
- }
3011
- compileShader(gl, type, source) {
3012
- const shader = gl.createShader(type);
3013
- if (!shader) return null;
3014
- gl.shaderSource(shader, source);
3015
- gl.compileShader(shader);
3016
- if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
3017
- console.warn(gl.getShaderInfoLog(shader));
3018
- return null;
3019
- }
3020
- return shader;
3021
- }
3022
- renderToContext(targetCtx, source, settings) {
3023
- const gl = this.gl;
3024
- const program = this.program;
3025
- if (!gl || !program || !this.isSupported) {
3026
- targetCtx.clearRect(0, 0, source.width, source.height);
3027
- targetCtx.drawImage(source, 0, 0);
3028
- return;
3029
- }
3030
- const w = source.width;
3031
- const h = source.height;
3032
- const canvas = gl.canvas;
3033
- if (canvas.width !== w || canvas.height !== h) {
3034
- canvas.width = w;
3035
- canvas.height = h;
3036
- }
3037
- gl.viewport(0, 0, w, h);
3038
- gl.clearColor(0, 0, 0, 0);
3039
- gl.clear(gl.COLOR_BUFFER_BIT);
3040
- gl.useProgram(program);
3041
- gl.activeTexture(gl.TEXTURE0);
3042
- gl.bindTexture(gl.TEXTURE_2D, this.texture);
3043
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
3044
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
3045
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
3046
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
3047
- gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
3048
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);
3049
- gl.uniform1i(gl.getUniformLocation(program, "u_tex"), 0);
3050
- gl.uniform2f(gl.getUniformLocation(program, "u_texel"), 1 / w, 1 / h);
3051
- gl.uniform1f(gl.getUniformLocation(program, "u_blur"), settings.blur ?? 0);
3052
- gl.uniform1f(gl.getUniformLocation(program, "u_bloom"), settings.bloom ?? 0);
3053
- gl.uniform1f(gl.getUniformLocation(program, "u_bloomThreshold"), settings.bloomThreshold ?? 0.6);
3054
- gl.bindVertexArray(this.vao);
3055
- gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
3056
- gl.bindVertexArray(null);
3057
- targetCtx.clearRect(0, 0, w, h);
3058
- targetCtx.drawImage(canvas, 0, 0);
3059
- }
3060
- dispose() {
3061
- const gl = this.gl;
3062
- if (!gl) return;
3063
- if (this.texture) gl.deleteTexture(this.texture);
3064
- if (this.program) gl.deleteProgram(this.program);
3065
- if (this.vao) gl.deleteVertexArray(this.vao);
3066
- this.gl = null;
3067
- }
3068
- };
3069
-
3070
2364
  // src/engine/mask.ts
3071
2365
  function applyMaskReveal(ctx, doc, width, height) {
3072
2366
  const maskLayer = doc.effectLayers.find((l) => l.type === "mask" && l.enabled);
@@ -3094,14 +2388,6 @@ function applyMaskReveal(ctx, doc, width, height) {
3094
2388
  }
3095
2389
 
3096
2390
  // src/engine/evaluate.ts
3097
- var sharedCompositor = null;
3098
- function getCompositor() {
3099
- if (typeof document === "undefined") return null;
3100
- if (!sharedCompositor) {
3101
- sharedCompositor = new WebGLCompositor();
3102
- }
3103
- return sharedCompositor;
3104
- }
3105
2391
  function evaluateScene(doc, time, ctx, options = {}) {
3106
2392
  const animated = applyTimelineAtTime(doc, time);
3107
2393
  const cfg = sceneToConfig(animated);
@@ -3128,11 +2414,21 @@ function evaluateScene(doc, time, ctx, options = {}) {
3128
2414
  tctx.clearRect(0, 0, w, h);
3129
2415
  renderTextEffectCore(tctx, cfg);
3130
2416
  applyMaskReveal(tctx, animated, w, h);
3131
- const compositor = options.compositor ?? getCompositor();
3132
- if (compositor?.isSupported) {
3133
- compositor.renderToContext(ctx, temp, comp);
2417
+ ctx.clearRect(0, 0, w, h);
2418
+ if (supportsCtxFilter()) {
2419
+ ctx.save();
2420
+ const blur = Math.max(0, comp.blur);
2421
+ const bloom = Math.max(0, comp.bloom);
2422
+ if (blur > 0) ctx.filter = `blur(${blur}px)`;
2423
+ ctx.drawImage(temp, 0, 0);
2424
+ if (bloom > 0) {
2425
+ ctx.globalCompositeOperation = "screen";
2426
+ ctx.globalAlpha = Math.min(0.8, bloom * 0.25);
2427
+ ctx.filter = `blur(${Math.max(1, bloom * 4)}px)`;
2428
+ ctx.drawImage(temp, 0, 0);
2429
+ }
2430
+ ctx.restore();
3134
2431
  } else {
3135
- ctx.clearRect(0, 0, w, h);
3136
2432
  ctx.drawImage(temp, 0, 0);
3137
2433
  }
3138
2434
  CanvasDevice.release(temp);