@kolkrabbi/design-editor 0.48.0 → 0.49.1

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,2129 @@
1
+ import { E as e, o as t, w as n } from "./__vite-browser-external-y2xWjzgx.js";
2
+ import { $ as r, A as i, B as a, E as o, Fn as s, Hn as c, J as l, Mt as u, Nr as d, O as f, Wn as p, X as m, Z as ee, q as h, xn as g, z as _ } from "./rolls-ZToBSscx.js";
3
+ import "./useLayerEdit-D6vwfIoB.js";
4
+ import "./effectCategories-B5jhXEyy.js";
5
+ import "./generators-OCg5XjTX.js";
6
+ import { g as v } from "./store-BDAxvWTE.js";
7
+ import { n as y, r as b } from "./BindDot-BAAc-KSs.js";
8
+ import { l as te } from "./Timeline-BH3BF2m4.js";
9
+ import { h as x } from "./src-PZgdetsA.js";
10
+ import { At as ne, C as re, E as ie, It as S, Pt as C, T as ae, Tt as w, _t as T, at as oe, bt as se, gt as ce, in as le, j as ue, rt as de, vt as fe, yt as pe, z as me } from "./core-DyfKZlBI.js";
11
+ import { t as he } from "./previewScale-C6EBx--U.js";
12
+ import { Button as E, ButtonGroup as ge, CommandOverlay as _e, Dropdown as ve, Input as ye, KbdKeys as be, LabeledControl as xe, LabeledControlSection as D, Menu as Se, ModalDialog as Ce, Slider as we, TabsRow as Te, ToggleSwitch as Ee, Tooltip as De, TreeRow as Oe, svgToPngBlob as ke, useModal as Ae } from "@kolkrabbi/kol-component";
13
+ import { useEffect as O, useMemo as je, useRef as k, useState as A, useSyncExternalStore as Me } from "react";
14
+ import { Fragment as Ne, jsx as j, jsxs as M } from "react/jsx-runtime";
15
+ import N from "@kolkrabbi/kol-component/utilities/kolboxGlyph";
16
+ //#region src/editor/kolbox/ui/ask.js
17
+ var P = null, Pe = (e) => new Promise((t) => P ? P("confirm", e, t) : t(!1)), Fe = (e) => new Promise((t) => P ? P("prompt", e, t) : t(null));
18
+ function Ie() {
19
+ let e = Ae(), t = k(null);
20
+ return O(() => {
21
+ let n = (n, r, i) => {
22
+ let a = n === "prompt" ? null : !1;
23
+ t.current?.resolve(t.current.empty);
24
+ let o = {
25
+ resolve: i,
26
+ empty: a
27
+ };
28
+ t.current = o, (n === "prompt" ? e.prompt(r.title, r.value ?? "", {
29
+ okLabel: r.action,
30
+ cancelLabel: r.cancel,
31
+ placeholder: r.placeholder
32
+ }) : r.cancel === null ? e.alert(r.title, {
33
+ okLabel: r.action,
34
+ body: r.message
35
+ }).then(() => !0) : e.confirm(r.title, {
36
+ okLabel: r.action,
37
+ cancelLabel: r.cancel,
38
+ body: r.message
39
+ })).then((e) => {
40
+ t.current === o && (t.current = null, i(e));
41
+ });
42
+ };
43
+ return P = n, () => {
44
+ P === n && (P = null);
45
+ };
46
+ }, [e]), null;
47
+ }
48
+ //#endregion
49
+ //#region src/editor/compose/ContentScope.jsx
50
+ var Le = (e, t, n) => e.map((e) => e.id === t ? n : Array.isArray(e.children) ? {
51
+ ...e,
52
+ children: Le(e.children, t, n)
53
+ } : e);
54
+ function Re({ hostId: e, rowKey: t, children: n }) {
55
+ let r = l(), i = g(r.layers, e), a = m(i).find((e) => e.key === t), o = je(() => i && a ? ee(i, a) : null, [i, a]), s = je(() => o ? {
56
+ ...r,
57
+ layers: Le(r.layers, e, o),
58
+ updateLayer: (n, i) => n === e ? r.updateContent(e, t, i) : r.updateLayer(n, i)
59
+ } : r, [
60
+ r,
61
+ o,
62
+ e,
63
+ t
64
+ ]);
65
+ return o ? /* @__PURE__ */ j(p.Provider, {
66
+ value: s,
67
+ children: n
68
+ }) : null;
69
+ }
70
+ //#endregion
71
+ //#region src/editor/kolbox/editor/engine.js
72
+ var ze = { "settings-drawer": "Mod+," }, Be = (e) => e && ze[e.id] ? {
73
+ ...e,
74
+ combo: ze[e.id]
75
+ } : e, Ve = (e) => Be(pe(e)), He = (e) => se(e).map(({ section: e, items: t }) => ({
76
+ section: e,
77
+ items: t.map(Be)
78
+ })), Ue = ze["settings-drawer"], F = [
79
+ {
80
+ value: "all",
81
+ label: "Overview"
82
+ },
83
+ {
84
+ value: "actions",
85
+ label: "Actions"
86
+ },
87
+ {
88
+ value: "tools",
89
+ label: "Tools"
90
+ },
91
+ {
92
+ value: "pages",
93
+ label: "Pages"
94
+ }
95
+ ], We = [
96
+ "tool:text",
97
+ "tool:rect",
98
+ "tool:pen",
99
+ "action:View›Cards›Layers"
100
+ ], I = [], Ge = (e) => {
101
+ I = [e, ...I.filter((t) => t !== e)].slice(0, 8);
102
+ };
103
+ function Ke(e) {
104
+ let t = [], n = (e, r) => (e ?? []).forEach((e) => (Array.isArray(e) ? e : e.rows ?? []).forEach((e) => {
105
+ if (!(!e || e.disabled)) {
106
+ if (e.submenu?.length) return n(e.submenu, [...r, e.label]);
107
+ typeof e.run != "function" || !e.label || t.push({
108
+ id: `action:${[...r, e.label].join("›")}`,
109
+ label: e.label,
110
+ icon: e.icon ?? "command",
111
+ hint: e.shortcut ?? r.join(" › "),
112
+ kbd: !!e.shortcut,
113
+ tab: "actions",
114
+ menu: r[0],
115
+ run: e.run
116
+ });
117
+ }
118
+ }));
119
+ e.forEach((e) => n(e.groups, [e.label]));
120
+ let r = /* @__PURE__ */ new Set();
121
+ return t.filter((e) => r.has(e.id) ? !1 : r.add(e.id));
122
+ }
123
+ var qe = {
124
+ Plus: ["+", "Equal"],
125
+ Space: [" ", "Space"]
126
+ }, Je = {
127
+ ",": "Comma",
128
+ ".": "Period",
129
+ "/": "Slash",
130
+ "\\": "Backslash",
131
+ ";": "Semicolon",
132
+ "'": "Quote",
133
+ "[": "BracketLeft",
134
+ "]": "BracketRight",
135
+ "-": "Minus",
136
+ "=": "Equal",
137
+ "`": "Backquote"
138
+ }, Ye = (e) => !!e && !e.includes("–");
139
+ function Xe(e) {
140
+ if (!Ye(e)) return;
141
+ if (e === "00") {
142
+ Xe("0"), Xe("0");
143
+ return;
144
+ }
145
+ let t = e.split("+"), n = t.pop() || "+", r = t.includes("Mod"), i = t.includes("Shift") || n === "?", a = t.includes("Alt"), o = /Mac|iPhone|iPad/.test(navigator.platform), [s, c] = qe[n] ?? [n, n];
146
+ n.length === 1 && (s = /[a-z]/i.test(n) ? i ? n.toUpperCase() : n.toLowerCase() : n, c = /[a-z]/i.test(n) ? `Key${n.toUpperCase()}` : /[0-9]/.test(n) ? `Digit${n}` : Je[n] ?? "");
147
+ let l = {
148
+ key: s,
149
+ code: c,
150
+ shiftKey: i,
151
+ altKey: a,
152
+ metaKey: r && o,
153
+ ctrlKey: r && !o,
154
+ bubbles: !0,
155
+ cancelable: !0
156
+ };
157
+ document.body.dispatchEvent(new KeyboardEvent("keydown", l)), document.body.dispatchEvent(new KeyboardEvent("keyup", l));
158
+ }
159
+ function Ze({ menus: e = [], tools: t = [], layers: n = [], pages: r = [], files: i = [], shortcuts: a = [] }) {
160
+ return [
161
+ ...i.map((e) => ({
162
+ id: `file:${e.id}`,
163
+ label: e.name,
164
+ icon: "file",
165
+ hint: e.hint,
166
+ tab: "files",
167
+ run: e.run
168
+ })),
169
+ ...n.map((e) => ({
170
+ id: `layer:${e.id}`,
171
+ label: e.name,
172
+ icon: "layers",
173
+ hint: e.kind,
174
+ tab: "layers",
175
+ run: e.run
176
+ })),
177
+ ...r.map((e) => ({
178
+ ...e,
179
+ id: `page:${e.id}`,
180
+ tab: "pages"
181
+ })),
182
+ ...a.flatMap((e) => e.items.map((t, n) => ({
183
+ id: `key:${e.section}:${t.id ?? n}:${t.combo}`,
184
+ label: t.label,
185
+ hint: t.keys,
186
+ kbd: !0,
187
+ tab: "shortcuts",
188
+ section: e.section,
189
+ run: Ye(t.combo) ? () => setTimeout(() => Xe(t.combo)) : void 0
190
+ }))),
191
+ ...Ke(e),
192
+ ...t.map((e) => ({
193
+ id: `tool:${e.id ?? e.label}`,
194
+ label: e.label,
195
+ icon: e.icon,
196
+ hint: e.kbd,
197
+ kbd: !!e.kbd,
198
+ tab: "tools",
199
+ run: e.run,
200
+ disabled: e.disabled,
201
+ disabledHint: e.disabledHint
202
+ }))
203
+ ];
204
+ }
205
+ function Qe(e) {
206
+ let t = [];
207
+ return e.filter((e) => e.tab === "shortcuts").forEach((e) => {
208
+ let n = t[t.length - 1];
209
+ n?.label !== e.section && (n = {
210
+ id: `cat:${e.section}`,
211
+ label: e.section,
212
+ group: "Shortcuts",
213
+ tab: "shortcuts",
214
+ open: !0,
215
+ items: []
216
+ }, t.push(n)), n.items.push(e);
217
+ }), t;
218
+ }
219
+ function $e(e) {
220
+ let t = new Map(e.map((e) => [e.id, e])), n = [...I, ...We.filter((e) => !I.includes(e))].slice(0, 4);
221
+ return [
222
+ ...e.filter((e) => e.tab === "files").map((e) => ({
223
+ ...e,
224
+ group: "Files"
225
+ })),
226
+ ...e.filter((e) => e.tab === "pages").map((e) => ({
227
+ ...e,
228
+ group: "Pages"
229
+ })),
230
+ ...Qe(e),
231
+ ...n.map((e) => t.get(e)).filter(Boolean).map((e) => ({
232
+ ...e,
233
+ id: `recent:${e.id}`,
234
+ group: "Recent",
235
+ key: e.id
236
+ })),
237
+ ...e.filter((e) => e.tab === "actions" || e.tab === "tools").map((e) => ({
238
+ ...e,
239
+ group: e.tab === "tools" ? "Tools" : e.menu,
240
+ tabOnly: !0
241
+ }))
242
+ ];
243
+ }
244
+ var et = {
245
+ files: "Files",
246
+ layers: "Layers",
247
+ pages: "Pages",
248
+ shortcuts: "Shortcuts",
249
+ tools: "Tools",
250
+ actions: "Actions"
251
+ };
252
+ function tt(e, t) {
253
+ let n = t.trim().toLowerCase();
254
+ if (!n) return [];
255
+ let r = (e) => e.label.toLowerCase().includes(n), i = [
256
+ "files",
257
+ "layers",
258
+ "pages",
259
+ "shortcuts"
260
+ ].flatMap((t) => e.filter((e) => e.tab === t && r(e))), a = e.filter((e) => e.tab === "tools" || e.tab === "actions").map((e) => ({
261
+ r: e,
262
+ at: e.label.toLowerCase().indexOf(n),
263
+ hinted: String(e.hint ?? "").toLowerCase().includes(n)
264
+ })).filter((e) => e.at >= 0 || e.hinted).sort((e, t) => (t.at === 0) - (e.at === 0)).slice(0, 40).map(({ r: e }) => e);
265
+ return [...i, ...a].map((e) => ({
266
+ ...e,
267
+ group: et[e.tab]
268
+ }));
269
+ }
270
+ function nt(e, t) {
271
+ let n = (e) => t === F[0].value ? !e.tabOnly : e.tab === t, r = [], i = /* @__PURE__ */ new Map();
272
+ return e.filter(n).forEach((e) => {
273
+ let t = e.group ?? "";
274
+ i.has(t) || (i.set(t, {
275
+ title: t,
276
+ rows: []
277
+ }), r.push(i.get(t))), i.get(t).rows.push(e);
278
+ }), r;
279
+ }
280
+ //#endregion
281
+ //#region src/editor/kolbox/editor/windows/WindowShortcuts.jsx
282
+ var rt = (e) => He(e).map(({ section: e, items: t }) => ({
283
+ section: e,
284
+ items: t.map((e) => ({
285
+ id: e.id,
286
+ label: e.label,
287
+ combo: e.combo,
288
+ keys: ce(e.combo)
289
+ }))
290
+ }));
291
+ function it({ view: e = "editor" }) {
292
+ return /* @__PURE__ */ j("div", {
293
+ "data-window": "shortcuts",
294
+ children: rt(e).map(({ section: e, items: t }) => /* @__PURE__ */ j(D, {
295
+ variant: "kolbox",
296
+ label: e,
297
+ children: t.map((e, t) => /* @__PURE__ */ j(xe, {
298
+ variant: "kolbox",
299
+ horizontal: !0,
300
+ label: e.label,
301
+ labelWidth: 160,
302
+ children: /* @__PURE__ */ j("span", {
303
+ className: "flex flex-1 justify-end",
304
+ "data-combo": !0,
305
+ children: /* @__PURE__ */ j(be, {
306
+ variant: "kolbox",
307
+ keys: e.keys,
308
+ size: "md"
309
+ })
310
+ })
311
+ }, `${e.id}-${t}`))
312
+ }, e))
313
+ });
314
+ }
315
+ function at({ onClose: e, view: t = "editor" }) {
316
+ let [n, r] = A(0);
317
+ return /* @__PURE__ */ j(_e, {
318
+ variant: "kolbox",
319
+ open: !0,
320
+ mode: "shortcuts",
321
+ onClose: e,
322
+ groups: [{
323
+ title: "Shortcuts",
324
+ rows: Qe(Ze({ shortcuts: rt(t) }))
325
+ }],
326
+ active: n,
327
+ onActive: r
328
+ });
329
+ }
330
+ //#endregion
331
+ //#region src/editor/kolbox/editor/windows/WindowSettings.jsx
332
+ var ot = s.map((e) => ({
333
+ value: e.id,
334
+ label: e.label
335
+ })).filter((e) => e.value !== "custom"), st = [{
336
+ value: "full",
337
+ label: "Full"
338
+ }, {
339
+ value: "half",
340
+ label: "Half"
341
+ }], ct = [
342
+ 2,
343
+ 4,
344
+ 8,
345
+ 12,
346
+ 16
347
+ ].map((e) => ({
348
+ value: e,
349
+ label: `${e} s`
350
+ })), lt = [
351
+ "kolcore",
352
+ "kolbox",
353
+ "minimal",
354
+ "folio"
355
+ ], ut = (e) => {
356
+ document.documentElement.dataset.themeVariant = e;
357
+ try {
358
+ localStorage.setItem("kolbox-theme-variant", e);
359
+ } catch {}
360
+ };
361
+ function dt() {
362
+ let [e, t] = A(() => lt.includes(document.documentElement.dataset.themeVariant) ? document.documentElement.dataset.themeVariant : "kolbox");
363
+ return /* @__PURE__ */ j(R, {
364
+ label: "Theme",
365
+ options: lt,
366
+ value: e,
367
+ onChange: (e) => {
368
+ ut(e), t(e);
369
+ }
370
+ });
371
+ }
372
+ var ft = [
373
+ "dark",
374
+ "light",
375
+ "system"
376
+ ], pt = (e) => {
377
+ let t = document.documentElement;
378
+ e === "system" ? delete t.dataset.theme : t.dataset.theme = e;
379
+ try {
380
+ localStorage.setItem("kol-theme", e);
381
+ } catch {}
382
+ };
383
+ function mt() {
384
+ let t = e();
385
+ return oe() === "kolbox" ? [["Style", /* @__PURE__ */ j(R, {
386
+ label: "Style",
387
+ options: de,
388
+ value: t.style ?? "default",
389
+ onChange: (e) => n("style", e)
390
+ })]] : [];
391
+ }
392
+ function ht() {
393
+ let [e, t] = A(() => document.documentElement.dataset.theme || "system");
394
+ return /* @__PURE__ */ j(R, {
395
+ label: "Mode",
396
+ options: ft,
397
+ value: e,
398
+ onChange: (e) => {
399
+ pt(e), t(e);
400
+ }
401
+ });
402
+ }
403
+ var gt = {
404
+ defaultAspect: "4:5",
405
+ defaultTheme: "kol",
406
+ autoplay: !1,
407
+ clipToFrame: !0,
408
+ defaultLoopSeconds: 4
409
+ }, _t = {
410
+ defaultAspect: "4:5",
411
+ defaultTheme: "kol",
412
+ autoplay: !1,
413
+ clipToFrame: !0,
414
+ labsModDots: !1,
415
+ defaultLoopSeconds: 4
416
+ }, vt = (e) => () => {
417
+ for (let [t, r] of Object.entries(e)) n(t, r);
418
+ t.setLoopSeconds(e.defaultLoopSeconds);
419
+ }, yt = {
420
+ name: "FXR",
421
+ about: "A DOM/SVG design compositor — frames, layers, vector tools — with generative, kinetic-type and effects layers on the same engine, served through three chromes: the Editor, Labs, and the Randomiser. Ships as a standalone app and as the embeddable @kolkrabbi/design-editor library.",
422
+ links: [
423
+ {
424
+ label: "GitHub",
425
+ url: "https://github.com/Tor-Grimsson/kol-fxr"
426
+ },
427
+ {
428
+ label: "Kolkrabbi",
429
+ url: "https://fxr.kolkrabbi.io"
430
+ },
431
+ {
432
+ label: "Vercel",
433
+ url: "https://vercel.com/tor-grimssons-projects/kol-fxr"
434
+ }
435
+ ]
436
+ }, bt = [
437
+ {
438
+ value: "settings",
439
+ label: "Settings"
440
+ },
441
+ {
442
+ value: "shortcuts",
443
+ label: "Shortcuts"
444
+ },
445
+ {
446
+ value: "about",
447
+ label: "About"
448
+ }
449
+ ], L = ({ label: e, on: t, onChange: n, disabled: r }) => /* @__PURE__ */ j("span", {
450
+ className: "flex flex-1 justify-end",
451
+ children: /* @__PURE__ */ j(Ee, {
452
+ variant: "kolbox",
453
+ "aria-label": e,
454
+ checked: !!t,
455
+ onChange: n,
456
+ disabled: r
457
+ })
458
+ }), R = ({ label: e, options: t, value: n, onChange: r }) => /* @__PURE__ */ j(ve, {
459
+ variant: "kolbox",
460
+ ariaLabel: e,
461
+ options: t,
462
+ value: n,
463
+ onChange: (e) => r(t.find((t) => String(t.value) === e)?.value ?? e),
464
+ className: "flex-1"
465
+ }), xt = ({ sections: e }) => e.map(([e, t], n) => /* @__PURE__ */ j(D, {
466
+ variant: "kolbox",
467
+ label: e,
468
+ children: t.map(([e, t]) => /* @__PURE__ */ j(xe, {
469
+ variant: "kolbox",
470
+ horizontal: !0,
471
+ label: e,
472
+ labelWidth: 160,
473
+ children: t
474
+ }, e))
475
+ }, `${e}-${n}`));
476
+ function St() {
477
+ let r = e(), i = b(), { showGrid: a, toggleGrid: o } = l(), s = d("generators"), c = mt();
478
+ return /* @__PURE__ */ j(xt, { sections: [
479
+ ["Display", [
480
+ ["Theme", /* @__PURE__ */ j(dt, {})],
481
+ ["Mode", /* @__PURE__ */ j(ht, {})],
482
+ ...c,
483
+ ["Preview resolution", /* @__PURE__ */ j(R, {
484
+ label: "Preview resolution",
485
+ options: st,
486
+ value: r.previewRes,
487
+ onChange: (e) => n("previewRes", e)
488
+ })]
489
+ ]],
490
+ ["Defaults", [
491
+ ["Default aspect", /* @__PURE__ */ j(R, {
492
+ label: "Default aspect",
493
+ options: ot,
494
+ value: r.defaultAspect,
495
+ onChange: (e) => n("defaultAspect", e)
496
+ })],
497
+ ...s ? [["Loop theme", /* @__PURE__ */ j(R, {
498
+ label: "Loop theme",
499
+ options: s.THEME_OPTIONS,
500
+ value: r.defaultTheme,
501
+ onChange: (e) => n("defaultTheme", e)
502
+ })]] : [],
503
+ ["Clip to frame", /* @__PURE__ */ j(L, {
504
+ label: "Clip to frame",
505
+ on: r.clipToFrame,
506
+ onChange: (e) => n("clipToFrame", e)
507
+ })],
508
+ ["Modulation dots", /* @__PURE__ */ j(L, {
509
+ label: "Modulation dots",
510
+ on: i,
511
+ onChange: (e) => {
512
+ e !== i && y();
513
+ }
514
+ })]
515
+ ]],
516
+ ["Canvas", [
517
+ ["Grab (C)", /* @__PURE__ */ j(L, {
518
+ label: "Grab (C)",
519
+ on: r.grab,
520
+ onChange: (e) => n("grab", e)
521
+ })],
522
+ ["Interactions", /* @__PURE__ */ j(L, {
523
+ label: "Interactions",
524
+ on: r.interactions !== !1,
525
+ onChange: (e) => n("interactions", e)
526
+ })],
527
+ ["Zoom lock (Z)", /* @__PURE__ */ j(L, {
528
+ label: "Zoom lock (Z)",
529
+ on: r.zoomLock,
530
+ onChange: (e) => n("zoomLock", e)
531
+ })]
532
+ ]],
533
+ ["Transport", [["Autoplay", /* @__PURE__ */ j(L, {
534
+ label: "Autoplay",
535
+ on: r.autoplay,
536
+ onChange: (e) => n("autoplay", e)
537
+ })], ["Loop length", /* @__PURE__ */ j(R, {
538
+ label: "Loop length",
539
+ options: ct,
540
+ value: r.defaultLoopSeconds,
541
+ onChange: (e) => {
542
+ n("defaultLoopSeconds", e), t.setLoopSeconds(e);
543
+ }
544
+ })]]],
545
+ ["Canvas", [["Show grid", /* @__PURE__ */ j(L, {
546
+ label: "Show grid",
547
+ on: a,
548
+ onChange: o
549
+ })]]]
550
+ ] });
551
+ }
552
+ function Ct() {
553
+ let r = e(), i = d("generators"), a = mt();
554
+ return /* @__PURE__ */ j(xt, { sections: [
555
+ ["Display", [
556
+ ["Theme", /* @__PURE__ */ j(dt, {})],
557
+ ["Mode", /* @__PURE__ */ j(ht, {})],
558
+ ...a
559
+ ]],
560
+ ["Defaults", [
561
+ ["Default aspect", /* @__PURE__ */ j(R, {
562
+ label: "Default aspect",
563
+ options: ot,
564
+ value: r.defaultAspect,
565
+ onChange: (e) => n("defaultAspect", e)
566
+ })],
567
+ ...i ? [["Loop theme", /* @__PURE__ */ j(R, {
568
+ label: "Loop theme",
569
+ options: i.THEME_OPTIONS,
570
+ value: r.defaultTheme,
571
+ onChange: (e) => n("defaultTheme", e)
572
+ })]] : [],
573
+ ["Clip to frame", /* @__PURE__ */ j(L, {
574
+ label: "Clip to frame",
575
+ on: r.clipToFrame,
576
+ onChange: (e) => n("clipToFrame", e)
577
+ })],
578
+ ["Modulation dots", /* @__PURE__ */ j(L, {
579
+ label: "Modulation dots",
580
+ on: r.labsModDots,
581
+ onChange: (e) => n("labsModDots", e)
582
+ })]
583
+ ]],
584
+ ["Transport", [["Autoplay", /* @__PURE__ */ j(L, {
585
+ label: "Autoplay",
586
+ on: r.autoplay,
587
+ onChange: (e) => n("autoplay", e)
588
+ })], ["Loop length", /* @__PURE__ */ j(R, {
589
+ label: "Loop length",
590
+ options: ct,
591
+ value: r.defaultLoopSeconds,
592
+ onChange: (e) => {
593
+ n("defaultLoopSeconds", e), t.setLoopSeconds(e);
594
+ }
595
+ })]]]
596
+ ] });
597
+ }
598
+ function wt() {
599
+ return /* @__PURE__ */ M("div", {
600
+ "data-window": "about",
601
+ children: [
602
+ /* @__PURE__ */ j(D, {
603
+ variant: "kolbox",
604
+ label: yt.name,
605
+ children: /* @__PURE__ */ j("p", {
606
+ className: "font-mono text-value text-muted",
607
+ children: yt.about
608
+ })
609
+ }),
610
+ /* @__PURE__ */ j(D, {
611
+ variant: "kolbox",
612
+ label: "Links",
613
+ children: yt.links.map((e) => /* @__PURE__ */ j(xe, {
614
+ variant: "kolbox",
615
+ horizontal: !0,
616
+ label: e.label,
617
+ children: /* @__PURE__ */ j("a", {
618
+ href: e.url,
619
+ target: "_blank",
620
+ rel: "noopener noreferrer",
621
+ className: "min-w-0 font-mono text-value break-all text-text hover:underline",
622
+ children: e.url
623
+ })
624
+ }, e.label))
625
+ }),
626
+ /* @__PURE__ */ j(D, {
627
+ variant: "kolbox",
628
+ children: /* @__PURE__ */ M("span", {
629
+ className: "flex flex-col font-mono text-value text-muted",
630
+ children: [/* @__PURE__ */ j("span", { children: "Kolkrabbi Vinnustofa" }), /* @__PURE__ */ j("span", { children: (/* @__PURE__ */ new Date()).getFullYear() })]
631
+ })
632
+ })
633
+ ]
634
+ });
635
+ }
636
+ function Tt({ onClose: e, view: t = "editor", tab: n = "settings", hubRows: r = !1 }) {
637
+ let [i, a] = A(n), o = t === "editor" && !r;
638
+ return /* @__PURE__ */ M(Ce, {
639
+ variant: "kolbox",
640
+ open: !0,
641
+ onClose: e,
642
+ title: o ? "Display settings" : "Settings",
643
+ className: "h-modal-generator-height",
644
+ footer: /* @__PURE__ */ j(De, {
645
+ variant: "kolbox",
646
+ label: "Reset to defaults",
647
+ children: /* @__PURE__ */ j(E, {
648
+ variant: "kolbox",
649
+ iconOnly: "refresh",
650
+ "aria-label": "Reset to defaults",
651
+ onClick: vt(o ? gt : _t)
652
+ })
653
+ }),
654
+ children: [/* @__PURE__ */ j("div", {
655
+ className: "shrink-0 px-4 pb-2",
656
+ children: /* @__PURE__ */ j(Te, {
657
+ variant: "kolbox",
658
+ tabs: bt,
659
+ value: i,
660
+ onChange: a,
661
+ className: "w-full"
662
+ })
663
+ }), /* @__PURE__ */ j("div", {
664
+ "data-window": "settings",
665
+ "data-tab": i,
666
+ children: i === "settings" ? j(o ? St : Ct, {}) : i === "shortcuts" ? /* @__PURE__ */ j(it, { view: t }) : /* @__PURE__ */ j(wt, {})
667
+ })]
668
+ });
669
+ }
670
+ //#endregion
671
+ //#region src/editor/kolbox/app/sampleMedia.js
672
+ var Et = "Sample library: the app hosting the editor has connected no media.", z = (e) => `data:image/svg+xml;utf8,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="800" height="1000" viewBox="0 0 800 1000">${e}</svg>`)}`, Dt = [
673
+ ["sample/circle.svg", z("<rect width=\"800\" height=\"1000\" fill=\"#1b1b1b\"/><circle cx=\"400\" cy=\"500\" r=\"260\" fill=\"#f2c230\"/>")],
674
+ ["sample/stripes.svg", z("<rect width=\"800\" height=\"1000\" fill=\"#ece8df\"/>" + Array.from({ length: 10 }, (e, t) => `<rect y="${t * 100}" width="800" height="50" fill="#9c4a1e"/>`).join(""))],
675
+ ["sample/grid.svg", z("<rect width=\"800\" height=\"1000\" fill=\"#22303c\"/>" + Array.from({ length: 20 }, (e, t) => `<circle cx="${100 + t % 4 * 200}" cy="${100 + Math.floor(t / 4) * 200}" r="60" fill="#8fb3d9"/>`).join(""))],
676
+ ["sample/blocks.svg", z("<rect width=\"800\" height=\"1000\" fill=\"#f4f1ea\"/><rect x=\"80\" y=\"120\" width=\"380\" height=\"380\" fill=\"#1f3a5f\"/><rect x=\"340\" y=\"420\" width=\"380\" height=\"460\" fill=\"#d94f30\"/>")]
677
+ ], Ot = new Map(Dt), kt = {
678
+ sample: !0,
679
+ buckets: () => [{
680
+ id: "sample",
681
+ label: "Sample library"
682
+ }],
683
+ listMedia: async (e = "") => Dt.filter(([t]) => t.startsWith(e)).map(([e, t]) => ({
684
+ key: e,
685
+ size: t.length,
686
+ contentType: "image/svg+xml",
687
+ lastModified: "2026-11-20T00:00:00Z"
688
+ })),
689
+ mediaUrl: (e) => Ot.get(e) ?? "",
690
+ proxied: (e) => e
691
+ }, B = (e) => (e?.contentType ?? "").split("/")[0], V = (e) => e.replace(/\/$/, "").split("/").pop(), At = [
692
+ [
693
+ "columns",
694
+ "columns",
695
+ "Columns"
696
+ ],
697
+ [
698
+ "rows",
699
+ "row",
700
+ "Rows"
701
+ ],
702
+ [
703
+ "grid",
704
+ "grid",
705
+ "Grid"
706
+ ]
707
+ ], jt = ({ label: e, children: t }) => /* @__PURE__ */ j(De, {
708
+ variant: "kolbox",
709
+ label: e,
710
+ children: t
711
+ });
712
+ function Mt(e, t) {
713
+ let n = /* @__PURE__ */ new Set(), r = [];
714
+ for (let i of e) {
715
+ if (!i.key.startsWith(t)) continue;
716
+ let e = i.key.slice(t.length), a = e.indexOf("/");
717
+ a >= 0 ? n.add(t + e.slice(0, a + 1)) : r.push(i);
718
+ }
719
+ return {
720
+ folders: [...n].sort(),
721
+ files: r.sort((e, t) => e.key.localeCompare(t.key))
722
+ };
723
+ }
724
+ function Nt({ open: e, accept: t = ["image", "video"], onClose: n, onSelect: r }) {
725
+ let i = ie(), a = je(() => i.buckets?.() ?? [], [i]), [o, s] = A(a[0]?.id), [c, l] = A([]), [u, d] = A(""), [f, p] = A(null), [m, ee] = A("columns"), [h, g] = A(!1), [_, v] = A(""), [y, b] = A(96);
726
+ O(() => {
727
+ if (!e) return;
728
+ let t = !0;
729
+ return d(""), p(null), v(""), Promise.resolve(i.listMedia("", { bucket: o })).then((e) => t && l(e ?? [])), () => {
730
+ t = !1;
731
+ };
732
+ }, [
733
+ e,
734
+ o,
735
+ i
736
+ ]);
737
+ let te = !!f && (typeof t == "function" ? t(f) : t.includes(B(f))), x = (e = f) => {
738
+ e && (r?.(i.mediaUrl(e.fullKey ?? e.key, o), {
739
+ contentType: e.contentType,
740
+ kind: B(e)
741
+ }), n?.());
742
+ }, ne = k(null);
743
+ ne.current = te ? () => x() : null, O(() => {
744
+ if (!e) return;
745
+ let t = (e) => {
746
+ e.key !== "Enter" || e.metaKey || e.ctrlKey || e.altKey || e.target?.closest?.("input, textarea, button, [contenteditable=\"true\"]") || !ne.current || (e.preventDefault(), e.stopPropagation(), ne.current());
747
+ };
748
+ return window.addEventListener("keydown", t, !0), () => window.removeEventListener("keydown", t, !0);
749
+ }, [e]);
750
+ let re = a.find((e) => e.id === o)?.label ?? o, S = u ? u.replace(/\/$/, "").split("/") : [], C = _.trim().toLowerCase(), w = C ? {
751
+ folders: [],
752
+ files: c.filter((e) => e.key.toLowerCase().includes(C))
753
+ } : Mt(c, u), T = c.reduce((e, t) => e + (t.size ?? 0), 0), oe = (e, t) => B(e) === "image" ? /* @__PURE__ */ j("img", {
754
+ src: i.mediaUrl(e.key, o),
755
+ alt: "",
756
+ loading: "lazy",
757
+ className: `object-cover ${t}`
758
+ }) : /* @__PURE__ */ j("span", {
759
+ className: `flex items-center justify-center bg-field text-muted ${t}`,
760
+ children: /* @__PURE__ */ j(N, { name: B(e) === "video" ? "video" : "file" })
761
+ }), se = (e) => /* @__PURE__ */ j(Oe, {
762
+ variant: "kolbox",
763
+ icon: B(e) === "image" ? "image" : B(e) === "video" ? "video" : "file",
764
+ label: V(e.key),
765
+ active: f?.key === e.key,
766
+ onClick: () => p(e),
767
+ onDoubleClick: () => (typeof t == "function" ? t(e) : t.includes(B(e))) && x(e),
768
+ trailing: /* @__PURE__ */ j("span", {
769
+ className: "shrink-0 font-mono text-meta text-muted",
770
+ children: ae?.(e.size) ?? e.size
771
+ }),
772
+ "data-media-file": e.key
773
+ }, e.key), ce = (e, t) => /* @__PURE__ */ j(Oe, {
774
+ variant: "kolbox",
775
+ icon: "folder",
776
+ label: V(e),
777
+ active: t,
778
+ onClick: () => {
779
+ d(e), p(null);
780
+ },
781
+ trailing: /* @__PURE__ */ j(N, {
782
+ name: "chevron-right",
783
+ size: 12,
784
+ className: "text-muted"
785
+ }),
786
+ "data-media-folder": e
787
+ }, e), le = () => m === "grid" ? /* @__PURE__ */ M("div", {
788
+ className: "grid gap-2 p-2",
789
+ style: { gridTemplateColumns: `repeat(auto-fill, minmax(${y}px, 1fr))` },
790
+ children: [w.folders.map((e) => /* @__PURE__ */ M("button", {
791
+ type: "button",
792
+ onClick: () => {
793
+ d(e), p(null);
794
+ },
795
+ "data-media-folder": e,
796
+ className: "flex flex-col gap-1 rounded-control p-1 text-left outline-none hover:bg-field focus-visible:outline-solid focus-visible:outline-1 focus-visible:outline-accent",
797
+ children: [/* @__PURE__ */ j("span", {
798
+ className: "flex aspect-square w-full items-center justify-center rounded-control bg-field text-muted",
799
+ children: /* @__PURE__ */ j(N, { name: "folder" })
800
+ }), /* @__PURE__ */ j("span", {
801
+ className: "truncate text-label text-text",
802
+ children: V(e)
803
+ })]
804
+ }, e)), w.files.map((e) => /* @__PURE__ */ M("button", {
805
+ type: "button",
806
+ onClick: () => p(e),
807
+ onDoubleClick: () => (typeof t == "function" ? t(e) : t.includes(B(e))) && x(e),
808
+ "data-media-file": e.key,
809
+ className: `flex flex-col gap-1 rounded-control p-1 text-left outline-none focus-visible:outline-solid focus-visible:outline-1 focus-visible:outline-accent ${f?.key === e.key ? "bg-accent-tint" : "hover:bg-field"}`,
810
+ children: [oe(e, "aspect-square w-full rounded-control"), /* @__PURE__ */ j("span", {
811
+ className: `truncate text-label ${f?.key === e.key ? "text-accent" : "text-text"}`,
812
+ children: V(e.key)
813
+ })]
814
+ }, e.key))]
815
+ }) : m === "rows" ? /* @__PURE__ */ M("div", {
816
+ className: "flex flex-col gap-1 p-2",
817
+ children: [w.folders.map((e) => ce(e, !1)), w.files.map(se)]
818
+ }) : /* @__PURE__ */ M("div", {
819
+ className: "flex h-full",
820
+ children: [(C ? [{
821
+ p: "",
822
+ ...w
823
+ }] : ["", ...S.map((e, t) => `${S.slice(0, t + 1).join("/")}/`)].map((e) => ({
824
+ p: e,
825
+ ...Mt(c, e)
826
+ }))).map(({ p: e, folders: t, files: n }) => /* @__PURE__ */ M("div", {
827
+ className: "flex w-56 shrink-0 flex-col gap-1 overflow-y-auto p-2",
828
+ "data-media-column": e,
829
+ children: [t.map((e) => ce(e, u.startsWith(e))), n.map(se)]
830
+ }, e)), /* @__PURE__ */ M("div", {
831
+ className: "flex min-w-0 flex-1 flex-col items-center justify-center gap-2 p-4",
832
+ "data-media-preview": !0,
833
+ children: [f && oe(f, "max-h-64 w-full rounded-well object-contain"), f && /* @__PURE__ */ j("span", {
834
+ className: "font-mono text-meta text-muted",
835
+ children: ae?.(f.size) ?? f.size
836
+ })]
837
+ })]
838
+ });
839
+ return /* @__PURE__ */ j(Ce, {
840
+ variant: "kolbox",
841
+ open: e,
842
+ onClose: n,
843
+ title: "Media",
844
+ width: "var(--spacing-modal-wide)",
845
+ className: "h-modal-generator-height",
846
+ actions: /* @__PURE__ */ M(Ne, { children: [/* @__PURE__ */ j(ve, {
847
+ variant: "kolbox",
848
+ ariaLabel: "Bucket",
849
+ value: o,
850
+ options: a.map((e) => ({
851
+ value: e.id,
852
+ label: e.label ?? e.id
853
+ })),
854
+ onChange: s,
855
+ className: "w-44"
856
+ }), /* @__PURE__ */ j(jt, {
857
+ label: "Display settings are in the Library",
858
+ children: /* @__PURE__ */ j(E, {
859
+ variant: "kolbox",
860
+ iconOnly: "gear",
861
+ "aria-label": "Display settings",
862
+ disabled: !0
863
+ })
864
+ })] }),
865
+ footer: /* @__PURE__ */ M(Ne, { children: [
866
+ /* @__PURE__ */ j("span", {
867
+ className: "mr-auto min-w-0 truncate font-mono text-meta text-muted",
868
+ "data-media-picked": !0,
869
+ children: f ? f.key : "Select a file"
870
+ }),
871
+ /* @__PURE__ */ j(E, {
872
+ variant: "kolbox",
873
+ tone: "ghost",
874
+ onClick: n,
875
+ children: "Cancel"
876
+ }),
877
+ te ? /* @__PURE__ */ j(E, {
878
+ variant: "kolbox",
879
+ tone: "primary",
880
+ onClick: () => x(),
881
+ "data-media-use": !0,
882
+ children: "Use"
883
+ }) : /* @__PURE__ */ j(jt, {
884
+ label: f ? "This file is not a kind this place takes" : "Select a file first",
885
+ children: /* @__PURE__ */ j(E, {
886
+ variant: "kolbox",
887
+ tone: "primary",
888
+ disabled: !0,
889
+ "data-media-use": !0,
890
+ children: "Use"
891
+ })
892
+ })
893
+ ] }),
894
+ children: /* @__PURE__ */ M("div", {
895
+ className: "flex min-h-0 flex-1 flex-col gap-2 px-4 pb-4",
896
+ "data-window": "media-picker",
897
+ children: [
898
+ i.sample && /* @__PURE__ */ j("p", {
899
+ className: "shrink-0 text-help text-muted",
900
+ "data-media-sample": !0,
901
+ children: "Sample library: the app hosting the editor has connected no media."
902
+ }),
903
+ /* @__PURE__ */ M("div", {
904
+ className: "flex h-control shrink-0 items-center gap-2",
905
+ children: [
906
+ /* @__PURE__ */ j("nav", {
907
+ className: "flex min-w-0 flex-1 items-center gap-1 truncate text-label",
908
+ "data-media-crumbs": !0,
909
+ children: [
910
+ ["Media", null],
911
+ [re, ""],
912
+ ...S.map((e, t) => [e, `${S.slice(0, t + 1).join("/")}/`])
913
+ ].map(([e, t], n, r) => /* @__PURE__ */ M("span", {
914
+ className: "flex items-center gap-1",
915
+ children: [n > 0 && /* @__PURE__ */ j("span", {
916
+ className: "text-muted",
917
+ children: "/"
918
+ }), t === null ? /* @__PURE__ */ j("span", {
919
+ className: "truncate text-muted",
920
+ children: e
921
+ }) : /* @__PURE__ */ j("button", {
922
+ type: "button",
923
+ onClick: () => {
924
+ d(t), p(null);
925
+ },
926
+ className: `truncate outline-none focus-visible:outline-solid focus-visible:outline-1 focus-visible:outline-accent ${n === r.length - 1 ? "text-text" : "text-muted hover:text-text"}`,
927
+ children: e
928
+ })]
929
+ }, n))
930
+ }),
931
+ h && /* @__PURE__ */ j(ye, {
932
+ variant: "kolbox",
933
+ size: "md",
934
+ iconLeft: "search",
935
+ placeholder: "Search this bucket",
936
+ "aria-label": "Search this bucket",
937
+ value: _,
938
+ onChange: (e) => v(e.target.value),
939
+ autoFocus: !0,
940
+ className: "w-56"
941
+ }),
942
+ /* @__PURE__ */ j(jt, {
943
+ label: "Filters are in the Library; Search finds by name here",
944
+ children: /* @__PURE__ */ j(E, {
945
+ variant: "kolbox",
946
+ iconOnly: "filter",
947
+ "aria-label": "Filter",
948
+ disabled: !0
949
+ })
950
+ }),
951
+ /* @__PURE__ */ j(E, {
952
+ variant: "kolbox",
953
+ iconOnly: "search",
954
+ "aria-label": "Search",
955
+ pressed: h,
956
+ onClick: () => {
957
+ g((e) => !e), v("");
958
+ }
959
+ }),
960
+ /* @__PURE__ */ j(ge, {
961
+ layout: "joined",
962
+ variant: "kolbox",
963
+ options: At.map(([e, t, n]) => ({
964
+ icon: t,
965
+ ariaLabel: n,
966
+ pressed: m === e,
967
+ onPress: () => ee(e)
968
+ }))
969
+ })
970
+ ]
971
+ }),
972
+ /* @__PURE__ */ j("div", {
973
+ className: "min-h-0 flex-1 overflow-auto rounded-well bg-ground",
974
+ "data-media-listing": m,
975
+ children: le()
976
+ }),
977
+ /* @__PURE__ */ M("div", {
978
+ className: "flex h-control shrink-0 items-center gap-2",
979
+ children: [/* @__PURE__ */ j("span", {
980
+ className: "min-w-0 flex-1 truncate font-mono text-meta text-muted",
981
+ "data-media-count": !0,
982
+ children: `${w.folders.length} ${w.folders.length === 1 ? "folder" : "folders"}, ${w.files.length} ${w.files.length === 1 ? "file" : "files"}, ${ae?.(T) ?? T}`
983
+ }), /* @__PURE__ */ j(we, {
984
+ variant: "kolbox",
985
+ "aria-label": "Row size",
986
+ value: y,
987
+ min: 48,
988
+ max: 192,
989
+ step: 8,
990
+ onChange: b,
991
+ formatValue: (e) => `${e}`,
992
+ className: "w-40"
993
+ })]
994
+ })
995
+ ]
996
+ })
997
+ });
998
+ }
999
+ var H = null, Pt = (e = {}) => new Promise((t) => H ? H({
1000
+ ...e,
1001
+ resolve: t
1002
+ }) : t(null));
1003
+ function Ft() {
1004
+ let { addLayer: e, updateLayer: t, beginTransaction: n, commitTransaction: r, layers: i } = l(), [o, s] = A(null), c = k(null);
1005
+ O(() => {
1006
+ let e = (e) => {
1007
+ c.current?.resolve(null), c.current = e, s(e);
1008
+ };
1009
+ return H = e, () => {
1010
+ H === e && (H = null);
1011
+ };
1012
+ }, []);
1013
+ let u = (e) => {
1014
+ let t = c.current;
1015
+ c.current = null, s(null), t?.resolve(e);
1016
+ };
1017
+ return /* @__PURE__ */ j(Nt, {
1018
+ open: !!o,
1019
+ accept: o?.accept,
1020
+ onClose: () => c.current && u(null),
1021
+ onSelect: (o, { contentType: s, kind: l } = {}) => {
1022
+ let d = c.current, f = ue(o), p = l === "video" ? "video" : "image";
1023
+ if (d?.place === !1) {
1024
+ u({
1025
+ url: o,
1026
+ contentType: s,
1027
+ kind: l
1028
+ });
1029
+ return;
1030
+ }
1031
+ if (d?.layerId && d.fill) {
1032
+ let e = g(i, d.layerId)?.fill, a = e?.type === "image" || e?.type === "video" ? e : {
1033
+ type: "image",
1034
+ fit: "cover"
1035
+ };
1036
+ n(), t(d.layerId, { fill: {
1037
+ ...a,
1038
+ src: f,
1039
+ srcType: p,
1040
+ type: "image"
1041
+ } }), r();
1042
+ } else if (d?.layerId) n(), t(d.layerId, {
1043
+ src: f,
1044
+ srcType: p
1045
+ }), r();
1046
+ else {
1047
+ let t = new Image();
1048
+ t.onload = () => {
1049
+ if (!t.naturalWidth || !t.naturalHeight) return;
1050
+ let n = Math.min(1, 720 / t.naturalWidth, 720 / t.naturalHeight), r = Math.round(t.naturalWidth * n), i = Math.round(t.naturalHeight * n);
1051
+ e("photo", {
1052
+ src: f,
1053
+ srcType: p,
1054
+ x: Math.round((a - r) / 2),
1055
+ y: Math.round((_ - i) / 2),
1056
+ w: r,
1057
+ h: i,
1058
+ fit: "cover"
1059
+ });
1060
+ }, t.src = f;
1061
+ }
1062
+ u({
1063
+ url: o,
1064
+ contentType: s,
1065
+ kind: l
1066
+ });
1067
+ }
1068
+ });
1069
+ }
1070
+ //#endregion
1071
+ //#region src/editor/kolbox/app/WindowSignIn.jsx
1072
+ function It({ onClose: e }) {
1073
+ return /* @__PURE__ */ j(Ce, {
1074
+ variant: "kolbox",
1075
+ open: !0,
1076
+ movable: "sign-in",
1077
+ onClose: e,
1078
+ title: "Sign in",
1079
+ footer: /* @__PURE__ */ M(Ne, { children: [/* @__PURE__ */ j("span", { className: "flex-1" }), /* @__PURE__ */ j(E, {
1080
+ variant: "kolbox",
1081
+ tone: "primary",
1082
+ onClick: e,
1083
+ children: "OK"
1084
+ })] }),
1085
+ children: /* @__PURE__ */ M("div", {
1086
+ className: "flex flex-col gap-3 px-4 pb-4",
1087
+ "data-window": "sign-in",
1088
+ children: [/* @__PURE__ */ j("p", {
1089
+ className: "text-label text-text",
1090
+ children: "No account is connected."
1091
+ }), /* @__PURE__ */ j("p", {
1092
+ className: "text-help text-muted",
1093
+ children: "The app that hosts the editor connects one by passing its account: the session and its sign-in and sign-out. Until then your files, folders, media, palettes and themes are kept in this browser, on this device."
1094
+ })]
1095
+ })
1096
+ });
1097
+ }
1098
+ //#endregion
1099
+ //#region src/editor/kolbox/files/account.js
1100
+ var Lt = () => !!x(), Rt = () => x()?.session ?? null, zt = () => x()?.signIn?.(), Bt = () => x()?.signOut?.(), Vt = {
1101
+ "/editor": "editor",
1102
+ "/labs": "labs",
1103
+ "/morph": "labs"
1104
+ }, Ht = new Set(Object.keys(Vt)), Ut = (e) => Vt[e] ?? "home", Wt = (e, t) => () => window.dispatchEvent(new CustomEvent(e, { detail: t })), Gt = (e) => Wt("kolbox:settings", { tab: e })(), Kt = Wt("kolbox:media"), qt = Wt("kolbox:sign-in"), U = () => !!Rt();
1105
+ function Jt({ screen: e, onLeave: t }) {
1106
+ let [n, r] = A(null), [, i] = A(0), a = k(e);
1107
+ a.current = e;
1108
+ let o = k(t);
1109
+ o.current = t;
1110
+ let s = Ut(e);
1111
+ O(() => {
1112
+ let e = (e) => window.dispatchEvent(new CustomEvent(e, { cancelable: !0 })), t = (t) => {
1113
+ e("kol:open-settings") && r((e) => e?.id === "settings" ? null : {
1114
+ id: "settings",
1115
+ tab: t?.detail?.tab ?? "settings"
1116
+ });
1117
+ }, n = () => {
1118
+ e("kol:show-shortcuts") && r((e) => e?.id === "shortcuts" ? null : { id: "shortcuts" });
1119
+ }, o = () => r({ id: "media" }), s = async () => {
1120
+ if (!Rt()) {
1121
+ Lt() ? zt() : r({ id: "sign-in" });
1122
+ return;
1123
+ }
1124
+ await Pe({
1125
+ title: "Sign out? Your files stay on this device.",
1126
+ action: "Sign out"
1127
+ }) && Bt(), i((e) => e + 1), window.dispatchEvent(new CustomEvent("kolbox:account"));
1128
+ }, c = (e) => {
1129
+ if (fe(e, Ue)) {
1130
+ e.preventDefault(), e.repeat || t();
1131
+ return;
1132
+ }
1133
+ T(e) || e.metaKey || e.ctrlKey || e.altKey || e.repeat || e.key === "s" && !e.shiftKey && !Ht.has(a.current) && setTimeout(() => {
1134
+ e.defaultPrevented || n();
1135
+ });
1136
+ }, l = {
1137
+ "kolbox:settings": t,
1138
+ "kolbox:shortcuts": n,
1139
+ "kolbox:media": o,
1140
+ "kolbox:sign-in": s
1141
+ };
1142
+ return Object.entries(l).forEach(([e, t]) => window.addEventListener(e, t)), window.addEventListener("keydown", c), () => {
1143
+ Object.entries(l).forEach(([e, t]) => window.removeEventListener(e, t)), window.removeEventListener("keydown", c);
1144
+ };
1145
+ }, []);
1146
+ let c = () => window.location.hash === "#/settings";
1147
+ O(() => {
1148
+ let e = () => window.dispatchEvent(new CustomEvent("kol:open-settings", { cancelable: !0 })), t = () => {
1149
+ c() && e() && r({
1150
+ id: "settings",
1151
+ tab: "settings"
1152
+ });
1153
+ }, n = () => {
1154
+ c() && o.current?.();
1155
+ };
1156
+ return t(), window.addEventListener("hashchange", t), window.addEventListener("kolbox:settings-closed", n), () => {
1157
+ window.removeEventListener("hashchange", t), window.removeEventListener("kolbox:settings-closed", n);
1158
+ };
1159
+ }, []);
1160
+ let l = () => {
1161
+ r(null), c() && t?.();
1162
+ };
1163
+ return n?.id === "settings" ? /* @__PURE__ */ j(Tt, {
1164
+ onClose: l,
1165
+ view: s,
1166
+ tab: n.tab,
1167
+ hubRows: !0
1168
+ }) : n?.id === "shortcuts" ? /* @__PURE__ */ j(at, {
1169
+ onClose: l,
1170
+ view: s
1171
+ }) : n?.id === "sign-in" ? /* @__PURE__ */ j(It, { onClose: l }) : n?.id === "media" ? /* @__PURE__ */ j(Nt, {
1172
+ open: !0,
1173
+ onClose: l,
1174
+ onSelect: l
1175
+ }) : null;
1176
+ }
1177
+ //#endregion
1178
+ //#region src/editor/kolbox/ui/MenuMain.jsx
1179
+ var Yt = () => window.dispatchEvent(new CustomEvent("kolbox:search")), W = (e) => () => {
1180
+ window.location.hash = e;
1181
+ };
1182
+ function Xt({ mode: e, settings: t } = {}) {
1183
+ return [
1184
+ {
1185
+ label: "Home",
1186
+ run: W("#/home")
1187
+ },
1188
+ {
1189
+ label: "Chromes",
1190
+ submenu: [[
1191
+ {
1192
+ label: "Home",
1193
+ check: e === "home",
1194
+ run: W("#/home")
1195
+ },
1196
+ {
1197
+ label: "Library",
1198
+ check: e === "library",
1199
+ run: W("#/library")
1200
+ },
1201
+ {
1202
+ label: "Editor",
1203
+ check: e === "editor",
1204
+ run: W("#/editor")
1205
+ },
1206
+ {
1207
+ label: "Labs",
1208
+ check: e === "labs",
1209
+ run: W("#/labs")
1210
+ },
1211
+ {
1212
+ label: "Randomiser",
1213
+ check: e === "randomiser",
1214
+ run: W("#/randomiser")
1215
+ },
1216
+ {
1217
+ label: "Morph",
1218
+ check: e === "morph",
1219
+ run: W("#/morph")
1220
+ }
1221
+ ]]
1222
+ },
1223
+ {
1224
+ label: "Media",
1225
+ run: Kt
1226
+ },
1227
+ {
1228
+ label: U() ? "Signed in" : "Sign in",
1229
+ run: qt
1230
+ },
1231
+ {
1232
+ label: "Settings…",
1233
+ shortcut: "⌘,",
1234
+ run: () => Gt(),
1235
+ ...t
1236
+ }
1237
+ ];
1238
+ }
1239
+ var G = (e) => () => window.dispatchEvent(new CustomEvent("kolbox:labs", { detail: e })), Zt = [{
1240
+ label: "File",
1241
+ groups: [[{
1242
+ label: "Save",
1243
+ shortcut: "⌘S",
1244
+ run: G("save")
1245
+ }, {
1246
+ label: "Files…",
1247
+ shortcut: "⌘O",
1248
+ run: G("files")
1249
+ }], [{
1250
+ label: "Export PNG",
1251
+ run: G("export-png")
1252
+ }, {
1253
+ label: "Export loop (webm)",
1254
+ run: G("export-loop")
1255
+ }]]
1256
+ }, {
1257
+ label: "Window",
1258
+ groups: [[{
1259
+ label: "Output",
1260
+ run: G("output")
1261
+ }, {
1262
+ label: "File",
1263
+ run: G("file")
1264
+ }], [
1265
+ {
1266
+ label: "Shortcuts",
1267
+ shortcut: "S",
1268
+ run: G("shortcuts")
1269
+ },
1270
+ {
1271
+ label: "Settings",
1272
+ shortcut: "⌘,",
1273
+ run: G("settings")
1274
+ },
1275
+ {
1276
+ label: "Media",
1277
+ run: G("media")
1278
+ }
1279
+ ]]
1280
+ }];
1281
+ function Qt({ anchor: e, open: t, onClose: n, menus: r = [], app: i = [] }) {
1282
+ return /* @__PURE__ */ j(Se, {
1283
+ variant: "kolbox",
1284
+ "aria-label": "Main menu",
1285
+ minWidth: 196,
1286
+ anchor: e,
1287
+ open: t,
1288
+ onClose: n,
1289
+ onSelect: (e) => e.run?.(),
1290
+ groups: [
1291
+ i.filter((e) => e.label === "Home"),
1292
+ [{
1293
+ label: "Actions…",
1294
+ icon: "search",
1295
+ shortcut: "⌘K",
1296
+ run: Yt
1297
+ }],
1298
+ r.map((e) => ({
1299
+ label: e.label,
1300
+ submenu: e.groups
1301
+ })),
1302
+ i.filter((e) => e.label !== "Home")
1303
+ ].filter((e) => e.length)
1304
+ });
1305
+ }
1306
+ //#endregion
1307
+ //#region src/editor/kolbox/editor/windows/InsertImage.jsx
1308
+ var $t = () => window.dispatchEvent(new CustomEvent("kol:insert-image"));
1309
+ function en() {
1310
+ let { addLayer: e } = l(), t = k(null);
1311
+ return O(() => {
1312
+ let e = () => t.current?.click(), n = (t) => {
1313
+ T(t) || !fe(t, Ve("insert-image").combo) || (t.preventDefault(), t.stopPropagation(), e());
1314
+ };
1315
+ return window.addEventListener("kol:insert-image", e), window.addEventListener("keydown", n, !0), () => {
1316
+ window.removeEventListener("kol:insert-image", e), window.removeEventListener("keydown", n, !0);
1317
+ };
1318
+ }, []), /* @__PURE__ */ j("input", {
1319
+ ref: t,
1320
+ type: "file",
1321
+ accept: "image/*",
1322
+ className: "hidden",
1323
+ onChange: (t) => {
1324
+ let n = t.target.files?.[0];
1325
+ if (t.target.value = "", !n) return;
1326
+ let r = new FileReader();
1327
+ r.onload = () => {
1328
+ let t = new Image();
1329
+ t.onload = () => {
1330
+ if (!t.naturalWidth || !t.naturalHeight) return;
1331
+ let n = Math.min(1, 720 / t.naturalWidth, 720 / t.naturalHeight), i = Math.round(t.naturalWidth * n), o = Math.round(t.naturalHeight * n);
1332
+ e("photo", {
1333
+ src: r.result,
1334
+ x: Math.round((a - i) / 2),
1335
+ y: Math.round((_ - o) / 2),
1336
+ w: i,
1337
+ h: o,
1338
+ fit: "cover"
1339
+ });
1340
+ }, t.src = r.result;
1341
+ }, r.readAsDataURL(n);
1342
+ },
1343
+ "data-insert-image": !0
1344
+ });
1345
+ }
1346
+ //#endregion
1347
+ //#region src/editor/kolbox/editor/windows/eyedrop.jsx
1348
+ var tn = () => window.dispatchEvent(new CustomEvent("kol:eyedrop"));
1349
+ function nn() {
1350
+ let e = me(), { layers: t, palette: n, aspect: r, customRatio: i, canvasFill: a } = l(), o = k(null);
1351
+ return o.current = async () => {
1352
+ let o = typeof a == "string" && a.startsWith("var(") ? null : h(a, n) ?? null;
1353
+ try {
1354
+ let a = await re({
1355
+ layers: t,
1356
+ palette: n,
1357
+ aspect: r,
1358
+ customRatio: i,
1359
+ canvasFillHex: o
1360
+ });
1361
+ a && e.onChange(a);
1362
+ } catch {}
1363
+ }, O(() => {
1364
+ let e = () => o.current();
1365
+ return window.addEventListener("kol:eyedrop", e), () => window.removeEventListener("kol:eyedrop", e);
1366
+ }, []), null;
1367
+ }
1368
+ //#endregion
1369
+ //#region src/editor/kolbox/search/ModalSearchHost.jsx
1370
+ var rn = (e) => () => window.dispatchEvent(new CustomEvent("kol:command", { detail: { id: e } })), an = {
1371
+ editor: "editor",
1372
+ labs: "labs",
1373
+ morph: "labs"
1374
+ };
1375
+ function on() {
1376
+ let { setTool: e } = le(), t = l(), n = [
1377
+ {
1378
+ id: "select",
1379
+ icon: "pointer",
1380
+ label: "Select",
1381
+ kbd: "V"
1382
+ },
1383
+ {
1384
+ id: "zoom",
1385
+ icon: "search",
1386
+ label: "Zoom",
1387
+ kbd: "Z"
1388
+ },
1389
+ {
1390
+ id: "rect",
1391
+ icon: "square",
1392
+ label: "Rectangle",
1393
+ kbd: "R"
1394
+ },
1395
+ {
1396
+ id: "ellipse",
1397
+ icon: "circle",
1398
+ label: "Ellipse",
1399
+ kbd: "O"
1400
+ },
1401
+ {
1402
+ id: "text",
1403
+ icon: "aa",
1404
+ label: "Text",
1405
+ kbd: "T"
1406
+ },
1407
+ {
1408
+ id: "pen",
1409
+ icon: "pen",
1410
+ label: "Pen",
1411
+ kbd: "P"
1412
+ },
1413
+ {
1414
+ id: "image",
1415
+ icon: "image",
1416
+ label: "Insert image",
1417
+ run: $t
1418
+ },
1419
+ {
1420
+ id: "pattern",
1421
+ icon: "pattern-tool",
1422
+ label: "Pattern"
1423
+ },
1424
+ {
1425
+ id: "hand",
1426
+ icon: "hand",
1427
+ label: "Hand"
1428
+ },
1429
+ {
1430
+ id: "orbit",
1431
+ icon: "shape-torus",
1432
+ label: "Orbit",
1433
+ kbd: "C"
1434
+ },
1435
+ {
1436
+ label: "Node select",
1437
+ icon: "pointer-node",
1438
+ kbd: "A",
1439
+ run: () => window.dispatchEvent(new CustomEvent("kol:node-edit"))
1440
+ },
1441
+ {
1442
+ id: "triangle",
1443
+ icon: "triangle",
1444
+ label: "Triangle"
1445
+ },
1446
+ {
1447
+ id: "line",
1448
+ icon: "line",
1449
+ label: "Line"
1450
+ },
1451
+ {
1452
+ id: "polygon",
1453
+ icon: "polygon",
1454
+ label: "Polygon"
1455
+ },
1456
+ {
1457
+ id: "star",
1458
+ icon: "star",
1459
+ label: "Star"
1460
+ },
1461
+ ...d("motion") ? [{
1462
+ label: "Kinetic type",
1463
+ icon: "type-02",
1464
+ run: () => t.addLayer("kinetic")
1465
+ }] : [],
1466
+ {
1467
+ label: "Fill / stroke",
1468
+ icon: "swap",
1469
+ kbd: "X",
1470
+ run: rn("paint-toggle")
1471
+ },
1472
+ {
1473
+ label: "Reset colours",
1474
+ icon: "refresh",
1475
+ kbd: "D",
1476
+ run: rn("paint-default")
1477
+ },
1478
+ {
1479
+ label: "Eyedropper",
1480
+ icon: "eyedropper",
1481
+ kbd: "I",
1482
+ run: tn
1483
+ }
1484
+ ], r = [], i = (e) => (e ?? []).forEach((e) => {
1485
+ r.push({
1486
+ id: e.id,
1487
+ name: te(e),
1488
+ kind: e.type,
1489
+ run: () => t.select(e.id)
1490
+ }), i(e.children);
1491
+ });
1492
+ return i(t.layers), {
1493
+ tools: n.map((t) => ({
1494
+ ...t,
1495
+ run: t.run ?? (() => e(t.id))
1496
+ })),
1497
+ layers: r
1498
+ };
1499
+ }
1500
+ var K = (e) => () => {
1501
+ window.location.hash = e;
1502
+ }, sn = (e, t) => {
1503
+ let n = new URL(window.location.href);
1504
+ n.searchParams.set("open", e), n.hash = t === "morph" ? "#/morph" : "#/editor", window.history.pushState(null, "", n.pathname + n.search + n.hash), window.dispatchEvent(new HashChangeEvent("hashchange"));
1505
+ }, cn = (e) => e ? `Edited ${new Date(e).toLocaleDateString(void 0, {
1506
+ day: "numeric",
1507
+ month: "short"
1508
+ })}, ${new Date(e).toLocaleTimeString(void 0, {
1509
+ hour: "2-digit",
1510
+ minute: "2-digit"
1511
+ })}` : void 0, ln = () => (v().preset ?? []).filter((e) => !e.shipped).map((e) => ({
1512
+ id: e.id,
1513
+ name: e.name || "Untitled",
1514
+ hint: cn(e.updatedAt ?? e.savedAt),
1515
+ run: () => sn(e.id, e.mode ?? "editor")
1516
+ })), un = () => [
1517
+ {
1518
+ id: "/home",
1519
+ icon: "home-01",
1520
+ label: "Home",
1521
+ run: K("#/home")
1522
+ },
1523
+ {
1524
+ id: "/library",
1525
+ icon: "nav-library",
1526
+ label: "Library",
1527
+ run: K("#/library")
1528
+ },
1529
+ {
1530
+ id: "/editor",
1531
+ icon: "desktop",
1532
+ label: "Editor",
1533
+ run: K("#/editor")
1534
+ },
1535
+ {
1536
+ id: "/labs",
1537
+ icon: "globe",
1538
+ label: "Labs",
1539
+ run: K("#/labs")
1540
+ },
1541
+ {
1542
+ id: "/randomiser",
1543
+ icon: "refresh",
1544
+ label: "Randomiser",
1545
+ run: K("#/randomiser")
1546
+ },
1547
+ {
1548
+ id: "/morph",
1549
+ icon: "swap",
1550
+ label: "Morph",
1551
+ run: K("#/morph")
1552
+ },
1553
+ {
1554
+ id: "media",
1555
+ icon: "image",
1556
+ label: "Media",
1557
+ run: Kt
1558
+ },
1559
+ {
1560
+ id: "sign-in",
1561
+ icon: U() ? "cloud" : "user",
1562
+ label: U() ? "Signed in" : "Sign in",
1563
+ run: qt
1564
+ },
1565
+ {
1566
+ id: "settings",
1567
+ icon: "nav-settings",
1568
+ label: "Settings",
1569
+ run: () => Gt()
1570
+ }
1571
+ ].map((e) => ({
1572
+ hint: "Page",
1573
+ ...e
1574
+ }));
1575
+ function dn({ mode: e, menus: t, tools: n = [], layers: r = [] }) {
1576
+ let [i, a] = A(!1), [o, s] = A(""), [c, l] = A(F[0].value), [u, d] = A(0);
1577
+ O(() => {
1578
+ let e = () => a((e) => !e);
1579
+ return window.addEventListener("kolbox:search", e), () => window.removeEventListener("kolbox:search", e);
1580
+ }, []), O(() => {
1581
+ i || (s(""), l(F[0].value));
1582
+ }, [i]);
1583
+ let f = i ? Ze({
1584
+ menus: t,
1585
+ tools: n,
1586
+ layers: r,
1587
+ pages: un(),
1588
+ files: ln(),
1589
+ shortcuts: rt(an[e] ?? "home")
1590
+ }) : [], p = i ? nt(o ? tt(f, o) : $e(f), c) : [], m = p.flatMap((e) => e.rows);
1591
+ return O(() => {
1592
+ d(Math.max(0, m.findIndex((e) => !e.disabled)));
1593
+ }, [
1594
+ o,
1595
+ i,
1596
+ c,
1597
+ m.map((e) => e.id).join("\0")
1598
+ ]), /* @__PURE__ */ j(_e, {
1599
+ variant: "kolbox",
1600
+ open: i,
1601
+ onClose: () => a(!1),
1602
+ query: o,
1603
+ onQueryChange: s,
1604
+ tabs: F,
1605
+ tab: c,
1606
+ onTab: l,
1607
+ groups: p,
1608
+ active: u,
1609
+ onActive: d,
1610
+ onSelect: (e) => {
1611
+ Ge(e.key ?? e.id), a(!1), e.run?.();
1612
+ },
1613
+ empty: e === "editor" ? "Search files, layers, pages, tools, menu actions and shortcuts by name." : "Search files, pages, menu actions and shortcuts by name."
1614
+ });
1615
+ }
1616
+ function fn({ menus: e }) {
1617
+ let { tools: t, layers: n } = on();
1618
+ return /* @__PURE__ */ j(dn, {
1619
+ mode: "editor",
1620
+ menus: e,
1621
+ tools: t,
1622
+ layers: n
1623
+ });
1624
+ }
1625
+ function pn({ mode: e, menus: t }) {
1626
+ return e === "editor" ? /* @__PURE__ */ j(fn, { menus: t ?? [] }) : /* @__PURE__ */ j(dn, {
1627
+ mode: e,
1628
+ menus: t ?? [{
1629
+ label: "FXR",
1630
+ groups: [Xt({ mode: e })]
1631
+ }]
1632
+ });
1633
+ }
1634
+ //#endregion
1635
+ //#region src/editor/kolbox/files/places.js
1636
+ var mn = "kolbox.places.v1", q = {
1637
+ id: "drafts",
1638
+ name: "Drafts",
1639
+ builtIn: !0
1640
+ }, hn = {
1641
+ media: !0,
1642
+ theme: !0
1643
+ }, gn = {
1644
+ folders: [],
1645
+ placeOf: {},
1646
+ keepOf: {},
1647
+ trashed: {},
1648
+ starred: []
1649
+ }, J = null;
1650
+ function Y() {
1651
+ if (J) return J;
1652
+ try {
1653
+ J = {
1654
+ ...gn,
1655
+ ...JSON.parse(localStorage.getItem(mn) || "null")
1656
+ };
1657
+ } catch {
1658
+ J = { ...gn };
1659
+ }
1660
+ return J;
1661
+ }
1662
+ function X(e) {
1663
+ J = e;
1664
+ try {
1665
+ localStorage.setItem(mn, JSON.stringify(e));
1666
+ } catch (e) {
1667
+ console.warn("places: could not save to this browser:", e?.message || e);
1668
+ }
1669
+ window.dispatchEvent(new CustomEvent("kolbox:places"));
1670
+ }
1671
+ var _n = (e) => {
1672
+ let t = (t) => {
1673
+ t.key === mn && (J = null, e());
1674
+ };
1675
+ return window.addEventListener("kolbox:places", e), window.addEventListener("storage", t), () => {
1676
+ window.removeEventListener("kolbox:places", e), window.removeEventListener("storage", t);
1677
+ };
1678
+ }, vn = () => [q, ...Y().folders], yn = (e) => vn().find((t) => t.id === e) ?? q;
1679
+ function bn(e) {
1680
+ let t = String(e ?? "").trim();
1681
+ if (!t) return null;
1682
+ let n = Y(), r = n.folders.find((e) => e.name.toLowerCase() === t.toLowerCase());
1683
+ if (r) return r.id;
1684
+ let i = `f-${Date.now().toString(36)}${Math.random().toString(36).slice(2, 6)}`;
1685
+ return X({
1686
+ ...n,
1687
+ folders: [...n.folders, {
1688
+ id: i,
1689
+ name: t,
1690
+ created: Date.now()
1691
+ }]
1692
+ }), i;
1693
+ }
1694
+ var xn = (e) => Y().placeOf[e] && vn().some((t) => t.id === Y().placeOf[e]) ? Y().placeOf[e] : q.id;
1695
+ function Sn(e, t) {
1696
+ if (!e) return;
1697
+ let n = Y();
1698
+ X({
1699
+ ...n,
1700
+ placeOf: {
1701
+ ...n.placeOf,
1702
+ [e]: t || q.id
1703
+ }
1704
+ });
1705
+ }
1706
+ var Cn = (e) => ({
1707
+ ...hn,
1708
+ ...Y().keepOf[e] ?? {}
1709
+ });
1710
+ function wn(e, t) {
1711
+ if (!e) return;
1712
+ let n = Y();
1713
+ X({
1714
+ ...n,
1715
+ keepOf: {
1716
+ ...n.keepOf,
1717
+ [e]: {
1718
+ ...hn,
1719
+ ...t
1720
+ }
1721
+ }
1722
+ });
1723
+ }
1724
+ function Tn(e) {
1725
+ let t = Y(), { [e]: n, ...r } = t.placeOf, { [e]: i, ...a } = t.keepOf, { [e]: o, ...s } = t.trashed;
1726
+ X({
1727
+ ...t,
1728
+ placeOf: r,
1729
+ keepOf: a,
1730
+ trashed: s,
1731
+ starred: t.starred.filter((t) => t !== e)
1732
+ });
1733
+ }
1734
+ var En = (e) => Y().trashed[e] ?? null;
1735
+ function Dn(e) {
1736
+ let t = Y();
1737
+ X({
1738
+ ...t,
1739
+ trashed: {
1740
+ ...t.trashed,
1741
+ [e]: Date.now()
1742
+ },
1743
+ starred: t.starred.filter((t) => t !== e)
1744
+ });
1745
+ }
1746
+ function On(e) {
1747
+ let t = Y(), { [e]: n, ...r } = t.trashed;
1748
+ X({
1749
+ ...t,
1750
+ trashed: r
1751
+ });
1752
+ }
1753
+ var kn = () => Y().starred, An = (e) => Y().starred.includes(e);
1754
+ function jn(e) {
1755
+ let t = Y();
1756
+ X({
1757
+ ...t,
1758
+ starred: t.starred.includes(e) ? t.starred.filter((t) => t !== e) : [...t.starred, e]
1759
+ });
1760
+ }
1761
+ function Mn(e, t) {
1762
+ let n = String(t ?? "").trim(), r = Y();
1763
+ n && X({
1764
+ ...r,
1765
+ folders: r.folders.map((t) => t.id === e ? {
1766
+ ...t,
1767
+ name: n
1768
+ } : t)
1769
+ });
1770
+ }
1771
+ function Nn(e) {
1772
+ let t = Y(), n = Date.now(), r = Object.keys(t.placeOf).filter((n) => t.placeOf[n] === e), i = { ...t.trashed };
1773
+ r.forEach((e) => {
1774
+ i[e] ??= n;
1775
+ }), X({
1776
+ ...t,
1777
+ folders: t.folders.filter((t) => t.id !== e),
1778
+ trashed: i,
1779
+ starred: t.starred.filter((t) => t !== e)
1780
+ });
1781
+ }
1782
+ function Pn() {
1783
+ return Me(_n, Y, Y);
1784
+ }
1785
+ //#endregion
1786
+ //#region src/editor/kolbox/editor/export/render.js
1787
+ var Fn = [
1788
+ {
1789
+ value: "png",
1790
+ label: "PNG"
1791
+ },
1792
+ {
1793
+ value: "jpg",
1794
+ label: "JPG"
1795
+ },
1796
+ {
1797
+ value: "svg",
1798
+ label: "SVG"
1799
+ },
1800
+ {
1801
+ value: "pdf",
1802
+ label: "PDF"
1803
+ },
1804
+ {
1805
+ value: "webm",
1806
+ label: "Video (WebM)"
1807
+ }
1808
+ ], In = Fn.filter((e) => e.value !== "webm"), Z = 30, Ln = [
1809
+ .5,
1810
+ 1,
1811
+ 2,
1812
+ 3,
1813
+ 4
1814
+ ], Q = (e, t = "Untitled") => String(e ?? "").replace(/[\\/:*?"<>|]+/g, "-").replace(/\s+/g, " ").trim().slice(0, 80) || t, Rn = (e, t = 0) => e?.name || `Frame ${t + 1}`, zn = (e) => typeof e.x == "number" && e.w > 0 && e.h > 0;
1815
+ function Bn(e, t, n) {
1816
+ let r = t.density > 0 ? t.density : 1, i = u(e, t.id).map((e) => typeof e.x == "number" ? {
1817
+ ...e,
1818
+ x: e.x - t.x,
1819
+ y: e.y - t.y
1820
+ } : e);
1821
+ return {
1822
+ name: Rn(t, n),
1823
+ layers: i,
1824
+ w: Math.max(1, Math.round(t.w * r)),
1825
+ h: Math.max(1, Math.round(t.h * r)),
1826
+ fill: t.color ?? null,
1827
+ fillOpacity: t.fillOpacity ?? 1,
1828
+ viewW: t.w,
1829
+ edge: t,
1830
+ framed: !0
1831
+ };
1832
+ }
1833
+ function $(e, t, n = !1) {
1834
+ let r = t.filter((e) => e && e.visible !== !1 && zn(e)), i = n ? [...r.filter((e) => e.type === "frame"), ...r.filter((e) => e.type !== "frame")] : r.filter((e) => e.type !== "frame");
1835
+ if (!i.length) return null;
1836
+ let a = Math.min(...i.map((e) => e.x)), o = Math.min(...i.map((e) => e.y)), s = Math.max(...i.map((e) => e.x + e.w)) - a, c = Math.max(...i.map((e) => e.y + e.h)) - o;
1837
+ return {
1838
+ name: e,
1839
+ layers: i.map((e) => ({
1840
+ ...e,
1841
+ x: e.x - a,
1842
+ y: e.y - o
1843
+ })),
1844
+ w: Math.max(1, Math.round(s)),
1845
+ h: Math.max(1, Math.round(c)),
1846
+ fill: null,
1847
+ fillOpacity: 1,
1848
+ viewW: s,
1849
+ framed: !1
1850
+ };
1851
+ }
1852
+ function Vn(e, t) {
1853
+ let { layers: n, frameMode: r, activeFrame: i, selectedIds: a = [] } = e, o = r ? n.filter((e) => e.type === "frame") : [], s = (e) => o.indexOf(e), c = () => ({
1854
+ name: e.canvasName || "Canvas",
1855
+ layers: n,
1856
+ w: e.canvasW,
1857
+ h: e.canvasH,
1858
+ fill: e.canvasFill,
1859
+ fillOpacity: e.canvasFillOpacity ?? 1,
1860
+ viewW: null,
1861
+ framed: !0
1862
+ });
1863
+ if (t === "frames" || t === "frames:all") {
1864
+ if (!r) return [c()];
1865
+ let n = t === "frames:all", i = e.everyFrame(n ? null : e.pageId), a = n && new Set(i.map((e) => e.pageId)).size > 1;
1866
+ return i.flatMap((t) => Vn({
1867
+ ...e,
1868
+ layers: t.layers
1869
+ }, `layer:${t.frame.id}`).map((e) => a ? {
1870
+ ...e,
1871
+ name: `${t.pageName} ${e.name}`
1872
+ } : e));
1873
+ }
1874
+ if (t === "page") {
1875
+ if (!r) return [c()];
1876
+ let t = $(e.pages?.find((t) => t.id === e.pageId)?.name || "Page", n, !0);
1877
+ return t ? [t] : [];
1878
+ }
1879
+ if (t === "selection") {
1880
+ let e = a.filter((e) => e !== "canvas").map((e) => g(n, e)).filter(Boolean);
1881
+ if (e.length === 1 && e[0].type === "frame") return [Bn(n, e[0], s(e[0]))];
1882
+ let t = $(e.length === 1 && e[0].name || "Selection", e);
1883
+ return t ? [t] : [];
1884
+ }
1885
+ if (typeof t == "string" && t.startsWith("layer:")) {
1886
+ let e = g(n, t.slice(6));
1887
+ if (!e) return [];
1888
+ if (e.type === "frame") return [Bn(n, e, s(e))];
1889
+ let r = $(e.name || "Layer", [e]);
1890
+ return r ? [r] : [];
1891
+ }
1892
+ if (!r) return [c()];
1893
+ if (i) return [Bn(n, i, s(i))];
1894
+ let l = $("Page", n);
1895
+ return l ? [l] : [];
1896
+ }
1897
+ function Hn(e) {
1898
+ let { frameMode: t, activeFrame: n, layers: r, selectedIds: i = [] } = e, a = t ? r.filter((e) => e.type === "frame") : [], o = [{
1899
+ value: "frame",
1900
+ label: t ? n ? `Frame: ${Rn(n, a.indexOf(n))}` : "Page" : "Frame"
1901
+ }], s = i.filter((e) => e !== "canvas");
1902
+ s.length && !(s.length === 1 && n?.id === s[0]) && o.push({
1903
+ value: "selection",
1904
+ label: s.length === 1 ? "Selection" : `Selection (${s.length})`
1905
+ });
1906
+ let c = t ? e.everyFrame().length : 0;
1907
+ return c > 1 && o.push({
1908
+ value: "frames",
1909
+ label: `Every frame (${c})`
1910
+ }), o;
1911
+ }
1912
+ function Un(e) {
1913
+ let t = (e) => (e ?? []).some((e) => o(e) || e.type === "loop" || e.type === "kinetic" || e.type === "photo" && (e.srcType === "video" || e.srcType === "webcam") || t(e.children));
1914
+ return t(r(e));
1915
+ }
1916
+ var Wn = /* @__PURE__ */ new Map(), Gn = (e) => typeof e == "string" && !e.startsWith("data:"), Kn = (e) => new Promise((t, n) => {
1917
+ let r = new FileReader();
1918
+ r.onload = () => t(r.result), r.onerror = n, r.readAsDataURL(e);
1919
+ }), qn = (e) => e.type === "photo" && e.srcType === "video" || e.fill?.type === "video", Jn = (e, t) => qn(e) && !t ? null : e.type === "photo" && e.srcType !== "webcam" && Gn(e.src) ? e.src : (e.fill?.type === "image" || e.fill?.type === "video") && Gn(e.fill.src) ? e.fill.src : null;
1920
+ async function Yn(e, { clips: t = 0 } = {}) {
1921
+ let n = [], r = (e) => (e ?? []).forEach((e) => {
1922
+ let i = Jn(e, t);
1923
+ i && !Wn.has(i) && n.push([i, qn(e)]), r(e.children);
1924
+ });
1925
+ r(e), await Promise.all(n.map(async ([e, n]) => {
1926
+ try {
1927
+ let r = await fetch(e), i = r.ok ? await r.blob() : null;
1928
+ i && (!n || i.size <= t) && Wn.set(e, await Kn(i));
1929
+ } catch {}
1930
+ }));
1931
+ let i = (e) => e.map((e) => {
1932
+ let n = Jn(e, t), r = n && Wn.get(n), a = r && (!qn(e) || r.length * .75 <= t) ? r : null, o = Array.isArray(e.children) ? i(e.children) : e.children;
1933
+ if (!a && o === e.children) return e;
1934
+ let s = {
1935
+ ...e,
1936
+ ...o === e.children ? {} : { children: o }
1937
+ };
1938
+ return a && e.type === "photo" ? s.src = a : a && (s.fill = {
1939
+ ...e.fill,
1940
+ src: a
1941
+ }), s;
1942
+ });
1943
+ return i(e);
1944
+ }
1945
+ async function Xn(e, { palette: n, aspect: a, fill: o = !0, rasterScale: s = 1, ctx: l = t.getCtx() }) {
1946
+ let u = i(r(e.layers), l);
1947
+ await S(u), u.some((e) => e.type === "kinetic") && await d("motion")?.warmFontCss?.();
1948
+ let f = o ? h(e.fill ?? null, n) : null, p = typeof f == "string" && f.match(/^var\((--[^),\s]+)/), m = p ? c(p[1]) || null : f;
1949
+ return ne({
1950
+ layers: await Yn(u),
1951
+ palette: n,
1952
+ aspect: a,
1953
+ canvasW: e.w,
1954
+ canvasH: e.h,
1955
+ rasterScale: s,
1956
+ fill: m,
1957
+ fillOpacity: e.fillOpacity ?? 1,
1958
+ viewW: e.viewW,
1959
+ edge: e.edge ?? null
1960
+ });
1961
+ }
1962
+ async function Zn(e) {
1963
+ let t = await createImageBitmap(e), n = document.createElement("canvas");
1964
+ n.width = t.width, n.height = t.height;
1965
+ let r = n.getContext("2d");
1966
+ return r.fillStyle = "#fff", r.fillRect(0, 0, n.width, n.height), r.drawImage(t, 0, 0), {
1967
+ blob: await new Promise((e) => n.toBlob(e, "image/jpeg", .92)),
1968
+ w: n.width,
1969
+ h: n.height
1970
+ };
1971
+ }
1972
+ async function Qn({ blob: e, w: t, h: n }, r, i) {
1973
+ let a = new Uint8Array(await e.arrayBuffer()), o = new TextEncoder(), s = `q ${r} 0 0 ${i} 0 0 cm /Im0 Do Q`, c = [
1974
+ "<< /Type /Catalog /Pages 2 0 R >>",
1975
+ "<< /Type /Pages /Kids [3 0 R] /Count 1 >>",
1976
+ `<< /Type /Page /Parent 2 0 R /MediaBox [0 0 ${r} ${i}] /Resources << /XObject << /Im0 4 0 R >> >> /Contents 5 0 R >>`,
1977
+ [
1978
+ `<< /Type /XObject /Subtype /Image /Width ${t} /Height ${n} /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length ${a.length} >>\nstream\n`,
1979
+ a,
1980
+ "\nendstream"
1981
+ ],
1982
+ `<< /Length ${s.length} >>\nstream\n${s}\nendstream`
1983
+ ], l = [], u = 0, d = (e) => {
1984
+ let t = typeof e == "string" ? o.encode(e) : e;
1985
+ l.push(t), u += t.length;
1986
+ }, f = [];
1987
+ d("%PDF-1.4\n"), c.forEach((e, t) => {
1988
+ f.push(u), d(`${t + 1} 0 obj\n`), [].concat(e).forEach(d), d("\nendobj\n");
1989
+ });
1990
+ let p = u;
1991
+ return d(`xref\n0 ${c.length + 1}\n0000000000 65535 f \n${f.map((e) => `${String(e).padStart(10, "0")} 00000 n \n`).join("")}`), d(`trailer\n<< /Size ${c.length + 1} /Root 1 0 R >>\nstartxref\n${p}\n%%EOF\n`), new Blob(l, { type: "application/pdf" });
1992
+ }
1993
+ async function $n(e, { format: t, scale: n = 1, fill: r = !0, palette: i, aspect: a, name: o, suffix: s = "" }) {
1994
+ let c = t !== "svg", l = await Xn(e, {
1995
+ palette: i,
1996
+ aspect: a,
1997
+ fill: r,
1998
+ rasterScale: c ? n : 1
1999
+ }), u = `${Q(o ?? e.name)}${s ? Q(s, "") : !c || n === 1 ? "" : `@${n}x`}`;
2000
+ if (t === "svg") return {
2001
+ name: `${u}.svg`,
2002
+ blob: new Blob([l], { type: "image/svg+xml" })
2003
+ };
2004
+ let d = await ke(l, n);
2005
+ if (t === "png") return {
2006
+ name: `${u}.png`,
2007
+ blob: d
2008
+ };
2009
+ let f = await Zn(d);
2010
+ return t === "jpg" ? {
2011
+ name: `${u}.jpg`,
2012
+ blob: f.blob
2013
+ } : {
2014
+ name: `${u}.pdf`,
2015
+ blob: await Qn(f, e.w, e.h)
2016
+ };
2017
+ }
2018
+ var er = () => new Promise((e) => requestAnimationFrame(e));
2019
+ async function tr(e, t, n, r) {
2020
+ let i = URL.createObjectURL(new Blob([t], { type: "image/svg+xml" }));
2021
+ try {
2022
+ let t = new Image();
2023
+ await new Promise((e, n) => {
2024
+ t.onload = e, t.onerror = () => n(/* @__PURE__ */ Error("SVG rasterize failed")), t.src = i;
2025
+ }), e.clearRect(0, 0, n, r), e.drawImage(t, 0, 0, n, r);
2026
+ } finally {
2027
+ URL.revokeObjectURL(i);
2028
+ }
2029
+ }
2030
+ async function nr(e, { scale: n = 1, palette: a, aspect: o, name: s, onProgress: c }) {
2031
+ let l = Math.max(1, Math.round(t.getLoopSeconds() * Z)), u = Math.round(e.w * n), d = Math.round(e.h * n), p = document.createElement("canvas");
2032
+ p.width = u, p.height = d;
2033
+ let m = p.getContext("2d"), { Output: ee, WebMOutputFormat: h, BufferTarget: g, CanvasSource: _ } = await import("./src-D-TQbBo2.js"), v = new ee({
2034
+ format: new h(),
2035
+ target: new g()
2036
+ }), y = new _(p, {
2037
+ codec: "vp9",
2038
+ bitrate: Math.round(u * d * Z * .1)
2039
+ });
2040
+ v.addVideoTrack(y, { frameRate: Z }), await v.start();
2041
+ let b = f();
2042
+ for (let n = 0; n < l; n++) i(r(e.layers), {
2043
+ ...t.getCtx(),
2044
+ t: n / l,
2045
+ smoothState: b
2046
+ });
2047
+ for (let r = 0; r < l; r++) t.seek(r / l), await er(), await er(), await tr(m, await Xn(e, {
2048
+ palette: a,
2049
+ aspect: o,
2050
+ rasterScale: n,
2051
+ ctx: {
2052
+ ...t.getCtx(),
2053
+ smoothState: b
2054
+ }
2055
+ }), u, d), await y.add(r / Z, 1 / Z), c?.(r + 1, l);
2056
+ return await v.finalize(), {
2057
+ name: `${Q(s ?? e.name)}.webm`,
2058
+ blob: new Blob([v.target.buffer], { type: "video/webm" })
2059
+ };
2060
+ }
2061
+ var rr = (e, { names: n = [], onProgress: r, ...i }) => he(async () => {
2062
+ let a = t.isPlaying(), o = t.getT();
2063
+ a && t.pause();
2064
+ try {
2065
+ let t = [];
2066
+ for (let a = 0; a < e.length; a++) t.push(await nr(e[a], {
2067
+ ...i,
2068
+ name: n[a],
2069
+ onProgress: (t, n) => r?.(a * n + t, e.length * n)
2070
+ }));
2071
+ return t;
2072
+ } finally {
2073
+ t.seek(o), a && t.play();
2074
+ }
2075
+ });
2076
+ async function ir(e, t) {
2077
+ if (e.length) {
2078
+ if (e.length === 1) {
2079
+ C(e[0].blob, e[0].name);
2080
+ return;
2081
+ }
2082
+ C(w(await Promise.all(e.map(async (e) => ({
2083
+ name: e.name,
2084
+ data: new Uint8Array(await e.blob.arrayBuffer())
2085
+ })))), `${Q(t)}.zip`);
2086
+ }
2087
+ }
2088
+ //#endregion
2089
+ //#region src/editor/kolbox/files/portable.js
2090
+ var ar = "kol-design-editor", or = 1, sr = ".kol.json", cr = 15e5;
2091
+ async function lr(e, { media: t = !0, theme: n = !0 } = {}, r = cr) {
2092
+ let i = { ...e };
2093
+ return t && (i.layers = await Yn(e.layers ?? [], { clips: r })), n || (i.palette = null), i;
2094
+ }
2095
+ async function ur(e, t) {
2096
+ let n = {
2097
+ page: ar,
2098
+ version: or,
2099
+ spec: await lr(e, {
2100
+ media: !0,
2101
+ theme: !0
2102
+ }, Infinity)
2103
+ };
2104
+ return {
2105
+ blob: new Blob([JSON.stringify(n, null, 2)], { type: "application/json" }),
2106
+ name: `${Q(t)}${sr}`
2107
+ };
2108
+ }
2109
+ async function dr(e) {
2110
+ let t;
2111
+ try {
2112
+ t = JSON.parse(await e.text());
2113
+ } catch {
2114
+ throw Error("Not a JSON file");
2115
+ }
2116
+ if (!t || t.page !== ar) throw Error("Not a KOL file");
2117
+ if (t.version !== or) throw Error(`Unsupported file version (${t.version})`);
2118
+ if (!t.spec || typeof t.spec != "object" || !Array.isArray(t.spec.layers)) throw Error("No document in file");
2119
+ return {
2120
+ ...t.spec,
2121
+ name: t.spec.name || e.name.replace(/\.kol\.json$|\.json$/i, "")
2122
+ };
2123
+ }
2124
+ var fr = () => new Promise((e) => {
2125
+ let t = document.createElement("input");
2126
+ t.type = "file", t.accept = `${sr},.json,application/json`, t.onchange = () => e(t.files?.[0] ?? null), t.addEventListener("cancel", () => e(null)), t.click();
2127
+ });
2128
+ //#endregion
2129
+ export { Pt as $, kn as A, Zt as B, vn as C, Mn as D, Nn as E, pn as F, Jt as G, Xt as H, nn as I, Gt as J, U as K, tn as L, Dn as M, En as N, On as O, Pn as P, Ft as Q, en as R, Cn as S, xn as T, G as U, Qt as V, Yt as W, Rt as X, qt as Y, Bt as Z, hn as _, Fn as a, Re as at, Tn as b, Un as c, Fe as ct, rr as d, Et as et, Vn as f, q as g, ir as h, dr as i, Ve as it, jn as j, wn as k, $n as l, N as lt, Hn as m, fr as n, Tt as nt, Ln as o, Ie as ot, Q as p, Kt as q, ur as r, at as rt, In as s, Pe as st, lr as t, kt as tt, Xn as u, bn as v, Sn as w, An as x, yn as y, $t as z };