@clypra-studio/engine 1.8.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-B2KQXJLS.js → chunk-JP44RJUI.js} +2 -2
- package/dist/{chunk-NG4F55V7.js → chunk-V5VSY64D.js} +2 -2
- package/dist/chunk-XHHAW7MS.js +598 -0
- package/dist/chunk-XHHAW7MS.js.map +1 -0
- package/dist/{chunk-7ORA5BPW.js → chunk-YBOYDQU5.js} +199 -2
- package/dist/chunk-YBOYDQU5.js.map +1 -0
- package/dist/index.cjs +647 -1744
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +345 -9
- package/dist/index.js.map +1 -1
- package/dist/rendering/index.cjs +198 -0
- package/dist/rendering/index.cjs.map +1 -1
- package/dist/rendering/index.js +2 -3
- package/dist/textEffects/index.cjs +198 -1
- package/dist/textEffects/index.cjs.map +1 -1
- package/dist/textEffects/index.js +2 -3
- package/dist/transitions/index.js +0 -1
- package/dist/videoEffects/index.cjs +106 -1741
- package/dist/videoEffects/index.cjs.map +1 -1
- package/dist/videoEffects/index.d.cts +2 -115
- package/dist/videoEffects/index.d.ts +2 -115
- package/dist/videoEffects/index.js +1 -6
- package/package.json +12 -12
- package/dist/chunk-7ORA5BPW.js.map +0 -1
- package/dist/chunk-PZ5AY32C.js +0 -10
- package/dist/chunk-PZ5AY32C.js.map +0 -1
- package/dist/chunk-SH7HOGVX.js +0 -2235
- package/dist/chunk-SH7HOGVX.js.map +0 -1
- /package/dist/{chunk-B2KQXJLS.js.map → chunk-JP44RJUI.js.map} +0 -0
- /package/dist/{chunk-NG4F55V7.js.map → chunk-V5VSY64D.js.map} +0 -0
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
evaluateScene,
|
|
7
7
|
sceneToConfig,
|
|
8
8
|
textEffectConfigToScene
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-YBOYDQU5.js";
|
|
10
10
|
|
|
11
11
|
// src/templates/keyframes.ts
|
|
12
12
|
function cubicBezier(x1, y1, x2, y2) {
|
|
@@ -2108,4 +2108,4 @@ export {
|
|
|
2108
2108
|
renderTextTemplateToCanvas,
|
|
2109
2109
|
renderCanonicalToCanvas
|
|
2110
2110
|
};
|
|
2111
|
-
//# sourceMappingURL=chunk-
|
|
2111
|
+
//# sourceMappingURL=chunk-JP44RJUI.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
resolveFontFamilyName
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-YBOYDQU5.js";
|
|
4
4
|
|
|
5
5
|
// src/fontLoader.ts
|
|
6
6
|
var FONT_VARIANTS = [
|
|
@@ -297,4 +297,4 @@ export {
|
|
|
297
297
|
resetFontLoader,
|
|
298
298
|
ensureFontsLoaded
|
|
299
299
|
};
|
|
300
|
-
//# sourceMappingURL=chunk-
|
|
300
|
+
//# sourceMappingURL=chunk-V5VSY64D.js.map
|
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
// src/videoEffects/effectsRegistry.ts
|
|
2
|
+
var EFFECTS_REGISTRY = {
|
|
3
|
+
shockwave: {
|
|
4
|
+
id: "shockwave",
|
|
5
|
+
name: "Shockwave",
|
|
6
|
+
category: "distortion",
|
|
7
|
+
description: "Expanding shockwave wave refraction",
|
|
8
|
+
defaultParams: {
|
|
9
|
+
centerX: 0.5,
|
|
10
|
+
centerY: 0.5,
|
|
11
|
+
speed: 1.5,
|
|
12
|
+
amplitude: 30,
|
|
13
|
+
wavelength: 160,
|
|
14
|
+
brightness: 1,
|
|
15
|
+
radius: 600,
|
|
16
|
+
animated: true
|
|
17
|
+
},
|
|
18
|
+
parameterSchema: {
|
|
19
|
+
centerX: { type: "number", label: "Center X", min: 0, max: 1, default: 0.5, step: 0.05 },
|
|
20
|
+
centerY: { type: "number", label: "Center Y", min: 0, max: 1, default: 0.5, step: 0.05 },
|
|
21
|
+
speed: { type: "number", label: "Speed", min: 0.1, max: 5, default: 1.5, step: 0.1 },
|
|
22
|
+
amplitude: { type: "number", label: "Amplitude", min: 1, max: 100, default: 30, step: 1 },
|
|
23
|
+
wavelength: { type: "number", label: "Wavelength", min: 10, max: 300, default: 160, step: 5 },
|
|
24
|
+
brightness: { type: "number", label: "Brightness", min: 0.5, max: 2, default: 1, step: 0.05 },
|
|
25
|
+
radius: { type: "number", label: "Max Radius", min: 100, max: 1e3, default: 600, step: 10 }
|
|
26
|
+
},
|
|
27
|
+
tags: ["distortion", "ripple", "shockwave"]
|
|
28
|
+
},
|
|
29
|
+
ChromaticAberration: {
|
|
30
|
+
id: "ChromaticAberration",
|
|
31
|
+
name: "Chromatic Aberration",
|
|
32
|
+
category: "glitch",
|
|
33
|
+
description: "Directional RGB channel displacement with optical edge-feather falloff",
|
|
34
|
+
defaultParams: {
|
|
35
|
+
amount: 8,
|
|
36
|
+
angleDegrees: 0,
|
|
37
|
+
edgeFeather: 0.5
|
|
38
|
+
},
|
|
39
|
+
parameterSchema: {
|
|
40
|
+
amount: { type: "number", label: "Amount (px)", min: 0, max: 50, default: 8, step: 0.5 },
|
|
41
|
+
angleDegrees: { type: "number", label: "Angle (\xB0)", min: 0, max: 360, default: 0, step: 1 },
|
|
42
|
+
edgeFeather: { type: "number", label: "Edge Feather", min: 0, max: 1, default: 0.5, step: 0.05 }
|
|
43
|
+
},
|
|
44
|
+
tags: ["glitch", "chromatic", "aberration", "color", "distortion", "lens", "optical"]
|
|
45
|
+
},
|
|
46
|
+
RgbSplit: {
|
|
47
|
+
id: "RgbSplit",
|
|
48
|
+
name: "RGB Split",
|
|
49
|
+
category: "glitch",
|
|
50
|
+
description: "Discrete horizontal and vertical color channel separation",
|
|
51
|
+
defaultParams: {
|
|
52
|
+
splitX: 8,
|
|
53
|
+
splitY: 8
|
|
54
|
+
},
|
|
55
|
+
parameterSchema: {
|
|
56
|
+
splitX: { type: "number", label: "Split X (px)", min: 0, max: 50, default: 8, step: 0.5 },
|
|
57
|
+
splitY: { type: "number", label: "Split Y (px)", min: 0, max: 50, default: 8, step: 0.5 }
|
|
58
|
+
},
|
|
59
|
+
tags: ["glitch", "rgb", "split", "color", "shift"]
|
|
60
|
+
},
|
|
61
|
+
FilmGrain: {
|
|
62
|
+
id: "FilmGrain",
|
|
63
|
+
name: "Film Grain",
|
|
64
|
+
category: "retro",
|
|
65
|
+
description: "Procedural cinematic film grain with adjustable size and intensity",
|
|
66
|
+
defaultParams: {
|
|
67
|
+
grainIntensity: 0.15,
|
|
68
|
+
grainSize: 1,
|
|
69
|
+
grainSeed: 0,
|
|
70
|
+
animated: true
|
|
71
|
+
},
|
|
72
|
+
parameterSchema: {
|
|
73
|
+
grainIntensity: { type: "number", label: "Intensity", min: 0, max: 1, default: 0.15, step: 0.01 },
|
|
74
|
+
grainSize: { type: "number", label: "Grain Size", min: 0.1, max: 5, default: 1, step: 0.1 },
|
|
75
|
+
grainSeed: { type: "number", label: "Grain Seed", min: 0, max: 100, default: 0, step: 0.1 },
|
|
76
|
+
animated: { type: "boolean", label: "Animated", default: true }
|
|
77
|
+
},
|
|
78
|
+
tags: ["retro", "film", "grain", "noise", "cinematic", "texture"]
|
|
79
|
+
},
|
|
80
|
+
Scanlines: {
|
|
81
|
+
id: "Scanlines",
|
|
82
|
+
name: "Scanlines",
|
|
83
|
+
category: "retro",
|
|
84
|
+
description: "CRT raster scanlines with controllable count and intensity",
|
|
85
|
+
defaultParams: {
|
|
86
|
+
scanlineCount: 120,
|
|
87
|
+
scanlineIntensity: 0.5
|
|
88
|
+
},
|
|
89
|
+
parameterSchema: {
|
|
90
|
+
scanlineCount: { type: "number", label: "Line Count", min: 10, max: 1e3, default: 120, step: 10 },
|
|
91
|
+
scanlineIntensity: { type: "number", label: "Intensity", min: 0, max: 1, default: 0.5, step: 0.05 }
|
|
92
|
+
},
|
|
93
|
+
tags: ["retro", "crt", "scanlines", "tv", "vhs", "analog"]
|
|
94
|
+
},
|
|
95
|
+
Pixelate: {
|
|
96
|
+
id: "Pixelate",
|
|
97
|
+
name: "Pixelate",
|
|
98
|
+
category: "retro",
|
|
99
|
+
description: "Mosaic pixelation with adjustable block size",
|
|
100
|
+
defaultParams: {
|
|
101
|
+
pixelSize: 18
|
|
102
|
+
},
|
|
103
|
+
parameterSchema: {
|
|
104
|
+
pixelSize: { type: "number", label: "Block Size (px)", min: 1, max: 100, default: 18, step: 1 }
|
|
105
|
+
},
|
|
106
|
+
tags: ["retro", "pixelate", "mosaic", "8bit", "censorship"]
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
function getEffectMetadata(id) {
|
|
110
|
+
return EFFECTS_REGISTRY[id];
|
|
111
|
+
}
|
|
112
|
+
function getEffectsByCategory(category) {
|
|
113
|
+
return Object.values(EFFECTS_REGISTRY).filter((effect) => effect.category === category);
|
|
114
|
+
}
|
|
115
|
+
function getEffectRenderer(id) {
|
|
116
|
+
if (id === "shockwave") {
|
|
117
|
+
return (ctx, _params, intensity, time) => {
|
|
118
|
+
const width = ctx.canvas.width;
|
|
119
|
+
const height = ctx.canvas.height;
|
|
120
|
+
ctx.save();
|
|
121
|
+
ctx.strokeStyle = `rgba(255, 255, 255, ${intensity * 0.25})`;
|
|
122
|
+
ctx.lineWidth = 6;
|
|
123
|
+
ctx.beginPath();
|
|
124
|
+
ctx.arc(width / 2, height / 2, time * 160 % (width / 2 + 50), 0, Math.PI * 2);
|
|
125
|
+
ctx.stroke();
|
|
126
|
+
ctx.restore();
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
function searchEffects(query) {
|
|
132
|
+
const lowerQuery = query.toLowerCase();
|
|
133
|
+
return Object.values(EFFECTS_REGISTRY).filter(
|
|
134
|
+
(effect) => effect.name.toLowerCase().includes(lowerQuery) || effect.description.toLowerCase().includes(lowerQuery) || effect.tags.some((tag) => tag.toLowerCase().includes(lowerQuery))
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// src/videoEffects/EffectRenderer.ts
|
|
139
|
+
var EffectRenderer = class {
|
|
140
|
+
/**
|
|
141
|
+
* Apply an effect to a canvas context
|
|
142
|
+
*
|
|
143
|
+
* @param ctx - Canvas 2D context
|
|
144
|
+
* @param renderer - Effect type
|
|
145
|
+
* @param params - Effect parameters
|
|
146
|
+
* @param intensity - Effect intensity (0-1)
|
|
147
|
+
* @param time - Current time for animated effects
|
|
148
|
+
*/
|
|
149
|
+
static apply(ctx, renderer, params, intensity = 1, time = 0, bodyMask) {
|
|
150
|
+
const method = getEffectRenderer(renderer);
|
|
151
|
+
if (method) {
|
|
152
|
+
method.call(this, ctx, params, intensity, time, bodyMask);
|
|
153
|
+
} else {
|
|
154
|
+
console.warn(`Unknown effect renderer: ${renderer}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// src/videoEffects/EffectGraph.ts
|
|
160
|
+
var EffectGraph = class {
|
|
161
|
+
schemaVersion;
|
|
162
|
+
graphId;
|
|
163
|
+
name;
|
|
164
|
+
nodes = /* @__PURE__ */ new Map();
|
|
165
|
+
edges = [];
|
|
166
|
+
connections = [];
|
|
167
|
+
constructor(definition) {
|
|
168
|
+
if (definition) {
|
|
169
|
+
this.schemaVersion = definition.schemaVersion;
|
|
170
|
+
this.graphId = definition.graphId;
|
|
171
|
+
this.name = definition.name;
|
|
172
|
+
for (const node of definition.nodes) {
|
|
173
|
+
this.nodes.set(node.id, node);
|
|
174
|
+
}
|
|
175
|
+
this.connections = [...definition.connections];
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
addNode(node) {
|
|
179
|
+
if (this.nodes.has(node.id)) {
|
|
180
|
+
throw new Error(`[EffectGraph] Node "${node.id}" already exists`);
|
|
181
|
+
}
|
|
182
|
+
this.nodes.set(node.id, node);
|
|
183
|
+
return this;
|
|
184
|
+
}
|
|
185
|
+
addEdge(from, to) {
|
|
186
|
+
if (!this.nodes.has(from)) throw new Error(`[EffectGraph] Unknown node "${from}"`);
|
|
187
|
+
if (!this.nodes.has(to)) throw new Error(`[EffectGraph] Unknown node "${to}"`);
|
|
188
|
+
this.edges.push({ from, to });
|
|
189
|
+
return this;
|
|
190
|
+
}
|
|
191
|
+
removeNode(id) {
|
|
192
|
+
this.nodes.delete(id);
|
|
193
|
+
this.edges = this.edges.filter((e) => e.from !== id && e.to !== id);
|
|
194
|
+
this.connections = this.connections.filter((c) => c.fromNode !== id && c.toNode !== id);
|
|
195
|
+
return this;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Topological sort via Kahn's algorithm.
|
|
199
|
+
* Returns nodes in render order or throws on circular dependency.
|
|
200
|
+
*/
|
|
201
|
+
resolve() {
|
|
202
|
+
const inDegree = /* @__PURE__ */ new Map();
|
|
203
|
+
const adjList = /* @__PURE__ */ new Map();
|
|
204
|
+
for (const id of this.nodes.keys()) {
|
|
205
|
+
inDegree.set(id, 0);
|
|
206
|
+
adjList.set(id, []);
|
|
207
|
+
}
|
|
208
|
+
for (const edge of this.edges) {
|
|
209
|
+
inDegree.set(edge.to, (inDegree.get(edge.to) ?? 0) + 1);
|
|
210
|
+
adjList.get(edge.from).push(edge.to);
|
|
211
|
+
}
|
|
212
|
+
for (const conn of this.connections) {
|
|
213
|
+
if (this.nodes.has(conn.fromNode) && this.nodes.has(conn.toNode)) {
|
|
214
|
+
const neighbors = adjList.get(conn.fromNode) || [];
|
|
215
|
+
if (!neighbors.includes(conn.toNode)) {
|
|
216
|
+
neighbors.push(conn.toNode);
|
|
217
|
+
adjList.set(conn.fromNode, neighbors);
|
|
218
|
+
inDegree.set(conn.toNode, (inDegree.get(conn.toNode) ?? 0) + 1);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
for (const [id, node] of this.nodes.entries()) {
|
|
223
|
+
if (node.dependencies) {
|
|
224
|
+
for (const depId of node.dependencies) {
|
|
225
|
+
if (this.nodes.has(depId)) {
|
|
226
|
+
const neighbors = adjList.get(depId) || [];
|
|
227
|
+
if (!neighbors.includes(id)) {
|
|
228
|
+
neighbors.push(id);
|
|
229
|
+
adjList.set(depId, neighbors);
|
|
230
|
+
inDegree.set(id, (inDegree.get(id) ?? 0) + 1);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const queue = [];
|
|
237
|
+
for (const [id, degree] of inDegree) {
|
|
238
|
+
if (degree === 0) queue.push(id);
|
|
239
|
+
}
|
|
240
|
+
const sorted = [];
|
|
241
|
+
while (queue.length > 0) {
|
|
242
|
+
const id = queue.shift();
|
|
243
|
+
sorted.push(this.nodes.get(id));
|
|
244
|
+
for (const neighbour of adjList.get(id) ?? []) {
|
|
245
|
+
const deg = (inDegree.get(neighbour) ?? 1) - 1;
|
|
246
|
+
inDegree.set(neighbour, deg);
|
|
247
|
+
if (deg === 0) queue.push(neighbour);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (sorted.length !== this.nodes.size) {
|
|
251
|
+
const cycle = [...this.nodes.keys()].filter((id) => (inDegree.get(id) ?? 0) > 0);
|
|
252
|
+
throw new Error(`[EffectGraph] Circular dependency detected in nodes: ${cycle.join(", ")}`);
|
|
253
|
+
}
|
|
254
|
+
return sorted;
|
|
255
|
+
}
|
|
256
|
+
getExecutionOrder() {
|
|
257
|
+
return this.resolve().map((node) => node.id);
|
|
258
|
+
}
|
|
259
|
+
getUpstreamNodes(nodeId) {
|
|
260
|
+
const node = this.nodes.get(nodeId);
|
|
261
|
+
const deps = node?.dependencies || [];
|
|
262
|
+
const connected = this.connections.filter((conn) => conn.toNode === nodeId).map((conn) => conn.fromNode);
|
|
263
|
+
return Array.from(/* @__PURE__ */ new Set([...deps, ...connected]));
|
|
264
|
+
}
|
|
265
|
+
/** Returns nodes that can execute in the browser-side authoring raster path. */
|
|
266
|
+
resolveCanvas2D() {
|
|
267
|
+
return this.resolve().filter((n) => n.effect?.backend !== "native");
|
|
268
|
+
}
|
|
269
|
+
get size() {
|
|
270
|
+
return this.nodes.size;
|
|
271
|
+
}
|
|
272
|
+
clear() {
|
|
273
|
+
this.nodes.clear();
|
|
274
|
+
this.edges = [];
|
|
275
|
+
this.connections = [];
|
|
276
|
+
return this;
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
// src/videoEffects/EffectEngine.ts
|
|
281
|
+
var EffectEngine = class {
|
|
282
|
+
activeGraph = null;
|
|
283
|
+
canvasPool = /* @__PURE__ */ new Map();
|
|
284
|
+
constructor() {
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Set the active effect graph to execute
|
|
288
|
+
*/
|
|
289
|
+
loadGraph(graph) {
|
|
290
|
+
this.activeGraph = graph;
|
|
291
|
+
this.clearPool();
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Clear active graph and associated canvases
|
|
295
|
+
*/
|
|
296
|
+
unloadGraph() {
|
|
297
|
+
this.activeGraph = null;
|
|
298
|
+
this.clearPool();
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Evaluate node parameters at specific timestamp `t`
|
|
302
|
+
*/
|
|
303
|
+
evaluateParameters(node, time) {
|
|
304
|
+
const params = { ...node.params };
|
|
305
|
+
if (!node.keyframes) return params;
|
|
306
|
+
for (const [key, track] of Object.entries(node.keyframes)) {
|
|
307
|
+
if (!track || track.length === 0) continue;
|
|
308
|
+
const sortedKeys = [...track].sort((a, b) => a.time - b.time);
|
|
309
|
+
if (time <= sortedKeys[0].time) {
|
|
310
|
+
params[key] = sortedKeys[0].value;
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
if (time >= sortedKeys[sortedKeys.length - 1].time) {
|
|
314
|
+
params[key] = sortedKeys[sortedKeys.length - 1].value;
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
for (let i = 0; i < sortedKeys.length - 1; i++) {
|
|
318
|
+
const k0 = sortedKeys[i];
|
|
319
|
+
const k1 = sortedKeys[i + 1];
|
|
320
|
+
if (time >= k0.time && time <= k1.time) {
|
|
321
|
+
const tRange = k1.time - k0.time;
|
|
322
|
+
const tProgress = tRange === 0 ? 0 : (time - k0.time) / tRange;
|
|
323
|
+
const easedProgress = this.applyEasing(k0.easing, tProgress);
|
|
324
|
+
params[key] = this.interpolate(k0.value, k1.value, easedProgress);
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return params;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Render the active graph onto a Canvas 2D Context
|
|
333
|
+
*
|
|
334
|
+
* @param ctx Target canvas context
|
|
335
|
+
* @param time Timestamp relative to effect start
|
|
336
|
+
* @param sourceTexture Optional raw image source
|
|
337
|
+
*/
|
|
338
|
+
render(ctx, time, sourceTexture) {
|
|
339
|
+
if (!this.activeGraph) return;
|
|
340
|
+
const width = ctx.canvas.width;
|
|
341
|
+
const height = ctx.canvas.height;
|
|
342
|
+
const execOrder = this.activeGraph.getExecutionOrder();
|
|
343
|
+
const outputs = /* @__PURE__ */ new Map();
|
|
344
|
+
for (const nodeId of execOrder) {
|
|
345
|
+
const node = this.activeGraph.nodes.get(nodeId);
|
|
346
|
+
const upstreams = this.activeGraph.getUpstreamNodes(nodeId);
|
|
347
|
+
const buffer = this.acquireCanvas(nodeId, width, height);
|
|
348
|
+
const bufferCtx = buffer.getContext("2d");
|
|
349
|
+
bufferCtx.clearRect(0, 0, width, height);
|
|
350
|
+
if (node.type === "source") {
|
|
351
|
+
if (sourceTexture) {
|
|
352
|
+
bufferCtx.drawImage(sourceTexture, 0, 0, width, height);
|
|
353
|
+
}
|
|
354
|
+
outputs.set(nodeId, buffer);
|
|
355
|
+
} else {
|
|
356
|
+
const evaluatedParams = this.evaluateParameters(node, time);
|
|
357
|
+
const intensity = evaluatedParams.intensity ?? 1;
|
|
358
|
+
if (upstreams.length > 0) {
|
|
359
|
+
const mainInput = outputs.get(upstreams[0]);
|
|
360
|
+
if (mainInput) {
|
|
361
|
+
bufferCtx.drawImage(mainInput, 0, 0, width, height);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
EffectRenderer.apply(bufferCtx, node.type, evaluatedParams, intensity, time);
|
|
365
|
+
outputs.set(nodeId, buffer);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
const finalNodeId = execOrder[execOrder.length - 1];
|
|
369
|
+
const finalFrame = outputs.get(finalNodeId);
|
|
370
|
+
if (finalFrame) {
|
|
371
|
+
ctx.drawImage(finalFrame, 0, 0, width, height);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Interpolate values (numbers or colors)
|
|
376
|
+
*/
|
|
377
|
+
interpolate(val0, val1, progress) {
|
|
378
|
+
if (typeof val0 === "number" && typeof val1 === "number") {
|
|
379
|
+
return val0 + (val1 - val0) * progress;
|
|
380
|
+
}
|
|
381
|
+
return progress < 0.5 ? val0 : val1;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Easing curves mapping
|
|
385
|
+
*/
|
|
386
|
+
applyEasing(easing, t) {
|
|
387
|
+
switch (easing) {
|
|
388
|
+
case "ease-in":
|
|
389
|
+
case "ease-in-quad":
|
|
390
|
+
return t * t;
|
|
391
|
+
case "ease-out":
|
|
392
|
+
case "ease-out-quad":
|
|
393
|
+
return t * (2 - t);
|
|
394
|
+
case "ease-in-out":
|
|
395
|
+
case "ease-in-out-quad":
|
|
396
|
+
return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
|
|
397
|
+
case "linear":
|
|
398
|
+
default:
|
|
399
|
+
return t;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Acquire Offscreen Canvas context from reuse pool
|
|
404
|
+
*/
|
|
405
|
+
acquireCanvas(nodeId, w, h) {
|
|
406
|
+
let canvas = this.canvasPool.get(nodeId);
|
|
407
|
+
if (!canvas) {
|
|
408
|
+
canvas = document.createElement("canvas");
|
|
409
|
+
this.canvasPool.set(nodeId, canvas);
|
|
410
|
+
}
|
|
411
|
+
if (canvas.width !== w || canvas.height !== h) {
|
|
412
|
+
canvas.width = w;
|
|
413
|
+
canvas.height = h;
|
|
414
|
+
}
|
|
415
|
+
return canvas;
|
|
416
|
+
}
|
|
417
|
+
clearPool() {
|
|
418
|
+
this.canvasPool.clear();
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
// src/videoEffects/utils/colorUtils.ts
|
|
423
|
+
function hexToRgba(hex, alpha) {
|
|
424
|
+
hex = hex.replace("#", "");
|
|
425
|
+
const r = parseInt(hex.substring(0, 2), 16);
|
|
426
|
+
const g = parseInt(hex.substring(2, 4), 16);
|
|
427
|
+
const b = parseInt(hex.substring(4, 6), 16);
|
|
428
|
+
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
429
|
+
}
|
|
430
|
+
function rgbaToComponents(rgba) {
|
|
431
|
+
const match = rgba.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);
|
|
432
|
+
if (!match) {
|
|
433
|
+
return { r: 0, g: 0, b: 0, a: 1 };
|
|
434
|
+
}
|
|
435
|
+
return {
|
|
436
|
+
r: parseInt(match[1]),
|
|
437
|
+
g: parseInt(match[2]),
|
|
438
|
+
b: parseInt(match[3]),
|
|
439
|
+
a: match[4] ? parseFloat(match[4]) : 1
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
function blendColors(color1, color2, ratio) {
|
|
443
|
+
const c1 = rgbaToComponents(color1);
|
|
444
|
+
const c2 = rgbaToComponents(color2);
|
|
445
|
+
const r = Math.round(c1.r * (1 - ratio) + c2.r * ratio);
|
|
446
|
+
const g = Math.round(c1.g * (1 - ratio) + c2.g * ratio);
|
|
447
|
+
const b = Math.round(c1.b * (1 - ratio) + c2.b * ratio);
|
|
448
|
+
const a = c1.a * (1 - ratio) + c2.a * ratio;
|
|
449
|
+
return `rgba(${r}, ${g}, ${b}, ${a})`;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// src/videoEffects/utils/canvasUtils.ts
|
|
453
|
+
function addNoise(ctx, amount) {
|
|
454
|
+
const width = ctx.canvas.width;
|
|
455
|
+
const height = ctx.canvas.height;
|
|
456
|
+
const imageData = ctx.getImageData(0, 0, width, height);
|
|
457
|
+
const data = imageData.data;
|
|
458
|
+
for (let i = 0; i < data.length; i += 4) {
|
|
459
|
+
const noise = (Math.random() - 0.5) * 255 * amount;
|
|
460
|
+
data[i] += noise;
|
|
461
|
+
data[i + 1] += noise;
|
|
462
|
+
data[i + 2] += noise;
|
|
463
|
+
}
|
|
464
|
+
ctx.putImageData(imageData, 0, 0);
|
|
465
|
+
}
|
|
466
|
+
function clearCanvas(ctx, color) {
|
|
467
|
+
if (color) {
|
|
468
|
+
ctx.fillStyle = color;
|
|
469
|
+
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
|
470
|
+
} else {
|
|
471
|
+
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
function withContext(ctx, fn) {
|
|
475
|
+
ctx.save();
|
|
476
|
+
try {
|
|
477
|
+
return fn(ctx);
|
|
478
|
+
} finally {
|
|
479
|
+
ctx.restore();
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// src/videoEffects/api.ts
|
|
484
|
+
function getEffectPreviewUrl(effectId, category) {
|
|
485
|
+
return `https://raw.githubusercontent.com/AIEraDev/clypra-api/main/public/effect-previews/${category}/${effectId}.webm`;
|
|
486
|
+
}
|
|
487
|
+
function effectMetadataToApi(metadata) {
|
|
488
|
+
const previewUrl = getEffectPreviewUrl(metadata.id, metadata.category);
|
|
489
|
+
return {
|
|
490
|
+
id: metadata.id,
|
|
491
|
+
name: metadata.name,
|
|
492
|
+
type: "effect",
|
|
493
|
+
category: metadata.category,
|
|
494
|
+
description: metadata.description,
|
|
495
|
+
thumbnail: generateThumbnailUrl(metadata.id),
|
|
496
|
+
renderer: metadata.id,
|
|
497
|
+
params: metadata.defaultParams,
|
|
498
|
+
parameterSchema: metadata.parameterSchema,
|
|
499
|
+
tags: metadata.tags,
|
|
500
|
+
isPremium: metadata.premium,
|
|
501
|
+
intensity: {
|
|
502
|
+
min: 0,
|
|
503
|
+
max: 1,
|
|
504
|
+
default: 0.8,
|
|
505
|
+
step: 0.01
|
|
506
|
+
},
|
|
507
|
+
previewUrl,
|
|
508
|
+
previewDuration: 3,
|
|
509
|
+
thumbnailUrl: generateThumbnailUrl(metadata.id)
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
function generateThumbnailUrl(effectId) {
|
|
513
|
+
return `https://raw.githubusercontent.com/AIEraDev/clypra-api/main/public/effect-thumbnails/${effectId}.jpg`;
|
|
514
|
+
}
|
|
515
|
+
function getAllEffectsForApi() {
|
|
516
|
+
return Object.values(EFFECTS_REGISTRY).map((metadata) => effectMetadataToApi(metadata));
|
|
517
|
+
}
|
|
518
|
+
function getEffectsByCategoryForApi(category) {
|
|
519
|
+
const effects = getEffectsByCategory(category);
|
|
520
|
+
return effects.map((metadata) => effectMetadataToApi(metadata));
|
|
521
|
+
}
|
|
522
|
+
function searchEffectsForApi(query) {
|
|
523
|
+
const results = searchEffects(query);
|
|
524
|
+
return results.map((metadata) => effectMetadataToApi(metadata));
|
|
525
|
+
}
|
|
526
|
+
function getEffectByIdForApi(id) {
|
|
527
|
+
const metadata = getEffectMetadata(id);
|
|
528
|
+
if (!metadata) return null;
|
|
529
|
+
return effectMetadataToApi(metadata);
|
|
530
|
+
}
|
|
531
|
+
function getEffectCategoriesSummary() {
|
|
532
|
+
const categories = /* @__PURE__ */ new Map();
|
|
533
|
+
Object.values(EFFECTS_REGISTRY).forEach((effect) => {
|
|
534
|
+
const cat = effect.category;
|
|
535
|
+
if (!categories.has(cat)) {
|
|
536
|
+
categories.set(cat, {
|
|
537
|
+
count: 0,
|
|
538
|
+
description: getCategoryDescription(cat)
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
categories.get(cat).count++;
|
|
542
|
+
});
|
|
543
|
+
return Array.from(categories.entries()).map(([id, data]) => ({
|
|
544
|
+
id,
|
|
545
|
+
name: capitalizeCategory(id),
|
|
546
|
+
count: data.count,
|
|
547
|
+
description: data.description
|
|
548
|
+
}));
|
|
549
|
+
}
|
|
550
|
+
function getCategoryDescription(category) {
|
|
551
|
+
const descriptions = {
|
|
552
|
+
essentials: "Essential visual enhancements",
|
|
553
|
+
glitch: "Digital glitches and VHS noise",
|
|
554
|
+
retro: "Vintage film and nostalgic looks",
|
|
555
|
+
light: "Lighting flares, glow, and leaks",
|
|
556
|
+
motion: "Blur, camera movement, and speed",
|
|
557
|
+
color: "Color corrections and grading",
|
|
558
|
+
body: "Body tracking and segmentation effects"
|
|
559
|
+
};
|
|
560
|
+
return descriptions[category] || "";
|
|
561
|
+
}
|
|
562
|
+
function capitalizeCategory(category) {
|
|
563
|
+
return category.charAt(0).toUpperCase() + category.slice(1);
|
|
564
|
+
}
|
|
565
|
+
function generateEffectsManifest() {
|
|
566
|
+
return {
|
|
567
|
+
version: "1.0.0",
|
|
568
|
+
totalCount: Object.keys(EFFECTS_REGISTRY).length,
|
|
569
|
+
categories: getEffectCategoriesSummary(),
|
|
570
|
+
effects: getAllEffectsForApi()
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
export {
|
|
575
|
+
EFFECTS_REGISTRY,
|
|
576
|
+
getEffectMetadata,
|
|
577
|
+
getEffectsByCategory,
|
|
578
|
+
getEffectRenderer,
|
|
579
|
+
searchEffects,
|
|
580
|
+
EffectRenderer,
|
|
581
|
+
EffectGraph,
|
|
582
|
+
EffectEngine,
|
|
583
|
+
hexToRgba,
|
|
584
|
+
rgbaToComponents,
|
|
585
|
+
blendColors,
|
|
586
|
+
addNoise,
|
|
587
|
+
clearCanvas,
|
|
588
|
+
withContext,
|
|
589
|
+
getEffectPreviewUrl,
|
|
590
|
+
effectMetadataToApi,
|
|
591
|
+
getAllEffectsForApi,
|
|
592
|
+
getEffectsByCategoryForApi,
|
|
593
|
+
searchEffectsForApi,
|
|
594
|
+
getEffectByIdForApi,
|
|
595
|
+
getEffectCategoriesSummary,
|
|
596
|
+
generateEffectsManifest
|
|
597
|
+
};
|
|
598
|
+
//# sourceMappingURL=chunk-XHHAW7MS.js.map
|