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