@motionscript/browser 0.1.0-alpha.8 → 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/CHANGELOG.md +22 -0
- package/LICENSE +201 -201
- package/NOTICE +49 -49
- package/README.md +141 -141
- package/dist/asset-bytes.js.map +1 -1
- package/dist/audio/bus-graph.js.map +1 -1
- package/dist/audio/effect-graph.js.map +1 -1
- package/dist/audio/index.js.map +1 -1
- package/dist/audio/loop-region.js.map +1 -1
- package/dist/audio/mixer.js.map +1 -1
- package/dist/audio/player.js.map +1 -1
- package/dist/browser/audio.js +1 -1
- package/dist/browser/chunks/{chunk-IILVN4SK.js → chunk-F3AZKPHU.js} +1 -1
- package/dist/browser/chunks/chunk-F3AZKPHU.js.map +7 -0
- package/dist/browser/index.js +20 -20
- package/dist/browser/index.js.map +4 -4
- package/dist/browser/manifest.json +1 -1
- package/dist/browser/ms_renderer_bg.wasm +0 -0
- package/dist/concat.js.map +1 -1
- package/dist/dynamic-nodes.js.map +1 -1
- package/dist/engine.js.map +1 -1
- package/dist/export-audio.js.map +1 -1
- package/dist/exporter.js.map +1 -1
- package/dist/frame-loop.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mix-timeline-audio.js.map +1 -1
- package/dist/parallel/export-parallel.js.map +1 -1
- package/dist/parallel/lane.js.map +1 -1
- package/dist/parallel/run-lanes.js.map +1 -1
- package/dist/parallel/session.js.map +1 -1
- package/dist/renderer.js.map +1 -1
- package/dist/screenshot.js.map +1 -1
- package/dist/still.js.map +1 -1
- package/dist/ticker.js.map +1 -1
- package/package.json +4 -4
- package/dist/audio/filter-graph.d.ts +0 -59
- package/dist/audio/filter-graph.d.ts.map +0 -1
- package/dist/audio/filter-graph.js +0 -241
- package/dist/audio/filter-graph.js.map +0 -1
- package/dist/browser/chunks/chunk-IILVN4SK.js.map +0 -7
- package/dist/canvaskit-renderer.d.ts +0 -8
- package/dist/canvaskit-renderer.d.ts.map +0 -1
- package/dist/canvaskit-renderer.js +0 -23
- package/dist/canvaskit-renderer.js.map +0 -1
- package/dist/decode/image-levels.d.ts +0 -137
- package/dist/decode/image-levels.d.ts.map +0 -1
- package/dist/decode/image-levels.js +0 -477
- package/dist/decode/image-levels.js.map +0 -1
- package/dist/decode/levels.d.ts +0 -37
- package/dist/decode/levels.d.ts.map +0 -1
- package/dist/decode/levels.js +0 -68
- package/dist/decode/levels.js.map +0 -1
- package/dist/decode/video-levels.d.ts +0 -37
- package/dist/decode/video-levels.d.ts.map +0 -1
- package/dist/decode/video-levels.js +0 -95
- package/dist/decode/video-levels.js.map +0 -1
- package/dist/getter.d.ts +0 -13
- package/dist/getter.d.ts.map +0 -1
- package/dist/getter.js +0 -39
- package/dist/getter.js.map +0 -1
- package/dist/measure-context.d.ts +0 -12
- package/dist/measure-context.d.ts.map +0 -1
- package/dist/measure-context.js +0 -12
- package/dist/measure-context.js.map +0 -1
- package/dist/render-context.d.ts +0 -34
- package/dist/render-context.d.ts.map +0 -1
- package/dist/render-context.js +0 -63
- package/dist/render-context.js.map +0 -1
- package/dist/storage-adapter.d.ts +0 -367
- package/dist/storage-adapter.d.ts.map +0 -1
- package/dist/storage-adapter.js +0 -1280
- package/dist/storage-adapter.js.map +0 -1
- package/dist/three/renderer.d.ts +0 -47
- package/dist/three/renderer.d.ts.map +0 -1
- package/dist/three/renderer.js +0 -182
- package/dist/three/renderer.js.map +0 -1
package/dist/decode/levels.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The resolutions a source may be decoded at.
|
|
3
|
-
*
|
|
4
|
-
* Levels sit half an octave apart, so a decode is never more than √2 larger than
|
|
5
|
-
* what a draw asked for, and a slow zoom re-decodes a dozen times across the
|
|
6
|
-
* whole range rather than once per frame.
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Longest edge any level is decoded at. The conventional maximum GPU texture
|
|
10
|
-
* edge, so pixels past it could not be sampled in one draw anyway; a 4096²
|
|
11
|
-
* RGBA level is 67 MB resident.
|
|
12
|
-
*/
|
|
13
|
-
export const MAX_IMAGE_DECODE_EDGE = 4096;
|
|
14
|
-
export const MIN_LEVEL_EDGE = 64;
|
|
15
|
-
/** `64·2^(k/2)` up to {@link MAX_IMAGE_DECODE_EDGE}. */
|
|
16
|
-
export const LEVEL_LADDER = (() => {
|
|
17
|
-
const out = [];
|
|
18
|
-
for (let k = 0;; k++) {
|
|
19
|
-
const edge = Math.round(MIN_LEVEL_EDGE * 2 ** (k / 2));
|
|
20
|
-
if (edge > MAX_IMAGE_DECODE_EDGE)
|
|
21
|
-
break;
|
|
22
|
-
out.push(edge);
|
|
23
|
-
}
|
|
24
|
-
return out;
|
|
25
|
-
})();
|
|
26
|
-
/**
|
|
27
|
-
* The largest level worth holding: the source's own long edge for a raster
|
|
28
|
-
* (there is no more detail to reveal), the ceiling for a vector.
|
|
29
|
-
*/
|
|
30
|
-
export function levelCap(intrinsic, vector) {
|
|
31
|
-
if (vector)
|
|
32
|
-
return MAX_IMAGE_DECODE_EDGE;
|
|
33
|
-
const long = Math.max(1, Math.round(Math.max(intrinsic.width, intrinsic.height)));
|
|
34
|
-
return Math.min(long, MAX_IMAGE_DECODE_EDGE);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* The level for a draw that needs `demand` device px along the source's long
|
|
38
|
-
* edge: the smallest rung at or above it, snapped to `cap` once a rung is
|
|
39
|
-
* within half an octave of it — a level at 0.8× the source costs almost what
|
|
40
|
-
* the source does and looks worse.
|
|
41
|
-
*/
|
|
42
|
-
export function levelFor(demand, cap) {
|
|
43
|
-
const need = Number.isFinite(demand) ? Math.max(0, demand) : cap;
|
|
44
|
-
if (need >= cap)
|
|
45
|
-
return cap;
|
|
46
|
-
const snap = cap / Math.SQRT2;
|
|
47
|
-
for (const edge of LEVEL_LADDER) {
|
|
48
|
-
if (edge >= snap)
|
|
49
|
-
return cap;
|
|
50
|
-
if (edge >= need)
|
|
51
|
-
return edge;
|
|
52
|
-
}
|
|
53
|
-
return cap;
|
|
54
|
-
}
|
|
55
|
-
/** The smallest level a source can be held at. */
|
|
56
|
-
export function floorLevel(cap) {
|
|
57
|
-
return levelFor(0, cap);
|
|
58
|
-
}
|
|
59
|
-
/** Pixel dimensions of `edge`, keeping the intrinsic aspect. */
|
|
60
|
-
export function levelSize(edge, intrinsic) {
|
|
61
|
-
const long = Math.max(intrinsic.width, intrinsic.height, 1);
|
|
62
|
-
const scale = edge / long;
|
|
63
|
-
return {
|
|
64
|
-
width: Math.max(1, Math.round(intrinsic.width * scale)),
|
|
65
|
-
height: Math.max(1, Math.round(intrinsic.height * scale)),
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
//# sourceMappingURL=levels.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"levels.js","sourceRoot":"","sources":["../../src/decode/levels.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAE1C,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,CAAC;AAEjC,wDAAwD;AACxD,MAAM,CAAC,MAAM,YAAY,GAAsB,CAAC,GAAG,EAAE;IACjD,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,KAAK,IAAI,CAAC,GAAG,CAAC,GAAI,CAAC,EAAE,EAAE,CAAC;QACpB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACvD,IAAI,IAAI,GAAG,qBAAqB;YAAE,MAAM;QACxC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC,CAAC,EAAE,CAAC;AAOL;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,SAAoB,EAAE,MAAe;IAC1D,IAAI,MAAM;Q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,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC;QACvD,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC;KAC5D,CAAC;AACN,CAAC","sourcesContent":["/**\r\n * The resolutions a source may be decoded at.\r\n *\r\n * Levels sit half an octave apart, so a decode is never more than √2 larger than\r\n * what a draw asked for, and a slow zoom re-decodes a dozen times across the\r\n * whole range rather than once per frame.\r\n */\r\n\r\n/**\r\n * Longest edge any level is decoded at. The conventional maximum GPU texture\r\n * edge, so pixels past it could not be sampled in one draw anyway; a 4096²\r\n * RGBA level is 67 MB resident.\r\n */\r\nexport const MAX_IMAGE_DECODE_EDGE = 4096;\r\n\r\nexport const MIN_LEVEL_EDGE = 64;\r\n\r\n/** `64·2^(k/2)` up to {@link MAX_IMAGE_DECODE_EDGE}. */\r\nexport const LEVEL_LADDER: readonly number[] = (() => {\r\n const out: number[] = [];\r\n for (let k = 0; ; k++) {\r\n const edge = Math.round(MIN_LEVEL_EDGE * 2 ** (k / 2));\r\n if (edge > MAX_IMAGE_DECODE_EDGE) break;\r\n out.push(edge);\r\n }\r\n return out;\r\n})();\r\n\r\nexport interface PixelSize {\r\n width: number;\r\n height: number;\r\n}\r\n\r\n/**\r\n * The largest level worth holding: the source's own long edge for a raster\r\n * (there is no more detail to reveal), the ceiling for a vector.\r\n */\r\nexport function levelCap(intrinsic: PixelSize, vector: boolean): number {\r\n if (vector) return MAX_IMAGE_DECODE_EDGE;\r\n const long = Math.max(1, Math.round(Math.max(intrinsic.width, intrinsic.height)));\r\n return Math.min(long, MAX_IMAGE_DECODE_EDGE);\r\n}\r\n\r\n/**\r\n * The level for a draw that needs `demand` device px along the source's long\r\n * edge: the smallest rung at or above it, snapped to `cap` once a rung is\r\n * within half an octave of it — a level at 0.8× the source costs almost what\r\n * the source does and looks worse.\r\n */\r\nexport function levelFor(demand: number, cap: number): number {\r\n const need = Number.isFinite(demand) ? Math.max(0, demand) : cap;\r\n if (need >= cap) return cap;\r\n const snap = cap / Math.SQRT2;\r\n for (const edge of LEVEL_LADDER) {\r\n if (edge >= snap) return cap;\r\n if (edge >= need) return edge;\r\n }\r\n return cap;\r\n}\r\n\r\n/** The smallest level a source can be held at. */\r\nexport function floorLevel(cap: number): number {\r\n return levelFor(0, cap);\r\n}\r\n\r\n/** Pixel dimensions of `edge`, keeping the intrinsic aspect. */\r\nexport function levelSize(edge: number, intrinsic: PixelSize): PixelSize {\r\n const long = Math.max(intrinsic.width, intrinsic.height, 1);\r\n const scale = edge / long;\r\n return {\r\n width: Math.max(1, Math.round(intrinsic.width * scale)),\r\n height: Math.max(1, Math.round(intrinsic.height * scale)),\r\n };\r\n}\r\n"]}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { DecodePolicy } from "./image-levels";
|
|
2
|
-
import { type PixelSize } from "./levels";
|
|
3
|
-
/**
|
|
4
|
-
* Decoded frames one clip's window may hold, in bytes. Frames are counted at
|
|
5
|
-
* their decoded level, so a clip drawn small keeps a long window and one drawn
|
|
6
|
-
* full-screen a short one, rather than a fixed count sized for neither.
|
|
7
|
-
*/
|
|
8
|
-
export declare const VIDEO_WINDOW_BUDGET_BYTES: number;
|
|
9
|
-
/** Forward and back window lengths for frames of `size`, split 3:1 like the fixed window was. */
|
|
10
|
-
export declare function videoWindowFrames(size: PixelSize | null): {
|
|
11
|
-
forward: number;
|
|
12
|
-
back: number;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* The level one clip's frames are snapshotted at, and how it follows demand.
|
|
16
|
-
*
|
|
17
|
-
* A clip has one level at a time, not one per draw: the decoder is sequential,
|
|
18
|
-
* and a frame is resized as it is snapshotted, so changing the level changes
|
|
19
|
-
* what the next snapshot produces without restarting the stream.
|
|
20
|
-
*/
|
|
21
|
-
export declare class VideoLevel {
|
|
22
|
-
level: number;
|
|
23
|
-
private _cap;
|
|
24
|
-
private _passNeed;
|
|
25
|
-
private _passDraws;
|
|
26
|
-
private _passAllOver;
|
|
27
|
-
private _overSince;
|
|
28
|
-
constructor(intrinsic: PixelSize, policy: DecodePolicy, lastDemand: number | undefined, surfaceEdge: number);
|
|
29
|
-
get cap(): number;
|
|
30
|
-
/** Record one draw's footprint; absent means the clip's own resolution. */
|
|
31
|
-
note(footprint: number | undefined): void;
|
|
32
|
-
/** Whether a frame snapshotted at `frameLevel` is good enough to count as the frame. */
|
|
33
|
-
accepts(frameLevel: number | undefined, policy: DecodePolicy): boolean;
|
|
34
|
-
/** The pass's demand is complete: move the level, and report whether it moved. */
|
|
35
|
-
endPass(policy: DecodePolicy, playing: boolean, now: number): boolean;
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=video-levels.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"video-levels.d.ts","sourceRoot":"","sources":["../../src/decode/video-levels.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,EAAkC,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1E;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,QAAoB,CAAC;AAK3D,iGAAiG;AACjG,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAS3F;AAED;;;;;;GAMG;AACH,qBAAa,UAAU;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,YAAY,CAAQ;IAC5B,OAAO,CAAC,UAAU,CAAuB;gBAE7B,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,GAAG,SAAS,EAAE,WAAW,EAAE,MAAM;IAO3G,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED,2EAA2E;IAC3E,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IASzC,wFAAwF;IACxF,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO;IAKtE,kFAAkF;IAClF,OAAO,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO;CA6BxE"}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { DOWNGRADE_AFTER_MS } from "./image-levels";
|
|
2
|
-
import { floorLevel, levelCap, levelFor } from "./levels";
|
|
3
|
-
/**
|
|
4
|
-
* Decoded frames one clip's window may hold, in bytes. Frames are counted at
|
|
5
|
-
* their decoded level, so a clip drawn small keeps a long window and one drawn
|
|
6
|
-
* full-screen a short one, rather than a fixed count sized for neither.
|
|
7
|
-
*/
|
|
8
|
-
export const VIDEO_WINDOW_BUDGET_BYTES = 512 * 1024 * 1024;
|
|
9
|
-
const MAX_FORWARD_FRAMES = 96;
|
|
10
|
-
const MAX_BACK_FRAMES = 32;
|
|
11
|
-
/** Forward and back window lengths for frames of `size`, split 3:1 like the fixed window was. */
|
|
12
|
-
export function videoWindowFrames(size) {
|
|
13
|
-
if (!size || !(size.width > 0) || !(size.height > 0)) {
|
|
14
|
-
return { forward: MAX_FORWARD_FRAMES, back: MAX_BACK_FRAMES };
|
|
15
|
-
}
|
|
16
|
-
const frames = VIDEO_WINDOW_BUDGET_BYTES / (size.width * size.height * 4);
|
|
17
|
-
return {
|
|
18
|
-
forward: Math.max(4, Math.min(MAX_FORWARD_FRAMES, Math.floor(frames * 0.75))),
|
|
19
|
-
back: Math.max(1, Math.min(MAX_BACK_FRAMES, Math.floor(frames * 0.25))),
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* The level one clip's frames are snapshotted at, and how it follows demand.
|
|
24
|
-
*
|
|
25
|
-
* A clip has one level at a time, not one per draw: the decoder is sequential,
|
|
26
|
-
* and a frame is resized as it is snapshotted, so changing the level changes
|
|
27
|
-
* what the next snapshot produces without restarting the stream.
|
|
28
|
-
*/
|
|
29
|
-
export class VideoLevel {
|
|
30
|
-
level;
|
|
31
|
-
_cap;
|
|
32
|
-
_passNeed = 0;
|
|
33
|
-
_passDraws = 0;
|
|
34
|
-
_passAllOver = true;
|
|
35
|
-
_overSince = null;
|
|
36
|
-
constructor(intrinsic, policy, lastDemand, surfaceEdge) {
|
|
37
|
-
this._cap = levelCap(intrinsic, false);
|
|
38
|
-
this.level = policy === "exact"
|
|
39
|
-
? floorLevel(this._cap)
|
|
40
|
-
: levelFor(lastDemand ?? Math.min(Math.max(intrinsic.width, intrinsic.height), surfaceEdge), this._cap);
|
|
41
|
-
}
|
|
42
|
-
get cap() {
|
|
43
|
-
return this._cap;
|
|
44
|
-
}
|
|
45
|
-
/** Record one draw's footprint; absent means the clip's own resolution. */
|
|
46
|
-
note(footprint) {
|
|
47
|
-
const need = footprint !== undefined && Number.isFinite(footprint) && footprint > 0
|
|
48
|
-
? Math.min(footprint, this._cap)
|
|
49
|
-
: this._cap;
|
|
50
|
-
this._passNeed = Math.max(this._passNeed, need);
|
|
51
|
-
this._passDraws++;
|
|
52
|
-
if (this.level < 2 * need)
|
|
53
|
-
this._passAllOver = false;
|
|
54
|
-
}
|
|
55
|
-
/** Whether a frame snapshotted at `frameLevel` is good enough to count as the frame. */
|
|
56
|
-
accepts(frameLevel, policy) {
|
|
57
|
-
if (frameLevel === undefined)
|
|
58
|
-
return true;
|
|
59
|
-
return policy === "exact" ? frameLevel === this.level : frameLevel >= this.level;
|
|
60
|
-
}
|
|
61
|
-
/** The pass's demand is complete: move the level, and report whether it moved. */
|
|
62
|
-
endPass(policy, playing, now) {
|
|
63
|
-
const draws = this._passDraws;
|
|
64
|
-
const need = this._passNeed;
|
|
65
|
-
const allOver = this._passAllOver;
|
|
66
|
-
this._passDraws = 0;
|
|
67
|
-
this._passNeed = 0;
|
|
68
|
-
this._passAllOver = true;
|
|
69
|
-
if (draws === 0)
|
|
70
|
-
return false;
|
|
71
|
-
const target = levelFor(need, this._cap);
|
|
72
|
-
const before = this.level;
|
|
73
|
-
if (policy === "exact") {
|
|
74
|
-
this.level = target;
|
|
75
|
-
}
|
|
76
|
-
else if (this.level < need) {
|
|
77
|
-
this.level = target;
|
|
78
|
-
this._overSince = null;
|
|
79
|
-
}
|
|
80
|
-
else if (allOver && !playing) {
|
|
81
|
-
// Only while paused: a playing clip dropping resolution is visible
|
|
82
|
-
// as a pop, and its window would re-decode behind the playhead.
|
|
83
|
-
this._overSince ??= now;
|
|
84
|
-
if (now - this._overSince >= DOWNGRADE_AFTER_MS) {
|
|
85
|
-
this.level = target;
|
|
86
|
-
this._overSince = null;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
this._overSince = null;
|
|
91
|
-
}
|
|
92
|
-
return this.level !== before;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
//# sourceMappingURL=video-levels.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"video-levels.js","sourceRoot":"","sources":["../../src/decode/video-levels.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAkB,MAAM,UAAU,CAAC;AAE1E;;;;GAIG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;AAE3D,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,iGAAiG;AACjG,MAAM,UAAU,iBAAiB,CAAC,IAAsB;IACpD,IAAI,CAAC,IAAI,IAAI,C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AK,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QAE9B,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QACzC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC;QAC1B,IAAI,MAAM,KAAK,OAAO,EAAE,CAAC;YACrB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC;QACxB,CAAC;aAAM,IAAI,IAAI,CAAC,KAAK,GAAG,IAAI,EAAE,CAAC;YAC3B,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC;YACpB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QAC3B,CAAC;aAAM,IAAI,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;YAC7B,mEAAmE;YACnE,gEAAgE;YAChE,IAAI,CAAC,UAAU,KAAK,GAAG,CAAC;YACxB,IAAI,GAAG,GAAG,IAAI,CAAC,UAAU,IAAI,kBAAkB,EAAE,CAAC;gBAC9C,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC;gBACpB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YAC3B,CAAC;QACL,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QAC3B,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,KAAK,MAAM,CAAC;IACjC,CAAC;CACJ","sourcesContent":["import type { DecodePolicy } from \"./image-levels\";\r\nimport { DOWNGRADE_AFTER_MS } from \"./image-levels\";\r\nimport { floorLevel, levelCap, levelFor, type PixelSize } from \"./levels\";\r\n\r\n/**\r\n * Decoded frames one clip's window may hold, in bytes. Frames are counted at\r\n * their decoded level, so a clip drawn small keeps a long window and one drawn\r\n * full-screen a short one, rather than a fixed count sized for neither.\r\n */\r\nexport const VIDEO_WINDOW_BUDGET_BYTES = 512 * 1024 * 1024;\r\n\r\nconst MAX_FORWARD_FRAMES = 96;\r\nconst MAX_BACK_FRAMES = 32;\r\n\r\n/** Forward and back window lengths for frames of `size`, split 3:1 like the fixed window was. */\r\nexport function videoWindowFrames(size: PixelSize | null): { forward: number; back: number } {\r\n if (!size || !(size.width > 0) || !(size.height > 0)) {\r\n return { forward: MAX_FORWARD_FRAMES, back: MAX_BACK_FRAMES };\r\n }\r\n const frames = VIDEO_WINDOW_BUDGET_BYTES / (size.width * size.height * 4);\r\n return {\r\n forward: Math.max(4, Math.min(MAX_FORWARD_FRAMES, Math.floor(frames * 0.75))),\r\n back: Math.max(1, Math.min(MAX_BACK_FRAMES, Math.floor(frames * 0.25))),\r\n };\r\n}\r\n\r\n/**\r\n * The level one clip's frames are snapshotted at, and how it follows demand.\r\n *\r\n * A clip has one level at a time, not one per draw: the decoder is sequential,\r\n * and a frame is resized as it is snapshotted, so changing the level changes\r\n * what the next snapshot produces without restarting the stream.\r\n */\r\nexport class VideoLevel {\r\n level: number;\r\n private _cap: number;\r\n private _passNeed = 0;\r\n private _passDraws = 0;\r\n private _passAllOver = true;\r\n private _overSince: number | null = null;\r\n\r\n constructor(intrinsic: PixelSize, policy: DecodePolicy, lastDemand: number | undefined, surfaceEdge: number) {\r\n this._cap = levelCap(intrinsic, false);\r\n this.level = policy === \"exact\"\r\n ? floorLevel(this._cap)\r\n : levelFor(lastDemand ?? Math.min(Math.max(intrinsic.width, intrinsic.height), surfaceEdge), this._cap);\r\n }\r\n\r\n get cap(): number {\r\n return this._cap;\r\n }\r\n\r\n /** Record one draw's footprint; absent means the clip's own resolution. */\r\n note(footprint: number | undefined): void {\r\n const need = footprint !== undefined && Number.isFinite(footprint) && footprint > 0\r\n ? Math.min(footprint, this._cap)\r\n : this._cap;\r\n this._passNeed = Math.max(this._passNeed, need);\r\n this._passDraws++;\r\n if (this.level < 2 * need) this._passAllOver = false;\r\n }\r\n\r\n /** Whether a frame snapshotted at `frameLevel` is good enough to count as the frame. */\r\n accepts(frameLevel: number | undefined, policy: DecodePolicy): boolean {\r\n if (frameLevel === undefined) return true;\r\n return policy === \"exact\" ? frameLevel === this.level : frameLevel >= this.level;\r\n }\r\n\r\n /** The pass's demand is complete: move the level, and report whether it moved. */\r\n endPass(policy: DecodePolicy, playing: boolean, now: number): boolean {\r\n const draws = this._passDraws;\r\n const need = this._passNeed;\r\n const allOver = this._passAllOver;\r\n this._passDraws = 0;\r\n this._passNeed = 0;\r\n this._passAllOver = true;\r\n if (draws === 0) return false;\r\n\r\n const target = levelFor(need, this._cap);\r\n const before = this.level;\r\n if (policy === \"exact\") {\r\n this.level = target;\r\n } else if (this.level < need) {\r\n this.level = target;\r\n this._overSince = null;\r\n } else if (allOver && !playing) {\r\n // Only while paused: a playing clip dropping resolution is visible\r\n // as a pop, and its window would re-decode behind the playhead.\r\n this._overSince ??= now;\r\n if (now - this._overSince >= DOWNGRADE_AFTER_MS) {\r\n this.level = target;\r\n this._overSince = null;\r\n }\r\n } else {\r\n this._overSince = null;\r\n }\r\n return this.level !== before;\r\n }\r\n}\r\n"]}
|
package/dist/getter.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { CanvasKit } from "@motionscript/canvaskit";
|
|
2
|
-
/**
|
|
3
|
-
* Loads and caches the CanvasKit wasm module (memoized — concurrent callers
|
|
4
|
-
* share the same init promise, and once resolved every call returns the same
|
|
5
|
-
* instance). `wasmUrl` defaults to the wasm shipped by `@motionscript/canvaskit`
|
|
6
|
-
* (resolved by the consumer's bundler), so consumers don't have to configure
|
|
7
|
-
* anything; pass a URL to override where the binary is loaded from.
|
|
8
|
-
*
|
|
9
|
-
* The glue is a dynamic import: CanvasKit is an optional peer, so a host that
|
|
10
|
-
* hands every entry a `renderer` neither installs nor loads it.
|
|
11
|
-
*/
|
|
12
|
-
export declare function getCanvasKit(wasmUrl?: string): Promise<CanvasKit>;
|
|
13
|
-
//# sourceMappingURL=getter.d.ts.map
|
package/dist/getter.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getter.d.ts","sourceRoot":"","sources":["../src/getter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAkBzD;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAYvE"}
|
package/dist/getter.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
let canvasKit = null;
|
|
2
|
-
let initPromise = null;
|
|
3
|
-
// Default to the wasm shipped by @motionscript/canvaskit so consumers don't
|
|
4
|
-
// have to configure anything. This MUST be the custom build that matches the
|
|
5
|
-
// glue imported below — the stock canvaskit-wasm binary lacks imports our glue
|
|
6
|
-
// expects (e.g. `pd`) and fails to link with a LinkError.
|
|
7
|
-
//
|
|
8
|
-
// Resolved **lazily**, not at module scope. `import.meta.url` is empty in a
|
|
9
|
-
// non-ESM output — an IIFE bundle, which is what the headless page loads — and
|
|
10
|
-
// `new URL("…", "")` throws on import, before any caller has had the chance to
|
|
11
|
-
// pass the explicit URL that would have made the default irrelevant.
|
|
12
|
-
function defaultWasmUrl() {
|
|
13
|
-
return new URL("@motionscript/canvaskit/canvaskit.wasm", import.meta.url).href;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Loads and caches the CanvasKit wasm module (memoized — concurrent callers
|
|
17
|
-
* share the same init promise, and once resolved every call returns the same
|
|
18
|
-
* instance). `wasmUrl` defaults to the wasm shipped by `@motionscript/canvaskit`
|
|
19
|
-
* (resolved by the consumer's bundler), so consumers don't have to configure
|
|
20
|
-
* anything; pass a URL to override where the binary is loaded from.
|
|
21
|
-
*
|
|
22
|
-
* The glue is a dynamic import: CanvasKit is an optional peer, so a host that
|
|
23
|
-
* hands every entry a `renderer` neither installs nor loads it.
|
|
24
|
-
*/
|
|
25
|
-
export async function getCanvasKit(wasmUrl) {
|
|
26
|
-
if (canvasKit)
|
|
27
|
-
return canvasKit;
|
|
28
|
-
if (initPromise)
|
|
29
|
-
return initPromise;
|
|
30
|
-
const url = wasmUrl ?? defaultWasmUrl();
|
|
31
|
-
initPromise = import("@motionscript/canvaskit")
|
|
32
|
-
.then(({ default: CanvasKitInit }) => CanvasKitInit({ locateFile: () => url }))
|
|
33
|
-
.then((ck) => {
|
|
34
|
-
canvasKit = ck;
|
|
35
|
-
return ck;
|
|
36
|
-
});
|
|
37
|
-
return initPromise;
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=getter.js.map
|
package/dist/getter.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getter.js","sourceRoot":"","sources":["../src/getter.ts"],"names":[],"mappings":"AAGA,IAAI,SAAS,GAAqB,IAAI,CAAC;AACvC,IAAI,WAAW,GAA8B,IAAI,CAAC;AAElD,4EAA4E;AAC5E,6EAA6E;AAC7E,+EAA+E;AAC/E,0DAA0D;AAC1D,EAAE;AACF,4EAA4E;AAC5E,+EAA+E;AAC/E,+EAA+E;AAC/E,qEAAqE;AACrE,SAAS,cAAc;IACnB,OAAO,IAAI,GAAG,CAAC,wCAAwC,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;AACnF,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAAgB;IAC/C,IAAI,SAAS;QAAE,OAAO,SAAS,CAAC;IAChC,IAAI,WAAW;QAAE,OAAO,WAAW,CAAC;IACpC,MAAM,GAAG,GAAG,OAAO,IAAI,cAAc,EAAE,CAAC;IAExC,WAAW,GAAG,MAAM,CAAC,yBAAyB,CAAC;SAC1C,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,EAAE,EAAE,CAAC,aAAa,CAAC,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;SAC9E,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE;QACT,SAAS,GAAG,EAAE,CAAC;QACf,OAAO,EAAE,CAAC;IACd,CAAC,CAAC,CAAC;IACP,OAAO,WAAW,CAAC;AACvB,CAAC","sourcesContent":["// @motionscript/core/src/engine.ts\r\nimport type { CanvasKit } from \"@motionscript/canvaskit\";\r\n\r\nlet canvasKit: CanvasKit | null = null;\r\nlet initPromise: Promise<CanvasKit> | null = null;\r\n\r\n// Default to the wasm shipped by @motionscript/canvaskit so consumers don't\r\n// have to configure anything. This MUST be the custom build that matches the\r\n// glue imported below — the stock canvaskit-wasm binary lacks imports our glue\r\n// expects (e.g. `pd`) and fails to link with a LinkError.\r\n//\r\n// Resolved **lazily**, not at module scope. `import.meta.url` is empty in a\r\n// non-ESM output — an IIFE bundle, which is what the headless page loads — and\r\n// `new URL(\"…\", \"\")` throws on import, before any caller has had the chance to\r\n// pass the explicit URL that would have made the default irrelevant.\r\nfunction defaultWasmUrl(): string {\r\n return new URL(\"@motionscript/canvaskit/canvaskit.wasm\", import.meta.url).href;\r\n}\r\n\r\n/**\r\n * Loads and caches the CanvasKit wasm module (memoized — concurrent callers\r\n * share the same init promise, and once resolved every call returns the same\r\n * instance). `wasmUrl` defaults to the wasm shipped by `@motionscript/canvaskit`\r\n * (resolved by the consumer's bundler), so consumers don't have to configure\r\n * anything; pass a URL to override where the binary is loaded from.\r\n *\r\n * The glue is a dynamic import: CanvasKit is an optional peer, so a host that\r\n * hands every entry a `renderer` neither installs nor loads it.\r\n */\r\nexport async function getCanvasKit(wasmUrl?: string): Promise<CanvasKit> {\r\n if (canvasKit) return canvasKit;\r\n if (initPromise) return initPromise;\r\n const url = wasmUrl ?? defaultWasmUrl();\r\n\r\n initPromise = import(\"@motionscript/canvaskit\")\r\n .then(({ default: CanvasKitInit }) => CanvasKitInit({ locateFile: () => url }))\r\n .then((ck) => {\r\n canvasKit = ck;\r\n return ck;\r\n });\r\n return initPromise;\r\n}\r\n"]}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { SkiaMeasureContext } from "@motionscript/skia-render/measure-context";
|
|
2
|
-
/**
|
|
3
|
-
* Browser alias for {@link SkiaMeasureContext}.
|
|
4
|
-
*
|
|
5
|
-
* A real subclass rather than a re-export, so `instanceof WebMeasureContext` and the
|
|
6
|
-
* name in a stack trace both still mean something, and so a future
|
|
7
|
-
* browser-specific measurement path has an obvious home. Text measurement itself
|
|
8
|
-
* is pure Skia paragraph layout and needs no platform code at all.
|
|
9
|
-
*/
|
|
10
|
-
export declare class WebMeasureContext extends SkiaMeasureContext {
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=measure-context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"measure-context.d.ts","sourceRoot":"","sources":["../src/measure-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AAE/E;;;;;;;GAOG;AACH,qBAAa,iBAAkB,SAAQ,kBAAkB;CAAI"}
|
package/dist/measure-context.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { SkiaMeasureContext } from "@motionscript/skia-render/measure-context";
|
|
2
|
-
/**
|
|
3
|
-
* Browser alias for {@link SkiaMeasureContext}.
|
|
4
|
-
*
|
|
5
|
-
* A real subclass rather than a re-export, so `instanceof WebMeasureContext` and the
|
|
6
|
-
* name in a stack trace both still mean something, and so a future
|
|
7
|
-
* browser-specific measurement path has an obvious home. Text measurement itself
|
|
8
|
-
* is pure Skia paragraph layout and needs no platform code at all.
|
|
9
|
-
*/
|
|
10
|
-
export class WebMeasureContext extends SkiaMeasureContext {
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=measure-context.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"measure-context.js","sourceRoot":"","sources":["../src/measure-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AAE/E;;;;;;;GAOG;AACH,MAAM,OAAO,iBAAkB,SAAQ,kBAAkB;CAAI","sourcesContent":["import { SkiaMeasureContext } from \"@motionscript/skia-render/measure-context\";\r\n\r\n/**\r\n * Browser alias for {@link SkiaMeasureContext}.\r\n *\r\n * A real subclass rather than a re-export, so `instanceof WebMeasureContext` and the\r\n * name in a stack trace both still mean something, and so a future\r\n * browser-specific measurement path has an obvious home. Text measurement itself\r\n * is pure Skia paragraph layout and needs no platform code at all.\r\n */\r\nexport class WebMeasureContext extends SkiaMeasureContext { }\r\n"]}
|
package/dist/render-context.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { CanvasKit } from "@motionscript/canvaskit";
|
|
2
|
-
import { SkiaRenderContext } from "@motionscript/skia-render/render-context";
|
|
3
|
-
import type { WebStorageAdapter } from "./storage-adapter";
|
|
4
|
-
/**
|
|
5
|
-
* Browser bindings for {@link SkiaRenderContext}.
|
|
6
|
-
*
|
|
7
|
-
* Everything about *how a frame is drawn* — shapes, fills, strokes, text, effects,
|
|
8
|
-
* clips, masks, the camera, the 3D composite — lives in
|
|
9
|
-
* `@motionscript/skia-render` and is shared with every other backend. What is
|
|
10
|
-
* genuinely browser-specific is only what is below: the WebGL renderer 3D draws
|
|
11
|
-
* with (installed on construction, so every path that draws has it), creating a
|
|
12
|
-
* WebGL-backed Skia surface over a `<canvas>`, and encoding a snapshot (this
|
|
13
|
-
* CanvasKit build ships no wasm image encoders, so the encode has to come from
|
|
14
|
-
* the host).
|
|
15
|
-
*/
|
|
16
|
-
export declare class WebRenderContext extends SkiaRenderContext {
|
|
17
|
-
constructor(canvasKit: CanvasKit, storageAdapter: WebStorageAdapter);
|
|
18
|
-
/** Attaches a WebGL CanvasKit surface to `canvas`, remounting if already mounted (HMR/StrictMode). */
|
|
19
|
-
mount(canvas: HTMLCanvasElement): void;
|
|
20
|
-
/**
|
|
21
|
-
* Core declares `unmount()`; it is `detach()` on the portable base, since
|
|
22
|
-
* "unmount" only means anything where there is a DOM element to unmount from.
|
|
23
|
-
*/
|
|
24
|
-
unmount(): void;
|
|
25
|
-
/**
|
|
26
|
-
* Snapshots the current surface and encodes it as an image data URL through a
|
|
27
|
-
* 2D canvas. Defaults to PNG; pass `mime`/`quality` (e.g. `"image/jpeg", 0.9`)
|
|
28
|
-
* for other formats.
|
|
29
|
-
*/
|
|
30
|
-
screenshot(mime?: string, quality?: number): string | undefined;
|
|
31
|
-
/** The surface read back into a fresh 2D canvas, or `undefined` when unmounted or no 2D context could be made. */
|
|
32
|
-
snapshotCanvas(): HTMLCanvasElement | undefined;
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=render-context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"render-context.d.ts","sourceRoot":"","sources":["../src/render-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAG3D;;;;;;;;;;;GAWG;AACH,qBAAa,gBAAiB,SAAQ,iBAAiB;gBACvC,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,iBAAiB;IAKnE,sGAAsG;IACtG,KAAK,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI;IAMtC;;;OAGG;IACM,OAAO,IAAI,IAAI;IAIxB;;;;OAIG;IACM,UAAU,CAAC,IAAI,GAAE,MAAoB,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAOrF,kHAAkH;IAClH,cAAc,IAAI,iBAAiB,GAAG,SAAS;CAelD"}
|
package/dist/render-context.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { SkiaRenderContext } from "@motionscript/skia-render/render-context";
|
|
2
|
-
import { installWebCanvas3D } from "./three/renderer";
|
|
3
|
-
/**
|
|
4
|
-
* Browser bindings for {@link SkiaRenderContext}.
|
|
5
|
-
*
|
|
6
|
-
* Everything about *how a frame is drawn* — shapes, fills, strokes, text, effects,
|
|
7
|
-
* clips, masks, the camera, the 3D composite — lives in
|
|
8
|
-
* `@motionscript/skia-render` and is shared with every other backend. What is
|
|
9
|
-
* genuinely browser-specific is only what is below: the WebGL renderer 3D draws
|
|
10
|
-
* with (installed on construction, so every path that draws has it), creating a
|
|
11
|
-
* WebGL-backed Skia surface over a `<canvas>`, and encoding a snapshot (this
|
|
12
|
-
* CanvasKit build ships no wasm image encoders, so the encode has to come from
|
|
13
|
-
* the host).
|
|
14
|
-
*/
|
|
15
|
-
export class WebRenderContext extends SkiaRenderContext {
|
|
16
|
-
constructor(canvasKit, storageAdapter) {
|
|
17
|
-
super(canvasKit, storageAdapter);
|
|
18
|
-
installWebCanvas3D();
|
|
19
|
-
}
|
|
20
|
-
/** Attaches a WebGL CanvasKit surface to `canvas`, remounting if already mounted (HMR/StrictMode). */
|
|
21
|
-
mount(canvas) {
|
|
22
|
-
const surface = this.canvasKit.MakeWebGLCanvasSurface(canvas);
|
|
23
|
-
if (!surface)
|
|
24
|
-
throw new Error("Failed to create CanvasKit surface");
|
|
25
|
-
this.attach(surface);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Core declares `unmount()`; it is `detach()` on the portable base, since
|
|
29
|
-
* "unmount" only means anything where there is a DOM element to unmount from.
|
|
30
|
-
*/
|
|
31
|
-
unmount() {
|
|
32
|
-
this.detach();
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Snapshots the current surface and encodes it as an image data URL through a
|
|
36
|
-
* 2D canvas. Defaults to PNG; pass `mime`/`quality` (e.g. `"image/jpeg", 0.9`)
|
|
37
|
-
* for other formats.
|
|
38
|
-
*/
|
|
39
|
-
screenshot(mime = "image/png", quality) {
|
|
40
|
-
// A data: URL rather than a blob: URL — both work as an <img> src and a
|
|
41
|
-
// data URL needs no revoke. `quality` is honored only by lossy formats
|
|
42
|
-
// (e.g. image/jpeg); the browser ignores it for image/png.
|
|
43
|
-
return this.snapshotCanvas()?.toDataURL(mime, quality);
|
|
44
|
-
}
|
|
45
|
-
/** The surface read back into a fresh 2D canvas, or `undefined` when unmounted or no 2D context could be made. */
|
|
46
|
-
snapshotCanvas() {
|
|
47
|
-
const snapshot = this.snapshotPixels();
|
|
48
|
-
if (!snapshot)
|
|
49
|
-
return undefined;
|
|
50
|
-
const { pixels, width, height } = snapshot;
|
|
51
|
-
const canvas = document.createElement("canvas");
|
|
52
|
-
canvas.width = width;
|
|
53
|
-
canvas.height = height;
|
|
54
|
-
const ctx = canvas.getContext("2d");
|
|
55
|
-
if (!ctx)
|
|
56
|
-
return undefined;
|
|
57
|
-
// `pixels` is already unpremultiplied RGBA8888 copied out of the wasm heap,
|
|
58
|
-
// which is exactly ImageData's layout.
|
|
59
|
-
ctx.putImageData(new ImageData(new Uint8ClampedArray(pixels), width, height), 0, 0);
|
|
60
|
-
return canvas;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
//# sourceMappingURL=render-context.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"render-context.js","sourceRoot":"","sources":["../src/render-context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAE7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,gBAAiB,SAAQ,iBAAiB;IACnD,YAAY,SAAoB,EAAE,cAAiC;QAC/D,KAAK,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;QACjC,kBAAkB,EAAE,CAAC;IACzB,CAAC;IAED,sGAAsG;IACtG,KAAK,CAAC,MAAyB;QAC3B,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC;QAC9D,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;QACpE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IAED;;;OAGG;IACM,OAAO;QACZ,IAAI,CAAC,MAAM,EAAE,CAAC;IAClB,CAAC;IAED;;;;OAIG;IACM,UAAU,CAAC,OAAe,WAAW,EAAE,OAAgB;QAC5D,wEAAwE;QACxE,uEAAuE;QACvE,2DAA2D;QAC3D,OAAO,IAAI,CAAC,cAAc,EAAE,EAAE,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC3D,CAAC;IAED,kHAAkH;IAClH,cAAc;QACV,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;QACvC,IAAI,CAAC,QAAQ;YAAE,OAAO,SAAS,CAAC;QAChC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,QAAQ,CAAC;QAE3C,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;QACrB,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;QACvB,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACpC,IAAI,CAAC,GAAG;YAAE,OAAO,SAAS,CAAC;QAC3B,4EAA4E;QAC5E,uCAAuC;QACvC,GAAG,CAAC,YAAY,CAAC,IAAI,SAAS,CAAC,IAAI,iBAAiB,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACpF,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ","sourcesContent":["import type { CanvasKit } from \"@motionscript/canvaskit\";\r\nimport { SkiaRenderContext } from \"@motionscript/skia-render/render-context\";\r\nimport type { WebStorageAdapter } from \"./storage-adapter\";\r\nimport { installWebCanvas3D } from \"./three/renderer\";\r\n\r\n/**\r\n * Browser bindings for {@link SkiaRenderContext}.\r\n *\r\n * Everything about *how a frame is drawn* — shapes, fills, strokes, text, effects,\r\n * clips, masks, the camera, the 3D composite — lives in\r\n * `@motionscript/skia-render` and is shared with every other backend. What is\r\n * genuinely browser-specific is only what is below: the WebGL renderer 3D draws\r\n * with (installed on construction, so every path that draws has it), creating a\r\n * WebGL-backed Skia surface over a `<canvas>`, and encoding a snapshot (this\r\n * CanvasKit build ships no wasm image encoders, so the encode has to come from\r\n * the host).\r\n */\r\nexport class WebRenderContext extends SkiaRenderContext {\r\n constructor(canvasKit: CanvasKit, storageAdapter: WebStorageAdapter) {\r\n super(canvasKit, storageAdapter);\r\n installWebCanvas3D();\r\n }\r\n\r\n /** Attaches a WebGL CanvasKit surface to `canvas`, remounting if already mounted (HMR/StrictMode). */\r\n mount(canvas: HTMLCanvasElement): void {\r\n const surface = this.canvasKit.MakeWebGLCanvasSurface(canvas);\r\n if (!surface) throw new Error(\"Failed to create CanvasKit surface\");\r\n this.attach(surface);\r\n }\r\n\r\n /**\r\n * Core declares `unmount()`; it is `detach()` on the portable base, since\r\n * \"unmount\" only means anything where there is a DOM element to unmount from.\r\n */\r\n override unmount(): void {\r\n this.detach();\r\n }\r\n\r\n /**\r\n * Snapshots the current surface and encodes it as an image data URL through a\r\n * 2D canvas. Defaults to PNG; pass `mime`/`quality` (e.g. `\"image/jpeg\", 0.9`)\r\n * for other formats.\r\n */\r\n override screenshot(mime: string = \"image/png\", quality?: number): string | undefined {\r\n // A data: URL rather than a blob: URL — both work as an <img> src and a\r\n // data URL needs no revoke. `quality` is honored only by lossy formats\r\n // (e.g. image/jpeg); the browser ignores it for image/png.\r\n return this.snapshotCanvas()?.toDataURL(mime, quality);\r\n }\r\n\r\n /** The surface read back into a fresh 2D canvas, or `undefined` when unmounted or no 2D context could be made. */\r\n snapshotCanvas(): HTMLCanvasElement | undefined {\r\n const snapshot = this.snapshotPixels();\r\n if (!snapshot) return undefined;\r\n const { pixels, width, height } = snapshot;\r\n\r\n const canvas = document.createElement(\"canvas\");\r\n canvas.width = width;\r\n canvas.height = height;\r\n const ctx = canvas.getContext(\"2d\");\r\n if (!ctx) return undefined;\r\n // `pixels` is already unpremultiplied RGBA8888 copied out of the wasm heap,\r\n // which is exactly ImageData's layout.\r\n ctx.putImageData(new ImageData(new Uint8ClampedArray(pixels), width, height), 0, 0);\r\n return canvas;\r\n }\r\n}\r\n"]}
|