@aelionsdk/render-ir 0.1.0-beta.1

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 FoyonaCZY and AelionSDK contributors
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,7 @@
1
+ # @aelionsdk/render-ir
2
+
3
+ Incremental render intermediate representation compiler for AelionSDK
4
+
5
+ Install with `npm install @aelionsdk/render-ir@next`.
6
+
7
+ Version 0.1.0-beta.1 is a prerelease and its API may change before the first stable release. This package is part of [AelionSDK](https://github.com/FoyonaCZY/AelionSDK); see the repository README for supported browsers, examples and deployment requirements.
@@ -0,0 +1,16 @@
1
+ export interface CaptionCue {
2
+ readonly id?: string;
3
+ readonly startUs: number;
4
+ readonly endUs: number;
5
+ readonly text: string;
6
+ readonly settings?: Readonly<Record<string, string>>;
7
+ }
8
+ export interface CaptionSerialization {
9
+ readonly text: string;
10
+ readonly warnings: readonly string[];
11
+ }
12
+ export declare function parseSrt(input: string): readonly CaptionCue[];
13
+ export declare function serializeSrt(cues: readonly CaptionCue[]): CaptionSerialization;
14
+ export declare function parseWebVtt(input: string): readonly CaptionCue[];
15
+ export declare function serializeWebVtt(cues: readonly CaptionCue[]): CaptionSerialization;
16
+ //# sourceMappingURL=captions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"captions.d.ts","sourceRoot":"","sources":["../src/captions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACtD;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC;AAoCD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,UAAU,EAAE,CAuB7D;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,UAAU,EAAE,GAAG,oBAAoB,CAc9E;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,UAAU,EAAE,CA0ChE;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,UAAU,EAAE,GAAG,oBAAoB,CAcjF"}
@@ -0,0 +1,131 @@
1
+ function timestamp(value) {
2
+ const match = /^(?:(\d{1,3}):)?(\d{2}):(\d{2})[,.](\d{3})$/u.exec(value.trim());
3
+ if (match === null)
4
+ throw new TypeError(`CAPTION_TIMESTAMP_INVALID: ${value}`);
5
+ const hours = Number(match[1] ?? 0);
6
+ const minutes = Number(match[2]);
7
+ const seconds = Number(match[3]);
8
+ const milliseconds = Number(match[4]);
9
+ if (minutes >= 60 || seconds >= 60)
10
+ throw new TypeError(`CAPTION_TIMESTAMP_INVALID: ${value}`);
11
+ return ((hours * 60 * 60 + minutes * 60 + seconds) * 1_000 + milliseconds) * 1_000;
12
+ }
13
+ function formatTimestamp(timeUs, separator) {
14
+ if (!Number.isSafeInteger(timeUs) || timeUs < 0)
15
+ throw new RangeError('Caption time is invalid');
16
+ const milliseconds = Math.floor(timeUs / 1_000);
17
+ const hours = Math.floor(milliseconds / 3_600_000);
18
+ const minutes = Math.floor((milliseconds % 3_600_000) / 60_000);
19
+ const seconds = Math.floor((milliseconds % 60_000) / 1_000);
20
+ const millis = milliseconds % 1_000;
21
+ return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}${separator}${millis.toString().padStart(3, '0')}`;
22
+ }
23
+ function validateCues(cues) {
24
+ for (const cue of cues) {
25
+ if (!Number.isSafeInteger(cue.startUs) ||
26
+ !Number.isSafeInteger(cue.endUs) ||
27
+ cue.startUs < 0 ||
28
+ cue.endUs <= cue.startUs) {
29
+ throw new RangeError('CAPTION_RANGE_INVALID');
30
+ }
31
+ }
32
+ }
33
+ export function parseSrt(input) {
34
+ const normalized = input.replaceAll('\r\n', '\n').trim();
35
+ if (normalized.length === 0)
36
+ return [];
37
+ const cues = normalized.split(/\n{2,}/u).map(block => {
38
+ const lines = block.split('\n');
39
+ const timelineIndex = lines.findIndex(line => line.includes('-->'));
40
+ const timeline = lines[timelineIndex];
41
+ if (timelineIndex < 0 || timeline === undefined)
42
+ throw new TypeError('SRT_CUE_INVALID');
43
+ const parts = timeline.split(/\s+-->\s+/u);
44
+ if (parts.length !== 2)
45
+ throw new TypeError('SRT_CUE_INVALID');
46
+ const start = parts[0];
47
+ const end = parts[1];
48
+ if (start === undefined || end === undefined)
49
+ throw new TypeError('SRT_CUE_INVALID');
50
+ const id = timelineIndex > 0 ? lines[0]?.trim() : undefined;
51
+ return {
52
+ ...(id === undefined || id.length === 0 ? {} : { id }),
53
+ startUs: timestamp(start),
54
+ endUs: timestamp(end),
55
+ text: lines.slice(timelineIndex + 1).join('\n'),
56
+ };
57
+ });
58
+ validateCues(cues);
59
+ return cues;
60
+ }
61
+ export function serializeSrt(cues) {
62
+ validateCues(cues);
63
+ const warnings = cues.some(cue => cue.settings !== undefined)
64
+ ? ['SRT does not preserve WebVTT cue settings; settings were omitted.']
65
+ : [];
66
+ return {
67
+ text: `${cues
68
+ .map((cue, index) => `${(index + 1).toString()}\n${formatTimestamp(cue.startUs, ',')} --> ${formatTimestamp(cue.endUs, ',')}\n${cue.text}`)
69
+ .join('\n\n')}\n`,
70
+ warnings,
71
+ };
72
+ }
73
+ export function parseWebVtt(input) {
74
+ const normalized = input
75
+ .replaceAll('\r\n', '\n')
76
+ .replace(/^\uFEFF/u, '')
77
+ .trim();
78
+ if (!normalized.startsWith('WEBVTT'))
79
+ throw new TypeError('WEBVTT_HEADER_MISSING');
80
+ const body = normalized.slice(normalized.indexOf('\n') + 1).trim();
81
+ if (body.length === 0)
82
+ return [];
83
+ const cues = body
84
+ .split(/\n{2,}/u)
85
+ .filter(block => !/^(NOTE|STYLE|REGION)(?:\s|$)/u.test(block))
86
+ .map(block => {
87
+ const lines = block.split('\n');
88
+ const timelineIndex = lines.findIndex(line => line.includes('-->'));
89
+ const timeline = lines[timelineIndex];
90
+ if (timelineIndex < 0 || timeline === undefined)
91
+ throw new TypeError('WEBVTT_CUE_INVALID');
92
+ const match = /^(\S+)\s+-->\s+(\S+)(?:\s+(.*))?$/u.exec(timeline);
93
+ if (match?.[1] === undefined || match[2] === undefined) {
94
+ throw new TypeError('WEBVTT_CUE_INVALID');
95
+ }
96
+ const settings = Object.fromEntries((match[3] ?? '')
97
+ .split(/\s+/u)
98
+ .filter(Boolean)
99
+ .map(value => {
100
+ const separator = value.indexOf(':');
101
+ return separator < 1
102
+ ? [value, '']
103
+ : [value.slice(0, separator), value.slice(separator + 1)];
104
+ }));
105
+ const id = timelineIndex > 0 ? lines[0]?.trim() : undefined;
106
+ return {
107
+ ...(id === undefined || id.length === 0 ? {} : { id }),
108
+ startUs: timestamp(match[1]),
109
+ endUs: timestamp(match[2]),
110
+ text: lines.slice(timelineIndex + 1).join('\n'),
111
+ ...(Object.keys(settings).length === 0 ? {} : { settings }),
112
+ };
113
+ });
114
+ validateCues(cues);
115
+ return cues;
116
+ }
117
+ export function serializeWebVtt(cues) {
118
+ validateCues(cues);
119
+ return {
120
+ text: `WEBVTT\n\n${cues
121
+ .map(cue => {
122
+ const settings = Object.entries(cue.settings ?? {})
123
+ .sort(([left], [right]) => left.localeCompare(right))
124
+ .map(([key, value]) => `${key}:${value}`)
125
+ .join(' ');
126
+ return `${cue.id === undefined ? '' : `${cue.id}\n`}${formatTimestamp(cue.startUs, '.')} --> ${formatTimestamp(cue.endUs, '.')}${settings.length === 0 ? '' : ` ${settings}`}\n${cue.text}`;
127
+ })
128
+ .join('\n\n')}\n`,
129
+ warnings: [],
130
+ };
131
+ }
@@ -0,0 +1,18 @@
1
+ import type { Diagnostic } from '@aelionsdk/core';
2
+ import type { RenderIr } from './types.js';
3
+ export type IrTransferFunction = 'srgb' | 'gamma22' | 'pq' | 'hlg';
4
+ export type IrOutputBitDepth = 8 | 10;
5
+ export interface ColorPipelineCapability {
6
+ readonly workingColorSpaces: ReadonlySet<string>;
7
+ readonly transferFunctions: ReadonlySet<IrTransferFunction>;
8
+ readonly bitDepths: ReadonlySet<IrOutputBitDepth>;
9
+ readonly hdrPresentation: boolean;
10
+ }
11
+ export interface ColorPipelineReport {
12
+ readonly ok: boolean;
13
+ readonly issues: readonly Diagnostic[];
14
+ }
15
+ export declare function validateColorPipelineContract(ir: RenderIr): void;
16
+ export declare function preflightColorPipeline(ir: RenderIr, capability: ColorPipelineCapability): ColorPipelineReport;
17
+ export declare const LOCAL_RGBA8_COLOR_CAPABILITY: ColorPipelineCapability;
18
+ //# sourceMappingURL=color.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../src/color.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,KAAK,CAAC;AACnE,MAAM,MAAM,gBAAgB,GAAG,CAAC,GAAG,EAAE,CAAC;AAEtC,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,kBAAkB,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACjD,QAAQ,CAAC,iBAAiB,EAAE,WAAW,CAAC,kBAAkB,CAAC,CAAC;IAC5D,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,gBAAgB,CAAC,CAAC;IAClD,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;CACnC;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,CAAC;CACxC;AAED,wBAAgB,6BAA6B,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAShE;AAED,wBAAgB,sBAAsB,CACpC,EAAE,EAAE,QAAQ,EACZ,UAAU,EAAE,uBAAuB,GAClC,mBAAmB,CAsCrB;AAED,eAAO,MAAM,4BAA4B,EAAE,uBAK1C,CAAC"}
package/dist/color.js ADDED
@@ -0,0 +1,55 @@
1
+ export function validateColorPipelineContract(ir) {
2
+ const transfer = ir.transferFunction ?? 'srgb';
3
+ const bitDepth = ir.bitDepth ?? 8;
4
+ if ((transfer === 'pq' || transfer === 'hlg') && ir.workingColorSpace !== 'rec2020-linear') {
5
+ throw new TypeError('COLOR_HDR_REQUIRES_REC2020');
6
+ }
7
+ if ((transfer === 'pq' || transfer === 'hlg') && bitDepth !== 10) {
8
+ throw new TypeError('COLOR_HDR_REQUIRES_10_BIT');
9
+ }
10
+ }
11
+ export function preflightColorPipeline(ir, capability) {
12
+ validateColorPipelineContract(ir);
13
+ const issues = [];
14
+ const transfer = ir.transferFunction ?? 'srgb';
15
+ const bitDepth = ir.bitDepth ?? 8;
16
+ if (!capability.workingColorSpaces.has(ir.workingColorSpace)) {
17
+ issues.push({
18
+ code: 'COLOR_WORKING_SPACE_UNSUPPORTED',
19
+ severity: 'error',
20
+ message: `Working color space ${ir.workingColorSpace} is unavailable`,
21
+ recoverable: true,
22
+ });
23
+ }
24
+ if (!capability.transferFunctions.has(transfer)) {
25
+ issues.push({
26
+ code: 'COLOR_TRANSFER_FUNCTION_UNSUPPORTED',
27
+ severity: 'error',
28
+ message: `Transfer function ${transfer} is unavailable`,
29
+ recoverable: true,
30
+ });
31
+ }
32
+ if (!capability.bitDepths.has(bitDepth)) {
33
+ issues.push({
34
+ code: 'COLOR_BIT_DEPTH_UNSUPPORTED',
35
+ severity: 'error',
36
+ message: `${bitDepth.toString()}-bit output is unavailable`,
37
+ recoverable: true,
38
+ });
39
+ }
40
+ if ((transfer === 'pq' || transfer === 'hlg') && !capability.hdrPresentation) {
41
+ issues.push({
42
+ code: 'COLOR_HDR_PRESENTATION_UNSUPPORTED',
43
+ severity: 'error',
44
+ message: 'The active output surface cannot present HDR',
45
+ recoverable: true,
46
+ });
47
+ }
48
+ return { ok: issues.length === 0, issues };
49
+ }
50
+ export const LOCAL_RGBA8_COLOR_CAPABILITY = {
51
+ workingColorSpaces: new Set(['srgb-linear', 'display-p3-linear', 'rec2020-linear']),
52
+ transferFunctions: new Set(['srgb', 'gamma22']),
53
+ bitDepths: new Set([8]),
54
+ hdrPresentation: false,
55
+ };
@@ -0,0 +1,15 @@
1
+ import { type AelionProject } from '@aelionsdk/project-schema';
2
+ import type { RenderIrCompilation, RenderCompileOptions } from './types.js';
3
+ export declare class IncrementalRenderCompiler {
4
+ #private;
5
+ /**
6
+ * Creates an isolated compiler that reuses this compiler's immutable baseline.
7
+ * Compiling on the fork cannot advance or corrupt the parent baseline; a host
8
+ * can promote the fork only after its surrounding transaction commits.
9
+ */
10
+ fork(): IncrementalRenderCompiler;
11
+ /** Releases the incremental baseline retained for clip/transition reuse. */
12
+ clear(): void;
13
+ compile(project: AelionProject, sequenceId: string, revision: bigint, optionsOrAffectedRanges?: RenderCompileOptions | RenderIrCompilation['stats']['affectedRanges']): RenderIrCompilation;
14
+ }
15
+ //# sourceMappingURL=compiler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,aAAa,EAAmB,MAAM,2BAA2B,CAAC;AAGpG,OAAO,KAAK,EAaV,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAkZpB,qBAAa,yBAAyB;;IAIpC;;;;OAIG;IACI,IAAI,IAAI,yBAAyB;IAMxC,4EAA4E;IACrE,KAAK,IAAI,IAAI;IAOb,OAAO,CACZ,OAAO,EAAE,aAAa,EACtB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,uBAAuB,GACnB,oBAAoB,GACpB,mBAAmB,CAAC,OAAO,CAAC,CAAC,gBAAgB,CAAM,GACtD,mBAAmB;CAqMvB"}