@pixerate/editor-react 0.95.0 → 0.96.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 (47) hide show
  1. package/README.md +2 -0
  2. package/dist/animation-editor/index.cjs +1240 -195
  3. package/dist/animation-editor/index.js +4 -2
  4. package/dist/canvas/index.cjs +1418 -373
  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-5R67YSSD.js → chunk-GLSOQNQR.js} +1 -1
  9. package/dist/{chunk-6YRSQW2V.js → chunk-IY6YOY5B.js} +1 -1
  10. package/dist/chunk-KIRIU53A.js +72 -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/index.cjs +1169 -124
  22. package/dist/effects/index.js +4 -2
  23. package/dist/gradient/FillPicker.d.cts +27 -0
  24. package/dist/gradient/FillPicker.d.ts +27 -0
  25. package/dist/gradient/GradientEditor.d.cts +21 -0
  26. package/dist/gradient/GradientEditor.d.ts +21 -0
  27. package/dist/gradient/index.cjs +1601 -0
  28. package/dist/gradient/index.d.cts +6 -0
  29. package/dist/gradient/index.d.ts +6 -0
  30. package/dist/gradient/index.js +617 -0
  31. package/dist/gradient/useGradientController.d.cts +10 -0
  32. package/dist/gradient/useGradientController.d.ts +10 -0
  33. package/dist/image-editor/index.cjs +1742 -697
  34. package/dist/image-editor/index.js +5 -3
  35. package/dist/index.cjs +2160 -1115
  36. package/dist/index.js +5 -3
  37. package/dist/paint-editor/index.cjs +1233 -188
  38. package/dist/paint-editor/index.js +4 -2
  39. package/dist/parameters/fields.d.cts +1 -1
  40. package/dist/parameters/fields.d.ts +1 -1
  41. package/dist/parameters/index.cjs +1218 -173
  42. package/dist/parameters/index.js +3 -1
  43. package/dist/vector/index.cjs +1219 -174
  44. package/dist/vector/index.js +4 -2
  45. package/dist/video-editor/index.cjs +1230 -185
  46. package/dist/video-editor/index.js +4 -2
  47. package/package.json +29 -3
@@ -0,0 +1,1067 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/color/index.ts
22
+ var color_exports = {};
23
+ __export(color_exports, {
24
+ ColorPicker: () => ColorPicker,
25
+ DualColorPicker: () => DualColorPicker,
26
+ useColorScheme: () => useColorScheme,
27
+ useResolvedColor: () => useResolvedColor
28
+ });
29
+ module.exports = __toCommonJS(color_exports);
30
+
31
+ // src/color/ColorPicker.tsx
32
+ var import_react = require("react");
33
+ var import_color = require("@pixerate/editor/color");
34
+ var import_jsx_runtime = require("react/jsx-runtime");
35
+ var LOCAL_STORAGE_KEY = "pixerate:color:recent";
36
+ function readLocalRecents() {
37
+ try {
38
+ if (typeof localStorage === "undefined") return [];
39
+ const raw = localStorage.getItem(LOCAL_STORAGE_KEY);
40
+ if (!raw) return [];
41
+ const parsed = JSON.parse(raw);
42
+ return Array.isArray(parsed) ? parsed : [];
43
+ } catch {
44
+ return [];
45
+ }
46
+ }
47
+ function writeLocalRecents(list) {
48
+ try {
49
+ if (typeof localStorage !== "undefined") {
50
+ localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(list));
51
+ }
52
+ } catch {
53
+ }
54
+ }
55
+ var CHECKERBOARD_BG = "repeating-conic-gradient(var(--pixerate-checker-a, #d4d4d8) 0 25%, var(--pixerate-checker-b, #ffffff) 0 50%)";
56
+ var DEFAULT_PICKER_STATE = { h: 0, s: 1, v: 1, alpha: 1 };
57
+ var ColorPicker = ({
58
+ value,
59
+ onChange,
60
+ onGestureStart,
61
+ onGestureEnd,
62
+ alpha = false,
63
+ swatches,
64
+ recent: controlledRecent,
65
+ onRecentChange,
66
+ contrastAgainst,
67
+ disabled = false,
68
+ className,
69
+ id,
70
+ "aria-label": ariaLabel = "Color picker"
71
+ }) => {
72
+ const generatedId = (0, import_react.useId)();
73
+ const pickerId = id || generatedId;
74
+ const [pickerState, setPickerState] = (0, import_react.useState)(
75
+ () => (0, import_color.pickerStateFromColor)(value) ?? DEFAULT_PICKER_STATE
76
+ );
77
+ const stateRef = (0, import_react.useRef)(pickerState);
78
+ stateRef.current = pickerState;
79
+ (0, import_react.useEffect)(() => {
80
+ const next = (0, import_color.pickerStateFromColor)(value, stateRef.current);
81
+ if (next) {
82
+ setPickerState(next);
83
+ }
84
+ }, [value]);
85
+ const [internalRecent, setInternalRecent] = (0, import_react.useState)(
86
+ () => controlledRecent ? [] : readLocalRecents()
87
+ );
88
+ const activeRecent = controlledRecent ?? internalRecent;
89
+ const recordRecent = (0, import_react.useCallback)(
90
+ (color) => {
91
+ const updated = (0, import_color.pushRecentColor)(activeRecent, color, 12);
92
+ if (!controlledRecent) {
93
+ setInternalRecent(updated);
94
+ writeLocalRecents(updated);
95
+ }
96
+ onRecentChange?.(updated);
97
+ },
98
+ [activeRecent, controlledRecent, onRecentChange]
99
+ );
100
+ const [textDraft, setTextDraft] = (0, import_react.useState)(value);
101
+ const [isInvalid, setIsInvalid] = (0, import_react.useState)(false);
102
+ const [isClipped, setIsClipped] = (0, import_react.useState)(false);
103
+ const isTypingRef = (0, import_react.useRef)(false);
104
+ (0, import_react.useEffect)(() => {
105
+ if (!isTypingRef.current) {
106
+ setTextDraft(value);
107
+ setIsInvalid(false);
108
+ const parsed = (0, import_color.parseColor)(value);
109
+ setIsClipped(Boolean(parsed && !(0, import_color.inSrgbGamut)(parsed)));
110
+ }
111
+ }, [value]);
112
+ const [hasEyeDropper, setHasEyeDropper] = (0, import_react.useState)(false);
113
+ (0, import_react.useEffect)(() => {
114
+ setHasEyeDropper(typeof window !== "undefined" && "EyeDropper" in window);
115
+ }, []);
116
+ const emitColorChange = (0, import_react.useCallback)(
117
+ (nextState) => {
118
+ setPickerState(nextState);
119
+ const hex = (0, import_color.pickerStateToHex)(nextState, alpha);
120
+ onChange(hex);
121
+ },
122
+ [alpha, onChange]
123
+ );
124
+ const latest = (0, import_react.useRef)({ emitColorChange, recordRecent, onGestureEnd, alpha });
125
+ latest.current = { emitColorChange, recordRecent, onGestureEnd, alpha };
126
+ const endDragRef = (0, import_react.useRef)(null);
127
+ (0, import_react.useEffect)(() => () => endDragRef.current?.(), []);
128
+ const startDrag = (e, next) => {
129
+ if (disabled) return;
130
+ e.preventDefault();
131
+ endDragRef.current?.();
132
+ onGestureStart?.();
133
+ const rect = e.currentTarget.getBoundingClientRect();
134
+ const update = (clientX, clientY) => {
135
+ const x = Math.max(0, Math.min(1, (clientX - rect.left) / rect.width));
136
+ const y = Math.max(0, Math.min(1, (clientY - rect.top) / rect.height));
137
+ latest.current.emitColorChange(next(stateRef.current, x, y));
138
+ };
139
+ update(e.clientX, e.clientY);
140
+ const onPointerMove = (ev) => update(ev.clientX, ev.clientY);
141
+ const end = () => {
142
+ window.removeEventListener("pointermove", onPointerMove);
143
+ window.removeEventListener("pointerup", onPointerUp);
144
+ window.removeEventListener("pointercancel", onPointerUp);
145
+ endDragRef.current = null;
146
+ latest.current.onGestureEnd?.();
147
+ };
148
+ const onPointerUp = () => {
149
+ end();
150
+ latest.current.recordRecent((0, import_color.pickerStateToHex)(stateRef.current, latest.current.alpha));
151
+ };
152
+ endDragRef.current = end;
153
+ window.addEventListener("pointermove", onPointerMove);
154
+ window.addEventListener("pointerup", onPointerUp);
155
+ window.addEventListener("pointercancel", onPointerUp);
156
+ };
157
+ const handleAreaPointerDown = (e) => startDrag(e, (state, x, y) => (0, import_color.pickerStateFromArea)(state, x, y));
158
+ const handleHuePointerDown = (e) => startDrag(e, (state, x) => (0, import_color.pickerStateFromHue)(state, x));
159
+ const handleAlphaPointerDown = (e) => startDrag(e, (state, x) => (0, import_color.pickerStateFromAlpha)(state, x));
160
+ const handleAreaKeyDown = (e) => {
161
+ if (disabled) return;
162
+ const next = (0, import_color.pickerKeyStep)(pickerState, "area", e.key, e.shiftKey);
163
+ if (next) {
164
+ e.preventDefault();
165
+ emitColorChange(next);
166
+ recordRecent((0, import_color.pickerStateToHex)(next, alpha));
167
+ }
168
+ };
169
+ const handleHueKeyDown = (e) => {
170
+ if (disabled) return;
171
+ const next = (0, import_color.pickerKeyStep)(pickerState, "hue", e.key, e.shiftKey);
172
+ if (next) {
173
+ e.preventDefault();
174
+ emitColorChange(next);
175
+ recordRecent((0, import_color.pickerStateToHex)(next, alpha));
176
+ }
177
+ };
178
+ const handleAlphaKeyDown = (e) => {
179
+ if (disabled) return;
180
+ const next = (0, import_color.pickerKeyStep)(pickerState, "alpha", e.key, e.shiftKey);
181
+ if (next) {
182
+ e.preventDefault();
183
+ emitColorChange(next);
184
+ recordRecent((0, import_color.pickerStateToHex)(next, alpha));
185
+ }
186
+ };
187
+ const commitTextInput = (inputElement) => {
188
+ isTypingRef.current = false;
189
+ const parsed = (0, import_color.parseColor)(textDraft);
190
+ if (parsed) {
191
+ setIsInvalid(false);
192
+ setIsClipped(!(0, import_color.inSrgbGamut)(parsed));
193
+ const formatted = (0, import_color.formatHex)(parsed);
194
+ onChange(formatted);
195
+ recordRecent(formatted);
196
+ } else {
197
+ setIsInvalid(true);
198
+ setTextDraft(value);
199
+ if (inputElement) {
200
+ inputElement.value = value;
201
+ }
202
+ }
203
+ };
204
+ const handleTextKeyDown = (e) => {
205
+ if (e.key === "Enter") {
206
+ e.preventDefault();
207
+ commitTextInput(e.currentTarget);
208
+ } else if (e.key === "Escape") {
209
+ e.preventDefault();
210
+ isTypingRef.current = false;
211
+ setIsInvalid(false);
212
+ setTextDraft(value);
213
+ e.currentTarget.value = value;
214
+ }
215
+ };
216
+ const handleEyeDropper = async () => {
217
+ if (disabled || !hasEyeDropper) return;
218
+ try {
219
+ const EyeDropperClass = window.EyeDropper;
220
+ const eyeDropper = new EyeDropperClass();
221
+ const res = await eyeDropper.open();
222
+ if (res?.sRGBHex) {
223
+ onChange(res.sRGBHex);
224
+ recordRecent(res.sRGBHex);
225
+ }
226
+ } catch {
227
+ }
228
+ };
229
+ const contrastResult = (0, import_react.useMemo)(() => {
230
+ if (!contrastAgainst) return null;
231
+ const fg = (0, import_color.parseColor)(value);
232
+ const bg = (0, import_color.parseColor)(contrastAgainst);
233
+ if (!fg || !bg) return null;
234
+ const ratio = (0, import_color.contrastRatio)(fg, bg);
235
+ const aa = ratio >= 4.5;
236
+ const aaa = ratio >= 7;
237
+ return { ratio, aa, aaa };
238
+ }, [value, contrastAgainst]);
239
+ const currentHex = (0, import_color.pickerStateToHex)(pickerState, alpha);
240
+ const liveDescription = `Selected color: ${value}${contrastResult ? `, contrast ${contrastResult.ratio.toFixed(1)}:1 against ${contrastAgainst}, ${contrastResult.aa ? "passes AA" : "fails AA"}` : ""}`;
241
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
242
+ "div",
243
+ {
244
+ id: pickerId,
245
+ role: "group",
246
+ "aria-label": ariaLabel,
247
+ className,
248
+ style: {
249
+ boxSizing: "border-box",
250
+ width: "var(--pixerate-color-picker-width, 240px)",
251
+ borderRadius: "var(--pixerate-color-picker-radius, 8px)",
252
+ background: "var(--pixerate-color-picker-bg, #1f2430)",
253
+ color: "var(--pixerate-color-picker-fg, #f0f2f5)",
254
+ padding: "12px",
255
+ display: "flex",
256
+ flexDirection: "column",
257
+ gap: "10px",
258
+ fontFamily: "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
259
+ fontSize: "12px",
260
+ userSelect: "none",
261
+ opacity: disabled ? 0.6 : 1,
262
+ pointerEvents: disabled ? "none" : "auto"
263
+ },
264
+ children: [
265
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
266
+ "span",
267
+ {
268
+ role: "status",
269
+ "aria-live": "polite",
270
+ style: {
271
+ position: "absolute",
272
+ width: "1px",
273
+ height: "1px",
274
+ padding: 0,
275
+ margin: "-1px",
276
+ overflow: "hidden",
277
+ clip: "rect(0, 0, 0, 0)",
278
+ whiteSpace: "nowrap",
279
+ border: 0
280
+ },
281
+ children: liveDescription
282
+ }
283
+ ),
284
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
285
+ "div",
286
+ {
287
+ role: "slider",
288
+ tabIndex: disabled ? -1 : 0,
289
+ "aria-label": "Saturation and brightness",
290
+ "aria-valuetext": `Saturation ${Math.round(pickerState.s * 100)}%, Brightness ${Math.round(
291
+ pickerState.v * 100
292
+ )}%`,
293
+ "aria-disabled": disabled,
294
+ onPointerDown: handleAreaPointerDown,
295
+ onKeyDown: handleAreaKeyDown,
296
+ style: {
297
+ position: "relative",
298
+ width: "100%",
299
+ height: "150px",
300
+ borderRadius: "6px",
301
+ background: (0, import_color.pickerAreaBackground)(pickerState),
302
+ cursor: disabled ? "default" : "crosshair",
303
+ touchAction: "none",
304
+ outline: "none"
305
+ },
306
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
307
+ "div",
308
+ {
309
+ style: {
310
+ position: "absolute",
311
+ width: "var(--pixerate-color-picker-thumb-size, 14px)",
312
+ height: "var(--pixerate-color-picker-thumb-size, 14px)",
313
+ borderRadius: "50%",
314
+ transform: "translate(-50%, -50%)",
315
+ left: `${pickerState.s * 100}%`,
316
+ top: `${(1 - pickerState.v) * 100}%`,
317
+ border: "2px solid #ffffff",
318
+ boxShadow: "0 0 2px 1px rgba(0,0,0,0.6)",
319
+ pointerEvents: "none",
320
+ backgroundColor: currentHex
321
+ }
322
+ }
323
+ )
324
+ }
325
+ ),
326
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
327
+ "div",
328
+ {
329
+ role: "slider",
330
+ tabIndex: disabled ? -1 : 0,
331
+ "aria-label": "Hue",
332
+ "aria-valuenow": Math.round(pickerState.h),
333
+ "aria-valuemin": 0,
334
+ "aria-valuemax": 360,
335
+ "aria-valuetext": `${Math.round(pickerState.h)} degrees`,
336
+ "aria-disabled": disabled,
337
+ onPointerDown: handleHuePointerDown,
338
+ onKeyDown: handleHueKeyDown,
339
+ style: {
340
+ position: "relative",
341
+ width: "100%",
342
+ height: "12px",
343
+ borderRadius: "6px",
344
+ background: import_color.PICKER_HUE_BACKGROUND,
345
+ cursor: disabled ? "default" : "pointer",
346
+ touchAction: "none",
347
+ outline: "none"
348
+ },
349
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
350
+ "div",
351
+ {
352
+ style: {
353
+ position: "absolute",
354
+ top: "50%",
355
+ transform: "translate(-50%, -50%)",
356
+ left: `${pickerState.h / 360 * 100}%`,
357
+ width: "var(--pixerate-color-picker-thumb-size, 14px)",
358
+ height: "var(--pixerate-color-picker-thumb-size, 14px)",
359
+ borderRadius: "50%",
360
+ border: "2px solid #ffffff",
361
+ boxShadow: "0 0 2px 1px rgba(0,0,0,0.6)",
362
+ pointerEvents: "none",
363
+ backgroundColor: `hsl(${pickerState.h}, 100%, 50%)`
364
+ }
365
+ }
366
+ )
367
+ }
368
+ ),
369
+ alpha && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
370
+ "div",
371
+ {
372
+ role: "slider",
373
+ tabIndex: disabled ? -1 : 0,
374
+ "aria-label": "Alpha",
375
+ "aria-valuenow": Math.round(pickerState.alpha * 100),
376
+ "aria-valuemin": 0,
377
+ "aria-valuemax": 100,
378
+ "aria-valuetext": `${Math.round(pickerState.alpha * 100)}%`,
379
+ "aria-disabled": disabled,
380
+ onPointerDown: handleAlphaPointerDown,
381
+ onKeyDown: handleAlphaKeyDown,
382
+ style: {
383
+ position: "relative",
384
+ width: "100%",
385
+ height: "12px",
386
+ borderRadius: "6px",
387
+ backgroundImage: CHECKERBOARD_BG,
388
+ backgroundSize: "8px 8px",
389
+ cursor: disabled ? "default" : "pointer",
390
+ touchAction: "none",
391
+ outline: "none",
392
+ overflow: "hidden"
393
+ },
394
+ children: [
395
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
396
+ "div",
397
+ {
398
+ style: {
399
+ position: "absolute",
400
+ inset: 0,
401
+ background: (0, import_color.pickerAlphaBackground)(pickerState)
402
+ }
403
+ }
404
+ ),
405
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
406
+ "div",
407
+ {
408
+ style: {
409
+ position: "absolute",
410
+ top: "50%",
411
+ transform: "translate(-50%, -50%)",
412
+ left: `${pickerState.alpha * 100}%`,
413
+ width: "var(--pixerate-color-picker-thumb-size, 14px)",
414
+ height: "var(--pixerate-color-picker-thumb-size, 14px)",
415
+ borderRadius: "50%",
416
+ border: "2px solid #ffffff",
417
+ boxShadow: "0 0 2px 1px rgba(0,0,0,0.6)",
418
+ pointerEvents: "none",
419
+ backgroundColor: currentHex
420
+ }
421
+ }
422
+ )
423
+ ]
424
+ }
425
+ ),
426
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "8px", marginTop: "2px" }, children: [
427
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
428
+ "div",
429
+ {
430
+ style: {
431
+ position: "relative",
432
+ width: "28px",
433
+ height: "28px",
434
+ borderRadius: "4px",
435
+ backgroundImage: CHECKERBOARD_BG,
436
+ backgroundSize: "8px 8px",
437
+ overflow: "hidden",
438
+ flexShrink: 0,
439
+ border: "1px solid rgba(255,255,255,0.15)"
440
+ },
441
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
442
+ "div",
443
+ {
444
+ style: {
445
+ width: "100%",
446
+ height: "100%",
447
+ backgroundColor: currentHex
448
+ }
449
+ }
450
+ )
451
+ }
452
+ ),
453
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
454
+ "input",
455
+ {
456
+ type: "text",
457
+ value: textDraft,
458
+ disabled,
459
+ "aria-label": "Color hex or CSS string",
460
+ "aria-invalid": isInvalid ? "true" : void 0,
461
+ onChange: (e) => {
462
+ isTypingRef.current = true;
463
+ setTextDraft(e.target.value);
464
+ setIsInvalid(false);
465
+ },
466
+ onKeyDown: handleTextKeyDown,
467
+ onBlur: (e) => commitTextInput(e.currentTarget),
468
+ style: {
469
+ flex: 1,
470
+ minWidth: 0,
471
+ height: "28px",
472
+ padding: "0 8px",
473
+ fontSize: "12px",
474
+ fontFamily: "monospace",
475
+ borderRadius: "4px",
476
+ border: isInvalid ? "1px solid #ef4444" : "1px solid rgba(255,255,255,0.2)",
477
+ background: "rgba(0,0,0,0.2)",
478
+ color: "inherit",
479
+ outline: "none"
480
+ }
481
+ }
482
+ ),
483
+ hasEyeDropper && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
484
+ "button",
485
+ {
486
+ type: "button",
487
+ disabled,
488
+ "aria-label": "Pick color from screen",
489
+ title: "Pick color from screen",
490
+ onClick: handleEyeDropper,
491
+ style: {
492
+ display: "inline-flex",
493
+ alignItems: "center",
494
+ justifyContent: "center",
495
+ width: "28px",
496
+ height: "28px",
497
+ borderRadius: "4px",
498
+ border: "1px solid rgba(255,255,255,0.2)",
499
+ background: "transparent",
500
+ color: "inherit",
501
+ cursor: disabled ? "default" : "pointer"
502
+ },
503
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
504
+ "svg",
505
+ {
506
+ width: "14",
507
+ height: "14",
508
+ viewBox: "0 0 24 24",
509
+ fill: "none",
510
+ stroke: "currentColor",
511
+ strokeWidth: "2",
512
+ strokeLinecap: "round",
513
+ strokeLinejoin: "round",
514
+ children: [
515
+ /* @__PURE__ */ (0, import_jsx_runtime.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" }),
516
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m5 16-3 3 1 1 3-3" }),
517
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m14 6 4 4" })
518
+ ]
519
+ }
520
+ )
521
+ }
522
+ )
523
+ ] }),
524
+ isClipped && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
525
+ "div",
526
+ {
527
+ role: "note",
528
+ title: "This colour was outside standard sRGB and clipped.",
529
+ style: {
530
+ display: "inline-flex",
531
+ alignItems: "center",
532
+ gap: "4px",
533
+ fontSize: "10px",
534
+ color: "#f59e0b",
535
+ background: "rgba(245, 158, 11, 0.1)",
536
+ padding: "2px 6px",
537
+ borderRadius: "4px",
538
+ alignSelf: "flex-start"
539
+ },
540
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "\u26A0 Clipped to sRGB" })
541
+ }
542
+ ),
543
+ contrastResult && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
544
+ "div",
545
+ {
546
+ style: {
547
+ display: "flex",
548
+ alignItems: "center",
549
+ justifyContent: "space-between",
550
+ fontSize: "11px",
551
+ padding: "4px 8px",
552
+ borderRadius: "4px",
553
+ background: "rgba(255,255,255,0.05)",
554
+ border: "1px solid rgba(255,255,255,0.1)"
555
+ },
556
+ children: [
557
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
558
+ "Contrast: ",
559
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("strong", { children: [
560
+ contrastResult.ratio.toFixed(2),
561
+ ":1"
562
+ ] })
563
+ ] }),
564
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", gap: "6px" }, children: [
565
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
566
+ "span",
567
+ {
568
+ style: {
569
+ color: contrastResult.aa ? "#10b981" : "#ef4444",
570
+ fontWeight: 600
571
+ },
572
+ children: [
573
+ "AA ",
574
+ contrastResult.aa ? "\u2713" : "\u2717"
575
+ ]
576
+ }
577
+ ),
578
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
579
+ "span",
580
+ {
581
+ style: {
582
+ color: contrastResult.aaa ? "#10b981" : "#ef4444",
583
+ fontWeight: 600
584
+ },
585
+ children: [
586
+ "AAA ",
587
+ contrastResult.aaa ? "\u2713" : "\u2717"
588
+ ]
589
+ }
590
+ )
591
+ ] })
592
+ ]
593
+ }
594
+ ),
595
+ swatches && swatches.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: "4px" }, children: [
596
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontSize: "10px", textTransform: "uppercase", opacity: 0.6 }, children: "Palette" }),
597
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { display: "flex", flexWrap: "wrap", gap: "4px" }, children: swatches.map((color, idx) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
598
+ "button",
599
+ {
600
+ type: "button",
601
+ "data-testid": "color-picker-swatch",
602
+ title: color,
603
+ disabled,
604
+ "aria-label": `Color ${color}`,
605
+ onClick: () => {
606
+ onChange(color);
607
+ recordRecent(color);
608
+ },
609
+ style: {
610
+ width: "18px",
611
+ height: "18px",
612
+ borderRadius: "3px",
613
+ backgroundColor: color,
614
+ border: color.toLowerCase() === value.toLowerCase() ? "2px solid #ffffff" : "1px solid rgba(255,255,255,0.2)",
615
+ cursor: disabled ? "default" : "pointer",
616
+ padding: 0,
617
+ outline: "none"
618
+ }
619
+ },
620
+ `${color}-${idx}`
621
+ )) })
622
+ ] }),
623
+ activeRecent.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: "4px" }, children: [
624
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontSize: "10px", textTransform: "uppercase", opacity: 0.6 }, children: "Recent" }),
625
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { display: "flex", flexWrap: "wrap", gap: "4px" }, children: activeRecent.map((color, idx) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
626
+ "button",
627
+ {
628
+ type: "button",
629
+ "data-testid": "color-picker-recent",
630
+ disabled,
631
+ "aria-label": `Color ${color}`,
632
+ onClick: () => {
633
+ onChange(color);
634
+ recordRecent(color);
635
+ },
636
+ style: {
637
+ width: "18px",
638
+ height: "18px",
639
+ borderRadius: "3px",
640
+ backgroundColor: color,
641
+ border: color.toLowerCase() === value.toLowerCase() ? "2px solid #ffffff" : "1px solid rgba(255,255,255,0.2)",
642
+ cursor: disabled ? "default" : "pointer",
643
+ padding: 0,
644
+ outline: "none"
645
+ }
646
+ },
647
+ `recent-${color}-${idx}`
648
+ )) })
649
+ ] })
650
+ ]
651
+ }
652
+ );
653
+ };
654
+
655
+ // src/color/DualColorPicker.tsx
656
+ var import_react2 = require("react");
657
+ var import_color2 = require("@pixerate/editor/color");
658
+ var import_jsx_runtime2 = require("react/jsx-runtime");
659
+ function DualColorPicker({
660
+ value,
661
+ onChange,
662
+ onGestureStart,
663
+ onGestureEnd,
664
+ scheme: controlledScheme,
665
+ onSchemeChange,
666
+ surfaces = import_color2.DEFAULT_SCHEME_SURFACES,
667
+ contrastAgainst,
668
+ alpha = false,
669
+ swatches,
670
+ disabled = false,
671
+ className = ""
672
+ }) {
673
+ const sameId = (0, import_react2.useId)();
674
+ const [internalScheme, setInternalScheme] = (0, import_react2.useState)("light");
675
+ const activeScheme = controlledScheme ?? internalScheme;
676
+ const handleSchemeSelect = (nextScheme) => {
677
+ if (onSchemeChange) {
678
+ onSchemeChange(nextScheme);
679
+ } else {
680
+ setInternalScheme(nextScheme);
681
+ }
682
+ };
683
+ const dual = (0, import_color2.normalizeDualColor)(value) ?? { light: "#000000", dark: "#000000" };
684
+ const isSame = dual.light.toLowerCase() === dual.dark.toLowerCase();
685
+ const [sameInBoth, setSameInBoth] = (0, import_react2.useState)(isSame);
686
+ const handleSameToggle = (e) => {
687
+ const nextSame = e.target.checked;
688
+ setSameInBoth(nextSame);
689
+ if (nextSame) {
690
+ const activeVal = activeScheme === "dark" ? dual.dark : dual.light;
691
+ onChange({ light: activeVal, dark: activeVal });
692
+ }
693
+ };
694
+ const handleDerive = () => {
695
+ if (disabled) return;
696
+ onGestureStart?.();
697
+ const currentActive = activeScheme === "dark" ? dual.dark : dual.light;
698
+ const derived = (0, import_color2.deriveDualColor)(currentActive, {
699
+ from: activeScheme,
700
+ // An unreadable surfaces prop falls back to the defaults rather than throwing.
701
+ surfaces: (0, import_color2.normalizeDualColor)(surfaces) ?? import_color2.DEFAULT_SCHEME_SURFACES
702
+ });
703
+ onChange(derived);
704
+ onGestureEnd?.();
705
+ };
706
+ const handleInnerChange = (hex) => {
707
+ if (sameInBoth) {
708
+ onChange({ light: hex, dark: hex });
709
+ } else {
710
+ const updated = (0, import_color2.setDualColorSide)(dual, activeScheme, hex);
711
+ onChange(updated);
712
+ }
713
+ };
714
+ const activeColor = activeScheme === "dark" ? dual.dark : dual.light;
715
+ const activeContrastTarget = contrastAgainst ? (0, import_color2.resolveColor)(contrastAgainst, activeScheme) ?? void 0 : void 0;
716
+ const dualContrast = contrastAgainst && (0, import_color2.normalizeDualColor)(contrastAgainst) ? (0, import_color2.checkDualColorContrast)(dual, contrastAgainst) : null;
717
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
718
+ "div",
719
+ {
720
+ className: `pixerate-dual-color-picker ${className}`,
721
+ style: {
722
+ display: "flex",
723
+ flexDirection: "column",
724
+ gap: "12px",
725
+ padding: "12px",
726
+ background: "#1a1d24",
727
+ color: "#e2e8f0",
728
+ borderRadius: "10px",
729
+ boxShadow: "0 4px 12px rgba(0,0,0,0.3)",
730
+ width: "260px",
731
+ fontFamily: "system-ui, -apple-system, sans-serif",
732
+ fontSize: "13px",
733
+ boxSizing: "border-box"
734
+ },
735
+ children: [
736
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
737
+ "div",
738
+ {
739
+ role: "tablist",
740
+ "aria-label": "Color scheme mode",
741
+ style: {
742
+ display: "flex",
743
+ background: "#111318",
744
+ borderRadius: "6px",
745
+ padding: "2px",
746
+ gap: "2px"
747
+ },
748
+ children: [
749
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
750
+ "button",
751
+ {
752
+ type: "button",
753
+ role: "tab",
754
+ "aria-selected": activeScheme === "light",
755
+ onClick: () => handleSchemeSelect("light"),
756
+ disabled,
757
+ style: {
758
+ flex: 1,
759
+ padding: "6px 8px",
760
+ border: "none",
761
+ borderRadius: "4px",
762
+ background: activeScheme === "light" ? "#2d3342" : "transparent",
763
+ color: activeScheme === "light" ? "#ffffff" : "#8c95a6",
764
+ fontWeight: activeScheme === "light" ? 600 : 400,
765
+ cursor: disabled ? "not-allowed" : "pointer",
766
+ fontSize: "12px",
767
+ transition: "all 0.15s ease"
768
+ },
769
+ children: "Light"
770
+ }
771
+ ),
772
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
773
+ "button",
774
+ {
775
+ type: "button",
776
+ role: "tab",
777
+ "aria-selected": activeScheme === "dark",
778
+ onClick: () => handleSchemeSelect("dark"),
779
+ disabled,
780
+ style: {
781
+ flex: 1,
782
+ padding: "6px 8px",
783
+ border: "none",
784
+ borderRadius: "4px",
785
+ background: activeScheme === "dark" ? "#2d3342" : "transparent",
786
+ color: activeScheme === "dark" ? "#ffffff" : "#8c95a6",
787
+ fontWeight: activeScheme === "dark" ? 600 : 400,
788
+ cursor: disabled ? "not-allowed" : "pointer",
789
+ fontSize: "12px",
790
+ transition: "all 0.15s ease"
791
+ },
792
+ children: "Dark"
793
+ }
794
+ )
795
+ ]
796
+ }
797
+ ),
798
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { display: "flex", gap: "8px" }, children: [
799
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
800
+ "button",
801
+ {
802
+ type: "button",
803
+ onClick: () => handleSchemeSelect("light"),
804
+ disabled,
805
+ title: "Edit light mode colour",
806
+ style: {
807
+ flex: 1,
808
+ display: "flex",
809
+ flexDirection: "column",
810
+ alignItems: "center",
811
+ gap: "6px",
812
+ padding: "8px",
813
+ background: surfaces.light,
814
+ color: "#000000",
815
+ border: activeScheme === "light" ? "2px solid #3b82f6" : "1px solid #333842",
816
+ borderRadius: "6px",
817
+ cursor: disabled ? "not-allowed" : "pointer",
818
+ outline: "none"
819
+ },
820
+ children: [
821
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
822
+ "span",
823
+ {
824
+ style: {
825
+ width: "100%",
826
+ height: "24px",
827
+ borderRadius: "4px",
828
+ background: dual.light,
829
+ border: "1px solid rgba(0,0,0,0.15)"
830
+ }
831
+ }
832
+ ),
833
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { fontSize: "11px", fontWeight: 600 }, children: "Light" })
834
+ ]
835
+ }
836
+ ),
837
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
838
+ "button",
839
+ {
840
+ type: "button",
841
+ onClick: () => handleSchemeSelect("dark"),
842
+ disabled,
843
+ title: "Edit dark mode colour",
844
+ style: {
845
+ flex: 1,
846
+ display: "flex",
847
+ flexDirection: "column",
848
+ alignItems: "center",
849
+ gap: "6px",
850
+ padding: "8px",
851
+ background: surfaces.dark,
852
+ color: "#ffffff",
853
+ border: activeScheme === "dark" ? "2px solid #3b82f6" : "1px solid #333842",
854
+ borderRadius: "6px",
855
+ cursor: disabled ? "not-allowed" : "pointer",
856
+ outline: "none"
857
+ },
858
+ children: [
859
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
860
+ "span",
861
+ {
862
+ style: {
863
+ width: "100%",
864
+ height: "24px",
865
+ borderRadius: "4px",
866
+ background: dual.dark,
867
+ border: "1px solid rgba(255,255,255,0.15)"
868
+ }
869
+ }
870
+ ),
871
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { fontSize: "11px", fontWeight: 600 }, children: "Dark" })
872
+ ]
873
+ }
874
+ )
875
+ ] }),
876
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
877
+ "div",
878
+ {
879
+ style: {
880
+ display: "flex",
881
+ alignItems: "center",
882
+ justifyContent: "space-between",
883
+ gap: "8px",
884
+ padding: "2px 0"
885
+ },
886
+ children: [
887
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
888
+ "label",
889
+ {
890
+ htmlFor: sameId,
891
+ style: {
892
+ display: "flex",
893
+ alignItems: "center",
894
+ gap: "6px",
895
+ cursor: disabled ? "not-allowed" : "pointer",
896
+ userSelect: "none",
897
+ fontSize: "12px",
898
+ color: "#c4cad4"
899
+ },
900
+ children: [
901
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
902
+ "input",
903
+ {
904
+ id: sameId,
905
+ type: "checkbox",
906
+ checked: sameInBoth,
907
+ onChange: handleSameToggle,
908
+ disabled,
909
+ style: { cursor: disabled ? "not-allowed" : "pointer" }
910
+ }
911
+ ),
912
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: "Same in both" })
913
+ ]
914
+ }
915
+ ),
916
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
917
+ "button",
918
+ {
919
+ type: "button",
920
+ onClick: handleDerive,
921
+ disabled,
922
+ style: {
923
+ padding: "4px 10px",
924
+ background: "#2d3342",
925
+ color: "#e2e8f0",
926
+ border: "1px solid #3b4252",
927
+ borderRadius: "4px",
928
+ fontSize: "11px",
929
+ fontWeight: 500,
930
+ cursor: disabled ? "not-allowed" : "pointer"
931
+ },
932
+ children: "Derive"
933
+ }
934
+ )
935
+ ]
936
+ }
937
+ ),
938
+ dualContrast && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
939
+ "div",
940
+ {
941
+ "data-testid": "dual-contrast-summary",
942
+ style: {
943
+ display: "flex",
944
+ justifyContent: "space-between",
945
+ background: "#111318",
946
+ padding: "6px 8px",
947
+ borderRadius: "6px",
948
+ fontSize: "11px",
949
+ color: "#8c95a6"
950
+ },
951
+ children: [
952
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
953
+ "Light:",
954
+ " ",
955
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("strong", { style: { color: dualContrast.light.level === "fail" ? "#ef4444" : "#22c55e" }, children: [
956
+ dualContrast.light.ratio.toFixed(2),
957
+ " (",
958
+ dualContrast.light.level,
959
+ ")"
960
+ ] })
961
+ ] }),
962
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
963
+ "Dark:",
964
+ " ",
965
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("strong", { style: { color: dualContrast.dark.level === "fail" ? "#ef4444" : "#22c55e" }, children: [
966
+ dualContrast.dark.ratio.toFixed(2),
967
+ " (",
968
+ dualContrast.dark.level,
969
+ ")"
970
+ ] })
971
+ ] })
972
+ ]
973
+ }
974
+ ),
975
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
976
+ ColorPicker,
977
+ {
978
+ value: activeColor,
979
+ onChange: handleInnerChange,
980
+ onGestureStart,
981
+ onGestureEnd,
982
+ contrastAgainst: activeContrastTarget,
983
+ alpha,
984
+ swatches,
985
+ disabled
986
+ }
987
+ )
988
+ ]
989
+ }
990
+ );
991
+ }
992
+
993
+ // src/color/useColorScheme.ts
994
+ var import_react3 = require("react");
995
+ var import_color3 = require("@pixerate/editor/color");
996
+ function getSnapshot(attribute) {
997
+ if (typeof window === "undefined" || typeof document === "undefined") {
998
+ return "light";
999
+ }
1000
+ if (attribute) {
1001
+ const el = document.documentElement;
1002
+ if (attribute === "class") {
1003
+ return el.classList.contains("dark") ? "dark" : "light";
1004
+ }
1005
+ const val = el.getAttribute(attribute);
1006
+ return val === "dark" ? "dark" : "light";
1007
+ }
1008
+ if (typeof window.matchMedia === "function") {
1009
+ return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
1010
+ }
1011
+ return "light";
1012
+ }
1013
+ function getServerSnapshot() {
1014
+ return "light";
1015
+ }
1016
+ function useColorScheme(options) {
1017
+ const override = options?.override;
1018
+ const attribute = options?.attribute;
1019
+ const subscribe = (0, import_react3.useMemo)(() => {
1020
+ return (callback) => {
1021
+ if (typeof window === "undefined" || typeof document === "undefined") {
1022
+ return () => {
1023
+ };
1024
+ }
1025
+ if (attribute) {
1026
+ const observer = new MutationObserver(() => {
1027
+ callback();
1028
+ });
1029
+ observer.observe(document.documentElement, {
1030
+ attributes: true,
1031
+ attributeFilter: [attribute]
1032
+ });
1033
+ return () => observer.disconnect();
1034
+ }
1035
+ if (typeof window.matchMedia === "function") {
1036
+ const mql = window.matchMedia("(prefers-color-scheme: dark)");
1037
+ const handler = () => callback();
1038
+ mql.addEventListener("change", handler);
1039
+ return () => mql.removeEventListener("change", handler);
1040
+ }
1041
+ return () => {
1042
+ };
1043
+ };
1044
+ }, [attribute]);
1045
+ const detected = (0, import_react3.useSyncExternalStore)(
1046
+ subscribe,
1047
+ () => getSnapshot(attribute),
1048
+ getServerSnapshot
1049
+ );
1050
+ return override ?? detected;
1051
+ }
1052
+ function useResolvedColor(value, scheme) {
1053
+ const detectedScheme = useColorScheme();
1054
+ const activeScheme = scheme ?? detectedScheme;
1055
+ return (0, import_color3.resolveColor)(value, activeScheme);
1056
+ }
1057
+
1058
+ // src/color/index.ts
1059
+ __reExport(color_exports, require("@pixerate/editor/color"), module.exports);
1060
+ // Annotate the CommonJS export names for ESM import in node:
1061
+ 0 && (module.exports = {
1062
+ ColorPicker,
1063
+ DualColorPicker,
1064
+ useColorScheme,
1065
+ useResolvedColor,
1066
+ ...require("@pixerate/editor/color")
1067
+ });