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