@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.
@@ -0,0 +1,655 @@
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({
147
+ description,
148
+ values,
149
+ onChange,
150
+ onReset,
151
+ keyframed,
152
+ onPreset,
153
+ onPresetName,
154
+ renderControlAddon,
155
+ disabled = false,
156
+ className = ""
157
+ }) {
158
+ const fields = useMemo2(() => effectParameterFields(description), [description]);
159
+ const idBase = useId();
160
+ const gesture = React3.useRef(null);
161
+ const count = React3.useRef(0);
162
+ return /* @__PURE__ */ jsxs2("div", { className: `space-y-2 ${className}`, "data-effect-parameters": description.id, children: [
163
+ (onPreset || onPresetName) && description.presets.length > 0 && /* @__PURE__ */ jsxs2(
164
+ "select",
165
+ {
166
+ className: "w-full rounded border border-border bg-transparent px-1 py-0.5 text-xs",
167
+ "aria-label": `${description.name} presets`,
168
+ value: "",
169
+ disabled,
170
+ onChange: (e) => {
171
+ const name = e.currentTarget.value;
172
+ if (!name) return;
173
+ if (onPresetName) {
174
+ onPresetName(name);
175
+ } else if (onPreset) {
176
+ const preset = description.presets.find((p) => p.name === name);
177
+ if (preset) onPreset({ ...description.defaults, ...preset.values });
178
+ }
179
+ },
180
+ children: [
181
+ /* @__PURE__ */ jsx3("option", { value: "", children: "Presets\u2026" }),
182
+ description.presets.map((p) => /* @__PURE__ */ jsx3("option", { value: p.name, children: p.name }, p.name))
183
+ ]
184
+ }
185
+ ),
186
+ fields.map((field) => {
187
+ const label = parameterLabel(field);
188
+ const inputId = `${idBase}-${field.id}`;
189
+ const keyed = keyframed?.has(field.id) ?? false;
190
+ const value = effectFieldValue(field, values[field.id]);
191
+ const changed = !keyed && !parameterValuesEqual(value, field.default);
192
+ return /* @__PURE__ */ jsxs2("div", { className: "space-y-1", "data-effect-control": field.id, children: [
193
+ /* @__PURE__ */ jsxs2("div", { className: "flex items-center gap-1.5", children: [
194
+ /* @__PURE__ */ jsx3("label", { htmlFor: inputId, className: "min-w-0 flex-1 truncate text-xs font-medium", title: field.description, children: label }),
195
+ keyed && /* @__PURE__ */ jsx3("span", { className: "text-[10px] text-muted-foreground", children: "keyframed" }),
196
+ renderControlAddon?.(field.id),
197
+ 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" })
198
+ ] }),
199
+ /* @__PURE__ */ jsx3(
200
+ ParameterFieldControl,
201
+ {
202
+ field,
203
+ value,
204
+ id: inputId,
205
+ disabled: disabled || keyed,
206
+ onChange: (v) => onChange(field.id, v, gesture.current),
207
+ onGestureStart: () => gesture.current = `${idBase}:${field.id}:${++count.current}`,
208
+ onGestureEnd: () => gesture.current = null
209
+ }
210
+ )
211
+ ] }, field.id);
212
+ }),
213
+ !fields.length && /* @__PURE__ */ jsx3("p", { className: "text-[11px] text-muted-foreground", children: "No controls." })
214
+ ] });
215
+ }
216
+
217
+ // src/effects/useEffectAuthoring.ts
218
+ import { useSyncExternalStore } from "react";
219
+ function useEffectAuthoring(session) {
220
+ return useSyncExternalStore(
221
+ (callback) => {
222
+ if (!session) return () => {
223
+ };
224
+ return session.subscribe(callback);
225
+ },
226
+ () => session ? session.getState() : null,
227
+ () => null
228
+ );
229
+ }
230
+
231
+ // src/effects/EffectAuthoringEditor.tsx
232
+ import { useCallback, useEffect as useEffect4, useRef as useRef2, useState as useState4 } from "react";
233
+ import { effectSampleInputs } from "@pixerate/editor/effects";
234
+ import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
235
+ function EffectAuthoringEditor({
236
+ session,
237
+ showSource = true,
238
+ showTimeline = true,
239
+ previewSize = { width: 480, height: 270 },
240
+ className = ""
241
+ }) {
242
+ const state = useEffectAuthoring(session);
243
+ const canvasRef = useRef2(null);
244
+ const rendererRef = useRef2(null);
245
+ const [rendererReady, setRendererReady] = useState4(0);
246
+ const renderingRef = useRef2(false);
247
+ const pendingRef = useRef2(false);
248
+ const timeRef = useRef2(0);
249
+ const inputsRef = useRef2({});
250
+ const [savingPreset, setSavingPreset] = useState4(false);
251
+ const [presetName, setPresetName] = useState4("");
252
+ const textareaRef = useRef2(null);
253
+ const gutterRef = useRef2(null);
254
+ const [sourceCode, setSourceCode] = useState4("");
255
+ const sourceDebounceRef = useRef2(null);
256
+ useEffect4(() => {
257
+ if (!session) {
258
+ if (rendererRef.current) {
259
+ rendererRef.current.dispose();
260
+ rendererRef.current = null;
261
+ }
262
+ return;
263
+ }
264
+ let live = true;
265
+ let createdRenderer = null;
266
+ Promise.resolve(session.createPreview(previewSize)).then((renderer) => {
267
+ if (!live) {
268
+ renderer.dispose();
269
+ return;
270
+ }
271
+ createdRenderer = renderer;
272
+ rendererRef.current = renderer;
273
+ setRendererReady((c) => c + 1);
274
+ });
275
+ return () => {
276
+ live = false;
277
+ if (createdRenderer) {
278
+ createdRenderer.dispose();
279
+ }
280
+ if (rendererRef.current === createdRenderer) {
281
+ rendererRef.current = null;
282
+ }
283
+ };
284
+ }, [session, previewSize.width, previewSize.height]);
285
+ const pump = useCallback(async () => {
286
+ if (renderingRef.current) {
287
+ pendingRef.current = true;
288
+ return;
289
+ }
290
+ renderingRef.current = true;
291
+ try {
292
+ do {
293
+ pendingRef.current = false;
294
+ const renderer = rendererRef.current;
295
+ if (!renderer) break;
296
+ try {
297
+ const pixels = await renderer.render({ time: timeRef.current, inputs: inputsRef.current });
298
+ const ctx = rendererRef.current === renderer ? canvasRef.current?.getContext("2d") : null;
299
+ if (ctx && typeof ImageData !== "undefined") {
300
+ ctx.putImageData(new ImageData(new Uint8ClampedArray(pixels.data), pixels.width, pixels.height), 0, 0);
301
+ }
302
+ } catch {
303
+ }
304
+ } while (pendingRef.current);
305
+ } finally {
306
+ renderingRef.current = false;
307
+ }
308
+ }, []);
309
+ const inputSpecs = state?.description.inputs;
310
+ useEffect4(() => {
311
+ inputsRef.current = inputSpecs ? effectSampleInputs({ inputs: inputSpecs }, previewSize) : {};
312
+ }, [inputSpecs, previewSize.width, previewSize.height]);
313
+ useEffect4(() => {
314
+ if (!state) return;
315
+ timeRef.current = state.time;
316
+ void pump();
317
+ }, [state, rendererReady, pump]);
318
+ useEffect4(() => {
319
+ if (state?.source !== null && state?.source !== void 0) {
320
+ setSourceCode(state.source);
321
+ }
322
+ }, [state?.source]);
323
+ useEffect4(() => {
324
+ return () => {
325
+ if (sourceDebounceRef.current) clearTimeout(sourceDebounceRef.current);
326
+ };
327
+ }, []);
328
+ if (!session || !state) {
329
+ return /* @__PURE__ */ jsx4("div", { className: `p-4 text-center text-xs text-muted-foreground ${className}`, children: "No effect authoring session is open." });
330
+ }
331
+ const hasSource = showSource && state.sourceLanguage !== null && typeof session.setSource === "function";
332
+ const handleSourceChange = (e) => {
333
+ const val = e.target.value;
334
+ setSourceCode(val);
335
+ if (sourceDebounceRef.current) clearTimeout(sourceDebounceRef.current);
336
+ sourceDebounceRef.current = setTimeout(() => {
337
+ session.setSource?.(val);
338
+ }, 300);
339
+ };
340
+ const handleSavePreset = (e) => {
341
+ e.preventDefault();
342
+ const trimmed = presetName.trim();
343
+ if (trimmed) {
344
+ session.savePreset(trimmed);
345
+ setSavingPreset(false);
346
+ setPresetName("");
347
+ }
348
+ };
349
+ const jumpToLine = (lineNum) => {
350
+ if (!textareaRef.current) return;
351
+ const lines = sourceCode.split("\n");
352
+ let offset = 0;
353
+ for (let i = 0; i < lineNum - 1 && i < lines.length; i++) {
354
+ offset += lines[i].length + 1;
355
+ }
356
+ textareaRef.current.focus();
357
+ textareaRef.current.setSelectionRange(offset, offset);
358
+ };
359
+ const sourceLines = sourceCode.split("\n");
360
+ const issueLines = new Set(
361
+ state.issues.map((i) => i.line).filter((l) => typeof l === "number")
362
+ );
363
+ return /* @__PURE__ */ jsxs3("div", { className: `space-y-4 rounded border border-border bg-background p-4 text-foreground ${className}`, "data-effect-authoring-editor": state.name, children: [
364
+ /* @__PURE__ */ jsxs3("div", { className: "flex flex-wrap items-center justify-between gap-2 border-b border-border pb-3", children: [
365
+ /* @__PURE__ */ jsxs3("div", { className: "flex items-center gap-2", children: [
366
+ /* @__PURE__ */ jsx4(
367
+ "button",
368
+ {
369
+ type: "button",
370
+ className: "rounded border border-border px-2.5 py-1 text-xs font-medium hover:bg-muted",
371
+ "aria-label": state.playing ? "Pause playback" : "Start playback",
372
+ onClick: () => state.playing ? session.pause() : session.play(),
373
+ children: state.playing ? "Pause" : "Play"
374
+ }
375
+ ),
376
+ /* @__PURE__ */ jsxs3("span", { className: "font-mono text-xs text-muted-foreground", "data-time-readout": true, children: [
377
+ state.time,
378
+ "ms / ",
379
+ state.duration,
380
+ "ms"
381
+ ] })
382
+ ] }),
383
+ /* @__PURE__ */ jsxs3("div", { className: "flex items-center gap-2", children: [
384
+ /* @__PURE__ */ jsx4(
385
+ "button",
386
+ {
387
+ type: "button",
388
+ className: "rounded border border-border px-2 py-1 text-xs disabled:opacity-40 hover:bg-muted",
389
+ "aria-label": "Undo",
390
+ disabled: !state.canUndo,
391
+ onClick: () => session.undo(),
392
+ children: "Undo"
393
+ }
394
+ ),
395
+ /* @__PURE__ */ jsx4(
396
+ "button",
397
+ {
398
+ type: "button",
399
+ className: "rounded border border-border px-2 py-1 text-xs disabled:opacity-40 hover:bg-muted",
400
+ "aria-label": "Redo",
401
+ disabled: !state.canRedo,
402
+ onClick: () => session.redo(),
403
+ children: "Redo"
404
+ }
405
+ ),
406
+ savingPreset ? /* @__PURE__ */ jsxs3("form", { onSubmit: handleSavePreset, className: "flex items-center gap-1", children: [
407
+ /* @__PURE__ */ jsx4(
408
+ "input",
409
+ {
410
+ type: "text",
411
+ className: "rounded border border-border bg-background px-1.5 py-0.5 text-xs",
412
+ placeholder: "Preset name",
413
+ autoFocus: true,
414
+ value: presetName,
415
+ onChange: (e) => setPresetName(e.target.value)
416
+ }
417
+ ),
418
+ /* @__PURE__ */ jsx4(
419
+ "button",
420
+ {
421
+ type: "submit",
422
+ className: "rounded bg-primary px-2 py-0.5 text-xs text-primary-foreground",
423
+ children: "Save"
424
+ }
425
+ ),
426
+ /* @__PURE__ */ jsx4(
427
+ "button",
428
+ {
429
+ type: "button",
430
+ className: "rounded border border-border px-1.5 py-0.5 text-xs hover:bg-muted",
431
+ onClick: () => setSavingPreset(false),
432
+ children: "Cancel"
433
+ }
434
+ )
435
+ ] }) : /* @__PURE__ */ jsx4(
436
+ "button",
437
+ {
438
+ type: "button",
439
+ className: "rounded border border-border px-2 py-1 text-xs hover:bg-muted",
440
+ onClick: () => setSavingPreset(true),
441
+ children: "Save preset\u2026"
442
+ }
443
+ )
444
+ ] })
445
+ ] }),
446
+ /* @__PURE__ */ jsxs3("div", { className: "grid grid-cols-1 gap-4 lg:grid-cols-2", children: [
447
+ /* @__PURE__ */ jsxs3("div", { className: "space-y-2", children: [
448
+ /* @__PURE__ */ jsx4("div", { className: "text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: "Preview" }),
449
+ /* @__PURE__ */ jsx4("div", { className: "relative flex aspect-video w-full items-center justify-center overflow-hidden rounded border border-border bg-black", children: /* @__PURE__ */ jsx4(
450
+ "canvas",
451
+ {
452
+ ref: canvasRef,
453
+ width: previewSize.width,
454
+ height: previewSize.height,
455
+ className: "h-full w-full object-contain",
456
+ "aria-label": "Effect preview canvas"
457
+ }
458
+ ) }),
459
+ state.issues.length > 0 && /* @__PURE__ */ jsx4("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__ */ jsxs3(
460
+ "div",
461
+ {
462
+ className: `cursor-pointer ${issue.severity === "error" ? "text-destructive" : "text-amber-500"}`,
463
+ onClick: () => issue.line !== void 0 && jumpToLine(issue.line),
464
+ children: [
465
+ issue.line !== void 0 ? `Line ${issue.line}: ` : "",
466
+ issue.message
467
+ ]
468
+ },
469
+ idx
470
+ )) })
471
+ ] }),
472
+ hasSource && /* @__PURE__ */ jsxs3("div", { className: "space-y-2", "data-effect-source-pane": true, children: [
473
+ /* @__PURE__ */ jsx4("div", { className: "flex items-center justify-between text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: /* @__PURE__ */ jsxs3("span", { children: [
474
+ "Source (",
475
+ state.sourceLanguage,
476
+ ")"
477
+ ] }) }),
478
+ /* @__PURE__ */ jsxs3("div", { className: "flex h-64 rounded border border-border bg-muted/20 font-mono text-xs", children: [
479
+ /* @__PURE__ */ jsx4("div", { ref: gutterRef, className: "select-none overflow-hidden border-r border-border bg-muted/40 px-2 py-2 text-right text-muted-foreground", "aria-hidden": "true", children: sourceLines.map((_, i) => {
480
+ const lineNum = i + 1;
481
+ const hasIssue = issueLines.has(lineNum);
482
+ return /* @__PURE__ */ jsx4(
483
+ "div",
484
+ {
485
+ "data-gutter-line": lineNum,
486
+ className: hasIssue ? "font-bold text-destructive" : "",
487
+ children: lineNum
488
+ },
489
+ i
490
+ );
491
+ }) }),
492
+ /* @__PURE__ */ jsx4(
493
+ "textarea",
494
+ {
495
+ ref: textareaRef,
496
+ value: sourceCode,
497
+ onChange: handleSourceChange,
498
+ onScroll: (e) => {
499
+ if (gutterRef.current) gutterRef.current.scrollTop = e.currentTarget.scrollTop;
500
+ },
501
+ "aria-label": "Effect source code",
502
+ spellCheck: false,
503
+ wrap: "off",
504
+ className: "flex-1 resize-none bg-transparent p-2 font-mono text-xs text-foreground focus:outline-none"
505
+ }
506
+ )
507
+ ] })
508
+ ] })
509
+ ] }),
510
+ /* @__PURE__ */ jsxs3("div", { className: "space-y-2 border-t border-border pt-4", children: [
511
+ /* @__PURE__ */ jsx4("div", { className: "text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: "Parameters" }),
512
+ /* @__PURE__ */ jsx4(
513
+ EffectParameters,
514
+ {
515
+ description: state.description,
516
+ values: state.values,
517
+ onChange: (control, val, gesture) => session.setValue(control, val, { gesture }),
518
+ onReset: (control) => session.resetValues([control]),
519
+ onPresetName: (name) => session.applyPreset(name),
520
+ renderControlAddon: (control) => {
521
+ const track = state.tracks[control];
522
+ const isAnimated = Boolean(track && track.length > 0);
523
+ const hasKeyframeAtPlayhead = isAnimated && track.some((kf) => kf.time === state.time);
524
+ return /* @__PURE__ */ jsx4(
525
+ "button",
526
+ {
527
+ type: "button",
528
+ "data-keyframe-toggle": control,
529
+ "aria-label": hasKeyframeAtPlayhead ? `Remove keyframe for ${control}` : `Add keyframe for ${control}`,
530
+ onClick: () => {
531
+ if (hasKeyframeAtPlayhead) {
532
+ session.removeKeyframe(control, state.time);
533
+ } else {
534
+ session.setKeyframe(control, state.time);
535
+ }
536
+ },
537
+ className: `rounded px-1 text-xs transition-colors ${hasKeyframeAtPlayhead ? "text-primary font-bold" : isAnimated ? "text-foreground" : "text-muted-foreground hover:text-foreground"}`,
538
+ title: hasKeyframeAtPlayhead ? "Remove keyframe at playhead" : "Add keyframe at playhead",
539
+ children: hasKeyframeAtPlayhead ? "\u25C6" : "\u25C7"
540
+ }
541
+ );
542
+ }
543
+ }
544
+ )
545
+ ] }),
546
+ showTimeline && /* @__PURE__ */ jsxs3("div", { className: "space-y-3 border-t border-border pt-4", "data-effect-timeline": true, children: [
547
+ /* @__PURE__ */ jsxs3("div", { className: "flex flex-wrap items-center justify-between gap-4", children: [
548
+ /* @__PURE__ */ jsx4("div", { className: "text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: "Timeline" }),
549
+ /* @__PURE__ */ jsxs3("div", { className: "flex items-center gap-3 text-xs", children: [
550
+ /* @__PURE__ */ jsxs3("label", { className: "flex items-center gap-1.5", children: [
551
+ /* @__PURE__ */ jsx4("span", { children: "Duration:" }),
552
+ /* @__PURE__ */ jsx4(DurationField, { duration: state.duration, onCommit: (duration) => session.setTiming({ duration }) }),
553
+ /* @__PURE__ */ jsx4("span", { className: "text-muted-foreground", children: "ms" })
554
+ ] }),
555
+ /* @__PURE__ */ jsxs3("label", { className: "flex items-center gap-1.5 cursor-pointer", children: [
556
+ /* @__PURE__ */ jsx4(
557
+ "input",
558
+ {
559
+ type: "checkbox",
560
+ "aria-label": "Loop playback",
561
+ checked: state.loop,
562
+ onChange: (e) => session.setTiming({ loop: e.target.checked })
563
+ }
564
+ ),
565
+ /* @__PURE__ */ jsx4("span", { children: "Loop" })
566
+ ] })
567
+ ] })
568
+ ] }),
569
+ /* @__PURE__ */ jsx4("div", { className: "space-y-1", children: /* @__PURE__ */ jsx4(
570
+ "input",
571
+ {
572
+ type: "range",
573
+ "aria-label": "Timeline scrubber",
574
+ min: 0,
575
+ max: state.duration,
576
+ value: state.time,
577
+ onChange: (e) => session.seek(Number(e.target.value)),
578
+ className: "w-full cursor-pointer accent-primary"
579
+ }
580
+ ) }),
581
+ Object.entries(state.tracks).length > 0 && /* @__PURE__ */ jsx4("div", { className: "space-y-2 pt-1", children: Object.entries(state.tracks).map(([control, keyframes]) => {
582
+ if (!keyframes || keyframes.length === 0) return null;
583
+ return /* @__PURE__ */ jsxs3("div", { className: "space-y-1", "data-track": control, children: [
584
+ /* @__PURE__ */ jsxs3("div", { className: "flex items-center justify-between text-xs text-muted-foreground", children: [
585
+ /* @__PURE__ */ jsx4("span", { className: "font-medium", children: control }),
586
+ /* @__PURE__ */ jsx4(
587
+ "button",
588
+ {
589
+ type: "button",
590
+ className: "text-[11px] hover:text-foreground",
591
+ onClick: () => session.clearTrack(control),
592
+ "aria-label": `Clear animation track for ${control}`,
593
+ children: "Clear track"
594
+ }
595
+ )
596
+ ] }),
597
+ /* @__PURE__ */ jsx4("div", { className: "relative h-4 w-full rounded bg-muted/40", children: keyframes.map((kf, i) => {
598
+ const leftPct = Math.max(
599
+ 0,
600
+ Math.min(100, kf.time / (state.duration || 1) * 100)
601
+ );
602
+ return /* @__PURE__ */ jsx4(
603
+ "button",
604
+ {
605
+ type: "button",
606
+ onClick: () => session.seek(kf.time),
607
+ "aria-label": `Seek to ${control} keyframe at ${kf.time}ms`,
608
+ title: `${control} @ ${kf.time}ms`,
609
+ style: { left: `${leftPct}%` },
610
+ className: "absolute top-1/2 -translate-x-1/2 -translate-y-1/2 text-[10px] text-primary hover:scale-125",
611
+ children: "\u25C6"
612
+ },
613
+ i
614
+ );
615
+ }) })
616
+ ] }, control);
617
+ }) })
618
+ ] })
619
+ ] });
620
+ }
621
+ function DurationField({ duration, onCommit }) {
622
+ const [draft, setDraft] = useState4(String(duration));
623
+ useEffect4(() => setDraft(String(duration)), [duration]);
624
+ const commit = () => {
625
+ const next = Number(draft);
626
+ if (Number.isFinite(next) && next >= 1 && next !== duration) onCommit(next);
627
+ else setDraft(String(duration));
628
+ };
629
+ return /* @__PURE__ */ jsx4(
630
+ "input",
631
+ {
632
+ type: "number",
633
+ "aria-label": "Duration",
634
+ min: 1,
635
+ value: draft,
636
+ onChange: (e) => setDraft(e.target.value),
637
+ onBlur: commit,
638
+ onKeyDown: (e) => {
639
+ if (e.key === "Enter") commit();
640
+ else if (e.key === "Escape") setDraft(String(duration));
641
+ },
642
+ className: "w-16 rounded border border-border bg-background px-1.5 py-0.5 text-xs font-mono"
643
+ }
644
+ );
645
+ }
646
+
647
+ export {
648
+ useEffects,
649
+ useEffectDescription,
650
+ EffectThumbnail,
651
+ EffectsBrowser,
652
+ EffectParameters,
653
+ useEffectAuthoring,
654
+ EffectAuthoringEditor
655
+ };
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import { type EffectAuthoringSession } from '@pixerate/editor/effects';
3
+ export interface EffectAuthoringEditorProps {
4
+ /** The effect authoring session to edit. */
5
+ session: EffectAuthoringSession | null;
6
+ /** Whether to show the source code editor pane when supported (default true). */
7
+ showSource?: boolean;
8
+ /** Whether to show the keyframe timeline below parameters (default true). */
9
+ showTimeline?: boolean;
10
+ /** Size of the preview canvas (default 480 × 270). */
11
+ previewSize?: {
12
+ width: number;
13
+ height: number;
14
+ };
15
+ /** Additional CSS class names. */
16
+ className?: string;
17
+ }
18
+ /**
19
+ * Visual effect authoring editor: preview canvas, source code pane with line gutter,
20
+ * parameter controls with keyframe toggles, and keyframe timeline.
21
+ */
22
+ export declare function EffectAuthoringEditor({ session, showSource, showTimeline, previewSize, className }: EffectAuthoringEditorProps): React.JSX.Element;