@open-artifact/motion-stage 0.0.0-stage → 0.12.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 +69 -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 +155 -0
- package/src/protocol/guards.d.ts +6 -0
- package/src/protocol/guards.js +208 -0
- package/src/protocol/layer-guards.d.ts +7 -0
- package/src/protocol/layer-guards.js +97 -0
- package/src/protocol/layers.d.ts +123 -0
- package/src/protocol/layers.js +1 -0
- package/src/protocol/types.d.ts +261 -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/captions.d.ts +26 -0
- package/src/runtime/captions.js +103 -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 +40 -0
- package/src/runtime/film.js +29 -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 +123 -0
- package/src/runtime/kit/camera.d.ts +40 -0
- package/src/runtime/kit/camera.js +56 -0
- package/src/runtime/kit/chip.d.ts +25 -0
- package/src/runtime/kit/chip.js +75 -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 +22 -0
- package/src/runtime/kit/geometry.js +46 -0
- package/src/runtime/kit/index.d.ts +95 -0
- package/src/runtime/kit/index.js +149 -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/layers/describe.d.ts +41 -0
- package/src/runtime/layers/describe.js +327 -0
- package/src/runtime/layers/item.d.ts +121 -0
- package/src/runtime/layers/item.js +149 -0
- package/src/runtime/layers/parts.d.ts +50 -0
- package/src/runtime/layers/parts.js +155 -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 +202 -0
- package/src/runtime/layers/walk.d.ts +16 -0
- package/src/runtime/layers/walk.js +333 -0
- package/src/runtime/load.d.ts +10 -0
- package/src/runtime/load.js +228 -0
- package/src/runtime/main.d.ts +1 -0
- package/src/runtime/main.js +69 -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 +35 -0
- package/src/runtime/recut.js +158 -0
- package/src/runtime/render.d.ts +80 -0
- package/src/runtime/render.js +342 -0
- package/src/runtime/retouch/ask.d.ts +17 -0
- package/src/runtime/retouch/ask.js +156 -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/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 +47 -0
- package/src/runtime/scenes/install.js +387 -0
- package/src/runtime/scenes/read.d.ts +15 -0
- package/src/runtime/scenes/read.js +57 -0
- package/src/runtime/scenes/scoped.d.ts +13 -0
- package/src/runtime/scenes/scoped.js +40 -0
- package/src/runtime/score.d.ts +26 -0
- package/src/runtime/score.js +221 -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/plate.d.ts +20 -0
- package/src/runtime/snapshot/plate.js +79 -0
- package/src/runtime/snapshot/serialize.d.ts +49 -0
- package/src/runtime/snapshot/serialize.js +271 -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 +210 -0
- package/src/runtime/video-sync.d.ts +26 -0
- package/src/runtime/video-sync.js +126 -0
- package/src/stills.d.ts +41 -0
- package/src/stills.js +253 -0
- package/src/tools/film.d.ts +13 -0
- package/src/tools/film.js +116 -0
- package/src/tools/main.d.ts +1 -0
- package/src/tools/main.js +216 -0
- package/src/tools/score.d.ts +4 -0
- package/src/tools/score.js +29 -0
- package/src/tools/types.d.ts +69 -0
- package/src/tools/types.js +2 -0
- package/src/tools.d.ts +5 -0
- package/src/tools.js +3 -0
- package/src/virtual.d.ts +11 -0
- package/src/vite.d.ts +8 -0
- package/src/vite.js +43 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
const n1 = (n) => String(Math.round(n * 10) / 10);
|
|
2
|
+
const n0 = (n) => String(Math.round(n));
|
|
3
|
+
function through(p) {
|
|
4
|
+
const first = p[0] ?? [0, 0];
|
|
5
|
+
const last = p[p.length - 1] ?? first;
|
|
6
|
+
let d = 'M' + n1(first[0]) + ' ' + n1(first[1]);
|
|
7
|
+
for (let k = 1; k < p.length - 1; k++) {
|
|
8
|
+
const a = p[k] ?? first;
|
|
9
|
+
const b = p[k + 1] ?? last;
|
|
10
|
+
d += 'Q' + n1(a[0]) + ' ' + n1(a[1]) + ' ' + n1((a[0] + b[0]) / 2) + ' ' + n1((a[1] + b[1]) / 2);
|
|
11
|
+
}
|
|
12
|
+
return d + 'L' + n1(last[0]) + ' ' + n1(last[1]);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The strokes for one element of w by h px, as path data: a pure function of its arguments, so that a frame follows
|
|
16
|
+
* from t alone.
|
|
17
|
+
*/
|
|
18
|
+
export function sketchBox(seed, w, h, o) {
|
|
19
|
+
const u = o.u;
|
|
20
|
+
const step = 110 * u;
|
|
21
|
+
const thin = Math.min(w, h);
|
|
22
|
+
const b = o.sides;
|
|
23
|
+
// Each line has random numbers of its own, drawn in an order its length does not change: as a box grows, what is drawn stays put.
|
|
24
|
+
const stream = (k) => {
|
|
25
|
+
// Mixed first: the generator is linear, and would give neighbouring seeds the same numbers a constant apart.
|
|
26
|
+
let m = seed + k * 104729;
|
|
27
|
+
m ^= m >>> 16;
|
|
28
|
+
m = Math.imul(m, 0x45d9f3b);
|
|
29
|
+
m ^= m >>> 16;
|
|
30
|
+
let s = ((m >>> 1) % 2147483646) + 1;
|
|
31
|
+
return () => (s = (s * 16807) % 2147483647) / 2147483647;
|
|
32
|
+
};
|
|
33
|
+
const line = (roll, x0, y0, x1, y1, amp) => {
|
|
34
|
+
const len = Math.hypot(x1 - x0, y1 - y0) || 1;
|
|
35
|
+
const ux = (x1 - x0) / len;
|
|
36
|
+
const uy = (y1 - y0) / len;
|
|
37
|
+
const over = Math.min(37 * u, len * 0.11, thin * 0.16);
|
|
38
|
+
const a = over * (0.3 + roll());
|
|
39
|
+
const all = len + a + over * (0.3 + roll());
|
|
40
|
+
const far = amp * Math.min(1, all / step);
|
|
41
|
+
const p = [];
|
|
42
|
+
let off = roll() * 2 - 1;
|
|
43
|
+
const put = (s, f) => {
|
|
44
|
+
p.push([x0 + ux * (s - a) - uy * f * far, y0 + uy * (s - a) + ux * f * far]);
|
|
45
|
+
};
|
|
46
|
+
for (let s = 0;; s += step) {
|
|
47
|
+
const next = roll() * 2 - 1;
|
|
48
|
+
put(s, off);
|
|
49
|
+
if (!(s + step < all) || p.length > 400) {
|
|
50
|
+
put(all, off + ((next - off) * (all - s)) / step);
|
|
51
|
+
return through(p);
|
|
52
|
+
}
|
|
53
|
+
off = next;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
// On one box a wider border is never a thinner pen: what chance adds is the box's own, and under 1 px.
|
|
57
|
+
const base = (3 + Math.max(0, Math.min(1, thin / u / 100 - 1.5))) * u;
|
|
58
|
+
const chance = stream(0)() * Math.min(0.5 * u, 0.8);
|
|
59
|
+
const pen = (bw) => Math.max(2 * u, base + bw - 2) + chance;
|
|
60
|
+
// Pencil: three thin passes; the third is spared on a small element, where it would only thicken the line.
|
|
61
|
+
const stroke = (k, bw, draw) => ({
|
|
62
|
+
main: draw(stream(1 + k), 1),
|
|
63
|
+
again: draw(stream(11 + k), 1.5),
|
|
64
|
+
third: Math.max(w, h) > step ? draw(stream(31 + k), 2.1) : '',
|
|
65
|
+
width: n1(pen(bw)),
|
|
66
|
+
});
|
|
67
|
+
const out = { wash: '', hatch: '', cross: '', fine: n1(1.5 * u), lines: [null, null, null, null] };
|
|
68
|
+
if (o.bar) {
|
|
69
|
+
// With its round ends the stroke covers what the element covers: a dot where the sides are equal.
|
|
70
|
+
out.lines[0] = stroke(0, thin - base + 2, (roll, k) => (w >= h ? line(roll, h / 2, h / 2, w - h / 2, h / 2, 3 * u * k) : line(roll, w / 2, w / 2, w / 2, h - w / 2, 3 * u * k)));
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
const mid = o.onEdge ? 0 : 0.5;
|
|
74
|
+
const x0 = b[3] * mid;
|
|
75
|
+
const y0 = b[0] * mid;
|
|
76
|
+
const x1 = w - b[1] * mid;
|
|
77
|
+
const y1 = h - b[2] * mid;
|
|
78
|
+
const whole = !!(b[0] && b[1] && b[2] && b[3]);
|
|
79
|
+
// As CSS does, radii too large for the box are shrunk by one factor.
|
|
80
|
+
const fit = Math.min(1, o.rx ? w / (2 * o.rx) : 1, o.ry ? h / (2 * o.ry) : 1);
|
|
81
|
+
const round = whole && Math.min(o.rx, o.ry) * fit >= 0.3 * thin;
|
|
82
|
+
const rx = round ? Math.max(0, o.rx * fit - x0) : 0;
|
|
83
|
+
const ry = round ? Math.max(0, o.ry * fit - y0) : 0;
|
|
84
|
+
if (round)
|
|
85
|
+
out.lines[0] = stroke(0, b[0], (roll, k) => ring(roll, k));
|
|
86
|
+
else {
|
|
87
|
+
const edges = [
|
|
88
|
+
[x0, y0, x1, y0],
|
|
89
|
+
[x1, y0, x1, y1],
|
|
90
|
+
[x1, y1, x0, y1],
|
|
91
|
+
[x0, y1, x0, y0],
|
|
92
|
+
];
|
|
93
|
+
edges.forEach((e, k) => {
|
|
94
|
+
if (b[k])
|
|
95
|
+
out.lines[k] = stroke(k, b[k] ?? 0, (roll, more) => line(roll, e[0], e[1], e[2], e[3], 4.5 * u * more));
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function ring(roll, k) {
|
|
99
|
+
// Each point: x, y, the outward normal, and a weight, 0 on a corner and 1 mid-way along a straight run.
|
|
100
|
+
const p = [];
|
|
101
|
+
const q = [];
|
|
102
|
+
const starts = [];
|
|
103
|
+
const full = 4.5 * u * k * 0.8;
|
|
104
|
+
const amp = Math.min(full, (full * Math.min(rx, ry)) / (96 * u));
|
|
105
|
+
const corners = [
|
|
106
|
+
[x1 - rx, y0 + ry, -90, 0, 1],
|
|
107
|
+
[x1 - rx, y1 - ry, 0, -1, 0],
|
|
108
|
+
[x0 + rx, y1 - ry, 90, 0, -1],
|
|
109
|
+
[x0 + rx, y0 + ry, 180, 1, 0],
|
|
110
|
+
];
|
|
111
|
+
corners.forEach((corner, j) => {
|
|
112
|
+
starts.push(p.length + 3);
|
|
113
|
+
for (let i = 0; i <= 6; i++) {
|
|
114
|
+
const t = ((corner[2] + 15 * i) * Math.PI) / 180;
|
|
115
|
+
p.push([corner[0] + rx * Math.cos(t), corner[1] + ry * Math.sin(t), Math.cos(t), Math.sin(t), 0]);
|
|
116
|
+
}
|
|
117
|
+
const run = j % 2 ? x1 - x0 - 2 * rx : y1 - y0 - 2 * ry;
|
|
118
|
+
const n = Math.min(Math.floor(run / step), 400);
|
|
119
|
+
const end = p[p.length - 1];
|
|
120
|
+
if (end)
|
|
121
|
+
for (let m = 1; m <= n; m++)
|
|
122
|
+
p.push([end[0] + (corner[3] * run * m) / (n + 1), end[1] + (corner[4] * run * m) / (n + 1), end[2], end[3], Math.sin((Math.PI * m) / (n + 1))]);
|
|
123
|
+
});
|
|
124
|
+
// A dashed ring stops where it began: dashes laid over dashes would show out of step.
|
|
125
|
+
const from = starts[Math.floor(roll() * 4)] ?? 0;
|
|
126
|
+
const p1 = roll() * 6.3;
|
|
127
|
+
const p2 = roll() * 6.3;
|
|
128
|
+
const p3 = roll() * 6.3;
|
|
129
|
+
const last = p.length + (o.broken ? 0 : 3);
|
|
130
|
+
let was = null;
|
|
131
|
+
for (let i = 0; i <= last; i++) {
|
|
132
|
+
// A slow swell and a drift, so that the end misses the beginning.
|
|
133
|
+
const at = p[(from + i) % p.length];
|
|
134
|
+
if (!at)
|
|
135
|
+
continue;
|
|
136
|
+
const t = ((from + i) * 2 * Math.PI) / p.length;
|
|
137
|
+
const off = (amp + at[4] * (full - amp)) * (0.55 * Math.sin(t + p1) + 0.35 * Math.sin(2 * t + p2) + 0.2 * Math.sin(3 * t + p3)) + amp * 0.9 * (i / last - 0.5);
|
|
138
|
+
// With no straight run between two corners, one ends on the point the next begins with.
|
|
139
|
+
if (!was || Math.hypot(at[0] - was[0], at[1] - was[1]) > 0.5)
|
|
140
|
+
q.push([at[0] + at[2] * off, at[1] + at[3] * off]);
|
|
141
|
+
was = at;
|
|
142
|
+
}
|
|
143
|
+
return through(q);
|
|
144
|
+
}
|
|
145
|
+
if (!whole || !o.hatch)
|
|
146
|
+
return out;
|
|
147
|
+
const arc = (x, y) => (round ? 'A' + n1(rx) + ' ' + n1(ry) + ' 0 0 1 ' + n1(x) + ' ' + n1(y) : '');
|
|
148
|
+
out.wash =
|
|
149
|
+
'M' + n1(x0 + rx) + ' ' + n1(y0) + 'H' + n1(x1 - rx) + arc(x1, y0 + ry) + 'V' + n1(y1 - ry) + arc(x1 - rx, y1) + 'H' + n1(x0 + rx) + arc(x0, y1 - ry) + 'V' + n1(y0 + ry) + arc(x0 + rx, y0) + 'Z';
|
|
150
|
+
const skip = o.skip;
|
|
151
|
+
const inside = (x, y) => {
|
|
152
|
+
if (x < x0 || x > x1 || y < y0 || y > y1 || (skip && x > skip[0] && x < skip[2] && y > skip[1] && y < skip[3]))
|
|
153
|
+
return false;
|
|
154
|
+
const ex = x < x0 + rx ? x0 + rx - x : x > x1 - rx ? x - (x1 - rx) : 0;
|
|
155
|
+
const ey = y < y0 + ry ? y0 + ry - y : y > y1 - ry ? y - (y1 - ry) : 0;
|
|
156
|
+
return !ex || !ey || (ex * ex) / (rx * rx) + (ey * ey) / (ry * ry) <= 1;
|
|
157
|
+
};
|
|
158
|
+
// Shading is two layers a few degrees apart, the second more open, and spared in a small box.
|
|
159
|
+
const layer = (k, lean, wide) => {
|
|
160
|
+
let d = '';
|
|
161
|
+
const roll = stream(k);
|
|
162
|
+
const turn = ((38 + lean + roll() * 10) * Math.PI) / 180;
|
|
163
|
+
const dx = -Math.sin(turn);
|
|
164
|
+
const dy = Math.cos(turn);
|
|
165
|
+
const gap = ((o.hatch === 2 ? 20 : 12) * wide * u) / dy;
|
|
166
|
+
const inch = 3 * u;
|
|
167
|
+
for (let px = gap * (0.3 + roll() * 0.5); px < w - (h * dx) / dy && d.length < 6000; px += gap * (0.7 + roll() * 0.6)) {
|
|
168
|
+
const trim = roll() * 2 * inch;
|
|
169
|
+
let from = -1;
|
|
170
|
+
for (let a = 0; a <= h / dy + inch; a += inch) {
|
|
171
|
+
const on = a <= h / dy && inside(px + dx * a, dy * a);
|
|
172
|
+
if (on && from < 0)
|
|
173
|
+
from = a;
|
|
174
|
+
if (!on && from >= 0) {
|
|
175
|
+
if (a - inch - from > 4 * inch)
|
|
176
|
+
d += 'M' + n0(px + dx * (from + trim)) + ' ' + n0(dy * (from + trim)) + 'L' + n0(px + dx * (a - inch)) + ' ' + n0(dy * (a - inch));
|
|
177
|
+
from = -1;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return d;
|
|
182
|
+
};
|
|
183
|
+
out.hatch = layer(21, 0, 1);
|
|
184
|
+
if (thin > step)
|
|
185
|
+
out.cross = layer(22, 7, 1.7);
|
|
186
|
+
return out;
|
|
187
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a snapshot's SVG picture is drawn at w × h. Shared by the stage (plates) and an export's raster frame.
|
|
3
|
+
* Resolves with a canvas or an ImageBitmap; given a canvas to draw in, always with an ImageBitmap.
|
|
4
|
+
*/
|
|
5
|
+
export type SnapshotSource = HTMLImageElement | HTMLCanvasElement | ImageBitmap;
|
|
6
|
+
export type SnapshotSurface = HTMLCanvasElement | ImageBitmap;
|
|
7
|
+
/** The catch sees a refusal, or a given canvas that is lost or cannot be copied: it draws in a new one. */
|
|
8
|
+
export declare function drawSnapshot(picture: SnapshotSource, w: number, h: number, into?: HTMLCanvasElement | null): Promise<SnapshotSurface>;
|
|
9
|
+
/**
|
|
10
|
+
* Ends an error message: why the text does not parse as XML, in this browser's parser's words (120 characters at
|
|
11
|
+
* most), or '' when it parses, the parser throws, or the text is so long that asking would be slow. Firefox puts
|
|
12
|
+
* the page's address among its words; it is left out.
|
|
13
|
+
*/
|
|
14
|
+
export declare function whyNoDecode(svg: string): string;
|
|
@@ -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,20 @@
|
|
|
1
|
+
import type { HoldFirstDraw } from './hold-first-draw.ts';
|
|
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,49 @@
|
|
|
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
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The node as XHTML text for an SVG foreignObject. Canvas, clip and big picture pixels are spliced into the text
|
|
22
|
+
* after serializing: an <img src> set in this long-lived document would start a load it keeps.
|
|
23
|
+
*/
|
|
24
|
+
export declare function serializeForRaster(node: HTMLElement, options: SerializeOptions): string;
|
|
25
|
+
/** A snapshot's text color under forced colors when nothing gives it one: a page's own, with no theme. */
|
|
26
|
+
export declare const PLAIN_INK = "#000";
|
|
27
|
+
/**
|
|
28
|
+
* The SVG keeps its content's own size with no viewBox, and the draw scales it to pw × ph: WebKit ignores an
|
|
29
|
+
* SVG-level scale for positioned HTML in a foreignObject. data-raster-size draws nothing: it makes the text, and so
|
|
30
|
+
* the URL the browser caches by, differ per output size.
|
|
31
|
+
*
|
|
32
|
+
* A snapshot is a document of its own, which the stage's opt-out of forced colors does not reach: the foreignObject
|
|
33
|
+
* opts out, frame and plate alike, or Chromium repaints the picture in the theme's colors. Its default text color is
|
|
34
|
+
* the theme's too, so under forced colors the caller gives `ink` for the root, as an attribute any rule in the snapshot
|
|
35
|
+
* overrides. Not light-dark(), as the stage has: Firefox takes a picture's scheme from the theme.
|
|
36
|
+
*/
|
|
37
|
+
export declare function svgForRaster(xml: string, width: number, height: number, scale: number, ink?: string): {
|
|
38
|
+
svg: string;
|
|
39
|
+
pw: number;
|
|
40
|
+
ph: number;
|
|
41
|
+
};
|
|
42
|
+
/** Taken before the film runs: a film's own matchMedia can replace the global. */
|
|
43
|
+
export declare function watchForcedColors(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Under forced colors (a Windows contrast theme) a frame keeps the film's own colors: the document opts out while
|
|
46
|
+
* `read` runs, or getComputedStyle would give the theme's colors. `read` must stay synchronous.
|
|
47
|
+
*/
|
|
48
|
+
export declare function inOwnColors<T>(read: () => T): T;
|
|
49
|
+
export declare const forcedColorsActive: () => boolean;
|