@dstackai/sqircle 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,1339 @@
1
+ import { useEffect as e, useId as t, useMemo as n, useState as r } from "react";
2
+ import { Fragment as i, jsx as a, jsxs as o } from "react/jsx-runtime";
3
+ //#region src/squircle/geometry.ts
4
+ var s = {
5
+ width: 800,
6
+ viewBoxHeight: 480,
7
+ exponent: 12,
8
+ samples: 160,
9
+ prismHeight: 10,
10
+ angleDegrees: 20,
11
+ inlayScale: .6
12
+ };
13
+ function c(e = {}) {
14
+ let t = e.exponent ?? s.exponent, n = e.samples ?? s.samples, r = e.width ?? s.width, i = e.viewBoxHeight ?? s.viewBoxHeight, a = e.prismHeight ?? s.prismHeight, o = e.angleDegrees ?? s.angleDegrees, c = e.inlayScale ?? s.inlayScale, l = o * Math.PI / 180, u = Math.cos(l), d = Math.sin(l), p = f(1, t, n).map((e) => (e.x - e.y) * u), b = Math.max(...p) - Math.min(...p), x = e.halfSize ?? r / b, S = f(x, t, n), C = S.map((e) => (e.x - e.y) * u), w = S.map((e) => (e.x + e.y) * d), T = e.center ?? {
15
+ x: -Math.min(...C),
16
+ y: a - Math.min(...w)
17
+ }, E = S.map((e) => m(e, a, T, u, d)), D = S.map((e) => m(e, 0, T, u, d)), O = h(S.map((e) => e.nx + e.ny >= 0)), k = g(O, n), A = _(E, O), j = _(D, O).reverse(), M = [...A, ...j], N = _(D, k), P = f(x * c, t, n).map((e) => m(e, a, T, u, d)), F = v(E), I = v([...E, ...M]);
18
+ return {
19
+ config: {
20
+ width: r,
21
+ viewBoxHeight: i,
22
+ exponent: t,
23
+ samples: n,
24
+ prismHeight: a,
25
+ angleDegrees: o,
26
+ inlayScale: c,
27
+ halfSize: x,
28
+ center: T
29
+ },
30
+ cosA: u,
31
+ sinA: d,
32
+ topPoints: E,
33
+ bottomPoints: D,
34
+ wallPoints: M,
35
+ hiddenPoints: N,
36
+ inlayPoints: P,
37
+ labelTransform: `matrix(${y(u)},${y(d)},${y(-u)},${y(d)},${y(T.x)},${y(T.y - a)})`,
38
+ topBounds: F,
39
+ sideBounds: I,
40
+ viewBox: `0 0 ${y(r)} ${y(i)}`
41
+ };
42
+ }
43
+ function l(e) {
44
+ return e.map((e) => `${y(e.x)},${y(e.y)}`).join(" ");
45
+ }
46
+ function u(e, t = {}) {
47
+ let n = t.gap ?? 88, r = t.material ?? "wireframe", i = t.paletteId ?? "15";
48
+ return Array.from({ length: Math.max(0, e) }, (t, a) => ({
49
+ id: `layer-${a + 1}`,
50
+ visible: !0,
51
+ offset: {
52
+ x: 0,
53
+ y: (e - a - 1) * n
54
+ },
55
+ base: {
56
+ material: r,
57
+ paletteId: i,
58
+ text: !1,
59
+ dash: !1
60
+ },
61
+ hover: void 0
62
+ }));
63
+ }
64
+ function d(e, t = 88) {
65
+ let n = e.length;
66
+ return e.map((e, r) => ({
67
+ ...e,
68
+ offset: {
69
+ x: e.offset?.x ?? 0,
70
+ y: (n - r - 1) * t
71
+ }
72
+ }));
73
+ }
74
+ function f(e, t, n) {
75
+ return Array.from({ length: n }, (r, i) => {
76
+ let a = 2 * Math.PI * i / n, o = Math.cos(a), s = Math.sin(a);
77
+ return {
78
+ x: e * p(o, 2 / t),
79
+ y: e * p(s, 2 / t),
80
+ nx: p(o, 2 * (t - 1) / t),
81
+ ny: p(s, 2 * (t - 1) / t)
82
+ };
83
+ });
84
+ }
85
+ function p(e, t) {
86
+ return Math.sign(e) * Math.abs(e) ** +t;
87
+ }
88
+ function m(e, t, n, r, i) {
89
+ return {
90
+ x: n.x + (e.x - e.y) * r,
91
+ y: n.y + (e.x + e.y) * i - t
92
+ };
93
+ }
94
+ function h(e) {
95
+ let t = [...e, ...e], n = {
96
+ start: 0,
97
+ length: 0
98
+ }, r = 0, i = 0;
99
+ return t.forEach((t, a) => {
100
+ t ? (i === 0 && (r = a), i += 1, i > n.length && i <= e.length && (n = {
101
+ start: r % e.length,
102
+ length: i
103
+ })) : i = 0;
104
+ }), n.length > 0 ? n : {
105
+ start: 0,
106
+ length: e.length
107
+ };
108
+ }
109
+ function g(e, t) {
110
+ return {
111
+ start: (e.start + e.length) % t,
112
+ length: Math.max(0, t - e.length)
113
+ };
114
+ }
115
+ function _(e, t) {
116
+ return Array.from({ length: t.length }, (n, r) => e[(t.start + r) % e.length]);
117
+ }
118
+ function v(e) {
119
+ let t = e.map((e) => e.x), n = e.map((e) => e.y);
120
+ return {
121
+ minX: Math.min(...t),
122
+ minY: Math.min(...n),
123
+ maxX: Math.max(...t),
124
+ maxY: Math.max(...n)
125
+ };
126
+ }
127
+ function y(e) {
128
+ return Number(e.toFixed(2)).toString();
129
+ }
130
+ //#endregion
131
+ //#region src/squircle/palettes.ts
132
+ var b = {
133
+ 13: {
134
+ id: "13",
135
+ label: "13 Alpha",
136
+ top: [
137
+ {
138
+ offset: 0,
139
+ color: "#f5f0ff"
140
+ },
141
+ {
142
+ offset: .48,
143
+ color: "#b388ff"
144
+ },
145
+ {
146
+ offset: 1,
147
+ color: "#0099ff"
148
+ }
149
+ ],
150
+ side: [
151
+ {
152
+ offset: 0,
153
+ color: "#8250e6"
154
+ },
155
+ {
156
+ offset: .5,
157
+ color: "#596ce8"
158
+ },
159
+ {
160
+ offset: 1,
161
+ color: "#0084e8"
162
+ }
163
+ ],
164
+ textWire: [
165
+ {
166
+ offset: 0,
167
+ color: "#b388ff"
168
+ },
169
+ {
170
+ offset: .52,
171
+ color: "#5c7fff"
172
+ },
173
+ {
174
+ offset: 1,
175
+ color: "#0099ff"
176
+ }
177
+ ],
178
+ labelFill: "#2a1060",
179
+ topEdge: "#7c5fd0",
180
+ sideEdge: "#2d1466",
181
+ swatch: ["#b388ff", "#0099ff"]
182
+ },
183
+ 14: {
184
+ id: "14",
185
+ label: "14 Alpha",
186
+ top: [
187
+ {
188
+ offset: 0,
189
+ color: "#e9fffb"
190
+ },
191
+ {
192
+ offset: .44,
193
+ color: "#44b9d6"
194
+ },
195
+ {
196
+ offset: 1,
197
+ color: "#006ce0"
198
+ }
199
+ ],
200
+ side: [
201
+ {
202
+ offset: 0,
203
+ color: "#38acbc"
204
+ },
205
+ {
206
+ offset: .52,
207
+ color: "#268ccf"
208
+ },
209
+ {
210
+ offset: 1,
211
+ color: "#005fc4"
212
+ }
213
+ ],
214
+ textWire: [
215
+ {
216
+ offset: 0,
217
+ color: "#44b9d6"
218
+ },
219
+ {
220
+ offset: .52,
221
+ color: "#2f8fe2"
222
+ },
223
+ {
224
+ offset: 1,
225
+ color: "#006ce0"
226
+ }
227
+ ],
228
+ labelFill: "#063f6a",
229
+ topEdge: "#237aa8",
230
+ sideEdge: "#063f6a",
231
+ swatch: ["#44b9d6", "#006ce0"]
232
+ },
233
+ 15: {
234
+ id: "15",
235
+ label: "15 Alpha",
236
+ top: [
237
+ {
238
+ offset: 0,
239
+ color: "#f0fbff"
240
+ },
241
+ {
242
+ offset: .34,
243
+ color: "#0099ff"
244
+ },
245
+ {
246
+ offset: .66,
247
+ color: "#5c7fff"
248
+ },
249
+ {
250
+ offset: 1,
251
+ color: "#962eff"
252
+ }
253
+ ],
254
+ side: [
255
+ {
256
+ offset: 0,
257
+ color: "#008fec"
258
+ },
259
+ {
260
+ offset: .34,
261
+ color: "#139cff"
262
+ },
263
+ {
264
+ offset: .56,
265
+ color: "#587fff"
266
+ },
267
+ {
268
+ offset: .78,
269
+ color: "#7c58f7"
270
+ },
271
+ {
272
+ offset: 1,
273
+ color: "#962eff"
274
+ }
275
+ ],
276
+ textWire: [
277
+ {
278
+ offset: 0,
279
+ color: "#0099ff"
280
+ },
281
+ {
282
+ offset: .52,
283
+ color: "#5c7fff"
284
+ },
285
+ {
286
+ offset: 1,
287
+ color: "#962eff"
288
+ }
289
+ ],
290
+ labelFill: "#f7fbff",
291
+ topEdge: "#7c5fd0",
292
+ sideEdge: "#2d1466",
293
+ swatch: ["#0099ff", "#962eff"]
294
+ },
295
+ 16: {
296
+ id: "16",
297
+ label: "16 Alpha",
298
+ top: [
299
+ {
300
+ offset: 0,
301
+ color: "#e9fbff"
302
+ },
303
+ {
304
+ offset: .46,
305
+ color: "#75cfff"
306
+ },
307
+ {
308
+ offset: 1,
309
+ color: "#2d49d8"
310
+ }
311
+ ],
312
+ side: [
313
+ {
314
+ offset: 0,
315
+ color: "#59b7ec"
316
+ },
317
+ {
318
+ offset: .54,
319
+ color: "#5874e0"
320
+ },
321
+ {
322
+ offset: 1,
323
+ color: "#263fb8"
324
+ }
325
+ ],
326
+ textWire: [
327
+ {
328
+ offset: 0,
329
+ color: "#75cfff"
330
+ },
331
+ {
332
+ offset: .52,
333
+ color: "#5c7fff"
334
+ },
335
+ {
336
+ offset: 1,
337
+ color: "#2d49d8"
338
+ }
339
+ ],
340
+ labelFill: "#10246a",
341
+ topEdge: "#3e65c8",
342
+ sideEdge: "#10246a",
343
+ swatch: ["#75cfff", "#2d49d8"]
344
+ },
345
+ 17: {
346
+ id: "17",
347
+ label: "17 Alpha",
348
+ top: [
349
+ {
350
+ offset: 0,
351
+ color: "#edf1ff"
352
+ },
353
+ {
354
+ offset: .46,
355
+ color: "#7f91ff"
356
+ },
357
+ {
358
+ offset: 1,
359
+ color: "#0099ff"
360
+ }
361
+ ],
362
+ side: [
363
+ {
364
+ offset: 0,
365
+ color: "#7081ef"
366
+ },
367
+ {
368
+ offset: .5,
369
+ color: "#617fee"
370
+ },
371
+ {
372
+ offset: 1,
373
+ color: "#0084e1"
374
+ }
375
+ ],
376
+ textWire: [
377
+ {
378
+ offset: 0,
379
+ color: "#7f91ff"
380
+ },
381
+ {
382
+ offset: .52,
383
+ color: "#5c9fff"
384
+ },
385
+ {
386
+ offset: 1,
387
+ color: "#0099ff"
388
+ }
389
+ ],
390
+ labelFill: "#17245e",
391
+ topEdge: "#5f6ed0",
392
+ sideEdge: "#17245e",
393
+ swatch: ["#7f91ff", "#0099ff"]
394
+ },
395
+ 18: {
396
+ id: "18",
397
+ label: "18 Alpha",
398
+ top: [
399
+ {
400
+ offset: 0,
401
+ color: "#f8fdff"
402
+ },
403
+ {
404
+ offset: .42,
405
+ color: "#b8e7ff"
406
+ },
407
+ {
408
+ offset: 1,
409
+ color: "#006ce0"
410
+ }
411
+ ],
412
+ side: [
413
+ {
414
+ offset: 0,
415
+ color: "#86d4f3"
416
+ },
417
+ {
418
+ offset: .5,
419
+ color: "#5da6dd"
420
+ },
421
+ {
422
+ offset: 1,
423
+ color: "#005dbc"
424
+ }
425
+ ],
426
+ textWire: [
427
+ {
428
+ offset: 0,
429
+ color: "#b8e7ff"
430
+ },
431
+ {
432
+ offset: .52,
433
+ color: "#42b4ff"
434
+ },
435
+ {
436
+ offset: 1,
437
+ color: "#006ce0"
438
+ }
439
+ ],
440
+ labelFill: "#064272",
441
+ topEdge: "#4f94c0",
442
+ sideEdge: "#064272",
443
+ swatch: ["#b8e7ff", "#006ce0"]
444
+ },
445
+ 19: {
446
+ id: "19",
447
+ label: "19 Alpha",
448
+ top: [
449
+ {
450
+ offset: 0,
451
+ color: "#e6fff9"
452
+ },
453
+ {
454
+ offset: .42,
455
+ color: "#42b4ff"
456
+ },
457
+ {
458
+ offset: 1,
459
+ color: "#8575ff"
460
+ }
461
+ ],
462
+ side: [
463
+ {
464
+ offset: 0,
465
+ color: "#1ea9eb"
466
+ },
467
+ {
468
+ offset: .5,
469
+ color: "#4f8cee"
470
+ },
471
+ {
472
+ offset: 1,
473
+ color: "#7866e8"
474
+ }
475
+ ],
476
+ textWire: [
477
+ {
478
+ offset: 0,
479
+ color: "#42b4ff"
480
+ },
481
+ {
482
+ offset: .52,
483
+ color: "#5c7fff"
484
+ },
485
+ {
486
+ offset: 1,
487
+ color: "#8575ff"
488
+ }
489
+ ],
490
+ labelFill: "#12306f",
491
+ topEdge: "#6470d8",
492
+ sideEdge: "#12306f",
493
+ swatch: ["#42b4ff", "#8575ff"]
494
+ },
495
+ 20: {
496
+ id: "20",
497
+ label: "20 Alpha",
498
+ top: [
499
+ {
500
+ offset: 0,
501
+ color: "#eef3ff"
502
+ },
503
+ {
504
+ offset: .38,
505
+ color: "#5c7fff"
506
+ },
507
+ {
508
+ offset: .7,
509
+ color: "#0099ff"
510
+ },
511
+ {
512
+ offset: 1,
513
+ color: "#b8e7ff"
514
+ }
515
+ ],
516
+ side: [
517
+ {
518
+ offset: 0,
519
+ color: "#536fe8"
520
+ },
521
+ {
522
+ offset: .52,
523
+ color: "#168fe8"
524
+ },
525
+ {
526
+ offset: 1,
527
+ color: "#8fd2ee"
528
+ }
529
+ ],
530
+ textWire: [
531
+ {
532
+ offset: 0,
533
+ color: "#5c7fff"
534
+ },
535
+ {
536
+ offset: .52,
537
+ color: "#0099ff"
538
+ },
539
+ {
540
+ offset: 1,
541
+ color: "#b8e7ff"
542
+ }
543
+ ],
544
+ labelFill: "#17245e",
545
+ topEdge: "#5a7bd0",
546
+ sideEdge: "#17245e",
547
+ swatch: ["#5c7fff", "#b8e7ff"]
548
+ }
549
+ }, x = Object.keys(b), S = "15";
550
+ function C(e) {
551
+ return b[e] ?? b[15];
552
+ }
553
+ //#endregion
554
+ //#region src/squircle/SquircleScene.tsx
555
+ var w = {
556
+ face: .35,
557
+ faceOpacity: .72,
558
+ wire: 1.6,
559
+ wireOpacity: .88,
560
+ hidden: 1.2,
561
+ hiddenOpacity: .28,
562
+ dash: 2.2,
563
+ wireDash: 1.6,
564
+ labelWire: 1.1
565
+ }, T = {
566
+ transparentFace: .38,
567
+ transparentAnnotation: .62,
568
+ solidAnnotation: .88
569
+ }, E = "GPU", D = 62, O = "Arial, Helvetica, sans-serif", k = 400;
570
+ function A({ layers: e, geometry: r, selectedLayerId: i, theme: s = "light", idPrefix: l, className: u, ariaLabel: d = "Squircle scene", fitToLayers: f = !0, transitionMs: p = 220, onLayerSelect: m }) {
571
+ let h = t().replace(/[^a-zA-Z0-9_-]/g, ""), g = l ?? `sq-${h}`, _ = n(() => c(r), [JSON.stringify(r ?? {})]), v = e.filter((e) => e.visible !== !1), y = Math.max(0, ...v.map((e) => e.offset?.y ?? 0)), b = r?.viewBoxHeight ?? (f ? Math.max(_.config.viewBoxHeight, y + _.sideBounds.maxY + 18) : _.config.viewBoxHeight), x = r?.viewBoxHeight === b ? _ : c({
572
+ ...r,
573
+ viewBoxHeight: b
574
+ }), S = { "--sq-transition-ms": `${p}ms` };
575
+ return /* @__PURE__ */ o("svg", {
576
+ className: [
577
+ "squircle-scene",
578
+ `sq-theme-${s}`,
579
+ u
580
+ ].filter(Boolean).join(" "),
581
+ "data-theme": s,
582
+ viewBox: x.viewBox,
583
+ role: "img",
584
+ "aria-label": d,
585
+ style: S,
586
+ children: [/* @__PURE__ */ a(j, {
587
+ prefix: g,
588
+ geometry: x
589
+ }), v.map((e) => /* @__PURE__ */ a(N, {
590
+ layer: e,
591
+ geometry: x,
592
+ prefix: g,
593
+ selected: i === e.id,
594
+ onSelect: m
595
+ }, e.id))]
596
+ });
597
+ }
598
+ function j({ prefix: e, geometry: t }) {
599
+ return /* @__PURE__ */ a("defs", { children: Object.values(b).map((n) => /* @__PURE__ */ o("g", { children: [
600
+ /* @__PURE__ */ a(M, {
601
+ id: `${e}-top-${n.id}`,
602
+ x1: t.topBounds.minX,
603
+ y1: t.topBounds.minY,
604
+ x2: t.topBounds.maxX,
605
+ y2: t.topBounds.maxY,
606
+ stops: n.top
607
+ }),
608
+ /* @__PURE__ */ a(M, {
609
+ id: `${e}-side-${n.id}`,
610
+ x1: t.sideBounds.minX,
611
+ y1: t.sideBounds.minY,
612
+ x2: t.sideBounds.maxX,
613
+ y2: t.sideBounds.maxY,
614
+ stops: n.side
615
+ }),
616
+ /* @__PURE__ */ a(M, {
617
+ id: `${e}-text-surface-${n.id}`,
618
+ x1: -425.63,
619
+ y1: -.1,
620
+ x2: 425.6,
621
+ y2: .07,
622
+ stops: n.top
623
+ }),
624
+ /* @__PURE__ */ a(M, {
625
+ id: `${e}-text-wire-${n.id}`,
626
+ x1: -64,
627
+ y1: -24,
628
+ x2: 64,
629
+ y2: 24,
630
+ stops: n.textWire
631
+ })
632
+ ] }, n.id)) });
633
+ }
634
+ function M({ id: e, x1: t, y1: n, x2: r, y2: i, stops: o }) {
635
+ return /* @__PURE__ */ a("linearGradient", {
636
+ id: e,
637
+ x1: t,
638
+ y1: n,
639
+ x2: r,
640
+ y2: i,
641
+ gradientUnits: "userSpaceOnUse",
642
+ children: o.map((e) => /* @__PURE__ */ a("stop", {
643
+ offset: e.offset,
644
+ stopColor: e.color
645
+ }, `${e.offset}-${e.color}`))
646
+ });
647
+ }
648
+ function N({ layer: e, geometry: t, prefix: n, selected: r, onSelect: i }) {
649
+ let s = F(e.base, e.stroke, e.opacity), c = e.hover ? F({
650
+ ...e.base,
651
+ ...e.hover
652
+ }, e.stroke, e.opacity) : null, l = !!(c && W(c) !== W(s)), u = e.offset?.x ?? 0, d = e.offset?.y ?? 0;
653
+ return /* @__PURE__ */ o("g", {
654
+ className: [
655
+ "sq-layer",
656
+ l ? "sq-has-hover" : "",
657
+ r ? "is-selected" : "",
658
+ e.className
659
+ ].filter(Boolean).join(" "),
660
+ "data-layer-id": e.id,
661
+ "data-hover-enabled": String(l),
662
+ transform: `translate(${u} ${d})`,
663
+ onClick: i ? () => i(e.id) : void 0,
664
+ children: [/* @__PURE__ */ a(P, {
665
+ className: "sq-base",
666
+ variant: s,
667
+ geometry: t,
668
+ prefix: n
669
+ }), l && c ? /* @__PURE__ */ a(P, {
670
+ className: "sq-hover",
671
+ variant: c,
672
+ geometry: t,
673
+ prefix: n
674
+ }) : null]
675
+ });
676
+ }
677
+ function P({ className: e, variant: t, geometry: n, prefix: r }) {
678
+ let s = C(t.paletteId), c = `url(#${r}-top-${s.id})`, u = `url(#${r}-side-${s.id})`, d = `url(#${r}-text-surface-${s.id})`, f = `url(#${r}-text-wire-${s.id})`, p = l(n.wallPoints), m = l(n.topPoints), h = l(n.hiddenPoints), g = l(n.inlayPoints);
679
+ return /* @__PURE__ */ o("g", {
680
+ className: [
681
+ "sq-variant",
682
+ e,
683
+ `sq-material-${t.material}`
684
+ ].join(" "),
685
+ children: [
686
+ t.material === "wireframe" ? /* @__PURE__ */ o(i, { children: [
687
+ /* @__PURE__ */ a("polyline", {
688
+ className: "sq-hidden",
689
+ points: h,
690
+ stroke: c,
691
+ strokeWidth: t.stroke.hidden,
692
+ opacity: t.stroke.hiddenOpacity
693
+ }),
694
+ /* @__PURE__ */ a("polygon", {
695
+ className: "sq-face sq-wire-side",
696
+ points: p,
697
+ fill: "none",
698
+ stroke: c,
699
+ strokeWidth: t.stroke.wire,
700
+ strokeOpacity: t.stroke.wireOpacity
701
+ }),
702
+ /* @__PURE__ */ a("polygon", {
703
+ className: "sq-face sq-wire-top",
704
+ points: m,
705
+ fill: "none",
706
+ stroke: c,
707
+ strokeWidth: t.stroke.wire,
708
+ strokeOpacity: t.stroke.wireOpacity
709
+ })
710
+ ] }) : /* @__PURE__ */ o(i, { children: [/* @__PURE__ */ a("polygon", {
711
+ className: "sq-face sq-solid-side",
712
+ points: p,
713
+ fill: u,
714
+ fillOpacity: t.material === "transparent" ? t.opacity.transparentFace : 1,
715
+ stroke: s.sideEdge,
716
+ strokeWidth: t.stroke.face,
717
+ strokeOpacity: t.stroke.faceOpacity
718
+ }), /* @__PURE__ */ a("polygon", {
719
+ className: "sq-face sq-solid-top",
720
+ points: m,
721
+ fill: c,
722
+ fillOpacity: t.material === "transparent" ? t.opacity.transparentFace : 1,
723
+ stroke: s.topEdge,
724
+ strokeWidth: t.stroke.face,
725
+ strokeOpacity: t.stroke.faceOpacity
726
+ })] }),
727
+ t.dash ? /* @__PURE__ */ a("polygon", {
728
+ className: "sq-inlay",
729
+ points: g,
730
+ stroke: V(t, s, c),
731
+ strokeWidth: t.material === "wireframe" ? t.stroke.wireDash : t.stroke.dash,
732
+ opacity: H(t)
733
+ }) : null,
734
+ t.text ? /* @__PURE__ */ a("text", {
735
+ className: "sq-label",
736
+ transform: n.labelTransform,
737
+ textAnchor: "middle",
738
+ dominantBaseline: "central",
739
+ fontFamily: t.textFontFamily,
740
+ fontSize: t.textSize,
741
+ fontWeight: t.textFontWeight,
742
+ ...U(t, s, d, f),
743
+ children: t.text
744
+ }) : null
745
+ ]
746
+ });
747
+ }
748
+ function F(e, t = {}, n = {}) {
749
+ return {
750
+ material: e.material ?? "wireframe",
751
+ paletteId: e.paletteId ?? "15",
752
+ text: L(e.text, I(e).gpu),
753
+ dash: e.dash ?? !1,
754
+ textStyle: R(e.textStyle ?? I(e).gpuStyle ?? "solid"),
755
+ textColor: z(e.textColor ?? I(e).gpuColor ?? "contrast"),
756
+ textSize: e.textSize ?? D,
757
+ textFontFamily: e.textFontFamily ?? O,
758
+ textFontWeight: e.textFontWeight ?? k,
759
+ dashColor: z(e.dashColor ?? "contrast"),
760
+ stroke: {
761
+ ...w,
762
+ ...t,
763
+ ...e.stroke
764
+ },
765
+ opacity: {
766
+ ...T,
767
+ ...n,
768
+ ...e.opacity
769
+ }
770
+ };
771
+ }
772
+ function I(e) {
773
+ return e;
774
+ }
775
+ function L(e, t) {
776
+ return typeof e == "string" ? e.trim() ? e : null : e === !0 || t ? E : null;
777
+ }
778
+ function R(e) {
779
+ return e === "wireframe" ? "wireframe" : "solid";
780
+ }
781
+ function z(e) {
782
+ return e === "auto" ? "contrast" : e;
783
+ }
784
+ function B(e, t) {
785
+ let n = z(e);
786
+ return n === "white" ? "#ffffff" : n === "black" ? "#05070a" : t;
787
+ }
788
+ function V(e, t, n) {
789
+ return e.material === "wireframe" ? n : B(e.dashColor, t.labelFill);
790
+ }
791
+ function H(e) {
792
+ return e.material === "transparent" ? e.opacity.transparentAnnotation : e.opacity.solidAnnotation;
793
+ }
794
+ function U(e, t, n, r) {
795
+ let i = H(e);
796
+ return e.material === "wireframe" ? e.textStyle === "wireframe" ? {
797
+ fill: "none",
798
+ stroke: r,
799
+ strokeWidth: e.stroke.labelWire,
800
+ opacity: i
801
+ } : {
802
+ fill: n,
803
+ stroke: "none",
804
+ strokeWidth: 0,
805
+ opacity: 1
806
+ } : e.textStyle === "wireframe" ? {
807
+ fill: "none",
808
+ stroke: B(e.textColor, t.labelFill),
809
+ strokeWidth: e.stroke.labelWire,
810
+ opacity: i
811
+ } : {
812
+ fill: B(e.textColor, t.labelFill),
813
+ stroke: "none",
814
+ strokeWidth: 0,
815
+ opacity: i
816
+ };
817
+ }
818
+ function W(e) {
819
+ return JSON.stringify(e);
820
+ }
821
+ //#endregion
822
+ //#region src/squircle/codeExport.ts
823
+ function ee({ layers: e, theme: t, componentName: n = "CustomSquircle", importPath: r = "./squircle", ariaLabel: i }) {
824
+ let a = re(n), o = JSON.stringify(r), s = JSON.stringify(i ?? `${a} composition`), c = JSON.stringify(e.map(G), null, 2);
825
+ return [
826
+ `import { SquircleScene, type SquircleLayerConfig, type SquircleTheme } from ${o};`,
827
+ "",
828
+ `const theme: SquircleTheme = ${JSON.stringify(t)};`,
829
+ "",
830
+ `const layers: SquircleLayerConfig[] = ${c};`,
831
+ "",
832
+ `export function ${a}() {`,
833
+ " return (",
834
+ " <SquircleScene",
835
+ " theme={theme}",
836
+ " layers={layers}",
837
+ ` ariaLabel={${s}}`,
838
+ " />",
839
+ " );",
840
+ "}",
841
+ ""
842
+ ].join("\n");
843
+ }
844
+ function G(e) {
845
+ return ne({
846
+ ...e,
847
+ base: K(e.base),
848
+ hover: e.hover ? K(e.hover) : void 0
849
+ });
850
+ }
851
+ function K(e) {
852
+ let { gpu: t, gpuStyle: n, gpuColor: r, ...i } = e, a = te(i.text, t), o = i.textStyle ?? n, s = i.textColor ?? r;
853
+ return ne({
854
+ ...i,
855
+ text: a,
856
+ textStyle: o,
857
+ textColor: s
858
+ });
859
+ }
860
+ function te(e, t) {
861
+ if (typeof e == "string") return e;
862
+ if (e === !0 || t) return "GPU";
863
+ if (e === !1) return !1;
864
+ }
865
+ function ne(e) {
866
+ return Object.fromEntries(Object.entries(e).filter(([, e]) => e !== void 0));
867
+ }
868
+ function re(e) {
869
+ let t = e.trim().split(/[^a-zA-Z0-9]+/).filter(Boolean).map((e) => e.charAt(0).toUpperCase() + e.slice(1)).join("") || "CustomSquircle";
870
+ return /^[A-Za-z_$]/.test(t) ? t : `Squircle${t}`;
871
+ }
872
+ //#endregion
873
+ //#region src/squircle/SquircleEditor.tsx
874
+ var ie = 88, ae = "GPU", oe = [
875
+ "wireframe",
876
+ "solid",
877
+ "transparent"
878
+ ];
879
+ function se(e = "15") {
880
+ return d([
881
+ {
882
+ id: "bottom",
883
+ visible: !0,
884
+ base: {
885
+ material: "wireframe",
886
+ paletteId: e
887
+ }
888
+ },
889
+ {
890
+ id: "middle",
891
+ visible: !0,
892
+ base: {
893
+ material: "wireframe",
894
+ paletteId: e
895
+ }
896
+ },
897
+ {
898
+ id: "top",
899
+ visible: !0,
900
+ base: {
901
+ material: "wireframe",
902
+ paletteId: e
903
+ }
904
+ }
905
+ ], ie);
906
+ }
907
+ function ce({ value: t, initialLayers: s, onChange: c, title: l = "Squircle", description: u = "React component constructor with 0-N layers and exported code.", className: f, layerGap: p = ie, showCode: m, showConfig: h = !0, codeComponentName: g, codeImportPath: _ = "./squircle", theme: v, defaultTheme: y = "light", onThemeChange: b, showThemeSwitch: x = !0 }) {
908
+ let [S, C] = r(() => s ?? se()), [w, T] = r(y), E = t ?? S, D = v ?? w, [O, k] = r(() => E.at(-1)?.id ?? null), [j, M] = r(!1), N = E.find((e) => e.id === O) ?? null, P = m ?? h, F = Math.max(0, ...E.map((e) => e.offset?.y ?? 0)), I = n(() => ({
909
+ layers: E,
910
+ geometry: { viewBoxHeight: Math.max(480, F + 320) },
911
+ selectedLayerId: O
912
+ }), [
913
+ E,
914
+ F,
915
+ O
916
+ ]), L = n(() => ee({
917
+ layers: E,
918
+ theme: D,
919
+ componentName: g ?? l,
920
+ importPath: _,
921
+ ariaLabel: `${l} composition`
922
+ }), [
923
+ D,
924
+ g,
925
+ _,
926
+ E,
927
+ l
928
+ ]);
929
+ e(() => {
930
+ O && E.some((e) => e.id === O) || k(E.at(-1)?.id ?? null);
931
+ }, [E, O]), e(() => {
932
+ M(!1);
933
+ }, [L]);
934
+ function R(e, n = {}) {
935
+ let r = n.reflow ? d(e, p) : e;
936
+ t || C(r), c?.(r);
937
+ }
938
+ function z(e, t) {
939
+ R(E.map((n) => n.id === e ? t(n) : n));
940
+ }
941
+ function B(e) {
942
+ N && z(N.id, (t) => ({
943
+ ...t,
944
+ base: {
945
+ ...t.base,
946
+ ...e
947
+ }
948
+ }));
949
+ }
950
+ function V(e) {
951
+ N && z(N.id, (t) => ({
952
+ ...t,
953
+ hover: {
954
+ ...t.hover ?? t.base,
955
+ ...e
956
+ }
957
+ }));
958
+ }
959
+ function H() {
960
+ let e = {
961
+ id: `layer-${E.length + 1}`,
962
+ visible: !0,
963
+ base: {
964
+ material: "wireframe",
965
+ paletteId: E.at(-1)?.base.paletteId ?? "15"
966
+ }
967
+ }, t = [...E, e];
968
+ k(e.id), R(t, { reflow: !0 });
969
+ }
970
+ function U() {
971
+ if (!N) return;
972
+ let e = E.filter((e) => e.id !== N.id);
973
+ k(e.at(-1)?.id ?? null), R(e, { reflow: !0 });
974
+ }
975
+ function W(e) {
976
+ z(e, (e) => ({
977
+ ...e,
978
+ visible: e.visible === !1
979
+ }));
980
+ }
981
+ function G(e) {
982
+ v || T(e), b?.(e);
983
+ }
984
+ async function K() {
985
+ try {
986
+ await navigator.clipboard.writeText(L);
987
+ } catch {
988
+ let e = document.createElement("textarea");
989
+ e.value = L, e.setAttribute("readonly", ""), e.style.position = "fixed", e.style.top = "-9999px", document.body.append(e), e.select(), document.execCommand("copy"), e.remove();
990
+ }
991
+ M(!0), window.setTimeout(() => M(!1), 1400);
992
+ }
993
+ return /* @__PURE__ */ o("main", {
994
+ className: [
995
+ "squircle-editor",
996
+ `squircle-editor-${D}`,
997
+ f
998
+ ].filter(Boolean).join(" "),
999
+ "data-theme": D,
1000
+ "aria-label": "Squircle editor",
1001
+ children: [/* @__PURE__ */ o("header", {
1002
+ className: "squircle-editor-topbar",
1003
+ children: [/* @__PURE__ */ o("div", { children: [/* @__PURE__ */ a("h1", { children: l }), /* @__PURE__ */ a("p", { children: u })] }), /* @__PURE__ */ o("div", {
1004
+ className: "topbar-actions",
1005
+ children: [
1006
+ x ? /* @__PURE__ */ o("div", {
1007
+ className: "theme-switch",
1008
+ role: "group",
1009
+ "aria-label": "Theme",
1010
+ children: [/* @__PURE__ */ a("button", {
1011
+ type: "button",
1012
+ "aria-pressed": D === "light",
1013
+ onClick: () => G("light"),
1014
+ children: "Light"
1015
+ }), /* @__PURE__ */ a("button", {
1016
+ type: "button",
1017
+ "aria-pressed": D === "dark",
1018
+ onClick: () => G("dark"),
1019
+ children: "Dark"
1020
+ })]
1021
+ }) : null,
1022
+ /* @__PURE__ */ a("button", {
1023
+ type: "button",
1024
+ onClick: H,
1025
+ children: "Add layer"
1026
+ }),
1027
+ /* @__PURE__ */ a("button", {
1028
+ type: "button",
1029
+ onClick: () => R([]),
1030
+ children: "Clear"
1031
+ })
1032
+ ]
1033
+ })]
1034
+ }), /* @__PURE__ */ o("section", {
1035
+ className: "squircle-editor-workspace",
1036
+ children: [
1037
+ /* @__PURE__ */ o("aside", {
1038
+ className: "side-panel",
1039
+ children: [/* @__PURE__ */ o("div", {
1040
+ className: "panel-heading",
1041
+ children: [/* @__PURE__ */ a("h2", { children: "Layers" }), /* @__PURE__ */ a("span", { children: E.length })]
1042
+ }), /* @__PURE__ */ a("div", {
1043
+ className: "squircle-editor-layer-list",
1044
+ children: [...E].reverse().map((e, t) => {
1045
+ let n = E.length - t;
1046
+ return /* @__PURE__ */ o("div", {
1047
+ className: "squircle-editor-layer-row",
1048
+ children: [/* @__PURE__ */ o("button", {
1049
+ type: "button",
1050
+ className: e.id === O ? "layer-select is-active" : "layer-select",
1051
+ onClick: () => k(e.id),
1052
+ children: [/* @__PURE__ */ a("strong", { children: n === E.length ? "Top" : n === 1 ? "Bottom" : `Layer ${n}` }), /* @__PURE__ */ a("span", { children: fe(e.base) })]
1053
+ }), /* @__PURE__ */ a("button", {
1054
+ type: "button",
1055
+ className: "icon-text",
1056
+ "aria-pressed": e.visible !== !1,
1057
+ onClick: () => W(e.id),
1058
+ children: e.visible === !1 ? "Show" : "Hide"
1059
+ })]
1060
+ }, e.id);
1061
+ })
1062
+ })]
1063
+ }),
1064
+ /* @__PURE__ */ o("section", {
1065
+ className: "squircle-editor-preview",
1066
+ children: [/* @__PURE__ */ a(A, {
1067
+ ...I,
1068
+ theme: D,
1069
+ ariaLabel: "Editable squircle composition",
1070
+ onLayerSelect: k
1071
+ }), P ? /* @__PURE__ */ o("section", {
1072
+ className: "code-panel",
1073
+ "aria-label": "Generated React code",
1074
+ children: [/* @__PURE__ */ o("header", {
1075
+ className: "code-panel-header",
1076
+ children: [/* @__PURE__ */ o("div", { children: [/* @__PURE__ */ a("h2", { children: "Code" }), /* @__PURE__ */ a("p", { children: "Copy a ready-to-use React component." })] }), /* @__PURE__ */ o("button", {
1077
+ type: "button",
1078
+ className: "copy-code-button",
1079
+ "aria-label": "Copy React code",
1080
+ title: "Copy React code",
1081
+ onClick: K,
1082
+ children: [/* @__PURE__ */ a(de, {}), /* @__PURE__ */ a("span", {
1083
+ className: "copy-status",
1084
+ "aria-live": "polite",
1085
+ children: j ? "Copied" : ""
1086
+ })]
1087
+ })]
1088
+ }), /* @__PURE__ */ a("pre", {
1089
+ className: "code-output",
1090
+ children: /* @__PURE__ */ a("code", { children: L })
1091
+ })]
1092
+ }) : null]
1093
+ }),
1094
+ /* @__PURE__ */ a("aside", {
1095
+ className: N ? "side-panel inspector-panel" : "side-panel inspector-panel is-empty",
1096
+ children: N ? /* @__PURE__ */ o(i, { children: [
1097
+ /* @__PURE__ */ o("div", {
1098
+ className: "panel-heading",
1099
+ children: [/* @__PURE__ */ a("h2", { children: N.id }), /* @__PURE__ */ a("button", {
1100
+ type: "button",
1101
+ className: "icon-text danger",
1102
+ onClick: U,
1103
+ children: "Delete"
1104
+ })]
1105
+ }),
1106
+ /* @__PURE__ */ o(q, {
1107
+ title: "Base",
1108
+ children: [
1109
+ /* @__PURE__ */ a(J, {
1110
+ label: "Material",
1111
+ value: N.base.material ?? "wireframe",
1112
+ options: oe,
1113
+ onChange: (e) => B({ material: e })
1114
+ }),
1115
+ /* @__PURE__ */ a(le, {
1116
+ value: N.base.paletteId ?? "15",
1117
+ onChange: (e) => B({ paletteId: e })
1118
+ }),
1119
+ /* @__PURE__ */ a(Y, {
1120
+ label: "Text",
1121
+ checked: Z(N.base),
1122
+ onChange: (e) => B({ text: e ? Q(N.base) : !1 })
1123
+ }),
1124
+ Z(N.base) ? /* @__PURE__ */ a(ue, {
1125
+ label: "Text",
1126
+ value: Q(N.base),
1127
+ onChange: (e) => B({ text: e })
1128
+ }) : null,
1129
+ /* @__PURE__ */ a(Y, {
1130
+ label: "Dash",
1131
+ checked: N.base.dash ?? !1,
1132
+ onChange: (e) => B({ dash: e })
1133
+ }),
1134
+ /* @__PURE__ */ a(J, {
1135
+ label: "Text paint",
1136
+ value: pe(N.base),
1137
+ options: ["solid", "wireframe"],
1138
+ onChange: (e) => B({ textStyle: e })
1139
+ })
1140
+ ]
1141
+ }),
1142
+ /* @__PURE__ */ o(q, {
1143
+ title: "Hover",
1144
+ children: [/* @__PURE__ */ a(Y, {
1145
+ label: "Enabled",
1146
+ checked: !!N.hover,
1147
+ onChange: (e) => {
1148
+ z(N.id, (t) => ({
1149
+ ...t,
1150
+ hover: e ? {
1151
+ ...t.base,
1152
+ material: t.base.material === "wireframe" ? "solid" : "wireframe"
1153
+ } : void 0
1154
+ }));
1155
+ }
1156
+ }), N.hover ? /* @__PURE__ */ o(i, { children: [/* @__PURE__ */ a(J, {
1157
+ label: "Material",
1158
+ value: N.hover.material ?? N.base.material ?? "wireframe",
1159
+ options: oe,
1160
+ onChange: (e) => V({ material: e })
1161
+ }), /* @__PURE__ */ a(le, {
1162
+ value: N.hover.paletteId ?? N.base.paletteId ?? "15",
1163
+ onChange: (e) => V({ paletteId: e })
1164
+ })] }) : null]
1165
+ }),
1166
+ /* @__PURE__ */ o(q, {
1167
+ title: "Stroke Widths",
1168
+ children: [
1169
+ /* @__PURE__ */ a(X, {
1170
+ label: "Face",
1171
+ value: N.stroke?.face ?? .35,
1172
+ min: 0,
1173
+ max: 1.5,
1174
+ step: .05,
1175
+ onChange: (e) => z(N.id, (t) => ({
1176
+ ...t,
1177
+ stroke: {
1178
+ ...t.stroke,
1179
+ face: e
1180
+ }
1181
+ }))
1182
+ }),
1183
+ /* @__PURE__ */ a(X, {
1184
+ label: "Wire",
1185
+ value: N.stroke?.wire ?? 1.6,
1186
+ min: .4,
1187
+ max: 4,
1188
+ step: .1,
1189
+ onChange: (e) => z(N.id, (t) => ({
1190
+ ...t,
1191
+ stroke: {
1192
+ ...t.stroke,
1193
+ wire: e
1194
+ }
1195
+ }))
1196
+ }),
1197
+ /* @__PURE__ */ a(X, {
1198
+ label: "Dash",
1199
+ value: N.stroke?.dash ?? 2.2,
1200
+ min: .6,
1201
+ max: 5,
1202
+ step: .1,
1203
+ onChange: (e) => z(N.id, (t) => ({
1204
+ ...t,
1205
+ stroke: {
1206
+ ...t.stroke,
1207
+ dash: e
1208
+ }
1209
+ }))
1210
+ }),
1211
+ /* @__PURE__ */ a(X, {
1212
+ label: "Text outline",
1213
+ value: N.stroke?.labelWire ?? 1.1,
1214
+ min: .4,
1215
+ max: 2,
1216
+ step: .05,
1217
+ onChange: (e) => z(N.id, (t) => ({
1218
+ ...t,
1219
+ stroke: {
1220
+ ...t.stroke,
1221
+ labelWire: e
1222
+ }
1223
+ }))
1224
+ })
1225
+ ]
1226
+ })
1227
+ ] }) : /* @__PURE__ */ a("p", {
1228
+ className: "empty-note",
1229
+ children: "Select a layer in the list or preview."
1230
+ })
1231
+ })
1232
+ ]
1233
+ })]
1234
+ });
1235
+ }
1236
+ function q({ title: e, children: t }) {
1237
+ return /* @__PURE__ */ o("section", {
1238
+ className: "editor-section",
1239
+ children: [/* @__PURE__ */ a("h3", { children: e }), t]
1240
+ });
1241
+ }
1242
+ function J({ label: e, value: t, options: n, onChange: r }) {
1243
+ return /* @__PURE__ */ o("label", {
1244
+ className: "field",
1245
+ children: [/* @__PURE__ */ a("span", { children: e }), /* @__PURE__ */ a("select", {
1246
+ value: t,
1247
+ onChange: (e) => r(e.target.value),
1248
+ children: n.map((e) => /* @__PURE__ */ a("option", {
1249
+ value: e,
1250
+ children: e
1251
+ }, e))
1252
+ })]
1253
+ });
1254
+ }
1255
+ function le({ value: e, onChange: t }) {
1256
+ return /* @__PURE__ */ o("label", {
1257
+ className: "field",
1258
+ children: [/* @__PURE__ */ a("span", { children: "Palette" }), /* @__PURE__ */ a("select", {
1259
+ value: e,
1260
+ onChange: (e) => t(e.target.value),
1261
+ children: x.map((e) => /* @__PURE__ */ a("option", {
1262
+ value: e,
1263
+ children: b[e].label
1264
+ }, e))
1265
+ })]
1266
+ });
1267
+ }
1268
+ function Y({ label: e, checked: t, onChange: n }) {
1269
+ return /* @__PURE__ */ o("label", {
1270
+ className: "toggle-field",
1271
+ children: [/* @__PURE__ */ a("input", {
1272
+ type: "checkbox",
1273
+ checked: t,
1274
+ onChange: (e) => n(e.target.checked)
1275
+ }), /* @__PURE__ */ a("span", { children: e })]
1276
+ });
1277
+ }
1278
+ function ue({ label: e, value: t, onChange: n }) {
1279
+ return /* @__PURE__ */ o("label", {
1280
+ className: "field",
1281
+ children: [/* @__PURE__ */ a("span", { children: e }), /* @__PURE__ */ a("input", {
1282
+ type: "text",
1283
+ value: t,
1284
+ onChange: (e) => n(e.target.value)
1285
+ })]
1286
+ });
1287
+ }
1288
+ function X({ label: e, value: t, min: n, max: r, step: i, onChange: s }) {
1289
+ return /* @__PURE__ */ o("label", {
1290
+ className: "field",
1291
+ children: [/* @__PURE__ */ o("span", { children: [
1292
+ e,
1293
+ ": ",
1294
+ t.toFixed(2)
1295
+ ] }), /* @__PURE__ */ a("input", {
1296
+ type: "range",
1297
+ min: n,
1298
+ max: r,
1299
+ step: i,
1300
+ value: t,
1301
+ onChange: (e) => s(Number(e.target.value))
1302
+ })]
1303
+ });
1304
+ }
1305
+ function de() {
1306
+ return /* @__PURE__ */ o("svg", {
1307
+ className: "copy-icon",
1308
+ viewBox: "0 0 24 24",
1309
+ "aria-hidden": "true",
1310
+ focusable: "false",
1311
+ children: [/* @__PURE__ */ a("rect", {
1312
+ x: "9",
1313
+ y: "9",
1314
+ width: "11",
1315
+ height: "11",
1316
+ rx: "2"
1317
+ }), /* @__PURE__ */ a("path", { d: "M5 15V6.8C5 5.8 5.8 5 6.8 5H15" })]
1318
+ });
1319
+ }
1320
+ function fe(e) {
1321
+ let t = [e.material ?? "wireframe", e.paletteId ?? "15"];
1322
+ return Z(e) && t.push(`text: ${Q(e)}`), e.dash && t.push("dash"), t.join(" / ");
1323
+ }
1324
+ function Z(e) {
1325
+ return typeof e.text == "string" ? e.text.trim().length > 0 : e.text === !0 || $(e).gpu === !0;
1326
+ }
1327
+ function Q(e) {
1328
+ return typeof e.text == "string" ? e.text : (e.text === !0 || $(e).gpu, ae);
1329
+ }
1330
+ function pe(e) {
1331
+ return e.textStyle ?? $(e).gpuStyle ?? "solid";
1332
+ }
1333
+ function $(e) {
1334
+ return e;
1335
+ }
1336
+ //#endregion
1337
+ export { s as DEFAULT_GEOMETRY, S as DEFAULT_PALETTE_ID, b as SQUIRCLE_PALETTES, x as SQUIRCLE_PALETTE_IDS, ce as SquircleEditor, A as SquircleScene, se as createDefaultSquircleEditorLayers, c as createSquircleGeometry, u as createSquircleLayers, ee as createSquircleReactCode, C as getSquirclePalette, d as reflowLayerOffsets, re as toComponentName };
1338
+
1339
+ //# sourceMappingURL=sqircle.js.map