patternl 0.0.1 → 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.
package/dist/index.mjs ADDED
@@ -0,0 +1,1754 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+
21
+ // src/lib/defaults.ts
22
+ function centerColumnZone(width) {
23
+ return { x: 0.5 - width / 2, y: 0, width, height: 1 };
24
+ }
25
+ var DEFAULT_CONFIG = {
26
+ canvas: { width: 800, height: 800, background: "#ffffff" },
27
+ sources: [],
28
+ sourceDistribution: "sequential",
29
+ sourceSeed: 1,
30
+ arrangement: { type: "grid", repeatX: 5, repeatY: 5, gapX: 0, gapY: 0, gridRotation: 0 },
31
+ scale: { min: 1, max: 1, step: { mode: "fixed" } },
32
+ opacity: { min: 1, max: 1, step: { mode: "fixed" } },
33
+ rotation: { min: 0, max: 0, step: { mode: "fixed" } },
34
+ color: null,
35
+ jitter: { position: 0, rotation: 0, scale: 0, seed: 1 },
36
+ distanceFalloff: { scaleEnd: 1, opacityEnd: 1 },
37
+ maxCopies: 200
38
+ };
39
+ function defaultArrangement(type) {
40
+ switch (type) {
41
+ case "grid":
42
+ return { type: "grid", repeatX: 5, repeatY: 5, gapX: 0, gapY: 0, gridRotation: 0 };
43
+ case "brick":
44
+ return { type: "brick", repeatX: 6, repeatY: 5, gapX: 4, gapY: 4, staggerOffset: 0.5, staggerAxis: "row" };
45
+ case "hex":
46
+ return { type: "hex", countAcross: 6, spacing: 80, orientation: "pointy" };
47
+ case "radial":
48
+ return { type: "radial", count: 8, radius: 250, startAngle: 0, arc: 360, faceOutward: true, mirrorAlternate: false };
49
+ case "concentric":
50
+ return { type: "concentric", rings: 3, copiesPerRing: 6, ringScaling: "proportional", ringGap: 80, innerRadius: 60, faceOutward: true, scalePerRing: 1 };
51
+ case "spiral":
52
+ return { type: "spiral", count: 20, innerRadius: 30, outerRadius: 320, turns: 2, faceOutward: true };
53
+ case "mirror":
54
+ return { type: "mirror", axes: 6, reflect: true, radius: 250 };
55
+ case "scatter":
56
+ return { type: "scatter", count: 40, minSize: 30, maxSize: 160, sizeBias: 2, gap: 24, blur: 0, seed: 1, clearZones: [] };
57
+ case "focal":
58
+ return {
59
+ type: "focal",
60
+ focus: { x: 0.84, y: 0.72, size: 700, rotation: -12, opacity: 0.25, blur: 0 },
61
+ satellites: { count: 7, minSize: 50, maxSize: 150, sizeBias: 1, gap: 40, blur: 2, seed: 1 },
62
+ clearZones: [centerColumnZone(0.3)]
63
+ };
64
+ default:
65
+ return { type: "grid", repeatX: 5, repeatY: 5, gapX: 0, gapY: 0, gridRotation: 0 };
66
+ }
67
+ }
68
+ var PRESETS = {
69
+ wallpaper: {
70
+ label: "Wallpaper",
71
+ config: { arrangement: { type: "grid", repeatX: 6, repeatY: 6, gapX: 0, gapY: 0, gridRotation: 0 } }
72
+ },
73
+ brickWall: {
74
+ label: "Brick Wall",
75
+ config: { arrangement: { type: "brick", repeatX: 8, repeatY: 6, gapX: 4, gapY: 4, staggerOffset: 0.5, staggerAxis: "row" } }
76
+ },
77
+ honeycomb: {
78
+ label: "Honeycomb",
79
+ config: { arrangement: { type: "hex", countAcross: 8, spacing: 70, orientation: "pointy" } }
80
+ },
81
+ radialBurst: {
82
+ label: "Radial Burst",
83
+ config: { arrangement: { type: "radial", count: 12, radius: 280, startAngle: 0, arc: 360, faceOutward: true, mirrorAlternate: false } }
84
+ },
85
+ snowflake: {
86
+ label: "Snowflake",
87
+ config: { arrangement: { type: "mirror", axes: 6, reflect: true, radius: 250 } }
88
+ },
89
+ mandala: {
90
+ label: "Mandala",
91
+ config: { arrangement: { type: "concentric", rings: 4, copiesPerRing: 8, ringScaling: "proportional", ringGap: 70, innerRadius: 50, faceOutward: true, scalePerRing: 0.85 } }
92
+ },
93
+ spiral: {
94
+ label: "Spiral",
95
+ config: { arrangement: { type: "spiral", count: 28, innerRadius: 20, outerRadius: 360, turns: 2.5, faceOutward: true } }
96
+ },
97
+ diamond: {
98
+ label: "Diamond Grid",
99
+ config: {
100
+ arrangement: { type: "grid", repeatX: 5, repeatY: 5, gapX: 12, gapY: 12, gridRotation: 0 },
101
+ rotation: { min: 45, max: 45, step: { mode: "fixed" } }
102
+ }
103
+ },
104
+ kaleidoscope: {
105
+ label: "Kaleidoscope",
106
+ config: { arrangement: { type: "mirror", axes: 8, reflect: true, radius: 300 } }
107
+ },
108
+ jitteredGrid: {
109
+ label: "Jittered Grid",
110
+ config: {
111
+ arrangement: { type: "grid", repeatX: 5, repeatY: 5, gapX: 0, gapY: 0, gridRotation: 0 },
112
+ jitter: { position: 60, rotation: 180, scale: 0.4, seed: 42 },
113
+ rotation: { min: 0, max: 360, step: { mode: "random", seed: 7 } }
114
+ }
115
+ },
116
+ scatter: {
117
+ label: "Scatter",
118
+ config: {
119
+ arrangement: defaultArrangement("scatter"),
120
+ scale: { min: 1, max: 1, step: { mode: "fixed" } },
121
+ rotation: { min: -30, max: 30, step: { mode: "random", seed: 7 } },
122
+ opacity: { min: 0.35, max: 1, step: { mode: "random", seed: 3 } }
123
+ }
124
+ },
125
+ splash: {
126
+ label: "Splash",
127
+ config: {
128
+ arrangement: defaultArrangement("focal"),
129
+ scale: { min: 1, max: 1, step: { mode: "fixed" } },
130
+ rotation: { min: -25, max: 25, step: { mode: "random", seed: 7 } },
131
+ opacity: { min: 0.1, max: 0.25, step: { mode: "random", seed: 3 } }
132
+ }
133
+ }
134
+ };
135
+
136
+ // src/lib/engine/seeder.ts
137
+ function seededHash(index, salt, seed) {
138
+ let h = (index + salt * 7919 + seed * 104729) * 2654435761 >>> 0;
139
+ h = (h ^ h >>> 16) * 73244475 >>> 0;
140
+ h = (h ^ h >>> 13) >>> 0;
141
+ return h;
142
+ }
143
+ function seededFloat01(index, salt, seed) {
144
+ return seededHash(index, salt, seed) / 4294967295;
145
+ }
146
+ function seededFloat(index, salt, seed) {
147
+ return seededHash(index, salt, seed) / 2147483647 * 2 - 1;
148
+ }
149
+ function seededIndex(index, count, seed) {
150
+ return seededHash(index, 0, seed) % count;
151
+ }
152
+
153
+ // src/lib/engine/layout.ts
154
+ function stepNumeric(range, index, total) {
155
+ const { min, max, step } = range;
156
+ switch (step.mode) {
157
+ case "fixed":
158
+ return min;
159
+ case "sequence": {
160
+ const v = min + index * step.amount;
161
+ return max >= min ? Math.min(max, Math.max(min, v)) : Math.max(max, Math.min(min, v));
162
+ }
163
+ case "grade": {
164
+ if (step.steps <= 1) return min;
165
+ const t = index % step.steps / (step.steps - 1);
166
+ return min + t * (max - min);
167
+ }
168
+ case "random": {
169
+ const t = seededFloat01(index, 99, step.seed);
170
+ return min + t * (max - min);
171
+ }
172
+ }
173
+ }
174
+ function stepColor(colors, mode, index) {
175
+ if (colors.length === 0) return "";
176
+ if (mode.mode === "sequence") return colors[index % colors.length];
177
+ return colors[seededIndex(index, colors.length, mode.seed)];
178
+ }
179
+ function makeCopy(index, x, y, rotation = 0, mirrorX = false) {
180
+ return { index, x, y, rotation, mirrorX, scaleMultiplier: 1, opacityMultiplier: 1, blur: 0, fixedStyle: false };
181
+ }
182
+ function computeGrid(arr, w, h) {
183
+ const copies = [];
184
+ const cols = Math.max(1, arr.repeatX);
185
+ const rows = Math.max(1, arr.repeatY);
186
+ const cellW = (w - arr.gapX * (cols - 1)) / cols;
187
+ const cellH = (h - arr.gapY * (rows - 1)) / rows;
188
+ const cx = w / 2, cy = h / 2;
189
+ const rotRad = arr.gridRotation * Math.PI / 180;
190
+ const cosR = Math.cos(rotRad), sinR = Math.sin(rotRad);
191
+ let idx = 0;
192
+ for (let r = 0; r < rows; r++) {
193
+ for (let c = 0; c < cols; c++) {
194
+ let x = cellW / 2 + c * (cellW + arr.gapX);
195
+ let y = cellH / 2 + r * (cellH + arr.gapY);
196
+ if (arr.gridRotation !== 0) {
197
+ const dx = x - cx, dy = y - cy;
198
+ x = cx + dx * cosR - dy * sinR;
199
+ y = cy + dx * sinR + dy * cosR;
200
+ }
201
+ copies.push(makeCopy(idx++, x, y));
202
+ }
203
+ }
204
+ return copies;
205
+ }
206
+ function computeBrick(arr, w, h) {
207
+ const copies = [];
208
+ const cols = Math.max(1, arr.repeatX);
209
+ const rows = Math.max(1, arr.repeatY);
210
+ const cellW = (w - arr.gapX * (cols - 1)) / cols;
211
+ const cellH = (h - arr.gapY * (rows - 1)) / rows;
212
+ let idx = 0;
213
+ for (let r = 0; r < rows; r++) {
214
+ for (let c = 0; c < cols; c++) {
215
+ let x = cellW / 2 + c * (cellW + arr.gapX);
216
+ let y = cellH / 2 + r * (cellH + arr.gapY);
217
+ if (arr.staggerAxis === "row" && r % 2 === 1) x += (cellW + arr.gapX) * arr.staggerOffset;
218
+ else if (arr.staggerAxis === "column" && c % 2 === 1) y += (cellH + arr.gapY) * arr.staggerOffset;
219
+ copies.push(makeCopy(idx++, x, y));
220
+ }
221
+ }
222
+ return copies;
223
+ }
224
+ function computeHex(arr, w, h) {
225
+ const copies = [];
226
+ const spacing = Math.max(1, arr.spacing);
227
+ const countAcross = Math.max(1, arr.countAcross);
228
+ const isFlat = arr.orientation === "flat";
229
+ const rowH = isFlat ? spacing * Math.sqrt(3) / 2 : spacing * 0.75;
230
+ const colW = isFlat ? spacing * 0.75 : spacing * Math.sqrt(3) / 2;
231
+ const rows = Math.ceil(h / rowH) + 1;
232
+ const cols = Math.min(countAcross, Math.ceil(w / colW) + 1);
233
+ const totalW = (cols - 1) * colW;
234
+ const totalH = (rows - 1) * rowH;
235
+ const offX = (w - totalW) / 2;
236
+ const offY = (h - totalH) / 2;
237
+ let idx = 0;
238
+ for (let r = 0; r < rows; r++) {
239
+ for (let c = 0; c < cols; c++) {
240
+ let x = offX + c * colW;
241
+ let y = offY + r * rowH;
242
+ if (isFlat) {
243
+ if (c % 2 === 1) y += rowH / 2;
244
+ } else {
245
+ if (r % 2 === 1) x += colW / 2;
246
+ }
247
+ copies.push(makeCopy(idx++, x, y));
248
+ }
249
+ }
250
+ return copies;
251
+ }
252
+ function computeRadial(arr, w, h) {
253
+ const copies = [];
254
+ const cx = w / 2, cy = h / 2;
255
+ const count = Math.max(1, arr.count);
256
+ const arcRad = arr.arc * Math.PI / 180;
257
+ const startRad = arr.startAngle * Math.PI / 180;
258
+ for (let i = 0; i < count; i++) {
259
+ const t = count === 1 ? 0 : i / (arr.arc >= 360 ? count : count - 1);
260
+ const angle = startRad + t * arcRad;
261
+ const x = cx + Math.cos(angle) * arr.radius;
262
+ const y = cy + Math.sin(angle) * arr.radius;
263
+ const rot = arr.faceOutward ? angle * 180 / Math.PI + 90 : 0;
264
+ const mirror = arr.mirrorAlternate && i % 2 === 1;
265
+ copies.push(makeCopy(i, x, y, rot, mirror));
266
+ }
267
+ return copies;
268
+ }
269
+ function computeConcentric(arr, w, h) {
270
+ const copies = [];
271
+ const cx = w / 2, cy = h / 2;
272
+ let idx = 0;
273
+ for (let ring = 0; ring < arr.rings; ring++) {
274
+ const radius = arr.innerRadius + ring * arr.ringGap;
275
+ const count = arr.ringScaling === "proportional" ? Math.round(arr.copiesPerRing * (ring + 1)) : arr.copiesPerRing;
276
+ const scaleMul = Math.pow(arr.scalePerRing, ring);
277
+ for (let i = 0; i < count; i++) {
278
+ const angle = i / count * Math.PI * 2;
279
+ const x = cx + Math.cos(angle) * radius;
280
+ const y = cy + Math.sin(angle) * radius;
281
+ const rot = arr.faceOutward ? angle * 180 / Math.PI + 90 : 0;
282
+ const copy = makeCopy(idx++, x, y, rot);
283
+ copy.scaleMultiplier = scaleMul;
284
+ copies.push(copy);
285
+ }
286
+ }
287
+ return copies;
288
+ }
289
+ function computeSpiral(arr, w, h) {
290
+ const copies = [];
291
+ const cx = w / 2, cy = h / 2;
292
+ const count = Math.max(1, arr.count);
293
+ const totalAngle = arr.turns * Math.PI * 2;
294
+ for (let i = 0; i < count; i++) {
295
+ const t = count === 1 ? 0 : i / (count - 1);
296
+ const angle = t * totalAngle;
297
+ const radius = arr.innerRadius + t * (arr.outerRadius - arr.innerRadius);
298
+ const x = cx + Math.cos(angle) * radius;
299
+ const y = cy + Math.sin(angle) * radius;
300
+ let rot = 0;
301
+ if (arr.faceOutward) {
302
+ const dr = (arr.outerRadius - arr.innerRadius) / (count - 1 || 1);
303
+ const dtheta = totalAngle / (count - 1 || 1);
304
+ rot = (angle + Math.atan2(dr, radius * dtheta)) * 180 / Math.PI;
305
+ }
306
+ copies.push(makeCopy(i, x, y, rot));
307
+ }
308
+ return copies;
309
+ }
310
+ function computeMirror(arr, w, h) {
311
+ const copies = [];
312
+ const cx = w / 2, cy = h / 2;
313
+ const axes = Math.max(2, arr.axes);
314
+ const total = arr.reflect ? axes * 2 : axes;
315
+ const angleStep = Math.PI * 2 / total;
316
+ for (let i = 0; i < total; i++) {
317
+ const angle = i * angleStep;
318
+ const x = cx + Math.cos(angle) * arr.radius;
319
+ const y = cy + Math.sin(angle) * arr.radius;
320
+ const rot = angle * 180 / Math.PI;
321
+ const mirror = arr.reflect && i % 2 === 1;
322
+ copies.push(makeCopy(i, x, y, rot, mirror));
323
+ }
324
+ return copies;
325
+ }
326
+ function hitsZone(x, y, r, zone, w, h) {
327
+ const zx = zone.x * w, zy = zone.y * h;
328
+ const nx = Math.max(zx, Math.min(x, zx + zone.width * w));
329
+ const ny = Math.max(zy, Math.min(y, zy + zone.height * h));
330
+ return Math.hypot(x - nx, y - ny) < r;
331
+ }
332
+ function placeScatter(p, w, h, baseSize, opts) {
333
+ const lo = Math.max(1, Math.min(p.minSize, p.maxSize));
334
+ const hi = Math.max(lo, p.maxSize);
335
+ const bias = Math.max(0.1, p.sizeBias);
336
+ const placed = [...opts.avoid];
337
+ const copies = [];
338
+ const maxTries = Math.min(2e4, Math.max(500, p.count * 300));
339
+ const dist = (a, x, y) => {
340
+ let dx = Math.abs(a.x - x), dy = Math.abs(a.y - y);
341
+ if (opts.wrap) {
342
+ dx = Math.min(dx, w - dx);
343
+ dy = Math.min(dy, h - dy);
344
+ }
345
+ return Math.hypot(dx, dy);
346
+ };
347
+ for (let t = 0; t < maxTries && copies.length < p.count; t++) {
348
+ const size = lo + (hi - lo) * Math.pow(seededFloat01(t, 11, p.seed), bias);
349
+ const x = seededFloat01(t, 12, p.seed) * w;
350
+ const y = seededFloat01(t, 13, p.seed) * h;
351
+ if (opts.clearZones.some((z) => hitsZone(x, y, size / 2, z, w, h))) continue;
352
+ if (placed.some((d) => dist(d, x, y) < (d.size + size) / 2 + p.gap)) continue;
353
+ placed.push({ x, y, size });
354
+ const copy = makeCopy(opts.startIndex + copies.length, x, y);
355
+ copy.scaleMultiplier = size / baseSize;
356
+ copy.blur = p.blur;
357
+ copies.push(copy);
358
+ }
359
+ return copies;
360
+ }
361
+ function computeScatter(arr, w, h, baseSize) {
362
+ return placeScatter(arr, w, h, baseSize, { wrap: true, avoid: [], clearZones: arr.clearZones, startIndex: 0 });
363
+ }
364
+ function computeFocal(arr, w, h, baseSize) {
365
+ const f = arr.focus;
366
+ const focus = makeCopy(0, f.x * w, f.y * h, f.rotation);
367
+ focus.scaleMultiplier = f.size / baseSize;
368
+ focus.opacityMultiplier = f.opacity;
369
+ focus.blur = f.blur;
370
+ focus.fixedStyle = true;
371
+ const satellites = placeScatter(arr.satellites, w, h, baseSize, {
372
+ wrap: false,
373
+ avoid: [{ x: focus.x, y: focus.y, size: f.size }],
374
+ clearZones: arr.clearZones,
375
+ startIndex: 1
376
+ });
377
+ return [focus, ...satellites];
378
+ }
379
+ function baseSourceSize(config) {
380
+ const sides = config.sources.map((s) => Math.max(s.spriteWidth, s.spriteHeight));
381
+ return sides.length ? Math.max(...sides) : 200;
382
+ }
383
+ function resolveCopyStyle(config, copy, total) {
384
+ if (copy.fixedStyle) {
385
+ return { scale: copy.scaleMultiplier, opacity: copy.opacityMultiplier, rotation: copy.rotation };
386
+ }
387
+ return {
388
+ scale: stepNumeric(config.scale, copy.index, total) * copy.scaleMultiplier,
389
+ opacity: stepNumeric(config.opacity, copy.index, total) * copy.opacityMultiplier,
390
+ rotation: stepNumeric(config.rotation, copy.index, total) + copy.rotation
391
+ };
392
+ }
393
+ function isTileable(config) {
394
+ return config.arrangement.type !== "focal";
395
+ }
396
+ function applyDistanceFalloff(copies, w, h, scaleEnd, opacityEnd) {
397
+ const cx = w / 2, cy = h / 2;
398
+ let maxDist = 0;
399
+ for (const c of copies) {
400
+ const d = Math.sqrt((c.x - cx) ** 2 + (c.y - cy) ** 2);
401
+ if (d > maxDist) maxDist = d;
402
+ }
403
+ if (maxDist <= 0) return;
404
+ for (const c of copies) {
405
+ if (c.fixedStyle) continue;
406
+ const t = Math.sqrt((c.x - cx) ** 2 + (c.y - cy) ** 2) / maxDist;
407
+ c.scaleMultiplier *= 1 + (scaleEnd - 1) * t;
408
+ c.opacityMultiplier *= 1 + (opacityEnd - 1) * t;
409
+ }
410
+ }
411
+ function applyJitter(copies, jitter) {
412
+ const { position, rotation, scale, seed } = jitter;
413
+ for (const c of copies) {
414
+ if (c.fixedStyle) continue;
415
+ if (position > 0) {
416
+ c.x += seededFloat(c.index, 3, seed) * position;
417
+ c.y += seededFloat(c.index, 4, seed) * position;
418
+ }
419
+ if (rotation > 0) {
420
+ c.rotation += seededFloat(c.index, 2, seed) * rotation;
421
+ }
422
+ if (scale > 0) {
423
+ c.scaleMultiplier *= 1 + seededFloat(c.index, 1, seed) * scale;
424
+ }
425
+ }
426
+ }
427
+ function computeLayout(config) {
428
+ const { arrangement: arr, canvas, distanceFalloff, maxCopies, jitter } = config;
429
+ const w = canvas.width, h = canvas.height;
430
+ let copies;
431
+ switch (arr.type) {
432
+ case "grid":
433
+ copies = computeGrid(arr, w, h);
434
+ break;
435
+ case "brick":
436
+ copies = computeBrick(arr, w, h);
437
+ break;
438
+ case "hex":
439
+ copies = computeHex(arr, w, h);
440
+ break;
441
+ case "radial":
442
+ copies = computeRadial(arr, w, h);
443
+ break;
444
+ case "concentric":
445
+ copies = computeConcentric(arr, w, h);
446
+ break;
447
+ case "spiral":
448
+ copies = computeSpiral(arr, w, h);
449
+ break;
450
+ case "mirror":
451
+ copies = computeMirror(arr, w, h);
452
+ break;
453
+ case "scatter":
454
+ copies = computeScatter(arr, w, h, baseSourceSize(config));
455
+ break;
456
+ case "focal":
457
+ copies = computeFocal(arr, w, h, baseSourceSize(config));
458
+ break;
459
+ }
460
+ if (copies.length > maxCopies) copies = copies.slice(0, maxCopies);
461
+ if (distanceFalloff.scaleEnd !== 1 || distanceFalloff.opacityEnd !== 1) {
462
+ applyDistanceFalloff(copies, w, h, distanceFalloff.scaleEnd, distanceFalloff.opacityEnd);
463
+ }
464
+ if (jitter.position > 0 || jitter.rotation > 0 || jitter.scale > 0) {
465
+ applyJitter(copies, jitter);
466
+ }
467
+ return copies;
468
+ }
469
+
470
+ // src/lib/svg/source.ts
471
+ var fetchCache = /* @__PURE__ */ new Map();
472
+ function bytesToBase64(bytes) {
473
+ let binary = "";
474
+ const chunk = 32768;
475
+ for (let i = 0; i < bytes.length; i += chunk) {
476
+ binary += String.fromCharCode(...bytes.subarray(i, i + chunk));
477
+ }
478
+ return btoa(binary);
479
+ }
480
+ async function fetchSourceUncached(url) {
481
+ var _a;
482
+ if (url.startsWith("data:")) {
483
+ const [header, data] = url.split(",");
484
+ if (!header.includes("image/svg+xml")) return { kind: "raster", dataUrl: url };
485
+ return { kind: "svg", text: header.includes("base64") ? atob(data) : decodeURIComponent(data) };
486
+ }
487
+ const res = await fetch(url);
488
+ if (!res.ok) throw new Error(`Failed to fetch source: ${url} (${res.status})`);
489
+ const type = (_a = res.headers.get("content-type")) != null ? _a : "";
490
+ const looksSvg = type.includes("svg") || !type.startsWith("image/") && /\.svg(\?|#|$)/i.test(url);
491
+ if (looksSvg) return { kind: "svg", text: await res.text() };
492
+ const mime = type.startsWith("image/") ? type.split(";")[0] : "image/png";
493
+ const bytes = new Uint8Array(await res.arrayBuffer());
494
+ return { kind: "raster", dataUrl: `data:${mime};base64,${bytesToBase64(bytes)}` };
495
+ }
496
+ function fetchSource(url) {
497
+ let pending = fetchCache.get(url);
498
+ if (!pending) {
499
+ pending = fetchSourceUncached(url);
500
+ pending.catch(() => fetchCache.delete(url));
501
+ fetchCache.set(url, pending);
502
+ }
503
+ return pending;
504
+ }
505
+ function clearFetchCache() {
506
+ fetchCache.clear();
507
+ }
508
+ function parseSvgMarkup(text) {
509
+ var _a, _b, _c;
510
+ const open = /<svg\b([^>]*?)(\/?)>/i.exec(text);
511
+ if (!open) throw new Error("Source is not an SVG");
512
+ const attrs = open[1];
513
+ const attr = (name) => {
514
+ var _a2, _b2;
515
+ return (_b2 = (_a2 = new RegExp(`\\s${name}\\s*=\\s*(["'])(.*?)\\1`, "i").exec(attrs)) == null ? void 0 : _a2[2]) != null ? _b2 : null;
516
+ };
517
+ let viewBox = attr("viewBox");
518
+ if (!viewBox) {
519
+ const w = parseFloat((_a = attr("width")) != null ? _a : "") || 100;
520
+ const h = parseFloat((_b = attr("height")) != null ? _b : "") || 100;
521
+ viewBox = `0 0 ${w} ${h}`;
522
+ }
523
+ const start = open.index + open[0].length;
524
+ const end = text.toLowerCase().lastIndexOf("</svg>");
525
+ const inner = open[2] === "/" || end < start ? "" : text.slice(start, end);
526
+ const namespaces = ((_c = attrs.match(/\sxmlns:[\w-]+\s*=\s*(["'])[^"']*\1/g)) != null ? _c : []).join("");
527
+ return { viewBox, inner, namespaces };
528
+ }
529
+
530
+ // src/lib/svg/loader.ts
531
+ var spriteCache = /* @__PURE__ */ new Map();
532
+ function cacheKey(source) {
533
+ return `${source.url}::${source.spriteWidth}x${source.spriteHeight}`;
534
+ }
535
+ async function loadSprite(source) {
536
+ const key = cacheKey(source);
537
+ const cached = spriteCache.get(key);
538
+ if (cached) return cached;
539
+ const fetched = await fetchSource(source.url);
540
+ const canvas = fetched.kind === "svg" ? await rasterizeSvg(fetched.text, source.spriteWidth, source.spriteHeight) : await rasterizeImage(fetched.dataUrl, source.spriteWidth, source.spriteHeight);
541
+ spriteCache.set(key, canvas);
542
+ return canvas;
543
+ }
544
+ async function loadSprites(sources) {
545
+ return Promise.all(sources.map(loadSprite));
546
+ }
547
+ function clearSpriteCache() {
548
+ spriteCache.clear();
549
+ clearFetchCache();
550
+ }
551
+ function rasterizeImage(dataUrl, width, height) {
552
+ return new Promise((resolve, reject) => {
553
+ const img = new Image();
554
+ img.onload = () => {
555
+ const canvas = document.createElement("canvas");
556
+ canvas.width = width;
557
+ canvas.height = height;
558
+ const fit = Math.min(width / img.naturalWidth, height / img.naturalHeight);
559
+ const dw = img.naturalWidth * fit, dh = img.naturalHeight * fit;
560
+ canvas.getContext("2d").drawImage(img, (width - dw) / 2, (height - dh) / 2, dw, dh);
561
+ resolve(canvas);
562
+ };
563
+ img.onerror = () => reject(new Error("Failed to load image"));
564
+ img.src = dataUrl;
565
+ });
566
+ }
567
+ function rasterizeSvg(svgText, width, height) {
568
+ return new Promise((resolve, reject) => {
569
+ const parser = new DOMParser();
570
+ const doc = parser.parseFromString(svgText, "image/svg+xml");
571
+ const svgEl = doc.documentElement;
572
+ if (!svgEl.getAttribute("viewBox")) {
573
+ const w = svgEl.getAttribute("width") || "100";
574
+ const h = svgEl.getAttribute("height") || "100";
575
+ svgEl.setAttribute("viewBox", `0 0 ${w} ${h}`);
576
+ }
577
+ svgEl.setAttribute("width", String(width));
578
+ svgEl.setAttribute("height", String(height));
579
+ const serialized = new XMLSerializer().serializeToString(svgEl);
580
+ const blob = new Blob([serialized], { type: "image/svg+xml" });
581
+ const url = URL.createObjectURL(blob);
582
+ const img = new Image();
583
+ img.onload = () => {
584
+ const canvas = document.createElement("canvas");
585
+ canvas.width = width;
586
+ canvas.height = height;
587
+ const ctx = canvas.getContext("2d");
588
+ ctx.drawImage(img, 0, 0, width, height);
589
+ URL.revokeObjectURL(url);
590
+ resolve(canvas);
591
+ };
592
+ img.onerror = () => {
593
+ URL.revokeObjectURL(url);
594
+ reject(new Error(`Failed to rasterize SVG`));
595
+ };
596
+ img.src = url;
597
+ });
598
+ }
599
+ var tintCache = /* @__PURE__ */ new Map();
600
+ function tintSprite(sprite, spriteKey, color, mode) {
601
+ const key = `${spriteKey}:${color}:${mode}`;
602
+ const cached = tintCache.get(key);
603
+ if (cached) return cached;
604
+ const w = sprite.width, h = sprite.height;
605
+ const off = document.createElement("canvas");
606
+ off.width = w;
607
+ off.height = h;
608
+ const ctx = off.getContext("2d");
609
+ ctx.drawImage(sprite, 0, 0);
610
+ if (mode === "luminance") {
611
+ const img = ctx.getImageData(0, 0, w, h);
612
+ const px = img.data;
613
+ for (let i = 0; i < px.length; i += 4) {
614
+ const lum = (0.2126 * px[i] + 0.7152 * px[i + 1] + 0.0722 * px[i + 2]) / 255;
615
+ px[i + 3] = Math.round(px[i + 3] * lum);
616
+ }
617
+ ctx.putImageData(img, 0, 0);
618
+ ctx.globalCompositeOperation = "source-in";
619
+ ctx.fillStyle = color;
620
+ ctx.fillRect(0, 0, w, h);
621
+ return cacheTint(key, off);
622
+ }
623
+ const compositeOp = mode === "source-in" ? "source-in" : mode === "overlay" ? "overlay" : "multiply";
624
+ ctx.globalCompositeOperation = compositeOp;
625
+ ctx.fillStyle = color;
626
+ ctx.fillRect(0, 0, w, h);
627
+ if (mode !== "source-in") {
628
+ ctx.globalCompositeOperation = "destination-in";
629
+ ctx.drawImage(sprite, 0, 0);
630
+ }
631
+ return cacheTint(key, off);
632
+ }
633
+ function cacheTint(key, canvas) {
634
+ if (tintCache.size > 256) {
635
+ const first = tintCache.keys().next().value;
636
+ if (first) tintCache.delete(first);
637
+ }
638
+ tintCache.set(key, canvas);
639
+ return canvas;
640
+ }
641
+ function clearTintCache() {
642
+ tintCache.clear();
643
+ }
644
+
645
+ // src/lib/render/canvas.ts
646
+ async function renderToCanvas(config) {
647
+ const { canvas: canvasCfg, sources, color, sourceDistribution, sourceSeed } = config;
648
+ const canvasEl = document.createElement("canvas");
649
+ canvasEl.width = canvasCfg.width;
650
+ canvasEl.height = canvasCfg.height;
651
+ const ctx = canvasEl.getContext("2d");
652
+ if (canvasCfg.background) {
653
+ ctx.fillStyle = canvasCfg.background;
654
+ ctx.fillRect(0, 0, canvasCfg.width, canvasCfg.height);
655
+ }
656
+ if (sources.length === 0) return canvasEl;
657
+ const sprites = await loadSprites(sources);
658
+ const copies = computeLayout(config);
659
+ const total = copies.length;
660
+ const isRandom = sourceDistribution === "random" && sprites.length > 1;
661
+ let prevAlpha = -1;
662
+ for (const copy of copies) {
663
+ const spriteIdx = sprites.length === 1 ? 0 : isRandom ? seededIndex(copy.index, sprites.length, sourceSeed) : copy.index % sprites.length;
664
+ const baseSprite = sprites[spriteIdx];
665
+ const { scale: copyScale, opacity: copyOpacity, rotation: copyRotation } = resolveCopyStyle(config, copy, total);
666
+ if (copyOpacity <= 5e-3 || copyScale <= 5e-3) continue;
667
+ let drawSprite = baseSprite;
668
+ const spriteKey = `${sources[spriteIdx].url}::${baseSprite.width}x${baseSprite.height}`;
669
+ if (color && color.colors.length > 0) {
670
+ const tintColor = stepColor(color.colors, color.step, copy.index);
671
+ if (tintColor) drawSprite = tintSprite(baseSprite, spriteKey, tintColor, color.tintMode);
672
+ }
673
+ const sw = drawSprite.width;
674
+ const sh = drawSprite.height;
675
+ if (Math.abs(copyOpacity - prevAlpha) > 5e-3) {
676
+ ctx.globalAlpha = copyOpacity;
677
+ prevAlpha = copyOpacity;
678
+ }
679
+ ctx.save();
680
+ if (copy.blur > 0) ctx.filter = `blur(${copy.blur}px)`;
681
+ ctx.translate(copy.x, copy.y);
682
+ if (copyRotation !== 0) ctx.rotate(copyRotation * Math.PI / 180);
683
+ if (copy.mirrorX) ctx.scale(-1, 1);
684
+ if (copyScale !== 1) ctx.scale(copyScale, copyScale);
685
+ ctx.drawImage(drawSprite, -sw / 2, -sh / 2);
686
+ ctx.restore();
687
+ }
688
+ ctx.globalAlpha = 1;
689
+ return canvasEl;
690
+ }
691
+
692
+ // src/lib/render/svg.ts
693
+ var svgSourceCache = /* @__PURE__ */ new Map();
694
+ async function parseSvgSource(source) {
695
+ const cacheKey2 = `${source.url}::${source.spriteWidth}x${source.spriteHeight}`;
696
+ const cached = svgSourceCache.get(cacheKey2);
697
+ if (cached) return cached;
698
+ const fetched = await fetchSource(source.url);
699
+ if (fetched.kind === "raster") {
700
+ const { spriteWidth: w, spriteHeight: h } = source;
701
+ const result2 = {
702
+ viewBox: `0 0 ${w} ${h}`,
703
+ inner: `<image href="${fetched.dataUrl}" width="${w}" height="${h}" preserveAspectRatio="xMidYMid meet"/>`,
704
+ namespaces: ""
705
+ };
706
+ svgSourceCache.set(cacheKey2, result2);
707
+ return result2;
708
+ }
709
+ const result = parseSvgMarkup(fetched.text);
710
+ svgSourceCache.set(cacheKey2, result);
711
+ return result;
712
+ }
713
+ function clearSvgSourceCache() {
714
+ svgSourceCache.clear();
715
+ }
716
+ function filterId({ tint, blur }) {
717
+ const t = tint ? `${tint.mode.replace(/-/g, "")}_${tint.color.replace(/[^a-zA-Z0-9]/g, "_")}` : "none";
718
+ return `f_${t}_b${String(blur).replace(".", "_")}`;
719
+ }
720
+ function tintPrimitives(color, mode) {
721
+ const flood = `<feFlood flood-color="${color}" result="c"/>`;
722
+ switch (mode) {
723
+ case "source-in":
724
+ return `${flood}<feComposite in="c" in2="SourceGraphic" operator="in" result="t"/>`;
725
+ case "luminance":
726
+ return `<feColorMatrix in="SourceGraphic" type="luminanceToAlpha" result="l"/><feComposite in="l" in2="SourceAlpha" operator="in" result="la"/>${flood}<feComposite in="c" in2="la" operator="in" result="t"/>`;
727
+ default:
728
+ return `${flood}<feBlend in="SourceGraphic" in2="c" mode="${mode}" result="b"/><feComposite in="b" in2="SourceGraphic" operator="in" result="t"/>`;
729
+ }
730
+ }
731
+ function makeFilter(spec) {
732
+ const region = spec.blur > 0 ? `x="-25%" y="-25%" width="150%" height="150%"` : `x="0%" y="0%" width="100%" height="100%"`;
733
+ const tint = spec.tint ? tintPrimitives(spec.tint.color, spec.tint.mode) : "";
734
+ const blur = spec.blur > 0 ? `<feGaussianBlur in="${spec.tint ? "t" : "SourceGraphic"}" stdDeviation="${spec.blur}"/>` : "";
735
+ return `<filter id="${filterId(spec)}" ${region} color-interpolation-filters="sRGB">${tint}${blur}</filter>`;
736
+ }
737
+ async function buildParts(config, wrapEdges = false) {
738
+ const { sources, color, sourceDistribution, sourceSeed } = config;
739
+ const { width: tileW, height: tileH } = config.canvas;
740
+ if (sources.length === 0) return { symbols: [], filters: [], uses: [] };
741
+ const parsed = await Promise.all(sources.map(parseSvgSource));
742
+ const copies = computeLayout(config);
743
+ const total = copies.length;
744
+ const isRandom = sourceDistribution === "random" && sources.length > 1;
745
+ const symbols = sources.map(
746
+ (src, i) => `<symbol id="src_${src.id}" viewBox="${parsed[i].viewBox}" overflow="visible"${parsed[i].namespaces}>${parsed[i].inner}</symbol>`
747
+ );
748
+ const filtersNeeded = /* @__PURE__ */ new Map();
749
+ const filterFor = (copyIndex, blur) => {
750
+ const c = color && color.colors.length > 0 ? stepColor(color.colors, color.step, copyIndex) : "";
751
+ const spec = { tint: c && color ? { color: c, mode: color.tintMode } : null, blur };
752
+ if (!spec.tint && !spec.blur) return null;
753
+ const id = filterId(spec);
754
+ if (!filtersNeeded.has(id)) filtersNeeded.set(id, makeFilter(spec));
755
+ return id;
756
+ };
757
+ const uses = [];
758
+ for (const copy of copies) {
759
+ const srcIdx = sources.length === 1 ? 0 : isRandom ? seededIndex(copy.index, sources.length, sourceSeed) : copy.index % sources.length;
760
+ const { scale: sc, opacity: op, rotation: rot } = resolveCopyStyle(config, copy, total);
761
+ if (op <= 5e-3 || sc <= 5e-3) continue;
762
+ const src = sources[srcIdx];
763
+ const w = src.spriteWidth * sc;
764
+ const h = src.spriteHeight * sc;
765
+ const opAttr = op < 0.995 ? ` opacity="${op.toFixed(3)}"` : "";
766
+ const fid = filterFor(copy.index, copy.blur);
767
+ const filterAttr = fid ? ` filter="url(#${fid})"` : "";
768
+ const makeUse = (dx, dy) => {
769
+ const xf = [`translate(${(copy.x + dx).toFixed(2)} ${(copy.y + dy).toFixed(2)})`];
770
+ if (rot !== 0) xf.push(`rotate(${rot.toFixed(3)})`);
771
+ if (copy.mirrorX) xf.push("scale(-1 1)");
772
+ return `<use href="#src_${src.id}" x="${(-w / 2).toFixed(2)}" y="${(-h / 2).toFixed(2)}" width="${w.toFixed(2)}" height="${h.toFixed(2)}" transform="${xf.join(" ")}"${opAttr}${filterAttr}/>`;
773
+ };
774
+ uses.push(makeUse(0, 0));
775
+ if (wrapEdges) {
776
+ const bound = Math.hypot(w, h) / 2;
777
+ const oL = copy.x - bound < 0;
778
+ const oR = copy.x + bound > tileW;
779
+ const oT = copy.y - bound < 0;
780
+ const oB = copy.y + bound > tileH;
781
+ if (oL) uses.push(makeUse(tileW, 0));
782
+ if (oR) uses.push(makeUse(-tileW, 0));
783
+ if (oT) uses.push(makeUse(0, tileH));
784
+ if (oB) uses.push(makeUse(0, -tileH));
785
+ if (oL && oT) uses.push(makeUse(tileW, tileH));
786
+ if (oR && oT) uses.push(makeUse(-tileW, tileH));
787
+ if (oL && oB) uses.push(makeUse(tileW, -tileH));
788
+ if (oR && oB) uses.push(makeUse(-tileW, -tileH));
789
+ }
790
+ }
791
+ return { symbols, filters: [...filtersNeeded.values()], uses };
792
+ }
793
+ async function renderToSvg(config) {
794
+ const { width, height, background } = config.canvas;
795
+ const { symbols, filters, uses } = await buildParts(config, false);
796
+ const bgRect = background ? `<rect width="${width}" height="${height}" fill="${background}"/>` : "";
797
+ return [
798
+ `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" overflow="hidden">`,
799
+ bgRect,
800
+ "<defs>",
801
+ ...symbols,
802
+ ...filters,
803
+ "</defs>",
804
+ ...uses,
805
+ "</svg>"
806
+ ].filter(Boolean).join("\n");
807
+ }
808
+ async function renderTileableSvg(config, vpWidth = "100%", vpHeight = "100%") {
809
+ const { width, height, background } = config.canvas;
810
+ const { symbols, filters, uses } = await buildParts(config, true);
811
+ const bgRect = background ? `<rect width="${width}" height="${height}" fill="${background}"/>` : "";
812
+ return [
813
+ `<svg xmlns="http://www.w3.org/2000/svg" width="${vpWidth}" height="${vpHeight}">`,
814
+ "<defs>",
815
+ ...symbols,
816
+ ...filters,
817
+ `<pattern id="tile" x="0" y="0" width="${width}" height="${height}" patternUnits="userSpaceOnUse">`,
818
+ bgRect,
819
+ ...uses,
820
+ "</pattern>",
821
+ "</defs>",
822
+ `<rect width="100%" height="100%" fill="url(#tile)"/>`,
823
+ "</svg>"
824
+ ].filter(Boolean).join("\n");
825
+ }
826
+ async function renderToSvgBlob(config) {
827
+ const svg = await renderToSvg(config);
828
+ return new Blob([svg], { type: "image/svg+xml" });
829
+ }
830
+ async function downloadSvg(config, filename = "pattern.svg", vpWidth, vpHeight) {
831
+ const w = vpWidth != null ? vpWidth : config.canvas.width;
832
+ const h = vpHeight != null ? vpHeight : config.canvas.height;
833
+ const svg = await renderTileableSvg(config, w, h);
834
+ const blob = new Blob([svg], { type: "image/svg+xml" });
835
+ const url = URL.createObjectURL(blob);
836
+ const a = document.createElement("a");
837
+ a.href = url;
838
+ a.download = filename;
839
+ a.click();
840
+ URL.revokeObjectURL(url);
841
+ }
842
+
843
+ // src/lib/render/export.ts
844
+ async function renderToDataURL(config, format = "png", quality = 0.92) {
845
+ const canvas = await renderToCanvas(config);
846
+ const mimeType = mimeFor(format);
847
+ return canvas.toDataURL(mimeType, quality);
848
+ }
849
+ async function renderToBlob(config, format = "png", quality = 0.92) {
850
+ const canvas = await renderToCanvas(config);
851
+ return new Promise((resolve, reject) => {
852
+ canvas.toBlob(
853
+ (blob) => blob ? resolve(blob) : reject(new Error("toBlob returned null")),
854
+ mimeFor(format),
855
+ quality
856
+ );
857
+ });
858
+ }
859
+ async function downloadPattern(config, filename = "pattern", format = "png", quality = 0.92) {
860
+ if (format === "svg") {
861
+ return downloadSvg(config, `${filename}.svg`);
862
+ }
863
+ const blob = await renderToBlob(config, format, quality);
864
+ const url = URL.createObjectURL(blob);
865
+ const a = document.createElement("a");
866
+ a.href = url;
867
+ a.download = `${filename}.${format}`;
868
+ a.click();
869
+ URL.revokeObjectURL(url);
870
+ }
871
+ function mimeFor(format) {
872
+ if (format === "jpg") return "image/jpeg";
873
+ if (format === "webp") return "image/webp";
874
+ return "image/png";
875
+ }
876
+
877
+ // src/components/PatternPreview.tsx
878
+ import { useEffect, useRef, useState, useCallback } from "react";
879
+ import { jsx, jsxs } from "react/jsx-runtime";
880
+ function PatternPreview({ config, className }) {
881
+ const [svgString, setSvgString] = useState("");
882
+ const [loading, setLoading] = useState(false);
883
+ const [error, setError] = useState("");
884
+ const renderToken = useRef(0);
885
+ const render = useCallback(async (cfg) => {
886
+ const token = ++renderToken.current;
887
+ if (!svgString) setLoading(true);
888
+ setError("");
889
+ try {
890
+ const svg = isTileable(cfg) ? await renderTileableSvg(cfg) : await renderToSvg(cfg);
891
+ if (token !== renderToken.current) return;
892
+ setSvgString(svg);
893
+ } catch (e) {
894
+ if (token !== renderToken.current) return;
895
+ setError(e instanceof Error ? e.message : String(e));
896
+ } finally {
897
+ if (token === renderToken.current) setLoading(false);
898
+ }
899
+ }, [svgString]);
900
+ useEffect(() => {
901
+ render(config);
902
+ }, [config, render]);
903
+ return /* @__PURE__ */ jsxs("div", { className: `relative overflow-hidden ${className != null ? className : ""}`, children: [
904
+ svgString ? (
905
+ // dangerouslySetInnerHTML updates the DOM synchronously in-place —
906
+ // no URL loading step, so no flash between renders.
907
+ /* @__PURE__ */ jsx("div", { className: "w-full h-full", dangerouslySetInnerHTML: { __html: svgString } })
908
+ ) : !error && !loading && /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center w-full h-full bg-gray-800", children: /* @__PURE__ */ jsx("span", { className: "text-gray-500 text-sm", children: "Add a source to preview" }) }),
909
+ loading && /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-gray-900", children: /* @__PURE__ */ jsx("div", { className: "w-5 h-5 border-2 border-indigo-400 border-t-transparent rounded-full animate-spin" }) }),
910
+ error && /* @__PURE__ */ jsx("div", { className: "absolute bottom-2 left-2 right-2 bg-red-900/80 text-red-200 text-xs rounded px-2 py-1.5 leading-snug", children: error })
911
+ ] });
912
+ }
913
+
914
+ // src/components/PatternStudio.tsx
915
+ import { useCallback as useCallback2, useState as useState4 } from "react";
916
+
917
+ // src/components/editor/PropertyRow.tsx
918
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
919
+ function PropertyRow(props) {
920
+ if (props.type === "slider") {
921
+ const display = props.format ? props.format(props.value) : String(Math.round(props.value * 100) / 100);
922
+ return /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-between gap-2", children: [
923
+ /* @__PURE__ */ jsx2("span", { className: "text-xs text-gray-400 shrink-0 w-24", children: props.label }),
924
+ /* @__PURE__ */ jsx2(
925
+ "input",
926
+ {
927
+ type: "range",
928
+ min: props.min,
929
+ max: props.max,
930
+ step: props.step,
931
+ value: props.value,
932
+ onChange: (e) => props.onChange(parseFloat(e.target.value)),
933
+ className: "flex-1 h-1 accent-indigo-400 cursor-pointer"
934
+ }
935
+ ),
936
+ /* @__PURE__ */ jsx2("span", { className: "text-xs text-gray-300 w-10 text-right tabular-nums", children: display })
937
+ ] });
938
+ }
939
+ if (props.type === "toggle") {
940
+ return /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-between", children: [
941
+ /* @__PURE__ */ jsx2("span", { className: "text-xs text-gray-400", children: props.label }),
942
+ /* @__PURE__ */ jsx2(
943
+ "button",
944
+ {
945
+ onClick: () => props.onChange(!props.value),
946
+ className: `relative w-8 h-4 rounded-full transition-colors ${props.value ? "bg-indigo-500" : "bg-gray-600"}`,
947
+ children: /* @__PURE__ */ jsx2("span", { className: `absolute top-0.5 w-3 h-3 rounded-full bg-white transition-transform ${props.value ? "translate-x-4" : "translate-x-0.5"}` })
948
+ }
949
+ )
950
+ ] });
951
+ }
952
+ return /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-between", children: [
953
+ /* @__PURE__ */ jsx2("span", { className: "text-xs text-gray-400", children: props.label }),
954
+ /* @__PURE__ */ jsx2(
955
+ "select",
956
+ {
957
+ value: props.value,
958
+ onChange: (e) => props.onChange(e.target.value),
959
+ className: "bg-gray-800 border border-gray-700 rounded px-2 py-1 text-xs text-white",
960
+ children: props.options.map((o) => /* @__PURE__ */ jsx2("option", { value: o.value, children: o.label }, o.value))
961
+ }
962
+ )
963
+ ] });
964
+ }
965
+
966
+ // src/components/editor/ArrangementEditor.tsx
967
+ import { Fragment, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
968
+ var ARRANGEMENT_TYPES = [
969
+ { value: "grid", label: "Grid" },
970
+ { value: "brick", label: "Brick" },
971
+ { value: "hex", label: "Hex" },
972
+ { value: "radial", label: "Radial" },
973
+ { value: "concentric", label: "Concentric" },
974
+ { value: "spiral", label: "Spiral" },
975
+ { value: "mirror", label: "Mirror" },
976
+ { value: "scatter", label: "Scatter" },
977
+ { value: "focal", label: "Focal + satellites" }
978
+ ];
979
+ function ArrangementEditor({ arrangement: arr, onChange }) {
980
+ function update(partial) {
981
+ onChange(__spreadValues(__spreadValues({}, arr), partial));
982
+ }
983
+ return /* @__PURE__ */ jsxs3("div", { className: "space-y-2", children: [
984
+ /* @__PURE__ */ jsx3("label", { className: "text-xs text-gray-400 font-medium block", children: "Arrangement" }),
985
+ /* @__PURE__ */ jsx3(
986
+ PropertyRow,
987
+ {
988
+ type: "select",
989
+ label: "Type",
990
+ value: arr.type,
991
+ options: ARRANGEMENT_TYPES,
992
+ onChange: (v) => onChange(defaultArrangement(v))
993
+ }
994
+ ),
995
+ arr.type === "grid" && /* @__PURE__ */ jsx3(GridControls, { arr, onUpdate: update }),
996
+ arr.type === "brick" && /* @__PURE__ */ jsx3(BrickControls, { arr, onUpdate: update }),
997
+ arr.type === "hex" && /* @__PURE__ */ jsx3(HexControls, { arr, onUpdate: update }),
998
+ arr.type === "radial" && /* @__PURE__ */ jsx3(RadialControls, { arr, onUpdate: update }),
999
+ arr.type === "concentric" && /* @__PURE__ */ jsx3(ConcentricControls, { arr, onUpdate: update }),
1000
+ arr.type === "spiral" && /* @__PURE__ */ jsx3(SpiralControls, { arr, onUpdate: update }),
1001
+ arr.type === "mirror" && /* @__PURE__ */ jsx3(MirrorControls, { arr, onUpdate: update }),
1002
+ arr.type === "scatter" && /* @__PURE__ */ jsxs3(Fragment, { children: [
1003
+ /* @__PURE__ */ jsx3(ScatterParamsControls, { params: arr, onUpdate: update }),
1004
+ /* @__PURE__ */ jsx3(ClearCenterControl, { zones: arr.clearZones, onChange: (clearZones) => update({ clearZones }) })
1005
+ ] }),
1006
+ arr.type === "focal" && /* @__PURE__ */ jsx3(FocalControls, { arr, onUpdate: update })
1007
+ ] });
1008
+ }
1009
+ function GridControls({ arr, onUpdate }) {
1010
+ return /* @__PURE__ */ jsxs3(Fragment, { children: [
1011
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Columns", value: arr.repeatX, min: 1, max: 24, step: 1, onChange: (v) => onUpdate({ repeatX: v }) }),
1012
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Rows", value: arr.repeatY, min: 1, max: 24, step: 1, onChange: (v) => onUpdate({ repeatY: v }) }),
1013
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Gap X", value: arr.gapX, min: -50, max: 200, step: 1, onChange: (v) => onUpdate({ gapX: v }) }),
1014
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Gap Y", value: arr.gapY, min: -50, max: 200, step: 1, onChange: (v) => onUpdate({ gapY: v }) }),
1015
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Rotation", value: arr.gridRotation, min: -180, max: 180, step: 1, onChange: (v) => onUpdate({ gridRotation: v }), format: (v) => `${v}\xB0` })
1016
+ ] });
1017
+ }
1018
+ function BrickControls({ arr, onUpdate }) {
1019
+ return /* @__PURE__ */ jsxs3(Fragment, { children: [
1020
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Columns", value: arr.repeatX, min: 1, max: 24, step: 1, onChange: (v) => onUpdate({ repeatX: v }) }),
1021
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Rows", value: arr.repeatY, min: 1, max: 24, step: 1, onChange: (v) => onUpdate({ repeatY: v }) }),
1022
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Gap X", value: arr.gapX, min: -50, max: 200, step: 1, onChange: (v) => onUpdate({ gapX: v }) }),
1023
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Gap Y", value: arr.gapY, min: -50, max: 200, step: 1, onChange: (v) => onUpdate({ gapY: v }) }),
1024
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Stagger", value: arr.staggerOffset, min: 0, max: 1, step: 0.05, onChange: (v) => onUpdate({ staggerOffset: v }) }),
1025
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "select", label: "Axis", value: arr.staggerAxis, options: [{ value: "row", label: "Row" }, { value: "column", label: "Column" }], onChange: (v) => onUpdate({ staggerAxis: v }) })
1026
+ ] });
1027
+ }
1028
+ function HexControls({ arr, onUpdate }) {
1029
+ return /* @__PURE__ */ jsxs3(Fragment, { children: [
1030
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Count across", value: arr.countAcross, min: 1, max: 24, step: 1, onChange: (v) => onUpdate({ countAcross: v }) }),
1031
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Spacing", value: arr.spacing, min: 10, max: 300, step: 5, onChange: (v) => onUpdate({ spacing: v }) }),
1032
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "select", label: "Orientation", value: arr.orientation, options: [{ value: "pointy", label: "Pointy-top" }, { value: "flat", label: "Flat-top" }], onChange: (v) => onUpdate({ orientation: v }) })
1033
+ ] });
1034
+ }
1035
+ function RadialControls({ arr, onUpdate }) {
1036
+ return /* @__PURE__ */ jsxs3(Fragment, { children: [
1037
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Count", value: arr.count, min: 1, max: 48, step: 1, onChange: (v) => onUpdate({ count: v }) }),
1038
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Radius", value: arr.radius, min: 10, max: 800, step: 5, onChange: (v) => onUpdate({ radius: v }) }),
1039
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Start angle", value: arr.startAngle, min: 0, max: 360, step: 5, onChange: (v) => onUpdate({ startAngle: v }), format: (v) => `${v}\xB0` }),
1040
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Arc", value: arr.arc, min: 10, max: 360, step: 5, onChange: (v) => onUpdate({ arc: v }), format: (v) => `${v}\xB0` }),
1041
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "toggle", label: "Face outward", value: arr.faceOutward, onChange: (v) => onUpdate({ faceOutward: v }) }),
1042
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "toggle", label: "Mirror alternate", value: arr.mirrorAlternate, onChange: (v) => onUpdate({ mirrorAlternate: v }) })
1043
+ ] });
1044
+ }
1045
+ function ConcentricControls({ arr, onUpdate }) {
1046
+ return /* @__PURE__ */ jsxs3(Fragment, { children: [
1047
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Rings", value: arr.rings, min: 1, max: 12, step: 1, onChange: (v) => onUpdate({ rings: v }) }),
1048
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Per ring", value: arr.copiesPerRing, min: 1, max: 24, step: 1, onChange: (v) => onUpdate({ copiesPerRing: v }) }),
1049
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "select", label: "Ring scaling", value: arr.ringScaling, options: [{ value: "fixed", label: "Fixed" }, { value: "proportional", label: "Proportional" }], onChange: (v) => onUpdate({ ringScaling: v }) }),
1050
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Ring gap", value: arr.ringGap, min: 10, max: 200, step: 5, onChange: (v) => onUpdate({ ringGap: v }) }),
1051
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Inner radius", value: arr.innerRadius, min: 0, max: 300, step: 5, onChange: (v) => onUpdate({ innerRadius: v }) }),
1052
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "toggle", label: "Face outward", value: arr.faceOutward, onChange: (v) => onUpdate({ faceOutward: v }) }),
1053
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Scale/ring", value: arr.scalePerRing, min: 0.3, max: 1.5, step: 0.05, onChange: (v) => onUpdate({ scalePerRing: v }) })
1054
+ ] });
1055
+ }
1056
+ function SpiralControls({ arr, onUpdate }) {
1057
+ return /* @__PURE__ */ jsxs3(Fragment, { children: [
1058
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Count", value: arr.count, min: 2, max: 120, step: 1, onChange: (v) => onUpdate({ count: v }) }),
1059
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Inner radius", value: arr.innerRadius, min: 0, max: 300, step: 5, onChange: (v) => onUpdate({ innerRadius: v }) }),
1060
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Outer radius", value: arr.outerRadius, min: 50, max: 800, step: 10, onChange: (v) => onUpdate({ outerRadius: v }) }),
1061
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Turns", value: arr.turns, min: 0.5, max: 12, step: 0.5, onChange: (v) => onUpdate({ turns: v }) }),
1062
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "toggle", label: "Face outward", value: arr.faceOutward, onChange: (v) => onUpdate({ faceOutward: v }) })
1063
+ ] });
1064
+ }
1065
+ function MirrorControls({ arr, onUpdate }) {
1066
+ return /* @__PURE__ */ jsxs3(Fragment, { children: [
1067
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Axes", value: arr.axes, min: 2, max: 16, step: 1, onChange: (v) => onUpdate({ axes: v }) }),
1068
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "toggle", label: "Reflect", value: arr.reflect, onChange: (v) => onUpdate({ reflect: v }) }),
1069
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Radius", value: arr.radius, min: 10, max: 800, step: 10, onChange: (v) => onUpdate({ radius: v }) })
1070
+ ] });
1071
+ }
1072
+ function ScatterParamsControls({ params: p, onUpdate }) {
1073
+ return /* @__PURE__ */ jsxs3(Fragment, { children: [
1074
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Count", value: p.count, min: 0, max: 200, step: 1, onChange: (v) => onUpdate({ count: v }) }),
1075
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Min size", value: p.minSize, min: 4, max: 600, step: 2, onChange: (v) => onUpdate({ minSize: v }) }),
1076
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Max size", value: p.maxSize, min: 4, max: 600, step: 2, onChange: (v) => onUpdate({ maxSize: v }) }),
1077
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Favor small", value: p.sizeBias, min: 0.5, max: 4, step: 0.1, onChange: (v) => onUpdate({ sizeBias: v }) }),
1078
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Gap", value: p.gap, min: 0, max: 300, step: 2, onChange: (v) => onUpdate({ gap: v }) }),
1079
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Blur", value: p.blur, min: 0, max: 20, step: 0.5, onChange: (v) => onUpdate({ blur: v }), format: (v) => `${v}px` }),
1080
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Seed", value: p.seed, min: 1, max: 999, step: 1, onChange: (v) => onUpdate({ seed: v }) })
1081
+ ] });
1082
+ }
1083
+ function ClearCenterControl({ zones, onChange }) {
1084
+ var _a, _b;
1085
+ const width = (_b = (_a = zones[0]) == null ? void 0 : _a.width) != null ? _b : 0;
1086
+ return /* @__PURE__ */ jsx3(
1087
+ PropertyRow,
1088
+ {
1089
+ type: "slider",
1090
+ label: "Clear center",
1091
+ value: width,
1092
+ min: 0,
1093
+ max: 0.8,
1094
+ step: 0.02,
1095
+ format: (v) => `${Math.round(v * 100)}%`,
1096
+ onChange: (v) => onChange(v > 0 ? [centerColumnZone(v)] : [])
1097
+ }
1098
+ );
1099
+ }
1100
+ function FocalControls({ arr, onUpdate }) {
1101
+ const focus = (u) => onUpdate({ focus: __spreadValues(__spreadValues({}, arr.focus), u) });
1102
+ const f = arr.focus;
1103
+ return /* @__PURE__ */ jsxs3(Fragment, { children: [
1104
+ /* @__PURE__ */ jsx3("label", { className: "text-xs text-gray-500 block pt-1", children: "Focal mark" }),
1105
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Size", value: f.size, min: 50, max: 3e3, step: 10, onChange: (v) => focus({ size: v }) }),
1106
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "X", value: f.x, min: -0.5, max: 1.5, step: 0.01, format: (v) => `${Math.round(v * 100)}%`, onChange: (v) => focus({ x: v }) }),
1107
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Y", value: f.y, min: -0.5, max: 1.5, step: 0.01, format: (v) => `${Math.round(v * 100)}%`, onChange: (v) => focus({ y: v }) }),
1108
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Rotation", value: f.rotation, min: -180, max: 180, step: 1, format: (v) => `${v}\xB0`, onChange: (v) => focus({ rotation: v }) }),
1109
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Opacity", value: f.opacity, min: 0, max: 1, step: 0.01, format: (v) => `${Math.round(v * 100)}%`, onChange: (v) => focus({ opacity: v }) }),
1110
+ /* @__PURE__ */ jsx3(PropertyRow, { type: "slider", label: "Blur", value: f.blur, min: 0, max: 40, step: 0.5, format: (v) => `${v}px`, onChange: (v) => focus({ blur: v }) }),
1111
+ /* @__PURE__ */ jsx3("label", { className: "text-xs text-gray-500 block pt-1", children: "Satellites" }),
1112
+ /* @__PURE__ */ jsx3(ScatterParamsControls, { params: arr.satellites, onUpdate: (u) => onUpdate({ satellites: __spreadValues(__spreadValues({}, arr.satellites), u) }) }),
1113
+ /* @__PURE__ */ jsx3(ClearCenterControl, { zones: arr.clearZones, onChange: (clearZones) => onUpdate({ clearZones }) })
1114
+ ] });
1115
+ }
1116
+
1117
+ // src/components/editor/SourceEditor.tsx
1118
+ import { useState as useState2 } from "react";
1119
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
1120
+ var nextId = 1;
1121
+ function SourceEditor({ sources, onChange }) {
1122
+ const [urlInput, setUrlInput] = useState2("");
1123
+ const [error, setError] = useState2("");
1124
+ function addSource() {
1125
+ const url = urlInput.trim();
1126
+ if (!url) return;
1127
+ setError("");
1128
+ const newSource = {
1129
+ id: String(nextId++),
1130
+ url,
1131
+ spriteWidth: 200,
1132
+ spriteHeight: 200
1133
+ };
1134
+ onChange([...sources, newSource]);
1135
+ setUrlInput("");
1136
+ }
1137
+ function removeSource(id) {
1138
+ clearSpriteCache();
1139
+ clearTintCache();
1140
+ clearSvgSourceCache();
1141
+ onChange(sources.filter((s) => s.id !== id));
1142
+ }
1143
+ function updateSource(id, patch) {
1144
+ clearSpriteCache();
1145
+ clearTintCache();
1146
+ clearSvgSourceCache();
1147
+ onChange(sources.map((s) => s.id === id ? __spreadValues(__spreadValues({}, s), patch) : s));
1148
+ }
1149
+ return /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
1150
+ /* @__PURE__ */ jsx4("label", { className: "text-xs text-gray-400 font-medium block", children: "Sources" }),
1151
+ /* @__PURE__ */ jsx4("p", { className: "text-[11px] text-gray-500", children: "One or more SVG or image (PNG, JPEG, WebP) URLs to stamp. Multiple sources cycle across copies. They must be CORS-accessible from this page." }),
1152
+ sources.map((src, i) => /* @__PURE__ */ jsxs4("div", { className: "bg-gray-800 rounded-lg p-2 space-y-2", children: [
1153
+ /* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-2", children: [
1154
+ /* @__PURE__ */ jsxs4("span", { className: "text-[10px] text-gray-500 shrink-0", children: [
1155
+ "#",
1156
+ i + 1
1157
+ ] }),
1158
+ /* @__PURE__ */ jsx4("span", { className: "text-xs text-gray-300 truncate flex-1", title: src.url, children: src.url }),
1159
+ /* @__PURE__ */ jsx4(
1160
+ "button",
1161
+ {
1162
+ onClick: () => removeSource(src.id),
1163
+ className: "text-gray-500 hover:text-red-400 text-xs shrink-0",
1164
+ title: "Remove",
1165
+ children: "\u2715"
1166
+ }
1167
+ )
1168
+ ] }),
1169
+ /* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
1170
+ /* @__PURE__ */ jsxs4("div", { className: "flex-1", children: [
1171
+ /* @__PURE__ */ jsx4("label", { className: "text-[10px] text-gray-500 block mb-0.5", children: "Width px" }),
1172
+ /* @__PURE__ */ jsx4(
1173
+ "input",
1174
+ {
1175
+ type: "number",
1176
+ value: src.spriteWidth,
1177
+ min: 16,
1178
+ max: 1024,
1179
+ onChange: (e) => updateSource(src.id, { spriteWidth: parseInt(e.target.value) || 200 }),
1180
+ className: "w-full bg-gray-700 border border-gray-600 rounded px-2 py-0.5 text-xs text-white"
1181
+ }
1182
+ )
1183
+ ] }),
1184
+ /* @__PURE__ */ jsxs4("div", { className: "flex-1", children: [
1185
+ /* @__PURE__ */ jsx4("label", { className: "text-[10px] text-gray-500 block mb-0.5", children: "Height px" }),
1186
+ /* @__PURE__ */ jsx4(
1187
+ "input",
1188
+ {
1189
+ type: "number",
1190
+ value: src.spriteHeight,
1191
+ min: 16,
1192
+ max: 1024,
1193
+ onChange: (e) => updateSource(src.id, { spriteHeight: parseInt(e.target.value) || 200 }),
1194
+ className: "w-full bg-gray-700 border border-gray-600 rounded px-2 py-0.5 text-xs text-white"
1195
+ }
1196
+ )
1197
+ ] })
1198
+ ] })
1199
+ ] }, src.id)),
1200
+ /* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
1201
+ /* @__PURE__ */ jsx4(
1202
+ "input",
1203
+ {
1204
+ type: "url",
1205
+ placeholder: "https://... or /local.svg or .png",
1206
+ value: urlInput,
1207
+ onChange: (e) => setUrlInput(e.target.value),
1208
+ onKeyDown: (e) => e.key === "Enter" && addSource(),
1209
+ className: "flex-1 bg-gray-800 border border-gray-700 rounded px-2 py-1.5 text-xs text-white placeholder-gray-600"
1210
+ }
1211
+ ),
1212
+ /* @__PURE__ */ jsx4(
1213
+ "button",
1214
+ {
1215
+ onClick: addSource,
1216
+ disabled: !urlInput.trim(),
1217
+ className: "px-3 py-1.5 text-xs rounded bg-indigo-600 text-white hover:bg-indigo-500 disabled:opacity-40 disabled:cursor-not-allowed",
1218
+ children: "Add"
1219
+ }
1220
+ )
1221
+ ] }),
1222
+ error && /* @__PURE__ */ jsx4("p", { className: "text-xs text-red-400", children: error })
1223
+ ] });
1224
+ }
1225
+
1226
+ // src/components/editor/StepEditor.tsx
1227
+ import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
1228
+ var STEP_MODES = [
1229
+ { value: "fixed", label: "Fixed" },
1230
+ { value: "sequence", label: "Sequence" },
1231
+ { value: "grade", label: "Grade" },
1232
+ { value: "random", label: "Random" }
1233
+ ];
1234
+ function StepEditor({ label, range, bounds, onChange, format }) {
1235
+ function updateStep(patch) {
1236
+ const merged = __spreadValues(__spreadValues({}, range.step), patch);
1237
+ onChange(__spreadProps(__spreadValues({}, range), { step: merged }));
1238
+ }
1239
+ const mode = range.step.mode;
1240
+ return /* @__PURE__ */ jsxs5("div", { className: "space-y-1.5", children: [
1241
+ /* @__PURE__ */ jsxs5("div", { className: "flex items-center justify-between", children: [
1242
+ /* @__PURE__ */ jsx5("span", { className: "text-xs text-gray-400 font-medium", children: label }),
1243
+ /* @__PURE__ */ jsx5(
1244
+ "select",
1245
+ {
1246
+ value: mode,
1247
+ onChange: (e) => {
1248
+ const m = e.target.value;
1249
+ const base = m === "fixed" ? { mode: "fixed" } : m === "sequence" ? { mode: "sequence", amount: 1 } : m === "grade" ? { mode: "grade", steps: 5 } : { mode: "random", seed: Math.floor(Math.random() * 999999) + 1 };
1250
+ onChange(__spreadProps(__spreadValues({}, range), { step: base }));
1251
+ },
1252
+ className: "bg-gray-800 border border-gray-700 rounded px-2 py-0.5 text-xs text-white",
1253
+ children: STEP_MODES.map((m) => /* @__PURE__ */ jsx5("option", { value: m.value, children: m.label }, m.value))
1254
+ }
1255
+ )
1256
+ ] }),
1257
+ /* @__PURE__ */ jsx5(PropertyRow, { type: "slider", label: "Min", value: range.min, min: bounds.min, max: bounds.max, step: bounds.step, onChange: (v) => onChange(__spreadProps(__spreadValues({}, range), { min: v })), format }),
1258
+ mode !== "fixed" && /* @__PURE__ */ jsx5(PropertyRow, { type: "slider", label: "Max", value: range.max, min: bounds.min, max: bounds.max, step: bounds.step, onChange: (v) => onChange(__spreadProps(__spreadValues({}, range), { max: v })), format }),
1259
+ mode === "sequence" && range.step.amount !== void 0 && /* @__PURE__ */ jsx5(
1260
+ PropertyRow,
1261
+ {
1262
+ type: "slider",
1263
+ label: "Amount",
1264
+ value: range.step.amount,
1265
+ min: -100,
1266
+ max: 100,
1267
+ step: 1,
1268
+ onChange: (v) => updateStep({ amount: v })
1269
+ }
1270
+ ),
1271
+ mode === "grade" && /* @__PURE__ */ jsx5(
1272
+ PropertyRow,
1273
+ {
1274
+ type: "slider",
1275
+ label: "Steps",
1276
+ value: range.step.steps,
1277
+ min: 2,
1278
+ max: 50,
1279
+ step: 1,
1280
+ onChange: (v) => updateStep({ steps: v })
1281
+ }
1282
+ )
1283
+ ] });
1284
+ }
1285
+
1286
+ // src/components/editor/ColorEditor.tsx
1287
+ import { useState as useState3 } from "react";
1288
+ import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
1289
+ var DEFAULT_COLOR = {
1290
+ colors: ["#6366f1"],
1291
+ step: { mode: "sequence" },
1292
+ tintMode: "source-in"
1293
+ };
1294
+ function ColorEditor({ color, onChange }) {
1295
+ const [newColor, setNewColor] = useState3("#6366f1");
1296
+ const enabled = color !== null;
1297
+ function toggle(on) {
1298
+ onChange(on ? __spreadValues({}, DEFAULT_COLOR) : null);
1299
+ }
1300
+ function update(patch) {
1301
+ if (!color) return;
1302
+ onChange(__spreadValues(__spreadValues({}, color), patch));
1303
+ }
1304
+ function addColor() {
1305
+ if (!color) return;
1306
+ onChange(__spreadProps(__spreadValues({}, color), { colors: [...color.colors, newColor] }));
1307
+ }
1308
+ function removeColor(i) {
1309
+ if (!color) return;
1310
+ onChange(__spreadProps(__spreadValues({}, color), { colors: color.colors.filter((_, j) => j !== i) }));
1311
+ }
1312
+ function updateColor(i, val) {
1313
+ if (!color) return;
1314
+ const updated = [...color.colors];
1315
+ updated[i] = val;
1316
+ onChange(__spreadProps(__spreadValues({}, color), { colors: updated }));
1317
+ }
1318
+ return /* @__PURE__ */ jsxs6("div", { className: "space-y-2", children: [
1319
+ /* @__PURE__ */ jsxs6("div", { className: "flex items-center justify-between", children: [
1320
+ /* @__PURE__ */ jsx6("label", { className: "text-xs text-gray-400 font-medium", children: "Color Cycle" }),
1321
+ /* @__PURE__ */ jsx6(
1322
+ "button",
1323
+ {
1324
+ onClick: () => toggle(!enabled),
1325
+ className: `relative w-8 h-4 rounded-full transition-colors ${enabled ? "bg-indigo-500" : "bg-gray-600"}`,
1326
+ children: /* @__PURE__ */ jsx6("span", { className: `absolute top-0.5 w-3 h-3 rounded-full bg-white transition-transform ${enabled ? "translate-x-4" : "translate-x-0.5"}` })
1327
+ }
1328
+ )
1329
+ ] }),
1330
+ enabled && color && /* @__PURE__ */ jsxs6(Fragment2, { children: [
1331
+ /* @__PURE__ */ jsx6(
1332
+ PropertyRow,
1333
+ {
1334
+ type: "select",
1335
+ label: "Blend mode",
1336
+ value: color.tintMode,
1337
+ options: [
1338
+ { value: "source-in", label: "Silhouette" },
1339
+ { value: "multiply", label: "Multiply" },
1340
+ { value: "overlay", label: "Overlay" },
1341
+ { value: "luminance", label: "Light parts" }
1342
+ ],
1343
+ onChange: (v) => update({ tintMode: v })
1344
+ }
1345
+ ),
1346
+ /* @__PURE__ */ jsx6(
1347
+ PropertyRow,
1348
+ {
1349
+ type: "select",
1350
+ label: "Step mode",
1351
+ value: color.step.mode,
1352
+ options: [
1353
+ { value: "sequence", label: "Sequence" },
1354
+ { value: "random", label: "Random" }
1355
+ ],
1356
+ onChange: (v) => {
1357
+ const step = v === "random" ? { mode: "random", seed: Math.floor(Math.random() * 999999) + 1 } : { mode: "sequence" };
1358
+ update({ step });
1359
+ }
1360
+ }
1361
+ ),
1362
+ /* @__PURE__ */ jsxs6("div", { className: "space-y-1", children: [
1363
+ /* @__PURE__ */ jsxs6("span", { className: "text-[11px] text-gray-500", children: [
1364
+ "Colors (",
1365
+ color.colors.length,
1366
+ ")"
1367
+ ] }),
1368
+ /* @__PURE__ */ jsx6("div", { className: "flex flex-wrap gap-1.5", children: color.colors.map((c, i) => /* @__PURE__ */ jsxs6("div", { className: "relative group", children: [
1369
+ /* @__PURE__ */ jsx6(
1370
+ "input",
1371
+ {
1372
+ type: "color",
1373
+ value: c,
1374
+ onChange: (e) => updateColor(i, e.target.value),
1375
+ className: "w-7 h-7 rounded border border-gray-600 cursor-pointer bg-transparent",
1376
+ title: c
1377
+ }
1378
+ ),
1379
+ /* @__PURE__ */ jsx6(
1380
+ "button",
1381
+ {
1382
+ onClick: () => removeColor(i),
1383
+ className: "absolute -top-1 -right-1 w-3.5 h-3.5 rounded-full bg-gray-700 text-gray-300 text-[8px] leading-none hidden group-hover:flex items-center justify-center",
1384
+ children: "\u2715"
1385
+ }
1386
+ )
1387
+ ] }, i)) })
1388
+ ] }),
1389
+ /* @__PURE__ */ jsxs6("div", { className: "flex items-center gap-2", children: [
1390
+ /* @__PURE__ */ jsx6(
1391
+ "input",
1392
+ {
1393
+ type: "color",
1394
+ value: newColor,
1395
+ onChange: (e) => setNewColor(e.target.value),
1396
+ className: "w-7 h-7 rounded border border-gray-600 cursor-pointer bg-transparent"
1397
+ }
1398
+ ),
1399
+ /* @__PURE__ */ jsx6(
1400
+ "button",
1401
+ {
1402
+ onClick: addColor,
1403
+ className: "px-2 py-0.5 text-[11px] rounded bg-gray-700 text-gray-300 hover:bg-gray-600 hover:text-white",
1404
+ children: "+ Add color"
1405
+ }
1406
+ ),
1407
+ color.colors.length > 0 && /* @__PURE__ */ jsx6(
1408
+ "button",
1409
+ {
1410
+ onClick: () => update({ colors: [] }),
1411
+ className: "px-2 py-0.5 text-[11px] rounded bg-gray-700 text-gray-400 hover:bg-gray-600 hover:text-white",
1412
+ children: "Clear"
1413
+ }
1414
+ )
1415
+ ] })
1416
+ ] })
1417
+ ] });
1418
+ }
1419
+
1420
+ // src/components/PatternStudio.tsx
1421
+ import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
1422
+ function PatternStudio({ initialConfig, onChange, className }) {
1423
+ const [config, setConfig] = useState4(() => __spreadProps(__spreadValues(__spreadValues({}, DEFAULT_CONFIG), initialConfig), {
1424
+ canvas: __spreadValues(__spreadValues({}, DEFAULT_CONFIG.canvas), initialConfig == null ? void 0 : initialConfig.canvas),
1425
+ jitter: __spreadValues(__spreadValues({}, DEFAULT_CONFIG.jitter), initialConfig == null ? void 0 : initialConfig.jitter),
1426
+ distanceFalloff: __spreadValues(__spreadValues({}, DEFAULT_CONFIG.distanceFalloff), initialConfig == null ? void 0 : initialConfig.distanceFalloff)
1427
+ }));
1428
+ const [exportFormat, setExportFormat] = useState4("svg");
1429
+ const [svgExportWidth, setSvgExportWidth] = useState4(1920);
1430
+ const [svgExportHeight, setSvgExportHeight] = useState4(1080);
1431
+ const [exporting, setExporting] = useState4(false);
1432
+ const update = useCallback2((patch) => {
1433
+ setConfig((prev) => {
1434
+ const next = __spreadValues(__spreadValues({}, prev), patch);
1435
+ onChange == null ? void 0 : onChange(next);
1436
+ return next;
1437
+ });
1438
+ }, [onChange]);
1439
+ async function handleExport() {
1440
+ setExporting(true);
1441
+ try {
1442
+ if (exportFormat === "svg") {
1443
+ await downloadSvg(config, "pattern.svg", svgExportWidth, svgExportHeight);
1444
+ } else {
1445
+ await downloadPattern(config, "pattern", exportFormat);
1446
+ }
1447
+ } finally {
1448
+ setExporting(false);
1449
+ }
1450
+ }
1451
+ function applyPreset(key) {
1452
+ const preset = PRESETS[key];
1453
+ if (!preset) return;
1454
+ const next = __spreadProps(__spreadValues(__spreadValues({}, config), preset.config), {
1455
+ canvas: __spreadValues(__spreadValues({}, config.canvas), preset.config.canvas),
1456
+ jitter: __spreadValues(__spreadValues({}, config.jitter), preset.config.jitter),
1457
+ distanceFalloff: __spreadValues({}, config.distanceFalloff)
1458
+ });
1459
+ setConfig(next);
1460
+ onChange == null ? void 0 : onChange(next);
1461
+ }
1462
+ function updateJitter(patch) {
1463
+ update({ jitter: __spreadValues(__spreadValues({}, config.jitter), patch) });
1464
+ }
1465
+ function updateFalloff(patch) {
1466
+ update({ distanceFalloff: __spreadValues(__spreadValues({}, config.distanceFalloff), patch) });
1467
+ }
1468
+ return /* @__PURE__ */ jsxs7("div", { className: `flex h-full bg-gray-950 text-white overflow-hidden ${className != null ? className : ""}`, children: [
1469
+ /* @__PURE__ */ jsxs7("div", { className: "w-72 shrink-0 flex flex-col border-r border-gray-800 overflow-y-auto", children: [
1470
+ /* @__PURE__ */ jsxs7("div", { className: "p-3 space-y-5 flex-1", children: [
1471
+ /* @__PURE__ */ jsxs7("section", { children: [
1472
+ /* @__PURE__ */ jsx7("label", { className: "text-xs text-gray-400 font-medium block mb-1.5", children: "Presets" }),
1473
+ /* @__PURE__ */ jsx7("div", { className: "grid grid-cols-3 gap-1", children: Object.entries(PRESETS).map(([key, p]) => /* @__PURE__ */ jsx7(
1474
+ "button",
1475
+ {
1476
+ onClick: () => applyPreset(key),
1477
+ className: "px-1.5 py-1.5 text-[10px] rounded bg-gray-800 text-gray-300 hover:bg-gray-700 hover:text-white transition-colors text-center leading-tight",
1478
+ children: p.label
1479
+ },
1480
+ key
1481
+ )) })
1482
+ ] }),
1483
+ /* @__PURE__ */ jsxs7("section", { className: "space-y-2", children: [
1484
+ /* @__PURE__ */ jsx7("label", { className: "text-xs text-gray-400 font-medium block", children: "Canvas" }),
1485
+ /* @__PURE__ */ jsx7(
1486
+ PropertyRow,
1487
+ {
1488
+ type: "slider",
1489
+ label: "Width",
1490
+ value: config.canvas.width,
1491
+ min: 100,
1492
+ max: 2400,
1493
+ step: 50,
1494
+ onChange: (v) => update({ canvas: __spreadProps(__spreadValues({}, config.canvas), { width: v }) })
1495
+ }
1496
+ ),
1497
+ /* @__PURE__ */ jsx7(
1498
+ PropertyRow,
1499
+ {
1500
+ type: "slider",
1501
+ label: "Height",
1502
+ value: config.canvas.height,
1503
+ min: 100,
1504
+ max: 2400,
1505
+ step: 50,
1506
+ onChange: (v) => update({ canvas: __spreadProps(__spreadValues({}, config.canvas), { height: v }) })
1507
+ }
1508
+ ),
1509
+ /* @__PURE__ */ jsxs7("div", { className: "flex items-center justify-between", children: [
1510
+ /* @__PURE__ */ jsx7("span", { className: "text-xs text-gray-400", children: "Background" }),
1511
+ /* @__PURE__ */ jsxs7("div", { className: "flex items-center gap-2", children: [
1512
+ /* @__PURE__ */ jsx7(
1513
+ "input",
1514
+ {
1515
+ type: "color",
1516
+ value: config.canvas.background || "#000000",
1517
+ onChange: (e) => update({ canvas: __spreadProps(__spreadValues({}, config.canvas), { background: e.target.value }) }),
1518
+ className: "w-6 h-6 rounded border border-gray-600 cursor-pointer bg-transparent"
1519
+ }
1520
+ ),
1521
+ /* @__PURE__ */ jsx7(
1522
+ "button",
1523
+ {
1524
+ onClick: () => update({ canvas: __spreadProps(__spreadValues({}, config.canvas), { background: "" }) }),
1525
+ className: "text-[10px] text-gray-500 hover:text-gray-300",
1526
+ title: "Transparent",
1527
+ children: "\u2298"
1528
+ }
1529
+ )
1530
+ ] })
1531
+ ] })
1532
+ ] }),
1533
+ /* @__PURE__ */ jsx7("section", { children: /* @__PURE__ */ jsx7(
1534
+ SourceEditor,
1535
+ {
1536
+ sources: config.sources,
1537
+ onChange: (sources) => update({ sources })
1538
+ }
1539
+ ) }),
1540
+ config.sources.length > 1 && /* @__PURE__ */ jsxs7("section", { className: "space-y-2", children: [
1541
+ /* @__PURE__ */ jsx7("label", { className: "text-xs text-gray-400 font-medium block", children: "Source Distribution" }),
1542
+ /* @__PURE__ */ jsx7(
1543
+ PropertyRow,
1544
+ {
1545
+ type: "select",
1546
+ label: "Mode",
1547
+ value: config.sourceDistribution,
1548
+ options: [
1549
+ { value: "sequential", label: "Sequential" },
1550
+ { value: "random", label: "Random" }
1551
+ ],
1552
+ onChange: (v) => update({ sourceDistribution: v })
1553
+ }
1554
+ )
1555
+ ] }),
1556
+ /* @__PURE__ */ jsx7("section", { children: /* @__PURE__ */ jsx7(
1557
+ ArrangementEditor,
1558
+ {
1559
+ arrangement: config.arrangement,
1560
+ onChange: (arrangement) => update({ arrangement })
1561
+ }
1562
+ ) }),
1563
+ /* @__PURE__ */ jsx7("section", { children: /* @__PURE__ */ jsx7(
1564
+ StepEditor,
1565
+ {
1566
+ label: "Scale",
1567
+ range: config.scale,
1568
+ bounds: { min: 0.05, max: 10, step: 0.05 },
1569
+ onChange: (scale) => update({ scale })
1570
+ }
1571
+ ) }),
1572
+ /* @__PURE__ */ jsx7("section", { children: /* @__PURE__ */ jsx7(
1573
+ StepEditor,
1574
+ {
1575
+ label: "Opacity",
1576
+ range: config.opacity,
1577
+ bounds: { min: 0, max: 1, step: 0.05 },
1578
+ onChange: (opacity) => update({ opacity })
1579
+ }
1580
+ ) }),
1581
+ /* @__PURE__ */ jsx7("section", { children: /* @__PURE__ */ jsx7(
1582
+ StepEditor,
1583
+ {
1584
+ label: "Rotation",
1585
+ range: config.rotation,
1586
+ bounds: { min: -360, max: 360, step: 1 },
1587
+ onChange: (rotation) => update({ rotation }),
1588
+ format: (v) => `${v}\xB0`
1589
+ }
1590
+ ) }),
1591
+ /* @__PURE__ */ jsx7("section", { children: /* @__PURE__ */ jsx7(
1592
+ ColorEditor,
1593
+ {
1594
+ color: config.color,
1595
+ onChange: (color) => update({ color })
1596
+ }
1597
+ ) }),
1598
+ /* @__PURE__ */ jsxs7("section", { className: "space-y-2", children: [
1599
+ /* @__PURE__ */ jsx7("label", { className: "text-xs text-gray-400 font-medium block", children: "Jitter" }),
1600
+ /* @__PURE__ */ jsx7("p", { className: "text-[11px] text-gray-500", children: "Per-copy randomness \u2014 seeded, reproducible." }),
1601
+ /* @__PURE__ */ jsx7(PropertyRow, { type: "slider", label: "Position", value: config.jitter.position, min: 0, max: 200, step: 1, onChange: (v) => updateJitter({ position: v }) }),
1602
+ /* @__PURE__ */ jsx7(PropertyRow, { type: "slider", label: "Rotation", value: config.jitter.rotation, min: 0, max: 180, step: 1, onChange: (v) => updateJitter({ rotation: v }), format: (v) => `${v}\xB0` }),
1603
+ /* @__PURE__ */ jsx7(PropertyRow, { type: "slider", label: "Scale", value: config.jitter.scale, min: 0, max: 1, step: 0.05, onChange: (v) => updateJitter({ scale: v }) }),
1604
+ (config.jitter.position > 0 || config.jitter.rotation > 0 || config.jitter.scale > 0) && /* @__PURE__ */ jsxs7("div", { className: "flex items-center justify-between", children: [
1605
+ /* @__PURE__ */ jsx7("span", { className: "text-xs text-gray-400", children: "Seed" }),
1606
+ /* @__PURE__ */ jsxs7("div", { className: "flex items-center gap-1", children: [
1607
+ /* @__PURE__ */ jsx7("span", { className: "text-xs text-gray-300 tabular-nums", children: config.jitter.seed }),
1608
+ /* @__PURE__ */ jsx7(
1609
+ "button",
1610
+ {
1611
+ onClick: () => updateJitter({ seed: Math.floor(Math.random() * 999999) + 1 }),
1612
+ className: "text-[10px] text-gray-500 hover:text-white px-1 py-0.5 rounded hover:bg-gray-700",
1613
+ title: "Reshuffle",
1614
+ children: "\u27F3"
1615
+ }
1616
+ )
1617
+ ] })
1618
+ ] })
1619
+ ] }),
1620
+ /* @__PURE__ */ jsxs7("section", { className: "space-y-2", children: [
1621
+ /* @__PURE__ */ jsx7("label", { className: "text-xs text-gray-400 font-medium block", children: "Distance Falloff" }),
1622
+ /* @__PURE__ */ jsx7(PropertyRow, { type: "slider", label: "Scale at edge", value: config.distanceFalloff.scaleEnd, min: 0.1, max: 3, step: 0.05, onChange: (v) => updateFalloff({ scaleEnd: v }) }),
1623
+ /* @__PURE__ */ jsx7(PropertyRow, { type: "slider", label: "Opacity at edge", value: config.distanceFalloff.opacityEnd, min: 0, max: 1, step: 0.05, onChange: (v) => updateFalloff({ opacityEnd: v }) })
1624
+ ] }),
1625
+ /* @__PURE__ */ jsx7("section", { children: /* @__PURE__ */ jsx7(PropertyRow, { type: "slider", label: "Max copies", value: config.maxCopies, min: 1, max: 1e3, step: 1, onChange: (v) => update({ maxCopies: v }) }) })
1626
+ ] }),
1627
+ /* @__PURE__ */ jsxs7("div", { className: "p-3 border-t border-gray-800 space-y-2", children: [
1628
+ /* @__PURE__ */ jsxs7("div", { className: "flex gap-2", children: [
1629
+ /* @__PURE__ */ jsxs7(
1630
+ "select",
1631
+ {
1632
+ value: exportFormat,
1633
+ onChange: (e) => setExportFormat(e.target.value),
1634
+ className: "bg-gray-800 border border-gray-700 rounded px-2 py-1.5 text-xs text-white",
1635
+ children: [
1636
+ /* @__PURE__ */ jsx7("option", { value: "svg", children: "SVG" }),
1637
+ /* @__PURE__ */ jsx7("option", { value: "png", children: "PNG" }),
1638
+ /* @__PURE__ */ jsx7("option", { value: "jpg", children: "JPG" }),
1639
+ /* @__PURE__ */ jsx7("option", { value: "webp", children: "WebP" })
1640
+ ]
1641
+ }
1642
+ ),
1643
+ /* @__PURE__ */ jsx7(
1644
+ "button",
1645
+ {
1646
+ onClick: handleExport,
1647
+ disabled: exporting || config.sources.length === 0,
1648
+ className: "flex-1 py-1.5 text-xs rounded bg-indigo-600 text-white hover:bg-indigo-500 disabled:opacity-40 disabled:cursor-not-allowed font-medium",
1649
+ children: exporting ? "Exporting\u2026" : "Export"
1650
+ }
1651
+ )
1652
+ ] }),
1653
+ exportFormat === "svg" && /* @__PURE__ */ jsxs7("div", { className: "flex items-center gap-1.5", children: [
1654
+ /* @__PURE__ */ jsx7("span", { className: "text-[10px] text-gray-500 shrink-0", children: "Viewport" }),
1655
+ /* @__PURE__ */ jsx7(
1656
+ "input",
1657
+ {
1658
+ type: "number",
1659
+ value: svgExportWidth,
1660
+ min: 1,
1661
+ onChange: (e) => setSvgExportWidth(parseInt(e.target.value) || 1920),
1662
+ className: "w-16 bg-gray-800 border border-gray-700 rounded px-1.5 py-1 text-xs text-white"
1663
+ }
1664
+ ),
1665
+ /* @__PURE__ */ jsx7("span", { className: "text-[10px] text-gray-600", children: "\xD7" }),
1666
+ /* @__PURE__ */ jsx7(
1667
+ "input",
1668
+ {
1669
+ type: "number",
1670
+ value: svgExportHeight,
1671
+ min: 1,
1672
+ onChange: (e) => setSvgExportHeight(parseInt(e.target.value) || 1080),
1673
+ className: "w-16 bg-gray-800 border border-gray-700 rounded px-1.5 py-1 text-xs text-white"
1674
+ }
1675
+ ),
1676
+ /* @__PURE__ */ jsx7("span", { className: "text-[10px] text-gray-600", children: "px" })
1677
+ ] })
1678
+ ] })
1679
+ ] }),
1680
+ /* @__PURE__ */ jsxs7("div", { className: "flex-1 flex flex-col min-w-0", children: [
1681
+ /* @__PURE__ */ jsx7(JsonBar, { config }),
1682
+ /* @__PURE__ */ jsx7(
1683
+ PatternPreview,
1684
+ {
1685
+ config,
1686
+ className: "flex-1"
1687
+ }
1688
+ )
1689
+ ] })
1690
+ ] });
1691
+ }
1692
+ function JsonBar({ config }) {
1693
+ const [open, setOpen] = useState4(false);
1694
+ function copyJson() {
1695
+ navigator.clipboard.writeText(JSON.stringify(config, null, 2));
1696
+ }
1697
+ return /* @__PURE__ */ jsxs7("div", { className: "border-b border-gray-800", children: [
1698
+ /* @__PURE__ */ jsxs7(
1699
+ "button",
1700
+ {
1701
+ onClick: () => setOpen((v) => !v),
1702
+ className: "w-full flex items-center justify-between px-4 py-2 text-xs text-gray-400 hover:text-white hover:bg-gray-900 transition-colors",
1703
+ children: [
1704
+ /* @__PURE__ */ jsx7("span", { children: "Config JSON" }),
1705
+ /* @__PURE__ */ jsx7("span", { children: open ? "\u25B2" : "\u25BC" })
1706
+ ]
1707
+ }
1708
+ ),
1709
+ open && /* @__PURE__ */ jsxs7("div", { className: "relative", children: [
1710
+ /* @__PURE__ */ jsx7("pre", { className: "text-[10px] text-gray-300 p-3 bg-gray-900 overflow-auto max-h-48 leading-relaxed", children: JSON.stringify(config, null, 2) }),
1711
+ /* @__PURE__ */ jsx7(
1712
+ "button",
1713
+ {
1714
+ onClick: copyJson,
1715
+ className: "absolute top-2 right-2 text-[10px] text-gray-500 hover:text-white px-2 py-1 rounded bg-gray-800 hover:bg-gray-700",
1716
+ children: "Copy"
1717
+ }
1718
+ )
1719
+ ] })
1720
+ ] });
1721
+ }
1722
+ export {
1723
+ DEFAULT_CONFIG,
1724
+ PRESETS,
1725
+ PatternPreview,
1726
+ PatternStudio,
1727
+ clearSpriteCache,
1728
+ clearSvgSourceCache,
1729
+ clearTintCache,
1730
+ computeLayout,
1731
+ defaultArrangement,
1732
+ downloadPattern,
1733
+ downloadSvg,
1734
+ fetchSource,
1735
+ isTileable,
1736
+ loadSprite,
1737
+ loadSprites,
1738
+ parseSvgMarkup,
1739
+ renderTileableSvg,
1740
+ renderToBlob,
1741
+ renderToCanvas,
1742
+ renderToDataURL,
1743
+ renderToSvg,
1744
+ renderToSvgBlob,
1745
+ resolveCopyStyle,
1746
+ seededFloat,
1747
+ seededFloat01,
1748
+ seededHash,
1749
+ seededIndex,
1750
+ stepColor,
1751
+ stepNumeric,
1752
+ tintSprite
1753
+ };
1754
+ //# sourceMappingURL=index.mjs.map