@pixerate/editor 0.123.0 → 0.124.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/agent/index.cjs +2 -2
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.js +3 -3
- package/dist/animation/index.d.cts +2 -1
- package/dist/animation/index.d.ts +2 -1
- package/dist/animation-editor/index.cjs.map +1 -1
- package/dist/animation-editor/index.d.cts +11 -733
- package/dist/animation-editor/index.d.ts +11 -733
- package/dist/animation-editor/index.js.map +1 -1
- package/dist/{bezier-C-W9LFyD.d.cts → bezier-CBzKKDjl.d.cts} +2 -66
- package/dist/{bezier-DQZE5dxA.d.ts → bezier-CWv6LQal.d.ts} +2 -66
- package/dist/{brushstrokeRender-M4S65DHT.cjs → brushstrokeRender-EELTV7U4.cjs} +8 -8
- package/dist/{brushstrokeRender-M4S65DHT.cjs.map → brushstrokeRender-EELTV7U4.cjs.map} +1 -1
- package/dist/{brushstrokeRender-CDDRSV2W.js → brushstrokeRender-LRV7GXGD.js} +3 -3
- package/dist/canvas/index.cjs +6 -6
- package/dist/canvas/index.d.cts +10 -6
- package/dist/canvas/index.d.ts +10 -6
- package/dist/canvas/index.js +1 -1
- package/dist/{chunk-TVXFHE4T.js → chunk-64PYNEHJ.js} +45 -12
- package/dist/chunk-64PYNEHJ.js.map +1 -0
- package/dist/{chunk-2IW3BWRT.cjs → chunk-7LQO6OHH.cjs} +2 -2
- package/dist/{chunk-2IW3BWRT.cjs.map → chunk-7LQO6OHH.cjs.map} +1 -1
- package/dist/chunk-IOXKXQNW.cjs +178 -0
- package/dist/chunk-IOXKXQNW.cjs.map +1 -0
- package/dist/{chunk-SMJGE7HM.cjs → chunk-IWSMDQE5.cjs} +523 -39
- package/dist/chunk-IWSMDQE5.cjs.map +1 -0
- package/dist/{chunk-KMBC4HNV.js → chunk-J67OLQUQ.js} +2 -2
- package/dist/{chunk-6CJRDJCU.cjs → chunk-PEHYWUVV.cjs} +176 -111
- package/dist/chunk-PEHYWUVV.cjs.map +1 -0
- package/dist/chunk-TGKT5QAB.js +178 -0
- package/dist/chunk-TGKT5QAB.js.map +1 -0
- package/dist/chunk-TK53AB4Q.cjs +215 -0
- package/dist/chunk-TK53AB4Q.cjs.map +1 -0
- package/dist/chunk-VFAKN46Z.js +215 -0
- package/dist/chunk-VFAKN46Z.js.map +1 -0
- package/dist/{chunk-6ZBR4J62.js → chunk-WATAQ2Z2.js} +79 -14
- package/dist/chunk-WATAQ2Z2.js.map +1 -0
- package/dist/{chunk-IPFRWILU.js → chunk-YVVSTD3B.js} +499 -15
- package/dist/chunk-YVVSTD3B.js.map +1 -0
- package/dist/{chunk-RLRUAPBJ.cjs → chunk-Z6OUCS2K.cjs} +47 -14
- package/dist/chunk-Z6OUCS2K.cjs.map +1 -0
- package/dist/effects/index.cjs +588 -0
- package/dist/effects/index.cjs.map +1 -0
- package/dist/effects/index.d.cts +131 -0
- package/dist/effects/index.d.ts +131 -0
- package/dist/effects/index.js +588 -0
- package/dist/effects/index.js.map +1 -0
- package/dist/evaluate-2S3vSPLy.d.cts +55 -0
- package/dist/evaluate-CfmT6xA3.d.ts +55 -0
- package/dist/{export-DfjzHAJI.d.ts → export-8RnlngAv.d.ts} +534 -128
- package/dist/{export-Dv0-ZVrV.d.ts → export-BzSRXyH6.d.cts} +390 -5
- package/dist/{export-Dv0-ZVrV.d.cts → export-DM3h7QEI.d.ts} +390 -5
- package/dist/{export-lU5qSpHE.d.cts → export-TqXMOlDt.d.cts} +534 -128
- package/dist/flair-CxB3fOcU.d.ts +739 -0
- package/dist/flair-D7BxyBwL.d.cts +739 -0
- package/dist/gradient-KDfCvhuj.d.cts +66 -0
- package/dist/gradient-KDfCvhuj.d.ts +66 -0
- package/dist/helpers-777mC6dc.d.cts +253 -0
- package/dist/helpers-DX2_7L5t.d.ts +253 -0
- package/dist/image-editor/index.cjs +1307 -805
- package/dist/image-editor/index.cjs.map +1 -1
- package/dist/image-editor/index.d.cts +39 -182
- package/dist/image-editor/index.d.ts +39 -182
- package/dist/image-editor/index.js +508 -6
- package/dist/image-editor/index.js.map +1 -1
- package/dist/{opentype-p8Xxf-Wh.d.ts → opentype-14PDI5D2.d.ts} +1 -1
- package/dist/{opentype-BV7wWatY.d.cts → opentype-D80AVmMu.d.cts} +1 -1
- package/dist/paint/index.cjs +2 -2
- package/dist/paint/index.d.cts +32 -10
- package/dist/paint/index.d.ts +32 -10
- package/dist/paint/index.js +1 -1
- package/dist/paint-editor/index.cjs +10 -8
- package/dist/paint-editor/index.cjs.map +1 -1
- package/dist/paint-editor/index.d.cts +11 -5
- package/dist/paint-editor/index.d.ts +11 -5
- package/dist/paint-editor/index.js +4 -2
- package/dist/paint-editor/index.js.map +1 -1
- package/dist/parameters/index.d.cts +4 -184
- package/dist/parameters/index.d.ts +4 -184
- package/dist/{pathfinder-IxcyhO00.d.cts → pathfinder-C0UoFypx.d.cts} +1 -1
- package/dist/{pathfinder-StVChJOT.d.ts → pathfinder-DjISxkUv.d.ts} +1 -1
- package/dist/{player-DrcP2xqj.d.cts → player-CBtEoU2x.d.cts} +2 -54
- package/dist/{player-DV4Jujdq.d.ts → player-cGLrngL_.d.ts} +2 -54
- package/dist/{svg-BtND4TJu.d.cts → svg-BDrjRnL1.d.cts} +3 -2
- package/dist/{svg-BfVXG7hL.d.ts → svg-C-vZ3q50.d.ts} +3 -2
- package/dist/tools/index.cjs +2 -2
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.js +3 -3
- package/dist/tools-C7JtLYzo.d.ts +126 -0
- package/dist/tools-DHKGHiSK.d.cts +126 -0
- package/dist/{types-fuXEme9j.d.ts → types-BcX7sCsn.d.ts} +2 -2
- package/dist/{types-DJF3Ghn5.d.cts → types-CznabG7m.d.cts} +2 -2
- package/dist/types-D3-J3TFf.d.ts +185 -0
- package/dist/types-DMcf_z4J.d.cts +185 -0
- package/dist/vector/index.d.cts +10 -10
- package/dist/vector/index.d.ts +10 -10
- package/dist/video-editor/index.cjs +749 -277
- package/dist/video-editor/index.cjs.map +1 -1
- package/dist/video-editor/index.d.cts +265 -138
- package/dist/video-editor/index.d.ts +265 -138
- package/dist/video-editor/index.js +490 -18
- package/dist/video-editor/index.js.map +1 -1
- package/dist/{warp-BjmAgQwq.d.cts → warp-CH9MM435.d.cts} +1 -1
- package/dist/{warp-Ca5fedzS.d.ts → warp-k_PdtXOG.d.ts} +1 -1
- package/package.json +6 -1
- package/skills/pixerate-image-editor/SKILL.md +7 -0
- package/skills/pixerate-image-editor/references/provider-effects.md +35 -0
- package/skills/pixerate-video-editor/SKILL.md +39 -1
- package/dist/chunk-6CJRDJCU.cjs.map +0 -1
- package/dist/chunk-6ZBR4J62.js.map +0 -1
- package/dist/chunk-IPFRWILU.js.map +0 -1
- package/dist/chunk-RLRUAPBJ.cjs.map +0 -1
- package/dist/chunk-SMJGE7HM.cjs.map +0 -1
- package/dist/chunk-TVXFHE4T.js.map +0 -1
- /package/dist/{brushstrokeRender-CDDRSV2W.js.map → brushstrokeRender-LRV7GXGD.js.map} +0 -0
- /package/dist/{chunk-KMBC4HNV.js.map → chunk-J67OLQUQ.js.map} +0 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isEffectError
|
|
3
|
+
} from "./chunk-TGKT5QAB.js";
|
|
4
|
+
|
|
5
|
+
// src/effects/types.ts
|
|
6
|
+
var EFFECT_KINDS = ["shader", "vector", "motion"];
|
|
7
|
+
var EFFECT_USES = ["filter", "transition", "generator", "overlay", "title", "motion", "interactive"];
|
|
8
|
+
|
|
9
|
+
// src/effects/tools.ts
|
|
10
|
+
var ANNOTATIONS = {
|
|
11
|
+
read: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
12
|
+
write: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
|
|
13
|
+
writeIdempotent: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
|
|
14
|
+
destructive: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false }
|
|
15
|
+
};
|
|
16
|
+
var NO_PROVIDER = "No effects provider is registered with this editor, so there are no effects to search, describe or apply. The host app must register one (setEffectsProvider); effects already in the document are kept and shown as placeholders.";
|
|
17
|
+
var object = (properties, required = []) => ({
|
|
18
|
+
type: "object",
|
|
19
|
+
properties,
|
|
20
|
+
...required.length ? { required } : {},
|
|
21
|
+
additionalProperties: false
|
|
22
|
+
});
|
|
23
|
+
var ENUM_LIMIT = 60;
|
|
24
|
+
var summaryOut = (e) => ({
|
|
25
|
+
id: e.id,
|
|
26
|
+
name: e.name,
|
|
27
|
+
kind: e.kind,
|
|
28
|
+
category: e.category,
|
|
29
|
+
uses: e.uses,
|
|
30
|
+
...e.description ? { description: e.description } : {},
|
|
31
|
+
transparent: e.transparent,
|
|
32
|
+
loop: e.loop,
|
|
33
|
+
...e.duration !== void 0 ? { duration: e.duration } : {}
|
|
34
|
+
});
|
|
35
|
+
function createEffectToolProvider(host) {
|
|
36
|
+
let catalog = null;
|
|
37
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
38
|
+
const notify = () => listeners.forEach((l) => l());
|
|
39
|
+
const catalogFor = (provider) => {
|
|
40
|
+
if (!provider) return null;
|
|
41
|
+
if (catalog?.provider !== provider) {
|
|
42
|
+
const entry = { provider, effects: null };
|
|
43
|
+
catalog = entry;
|
|
44
|
+
Promise.resolve().then(() => provider.list()).then((effects) => {
|
|
45
|
+
if (catalog === entry) {
|
|
46
|
+
entry.effects = effects;
|
|
47
|
+
notify();
|
|
48
|
+
}
|
|
49
|
+
}).catch(() => {
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return catalog.effects;
|
|
53
|
+
};
|
|
54
|
+
const requireProvider = () => {
|
|
55
|
+
const p = host.provider();
|
|
56
|
+
if (!p) throw new Error(NO_PROVIDER);
|
|
57
|
+
return p;
|
|
58
|
+
};
|
|
59
|
+
const writable = () => {
|
|
60
|
+
const reason = host.readOnlyReason();
|
|
61
|
+
if (reason) throw new Error(reason);
|
|
62
|
+
return requireProvider();
|
|
63
|
+
};
|
|
64
|
+
const explain = async (run) => {
|
|
65
|
+
try {
|
|
66
|
+
return await run();
|
|
67
|
+
} catch (error) {
|
|
68
|
+
if (isEffectError(error)) throw new Error(error.message);
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const valuesSchema = (what, keyframes = false) => ({
|
|
73
|
+
type: "object",
|
|
74
|
+
description: `${what}: control name \u2192 value, as listed by describe_effect (its "controls" schema: types, ranges, units and defaults). Only the given controls change; colours are "#rrggbb".${keyframes ? " A number control may instead be keyframes { keys: [{ t: ms from the start, v, ease }] }." : ""} Unknown controls and out-of-range values are refused with the valid ones.`
|
|
75
|
+
});
|
|
76
|
+
const effectIdSchema = (uses) => {
|
|
77
|
+
const effects = catalogFor(host.provider())?.filter((e) => e.kind !== "motion" && e.uses.some((u) => uses.includes(u)));
|
|
78
|
+
const base = `An effect id from search_effects (use ${uses.map((u) => `"${u}"`).join(" or ")}).`;
|
|
79
|
+
return effects && effects.length && effects.length <= ENUM_LIMIT ? { type: "string", enum: effects.map((e) => e.id), description: `${base} One of: ${effects.map((e) => `${e.id} (${e.name})`).join(", ")}.` } : { type: "string", minLength: 1, description: base };
|
|
80
|
+
};
|
|
81
|
+
const context = { requireProvider: writable, valuesSchema, effectIdSchema, annotations: ANNOTATIONS };
|
|
82
|
+
const TARGET = { type: "string", minLength: 1, description: host.target.id };
|
|
83
|
+
const INSTANCE = { type: "string", minLength: 1, description: `The effect's id on the ${host.target.noun}, from list_applied_effects or apply_effect.` };
|
|
84
|
+
const INDEX = { type: "integer", minimum: 0, description: `Place in the ${host.target.noun}'s effect stack: 0 is applied first (default: the end, applied last).` };
|
|
85
|
+
const OPACITY = { type: "number", minimum: 0, maximum: 1, description: "How much of the effect shows over its input, 0\u20131 (default 1)." };
|
|
86
|
+
const ENABLED = { type: "boolean", description: "false turns the effect off but keeps it (default true)." };
|
|
87
|
+
const readTools = () => [
|
|
88
|
+
{
|
|
89
|
+
name: "search_effects",
|
|
90
|
+
title: "Search effects",
|
|
91
|
+
description: `Searches the effects provider's catalog. Every word of query must appear in an effect's id, name, category, tags or description; filter by kind (shader, vector, motion), category or use (${EFFECT_USES.join(", ")}). For this editor, apply_effect takes uses ${host.applyUses.join(" or ")}. Returns { provider, effects: [{ id, name, kind, category, uses, description, transparent, loop, duration (ms) }], total }. With no provider registered it returns available: false and the reason. Call describe_effect next for an effect's controls.`,
|
|
92
|
+
inputSchema: object({
|
|
93
|
+
query: { type: "string", description: "Words to match (default: every effect)." },
|
|
94
|
+
kind: { type: "string", enum: [...EFFECT_KINDS], description: "shader (pixels), vector (animated SVG) or motion (animates vector art)." },
|
|
95
|
+
category: { type: "string", minLength: 1, description: `The provider's category, e.g. "gradient", "light", "transition".` },
|
|
96
|
+
use: { type: "string", enum: [...EFFECT_USES], description: "What the effect is for: filter changes a picture, transition blends two, generator draws a background, overlay draws over content, title draws a title, motion animates vector art, interactive reacts to input." },
|
|
97
|
+
limit: { type: "integer", minimum: 1, maximum: 200, description: "Most effects to return (default 20)." }
|
|
98
|
+
}),
|
|
99
|
+
annotations: { title: "Search effects", ...ANNOTATIONS.read },
|
|
100
|
+
handler: async (args) => {
|
|
101
|
+
const p = host.provider();
|
|
102
|
+
if (!p) return { available: false, reason: NO_PROVIDER, effects: [], total: 0 };
|
|
103
|
+
const found = await explain(async () => p.search(args.query ?? "", { kind: args.kind, category: args.category, use: args.use }));
|
|
104
|
+
const limit = args.limit ?? 20;
|
|
105
|
+
return { available: true, provider: { id: p.id, name: p.name, capabilities: p.capabilities }, effects: found.slice(0, limit).map(summaryOut), total: found.length };
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: "describe_effect",
|
|
110
|
+
title: "Describe an effect",
|
|
111
|
+
description: "Returns one effect's controls as a strict JSON Schema (each control described, with its type, range and units), its defaults, presets (named sets of values) and inputs, plus its summary. Use the control names and ranges for apply_effect and update_effect values. With no provider registered it returns available: false and the reason.",
|
|
112
|
+
inputSchema: object({ effect: { type: "string", minLength: 1, description: "An effect id from search_effects or list_applied_effects." } }, ["effect"]),
|
|
113
|
+
annotations: { title: "Describe an effect", ...ANNOTATIONS.read },
|
|
114
|
+
handler: async (args) => {
|
|
115
|
+
const p = host.provider();
|
|
116
|
+
if (!p) return { available: false, reason: NO_PROVIDER };
|
|
117
|
+
const d = await explain(async () => p.describe(args.effect));
|
|
118
|
+
return { available: true, ...summaryOut(d), controls: d.controls, defaults: d.defaults, presets: d.presets, inputs: d.inputs, appliesHere: d.kind !== "motion" && d.uses.some((u) => host.applyUses.includes(u)) };
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
name: "list_applied_effects",
|
|
123
|
+
title: "List applied effects",
|
|
124
|
+
description: `Lists the effects in the document: for each ${host.target.noun} that has any (or the one given), its effects in order with id, effect id, name, role, enabled, opacity and saved values. available is false for an effect the current provider does not have (or when none is registered): it is kept and drawn as a placeholder, and can still be removed. Works without a provider.`,
|
|
125
|
+
inputSchema: object({ target: { ...TARGET, description: `${host.target.id} Leave out to list every ${host.target.noun} with effects.` } }),
|
|
126
|
+
annotations: { title: "List applied effects", ...ANNOTATIONS.read },
|
|
127
|
+
handler: async (args) => {
|
|
128
|
+
const p = host.provider();
|
|
129
|
+
const known = new Set((p ? await explain(async () => p.list()) : []).map((e) => e.id));
|
|
130
|
+
const targets = host.list(args.target).map((t) => ({ ...t, effects: t.effects.map((e) => ({ ...e, available: known.has(e.effect) })) }));
|
|
131
|
+
return { provider: p ? { id: p.id, name: p.name } : null, ...p ? {} : { reason: NO_PROVIDER }, targets };
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
];
|
|
135
|
+
const writeTools = () => [
|
|
136
|
+
{
|
|
137
|
+
name: "apply_effect",
|
|
138
|
+
title: "Apply an effect",
|
|
139
|
+
description: `Adds a provider effect to a ${host.target.noun}. ${host.applyDetails} values are checked against describe_effect's controls first; nothing changes if any is wrong. One undo step. Returns the effect with its new id (for update_effect and remove_effect) and the ${host.target.noun}'s effects. Refused when no provider is registered.`,
|
|
140
|
+
inputSchema: object(
|
|
141
|
+
{
|
|
142
|
+
target: TARGET,
|
|
143
|
+
effect: effectIdSchema(host.applyUses),
|
|
144
|
+
values: valuesSchema("Control values over the effect's defaults", true),
|
|
145
|
+
index: INDEX,
|
|
146
|
+
enabled: ENABLED,
|
|
147
|
+
opacity: OPACITY
|
|
148
|
+
},
|
|
149
|
+
["target", "effect"]
|
|
150
|
+
),
|
|
151
|
+
annotations: { title: "Apply an effect", ...ANNOTATIONS.write },
|
|
152
|
+
handler: async (args) => {
|
|
153
|
+
writable();
|
|
154
|
+
return explain(() => host.apply(args.target, args.effect, { values: args.values, index: args.index, enabled: args.enabled, opacity: args.opacity }));
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
name: "update_effect",
|
|
159
|
+
title: "Change an applied effect",
|
|
160
|
+
description: `Changes one applied effect on a ${host.target.noun}: its values (merged over the current ones; null resets a control to its default), enabled, opacity or place in the stack. Values are checked against describe_effect's controls first. One undo step. Returns the effect as it is now and the ${host.target.noun}'s effects. Refused when no provider is registered.`,
|
|
161
|
+
inputSchema: object(
|
|
162
|
+
{
|
|
163
|
+
target: TARGET,
|
|
164
|
+
effect: INSTANCE,
|
|
165
|
+
values: { ...valuesSchema("Control values to change", true), description: `${valuesSchema("Control values to change", true).description} null resets a control to its default.` },
|
|
166
|
+
enabled: ENABLED,
|
|
167
|
+
opacity: OPACITY,
|
|
168
|
+
index: { ...INDEX, description: `Move it to this place in the ${host.target.noun}'s stack (0 = applied first).` }
|
|
169
|
+
},
|
|
170
|
+
["target", "effect"]
|
|
171
|
+
),
|
|
172
|
+
annotations: { title: "Change an applied effect", ...ANNOTATIONS.writeIdempotent },
|
|
173
|
+
handler: async (args) => {
|
|
174
|
+
writable();
|
|
175
|
+
if (args.values === void 0 && args.enabled === void 0 && args.opacity === void 0 && args.index === void 0) throw new Error("Give at least one of values, enabled, opacity or index to change.");
|
|
176
|
+
return explain(() => host.update(args.target, args.effect, { values: args.values, enabled: args.enabled, opacity: args.opacity, index: args.index }));
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
name: "remove_effect",
|
|
181
|
+
title: "Remove an applied effect",
|
|
182
|
+
description: `Removes one applied effect from a ${host.target.noun} (an effect the provider no longer has included). One undo step. Returns what was removed and the ${host.target.noun}'s remaining effects. Refused when no provider is registered.`,
|
|
183
|
+
inputSchema: object({ target: TARGET, effect: INSTANCE }, ["target", "effect"]),
|
|
184
|
+
annotations: { title: "Remove an applied effect", ...ANNOTATIONS.destructive },
|
|
185
|
+
handler: async (args) => {
|
|
186
|
+
writable();
|
|
187
|
+
return explain(() => host.remove(args.target, args.effect));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
];
|
|
191
|
+
return {
|
|
192
|
+
id: host.id,
|
|
193
|
+
...host.namespace ? { namespace: host.namespace } : {},
|
|
194
|
+
tools: () => {
|
|
195
|
+
const extra = host.extraTools?.(context) ?? [];
|
|
196
|
+
if (host.readOnlyReason()) return [...readTools(), ...extra.filter((t) => t.annotations?.readOnlyHint)];
|
|
197
|
+
return [...readTools(), ...writeTools(), ...extra];
|
|
198
|
+
},
|
|
199
|
+
subscribe: (l) => {
|
|
200
|
+
listeners.add(l);
|
|
201
|
+
const off = host.subscribe?.(l);
|
|
202
|
+
return () => {
|
|
203
|
+
listeners.delete(l);
|
|
204
|
+
off?.();
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export {
|
|
211
|
+
EFFECT_KINDS,
|
|
212
|
+
EFFECT_USES,
|
|
213
|
+
createEffectToolProvider
|
|
214
|
+
};
|
|
215
|
+
//# sourceMappingURL=chunk-VFAKN46Z.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/effects/types.ts","../src/effects/tools.ts"],"sourcesContent":["/**\n * The effects contract: how an editor finds, describes and renders effects that live in another\n * package. This library ships no effects of its own here, only the shapes a provider fills in;\n * a host passes a provider to an editor (`setEffectsProvider`) and the editor degrades to its\n * old behaviour without one.\n *\n * Every time is in milliseconds. Pixels are straight-alpha RGBA rows, top to bottom.\n */\n\nimport type { JsonSchema } from '../tools/schema.js';\nimport type { FlairSvgAnimation } from '../animation-editor/flair.js';\n\n/** How an effect is drawn: a pixel shader, an animated vector picture, or motion applied to someone else's vector art. */\nexport type EffectKind = 'shader' | 'vector' | 'motion';\n\n/**\n * What an effect is for. An effect may have several uses.\n *\n * - `filter`: changes an input picture (`inputs.source`).\n * - `transition`: blends `inputs.from` into `inputs.to`; `progress` runs 0 → 1.\n * - `generator`: draws a picture from nothing (a background, a texture).\n * - `overlay`: draws something meant to sit over other content, usually with transparency.\n * - `title`: draws type or a graphic meant as a title.\n * - `motion`: animates vector art (`applyVectorEffect`).\n * - `interactive`: reacts to pointer, scroll or audio input at run time.\n */\nexport type EffectUse = 'filter' | 'transition' | 'generator' | 'overlay' | 'title' | 'motion' | 'interactive';\n\nexport const EFFECT_KINDS: readonly EffectKind[] = ['shader', 'vector', 'motion'];\nexport const EFFECT_USES: readonly EffectUse[] = ['filter', 'transition', 'generator', 'overlay', 'title', 'motion', 'interactive'];\n\n/** One entry of a provider's catalog. */\nexport interface EffectSummary {\n\t/** Stable id, saved in documents. Never reused for a different effect. */\n\tid: string;\n\tname: string;\n\tkind: EffectKind;\n\t/** The provider's own grouping (e.g. `gradient`, `light`, `transition`). */\n\tcategory: string;\n\tuses: readonly EffectUse[];\n\tdescription?: string;\n\ttags?: readonly string[];\n\t/** True when the effect's output has transparent pixels (it can sit over other content). */\n\ttransparent: boolean;\n\t/** True when the effect loops; its `duration` is then one cycle. */\n\tloop: boolean;\n\t/** Length of one play (ms). Absent for effects that do not change over time. */\n\tduration?: number;\n}\n\nexport interface EffectSearchOptions {\n\tkind?: EffectKind;\n\tcategory?: string;\n\tuse?: EffectUse;\n\t/** Most results to return. */\n\tlimit?: number;\n}\n\n/** One control value: a number, a `#rrggbb` colour or other string, a switch, or a vector of numbers. */\nexport type EffectValue = number | string | boolean | readonly number[];\nexport type EffectValues = Readonly<Record<string, EffectValue>>;\n\n/**\n * The controls of an effect as a strict JSON Schema: `type: 'object'`, `additionalProperties:\n * false`, and a `description` on every property (with units and range). `checkEffectProvider`\n * checks this.\n */\nexport type EffectControlSchema = JsonSchema & {\n\ttype: 'object';\n\tproperties: { readonly [control: string]: JsonSchema };\n\tadditionalProperties: false;\n};\n\nexport interface EffectPreset {\n\tname: string;\n\t/** Values to apply over the defaults. */\n\tvalues: EffectValues;\n}\n\n/**\n * A named input the effect reads. Filters read `source`, transitions `from` and `to`; a mask is\n * passed separately (`EffectRenderRequest.mask`), not as an input.\n */\nexport interface EffectInputSpec {\n\tname: string;\n\tkind: 'image' | 'audio';\n\tdescription: string;\n\trequired: boolean;\n}\n\n/** Everything an editor needs to show an effect's controls and render it. */\nexport interface EffectDescription extends EffectSummary {\n\tcontrols: EffectControlSchema;\n\t/** A value for every control. */\n\tdefaults: EffectValues;\n\tpresets: readonly EffectPreset[];\n\tinputs: readonly EffectInputSpec[];\n}\n\n/**\n * Pixels in and out of a renderer, shaped like `ImageData`.\n *\n * `data` is 8-bit sRGB with straight alpha and is always present. `float`, when present, is the\n * same picture as 32-bit floats in **linear light** (sRGB primaries), straight alpha, where colour\n * may exceed 1. Renderers created with `depth` 16 or 32 return `float` when the provider\n * `supportsFloat`; `data` is then its clamped sRGB encoding.\n */\nexport interface EffectPixels {\n\twidth: number;\n\theight: number;\n\tdata: Uint8ClampedArray;\n\tfloat?: Float32Array;\n}\n\n/**\n * An input picture. Always accepted as `EffectPixels`; a provider whose capabilities include\n * `supportsHostImages` also takes the host's own image objects, which saves a read back.\n */\nexport type EffectImageSource = EffectPixels | ImageBitmap | OffscreenCanvas | VideoFrame;\n\nexport interface EffectRendererOptions {\n\t/** Output size in pixels. */\n\twidth: number;\n\theight: number;\n\t/** Bits per channel of the target (default 8). 16 and 32 ask for `float` output. */\n\tdepth?: 8 | 16 | 32;\n}\n\nexport interface EffectRenderRequest {\n\t/** Effect time (ms), from the start of the effect. */\n\ttime: number;\n\t/** Control values; missing controls take their defaults. Invalid values reject with `EffectControlError`. */\n\tvalues?: EffectValues;\n\t/** Pictures for the effect's named inputs (see `EffectDescription.inputs`). */\n\tinputs?: Readonly<Record<string, EffectImageSource>>;\n\t/** Coverage (alpha channel, 0 = untouched) limiting where the effect applies. Only with `supportsMask`. */\n\tmask?: EffectImageSource;\n\t/** Transitions: how far from `from` to `to`, 0–1. Defaults to `time / duration`. */\n\tprogress?: number;\n}\n\n/** A live renderer for one effect at one size. Not safe for concurrent `render` calls. */\nexport interface EffectRenderer {\n\treadonly effectId: string;\n\treadonly width: number;\n\treadonly height: number;\n\treadonly depth: 8 | 16 | 32;\n\trender(request: EffectRenderRequest): Promise<EffectPixels>;\n\t/** Frees GPU or worker resources. Rendering afterwards rejects. */\n\tdispose(): void;\n}\n\n/** One change of an animated SVG (the shape of Flair's `SvgAnimation`). */\nexport type EffectSvgAnimation = FlairSvgAnimation;\n\n/** An animated SVG: markup plus changes to its elements (the shape of Flair's `SvgMotion`). */\nexport interface EffectVectorMotion {\n\tsvg: string;\n\tanimate?: readonly EffectSvgAnimation[];\n\t/** Length of one play (ms). */\n\tduration: number;\n\tloop: boolean;\n\t/** Ms held on the last frame before looping. */\n\thold?: number;\n}\n\n/** What a vector or motion effect is applied to: SVG markup, optionally with the ids of the elements to animate (default: all). */\nexport type EffectVectorTarget = string | { svg: string; nodeIds?: readonly string[] };\n\n/** What a provider can do, so editors can degrade cleanly. */\nexport interface EffectProviderCapabilities {\n\t/** Renders off the main thread. */\n\tsupportsWorker: boolean;\n\t/** Returns `float` pixels for depth 16 and 32 renderers. */\n\tsupportsFloat: boolean;\n\t/** Honours `EffectRenderRequest.mask`; otherwise the editor masks the result itself. */\n\tsupportsMask: boolean;\n\t/** Takes `ImageBitmap`, `OffscreenCanvas` or `VideoFrame` inputs, not only `EffectPixels`. */\n\tsupportsHostImages: boolean;\n\t/** Implements `applyVectorEffect`. */\n\tsupportsVector: boolean;\n\t/** Largest width or height a renderer accepts (px). */\n\tmaxSize?: number;\n}\n\ntype MaybePromise<T> = T | Promise<T>;\n\n/**\n * A source of effects. Implementations live outside this library (for example Flair's\n * `flairEffects()`); `createFakeEffectProvider` is a small reference implementation.\n *\n * Unknown ids reject or throw `UnknownEffectError`, invalid values `EffectControlError`, and an\n * operation the provider cannot do `EffectUnsupportedError`.\n */\nexport interface EffectProvider {\n\t/** Stable id of the provider, saved next to effect ids (e.g. `flair`). */\n\treadonly id: string;\n\treadonly name: string;\n\treadonly version?: string;\n\treadonly capabilities: EffectProviderCapabilities;\n\tlist(options?: EffectSearchOptions): MaybePromise<readonly EffectSummary[]>;\n\t/** Effects matching every word of `query` (in name, id, category, tags or description), best first. */\n\tsearch(query: string, options?: EffectSearchOptions): MaybePromise<readonly EffectSummary[]>;\n\tdescribe(id: string): MaybePromise<EffectDescription>;\n\t/** A pixel renderer. A `vector` effect may refuse with `EffectUnsupportedError` where it cannot lay out SVG (a Worker). */\n\tcreateRenderer(id: string, options: EffectRendererOptions): MaybePromise<EffectRenderer>;\n\t/**\n\t * Vector and motion effects as an animated SVG. Present when `capabilities.supportsVector`. A\n\t * `motion` effect animates the target's elements (`nodeIds`, else each top-level element with an\n\t * id); a `vector` effect brings its own picture and ignores the target. Refuse a target the\n\t * effect cannot use with `EffectUnsupportedError`.\n\t */\n\tapplyVectorEffect?(id: string, target: EffectVectorTarget, values?: EffectValues): MaybePromise<EffectVectorMotion>;\n}\n","/**\n * The agent tools for provider effects, shared by every editor that takes an `EffectProvider`:\n * `search_effects`, `describe_effect`, `list_applied_effects`, `apply_effect`, `update_effect` and\n * `remove_effect`. An editor supplies an `EffectToolHost` (what its targets are and how to change\n * them as one undo step each) and may add tools of its own (`extraTools`).\n *\n * Without a provider the read tools say so (and `list_applied_effects` still lists what a\n * document holds), and the write tools refuse with the reason. On a read-only surface the write\n * tools are hidden.\n */\n\nimport type { AgentTool, AgentToolProvider } from '../tools/registry.js';\nimport type { JsonSchema } from '../tools/schema.js';\nimport { isEffectError } from './errors.js';\nimport { EFFECT_KINDS, EFFECT_USES, type EffectDescription, type EffectProvider, type EffectSummary, type EffectUse } from './types.js';\n\n/** One effect applied to a target, as the tools report it. */\nexport interface AppliedEffectInfo {\n\t/** Its id on the target: what `update_effect` and `remove_effect` take. */\n\tid: string;\n\teffect: string;\n\tname?: string;\n\tprovider?: string;\n\t/** What it is on the target (e.g. `clip effect`, `effect clip`, `transition`, `smart filter`, `effect layer`). */\n\trole: string;\n\tenabled: boolean;\n\t/** 0–1, or keyframes, where the role has an opacity. */\n\topacity?: unknown;\n\t/** Its saved control values (numbers may be keyframes where the editor allows them). */\n\tvalues: Record<string, unknown>;\n\t/** Its place in the target's stack (0 = applied first), for stacked roles. */\n\tindex?: number;\n}\n\nexport interface EffectTargetEffects {\n\ttarget: string;\n\t/** A label for the target (a clip or layer name). */\n\tname?: string;\n\teffects: AppliedEffectInfo[];\n}\n\nexport interface EffectChangeResult {\n\ttarget: string;\n\t/** What was added, changed or removed. */\n\teffect: AppliedEffectInfo;\n\t/** The target's effects afterwards. */\n\teffects: AppliedEffectInfo[];\n\t/** Other things the change made (a new clip or layer id, ...). */\n\t[extra: string]: unknown;\n}\n\n/** What an editor gives the shared effect tools. */\nexport interface EffectToolHost {\n\t/** Provider id (unique per registry). */\n\tid: string;\n\t/** Always prefix tool names with `<namespace>__`. */\n\tnamespace?: string;\n\t/** Words for the editor's targets, e.g. `{ noun: 'clip', id: 'A clip id from get_video_project (e.g. \"c1\").' }`. */\n\ttarget: { noun: string; id: string };\n\t/** The uses `apply_effect` takes on a target (others go through `extraTools`). */\n\tapplyUses: readonly EffectUse[];\n\t/** Text added to `apply_effect`'s description: where the effect goes and how it is drawn. */\n\tapplyDetails: string;\n\t/** The current provider, or `null`. */\n\tprovider(): EffectProvider | null;\n\t/** Why edits are refused now (read-only), or `null`. */\n\treadOnlyReason(): string | null;\n\t/** Every target with effects, or one target (throws for an unknown id, naming valid ones). */\n\tlist(target?: string): EffectTargetEffects[];\n\tapply(target: string, effect: string, args: { values?: Record<string, unknown>; index?: number; enabled?: boolean; opacity?: number }): Promise<EffectChangeResult>;\n\tupdate(target: string, instance: string, changes: { values?: Record<string, unknown>; index?: number; enabled?: boolean; opacity?: number }): Promise<EffectChangeResult>;\n\tremove(target: string, instance: string): Promise<EffectChangeResult>;\n\t/** Editor-specific effect tools (transitions, effect clips, effect layers, keyframes). */\n\textraTools?: (context: EffectToolContext) => AgentTool[];\n\t/** Lets the tool list follow the provider and read-only changes. */\n\tsubscribe?: (notify: () => void) => () => void;\n}\n\n/** Shared pieces for `extraTools`. */\nexport interface EffectToolContext {\n\t/** The provider, or a thrown error saying none is registered. */\n\trequireProvider(): EffectProvider;\n\t/** The schema of a `values` argument. */\n\tvaluesSchema(what: string, keyframes?: boolean): JsonSchema;\n\t/** The schema of an `effect` argument for effects with one of `uses`. */\n\teffectIdSchema(uses: readonly EffectUse[]): JsonSchema;\n\treadonly annotations: typeof ANNOTATIONS;\n}\n\nconst ANNOTATIONS = {\n\tread: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },\n\twrite: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },\n\twriteIdempotent: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },\n\tdestructive: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false }\n} as const;\n\nconst NO_PROVIDER = 'No effects provider is registered with this editor, so there are no effects to search, describe or apply. The host app must register one (setEffectsProvider); effects already in the document are kept and shown as placeholders.';\n\nconst object = (properties: Record<string, JsonSchema>, required: string[] = []): JsonSchema & { type: 'object' } => ({\n\ttype: 'object',\n\tproperties,\n\t...(required.length ? { required } : {}),\n\tadditionalProperties: false\n});\n\n/** The catalog fetched once per provider, so tool schemas can list effect ids. */\ninterface Catalog {\n\tprovider: EffectProvider;\n\teffects: readonly EffectSummary[] | null;\n}\n\n/** Most effect ids listed in an `effect` argument's enum; larger catalogs are searched instead. */\nconst ENUM_LIMIT = 60;\n\nconst summaryOut = (e: EffectSummary) => ({\n\tid: e.id,\n\tname: e.name,\n\tkind: e.kind,\n\tcategory: e.category,\n\tuses: e.uses,\n\t...(e.description ? { description: e.description } : {}),\n\ttransparent: e.transparent,\n\tloop: e.loop,\n\t...(e.duration !== undefined ? { duration: e.duration } : {})\n});\n\n/** The agent tools for provider effects in one editor (see the module comment). */\nexport function createEffectToolProvider(host: EffectToolHost): AgentToolProvider {\n\tlet catalog: Catalog | null = null;\n\tconst listeners = new Set<() => void>();\n\tconst notify = () => listeners.forEach((l) => l());\n\n\t/** Fetches the catalog of a new provider in the background; the tool list changes when it lands. */\n\tconst catalogFor = (provider: EffectProvider | null): readonly EffectSummary[] | null => {\n\t\tif (!provider) return null;\n\t\tif (catalog?.provider !== provider) {\n\t\t\tconst entry: Catalog = { provider, effects: null };\n\t\t\tcatalog = entry;\n\t\t\tPromise.resolve()\n\t\t\t\t.then(() => provider.list())\n\t\t\t\t.then((effects) => {\n\t\t\t\t\tif (catalog === entry) {\n\t\t\t\t\t\tentry.effects = effects;\n\t\t\t\t\t\tnotify();\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.catch(() => {});\n\t\t}\n\t\treturn catalog.effects;\n\t};\n\n\tconst requireProvider = (): EffectProvider => {\n\t\tconst p = host.provider();\n\t\tif (!p) throw new Error(NO_PROVIDER);\n\t\treturn p;\n\t};\n\tconst writable = () => {\n\t\tconst reason = host.readOnlyReason();\n\t\tif (reason) throw new Error(reason);\n\t\treturn requireProvider();\n\t};\n\t/** Turns provider errors into messages a model can act on. */\n\tconst explain = async <T>(run: () => Promise<T>): Promise<T> => {\n\t\ttry {\n\t\t\treturn await run();\n\t\t} catch (error) {\n\t\t\tif (isEffectError(error)) throw new Error(error.message);\n\t\t\tthrow error;\n\t\t}\n\t};\n\n\tconst valuesSchema = (what: string, keyframes = false): JsonSchema => ({\n\t\ttype: 'object',\n\t\tdescription: `${what}: control name → value, as listed by describe_effect (its \"controls\" schema: types, ranges, units and defaults). Only the given controls change; colours are \"#rrggbb\".${keyframes ? ' A number control may instead be keyframes { keys: [{ t: ms from the start, v, ease }] }.' : ''} Unknown controls and out-of-range values are refused with the valid ones.`\n\t});\n\tconst effectIdSchema = (uses: readonly EffectUse[]): JsonSchema => {\n\t\tconst effects = catalogFor(host.provider())?.filter((e) => e.kind !== 'motion' && e.uses.some((u) => uses.includes(u)));\n\t\tconst base = `An effect id from search_effects (use ${uses.map((u) => `\"${u}\"`).join(' or ')}).`;\n\t\treturn effects && effects.length && effects.length <= ENUM_LIMIT\n\t\t\t? { type: 'string', enum: effects.map((e) => e.id), description: `${base} One of: ${effects.map((e) => `${e.id} (${e.name})`).join(', ')}.` }\n\t\t\t: { type: 'string', minLength: 1, description: base };\n\t};\n\tconst context: EffectToolContext = { requireProvider: writable, valuesSchema, effectIdSchema, annotations: ANNOTATIONS };\n\n\tconst TARGET = { type: 'string', minLength: 1, description: host.target.id } as const;\n\tconst INSTANCE = { type: 'string', minLength: 1, description: `The effect's id on the ${host.target.noun}, from list_applied_effects or apply_effect.` } as const;\n\tconst INDEX = { type: 'integer', minimum: 0, description: `Place in the ${host.target.noun}'s effect stack: 0 is applied first (default: the end, applied last).` } as const;\n\tconst OPACITY = { type: 'number', minimum: 0, maximum: 1, description: 'How much of the effect shows over its input, 0–1 (default 1).' } as const;\n\tconst ENABLED = { type: 'boolean', description: 'false turns the effect off but keeps it (default true).' } as const;\n\n\tconst readTools = (): AgentTool[] => [\n\t\t{\n\t\t\tname: 'search_effects',\n\t\t\ttitle: 'Search effects',\n\t\t\tdescription: `Searches the effects provider's catalog. Every word of query must appear in an effect's id, name, category, tags or description; filter by kind (shader, vector, motion), category or use (${EFFECT_USES.join(', ')}). For this editor, apply_effect takes uses ${host.applyUses.join(' or ')}. Returns { provider, effects: [{ id, name, kind, category, uses, description, transparent, loop, duration (ms) }], total }. With no provider registered it returns available: false and the reason. Call describe_effect next for an effect's controls.`,\n\t\t\tinputSchema: object({\n\t\t\t\tquery: { type: 'string', description: 'Words to match (default: every effect).' },\n\t\t\t\tkind: { type: 'string', enum: [...EFFECT_KINDS], description: 'shader (pixels), vector (animated SVG) or motion (animates vector art).' },\n\t\t\t\tcategory: { type: 'string', minLength: 1, description: 'The provider\\'s category, e.g. \"gradient\", \"light\", \"transition\".' },\n\t\t\t\tuse: { type: 'string', enum: [...EFFECT_USES], description: 'What the effect is for: filter changes a picture, transition blends two, generator draws a background, overlay draws over content, title draws a title, motion animates vector art, interactive reacts to input.' },\n\t\t\t\tlimit: { type: 'integer', minimum: 1, maximum: 200, description: 'Most effects to return (default 20).' }\n\t\t\t}),\n\t\t\tannotations: { title: 'Search effects', ...ANNOTATIONS.read },\n\t\t\thandler: async (args) => {\n\t\t\t\tconst p = host.provider();\n\t\t\t\tif (!p) return { available: false, reason: NO_PROVIDER, effects: [], total: 0 };\n\t\t\t\tconst found = await explain(async () => p.search((args.query as string | undefined) ?? '', { kind: args.kind, category: args.category, use: args.use }));\n\t\t\t\tconst limit = (args.limit as number | undefined) ?? 20;\n\t\t\t\treturn { available: true, provider: { id: p.id, name: p.name, capabilities: p.capabilities }, effects: found.slice(0, limit).map(summaryOut), total: found.length };\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname: 'describe_effect',\n\t\t\ttitle: 'Describe an effect',\n\t\t\tdescription: 'Returns one effect\\'s controls as a strict JSON Schema (each control described, with its type, range and units), its defaults, presets (named sets of values) and inputs, plus its summary. Use the control names and ranges for apply_effect and update_effect values. With no provider registered it returns available: false and the reason.',\n\t\t\tinputSchema: object({ effect: { type: 'string', minLength: 1, description: 'An effect id from search_effects or list_applied_effects.' } }, ['effect']),\n\t\t\tannotations: { title: 'Describe an effect', ...ANNOTATIONS.read },\n\t\t\thandler: async (args) => {\n\t\t\t\tconst p = host.provider();\n\t\t\t\tif (!p) return { available: false, reason: NO_PROVIDER };\n\t\t\t\tconst d: EffectDescription = await explain(async () => p.describe(args.effect as string));\n\t\t\t\treturn { available: true, ...summaryOut(d), controls: d.controls, defaults: d.defaults, presets: d.presets, inputs: d.inputs, appliesHere: d.kind !== 'motion' && d.uses.some((u) => host.applyUses.includes(u)) };\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname: 'list_applied_effects',\n\t\t\ttitle: 'List applied effects',\n\t\t\tdescription: `Lists the effects in the document: for each ${host.target.noun} that has any (or the one given), its effects in order with id, effect id, name, role, enabled, opacity and saved values. available is false for an effect the current provider does not have (or when none is registered): it is kept and drawn as a placeholder, and can still be removed. Works without a provider.`,\n\t\t\tinputSchema: object({ target: { ...TARGET, description: `${host.target.id} Leave out to list every ${host.target.noun} with effects.` } }),\n\t\t\tannotations: { title: 'List applied effects', ...ANNOTATIONS.read },\n\t\t\thandler: async (args) => {\n\t\t\t\tconst p = host.provider();\n\t\t\t\tconst known = new Set((p ? await explain(async () => p.list()) : []).map((e) => e.id));\n\t\t\t\tconst targets = host.list(args.target as string | undefined).map((t) => ({ ...t, effects: t.effects.map((e) => ({ ...e, available: known.has(e.effect) })) }));\n\t\t\t\treturn { provider: p ? { id: p.id, name: p.name } : null, ...(p ? {} : { reason: NO_PROVIDER }), targets };\n\t\t\t}\n\t\t}\n\t];\n\n\tconst writeTools = (): AgentTool[] => [\n\t\t{\n\t\t\tname: 'apply_effect',\n\t\t\ttitle: 'Apply an effect',\n\t\t\tdescription: `Adds a provider effect to a ${host.target.noun}. ${host.applyDetails} values are checked against describe_effect's controls first; nothing changes if any is wrong. One undo step. Returns the effect with its new id (for update_effect and remove_effect) and the ${host.target.noun}'s effects. Refused when no provider is registered.`,\n\t\t\tinputSchema: object(\n\t\t\t\t{\n\t\t\t\t\ttarget: TARGET,\n\t\t\t\t\teffect: effectIdSchema(host.applyUses),\n\t\t\t\t\tvalues: valuesSchema('Control values over the effect\\'s defaults', true),\n\t\t\t\t\tindex: INDEX,\n\t\t\t\t\tenabled: ENABLED,\n\t\t\t\t\topacity: OPACITY\n\t\t\t\t},\n\t\t\t\t['target', 'effect']\n\t\t\t),\n\t\t\tannotations: { title: 'Apply an effect', ...ANNOTATIONS.write },\n\t\t\thandler: async (args) => {\n\t\t\t\twritable();\n\t\t\t\treturn explain(() => host.apply(args.target as string, args.effect as string, { values: args.values, index: args.index, enabled: args.enabled, opacity: args.opacity }));\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname: 'update_effect',\n\t\t\ttitle: 'Change an applied effect',\n\t\t\tdescription: `Changes one applied effect on a ${host.target.noun}: its values (merged over the current ones; null resets a control to its default), enabled, opacity or place in the stack. Values are checked against describe_effect's controls first. One undo step. Returns the effect as it is now and the ${host.target.noun}'s effects. Refused when no provider is registered.`,\n\t\t\tinputSchema: object(\n\t\t\t\t{\n\t\t\t\t\ttarget: TARGET,\n\t\t\t\t\teffect: INSTANCE,\n\t\t\t\t\tvalues: { ...valuesSchema('Control values to change', true), description: `${valuesSchema('Control values to change', true).description} null resets a control to its default.` },\n\t\t\t\t\tenabled: ENABLED,\n\t\t\t\t\topacity: OPACITY,\n\t\t\t\t\tindex: { ...INDEX, description: `Move it to this place in the ${host.target.noun}'s stack (0 = applied first).` }\n\t\t\t\t},\n\t\t\t\t['target', 'effect']\n\t\t\t),\n\t\t\tannotations: { title: 'Change an applied effect', ...ANNOTATIONS.writeIdempotent },\n\t\t\thandler: async (args) => {\n\t\t\t\twritable();\n\t\t\t\tif (args.values === undefined && args.enabled === undefined && args.opacity === undefined && args.index === undefined) throw new Error('Give at least one of values, enabled, opacity or index to change.');\n\t\t\t\treturn explain(() => host.update(args.target as string, args.effect as string, { values: args.values, enabled: args.enabled, opacity: args.opacity, index: args.index }));\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tname: 'remove_effect',\n\t\t\ttitle: 'Remove an applied effect',\n\t\t\tdescription: `Removes one applied effect from a ${host.target.noun} (an effect the provider no longer has included). One undo step. Returns what was removed and the ${host.target.noun}'s remaining effects. Refused when no provider is registered.`,\n\t\t\tinputSchema: object({ target: TARGET, effect: INSTANCE }, ['target', 'effect']),\n\t\t\tannotations: { title: 'Remove an applied effect', ...ANNOTATIONS.destructive },\n\t\t\thandler: async (args) => {\n\t\t\t\twritable();\n\t\t\t\treturn explain(() => host.remove(args.target as string, args.effect as string));\n\t\t\t}\n\t\t}\n\t];\n\n\treturn {\n\t\tid: host.id,\n\t\t...(host.namespace ? { namespace: host.namespace } : {}),\n\t\ttools: () => {\n\t\t\tconst extra = host.extraTools?.(context) ?? [];\n\t\t\tif (host.readOnlyReason()) return [...readTools(), ...extra.filter((t) => t.annotations?.readOnlyHint)];\n\t\t\treturn [...readTools(), ...writeTools(), ...extra];\n\t\t},\n\t\tsubscribe: (l) => {\n\t\t\tlisteners.add(l);\n\t\t\tconst off = host.subscribe?.(l);\n\t\t\treturn () => {\n\t\t\t\tlisteners.delete(l);\n\t\t\t\toff?.();\n\t\t\t};\n\t\t}\n\t};\n}\n"],"mappings":";;;;;AA4BO,IAAM,eAAsC,CAAC,UAAU,UAAU,QAAQ;AACzE,IAAM,cAAoC,CAAC,UAAU,cAAc,aAAa,WAAW,SAAS,UAAU,aAAa;;;AC4DlI,IAAM,cAAc;AAAA,EACnB,MAAM,EAAE,cAAc,MAAM,iBAAiB,OAAO,gBAAgB,MAAM,eAAe,MAAM;AAAA,EAC/F,OAAO,EAAE,cAAc,OAAO,iBAAiB,OAAO,gBAAgB,OAAO,eAAe,MAAM;AAAA,EAClG,iBAAiB,EAAE,cAAc,OAAO,iBAAiB,OAAO,gBAAgB,MAAM,eAAe,MAAM;AAAA,EAC3G,aAAa,EAAE,cAAc,OAAO,iBAAiB,MAAM,gBAAgB,OAAO,eAAe,MAAM;AACxG;AAEA,IAAM,cAAc;AAEpB,IAAM,SAAS,CAAC,YAAwC,WAAqB,CAA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AG,GAAG,MAAM,OAAO,CAAC,MAAM,EAAE,aAAa,YAAY,CAAC;AACtG,aAAO,CAAC,GAAG,UAAU,GAAG,GAAG,WAAW,GAAG,GAAG,KAAK;AAAA,IAClD;AAAA,IACA,WAAW,CAAC,MAAM;AACjB,gBAAU,IAAI,CAAC;AACf,YAAM,MAAM,KAAK,YAAY,CAAC;AAC9B,aAAO,MAAM;AACZ,kBAAU,OAAO,CAAC;AAClB,cAAM;AAAA,MACP;AAAA,IACD;AAAA,EACD;AACD;","names":[]}
|
|
@@ -4661,6 +4661,15 @@ var fail4 = (message) => {
|
|
|
4661
4661
|
throw new LayerOperationError(message);
|
|
4662
4662
|
};
|
|
4663
4663
|
var SMART_RENDER_MARGIN = MAX_EFFECT_REACH;
|
|
4664
|
+
var incompleteSurfaces = /* @__PURE__ */ new WeakSet();
|
|
4665
|
+
var isSmartSurfaceIncomplete = (surface) => incompleteSurfaces.has(surface);
|
|
4666
|
+
var surfaceIds = /* @__PURE__ */ new WeakMap();
|
|
4667
|
+
var nextSurfaceId = 0;
|
|
4668
|
+
var surfaceId = (s) => {
|
|
4669
|
+
let id = surfaceIds.get(s);
|
|
4670
|
+
if (id === void 0) surfaceIds.set(s, id = ++nextSurfaceId);
|
|
4671
|
+
return id;
|
|
4672
|
+
};
|
|
4664
4673
|
function newContentsId() {
|
|
4665
4674
|
return newLayerId("so");
|
|
4666
4675
|
}
|
|
@@ -4802,7 +4811,15 @@ function placeContents(layer, canvas, options = {}) {
|
|
|
4802
4811
|
}
|
|
4803
4812
|
function activeSmartFilters(stack) {
|
|
4804
4813
|
if (!stack?.enabled) return [];
|
|
4805
|
-
return stack.filters.filter((f) => f.kind !== "psd" && isActiveFilter(f) && f.opacity > 0);
|
|
4814
|
+
return stack.filters.filter((f) => f.kind !== "psd" && f.kind !== "effect" && isActiveFilter(f) && f.opacity > 0);
|
|
4815
|
+
}
|
|
4816
|
+
function activeEffectSmartFilters(stack) {
|
|
4817
|
+
if (!stack?.enabled) return [];
|
|
4818
|
+
return stack.filters.filter((f) => f.kind === "effect" && f.enabled && f.opacity > 0);
|
|
4819
|
+
}
|
|
4820
|
+
function runnableSmartFilters(stack) {
|
|
4821
|
+
if (!stack?.enabled) return [];
|
|
4822
|
+
return stack.filters.filter((f) => f.opacity > 0 && (f.kind === "effect" ? f.enabled : f.kind !== "psd" && isActiveFilter(f)));
|
|
4806
4823
|
}
|
|
4807
4824
|
function filterMaskCoverage(mask, canvas) {
|
|
4808
4825
|
if (!mask || mask.enabled === false || mask.source) return null;
|
|
@@ -4823,27 +4840,41 @@ function filterMaskCoverage(mask, canvas) {
|
|
|
4823
4840
|
return v;
|
|
4824
4841
|
}
|
|
4825
4842
|
function applySmartFilters(placed, stack, canvas) {
|
|
4826
|
-
const active =
|
|
4843
|
+
const active = runnableSmartFilters(stack);
|
|
4827
4844
|
if (!active.length || !(canvas.width > 0 && canvas.height > 0)) return placed;
|
|
4828
4845
|
const W = canvas.width;
|
|
4829
4846
|
const H = canvas.height;
|
|
4830
|
-
const
|
|
4847
|
+
const token = active.some((f) => f.kind === "effect") ? canvas.effects?.token ?? -1 : 0;
|
|
4848
|
+
const key = JSON.stringify([W, H, token, active.map((f) => ({ ...f, id: void 0 }))]);
|
|
4831
4849
|
let entry = filteredCache.get(placed);
|
|
4850
|
+
let incomplete = false;
|
|
4832
4851
|
if (!entry || entry.key !== key) {
|
|
4833
4852
|
const base = readRegion(placed, { x: 0, y: 0, width: W, height: H });
|
|
4834
4853
|
let acc = new Uint8ClampedArray(base);
|
|
4835
|
-
for (const f of active) {
|
|
4836
|
-
|
|
4837
|
-
|
|
4854
|
+
for (const [i, f] of active.entries()) {
|
|
4855
|
+
let out2;
|
|
4856
|
+
if (f.kind === "effect") {
|
|
4857
|
+
if (incomplete) continue;
|
|
4858
|
+
const inputKey = JSON.stringify([surfaceId(placed), W, H, active.slice(0, i + 1).map((x) => ({ ...x, id: void 0, blend: x === f ? void 0 : x.blend, opacity: x === f ? void 0 : x.opacity }))]);
|
|
4859
|
+
const r = canvas.effects?.resolve(f, acc, W, H, inputKey);
|
|
4860
|
+
if (!r?.result) {
|
|
4861
|
+
if (r?.pending) incomplete = true;
|
|
4862
|
+
continue;
|
|
4863
|
+
}
|
|
4864
|
+
out2 = new Uint8ClampedArray(r.result);
|
|
4865
|
+
} else {
|
|
4866
|
+
out2 = new Uint8ClampedArray(acc);
|
|
4867
|
+
runLayerFilters(out2, W, H, [f]);
|
|
4868
|
+
}
|
|
4838
4869
|
if (f.blend === "normal") {
|
|
4839
|
-
if (f.opacity >= 1) acc =
|
|
4840
|
-
else lerpInto(acc,
|
|
4870
|
+
if (f.opacity >= 1) acc = out2;
|
|
4871
|
+
else lerpInto(acc, out2, f.opacity, null);
|
|
4841
4872
|
} else {
|
|
4842
|
-
blendTile(acc,
|
|
4873
|
+
blendTile(acc, out2, f.blend, f.opacity, null);
|
|
4843
4874
|
}
|
|
4844
4875
|
}
|
|
4845
4876
|
entry = { key, base, filtered: acc };
|
|
4846
|
-
filteredCache.set(placed, entry);
|
|
4877
|
+
if (!incomplete) filteredCache.set(placed, entry);
|
|
4847
4878
|
}
|
|
4848
4879
|
const cov = filterMaskCoverage(stack.mask, canvas);
|
|
4849
4880
|
let result = entry.filtered;
|
|
@@ -4851,7 +4882,9 @@ function applySmartFilters(placed, stack, canvas) {
|
|
|
4851
4882
|
result = new Uint8ClampedArray(entry.base);
|
|
4852
4883
|
lerpInto(result, entry.filtered, 1, cov);
|
|
4853
4884
|
}
|
|
4854
|
-
|
|
4885
|
+
const out = surfaceFromPixels({ width: W, height: H, data: result }, 4, 0, 0);
|
|
4886
|
+
if (incomplete) incompleteSurfaces.add(out);
|
|
4887
|
+
return out;
|
|
4855
4888
|
}
|
|
4856
4889
|
function lerpInto(dst, src, k, coverage) {
|
|
4857
4890
|
for (let i = 0, p = 0; i < dst.length; i += 4, p++) {
|
|
@@ -4940,7 +4973,7 @@ function offsetSmartObject(layers, id, dx, dy, canvas) {
|
|
|
4940
4973
|
const moveMask = (m2) => m2 && m2.linked !== false && !m2.source ? { ...m2, surface: translateSurface(m2.surface, mx, my) } : m2;
|
|
4941
4974
|
if (layer.mask) next.mask = moveMask(layer.mask);
|
|
4942
4975
|
if (layer.smartFilters?.mask) next.smartFilters = { ...layer.smartFilters, mask: moveMask(layer.smartFilters.mask) };
|
|
4943
|
-
const spatial = activeSmartFilters(layer.smartFilters).some((f) => f.kind === "blur");
|
|
4976
|
+
const spatial = activeSmartFilters(layer.smartFilters).some((f) => f.kind === "blur") || activeEffectSmartFilters(layer.smartFilters).length > 0;
|
|
4944
4977
|
const b = contentBounds(layer.surface);
|
|
4945
4978
|
const m = SMART_RENDER_MARGIN;
|
|
4946
4979
|
const cut = b && (b.x <= -m || b.y <= -m || b.x + b.width >= canvas.width + m || b.y + b.height >= canvas.height + m);
|
|
@@ -5185,13 +5218,27 @@ function refitPlacement(layer, contents) {
|
|
|
5185
5218
|
}
|
|
5186
5219
|
function normalizeSmartFilter(raw, id = newLayerId("flt")) {
|
|
5187
5220
|
if (raw.kind === "psd") fail4("Photoshop filters can only come from a PSD; add develop or blur.");
|
|
5188
|
-
const base = normalizeFilter(raw, id);
|
|
5221
|
+
const base = raw.kind === "effect" ? normalizeEffectSmartFilter(raw, id) : normalizeFilter(raw, id);
|
|
5189
5222
|
const blend = raw.blend ?? "normal";
|
|
5190
5223
|
if (!isBlendMode(blend) || blend === "pigment") fail4(`Unknown blend mode "${String(blend)}" for a smart filter.`);
|
|
5191
5224
|
const opacity = raw.opacity ?? 1;
|
|
5192
5225
|
if (!(typeof opacity === "number" && opacity >= 0 && opacity <= 1)) fail4("opacity must be a number from 0 to 1.");
|
|
5193
5226
|
return { ...base, blend, opacity };
|
|
5194
5227
|
}
|
|
5228
|
+
function normalizeEffectSmartFilter(raw, id) {
|
|
5229
|
+
if (typeof raw.effect !== "string" || !raw.effect) fail4('An effect smart filter needs an "effect" id from search_effects.');
|
|
5230
|
+
const values = raw.values ?? {};
|
|
5231
|
+
if (typeof values !== "object" || values === null || Array.isArray(values)) fail4('"values" must be an object of control values.');
|
|
5232
|
+
return {
|
|
5233
|
+
id,
|
|
5234
|
+
kind: "effect",
|
|
5235
|
+
enabled: raw.enabled !== false,
|
|
5236
|
+
effect: raw.effect,
|
|
5237
|
+
...typeof raw.provider === "string" ? { provider: raw.provider } : {},
|
|
5238
|
+
...typeof raw.name === "string" ? { name: raw.name } : {},
|
|
5239
|
+
values: { ...values }
|
|
5240
|
+
};
|
|
5241
|
+
}
|
|
5195
5242
|
function withStack(layer, stack, canvas) {
|
|
5196
5243
|
const next = { ...layer };
|
|
5197
5244
|
if (stack && (stack.filters.length || stack.mask || !stack.enabled)) next.smartFilters = stack;
|
|
@@ -5422,6 +5469,7 @@ function serializeLayer(layer, ctx) {
|
|
|
5422
5469
|
}
|
|
5423
5470
|
if (layer.fillOpacity !== void 0 && layer.fillOpacity !== 1) out.fillOpacity = layer.fillOpacity;
|
|
5424
5471
|
if (layer.filters?.length) out.filters = JSON.parse(JSON.stringify(layer.filters));
|
|
5472
|
+
if (layer.generator) out.generator = JSON.parse(JSON.stringify(layer.generator));
|
|
5425
5473
|
if (layer.source !== "document") {
|
|
5426
5474
|
const deep = encodeDeepSurface(layer.surface);
|
|
5427
5475
|
if (deep) out.deep = deep;
|
|
@@ -5812,6 +5860,8 @@ function deserializeLayer(raw, ctx) {
|
|
|
5812
5860
|
if (typeof r.fillOpacity === "number" && r.fillOpacity !== 1) layer.fillOpacity = num2(r.fillOpacity, 0, 1, 1);
|
|
5813
5861
|
const filters = readFilters(r.filters);
|
|
5814
5862
|
if (filters) layer.filters = filters;
|
|
5863
|
+
const generator = readEffectRef(r.generator);
|
|
5864
|
+
if (generator) layer.generator = { ...generator, ...typeof r.generator.time === "number" && r.generator.time > 0 ? { time: r.generator.time } : {} };
|
|
5815
5865
|
return layer;
|
|
5816
5866
|
}
|
|
5817
5867
|
case "adjustment": {
|
|
@@ -5898,6 +5948,15 @@ function readContents(id, ctx) {
|
|
|
5898
5948
|
memo.set(id, c);
|
|
5899
5949
|
return c;
|
|
5900
5950
|
}
|
|
5951
|
+
var isEffectValue = (x) => typeof x === "string" || typeof x === "boolean" || typeof x === "number" && Number.isFinite(x) || Array.isArray(x) && x.every((n) => typeof n === "number" && Number.isFinite(n));
|
|
5952
|
+
function readEffectRef(raw) {
|
|
5953
|
+
if (!raw || typeof raw !== "object" || typeof raw.effect !== "string" || !raw.effect) return void 0;
|
|
5954
|
+
const values = {};
|
|
5955
|
+
if (raw.values && typeof raw.values === "object") {
|
|
5956
|
+
for (const [k, v] of Object.entries(raw.values)) if (isEffectValue(v)) values[k] = Array.isArray(v) ? [...v] : v;
|
|
5957
|
+
}
|
|
5958
|
+
return { effect: raw.effect, ...typeof raw.provider === "string" ? { provider: raw.provider } : {}, ...typeof raw.name === "string" ? { name: raw.name } : {}, values };
|
|
5959
|
+
}
|
|
5901
5960
|
function readSmartFilters(raw, ctx, what) {
|
|
5902
5961
|
if (!raw || typeof raw !== "object") return void 0;
|
|
5903
5962
|
const r = raw;
|
|
@@ -5918,6 +5977,10 @@ function readSmartFilters(raw, ctx, what) {
|
|
|
5918
5977
|
} else if (f.kind === "develop" || f.kind === "blur") {
|
|
5919
5978
|
const base = plain[k++];
|
|
5920
5979
|
if (base) filters.push({ ...base, blend, opacity });
|
|
5980
|
+
} else if (f.kind === "effect") {
|
|
5981
|
+
const ref = readEffectRef(f);
|
|
5982
|
+
if (ref) filters.push({ id: typeof f.id === "string" ? f.id : newLayerId("flt"), kind: "effect", enabled: f.enabled !== false, ...ref, blend, opacity });
|
|
5983
|
+
else ctx.problems.push(`${what}: an effect smart filter without an effect id was left out`);
|
|
5921
5984
|
}
|
|
5922
5985
|
}
|
|
5923
5986
|
const stack = { enabled: r.enabled !== false, filters };
|
|
@@ -11594,6 +11657,7 @@ export {
|
|
|
11594
11657
|
isValidWarp,
|
|
11595
11658
|
geometryHomography,
|
|
11596
11659
|
SMART_RENDER_MARGIN,
|
|
11660
|
+
isSmartSurfaceIncomplete,
|
|
11597
11661
|
newContentsId,
|
|
11598
11662
|
contentsBox,
|
|
11599
11663
|
placementGeometry,
|
|
@@ -11605,6 +11669,7 @@ export {
|
|
|
11605
11669
|
documentContents,
|
|
11606
11670
|
placeContents,
|
|
11607
11671
|
activeSmartFilters,
|
|
11672
|
+
activeEffectSmartFilters,
|
|
11608
11673
|
filterMaskCoverage,
|
|
11609
11674
|
applySmartFilters,
|
|
11610
11675
|
renderSmartObject,
|
|
@@ -11671,4 +11736,4 @@ export {
|
|
|
11671
11736
|
smartContentsFile,
|
|
11672
11737
|
exportPsd
|
|
11673
11738
|
};
|
|
11674
|
-
//# sourceMappingURL=chunk-
|
|
11739
|
+
//# sourceMappingURL=chunk-WATAQ2Z2.js.map
|