@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
@@ -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 }) {
@@ -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
+ };
@@ -6,7 +6,7 @@ import {
6
6
  EffectsBrowser,
7
7
  useEffectDescription,
8
8
  useEffects
9
- } from "./chunk-5R67YSSD.js";
9
+ } from "./chunk-Q7LAFHGP.js";
10
10
  import {
11
11
  PresenceLayer,
12
12
  useAgentPlayback,