@aicut/react 0.4.2 → 0.5.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/README.md +98 -2
- package/dist/index.cjs +35 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -2
- package/dist/index.d.ts +26 -2
- package/dist/index.js +40 -3
- package/dist/index.js.map +1 -1
- package/dist/webcodecs.cjs +35 -0
- package/dist/webcodecs.cjs.map +1 -0
- package/dist/webcodecs.d.cts +1 -0
- package/dist/webcodecs.d.ts +1 -0
- package/dist/webcodecs.js +12 -0
- package/dist/webcodecs.js.map +1 -0
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -69,9 +69,23 @@ interface VideoEditorProps {
|
|
|
69
69
|
theme?: Theme; // CSS-var overrides; reactive
|
|
70
70
|
locale?: Partial<Locale>; // EN default; pass localeZh for ZH
|
|
71
71
|
|
|
72
|
+
headerLeft?: ReactNode; // optional header row above
|
|
73
|
+
headerRight?: ReactNode; // the preview — collapses
|
|
74
|
+
// when both are empty
|
|
72
75
|
toolbarLeft?: ReactNode; // host controls — left bookend
|
|
73
76
|
toolbarRight?: ReactNode; // right bookend
|
|
74
77
|
|
|
78
|
+
playbackEngine?: PlaybackEngineFactory; // pluggable playback; default
|
|
79
|
+
// HtmlVideoEngine. Bound at
|
|
80
|
+
// mount — change + remount
|
|
81
|
+
// via `key` to re-apply.
|
|
82
|
+
timelineHeight?: number; // outer height of the bottom
|
|
83
|
+
// timeline area (default 240).
|
|
84
|
+
// Reactive; no remount needed.
|
|
85
|
+
trackHeight?: number; // per-row height (default 56).
|
|
86
|
+
// Initial-only; process-wide.
|
|
87
|
+
rulerHeight?: number; // time-label strip (default 24).
|
|
88
|
+
|
|
75
89
|
apiRef?: Ref<VideoEditorApi | null>;
|
|
76
90
|
|
|
77
91
|
onReady?: (api: VideoEditorApi) => void;
|
|
@@ -90,9 +104,24 @@ interface VideoEditorProps {
|
|
|
90
104
|
|
|
91
105
|
The `apiRef` value exposes the full **`EditorApi`** — `play`, `pause`, `seek`, `split`, `trimLeft`, `trimRight`, `setProject`, `getProject`, `addSource`, `addTrack`, `removeClip`, `undo`, `redo`, `setTheme`, `setLocale`, `requestExport`, and more. See [@aicut/core](https://www.npmjs.com/package/@aicut/core) for the complete surface.
|
|
92
106
|
|
|
93
|
-
## Custom toolbar
|
|
107
|
+
## Custom slots (header + toolbar)
|
|
94
108
|
|
|
95
|
-
The editor
|
|
109
|
+
The editor reserves **four** host-fillable slots — all empty by default with no chrome cost. The optional header above the preview auto-collapses when both header slots are empty, so the default layout is byte-for-byte identical to before they existed.
|
|
110
|
+
|
|
111
|
+
```tsx
|
|
112
|
+
<VideoEditor
|
|
113
|
+
// Header row above the preview — invisible when both null
|
|
114
|
+
headerLeft={<strong>Untitled project</strong>}
|
|
115
|
+
headerRight={
|
|
116
|
+
<>
|
|
117
|
+
<button onClick={share}>Share</button>
|
|
118
|
+
<button onClick={() => apiRef.current?.requestExport()}>Export</button>
|
|
119
|
+
</>
|
|
120
|
+
}
|
|
121
|
+
/>
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Toolbar bookends
|
|
96
125
|
|
|
97
126
|
```tsx
|
|
98
127
|
<VideoEditor
|
|
@@ -145,6 +174,73 @@ import { VideoEditor, localeZh } from "@aicut/react";
|
|
|
145
174
|
|
|
146
175
|
`locale` is reactive too — runtime swap re-titles the toolbar and re-paints canvas labels in place.
|
|
147
176
|
|
|
177
|
+
## Compact viewports
|
|
178
|
+
|
|
179
|
+
Default chrome is sized for desktop. For laptop side panels or embedded editors, shrink the bottom area to reclaim preview height:
|
|
180
|
+
|
|
181
|
+
```tsx
|
|
182
|
+
const [timelineHeight, setTimelineHeight] = useState(160);
|
|
183
|
+
|
|
184
|
+
<VideoEditor
|
|
185
|
+
defaultProject={project}
|
|
186
|
+
timelineHeight={timelineHeight} // reactive — drag a slider, the
|
|
187
|
+
// editor recompacts in place
|
|
188
|
+
trackHeight={40} // initial-only; needs remount to
|
|
189
|
+
// change (key={trackHeight})
|
|
190
|
+
/>
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Range guidance: `timelineHeight` ∈ [120, 480], `trackHeight` ∈ [28, 96], `rulerHeight` ∈ [18, 36]. The internal canvas scrolls vertically when tracks overflow.
|
|
194
|
+
|
|
195
|
+
## Custom playback engine
|
|
196
|
+
|
|
197
|
+
The editor talks to playback through a single interface. The default is
|
|
198
|
+
`HtmlVideoEngine` (one hidden `<video>` per source, swap on clip
|
|
199
|
+
boundaries). To plug in a different one — WebCodecs, WebGL compositor,
|
|
200
|
+
desktop-wrapper IPC bridge — pass a factory:
|
|
201
|
+
|
|
202
|
+
```tsx
|
|
203
|
+
import {
|
|
204
|
+
VideoEditor,
|
|
205
|
+
type PlaybackEngineFactory,
|
|
206
|
+
} from "@aicut/react";
|
|
207
|
+
|
|
208
|
+
const myEngine: PlaybackEngineFactory = ({ host, project }) =>
|
|
209
|
+
new MyCustomEngine(host, project); // implements PlaybackEngine
|
|
210
|
+
|
|
211
|
+
<VideoEditor
|
|
212
|
+
defaultProject={project}
|
|
213
|
+
playbackEngine={myEngine} // initial-only — bound at mount
|
|
214
|
+
/* … */
|
|
215
|
+
/>
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
`PlaybackEngine`, `PlaybackEngineFactory`, `PlaybackEngineOptions`, and
|
|
219
|
+
the built-in `HtmlVideoEngine` are re-exported from `@aicut/react` so
|
|
220
|
+
you don't need a separate `@aicut/core` import to write one.
|
|
221
|
+
|
|
222
|
+
See [@aicut/core's playback section](https://www.npmjs.com/package/@aicut/core#playback-engine)
|
|
223
|
+
for the full interface contract.
|
|
224
|
+
|
|
225
|
+
### WebCodecs engine (opt-in sub-entry)
|
|
226
|
+
|
|
227
|
+
For frame-accurate playback via the browser's `VideoDecoder` API, import from the sub-entry so mp4box.js (~200 KB) only loads when you ask for it:
|
|
228
|
+
|
|
229
|
+
```tsx
|
|
230
|
+
import {
|
|
231
|
+
WebCodecsEngine,
|
|
232
|
+
isWebCodecsSupported,
|
|
233
|
+
} from "@aicut/react/webcodecs";
|
|
234
|
+
|
|
235
|
+
const factory = isWebCodecsSupported()
|
|
236
|
+
? (opts) => new WebCodecsEngine({ ...opts, debug: true })
|
|
237
|
+
: undefined; // VideoEditor falls back to HtmlVideoEngine when undefined
|
|
238
|
+
|
|
239
|
+
<VideoEditor playbackEngine={factory} /* … */ />;
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
`WebCodecsEngine` v1 covers single-track MP4/MOV playback (H.264 / HEVC / VP9 / AV1 — whatever the browser's `VideoDecoder` supports). Multi-track compositing, audio, transitions land in follow-up releases.
|
|
243
|
+
|
|
148
244
|
## `<LightingEditor>` (opt-in sub-entry)
|
|
149
245
|
|
|
150
246
|
A 3D lighting director for AI relighting flows — separate component that doesn't pull three.js into the rest of your bundle.
|
package/dist/index.cjs
CHANGED
|
@@ -20,12 +20,20 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
CanvasCompositorEngine: () => import_core3.CanvasCompositorEngine,
|
|
24
|
+
HEADER_WIDTH: () => import_core3.HEADER_WIDTH,
|
|
25
|
+
HtmlVideoEngine: () => import_core3.HtmlVideoEngine,
|
|
26
|
+
RULER_HEIGHT: () => import_core3.RULER_HEIGHT,
|
|
27
|
+
TRACK_HEIGHT: () => import_core3.TRACK_HEIGHT,
|
|
23
28
|
Timeline: () => Timeline,
|
|
24
29
|
VideoEditor: () => VideoEditor,
|
|
30
|
+
canvasCompositorEngineFactory: () => import_core3.canvasCompositorEngineFactory,
|
|
25
31
|
createEmptyProject: () => import_core3.createEmptyProject,
|
|
26
32
|
createId: () => import_core3.createId,
|
|
33
|
+
htmlVideoEngineFactory: () => import_core3.htmlVideoEngineFactory,
|
|
27
34
|
localeEn: () => import_core3.localeEn,
|
|
28
|
-
localeZh: () => import_core3.localeZh
|
|
35
|
+
localeZh: () => import_core3.localeZh,
|
|
36
|
+
setTimelineMetrics: () => import_core3.setTimelineMetrics
|
|
29
37
|
});
|
|
30
38
|
module.exports = __toCommonJS(index_exports);
|
|
31
39
|
|
|
@@ -47,7 +55,11 @@ function VideoEditor(props) {
|
|
|
47
55
|
container: host,
|
|
48
56
|
project: cbRef.current.defaultProject,
|
|
49
57
|
theme: cbRef.current.theme,
|
|
50
|
-
locale: cbRef.current.locale
|
|
58
|
+
locale: cbRef.current.locale,
|
|
59
|
+
playbackEngine: cbRef.current.playbackEngine,
|
|
60
|
+
...cbRef.current.trackHeight != null ? { trackHeight: cbRef.current.trackHeight } : {},
|
|
61
|
+
...cbRef.current.rulerHeight != null ? { rulerHeight: cbRef.current.rulerHeight } : {},
|
|
62
|
+
...cbRef.current.timelineHeight != null ? { timelineHeight: cbRef.current.timelineHeight } : {}
|
|
51
63
|
});
|
|
52
64
|
editorRef.current = editor;
|
|
53
65
|
setSlots({
|
|
@@ -82,6 +94,18 @@ function VideoEditor(props) {
|
|
|
82
94
|
(0, import_react.useEffect)(() => {
|
|
83
95
|
if (props.locale) editorRef.current?.setLocale(props.locale);
|
|
84
96
|
}, [props.locale]);
|
|
97
|
+
(0, import_react.useEffect)(() => {
|
|
98
|
+
const host = hostRef.current;
|
|
99
|
+
if (!host) return;
|
|
100
|
+
if (props.timelineHeight != null && props.timelineHeight > 0) {
|
|
101
|
+
host.style.setProperty(
|
|
102
|
+
"--aicut-timeline-height",
|
|
103
|
+
`${Math.round(props.timelineHeight)}px`
|
|
104
|
+
);
|
|
105
|
+
} else {
|
|
106
|
+
host.style.removeProperty("--aicut-timeline-height");
|
|
107
|
+
}
|
|
108
|
+
}, [props.timelineHeight]);
|
|
85
109
|
(0, import_react.useImperativeHandle)(
|
|
86
110
|
props.apiRef,
|
|
87
111
|
() => editorRef.current,
|
|
@@ -195,11 +219,19 @@ function Timeline(props) {
|
|
|
195
219
|
var import_core3 = require("@aicut/core");
|
|
196
220
|
// Annotate the CommonJS export names for ESM import in node:
|
|
197
221
|
0 && (module.exports = {
|
|
222
|
+
CanvasCompositorEngine,
|
|
223
|
+
HEADER_WIDTH,
|
|
224
|
+
HtmlVideoEngine,
|
|
225
|
+
RULER_HEIGHT,
|
|
226
|
+
TRACK_HEIGHT,
|
|
198
227
|
Timeline,
|
|
199
228
|
VideoEditor,
|
|
229
|
+
canvasCompositorEngineFactory,
|
|
200
230
|
createEmptyProject,
|
|
201
231
|
createId,
|
|
232
|
+
htmlVideoEngineFactory,
|
|
202
233
|
localeEn,
|
|
203
|
-
localeZh
|
|
234
|
+
localeZh,
|
|
235
|
+
setTimelineMetrics
|
|
204
236
|
});
|
|
205
237
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/VideoEditor.tsx","../src/Timeline.tsx"],"sourcesContent":["export { VideoEditor } from \"./VideoEditor.js\";\nexport type { VideoEditorProps, VideoEditorApi } from \"./VideoEditor.js\";\nexport { Timeline } from \"./Timeline.js\";\nexport type { TimelineProps, TimelineApi } from \"./Timeline.js\";\nexport type {\n Project,\n MediaSource,\n Track,\n Clip,\n Ms,\n Theme,\n EditorApi,\n Locale,\n} from \"@aicut/core\";\nexport { createEmptyProject, createId, localeEn, localeZh } from \"@aicut/core\";\n","import {\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n type CSSProperties,\n type ReactNode,\n type Ref,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport {\n Editor,\n type EditorApi,\n type Locale,\n type Ms,\n type Project,\n type Theme,\n} from \"@aicut/core\";\n\nexport type VideoEditorApi = EditorApi;\n\nexport interface VideoEditorProps {\n /**\n * Initial project. Read once on mount — to swap projects after mount,\n * call `apiRef.current.setProject(...)` so React doesn't reinstantiate\n * the editor and lose playback state.\n */\n defaultProject?: Project;\n /** CSS variable overrides applied on mount and whenever this ref changes. */\n theme?: Theme;\n /**\n * UI string overrides (English default). Mirror prop — switching the\n * value calls `editor.setLocale` and the toolbar / canvas labels\n * update in place. Use `localeZh` from `@aicut/core` for Chinese.\n */\n locale?: Partial<Locale>;\n\n className?: string;\n style?: CSSProperties;\n\n /** Imperative handle for cut/seek/getProject/setProject/etc. */\n apiRef?: Ref<VideoEditorApi | null>;\n\n onReady?: (api: VideoEditorApi) => void;\n onChange?: (project: Project) => void;\n onExport?: (project: Project) => void;\n onTimeUpdate?: (timeMs: Ms) => void;\n onPlay?: () => void;\n onPause?: () => void;\n onSelectionChange?: (clipId: string | null) => void;\n onError?: (error: Error) => void;\n\n /**\n * Rendered into the very left of the editor's top toolbar — host\n * adds anything here (size dropdown, branding, status badge). The\n * library reserves no space for it; if you pass nothing, no\n * separator appears.\n */\n toolbarLeft?: ReactNode;\n /** Same as `toolbarLeft` but at the very right of the toolbar. */\n toolbarRight?: ReactNode;\n /**\n * Rendered into the LEFT side of an optional header bar above the\n * preview (project name, file menu, breadcrumbs). The header\n * collapses entirely when both header slots are empty, so the\n * default layout is identical to before this slot existed.\n */\n headerLeft?: ReactNode;\n /** Right side of the editor header — conventionally Share / Export / profile. */\n headerRight?: ReactNode;\n}\n\n/**\n * Declarative React shell over `@aicut/core` `Editor`. Mounts the\n * editor instance once, mirrors prop changes (`theme`) into it, and\n * forwards events as React-style callbacks.\n *\n * Intentionally uncontrolled for project state — the editor owns the\n * current project. Use `onChange` to persist and `apiRef.setProject`\n * to restore.\n */\nexport function VideoEditor(props: VideoEditorProps) {\n const hostRef = useRef<HTMLDivElement | null>(null);\n const editorRef = useRef<Editor | null>(null);\n // Toolbar slot DOM nodes don't exist until the editor mounts; we\n // hold them in state so React re-runs the render after mount and\n // the portals attach. Tracked separately for left + right because\n // each is independently controlled by host props.\n const [slots, setSlots] = useState<{\n left: HTMLElement;\n right: HTMLElement;\n headerLeft: HTMLElement;\n headerRight: HTMLElement;\n } | null>(null);\n\n // Latest-callback refs so the effect that creates the editor doesn't\n // re-run on every parent render just because props.onChange is a new\n // identity — the editor would otherwise be torn down constantly.\n const cbRef = useRef(props);\n cbRef.current = props;\n\n useEffect(() => {\n const host = hostRef.current;\n if (!host) return;\n const editor = Editor.create({\n container: host,\n project: cbRef.current.defaultProject,\n theme: cbRef.current.theme,\n locale: cbRef.current.locale,\n });\n editorRef.current = editor;\n setSlots({\n left: editor.toolbarLeft,\n right: editor.toolbarRight,\n headerLeft: editor.headerLeft,\n headerRight: editor.headerRight,\n });\n\n const offs = [\n editor.on(\"change\", ({ project }) => cbRef.current.onChange?.(project)),\n editor.on(\"export\", ({ project }) => cbRef.current.onExport?.(project)),\n editor.on(\"time\", ({ timeMs }) => cbRef.current.onTimeUpdate?.(timeMs)),\n editor.on(\"play\", () => cbRef.current.onPlay?.()),\n editor.on(\"pause\", () => cbRef.current.onPause?.()),\n editor.on(\"selectionChange\", ({ clipId }) =>\n cbRef.current.onSelectionChange?.(clipId),\n ),\n editor.on(\"error\", ({ error }) => cbRef.current.onError?.(error)),\n ];\n\n cbRef.current.onReady?.(editor);\n\n return () => {\n for (const off of offs) off();\n editor.destroy();\n editorRef.current = null;\n setSlots(null);\n };\n // Editor lifecycle is tied to mount; we deliberately don't list\n // any reactive deps. `theme` changes are pushed through the\n // separate effect below.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useEffect(() => {\n if (props.theme) editorRef.current?.setTheme(props.theme);\n }, [props.theme]);\n\n useEffect(() => {\n if (props.locale) editorRef.current?.setLocale(props.locale);\n }, [props.locale]);\n\n // Deps must include `slots`. Without it, the factory ran once during\n // the first commit — BEFORE the useEffect above had a chance to\n // create the editor — so `apiRef.current` was permanently locked to\n // null. `slots` flips from null to a real value the same instant\n // the editor is created, so it's the cleanest re-run trigger.\n useImperativeHandle<VideoEditorApi | null, VideoEditorApi | null>(\n props.apiRef,\n () => editorRef.current,\n [slots],\n );\n\n return (\n <div\n ref={hostRef}\n className={props.className}\n style={props.style}\n data-aicut-host=\"\"\n >\n {slots && props.toolbarLeft != null\n ? createPortal(props.toolbarLeft, slots.left)\n : null}\n {slots && props.toolbarRight != null\n ? createPortal(props.toolbarRight, slots.right)\n : null}\n {slots && props.headerLeft != null\n ? createPortal(props.headerLeft, slots.headerLeft)\n : null}\n {slots && props.headerRight != null\n ? createPortal(props.headerRight, slots.headerRight)\n : null}\n </div>\n );\n}\n","import {\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n type CSSProperties,\n type ReactNode,\n type Ref,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport {\n Timeline as CoreTimeline,\n type Clip,\n type Locale,\n type Ms,\n type Project,\n type TimelineOptions,\n} from \"@aicut/core\";\n\n/** Imperative handle exposed via `apiRef`. */\nexport interface TimelineApi {\n setProject(p: Project): void;\n getProject(): Project;\n setTime(t: Ms): void;\n getTime(): Ms;\n setScale(pxPerSec: number): void;\n getScale(): number;\n setSelection(id: string | null): void;\n getSelection(): string | null;\n setSnap(snap: boolean): void;\n fitToWindow(): void;\n getDebugInfo(): ReturnType<CoreTimeline[\"getDebugInfo\"]>;\n}\n\nexport interface TimelineProps {\n /** Initial project. Use `apiRef.current.setProject(...)` to swap. */\n defaultProject: Project;\n /** Initial scale (px/sec). Defaults to 80; auto-fits on first render. */\n defaultScale?: number;\n /** Initial playhead position. */\n defaultTime?: Ms;\n /** Initial selection. */\n defaultSelectedClipId?: string | null;\n\n /** Hide the left header column (compact / frame-picker mode). */\n showHeader?: boolean;\n /** Disable all editing interactions. */\n readOnly?: boolean;\n /** Snap to clip edges + playhead when dragging. Default true. */\n snap?: boolean;\n /** Apply fit-to-window on mount once duration is known. Default true. */\n autoFit?: boolean;\n /** UI string overrides (English default). */\n locale?: Partial<Locale>;\n /**\n * Render a 36px top toolbar strip with empty left/right flex slots\n * for host-supplied controls. Default false. Pair with `toolbarLeft`\n * / `toolbarRight` to inject content.\n */\n toolbar?: boolean;\n /** Rendered into the left slot of the timeline toolbar (toolbar must be true). */\n toolbarLeft?: ReactNode;\n /** Rendered into the right slot of the timeline toolbar. */\n toolbarRight?: ReactNode;\n\n className?: string;\n style?: CSSProperties;\n\n apiRef?: Ref<TimelineApi | null>;\n\n onSeek?: (timeMs: Ms) => void;\n onSelectClip?: (clipId: string | null) => void;\n onScaleChange?: (pxPerSec: number) => void;\n onMoveClip?: TimelineOptions[\"onMoveClip\"];\n onResizeClip?: TimelineOptions[\"onResizeClip\"];\n onChange?: (project: Project) => void;\n}\n\n/**\n * Standalone, framework-agnostic canvas Timeline wrapped for React.\n * Mount it without an `Editor` for use cases like a video frame-picker:\n *\n * ```tsx\n * <Timeline\n * defaultProject={{ version: 1, sources: [video], tracks: [{ id, kind: \"video\", clips: [{...}] }] }}\n * showHeader={false}\n * readOnly\n * onSeek={(ms) => setCurrentMs(ms)}\n * />\n * ```\n *\n * Uncontrolled for `project` and `pxPerSec` — the underlying Timeline\n * owns them and reports changes via callbacks. Call methods on\n * `apiRef.current` to drive it imperatively (mirroring ag-Grid /\n * VideoEditor patterns).\n */\nexport function Timeline(props: TimelineProps) {\n const hostRef = useRef<HTMLDivElement | null>(null);\n const tlRef = useRef<CoreTimeline | null>(null);\n const [slots, setSlots] = useState<{\n left: HTMLElement;\n right: HTMLElement;\n } | null>(null);\n\n // Latest-callback ref so the create-once effect doesn't tear the\n // timeline down on every render just because callback identities\n // change.\n const cbRef = useRef(props);\n cbRef.current = props;\n\n useEffect(() => {\n const host = hostRef.current;\n if (!host) return;\n const tl = CoreTimeline.create({\n container: host,\n project: cbRef.current.defaultProject,\n pxPerSec: cbRef.current.defaultScale,\n time: cbRef.current.defaultTime,\n selectedClipId: cbRef.current.defaultSelectedClipId ?? null,\n showHeader: cbRef.current.showHeader,\n readOnly: cbRef.current.readOnly,\n snap: cbRef.current.snap,\n autoFit: cbRef.current.autoFit,\n locale: cbRef.current.locale,\n toolbar: cbRef.current.toolbar,\n onSeek: (t) => cbRef.current.onSeek?.(t),\n onSelectClip: (id) => cbRef.current.onSelectClip?.(id),\n onScaleChange: (s) => cbRef.current.onScaleChange?.(s),\n onMoveClip: (id, opts) => cbRef.current.onMoveClip?.(id, opts),\n onResizeClip: (id, e) => cbRef.current.onResizeClip?.(id, e),\n onChange: (p) => cbRef.current.onChange?.(p),\n });\n tlRef.current = tl;\n if (tl.toolbarLeft && tl.toolbarRight) {\n setSlots({ left: tl.toolbarLeft, right: tl.toolbarRight });\n }\n return () => {\n tl.destroy();\n tlRef.current = null;\n setSlots(null);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useEffect(() => {\n if (props.locale) tlRef.current?.setLocale(props.locale);\n }, [props.locale]);\n\n useImperativeHandle<TimelineApi | null, TimelineApi | null>(\n props.apiRef,\n () => {\n const tl = tlRef.current;\n if (!tl) return null;\n return {\n setProject: (p) => tl.setProject(p),\n getProject: () => tl.getProject(),\n setTime: (t) => tl.setTime(t),\n getTime: () => tl.getTime(),\n setScale: (s) => tl.setScale(s),\n getScale: () => tl.getScale(),\n setSelection: (id) => tl.setSelection(id),\n getSelection: () => tl.getSelection(),\n setSnap: (s) => tl.setSnap(s),\n fitToWindow: () => tl.fitToWindow(),\n getDebugInfo: () => tl.getDebugInfo(),\n };\n },\n // Same caveat as VideoEditor.tsx — factory must re-run once the\n // timeline is created in useEffect, otherwise apiRef.current is\n // null forever. `slots` flips from null to a real value the\n // instant the timeline is ready, so it's the cleanest trigger.\n [slots],\n );\n\n return (\n <div\n ref={hostRef}\n className={props.className}\n style={{ width: \"100%\", height: 240, ...props.style }}\n data-aicut-timeline-host=\"\"\n >\n {slots && props.toolbarLeft != null\n ? createPortal(props.toolbarLeft, slots.left)\n : null}\n {slots && props.toolbarRight != null\n ? createPortal(props.toolbarRight, slots.right)\n : null}\n </div>\n );\n\n // Type-only re-export used to keep React/Vue prop typings in lockstep\n // with the core. Reference here so the symbol isn't tree-shaken.\n void ({} as Clip);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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,YAAM,KAAK,MAAM;AACjB,UAAI,CAAC,GAAI,QAAO;AAChB,aAAO;AAAA,QACL,YAAY,CAAC,MAAM,GAAG,WAAW,CAAC;AAAA,QAClC,YAAY,MAAM,GAAG,WAAW;AAAA,QAChC,SAAS,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,QAC5B,SAAS,MAAM,GAAG,QAAQ;AAAA,QAC1B,UAAU,CAAC,MAAM,GAAG,SAAS,CAAC;AAAA,QAC9B,UAAU,MAAM,GAAG,SAAS;AAAA,QAC5B,cAAc,CAAC,OAAO,GAAG,aAAa,EAAE;AAAA,QACxC,cAAc,MAAM,GAAG,aAAa;AAAA,QACpC,SAAS,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,QAC5B,aAAa,MAAM,GAAG,YAAY;AAAA,QAClC,cAAc,MAAM,GAAG,aAAa;AAAA,MACtC;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA,IAKA,CAAC,KAAK;AAAA,EACR;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,KAAK;AAAA,MACL,WAAW,MAAM;AAAA,MACjB,OAAO,EAAE,OAAO,QAAQ,QAAQ,KAAK,GAAG,MAAM,MAAM;AAAA,MACpD,4BAAyB;AAAA,MAExB;AAAA,iBAAS,MAAM,eAAe,WAC3B,gCAAa,MAAM,aAAa,MAAM,IAAI,IAC1C;AAAA,QACH,SAAS,MAAM,gBAAgB,WAC5B,gCAAa,MAAM,cAAc,MAAM,KAAK,IAC5C;AAAA;AAAA;AAAA,EACN;AAKF,OAAM,CAAC;AACT;;;AFnLA,IAAAC,eAAiE;","names":["import_react","import_react_dom","import_core","import_jsx_runtime","CoreTimeline","import_core"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/VideoEditor.tsx","../src/Timeline.tsx"],"sourcesContent":["export { VideoEditor } from \"./VideoEditor.js\";\nexport type { VideoEditorProps, VideoEditorApi } from \"./VideoEditor.js\";\nexport { Timeline } from \"./Timeline.js\";\nexport type { TimelineProps, TimelineApi } from \"./Timeline.js\";\nexport type {\n Project,\n MediaSource,\n Track,\n Clip,\n Ms,\n Theme,\n EditorApi,\n Locale,\n PlaybackEngine,\n PlaybackEngineFactory,\n PlaybackEngineOptions,\n CanvasCompositorEngineOptions,\n} from \"@aicut/core\";\nexport {\n createEmptyProject,\n createId,\n localeEn,\n localeZh,\n HtmlVideoEngine,\n htmlVideoEngineFactory,\n CanvasCompositorEngine,\n canvasCompositorEngineFactory,\n // Live bindings — re-reading them after `setTimelineMetrics` (which\n // EditorOptions.trackHeight / .rulerHeight calls under the hood)\n // returns the updated values.\n TRACK_HEIGHT,\n RULER_HEIGHT,\n HEADER_WIDTH,\n setTimelineMetrics,\n} from \"@aicut/core\";\n","import {\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n type CSSProperties,\n type ReactNode,\n type Ref,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport {\n Editor,\n type EditorApi,\n type Locale,\n type Ms,\n type PlaybackEngineFactory,\n type Project,\n type Theme,\n} from \"@aicut/core\";\n\nexport type VideoEditorApi = EditorApi;\n\nexport interface VideoEditorProps {\n /**\n * Initial project. Read once on mount — to swap projects after mount,\n * call `apiRef.current.setProject(...)` so React doesn't reinstantiate\n * the editor and lose playback state.\n */\n defaultProject?: Project;\n /** CSS variable overrides applied on mount and whenever this ref changes. */\n theme?: Theme;\n /**\n * UI string overrides (English default). Mirror prop — switching the\n * value calls `editor.setLocale` and the toolbar / canvas labels\n * update in place. Use `localeZh` from `@aicut/core` for Chinese.\n */\n locale?: Partial<Locale>;\n\n className?: string;\n style?: CSSProperties;\n\n /** Imperative handle for cut/seek/getProject/setProject/etc. */\n apiRef?: Ref<VideoEditorApi | null>;\n\n onReady?: (api: VideoEditorApi) => void;\n onChange?: (project: Project) => void;\n onExport?: (project: Project) => void;\n onTimeUpdate?: (timeMs: Ms) => void;\n onPlay?: () => void;\n onPause?: () => void;\n onSelectionChange?: (clipId: string | null) => void;\n onError?: (error: Error) => void;\n\n /**\n * Rendered into the very left of the editor's top toolbar — host\n * adds anything here (size dropdown, branding, status badge). The\n * library reserves no space for it; if you pass nothing, no\n * separator appears.\n */\n toolbarLeft?: ReactNode;\n /** Same as `toolbarLeft` but at the very right of the toolbar. */\n toolbarRight?: ReactNode;\n /**\n * Rendered into the LEFT side of an optional header bar above the\n * preview (project name, file menu, breadcrumbs). The header\n * collapses entirely when both header slots are empty, so the\n * default layout is identical to before this slot existed.\n */\n headerLeft?: ReactNode;\n /** Right side of the editor header — conventionally Share / Export / profile. */\n headerRight?: ReactNode;\n\n /**\n * Initial-only — picks the playback engine used by the underlying\n * core Editor. Defaults to the built-in `HtmlVideoEngine`. Pass a\n * factory to plug in a custom engine (WebCodecs, WebGL compositor,\n * IPC bridge to a native player, …). Swapping this prop after mount\n * has no effect — the editor binds its engine at construction.\n */\n playbackEngine?: PlaybackEngineFactory;\n /**\n * Initial-only — pixel height of each track row (default 56). Lower\n * values (~32–40) shrink the timeline for small viewports where the\n * default crowds out the preview. Applied process-wide; to re-apply\n * change this prop AND remount the component (e.g. via `key`).\n */\n trackHeight?: number;\n /** Initial-only — pixel height of the timeline ruler (default 24). */\n rulerHeight?: number;\n /**\n * Pixel height of the whole bottom timeline area (default 240).\n * Reactive — set anytime to change. The canvas inside fills 100%\n * and shows an internal scrollbar when track count overflows.\n * Useful range: [120, 480] depending on viewport.\n */\n timelineHeight?: number;\n}\n\n/**\n * Declarative React shell over `@aicut/core` `Editor`. Mounts the\n * editor instance once, mirrors prop changes (`theme`) into it, and\n * forwards events as React-style callbacks.\n *\n * Intentionally uncontrolled for project state — the editor owns the\n * current project. Use `onChange` to persist and `apiRef.setProject`\n * to restore.\n */\nexport function VideoEditor(props: VideoEditorProps) {\n const hostRef = useRef<HTMLDivElement | null>(null);\n const editorRef = useRef<Editor | null>(null);\n // Toolbar slot DOM nodes don't exist until the editor mounts; we\n // hold them in state so React re-runs the render after mount and\n // the portals attach. Tracked separately for left + right because\n // each is independently controlled by host props.\n const [slots, setSlots] = useState<{\n left: HTMLElement;\n right: HTMLElement;\n headerLeft: HTMLElement;\n headerRight: HTMLElement;\n } | null>(null);\n\n // Latest-callback refs so the effect that creates the editor doesn't\n // re-run on every parent render just because props.onChange is a new\n // identity — the editor would otherwise be torn down constantly.\n const cbRef = useRef(props);\n cbRef.current = props;\n\n useEffect(() => {\n const host = hostRef.current;\n if (!host) return;\n const editor = Editor.create({\n container: host,\n project: cbRef.current.defaultProject,\n theme: cbRef.current.theme,\n locale: cbRef.current.locale,\n playbackEngine: cbRef.current.playbackEngine,\n ...(cbRef.current.trackHeight != null\n ? { trackHeight: cbRef.current.trackHeight }\n : {}),\n ...(cbRef.current.rulerHeight != null\n ? { rulerHeight: cbRef.current.rulerHeight }\n : {}),\n ...(cbRef.current.timelineHeight != null\n ? { timelineHeight: cbRef.current.timelineHeight }\n : {}),\n });\n editorRef.current = editor;\n setSlots({\n left: editor.toolbarLeft,\n right: editor.toolbarRight,\n headerLeft: editor.headerLeft,\n headerRight: editor.headerRight,\n });\n\n const offs = [\n editor.on(\"change\", ({ project }) => cbRef.current.onChange?.(project)),\n editor.on(\"export\", ({ project }) => cbRef.current.onExport?.(project)),\n editor.on(\"time\", ({ timeMs }) => cbRef.current.onTimeUpdate?.(timeMs)),\n editor.on(\"play\", () => cbRef.current.onPlay?.()),\n editor.on(\"pause\", () => cbRef.current.onPause?.()),\n editor.on(\"selectionChange\", ({ clipId }) =>\n cbRef.current.onSelectionChange?.(clipId),\n ),\n editor.on(\"error\", ({ error }) => cbRef.current.onError?.(error)),\n ];\n\n cbRef.current.onReady?.(editor);\n\n return () => {\n for (const off of offs) off();\n editor.destroy();\n editorRef.current = null;\n setSlots(null);\n };\n // Editor lifecycle is tied to mount; we deliberately don't list\n // any reactive deps. `theme` changes are pushed through the\n // separate effect below.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useEffect(() => {\n if (props.theme) editorRef.current?.setTheme(props.theme);\n }, [props.theme]);\n\n useEffect(() => {\n if (props.locale) editorRef.current?.setLocale(props.locale);\n }, [props.locale]);\n\n // Reactive — the underlying CSS custom property can be updated on\n // the container any time; the timeline picks up the new height\n // immediately via CSS. No remount required.\n useEffect(() => {\n const host = hostRef.current;\n if (!host) return;\n if (props.timelineHeight != null && props.timelineHeight > 0) {\n host.style.setProperty(\n \"--aicut-timeline-height\",\n `${Math.round(props.timelineHeight)}px`,\n );\n } else {\n host.style.removeProperty(\"--aicut-timeline-height\");\n }\n }, [props.timelineHeight]);\n\n // Deps must include `slots`. Without it, the factory ran once during\n // the first commit — BEFORE the useEffect above had a chance to\n // create the editor — so `apiRef.current` was permanently locked to\n // null. `slots` flips from null to a real value the same instant\n // the editor is created, so it's the cleanest re-run trigger.\n useImperativeHandle<VideoEditorApi | null, VideoEditorApi | null>(\n props.apiRef,\n () => editorRef.current,\n [slots],\n );\n\n return (\n <div\n ref={hostRef}\n className={props.className}\n style={props.style}\n data-aicut-host=\"\"\n >\n {slots && props.toolbarLeft != null\n ? createPortal(props.toolbarLeft, slots.left)\n : null}\n {slots && props.toolbarRight != null\n ? createPortal(props.toolbarRight, slots.right)\n : null}\n {slots && props.headerLeft != null\n ? createPortal(props.headerLeft, slots.headerLeft)\n : null}\n {slots && props.headerRight != null\n ? createPortal(props.headerRight, slots.headerRight)\n : null}\n </div>\n );\n}\n","import {\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n type CSSProperties,\n type ReactNode,\n type Ref,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport {\n Timeline as CoreTimeline,\n type Clip,\n type Locale,\n type Ms,\n type Project,\n type TimelineOptions,\n} from \"@aicut/core\";\n\n/** Imperative handle exposed via `apiRef`. */\nexport interface TimelineApi {\n setProject(p: Project): void;\n getProject(): Project;\n setTime(t: Ms): void;\n getTime(): Ms;\n setScale(pxPerSec: number): void;\n getScale(): number;\n setSelection(id: string | null): void;\n getSelection(): string | null;\n setSnap(snap: boolean): void;\n fitToWindow(): void;\n getDebugInfo(): ReturnType<CoreTimeline[\"getDebugInfo\"]>;\n}\n\nexport interface TimelineProps {\n /** Initial project. Use `apiRef.current.setProject(...)` to swap. */\n defaultProject: Project;\n /** Initial scale (px/sec). Defaults to 80; auto-fits on first render. */\n defaultScale?: number;\n /** Initial playhead position. */\n defaultTime?: Ms;\n /** Initial selection. */\n defaultSelectedClipId?: string | null;\n\n /** Hide the left header column (compact / frame-picker mode). */\n showHeader?: boolean;\n /** Disable all editing interactions. */\n readOnly?: boolean;\n /** Snap to clip edges + playhead when dragging. Default true. */\n snap?: boolean;\n /** Apply fit-to-window on mount once duration is known. Default true. */\n autoFit?: boolean;\n /** UI string overrides (English default). */\n locale?: Partial<Locale>;\n /**\n * Render a 36px top toolbar strip with empty left/right flex slots\n * for host-supplied controls. Default false. Pair with `toolbarLeft`\n * / `toolbarRight` to inject content.\n */\n toolbar?: boolean;\n /** Rendered into the left slot of the timeline toolbar (toolbar must be true). */\n toolbarLeft?: ReactNode;\n /** Rendered into the right slot of the timeline toolbar. */\n toolbarRight?: ReactNode;\n\n className?: string;\n style?: CSSProperties;\n\n apiRef?: Ref<TimelineApi | null>;\n\n onSeek?: (timeMs: Ms) => void;\n onSelectClip?: (clipId: string | null) => void;\n onScaleChange?: (pxPerSec: number) => void;\n onMoveClip?: TimelineOptions[\"onMoveClip\"];\n onResizeClip?: TimelineOptions[\"onResizeClip\"];\n onChange?: (project: Project) => void;\n}\n\n/**\n * Standalone, framework-agnostic canvas Timeline wrapped for React.\n * Mount it without an `Editor` for use cases like a video frame-picker:\n *\n * ```tsx\n * <Timeline\n * defaultProject={{ version: 1, sources: [video], tracks: [{ id, kind: \"video\", clips: [{...}] }] }}\n * showHeader={false}\n * readOnly\n * onSeek={(ms) => setCurrentMs(ms)}\n * />\n * ```\n *\n * Uncontrolled for `project` and `pxPerSec` — the underlying Timeline\n * owns them and reports changes via callbacks. Call methods on\n * `apiRef.current` to drive it imperatively (mirroring ag-Grid /\n * VideoEditor patterns).\n */\nexport function Timeline(props: TimelineProps) {\n const hostRef = useRef<HTMLDivElement | null>(null);\n const tlRef = useRef<CoreTimeline | null>(null);\n const [slots, setSlots] = useState<{\n left: HTMLElement;\n right: HTMLElement;\n } | null>(null);\n\n // Latest-callback ref so the create-once effect doesn't tear the\n // timeline down on every render just because callback identities\n // change.\n const cbRef = useRef(props);\n cbRef.current = props;\n\n useEffect(() => {\n const host = hostRef.current;\n if (!host) return;\n const tl = CoreTimeline.create({\n container: host,\n project: cbRef.current.defaultProject,\n pxPerSec: cbRef.current.defaultScale,\n time: cbRef.current.defaultTime,\n selectedClipId: cbRef.current.defaultSelectedClipId ?? null,\n showHeader: cbRef.current.showHeader,\n readOnly: cbRef.current.readOnly,\n snap: cbRef.current.snap,\n autoFit: cbRef.current.autoFit,\n locale: cbRef.current.locale,\n toolbar: cbRef.current.toolbar,\n onSeek: (t) => cbRef.current.onSeek?.(t),\n onSelectClip: (id) => cbRef.current.onSelectClip?.(id),\n onScaleChange: (s) => cbRef.current.onScaleChange?.(s),\n onMoveClip: (id, opts) => cbRef.current.onMoveClip?.(id, opts),\n onResizeClip: (id, e) => cbRef.current.onResizeClip?.(id, e),\n onChange: (p) => cbRef.current.onChange?.(p),\n });\n tlRef.current = tl;\n if (tl.toolbarLeft && tl.toolbarRight) {\n setSlots({ left: tl.toolbarLeft, right: tl.toolbarRight });\n }\n return () => {\n tl.destroy();\n tlRef.current = null;\n setSlots(null);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useEffect(() => {\n if (props.locale) tlRef.current?.setLocale(props.locale);\n }, [props.locale]);\n\n useImperativeHandle<TimelineApi | null, TimelineApi | null>(\n props.apiRef,\n () => {\n const tl = tlRef.current;\n if (!tl) return null;\n return {\n setProject: (p) => tl.setProject(p),\n getProject: () => tl.getProject(),\n setTime: (t) => tl.setTime(t),\n getTime: () => tl.getTime(),\n setScale: (s) => tl.setScale(s),\n getScale: () => tl.getScale(),\n setSelection: (id) => tl.setSelection(id),\n getSelection: () => tl.getSelection(),\n setSnap: (s) => tl.setSnap(s),\n fitToWindow: () => tl.fitToWindow(),\n getDebugInfo: () => tl.getDebugInfo(),\n };\n },\n // Same caveat as VideoEditor.tsx — factory must re-run once the\n // timeline is created in useEffect, otherwise apiRef.current is\n // null forever. `slots` flips from null to a real value the\n // instant the timeline is ready, so it's the cleanest trigger.\n [slots],\n );\n\n return (\n <div\n ref={hostRef}\n className={props.className}\n style={{ width: \"100%\", height: 240, ...props.style }}\n data-aicut-timeline-host=\"\"\n >\n {slots && props.toolbarLeft != null\n ? createPortal(props.toolbarLeft, slots.left)\n : null}\n {slots && props.toolbarRight != null\n ? createPortal(props.toolbarRight, slots.right)\n : null}\n </div>\n );\n\n // Type-only re-export used to keep React/Vue prop typings in lockstep\n // with the core. Reference here so the symbol isn't tree-shaken.\n void ({} as Clip);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAQO;AACP,uBAA6B;AAC7B,kBAQO;AAsMH;AA7GG,SAAS,YAAY,OAAyB;AACnD,QAAM,cAAU,qBAA8B,IAAI;AAClD,QAAM,gBAAY,qBAAsB,IAAI;AAK5C,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAKhB,IAAI;AAKd,QAAM,YAAQ,qBAAO,KAAK;AAC1B,QAAM,UAAU;AAEhB,8BAAU,MAAM;AACd,UAAM,OAAO,QAAQ;AACrB,QAAI,CAAC,KAAM;AACX,UAAM,SAAS,mBAAO,OAAO;AAAA,MAC3B,WAAW;AAAA,MACX,SAAS,MAAM,QAAQ;AAAA,MACvB,OAAO,MAAM,QAAQ;AAAA,MACrB,QAAQ,MAAM,QAAQ;AAAA,MACtB,gBAAgB,MAAM,QAAQ;AAAA,MAC9B,GAAI,MAAM,QAAQ,eAAe,OAC7B,EAAE,aAAa,MAAM,QAAQ,YAA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AM;AAAA,IACN,MAAM;AACJ,YAAM,KAAK,MAAM;AACjB,UAAI,CAAC,GAAI,QAAO;AAChB,aAAO;AAAA,QACL,YAAY,CAAC,MAAM,GAAG,WAAW,CAAC;AAAA,QAClC,YAAY,MAAM,GAAG,WAAW;AAAA,QAChC,SAAS,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,QAC5B,SAAS,MAAM,GAAG,QAAQ;AAAA,QAC1B,UAAU,CAAC,MAAM,GAAG,SAAS,CAAC;AAAA,QAC9B,UAAU,MAAM,GAAG,SAAS;AAAA,QAC5B,cAAc,CAAC,OAAO,GAAG,aAAa,EAAE;AAAA,QACxC,cAAc,MAAM,GAAG,aAAa;AAAA,QACpC,SAAS,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,QAC5B,aAAa,MAAM,GAAG,YAAY;AAAA,QAClC,cAAc,MAAM,GAAG,aAAa;AAAA,MACtC;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA,IAKA,CAAC,KAAK;AAAA,EACR;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,KAAK;AAAA,MACL,WAAW,MAAM;AAAA,MACjB,OAAO,EAAE,OAAO,QAAQ,QAAQ,KAAK,GAAG,MAAM,MAAM;AAAA,MACpD,4BAAyB;AAAA,MAExB;AAAA,iBAAS,MAAM,eAAe,WAC3B,gCAAa,MAAM,aAAa,MAAM,IAAI,IAC1C;AAAA,QACH,SAAS,MAAM,gBAAgB,WAC5B,gCAAa,MAAM,cAAc,MAAM,KAAK,IAC5C;AAAA;AAAA;AAAA,EACN;AAKF,OAAM,CAAC;AACT;;;AF/KA,IAAAC,eAgBO;","names":["import_react","import_react_dom","import_core","import_jsx_runtime","CoreTimeline","import_core"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { CSSProperties, Ref, ReactNode } from 'react';
|
|
3
|
-
import { Project, Theme, Locale, EditorApi, Ms, Timeline as Timeline$1, TimelineOptions } from '@aicut/core';
|
|
4
|
-
export { Clip, EditorApi, Locale, MediaSource, Ms, Project, Theme, Track, createEmptyProject, createId, localeEn, localeZh } from '@aicut/core';
|
|
3
|
+
import { Project, Theme, Locale, EditorApi, Ms, PlaybackEngineFactory, Timeline as Timeline$1, TimelineOptions } from '@aicut/core';
|
|
4
|
+
export { CanvasCompositorEngine, CanvasCompositorEngineOptions, Clip, EditorApi, HEADER_WIDTH, HtmlVideoEngine, Locale, MediaSource, Ms, PlaybackEngine, PlaybackEngineFactory, PlaybackEngineOptions, Project, RULER_HEIGHT, TRACK_HEIGHT, Theme, Track, canvasCompositorEngineFactory, createEmptyProject, createId, htmlVideoEngineFactory, localeEn, localeZh, setTimelineMetrics } from '@aicut/core';
|
|
5
5
|
|
|
6
6
|
type VideoEditorApi = EditorApi;
|
|
7
7
|
interface VideoEditorProps {
|
|
@@ -49,6 +49,30 @@ interface VideoEditorProps {
|
|
|
49
49
|
headerLeft?: ReactNode;
|
|
50
50
|
/** Right side of the editor header — conventionally Share / Export / profile. */
|
|
51
51
|
headerRight?: ReactNode;
|
|
52
|
+
/**
|
|
53
|
+
* Initial-only — picks the playback engine used by the underlying
|
|
54
|
+
* core Editor. Defaults to the built-in `HtmlVideoEngine`. Pass a
|
|
55
|
+
* factory to plug in a custom engine (WebCodecs, WebGL compositor,
|
|
56
|
+
* IPC bridge to a native player, …). Swapping this prop after mount
|
|
57
|
+
* has no effect — the editor binds its engine at construction.
|
|
58
|
+
*/
|
|
59
|
+
playbackEngine?: PlaybackEngineFactory;
|
|
60
|
+
/**
|
|
61
|
+
* Initial-only — pixel height of each track row (default 56). Lower
|
|
62
|
+
* values (~32–40) shrink the timeline for small viewports where the
|
|
63
|
+
* default crowds out the preview. Applied process-wide; to re-apply
|
|
64
|
+
* change this prop AND remount the component (e.g. via `key`).
|
|
65
|
+
*/
|
|
66
|
+
trackHeight?: number;
|
|
67
|
+
/** Initial-only — pixel height of the timeline ruler (default 24). */
|
|
68
|
+
rulerHeight?: number;
|
|
69
|
+
/**
|
|
70
|
+
* Pixel height of the whole bottom timeline area (default 240).
|
|
71
|
+
* Reactive — set anytime to change. The canvas inside fills 100%
|
|
72
|
+
* and shows an internal scrollbar when track count overflows.
|
|
73
|
+
* Useful range: [120, 480] depending on viewport.
|
|
74
|
+
*/
|
|
75
|
+
timelineHeight?: number;
|
|
52
76
|
}
|
|
53
77
|
/**
|
|
54
78
|
* Declarative React shell over `@aicut/core` `Editor`. Mounts the
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { CSSProperties, Ref, ReactNode } from 'react';
|
|
3
|
-
import { Project, Theme, Locale, EditorApi, Ms, Timeline as Timeline$1, TimelineOptions } from '@aicut/core';
|
|
4
|
-
export { Clip, EditorApi, Locale, MediaSource, Ms, Project, Theme, Track, createEmptyProject, createId, localeEn, localeZh } from '@aicut/core';
|
|
3
|
+
import { Project, Theme, Locale, EditorApi, Ms, PlaybackEngineFactory, Timeline as Timeline$1, TimelineOptions } from '@aicut/core';
|
|
4
|
+
export { CanvasCompositorEngine, CanvasCompositorEngineOptions, Clip, EditorApi, HEADER_WIDTH, HtmlVideoEngine, Locale, MediaSource, Ms, PlaybackEngine, PlaybackEngineFactory, PlaybackEngineOptions, Project, RULER_HEIGHT, TRACK_HEIGHT, Theme, Track, canvasCompositorEngineFactory, createEmptyProject, createId, htmlVideoEngineFactory, localeEn, localeZh, setTimelineMetrics } from '@aicut/core';
|
|
5
5
|
|
|
6
6
|
type VideoEditorApi = EditorApi;
|
|
7
7
|
interface VideoEditorProps {
|
|
@@ -49,6 +49,30 @@ interface VideoEditorProps {
|
|
|
49
49
|
headerLeft?: ReactNode;
|
|
50
50
|
/** Right side of the editor header — conventionally Share / Export / profile. */
|
|
51
51
|
headerRight?: ReactNode;
|
|
52
|
+
/**
|
|
53
|
+
* Initial-only — picks the playback engine used by the underlying
|
|
54
|
+
* core Editor. Defaults to the built-in `HtmlVideoEngine`. Pass a
|
|
55
|
+
* factory to plug in a custom engine (WebCodecs, WebGL compositor,
|
|
56
|
+
* IPC bridge to a native player, …). Swapping this prop after mount
|
|
57
|
+
* has no effect — the editor binds its engine at construction.
|
|
58
|
+
*/
|
|
59
|
+
playbackEngine?: PlaybackEngineFactory;
|
|
60
|
+
/**
|
|
61
|
+
* Initial-only — pixel height of each track row (default 56). Lower
|
|
62
|
+
* values (~32–40) shrink the timeline for small viewports where the
|
|
63
|
+
* default crowds out the preview. Applied process-wide; to re-apply
|
|
64
|
+
* change this prop AND remount the component (e.g. via `key`).
|
|
65
|
+
*/
|
|
66
|
+
trackHeight?: number;
|
|
67
|
+
/** Initial-only — pixel height of the timeline ruler (default 24). */
|
|
68
|
+
rulerHeight?: number;
|
|
69
|
+
/**
|
|
70
|
+
* Pixel height of the whole bottom timeline area (default 240).
|
|
71
|
+
* Reactive — set anytime to change. The canvas inside fills 100%
|
|
72
|
+
* and shows an internal scrollbar when track count overflows.
|
|
73
|
+
* Useful range: [120, 480] depending on viewport.
|
|
74
|
+
*/
|
|
75
|
+
timelineHeight?: number;
|
|
52
76
|
}
|
|
53
77
|
/**
|
|
54
78
|
* Declarative React shell over `@aicut/core` `Editor`. Mounts the
|
package/dist/index.js
CHANGED
|
@@ -23,7 +23,11 @@ function VideoEditor(props) {
|
|
|
23
23
|
container: host,
|
|
24
24
|
project: cbRef.current.defaultProject,
|
|
25
25
|
theme: cbRef.current.theme,
|
|
26
|
-
locale: cbRef.current.locale
|
|
26
|
+
locale: cbRef.current.locale,
|
|
27
|
+
playbackEngine: cbRef.current.playbackEngine,
|
|
28
|
+
...cbRef.current.trackHeight != null ? { trackHeight: cbRef.current.trackHeight } : {},
|
|
29
|
+
...cbRef.current.rulerHeight != null ? { rulerHeight: cbRef.current.rulerHeight } : {},
|
|
30
|
+
...cbRef.current.timelineHeight != null ? { timelineHeight: cbRef.current.timelineHeight } : {}
|
|
27
31
|
});
|
|
28
32
|
editorRef.current = editor;
|
|
29
33
|
setSlots({
|
|
@@ -58,6 +62,18 @@ function VideoEditor(props) {
|
|
|
58
62
|
useEffect(() => {
|
|
59
63
|
if (props.locale) editorRef.current?.setLocale(props.locale);
|
|
60
64
|
}, [props.locale]);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
const host = hostRef.current;
|
|
67
|
+
if (!host) return;
|
|
68
|
+
if (props.timelineHeight != null && props.timelineHeight > 0) {
|
|
69
|
+
host.style.setProperty(
|
|
70
|
+
"--aicut-timeline-height",
|
|
71
|
+
`${Math.round(props.timelineHeight)}px`
|
|
72
|
+
);
|
|
73
|
+
} else {
|
|
74
|
+
host.style.removeProperty("--aicut-timeline-height");
|
|
75
|
+
}
|
|
76
|
+
}, [props.timelineHeight]);
|
|
61
77
|
useImperativeHandle(
|
|
62
78
|
props.apiRef,
|
|
63
79
|
() => editorRef.current,
|
|
@@ -175,13 +191,34 @@ function Timeline(props) {
|
|
|
175
191
|
}
|
|
176
192
|
|
|
177
193
|
// src/index.ts
|
|
178
|
-
import {
|
|
194
|
+
import {
|
|
195
|
+
createEmptyProject,
|
|
196
|
+
createId,
|
|
197
|
+
localeEn,
|
|
198
|
+
localeZh,
|
|
199
|
+
HtmlVideoEngine,
|
|
200
|
+
htmlVideoEngineFactory,
|
|
201
|
+
CanvasCompositorEngine,
|
|
202
|
+
canvasCompositorEngineFactory,
|
|
203
|
+
TRACK_HEIGHT,
|
|
204
|
+
RULER_HEIGHT,
|
|
205
|
+
HEADER_WIDTH,
|
|
206
|
+
setTimelineMetrics
|
|
207
|
+
} from "@aicut/core";
|
|
179
208
|
export {
|
|
209
|
+
CanvasCompositorEngine,
|
|
210
|
+
HEADER_WIDTH,
|
|
211
|
+
HtmlVideoEngine,
|
|
212
|
+
RULER_HEIGHT,
|
|
213
|
+
TRACK_HEIGHT,
|
|
180
214
|
Timeline,
|
|
181
215
|
VideoEditor,
|
|
216
|
+
canvasCompositorEngineFactory,
|
|
182
217
|
createEmptyProject,
|
|
183
218
|
createId,
|
|
219
|
+
htmlVideoEngineFactory,
|
|
184
220
|
localeEn,
|
|
185
|
-
localeZh
|
|
221
|
+
localeZh,
|
|
222
|
+
setTimelineMetrics
|
|
186
223
|
};
|
|
187
224
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/VideoEditor.tsx","../src/Timeline.tsx","../src/index.ts"],"sourcesContent":["import {\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n type CSSProperties,\n type ReactNode,\n type Ref,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport {\n Editor,\n type EditorApi,\n type Locale,\n type Ms,\n type Project,\n type Theme,\n} from \"@aicut/core\";\n\nexport type VideoEditorApi = EditorApi;\n\nexport interface VideoEditorProps {\n /**\n * Initial project. Read once on mount — to swap projects after mount,\n * call `apiRef.current.setProject(...)` so React doesn't reinstantiate\n * the editor and lose playback state.\n */\n defaultProject?: Project;\n /** CSS variable overrides applied on mount and whenever this ref changes. */\n theme?: Theme;\n /**\n * UI string overrides (English default). Mirror prop — switching the\n * value calls `editor.setLocale` and the toolbar / canvas labels\n * update in place. Use `localeZh` from `@aicut/core` for Chinese.\n */\n locale?: Partial<Locale>;\n\n className?: string;\n style?: CSSProperties;\n\n /** Imperative handle for cut/seek/getProject/setProject/etc. */\n apiRef?: Ref<VideoEditorApi | null>;\n\n onReady?: (api: VideoEditorApi) => void;\n onChange?: (project: Project) => void;\n onExport?: (project: Project) => void;\n onTimeUpdate?: (timeMs: Ms) => void;\n onPlay?: () => void;\n onPause?: () => void;\n onSelectionChange?: (clipId: string | null) => void;\n onError?: (error: Error) => void;\n\n /**\n * Rendered into the very left of the editor's top toolbar — host\n * adds anything here (size dropdown, branding, status badge). The\n * library reserves no space for it; if you pass nothing, no\n * separator appears.\n */\n toolbarLeft?: ReactNode;\n /** Same as `toolbarLeft` but at the very right of the toolbar. */\n toolbarRight?: ReactNode;\n /**\n * Rendered into the LEFT side of an optional header bar above the\n * preview (project name, file menu, breadcrumbs). The header\n * collapses entirely when both header slots are empty, so the\n * default layout is identical to before this slot existed.\n */\n headerLeft?: ReactNode;\n /** Right side of the editor header — conventionally Share / Export / profile. */\n headerRight?: ReactNode;\n}\n\n/**\n * Declarative React shell over `@aicut/core` `Editor`. Mounts the\n * editor instance once, mirrors prop changes (`theme`) into it, and\n * forwards events as React-style callbacks.\n *\n * Intentionally uncontrolled for project state — the editor owns the\n * current project. Use `onChange` to persist and `apiRef.setProject`\n * to restore.\n */\nexport function VideoEditor(props: VideoEditorProps) {\n const hostRef = useRef<HTMLDivElement | null>(null);\n const editorRef = useRef<Editor | null>(null);\n // Toolbar slot DOM nodes don't exist until the editor mounts; we\n // hold them in state so React re-runs the render after mount and\n // the portals attach. Tracked separately for left + right because\n // each is independently controlled by host props.\n const [slots, setSlots] = useState<{\n left: HTMLElement;\n right: HTMLElement;\n headerLeft: HTMLElement;\n headerRight: HTMLElement;\n } | null>(null);\n\n // Latest-callback refs so the effect that creates the editor doesn't\n // re-run on every parent render just because props.onChange is a new\n // identity — the editor would otherwise be torn down constantly.\n const cbRef = useRef(props);\n cbRef.current = props;\n\n useEffect(() => {\n const host = hostRef.current;\n if (!host) return;\n const editor = Editor.create({\n container: host,\n project: cbRef.current.defaultProject,\n theme: cbRef.current.theme,\n locale: cbRef.current.locale,\n });\n editorRef.current = editor;\n setSlots({\n left: editor.toolbarLeft,\n right: editor.toolbarRight,\n headerLeft: editor.headerLeft,\n headerRight: editor.headerRight,\n });\n\n const offs = [\n editor.on(\"change\", ({ project }) => cbRef.current.onChange?.(project)),\n editor.on(\"export\", ({ project }) => cbRef.current.onExport?.(project)),\n editor.on(\"time\", ({ timeMs }) => cbRef.current.onTimeUpdate?.(timeMs)),\n editor.on(\"play\", () => cbRef.current.onPlay?.()),\n editor.on(\"pause\", () => cbRef.current.onPause?.()),\n editor.on(\"selectionChange\", ({ clipId }) =>\n cbRef.current.onSelectionChange?.(clipId),\n ),\n editor.on(\"error\", ({ error }) => cbRef.current.onError?.(error)),\n ];\n\n cbRef.current.onReady?.(editor);\n\n return () => {\n for (const off of offs) off();\n editor.destroy();\n editorRef.current = null;\n setSlots(null);\n };\n // Editor lifecycle is tied to mount; we deliberately don't list\n // any reactive deps. `theme` changes are pushed through the\n // separate effect below.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useEffect(() => {\n if (props.theme) editorRef.current?.setTheme(props.theme);\n }, [props.theme]);\n\n useEffect(() => {\n if (props.locale) editorRef.current?.setLocale(props.locale);\n }, [props.locale]);\n\n // Deps must include `slots`. Without it, the factory ran once during\n // the first commit — BEFORE the useEffect above had a chance to\n // create the editor — so `apiRef.current` was permanently locked to\n // null. `slots` flips from null to a real value the same instant\n // the editor is created, so it's the cleanest re-run trigger.\n useImperativeHandle<VideoEditorApi | null, VideoEditorApi | null>(\n props.apiRef,\n () => editorRef.current,\n [slots],\n );\n\n return (\n <div\n ref={hostRef}\n className={props.className}\n style={props.style}\n data-aicut-host=\"\"\n >\n {slots && props.toolbarLeft != null\n ? createPortal(props.toolbarLeft, slots.left)\n : null}\n {slots && props.toolbarRight != null\n ? createPortal(props.toolbarRight, slots.right)\n : null}\n {slots && props.headerLeft != null\n ? createPortal(props.headerLeft, slots.headerLeft)\n : null}\n {slots && props.headerRight != null\n ? createPortal(props.headerRight, slots.headerRight)\n : null}\n </div>\n );\n}\n","import {\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n type CSSProperties,\n type ReactNode,\n type Ref,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport {\n Timeline as CoreTimeline,\n type Clip,\n type Locale,\n type Ms,\n type Project,\n type TimelineOptions,\n} from \"@aicut/core\";\n\n/** Imperative handle exposed via `apiRef`. */\nexport interface TimelineApi {\n setProject(p: Project): void;\n getProject(): Project;\n setTime(t: Ms): void;\n getTime(): Ms;\n setScale(pxPerSec: number): void;\n getScale(): number;\n setSelection(id: string | null): void;\n getSelection(): string | null;\n setSnap(snap: boolean): void;\n fitToWindow(): void;\n getDebugInfo(): ReturnType<CoreTimeline[\"getDebugInfo\"]>;\n}\n\nexport interface TimelineProps {\n /** Initial project. Use `apiRef.current.setProject(...)` to swap. */\n defaultProject: Project;\n /** Initial scale (px/sec). Defaults to 80; auto-fits on first render. */\n defaultScale?: number;\n /** Initial playhead position. */\n defaultTime?: Ms;\n /** Initial selection. */\n defaultSelectedClipId?: string | null;\n\n /** Hide the left header column (compact / frame-picker mode). */\n showHeader?: boolean;\n /** Disable all editing interactions. */\n readOnly?: boolean;\n /** Snap to clip edges + playhead when dragging. Default true. */\n snap?: boolean;\n /** Apply fit-to-window on mount once duration is known. Default true. */\n autoFit?: boolean;\n /** UI string overrides (English default). */\n locale?: Partial<Locale>;\n /**\n * Render a 36px top toolbar strip with empty left/right flex slots\n * for host-supplied controls. Default false. Pair with `toolbarLeft`\n * / `toolbarRight` to inject content.\n */\n toolbar?: boolean;\n /** Rendered into the left slot of the timeline toolbar (toolbar must be true). */\n toolbarLeft?: ReactNode;\n /** Rendered into the right slot of the timeline toolbar. */\n toolbarRight?: ReactNode;\n\n className?: string;\n style?: CSSProperties;\n\n apiRef?: Ref<TimelineApi | null>;\n\n onSeek?: (timeMs: Ms) => void;\n onSelectClip?: (clipId: string | null) => void;\n onScaleChange?: (pxPerSec: number) => void;\n onMoveClip?: TimelineOptions[\"onMoveClip\"];\n onResizeClip?: TimelineOptions[\"onResizeClip\"];\n onChange?: (project: Project) => void;\n}\n\n/**\n * Standalone, framework-agnostic canvas Timeline wrapped for React.\n * Mount it without an `Editor` for use cases like a video frame-picker:\n *\n * ```tsx\n * <Timeline\n * defaultProject={{ version: 1, sources: [video], tracks: [{ id, kind: \"video\", clips: [{...}] }] }}\n * showHeader={false}\n * readOnly\n * onSeek={(ms) => setCurrentMs(ms)}\n * />\n * ```\n *\n * Uncontrolled for `project` and `pxPerSec` — the underlying Timeline\n * owns them and reports changes via callbacks. Call methods on\n * `apiRef.current` to drive it imperatively (mirroring ag-Grid /\n * VideoEditor patterns).\n */\nexport function Timeline(props: TimelineProps) {\n const hostRef = useRef<HTMLDivElement | null>(null);\n const tlRef = useRef<CoreTimeline | null>(null);\n const [slots, setSlots] = useState<{\n left: HTMLElement;\n right: HTMLElement;\n } | null>(null);\n\n // Latest-callback ref so the create-once effect doesn't tear the\n // timeline down on every render just because callback identities\n // change.\n const cbRef = useRef(props);\n cbRef.current = props;\n\n useEffect(() => {\n const host = hostRef.current;\n if (!host) return;\n const tl = CoreTimeline.create({\n container: host,\n project: cbRef.current.defaultProject,\n pxPerSec: cbRef.current.defaultScale,\n time: cbRef.current.defaultTime,\n selectedClipId: cbRef.current.defaultSelectedClipId ?? null,\n showHeader: cbRef.current.showHeader,\n readOnly: cbRef.current.readOnly,\n snap: cbRef.current.snap,\n autoFit: cbRef.current.autoFit,\n locale: cbRef.current.locale,\n toolbar: cbRef.current.toolbar,\n onSeek: (t) => cbRef.current.onSeek?.(t),\n onSelectClip: (id) => cbRef.current.onSelectClip?.(id),\n onScaleChange: (s) => cbRef.current.onScaleChange?.(s),\n onMoveClip: (id, opts) => cbRef.current.onMoveClip?.(id, opts),\n onResizeClip: (id, e) => cbRef.current.onResizeClip?.(id, e),\n onChange: (p) => cbRef.current.onChange?.(p),\n });\n tlRef.current = tl;\n if (tl.toolbarLeft && tl.toolbarRight) {\n setSlots({ left: tl.toolbarLeft, right: tl.toolbarRight });\n }\n return () => {\n tl.destroy();\n tlRef.current = null;\n setSlots(null);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useEffect(() => {\n if (props.locale) tlRef.current?.setLocale(props.locale);\n }, [props.locale]);\n\n useImperativeHandle<TimelineApi | null, TimelineApi | null>(\n props.apiRef,\n () => {\n const tl = tlRef.current;\n if (!tl) return null;\n return {\n setProject: (p) => tl.setProject(p),\n getProject: () => tl.getProject(),\n setTime: (t) => tl.setTime(t),\n getTime: () => tl.getTime(),\n setScale: (s) => tl.setScale(s),\n getScale: () => tl.getScale(),\n setSelection: (id) => tl.setSelection(id),\n getSelection: () => tl.getSelection(),\n setSnap: (s) => tl.setSnap(s),\n fitToWindow: () => tl.fitToWindow(),\n getDebugInfo: () => tl.getDebugInfo(),\n };\n },\n // Same caveat as VideoEditor.tsx — factory must re-run once the\n // timeline is created in useEffect, otherwise apiRef.current is\n // null forever. `slots` flips from null to a real value the\n // instant the timeline is ready, so it's the cleanest trigger.\n [slots],\n );\n\n return (\n <div\n ref={hostRef}\n className={props.className}\n style={{ width: \"100%\", height: 240, ...props.style }}\n data-aicut-timeline-host=\"\"\n >\n {slots && props.toolbarLeft != null\n ? createPortal(props.toolbarLeft, slots.left)\n : null}\n {slots && props.toolbarRight != null\n ? createPortal(props.toolbarRight, slots.right)\n : null}\n </div>\n );\n\n // Type-only re-export used to keep React/Vue prop typings in lockstep\n // with the core. Reference here so the symbol isn't tree-shaken.\n void ({} as Clip);\n}\n","export { VideoEditor } from \"./VideoEditor.js\";\nexport type { VideoEditorProps, VideoEditorApi } from \"./VideoEditor.js\";\nexport { Timeline } from \"./Timeline.js\";\nexport type { TimelineProps, TimelineApi } from \"./Timeline.js\";\nexport type {\n Project,\n MediaSource,\n Track,\n Clip,\n Ms,\n Theme,\n EditorApi,\n Locale,\n} from \"@aicut/core\";\nexport { createEmptyProject, createId, localeEn, localeZh } from \"@aicut/core\";\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,OAMK;AAmJH;AAnFG,SAAS,YAAY,OAAyB;AACnD,QAAM,UAAU,OAA8B,IAAI;AAClD,QAAM,YAAY,OAAsB,IAAI;AAK5C,QAAM,CAAC,OAAO,QAAQ,IAAI,SAKhB,IAAI;AAKd,QAAM,QAAQ,OAAO,KAAK;AAC1B,QAAM,UAAU;AAEhB,YAAU,MAAM;AACd,UAAM,OAAO,QAAQ;AACrB,QAAI,CAAC,K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AA,QAC1B,UAAU,CAAC,MAAM,GAAG,SAAS,CAAC;AAAA,QAC9B,UAAU,MAAM,GAAG,SAAS;AAAA,QAC5B,cAAc,CAAC,OAAO,GAAG,aAAa,EAAE;AAAA,QACxC,cAAc,MAAM,GAAG,aAAa;AAAA,QACpC,SAAS,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,QAC5B,aAAa,MAAM,GAAG,YAAY;AAAA,QAClC,cAAc,MAAM,GAAG,aAAa;AAAA,MACtC;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA,IAKA,CAAC,KAAK;AAAA,EACR;AAEA,SACE,gBAAAI;AAAA,IAAC;AAAA;AAAA,MACC,KAAK;AAAA,MACL,WAAW,MAAM;AAAA,MACjB,OAAO,EAAE,OAAO,QAAQ,QAAQ,KAAK,GAAG,MAAM,MAAM;AAAA,MACpD,4BAAyB;AAAA,MAExB;AAAA,iBAAS,MAAM,eAAe,OAC3BD,cAAa,MAAM,aAAa,MAAM,IAAI,IAC1C;AAAA,QACH,SAAS,MAAM,gBAAgB,OAC5BA,cAAa,MAAM,cAAc,MAAM,KAAK,IAC5C;AAAA;AAAA;AAAA,EACN;AAKF,OAAM,CAAC;AACT;;;ACnLA,SAAS,oBAAoB,UAAU,UAAU,gBAAgB;","names":["useEffect","useImperativeHandle","useRef","useState","createPortal","jsxs"]}
|
|
1
|
+
{"version":3,"sources":["../src/VideoEditor.tsx","../src/Timeline.tsx","../src/index.ts"],"sourcesContent":["import {\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n type CSSProperties,\n type ReactNode,\n type Ref,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport {\n Editor,\n type EditorApi,\n type Locale,\n type Ms,\n type PlaybackEngineFactory,\n type Project,\n type Theme,\n} from \"@aicut/core\";\n\nexport type VideoEditorApi = EditorApi;\n\nexport interface VideoEditorProps {\n /**\n * Initial project. Read once on mount — to swap projects after mount,\n * call `apiRef.current.setProject(...)` so React doesn't reinstantiate\n * the editor and lose playback state.\n */\n defaultProject?: Project;\n /** CSS variable overrides applied on mount and whenever this ref changes. */\n theme?: Theme;\n /**\n * UI string overrides (English default). Mirror prop — switching the\n * value calls `editor.setLocale` and the toolbar / canvas labels\n * update in place. Use `localeZh` from `@aicut/core` for Chinese.\n */\n locale?: Partial<Locale>;\n\n className?: string;\n style?: CSSProperties;\n\n /** Imperative handle for cut/seek/getProject/setProject/etc. */\n apiRef?: Ref<VideoEditorApi | null>;\n\n onReady?: (api: VideoEditorApi) => void;\n onChange?: (project: Project) => void;\n onExport?: (project: Project) => void;\n onTimeUpdate?: (timeMs: Ms) => void;\n onPlay?: () => void;\n onPause?: () => void;\n onSelectionChange?: (clipId: string | null) => void;\n onError?: (error: Error) => void;\n\n /**\n * Rendered into the very left of the editor's top toolbar — host\n * adds anything here (size dropdown, branding, status badge). The\n * library reserves no space for it; if you pass nothing, no\n * separator appears.\n */\n toolbarLeft?: ReactNode;\n /** Same as `toolbarLeft` but at the very right of the toolbar. */\n toolbarRight?: ReactNode;\n /**\n * Rendered into the LEFT side of an optional header bar above the\n * preview (project name, file menu, breadcrumbs). The header\n * collapses entirely when both header slots are empty, so the\n * default layout is identical to before this slot existed.\n */\n headerLeft?: ReactNode;\n /** Right side of the editor header — conventionally Share / Export / profile. */\n headerRight?: ReactNode;\n\n /**\n * Initial-only — picks the playback engine used by the underlying\n * core Editor. Defaults to the built-in `HtmlVideoEngine`. Pass a\n * factory to plug in a custom engine (WebCodecs, WebGL compositor,\n * IPC bridge to a native player, …). Swapping this prop after mount\n * has no effect — the editor binds its engine at construction.\n */\n playbackEngine?: PlaybackEngineFactory;\n /**\n * Initial-only — pixel height of each track row (default 56). Lower\n * values (~32–40) shrink the timeline for small viewports where the\n * default crowds out the preview. Applied process-wide; to re-apply\n * change this prop AND remount the component (e.g. via `key`).\n */\n trackHeight?: number;\n /** Initial-only — pixel height of the timeline ruler (default 24). */\n rulerHeight?: number;\n /**\n * Pixel height of the whole bottom timeline area (default 240).\n * Reactive — set anytime to change. The canvas inside fills 100%\n * and shows an internal scrollbar when track count overflows.\n * Useful range: [120, 480] depending on viewport.\n */\n timelineHeight?: number;\n}\n\n/**\n * Declarative React shell over `@aicut/core` `Editor`. Mounts the\n * editor instance once, mirrors prop changes (`theme`) into it, and\n * forwards events as React-style callbacks.\n *\n * Intentionally uncontrolled for project state — the editor owns the\n * current project. Use `onChange` to persist and `apiRef.setProject`\n * to restore.\n */\nexport function VideoEditor(props: VideoEditorProps) {\n const hostRef = useRef<HTMLDivElement | null>(null);\n const editorRef = useRef<Editor | null>(null);\n // Toolbar slot DOM nodes don't exist until the editor mounts; we\n // hold them in state so React re-runs the render after mount and\n // the portals attach. Tracked separately for left + right because\n // each is independently controlled by host props.\n const [slots, setSlots] = useState<{\n left: HTMLElement;\n right: HTMLElement;\n headerLeft: HTMLElement;\n headerRight: HTMLElement;\n } | null>(null);\n\n // Latest-callback refs so the effect that creates the editor doesn't\n // re-run on every parent render just because props.onChange is a new\n // identity — the editor would otherwise be torn down constantly.\n const cbRef = useRef(props);\n cbRef.current = props;\n\n useEffect(() => {\n const host = hostRef.current;\n if (!host) return;\n const editor = Editor.create({\n container: host,\n project: cbRef.current.defaultProject,\n theme: cbRef.current.theme,\n locale: cbRef.current.locale,\n playbackEngine: cbRef.current.playbackEngine,\n ...(cbRef.current.trackHeight != null\n ? { trackHeight: cbRef.current.trackHeight }\n : {}),\n ...(cbRef.current.rulerHeight != null\n ? { rulerHeight: cbRef.current.rulerHeight }\n : {}),\n ...(cbRef.current.timelineHeight != null\n ? { timelineHeight: cbRef.current.timelineHeight }\n : {}),\n });\n editorRef.current = editor;\n setSlots({\n left: editor.toolbarLeft,\n right: editor.toolbarRight,\n headerLeft: editor.headerLeft,\n headerRight: editor.headerRight,\n });\n\n const offs = [\n editor.on(\"change\", ({ project }) => cbRef.current.onChange?.(project)),\n editor.on(\"export\", ({ project }) => cbRef.current.onExport?.(project)),\n editor.on(\"time\", ({ timeMs }) => cbRef.current.onTimeUpdate?.(timeMs)),\n editor.on(\"play\", () => cbRef.current.onPlay?.()),\n editor.on(\"pause\", () => cbRef.current.onPause?.()),\n editor.on(\"selectionChange\", ({ clipId }) =>\n cbRef.current.onSelectionChange?.(clipId),\n ),\n editor.on(\"error\", ({ error }) => cbRef.current.onError?.(error)),\n ];\n\n cbRef.current.onReady?.(editor);\n\n return () => {\n for (const off of offs) off();\n editor.destroy();\n editorRef.current = null;\n setSlots(null);\n };\n // Editor lifecycle is tied to mount; we deliberately don't list\n // any reactive deps. `theme` changes are pushed through the\n // separate effect below.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useEffect(() => {\n if (props.theme) editorRef.current?.setTheme(props.theme);\n }, [props.theme]);\n\n useEffect(() => {\n if (props.locale) editorRef.current?.setLocale(props.locale);\n }, [props.locale]);\n\n // Reactive — the underlying CSS custom property can be updated on\n // the container any time; the timeline picks up the new height\n // immediately via CSS. No remount required.\n useEffect(() => {\n const host = hostRef.current;\n if (!host) return;\n if (props.timelineHeight != null && props.timelineHeight > 0) {\n host.style.setProperty(\n \"--aicut-timeline-height\",\n `${Math.round(props.timelineHeight)}px`,\n );\n } else {\n host.style.removeProperty(\"--aicut-timeline-height\");\n }\n }, [props.timelineHeight]);\n\n // Deps must include `slots`. Without it, the factory ran once during\n // the first commit — BEFORE the useEffect above had a chance to\n // create the editor — so `apiRef.current` was permanently locked to\n // null. `slots` flips from null to a real value the same instant\n // the editor is created, so it's the cleanest re-run trigger.\n useImperativeHandle<VideoEditorApi | null, VideoEditorApi | null>(\n props.apiRef,\n () => editorRef.current,\n [slots],\n );\n\n return (\n <div\n ref={hostRef}\n className={props.className}\n style={props.style}\n data-aicut-host=\"\"\n >\n {slots && props.toolbarLeft != null\n ? createPortal(props.toolbarLeft, slots.left)\n : null}\n {slots && props.toolbarRight != null\n ? createPortal(props.toolbarRight, slots.right)\n : null}\n {slots && props.headerLeft != null\n ? createPortal(props.headerLeft, slots.headerLeft)\n : null}\n {slots && props.headerRight != null\n ? createPortal(props.headerRight, slots.headerRight)\n : null}\n </div>\n );\n}\n","import {\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n type CSSProperties,\n type ReactNode,\n type Ref,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport {\n Timeline as CoreTimeline,\n type Clip,\n type Locale,\n type Ms,\n type Project,\n type TimelineOptions,\n} from \"@aicut/core\";\n\n/** Imperative handle exposed via `apiRef`. */\nexport interface TimelineApi {\n setProject(p: Project): void;\n getProject(): Project;\n setTime(t: Ms): void;\n getTime(): Ms;\n setScale(pxPerSec: number): void;\n getScale(): number;\n setSelection(id: string | null): void;\n getSelection(): string | null;\n setSnap(snap: boolean): void;\n fitToWindow(): void;\n getDebugInfo(): ReturnType<CoreTimeline[\"getDebugInfo\"]>;\n}\n\nexport interface TimelineProps {\n /** Initial project. Use `apiRef.current.setProject(...)` to swap. */\n defaultProject: Project;\n /** Initial scale (px/sec). Defaults to 80; auto-fits on first render. */\n defaultScale?: number;\n /** Initial playhead position. */\n defaultTime?: Ms;\n /** Initial selection. */\n defaultSelectedClipId?: string | null;\n\n /** Hide the left header column (compact / frame-picker mode). */\n showHeader?: boolean;\n /** Disable all editing interactions. */\n readOnly?: boolean;\n /** Snap to clip edges + playhead when dragging. Default true. */\n snap?: boolean;\n /** Apply fit-to-window on mount once duration is known. Default true. */\n autoFit?: boolean;\n /** UI string overrides (English default). */\n locale?: Partial<Locale>;\n /**\n * Render a 36px top toolbar strip with empty left/right flex slots\n * for host-supplied controls. Default false. Pair with `toolbarLeft`\n * / `toolbarRight` to inject content.\n */\n toolbar?: boolean;\n /** Rendered into the left slot of the timeline toolbar (toolbar must be true). */\n toolbarLeft?: ReactNode;\n /** Rendered into the right slot of the timeline toolbar. */\n toolbarRight?: ReactNode;\n\n className?: string;\n style?: CSSProperties;\n\n apiRef?: Ref<TimelineApi | null>;\n\n onSeek?: (timeMs: Ms) => void;\n onSelectClip?: (clipId: string | null) => void;\n onScaleChange?: (pxPerSec: number) => void;\n onMoveClip?: TimelineOptions[\"onMoveClip\"];\n onResizeClip?: TimelineOptions[\"onResizeClip\"];\n onChange?: (project: Project) => void;\n}\n\n/**\n * Standalone, framework-agnostic canvas Timeline wrapped for React.\n * Mount it without an `Editor` for use cases like a video frame-picker:\n *\n * ```tsx\n * <Timeline\n * defaultProject={{ version: 1, sources: [video], tracks: [{ id, kind: \"video\", clips: [{...}] }] }}\n * showHeader={false}\n * readOnly\n * onSeek={(ms) => setCurrentMs(ms)}\n * />\n * ```\n *\n * Uncontrolled for `project` and `pxPerSec` — the underlying Timeline\n * owns them and reports changes via callbacks. Call methods on\n * `apiRef.current` to drive it imperatively (mirroring ag-Grid /\n * VideoEditor patterns).\n */\nexport function Timeline(props: TimelineProps) {\n const hostRef = useRef<HTMLDivElement | null>(null);\n const tlRef = useRef<CoreTimeline | null>(null);\n const [slots, setSlots] = useState<{\n left: HTMLElement;\n right: HTMLElement;\n } | null>(null);\n\n // Latest-callback ref so the create-once effect doesn't tear the\n // timeline down on every render just because callback identities\n // change.\n const cbRef = useRef(props);\n cbRef.current = props;\n\n useEffect(() => {\n const host = hostRef.current;\n if (!host) return;\n const tl = CoreTimeline.create({\n container: host,\n project: cbRef.current.defaultProject,\n pxPerSec: cbRef.current.defaultScale,\n time: cbRef.current.defaultTime,\n selectedClipId: cbRef.current.defaultSelectedClipId ?? null,\n showHeader: cbRef.current.showHeader,\n readOnly: cbRef.current.readOnly,\n snap: cbRef.current.snap,\n autoFit: cbRef.current.autoFit,\n locale: cbRef.current.locale,\n toolbar: cbRef.current.toolbar,\n onSeek: (t) => cbRef.current.onSeek?.(t),\n onSelectClip: (id) => cbRef.current.onSelectClip?.(id),\n onScaleChange: (s) => cbRef.current.onScaleChange?.(s),\n onMoveClip: (id, opts) => cbRef.current.onMoveClip?.(id, opts),\n onResizeClip: (id, e) => cbRef.current.onResizeClip?.(id, e),\n onChange: (p) => cbRef.current.onChange?.(p),\n });\n tlRef.current = tl;\n if (tl.toolbarLeft && tl.toolbarRight) {\n setSlots({ left: tl.toolbarLeft, right: tl.toolbarRight });\n }\n return () => {\n tl.destroy();\n tlRef.current = null;\n setSlots(null);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useEffect(() => {\n if (props.locale) tlRef.current?.setLocale(props.locale);\n }, [props.locale]);\n\n useImperativeHandle<TimelineApi | null, TimelineApi | null>(\n props.apiRef,\n () => {\n const tl = tlRef.current;\n if (!tl) return null;\n return {\n setProject: (p) => tl.setProject(p),\n getProject: () => tl.getProject(),\n setTime: (t) => tl.setTime(t),\n getTime: () => tl.getTime(),\n setScale: (s) => tl.setScale(s),\n getScale: () => tl.getScale(),\n setSelection: (id) => tl.setSelection(id),\n getSelection: () => tl.getSelection(),\n setSnap: (s) => tl.setSnap(s),\n fitToWindow: () => tl.fitToWindow(),\n getDebugInfo: () => tl.getDebugInfo(),\n };\n },\n // Same caveat as VideoEditor.tsx — factory must re-run once the\n // timeline is created in useEffect, otherwise apiRef.current is\n // null forever. `slots` flips from null to a real value the\n // instant the timeline is ready, so it's the cleanest trigger.\n [slots],\n );\n\n return (\n <div\n ref={hostRef}\n className={props.className}\n style={{ width: \"100%\", height: 240, ...props.style }}\n data-aicut-timeline-host=\"\"\n >\n {slots && props.toolbarLeft != null\n ? createPortal(props.toolbarLeft, slots.left)\n : null}\n {slots && props.toolbarRight != null\n ? createPortal(props.toolbarRight, slots.right)\n : null}\n </div>\n );\n\n // Type-only re-export used to keep React/Vue prop typings in lockstep\n // with the core. Reference here so the symbol isn't tree-shaken.\n void ({} as Clip);\n}\n","export { VideoEditor } from \"./VideoEditor.js\";\nexport type { VideoEditorProps, VideoEditorApi } from \"./VideoEditor.js\";\nexport { Timeline } from \"./Timeline.js\";\nexport type { TimelineProps, TimelineApi } from \"./Timeline.js\";\nexport type {\n Project,\n MediaSource,\n Track,\n Clip,\n Ms,\n Theme,\n EditorApi,\n Locale,\n PlaybackEngine,\n PlaybackEngineFactory,\n PlaybackEngineOptions,\n CanvasCompositorEngineOptions,\n} from \"@aicut/core\";\nexport {\n createEmptyProject,\n createId,\n localeEn,\n localeZh,\n HtmlVideoEngine,\n htmlVideoEngineFactory,\n CanvasCompositorEngine,\n canvasCompositorEngineFactory,\n // Live bindings — re-reading them after `setTimelineMetrics` (which\n // EditorOptions.trackHeight / .rulerHeight calls under the hood)\n // returns the updated values.\n TRACK_HEIGHT,\n RULER_HEIGHT,\n HEADER_WIDTH,\n setTimelineMetrics,\n} from \"@aicut/core\";\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,OAOK;AAsMH;AA7GG,SAAS,YAAY,OAAyB;AACnD,QAAM,UAAU,OAA8B,IAAI;AAClD,QAAM,YAAY,OAAsB,IAAI;AAK5C,QAAM,CAAC,OAAO,QAAQ,IAAI,SAKhB,IAAI;AAKd,QAAM,QAAQ,OAAO,KAAK;AAC1B,QAAM,UAAU;AAEhB,YAAU,MAAM;AACd,UAAM,OAAO,QAAQ;AACrB,QAAI,CAAC,KAAM;AACX,UAAM,SAAS,OAAO,OAAO;AAAA,MAC3B,WAAW;AAAA,MACX,SAAS,MAAM,QAAQ;AAAA,MACvB,OAAO,MAAM,QAAQ;AAAA,MACrB,QAAQ,MAAM,QAAQ;AAAA,MACtB,gBAAgB,MAAM,QAAQ;AAAA,MAC9B,GAAI,MAAM,QAAQ,eAAe,OAC7B,EAAE,aAAa,MAAM,QAAQ,YAAY,IACzC,CAAC;AAAA,MACL,GAAI,MAAM,QAAQ,eAAe,OAC7B,EAAE,aAAa,MAAM,QAAQ,YAAY,IACzC,CAAC;AAAA,MACL,GAAI,MAAM,QAAQ,kBAAkB,OAChC,EAAE,gBAAgB,MAAM,QAAQ,eAAe,IAC/C,CAAC;AAAA,IACP,CAAC;AACD,cAAU,UAAU;AACpB,aAAS;AAAA,MACP,MAAM,OAAO;AAAA,MACb,OAAO,OAAO;A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AC,MAAM,GAAG,QAAQ,CAAC;AAAA,QAC5B,SAAS,MAAM,GAAG,QAAQ;AAAA,QAC1B,UAAU,CAAC,MAAM,GAAG,SAAS,CAAC;AAAA,QAC9B,UAAU,MAAM,GAAG,SAAS;AAAA,QAC5B,cAAc,CAAC,OAAO,GAAG,aAAa,EAAE;AAAA,QACxC,cAAc,MAAM,GAAG,aAAa;AAAA,QACpC,SAAS,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,QAC5B,aAAa,MAAM,GAAG,YAAY;AAAA,QAClC,cAAc,MAAM,GAAG,aAAa;AAAA,MACtC;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA,IAKA,CAAC,KAAK;AAAA,EACR;AAEA,SACE,gBAAAI;AAAA,IAAC;AAAA;AAAA,MACC,KAAK;AAAA,MACL,WAAW,MAAM;AAAA,MACjB,OAAO,EAAE,OAAO,QAAQ,QAAQ,KAAK,GAAG,MAAM,MAAM;AAAA,MACpD,4BAAyB;AAAA,MAExB;AAAA,iBAAS,MAAM,eAAe,OAC3BD,cAAa,MAAM,aAAa,MAAM,IAAI,IAC1C;AAAA,QACH,SAAS,MAAM,gBAAgB,OAC5BA,cAAa,MAAM,cAAc,MAAM,KAAK,IAC5C;AAAA;AAAA;AAAA,EACN;AAKF,OAAM,CAAC;AACT;;;AC/KA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAIA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":["useEffect","useImperativeHandle","useRef","useState","createPortal","jsxs"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/webcodecs.ts
|
|
21
|
+
var webcodecs_exports = {};
|
|
22
|
+
__export(webcodecs_exports, {
|
|
23
|
+
WebCodecsEngine: () => import_webcodecs.WebCodecsEngine,
|
|
24
|
+
isWebCodecsSupported: () => import_webcodecs.isWebCodecsSupported,
|
|
25
|
+
webCodecsEngineFactory: () => import_webcodecs.webCodecsEngineFactory
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(webcodecs_exports);
|
|
28
|
+
var import_webcodecs = require("@aicut/core/webcodecs");
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
WebCodecsEngine,
|
|
32
|
+
isWebCodecsSupported,
|
|
33
|
+
webCodecsEngineFactory
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=webcodecs.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/webcodecs.ts"],"sourcesContent":["/**\n * @aicut/react/webcodecs — separate entry that pulls mp4box.js for\n * frame-accurate WebCodecs playback. Users who never import this\n * path don't pay the mp4box bundle cost.\n *\n * Pass the factory directly to `<VideoEditor playbackEngine={…} />`,\n * or wrap it in a closure to flip `debug: true`.\n */\nexport {\n WebCodecsEngine,\n webCodecsEngineFactory,\n isWebCodecsSupported,\n type WebCodecsEngineOptions,\n type DemuxedTrack,\n} from \"@aicut/core/webcodecs\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,uBAMO;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DemuxedTrack, WebCodecsEngine, WebCodecsEngineOptions, isWebCodecsSupported, webCodecsEngineFactory } from '@aicut/core/webcodecs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DemuxedTrack, WebCodecsEngine, WebCodecsEngineOptions, isWebCodecsSupported, webCodecsEngineFactory } from '@aicut/core/webcodecs';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/webcodecs.ts
|
|
2
|
+
import {
|
|
3
|
+
WebCodecsEngine,
|
|
4
|
+
webCodecsEngineFactory,
|
|
5
|
+
isWebCodecsSupported
|
|
6
|
+
} from "@aicut/core/webcodecs";
|
|
7
|
+
export {
|
|
8
|
+
WebCodecsEngine,
|
|
9
|
+
isWebCodecsSupported,
|
|
10
|
+
webCodecsEngineFactory
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=webcodecs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/webcodecs.ts"],"sourcesContent":["/**\n * @aicut/react/webcodecs — separate entry that pulls mp4box.js for\n * frame-accurate WebCodecs playback. Users who never import this\n * path don't pay the mp4box bundle cost.\n *\n * Pass the factory directly to `<VideoEditor playbackEngine={…} />`,\n * or wrap it in a closure to flip `debug: true`.\n */\nexport {\n WebCodecsEngine,\n webCodecsEngineFactory,\n isWebCodecsSupported,\n type WebCodecsEngineOptions,\n type DemuxedTrack,\n} from \"@aicut/core/webcodecs\";\n"],"mappings":";AAQA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aicut/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "React wrapper for the AiCut video editor + lighting picker — thin declarative shells over @aicut/core.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "ziqiang <ziqiangytu@gmail.com>",
|
|
@@ -52,6 +52,11 @@
|
|
|
52
52
|
"types": "./dist/lighting.d.ts",
|
|
53
53
|
"import": "./dist/lighting.js",
|
|
54
54
|
"require": "./dist/lighting.cjs"
|
|
55
|
+
},
|
|
56
|
+
"./webcodecs": {
|
|
57
|
+
"types": "./dist/webcodecs.d.ts",
|
|
58
|
+
"import": "./dist/webcodecs.js",
|
|
59
|
+
"require": "./dist/webcodecs.cjs"
|
|
55
60
|
}
|
|
56
61
|
},
|
|
57
62
|
"files": [
|
|
@@ -59,7 +64,7 @@
|
|
|
59
64
|
"README.md"
|
|
60
65
|
],
|
|
61
66
|
"dependencies": {
|
|
62
|
-
"@aicut/core": "0.
|
|
67
|
+
"@aicut/core": "0.5.0"
|
|
63
68
|
},
|
|
64
69
|
"peerDependencies": {
|
|
65
70
|
"react": "^18.0.0 || ^19.0.0",
|