clipoox-render 0.2.0 → 0.3.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 (131) hide show
  1. package/dist/server-text/titleRaster.js +1394 -0
  2. package/package.json +5 -3
  3. package/scripts/render-local.mjs +1514 -1379
  4. package/shared/transitionStarterPack.json +261 -0
  5. package/web/assets/{FxEmbed-BymBArNa.js → FxEmbed-D7k1ThAF.js} +1 -1
  6. package/web/assets/{GLTFLoader-Dy6SrZg8.js → GLTFLoader-BHWu1lKg.js} +1 -1
  7. package/web/assets/{MotionEmbed-PmXWSWe5.js → MotionEmbed-DFni5IAh.js} +1 -1
  8. package/web/assets/PluginStore-BrupM_8E.js +3 -0
  9. package/web/assets/{ShotComposer-Dprx-Yi7.js → ShotComposer-BLztjSKy.js} +4 -4
  10. package/web/assets/TemplateEmbed-BbAimhLj.js +2 -0
  11. package/web/assets/TimelinePlugins-BI1bE9pX.js +5 -0
  12. package/web/assets/TimelinePlugins-DYarX9RK.css +1 -0
  13. package/web/assets/TimelineShotFx-CQN3WIfN.js +2 -0
  14. package/web/assets/TransitionEmbed-CmoIrHVr.js +1 -0
  15. package/web/assets/{Whiteboard-DybaKCdo.js → Whiteboard-DMk0unYK.js} +3 -3
  16. package/web/assets/aerial-DT_gUtSh.js +2 -0
  17. package/web/assets/{agentTools-CxZqRLeR.js → agentTools-qOww5RUs.js} +2 -2
  18. package/web/assets/analyzerRun-B2FLUp4G.js +1 -0
  19. package/web/assets/{analyzerSandbox-DO5ZTv5q.js → analyzerSandbox-CJVsEhrg.js} +2 -2
  20. package/web/assets/{api-BsKbf3l3.js → api-QBI5GJTZ.js} +148 -148
  21. package/web/assets/auraTrack-CEs_Q9EP.js +1 -0
  22. package/web/assets/{breakthrough-Dv1bndQb.js → breakthrough-DvkxvNK9.js} +2 -2
  23. package/web/assets/{cameraPresets-B234aNzE.js → cameraPresets-4pFeF2YG.js} +1 -1
  24. package/web/assets/{captionLayout-CNgb471H.js → captionLayout-C67EMVI1.js} +1 -1
  25. package/web/assets/{clientExport-NtJmxOYP.js → clientExport-C4VgAJtO.js} +1 -1
  26. package/web/assets/{depthEstimate-wVYSJtW8.js → depthEstimate-mnXDZMW-.js} +1 -1
  27. package/web/assets/{directorTools-BqFcShgT.js → directorTools-BOHZjcww.js} +1 -1
  28. package/web/assets/{distortFrames-D3TQNcJA.js → distortFrames-Csuj2jHE.js} +2 -2
  29. package/web/assets/{distortGL-BklPDXPq.js → distortGL-BaXfN0IK.js} +2 -2
  30. package/web/assets/{editTools-BQlG5WB_.js → editTools-m0VGPmfF.js} +1 -1
  31. package/web/assets/{exportEncode-CaKEPgsy.js → exportEncode-D9OT7_5k.js} +1 -1
  32. package/web/assets/{exportGlb-DstxwzH5.js → exportGlb-CLfTnbMG.js} +1 -1
  33. package/web/assets/faceTracker-W0iZSiMe.js +1 -0
  34. package/web/assets/fightDirector-CECPf2iH.js +1 -0
  35. package/web/assets/{fightDrama-G7bXfpQu.js → fightDrama-CqNoa5XI.js} +2 -2
  36. package/web/assets/{frameSink-Dj71jCRb.js → frameSink-BGRj7wqY.js} +3 -3
  37. package/web/assets/{gpuCompose-DIxBHlTa.js → gpuCompose-CIEoLFem.js} +1 -1
  38. package/web/assets/gpuExport-uyOAyrhm.js +190 -0
  39. package/web/assets/handMatte-mHxZwLZD.js +1 -0
  40. package/web/assets/handTracker-dTVeSUzt.js +2 -0
  41. package/web/assets/{index-CZn97Ygs.js → index-D7M5t2re.js} +1 -1
  42. package/web/assets/layer-worker-Cp0pjurp.js +5 -0
  43. package/web/assets/library-Dsz_MLyd.js +1 -0
  44. package/web/assets/{lottieLayer-CfUPParC.js → lottieLayer-CDCGeJyv.js} +5 -5
  45. package/web/assets/{lottie_light_canvas-7iv3btPX.js → lottie_light_canvas-BblLU4nU.js} +1 -1
  46. package/web/assets/main-BQ8IY0WV.css +1 -0
  47. package/web/assets/{main-M1vRa-gd.js → main-CVRIuDW2.js} +76 -76
  48. package/web/assets/{mapBake-lPNhNZgv.js → mapBake-CNMOKXA7.js} +1 -1
  49. package/web/assets/maskTrack-Dtv6Jr06.js +1 -0
  50. package/web/assets/matteFixRun-BLDH2AjH.js +1 -0
  51. package/web/assets/{objectLocate-BDqfSo9J.js → objectLocate-Cy3IFBSF.js} +1 -1
  52. package/web/assets/{objectTrack.worker-ENzKeSiV.js → objectTrack.worker-BlZkgpOX.js} +483 -352
  53. package/web/assets/pendingMatte-C2AWApuv.js +2 -0
  54. package/web/assets/personAi-DPUnoymj.js +2 -0
  55. package/web/assets/plateCamera-C96L5GKm.js +1 -0
  56. package/web/assets/{plateCameraMatch-D41LQrsm.js → plateCameraMatch-Chk-ZjDi.js} +2 -2
  57. package/web/assets/{plateFollow-CNfi4xuP.js → plateFollow-B9_QTgvo.js} +2 -2
  58. package/web/assets/plateMatte-BiqyI_8x.js +2 -0
  59. package/web/assets/{pluginAutomation-BtQ_w2TB.js → pluginAutomation-5DYldFrb.js} +1 -1
  60. package/web/assets/poseTracker-PuI8vWpR.js +1 -0
  61. package/web/assets/{productTools-r2RgILaA.js → productTools-B1h5cgyt.js} +2 -2
  62. package/web/assets/remote-BJdzzFZg.js +1241 -0
  63. package/web/assets/{rigTrack-Bx9QHlFv.js → rigTrack-CUt4O67J.js} +1 -1
  64. package/web/assets/{rotoMaskStore-pxpRt5Cj.js → rotoMaskStore-DIi45swK.js} +1 -1
  65. package/web/assets/{rotoMatte-DyXlW4jK.js → rotoMatte-013RKqHu.js} +1 -1
  66. package/web/assets/{rotoscope-GORCSVBr.js → rotoscope-d_TUxa-J.js} +1 -1
  67. package/web/assets/{sceneTrack.worker-CEvCN5OB.js → sceneTrack.worker-CT4uoTKn.js} +475 -344
  68. package/web/assets/{shot-worker-B8JWkmBz.js → shot-worker-B1iZT6F5.js} +1 -1
  69. package/web/assets/{shotFxAgent-CzHfe75S.js → shotFxAgent-BDfe73TP.js} +2 -2
  70. package/web/assets/{skin-BkaT2QuX.js → skin-GDY3QPkV.js} +1 -1
  71. package/web/assets/{spark.module-BRT8yMS4.js → spark.module-DdwuJ_hb.js} +1 -1
  72. package/web/assets/{spellDuel-BUy289OT.js → spellDuel-DjNN00bv.js} +2 -2
  73. package/web/assets/{store-BSSbvpzr.js → store-2zneEhhu.js} +1 -1
  74. package/web/assets/{surfaceLight-CMaBhZ_d.js → surfaceLight-B_SYg_f8.js} +1 -1
  75. package/web/assets/surfacePin-zDPmq-hH.js +2 -0
  76. package/web/assets/{textAnimators-Cihw35O8.js → textAnimators-Bdt5LWXk.js} +1 -1
  77. package/web/assets/{thumb-Cs636sYt.js → thumb-byAKvhQP.js} +1 -1
  78. package/web/assets/timeline3d-YIIk_Kn2.js +2 -0
  79. package/web/assets/timeline3dExport-CEH1RjNf.js +1 -0
  80. package/web/assets/{timelineComp-CRRzLazc.js → timelineComp-B73i_8vD.js} +1 -1
  81. package/web/assets/{timelineProps-tN2YsMYN.js → timelineProps-B2pnudeT.js} +1 -1
  82. package/web/assets/{timelineText-CkoUgWcY.js → timelineText-BcL4Pw3C.js} +1 -1
  83. package/web/assets/{titleArt-CcTdJuOC.js → titleArt-hb_T45WJ.js} +5 -5
  84. package/web/assets/{titleFrameBudget-3MFHWIT6.js → titleFrameBudget-Cml-MO53.js} +970 -839
  85. package/web/assets/titleFrames-Dw0PEBdV.js +1 -0
  86. package/web/assets/{tool-BhIsq238.js → tool-Bt9bclIf.js} +1 -1
  87. package/web/assets/{tools-DMUnabc_.js → tools-BXeJbgZJ.js} +1 -1
  88. package/web/assets/{toonTools-CICrV3QB.js → toonTools-u7Y9fdEZ.js} +2 -2
  89. package/web/assets/trackAnchor-9MnVHe4S.js +1 -0
  90. package/web/assets/{userFonts-BZ4QL-zq.js → userFonts-BHduCNtc.js} +1 -1
  91. package/web/assets/{vfxAlpha-D3Dk1tfF.js → vfxAlpha-DpV4rbI-.js} +1 -1
  92. package/web/assets/vfxBackground-Ddviync5.js +2 -0
  93. package/web/assets/{videoExport-l5MGvMn_.js → videoExport-z5WjM0hw.js} +1 -1
  94. package/web/assets/{views-BdWnG2xK.js → views-CsrYzCSR.js} +1 -1
  95. package/web/assets/weaponDuel-CLLgv5A4.js +1 -0
  96. package/web/assets/{windowFrames-CoIyWqxr.js → windowFrames-BQEWQkEs.js} +1 -1
  97. package/web/layer-worker.html +3 -3
  98. package/web/assets/PluginStore-BVsm6n6N.js +0 -3
  99. package/web/assets/TemplateEmbed-CrZXoUk_.js +0 -2
  100. package/web/assets/TimelinePlugins-B1KGtbmb.js +0 -5
  101. package/web/assets/TimelinePlugins-B5WmAawO.css +0 -1
  102. package/web/assets/TimelineShotFx-DoLx312Y.js +0 -2
  103. package/web/assets/TransitionEmbed-C5SUosv2.js +0 -1
  104. package/web/assets/aerial-DSt_mJNA.js +0 -2
  105. package/web/assets/analyzerRun-DCJwb_-Z.js +0 -1
  106. package/web/assets/auraTrack-QR0WqBHp.js +0 -1
  107. package/web/assets/desktop-BWhFnYwd.js +0 -1
  108. package/web/assets/faceTracker-DWxxieVC.js +0 -1
  109. package/web/assets/fightDirector-OMlPZgjv.js +0 -1
  110. package/web/assets/gpuExport-CPSw_dmq.js +0 -189
  111. package/web/assets/handMatte-DHsHHz4m.js +0 -1
  112. package/web/assets/handTracker-D_O-C4Dw.js +0 -2
  113. package/web/assets/layer-worker-Bar7WgOA.js +0 -5
  114. package/web/assets/library-BtBrCaFk.js +0 -1
  115. package/web/assets/main-BPmr0TOL.css +0 -1
  116. package/web/assets/maskTrack-D2jUh7aw.js +0 -1
  117. package/web/assets/matteFixRun-B7tWV9Y1.js +0 -1
  118. package/web/assets/pendingMatte-q35zVaiB.js +0 -2
  119. package/web/assets/personAi-ZjQVo-80.js +0 -2
  120. package/web/assets/plateCamera-A2E_WO_x.js +0 -1
  121. package/web/assets/plateMatte-BdIxGhw5.js +0 -2
  122. package/web/assets/poseTracker-DVX__OK7.js +0 -1
  123. package/web/assets/remote-sTZauTqM.js +0 -1220
  124. package/web/assets/surfacePin-DM9b9ubh.js +0 -2
  125. package/web/assets/timeline3d-BEuZZOxM.js +0 -2
  126. package/web/assets/timeline3dExport-CmSI_pjv.js +0 -1
  127. package/web/assets/titleFrames-w-iWje9N.js +0 -1
  128. package/web/assets/trackAnchor-D2bB5mZE.js +0 -1
  129. package/web/assets/vfxBackground-CHlCg8lb.js +0 -2
  130. package/web/assets/vfxTrack-CqiQDEYm.js +0 -1
  131. package/web/assets/weaponDuel-B2wTffPC.js +0 -1
@@ -0,0 +1,1394 @@
1
+ const REST = { opacity: 1, x: 0, y: 0, scale: 1, scaleX: 1, scaleY: 1, reveal: 1, wipeX: 1, wipeY: 1, brightness: 1, blur: 0, rotate: 0, spread: 0, glitch: 0, flicker: 0, count: 1 };
2
+ const ADDITIVE = ["x", "y", "rotate", "blur", "spread", "glitch", "flicker"];
3
+ const ease = {
4
+ linear: (t) => t,
5
+ easeOutCubic: (t) => 1 - (1 - t) ** 3,
6
+ easeOutQuart: (t) => 1 - (1 - t) ** 4,
7
+ easeOutExpo: (t) => t >= 1 ? 1 : 1 - 2 ** (-10 * t),
8
+ easeInOutCubic: (t) => t < 0.5 ? 4 * t ** 3 : 1 - (-2 * t + 2) ** 3 / 2,
9
+ easeOutBack: (t) => 1 + 2.70158 * (t - 1) ** 3 + 1.70158 * (t - 1) ** 2,
10
+ // Cartoon bounce: a springy overshoot that settles (elastic) / a ball landing (bounce). Both end exactly at 1.
11
+ easeOutElastic: (t) => t <= 0 ? 0 : t >= 1 ? 1 : 2 ** (-10 * t) * Math.sin((t * 10 - 0.75) * (2 * Math.PI / 3)) + 1,
12
+ easeOutBounce: (t) => {
13
+ const n = 7.5625, d = 2.75;
14
+ if (t < 1 / d) return n * t * t;
15
+ if (t < 2 / d) return n * (t -= 1.5 / d) * t + 0.75;
16
+ if (t < 2.5 / d) return n * (t -= 2.25 / d) * t + 0.9375;
17
+ return n * (t -= 2.625 / d) * t + 0.984375;
18
+ }
19
+ };
20
+ function shuffled(count, seed) {
21
+ const order = [...Array(count).keys()];
22
+ let s = seed || 1;
23
+ for (let i = count - 1; i > 0; i--) {
24
+ s = s * 16807 % 2147483647;
25
+ const j = s % (i + 1);
26
+ [order[i], order[j]] = [order[j], order[i]];
27
+ }
28
+ return order;
29
+ }
30
+ function rank(index, count, order) {
31
+ if (order === "reverse") return count - 1 - index;
32
+ if (order === "center") return Math.abs(index - (count - 1) / 2) * 2 | 0;
33
+ if (order === "random") return shuffled(count, count * 7919).indexOf(index);
34
+ return index;
35
+ }
36
+ function introLength(animation, layout) {
37
+ let end = 0;
38
+ for (const t of animation.in) for (const [line, units] of layout.entries()) {
39
+ if (t.lines && !t.lines.includes(line)) continue;
40
+ const count = t.unit === "line" ? 1 : units[t.unit];
41
+ for (let i = 0; i < count; i++) end = Math.max(end, beginOf(t, i, count) + t.duration);
42
+ }
43
+ return end;
44
+ }
45
+ function beginOf(t, unitIndex, unitCount) {
46
+ if (t.at) {
47
+ const r = rank(unitIndex, unitCount, t.order), k = Math.min(r, t.at.length - 1);
48
+ return t.at[k] + t.stagger * (r - k);
49
+ }
50
+ return t.start + t.stagger * rank(unitIndex, unitCount, t.order);
51
+ }
52
+ function progress(t, unitIndex, unitCount, time) {
53
+ const begin = beginOf(t, unitIndex, unitCount);
54
+ return ease[t.easing](Math.min(1, Math.max(0, (time - begin) / t.duration)));
55
+ }
56
+ function animationClock(animation, layout, time, clipDuration, minIntro = 0) {
57
+ const intro = Math.max(minIntro, introLength(animation, layout)), outWindow = intro / animation.outSpeed;
58
+ return animation.out === "reverse" && Number.isFinite(clipDuration) && time > Math.max(intro, clipDuration - outWindow) ? (clipDuration - time) * animation.outSpeed : time;
59
+ }
60
+ function levelPose(animation, kind, line, index, count, clock) {
61
+ const pose = { ...REST, masked: false };
62
+ for (const t of animation.in) {
63
+ if (t.unit !== kind || t.lines && !t.lines.includes(line)) continue;
64
+ const e = progress(t, index, count, clock);
65
+ if (t.mask && e < 1) pose.masked = true;
66
+ for (const [key, from] of Object.entries(t.from)) {
67
+ const value = from + (REST[key] - from) * e;
68
+ if (ADDITIVE.includes(key)) pose[key] += value;
69
+ else pose[key] *= value;
70
+ }
71
+ }
72
+ return pose;
73
+ }
74
+ const REST_POSE = Object.freeze({ ...REST });
75
+ function designMotionEnd(design, rows = 1) {
76
+ let end = 0;
77
+ for (const l of design?.layers || []) if (l.motion) end = Math.max(end, l.motion.start + l.motion.duration + (l.motion.stagger || 0) * Math.max(0, rows - 1));
78
+ return end;
79
+ }
80
+ function layerPose(motion, clock) {
81
+ const pose = { ...REST };
82
+ if (!motion) return pose;
83
+ const e = ease[motion.easing](Math.min(1, Math.max(0, (clock - motion.start) / motion.duration)));
84
+ for (const [key, from] of Object.entries(motion.from)) pose[key] = from + (REST[key] - from) * e;
85
+ pose.rotate += motion.spin * Math.max(0, clock - motion.start);
86
+ return pose;
87
+ }
88
+ function countText(text, k) {
89
+ if (k === 1) return text;
90
+ return text.replace(/\d[\d.,]*\d|\d/, (m) => {
91
+ const sep = /^\d{1,3}([.,]\d{3})+$/.test(m) ? m.match(/[.,]/)[0] : "";
92
+ if (!sep && /[.,]/.test(m)) {
93
+ const dec = m.split(/[.,]/)[1].length, v2 = Math.max(0, Number(m.replace(",", ".")) * k);
94
+ return v2.toFixed(dec).replace(".", m.includes(",") ? "," : ".");
95
+ }
96
+ const v = String(Math.max(0, Math.round(Number(m.replace(/[.,]/g, "")) * k)));
97
+ return sep ? v.replace(/\B(?=(\d{3})+(?!\d))/g, sep) : v;
98
+ });
99
+ }
100
+ const TEXT_ICONS = Object.freeze({
101
+ "sparkle": ["m12 2 2.4 6.6L21 11l-6.6 2.4L12 20l-2.4-6.6L3 11l6.6-2.4L12 2Z", "m19 17 1 3 3 1-3 1-1 3-1-3-3-1 3-1 1-3Z"],
102
+ "pen": ["M5 16 16 5l3 3L8 19H5v-3Z", "m14 7 3 3M4 20h16"],
103
+ "target": ["M3 12a9 9 0 1 0 18 0a9 9 0 1 0 -18 0Z", "M9 12a3 3 0 1 0 6 0a3 3 0 1 0 -6 0Z", "M12 1v4m0 14v4M1 12h4m14 0h4"],
104
+ "play": ["M5 5h14a2 2 0 0 1 2 2v10a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-10a2 2 0 0 1 2 -2Z", "m10 9 5 3-5 3V9Z"],
105
+ "bolt": ["m13 2-8 11h6l-1 9 9-12h-6l0-8Z"],
106
+ "navigate": ["M4 17 10 3l3 9 7-3-6 12-3-7-7 3Z"],
107
+ "chip": ["M6 4h12a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2Z", "M9 9h6v6h-6Z", "M8 1v3m8-3v3M8 20v3m8-3v3M1 8h3m-3 8h3m16-8h3m-3 8h3"],
108
+ "data": ["M4 6h16M4 12h10M4 18h16", "m17 10 4 2-4 2"],
109
+ "building": ["M3 21V8l9-5 9 5v13H3Z", "M9 21v-7h6v7M8 9h1m6 0h1"],
110
+ "signal": ["M4 16a8 8 0 0 1 16 0M7 16a5 5 0 0 1 10 0M10 16a2 2 0 0 1 4 0M12 20h.01"],
111
+ "office": ["M3 21V4h11v17M14 9h7v12H3M7 8h3m-3 4h3m-3 4h3m10-3h-2m2 4h-2"],
112
+ "cloud": ["M4 15a4 4 0 0 1 1-8 7 7 0 0 1 13 1 4 4 0 0 1 1 8H4Z", "m9 19 3 3 3-3M12 13v9"],
113
+ "skyline": ["M3 21V9l5-3v15M8 21V4l6-2v19m0-11 7-3v14M3 21h18"],
114
+ "network": ["M2 12a2 2 0 1 0 4 0a2 2 0 1 0 -4 0Z", "M18 6a2 2 0 1 0 4 0a2 2 0 1 0 -4 0Z", "M18 18a2 2 0 1 0 4 0a2 2 0 1 0 -4 0Z", "m6 11 12-4M6 13l12 4"],
115
+ "video": ["M5 5h14a2 2 0 0 1 2 2v10a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-10a2 2 0 0 1 2 -2Z", "m10 9 5 3-5 3V9Z", "M7 22h10"],
116
+ "home": ["m3 11 9-8 9 8v10H3V11Z", "M9 21v-7h6v7M8 10h.01m8 0h.01"],
117
+ "compass": ["M3 12a9 9 0 1 0 18 0a9 9 0 1 0 -18 0Z", "m12 4 3 8-3 8-3-8 3-8ZM4 12h16"],
118
+ "grid": ["M3 3h18v18H3V3ZM3 9h18M9 3v18M15 9v12"],
119
+ "chart": ["M3 20h18M5 17l5-6 4 3 5-8", "m16 6 3 0 0 3"],
120
+ "pin": ["M20 10c0 6-8 12-8 12S4 16 4 10a8 8 0 1 1 16 0Z", "M9.5 10a2.5 2.5 0 1 0 5.0 0a2.5 2.5 0 1 0 -5.0 0Z"]
121
+ });
122
+ const TIMELINE_FONTS = [
123
+ { family: "Inter", category: "Sans serif" },
124
+ { family: "Be Vietnam Pro", category: "Sans serif" },
125
+ { family: "Roboto", category: "Sans serif" },
126
+ { family: "Open Sans", category: "Sans serif" },
127
+ { family: "Montserrat", category: "Sans serif" },
128
+ { family: "Manrope", category: "Sans serif" },
129
+ { family: "Lexend", category: "Sans serif" },
130
+ { family: "Archivo", category: "Sans serif" },
131
+ { family: "Barlow", category: "Sans serif" },
132
+ { family: "Noto Sans", category: "Sans serif" },
133
+ { family: "Noto Serif", category: "Serif" },
134
+ { family: "Playfair Display", category: "Serif" },
135
+ { family: "Oswald", category: "Display" },
136
+ { family: "Anton", category: "Display" },
137
+ { family: "Bungee", category: "Display" },
138
+ { family: "Dancing Script", category: "Handwriting" },
139
+ { family: "Arial", category: "System" },
140
+ { family: "Georgia", category: "System" },
141
+ { family: "Courier New", category: "System" }
142
+ ];
143
+ TIMELINE_FONTS.map((font) => font.family);
144
+ const HEX = /^#[0-9a-f]{6}$/i;
145
+ const hexToRgb = (hex) => [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16) / 255);
146
+ const toHex = (rgb) => "#" + rgb.map((v) => Math.round(Math.max(0, Math.min(1, v)) * 255).toString(16).padStart(2, "0")).join("");
147
+ function hexToHsl(hex) {
148
+ const [r, g, b] = hexToRgb(hex), max = Math.max(r, g, b), min = Math.min(r, g, b), l = (max + min) / 2, d = max - min;
149
+ if (!d) return [0, 0, l];
150
+ const s = d / (1 - Math.abs(2 * l - 1));
151
+ const h = max === r ? ((g - b) / d + 6) % 6 : max === g ? (b - r) / d + 2 : (r - g) / d + 4;
152
+ return [h * 60, s, l];
153
+ }
154
+ function hslToHex(h, s, l) {
155
+ const c = (1 - Math.abs(2 * l - 1)) * s, x = c * (1 - Math.abs(h / 60 % 2 - 1)), m = l - c / 2;
156
+ const [r, g, b] = h < 60 ? [c, x, 0] : h < 120 ? [x, c, 0] : h < 180 ? [0, c, x] : h < 240 ? [0, x, c] : h < 300 ? [x, 0, c] : [c, 0, x];
157
+ return toHex([r + m, g + m, b + m]);
158
+ }
159
+ const BRIGHT = { yellow: 55, cyan: 185, magenta: 315 };
160
+ function brightHue(h, toward) {
161
+ if (toward === "yellow") return BRIGHT.yellow;
162
+ if (toward === "cyan") return BRIGHT.cyan;
163
+ if (toward === "pink") return BRIGHT.magenta;
164
+ const d = (a, b) => Math.abs((a - b + 540) % 360 - 180);
165
+ for (const v of Object.values(BRIGHT)) if (d(h, v) <= 15) return v;
166
+ return h >= 345 || h < 135 ? BRIGHT.yellow : h < 255 ? BRIGHT.cyan : BRIGHT.magenta;
167
+ }
168
+ function autoFill(base, { white = false, toward = "auto" } = {}) {
169
+ if (!HEX.test(base)) throw new Error("màu gốc phải là #rrggbb");
170
+ const [h, s, l] = hexToHsl(base);
171
+ if (s < 0.15) return l < 0.35 ? { type: "radial", gradient: ["#5c5c5c", "#0d0d0d"] } : { type: "radial", gradient: ["#ffffff", white ? "#d6d6d6" : "#8a8a8a"], stops: [0.25, 1] };
172
+ const dark = hslToHex(h, Math.max(0.75, s), Math.min(0.5, Math.max(0.32, l)));
173
+ const bright = hslToHex(brightHue(h, toward), 1, 0.58);
174
+ return white ? { gradient: ["#ffffff", bright, dark], stops: [0, 0.38, 1], angle: 90 } : { gradient: [bright, dark], angle: 90 };
175
+ }
176
+ const TITLE_FRAME = Object.freeze({ width: 1280, height: 720 });
177
+ const N = 240;
178
+ function samplePath(spec, t = 0, frame = TITLE_FRAME) {
179
+ const W2 = frame.width, H2 = frame.height, cx = (spec.x ?? 0.5) * W2, cy = (spec.y ?? 0.5) * H2;
180
+ const pts = [];
181
+ let closed = false;
182
+ if (spec.type === "circle" || spec.type === "arc") {
183
+ const r = (spec.size ?? 0.3) * H2, sweep = spec.type === "circle" ? 360 : spec.sweep ?? 180;
184
+ closed = spec.type === "circle";
185
+ const mid = (spec.angle ?? -90) + (spec.spin ?? 0) * t, a0 = (mid - sweep / 2) * Math.PI / 180, a1 = (mid + sweep / 2) * Math.PI / 180;
186
+ const n = closed ? N : Math.max(8, Math.round(N * sweep / 360));
187
+ for (let i = 0; i <= n; i++) {
188
+ const a = spec.inside ? a1 - (a1 - a0) * i / n : a0 + (a1 - a0) * i / n;
189
+ pts.push([cx + Math.cos(a) * r, cy + Math.sin(a) * r]);
190
+ }
191
+ } else if (spec.type === "wave") {
192
+ const w = (spec.width ?? 0.8) * W2, amp = (spec.size ?? 0.08) * H2, k = spec.waves ?? 2, ph = (spec.angle ?? 0) * Math.PI / 180;
193
+ for (let i = 0; i <= N; i++) {
194
+ const u = i / N;
195
+ pts.push([cx - w / 2 + w * u, cy + Math.sin(u * k * Math.PI * 2 + ph) * amp]);
196
+ }
197
+ } else {
198
+ const P = spec.points.map(([u, v]) => [u * W2, v * H2]), seg = P.length - 1, per = Math.max(4, Math.round(N / seg));
199
+ for (let s = 0; s < seg; s++) {
200
+ const p0 = P[Math.max(0, s - 1)], p1 = P[s], p2 = P[s + 1], p3 = P[Math.min(seg, s + 2)];
201
+ for (let j = 0; j < per; j++) {
202
+ const u = j / per, u2 = u * u, u3 = u2 * u;
203
+ pts.push([0, 1].map((d) => 0.5 * (2 * p1[d] + (-p0[d] + p2[d]) * u + (2 * p0[d] - 5 * p1[d] + 4 * p2[d] - p3[d]) * u2 + (-p0[d] + 3 * p1[d] - 3 * p2[d] + p3[d]) * u3)));
204
+ }
205
+ }
206
+ pts.push(P[seg]);
207
+ }
208
+ const len = [0];
209
+ for (let i = 1; i < pts.length; i++) len.push(len[i - 1] + Math.hypot(pts[i][0] - pts[i - 1][0], pts[i][1] - pts[i - 1][1]));
210
+ return { pts, len, total: len.at(-1), closed, centre: [cx, cy] };
211
+ }
212
+ function pathAt(P, s) {
213
+ const T = P.total || 1;
214
+ if (P.closed) s = (s % T + T) % T;
215
+ else s = Math.max(0, Math.min(T, s));
216
+ let i = 1;
217
+ while (i < P.len.length - 1 && P.len[i] < s) i++;
218
+ const a = P.pts[i - 1], b = P.pts[i], seg = P.len[i] - P.len[i - 1] || 1, u = (s - P.len[i - 1]) / seg;
219
+ return { x: a[0] + (b[0] - a[0]) * u, y: a[1] + (b[1] - a[1]) * u, angle: Math.atan2(b[1] - a[1], b[0] - a[0]) };
220
+ }
221
+ function placeLetters(spec, widths, t = 0, frame = TITLE_FRAME) {
222
+ const P = samplePath(spec, t, frame), total = widths.reduce((a, b) => a + b, 0);
223
+ const start = (P.total - total) / 2 + (spec.speed ?? 0) * t * P.total;
224
+ let run = 0;
225
+ return widths.map((w) => {
226
+ const s = start + run + w / 2;
227
+ run += w;
228
+ const q = pathAt(P, s), visible = P.closed || s >= 0 && s <= P.total;
229
+ return { x: q.x, y: q.y, angle: q.angle, visible };
230
+ });
231
+ }
232
+ function lineStyleAt(design, index, count) {
233
+ const ls = design?.lines;
234
+ if (!ls) return void 0;
235
+ return ls[design.linesFrom === "end" ? ls.length - (count - index) : index];
236
+ }
237
+ const newCanvas = (width, height) => typeof document !== "undefined" ? Object.assign(document.createElement("canvas"), { width, height }) : new OffscreenCanvas(width, height);
238
+ const W = 1280, H = 720;
239
+ const cache = /* @__PURE__ */ new Map();
240
+ const MAX_CACHED = 8;
241
+ const canvas = () => newCanvas(W, H);
242
+ function fadeAt(x, y, angle) {
243
+ const a = angle * Math.PI / 180, c = Math.cos(a), s = Math.sin(a), h = (Math.abs(c) * W + Math.abs(s) * H) / 2;
244
+ return Math.min(1, Math.max(0, ((x - W / 2) * c + (y - H / 2) * s + h) / (2 * h)));
245
+ }
246
+ function rng$1(seed) {
247
+ return () => {
248
+ seed |= 0;
249
+ seed = seed + 1831565813 | 0;
250
+ let t = Math.imul(seed ^ seed >>> 15, 1 | seed);
251
+ t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
252
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
253
+ };
254
+ }
255
+ function draw(layer, color) {
256
+ const out = canvas(), ctx = out.getContext("2d");
257
+ const { scale, size, fade, fadeAngle } = layer;
258
+ ctx.fillStyle = color;
259
+ if (layer.pattern === "grain") {
260
+ const cell = Math.max(1, Math.round(scale / 4)), cols = Math.ceil(W / cell), rows = Math.ceil(H / cell), next = rng$1(1729);
261
+ for (let j = 0; j < rows; j++) for (let i = 0; i < cols; i++) {
262
+ const x = i * cell, y = j * cell, density = size * (1 - fade * fadeAt(x, y, fadeAngle));
263
+ if (next() < density) ctx.fillRect(x, y, cell, cell);
264
+ }
265
+ return out;
266
+ }
267
+ const a = layer.angle * Math.PI / 180, c = Math.cos(a), s = Math.sin(a), reach = Math.hypot(W, H) / 2 + scale;
268
+ ctx.beginPath();
269
+ for (let v = -reach; v <= reach; v += scale) {
270
+ if (layer.pattern === "lines") {
271
+ for (let u = -reach; u < reach; u += scale * 2) {
272
+ const mx = W / 2 + (u + scale) * c - v * s, my = H / 2 + (u + scale) * s + v * c, half = scale * size * (1 - fade * fadeAt(mx, my, fadeAngle)) / 2;
273
+ if (half < 0.15) continue;
274
+ const pts = [[u, v - half], [u + scale * 2, v - half], [u + scale * 2, v + half], [u, v + half]].map(([pu, pv]) => [W / 2 + pu * c - pv * s, H / 2 + pu * s + pv * c]);
275
+ ctx.moveTo(pts[0][0], pts[0][1]);
276
+ for (const [px, py] of pts.slice(1)) ctx.lineTo(px, py);
277
+ ctx.closePath();
278
+ }
279
+ continue;
280
+ }
281
+ for (let u = -reach; u <= reach; u += scale) {
282
+ const x = W / 2 + u * c - v * s, y = H / 2 + u * s + v * c;
283
+ if (x < -scale || y < -scale || x > W + scale || y > H + scale) continue;
284
+ const r = scale * 0.6 * size * (1 - fade * fadeAt(x, y, fadeAngle));
285
+ if (r < 0.3) continue;
286
+ ctx.moveTo(x + r, y);
287
+ ctx.arc(x, y, r, 0, Math.PI * 2);
288
+ }
289
+ }
290
+ ctx.fill();
291
+ return out;
292
+ }
293
+ function texturePattern(layer, color, invert) {
294
+ const key = JSON.stringify([layer.pattern, layer.scale, layer.size, layer.angle, layer.fade, layer.fadeAngle, color, invert]);
295
+ let hit = cache.get(key);
296
+ if (hit) {
297
+ cache.delete(key);
298
+ cache.set(key, hit);
299
+ return hit;
300
+ }
301
+ hit = draw(layer, invert ? "#000000" : color);
302
+ if (invert) {
303
+ const inv = canvas(), x = inv.getContext("2d");
304
+ x.fillStyle = "#000000";
305
+ x.fillRect(0, 0, W, H);
306
+ x.globalCompositeOperation = "destination-out";
307
+ x.drawImage(hit, 0, 0);
308
+ hit = inv;
309
+ }
310
+ cache.set(key, hit);
311
+ if (cache.size > MAX_CACHED) cache.delete(cache.keys().next().value);
312
+ return hit;
313
+ }
314
+ function applyTexture(ctx, layer, color) {
315
+ ctx.save();
316
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
317
+ ctx.filter = "none";
318
+ ctx.shadowBlur = 0;
319
+ ctx.globalAlpha = layer.opacity;
320
+ ctx.globalCompositeOperation = layer.mode === "atop" ? "source-atop" : "destination-out";
321
+ ctx.drawImage(texturePattern(layer, color, layer.mode === "keep"), 0, 0);
322
+ ctx.restore();
323
+ }
324
+ const segmenter$1 = typeof Intl !== "undefined" && "Segmenter" in Intl ? new Intl.Segmenter("vi", { granularity: "grapheme" }) : null;
325
+ function graphemes$1(text) {
326
+ const s = String(text ?? "").normalize("NFC");
327
+ if (segmenter$1) return Array.from(segmenter$1.segment(s), (x) => x.segment);
328
+ const out = [];
329
+ for (const ch of Array.from(s)) {
330
+ if (out.length && new RegExp("\\p{M}", "u").test(ch)) out[out.length - 1] += ch;
331
+ else out.push(ch);
332
+ }
333
+ return out;
334
+ }
335
+ function animatorUnits(rows) {
336
+ const units = [];
337
+ let c = 0, cn = -1, w = -1;
338
+ rows.forEach((row, line) => {
339
+ let inWord = false;
340
+ for (const g of graphemes$1(row)) {
341
+ const space = !/\S/u.test(g);
342
+ if (!space) {
343
+ cn++;
344
+ if (!inWord) {
345
+ w++;
346
+ inWord = true;
347
+ }
348
+ } else inWord = false;
349
+ units.push({ row: line, text: g, space, chars: c++, charsNoSpace: Math.max(0, cn), words: Math.max(0, w), lines: line });
350
+ }
351
+ });
352
+ return { units, counts: { chars: c, charsNoSpace: cn + 1, words: w + 1, lines: rows.length } };
353
+ }
354
+ const EASE = { linear: (t) => t, easeIn: (t) => t * t * t, easeOut: (t) => 1 - (1 - t) ** 3, easeInOut: (t) => t < 0.5 ? 4 * t ** 3 : 1 - (-2 * t + 2) ** 3 / 2 };
355
+ function keyAt(keys, t, fallback, loop = false) {
356
+ if (!keys?.length) return fallback;
357
+ if (loop && keys.length > 1) {
358
+ const a = keys[0].time, span = keys.at(-1).time - a;
359
+ if (span > 1e-6 && t > a) t = a + (t - a) % span;
360
+ }
361
+ if (t <= keys[0].time) return keys[0].value;
362
+ for (let i = 1; i < keys.length; i++) {
363
+ const k0 = keys[i - 1], k1 = keys[i];
364
+ if (t <= k1.time) {
365
+ if (k0.ease === "hold") return k0.value;
366
+ const u = (t - k0.time) / Math.max(1e-9, k1.time - k0.time);
367
+ return k0.value + (k1.value - k0.value) * EASE[k0.ease ?? "linear"](u);
368
+ }
369
+ }
370
+ return keys.at(-1).value;
371
+ }
372
+ const rng = (seed) => () => {
373
+ seed |= 0;
374
+ seed = seed + 1831565813 | 0;
375
+ let t = Math.imul(seed ^ seed >>> 15, 1 | seed);
376
+ t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
377
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
378
+ };
379
+ const permCache = /* @__PURE__ */ new Map();
380
+ function randomOrder(n, seed) {
381
+ const key = n + ":" + seed;
382
+ let p = permCache.get(key);
383
+ if (p) return p;
384
+ const next = rng(seed * 7919 + 17);
385
+ p = [...Array(n).keys()];
386
+ for (let i = n - 1; i > 0; i--) {
387
+ const j = Math.floor(next() * (i + 1));
388
+ [p[i], p[j]] = [p[j], p[i]];
389
+ }
390
+ if (permCache.size > 200) permCache.clear();
391
+ permCache.set(key, p);
392
+ return p;
393
+ }
394
+ const clamp01 = (v) => Math.min(1, Math.max(0, v));
395
+ function eased(v, low, high) {
396
+ const l = low / 100, h = high / 100;
397
+ v = l >= 0 ? v ** (1 + 2 * l) : 1 - (1 - v) ** (1 - 2 * l);
398
+ return h >= 0 ? 1 - (1 - v) ** (1 + 2 * h) : v ** (1 - 2 * h);
399
+ }
400
+ function rangeAmount(s, index, count, t) {
401
+ if (count <= 0) return 0;
402
+ const i = s.random ? randomOrder(count, s.seed)[index] : index;
403
+ const k = s.keys || {}, loop = !!s.loop;
404
+ const st = keyAt(k.start, t, s.start, loop) / 100, en = keyAt(k.end, t, s.end, loop) / 100, off = keyAt(k.offset, t, s.offset, loop) / 100, amt = keyAt(k.amount, t, s.amount, loop) / 100;
405
+ const a = Math.min(st, en) + off, b = Math.max(st, en) + off;
406
+ let v;
407
+ if (s.shape === "square") {
408
+ const lo = i / count, hi = (i + 1) / count, cover = clamp01((Math.min(hi, b) - Math.max(lo, a)) * count);
409
+ const sm = s.smoothness / 100;
410
+ v = sm >= 1 ? cover : sm <= 0 ? cover > 0.5 + 1e-9 ? 1 : cover < 0.5 - 1e-9 ? 0 : 0.5 : clamp01((cover - 0.5) / sm + 0.5);
411
+ } else {
412
+ const p = (i + 0.5) / count, span = b - a;
413
+ const u = span > 1e-9 ? (p - a) / span : p < a ? -1 : 2;
414
+ if (s.shape === "rampUp") v = clamp01(u);
415
+ else if (s.shape === "rampDown") v = 1 - clamp01(u);
416
+ else if (u < 0 || u > 1) v = 0;
417
+ else if (s.shape === "triangle") v = 1 - Math.abs(2 * u - 1);
418
+ else if (s.shape === "round") v = Math.sqrt(Math.max(0, 1 - (2 * u - 1) ** 2));
419
+ else v = (1 - Math.cos(2 * Math.PI * u)) / 2;
420
+ }
421
+ if (s.easeHigh || s.easeLow) v = eased(clamp01(v), s.easeLow, s.easeHigh);
422
+ return v * amt;
423
+ }
424
+ const hash = (n, seed) => {
425
+ const x = Math.sin(n * 127.1 + seed * 311.7) * 43758.5453;
426
+ return (x - Math.floor(x)) * 2 - 1;
427
+ };
428
+ const noise1 = (x, seed) => {
429
+ const i = Math.floor(x), f = x - i, s = f * f * (3 - 2 * f);
430
+ return hash(i, seed) * (1 - s) + hash(i + 1, seed) * s;
431
+ };
432
+ function wigglyAmount(s, index, count, t) {
433
+ const x = t * s.wiggles, c = s.correlation / 100;
434
+ const v = c * noise1(x, s.seed) + (1 - c) * noise1(x + index * 3.17, s.seed + 1 + index * 13.7);
435
+ return (s.minAmount + (v + 1) / 2 * (s.maxAmount - s.minAmount)) / 100;
436
+ }
437
+ function selection(animator, unit, counts, t) {
438
+ let v = 0;
439
+ animator.selectors.forEach((s, j) => {
440
+ const n = counts[s.basedOn], i = unit[s.basedOn];
441
+ const a = s.type === "wiggly" ? wigglyAmount(s, i, n, t) : rangeAmount(s, i, n, t);
442
+ v = j === 0 ? a : s.mode === "intersect" ? v * a : s.mode === "subtract" ? v - a : v + a;
443
+ });
444
+ return Math.max(-1, Math.min(1, v));
445
+ }
446
+ const REST_GLYPH = Object.freeze({ x: 0, y: 0, scale: 1, rotate: 0, opacity: 1, tracking: 0, blur: 0, skew: 0, stroke: 0, strokeColor: null, fill: null, fillAmount: 0 });
447
+ const mixHex = (a, b, k) => {
448
+ const p = parseInt(a.slice(1), 16), q = parseInt(b.slice(1), 16);
449
+ return "#" + [16, 8, 0].map((s) => Math.round((p >> s & 255) + ((q >> s & 255) - (p >> s & 255)) * k).toString(16).padStart(2, "0")).join("");
450
+ };
451
+ function animatorPoses(animators, layout, t) {
452
+ const { units, counts } = layout;
453
+ return units.map((u) => {
454
+ const p = { ...REST_GLYPH };
455
+ for (const a of animators) {
456
+ const s = selection(a, u, counts, t);
457
+ if (Math.abs(s) < 1e-6) continue;
458
+ const q = a.properties;
459
+ if (q.x) p.x += q.x * s;
460
+ if (q.y) p.y += q.y * s;
461
+ if (q.rotate) p.rotate += q.rotate * s;
462
+ if (q.tracking) p.tracking += q.tracking * s;
463
+ if (q.blur) p.blur += q.blur * s;
464
+ if (q.skew) p.skew += q.skew * s;
465
+ if (q.stroke) {
466
+ p.stroke += q.stroke * s;
467
+ p.strokeColor = q.strokeColor ?? p.strokeColor ?? "#000000";
468
+ }
469
+ if (q.scale !== void 0) p.scale *= Math.max(0, 1 + (q.scale / 100 - 1) * s);
470
+ if (q.opacity !== void 0) p.opacity *= clamp01(1 + (q.opacity / 100 - 1) * s);
471
+ if (q.fill) {
472
+ const k = clamp01(Math.abs(s));
473
+ p.fill = p.fill ? mixHex(p.fill, q.fill, k) : q.fill;
474
+ p.fillAmount = p.fillAmount + (1 - p.fillAmount) * k;
475
+ }
476
+ }
477
+ p.blur = Math.max(0, p.blur);
478
+ p.stroke = Math.max(0, p.stroke);
479
+ return p;
480
+ });
481
+ }
482
+ const K = (a, b, d, ease2) => [{ time: 0, value: a, ...ease2 ? { ease: ease2 } : {} }, { time: d, value: b }];
483
+ const RAW_PRESETS = {
484
+ // the classic typewriter: characters after Start are hidden; Start runs 0 → 100 %
485
+ "type-on": (d) => [{ name: "Type on", properties: { opacity: 0 }, selectors: [{ basedOn: "chars", shape: "square", smoothness: 0, start: 0, end: 100, keys: { start: K(0, 100, d) } }] }],
486
+ "fade-up-chars": (d) => [{ name: "Fade up", properties: { opacity: 0, y: 18 }, selectors: [{ basedOn: "charsNoSpace", shape: "rampUp", start: 0, end: 25, keys: { offset: K(-25, 100, d, "easeOut") } }] }],
487
+ "cascade-bottom": (d) => [{ name: "Cascade", properties: { y: 160, opacity: 0, rotate: 12 }, selectors: [{ basedOn: "charsNoSpace", shape: "rampUp", start: 0, end: 35, easeHigh: 60, keys: { offset: K(-35, 100, d, "easeOut") } }] }],
488
+ // each word pops: scale up from 0, then a triangle a little behind overshoots it (130 %) as it lands
489
+ "scale-pop-words": (d) => [
490
+ { name: "Pop in", properties: { scale: 0, opacity: 0 }, selectors: [{ basedOn: "words", shape: "rampUp", start: 0, end: 20, keys: { offset: K(-20, 100, d) } }] },
491
+ { name: "Overshoot", properties: { scale: 135 }, selectors: [{ basedOn: "words", shape: "triangle", start: 0, end: 30, keys: { offset: K(-45, 100, d) } }] }
492
+ ],
493
+ "blur-in": (d) => [{ name: "Blur in", properties: { blur: 22, opacity: 0, scale: 125 }, selectors: [{ basedOn: "charsNoSpace", shape: "rampUp", start: 0, end: 40, keys: { offset: K(-40, 100, d, "easeOut") } }] }],
494
+ "tracking-in": (d) => [{ name: "Tracking in", properties: { tracking: 48, opacity: 0 }, selectors: [{ basedOn: "chars", shape: "square", start: 0, end: 100, keys: { amount: K(100, 0, d, "easeOut") } }] }],
495
+ "random-fade": (d) => [{ name: "Random fade", properties: { opacity: 0 }, selectors: [{ basedOn: "charsNoSpace", shape: "square", random: true, seed: 7, start: 0, end: 100, keys: { start: K(0, 100, d) } }] }],
496
+ // a bump of position y travelling along the line, looped (AE: Offset keyed + loopOut)
497
+ "wave": (d) => [{ name: "Wave", properties: { y: -28 }, selectors: [{ basedOn: "chars", shape: "smooth", start: 0, end: 34, loop: true, keys: { offset: K(-34, 100, Math.max(1.2, Math.min(2.4, d * 2))) } }] }]
498
+ };
499
+ Object.freeze(Object.keys(RAW_PRESETS));
500
+ const FRAME = { width: 1280, height: 720 };
501
+ let surface = null;
502
+ const textureSurface = () => surface ??= newCanvas(FRAME.width, FRAME.height);
503
+ function wrapLines(ctx, text) {
504
+ const lines = [];
505
+ for (const paragraph of text.split("\n")) {
506
+ let line = "";
507
+ for (const char of Array.from(paragraph)) {
508
+ if (line && ctx.measureText(line + char).width > 1050) {
509
+ lines.push(line);
510
+ line = "";
511
+ }
512
+ line += char;
513
+ }
514
+ lines.push(line);
515
+ }
516
+ return lines;
517
+ }
518
+ function drawTimelineTitle(ctx, title, frame) {
519
+ if (title.design) {
520
+ if (!title.design.layers.some((l) => l.type === "texture")) return drawDesignedTitle(ctx, title, title.design, frame);
521
+ const s = textureSurface(), sctx = s.getContext("2d");
522
+ sctx.setTransform(1, 0, 0, 1, 0, 0);
523
+ sctx.globalAlpha = 1;
524
+ sctx.globalCompositeOperation = "source-over";
525
+ sctx.clearRect(0, 0, FRAME.width, FRAME.height);
526
+ drawDesignedTitle(sctx, title, title.design, frame);
527
+ ctx.drawImage(s, 0, 0);
528
+ return;
529
+ }
530
+ const { text, fontSize, color, placement, fontFamily = "Arial", align = "center", styleId = "classic", accentColor = "#32d8cd" } = title;
531
+ const display = styleId !== "classic", weight = display ? 800 : 600;
532
+ ctx.font = `${weight} ${fontSize}px "${fontFamily}", sans-serif`;
533
+ ctx.textAlign = align;
534
+ ctx.textBaseline = "middle";
535
+ const lines = wrapLines(ctx, text);
536
+ const lineHeight = fontSize * (display ? 1.12 : 1.3);
537
+ if (lines.length * lineHeight > 560) throw Error("Text is too long for the frame; reduce copy or font size");
538
+ const height = lines.length * lineHeight, y = placement === "top" ? 80 + height / 2 : placement === "lower" ? 640 - height / 2 : 360;
539
+ lines.forEach((line, i) => {
540
+ const x = align === "left" ? 90 : align === "right" ? 1190 : 640, baseline = y + (i - (lines.length - 1) / 2) * lineHeight;
541
+ const width = ctx.measureText(line).width;
542
+ ctx.save();
543
+ if (styleId === "accent-bar") {
544
+ const left = align === "left" ? x - 18 : align === "right" ? x - width - 18 : x - width / 2 - 18;
545
+ ctx.fillStyle = accentColor;
546
+ ctx.beginPath();
547
+ ctx.roundRect(left, baseline - fontSize * 0.56, width + 36, fontSize * 1.12, 10);
548
+ ctx.fill();
549
+ }
550
+ if (styleId === "tape-label") {
551
+ const pad = fontSize * 0.45, w = width + pad * 2, h = fontSize * 1.32, cx = align === "left" ? x + width / 2 : align === "right" ? x - width / 2 : x, tilt = (i % 2 ? 1 : -1) * 0.028, teeth = 6;
552
+ ctx.save();
553
+ ctx.translate(cx, baseline);
554
+ ctx.rotate(tilt);
555
+ ctx.beginPath();
556
+ ctx.moveTo(-w / 2, -h / 2);
557
+ ctx.lineTo(w / 2, -h / 2);
558
+ for (let k = 1; k <= teeth; k++) ctx.lineTo(w / 2 + (k % 2 ? fontSize * 0.07 : 0), -h / 2 + h * k / teeth);
559
+ ctx.lineTo(-w / 2, h / 2);
560
+ for (let k = teeth - 1; k >= 0; k--) ctx.lineTo(-w / 2 - (k % 2 ? fontSize * 0.07 : 0), -h / 2 + h * k / teeth);
561
+ ctx.closePath();
562
+ ctx.shadowColor = "rgba(0,0,0,0.22)";
563
+ ctx.shadowBlur = fontSize * 0.12;
564
+ ctx.shadowOffsetY = fontSize * 0.04;
565
+ ctx.globalAlpha = 0.94;
566
+ ctx.fillStyle = accentColor;
567
+ ctx.fill();
568
+ ctx.shadowColor = "transparent";
569
+ ctx.globalAlpha = 0.07;
570
+ ctx.strokeStyle = "#5a4a30";
571
+ ctx.lineWidth = 1;
572
+ for (let k = 1; k < 5; k++) {
573
+ const yy = -h / 2 + h * k / 5;
574
+ ctx.beginPath();
575
+ ctx.moveTo(-w / 2, yy);
576
+ ctx.lineTo(w / 2, yy + (k % 2 ? 1.5 : -1.5));
577
+ ctx.stroke();
578
+ }
579
+ ctx.restore();
580
+ ctx.save();
581
+ ctx.translate(cx, baseline);
582
+ ctx.rotate(tilt);
583
+ ctx.translate(-cx, -baseline);
584
+ }
585
+ if (styleId === "echo-stack") {
586
+ ctx.fillStyle = accentColor;
587
+ ctx.globalAlpha = 0.82;
588
+ ctx.fillText(line, x + 13, baseline + 13);
589
+ ctx.globalAlpha = 1;
590
+ }
591
+ if (styleId === "outline-punch") {
592
+ ctx.lineWidth = Math.max(4, fontSize * 0.11);
593
+ ctx.lineJoin = "round";
594
+ ctx.strokeStyle = accentColor;
595
+ ctx.strokeText(line, x, baseline);
596
+ }
597
+ if (styleId === "neon-edge") {
598
+ ctx.shadowColor = accentColor;
599
+ ctx.shadowBlur = 25;
600
+ ctx.strokeStyle = accentColor;
601
+ ctx.lineWidth = Math.max(3, fontSize * 0.07);
602
+ ctx.lineJoin = "round";
603
+ ctx.strokeText(line, x, baseline);
604
+ ctx.shadowBlur = 12;
605
+ }
606
+ if (styleId === "classic") {
607
+ ctx.shadowColor = "#000000";
608
+ ctx.shadowBlur = 8;
609
+ }
610
+ ctx.fillStyle = styleId === "duotone-stack" && i % 2 ? accentColor : color;
611
+ ctx.fillText(line, x, baseline);
612
+ if (styleId === "tape-label") ctx.restore();
613
+ if (styleId === "duotone-stack" && i === lines.length - 1) {
614
+ const left = align === "left" ? x : align === "right" ? x - width : x - width / 2;
615
+ ctx.fillStyle = accentColor;
616
+ ctx.fillRect(left, baseline + fontSize * 0.55, Math.min(width, 760), Math.max(4, fontSize * 0.07));
617
+ }
618
+ ctx.restore();
619
+ });
620
+ }
621
+ const segmenter = typeof Intl !== "undefined" && "Segmenter" in Intl ? new Intl.Segmenter("vi", { granularity: "grapheme" }) : null;
622
+ const graphemes = (text) => segmenter ? Array.from(segmenter.segment(text), (s) => s.segment) : Array.from(text);
623
+ function darken(hex, brightness) {
624
+ if (brightness >= 0.999 || !/^#[0-9a-f]{6}$/i.test(hex)) return hex;
625
+ const n = parseInt(hex.slice(1), 16), f = Math.max(0, brightness);
626
+ return `rgb(${Math.round((n >> 16 & 255) * f)},${Math.round((n >> 8 & 255) * f)},${Math.round((n & 255) * f)})`;
627
+ }
628
+ function mix(hex, to, k) {
629
+ if (!/^#[0-9a-f]{6}$/i.test(hex)) return hex;
630
+ const n = parseInt(hex.slice(1), 16);
631
+ return "#" + [n >> 16 & 255, n >> 8 & 255, n & 255].map((v) => Math.round(v + (to - v) * k).toString(16).padStart(2, "0")).join("");
632
+ }
633
+ const ruleEnds = (hex) => {
634
+ if (!/^#[0-9a-f]{6}$/i.test(hex)) return [hex, hex];
635
+ const g = autoFill(hex.toLowerCase()).gradient;
636
+ return [g[0], g.at(-1)];
637
+ };
638
+ function gradientIn(ctx, fill, left, top, width, h, colour) {
639
+ const cx = left + width / 2, cy = top + h / 2;
640
+ let g;
641
+ if (fill.type === "radial") g = ctx.createRadialGradient(cx, cy, 0, cx, cy, Math.max(width, h) / 2);
642
+ else {
643
+ const rad = (fill.angle ?? 90) * Math.PI / 180, dx = Math.cos(rad) * width / 2, dy = Math.sin(rad) * h / 2;
644
+ g = ctx.createLinearGradient(cx - dx, cy - dy, cx + dx, cy + dy);
645
+ }
646
+ fill.gradient.forEach((stop, i) => g.addColorStop(fill.stops?.[i] ?? i / (fill.gradient.length - 1), colour(stop)));
647
+ return g;
648
+ }
649
+ const mainPaint = (fill) => typeof fill === "string" ? fill : fill.type === "radial" ? fill.gradient[0] : fill.gradient.at(-1);
650
+ const rgba = (hex, a) => {
651
+ if (!/^#[0-9a-f]{6}$/i.test(hex)) return `rgba(255,255,255,${a})`;
652
+ const n = parseInt(hex.slice(1), 16);
653
+ return `rgba(${n >> 16 & 255},${n >> 8 & 255},${n & 255},${a})`;
654
+ };
655
+ function fontFor(design, size, family, style) {
656
+ const stretch = style?.stretch ?? design.stretch;
657
+ return `${style?.italic ? "italic " : ""}${style?.weight ?? design.weight} ${stretch && stretch !== "normal" ? stretch + " " : ""}${size}px "${style?.font ?? family}", sans-serif`;
658
+ }
659
+ function setFont(ctx, design, size, family, style) {
660
+ ctx.font = fontFor(design, size, family, style);
661
+ if ("letterSpacing" in ctx) ctx.letterSpacing = `${((style?.tracking ?? design.tracking ?? 0) * size).toFixed(2)}px`;
662
+ }
663
+ const noise = (n) => {
664
+ const x = Math.sin(n * 127.1 + 311.7) * 43758.5453;
665
+ return x - Math.floor(x);
666
+ };
667
+ function layoutDesigned(ctx, title, design, text) {
668
+ const { fontSize, placement, fontFamily = "Arial", align = "center" } = title;
669
+ const ink = design.stack === "ink";
670
+ ctx.textBaseline = ink ? "alphabetic" : "middle";
671
+ ctx.textAlign = "left";
672
+ const fit = !!design.lines, maxW = design.maxWidth ? design.maxWidth * FRAME.width : 1050;
673
+ const extras = !!design.lines?.some((l) => l.side || l.x || l.y || l.align);
674
+ const place = (k2) => {
675
+ const out = [];
676
+ const paras = text.split("\n");
677
+ paras.forEach((paragraph, index) => {
678
+ const style = lineStyleAt(design, index, paras.length);
679
+ let size = fontSize * (style?.scale ?? 1) * k2;
680
+ setFont(ctx, design, size, fontFamily, style);
681
+ if (fit) {
682
+ const cap = extras ? maxW * k2 : maxW, w = ctx.measureText(paragraph || " ").width;
683
+ if (w > cap) {
684
+ size *= cap / w;
685
+ setFont(ctx, design, size, fontFamily, style);
686
+ }
687
+ }
688
+ const wrapped = [];
689
+ let line = "";
690
+ if (fit) wrapped.push(paragraph);
691
+ else if (design.wrap === "word") {
692
+ for (const word of paragraph.split(/(\s+)/)) {
693
+ if (line && line.trim() && ctx.measureText(line + word).width > maxW && word.trim()) {
694
+ wrapped.push(line.trimEnd());
695
+ line = "";
696
+ }
697
+ if (!line && !word.trim()) continue;
698
+ if (ctx.measureText(word).width > maxW) {
699
+ for (const char of graphemes(word)) {
700
+ if (line && ctx.measureText(line + char).width > maxW) {
701
+ wrapped.push(line);
702
+ line = "";
703
+ }
704
+ line += char;
705
+ }
706
+ } else line += word;
707
+ }
708
+ wrapped.push(line.trimEnd());
709
+ } else {
710
+ for (const char of graphemes(paragraph)) {
711
+ if (line && ctx.measureText(line + char).width > maxW) {
712
+ wrapped.push(line);
713
+ line = "";
714
+ }
715
+ line += char;
716
+ }
717
+ wrapped.push(line);
718
+ }
719
+ for (const part of wrapped) {
720
+ const m = ctx.measureText(part || " ");
721
+ out.push({ text: part, paragraph: index, size, fill: style?.fill, style, width: m.width, left: 0, center: 0, ascent: ink ? m.actualBoundingBoxAscent : size * 0.56, descent: ink ? m.actualBoundingBoxDescent : size * 0.56 });
722
+ }
723
+ });
724
+ const heights = out.map((r) => ink ? r.ascent + r.descent : r.size * design.lineHeight);
725
+ const gaps = out.map((r) => ink ? (design.gap ?? 0.08) * r.size : 0);
726
+ const side = (r) => !!r.style?.side;
727
+ const main = out.map((_, i) => i).filter((i) => !side(out[i]));
728
+ let total = 0;
729
+ main.forEach((i, j) => {
730
+ total += heights[i] + (j ? gaps[i] : 0);
731
+ });
732
+ const top = (placement === "top" ? 80 : placement === "lower" ? 640 - total : FRAME.height / 2 - total / 2) + (design.shiftY ?? 0) * FRAME.height;
733
+ const ax = (align === "left" ? 90 : align === "right" ? 1190 : FRAME.width / 2) + (design.shiftX ?? 0) * FRAME.width;
734
+ const blockW = Math.max(0, ...main.map((i) => out[i].width)), bx = align === "left" ? ax : align === "right" ? ax - blockW : ax - blockW / 2;
735
+ let cursor = top;
736
+ main.forEach((i, j) => {
737
+ const r = out[i];
738
+ if (j) cursor += gaps[i];
739
+ r.center = cursor + heights[i] / 2;
740
+ cursor += heights[i];
741
+ const a = r.style?.align ?? align;
742
+ r.left = a === "left" ? bx : a === "right" ? bx + blockW - r.width : bx + (blockW - r.width) / 2;
743
+ });
744
+ if (!extras) return { rows: out, heights, gaps, total, box: { x: bx, y: top, w: blockW, h: total }, extras, ink };
745
+ const em = fontSize * k2;
746
+ for (const r of out) {
747
+ if (side(r)) {
748
+ r.center = top + total / 2;
749
+ r.left = r.style.side === "left" ? bx - 0.12 * em - r.width : bx + blockW + 0.12 * em;
750
+ }
751
+ r.left += (r.style?.x ?? 0) * em;
752
+ r.center += (r.style?.y ?? 0) * em;
753
+ }
754
+ const x0 = Math.min(...out.map((r) => r.left)), x1 = Math.max(...out.map((r) => r.left + r.width));
755
+ const y0 = Math.min(...out.map((r, i) => r.center - heights[i] / 2)), y1 = Math.max(...out.map((r, i) => r.center + heights[i] / 2));
756
+ const dx = align === "left" ? ax - x0 : align === "right" ? ax - x1 : ax - (x0 + x1) / 2;
757
+ const dy = (placement === "top" ? 80 : placement === "lower" ? 640 - (y1 - y0) : FRAME.height / 2 - (y1 - y0) / 2) + (design.shiftY ?? 0) * FRAME.height - y0;
758
+ for (const r of out) {
759
+ r.left += dx;
760
+ r.center += dy;
761
+ }
762
+ return { rows: out, heights, gaps, total, box: { x: x0 + dx, y: y0 + dy, w: x1 - x0, h: y1 - y0 }, extras, ink };
763
+ };
764
+ let laid = place(1), k = 1;
765
+ for (let i = 0; i < 4; i++) {
766
+ const h = laid.extras ? laid.box.h : laid.total, over = Math.max(h / 560, laid.extras ? laid.box.w / maxW : 0);
767
+ if (over <= 1) break;
768
+ k *= 0.98 / over;
769
+ laid = place(k);
770
+ }
771
+ if ((laid.extras ? laid.box.h : laid.total) > 560) throw Error("Text is too long for the frame; reduce copy or font size");
772
+ return laid;
773
+ }
774
+ const displayText = (title, design) => (design.uppercase ? title.text.toLocaleUpperCase("vi") : title.text).normalize("NFC");
775
+ function swashPath(ctx, left, y, w, h, size) {
776
+ const P = [[left, y + size * 0.1], [left + w * 0.55, y + size * 0.2], [left + w, y - size * 0.26]], N2 = 28, top = [], bottom = [];
777
+ for (let i = 0; i <= N2; i++) {
778
+ const t = i / N2, a = (1 - t) * (1 - t), b = 2 * (1 - t) * t, c = t * t;
779
+ const x = a * P[0][0] + b * P[1][0] + c * P[2][0], yy = a * P[0][1] + b * P[1][1] + c * P[2][1];
780
+ const dx = 2 * (1 - t) * (P[1][0] - P[0][0]) + 2 * t * (P[2][0] - P[1][0]), dy = 2 * (1 - t) * (P[1][1] - P[0][1]) + 2 * t * (P[2][1] - P[1][1]), len = Math.hypot(dx, dy) || 1;
781
+ const th = h * Math.pow(Math.sin(Math.PI * t), 0.55) * (1.25 - 0.55 * t) / 2;
782
+ top.push([x - dy / len * th, yy + dx / len * th]);
783
+ bottom.push([x + dy / len * th, yy - dx / len * th]);
784
+ }
785
+ ctx.beginPath();
786
+ ctx.moveTo(top[0][0], top[0][1]);
787
+ for (const p of top.slice(1)) ctx.lineTo(p[0], p[1]);
788
+ for (const p of bottom.reverse()) ctx.lineTo(p[0], p[1]);
789
+ ctx.closePath();
790
+ }
791
+ function applyLayerMotion(ctx, p, rect, origin, size) {
792
+ ctx.globalAlpha *= Math.min(1, Math.max(0, p.opacity));
793
+ if (ctx.globalAlpha < 2e-3) return false;
794
+ const m = size * 0.3;
795
+ if (p.wipeX < 1) {
796
+ const w = (rect.w + 2 * m) * Math.max(0, p.wipeX);
797
+ ctx.beginPath();
798
+ ctx.rect(origin === "right" ? rect.x + rect.w + m - w : rect.x - m, rect.y - size * 2, w, rect.h + size * 4);
799
+ ctx.clip();
800
+ }
801
+ if (p.wipeY < 1) {
802
+ const h = (rect.h + 2 * m) * Math.max(0, p.wipeY);
803
+ ctx.beginPath();
804
+ ctx.rect(rect.x - size * 2, origin === "bottom" ? rect.y + rect.h + m - h : rect.y - m, rect.w + size * 4, h);
805
+ ctx.clip();
806
+ }
807
+ const ox = origin === "left" ? rect.x : origin === "right" ? rect.x + rect.w : rect.x + rect.w / 2, oy = origin === "top" ? rect.y : origin === "bottom" ? rect.y + rect.h : rect.y + rect.h / 2;
808
+ ctx.translate(ox + p.x * size, oy + p.y * size);
809
+ ctx.rotate(p.rotate * Math.PI / 180);
810
+ ctx.scale(p.scale * p.scaleX, p.scale * p.scaleY);
811
+ ctx.translate(-ox, -oy);
812
+ return true;
813
+ }
814
+ const scratch = [];
815
+ function scratchCtx(i, w, h) {
816
+ let c = scratch[i];
817
+ if (!c || c.width !== w || c.height !== h) {
818
+ c = typeof document !== "undefined" ? Object.assign(document.createElement("canvas"), { width: w, height: h }) : new OffscreenCanvas(w, h);
819
+ scratch[i] = c;
820
+ }
821
+ return c.getContext("2d");
822
+ }
823
+ function innerGlowText(ctx, text, color, blurPx) {
824
+ const W2 = ctx.canvas.width, H2 = ctx.canvas.height, m = ctx.getTransform(), a = scratchCtx(0, W2, H2), b = scratchCtx(1, W2, H2);
825
+ const same = (c) => {
826
+ c.font = ctx.font;
827
+ c.textAlign = ctx.textAlign;
828
+ c.textBaseline = ctx.textBaseline;
829
+ const o = c, src = ctx;
830
+ for (const k of ["letterSpacing", "fontStretch", "fontKerning"]) if (k in src) o[k] = src[k];
831
+ };
832
+ a.setTransform(1, 0, 0, 1, 0, 0);
833
+ a.globalCompositeOperation = "source-over";
834
+ a.clearRect(0, 0, W2, H2);
835
+ a.fillStyle = color;
836
+ a.fillRect(0, 0, W2, H2);
837
+ a.setTransform(m);
838
+ same(a);
839
+ a.globalCompositeOperation = "destination-out";
840
+ a.fillStyle = "#000";
841
+ text(a);
842
+ b.setTransform(1, 0, 0, 1, 0, 0);
843
+ b.globalCompositeOperation = "source-over";
844
+ b.clearRect(0, 0, W2, H2);
845
+ b.filter = `blur(${Math.max(0.5, blurPx).toFixed(1)}px)`;
846
+ b.drawImage(a.canvas, 0, 0);
847
+ b.filter = "none";
848
+ b.setTransform(m);
849
+ same(b);
850
+ b.globalCompositeOperation = "destination-in";
851
+ b.fillStyle = "#000";
852
+ text(b);
853
+ ctx.save();
854
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
855
+ ctx.shadowColor = "transparent";
856
+ ctx.filter = "none";
857
+ ctx.drawImage(b.canvas, 0, 0);
858
+ ctx.restore();
859
+ }
860
+ function drawPathTitle(ctx, title, design, text, resolve, frame) {
861
+ const { fontSize, fontFamily = "Arial" } = title, style = lineStyleAt(design, 0, 1), size = fontSize * (style?.scale ?? 1);
862
+ setFont(ctx, design, size, fontFamily, style);
863
+ const chars = graphemes(text.replace(/\s*\n\s*/g, " ")), widths = chars.map((c) => ctx.measureText(c).width);
864
+ const t = frame ? frame.time : 0, at = placeLetters(design.path, widths, t, FRAME), n = chars.length;
865
+ const typeOn = frame && title.animation ? Math.min(0.8, Math.max(0.1, frame.duration * 0.4)) : 0;
866
+ const paintOf = (fill) => {
867
+ if (typeof fill === "string") return resolve(fill);
868
+ const h = size * 0.5, a = (fill.angle ?? 90) * Math.PI / 180, dx = Math.cos(a) * h, dy = Math.sin(a) * h;
869
+ const g = fill.type === "radial" ? ctx.createRadialGradient(0, 0, 0, 0, 0, size * 0.6) : ctx.createLinearGradient(-dx, -dy, dx, dy);
870
+ fill.gradient.forEach((c, i) => g.addColorStop(fill.stops?.[i] ?? i / Math.max(1, fill.gradient.length - 1), resolve(c)));
871
+ return g;
872
+ };
873
+ ctx.textAlign = "center";
874
+ ctx.textBaseline = "middle";
875
+ const poses = frame && title.animators?.length ? animatorPoses(title.animators, animatorUnits([chars.join("")]), frame.time) : null;
876
+ for (const layer of design.layers) {
877
+ if (layer.type !== "text") continue;
878
+ ctx.save();
879
+ ctx.globalAlpha = layer.opacity;
880
+ if (layer.shadow) {
881
+ ctx.shadowColor = resolve(layer.shadow.color);
882
+ ctx.shadowBlur = layer.shadow.blur * size;
883
+ ctx.shadowOffsetX = layer.shadow.x * size;
884
+ ctx.shadowOffsetY = layer.shadow.y * size;
885
+ }
886
+ const ox = (layer.offset?.x || 0) * size, oy = (layer.offset?.y || 0) * size;
887
+ chars.forEach((ch, i) => {
888
+ const q = at[i];
889
+ if (!q.visible || !ch.trim()) return;
890
+ const a = typeOn ? Math.min(1, Math.max(0, (t - i / Math.max(1, n) * typeOn) / 0.15)) : 1;
891
+ if (a <= 0) return;
892
+ const p = poses?.[i];
893
+ if (p && (p.opacity <= 2e-3 || p.scale <= 1e-4)) return;
894
+ ctx.save();
895
+ ctx.globalAlpha *= a;
896
+ ctx.translate(q.x + ox, q.y + oy);
897
+ ctx.rotate(q.angle);
898
+ const glyph = () => {
899
+ if (layer.stroke) {
900
+ ctx.strokeStyle = resolve(layer.stroke.color);
901
+ ctx.lineWidth = Math.max(1.5, layer.stroke.width * size);
902
+ ctx.strokeText(ch, 0, 0);
903
+ }
904
+ ctx.fillStyle = paintOf(layer.fill);
905
+ ctx.fillText(ch, 0, 0);
906
+ };
907
+ if (p) drawGlyph(ctx, p, 0, 0, glyph, (m) => m === "fill" ? ctx.fillText(ch, 0, 0) : ctx.strokeText(ch, 0, 0));
908
+ else glyph();
909
+ ctx.restore();
910
+ });
911
+ ctx.restore();
912
+ }
913
+ }
914
+ const glyphCache = /* @__PURE__ */ new Map();
915
+ function glyphX(ctx, text, gs) {
916
+ const key = ctx.font + "|" + (ctx.letterSpacing ?? "") + "|" + text;
917
+ let xs = glyphCache.get(key);
918
+ if (!xs) {
919
+ let pre = "";
920
+ xs = [0];
921
+ for (const g of gs) {
922
+ pre += g;
923
+ xs.push(ctx.measureText(pre).width);
924
+ }
925
+ if (glyphCache.size > 400) glyphCache.clear();
926
+ glyphCache.set(key, xs);
927
+ }
928
+ return xs;
929
+ }
930
+ function drawGlyph(ctx, p, cx, cy, draw2, paint) {
931
+ ctx.globalAlpha *= p.opacity;
932
+ ctx.translate(cx + p.x, cy + p.y);
933
+ if (p.rotate) ctx.rotate(p.rotate * Math.PI / 180);
934
+ if (p.skew) ctx.transform(1, 0, Math.tan(-p.skew * Math.PI / 180), 1, 0, 0);
935
+ if (p.scale !== 1) ctx.scale(p.scale, p.scale);
936
+ ctx.translate(-cx, -cy);
937
+ if (p.blur > 0.05) ctx.filter = `blur(${p.blur.toFixed(1)}px)`;
938
+ if (p.stroke > 0.05 && p.strokeColor) {
939
+ ctx.save();
940
+ ctx.lineWidth = p.stroke * 2;
941
+ ctx.lineJoin = "round";
942
+ ctx.strokeStyle = p.strokeColor;
943
+ paint("stroke");
944
+ ctx.restore();
945
+ }
946
+ draw2();
947
+ if (p.fill && p.fillAmount > 2e-3) {
948
+ ctx.save();
949
+ ctx.shadowColor = "transparent";
950
+ ctx.globalAlpha *= p.fillAmount;
951
+ ctx.fillStyle = p.fill;
952
+ paint("fill");
953
+ ctx.restore();
954
+ }
955
+ }
956
+ function drawDesignedTitle(ctx, title, design, frame) {
957
+ const { fontSize, color, fontFamily = "Arial", align = "center", accentColor = "#dfff00" } = title;
958
+ const text = displayText(title, design);
959
+ const resolve = (paint) => paint === "{color}" ? color : paint === "{accent}" ? accentColor : paint === "{accent-hi}" ? mix(accentColor, 255, 0.5) : paint === "{accent-lo}" ? mix(accentColor, 0, 0.45) : paint === "{accent-bright}" ? ruleEnds(accentColor)[0] : paint === "{accent-deep}" ? ruleEnds(accentColor)[1] : paint === "{color-lo}" ? mix(color, 0, 0.45) : paint === "transparent" ? "rgba(0,0,0,0)" : paint;
960
+ ctx.lineJoin = "round";
961
+ if (design.path) {
962
+ drawPathTitle(ctx, title, design, text, resolve, frame);
963
+ return;
964
+ }
965
+ const { rows, heights, total, box, extras, ink } = layoutDesigned(ctx, title, design, text);
966
+ const baseline = (r) => ink ? r.center + (r.ascent - r.descent) / 2 : r.center;
967
+ const band = (ri) => ink ? heights[ri] : rows[ri].size * 1.12;
968
+ const paragraphs = Math.max(...rows.map((r) => r.paragraph)) + 1;
969
+ const anim = frame && title.animation ? title.animation : void 0;
970
+ const layout = anim ? Array.from({ length: paragraphs }, (_, p) => {
971
+ const t = rows.filter((r) => r.paragraph === p).map((r) => r.text).join(" ");
972
+ return { word: Math.max(1, t.split(/\s+/).filter(Boolean).length), char: Math.max(1, graphemes(t.replace(/\s/g, "")).length) };
973
+ }) : [];
974
+ const clock = anim && frame ? animationClock(anim, layout, frame.time, frame.duration, designMotionEnd(design, rows.length)) : frame ? frame.time : 1e6;
975
+ const rest = { ...REST_POSE, masked: false };
976
+ const pose = (kind, p, i, n) => anim ? levelPose(anim, kind, p, i, n, clock) : rest;
977
+ const paintFor = (fill, left, top, width, h, brightness) => {
978
+ if (typeof fill === "string") return darken(resolve(fill), brightness);
979
+ return gradientIn(ctx, fill, left, top, width, h, (p) => darken(resolve(p), brightness));
980
+ };
981
+ let glitch = 0;
982
+ const applyPose = (p, cx, cy, halfH, size, left = cx - 4e3, width = 8e3) => {
983
+ ctx.globalAlpha *= Math.min(1, Math.max(0, p.opacity));
984
+ if (p.flicker > 0 && noise(Math.floor(clock * 24) + cx * 0.01) < p.flicker) ctx.globalAlpha = 0;
985
+ if (p.reveal < 1 || p.masked) {
986
+ const h = Math.max(0, halfH * p.reveal);
987
+ ctx.beginPath();
988
+ ctx.rect(-4e3, cy - h, 8e3, h * 2);
989
+ ctx.clip();
990
+ }
991
+ if (p.wipeX < 1) {
992
+ ctx.beginPath();
993
+ ctx.rect(left - size * 0.1, cy - halfH * 1.6, (width + size * 0.2) * Math.max(0, p.wipeX), halfH * 3.2);
994
+ ctx.clip();
995
+ }
996
+ if (p.wipeY < 1) {
997
+ ctx.beginPath();
998
+ ctx.rect(-4e3, cy - halfH * 1.2, 8e3, halfH * 2.4 * Math.max(0, p.wipeY));
999
+ ctx.clip();
1000
+ }
1001
+ const jitter = p.glitch > 0 ? p.glitch * size * 0.35 * (noise(Math.floor(clock * 18) + cy * 0.01) * 2 - 1) : 0;
1002
+ glitch = Math.max(glitch, p.glitch);
1003
+ ctx.translate(cx + p.x * size + jitter, cy + p.y * size);
1004
+ ctx.rotate(p.rotate * Math.PI / 180);
1005
+ ctx.scale(p.scale * p.scaleX, p.scale * p.scaleY);
1006
+ ctx.translate(-cx, -cy);
1007
+ if (p.blur > 0) ctx.filter = `blur(${(p.blur * size).toFixed(1)}px)`;
1008
+ return p.brightness;
1009
+ };
1010
+ const unitsOf = (r) => {
1011
+ setFont(ctx, design, r.size, fontFamily, r.style);
1012
+ const before = rows.filter((o) => o.paragraph === r.paragraph && rows.indexOf(o) < rows.indexOf(r));
1013
+ let charBase = graphemes(before.map((o) => o.text).join("").replace(/\s/g, "")).length, wordBase = before.map((o) => o.text).join(" ").split(/\s+/).filter(Boolean).length;
1014
+ const chars = [];
1015
+ let word = wordBase - 1, prevSpace = true, prefix = "";
1016
+ for (const g of graphemes(r.text)) {
1017
+ const x = ctx.measureText(prefix).width;
1018
+ prefix += g;
1019
+ if (/\s/.test(g)) {
1020
+ prevSpace = true;
1021
+ continue;
1022
+ }
1023
+ if (prevSpace) {
1024
+ word++;
1025
+ prevSpace = false;
1026
+ }
1027
+ chars.push({ text: g, x: r.left + x, w: ctx.measureText(prefix).width - x, char: charBase++, word });
1028
+ }
1029
+ return chars;
1030
+ };
1031
+ const perUnit = (p, kind) => !!anim?.in.some((t) => t.unit === kind && (!t.lines || t.lines.includes(p)));
1032
+ const layoutOf = (p) => layout[p] || { word: 1, char: 1 };
1033
+ const paraWords = Array.from({ length: paragraphs }, (_, p) => rows.filter((r) => r.paragraph === p).map((r) => r.text).join(" ").split(/\s+/).filter(Boolean).length);
1034
+ const wordStart = (p) => paraWords.slice(0, p).reduce((a, b) => a + b, 0);
1035
+ const rowAlign = (r) => r.style?.align ?? align;
1036
+ const animators = frame && title.animators?.length ? title.animators : null;
1037
+ const glyphs = animators ? animatorUnits(rows.map((r) => r.text)) : null;
1038
+ const poses = animators && glyphs ? animatorPoses(animators, glyphs, frame.time) : null;
1039
+ const rowFirst = [];
1040
+ if (glyphs) {
1041
+ let k = 0;
1042
+ for (let i = 0; i < rows.length; i++) {
1043
+ rowFirst.push(k);
1044
+ k += graphemes(rows[i].text).length;
1045
+ }
1046
+ }
1047
+ for (const layer of design.layers) {
1048
+ if (layer.type === "texture") {
1049
+ applyTexture(ctx, layer, resolve(layer.color));
1050
+ continue;
1051
+ }
1052
+ if (layer.type === "shape" || layer.type === "icon") {
1053
+ ctx.save();
1054
+ drawDecor(ctx, layer, clock, resolve);
1055
+ ctx.restore();
1056
+ continue;
1057
+ }
1058
+ ctx.save();
1059
+ ctx.globalAlpha = layer.opacity;
1060
+ if (layer.type === "box" && layer.per === "block") {
1061
+ const first = rows[0], lp = pose("line", first.paragraph, first.paragraph, paragraphs), padX = layer.padX * fontSize, padY = layer.padY * fontSize;
1062
+ const left = (extras ? box.x : Math.min(...rows.map((r) => r.left))) - padX, topY = (extras ? box.y : rows[0].center - band(0) / 2) - padY, width = (extras ? box.w : Math.max(...rows.map((r) => r.width))) + padX * 2;
1063
+ const h = (extras ? box.h : total - (heights[0] - band(0)) / 2 - (heights.at(-1) - band(rows.length - 1)) / 2) + padY * 2;
1064
+ const b = applyPose(lp, left + width / 2, topY + h / 2, h / 2, fontSize);
1065
+ if (!layer.motion || applyLayerMotion(ctx, layerPose(layer.motion, clock), { x: left, y: topY, w: width, h }, layer.motion.origin, fontSize)) {
1066
+ if (layer.skewX) {
1067
+ ctx.translate(left + width / 2, topY + h / 2);
1068
+ ctx.transform(1, 0, Math.tan(-layer.skewX * Math.PI / 180), 1, 0, 0);
1069
+ ctx.translate(-left - width / 2, -topY - h / 2);
1070
+ }
1071
+ if (layer.shadow) {
1072
+ ctx.shadowColor = resolve(layer.shadow.color);
1073
+ ctx.shadowBlur = layer.shadow.blur * fontSize;
1074
+ ctx.shadowOffsetX = layer.shadow.x * fontSize;
1075
+ ctx.shadowOffsetY = layer.shadow.y * fontSize;
1076
+ }
1077
+ ctx.fillStyle = paintFor(layer.fill, left, topY, width, h, b);
1078
+ ctx.beginPath();
1079
+ ctx.roundRect(left, topY, width, h, layer.radius * fontSize);
1080
+ ctx.fill();
1081
+ if (layer.stroke) {
1082
+ ctx.strokeStyle = darken(resolve(layer.stroke.color), b);
1083
+ ctx.lineWidth = Math.max(1.5, layer.stroke.width * fontSize);
1084
+ ctx.stroke();
1085
+ }
1086
+ }
1087
+ ctx.restore();
1088
+ continue;
1089
+ }
1090
+ const on = rows.map((r, ri) => layer.lines ? layer.lines.includes(r.paragraph) : layer.type === "underline" ? layer.line === "all" || ri === rows.length - 1 : true);
1091
+ let rank2 = 0;
1092
+ for (const [ri, r] of rows.entries()) {
1093
+ if (!on[ri]) continue;
1094
+ const order = rank2++;
1095
+ ctx.save();
1096
+ const cx = r.left + r.width / 2;
1097
+ if (r.style?.rotate) {
1098
+ ctx.translate(cx, r.center);
1099
+ ctx.rotate(r.style.rotate * Math.PI / 180);
1100
+ ctx.translate(-cx, -r.center);
1101
+ }
1102
+ const lp = pose("line", r.paragraph, r.paragraph, paragraphs);
1103
+ glitch = 0;
1104
+ const lineBright = applyPose(lp, cx, r.center, heights[ri] / 2 + r.size * 0.1, r.size, r.left, r.width);
1105
+ const moved = (rect) => !layer.motion || applyLayerMotion(ctx, layerPose(layer.motion, clock - (layer.motion.stagger ?? 0) * order), rect, layer.motion.origin, r.size);
1106
+ if (layer.type === "box") {
1107
+ const padX = layer.padX * r.size, padY = layer.padY * r.size, left = r.left - padX, topY = r.center - band(ri) / 2 - padY, w = r.width + padX * 2, h = band(ri) + padY * 2;
1108
+ if (moved({ x: left, y: topY, w, h })) {
1109
+ if (layer.skewX) {
1110
+ ctx.translate(left + w / 2, topY + h / 2);
1111
+ ctx.transform(1, 0, Math.tan(-layer.skewX * Math.PI / 180), 1, 0, 0);
1112
+ ctx.translate(-left - w / 2, -topY - h / 2);
1113
+ }
1114
+ if (layer.shadow) {
1115
+ ctx.shadowColor = resolve(layer.shadow.color);
1116
+ ctx.shadowBlur = layer.shadow.blur * r.size;
1117
+ ctx.shadowOffsetX = layer.shadow.x * r.size;
1118
+ ctx.shadowOffsetY = layer.shadow.y * r.size;
1119
+ }
1120
+ ctx.fillStyle = paintFor(layer.fill, left, topY, w, h, lineBright);
1121
+ ctx.beginPath();
1122
+ ctx.roundRect(left, topY, w, h, layer.radius * r.size);
1123
+ ctx.fill();
1124
+ if (layer.stroke) {
1125
+ ctx.strokeStyle = darken(resolve(layer.stroke.color), lineBright);
1126
+ ctx.lineWidth = Math.max(1.5, layer.stroke.width * r.size);
1127
+ ctx.stroke();
1128
+ }
1129
+ }
1130
+ }
1131
+ if (layer.type === "underline") {
1132
+ const width = r.width * layer.width, a = rowAlign(r), left = a === "left" ? r.left : a === "right" ? r.left + r.width - width : r.left + (r.width - width) / 2;
1133
+ const topY = r.center + layer.offsetY * r.size, h = Math.max(3, layer.height * r.size);
1134
+ if (moved({ x: left, y: topY - (layer.style === "swash" ? r.size * 0.3 : 0), w: width, h: h + (layer.style === "swash" ? r.size * 0.5 : 0) })) {
1135
+ ctx.fillStyle = paintFor(layer.fill, left, topY, width, h, lineBright);
1136
+ if (layer.style === "swash") {
1137
+ swashPath(ctx, left, topY, width, h, r.size);
1138
+ ctx.fill();
1139
+ } else ctx.fillRect(left, topY, width, h);
1140
+ }
1141
+ }
1142
+ if (layer.type === "text") {
1143
+ setFont(ctx, design, r.size, fontFamily, r.style);
1144
+ const shown = lp.count !== 1 ? countText(r.text, lp.count) : r.text;
1145
+ let rowLeft = r.left, rowW = r.width;
1146
+ if (shown !== r.text) {
1147
+ rowW = ctx.measureText(shown).width;
1148
+ const a = rowAlign(r);
1149
+ rowLeft = a === "left" ? r.left : a === "right" ? r.left + r.width - rowW : r.left + (r.width - rowW) / 2;
1150
+ }
1151
+ const ox = (layer.offset?.x || 0) * r.size, oy = (layer.offset?.y || 0) * r.size;
1152
+ if (frame && layer.flicker && noise(Math.floor(clock * 12) * 1.37 + 5) < layer.flicker) ctx.globalAlpha *= 0.18;
1153
+ if (!moved({ x: rowLeft + ox - r.size * 0.05, y: r.center - band(ri) / 2 + oy - r.size * 0.12, w: rowW + r.size * 0.1, h: band(ri) + r.size * 0.24 })) {
1154
+ ctx.restore();
1155
+ continue;
1156
+ }
1157
+ if (layer.shadow) {
1158
+ ctx.shadowColor = resolve(layer.shadow.color);
1159
+ ctx.shadowBlur = layer.shadow.blur * r.size;
1160
+ ctx.shadowOffsetX = layer.shadow.x * r.size;
1161
+ ctx.shadowOffsetY = layer.shadow.y * r.size;
1162
+ }
1163
+ const base = layer.lineFills ? layer.lineFills[ri % layer.lineFills.length] : void 0;
1164
+ let shine = null;
1165
+ if (frame && layer.shine) {
1166
+ const s = layer.shine;
1167
+ let local = clock - s.start;
1168
+ if (local >= 0 && s.every > 0) local %= s.every;
1169
+ const pr = local / s.duration;
1170
+ if (local >= 0 && pr < 1) {
1171
+ const bw = s.width * r.size, c = rowLeft - bw + (rowW + bw * 2) * pr, rad = s.angle * Math.PI / 180, col = resolve(s.color);
1172
+ shine = ctx.createLinearGradient(c - bw * Math.cos(rad), r.center - bw * Math.sin(rad), c + bw * Math.cos(rad), r.center + bw * Math.sin(rad));
1173
+ shine.addColorStop(0, rgba(col, 0));
1174
+ shine.addColorStop(0.5, rgba(col, 1));
1175
+ shine.addColorStop(1, rgba(col, 0));
1176
+ }
1177
+ }
1178
+ const ownFill = base ?? (r.fill && layer.fill === "{color}" ? r.fill : layer.fill);
1179
+ const top = r.center - band(ri) / 2 + oy;
1180
+ const fillOf = (f, bright) => paintFor(f, rowLeft + ox, top, rowW, band(ri), bright);
1181
+ const inkBottom = layer.reflection ? baseline(r) + oy + ctx.measureText(shown).actualBoundingBoxDescent : 0;
1182
+ const draw2 = (t, x, bright, over) => {
1183
+ const y = baseline(r) + oy, f = over ?? ownFill;
1184
+ if (glitch > 0.02) {
1185
+ const a = ctx.globalAlpha, d = glitch * r.size * 0.08;
1186
+ ctx.globalAlpha = a * 0.85;
1187
+ ctx.fillStyle = "#fd436a";
1188
+ ctx.fillText(t, x + ox + d, y);
1189
+ ctx.fillStyle = "#37eaff";
1190
+ ctx.fillText(t, x + ox - d, y);
1191
+ ctx.globalAlpha = a;
1192
+ }
1193
+ if (layer.stroke) {
1194
+ ctx.strokeStyle = darken(resolve(layer.stroke.color), bright);
1195
+ ctx.lineWidth = Math.max(2, layer.stroke.width * r.size);
1196
+ ctx.strokeText(t, x + ox, y);
1197
+ }
1198
+ ctx.fillStyle = fillOf(f, bright);
1199
+ ctx.fillText(t, x + ox, y);
1200
+ if (layer.innerGlow) {
1201
+ const m = ctx.getTransform();
1202
+ innerGlowText(ctx, (c) => c.fillText(t, x + ox, y), darken(resolve(layer.innerGlow.color), bright), layer.innerGlow.blur * r.size * Math.hypot(m.a, m.b));
1203
+ }
1204
+ if (shine) {
1205
+ ctx.save();
1206
+ ctx.shadowColor = "transparent";
1207
+ ctx.fillStyle = shine;
1208
+ ctx.fillText(t, x + ox, y);
1209
+ ctx.restore();
1210
+ }
1211
+ if (layer.reflection) {
1212
+ const rf = layer.reflection, axis = inkBottom + rf.gap * r.size, len = band(ri) * rf.fade, c = resolve(mainPaint(f)), hollow = !/^#[0-9a-f]{6}$/i.test(c);
1213
+ const col = hollow && layer.stroke ? resolve(layer.stroke.color) : c;
1214
+ ctx.save();
1215
+ ctx.shadowColor = "transparent";
1216
+ ctx.filter = "none";
1217
+ ctx.translate(0, 2 * axis);
1218
+ ctx.scale(1, -1);
1219
+ const g = ctx.createLinearGradient(0, axis, 0, axis - len);
1220
+ g.addColorStop(0, rgba(col, rf.opacity));
1221
+ g.addColorStop(1, rgba(col, 0));
1222
+ if (hollow && layer.stroke) {
1223
+ ctx.strokeStyle = g;
1224
+ ctx.lineWidth = Math.max(2, layer.stroke.width * r.size);
1225
+ ctx.strokeText(t, x + ox, y);
1226
+ } else {
1227
+ ctx.fillStyle = g;
1228
+ ctx.fillText(t, x + ox, y);
1229
+ }
1230
+ ctx.restore();
1231
+ }
1232
+ };
1233
+ const hl = /* @__PURE__ */ new Map();
1234
+ for (const h of layer.highlights ?? []) for (const w of h.words) hl.set(w, h.fill);
1235
+ const firstWord = wordStart(r.paragraph);
1236
+ const words = perUnit(r.paragraph, "word"), chars = perUnit(r.paragraph, "char"), spread = lp.spread;
1237
+ if (poses) {
1238
+ const gs = graphemes(r.text), xs = glyphX(ctx, r.text, gs), base2 = rowFirst[ri], units = unitsOf(r);
1239
+ let total2 = 0;
1240
+ for (let k = 0; k < gs.length; k++) total2 += poses[base2 + k].tracking;
1241
+ const a = rowAlign(r), shift0 = a === "left" ? 0 : a === "right" ? -total2 : -total2 / 2;
1242
+ let shift = shift0, n = 0;
1243
+ for (let k = 0; k < gs.length; k++) {
1244
+ const p = poses[base2 + k], x = r.left + xs[k], w = xs[k + 1] - xs[k], space = !/\S/u.test(gs[k]), u = space ? null : units[n++];
1245
+ const at = shift;
1246
+ shift += p.tracking;
1247
+ if (space || !u || p.opacity <= 2e-3 || p.scale <= 1e-4) continue;
1248
+ ctx.save();
1249
+ let bright = lineBright;
1250
+ if (words) bright *= applyPose(pose("word", r.paragraph, u.word, layoutOf(r.paragraph).word), u.x + u.w / 2, r.center, heights[ri] / 2 + r.size * 0.1, r.size);
1251
+ if (chars) bright *= applyPose(pose("char", r.paragraph, u.char, layoutOf(r.paragraph).char), u.x + u.w / 2, r.center, heights[ri] / 2 + r.size * 0.1, r.size);
1252
+ if (ctx.globalAlpha > 2e-3) drawGlyph(ctx, p, x + at + ox + w / 2, r.center, () => draw2(gs[k], x + at, bright, hl.get(firstWord + u.word)), (m) => m === "fill" ? ctx.fillText(gs[k], x + at + ox, baseline(r) + oy) : ctx.strokeText(gs[k], x + at + ox, baseline(r) + oy));
1253
+ ctx.restore();
1254
+ }
1255
+ } else if (!words && !chars && !spread) {
1256
+ if (!hl.size || shown !== r.text) draw2(shown, rowLeft, lineBright);
1257
+ else {
1258
+ const spans = /* @__PURE__ */ new Map();
1259
+ for (const u of unitsOf(r)) {
1260
+ const g = firstWord + u.word, sp = spans.get(g);
1261
+ spans.set(g, sp ? { x0: Math.min(sp.x0, u.x), x1: Math.max(sp.x1, u.x + u.w) } : { x0: u.x, x1: u.x + u.w });
1262
+ }
1263
+ const lit = [...spans].filter(([g]) => hl.has(g)), pad = r.size * 0.04;
1264
+ ctx.save();
1265
+ ctx.beginPath();
1266
+ ctx.rect(-1e5, -1e5, 2e5, 2e5);
1267
+ for (const [, sp] of lit) ctx.rect(sp.x0 + ox - pad, -1e5, sp.x1 - sp.x0 + pad * 2, 2e5);
1268
+ ctx.clip("evenodd");
1269
+ draw2(shown, rowLeft, lineBright);
1270
+ ctx.restore();
1271
+ for (const [g, sp] of lit) {
1272
+ ctx.save();
1273
+ ctx.beginPath();
1274
+ ctx.rect(sp.x0 + ox - pad, -1e5, sp.x1 - sp.x0 + pad * 2, 2e5);
1275
+ ctx.clip();
1276
+ draw2(shown, rowLeft, lineBright, hl.get(g));
1277
+ ctx.restore();
1278
+ }
1279
+ }
1280
+ } else {
1281
+ const units = unitsOf(r), mid = (units.length - 1) / 2;
1282
+ for (const [k, u] of units.entries()) {
1283
+ ctx.save();
1284
+ if (spread) ctx.translate((k - mid) * spread * r.size, 0);
1285
+ let bright = lineBright;
1286
+ if (words) bright *= applyPose(pose("word", r.paragraph, u.word, layoutOf(r.paragraph).word), u.x + u.w / 2, r.center, heights[ri] / 2 + r.size * 0.1, r.size);
1287
+ if (chars) bright *= applyPose(pose("char", r.paragraph, u.char, layoutOf(r.paragraph).char), u.x + u.w / 2, r.center, heights[ri] / 2 + r.size * 0.1, r.size);
1288
+ if (ctx.globalAlpha > 2e-3) draw2(u.text, u.x, bright, hl.get(firstWord + u.word));
1289
+ ctx.restore();
1290
+ }
1291
+ }
1292
+ }
1293
+ ctx.restore();
1294
+ }
1295
+ ctx.restore();
1296
+ }
1297
+ }
1298
+ function drawDecor(ctx, layer, clock, resolve) {
1299
+ const W2 = FRAME.width, H2 = FRAME.height, p = layerPose(layer.motion, clock);
1300
+ ctx.globalAlpha = layer.opacity * Math.min(1, Math.max(0, p.opacity));
1301
+ if (ctx.globalAlpha < 2e-3) return;
1302
+ let cx, cy, w, h;
1303
+ if (layer.type === "shape") {
1304
+ cx = (layer.box[0] + layer.box[2] / 2) * W2;
1305
+ cy = (layer.box[1] + layer.box[3] / 2) * H2;
1306
+ w = layer.box[2] * W2;
1307
+ h = layer.box[3] * H2;
1308
+ } else {
1309
+ w = h = layer.size * H2;
1310
+ cx = layer.center[0] * W2;
1311
+ cy = layer.center[1] * H2;
1312
+ }
1313
+ const origin = layer.motion?.origin ?? "center";
1314
+ const ax = origin === "left" ? cx - w / 2 : origin === "right" ? cx + w / 2 : cx, ay = origin === "top" ? cy - h / 2 : origin === "bottom" ? cy + h / 2 : cy;
1315
+ if (p.wipeX < 1) {
1316
+ ctx.beginPath();
1317
+ ctx.rect(cx - w / 2 - 8, cy - h / 2 - 8, (w + 16) * Math.max(0, p.wipeX), h + 16);
1318
+ ctx.clip();
1319
+ }
1320
+ if (p.wipeY < 1) {
1321
+ ctx.beginPath();
1322
+ ctx.rect(cx - w / 2 - 8, cy - h / 2 - 8, w + 16, (h + 16) * Math.max(0, p.wipeY));
1323
+ ctx.clip();
1324
+ }
1325
+ ctx.translate(ax + p.x * W2, ay + p.y * H2);
1326
+ ctx.scale(p.scale * p.scaleX, p.scale * p.scaleY);
1327
+ ctx.translate(cx - ax, cy - ay);
1328
+ ctx.rotate(((layer.rotate || 0) + p.rotate) * Math.PI / 180);
1329
+ if (layer.type === "shape") {
1330
+ if (layer.skewX) ctx.transform(1, 0, Math.tan(layer.skewX * Math.PI / 180), 1, 0, 0);
1331
+ if (layer.blur) ctx.filter = `blur(${(layer.blur * H2).toFixed(1)}px)`;
1332
+ if (layer.shape === "glow") {
1333
+ const c = typeof layer.fill === "string" ? resolve(layer.fill) : resolve(layer.stroke?.color ?? "{accent}"), r = Math.max(w, h) / 2;
1334
+ ctx.scale(w / 2 / r, h / 2 / r);
1335
+ const g = ctx.createRadialGradient(0, 0, 0, 0, 0, r);
1336
+ g.addColorStop(0, c);
1337
+ g.addColorStop(1, "rgba(0,0,0,0)");
1338
+ ctx.fillStyle = g;
1339
+ ctx.beginPath();
1340
+ ctx.arc(0, 0, r, 0, Math.PI * 2);
1341
+ ctx.fill();
1342
+ return;
1343
+ }
1344
+ ctx.beginPath();
1345
+ if (layer.shape === "rect") ctx.roundRect(-w / 2, -h / 2, w, h, Math.min(w, h) / 2 * Math.min(1, layer.radius * 2));
1346
+ else ctx.ellipse(0, 0, w / 2, h / 2, 0, 0, Math.PI * 2);
1347
+ if (layer.fill) {
1348
+ if (typeof layer.fill === "string") ctx.fillStyle = resolve(layer.fill);
1349
+ else ctx.fillStyle = gradientIn(ctx, layer.fill, -w / 2, -h / 2, w, h, resolve);
1350
+ ctx.fill();
1351
+ }
1352
+ if (layer.stroke) {
1353
+ ctx.strokeStyle = resolve(layer.stroke.color);
1354
+ ctx.lineWidth = layer.stroke.width;
1355
+ ctx.setLineDash(layer.stroke.dash ?? []);
1356
+ ctx.stroke();
1357
+ }
1358
+ return;
1359
+ }
1360
+ if (layer.glow) {
1361
+ ctx.shadowColor = resolve(layer.color);
1362
+ ctx.shadowBlur = layer.glow * w * 0.5;
1363
+ }
1364
+ if (layer.badge !== "none") {
1365
+ ctx.save();
1366
+ if (layer.badge === "diamond") ctx.rotate(Math.PI / 4);
1367
+ const s = layer.badge === "diamond" ? w * 0.72 : w;
1368
+ ctx.beginPath();
1369
+ if (layer.badge === "circle") ctx.arc(0, 0, w / 2, 0, Math.PI * 2);
1370
+ else ctx.roundRect(-s / 2, -s / 2, s, s, layer.badge === "square" ? 0 : s * 0.22);
1371
+ if (layer.badgeFill) {
1372
+ ctx.fillStyle = resolve(layer.badgeFill);
1373
+ ctx.fill();
1374
+ }
1375
+ if (layer.badgeStroke) {
1376
+ ctx.strokeStyle = resolve(layer.badgeStroke);
1377
+ ctx.lineWidth = 2;
1378
+ ctx.stroke();
1379
+ }
1380
+ ctx.restore();
1381
+ }
1382
+ ctx.shadowBlur = 0;
1383
+ const glyph = w * 0.6, k = glyph / 24;
1384
+ ctx.translate(-glyph / 2, -glyph / 2);
1385
+ ctx.scale(k, k);
1386
+ ctx.strokeStyle = resolve(layer.color);
1387
+ ctx.lineWidth = layer.width;
1388
+ ctx.lineCap = "round";
1389
+ ctx.lineJoin = "round";
1390
+ for (const d of TEXT_ICONS[layer.name] ?? []) ctx.stroke(new Path2D(d));
1391
+ }
1392
+ export {
1393
+ drawTimelineTitle
1394
+ };