@pixerate/editor 0.124.1 → 0.126.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 (97) hide show
  1. package/dist/agent/index.cjs +3 -3
  2. package/dist/agent/index.cjs.map +1 -1
  3. package/dist/agent/index.js +3 -3
  4. package/dist/animation-editor/index.cjs +422 -85
  5. package/dist/animation-editor/index.cjs.map +1 -1
  6. package/dist/animation-editor/index.d.cts +174 -7
  7. package/dist/animation-editor/index.d.ts +174 -7
  8. package/dist/animation-editor/index.js +346 -9
  9. package/dist/animation-editor/index.js.map +1 -1
  10. package/dist/{chunk-ORHMVUR6.js → chunk-FICSDDDF.js} +5 -3
  11. package/dist/{chunk-ORHMVUR6.js.map → chunk-FICSDDDF.js.map} +1 -1
  12. package/dist/chunk-FJ3324TZ.js +59 -0
  13. package/dist/chunk-FJ3324TZ.js.map +1 -0
  14. package/dist/{chunk-5EO2IXQE.js → chunk-FPRIUR4T.js} +1 -1
  15. package/dist/chunk-FPRIUR4T.js.map +1 -0
  16. package/dist/{chunk-FHYDQOPC.cjs → chunk-JODTP4DP.cjs} +178 -7
  17. package/dist/chunk-JODTP4DP.cjs.map +1 -0
  18. package/dist/{chunk-NGYD3AMN.js → chunk-MPQAO33O.js} +2 -2
  19. package/dist/{chunk-PEHYWUVV.cjs → chunk-O5RVCDEC.cjs} +82 -82
  20. package/dist/{chunk-PEHYWUVV.cjs.map → chunk-O5RVCDEC.cjs.map} +1 -1
  21. package/dist/{chunk-JRXJTPES.js → chunk-QFSTQHZY.js} +176 -5
  22. package/dist/chunk-QFSTQHZY.js.map +1 -0
  23. package/dist/{chunk-5XXMLBH4.cjs → chunk-QQKTOA4U.cjs} +1 -1
  24. package/dist/chunk-QQKTOA4U.cjs.map +1 -0
  25. package/dist/{chunk-4QQZV5Y5.cjs → chunk-SFCPGMCT.cjs} +11 -9
  26. package/dist/chunk-SFCPGMCT.cjs.map +1 -0
  27. package/dist/{chunk-WE25VLCO.cjs → chunk-V5YGPRCZ.cjs} +36 -36
  28. package/dist/{chunk-WE25VLCO.cjs.map → chunk-V5YGPRCZ.cjs.map} +1 -1
  29. package/dist/chunk-W6QTLHZ3.cjs +59 -0
  30. package/dist/chunk-W6QTLHZ3.cjs.map +1 -0
  31. package/dist/{chunk-WATAQ2Z2.js → chunk-WUDPFWAN.js} +2 -2
  32. package/dist/effects/index.cjs +59 -33
  33. package/dist/effects/index.cjs.map +1 -1
  34. package/dist/effects/index.d.cts +4 -5
  35. package/dist/effects/index.d.ts +4 -5
  36. package/dist/effects/index.js +33 -7
  37. package/dist/effects/index.js.map +1 -1
  38. package/dist/{export-WmYoWmLM.d.cts → export-Bp7ji2r4.d.cts} +1 -2
  39. package/dist/{export-BdfY_lH0.d.ts → export-C1s4eolZ.d.ts} +1 -1
  40. package/dist/{export-BGtXgMJ3.d.ts → export-DAyPY94f.d.ts} +1 -2
  41. package/dist/{export-CbpjwxaI.d.cts → export-DVl4fWy5.d.cts} +1 -1
  42. package/dist/generation/index.cjs +3 -3
  43. package/dist/generation/index.cjs.map +1 -1
  44. package/dist/generation/index.js +3 -3
  45. package/dist/helpers-BBLlekuM.d.ts +2009 -0
  46. package/dist/helpers-i95Ob6Vi.d.cts +2009 -0
  47. package/dist/image-editor/index.cjs +627 -627
  48. package/dist/image-editor/index.cjs.map +1 -1
  49. package/dist/image-editor/index.d.cts +5 -7
  50. package/dist/image-editor/index.d.ts +5 -7
  51. package/dist/image-editor/index.js +13 -13
  52. package/dist/paint-editor/index.cjs +736 -115
  53. package/dist/paint-editor/index.cjs.map +1 -1
  54. package/dist/paint-editor/index.d.cts +248 -13
  55. package/dist/paint-editor/index.d.ts +248 -13
  56. package/dist/paint-editor/index.js +634 -13
  57. package/dist/paint-editor/index.js.map +1 -1
  58. package/dist/{svg-BDrjRnL1.d.cts → svg-BkRL-fZJ.d.cts} +1 -1
  59. package/dist/{svg-C-vZ3q50.d.ts → svg-DJKriJ4A.d.ts} +1 -1
  60. package/dist/tools/index.cjs +2 -2
  61. package/dist/tools/index.cjs.map +1 -1
  62. package/dist/tools/index.js +3 -3
  63. package/dist/{tools-C7JtLYzo.d.ts → tools-CM8Oe8F3.d.ts} +1 -1
  64. package/dist/{tools-DHKGHiSK.d.cts → tools-DZCv2kX1.d.cts} +1 -1
  65. package/dist/vector/index.cjs +1030 -883
  66. package/dist/vector/index.cjs.map +1 -1
  67. package/dist/vector/index.d.cts +61 -6
  68. package/dist/vector/index.d.ts +61 -6
  69. package/dist/vector/index.js +153 -6
  70. package/dist/vector/index.js.map +1 -1
  71. package/dist/video-editor/index.cjs +272 -273
  72. package/dist/video-editor/index.cjs.map +1 -1
  73. package/dist/video-editor/index.d.cts +4 -6
  74. package/dist/video-editor/index.d.ts +4 -6
  75. package/dist/video-editor/index.js +6 -7
  76. package/dist/video-editor/index.js.map +1 -1
  77. package/package.json +1 -1
  78. package/skills/pixerate-animation-editor/SKILL.md +24 -1
  79. package/skills/pixerate-paint-editor/SKILL.md +40 -1
  80. package/skills/pixerate-vector/SKILL.md +15 -0
  81. package/dist/chunk-4QQZV5Y5.cjs.map +0 -1
  82. package/dist/chunk-5EO2IXQE.js.map +0 -1
  83. package/dist/chunk-5XXMLBH4.cjs.map +0 -1
  84. package/dist/chunk-CN4PJHUG.cjs +0 -234
  85. package/dist/chunk-CN4PJHUG.cjs.map +0 -1
  86. package/dist/chunk-FHYDQOPC.cjs.map +0 -1
  87. package/dist/chunk-JRXJTPES.js.map +0 -1
  88. package/dist/chunk-QEG3GRN2.js +0 -234
  89. package/dist/chunk-QEG3GRN2.js.map +0 -1
  90. package/dist/flair-CxB3fOcU.d.ts +0 -739
  91. package/dist/flair-D7BxyBwL.d.cts +0 -739
  92. package/dist/helpers-777mC6dc.d.cts +0 -253
  93. package/dist/helpers-DX2_7L5t.d.ts +0 -253
  94. package/dist/types-BcX7sCsn.d.ts +0 -993
  95. package/dist/types-CznabG7m.d.cts +0 -993
  96. /package/dist/{chunk-NGYD3AMN.js.map → chunk-MPQAO33O.js.map} +0 -0
  97. /package/dist/{chunk-WATAQ2Z2.js.map → chunk-WUDPFWAN.js.map} +0 -0
@@ -1,234 +0,0 @@
1
- import {
2
- validateJsonSchema
3
- } from "./chunk-4FX5ACVG.js";
4
-
5
- // src/effects/errors.ts
6
- var EFFECT_ERROR_CODES = ["unknown_effect", "invalid_values", "unsupported", "disposed", "no_provider"];
7
- var EffectError = class extends Error {
8
- code;
9
- effectId;
10
- constructor(code, message, effectId) {
11
- super(message);
12
- this.name = "EffectError";
13
- this.code = code;
14
- this.effectId = effectId;
15
- }
16
- };
17
- var UnknownEffectError = class extends EffectError {
18
- constructor(effectId, providerName) {
19
- super(
20
- "unknown_effect",
21
- `Unknown effect "${effectId}"${providerName ? ` in ${providerName}` : ""}. Call search_effects or list() for valid ids.`,
22
- effectId
23
- );
24
- this.name = "UnknownEffectError";
25
- }
26
- };
27
- var EffectControlError = class extends EffectError {
28
- details;
29
- constructor(effectId, details) {
30
- const lines = details.map((d) => `- ${d.path || "/"}: ${d.message}`).join("\n");
31
- super("invalid_values", `Invalid values for effect "${effectId}":
32
- ${lines}`, effectId);
33
- this.name = "EffectControlError";
34
- this.details = details;
35
- }
36
- };
37
- var EffectUnsupportedError = class extends EffectError {
38
- constructor(message, effectId) {
39
- super("unsupported", message, effectId);
40
- this.name = "EffectUnsupportedError";
41
- }
42
- };
43
- var EffectDisposedError = class extends EffectError {
44
- constructor(effectId) {
45
- super("disposed", `The renderer for "${effectId}" was disposed. Create a new renderer.`, effectId);
46
- this.name = "EffectDisposedError";
47
- }
48
- };
49
- var NoEffectsProviderError = class extends EffectError {
50
- constructor() {
51
- super("no_provider", "No effects provider is registered with this editor. The host must call setEffectsProvider(provider) first.");
52
- this.name = "NoEffectsProviderError";
53
- }
54
- };
55
- function isEffectError(error) {
56
- if (error instanceof EffectError) return true;
57
- const code = error instanceof Error ? error.code : void 0;
58
- return typeof code === "string" && EFFECT_ERROR_CODES.includes(code);
59
- }
60
-
61
- // src/effects/helpers.ts
62
- function effectValueErrors(description, values) {
63
- if (values === void 0) return [];
64
- return validateJsonSchema(values, { ...description.controls, required: [] });
65
- }
66
- function resolveEffectValues(description, values) {
67
- const errors = effectValueErrors(description, values);
68
- if (errors.length) throw new EffectControlError(description.id, errors);
69
- return { ...description.defaults, ...values ?? {} };
70
- }
71
- var matchesFilters = (e, o) => (!o.kind || e.kind === o.kind) && (!o.category || e.category === o.category) && (!o.use || e.uses.includes(o.use));
72
- function searchEffectSummaries(catalog, query = "", options = {}) {
73
- const words = query.toLowerCase().split(/\s+/).filter(Boolean);
74
- const scored = [];
75
- catalog.forEach((e, i) => {
76
- if (!matchesFilters(e, options)) return;
77
- const name = e.name.toLowerCase();
78
- const hay = [e.id, e.name, e.category, ...e.tags ?? [], e.description ?? ""].join(" ").toLowerCase();
79
- let score = 0;
80
- for (const w of words) {
81
- if (!hay.includes(w)) return;
82
- score += name.startsWith(w) ? 3 : name.includes(w) ? 2 : 1;
83
- }
84
- scored.push({ e, score, i });
85
- });
86
- scored.sort((a, b) => b.score - a.score || a.i - b.i);
87
- const out = scored.map((s) => s.e);
88
- return options.limit !== void 0 ? out.slice(0, Math.max(0, options.limit)) : out;
89
- }
90
- function createEffectPixels(width, height, float = false) {
91
- const n = Math.max(0, width * height * 4);
92
- return { width, height, data: new Uint8ClampedArray(n), ...float ? { float: new Float32Array(n) } : {} };
93
- }
94
- function isEffectPixels(source) {
95
- return !!source && typeof source === "object" && source.data instanceof Uint8ClampedArray && typeof source.width === "number" && typeof source.height === "number";
96
- }
97
- var srgbToLinear = (v) => v <= 0.04045 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
98
- var linearToSrgb = (v) => v > 0 ? v <= 31308e-7 ? v * 12.92 : 1.055 * Math.pow(v, 1 / 2.4) - 0.055 : 0;
99
- function encodeEffectFloat(pixels) {
100
- const f = pixels.float;
101
- if (!f) return pixels;
102
- const d = pixels.data;
103
- for (let i = 0; i < d.length; i += 4) {
104
- d[i] = Math.round(linearToSrgb(f[i]) * 255);
105
- d[i + 1] = Math.round(linearToSrgb(f[i + 1]) * 255);
106
- d[i + 2] = Math.round(linearToSrgb(f[i + 2]) * 255);
107
- d[i + 3] = Math.round(Math.min(1, Math.max(0, f[i + 3])) * 255);
108
- }
109
- return pixels;
110
- }
111
- function applyEffectMask(result, mask, source) {
112
- const { data } = result;
113
- const m = mask.data;
114
- for (let i = 0; i < data.length; i += 4) {
115
- const k = m[i + 3] / 255;
116
- if (k >= 1) continue;
117
- if (source) {
118
- for (let c = 0; c < 4; c++) data[i + c] = source.data[i + c] + (data[i + c] - source.data[i + c]) * k;
119
- if (result.float && source.float) {
120
- for (let c = 0; c < 4; c++) result.float[i + c] = source.float[i + c] + (result.float[i + c] - source.float[i + c]) * k;
121
- }
122
- } else {
123
- data[i + 3] = data[i + 3] * k;
124
- if (result.float) result.float[i + 3] *= k;
125
- }
126
- }
127
- return result;
128
- }
129
- var EffectsSlot = class {
130
- current = null;
131
- listeners = /* @__PURE__ */ new Set();
132
- get provider() {
133
- return this.current;
134
- }
135
- set(provider) {
136
- if (provider === this.current) return;
137
- this.current = provider;
138
- for (const l of [...this.listeners]) l(provider);
139
- }
140
- /** Sets `provider` and returns a function that clears it again (if it is still the one set). */
141
- use(provider) {
142
- this.set(provider);
143
- return () => {
144
- if (this.current === provider) this.set(null);
145
- };
146
- }
147
- /** The provider, or a `NoEffectsProviderError`. */
148
- require() {
149
- if (!this.current) throw new NoEffectsProviderError();
150
- return this.current;
151
- }
152
- subscribe(listener) {
153
- this.listeners.add(listener);
154
- return () => this.listeners.delete(listener);
155
- }
156
- };
157
-
158
- // src/effects/pool.ts
159
- var EffectRendererPool = class {
160
- entries = /* @__PURE__ */ new Map();
161
- maxRenderers;
162
- constructor(options = {}) {
163
- this.maxRenderers = Math.max(1, options.maxRenderers ?? 4);
164
- }
165
- /** Live renderers now. */
166
- get size() {
167
- return this.entries.size;
168
- }
169
- /** Renders `request` with the provider's renderer for this effect, size and depth (made on first use). */
170
- render(provider, id, size, request) {
171
- const depth = size.depth ?? 8;
172
- const key = `${provider.id}:${id}@${size.width}x${size.height}x${depth}`;
173
- let entry = this.entries.get(key);
174
- if (entry) {
175
- this.entries.delete(key);
176
- this.entries.set(key, entry);
177
- } else {
178
- const renderer = Promise.resolve().then(() => provider.createRenderer(id, { width: size.width, height: size.height, depth }));
179
- renderer.catch(() => {
180
- if (this.entries.get(key)?.renderer === renderer) this.entries.delete(key);
181
- });
182
- entry = { renderer, queue: Promise.resolve() };
183
- this.entries.set(key, entry);
184
- this.evict();
185
- }
186
- const e = entry;
187
- const next = e.queue.then(() => e.renderer).then((r) => r.render(request));
188
- e.queue = next.catch(() => void 0);
189
- return next;
190
- }
191
- /** Disposes the least recently used renderers over the limit, after their queued renders. */
192
- evict() {
193
- while (this.entries.size > this.maxRenderers) {
194
- const [key, entry] = this.entries.entries().next().value;
195
- this.entries.delete(key);
196
- dispose(entry);
197
- }
198
- }
199
- /** Disposes every renderer (after its queued renders). */
200
- clear() {
201
- for (const entry of this.entries.values()) dispose(entry);
202
- this.entries.clear();
203
- }
204
- };
205
- function dispose(entry) {
206
- entry.queue.then(() => entry.renderer).then(
207
- (r) => r.dispose(),
208
- () => {
209
- }
210
- );
211
- }
212
-
213
- export {
214
- EFFECT_ERROR_CODES,
215
- EffectError,
216
- UnknownEffectError,
217
- EffectControlError,
218
- EffectUnsupportedError,
219
- EffectDisposedError,
220
- NoEffectsProviderError,
221
- isEffectError,
222
- effectValueErrors,
223
- resolveEffectValues,
224
- searchEffectSummaries,
225
- createEffectPixels,
226
- isEffectPixels,
227
- srgbToLinear,
228
- linearToSrgb,
229
- encodeEffectFloat,
230
- applyEffectMask,
231
- EffectsSlot,
232
- EffectRendererPool
233
- };
234
- //# sourceMappingURL=chunk-QEG3GRN2.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/effects/errors.ts","../src/effects/helpers.ts","../src/effects/pool.ts"],"sourcesContent":["import type { SchemaValidationError } from '../tools/schema.js';\n\nexport type EffectErrorCode = 'unknown_effect' | 'invalid_values' | 'unsupported' | 'disposed' | 'no_provider';\n\nexport const EFFECT_ERROR_CODES: readonly EffectErrorCode[] = ['unknown_effect', 'invalid_values', 'unsupported', 'disposed', 'no_provider'];\n\n/**\n * Base of every effects error. Check `code` (or use `isEffectError`) rather than `instanceof`\n * across packages, since a provider may be bundled with its own copy of this class.\n */\nexport class EffectError extends Error {\n\treadonly code: EffectErrorCode;\n\treadonly effectId?: string;\n\n\tconstructor(code: EffectErrorCode, message: string, effectId?: string) {\n\t\tsuper(message);\n\t\tthis.name = 'EffectError';\n\t\tthis.code = code;\n\t\tthis.effectId = effectId;\n\t}\n}\n\n/** No effect has this id. */\nexport class UnknownEffectError extends EffectError {\n\tconstructor(effectId: string, providerName?: string) {\n\t\tsuper(\n\t\t\t'unknown_effect',\n\t\t\t`Unknown effect \"${effectId}\"${providerName ? ` in ${providerName}` : ''}. Call search_effects or list() for valid ids.`,\n\t\t\teffectId\n\t\t);\n\t\tthis.name = 'UnknownEffectError';\n\t}\n}\n\n/** Control values do not match the effect's control schema (unknown control, wrong type, out of range). */\nexport class EffectControlError extends EffectError {\n\treadonly details: readonly SchemaValidationError[];\n\n\tconstructor(effectId: string, details: readonly SchemaValidationError[]) {\n\t\tconst lines = details.map((d) => `- ${d.path || '/'}: ${d.message}`).join('\\n');\n\t\tsuper('invalid_values', `Invalid values for effect \"${effectId}\":\\n${lines}`, effectId);\n\t\tthis.name = 'EffectControlError';\n\t\tthis.details = details;\n\t}\n}\n\n/** The provider cannot do this (a vector effect asked for pixels, a size above `maxSize`, a missing input...). */\nexport class EffectUnsupportedError extends EffectError {\n\tconstructor(message: string, effectId?: string) {\n\t\tsuper('unsupported', message, effectId);\n\t\tthis.name = 'EffectUnsupportedError';\n\t}\n}\n\n/** The renderer was disposed. Create a new one. */\nexport class EffectDisposedError extends EffectError {\n\tconstructor(effectId: string) {\n\t\tsuper('disposed', `The renderer for \"${effectId}\" was disposed. Create a new renderer.`, effectId);\n\t\tthis.name = 'EffectDisposedError';\n\t}\n}\n\n/** No effects provider is registered with this editor. */\nexport class NoEffectsProviderError extends EffectError {\n\tconstructor() {\n\t\tsuper('no_provider', 'No effects provider is registered with this editor. The host must call setEffectsProvider(provider) first.');\n\t\tthis.name = 'NoEffectsProviderError';\n\t}\n}\n\n/** True for any effects error, including one thrown by another copy of this module. */\nexport function isEffectError(error: unknown): error is EffectError {\n\tif (error instanceof EffectError) return true;\n\tconst code = error instanceof Error ? (error as unknown as { code?: unknown }).code : undefined;\n\treturn typeof code === 'string' && EFFECT_ERROR_CODES.includes(code as EffectErrorCode);\n}\n","/**\n * Helpers for providers and editors: value validation, catalog search, pixel buffers, masking,\n * and a provider slot editors hold.\n */\n\nimport { validateJsonSchema, type SchemaValidationError } from '../tools/schema.js';\nimport { EffectControlError, NoEffectsProviderError } from './errors.js';\nimport type {\n\tEffectDescription,\n\tEffectImageSource,\n\tEffectPixels,\n\tEffectProvider,\n\tEffectSearchOptions,\n\tEffectSummary,\n\tEffectValues\n} from './types.js';\n\n// ---------------------------------------------------------------------------\n// Values\n// ---------------------------------------------------------------------------\n\n/** Problems with `values` against an effect's control schema (unknown controls, types, ranges). Partial values are fine. */\nexport function effectValueErrors(description: Pick<EffectDescription, 'controls'>, values: unknown): SchemaValidationError[] {\n\tif (values === undefined) return [];\n\treturn validateJsonSchema(values, { ...description.controls, required: [] });\n}\n\n/**\n * `values` over the effect's defaults, validated against its control schema. Throws\n * `EffectControlError` naming every bad control. Providers call this in `render`; editors call\n * it before saving values.\n */\nexport function resolveEffectValues(description: Pick<EffectDescription, 'id' | 'controls' | 'defaults'>, values?: EffectValues): Record<string, EffectValues[string]> {\n\tconst errors = effectValueErrors(description, values);\n\tif (errors.length) throw new EffectControlError(description.id, errors);\n\treturn { ...description.defaults, ...(values ?? {}) };\n}\n\n// ---------------------------------------------------------------------------\n// Search\n// ---------------------------------------------------------------------------\n\nconst matchesFilters = (e: EffectSummary, o: EffectSearchOptions) =>\n\t(!o.kind || e.kind === o.kind) && (!o.category || e.category === o.category) && (!o.use || e.uses.includes(o.use));\n\n/**\n * Filters a catalog and ranks it against `query` (every word must appear in the id, name,\n * category, tags or description; name matches rank first). An empty query keeps catalog order.\n * Providers can implement `list` and `search` with it.\n */\nexport function searchEffectSummaries<T extends EffectSummary>(catalog: readonly T[], query = '', options: EffectSearchOptions = {}): T[] {\n\tconst words = query.toLowerCase().split(/\\s+/).filter(Boolean);\n\tconst scored: { e: T; score: number; i: number }[] = [];\n\tcatalog.forEach((e, i) => {\n\t\tif (!matchesFilters(e, options)) return;\n\t\tconst name = e.name.toLowerCase();\n\t\tconst hay = [e.id, e.name, e.category, ...(e.tags ?? []), e.description ?? ''].join(' ').toLowerCase();\n\t\tlet score = 0;\n\t\tfor (const w of words) {\n\t\t\tif (!hay.includes(w)) return;\n\t\t\tscore += name.startsWith(w) ? 3 : name.includes(w) ? 2 : 1;\n\t\t}\n\t\tscored.push({ e, score, i });\n\t});\n\tscored.sort((a, b) => b.score - a.score || a.i - b.i);\n\tconst out = scored.map((s) => s.e);\n\treturn options.limit !== undefined ? out.slice(0, Math.max(0, options.limit)) : out;\n}\n\n// ---------------------------------------------------------------------------\n// Pixels\n// ---------------------------------------------------------------------------\n\n/** A transparent picture, with float samples when `float` is set. */\nexport function createEffectPixels(width: number, height: number, float = false): EffectPixels {\n\tconst n = Math.max(0, width * height * 4);\n\treturn { width, height, data: new Uint8ClampedArray(n), ...(float ? { float: new Float32Array(n) } : {}) };\n}\n\n/** True for an `EffectPixels` (rather than a host image object). */\nexport function isEffectPixels(source: EffectImageSource | unknown): source is EffectPixels {\n\treturn (\n\t\t!!source &&\n\t\ttypeof source === 'object' &&\n\t\t(source as EffectPixels).data instanceof Uint8ClampedArray &&\n\t\ttypeof (source as EffectPixels).width === 'number' &&\n\t\ttypeof (source as EffectPixels).height === 'number'\n\t);\n}\n\n/** sRGB-encoded 0–1 to linear light. */\nexport const srgbToLinear = (v: number) => (v <= 0.04045 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4));\n/** Linear light to sRGB-encoded (clamped below at 0; may exceed 1). */\nexport const linearToSrgb = (v: number) => (v > 0 ? (v <= 0.0031308 ? v * 12.92 : 1.055 * Math.pow(v, 1 / 2.4) - 0.055) : 0);\n\n/** Fills `pixels.data` from `pixels.float` (linear float to clamped 8-bit sRGB). */\nexport function encodeEffectFloat(pixels: EffectPixels): EffectPixels {\n\tconst f = pixels.float;\n\tif (!f) return pixels;\n\tconst d = pixels.data;\n\tfor (let i = 0; i < d.length; i += 4) {\n\t\td[i] = Math.round(linearToSrgb(f[i]) * 255);\n\t\td[i + 1] = Math.round(linearToSrgb(f[i + 1]) * 255);\n\t\td[i + 2] = Math.round(linearToSrgb(f[i + 2]) * 255);\n\t\td[i + 3] = Math.round(Math.min(1, Math.max(0, f[i + 3])) * 255);\n\t}\n\treturn pixels;\n}\n\n/**\n * Blends an effect `result` back over its `source` by `mask` coverage (alpha channel), in place\n * on `result`: where the mask is 0 the source shows, where it is 255 the result. Without a\n * source (generators), the result's alpha is multiplied by coverage. Editors use it when the\n * provider does not `supportsMask`. All three must have the same size.\n */\nexport function applyEffectMask(result: EffectPixels, mask: EffectPixels, source?: EffectPixels): EffectPixels {\n\tconst { data } = result;\n\tconst m = mask.data;\n\tfor (let i = 0; i < data.length; i += 4) {\n\t\tconst k = m[i + 3] / 255;\n\t\tif (k >= 1) continue;\n\t\tif (source) {\n\t\t\tfor (let c = 0; c < 4; c++) data[i + c] = source.data[i + c] + (data[i + c] - source.data[i + c]) * k;\n\t\t\tif (result.float && source.float) {\n\t\t\t\tfor (let c = 0; c < 4; c++) result.float[i + c] = source.float[i + c] + (result.float[i + c] - source.float[i + c]) * k;\n\t\t\t}\n\t\t} else {\n\t\t\tdata[i + 3] = data[i + 3] * k;\n\t\t\tif (result.float) result.float[i + 3] *= k;\n\t\t}\n\t}\n\treturn result;\n}\n\n// ---------------------------------------------------------------------------\n// The slot an editor keeps\n// ---------------------------------------------------------------------------\n\n/**\n * Holds an editor's effects provider. Controllers expose it as `effectsProvider`,\n * `setEffectsProvider(provider | null)` and `useEffects(provider)`; listeners hear every change.\n */\nexport class EffectsSlot {\n\tprivate current: EffectProvider | null = null;\n\tprivate readonly listeners = new Set<(provider: EffectProvider | null) => void>();\n\n\tget provider(): EffectProvider | null {\n\t\treturn this.current;\n\t}\n\n\tset(provider: EffectProvider | null): void {\n\t\tif (provider === this.current) return;\n\t\tthis.current = provider;\n\t\tfor (const l of [...this.listeners]) l(provider);\n\t}\n\n\t/** Sets `provider` and returns a function that clears it again (if it is still the one set). */\n\tuse(provider: EffectProvider): () => void {\n\t\tthis.set(provider);\n\t\treturn () => {\n\t\t\tif (this.current === provider) this.set(null);\n\t\t};\n\t}\n\n\t/** The provider, or a `NoEffectsProviderError`. */\n\trequire(): EffectProvider {\n\t\tif (!this.current) throw new NoEffectsProviderError();\n\t\treturn this.current;\n\t}\n\n\tsubscribe(listener: (provider: EffectProvider | null) => void): () => void {\n\t\tthis.listeners.add(listener);\n\t\treturn () => this.listeners.delete(listener);\n\t}\n}\n","/**\n * `EffectRendererPool`: keeps a few live renderers, reused per effect, size and depth.\n *\n * GPU providers hold one graphics context per renderer, and browsers allow only about sixteen\n * WebGL contexts at a time (the oldest is lost after that). So the pool keeps at most\n * `maxRenderers` renderers. It disposes the least recently used one once its renders finish, and it\n * runs one render at a time per renderer, as the contract requires.\n */\n\nimport type { EffectPixels, EffectProvider, EffectRenderer, EffectRenderRequest } from './types.js';\n\ninterface PoolEntry {\n\trenderer: Promise<EffectRenderer>;\n\t/** The last render queued on it. */\n\tqueue: Promise<unknown>;\n}\n\nexport interface EffectRendererPoolOptions {\n\t/** Most live renderers (default 4). */\n\tmaxRenderers?: number;\n}\n\nexport class EffectRendererPool {\n\tprivate readonly entries = new Map<string, PoolEntry>();\n\tprivate readonly maxRenderers: number;\n\n\tconstructor(options: EffectRendererPoolOptions = {}) {\n\t\tthis.maxRenderers = Math.max(1, options.maxRenderers ?? 4);\n\t}\n\n\t/** Live renderers now. */\n\tget size(): number {\n\t\treturn this.entries.size;\n\t}\n\n\t/** Renders `request` with the provider's renderer for this effect, size and depth (made on first use). */\n\trender(provider: EffectProvider, id: string, size: { width: number; height: number; depth?: 8 | 16 | 32 }, request: EffectRenderRequest): Promise<EffectPixels> {\n\t\tconst depth = size.depth ?? 8;\n\t\tconst key = `${provider.id}:${id}@${size.width}x${size.height}x${depth}`;\n\t\tlet entry = this.entries.get(key);\n\t\tif (entry) {\n\t\t\tthis.entries.delete(key);\n\t\t\tthis.entries.set(key, entry);\n\t\t} else {\n\t\t\tconst renderer = Promise.resolve().then(() => provider.createRenderer(id, { width: size.width, height: size.height, depth }));\n\t\t\trenderer.catch(() => {\n\t\t\t\tif (this.entries.get(key)?.renderer === renderer) this.entries.delete(key);\n\t\t\t});\n\t\t\tentry = { renderer, queue: Promise.resolve() };\n\t\t\tthis.entries.set(key, entry);\n\t\t\tthis.evict();\n\t\t}\n\t\tconst e = entry;\n\t\tconst next = e.queue.then(() => e.renderer).then((r) => r.render(request));\n\t\te.queue = next.catch(() => undefined);\n\t\treturn next;\n\t}\n\n\t/** Disposes the least recently used renderers over the limit, after their queued renders. */\n\tprivate evict(): void {\n\t\twhile (this.entries.size > this.maxRenderers) {\n\t\t\tconst [key, entry] = this.entries.entries().next().value!;\n\t\t\tthis.entries.delete(key);\n\t\t\tdispose(entry);\n\t\t}\n\t}\n\n\t/** Disposes every renderer (after its queued renders). */\n\tclear(): void {\n\t\tfor (const entry of this.entries.values()) dispose(entry);\n\t\tthis.entries.clear();\n\t}\n}\n\nfunction dispose(entry: PoolEntry) {\n\tentry.queue\n\t\t.then(() => entry.renderer)\n\t\t.then(\n\t\t\t(r) => r.dispose(),\n\t\t\t() => {}\n\t\t);\n}\n"],"mappings":";;;;;AAIO,IAAM,qBAAiD,CAAC,kBAAkB,kBAAkB,eAAe,YAAY,aAAa;AAMpI,IAAM,cAAN,cAA0B,MAAM;AAAA,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