@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.
- package/README.md +2 -0
- package/dist/animation-editor/index.cjs +1261 -198
- package/dist/animation-editor/index.js +4 -2
- package/dist/canvas/index.cjs +1439 -376
- package/dist/canvas/index.js +4 -2
- package/dist/chunk-3I7FOSLF.js +988 -0
- package/dist/{chunk-OTGJEYHV.js → chunk-5LFQ2UQZ.js} +75 -68
- package/dist/chunk-KIRIU53A.js +72 -0
- package/dist/{chunk-6YRSQW2V.js → chunk-NC4RLZTK.js} +1 -1
- package/dist/chunk-Q7LAFHGP.js +655 -0
- package/dist/color/ColorPicker.d.cts +30 -0
- package/dist/color/ColorPicker.d.ts +30 -0
- package/dist/color/DualColorPicker.d.cts +29 -0
- package/dist/color/DualColorPicker.d.ts +29 -0
- package/dist/color/index.cjs +1067 -0
- package/dist/color/index.d.cts +7 -0
- package/dist/color/index.d.ts +7 -0
- package/dist/color/index.js +14 -0
- package/dist/color/useColorScheme.d.cts +16 -0
- package/dist/color/useColorScheme.d.ts +16 -0
- package/dist/effects/EffectAuthoringEditor.d.cts +22 -0
- package/dist/effects/EffectAuthoringEditor.d.ts +22 -0
- package/dist/effects/EffectParameters.d.cts +5 -1
- package/dist/effects/EffectParameters.d.ts +5 -1
- package/dist/effects/index.cjs +1624 -127
- package/dist/effects/index.d.cts +2 -0
- package/dist/effects/index.d.ts +2 -0
- package/dist/effects/index.js +8 -2
- package/dist/effects/useEffectAuthoring.d.cts +6 -0
- package/dist/effects/useEffectAuthoring.d.ts +6 -0
- package/dist/gradient/FillPicker.d.cts +27 -0
- package/dist/gradient/FillPicker.d.ts +27 -0
- package/dist/gradient/GradientEditor.d.cts +21 -0
- package/dist/gradient/GradientEditor.d.ts +21 -0
- package/dist/gradient/index.cjs +1601 -0
- package/dist/gradient/index.d.cts +6 -0
- package/dist/gradient/index.d.ts +6 -0
- package/dist/gradient/index.js +617 -0
- package/dist/gradient/useGradientController.d.cts +10 -0
- package/dist/gradient/useGradientController.d.ts +10 -0
- package/dist/image-editor/index.cjs +1763 -700
- package/dist/image-editor/index.js +5 -3
- package/dist/index.cjs +2181 -1118
- package/dist/index.js +5 -3
- package/dist/paint-editor/index.cjs +1254 -191
- package/dist/paint-editor/index.js +4 -2
- package/dist/parameters/fields.d.cts +1 -1
- package/dist/parameters/fields.d.ts +1 -1
- package/dist/parameters/index.cjs +1218 -173
- package/dist/parameters/index.js +3 -1
- package/dist/vector/index.cjs +1240 -177
- package/dist/vector/index.js +4 -2
- package/dist/video-editor/index.cjs +1251 -188
- package/dist/video-editor/index.js +4 -2
- package/package.json +29 -3
- 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
|
|
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
|
|
183
|
+
const shown = alpha ? hex : rgb;
|
|
177
184
|
const off = disabled || field.readOnly;
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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__ */
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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": `${
|
|
213
|
-
value:
|
|
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
|
-
|
|
225
|
-
"
|
|
239
|
+
open && /* @__PURE__ */ jsx(
|
|
240
|
+
"div",
|
|
226
241
|
{
|
|
227
|
-
|
|
228
|
-
"
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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
|
-
|
|
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
|
+
};
|