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