@pixerate/editor-react 0.162.0 → 0.164.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.
@@ -132,6 +132,10 @@ var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount =
132
132
  const ctx = water.current?.getContext("2d");
133
133
  if (ctx && typeof ctx.createImageData === "function") (0, import_paint_editor2.drawWaterOverlay)(controller, ctx);
134
134
  }, [state, controller]);
135
+ (0, import_react2.useEffect)(() => {
136
+ const player = controller.playEffects();
137
+ return () => player.stop();
138
+ }, [controller]);
135
139
  (0, import_react2.useEffect)(() => {
136
140
  const el = viewport.current;
137
141
  if (!el) return;
@@ -3353,6 +3357,12 @@ var PaintEffectsPanel = ({ controller, className }) => {
3353
3357
  const layerEffect = activeId ? controller.getEffectLayer(activeId) : void 0;
3354
3358
  const active = activeId ? controller.getLayer(activeId) : void 0;
3355
3359
  const effectPaint = state.effectPaint;
3360
+ const animation = controller.getAnimation();
3361
+ const playback = state.effectPlayback;
3362
+ const repaint = (patch) => {
3363
+ if (!effectPaint) return;
3364
+ run(() => controller.setEffectPaint({ effect: effectPaint.effect, values: effectPaint.values, time: effectPaint.time, map: effectPaint.map, live: effectPaint.live, ...patch }));
3365
+ };
3356
3366
  const thumbnail = (0, import_react22.useMemo)(() => effectPaint && !state.effectPaintRendering ? controller.effectPaintThumbnail(48) : null, [controller, effectPaint, state.effectPaintRendering]);
3357
3367
  const run = (work) => attempt(() => {
3358
3368
  setBusy(true);
@@ -3431,7 +3441,53 @@ var PaintEffectsPanel = ({ controller, className }) => {
3431
3441
  ] }),
3432
3442
  /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("button", { type: "button", className: button, "aria-label": "Stop painting with the effect", onClick: () => attempt(() => controller.setColor(state.color)), children: "\u2715" })
3433
3443
  ] }),
3434
- /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(Controls, { provider, effect: effectPaint.effect, values: effectPaint.values, apply: (values) => run(() => controller.setEffectPaint({ effect: effectPaint.effect, values: { ...effectPaint.values, ...values }, time: effectPaint.time })) })
3444
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: "flex flex-wrap items-center gap-2", "data-testid": "effect-paint-placement", children: [
3445
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("label", { className: "flex items-center gap-1", title: "Lay the effect along each stroke instead of fixing it to the canvas", children: [
3446
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("input", { type: "checkbox", checked: Boolean(effectPaint.map), onChange: (e) => repaint({ map: e.target.checked ? { by: "stroke", length: 300, repeat: "repeat" } : { by: "canvas" } }) }),
3447
+ "Along the stroke"
3448
+ ] }),
3449
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("label", { className: "flex items-center gap-1", title: "Strokes on a stroke layer keep playing the effect", children: [
3450
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("input", { type: "checkbox", checked: Boolean(effectPaint.live), onChange: (e) => repaint({ live: e.target.checked }) }),
3451
+ "Live"
3452
+ ] })
3453
+ ] }),
3454
+ effectPaint.map && /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: "flex flex-wrap items-center gap-2", children: [
3455
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("label", { className: "flex items-center gap-1", children: [
3456
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("span", { className: "text-slate-400", children: "Length" }),
3457
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
3458
+ "input",
3459
+ {
3460
+ type: "number",
3461
+ "aria-label": "Effect length along the stroke",
3462
+ min: 16,
3463
+ max: 4096,
3464
+ defaultValue: effectPaint.map.length,
3465
+ onBlur: (e) => Number(e.target.value) !== effectPaint.map.length && repaint({ map: { ...effectPaint.map, length: Number(e.target.value) } }),
3466
+ className: "w-16 rounded bg-slate-800 px-1 py-0.5"
3467
+ },
3468
+ effectPaint.map.length
3469
+ )
3470
+ ] }),
3471
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("select", { "aria-label": "Effect repeat", value: effectPaint.map.repeat, onChange: (e) => repaint({ map: { ...effectPaint.map, repeat: e.target.value } }), className: "rounded bg-slate-800 px-1 py-0.5", children: [
3472
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("option", { value: "repeat", children: "Repeat" }),
3473
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("option", { value: "mirror", children: "Mirror" }),
3474
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("option", { value: "clamp", children: "Clamp" })
3475
+ ] })
3476
+ ] }),
3477
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(Controls, { provider, effect: effectPaint.effect, values: effectPaint.values, apply: (values) => repaint({ values: { ...effectPaint.values, ...values } }) })
3478
+ ] }),
3479
+ animation && /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: "flex items-center gap-2 rounded border border-slate-700 p-1", "data-effect-part": "playback", children: [
3480
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("span", { className: "flex-1 truncate", children: [
3481
+ "Live paint: ",
3482
+ animation.strokes,
3483
+ " ",
3484
+ animation.strokes === 1 ? "stroke" : "strokes"
3485
+ ] }),
3486
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("button", { type: "button", className: button, "aria-pressed": playback.playing, onClick: () => attempt(() => controller.setEffectPlayback({ playing: !playback.playing })), children: playback.playing ? "Pause" : "Play" }),
3487
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("label", { className: "flex items-center gap-1", children: [
3488
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("span", { className: "text-slate-400", children: "fps" }),
3489
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("input", { type: "number", "aria-label": "Live paint frame rate", min: 1, max: 60, value: playback.fps, onChange: (e) => attempt(() => controller.setEffectPlayback({ fps: Math.round(Number(e.target.value)) })), className: "w-12 rounded bg-slate-800 px-1 py-0.5" })
3490
+ ] })
3435
3491
  ] }),
3436
3492
  layerEffect && activeId && /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: "flex flex-col gap-1 rounded border border-slate-700 p-1", "data-effect-part": "layer", children: [
3437
3493
  /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: "flex items-center gap-1", children: [
@@ -104,6 +104,10 @@ var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount =
104
104
  const ctx = water.current?.getContext("2d");
105
105
  if (ctx && typeof ctx.createImageData === "function") drawWaterOverlay(controller, ctx);
106
106
  }, [state, controller]);
107
+ useEffect2(() => {
108
+ const player = controller.playEffects();
109
+ return () => player.stop();
110
+ }, [controller]);
107
111
  useEffect2(() => {
108
112
  const el = viewport.current;
109
113
  if (!el) return;
@@ -1385,6 +1389,12 @@ var PaintEffectsPanel = ({ controller, className }) => {
1385
1389
  const layerEffect = activeId ? controller.getEffectLayer(activeId) : void 0;
1386
1390
  const active = activeId ? controller.getLayer(activeId) : void 0;
1387
1391
  const effectPaint = state.effectPaint;
1392
+ const animation = controller.getAnimation();
1393
+ const playback = state.effectPlayback;
1394
+ const repaint = (patch) => {
1395
+ if (!effectPaint) return;
1396
+ run(() => controller.setEffectPaint({ effect: effectPaint.effect, values: effectPaint.values, time: effectPaint.time, map: effectPaint.map, live: effectPaint.live, ...patch }));
1397
+ };
1388
1398
  const thumbnail = useMemo6(() => effectPaint && !state.effectPaintRendering ? controller.effectPaintThumbnail(48) : null, [controller, effectPaint, state.effectPaintRendering]);
1389
1399
  const run = (work) => attempt(() => {
1390
1400
  setBusy(true);
@@ -1463,7 +1473,53 @@ var PaintEffectsPanel = ({ controller, className }) => {
1463
1473
  ] }),
1464
1474
  /* @__PURE__ */ jsx12("button", { type: "button", className: button, "aria-label": "Stop painting with the effect", onClick: () => attempt(() => controller.setColor(state.color)), children: "\u2715" })
1465
1475
  ] }),
1466
- /* @__PURE__ */ jsx12(Controls, { provider, effect: effectPaint.effect, values: effectPaint.values, apply: (values) => run(() => controller.setEffectPaint({ effect: effectPaint.effect, values: { ...effectPaint.values, ...values }, time: effectPaint.time })) })
1476
+ /* @__PURE__ */ jsxs11("div", { className: "flex flex-wrap items-center gap-2", "data-testid": "effect-paint-placement", children: [
1477
+ /* @__PURE__ */ jsxs11("label", { className: "flex items-center gap-1", title: "Lay the effect along each stroke instead of fixing it to the canvas", children: [
1478
+ /* @__PURE__ */ jsx12("input", { type: "checkbox", checked: Boolean(effectPaint.map), onChange: (e) => repaint({ map: e.target.checked ? { by: "stroke", length: 300, repeat: "repeat" } : { by: "canvas" } }) }),
1479
+ "Along the stroke"
1480
+ ] }),
1481
+ /* @__PURE__ */ jsxs11("label", { className: "flex items-center gap-1", title: "Strokes on a stroke layer keep playing the effect", children: [
1482
+ /* @__PURE__ */ jsx12("input", { type: "checkbox", checked: Boolean(effectPaint.live), onChange: (e) => repaint({ live: e.target.checked }) }),
1483
+ "Live"
1484
+ ] })
1485
+ ] }),
1486
+ effectPaint.map && /* @__PURE__ */ jsxs11("div", { className: "flex flex-wrap items-center gap-2", children: [
1487
+ /* @__PURE__ */ jsxs11("label", { className: "flex items-center gap-1", children: [
1488
+ /* @__PURE__ */ jsx12("span", { className: "text-slate-400", children: "Length" }),
1489
+ /* @__PURE__ */ jsx12(
1490
+ "input",
1491
+ {
1492
+ type: "number",
1493
+ "aria-label": "Effect length along the stroke",
1494
+ min: 16,
1495
+ max: 4096,
1496
+ defaultValue: effectPaint.map.length,
1497
+ onBlur: (e) => Number(e.target.value) !== effectPaint.map.length && repaint({ map: { ...effectPaint.map, length: Number(e.target.value) } }),
1498
+ className: "w-16 rounded bg-slate-800 px-1 py-0.5"
1499
+ },
1500
+ effectPaint.map.length
1501
+ )
1502
+ ] }),
1503
+ /* @__PURE__ */ jsxs11("select", { "aria-label": "Effect repeat", value: effectPaint.map.repeat, onChange: (e) => repaint({ map: { ...effectPaint.map, repeat: e.target.value } }), className: "rounded bg-slate-800 px-1 py-0.5", children: [
1504
+ /* @__PURE__ */ jsx12("option", { value: "repeat", children: "Repeat" }),
1505
+ /* @__PURE__ */ jsx12("option", { value: "mirror", children: "Mirror" }),
1506
+ /* @__PURE__ */ jsx12("option", { value: "clamp", children: "Clamp" })
1507
+ ] })
1508
+ ] }),
1509
+ /* @__PURE__ */ jsx12(Controls, { provider, effect: effectPaint.effect, values: effectPaint.values, apply: (values) => repaint({ values: { ...effectPaint.values, ...values } }) })
1510
+ ] }),
1511
+ animation && /* @__PURE__ */ jsxs11("div", { className: "flex items-center gap-2 rounded border border-slate-700 p-1", "data-effect-part": "playback", children: [
1512
+ /* @__PURE__ */ jsxs11("span", { className: "flex-1 truncate", children: [
1513
+ "Live paint: ",
1514
+ animation.strokes,
1515
+ " ",
1516
+ animation.strokes === 1 ? "stroke" : "strokes"
1517
+ ] }),
1518
+ /* @__PURE__ */ jsx12("button", { type: "button", className: button, "aria-pressed": playback.playing, onClick: () => attempt(() => controller.setEffectPlayback({ playing: !playback.playing })), children: playback.playing ? "Pause" : "Play" }),
1519
+ /* @__PURE__ */ jsxs11("label", { className: "flex items-center gap-1", children: [
1520
+ /* @__PURE__ */ jsx12("span", { className: "text-slate-400", children: "fps" }),
1521
+ /* @__PURE__ */ jsx12("input", { type: "number", "aria-label": "Live paint frame rate", min: 1, max: 60, value: playback.fps, onChange: (e) => attempt(() => controller.setEffectPlayback({ fps: Math.round(Number(e.target.value)) })), className: "w-12 rounded bg-slate-800 px-1 py-0.5" })
1522
+ ] })
1467
1523
  ] }),
1468
1524
  layerEffect && activeId && /* @__PURE__ */ jsxs11("div", { className: "flex flex-col gap-1 rounded border border-slate-700 p-1", "data-effect-part": "layer", children: [
1469
1525
  /* @__PURE__ */ jsxs11("div", { className: "flex items-center gap-1", children: [
@@ -130,7 +130,16 @@ var import_react2 = require("react");
130
130
  var import_video_editor2 = require("@pixerate/editor/video-editor");
131
131
  var import_jsx_runtime = require("react/jsx-runtime");
132
132
  function VideoPreview({ controller, resolution, onFrame, className = "", style }) {
133
- const { project } = useVideoEditorState(controller);
133
+ const { project, pathDrawing } = useVideoEditorState(controller);
134
+ const gesture = (0, import_react2.useMemo)(() => new import_video_editor2.VideoPathGesture(project), [project.width, project.height]);
135
+ const [drawn, setDrawn] = (0, import_react2.useState)([]);
136
+ (0, import_react2.useEffect)(() => {
137
+ if (!pathDrawing) return;
138
+ const onKey = (e) => e.key === "Escape" && controller.cancelPathDrawing();
139
+ window.addEventListener("keydown", onKey);
140
+ return () => window.removeEventListener("keydown", onKey);
141
+ }, [controller, pathDrawing]);
142
+ const box = (el) => el.getBoundingClientRect();
134
143
  const canvas = (0, import_react2.useRef)(null);
135
144
  const frameRef = (0, import_react2.useRef)(onFrame);
136
145
  frameRef.current = onFrame;
@@ -140,7 +149,7 @@ function VideoPreview({ controller, resolution, onFrame, className = "", style }
140
149
  const engine = new import_video_editor2.VideoPreviewEngine(controller, el, { resolution, onFrame: (frame) => frameRef.current?.(frame) });
141
150
  return () => engine.destroy();
142
151
  }, [controller, resolution]);
143
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
152
+ const preview = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
144
153
  "canvas",
145
154
  {
146
155
  ref: canvas,
@@ -151,6 +160,32 @@ function VideoPreview({ controller, resolution, onFrame, className = "", style }
151
160
  "data-video-preview": ""
152
161
  }
153
162
  );
163
+ if (!pathDrawing) return preview;
164
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { position: "relative" }, children: [
165
+ preview,
166
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
167
+ "svg",
168
+ {
169
+ viewBox: `0 0 ${project.width} ${project.height}`,
170
+ style: { position: "absolute", inset: 0, width: "100%", height: "100%", cursor: "crosshair", touchAction: "none" },
171
+ role: "application",
172
+ "aria-label": "Draw the effect's path",
173
+ "data-video-path-drawing": "",
174
+ onPointerDown: (e) => {
175
+ e.currentTarget.setPointerCapture?.(e.pointerId);
176
+ gesture.down(e, box(e.currentTarget));
177
+ setDrawn([...gesture.points]);
178
+ },
179
+ onPointerMove: (e) => gesture.move(e, box(e.currentTarget)) && setDrawn([...gesture.points]),
180
+ onPointerUp: () => {
181
+ const points = gesture.up();
182
+ setDrawn([]);
183
+ if (points) void controller.finishPathDrawing(points);
184
+ },
185
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("polyline", { points: drawn.join(" "), fill: "none", stroke: "#22d3ee", strokeWidth: Math.max(2, project.width / 300), strokeLinecap: "round", strokeLinejoin: "round" })
186
+ }
187
+ )
188
+ ] });
154
189
  }
155
190
 
156
191
  // src/video-editor/VideoScopes.tsx
@@ -4102,9 +4137,25 @@ var import_react28 = require("react");
4102
4137
  // src/video-editor/VideoEffectsPanel.tsx
4103
4138
  var import_react27 = require("react");
4104
4139
  var import_video_editor12 = require("@pixerate/editor/video-editor");
4140
+ var import_effects7 = require("@pixerate/editor/effects");
4105
4141
  var import_jsx_runtime22 = require("react/jsx-runtime");
4106
4142
  var btn8 = "rounded border border-border px-1.5 py-0.5 text-[11px] disabled:opacity-40";
4107
4143
  var keyedOf = (values) => new Set(Object.entries(values ?? {}).filter(([, v]) => (0, import_video_editor12.isVideoKeyframes)(v)).map(([k]) => k));
4144
+ function PathControls({ controller, clip, instance, provider, disabled, report }) {
4145
+ const state = useVideoEditorState(controller);
4146
+ const [words, setWords] = (0, import_react27.useState)("");
4147
+ const drawing = state.pathDrawing?.clip === clip.id && state.pathDrawing.instance === instance;
4148
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: "flex flex-wrap items-center gap-1", "data-effect-part": "path", children: [
4149
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("span", { className: "text-muted-foreground", children: "Path" }),
4150
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("button", { type: "button", className: btn8, disabled, "aria-pressed": drawing, title: "Draw the path on the preview", onClick: () => drawing ? controller.cancelPathDrawing() : controller.startPathDrawing({ clip: clip.id, instance }), children: drawing ? "Drawing\u2026 (Esc)" : "Draw path" }),
4151
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("button", { type: "button", className: btn8, disabled: disabled || !clip.mask, title: clip.mask ? "Run it along this clip's mask outline" : "Give the clip a mask first", onClick: () => report(controller.setEffectPath(clip.id, instance, { mask: { clip: clip.id } })), children: "Use mask outline" }),
4152
+ provider.pathFromText && /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(import_jsx_runtime22.Fragment, { children: [
4153
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("input", { className: "w-24 rounded border border-border bg-transparent px-1 py-0.5", "aria-label": "Words to write along the path", placeholder: "Words", value: words, disabled, onChange: (e) => setWords(e.currentTarget.value) }),
4154
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("button", { type: "button", className: btn8, disabled: disabled || !words.trim(), onClick: () => report(controller.setEffectPath(clip.id, instance, { text: words })), children: "Write" })
4155
+ ] }),
4156
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("button", { type: "button", className: btn8, disabled, onClick: () => report(controller.setEffectPath(clip.id, instance, { d: "" })), children: "Clear path" })
4157
+ ] });
4158
+ }
4108
4159
  function EffectControls({
4109
4160
  provider,
4110
4161
  effect,
@@ -4112,7 +4163,8 @@ function EffectControls({
4112
4163
  values,
4113
4164
  disabled,
4114
4165
  onChange,
4115
- onPreset
4166
+ onPreset,
4167
+ path
4116
4168
  }) {
4117
4169
  const { description, error } = useEffectDescription(provider, effect);
4118
4170
  if (!provider) return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("p", { className: "text-[11px] text-muted-foreground", children: [
@@ -4122,7 +4174,10 @@ function EffectControls({
4122
4174
  ] });
4123
4175
  if (error) return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("p", { className: "text-[11px] text-amber-500", children: error });
4124
4176
  if (!description) return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("p", { className: "text-[11px] text-muted-foreground", children: "Loading\u2026" });
4125
- return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(EffectParameters, { description, values: values ?? {}, keyframed: keyedOf(values), disabled, onChange, onReset: (k) => onChange(k, description.defaults[k], null), onPreset });
4177
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(import_jsx_runtime22.Fragment, { children: [
4178
+ path && (0, import_effects7.pathControlsOf)(description).length > 0 && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(PathControls, { ...path, provider, disabled }),
4179
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(EffectParameters, { description, values: values ?? {}, keyframed: keyedOf(values), disabled, onChange, onReset: (k) => onChange(k, description.defaults[k], null), onPreset })
4180
+ ] });
4126
4181
  }
4127
4182
  function VideoEffectsPanel({ controller, className = "" }) {
4128
4183
  const state = useVideoEditorState(controller);
@@ -4163,7 +4218,8 @@ function VideoEffectsPanel({ controller, className = "" }) {
4163
4218
  values: clip.values,
4164
4219
  disabled,
4165
4220
  onChange: (k, v, gesture) => report(controller.updateEffectValues(clip.id, "generator", { [k]: v }, { merge: gesture ?? void 0 })),
4166
- onPreset: (values) => report(controller.updateEffectValues(clip.id, "generator", values))
4221
+ onPreset: (values) => report(controller.updateEffectValues(clip.id, "generator", values)),
4222
+ path: { controller, clip, instance: "generator", report }
4167
4223
  }
4168
4224
  )
4169
4225
  ] }),
@@ -4243,7 +4299,8 @@ function VideoEffectsPanel({ controller, className = "" }) {
4243
4299
  values: e.values,
4244
4300
  disabled,
4245
4301
  onChange: (k, v, gesture) => report(controller.updateClipEffect(clip.id, e.id, { values: { [k]: v } }, { merge: gesture ?? void 0 })),
4246
- onPreset: (values) => report(controller.updateClipEffect(clip.id, e.id, { values }))
4302
+ onPreset: (values) => report(controller.updateClipEffect(clip.id, e.id, { values })),
4303
+ path: { controller, clip, instance: e.id, report }
4247
4304
  }
4248
4305
  )
4249
4306
  ] })