@clypra-studio/engine 1.2.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +13 -39
  2. package/dist/{chunk-LT3HTJ3X.js → chunk-3UEOLDJJ.js} +5 -829
  3. package/dist/chunk-3UEOLDJJ.js.map +1 -0
  4. package/dist/{chunk-Y4FMAOTW.js → chunk-E6O6LZME.js} +266 -1004
  5. package/dist/chunk-E6O6LZME.js.map +1 -0
  6. package/dist/chunk-PU3Q4QI7.js +833 -0
  7. package/dist/chunk-PU3Q4QI7.js.map +1 -0
  8. package/dist/{index-D6GAXDBy.d.cts → index-C18SQ-y6.d.cts} +171 -37
  9. package/dist/{index-D6GAXDBy.d.ts → index-C18SQ-y6.d.ts} +171 -37
  10. package/dist/index.cjs +12064 -19908
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +3302 -7641
  13. package/dist/index.d.ts +3302 -7641
  14. package/dist/index.js +11201 -14606
  15. package/dist/index.js.map +1 -1
  16. package/dist/textEffects/index.cjs +259 -971
  17. package/dist/textEffects/index.cjs.map +1 -1
  18. package/dist/textEffects/index.d.cts +1 -1
  19. package/dist/textEffects/index.d.ts +1 -1
  20. package/dist/textEffects/index.js +1 -1
  21. package/dist/transitions/index.cjs +18 -2199
  22. package/dist/transitions/index.cjs.map +1 -1
  23. package/dist/transitions/index.d.cts +37 -53
  24. package/dist/transitions/index.d.ts +37 -53
  25. package/dist/transitions/index.js +3 -51
  26. package/dist/videoEffects/index.cjs +4 -835
  27. package/dist/videoEffects/index.cjs.map +1 -1
  28. package/dist/videoEffects/index.d.cts +9 -138
  29. package/dist/videoEffects/index.d.ts +9 -138
  30. package/dist/videoEffects/index.js +1 -15
  31. package/package.json +14 -17
  32. package/dist/TransitionDefinition-CQoSb4ZB.d.cts +0 -158
  33. package/dist/TransitionDefinition-CQoSb4ZB.d.ts +0 -158
  34. package/dist/chunk-FIJBB3MH.js +0 -2990
  35. package/dist/chunk-FIJBB3MH.js.map +0 -1
  36. package/dist/chunk-LT3HTJ3X.js.map +0 -1
  37. package/dist/chunk-RYA4KGDB.js +0 -690
  38. package/dist/chunk-RYA4KGDB.js.map +0 -1
  39. package/dist/chunk-Y4FMAOTW.js.map +0 -1
  40. package/dist/index-Da47I6aX.d.cts +0 -139
  41. package/dist/index-Da47I6aX.d.ts +0 -139
  42. package/dist/v2/backends/index.cjs +0 -693
  43. package/dist/v2/backends/index.cjs.map +0 -1
  44. package/dist/v2/backends/index.d.cts +0 -3
  45. package/dist/v2/backends/index.d.ts +0 -3
  46. package/dist/v2/backends/index.js +0 -8
  47. package/dist/v2/backends/index.js.map +0 -1
@@ -553,7 +553,7 @@ var EFFECTS_REGISTRY = {
553
553
  },
554
554
  tags: ["body", "segmentation", "glow"]
555
555
  },
556
- // PixiJS Video Filter Effects (Unified Registry Metadata)
556
+ // Native video filter effects (unified registry metadata)
557
557
  "light-leak": {
558
558
  id: "light-leak",
559
559
  name: "Light Leak",
@@ -1264,7 +1264,7 @@ function getEffectRenderer(id) {
1264
1264
  body_outline: renderBodyOutline,
1265
1265
  body_particles: renderBodyParticles,
1266
1266
  "body-segmentation-glow": renderBodySegmentationGlow,
1267
- // PixiJS variant fallbacks (supporting both kebab-case and underscore normalized variants)
1267
+ // Normalized aliases retained for existing saved projects.
1268
1268
  "light-leak": renderLightLeak,
1269
1269
  "lens-flare": renderLightLeak2,
1270
1270
  "lens_flare": renderLightLeak2,
@@ -1874,19 +1874,9 @@ var EffectGraph = class {
1874
1874
  const connected = this.connections.filter((conn) => conn.toNode === nodeId).map((conn) => conn.fromNode);
1875
1875
  return Array.from(/* @__PURE__ */ new Set([...deps, ...connected]));
1876
1876
  }
1877
- /**
1878
- * Returns only the PixiJS nodes in resolved order.
1879
- * Used by EffectRenderer to build the PixiJS filter + motion pipeline.
1880
- */
1881
- resolvePixi() {
1882
- return this.resolve().filter((n) => n.effect?.backend === "pixi");
1883
- }
1884
- /**
1885
- * Returns only the Canvas2D nodes in resolved order.
1886
- * Used by EffectRenderer for text effect overlays.
1887
- */
1877
+ /** Returns nodes that can execute in the browser-side authoring raster path. */
1888
1878
  resolveCanvas2D() {
1889
- return this.resolve().filter((n) => n.effect?.backend === "canvas2d");
1879
+ return this.resolve().filter((n) => n.effect?.backend !== "native");
1890
1880
  }
1891
1881
  get size() {
1892
1882
  return this.nodes.size;
@@ -2163,813 +2153,6 @@ function generateEffectsManifest() {
2163
2153
  };
2164
2154
  }
2165
2155
 
2166
- // src/videoEffects/EffectDefinition.ts
2167
- function isCanvas2DEffect(e) {
2168
- return e.backend === "canvas2d";
2169
- }
2170
- function isPixiEffect(e) {
2171
- return e.backend === "pixi";
2172
- }
2173
- function isFilterEffect(e) {
2174
- return isPixiEffect(e) && e.subtype === "filter";
2175
- }
2176
- function isMotionEffect(e) {
2177
- return isPixiEffect(e) && e.subtype === "motion";
2178
- }
2179
- function isCompositeEffect(e) {
2180
- return isPixiEffect(e) && e.subtype === "composite";
2181
- }
2182
-
2183
- // src/videoEffects/PixiRenderer.ts
2184
- import { Application, Container, Sprite, Texture, Filter, RenderTexture } from "pixi.js";
2185
- var PixiRenderer = class {
2186
- app = null;
2187
- videoSprite = null;
2188
- transitionSprite = null;
2189
- _activeTransition = null;
2190
- fromRenderTexture = null;
2191
- toRenderTexture = null;
2192
- blitSprite = null;
2193
- _transitionFromTex = null;
2194
- _transitionToTex = null;
2195
- overlayContainer = null;
2196
- baseMediaContainer = null;
2197
- mounted = /* @__PURE__ */ new Map();
2198
- initialized = false;
2199
- initializing = false;
2200
- _activeSource = null;
2201
- _fitMode = "fit";
2202
- /**
2203
- * Initialize the PixiJS Application.
2204
- * Call once, reuse across effect changes.
2205
- *
2206
- * @param canvas The target HTMLCanvasElement (Studio preview or rasterizer offscreen canvas)
2207
- * @param width Canvas width in pixels
2208
- * @param height Canvas height in pixels
2209
- */
2210
- async init(canvas, width, height) {
2211
- if (this.initialized || this.initializing) return;
2212
- this.initializing = true;
2213
- canvas.addEventListener("webglcontextlost", (event) => {
2214
- event.preventDefault();
2215
- console.warn("[PixiRenderer] WebGL context lost \u2014 attempting recovery");
2216
- });
2217
- canvas.addEventListener("webglcontextrestored", () => {
2218
- console.log("[PixiRenderer] WebGL context restored");
2219
- });
2220
- const app = new Application();
2221
- try {
2222
- await app.init({
2223
- canvas,
2224
- width,
2225
- height,
2226
- backgroundAlpha: 0,
2227
- // transparent — composited over video below
2228
- antialias: true,
2229
- preference: "webgl",
2230
- // WebGL for production stability; swap to 'webgpu' later
2231
- resolution: typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1,
2232
- autoDensity: true,
2233
- preserveDrawingBuffer: true,
2234
- // CRITICAL: disable the auto-render ticker.
2235
- // The compositor calls renderer.render() at the END of every composeFrame(),
2236
- // after all sprite states are finalized. If Pixi's own ticker fires between
2237
- // beginTextFrame() (which hides all sprites) and the awaited
2238
- // renderTextLayerBridged() / renderStickerLayerBridged() calls that re-show
2239
- // them, it renders a fully-invisible frame → visible blink of text and stickers.
2240
- autoStart: false
2241
- });
2242
- } catch (e) {
2243
- this.initializing = false;
2244
- throw e;
2245
- }
2246
- if (!this.initializing) {
2247
- app.destroy(true);
2248
- return;
2249
- }
2250
- this.app = app;
2251
- this.videoSprite = new Sprite();
2252
- this.videoSprite.width = width;
2253
- this.videoSprite.height = height;
2254
- this.transitionSprite = new Sprite();
2255
- this.transitionSprite.width = width;
2256
- this.transitionSprite.height = height;
2257
- this.transitionSprite.visible = false;
2258
- this.overlayContainer = new Container();
2259
- this.baseMediaContainer = new Container();
2260
- this.baseMediaContainer.sortableChildren = true;
2261
- this.app.stage.addChildAt(this.baseMediaContainer, 0);
2262
- this.app.stage.addChild(this.videoSprite);
2263
- this.app.stage.addChild(this.transitionSprite);
2264
- this.app.stage.addChild(this.overlayContainer);
2265
- this.initialized = true;
2266
- this.initializing = false;
2267
- }
2268
- setVideoSource(video) {
2269
- if (this._activeSource === video) {
2270
- this.resizeSprites();
2271
- return;
2272
- }
2273
- this._activeSource = video;
2274
- if (!this.videoSprite || !this.app) return;
2275
- const texture = Texture.from(video);
2276
- this.videoSprite.texture = texture;
2277
- this.resizeSprites();
2278
- }
2279
- setImageSource(image) {
2280
- if (this._activeSource === image) {
2281
- this.resizeSprites();
2282
- return;
2283
- }
2284
- this._activeSource = image;
2285
- if (!this.videoSprite || !this.app) return;
2286
- const texture = Texture.from(image);
2287
- this.videoSprite.texture = texture;
2288
- this.resizeSprites();
2289
- }
2290
- // -------------------------------------------------------------------------
2291
- // Effect lifecycle
2292
- // -------------------------------------------------------------------------
2293
- /**
2294
- * Mount a resolved set of PixiJS graph nodes.
2295
- * Builds filter chains and initialises motion effects.
2296
- * Previously mounted effects NOT in the new list are unmounted.
2297
- */
2298
- applyNodes(nodes, globalParams) {
2299
- if (!this.app || !this.videoSprite || !this.overlayContainer) {
2300
- throw new Error("[PixiRenderer] call init() before applyNodes()");
2301
- }
2302
- const incomingIds = new Set(nodes.map((n) => n.id));
2303
- for (const [id, mounted] of this.mounted) {
2304
- if (!incomingIds.has(id)) {
2305
- this._unmount(mounted);
2306
- this.mounted.delete(id);
2307
- }
2308
- }
2309
- const filterChain = [];
2310
- for (const node of nodes) {
2311
- const def = node.effect;
2312
- if (!isPixiEffect(def)) continue;
2313
- const params = globalParams?.get(node.id) ?? this._defaultParams(def);
2314
- if (this.mounted.has(node.id)) {
2315
- const m = this.mounted.get(node.id);
2316
- Object.assign(m.params, params);
2317
- Object.assign(m.ctx.params, params);
2318
- if (m.filters && m.definition.filterSpec?.updateUniforms) {
2319
- m.definition.filterSpec.updateUniforms(m.filters.length === 1 ? m.filters[0] : m.filters, m.params, 0);
2320
- }
2321
- if (m.filters) filterChain.push(...m.filters);
2322
- continue;
2323
- }
2324
- const ctx = {
2325
- app: this.app,
2326
- container: this.overlayContainer,
2327
- ticker: this.app.ticker,
2328
- params,
2329
- width: this.app.screen.width,
2330
- height: this.app.screen.height
2331
- };
2332
- let filters = null;
2333
- let tickerFn = void 0;
2334
- if ((isFilterEffect(def) || isCompositeEffect(def)) && def.filterSpec) {
2335
- const result = def.filterSpec.create(params);
2336
- filters = Array.isArray(result) ? result : [result];
2337
- filterChain.push(...filters);
2338
- if (def.filterSpec.updateUniforms) {
2339
- const spec = def.filterSpec;
2340
- const elapsed = { value: 0 };
2341
- tickerFn = (ticker) => {
2342
- elapsed.value += ticker.deltaMS;
2343
- if (filters) {
2344
- spec.updateUniforms(filters.length === 1 ? filters[0] : filters, params, elapsed.value);
2345
- }
2346
- };
2347
- this.app.ticker.add(tickerFn);
2348
- }
2349
- }
2350
- if ((isMotionEffect(def) || isCompositeEffect(def)) && def.mount) {
2351
- def.mount(ctx);
2352
- }
2353
- this.mounted.set(node.id, { node, definition: def, params, filters, ctx, tickerFn });
2354
- }
2355
- this.videoSprite.filters = filterChain.length > 0 ? filterChain : null;
2356
- }
2357
- /**
2358
- * Update multiple params on a mounted effect in one pass.
2359
- */
2360
- updateParams(nodeId, params) {
2361
- const m = this.mounted.get(nodeId);
2362
- if (!m) return;
2363
- Object.assign(m.params, params);
2364
- Object.assign(m.ctx.params, params);
2365
- if (m.filters && m.definition.filterSpec?.updateUniforms) {
2366
- m.definition.filterSpec.updateUniforms(m.filters.length === 1 ? m.filters[0] : m.filters, m.params, 0);
2367
- }
2368
- }
2369
- /**
2370
- * Force a render pass (required for static image previews after uniform changes).
2371
- */
2372
- render() {
2373
- if (!this.app) return;
2374
- this.app.renderer.render({ container: this.app.stage });
2375
- }
2376
- /**
2377
- * Update a single param on a mounted effect.
2378
- * Triggers uniform refresh and calls onParamChange lifecycle hook.
2379
- */
2380
- updateParam(nodeId, key, value) {
2381
- const m = this.mounted.get(nodeId);
2382
- if (!m) return;
2383
- m.params[key] = value;
2384
- m.ctx.params[key] = value;
2385
- if (m.filters && m.definition.filterSpec?.updateUniforms) {
2386
- m.definition.filterSpec.updateUniforms(m.filters.length === 1 ? m.filters[0] : m.filters, m.params, 0);
2387
- }
2388
- m.definition.onParamChange?.(m.ctx, key, value);
2389
- }
2390
- /**
2391
- * Capture the current rendered frame as an ImageData.
2392
- * Used by the Desktop rasterizer to extract pixels for FFmpeg.
2393
- */
2394
- captureFrame() {
2395
- if (!this.app) return null;
2396
- const canvas = this.app.canvas;
2397
- const ctx = canvas.getContext("2d");
2398
- if (!ctx) return null;
2399
- return ctx.getImageData(0, 0, canvas.width, canvas.height);
2400
- }
2401
- /**
2402
- * Resize the renderer (e.g. when project resolution changes).
2403
- */
2404
- resize(width, height) {
2405
- if (!this.app) return;
2406
- this.app.renderer.resize(width, height);
2407
- this.resizeSprites();
2408
- }
2409
- setFitMode(mode) {
2410
- if (this._fitMode === mode) return;
2411
- this._fitMode = mode;
2412
- this.resizeSprites();
2413
- }
2414
- resizeSprites() {
2415
- if (this.videoSprite && this.videoSprite.texture) {
2416
- this._resizeSprite(this.videoSprite, this.videoSprite.texture, this._fitMode);
2417
- }
2418
- if (this.transitionSprite) {
2419
- if (this._activeTransition) {
2420
- this.transitionSprite.width = this.app?.screen.width ?? 1280;
2421
- this.transitionSprite.height = this.app?.screen.height ?? 720;
2422
- this.transitionSprite.position.set(0, 0);
2423
- } else if (this.transitionSprite.texture) {
2424
- this._resizeSprite(this.transitionSprite, this.transitionSprite.texture, this._fitMode);
2425
- }
2426
- }
2427
- }
2428
- _getElementDimensions(texture) {
2429
- const sourceEl = this._activeSource;
2430
- if (sourceEl) {
2431
- const tagName = sourceEl.tagName;
2432
- if ((tagName === "VIDEO" || sourceEl.videoWidth !== void 0) && sourceEl.videoWidth > 0) {
2433
- return { width: sourceEl.videoWidth, height: sourceEl.videoHeight };
2434
- }
2435
- if ((tagName === "IMG" || sourceEl.naturalWidth !== void 0) && sourceEl.naturalWidth > 0) {
2436
- return { width: sourceEl.naturalWidth, height: sourceEl.naturalHeight };
2437
- }
2438
- if ((tagName === "CANVAS" || sourceEl.getContext !== void 0) && sourceEl.width > 0) {
2439
- return { width: sourceEl.width, height: sourceEl.height };
2440
- }
2441
- }
2442
- const resource = texture.source?.resource || texture.source?.source;
2443
- if (resource) {
2444
- const tagName = resource.tagName;
2445
- if ((tagName === "VIDEO" || resource.videoWidth !== void 0) && resource.videoWidth > 0) {
2446
- return { width: resource.videoWidth, height: resource.videoHeight };
2447
- }
2448
- if ((tagName === "IMG" || resource.naturalWidth !== void 0) && resource.naturalWidth > 0) {
2449
- return { width: resource.naturalWidth, height: resource.naturalHeight };
2450
- }
2451
- if ((tagName === "CANVAS" || resource.getContext !== void 0) && resource.width > 0) {
2452
- return { width: resource.width, height: resource.height };
2453
- }
2454
- }
2455
- if (texture.width > 0) {
2456
- return { width: texture.width, height: texture.height };
2457
- }
2458
- return { width: 1280, height: 720 };
2459
- }
2460
- _resizeSprite(sprite, texture, fitMode) {
2461
- if (!this.app) return;
2462
- const canvasWidth = this.app.screen.width;
2463
- const canvasHeight = this.app.screen.height;
2464
- const { width: texWidth, height: texHeight } = this._getElementDimensions(texture);
2465
- if (fitMode === "stretch") {
2466
- sprite.width = canvasWidth;
2467
- sprite.height = canvasHeight;
2468
- sprite.position.set(0, 0);
2469
- } else {
2470
- const scaleX = canvasWidth / texWidth;
2471
- const scaleY = canvasHeight / texHeight;
2472
- const scale = fitMode === "fit" ? Math.min(scaleX, scaleY) : Math.max(scaleX, scaleY);
2473
- sprite.width = texWidth * scale;
2474
- sprite.height = texHeight * scale;
2475
- sprite.position.set((canvasWidth - sprite.width) / 2, (canvasHeight - sprite.height) / 2);
2476
- }
2477
- }
2478
- /**
2479
- * Full teardown — unmounts all effects, destroys the PixiJS Application.
2480
- * Call when the editor session ends or the Studio workspace unmounts.
2481
- */
2482
- destroy() {
2483
- this.initializing = false;
2484
- for (const mounted of this.mounted.values()) {
2485
- this._unmount(mounted);
2486
- }
2487
- this.mounted.clear();
2488
- if (this.app) {
2489
- try {
2490
- const gl = this.app.renderer.gl;
2491
- this.app.destroy(true, { children: true, texture: true });
2492
- gl?.getExtension("WEBGL_lose_context")?.loseContext();
2493
- } catch (e) {
2494
- console.warn("Error destroying Pixi application:", e);
2495
- }
2496
- this.app = null;
2497
- }
2498
- this.videoSprite = null;
2499
- this.transitionSprite = null;
2500
- this.overlayContainer = null;
2501
- this.baseMediaContainer = null;
2502
- this.initialized = false;
2503
- this._activeTransition = null;
2504
- this._activeSource = null;
2505
- if (this.fromRenderTexture) {
2506
- this.fromRenderTexture.destroy(true);
2507
- this.fromRenderTexture = null;
2508
- }
2509
- if (this.toRenderTexture) {
2510
- this.toRenderTexture.destroy(true);
2511
- this.toRenderTexture = null;
2512
- }
2513
- if (this.blitSprite) {
2514
- this.blitSprite.destroy();
2515
- this.blitSprite = null;
2516
- }
2517
- }
2518
- // -------------------------------------------------------------------------
2519
- // Private helpers
2520
- // -------------------------------------------------------------------------
2521
- _unmount(m) {
2522
- if ((isMotionEffect(m.definition) || isCompositeEffect(m.definition)) && m.definition.unmount) {
2523
- m.definition.unmount(m.ctx);
2524
- }
2525
- if (m.tickerFn && this.app) {
2526
- this.app.ticker.remove(m.tickerFn);
2527
- }
2528
- if (m.filters) {
2529
- for (const f of m.filters) f.destroy();
2530
- }
2531
- }
2532
- _defaultParams(def) {
2533
- return Object.fromEntries(def.params.map((p) => [p.key, p.value]));
2534
- }
2535
- getApp() {
2536
- return this.app;
2537
- }
2538
- getVideoSprite() {
2539
- return this.videoSprite;
2540
- }
2541
- getTransitionSprite() {
2542
- return this.transitionSprite;
2543
- }
2544
- getBaseMediaContainer() {
2545
- return this.baseMediaContainer;
2546
- }
2547
- getOverlayContainer() {
2548
- return this.overlayContainer;
2549
- }
2550
- get isReady() {
2551
- return this.initialized;
2552
- }
2553
- _ensureRenderTextures(width, height) {
2554
- if (!this.fromRenderTexture || this.fromRenderTexture.width !== width || this.fromRenderTexture.height !== height) {
2555
- if (this.fromRenderTexture) this.fromRenderTexture.destroy(true);
2556
- this.fromRenderTexture = RenderTexture.create({ width, height });
2557
- }
2558
- if (!this.toRenderTexture || this.toRenderTexture.width !== width || this.toRenderTexture.height !== height) {
2559
- if (this.toRenderTexture) this.toRenderTexture.destroy(true);
2560
- this.toRenderTexture = RenderTexture.create({ width, height });
2561
- }
2562
- if (!this.blitSprite) {
2563
- this.blitSprite = new Sprite();
2564
- }
2565
- }
2566
- _blitTransitionFrames() {
2567
- if (!this.app || !this._transitionFromTex || !this._transitionToTex || !this.fromRenderTexture || !this.toRenderTexture || !this.blitSprite) {
2568
- return;
2569
- }
2570
- const currentFitMode = this._fitMode;
2571
- this.blitSprite.texture = this._transitionFromTex;
2572
- this._resizeSprite(this.blitSprite, this._transitionFromTex, currentFitMode);
2573
- this.app.renderer.render({
2574
- container: this.blitSprite,
2575
- target: this.fromRenderTexture,
2576
- clear: true
2577
- });
2578
- this.blitSprite.texture = this._transitionToTex;
2579
- this._resizeSprite(this.blitSprite, this._transitionToTex, currentFitMode);
2580
- this.app.renderer.render({
2581
- container: this.blitSprite,
2582
- target: this.toRenderTexture,
2583
- clear: true
2584
- });
2585
- this.blitSprite.texture = Texture.EMPTY;
2586
- }
2587
- mountTransition(definition, fromTexture, toTexture, params) {
2588
- if (!this.transitionSprite || !this.videoSprite || !this.app) return;
2589
- this._activeSource = null;
2590
- if (this._activeTransition?.filter) {
2591
- this._activeTransition.filter.destroy();
2592
- }
2593
- this._transitionFromTex = fromTexture;
2594
- this._transitionToTex = toTexture;
2595
- const canvasWidth = this.app.screen.width;
2596
- const canvasHeight = this.app.screen.height;
2597
- this._ensureRenderTextures(canvasWidth, canvasHeight);
2598
- this._blitTransitionFrames();
2599
- const fromRT = this.fromRenderTexture;
2600
- const toRT = this.toRenderTexture;
2601
- const originalFilterFrom = Filter.from;
2602
- Filter.from = function(options) {
2603
- if (options && options.resources) {
2604
- if (!options.resources.uFrom) {
2605
- options.resources.uFrom = fromRT.source;
2606
- }
2607
- if (!options.resources.uTo) {
2608
- options.resources.uTo = toRT.source;
2609
- }
2610
- }
2611
- return originalFilterFrom.call(this, options);
2612
- };
2613
- let filter;
2614
- try {
2615
- filter = definition.create(params);
2616
- } finally {
2617
- Filter.from = originalFilterFrom;
2618
- }
2619
- filter.resources.uFrom = fromRT.source;
2620
- filter.resources.uTo = toRT.source;
2621
- this.transitionSprite.texture = fromRT;
2622
- this.transitionSprite.filters = [filter];
2623
- this.transitionSprite.visible = true;
2624
- this.videoSprite.visible = false;
2625
- if (this.baseMediaContainer) {
2626
- this.baseMediaContainer.visible = false;
2627
- }
2628
- this._activeTransition = { definition, filter, params };
2629
- this.resizeSprites();
2630
- }
2631
- getActiveTransitionId() {
2632
- return this._activeTransition?.definition.id || null;
2633
- }
2634
- updateTransitionProgress(id, progress, params) {
2635
- if (!this._activeTransition) return;
2636
- if (params) {
2637
- this._activeTransition.params = params;
2638
- }
2639
- this._blitTransitionFrames();
2640
- this._activeTransition.definition.updateProgress(this._activeTransition.filter, progress, this._activeTransition.params);
2641
- }
2642
- unmountTransition() {
2643
- if (this.transitionSprite) {
2644
- this.transitionSprite.visible = false;
2645
- this.transitionSprite.filters = null;
2646
- }
2647
- if (this.videoSprite) {
2648
- this.videoSprite.visible = true;
2649
- }
2650
- if (this.baseMediaContainer) {
2651
- this.baseMediaContainer.visible = true;
2652
- }
2653
- if (this._activeTransition?.filter) {
2654
- this._activeTransition.filter.destroy();
2655
- }
2656
- this._activeTransition = null;
2657
- this._transitionFromTex = null;
2658
- this._transitionToTex = null;
2659
- }
2660
- };
2661
-
2662
- // src/videoEffects/example.ts
2663
- var example_exports = {};
2664
- __export(example_exports, {
2665
- NeonGlowEffect: () => NeonGlowEffect,
2666
- ParticleBurstEffect: () => ParticleBurstEffect,
2667
- VHSCompositeEffect: () => VHSCompositeEffect
2668
- });
2669
- import { Filter as Filter2, Container as Container2, Graphics } from "pixi.js";
2670
- var hexToRgb = (hex) => {
2671
- const r = parseInt(hex.slice(1, 3), 16) / 255;
2672
- const g = parseInt(hex.slice(3, 5), 16) / 255;
2673
- const b = parseInt(hex.slice(5, 7), 16) / 255;
2674
- return [r, g, b];
2675
- };
2676
- var hexToDec = (hex) => parseInt(hex.replace("#", ""), 16);
2677
- var DEFAULT_VERTEX_SHADER = `
2678
- in vec2 aPosition;
2679
- out vec2 vTextureCoord;
2680
-
2681
- uniform vec4 uInputSize;
2682
- uniform vec4 uOutputFrame;
2683
-
2684
- vec4 filterVertexPosition(void) {
2685
- vec2 position = aPosition * uOutputFrame.zw + uOutputFrame.xy;
2686
- return vec4(position * uInputSize.zw * 2.0 - 1.0, 0.0, 1.0);
2687
- }
2688
-
2689
- vec2 filterTextureCoord(void) {
2690
- return aPosition * (uOutputFrame.zw * uInputSize.xy);
2691
- }
2692
-
2693
- void main(void) {
2694
- gl_Position = filterVertexPosition();
2695
- vTextureCoord = filterTextureCoord();
2696
- }
2697
- `;
2698
- var NeonGlowEffect = {
2699
- backend: "pixi",
2700
- subtype: "filter",
2701
- id: "neon-glow",
2702
- name: "Neon Glow",
2703
- category: "neon",
2704
- description: "GPU chromatic aberration with pulsing glow. Zero CPU cost per frame.",
2705
- tags: ["glow", "neon", "chromatic", "aberration", "rgb"],
2706
- thumbnail: "https://clypra-worker-api.abdulkabirmusa.com/thumbnails/neon-glow.webp",
2707
- params: [
2708
- { key: "spread", label: "Spread", type: "range", value: 4, min: 0, max: 20, step: 0.5 },
2709
- { key: "strength", label: "Glow strength", type: "range", value: 0.6, min: 0, max: 1, step: 0.01 },
2710
- { key: "color", label: "Glow color", type: "color", value: "#7C6FFF" },
2711
- { key: "pulse", label: "Pulse", type: "toggle", value: true },
2712
- { key: "pulseSpeed", label: "Pulse speed", type: "range", value: 1.5, min: 0.1, max: 5, step: 0.1 }
2713
- ],
2714
- filterSpec: {
2715
- create(params) {
2716
- const fragment = `
2717
- in vec2 vTextureCoord;
2718
- out vec4 finalColor;
2719
-
2720
- uniform sampler2D uTexture;
2721
- uniform float uSpread;
2722
- uniform float uStrength;
2723
- uniform vec3 uGlowColor;
2724
- uniform float uTime;
2725
- uniform bool uPulse;
2726
- uniform float uPulseSpeed;
2727
-
2728
- void main(void) {
2729
- vec2 uv = vTextureCoord;
2730
-
2731
- // Chromatic aberration \u2014 shift R and B channels outward from center
2732
- vec2 dir = uv - 0.5;
2733
- float dist = length(dir) * uSpread * 0.01;
2734
- vec2 redUV = uv + dir * dist;
2735
- vec2 blueUV = uv - dir * dist;
2736
-
2737
- float r = texture(uTexture, redUV).r;
2738
- float g = texture(uTexture, uv).g;
2739
- float b = texture(uTexture, blueUV).b;
2740
- float a = texture(uTexture, uv).a;
2741
-
2742
- vec4 base = vec4(r, g, b, a);
2743
-
2744
- // Soft glow overlay \u2014 animated pulse
2745
- float pulse = uPulse
2746
- ? 0.5 + 0.5 * sin(uTime * uPulseSpeed * 6.28318)
2747
- : 1.0;
2748
- float glow = uStrength * pulse;
2749
-
2750
- // Additive blend of glow color onto base
2751
- vec3 glowContrib = uGlowColor * glow * base.a;
2752
- finalColor = vec4(base.rgb + glowContrib, base.a);
2753
- }
2754
- `;
2755
- const rgb = hexToRgb(params.color);
2756
- return Filter2.from({
2757
- gl: { vertex: DEFAULT_VERTEX_SHADER, fragment },
2758
- resources: {
2759
- uniforms: {
2760
- uSpread: { value: params.spread, type: "f32" },
2761
- uStrength: { value: params.strength, type: "f32" },
2762
- uGlowColor: { value: rgb, type: "vec3<f32>" },
2763
- uTime: { value: 0, type: "f32" },
2764
- uPulse: { value: params.pulse, type: "bool" },
2765
- uPulseSpeed: { value: params.pulseSpeed, type: "f32" }
2766
- }
2767
- }
2768
- });
2769
- },
2770
- updateUniforms(filter, params, elapsed) {
2771
- const uniforms = filter.resources?.uniforms?.uniforms;
2772
- if (!uniforms) return;
2773
- uniforms.uTime = elapsed / 1e3;
2774
- uniforms.uSpread = params.spread;
2775
- uniforms.uStrength = params.strength;
2776
- uniforms.uPulse = params.pulse;
2777
- uniforms.uPulseSpeed = params.pulseSpeed;
2778
- const hex = params.color;
2779
- uniforms.uGlowColor = hexToRgb(hex);
2780
- }
2781
- }
2782
- };
2783
- var ParticleBurstEffect = {
2784
- backend: "pixi",
2785
- subtype: "motion",
2786
- id: "particle-burst",
2787
- name: "Particle Burst",
2788
- category: "particle",
2789
- description: "Ticker-driven particle system. Emits from center, fades out on edges.",
2790
- tags: ["particle", "burst", "motion", "overlay"],
2791
- thumbnail: "https://clypra-worker-api.abdulkabirmusa.com/thumbnails/particle-burst.webp",
2792
- params: [
2793
- { key: "count", label: "Particle count", type: "range", value: 80, min: 10, max: 300, step: 10 },
2794
- { key: "speed", label: "Speed", type: "range", value: 2, min: 0.5, max: 8, step: 0.5 },
2795
- { key: "size", label: "Size", type: "range", value: 4, min: 1, max: 12, step: 1 },
2796
- { key: "color", label: "Particle color", type: "color", value: "#7C6FFF" },
2797
- { key: "fade", label: "Fade out", type: "toggle", value: true }
2798
- ],
2799
- mount(ctx) {
2800
- ctx._particleContainer = new Container2();
2801
- ctx.container.addChild(ctx._particleContainer);
2802
- const particles = [];
2803
- ctx._particles = particles;
2804
- const emit = () => {
2805
- const count = ctx.params.count;
2806
- while (particles.length < count) {
2807
- const angle = Math.random() * Math.PI * 2;
2808
- const speed = ctx.params.speed * (0.5 + Math.random());
2809
- const gfx = new Graphics();
2810
- gfx.circle(0, 0, ctx.params.size);
2811
- gfx.fill({ color: hexToDec(ctx.params.color), alpha: 0.9 });
2812
- gfx.x = ctx.width / 2 + (Math.random() - 0.5) * ctx.width * 0.3;
2813
- gfx.y = ctx.height / 2 + (Math.random() - 0.5) * ctx.height * 0.3;
2814
- ctx._particleContainer.addChild(gfx);
2815
- const maxLife = 60 + Math.random() * 60;
2816
- particles.push({ gfx, vx: Math.cos(angle) * speed, vy: Math.sin(angle) * speed, life: maxLife, maxLife });
2817
- }
2818
- };
2819
- ctx._tickerFn = (ticker) => {
2820
- emit();
2821
- for (let i = particles.length - 1; i >= 0; i--) {
2822
- const p = particles[i];
2823
- p.gfx.x += p.vx;
2824
- p.gfx.y += p.vy;
2825
- p.life -= ticker.deltaTime;
2826
- if (ctx.params.fade) {
2827
- p.gfx.alpha = Math.max(0, p.life / p.maxLife);
2828
- }
2829
- if (p.life <= 0 || p.gfx.x < -20 || p.gfx.x > ctx.width + 20 || p.gfx.y < -20 || p.gfx.y > ctx.height + 20) {
2830
- p.life = p.maxLife;
2831
- p.gfx.x = ctx.width / 2 + (Math.random() - 0.5) * ctx.width * 0.3;
2832
- p.gfx.y = ctx.height / 2 + (Math.random() - 0.5) * ctx.height * 0.3;
2833
- p.gfx.alpha = 1;
2834
- }
2835
- }
2836
- };
2837
- ctx.ticker.add(ctx._tickerFn);
2838
- },
2839
- unmount(ctx) {
2840
- if (ctx._tickerFn) {
2841
- ctx.ticker.remove(ctx._tickerFn);
2842
- }
2843
- if (ctx._particleContainer) {
2844
- ctx.container.removeChild(ctx._particleContainer);
2845
- ctx._particleContainer.destroy({ children: true });
2846
- }
2847
- },
2848
- onParamChange(ctx, key, value) {
2849
- if (key === "color") {
2850
- for (const p of ctx._particles ?? []) {
2851
- p.gfx.clear();
2852
- p.gfx.circle(0, 0, ctx.params.size);
2853
- p.gfx.fill({ color: hexToDec(value), alpha: 0.9 });
2854
- }
2855
- }
2856
- }
2857
- };
2858
- var VHSCompositeEffect = {
2859
- backend: "pixi",
2860
- subtype: "composite",
2861
- id: "vhs-composite",
2862
- name: "VHS",
2863
- category: "retro",
2864
- description: "Classic VHS look: scanlines + noise shader with animated glitch band overlay.",
2865
- tags: ["vhs", "retro", "glitch", "scanlines", "noise", "composite"],
2866
- thumbnail: "https://clypra-worker-api.abdulkabirmusa.com/thumbnails/vhs-composite.webp",
2867
- params: [
2868
- { key: "noise", label: "Noise", type: "range", value: 0.08, min: 0, max: 0.3, step: 0.01 },
2869
- { key: "scanlines", label: "Scanlines", type: "toggle", value: true },
2870
- { key: "lineAlpha", label: "Line alpha", type: "range", value: 0.25, min: 0, max: 1, step: 0.05 },
2871
- { key: "hShift", label: "H-shift", type: "range", value: 3e-3, min: 0, max: 0.02, step: 1e-3 },
2872
- { key: "bandSpeed", label: "Band speed", type: "range", value: 1.2, min: 0.1, max: 5, step: 0.1 },
2873
- { key: "bandAlpha", label: "Band alpha", type: "range", value: 0.35, min: 0, max: 1, step: 0.05 }
2874
- ],
2875
- // ── Filter part ──────────────────────────────────────────────────────────
2876
- filterSpec: {
2877
- create(params) {
2878
- const fragment = `
2879
- in vec2 vTextureCoord;
2880
- out vec4 finalColor;
2881
-
2882
- uniform sampler2D uTexture;
2883
- uniform float uNoise;
2884
- uniform bool uScanlines;
2885
- uniform float uLineAlpha;
2886
- uniform float uHShift;
2887
- uniform float uTime;
2888
-
2889
- float rand(vec2 co) {
2890
- return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453);
2891
- }
2892
-
2893
- void main(void) {
2894
- vec2 uv = vTextureCoord;
2895
-
2896
- // Horizontal shift on random bands
2897
- float bandY = floor(uv.y * 240.0) / 240.0;
2898
- float shift = (rand(vec2(bandY, floor(uTime * 15.0))) - 0.5) * uHShift;
2899
- uv.x += shift;
2900
-
2901
- vec4 color = texture(uTexture, clamp(uv, 0.0, 1.0));
2902
-
2903
- // Noise grain
2904
- float grain = rand(uv + uTime) * uNoise;
2905
- color.rgb += grain;
2906
-
2907
- // Scanlines
2908
- if (uScanlines) {
2909
- float line = step(0.5, fract(vTextureCoord.y * 240.0));
2910
- color.rgb = mix(color.rgb, color.rgb * 0.7, line * uLineAlpha);
2911
- }
2912
-
2913
- // Slight desaturation for the washed-out VHS look
2914
- float luma = dot(color.rgb, vec3(0.299, 0.587, 0.114));
2915
- color.rgb = mix(vec3(luma), color.rgb, 0.75);
2916
-
2917
- finalColor = color;
2918
- }
2919
- `;
2920
- return Filter2.from({
2921
- gl: { vertex: DEFAULT_VERTEX_SHADER, fragment },
2922
- resources: {
2923
- uniforms: {
2924
- uNoise: { value: params.noise, type: "f32" },
2925
- uScanlines: { value: params.scanlines, type: "bool" },
2926
- uLineAlpha: { value: params.lineAlpha, type: "f32" },
2927
- uHShift: { value: params.hShift, type: "f32" },
2928
- uTime: { value: 0, type: "f32" }
2929
- }
2930
- }
2931
- });
2932
- },
2933
- updateUniforms(filter, params, elapsed) {
2934
- const uniforms = filter.resources?.uniforms?.uniforms;
2935
- if (!uniforms) return;
2936
- uniforms.uTime = elapsed / 1e3;
2937
- uniforms.uNoise = params.noise;
2938
- uniforms.uScanlines = params.scanlines;
2939
- uniforms.uLineAlpha = params.lineAlpha;
2940
- uniforms.uHShift = params.hShift;
2941
- }
2942
- },
2943
- // ── Motion part (animated glitch band) ───────────────────────────────────
2944
- mount(ctx) {
2945
- const band = new Graphics();
2946
- ctx._vhsBand = band;
2947
- ctx._bandY = Math.random() * ctx.height;
2948
- const draw = () => {
2949
- band.clear();
2950
- band.rect(0, ctx._bandY, ctx.width, 8);
2951
- band.fill({ color: 16777215, alpha: ctx.params.bandAlpha });
2952
- };
2953
- draw();
2954
- ctx.container.addChild(band);
2955
- ctx._tickerFn = (ticker) => {
2956
- ctx._bandY += ctx.params.bandSpeed * ticker.deltaTime;
2957
- if (ctx._bandY > ctx.height + 20) ctx._bandY = -20;
2958
- draw();
2959
- };
2960
- ctx.ticker.add(ctx._tickerFn);
2961
- },
2962
- unmount(ctx) {
2963
- if (ctx._tickerFn) ctx.ticker.remove(ctx._tickerFn);
2964
- if (ctx._vhsBand) {
2965
- ctx.container.removeChild(ctx._vhsBand);
2966
- ctx._vhsBand.destroy();
2967
- }
2968
- },
2969
- onParamChange(ctx, key) {
2970
- }
2971
- };
2972
-
2973
2156
  // src/videoEffects/renderers/camera/index.ts
2974
2157
  var camera_exports = {};
2975
2158
  __export(camera_exports, {
@@ -3047,13 +2230,6 @@ export {
3047
2230
  getEffectByIdForApi,
3048
2231
  getEffectCategoriesSummary,
3049
2232
  generateEffectsManifest,
3050
- isCanvas2DEffect,
3051
- isPixiEffect,
3052
- isFilterEffect,
3053
- isMotionEffect,
3054
- isCompositeEffect,
3055
- PixiRenderer,
3056
- example_exports,
3057
2233
  camera_exports
3058
2234
  };
3059
- //# sourceMappingURL=chunk-LT3HTJ3X.js.map
2235
+ //# sourceMappingURL=chunk-3UEOLDJJ.js.map