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