@pixerate/editor-react 0.115.0 → 0.117.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/dist/{chunk-2KXZLZAS.js → chunk-K7GU7BS7.js} +118 -26
- package/dist/image-editor/ImageProviderEffectsPanel.d.cts +6 -4
- package/dist/image-editor/ImageProviderEffectsPanel.d.ts +6 -4
- package/dist/image-editor/LayerEffectsPanel.d.cts +6 -1
- package/dist/image-editor/LayerEffectsPanel.d.ts +6 -1
- package/dist/image-editor/index.cjs +112 -20
- package/dist/image-editor/index.js +1 -1
- package/dist/index.cjs +112 -20
- package/dist/index.js +1 -1
- package/package.json +3 -3
|
@@ -190,7 +190,7 @@ function useImageEffectsTools(registry, controller, options = {}) {
|
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
// src/image-editor/ImageEditor.tsx
|
|
193
|
-
import React15, { useRef as
|
|
193
|
+
import React15, { useRef as useRef7, useEffect as useEffect13, useState as useState16 } from "react";
|
|
194
194
|
import {
|
|
195
195
|
normalizeProcessVersion,
|
|
196
196
|
LATEST_PROCESS_VERSION,
|
|
@@ -1451,7 +1451,7 @@ import { useEffect as useEffect6, useRef as useRef5, useState as useState7 } fro
|
|
|
1451
1451
|
import { useEffect as useEffect5, useRef as useRef4, useState as useState6 } from "react";
|
|
1452
1452
|
import { LAYER_EFFECT_MENU, effectControlChange, layerEffectControls, layerEffectsPanel } from "@pixerate/editor/image-editor";
|
|
1453
1453
|
import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1454
|
-
var LayerEffectsPanel = ({ controller, layerId, className }) => {
|
|
1454
|
+
var LayerEffectsPanel = ({ controller, layerId, heading = true, className }) => {
|
|
1455
1455
|
const [, setTick] = useState6(0);
|
|
1456
1456
|
useEffect5(() => controller.subscribe(() => setTick((n) => n + 1)), [controller]);
|
|
1457
1457
|
const [open, setOpen] = useState6(null);
|
|
@@ -1533,9 +1533,9 @@ var LayerEffectsPanel = ({ controller, layerId, className }) => {
|
|
|
1533
1533
|
] }, c.key);
|
|
1534
1534
|
}
|
|
1535
1535
|
};
|
|
1536
|
-
return /* @__PURE__ */ jsxs7("div", { className: `flex flex-col gap-1.5 text-xs text-foreground ${className ?? ""}`, "data-testid": "layer-effects", "aria-label": "Layer
|
|
1536
|
+
return /* @__PURE__ */ jsxs7("div", { className: `flex flex-col gap-1.5 text-xs text-foreground ${className ?? ""}`, "data-testid": "layer-effects", "aria-label": "Layer style", role: "group", children: [
|
|
1537
1537
|
/* @__PURE__ */ jsxs7("div", { className: "flex flex-wrap items-center gap-2", children: [
|
|
1538
|
-
/* @__PURE__ */ jsx7("span", { className: "font-semibold text-foreground", children: "
|
|
1538
|
+
/* @__PURE__ */ jsx7("span", { className: "font-semibold text-foreground", children: heading ? "Layer Style" : "Styles" }),
|
|
1539
1539
|
/* @__PURE__ */ jsxs7("label", { className: "flex items-center gap-1 text-foreground", children: [
|
|
1540
1540
|
/* @__PURE__ */ jsx7(ImageCheckbox, { label: "Effects on", checked: model.enabled, disabled: model.readOnly, onChange: (on) => attempt(() => controller.setLayerEffectsEnabled(id, on)) }),
|
|
1541
1541
|
"On"
|
|
@@ -1561,12 +1561,12 @@ var LayerEffectsPanel = ({ controller, layerId, className }) => {
|
|
|
1561
1561
|
),
|
|
1562
1562
|
"%"
|
|
1563
1563
|
] }),
|
|
1564
|
-
/* @__PURE__ */ jsx7(
|
|
1564
|
+
heading && /* @__PURE__ */ jsx7(
|
|
1565
1565
|
ImageSelect,
|
|
1566
1566
|
{
|
|
1567
|
-
label: "Add
|
|
1567
|
+
label: "Add style",
|
|
1568
1568
|
value: "",
|
|
1569
|
-
placeholder: "Add
|
|
1569
|
+
placeholder: "Add style\u2026",
|
|
1570
1570
|
disabled: model.readOnly,
|
|
1571
1571
|
options: LAYER_EFFECT_MENU.map((m) => ({ value: m.kind, label: m.label })),
|
|
1572
1572
|
onChange: (v) => {
|
|
@@ -2046,8 +2046,8 @@ var LayersPanel = ({ controller, thumbnailSize = 32, psd = true, psdFileName = "
|
|
|
2046
2046
|
};
|
|
2047
2047
|
|
|
2048
2048
|
// src/image-editor/ImageProviderEffectsPanel.tsx
|
|
2049
|
-
import
|
|
2050
|
-
import { EFFECT_LAYER_USES, findLayer } from "@pixerate/editor/image-editor";
|
|
2049
|
+
import { useEffect as useEffect7, useRef as useRef6, useState as useState8 } from "react";
|
|
2050
|
+
import { EFFECT_LAYER_USES, effectLayerTiming, findLayer } from "@pixerate/editor/image-editor";
|
|
2051
2051
|
|
|
2052
2052
|
// src/image-editor/controls/parameterControls.tsx
|
|
2053
2053
|
import { matchParameterOptionValue } from "@pixerate/editor/parameters";
|
|
@@ -2125,12 +2125,14 @@ function ImageEffectControls({ provider, effect, name, values, onChange, onPrese
|
|
|
2125
2125
|
|
|
2126
2126
|
// src/image-editor/ImageProviderEffectsPanel.tsx
|
|
2127
2127
|
import { jsx as jsx11, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
2128
|
+
var fmt = (ms) => `${(ms / 1e3).toFixed(ms < 1e4 ? 2 : 1)} s`;
|
|
2128
2129
|
function ImageProviderEffectsPanel({ controller, className = "", components }) {
|
|
2129
2130
|
const [, setTick] = useState8(0);
|
|
2130
2131
|
useEffect7(() => controller.subscribe(() => setTick((n) => n + 1)), [controller]);
|
|
2131
2132
|
const [browse, setBrowse] = useState8(null);
|
|
2132
2133
|
const [message, setMessage] = useState8(null);
|
|
2133
2134
|
const [open, setOpen] = useState8(null);
|
|
2135
|
+
const [scrubbed, setScrubbed] = useState8(null);
|
|
2134
2136
|
const provider = controller.effectsProvider;
|
|
2135
2137
|
const state = controller.getState();
|
|
2136
2138
|
const layer = state.activeLayerId ? findLayer(state.layers, state.activeLayerId)?.layer ?? null : null;
|
|
@@ -2138,7 +2140,7 @@ function ImageProviderEffectsPanel({ controller, className = "", components }) {
|
|
|
2138
2140
|
setMessage(null);
|
|
2139
2141
|
Promise.resolve().then(work).catch((e) => setMessage(e instanceof Error ? e.message : String(e)));
|
|
2140
2142
|
};
|
|
2141
|
-
const drags =
|
|
2143
|
+
const drags = useRef6(/* @__PURE__ */ new Set());
|
|
2142
2144
|
const commit = (gesture) => {
|
|
2143
2145
|
if (gesture) {
|
|
2144
2146
|
if (!drags.current.has(gesture)) {
|
|
@@ -2151,21 +2153,105 @@ function ImageProviderEffectsPanel({ controller, className = "", components }) {
|
|
|
2151
2153
|
};
|
|
2152
2154
|
const filters = layer?.type === "smart" ? (layer.smartFilters?.filters ?? []).filter((f) => f.kind === "effect") : [];
|
|
2153
2155
|
const generator = layer?.type === "pixel" ? layer.generator : void 0;
|
|
2154
|
-
const canFilter = !!layer && layer.type !== "adjustment" && layer.type !== "annotation";
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2156
|
+
const canFilter = !!provider && !!layer && layer.type !== "adjustment" && layer.type !== "annotation";
|
|
2157
|
+
const { description } = useEffectDescription(provider, generator?.effect);
|
|
2158
|
+
const timing = generator ? effectLayerTiming(generator, description) : null;
|
|
2159
|
+
const scrub = useRef6({ next: null, busy: false, gesture: null });
|
|
2160
|
+
const scrubTo = (layerId, time) => {
|
|
2161
|
+
const s = scrub.current;
|
|
2162
|
+
setScrubbed(time);
|
|
2163
|
+
s.next = { layerId, time, commit: commit(s.gesture) };
|
|
2164
|
+
if (s.busy) return;
|
|
2165
|
+
s.busy = true;
|
|
2166
|
+
const step = () => {
|
|
2167
|
+
const n = s.next;
|
|
2168
|
+
s.next = null;
|
|
2169
|
+
if (!n) return Promise.resolve();
|
|
2170
|
+
return controller.updateEffectLayer(n.layerId, { time: n.time }, n.commit).then(step);
|
|
2171
|
+
};
|
|
2172
|
+
step().catch((e) => setMessage(e instanceof Error ? e.message : String(e))).finally(() => {
|
|
2173
|
+
s.busy = false;
|
|
2174
|
+
setScrubbed(null);
|
|
2175
|
+
});
|
|
2176
|
+
};
|
|
2177
|
+
const shown = scrubbed ?? timing?.time ?? 0;
|
|
2178
|
+
return /* @__PURE__ */ jsxs10("section", { className: `flex flex-col gap-2 text-xs ${className}`, "aria-label": "Effects", "data-image-provider-effects": "", children: [
|
|
2161
2179
|
!provider && /* @__PURE__ */ jsx11("p", { className: "text-[11px] text-muted-foreground", children: "No effects provider is registered. Effects in the document are kept." }),
|
|
2162
|
-
|
|
2163
|
-
browse === "layer" && /* @__PURE__ */ jsx11(EffectsBrowser, { provider, uses: EFFECT_LAYER_USES, title: "Generators and overlays", onPick: (e) => (setBrowse(null), run(() => controller.addEffectLayer(e.id))) }),
|
|
2164
|
-
generator && layer && /* @__PURE__ */ jsxs10("div", { className: "space-y-1", "data-effect-part": "generator", children: [
|
|
2180
|
+
generator && layer && /* @__PURE__ */ jsxs10("div", { className: "space-y-2", "data-effect-part": "generator", children: [
|
|
2165
2181
|
/* @__PURE__ */ jsxs10("div", { className: "flex items-center gap-1", children: [
|
|
2166
|
-
/* @__PURE__ */ jsx11("span", { className: "flex-1 font-medium text-foreground", children: generator.name ?? generator.effect }),
|
|
2182
|
+
/* @__PURE__ */ jsx11("span", { className: "min-w-0 flex-1 truncate font-medium text-foreground", title: generator.name ?? generator.effect, children: generator.name ?? generator.effect }),
|
|
2183
|
+
/* @__PURE__ */ jsx11("button", { type: "button", className: imageOutlineButtonClass, disabled: !provider, "aria-pressed": browse === "change", onClick: () => setBrowse(browse === "change" ? null : "change"), children: "Change\u2026" }),
|
|
2167
2184
|
/* @__PURE__ */ jsx11("button", { type: "button", className: imageOutlineButtonClass, title: "Keep the pixels as a plain layer", onClick: () => run(() => controller.rasterizeEffectLayer(layer.id)), children: "Rasterize" })
|
|
2168
2185
|
] }),
|
|
2186
|
+
browse === "change" && /* @__PURE__ */ jsx11(EffectsBrowser, { provider, uses: EFFECT_LAYER_USES, title: "Change the effect to", onPick: (e) => (setBrowse(null), run(() => controller.updateEffectLayer(layer.id, { effect: e.id }))) }),
|
|
2187
|
+
timing && /* @__PURE__ */ jsxs10("div", { className: "space-y-1.5 rounded border border-border p-1.5", "data-effect-part": "timing", role: "group", "aria-label": "Frames", children: [
|
|
2188
|
+
/* @__PURE__ */ jsxs10("div", { className: "flex gap-1", role: "radiogroup", "aria-label": "Output", children: [
|
|
2189
|
+
/* @__PURE__ */ jsx11(
|
|
2190
|
+
"button",
|
|
2191
|
+
{
|
|
2192
|
+
type: "button",
|
|
2193
|
+
role: "radio",
|
|
2194
|
+
"aria-checked": timing.mode === "still",
|
|
2195
|
+
className: `${imageOutlineButtonClass} flex-1 ${timing.mode === "still" ? "bg-accent text-accent-foreground" : ""}`,
|
|
2196
|
+
onClick: () => run(() => controller.updateEffectLayer(layer.id, { animate: null })),
|
|
2197
|
+
children: "Still frame"
|
|
2198
|
+
}
|
|
2199
|
+
),
|
|
2200
|
+
/* @__PURE__ */ jsx11(
|
|
2201
|
+
"button",
|
|
2202
|
+
{
|
|
2203
|
+
type: "button",
|
|
2204
|
+
role: "radio",
|
|
2205
|
+
"aria-checked": timing.mode === "animate",
|
|
2206
|
+
className: `${imageOutlineButtonClass} flex-1 ${timing.mode === "animate" ? "bg-accent text-accent-foreground" : ""}`,
|
|
2207
|
+
onClick: () => run(() => controller.updateEffectLayer(layer.id, { animate: { duration: timing.duration } })),
|
|
2208
|
+
children: "Animate"
|
|
2209
|
+
}
|
|
2210
|
+
)
|
|
2211
|
+
] }),
|
|
2212
|
+
/* @__PURE__ */ jsxs10("label", { className: "flex items-center gap-1.5", children: [
|
|
2213
|
+
/* @__PURE__ */ jsx11("span", { className: "w-16 shrink-0 text-[11px] text-foreground", children: timing.mode === "still" ? "Frame" : "Starts at" }),
|
|
2214
|
+
/* @__PURE__ */ jsx11(
|
|
2215
|
+
ImageRange,
|
|
2216
|
+
{
|
|
2217
|
+
min: 0,
|
|
2218
|
+
max: timing.range,
|
|
2219
|
+
step: Math.max(1, Math.round(timing.range / 200)),
|
|
2220
|
+
className: "flex-1",
|
|
2221
|
+
value: shown,
|
|
2222
|
+
label: timing.mode === "still" ? "Frame" : "Starts at",
|
|
2223
|
+
onStart: () => scrub.current.gesture = `time:${Date.now()}`,
|
|
2224
|
+
onEnd: () => scrub.current.gesture = null,
|
|
2225
|
+
onChange: (t) => scrubTo(layer.id, t)
|
|
2226
|
+
}
|
|
2227
|
+
),
|
|
2228
|
+
/* @__PURE__ */ jsx11("span", { className: "w-12 shrink-0 text-right tabular-nums text-muted-foreground", children: fmt(shown) })
|
|
2229
|
+
] }),
|
|
2230
|
+
timing.mode === "animate" && /* @__PURE__ */ jsxs10("label", { className: "flex items-center gap-1.5", children: [
|
|
2231
|
+
/* @__PURE__ */ jsx11("span", { className: "w-16 shrink-0 text-[11px] text-foreground", children: "Length" }),
|
|
2232
|
+
/* @__PURE__ */ jsx11(
|
|
2233
|
+
"input",
|
|
2234
|
+
{
|
|
2235
|
+
type: "number",
|
|
2236
|
+
"aria-label": "Animation length in seconds",
|
|
2237
|
+
min: 0.1,
|
|
2238
|
+
max: 60,
|
|
2239
|
+
step: 0.1,
|
|
2240
|
+
defaultValue: Math.round(timing.duration / 100) / 10,
|
|
2241
|
+
className: "w-16 rounded border border-border bg-muted px-1 text-foreground",
|
|
2242
|
+
onBlur: (e) => {
|
|
2243
|
+
const s = Number(e.currentTarget.value);
|
|
2244
|
+
if (s > 0 && s * 1e3 !== timing.duration) run(() => controller.updateEffectLayer(layer.id, { animate: { duration: Math.min(60, s) * 1e3 } }));
|
|
2245
|
+
}
|
|
2246
|
+
},
|
|
2247
|
+
timing.duration
|
|
2248
|
+
),
|
|
2249
|
+
/* @__PURE__ */ jsxs10("span", { className: "text-muted-foreground", children: [
|
|
2250
|
+
"s",
|
|
2251
|
+
timing.loops ? ` \xB7 loops every ${fmt(timing.range)}` : ""
|
|
2252
|
+
] })
|
|
2253
|
+
] })
|
|
2254
|
+
] }),
|
|
2169
2255
|
/* @__PURE__ */ jsx11(
|
|
2170
2256
|
ImageEffectControls,
|
|
2171
2257
|
{
|
|
@@ -2179,7 +2265,12 @@ function ImageProviderEffectsPanel({ controller, className = "", components }) {
|
|
|
2179
2265
|
}
|
|
2180
2266
|
)
|
|
2181
2267
|
] }),
|
|
2182
|
-
|
|
2268
|
+
layer && canFilter && /* @__PURE__ */ jsxs10("div", { className: "flex items-center gap-1", "data-effect-part": "applied", children: [
|
|
2269
|
+
/* @__PURE__ */ jsx11("span", { className: "flex-1 font-semibold uppercase tracking-wider text-[11px] text-foreground", children: "Filters" }),
|
|
2270
|
+
/* @__PURE__ */ jsx11("button", { type: "button", className: imageOutlineButtonClass, "aria-pressed": browse === "filter", onClick: () => setBrowse(browse === "filter" ? null : "filter"), children: "Add filter\u2026" })
|
|
2271
|
+
] }),
|
|
2272
|
+
browse === "filter" && layer && /* @__PURE__ */ jsx11(EffectsBrowser, { provider, uses: ["filter"], title: "Filters", onPick: (e) => (setBrowse(null), run(() => controller.applyEffectFilter(layer.id, e.id))) }),
|
|
2273
|
+
filters.length > 0 && layer && /* @__PURE__ */ jsx11("ol", { className: "space-y-1", "data-effect-part": "filters", "aria-label": "Filters", children: filters.map((f) => {
|
|
2183
2274
|
const label = f.kind === "effect" ? f.name ?? f.effect : f.kind;
|
|
2184
2275
|
const all = layer.smartFilters.filters;
|
|
2185
2276
|
const index = all.indexOf(f);
|
|
@@ -2230,6 +2321,7 @@ function ImageProviderEffectsPanel({ controller, className = "", components }) {
|
|
|
2230
2321
|
] })
|
|
2231
2322
|
] }, f.id);
|
|
2232
2323
|
}) }),
|
|
2324
|
+
layer && canFilter && !generator && filters.length === 0 && /* @__PURE__ */ jsx11("p", { className: "text-[11px] text-muted-foreground", children: "No filters yet. A filter changes the layer's pixels and stays editable. Layer styles such as a drop shadow are in the layer's properties; new effect layers are added from the layers panel." }),
|
|
2233
2325
|
!layer && /* @__PURE__ */ jsx11("p", { className: "text-[11px] text-muted-foreground", children: "Select a layer to apply effects to it." }),
|
|
2234
2326
|
message && /* @__PURE__ */ jsx11("p", { role: "alert", className: "text-[11px] text-destructive", children: message })
|
|
2235
2327
|
] });
|
|
@@ -3089,9 +3181,9 @@ var ImageEditor = ({
|
|
|
3089
3181
|
});
|
|
3090
3182
|
const legacyProcess = normalizeProcessVersion(state.adjustments.process) < LATEST_PROCESS_VERSION;
|
|
3091
3183
|
const [activeTab, setActiveTab] = useState16("crop");
|
|
3092
|
-
const rootRef =
|
|
3184
|
+
const rootRef = useRef7(null);
|
|
3093
3185
|
const canvasMode = activeTab === "crop" || activeTab === "select" || activeTab === "paint" || activeTab === "annotate" ? activeTab : "none";
|
|
3094
|
-
const activeTabRef =
|
|
3186
|
+
const activeTabRef = useRef7(activeTab);
|
|
3095
3187
|
activeTabRef.current = activeTab;
|
|
3096
3188
|
const openPanel = async (ref) => {
|
|
3097
3189
|
if (ref.kind !== "panel" || activeTabRef.current === ref.id) return;
|
|
@@ -3112,8 +3204,8 @@ var ImageEditor = ({
|
|
|
3112
3204
|
else setShapeTypeError(message);
|
|
3113
3205
|
};
|
|
3114
3206
|
const finishTyping = () => setTypeSession(null);
|
|
3115
|
-
const transformToolRef =
|
|
3116
|
-
const transformControllerRef =
|
|
3207
|
+
const transformToolRef = useRef7(null);
|
|
3208
|
+
const transformControllerRef = useRef7(controller);
|
|
3117
3209
|
if (!transformToolRef.current || transformControllerRef.current !== controller) {
|
|
3118
3210
|
transformToolRef.current?.cancel();
|
|
3119
3211
|
transformToolRef.current = new FreeTransformTool2(controller, {
|
|
@@ -8,9 +8,11 @@ export interface ImageProviderEffectsPanelProps {
|
|
|
8
8
|
components?: ParameterComponents;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
* Provider effects
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* smart object in the same undo step.
|
|
11
|
+
* Provider effects for the active layer. An effect layer first: its effect (change it or
|
|
12
|
+
* rasterize it), a still frame or an animation for an effect that moves, and its controls. Then
|
|
13
|
+
* the provider filters applied to the layer (smart filters; applying one converts a pixel layer to
|
|
14
|
+
* a smart object in the same undo step). Layer styles (drop shadow, stroke…) are not here: they
|
|
15
|
+
* are part of the layer's properties (`LayerEffectsPanel`). New effect layers come from the layers
|
|
16
|
+
* panel. Without a provider it says why nothing can be added.
|
|
15
17
|
*/
|
|
16
18
|
export declare function ImageProviderEffectsPanel({ controller, className, components }: ImageProviderEffectsPanelProps): React.JSX.Element;
|
|
@@ -8,9 +8,11 @@ export interface ImageProviderEffectsPanelProps {
|
|
|
8
8
|
components?: ParameterComponents;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
* Provider effects
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* smart object in the same undo step.
|
|
11
|
+
* Provider effects for the active layer. An effect layer first: its effect (change it or
|
|
12
|
+
* rasterize it), a still frame or an animation for an effect that moves, and its controls. Then
|
|
13
|
+
* the provider filters applied to the layer (smart filters; applying one converts a pixel layer to
|
|
14
|
+
* a smart object in the same undo step). Layer styles (drop shadow, stroke…) are not here: they
|
|
15
|
+
* are part of the layer's properties (`LayerEffectsPanel`). New effect layers come from the layers
|
|
16
|
+
* panel. Without a provider it says why nothing can be added.
|
|
15
17
|
*/
|
|
16
18
|
export declare function ImageProviderEffectsPanel({ controller, className, components }: ImageProviderEffectsPanelProps): React.JSX.Element;
|
|
@@ -4,10 +4,15 @@ export interface LayerEffectsPanelProps {
|
|
|
4
4
|
controller: ImageEditorController;
|
|
5
5
|
/** The layer whose effects to show (default: the active layer). */
|
|
6
6
|
layerId?: string | null;
|
|
7
|
+
/**
|
|
8
|
+
* Show the "Layer Style" title and the "Add style" menu (default true). Without them (inside a
|
|
9
|
+
* panel that adds styles from its own menu) the master switch and Scale stay.
|
|
10
|
+
*/
|
|
11
|
+
heading?: boolean;
|
|
7
12
|
className?: string;
|
|
8
13
|
}
|
|
9
14
|
/**
|
|
10
|
-
* A layer's effects (Photoshop's layer styles): the master switch, Scale Effects, an "Add
|
|
15
|
+
* A layer's effects (Photoshop's layer styles): the master switch, Scale Effects, an "Add style"
|
|
11
16
|
* menu, and each effect with its enabled toggle, remove button and, when expanded, its settings.
|
|
12
17
|
* Every change is one undo step (a slider drag is one step too).
|
|
13
18
|
*/
|
|
@@ -4,10 +4,15 @@ export interface LayerEffectsPanelProps {
|
|
|
4
4
|
controller: ImageEditorController;
|
|
5
5
|
/** The layer whose effects to show (default: the active layer). */
|
|
6
6
|
layerId?: string | null;
|
|
7
|
+
/**
|
|
8
|
+
* Show the "Layer Style" title and the "Add style" menu (default true). Without them (inside a
|
|
9
|
+
* panel that adds styles from its own menu) the master switch and Scale stay.
|
|
10
|
+
*/
|
|
11
|
+
heading?: boolean;
|
|
7
12
|
className?: string;
|
|
8
13
|
}
|
|
9
14
|
/**
|
|
10
|
-
* A layer's effects (Photoshop's layer styles): the master switch, Scale Effects, an "Add
|
|
15
|
+
* A layer's effects (Photoshop's layer styles): the master switch, Scale Effects, an "Add style"
|
|
11
16
|
* menu, and each effect with its enabled toggle, remove button and, when expanded, its settings.
|
|
12
17
|
* Every change is one undo step (a slider drag is one step too).
|
|
13
18
|
*/
|
|
@@ -1536,7 +1536,7 @@ var import_react11 = require("react");
|
|
|
1536
1536
|
var import_react10 = require("react");
|
|
1537
1537
|
var import_image_editor7 = require("@pixerate/editor/image-editor");
|
|
1538
1538
|
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1539
|
-
var LayerEffectsPanel = ({ controller, layerId, className }) => {
|
|
1539
|
+
var LayerEffectsPanel = ({ controller, layerId, heading = true, className }) => {
|
|
1540
1540
|
const [, setTick] = (0, import_react10.useState)(0);
|
|
1541
1541
|
(0, import_react10.useEffect)(() => controller.subscribe(() => setTick((n) => n + 1)), [controller]);
|
|
1542
1542
|
const [open, setOpen] = (0, import_react10.useState)(null);
|
|
@@ -1618,9 +1618,9 @@ var LayerEffectsPanel = ({ controller, layerId, className }) => {
|
|
|
1618
1618
|
] }, c.key);
|
|
1619
1619
|
}
|
|
1620
1620
|
};
|
|
1621
|
-
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: `flex flex-col gap-1.5 text-xs text-foreground ${className ?? ""}`, "data-testid": "layer-effects", "aria-label": "Layer
|
|
1621
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: `flex flex-col gap-1.5 text-xs text-foreground ${className ?? ""}`, "data-testid": "layer-effects", "aria-label": "Layer style", role: "group", children: [
|
|
1622
1622
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "flex flex-wrap items-center gap-2", children: [
|
|
1623
|
-
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "font-semibold text-foreground", children: "
|
|
1623
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "font-semibold text-foreground", children: heading ? "Layer Style" : "Styles" }),
|
|
1624
1624
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("label", { className: "flex items-center gap-1 text-foreground", children: [
|
|
1625
1625
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ImageCheckbox, { label: "Effects on", checked: model.enabled, disabled: model.readOnly, onChange: (on) => attempt(() => controller.setLayerEffectsEnabled(id, on)) }),
|
|
1626
1626
|
"On"
|
|
@@ -1646,12 +1646,12 @@ var LayerEffectsPanel = ({ controller, layerId, className }) => {
|
|
|
1646
1646
|
),
|
|
1647
1647
|
"%"
|
|
1648
1648
|
] }),
|
|
1649
|
-
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1649
|
+
heading && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1650
1650
|
ImageSelect,
|
|
1651
1651
|
{
|
|
1652
|
-
label: "Add
|
|
1652
|
+
label: "Add style",
|
|
1653
1653
|
value: "",
|
|
1654
|
-
placeholder: "Add
|
|
1654
|
+
placeholder: "Add style\u2026",
|
|
1655
1655
|
disabled: model.readOnly,
|
|
1656
1656
|
options: import_image_editor7.LAYER_EFFECT_MENU.map((m) => ({ value: m.kind, label: m.label })),
|
|
1657
1657
|
onChange: (v) => {
|
|
@@ -2116,7 +2116,7 @@ var LayersPanel = ({ controller, thumbnailSize = 32, psd = true, psdFileName = "
|
|
|
2116
2116
|
};
|
|
2117
2117
|
|
|
2118
2118
|
// src/image-editor/ImageProviderEffectsPanel.tsx
|
|
2119
|
-
var import_react21 =
|
|
2119
|
+
var import_react21 = require("react");
|
|
2120
2120
|
var import_image_editor9 = require("@pixerate/editor/image-editor");
|
|
2121
2121
|
|
|
2122
2122
|
// src/effects/useEffects.ts
|
|
@@ -3961,12 +3961,14 @@ function ImageEffectControls({ provider, effect, name, values, onChange, onPrese
|
|
|
3961
3961
|
|
|
3962
3962
|
// src/image-editor/ImageProviderEffectsPanel.tsx
|
|
3963
3963
|
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
3964
|
+
var fmt = (ms) => `${(ms / 1e3).toFixed(ms < 1e4 ? 2 : 1)} s`;
|
|
3964
3965
|
function ImageProviderEffectsPanel({ controller, className = "", components }) {
|
|
3965
3966
|
const [, setTick] = (0, import_react21.useState)(0);
|
|
3966
3967
|
(0, import_react21.useEffect)(() => controller.subscribe(() => setTick((n) => n + 1)), [controller]);
|
|
3967
3968
|
const [browse, setBrowse] = (0, import_react21.useState)(null);
|
|
3968
3969
|
const [message, setMessage] = (0, import_react21.useState)(null);
|
|
3969
3970
|
const [open, setOpen] = (0, import_react21.useState)(null);
|
|
3971
|
+
const [scrubbed, setScrubbed] = (0, import_react21.useState)(null);
|
|
3970
3972
|
const provider = controller.effectsProvider;
|
|
3971
3973
|
const state = controller.getState();
|
|
3972
3974
|
const layer = state.activeLayerId ? (0, import_image_editor9.findLayer)(state.layers, state.activeLayerId)?.layer ?? null : null;
|
|
@@ -3974,7 +3976,7 @@ function ImageProviderEffectsPanel({ controller, className = "", components }) {
|
|
|
3974
3976
|
setMessage(null);
|
|
3975
3977
|
Promise.resolve().then(work).catch((e) => setMessage(e instanceof Error ? e.message : String(e)));
|
|
3976
3978
|
};
|
|
3977
|
-
const drags = import_react21.
|
|
3979
|
+
const drags = (0, import_react21.useRef)(/* @__PURE__ */ new Set());
|
|
3978
3980
|
const commit = (gesture) => {
|
|
3979
3981
|
if (gesture) {
|
|
3980
3982
|
if (!drags.current.has(gesture)) {
|
|
@@ -3987,21 +3989,105 @@ function ImageProviderEffectsPanel({ controller, className = "", components }) {
|
|
|
3987
3989
|
};
|
|
3988
3990
|
const filters = layer?.type === "smart" ? (layer.smartFilters?.filters ?? []).filter((f) => f.kind === "effect") : [];
|
|
3989
3991
|
const generator = layer?.type === "pixel" ? layer.generator : void 0;
|
|
3990
|
-
const canFilter = !!layer && layer.type !== "adjustment" && layer.type !== "annotation";
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3992
|
+
const canFilter = !!provider && !!layer && layer.type !== "adjustment" && layer.type !== "annotation";
|
|
3993
|
+
const { description } = useEffectDescription(provider, generator?.effect);
|
|
3994
|
+
const timing = generator ? (0, import_image_editor9.effectLayerTiming)(generator, description) : null;
|
|
3995
|
+
const scrub = (0, import_react21.useRef)({ next: null, busy: false, gesture: null });
|
|
3996
|
+
const scrubTo = (layerId, time) => {
|
|
3997
|
+
const s = scrub.current;
|
|
3998
|
+
setScrubbed(time);
|
|
3999
|
+
s.next = { layerId, time, commit: commit(s.gesture) };
|
|
4000
|
+
if (s.busy) return;
|
|
4001
|
+
s.busy = true;
|
|
4002
|
+
const step = () => {
|
|
4003
|
+
const n = s.next;
|
|
4004
|
+
s.next = null;
|
|
4005
|
+
if (!n) return Promise.resolve();
|
|
4006
|
+
return controller.updateEffectLayer(n.layerId, { time: n.time }, n.commit).then(step);
|
|
4007
|
+
};
|
|
4008
|
+
step().catch((e) => setMessage(e instanceof Error ? e.message : String(e))).finally(() => {
|
|
4009
|
+
s.busy = false;
|
|
4010
|
+
setScrubbed(null);
|
|
4011
|
+
});
|
|
4012
|
+
};
|
|
4013
|
+
const shown = scrubbed ?? timing?.time ?? 0;
|
|
4014
|
+
return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("section", { className: `flex flex-col gap-2 text-xs ${className}`, "aria-label": "Effects", "data-image-provider-effects": "", children: [
|
|
3997
4015
|
!provider && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("p", { className: "text-[11px] text-muted-foreground", children: "No effects provider is registered. Effects in the document are kept." }),
|
|
3998
|
-
|
|
3999
|
-
browse === "layer" && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(EffectsBrowser, { provider, uses: import_image_editor9.EFFECT_LAYER_USES, title: "Generators and overlays", onPick: (e) => (setBrowse(null), run(() => controller.addEffectLayer(e.id))) }),
|
|
4000
|
-
generator && layer && /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "space-y-1", "data-effect-part": "generator", children: [
|
|
4016
|
+
generator && layer && /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "space-y-2", "data-effect-part": "generator", children: [
|
|
4001
4017
|
/* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "flex items-center gap-1", children: [
|
|
4002
|
-
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("span", { className: "flex-1 font-medium text-foreground", children: generator.name ?? generator.effect }),
|
|
4018
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("span", { className: "min-w-0 flex-1 truncate font-medium text-foreground", title: generator.name ?? generator.effect, children: generator.name ?? generator.effect }),
|
|
4019
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("button", { type: "button", className: imageOutlineButtonClass, disabled: !provider, "aria-pressed": browse === "change", onClick: () => setBrowse(browse === "change" ? null : "change"), children: "Change\u2026" }),
|
|
4003
4020
|
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("button", { type: "button", className: imageOutlineButtonClass, title: "Keep the pixels as a plain layer", onClick: () => run(() => controller.rasterizeEffectLayer(layer.id)), children: "Rasterize" })
|
|
4004
4021
|
] }),
|
|
4022
|
+
browse === "change" && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(EffectsBrowser, { provider, uses: import_image_editor9.EFFECT_LAYER_USES, title: "Change the effect to", onPick: (e) => (setBrowse(null), run(() => controller.updateEffectLayer(layer.id, { effect: e.id }))) }),
|
|
4023
|
+
timing && /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "space-y-1.5 rounded border border-border p-1.5", "data-effect-part": "timing", role: "group", "aria-label": "Frames", children: [
|
|
4024
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "flex gap-1", role: "radiogroup", "aria-label": "Output", children: [
|
|
4025
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
4026
|
+
"button",
|
|
4027
|
+
{
|
|
4028
|
+
type: "button",
|
|
4029
|
+
role: "radio",
|
|
4030
|
+
"aria-checked": timing.mode === "still",
|
|
4031
|
+
className: `${imageOutlineButtonClass} flex-1 ${timing.mode === "still" ? "bg-accent text-accent-foreground" : ""}`,
|
|
4032
|
+
onClick: () => run(() => controller.updateEffectLayer(layer.id, { animate: null })),
|
|
4033
|
+
children: "Still frame"
|
|
4034
|
+
}
|
|
4035
|
+
),
|
|
4036
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
4037
|
+
"button",
|
|
4038
|
+
{
|
|
4039
|
+
type: "button",
|
|
4040
|
+
role: "radio",
|
|
4041
|
+
"aria-checked": timing.mode === "animate",
|
|
4042
|
+
className: `${imageOutlineButtonClass} flex-1 ${timing.mode === "animate" ? "bg-accent text-accent-foreground" : ""}`,
|
|
4043
|
+
onClick: () => run(() => controller.updateEffectLayer(layer.id, { animate: { duration: timing.duration } })),
|
|
4044
|
+
children: "Animate"
|
|
4045
|
+
}
|
|
4046
|
+
)
|
|
4047
|
+
] }),
|
|
4048
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("label", { className: "flex items-center gap-1.5", children: [
|
|
4049
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("span", { className: "w-16 shrink-0 text-[11px] text-foreground", children: timing.mode === "still" ? "Frame" : "Starts at" }),
|
|
4050
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
4051
|
+
ImageRange,
|
|
4052
|
+
{
|
|
4053
|
+
min: 0,
|
|
4054
|
+
max: timing.range,
|
|
4055
|
+
step: Math.max(1, Math.round(timing.range / 200)),
|
|
4056
|
+
className: "flex-1",
|
|
4057
|
+
value: shown,
|
|
4058
|
+
label: timing.mode === "still" ? "Frame" : "Starts at",
|
|
4059
|
+
onStart: () => scrub.current.gesture = `time:${Date.now()}`,
|
|
4060
|
+
onEnd: () => scrub.current.gesture = null,
|
|
4061
|
+
onChange: (t) => scrubTo(layer.id, t)
|
|
4062
|
+
}
|
|
4063
|
+
),
|
|
4064
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("span", { className: "w-12 shrink-0 text-right tabular-nums text-muted-foreground", children: fmt(shown) })
|
|
4065
|
+
] }),
|
|
4066
|
+
timing.mode === "animate" && /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("label", { className: "flex items-center gap-1.5", children: [
|
|
4067
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("span", { className: "w-16 shrink-0 text-[11px] text-foreground", children: "Length" }),
|
|
4068
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
4069
|
+
"input",
|
|
4070
|
+
{
|
|
4071
|
+
type: "number",
|
|
4072
|
+
"aria-label": "Animation length in seconds",
|
|
4073
|
+
min: 0.1,
|
|
4074
|
+
max: 60,
|
|
4075
|
+
step: 0.1,
|
|
4076
|
+
defaultValue: Math.round(timing.duration / 100) / 10,
|
|
4077
|
+
className: "w-16 rounded border border-border bg-muted px-1 text-foreground",
|
|
4078
|
+
onBlur: (e) => {
|
|
4079
|
+
const s = Number(e.currentTarget.value);
|
|
4080
|
+
if (s > 0 && s * 1e3 !== timing.duration) run(() => controller.updateEffectLayer(layer.id, { animate: { duration: Math.min(60, s) * 1e3 } }));
|
|
4081
|
+
}
|
|
4082
|
+
},
|
|
4083
|
+
timing.duration
|
|
4084
|
+
),
|
|
4085
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("span", { className: "text-muted-foreground", children: [
|
|
4086
|
+
"s",
|
|
4087
|
+
timing.loops ? ` \xB7 loops every ${fmt(timing.range)}` : ""
|
|
4088
|
+
] })
|
|
4089
|
+
] })
|
|
4090
|
+
] }),
|
|
4005
4091
|
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
4006
4092
|
ImageEffectControls,
|
|
4007
4093
|
{
|
|
@@ -4015,7 +4101,12 @@ function ImageProviderEffectsPanel({ controller, className = "", components }) {
|
|
|
4015
4101
|
}
|
|
4016
4102
|
)
|
|
4017
4103
|
] }),
|
|
4018
|
-
|
|
4104
|
+
layer && canFilter && /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "flex items-center gap-1", "data-effect-part": "applied", children: [
|
|
4105
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("span", { className: "flex-1 font-semibold uppercase tracking-wider text-[11px] text-foreground", children: "Filters" }),
|
|
4106
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("button", { type: "button", className: imageOutlineButtonClass, "aria-pressed": browse === "filter", onClick: () => setBrowse(browse === "filter" ? null : "filter"), children: "Add filter\u2026" })
|
|
4107
|
+
] }),
|
|
4108
|
+
browse === "filter" && layer && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(EffectsBrowser, { provider, uses: ["filter"], title: "Filters", onPick: (e) => (setBrowse(null), run(() => controller.applyEffectFilter(layer.id, e.id))) }),
|
|
4109
|
+
filters.length > 0 && layer && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("ol", { className: "space-y-1", "data-effect-part": "filters", "aria-label": "Filters", children: filters.map((f) => {
|
|
4019
4110
|
const label = f.kind === "effect" ? f.name ?? f.effect : f.kind;
|
|
4020
4111
|
const all = layer.smartFilters.filters;
|
|
4021
4112
|
const index = all.indexOf(f);
|
|
@@ -4066,6 +4157,7 @@ function ImageProviderEffectsPanel({ controller, className = "", components }) {
|
|
|
4066
4157
|
] })
|
|
4067
4158
|
] }, f.id);
|
|
4068
4159
|
}) }),
|
|
4160
|
+
layer && canFilter && !generator && filters.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("p", { className: "text-[11px] text-muted-foreground", children: "No filters yet. A filter changes the layer's pixels and stays editable. Layer styles such as a drop shadow are in the layer's properties; new effect layers are added from the layers panel." }),
|
|
4069
4161
|
!layer && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("p", { className: "text-[11px] text-muted-foreground", children: "Select a layer to apply effects to it." }),
|
|
4070
4162
|
message && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("p", { role: "alert", className: "text-[11px] text-destructive", children: message })
|
|
4071
4163
|
] });
|
package/dist/index.cjs
CHANGED
|
@@ -5250,7 +5250,7 @@ var import_react47 = require("react");
|
|
|
5250
5250
|
var import_react46 = require("react");
|
|
5251
5251
|
var import_image_editor7 = require("@pixerate/editor/image-editor");
|
|
5252
5252
|
var import_jsx_runtime25 = require("react/jsx-runtime");
|
|
5253
|
-
var LayerEffectsPanel = ({ controller, layerId, className }) => {
|
|
5253
|
+
var LayerEffectsPanel = ({ controller, layerId, heading = true, className }) => {
|
|
5254
5254
|
const [, setTick] = (0, import_react46.useState)(0);
|
|
5255
5255
|
(0, import_react46.useEffect)(() => controller.subscribe(() => setTick((n) => n + 1)), [controller]);
|
|
5256
5256
|
const [open, setOpen] = (0, import_react46.useState)(null);
|
|
@@ -5332,9 +5332,9 @@ var LayerEffectsPanel = ({ controller, layerId, className }) => {
|
|
|
5332
5332
|
] }, c.key);
|
|
5333
5333
|
}
|
|
5334
5334
|
};
|
|
5335
|
-
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: `flex flex-col gap-1.5 text-xs text-foreground ${className ?? ""}`, "data-testid": "layer-effects", "aria-label": "Layer
|
|
5335
|
+
return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: `flex flex-col gap-1.5 text-xs text-foreground ${className ?? ""}`, "data-testid": "layer-effects", "aria-label": "Layer style", role: "group", children: [
|
|
5336
5336
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "flex flex-wrap items-center gap-2", children: [
|
|
5337
|
-
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "font-semibold text-foreground", children: "
|
|
5337
|
+
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)("span", { className: "font-semibold text-foreground", children: heading ? "Layer Style" : "Styles" }),
|
|
5338
5338
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("label", { className: "flex items-center gap-1 text-foreground", children: [
|
|
5339
5339
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(ImageCheckbox, { label: "Effects on", checked: model.enabled, disabled: model.readOnly, onChange: (on) => attempt(() => controller.setLayerEffectsEnabled(id, on)) }),
|
|
5340
5340
|
"On"
|
|
@@ -5360,12 +5360,12 @@ var LayerEffectsPanel = ({ controller, layerId, className }) => {
|
|
|
5360
5360
|
),
|
|
5361
5361
|
"%"
|
|
5362
5362
|
] }),
|
|
5363
|
-
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
5363
|
+
heading && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
5364
5364
|
ImageSelect,
|
|
5365
5365
|
{
|
|
5366
|
-
label: "Add
|
|
5366
|
+
label: "Add style",
|
|
5367
5367
|
value: "",
|
|
5368
|
-
placeholder: "Add
|
|
5368
|
+
placeholder: "Add style\u2026",
|
|
5369
5369
|
disabled: model.readOnly,
|
|
5370
5370
|
options: import_image_editor7.LAYER_EFFECT_MENU.map((m) => ({ value: m.kind, label: m.label })),
|
|
5371
5371
|
onChange: (v) => {
|
|
@@ -5830,7 +5830,7 @@ var LayersPanel = ({ controller, thumbnailSize = 32, psd = true, psdFileName = "
|
|
|
5830
5830
|
};
|
|
5831
5831
|
|
|
5832
5832
|
// src/image-editor/ImageProviderEffectsPanel.tsx
|
|
5833
|
-
var import_react57 =
|
|
5833
|
+
var import_react57 = require("react");
|
|
5834
5834
|
var import_image_editor9 = require("@pixerate/editor/image-editor");
|
|
5835
5835
|
|
|
5836
5836
|
// src/effects/useEffects.ts
|
|
@@ -7675,12 +7675,14 @@ function ImageEffectControls({ provider, effect, name, values, onChange, onPrese
|
|
|
7675
7675
|
|
|
7676
7676
|
// src/image-editor/ImageProviderEffectsPanel.tsx
|
|
7677
7677
|
var import_jsx_runtime36 = require("react/jsx-runtime");
|
|
7678
|
+
var fmt = (ms) => `${(ms / 1e3).toFixed(ms < 1e4 ? 2 : 1)} s`;
|
|
7678
7679
|
function ImageProviderEffectsPanel({ controller, className = "", components }) {
|
|
7679
7680
|
const [, setTick] = (0, import_react57.useState)(0);
|
|
7680
7681
|
(0, import_react57.useEffect)(() => controller.subscribe(() => setTick((n) => n + 1)), [controller]);
|
|
7681
7682
|
const [browse, setBrowse] = (0, import_react57.useState)(null);
|
|
7682
7683
|
const [message2, setMessage] = (0, import_react57.useState)(null);
|
|
7683
7684
|
const [open, setOpen] = (0, import_react57.useState)(null);
|
|
7685
|
+
const [scrubbed, setScrubbed] = (0, import_react57.useState)(null);
|
|
7684
7686
|
const provider = controller.effectsProvider;
|
|
7685
7687
|
const state = controller.getState();
|
|
7686
7688
|
const layer = state.activeLayerId ? (0, import_image_editor9.findLayer)(state.layers, state.activeLayerId)?.layer ?? null : null;
|
|
@@ -7688,7 +7690,7 @@ function ImageProviderEffectsPanel({ controller, className = "", components }) {
|
|
|
7688
7690
|
setMessage(null);
|
|
7689
7691
|
Promise.resolve().then(work).catch((e) => setMessage(e instanceof Error ? e.message : String(e)));
|
|
7690
7692
|
};
|
|
7691
|
-
const drags = import_react57.
|
|
7693
|
+
const drags = (0, import_react57.useRef)(/* @__PURE__ */ new Set());
|
|
7692
7694
|
const commit = (gesture) => {
|
|
7693
7695
|
if (gesture) {
|
|
7694
7696
|
if (!drags.current.has(gesture)) {
|
|
@@ -7701,21 +7703,105 @@ function ImageProviderEffectsPanel({ controller, className = "", components }) {
|
|
|
7701
7703
|
};
|
|
7702
7704
|
const filters = layer?.type === "smart" ? (layer.smartFilters?.filters ?? []).filter((f) => f.kind === "effect") : [];
|
|
7703
7705
|
const generator = layer?.type === "pixel" ? layer.generator : void 0;
|
|
7704
|
-
const canFilter = !!layer && layer.type !== "adjustment" && layer.type !== "annotation";
|
|
7705
|
-
|
|
7706
|
-
|
|
7707
|
-
|
|
7708
|
-
|
|
7709
|
-
|
|
7710
|
-
|
|
7706
|
+
const canFilter = !!provider && !!layer && layer.type !== "adjustment" && layer.type !== "annotation";
|
|
7707
|
+
const { description } = useEffectDescription(provider, generator?.effect);
|
|
7708
|
+
const timing = generator ? (0, import_image_editor9.effectLayerTiming)(generator, description) : null;
|
|
7709
|
+
const scrub = (0, import_react57.useRef)({ next: null, busy: false, gesture: null });
|
|
7710
|
+
const scrubTo = (layerId, time) => {
|
|
7711
|
+
const s = scrub.current;
|
|
7712
|
+
setScrubbed(time);
|
|
7713
|
+
s.next = { layerId, time, commit: commit(s.gesture) };
|
|
7714
|
+
if (s.busy) return;
|
|
7715
|
+
s.busy = true;
|
|
7716
|
+
const step = () => {
|
|
7717
|
+
const n = s.next;
|
|
7718
|
+
s.next = null;
|
|
7719
|
+
if (!n) return Promise.resolve();
|
|
7720
|
+
return controller.updateEffectLayer(n.layerId, { time: n.time }, n.commit).then(step);
|
|
7721
|
+
};
|
|
7722
|
+
step().catch((e) => setMessage(e instanceof Error ? e.message : String(e))).finally(() => {
|
|
7723
|
+
s.busy = false;
|
|
7724
|
+
setScrubbed(null);
|
|
7725
|
+
});
|
|
7726
|
+
};
|
|
7727
|
+
const shown = scrubbed ?? timing?.time ?? 0;
|
|
7728
|
+
return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("section", { className: `flex flex-col gap-2 text-xs ${className}`, "aria-label": "Effects", "data-image-provider-effects": "", children: [
|
|
7711
7729
|
!provider && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("p", { className: "text-[11px] text-muted-foreground", children: "No effects provider is registered. Effects in the document are kept." }),
|
|
7712
|
-
|
|
7713
|
-
browse === "layer" && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(EffectsBrowser, { provider, uses: import_image_editor9.EFFECT_LAYER_USES, title: "Generators and overlays", onPick: (e) => (setBrowse(null), run(() => controller.addEffectLayer(e.id))) }),
|
|
7714
|
-
generator && layer && /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "space-y-1", "data-effect-part": "generator", children: [
|
|
7730
|
+
generator && layer && /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "space-y-2", "data-effect-part": "generator", children: [
|
|
7715
7731
|
/* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "flex items-center gap-1", children: [
|
|
7716
|
-
/* @__PURE__ */ (0, import_jsx_runtime36.jsx)("span", { className: "flex-1 font-medium text-foreground", children: generator.name ?? generator.effect }),
|
|
7732
|
+
/* @__PURE__ */ (0, import_jsx_runtime36.jsx)("span", { className: "min-w-0 flex-1 truncate font-medium text-foreground", title: generator.name ?? generator.effect, children: generator.name ?? generator.effect }),
|
|
7733
|
+
/* @__PURE__ */ (0, import_jsx_runtime36.jsx)("button", { type: "button", className: imageOutlineButtonClass, disabled: !provider, "aria-pressed": browse === "change", onClick: () => setBrowse(browse === "change" ? null : "change"), children: "Change\u2026" }),
|
|
7717
7734
|
/* @__PURE__ */ (0, import_jsx_runtime36.jsx)("button", { type: "button", className: imageOutlineButtonClass, title: "Keep the pixels as a plain layer", onClick: () => run(() => controller.rasterizeEffectLayer(layer.id)), children: "Rasterize" })
|
|
7718
7735
|
] }),
|
|
7736
|
+
browse === "change" && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(EffectsBrowser, { provider, uses: import_image_editor9.EFFECT_LAYER_USES, title: "Change the effect to", onPick: (e) => (setBrowse(null), run(() => controller.updateEffectLayer(layer.id, { effect: e.id }))) }),
|
|
7737
|
+
timing && /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "space-y-1.5 rounded border border-border p-1.5", "data-effect-part": "timing", role: "group", "aria-label": "Frames", children: [
|
|
7738
|
+
/* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "flex gap-1", role: "radiogroup", "aria-label": "Output", children: [
|
|
7739
|
+
/* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
|
7740
|
+
"button",
|
|
7741
|
+
{
|
|
7742
|
+
type: "button",
|
|
7743
|
+
role: "radio",
|
|
7744
|
+
"aria-checked": timing.mode === "still",
|
|
7745
|
+
className: `${imageOutlineButtonClass} flex-1 ${timing.mode === "still" ? "bg-accent text-accent-foreground" : ""}`,
|
|
7746
|
+
onClick: () => run(() => controller.updateEffectLayer(layer.id, { animate: null })),
|
|
7747
|
+
children: "Still frame"
|
|
7748
|
+
}
|
|
7749
|
+
),
|
|
7750
|
+
/* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
|
7751
|
+
"button",
|
|
7752
|
+
{
|
|
7753
|
+
type: "button",
|
|
7754
|
+
role: "radio",
|
|
7755
|
+
"aria-checked": timing.mode === "animate",
|
|
7756
|
+
className: `${imageOutlineButtonClass} flex-1 ${timing.mode === "animate" ? "bg-accent text-accent-foreground" : ""}`,
|
|
7757
|
+
onClick: () => run(() => controller.updateEffectLayer(layer.id, { animate: { duration: timing.duration } })),
|
|
7758
|
+
children: "Animate"
|
|
7759
|
+
}
|
|
7760
|
+
)
|
|
7761
|
+
] }),
|
|
7762
|
+
/* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("label", { className: "flex items-center gap-1.5", children: [
|
|
7763
|
+
/* @__PURE__ */ (0, import_jsx_runtime36.jsx)("span", { className: "w-16 shrink-0 text-[11px] text-foreground", children: timing.mode === "still" ? "Frame" : "Starts at" }),
|
|
7764
|
+
/* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
|
7765
|
+
ImageRange,
|
|
7766
|
+
{
|
|
7767
|
+
min: 0,
|
|
7768
|
+
max: timing.range,
|
|
7769
|
+
step: Math.max(1, Math.round(timing.range / 200)),
|
|
7770
|
+
className: "flex-1",
|
|
7771
|
+
value: shown,
|
|
7772
|
+
label: timing.mode === "still" ? "Frame" : "Starts at",
|
|
7773
|
+
onStart: () => scrub.current.gesture = `time:${Date.now()}`,
|
|
7774
|
+
onEnd: () => scrub.current.gesture = null,
|
|
7775
|
+
onChange: (t) => scrubTo(layer.id, t)
|
|
7776
|
+
}
|
|
7777
|
+
),
|
|
7778
|
+
/* @__PURE__ */ (0, import_jsx_runtime36.jsx)("span", { className: "w-12 shrink-0 text-right tabular-nums text-muted-foreground", children: fmt(shown) })
|
|
7779
|
+
] }),
|
|
7780
|
+
timing.mode === "animate" && /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("label", { className: "flex items-center gap-1.5", children: [
|
|
7781
|
+
/* @__PURE__ */ (0, import_jsx_runtime36.jsx)("span", { className: "w-16 shrink-0 text-[11px] text-foreground", children: "Length" }),
|
|
7782
|
+
/* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
|
7783
|
+
"input",
|
|
7784
|
+
{
|
|
7785
|
+
type: "number",
|
|
7786
|
+
"aria-label": "Animation length in seconds",
|
|
7787
|
+
min: 0.1,
|
|
7788
|
+
max: 60,
|
|
7789
|
+
step: 0.1,
|
|
7790
|
+
defaultValue: Math.round(timing.duration / 100) / 10,
|
|
7791
|
+
className: "w-16 rounded border border-border bg-muted px-1 text-foreground",
|
|
7792
|
+
onBlur: (e) => {
|
|
7793
|
+
const s = Number(e.currentTarget.value);
|
|
7794
|
+
if (s > 0 && s * 1e3 !== timing.duration) run(() => controller.updateEffectLayer(layer.id, { animate: { duration: Math.min(60, s) * 1e3 } }));
|
|
7795
|
+
}
|
|
7796
|
+
},
|
|
7797
|
+
timing.duration
|
|
7798
|
+
),
|
|
7799
|
+
/* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("span", { className: "text-muted-foreground", children: [
|
|
7800
|
+
"s",
|
|
7801
|
+
timing.loops ? ` \xB7 loops every ${fmt(timing.range)}` : ""
|
|
7802
|
+
] })
|
|
7803
|
+
] })
|
|
7804
|
+
] }),
|
|
7719
7805
|
/* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
|
7720
7806
|
ImageEffectControls,
|
|
7721
7807
|
{
|
|
@@ -7729,7 +7815,12 @@ function ImageProviderEffectsPanel({ controller, className = "", components }) {
|
|
|
7729
7815
|
}
|
|
7730
7816
|
)
|
|
7731
7817
|
] }),
|
|
7732
|
-
|
|
7818
|
+
layer && canFilter && /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "flex items-center gap-1", "data-effect-part": "applied", children: [
|
|
7819
|
+
/* @__PURE__ */ (0, import_jsx_runtime36.jsx)("span", { className: "flex-1 font-semibold uppercase tracking-wider text-[11px] text-foreground", children: "Filters" }),
|
|
7820
|
+
/* @__PURE__ */ (0, import_jsx_runtime36.jsx)("button", { type: "button", className: imageOutlineButtonClass, "aria-pressed": browse === "filter", onClick: () => setBrowse(browse === "filter" ? null : "filter"), children: "Add filter\u2026" })
|
|
7821
|
+
] }),
|
|
7822
|
+
browse === "filter" && layer && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(EffectsBrowser, { provider, uses: ["filter"], title: "Filters", onPick: (e) => (setBrowse(null), run(() => controller.applyEffectFilter(layer.id, e.id))) }),
|
|
7823
|
+
filters.length > 0 && layer && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("ol", { className: "space-y-1", "data-effect-part": "filters", "aria-label": "Filters", children: filters.map((f) => {
|
|
7733
7824
|
const label = f.kind === "effect" ? f.name ?? f.effect : f.kind;
|
|
7734
7825
|
const all = layer.smartFilters.filters;
|
|
7735
7826
|
const index = all.indexOf(f);
|
|
@@ -7780,6 +7871,7 @@ function ImageProviderEffectsPanel({ controller, className = "", components }) {
|
|
|
7780
7871
|
] })
|
|
7781
7872
|
] }, f.id);
|
|
7782
7873
|
}) }),
|
|
7874
|
+
layer && canFilter && !generator && filters.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("p", { className: "text-[11px] text-muted-foreground", children: "No filters yet. A filter changes the layer's pixels and stays editable. Layer styles such as a drop shadow are in the layer's properties; new effect layers are added from the layers panel." }),
|
|
7783
7875
|
!layer && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("p", { className: "text-[11px] text-muted-foreground", children: "Select a layer to apply effects to it." }),
|
|
7784
7876
|
message2 && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("p", { role: "alert", className: "text-[11px] text-destructive", children: message2 })
|
|
7785
7877
|
] });
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixerate/editor-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.117.0",
|
|
4
4
|
"description": "React bindings and prompt/rich-text components for @pixerate/editor",
|
|
5
5
|
"author": "Pixerate",
|
|
6
6
|
"license": "MIT",
|
|
@@ -254,7 +254,7 @@
|
|
|
254
254
|
"dependencies": {},
|
|
255
255
|
"peerDependencies": {
|
|
256
256
|
"@dagrejs/dagre": "^1.1.8",
|
|
257
|
-
"@pixerate/editor": ">=0.
|
|
257
|
+
"@pixerate/editor": ">=0.178.0 <1.0.0-0",
|
|
258
258
|
"@tiptap/core": "^2.27.3",
|
|
259
259
|
"@tiptap/extension-bubble-menu": "^2.27.3",
|
|
260
260
|
"@tiptap/extension-placeholder": "^2.27.3",
|
|
@@ -305,7 +305,7 @@
|
|
|
305
305
|
"tsup": "^9.0.0",
|
|
306
306
|
"typescript": "^5.7.3",
|
|
307
307
|
"vitest": "^5.0.5",
|
|
308
|
-
"@pixerate/editor": "0.
|
|
308
|
+
"@pixerate/editor": "0.178.0"
|
|
309
309
|
},
|
|
310
310
|
"scripts": {
|
|
311
311
|
"build": "tsup && tsc -p tsconfig.build.json && node ../../scripts/finalize-declarations.mjs dist",
|