@aicut/core 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ziqiang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,201 @@
1
+ # @aicut/core
2
+
3
+ Framework-agnostic video editor engine. Owns the project data model, the HTML5 playback engine, the canvas timeline (ruler, tracks, clips, thumbnails, playhead, snap, in-canvas scrollbars), and a vanilla DOM toolbar.
4
+
5
+ For React or Vue apps, prefer **[@aicut/react](https://www.npmjs.com/package/@aicut/react)** or **[@aicut/vue](https://www.npmjs.com/package/@aicut/vue)** — they wrap this same engine.
6
+
7
+ ```bash
8
+ pnpm add @aicut/core
9
+ ```
10
+
11
+ ## Quick start
12
+
13
+ ```ts
14
+ import { Editor } from "@aicut/core";
15
+ import "@aicut/core/styles.css";
16
+
17
+ const editor = Editor.create({
18
+ container: document.getElementById("app")!,
19
+ project: {
20
+ version: 1,
21
+ sources: [
22
+ { id: "s1", url: "/media/a.mp4", kind: "video", name: "a.mp4" },
23
+ ],
24
+ tracks: [
25
+ {
26
+ id: "t1",
27
+ kind: "video",
28
+ clips: [{ id: "c1", sourceId: "s1", in: 0, out: 5000, start: 0 }],
29
+ },
30
+ ],
31
+ },
32
+ });
33
+
34
+ editor.on("change", ({ project }) => localStorage.setItem("aicut", JSON.stringify(project)));
35
+ editor.on("export", ({ project }) => fetch("/api/export", {
36
+ method: "POST",
37
+ headers: { "content-type": "application/json" },
38
+ body: JSON.stringify({ project }),
39
+ }));
40
+ ```
41
+
42
+ The editor renders into your `container`. Call methods on the returned `editor` instance to drive it imperatively.
43
+
44
+ ## API surface
45
+
46
+ ### Playback & editing
47
+
48
+ ```ts
49
+ editor.play(); editor.pause(); editor.togglePlay(); editor.seek(timeMs);
50
+ editor.split(); // split at playhead
51
+ editor.trimLeft(); // trim selected clip's left edge to playhead
52
+ editor.trimRight();
53
+ editor.removeClip(clipId);
54
+ editor.setClipSpeed(clipId, 2);
55
+
56
+ editor.undo(); editor.redo();
57
+ editor.canUndo(); editor.canRedo();
58
+ ```
59
+
60
+ ### Project, sources, tracks
61
+
62
+ ```ts
63
+ editor.getProject(); // deep clone of current state
64
+ editor.setProject(p); // replace, preserves auto-fit etc.
65
+ editor.reset(); // empty single-track project
66
+ editor.addSource({ id, url, kind: "video" });
67
+ editor.addTrack("video");
68
+ editor.removeTrack(trackId);
69
+ editor.moveClip(clipId, { start, trackId, newTrack });
70
+ editor.resizeClip(clipId, { in, out, start });
71
+ ```
72
+
73
+ ### Viewport
74
+
75
+ ```ts
76
+ editor.getScale(); editor.setScale(80); // px per second
77
+ editor.getSnap(); editor.setSnap(false);
78
+ editor.getSelection(); editor.setSelection(clipId);
79
+ editor.enterFullscreen(); editor.exitFullscreen();
80
+ ```
81
+
82
+ ### Events
83
+
84
+ ```ts
85
+ const off = editor.on("change", ({ project }) => /* … */);
86
+ editor.on("time", ({ timeMs }) => /* playback tick */);
87
+ editor.on("export", ({ project }) => /* host-triggered export */);
88
+ editor.on("selectionChange", ({ clipId }) => /* … */);
89
+ editor.on("historyChange", ({ canUndo, canRedo }) => /* … */);
90
+ editor.on("ready", ({ sourceId }) => /* per-source metadata loaded */);
91
+ editor.on("scaleChange", ({ pxPerSec }) => /* … */);
92
+ editor.on("snapChange", ({ snap }) => /* … */);
93
+ editor.on("error", ({ error }) => /* … */);
94
+ off(); // unsubscribe
95
+ ```
96
+
97
+ ### Triggering export
98
+
99
+ The library never calls a backend on its own — `requestExport()` fires the `export` event with the current project JSON; your handler decides what to do.
100
+
101
+ ```ts
102
+ editor.requestExport(); // → emits "export" with project
103
+ ```
104
+
105
+ ## Theming
106
+
107
+ CSS variables; pass any subset via `theme` and the rest fall back to the defaults.
108
+
109
+ ```ts
110
+ Editor.create({
111
+ container,
112
+ project,
113
+ theme: {
114
+ controlsBg: "#1f1f22",
115
+ controlsText: "rgba(255, 255, 255, 0.85)",
116
+ controlsBorder: "rgba(255, 255, 255, 0.08)",
117
+ controlsHover: "rgba(255, 255, 255, 0.08)",
118
+ controlsActive: "rgba(255, 255, 255, 0.12)",
119
+ previewBg: "#000", // letterbox colour
120
+ },
121
+ });
122
+
123
+ editor.setTheme({ controlsBg: "#f6f6f8", previewBg: "#e4e4e7" }); // runtime swap
124
+ ```
125
+
126
+ Every variable is also a plain CSS custom property — `.aicut-root { --aicut-controls-bg: …; }` works too.
127
+
128
+ ## Internationalisation
129
+
130
+ English by default. Bundled `localeZh` covers the whole editor (toolbar tooltips, exit-fullscreen overlay, canvas track headers).
131
+
132
+ ```ts
133
+ import { Editor, localeZh } from "@aicut/core";
134
+
135
+ Editor.create({ container, project, locale: localeZh });
136
+
137
+ // Partial override + runtime swap
138
+ editor.setLocale({ undo: "Annuler", redo: "Refaire" });
139
+ ```
140
+
141
+ `Locale` is exported as a type if you need to typecheck a custom pack.
142
+
143
+ ## Toolbar slots
144
+
145
+ Both the editor's built-in toolbar and the standalone `Timeline`'s optional toolbar reserve `toolbarLeft` / `toolbarRight` slot DOM elements for host-supplied controls.
146
+
147
+ ```ts
148
+ const editor = Editor.create({ container, project });
149
+ const exportBtn = document.createElement("button");
150
+ exportBtn.textContent = "Export";
151
+ exportBtn.onclick = () => editor.requestExport();
152
+ editor.toolbarRight.appendChild(exportBtn);
153
+ ```
154
+
155
+ The library paints nothing into either slot and renders no separator until they're populated.
156
+
157
+ ## Standalone Timeline
158
+
159
+ Use the canvas timeline without the rest of the editor — useful for a frame-picker, thumbnail strip, or a read-only preview.
160
+
161
+ ```ts
162
+ import { Timeline } from "@aicut/core";
163
+
164
+ const tl = Timeline.create({
165
+ container: document.getElementById("strip")!,
166
+ project: { /* one-clip project */ },
167
+ showHeader: false,
168
+ readOnly: true,
169
+ onSeek: (ms) => console.log("picked", ms),
170
+ });
171
+ ```
172
+
173
+ ## Data model
174
+
175
+ ```ts
176
+ interface Project {
177
+ version: 1;
178
+ sources: MediaSource[];
179
+ tracks: Track[];
180
+ }
181
+
182
+ interface MediaSource {
183
+ id: string; url: string; kind: "video" | "audio";
184
+ duration?: number; name?: string;
185
+ }
186
+
187
+ interface Track { id: string; kind: "video" | "audio"; clips: Clip[]; }
188
+
189
+ interface Clip {
190
+ id: string; sourceId: string;
191
+ in: Ms; out: Ms; // window into the source (exclusive at `out`)
192
+ start: Ms; // position on the timeline
193
+ speed?: number;
194
+ }
195
+
196
+ type Ms = number; // integer milliseconds; no frame-rate coupling
197
+ ```
198
+
199
+ ## License
200
+
201
+ MIT