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