@melite/models-h3 0.0.0-stage → 0.1.4-alpha

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,215 @@
1
+ export const SEAM_OVERLAP_FRAMES = 22;
2
+ export const GRID_BASE_FRAMES = 22;
3
+ export const GRID_STEP_FRAMES = 17;
4
+ export const GRID_MAX_FRAMES = 362;
5
+ export const GRID_REMAINDER = 5;
6
+ export const IMAGE_BUS_SLOTS = 9;
7
+ export const REF_CAPS = {
8
+ images: 8,
9
+ videos: 3,
10
+ audios: 3,
11
+ };
12
+ export function transitionOverlap(transition) {
13
+ return transition === 'cut' ? 0 : SEAM_OVERLAP_FRAMES;
14
+ }
15
+ export function spanOverlap(span) {
16
+ return transitionOverlap(span.transition);
17
+ }
18
+ export function spanStanzaFrames(span, carry = 0) {
19
+ const k = Math.round((span.end - span.start + carry - GRID_BASE_FRAMES) / GRID_STEP_FRAMES);
20
+ return Math.min(GRID_MAX_FRAMES, Math.max(GRID_BASE_FRAMES, GRID_BASE_FRAMES + GRID_STEP_FRAMES * k));
21
+ }
22
+ export function carriedSpanGrid(span, carry = SEAM_OVERLAP_FRAMES) {
23
+ const generatedStart = span.start - carry;
24
+ const requestedLength = span.end - span.start + carry;
25
+ const length = spanStanzaFrames(span, carry);
26
+ const rawIndex = (requestedLength - GRID_BASE_FRAMES) / GRID_STEP_FRAMES;
27
+ const maxIndex = (GRID_MAX_FRAMES - GRID_BASE_FRAMES) / GRID_STEP_FRAMES;
28
+ const lowerIndex = Math.max(0, Math.min(maxIndex, Math.floor(rawIndex)));
29
+ const upperIndex = Math.max(0, Math.min(maxIndex, Math.ceil(rawIndex)));
30
+ const endAt = (index) => generatedStart + GRID_BASE_FRAMES + GRID_STEP_FRAMES * index;
31
+ return {
32
+ generatedStart,
33
+ generatedEnd: generatedStart + length,
34
+ length,
35
+ lowerEnd: endAt(lowerIndex),
36
+ upperEnd: endAt(upperIndex),
37
+ };
38
+ }
39
+ export function assertCarriedSpanGrid(span, where, carry = SEAM_OVERLAP_FRAMES) {
40
+ const grid = carriedSpanGrid(span, carry);
41
+ const requestedLength = span.end - span.start + carry;
42
+ if (grid.length !== requestedLength) {
43
+ const legal = grid.lowerEnd === grid.upperEnd
44
+ ? `${grid.lowerEnd}`
45
+ : `${grid.lowerEnd} and ${grid.upperEnd}`;
46
+ throw new Error(`${where}: authored range ${span.start}→${span.end} cannot land on the 22+17k carried grid; ` +
47
+ `generated snapped range ${grid.generatedStart}→${grid.generatedEnd}; ` +
48
+ `legal neighboring end frames ${legal} ` +
49
+ `(a carried window's span is 17f — its 22f seam is the generation head; ` +
50
+ `a first or cut window is 22+17f)`);
51
+ }
52
+ return grid.length;
53
+ }
54
+ export function gridSnap(length) {
55
+ const k = Math.round((length - GRID_BASE_FRAMES) / GRID_STEP_FRAMES);
56
+ return Math.min(GRID_MAX_FRAMES, Math.max(GRID_BASE_FRAMES, GRID_BASE_FRAMES + GRID_STEP_FRAMES * k));
57
+ }
58
+ /** THE GRID PREDICATE, one owner: a length the engine can render is
59
+ * 22+17k inside [22,362]. Every refusal door asks this question, so
60
+ * knob pins, single windows, cut windows, and carried windows cannot
61
+ * drift into different laws. */
62
+ export function isGridLength(length) {
63
+ return Number.isInteger(length) &&
64
+ length >= GRID_BASE_FRAMES &&
65
+ length <= GRID_MAX_FRAMES &&
66
+ (length - GRID_BASE_FRAMES) % GRID_STEP_FRAMES === 0;
67
+ }
68
+ export function assertGridLength(length, where) {
69
+ if (typeof length !== 'number' || !isGridLength(length)) {
70
+ const nearest = typeof length === 'number' && Number.isFinite(length)
71
+ ? gridSnap(Math.min(GRID_MAX_FRAMES, Math.max(GRID_BASE_FRAMES, Math.round(length))))
72
+ : 124;
73
+ throw new Error(`${where}: length ${String(length)}f is off-grid — the engine renders ` +
74
+ `22+17k frames in [22,362] (nearest legal: ${nearest}f); ` +
75
+ `the doc-proven geometry is 0→124→243→362`);
76
+ }
77
+ return length;
78
+ }
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+ export function assertSpanGrid(span, where, carry = 0) {
88
+ if (carry > 0)
89
+ return assertCarriedSpanGrid(span, where, carry);
90
+ const length = span.end - span.start;
91
+ if (!isGridLength(length)) {
92
+ throw new Error(`${where}: authored range ${span.start}→${span.end} has length ${length}f, which cannot land on the 22+17k grid ` +
93
+ `(nearest legal: ${gridSnap(length)}f); the doc-proven geometry is 0→124→243→362 ` +
94
+ `(a first or cut window is 22+17f; a carried window's span is 17f — its 22f seam is the generation head)`);
95
+ }
96
+ return length;
97
+ }
98
+ export function deliveredFrames(call, index) {
99
+ const span = call.end_frame - call.start_frame;
100
+ if (index === 0 || call.transition === 'cut')
101
+ return span;
102
+ return Math.max(0, span - SEAM_OVERLAP_FRAMES);
103
+ }
104
+ export function imageReferenceCap(hasLastFrame) {
105
+ return hasLastFrame ? REF_CAPS.images - 1 : REF_CAPS.images;
106
+ }
107
+ export function splitRefList(value) {
108
+ if (!value)
109
+ return [];
110
+ const out = [];
111
+ let i = 0;
112
+ while (i < value.length) {
113
+ while (i < value.length && (value[i] === ',' || value[i] === ' ' || value[i] === '\t'))
114
+ i++;
115
+ if (i >= value.length)
116
+ break;
117
+ const start = i;
118
+ const isData = value.startsWith('data:', i);
119
+ let mimeComma = false;
120
+ while (i < value.length) {
121
+ if (value[i] === ',') {
122
+ if (isData && !mimeComma) {
123
+ mimeComma = true;
124
+ i++;
125
+ continue;
126
+ }
127
+ break;
128
+ }
129
+ i++;
130
+ }
131
+ let end = i;
132
+ while (end > start && (value[end - 1] === ' ' || value[end - 1] === '\t'))
133
+ end--;
134
+ out.push(value.slice(start, end));
135
+ }
136
+ return out;
137
+ }
138
+ export function normalizeDeclaredRefs(value) {
139
+ if (Array.isArray(value)) {
140
+ return value.filter((entry) => typeof entry === 'string' && entry.trim() !== '');
141
+ }
142
+ if (typeof value === 'string')
143
+ return splitRefList(value);
144
+ return [];
145
+ }
146
+ export function joinRefList(value) {
147
+ if (Array.isArray(value)) {
148
+ const entries = value.map(String).map((entry) => entry.trim()).filter(Boolean);
149
+ return entries.length > 0 ? entries.join(', ') : undefined;
150
+ }
151
+ if (typeof value === 'string' && value.trim())
152
+ return value.trim();
153
+ return undefined;
154
+ }
155
+ export function mergeDeclaredRefs(declared, perCall) {
156
+ return [...declared, ...perCall.filter((entry) => !declared.includes(entry))];
157
+ }
158
+ export function refGenreOf(name, url) {
159
+ const lowerName = name.toLowerCase();
160
+ if (/^video_w\d+_/.test(lowerName)) {
161
+ if (lowerName.endsWith('_last_frame') || lowerName.includes('_prev'))
162
+ return 'image';
163
+ return 'video';
164
+ }
165
+ const source = `${lowerName} ${url ? url.toLowerCase().split('?')[0] : ''}`;
166
+ const extension = source.split('.').pop().split(/[^a-z0-9]/)[0];
167
+ if (['png', 'jpg', 'jpeg', 'webp', 'gif', 'bmp', 'avif'].includes(extension))
168
+ return 'image';
169
+ if (['mp4', 'webm', 'mov', 'mkv', 'avi', 'm4v'].includes(extension))
170
+ return 'video';
171
+ if (['mp3', 'wav', 'flac', 'ogg', 'm4a', 'aac', 'opus'].includes(extension))
172
+ return 'audio';
173
+ return 'other';
174
+ }
175
+ export const KNOB_ORDER = [
176
+ 'steps', 'denoise', 'sampler_name', 'sched_name',
177
+ 'shift_video', 'shift_audio',
178
+ 'sla_sparsity', 'sla_block_size',
179
+ 'sla_min_seq_len', 'sla_dense_last_steps',
180
+ 'sla_protect_audio', 'sla_stabilize_motion',
181
+ 'sla_reference_protection', 'sla_dense_backend',
182
+ 'sla_dense_steps', 'sla_disable_fp16_accum',
183
+ 'sharpen_enabled', 'sharpen_method', 'sharpen_strength',
184
+ 'sharpen_radius', 'sharpen_threshold', 'sharpen_iterations',
185
+ 'interpolate_enabled', 'interp_model', 'interp_multiplier',
186
+ 'length',
187
+ ];
188
+ export const CALL_KNOB_KEYS = new Set(KNOB_ORDER);
189
+ export const CALL_KEYS = new Set([
190
+ 'text', 'start_frame', 'end_frame', 'image', 'clip', 'audio',
191
+ 'transition', 'knobs', 'refs',
192
+ 'ref_image', 'image_name', 'ref_images', 'ref_videos', 'ref_audios',
193
+ 'beats', 'last_frame', 'first_frame_prev_sec', 'seam_carry',
194
+ ]);
195
+ export const LEGACY_KNOB_KEY = {
196
+ sampling_steps: 'steps',
197
+ sampler: 'sampler_name',
198
+ scheduler: 'sched_name',
199
+ h3_sla_sparsity: 'sla_sparsity',
200
+ h3_sla_block_size: 'sla_block_size',
201
+ h3_sla_min_seq_len: 'sla_min_seq_len',
202
+ h3_sla_dense_last_steps: 'sla_dense_last_steps',
203
+ h3_sla_protect_audio: 'sla_protect_audio',
204
+ h3_sla_stabilize_motion: 'sla_stabilize_motion',
205
+ h3_sla_reference_protection: 'sla_reference_protection',
206
+ h3_sla_dense_backend: 'sla_dense_backend',
207
+ h3_sla_dense_steps: 'sla_dense_steps',
208
+ h3_sla_disable_fp16_accum: 'sla_disable_fp16_accum',
209
+ interpolate_model: 'interp_model',
210
+ interpolate_multiplier: 'interp_multiplier',
211
+ };
212
+ export function migrateCallKnobKey(key) {
213
+ return LEGACY_KNOB_KEY[key] ?? key;
214
+ }
215
+ //# sourceMappingURL=timelineContract.js.map
package/package.json CHANGED
@@ -1,6 +1,59 @@
1
1
  {
2
2
  "name": "@melite/models-h3",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.4-alpha",
4
+ "license": "SSPL-1.0",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./lib/index.d.ts",
9
+ "default": "./lib/index.js"
10
+ },
11
+ "./package.json": "./package.json",
12
+ "./mods/loras": {
13
+ "types": "./lib/mods/loras.d.ts",
14
+ "default": "./lib/mods/loras.js"
15
+ },
16
+ "./timelineContract": {
17
+ "types": "./lib/timelineContract.d.ts",
18
+ "default": "./lib/timelineContract.js"
19
+ },
20
+ "./filmMix": {
21
+ "types": "./lib/filmMix.d.ts",
22
+ "default": "./lib/filmMix.js"
23
+ },
24
+ "./actions": {
25
+ "types": "./lib/actions.d.ts",
26
+ "default": "./lib/actions.js"
27
+ },
28
+ "./schema": {
29
+ "types": "./lib/schema.d.ts",
30
+ "default": "./lib/schema.js"
31
+ }
32
+ },
33
+ "dependencies": {
34
+ "@deepseek-ai/schemastery": "^3.18.4",
35
+ "@melite/comfyui-cordis": "0.1.4-alpha",
36
+ "@melite/comfyui-card-kit": "0.1.4-alpha",
37
+ "@melite/contracts": "0.1.4-alpha"
38
+ },
39
+ "devDependencies": {
40
+ "@types/node": "^22.20.0",
41
+ "typescript": "^5.9.3",
42
+ "@deepseek-ai/cordis": "^4.0.4"
43
+ },
44
+ "files": [
45
+ "lib/index.js",
46
+ "lib/**/*.js",
47
+ "lib/**/*.d.ts"
48
+ ],
49
+ "peerDependencies": {
50
+ "@deepseek-ai/cordis": "^4.0.4"
51
+ },
52
+ "scripts": {
53
+ "build": "tsc -p tsconfig.build-mods.json && tsc -p tsconfig.build.json",
54
+ "typecheck": "tsc --noEmit"
55
+ },
56
+ "publishConfig": {
57
+ "access": "public"
58
+ }
59
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.