@pixerate/editor-react 0.96.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.
@@ -2911,13 +2911,24 @@ function ParameterFieldControl({ field, value, onChange, resolveFile, ...rest })
2911
2911
 
2912
2912
  // src/effects/EffectParameters.tsx
2913
2913
  var import_jsx_runtime14 = require("react/jsx-runtime");
2914
- function EffectParameters({ description, values, onChange, onReset, keyframed, onPreset, disabled = false, className = "" }) {
2914
+ function EffectParameters({
2915
+ description,
2916
+ values,
2917
+ onChange,
2918
+ onReset,
2919
+ keyframed,
2920
+ onPreset,
2921
+ onPresetName,
2922
+ renderControlAddon,
2923
+ disabled = false,
2924
+ className = ""
2925
+ }) {
2915
2926
  const fields = (0, import_react17.useMemo)(() => (0, import_effects3.effectParameterFields)(description), [description]);
2916
2927
  const idBase = (0, import_react17.useId)();
2917
2928
  const gesture = import_react17.default.useRef(null);
2918
2929
  const count = import_react17.default.useRef(0);
2919
2930
  return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: `space-y-2 ${className}`, "data-effect-parameters": description.id, children: [
2920
- onPreset && description.presets.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
2931
+ (onPreset || onPresetName) && description.presets.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
2921
2932
  "select",
2922
2933
  {
2923
2934
  className: "w-full rounded border border-border bg-transparent px-1 py-0.5 text-xs",
@@ -2925,8 +2936,14 @@ function EffectParameters({ description, values, onChange, onReset, keyframed, o
2925
2936
  value: "",
2926
2937
  disabled,
2927
2938
  onChange: (e) => {
2928
- const preset = description.presets.find((p) => p.name === e.currentTarget.value);
2929
- if (preset) onPreset({ ...description.defaults, ...preset.values });
2939
+ const name = e.currentTarget.value;
2940
+ if (!name) return;
2941
+ if (onPresetName) {
2942
+ onPresetName(name);
2943
+ } else if (onPreset) {
2944
+ const preset = description.presets.find((p) => p.name === name);
2945
+ if (preset) onPreset({ ...description.defaults, ...preset.values });
2946
+ }
2930
2947
  },
2931
2948
  children: [
2932
2949
  /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("option", { value: "", children: "Presets\u2026" }),
@@ -2944,6 +2961,7 @@ function EffectParameters({ description, values, onChange, onReset, keyframed, o
2944
2961
  /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "flex items-center gap-1.5", children: [
2945
2962
  /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("label", { htmlFor: inputId, className: "min-w-0 flex-1 truncate text-xs font-medium", title: field.description, children: label }),
2946
2963
  keyed && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "text-[10px] text-muted-foreground", children: "keyframed" }),
2964
+ renderControlAddon?.(field.id),
2947
2965
  onReset && changed && !disabled && /* @__PURE__ */ (0, import_jsx_runtime14.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" })
2948
2966
  ] }),
2949
2967
  /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
@@ -18,9 +18,9 @@ import {
18
18
  useImageEditor,
19
19
  useImageEffectsTools,
20
20
  useImageHistogram
21
- } from "../chunk-IY6YOY5B.js";
21
+ } from "../chunk-NC4RLZTK.js";
22
22
  import "../chunk-AJCWF6SN.js";
23
- import "../chunk-GLSOQNQR.js";
23
+ import "../chunk-Q7LAFHGP.js";
24
24
  import "../chunk-5LFQ2UQZ.js";
25
25
  import "../chunk-KIRIU53A.js";
26
26
  import "../chunk-3I7FOSLF.js";
package/dist/index.cjs CHANGED
@@ -6600,13 +6600,24 @@ function ParameterFieldControl({ field, value, onChange, resolveFile, ...rest })
6600
6600
 
6601
6601
  // src/effects/EffectParameters.tsx
6602
6602
  var import_jsx_runtime30 = require("react/jsx-runtime");
6603
- function EffectParameters({ description, values, onChange, onReset, keyframed, onPreset, disabled = false, className = "" }) {
6603
+ function EffectParameters({
6604
+ description,
6605
+ values,
6606
+ onChange,
6607
+ onReset,
6608
+ keyframed,
6609
+ onPreset,
6610
+ onPresetName,
6611
+ renderControlAddon,
6612
+ disabled = false,
6613
+ className = ""
6614
+ }) {
6604
6615
  const fields = (0, import_react52.useMemo)(() => (0, import_effects3.effectParameterFields)(description), [description]);
6605
6616
  const idBase = (0, import_react52.useId)();
6606
6617
  const gesture = import_react52.default.useRef(null);
6607
6618
  const count = import_react52.default.useRef(0);
6608
6619
  return /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)("div", { className: `space-y-2 ${className}`, "data-effect-parameters": description.id, children: [
6609
- onPreset && description.presets.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(
6620
+ (onPreset || onPresetName) && description.presets.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(
6610
6621
  "select",
6611
6622
  {
6612
6623
  className: "w-full rounded border border-border bg-transparent px-1 py-0.5 text-xs",
@@ -6614,8 +6625,14 @@ function EffectParameters({ description, values, onChange, onReset, keyframed, o
6614
6625
  value: "",
6615
6626
  disabled,
6616
6627
  onChange: (e) => {
6617
- const preset = description.presets.find((p) => p.name === e.currentTarget.value);
6618
- if (preset) onPreset({ ...description.defaults, ...preset.values });
6628
+ const name = e.currentTarget.value;
6629
+ if (!name) return;
6630
+ if (onPresetName) {
6631
+ onPresetName(name);
6632
+ } else if (onPreset) {
6633
+ const preset = description.presets.find((p) => p.name === name);
6634
+ if (preset) onPreset({ ...description.defaults, ...preset.values });
6635
+ }
6619
6636
  },
6620
6637
  children: [
6621
6638
  /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("option", { value: "", children: "Presets\u2026" }),
@@ -6633,6 +6650,7 @@ function EffectParameters({ description, values, onChange, onReset, keyframed, o
6633
6650
  /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)("div", { className: "flex items-center gap-1.5", children: [
6634
6651
  /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("label", { htmlFor: inputId, className: "min-w-0 flex-1 truncate text-xs font-medium", title: field.description, children: label }),
6635
6652
  keyed && /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("span", { className: "text-[10px] text-muted-foreground", children: "keyframed" }),
6653
+ renderControlAddon?.(field.id),
6636
6654
  onReset && changed && !disabled && /* @__PURE__ */ (0, import_jsx_runtime30.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" })
6637
6655
  ] }),
6638
6656
  /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
package/dist/index.js CHANGED
@@ -42,9 +42,9 @@ import {
42
42
  useImageEditor,
43
43
  useImageEffectsTools,
44
44
  useImageHistogram
45
- } from "./chunk-IY6YOY5B.js";
45
+ } from "./chunk-NC4RLZTK.js";
46
46
  import "./chunk-AJCWF6SN.js";
47
- import "./chunk-GLSOQNQR.js";
47
+ import "./chunk-Q7LAFHGP.js";
48
48
  import "./chunk-5LFQ2UQZ.js";
49
49
  import "./chunk-KIRIU53A.js";
50
50
  import "./chunk-3I7FOSLF.js";
@@ -2972,13 +2972,24 @@ function ParameterFieldControl({ field, value, onChange, resolveFile, ...rest })
2972
2972
 
2973
2973
  // src/effects/EffectParameters.tsx
2974
2974
  var import_jsx_runtime19 = require("react/jsx-runtime");
2975
- function EffectParameters({ description, values, onChange, onReset, keyframed, onPreset, disabled = false, className = "" }) {
2975
+ function EffectParameters({
2976
+ description,
2977
+ values,
2978
+ onChange,
2979
+ onReset,
2980
+ keyframed,
2981
+ onPreset,
2982
+ onPresetName,
2983
+ renderControlAddon,
2984
+ disabled = false,
2985
+ className = ""
2986
+ }) {
2976
2987
  const fields = (0, import_react21.useMemo)(() => (0, import_effects3.effectParameterFields)(description), [description]);
2977
2988
  const idBase = (0, import_react21.useId)();
2978
2989
  const gesture = import_react21.default.useRef(null);
2979
2990
  const count = import_react21.default.useRef(0);
2980
2991
  return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: `space-y-2 ${className}`, "data-effect-parameters": description.id, children: [
2981
- onPreset && description.presets.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
2992
+ (onPreset || onPresetName) && description.presets.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
2982
2993
  "select",
2983
2994
  {
2984
2995
  className: "w-full rounded border border-border bg-transparent px-1 py-0.5 text-xs",
@@ -2986,8 +2997,14 @@ function EffectParameters({ description, values, onChange, onReset, keyframed, o
2986
2997
  value: "",
2987
2998
  disabled,
2988
2999
  onChange: (e) => {
2989
- const preset = description.presets.find((p) => p.name === e.currentTarget.value);
2990
- if (preset) onPreset({ ...description.defaults, ...preset.values });
3000
+ const name = e.currentTarget.value;
3001
+ if (!name) return;
3002
+ if (onPresetName) {
3003
+ onPresetName(name);
3004
+ } else if (onPreset) {
3005
+ const preset = description.presets.find((p) => p.name === name);
3006
+ if (preset) onPreset({ ...description.defaults, ...preset.values });
3007
+ }
2991
3008
  },
2992
3009
  children: [
2993
3010
  /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("option", { value: "", children: "Presets\u2026" }),
@@ -3005,6 +3022,7 @@ function EffectParameters({ description, values, onChange, onReset, keyframed, o
3005
3022
  /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex items-center gap-1.5", children: [
3006
3023
  /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("label", { htmlFor: inputId, className: "min-w-0 flex-1 truncate text-xs font-medium", title: field.description, children: label }),
3007
3024
  keyed && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "text-[10px] text-muted-foreground", children: "keyframed" }),
3025
+ renderControlAddon?.(field.id),
3008
3026
  onReset && changed && !disabled && /* @__PURE__ */ (0, import_jsx_runtime19.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" })
3009
3027
  ] }),
3010
3028
  /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
@@ -5,7 +5,7 @@ import {
5
5
  EffectParameters,
6
6
  EffectsBrowser,
7
7
  useEffectDescription
8
- } from "../chunk-GLSOQNQR.js";
8
+ } from "../chunk-Q7LAFHGP.js";
9
9
  import "../chunk-5LFQ2UQZ.js";
10
10
  import "../chunk-KIRIU53A.js";
11
11
  import "../chunk-3I7FOSLF.js";
@@ -4654,13 +4654,24 @@ function ParameterFieldControl({ field, value, onChange, resolveFile, ...rest })
4654
4654
 
4655
4655
  // src/effects/EffectParameters.tsx
4656
4656
  var import_jsx_runtime27 = require("react/jsx-runtime");
4657
- function EffectParameters({ description, values, onChange, onReset, keyframed, onPreset, disabled = false, className = "" }) {
4657
+ function EffectParameters({
4658
+ description,
4659
+ values,
4660
+ onChange,
4661
+ onReset,
4662
+ keyframed,
4663
+ onPreset,
4664
+ onPresetName,
4665
+ renderControlAddon,
4666
+ disabled = false,
4667
+ className = ""
4668
+ }) {
4658
4669
  const fields = (0, import_react22.useMemo)(() => (0, import_effects3.effectParameterFields)(description), [description]);
4659
4670
  const idBase = (0, import_react22.useId)();
4660
4671
  const gesture = import_react22.default.useRef(null);
4661
4672
  const count = import_react22.default.useRef(0);
4662
4673
  return /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: `space-y-2 ${className}`, "data-effect-parameters": description.id, children: [
4663
- onPreset && description.presets.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(
4674
+ (onPreset || onPresetName) && description.presets.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(
4664
4675
  "select",
4665
4676
  {
4666
4677
  className: "w-full rounded border border-border bg-transparent px-1 py-0.5 text-xs",
@@ -4668,8 +4679,14 @@ function EffectParameters({ description, values, onChange, onReset, keyframed, o
4668
4679
  value: "",
4669
4680
  disabled,
4670
4681
  onChange: (e) => {
4671
- const preset = description.presets.find((p) => p.name === e.currentTarget.value);
4672
- if (preset) onPreset({ ...description.defaults, ...preset.values });
4682
+ const name = e.currentTarget.value;
4683
+ if (!name) return;
4684
+ if (onPresetName) {
4685
+ onPresetName(name);
4686
+ } else if (onPreset) {
4687
+ const preset = description.presets.find((p) => p.name === name);
4688
+ if (preset) onPreset({ ...description.defaults, ...preset.values });
4689
+ }
4673
4690
  },
4674
4691
  children: [
4675
4692
  /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("option", { value: "", children: "Presets\u2026" }),
@@ -4687,6 +4704,7 @@ function EffectParameters({ description, values, onChange, onReset, keyframed, o
4687
4704
  /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "flex items-center gap-1.5", children: [
4688
4705
  /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("label", { htmlFor: inputId, className: "min-w-0 flex-1 truncate text-xs font-medium", title: field.description, children: label }),
4689
4706
  keyed && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: "text-[10px] text-muted-foreground", children: "keyframed" }),
4707
+ renderControlAddon?.(field.id),
4690
4708
  onReset && changed && !disabled && /* @__PURE__ */ (0, import_jsx_runtime27.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" })
4691
4709
  ] }),
4692
4710
  /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
@@ -3,7 +3,7 @@ import {
3
3
  EffectsBrowser,
4
4
  useEffectDescription,
5
5
  useEffects
6
- } from "../chunk-GLSOQNQR.js";
6
+ } from "../chunk-Q7LAFHGP.js";
7
7
  import "../chunk-5LFQ2UQZ.js";
8
8
  import "../chunk-KIRIU53A.js";
9
9
  import "../chunk-3I7FOSLF.js";
@@ -2842,13 +2842,24 @@ function ParameterFieldControl({ field: field2, value, onChange, resolveFile, ..
2842
2842
 
2843
2843
  // src/effects/EffectParameters.tsx
2844
2844
  var import_jsx_runtime15 = require("react/jsx-runtime");
2845
- function EffectParameters({ description, values, onChange, onReset, keyframed, onPreset, disabled = false, className = "" }) {
2845
+ function EffectParameters({
2846
+ description,
2847
+ values,
2848
+ onChange,
2849
+ onReset,
2850
+ keyframed,
2851
+ onPreset,
2852
+ onPresetName,
2853
+ renderControlAddon,
2854
+ disabled = false,
2855
+ className = ""
2856
+ }) {
2846
2857
  const fields = (0, import_react18.useMemo)(() => (0, import_effects3.effectParameterFields)(description), [description]);
2847
2858
  const idBase = (0, import_react18.useId)();
2848
2859
  const gesture = import_react18.default.useRef(null);
2849
2860
  const count = import_react18.default.useRef(0);
2850
2861
  return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: `space-y-2 ${className}`, "data-effect-parameters": description.id, children: [
2851
- onPreset && description.presets.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
2862
+ (onPreset || onPresetName) && description.presets.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
2852
2863
  "select",
2853
2864
  {
2854
2865
  className: "w-full rounded border border-border bg-transparent px-1 py-0.5 text-xs",
@@ -2856,8 +2867,14 @@ function EffectParameters({ description, values, onChange, onReset, keyframed, o
2856
2867
  value: "",
2857
2868
  disabled,
2858
2869
  onChange: (e) => {
2859
- const preset = description.presets.find((p) => p.name === e.currentTarget.value);
2860
- if (preset) onPreset({ ...description.defaults, ...preset.values });
2870
+ const name = e.currentTarget.value;
2871
+ if (!name) return;
2872
+ if (onPresetName) {
2873
+ onPresetName(name);
2874
+ } else if (onPreset) {
2875
+ const preset = description.presets.find((p) => p.name === name);
2876
+ if (preset) onPreset({ ...description.defaults, ...preset.values });
2877
+ }
2861
2878
  },
2862
2879
  children: [
2863
2880
  /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("option", { value: "", children: "Presets\u2026" }),
@@ -2875,6 +2892,7 @@ function EffectParameters({ description, values, onChange, onReset, keyframed, o
2875
2892
  /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: "flex items-center gap-1.5", children: [
2876
2893
  /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("label", { htmlFor: inputId, className: "min-w-0 flex-1 truncate text-xs font-medium", title: field2.description, children: label }),
2877
2894
  keyed && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "text-[10px] text-muted-foreground", children: "keyframed" }),
2895
+ renderControlAddon?.(field2.id),
2878
2896
  onReset && changed && !disabled && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("button", { type: "button", className: "rounded px-1 text-[11px] text-muted-foreground hover:text-foreground", "aria-label": `Reset ${label}`, onClick: () => onReset(field2.id), children: "\u21BA" })
2879
2897
  ] }),
2880
2898
  /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
@@ -3,7 +3,7 @@ import {
3
3
  EffectsBrowser,
4
4
  useEffectDescription,
5
5
  useEffects
6
- } from "../chunk-GLSOQNQR.js";
6
+ } from "../chunk-Q7LAFHGP.js";
7
7
  import "../chunk-5LFQ2UQZ.js";
8
8
  import "../chunk-KIRIU53A.js";
9
9
  import "../chunk-3I7FOSLF.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixerate/editor-react",
3
- "version": "0.96.0",
3
+ "version": "0.97.0",
4
4
  "description": "React bindings and prompt/rich-text components for @pixerate/editor",
5
5
  "author": "Pixerate",
6
6
  "license": "MIT",
@@ -245,7 +245,7 @@
245
245
  },
246
246
  "peerDependencies": {
247
247
  "@dagrejs/dagre": "^1.1.8",
248
- "@pixerate/editor": ">=0.147.0 <1.0.0-0",
248
+ "@pixerate/editor": ">=0.148.0 <1.0.0-0",
249
249
  "@tiptap/core": "^2.27.3",
250
250
  "@tiptap/pm": "^2.27.3",
251
251
  "@tiptap/react": "^2.27.3",
@@ -272,7 +272,7 @@
272
272
  "tsup": "^9.0.0",
273
273
  "typescript": "^5.7.3",
274
274
  "vitest": "^5.0.5",
275
- "@pixerate/editor": "0.147.0"
275
+ "@pixerate/editor": "0.148.0"
276
276
  },
277
277
  "scripts": {
278
278
  "build": "tsup && tsc -p tsconfig.build.json && node ../../scripts/finalize-declarations.mjs dist",
@@ -1,205 +0,0 @@
1
- import {
2
- ParameterFieldControl
3
- } from "./chunk-5LFQ2UQZ.js";
4
-
5
- // src/effects/useEffects.ts
6
- import { useEffect, useState } from "react";
7
- function useEffects(host, provider) {
8
- useEffect(() => {
9
- if (!host || !provider) return;
10
- return host.useEffects(provider);
11
- }, [host, provider]);
12
- }
13
- function useEffectDescription(provider, effect) {
14
- const [state, setState] = useState({ key: "", description: null, error: null });
15
- const key = provider && effect ? `${provider.id}:${effect}` : "";
16
- useEffect(() => {
17
- if (!provider || !effect) return;
18
- let live = true;
19
- Promise.resolve().then(() => provider.describe(effect)).then(
20
- (description) => live && setState({ key, description, error: null }),
21
- (e) => live && setState({ key, description: null, error: e instanceof Error ? e.message : String(e) })
22
- );
23
- return () => {
24
- live = false;
25
- };
26
- }, [provider, effect, key]);
27
- return state.key === key ? { description: state.description, error: state.error } : { description: null, error: null };
28
- }
29
-
30
- // src/effects/EffectThumbnail.tsx
31
- import { useEffect as useEffect2, useRef, useState as useState2 } from "react";
32
- import { renderEffectThumbnail } from "@pixerate/editor/effects";
33
- import { jsx } from "react/jsx-runtime";
34
- function EffectThumbnail({ provider, effect, width = 96, height = 54, className = "" }) {
35
- const ref = useRef(null);
36
- const [failed, setFailed] = useState2(effect.kind === "motion");
37
- useEffect2(() => {
38
- if (effect.kind === "motion") return;
39
- let live = true;
40
- renderEffectThumbnail(provider, effect, { width, height }).then(
41
- (pixels) => {
42
- const ctx = live ? ref.current?.getContext("2d") : null;
43
- if (!ctx || typeof ImageData === "undefined") return;
44
- ctx.putImageData(new ImageData(new Uint8ClampedArray(pixels.data), pixels.width, pixels.height), 0, 0);
45
- },
46
- () => live && setFailed(true)
47
- );
48
- return () => {
49
- live = false;
50
- };
51
- }, [provider, effect, width, height]);
52
- return /* @__PURE__ */ jsx(
53
- "div",
54
- {
55
- className: `relative overflow-hidden rounded border border-border bg-[repeating-conic-gradient(#8884_0_25%,transparent_0_50%)] bg-[length:12px_12px] ${className}`,
56
- style: { aspectRatio: `${width} / ${height}` },
57
- "data-effect-thumbnail": effect.id,
58
- children: failed ? /* @__PURE__ */ jsx("span", { className: "absolute inset-0 flex items-center justify-center text-[10px] text-muted-foreground", children: effect.kind === "motion" ? "Motion" : "No preview" }) : /* @__PURE__ */ jsx("canvas", { ref, width, height, className: "h-full w-full", "aria-hidden": "true" })
59
- }
60
- );
61
- }
62
-
63
- // src/effects/EffectsBrowser.tsx
64
- import { useEffect as useEffect3, useMemo, useState as useState3 } from "react";
65
- import { EFFECT_USE_LABELS } from "@pixerate/editor/effects";
66
- import { jsx as jsx2, jsxs } from "react/jsx-runtime";
67
- function EffectsBrowser({ provider, uses, kinds, onPick, thumbnails = true, title = "Effects", className = "" }) {
68
- const [all, setAll] = useState3([]);
69
- const [query, setQuery] = useState3("");
70
- const [category, setCategory] = useState3("");
71
- const [use, setUse] = useState3("");
72
- const [error, setError] = useState3(null);
73
- useEffect3(() => {
74
- if (!provider) return setAll([]);
75
- let live = true;
76
- Promise.resolve().then(() => provider.list()).then(
77
- (list) => live && (setAll(list), setError(null)),
78
- (e) => live && setError(e instanceof Error ? e.message : String(e))
79
- );
80
- return () => {
81
- live = false;
82
- };
83
- }, [provider]);
84
- const [found, setFound] = useState3([]);
85
- useEffect3(() => {
86
- if (!provider) return setFound([]);
87
- let live = true;
88
- Promise.resolve().then(() => provider.search(query, { ...category ? { category } : {}, ...use ? { use } : {} })).then((list) => live && setFound(list), () => live && setFound([]));
89
- return () => {
90
- live = false;
91
- };
92
- }, [provider, query, category, use]);
93
- const allowed = (e) => (!kinds || kinds.includes(e.kind)) && (uses ? e.kind !== "motion" || uses.includes("motion") : e.kind !== "motion") && (!uses || e.uses.some((u) => uses.includes(u)));
94
- const categories = useMemo(() => [...new Set(all.filter(allowed).map((e) => e.category))], [all, uses, kinds]);
95
- const shown = found.filter(allowed);
96
- if (!provider)
97
- return /* @__PURE__ */ jsx2("div", { className: `rounded-md border border-dashed border-border p-3 text-xs text-muted-foreground ${className}`, "data-effects-browser": "", "data-effects-unavailable": "", children: "No effects provider is registered, so effects cannot be added. Effects already in the document are kept." });
98
- return /* @__PURE__ */ jsxs("section", { className: `flex flex-col gap-2 ${className}`, "data-effects-browser": "", "aria-label": "Effects browser", children: [
99
- title && /* @__PURE__ */ jsx2("h3", { className: "text-xs font-semibold", children: title }),
100
- /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-1", children: [
101
- /* @__PURE__ */ jsx2(
102
- "input",
103
- {
104
- type: "search",
105
- className: "min-w-0 flex-1 rounded border border-border bg-transparent px-1.5 py-0.5 text-xs",
106
- placeholder: "Search effects",
107
- "aria-label": "Search effects",
108
- value: query,
109
- onChange: (e) => setQuery(e.currentTarget.value)
110
- }
111
- ),
112
- /* @__PURE__ */ jsxs("select", { className: "rounded border border-border bg-transparent px-1 py-0.5 text-xs", "aria-label": "Category", value: category, onChange: (e) => setCategory(e.currentTarget.value), children: [
113
- /* @__PURE__ */ jsx2("option", { value: "", children: "All categories" }),
114
- categories.map((c) => /* @__PURE__ */ jsx2("option", { value: c, children: c }, c))
115
- ] }),
116
- uses && uses.length > 1 && /* @__PURE__ */ jsxs("select", { className: "rounded border border-border bg-transparent px-1 py-0.5 text-xs", "aria-label": "Use", value: use, onChange: (e) => setUse(e.currentTarget.value), children: [
117
- /* @__PURE__ */ jsx2("option", { value: "", children: "Any use" }),
118
- uses.map((u) => /* @__PURE__ */ jsx2("option", { value: u, children: EFFECT_USE_LABELS[u] }, u))
119
- ] })
120
- ] }),
121
- error && /* @__PURE__ */ jsx2("p", { role: "alert", className: "text-[11px] text-destructive", children: error }),
122
- /* @__PURE__ */ jsx2("ul", { className: "grid max-h-96 grid-cols-[repeat(auto-fill,minmax(6.5rem,1fr))] gap-1.5 overflow-y-auto", role: "list", children: shown.map((e) => /* @__PURE__ */ jsx2("li", { children: /* @__PURE__ */ jsxs(
123
- "button",
124
- {
125
- type: "button",
126
- className: "flex w-full flex-col gap-1 rounded border border-transparent p-1 text-left hover:border-border focus-visible:border-border",
127
- title: e.description ?? e.name,
128
- "data-effect-id": e.id,
129
- onClick: () => onPick(e),
130
- children: [
131
- thumbnails && /* @__PURE__ */ jsx2(EffectThumbnail, { provider, effect: e }),
132
- /* @__PURE__ */ jsx2("span", { className: "truncate text-[11px] font-medium", children: e.name }),
133
- /* @__PURE__ */ jsx2("span", { className: "truncate text-[10px] text-muted-foreground", children: e.uses.map((u) => EFFECT_USE_LABELS[u]).join(" \xB7 ") })
134
- ]
135
- }
136
- ) }, e.id)) }),
137
- !shown.length && !error && /* @__PURE__ */ jsx2("p", { className: "text-[11px] text-muted-foreground", children: "No effects match." })
138
- ] });
139
- }
140
-
141
- // src/effects/EffectParameters.tsx
142
- import React3, { useId, useMemo as useMemo2 } from "react";
143
- import { effectFieldValue, effectParameterFields } from "@pixerate/editor/effects";
144
- import { parameterLabel, parameterValuesEqual } from "@pixerate/editor/parameters";
145
- import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
146
- function EffectParameters({ description, values, onChange, onReset, keyframed, onPreset, disabled = false, className = "" }) {
147
- const fields = useMemo2(() => effectParameterFields(description), [description]);
148
- const idBase = useId();
149
- const gesture = React3.useRef(null);
150
- const count = React3.useRef(0);
151
- return /* @__PURE__ */ jsxs2("div", { className: `space-y-2 ${className}`, "data-effect-parameters": description.id, children: [
152
- onPreset && description.presets.length > 0 && /* @__PURE__ */ jsxs2(
153
- "select",
154
- {
155
- className: "w-full rounded border border-border bg-transparent px-1 py-0.5 text-xs",
156
- "aria-label": `${description.name} presets`,
157
- value: "",
158
- disabled,
159
- onChange: (e) => {
160
- const preset = description.presets.find((p) => p.name === e.currentTarget.value);
161
- if (preset) onPreset({ ...description.defaults, ...preset.values });
162
- },
163
- children: [
164
- /* @__PURE__ */ jsx3("option", { value: "", children: "Presets\u2026" }),
165
- description.presets.map((p) => /* @__PURE__ */ jsx3("option", { value: p.name, children: p.name }, p.name))
166
- ]
167
- }
168
- ),
169
- fields.map((field) => {
170
- const label = parameterLabel(field);
171
- const inputId = `${idBase}-${field.id}`;
172
- const keyed = keyframed?.has(field.id) ?? false;
173
- const value = effectFieldValue(field, values[field.id]);
174
- const changed = !keyed && !parameterValuesEqual(value, field.default);
175
- return /* @__PURE__ */ jsxs2("div", { className: "space-y-1", "data-effect-control": field.id, children: [
176
- /* @__PURE__ */ jsxs2("div", { className: "flex items-center gap-1.5", children: [
177
- /* @__PURE__ */ jsx3("label", { htmlFor: inputId, className: "min-w-0 flex-1 truncate text-xs font-medium", title: field.description, children: label }),
178
- keyed && /* @__PURE__ */ jsx3("span", { className: "text-[10px] text-muted-foreground", children: "keyframed" }),
179
- onReset && changed && !disabled && /* @__PURE__ */ jsx3("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" })
180
- ] }),
181
- /* @__PURE__ */ jsx3(
182
- ParameterFieldControl,
183
- {
184
- field,
185
- value,
186
- id: inputId,
187
- disabled: disabled || keyed,
188
- onChange: (v) => onChange(field.id, v, gesture.current),
189
- onGestureStart: () => gesture.current = `${idBase}:${field.id}:${++count.current}`,
190
- onGestureEnd: () => gesture.current = null
191
- }
192
- )
193
- ] }, field.id);
194
- }),
195
- !fields.length && /* @__PURE__ */ jsx3("p", { className: "text-[11px] text-muted-foreground", children: "No controls." })
196
- ] });
197
- }
198
-
199
- export {
200
- useEffects,
201
- useEffectDescription,
202
- EffectThumbnail,
203
- EffectsBrowser,
204
- EffectParameters
205
- };