@tvolden/block-code-editor 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +41 -0
  3. package/dist/block-editor.cjs +9 -1
  4. package/dist/block-editor.js +2147 -2101
  5. package/dist/blockRegistry.d.ts +9 -2
  6. package/dist/collaboration/presence.d.ts +23 -0
  7. package/dist/collaboration/sync.d.ts +71 -0
  8. package/dist/collaboration/types.d.ts +93 -0
  9. package/dist/commands/apply.d.ts +18 -0
  10. package/dist/commands/build.d.ts +31 -0
  11. package/dist/commands/index.d.ts +4 -0
  12. package/dist/commands/invert.d.ts +6 -0
  13. package/dist/commands/types.d.ts +84 -0
  14. package/dist/components/BlockPalette.d.ts +4 -5
  15. package/dist/components/BlockRenderer.d.ts +12 -2
  16. package/dist/components/Canvas.d.ts +6 -0
  17. package/dist/components/ExportMenu.d.ts +6 -0
  18. package/dist/components/MouthDecorations.d.ts +13 -0
  19. package/dist/components/PackagesTab.d.ts +20 -0
  20. package/dist/components/PeersOverlay.d.ts +14 -0
  21. package/dist/components/SocketHint.d.ts +11 -0
  22. package/dist/components/UndoRedoBar.d.ts +11 -0
  23. package/dist/demo/LocalServer.d.ts +38 -0
  24. package/dist/demo/pythonWriter.d.ts +6 -0
  25. package/dist/editor/BlockEditor.d.ts +27 -6
  26. package/dist/editor/activeEditor.d.ts +12 -0
  27. package/dist/export/program.d.ts +55 -0
  28. package/dist/index.d.ts +10 -5
  29. package/dist/types.d.ts +39 -0
  30. package/dist/utils/blockLayout.d.ts +60 -4
  31. package/dist/utils/blockShapes.d.ts +12 -1
  32. package/dist/utils/packages.d.ts +17 -0
  33. package/dist/utils/storage.d.ts +6 -0
  34. package/package.json +11 -2
  35. package/dist/carddesigner/CardCanvas.d.ts +0 -10
  36. package/dist/carddesigner/CardDesigner.d.ts +0 -47
  37. package/dist/carddesigner/CardPreview.d.ts +0 -11
  38. package/dist/carddesigner/cardDesignTypes.d.ts +0 -85
  39. package/dist/packages.json +0 -23
@@ -1,6 +1,659 @@
1
- import { jsxs as d, jsx as t, Fragment as at } from "react/jsx-runtime";
2
- import { createContext as _t, useContext as Yt, useRef as Te, useState as U, useEffect as ge, useMemo as et, forwardRef as Lt, useCallback as le } from "react";
3
- const me = {
1
+ import { jsxs as y, jsx as a, Fragment as no } from "react/jsx-runtime";
2
+ import { createContext as oo, useContext as ro, useState as P, useMemo as ze, forwardRef as io, useEffect as Q, useRef as te, useCallback as E } from "react";
3
+ function so(e, t, n) {
4
+ "dependencies" in e ? n(e.dependencies(t)) : e.onClick();
5
+ }
6
+ function J(e) {
7
+ return `${e.publisher}/${e.name}`;
8
+ }
9
+ function He(e) {
10
+ return `${dt}${J(e)}@${e.version}`;
11
+ }
12
+ const dt = "dep:";
13
+ function co(e, t) {
14
+ const n = e.split(/[.-]/), r = t.split(/[.-]/);
15
+ for (let o = 0; o < Math.max(n.length, r.length); o++) {
16
+ const i = n[o] ?? "0", s = r[o] ?? "0", c = Number(i), f = Number(s), g = !isNaN(c) && !isNaN(f) ? c - f : i.localeCompare(s);
17
+ if (g !== 0) return g;
18
+ }
19
+ return 0;
20
+ }
21
+ const Br = 1;
22
+ class _ extends Error {
23
+ code;
24
+ constructor(t, n) {
25
+ super(n), this.name = "CommandRejected", this.code = t;
26
+ }
27
+ }
28
+ function Ve(e, t) {
29
+ switch (t.type) {
30
+ case "InsertBlocks":
31
+ return uo(e, t);
32
+ case "RemoveBlocks":
33
+ return fo(e, t);
34
+ case "MoveBlock":
35
+ return po(e, t);
36
+ case "Attach":
37
+ return ho(e, t);
38
+ case "Detach":
39
+ return yo(e, t);
40
+ case "SetText":
41
+ return mo(e, t);
42
+ case "SetDependencies":
43
+ return ko(e, t);
44
+ case "Batch":
45
+ return xo(e, t);
46
+ default:
47
+ throw new _("INVALID_COMMAND", `Unknown command type '${t.type}'.`);
48
+ }
49
+ }
50
+ function ut(e) {
51
+ return {
52
+ textValue: e?.textValue ?? null,
53
+ queryBlockId: e?.queryBlockId ?? null,
54
+ commandBlockId: e?.commandBlockId ?? null
55
+ };
56
+ }
57
+ function Te(e) {
58
+ const t = _t(e) ? { x: e.x, y: e.y } : { x: 0, y: 0 };
59
+ return { ...e, ...t, paramSlots: e.paramSlots.map(ut) };
60
+ }
61
+ function Me(e) {
62
+ return e == null || e === "" ? null : e;
63
+ }
64
+ function _e(e, t) {
65
+ const n = e.blocks.get(t);
66
+ if (!n) throw new _("BLOCK_NOT_FOUND", `Block '${t}' doesn't exist.`);
67
+ return n;
68
+ }
69
+ function _t(e) {
70
+ return !e.parentBlockId && !e.embeddedInBlockId;
71
+ }
72
+ function pn(e) {
73
+ const t = [];
74
+ e.nextBlockId && t.push(e.nextBlockId);
75
+ for (const n of e.paramSlots)
76
+ n.queryBlockId && t.push(n.queryBlockId), n.commandBlockId && t.push(n.commandBlockId);
77
+ return t;
78
+ }
79
+ function ft(e, t) {
80
+ const n = [], r = /* @__PURE__ */ new Set(), o = [t];
81
+ for (; o.length > 0; ) {
82
+ const i = o.shift();
83
+ if (r.has(i)) continue;
84
+ const s = e.get(i);
85
+ s && (r.add(i), n.push(i), o.push(...pn(s)));
86
+ }
87
+ return n;
88
+ }
89
+ function hn(e) {
90
+ const t = (o) => new _("NOT_A_FRAGMENT", `The blocks aren't one fragment: ${o}.`);
91
+ if (e.length === 0) throw new _("INVALID_COMMAND", "The command has no blocks.");
92
+ const n = /* @__PURE__ */ new Map();
93
+ for (const o of e) {
94
+ if (n.has(o.instanceId)) throw t(`'${o.instanceId}' is given twice`);
95
+ n.set(o.instanceId, o);
96
+ }
97
+ const r = e.filter(_t);
98
+ if (r.length !== 1) throw t(`it has ${r.length} roots`);
99
+ for (const o of e) {
100
+ if (o.nextBlockId) {
101
+ const i = n.get(o.nextBlockId);
102
+ if (!i || i.parentBlockId !== o.instanceId || i.embeddedInBlockId)
103
+ throw t(`the block under '${o.instanceId}' doesn't match`);
104
+ }
105
+ if (o.paramSlots.forEach((i, s) => {
106
+ for (const c of [i.queryBlockId, i.commandBlockId]) {
107
+ if (!c) continue;
108
+ const f = n.get(c);
109
+ if (!f || f.embeddedInBlockId !== o.instanceId || f.embeddedSlotIndex !== s || f.parentBlockId)
110
+ throw t(`slot ${s} of '${o.instanceId}' doesn't match`);
111
+ }
112
+ }), o.parentBlockId) {
113
+ const i = n.get(o.parentBlockId);
114
+ if (!i || i.nextBlockId !== o.instanceId)
115
+ throw t(`the block above '${o.instanceId}' doesn't match`);
116
+ }
117
+ if (o.embeddedInBlockId) {
118
+ const i = n.get(o.embeddedInBlockId)?.paramSlots[o.embeddedSlotIndex];
119
+ if (!i || i.queryBlockId !== o.instanceId && i.commandBlockId !== o.instanceId)
120
+ throw t(`the block holding '${o.instanceId}' doesn't match`);
121
+ }
122
+ }
123
+ if (ft(n, r[0].instanceId).length !== e.length) throw t("not every block hangs off the root");
124
+ return r[0];
125
+ }
126
+ function lo(e, t) {
127
+ return JSON.stringify(Te(e)) === JSON.stringify(Te(t));
128
+ }
129
+ function it(e, t, n) {
130
+ const r = e.paramSlots.map(ut);
131
+ return r[t] = { ...r[t], ...n }, { ...e, paramSlots: r };
132
+ }
133
+ function gn(e, t) {
134
+ if (!Number.isInteger(t) || t < 0 || t >= e.paramSlots.length)
135
+ throw new _("NO_SUCH_SLOT", `Block '${e.instanceId}' has no slot ${t}.`);
136
+ return ut(e.paramSlots[t]);
137
+ }
138
+ function yn(e, t) {
139
+ if (e.x !== t.x || e.y !== t.y)
140
+ throw new _("POSITION_CHANGED", `Block '${e.instanceId}' isn't at (${t.x}, ${t.y}).`);
141
+ }
142
+ function mn(e) {
143
+ if (!_t(e)) throw new _("NOT_A_ROOT", `Block '${e.instanceId}' is linked, not a root.`);
144
+ }
145
+ const Bt = (e) => `${e.publisher}/${e.name}@${e.version}`;
146
+ function ao(e, t) {
147
+ const n = new Set(e.map(Bt));
148
+ return e.length === t.length && n.size === new Set(t.map(Bt)).size && t.every((r) => n.has(Bt(r)));
149
+ }
150
+ function uo(e, t) {
151
+ hn(t.blocks);
152
+ for (const r of t.blocks)
153
+ if (e.blocks.has(r.instanceId))
154
+ throw new _("ID_EXISTS", `Block '${r.instanceId}' already exists.`);
155
+ const n = new Map(e.blocks);
156
+ for (const r of t.blocks) n.set(r.instanceId, Te(r));
157
+ return { ...e, blocks: n };
158
+ }
159
+ function fo(e, t) {
160
+ hn(t.blocks);
161
+ const n = /* @__PURE__ */ new Set();
162
+ for (const o of t.blocks) {
163
+ const i = _e(e, o.instanceId);
164
+ if (!lo(i, o)) throw new _("BLOCK_CHANGED", `Block '${o.instanceId}' has changed.`);
165
+ n.add(o.instanceId);
166
+ }
167
+ for (const o of e.blocks.values())
168
+ if (!n.has(o.instanceId) && pn(o).some((i) => n.has(i)))
169
+ throw new _("LINKED_FROM_OUTSIDE", `Block '${o.instanceId}' links into the blocks to remove.`);
170
+ const r = new Map(e.blocks);
171
+ return n.forEach((o) => r.delete(o)), { ...e, blocks: r };
172
+ }
173
+ function po(e, t) {
174
+ const n = _e(e, t.id);
175
+ mn(n), yn(n, t.from);
176
+ const r = new Map(e.blocks);
177
+ return r.set(n.instanceId, { ...n, x: t.to.x, y: t.to.y }), { ...e, blocks: r };
178
+ }
179
+ function ho(e, t) {
180
+ const n = _e(e, t.id);
181
+ mn(n), yn(n, t.from);
182
+ const r = t.to, o = "next" in r ? r.next : "mouth" in r ? r.mouth : r.socket, i = _e(e, o);
183
+ if (ft(e.blocks, n.instanceId).includes(o))
184
+ throw new _("CYCLE", `Block '${o}' is inside the fragment of '${n.instanceId}'.`);
185
+ const s = new Map(e.blocks);
186
+ if ("next" in r) {
187
+ if (i.nextBlockId) throw new _("PLACE_OCCUPIED", `Block '${o}' already has a block under it.`);
188
+ return s.set(o, { ...i, nextBlockId: n.instanceId }), s.set(n.instanceId, { ...n, x: 0, y: 0, parentBlockId: o }), { ...e, blocks: s };
189
+ }
190
+ const c = gn(i, r.slot);
191
+ if ("mouth" in r) {
192
+ if (c.commandBlockId || c.queryBlockId)
193
+ throw new _("PLACE_OCCUPIED", `Mouth ${r.slot} of '${o}' isn't empty.`);
194
+ s.set(o, it(i, r.slot, { commandBlockId: n.instanceId }));
195
+ } else {
196
+ if (c.queryBlockId || c.commandBlockId || c.textValue !== null)
197
+ throw new _("PLACE_OCCUPIED", `Socket ${r.slot} of '${o}' isn't empty.`);
198
+ s.set(o, it(i, r.slot, { queryBlockId: n.instanceId }));
199
+ }
200
+ return s.set(n.instanceId, { ...n, x: 0, y: 0, embeddedInBlockId: o, embeddedSlotIndex: r.slot }), { ...e, blocks: s };
201
+ }
202
+ function go(e, t, n) {
203
+ if ("next" in n)
204
+ return t.parentBlockId === n.next && e.blocks.get(n.next)?.nextBlockId === t.instanceId;
205
+ const r = "mouth" in n ? n.mouth : n.socket;
206
+ if (t.embeddedInBlockId !== r || t.embeddedSlotIndex !== n.slot) return !1;
207
+ const o = ut(e.blocks.get(r)?.paramSlots[n.slot]);
208
+ return ("mouth" in n ? o.commandBlockId : o.queryBlockId) === t.instanceId;
209
+ }
210
+ function yo(e, t) {
211
+ const n = _e(e, t.id);
212
+ if (!go(e, n, t.from))
213
+ throw new _("NOT_AT_PLACE", `Block '${n.instanceId}' isn't linked at the given place.`);
214
+ const r = new Map(e.blocks), o = t.from;
215
+ if ("next" in o) {
216
+ const i = r.get(o.next);
217
+ r.set(o.next, { ...i, nextBlockId: null });
218
+ } else {
219
+ const i = "mouth" in o ? o.mouth : o.socket, s = "mouth" in o ? { commandBlockId: null } : { queryBlockId: null };
220
+ r.set(i, it(r.get(i), o.slot, s));
221
+ }
222
+ return r.set(n.instanceId, {
223
+ ...n,
224
+ x: t.to.x,
225
+ y: t.to.y,
226
+ parentBlockId: null,
227
+ embeddedInBlockId: null,
228
+ embeddedSlotIndex: -1
229
+ }), { ...e, blocks: r };
230
+ }
231
+ function mo(e, t) {
232
+ const n = _e(e, t.blockId), r = gn(n, t.slot);
233
+ if (r.queryBlockId)
234
+ throw new _("SLOT_HAS_QUERY", `Slot ${t.slot} of '${n.instanceId}' holds a query.`);
235
+ if (Me(r.textValue) !== Me(t.from))
236
+ throw new _("TEXT_CHANGED", `Slot ${t.slot} of '${n.instanceId}' has changed.`);
237
+ const o = new Map(e.blocks);
238
+ return o.set(n.instanceId, it(n, t.slot, { textValue: Me(t.to) })), { ...e, blocks: o };
239
+ }
240
+ function ko(e, t) {
241
+ if (!ao(e.dependencies, t.from))
242
+ throw new _("DEPENDENCIES_CHANGED", "The dependencies have changed.");
243
+ return { ...e, dependencies: t.to.map((n) => ({ publisher: n.publisher, name: n.name, version: n.version })) };
244
+ }
245
+ function xo(e, t) {
246
+ return t.commands.reduce(Ve, e);
247
+ }
248
+ const Ae = { x: 0, y: 0 };
249
+ class pt {
250
+ state;
251
+ commands = [];
252
+ constructor(t) {
253
+ this.state = t;
254
+ }
255
+ get current() {
256
+ return this.state;
257
+ }
258
+ add(t) {
259
+ this.state = Ve(this.state, t), this.commands.push(t);
260
+ }
261
+ /** The user action: nothing, one command, or a batch. */
262
+ build() {
263
+ return this.commands.length === 0 ? null : this.commands.length === 1 ? this.commands[0] : { type: "Batch", commands: this.commands };
264
+ }
265
+ }
266
+ function kn(e) {
267
+ return { x: Math.round(e.x), y: Math.round(e.y) };
268
+ }
269
+ function Nt(e, t) {
270
+ return t.parentBlockId ? { next: t.parentBlockId } : t.embeddedInBlockId ? e.blocks.get(t.embeddedInBlockId)?.paramSlots[t.embeddedSlotIndex]?.commandBlockId === t.instanceId ? { mouth: t.embeddedInBlockId, slot: t.embeddedSlotIndex } : { socket: t.embeddedInBlockId, slot: t.embeddedSlotIndex } : null;
271
+ }
272
+ function bo(e, t) {
273
+ return JSON.stringify(e) === JSON.stringify(t);
274
+ }
275
+ function xn(e, t) {
276
+ return ft(e.blocks, t).map((n) => Te(e.blocks.get(n)));
277
+ }
278
+ function Io(e, t) {
279
+ let n = t;
280
+ for (; ; ) {
281
+ const r = e.blocks.get(n)?.nextBlockId;
282
+ if (!r) return n;
283
+ n = r;
284
+ }
285
+ }
286
+ function bn(e, t, n) {
287
+ const r = e.current.blocks.get(t), o = { x: r.x, y: r.y };
288
+ if ("socket" in n) {
289
+ const i = Me(e.current.blocks.get(n.socket)?.paramSlots[n.slot]?.textValue);
290
+ i !== null && e.add({ type: "SetText", blockId: n.socket, slot: n.slot, from: i, to: null }), e.add({ type: "Attach", id: t, to: n, from: o });
291
+ return;
292
+ }
293
+ if ("mouth" in n) {
294
+ const i = e.current.blocks.get(n.mouth)?.paramSlots[n.slot]?.commandBlockId ?? null;
295
+ if (i) {
296
+ e.add({ type: "Detach", id: i, from: n, to: Ae }), e.add({ type: "Attach", id: t, to: n, from: o }), e.add({ type: "Attach", id: i, to: { next: Io(e.current, t) }, from: Ae });
297
+ return;
298
+ }
299
+ }
300
+ e.add({ type: "Attach", id: t, to: n, from: o });
301
+ }
302
+ function vo(e, t, n, r) {
303
+ const o = new pt(e), i = kn(n);
304
+ return o.add({ type: "InsertBlocks", blocks: [Te({ ...t, ...i })] }), r && bn(o, t.instanceId, r), o.build();
305
+ }
306
+ function So(e, t, n, r) {
307
+ const o = e.blocks.get(t);
308
+ if (!o) return null;
309
+ const i = new pt(e), s = kn(n), c = Nt(e, o);
310
+ return r && c && bo(r, c) ? null : (c ? i.add({ type: "Detach", id: t, from: c, to: s }) : !r && (o.x !== s.x || o.y !== s.y) && i.add({ type: "MoveBlock", id: t, from: { x: o.x, y: o.y }, to: s }), r && bn(i, t, r), i.build());
311
+ }
312
+ function $o(e, t) {
313
+ const n = e.blocks.get(t);
314
+ if (!n) return null;
315
+ const r = new pt(e), o = Nt(e, n);
316
+ return o && r.add({ type: "Detach", id: t, from: o, to: Ae }), r.add({ type: "RemoveBlocks", blocks: xn(r.current, t) }), r.build();
317
+ }
318
+ function Bo(e, t, n, r) {
319
+ const o = Me(n), i = Me(r);
320
+ return o === i ? null : { type: "SetText", blockId: e, slot: t, from: o, to: i };
321
+ }
322
+ function wo(e, t, n) {
323
+ const r = new pt(e);
324
+ for (const o of n) {
325
+ const i = r.current.blocks.get(o);
326
+ if (!i) continue;
327
+ const s = Nt(r.current, i), c = i.nextBlockId;
328
+ if (c) {
329
+ const f = s ? Ae : { x: i.x, y: i.y };
330
+ r.add({ type: "Detach", id: c, from: { next: o }, to: f });
331
+ }
332
+ s && r.add({ type: "Detach", id: o, from: s, to: Ae }), r.add({ type: "RemoveBlocks", blocks: xn(r.current, o) }), c && s && r.add({ type: "Attach", id: c, to: s, from: Ae });
333
+ }
334
+ return r.add({ type: "SetDependencies", from: r.current.dependencies, to: t }), r.build();
335
+ }
336
+ function In(e) {
337
+ switch (e.type) {
338
+ case "InsertBlocks":
339
+ return { type: "RemoveBlocks", blocks: e.blocks };
340
+ case "RemoveBlocks":
341
+ return { type: "InsertBlocks", blocks: e.blocks };
342
+ case "MoveBlock":
343
+ return { type: "MoveBlock", id: e.id, from: e.to, to: e.from };
344
+ case "Attach":
345
+ return { type: "Detach", id: e.id, from: e.to, to: e.from };
346
+ case "Detach":
347
+ return { type: "Attach", id: e.id, to: e.from, from: e.to };
348
+ case "SetText":
349
+ return { type: "SetText", blockId: e.blockId, slot: e.slot, from: e.to, to: e.from };
350
+ case "SetDependencies":
351
+ return { type: "SetDependencies", from: e.to, to: e.from };
352
+ case "Batch":
353
+ return { type: "Batch", commands: e.commands.map(In).reverse() };
354
+ default:
355
+ throw new _("INVALID_COMMAND", `Unknown command type '${e.type}'.`);
356
+ }
357
+ }
358
+ function vn(e, t = 0) {
359
+ return { confirmed: e, version: t, pending: [], undo: [], redo: [] };
360
+ }
361
+ function To(e, t, n) {
362
+ return { ...e, pending: [...e.pending, { id: t, command: n, kind: "do", original: n }] };
363
+ }
364
+ function Co(e, t) {
365
+ const n = e.undo[e.undo.length - 1];
366
+ if (!n || !st(e)) return null;
367
+ const r = In(n);
368
+ return { sync: { ...e, pending: [...e.pending, { id: t, command: r, kind: "undo", original: n }] }, command: r };
369
+ }
370
+ function Eo(e, t) {
371
+ const n = e.redo[e.redo.length - 1];
372
+ return !n || !st(e) ? null : { sync: { ...e, pending: [...e.pending, { id: t, command: n, kind: "redo", original: n }] }, command: n };
373
+ }
374
+ function st(e) {
375
+ return e.pending.length === 0;
376
+ }
377
+ function Po(e, t, n) {
378
+ return { sync: vn(e, t), dropped: n.pending.length };
379
+ }
380
+ function ln(e, t, n) {
381
+ let r;
382
+ try {
383
+ r = Ve(e.confirmed, t.command);
384
+ } catch {
385
+ return { sync: e, outOfSync: !0 };
386
+ }
387
+ const o = e.pending.find((s) => s.id === t.id), i = { ...e, confirmed: r, version: n, pending: e.pending.filter((s) => s.id !== t.id) };
388
+ if (!o) return { sync: i, outOfSync: !1 };
389
+ switch (o.kind) {
390
+ case "do":
391
+ return { sync: { ...i, undo: [...i.undo, o.original], redo: [] }, outOfSync: !1 };
392
+ case "undo":
393
+ return { sync: { ...i, undo: i.undo.slice(0, -1), redo: [...i.redo, o.original] }, outOfSync: !1 };
394
+ case "redo":
395
+ return { sync: { ...i, undo: [...i.undo, o.original], redo: i.redo.slice(0, -1) }, outOfSync: !1 };
396
+ }
397
+ }
398
+ function an(e, t) {
399
+ const n = e.pending.find((o) => o.id === t) ?? null;
400
+ if (!n) return { sync: e, action: null };
401
+ const r = { ...e, pending: e.pending.filter((o) => o.id !== t) };
402
+ return n.kind === "undo" ? { sync: { ...r, undo: r.undo.slice(0, -1) }, action: n } : n.kind === "redo" ? { sync: { ...r, redo: r.redo.slice(0, -1) }, action: n } : { sync: r, action: n };
403
+ }
404
+ function dn(e) {
405
+ let t = e.confirmed;
406
+ for (const r of e.pending)
407
+ try {
408
+ t = Ve(t, r.command);
409
+ } catch {
410
+ break;
411
+ }
412
+ const n = /* @__PURE__ */ new Set();
413
+ return t !== e.confirmed && t.blocks.forEach((r, o) => {
414
+ e.confirmed.blocks.get(o) !== r && n.add(o);
415
+ }), { state: t, provisionalIds: n };
416
+ }
417
+ const Sn = 66, Do = { cursor: null, drag: null, typing: null };
418
+ class Mo {
419
+ presence = Do;
420
+ lastSent = Number.NEGATIVE_INFINITY;
421
+ timer = null;
422
+ send;
423
+ intervalMs;
424
+ now;
425
+ constructor(t, n = Sn, r = Date.now) {
426
+ this.send = t, this.intervalMs = n, this.now = r;
427
+ }
428
+ get current() {
429
+ return this.presence;
430
+ }
431
+ /** A change sent within the interval (e.g. the cursor moving). */
432
+ update(t) {
433
+ if (this.presence = { ...this.presence, ...t }, this.timer) return;
434
+ const n = this.lastSent + this.intervalMs - this.now();
435
+ n <= 0 ? this.flush() : this.timer = setTimeout(() => this.flush(), n);
436
+ }
437
+ /** A change sent at once (a drag or typing starting or ending). */
438
+ updateNow(t) {
439
+ this.presence = { ...this.presence, ...t }, this.flush();
440
+ }
441
+ /** Stops a pending send. */
442
+ dispose() {
443
+ this.timer && clearTimeout(this.timer), this.timer = null;
444
+ }
445
+ flush() {
446
+ this.dispose(), this.lastSent = this.now(), this.send(this.presence);
447
+ }
448
+ }
449
+ const Tt = "command", de = /* @__PURE__ */ new Map(), Ue = /* @__PURE__ */ new Map(), xe = /* @__PURE__ */ new Map();
450
+ async function Ot(e) {
451
+ const t = xe.get(e.id);
452
+ if (t && t.info.url === e.url) return t;
453
+ t && Lt(e.id);
454
+ const n = await fetch(e.url);
455
+ if (!n.ok) throw new Error(`HTTP ${n.status} fetching ${e.url}`);
456
+ const r = await n.json(), o = [], i = [];
457
+ for (const c of r)
458
+ de.has(c.id) ? i.push(c.id) : (de.set(c.id, c), Ue.set(c.id, e.id), o.push(c.id));
459
+ const s = { info: e, blockIds: o, conflictIds: i };
460
+ return xe.set(e.id, s), s;
461
+ }
462
+ function Lt(e) {
463
+ const t = xe.get(e);
464
+ if (t) {
465
+ for (const n of t.blockIds)
466
+ de.delete(n), Ue.delete(n);
467
+ xe.delete(e);
468
+ }
469
+ }
470
+ function We() {
471
+ return Array.from(xe.values());
472
+ }
473
+ function $n(e) {
474
+ return Ue.get(e);
475
+ }
476
+ function ct(e) {
477
+ const t = de.get(e);
478
+ if (!t) throw new Error(`Block definition not found: "${e}"`);
479
+ return t;
480
+ }
481
+ function z(e) {
482
+ return de.get(e);
483
+ }
484
+ function Bn() {
485
+ return [...de.values()];
486
+ }
487
+ function Ao() {
488
+ return [...new Set(Bn().map((e) => e.category))];
489
+ }
490
+ function _o(e, t) {
491
+ const n = [], r = [];
492
+ for (const i of t)
493
+ de.has(i.id) ? r.push(i.id) : (de.set(i.id, i), Ue.set(i.id, e.id), n.push(i.id));
494
+ const o = { info: e, blockIds: n, conflictIds: r };
495
+ return xe.set(e.id, o), o;
496
+ }
497
+ async function No(e) {
498
+ xe.get(un)?.info.url !== e && (de.clear(), Ue.clear(), xe.clear(), await Ot({ id: un, name: "Core", description: "Built-in blocks", url: e, builtIn: !0 }));
499
+ }
500
+ const un = "__core__", wn = 36, me = 50, ke = 24, Ye = 24, Rt = 16, Oo = 24, Ct = 24, Lo = 16, Ht = 26, et = 12, wt = 12, Tn = 8, Et = 6;
501
+ function Cn(e) {
502
+ return e.blockType === "query" && e.returnType ? `${e.name} [${e.returnType}]` : e.name;
503
+ }
504
+ const Ro = {
505
+ number: { w: 44, h: ke },
506
+ string: { w: 60, h: ke },
507
+ boolean: { w: 52, h: ke }
508
+ }, Ho = { w: 75, h: ke };
509
+ function En(e) {
510
+ return Ro[e] ?? Ho;
511
+ }
512
+ function Ne(e, t) {
513
+ return e.blockType === "command" && t.type === Tt;
514
+ }
515
+ function Pn(e, t, n) {
516
+ if (t?.queryBlockId && n) {
517
+ const r = n.get(t.queryBlockId);
518
+ if (r) {
519
+ const o = z(r.definitionId);
520
+ if (o) return ue(o, r.paramSlots, n);
521
+ }
522
+ }
523
+ return En(e).w;
524
+ }
525
+ const zo = 5;
526
+ function Wo(e, t, n) {
527
+ const o = t === "number" || t === "boolean" ? n - ke : n - 10, i = Math.floor(o / zo);
528
+ return e.length <= i ? e : i <= 1 ? "…" : `${e.slice(0, i - 1)}…`;
529
+ }
530
+ function lt(e, t) {
531
+ return `${e}: ${t}`;
532
+ }
533
+ function zt(e) {
534
+ return Math.max(72, e.length * 6 + 22);
535
+ }
536
+ function ue(e, t, n) {
537
+ let r = et + wt + Cn(e).length * Et;
538
+ for (let i = 0; i < e.params.length; i++)
539
+ Ne(e, e.params[i]) || (r += Tn + Pn(e.params[i].type, t?.[i], n));
540
+ if (e.blockType === "start" && e.provides)
541
+ for (const i of e.provides)
542
+ r = Math.max(r, et + zt(i.name) + wt);
543
+ e.params.forEach((i) => {
544
+ Ne(e, i) && (r = Math.max(r, Rt + et + i.name.length * Et + wt));
545
+ });
546
+ const o = e.blockType === "start" ? 140 : 110;
547
+ return Math.max(o, r);
548
+ }
549
+ function Xe(e) {
550
+ return e.blockType === "start" ? me : e.blockType === "command" ? wn : ke;
551
+ }
552
+ function be(e, t, n) {
553
+ if (e.blockType === "start") {
554
+ const r = e.provides?.length ?? 0;
555
+ return me + (r > 0 ? 8 + r * Ht : 0);
556
+ }
557
+ if (e.blockType === "command") {
558
+ const r = Ee(e, t, n);
559
+ if (r.length === 0) return wn;
560
+ const o = r[r.length - 1];
561
+ return o.y + o.h + Lo;
562
+ }
563
+ return ke;
564
+ }
565
+ function Wt(e, t) {
566
+ const n = z(e.definitionId);
567
+ return n ? be(n, e.paramSlots, t) : Ye;
568
+ }
569
+ function Dn(e, t) {
570
+ let n = 0;
571
+ const r = /* @__PURE__ */ new Set();
572
+ let o = e;
573
+ for (; o && !r.has(o); ) {
574
+ r.add(o);
575
+ const i = t.get(o);
576
+ if (!i) break;
577
+ n += Wt(i, t), o = i.nextBlockId;
578
+ }
579
+ return n;
580
+ }
581
+ function Ee(e, t, n) {
582
+ const r = [];
583
+ let o = Xe(e);
584
+ return e.params.forEach((i, s) => {
585
+ if (!Ne(e, i)) return;
586
+ let c = null;
587
+ r.length > 0 && (c = o, o += Ct);
588
+ const f = t?.[s]?.commandBlockId, g = f && n ? Dn(f, n) : 0, h = Math.max(Oo, g);
589
+ r.push({ index: s, name: i.name, x: Rt, y: o, h, dividerY: c }), o += h;
590
+ }), r;
591
+ }
592
+ function je(e, t, n) {
593
+ const r = Xe(e), o = [];
594
+ let i = et + Cn(e).length * Et;
595
+ for (let s = 0; s < e.params.length; s++) {
596
+ const c = e.params[s];
597
+ if (Ne(e, c)) continue;
598
+ const f = Pn(c.type, t?.[s], n), g = En(c.type).h;
599
+ i += Tn, o.push({ x: i, y: (r - g) / 2, w: f, h: g, type: c.type, index: s }), i += f;
600
+ }
601
+ return o;
602
+ }
603
+ function qo(e) {
604
+ const t = /* @__PURE__ */ new Map();
605
+ function n(r, o, i) {
606
+ const s = e.get(r);
607
+ if (!s || t.has(r)) return;
608
+ t.set(r, { x: o, y: i });
609
+ const c = z(s.definitionId);
610
+ if (c) {
611
+ for (const f of je(c, s.paramSlots, e)) {
612
+ const g = s.paramSlots[f.index]?.queryBlockId;
613
+ g && n(g, o + f.x, i + f.y);
614
+ }
615
+ for (const f of Ee(c, s.paramSlots, e)) {
616
+ const g = s.paramSlots[f.index]?.commandBlockId;
617
+ g && n(g, o + f.x, i + f.y);
618
+ }
619
+ }
620
+ s.nextBlockId && n(s.nextBlockId, o, i + Wt(s, e));
621
+ }
622
+ return e.forEach((r) => {
623
+ !r.parentBlockId && !r.embeddedInBlockId && n(r.instanceId, r.x, r.y);
624
+ }), t;
625
+ }
626
+ function Yo(e, t) {
627
+ const n = /* @__PURE__ */ new Set();
628
+ function r(s) {
629
+ const c = [];
630
+ let f = s ?? null;
631
+ for (; f && !n.has(f); ) {
632
+ const g = e.blocks.get(f);
633
+ if (!g) break;
634
+ c.push(o(g)), f = g.nextBlockId;
635
+ }
636
+ return c;
637
+ }
638
+ function o(s) {
639
+ n.add(s.instanceId);
640
+ const c = t(s.definitionId), f = s.paramSlots.map((g, h) => {
641
+ const B = c?.params[h] ?? { name: `param${h}`, type: "string" }, W = g.queryBlockId ? e.blocks.get(g.queryBlockId) : void 0;
642
+ let w;
643
+ return c && Ne(c, B) ? w = { kind: "body", body: r(g.commandBlockId) } : W ? w = { kind: "query", node: o(W) } : g.textValue !== null && g.textValue !== void 0 && g.textValue !== "" ? w = { kind: "text", text: g.textValue } : w = { kind: "empty" }, { name: B.name, type: B.type, value: w };
644
+ });
645
+ return {
646
+ definitionId: s.definitionId,
647
+ name: c?.name ?? s.definitionId,
648
+ blockType: c?.blockType ?? "missing",
649
+ args: f
650
+ };
651
+ }
652
+ return {
653
+ roots: [...e.blocks.values()].filter((s) => !s.parentBlockId && !s.embeddedInBlockId).sort((s, c) => s.y - c.y || s.x - c.x || (s.instanceId < c.instanceId ? -1 : s.instanceId > c.instanceId ? 1 : 0)).map((s) => ({ position: { x: s.x, y: s.y }, body: r(s.instanceId) }))
654
+ };
655
+ }
656
+ const qe = {
4
657
  id: "dark",
5
658
  label: "Dark",
6
659
  // Surfaces — stepped hierarchy so each layer reads as distinct
@@ -55,7 +708,7 @@ const me = {
55
708
  switcherText: "#5a6888",
56
709
  switcherActiveText: "#c9a43a",
57
710
  switcherBorder: "#252d42"
58
- }, Ft = {
711
+ }, Vo = {
59
712
  id: "light",
60
713
  label: "Light",
61
714
  appBg: "#f0f2f6",
@@ -98,1457 +751,446 @@ const me = {
98
751
  switcherText: "#9090a0",
99
752
  switcherActiveText: "#1a2030",
100
753
  switcherBorder: "#dde2ec"
101
- }, Ce = [me, Ft], Pe = _t(me);
102
- function G() {
103
- return Yt(Pe);
754
+ }, tt = [qe, Vo], nt = oo(qe);
755
+ function ee() {
756
+ return ro(nt);
104
757
  }
105
- const ie = 280, pe = 392, Me = 16, B = 48;
106
- function Nt() {
107
- return {
108
- version: "1",
109
- meta: {
110
- name: "New Card",
111
- description: "",
112
- cardType: "",
113
- tags: "",
114
- customFields: []
115
- },
116
- background: { color: "#1a2a4a", imageUrl: "" },
117
- elements: []
118
- };
758
+ const F = 16, ye = 14, Be = F + ye / 2, we = 5, D = 4;
759
+ function Uo(e, t) {
760
+ return [
761
+ `M ${D} 0`,
762
+ // Top edge with inlet (triangle dips into the block)
763
+ `H ${F} L ${Be} ${we} L ${F + ye} 0`,
764
+ `H ${e - D} Q ${e} 0 ${e} ${D}`,
765
+ `V ${t - D} Q ${e} ${t} ${e - D} ${t}`,
766
+ // Bottom edge with outlet (triangle protrudes below)
767
+ `H ${F + ye} L ${Be} ${t + we} L ${F} ${t}`,
768
+ `H ${D} Q 0 ${t} 0 ${t - D}`,
769
+ `V ${D} Q 0 0 ${D} 0 Z`
770
+ ].join(" ");
119
771
  }
120
- let Xt = 0;
121
- function Fe() {
122
- return `el${++Xt}_${Date.now()}`;
772
+ function Xo(e, t, n, r) {
773
+ const o = [
774
+ `M ${D} 0`,
775
+ // Top edge with inlet
776
+ `H ${F} L ${Be} ${we} L ${F + ye} 0`,
777
+ `H ${e - D} Q ${e} 0 ${e} ${D}`
778
+ ];
779
+ for (const i of r) {
780
+ const s = i.y, c = i.y + i.h;
781
+ o.push(
782
+ // Right edge down to the mouth, then its roof leftwards with an outlet tab into the mouth
783
+ `V ${s}`,
784
+ `H ${n + F + ye} L ${n + Be} ${s + we} L ${n + F} ${s}`,
785
+ `H ${n}`,
786
+ // Inner wall, then the floor rightwards with an inlet for the chain's last tab
787
+ `V ${c}`,
788
+ `H ${n + F} L ${n + Be} ${c + we} L ${n + F + ye} ${c}`,
789
+ `H ${e}`
790
+ );
791
+ }
792
+ return o.push(
793
+ `V ${t - D} Q ${e} ${t} ${e - D} ${t}`,
794
+ // Bottom edge with outlet
795
+ `H ${F + ye} L ${Be} ${t + we} L ${F} ${t}`,
796
+ `H ${D} Q 0 ${t} 0 ${t - D}`,
797
+ `V ${D} Q 0 0 ${D} 0 Z`
798
+ ), o.join(" ");
123
799
  }
124
- function kt(e, n) {
125
- const r = {
126
- name: n.name,
127
- description: n.description,
128
- type: n.cardType,
129
- tags: n.tags
130
- };
131
- for (const { key: l, value: i } of n.customFields)
132
- l.trim() && (r[l.trim().toLowerCase()] = i);
133
- return e.replace(
134
- /\{\{(\w+)\}\}/g,
135
- (l, i) => Object.prototype.hasOwnProperty.call(r, i.toLowerCase()) ? r[i.toLowerCase()] : l
136
- );
800
+ function jo(e, t) {
801
+ return [
802
+ "M 0 10 Q 0 0 10 0",
803
+ `H ${e - 10} Q ${e} 0 ${e} 10`,
804
+ `V ${t - D} Q ${e} ${t} ${e - D} ${t}`,
805
+ // Bottom outlet only — start blocks have no inlet
806
+ `H ${F + ye} L ${Be} ${t + we} L ${F} ${t}`,
807
+ `H ${D} Q 0 ${t} 0 ${t - D}`,
808
+ "V 10 Z"
809
+ ].join(" ");
137
810
  }
138
- const Ne = 8, qt = ie + 2 * B, Ot = pe + 2 * B;
139
- function jt({ design: e, selectedId: n, onSelect: r, onMove: l, onResize: i }) {
140
- const o = Te(null), a = Te(null);
141
- function p(c) {
142
- const k = o.current, x = k.createSVGPoint();
143
- x.x = c.clientX, x.y = c.clientY;
144
- const M = x.matrixTransform(k.getScreenCTM().inverse());
145
- return { x: M.x - B, y: M.y - B };
146
- }
147
- function C(c, k) {
148
- c.stopPropagation(), r(k.id);
149
- const { x, y: M } = p(c);
150
- a.current = { kind: "move", id: k.id, ox: x - k.x, oy: M - k.y }, o.current.setPointerCapture(c.pointerId);
151
- }
152
- function s(c, k, x) {
153
- c.stopPropagation();
154
- const { x: M, y: I } = p(c);
155
- a.current = {
156
- kind: "resize",
157
- id: k.id,
158
- handle: x,
159
- startX: k.x,
160
- startY: k.y,
161
- startW: k.w,
162
- startH: k.h,
163
- px0: M,
164
- py0: I
165
- }, o.current.setPointerCapture(c.pointerId);
166
- }
167
- function P(c) {
168
- const k = a.current;
169
- if (!k) return;
170
- const { x, y: M } = p(c);
171
- if (k.kind === "move") {
172
- l(k.id, Math.round(x - k.ox), Math.round(M - k.oy));
173
- return;
174
- }
175
- const I = x - k.px0, _ = M - k.py0, Q = 20;
176
- let { startX: re, startY: R, startW: u, startH: A } = k;
177
- if (k.handle === "nw") {
178
- const Y = Math.min(I, u - Q), g = Math.min(_, A - Q);
179
- re += Y, R += g, u -= Y, A -= g;
180
- } else if (k.handle === "ne") {
181
- const Y = Math.min(_, A - Q);
182
- R += Y, A -= Y, u = Math.max(Q, u + I);
183
- } else if (k.handle === "sw") {
184
- const Y = Math.min(I, u - Q);
185
- re += Y, u -= Y, A = Math.max(Q, A + _);
186
- } else
187
- u = Math.max(Q, u + I), A = Math.max(Q, A + _);
188
- i(k.id, Math.round(re), Math.round(R), Math.round(u), Math.round(A));
189
- }
190
- function T() {
191
- a.current = null;
192
- }
193
- const v = e.elements.find((c) => c.id === n) ?? null;
194
- return /* @__PURE__ */ d(
195
- "svg",
196
- {
197
- ref: o,
198
- viewBox: `0 0 ${qt} ${Ot}`,
199
- preserveAspectRatio: "xMidYMid meet",
200
- style: { width: "100%", height: "100%", display: "block" },
201
- onPointerMove: P,
202
- onPointerUp: T,
203
- onPointerDown: () => r(null),
204
- children: [
205
- /* @__PURE__ */ d("defs", { children: [
206
- /* @__PURE__ */ t("filter", { id: "cd-shadow", x: "-25%", y: "-25%", width: "150%", height: "150%", children: /* @__PURE__ */ t("feDropShadow", { dx: "0", dy: "6", stdDeviation: "10", floodColor: "rgba(0,0,0,0.65)" }) }),
207
- /* @__PURE__ */ t("clipPath", { id: "cd-clip", children: /* @__PURE__ */ t("rect", { x: B, y: B, width: ie, height: pe, rx: Me }) })
208
- ] }),
209
- /* @__PURE__ */ t(
210
- "rect",
211
- {
212
- x: B,
213
- y: B,
214
- width: ie,
215
- height: pe,
216
- rx: Me,
217
- fill: e.background.color,
218
- filter: "url(#cd-shadow)"
219
- }
220
- ),
221
- e.background.imageUrl && /* @__PURE__ */ t(
222
- "image",
223
- {
224
- href: e.background.imageUrl,
225
- x: B,
226
- y: B,
227
- width: ie,
228
- height: pe,
229
- clipPath: "url(#cd-clip)",
230
- preserveAspectRatio: "xMidYMid slice"
231
- }
232
- ),
233
- /* @__PURE__ */ t("g", { clipPath: "url(#cd-clip)", children: e.elements.map((c) => /* @__PURE__ */ t(Vt, { el: c, meta: e.meta, onDown: C }, c.id)) }),
234
- v && /* @__PURE__ */ d(at, { children: [
235
- /* @__PURE__ */ t(
236
- "rect",
237
- {
238
- x: B + v.x - 1,
239
- y: B + v.y - 1,
240
- width: v.w + 2,
241
- height: v.h + 2,
242
- fill: "none",
243
- stroke: "#4a9eff",
244
- strokeWidth: 1.5,
245
- strokeDasharray: "4 2",
246
- pointerEvents: "none"
247
- }
248
- ),
249
- ["nw", "ne", "sw", "se"].map((c) => {
250
- const k = B + v.x + (c.includes("e") ? v.w : 0), x = B + v.y + (c.includes("s") ? v.h : 0);
251
- return /* @__PURE__ */ t(
252
- "rect",
253
- {
254
- x: k - Ne / 2,
255
- y: x - Ne / 2,
256
- width: Ne,
257
- height: Ne,
258
- fill: "white",
259
- stroke: "#4a9eff",
260
- strokeWidth: 1.5,
261
- style: { cursor: `${c}-resize` },
262
- onPointerDown: (M) => {
263
- M.stopPropagation(), s(M, v, c);
264
- }
265
- },
266
- c
267
- );
268
- })
269
- ] }),
270
- /* @__PURE__ */ t(
271
- "rect",
272
- {
273
- x: B,
274
- y: B,
275
- width: ie,
276
- height: pe,
277
- rx: Me,
278
- fill: "none",
279
- stroke: "rgba(255,255,255,0.13)",
280
- strokeWidth: 1.5,
281
- pointerEvents: "none"
282
- }
283
- )
284
- ]
285
- }
286
- );
811
+ function Fo(e, t) {
812
+ const n = t / 2;
813
+ return [
814
+ `M ${n} 0 H ${e - n}`,
815
+ `A ${n} ${n} 0 0 1 ${e - n} ${t}`,
816
+ `H ${n} A ${n} ${n} 0 0 1 ${n} 0 Z`
817
+ ].join(" ");
287
818
  }
288
- function Vt({ el: e, meta: n, onDown: r }) {
289
- const l = (i) => r(i, e);
290
- return e.type === "rectangle" ? /* @__PURE__ */ t(
291
- "rect",
292
- {
293
- x: B + e.x,
294
- y: B + e.y,
295
- width: e.w,
296
- height: e.h,
297
- rx: e.rx,
298
- fill: e.fill,
299
- stroke: e.stroke,
300
- strokeWidth: e.strokeWidth,
301
- style: { cursor: "move" },
302
- onPointerDown: l
303
- }
304
- ) : e.type === "circle" ? /* @__PURE__ */ t(
305
- "ellipse",
306
- {
307
- cx: B + e.x + e.w / 2,
308
- cy: B + e.y + e.h / 2,
309
- rx: e.w / 2,
310
- ry: e.h / 2,
311
- fill: e.fill,
312
- stroke: e.stroke,
313
- strokeWidth: e.strokeWidth,
314
- style: { cursor: "move" },
315
- onPointerDown: l
316
- }
317
- ) : e.type === "image" ? /* @__PURE__ */ t(
318
- "image",
319
- {
320
- href: e.src,
321
- x: B + e.x,
322
- y: B + e.y,
323
- width: e.w,
324
- height: e.h,
325
- preserveAspectRatio: "xMidYMid slice",
326
- style: { cursor: "move" },
327
- onPointerDown: l
328
- }
329
- ) : e.type === "text" ? /* @__PURE__ */ t(
330
- "foreignObject",
331
- {
332
- x: B + e.x,
333
- y: B + e.y,
334
- width: e.w,
335
- height: e.h,
336
- style: { cursor: "move", overflow: "visible" },
337
- onPointerDown: l,
338
- children: /* @__PURE__ */ t("div", { style: {
339
- width: "100%",
340
- height: "100%",
341
- overflow: "hidden",
342
- fontSize: `${e.fontSize}px`,
343
- fontWeight: e.fontWeight,
344
- fontStyle: e.fontStyle,
345
- color: e.color,
346
- textAlign: e.align,
347
- userSelect: "none",
348
- lineHeight: 1.35,
349
- boxSizing: "border-box",
350
- padding: "2px 4px",
351
- whiteSpace: "pre-wrap",
352
- wordBreak: "break-word"
353
- }, children: kt(e.content, n) })
354
- }
355
- ) : null;
819
+ function Qo(e, t) {
820
+ const n = t / 2;
821
+ return [
822
+ `M ${n} 0 H ${e - n}`,
823
+ `L ${e} ${t / 2} L ${e - n} ${t}`,
824
+ `H ${n} L 0 ${t / 2} Z`
825
+ ].join(" ");
356
826
  }
357
- function St({ onSelect: e }) {
358
- const n = G();
359
- return /* @__PURE__ */ t("div", { style: { display: "flex", gap: 4 }, children: Ce.map((r) => /* @__PURE__ */ t("button", { onClick: () => e(r), style: {
360
- background: n.id === r.id ? n.switcherActiveBg : n.switcherBg,
361
- border: `1px solid ${n.switcherBorder}`,
362
- borderRadius: 4,
363
- padding: "2px 9px",
364
- color: n.id === r.id ? n.switcherActiveText : n.switcherText,
365
- fontSize: 10,
366
- fontWeight: n.id === r.id ? "bold" : "normal",
367
- letterSpacing: 0.5,
368
- cursor: "pointer",
369
- transition: "color 0.1s, background 0.1s"
370
- }, children: r.label }, r.id)) });
827
+ function Mn(e, t, n) {
828
+ return [
829
+ `M ${n} 0 H ${e - n} Q ${e} 0 ${e} ${n}`,
830
+ `V ${t - n} Q ${e} ${t} ${e - n} ${t}`,
831
+ `H ${n} Q 0 ${t} 0 ${t - n}`,
832
+ `V ${n} Q 0 0 ${n} 0 Z`
833
+ ].join(" ");
371
834
  }
372
- const qe = 248, wt = "cardcq-card-design";
373
- function Qt() {
374
- try {
375
- const e = localStorage.getItem(wt);
376
- if (e) {
377
- const n = JSON.parse(e);
378
- return Array.isArray(n.meta.customFields) || (n.meta.customFields = []), n;
379
- }
380
- } catch {
381
- }
382
- return Nt();
383
- }
384
- function wn({
385
- onThemeChange: e,
386
- navTabs: n,
387
- themeId: r,
388
- hideTitleBar: l,
389
- compactMode: i,
390
- workspaceOnly: o,
391
- design: a,
392
- onDesignChange: p,
393
- selectedId: C,
394
- onSelectedIdChange: s,
395
- onExport: P,
396
- onImport: T
397
- }) {
398
- const v = G(), [c, k] = U(
399
- () => r ? Ce.find((h) => h.id === r) ?? me : me
400
- );
401
- ge(() => {
402
- r && k(Ce.find((h) => h.id === r) ?? me);
403
- }, [r]);
404
- const x = r ? c : v, M = a !== void 0, [I, _] = U(Qt), [Q, re] = U(null), R = M ? a : I, u = C !== void 0 ? C : Q;
405
- function A(h) {
406
- M ? p?.(h(R)) : _(h);
407
- }
408
- function Y(h) {
409
- s ? s(h) : re(h);
410
- }
411
- const g = Te(null);
412
- ge(() => {
413
- M || (g.current && clearTimeout(g.current), g.current = setTimeout(() => {
414
- localStorage.setItem(wt, JSON.stringify(I));
415
- }, 150));
416
- }, [I, M]);
417
- function F(h) {
418
- A(($) => ({ ...$, meta: { ...$.meta, ...h } }));
419
- }
420
- function Z(h) {
421
- A(($) => ({ ...$, background: { ...$.background, ...h } }));
422
- }
423
- function fe(h, $) {
424
- A((E) => ({
425
- ...E,
426
- elements: E.elements.map((z) => z.id === h ? { ...z, ...$ } : z)
427
- }));
428
- }
429
- function he(h) {
430
- A(($) => ({ ...$, elements: $.elements.filter((E) => E.id !== h) })), Y(null);
431
- }
432
- function X(h) {
433
- A(($) => ({ ...$, elements: [...$.elements, h] })), Y(h.id);
434
- }
435
- function xe(h, $) {
436
- A((E) => {
437
- const z = E.elements.findIndex((ve) => ve.id === h), q = z + $;
438
- if (q < 0 || q >= E.elements.length) return E;
439
- const J = [...E.elements];
440
- return [J[z], J[q]] = [J[q], J[z]], { ...E, elements: J };
441
- });
442
- }
443
- ge(() => {
444
- function h($) {
445
- if (!u) return;
446
- const E = $.target;
447
- if (E instanceof HTMLInputElement || E instanceof HTMLTextAreaElement || E instanceof HTMLSelectElement) return;
448
- const z = $.shiftKey ? 10 : 1;
449
- let q = 0, J = 0;
450
- if ($.key === "ArrowLeft") q = -z;
451
- else if ($.key === "ArrowRight") q = z;
452
- else if ($.key === "ArrowUp") J = -z;
453
- else if ($.key === "ArrowDown") J = z;
454
- else return;
455
- $.preventDefault(), A((ve) => ({
456
- ...ve,
457
- elements: ve.elements.map(
458
- (ke) => ke.id === u ? { ...ke, x: ke.x + q, y: ke.y + J } : ke
459
- )
460
- }));
461
- }
462
- return window.addEventListener("keydown", h), () => window.removeEventListener("keydown", h);
463
- }, [u]);
464
- function ce() {
465
- X({
466
- id: Fe(),
467
- type: "text",
468
- x: 20,
469
- y: 20,
470
- w: ie - 40,
471
- h: 36,
472
- content: "Card Name",
473
- fontSize: 18,
474
- fontWeight: "bold",
475
- fontStyle: "normal",
476
- color: "#ffffff",
477
- align: "center"
478
- });
479
- }
480
- function We() {
481
- X({
482
- id: Fe(),
483
- type: "rectangle",
484
- x: 40,
485
- y: 60,
486
- w: 200,
487
- h: 100,
488
- fill: "#2a3a5a",
489
- stroke: "#4a6090",
490
- strokeWidth: 2,
491
- rx: 6
492
- });
493
- }
494
- function Be() {
495
- X({
496
- id: Fe(),
497
- type: "circle",
498
- x: 90,
499
- y: 100,
500
- w: 100,
501
- h: 100,
502
- fill: "#2a3a5a",
503
- stroke: "#4a6090",
504
- strokeWidth: 2
505
- });
835
+ function Ko(e, t) {
836
+ return Mn(e, t, 5);
837
+ }
838
+ function Go(e, t) {
839
+ return Mn(e, t, 9);
840
+ }
841
+ function qt(e, t, n) {
842
+ switch (e) {
843
+ case "number":
844
+ return Fo(t, n);
845
+ case "boolean":
846
+ return Qo(t, n);
847
+ case "string":
848
+ return Ko(t, n);
849
+ default:
850
+ return Go(t, n);
506
851
  }
507
- function yt() {
508
- X({
509
- id: Fe(),
510
- type: "image",
511
- x: 20,
512
- y: 60,
513
- w: ie - 40,
514
- h: 160,
515
- src: ""
516
- });
852
+ }
853
+ function Yt(e, t, n) {
854
+ return qt(e, t, n);
855
+ }
856
+ function Vt(e, t, n) {
857
+ const r = ue(e, t, n), o = be(e, t, n);
858
+ if (e.blockType === "start") return jo(r, o);
859
+ if (e.blockType === "query") return qt(e.returnType, r, o);
860
+ const i = Ee(e, t, n);
861
+ return i.length > 0 ? Xo(r, o, Rt, i) : Uo(r, o);
862
+ }
863
+ function Zo({ available: e, dependencies: t, onChange: n, actions: r, blockCounts: o, conflictCounts: i }) {
864
+ const s = ee(), [c, f] = P(""), [g, h] = P(""), [B, W] = P(!1), [w, N] = P(null), I = new Map(e.map((x) => [J(x), x])), v = new Set(t.map(J)), K = e.filter((x) => !v.has(J(x)));
865
+ function G() {
866
+ const x = I.get(c);
867
+ if (!x) return;
868
+ const T = B && g.trim() ? g.trim() : x.version;
869
+ n([...t, { publisher: x.publisher, name: x.name, version: T }]), f(""), h("");
517
870
  }
518
- function He() {
519
- const h = JSON.stringify(R, null, 2), $ = new Blob([h], { type: "application/json" }), E = URL.createObjectURL($), z = document.createElement("a");
520
- z.href = E, z.download = `${R.meta.name.replace(/\s+/g, "_") || "card"}.json`, z.click(), URL.revokeObjectURL(E);
871
+ function k(x) {
872
+ n(t.filter((T) => J(T) !== x)), N(null);
521
873
  }
522
- function Ue() {
523
- const h = document.createElement("input");
524
- h.type = "file", h.accept = ".json,application/json", h.onchange = () => {
525
- const $ = h.files?.[0];
526
- if (!$) return;
527
- const E = new FileReader();
528
- E.onload = (z) => {
529
- try {
530
- const q = JSON.parse(z.target?.result);
531
- Array.isArray(q.meta.customFields) || (q.meta.customFields = []), A(() => q), Y(null);
532
- } catch {
533
- alert("Invalid JSON file");
534
- }
535
- }, E.readAsText($);
536
- }, h.click();
874
+ function ne(x, T) {
875
+ n(t.map((q) => J(q) === x ? { ...q, version: T } : q));
537
876
  }
538
- const de = R.elements.find((h) => h.id === u) ?? null, ae = st(x), Ee = i ? { width: qe, flexShrink: 0 } : { flex: 1, minWidth: 0 }, _e = {
539
- design: R,
540
- selectedId: u,
541
- sel: de,
542
- theme: x,
543
- onSelect: Y,
544
- onMove: (h, $, E) => fe(h, { x: $, y: E }),
545
- onResize: (h, $, E, z, q) => fe(h, { x: $, y: E, w: z, h: q }),
546
- onUpdate: (h) => {
547
- de && fe(de.id, h);
548
- },
549
- onDelete: () => {
550
- de && he(de.id);
551
- },
552
- onMoveZ: (h) => {
553
- de && xe(de.id, h);
554
- },
555
- onUpdateBg: Z,
556
- onAddText: ce,
557
- onAddRect: We,
558
- onAddCircle: Be,
559
- onAddImage: yt
560
- };
561
- return o ? /* @__PURE__ */ t(Pe.Provider, { value: x, children: /* @__PURE__ */ t("div", { style: { display: "flex", flex: 1, minWidth: 0, minHeight: 0, overflow: "hidden", fontFamily: "system-ui, sans-serif" }, children: /* @__PURE__ */ t(xt, { ..._e }) }) }) : /* @__PURE__ */ t(Pe.Provider, { value: x, children: /* @__PURE__ */ d("div", { style: {
562
- display: "flex",
563
- flexDirection: "column",
564
- ...Ee,
565
- overflow: "hidden",
566
- background: x.appBg,
567
- color: x.textPrimary,
568
- fontFamily: "system-ui, sans-serif"
569
- }, children: [
570
- !l && /* @__PURE__ */ d("div", { style: {
571
- flexShrink: 0,
572
- display: "flex",
573
- alignItems: "center",
574
- gap: 10,
575
- padding: "0 14px",
576
- height: 38,
577
- background: x.titleBg,
578
- borderBottom: `1px solid ${x.border}`
579
- }, children: [
580
- /* @__PURE__ */ t("span", { style: { color: x.titlePrimaryText, fontWeight: "bold", fontSize: 13, letterSpacing: 1, textTransform: "uppercase" }, children: "CardCQ" }),
581
- /* @__PURE__ */ t("span", { style: { color: x.titleSecondaryText, fontSize: 11, letterSpacing: 0.5 }, children: "Card Designer" }),
582
- n,
583
- /* @__PURE__ */ t("div", { style: { marginLeft: "auto" }, children: /* @__PURE__ */ t(St, { onSelect: (h) => e?.(h) }) })
584
- ] }),
585
- /* @__PURE__ */ d("div", { style: { display: "flex", flex: 1, minHeight: 0, overflow: "hidden" }, children: [
586
- /* @__PURE__ */ d("div", { style: {
587
- width: qe,
588
- flexShrink: 0,
589
- background: x.paletteBg,
590
- borderRight: `1px solid ${x.border}`,
591
- display: "flex",
592
- flexDirection: "column",
593
- overflow: "hidden"
594
- }, children: [
595
- /* @__PURE__ */ t(tt, { children: "Card Properties" }),
596
- /* @__PURE__ */ t("div", { style: { flex: 1, overflowY: "auto", padding: 12 }, children: /* @__PURE__ */ d(rt, { children: [
597
- /* @__PURE__ */ t(nt, { children: "Meta" }),
598
- /* @__PURE__ */ t($e, { lbl: "Name", children: /* @__PURE__ */ t(
599
- "input",
600
- {
601
- type: "text",
602
- value: R.meta.name,
603
- style: ae,
604
- onChange: (h) => F({ name: h.target.value })
605
- }
606
- ) }),
607
- /* @__PURE__ */ t($e, { lbl: "Type", children: /* @__PURE__ */ t(
608
- "input",
609
- {
610
- type: "text",
611
- value: R.meta.cardType,
612
- style: ae,
613
- placeholder: "e.g. Creature, Spell…",
614
- onChange: (h) => F({ cardType: h.target.value })
615
- }
616
- ) }),
617
- /* @__PURE__ */ t($e, { lbl: "Description", children: /* @__PURE__ */ t(
618
- "textarea",
619
- {
620
- value: R.meta.description,
621
- onChange: (h) => F({ description: h.target.value }),
622
- style: { ...ae, height: 56, resize: "none" }
623
- }
624
- ) }),
625
- /* @__PURE__ */ t($e, { lbl: "Tags (comma-separated)", children: /* @__PURE__ */ t(
626
- "input",
627
- {
628
- type: "text",
629
- value: R.meta.tags,
630
- style: ae,
631
- onChange: (h) => F({ tags: h.target.value })
632
- }
633
- ) }),
634
- /* @__PURE__ */ d("div", { style: { marginTop: 4 }, children: [
635
- /* @__PURE__ */ t("div", { style: { fontSize: 11, color: x.textMuted, marginBottom: 6 }, children: "Custom Fields" }),
636
- R.meta.customFields.map((h, $) => /* @__PURE__ */ d("div", { style: { display: "flex", gap: 4, marginBottom: 4, alignItems: "center" }, children: [
637
- /* @__PURE__ */ t(
638
- "input",
639
- {
640
- type: "text",
641
- value: h.key,
642
- placeholder: "key",
643
- onChange: (E) => {
644
- const z = R.meta.customFields.map(
645
- (q, J) => J === $ ? { ...q, key: E.target.value } : q
646
- );
647
- F({ customFields: z });
648
- },
649
- style: { ...ae, flex: "0 0 80px", width: 80 }
650
- }
651
- ),
652
- /* @__PURE__ */ t(
653
- "input",
654
- {
655
- type: "text",
656
- value: h.value,
657
- placeholder: "value",
658
- onChange: (E) => {
659
- const z = R.meta.customFields.map(
660
- (q, J) => J === $ ? { ...q, value: E.target.value } : q
661
- );
662
- F({ customFields: z });
663
- },
664
- style: { ...ae, flex: 1 }
665
- }
666
- ),
667
- /* @__PURE__ */ t(
668
- "button",
669
- {
670
- onClick: () => F({ customFields: R.meta.customFields.filter((E, z) => z !== $) }),
671
- style: {
672
- flexShrink: 0,
673
- background: "none",
674
- border: `1px solid ${x.border}`,
675
- color: x.textMuted,
676
- borderRadius: 4,
677
- width: 22,
678
- height: 22,
679
- cursor: "pointer",
680
- fontSize: 12,
681
- lineHeight: 1,
682
- padding: 0
683
- },
684
- title: "Remove field",
685
- children: "×"
686
- }
687
- )
688
- ] }, $)),
689
- /* @__PURE__ */ t(
690
- "button",
691
- {
692
- onClick: () => F({ customFields: [...R.meta.customFields, { key: "", value: "" }] }),
693
- style: {
694
- width: "100%",
695
- marginTop: 2,
696
- background: "none",
697
- border: `1px dashed ${x.border}`,
698
- color: x.textMuted,
699
- borderRadius: 4,
700
- padding: "4px",
701
- cursor: "pointer",
702
- fontSize: 11
703
- },
704
- children: "+ Add Field"
705
- }
706
- )
707
- ] })
708
- ] }) }),
709
- /* @__PURE__ */ d("div", { style: {
710
- flexShrink: 0,
711
- padding: "10px 12px",
712
- borderTop: `1px solid ${x.border}`,
713
- display: "flex",
714
- gap: 6
715
- }, children: [
716
- /* @__PURE__ */ t(
717
- "button",
718
- {
719
- onClick: P ?? He,
720
- style: {
721
- flex: 1,
722
- background: x.accent,
723
- border: "none",
724
- color: "#0e1118",
725
- borderRadius: 4,
726
- padding: "6px",
727
- cursor: "pointer",
728
- fontSize: 11,
729
- fontWeight: 600
730
- },
731
- children: "Export"
732
- }
733
- ),
734
- /* @__PURE__ */ t(
735
- "button",
736
- {
737
- onClick: T ?? Ue,
738
- style: {
739
- flex: 1,
740
- background: x.blockBody,
741
- border: `1px solid ${x.border}`,
742
- color: x.textPrimary,
743
- borderRadius: 4,
744
- padding: "6px",
745
- cursor: "pointer",
746
- fontSize: 11
747
- },
748
- children: "Import"
749
- }
750
- )
751
- ] })
752
- ] }),
753
- !i && /* @__PURE__ */ t(xt, { ..._e })
754
- ] })
755
- ] }) });
756
- }
757
- function xt({
758
- design: e,
759
- selectedId: n,
760
- onSelect: r,
761
- onMove: l,
762
- onResize: i,
763
- onUpdate: o,
764
- onDelete: a,
765
- onMoveZ: p,
766
- sel: C,
767
- theme: s,
768
- onUpdateBg: P,
769
- onAddText: T,
770
- onAddRect: v,
771
- onAddCircle: c,
772
- onAddImage: k
773
- }) {
774
- const x = st(s);
775
- return /* @__PURE__ */ d(at, { children: [
776
- /* @__PURE__ */ d("div", { style: {
777
- width: qe,
778
- flexShrink: 0,
779
- background: s.paletteBg,
780
- borderRight: `1px solid ${s.border}`,
781
- display: "flex",
782
- flexDirection: "column",
783
- overflow: "hidden"
784
- }, children: [
785
- /* @__PURE__ */ t(tt, { children: "Design Tools" }),
786
- /* @__PURE__ */ d("div", { style: { flex: 1, overflowY: "auto", padding: 12 }, children: [
787
- /* @__PURE__ */ d(rt, { children: [
788
- /* @__PURE__ */ t(nt, { children: "Background" }),
789
- /* @__PURE__ */ t($e, { lbl: "Color", children: /* @__PURE__ */ d("div", { style: { display: "flex", alignItems: "center", gap: 8 }, children: [
790
- /* @__PURE__ */ t(
791
- "input",
792
- {
793
- type: "color",
794
- value: e.background.color,
795
- onChange: (M) => P({ color: M.target.value }),
796
- style: { width: 32, height: 24, border: "none", padding: 0, cursor: "pointer", background: "none" }
797
- }
798
- ),
799
- /* @__PURE__ */ t("span", { style: { fontSize: 11, color: s.textMuted }, children: e.background.color })
800
- ] }) }),
801
- /* @__PURE__ */ t($e, { lbl: "Image URL", children: /* @__PURE__ */ t(
802
- "input",
803
- {
804
- type: "text",
805
- value: e.background.imageUrl,
806
- style: x,
807
- placeholder: "https://…",
808
- onChange: (M) => P({ imageUrl: M.target.value })
809
- }
810
- ) })
811
- ] }),
812
- /* @__PURE__ */ d(rt, { children: [
813
- /* @__PURE__ */ t(nt, { children: "Add Element" }),
814
- /* @__PURE__ */ t("div", { style: { display: "grid", gridTemplateColumns: "1fr 1fr", gap: 6 }, children: [
815
- { label: "Text", icon: "T", fn: T },
816
- { label: "Rect", icon: "□", fn: v },
817
- { label: "Circle", icon: "○", fn: c },
818
- { label: "Image", icon: "⬛", fn: k }
819
- ].map(({ label: M, icon: I, fn: _ }) => /* @__PURE__ */ d("button", { onClick: _, style: {
820
- background: s.blockBody,
821
- border: `1px solid ${s.border}`,
822
- color: s.textPrimary,
823
- borderRadius: 4,
824
- padding: "7px 4px",
825
- cursor: "pointer",
826
- fontSize: 11,
827
- display: "flex",
828
- alignItems: "center",
829
- gap: 5,
830
- justifyContent: "center"
831
- }, children: [
832
- /* @__PURE__ */ t("span", { style: { fontFamily: "monospace", fontSize: 13 }, children: I }),
833
- M
834
- ] }, M)) })
835
- ] })
836
- ] })
837
- ] }),
838
- /* @__PURE__ */ d("div", { style: {
839
- flex: 1,
840
- minWidth: 0,
841
- background: s.canvasBg,
842
- display: "flex",
843
- alignItems: "center",
844
- justifyContent: "center",
845
- overflow: "hidden",
846
- position: "relative"
847
- }, children: [
848
- /* @__PURE__ */ t("div", { style: {
849
- position: "absolute",
850
- inset: 0,
851
- pointerEvents: "none",
852
- backgroundImage: `radial-gradient(circle, ${s.gridDot} 1px, transparent 1px)`,
853
- backgroundSize: "20px 20px"
854
- } }),
855
- /* @__PURE__ */ t(
856
- jt,
857
- {
858
- design: e,
859
- selectedId: n,
860
- onSelect: r,
861
- onMove: l,
862
- onResize: i
863
- }
864
- )
865
- ] }),
866
- /* @__PURE__ */ d("div", { style: {
867
- width: qe,
868
- flexShrink: 0,
869
- background: s.paletteBg,
870
- borderLeft: `1px solid ${s.border}`,
871
- display: "flex",
872
- flexDirection: "column",
873
- overflow: "hidden"
874
- }, children: [
875
- /* @__PURE__ */ t(tt, { children: "Element Properties" }),
876
- /* @__PURE__ */ t("div", { style: { flex: 1, overflowY: "auto", padding: 12 }, children: C ? /* @__PURE__ */ t(
877
- Ut,
878
- {
879
- el: C,
880
- onUpdate: o,
881
- onDelete: a,
882
- onMoveZ: p
883
- }
884
- ) : /* @__PURE__ */ d("div", { style: { color: s.textMuted, fontSize: 12, textAlign: "center", marginTop: 40, lineHeight: 1.6 }, children: [
885
- "Select an element on",
886
- /* @__PURE__ */ t("br", {}),
887
- "the card to edit it"
888
- ] }) })
889
- ] })
890
- ] });
891
- }
892
- function st(e) {
893
- return {
894
- width: "100%",
895
- background: e.inputBg,
896
- border: `1px solid ${e.inputBorder}`,
877
+ const X = {
878
+ background: s.inputBg,
879
+ color: s.textPrimary,
880
+ border: `1px solid ${s.inputBorder}`,
897
881
  borderRadius: 4,
898
- color: e.textPrimary,
899
- fontSize: 12,
882
+ fontSize: 11,
900
883
  padding: "4px 6px",
901
884
  outline: "none",
902
- boxSizing: "border-box"
903
- };
904
- }
905
- function tt({ children: e }) {
906
- const n = G();
907
- return /* @__PURE__ */ t("div", { style: {
908
- padding: "8px 12px",
909
- background: n.paletteHeaderBg,
910
- borderBottom: `1px solid ${n.border}`,
911
- fontSize: 11,
912
- fontWeight: 600,
913
- color: n.textSecondary,
914
- letterSpacing: "0.05em",
915
- textTransform: "uppercase",
916
- flexShrink: 0
917
- }, children: e });
918
- }
919
- function nt({ children: e }) {
920
- const n = G();
921
- return /* @__PURE__ */ t("div", { style: {
922
- fontSize: 10,
923
- fontWeight: 700,
924
- color: n.accent,
925
- marginBottom: 8,
926
- letterSpacing: "0.08em",
927
- textTransform: "uppercase"
928
- }, children: e });
929
- }
930
- function rt({ children: e }) {
931
- const n = G();
932
- return /* @__PURE__ */ t("div", { style: { borderBottom: `1px solid ${n.border}`, paddingBottom: 12, marginBottom: 12 }, children: e });
933
- }
934
- function $e({ lbl: e, children: n }) {
935
- const r = G();
936
- return /* @__PURE__ */ d("div", { style: { marginBottom: 8 }, children: [
937
- /* @__PURE__ */ t("label", { style: { fontSize: 11, color: r.textMuted, marginBottom: 2, display: "block" }, children: e }),
938
- n
939
- ] });
940
- }
941
- function Ut({ el: e, onUpdate: n, onDelete: r, onMoveZ: l }) {
942
- const i = G(), o = st(i), a = { fontSize: 11, color: i.textMuted, marginBottom: 2, display: "block" }, p = { borderBottom: `1px solid ${i.border}`, paddingBottom: 12, marginBottom: 12 }, C = { fontSize: 10, fontWeight: 700, color: i.accent, marginBottom: 8, letterSpacing: "0.08em", textTransform: "uppercase" }, s = {
943
- background: i.blockBody,
944
- border: `1px solid ${i.border}`,
945
- color: i.textPrimary,
885
+ minWidth: 0
886
+ }, re = {
887
+ background: "none",
888
+ color: s.textSecondary,
889
+ border: `1px solid ${s.border}`,
946
890
  borderRadius: 4,
947
- padding: "4px 6px",
948
- cursor: "pointer",
949
- fontSize: 11
950
- }, P = (c) => ({
951
- ...s,
952
- background: c ? i.accent : i.blockBody,
953
- color: c ? "#0e1118" : i.textPrimary
954
- });
955
- function T(c, k, x, M, I) {
956
- return /* @__PURE__ */ d("div", { children: [
957
- /* @__PURE__ */ t("label", { style: a, children: c }),
958
- /* @__PURE__ */ t(
959
- "input",
960
- {
961
- type: "number",
962
- value: x,
963
- min: M,
964
- max: I,
965
- onChange: (_) => n({ [k]: Number(_.target.value) }),
966
- style: o
967
- }
968
- )
969
- ] });
970
- }
971
- function v(c, k, x) {
972
- return /* @__PURE__ */ d("div", { style: { marginBottom: 8 }, children: [
973
- /* @__PURE__ */ t("label", { style: a, children: c }),
974
- /* @__PURE__ */ d("div", { style: { display: "flex", alignItems: "center", gap: 6 }, children: [
975
- /* @__PURE__ */ t(
976
- "input",
891
+ fontSize: 11,
892
+ padding: "4px 8px",
893
+ cursor: "pointer"
894
+ }, le = w ? o.get(w) ?? 0 : 0;
895
+ return /* @__PURE__ */ y("div", { style: { flex: 1, overflowY: "auto", padding: 10, display: "flex", flexDirection: "column", gap: 6 }, children: [
896
+ t.length === 0 && /* @__PURE__ */ a("div", { style: { color: s.textMuted, fontSize: 11, fontStyle: "italic" }, children: "No packages yet — add one to get blocks." }),
897
+ w && /* @__PURE__ */ y("div", { style: {
898
+ border: `1px solid ${s.deleteActiveBorder}`,
899
+ background: s.deleteActiveBg,
900
+ borderRadius: 4,
901
+ padding: "6px 8px",
902
+ fontSize: 11,
903
+ color: s.textPrimary
904
+ }, children: [
905
+ "Remove ",
906
+ /* @__PURE__ */ a("b", { children: w }),
907
+ "?",
908
+ " ",
909
+ le > 0 ? `Its ${le} block${le === 1 ? "" : "s"} on the canvas ${le === 1 ? "is" : "are"} deleted.` : "None of its blocks are on the canvas.",
910
+ /* @__PURE__ */ y("div", { style: { display: "flex", gap: 6, marginTop: 6 }, children: [
911
+ /* @__PURE__ */ a(
912
+ "button",
977
913
  {
978
- type: "color",
979
- value: x,
980
- onChange: (M) => n({ [k]: M.target.value }),
981
- style: { width: 32, height: 22, border: "none", padding: 0, cursor: "pointer", background: "none" }
914
+ type: "button",
915
+ onClick: () => k(w),
916
+ style: { ...re, background: s.deleteActiveBorder, color: "white", borderColor: s.deleteActiveBorder },
917
+ children: "Remove"
982
918
  }
983
919
  ),
984
- /* @__PURE__ */ t("span", { style: { fontSize: 11, color: i.textMuted }, children: x })
985
- ] })
986
- ] });
987
- }
988
- return /* @__PURE__ */ d("div", { children: [
989
- /* @__PURE__ */ t("div", { style: { fontSize: 10, color: i.accent, fontWeight: 700, letterSpacing: "0.1em", textTransform: "uppercase", marginBottom: 10 }, children: e.type }),
990
- /* @__PURE__ */ d("div", { style: p, children: [
991
- /* @__PURE__ */ t("div", { style: C, children: "Transform" }),
992
- /* @__PURE__ */ d("div", { style: { display: "grid", gridTemplateColumns: "1fr 1fr", gap: 6 }, children: [
993
- T("X", "x", e.x),
994
- T("Y", "y", e.y),
995
- T("W", "w", e.w, 1),
996
- T("H", "h", e.h, 1)
920
+ /* @__PURE__ */ a("button", { type: "button", onClick: () => N(null), style: re, children: "Cancel" })
997
921
  ] })
998
922
  ] }),
999
- e.type === "text" && /* @__PURE__ */ d("div", { style: p, children: [
1000
- /* @__PURE__ */ t("div", { style: C, children: "Text" }),
1001
- /* @__PURE__ */ d("div", { style: { marginBottom: 8 }, children: [
1002
- /* @__PURE__ */ t("label", { style: a, children: "Content" }),
1003
- /* @__PURE__ */ t(
1004
- "textarea",
1005
- {
1006
- value: e.content,
1007
- onChange: (c) => n({ content: c.target.value }),
1008
- style: { ...o, height: 72, resize: "none" }
1009
- }
1010
- )
1011
- ] }),
1012
- /* @__PURE__ */ d("div", { style: { display: "grid", gridTemplateColumns: "1fr 1fr", gap: 6, marginBottom: 8 }, children: [
1013
- /* @__PURE__ */ d("div", { children: [
1014
- /* @__PURE__ */ t("label", { style: a, children: "Font Size" }),
1015
- /* @__PURE__ */ t(
1016
- "input",
1017
- {
1018
- type: "number",
1019
- value: e.fontSize,
1020
- min: 6,
1021
- max: 96,
1022
- onChange: (c) => n({ fontSize: Number(c.target.value) }),
1023
- style: o
1024
- }
1025
- )
1026
- ] }),
1027
- /* @__PURE__ */ d("div", { children: [
1028
- /* @__PURE__ */ t("label", { style: a, children: "Color" }),
1029
- /* @__PURE__ */ t(
1030
- "input",
1031
- {
1032
- type: "color",
1033
- value: e.color,
1034
- onChange: (c) => n({ color: c.target.value }),
1035
- style: { width: "100%", height: 28, border: "none", padding: 0, cursor: "pointer", background: "none" }
1036
- }
1037
- )
1038
- ] })
1039
- ] }),
1040
- /* @__PURE__ */ d("div", { style: { display: "flex", gap: 4 }, children: [
1041
- /* @__PURE__ */ t(
1042
- "button",
923
+ t.map((x) => {
924
+ const T = J(x), q = I.get(T), Y = q && co(q.version, x.version) > 0 ? q.version : null, ae = i.get(T) ?? 0;
925
+ return /* @__PURE__ */ y("div", { style: { display: "flex", alignItems: "center", gap: 6, fontSize: 11 }, children: [
926
+ /* @__PURE__ */ a("span", { "aria-hidden": !0, style: { width: 9, height: 9, flexShrink: 0, background: q?.color ?? s.border } }),
927
+ /* @__PURE__ */ a("span", { title: q?.description, style: {
928
+ color: s.textPrimary,
929
+ overflow: "hidden",
930
+ textOverflow: "ellipsis",
931
+ whiteSpace: "nowrap"
932
+ }, children: T }),
933
+ /* @__PURE__ */ a("span", { style: { color: s.textMuted, fontVariantNumeric: "tabular-nums" }, children: x.version }),
934
+ ae > 0 && /* @__PURE__ */ y(
935
+ "span",
1043
936
  {
1044
- onClick: () => n({ fontWeight: e.fontWeight === "bold" ? "normal" : "bold" }),
1045
- style: { ...P(e.fontWeight === "bold"), flex: 1, fontWeight: "bold" },
1046
- children: "B"
937
+ title: `${ae} block ID(s) skipped: another package already defines them`,
938
+ style: { fontSize: 9, color: s.accent, border: `1px solid ${s.accent}`, borderRadius: 3, padding: "0 3px" },
939
+ children: [
940
+ "⚠ ",
941
+ ae
942
+ ]
1047
943
  }
1048
944
  ),
1049
- /* @__PURE__ */ t(
945
+ Y && /* @__PURE__ */ y(
1050
946
  "button",
1051
947
  {
1052
- onClick: () => n({ fontStyle: e.fontStyle === "italic" ? "normal" : "italic" }),
1053
- style: { ...P(e.fontStyle === "italic"), flex: 1, fontStyle: "italic" },
1054
- children: "I"
948
+ type: "button",
949
+ onClick: () => ne(T, Y),
950
+ title: `Version ${Y} is available. Click to update.`,
951
+ style: { ...re, padding: "0 5px", fontSize: 10, color: s.accent, borderColor: s.accent },
952
+ children: [
953
+ Y,
954
+ " available"
955
+ ]
1055
956
  }
1056
957
  ),
1057
- ["left", "center", "right"].map((c) => /* @__PURE__ */ t(
958
+ /* @__PURE__ */ a(
1058
959
  "button",
1059
960
  {
1060
- onClick: () => n({ align: c }),
1061
- style: { ...P(e.align === c), flex: 1 },
1062
- children: c === "left" ? "⇤" : c === "center" ? "⇔" : "⇥"
1063
- },
1064
- c
1065
- ))
1066
- ] })
1067
- ] }),
1068
- (e.type === "rectangle" || e.type === "circle") && /* @__PURE__ */ d("div", { style: p, children: [
1069
- /* @__PURE__ */ t("div", { style: C, children: "Appearance" }),
1070
- v("Fill", "fill", e.fill),
1071
- v("Stroke", "stroke", e.stroke),
1072
- /* @__PURE__ */ d("div", { style: { marginBottom: e.type === "rectangle" ? 8 : 0 }, children: [
1073
- /* @__PURE__ */ t("label", { style: a, children: "Stroke Width" }),
1074
- /* @__PURE__ */ t(
1075
- "input",
1076
- {
1077
- type: "number",
1078
- value: e.strokeWidth,
1079
- min: 0,
1080
- max: 20,
1081
- onChange: (c) => n({ strokeWidth: Number(c.target.value) }),
1082
- style: o
961
+ type: "button",
962
+ onClick: () => N(T),
963
+ title: "Remove package",
964
+ style: { marginLeft: "auto", background: "none", border: "none", color: s.textMuted, fontSize: 15, lineHeight: 1, cursor: "pointer" },
965
+ children: "×"
1083
966
  }
1084
967
  )
968
+ ] }, T);
969
+ }),
970
+ /* @__PURE__ */ y("div", { style: { display: "flex", gap: 6, marginTop: 4 }, children: [
971
+ /* @__PURE__ */ y("select", { value: c, onChange: (x) => f(x.target.value), style: { ...X, flex: 1 }, children: [
972
+ /* @__PURE__ */ a("option", { value: "", children: K.length ? "Add package…" : "No more packages" }),
973
+ K.map((x) => /* @__PURE__ */ y("option", { value: J(x), children: [
974
+ J(x),
975
+ " ",
976
+ x.version
977
+ ] }, J(x)))
1085
978
  ] }),
1086
- e.type === "rectangle" && /* @__PURE__ */ d("div", { children: [
1087
- /* @__PURE__ */ t("label", { style: a, children: "Corner Radius" }),
1088
- /* @__PURE__ */ t(
1089
- "input",
1090
- {
1091
- type: "number",
1092
- value: e.rx,
1093
- min: 0,
1094
- max: 140,
1095
- onChange: (c) => n({ rx: Number(c.target.value) }),
1096
- style: o
1097
- }
1098
- )
1099
- ] })
1100
- ] }),
1101
- e.type === "image" && /* @__PURE__ */ d("div", { style: p, children: [
1102
- /* @__PURE__ */ t("div", { style: C, children: "Image" }),
1103
- /* @__PURE__ */ t("label", { style: a, children: "URL or Data URI" }),
1104
- /* @__PURE__ */ t(
979
+ B && /* @__PURE__ */ a(
1105
980
  "input",
1106
981
  {
1107
- type: "text",
1108
- value: e.src,
1109
- style: o,
1110
- placeholder: "https://…",
1111
- onChange: (c) => n({ src: c.target.value })
982
+ value: g,
983
+ onChange: (x) => h(x.target.value),
984
+ placeholder: I.get(c)?.version ?? "version",
985
+ style: { ...X, width: 64 }
986
+ }
987
+ ),
988
+ /* @__PURE__ */ a(
989
+ "button",
990
+ {
991
+ type: "button",
992
+ onClick: G,
993
+ disabled: !c,
994
+ style: { ...re, opacity: c ? 1 : 0.4, cursor: c ? "pointer" : "default" },
995
+ children: "Add"
1112
996
  }
1113
997
  )
1114
998
  ] }),
1115
- /* @__PURE__ */ d("div", { style: { display: "flex", gap: 6, marginBottom: 8 }, children: [
1116
- /* @__PURE__ */ t("button", { onClick: () => l(-1), style: { ...s, flex: 1 }, children: "↓ Send Back" }),
1117
- /* @__PURE__ */ t("button", { onClick: () => l(1), style: { ...s, flex: 1 }, children: "↑ Bring Fwd" })
1118
- ] }),
1119
- /* @__PURE__ */ t("button", { onClick: r, style: {
1120
- width: "100%",
1121
- background: "#3a0c0c",
1122
- border: "1px solid #8a2020",
1123
- color: "#e06060",
1124
- borderRadius: 4,
1125
- padding: "6px",
1126
- cursor: "pointer",
1127
- fontSize: 11
1128
- }, children: "Delete Element" })
999
+ r && r.length > 0 && /* @__PURE__ */ a("div", { style: { display: "flex", flexWrap: "wrap", gap: 6 }, children: r.map((x) => /* @__PURE__ */ a("button", { type: "button", onClick: () => so(x, t, n), title: x.title, style: re, children: x.label }, x.label)) }),
1000
+ /* @__PURE__ */ a(
1001
+ "button",
1002
+ {
1003
+ type: "button",
1004
+ onClick: () => W((x) => !x),
1005
+ style: { alignSelf: "flex-start", background: "none", border: "none", padding: 0, color: s.textMuted, fontSize: 10, cursor: "pointer" },
1006
+ children: B ? "Hide version choice" : "Choose a specific version…"
1007
+ }
1008
+ )
1129
1009
  ] });
1130
1010
  }
1131
- const Kt = ie + 2 * B, Zt = pe + 2 * B;
1132
- function In({ design: e, uid: n, style: r, className: l }) {
1133
- const i = `cp-shadow-${n}`, o = `cp-clip-${n}`;
1134
- return /* @__PURE__ */ d(
1135
- "svg",
1136
- {
1137
- viewBox: `0 0 ${Kt} ${Zt}`,
1138
- preserveAspectRatio: "xMidYMid meet",
1139
- style: { display: "block", ...r },
1140
- className: l,
1141
- children: [
1142
- /* @__PURE__ */ d("defs", { children: [
1143
- /* @__PURE__ */ t("filter", { id: i, x: "-30%", y: "-20%", width: "160%", height: "150%", children: /* @__PURE__ */ t("feDropShadow", { dx: "0", dy: "4", stdDeviation: "8", floodColor: "rgba(0,0,0,0.55)" }) }),
1144
- /* @__PURE__ */ t("clipPath", { id: o, children: /* @__PURE__ */ t("rect", { x: B, y: B, width: ie, height: pe, rx: Me }) })
1145
- ] }),
1146
- /* @__PURE__ */ t(
1147
- "rect",
1148
- {
1149
- x: B,
1150
- y: B,
1151
- width: ie,
1152
- height: pe,
1153
- rx: Me,
1154
- fill: e.background.color,
1155
- filter: `url(#${i})`
1156
- }
1157
- ),
1158
- e.background.imageUrl && /* @__PURE__ */ t(
1159
- "image",
1160
- {
1161
- href: e.background.imageUrl,
1162
- x: B,
1163
- y: B,
1164
- width: ie,
1165
- height: pe,
1166
- clipPath: `url(#${o})`,
1167
- preserveAspectRatio: "xMidYMid slice"
1168
- }
1169
- ),
1170
- /* @__PURE__ */ t("g", { clipPath: `url(#${o})`, children: e.elements.map((a, p) => /* @__PURE__ */ t(Jt, { el: a, meta: e.meta }, a.id ?? p)) }),
1171
- /* @__PURE__ */ t(
1172
- "rect",
1173
- {
1174
- x: B,
1175
- y: B,
1176
- width: ie,
1177
- height: pe,
1178
- rx: Me,
1179
- fill: "none",
1180
- stroke: "rgba(255,255,255,0.13)",
1181
- strokeWidth: 1.5,
1182
- pointerEvents: "none"
1183
- }
1184
- )
1185
- ]
1186
- }
1187
- );
1188
- }
1189
- function Jt({ el: e, meta: n }) {
1190
- return e.type === "rectangle" ? /* @__PURE__ */ t(
1191
- "rect",
1192
- {
1193
- x: B + e.x,
1194
- y: B + e.y,
1195
- width: e.w,
1196
- height: e.h,
1197
- rx: e.rx,
1198
- fill: e.fill,
1199
- stroke: e.stroke,
1200
- strokeWidth: e.strokeWidth
1201
- }
1202
- ) : e.type === "circle" ? /* @__PURE__ */ t(
1203
- "ellipse",
1204
- {
1205
- cx: B + e.x + e.w / 2,
1206
- cy: B + e.y + e.h / 2,
1207
- rx: e.w / 2,
1208
- ry: e.h / 2,
1209
- fill: e.fill,
1210
- stroke: e.stroke,
1211
- strokeWidth: e.strokeWidth
1212
- }
1213
- ) : e.type === "image" ? /* @__PURE__ */ t(
1214
- "image",
1215
- {
1216
- href: e.src,
1217
- x: B + e.x,
1218
- y: B + e.y,
1219
- width: e.w,
1220
- height: e.h,
1221
- preserveAspectRatio: "xMidYMid slice"
1222
- }
1223
- ) : e.type === "text" ? /* @__PURE__ */ t(
1224
- "foreignObject",
1225
- {
1226
- x: B + e.x,
1227
- y: B + e.y,
1228
- width: e.w,
1229
- height: e.h,
1230
- style: { overflow: "visible" },
1231
- children: /* @__PURE__ */ t("div", { style: {
1232
- width: "100%",
1233
- height: "100%",
1234
- overflow: "hidden",
1235
- fontSize: `${e.fontSize}px`,
1236
- fontWeight: e.fontWeight,
1237
- fontStyle: e.fontStyle,
1238
- color: e.color,
1239
- textAlign: e.align,
1240
- lineHeight: 1.35,
1241
- boxSizing: "border-box",
1242
- padding: "2px 4px",
1243
- whiteSpace: "pre-wrap",
1244
- wordBreak: "break-word"
1245
- }, children: kt(e.content, n) })
1246
- }
1247
- ) : null;
1248
- }
1249
- const ye = /* @__PURE__ */ new Map(), Qe = /* @__PURE__ */ new Map(), Ae = /* @__PURE__ */ new Map();
1250
- async function ot(e) {
1251
- const n = await fetch(e.url);
1252
- if (!n.ok) throw new Error(`HTTP ${n.status} fetching ${e.url}`);
1253
- const r = await n.json(), l = [], i = [];
1254
- for (const a of r)
1255
- ye.has(a.id) ? i.push(a.id) : (ye.set(a.id, a), Qe.set(a.id, e.id), l.push(a.id));
1256
- const o = { info: e, blockIds: l, conflictIds: i };
1257
- return Ae.set(e.id, o), o;
1258
- }
1259
- function mt(e) {
1260
- const n = Ae.get(e);
1261
- if (n) {
1262
- for (const r of n.blockIds)
1263
- ye.delete(r), Qe.delete(r);
1264
- Ae.delete(e);
1265
- }
1266
- }
1267
- function Xe() {
1268
- return Array.from(Ae.values());
1269
- }
1270
- function Re(e) {
1271
- const n = ye.get(e);
1272
- if (!n) throw new Error(`Block definition not found: "${e}"`);
1273
- return n;
1274
- }
1275
- function ne(e) {
1276
- return ye.get(e);
1277
- }
1278
- function It() {
1279
- return [...ye.values()];
1280
- }
1281
- function Gt() {
1282
- return [...new Set(It().map((e) => e.category))];
1283
- }
1284
- function en(e, n) {
1285
- const r = [], l = [];
1286
- for (const o of n)
1287
- ye.has(o.id) ? l.push(o.id) : (ye.set(o.id, o), Qe.set(o.id, e.id), r.push(o.id));
1288
- const i = { info: e, blockIds: r, conflictIds: l };
1289
- return Ae.set(e.id, i), i;
1290
- }
1291
- async function tn(e) {
1292
- ye.clear(), Qe.clear(), Ae.clear(), await ot({ id: "__core__", name: "Core", description: "Built-in blocks", url: e, builtIn: !0 });
1293
- }
1294
- const nn = 36, ue = 50, be = 24, pt = 26, it = 12, bt = 12, Bt = 8, $t = 6, Tt = /* @__PURE__ */ new Set(["number", "string", "boolean"]);
1295
- function Ct(e) {
1296
- return e.blockType === "query" && e.returnType ? `${e.name} [${e.returnType}]` : e.name;
1297
- }
1298
- const rn = {
1299
- number: { w: 44, h: be },
1300
- string: { w: 60, h: be },
1301
- boolean: { w: 52, h: be }
1302
- }, on = { w: 75, h: be };
1303
- function Pt(e) {
1304
- return rn[e] ?? on;
1305
- }
1306
- function Mt(e, n, r) {
1307
- if (n?.queryBlockId && r) {
1308
- const l = r.get(n.queryBlockId);
1309
- if (l) {
1310
- const i = ne(l.definitionId);
1311
- if (i) return we(i, l.paramSlots, r);
1312
- }
1313
- }
1314
- return Pt(e).w;
1315
- }
1316
- function ut(e) {
1317
- return Math.max(72, e.length * 6 + 22);
1318
- }
1319
- function we(e, n, r) {
1320
- let l = it + bt + Ct(e).length * $t;
1321
- for (let o = 0; o < e.params.length; o++)
1322
- l += Bt + Mt(e.params[o].type, n?.[o], r);
1323
- if (e.blockType === "start" && e.provides)
1324
- for (const o of e.provides)
1325
- l = Math.max(l, it + ut(o.name) + bt);
1326
- const i = e.blockType === "start" ? 140 : 110;
1327
- return Math.max(i, l);
1328
- }
1329
- function Ie(e) {
1330
- if (e.blockType === "start") {
1331
- const n = e.provides?.length ?? 0;
1332
- return ue + (n > 0 ? 8 + n * pt : 0);
1333
- }
1334
- return e.blockType === "command" ? nn : be;
1335
- }
1336
- function Oe(e, n, r) {
1337
- const l = e.blockType === "start" ? ue : Ie(e), i = [];
1338
- let o = it + Ct(e).length * $t;
1339
- for (let a = 0; a < e.params.length; a++) {
1340
- const p = e.params[a], C = Mt(p.type, n?.[a], r), s = Pt(p.type).h;
1341
- o += Bt, i.push({ x: o, y: (l - s) / 2, w: C, h: s, type: p.type, index: a }), o += C;
1342
- }
1343
- return i;
1344
- }
1345
- const Se = 16, je = 14, lt = Se + je / 2, ct = 5, te = 4;
1346
- function ft(e, n) {
1347
- return [
1348
- `M ${te} 0`,
1349
- // Top edge with inlet (triangle dips into the block)
1350
- `H ${Se} L ${lt} ${ct} L ${Se + je} 0`,
1351
- `H ${e - te} Q ${e} 0 ${e} ${te}`,
1352
- `V ${n - te} Q ${e} ${n} ${e - te} ${n}`,
1353
- // Bottom edge with outlet (triangle protrudes below)
1354
- `H ${Se + je} L ${lt} ${n + ct} L ${Se} ${n}`,
1355
- `H ${te} Q 0 ${n} 0 ${n - te}`,
1356
- `V ${te} Q 0 0 ${te} 0 Z`
1357
- ].join(" ");
1358
- }
1359
- function ht(e, n) {
1360
- return [
1361
- "M 0 10 Q 0 0 10 0",
1362
- `H ${e - 10} Q ${e} 0 ${e} 10`,
1363
- `V ${n - te} Q ${e} ${n} ${e - te} ${n}`,
1364
- // Bottom outlet only — start blocks have no inlet
1365
- `H ${Se + je} L ${lt} ${n + ct} L ${Se} ${n}`,
1366
- `H ${te} Q 0 ${n} 0 ${n - te}`,
1367
- "V 10 Z"
1368
- ].join(" ");
1369
- }
1370
- function ln(e, n) {
1371
- const r = n / 2;
1372
- return [
1373
- `M ${r} 0 H ${e - r}`,
1374
- `A ${r} ${r} 0 0 1 ${e - r} ${n}`,
1375
- `H ${r} A ${r} ${r} 0 0 1 ${r} 0 Z`
1376
- ].join(" ");
1377
- }
1378
- function cn(e, n) {
1379
- const r = n / 2;
1380
- return [
1381
- `M ${r} 0 H ${e - r}`,
1382
- `L ${e} ${n / 2} L ${e - r} ${n}`,
1383
- `H ${r} L 0 ${n / 2} Z`
1384
- ].join(" ");
1385
- }
1386
- function At(e, n, r) {
1387
- return [
1388
- `M ${r} 0 H ${e - r} Q ${e} 0 ${e} ${r}`,
1389
- `V ${n - r} Q ${e} ${n} ${e - r} ${n}`,
1390
- `H ${r} Q 0 ${n} 0 ${n - r}`,
1391
- `V ${r} Q 0 0 ${r} 0 Z`
1392
- ].join(" ");
1393
- }
1394
- function dn(e, n) {
1395
- return At(e, n, 5);
1396
- }
1397
- function an(e, n) {
1398
- return At(e, n, 9);
1399
- }
1400
- function ze(e, n, r) {
1401
- switch (e) {
1402
- case "number":
1403
- return ln(n, r);
1404
- case "boolean":
1405
- return cn(n, r);
1406
- case "string":
1407
- return dn(n, r);
1408
- default:
1409
- return an(n, r);
1410
- }
1011
+ const Jo = "#c08820";
1012
+ function Ut({ mouths: e, w: t, isEmpty: n }) {
1013
+ const r = ee();
1014
+ return /* @__PURE__ */ a("g", { style: { pointerEvents: "none" }, children: e.map((o) => /* @__PURE__ */ y("g", { children: [
1015
+ o.dividerY !== null && /* @__PURE__ */ y("g", { style: { pointerEvents: "all" }, children: [
1016
+ /* @__PURE__ */ a("title", { children: lt(o.name, Tt) }),
1017
+ /* @__PURE__ */ a("rect", { x: 0, y: o.dividerY, width: t, height: Ct, fill: "transparent" }),
1018
+ /* @__PURE__ */ a(
1019
+ "text",
1020
+ {
1021
+ x: 11,
1022
+ y: o.dividerY + Ct / 2 + 4,
1023
+ fill: r.blockText,
1024
+ fontSize: 10,
1025
+ fontWeight: "bold",
1026
+ fontFamily: "sans-serif",
1027
+ style: { userSelect: "none" },
1028
+ children: o.name
1029
+ }
1030
+ )
1031
+ ] }),
1032
+ n(o.index) && /* @__PURE__ */ y("g", { style: { pointerEvents: "all" }, children: [
1033
+ /* @__PURE__ */ a("title", { children: lt(o.name, Tt) }),
1034
+ /* @__PURE__ */ a(
1035
+ "rect",
1036
+ {
1037
+ x: o.x + 3,
1038
+ y: o.y + 3,
1039
+ width: Math.max(60, o.name.length * 6 + 20),
1040
+ height: o.h - 6,
1041
+ rx: 3,
1042
+ fill: "transparent",
1043
+ stroke: Jo,
1044
+ strokeWidth: 1,
1045
+ strokeDasharray: "4,3"
1046
+ }
1047
+ ),
1048
+ /* @__PURE__ */ a(
1049
+ "text",
1050
+ {
1051
+ x: o.x + 10,
1052
+ y: o.y + o.h / 2 + 3,
1053
+ fill: r.textMuted,
1054
+ fontSize: 9,
1055
+ fontFamily: "sans-serif",
1056
+ fontStyle: "italic",
1057
+ style: { userSelect: "none" },
1058
+ children: o.name
1059
+ }
1060
+ )
1061
+ ] })
1062
+ ] }, o.index)) });
1411
1063
  }
1412
- function Wt(e, n, r) {
1413
- return ze(e, n, r);
1064
+ function An({ name: e, type: t, w: n, h: r }) {
1065
+ const o = ee();
1066
+ return /* @__PURE__ */ a(
1067
+ "text",
1068
+ {
1069
+ x: n / 2,
1070
+ y: r / 2 + 3,
1071
+ textAnchor: "middle",
1072
+ fill: o.textMuted,
1073
+ fontSize: 9,
1074
+ fontFamily: "sans-serif",
1075
+ fontStyle: "italic",
1076
+ style: { userSelect: "none", pointerEvents: "none" },
1077
+ children: Wo(e, t, n)
1078
+ }
1079
+ );
1414
1080
  }
1415
- function Et({ def: e, onPointerDown: n, isPlaced: r }) {
1416
- const l = G(), i = we(e), o = Ie(e), a = Oe(e), p = `pal-${e.id}`;
1417
- let C;
1418
- return e.blockType === "start" ? C = ht(i, o) : e.blockType === "command" ? C = ft(i, o) : C = ze(e.returnType, i, be), /* @__PURE__ */ t(
1081
+ function _n({ def: e, onPointerDown: t, isPlaced: n }) {
1082
+ const r = ee(), o = ue(e), i = be(e), s = je(e), c = Ee(e), f = `pal-${e.id}`, g = Vt(e);
1083
+ return /* @__PURE__ */ a(
1419
1084
  "div",
1420
1085
  {
1421
- style: { marginBottom: 6, userSelect: "none", position: "relative", opacity: r ? 0.4 : 1 },
1422
- onPointerDown: r ? void 0 : (s) => n(s, e.id),
1423
- title: r ? "Already on canvas — only one instance allowed" : void 0,
1424
- children: /* @__PURE__ */ d("svg", { width: i + 2, height: o + 8, style: { display: "block", cursor: r ? "not-allowed" : "grab", overflow: "visible" }, children: [
1425
- /* @__PURE__ */ t("defs", { children: /* @__PURE__ */ t("clipPath", { id: p, children: /* @__PURE__ */ t("path", { d: C }) }) }),
1426
- /* @__PURE__ */ d("g", { transform: "translate(1, 1)", children: [
1427
- /* @__PURE__ */ t("path", { d: C, fill: l.blockBody, stroke: l.blockBorder, strokeWidth: 1.5 }),
1428
- /* @__PURE__ */ t(
1086
+ style: { marginBottom: 6, userSelect: "none", position: "relative", opacity: n ? 0.4 : 1 },
1087
+ onPointerDown: n ? void 0 : (h) => t(h, e.id),
1088
+ title: n ? "Already on canvas — only one instance allowed" : void 0,
1089
+ children: /* @__PURE__ */ y("svg", { width: o + 2, height: i + 8, style: { display: "block", cursor: n ? "not-allowed" : "grab", overflow: "visible" }, children: [
1090
+ /* @__PURE__ */ a("defs", { children: /* @__PURE__ */ a("clipPath", { id: f, children: /* @__PURE__ */ a("path", { d: g }) }) }),
1091
+ /* @__PURE__ */ y("g", { transform: "translate(1, 1)", children: [
1092
+ /* @__PURE__ */ a("path", { d: g, fill: r.blockBody, stroke: r.blockBorder, strokeWidth: 1.5 }),
1093
+ /* @__PURE__ */ a(
1429
1094
  "rect",
1430
1095
  {
1431
1096
  x: 0,
1432
1097
  y: 0,
1433
1098
  width: 4,
1434
- height: o + 20,
1099
+ height: i + 20,
1435
1100
  fill: e.color,
1436
- clipPath: `url(#${p})`
1101
+ clipPath: `url(#${f})`
1437
1102
  }
1438
1103
  ),
1439
- /* @__PURE__ */ d(
1104
+ c.length > 0 && /* @__PURE__ */ a(Ut, { mouths: c, w: o, isEmpty: () => !0 }),
1105
+ /* @__PURE__ */ y(
1440
1106
  "text",
1441
1107
  {
1442
1108
  x: 11,
1443
- y: (e.blockType === "start" ? ue : o) / 2 + 4,
1444
- fill: l.blockText,
1109
+ y: Xe(e) / 2 + 4,
1110
+ fill: r.blockText,
1445
1111
  fontSize: 11,
1446
1112
  fontWeight: "bold",
1447
1113
  fontFamily: "sans-serif",
1448
1114
  style: { userSelect: "none", pointerEvents: "none" },
1449
1115
  children: [
1450
1116
  e.name,
1451
- e.blockType === "query" && e.returnType && /* @__PURE__ */ t("tspan", { fill: l.textMuted, fontSize: 9, fontWeight: "normal", children: ` [${e.returnType}]` })
1117
+ e.blockType === "query" && e.returnType && /* @__PURE__ */ a("tspan", { fill: r.textMuted, fontSize: 9, fontWeight: "normal", children: ` [${e.returnType}]` })
1452
1118
  ]
1453
1119
  }
1454
1120
  ),
1455
- r && /* @__PURE__ */ t(
1121
+ n && /* @__PURE__ */ a(
1456
1122
  "text",
1457
1123
  {
1458
- x: i / 2,
1459
- y: o / 2 + 4,
1124
+ x: o / 2,
1125
+ y: i / 2 + 4,
1460
1126
  textAnchor: "middle",
1461
- fill: l.textMuted,
1127
+ fill: r.textMuted,
1462
1128
  fontSize: 9,
1463
1129
  fontFamily: "sans-serif",
1464
1130
  style: { userSelect: "none", pointerEvents: "none" },
1465
1131
  children: "✓ on canvas"
1466
1132
  }
1467
1133
  ),
1468
- a.map((s) => {
1469
- const P = e.params[s.index]?.name, T = !Tt.has(s.type);
1470
- return /* @__PURE__ */ d("g", { transform: `translate(${s.x},${s.y})`, children: [
1471
- /* @__PURE__ */ t(
1134
+ s.map((h) => {
1135
+ const B = e.params[h.index].name;
1136
+ return /* @__PURE__ */ y("g", { transform: `translate(${h.x},${h.y})`, children: [
1137
+ /* @__PURE__ */ a("title", { children: lt(B, h.type) }),
1138
+ /* @__PURE__ */ a(
1472
1139
  "path",
1473
1140
  {
1474
- d: Wt(s.type, s.w, s.h),
1475
- fill: l.socketBody,
1476
- stroke: l.blockBorder,
1141
+ d: Yt(h.type, h.w, h.h),
1142
+ fill: r.socketBody,
1143
+ stroke: r.blockBorder,
1477
1144
  strokeWidth: 1
1478
1145
  }
1479
1146
  ),
1480
- T ? /* @__PURE__ */ t(
1481
- "text",
1482
- {
1483
- x: s.w / 2,
1484
- y: s.h / 2 + 3,
1485
- textAnchor: "middle",
1486
- fill: l.textSecondary,
1487
- fontSize: 9,
1488
- fontFamily: "sans-serif",
1489
- style: { userSelect: "none", pointerEvents: "none" },
1490
- children: s.type
1491
- }
1492
- ) : P ? /* @__PURE__ */ t(
1493
- "text",
1494
- {
1495
- x: s.w / 2,
1496
- y: s.h / 2 + 3,
1497
- textAnchor: "middle",
1498
- fill: l.textMuted,
1499
- fontSize: 9,
1500
- fontFamily: "sans-serif",
1501
- fontStyle: "italic",
1502
- style: { userSelect: "none", pointerEvents: "none" },
1503
- children: P
1504
- }
1505
- ) : null
1506
- ] }, s.index);
1147
+ /* @__PURE__ */ a(An, { name: B, type: h.type, w: h.w, h: h.h })
1148
+ ] }, h.index);
1507
1149
  }),
1508
- e.blockType === "start" && e.provides && e.provides.length > 0 && /* @__PURE__ */ d("g", { children: [
1509
- /* @__PURE__ */ t(
1150
+ e.blockType === "start" && e.provides && e.provides.length > 0 && /* @__PURE__ */ y("g", { children: [
1151
+ /* @__PURE__ */ a(
1510
1152
  "line",
1511
1153
  {
1512
1154
  x1: 8,
1513
- y1: ue,
1514
- x2: i - 8,
1515
- y2: ue,
1155
+ y1: me,
1156
+ x2: o - 8,
1157
+ y2: me,
1516
1158
  stroke: "rgba(255,255,255,0.15)",
1517
1159
  strokeWidth: 1
1518
1160
  }
1519
1161
  ),
1520
- e.provides.map((s, P) => {
1521
- const v = ne(s.id)?.color ?? e.color, c = ut(s.name), k = 20;
1522
- return /* @__PURE__ */ d("g", { transform: `translate(8, ${ue + 6 + P * pt})`, children: [
1523
- /* @__PURE__ */ t(
1162
+ e.provides.map((h, B) => {
1163
+ const w = z(h.id)?.color ?? e.color, N = zt(h.name), I = 20;
1164
+ return /* @__PURE__ */ y("g", { transform: `translate(8, ${me + 6 + B * Ht})`, children: [
1165
+ /* @__PURE__ */ a(
1524
1166
  "rect",
1525
1167
  {
1526
1168
  x: 0,
1527
1169
  y: 0,
1528
- width: c,
1529
- height: k,
1170
+ width: N,
1171
+ height: I,
1530
1172
  rx: 10,
1531
- fill: v,
1173
+ fill: w,
1532
1174
  opacity: 0.82,
1533
1175
  stroke: "rgba(255,255,255,0.25)",
1534
1176
  strokeWidth: 1
1535
1177
  }
1536
1178
  ),
1537
- /* @__PURE__ */ t(
1179
+ /* @__PURE__ */ a(
1538
1180
  "text",
1539
1181
  {
1540
- x: c / 2,
1541
- y: k / 2 + 3.5,
1182
+ x: N / 2,
1183
+ y: I / 2 + 3.5,
1542
1184
  textAnchor: "middle",
1543
1185
  fill: "white",
1544
1186
  fontSize: 9.5,
1545
1187
  fontFamily: "sans-serif",
1546
1188
  fontWeight: "bold",
1547
1189
  style: { userSelect: "none", pointerEvents: "none" },
1548
- children: s.name
1190
+ children: h.name
1549
1191
  }
1550
1192
  )
1551
- ] }, s.id);
1193
+ ] }, h.id);
1552
1194
  })
1553
1195
  ] })
1554
1196
  ] })
@@ -1556,13 +1198,13 @@ function Et({ def: e, onPointerDown: n, isPlaced: r }) {
1556
1198
  }
1557
1199
  );
1558
1200
  }
1559
- function sn({ cat: e, defs: n, collapsed: r, onToggle: l, onPointerDown: i, placedStartIds: o }) {
1560
- const a = G();
1561
- return /* @__PURE__ */ d("div", { style: { marginBottom: 2 }, children: [
1562
- /* @__PURE__ */ d(
1201
+ function er({ cat: e, defs: t, collapsed: n, onToggle: r, onPointerDown: o, placedStartIds: i }) {
1202
+ const s = ee();
1203
+ return /* @__PURE__ */ y("div", { style: { marginBottom: 2 }, children: [
1204
+ /* @__PURE__ */ y(
1563
1205
  "button",
1564
1206
  {
1565
- onClick: () => l(e),
1207
+ onClick: () => r(e),
1566
1208
  style: {
1567
1209
  display: "flex",
1568
1210
  alignItems: "center",
@@ -1571,119 +1213,49 @@ function sn({ cat: e, defs: n, collapsed: r, onToggle: l, onPointerDown: i, plac
1571
1213
  background: "none",
1572
1214
  border: "none",
1573
1215
  padding: "5px 0 4px",
1574
- borderBottom: `1px solid ${a.border}`,
1216
+ borderBottom: `1px solid ${s.border}`,
1575
1217
  cursor: "pointer",
1576
1218
  textAlign: "left",
1577
- marginBottom: r ? 0 : 6
1219
+ marginBottom: n ? 0 : 6
1578
1220
  },
1579
1221
  children: [
1580
- /* @__PURE__ */ t("span", { style: { color: a.accent, fontSize: 8, lineHeight: 1, opacity: 0.6 }, children: r ? "▶" : "▼" }),
1581
- /* @__PURE__ */ t("span", { style: { color: a.accent, fontSize: 10, fontWeight: "bold", textTransform: "uppercase", letterSpacing: 1, opacity: 0.85 }, children: e }),
1582
- r && /* @__PURE__ */ t("span", { style: { color: a.textMuted, fontSize: 9, marginLeft: "auto" }, children: n.length })
1222
+ /* @__PURE__ */ a("span", { style: { color: s.accent, fontSize: 8, lineHeight: 1, opacity: 0.6 }, children: n ? "▶" : "▼" }),
1223
+ /* @__PURE__ */ a("span", { style: { color: s.accent, fontSize: 10, fontWeight: "bold", textTransform: "uppercase", letterSpacing: 1, opacity: 0.85 }, children: e }),
1224
+ n && /* @__PURE__ */ a("span", { style: { color: s.textMuted, fontSize: 9, marginLeft: "auto" }, children: t.length })
1583
1225
  ]
1584
1226
  }
1585
1227
  ),
1586
- !r && /* @__PURE__ */ t("div", { style: { paddingBottom: 4 }, children: n.map((p) => /* @__PURE__ */ t(
1587
- Et,
1228
+ !n && /* @__PURE__ */ a("div", { style: { paddingBottom: 4 }, children: t.map((c) => /* @__PURE__ */ a(
1229
+ _n,
1588
1230
  {
1589
- def: p,
1590
- onPointerDown: i,
1591
- isPlaced: p.blockType === "start" && o.has(p.id)
1231
+ def: c,
1232
+ onPointerDown: o,
1233
+ isPlaced: c.blockType === "start" && i.has(c.id)
1592
1234
  },
1593
- p.id
1235
+ c.id
1594
1236
  )) })
1595
1237
  ] });
1596
1238
  }
1597
- function pn({ pkg: e, loaded: n, toggling: r, onToggle: l }) {
1598
- const i = G(), o = !!n;
1599
- return /* @__PURE__ */ d("div", { style: {
1600
- display: "flex",
1601
- alignItems: "flex-start",
1602
- justifyContent: "space-between",
1603
- gap: 8,
1604
- padding: "10px 12px",
1605
- marginBottom: 6,
1606
- background: o ? i.pkgActiveBg : i.pkgBg,
1607
- border: `1px solid ${o ? i.pkgActiveBorder : i.pkgBorder}`,
1608
- borderRadius: 5
1609
- }, children: [
1610
- /* @__PURE__ */ d("div", { style: { flex: 1, minWidth: 0 }, children: [
1611
- /* @__PURE__ */ d("div", { style: { display: "flex", alignItems: "center", gap: 6, marginBottom: 2 }, children: [
1612
- /* @__PURE__ */ t("span", { style: { color: o ? i.pkgActiveText : i.pkgText, fontSize: 11, fontWeight: "bold", letterSpacing: 0.3 }, children: e.name }),
1613
- n && n.conflictIds.length > 0 && /* @__PURE__ */ d(
1614
- "span",
1615
- {
1616
- title: `${n.conflictIds.length} block ID(s) skipped due to conflicts`,
1617
- style: { fontSize: 9, color: i.accent, border: `1px solid ${i.accent}`, borderRadius: 3, padding: "1px 4px", opacity: 0.7 },
1618
- children: [
1619
- "⚠ ",
1620
- n.conflictIds.length
1621
- ]
1622
- }
1623
- )
1624
- ] }),
1625
- /* @__PURE__ */ t("div", { style: { color: i.pkgSubText, fontSize: 10 }, children: o ? `${n.blockIds.length} block${n.blockIds.length !== 1 ? "s" : ""} active` : e.description })
1626
- ] }),
1627
- /* @__PURE__ */ t(
1628
- "button",
1629
- {
1630
- disabled: r,
1631
- onClick: () => l(e, o),
1632
- title: o ? `Remove ${e.name}` : `Add ${e.name}`,
1633
- style: {
1634
- flexShrink: 0,
1635
- marginTop: 1,
1636
- width: 22,
1637
- height: 22,
1638
- background: "none",
1639
- border: `1px solid ${o ? "#804040" : "#407040"}`,
1640
- borderRadius: 4,
1641
- color: o ? "#c05050" : "#508050",
1642
- fontSize: 16,
1643
- lineHeight: 1,
1644
- cursor: r ? "wait" : "pointer",
1645
- display: "flex",
1646
- alignItems: "center",
1647
- justifyContent: "center",
1648
- padding: 0,
1649
- opacity: r ? 0.4 : 1,
1650
- transition: "opacity 0.1s"
1651
- },
1652
- children: r ? "…" : o ? "×" : "+"
1653
- }
1654
- )
1655
- ] });
1656
- }
1657
- function un({
1239
+ function tr({
1658
1240
  onPointerDown: e,
1659
- isDropTarget: n,
1660
- registryVersion: r,
1661
- availablePackages: l,
1662
- loadedPackages: i,
1663
- onPackageToggle: o,
1664
- placedStartIds: a
1241
+ isDropTarget: t,
1242
+ registryVersion: n,
1243
+ packages: r,
1244
+ placedStartIds: o
1665
1245
  }) {
1666
- const p = G(), [C, s] = U("blocks"), [P, T] = U(""), [v, c] = U(/* @__PURE__ */ new Set()), [k, x] = U(null), M = et(() => It().filter((g) => !g.category.startsWith("$")), [r]), I = et(() => Gt().filter((g) => !g.startsWith("$")), [r]), _ = P.trim().toLowerCase(), Q = _ ? M.filter((g) => g.name.toLowerCase().includes(_)) : null;
1667
- function re(g) {
1668
- c((F) => {
1669
- const Z = new Set(F);
1670
- return Z.has(g) ? Z.delete(g) : Z.add(g), Z;
1246
+ const i = ee(), [s, c] = P("blocks"), [f, g] = P(""), [h, B] = P(/* @__PURE__ */ new Set()), W = ze(() => Bn().filter((k) => !k.category.startsWith("$")), [n]), w = ze(() => Ao().filter((k) => !k.startsWith("$")), [n]), N = f.trim().toLowerCase(), I = N ? W.filter((k) => k.name.toLowerCase().includes(N)) : null;
1247
+ function v(k) {
1248
+ B((ne) => {
1249
+ const X = new Set(ne);
1250
+ return X.has(k) ? X.delete(k) : X.add(k), X;
1671
1251
  });
1672
1252
  }
1673
- async function R(g, F) {
1674
- x(g.id);
1675
- try {
1676
- await o(g, F);
1677
- } finally {
1678
- x(null);
1679
- }
1680
- }
1681
- const u = new Map(i.map((g) => [g.info.id, g])), A = i.filter((g) => g.info.id !== "__core__").length, Y = (g) => ({
1253
+ const K = r?.dependencies.length ?? 0, G = (k) => ({
1682
1254
  flex: 1,
1683
1255
  background: "none",
1684
1256
  border: "none",
1685
- borderBottom: `2px solid ${C === g ? p.accent : "transparent"}`,
1686
- color: C === g ? p.accent : p.textMuted,
1257
+ borderBottom: `2px solid ${s === k ? i.accent : "transparent"}`,
1258
+ color: s === k ? i.accent : i.textMuted,
1687
1259
  fontSize: 10,
1688
1260
  fontWeight: "bold",
1689
1261
  textTransform: "uppercase",
@@ -1692,72 +1264,72 @@ function un({
1692
1264
  cursor: "pointer",
1693
1265
  transition: "color 0.15s, border-color 0.15s"
1694
1266
  });
1695
- return /* @__PURE__ */ d("div", { style: {
1267
+ return /* @__PURE__ */ y("div", { style: {
1696
1268
  width: 260,
1697
1269
  minWidth: 260,
1698
- backgroundColor: p.paletteBg,
1699
- borderRight: `1px solid ${p.border}`,
1270
+ backgroundColor: i.paletteBg,
1271
+ borderRight: `1px solid ${i.border}`,
1700
1272
  display: "flex",
1701
1273
  flexDirection: "column",
1702
1274
  height: "100%",
1703
1275
  overflow: "hidden"
1704
1276
  }, children: [
1705
- /* @__PURE__ */ d("div", { style: { display: "flex", borderBottom: `1px solid ${p.border}`, flexShrink: 0, background: p.paletteHeaderBg }, children: [
1706
- /* @__PURE__ */ t("button", { style: Y("blocks"), onClick: () => s("blocks"), children: "Blocks" }),
1707
- /* @__PURE__ */ d("button", { style: Y("packages"), onClick: () => s("packages"), children: [
1277
+ r && /* @__PURE__ */ y("div", { style: { display: "flex", borderBottom: `1px solid ${i.border}`, flexShrink: 0, background: i.paletteHeaderBg }, children: [
1278
+ /* @__PURE__ */ a("button", { style: G("blocks"), onClick: () => c("blocks"), children: "Blocks" }),
1279
+ /* @__PURE__ */ y("button", { style: G("packages"), onClick: () => c("packages"), children: [
1708
1280
  "Packages",
1709
- A > 0 ? ` · ${A}` : ""
1281
+ K > 0 ? ` · ${K}` : ""
1710
1282
  ] })
1711
1283
  ] }),
1712
- C === "blocks" && /* @__PURE__ */ d(at, { children: [
1713
- /* @__PURE__ */ t("div", { style: { padding: "8px 10px 6px", flexShrink: 0 }, children: /* @__PURE__ */ t(
1284
+ s === "blocks" && /* @__PURE__ */ y(no, { children: [
1285
+ /* @__PURE__ */ a("div", { style: { padding: "8px 10px 6px", flexShrink: 0 }, children: /* @__PURE__ */ a(
1714
1286
  "input",
1715
1287
  {
1716
1288
  type: "search",
1717
1289
  placeholder: "Search blocks…",
1718
- value: P,
1719
- onChange: (g) => T(g.target.value),
1290
+ value: f,
1291
+ onChange: (k) => g(k.target.value),
1720
1292
  style: {
1721
1293
  width: "100%",
1722
1294
  boxSizing: "border-box",
1723
- background: p.inputBg,
1724
- border: `1px solid ${p.inputBorder}`,
1295
+ background: i.inputBg,
1296
+ border: `1px solid ${i.inputBorder}`,
1725
1297
  borderRadius: 4,
1726
- color: p.textPrimary,
1298
+ color: i.textPrimary,
1727
1299
  fontSize: 11,
1728
1300
  padding: "5px 9px",
1729
1301
  outline: "none"
1730
1302
  }
1731
1303
  }
1732
1304
  ) }),
1733
- /* @__PURE__ */ t("div", { style: { flex: 1, overflowY: "auto", padding: "4px 10px 0" }, children: Q ? Q.length > 0 ? Q.map((g) => /* @__PURE__ */ t(
1734
- Et,
1305
+ /* @__PURE__ */ a("div", { style: { flex: 1, overflowY: "auto", padding: "4px 10px 0" }, children: I ? I.length > 0 ? I.map((k) => /* @__PURE__ */ a(
1306
+ _n,
1735
1307
  {
1736
- def: g,
1308
+ def: k,
1737
1309
  onPointerDown: e,
1738
- isPlaced: g.blockType === "start" && a.has(g.id)
1310
+ isPlaced: k.blockType === "start" && o.has(k.id)
1739
1311
  },
1740
- g.id
1741
- )) : /* @__PURE__ */ t("div", { style: { color: p.textMuted, fontSize: 11, padding: "12px 0", textAlign: "center" }, children: "No blocks match" }) : I.map((g) => /* @__PURE__ */ t(
1742
- sn,
1312
+ k.id
1313
+ )) : /* @__PURE__ */ a("div", { style: { color: i.textMuted, fontSize: 11, padding: "12px 0", textAlign: "center" }, children: "No blocks match" }) : w.map((k) => /* @__PURE__ */ a(
1314
+ er,
1743
1315
  {
1744
- cat: g,
1745
- defs: M.filter((F) => F.category === g),
1746
- collapsed: v.has(g),
1747
- onToggle: re,
1316
+ cat: k,
1317
+ defs: W.filter((ne) => ne.category === k),
1318
+ collapsed: h.has(k),
1319
+ onToggle: v,
1748
1320
  onPointerDown: e,
1749
- placedStartIds: a
1321
+ placedStartIds: o
1750
1322
  },
1751
- g
1323
+ k
1752
1324
  )) }),
1753
- /* @__PURE__ */ t("div", { style: {
1325
+ /* @__PURE__ */ a("div", { style: {
1754
1326
  flexShrink: 0,
1755
1327
  margin: "8px 10px 10px",
1756
1328
  padding: "7px 10px",
1757
1329
  borderRadius: 4,
1758
- background: n ? p.deleteActiveBg : "transparent",
1759
- border: `1px dashed ${n ? p.deleteActiveBorder : p.deleteBorder}`,
1760
- color: n ? p.deleteActiveText : p.deleteText,
1330
+ background: t ? i.deleteActiveBg : "transparent",
1331
+ border: `1px dashed ${t ? i.deleteActiveBorder : i.deleteBorder}`,
1332
+ color: t ? i.deleteActiveText : i.deleteText,
1761
1333
  textAlign: "center",
1762
1334
  fontSize: 10,
1763
1335
  fontWeight: "bold",
@@ -1766,134 +1338,144 @@ function un({
1766
1338
  transition: "background 0.12s, color 0.12s, border-color 0.12s",
1767
1339
  pointerEvents: "none",
1768
1340
  userSelect: "none"
1769
- }, children: n ? "Release to delete" : "Drag here to delete" })
1341
+ }, children: t ? "Release to delete" : "Drag here to delete" })
1770
1342
  ] }),
1771
- C === "packages" && /* @__PURE__ */ t("div", { style: { flex: 1, overflowY: "auto", padding: "10px" }, children: l.length === 0 ? /* @__PURE__ */ t("div", { style: { color: p.textMuted, fontSize: 11, textAlign: "center", padding: "20px 0" }, children: "No packages available" }) : l.map((g) => /* @__PURE__ */ t(
1772
- pn,
1773
- {
1774
- pkg: g,
1775
- loaded: u.get(g.id),
1776
- toggling: k === g.id,
1777
- onToggle: R
1778
- },
1779
- g.id
1780
- )) })
1343
+ s === "packages" && r && /* @__PURE__ */ a(Zo, { ...r })
1781
1344
  ] });
1782
1345
  }
1783
- function fn(e, n, r) {
1784
- let l = e;
1346
+ function nr(e, t, n) {
1347
+ let r = e;
1785
1348
  for (; ; )
1786
- if (l.embeddedInBlockId) {
1787
- const i = r.get(l.embeddedInBlockId);
1788
- if (!i) return !1;
1789
- l = i;
1790
- } else if (l.parentBlockId) {
1791
- const i = r.get(l.parentBlockId);
1792
- if (!i) return !1;
1793
- l = i;
1349
+ if (r.embeddedInBlockId) {
1350
+ const o = n.get(r.embeddedInBlockId);
1351
+ if (!o) return !1;
1352
+ r = o;
1353
+ } else if (r.parentBlockId) {
1354
+ const o = n.get(r.parentBlockId);
1355
+ if (!o) return !1;
1356
+ r = o;
1794
1357
  } else
1795
- return ne(l.definitionId)?.provides?.some((o) => o.id === n) ?? !1;
1796
- }
1797
- function hn(e, n) {
1798
- const r = ne(e.definitionId), l = we(r, e.paramSlots, n), i = Ie(r);
1799
- return r.blockType === "start" ? ht(l, i) : r.blockType === "command" ? ft(l, i) : ze(r.returnType, l, i);
1800
- }
1801
- function gt({
1802
- block: e,
1803
- allBlocks: n,
1804
- onPointerDown: r,
1805
- onBlockClick: l,
1806
- onSocketClick: i,
1807
- editingSocket: o,
1808
- onSocketCommit: a,
1809
- onSocketCancelEdit: p,
1810
- onOutputDrag: C,
1811
- isGhost: s,
1812
- isDragging: P,
1813
- embedded: T
1814
- }) {
1815
- const v = G(), c = ne(e.definitionId);
1816
- if (!c) {
1817
- const u = r ? (g) => {
1818
- g.stopPropagation(), r(g, e.instanceId);
1819
- } : void 0, A = l ? (g) => {
1820
- g.stopPropagation(), l(e.instanceId);
1821
- } : void 0, Y = e.definitionId.replace(/^__coll__/, "").slice(0, 16);
1822
- return /* @__PURE__ */ d(
1358
+ return z(r.definitionId)?.provides?.some((i) => i.id === t) ?? !1;
1359
+ }
1360
+ function ht(e) {
1361
+ const {
1362
+ block: t,
1363
+ allBlocks: n,
1364
+ onPointerDown: r,
1365
+ onBlockClick: o,
1366
+ onSocketClick: i,
1367
+ editingSocket: s,
1368
+ onSocketCommit: c,
1369
+ onSocketCancelEdit: f,
1370
+ onOutputDrag: g,
1371
+ isGhost: h,
1372
+ draggingIds: B,
1373
+ provisionalIds: W,
1374
+ onSocketInput: w,
1375
+ embedded: N
1376
+ } = e, I = ee(), v = z(t.definitionId), K = B?.has(t.instanceId) ?? !1, G = W?.has(t.instanceId) ?? !1, k = (m, b, M, V) => {
1377
+ const Z = m ? n.get(m) : void 0;
1378
+ return Z ? /* @__PURE__ */ a("g", { transform: `translate(${b},${M})`, children: /* @__PURE__ */ a(
1379
+ ht,
1380
+ {
1381
+ block: Z,
1382
+ allBlocks: n,
1383
+ onPointerDown: r,
1384
+ onBlockClick: o,
1385
+ onSocketClick: i,
1386
+ editingSocket: s,
1387
+ onSocketCommit: c,
1388
+ onSocketCancelEdit: f,
1389
+ onOutputDrag: g,
1390
+ isGhost: h,
1391
+ draggingIds: B,
1392
+ provisionalIds: W,
1393
+ onSocketInput: w,
1394
+ embedded: !0
1395
+ }
1396
+ ) }, V) : null;
1397
+ };
1398
+ if (!v) {
1399
+ const m = r ? (V) => {
1400
+ V.stopPropagation(), r(V, t.instanceId);
1401
+ } : void 0, b = o ? (V) => {
1402
+ V.stopPropagation(), o(t.instanceId);
1403
+ } : void 0, M = t.definitionId.replace(/^__coll__/, "").slice(0, 16);
1404
+ return /* @__PURE__ */ y(
1823
1405
  "g",
1824
1406
  {
1825
- transform: s || T ? void 0 : `translate(${e.x},${e.y})`,
1826
- opacity: P ? 0.35 : 0.85,
1827
- onPointerDown: u,
1828
- onClick: A,
1829
- style: { cursor: "grab" },
1407
+ transform: h || N ? void 0 : `translate(${t.x},${t.y})`,
1408
+ opacity: K ? 0.35 : 0.85,
1830
1409
  children: [
1831
- /* @__PURE__ */ t(
1832
- "rect",
1833
- {
1834
- x: 0,
1835
- y: 0,
1836
- width: 160,
1837
- height: 24,
1838
- rx: 3,
1839
- fill: "rgba(160,40,40,0.18)",
1840
- stroke: "#c05050",
1841
- strokeWidth: 1.5,
1842
- strokeDasharray: "5,3"
1843
- }
1844
- ),
1845
- /* @__PURE__ */ d(
1846
- "text",
1847
- {
1848
- x: 8,
1849
- y: 16,
1850
- fill: "#c05050",
1851
- fontSize: 10,
1852
- fontFamily: "sans-serif",
1853
- fontStyle: "italic",
1854
- style: { userSelect: "none", pointerEvents: "none" },
1855
- children: [
1856
- "⚠ ",
1857
- Y,
1858
- " (missing)"
1859
- ]
1860
- }
1861
- )
1410
+ /* @__PURE__ */ y("g", { onPointerDown: m, onClick: b, style: { cursor: "grab" }, children: [
1411
+ /* @__PURE__ */ a(
1412
+ "rect",
1413
+ {
1414
+ x: 0,
1415
+ y: 0,
1416
+ width: 160,
1417
+ height: Ye,
1418
+ rx: 3,
1419
+ fill: "rgba(160,40,40,0.18)",
1420
+ stroke: "#c05050",
1421
+ strokeWidth: 1.5,
1422
+ strokeDasharray: "5,3"
1423
+ }
1424
+ ),
1425
+ /* @__PURE__ */ y(
1426
+ "text",
1427
+ {
1428
+ x: 8,
1429
+ y: 16,
1430
+ fill: "#c05050",
1431
+ fontSize: 10,
1432
+ fontFamily: "sans-serif",
1433
+ fontStyle: "italic",
1434
+ style: { userSelect: "none", pointerEvents: "none" },
1435
+ children: [
1436
+ "⚠ ",
1437
+ M,
1438
+ " (missing)"
1439
+ ]
1440
+ }
1441
+ )
1442
+ ] }),
1443
+ k(t.nextBlockId, 0, Ye, "next")
1862
1444
  ]
1863
1445
  }
1864
1446
  );
1865
1447
  }
1866
- const k = we(c, e.paramSlots, n), x = Ie(c), M = Oe(c, e.paramSlots, n), I = s ? 0.75 : P ? 0.35 : 1, _ = `clip-${s ? "g" : "c"}-${e.instanceId}`, Q = hn(e, n), re = r ? (u) => {
1867
- u.stopPropagation(), r(u, e.instanceId);
1868
- } : void 0, R = l ? (u) => {
1869
- u.stopPropagation(), l(e.instanceId);
1448
+ const ne = ue(v, t.paramSlots, n), X = be(v, t.paramSlots, n), re = Xe(v), le = je(v, t.paramSlots, n), x = Ee(v, t.paramSlots, n), T = K ? 0.35 : G ? 0.6 : h && !N ? 0.75 : 1, q = `clip-${h ? "g" : "c"}-${t.instanceId}`, Y = Vt(v, t.paramSlots, n), ae = r ? (m) => {
1449
+ m.stopPropagation(), r(m, t.instanceId);
1450
+ } : void 0, ie = o ? (m) => {
1451
+ m.stopPropagation(), o(t.instanceId);
1870
1452
  } : void 0;
1871
- if (c.category.startsWith("$") && !s && !fn(e, c.id, n)) {
1872
- const u = we(c), A = be, Y = ze(c.returnType ?? "string", u, A);
1873
- return /* @__PURE__ */ d(
1453
+ if (v.category.startsWith("$") && !h && !nr(t, v.id, n)) {
1454
+ const m = ue(v), b = ke, M = qt(v.returnType ?? "string", m, b);
1455
+ return /* @__PURE__ */ y(
1874
1456
  "g",
1875
1457
  {
1876
- transform: s || T ? void 0 : `translate(${e.x},${e.y})`,
1877
- opacity: P ? 0.35 : 0.85,
1878
- onPointerDown: re,
1879
- onClick: R,
1458
+ transform: h || N ? void 0 : `translate(${t.x},${t.y})`,
1459
+ opacity: K ? 0.35 : 0.85,
1460
+ onPointerDown: ae,
1461
+ onClick: ie,
1880
1462
  style: { cursor: "grab" },
1881
1463
  children: [
1882
- /* @__PURE__ */ t(
1464
+ /* @__PURE__ */ a(
1883
1465
  "path",
1884
1466
  {
1885
- d: Y,
1467
+ d: M,
1886
1468
  fill: "rgba(180,100,0,0.15)",
1887
1469
  stroke: "#c08820",
1888
1470
  strokeWidth: 1.5,
1889
1471
  strokeDasharray: "5,3"
1890
1472
  }
1891
1473
  ),
1892
- /* @__PURE__ */ d(
1474
+ /* @__PURE__ */ y(
1893
1475
  "text",
1894
1476
  {
1895
- x: u / 2,
1896
- y: A / 2 + 3.5,
1477
+ x: m / 2,
1478
+ y: b / 2 + 3.5,
1897
1479
  textAnchor: "middle",
1898
1480
  fill: "#c08820",
1899
1481
  fontSize: 9,
@@ -1902,7 +1484,7 @@ function gt({
1902
1484
  style: { userSelect: "none", pointerEvents: "none" },
1903
1485
  children: [
1904
1486
  "⚠ ",
1905
- c.name
1487
+ v.name
1906
1488
  ]
1907
1489
  }
1908
1490
  )
@@ -1910,635 +1492,909 @@ function gt({
1910
1492
  }
1911
1493
  );
1912
1494
  }
1913
- return /* @__PURE__ */ d(
1495
+ return /* @__PURE__ */ y(
1914
1496
  "g",
1915
1497
  {
1916
- transform: s || T ? void 0 : `translate(${e.x},${e.y})`,
1917
- opacity: I,
1918
- onPointerDown: re,
1919
- onClick: R,
1920
- style: { cursor: s ? "grabbing" : "grab" },
1498
+ transform: h || N ? void 0 : `translate(${t.x},${t.y})`,
1499
+ opacity: T,
1500
+ onPointerDown: ae,
1501
+ onClick: ie,
1502
+ style: { cursor: h ? "grabbing" : "grab" },
1921
1503
  children: [
1922
- /* @__PURE__ */ t("defs", { children: /* @__PURE__ */ t("clipPath", { id: _, children: /* @__PURE__ */ t("path", { d: Q }) }) }),
1923
- /* @__PURE__ */ t("path", { d: Q, fill: v.blockBody, stroke: v.blockBorder, strokeWidth: 1.5 }),
1924
- /* @__PURE__ */ t(
1504
+ /* @__PURE__ */ a("defs", { children: /* @__PURE__ */ a("clipPath", { id: q, children: /* @__PURE__ */ a("path", { d: Y }) }) }),
1505
+ /* @__PURE__ */ a(
1506
+ "path",
1507
+ {
1508
+ d: Y,
1509
+ fill: I.blockBody,
1510
+ stroke: G ? I.accent : I.blockBorder,
1511
+ strokeWidth: 1.5,
1512
+ strokeDasharray: G ? "4,3" : void 0
1513
+ }
1514
+ ),
1515
+ /* @__PURE__ */ a(
1925
1516
  "rect",
1926
1517
  {
1927
1518
  x: 0,
1928
1519
  y: 0,
1929
1520
  width: 4,
1930
- height: x + 20,
1931
- fill: c.color,
1932
- clipPath: `url(#${_})`
1521
+ height: X + 20,
1522
+ fill: v.color,
1523
+ clipPath: `url(#${q})`
1933
1524
  }
1934
1525
  ),
1935
- /* @__PURE__ */ d(
1526
+ /* @__PURE__ */ y(
1936
1527
  "text",
1937
1528
  {
1938
1529
  x: 11,
1939
- y: (c.blockType === "start" ? ue : x) / 2 + 4,
1940
- fill: v.blockText,
1530
+ y: re / 2 + 4,
1531
+ fill: I.blockText,
1941
1532
  fontSize: 11,
1942
1533
  fontWeight: "bold",
1943
1534
  fontFamily: "sans-serif",
1944
1535
  style: { userSelect: "none", pointerEvents: "none" },
1945
1536
  children: [
1946
- c.name,
1947
- c.blockType === "query" && c.returnType && /* @__PURE__ */ t("tspan", { fill: v.textMuted, fontSize: 9, fontWeight: "normal", children: ` [${c.returnType}]` })
1537
+ v.name,
1538
+ v.blockType === "query" && v.returnType && /* @__PURE__ */ a("tspan", { fill: I.textMuted, fontSize: 9, fontWeight: "normal", children: ` [${v.returnType}]` })
1948
1539
  ]
1949
1540
  }
1950
1541
  ),
1951
- c.blockType === "start" && c.provides && c.provides.length > 0 && /* @__PURE__ */ d("g", { children: [
1952
- /* @__PURE__ */ t(
1542
+ v.blockType === "start" && v.provides && v.provides.length > 0 && /* @__PURE__ */ y("g", { children: [
1543
+ /* @__PURE__ */ a(
1953
1544
  "line",
1954
1545
  {
1955
1546
  x1: 8,
1956
- y1: ue,
1957
- x2: k - 8,
1958
- y2: ue,
1547
+ y1: me,
1548
+ x2: ne - 8,
1549
+ y2: me,
1959
1550
  stroke: "rgba(255,255,255,0.15)",
1960
1551
  strokeWidth: 1
1961
1552
  }
1962
1553
  ),
1963
- c.provides.map((u, A) => {
1964
- const g = ne(u.id)?.color ?? c.color, F = ut(u.name), Z = 20, fe = 8, he = ue + 6 + A * pt, X = !s && !T;
1965
- return /* @__PURE__ */ d(
1554
+ v.provides.map((m, b) => {
1555
+ const V = z(m.id)?.color ?? v.color, Z = zt(m.name), Ie = 20, ve = 8, fe = me + 6 + b * Ht, O = !h && !N;
1556
+ return /* @__PURE__ */ y(
1966
1557
  "g",
1967
1558
  {
1968
- transform: `translate(${fe}, ${he})`,
1969
- onPointerDown: X ? (xe) => {
1970
- xe.stopPropagation(), C?.(xe, u.id);
1559
+ transform: `translate(${ve}, ${fe})`,
1560
+ onPointerDown: O ? (Oe) => {
1561
+ Oe.stopPropagation(), g?.(Oe, m.id);
1971
1562
  } : void 0,
1972
- style: { cursor: X ? "grab" : "default" },
1563
+ style: { cursor: O ? "grab" : "default" },
1973
1564
  children: [
1974
- /* @__PURE__ */ t(
1565
+ /* @__PURE__ */ a(
1975
1566
  "rect",
1976
1567
  {
1977
1568
  x: 0,
1978
1569
  y: 0,
1979
- width: F,
1980
- height: Z,
1570
+ width: Z,
1571
+ height: Ie,
1981
1572
  rx: 10,
1982
- fill: g,
1573
+ fill: V,
1983
1574
  opacity: 0.82,
1984
1575
  stroke: "rgba(255,255,255,0.25)",
1985
1576
  strokeWidth: 1
1986
1577
  }
1987
1578
  ),
1988
- /* @__PURE__ */ t(
1579
+ /* @__PURE__ */ a(
1989
1580
  "text",
1990
1581
  {
1991
- x: F / 2,
1992
- y: Z / 2 + 3.5,
1582
+ x: Z / 2,
1583
+ y: Ie / 2 + 3.5,
1993
1584
  textAnchor: "middle",
1994
1585
  fill: "white",
1995
1586
  fontSize: 9.5,
1996
1587
  fontFamily: "sans-serif",
1997
1588
  fontWeight: "bold",
1998
1589
  style: { userSelect: "none", pointerEvents: "none" },
1999
- children: u.name
1590
+ children: m.name
2000
1591
  }
2001
1592
  )
2002
1593
  ]
2003
1594
  },
2004
- u.id
1595
+ m.id
2005
1596
  );
2006
1597
  })
2007
1598
  ] }),
2008
- M.map((u) => {
2009
- const A = e.paramSlots[u.index], Y = A?.queryBlockId, g = Y ? n.get(Y) : null;
2010
- if (g)
2011
- return /* @__PURE__ */ t("g", { transform: `translate(${u.x},${u.y})`, children: /* @__PURE__ */ t(
2012
- gt,
2013
- {
2014
- block: g,
2015
- allBlocks: n,
2016
- onPointerDown: r,
2017
- onBlockClick: l,
2018
- onSocketClick: i,
2019
- editingSocket: o,
2020
- onSocketCommit: a,
2021
- onSocketCancelEdit: p,
2022
- onOutputDrag: C,
2023
- embedded: !0
2024
- }
2025
- ) }, u.index);
2026
- const F = A?.textValue, Z = c.params[u.index]?.name, fe = !Tt.has(u.type), he = o?.blockId === e.instanceId && o?.slotIndex === u.index;
2027
- return /* @__PURE__ */ d(
1599
+ le.map((m) => {
1600
+ const b = t.paramSlots[m.index], M = b?.queryBlockId, V = M ? n.get(M) : null, Z = v.params[m.index].name, Ie = lt(Z, m.type);
1601
+ if (V)
1602
+ return /* @__PURE__ */ y("g", { children: [
1603
+ /* @__PURE__ */ a("title", { children: Ie }),
1604
+ k(M, m.x, m.y, "query")
1605
+ ] }, m.index);
1606
+ const ve = b?.textValue, fe = s?.blockId === t.instanceId && s?.slotIndex === m.index;
1607
+ return /* @__PURE__ */ y(
2028
1608
  "g",
2029
1609
  {
2030
- transform: `translate(${u.x},${u.y})`,
2031
- onPointerDown: (X) => X.stopPropagation(),
2032
- onClick: (X) => {
2033
- X.stopPropagation(), i?.(e.instanceId, u.index);
1610
+ transform: `translate(${m.x},${m.y})`,
1611
+ onPointerDown: (O) => O.stopPropagation(),
1612
+ onClick: (O) => {
1613
+ O.stopPropagation(), i?.(t.instanceId, m.index);
2034
1614
  },
2035
1615
  style: { cursor: "text" },
2036
1616
  children: [
2037
- /* @__PURE__ */ t(
1617
+ /* @__PURE__ */ a("title", { children: Ie }),
1618
+ /* @__PURE__ */ a(
2038
1619
  "path",
2039
1620
  {
2040
- d: Wt(u.type, u.w, u.h),
2041
- fill: he ? v.blockBorder : v.socketBody,
2042
- stroke: v.blockBorder,
2043
- strokeWidth: he ? 1.5 : 1
1621
+ d: Yt(m.type, m.w, m.h),
1622
+ fill: fe ? I.blockBorder : I.socketBody,
1623
+ stroke: I.blockBorder,
1624
+ strokeWidth: fe ? 1.5 : 1
2044
1625
  }
2045
1626
  ),
2046
- he ? /* @__PURE__ */ t("foreignObject", { x: 0, y: 0, width: u.w, height: u.h, children: /* @__PURE__ */ t(
1627
+ fe ? /* @__PURE__ */ a("foreignObject", { x: 0, y: 0, width: m.w, height: m.h, children: /* @__PURE__ */ a(
2047
1628
  "input",
2048
1629
  {
2049
1630
  autoFocus: !0,
2050
- defaultValue: F ?? "",
2051
- onKeyDown: (X) => {
2052
- X.stopPropagation(), X.key === "Enter" && a?.(e.instanceId, u.index, X.target.value), X.key === "Escape" && p?.();
1631
+ defaultValue: ve ?? "",
1632
+ onChange: (O) => w?.(t.instanceId, m.index, O.target.value),
1633
+ onKeyDown: (O) => {
1634
+ O.stopPropagation(), O.key === "Enter" && c?.(t.instanceId, m.index, O.target.value), O.key === "Escape" && f?.();
2053
1635
  },
2054
- onBlur: (X) => a?.(e.instanceId, u.index, X.target.value),
2055
- onPointerDown: (X) => X.stopPropagation(),
1636
+ onBlur: (O) => c?.(t.instanceId, m.index, O.target.value),
1637
+ onPointerDown: (O) => O.stopPropagation(),
2056
1638
  style: {
2057
1639
  width: "100%",
2058
1640
  height: "100%",
2059
1641
  background: "transparent",
2060
1642
  border: "none",
2061
1643
  outline: "none",
2062
- color: v.blockText,
1644
+ color: I.blockText,
2063
1645
  fontSize: 10,
2064
1646
  fontFamily: "sans-serif",
2065
1647
  textAlign: "center",
2066
1648
  padding: "0 4px",
2067
1649
  boxSizing: "border-box",
2068
- caretColor: v.blockText
1650
+ caretColor: I.blockText
2069
1651
  }
2070
1652
  }
2071
- ) }) : F ? /* @__PURE__ */ t(
1653
+ ) }) : ve ? /* @__PURE__ */ a(
2072
1654
  "text",
2073
1655
  {
2074
- x: u.w / 2,
2075
- y: u.h / 2 + 4,
1656
+ x: m.w / 2,
1657
+ y: m.h / 2 + 4,
2076
1658
  textAnchor: "middle",
2077
- fill: v.blockText,
1659
+ fill: I.blockText,
2078
1660
  fontSize: 10,
2079
1661
  fontFamily: "sans-serif",
1662
+ fontStyle: G ? "italic" : void 0,
2080
1663
  style: { userSelect: "none", pointerEvents: "none" },
2081
- children: F
2082
- }
2083
- ) : fe ? /* @__PURE__ */ t(
2084
- "text",
2085
- {
2086
- x: u.w / 2,
2087
- y: u.h / 2 + 3,
2088
- textAnchor: "middle",
2089
- fill: v.textSecondary,
2090
- fontSize: 9,
2091
- fontFamily: "sans-serif",
2092
- style: { userSelect: "none", pointerEvents: "none" },
2093
- children: u.type
2094
- }
2095
- ) : Z ? /* @__PURE__ */ t(
2096
- "text",
2097
- {
2098
- x: u.w / 2,
2099
- y: u.h / 2 + 3,
2100
- textAnchor: "middle",
2101
- fill: v.textMuted,
2102
- fontSize: 9,
2103
- fontFamily: "sans-serif",
2104
- fontStyle: "italic",
2105
- style: { userSelect: "none", pointerEvents: "none" },
2106
- children: Z
1664
+ children: ve
2107
1665
  }
2108
- ) : null
1666
+ ) : /* @__PURE__ */ a(An, { name: Z, type: m.type, w: m.w, h: m.h })
2109
1667
  ]
2110
1668
  },
2111
- u.index
1669
+ m.index
2112
1670
  );
2113
- })
1671
+ }),
1672
+ x.length > 0 && /* @__PURE__ */ a(Ut, { mouths: x, w: ne, isEmpty: (m) => !t.paramSlots[m]?.commandBlockId }),
1673
+ x.map((m) => k(t.paramSlots[m.index]?.commandBlockId, m.x, m.y, `mouth-${m.index}`)),
1674
+ k(t.nextBlockId, 0, X, "next")
2114
1675
  ]
2115
1676
  }
2116
1677
  );
2117
1678
  }
2118
- const Dt = Lt(
1679
+ const Nn = io(
2119
1680
  ({
2120
1681
  blocks: e,
2121
- draggingIds: n,
1682
+ draggingIds: t,
1683
+ provisionalIds: n,
2122
1684
  onBlockPointerDown: r,
2123
- onBlockClick: l,
1685
+ onBlockClick: o,
2124
1686
  onSocketClick: i,
2125
- editingSocket: o,
2126
- onSocketCommit: a,
2127
- onSocketCancelEdit: p,
2128
- onOutputDrag: C
2129
- }, s) => {
2130
- const P = G(), T = [...e.values()].filter((v) => !v.embeddedInBlockId);
2131
- return /* @__PURE__ */ d(
1687
+ editingSocket: s,
1688
+ onSocketInput: c,
1689
+ onSocketCommit: f,
1690
+ onSocketCancelEdit: g,
1691
+ onOutputDrag: h,
1692
+ overlay: B
1693
+ }, W) => {
1694
+ const w = ee(), N = [...e.values()].filter((I) => !I.embeddedInBlockId && !I.parentBlockId);
1695
+ return /* @__PURE__ */ y(
2132
1696
  "svg",
2133
1697
  {
2134
- ref: s,
2135
- style: { flex: 1, background: P.canvasBg, display: "block" },
2136
- onPointerDown: (v) => {
2137
- v.target === v.currentTarget && v.preventDefault();
1698
+ ref: W,
1699
+ style: { flex: 1, background: w.canvasBg, display: "block" },
1700
+ onPointerDown: (I) => {
1701
+ I.target === I.currentTarget && I.preventDefault();
2138
1702
  },
2139
1703
  children: [
2140
- /* @__PURE__ */ t("defs", { children: /* @__PURE__ */ t("pattern", { id: "grid", width: "28", height: "28", patternUnits: "userSpaceOnUse", children: /* @__PURE__ */ t("circle", { cx: "14", cy: "14", r: "0.7", fill: P.gridDot }) }) }),
2141
- /* @__PURE__ */ t("rect", { width: "100%", height: "100%", fill: "url(#grid)" }),
2142
- T.map((v) => /* @__PURE__ */ t(
2143
- gt,
1704
+ /* @__PURE__ */ a("defs", { children: /* @__PURE__ */ a("pattern", { id: "grid", width: "28", height: "28", patternUnits: "userSpaceOnUse", children: /* @__PURE__ */ a("circle", { cx: "14", cy: "14", r: "0.7", fill: w.gridDot }) }) }),
1705
+ /* @__PURE__ */ a("rect", { width: "100%", height: "100%", fill: "url(#grid)" }),
1706
+ N.map((I) => /* @__PURE__ */ a(
1707
+ ht,
2144
1708
  {
2145
- block: v,
1709
+ block: I,
2146
1710
  allBlocks: e,
2147
1711
  onPointerDown: r,
2148
- onBlockClick: l,
1712
+ onBlockClick: o,
2149
1713
  onSocketClick: i,
2150
- isDragging: n.has(v.instanceId),
2151
- editingSocket: o,
2152
- onSocketCommit: a,
2153
- onSocketCancelEdit: p,
2154
- onOutputDrag: C
1714
+ draggingIds: t,
1715
+ provisionalIds: n,
1716
+ editingSocket: s,
1717
+ onSocketInput: c,
1718
+ onSocketCommit: f,
1719
+ onSocketCancelEdit: g,
1720
+ onOutputDrag: h
2155
1721
  },
2156
- v.instanceId
2157
- ))
1722
+ I.instanceId
1723
+ )),
1724
+ B
2158
1725
  ]
2159
1726
  }
2160
1727
  );
2161
1728
  }
2162
1729
  );
2163
- Dt.displayName = "Canvas";
2164
- let dt = 1;
2165
- function gn() {
2166
- return `b${dt++}`;
2167
- }
2168
- function Ve(e, n) {
2169
- const r = [], l = [...e];
2170
- for (; l.length > 0; ) {
2171
- const i = l.shift();
2172
- r.push(i), n.get(i)?.paramSlots.forEach((o) => {
2173
- o.queryBlockId && l.push(o.queryBlockId);
2174
- });
1730
+ Nn.displayName = "Canvas";
1731
+ function or({ onSelect: e }) {
1732
+ const t = ee();
1733
+ return /* @__PURE__ */ a("div", { style: { display: "flex", gap: 4 }, children: tt.map((n) => /* @__PURE__ */ a("button", { onClick: () => e(n), style: {
1734
+ background: t.id === n.id ? t.switcherActiveBg : t.switcherBg,
1735
+ border: `1px solid ${t.switcherBorder}`,
1736
+ borderRadius: 4,
1737
+ padding: "2px 9px",
1738
+ color: t.id === n.id ? t.switcherActiveText : t.switcherText,
1739
+ fontSize: 10,
1740
+ fontWeight: t.id === n.id ? "bold" : "normal",
1741
+ letterSpacing: 0.5,
1742
+ cursor: "pointer",
1743
+ transition: "color 0.1s, background 0.1s"
1744
+ }, children: n.label }, n.id)) });
1745
+ }
1746
+ function rr({ canUndo: e, canRedo: t, onUndo: n, onRedo: r, notice: o, extra: i }) {
1747
+ const s = ee(), c = (f) => ({
1748
+ width: 28,
1749
+ height: 24,
1750
+ padding: 0,
1751
+ background: s.paletteBg,
1752
+ color: f ? s.textPrimary : s.textMuted,
1753
+ border: `1px solid ${s.border}`,
1754
+ borderRadius: 4,
1755
+ fontSize: 14,
1756
+ lineHeight: 1,
1757
+ cursor: f ? "pointer" : "default",
1758
+ opacity: f ? 1 : 0.5
1759
+ });
1760
+ return /* @__PURE__ */ y("div", { style: { position: "absolute", top: 8, right: 8, display: "flex", alignItems: "center", gap: 6, pointerEvents: "none" }, children: [
1761
+ o && /* @__PURE__ */ a("span", { style: {
1762
+ fontSize: 11,
1763
+ color: s.textPrimary,
1764
+ background: s.paletteBg,
1765
+ border: `1px solid ${s.accent}`,
1766
+ borderRadius: 4,
1767
+ padding: "3px 8px"
1768
+ }, children: o }),
1769
+ i && /* @__PURE__ */ a("div", { style: { pointerEvents: "auto" }, children: i }),
1770
+ /* @__PURE__ */ a(
1771
+ "button",
1772
+ {
1773
+ type: "button",
1774
+ title: "Undo (Ctrl+Z)",
1775
+ "aria-label": "Undo",
1776
+ disabled: !e,
1777
+ onClick: n,
1778
+ style: { ...c(e), pointerEvents: "auto" },
1779
+ children: "↶"
1780
+ }
1781
+ ),
1782
+ /* @__PURE__ */ a(
1783
+ "button",
1784
+ {
1785
+ type: "button",
1786
+ title: "Redo (Ctrl+Shift+Z)",
1787
+ "aria-label": "Redo",
1788
+ disabled: !t,
1789
+ onClick: r,
1790
+ style: { ...c(t), pointerEvents: "auto" },
1791
+ children: "↷"
1792
+ }
1793
+ )
1794
+ ] });
1795
+ }
1796
+ function ir(e) {
1797
+ try {
1798
+ return localStorage.getItem(e);
1799
+ } catch {
1800
+ return null;
2175
1801
  }
2176
- return r;
2177
1802
  }
2178
- function yn(e) {
2179
- const n = [];
2180
- if (e.forEach((i) => {
2181
- ne(i.definitionId) || n.push(i.instanceId);
2182
- }), n.length === 0) return e;
2183
- const r = new Map(e);
2184
- for (const i of n) {
2185
- const o = r.get(i);
2186
- if (o) {
2187
- if (o.parentBlockId || o.nextBlockId) {
2188
- const a = o.parentBlockId ? r.get(o.parentBlockId) : null, p = o.nextBlockId ? r.get(o.nextBlockId) : null;
2189
- a && r.set(o.parentBlockId, { ...a, nextBlockId: o.nextBlockId ?? null }), p && r.set(o.nextBlockId, { ...p, parentBlockId: o.parentBlockId ?? null });
1803
+ function sr(e, t) {
1804
+ try {
1805
+ localStorage.setItem(e, t);
1806
+ } catch {
1807
+ }
1808
+ }
1809
+ let Ce = null;
1810
+ function cr(e) {
1811
+ Ce === null && (Ce = e);
1812
+ }
1813
+ function lr(e) {
1814
+ Ce === e && (Ce = null);
1815
+ }
1816
+ function ar(e) {
1817
+ Ce = e;
1818
+ }
1819
+ function dr(e) {
1820
+ return Ce === null || Ce === e;
1821
+ }
1822
+ function ur({ writers: e, onExport: t }) {
1823
+ const n = ee(), [r, o] = P(!1);
1824
+ return /* @__PURE__ */ y("div", { style: { position: "relative" }, children: [
1825
+ /* @__PURE__ */ a(
1826
+ "button",
1827
+ {
1828
+ type: "button",
1829
+ onClick: () => o((i) => !i),
1830
+ "aria-expanded": r,
1831
+ style: {
1832
+ height: 24,
1833
+ padding: "0 8px",
1834
+ fontSize: 11,
1835
+ background: n.paletteBg,
1836
+ color: n.textPrimary,
1837
+ border: `1px solid ${n.border}`,
1838
+ borderRadius: 4,
1839
+ cursor: "pointer"
1840
+ },
1841
+ children: "Export ▾"
2190
1842
  }
2191
- if (o.embeddedInBlockId && o.embeddedSlotIndex >= 0) {
2192
- const a = r.get(o.embeddedInBlockId);
2193
- if (a) {
2194
- const p = [...a.paramSlots];
2195
- p[o.embeddedSlotIndex] = { textValue: null, queryBlockId: null }, r.set(o.embeddedInBlockId, { ...a, paramSlots: p });
2196
- }
1843
+ ),
1844
+ r && /* @__PURE__ */ a("div", { role: "menu", style: {
1845
+ position: "absolute",
1846
+ top: 28,
1847
+ right: 0,
1848
+ minWidth: 120,
1849
+ zIndex: 10,
1850
+ background: n.paletteBg,
1851
+ border: `1px solid ${n.border}`,
1852
+ borderRadius: 4,
1853
+ padding: 3
1854
+ }, children: e.map((i) => /* @__PURE__ */ y(
1855
+ "button",
1856
+ {
1857
+ type: "button",
1858
+ role: "menuitem",
1859
+ onClick: () => {
1860
+ o(!1), t(i);
1861
+ },
1862
+ style: {
1863
+ display: "block",
1864
+ width: "100%",
1865
+ textAlign: "left",
1866
+ padding: "4px 8px",
1867
+ fontSize: 11,
1868
+ background: "none",
1869
+ border: "none",
1870
+ color: n.textPrimary,
1871
+ cursor: "pointer"
1872
+ },
1873
+ children: [
1874
+ i.label,
1875
+ " ",
1876
+ /* @__PURE__ */ y("span", { style: { color: n.textMuted }, children: [
1877
+ ".",
1878
+ i.fileExtension
1879
+ ] })
1880
+ ]
1881
+ },
1882
+ i.id
1883
+ )) })
1884
+ ] });
1885
+ }
1886
+ function fr(e, t) {
1887
+ const n = z(e.definitionId);
1888
+ if (!n) return { w: 160, h: Ye };
1889
+ const r = n.blockType === "query" ? Wt(e, t) : Dn(e.instanceId, t);
1890
+ return { w: ue(n, e.paramSlots, t), h: r };
1891
+ }
1892
+ function pr({ peers: e, blocks: t, layout: n }) {
1893
+ const r = ee();
1894
+ return /* @__PURE__ */ a("g", { style: { pointerEvents: "none" }, children: e.map((o) => {
1895
+ const { color: i } = o, s = [];
1896
+ if (o.typing) {
1897
+ const c = t.get(o.typing.blockId), f = n.get(o.typing.blockId), g = c && z(c.definitionId), h = g && c && je(g, c.paramSlots, t).find((B) => B.index === o.typing.slot);
1898
+ f && h && s.push(
1899
+ /* @__PURE__ */ y("g", { transform: `translate(${f.x + h.x},${f.y + h.y})`, children: [
1900
+ /* @__PURE__ */ a("path", { d: Yt(h.type, h.w, h.h), fill: r.socketBody, stroke: i, strokeWidth: 2 }),
1901
+ /* @__PURE__ */ y("text", { x: h.w / 2, y: h.h / 2 + 4, textAnchor: "middle", fill: i, fontSize: 10, fontFamily: "sans-serif", children: [
1902
+ o.typing.text,
1903
+ "|"
1904
+ ] })
1905
+ ] }, "typing")
1906
+ );
1907
+ }
1908
+ if (o.drag && "leadId" in o.drag) {
1909
+ const c = t.get(o.drag.leadId), f = n.get(o.drag.leadId);
1910
+ if (c && f) {
1911
+ const { w: g, h } = fr(c, t);
1912
+ s.push(
1913
+ /* @__PURE__ */ a(
1914
+ "rect",
1915
+ {
1916
+ x: f.x - 3,
1917
+ y: f.y - 3,
1918
+ width: g + 6,
1919
+ height: h + 6,
1920
+ rx: 5,
1921
+ fill: "none",
1922
+ stroke: i,
1923
+ strokeWidth: 1.5,
1924
+ strokeDasharray: "5,3"
1925
+ },
1926
+ "origin"
1927
+ ),
1928
+ /* @__PURE__ */ y("g", { transform: `translate(${o.drag.at.x},${o.drag.at.y})`, opacity: 0.5, children: [
1929
+ /* @__PURE__ */ a(ht, { block: c, allBlocks: t, isGhost: !0 }),
1930
+ /* @__PURE__ */ a("rect", { x: -3, y: -3, width: g + 6, height: h + 6, rx: 5, fill: "none", stroke: i, strokeWidth: 1.5 })
1931
+ ] }, "ghost")
1932
+ );
2197
1933
  }
2198
1934
  }
2199
- }
2200
- return new Set(Ve(n, e)).forEach((i) => r.delete(i)), r;
1935
+ if (o.drag && "definitionId" in o.drag) {
1936
+ const c = z(o.drag.definitionId), f = c ? ue(c) : 120, g = c ? be(c) : Ye;
1937
+ s.push(
1938
+ /* @__PURE__ */ y("g", { transform: `translate(${o.drag.at.x},${o.drag.at.y})`, children: [
1939
+ /* @__PURE__ */ a("rect", { width: f, height: g, rx: 4, fill: i, fillOpacity: 0.12, stroke: i, strokeWidth: 1.5, strokeDasharray: "5,3" }),
1940
+ /* @__PURE__ */ a("text", { x: 8, y: g / 2 + 4, fill: i, fontSize: 11, fontWeight: "bold", fontFamily: "sans-serif", children: c?.name ?? o.drag.definitionId })
1941
+ ] }, "new")
1942
+ );
1943
+ }
1944
+ if (o.cursor) {
1945
+ const c = o.name.length * 6.5 + 10;
1946
+ s.push(
1947
+ /* @__PURE__ */ y("g", { transform: `translate(${o.cursor.x},${o.cursor.y})`, children: [
1948
+ /* @__PURE__ */ a("path", { d: "M 0 0 L 0 14 L 4 10.5 L 7 17 L 9.5 16 L 6.5 9.5 L 11 9.5 Z", fill: i, stroke: "white", strokeWidth: 1 }),
1949
+ /* @__PURE__ */ a("rect", { x: 12, y: 14, width: c, height: 16, rx: 3, fill: i }),
1950
+ /* @__PURE__ */ a("text", { x: 17, y: 26, fill: "white", fontSize: 10, fontFamily: "sans-serif", children: o.name })
1951
+ ] }, "cursor")
1952
+ );
1953
+ }
1954
+ return /* @__PURE__ */ a("g", { children: s }, o.clientId);
1955
+ }) });
1956
+ }
1957
+ const hr = "local";
1958
+ function gr(e, t, n) {
1959
+ const r = e === "undo" ? "Couldn't undo" : e === "redo" ? "Couldn't redo" : "Your change was undone";
1960
+ return t === "HOST_REJECTED" ? `${r}: ${n}` : `${r}: ${{
1961
+ TEXT_CHANGED: "someone else changed that parameter",
1962
+ PLACE_OCCUPIED: "someone else put a block there first",
1963
+ BLOCK_NOT_FOUND: "a block it needs was deleted",
1964
+ BLOCK_CHANGED: "someone else changed those blocks",
1965
+ NOT_AT_PLACE: "someone else moved that block",
1966
+ NOT_A_ROOT: "someone else moved that block",
1967
+ POSITION_CHANGED: "someone else moved that block",
1968
+ DEPENDENCIES_CHANGED: "someone else changed the packages"
1969
+ }[t] ?? "the canvas has changed"}.`;
1970
+ }
1971
+ function ot() {
1972
+ if (typeof crypto.randomUUID == "function") return crypto.randomUUID();
1973
+ const e = crypto.getRandomValues(new Uint8Array(16));
1974
+ e[6] = e[6] & 15 | 64, e[8] = e[8] & 63 | 128;
1975
+ const t = [...e].map((n) => n.toString(16).padStart(2, "0")).join("");
1976
+ return `${t.slice(0, 8)}-${t.slice(8, 12)}-${t.slice(12, 16)}-${t.slice(16, 20)}-${t.slice(20)}`;
1977
+ }
1978
+ function yr(e, t) {
1979
+ return e.embeddedInBlockId ? t.get(e.embeddedInBlockId)?.paramSlots[e.embeddedSlotIndex]?.commandBlockId === e.instanceId : !1;
2201
1980
  }
2202
- function xn(e, n, r) {
2203
- const l = Re(e);
1981
+ function mr(e) {
1982
+ return e.kind === "next" ? { next: e.blockId } : { mouth: e.blockId, slot: e.slotIndex };
1983
+ }
1984
+ async function fn(e, t) {
1985
+ if (!e || !t) return !1;
1986
+ const n = new Map(e.map((s) => [He(s), s])), r = new Set(We().map((s) => s.info.id).filter((s) => s.startsWith(dt))), o = [...r].filter((s) => !n.has(s)), i = [...n].filter(([s]) => !r.has(s));
1987
+ o.forEach(Lt);
1988
+ for (const [s, c] of i)
1989
+ await Ot({ id: s, name: J(c), description: "", url: t(c), builtIn: !1 });
1990
+ return o.length > 0 || i.length > 0;
1991
+ }
1992
+ function kr(e) {
1993
+ const t = new Map(We().map((r) => [r.info.id, r.info.name])), n = /* @__PURE__ */ new Map();
1994
+ return e.forEach((r) => {
1995
+ const o = $n(r.definitionId);
1996
+ if (!o?.startsWith(dt)) return;
1997
+ const i = t.get(o);
1998
+ n.set(i, (n.get(i) ?? 0) + 1);
1999
+ }), n;
2000
+ }
2001
+ function xr(e, t, n) {
2002
+ const r = ct(e);
2204
2003
  return {
2205
- instanceId: gn(),
2004
+ instanceId: ot(),
2206
2005
  definitionId: e,
2207
- x: n,
2208
- y: r,
2006
+ x: t,
2007
+ y: n,
2209
2008
  nextBlockId: null,
2210
2009
  parentBlockId: null,
2211
2010
  embeddedInBlockId: null,
2212
2011
  embeddedSlotIndex: -1,
2213
- paramSlots: l.params.map(() => ({ textValue: null, queryBlockId: null }))
2012
+ paramSlots: r.params.map(() => ({ textValue: null, queryBlockId: null, commandBlockId: null }))
2214
2013
  };
2215
2014
  }
2216
- function vt(e, n) {
2217
- const r = [];
2218
- let l = e;
2219
- for (; l; )
2220
- r.push(l), l = n.get(l)?.nextBlockId ?? null;
2221
- return r;
2222
- }
2223
- function Rt(e, n) {
2224
- const r = n.get(e);
2225
- return r?.parentBlockId ? Rt(r.parentBlockId, n) : e;
2226
- }
2227
- function zt(e, n) {
2228
- const r = ne(e.definitionId);
2229
- if (!r) return `[missing:${e.definitionId}]`;
2230
- const l = e.paramSlots.map((i, o) => {
2231
- if (i.queryBlockId) {
2232
- const a = n.get(i.queryBlockId);
2233
- if (a) return zt(a, n);
2015
+ function Pt(e, t) {
2016
+ const n = [];
2017
+ let r = e;
2018
+ for (; r; )
2019
+ n.push(r), r = t.get(r)?.nextBlockId ?? null;
2020
+ return n;
2021
+ }
2022
+ function Dt(e, t) {
2023
+ const n = t.get(e);
2024
+ return n?.parentBlockId ? Dt(n.parentBlockId, t) : n && yr(n, t) ? Dt(n.embeddedInBlockId, t) : e;
2025
+ }
2026
+ function Mt(e, t) {
2027
+ const n = z(e.definitionId);
2028
+ if (!n) return `[missing:${e.definitionId}]`;
2029
+ const r = e.paramSlots.map((o, i) => {
2030
+ const s = n.params[i];
2031
+ if (s && Ne(n, s)) {
2032
+ const f = (o.commandBlockId ? Pt(o.commandBlockId, t) : []).map((g) => t.get(g)).filter(Boolean).map((g) => Mt(g, t));
2033
+ return f.length > 0 ? `{ ${f.join("; ")} }` : "{ }";
2234
2034
  }
2235
- return i.textValue !== null && i.textValue !== void 0 ? r.params[o]?.type === "string" ? `"${i.textValue}"` : i.textValue : "_";
2035
+ if (o.queryBlockId) {
2036
+ const c = t.get(o.queryBlockId);
2037
+ if (c) return Mt(c, t);
2038
+ }
2039
+ return o.textValue !== null && o.textValue !== void 0 ? n.params[i]?.type === "string" ? `"${o.textValue}"` : o.textValue : "_";
2236
2040
  });
2237
- return `${r.id}(${l.join(", ")})`;
2238
- }
2239
- function mn(e, n) {
2240
- const r = new Map(e);
2241
- return Ve(n, e).forEach((l) => r.delete(l)), r;
2242
- }
2243
- function bn(e, n, r, l) {
2244
- const i = e.get(n);
2245
- if (!i) return e;
2246
- const o = [...i.paramSlots];
2247
- o[r] = { ...o[r], textValue: l || null };
2248
- const a = new Map(e);
2249
- return a.set(n, { ...i, paramSlots: o }), a;
2250
- }
2251
- function vn({ ghostPos: e, dragRef: n, blocks: r }) {
2252
- const l = G();
2041
+ return `${n.id}(${r.join(", ")})`;
2042
+ }
2043
+ function br({ ghostPos: e, dragRef: t, blocks: n }) {
2044
+ const r = ee();
2253
2045
  if (!e) return null;
2254
- const i = n.current;
2255
- if (i?.type === "canvas" && i.instanceId) {
2256
- const T = r.get(i.instanceId);
2257
- if (T)
2258
- return /* @__PURE__ */ t("svg", { style: { position: "fixed", top: 0, left: 0, width: "100%", height: "100%", pointerEvents: "none", zIndex: 9999 }, children: /* @__PURE__ */ t("g", { transform: `translate(${e.x},${e.y})`, opacity: 0.8, children: /* @__PURE__ */ t(gt, { block: T, allBlocks: r, isGhost: !0 }) }) });
2046
+ const o = t.current;
2047
+ if (o?.type === "canvas" && o.instanceId) {
2048
+ const h = n.get(o.instanceId);
2049
+ if (h)
2050
+ return /* @__PURE__ */ a("svg", { style: { position: "fixed", top: 0, left: 0, width: "100%", height: "100%", pointerEvents: "none", zIndex: 9999 }, children: /* @__PURE__ */ a("g", { transform: `translate(${e.x},${e.y})`, opacity: 0.8, children: /* @__PURE__ */ a(ht, { block: h, allBlocks: n, isGhost: !0 }) }) });
2259
2051
  }
2260
- const o = Re(e.defId), a = we(o), p = Ie(o), C = o.blockType === "query" ? be : p, s = o.blockType === "command";
2261
- let P;
2262
- return o.blockType === "start" ? P = ht(a, p) : o.blockType === "command" ? P = ft(a, C) : P = ze(o.returnType, a, C), /* @__PURE__ */ d("svg", { style: { position: "fixed", top: 0, left: 0, width: "100%", height: "100%", pointerEvents: "none", zIndex: 9999 }, children: [
2263
- s && /* @__PURE__ */ t("defs", { children: /* @__PURE__ */ t("clipPath", { id: "ghost-pal-clip", children: /* @__PURE__ */ t("path", { d: P }) }) }),
2264
- /* @__PURE__ */ d("g", { transform: `translate(${e.x},${e.y})`, opacity: 0.8, children: [
2265
- /* @__PURE__ */ t("path", { d: P, fill: s ? l.blockBody : o.color, stroke: s ? l.blockBorder : "rgba(0,0,0,0.4)", strokeWidth: 1.5 }),
2266
- s && /* @__PURE__ */ t("rect", { x: 0, y: 0, width: 4, height: C + 20, fill: o.color, clipPath: "url(#ghost-pal-clip)" }),
2267
- /* @__PURE__ */ t(
2052
+ const i = ct(e.defId), s = be(i), c = i.blockType === "command", f = Vt(i), g = Ee(i);
2053
+ return /* @__PURE__ */ y("svg", { style: { position: "fixed", top: 0, left: 0, width: "100%", height: "100%", pointerEvents: "none", zIndex: 9999 }, children: [
2054
+ c && /* @__PURE__ */ a("defs", { children: /* @__PURE__ */ a("clipPath", { id: "ghost-pal-clip", children: /* @__PURE__ */ a("path", { d: f }) }) }),
2055
+ /* @__PURE__ */ y("g", { transform: `translate(${e.x},${e.y})`, opacity: 0.8, children: [
2056
+ /* @__PURE__ */ a("path", { d: f, fill: c ? r.blockBody : i.color, stroke: c ? r.blockBorder : "rgba(0,0,0,0.4)", strokeWidth: 1.5 }),
2057
+ c && /* @__PURE__ */ a("rect", { x: 0, y: 0, width: 4, height: s + 20, fill: i.color, clipPath: "url(#ghost-pal-clip)" }),
2058
+ g.length > 0 && /* @__PURE__ */ a(Ut, { mouths: g, w: ue(i), isEmpty: () => !0 }),
2059
+ /* @__PURE__ */ a(
2268
2060
  "text",
2269
2061
  {
2270
2062
  x: 11,
2271
- y: C / 2 + 4,
2272
- fill: s ? l.blockText : "white",
2063
+ y: Xe(i) / 2 + 4,
2064
+ fill: c ? r.blockText : "white",
2273
2065
  fontSize: 11,
2274
2066
  fontWeight: "bold",
2275
2067
  fontFamily: "sans-serif",
2276
2068
  style: { userSelect: "none" },
2277
- children: o.name
2069
+ children: i.name
2278
2070
  }
2279
2071
  )
2280
2072
  ] })
2281
2073
  ] });
2282
2074
  }
2283
- function Bn({ blocksUrl: e = "/blocks.json", blocksUrls: n, onRun: r, onThemeChange: l, navTabs: i, initialState: o, onSave: a, themeId: p, hideTitleBar: C, getStateRef: s, additionalBlocks: P }) {
2284
- const [T, v] = U(() => {
2285
- if (p) return Ce.find((S) => S.id === p) ?? me;
2286
- const f = localStorage.getItem("cardcq-theme");
2287
- return Ce.find((S) => S.id === f) ?? me;
2075
+ function Ir(e, t) {
2076
+ return e.returnType === t || (e.usableAs?.includes(t) ?? !1);
2077
+ }
2078
+ function wr({
2079
+ blocksUrl: e = "/blocks.json",
2080
+ blocksUrls: t,
2081
+ onRun: n,
2082
+ onThemeChange: r,
2083
+ navTabs: o,
2084
+ initialState: i,
2085
+ onSave: s,
2086
+ themeId: c,
2087
+ hideTitleBar: f,
2088
+ getStateRef: g,
2089
+ additionalBlocks: h,
2090
+ dependencies: B,
2091
+ onDependenciesChange: W,
2092
+ packageBlocksUrl: w,
2093
+ availablePackages: N,
2094
+ packageActions: I,
2095
+ collaboration: v,
2096
+ scriptWriters: K,
2097
+ onExport: G
2098
+ }) {
2099
+ const [k, ne] = P(() => {
2100
+ if (c) return tt.find((d) => d.id === c) ?? qe;
2101
+ const l = ir("cardcq-theme");
2102
+ return tt.find((d) => d.id === l) ?? qe;
2288
2103
  });
2289
- ge(() => {
2290
- if (!p) return;
2291
- const f = Ce.find((S) => S.id === p) ?? me;
2292
- v(f);
2293
- }, [p]);
2294
- const [c, k] = U(!1), [x, M] = U(null), [I, _] = U(() => {
2295
- if (!o) return /* @__PURE__ */ new Map();
2296
- const f = new Map(o.blocks);
2297
- return f.forEach((S, m) => {
2298
- const w = parseInt(m.slice(1), 10);
2299
- !isNaN(w) && w >= dt && (dt = w + 1);
2300
- }), f;
2301
- }), Q = et(() => {
2302
- const f = /* @__PURE__ */ new Set();
2303
- for (const S of I.values())
2304
- ne(S.definitionId)?.blockType === "start" && f.add(S.definitionId);
2305
- return f;
2306
- }, [I]), [re, R] = U(null), [u, A] = U(/* @__PURE__ */ new Set()), [Y, g] = U(!1), [F, Z] = U(0), [fe, he] = U([]), [X, xe] = U([]);
2307
- ge(() => {
2308
- s && (s.current = () => ({ blocks: [...I.entries()] }));
2309
- }, [I, s]);
2310
- const ce = Te(null), We = Te(!1), Be = Te(null), He = (n ?? [e]).join("|");
2311
- ge(() => {
2312
- const f = He.split("|");
2313
- k(!1), M(null), tn(f[0]).then(async () => {
2314
- for (let S = 1; S < f.length; S++)
2315
- await ot({
2316
- id: `__extra_${S}__`,
2317
- name: `Extra ${S}`,
2318
- description: "",
2319
- url: f[S],
2320
- builtIn: !0
2321
- });
2322
- k(!0), xe(Xe());
2323
- }).catch((S) => M(String(S)));
2324
- }, [He]), ge(() => {
2325
- fetch("/packages.json").then((f) => f.json()).then(he).catch(() => {
2326
- });
2327
- }, []), ge(() => {
2328
- c && (mt("__inline__"), P && P.length > 0 && en(
2329
- { id: "__inline__", name: "Inline", description: "", url: "", builtIn: !0 },
2330
- P
2331
- ), xe(Xe()), Z((f) => f + 1), _((f) => yn(f)));
2332
- }, [P, c]);
2333
- const Ue = le(async (f, S) => {
2334
- if (S) {
2335
- const m = Xe().find((w) => w.info.id === f.id);
2336
- if (m) {
2337
- const w = new Set(m.blockIds);
2338
- _((D) => {
2339
- const W = new Map(D), N = [];
2340
- W.forEach((b) => {
2341
- w.has(b.definitionId) && N.push(b.instanceId);
2342
- });
2343
- const L = new Set(Ve(N, W));
2344
- return W.forEach((b) => {
2345
- if (L.has(b.instanceId)) return;
2346
- let j = !1, y = b;
2347
- b.nextBlockId && L.has(b.nextBlockId) && (y = { ...y, nextBlockId: null }, j = !0), b.parentBlockId && L.has(b.parentBlockId) && (y = { ...y, parentBlockId: null }, j = !0), j && W.set(b.instanceId, y);
2348
- }), L.forEach((b) => W.delete(b)), W;
2349
- });
2350
- }
2351
- mt(f.id);
2352
- } else
2353
- await ot(f);
2354
- xe(Xe()), Z((m) => m + 1);
2355
- }, []), de = le((f, S) => {
2356
- const m = Be.current?.getBoundingClientRect() ?? { left: 0, top: 0 };
2357
- return { x: f - m.left, y: S - m.top };
2358
- }, []), ae = le((f, S, m) => {
2359
- let D = null;
2360
- return I.forEach((W) => {
2361
- if (m.has(W.instanceId) || W.embeddedInBlockId || W.nextBlockId) return;
2362
- const N = ne(W.definitionId);
2363
- if (!N || N.blockType === "query") return;
2364
- const L = W.y + Ie(N), b = Math.abs(f - W.x), j = Math.abs(S - L);
2365
- if (b < 40 && j < 24) {
2366
- const y = Math.hypot(b, j);
2367
- (!D || y < D.dist) && (D = { blockId: W.instanceId, snapX: W.x, snapY: L, dist: y });
2368
- }
2369
- }), D;
2370
- }, [I]), Ee = le((f, S, m, w) => {
2371
- const D = ne(m);
2372
- if (!D || D.blockType !== "query") return null;
2373
- const W = 20;
2374
- let N = null;
2375
- return I.forEach((L) => {
2376
- if (w.has(L.instanceId)) return;
2377
- const b = ne(L.definitionId);
2378
- if (!b) return;
2379
- Oe(b, L.paramSlots, I).forEach((y) => {
2380
- if (y.type !== D.returnType || L.paramSlots[y.index]?.queryBlockId) return;
2381
- const V = L.x + y.x + y.w / 2, se = L.y + y.y + y.h / 2, K = Math.abs(f + y.w / 2 - V), oe = Math.abs(S + y.h / 2 - se);
2382
- if (K < y.w / 2 + W && oe < y.h / 2 + W) {
2383
- const H = Math.hypot(K, oe);
2384
- (!N || H < N.dist) && (N = { blockId: L.instanceId, slotIndex: y.index, snapX: L.x + y.x, snapY: L.y + y.y, dist: H });
2104
+ Q(() => {
2105
+ if (!c) return;
2106
+ const l = tt.find((d) => d.id === c) ?? qe;
2107
+ ne(l);
2108
+ }, [c]);
2109
+ const [X, re] = P(!1), [le, x] = P(null), T = v?.commands, q = v?.clientId ?? hr, [Y, ae] = P(() => vn({
2110
+ blocks: new Map((i?.blocks ?? []).map(([l, d]) => [l, Te(d)])),
2111
+ dependencies: B ?? []
2112
+ })), { state: ie, provisionalIds: m } = ze(() => dn(Y), [Y]), b = ie.blocks, M = te(Y), V = te(ie);
2113
+ Q(() => {
2114
+ M.current = Y, V.current = ie;
2115
+ });
2116
+ const Z = (B ?? []).map(He).join("|"), [Ie, ve] = P(Z);
2117
+ Z !== Ie && (ve(Z), !T && Z !== Y.confirmed.dependencies.map(He).join("|") && ae((l) => ({ ...l, confirmed: { ...l.confirmed, dependencies: B ?? [] } })));
2118
+ const fe = te(W);
2119
+ Q(() => {
2120
+ fe.current = W;
2121
+ });
2122
+ const [O, Oe] = P(null), Le = te(null), Pe = E((l) => {
2123
+ Oe(l), Le.current && clearTimeout(Le.current), Le.current = setTimeout(() => Oe(null), 5e3);
2124
+ }, []);
2125
+ Q(() => () => {
2126
+ Le.current && clearTimeout(Le.current);
2127
+ }, []);
2128
+ const pe = E((l) => {
2129
+ const d = M.current;
2130
+ M.current = l, V.current = dn(l).state, ae(l), l.confirmed.dependencies !== d.confirmed.dependencies && fe.current?.(l.confirmed.dependencies);
2131
+ }, []), De = E((l, d, u) => {
2132
+ const p = { id: d, clientId: q, baseVersion: M.current.version, command: u };
2133
+ if (T) {
2134
+ pe(l), T.submit(p);
2135
+ return;
2136
+ }
2137
+ const S = ln(l, p, l.version + 1);
2138
+ S.outOfSync ? (pe(an(l, d).sync), Pe("That change couldn't be made: the canvas has changed.")) : pe(S.sync);
2139
+ }, [q, T, pe, Pe]), he = E((l) => {
2140
+ if (!l) return;
2141
+ const d = ot();
2142
+ De(To(M.current, d, l), d, l);
2143
+ }, [De]), gt = E(() => {
2144
+ const l = ot(), d = Co(M.current, l);
2145
+ d && De(d.sync, l, d.command);
2146
+ }, [De]), yt = E(() => {
2147
+ const l = ot(), d = Eo(M.current, l);
2148
+ d && De(d.sync, l, d.command);
2149
+ }, [De]), Fe = v?.presence, jt = v?.presenceIntervalMs ?? Sn, oe = te(null), [Ft, Qt] = P([]);
2150
+ Q(() => {
2151
+ if (!Fe) return;
2152
+ const l = new Mo((u) => Fe.publish(u), jt);
2153
+ oe.current = l;
2154
+ const d = Fe.subscribe((u) => Qt(u.filter((p) => p.clientId !== q)));
2155
+ return () => {
2156
+ l.updateNow({ cursor: null, drag: null, typing: null }), l.dispose(), oe.current = null, d(), Qt([]);
2157
+ };
2158
+ }, [Fe, jt, q]), Q(() => {
2159
+ if (T)
2160
+ return T.subscribe((l) => {
2161
+ if (l.type === "snapshot") {
2162
+ const d = {
2163
+ blocks: new Map(l.state.blocks.map(([p, S]) => [p, Te(S)])),
2164
+ dependencies: l.state.dependencies
2165
+ }, u = Po(d, l.version, M.current);
2166
+ pe(u.sync), u.dropped > 0 && Pe("Reloaded from the server: your unconfirmed changes were discarded.");
2167
+ } else if (l.type === "applied") {
2168
+ const d = ln(M.current, l.envelope, l.version);
2169
+ d.outOfSync ? (Pe("Out of sync with the server: reloading…"), T.resync?.()) : pe(d.sync);
2170
+ } else {
2171
+ const d = an(M.current, l.id);
2172
+ pe(d.sync), d.action && Pe(gr(d.action.kind, l.code, l.message));
2385
2173
  }
2386
2174
  });
2387
- }), N;
2388
- }, [I]), _e = le((f) => {
2389
- if (ce.current?.moved) return;
2390
- const S = Rt(f, I), w = vt(S, I).map((D) => I.get(D)).filter(Boolean).map((D) => zt(D, I));
2391
- r?.(w);
2392
- }, [I, r]), [h, $] = U(null), E = le((f, S) => {
2393
- ce.current?.moved || $({ blockId: f, slotIndex: S });
2394
- }, []), z = le((f, S, m) => {
2395
- $(null), _((w) => bn(w, f, S, m));
2396
- }, []), q = le(() => $(null), []), J = le((f) => {
2397
- v(f), p || localStorage.setItem("cardcq-theme", f.id), l?.(f);
2398
- }, [l, p]), ve = le((f, S) => {
2399
- f.preventDefault();
2400
- const m = Re(S), w = we(m), D = Ie(m);
2401
- ce.current = {
2402
- type: "palette",
2403
- defId: S,
2404
- offsetX: w / 2,
2405
- offsetY: D / 2,
2406
- startClientX: f.clientX,
2407
- startClientY: f.clientY,
2408
- moved: !1
2409
- }, R({ x: f.clientX - w / 2, y: f.clientY - D / 2, defId: S }), f.target.setPointerCapture(f.pointerId);
2410
- }, []), ke = le((f, S) => {
2411
- f.preventDefault();
2412
- const m = I.get(S);
2413
- if (!m) return;
2414
- const { x: w, y: D } = de(f.clientX, f.clientY);
2415
- let W = m.x, N = m.y;
2416
- if (m.embeddedInBlockId) {
2417
- const V = I.get(m.embeddedInBlockId);
2418
- if (V) {
2419
- const K = Oe(Re(V.definitionId), V.paramSlots, I)[m.embeddedSlotIndex];
2420
- K && (W = V.x + K.x, N = V.y + K.y);
2421
- }
2175
+ }, [T, pe, Pe]);
2176
+ const [Se] = P(() => /* @__PURE__ */ Symbol("BlockEditor"));
2177
+ Q(() => (cr(Se), () => lr(Se)), [Se]);
2178
+ const Kt = E(() => ar(Se), [Se]);
2179
+ Q(() => {
2180
+ function l(d) {
2181
+ if (!dr(Se)) return;
2182
+ const u = d.target;
2183
+ if (u && (u.isContentEditable || ["INPUT", "TEXTAREA", "SELECT"].includes(u.tagName)) || !(d.ctrlKey || d.metaKey)) return;
2184
+ const p = d.key.toLowerCase();
2185
+ p === "z" && !d.shiftKey ? (d.preventDefault(), gt()) : (p === "z" && d.shiftKey || p === "y" && !d.metaKey) && (d.preventDefault(), yt());
2422
2186
  }
2423
- const L = w - W, b = D - N, y = ne(m.definitionId)?.blockType === "query" ? [S] : vt(S, I);
2424
- if (m.embeddedInBlockId || m.parentBlockId) {
2425
- const V = m.embeddedInBlockId, se = m.embeddedSlotIndex, K = m.parentBlockId;
2426
- _((oe) => {
2427
- const H = new Map(oe);
2428
- if (V) {
2429
- const O = H.get(V);
2430
- if (O) {
2431
- const ee = [...O.paramSlots];
2432
- ee[se] = { textValue: null, queryBlockId: null }, H.set(V, { ...O, paramSlots: ee });
2433
- }
2434
- H.set(S, { ...m, x: W, y: N, embeddedInBlockId: null, embeddedSlotIndex: -1 });
2187
+ return window.addEventListener("keydown", l), () => window.removeEventListener("keydown", l);
2188
+ }, [gt, yt, Se]);
2189
+ const Ln = ze(() => {
2190
+ const l = /* @__PURE__ */ new Set();
2191
+ for (const d of b.values())
2192
+ z(d.definitionId)?.blockType === "start" && l.add(d.definitionId);
2193
+ return l;
2194
+ }, [b]), [Rn, Qe] = P(null), [Hn, Gt] = P(/* @__PURE__ */ new Set()), [zn, Zt] = P(!1), [Jt, mt] = P(0), [Wn, kt] = P([]), $e = ze(() => qo(b), [b, Jt]);
2195
+ Q(() => {
2196
+ g && (g.current = () => ({ blocks: [...b.entries()] }));
2197
+ }, [b, g]);
2198
+ const se = te(null), xt = te(!1), Ke = te(null), en = (t ?? [e]).join("|"), bt = B !== void 0 || v?.commands !== void 0 && w !== void 0, It = te(bt ? ie.dependencies : void 0), vt = te(w);
2199
+ Q(() => {
2200
+ It.current = bt ? ie.dependencies : void 0, vt.current = w;
2201
+ });
2202
+ const qn = ie.dependencies.map(He).join("|"), Ge = te(Promise.resolve());
2203
+ Q(() => {
2204
+ let l = !1;
2205
+ const d = en.split("|");
2206
+ return re(!1), x(null), Ge.current = Ge.current.then(async () => {
2207
+ if (!l)
2208
+ try {
2209
+ await No(d[0]);
2210
+ for (let u = 1; u < d.length && !l; u++)
2211
+ await Ot({
2212
+ id: `__extra_${u}__`,
2213
+ name: `Extra ${u}`,
2214
+ description: "",
2215
+ url: d[u],
2216
+ builtIn: !0
2217
+ });
2218
+ if (l || (await fn(It.current, vt.current), l)) return;
2219
+ kt(We()), mt((u) => u + 1), re(!0);
2220
+ } catch (u) {
2221
+ l || x(String(u));
2222
+ }
2223
+ }), () => {
2224
+ l = !0;
2225
+ };
2226
+ }, [en]), Q(() => {
2227
+ if (!X) return;
2228
+ let l = !1;
2229
+ return Ge.current = Ge.current.then(async () => {
2230
+ if (!l)
2231
+ try {
2232
+ if (!await fn(It.current, vt.current)) return;
2233
+ kt(We()), mt((u) => u + 1);
2234
+ } catch (d) {
2235
+ x(String(d));
2435
2236
  }
2436
- if (K) {
2437
- const O = H.get(K);
2438
- O && H.set(K, { ...O, nextBlockId: null });
2439
- const ee = H.get(S);
2440
- ee && H.set(S, { ...ee, parentBlockId: null });
2237
+ }), () => {
2238
+ l = !0;
2239
+ };
2240
+ }, [X, qn]), Q(() => {
2241
+ X && (Lt("__inline__"), h && h.length > 0 && _o(
2242
+ { id: "__inline__", name: "Inline", description: "", url: "", builtIn: !0 },
2243
+ h
2244
+ ), kt(We()), mt((l) => l + 1));
2245
+ }, [h, X]);
2246
+ const ge = E((l, d) => {
2247
+ const u = Ke.current?.getBoundingClientRect() ?? { left: 0, top: 0 };
2248
+ return { x: l - u.left, y: d - u.top };
2249
+ }, []), tn = E((l, d, u, p, S) => {
2250
+ if (z(u)?.blockType !== "command") return null;
2251
+ let H = null;
2252
+ const L = (C) => {
2253
+ (!H || C.dist < H.dist) && (H = C);
2254
+ }, R = (C, U) => {
2255
+ const j = Math.abs(l - C), $ = Math.abs(d - U);
2256
+ return j < 40 && $ < 24 ? Math.hypot(j, $) : null;
2257
+ };
2258
+ return b.forEach((C) => {
2259
+ if (S.has(C.instanceId)) return;
2260
+ const U = z(C.definitionId), j = $e.get(C.instanceId);
2261
+ if (!(!U || U.blockType === "query" || !j)) {
2262
+ if (!C.nextBlockId || C.nextBlockId === p) {
2263
+ const $ = j.y + be(U, C.paramSlots, b), ce = R(j.x, $);
2264
+ ce !== null && L({ kind: "next", blockId: C.instanceId, snapX: j.x, snapY: $, dist: ce });
2265
+ }
2266
+ for (const $ of Ee(U, C.paramSlots, b)) {
2267
+ const ce = j.x + $.x, Ze = j.y + $.y, Je = R(ce, Ze);
2268
+ Je !== null && L({ kind: "mouth", blockId: C.instanceId, slotIndex: $.index, snapX: ce, snapY: Ze, dist: Je });
2269
+ }
2270
+ }
2271
+ }), H;
2272
+ }, [b, $e]), nn = E((l, d, u, p, S) => {
2273
+ const A = z(u);
2274
+ if (!A || A.blockType !== "query") return null;
2275
+ const H = 20;
2276
+ let L = null;
2277
+ return b.forEach((R) => {
2278
+ if (S.has(R.instanceId)) return;
2279
+ const C = z(R.definitionId), U = $e.get(R.instanceId);
2280
+ if (!C || !U) return;
2281
+ je(C, R.paramSlots, b).forEach(($) => {
2282
+ if (!Ir(A, $.type)) return;
2283
+ const ce = R.paramSlots[$.index]?.queryBlockId;
2284
+ if (ce && ce !== p) return;
2285
+ const Ze = U.x + $.x + $.w / 2, Je = U.y + $.y + $.h / 2, rn = Math.abs(l + $.w / 2 - Ze), sn = Math.abs(d + $.h / 2 - Je);
2286
+ if (rn < $.w / 2 + H && sn < $.h / 2 + H) {
2287
+ const cn = Math.hypot(rn, sn);
2288
+ (!L || cn < L.dist) && (L = { blockId: R.instanceId, slotIndex: $.index, snapX: U.x + $.x, snapY: U.y + $.y, dist: cn });
2441
2289
  }
2442
- return H;
2443
2290
  });
2444
- }
2445
- ce.current = {
2291
+ }), L;
2292
+ }, [b, $e]), Yn = E((l) => {
2293
+ if (se.current?.moved) return;
2294
+ const d = Dt(l, b), p = Pt(d, b).map((S) => b.get(S)).filter(Boolean).map((S) => Mt(S, b));
2295
+ n?.(p);
2296
+ }, [b, n]), [Vn, St] = P(null), Re = te(null), Un = E((l, d) => {
2297
+ if (se.current?.moved) return;
2298
+ const u = V.current.blocks.get(l)?.paramSlots[d]?.textValue ?? null;
2299
+ Re.current = { blockId: l, slotIndex: d, startText: u }, St(Re.current), oe.current?.updateNow({ typing: { blockId: l, slot: d, text: u ?? "" } });
2300
+ }, []), Xn = E((l, d, u) => {
2301
+ oe.current?.update({ typing: { blockId: l, slot: d, text: u } });
2302
+ }, []), jn = E((l, d, u) => {
2303
+ const p = Re.current;
2304
+ Re.current = null, St(null), !(!p || p.blockId !== l || p.slotIndex !== d) && (oe.current?.updateNow({ typing: null }), he(Bo(l, d, p.startText, u)));
2305
+ }, [he]), Fn = E(() => {
2306
+ Re.current = null, St(null), oe.current?.updateNow({ typing: null });
2307
+ }, []), Qn = E((l) => {
2308
+ const d = V.current, u = new Set(l.map(J)), p = new Set(d.dependencies.filter((A) => !u.has(J(A))).map(He)), S = [...d.blocks.values()].filter((A) => p.has($n(A.definitionId) ?? "")).map((A) => A.instanceId);
2309
+ he(wo(d, l, S));
2310
+ }, [he]), Kn = E((l) => {
2311
+ ne(l), c || sr("cardcq-theme", l.id), r?.(l);
2312
+ }, [r, c]), on = E((l, d) => {
2313
+ l.preventDefault();
2314
+ const u = ct(d), p = ue(u), S = be(u);
2315
+ se.current = {
2316
+ type: "palette",
2317
+ defId: d,
2318
+ offsetX: p / 2,
2319
+ offsetY: S / 2,
2320
+ startClientX: l.clientX,
2321
+ startClientY: l.clientY,
2322
+ moved: !1
2323
+ }, Qe({ x: l.clientX - p / 2, y: l.clientY - S / 2, defId: d }), l.target.setPointerCapture(l.pointerId);
2324
+ }, []), Gn = E((l, d) => {
2325
+ l.preventDefault();
2326
+ const u = b.get(d);
2327
+ if (!u) return;
2328
+ const { x: p, y: S } = ge(l.clientX, l.clientY), { x: A, y: H } = $e.get(d) ?? u, L = p - A, R = S - H, U = z(u.definitionId)?.blockType === "query" ? [d] : Pt(d, b);
2329
+ se.current = {
2446
2330
  type: "canvas",
2447
- defId: m.definitionId,
2448
- instanceId: S,
2449
- carriedIds: y,
2331
+ defId: u.definitionId,
2332
+ instanceId: d,
2333
+ carriedIds: U,
2450
2334
  offsetX: L,
2451
- offsetY: b,
2452
- startClientX: f.clientX,
2453
- startClientY: f.clientY,
2335
+ offsetY: R,
2336
+ startClientX: l.clientX,
2337
+ startClientY: l.clientY,
2454
2338
  moved: !1
2455
- }, A(new Set(y)), R({ x: f.clientX - L, y: f.clientY - b, defId: m.definitionId }), f.target.setPointerCapture(f.pointerId);
2456
- }, [I, de]);
2457
- ge(() => {
2458
- function f(m) {
2459
- const w = ce.current;
2460
- if (w && ((Math.abs(m.clientX - w.startClientX) > 4 || Math.abs(m.clientY - w.startClientY) > 4) && (w.moved = !0), !!w.moved && (R({ x: m.clientX - w.offsetX, y: m.clientY - w.offsetY, defId: w.defId }), w.type === "canvas"))) {
2461
- const D = Be.current?.getBoundingClientRect(), W = !!D && m.clientX < D.left;
2462
- W !== We.current && (We.current = W, g(W));
2339
+ }, Gt(/* @__PURE__ */ new Set([d])), Qe({ x: l.clientX - L, y: l.clientY - R, defId: u.definitionId }), l.target.setPointerCapture(l.pointerId);
2340
+ }, [b, $e, ge]);
2341
+ Q(() => {
2342
+ function l(u) {
2343
+ const p = se.current;
2344
+ if (!p) return;
2345
+ let S = !1;
2346
+ if (!p.moved && (Math.abs(u.clientX - p.startClientX) > 4 || Math.abs(u.clientY - p.startClientY) > 4) && (p.moved = !0, S = !0), !p.moved) return;
2347
+ Qe({ x: u.clientX - p.offsetX, y: u.clientY - p.offsetY, defId: p.defId });
2348
+ const A = ge(u.clientX - p.offsetX, u.clientY - p.offsetY), H = p.type === "canvas" ? { drag: { leadId: p.instanceId, at: A }, cursor: ge(u.clientX, u.clientY) } : { drag: { definitionId: p.defId, at: A }, cursor: ge(u.clientX, u.clientY) };
2349
+ if (S ? oe.current?.updateNow(H) : oe.current?.update(H), p.type === "canvas") {
2350
+ const L = Ke.current?.getBoundingClientRect(), R = !!L && u.clientX < L.left;
2351
+ R !== xt.current && (xt.current = R, Zt(R));
2463
2352
  }
2464
2353
  }
2465
- function S(m) {
2466
- const w = ce.current;
2467
- if (!w || (ce.current = null, R(null), A(/* @__PURE__ */ new Set()), We.current = !1, g(!1), !w.moved)) return;
2468
- const D = Be.current?.getBoundingClientRect();
2469
- if (!D) return;
2470
- if (w.type === "canvas" && m.clientX < D.left) {
2471
- _((b) => mn(b, w.carriedIds));
2354
+ function d(u) {
2355
+ const p = se.current;
2356
+ if (!p || (se.current = null, Qe(null), Gt(/* @__PURE__ */ new Set()), xt.current = !1, Zt(!1), !p.moved)) return;
2357
+ oe.current?.updateNow({ drag: null });
2358
+ const S = Ke.current?.getBoundingClientRect();
2359
+ if (!S) return;
2360
+ const A = V.current;
2361
+ if (p.type === "canvas" && u.clientX < S.left) {
2362
+ he($o(A, p.instanceId));
2472
2363
  return;
2473
2364
  }
2474
- const W = m.clientX - w.offsetX - D.left, N = m.clientY - w.offsetY - D.top, L = Re(w.defId);
2475
- if (w.type === "palette") {
2476
- if (m.clientX < D.left || m.clientX > D.right || m.clientY < D.top || m.clientY > D.bottom || L?.blockType === "start" && [...I.values()].some((y) => y.definitionId === w.defId))
2477
- return;
2478
- const b = xn(w.defId, W, N);
2479
- if (L.blockType !== "query") {
2480
- const j = ae(W, N, /* @__PURE__ */ new Set());
2481
- if (j) {
2482
- const { blockId: y, snapX: V, snapY: se } = j;
2483
- b.x = V, b.y = se, b.parentBlockId = y, _((K) => {
2484
- const oe = new Map(K), H = oe.get(y);
2485
- return oe.set(y, { ...H, nextBlockId: b.instanceId }), oe.set(b.instanceId, b), oe;
2486
- });
2487
- return;
2488
- }
2489
- } else {
2490
- const j = Ee(W, N, w.defId, /* @__PURE__ */ new Set());
2491
- if (j) {
2492
- const { blockId: y, slotIndex: V, snapX: se, snapY: K } = j;
2493
- b.x = se, b.y = K, b.embeddedInBlockId = y, b.embeddedSlotIndex = V, _((oe) => {
2494
- const H = new Map(oe), O = H.get(y), ee = [...O.paramSlots];
2495
- return ee[V] = { textValue: null, queryBlockId: b.instanceId }, H.set(y, { ...O, paramSlots: ee }), H.set(b.instanceId, b), H;
2496
- });
2497
- return;
2498
- }
2499
- }
2500
- _((j) => {
2501
- const y = new Map(j);
2502
- return y.set(b.instanceId, b), y;
2503
- });
2365
+ const H = u.clientX - p.offsetX - S.left, L = u.clientY - p.offsetY - S.top, R = ct(p.defId), C = p.type === "canvas" ? p.instanceId : null, U = new Set(C ? ft(A.blocks, C) : []);
2366
+ let j = null;
2367
+ if (R.blockType === "query") {
2368
+ const $ = nn(H, L, p.defId, C, U);
2369
+ $ && (j = { socket: $.blockId, slot: $.slotIndex });
2504
2370
  } else {
2505
- const b = w.instanceId;
2506
- _((j) => {
2507
- const y = new Map(j), V = y.get(b);
2508
- if (!V) return j;
2509
- const se = W - V.x, K = N - V.y;
2510
- if (Ve(w.carriedIds, y).forEach((H) => {
2511
- const O = y.get(H);
2512
- O && y.set(H, { ...O, x: O.x + se, y: O.y + K });
2513
- }), L.blockType !== "query") {
2514
- const H = ae(W, N, new Set(w.carriedIds));
2515
- if (H) {
2516
- const { blockId: O, snapX: ee, snapY: Ze } = H, Je = ee - W, Ge = Ze - N;
2517
- w.carriedIds.forEach((De) => {
2518
- const Le = y.get(De);
2519
- Le && y.set(De, { ...Le, x: Le.x + Je, y: Le.y + Ge });
2520
- });
2521
- const Ye = y.get(O);
2522
- y.set(O, { ...Ye, nextBlockId: b }), y.set(b, { ...y.get(b), parentBlockId: O });
2523
- }
2524
- } else {
2525
- const H = Ee(W, N, w.defId, /* @__PURE__ */ new Set([b]));
2526
- if (H) {
2527
- const { blockId: O, slotIndex: ee, snapX: Ze, snapY: Je } = H, Ge = y.get(b);
2528
- y.set(b, { ...Ge, x: Ze, y: Je, embeddedInBlockId: O, embeddedSlotIndex: ee });
2529
- const Ye = y.get(O), De = [...Ye.paramSlots];
2530
- De[ee] = { textValue: null, queryBlockId: b }, y.set(O, { ...Ye, paramSlots: De });
2531
- }
2532
- }
2533
- return y;
2534
- });
2371
+ const $ = tn(H, L, p.defId, C, U);
2372
+ $ && (j = mr($));
2535
2373
  }
2374
+ if (p.type === "palette") {
2375
+ if (u.clientX < S.left || u.clientX > S.right || u.clientY < S.top || u.clientY > S.bottom || R.blockType === "start" && [...A.blocks.values()].some((ce) => ce.definitionId === p.defId))
2376
+ return;
2377
+ he(vo(A, xr(p.defId, H, L), { x: H, y: L }, j));
2378
+ } else
2379
+ he(So(A, C, { x: H, y: L }, j));
2536
2380
  }
2537
- return document.addEventListener("pointermove", f), document.addEventListener("pointerup", S), () => {
2538
- document.removeEventListener("pointermove", f), document.removeEventListener("pointerup", S);
2381
+ return document.addEventListener("pointermove", l), document.addEventListener("pointerup", d), () => {
2382
+ document.removeEventListener("pointermove", l), document.removeEventListener("pointerup", d);
2539
2383
  };
2540
- }, [I, ae, Ee]);
2541
- const Ke = {
2384
+ }, [tn, nn, he, ge]);
2385
+ const Zn = E((l) => {
2386
+ se.current?.moved || oe.current?.update({ cursor: ge(l.clientX, l.clientY) });
2387
+ }, [ge]), Jn = E(() => {
2388
+ se.current?.moved || oe.current?.updateNow({ cursor: null });
2389
+ }, []), eo = E((l) => {
2390
+ const d = l.write(Yo(V.current, z));
2391
+ if (G) {
2392
+ G(d, l);
2393
+ return;
2394
+ }
2395
+ const u = URL.createObjectURL(new Blob([d], { type: "text/plain" })), p = document.createElement("a");
2396
+ p.href = u, p.download = `behavior.${l.fileExtension}`, p.click(), URL.revokeObjectURL(u);
2397
+ }, [G]), $t = {
2542
2398
  display: "flex",
2543
2399
  flexDirection: "column",
2544
2400
  flex: 1,
@@ -2546,45 +2402,45 @@ function Bn({ blocksUrl: e = "/blocks.json", blocksUrls: n, onRun: r, onThemeCha
2546
2402
  width: "100%",
2547
2403
  height: "100%",
2548
2404
  overflow: "hidden",
2549
- background: T.appBg,
2550
- color: T.textPrimary,
2405
+ background: k.appBg,
2406
+ color: k.textPrimary,
2551
2407
  fontFamily: "system-ui, sans-serif",
2552
2408
  boxSizing: "border-box"
2553
- }, Ht = {
2409
+ }, to = {
2554
2410
  display: "flex",
2555
2411
  flex: 1,
2556
2412
  minHeight: 0,
2557
2413
  overflow: "hidden"
2558
2414
  };
2559
- return x ? /* @__PURE__ */ t(Pe.Provider, { value: T, children: /* @__PURE__ */ d("div", { style: { ...Ke, alignItems: "center", justifyContent: "center", color: "#c06060", fontFamily: "monospace" }, children: [
2415
+ return le ? /* @__PURE__ */ a(nt.Provider, { value: k, children: /* @__PURE__ */ y("div", { style: { ...$t, alignItems: "center", justifyContent: "center", color: "#c06060", fontFamily: "monospace" }, children: [
2560
2416
  "Failed to load blocks: ",
2561
- x
2562
- ] }) }) : c ? /* @__PURE__ */ t(Pe.Provider, { value: T, children: /* @__PURE__ */ d("div", { style: Ke, children: [
2563
- !C && /* @__PURE__ */ d("div", { style: {
2417
+ le
2418
+ ] }) }) : X ? /* @__PURE__ */ a(nt.Provider, { value: k, children: /* @__PURE__ */ y("div", { style: $t, onPointerDownCapture: Kt, onFocusCapture: Kt, children: [
2419
+ !f && /* @__PURE__ */ y("div", { style: {
2564
2420
  flexShrink: 0,
2565
2421
  display: "flex",
2566
2422
  alignItems: "center",
2567
2423
  gap: 10,
2568
2424
  padding: "0 14px",
2569
2425
  height: 38,
2570
- background: T.titleBg,
2571
- borderBottom: `1px solid ${T.border}`
2426
+ background: k.titleBg,
2427
+ borderBottom: `1px solid ${k.border}`
2572
2428
  }, children: [
2573
- /* @__PURE__ */ t("span", { style: { color: T.titlePrimaryText, fontWeight: "bold", fontSize: 13, letterSpacing: 1, textTransform: "uppercase" }, children: "CardCQ" }),
2574
- /* @__PURE__ */ t("span", { style: { color: T.titleSecondaryText, fontSize: 11, letterSpacing: 0.5 }, children: "Behavior Editor" }),
2575
- i,
2576
- /* @__PURE__ */ d("div", { style: { marginLeft: "auto", display: "flex", alignItems: "center", gap: 8 }, children: [
2577
- a && /* @__PURE__ */ t(
2429
+ /* @__PURE__ */ a("span", { style: { color: k.titlePrimaryText, fontWeight: "bold", fontSize: 13, letterSpacing: 1, textTransform: "uppercase" }, children: "CardCQ" }),
2430
+ /* @__PURE__ */ a("span", { style: { color: k.titleSecondaryText, fontSize: 11, letterSpacing: 0.5 }, children: "Behavior Editor" }),
2431
+ o,
2432
+ /* @__PURE__ */ y("div", { style: { marginLeft: "auto", display: "flex", alignItems: "center", gap: 8 }, children: [
2433
+ s && /* @__PURE__ */ a(
2578
2434
  "button",
2579
2435
  {
2580
- onClick: () => a({ blocks: [...I.entries()] }),
2436
+ onClick: () => s({ blocks: [...b.entries()] }),
2581
2437
  style: {
2582
2438
  padding: "3px 10px",
2583
2439
  fontSize: 11,
2584
2440
  fontWeight: "bold",
2585
- background: T.titleBg,
2586
- color: T.titlePrimaryText,
2587
- border: `1px solid ${T.border}`,
2441
+ background: k.titleBg,
2442
+ color: k.titlePrimaryText,
2443
+ border: `1px solid ${k.border}`,
2588
2444
  borderRadius: 4,
2589
2445
  cursor: "pointer",
2590
2446
  letterSpacing: 0.5
@@ -2592,50 +2448,240 @@ function Bn({ blocksUrl: e = "/blocks.json", blocksUrls: n, onRun: r, onThemeCha
2592
2448
  children: "Save"
2593
2449
  }
2594
2450
  ),
2595
- !p && /* @__PURE__ */ t(St, { onSelect: J })
2451
+ !c && /* @__PURE__ */ a(or, { onSelect: Kn })
2596
2452
  ] })
2597
2453
  ] }),
2598
- /* @__PURE__ */ d("div", { style: Ht, children: [
2599
- /* @__PURE__ */ t(
2600
- un,
2454
+ /* @__PURE__ */ y("div", { style: to, children: [
2455
+ /* @__PURE__ */ a(
2456
+ tr,
2601
2457
  {
2602
- onPointerDown: ve,
2603
- isDropTarget: Y,
2604
- registryVersion: F,
2605
- availablePackages: fe,
2606
- loadedPackages: X,
2607
- onPackageToggle: Ue,
2608
- placedStartIds: Q
2458
+ onPointerDown: on,
2459
+ isDropTarget: zn,
2460
+ registryVersion: Jt,
2461
+ packages: bt && (W || T) ? {
2462
+ available: N ?? [],
2463
+ dependencies: ie.dependencies,
2464
+ onChange: Qn,
2465
+ actions: I,
2466
+ blockCounts: kr(b),
2467
+ conflictCounts: new Map(Wn.filter((l) => l.info.id.startsWith(dt)).map((l) => [l.info.name, l.conflictIds.length]))
2468
+ } : void 0,
2469
+ placedStartIds: Ln
2609
2470
  }
2610
2471
  ),
2611
- /* @__PURE__ */ t(
2612
- Dt,
2472
+ /* @__PURE__ */ y(
2473
+ "div",
2613
2474
  {
2614
- ref: Be,
2615
- blocks: I,
2616
- draggingIds: u,
2617
- onBlockPointerDown: ke,
2618
- onBlockClick: _e,
2619
- onSocketClick: E,
2620
- editingSocket: h,
2621
- onSocketCommit: z,
2622
- onSocketCancelEdit: q,
2623
- onOutputDrag: ve
2475
+ style: { flex: 1, minWidth: 0, display: "flex", position: "relative" },
2476
+ onPointerMove: Zn,
2477
+ onPointerLeave: Jn,
2478
+ children: [
2479
+ /* @__PURE__ */ a(
2480
+ Nn,
2481
+ {
2482
+ ref: Ke,
2483
+ blocks: b,
2484
+ draggingIds: Hn,
2485
+ provisionalIds: m,
2486
+ onBlockPointerDown: Gn,
2487
+ onBlockClick: Yn,
2488
+ onSocketClick: Un,
2489
+ editingSocket: Vn,
2490
+ onSocketInput: Xn,
2491
+ onSocketCommit: jn,
2492
+ onSocketCancelEdit: Fn,
2493
+ onOutputDrag: on,
2494
+ overlay: Ft.length > 0 ? /* @__PURE__ */ a(pr, { peers: Ft, blocks: b, layout: $e }) : null
2495
+ }
2496
+ ),
2497
+ /* @__PURE__ */ a(
2498
+ rr,
2499
+ {
2500
+ canUndo: st(Y) && Y.undo.length > 0,
2501
+ canRedo: st(Y) && Y.redo.length > 0,
2502
+ onUndo: gt,
2503
+ onRedo: yt,
2504
+ notice: O,
2505
+ extra: K && K.length > 0 ? /* @__PURE__ */ a(ur, { writers: K, onExport: eo }) : null
2506
+ }
2507
+ )
2508
+ ]
2624
2509
  }
2625
2510
  )
2626
2511
  ] }),
2627
- /* @__PURE__ */ t(vn, { ghostPos: re, dragRef: ce, blocks: I })
2628
- ] }) }) : /* @__PURE__ */ t(Pe.Provider, { value: T, children: /* @__PURE__ */ t("div", { style: { ...Ke, alignItems: "center", justifyContent: "center", color: T.textMuted }, children: "Loading…" }) });
2512
+ /* @__PURE__ */ a(br, { ghostPos: Rn, dragRef: se, blocks: b })
2513
+ ] }) }) : /* @__PURE__ */ a(nt.Provider, { value: k, children: /* @__PURE__ */ a("div", { style: { ...$t, alignItems: "center", justifyContent: "center", color: k.textMuted }, children: "Loading…" }) });
2514
+ }
2515
+ function Xt(e) {
2516
+ const t = e.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").replace(/[^A-Za-z0-9]+/g, "_").replace(/^_+|_+$/g, "").toLowerCase();
2517
+ return /^[0-9]/.test(t) ? `_${t}` : t || "_";
2518
+ }
2519
+ function At(e) {
2520
+ return JSON.stringify(e);
2521
+ }
2522
+ function On(e, t) {
2523
+ switch (e.kind) {
2524
+ case "text":
2525
+ return t === "string" ? At(e.text) : t === "boolean" ? e.text.toLowerCase() === "true" ? "True" : "False" : /^-?\d+(\.\d+)?$/.test(e.text) ? e.text : At(e.text);
2526
+ case "query":
2527
+ return rt(e.node);
2528
+ case "body":
2529
+ return "None";
2530
+ // mouths are written as blocks, not arguments
2531
+ case "empty":
2532
+ return "None";
2533
+ }
2534
+ }
2535
+ function rt(e) {
2536
+ const t = e.args.filter((n) => n.value.kind !== "body").map((n) => On(n.value, n.type));
2537
+ return `${Xt(e.name)}(${t.join(", ")})`;
2538
+ }
2539
+ function at(e, t) {
2540
+ return e.length === 0 ? [`${t}pass`] : e.flatMap((n) => {
2541
+ const r = n.args.filter((i) => i.value.kind === "body");
2542
+ if (r.length === 0) return [`${t}${rt(n)}`];
2543
+ const o = `${t} `;
2544
+ if (r.length === 1) {
2545
+ const i = r[0].value;
2546
+ return [`${t}with ${rt(n)}:`, ...at(i.body, o)];
2547
+ }
2548
+ return [
2549
+ `${t}with ${rt(n)}:`,
2550
+ ...r.flatMap((i) => [
2551
+ `${o}with ${Xt(i.name)}:`,
2552
+ ...at(i.value.body, `${o} `)
2553
+ ])
2554
+ ];
2555
+ });
2556
+ }
2557
+ const Tr = {
2558
+ id: "python",
2559
+ label: "Python",
2560
+ fileExtension: "py",
2561
+ write(e) {
2562
+ return `# Generated by the block editor
2563
+
2564
+ ${e.roots.map((n, r) => {
2565
+ const [o, ...i] = n.body;
2566
+ if (o?.blockType === "start") {
2567
+ const s = o.args.filter((c) => c.value.kind !== "body").map((c) => On(c.value, c.type));
2568
+ return [
2569
+ `@on(${[At(o.name), ...s].join(", ")})`,
2570
+ `def ${Xt(o.name)}():`,
2571
+ ...at(i, " ")
2572
+ ].join(`
2573
+ `);
2574
+ }
2575
+ return [`def chain_${r + 1}():`, ...at(n.body, " ")].join(`
2576
+ `);
2577
+ }).join(`
2578
+
2579
+
2580
+ `)}
2581
+ `;
2582
+ }
2583
+ };
2584
+ class Cr {
2585
+ state;
2586
+ version = 0;
2587
+ clients = /* @__PURE__ */ new Map();
2588
+ /** How long the server takes to answer a command (to make pending actions visible). */
2589
+ delayMs;
2590
+ constructor(t, n = 0) {
2591
+ this.state = t, this.delayMs = n;
2592
+ }
2593
+ get delay() {
2594
+ return this.delayMs;
2595
+ }
2596
+ setDelay(t) {
2597
+ this.delayMs = t;
2598
+ }
2599
+ /** The server's current state and version. */
2600
+ get current() {
2601
+ return { state: this.state, version: this.version };
2602
+ }
2603
+ /** A client's channels. Connecting again with the same id gives channels to the same client (its listeners stay). */
2604
+ connect(t, n, r) {
2605
+ const o = this.clients.get(t) ?? {
2606
+ id: t,
2607
+ name: n,
2608
+ color: r,
2609
+ commandListeners: /* @__PURE__ */ new Set(),
2610
+ presenceListeners: /* @__PURE__ */ new Set(),
2611
+ presence: { cursor: null, drag: null, typing: null }
2612
+ };
2613
+ return o.name = n, o.color = r, this.clients.set(t, o), { commands: {
2614
+ submit: (c) => this.later(() => this.receive(c)),
2615
+ subscribe: (c) => (o.commandListeners.add(c), this.later(() => c(this.snapshot())), () => o.commandListeners.delete(c)),
2616
+ resync: () => this.later(() => o.commandListeners.forEach((c) => c(this.snapshot())))
2617
+ }, presence: {
2618
+ publish: (c) => {
2619
+ o.presence = c, this.broadcastPresence();
2620
+ },
2621
+ subscribe: (c) => (o.presenceListeners.add(c), c(this.peersOf(t)), () => o.presenceListeners.delete(c))
2622
+ } };
2623
+ }
2624
+ /**
2625
+ * A client went away (closed, or timed out on a real transport): its listeners are dropped and it leaves the
2626
+ * others' peer lists.
2627
+ */
2628
+ disconnect(t) {
2629
+ this.clients.delete(t) && this.broadcastPresence();
2630
+ }
2631
+ later(t) {
2632
+ this.delayMs > 0 ? setTimeout(t, this.delayMs) : queueMicrotask(t);
2633
+ }
2634
+ snapshot() {
2635
+ return { type: "snapshot", state: { blocks: [...this.state.blocks.entries()], dependencies: this.state.dependencies }, version: this.version };
2636
+ }
2637
+ receive(t) {
2638
+ try {
2639
+ this.state = Ve(this.state, t.command);
2640
+ } catch (r) {
2641
+ if (!(r instanceof _)) throw r;
2642
+ const o = { type: "rejected", id: t.id, code: r.code, message: r.message };
2643
+ this.clients.get(t.clientId)?.commandListeners.forEach((i) => i(o));
2644
+ return;
2645
+ }
2646
+ this.version += 1;
2647
+ const n = { type: "applied", envelope: t, version: this.version };
2648
+ this.clients.forEach((r) => r.commandListeners.forEach((o) => o(n)));
2649
+ }
2650
+ peersOf(t) {
2651
+ return [...this.clients.values()].filter((n) => n.id !== t).map((n) => ({ ...n.presence, clientId: n.id, name: n.name, color: n.color }));
2652
+ }
2653
+ broadcastPresence() {
2654
+ this.clients.forEach((t) => t.presenceListeners.forEach((n) => n(this.peersOf(t.id))));
2655
+ }
2629
2656
  }
2630
2657
  export {
2631
- Bn as BlockEditor,
2632
- wn as CardDesigner,
2633
- In as CardPreview,
2634
- Ce as THEMES,
2635
- Pe as ThemeContext,
2636
- St as ThemeSwitcher,
2637
- me as darkTheme,
2638
- Bn as default,
2639
- Nt as defaultCardDesign,
2640
- G as useTheme
2658
+ wr as BlockEditor,
2659
+ Br as COMMANDS_VERSION,
2660
+ Tt as COMMAND_PARAM_TYPE,
2661
+ _ as CommandRejected,
2662
+ Cr as LocalServer,
2663
+ tt as THEMES,
2664
+ nt as ThemeContext,
2665
+ or as ThemeSwitcher,
2666
+ Ve as applyCommand,
2667
+ wo as changeDependencies,
2668
+ co as compareVersions,
2669
+ qe as darkTheme,
2670
+ wr as default,
2671
+ $o as deleteChain,
2672
+ ft as fragmentOf,
2673
+ In as invertCommand,
2674
+ So as moveChain,
2675
+ Te as normalizeBlock,
2676
+ ut as normalizeSlot,
2677
+ Me as normalizeText,
2678
+ J as packageKey,
2679
+ vo as placeNewBlock,
2680
+ Nt as placeOf,
2681
+ Tr as pythonWriter,
2682
+ kn as roundPosition,
2683
+ bo as samePlace,
2684
+ Bo as setSocketText,
2685
+ Yo as toProgram,
2686
+ ee as useTheme
2641
2687
  };