@pixerate/editor-react 0.94.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 (56) hide show
  1. package/README.md +3 -1
  2. package/dist/animation-editor/index.cjs +1240 -195
  3. package/dist/animation-editor/index.js +4 -2
  4. package/dist/canvas/index.cjs +1419 -372
  5. package/dist/canvas/index.js +9 -4
  6. package/dist/canvas/useMermaidDiagram.d.cts +7 -1
  7. package/dist/canvas/useMermaidDiagram.d.ts +7 -1
  8. package/dist/chunk-3I7FOSLF.js +988 -0
  9. package/dist/{chunk-OTGJEYHV.js → chunk-5LFQ2UQZ.js} +75 -68
  10. package/dist/{chunk-5R67YSSD.js → chunk-GLSOQNQR.js} +1 -1
  11. package/dist/{chunk-6YRSQW2V.js → chunk-IY6YOY5B.js} +1 -1
  12. package/dist/chunk-KIRIU53A.js +72 -0
  13. package/dist/{chunk-NNM633RN.js → chunk-R7MEGRPV.js} +23 -0
  14. package/dist/color/ColorPicker.d.cts +30 -0
  15. package/dist/color/ColorPicker.d.ts +30 -0
  16. package/dist/color/DualColorPicker.d.cts +29 -0
  17. package/dist/color/DualColorPicker.d.ts +29 -0
  18. package/dist/color/index.cjs +1067 -0
  19. package/dist/color/index.d.cts +7 -0
  20. package/dist/color/index.d.ts +7 -0
  21. package/dist/color/index.js +14 -0
  22. package/dist/color/useColorScheme.d.cts +16 -0
  23. package/dist/color/useColorScheme.d.ts +16 -0
  24. package/dist/effects/index.cjs +1169 -124
  25. package/dist/effects/index.js +4 -2
  26. package/dist/gradient/FillPicker.d.cts +27 -0
  27. package/dist/gradient/FillPicker.d.ts +27 -0
  28. package/dist/gradient/GradientEditor.d.cts +21 -0
  29. package/dist/gradient/GradientEditor.d.ts +21 -0
  30. package/dist/gradient/index.cjs +1601 -0
  31. package/dist/gradient/index.d.cts +6 -0
  32. package/dist/gradient/index.d.ts +6 -0
  33. package/dist/gradient/index.js +617 -0
  34. package/dist/gradient/useGradientController.d.cts +10 -0
  35. package/dist/gradient/useGradientController.d.ts +10 -0
  36. package/dist/image-editor/index.cjs +1742 -697
  37. package/dist/image-editor/index.js +5 -3
  38. package/dist/index.cjs +2181 -1115
  39. package/dist/index.js +9 -5
  40. package/dist/paint-editor/index.cjs +1233 -188
  41. package/dist/paint-editor/index.js +4 -2
  42. package/dist/parameters/fields.d.cts +1 -1
  43. package/dist/parameters/fields.d.ts +1 -1
  44. package/dist/parameters/index.cjs +1218 -173
  45. package/dist/parameters/index.js +3 -1
  46. package/dist/persistence/index.cjs +25 -4
  47. package/dist/persistence/index.d.cts +1 -0
  48. package/dist/persistence/index.d.ts +1 -0
  49. package/dist/persistence/index.js +5 -3
  50. package/dist/persistence/useEditorAutosave.d.cts +17 -0
  51. package/dist/persistence/useEditorAutosave.d.ts +17 -0
  52. package/dist/vector/index.cjs +1219 -174
  53. package/dist/vector/index.js +4 -2
  54. package/dist/video-editor/index.cjs +1230 -185
  55. package/dist/video-editor/index.js +4 -2
  56. package/package.json +29 -3
@@ -1,5 +1,9 @@
1
+ import {
2
+ ColorPicker
3
+ } from "./chunk-3I7FOSLF.js";
4
+
1
5
  // src/parameters/fields.tsx
2
- import { useRef } from "react";
6
+ import { useEffect, useRef, useState } from "react";
3
7
  import {
4
8
  choiceOptionLabel,
5
9
  formatParameterNumber,
@@ -169,48 +173,59 @@ function ParameterSelect({ field, value, onChange, disabled, id }) {
169
173
  );
170
174
  }
171
175
  function ParameterColor({ field, value, onChange, onGestureStart, onGestureEnd, disabled, id }) {
172
- const picking = useRef(false);
176
+ const [open, setOpen] = useState(false);
177
+ const containerRef = useRef(null);
178
+ const buttonRef = useRef(null);
179
+ const popoverRef = useRef(null);
173
180
  const alpha = !!field.alpha;
174
181
  const hex = normalizeHexColor(value, true) ?? "#000000ff";
175
182
  const rgb = hex.slice(0, 7);
176
- const a = hex.slice(7);
183
+ const shown = alpha ? hex : rgb;
177
184
  const off = disabled || field.readOnly;
178
- const start = () => {
179
- if (picking.current) return;
180
- picking.current = true;
181
- onGestureStart?.();
182
- };
183
- const end = () => {
184
- if (!picking.current) return;
185
- picking.current = false;
186
- onGestureEnd?.();
187
- };
188
- return /* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
185
+ const name = parameterLabel(field);
186
+ useEffect(() => {
187
+ if (!open) return;
188
+ const onPointerDown = (e) => {
189
+ if (containerRef.current && !containerRef.current.contains(e.target)) {
190
+ setOpen(false);
191
+ }
192
+ };
193
+ const onKeyDown = (e) => {
194
+ if (e.key === "Escape") {
195
+ e.stopPropagation();
196
+ setOpen(false);
197
+ buttonRef.current?.focus();
198
+ }
199
+ };
200
+ window.addEventListener("pointerdown", onPointerDown, true);
201
+ window.addEventListener("keydown", onKeyDown, true);
202
+ return () => {
203
+ window.removeEventListener("pointerdown", onPointerDown, true);
204
+ window.removeEventListener("keydown", onKeyDown, true);
205
+ };
206
+ }, [open]);
207
+ return /* @__PURE__ */ jsxs("div", { ref: containerRef, className: "relative space-y-1.5", children: [
189
208
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
190
- /* @__PURE__ */ 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: [
191
- /* @__PURE__ */ jsx("span", { className: "absolute inset-0", style: { background: alpha ? hex : rgb } }),
192
- /* @__PURE__ */ jsx(
193
- "input",
194
- {
195
- type: "color",
196
- "aria-label": parameterLabel(field),
197
- value: rgb,
198
- disabled: off,
199
- className: "absolute inset-0 h-full w-full cursor-pointer opacity-0 disabled:cursor-not-allowed",
200
- onChange: (e) => {
201
- start();
202
- onChange(alpha ? `${e.target.value}${a}` : e.target.value);
203
- },
204
- onBlur: end
205
- }
206
- )
207
- ] }),
209
+ /* @__PURE__ */ jsx(
210
+ "button",
211
+ {
212
+ ref: buttonRef,
213
+ type: "button",
214
+ "aria-label": name,
215
+ "aria-expanded": open,
216
+ "aria-haspopup": "dialog",
217
+ disabled: off,
218
+ onClick: () => setOpen((prev) => !prev),
219
+ 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",
220
+ children: /* @__PURE__ */ jsx("span", { className: "absolute inset-0", style: { background: shown } })
221
+ }
222
+ ),
208
223
  /* @__PURE__ */ jsx(
209
224
  ParameterCommitInput,
210
225
  {
211
226
  id,
212
- "aria-label": `${parameterLabel(field)} hex`,
213
- value: alpha ? hex : rgb,
227
+ "aria-label": `${name} hex`,
228
+ value: shown,
214
229
  disabled: off,
215
230
  spellCheck: false,
216
231
  className: `${parameterInputClass} font-mono`,
@@ -221,42 +236,34 @@ function ParameterColor({ field, value, onChange, onGestureStart, onGestureEnd,
221
236
  }
222
237
  )
223
238
  ] }),
224
- alpha && /* @__PURE__ */ jsx(
225
- "input",
239
+ open && /* @__PURE__ */ jsx(
240
+ "div",
226
241
  {
227
- type: "range",
228
- "aria-label": `${parameterLabel(field)} opacity`,
229
- min: 0,
230
- max: 255,
231
- step: 1,
232
- value: parseInt(a, 16),
233
- disabled: off,
234
- className: rangeClass,
235
- onPointerDown: start,
236
- onPointerUp: end,
237
- onPointerCancel: end,
238
- onBlur: end,
239
- onChange: (e) => onChange(`${rgb}${Number(e.target.value).toString(16).padStart(2, "0")}`)
240
- }
241
- ),
242
- field.swatches && field.swatches.length > 0 && /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1", children: field.swatches.map((s) => {
243
- const swatch = normalizeHexColor(s, alpha);
244
- if (!swatch) return null;
245
- return /* @__PURE__ */ jsx(
246
- "button",
247
- {
248
- type: "button",
249
- title: swatch,
250
- "aria-label": `${parameterLabel(field)} ${swatch}`,
251
- "aria-pressed": swatch === (alpha ? hex : rgb),
252
- disabled: off,
253
- onClick: () => onChange(swatch),
254
- className: "h-5 w-5 rounded border border-input aria-pressed:ring-1 aria-pressed:ring-primary",
255
- style: { background: swatch }
242
+ ref: popoverRef,
243
+ role: "dialog",
244
+ "aria-label": name,
245
+ tabIndex: -1,
246
+ onBlur: (e) => {
247
+ if (popoverRef.current && !popoverRef.current.contains(e.relatedTarget)) {
248
+ setOpen(false);
249
+ }
256
250
  },
257
- s
258
- );
259
- }) })
251
+ 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",
252
+ style: { background: "var(--popover, var(--background, #fff))" },
253
+ children: /* @__PURE__ */ jsx(
254
+ ColorPicker,
255
+ {
256
+ value: shown,
257
+ alpha,
258
+ swatches: field.swatches,
259
+ disabled: off,
260
+ onChange,
261
+ onGestureStart,
262
+ onGestureEnd
263
+ }
264
+ )
265
+ }
266
+ )
260
267
  ] });
261
268
  }
262
269
  function ParameterVector({ field, value, onChange, disabled, id }) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ParameterFieldControl
3
- } from "./chunk-OTGJEYHV.js";
3
+ } from "./chunk-5LFQ2UQZ.js";
4
4
 
5
5
  // src/effects/useEffects.ts
6
6
  import { useEffect, useState } from "react";
@@ -6,7 +6,7 @@ import {
6
6
  EffectsBrowser,
7
7
  useEffectDescription,
8
8
  useEffects
9
- } from "./chunk-5R67YSSD.js";
9
+ } from "./chunk-GLSOQNQR.js";
10
10
  import {
11
11
  PresenceLayer,
12
12
  useAgentPlayback,
@@ -0,0 +1,72 @@
1
+ // src/color/useColorScheme.ts
2
+ import { useSyncExternalStore, useMemo } from "react";
3
+ import { resolveColor } from "@pixerate/editor/color";
4
+ function getSnapshot(attribute) {
5
+ if (typeof window === "undefined" || typeof document === "undefined") {
6
+ return "light";
7
+ }
8
+ if (attribute) {
9
+ const el = document.documentElement;
10
+ if (attribute === "class") {
11
+ return el.classList.contains("dark") ? "dark" : "light";
12
+ }
13
+ const val = el.getAttribute(attribute);
14
+ return val === "dark" ? "dark" : "light";
15
+ }
16
+ if (typeof window.matchMedia === "function") {
17
+ return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
18
+ }
19
+ return "light";
20
+ }
21
+ function getServerSnapshot() {
22
+ return "light";
23
+ }
24
+ function useColorScheme(options) {
25
+ const override = options?.override;
26
+ const attribute = options?.attribute;
27
+ const subscribe = useMemo(() => {
28
+ return (callback) => {
29
+ if (typeof window === "undefined" || typeof document === "undefined") {
30
+ return () => {
31
+ };
32
+ }
33
+ if (attribute) {
34
+ const observer = new MutationObserver(() => {
35
+ callback();
36
+ });
37
+ observer.observe(document.documentElement, {
38
+ attributes: true,
39
+ attributeFilter: [attribute]
40
+ });
41
+ return () => observer.disconnect();
42
+ }
43
+ if (typeof window.matchMedia === "function") {
44
+ const mql = window.matchMedia("(prefers-color-scheme: dark)");
45
+ const handler = () => callback();
46
+ mql.addEventListener("change", handler);
47
+ return () => mql.removeEventListener("change", handler);
48
+ }
49
+ return () => {
50
+ };
51
+ };
52
+ }, [attribute]);
53
+ const detected = useSyncExternalStore(
54
+ subscribe,
55
+ () => getSnapshot(attribute),
56
+ getServerSnapshot
57
+ );
58
+ return override ?? detected;
59
+ }
60
+ function useResolvedColor(value, scheme) {
61
+ const detectedScheme = useColorScheme();
62
+ const activeScheme = scheme ?? detectedScheme;
63
+ return resolveColor(value, activeScheme);
64
+ }
65
+
66
+ // src/color/index.ts
67
+ export * from "@pixerate/editor/color";
68
+
69
+ export {
70
+ useColorScheme,
71
+ useResolvedColor
72
+ };
@@ -105,6 +105,28 @@ function useAutosave(options) {
105
105
  return { status, recovery, pendingRecovery, restore, discard, flushNow, markClean, notifyChange, controller };
106
106
  }
107
107
 
108
+ // src/persistence/useEditorAutosave.ts
109
+ import { useCallback as useCallback2 } from "react";
110
+ import {
111
+ parseEditorDocument,
112
+ toEditorDocumentFile
113
+ } from "@pixerate/editor/persistence";
114
+ function useEditorAutosave(doc, options) {
115
+ const autosave = useAutosave({
116
+ ...options,
117
+ key: options.key ?? doc.kind,
118
+ getSnapshot: () => toEditorDocumentFile(doc),
119
+ deserialize: (text) => parseEditorDocument(text, { kind: doc.kind }),
120
+ history: doc
121
+ });
122
+ const take = autosave.restore;
123
+ const restore = useCallback2(() => {
124
+ const snapshot = take();
125
+ return snapshot ? doc.loadDocument(snapshot, { history: "reset" }) : void 0;
126
+ }, [take, doc]);
127
+ return { ...autosave, restore };
128
+ }
129
+
108
130
  // src/persistence/RecoveryPrompt.tsx
109
131
  import { formatRecoveryMessage } from "@pixerate/editor/persistence";
110
132
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -162,5 +184,6 @@ var RecoveryPrompt = ({
162
184
 
163
185
  export {
164
186
  useAutosave,
187
+ useEditorAutosave,
165
188
  RecoveryPrompt
166
189
  };
@@ -0,0 +1,30 @@
1
+ import React from "react";
2
+ export interface ColorPickerProps {
3
+ /** The current colour value (any valid CSS colour string or hex). */
4
+ value: string;
5
+ /** Called when the colour value changes. */
6
+ onChange: (value: string) => void;
7
+ /** Called when a continuous pointer drag or keyboard interaction starts. */
8
+ onGestureStart?: () => void;
9
+ /** Called when a continuous pointer drag or keyboard interaction ends. */
10
+ onGestureEnd?: () => void;
11
+ /** Whether the alpha channel slider is shown and alpha hex values emitted. Default: false. */
12
+ alpha?: boolean;
13
+ /** Palette swatches shown beneath the sliders. */
14
+ swatches?: readonly string[];
15
+ /** Controlled recent colours. If omitted, internal recents persisted in localStorage are used. */
16
+ recent?: readonly string[];
17
+ /** Called when the list of recent colours changes. */
18
+ onRecentChange?: (recent: readonly string[]) => void;
19
+ /** If provided, renders live WCAG contrast ratio badges against this background colour. */
20
+ contrastAgainst?: string;
21
+ /** Whether the picker is disabled. */
22
+ disabled?: boolean;
23
+ /** Additional CSS class names for the outer container. */
24
+ className?: string;
25
+ /** Optional DOM id for the container. */
26
+ id?: string;
27
+ /** Accessible label for the colour picker group. */
28
+ "aria-label"?: string;
29
+ }
30
+ export declare const ColorPicker: React.FC<ColorPickerProps>;
@@ -0,0 +1,30 @@
1
+ import React from "react";
2
+ export interface ColorPickerProps {
3
+ /** The current colour value (any valid CSS colour string or hex). */
4
+ value: string;
5
+ /** Called when the colour value changes. */
6
+ onChange: (value: string) => void;
7
+ /** Called when a continuous pointer drag or keyboard interaction starts. */
8
+ onGestureStart?: () => void;
9
+ /** Called when a continuous pointer drag or keyboard interaction ends. */
10
+ onGestureEnd?: () => void;
11
+ /** Whether the alpha channel slider is shown and alpha hex values emitted. Default: false. */
12
+ alpha?: boolean;
13
+ /** Palette swatches shown beneath the sliders. */
14
+ swatches?: readonly string[];
15
+ /** Controlled recent colours. If omitted, internal recents persisted in localStorage are used. */
16
+ recent?: readonly string[];
17
+ /** Called when the list of recent colours changes. */
18
+ onRecentChange?: (recent: readonly string[]) => void;
19
+ /** If provided, renders live WCAG contrast ratio badges against this background colour. */
20
+ contrastAgainst?: string;
21
+ /** Whether the picker is disabled. */
22
+ disabled?: boolean;
23
+ /** Additional CSS class names for the outer container. */
24
+ className?: string;
25
+ /** Optional DOM id for the container. */
26
+ id?: string;
27
+ /** Accessible label for the colour picker group. */
28
+ "aria-label"?: string;
29
+ }
30
+ export declare const ColorPicker: React.FC<ColorPickerProps>;
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+ import { type ColorScheme, type ColorValue, type DualColor } from '@pixerate/editor/color';
3
+ export interface DualColorPickerProps {
4
+ /** Active color value: plain CSS colour, light-dark() string, or { light, dark } object. */
5
+ value: ColorValue;
6
+ /** Called when either half changes. Always receives normalised DualColor with hex values. */
7
+ onChange: (value: DualColor) => void;
8
+ /** Called when a continuous dragging gesture begins in the inner picker or during derivation. */
9
+ onGestureStart?: () => void;
10
+ /** Called when a continuous dragging gesture ends in the inner picker or during derivation. */
11
+ onGestureEnd?: () => void;
12
+ /** Which scheme half is currently selected for editing ('light' or 'dark'). */
13
+ scheme?: ColorScheme;
14
+ /** Called when the selected scheme half changes. */
15
+ onSchemeChange?: (scheme: ColorScheme) => void;
16
+ /** Background surfaces for light and dark previews. Default { light: '#ffffff', dark: '#0b0b0f' }. */
17
+ surfaces?: DualColor;
18
+ /** Contrast reference target to measure against in both schemes. */
19
+ contrastAgainst?: ColorValue;
20
+ /** Whether alpha transparency is enabled. Default false. */
21
+ alpha?: boolean;
22
+ /** Swatch palette colours. */
23
+ swatches?: string[];
24
+ /** Whether interactions are disabled. Default false. */
25
+ disabled?: boolean;
26
+ /** Additional CSS class name. */
27
+ className?: string;
28
+ }
29
+ export declare function DualColorPicker({ value, onChange, onGestureStart, onGestureEnd, scheme: controlledScheme, onSchemeChange, surfaces, contrastAgainst, alpha, swatches, disabled, className }: DualColorPickerProps): React.ReactElement;
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+ import { type ColorScheme, type ColorValue, type DualColor } from '@pixerate/editor/color';
3
+ export interface DualColorPickerProps {
4
+ /** Active color value: plain CSS colour, light-dark() string, or { light, dark } object. */
5
+ value: ColorValue;
6
+ /** Called when either half changes. Always receives normalised DualColor with hex values. */
7
+ onChange: (value: DualColor) => void;
8
+ /** Called when a continuous dragging gesture begins in the inner picker or during derivation. */
9
+ onGestureStart?: () => void;
10
+ /** Called when a continuous dragging gesture ends in the inner picker or during derivation. */
11
+ onGestureEnd?: () => void;
12
+ /** Which scheme half is currently selected for editing ('light' or 'dark'). */
13
+ scheme?: ColorScheme;
14
+ /** Called when the selected scheme half changes. */
15
+ onSchemeChange?: (scheme: ColorScheme) => void;
16
+ /** Background surfaces for light and dark previews. Default { light: '#ffffff', dark: '#0b0b0f' }. */
17
+ surfaces?: DualColor;
18
+ /** Contrast reference target to measure against in both schemes. */
19
+ contrastAgainst?: ColorValue;
20
+ /** Whether alpha transparency is enabled. Default false. */
21
+ alpha?: boolean;
22
+ /** Swatch palette colours. */
23
+ swatches?: string[];
24
+ /** Whether interactions are disabled. Default false. */
25
+ disabled?: boolean;
26
+ /** Additional CSS class name. */
27
+ className?: string;
28
+ }
29
+ export declare function DualColorPicker({ value, onChange, onGestureStart, onGestureEnd, scheme: controlledScheme, onSchemeChange, surfaces, contrastAgainst, alpha, swatches, disabled, className }: DualColorPickerProps): React.ReactElement;