@weasel-js/diagram 1.11.0 → 1.11.1
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/README.md +696 -4
- package/dist/chunk-43LDZ6L4.js +2053 -0
- package/dist/chunk-43LDZ6L4.js.map +1 -0
- package/dist/chunk-CI3I3I6T.js +3600 -0
- package/dist/chunk-CI3I3I6T.js.map +1 -0
- package/dist/{chunk-NUMMW5BI.js → chunk-IM6DHWZO.js} +388 -33
- package/dist/chunk-IM6DHWZO.js.map +1 -0
- package/dist/chunk-QKSWZEJH.js +312 -0
- package/dist/chunk-QKSWZEJH.js.map +1 -0
- package/dist/chunk-T6DQT553.js +1431 -0
- package/dist/chunk-T6DQT553.js.map +1 -0
- package/dist/chunk-WDIE35AK.js +3 -0
- package/dist/chunk-WDIE35AK.js.map +1 -0
- package/dist/{fromData-GKqRgPFs.d.ts → dataTypes-B-iEwKZp.d.ts} +229 -55
- package/dist/effect-audio.d.ts +138 -0
- package/dist/effect-audio.js +527 -0
- package/dist/effect-audio.js.map +1 -0
- package/dist/effect.d.ts +486 -121
- package/dist/effect.js +1599 -340
- package/dist/effect.js.map +1 -1
- package/dist/icons.table.d.ts +6 -0
- package/dist/icons.table.js +32 -0
- package/dist/icons.table.js.map +1 -0
- package/dist/icons.table.json +24 -0
- package/dist/index.d.ts +2149 -88
- package/dist/index.js +1056 -2
- package/dist/index.js.map +1 -1
- package/dist/layout.d.ts +3 -3
- package/dist/{layout.entry-BoWFcR4G.d.ts → layout.entry-CH9gc0CY.d.ts} +230 -3
- package/dist/layout.js +3 -1
- package/dist/stageTypes-DvnR8cKQ.d.ts +189 -0
- package/dist/{body-2lC7IiIA.d.ts → types-BbHunLXm.d.ts} +147 -7
- package/package.json +28 -7
- package/dist/chunk-C4NAI6NV.js +0 -2041
- package/dist/chunk-C4NAI6NV.js.map +0 -1
- package/dist/chunk-NUMMW5BI.js.map +0 -1
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { DIAGRAM_THEMES, edgeIdOf } from './chunk-43LDZ6L4.js';
|
|
2
|
+
|
|
3
|
+
// src/effect/check.ts
|
|
4
|
+
function splitProblem(stage) {
|
|
5
|
+
const split = stage.split;
|
|
6
|
+
if (split === void 0) return null;
|
|
7
|
+
if (!(stage.inputs ?? []).some((p) => p.id === split.input)) return `splits on "${split.input}", which is not one of its inputs`;
|
|
8
|
+
if (split.at.length === 0) return "splits with no cuts";
|
|
9
|
+
if (!split.at.every(Number.isFinite)) return "has a cut that is not a finite number";
|
|
10
|
+
if (split.at.some((cut, i) => i > 0 && cut <= split.at[i - 1])) return "has cuts that are not in ascending order";
|
|
11
|
+
const exits = (stage.outputs ?? []).length;
|
|
12
|
+
if (exits !== split.at.length + 1) return `has ${split.at.length} cuts and ${exits} outputs; it needs ${split.at.length + 1}`;
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
function checkPipeline(pipeline) {
|
|
16
|
+
const out = [];
|
|
17
|
+
const stages = /* @__PURE__ */ new Map();
|
|
18
|
+
for (const stage of pipeline.stages) {
|
|
19
|
+
if (stages.has(stage.id)) {
|
|
20
|
+
out.push({ kind: "duplicate-stage", stage: stage.id, message: `Stage "${stage.id}" appears more than once.` });
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
stages.set(stage.id, stage);
|
|
24
|
+
const seen = /* @__PURE__ */ new Set();
|
|
25
|
+
for (const port of [...stage.inputs ?? [], ...stage.outputs ?? []]) {
|
|
26
|
+
if (seen.has(port.id)) {
|
|
27
|
+
out.push({ kind: "duplicate-port", stage: stage.id, port: port.id, message: `Stage "${stage.id}" has two ports called "${port.id}".` });
|
|
28
|
+
}
|
|
29
|
+
seen.add(port.id);
|
|
30
|
+
}
|
|
31
|
+
const split = splitProblem(stage);
|
|
32
|
+
if (split !== null) out.push({ kind: "bad-split", stage: stage.id, message: `Stage "${stage.id}" ${split}.` });
|
|
33
|
+
}
|
|
34
|
+
pipeline.wires.forEach((wire, index) => {
|
|
35
|
+
const ends = [["from", "outputs", "inputs"], ["to", "inputs", "outputs"]].map(([end, own, other]) => {
|
|
36
|
+
const ref = wire[end];
|
|
37
|
+
const stage = stages.get(ref.stage);
|
|
38
|
+
if (stage === void 0) {
|
|
39
|
+
out.push({ kind: "missing-stage", wire: index, stage: ref.stage, message: `Wire ${index} names stage "${ref.stage}", which does not exist.` });
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const port = (stage[own] ?? []).find((p) => p.id === ref.port);
|
|
43
|
+
if (port !== void 0) return port;
|
|
44
|
+
const wrong = (stage[other] ?? []).some((p) => p.id === ref.port);
|
|
45
|
+
out.push(wrong ? { kind: "wrong-direction", wire: index, stage: ref.stage, port: ref.port, message: `Wire ${index} ${end === "from" ? "starts at an input" : "ends at an output"}, "${ref.stage}.${ref.port}".` } : { kind: "missing-port", wire: index, stage: ref.stage, port: ref.port, message: `Wire ${index} names port "${ref.stage}.${ref.port}", which does not exist.` });
|
|
46
|
+
return null;
|
|
47
|
+
});
|
|
48
|
+
const [from, to] = ends;
|
|
49
|
+
if (from && to && from.type !== to.type) {
|
|
50
|
+
out.push({ kind: "type-mismatch", wire: index, message: `Wire ${index} joins a "${from.type}" output to a "${to.type}" input.` });
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
const groupIds = /* @__PURE__ */ new Set();
|
|
54
|
+
const groups = (pipeline.groups ?? []).filter((group) => {
|
|
55
|
+
const repeat = groupIds.has(group.id);
|
|
56
|
+
if (repeat || stages.has(group.id)) {
|
|
57
|
+
out.push({
|
|
58
|
+
kind: "duplicate-group",
|
|
59
|
+
group: group.id,
|
|
60
|
+
message: repeat ? `Group "${group.id}" appears more than once.` : `Group "${group.id}" has the id of a stage.`
|
|
61
|
+
});
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
groupIds.add(group.id);
|
|
65
|
+
return true;
|
|
66
|
+
});
|
|
67
|
+
for (const group of groups) {
|
|
68
|
+
for (const member of group.members) {
|
|
69
|
+
if (stages.has(member) || groupIds.has(member)) continue;
|
|
70
|
+
out.push({ kind: "missing-member", group: group.id, message: `Group "${group.id}" names "${member}", which is neither a stage nor a group.` });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// src/effect/stageTypes.ts
|
|
77
|
+
function stageFromType(t, id) {
|
|
78
|
+
const stage = { id, title: t.title, type: t.type };
|
|
79
|
+
if (t.kind !== void 0) stage.kind = t.kind;
|
|
80
|
+
if (t.inputs) stage.inputs = t.inputs.map((p) => ({ ...p }));
|
|
81
|
+
if (t.outputs) stage.outputs = t.outputs.map((p) => ({ ...p }));
|
|
82
|
+
if (t.params) stage.params = t.params.map((p) => ({ ...p, ...p.control ? { control: structuredClone(p.control) } : {} }));
|
|
83
|
+
return stage;
|
|
84
|
+
}
|
|
85
|
+
function stepPlaces(step) {
|
|
86
|
+
const text = String(step);
|
|
87
|
+
if (text.includes("e")) return Math.min(20, Math.max(0, -Math.floor(Math.log10(step))));
|
|
88
|
+
const dot = text.indexOf(".");
|
|
89
|
+
return dot === -1 ? 0 : text.length - dot - 1;
|
|
90
|
+
}
|
|
91
|
+
function formatParam(control) {
|
|
92
|
+
switch (control.kind) {
|
|
93
|
+
case "number": {
|
|
94
|
+
const n = control.value.toFixed(control.step === void 0 ? 1 : stepPlaces(control.step)).replace(/^-(?=[0.]*$)/, "");
|
|
95
|
+
return control.unit ? `${n} ${control.unit}` : n;
|
|
96
|
+
}
|
|
97
|
+
case "enum":
|
|
98
|
+
return control.options.find((x) => x.value === control.value)?.label ?? control.value;
|
|
99
|
+
case "boolean":
|
|
100
|
+
return control.value ? "on" : "off";
|
|
101
|
+
case "string":
|
|
102
|
+
return control.value;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/effect/draw.ts
|
|
107
|
+
var LOOK_THEME = DIAGRAM_THEMES.night;
|
|
108
|
+
var UNTYPED = "#8aa2b5";
|
|
109
|
+
var PROBLEM_COLOR = "#ff5d5d";
|
|
110
|
+
var BYPASSED_DASH = [4, 3];
|
|
111
|
+
function typeColors(pipeline, given = {}, series = LOOK_THEME.series) {
|
|
112
|
+
const colors = /* @__PURE__ */ new Map();
|
|
113
|
+
for (const stage of pipeline.stages) {
|
|
114
|
+
for (const port of [...stage.inputs ?? [], ...stage.outputs ?? []]) {
|
|
115
|
+
if (colors.has(port.type)) continue;
|
|
116
|
+
colors.set(port.type, given[port.type] ?? series[colors.size % series.length]);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return (type) => type === void 0 ? UNTYPED : colors.get(type) ?? given[type] ?? UNTYPED;
|
|
120
|
+
}
|
|
121
|
+
function isControl(pipeline, type) {
|
|
122
|
+
return type !== void 0 && pipeline.types?.[type]?.control === true;
|
|
123
|
+
}
|
|
124
|
+
function stageStyle(stage, theme = LOOK_THEME) {
|
|
125
|
+
const { roles, defaultRole } = theme;
|
|
126
|
+
return stage.bypassed === true ? { ...roles.muted ?? roles[defaultRole], dash: BYPASSED_DASH } : roles[defaultRole];
|
|
127
|
+
}
|
|
128
|
+
function wireStyle(color, control, problem) {
|
|
129
|
+
return {
|
|
130
|
+
stroke: problem ? PROBLEM_COLOR : color,
|
|
131
|
+
width: 2,
|
|
132
|
+
markerEnd: null,
|
|
133
|
+
...control ? { dash: [5, 4] } : {}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function uniqueStages(pipeline) {
|
|
137
|
+
const seen = /* @__PURE__ */ new Set();
|
|
138
|
+
return pipeline.stages.filter((s) => seen.has(s.id) ? false : (seen.add(s.id), true));
|
|
139
|
+
}
|
|
140
|
+
function uniqueGroups(pipeline) {
|
|
141
|
+
const seen = new Set(pipeline.stages.map((s) => s.id));
|
|
142
|
+
return (pipeline.groups ?? []).filter((g) => seen.has(g.id) ? false : (seen.add(g.id), true));
|
|
143
|
+
}
|
|
144
|
+
function portOn(stage, id) {
|
|
145
|
+
return [...stage?.inputs ?? [], ...stage?.outputs ?? []].find((p) => p.id === id);
|
|
146
|
+
}
|
|
147
|
+
function kindOf(stage) {
|
|
148
|
+
return stage.kind === "decision" || stage.kind === "source" || stage.kind === "sink" ? stage.kind : "stage";
|
|
149
|
+
}
|
|
150
|
+
function drawableWires(pipeline) {
|
|
151
|
+
const stages = new Map(uniqueStages(pipeline).map((s) => [s.id, s]));
|
|
152
|
+
const flagged = new Set(checkPipeline(pipeline).flatMap((p) => p.wire === void 0 ? [] : [p.wire]));
|
|
153
|
+
return pipeline.wires.flatMap((wire, index) => {
|
|
154
|
+
const fromStage = stages.get(wire.from.stage);
|
|
155
|
+
const toStage = stages.get(wire.to.stage);
|
|
156
|
+
const from = portOn(fromStage, wire.from.port);
|
|
157
|
+
if (fromStage === void 0 || toStage === void 0 || from === void 0 || portOn(toStage, wire.to.port) === void 0) return [];
|
|
158
|
+
return [{ wire, index, type: from.type, problem: flagged.has(index), fromStage, toStage }];
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
var NO_VALUE = "\u2013";
|
|
162
|
+
var VALUE_ROOM = "00000.000";
|
|
163
|
+
function shownPorts(stage) {
|
|
164
|
+
return (stage.outputs?.length ?? 0) > 0 ? stage.outputs : stage.inputs ?? [];
|
|
165
|
+
}
|
|
166
|
+
var valueRowId = (port) => `value:${port}`;
|
|
167
|
+
var previewRowId = (port) => `preview:${port}`;
|
|
168
|
+
var PREVIEW_SIZE = 48;
|
|
169
|
+
var PREVIEW_DENSITY = 2;
|
|
170
|
+
function runRowsOf(o) {
|
|
171
|
+
return {
|
|
172
|
+
...o.showValues !== void 0 ? { showValues: o.showValues } : {},
|
|
173
|
+
...o.showPreviews !== void 0 ? { showPreviews: o.showPreviews } : {},
|
|
174
|
+
...o.previewSize !== void 0 ? { previewSize: o.previewSize } : {}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function stageRows(stage, opts) {
|
|
178
|
+
const rows = [{ kind: "label", text: stage.title, style: { bold: true } }];
|
|
179
|
+
const side = (ports) => (ports ?? []).map((p) => ({ id: p.id, label: p.label ?? p.id, type: p.type }));
|
|
180
|
+
if (opts.withPorts && ((stage.inputs?.length ?? 0) > 0 || (stage.outputs?.length ?? 0) > 0)) {
|
|
181
|
+
rows.push({ kind: "ports", left: side(stage.inputs), right: side(stage.outputs) });
|
|
182
|
+
}
|
|
183
|
+
const size = opts.previewSize ?? PREVIEW_SIZE;
|
|
184
|
+
const preview = typeof size === "number" ? { width: size, height: size } : size;
|
|
185
|
+
const seen = /* @__PURE__ */ new Set();
|
|
186
|
+
for (const p of shownPorts(stage)) {
|
|
187
|
+
if (seen.has(p.id)) continue;
|
|
188
|
+
seen.add(p.id);
|
|
189
|
+
if (opts.showValues === true) {
|
|
190
|
+
rows.push({ kind: "field", id: valueRowId(p.id), label: p.label ?? p.id, value: NO_VALUE, room: VALUE_ROOM });
|
|
191
|
+
}
|
|
192
|
+
if (opts.showPreviews === true) rows.push({ kind: "slot", id: previewRowId(p.id), ...preview });
|
|
193
|
+
}
|
|
194
|
+
if (opts.showParams) for (const p of stage.params ?? []) rows.push({ kind: "field", label: p.label, value: p.control ? formatParam(p.control) : p.value });
|
|
195
|
+
return rows;
|
|
196
|
+
}
|
|
197
|
+
function exitLabel(d) {
|
|
198
|
+
if (d.wire.label !== void 0) return d.wire.label;
|
|
199
|
+
return kindOf(d.fromStage) === "decision" ? portOn(d.fromStage, d.wire.from.port)?.label ?? d.wire.from.port : void 0;
|
|
200
|
+
}
|
|
201
|
+
function boxNode(stage, opts) {
|
|
202
|
+
return {
|
|
203
|
+
id: stage.id,
|
|
204
|
+
outline: kindOf(stage) === "stage" ? "rect" : "stadium",
|
|
205
|
+
rows: stageRows(stage, { showParams: opts.showParams, withPorts: opts.rowPorts, ...runRowsOf(opts.run ?? {}) }),
|
|
206
|
+
// Always set: left off, a stage port named n, e, s or w would share its id with a compass default.
|
|
207
|
+
ports: opts.ports
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function wireEdge(from, to, label, id) {
|
|
211
|
+
return {
|
|
212
|
+
...id !== void 0 ? { id } : {},
|
|
213
|
+
from: from.stage,
|
|
214
|
+
fromPort: from.port,
|
|
215
|
+
to: to.stage,
|
|
216
|
+
toPort: to.port,
|
|
217
|
+
...label !== void 0 ? { label } : {}
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function wireEdges(pipeline, color) {
|
|
221
|
+
return drawableWires(pipeline).map((d) => ({
|
|
222
|
+
edge: wireEdge(d.wire.from, d.wire.to, exitLabel(d), d.wire.id),
|
|
223
|
+
style: wireStyle(color(d.type), isControl(pipeline, d.type), d.problem)
|
|
224
|
+
}));
|
|
225
|
+
}
|
|
226
|
+
function sceneStyles(stages, edges, theme = LOOK_THEME) {
|
|
227
|
+
const nodes = new Map(stages.map((s) => [s.id, stageStyle(s, theme)]));
|
|
228
|
+
const wires = new Map(edges.map((e) => [edgeIdOf(e.edge), e.style]));
|
|
229
|
+
return {
|
|
230
|
+
theme,
|
|
231
|
+
nodeStyle: (n) => nodes.get(n.id) ?? theme.roles[theme.defaultRole],
|
|
232
|
+
edgeStyle: (e) => wires.get(edgeIdOf(e)) ?? wireStyle(UNTYPED, false, false)
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// src/effect/runner/order.ts
|
|
237
|
+
function runOrder(pipeline) {
|
|
238
|
+
const ids = uniqueStages(pipeline).map((s) => s.id);
|
|
239
|
+
const index = new Map(ids.map((id, i) => [id, i]));
|
|
240
|
+
const next = ids.map(() => []);
|
|
241
|
+
for (const w of pipeline.wires) {
|
|
242
|
+
const a = index.get(w.from.stage);
|
|
243
|
+
const b = index.get(w.to.stage);
|
|
244
|
+
if (a !== void 0 && b !== void 0) next[a].push(b);
|
|
245
|
+
}
|
|
246
|
+
const onCycle = cycleMembers(next);
|
|
247
|
+
const waiting = ids.map(() => 0);
|
|
248
|
+
for (let a = 0; a < ids.length; a++) {
|
|
249
|
+
if (!onCycle[a]) {
|
|
250
|
+
for (const b of next[a]) if (!onCycle[b]) waiting[b]++;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const ready = new Set(ids.flatMap((_, i) => !onCycle[i] && waiting[i] === 0 ? [i] : []));
|
|
254
|
+
const order = [];
|
|
255
|
+
while (ready.size > 0) {
|
|
256
|
+
const i = Math.min(...ready);
|
|
257
|
+
ready.delete(i);
|
|
258
|
+
order.push(ids[i]);
|
|
259
|
+
for (const b of next[i]) if (!onCycle[b] && --waiting[b] === 0) ready.add(b);
|
|
260
|
+
}
|
|
261
|
+
return { order, cyclic: ids.filter((_, i) => onCycle[i]) };
|
|
262
|
+
}
|
|
263
|
+
function cycleMembers(next) {
|
|
264
|
+
const n = next.length;
|
|
265
|
+
const low = new Array(n).fill(-1);
|
|
266
|
+
const seen = new Array(n).fill(-1);
|
|
267
|
+
const onStack = new Array(n).fill(false);
|
|
268
|
+
const result = new Array(n).fill(false);
|
|
269
|
+
const stack = [];
|
|
270
|
+
let counter = 0;
|
|
271
|
+
const visit = (v) => {
|
|
272
|
+
seen[v] = low[v] = counter++;
|
|
273
|
+
stack.push(v);
|
|
274
|
+
onStack[v] = true;
|
|
275
|
+
for (const w2 of next[v]) {
|
|
276
|
+
if (seen[w2] === -1) {
|
|
277
|
+
visit(w2);
|
|
278
|
+
low[v] = Math.min(low[v], low[w2]);
|
|
279
|
+
} else if (onStack[w2]) {
|
|
280
|
+
low[v] = Math.min(low[v], seen[w2]);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (low[v] !== seen[v]) return;
|
|
284
|
+
const component = [];
|
|
285
|
+
let w;
|
|
286
|
+
do {
|
|
287
|
+
w = stack.pop();
|
|
288
|
+
onStack[w] = false;
|
|
289
|
+
component.push(w);
|
|
290
|
+
} while (w !== v);
|
|
291
|
+
if (component.length > 1 || next[v].includes(v)) for (const c of component) result[c] = true;
|
|
292
|
+
};
|
|
293
|
+
for (let v = 0; v < n; v++) if (seen[v] === -1) visit(v);
|
|
294
|
+
return result;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// src/effect/runner/params.ts
|
|
298
|
+
function paramValues(stage) {
|
|
299
|
+
return Object.fromEntries((stage.params ?? []).map((p) => [p.id ?? p.label, p.control?.value ?? p.value]));
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// src/effect/runner/previews.ts
|
|
303
|
+
function previewsOf(run) {
|
|
304
|
+
return Object.values(run.stages).flatMap((s) => Object.values(s.previews ?? {}));
|
|
305
|
+
}
|
|
306
|
+
function closeBitmaps(bitmaps) {
|
|
307
|
+
for (const b of new Set(bitmaps)) b.close();
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export { LOOK_THEME, NO_VALUE, PREVIEW_DENSITY, PREVIEW_SIZE, PROBLEM_COLOR, boxNode, checkPipeline, closeBitmaps, drawableWires, exitLabel, formatParam, isControl, kindOf, paramValues, portOn, previewRowId, previewsOf, runOrder, sceneStyles, shownPorts, splitProblem, stageFromType, stageRows, stageStyle, typeColors, uniqueGroups, uniqueStages, valueRowId, wireEdge, wireEdges, wireStyle };
|
|
311
|
+
//# sourceMappingURL=chunk-QKSWZEJH.js.map
|
|
312
|
+
//# sourceMappingURL=chunk-QKSWZEJH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/effect/check.ts","../src/effect/stageTypes.ts","../src/effect/draw.ts","../src/effect/runner/order.ts","../src/effect/runner/params.ts","../src/effect/runner/previews.ts"],"names":["w"],"mappings":";;;AAeO,SAAS,aAAa,KAAA,EAAmC;AAC9D,EAAA,MAAM,QAAQ,KAAA,CAAM,KAAA;AACpB,EAAA,IAAI,KAAA,KAAU,QAAW,OAAO,IAAA;AAChC,EAAA,IAAI,EAAE,KAAA,CAAM,MAAA,IAAU,EAAC,EAAG,KAAK,CAAC,CAAA,KAAM,CAAA,CAAE,EAAA,KAAO,MAAM,KAAK,CAAA,EAAG,OAAO,CAAA,WAAA,EAAc,MAAM,KAAK,CAAA,iC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,CAAA;AACvD,EAAA,OAAO,MAAA;AACT;;;ACvEO,SAAS,YAAY,KAAA,EAA6C;AACvE,EAAA,OAAO,MAAA,CAAO,aAAa,KAAA,CAAM,MAAA,IAAU,EAAC,EAAG,GAAA,CAAI,CAAC,CAAA,KAAM,CAAC,EAAE,EAAA,IAAM,CAAA,CAAE,OAAO,CAAA,CAAE,OAAA,EAAS,SAAS,CAAA,CAAE,KAAK,CAAC,CAAC,CAAA;AAC3G;;;ACHO,SAAS,WAAW,GAAA,EAA+B;AACxD,EAAA,OAAO,MAAA,CAAO,MAAA,CAAO,GAAA,CAAI,MAAM,EAAE,OAAA,CAAQ,CAAC,CAAA,KAAM,MAAA,CAAO,MAAA,CAAO,CAAA,CAAE,QAAA,IAAY,EAAE,CAAC,CAAA;AACjF;AAEO,SAAS,aAAa,OAAA,EAAuC;AAClE,EAAA,KAAA,MAAW,KAAK,IAAI,GAAA,CAAI,OAAO,CAAA,IAAK,KAAA,EAAM;AAC5C","file":"chunk-QKSWZEJH.js","sourcesContent":["import type { EffectPipeline, EffectStage } from './types';\n\n/** One thing wrong with a pipeline, and where. */\nexport interface EffectProblem {\n kind: 'missing-stage' | 'missing-port' | 'wrong-direction' | 'type-mismatch'\n | 'duplicate-stage' | 'duplicate-port' | 'duplicate-group' | 'missing-member' | 'bad-split';\n message: string;\n stage?: string;\n port?: string;\n /** Index into `pipeline.wires`. */\n wire?: number;\n group?: string;\n}\n\n/** What `split` gets wrong on `stage`, or null. */\nexport function splitProblem(stage: EffectStage): string | null {\n const split = stage.split;\n if (split === undefined) return null;\n if (!(stage.inputs ?? []).some((p) => p.id === split.input)) return `splits on \"${split.input}\", which is not one of its inputs`;\n if (split.at.length === 0) return 'splits with no cuts';\n if (!split.at.every(Number.isFinite)) return 'has a cut that is not a finite number';\n if (split.at.some((cut, i) => i > 0 && cut <= split.at[i - 1]!)) return 'has cuts that are not in ascending order';\n const exits = (stage.outputs ?? []).length;\n if (exits !== split.at.length + 1) return `has ${split.at.length} cuts and ${exits} outputs; it needs ${split.at.length + 1}`;\n return null;\n}\n\n/** Everything wrong with `pipeline`. Never throws. */\nexport function checkPipeline(pipeline: EffectPipeline): EffectProblem[] {\n const out: EffectProblem[] = [];\n const stages = new Map<string, EffectStage>();\n for (const stage of pipeline.stages) {\n if (stages.has(stage.id)) {\n out.push({ kind: 'duplicate-stage', stage: stage.id, message: `Stage \"${stage.id}\" appears more than once.` });\n continue;\n }\n stages.set(stage.id, stage);\n const seen = new Set<string>();\n for (const port of [...(stage.inputs ?? []), ...(stage.outputs ?? [])]) {\n if (seen.has(port.id)) {\n out.push({ kind: 'duplicate-port', stage: stage.id, port: port.id, message: `Stage \"${stage.id}\" has two ports called \"${port.id}\".` });\n }\n seen.add(port.id);\n }\n const split = splitProblem(stage);\n if (split !== null) out.push({ kind: 'bad-split', stage: stage.id, message: `Stage \"${stage.id}\" ${split}.` });\n }\n\n pipeline.wires.forEach((wire, index) => {\n const ends = ([['from', 'outputs', 'inputs'], ['to', 'inputs', 'outputs']] as const).map(([end, own, other]) => {\n const ref = wire[end];\n const stage = stages.get(ref.stage);\n if (stage === undefined) {\n out.push({ kind: 'missing-stage', wire: index, stage: ref.stage, message: `Wire ${index} names stage \"${ref.stage}\", which does not exist.` });\n return null;\n }\n const port = (stage[own] ?? []).find((p) => p.id === ref.port);\n if (port !== undefined) return port;\n const wrong = (stage[other] ?? []).some((p) => p.id === ref.port);\n out.push(wrong\n ? { kind: 'wrong-direction', wire: index, stage: ref.stage, port: ref.port, message: `Wire ${index} ${end === 'from' ? 'starts at an input' : 'ends at an output'}, \"${ref.stage}.${ref.port}\".` }\n : { kind: 'missing-port', wire: index, stage: ref.stage, port: ref.port, message: `Wire ${index} names port \"${ref.stage}.${ref.port}\", which does not exist.` });\n return null;\n });\n const [from, to] = ends;\n if (from && to && from.type !== to.type) {\n out.push({ kind: 'type-mismatch', wire: index, message: `Wire ${index} joins a \"${from.type}\" output to a \"${to.type}\" input.` });\n }\n });\n\n const groupIds = new Set<string>();\n const groups = (pipeline.groups ?? []).filter((group) => {\n const repeat = groupIds.has(group.id);\n if (repeat || stages.has(group.id)) {\n out.push({\n kind: 'duplicate-group',\n group: group.id,\n message: repeat ? `Group \"${group.id}\" appears more than once.` : `Group \"${group.id}\" has the id of a stage.`,\n });\n return false;\n }\n groupIds.add(group.id);\n return true;\n });\n for (const group of groups) {\n for (const member of group.members) {\n if (stages.has(member) || groupIds.has(member)) continue;\n out.push({ kind: 'missing-member', group: group.id, message: `Group \"${group.id}\" names \"${member}\", which is neither a stage nor a group.` });\n }\n }\n return out;\n}\n","import type { EffectParam, EffectParamControl, EffectPort, EffectStage } from './types';\n\n/** A palette entry: a stage's ports and params, ready to be copied into a pipeline. */\nexport interface EffectStageType {\n type: string;\n title: string;\n kind?: string;\n inputs?: readonly EffectPort[];\n outputs?: readonly EffectPort[];\n params?: readonly EffectParam[];\n}\n\n/** A stage of type `t` with its own copy of the ports and params; no link back. */\nexport function stageFromType(t: EffectStageType, id: string): EffectStage {\n const stage: EffectStage = { id, title: t.title, type: t.type };\n if (t.kind !== undefined) stage.kind = t.kind;\n if (t.inputs) stage.inputs = t.inputs.map((p) => ({ ...p }));\n if (t.outputs) stage.outputs = t.outputs.map((p) => ({ ...p }));\n if (t.params) stage.params = t.params.map((p) => ({ ...p, ...(p.control ? { control: structuredClone(p.control) } : {}) }));\n return stage;\n}\n\n/** The places after the point `step` is written with, which a multiple of it needs. */\nfunction stepPlaces(step: number): number {\n const text = String(step);\n if (text.includes('e')) return Math.min(20, Math.max(0, -Math.floor(Math.log10(step))));\n const dot = text.indexOf('.');\n return dot === -1 ? 0 : text.length - dot - 1;\n}\n\n/** The display string for a control's value, to as many places as its `step` has (one without a step). */\nexport function formatParam(control: EffectParamControl): string {\n switch (control.kind) {\n case 'number': {\n const n = control.value.toFixed(control.step === undefined ? 1 : stepPlaces(control.step)).replace(/^-(?=[0.]*$)/, '');\n return control.unit ? `${n} ${control.unit}` : n;\n }\n case 'enum':\n return control.options.find((x) => x.value === control.value)?.label ?? control.value;\n case 'boolean':\n return control.value ? 'on' : 'off';\n case 'string':\n return control.value;\n }\n}\n","/** What every look shares: how a type is colored, how a stage and a wire are\n * styled, and the lookups a look does over a pipeline. */\nimport type { Row } from '../body';\nimport { edgeIdOf, type DataEdge, type DataNode, type DiagramData, type DiagramSceneOptions, type EdgeStyle, type NodeStyle } from '../fromData';\nimport { DIAGRAM_THEMES } from '../theme/themes';\nimport type { DiagramTheme } from '../theme/types';\nimport type { PortSpec } from '../types';\nimport { checkPipeline } from './check';\nimport { formatParam } from './stageTypes';\nimport type { EffectGroup, EffectPipeline, EffectPort, EffectStage, EffectWire } from './types';\n\n/** The color of a value type, for a port or a wire. Answers `undefined`, a\n * port with no type, with a neutral color. */\nexport type TypeColor = (type: string | undefined) => string;\n\n/** What a look hands back: `diagramScene`'s two arguments, and its colors. */\nexport interface EffectLookResult {\n data: DiagramData;\n scene: DiagramSceneOptions;\n color: TypeColor;\n /** Edges standing in for a decision's exits where the look draws no\n * decision, keyed by edge id: which stage chose, and by which output. A\n * run reads that stage's `taken` for them. */\n exits?: ReadonlyMap<string, { stage: string; port: string }>;\n /** The stages on the main line, in the order the look draws them, for a\n * reorder to drag along. Looks that place stages freely leave it out. */\n order?: LookOrder;\n /** The lanes, top down, where the look draws lanes. */\n laneOrder?: LookOrder;\n}\n\n/** A sequence a look draws: the scene node ids of its items in order along\n * `axis`. `reorder`'s `sequenceSlots` turns it into slots once the items\n * have drawn boxes. */\nexport interface LookOrder {\n axis: 'x' | 'y';\n /** `grip` is where a press picks the item up, in world units; default its drawn box. */\n items: readonly { id: string; grip?: { x: number; y: number; width: number; height: number } }[];\n}\n\n/** One way of drawing a pipeline. Unparameterized, a look whose options are\n * not known: any look fits it, and it is called with none. */\nexport type EffectLook<TOptions = never> = (pipeline: EffectPipeline, options?: TOptions) => EffectLookResult;\n\n/** The theme the shipped looks draw in when their options name none. */\nexport const LOOK_THEME: DiagramTheme = DIAGRAM_THEMES.night!;\n\n/** The option every shipped look takes for its colors. */\nexport interface LookThemeOptions {\n /** Stages take its default role, bypassed ones its muted role; value types its `series` in\n * turn; groups its container; lanes its lane bodies. Default `night`. */\n theme?: DiagramTheme;\n}\n\nconst UNTYPED = '#8aa2b5';\n/** The color `wireStyle` draws a wire in when `checkPipeline` reported it. */\nexport const PROBLEM_COLOR = '#ff5d5d';\n\nconst BYPASSED_DASH = [4, 3];\n\n/** A color per type: the one given, or the next in `series` in the order\n * types first appear on the pipeline's ports. */\nexport function typeColors(\n pipeline: EffectPipeline, given: Readonly<Record<string, string>> = {}, series: readonly string[] = LOOK_THEME.series,\n): TypeColor {\n const colors = new Map<string, string>();\n for (const stage of pipeline.stages) {\n for (const port of [...(stage.inputs ?? []), ...(stage.outputs ?? [])]) {\n if (colors.has(port.type)) continue;\n colors.set(port.type, given[port.type] ?? series[colors.size % series.length]!);\n }\n }\n return (type) => (type === undefined ? UNTYPED : colors.get(type) ?? given[type] ?? UNTYPED);\n}\n\n/** Whether `type` is one the pipeline's `types` mark as `control`. */\nexport function isControl(pipeline: EffectPipeline, type: string | undefined): boolean {\n return type !== undefined && pipeline.types?.[type]?.control === true;\n}\n\n/** The node style the shipped looks give a stage: the theme's default role, or dashed in its\n * muted role when the stage is bypassed. */\nexport function stageStyle(stage: EffectStage, theme: DiagramTheme = LOOK_THEME): NodeStyle {\n const { roles, defaultRole } = theme;\n return stage.bypassed === true ? { ...(roles.muted ?? roles[defaultRole]!), dash: BYPASSED_DASH } : roles[defaultRole]!;\n}\n\n/** The edge style the shipped looks give a wire: `color`, dashed for a\n * control wire, and `PROBLEM_COLOR` in place of `color` for a flagged one. */\nexport function wireStyle(color: string, control: boolean, problem: boolean): EdgeStyle {\n return {\n stroke: problem ? PROBLEM_COLOR : color,\n width: 2,\n markerEnd: null,\n ...(control ? { dash: [5, 4] } : {}),\n };\n}\n\n/** Stages with the repeats dropped, first one kept. `diagramScene` throws on\n * a repeated id, so a look builds its nodes from these. */\nexport function uniqueStages(pipeline: EffectPipeline): EffectStage[] {\n const seen = new Set<string>();\n return pipeline.stages.filter((s) => (seen.has(s.id) ? false : (seen.add(s.id), true)));\n}\n\n/** Groups with the repeats dropped, first one kept, and none that has the id\n * of a stage: `diagramScene` throws on an id that names two things. */\nexport function uniqueGroups(pipeline: EffectPipeline): EffectGroup[] {\n const seen = new Set(pipeline.stages.map((s) => s.id));\n return (pipeline.groups ?? []).filter((g) => (seen.has(g.id) ? false : (seen.add(g.id), true)));\n}\n\n/** The port called `id` among a stage's inputs and outputs, inputs first. */\nexport function portOn(stage: EffectStage | undefined, id: string): EffectPort | undefined {\n return [...(stage?.inputs ?? []), ...(stage?.outputs ?? [])].find((p) => p.id === id);\n}\n\n/** A stage's `kind` as the shipped looks read it: any value they do not know is `'stage'`. */\nexport function kindOf(stage: EffectStage): 'stage' | 'decision' | 'source' | 'sink' {\n return stage.kind === 'decision' || stage.kind === 'source' || stage.kind === 'sink' ? stage.kind : 'stage';\n}\n\n/** A wire with both ends present, and what a look needs to draw it. */\nexport interface DrawableWire {\n wire: EffectWire;\n /** Index into `pipeline.wires`. */\n index: number;\n /** The value type of the port the wire leaves. */\n type: string | undefined;\n /** `checkPipeline` reported it. */\n problem: boolean;\n fromStage: EffectStage;\n toStage: EffectStage;\n}\n\n/** The wires a look can draw: each one whose two stages and two ports exist,\n * in the pipeline's order. A wire `checkPipeline` reported and that still has\n * both ends is kept, with `problem` set. */\nexport function drawableWires(pipeline: EffectPipeline): DrawableWire[] {\n const stages = new Map(uniqueStages(pipeline).map((s) => [s.id, s]));\n const flagged = new Set(checkPipeline(pipeline).flatMap((p) => (p.wire === undefined ? [] : [p.wire])));\n return pipeline.wires.flatMap((wire, index) => {\n const fromStage = stages.get(wire.from.stage);\n const toStage = stages.get(wire.to.stage);\n const from = portOn(fromStage, wire.from.port);\n if (fromStage === undefined || toStage === undefined || from === undefined || portOn(toStage, wire.to.port) === undefined) return [];\n return [{ wire, index, type: from.type, problem: flagged.has(index), fromStage, toStage }];\n });\n}\n\n/** What a value row shows before a run fills it in. */\nexport const NO_VALUE = '–';\n/** What a value row is measured as, so most values a run writes fit. */\nconst VALUE_ROOM = '00000.000';\n\n/** The ports a run shows values and previews on: a stage's outputs, or for a\n * stage with none, such as a sink, its inputs, so the end of a pipeline\n * shows what reached it. */\nexport function shownPorts(stage: EffectStage): readonly EffectPort[] {\n return (stage.outputs?.length ?? 0) > 0 ? stage.outputs! : stage.inputs ?? [];\n}\n\n/** The row id of the value row for an output, under its stage's body. */\nexport const valueRowId = (port: string): string => `value:${port}`;\n/** The row id of the preview slot for an output, under its stage's body. */\nexport const previewRowId = (port: string): string => `preview:${port}`;\n\n/** `RunRowOptions.previewSize`'s default: a 48-unit square. */\nexport const PREVIEW_SIZE = 48;\n\n/** Device pixels per preview unit, so a preview stays sharp on a 2× display. */\nexport const PREVIEW_DENSITY = 2;\n\n/** The rows a look keeps on each stage for what an `EffectRun` shows there.\n * Kept from the start, so a run fills them in without the chart laying out\n * again. A decision's symbol keeps neither. */\nexport interface RunRowOptions {\n /** A row per output for its value. Default false. */\n showValues?: boolean;\n /** A slot per output for its preview, after its value row. Default false. */\n showPreviews?: boolean;\n /** The preview slot's size: a square's side, or a width and height. A\n * preview is stretched to fill it. Default `PREVIEW_SIZE`. */\n previewSize?: number | { width: number; height: number };\n}\n\n/** The `RunRowOptions` out of a look's options. */\nfunction runRowsOf(o: RunRowOptions): RunRowOptions {\n return {\n ...(o.showValues !== undefined ? { showValues: o.showValues } : {}),\n ...(o.showPreviews !== undefined ? { showPreviews: o.showPreviews } : {}),\n ...(o.previewSize !== undefined ? { previewSize: o.previewSize } : {}),\n };\n}\n\n/** The body rows of an ordinary stage: its title, a row of its ports when\n * `withPorts` (inputs left, outputs right), then for each of its\n * `shownPorts` its value row when `showValues` and its preview slot when\n * `showPreviews`, then its\n * params when `showParams`. */\nexport function stageRows(\n stage: EffectStage,\n opts: { showParams: boolean; withPorts: boolean } & RunRowOptions,\n): Row[] {\n const rows: Row[] = [{ kind: 'label', text: stage.title, style: { bold: true } }];\n const side = (ports: EffectStage['inputs']) => (ports ?? []).map((p) => ({ id: p.id, label: p.label ?? p.id, type: p.type }));\n if (opts.withPorts && ((stage.inputs?.length ?? 0) > 0 || (stage.outputs?.length ?? 0) > 0)) {\n rows.push({ kind: 'ports', left: side(stage.inputs), right: side(stage.outputs) });\n }\n const size = opts.previewSize ?? PREVIEW_SIZE;\n const preview = typeof size === 'number' ? { width: size, height: size } : size;\n // A repeated port id is a problem `checkPipeline` reports; one row for it.\n const seen = new Set<string>();\n for (const p of shownPorts(stage)) {\n if (seen.has(p.id)) continue;\n seen.add(p.id);\n if (opts.showValues === true) {\n rows.push({ kind: 'field', id: valueRowId(p.id), label: p.label ?? p.id, value: NO_VALUE, room: VALUE_ROOM });\n }\n if (opts.showPreviews === true) rows.push({ kind: 'slot', id: previewRowId(p.id), ...preview });\n }\n if (opts.showParams) for (const p of stage.params ?? []) rows.push({ kind: 'field', label: p.label, value: p.control ? formatParam(p.control) : p.value });\n return rows;\n}\n\n/** What a wire is called: its own label, or for a wire leaving a decision the\n * exit's label, which defaults to the exit's id. Any other wire has no name. */\nexport function exitLabel(d: DrawableWire): string | undefined {\n if (d.wire.label !== undefined) return d.wire.label;\n return kindOf(d.fromStage) === 'decision' ? portOn(d.fromStage, d.wire.from.port)?.label ?? d.wire.from.port : undefined;\n}\n\n/** The node the shipped looks draw for a stage that is not a decision: a box,\n * or a stadium for a source or a sink, holding `stageRows`. `ports` are its\n * perimeter ports; pass none when the rows carry them. */\nexport function boxNode(\n stage: EffectStage,\n opts: { showParams: boolean; rowPorts: boolean; ports: readonly PortSpec[]; run?: RunRowOptions },\n): DataNode {\n return {\n id: stage.id,\n outline: kindOf(stage) === 'stage' ? 'rect' : 'stadium',\n rows: stageRows(stage, { showParams: opts.showParams, withPorts: opts.rowPorts, ...runRowsOf(opts.run ?? {}) }),\n // Always set: left off, a stage port named n, e, s or w would share its id with a compass default.\n ports: opts.ports,\n };\n}\n\n/** One edge of a look's data, from port to port. */\nexport function wireEdge(\n from: EffectWire['from'],\n to: EffectWire['to'],\n label: string | undefined,\n id?: string,\n): DataEdge {\n return {\n ...(id !== undefined ? { id } : {}),\n from: from.stage, fromPort: from.port, to: to.stage, toPort: to.port,\n ...(label !== undefined ? { label } : {}),\n };\n}\n\n/** One edge per drawable wire, from port to port, named by `exitLabel` and\n * styled by `wireStyle` in its type's color. */\nexport function wireEdges(pipeline: EffectPipeline, color: TypeColor): { edge: DataEdge; style: EdgeStyle }[] {\n return drawableWires(pipeline).map((d) => ({\n edge: wireEdge(d.wire.from, d.wire.to, exitLabel(d), d.wire.id),\n style: wireStyle(color(d.type), isControl(pipeline, d.type), d.problem),\n }));\n}\n\n/** A look's `nodeStyle`, `edgeStyle`, and `theme`: `stageStyle` for each stage,\n * and for each edge the style paired with it. */\nexport function sceneStyles(\n stages: readonly EffectStage[],\n edges: readonly { edge: DataEdge; style: EdgeStyle }[],\n theme: DiagramTheme = LOOK_THEME,\n): Required<Pick<DiagramSceneOptions, 'nodeStyle' | 'edgeStyle' | 'theme'>> {\n const nodes = new Map(stages.map((s) => [s.id, stageStyle(s, theme)]));\n const wires = new Map(edges.map((e) => [edgeIdOf(e.edge), e.style]));\n return {\n theme,\n nodeStyle: (n) => nodes.get(n.id) ?? theme.roles[theme.defaultRole]!,\n edgeStyle: (e) => wires.get(edgeIdOf(e)) ?? wireStyle(UNTYPED, false, false),\n };\n}\n","import { uniqueStages } from '../draw';\nimport type { EffectPipeline } from '../types';\n\n/** The order a run evaluates stages in, and the stages it never can. */\nexport interface RunOrder {\n /** Every stage outside a cycle, each after every stage that feeds it. */\n order: string[];\n /** The stages on a cycle of wires, in stage order. */\n cyclic: string[];\n}\n\n/** The stages topologically over data and control wires alike, stable by\n * stage order: of the stages ready to go, the earliest goes first. A stage on\n * a cycle is left out, and so are its wires. */\nexport function runOrder(pipeline: EffectPipeline): RunOrder {\n const ids = uniqueStages(pipeline).map((s) => s.id);\n const index = new Map(ids.map((id, i) => [id, i]));\n const next = ids.map(() => [] as number[]);\n for (const w of pipeline.wires) {\n const a = index.get(w.from.stage);\n const b = index.get(w.to.stage);\n if (a !== undefined && b !== undefined) next[a]!.push(b);\n }\n const onCycle = cycleMembers(next);\n\n const waiting = ids.map(() => 0);\n for (let a = 0; a < ids.length; a++) {\n if (!onCycle[a]) for (const b of next[a]!) if (!onCycle[b]) waiting[b]!++;\n }\n const ready = new Set(ids.flatMap((_, i) => (!onCycle[i] && waiting[i] === 0 ? [i] : [])));\n const order: string[] = [];\n while (ready.size > 0) {\n const i = Math.min(...ready);\n ready.delete(i);\n order.push(ids[i]!);\n for (const b of next[i]!) if (!onCycle[b] && --waiting[b]! === 0) ready.add(b);\n }\n return { order, cyclic: ids.filter((_, i) => onCycle[i]) };\n}\n\n/** Whether each vertex is on a cycle: in a strongly connected component of\n * more than one vertex, or wired to itself. Tarjan's algorithm. */\nfunction cycleMembers(next: readonly (readonly number[])[]): boolean[] {\n const n = next.length;\n const low = new Array<number>(n).fill(-1);\n const seen = new Array<number>(n).fill(-1);\n const onStack = new Array<boolean>(n).fill(false);\n const result = new Array<boolean>(n).fill(false);\n const stack: number[] = [];\n let counter = 0;\n const visit = (v: number): void => {\n seen[v] = low[v] = counter++;\n stack.push(v);\n onStack[v] = true;\n for (const w of next[v]!) {\n if (seen[w] === -1) {\n visit(w);\n low[v] = Math.min(low[v]!, low[w]!);\n } else if (onStack[w]) {\n low[v] = Math.min(low[v]!, seen[w]!);\n }\n }\n if (low[v] !== seen[v]) return;\n const component: number[] = [];\n let w: number;\n do {\n w = stack.pop()!;\n onStack[w] = false;\n component.push(w);\n } while (w !== v);\n if (component.length > 1 || next[v]!.includes(v)) for (const c of component) result[c] = true;\n };\n for (let v = 0; v < n; v++) if (seen[v] === -1) visit(v);\n return result;\n}\n","import type { EffectStage } from '../types';\n\n/** A stage's params by id (label when it has none), each its control's value or its display value. */\nexport function paramValues(stage: EffectStage): Record<string, unknown> {\n return Object.fromEntries((stage.params ?? []).map((p) => [p.id ?? p.label, p.control?.value ?? p.value]));\n}\n","import type { EffectRun } from '../types';\n\nexport function previewsOf(run: EffectRun): ImageBitmap[] {\n return Object.values(run.stages).flatMap((s) => Object.values(s.previews ?? {}));\n}\n\nexport function closeBitmaps(bitmaps: readonly ImageBitmap[]): void {\n for (const b of new Set(bitmaps)) b.close();\n}\n"]}
|