@openartifactsai/motion-stage 0.0.0-stage → 0.23.0-rc.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 +202 -0
- package/NOTICE +5 -0
- package/README.md +5 -2
- package/package.json +70 -4
- package/src/build.d.ts +18 -0
- package/src/build.js +73 -0
- package/src/host.d.ts +37 -0
- package/src/host.js +76 -0
- package/src/index.d.ts +11 -0
- package/src/index.js +6 -0
- package/src/layers.d.ts +30 -0
- package/src/layers.js +56 -0
- package/src/offline/audio.d.ts +19 -0
- package/src/offline/audio.js +20 -0
- package/src/offline/data.d.ts +26 -0
- package/src/offline/data.js +71 -0
- package/src/offline/main.d.ts +9 -0
- package/src/offline/main.js +52 -0
- package/src/offline/player.d.ts +23 -0
- package/src/offline/player.js +157 -0
- package/src/protocol/clip-guards.d.ts +5 -0
- package/src/protocol/clip-guards.js +22 -0
- package/src/protocol/guards.d.ts +6 -0
- package/src/protocol/guards.js +257 -0
- package/src/protocol/layer-guards.d.ts +7 -0
- package/src/protocol/layer-guards.js +100 -0
- package/src/protocol/layers.d.ts +135 -0
- package/src/protocol/layers.js +1 -0
- package/src/protocol/types.d.ts +340 -0
- package/src/protocol/types.js +7 -0
- package/src/protocol.d.ts +2 -0
- package/src/protocol.js +2 -0
- package/src/raster.d.ts +4 -0
- package/src/raster.js +2 -0
- package/src/runtime/assets.d.ts +19 -0
- package/src/runtime/assets.js +63 -0
- package/src/runtime/caption-box.d.ts +3 -0
- package/src/runtime/caption-box.js +16 -0
- package/src/runtime/captions.d.ts +31 -0
- package/src/runtime/captions.js +115 -0
- package/src/runtime/clip-captions.d.ts +9 -0
- package/src/runtime/clip-captions.js +27 -0
- package/src/runtime/clips.d.ts +83 -0
- package/src/runtime/clips.js +259 -0
- package/src/runtime/console.d.ts +13 -0
- package/src/runtime/console.js +99 -0
- package/src/runtime/cut.d.ts +7 -0
- package/src/runtime/cut.js +63 -0
- package/src/runtime/determinism.d.ts +12 -0
- package/src/runtime/determinism.js +47 -0
- package/src/runtime/film.d.ts +43 -0
- package/src/runtime/film.js +31 -0
- package/src/runtime/focus.d.ts +8 -0
- package/src/runtime/focus.js +71 -0
- package/src/runtime/fonts.d.ts +22 -0
- package/src/runtime/fonts.js +109 -0
- package/src/runtime/frame.d.ts +9 -0
- package/src/runtime/frame.js +140 -0
- package/src/runtime/fx/backdrop.d.ts +60 -0
- package/src/runtime/fx/backdrop.js +264 -0
- package/src/runtime/fx/color.d.ts +19 -0
- package/src/runtime/fx/color.js +84 -0
- package/src/runtime/fx/css-color.d.ts +6 -0
- package/src/runtime/fx/css-color.js +44 -0
- package/src/runtime/fx/curve.d.ts +12 -0
- package/src/runtime/fx/curve.js +34 -0
- package/src/runtime/fx/gl.d.ts +29 -0
- package/src/runtime/fx/gl.js +207 -0
- package/src/runtime/fx/glsl.d.ts +35 -0
- package/src/runtime/fx/glsl.js +113 -0
- package/src/runtime/fx/index.d.ts +23 -0
- package/src/runtime/fx/index.js +151 -0
- package/src/runtime/fx/key.d.ts +11 -0
- package/src/runtime/fx/key.js +21 -0
- package/src/runtime/fx/numbers.d.ts +14 -0
- package/src/runtime/fx/numbers.js +57 -0
- package/src/runtime/fx/pace.d.ts +17 -0
- package/src/runtime/fx/pace.js +26 -0
- package/src/runtime/fx/paint.d.ts +28 -0
- package/src/runtime/fx/paint.js +150 -0
- package/src/runtime/guard.d.ts +4 -0
- package/src/runtime/guard.js +141 -0
- package/src/runtime/hand-titles/index.d.ts +9 -0
- package/src/runtime/hand-titles/index.js +73 -0
- package/src/runtime/hand-titles/layer.d.ts +20 -0
- package/src/runtime/hand-titles/layer.js +118 -0
- package/src/runtime/hand-titles/place.d.ts +27 -0
- package/src/runtime/hand-titles/place.js +45 -0
- package/src/runtime/held-store.d.ts +35 -0
- package/src/runtime/held-store.js +63 -0
- package/src/runtime/held.d.ts +19 -0
- package/src/runtime/held.js +225 -0
- package/src/runtime/kit/camera.d.ts +59 -0
- package/src/runtime/kit/camera.js +81 -0
- package/src/runtime/kit/chip.d.ts +25 -0
- package/src/runtime/kit/chip.js +75 -0
- package/src/runtime/kit/count.d.ts +37 -0
- package/src/runtime/kit/count.js +100 -0
- package/src/runtime/kit/cursor.d.ts +46 -0
- package/src/runtime/kit/cursor.js +108 -0
- package/src/runtime/kit/dom.d.ts +14 -0
- package/src/runtime/kit/dom.js +46 -0
- package/src/runtime/kit/geometry.d.ts +24 -0
- package/src/runtime/kit/geometry.js +56 -0
- package/src/runtime/kit/index.d.ts +113 -0
- package/src/runtime/kit/index.js +157 -0
- package/src/runtime/kit/mark-strokes.d.ts +65 -0
- package/src/runtime/kit/mark-strokes.js +226 -0
- package/src/runtime/kit/marks.d.ts +21 -0
- package/src/runtime/kit/marks.js +165 -0
- package/src/runtime/kit/math.d.ts +23 -0
- package/src/runtime/kit/math.js +35 -0
- package/src/runtime/kit/paper.d.ts +7 -0
- package/src/runtime/kit/paper.js +27 -0
- package/src/runtime/kit/random.d.ts +8 -0
- package/src/runtime/kit/random.js +32 -0
- package/src/runtime/kit/text-fx.d.ts +18 -0
- package/src/runtime/kit/text-fx.js +55 -0
- package/src/runtime/kit/typing.d.ts +21 -0
- package/src/runtime/kit/typing.js +42 -0
- package/src/runtime/laid/layer.d.ts +44 -0
- package/src/runtime/laid/layer.js +370 -0
- package/src/runtime/layers/describe.d.ts +41 -0
- package/src/runtime/layers/describe.js +327 -0
- package/src/runtime/layers/item.d.ts +123 -0
- package/src/runtime/layers/item.js +150 -0
- package/src/runtime/layers/parts.d.ts +53 -0
- package/src/runtime/layers/parts.js +158 -0
- package/src/runtime/layers/rows.d.ts +4 -0
- package/src/runtime/layers/rows.js +233 -0
- package/src/runtime/layers/scan.d.ts +24 -0
- package/src/runtime/layers/scan.js +204 -0
- package/src/runtime/layers/walk.d.ts +16 -0
- package/src/runtime/layers/walk.js +337 -0
- package/src/runtime/load.d.ts +10 -0
- package/src/runtime/load.js +267 -0
- package/src/runtime/main.d.ts +1 -0
- package/src/runtime/main.js +90 -0
- package/src/runtime/modules.d.ts +23 -0
- package/src/runtime/modules.js +53 -0
- package/src/runtime/port.d.ts +8 -0
- package/src/runtime/port.js +46 -0
- package/src/runtime/questions.d.ts +24 -0
- package/src/runtime/questions.js +162 -0
- package/src/runtime/recut.d.ts +81 -0
- package/src/runtime/recut.js +325 -0
- package/src/runtime/render.d.ts +80 -0
- package/src/runtime/render.js +358 -0
- package/src/runtime/retouch/ask.d.ts +17 -0
- package/src/runtime/retouch/ask.js +171 -0
- package/src/runtime/retouch/entry.d.ts +77 -0
- package/src/runtime/retouch/entry.js +1 -0
- package/src/runtime/retouch/judge.d.ts +25 -0
- package/src/runtime/retouch/judge.js +209 -0
- package/src/runtime/retouch/look.d.ts +39 -0
- package/src/runtime/retouch/look.js +135 -0
- package/src/runtime/retouch/own-styles.d.ts +19 -0
- package/src/runtime/retouch/own-styles.js +141 -0
- package/src/runtime/retouch/parts.d.ts +22 -0
- package/src/runtime/retouch/parts.js +166 -0
- package/src/runtime/retouch/retouch.d.ts +37 -0
- package/src/runtime/retouch/retouch.js +238 -0
- package/src/runtime/retouch/seat.d.ts +40 -0
- package/src/runtime/retouch/seat.js +228 -0
- package/src/runtime/retouch/state.d.ts +37 -0
- package/src/runtime/retouch/state.js +153 -0
- package/src/runtime/retouch/type-style.d.ts +19 -0
- package/src/runtime/retouch/type-style.js +111 -0
- package/src/runtime/scan.d.ts +2 -0
- package/src/runtime/scan.js +49 -0
- package/src/runtime/scenes/card.d.ts +12 -0
- package/src/runtime/scenes/card.js +56 -0
- package/src/runtime/scenes/install.d.ts +69 -0
- package/src/runtime/scenes/install.js +528 -0
- package/src/runtime/scenes/read.d.ts +27 -0
- package/src/runtime/scenes/read.js +73 -0
- package/src/runtime/scenes/scoped.d.ts +13 -0
- package/src/runtime/scenes/scoped.js +46 -0
- package/src/runtime/score.d.ts +32 -0
- package/src/runtime/score.js +262 -0
- package/src/runtime/sketch/pen.d.ts +3 -0
- package/src/runtime/sketch/pen.js +371 -0
- package/src/runtime/sketch/strokes.d.ts +41 -0
- package/src/runtime/sketch/strokes.js +187 -0
- package/src/runtime/snapshot/draw.d.ts +14 -0
- package/src/runtime/snapshot/draw.js +125 -0
- package/src/runtime/snapshot/hold-first-draw.d.ts +12 -0
- package/src/runtime/snapshot/hold-first-draw.js +128 -0
- package/src/runtime/snapshot/lift.d.ts +41 -0
- package/src/runtime/snapshot/lift.js +161 -0
- package/src/runtime/snapshot/plate.d.ts +20 -0
- package/src/runtime/snapshot/plate.js +79 -0
- package/src/runtime/snapshot/serialize.d.ts +51 -0
- package/src/runtime/snapshot/serialize.js +286 -0
- package/src/runtime/snapshot/styles.d.ts +8 -0
- package/src/runtime/snapshot/styles.js +109 -0
- package/src/runtime/snapshot/xml.d.ts +6 -0
- package/src/runtime/snapshot/xml.js +110 -0
- package/src/runtime/stage-size.d.ts +7 -0
- package/src/runtime/stage-size.js +3 -0
- package/src/runtime/stage.d.ts +27 -0
- package/src/runtime/stage.js +154 -0
- package/src/runtime/stretch.d.ts +13 -0
- package/src/runtime/stretch.js +16 -0
- package/src/runtime/texts.d.ts +24 -0
- package/src/runtime/texts.js +211 -0
- package/src/runtime/video-sync.d.ts +51 -0
- package/src/runtime/video-sync.js +218 -0
- package/src/stills.d.ts +90 -0
- package/src/stills.js +329 -0
- package/src/tools/film.d.ts +13 -0
- package/src/tools/film.js +116 -0
- package/src/tools/levels.d.ts +8 -0
- package/src/tools/levels.js +28 -0
- package/src/tools/main.d.ts +1 -0
- package/src/tools/main.js +223 -0
- package/src/tools/score.d.ts +4 -0
- package/src/tools/score.js +35 -0
- package/src/tools/types.d.ts +84 -0
- package/src/tools/types.js +2 -0
- package/src/tools.d.ts +6 -0
- package/src/tools.js +4 -0
- package/src/virtual.d.ts +11 -0
- package/src/vite.d.ts +8 -0
- package/src/vite.js +43 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
function drawPlain(source, w, h, into) {
|
|
2
|
+
const canvas = into ?? document.createElement('canvas');
|
|
3
|
+
canvas.width = w;
|
|
4
|
+
canvas.height = h;
|
|
5
|
+
const context = canvas.getContext('2d');
|
|
6
|
+
if (!context)
|
|
7
|
+
throw new Error('no 2d context');
|
|
8
|
+
context.drawImage(source, 0, 0, w, h);
|
|
9
|
+
// A lost context ignores draws until the browser restores it; the caller's catch then takes a new canvas.
|
|
10
|
+
if (into && context.isContextLost())
|
|
11
|
+
throw new Error('canvas context lost');
|
|
12
|
+
// createImageBitmap copies the canvas now, so frames that share it cannot get each other's picture.
|
|
13
|
+
return into ? createImageBitmap(canvas) : canvas;
|
|
14
|
+
}
|
|
15
|
+
const drawBitmap = (source, w, h) => createImageBitmap(source, { resizeWidth: w, resizeHeight: h });
|
|
16
|
+
/*
|
|
17
|
+
* The test scene, 16 × 12: an opaque box and, two bands down, a bare one, each with a hard shadow 8 px to its right.
|
|
18
|
+
* Redrawn right at 32 × 24 it is opaque or clear on both sides of every upright edge of rows 4, 12 and 20.
|
|
19
|
+
*/
|
|
20
|
+
const SCENE = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="12"><foreignObject width="16" height="12"><div xmlns="http://www.w3.org/1999/xhtml">' +
|
|
21
|
+
'<div style="width:4px;height:4px;background:#000;box-shadow:8px 0 0 #000"></div><div style="width:4px;height:4px;margin-top:4px;box-shadow:8px 0 0 #000"></div></div></foreignObject></svg>';
|
|
22
|
+
const RIGHT = '11001100' + '00000000' + '00001100';
|
|
23
|
+
function drawsRight(picture) {
|
|
24
|
+
if (picture.width !== 32 || picture.height !== 24)
|
|
25
|
+
return false;
|
|
26
|
+
const copy = drawPlain(picture, 32, 24);
|
|
27
|
+
if (!(copy instanceof HTMLCanvasElement))
|
|
28
|
+
return false;
|
|
29
|
+
const pixels = copy.getContext('2d')?.getImageData(0, 0, 32, 24).data;
|
|
30
|
+
if (!pixels)
|
|
31
|
+
return false;
|
|
32
|
+
for (let i = 0; i < 24; i++) {
|
|
33
|
+
const alpha = pixels[((4 + 8 * (i >> 3)) * 32 + 8 * ((i & 7) >> 1) + 7 * (i & 1)) * 4 + 3] ?? 0;
|
|
34
|
+
if (RIGHT.charAt(i) === '1' ? alpha < 224 : alpha > 31)
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
function transfers(bitmap) {
|
|
40
|
+
const channel = new MessageChannel();
|
|
41
|
+
try {
|
|
42
|
+
channel.port1.postMessage(bitmap, [bitmap]);
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
channel.port1.close();
|
|
50
|
+
channel.port2.close();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// WebKit is told apart by a CSS property only it has; a WebKit that dropped it keeps the plain draw.
|
|
54
|
+
function isWebKit() {
|
|
55
|
+
try {
|
|
56
|
+
return CSS.supports('-webkit-nbsp-mode', 'space');
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
let chosen = null;
|
|
63
|
+
/**
|
|
64
|
+
* WebKit's canvas leaves CSS shadows' offset and blur unscaled when it draws an SVG at another size, so there the
|
|
65
|
+
* picture is resized by createImageBitmap, if that draws the test scene right. Other engines must not try it:
|
|
66
|
+
* Chromium's bitmap cannot be posted.
|
|
67
|
+
*/
|
|
68
|
+
function pickWay() {
|
|
69
|
+
if (chosen)
|
|
70
|
+
return chosen;
|
|
71
|
+
chosen = !isWebKit()
|
|
72
|
+
? Promise.resolve('plain')
|
|
73
|
+
: new Promise((done) => {
|
|
74
|
+
const scene = new Image();
|
|
75
|
+
scene.onerror = () => done('plain');
|
|
76
|
+
scene.onload = () => {
|
|
77
|
+
new Promise((next) => {
|
|
78
|
+
const plain = drawPlain(scene, 32, 24);
|
|
79
|
+
next(plain instanceof HTMLCanvasElement && drawsRight(plain) ? null : drawBitmap(scene, 32, 24));
|
|
80
|
+
})
|
|
81
|
+
.then((bitmap) => {
|
|
82
|
+
let good = false;
|
|
83
|
+
try {
|
|
84
|
+
good = bitmap !== null && drawsRight(bitmap) && transfers(bitmap);
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
if (bitmap !== null && !good)
|
|
88
|
+
bitmap.close();
|
|
89
|
+
}
|
|
90
|
+
done(good ? 'bitmap' : 'plain');
|
|
91
|
+
})
|
|
92
|
+
.catch(() => done('plain'));
|
|
93
|
+
};
|
|
94
|
+
scene.src = 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(SCENE);
|
|
95
|
+
});
|
|
96
|
+
return chosen;
|
|
97
|
+
}
|
|
98
|
+
/** The catch sees a refusal, or a given canvas that is lost or cannot be copied: it draws in a new one. */
|
|
99
|
+
export function drawSnapshot(picture, w, h, into) {
|
|
100
|
+
return pickWay()
|
|
101
|
+
.then((way) => (way === 'bitmap' ? drawBitmap(picture, w, h) : drawPlain(picture, w, h, into)))
|
|
102
|
+
.catch(() => drawPlain(picture, w, h, into ? document.createElement('canvas') : null));
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Ends an error message: why the text does not parse as XML, in this browser's parser's words (120 characters at
|
|
106
|
+
* most), or '' when it parses, the parser throws, or the text is so long that asking would be slow. Firefox puts
|
|
107
|
+
* the page's address among its words; it is left out.
|
|
108
|
+
*/
|
|
109
|
+
export function whyNoDecode(svg) {
|
|
110
|
+
try {
|
|
111
|
+
const said = svg.length > 1e6 ? null : new DOMParser().parseFromString(svg, 'image/svg+xml').getElementsByTagName('parsererror')[0];
|
|
112
|
+
if (!said)
|
|
113
|
+
return '';
|
|
114
|
+
const words = ((said.querySelector('div') ?? said.firstChild ?? said).textContent ?? '')
|
|
115
|
+
.replace(/\s+/g, ' ')
|
|
116
|
+
.replace(/ Location: \S+/, '')
|
|
117
|
+
.trim()
|
|
118
|
+
.replace(/:$/, '');
|
|
119
|
+
return (': written out as XML to be drawn, it does not parse. The browser says, counting in that XML and not in the film’s code: ' +
|
|
120
|
+
(words.length > 120 ? words.slice(0, 119) + '…' : words));
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return '';
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Firefox leaves text filled through `background-clip: text` out of an SVG picture drawn before its 5 ms first-paint
|
|
3
|
+
* timer fires, and keeps that picture. `holdFirstDraw(svg, waitMs, draw)` calls `draw` once a test picture made after
|
|
4
|
+
* `svg` shows its own clipped text, or after `waitMs` (512 by default, 2000 at most, at once unless above 0).
|
|
5
|
+
* Elsewhere it draws at once. Delete once Firefox shows such text in a picture drawn in its onload.
|
|
6
|
+
*/
|
|
7
|
+
export type HoldFirstDraw = (svg: string, waitMs: number | undefined, draw: () => void) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Made before the film clock replaces performance.now: it binds the real one, and never calls Math.random.
|
|
10
|
+
* Only Firefox supports -moz-appearance; a Firefox that dropped it would lose such text again.
|
|
11
|
+
*/
|
|
12
|
+
export declare function makeHoldFirstDraw(): HoldFirstDraw;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
const atOnce = (_svg, _waitMs, draw) => draw();
|
|
2
|
+
/**
|
|
3
|
+
* Made before the film clock replaces performance.now: it binds the real one, and never calls Math.random.
|
|
4
|
+
* Only Firefox supports -moz-appearance; a Firefox that dropped it would lose such text again.
|
|
5
|
+
*/
|
|
6
|
+
export function makeHoldFirstDraw() {
|
|
7
|
+
try {
|
|
8
|
+
if (!CSS.supports('-moz-appearance', 'none'))
|
|
9
|
+
return atOnce;
|
|
10
|
+
return firefoxHold(performance.now.bind(performance), crypto.getRandomValues.bind(crypto));
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return atOnce;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// A canvas that cannot be read counts as inked, so that nothing waits for it.
|
|
17
|
+
function inked(picture) {
|
|
18
|
+
try {
|
|
19
|
+
const canvas = document.createElement('canvas');
|
|
20
|
+
canvas.width = canvas.height = 16;
|
|
21
|
+
const context = canvas.getContext('2d', { willReadFrequently: true });
|
|
22
|
+
if (!context)
|
|
23
|
+
return true;
|
|
24
|
+
if (picture)
|
|
25
|
+
context.drawImage(picture, 0, 0);
|
|
26
|
+
const pixels = context.getImageData(0, 0, 16, 16).data;
|
|
27
|
+
for (let p = 3; p < pixels.length; p += 4)
|
|
28
|
+
if ((pixels[p] ?? 0) > 64)
|
|
29
|
+
return true;
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Firefox writes such a background as "padding-box text" once a script has changed the style.
|
|
37
|
+
function maySpellSuchAFill(svg) {
|
|
38
|
+
return svg.indexOf('-clip') >= 0 || svg.indexOf('-box text') >= 0 || /background\s*:[^;:}"]{0,600}\btext\b/.test(svg);
|
|
39
|
+
}
|
|
40
|
+
function firefoxHold(now, random) {
|
|
41
|
+
const wait = setTimeout.bind(self);
|
|
42
|
+
const clear = clearTimeout.bind(self);
|
|
43
|
+
const Picture = Image;
|
|
44
|
+
const Channel = MessageChannel;
|
|
45
|
+
let faked;
|
|
46
|
+
let ranOut = 0;
|
|
47
|
+
// Its URL is new each time: Firefox reuses the picture it already made for a URL.
|
|
48
|
+
const testPicture = (then) => {
|
|
49
|
+
const picture = new Picture();
|
|
50
|
+
const id = random(new Uint32Array(2));
|
|
51
|
+
picture.onload = () => then(picture);
|
|
52
|
+
picture.onerror = () => then(null);
|
|
53
|
+
picture.src =
|
|
54
|
+
'data:image/svg+xml;charset=utf-8,' +
|
|
55
|
+
encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" data-n="${id[0]}-${id[1]}"><foreignObject width="16" height="16"><div xmlns="http://www.w3.org/1999/xhtml" style="font:700 16px/16px sans-serif;background:#000;-webkit-background-clip:text;background-clip:text;color:transparent">MM</div></foreignObject></svg>`);
|
|
56
|
+
};
|
|
57
|
+
// Waits by messages to itself: Firefox slows setTimeout to once a second in a hidden tab. It always yields once.
|
|
58
|
+
const turns = (until, then) => {
|
|
59
|
+
const channel = new Channel();
|
|
60
|
+
channel.port1.onmessage = () => {
|
|
61
|
+
if (now() < until)
|
|
62
|
+
channel.port2.postMessage(0);
|
|
63
|
+
else {
|
|
64
|
+
channel.port1.close();
|
|
65
|
+
then();
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
channel.port2.postMessage(0);
|
|
69
|
+
};
|
|
70
|
+
return (svg, waitMs = 512, draw) => {
|
|
71
|
+
if (!(waitMs > 0) || ranOut >= 3 || !maySpellSuchAFill(svg))
|
|
72
|
+
return draw();
|
|
73
|
+
// Reads are faked (privacy.resistFingerprinting): no test picture could be judged.
|
|
74
|
+
if (faked === undefined)
|
|
75
|
+
faked = inked(null);
|
|
76
|
+
if (faked)
|
|
77
|
+
return draw();
|
|
78
|
+
const looks = [0];
|
|
79
|
+
const tests = [];
|
|
80
|
+
let done = false;
|
|
81
|
+
let guard;
|
|
82
|
+
const finish = (showed) => {
|
|
83
|
+
if (done)
|
|
84
|
+
return;
|
|
85
|
+
done = true;
|
|
86
|
+
clear(guard);
|
|
87
|
+
ranOut = showed ? 0 : ranOut + 1;
|
|
88
|
+
draw();
|
|
89
|
+
};
|
|
90
|
+
// Each look reads its own picture: one first drawn too early stays blank.
|
|
91
|
+
const look = (n, start) => {
|
|
92
|
+
try {
|
|
93
|
+
turns(start + (looks[n] ?? 0), () => {
|
|
94
|
+
if (done)
|
|
95
|
+
return;
|
|
96
|
+
if (inked(tests[n] ?? null))
|
|
97
|
+
finish(true);
|
|
98
|
+
else if (n + 1 < looks.length)
|
|
99
|
+
look(n + 1, start);
|
|
100
|
+
else
|
|
101
|
+
finish(false);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
finish(false);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
try {
|
|
109
|
+
guard = wait(() => finish(false), 4000);
|
|
110
|
+
for (let ms = 8; ms < waitMs && ms < 2000; ms *= 2)
|
|
111
|
+
looks.push(ms);
|
|
112
|
+
looks.push(Math.min(waitMs, 2000));
|
|
113
|
+
let left = looks.length;
|
|
114
|
+
looks.forEach((_ms, i) => {
|
|
115
|
+
testPicture((picture) => {
|
|
116
|
+
if (!picture)
|
|
117
|
+
return finish(false);
|
|
118
|
+
tests[i] = picture;
|
|
119
|
+
if (--left === 0)
|
|
120
|
+
look(0, now());
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
finish(false);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** A box in the film's own pixels. */
|
|
2
|
+
export interface FilmBox {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
w: number;
|
|
6
|
+
h: number;
|
|
7
|
+
}
|
|
8
|
+
/** A box on screen, as getBoundingClientRect gives it. */
|
|
9
|
+
export interface ScreenBox {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
}
|
|
15
|
+
/** Whether `box` covers the whole `width` × `height` frame. */
|
|
16
|
+
export declare function coversFrame(box: FilmBox, width: number, height: number): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* `shown` in the film's pixels, given where the stage is on screen (`stage`) and its own width. Null when the stage is
|
|
19
|
+
* not drawn at a size.
|
|
20
|
+
*/
|
|
21
|
+
export declare function inFilmPixels(shown: ScreenBox, stage: ScreenBox, width: number): FilmBox | null;
|
|
22
|
+
/** Whether a CSS color, as getComputedStyle gives it, has no transparency. */
|
|
23
|
+
export declare function opaqueColor(color: string): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* The backdrop an export's frame can take out of the stage's snapshot, or null. As FX.backdrop sets it up: a canvas
|
|
26
|
+
* below everything else (a negative z-index) in a box that is a layer of its own, drawn at z-index 0. Under it, then,
|
|
27
|
+
* lie only that box's own background and what the page draws before the box: the backgrounds of the boxes around it,
|
|
28
|
+
* and what comes before it or is laid flat beside it. Those must draw nothing, and the boxes around it must not fade,
|
|
29
|
+
* blend, filter, clip or move it.
|
|
30
|
+
*/
|
|
31
|
+
export declare function liftableBackdrop(stage: HTMLElement, width: number, height: number): HTMLCanvasElement | null;
|
|
32
|
+
/**
|
|
33
|
+
* The backdrop as the export draws it under the snapshot: `pw` × `ph` pixels, its color under its paint, where it is
|
|
34
|
+
* on the stage. Null when this browser cannot make the picture at once.
|
|
35
|
+
*/
|
|
36
|
+
export declare function liftedPicture(canvas: HTMLCanvasElement, stage: HTMLElement, width: number, pw: number, ph: number): ImageBitmap | null;
|
|
37
|
+
/**
|
|
38
|
+
* In a snapshot's copy of the stage (`clone`, which mirrors `stage`), the boxes around a taken-out backdrop draw no
|
|
39
|
+
* background: the backdrop hid them, and the picture drawn under the snapshot must show through.
|
|
40
|
+
*/
|
|
41
|
+
export declare function clearUnder(stage: HTMLElement, clone: HTMLElement, canvas: HTMLCanvasElement): void;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* An export's frame can take a painted backdrop out of its snapshot. Writing a full-size backdrop into the SVG as a PNG
|
|
3
|
+
* costs most of such a frame (the PNG is encoded here, sent, and decoded again by the raster frame), so when the
|
|
4
|
+
* backdrop is what everything else is drawn over, its pixels go along as a picture of their own and the export draws
|
|
5
|
+
* the snapshot on top of it. A backdrop is taken out only when that draws the same frame: it covers the whole frame
|
|
6
|
+
* with an opaque color under its paint, nothing on the stage is drawn beneath it, and nothing around it fades,
|
|
7
|
+
* blends, filters, clips or moves it.
|
|
8
|
+
*/
|
|
9
|
+
/** Below a hundredth of a pixel a box is taken to reach the frame's edge. */
|
|
10
|
+
const EDGE = 0.01;
|
|
11
|
+
/** Whether `box` covers the whole `width` × `height` frame. */
|
|
12
|
+
export function coversFrame(box, width, height) {
|
|
13
|
+
return box.w > 0 && box.h > 0 && box.x <= EDGE && box.y <= EDGE && box.x + box.w >= width - EDGE && box.y + box.h >= height - EDGE;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* `shown` in the film's pixels, given where the stage is on screen (`stage`) and its own width. Null when the stage is
|
|
17
|
+
* not drawn at a size.
|
|
18
|
+
*/
|
|
19
|
+
export function inFilmPixels(shown, stage, width) {
|
|
20
|
+
const k = stage.width / width;
|
|
21
|
+
if (!(k > 0) || !Number.isFinite(k))
|
|
22
|
+
return null;
|
|
23
|
+
return { x: (shown.x - stage.x) / k, y: (shown.y - stage.y) / k, w: shown.width / k, h: shown.height / k };
|
|
24
|
+
}
|
|
25
|
+
/** Whether a CSS color, as getComputedStyle gives it, has no transparency. */
|
|
26
|
+
export function opaqueColor(color) {
|
|
27
|
+
const parts = /^rgba?\(([^)]*)\)$/.exec(color.trim().toLowerCase());
|
|
28
|
+
if (parts === null)
|
|
29
|
+
return false;
|
|
30
|
+
const values = (parts[1] ?? '').split(/[\s,/]+/).filter((part) => part !== '');
|
|
31
|
+
if (values.length === 3)
|
|
32
|
+
return true;
|
|
33
|
+
if (values.length !== 4)
|
|
34
|
+
return false;
|
|
35
|
+
const alpha = values[3] ?? '';
|
|
36
|
+
return alpha.endsWith('%') ? Number.parseFloat(alpha) >= 100 : Number.parseFloat(alpha) >= 1;
|
|
37
|
+
}
|
|
38
|
+
/** Whether an element draws what is inside it as it is: no fade, blend, filter, clip or mask. */
|
|
39
|
+
function plainGroup(style) {
|
|
40
|
+
const none = (value) => value === 'none' || value === '';
|
|
41
|
+
return style.opacity === '1' && none(style.filter) && none(style.backdropFilter) && (style.mixBlendMode === 'normal' || style.mixBlendMode === '') && none(style.clipPath) && none(style.maskImage);
|
|
42
|
+
}
|
|
43
|
+
const drawsNothing = (element) => element.getClientRects().length === 0;
|
|
44
|
+
/** Whether an element draws what is inside it as a layer of its own (a stacking context). */
|
|
45
|
+
function ownLayer(style) {
|
|
46
|
+
return style.isolation === 'isolate' || (style.position !== 'static' && style.zIndex !== 'auto');
|
|
47
|
+
}
|
|
48
|
+
/** Whether a later sibling of a layer drawn at z-index 0 is drawn over that layer, as the page lays layers. */
|
|
49
|
+
function drawnOver(element) {
|
|
50
|
+
if (drawsNothing(element))
|
|
51
|
+
return true;
|
|
52
|
+
const style = getComputedStyle(element);
|
|
53
|
+
return style.position !== 'static' || style.isolation === 'isolate' || style.opacity !== '1' || style.transform !== 'none';
|
|
54
|
+
}
|
|
55
|
+
const hasText = (parent) => [...parent.childNodes].some((node) => node.nodeType === Node.TEXT_NODE && (node.textContent ?? '').trim() !== '');
|
|
56
|
+
/**
|
|
57
|
+
* The backdrop an export's frame can take out of the stage's snapshot, or null. As FX.backdrop sets it up: a canvas
|
|
58
|
+
* below everything else (a negative z-index) in a box that is a layer of its own, drawn at z-index 0. Under it, then,
|
|
59
|
+
* lie only that box's own background and what the page draws before the box: the backgrounds of the boxes around it,
|
|
60
|
+
* and what comes before it or is laid flat beside it. Those must draw nothing, and the boxes around it must not fade,
|
|
61
|
+
* blend, filter, clip or move it.
|
|
62
|
+
*/
|
|
63
|
+
export function liftableBackdrop(stage, width, height) {
|
|
64
|
+
const canvas = [...stage.querySelectorAll('canvas[data-film-backdrop]')].find((found) => !drawsNothing(found));
|
|
65
|
+
if (!(canvas instanceof HTMLCanvasElement))
|
|
66
|
+
return null;
|
|
67
|
+
const own = getComputedStyle(canvas);
|
|
68
|
+
if (own.visibility !== 'visible' || own.transform !== 'none' || !own.zIndex.startsWith('-') || !plainGroup(own) || !opaqueColor(own.backgroundColor))
|
|
69
|
+
return null;
|
|
70
|
+
const box = inFilmPixels(canvas.getBoundingClientRect(), stage.getBoundingClientRect(), width);
|
|
71
|
+
if (box === null || !coversFrame(box, width, height))
|
|
72
|
+
return null;
|
|
73
|
+
const into = canvas.parentElement;
|
|
74
|
+
if (into === null || !stage.contains(into))
|
|
75
|
+
return null;
|
|
76
|
+
for (let at = into;;) {
|
|
77
|
+
const style = getComputedStyle(at);
|
|
78
|
+
if (!plainGroup(style))
|
|
79
|
+
return null;
|
|
80
|
+
if (at === stage)
|
|
81
|
+
break;
|
|
82
|
+
if (style.transform !== 'none' || !(style.zIndex === 'auto' || style.zIndex === '0'))
|
|
83
|
+
return null;
|
|
84
|
+
if (at === into && !ownLayer(style))
|
|
85
|
+
return null;
|
|
86
|
+
for (let before = at.previousElementSibling; before !== null; before = before.previousElementSibling)
|
|
87
|
+
if (!drawsNothing(before))
|
|
88
|
+
return null;
|
|
89
|
+
for (let after = at.nextElementSibling; after !== null; after = after.nextElementSibling)
|
|
90
|
+
if (!drawnOver(after))
|
|
91
|
+
return null;
|
|
92
|
+
const parent = at.parentElement;
|
|
93
|
+
if (parent === null || hasText(parent))
|
|
94
|
+
return null;
|
|
95
|
+
at = parent;
|
|
96
|
+
}
|
|
97
|
+
// Nothing else is put below by a negative z-index, but other backdrops, each below the box it is in.
|
|
98
|
+
for (const element of stage.querySelectorAll('*')) {
|
|
99
|
+
if (element === canvas || !getComputedStyle(element).zIndex.startsWith('-'))
|
|
100
|
+
continue;
|
|
101
|
+
const parent = element.parentElement;
|
|
102
|
+
if (!element.matches('canvas[data-film-backdrop]') || parent === null || !ownLayer(getComputedStyle(parent)))
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
return canvas;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The backdrop as the export draws it under the snapshot: `pw` × `ph` pixels, its color under its paint, where it is
|
|
109
|
+
* on the stage. Null when this browser cannot make the picture at once.
|
|
110
|
+
*/
|
|
111
|
+
export function liftedPicture(canvas, stage, width, pw, ph) {
|
|
112
|
+
if (typeof OffscreenCanvas !== 'function')
|
|
113
|
+
return null;
|
|
114
|
+
const box = inFilmPixels(canvas.getBoundingClientRect(), stage.getBoundingClientRect(), width);
|
|
115
|
+
if (box === null)
|
|
116
|
+
return null;
|
|
117
|
+
const k = pw / width;
|
|
118
|
+
try {
|
|
119
|
+
const picture = new OffscreenCanvas(pw, ph);
|
|
120
|
+
const context = picture.getContext('2d');
|
|
121
|
+
if (context === null)
|
|
122
|
+
return null;
|
|
123
|
+
context.fillStyle = getComputedStyle(canvas).backgroundColor;
|
|
124
|
+
context.fillRect(box.x * k, box.y * k, box.w * k, box.h * k);
|
|
125
|
+
context.drawImage(canvas, box.x * k, box.y * k, box.w * k, box.h * k);
|
|
126
|
+
return picture.transferToImageBitmap();
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* In a snapshot's copy of the stage (`clone`, which mirrors `stage`), the boxes around a taken-out backdrop draw no
|
|
134
|
+
* background: the backdrop hid them, and the picture drawn under the snapshot must show through.
|
|
135
|
+
*/
|
|
136
|
+
export function clearUnder(stage, clone, canvas) {
|
|
137
|
+
const path = [];
|
|
138
|
+
for (let at = canvas; at !== stage;) {
|
|
139
|
+
const parent = at.parentElement;
|
|
140
|
+
if (parent === null)
|
|
141
|
+
return;
|
|
142
|
+
path.unshift([...parent.children].indexOf(at));
|
|
143
|
+
at = parent;
|
|
144
|
+
}
|
|
145
|
+
const chain = [clone];
|
|
146
|
+
let copy = clone;
|
|
147
|
+
for (const index of path.slice(0, -1)) {
|
|
148
|
+
const next = copy.children[index];
|
|
149
|
+
if (next === undefined)
|
|
150
|
+
return;
|
|
151
|
+
chain.push(next);
|
|
152
|
+
copy = next;
|
|
153
|
+
}
|
|
154
|
+
for (const element of chain) {
|
|
155
|
+
if (!(element instanceof HTMLElement))
|
|
156
|
+
continue;
|
|
157
|
+
element.style.setProperty('background', 'none', 'important');
|
|
158
|
+
element.style.setProperty('border-color', 'transparent', 'important');
|
|
159
|
+
element.style.setProperty('box-shadow', 'none', 'important');
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { HoldFirstDraw } from './hold-first-draw.js';
|
|
2
|
+
/** The hold is made before the film clock replaces performance.now; the wait comes with the load. */
|
|
3
|
+
export declare function setPlateHold(made: HoldFirstDraw, waitMs: number | undefined): void;
|
|
4
|
+
export declare const plateStats: () => {
|
|
5
|
+
count: number;
|
|
6
|
+
bytes: number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* XHTML for a foreignObject, drawn to a canvas at `scale`. A plate has none of the film's CSS and so no root color of
|
|
10
|
+
* its own: under forced colors its text is plain black, as it is with no theme.
|
|
11
|
+
*/
|
|
12
|
+
export declare function rasterXml(xml: string, width: number, height: number, scale: number): Promise<HTMLCanvasElement>;
|
|
13
|
+
export interface PlateOptions {
|
|
14
|
+
width?: number;
|
|
15
|
+
height?: number;
|
|
16
|
+
scale?: number;
|
|
17
|
+
css?: string;
|
|
18
|
+
}
|
|
19
|
+
/** `kit.raster(html, options)`: a DOM plate drawn once to a canvas, for a cut that draws on canvas (call it in init). */
|
|
20
|
+
export declare function raster(html: string | Node, options?: PlateOptions): Promise<HTMLCanvasElement>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { fontFaceCss, stackCss } from "../fonts.js";
|
|
2
|
+
import { el, h } from "../kit/dom.js";
|
|
3
|
+
import { stageSize } from "../stage-size.js";
|
|
4
|
+
import { noMargin } from "../stage.js";
|
|
5
|
+
import { drawSnapshot, whyNoDecode } from "./draw.js";
|
|
6
|
+
import { PLAIN_INK, decodeFirst, forcedColorsActive, svgForRaster } from "./serialize.js";
|
|
7
|
+
import { xmlOf } from "./xml.js";
|
|
8
|
+
const PLATES_WARN_BYTES = 256 * 1024 * 1024;
|
|
9
|
+
let hold = null;
|
|
10
|
+
let holdMs;
|
|
11
|
+
let plateCount = 0;
|
|
12
|
+
let plateBytes = 0;
|
|
13
|
+
/** The hold is made before the film clock replaces performance.now; the wait comes with the load. */
|
|
14
|
+
export function setPlateHold(made, waitMs) {
|
|
15
|
+
hold = made;
|
|
16
|
+
holdMs = waitMs;
|
|
17
|
+
}
|
|
18
|
+
export const plateStats = () => ({ count: plateCount, bytes: plateBytes });
|
|
19
|
+
function toCanvas(surface, width, height) {
|
|
20
|
+
if (surface instanceof HTMLCanvasElement)
|
|
21
|
+
return surface;
|
|
22
|
+
const canvas = document.createElement('canvas');
|
|
23
|
+
canvas.width = width;
|
|
24
|
+
canvas.height = height;
|
|
25
|
+
canvas.getContext('2d')?.drawImage(surface, 0, 0);
|
|
26
|
+
surface.close();
|
|
27
|
+
return canvas;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* XHTML for a foreignObject, drawn to a canvas at `scale`. A plate has none of the film's CSS and so no root color of
|
|
31
|
+
* its own: under forced colors its text is plain black, as it is with no theme.
|
|
32
|
+
*/
|
|
33
|
+
export function rasterXml(xml, width, height, scale) {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
const { svg, pw, ph } = svgForRaster(xml, width, height, scale, forcedColorsActive() ? PLAIN_INK : undefined);
|
|
36
|
+
const image = new Image();
|
|
37
|
+
const draw = () => {
|
|
38
|
+
try {
|
|
39
|
+
drawSnapshot(image, pw, ph)
|
|
40
|
+
.then((surface) => toCanvas(surface, pw, ph))
|
|
41
|
+
.then(resolve, reject);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
reject(error);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
image.onload = () => (hold ? hold(svg, holdMs, draw) : draw());
|
|
48
|
+
image.onerror = () => reject(new Error('snapshot decode failed (foreignObject)' + whyNoDecode(svg)));
|
|
49
|
+
image.src = 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(svg);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/** `kit.raster(html, options)`: a DOM plate drawn once to a canvas, for a cut that draws on canvas (call it in init). */
|
|
53
|
+
export function raster(html, options = {}) {
|
|
54
|
+
const width = options.width || stageSize.width;
|
|
55
|
+
const height = options.height || stageSize.height;
|
|
56
|
+
const scale = options.scale || 1;
|
|
57
|
+
const holder = el('div', { style: `width:${width}px;height:${height}px;position:relative;overflow:hidden` });
|
|
58
|
+
holder.appendChild(el('style', { text: noMargin('') + fontFaceCss() + stackCss() + (options.css ?? '') }));
|
|
59
|
+
let body = typeof html === 'string' ? h('<div>' + html + '</div>') : html;
|
|
60
|
+
// A stray </div> in a stored film's string: the plate stays what it was, the wrapper alone.
|
|
61
|
+
if (typeof html === 'string' && body instanceof Element && body.hasAttribute('data-kit-holder'))
|
|
62
|
+
body = body.firstElementChild;
|
|
63
|
+
if (body)
|
|
64
|
+
holder.appendChild(body);
|
|
65
|
+
decodeFirst(holder);
|
|
66
|
+
// xmlOf changes what it is given, and html may be the film's own node: a copy, in a document where no custom element's constructor runs and no picture loads.
|
|
67
|
+
const wrap = document.createElement('div');
|
|
68
|
+
wrap.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml');
|
|
69
|
+
wrap.style.cssText = `width:${width}px;height:${height}px;overflow:hidden;position:relative`;
|
|
70
|
+
wrap.appendChild(holder);
|
|
71
|
+
const copy = document.implementation.createHTMLDocument('').importNode(wrap, true);
|
|
72
|
+
return rasterXml(xmlOf(copy), width, height, scale).then((canvas) => {
|
|
73
|
+
plateCount++;
|
|
74
|
+
plateBytes += canvas.width * canvas.height * 4;
|
|
75
|
+
if (plateBytes > PLATES_WARN_BYTES)
|
|
76
|
+
console.warn('kit.raster: plates now hold ' + Math.round(plateBytes / 1048576) + ' MB');
|
|
77
|
+
return canvas;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** A stand-in with no picture: an <img> without a source draws with a broken-image border. */
|
|
2
|
+
export declare const CLEAR_PIXEL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNgYGBgAAAABQABeqhXUAAAAABJRU5ErkJggg==";
|
|
3
|
+
/** The #fx canvas's last PNG, kept until something touches the canvas. */
|
|
4
|
+
export interface FxPicture {
|
|
5
|
+
canvas: HTMLCanvasElement;
|
|
6
|
+
png(): string;
|
|
7
|
+
}
|
|
8
|
+
/** WebKit can paint a picture inside an SVG image blank unless it is told to decode before painting. */
|
|
9
|
+
export declare function decodeFirst(root: ParentNode): void;
|
|
10
|
+
export interface SerializeOptions {
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
/** Under 1, for a caller that only inspects the picture: media are read from small copies and the fonts left out. */
|
|
14
|
+
mediaScale: number;
|
|
15
|
+
fx: FxPicture | null;
|
|
16
|
+
/** Over 0: the scale of a small preview, which leaves slight displacement out. */
|
|
17
|
+
smoothAt: number;
|
|
18
|
+
warn: (video: HTMLVideoElement, key: string, message: string) => void;
|
|
19
|
+
/** A backdrop taken out of the snapshot (see lift.ts): it and what lies under it draw nothing. */
|
|
20
|
+
lift?: HTMLCanvasElement | null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The node as XHTML text for an SVG foreignObject. Canvas, clip and big picture pixels are spliced into the text
|
|
24
|
+
* after serializing: an <img src> set in this long-lived document would start a load it keeps.
|
|
25
|
+
*/
|
|
26
|
+
export declare function serializeForRaster(node: HTMLElement, options: SerializeOptions): string;
|
|
27
|
+
/** A snapshot's text color under forced colors when nothing gives it one: a page's own, with no theme. */
|
|
28
|
+
export declare const PLAIN_INK = "#000";
|
|
29
|
+
/**
|
|
30
|
+
* The SVG keeps its content's own size with no viewBox, and the draw scales it to pw × ph: WebKit ignores an
|
|
31
|
+
* SVG-level scale for positioned HTML in a foreignObject. data-raster-size draws nothing: it makes the text, and so
|
|
32
|
+
* the URL the browser caches by, differ per output size.
|
|
33
|
+
*
|
|
34
|
+
* A snapshot is a document of its own, which the stage's opt-out of forced colors does not reach: the foreignObject
|
|
35
|
+
* opts out, frame and plate alike, or Chromium repaints the picture in the theme's colors. Its default text color is
|
|
36
|
+
* the theme's too, so under forced colors the caller gives `ink` for the root, as an attribute any rule in the snapshot
|
|
37
|
+
* overrides. Not light-dark(), as the stage has: Firefox takes a picture's scheme from the theme.
|
|
38
|
+
*/
|
|
39
|
+
export declare function svgForRaster(xml: string, width: number, height: number, scale: number, ink?: string): {
|
|
40
|
+
svg: string;
|
|
41
|
+
pw: number;
|
|
42
|
+
ph: number;
|
|
43
|
+
};
|
|
44
|
+
/** Taken before the film runs: a film's own matchMedia can replace the global. */
|
|
45
|
+
export declare function watchForcedColors(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Under forced colors (a Windows contrast theme) a frame keeps the film's own colors: the document opts out while
|
|
48
|
+
* `read` runs, or getComputedStyle would give the theme's colors. `read` must stay synchronous.
|
|
49
|
+
*/
|
|
50
|
+
export declare function inOwnColors<T>(read: () => T): T;
|
|
51
|
+
export declare const forcedColorsActive: () => boolean;
|