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