@pixerate/editor-react 0.112.0 → 0.113.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.
@@ -1695,6 +1695,7 @@ function EffectAuthoringEditor({
1695
1695
  const pendingRef = (0, import_react10.useRef)(false);
1696
1696
  const timeRef = (0, import_react10.useRef)(0);
1697
1697
  const inputsRef = (0, import_react10.useRef)({});
1698
+ const [previewError, setPreviewError] = (0, import_react10.useState)(null);
1698
1699
  const [savingPreset, setSavingPreset] = (0, import_react10.useState)(false);
1699
1700
  const [presetName, setPresetName] = (0, import_react10.useState)("");
1700
1701
  const textareaRef = (0, import_react10.useRef)(null);
@@ -1702,6 +1703,9 @@ function EffectAuthoringEditor({
1702
1703
  const [sourceCode, setSourceCode] = (0, import_react10.useState)("");
1703
1704
  const sourceDebounceRef = (0, import_react10.useRef)(null);
1704
1705
  (0, import_react10.useEffect)(() => {
1706
+ const canvas = canvasRef.current;
1707
+ canvas?.getContext("2d")?.clearRect(0, 0, canvas.width, canvas.height);
1708
+ setPreviewError(null);
1705
1709
  if (!session) {
1706
1710
  if (rendererRef.current) {
1707
1711
  rendererRef.current.dispose();
@@ -1719,6 +1723,8 @@ function EffectAuthoringEditor({
1719
1723
  createdRenderer = renderer;
1720
1724
  rendererRef.current = renderer;
1721
1725
  setRendererReady((c) => c + 1);
1726
+ }).catch((e) => {
1727
+ if (live) setPreviewError(session.getState().previewError || (e instanceof Error ? e.message : String(e)));
1722
1728
  });
1723
1729
  return () => {
1724
1730
  live = false;
@@ -1747,7 +1753,13 @@ function EffectAuthoringEditor({
1747
1753
  if (ctx && typeof ImageData !== "undefined") {
1748
1754
  ctx.putImageData(new ImageData(new Uint8ClampedArray(pixels.data), pixels.width, pixels.height), 0, 0);
1749
1755
  }
1750
- } catch {
1756
+ if (rendererRef.current === renderer) setPreviewError(null);
1757
+ } catch (e) {
1758
+ if (rendererRef.current === renderer) {
1759
+ const canvas = canvasRef.current;
1760
+ canvas?.getContext("2d")?.clearRect(0, 0, canvas.width, canvas.height);
1761
+ setPreviewError(e instanceof Error ? e.message : String(e));
1762
+ }
1751
1763
  }
1752
1764
  } while (pendingRef.current);
1753
1765
  } finally {
@@ -1894,16 +1906,19 @@ function EffectAuthoringEditor({
1894
1906
  /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "grid grid-cols-1 gap-4 lg:grid-cols-2", children: [
1895
1907
  /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "space-y-2", children: [
1896
1908
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: "Preview" }),
1897
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "relative flex aspect-video w-full items-center justify-center overflow-hidden rounded border border-border bg-black", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1898
- "canvas",
1899
- {
1900
- ref: canvasRef,
1901
- width: previewSize.width,
1902
- height: previewSize.height,
1903
- className: "h-full w-full object-contain",
1904
- "aria-label": "Effect preview canvas"
1905
- }
1906
- ) }),
1909
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "relative flex aspect-video w-full items-center justify-center overflow-hidden rounded border border-border bg-black", children: [
1910
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1911
+ "canvas",
1912
+ {
1913
+ ref: canvasRef,
1914
+ width: previewSize.width,
1915
+ height: previewSize.height,
1916
+ className: "h-full w-full object-contain",
1917
+ "aria-label": "Effect preview canvas"
1918
+ }
1919
+ ),
1920
+ previewError && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "absolute inset-0 flex items-center justify-center p-4 text-center text-xs text-white/80", role: "status", "data-effect-preview-error": true, children: previewError })
1921
+ ] }),
1907
1922
  state.issues.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "space-y-1 rounded border border-destructive/20 bg-destructive/10 p-2 text-xs", "data-effect-issues": true, children: state.issues.map((issue, idx) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
1908
1923
  "div",
1909
1924
  {
@@ -6,7 +6,7 @@ import {
6
6
  useEffectAuthoring,
7
7
  useEffectDescription,
8
8
  useEffects
9
- } from "../chunk-ZQ6H2C7N.js";
9
+ } from "../chunk-BWEARAWR.js";
10
10
  import "../chunk-5LFQ2UQZ.js";
11
11
  import "../chunk-KIRIU53A.js";
12
12
  import "../chunk-3I7FOSLF.js";
@@ -0,0 +1,66 @@
1
+ import { type ComponentType, type ReactNode } from 'react';
2
+ /** A checkbox in the image editor's panels. */
3
+ export interface ImageCheckboxProps {
4
+ checked: boolean;
5
+ /** The accessible name. */
6
+ label: string;
7
+ disabled?: boolean;
8
+ onChange: (checked: boolean) => void;
9
+ className?: string;
10
+ }
11
+ /** A range slider in the image editor's panels. */
12
+ export interface ImageRangeProps {
13
+ value: number;
14
+ min: number;
15
+ max: number;
16
+ step: number;
17
+ /** The accessible name. */
18
+ label: string;
19
+ disabled?: boolean;
20
+ /** Every change while the value moves. */
21
+ onChange: (value: number) => void;
22
+ /** A drag (or key press) starts. */
23
+ onStart?: () => void;
24
+ /** A drag (or key press) ends. */
25
+ onEnd?: () => void;
26
+ className?: string;
27
+ }
28
+ /** One choice of an {@link ImageSelectProps}. */
29
+ export interface ImageSelectOption {
30
+ value: string;
31
+ label: string;
32
+ }
33
+ /** A dropdown in the image editor's panels. */
34
+ export interface ImageSelectProps {
35
+ value: string;
36
+ options: readonly ImageSelectOption[];
37
+ /** The accessible name. */
38
+ label: string;
39
+ /** Shown when `value` matches no option (e.g. "Add effect…"). */
40
+ placeholder?: string;
41
+ disabled?: boolean;
42
+ onChange: (value: string) => void;
43
+ className?: string;
44
+ }
45
+ /**
46
+ * The host's own form controls for the image editor's panels. Any left out fall back to the
47
+ * editor's plain inputs.
48
+ */
49
+ export interface ImageEditorControls {
50
+ Checkbox?: ComponentType<ImageCheckboxProps>;
51
+ Range?: ComponentType<ImageRangeProps>;
52
+ Select?: ComponentType<ImageSelectProps>;
53
+ }
54
+ /** Makes the image editor's panels inside it use the host's controls. */
55
+ export declare function ImageEditorControlsProvider({ controls, children }: {
56
+ controls: ImageEditorControls;
57
+ children?: ReactNode;
58
+ }): import("react").JSX.Element;
59
+ /** The controls set by an enclosing {@link ImageEditorControlsProvider}, or none. */
60
+ export declare function useImageEditorControls(): ImageEditorControls;
61
+ /** A checkbox: the host's, or a plain input. */
62
+ export declare function ImageCheckbox(props: ImageCheckboxProps): import("react").JSX.Element;
63
+ /** A range slider: the host's, or a plain input. */
64
+ export declare function ImageRange(props: ImageRangeProps): import("react").JSX.Element;
65
+ /** A dropdown: the host's, or a plain select. */
66
+ export declare function ImageSelect(props: ImageSelectProps): import("react").JSX.Element;
@@ -0,0 +1,66 @@
1
+ import { type ComponentType, type ReactNode } from 'react';
2
+ /** A checkbox in the image editor's panels. */
3
+ export interface ImageCheckboxProps {
4
+ checked: boolean;
5
+ /** The accessible name. */
6
+ label: string;
7
+ disabled?: boolean;
8
+ onChange: (checked: boolean) => void;
9
+ className?: string;
10
+ }
11
+ /** A range slider in the image editor's panels. */
12
+ export interface ImageRangeProps {
13
+ value: number;
14
+ min: number;
15
+ max: number;
16
+ step: number;
17
+ /** The accessible name. */
18
+ label: string;
19
+ disabled?: boolean;
20
+ /** Every change while the value moves. */
21
+ onChange: (value: number) => void;
22
+ /** A drag (or key press) starts. */
23
+ onStart?: () => void;
24
+ /** A drag (or key press) ends. */
25
+ onEnd?: () => void;
26
+ className?: string;
27
+ }
28
+ /** One choice of an {@link ImageSelectProps}. */
29
+ export interface ImageSelectOption {
30
+ value: string;
31
+ label: string;
32
+ }
33
+ /** A dropdown in the image editor's panels. */
34
+ export interface ImageSelectProps {
35
+ value: string;
36
+ options: readonly ImageSelectOption[];
37
+ /** The accessible name. */
38
+ label: string;
39
+ /** Shown when `value` matches no option (e.g. "Add effect…"). */
40
+ placeholder?: string;
41
+ disabled?: boolean;
42
+ onChange: (value: string) => void;
43
+ className?: string;
44
+ }
45
+ /**
46
+ * The host's own form controls for the image editor's panels. Any left out fall back to the
47
+ * editor's plain inputs.
48
+ */
49
+ export interface ImageEditorControls {
50
+ Checkbox?: ComponentType<ImageCheckboxProps>;
51
+ Range?: ComponentType<ImageRangeProps>;
52
+ Select?: ComponentType<ImageSelectProps>;
53
+ }
54
+ /** Makes the image editor's panels inside it use the host's controls. */
55
+ export declare function ImageEditorControlsProvider({ controls, children }: {
56
+ controls: ImageEditorControls;
57
+ children?: ReactNode;
58
+ }): import("react").JSX.Element;
59
+ /** The controls set by an enclosing {@link ImageEditorControlsProvider}, or none. */
60
+ export declare function useImageEditorControls(): ImageEditorControls;
61
+ /** A checkbox: the host's, or a plain input. */
62
+ export declare function ImageCheckbox(props: ImageCheckboxProps): import("react").JSX.Element;
63
+ /** A range slider: the host's, or a plain input. */
64
+ export declare function ImageRange(props: ImageRangeProps): import("react").JSX.Element;
65
+ /** A dropdown: the host's, or a plain select. */
66
+ export declare function ImageSelect(props: ImageSelectProps): import("react").JSX.Element;