@clypra-studio/engine 1.4.0 → 1.6.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.
- package/dist/{chunk-E6O6LZME.js → chunk-7ORA5BPW.js} +14 -299
- package/dist/chunk-7ORA5BPW.js.map +1 -0
- package/dist/chunk-NG4F55V7.js +300 -0
- package/dist/chunk-NG4F55V7.js.map +1 -0
- package/dist/{chunk-3UEOLDJJ.js → chunk-SH7HOGVX.js} +1 -1
- package/dist/chunk-SH7HOGVX.js.map +1 -0
- package/dist/chunk-V5D5SJPO.js +1946 -0
- package/dist/chunk-V5D5SJPO.js.map +1 -0
- package/dist/index-DKJxLj6P.d.cts +122 -0
- package/dist/index-DbojK0dC.d.ts +491 -0
- package/dist/index-QSvA1MMy.d.ts +122 -0
- package/dist/index-l2Qgw6Dt.d.cts +491 -0
- package/dist/index.cjs +3669 -484
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +248 -150
- package/dist/index.d.ts +248 -150
- package/dist/index.js +2226 -930
- package/dist/index.js.map +1 -1
- package/dist/rendering/index.cjs +3743 -0
- package/dist/rendering/index.cjs.map +1 -0
- package/dist/rendering/index.d.cts +2 -0
- package/dist/rendering/index.d.ts +2 -0
- package/dist/rendering/index.js +23 -0
- package/dist/rendering/index.js.map +1 -0
- package/dist/textEffects/index.cjs +13 -5
- package/dist/textEffects/index.cjs.map +1 -1
- package/dist/textEffects/index.d.cts +2 -1
- package/dist/textEffects/index.d.ts +2 -1
- package/dist/textEffects/index.js +6 -4
- package/dist/{index-C18SQ-y6.d.cts → types-CoshNXmU.d.cts} +142 -129
- package/dist/{index-C18SQ-y6.d.ts → types-CoshNXmU.d.ts} +142 -129
- package/dist/videoEffects/index.cjs.map +1 -1
- package/dist/videoEffects/index.js +1 -1
- package/package.json +6 -1
- package/dist/chunk-3UEOLDJJ.js.map +0 -1
- package/dist/chunk-E6O6LZME.js.map +0 -1
|
@@ -0,0 +1,3743 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/rendering/index.ts
|
|
20
|
+
var rendering_exports = {};
|
|
21
|
+
__export(rendering_exports, {
|
|
22
|
+
CANONICAL_RENDERER_VERSION: () => CANONICAL_RENDERER_VERSION,
|
|
23
|
+
TEXT_TEMPLATE_RENDERER_VERSION: () => TEXT_TEMPLATE_RENDERER_VERSION,
|
|
24
|
+
getTextTemplateControls: () => getTextTemplateControls,
|
|
25
|
+
renderCanonicalToCanvas: () => renderCanonicalToCanvas,
|
|
26
|
+
renderTextEffectToCanvas: () => renderTextEffectToCanvas,
|
|
27
|
+
renderTextTemplateToCanvas: () => renderTextTemplateToCanvas,
|
|
28
|
+
resolveTemplateFontFamily: () => resolveTemplateFontFamily,
|
|
29
|
+
resolveTextTemplateArtifact: () => resolveTextTemplateArtifact
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(rendering_exports);
|
|
32
|
+
|
|
33
|
+
// src/engine/schema.ts
|
|
34
|
+
var DEFAULT_CANVAS_WIDTH = 800;
|
|
35
|
+
var DEFAULT_CANVAS_HEIGHT = 200;
|
|
36
|
+
var DEFAULT_FONT_SIZE = 80;
|
|
37
|
+
function newLayerId() {
|
|
38
|
+
return `layer-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 7)}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/presets.ts
|
|
42
|
+
var defaultConfig = {
|
|
43
|
+
text: "CLYPRA STUDIO",
|
|
44
|
+
effectName: "My Effect",
|
|
45
|
+
fontFamily: "Poppins",
|
|
46
|
+
fontWeight: 700,
|
|
47
|
+
fontStyle: "normal",
|
|
48
|
+
fontSize: DEFAULT_FONT_SIZE,
|
|
49
|
+
letterSpacing: 4,
|
|
50
|
+
lineHeight: 1.2,
|
|
51
|
+
fillType: "solid",
|
|
52
|
+
fillColor: "#FFFFFF",
|
|
53
|
+
fillGradientAngle: 90,
|
|
54
|
+
fillGradientStops: [
|
|
55
|
+
{ color: "#FFFFFF", offset: 0 },
|
|
56
|
+
{ color: "#E0E0E0", offset: 100 }
|
|
57
|
+
],
|
|
58
|
+
strokeEnabled: false,
|
|
59
|
+
strokeColor: "#7C6FFF",
|
|
60
|
+
strokeWidth: 4,
|
|
61
|
+
strokePosition: "outside",
|
|
62
|
+
strokeOpacity: 100,
|
|
63
|
+
strokeLineJoin: "round",
|
|
64
|
+
glowLayers: [
|
|
65
|
+
{ enabled: false, color: "#7C6FFF", blur: 20, opacity: 80, type: "outer" },
|
|
66
|
+
{ enabled: false, color: "#FF007C", blur: 40, opacity: 60, type: "outer" },
|
|
67
|
+
{ enabled: false, color: "#00F0FF", blur: 60, opacity: 40, type: "outer" }
|
|
68
|
+
],
|
|
69
|
+
shadowEnabled: false,
|
|
70
|
+
shadowColor: "#000000",
|
|
71
|
+
shadowBlur: 10,
|
|
72
|
+
shadowOffsetX: 5,
|
|
73
|
+
shadowOffsetY: 5,
|
|
74
|
+
shadowOpacity: 80,
|
|
75
|
+
shadowType: "drop",
|
|
76
|
+
bevelEnabled: false,
|
|
77
|
+
bevelDepth: 5,
|
|
78
|
+
bevelHighlight: "#FFFFFF",
|
|
79
|
+
bevelShadow: "#000000",
|
|
80
|
+
bevelDirection: "bottom-right",
|
|
81
|
+
bevelCoreColor: "#000000",
|
|
82
|
+
bevelEdgeColor: "#2A2A38",
|
|
83
|
+
bevelEdgeWidth: 0,
|
|
84
|
+
bevelBlur: 0,
|
|
85
|
+
bevelBlurColor: "#000000",
|
|
86
|
+
bevelPerspectiveEnabled: false,
|
|
87
|
+
bevelVanishingPointX: 40,
|
|
88
|
+
bevelVanishingPointY: 80,
|
|
89
|
+
bevelFocalLength: 400,
|
|
90
|
+
stackEnabled: false,
|
|
91
|
+
stackCount: 3,
|
|
92
|
+
stackOffsetX: 10,
|
|
93
|
+
stackOffsetY: -10,
|
|
94
|
+
stackOpacityDecay: 20,
|
|
95
|
+
stackColor1: "#FF7C00",
|
|
96
|
+
stackColor2: "#00FFDD",
|
|
97
|
+
stackColor3: "#FF00AA",
|
|
98
|
+
stackColor4: "#AA00FF",
|
|
99
|
+
panelEnabled: false,
|
|
100
|
+
panelColor: "#1E1E26",
|
|
101
|
+
panelOpacity: 80,
|
|
102
|
+
panelRadius: 12,
|
|
103
|
+
panelPaddingX: 40,
|
|
104
|
+
panelPaddingY: 20,
|
|
105
|
+
panelStrokeEnabled: false,
|
|
106
|
+
panelStrokeColor: "#2A2A38",
|
|
107
|
+
panelStrokeWidth: 2,
|
|
108
|
+
canvasWidth: DEFAULT_CANVAS_WIDTH,
|
|
109
|
+
canvasHeight: DEFAULT_CANVAS_HEIGHT,
|
|
110
|
+
textPosX: "center",
|
|
111
|
+
textPosY: "middle",
|
|
112
|
+
wrapText: true,
|
|
113
|
+
autoFitText: false
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// src/engine/timelineDefaults.ts
|
|
117
|
+
function ensureDefaultTimeline(doc) {
|
|
118
|
+
if (doc.timeline.tracks.length > 0) return doc;
|
|
119
|
+
const shadowLayer = doc.effectLayers.find((l) => l.type === "shadow");
|
|
120
|
+
const maskLayer = doc.effectLayers.find((l) => l.type === "mask");
|
|
121
|
+
const tracks = [];
|
|
122
|
+
if (shadowLayer) {
|
|
123
|
+
tracks.push({
|
|
124
|
+
layerId: shadowLayer.id,
|
|
125
|
+
paramPath: "shadowOffsetY",
|
|
126
|
+
keyframes: [
|
|
127
|
+
{ time: 0, value: shadowLayer.params.shadowOffsetY ?? 5, easing: "easeInOut" },
|
|
128
|
+
{
|
|
129
|
+
time: doc.timeline.duration / 2,
|
|
130
|
+
value: (shadowLayer.params.shadowOffsetY ?? 5) + 8,
|
|
131
|
+
easing: "easeInOut"
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
time: doc.timeline.duration,
|
|
135
|
+
value: shadowLayer.params.shadowOffsetY ?? 5,
|
|
136
|
+
easing: "easeInOut"
|
|
137
|
+
}
|
|
138
|
+
]
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
if (maskLayer) {
|
|
142
|
+
tracks.push({
|
|
143
|
+
layerId: maskLayer.id,
|
|
144
|
+
paramPath: "revealProgress",
|
|
145
|
+
keyframes: [
|
|
146
|
+
{ time: 0, value: 0, easing: "easeOut" },
|
|
147
|
+
{ time: doc.timeline.duration * 0.85, value: 1, easing: "easeOut" }
|
|
148
|
+
]
|
|
149
|
+
});
|
|
150
|
+
maskLayer.enabled = false;
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
...doc,
|
|
154
|
+
effectLayers: doc.effectLayers.map((l) => ({ ...l })),
|
|
155
|
+
timeline: { ...doc.timeline, tracks }
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// src/engine/migrate.ts
|
|
160
|
+
function layer(type, name, params, extra) {
|
|
161
|
+
return {
|
|
162
|
+
id: extra?.id ?? newLayerId(),
|
|
163
|
+
type,
|
|
164
|
+
name,
|
|
165
|
+
enabled: true,
|
|
166
|
+
opacity: 1,
|
|
167
|
+
blendMode: "source-over",
|
|
168
|
+
target: type === "panel" ? "scene" : "text",
|
|
169
|
+
params,
|
|
170
|
+
...extra
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
var REMOVED_INK_FIELDS = [
|
|
174
|
+
"customRenderer",
|
|
175
|
+
"inkColor",
|
|
176
|
+
"bristleDensity",
|
|
177
|
+
"bristleSkipRate",
|
|
178
|
+
"dripRate",
|
|
179
|
+
"dripMaxLength",
|
|
180
|
+
"grainDensity",
|
|
181
|
+
"skewX"
|
|
182
|
+
];
|
|
183
|
+
function stripRemovedRendererFields(value) {
|
|
184
|
+
const out = { ...value };
|
|
185
|
+
for (const key of REMOVED_INK_FIELDS) delete out[key];
|
|
186
|
+
return out;
|
|
187
|
+
}
|
|
188
|
+
function textEffectConfigToScene(cfg) {
|
|
189
|
+
const safeConfig = stripRemovedRendererFields(cfg);
|
|
190
|
+
const layers = [];
|
|
191
|
+
layers.push(
|
|
192
|
+
layer(
|
|
193
|
+
"panel",
|
|
194
|
+
"Background Panel",
|
|
195
|
+
{
|
|
196
|
+
enabled: safeConfig.panelEnabled,
|
|
197
|
+
panelEnabled: safeConfig.panelEnabled,
|
|
198
|
+
panelColor: safeConfig.panelColor,
|
|
199
|
+
panelOpacity: safeConfig.panelOpacity,
|
|
200
|
+
panelRadius: safeConfig.panelRadius,
|
|
201
|
+
panelPaddingX: safeConfig.panelPaddingX,
|
|
202
|
+
panelPaddingY: safeConfig.panelPaddingY,
|
|
203
|
+
panelStrokeEnabled: safeConfig.panelStrokeEnabled,
|
|
204
|
+
panelStrokeColor: safeConfig.panelStrokeColor,
|
|
205
|
+
panelStrokeWidth: safeConfig.panelStrokeWidth
|
|
206
|
+
},
|
|
207
|
+
{ enabled: safeConfig.panelEnabled, id: "panel" }
|
|
208
|
+
)
|
|
209
|
+
);
|
|
210
|
+
(safeConfig.glowLayers || []).forEach((g, i) => {
|
|
211
|
+
layers.push(layer("glow", `Glow ${i + 1}`, { ...g, enabled: g.enabled }, { id: `glow-${i + 1}`, enabled: g.enabled, opacity: (g.opacity ?? 100) / 100 }));
|
|
212
|
+
});
|
|
213
|
+
layers.push(
|
|
214
|
+
layer(
|
|
215
|
+
"shadow",
|
|
216
|
+
"Shadow",
|
|
217
|
+
{
|
|
218
|
+
enabled: safeConfig.shadowEnabled,
|
|
219
|
+
shadowEnabled: safeConfig.shadowEnabled,
|
|
220
|
+
shadowColor: safeConfig.shadowColor,
|
|
221
|
+
shadowBlur: safeConfig.shadowBlur,
|
|
222
|
+
shadowOffsetX: safeConfig.shadowOffsetX,
|
|
223
|
+
shadowOffsetY: safeConfig.shadowOffsetY,
|
|
224
|
+
shadowOpacity: safeConfig.shadowOpacity,
|
|
225
|
+
shadowType: safeConfig.shadowType
|
|
226
|
+
},
|
|
227
|
+
{ enabled: safeConfig.shadowEnabled, id: "shadow" }
|
|
228
|
+
)
|
|
229
|
+
);
|
|
230
|
+
layers.push(
|
|
231
|
+
layer(
|
|
232
|
+
"extrusion",
|
|
233
|
+
"Bevel / Extrusion",
|
|
234
|
+
{
|
|
235
|
+
enabled: safeConfig.bevelEnabled,
|
|
236
|
+
bevelEnabled: safeConfig.bevelEnabled,
|
|
237
|
+
bevelDepth: safeConfig.bevelDepth,
|
|
238
|
+
bevelHighlight: safeConfig.bevelHighlight,
|
|
239
|
+
bevelShadow: safeConfig.bevelShadow,
|
|
240
|
+
bevelDirection: safeConfig.bevelDirection,
|
|
241
|
+
bevelCoreColor: safeConfig.bevelCoreColor,
|
|
242
|
+
bevelEdgeColor: safeConfig.bevelEdgeColor,
|
|
243
|
+
bevelEdgeWidth: safeConfig.bevelEdgeWidth,
|
|
244
|
+
bevelBlur: safeConfig.bevelBlur,
|
|
245
|
+
bevelBlurColor: safeConfig.bevelBlurColor,
|
|
246
|
+
bevelPerspectiveEnabled: safeConfig.bevelPerspectiveEnabled,
|
|
247
|
+
bevelVanishingPointX: safeConfig.bevelVanishingPointX,
|
|
248
|
+
bevelVanishingPointY: safeConfig.bevelVanishingPointY,
|
|
249
|
+
bevelFocalLength: safeConfig.bevelFocalLength
|
|
250
|
+
},
|
|
251
|
+
{ enabled: safeConfig.bevelEnabled, id: "extrusion" }
|
|
252
|
+
)
|
|
253
|
+
);
|
|
254
|
+
layers.push(
|
|
255
|
+
layer(
|
|
256
|
+
"duplicateStack",
|
|
257
|
+
"Stack Extrusion",
|
|
258
|
+
{
|
|
259
|
+
enabled: !!safeConfig.stackEnabled,
|
|
260
|
+
stackEnabled: safeConfig.stackEnabled,
|
|
261
|
+
stackCount: safeConfig.stackCount,
|
|
262
|
+
stackOffsetX: safeConfig.stackOffsetX,
|
|
263
|
+
stackOffsetY: safeConfig.stackOffsetY,
|
|
264
|
+
stackOpacityDecay: safeConfig.stackOpacityDecay,
|
|
265
|
+
stackColor1: safeConfig.stackColor1,
|
|
266
|
+
stackColor2: safeConfig.stackColor2,
|
|
267
|
+
stackColor3: safeConfig.stackColor3,
|
|
268
|
+
stackColor4: safeConfig.stackColor4
|
|
269
|
+
},
|
|
270
|
+
{ enabled: !!safeConfig.stackEnabled, id: "duplicate-stack" }
|
|
271
|
+
)
|
|
272
|
+
);
|
|
273
|
+
layers.push(
|
|
274
|
+
layer(
|
|
275
|
+
"stroke",
|
|
276
|
+
"Stroke",
|
|
277
|
+
{
|
|
278
|
+
enabled: safeConfig.strokeEnabled,
|
|
279
|
+
strokeEnabled: safeConfig.strokeEnabled,
|
|
280
|
+
strokeColor: safeConfig.strokeColor,
|
|
281
|
+
strokeWidth: safeConfig.strokeWidth,
|
|
282
|
+
strokePosition: safeConfig.strokePosition,
|
|
283
|
+
strokeOpacity: safeConfig.strokeOpacity,
|
|
284
|
+
strokeLineJoin: safeConfig.strokeLineJoin,
|
|
285
|
+
strokeBlur: safeConfig.strokeBlur,
|
|
286
|
+
strokeType: safeConfig.strokeType,
|
|
287
|
+
strokeColorSecondary: safeConfig.strokeColorSecondary,
|
|
288
|
+
strokeWidthSecondary: safeConfig.strokeWidthSecondary,
|
|
289
|
+
strokeFadeRange: safeConfig.strokeFadeRange
|
|
290
|
+
},
|
|
291
|
+
{ enabled: safeConfig.strokeEnabled, id: "stroke" }
|
|
292
|
+
)
|
|
293
|
+
);
|
|
294
|
+
layers.push(
|
|
295
|
+
layer(
|
|
296
|
+
"fill",
|
|
297
|
+
"Fill",
|
|
298
|
+
{
|
|
299
|
+
enabled: safeConfig.fillType !== "none",
|
|
300
|
+
fillType: safeConfig.fillType,
|
|
301
|
+
fillColor: safeConfig.fillColor,
|
|
302
|
+
fillGradientAngle: safeConfig.fillGradientAngle,
|
|
303
|
+
fillGradientStops: safeConfig.fillGradientStops,
|
|
304
|
+
patternType: safeConfig.patternType,
|
|
305
|
+
perCharFillEnabled: safeConfig.perCharFillEnabled,
|
|
306
|
+
charFillColors: safeConfig.charFillColors
|
|
307
|
+
},
|
|
308
|
+
{ enabled: safeConfig.fillType !== "none", id: "fill" }
|
|
309
|
+
)
|
|
310
|
+
);
|
|
311
|
+
layers.push(layer("mask", "Text Alpha Mask", { maskType: "alphaText", revealProgress: 1 }, { enabled: false, id: "mask" }));
|
|
312
|
+
layers.push(layer("filter", "Compositor FX", { blur: 0, bloom: 0 }, { enabled: false, target: "previous", id: "compositor" }));
|
|
313
|
+
const doc = {
|
|
314
|
+
version: 1,
|
|
315
|
+
schemaVersion: 2,
|
|
316
|
+
effectName: safeConfig.effectName,
|
|
317
|
+
canvas: {
|
|
318
|
+
width: safeConfig.canvasWidth,
|
|
319
|
+
height: safeConfig.canvasHeight,
|
|
320
|
+
background: "transparent"
|
|
321
|
+
},
|
|
322
|
+
text: {
|
|
323
|
+
content: safeConfig.text,
|
|
324
|
+
fontFamily: safeConfig.fontFamily,
|
|
325
|
+
fontWeight: safeConfig.fontWeight,
|
|
326
|
+
fontStyle: safeConfig.fontStyle,
|
|
327
|
+
fontSize: safeConfig.fontSize,
|
|
328
|
+
letterSpacing: safeConfig.letterSpacing,
|
|
329
|
+
lineHeight: safeConfig.lineHeight,
|
|
330
|
+
textPosX: safeConfig.textPosX,
|
|
331
|
+
textPosY: safeConfig.textPosY,
|
|
332
|
+
wrapText: safeConfig.wrapText !== false,
|
|
333
|
+
autoFitText: !!safeConfig.autoFitText,
|
|
334
|
+
perCharFillEnabled: safeConfig.perCharFillEnabled,
|
|
335
|
+
charFillColors: safeConfig.charFillColors
|
|
336
|
+
},
|
|
337
|
+
effectLayers: layers,
|
|
338
|
+
compositor: { blur: 0, bloom: 0, bloomThreshold: 0.6 },
|
|
339
|
+
timeline: { duration: 2, fps: 30, loop: true, tracks: [] },
|
|
340
|
+
legacyConfig: { ...safeConfig }
|
|
341
|
+
};
|
|
342
|
+
return ensureDefaultTimeline(doc);
|
|
343
|
+
}
|
|
344
|
+
function getLayerParams(doc, type, index = 0) {
|
|
345
|
+
const found = doc.effectLayers.filter((l) => l.type === type);
|
|
346
|
+
return found[index]?.params;
|
|
347
|
+
}
|
|
348
|
+
function sceneToConfig(doc) {
|
|
349
|
+
const base = doc.legacyConfig ? stripRemovedRendererFields(doc.legacyConfig) : {
|
|
350
|
+
...createDefaultFromScene(doc)
|
|
351
|
+
};
|
|
352
|
+
base.effectName = doc.effectName;
|
|
353
|
+
base.text = doc.text.content;
|
|
354
|
+
base.fontFamily = doc.text.fontFamily;
|
|
355
|
+
base.fontWeight = doc.text.fontWeight;
|
|
356
|
+
base.fontStyle = doc.text.fontStyle;
|
|
357
|
+
base.fontSize = doc.text.fontSize;
|
|
358
|
+
base.letterSpacing = doc.text.letterSpacing;
|
|
359
|
+
base.lineHeight = doc.text.lineHeight;
|
|
360
|
+
base.textPosX = doc.text.textPosX;
|
|
361
|
+
base.textPosY = doc.text.textPosY;
|
|
362
|
+
base.wrapText = doc.text.wrapText !== false;
|
|
363
|
+
base.autoFitText = !!doc.text.autoFitText;
|
|
364
|
+
base.canvasWidth = doc.canvas.width;
|
|
365
|
+
base.canvasHeight = doc.canvas.height;
|
|
366
|
+
const withoutLayerEnabled = (params) => {
|
|
367
|
+
const { enabled: _enabled, ...visualParams } = params;
|
|
368
|
+
return visualParams;
|
|
369
|
+
};
|
|
370
|
+
const panel = getLayerParams(doc, "panel");
|
|
371
|
+
if (panel) {
|
|
372
|
+
Object.assign(base, {
|
|
373
|
+
panelEnabled: !!doc.effectLayers.find((l) => l.type === "panel")?.enabled && panel.enabled !== false && panel.panelEnabled !== false,
|
|
374
|
+
...withoutLayerEnabled(panel),
|
|
375
|
+
panelOpacity: panel.panelOpacity,
|
|
376
|
+
panelRadius: panel.panelRadius,
|
|
377
|
+
panelPaddingX: panel.panelPaddingX,
|
|
378
|
+
panelPaddingY: panel.panelPaddingY,
|
|
379
|
+
panelStrokeEnabled: panel.panelStrokeEnabled,
|
|
380
|
+
panelStrokeColor: panel.panelStrokeColor,
|
|
381
|
+
panelStrokeWidth: panel.panelStrokeWidth
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
const glows = doc.effectLayers.filter((l) => l.type === "glow");
|
|
385
|
+
base.glowLayers = glows.map((l) => {
|
|
386
|
+
const p = l.params;
|
|
387
|
+
return {
|
|
388
|
+
enabled: l.enabled && (p.enabled ?? true) && (l.opacity ?? 1) > 0,
|
|
389
|
+
color: p.color ?? "#7C6FFF",
|
|
390
|
+
blur: p.blur ?? 20,
|
|
391
|
+
opacity: Math.round((p.opacity ?? 80) * (l.opacity ?? 1)),
|
|
392
|
+
type: p.type ?? "outer",
|
|
393
|
+
strength: p.strength,
|
|
394
|
+
spread: p.spread
|
|
395
|
+
};
|
|
396
|
+
});
|
|
397
|
+
while (base.glowLayers.length < 3) {
|
|
398
|
+
base.glowLayers.push({
|
|
399
|
+
enabled: false,
|
|
400
|
+
color: "#7C6FFF",
|
|
401
|
+
blur: 20,
|
|
402
|
+
opacity: 80,
|
|
403
|
+
type: "outer"
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
const shadow = getLayerParams(doc, "shadow");
|
|
407
|
+
if (shadow) Object.assign(base, { ...withoutLayerEnabled(shadow), shadowEnabled: !!doc.effectLayers.find((l) => l.type === "shadow")?.enabled && shadow.enabled !== false && shadow.shadowEnabled !== false });
|
|
408
|
+
const extrusion = getLayerParams(doc, "extrusion");
|
|
409
|
+
if (extrusion) Object.assign(base, { ...withoutLayerEnabled(extrusion), bevelEnabled: !!doc.effectLayers.find((l) => l.type === "extrusion")?.enabled && extrusion.enabled !== false && extrusion.bevelEnabled !== false });
|
|
410
|
+
const stack = getLayerParams(doc, "duplicateStack");
|
|
411
|
+
if (stack) Object.assign(base, { ...withoutLayerEnabled(stack), stackEnabled: !!doc.effectLayers.find((l) => l.type === "duplicateStack")?.enabled && stack.enabled !== false && stack.stackEnabled !== false });
|
|
412
|
+
const stroke = getLayerParams(doc, "stroke");
|
|
413
|
+
if (stroke) Object.assign(base, { ...withoutLayerEnabled(stroke), strokeEnabled: !!doc.effectLayers.find((l) => l.type === "stroke")?.enabled && stroke.enabled !== false && stroke.strokeEnabled !== false });
|
|
414
|
+
const fill = getLayerParams(doc, "fill");
|
|
415
|
+
if (fill) Object.assign(base, withoutLayerEnabled(fill));
|
|
416
|
+
base.perCharFillEnabled = doc.text.perCharFillEnabled ?? fill?.perCharFillEnabled;
|
|
417
|
+
base.charFillColors = doc.text.charFillColors ?? fill?.charFillColors;
|
|
418
|
+
base.glowLayers = base.glowLayers.slice(0, 6);
|
|
419
|
+
const filterLayers = doc.effectLayers.filter((l) => l.type === "filter" && l.enabled);
|
|
420
|
+
const filter = filterLayers[filterLayers.length - 1]?.params;
|
|
421
|
+
const compositor = {
|
|
422
|
+
blur: filter?.blur ?? doc.compositor.blur ?? 0,
|
|
423
|
+
bloom: filter?.bloom ?? doc.compositor.bloom ?? 0,
|
|
424
|
+
bloomThreshold: doc.compositor.bloomThreshold ?? 0.6
|
|
425
|
+
};
|
|
426
|
+
return base;
|
|
427
|
+
}
|
|
428
|
+
function createDefaultFromScene(doc) {
|
|
429
|
+
const cfg = { ...defaultConfig };
|
|
430
|
+
cfg.text = doc.text.content;
|
|
431
|
+
return cfg;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// src/engine/animation.ts
|
|
435
|
+
function ease(t, kind = "linear") {
|
|
436
|
+
switch (kind) {
|
|
437
|
+
case "easeIn":
|
|
438
|
+
return t * t;
|
|
439
|
+
case "easeOut":
|
|
440
|
+
return t * (2 - t);
|
|
441
|
+
case "easeInOut":
|
|
442
|
+
return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
|
|
443
|
+
default:
|
|
444
|
+
return t;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
function interpolateKeyframes(keyframes, time) {
|
|
448
|
+
if (keyframes.length === 0) return 0;
|
|
449
|
+
const sorted = [...keyframes].sort((a, b) => a.time - b.time);
|
|
450
|
+
if (time <= sorted[0].time) return sorted[0].value;
|
|
451
|
+
if (time >= sorted[sorted.length - 1].time) return sorted[sorted.length - 1].value;
|
|
452
|
+
for (let i = 0; i < sorted.length - 1; i++) {
|
|
453
|
+
const a = sorted[i];
|
|
454
|
+
const b = sorted[i + 1];
|
|
455
|
+
if (time >= a.time && time <= b.time) {
|
|
456
|
+
const span = b.time - a.time || 1;
|
|
457
|
+
const localT = (time - a.time) / span;
|
|
458
|
+
const eased = ease(localT, b.easing ?? "linear");
|
|
459
|
+
return a.value + (b.value - a.value) * eased;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
return sorted[sorted.length - 1].value;
|
|
463
|
+
}
|
|
464
|
+
function resolveAnimatedScalar(doc, layerId, paramPath, baseValue, time) {
|
|
465
|
+
const track = doc.timeline.tracks.find((t) => t.layerId === layerId && t.paramPath === paramPath);
|
|
466
|
+
if (!track || track.keyframes.length === 0) return baseValue;
|
|
467
|
+
return interpolateKeyframes(track.keyframes, time);
|
|
468
|
+
}
|
|
469
|
+
function applyTimelineAtTime(doc, time) {
|
|
470
|
+
const looped = doc.timeline.loop && doc.timeline.duration > 0 ? time % doc.timeline.duration : Math.min(time, doc.timeline.duration);
|
|
471
|
+
const layers = doc.effectLayers.map((layer2) => {
|
|
472
|
+
let opacity = layer2.opacity;
|
|
473
|
+
const params = { ...layer2.params };
|
|
474
|
+
for (const track of doc.timeline.tracks) {
|
|
475
|
+
if (track.layerId !== layer2.id) continue;
|
|
476
|
+
if (track.paramPath === "layerOpacity") {
|
|
477
|
+
opacity = resolveAnimatedScalar(doc, layer2.id, track.paramPath, opacity, looped);
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
const parts = track.paramPath.split(".");
|
|
481
|
+
let target = params;
|
|
482
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
483
|
+
const key = parts[i];
|
|
484
|
+
if (typeof target[key] !== "object" || target[key] === null) {
|
|
485
|
+
target[key] = {};
|
|
486
|
+
}
|
|
487
|
+
target = target[key];
|
|
488
|
+
}
|
|
489
|
+
const leaf = parts[parts.length - 1];
|
|
490
|
+
const current = typeof target[leaf] === "number" ? target[leaf] : 0;
|
|
491
|
+
target[leaf] = resolveAnimatedScalar(doc, layer2.id, track.paramPath, current, looped);
|
|
492
|
+
}
|
|
493
|
+
return { ...layer2, opacity, params };
|
|
494
|
+
});
|
|
495
|
+
return { ...doc, effectLayers: layers };
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// src/templates/keyframes.ts
|
|
499
|
+
function cubicBezier(x1, y1, x2, y2) {
|
|
500
|
+
return function(t) {
|
|
501
|
+
if (t <= 0) return 0;
|
|
502
|
+
if (t >= 1) return 1;
|
|
503
|
+
let tApprox = t;
|
|
504
|
+
for (let i = 0; i < 8; i++) {
|
|
505
|
+
const currentX = 3 * (1 - tApprox) * (1 - tApprox) * tApprox * x1 + 3 * (1 - tApprox) * tApprox * tApprox * x2 + tApprox * tApprox * tApprox;
|
|
506
|
+
const slope = 3 * (1 - tApprox) * (1 - tApprox) * x1 + 6 * (1 - tApprox) * tApprox * (x2 - x1) + 3 * tApprox * tApprox * (1 - x2);
|
|
507
|
+
if (Math.abs(slope) < 1e-6) break;
|
|
508
|
+
tApprox -= (currentX - t) / slope;
|
|
509
|
+
}
|
|
510
|
+
tApprox = Math.max(0, Math.min(1, tApprox));
|
|
511
|
+
return 3 * (1 - tApprox) * (1 - tApprox) * tApprox * y1 + 3 * (1 - tApprox) * tApprox * tApprox * y2 + tApprox * tApprox * tApprox;
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
function solveSpring(t, params) {
|
|
515
|
+
const mass = params?.mass ?? 1;
|
|
516
|
+
const stiffness = params?.stiffness ?? 100;
|
|
517
|
+
const damping = params?.damping ?? 10;
|
|
518
|
+
const omega0 = Math.sqrt(stiffness / mass);
|
|
519
|
+
const zeta = damping / (2 * Math.sqrt(stiffness * mass));
|
|
520
|
+
if (zeta < 1) {
|
|
521
|
+
const omegaD = omega0 * Math.sqrt(1 - zeta * zeta);
|
|
522
|
+
const envelope = Math.exp(-zeta * omega0 * t);
|
|
523
|
+
return 1 - envelope * (Math.cos(omegaD * t) + zeta / Math.sqrt(1 - zeta * zeta) * Math.sin(omegaD * t));
|
|
524
|
+
} else {
|
|
525
|
+
return 1 - (1 + omega0 * t) * Math.exp(-omega0 * t);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
function easeOutBounce(t) {
|
|
529
|
+
const n1 = 7.5625;
|
|
530
|
+
const d1 = 2.75;
|
|
531
|
+
if (t < 1 / d1) {
|
|
532
|
+
return n1 * t * t;
|
|
533
|
+
} else if (t < 2 / d1) {
|
|
534
|
+
let tVal = t - 1.5 / d1;
|
|
535
|
+
return n1 * tVal * tVal + 0.75;
|
|
536
|
+
} else if (t < 2.5 / d1) {
|
|
537
|
+
let tVal = t - 2.25 / d1;
|
|
538
|
+
return n1 * tVal * tVal + 0.9375;
|
|
539
|
+
} else {
|
|
540
|
+
let tVal = t - 2.625 / d1;
|
|
541
|
+
return n1 * tVal * tVal + 0.984375;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
function isKeyframed(value) {
|
|
545
|
+
return typeof value === "object" && value !== null && "keyframes" in value && Array.isArray(value.keyframes);
|
|
546
|
+
}
|
|
547
|
+
function evaluateAnimatable(value, time, templateDuration) {
|
|
548
|
+
if (!isKeyframed(value)) {
|
|
549
|
+
return value;
|
|
550
|
+
}
|
|
551
|
+
const { keyframes } = value;
|
|
552
|
+
if (keyframes.length === 0) {
|
|
553
|
+
throw new Error("Keyframes array cannot be empty");
|
|
554
|
+
}
|
|
555
|
+
if (keyframes.length === 1) {
|
|
556
|
+
return keyframes[0].value;
|
|
557
|
+
}
|
|
558
|
+
const sorted = [...keyframes].sort((a, b) => a.time - b.time);
|
|
559
|
+
if (time <= sorted[0].time) {
|
|
560
|
+
return sorted[0].value;
|
|
561
|
+
}
|
|
562
|
+
if (time >= sorted[sorted.length - 1].time) {
|
|
563
|
+
return sorted[sorted.length - 1].value;
|
|
564
|
+
}
|
|
565
|
+
let leftIdx = 0;
|
|
566
|
+
for (let i = 0; i < sorted.length - 1; i++) {
|
|
567
|
+
if (time >= sorted[i].time && time <= sorted[i + 1].time) {
|
|
568
|
+
leftIdx = i;
|
|
569
|
+
break;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
const left = sorted[leftIdx];
|
|
573
|
+
const right = sorted[leftIdx + 1];
|
|
574
|
+
const range = right.time - left.time;
|
|
575
|
+
const t = range === 0 ? 0 : (time - left.time) / range;
|
|
576
|
+
const easedT = applyEasing(t, right.easing || "linear", right.bezier, right.spring);
|
|
577
|
+
return interpolateValue(left.value, right.value, easedT);
|
|
578
|
+
}
|
|
579
|
+
function applyEasing(t, easing, bezier, spring) {
|
|
580
|
+
switch (easing) {
|
|
581
|
+
case "linear":
|
|
582
|
+
return t;
|
|
583
|
+
case "ease-in":
|
|
584
|
+
return t * t;
|
|
585
|
+
case "ease-out":
|
|
586
|
+
return t * (2 - t);
|
|
587
|
+
case "ease-in-out":
|
|
588
|
+
return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
|
|
589
|
+
case "ease":
|
|
590
|
+
return cubicBezier(0.25, 0.1, 0.25, 1)(t);
|
|
591
|
+
case "cubic-bezier":
|
|
592
|
+
if (bezier) {
|
|
593
|
+
return cubicBezier(bezier.x1, bezier.y1, bezier.x2, bezier.y2)(t);
|
|
594
|
+
}
|
|
595
|
+
return cubicBezier(0.4, 0, 0.2, 1)(t);
|
|
596
|
+
case "spring":
|
|
597
|
+
return solveSpring(t, spring);
|
|
598
|
+
case "bounce":
|
|
599
|
+
return easeOutBounce(t);
|
|
600
|
+
default:
|
|
601
|
+
return t;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
function interpolateValue(from, to, t) {
|
|
605
|
+
if (typeof from === "number" && typeof to === "number") {
|
|
606
|
+
return from + (to - from) * t;
|
|
607
|
+
}
|
|
608
|
+
if (typeof from === "string" && typeof to === "string") {
|
|
609
|
+
const isFromColor = from.startsWith("#") || from.startsWith("rgb");
|
|
610
|
+
const isToColor = to.startsWith("#") || to.startsWith("rgb");
|
|
611
|
+
if (isFromColor && isToColor) {
|
|
612
|
+
return interpolateColorString(from, to, t);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
return t < 0.5 ? from : to;
|
|
616
|
+
}
|
|
617
|
+
function parseColor(color) {
|
|
618
|
+
if (!color) return null;
|
|
619
|
+
const trimmed = color.trim().toLowerCase();
|
|
620
|
+
if (trimmed.startsWith("#")) {
|
|
621
|
+
const hex = trimmed.slice(1);
|
|
622
|
+
if (hex.length === 3) {
|
|
623
|
+
return {
|
|
624
|
+
r: parseInt(hex[0] + hex[0], 16),
|
|
625
|
+
g: parseInt(hex[1] + hex[1], 16),
|
|
626
|
+
b: parseInt(hex[2] + hex[2], 16),
|
|
627
|
+
a: 1
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
if (hex.length === 4) {
|
|
631
|
+
return {
|
|
632
|
+
r: parseInt(hex[0] + hex[0], 16),
|
|
633
|
+
g: parseInt(hex[1] + hex[1], 16),
|
|
634
|
+
b: parseInt(hex[2] + hex[2], 16),
|
|
635
|
+
a: parseInt(hex[3] + hex[3], 16) / 255
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
if (hex.length === 6) {
|
|
639
|
+
return {
|
|
640
|
+
r: parseInt(hex.slice(0, 2), 16),
|
|
641
|
+
g: parseInt(hex.slice(2, 4), 16),
|
|
642
|
+
b: parseInt(hex.slice(4, 6), 16),
|
|
643
|
+
a: 1
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
if (hex.length === 8) {
|
|
647
|
+
return {
|
|
648
|
+
r: parseInt(hex.slice(0, 2), 16),
|
|
649
|
+
g: parseInt(hex.slice(2, 4), 16),
|
|
650
|
+
b: parseInt(hex.slice(4, 6), 16),
|
|
651
|
+
a: parseInt(hex.slice(6, 8), 16) / 255
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
const match = trimmed.match(/^rgba?\s*\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)(?:\s*,\s*([\d.]+))?\s*\)$/);
|
|
656
|
+
if (match) {
|
|
657
|
+
return {
|
|
658
|
+
r: Math.min(255, Math.max(0, parseFloat(match[1]))),
|
|
659
|
+
g: Math.min(255, Math.max(0, parseFloat(match[2]))),
|
|
660
|
+
b: Math.min(255, Math.max(0, parseFloat(match[3]))),
|
|
661
|
+
a: match[4] !== void 0 ? Math.min(1, Math.max(0, parseFloat(match[4]))) : 1
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
return null;
|
|
665
|
+
}
|
|
666
|
+
function interpolateColorString(from, to, t) {
|
|
667
|
+
const c1 = parseColor(from);
|
|
668
|
+
const c2 = parseColor(to);
|
|
669
|
+
if (!c1 || !c2) {
|
|
670
|
+
return t < 0.5 ? from : to;
|
|
671
|
+
}
|
|
672
|
+
const r = Math.round(c1.r + (c2.r - c1.r) * t);
|
|
673
|
+
const g = Math.round(c1.g + (c2.g - c1.g) * t);
|
|
674
|
+
const b = Math.round(c1.b + (c2.b - c1.b) * t);
|
|
675
|
+
const a = Math.round((c1.a + (c2.a - c1.a) * t) * 100) / 100;
|
|
676
|
+
if (a >= 1) {
|
|
677
|
+
return `#${r.toString(16).padStart(2, "0")}${g.toString(16).padStart(2, "0")}${b.toString(16).padStart(2, "0")}`;
|
|
678
|
+
}
|
|
679
|
+
return `rgba(${r}, ${g}, ${b}, ${a})`;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
// src/contracts.ts
|
|
683
|
+
var CANONICAL_RENDERER_VERSION = "1.4.0";
|
|
684
|
+
|
|
685
|
+
// src/textTemplates/contract.ts
|
|
686
|
+
var TEXT_TEMPLATE_KIND = "text-template";
|
|
687
|
+
var TEXT_TEMPLATE_SCHEMA_VERSION = 4;
|
|
688
|
+
var TEXT_TEMPLATE_RENDERER_VERSION = "1.5.0";
|
|
689
|
+
|
|
690
|
+
// src/engine/textLayout.ts
|
|
691
|
+
function measureLine(ctx, line, letterSpacing) {
|
|
692
|
+
const prev = ctx.letterSpacing;
|
|
693
|
+
if (letterSpacing !== 0) {
|
|
694
|
+
ctx.letterSpacing = `${letterSpacing}px`;
|
|
695
|
+
}
|
|
696
|
+
const w = ctx.measureText(line || " ").width;
|
|
697
|
+
ctx.letterSpacing = prev ?? "0px";
|
|
698
|
+
return w;
|
|
699
|
+
}
|
|
700
|
+
function getSafeRect(cfg) {
|
|
701
|
+
const w = cfg.canvasWidth || DEFAULT_CANVAS_WIDTH;
|
|
702
|
+
const h = cfg.canvasHeight || DEFAULT_CANVAS_HEIGHT;
|
|
703
|
+
const marginX = cfg.panelEnabled ? (cfg.panelPaddingX ?? 40) + 16 : Math.min(48, w * 0.06);
|
|
704
|
+
const marginY = cfg.panelEnabled ? (cfg.panelPaddingY ?? 20) + 16 : Math.min(40, h * 0.1);
|
|
705
|
+
return {
|
|
706
|
+
x: marginX,
|
|
707
|
+
y: marginY,
|
|
708
|
+
width: Math.max(40, w - marginX * 2),
|
|
709
|
+
height: Math.max(24, h - marginY * 2)
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
function wrapTextToWidth(ctx, text, maxWidth, letterSpacing) {
|
|
713
|
+
const paragraphs = text.split("\n");
|
|
714
|
+
const lines = [];
|
|
715
|
+
for (const para of paragraphs) {
|
|
716
|
+
if (para === "") {
|
|
717
|
+
lines.push("");
|
|
718
|
+
continue;
|
|
719
|
+
}
|
|
720
|
+
let current = "";
|
|
721
|
+
for (let i = 0; i < para.length; i++) {
|
|
722
|
+
const char = para[i];
|
|
723
|
+
const tryLine = current + char;
|
|
724
|
+
if (measureLine(ctx, tryLine, letterSpacing) <= maxWidth) {
|
|
725
|
+
current = tryLine;
|
|
726
|
+
} else {
|
|
727
|
+
if (current) {
|
|
728
|
+
lines.push(current);
|
|
729
|
+
}
|
|
730
|
+
current = char;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
if (current) {
|
|
734
|
+
lines.push(current);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
return lines.length > 0 ? lines : [""];
|
|
738
|
+
}
|
|
739
|
+
function layoutWithFontSize(ctx, cfg, fontSize, lines) {
|
|
740
|
+
const cWidth = cfg.canvasWidth || DEFAULT_CANVAS_WIDTH;
|
|
741
|
+
const cHeight = cfg.canvasHeight || DEFAULT_CANVAS_HEIGHT;
|
|
742
|
+
const safe = getSafeRect(cfg);
|
|
743
|
+
const lineHeight = cfg.lineHeight ?? 1.2;
|
|
744
|
+
const letterSpacing = cfg.letterSpacing ?? 0;
|
|
745
|
+
const fontStr = `${cfg.fontStyle} ${cfg.fontWeight} ${fontSize}px "${cfg.fontFamily}"`;
|
|
746
|
+
ctx.font = fontStr;
|
|
747
|
+
const lineWidths = lines.map((line) => measureLine(ctx, line, letterSpacing));
|
|
748
|
+
const maxLineWidth = Math.max(...lineWidths, 1);
|
|
749
|
+
const textBlockHeight = lines.length === 1 ? fontSize : (lines.length - 1) * fontSize * lineHeight + fontSize;
|
|
750
|
+
let align = "center";
|
|
751
|
+
let startX = cWidth / 2;
|
|
752
|
+
if (cfg.textPosX === "left") {
|
|
753
|
+
align = "left";
|
|
754
|
+
startX = safe.x;
|
|
755
|
+
} else if (cfg.textPosX === "right") {
|
|
756
|
+
align = "right";
|
|
757
|
+
startX = safe.x + safe.width;
|
|
758
|
+
} else {
|
|
759
|
+
startX = safe.x + safe.width / 2;
|
|
760
|
+
}
|
|
761
|
+
let startY = safe.y + (safe.height - textBlockHeight) / 2 + fontSize * 0.85;
|
|
762
|
+
if (cfg.textPosY === "top") {
|
|
763
|
+
startY = safe.y + fontSize * 0.85;
|
|
764
|
+
} else if (cfg.textPosY === "bottom") {
|
|
765
|
+
startY = safe.y + safe.height - textBlockHeight + fontSize * 0.85;
|
|
766
|
+
}
|
|
767
|
+
let xMin = startX;
|
|
768
|
+
if (align === "center") xMin = startX - maxLineWidth / 2;
|
|
769
|
+
else if (align === "right") xMin = startX - maxLineWidth;
|
|
770
|
+
const yMin = startY - fontSize * 0.85;
|
|
771
|
+
const yMax = startY + (lines.length - 1) * fontSize * lineHeight + fontSize * 0.15;
|
|
772
|
+
return {
|
|
773
|
+
lines,
|
|
774
|
+
fontSize,
|
|
775
|
+
startX,
|
|
776
|
+
startY,
|
|
777
|
+
align,
|
|
778
|
+
lineWidths,
|
|
779
|
+
bounds: {
|
|
780
|
+
xMin,
|
|
781
|
+
yMin,
|
|
782
|
+
xMax: xMin + maxLineWidth,
|
|
783
|
+
yMax,
|
|
784
|
+
maxLineWidth,
|
|
785
|
+
textBlockHeight
|
|
786
|
+
},
|
|
787
|
+
safeRect: safe
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
function measureTextFits(ctx, cfg, fontSize, lines) {
|
|
791
|
+
const safe = getSafeRect(cfg);
|
|
792
|
+
const lineHeight = cfg.lineHeight ?? 1.2;
|
|
793
|
+
const layout = layoutWithFontSize(ctx, cfg, fontSize, lines);
|
|
794
|
+
return layout.bounds.maxLineWidth <= safe.width + 1 && layout.bounds.textBlockHeight <= safe.height + 1;
|
|
795
|
+
}
|
|
796
|
+
function computeAutoFitFontSize(ctx, cfg, wrappedLines) {
|
|
797
|
+
const max = Math.min(cfg.fontSize || DEFAULT_FONT_SIZE, 200);
|
|
798
|
+
let lo = 12;
|
|
799
|
+
let hi = max;
|
|
800
|
+
let best = 12;
|
|
801
|
+
while (lo <= hi) {
|
|
802
|
+
const mid = Math.floor((lo + hi) / 2);
|
|
803
|
+
if (measureTextFits(ctx, cfg, mid, wrappedLines)) {
|
|
804
|
+
best = mid;
|
|
805
|
+
lo = mid + 1;
|
|
806
|
+
} else {
|
|
807
|
+
hi = mid - 1;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
return best;
|
|
811
|
+
}
|
|
812
|
+
function computeTextLayout(ctx, cfg, options) {
|
|
813
|
+
const safe = getSafeRect(cfg);
|
|
814
|
+
const wrap = options?.wrap ?? true;
|
|
815
|
+
const autoFit = options?.autoFit ?? !!cfg.autoFitText;
|
|
816
|
+
let lines = cfg.text.split("\n");
|
|
817
|
+
if (wrap) {
|
|
818
|
+
lines = wrapTextToWidth(ctx, cfg.text, safe.width, cfg.letterSpacing ?? 0);
|
|
819
|
+
}
|
|
820
|
+
let fontSize = cfg.fontSize;
|
|
821
|
+
if (autoFit) {
|
|
822
|
+
fontSize = computeAutoFitFontSize(ctx, cfg, lines);
|
|
823
|
+
}
|
|
824
|
+
return layoutWithFontSize(ctx, cfg, fontSize, lines);
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
// src/engine/perCharFill.ts
|
|
828
|
+
function measureLineWidth(ctx, line, letterSpacing) {
|
|
829
|
+
if (!line) return 0;
|
|
830
|
+
let w = 0;
|
|
831
|
+
for (let i = 0; i < line.length; i++) {
|
|
832
|
+
w += ctx.measureText(line[i]).width;
|
|
833
|
+
if (i < line.length - 1) w += letterSpacing;
|
|
834
|
+
}
|
|
835
|
+
return w;
|
|
836
|
+
}
|
|
837
|
+
function drawPerCharText(ctx, opts) {
|
|
838
|
+
const {
|
|
839
|
+
lines,
|
|
840
|
+
startX,
|
|
841
|
+
startY,
|
|
842
|
+
lineAdvance,
|
|
843
|
+
align,
|
|
844
|
+
letterSpacing,
|
|
845
|
+
charFillColors,
|
|
846
|
+
defaultColor,
|
|
847
|
+
mode,
|
|
848
|
+
offsetX = 0,
|
|
849
|
+
offsetY = 0
|
|
850
|
+
} = opts;
|
|
851
|
+
ctx.save();
|
|
852
|
+
const prevSpacing = ctx.letterSpacing;
|
|
853
|
+
ctx.letterSpacing = "0px";
|
|
854
|
+
ctx.textBaseline = "alphabetic";
|
|
855
|
+
let glyphIndex = 0;
|
|
856
|
+
lines.forEach((line, lineIndex) => {
|
|
857
|
+
const py = startY + lineIndex * lineAdvance;
|
|
858
|
+
const lineWidth = measureLineWidth(ctx, line, letterSpacing);
|
|
859
|
+
let x = startX;
|
|
860
|
+
if (align === "center") x = startX - lineWidth / 2;
|
|
861
|
+
else if (align === "right") x = startX - lineWidth;
|
|
862
|
+
for (let i = 0; i < line.length; i++) {
|
|
863
|
+
const ch = line[i];
|
|
864
|
+
const color = charFillColors[glyphIndex] ?? defaultColor;
|
|
865
|
+
if (mode === "fill") ctx.fillStyle = color;
|
|
866
|
+
else ctx.strokeStyle = color;
|
|
867
|
+
const drawX = x + offsetX;
|
|
868
|
+
const drawY = py + offsetY;
|
|
869
|
+
if (mode === "fill") ctx.fillText(ch, drawX, drawY);
|
|
870
|
+
else ctx.strokeText(ch, drawX, drawY);
|
|
871
|
+
x += ctx.measureText(ch).width + letterSpacing;
|
|
872
|
+
glyphIndex++;
|
|
873
|
+
}
|
|
874
|
+
});
|
|
875
|
+
ctx.letterSpacing = prevSpacing ?? "0px";
|
|
876
|
+
ctx.restore();
|
|
877
|
+
}
|
|
878
|
+
function shouldUsePerCharFill(cfg) {
|
|
879
|
+
return !!cfg.perCharFillEnabled && cfg.fillType === "solid" && (cfg.charFillColors?.length ?? 0) > 0;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
// src/platform.ts
|
|
883
|
+
var _ctxFilter = null;
|
|
884
|
+
var _roundRect = null;
|
|
885
|
+
var _offscreenCanvas = null;
|
|
886
|
+
function probe2d() {
|
|
887
|
+
if (typeof OffscreenCanvas !== "undefined") {
|
|
888
|
+
try {
|
|
889
|
+
return new OffscreenCanvas(1, 1).getContext("2d");
|
|
890
|
+
} catch {
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
if (typeof document !== "undefined") {
|
|
894
|
+
try {
|
|
895
|
+
return document.createElement("canvas").getContext("2d");
|
|
896
|
+
} catch {
|
|
897
|
+
return null;
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
return null;
|
|
901
|
+
}
|
|
902
|
+
function supportsCtxFilter() {
|
|
903
|
+
if (_ctxFilter !== null) return _ctxFilter;
|
|
904
|
+
const ctx = probe2d();
|
|
905
|
+
if (!ctx) {
|
|
906
|
+
_ctxFilter = false;
|
|
907
|
+
return false;
|
|
908
|
+
}
|
|
909
|
+
try {
|
|
910
|
+
ctx.filter = "blur(4px)";
|
|
911
|
+
_ctxFilter = typeof ctx.filter === "string" && ctx.filter.includes("blur");
|
|
912
|
+
} catch {
|
|
913
|
+
_ctxFilter = false;
|
|
914
|
+
}
|
|
915
|
+
return _ctxFilter;
|
|
916
|
+
}
|
|
917
|
+
function supportsRoundRect() {
|
|
918
|
+
if (_roundRect !== null) return _roundRect;
|
|
919
|
+
const ctx = probe2d();
|
|
920
|
+
_roundRect = !!ctx && typeof ctx.roundRect === "function";
|
|
921
|
+
return _roundRect;
|
|
922
|
+
}
|
|
923
|
+
function supportsOffscreenCanvas() {
|
|
924
|
+
if (_offscreenCanvas !== null) return _offscreenCanvas;
|
|
925
|
+
_offscreenCanvas = typeof globalThis !== "undefined" && typeof globalThis.OffscreenCanvas === "function";
|
|
926
|
+
return _offscreenCanvas;
|
|
927
|
+
}
|
|
928
|
+
function createCanvas(width, height) {
|
|
929
|
+
if (supportsOffscreenCanvas()) {
|
|
930
|
+
return new OffscreenCanvas(width, height);
|
|
931
|
+
}
|
|
932
|
+
if (typeof document !== "undefined") {
|
|
933
|
+
const canvas = document.createElement("canvas");
|
|
934
|
+
canvas.width = width;
|
|
935
|
+
canvas.height = height;
|
|
936
|
+
return canvas;
|
|
937
|
+
}
|
|
938
|
+
const factory = globalThis.__clypraCreateCanvas;
|
|
939
|
+
if (factory) return factory(width, height);
|
|
940
|
+
try {
|
|
941
|
+
const nodeRequire = (0, eval)("require");
|
|
942
|
+
const nodeCanvas = nodeRequire("@napi-rs/canvas");
|
|
943
|
+
return nodeCanvas.createCanvas(width, height);
|
|
944
|
+
} catch {
|
|
945
|
+
throw new Error("[clypra/engine] No canvas implementation available in this environment. Set globalThis.__clypraCreateCanvas or install @napi-rs/canvas.");
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
function releaseCanvas(canvas) {
|
|
949
|
+
if (typeof OffscreenCanvas !== "undefined" && canvas instanceof OffscreenCanvas) return;
|
|
950
|
+
canvas.width = 0;
|
|
951
|
+
canvas.height = 0;
|
|
952
|
+
}
|
|
953
|
+
var CanvasDevice = class {
|
|
954
|
+
static canvases = [];
|
|
955
|
+
static maxPoolSize = 10;
|
|
956
|
+
/**
|
|
957
|
+
* Acquire a Canvas context from the pool or create a new one.
|
|
958
|
+
* If a canvas is pulled from the pool, it is resized to the target dimensions.
|
|
959
|
+
*/
|
|
960
|
+
static acquire(width, height) {
|
|
961
|
+
let canvas;
|
|
962
|
+
if (this.canvases.length > 0) {
|
|
963
|
+
canvas = this.canvases.pop();
|
|
964
|
+
if (canvas.width !== width || canvas.height !== height) {
|
|
965
|
+
canvas.width = width;
|
|
966
|
+
canvas.height = height;
|
|
967
|
+
}
|
|
968
|
+
} else {
|
|
969
|
+
canvas = createCanvas(width, height);
|
|
970
|
+
}
|
|
971
|
+
return canvas;
|
|
972
|
+
}
|
|
973
|
+
/**
|
|
974
|
+
* Release a canvas back to the pool, or free its resources immediately if pool is full.
|
|
975
|
+
*/
|
|
976
|
+
static release(canvas) {
|
|
977
|
+
if (this.canvases.length < this.maxPoolSize) {
|
|
978
|
+
this.canvases.push(canvas);
|
|
979
|
+
} else {
|
|
980
|
+
releaseCanvas(canvas);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
/**
|
|
984
|
+
* Disposes all pooled canvases to release GPU/memory backing stores.
|
|
985
|
+
*/
|
|
986
|
+
static clearPool() {
|
|
987
|
+
while (this.canvases.length > 0) {
|
|
988
|
+
const c = this.canvases.pop();
|
|
989
|
+
releaseCanvas(c);
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
};
|
|
993
|
+
|
|
994
|
+
// src/canvas-utils.ts
|
|
995
|
+
function drawRoundedRect(ctx, x, y, w, h, r) {
|
|
996
|
+
const radius = Math.max(0, Math.min(r, Math.min(w, h) / 2));
|
|
997
|
+
ctx.beginPath();
|
|
998
|
+
if (supportsRoundRect()) {
|
|
999
|
+
ctx.roundRect(x, y, w, h, radius);
|
|
1000
|
+
} else {
|
|
1001
|
+
ctx.moveTo(x + radius, y);
|
|
1002
|
+
ctx.lineTo(x + w - radius, y);
|
|
1003
|
+
ctx.quadraticCurveTo(x + w, y, x + w, y + radius);
|
|
1004
|
+
ctx.lineTo(x + w, y + h - radius);
|
|
1005
|
+
ctx.quadraticCurveTo(x + w, y + h, x + w - radius, y + h);
|
|
1006
|
+
ctx.lineTo(x + radius, y + h);
|
|
1007
|
+
ctx.quadraticCurveTo(x, y + h, x, y + h - radius);
|
|
1008
|
+
ctx.lineTo(x, y + radius);
|
|
1009
|
+
ctx.quadraticCurveTo(x, y, x + radius, y);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
// src/engine/procedural/utils.ts
|
|
1014
|
+
function hexToRgb(hex) {
|
|
1015
|
+
const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
|
|
1016
|
+
const fullHex = hex.replace(shorthandRegex, (m, r, g, b) => r + r + g + g + b + b);
|
|
1017
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(fullHex);
|
|
1018
|
+
return result ? {
|
|
1019
|
+
r: parseInt(result[1], 16),
|
|
1020
|
+
g: parseInt(result[2], 16),
|
|
1021
|
+
b: parseInt(result[3], 16)
|
|
1022
|
+
} : { r: 255, g: 255, b: 255 };
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
// src/renderer.ts
|
|
1026
|
+
function getCanvas2DContext(canvas) {
|
|
1027
|
+
return canvas.getContext("2d");
|
|
1028
|
+
}
|
|
1029
|
+
function ctxSupportsFilter(ctx) {
|
|
1030
|
+
try {
|
|
1031
|
+
const prev = ctx.filter;
|
|
1032
|
+
ctx.filter = "blur(4px)";
|
|
1033
|
+
const ok = typeof ctx.filter === "string" && ctx.filter.includes("blur");
|
|
1034
|
+
ctx.filter = prev;
|
|
1035
|
+
return ok;
|
|
1036
|
+
} catch {
|
|
1037
|
+
return false;
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
function renderTextEffectCore(ctx, cfg) {
|
|
1041
|
+
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;
|
|
1042
|
+
ctx.imageSmoothingEnabled = true;
|
|
1043
|
+
ctx.lineJoin = strokeLineJoin;
|
|
1044
|
+
const cWidth = canvasWidth || DEFAULT_CANVAS_WIDTH;
|
|
1045
|
+
const cHeight = canvasHeight || DEFAULT_CANVAS_HEIGHT;
|
|
1046
|
+
const layout = computeTextLayout(ctx, cfg, {
|
|
1047
|
+
wrap: cfg.wrapText !== false,
|
|
1048
|
+
autoFit: !!cfg.autoFitText
|
|
1049
|
+
});
|
|
1050
|
+
const lines = layout.lines;
|
|
1051
|
+
const numLines = lines.length;
|
|
1052
|
+
const effectiveFontSize = layout.fontSize;
|
|
1053
|
+
const lineAdvance = effectiveFontSize * lineHeight;
|
|
1054
|
+
const textBlockHeight = layout.bounds.textBlockHeight;
|
|
1055
|
+
let startX = layout.startX;
|
|
1056
|
+
let startY = layout.startY;
|
|
1057
|
+
const align = layout.align;
|
|
1058
|
+
const maxLineWidth = layout.bounds.maxLineWidth;
|
|
1059
|
+
const lineWidths = layout.lineWidths;
|
|
1060
|
+
const fontStr = `${fontStyle} ${fontWeight} ${effectiveFontSize}px "${fontFamily}"`;
|
|
1061
|
+
ctx.font = fontStr;
|
|
1062
|
+
ctx.textAlign = align;
|
|
1063
|
+
if (letterSpacing !== 0) {
|
|
1064
|
+
ctx.letterSpacing = `${letterSpacing}px`;
|
|
1065
|
+
}
|
|
1066
|
+
let xMin = layout.bounds.xMin;
|
|
1067
|
+
let xMax = layout.bounds.xMax;
|
|
1068
|
+
let yMin = layout.bounds.yMin;
|
|
1069
|
+
let yMax = layout.bounds.yMax;
|
|
1070
|
+
let shiftX_half = 0;
|
|
1071
|
+
let shiftY_half = 0;
|
|
1072
|
+
if (bevelEnabled && bevelDepth > 0) {
|
|
1073
|
+
if (bevelPerspectiveEnabled) {
|
|
1074
|
+
const vpx = cWidth / 2 + (bevelVanishingPointX !== void 0 ? bevelVanishingPointX : 40) / 100 * (cWidth / 2);
|
|
1075
|
+
const vpy = cHeight / 2 + (bevelVanishingPointY !== void 0 ? bevelVanishingPointY : 80) / 100 * (cHeight / 2);
|
|
1076
|
+
const fl = Math.max(100, bevelFocalLength !== void 0 ? bevelFocalLength : 400);
|
|
1077
|
+
const scale = fl / (fl + bevelDepth);
|
|
1078
|
+
const shiftX_back = (vpx - startX) * (1 - scale);
|
|
1079
|
+
const shiftY_back = (vpy - startY) * (1 - scale);
|
|
1080
|
+
shiftX_half = shiftX_back / 2;
|
|
1081
|
+
shiftY_half = shiftY_back / 2;
|
|
1082
|
+
} else {
|
|
1083
|
+
let dx = 0;
|
|
1084
|
+
let dy = 0;
|
|
1085
|
+
if (bevelDirection === "bottom-right") {
|
|
1086
|
+
dx = bevelDepth;
|
|
1087
|
+
dy = bevelDepth;
|
|
1088
|
+
} else if (bevelDirection === "bottom") {
|
|
1089
|
+
dy = bevelDepth;
|
|
1090
|
+
} else if (bevelDirection === "right") {
|
|
1091
|
+
dx = bevelDepth;
|
|
1092
|
+
}
|
|
1093
|
+
shiftX_half = dx / 2;
|
|
1094
|
+
shiftY_half = dy / 2;
|
|
1095
|
+
}
|
|
1096
|
+
startX -= shiftX_half;
|
|
1097
|
+
startY -= shiftY_half;
|
|
1098
|
+
xMin -= shiftX_half;
|
|
1099
|
+
xMax -= shiftX_half;
|
|
1100
|
+
yMin -= shiftY_half;
|
|
1101
|
+
yMax -= shiftY_half;
|
|
1102
|
+
}
|
|
1103
|
+
let total_xMin = xMin;
|
|
1104
|
+
let total_xMax = xMax;
|
|
1105
|
+
let total_yMin = yMin;
|
|
1106
|
+
let total_yMax = yMax;
|
|
1107
|
+
if (bevelEnabled && bevelDepth > 0) {
|
|
1108
|
+
if (bevelPerspectiveEnabled) {
|
|
1109
|
+
const vpx = cWidth / 2 + (bevelVanishingPointX !== void 0 ? bevelVanishingPointX : 40) / 100 * (cWidth / 2);
|
|
1110
|
+
const vpy = cHeight / 2 + (bevelVanishingPointY !== void 0 ? bevelVanishingPointY : 80) / 100 * (cHeight / 2);
|
|
1111
|
+
const fl = Math.max(100, bevelFocalLength !== void 0 ? bevelFocalLength : 400);
|
|
1112
|
+
const scale = fl / (fl + bevelDepth);
|
|
1113
|
+
const x_new_left = vpx + (xMin - vpx) * scale;
|
|
1114
|
+
const x_new_right = vpx + (xMax - vpx) * scale;
|
|
1115
|
+
const y_new_top = vpy + (yMin - vpy) * scale;
|
|
1116
|
+
const y_new_bottom = vpy + (yMax - vpy) * scale;
|
|
1117
|
+
total_xMin = Math.min(xMin, x_new_left, x_new_right);
|
|
1118
|
+
total_xMax = Math.max(xMax, x_new_left, x_new_right);
|
|
1119
|
+
total_yMin = Math.min(yMin, y_new_top, y_new_bottom);
|
|
1120
|
+
total_yMax = Math.max(yMax, y_new_top, y_new_bottom);
|
|
1121
|
+
} else {
|
|
1122
|
+
let dx = 0;
|
|
1123
|
+
let dy = 0;
|
|
1124
|
+
if (bevelDirection === "bottom-right") {
|
|
1125
|
+
dx = bevelDepth;
|
|
1126
|
+
dy = bevelDepth;
|
|
1127
|
+
} else if (bevelDirection === "bottom") {
|
|
1128
|
+
dy = bevelDepth;
|
|
1129
|
+
} else if (bevelDirection === "right") {
|
|
1130
|
+
dx = bevelDepth;
|
|
1131
|
+
}
|
|
1132
|
+
total_xMin = Math.min(xMin, xMin + dx);
|
|
1133
|
+
total_xMax = Math.max(xMax, xMax + dx);
|
|
1134
|
+
total_yMin = Math.min(yMin, yMin + dy);
|
|
1135
|
+
total_yMax = Math.max(yMax, yMax + dy);
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
const usePerCharFill = shouldUsePerCharFill(cfg);
|
|
1139
|
+
const perCharColors = cfg.charFillColors ?? [];
|
|
1140
|
+
const renderLines = (mode, overrideStyle, offsetX = 0, offsetY = 0, options) => {
|
|
1141
|
+
if (options?.perCharFill && usePerCharFill && mode === "fill" && !overrideStyle) {
|
|
1142
|
+
drawPerCharText(ctx, {
|
|
1143
|
+
lines,
|
|
1144
|
+
startX,
|
|
1145
|
+
startY,
|
|
1146
|
+
lineAdvance,
|
|
1147
|
+
align,
|
|
1148
|
+
letterSpacing,
|
|
1149
|
+
charFillColors: perCharColors,
|
|
1150
|
+
defaultColor: fillColor,
|
|
1151
|
+
mode: "fill",
|
|
1152
|
+
offsetX,
|
|
1153
|
+
offsetY
|
|
1154
|
+
});
|
|
1155
|
+
return;
|
|
1156
|
+
}
|
|
1157
|
+
const savedLetterSpacing = ctx.letterSpacing || "normal";
|
|
1158
|
+
if (letterSpacing !== 0) {
|
|
1159
|
+
ctx.letterSpacing = `${letterSpacing}px`;
|
|
1160
|
+
}
|
|
1161
|
+
if (overrideStyle) {
|
|
1162
|
+
if (mode === "fill") {
|
|
1163
|
+
ctx.fillStyle = overrideStyle;
|
|
1164
|
+
} else {
|
|
1165
|
+
ctx.strokeStyle = overrideStyle;
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
lines.forEach((line, index) => {
|
|
1169
|
+
const py = startY + index * lineAdvance;
|
|
1170
|
+
if (mode === "fill") {
|
|
1171
|
+
ctx.fillText(line, startX + offsetX, py + offsetY);
|
|
1172
|
+
} else {
|
|
1173
|
+
ctx.strokeText(line, startX + offsetX, py + offsetY);
|
|
1174
|
+
}
|
|
1175
|
+
});
|
|
1176
|
+
ctx.letterSpacing = savedLetterSpacing;
|
|
1177
|
+
};
|
|
1178
|
+
const renderWithShadowTrick = (mode, sColor, sBlur, sOffsetX, sOffsetY, opacity, overrideStyle = "#000", spread = 0) => {
|
|
1179
|
+
ctx.save();
|
|
1180
|
+
ctx.globalAlpha = opacity / 100;
|
|
1181
|
+
const shiftX = 1e4;
|
|
1182
|
+
ctx.shadowColor = sColor;
|
|
1183
|
+
ctx.shadowBlur = sBlur;
|
|
1184
|
+
ctx.shadowOffsetX = shiftX + sOffsetX;
|
|
1185
|
+
ctx.shadowOffsetY = sOffsetY;
|
|
1186
|
+
const savedLetterSpacing = ctx.letterSpacing || "normal";
|
|
1187
|
+
if (letterSpacing !== 0) {
|
|
1188
|
+
ctx.letterSpacing = `${letterSpacing}px`;
|
|
1189
|
+
}
|
|
1190
|
+
const prevStyle = mode === "fill" ? ctx.fillStyle : ctx.strokeStyle;
|
|
1191
|
+
if (mode === "fill") {
|
|
1192
|
+
ctx.fillStyle = overrideStyle;
|
|
1193
|
+
} else {
|
|
1194
|
+
ctx.strokeStyle = overrideStyle;
|
|
1195
|
+
}
|
|
1196
|
+
const prevStrokeStyle = ctx.strokeStyle;
|
|
1197
|
+
const prevLineWidth = ctx.lineWidth;
|
|
1198
|
+
if (spread > 0) {
|
|
1199
|
+
ctx.strokeStyle = overrideStyle;
|
|
1200
|
+
ctx.lineWidth = spread * 2;
|
|
1201
|
+
ctx.lineJoin = strokeLineJoin;
|
|
1202
|
+
}
|
|
1203
|
+
lines.forEach((line, index) => {
|
|
1204
|
+
const py = startY + index * lineAdvance;
|
|
1205
|
+
if (mode === "fill") {
|
|
1206
|
+
if (spread > 0) {
|
|
1207
|
+
ctx.strokeText(line, startX - shiftX, py);
|
|
1208
|
+
}
|
|
1209
|
+
ctx.fillText(line, startX - shiftX, py);
|
|
1210
|
+
} else {
|
|
1211
|
+
ctx.strokeText(line, startX - shiftX, py);
|
|
1212
|
+
}
|
|
1213
|
+
});
|
|
1214
|
+
ctx.letterSpacing = savedLetterSpacing;
|
|
1215
|
+
if (mode === "fill") {
|
|
1216
|
+
ctx.fillStyle = prevStyle;
|
|
1217
|
+
} else {
|
|
1218
|
+
ctx.strokeStyle = prevStyle;
|
|
1219
|
+
}
|
|
1220
|
+
if (spread > 0) {
|
|
1221
|
+
ctx.strokeStyle = prevStrokeStyle;
|
|
1222
|
+
ctx.lineWidth = prevLineWidth;
|
|
1223
|
+
}
|
|
1224
|
+
ctx.restore();
|
|
1225
|
+
};
|
|
1226
|
+
const renderGlowLayer = (layer2) => {
|
|
1227
|
+
let glowCanvas = null;
|
|
1228
|
+
try {
|
|
1229
|
+
glowCanvas = createCanvas(Math.max(1, Math.ceil(cWidth)), Math.max(1, Math.ceil(cHeight)));
|
|
1230
|
+
const glowCtx = getCanvas2DContext(glowCanvas);
|
|
1231
|
+
if (!glowCtx) return false;
|
|
1232
|
+
glowCtx.clearRect(0, 0, cWidth, cHeight);
|
|
1233
|
+
glowCtx.save();
|
|
1234
|
+
glowCtx.font = fontStr;
|
|
1235
|
+
glowCtx.textAlign = align;
|
|
1236
|
+
glowCtx.textBaseline = "alphabetic";
|
|
1237
|
+
if (letterSpacing !== 0) glowCtx.letterSpacing = `${letterSpacing}px`;
|
|
1238
|
+
glowCtx.globalAlpha = Math.max(0, Math.min(100, layer2.opacity)) / 100;
|
|
1239
|
+
glowCtx.fillStyle = layer2.color;
|
|
1240
|
+
glowCtx.strokeStyle = layer2.color;
|
|
1241
|
+
const spread = Math.max(0, layer2.spread ?? 0);
|
|
1242
|
+
if (spread > 0) {
|
|
1243
|
+
glowCtx.lineWidth = spread * 2;
|
|
1244
|
+
glowCtx.lineJoin = strokeLineJoin;
|
|
1245
|
+
}
|
|
1246
|
+
const drawSource = () => {
|
|
1247
|
+
lines.forEach((line, index) => {
|
|
1248
|
+
const py = startY + index * lineAdvance;
|
|
1249
|
+
if (spread > 0) glowCtx.strokeText(line, startX, py);
|
|
1250
|
+
glowCtx.fillText(line, startX, py);
|
|
1251
|
+
});
|
|
1252
|
+
};
|
|
1253
|
+
const useFilter = ctxSupportsFilter(glowCtx);
|
|
1254
|
+
if (useFilter) {
|
|
1255
|
+
glowCtx.filter = `blur(${Math.max(0, layer2.blur)}px)`;
|
|
1256
|
+
drawSource();
|
|
1257
|
+
glowCtx.filter = "none";
|
|
1258
|
+
} else {
|
|
1259
|
+
glowCtx.shadowColor = layer2.color;
|
|
1260
|
+
glowCtx.shadowBlur = Math.max(0, layer2.blur);
|
|
1261
|
+
glowCtx.shadowOffsetX = 0;
|
|
1262
|
+
glowCtx.shadowOffsetY = 0;
|
|
1263
|
+
drawSource();
|
|
1264
|
+
glowCtx.shadowColor = "transparent";
|
|
1265
|
+
glowCtx.shadowBlur = 0;
|
|
1266
|
+
}
|
|
1267
|
+
glowCtx.globalCompositeOperation = "destination-out";
|
|
1268
|
+
glowCtx.globalAlpha = 1;
|
|
1269
|
+
drawSource();
|
|
1270
|
+
glowCtx.restore();
|
|
1271
|
+
ctx.save();
|
|
1272
|
+
if (layer2.type === "inner") {
|
|
1273
|
+
ctx.globalCompositeOperation = "source-atop";
|
|
1274
|
+
}
|
|
1275
|
+
ctx.globalAlpha = 1;
|
|
1276
|
+
const passes = Math.max(1, Math.min(20, layer2.strength ?? 1));
|
|
1277
|
+
for (let pass = 0; pass < passes; pass += 1) {
|
|
1278
|
+
ctx.drawImage(glowCanvas, 0, 0);
|
|
1279
|
+
}
|
|
1280
|
+
ctx.restore();
|
|
1281
|
+
return true;
|
|
1282
|
+
} catch {
|
|
1283
|
+
return false;
|
|
1284
|
+
} finally {
|
|
1285
|
+
if (glowCanvas) releaseCanvas(glowCanvas);
|
|
1286
|
+
}
|
|
1287
|
+
};
|
|
1288
|
+
if (panelEnabled) {
|
|
1289
|
+
ctx.save();
|
|
1290
|
+
ctx.globalAlpha = panelOpacity / 100;
|
|
1291
|
+
ctx.fillStyle = panelColor;
|
|
1292
|
+
const px = total_xMin - panelPaddingX;
|
|
1293
|
+
const py = total_yMin - panelPaddingY;
|
|
1294
|
+
const pw = total_xMax - total_xMin + 2 * panelPaddingX;
|
|
1295
|
+
const ph = total_yMax - total_yMin + 2 * panelPaddingY;
|
|
1296
|
+
const cx = px + pw / 2;
|
|
1297
|
+
const cy = py + ph / 2;
|
|
1298
|
+
const isComicBurst = cfg.effectName.toLowerCase().includes("comic") || cfg.panelStyle === "burst";
|
|
1299
|
+
ctx.beginPath();
|
|
1300
|
+
if (isComicBurst) {
|
|
1301
|
+
const numPoints = 36;
|
|
1302
|
+
const rx = pw * 0.56;
|
|
1303
|
+
const ry = ph * 0.68;
|
|
1304
|
+
for (let i = 0; i < numPoints; i++) {
|
|
1305
|
+
const angle = i / numPoints * Math.PI * 2;
|
|
1306
|
+
const wave1 = Math.sin(angle * 8) * 0.12;
|
|
1307
|
+
const wave3 = Math.cos(angle * 14) * 0.05;
|
|
1308
|
+
const isSpikePeak = i % 2 === 0;
|
|
1309
|
+
const depthFactor = isSpikePeak ? 1.12 + wave1 + wave3 : 0.76 - wave3;
|
|
1310
|
+
const sx = cx + Math.cos(angle) * rx * depthFactor;
|
|
1311
|
+
const sy = cy + Math.sin(angle) * ry * depthFactor;
|
|
1312
|
+
if (i === 0) {
|
|
1313
|
+
ctx.moveTo(sx, sy);
|
|
1314
|
+
} else {
|
|
1315
|
+
ctx.lineTo(sx, sy);
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
} else {
|
|
1319
|
+
drawRoundedRect(ctx, px, py, pw, ph, panelRadius);
|
|
1320
|
+
}
|
|
1321
|
+
ctx.closePath();
|
|
1322
|
+
ctx.fill();
|
|
1323
|
+
if (panelStrokeEnabled) {
|
|
1324
|
+
ctx.strokeStyle = panelStrokeColor;
|
|
1325
|
+
ctx.lineWidth = panelStrokeWidth;
|
|
1326
|
+
const prevLineJoin = ctx.lineJoin;
|
|
1327
|
+
if (isComicBurst) {
|
|
1328
|
+
ctx.lineJoin = "miter";
|
|
1329
|
+
}
|
|
1330
|
+
ctx.stroke();
|
|
1331
|
+
ctx.lineJoin = prevLineJoin;
|
|
1332
|
+
}
|
|
1333
|
+
ctx.restore();
|
|
1334
|
+
}
|
|
1335
|
+
glowLayers.forEach((layer2) => {
|
|
1336
|
+
if (layer2.enabled && layer2.type === "outer" && layer2.opacity > 0) {
|
|
1337
|
+
if (!renderGlowLayer(layer2)) {
|
|
1338
|
+
const renderCount = Math.max(1, Math.min(20, layer2.strength ?? 1));
|
|
1339
|
+
for (let i = 0; i < renderCount; i += 1) {
|
|
1340
|
+
renderWithShadowTrick("fill", layer2.color, layer2.blur, 0, 0, layer2.opacity, "#000", layer2.spread ?? 0);
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
});
|
|
1345
|
+
if (shadowEnabled && shadowType === "drop" && shadowOpacity > 0) {
|
|
1346
|
+
if (bevelEnabled && bevelDepth > 0) {
|
|
1347
|
+
if (bevelPerspectiveEnabled) {
|
|
1348
|
+
const vpx = cWidth / 2 + (bevelVanishingPointX !== void 0 ? bevelVanishingPointX : 40) / 100 * (cWidth / 2);
|
|
1349
|
+
const vpy = cHeight / 2 + (bevelVanishingPointY !== void 0 ? bevelVanishingPointY : 80) / 100 * (cHeight / 2);
|
|
1350
|
+
const fl = Math.max(100, bevelFocalLength !== void 0 ? bevelFocalLength : 400);
|
|
1351
|
+
const scale = fl / (fl + bevelDepth);
|
|
1352
|
+
ctx.save();
|
|
1353
|
+
ctx.translate(vpx, vpy);
|
|
1354
|
+
ctx.scale(scale, scale);
|
|
1355
|
+
ctx.translate(-vpx, -vpy);
|
|
1356
|
+
renderWithShadowTrick("fill", shadowColor, shadowBlur, shadowOffsetX, shadowOffsetY, shadowOpacity);
|
|
1357
|
+
ctx.restore();
|
|
1358
|
+
} else {
|
|
1359
|
+
let dx = 0;
|
|
1360
|
+
let dy = 0;
|
|
1361
|
+
if (bevelDirection === "bottom-right") {
|
|
1362
|
+
dx = bevelDepth;
|
|
1363
|
+
dy = bevelDepth;
|
|
1364
|
+
} else if (bevelDirection === "bottom") {
|
|
1365
|
+
dy = bevelDepth;
|
|
1366
|
+
} else if (bevelDirection === "right") {
|
|
1367
|
+
dx = bevelDepth;
|
|
1368
|
+
}
|
|
1369
|
+
renderWithShadowTrick("fill", shadowColor, shadowBlur, shadowOffsetX + dx, shadowOffsetY + dy, shadowOpacity);
|
|
1370
|
+
}
|
|
1371
|
+
} else {
|
|
1372
|
+
renderWithShadowTrick("fill", shadowColor, shadowBlur, shadowOffsetX, shadowOffsetY, shadowOpacity);
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
const isGlitch = cfg.effectName.toLowerCase().includes("glitch") || cfg.text === "SYSTEM ERR";
|
|
1376
|
+
if (isGlitch) {
|
|
1377
|
+
ctx.save();
|
|
1378
|
+
ctx.globalAlpha = 0.8;
|
|
1379
|
+
renderLines("fill", "#00FFFF", -4, -2);
|
|
1380
|
+
renderLines("fill", "#FF00FF", 4, 2);
|
|
1381
|
+
ctx.restore();
|
|
1382
|
+
}
|
|
1383
|
+
if (bevelEnabled && bevelDepth > 0) {
|
|
1384
|
+
const shadowRgb = hexToRgb(bevelShadow || "#1A0A00");
|
|
1385
|
+
const coreRgb = hexToRgb(bevelCoreColor || bevelShadow || "#3A1A00");
|
|
1386
|
+
const highlightRgb = hexToRgb(bevelHighlight || "#FFFFFF");
|
|
1387
|
+
const shadeForDepth = (t) => {
|
|
1388
|
+
const eased = t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
|
|
1389
|
+
if (eased <= 0.5) {
|
|
1390
|
+
const u = eased * 2;
|
|
1391
|
+
const r = Math.round(shadowRgb.r + (coreRgb.r - shadowRgb.r) * u);
|
|
1392
|
+
const g = Math.round(shadowRgb.g + (coreRgb.g - shadowRgb.g) * u);
|
|
1393
|
+
const b = Math.round(shadowRgb.b + (coreRgb.b - shadowRgb.b) * u);
|
|
1394
|
+
return `rgb(${r},${g},${b})`;
|
|
1395
|
+
} else {
|
|
1396
|
+
const u = (eased - 0.5) * 2;
|
|
1397
|
+
const r = Math.round(coreRgb.r + (highlightRgb.r - coreRgb.r) * u);
|
|
1398
|
+
const g = Math.round(coreRgb.g + (highlightRgb.g - coreRgb.g) * u);
|
|
1399
|
+
const b = Math.round(coreRgb.b + (highlightRgb.b - coreRgb.b) * u);
|
|
1400
|
+
return `rgb(${r},${g},${b})`;
|
|
1401
|
+
}
|
|
1402
|
+
};
|
|
1403
|
+
if (bevelPerspectiveEnabled) {
|
|
1404
|
+
const vpx = cWidth / 2 + (bevelVanishingPointX !== void 0 ? bevelVanishingPointX : 40) / 100 * (cWidth / 2);
|
|
1405
|
+
const vpy = cHeight / 2 + (bevelVanishingPointY !== void 0 ? bevelVanishingPointY : 80) / 100 * (cHeight / 2);
|
|
1406
|
+
const fl = Math.max(100, bevelFocalLength !== void 0 ? bevelFocalLength : 400);
|
|
1407
|
+
if (bevelBlur && bevelBlur > 0) {
|
|
1408
|
+
const blurColor = bevelBlurColor || bevelShadow || "#000000";
|
|
1409
|
+
if (ctxSupportsFilter(ctx)) {
|
|
1410
|
+
ctx.save();
|
|
1411
|
+
ctx.filter = `blur(${bevelBlur}px)`;
|
|
1412
|
+
for (let i = bevelDepth; i > 0; i -= Math.max(1, Math.floor(bevelDepth / 4))) {
|
|
1413
|
+
const scale = fl / (fl + i);
|
|
1414
|
+
ctx.save();
|
|
1415
|
+
ctx.translate(vpx, vpy);
|
|
1416
|
+
ctx.scale(scale, scale);
|
|
1417
|
+
ctx.translate(-vpx, -vpy);
|
|
1418
|
+
renderLines("fill", blurColor);
|
|
1419
|
+
ctx.restore();
|
|
1420
|
+
}
|
|
1421
|
+
ctx.restore();
|
|
1422
|
+
} else {
|
|
1423
|
+
for (let i = bevelDepth; i > 0; i -= Math.max(1, Math.floor(bevelDepth / 4))) {
|
|
1424
|
+
const scale = fl / (fl + i);
|
|
1425
|
+
ctx.save();
|
|
1426
|
+
ctx.translate(vpx, vpy);
|
|
1427
|
+
ctx.scale(scale, scale);
|
|
1428
|
+
ctx.translate(-vpx, -vpy);
|
|
1429
|
+
renderWithShadowTrick("fill", blurColor, bevelBlur, 0, 0, 100);
|
|
1430
|
+
ctx.restore();
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
ctx.save();
|
|
1435
|
+
for (let i = bevelDepth; i > 0; i--) {
|
|
1436
|
+
const t = 1 - (i - 1) / Math.max(1, bevelDepth - 1);
|
|
1437
|
+
const aoFactor = 0.35 + 0.65 * (1 - (i - 1) / Math.max(1, bevelDepth));
|
|
1438
|
+
const baseColor = shadeForDepth(t);
|
|
1439
|
+
const bRgb = hexToRgb(baseColor.startsWith("#") ? baseColor : "#000000");
|
|
1440
|
+
const baseRgbParsed = (() => {
|
|
1441
|
+
const m = baseColor.match(/rgb\((\d+),(\d+),(\d+)\)/);
|
|
1442
|
+
return m ? { r: +m[1], g: +m[2], b: +m[3] } : bRgb;
|
|
1443
|
+
})();
|
|
1444
|
+
const aoColor = `rgb(${Math.round(baseRgbParsed.r * aoFactor)},${Math.round(baseRgbParsed.g * aoFactor)},${Math.round(baseRgbParsed.b * aoFactor)})`;
|
|
1445
|
+
const scale = fl / (fl + i);
|
|
1446
|
+
ctx.save();
|
|
1447
|
+
ctx.translate(vpx, vpy);
|
|
1448
|
+
ctx.scale(scale, scale);
|
|
1449
|
+
ctx.translate(-vpx, -vpy);
|
|
1450
|
+
renderLines("fill", aoColor);
|
|
1451
|
+
if (bevelEdgeWidth && bevelEdgeWidth > 0) {
|
|
1452
|
+
ctx.save();
|
|
1453
|
+
ctx.strokeStyle = bevelEdgeColor || "#000000";
|
|
1454
|
+
ctx.lineWidth = bevelEdgeWidth;
|
|
1455
|
+
ctx.lineJoin = strokeLineJoin || "round";
|
|
1456
|
+
renderLines("stroke");
|
|
1457
|
+
ctx.restore();
|
|
1458
|
+
}
|
|
1459
|
+
ctx.restore();
|
|
1460
|
+
}
|
|
1461
|
+
ctx.restore();
|
|
1462
|
+
if (bevelEdgeWidth && bevelEdgeWidth > 0) {
|
|
1463
|
+
ctx.save();
|
|
1464
|
+
ctx.globalAlpha = 0.6;
|
|
1465
|
+
ctx.strokeStyle = bevelHighlight;
|
|
1466
|
+
ctx.lineWidth = Math.max(0.5, (bevelEdgeWidth || 1) * 0.5);
|
|
1467
|
+
ctx.lineJoin = strokeLineJoin || "round";
|
|
1468
|
+
renderLines("stroke");
|
|
1469
|
+
ctx.restore();
|
|
1470
|
+
}
|
|
1471
|
+
} else {
|
|
1472
|
+
const getDirOffset = (i) => {
|
|
1473
|
+
if (bevelDirection === "bottom-right") return { dx: i, dy: i };
|
|
1474
|
+
if (bevelDirection === "bottom") return { dx: 0, dy: i };
|
|
1475
|
+
if (bevelDirection === "right") return { dx: i, dy: 0 };
|
|
1476
|
+
return { dx: i, dy: i };
|
|
1477
|
+
};
|
|
1478
|
+
if (bevelBlur && bevelBlur > 0) {
|
|
1479
|
+
const blurColor = bevelBlurColor || bevelShadow || "#000000";
|
|
1480
|
+
if (ctxSupportsFilter(ctx)) {
|
|
1481
|
+
ctx.save();
|
|
1482
|
+
ctx.filter = `blur(${bevelBlur}px)`;
|
|
1483
|
+
for (let i = bevelDepth; i > 0; i -= Math.max(1, Math.floor(bevelDepth / 4))) {
|
|
1484
|
+
const { dx, dy } = getDirOffset(i);
|
|
1485
|
+
renderLines("fill", blurColor, dx, dy);
|
|
1486
|
+
}
|
|
1487
|
+
ctx.restore();
|
|
1488
|
+
} else {
|
|
1489
|
+
for (let i = bevelDepth; i > 0; i -= Math.max(1, Math.floor(bevelDepth / 4))) {
|
|
1490
|
+
const { dx, dy } = getDirOffset(i);
|
|
1491
|
+
renderWithShadowTrick("fill", blurColor, bevelBlur, dx, dy, 100);
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
ctx.save();
|
|
1496
|
+
for (let i = bevelDepth; i > 0; i--) {
|
|
1497
|
+
const { dx, dy } = getDirOffset(i);
|
|
1498
|
+
const t = 1 - (i - 1) / Math.max(1, bevelDepth - 1);
|
|
1499
|
+
const depthRatio = (i - 1) / Math.max(1, bevelDepth - 1);
|
|
1500
|
+
const aoFactor = 0.25 + 0.75 * (1 - depthRatio * 0.8);
|
|
1501
|
+
const baseColor = shadeForDepth(t);
|
|
1502
|
+
const baseRgbParsed = (() => {
|
|
1503
|
+
const m = baseColor.match(/rgb\((\d+),(\d+),(\d+)\)/);
|
|
1504
|
+
return m ? { r: +m[1], g: +m[2], b: +m[3] } : shadowRgb;
|
|
1505
|
+
})();
|
|
1506
|
+
const shadedColor = `rgb(${Math.round(baseRgbParsed.r * aoFactor)},${Math.round(baseRgbParsed.g * aoFactor)},${Math.round(baseRgbParsed.b * aoFactor)})`;
|
|
1507
|
+
renderLines("fill", shadedColor, dx, dy);
|
|
1508
|
+
if (bevelEdgeWidth && bevelEdgeWidth > 0) {
|
|
1509
|
+
ctx.save();
|
|
1510
|
+
ctx.globalAlpha = 0.4 + 0.6 * (1 - depthRatio);
|
|
1511
|
+
ctx.strokeStyle = bevelEdgeColor || "#000000";
|
|
1512
|
+
ctx.lineWidth = bevelEdgeWidth;
|
|
1513
|
+
ctx.lineJoin = strokeLineJoin || "round";
|
|
1514
|
+
renderLines("stroke", void 0, dx, dy);
|
|
1515
|
+
ctx.restore();
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
ctx.restore();
|
|
1519
|
+
ctx.save();
|
|
1520
|
+
ctx.globalAlpha = 0.5;
|
|
1521
|
+
ctx.strokeStyle = bevelHighlight;
|
|
1522
|
+
ctx.lineWidth = Math.max(0.5, bevelEdgeWidth || 1.5);
|
|
1523
|
+
ctx.lineJoin = "round";
|
|
1524
|
+
renderLines("stroke", bevelHighlight, 0, 0);
|
|
1525
|
+
ctx.restore();
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
const applyStroke = () => {
|
|
1529
|
+
ctx.save();
|
|
1530
|
+
const sType = strokeType || "single";
|
|
1531
|
+
const sBlur = strokeBlur || 0;
|
|
1532
|
+
const sColorSecondary = strokeColorSecondary || "#FFFFFF";
|
|
1533
|
+
const sWidthSecondary = strokeWidthSecondary !== void 0 ? strokeWidthSecondary : 4;
|
|
1534
|
+
const sFadeRange = strokeFadeRange || 0;
|
|
1535
|
+
ctx.lineJoin = strokeLineJoin || "round";
|
|
1536
|
+
let customStrokeStyle = strokeColor;
|
|
1537
|
+
if (sFadeRange > 0) {
|
|
1538
|
+
const grad = ctx.createLinearGradient(0, yMin, 0, yMax);
|
|
1539
|
+
const rgb = hexToRgb(strokeColor);
|
|
1540
|
+
grad.addColorStop(0, `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${strokeOpacity / 100})`);
|
|
1541
|
+
const fadeLimit = Math.min(1, sFadeRange / 100);
|
|
1542
|
+
grad.addColorStop(fadeLimit, `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, 0)`);
|
|
1543
|
+
grad.addColorStop(1, `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, 0)`);
|
|
1544
|
+
customStrokeStyle = grad;
|
|
1545
|
+
}
|
|
1546
|
+
const drawStrokeLayer = (color, width, blurAmount, opacity, position) => {
|
|
1547
|
+
if (blurAmount > 0 && ctxSupportsFilter(ctx)) {
|
|
1548
|
+
ctx.save();
|
|
1549
|
+
ctx.globalAlpha = opacity / 100;
|
|
1550
|
+
ctx.strokeStyle = color;
|
|
1551
|
+
ctx.filter = `blur(${blurAmount}px)`;
|
|
1552
|
+
if (position === "outside") {
|
|
1553
|
+
ctx.lineWidth = width * 2;
|
|
1554
|
+
renderLines("stroke");
|
|
1555
|
+
} else if (position === "center") {
|
|
1556
|
+
ctx.lineWidth = width;
|
|
1557
|
+
renderLines("stroke");
|
|
1558
|
+
} else if (position === "inside") {
|
|
1559
|
+
ctx.globalCompositeOperation = "source-atop";
|
|
1560
|
+
ctx.lineWidth = width * 2;
|
|
1561
|
+
renderLines("stroke");
|
|
1562
|
+
}
|
|
1563
|
+
ctx.restore();
|
|
1564
|
+
} else if (blurAmount > 0) {
|
|
1565
|
+
const colorStr = typeof color === "string" ? color : strokeColor;
|
|
1566
|
+
const spread = position === "center" ? width / 2 : width;
|
|
1567
|
+
if (position === "inside") {
|
|
1568
|
+
ctx.save();
|
|
1569
|
+
ctx.globalCompositeOperation = "source-atop";
|
|
1570
|
+
renderWithShadowTrick("stroke", colorStr, blurAmount, 0, 0, opacity, void 0, spread);
|
|
1571
|
+
ctx.restore();
|
|
1572
|
+
} else {
|
|
1573
|
+
renderWithShadowTrick("stroke", colorStr, blurAmount, 0, 0, opacity, void 0, spread);
|
|
1574
|
+
}
|
|
1575
|
+
} else {
|
|
1576
|
+
ctx.save();
|
|
1577
|
+
ctx.globalAlpha = opacity / 100;
|
|
1578
|
+
ctx.strokeStyle = color;
|
|
1579
|
+
if (position === "outside") {
|
|
1580
|
+
ctx.lineWidth = width * 2;
|
|
1581
|
+
renderLines("stroke");
|
|
1582
|
+
} else if (position === "center") {
|
|
1583
|
+
ctx.lineWidth = width;
|
|
1584
|
+
renderLines("stroke");
|
|
1585
|
+
} else if (position === "inside") {
|
|
1586
|
+
ctx.globalCompositeOperation = "source-atop";
|
|
1587
|
+
ctx.lineWidth = width * 2;
|
|
1588
|
+
renderLines("stroke");
|
|
1589
|
+
}
|
|
1590
|
+
ctx.restore();
|
|
1591
|
+
}
|
|
1592
|
+
};
|
|
1593
|
+
if (sType === "double") {
|
|
1594
|
+
const outerWidth = strokeWidth + sWidthSecondary;
|
|
1595
|
+
drawStrokeLayer(sColorSecondary, outerWidth, sBlur, strokeOpacity, strokePosition);
|
|
1596
|
+
drawStrokeLayer(
|
|
1597
|
+
customStrokeStyle,
|
|
1598
|
+
strokeWidth,
|
|
1599
|
+
0,
|
|
1600
|
+
// inner remains crisp
|
|
1601
|
+
strokeOpacity,
|
|
1602
|
+
strokePosition
|
|
1603
|
+
);
|
|
1604
|
+
} else if (sType === "neon") {
|
|
1605
|
+
drawStrokeLayer(
|
|
1606
|
+
strokeColor,
|
|
1607
|
+
strokeWidth * 1.8,
|
|
1608
|
+
sBlur || 8,
|
|
1609
|
+
// fallback blur to look gorgeous
|
|
1610
|
+
strokeOpacity * 0.7,
|
|
1611
|
+
strokePosition
|
|
1612
|
+
);
|
|
1613
|
+
drawStrokeLayer("#FFFFFF", strokeWidth * 0.5, 0, 95, strokePosition);
|
|
1614
|
+
} else {
|
|
1615
|
+
drawStrokeLayer(customStrokeStyle, strokeWidth, sBlur, strokeOpacity, strokePosition);
|
|
1616
|
+
}
|
|
1617
|
+
ctx.restore();
|
|
1618
|
+
};
|
|
1619
|
+
if (stackEnabled && (stackCount ?? 0) >= 1) {
|
|
1620
|
+
const cnt = stackCount ?? 3;
|
|
1621
|
+
const offX = stackOffsetX ?? 10;
|
|
1622
|
+
const offY = stackOffsetY ?? -10;
|
|
1623
|
+
const decay = (stackOpacityDecay ?? 20) / 100;
|
|
1624
|
+
const stackColors = [stackColor1 || "#FF7C00", stackColor2 || "#00FFDD", stackColor3 || "#FF00AA", stackColor4 || "#AA00FF"];
|
|
1625
|
+
for (let s = cnt; s >= 1; s--) {
|
|
1626
|
+
ctx.save();
|
|
1627
|
+
const dx = s * offX;
|
|
1628
|
+
const dy = s * offY;
|
|
1629
|
+
const layerOpacity = Math.max(0.01, 1 - s * decay);
|
|
1630
|
+
ctx.globalAlpha = layerOpacity;
|
|
1631
|
+
const layerColor = stackColors[(s - 1) % stackColors.length] || "#FFFFFF";
|
|
1632
|
+
if (strokeEnabled && strokeWidth > 0 && strokePosition !== "inside") {
|
|
1633
|
+
ctx.save();
|
|
1634
|
+
ctx.strokeStyle = layerColor;
|
|
1635
|
+
ctx.lineWidth = strokeWidth;
|
|
1636
|
+
ctx.lineJoin = strokeLineJoin;
|
|
1637
|
+
ctx.globalAlpha = strokeOpacity / 100 * layerOpacity;
|
|
1638
|
+
renderLines("stroke", layerColor, dx, dy);
|
|
1639
|
+
ctx.restore();
|
|
1640
|
+
}
|
|
1641
|
+
renderLines("fill", layerColor, dx, dy);
|
|
1642
|
+
ctx.restore();
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
if (strokeEnabled && strokeWidth > 0 && strokePosition !== "inside") {
|
|
1646
|
+
applyStroke();
|
|
1647
|
+
}
|
|
1648
|
+
ctx.save();
|
|
1649
|
+
let textFill = fillColor;
|
|
1650
|
+
if (fillType === "linear" && fillGradientStops.length >= 2) {
|
|
1651
|
+
const angleRad = fillGradientAngle * Math.PI / 180;
|
|
1652
|
+
const cx = (xMin + xMax) / 2;
|
|
1653
|
+
const cy = (yMin + yMax) / 2;
|
|
1654
|
+
const r = Math.max(xMax - xMin, yMax - yMin) / 2;
|
|
1655
|
+
const x0 = cx - Math.cos(angleRad) * r;
|
|
1656
|
+
const y0 = cy - Math.sin(angleRad) * r;
|
|
1657
|
+
const x1 = cx + Math.cos(angleRad) * r;
|
|
1658
|
+
const y1 = cy + Math.sin(angleRad) * r;
|
|
1659
|
+
const grad = ctx.createLinearGradient(x0, y0, x1, y1);
|
|
1660
|
+
fillGradientStops.forEach((stop) => {
|
|
1661
|
+
grad.addColorStop(stop.offset / 100, stop.color);
|
|
1662
|
+
});
|
|
1663
|
+
textFill = grad;
|
|
1664
|
+
} else if (fillType === "radial" && fillGradientStops.length >= 2) {
|
|
1665
|
+
const cx = (xMin + xMax) / 2;
|
|
1666
|
+
const cy = (yMin + yMax) / 2;
|
|
1667
|
+
const r = Math.max(xMax - xMin, yMax - yMin) / 1.5;
|
|
1668
|
+
const grad = ctx.createRadialGradient(cx, cy, 2, cx, cy, r);
|
|
1669
|
+
fillGradientStops.forEach((stop) => {
|
|
1670
|
+
grad.addColorStop(stop.offset / 100, stop.color);
|
|
1671
|
+
});
|
|
1672
|
+
textFill = grad;
|
|
1673
|
+
} else if (fillType === "pattern") {
|
|
1674
|
+
const pType = patternType || "chalk";
|
|
1675
|
+
const patColor = fillColor || "#ffffff";
|
|
1676
|
+
const patCanvas = createCanvas(128, 128);
|
|
1677
|
+
if (pType === "carbon") {
|
|
1678
|
+
patCanvas.width = 8;
|
|
1679
|
+
patCanvas.height = 8;
|
|
1680
|
+
} else if (pType === "stripes") {
|
|
1681
|
+
patCanvas.width = 16;
|
|
1682
|
+
patCanvas.height = 16;
|
|
1683
|
+
} else if (pType === "halftone") {
|
|
1684
|
+
patCanvas.width = 24;
|
|
1685
|
+
patCanvas.height = 24;
|
|
1686
|
+
} else if (pType === "noise") {
|
|
1687
|
+
patCanvas.width = 96;
|
|
1688
|
+
patCanvas.height = 96;
|
|
1689
|
+
} else if (pType === "film" || pType === "brushed" || pType === "paper") {
|
|
1690
|
+
patCanvas.width = 128;
|
|
1691
|
+
patCanvas.height = 128;
|
|
1692
|
+
} else if (pType === "marble") {
|
|
1693
|
+
patCanvas.width = 256;
|
|
1694
|
+
patCanvas.height = 256;
|
|
1695
|
+
} else {
|
|
1696
|
+
patCanvas.width = 120;
|
|
1697
|
+
patCanvas.height = 120;
|
|
1698
|
+
}
|
|
1699
|
+
const patCtx = getCanvas2DContext(patCanvas);
|
|
1700
|
+
const seedRandom = (initSeed) => {
|
|
1701
|
+
let currentSeed = initSeed;
|
|
1702
|
+
return () => {
|
|
1703
|
+
currentSeed = (currentSeed * 1664525 + 1013904223) % 4294967296;
|
|
1704
|
+
return currentSeed / 4294967296;
|
|
1705
|
+
};
|
|
1706
|
+
};
|
|
1707
|
+
const rand = seedRandom(42);
|
|
1708
|
+
if (pType === "chalk") {
|
|
1709
|
+
patCtx.fillStyle = "rgba(0,0,0,0)";
|
|
1710
|
+
patCtx.fillRect(0, 0, 120, 120);
|
|
1711
|
+
patCtx.fillStyle = patColor;
|
|
1712
|
+
for (let i = 0; i < 3500; i++) {
|
|
1713
|
+
const px = Math.floor(rand() * 120);
|
|
1714
|
+
const py = Math.floor(rand() * 120);
|
|
1715
|
+
patCtx.globalAlpha = 0.08 + rand() * 0.18;
|
|
1716
|
+
patCtx.fillRect(px, py, 1.2, 1.2);
|
|
1717
|
+
}
|
|
1718
|
+
patCtx.strokeStyle = patColor;
|
|
1719
|
+
for (let s = 0; s < 4; s++) {
|
|
1720
|
+
const angle = s * Math.PI / 4 + (rand() - 0.5) * 0.15;
|
|
1721
|
+
patCtx.lineWidth = 0.5 + rand() * 0.9;
|
|
1722
|
+
for (let i = 0; i < 40; i++) {
|
|
1723
|
+
patCtx.globalAlpha = 0.05 + rand() * 0.16;
|
|
1724
|
+
patCtx.beginPath();
|
|
1725
|
+
const startX2 = rand() * 120;
|
|
1726
|
+
const startY2 = rand() * 120;
|
|
1727
|
+
const len = 15 + rand() * 30;
|
|
1728
|
+
patCtx.moveTo(startX2, startY2);
|
|
1729
|
+
patCtx.lineTo(startX2 + Math.cos(angle) * len, startY2 + Math.sin(angle) * len);
|
|
1730
|
+
patCtx.stroke();
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
for (let i = 0; i < 220; i++) {
|
|
1734
|
+
const cx = rand() * 120;
|
|
1735
|
+
const cy = rand() * 120;
|
|
1736
|
+
const r = 1 + rand() * 3;
|
|
1737
|
+
patCtx.globalAlpha = 0.03 + rand() * 0.08;
|
|
1738
|
+
patCtx.fillStyle = patColor;
|
|
1739
|
+
patCtx.beginPath();
|
|
1740
|
+
patCtx.arc(cx, cy, r, 0, Math.PI * 2);
|
|
1741
|
+
patCtx.fill();
|
|
1742
|
+
}
|
|
1743
|
+
} else if (pType === "noise") {
|
|
1744
|
+
patCtx.fillStyle = "rgba(0,0,0,0)";
|
|
1745
|
+
patCtx.fillRect(0, 0, 96, 96);
|
|
1746
|
+
patCtx.fillStyle = patColor;
|
|
1747
|
+
for (let i = 0; i < 4500; i++) {
|
|
1748
|
+
const px = Math.floor(rand() * 96);
|
|
1749
|
+
const py = Math.floor(rand() * 96);
|
|
1750
|
+
patCtx.globalAlpha = 0.12 + rand() * 0.38;
|
|
1751
|
+
patCtx.fillRect(px, py, rand() > 0.85 ? 1.5 : 1, rand() > 0.85 ? 1.5 : 1);
|
|
1752
|
+
}
|
|
1753
|
+
for (let i = 0; i < 150; i++) {
|
|
1754
|
+
const px = Math.floor(rand() * 96);
|
|
1755
|
+
const py = Math.floor(rand() * 96);
|
|
1756
|
+
const size = 1.6 + rand() * 1.5;
|
|
1757
|
+
patCtx.globalAlpha = 0.05 + rand() * 0.12;
|
|
1758
|
+
patCtx.fillRect(px, py, size, size);
|
|
1759
|
+
}
|
|
1760
|
+
} else if (pType === "grunge") {
|
|
1761
|
+
patCtx.fillStyle = "rgba(0,0,0,0)";
|
|
1762
|
+
patCtx.fillRect(0, 0, 128, 128);
|
|
1763
|
+
patCtx.fillStyle = patColor;
|
|
1764
|
+
for (let i = 0; i < 60; i++) {
|
|
1765
|
+
const cx = rand() * 128;
|
|
1766
|
+
const cy = rand() * 128;
|
|
1767
|
+
const r = 3 + rand() * 18;
|
|
1768
|
+
patCtx.globalAlpha = 0.06 + rand() * 0.15;
|
|
1769
|
+
patCtx.beginPath();
|
|
1770
|
+
patCtx.arc(cx, cy, r, 0, Math.PI * 2);
|
|
1771
|
+
patCtx.fill();
|
|
1772
|
+
}
|
|
1773
|
+
patCtx.strokeStyle = patColor;
|
|
1774
|
+
for (let i = 0; i < 22; i++) {
|
|
1775
|
+
const sx = rand() * 128;
|
|
1776
|
+
const sy = rand() * 128;
|
|
1777
|
+
const angle = rand() * Math.PI / 3 - Math.PI / 6;
|
|
1778
|
+
const len = 12 + rand() * 25;
|
|
1779
|
+
patCtx.lineWidth = 0.5 + rand() * 1.5;
|
|
1780
|
+
patCtx.globalAlpha = 0.15 + rand() * 0.25;
|
|
1781
|
+
patCtx.beginPath();
|
|
1782
|
+
patCtx.moveTo(sx, sy);
|
|
1783
|
+
patCtx.lineTo(sx + Math.cos(angle) * len, sy + Math.sin(angle) * len);
|
|
1784
|
+
patCtx.stroke();
|
|
1785
|
+
}
|
|
1786
|
+
for (let i = 0; i < 1800; i++) {
|
|
1787
|
+
const px = Math.floor(rand() * 128);
|
|
1788
|
+
const py = Math.floor(rand() * 128);
|
|
1789
|
+
patCtx.globalAlpha = 0.08 + rand() * 0.22;
|
|
1790
|
+
patCtx.fillRect(px, py, 1.2, 1.2);
|
|
1791
|
+
}
|
|
1792
|
+
} else if (pType === "carbon") {
|
|
1793
|
+
patCtx.fillStyle = "rgba(0,0,0,0.15)";
|
|
1794
|
+
patCtx.fillRect(0, 0, 8, 8);
|
|
1795
|
+
patCtx.fillStyle = patColor;
|
|
1796
|
+
patCtx.globalAlpha = 0.65;
|
|
1797
|
+
patCtx.fillRect(0, 0, 4, 4);
|
|
1798
|
+
patCtx.fillRect(4, 4, 4, 4);
|
|
1799
|
+
patCtx.fillStyle = "#FFFFFF";
|
|
1800
|
+
patCtx.globalAlpha = 0.22;
|
|
1801
|
+
patCtx.fillRect(0, 0, 4, 1);
|
|
1802
|
+
patCtx.fillRect(4, 4, 4, 1);
|
|
1803
|
+
patCtx.fillStyle = "#000000";
|
|
1804
|
+
patCtx.globalAlpha = 0.35;
|
|
1805
|
+
patCtx.fillRect(0, 3, 4, 1);
|
|
1806
|
+
patCtx.fillRect(4, 7, 4, 1);
|
|
1807
|
+
} else if (pType === "stripes") {
|
|
1808
|
+
patCtx.fillStyle = "rgba(0,0,0,0)";
|
|
1809
|
+
patCtx.fillRect(0, 0, 16, 16);
|
|
1810
|
+
patCtx.strokeStyle = patColor;
|
|
1811
|
+
patCtx.lineWidth = 3.5;
|
|
1812
|
+
patCtx.globalAlpha = 0.65;
|
|
1813
|
+
patCtx.beginPath();
|
|
1814
|
+
patCtx.moveTo(-4, 12);
|
|
1815
|
+
patCtx.lineTo(12, -4);
|
|
1816
|
+
patCtx.moveTo(0, 16);
|
|
1817
|
+
patCtx.lineTo(16, 0);
|
|
1818
|
+
patCtx.moveTo(4, 20);
|
|
1819
|
+
patCtx.lineTo(20, 4);
|
|
1820
|
+
patCtx.stroke();
|
|
1821
|
+
} else if (pType === "film") {
|
|
1822
|
+
patCtx.fillStyle = patColor;
|
|
1823
|
+
patCtx.globalAlpha = 0.94;
|
|
1824
|
+
patCtx.fillRect(0, 0, 128, 128);
|
|
1825
|
+
for (let i = 0; i < 4800; i++) {
|
|
1826
|
+
const px = Math.floor(rand() * 128);
|
|
1827
|
+
const py = Math.floor(rand() * 128);
|
|
1828
|
+
const isDark = rand() > 0.45;
|
|
1829
|
+
patCtx.fillStyle = isDark ? "#000000" : "#FFFFFF";
|
|
1830
|
+
patCtx.globalAlpha = isDark ? 0.13 + rand() * 0.22 : 0.15 + rand() * 0.28;
|
|
1831
|
+
patCtx.fillRect(px, py, rand() > 0.9 ? 1.5 : 1, rand() > 0.9 ? 1.5 : 1);
|
|
1832
|
+
}
|
|
1833
|
+
patCtx.strokeStyle = "rgba(255, 255, 255, 0.48)";
|
|
1834
|
+
for (let i = 0; i < 10; i++) {
|
|
1835
|
+
const sx = rand() * 128;
|
|
1836
|
+
const sy = rand() * 128;
|
|
1837
|
+
const len = 12 + rand() * 45;
|
|
1838
|
+
const angle = -Math.PI / 2 + (rand() - 0.5) * 0.18;
|
|
1839
|
+
patCtx.lineWidth = 0.35 + rand() * 0.55;
|
|
1840
|
+
patCtx.globalAlpha = 0.22 + rand() * 0.38;
|
|
1841
|
+
patCtx.beginPath();
|
|
1842
|
+
patCtx.moveTo(sx, sy);
|
|
1843
|
+
patCtx.lineTo(sx + Math.cos(angle) * len, sy + Math.sin(angle) * len);
|
|
1844
|
+
patCtx.stroke();
|
|
1845
|
+
}
|
|
1846
|
+
patCtx.strokeStyle = "rgba(0, 0, 0, 0.32)";
|
|
1847
|
+
for (let i = 0; i < 5; i++) {
|
|
1848
|
+
const sx = rand() * 128;
|
|
1849
|
+
const sy = rand() * 128;
|
|
1850
|
+
const len = 15 + rand() * 50;
|
|
1851
|
+
const angle = -Math.PI / 2 + (rand() - 0.5) * 0.12;
|
|
1852
|
+
patCtx.lineWidth = 0.3 + rand() * 0.5;
|
|
1853
|
+
patCtx.globalAlpha = 0.18 + rand() * 0.25;
|
|
1854
|
+
patCtx.beginPath();
|
|
1855
|
+
patCtx.moveTo(sx, sy);
|
|
1856
|
+
patCtx.lineTo(sx + Math.cos(angle) * len, sy + Math.sin(angle) * len);
|
|
1857
|
+
patCtx.stroke();
|
|
1858
|
+
}
|
|
1859
|
+
patCtx.strokeStyle = "rgba(0, 0, 0, 0.48)";
|
|
1860
|
+
for (let i = 0; i < 4; i++) {
|
|
1861
|
+
const sx = rand() * 128;
|
|
1862
|
+
const sy = rand() * 128;
|
|
1863
|
+
patCtx.lineWidth = 0.55 + rand() * 0.65;
|
|
1864
|
+
patCtx.globalAlpha = 0.35 + rand() * 0.3;
|
|
1865
|
+
patCtx.beginPath();
|
|
1866
|
+
patCtx.moveTo(sx, sy);
|
|
1867
|
+
patCtx.quadraticCurveTo(sx + (rand() - 0.5) * 16, sy + (rand() - 0.5) * 16, sx + (rand() - 0.5) * 28, sy + (rand() - 0.5) * 28);
|
|
1868
|
+
patCtx.stroke();
|
|
1869
|
+
}
|
|
1870
|
+
patCtx.fillStyle = "#FFFFFF";
|
|
1871
|
+
for (let i = 0; i < 30; i++) {
|
|
1872
|
+
const cx = rand() * 128;
|
|
1873
|
+
const cy = rand() * 128;
|
|
1874
|
+
const r = 0.75 + rand() * 2.4;
|
|
1875
|
+
patCtx.globalAlpha = 0.25 + rand() * 0.5;
|
|
1876
|
+
patCtx.beginPath();
|
|
1877
|
+
patCtx.arc(cx, cy, r, 0, Math.PI * 2);
|
|
1878
|
+
patCtx.fill();
|
|
1879
|
+
}
|
|
1880
|
+
patCtx.fillStyle = "#000000";
|
|
1881
|
+
for (let i = 0; i < 20; i++) {
|
|
1882
|
+
const cx = rand() * 128;
|
|
1883
|
+
const cy = rand() * 128;
|
|
1884
|
+
const r = 0.65 + rand() * 2;
|
|
1885
|
+
patCtx.globalAlpha = 0.2 + rand() * 0.4;
|
|
1886
|
+
patCtx.beginPath();
|
|
1887
|
+
patCtx.arc(cx, cy, r, 0, Math.PI * 2);
|
|
1888
|
+
patCtx.fill();
|
|
1889
|
+
}
|
|
1890
|
+
} else if (pType === "brushed") {
|
|
1891
|
+
patCtx.fillStyle = patColor;
|
|
1892
|
+
patCtx.fillRect(0, 0, 128, 128);
|
|
1893
|
+
for (let i = 0; i < 350; i++) {
|
|
1894
|
+
const y = rand() * 128;
|
|
1895
|
+
const x = rand() * 128;
|
|
1896
|
+
const len = 30 + rand() * 80;
|
|
1897
|
+
const thickness = 0.5 + rand() * 1.5;
|
|
1898
|
+
const isLight = rand() > 0.45;
|
|
1899
|
+
patCtx.strokeStyle = isLight ? "#FFFFFF" : "#000000";
|
|
1900
|
+
patCtx.globalAlpha = isLight ? 0.04 + rand() * 0.12 : 0.03 + rand() * 0.08;
|
|
1901
|
+
patCtx.lineWidth = thickness;
|
|
1902
|
+
patCtx.beginPath();
|
|
1903
|
+
patCtx.moveTo(x, y);
|
|
1904
|
+
patCtx.lineTo(x + len, y);
|
|
1905
|
+
patCtx.stroke();
|
|
1906
|
+
if (x + len > 128) {
|
|
1907
|
+
patCtx.beginPath();
|
|
1908
|
+
patCtx.moveTo(x - 128, y);
|
|
1909
|
+
patCtx.lineTo(x + len - 128, y);
|
|
1910
|
+
patCtx.stroke();
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
for (let i = 0; i < 8; i++) {
|
|
1914
|
+
const x = rand() * 128;
|
|
1915
|
+
const w = 10 + rand() * 30;
|
|
1916
|
+
const isLight = rand() > 0.5;
|
|
1917
|
+
const grad = patCtx.createLinearGradient(x, 0, x + w, 0);
|
|
1918
|
+
const baseColor = isLight ? "255,255,255" : "0,0,0";
|
|
1919
|
+
const alpha = 0.01 + rand() * 0.04;
|
|
1920
|
+
grad.addColorStop(0, `rgba(${baseColor}, 0)`);
|
|
1921
|
+
grad.addColorStop(0.5, `rgba(${baseColor}, ${alpha})`);
|
|
1922
|
+
grad.addColorStop(1, `rgba(${baseColor}, 0)`);
|
|
1923
|
+
patCtx.fillStyle = grad;
|
|
1924
|
+
patCtx.globalAlpha = 1;
|
|
1925
|
+
patCtx.fillRect(x, 0, w, 128);
|
|
1926
|
+
if (x + w > 128) {
|
|
1927
|
+
patCtx.fillRect(x - 128, 0, w, 128);
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
} else if (pType === "marble") {
|
|
1931
|
+
patCtx.fillStyle = patColor;
|
|
1932
|
+
patCtx.fillRect(0, 0, 256, 256);
|
|
1933
|
+
for (let i = 0; i < 8; i++) {
|
|
1934
|
+
const cx = rand() * 256;
|
|
1935
|
+
const cy = rand() * 256;
|
|
1936
|
+
const r = 40 + rand() * 70;
|
|
1937
|
+
const grad = patCtx.createRadialGradient(cx, cy, 0, cx, cy, r);
|
|
1938
|
+
const isLight = rand() > 0.45;
|
|
1939
|
+
const alpha = 0.06 + rand() * 0.12;
|
|
1940
|
+
const cStr = isLight ? "255,255,255" : "0,0,0";
|
|
1941
|
+
grad.addColorStop(0, `rgba(${cStr}, ${alpha})`);
|
|
1942
|
+
grad.addColorStop(0.5, `rgba(${cStr}, ${alpha * 0.4})`);
|
|
1943
|
+
grad.addColorStop(1, `rgba(${cStr}, 0)`);
|
|
1944
|
+
patCtx.fillStyle = grad;
|
|
1945
|
+
patCtx.globalAlpha = 1;
|
|
1946
|
+
patCtx.beginPath();
|
|
1947
|
+
patCtx.arc(cx, cy, r, 0, Math.PI * 2);
|
|
1948
|
+
patCtx.fill();
|
|
1949
|
+
}
|
|
1950
|
+
const drawMarbleVein = (color, width, opac) => {
|
|
1951
|
+
patCtx.strokeStyle = color;
|
|
1952
|
+
patCtx.lineWidth = width;
|
|
1953
|
+
patCtx.globalAlpha = opac;
|
|
1954
|
+
let px = rand() * 256;
|
|
1955
|
+
let py = 0;
|
|
1956
|
+
patCtx.beginPath();
|
|
1957
|
+
patCtx.moveTo(px, py);
|
|
1958
|
+
const steps = 18;
|
|
1959
|
+
for (let s = 1; s <= steps; s++) {
|
|
1960
|
+
const progress = s / steps;
|
|
1961
|
+
const targetY = progress * 256;
|
|
1962
|
+
const frequency = 4;
|
|
1963
|
+
const amp = 35;
|
|
1964
|
+
const noise = Math.sin(progress * Math.PI * frequency + rand() * 2) * amp;
|
|
1965
|
+
const targetX = (px + (rand() - 0.5) * 50 + noise + 256) % 256;
|
|
1966
|
+
patCtx.lineTo(targetX, targetY);
|
|
1967
|
+
}
|
|
1968
|
+
patCtx.stroke();
|
|
1969
|
+
};
|
|
1970
|
+
for (let i = 0; i < 4; i++) {
|
|
1971
|
+
drawMarbleVein("#000000", 1.2 + rand() * 1.5, 0.15 + rand() * 0.15);
|
|
1972
|
+
}
|
|
1973
|
+
for (let i = 0; i < 3; i++) {
|
|
1974
|
+
const isGold = rand() > 0.4;
|
|
1975
|
+
const vColor = isGold ? "#EAB308" : "#FFFFFF";
|
|
1976
|
+
drawMarbleVein(vColor, 0.7 + rand() * 0.8, 0.2 + rand() * 0.2);
|
|
1977
|
+
}
|
|
1978
|
+
for (let i = 0; i < 5; i++) {
|
|
1979
|
+
drawMarbleVein("#000000", 0.4, 0.08 + rand() * 0.06);
|
|
1980
|
+
}
|
|
1981
|
+
} else if (pType === "halftone") {
|
|
1982
|
+
patCtx.fillStyle = "rgba(0,0,0,0)";
|
|
1983
|
+
patCtx.fillRect(0, 0, 24, 24);
|
|
1984
|
+
const dotColor = fillColor || "#ffffff";
|
|
1985
|
+
patCtx.fillStyle = "#000000";
|
|
1986
|
+
patCtx.globalAlpha = 0.35;
|
|
1987
|
+
patCtx.beginPath();
|
|
1988
|
+
patCtx.arc(12, 12, 5.5, 0, Math.PI * 2);
|
|
1989
|
+
patCtx.arc(0, 0, 3.5, 0, Math.PI * 2);
|
|
1990
|
+
patCtx.arc(24, 0, 3.5, 0, Math.PI * 2);
|
|
1991
|
+
patCtx.arc(0, 24, 3.5, 0, Math.PI * 2);
|
|
1992
|
+
patCtx.arc(24, 24, 3.5, 0, Math.PI * 2);
|
|
1993
|
+
patCtx.fill();
|
|
1994
|
+
patCtx.fillStyle = dotColor;
|
|
1995
|
+
patCtx.globalAlpha = 0.95;
|
|
1996
|
+
patCtx.beginPath();
|
|
1997
|
+
patCtx.arc(11, 11, 5, 0, Math.PI * 2);
|
|
1998
|
+
patCtx.arc(0, 0, 3, 0, Math.PI * 2);
|
|
1999
|
+
patCtx.arc(24, 0, 3, 0, Math.PI * 2);
|
|
2000
|
+
patCtx.arc(0, 24, 3, 0, Math.PI * 2);
|
|
2001
|
+
patCtx.arc(24, 24, 3, 0, Math.PI * 2);
|
|
2002
|
+
patCtx.fill();
|
|
2003
|
+
patCtx.fillStyle = dotColor === "#FFFFFF" || dotColor === "#ffffff" ? "#7C6FFF" : "#FFFFFF";
|
|
2004
|
+
patCtx.globalAlpha = 0.55;
|
|
2005
|
+
patCtx.beginPath();
|
|
2006
|
+
patCtx.arc(12, 0, 1.5, 0, Math.PI * 2);
|
|
2007
|
+
patCtx.arc(12, 24, 1.5, 0, Math.PI * 2);
|
|
2008
|
+
patCtx.arc(0, 12, 1.5, 0, Math.PI * 2);
|
|
2009
|
+
patCtx.arc(24, 12, 1.5, 0, Math.PI * 2);
|
|
2010
|
+
patCtx.fill();
|
|
2011
|
+
} else if (pType === "paper") {
|
|
2012
|
+
patCtx.fillStyle = patColor;
|
|
2013
|
+
patCtx.fillRect(0, 0, 128, 128);
|
|
2014
|
+
for (let i = 0; i < 350; i++) {
|
|
2015
|
+
const fx = rand() * 128;
|
|
2016
|
+
const fy = rand() * 128;
|
|
2017
|
+
const flen = 3 + rand() * 12;
|
|
2018
|
+
const fangle = rand() * Math.PI * 2;
|
|
2019
|
+
const isDark = rand() > 0.4;
|
|
2020
|
+
patCtx.strokeStyle = isDark ? "#000000" : "#FFFFFF";
|
|
2021
|
+
patCtx.globalAlpha = isDark ? 0.03 + rand() * 0.08 : 0.05 + rand() * 0.12;
|
|
2022
|
+
patCtx.lineWidth = 0.4 + rand() * 0.7;
|
|
2023
|
+
patCtx.beginPath();
|
|
2024
|
+
patCtx.moveTo(fx, fy);
|
|
2025
|
+
patCtx.quadraticCurveTo(fx + Math.cos(fangle) * flen * 0.5 + (rand() - 0.5) * 4, fy + Math.sin(fangle) * flen * 0.5 + (rand() - 0.5) * 4, fx + Math.cos(fangle) * flen, fy + Math.sin(fangle) * flen);
|
|
2026
|
+
patCtx.stroke();
|
|
2027
|
+
}
|
|
2028
|
+
for (let i = 0; i < 5e3; i++) {
|
|
2029
|
+
const gx = Math.floor(rand() * 128);
|
|
2030
|
+
const gy = Math.floor(rand() * 128);
|
|
2031
|
+
const isDark = rand() > 0.5;
|
|
2032
|
+
patCtx.fillStyle = isDark ? "#000000" : "#FFFFFF";
|
|
2033
|
+
patCtx.globalAlpha = isDark ? 0.04 : 0.06;
|
|
2034
|
+
patCtx.fillRect(gx, gy, 1, 1);
|
|
2035
|
+
}
|
|
2036
|
+
const points = [];
|
|
2037
|
+
for (let i = 0; i < 6; i++) {
|
|
2038
|
+
points.push([rand() * 128, rand() * 128]);
|
|
2039
|
+
}
|
|
2040
|
+
points.push([0, 0], [128, 0], [128, 128], [0, 128]);
|
|
2041
|
+
for (let i = 0; i < 15; i++) {
|
|
2042
|
+
const p1 = points[Math.floor(rand() * points.length)];
|
|
2043
|
+
const p2 = points[Math.floor(rand() * points.length)];
|
|
2044
|
+
const p3 = points[Math.floor(rand() * points.length)];
|
|
2045
|
+
if (p1 !== p2 && p2 !== p3) {
|
|
2046
|
+
const grad = patCtx.createLinearGradient(p1[0], p1[1], p2[0], p2[1]);
|
|
2047
|
+
const alpha = 0.01 + rand() * 0.06;
|
|
2048
|
+
const isDark = rand() > 0.5;
|
|
2049
|
+
const cStr = isDark ? "0,0,0" : "255,255,255";
|
|
2050
|
+
grad.addColorStop(0, `rgba(${cStr}, ${alpha})`);
|
|
2051
|
+
grad.addColorStop(1, `rgba(${cStr}, 0)`);
|
|
2052
|
+
patCtx.fillStyle = grad;
|
|
2053
|
+
patCtx.globalAlpha = 1;
|
|
2054
|
+
patCtx.beginPath();
|
|
2055
|
+
patCtx.moveTo(p1[0], p1[1]);
|
|
2056
|
+
patCtx.lineTo(p2[0], p2[1]);
|
|
2057
|
+
patCtx.lineTo(p3[0], p3[1]);
|
|
2058
|
+
patCtx.closePath();
|
|
2059
|
+
patCtx.fill();
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
for (let i = 0; i < 12; i++) {
|
|
2063
|
+
const sx = rand() * 128;
|
|
2064
|
+
const sy = rand() * 128;
|
|
2065
|
+
const ex = rand() * 128;
|
|
2066
|
+
const ey = rand() * 128;
|
|
2067
|
+
const dx = ex - sx;
|
|
2068
|
+
const dy = ey - sy;
|
|
2069
|
+
const len = Math.sqrt(dx * dx + dy * dy);
|
|
2070
|
+
if (len === 0) continue;
|
|
2071
|
+
const nx = -dy / len;
|
|
2072
|
+
const ny = dx / len;
|
|
2073
|
+
patCtx.strokeStyle = "#000000";
|
|
2074
|
+
patCtx.lineWidth = 0.5 + rand() * 1.2;
|
|
2075
|
+
patCtx.globalAlpha = 0.05 + rand() * 0.12;
|
|
2076
|
+
patCtx.beginPath();
|
|
2077
|
+
patCtx.moveTo(sx + nx * 0.8, sy + ny * 0.8);
|
|
2078
|
+
patCtx.lineTo(ex + nx * 0.8, ey + ny * 0.8);
|
|
2079
|
+
patCtx.stroke();
|
|
2080
|
+
patCtx.strokeStyle = "#000000";
|
|
2081
|
+
patCtx.lineWidth = 0.3 + rand() * 0.4;
|
|
2082
|
+
patCtx.globalAlpha = 0.08 + rand() * 0.15;
|
|
2083
|
+
patCtx.beginPath();
|
|
2084
|
+
patCtx.moveTo(sx, sy);
|
|
2085
|
+
patCtx.lineTo(ex, ey);
|
|
2086
|
+
patCtx.stroke();
|
|
2087
|
+
patCtx.strokeStyle = "#FFFFFF";
|
|
2088
|
+
patCtx.lineWidth = 0.6 + rand() * 1.5;
|
|
2089
|
+
patCtx.globalAlpha = 0.08 + rand() * 0.22;
|
|
2090
|
+
patCtx.beginPath();
|
|
2091
|
+
patCtx.moveTo(sx - nx * 0.8, sy - ny * 0.8);
|
|
2092
|
+
patCtx.lineTo(ex - nx * 0.8, ey - ny * 0.8);
|
|
2093
|
+
patCtx.stroke();
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
const pat = ctx.createPattern(patCanvas, "repeat");
|
|
2097
|
+
if (pat) {
|
|
2098
|
+
textFill = pat;
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
const createSeededRand = (seed) => {
|
|
2102
|
+
let val = seed;
|
|
2103
|
+
return () => {
|
|
2104
|
+
val = (val * 9301 + 49297) % 233280;
|
|
2105
|
+
return val / 233280;
|
|
2106
|
+
};
|
|
2107
|
+
};
|
|
2108
|
+
const isInkStyle = cfg.effectName.toLowerCase().includes("ink") || cfg.fontFamily.toLowerCase().includes("brush") || cfg.effectName.toLowerCase().includes("grunge") || cfg.effectName.toLowerCase().includes("scratch") || cfg.fontFamily === "Permanent Marker";
|
|
2109
|
+
if (isInkStyle) {
|
|
2110
|
+
const tCanvas = createCanvas(cWidth, cHeight);
|
|
2111
|
+
tCanvas.width = cWidth;
|
|
2112
|
+
tCanvas.height = cHeight;
|
|
2113
|
+
const tCtx = getCanvas2DContext(tCanvas);
|
|
2114
|
+
if (tCtx) {
|
|
2115
|
+
tCtx.font = fontStr;
|
|
2116
|
+
tCtx.textAlign = align;
|
|
2117
|
+
tCtx.textBaseline = "alphabetic";
|
|
2118
|
+
const rand = createSeededRand(text.length * 171 + fontSize * 11 + (fillColor ? fillColor.length : 1));
|
|
2119
|
+
tCtx.fillStyle = "#FFFFFF";
|
|
2120
|
+
const originalLSpacing = tCtx.letterSpacing || "normal";
|
|
2121
|
+
if (letterSpacing !== 0) {
|
|
2122
|
+
tCtx.letterSpacing = `${letterSpacing}px`;
|
|
2123
|
+
}
|
|
2124
|
+
lines.forEach((line, index) => {
|
|
2125
|
+
const py = startY + index * lineAdvance;
|
|
2126
|
+
tCtx.fillText(line, startX, py);
|
|
2127
|
+
});
|
|
2128
|
+
const mxMin = Math.max(0, Math.floor(xMin - 20));
|
|
2129
|
+
const mxMax = Math.min(cWidth - 1, Math.ceil(xMax + 20));
|
|
2130
|
+
const myMin = Math.max(0, Math.floor(yMin - 20));
|
|
2131
|
+
const myMax = Math.min(cHeight - 1, Math.ceil(yMax + 20));
|
|
2132
|
+
const scanW = mxMax - mxMin;
|
|
2133
|
+
const scanH = myMax - myMin;
|
|
2134
|
+
if (scanW > 0 && scanH > 0) {
|
|
2135
|
+
const imgData = tCtx.getImageData(mxMin, myMin, scanW, scanH);
|
|
2136
|
+
const data = imgData.data;
|
|
2137
|
+
const isFilled = (coordX, coordY) => {
|
|
2138
|
+
if (coordX < 0 || coordX >= scanW || coordY < 0 || coordY >= scanH) return false;
|
|
2139
|
+
const idx = (coordY * scanW + coordX) * 4;
|
|
2140
|
+
return data[idx + 3] > 70;
|
|
2141
|
+
};
|
|
2142
|
+
const topEdges = [];
|
|
2143
|
+
const bottomEdges = [];
|
|
2144
|
+
const boundaryEdges = [];
|
|
2145
|
+
const insidePixels = [];
|
|
2146
|
+
for (let y = 1; y < scanH - 1; y += 1) {
|
|
2147
|
+
for (let x = 1; x < scanW - 1; x += 1) {
|
|
2148
|
+
if (isFilled(x, y)) {
|
|
2149
|
+
const emptyLeft = !isFilled(x - 1, y);
|
|
2150
|
+
const emptyRight = !isFilled(x + 1, y);
|
|
2151
|
+
const emptyTop = !isFilled(x, y - 1);
|
|
2152
|
+
const emptyBottom = !isFilled(x, y + 1);
|
|
2153
|
+
if (emptyTop) {
|
|
2154
|
+
topEdges.push({ x: mxMin + x, y: myMin + y });
|
|
2155
|
+
} else if (emptyBottom) {
|
|
2156
|
+
bottomEdges.push({ x: mxMin + x, y: myMin + y });
|
|
2157
|
+
} else if (emptyLeft || emptyRight) {
|
|
2158
|
+
boundaryEdges.push({ x: mxMin + x, y: myMin + y });
|
|
2159
|
+
} else {
|
|
2160
|
+
if (rand() < 0.15) {
|
|
2161
|
+
insidePixels.push({ x: mxMin + x, y: myMin + y });
|
|
2162
|
+
}
|
|
2163
|
+
}
|
|
2164
|
+
}
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
2167
|
+
tCtx.strokeStyle = "#FFFFFF";
|
|
2168
|
+
tCtx.fillStyle = "#FFFFFF";
|
|
2169
|
+
const topSampleRate = 5;
|
|
2170
|
+
for (let i = 0; i < topEdges.length; i += topSampleRate) {
|
|
2171
|
+
const pt = topEdges[i];
|
|
2172
|
+
const h = fontSize * (0.06 + rand() * 0.16);
|
|
2173
|
+
const w = 1.8 + rand() * 2.5;
|
|
2174
|
+
const slantOffset = h * 0.22;
|
|
2175
|
+
tCtx.beginPath();
|
|
2176
|
+
tCtx.moveTo(pt.x - w / 2, pt.y);
|
|
2177
|
+
tCtx.lineTo(pt.x + w / 2, pt.y);
|
|
2178
|
+
tCtx.lineTo(pt.x + slantOffset, pt.y - h);
|
|
2179
|
+
tCtx.closePath();
|
|
2180
|
+
tCtx.fill();
|
|
2181
|
+
}
|
|
2182
|
+
const bottomSampleRate = 5;
|
|
2183
|
+
for (let i = 0; i < bottomEdges.length; i += bottomSampleRate) {
|
|
2184
|
+
const pt = bottomEdges[i];
|
|
2185
|
+
const h = fontSize * (0.07 + rand() * 0.2);
|
|
2186
|
+
const w = 1.8 + rand() * 2.5;
|
|
2187
|
+
const slantOffset = -h * 0.22;
|
|
2188
|
+
tCtx.beginPath();
|
|
2189
|
+
tCtx.moveTo(pt.x - w / 2, pt.y);
|
|
2190
|
+
tCtx.lineTo(pt.x + w / 2, pt.y);
|
|
2191
|
+
tCtx.lineTo(pt.x + slantOffset, pt.y + h);
|
|
2192
|
+
tCtx.closePath();
|
|
2193
|
+
tCtx.fill();
|
|
2194
|
+
}
|
|
2195
|
+
const boundarySampleRate = 3;
|
|
2196
|
+
for (let i = 0; i < boundaryEdges.length; i += boundarySampleRate) {
|
|
2197
|
+
const pt = boundaryEdges[i];
|
|
2198
|
+
const r = 0.5 + rand() * 1.5;
|
|
2199
|
+
tCtx.beginPath();
|
|
2200
|
+
tCtx.arc(pt.x + (rand() - 0.5) * 1.2, pt.y + (rand() - 0.5) * 1.2, r, 0, Math.PI * 2);
|
|
2201
|
+
tCtx.fill();
|
|
2202
|
+
}
|
|
2203
|
+
const splatterCount = Math.floor(fontSize * 0.5);
|
|
2204
|
+
for (let s = 0; s < splatterCount; s++) {
|
|
2205
|
+
const pt = boundaryEdges[Math.floor(rand() * boundaryEdges.length)] || topEdges[Math.floor(rand() * topEdges.length)];
|
|
2206
|
+
if (pt) {
|
|
2207
|
+
const dist = 3 + rand() * (fontSize * 0.24);
|
|
2208
|
+
const angle = rand() * Math.PI * 2;
|
|
2209
|
+
const sx = pt.x + Math.cos(angle) * dist;
|
|
2210
|
+
const sy = pt.y + Math.sin(angle) * dist;
|
|
2211
|
+
const size = 0.4 + rand() * 1.6;
|
|
2212
|
+
tCtx.globalAlpha = 0.25 + rand() * 0.65;
|
|
2213
|
+
tCtx.beginPath();
|
|
2214
|
+
tCtx.arc(sx, sy, size, 0, Math.PI * 2);
|
|
2215
|
+
tCtx.fill();
|
|
2216
|
+
tCtx.globalAlpha = 1;
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
tCtx.save();
|
|
2220
|
+
tCtx.globalCompositeOperation = "destination-out";
|
|
2221
|
+
const scratchCount = Math.floor(fontSize * 0.42);
|
|
2222
|
+
for (let i = 0; i < scratchCount; i++) {
|
|
2223
|
+
const pt = insidePixels[Math.floor(rand() * insidePixels.length)];
|
|
2224
|
+
if (pt) {
|
|
2225
|
+
const len = fontSize * (0.06 + rand() * 0.14);
|
|
2226
|
+
const angle = -Math.PI / 4.2 + (rand() - 0.5) * 0.1;
|
|
2227
|
+
tCtx.lineWidth = 0.5 + rand() * 0.8;
|
|
2228
|
+
tCtx.globalAlpha = 0.2 + rand() * 0.4;
|
|
2229
|
+
tCtx.beginPath();
|
|
2230
|
+
tCtx.moveTo(pt.x - Math.cos(angle) * (len / 2), pt.y - Math.sin(angle) * (len / 2));
|
|
2231
|
+
tCtx.lineTo(pt.x + Math.cos(angle) * (len / 2), pt.y + Math.sin(angle) * (len / 2));
|
|
2232
|
+
tCtx.stroke();
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
tCtx.restore();
|
|
2236
|
+
}
|
|
2237
|
+
tCtx.letterSpacing = originalLSpacing;
|
|
2238
|
+
ctx.save();
|
|
2239
|
+
const tintCanvas = createCanvas(cWidth, cHeight);
|
|
2240
|
+
tintCanvas.width = cWidth;
|
|
2241
|
+
tintCanvas.height = cHeight;
|
|
2242
|
+
const tintCtx = getCanvas2DContext(tintCanvas);
|
|
2243
|
+
if (tintCtx) {
|
|
2244
|
+
tintCtx.drawImage(tCanvas, 0, 0);
|
|
2245
|
+
tintCtx.globalCompositeOperation = "source-in";
|
|
2246
|
+
tintCtx.fillStyle = textFill;
|
|
2247
|
+
tintCtx.fillRect(0, 0, cWidth, cHeight);
|
|
2248
|
+
ctx.drawImage(tintCanvas, 0, 0);
|
|
2249
|
+
}
|
|
2250
|
+
ctx.restore();
|
|
2251
|
+
}
|
|
2252
|
+
} else {
|
|
2253
|
+
ctx.save();
|
|
2254
|
+
if (fillType !== "none") {
|
|
2255
|
+
if (usePerCharFill && fillType === "solid") {
|
|
2256
|
+
renderLines("fill", void 0, 0, 0, { perCharFill: true });
|
|
2257
|
+
} else {
|
|
2258
|
+
renderLines("fill", textFill);
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2261
|
+
ctx.restore();
|
|
2262
|
+
}
|
|
2263
|
+
if (strokeEnabled && strokeWidth > 0 && strokePosition === "inside") {
|
|
2264
|
+
applyStroke();
|
|
2265
|
+
}
|
|
2266
|
+
glowLayers.forEach((layer2) => {
|
|
2267
|
+
if (layer2.enabled && layer2.type === "inner" && layer2.opacity > 0) {
|
|
2268
|
+
ctx.save();
|
|
2269
|
+
if (!renderGlowLayer(layer2)) {
|
|
2270
|
+
ctx.globalCompositeOperation = "source-atop";
|
|
2271
|
+
const renderCount = Math.max(1, Math.min(20, layer2.strength ?? 1));
|
|
2272
|
+
for (let i = 0; i < renderCount; i += 1) {
|
|
2273
|
+
renderWithShadowTrick("fill", layer2.color, layer2.blur, 0, 0, layer2.opacity, "#000000", layer2.spread ?? 0);
|
|
2274
|
+
}
|
|
2275
|
+
}
|
|
2276
|
+
ctx.restore();
|
|
2277
|
+
}
|
|
2278
|
+
});
|
|
2279
|
+
if (shadowEnabled && shadowType === "inner" && shadowOpacity > 0) {
|
|
2280
|
+
ctx.save();
|
|
2281
|
+
ctx.globalCompositeOperation = "source-atop";
|
|
2282
|
+
renderWithShadowTrick("fill", shadowColor, shadowBlur, shadowOffsetX, shadowOffsetY, shadowOpacity, "#000000");
|
|
2283
|
+
ctx.restore();
|
|
2284
|
+
}
|
|
2285
|
+
if (isGlitch) {
|
|
2286
|
+
ctx.save();
|
|
2287
|
+
ctx.globalCompositeOperation = "source-atop";
|
|
2288
|
+
ctx.strokeStyle = "rgba(0,0,0,0.18)";
|
|
2289
|
+
ctx.lineWidth = 1.5;
|
|
2290
|
+
for (let ly = yMin; ly < yMax; ly += 4) {
|
|
2291
|
+
ctx.beginPath();
|
|
2292
|
+
ctx.moveTo(xMin - 50, ly);
|
|
2293
|
+
ctx.lineTo(xMax + 50, ly);
|
|
2294
|
+
ctx.stroke();
|
|
2295
|
+
}
|
|
2296
|
+
ctx.restore();
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
|
|
2300
|
+
// src/engine/mask.ts
|
|
2301
|
+
function applyMaskReveal(ctx, doc, width, height) {
|
|
2302
|
+
const maskLayer = doc.effectLayers.find((l) => l.type === "mask" && l.enabled);
|
|
2303
|
+
if (!maskLayer) return;
|
|
2304
|
+
const maskType = maskLayer.params.maskType || "alphaText";
|
|
2305
|
+
const progress = Math.max(0, Math.min(1, maskLayer.params.revealProgress ?? 1));
|
|
2306
|
+
if (progress >= 1) return;
|
|
2307
|
+
ctx.save();
|
|
2308
|
+
ctx.globalCompositeOperation = "destination-in";
|
|
2309
|
+
if (maskType === "rectReveal") {
|
|
2310
|
+
const w = width * progress;
|
|
2311
|
+
ctx.fillStyle = "#ffffff";
|
|
2312
|
+
ctx.fillRect(0, 0, w, height);
|
|
2313
|
+
} else {
|
|
2314
|
+
const w = width * progress;
|
|
2315
|
+
const grad = ctx.createLinearGradient(0, 0, width, 0);
|
|
2316
|
+
grad.addColorStop(0, "rgba(255,255,255,1)");
|
|
2317
|
+
grad.addColorStop(Math.max(0, progress - 0.02), "rgba(255,255,255,1)");
|
|
2318
|
+
grad.addColorStop(Math.min(1, progress + 0.02), "rgba(255,255,255,0)");
|
|
2319
|
+
grad.addColorStop(1, "rgba(255,255,255,0)");
|
|
2320
|
+
ctx.fillStyle = grad;
|
|
2321
|
+
ctx.fillRect(0, 0, width, height);
|
|
2322
|
+
}
|
|
2323
|
+
ctx.restore();
|
|
2324
|
+
}
|
|
2325
|
+
|
|
2326
|
+
// src/engine/evaluate.ts
|
|
2327
|
+
function evaluateScene(doc, time, ctx, options = {}) {
|
|
2328
|
+
const animated = applyTimelineAtTime(doc, time);
|
|
2329
|
+
const cfg = sceneToConfig(animated);
|
|
2330
|
+
const w = cfg.canvasWidth || DEFAULT_CANVAS_WIDTH;
|
|
2331
|
+
const h = cfg.canvasHeight || DEFAULT_CANVAS_HEIGHT;
|
|
2332
|
+
const filterLayers = animated.effectLayers.filter((l) => l.type === "filter" && l.enabled);
|
|
2333
|
+
const lastFilter = filterLayers[filterLayers.length - 1]?.params;
|
|
2334
|
+
const comp = {
|
|
2335
|
+
blur: lastFilter?.blur ?? animated.compositor.blur ?? 0,
|
|
2336
|
+
bloom: lastFilter?.bloom ?? animated.compositor.bloom ?? 0,
|
|
2337
|
+
bloomThreshold: animated.compositor.bloomThreshold ?? 0.6
|
|
2338
|
+
};
|
|
2339
|
+
const usePostFx = !options.skipPostFx && (comp.blur > 0 || comp.bloom > 0);
|
|
2340
|
+
const finishFrame = () => applyMaskReveal(ctx, animated, w, h);
|
|
2341
|
+
if (!usePostFx) {
|
|
2342
|
+
ctx.clearRect(0, 0, w, h);
|
|
2343
|
+
renderTextEffectCore(ctx, cfg);
|
|
2344
|
+
finishFrame();
|
|
2345
|
+
return;
|
|
2346
|
+
}
|
|
2347
|
+
const temp = CanvasDevice.acquire(w, h);
|
|
2348
|
+
const tctx = temp.getContext("2d");
|
|
2349
|
+
if (tctx) {
|
|
2350
|
+
tctx.clearRect(0, 0, w, h);
|
|
2351
|
+
renderTextEffectCore(tctx, cfg);
|
|
2352
|
+
applyMaskReveal(tctx, animated, w, h);
|
|
2353
|
+
ctx.clearRect(0, 0, w, h);
|
|
2354
|
+
if (supportsCtxFilter()) {
|
|
2355
|
+
ctx.save();
|
|
2356
|
+
const blur = Math.max(0, comp.blur);
|
|
2357
|
+
const bloom = Math.max(0, comp.bloom);
|
|
2358
|
+
if (blur > 0) ctx.filter = `blur(${blur}px)`;
|
|
2359
|
+
ctx.drawImage(temp, 0, 0);
|
|
2360
|
+
if (bloom > 0) {
|
|
2361
|
+
ctx.globalCompositeOperation = "screen";
|
|
2362
|
+
ctx.globalAlpha = Math.min(0.8, bloom * 0.25);
|
|
2363
|
+
ctx.filter = `blur(${Math.max(1, bloom * 4)}px)`;
|
|
2364
|
+
ctx.drawImage(temp, 0, 0);
|
|
2365
|
+
}
|
|
2366
|
+
ctx.restore();
|
|
2367
|
+
} else {
|
|
2368
|
+
ctx.drawImage(temp, 0, 0);
|
|
2369
|
+
}
|
|
2370
|
+
CanvasDevice.release(temp);
|
|
2371
|
+
return;
|
|
2372
|
+
}
|
|
2373
|
+
CanvasDevice.release(temp);
|
|
2374
|
+
renderTextEffectCore(ctx, cfg);
|
|
2375
|
+
finishFrame();
|
|
2376
|
+
}
|
|
2377
|
+
function evaluateConfig(cfg, time, ctx, options) {
|
|
2378
|
+
evaluateScene(textEffectConfigToScene(cfg), time, ctx, options);
|
|
2379
|
+
}
|
|
2380
|
+
|
|
2381
|
+
// src/rendering/textEffectRenderer.ts
|
|
2382
|
+
function isScene(value) {
|
|
2383
|
+
return Boolean(value && typeof value === "object" && Array.isArray(value.effectLayers) && value.canvas);
|
|
2384
|
+
}
|
|
2385
|
+
function isConfig(value) {
|
|
2386
|
+
return Boolean(value && typeof value === "object" && typeof value.text === "string" && typeof value.fontFamily === "string");
|
|
2387
|
+
}
|
|
2388
|
+
function renderTextEffectToCanvas(ctx, input) {
|
|
2389
|
+
const source = input.source;
|
|
2390
|
+
const scene = isScene(source) ? source : isScene(source?.scene) ? source.scene : isConfig(source?.config) ? textEffectConfigToScene(source.config) : isConfig(source) ? textEffectConfigToScene(source) : null;
|
|
2391
|
+
if (!scene) {
|
|
2392
|
+
return {
|
|
2393
|
+
capability: "text-effect",
|
|
2394
|
+
rendererVersion: CANONICAL_RENDERER_VERSION,
|
|
2395
|
+
diagnostics: [{ level: "error", code: "effect-source-invalid", message: "Text effect source is not a scene or supported configuration.", capability: "text-effect" }],
|
|
2396
|
+
usedDependencies: []
|
|
2397
|
+
};
|
|
2398
|
+
}
|
|
2399
|
+
if (isConfig(source)) evaluateConfig(source, input.context.time, ctx);
|
|
2400
|
+
else evaluateScene(scene, input.context.time, ctx);
|
|
2401
|
+
return {
|
|
2402
|
+
capability: "text-effect",
|
|
2403
|
+
revisionId: source?.revisionId,
|
|
2404
|
+
contentHash: source?.contentHash,
|
|
2405
|
+
rendererVersion: source?.rendererVersion ?? CANONICAL_RENDERER_VERSION,
|
|
2406
|
+
diagnostics: [],
|
|
2407
|
+
usedDependencies: []
|
|
2408
|
+
};
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2411
|
+
// src/textTemplates/validator.ts
|
|
2412
|
+
var MAX_NODES = 500;
|
|
2413
|
+
var MAX_CONTROLS = 100;
|
|
2414
|
+
function validateTextTemplateArtifact(artifact) {
|
|
2415
|
+
const diagnostics = [];
|
|
2416
|
+
if (!artifact || artifact.kind !== "text-template") {
|
|
2417
|
+
return [{ severity: "error", code: "TEMPLATE_KIND", message: "Artifact kind must be text-template" }];
|
|
2418
|
+
}
|
|
2419
|
+
const { document: document2, timing, controls } = artifact;
|
|
2420
|
+
if (!document2 || !document2.id) {
|
|
2421
|
+
diagnostics.push({ severity: "error", code: "TEMPLATE_ID", message: "Template ID is required" });
|
|
2422
|
+
}
|
|
2423
|
+
if (!Number.isFinite(document2.canvas.width) || document2.canvas.width <= 0 || !Number.isFinite(document2.canvas.height) || document2.canvas.height <= 0) {
|
|
2424
|
+
diagnostics.push({ severity: "error", code: "CANVAS_SIZE", message: "Canvas dimensions must be positive finite numbers" });
|
|
2425
|
+
}
|
|
2426
|
+
if (!Number.isFinite(timing.duration) || timing.duration <= 0) {
|
|
2427
|
+
diagnostics.push({ severity: "error", code: "DURATION", message: "Duration must be positive" });
|
|
2428
|
+
}
|
|
2429
|
+
if (!Number.isFinite(timing.fps) || timing.fps <= 0 || timing.fps > 240) {
|
|
2430
|
+
diagnostics.push({ severity: "error", code: "FPS", message: "FPS must be between 0 and 240" });
|
|
2431
|
+
}
|
|
2432
|
+
const ids = /* @__PURE__ */ new Set();
|
|
2433
|
+
let nodeCount = 0;
|
|
2434
|
+
const visit = (node) => {
|
|
2435
|
+
nodeCount += 1;
|
|
2436
|
+
if (!node.id) {
|
|
2437
|
+
diagnostics.push({ severity: "error", code: "NODE_ID", message: "Every node needs a stable ID" });
|
|
2438
|
+
} else if (ids.has(node.id)) {
|
|
2439
|
+
diagnostics.push({ severity: "error", code: "DUPLICATE_NODE_ID", message: `Duplicate node ID: ${node.id}`, nodeId: node.id });
|
|
2440
|
+
} else {
|
|
2441
|
+
ids.add(node.id);
|
|
2442
|
+
}
|
|
2443
|
+
for (const value of [node.x, node.y]) {
|
|
2444
|
+
if (!Number.isFinite(value)) {
|
|
2445
|
+
diagnostics.push({ severity: "error", code: "NODE_GEOMETRY", message: `Node ${node.id} has non-finite position`, nodeId: node.id });
|
|
2446
|
+
}
|
|
2447
|
+
}
|
|
2448
|
+
for (const [axis, value] of [["width", node.width], ["height", node.height]]) {
|
|
2449
|
+
if (value === "auto") {
|
|
2450
|
+
if (node.type !== "text" && node.type !== "container") {
|
|
2451
|
+
diagnostics.push({
|
|
2452
|
+
severity: "error",
|
|
2453
|
+
code: "NODE_GEOMETRY_AUTO_NOT_SUPPORTED",
|
|
2454
|
+
message: `Node ${node.id} (${node.type}) does not support auto ${axis} \u2014 only text and container nodes can use content-driven sizing`,
|
|
2455
|
+
nodeId: node.id
|
|
2456
|
+
});
|
|
2457
|
+
}
|
|
2458
|
+
} else if (!Number.isFinite(value)) {
|
|
2459
|
+
diagnostics.push({ severity: "error", code: "NODE_GEOMETRY", message: `Node ${node.id} has non-finite geometry`, nodeId: node.id });
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
if (node.type === "text" && !node.text) {
|
|
2463
|
+
diagnostics.push({ severity: "warning", code: "EMPTY_TEXT", message: `Text node ${node.id} is empty`, nodeId: node.id });
|
|
2464
|
+
}
|
|
2465
|
+
};
|
|
2466
|
+
(document2.nodes || []).forEach(visit);
|
|
2467
|
+
if (nodeCount > MAX_NODES) {
|
|
2468
|
+
diagnostics.push({ severity: "error", code: "NODE_LIMIT", message: `Template exceeds the ${MAX_NODES}-node limit` });
|
|
2469
|
+
}
|
|
2470
|
+
if ((controls || []).length > MAX_CONTROLS) {
|
|
2471
|
+
diagnostics.push({ severity: "error", code: "CONTROL_LIMIT", message: `Template exceeds the ${MAX_CONTROLS}-control limit` });
|
|
2472
|
+
}
|
|
2473
|
+
const controlIds = /* @__PURE__ */ new Set();
|
|
2474
|
+
for (const control of controls || []) {
|
|
2475
|
+
if (controlIds.has(control.id)) {
|
|
2476
|
+
diagnostics.push({ severity: "error", code: "DUPLICATE_CONTROL_ID", message: `Duplicate control ID: ${control.id}` });
|
|
2477
|
+
}
|
|
2478
|
+
controlIds.add(control.id);
|
|
2479
|
+
if (!ids.has(control.target.nodeId)) {
|
|
2480
|
+
diagnostics.push({ severity: "error", code: "CONTROL_TARGET", message: `Control ${control.id} targets missing node ${control.target.nodeId}` });
|
|
2481
|
+
}
|
|
2482
|
+
if (control.target.propertyPath.includes("__proto__") || control.target.propertyPath.includes("constructor") || control.target.propertyPath.includes("prototype")) {
|
|
2483
|
+
diagnostics.push({ severity: "error", code: "UNSAFE_TARGET", message: `Control ${control.id} has an unsafe target path` });
|
|
2484
|
+
}
|
|
2485
|
+
}
|
|
2486
|
+
const regions = [timing.intro, timing.outro, timing.loop].filter(Boolean);
|
|
2487
|
+
regions.forEach((region) => {
|
|
2488
|
+
if (!Number.isFinite(region.start) || !Number.isFinite(region.end) || region.start < 0 || region.end <= region.start || region.end > timing.duration) {
|
|
2489
|
+
diagnostics.push({ severity: "error", code: "TIMING_REGION", message: "Timing regions must fit within the template duration" });
|
|
2490
|
+
}
|
|
2491
|
+
});
|
|
2492
|
+
return diagnostics;
|
|
2493
|
+
}
|
|
2494
|
+
function assertValidTextTemplateArtifact(artifact) {
|
|
2495
|
+
const errors = validateTextTemplateArtifact(artifact).filter((diagnostic) => diagnostic.severity === "error");
|
|
2496
|
+
if (errors.length) {
|
|
2497
|
+
throw new Error(errors.map((diagnostic) => diagnostic.message).join("; "));
|
|
2498
|
+
}
|
|
2499
|
+
}
|
|
2500
|
+
|
|
2501
|
+
// src/textTemplates/normalize.ts
|
|
2502
|
+
function clone(value) {
|
|
2503
|
+
return JSON.parse(JSON.stringify(value));
|
|
2504
|
+
}
|
|
2505
|
+
function stableStringify(value) {
|
|
2506
|
+
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
2507
|
+
if (Array.isArray(value)) return `[${value.map(stableStringify).join(",")}]`;
|
|
2508
|
+
const object = value;
|
|
2509
|
+
return `{${Object.keys(object).sort().map((key) => `${JSON.stringify(key)}:${stableStringify(object[key])}`).join(",")}}`;
|
|
2510
|
+
}
|
|
2511
|
+
function canonicalTemplateHash(value) {
|
|
2512
|
+
const input = stableStringify(value);
|
|
2513
|
+
let hash = 2166136261;
|
|
2514
|
+
for (let index = 0; index < input.length; index += 1) {
|
|
2515
|
+
hash ^= input.charCodeAt(index);
|
|
2516
|
+
hash = Math.imul(hash, 16777619);
|
|
2517
|
+
}
|
|
2518
|
+
return `fnv1a-${(hash >>> 0).toString(16).padStart(8, "0")}`;
|
|
2519
|
+
}
|
|
2520
|
+
function now() {
|
|
2521
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
2522
|
+
}
|
|
2523
|
+
function resolveAnimatableValue(raw, fallback) {
|
|
2524
|
+
if (raw == null) return fallback;
|
|
2525
|
+
if (typeof raw === "object" && raw !== null && "keyframes" in raw && Array.isArray(raw.keyframes)) {
|
|
2526
|
+
const kfs = raw.keyframes;
|
|
2527
|
+
if (kfs.length > 0 && kfs[0]?.value !== void 0) {
|
|
2528
|
+
return kfs[0].value;
|
|
2529
|
+
}
|
|
2530
|
+
}
|
|
2531
|
+
return raw;
|
|
2532
|
+
}
|
|
2533
|
+
function resolveNumericProperty(raw, fallback) {
|
|
2534
|
+
const unwrapped = resolveAnimatableValue(raw, fallback);
|
|
2535
|
+
const n = Number(unwrapped);
|
|
2536
|
+
return Number.isFinite(n) ? n : fallback;
|
|
2537
|
+
}
|
|
2538
|
+
function resolveStringProperty(raw, fallback) {
|
|
2539
|
+
const unwrapped = resolveAnimatableValue(raw, fallback);
|
|
2540
|
+
return unwrapped != null ? String(unwrapped) : fallback;
|
|
2541
|
+
}
|
|
2542
|
+
function resolveDimension(raw, fallback) {
|
|
2543
|
+
if (raw === "auto") return "auto";
|
|
2544
|
+
const unwrapped = resolveAnimatableValue(raw, fallback);
|
|
2545
|
+
if (unwrapped === "auto") return "auto";
|
|
2546
|
+
const n = Number(unwrapped);
|
|
2547
|
+
return Number.isFinite(n) ? n : fallback;
|
|
2548
|
+
}
|
|
2549
|
+
function propertyKeyframes(layer2) {
|
|
2550
|
+
const result = {};
|
|
2551
|
+
for (const property of ["x", "y", "width", "height", "opacity", "fontSize", "fontWeight", "letterSpacing"]) {
|
|
2552
|
+
const value = layer2?.[property];
|
|
2553
|
+
if (value && typeof value === "object" && Array.isArray(value.keyframes) && value.keyframes.length > 0) {
|
|
2554
|
+
result[property] = { keyframes: clone(value.keyframes) };
|
|
2555
|
+
}
|
|
2556
|
+
}
|
|
2557
|
+
return Object.keys(result).length ? result : void 0;
|
|
2558
|
+
}
|
|
2559
|
+
function nodeAnimation(layer2) {
|
|
2560
|
+
const propertyFrames = propertyKeyframes(layer2);
|
|
2561
|
+
if (!propertyFrames) return layer2?.animation;
|
|
2562
|
+
return {
|
|
2563
|
+
...layer2?.animation || { in: "none", out: "none", inDuration: 0, outDuration: 0, hold: "full" },
|
|
2564
|
+
propertyKeyframes: propertyFrames
|
|
2565
|
+
};
|
|
2566
|
+
}
|
|
2567
|
+
function legacyLayerToNode(layer2, index) {
|
|
2568
|
+
const id = String(layer2?.id || `${layer2?.kind || "node"}-${index + 1}`);
|
|
2569
|
+
const x = resolveNumericProperty(layer2?.x ?? layer2?.relativePosition?.x, 0);
|
|
2570
|
+
const y = resolveNumericProperty(layer2?.y ?? layer2?.relativePosition?.y, 0);
|
|
2571
|
+
const width = resolveDimension(layer2?.width, 400);
|
|
2572
|
+
const height = resolveDimension(layer2?.height, 120);
|
|
2573
|
+
const animation = nodeAnimation(layer2);
|
|
2574
|
+
const anchor = layer2?.anchor;
|
|
2575
|
+
const parentId = layer2?.parentId;
|
|
2576
|
+
const visible = layer2?.visible !== false;
|
|
2577
|
+
if (layer2?.kind === "container" || layer2?.kind === "group") {
|
|
2578
|
+
const container = layer2?.containerProperties || layer2;
|
|
2579
|
+
const layout = container?.layout || {};
|
|
2580
|
+
return {
|
|
2581
|
+
id,
|
|
2582
|
+
name: String(layer2?.name || id),
|
|
2583
|
+
type: "container",
|
|
2584
|
+
layout: {
|
|
2585
|
+
type: layout.type === "absolute" ? "absolute" : "flex",
|
|
2586
|
+
direction: layout.direction === "column" ? "column" : "row",
|
|
2587
|
+
gap: resolveNumericProperty(layout.gap, 0),
|
|
2588
|
+
alignItems: ["start", "center", "end", "stretch"].includes(
|
|
2589
|
+
layout.alignItems
|
|
2590
|
+
) ? layout.alignItems : "center",
|
|
2591
|
+
justifyContent: [
|
|
2592
|
+
"start",
|
|
2593
|
+
"center",
|
|
2594
|
+
"end",
|
|
2595
|
+
"space-between",
|
|
2596
|
+
"space-around"
|
|
2597
|
+
].includes(layout.justifyContent) ? layout.justifyContent : "start",
|
|
2598
|
+
paddingTop: resolveNumericProperty(
|
|
2599
|
+
layout.paddingTop ?? container.paddingTop,
|
|
2600
|
+
0
|
|
2601
|
+
),
|
|
2602
|
+
paddingRight: resolveNumericProperty(
|
|
2603
|
+
layout.paddingRight ?? container.paddingRight,
|
|
2604
|
+
0
|
|
2605
|
+
),
|
|
2606
|
+
paddingBottom: resolveNumericProperty(
|
|
2607
|
+
layout.paddingBottom ?? container.paddingBottom,
|
|
2608
|
+
0
|
|
2609
|
+
),
|
|
2610
|
+
paddingLeft: resolveNumericProperty(
|
|
2611
|
+
layout.paddingLeft ?? container.paddingLeft,
|
|
2612
|
+
0
|
|
2613
|
+
)
|
|
2614
|
+
},
|
|
2615
|
+
x,
|
|
2616
|
+
y,
|
|
2617
|
+
width,
|
|
2618
|
+
height,
|
|
2619
|
+
visible,
|
|
2620
|
+
style: {
|
|
2621
|
+
backgroundColor: container?.backgroundColor ? resolveStringProperty(container.backgroundColor, "") : void 0,
|
|
2622
|
+
backgroundOpacity: resolveNumericProperty(
|
|
2623
|
+
container?.backgroundOpacity,
|
|
2624
|
+
1
|
|
2625
|
+
),
|
|
2626
|
+
borderRadius: resolveNumericProperty(
|
|
2627
|
+
container?.backgroundRadius ?? container?.borderRadius,
|
|
2628
|
+
0
|
|
2629
|
+
),
|
|
2630
|
+
borderColor: container?.backgroundBorderColor ?? container?.borderColor ? resolveStringProperty(
|
|
2631
|
+
container.backgroundBorderColor ?? container.borderColor,
|
|
2632
|
+
""
|
|
2633
|
+
) : void 0,
|
|
2634
|
+
borderWidth: resolveNumericProperty(
|
|
2635
|
+
container?.backgroundBorderWidth ?? container?.borderWidth,
|
|
2636
|
+
0
|
|
2637
|
+
),
|
|
2638
|
+
opacity: resolveNumericProperty(container?.opacity, 1)
|
|
2639
|
+
},
|
|
2640
|
+
animation,
|
|
2641
|
+
anchor,
|
|
2642
|
+
parentId
|
|
2643
|
+
};
|
|
2644
|
+
}
|
|
2645
|
+
if (layer2?.kind === "shape" || layer2?.kind === "solid") {
|
|
2646
|
+
const shape = layer2?.solidProperties || layer2;
|
|
2647
|
+
return {
|
|
2648
|
+
id,
|
|
2649
|
+
name: String(layer2?.name || id),
|
|
2650
|
+
type: "shape",
|
|
2651
|
+
shapeType: shape?.shape === "circle" ? "circle" : shape?.shape === "line" ? "line" : "rectangle",
|
|
2652
|
+
x,
|
|
2653
|
+
y,
|
|
2654
|
+
width: typeof width === "number" ? width : 400,
|
|
2655
|
+
height: typeof height === "number" ? height : 200,
|
|
2656
|
+
visible,
|
|
2657
|
+
style: {
|
|
2658
|
+
fillColor: resolveStringProperty(
|
|
2659
|
+
shape?.fill ?? shape?.color,
|
|
2660
|
+
"#000000"
|
|
2661
|
+
),
|
|
2662
|
+
fillOpacity: resolveNumericProperty(
|
|
2663
|
+
shape?.opacity ?? shape?.fillOpacity,
|
|
2664
|
+
1
|
|
2665
|
+
),
|
|
2666
|
+
strokeColor: shape?.stroke?.color ? resolveStringProperty(shape.stroke.color, "#000000") : void 0,
|
|
2667
|
+
strokeWidth: shape?.stroke?.width ? resolveNumericProperty(shape.stroke.width, 0) : void 0
|
|
2668
|
+
},
|
|
2669
|
+
animation,
|
|
2670
|
+
anchor,
|
|
2671
|
+
parentId
|
|
2672
|
+
};
|
|
2673
|
+
}
|
|
2674
|
+
if (layer2?.kind === "image") {
|
|
2675
|
+
const image = layer2?.imageProperties || layer2;
|
|
2676
|
+
return {
|
|
2677
|
+
id,
|
|
2678
|
+
name: String(layer2?.name || id),
|
|
2679
|
+
type: "media",
|
|
2680
|
+
mediaType: "image",
|
|
2681
|
+
x,
|
|
2682
|
+
y,
|
|
2683
|
+
width: typeof width === "number" ? width : 400,
|
|
2684
|
+
height: typeof height === "number" ? height : 300,
|
|
2685
|
+
visible,
|
|
2686
|
+
assetId: image?.assetId,
|
|
2687
|
+
src: image?.url,
|
|
2688
|
+
style: { opacity: resolveNumericProperty(image?.opacity, 1) },
|
|
2689
|
+
animation,
|
|
2690
|
+
anchor,
|
|
2691
|
+
parentId
|
|
2692
|
+
};
|
|
2693
|
+
}
|
|
2694
|
+
const text = layer2?.textProperties || layer2;
|
|
2695
|
+
return {
|
|
2696
|
+
id,
|
|
2697
|
+
name: String(layer2?.name || id),
|
|
2698
|
+
type: "text",
|
|
2699
|
+
text: resolveStringProperty(text?.content ?? text?.text, "Text"),
|
|
2700
|
+
x,
|
|
2701
|
+
y,
|
|
2702
|
+
width,
|
|
2703
|
+
height,
|
|
2704
|
+
visible,
|
|
2705
|
+
animation,
|
|
2706
|
+
anchor,
|
|
2707
|
+
parentId,
|
|
2708
|
+
style: {
|
|
2709
|
+
fontFamily: resolveStringProperty(text?.fontFamily, "Inter Variable"),
|
|
2710
|
+
fontSize: resolveNumericProperty(text?.fontSize, 48),
|
|
2711
|
+
fontWeight: resolveAnimatableValue(text?.fontWeight, 400),
|
|
2712
|
+
fontStyle: text?.fontStyle === "italic" ? "italic" : "normal",
|
|
2713
|
+
textColor: resolveStringProperty(
|
|
2714
|
+
text?.color ?? text?.textColor,
|
|
2715
|
+
"#FFFFFF"
|
|
2716
|
+
),
|
|
2717
|
+
textAlign: text?.align || text?.textAlign || "center",
|
|
2718
|
+
lineHeight: resolveNumericProperty(text?.lineHeight, 1.2),
|
|
2719
|
+
letterSpacing: resolveNumericProperty(text?.letterSpacing, 0),
|
|
2720
|
+
overflow: text?.overflow,
|
|
2721
|
+
verticalAlign: text?.verticalAlign
|
|
2722
|
+
},
|
|
2723
|
+
backgroundPanel: text?.backgroundColor || text?.backgroundPanel ? {
|
|
2724
|
+
color: text?.backgroundPanel?.color ?? text?.backgroundColor ? resolveStringProperty(
|
|
2725
|
+
text?.backgroundPanel?.color ?? text?.backgroundColor,
|
|
2726
|
+
"#000000"
|
|
2727
|
+
) : void 0,
|
|
2728
|
+
opacity: resolveNumericProperty(
|
|
2729
|
+
text?.backgroundPanel?.opacity ?? text?.backgroundOpacity,
|
|
2730
|
+
1
|
|
2731
|
+
),
|
|
2732
|
+
paddingTop: resolveNumericProperty(
|
|
2733
|
+
text?.backgroundPanel?.paddingTop ?? text?.paddingTop,
|
|
2734
|
+
0
|
|
2735
|
+
),
|
|
2736
|
+
paddingRight: resolveNumericProperty(
|
|
2737
|
+
text?.backgroundPanel?.paddingRight ?? text?.paddingRight,
|
|
2738
|
+
0
|
|
2739
|
+
),
|
|
2740
|
+
paddingBottom: resolveNumericProperty(
|
|
2741
|
+
text?.backgroundPanel?.paddingBottom ?? text?.paddingBottom,
|
|
2742
|
+
0
|
|
2743
|
+
),
|
|
2744
|
+
paddingLeft: resolveNumericProperty(
|
|
2745
|
+
text?.backgroundPanel?.paddingLeft ?? text?.paddingLeft,
|
|
2746
|
+
0
|
|
2747
|
+
),
|
|
2748
|
+
borderRadius: resolveNumericProperty(
|
|
2749
|
+
text?.backgroundPanel?.borderRadius ?? text?.backgroundRadius,
|
|
2750
|
+
0
|
|
2751
|
+
),
|
|
2752
|
+
borderColor: text?.backgroundPanel?.borderColor ?? text?.backgroundBorderColor ? resolveStringProperty(
|
|
2753
|
+
text?.backgroundPanel?.borderColor ?? text?.backgroundBorderColor,
|
|
2754
|
+
"#000000"
|
|
2755
|
+
) : void 0,
|
|
2756
|
+
borderWidth: resolveNumericProperty(
|
|
2757
|
+
text?.backgroundPanel?.borderWidth ?? text?.backgroundBorderWidth,
|
|
2758
|
+
0
|
|
2759
|
+
)
|
|
2760
|
+
} : void 0,
|
|
2761
|
+
spans: Array.isArray(text?.spans) ? clone(text.spans) : void 0,
|
|
2762
|
+
perCharFillEnabled: Boolean(text?.perCharFillEnabled),
|
|
2763
|
+
charFillColors: Array.isArray(text?.charFillColors) ? clone(text.charFillColors) : void 0,
|
|
2764
|
+
splitAnimator: text?.splitAnimator ? clone(text.splitAnimator) : void 0,
|
|
2765
|
+
textEffectRef: text?.styleRef ? clone(text.styleRef) : void 0,
|
|
2766
|
+
// Kept as optional metadata for compatibility with role-based editor
|
|
2767
|
+
// customizations. The canonical renderer does not depend on roles.
|
|
2768
|
+
...layer2?.role ? { role: String(layer2.role) } : {}
|
|
2769
|
+
};
|
|
2770
|
+
}
|
|
2771
|
+
function inferControls(nodes) {
|
|
2772
|
+
const controls = [];
|
|
2773
|
+
for (const node of nodes) {
|
|
2774
|
+
if (node.type === "text") {
|
|
2775
|
+
controls.push({
|
|
2776
|
+
id: `text-${node.id}`,
|
|
2777
|
+
label: node.name || "Text",
|
|
2778
|
+
type: "text",
|
|
2779
|
+
defaultValue: node.text,
|
|
2780
|
+
constraints: { multiline: true, maxLength: 500 },
|
|
2781
|
+
target: { nodeId: node.id, propertyPath: "text" }
|
|
2782
|
+
});
|
|
2783
|
+
}
|
|
2784
|
+
}
|
|
2785
|
+
return controls;
|
|
2786
|
+
}
|
|
2787
|
+
function collectDependencies(nodes) {
|
|
2788
|
+
const assets = [];
|
|
2789
|
+
const fonts = [];
|
|
2790
|
+
const textEffects = [];
|
|
2791
|
+
const seenAssets = /* @__PURE__ */ new Set();
|
|
2792
|
+
const seenFonts = /* @__PURE__ */ new Set();
|
|
2793
|
+
const seenEffects = /* @__PURE__ */ new Set();
|
|
2794
|
+
for (const node of nodes) {
|
|
2795
|
+
if (node.type === "media" && node.assetId && !seenAssets.has(node.assetId)) {
|
|
2796
|
+
assets.push({
|
|
2797
|
+
id: node.assetId,
|
|
2798
|
+
type: "image",
|
|
2799
|
+
mimeType: "image/png",
|
|
2800
|
+
uri: node.src || "",
|
|
2801
|
+
contentHash: node.assetId
|
|
2802
|
+
});
|
|
2803
|
+
seenAssets.add(node.assetId);
|
|
2804
|
+
}
|
|
2805
|
+
if (node.type === "text" && node.style?.fontFamily) {
|
|
2806
|
+
const key = `${node.style.fontFamily}:${node.style.fontWeight || 400}`;
|
|
2807
|
+
if (!seenFonts.has(key)) {
|
|
2808
|
+
fonts.push({
|
|
2809
|
+
family: node.style.fontFamily,
|
|
2810
|
+
weight: Number(node.style.fontWeight || 400),
|
|
2811
|
+
style: "normal"
|
|
2812
|
+
});
|
|
2813
|
+
seenFonts.add(key);
|
|
2814
|
+
}
|
|
2815
|
+
if (node.textEffectRef) {
|
|
2816
|
+
const effectKey = `${node.textEffectRef.effectId}:${node.textEffectRef.revisionId}`;
|
|
2817
|
+
if (!seenEffects.has(effectKey)) {
|
|
2818
|
+
textEffects.push(clone(node.textEffectRef));
|
|
2819
|
+
seenEffects.add(effectKey);
|
|
2820
|
+
}
|
|
2821
|
+
}
|
|
2822
|
+
}
|
|
2823
|
+
}
|
|
2824
|
+
return { assets, fonts, textEffects };
|
|
2825
|
+
}
|
|
2826
|
+
function normalizeTextTemplateArtifact(input) {
|
|
2827
|
+
if (!input || typeof input !== "object")
|
|
2828
|
+
throw new Error("Invalid text template artifact");
|
|
2829
|
+
const raw = input;
|
|
2830
|
+
const source = raw.document && typeof raw.document === "object" ? raw.document : raw;
|
|
2831
|
+
const rawLayers = Array.isArray(source.layers) ? source.layers : Array.isArray(source.elements) ? source.elements : [];
|
|
2832
|
+
const nodes = Array.isArray(source.nodes) ? clone(source.nodes) : rawLayers.map(legacyLayerToNode);
|
|
2833
|
+
const id = String(
|
|
2834
|
+
raw.metadata?.id ?? source.id ?? raw.id ?? "untitled-text-template"
|
|
2835
|
+
);
|
|
2836
|
+
const label = String(
|
|
2837
|
+
raw.metadata?.label ?? source.title ?? raw.label ?? raw.name ?? id
|
|
2838
|
+
);
|
|
2839
|
+
const duration = Number(
|
|
2840
|
+
raw.timing?.duration ?? source.duration ?? raw.duration ?? 4
|
|
2841
|
+
);
|
|
2842
|
+
const fps = Number(raw.timing?.fps ?? source.fps ?? raw.fps ?? 30);
|
|
2843
|
+
const width = Number(
|
|
2844
|
+
source.canvas?.width ?? source.canvasWidth ?? raw.canvasWidth ?? raw.width ?? 1920
|
|
2845
|
+
);
|
|
2846
|
+
const height = Number(
|
|
2847
|
+
source.canvas?.height ?? source.canvasHeight ?? raw.canvasHeight ?? raw.height ?? 1080
|
|
2848
|
+
);
|
|
2849
|
+
const createdAt = String(
|
|
2850
|
+
raw.revision?.createdAt ?? source.createdAt ?? now()
|
|
2851
|
+
);
|
|
2852
|
+
const document2 = {
|
|
2853
|
+
id,
|
|
2854
|
+
kind: TEXT_TEMPLATE_KIND,
|
|
2855
|
+
schemaVersion: TEXT_TEMPLATE_SCHEMA_VERSION,
|
|
2856
|
+
templateVersion: 1,
|
|
2857
|
+
canvas: {
|
|
2858
|
+
width,
|
|
2859
|
+
height,
|
|
2860
|
+
fps,
|
|
2861
|
+
backgroundColor: source.canvas?.backgroundColor ?? raw.backgroundColor
|
|
2862
|
+
},
|
|
2863
|
+
nodes,
|
|
2864
|
+
variables: source.variables && typeof source.variables === "object" ? clone(source.variables) : void 0
|
|
2865
|
+
};
|
|
2866
|
+
const controls = Array.isArray(raw.controls) ? clone(raw.controls) : inferControls(nodes);
|
|
2867
|
+
const timing = {
|
|
2868
|
+
duration,
|
|
2869
|
+
fps,
|
|
2870
|
+
durationPolicy: raw.timing?.durationPolicy || "stretch",
|
|
2871
|
+
intro: raw.timing?.intro ? clone(raw.timing.intro) : void 0,
|
|
2872
|
+
outro: raw.timing?.outro ? clone(raw.timing.outro) : void 0,
|
|
2873
|
+
loop: raw.timing?.loop ? clone(raw.timing.loop) : void 0,
|
|
2874
|
+
markers: Array.isArray(raw.timing?.markers) ? clone(raw.timing.markers) : void 0
|
|
2875
|
+
};
|
|
2876
|
+
const dependencies = raw.dependencies?.assets ? clone(raw.dependencies) : collectDependencies(nodes);
|
|
2877
|
+
const content = { document: document2, controls, timing, dependencies };
|
|
2878
|
+
const contentHash = String(
|
|
2879
|
+
raw.revision?.contentHash || canonicalTemplateHash(content)
|
|
2880
|
+
);
|
|
2881
|
+
const revision = {
|
|
2882
|
+
revisionId: String(
|
|
2883
|
+
raw.revision?.revisionId ?? raw.revisionId ?? `rev-${contentHash}`
|
|
2884
|
+
),
|
|
2885
|
+
contentHash,
|
|
2886
|
+
schemaVersion: TEXT_TEMPLATE_SCHEMA_VERSION,
|
|
2887
|
+
rendererVersion: String(
|
|
2888
|
+
raw.revision?.rendererVersion ?? raw.rendererVersion ?? TEXT_TEMPLATE_RENDERER_VERSION
|
|
2889
|
+
),
|
|
2890
|
+
createdAt,
|
|
2891
|
+
status: raw.revision?.status
|
|
2892
|
+
};
|
|
2893
|
+
const metadata = {
|
|
2894
|
+
id,
|
|
2895
|
+
label,
|
|
2896
|
+
category: String(
|
|
2897
|
+
raw.metadata?.category ?? source.category ?? raw.category ?? "title-card"
|
|
2898
|
+
),
|
|
2899
|
+
description: String(
|
|
2900
|
+
raw.metadata?.description ?? source.description ?? raw.description ?? ""
|
|
2901
|
+
),
|
|
2902
|
+
tags: Array.isArray(raw.metadata?.tags) ? clone(raw.metadata.tags) : Array.isArray(raw.tags) ? raw.tags.map(String) : [],
|
|
2903
|
+
creatorName: raw.metadata?.creatorName ?? raw.creatorName,
|
|
2904
|
+
creatorLink: raw.metadata?.creatorLink ?? raw.creatorLink,
|
|
2905
|
+
thumbnailUrl: raw.previews?.thumbnailUrl ?? raw.thumbnail ?? raw.thumbnailUrl,
|
|
2906
|
+
previewVideoUrl: raw.previews?.previewVideoUrl ?? raw.preview ?? raw.previewVideoUrl
|
|
2907
|
+
};
|
|
2908
|
+
return {
|
|
2909
|
+
kind: TEXT_TEMPLATE_KIND,
|
|
2910
|
+
schemaVersion: TEXT_TEMPLATE_SCHEMA_VERSION,
|
|
2911
|
+
metadata,
|
|
2912
|
+
document: document2,
|
|
2913
|
+
controls,
|
|
2914
|
+
timing,
|
|
2915
|
+
dependencies,
|
|
2916
|
+
revision,
|
|
2917
|
+
previews: raw.previews || metadata.thumbnailUrl || metadata.previewVideoUrl ? {
|
|
2918
|
+
thumbnailUrl: metadata.thumbnailUrl,
|
|
2919
|
+
previewVideoUrl: metadata.previewVideoUrl
|
|
2920
|
+
} : void 0
|
|
2921
|
+
};
|
|
2922
|
+
}
|
|
2923
|
+
|
|
2924
|
+
// src/textTemplates/compiler.ts
|
|
2925
|
+
function clone2(value) {
|
|
2926
|
+
return JSON.parse(JSON.stringify(value));
|
|
2927
|
+
}
|
|
2928
|
+
function findNode(nodes, id) {
|
|
2929
|
+
for (const node of nodes) {
|
|
2930
|
+
if (node.id === id) return node;
|
|
2931
|
+
}
|
|
2932
|
+
return void 0;
|
|
2933
|
+
}
|
|
2934
|
+
function setPath(target, path, value) {
|
|
2935
|
+
const parts = path.split(".").filter(Boolean);
|
|
2936
|
+
if (!parts.length || parts.some((part) => part === "__proto__" || part === "constructor" || part === "prototype")) {
|
|
2937
|
+
return;
|
|
2938
|
+
}
|
|
2939
|
+
let cursor = target;
|
|
2940
|
+
for (let index = 0; index < parts.length - 1; index += 1) {
|
|
2941
|
+
const part = parts[index];
|
|
2942
|
+
if (!cursor[part] || typeof cursor[part] !== "object") cursor[part] = {};
|
|
2943
|
+
cursor = cursor[part];
|
|
2944
|
+
}
|
|
2945
|
+
cursor[parts[parts.length - 1]] = value;
|
|
2946
|
+
}
|
|
2947
|
+
function finite(value, fallback) {
|
|
2948
|
+
return typeof value === "number" && Number.isFinite(value) ? value : fallback;
|
|
2949
|
+
}
|
|
2950
|
+
function fallbackTextWidth(text, style) {
|
|
2951
|
+
const fontSize = Math.max(1, finite(style.fontSize, 48));
|
|
2952
|
+
const letterSpacing = finite(style.letterSpacing, 0);
|
|
2953
|
+
return Array.from(text).reduce((total) => total + fontSize * 0.55 + letterSpacing, 0);
|
|
2954
|
+
}
|
|
2955
|
+
function measureTextNode(node, runtime) {
|
|
2956
|
+
const style = node.style;
|
|
2957
|
+
const lines = String(node.text ?? "").split("\n");
|
|
2958
|
+
const measure = runtime?.measureText;
|
|
2959
|
+
const widths = lines.map((line) => {
|
|
2960
|
+
const measured = measure?.(line, style)?.width;
|
|
2961
|
+
return Number.isFinite(measured) ? Math.max(0, measured) : fallbackTextWidth(line, style);
|
|
2962
|
+
});
|
|
2963
|
+
const lineHeight = Math.max(1, finite(style.fontSize, 48) * finite(style.lineHeight, 1.2));
|
|
2964
|
+
return {
|
|
2965
|
+
width: Math.max(1, ...widths),
|
|
2966
|
+
height: Math.max(1, lines.length * lineHeight)
|
|
2967
|
+
};
|
|
2968
|
+
}
|
|
2969
|
+
function resolveNodeSize(node, runtime) {
|
|
2970
|
+
if (node.type === "text") {
|
|
2971
|
+
const measured = measureTextNode(node, runtime);
|
|
2972
|
+
return {
|
|
2973
|
+
width: node.width === "auto" ? measured.width : Math.max(1, finite(node.width, measured.width)),
|
|
2974
|
+
height: node.height === "auto" ? measured.height : Math.max(1, finite(node.height, measured.height))
|
|
2975
|
+
};
|
|
2976
|
+
}
|
|
2977
|
+
return {
|
|
2978
|
+
width: node.width === "auto" ? 0 : Math.max(1, finite(node.width, 1)),
|
|
2979
|
+
height: node.height === "auto" ? 0 : Math.max(1, finite(node.height, 1))
|
|
2980
|
+
};
|
|
2981
|
+
}
|
|
2982
|
+
function resolveControls(controls, values) {
|
|
2983
|
+
const resolved = {};
|
|
2984
|
+
for (const control of controls || []) {
|
|
2985
|
+
const value = values && Object.prototype.hasOwnProperty.call(values, control.id) ? values[control.id] : control.defaultValue;
|
|
2986
|
+
if (control.type === "number") {
|
|
2987
|
+
const numeric = Number(value);
|
|
2988
|
+
resolved[control.id] = Number.isFinite(numeric) ? Math.min(
|
|
2989
|
+
control.constraints?.max ?? numeric,
|
|
2990
|
+
Math.max(control.constraints?.min ?? numeric, numeric)
|
|
2991
|
+
) : control.defaultValue;
|
|
2992
|
+
} else if (control.type === "boolean") {
|
|
2993
|
+
resolved[control.id] = value === true;
|
|
2994
|
+
} else {
|
|
2995
|
+
resolved[control.id] = value;
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
return resolved;
|
|
2999
|
+
}
|
|
3000
|
+
function mapTime(time, artifact, clipDuration) {
|
|
3001
|
+
const duration = artifact.timing.duration;
|
|
3002
|
+
const targetDuration = clipDuration && clipDuration > 0 ? clipDuration : duration;
|
|
3003
|
+
const localTime = Math.max(0, Math.min(time, targetDuration));
|
|
3004
|
+
if (artifact.timing.durationPolicy === "stretch" && targetDuration !== duration) {
|
|
3005
|
+
const introEnd = artifact.timing.intro?.end ?? 0;
|
|
3006
|
+
const outroDuration = duration - (artifact.timing.outro?.start ?? duration);
|
|
3007
|
+
const outroStartInTarget = targetDuration - outroDuration;
|
|
3008
|
+
if (localTime <= introEnd) {
|
|
3009
|
+
return localTime;
|
|
3010
|
+
} else if (localTime >= outroStartInTarget) {
|
|
3011
|
+
const outroProgress = outroDuration > 0 ? (localTime - outroStartInTarget) / outroDuration : 1;
|
|
3012
|
+
return (artifact.timing.outro?.start ?? duration) + outroProgress * outroDuration;
|
|
3013
|
+
} else {
|
|
3014
|
+
const flexibleTarget = Math.max(1e-3, outroStartInTarget - introEnd);
|
|
3015
|
+
const flexibleAuthored = Math.max(0, (artifact.timing.outro?.start ?? duration) - introEnd);
|
|
3016
|
+
const progress = (localTime - introEnd) / flexibleTarget;
|
|
3017
|
+
return introEnd + progress * flexibleAuthored;
|
|
3018
|
+
}
|
|
3019
|
+
}
|
|
3020
|
+
if (artifact.timing.durationPolicy === "loop") {
|
|
3021
|
+
const loop = artifact.timing.loop;
|
|
3022
|
+
if (loop && loop.end > loop.start && localTime > loop.start) {
|
|
3023
|
+
return loop.start + (localTime - loop.start) % (loop.end - loop.start);
|
|
3024
|
+
}
|
|
3025
|
+
}
|
|
3026
|
+
return Math.max(0, Math.min(localTime, duration));
|
|
3027
|
+
}
|
|
3028
|
+
function easeBezier(t) {
|
|
3029
|
+
const clamped = Math.max(0, Math.min(1, t));
|
|
3030
|
+
return cubicBezier(0.4, 0, 0.2, 1)(clamped);
|
|
3031
|
+
}
|
|
3032
|
+
function applyAnimationPreset(preset, t, direction) {
|
|
3033
|
+
const ease2 = easeBezier(t);
|
|
3034
|
+
const clamped = Math.max(0, Math.min(1, t));
|
|
3035
|
+
const p = direction === "in" ? ease2 : 1 - ease2;
|
|
3036
|
+
let opacity = 1;
|
|
3037
|
+
let x = 0;
|
|
3038
|
+
let y = 0;
|
|
3039
|
+
let scale = 1;
|
|
3040
|
+
let blur = 0;
|
|
3041
|
+
let typewriterProgress = 1;
|
|
3042
|
+
switch (preset) {
|
|
3043
|
+
case "fade":
|
|
3044
|
+
opacity = p;
|
|
3045
|
+
break;
|
|
3046
|
+
case "typewriter":
|
|
3047
|
+
typewriterProgress = direction === "in" ? clamped : 1 - clamped;
|
|
3048
|
+
break;
|
|
3049
|
+
case "slide-up":
|
|
3050
|
+
opacity = p;
|
|
3051
|
+
y = (1 - p) * 40;
|
|
3052
|
+
break;
|
|
3053
|
+
case "slide-down":
|
|
3054
|
+
opacity = p;
|
|
3055
|
+
y = (p - 1) * 40;
|
|
3056
|
+
break;
|
|
3057
|
+
case "slide-left":
|
|
3058
|
+
opacity = p;
|
|
3059
|
+
x = (1 - p) * 40;
|
|
3060
|
+
break;
|
|
3061
|
+
case "slide-right":
|
|
3062
|
+
opacity = p;
|
|
3063
|
+
x = (p - 1) * 40;
|
|
3064
|
+
break;
|
|
3065
|
+
case "scale-in":
|
|
3066
|
+
opacity = p;
|
|
3067
|
+
scale = 0.8 + p * 0.2;
|
|
3068
|
+
break;
|
|
3069
|
+
case "scale-out":
|
|
3070
|
+
opacity = p;
|
|
3071
|
+
scale = 1.2 - (1 - p) * 0.2;
|
|
3072
|
+
break;
|
|
3073
|
+
case "blur-in":
|
|
3074
|
+
case "blur-out":
|
|
3075
|
+
opacity = p;
|
|
3076
|
+
blur = (1 - p) * 15;
|
|
3077
|
+
break;
|
|
3078
|
+
case "3d-flip":
|
|
3079
|
+
opacity = p;
|
|
3080
|
+
scale = 0.6 + p * 0.4;
|
|
3081
|
+
y = (1 - p) * 25;
|
|
3082
|
+
break;
|
|
3083
|
+
case "scale-pop":
|
|
3084
|
+
opacity = p;
|
|
3085
|
+
scale = p < 0.7 ? p / 0.7 * 1.15 : 1.15 - (p - 0.7) / 0.3 * 0.15;
|
|
3086
|
+
break;
|
|
3087
|
+
case "wave":
|
|
3088
|
+
opacity = p;
|
|
3089
|
+
y = Math.sin(p * Math.PI) * -15;
|
|
3090
|
+
break;
|
|
3091
|
+
case "track-in":
|
|
3092
|
+
opacity = p;
|
|
3093
|
+
blur = (1 - p) * 8;
|
|
3094
|
+
break;
|
|
3095
|
+
case "glitch":
|
|
3096
|
+
opacity = p > 0.05 ? 1 : 0;
|
|
3097
|
+
x = Math.sin(p * 25) * 6 * (1 - p);
|
|
3098
|
+
break;
|
|
3099
|
+
case "none":
|
|
3100
|
+
default:
|
|
3101
|
+
break;
|
|
3102
|
+
}
|
|
3103
|
+
return { opacity, x, y, scale, blur, typewriterProgress };
|
|
3104
|
+
}
|
|
3105
|
+
function computeNodeAnimationState(animation, time, duration) {
|
|
3106
|
+
if (!animation) return { opacity: 1, x: 0, y: 0, scale: 1, blur: 0, typewriterProgress: 1 };
|
|
3107
|
+
const inEnd = Number(animation.inDuration ?? 0);
|
|
3108
|
+
const outStart = duration - Number(animation.outDuration ?? 0);
|
|
3109
|
+
if (time < inEnd && inEnd > 0) {
|
|
3110
|
+
const t = time / inEnd;
|
|
3111
|
+
return applyAnimationPreset(animation.in || "fade", t, "in");
|
|
3112
|
+
} else if (time > outStart && Number(animation.outDuration ?? 0) > 0) {
|
|
3113
|
+
const t = (time - outStart) / Number(animation.outDuration ?? 0);
|
|
3114
|
+
return applyAnimationPreset(animation.out || "fade", t, "out");
|
|
3115
|
+
}
|
|
3116
|
+
return { opacity: 1, x: 0, y: 0, scale: 1, blur: 0, typewriterProgress: 1 };
|
|
3117
|
+
}
|
|
3118
|
+
function evaluateNodeProperty(node, property, fallback, time, duration) {
|
|
3119
|
+
const frames = node.animation?.propertyKeyframes?.[property];
|
|
3120
|
+
if (!frames?.keyframes?.length) return fallback;
|
|
3121
|
+
return evaluateAnimatable(frames, time, duration);
|
|
3122
|
+
}
|
|
3123
|
+
function compileTextTemplate(artifact, context) {
|
|
3124
|
+
assertValidTextTemplateArtifact(artifact);
|
|
3125
|
+
const resolvedControls = resolveControls(artifact.controls, context.controlValues);
|
|
3126
|
+
const document2 = clone2(artifact.document);
|
|
3127
|
+
for (const control of artifact.controls || []) {
|
|
3128
|
+
const node = findNode(document2.nodes, control.target.nodeId);
|
|
3129
|
+
if (node) setPath(node, control.target.propertyPath, resolvedControls[control.id]);
|
|
3130
|
+
}
|
|
3131
|
+
const time = mapTime(context.time, artifact, context.clipDuration);
|
|
3132
|
+
const flexPositions = /* @__PURE__ */ new Map();
|
|
3133
|
+
const containers = (document2.nodes || []).filter((n) => n.type === "container");
|
|
3134
|
+
for (const container of containers) {
|
|
3135
|
+
const children = (document2.nodes || []).filter((n) => n.parentId === container.id && n.visible !== false);
|
|
3136
|
+
const layout = container.layout || { type: "flex", direction: "column", gap: 0, alignItems: "start", justifyContent: "start" };
|
|
3137
|
+
const direction = layout.direction || "column";
|
|
3138
|
+
const gap = layout.gap || 0;
|
|
3139
|
+
const padTop = layout.paddingTop || 0;
|
|
3140
|
+
const padRight = layout.paddingRight || 0;
|
|
3141
|
+
const padBottom = layout.paddingBottom || 0;
|
|
3142
|
+
const padLeft = layout.paddingLeft || 0;
|
|
3143
|
+
const alignItems = layout.alignItems || "center";
|
|
3144
|
+
const containerX = container.x;
|
|
3145
|
+
const containerY = container.y;
|
|
3146
|
+
if (direction === "column") {
|
|
3147
|
+
let totalChildHeight = 0;
|
|
3148
|
+
let maxChildWidth = 0;
|
|
3149
|
+
const childSizes = [];
|
|
3150
|
+
for (const child of children) {
|
|
3151
|
+
const measured = resolveNodeSize(child, context.runtime);
|
|
3152
|
+
const cw = measured.width;
|
|
3153
|
+
const ch = measured.height;
|
|
3154
|
+
childSizes.push({ id: child.id, width: cw, height: ch });
|
|
3155
|
+
totalChildHeight += ch;
|
|
3156
|
+
maxChildWidth = Math.max(maxChildWidth, cw);
|
|
3157
|
+
}
|
|
3158
|
+
if (children.length > 1) {
|
|
3159
|
+
totalChildHeight += (children.length - 1) * gap;
|
|
3160
|
+
}
|
|
3161
|
+
const containerW = container.width === "auto" ? maxChildWidth + padLeft + padRight : Number(container.width);
|
|
3162
|
+
const containerH = container.height === "auto" ? totalChildHeight + padTop + padBottom : Number(container.height);
|
|
3163
|
+
flexPositions.set(container.id, { x: containerX, y: containerY, width: containerW, height: containerH });
|
|
3164
|
+
let currentY = containerY + padTop;
|
|
3165
|
+
const innerW = Math.max(0, containerW - padLeft - padRight);
|
|
3166
|
+
for (const child of childSizes) {
|
|
3167
|
+
let childX = containerX + padLeft;
|
|
3168
|
+
if (alignItems === "center") {
|
|
3169
|
+
childX = containerX + padLeft + (innerW - child.width) / 2;
|
|
3170
|
+
} else if (alignItems === "end") {
|
|
3171
|
+
childX = containerX + padLeft + (innerW - child.width);
|
|
3172
|
+
} else if (alignItems === "stretch") {
|
|
3173
|
+
child.width = innerW;
|
|
3174
|
+
}
|
|
3175
|
+
flexPositions.set(child.id, { x: childX, y: currentY, width: child.width, height: child.height });
|
|
3176
|
+
currentY += child.height + gap;
|
|
3177
|
+
}
|
|
3178
|
+
} else {
|
|
3179
|
+
let totalChildWidth = 0;
|
|
3180
|
+
let maxChildHeight = 0;
|
|
3181
|
+
const childSizes = [];
|
|
3182
|
+
for (const child of children) {
|
|
3183
|
+
const measured = resolveNodeSize(child, context.runtime);
|
|
3184
|
+
const cw = measured.width;
|
|
3185
|
+
const ch = measured.height;
|
|
3186
|
+
childSizes.push({ id: child.id, width: cw, height: ch });
|
|
3187
|
+
totalChildWidth += cw;
|
|
3188
|
+
maxChildHeight = Math.max(maxChildHeight, ch);
|
|
3189
|
+
}
|
|
3190
|
+
if (children.length > 1) {
|
|
3191
|
+
totalChildWidth += (children.length - 1) * gap;
|
|
3192
|
+
}
|
|
3193
|
+
const containerW = container.width === "auto" ? totalChildWidth + padLeft + padRight : Number(container.width);
|
|
3194
|
+
const containerH = container.height === "auto" ? maxChildHeight + padTop + padBottom : Number(container.height);
|
|
3195
|
+
flexPositions.set(container.id, { x: containerX, y: containerY, width: containerW, height: containerH });
|
|
3196
|
+
let currentX = containerX + padLeft;
|
|
3197
|
+
const innerH = Math.max(0, containerH - padTop - padBottom);
|
|
3198
|
+
for (const child of childSizes) {
|
|
3199
|
+
let childY = containerY + padTop;
|
|
3200
|
+
if (alignItems === "center") {
|
|
3201
|
+
childY = containerY + padTop + (innerH - child.height) / 2;
|
|
3202
|
+
} else if (alignItems === "end") {
|
|
3203
|
+
childY = containerY + padTop + (innerH - child.height);
|
|
3204
|
+
} else if (alignItems === "stretch") {
|
|
3205
|
+
child.height = innerH;
|
|
3206
|
+
}
|
|
3207
|
+
flexPositions.set(child.id, { x: currentX, y: childY, width: child.width, height: child.height });
|
|
3208
|
+
currentX += child.width + gap;
|
|
3209
|
+
}
|
|
3210
|
+
}
|
|
3211
|
+
}
|
|
3212
|
+
const layers = (document2.nodes || []).map((node) => {
|
|
3213
|
+
const animState = computeNodeAnimationState(node.animation, time, artifact.timing.duration);
|
|
3214
|
+
const fullText = node.type === "text" ? node.text : void 0;
|
|
3215
|
+
const visibleText = fullText === void 0 ? void 0 : Array.from(fullText).slice(0, Math.floor(fullText.length * animState.typewriterProgress)).join("");
|
|
3216
|
+
const flexPos = flexPositions.get(node.id);
|
|
3217
|
+
const baseX = flexPos?.x ?? evaluateNodeProperty(node, "x", Number(node.x), time, artifact.timing.duration);
|
|
3218
|
+
const baseY = flexPos?.y ?? evaluateNodeProperty(node, "y", Number(node.y), time, artifact.timing.duration);
|
|
3219
|
+
const measuredSize = node.type === "text" ? measureTextNode(node, context.runtime) : void 0;
|
|
3220
|
+
const resolvedWidth = flexPos?.width ?? (node.width === "auto" ? measuredSize?.width ?? 1 : evaluateNodeProperty(node, "width", Number(node.width), time, artifact.timing.duration));
|
|
3221
|
+
const resolvedHeight = flexPos?.height ?? (node.height === "auto" ? measuredSize?.height ?? 1 : evaluateNodeProperty(node, "height", Number(node.height), time, artifact.timing.duration));
|
|
3222
|
+
const baseOpacity = node.type === "shape" ? node.style.fillOpacity ?? 1 : node.type === "media" ? node.style?.opacity ?? 1 : node.type === "container" ? node.style?.opacity ?? 1 : 1;
|
|
3223
|
+
return {
|
|
3224
|
+
id: node.id,
|
|
3225
|
+
type: node.type,
|
|
3226
|
+
parentId: node.parentId,
|
|
3227
|
+
x: baseX + animState.x,
|
|
3228
|
+
y: baseY + animState.y,
|
|
3229
|
+
width: resolvedWidth * animState.scale,
|
|
3230
|
+
height: resolvedHeight * animState.scale,
|
|
3231
|
+
rotation: 0,
|
|
3232
|
+
opacity: node.visible === false ? 0 : animState.opacity * baseOpacity,
|
|
3233
|
+
visible: node.visible !== false && animState.opacity > 0,
|
|
3234
|
+
text: visibleText,
|
|
3235
|
+
assetId: node.type === "media" ? node.assetId : void 0,
|
|
3236
|
+
mediaUrl: node.type === "media" ? node.src : void 0,
|
|
3237
|
+
style: node.style,
|
|
3238
|
+
content: node.type === "text" ? {
|
|
3239
|
+
text: node.text,
|
|
3240
|
+
backgroundPanel: node.backgroundPanel,
|
|
3241
|
+
splitAnimator: node.splitAnimator,
|
|
3242
|
+
typewriterProgress: animState.typewriterProgress,
|
|
3243
|
+
splitProgress: Number(node.animation?.inDuration ?? 0) > 0 ? Math.max(0, Math.min(1, time / Number(node.animation?.inDuration))) : 1
|
|
3244
|
+
} : void 0
|
|
3245
|
+
};
|
|
3246
|
+
});
|
|
3247
|
+
const capabilities = {
|
|
3248
|
+
studio: { status: "exact", unsupportedFeatures: [], warnings: [] },
|
|
3249
|
+
editor: { status: "exact", unsupportedFeatures: [], warnings: [] },
|
|
3250
|
+
export: { status: "exact", unsupportedFeatures: [], warnings: [] }
|
|
3251
|
+
};
|
|
3252
|
+
return {
|
|
3253
|
+
kind: "text-template",
|
|
3254
|
+
templateId: artifact.metadata.id,
|
|
3255
|
+
revisionId: artifact.revision.revisionId,
|
|
3256
|
+
contentHash: artifact.revision.contentHash || canonicalTemplateHash(artifact),
|
|
3257
|
+
width: artifact.document.canvas.width,
|
|
3258
|
+
height: artifact.document.canvas.height,
|
|
3259
|
+
duration: artifact.timing.duration,
|
|
3260
|
+
fps: artifact.timing.fps,
|
|
3261
|
+
time,
|
|
3262
|
+
evaluatedScene: { nodes: layers, diagnostics: [] },
|
|
3263
|
+
resolvedControls,
|
|
3264
|
+
layers,
|
|
3265
|
+
dependencies: artifact.dependencies,
|
|
3266
|
+
capabilities,
|
|
3267
|
+
diagnostics: []
|
|
3268
|
+
};
|
|
3269
|
+
}
|
|
3270
|
+
|
|
3271
|
+
// src/templates/textSplitter.ts
|
|
3272
|
+
function splitTextContent(text, mode) {
|
|
3273
|
+
if (!text) return [];
|
|
3274
|
+
const units = [];
|
|
3275
|
+
if (mode === "character") {
|
|
3276
|
+
const chars = Array.from(text);
|
|
3277
|
+
let charPos = 0;
|
|
3278
|
+
chars.forEach((char, idx) => {
|
|
3279
|
+
units.push({
|
|
3280
|
+
text: char,
|
|
3281
|
+
index: idx,
|
|
3282
|
+
totalUnits: chars.length,
|
|
3283
|
+
charStartIndex: charPos,
|
|
3284
|
+
charEndIndex: charPos + char.length,
|
|
3285
|
+
isWhitespace: char === " " || char === " " || char === "\n"
|
|
3286
|
+
});
|
|
3287
|
+
charPos += char.length;
|
|
3288
|
+
});
|
|
3289
|
+
} else if (mode === "word") {
|
|
3290
|
+
const tokens = text.match(/\S+|\s+/g) || [text];
|
|
3291
|
+
let wordIdx = 0;
|
|
3292
|
+
let charPos = 0;
|
|
3293
|
+
tokens.forEach((token) => {
|
|
3294
|
+
const isWhitespace = /^\s+$/.test(token);
|
|
3295
|
+
units.push({
|
|
3296
|
+
text: token,
|
|
3297
|
+
index: isWhitespace ? -1 : wordIdx++,
|
|
3298
|
+
totalUnits: 0,
|
|
3299
|
+
// Assigned below
|
|
3300
|
+
charStartIndex: charPos,
|
|
3301
|
+
charEndIndex: charPos + token.length,
|
|
3302
|
+
isWhitespace
|
|
3303
|
+
});
|
|
3304
|
+
charPos += token.length;
|
|
3305
|
+
});
|
|
3306
|
+
const totalWords = wordIdx;
|
|
3307
|
+
units.forEach((u) => {
|
|
3308
|
+
u.totalUnits = totalWords;
|
|
3309
|
+
});
|
|
3310
|
+
} else if (mode === "line") {
|
|
3311
|
+
const lines = text.split("\n");
|
|
3312
|
+
let charPos = 0;
|
|
3313
|
+
lines.forEach((line, idx) => {
|
|
3314
|
+
units.push({
|
|
3315
|
+
text: line,
|
|
3316
|
+
index: idx,
|
|
3317
|
+
totalUnits: lines.length,
|
|
3318
|
+
charStartIndex: charPos,
|
|
3319
|
+
charEndIndex: charPos + line.length,
|
|
3320
|
+
isWhitespace: line.length === 0
|
|
3321
|
+
});
|
|
3322
|
+
charPos += line.length + 1;
|
|
3323
|
+
});
|
|
3324
|
+
}
|
|
3325
|
+
return units;
|
|
3326
|
+
}
|
|
3327
|
+
function getStaggerRank(index, totalUnits, direction, seed = 42) {
|
|
3328
|
+
if (totalUnits <= 1) return 0;
|
|
3329
|
+
switch (direction) {
|
|
3330
|
+
case "start-to-end":
|
|
3331
|
+
return index;
|
|
3332
|
+
case "end-to-start":
|
|
3333
|
+
return totalUnits - 1 - index;
|
|
3334
|
+
case "center-out": {
|
|
3335
|
+
const center = (totalUnits - 1) / 2;
|
|
3336
|
+
return Math.abs(index - center);
|
|
3337
|
+
}
|
|
3338
|
+
case "edges-in": {
|
|
3339
|
+
const center = (totalUnits - 1) / 2;
|
|
3340
|
+
return center - Math.abs(index - center);
|
|
3341
|
+
}
|
|
3342
|
+
case "random": {
|
|
3343
|
+
let t = (index + 1) * (seed + 1831565813);
|
|
3344
|
+
t = Math.imul(t ^ t >>> 15, t | 1);
|
|
3345
|
+
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
|
|
3346
|
+
const rand = ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
3347
|
+
return rand * totalUnits;
|
|
3348
|
+
}
|
|
3349
|
+
default:
|
|
3350
|
+
return index;
|
|
3351
|
+
}
|
|
3352
|
+
}
|
|
3353
|
+
function evaluateSplitTextTransforms(units, animator, progress, direction = "in") {
|
|
3354
|
+
const {
|
|
3355
|
+
direction: staggerDir,
|
|
3356
|
+
delayPerUnit,
|
|
3357
|
+
overlap,
|
|
3358
|
+
randomSeed = 1234,
|
|
3359
|
+
initialTransform,
|
|
3360
|
+
easing = "ease",
|
|
3361
|
+
bezier,
|
|
3362
|
+
durationPerUnit = 0.4
|
|
3363
|
+
} = animator;
|
|
3364
|
+
const validUnits = units.filter((u) => !u.isWhitespace || animator.splitBy === "character");
|
|
3365
|
+
const totalUnits = validUnits.length;
|
|
3366
|
+
if (totalUnits === 0) return [];
|
|
3367
|
+
const maxRank = Math.max(
|
|
3368
|
+
...validUnits.map((u) => getStaggerRank(u.index >= 0 ? u.index : 0, totalUnits, staggerDir, randomSeed))
|
|
3369
|
+
);
|
|
3370
|
+
return units.map((unit) => {
|
|
3371
|
+
if (unit.isWhitespace && animator.splitBy !== "character") {
|
|
3372
|
+
return {
|
|
3373
|
+
unit,
|
|
3374
|
+
progress: 1,
|
|
3375
|
+
x: 0,
|
|
3376
|
+
y: 0,
|
|
3377
|
+
z: 0,
|
|
3378
|
+
scale: 1,
|
|
3379
|
+
scaleX: 1,
|
|
3380
|
+
scaleY: 1,
|
|
3381
|
+
rotation: 0,
|
|
3382
|
+
rotateX: 0,
|
|
3383
|
+
rotateY: 0,
|
|
3384
|
+
opacity: 1,
|
|
3385
|
+
blur: 0,
|
|
3386
|
+
letterSpacingOffset: 0
|
|
3387
|
+
};
|
|
3388
|
+
}
|
|
3389
|
+
const rank = getStaggerRank(unit.index >= 0 ? unit.index : 0, totalUnits, staggerDir, randomSeed);
|
|
3390
|
+
const staggerNormalized = maxRank > 0 ? rank / maxRank * (1 - overlap) : 0;
|
|
3391
|
+
const unitTimeSpan = 1 - staggerNormalized;
|
|
3392
|
+
let unitProgress = unitTimeSpan > 0 ? Math.max(0, Math.min(1, (progress - staggerNormalized) / unitTimeSpan)) : 1;
|
|
3393
|
+
const easedT = applyEasing(unitProgress, easing, bezier);
|
|
3394
|
+
const p = direction === "in" ? easedT : 1 - easedT;
|
|
3395
|
+
const init = initialTransform;
|
|
3396
|
+
const x = (init.x ?? 0) * (1 - p);
|
|
3397
|
+
const y = (init.y ?? 0) * (1 - p);
|
|
3398
|
+
const z = (init.z ?? 0) * (1 - p);
|
|
3399
|
+
const scale = (init.scale ?? 1) * (1 - p) + 1 * p;
|
|
3400
|
+
const scaleX = (init.scaleX ?? 1) * (1 - p) + 1 * p;
|
|
3401
|
+
const scaleY = (init.scaleY ?? 1) * (1 - p) + 1 * p;
|
|
3402
|
+
const rotation = (init.rotation ?? 0) * (1 - p);
|
|
3403
|
+
const rotateX = (init.rotateX ?? 0) * (1 - p);
|
|
3404
|
+
const rotateY = (init.rotateY ?? 0) * (1 - p);
|
|
3405
|
+
const opacity = (init.opacity ?? 0) * (1 - p) + 1 * p;
|
|
3406
|
+
const blur = (init.blur ?? 0) * (1 - p);
|
|
3407
|
+
const letterSpacingOffset = (init.letterSpacingOffset ?? 0) * (1 - p);
|
|
3408
|
+
return {
|
|
3409
|
+
unit,
|
|
3410
|
+
progress: p,
|
|
3411
|
+
x,
|
|
3412
|
+
y,
|
|
3413
|
+
z,
|
|
3414
|
+
scale,
|
|
3415
|
+
scaleX,
|
|
3416
|
+
scaleY,
|
|
3417
|
+
rotation,
|
|
3418
|
+
rotateX,
|
|
3419
|
+
rotateY,
|
|
3420
|
+
opacity,
|
|
3421
|
+
blur,
|
|
3422
|
+
letterSpacingOffset
|
|
3423
|
+
};
|
|
3424
|
+
});
|
|
3425
|
+
}
|
|
3426
|
+
|
|
3427
|
+
// src/rendering/textTemplateRenderer.ts
|
|
3428
|
+
function isObject(value) {
|
|
3429
|
+
return Boolean(value && typeof value === "object");
|
|
3430
|
+
}
|
|
3431
|
+
function isCanonicalArtifact(value) {
|
|
3432
|
+
return isObject(value) && value.kind === "text-template" && isObject(value.document) && Array.isArray(value.document.nodes);
|
|
3433
|
+
}
|
|
3434
|
+
function hasLegacyLayers(value) {
|
|
3435
|
+
return isObject(value) && (Array.isArray(value.layers) || Array.isArray(value.elements));
|
|
3436
|
+
}
|
|
3437
|
+
function resolveTextTemplateArtifact(input, options = {}) {
|
|
3438
|
+
if (!isObject(input)) return null;
|
|
3439
|
+
if (isCanonicalArtifact(input)) return normalizeTextTemplateArtifact(input);
|
|
3440
|
+
for (const key of ["templateData", "injectedData", "templateDefinition", "lottieData", "artifact", "snapshot"]) {
|
|
3441
|
+
const nested = input[key];
|
|
3442
|
+
if (nested && nested !== input) {
|
|
3443
|
+
const resolved = resolveTextTemplateArtifact(nested, options);
|
|
3444
|
+
if (resolved) return resolved;
|
|
3445
|
+
}
|
|
3446
|
+
}
|
|
3447
|
+
if (options.allowLegacy !== false && hasLegacyLayers(input)) return normalizeTextTemplateArtifact(input);
|
|
3448
|
+
return null;
|
|
3449
|
+
}
|
|
3450
|
+
function getTextTemplateControls(input) {
|
|
3451
|
+
return resolveTextTemplateArtifact(input)?.controls ?? [];
|
|
3452
|
+
}
|
|
3453
|
+
function finite2(value, fallback) {
|
|
3454
|
+
const number = Number(value);
|
|
3455
|
+
return Number.isFinite(number) ? number : fallback;
|
|
3456
|
+
}
|
|
3457
|
+
function cssColor(value, fallback) {
|
|
3458
|
+
return typeof value === "string" && value.trim() ? value : fallback;
|
|
3459
|
+
}
|
|
3460
|
+
function roundedRect(ctx, x, y, width, height, radius) {
|
|
3461
|
+
const r = Math.max(0, Math.min(radius, Math.min(Math.abs(width), Math.abs(height)) / 2));
|
|
3462
|
+
if (r <= 0) {
|
|
3463
|
+
ctx.rect(x, y, width, height);
|
|
3464
|
+
return;
|
|
3465
|
+
}
|
|
3466
|
+
ctx.moveTo(x + r, y);
|
|
3467
|
+
ctx.arcTo(x + width, y, x + width, y + height, r);
|
|
3468
|
+
ctx.arcTo(x + width, y + height, x, y + height, r);
|
|
3469
|
+
ctx.arcTo(x, y + height, x, y, r);
|
|
3470
|
+
ctx.arcTo(x, y, x + width, y, r);
|
|
3471
|
+
ctx.closePath();
|
|
3472
|
+
}
|
|
3473
|
+
function drawPanel(ctx, panel, x, y, width, height) {
|
|
3474
|
+
ctx.save();
|
|
3475
|
+
const left = finite2(panel.paddingLeft, 0);
|
|
3476
|
+
const right = finite2(panel.paddingRight, left);
|
|
3477
|
+
const top = finite2(panel.paddingTop, 0);
|
|
3478
|
+
const bottom = finite2(panel.paddingBottom, top);
|
|
3479
|
+
const px = x - left;
|
|
3480
|
+
const py = y - top;
|
|
3481
|
+
const pw = width + left + right;
|
|
3482
|
+
const ph = height + top + bottom;
|
|
3483
|
+
ctx.beginPath();
|
|
3484
|
+
roundedRect(ctx, px, py, pw, ph, finite2(panel.borderRadius, 0));
|
|
3485
|
+
ctx.fillStyle = cssColor(panel.color, "#000000");
|
|
3486
|
+
ctx.globalAlpha *= Math.max(0, Math.min(1, finite2(panel.opacity, 1)));
|
|
3487
|
+
ctx.fill();
|
|
3488
|
+
if (finite2(panel.borderWidth, 0) > 0 && panel.borderColor) {
|
|
3489
|
+
ctx.lineWidth = finite2(panel.borderWidth, 1);
|
|
3490
|
+
ctx.strokeStyle = cssColor(panel.borderColor, "#000000");
|
|
3491
|
+
ctx.stroke();
|
|
3492
|
+
}
|
|
3493
|
+
ctx.restore();
|
|
3494
|
+
}
|
|
3495
|
+
function letterSpacedText(ctx, text, x, y, maxWidth, letterSpacing) {
|
|
3496
|
+
if (!letterSpacing) {
|
|
3497
|
+
ctx.fillText(text, x, y, maxWidth);
|
|
3498
|
+
return;
|
|
3499
|
+
}
|
|
3500
|
+
const glyphs = Array.from(text);
|
|
3501
|
+
const widths = glyphs.map((glyph) => ctx.measureText(glyph).width);
|
|
3502
|
+
const total = widths.reduce((sum, value) => sum + value, 0) + Math.max(0, glyphs.length - 1) * letterSpacing;
|
|
3503
|
+
const align = ctx.textAlign;
|
|
3504
|
+
let cursor = x;
|
|
3505
|
+
if (align === "center") cursor -= total / 2;
|
|
3506
|
+
if (align === "right") cursor -= total;
|
|
3507
|
+
ctx.textAlign = "left";
|
|
3508
|
+
for (let index = 0; index < glyphs.length; index += 1) {
|
|
3509
|
+
ctx.fillText(glyphs[index], cursor, y);
|
|
3510
|
+
cursor += widths[index] + letterSpacing;
|
|
3511
|
+
}
|
|
3512
|
+
ctx.textAlign = align;
|
|
3513
|
+
}
|
|
3514
|
+
var FONT_ALIAS_MAP = {
|
|
3515
|
+
"inter": "Inter Variable",
|
|
3516
|
+
"inter variable": "Inter Variable",
|
|
3517
|
+
"outfit": "Outfit Variable",
|
|
3518
|
+
"outfit variable": "Outfit Variable",
|
|
3519
|
+
"playfair display": "Playfair Display Variable",
|
|
3520
|
+
"playfair display variable": "Playfair Display Variable",
|
|
3521
|
+
"montserrat": "Montserrat Variable",
|
|
3522
|
+
"montserrat variable": "Montserrat Variable",
|
|
3523
|
+
"roboto": "Roboto Variable",
|
|
3524
|
+
"roboto variable": "Roboto Variable",
|
|
3525
|
+
"roboto condensed": "Roboto Condensed Variable",
|
|
3526
|
+
"roboto condensed variable": "Roboto Condensed Variable",
|
|
3527
|
+
"raleway": "Raleway Variable",
|
|
3528
|
+
"raleway variable": "Raleway Variable",
|
|
3529
|
+
"space grotesk": "Space Grotesk Variable",
|
|
3530
|
+
"space grotesk variable": "Space Grotesk Variable",
|
|
3531
|
+
"nunito": "Nunito Variable",
|
|
3532
|
+
"nunito variable": "Nunito Variable",
|
|
3533
|
+
"open sans": "Open Sans Variable",
|
|
3534
|
+
"open sans variable": "Open Sans Variable",
|
|
3535
|
+
"oswald": "Oswald Variable",
|
|
3536
|
+
"oswald variable": "Oswald Variable",
|
|
3537
|
+
"geist": "Geist Variable",
|
|
3538
|
+
"geist variable": "Geist Variable",
|
|
3539
|
+
"dancing script": "Dancing Script Variable",
|
|
3540
|
+
"dancing script variable": "Dancing Script Variable"
|
|
3541
|
+
};
|
|
3542
|
+
function resolveTemplateFontFamily(family) {
|
|
3543
|
+
if (!family) return "sans-serif";
|
|
3544
|
+
const clean = String(family).trim().replace(/^["']|["']$/g, "");
|
|
3545
|
+
const lower = clean.toLowerCase();
|
|
3546
|
+
return FONT_ALIAS_MAP[lower] || clean;
|
|
3547
|
+
}
|
|
3548
|
+
function constructFontStack(fontStyle, fontWeight, fontSize, rawFamily) {
|
|
3549
|
+
const canonical = resolveTemplateFontFamily(rawFamily);
|
|
3550
|
+
const cleanRaw = String(rawFamily || "").trim().replace(/^["']|["']$/g, "");
|
|
3551
|
+
const style = fontStyle === "italic" ? "italic" : "normal";
|
|
3552
|
+
const weight = fontWeight ?? 400;
|
|
3553
|
+
if (canonical && cleanRaw && canonical.toLowerCase() !== cleanRaw.toLowerCase()) {
|
|
3554
|
+
return `${style} ${weight} ${fontSize}px "${canonical}", "${cleanRaw}", sans-serif`;
|
|
3555
|
+
}
|
|
3556
|
+
return `${style} ${weight} ${fontSize}px "${canonical || cleanRaw || "sans-serif"}", sans-serif`;
|
|
3557
|
+
}
|
|
3558
|
+
function drawTextLayer(ctx, layer2, style) {
|
|
3559
|
+
const text = layer2.text ?? "";
|
|
3560
|
+
const fontSize = finite2(style.fontSize, 48);
|
|
3561
|
+
const fontWeight = style.fontWeight ?? 400;
|
|
3562
|
+
const fontStyle = style.fontStyle || "normal";
|
|
3563
|
+
const rawFamily = String(style.fontFamily || "sans-serif").replace(/"/g, "");
|
|
3564
|
+
ctx.font = constructFontStack(fontStyle, fontWeight, fontSize, rawFamily);
|
|
3565
|
+
ctx.fillStyle = cssColor(style.textColor, "#FFFFFF");
|
|
3566
|
+
ctx.textAlign = style.textAlign ?? "left";
|
|
3567
|
+
ctx.textBaseline = style.verticalAlign === "top" ? "top" : style.verticalAlign === "bottom" ? "bottom" : "middle";
|
|
3568
|
+
const lineHeight = fontSize * finite2(style.lineHeight, 1.2);
|
|
3569
|
+
const maxWidth = Math.max(1, layer2.width);
|
|
3570
|
+
const lines = style.overflow === "wrap" ? wrapText(ctx, text, maxWidth) : [text];
|
|
3571
|
+
const blockHeight = lines.length * lineHeight;
|
|
3572
|
+
const startY = style.verticalAlign === "top" ? layer2.y : style.verticalAlign === "bottom" ? layer2.y + layer2.height - blockHeight + lineHeight : layer2.y + (layer2.height - blockHeight) / 2 + lineHeight / 2;
|
|
3573
|
+
const anchorX = style.textAlign === "center" ? layer2.x + layer2.width / 2 : style.textAlign === "right" ? layer2.x + layer2.width : layer2.x;
|
|
3574
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
3575
|
+
letterSpacedText(ctx, lines[index], anchorX, startY + index * lineHeight, maxWidth, finite2(style.letterSpacing, 0));
|
|
3576
|
+
}
|
|
3577
|
+
}
|
|
3578
|
+
function drawSplitTextLayer(ctx, layer2, style, animator, progress) {
|
|
3579
|
+
const text = layer2.text ?? "";
|
|
3580
|
+
const fontSize = finite2(style.fontSize, 48);
|
|
3581
|
+
const fontWeight = style.fontWeight ?? 400;
|
|
3582
|
+
const fontStyle = style.fontStyle || "normal";
|
|
3583
|
+
const rawFamily = String(style.fontFamily || "sans-serif").replace(/"/g, "");
|
|
3584
|
+
ctx.font = constructFontStack(fontStyle, fontWeight, fontSize, rawFamily);
|
|
3585
|
+
ctx.textBaseline = "middle";
|
|
3586
|
+
ctx.textAlign = "left";
|
|
3587
|
+
ctx.fillStyle = cssColor(style.textColor, "#FFFFFF");
|
|
3588
|
+
const units = splitTextContent(text, animator.splitBy);
|
|
3589
|
+
const transforms = evaluateSplitTextTransforms(units, animator, progress, "in");
|
|
3590
|
+
const lineHeight = fontSize * finite2(style.lineHeight, 1.2);
|
|
3591
|
+
const fullWidth = ctx.measureText(text.split("\n")[0] ?? "").width;
|
|
3592
|
+
let cursorX = style.textAlign === "center" ? layer2.x + (layer2.width - fullWidth) / 2 : style.textAlign === "right" ? layer2.x + layer2.width - fullWidth : layer2.x;
|
|
3593
|
+
let cursorY = layer2.y + layer2.height / 2;
|
|
3594
|
+
for (const item of transforms) {
|
|
3595
|
+
if (item.unit.text.includes("\n")) {
|
|
3596
|
+
cursorX = layer2.x;
|
|
3597
|
+
cursorY += lineHeight;
|
|
3598
|
+
continue;
|
|
3599
|
+
}
|
|
3600
|
+
const advance = ctx.measureText(item.unit.text).width;
|
|
3601
|
+
ctx.save();
|
|
3602
|
+
ctx.globalAlpha *= Math.max(0, Math.min(1, item.opacity));
|
|
3603
|
+
if (item.blur > 0) ctx.filter = `blur(${item.blur}px)`;
|
|
3604
|
+
ctx.translate(cursorX + item.x, cursorY + item.y);
|
|
3605
|
+
ctx.rotate(item.rotation * Math.PI / 180);
|
|
3606
|
+
ctx.scale(item.scaleX, item.scaleY);
|
|
3607
|
+
ctx.fillText(item.unit.text, 0, 0);
|
|
3608
|
+
ctx.restore();
|
|
3609
|
+
cursorX += advance + item.letterSpacingOffset;
|
|
3610
|
+
}
|
|
3611
|
+
}
|
|
3612
|
+
function wrapText(ctx, text, maxWidth) {
|
|
3613
|
+
const words = text.split(/\s+/);
|
|
3614
|
+
const lines = [];
|
|
3615
|
+
let line = "";
|
|
3616
|
+
for (const word of words) {
|
|
3617
|
+
const candidate = line ? `${line} ${word}` : word;
|
|
3618
|
+
if (line && ctx.measureText(candidate).width > maxWidth) {
|
|
3619
|
+
lines.push(line);
|
|
3620
|
+
line = word;
|
|
3621
|
+
} else {
|
|
3622
|
+
line = candidate;
|
|
3623
|
+
}
|
|
3624
|
+
}
|
|
3625
|
+
if (line || !lines.length) lines.push(line);
|
|
3626
|
+
return lines;
|
|
3627
|
+
}
|
|
3628
|
+
function drawLayer(ctx, layer2) {
|
|
3629
|
+
if (!layer2.visible || layer2.opacity <= 0) return;
|
|
3630
|
+
ctx.save();
|
|
3631
|
+
ctx.globalAlpha *= Math.max(0, Math.min(1, layer2.opacity));
|
|
3632
|
+
if (layer2.type === "shape") {
|
|
3633
|
+
const style = layer2.style ?? {};
|
|
3634
|
+
ctx.beginPath();
|
|
3635
|
+
roundedRect(ctx, layer2.x, layer2.y, layer2.width, layer2.height, finite2(style.borderRadius, 0));
|
|
3636
|
+
ctx.fillStyle = cssColor(style.fillColor, "#000000");
|
|
3637
|
+
ctx.globalAlpha *= Math.max(0, Math.min(1, finite2(style.fillOpacity, 1)));
|
|
3638
|
+
ctx.fill();
|
|
3639
|
+
if (finite2(style.strokeWidth, 0) > 0 && style.strokeColor) {
|
|
3640
|
+
ctx.lineWidth = finite2(style.strokeWidth, 1);
|
|
3641
|
+
ctx.strokeStyle = cssColor(style.strokeColor, "#000000");
|
|
3642
|
+
ctx.stroke();
|
|
3643
|
+
}
|
|
3644
|
+
} else if (layer2.type === "container") {
|
|
3645
|
+
const style = layer2.style ?? {};
|
|
3646
|
+
if (style.backgroundColor) {
|
|
3647
|
+
ctx.beginPath();
|
|
3648
|
+
roundedRect(ctx, layer2.x, layer2.y, layer2.width, layer2.height, finite2(style.borderRadius, 0));
|
|
3649
|
+
ctx.fillStyle = cssColor(style.backgroundColor, "#000000");
|
|
3650
|
+
ctx.globalAlpha *= Math.max(0, Math.min(1, finite2(style.backgroundOpacity, 1)));
|
|
3651
|
+
ctx.fill();
|
|
3652
|
+
}
|
|
3653
|
+
} else if (layer2.type === "text" || layer2.type === "rich-text") {
|
|
3654
|
+
const style = layer2.style ?? {};
|
|
3655
|
+
if (style && layer2.content?.backgroundPanel) {
|
|
3656
|
+
drawPanel(ctx, layer2.content.backgroundPanel, layer2.x, layer2.y, layer2.width, layer2.height);
|
|
3657
|
+
}
|
|
3658
|
+
const splitAnimator = layer2.content?.splitAnimator;
|
|
3659
|
+
if (splitAnimator) {
|
|
3660
|
+
drawSplitTextLayer(ctx, layer2, style, splitAnimator, finite2(layer2.content?.splitProgress, 1));
|
|
3661
|
+
} else {
|
|
3662
|
+
drawTextLayer(ctx, layer2, style);
|
|
3663
|
+
}
|
|
3664
|
+
}
|
|
3665
|
+
ctx.restore();
|
|
3666
|
+
}
|
|
3667
|
+
function renderTextTemplateToCanvas(ctx, input) {
|
|
3668
|
+
const artifact = input.artifact;
|
|
3669
|
+
const runtime = {
|
|
3670
|
+
...input.context.runtime || {},
|
|
3671
|
+
// Measure with the exact Canvas context that will draw the layer. This
|
|
3672
|
+
// makes auto-sized nodes use loaded font metrics instead of a fixed box.
|
|
3673
|
+
measureText: (text, style) => {
|
|
3674
|
+
const rawFamily = String(style.fontFamily || "sans-serif").replace(/"/g, "");
|
|
3675
|
+
ctx.save();
|
|
3676
|
+
ctx.font = constructFontStack(style.fontStyle, style.fontWeight, finite2(style.fontSize, 48), rawFamily);
|
|
3677
|
+
const width = ctx.measureText(text).width + Math.max(0, text.length - 1) * finite2(style.letterSpacing, 0);
|
|
3678
|
+
ctx.restore();
|
|
3679
|
+
return { width };
|
|
3680
|
+
}
|
|
3681
|
+
};
|
|
3682
|
+
const compiled = compileTextTemplate(artifact, {
|
|
3683
|
+
time: input.context.time,
|
|
3684
|
+
target: input.context.environment === "preview" || input.context.environment === "thumbnail" ? "editor" : input.context.environment,
|
|
3685
|
+
clipDuration: input.context.clipDuration,
|
|
3686
|
+
controlValues: input.context.controlValues,
|
|
3687
|
+
runtime
|
|
3688
|
+
});
|
|
3689
|
+
const outputWidth = finite2(input.context.width, compiled.width);
|
|
3690
|
+
const outputHeight = finite2(input.context.height, compiled.height);
|
|
3691
|
+
const scaleX = outputWidth / compiled.width;
|
|
3692
|
+
const scaleY = outputHeight / compiled.height;
|
|
3693
|
+
ctx.save();
|
|
3694
|
+
ctx.scale(scaleX, scaleY);
|
|
3695
|
+
if (artifact.document.canvas.backgroundColor) {
|
|
3696
|
+
ctx.fillStyle = artifact.document.canvas.backgroundColor;
|
|
3697
|
+
ctx.fillRect(0, 0, compiled.width, compiled.height);
|
|
3698
|
+
}
|
|
3699
|
+
for (const layer2 of compiled.layers) drawLayer(ctx, layer2);
|
|
3700
|
+
ctx.restore();
|
|
3701
|
+
return {
|
|
3702
|
+
capability: "text-template",
|
|
3703
|
+
revisionId: compiled.revisionId,
|
|
3704
|
+
contentHash: compiled.contentHash,
|
|
3705
|
+
rendererVersion: artifact.revision.rendererVersion || TEXT_TEMPLATE_RENDERER_VERSION,
|
|
3706
|
+
diagnostics: compiled.diagnostics.map((diagnostic) => ({ ...diagnostic, capability: "text-template" })),
|
|
3707
|
+
usedDependencies: [
|
|
3708
|
+
...artifact.dependencies.fonts.map((font) => `font:${font.family}:${font.weight ?? "normal"}`),
|
|
3709
|
+
...artifact.dependencies.assets.map((asset) => `asset:${asset.id}:${asset.contentHash}`),
|
|
3710
|
+
...artifact.dependencies.textEffects.map((effect) => `text-effect:${effect.effectId}:${effect.revisionId}:${effect.contentHash}`)
|
|
3711
|
+
],
|
|
3712
|
+
compiledTemplate: compiled
|
|
3713
|
+
};
|
|
3714
|
+
}
|
|
3715
|
+
|
|
3716
|
+
// src/rendering/index.ts
|
|
3717
|
+
function renderCanonicalToCanvas(ctx, input) {
|
|
3718
|
+
if (input.capability === "text-template") {
|
|
3719
|
+
const artifact = resolveTextTemplateArtifact(input.artifact);
|
|
3720
|
+
if (!artifact) {
|
|
3721
|
+
return {
|
|
3722
|
+
capability: "text-template",
|
|
3723
|
+
rendererVersion: TEXT_TEMPLATE_RENDERER_VERSION,
|
|
3724
|
+
diagnostics: [{ level: "error", code: "template-artifact-missing", message: "A full text-template artifact is required for rendering.", capability: "text-template" }],
|
|
3725
|
+
usedDependencies: []
|
|
3726
|
+
};
|
|
3727
|
+
}
|
|
3728
|
+
return renderTextTemplateToCanvas(ctx, { artifact, context: input.context });
|
|
3729
|
+
}
|
|
3730
|
+
return renderTextEffectToCanvas(ctx, { source: input.source, context: input.context });
|
|
3731
|
+
}
|
|
3732
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
3733
|
+
0 && (module.exports = {
|
|
3734
|
+
CANONICAL_RENDERER_VERSION,
|
|
3735
|
+
TEXT_TEMPLATE_RENDERER_VERSION,
|
|
3736
|
+
getTextTemplateControls,
|
|
3737
|
+
renderCanonicalToCanvas,
|
|
3738
|
+
renderTextEffectToCanvas,
|
|
3739
|
+
renderTextTemplateToCanvas,
|
|
3740
|
+
resolveTemplateFontFamily,
|
|
3741
|
+
resolveTextTemplateArtifact
|
|
3742
|
+
});
|
|
3743
|
+
//# sourceMappingURL=index.cjs.map
|