@pixerate/editor-react 0.95.0 → 0.97.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.
Files changed (56) hide show
  1. package/README.md +2 -0
  2. package/dist/animation-editor/index.cjs +1261 -198
  3. package/dist/animation-editor/index.js +4 -2
  4. package/dist/canvas/index.cjs +1439 -376
  5. package/dist/canvas/index.js +4 -2
  6. package/dist/chunk-3I7FOSLF.js +988 -0
  7. package/dist/{chunk-OTGJEYHV.js → chunk-5LFQ2UQZ.js} +75 -68
  8. package/dist/chunk-KIRIU53A.js +72 -0
  9. package/dist/{chunk-6YRSQW2V.js → chunk-NC4RLZTK.js} +1 -1
  10. package/dist/chunk-Q7LAFHGP.js +655 -0
  11. package/dist/color/ColorPicker.d.cts +30 -0
  12. package/dist/color/ColorPicker.d.ts +30 -0
  13. package/dist/color/DualColorPicker.d.cts +29 -0
  14. package/dist/color/DualColorPicker.d.ts +29 -0
  15. package/dist/color/index.cjs +1067 -0
  16. package/dist/color/index.d.cts +7 -0
  17. package/dist/color/index.d.ts +7 -0
  18. package/dist/color/index.js +14 -0
  19. package/dist/color/useColorScheme.d.cts +16 -0
  20. package/dist/color/useColorScheme.d.ts +16 -0
  21. package/dist/effects/EffectAuthoringEditor.d.cts +22 -0
  22. package/dist/effects/EffectAuthoringEditor.d.ts +22 -0
  23. package/dist/effects/EffectParameters.d.cts +5 -1
  24. package/dist/effects/EffectParameters.d.ts +5 -1
  25. package/dist/effects/index.cjs +1624 -127
  26. package/dist/effects/index.d.cts +2 -0
  27. package/dist/effects/index.d.ts +2 -0
  28. package/dist/effects/index.js +8 -2
  29. package/dist/effects/useEffectAuthoring.d.cts +6 -0
  30. package/dist/effects/useEffectAuthoring.d.ts +6 -0
  31. package/dist/gradient/FillPicker.d.cts +27 -0
  32. package/dist/gradient/FillPicker.d.ts +27 -0
  33. package/dist/gradient/GradientEditor.d.cts +21 -0
  34. package/dist/gradient/GradientEditor.d.ts +21 -0
  35. package/dist/gradient/index.cjs +1601 -0
  36. package/dist/gradient/index.d.cts +6 -0
  37. package/dist/gradient/index.d.ts +6 -0
  38. package/dist/gradient/index.js +617 -0
  39. package/dist/gradient/useGradientController.d.cts +10 -0
  40. package/dist/gradient/useGradientController.d.ts +10 -0
  41. package/dist/image-editor/index.cjs +1763 -700
  42. package/dist/image-editor/index.js +5 -3
  43. package/dist/index.cjs +2181 -1118
  44. package/dist/index.js +5 -3
  45. package/dist/paint-editor/index.cjs +1254 -191
  46. package/dist/paint-editor/index.js +4 -2
  47. package/dist/parameters/fields.d.cts +1 -1
  48. package/dist/parameters/fields.d.ts +1 -1
  49. package/dist/parameters/index.cjs +1218 -173
  50. package/dist/parameters/index.js +3 -1
  51. package/dist/vector/index.cjs +1240 -177
  52. package/dist/vector/index.js +4 -2
  53. package/dist/video-editor/index.cjs +1251 -188
  54. package/dist/video-editor/index.js +4 -2
  55. package/package.json +29 -3
  56. package/dist/chunk-5R67YSSD.js +0 -205
@@ -17,6 +17,7 @@ var __copyProps = (to, from, except, desc) => {
17
17
  }
18
18
  return to;
19
19
  };
20
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
21
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
22
  // If the importer is in node compatibility mode or this is not an ESM
22
23
  // file that has been converted to a CommonJS file using a Babel-
@@ -30,9 +31,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
31
  // src/effects/index.ts
31
32
  var effects_exports = {};
32
33
  __export(effects_exports, {
34
+ EffectAuthoringEditor: () => EffectAuthoringEditor,
33
35
  EffectParameters: () => EffectParameters,
34
36
  EffectThumbnail: () => EffectThumbnail,
35
37
  EffectsBrowser: () => EffectsBrowser,
38
+ useEffectAuthoring: () => useEffectAuthoring,
36
39
  useEffectDescription: () => useEffectDescription,
37
40
  useEffects: () => useEffects
38
41
  });
@@ -175,14 +178,1055 @@ function EffectsBrowser({ provider, uses, kinds, onPick, thumbnails = true, titl
175
178
  }
176
179
 
177
180
  // src/effects/EffectParameters.tsx
178
- var import_react5 = __toESM(require("react"), 1);
181
+ var import_react8 = __toESM(require("react"), 1);
179
182
  var import_effects3 = require("@pixerate/editor/effects");
180
183
  var import_parameters2 = require("@pixerate/editor/parameters");
181
184
 
182
185
  // src/parameters/fields.tsx
183
- var import_react4 = require("react");
186
+ var import_react7 = require("react");
184
187
  var import_parameters = require("@pixerate/editor/parameters");
188
+
189
+ // src/color/index.ts
190
+ var color_exports = {};
191
+ __export(color_exports, {
192
+ ColorPicker: () => ColorPicker,
193
+ DualColorPicker: () => DualColorPicker,
194
+ useColorScheme: () => useColorScheme,
195
+ useResolvedColor: () => useResolvedColor
196
+ });
197
+
198
+ // src/color/ColorPicker.tsx
199
+ var import_react4 = require("react");
200
+ var import_color = require("@pixerate/editor/color");
185
201
  var import_jsx_runtime3 = require("react/jsx-runtime");
202
+ var LOCAL_STORAGE_KEY = "pixerate:color:recent";
203
+ function readLocalRecents() {
204
+ try {
205
+ if (typeof localStorage === "undefined") return [];
206
+ const raw = localStorage.getItem(LOCAL_STORAGE_KEY);
207
+ if (!raw) return [];
208
+ const parsed = JSON.parse(raw);
209
+ return Array.isArray(parsed) ? parsed : [];
210
+ } catch {
211
+ return [];
212
+ }
213
+ }
214
+ function writeLocalRecents(list) {
215
+ try {
216
+ if (typeof localStorage !== "undefined") {
217
+ localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(list));
218
+ }
219
+ } catch {
220
+ }
221
+ }
222
+ var CHECKERBOARD_BG = "repeating-conic-gradient(var(--pixerate-checker-a, #d4d4d8) 0 25%, var(--pixerate-checker-b, #ffffff) 0 50%)";
223
+ var DEFAULT_PICKER_STATE = { h: 0, s: 1, v: 1, alpha: 1 };
224
+ var ColorPicker = ({
225
+ value,
226
+ onChange,
227
+ onGestureStart,
228
+ onGestureEnd,
229
+ alpha = false,
230
+ swatches,
231
+ recent: controlledRecent,
232
+ onRecentChange,
233
+ contrastAgainst,
234
+ disabled = false,
235
+ className,
236
+ id,
237
+ "aria-label": ariaLabel = "Color picker"
238
+ }) => {
239
+ const generatedId = (0, import_react4.useId)();
240
+ const pickerId = id || generatedId;
241
+ const [pickerState, setPickerState] = (0, import_react4.useState)(
242
+ () => (0, import_color.pickerStateFromColor)(value) ?? DEFAULT_PICKER_STATE
243
+ );
244
+ const stateRef = (0, import_react4.useRef)(pickerState);
245
+ stateRef.current = pickerState;
246
+ (0, import_react4.useEffect)(() => {
247
+ const next = (0, import_color.pickerStateFromColor)(value, stateRef.current);
248
+ if (next) {
249
+ setPickerState(next);
250
+ }
251
+ }, [value]);
252
+ const [internalRecent, setInternalRecent] = (0, import_react4.useState)(
253
+ () => controlledRecent ? [] : readLocalRecents()
254
+ );
255
+ const activeRecent = controlledRecent ?? internalRecent;
256
+ const recordRecent = (0, import_react4.useCallback)(
257
+ (color) => {
258
+ const updated = (0, import_color.pushRecentColor)(activeRecent, color, 12);
259
+ if (!controlledRecent) {
260
+ setInternalRecent(updated);
261
+ writeLocalRecents(updated);
262
+ }
263
+ onRecentChange?.(updated);
264
+ },
265
+ [activeRecent, controlledRecent, onRecentChange]
266
+ );
267
+ const [textDraft, setTextDraft] = (0, import_react4.useState)(value);
268
+ const [isInvalid, setIsInvalid] = (0, import_react4.useState)(false);
269
+ const [isClipped, setIsClipped] = (0, import_react4.useState)(false);
270
+ const isTypingRef = (0, import_react4.useRef)(false);
271
+ (0, import_react4.useEffect)(() => {
272
+ if (!isTypingRef.current) {
273
+ setTextDraft(value);
274
+ setIsInvalid(false);
275
+ const parsed = (0, import_color.parseColor)(value);
276
+ setIsClipped(Boolean(parsed && !(0, import_color.inSrgbGamut)(parsed)));
277
+ }
278
+ }, [value]);
279
+ const [hasEyeDropper, setHasEyeDropper] = (0, import_react4.useState)(false);
280
+ (0, import_react4.useEffect)(() => {
281
+ setHasEyeDropper(typeof window !== "undefined" && "EyeDropper" in window);
282
+ }, []);
283
+ const emitColorChange = (0, import_react4.useCallback)(
284
+ (nextState) => {
285
+ setPickerState(nextState);
286
+ const hex = (0, import_color.pickerStateToHex)(nextState, alpha);
287
+ onChange(hex);
288
+ },
289
+ [alpha, onChange]
290
+ );
291
+ const latest = (0, import_react4.useRef)({ emitColorChange, recordRecent, onGestureEnd, alpha });
292
+ latest.current = { emitColorChange, recordRecent, onGestureEnd, alpha };
293
+ const endDragRef = (0, import_react4.useRef)(null);
294
+ (0, import_react4.useEffect)(() => () => endDragRef.current?.(), []);
295
+ const startDrag = (e, next) => {
296
+ if (disabled) return;
297
+ e.preventDefault();
298
+ endDragRef.current?.();
299
+ onGestureStart?.();
300
+ const rect = e.currentTarget.getBoundingClientRect();
301
+ const update = (clientX, clientY) => {
302
+ const x = Math.max(0, Math.min(1, (clientX - rect.left) / rect.width));
303
+ const y = Math.max(0, Math.min(1, (clientY - rect.top) / rect.height));
304
+ latest.current.emitColorChange(next(stateRef.current, x, y));
305
+ };
306
+ update(e.clientX, e.clientY);
307
+ const onPointerMove = (ev) => update(ev.clientX, ev.clientY);
308
+ const end = () => {
309
+ window.removeEventListener("pointermove", onPointerMove);
310
+ window.removeEventListener("pointerup", onPointerUp);
311
+ window.removeEventListener("pointercancel", onPointerUp);
312
+ endDragRef.current = null;
313
+ latest.current.onGestureEnd?.();
314
+ };
315
+ const onPointerUp = () => {
316
+ end();
317
+ latest.current.recordRecent((0, import_color.pickerStateToHex)(stateRef.current, latest.current.alpha));
318
+ };
319
+ endDragRef.current = end;
320
+ window.addEventListener("pointermove", onPointerMove);
321
+ window.addEventListener("pointerup", onPointerUp);
322
+ window.addEventListener("pointercancel", onPointerUp);
323
+ };
324
+ const handleAreaPointerDown = (e) => startDrag(e, (state, x, y) => (0, import_color.pickerStateFromArea)(state, x, y));
325
+ const handleHuePointerDown = (e) => startDrag(e, (state, x) => (0, import_color.pickerStateFromHue)(state, x));
326
+ const handleAlphaPointerDown = (e) => startDrag(e, (state, x) => (0, import_color.pickerStateFromAlpha)(state, x));
327
+ const handleAreaKeyDown = (e) => {
328
+ if (disabled) return;
329
+ const next = (0, import_color.pickerKeyStep)(pickerState, "area", e.key, e.shiftKey);
330
+ if (next) {
331
+ e.preventDefault();
332
+ emitColorChange(next);
333
+ recordRecent((0, import_color.pickerStateToHex)(next, alpha));
334
+ }
335
+ };
336
+ const handleHueKeyDown = (e) => {
337
+ if (disabled) return;
338
+ const next = (0, import_color.pickerKeyStep)(pickerState, "hue", e.key, e.shiftKey);
339
+ if (next) {
340
+ e.preventDefault();
341
+ emitColorChange(next);
342
+ recordRecent((0, import_color.pickerStateToHex)(next, alpha));
343
+ }
344
+ };
345
+ const handleAlphaKeyDown = (e) => {
346
+ if (disabled) return;
347
+ const next = (0, import_color.pickerKeyStep)(pickerState, "alpha", e.key, e.shiftKey);
348
+ if (next) {
349
+ e.preventDefault();
350
+ emitColorChange(next);
351
+ recordRecent((0, import_color.pickerStateToHex)(next, alpha));
352
+ }
353
+ };
354
+ const commitTextInput = (inputElement) => {
355
+ isTypingRef.current = false;
356
+ const parsed = (0, import_color.parseColor)(textDraft);
357
+ if (parsed) {
358
+ setIsInvalid(false);
359
+ setIsClipped(!(0, import_color.inSrgbGamut)(parsed));
360
+ const formatted = (0, import_color.formatHex)(parsed);
361
+ onChange(formatted);
362
+ recordRecent(formatted);
363
+ } else {
364
+ setIsInvalid(true);
365
+ setTextDraft(value);
366
+ if (inputElement) {
367
+ inputElement.value = value;
368
+ }
369
+ }
370
+ };
371
+ const handleTextKeyDown = (e) => {
372
+ if (e.key === "Enter") {
373
+ e.preventDefault();
374
+ commitTextInput(e.currentTarget);
375
+ } else if (e.key === "Escape") {
376
+ e.preventDefault();
377
+ isTypingRef.current = false;
378
+ setIsInvalid(false);
379
+ setTextDraft(value);
380
+ e.currentTarget.value = value;
381
+ }
382
+ };
383
+ const handleEyeDropper = async () => {
384
+ if (disabled || !hasEyeDropper) return;
385
+ try {
386
+ const EyeDropperClass = window.EyeDropper;
387
+ const eyeDropper = new EyeDropperClass();
388
+ const res = await eyeDropper.open();
389
+ if (res?.sRGBHex) {
390
+ onChange(res.sRGBHex);
391
+ recordRecent(res.sRGBHex);
392
+ }
393
+ } catch {
394
+ }
395
+ };
396
+ const contrastResult = (0, import_react4.useMemo)(() => {
397
+ if (!contrastAgainst) return null;
398
+ const fg = (0, import_color.parseColor)(value);
399
+ const bg = (0, import_color.parseColor)(contrastAgainst);
400
+ if (!fg || !bg) return null;
401
+ const ratio = (0, import_color.contrastRatio)(fg, bg);
402
+ const aa = ratio >= 4.5;
403
+ const aaa = ratio >= 7;
404
+ return { ratio, aa, aaa };
405
+ }, [value, contrastAgainst]);
406
+ const currentHex = (0, import_color.pickerStateToHex)(pickerState, alpha);
407
+ const liveDescription = `Selected color: ${value}${contrastResult ? `, contrast ${contrastResult.ratio.toFixed(1)}:1 against ${contrastAgainst}, ${contrastResult.aa ? "passes AA" : "fails AA"}` : ""}`;
408
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
409
+ "div",
410
+ {
411
+ id: pickerId,
412
+ role: "group",
413
+ "aria-label": ariaLabel,
414
+ className,
415
+ style: {
416
+ boxSizing: "border-box",
417
+ width: "var(--pixerate-color-picker-width, 240px)",
418
+ borderRadius: "var(--pixerate-color-picker-radius, 8px)",
419
+ background: "var(--pixerate-color-picker-bg, #1f2430)",
420
+ color: "var(--pixerate-color-picker-fg, #f0f2f5)",
421
+ padding: "12px",
422
+ display: "flex",
423
+ flexDirection: "column",
424
+ gap: "10px",
425
+ fontFamily: "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
426
+ fontSize: "12px",
427
+ userSelect: "none",
428
+ opacity: disabled ? 0.6 : 1,
429
+ pointerEvents: disabled ? "none" : "auto"
430
+ },
431
+ children: [
432
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
433
+ "span",
434
+ {
435
+ role: "status",
436
+ "aria-live": "polite",
437
+ style: {
438
+ position: "absolute",
439
+ width: "1px",
440
+ height: "1px",
441
+ padding: 0,
442
+ margin: "-1px",
443
+ overflow: "hidden",
444
+ clip: "rect(0, 0, 0, 0)",
445
+ whiteSpace: "nowrap",
446
+ border: 0
447
+ },
448
+ children: liveDescription
449
+ }
450
+ ),
451
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
452
+ "div",
453
+ {
454
+ role: "slider",
455
+ tabIndex: disabled ? -1 : 0,
456
+ "aria-label": "Saturation and brightness",
457
+ "aria-valuetext": `Saturation ${Math.round(pickerState.s * 100)}%, Brightness ${Math.round(
458
+ pickerState.v * 100
459
+ )}%`,
460
+ "aria-disabled": disabled,
461
+ onPointerDown: handleAreaPointerDown,
462
+ onKeyDown: handleAreaKeyDown,
463
+ style: {
464
+ position: "relative",
465
+ width: "100%",
466
+ height: "150px",
467
+ borderRadius: "6px",
468
+ background: (0, import_color.pickerAreaBackground)(pickerState),
469
+ cursor: disabled ? "default" : "crosshair",
470
+ touchAction: "none",
471
+ outline: "none"
472
+ },
473
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
474
+ "div",
475
+ {
476
+ style: {
477
+ position: "absolute",
478
+ width: "var(--pixerate-color-picker-thumb-size, 14px)",
479
+ height: "var(--pixerate-color-picker-thumb-size, 14px)",
480
+ borderRadius: "50%",
481
+ transform: "translate(-50%, -50%)",
482
+ left: `${pickerState.s * 100}%`,
483
+ top: `${(1 - pickerState.v) * 100}%`,
484
+ border: "2px solid #ffffff",
485
+ boxShadow: "0 0 2px 1px rgba(0,0,0,0.6)",
486
+ pointerEvents: "none",
487
+ backgroundColor: currentHex
488
+ }
489
+ }
490
+ )
491
+ }
492
+ ),
493
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
494
+ "div",
495
+ {
496
+ role: "slider",
497
+ tabIndex: disabled ? -1 : 0,
498
+ "aria-label": "Hue",
499
+ "aria-valuenow": Math.round(pickerState.h),
500
+ "aria-valuemin": 0,
501
+ "aria-valuemax": 360,
502
+ "aria-valuetext": `${Math.round(pickerState.h)} degrees`,
503
+ "aria-disabled": disabled,
504
+ onPointerDown: handleHuePointerDown,
505
+ onKeyDown: handleHueKeyDown,
506
+ style: {
507
+ position: "relative",
508
+ width: "100%",
509
+ height: "12px",
510
+ borderRadius: "6px",
511
+ background: import_color.PICKER_HUE_BACKGROUND,
512
+ cursor: disabled ? "default" : "pointer",
513
+ touchAction: "none",
514
+ outline: "none"
515
+ },
516
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
517
+ "div",
518
+ {
519
+ style: {
520
+ position: "absolute",
521
+ top: "50%",
522
+ transform: "translate(-50%, -50%)",
523
+ left: `${pickerState.h / 360 * 100}%`,
524
+ width: "var(--pixerate-color-picker-thumb-size, 14px)",
525
+ height: "var(--pixerate-color-picker-thumb-size, 14px)",
526
+ borderRadius: "50%",
527
+ border: "2px solid #ffffff",
528
+ boxShadow: "0 0 2px 1px rgba(0,0,0,0.6)",
529
+ pointerEvents: "none",
530
+ backgroundColor: `hsl(${pickerState.h}, 100%, 50%)`
531
+ }
532
+ }
533
+ )
534
+ }
535
+ ),
536
+ alpha && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
537
+ "div",
538
+ {
539
+ role: "slider",
540
+ tabIndex: disabled ? -1 : 0,
541
+ "aria-label": "Alpha",
542
+ "aria-valuenow": Math.round(pickerState.alpha * 100),
543
+ "aria-valuemin": 0,
544
+ "aria-valuemax": 100,
545
+ "aria-valuetext": `${Math.round(pickerState.alpha * 100)}%`,
546
+ "aria-disabled": disabled,
547
+ onPointerDown: handleAlphaPointerDown,
548
+ onKeyDown: handleAlphaKeyDown,
549
+ style: {
550
+ position: "relative",
551
+ width: "100%",
552
+ height: "12px",
553
+ borderRadius: "6px",
554
+ backgroundImage: CHECKERBOARD_BG,
555
+ backgroundSize: "8px 8px",
556
+ cursor: disabled ? "default" : "pointer",
557
+ touchAction: "none",
558
+ outline: "none",
559
+ overflow: "hidden"
560
+ },
561
+ children: [
562
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
563
+ "div",
564
+ {
565
+ style: {
566
+ position: "absolute",
567
+ inset: 0,
568
+ background: (0, import_color.pickerAlphaBackground)(pickerState)
569
+ }
570
+ }
571
+ ),
572
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
573
+ "div",
574
+ {
575
+ style: {
576
+ position: "absolute",
577
+ top: "50%",
578
+ transform: "translate(-50%, -50%)",
579
+ left: `${pickerState.alpha * 100}%`,
580
+ width: "var(--pixerate-color-picker-thumb-size, 14px)",
581
+ height: "var(--pixerate-color-picker-thumb-size, 14px)",
582
+ borderRadius: "50%",
583
+ border: "2px solid #ffffff",
584
+ boxShadow: "0 0 2px 1px rgba(0,0,0,0.6)",
585
+ pointerEvents: "none",
586
+ backgroundColor: currentHex
587
+ }
588
+ }
589
+ )
590
+ ]
591
+ }
592
+ ),
593
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "8px", marginTop: "2px" }, children: [
594
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
595
+ "div",
596
+ {
597
+ style: {
598
+ position: "relative",
599
+ width: "28px",
600
+ height: "28px",
601
+ borderRadius: "4px",
602
+ backgroundImage: CHECKERBOARD_BG,
603
+ backgroundSize: "8px 8px",
604
+ overflow: "hidden",
605
+ flexShrink: 0,
606
+ border: "1px solid rgba(255,255,255,0.15)"
607
+ },
608
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
609
+ "div",
610
+ {
611
+ style: {
612
+ width: "100%",
613
+ height: "100%",
614
+ backgroundColor: currentHex
615
+ }
616
+ }
617
+ )
618
+ }
619
+ ),
620
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
621
+ "input",
622
+ {
623
+ type: "text",
624
+ value: textDraft,
625
+ disabled,
626
+ "aria-label": "Color hex or CSS string",
627
+ "aria-invalid": isInvalid ? "true" : void 0,
628
+ onChange: (e) => {
629
+ isTypingRef.current = true;
630
+ setTextDraft(e.target.value);
631
+ setIsInvalid(false);
632
+ },
633
+ onKeyDown: handleTextKeyDown,
634
+ onBlur: (e) => commitTextInput(e.currentTarget),
635
+ style: {
636
+ flex: 1,
637
+ minWidth: 0,
638
+ height: "28px",
639
+ padding: "0 8px",
640
+ fontSize: "12px",
641
+ fontFamily: "monospace",
642
+ borderRadius: "4px",
643
+ border: isInvalid ? "1px solid #ef4444" : "1px solid rgba(255,255,255,0.2)",
644
+ background: "rgba(0,0,0,0.2)",
645
+ color: "inherit",
646
+ outline: "none"
647
+ }
648
+ }
649
+ ),
650
+ hasEyeDropper && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
651
+ "button",
652
+ {
653
+ type: "button",
654
+ disabled,
655
+ "aria-label": "Pick color from screen",
656
+ title: "Pick color from screen",
657
+ onClick: handleEyeDropper,
658
+ style: {
659
+ display: "inline-flex",
660
+ alignItems: "center",
661
+ justifyContent: "center",
662
+ width: "28px",
663
+ height: "28px",
664
+ borderRadius: "4px",
665
+ border: "1px solid rgba(255,255,255,0.2)",
666
+ background: "transparent",
667
+ color: "inherit",
668
+ cursor: disabled ? "default" : "pointer"
669
+ },
670
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
671
+ "svg",
672
+ {
673
+ width: "14",
674
+ height: "14",
675
+ viewBox: "0 0 24 24",
676
+ fill: "none",
677
+ stroke: "currentColor",
678
+ strokeWidth: "2",
679
+ strokeLinecap: "round",
680
+ strokeLinejoin: "round",
681
+ children: [
682
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m19 11-8-8-8.5 8.5a2.12 2.12 0 0 0 0 3l2.5 2.5 1.5-1.5" }),
683
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m5 16-3 3 1 1 3-3" }),
684
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m14 6 4 4" })
685
+ ]
686
+ }
687
+ )
688
+ }
689
+ )
690
+ ] }),
691
+ isClipped && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
692
+ "div",
693
+ {
694
+ role: "note",
695
+ title: "This colour was outside standard sRGB and clipped.",
696
+ style: {
697
+ display: "inline-flex",
698
+ alignItems: "center",
699
+ gap: "4px",
700
+ fontSize: "10px",
701
+ color: "#f59e0b",
702
+ background: "rgba(245, 158, 11, 0.1)",
703
+ padding: "2px 6px",
704
+ borderRadius: "4px",
705
+ alignSelf: "flex-start"
706
+ },
707
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: "\u26A0 Clipped to sRGB" })
708
+ }
709
+ ),
710
+ contrastResult && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
711
+ "div",
712
+ {
713
+ style: {
714
+ display: "flex",
715
+ alignItems: "center",
716
+ justifyContent: "space-between",
717
+ fontSize: "11px",
718
+ padding: "4px 8px",
719
+ borderRadius: "4px",
720
+ background: "rgba(255,255,255,0.05)",
721
+ border: "1px solid rgba(255,255,255,0.1)"
722
+ },
723
+ children: [
724
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { children: [
725
+ "Contrast: ",
726
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("strong", { children: [
727
+ contrastResult.ratio.toFixed(2),
728
+ ":1"
729
+ ] })
730
+ ] }),
731
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "flex", gap: "6px" }, children: [
732
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
733
+ "span",
734
+ {
735
+ style: {
736
+ color: contrastResult.aa ? "#10b981" : "#ef4444",
737
+ fontWeight: 600
738
+ },
739
+ children: [
740
+ "AA ",
741
+ contrastResult.aa ? "\u2713" : "\u2717"
742
+ ]
743
+ }
744
+ ),
745
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
746
+ "span",
747
+ {
748
+ style: {
749
+ color: contrastResult.aaa ? "#10b981" : "#ef4444",
750
+ fontWeight: 600
751
+ },
752
+ children: [
753
+ "AAA ",
754
+ contrastResult.aaa ? "\u2713" : "\u2717"
755
+ ]
756
+ }
757
+ )
758
+ ] })
759
+ ]
760
+ }
761
+ ),
762
+ swatches && swatches.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: "4px" }, children: [
763
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontSize: "10px", textTransform: "uppercase", opacity: 0.6 }, children: "Palette" }),
764
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { display: "flex", flexWrap: "wrap", gap: "4px" }, children: swatches.map((color, idx) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
765
+ "button",
766
+ {
767
+ type: "button",
768
+ "data-testid": "color-picker-swatch",
769
+ title: color,
770
+ disabled,
771
+ "aria-label": `Color ${color}`,
772
+ onClick: () => {
773
+ onChange(color);
774
+ recordRecent(color);
775
+ },
776
+ style: {
777
+ width: "18px",
778
+ height: "18px",
779
+ borderRadius: "3px",
780
+ backgroundColor: color,
781
+ border: color.toLowerCase() === value.toLowerCase() ? "2px solid #ffffff" : "1px solid rgba(255,255,255,0.2)",
782
+ cursor: disabled ? "default" : "pointer",
783
+ padding: 0,
784
+ outline: "none"
785
+ }
786
+ },
787
+ `${color}-${idx}`
788
+ )) })
789
+ ] }),
790
+ activeRecent.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: "4px" }, children: [
791
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontSize: "10px", textTransform: "uppercase", opacity: 0.6 }, children: "Recent" }),
792
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { display: "flex", flexWrap: "wrap", gap: "4px" }, children: activeRecent.map((color, idx) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
793
+ "button",
794
+ {
795
+ type: "button",
796
+ "data-testid": "color-picker-recent",
797
+ disabled,
798
+ "aria-label": `Color ${color}`,
799
+ onClick: () => {
800
+ onChange(color);
801
+ recordRecent(color);
802
+ },
803
+ style: {
804
+ width: "18px",
805
+ height: "18px",
806
+ borderRadius: "3px",
807
+ backgroundColor: color,
808
+ border: color.toLowerCase() === value.toLowerCase() ? "2px solid #ffffff" : "1px solid rgba(255,255,255,0.2)",
809
+ cursor: disabled ? "default" : "pointer",
810
+ padding: 0,
811
+ outline: "none"
812
+ }
813
+ },
814
+ `recent-${color}-${idx}`
815
+ )) })
816
+ ] })
817
+ ]
818
+ }
819
+ );
820
+ };
821
+
822
+ // src/color/DualColorPicker.tsx
823
+ var import_react5 = require("react");
824
+ var import_color2 = require("@pixerate/editor/color");
825
+ var import_jsx_runtime4 = require("react/jsx-runtime");
826
+ function DualColorPicker({
827
+ value,
828
+ onChange,
829
+ onGestureStart,
830
+ onGestureEnd,
831
+ scheme: controlledScheme,
832
+ onSchemeChange,
833
+ surfaces = import_color2.DEFAULT_SCHEME_SURFACES,
834
+ contrastAgainst,
835
+ alpha = false,
836
+ swatches,
837
+ disabled = false,
838
+ className = ""
839
+ }) {
840
+ const sameId = (0, import_react5.useId)();
841
+ const [internalScheme, setInternalScheme] = (0, import_react5.useState)("light");
842
+ const activeScheme = controlledScheme ?? internalScheme;
843
+ const handleSchemeSelect = (nextScheme) => {
844
+ if (onSchemeChange) {
845
+ onSchemeChange(nextScheme);
846
+ } else {
847
+ setInternalScheme(nextScheme);
848
+ }
849
+ };
850
+ const dual = (0, import_color2.normalizeDualColor)(value) ?? { light: "#000000", dark: "#000000" };
851
+ const isSame = dual.light.toLowerCase() === dual.dark.toLowerCase();
852
+ const [sameInBoth, setSameInBoth] = (0, import_react5.useState)(isSame);
853
+ const handleSameToggle = (e) => {
854
+ const nextSame = e.target.checked;
855
+ setSameInBoth(nextSame);
856
+ if (nextSame) {
857
+ const activeVal = activeScheme === "dark" ? dual.dark : dual.light;
858
+ onChange({ light: activeVal, dark: activeVal });
859
+ }
860
+ };
861
+ const handleDerive = () => {
862
+ if (disabled) return;
863
+ onGestureStart?.();
864
+ const currentActive = activeScheme === "dark" ? dual.dark : dual.light;
865
+ const derived = (0, import_color2.deriveDualColor)(currentActive, {
866
+ from: activeScheme,
867
+ // An unreadable surfaces prop falls back to the defaults rather than throwing.
868
+ surfaces: (0, import_color2.normalizeDualColor)(surfaces) ?? import_color2.DEFAULT_SCHEME_SURFACES
869
+ });
870
+ onChange(derived);
871
+ onGestureEnd?.();
872
+ };
873
+ const handleInnerChange = (hex) => {
874
+ if (sameInBoth) {
875
+ onChange({ light: hex, dark: hex });
876
+ } else {
877
+ const updated = (0, import_color2.setDualColorSide)(dual, activeScheme, hex);
878
+ onChange(updated);
879
+ }
880
+ };
881
+ const activeColor = activeScheme === "dark" ? dual.dark : dual.light;
882
+ const activeContrastTarget = contrastAgainst ? (0, import_color2.resolveColor)(contrastAgainst, activeScheme) ?? void 0 : void 0;
883
+ const dualContrast = contrastAgainst && (0, import_color2.normalizeDualColor)(contrastAgainst) ? (0, import_color2.checkDualColorContrast)(dual, contrastAgainst) : null;
884
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
885
+ "div",
886
+ {
887
+ className: `pixerate-dual-color-picker ${className}`,
888
+ style: {
889
+ display: "flex",
890
+ flexDirection: "column",
891
+ gap: "12px",
892
+ padding: "12px",
893
+ background: "#1a1d24",
894
+ color: "#e2e8f0",
895
+ borderRadius: "10px",
896
+ boxShadow: "0 4px 12px rgba(0,0,0,0.3)",
897
+ width: "260px",
898
+ fontFamily: "system-ui, -apple-system, sans-serif",
899
+ fontSize: "13px",
900
+ boxSizing: "border-box"
901
+ },
902
+ children: [
903
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
904
+ "div",
905
+ {
906
+ role: "tablist",
907
+ "aria-label": "Color scheme mode",
908
+ style: {
909
+ display: "flex",
910
+ background: "#111318",
911
+ borderRadius: "6px",
912
+ padding: "2px",
913
+ gap: "2px"
914
+ },
915
+ children: [
916
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
917
+ "button",
918
+ {
919
+ type: "button",
920
+ role: "tab",
921
+ "aria-selected": activeScheme === "light",
922
+ onClick: () => handleSchemeSelect("light"),
923
+ disabled,
924
+ style: {
925
+ flex: 1,
926
+ padding: "6px 8px",
927
+ border: "none",
928
+ borderRadius: "4px",
929
+ background: activeScheme === "light" ? "#2d3342" : "transparent",
930
+ color: activeScheme === "light" ? "#ffffff" : "#8c95a6",
931
+ fontWeight: activeScheme === "light" ? 600 : 400,
932
+ cursor: disabled ? "not-allowed" : "pointer",
933
+ fontSize: "12px",
934
+ transition: "all 0.15s ease"
935
+ },
936
+ children: "Light"
937
+ }
938
+ ),
939
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
940
+ "button",
941
+ {
942
+ type: "button",
943
+ role: "tab",
944
+ "aria-selected": activeScheme === "dark",
945
+ onClick: () => handleSchemeSelect("dark"),
946
+ disabled,
947
+ style: {
948
+ flex: 1,
949
+ padding: "6px 8px",
950
+ border: "none",
951
+ borderRadius: "4px",
952
+ background: activeScheme === "dark" ? "#2d3342" : "transparent",
953
+ color: activeScheme === "dark" ? "#ffffff" : "#8c95a6",
954
+ fontWeight: activeScheme === "dark" ? 600 : 400,
955
+ cursor: disabled ? "not-allowed" : "pointer",
956
+ fontSize: "12px",
957
+ transition: "all 0.15s ease"
958
+ },
959
+ children: "Dark"
960
+ }
961
+ )
962
+ ]
963
+ }
964
+ ),
965
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { display: "flex", gap: "8px" }, children: [
966
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
967
+ "button",
968
+ {
969
+ type: "button",
970
+ onClick: () => handleSchemeSelect("light"),
971
+ disabled,
972
+ title: "Edit light mode colour",
973
+ style: {
974
+ flex: 1,
975
+ display: "flex",
976
+ flexDirection: "column",
977
+ alignItems: "center",
978
+ gap: "6px",
979
+ padding: "8px",
980
+ background: surfaces.light,
981
+ color: "#000000",
982
+ border: activeScheme === "light" ? "2px solid #3b82f6" : "1px solid #333842",
983
+ borderRadius: "6px",
984
+ cursor: disabled ? "not-allowed" : "pointer",
985
+ outline: "none"
986
+ },
987
+ children: [
988
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
989
+ "span",
990
+ {
991
+ style: {
992
+ width: "100%",
993
+ height: "24px",
994
+ borderRadius: "4px",
995
+ background: dual.light,
996
+ border: "1px solid rgba(0,0,0,0.15)"
997
+ }
998
+ }
999
+ ),
1000
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: { fontSize: "11px", fontWeight: 600 }, children: "Light" })
1001
+ ]
1002
+ }
1003
+ ),
1004
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
1005
+ "button",
1006
+ {
1007
+ type: "button",
1008
+ onClick: () => handleSchemeSelect("dark"),
1009
+ disabled,
1010
+ title: "Edit dark mode colour",
1011
+ style: {
1012
+ flex: 1,
1013
+ display: "flex",
1014
+ flexDirection: "column",
1015
+ alignItems: "center",
1016
+ gap: "6px",
1017
+ padding: "8px",
1018
+ background: surfaces.dark,
1019
+ color: "#ffffff",
1020
+ border: activeScheme === "dark" ? "2px solid #3b82f6" : "1px solid #333842",
1021
+ borderRadius: "6px",
1022
+ cursor: disabled ? "not-allowed" : "pointer",
1023
+ outline: "none"
1024
+ },
1025
+ children: [
1026
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1027
+ "span",
1028
+ {
1029
+ style: {
1030
+ width: "100%",
1031
+ height: "24px",
1032
+ borderRadius: "4px",
1033
+ background: dual.dark,
1034
+ border: "1px solid rgba(255,255,255,0.15)"
1035
+ }
1036
+ }
1037
+ ),
1038
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: { fontSize: "11px", fontWeight: 600 }, children: "Dark" })
1039
+ ]
1040
+ }
1041
+ )
1042
+ ] }),
1043
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
1044
+ "div",
1045
+ {
1046
+ style: {
1047
+ display: "flex",
1048
+ alignItems: "center",
1049
+ justifyContent: "space-between",
1050
+ gap: "8px",
1051
+ padding: "2px 0"
1052
+ },
1053
+ children: [
1054
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
1055
+ "label",
1056
+ {
1057
+ htmlFor: sameId,
1058
+ style: {
1059
+ display: "flex",
1060
+ alignItems: "center",
1061
+ gap: "6px",
1062
+ cursor: disabled ? "not-allowed" : "pointer",
1063
+ userSelect: "none",
1064
+ fontSize: "12px",
1065
+ color: "#c4cad4"
1066
+ },
1067
+ children: [
1068
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1069
+ "input",
1070
+ {
1071
+ id: sameId,
1072
+ type: "checkbox",
1073
+ checked: sameInBoth,
1074
+ onChange: handleSameToggle,
1075
+ disabled,
1076
+ style: { cursor: disabled ? "not-allowed" : "pointer" }
1077
+ }
1078
+ ),
1079
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: "Same in both" })
1080
+ ]
1081
+ }
1082
+ ),
1083
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1084
+ "button",
1085
+ {
1086
+ type: "button",
1087
+ onClick: handleDerive,
1088
+ disabled,
1089
+ style: {
1090
+ padding: "4px 10px",
1091
+ background: "#2d3342",
1092
+ color: "#e2e8f0",
1093
+ border: "1px solid #3b4252",
1094
+ borderRadius: "4px",
1095
+ fontSize: "11px",
1096
+ fontWeight: 500,
1097
+ cursor: disabled ? "not-allowed" : "pointer"
1098
+ },
1099
+ children: "Derive"
1100
+ }
1101
+ )
1102
+ ]
1103
+ }
1104
+ ),
1105
+ dualContrast && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
1106
+ "div",
1107
+ {
1108
+ "data-testid": "dual-contrast-summary",
1109
+ style: {
1110
+ display: "flex",
1111
+ justifyContent: "space-between",
1112
+ background: "#111318",
1113
+ padding: "6px 8px",
1114
+ borderRadius: "6px",
1115
+ fontSize: "11px",
1116
+ color: "#8c95a6"
1117
+ },
1118
+ children: [
1119
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
1120
+ "Light:",
1121
+ " ",
1122
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("strong", { style: { color: dualContrast.light.level === "fail" ? "#ef4444" : "#22c55e" }, children: [
1123
+ dualContrast.light.ratio.toFixed(2),
1124
+ " (",
1125
+ dualContrast.light.level,
1126
+ ")"
1127
+ ] })
1128
+ ] }),
1129
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
1130
+ "Dark:",
1131
+ " ",
1132
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("strong", { style: { color: dualContrast.dark.level === "fail" ? "#ef4444" : "#22c55e" }, children: [
1133
+ dualContrast.dark.ratio.toFixed(2),
1134
+ " (",
1135
+ dualContrast.dark.level,
1136
+ ")"
1137
+ ] })
1138
+ ] })
1139
+ ]
1140
+ }
1141
+ ),
1142
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1143
+ ColorPicker,
1144
+ {
1145
+ value: activeColor,
1146
+ onChange: handleInnerChange,
1147
+ onGestureStart,
1148
+ onGestureEnd,
1149
+ contrastAgainst: activeContrastTarget,
1150
+ alpha,
1151
+ swatches,
1152
+ disabled
1153
+ }
1154
+ )
1155
+ ]
1156
+ }
1157
+ );
1158
+ }
1159
+
1160
+ // src/color/useColorScheme.ts
1161
+ var import_react6 = require("react");
1162
+ var import_color3 = require("@pixerate/editor/color");
1163
+ function getSnapshot(attribute) {
1164
+ if (typeof window === "undefined" || typeof document === "undefined") {
1165
+ return "light";
1166
+ }
1167
+ if (attribute) {
1168
+ const el = document.documentElement;
1169
+ if (attribute === "class") {
1170
+ return el.classList.contains("dark") ? "dark" : "light";
1171
+ }
1172
+ const val = el.getAttribute(attribute);
1173
+ return val === "dark" ? "dark" : "light";
1174
+ }
1175
+ if (typeof window.matchMedia === "function") {
1176
+ return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
1177
+ }
1178
+ return "light";
1179
+ }
1180
+ function getServerSnapshot() {
1181
+ return "light";
1182
+ }
1183
+ function useColorScheme(options) {
1184
+ const override = options?.override;
1185
+ const attribute = options?.attribute;
1186
+ const subscribe = (0, import_react6.useMemo)(() => {
1187
+ return (callback) => {
1188
+ if (typeof window === "undefined" || typeof document === "undefined") {
1189
+ return () => {
1190
+ };
1191
+ }
1192
+ if (attribute) {
1193
+ const observer = new MutationObserver(() => {
1194
+ callback();
1195
+ });
1196
+ observer.observe(document.documentElement, {
1197
+ attributes: true,
1198
+ attributeFilter: [attribute]
1199
+ });
1200
+ return () => observer.disconnect();
1201
+ }
1202
+ if (typeof window.matchMedia === "function") {
1203
+ const mql = window.matchMedia("(prefers-color-scheme: dark)");
1204
+ const handler = () => callback();
1205
+ mql.addEventListener("change", handler);
1206
+ return () => mql.removeEventListener("change", handler);
1207
+ }
1208
+ return () => {
1209
+ };
1210
+ };
1211
+ }, [attribute]);
1212
+ const detected = (0, import_react6.useSyncExternalStore)(
1213
+ subscribe,
1214
+ () => getSnapshot(attribute),
1215
+ getServerSnapshot
1216
+ );
1217
+ return override ?? detected;
1218
+ }
1219
+ function useResolvedColor(value, scheme) {
1220
+ const detectedScheme = useColorScheme();
1221
+ const activeScheme = scheme ?? detectedScheme;
1222
+ return (0, import_color3.resolveColor)(value, activeScheme);
1223
+ }
1224
+
1225
+ // src/color/index.ts
1226
+ __reExport(color_exports, require("@pixerate/editor/color"));
1227
+
1228
+ // src/parameters/fields.tsx
1229
+ var import_jsx_runtime5 = require("react/jsx-runtime");
186
1230
  var parameterInputClass = "h-7 w-full min-w-0 rounded-md border border-input bg-background px-2 text-xs text-foreground tabular-nums focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50";
187
1231
  var parameterButtonClass = "inline-flex h-7 items-center justify-center gap-1 rounded-md border border-input bg-background px-2 text-xs text-foreground hover:bg-muted focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50";
188
1232
  var rangeClass = "h-4 w-full min-w-0 flex-1 cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-50";
@@ -206,7 +1250,7 @@ function ParameterCommitInput({ value, onCommit, multiline, className, onKeyDown
206
1250
  onKeyDown: keyDown,
207
1251
  ...rest
208
1252
  };
209
- return multiline ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("textarea", { ...props, className: `${props.className} h-auto min-h-[3.5rem] py-1` }, value) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("input", { type: "text", ...props }, value);
1253
+ return multiline ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("textarea", { ...props, className: `${props.className} h-auto min-h-[3.5rem] py-1` }, value) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("input", { type: "text", ...props }, value);
210
1254
  }
211
1255
  var plainNumber = (field, value) => (0, import_parameters.formatParameterNumber)({ ...field, unit: void 0 }, value);
212
1256
  function ParameterNumberInput({
@@ -217,8 +1261,8 @@ function ParameterNumberInput({
217
1261
  id,
218
1262
  "aria-label": ariaLabel
219
1263
  }) {
220
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "relative min-w-0 flex-1", children: [
221
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1264
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "relative min-w-0 flex-1", children: [
1265
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
222
1266
  ParameterCommitInput,
223
1267
  {
224
1268
  id,
@@ -240,21 +1284,21 @@ function ParameterNumberInput({
240
1284
  }
241
1285
  }
242
1286
  ),
243
- field.unit && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "pointer-events-none absolute right-2 top-1/2 -translate-y-1/2 text-[10px] text-muted-foreground", children: field.unit })
1287
+ field.unit && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "pointer-events-none absolute right-2 top-1/2 -translate-y-1/2 text-[10px] text-muted-foreground", children: field.unit })
244
1288
  ] });
245
1289
  }
246
1290
  function ParameterSlider(props) {
247
1291
  const { field, value, onChange, onGestureStart, onGestureEnd, disabled } = props;
248
- const dragging = (0, import_react4.useRef)(false);
1292
+ const dragging = (0, import_react7.useRef)(false);
249
1293
  const end = () => {
250
1294
  if (!dragging.current) return;
251
1295
  dragging.current = false;
252
1296
  onGestureEnd?.();
253
1297
  };
254
- if (!(0, import_parameters.isSliderField)(field)) return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ParameterNumberInput, { ...props });
1298
+ if (!(0, import_parameters.isSliderField)(field)) return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ParameterNumberInput, { ...props });
255
1299
  const step = (0, import_parameters.parameterStep)(field);
256
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex items-center gap-2", children: [
257
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1300
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-2", children: [
1301
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
258
1302
  "input",
259
1303
  {
260
1304
  type: "range",
@@ -277,11 +1321,11 @@ function ParameterSlider(props) {
277
1321
  onChange: (e) => onChange((0, import_parameters.clampParameterNumber)(field, Number(e.target.value)))
278
1322
  }
279
1323
  ),
280
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "w-20 shrink-0", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ParameterNumberInput, { ...props, id: props.id, "aria-label": `${(0, import_parameters.parameterLabel)(field)} value` }) })
1324
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "w-20 shrink-0", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ParameterNumberInput, { ...props, id: props.id, "aria-label": `${(0, import_parameters.parameterLabel)(field)} value` }) })
281
1325
  ] });
282
1326
  }
283
1327
  function ParameterToggle({ field, value, onChange, disabled, id }) {
284
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1328
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
285
1329
  "button",
286
1330
  {
287
1331
  type: "button",
@@ -292,7 +1336,7 @@ function ParameterToggle({ field, value, onChange, disabled, id }) {
292
1336
  disabled: disabled || field.readOnly,
293
1337
  onClick: () => onChange(!value),
294
1338
  className: `relative inline-flex h-5 w-9 shrink-0 items-center rounded-full border border-transparent transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary disabled:opacity-50 ${value ? "bg-primary" : "bg-muted"}`,
295
- children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1339
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
296
1340
  "span",
297
1341
  {
298
1342
  className: `pointer-events-none block h-4 w-4 rounded-full bg-background shadow transition-transform ${value ? "translate-x-4" : "translate-x-0.5"}`
@@ -305,7 +1349,7 @@ function ParameterSelect({ field, value, onChange, disabled, id }) {
305
1349
  const options = (0, import_parameters.getChoiceOptions)(field);
306
1350
  const off = disabled || field.readOnly;
307
1351
  if (field.control === "segmented") {
308
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { role: "radiogroup", "aria-label": (0, import_parameters.parameterLabel)(field), className: "inline-flex flex-wrap rounded-md border border-input bg-muted p-0.5", children: options.map((o) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1352
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { role: "radiogroup", "aria-label": (0, import_parameters.parameterLabel)(field), className: "inline-flex flex-wrap rounded-md border border-input bg-muted p-0.5", children: options.map((o) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
309
1353
  "button",
310
1354
  {
311
1355
  type: "button",
@@ -321,7 +1365,7 @@ function ParameterSelect({ field, value, onChange, disabled, id }) {
321
1365
  )) });
322
1366
  }
323
1367
  const index = options.findIndex((o) => o.value === value);
324
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1368
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
325
1369
  "select",
326
1370
  {
327
1371
  id,
@@ -333,53 +1377,64 @@ function ParameterSelect({ field, value, onChange, disabled, id }) {
333
1377
  if (option) onChange(option.value);
334
1378
  },
335
1379
  className: parameterInputClass,
336
- children: options.map((o, i) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: String(i), title: o.description, children: (0, import_parameters.choiceOptionLabel)(o) }, String(o.value)))
1380
+ children: options.map((o, i) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: String(i), title: o.description, children: (0, import_parameters.choiceOptionLabel)(o) }, String(o.value)))
337
1381
  }
338
1382
  );
339
1383
  }
340
1384
  function ParameterColor({ field, value, onChange, onGestureStart, onGestureEnd, disabled, id }) {
341
- const picking = (0, import_react4.useRef)(false);
1385
+ const [open, setOpen] = (0, import_react7.useState)(false);
1386
+ const containerRef = (0, import_react7.useRef)(null);
1387
+ const buttonRef = (0, import_react7.useRef)(null);
1388
+ const popoverRef = (0, import_react7.useRef)(null);
342
1389
  const alpha = !!field.alpha;
343
1390
  const hex = (0, import_parameters.normalizeHexColor)(value, true) ?? "#000000ff";
344
1391
  const rgb = hex.slice(0, 7);
345
- const a = hex.slice(7);
1392
+ const shown = alpha ? hex : rgb;
346
1393
  const off = disabled || field.readOnly;
347
- const start = () => {
348
- if (picking.current) return;
349
- picking.current = true;
350
- onGestureStart?.();
351
- };
352
- const end = () => {
353
- if (!picking.current) return;
354
- picking.current = false;
355
- onGestureEnd?.();
356
- };
357
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "space-y-1.5", children: [
358
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex items-center gap-2", children: [
359
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: "relative h-7 w-9 shrink-0 overflow-hidden rounded-md border border-input bg-[repeating-conic-gradient(#d4d4d8_0_25%,#fff_0_50%)] bg-[length:8px_8px]", children: [
360
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "absolute inset-0", style: { background: alpha ? hex : rgb } }),
361
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
362
- "input",
363
- {
364
- type: "color",
365
- "aria-label": (0, import_parameters.parameterLabel)(field),
366
- value: rgb,
367
- disabled: off,
368
- className: "absolute inset-0 h-full w-full cursor-pointer opacity-0 disabled:cursor-not-allowed",
369
- onChange: (e) => {
370
- start();
371
- onChange(alpha ? `${e.target.value}${a}` : e.target.value);
372
- },
373
- onBlur: end
374
- }
375
- )
376
- ] }),
377
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1394
+ const name = (0, import_parameters.parameterLabel)(field);
1395
+ (0, import_react7.useEffect)(() => {
1396
+ if (!open) return;
1397
+ const onPointerDown = (e) => {
1398
+ if (containerRef.current && !containerRef.current.contains(e.target)) {
1399
+ setOpen(false);
1400
+ }
1401
+ };
1402
+ const onKeyDown = (e) => {
1403
+ if (e.key === "Escape") {
1404
+ e.stopPropagation();
1405
+ setOpen(false);
1406
+ buttonRef.current?.focus();
1407
+ }
1408
+ };
1409
+ window.addEventListener("pointerdown", onPointerDown, true);
1410
+ window.addEventListener("keydown", onKeyDown, true);
1411
+ return () => {
1412
+ window.removeEventListener("pointerdown", onPointerDown, true);
1413
+ window.removeEventListener("keydown", onKeyDown, true);
1414
+ };
1415
+ }, [open]);
1416
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { ref: containerRef, className: "relative space-y-1.5", children: [
1417
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-2", children: [
1418
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1419
+ "button",
1420
+ {
1421
+ ref: buttonRef,
1422
+ type: "button",
1423
+ "aria-label": name,
1424
+ "aria-expanded": open,
1425
+ "aria-haspopup": "dialog",
1426
+ disabled: off,
1427
+ onClick: () => setOpen((prev) => !prev),
1428
+ className: "relative h-7 w-9 shrink-0 overflow-hidden rounded-md border border-input bg-[repeating-conic-gradient(#d4d4d8_0_25%,#fff_0_50%)] bg-[length:8px_8px] focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50",
1429
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "absolute inset-0", style: { background: shown } })
1430
+ }
1431
+ ),
1432
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
378
1433
  ParameterCommitInput,
379
1434
  {
380
1435
  id,
381
- "aria-label": `${(0, import_parameters.parameterLabel)(field)} hex`,
382
- value: alpha ? hex : rgb,
1436
+ "aria-label": `${name} hex`,
1437
+ value: shown,
383
1438
  disabled: off,
384
1439
  spellCheck: false,
385
1440
  className: `${parameterInputClass} font-mono`,
@@ -390,51 +1445,43 @@ function ParameterColor({ field, value, onChange, onGestureStart, onGestureEnd,
390
1445
  }
391
1446
  )
392
1447
  ] }),
393
- alpha && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
394
- "input",
1448
+ open && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1449
+ "div",
395
1450
  {
396
- type: "range",
397
- "aria-label": `${(0, import_parameters.parameterLabel)(field)} opacity`,
398
- min: 0,
399
- max: 255,
400
- step: 1,
401
- value: parseInt(a, 16),
402
- disabled: off,
403
- className: rangeClass,
404
- onPointerDown: start,
405
- onPointerUp: end,
406
- onPointerCancel: end,
407
- onBlur: end,
408
- onChange: (e) => onChange(`${rgb}${Number(e.target.value).toString(16).padStart(2, "0")}`)
409
- }
410
- ),
411
- field.swatches && field.swatches.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "flex flex-wrap gap-1", children: field.swatches.map((s) => {
412
- const swatch = (0, import_parameters.normalizeHexColor)(s, alpha);
413
- if (!swatch) return null;
414
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
415
- "button",
416
- {
417
- type: "button",
418
- title: swatch,
419
- "aria-label": `${(0, import_parameters.parameterLabel)(field)} ${swatch}`,
420
- "aria-pressed": swatch === (alpha ? hex : rgb),
421
- disabled: off,
422
- onClick: () => onChange(swatch),
423
- className: "h-5 w-5 rounded border border-input aria-pressed:ring-1 aria-pressed:ring-primary",
424
- style: { background: swatch }
1451
+ ref: popoverRef,
1452
+ role: "dialog",
1453
+ "aria-label": name,
1454
+ tabIndex: -1,
1455
+ onBlur: (e) => {
1456
+ if (popoverRef.current && !popoverRef.current.contains(e.relatedTarget)) {
1457
+ setOpen(false);
1458
+ }
425
1459
  },
426
- s
427
- );
428
- }) })
1460
+ className: "absolute left-0 top-full z-50 mt-1 w-64 rounded-lg border border-border bg-popover p-2 text-popover-foreground shadow-xl",
1461
+ style: { background: "var(--popover, var(--background, #fff))" },
1462
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1463
+ ColorPicker,
1464
+ {
1465
+ value: shown,
1466
+ alpha,
1467
+ swatches: field.swatches,
1468
+ disabled: off,
1469
+ onChange,
1470
+ onGestureStart,
1471
+ onGestureEnd
1472
+ }
1473
+ )
1474
+ }
1475
+ )
429
1476
  ] });
430
1477
  }
431
1478
  function ParameterVector({ field, value, onChange, disabled, id }) {
432
1479
  const size = (0, import_parameters.vectorSize)(field);
433
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "grid gap-1.5", style: { gridTemplateColumns: `repeat(${size}, minmax(0, 1fr))` }, children: Array.from({ length: size }, (_, i) => {
1480
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "grid gap-1.5", style: { gridTemplateColumns: `repeat(${size}, minmax(0, 1fr))` }, children: Array.from({ length: size }, (_, i) => {
434
1481
  const component = (0, import_parameters.vectorComponentField)(field, i);
435
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { className: "flex min-w-0 items-center gap-1", children: [
436
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "w-3 shrink-0 text-[10px] uppercase text-muted-foreground", children: component.label }),
437
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1482
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "flex min-w-0 items-center gap-1", children: [
1483
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "w-3 shrink-0 text-[10px] uppercase text-muted-foreground", children: component.label }),
1484
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
438
1485
  ParameterNumberInput,
439
1486
  {
440
1487
  field: component,
@@ -451,11 +1498,11 @@ function ParameterVector({ field, value, onChange, disabled, id }) {
451
1498
  function ParameterImage({ field, value, onChange, disabled, id, resolveFile }) {
452
1499
  const off = disabled || field.readOnly;
453
1500
  const name = (0, import_parameters.parameterLabel)(field);
454
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "space-y-1.5", children: [
455
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex items-center gap-2", children: [
456
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "flex h-12 w-16 shrink-0 items-center justify-center overflow-hidden rounded-md border border-input bg-muted", children: value ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("img", { src: value, alt: name, className: "h-full w-full object-cover" }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "text-[10px] text-muted-foreground", children: "None" }) }),
457
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [
458
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1501
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-1.5", children: [
1502
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-2", children: [
1503
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex h-12 w-16 shrink-0 items-center justify-center overflow-hidden rounded-md border border-input bg-muted", children: value ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("img", { src: value, alt: name, className: "h-full w-full object-cover" }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-[10px] text-muted-foreground", children: "None" }) }),
1504
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [
1505
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
459
1506
  ParameterCommitInput,
460
1507
  {
461
1508
  id,
@@ -466,10 +1513,10 @@ function ParameterImage({ field, value, onChange, disabled, id, resolveFile }) {
466
1513
  onCommit: (text) => onChange(text.trim())
467
1514
  }
468
1515
  ),
469
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex gap-1", children: [
470
- resolveFile && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { className: `${parameterButtonClass} cursor-pointer ${off ? "pointer-events-none opacity-50" : ""}`, children: [
1516
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-1", children: [
1517
+ resolveFile && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: `${parameterButtonClass} cursor-pointer ${off ? "pointer-events-none opacity-50" : ""}`, children: [
471
1518
  "Choose file\u2026",
472
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1519
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
473
1520
  "input",
474
1521
  {
475
1522
  type: "file",
@@ -485,11 +1532,11 @@ function ParameterImage({ field, value, onChange, disabled, id, resolveFile }) {
485
1532
  }
486
1533
  )
487
1534
  ] }),
488
- value && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", className: parameterButtonClass, disabled: off, onClick: () => onChange(""), "aria-label": `Clear ${name}`, children: "Clear" })
1535
+ value && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", className: parameterButtonClass, disabled: off, onClick: () => onChange(""), "aria-label": `Clear ${name}`, children: "Clear" })
489
1536
  ] })
490
1537
  ] })
491
1538
  ] }),
492
- field.options && field.options.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "flex flex-wrap gap-1", children: field.options.map((o) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1539
+ field.options && field.options.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex flex-wrap gap-1", children: field.options.map((o) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
493
1540
  "button",
494
1541
  {
495
1542
  type: "button",
@@ -499,14 +1546,14 @@ function ParameterImage({ field, value, onChange, disabled, id, resolveFile }) {
499
1546
  disabled: off,
500
1547
  onClick: () => onChange(o.url),
501
1548
  className: "h-9 w-12 overflow-hidden rounded border border-input aria-pressed:ring-2 aria-pressed:ring-primary",
502
- children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("img", { src: o.url, alt: "", className: "h-full w-full object-cover" })
1549
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("img", { src: o.url, alt: "", className: "h-full w-full object-cover" })
503
1550
  },
504
1551
  o.url
505
1552
  )) })
506
1553
  ] });
507
1554
  }
508
1555
  function ParameterText({ field, value, onChange, disabled, id }) {
509
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1556
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
510
1557
  ParameterCommitInput,
511
1558
  {
512
1559
  id,
@@ -525,31 +1572,42 @@ function ParameterFieldControl({ field, value, onChange, resolveFile, ...rest })
525
1572
  switch (field.type) {
526
1573
  case "number":
527
1574
  case "int":
528
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ParameterSlider, { field, value, onChange: set, ...rest });
1575
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ParameterSlider, { field, value, onChange: set, ...rest });
529
1576
  case "boolean":
530
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ParameterToggle, { field, value, onChange: set, ...rest });
1577
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ParameterToggle, { field, value, onChange: set, ...rest });
531
1578
  case "choice":
532
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ParameterSelect, { field, value, onChange: set, ...rest });
1579
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ParameterSelect, { field, value, onChange: set, ...rest });
533
1580
  case "color":
534
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ParameterColor, { field, value, onChange: set, ...rest });
1581
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ParameterColor, { field, value, onChange: set, ...rest });
535
1582
  case "vector":
536
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ParameterVector, { field, value, onChange: set, ...rest });
1583
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ParameterVector, { field, value, onChange: set, ...rest });
537
1584
  case "image":
538
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ParameterImage, { field, value, onChange: set, resolveFile, ...rest });
1585
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ParameterImage, { field, value, onChange: set, resolveFile, ...rest });
539
1586
  case "text":
540
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ParameterText, { field, value, onChange: set, ...rest });
1587
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ParameterText, { field, value, onChange: set, ...rest });
541
1588
  }
542
1589
  }
543
1590
 
544
1591
  // src/effects/EffectParameters.tsx
545
- var import_jsx_runtime4 = require("react/jsx-runtime");
546
- function EffectParameters({ description, values, onChange, onReset, keyframed, onPreset, disabled = false, className = "" }) {
547
- const fields = (0, import_react5.useMemo)(() => (0, import_effects3.effectParameterFields)(description), [description]);
548
- const idBase = (0, import_react5.useId)();
549
- const gesture = import_react5.default.useRef(null);
550
- const count = import_react5.default.useRef(0);
551
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: `space-y-2 ${className}`, "data-effect-parameters": description.id, children: [
552
- onPreset && description.presets.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
1592
+ var import_jsx_runtime6 = require("react/jsx-runtime");
1593
+ function EffectParameters({
1594
+ description,
1595
+ values,
1596
+ onChange,
1597
+ onReset,
1598
+ keyframed,
1599
+ onPreset,
1600
+ onPresetName,
1601
+ renderControlAddon,
1602
+ disabled = false,
1603
+ className = ""
1604
+ }) {
1605
+ const fields = (0, import_react8.useMemo)(() => (0, import_effects3.effectParameterFields)(description), [description]);
1606
+ const idBase = (0, import_react8.useId)();
1607
+ const gesture = import_react8.default.useRef(null);
1608
+ const count = import_react8.default.useRef(0);
1609
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: `space-y-2 ${className}`, "data-effect-parameters": description.id, children: [
1610
+ (onPreset || onPresetName) && description.presets.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
553
1611
  "select",
554
1612
  {
555
1613
  className: "w-full rounded border border-border bg-transparent px-1 py-0.5 text-xs",
@@ -557,12 +1615,18 @@ function EffectParameters({ description, values, onChange, onReset, keyframed, o
557
1615
  value: "",
558
1616
  disabled,
559
1617
  onChange: (e) => {
560
- const preset = description.presets.find((p) => p.name === e.currentTarget.value);
561
- if (preset) onPreset({ ...description.defaults, ...preset.values });
1618
+ const name = e.currentTarget.value;
1619
+ if (!name) return;
1620
+ if (onPresetName) {
1621
+ onPresetName(name);
1622
+ } else if (onPreset) {
1623
+ const preset = description.presets.find((p) => p.name === name);
1624
+ if (preset) onPreset({ ...description.defaults, ...preset.values });
1625
+ }
562
1626
  },
563
1627
  children: [
564
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("option", { value: "", children: "Presets\u2026" }),
565
- description.presets.map((p) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("option", { value: p.name, children: p.name }, p.name))
1628
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("option", { value: "", children: "Presets\u2026" }),
1629
+ description.presets.map((p) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("option", { value: p.name, children: p.name }, p.name))
566
1630
  ]
567
1631
  }
568
1632
  ),
@@ -572,13 +1636,14 @@ function EffectParameters({ description, values, onChange, onReset, keyframed, o
572
1636
  const keyed = keyframed?.has(field.id) ?? false;
573
1637
  const value = (0, import_effects3.effectFieldValue)(field, values[field.id]);
574
1638
  const changed = !keyed && !(0, import_parameters2.parameterValuesEqual)(value, field.default);
575
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "space-y-1", "data-effect-control": field.id, children: [
576
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex items-center gap-1.5", children: [
577
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("label", { htmlFor: inputId, className: "min-w-0 flex-1 truncate text-xs font-medium", title: field.description, children: label }),
578
- keyed && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "text-[10px] text-muted-foreground", children: "keyframed" }),
579
- onReset && changed && !disabled && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: "rounded px-1 text-[11px] text-muted-foreground hover:text-foreground", "aria-label": `Reset ${label}`, onClick: () => onReset(field.id), children: "\u21BA" })
1639
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "space-y-1", "data-effect-control": field.id, children: [
1640
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex items-center gap-1.5", children: [
1641
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("label", { htmlFor: inputId, className: "min-w-0 flex-1 truncate text-xs font-medium", title: field.description, children: label }),
1642
+ keyed && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "text-[10px] text-muted-foreground", children: "keyframed" }),
1643
+ renderControlAddon?.(field.id),
1644
+ onReset && changed && !disabled && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "rounded px-1 text-[11px] text-muted-foreground hover:text-foreground", "aria-label": `Reset ${label}`, onClick: () => onReset(field.id), children: "\u21BA" })
580
1645
  ] }),
581
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1646
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
582
1647
  ParameterFieldControl,
583
1648
  {
584
1649
  field,
@@ -592,14 +1657,446 @@ function EffectParameters({ description, values, onChange, onReset, keyframed, o
592
1657
  )
593
1658
  ] }, field.id);
594
1659
  }),
595
- !fields.length && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "text-[11px] text-muted-foreground", children: "No controls." })
1660
+ !fields.length && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "text-[11px] text-muted-foreground", children: "No controls." })
596
1661
  ] });
597
1662
  }
1663
+
1664
+ // src/effects/useEffectAuthoring.ts
1665
+ var import_react9 = require("react");
1666
+ function useEffectAuthoring(session) {
1667
+ return (0, import_react9.useSyncExternalStore)(
1668
+ (callback) => {
1669
+ if (!session) return () => {
1670
+ };
1671
+ return session.subscribe(callback);
1672
+ },
1673
+ () => session ? session.getState() : null,
1674
+ () => null
1675
+ );
1676
+ }
1677
+
1678
+ // src/effects/EffectAuthoringEditor.tsx
1679
+ var import_react10 = require("react");
1680
+ var import_effects4 = require("@pixerate/editor/effects");
1681
+ var import_jsx_runtime7 = require("react/jsx-runtime");
1682
+ function EffectAuthoringEditor({
1683
+ session,
1684
+ showSource = true,
1685
+ showTimeline = true,
1686
+ previewSize = { width: 480, height: 270 },
1687
+ className = ""
1688
+ }) {
1689
+ const state = useEffectAuthoring(session);
1690
+ const canvasRef = (0, import_react10.useRef)(null);
1691
+ const rendererRef = (0, import_react10.useRef)(null);
1692
+ const [rendererReady, setRendererReady] = (0, import_react10.useState)(0);
1693
+ const renderingRef = (0, import_react10.useRef)(false);
1694
+ const pendingRef = (0, import_react10.useRef)(false);
1695
+ const timeRef = (0, import_react10.useRef)(0);
1696
+ const inputsRef = (0, import_react10.useRef)({});
1697
+ const [savingPreset, setSavingPreset] = (0, import_react10.useState)(false);
1698
+ const [presetName, setPresetName] = (0, import_react10.useState)("");
1699
+ const textareaRef = (0, import_react10.useRef)(null);
1700
+ const gutterRef = (0, import_react10.useRef)(null);
1701
+ const [sourceCode, setSourceCode] = (0, import_react10.useState)("");
1702
+ const sourceDebounceRef = (0, import_react10.useRef)(null);
1703
+ (0, import_react10.useEffect)(() => {
1704
+ if (!session) {
1705
+ if (rendererRef.current) {
1706
+ rendererRef.current.dispose();
1707
+ rendererRef.current = null;
1708
+ }
1709
+ return;
1710
+ }
1711
+ let live = true;
1712
+ let createdRenderer = null;
1713
+ Promise.resolve(session.createPreview(previewSize)).then((renderer) => {
1714
+ if (!live) {
1715
+ renderer.dispose();
1716
+ return;
1717
+ }
1718
+ createdRenderer = renderer;
1719
+ rendererRef.current = renderer;
1720
+ setRendererReady((c) => c + 1);
1721
+ });
1722
+ return () => {
1723
+ live = false;
1724
+ if (createdRenderer) {
1725
+ createdRenderer.dispose();
1726
+ }
1727
+ if (rendererRef.current === createdRenderer) {
1728
+ rendererRef.current = null;
1729
+ }
1730
+ };
1731
+ }, [session, previewSize.width, previewSize.height]);
1732
+ const pump = (0, import_react10.useCallback)(async () => {
1733
+ if (renderingRef.current) {
1734
+ pendingRef.current = true;
1735
+ return;
1736
+ }
1737
+ renderingRef.current = true;
1738
+ try {
1739
+ do {
1740
+ pendingRef.current = false;
1741
+ const renderer = rendererRef.current;
1742
+ if (!renderer) break;
1743
+ try {
1744
+ const pixels = await renderer.render({ time: timeRef.current, inputs: inputsRef.current });
1745
+ const ctx = rendererRef.current === renderer ? canvasRef.current?.getContext("2d") : null;
1746
+ if (ctx && typeof ImageData !== "undefined") {
1747
+ ctx.putImageData(new ImageData(new Uint8ClampedArray(pixels.data), pixels.width, pixels.height), 0, 0);
1748
+ }
1749
+ } catch {
1750
+ }
1751
+ } while (pendingRef.current);
1752
+ } finally {
1753
+ renderingRef.current = false;
1754
+ }
1755
+ }, []);
1756
+ const inputSpecs = state?.description.inputs;
1757
+ (0, import_react10.useEffect)(() => {
1758
+ inputsRef.current = inputSpecs ? (0, import_effects4.effectSampleInputs)({ inputs: inputSpecs }, previewSize) : {};
1759
+ }, [inputSpecs, previewSize.width, previewSize.height]);
1760
+ (0, import_react10.useEffect)(() => {
1761
+ if (!state) return;
1762
+ timeRef.current = state.time;
1763
+ void pump();
1764
+ }, [state, rendererReady, pump]);
1765
+ (0, import_react10.useEffect)(() => {
1766
+ if (state?.source !== null && state?.source !== void 0) {
1767
+ setSourceCode(state.source);
1768
+ }
1769
+ }, [state?.source]);
1770
+ (0, import_react10.useEffect)(() => {
1771
+ return () => {
1772
+ if (sourceDebounceRef.current) clearTimeout(sourceDebounceRef.current);
1773
+ };
1774
+ }, []);
1775
+ if (!session || !state) {
1776
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: `p-4 text-center text-xs text-muted-foreground ${className}`, children: "No effect authoring session is open." });
1777
+ }
1778
+ const hasSource = showSource && state.sourceLanguage !== null && typeof session.setSource === "function";
1779
+ const handleSourceChange = (e) => {
1780
+ const val = e.target.value;
1781
+ setSourceCode(val);
1782
+ if (sourceDebounceRef.current) clearTimeout(sourceDebounceRef.current);
1783
+ sourceDebounceRef.current = setTimeout(() => {
1784
+ session.setSource?.(val);
1785
+ }, 300);
1786
+ };
1787
+ const handleSavePreset = (e) => {
1788
+ e.preventDefault();
1789
+ const trimmed = presetName.trim();
1790
+ if (trimmed) {
1791
+ session.savePreset(trimmed);
1792
+ setSavingPreset(false);
1793
+ setPresetName("");
1794
+ }
1795
+ };
1796
+ const jumpToLine = (lineNum) => {
1797
+ if (!textareaRef.current) return;
1798
+ const lines = sourceCode.split("\n");
1799
+ let offset = 0;
1800
+ for (let i = 0; i < lineNum - 1 && i < lines.length; i++) {
1801
+ offset += lines[i].length + 1;
1802
+ }
1803
+ textareaRef.current.focus();
1804
+ textareaRef.current.setSelectionRange(offset, offset);
1805
+ };
1806
+ const sourceLines = sourceCode.split("\n");
1807
+ const issueLines = new Set(
1808
+ state.issues.map((i) => i.line).filter((l) => typeof l === "number")
1809
+ );
1810
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: `space-y-4 rounded border border-border bg-background p-4 text-foreground ${className}`, "data-effect-authoring-editor": state.name, children: [
1811
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex flex-wrap items-center justify-between gap-2 border-b border-border pb-3", children: [
1812
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex items-center gap-2", children: [
1813
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1814
+ "button",
1815
+ {
1816
+ type: "button",
1817
+ className: "rounded border border-border px-2.5 py-1 text-xs font-medium hover:bg-muted",
1818
+ "aria-label": state.playing ? "Pause playback" : "Start playback",
1819
+ onClick: () => state.playing ? session.pause() : session.play(),
1820
+ children: state.playing ? "Pause" : "Play"
1821
+ }
1822
+ ),
1823
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "font-mono text-xs text-muted-foreground", "data-time-readout": true, children: [
1824
+ state.time,
1825
+ "ms / ",
1826
+ state.duration,
1827
+ "ms"
1828
+ ] })
1829
+ ] }),
1830
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex items-center gap-2", children: [
1831
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1832
+ "button",
1833
+ {
1834
+ type: "button",
1835
+ className: "rounded border border-border px-2 py-1 text-xs disabled:opacity-40 hover:bg-muted",
1836
+ "aria-label": "Undo",
1837
+ disabled: !state.canUndo,
1838
+ onClick: () => session.undo(),
1839
+ children: "Undo"
1840
+ }
1841
+ ),
1842
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1843
+ "button",
1844
+ {
1845
+ type: "button",
1846
+ className: "rounded border border-border px-2 py-1 text-xs disabled:opacity-40 hover:bg-muted",
1847
+ "aria-label": "Redo",
1848
+ disabled: !state.canRedo,
1849
+ onClick: () => session.redo(),
1850
+ children: "Redo"
1851
+ }
1852
+ ),
1853
+ savingPreset ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("form", { onSubmit: handleSavePreset, className: "flex items-center gap-1", children: [
1854
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1855
+ "input",
1856
+ {
1857
+ type: "text",
1858
+ className: "rounded border border-border bg-background px-1.5 py-0.5 text-xs",
1859
+ placeholder: "Preset name",
1860
+ autoFocus: true,
1861
+ value: presetName,
1862
+ onChange: (e) => setPresetName(e.target.value)
1863
+ }
1864
+ ),
1865
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1866
+ "button",
1867
+ {
1868
+ type: "submit",
1869
+ className: "rounded bg-primary px-2 py-0.5 text-xs text-primary-foreground",
1870
+ children: "Save"
1871
+ }
1872
+ ),
1873
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1874
+ "button",
1875
+ {
1876
+ type: "button",
1877
+ className: "rounded border border-border px-1.5 py-0.5 text-xs hover:bg-muted",
1878
+ onClick: () => setSavingPreset(false),
1879
+ children: "Cancel"
1880
+ }
1881
+ )
1882
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1883
+ "button",
1884
+ {
1885
+ type: "button",
1886
+ className: "rounded border border-border px-2 py-1 text-xs hover:bg-muted",
1887
+ onClick: () => setSavingPreset(true),
1888
+ children: "Save preset\u2026"
1889
+ }
1890
+ )
1891
+ ] })
1892
+ ] }),
1893
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "grid grid-cols-1 gap-4 lg:grid-cols-2", children: [
1894
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "space-y-2", children: [
1895
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: "Preview" }),
1896
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "relative flex aspect-video w-full items-center justify-center overflow-hidden rounded border border-border bg-black", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1897
+ "canvas",
1898
+ {
1899
+ ref: canvasRef,
1900
+ width: previewSize.width,
1901
+ height: previewSize.height,
1902
+ className: "h-full w-full object-contain",
1903
+ "aria-label": "Effect preview canvas"
1904
+ }
1905
+ ) }),
1906
+ state.issues.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "space-y-1 rounded border border-destructive/20 bg-destructive/10 p-2 text-xs", "data-effect-issues": true, children: state.issues.map((issue, idx) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
1907
+ "div",
1908
+ {
1909
+ className: `cursor-pointer ${issue.severity === "error" ? "text-destructive" : "text-amber-500"}`,
1910
+ onClick: () => issue.line !== void 0 && jumpToLine(issue.line),
1911
+ children: [
1912
+ issue.line !== void 0 ? `Line ${issue.line}: ` : "",
1913
+ issue.message
1914
+ ]
1915
+ },
1916
+ idx
1917
+ )) })
1918
+ ] }),
1919
+ hasSource && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "space-y-2", "data-effect-source-pane": true, children: [
1920
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "flex items-center justify-between text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { children: [
1921
+ "Source (",
1922
+ state.sourceLanguage,
1923
+ ")"
1924
+ ] }) }),
1925
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex h-64 rounded border border-border bg-muted/20 font-mono text-xs", children: [
1926
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { ref: gutterRef, className: "select-none overflow-hidden border-r border-border bg-muted/40 px-2 py-2 text-right text-muted-foreground", "aria-hidden": "true", children: sourceLines.map((_, i) => {
1927
+ const lineNum = i + 1;
1928
+ const hasIssue = issueLines.has(lineNum);
1929
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1930
+ "div",
1931
+ {
1932
+ "data-gutter-line": lineNum,
1933
+ className: hasIssue ? "font-bold text-destructive" : "",
1934
+ children: lineNum
1935
+ },
1936
+ i
1937
+ );
1938
+ }) }),
1939
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1940
+ "textarea",
1941
+ {
1942
+ ref: textareaRef,
1943
+ value: sourceCode,
1944
+ onChange: handleSourceChange,
1945
+ onScroll: (e) => {
1946
+ if (gutterRef.current) gutterRef.current.scrollTop = e.currentTarget.scrollTop;
1947
+ },
1948
+ "aria-label": "Effect source code",
1949
+ spellCheck: false,
1950
+ wrap: "off",
1951
+ className: "flex-1 resize-none bg-transparent p-2 font-mono text-xs text-foreground focus:outline-none"
1952
+ }
1953
+ )
1954
+ ] })
1955
+ ] })
1956
+ ] }),
1957
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "space-y-2 border-t border-border pt-4", children: [
1958
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: "Parameters" }),
1959
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1960
+ EffectParameters,
1961
+ {
1962
+ description: state.description,
1963
+ values: state.values,
1964
+ onChange: (control, val, gesture) => session.setValue(control, val, { gesture }),
1965
+ onReset: (control) => session.resetValues([control]),
1966
+ onPresetName: (name) => session.applyPreset(name),
1967
+ renderControlAddon: (control) => {
1968
+ const track = state.tracks[control];
1969
+ const isAnimated = Boolean(track && track.length > 0);
1970
+ const hasKeyframeAtPlayhead = isAnimated && track.some((kf) => kf.time === state.time);
1971
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1972
+ "button",
1973
+ {
1974
+ type: "button",
1975
+ "data-keyframe-toggle": control,
1976
+ "aria-label": hasKeyframeAtPlayhead ? `Remove keyframe for ${control}` : `Add keyframe for ${control}`,
1977
+ onClick: () => {
1978
+ if (hasKeyframeAtPlayhead) {
1979
+ session.removeKeyframe(control, state.time);
1980
+ } else {
1981
+ session.setKeyframe(control, state.time);
1982
+ }
1983
+ },
1984
+ className: `rounded px-1 text-xs transition-colors ${hasKeyframeAtPlayhead ? "text-primary font-bold" : isAnimated ? "text-foreground" : "text-muted-foreground hover:text-foreground"}`,
1985
+ title: hasKeyframeAtPlayhead ? "Remove keyframe at playhead" : "Add keyframe at playhead",
1986
+ children: hasKeyframeAtPlayhead ? "\u25C6" : "\u25C7"
1987
+ }
1988
+ );
1989
+ }
1990
+ }
1991
+ )
1992
+ ] }),
1993
+ showTimeline && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "space-y-3 border-t border-border pt-4", "data-effect-timeline": true, children: [
1994
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex flex-wrap items-center justify-between gap-4", children: [
1995
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: "Timeline" }),
1996
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex items-center gap-3 text-xs", children: [
1997
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("label", { className: "flex items-center gap-1.5", children: [
1998
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: "Duration:" }),
1999
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(DurationField, { duration: state.duration, onCommit: (duration) => session.setTiming({ duration }) }),
2000
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "text-muted-foreground", children: "ms" })
2001
+ ] }),
2002
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("label", { className: "flex items-center gap-1.5 cursor-pointer", children: [
2003
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2004
+ "input",
2005
+ {
2006
+ type: "checkbox",
2007
+ "aria-label": "Loop playback",
2008
+ checked: state.loop,
2009
+ onChange: (e) => session.setTiming({ loop: e.target.checked })
2010
+ }
2011
+ ),
2012
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: "Loop" })
2013
+ ] })
2014
+ ] })
2015
+ ] }),
2016
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "space-y-1", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2017
+ "input",
2018
+ {
2019
+ type: "range",
2020
+ "aria-label": "Timeline scrubber",
2021
+ min: 0,
2022
+ max: state.duration,
2023
+ value: state.time,
2024
+ onChange: (e) => session.seek(Number(e.target.value)),
2025
+ className: "w-full cursor-pointer accent-primary"
2026
+ }
2027
+ ) }),
2028
+ Object.entries(state.tracks).length > 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "space-y-2 pt-1", children: Object.entries(state.tracks).map(([control, keyframes]) => {
2029
+ if (!keyframes || keyframes.length === 0) return null;
2030
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "space-y-1", "data-track": control, children: [
2031
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "flex items-center justify-between text-xs text-muted-foreground", children: [
2032
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "font-medium", children: control }),
2033
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2034
+ "button",
2035
+ {
2036
+ type: "button",
2037
+ className: "text-[11px] hover:text-foreground",
2038
+ onClick: () => session.clearTrack(control),
2039
+ "aria-label": `Clear animation track for ${control}`,
2040
+ children: "Clear track"
2041
+ }
2042
+ )
2043
+ ] }),
2044
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "relative h-4 w-full rounded bg-muted/40", children: keyframes.map((kf, i) => {
2045
+ const leftPct = Math.max(
2046
+ 0,
2047
+ Math.min(100, kf.time / (state.duration || 1) * 100)
2048
+ );
2049
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2050
+ "button",
2051
+ {
2052
+ type: "button",
2053
+ onClick: () => session.seek(kf.time),
2054
+ "aria-label": `Seek to ${control} keyframe at ${kf.time}ms`,
2055
+ title: `${control} @ ${kf.time}ms`,
2056
+ style: { left: `${leftPct}%` },
2057
+ className: "absolute top-1/2 -translate-x-1/2 -translate-y-1/2 text-[10px] text-primary hover:scale-125",
2058
+ children: "\u25C6"
2059
+ },
2060
+ i
2061
+ );
2062
+ }) })
2063
+ ] }, control);
2064
+ }) })
2065
+ ] })
2066
+ ] });
2067
+ }
2068
+ function DurationField({ duration, onCommit }) {
2069
+ const [draft, setDraft] = (0, import_react10.useState)(String(duration));
2070
+ (0, import_react10.useEffect)(() => setDraft(String(duration)), [duration]);
2071
+ const commit = () => {
2072
+ const next = Number(draft);
2073
+ if (Number.isFinite(next) && next >= 1 && next !== duration) onCommit(next);
2074
+ else setDraft(String(duration));
2075
+ };
2076
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2077
+ "input",
2078
+ {
2079
+ type: "number",
2080
+ "aria-label": "Duration",
2081
+ min: 1,
2082
+ value: draft,
2083
+ onChange: (e) => setDraft(e.target.value),
2084
+ onBlur: commit,
2085
+ onKeyDown: (e) => {
2086
+ if (e.key === "Enter") commit();
2087
+ else if (e.key === "Escape") setDraft(String(duration));
2088
+ },
2089
+ className: "w-16 rounded border border-border bg-background px-1.5 py-0.5 text-xs font-mono"
2090
+ }
2091
+ );
2092
+ }
598
2093
  // Annotate the CommonJS export names for ESM import in node:
599
2094
  0 && (module.exports = {
2095
+ EffectAuthoringEditor,
600
2096
  EffectParameters,
601
2097
  EffectThumbnail,
602
2098
  EffectsBrowser,
2099
+ useEffectAuthoring,
603
2100
  useEffectDescription,
604
2101
  useEffects
605
2102
  });