@open-artifact/motion-stage 0.0.0-stage → 0.12.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 +71 -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,342 @@
|
|
|
1
|
+
import { forgetErrors, reportError } from "./console.js";
|
|
2
|
+
import { RealMessageChannel, filmTime, realNow, setFilmTime } from "./determinism.js";
|
|
3
|
+
import { film, filmAt, isThenable, playedDuration } from "./film.js";
|
|
4
|
+
import { say } from "./port.js";
|
|
5
|
+
import { anyRetouch, apply, isDue, setRecord, tell } from "./retouch/retouch.js";
|
|
6
|
+
import { stretchOf } from "./stretch.js";
|
|
7
|
+
import { builtStage, stageParts } from "./stage.js";
|
|
8
|
+
import { stageSize } from "./stage-size.js";
|
|
9
|
+
import { tellTexts } from "./texts.js";
|
|
10
|
+
import { syncVideos, videoSeeks } from "./video-sync.js";
|
|
11
|
+
const RENDER_LIMIT_MS = 10000;
|
|
12
|
+
const SETTLE_WAIT_MS = 1000;
|
|
13
|
+
/** A paused moment is drawn after this long when no animation frame came: a frame that is hidden or throttled gets none. */
|
|
14
|
+
const PAUSED_DRAW_MS = 100;
|
|
15
|
+
/** A render promise that never settled: the frame that waits for it fails for good. */
|
|
16
|
+
export class RenderStuck extends Error {
|
|
17
|
+
/** A tab in the background, not the film, may be why. */
|
|
18
|
+
inBackground;
|
|
19
|
+
constructor(message, inBackground) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.inBackground = inBackground;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export const renderState = {
|
|
25
|
+
ok: true,
|
|
26
|
+
error: null,
|
|
27
|
+
/** How many renders have been begun. */
|
|
28
|
+
count: 0,
|
|
29
|
+
warnedAsync: false,
|
|
30
|
+
/** A render of a moment drawn for a look alone (drawOwn) has given a promise in this load. */
|
|
31
|
+
gavePromise: false,
|
|
32
|
+
/** The played moment renderAt drew last. */
|
|
33
|
+
drawnAt: null,
|
|
34
|
+
};
|
|
35
|
+
const unsettled = [];
|
|
36
|
+
/** Every render promise goes through here: the stage may change until it settles. */
|
|
37
|
+
function track(promise) {
|
|
38
|
+
const entry = { q: Promise.resolve(), waited: false, done: false };
|
|
39
|
+
entry.q = promise.then(() => undefined, () => undefined).then(() => {
|
|
40
|
+
entry.done = true;
|
|
41
|
+
unsettled.splice(unsettled.indexOf(entry), 1);
|
|
42
|
+
});
|
|
43
|
+
unsettled.push(entry);
|
|
44
|
+
return promise;
|
|
45
|
+
}
|
|
46
|
+
export const unsettledNow = () => unsettled.slice();
|
|
47
|
+
/**
|
|
48
|
+
* null: nothing to wait for. Else settles when the pending renders no wait has given up on have settled, or after
|
|
49
|
+
* a second: a render that stays pending costs the waits one second in all, not one each.
|
|
50
|
+
*/
|
|
51
|
+
export function rendersSettle() {
|
|
52
|
+
const now = unsettled.filter((entry) => !entry.waited);
|
|
53
|
+
if (now.length === 0)
|
|
54
|
+
return null;
|
|
55
|
+
return Promise.race([
|
|
56
|
+
Promise.all(now.map((entry) => entry.q)),
|
|
57
|
+
new Promise((resolve) => setTimeout(() => {
|
|
58
|
+
for (const entry of now)
|
|
59
|
+
entry.waited = true;
|
|
60
|
+
resolve();
|
|
61
|
+
}, SETTLE_WAIT_MS)),
|
|
62
|
+
]);
|
|
63
|
+
}
|
|
64
|
+
/** One turn of the event loop, by a message: a tab in the background slows timers to a second. */
|
|
65
|
+
export function nextTask() {
|
|
66
|
+
return new Promise((resolve) => {
|
|
67
|
+
const timer = setTimeout(resolve, RealMessageChannel ? 100 : 0);
|
|
68
|
+
if (!RealMessageChannel)
|
|
69
|
+
return;
|
|
70
|
+
try {
|
|
71
|
+
const channel = new RealMessageChannel();
|
|
72
|
+
channel.port1.onmessage = () => {
|
|
73
|
+
channel.port1.close();
|
|
74
|
+
clearTimeout(timer);
|
|
75
|
+
resolve();
|
|
76
|
+
};
|
|
77
|
+
channel.port2.postMessage(0);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
// The timer does it.
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* One moment of the film's own time, drawn for a look at the stage alone. false: the film threw there. null: a
|
|
86
|
+
* render has given a promise in this load, so nothing more is drawn here: a render for another moment that finished
|
|
87
|
+
* late could draw that moment over the frame on show.
|
|
88
|
+
*/
|
|
89
|
+
export function drawOwn(T) {
|
|
90
|
+
const cut = film.cut;
|
|
91
|
+
const kit = film.kit;
|
|
92
|
+
if (!cut || !kit || renderState.gavePromise || renderState.warnedAsync)
|
|
93
|
+
return null;
|
|
94
|
+
setFilmTime(T);
|
|
95
|
+
try {
|
|
96
|
+
const drawn = cut.render(T, kit);
|
|
97
|
+
if (!isThenable(drawn))
|
|
98
|
+
return true;
|
|
99
|
+
// It may still paint when it settles, so it is waited for like any render's, and the draw that began it is done again (afterSample).
|
|
100
|
+
renderState.gavePromise = true;
|
|
101
|
+
void track(Promise.race([Promise.resolve(drawn), new Promise((resolve) => setTimeout(resolve, RENDER_LIMIT_MS))]));
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* A sample a draw began (drawOwn) that gave a promise paints its own moment when it settles, after that draw. So what
|
|
110
|
+
* relies on the draw waits for it and has its moment drawn again. before: gavePromise ahead of the draw. again:
|
|
111
|
+
* whether the redraw is still wanted then. null: no such sample; else the redraw's own promise, wrapped so it is
|
|
112
|
+
* handed over as it is, or null where it drew at once or was not wanted.
|
|
113
|
+
*/
|
|
114
|
+
export function afterSample(before, t, again) {
|
|
115
|
+
if (before || !renderState.gavePromise)
|
|
116
|
+
return null;
|
|
117
|
+
return Promise.resolve(rendersSettle()).then(() => ({ q: again && !again() ? null : renderAt(typeof t === 'function' ? t() : t) }));
|
|
118
|
+
}
|
|
119
|
+
/** A fault in laying what a person changed by hand costs their changes, not the film. */
|
|
120
|
+
export function unretouched() {
|
|
121
|
+
console.warn('What a person changed by hand about how things look (modules/retouched.json) could not be applied: the film is shown without it.');
|
|
122
|
+
try {
|
|
123
|
+
setRecord(null);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
// Nothing is laid.
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/** The stretch of the frame renderAt drew last; null: nothing is to be laid on it. */
|
|
130
|
+
let lastOn = null;
|
|
131
|
+
/** Tells, ahead of the frame itself, what is laid on the entries of its stretch not told yet. */
|
|
132
|
+
function tellDue(on, duration) {
|
|
133
|
+
const name = on.name;
|
|
134
|
+
if (name === null || !isDue(name, on.lo))
|
|
135
|
+
return;
|
|
136
|
+
try {
|
|
137
|
+
tell(name, on.lo, on.hi, (s) => drawOwn(on.base + Math.max(on.lo, Math.min(on.hi - 1 / 240, s))), (s) => s < duration && drawOwn(Math.max(0, s)));
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
unretouched();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/** Marks what is laid on the frame drawn last: at once, and again when its promise settles, since the browser may paint between. */
|
|
144
|
+
function lay(value) {
|
|
145
|
+
try {
|
|
146
|
+
if (lastOn)
|
|
147
|
+
apply(lastOn.name, lastOn.lo);
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
unretouched();
|
|
151
|
+
}
|
|
152
|
+
return value;
|
|
153
|
+
}
|
|
154
|
+
/** Draws played moment `t`. Gives back the render's promise, bounded, if it gave one. */
|
|
155
|
+
export function renderAt(t) {
|
|
156
|
+
const cut = film.cut;
|
|
157
|
+
const kit = film.kit;
|
|
158
|
+
if (!cut || !kit)
|
|
159
|
+
return null;
|
|
160
|
+
renderState.count++;
|
|
161
|
+
renderState.drawnAt = t;
|
|
162
|
+
const played = Math.max(0, Math.min(playedDuration(), Number(t) || 0));
|
|
163
|
+
film.played = played;
|
|
164
|
+
const at = filmAt(played);
|
|
165
|
+
film.rate = at.rate;
|
|
166
|
+
const on = anyRetouch() ? stretchOf(at.T) : null;
|
|
167
|
+
lastOn = on;
|
|
168
|
+
if (on)
|
|
169
|
+
tellDue(on, cut.duration);
|
|
170
|
+
setFilmTime(at.T);
|
|
171
|
+
const parts = builtStage();
|
|
172
|
+
parts.fxWatch.clear(stageSize.width, stageSize.height);
|
|
173
|
+
videoSeeks.clear();
|
|
174
|
+
const wasOk = renderState.ok;
|
|
175
|
+
renderState.ok = true;
|
|
176
|
+
let drawn;
|
|
177
|
+
try {
|
|
178
|
+
drawn = cut.render(at.T, kit);
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
renderState.ok = false;
|
|
182
|
+
renderState.error = error;
|
|
183
|
+
reportError('render', error);
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
if (on)
|
|
187
|
+
lay(undefined);
|
|
188
|
+
film.captions?.draw(played, parts.stage);
|
|
189
|
+
if (!isThenable(drawn)) {
|
|
190
|
+
// Recovered: a later failure is reported afresh.
|
|
191
|
+
if (!wasOk)
|
|
192
|
+
forgetErrors();
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
if (!renderState.warnedAsync) {
|
|
196
|
+
renderState.warnedAsync = true;
|
|
197
|
+
console.warn('CUT.render returned a Promise: live playback will not wait for it (only exported frames do). Do async work in init().');
|
|
198
|
+
}
|
|
199
|
+
const bounded = Promise.race([
|
|
200
|
+
Promise.resolve(drawn).then((value) => (on ? lay(value) : value)),
|
|
201
|
+
new Promise((_, fail) => setTimeout(() => {
|
|
202
|
+
const hidden = document.hidden === true;
|
|
203
|
+
fail(new RenderStuck('render(' + at.T.toFixed(3) + ') returned a Promise that did not settle within 10 s' + (hidden ? ' (this tab was in the background)' : ''), hidden));
|
|
204
|
+
}, RENDER_LIMIT_MS)),
|
|
205
|
+
]).then((value) => {
|
|
206
|
+
if (!wasOk)
|
|
207
|
+
forgetErrors();
|
|
208
|
+
// The caption of the frame drawn last: a later one may be up by now.
|
|
209
|
+
const now = stageParts();
|
|
210
|
+
if (now)
|
|
211
|
+
film.captions?.draw(film.played, now.stage);
|
|
212
|
+
return value;
|
|
213
|
+
});
|
|
214
|
+
return track(bounded);
|
|
215
|
+
}
|
|
216
|
+
export function syncClips(mode, quick = false) {
|
|
217
|
+
const cut = film.cut;
|
|
218
|
+
return syncVideos(stageParts()?.stage ?? null, filmTime(), mode, { fps: cut?.fps ?? 60, rate: film.rate, retimed: !!film.clock }, quick);
|
|
219
|
+
}
|
|
220
|
+
/** The frame pulls, layer readings and look questions take turns on the one stage. */
|
|
221
|
+
let turns = Promise.resolve();
|
|
222
|
+
export const busy = { framing: false };
|
|
223
|
+
/** The turn under way held the stage, drawing moments of its own. */
|
|
224
|
+
let held = false;
|
|
225
|
+
/** A turn draws moments of its own: live renders wait until {@link releaseStage}. */
|
|
226
|
+
export function holdStage() {
|
|
227
|
+
busy.framing = true;
|
|
228
|
+
held = true;
|
|
229
|
+
}
|
|
230
|
+
export function releaseStage() {
|
|
231
|
+
busy.framing = false;
|
|
232
|
+
}
|
|
233
|
+
export function takeTurn(job) {
|
|
234
|
+
turns = turns.then(async () => {
|
|
235
|
+
held = false;
|
|
236
|
+
// Nothing may throw out of a turn: every later one would be skipped.
|
|
237
|
+
try {
|
|
238
|
+
await job();
|
|
239
|
+
}
|
|
240
|
+
catch {
|
|
241
|
+
// The next frame draws it.
|
|
242
|
+
}
|
|
243
|
+
// A live render that came meanwhile skipped the words; the turn has drawn the moment on show again.
|
|
244
|
+
if (held && showsAsked())
|
|
245
|
+
tellTexts();
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
let pending = null;
|
|
249
|
+
let asked = null;
|
|
250
|
+
let queued = false;
|
|
251
|
+
/** The render count of the newest frame said to be presented. */
|
|
252
|
+
let presented = 0;
|
|
253
|
+
let shownT = null;
|
|
254
|
+
/**
|
|
255
|
+
* The stage shows, still, the moment the page last asked for, with nothing to draw over it: what its words are is
|
|
256
|
+
* worth telling. Not before the page's first render of a load, whose own first frame is at 0.
|
|
257
|
+
*/
|
|
258
|
+
export const showsAsked = () => !pending && !busy.framing && !!asked && !asked.playing && renderState.drawnAt === shownT;
|
|
259
|
+
/** The moment the page last asked to see, drawn yet or not. */
|
|
260
|
+
export const onShow = () => pending?.t ?? shownT ?? 0;
|
|
261
|
+
export const isPlaying = () => !!asked && asked.playing;
|
|
262
|
+
export const hasPending = () => pending !== null;
|
|
263
|
+
/** A moment a question drew again is the one on show. */
|
|
264
|
+
export const setShown = (t) => {
|
|
265
|
+
shownT = t;
|
|
266
|
+
};
|
|
267
|
+
export function askRender(next) {
|
|
268
|
+
pending = next;
|
|
269
|
+
if (!queued) {
|
|
270
|
+
queued = true;
|
|
271
|
+
requestAnimationFrame(flushRender);
|
|
272
|
+
}
|
|
273
|
+
if (!next.playing)
|
|
274
|
+
setTimeout(flushPaused, PAUSED_DRAW_MS);
|
|
275
|
+
}
|
|
276
|
+
/** Paused, a moment asked for is drawn without waiting on animation frames that may never come. */
|
|
277
|
+
function flushPaused() {
|
|
278
|
+
if (pending && !pending.playing)
|
|
279
|
+
flushRender();
|
|
280
|
+
}
|
|
281
|
+
/** Draws the moment on show again under the same ask, after a change the film reads, such as the render mode. */
|
|
282
|
+
export function redraw() {
|
|
283
|
+
const last = pending ?? asked;
|
|
284
|
+
if (last)
|
|
285
|
+
askRender(last);
|
|
286
|
+
}
|
|
287
|
+
function flushRender() {
|
|
288
|
+
queued = false;
|
|
289
|
+
if (!pending || !film.loaded)
|
|
290
|
+
return;
|
|
291
|
+
// A frame pull owns the stage until its snapshot is serialized; live renders wait for it.
|
|
292
|
+
if (busy.framing) {
|
|
293
|
+
queued = true;
|
|
294
|
+
requestAnimationFrame(flushRender);
|
|
295
|
+
if (!pending.playing)
|
|
296
|
+
setTimeout(flushPaused, PAUSED_DRAW_MS);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
const ask = pending;
|
|
300
|
+
pending = null;
|
|
301
|
+
const began = realNow();
|
|
302
|
+
shownT = ask.t;
|
|
303
|
+
const sampled = renderState.gavePromise;
|
|
304
|
+
const drawn = renderAt(ask.t);
|
|
305
|
+
const count = renderState.count;
|
|
306
|
+
asked = ask;
|
|
307
|
+
// Settled after a newer frame was shown: that one said 'presented', which answers this one's waiters too.
|
|
308
|
+
const done = (ok) => {
|
|
309
|
+
if (count < presented)
|
|
310
|
+
return;
|
|
311
|
+
presented = count;
|
|
312
|
+
const now = pending ?? asked ?? ask;
|
|
313
|
+
if (!busy.framing)
|
|
314
|
+
void syncClips(now.playing ? 'play' : 'hold');
|
|
315
|
+
say({ type: 'presented', seq: ask.seq, t: ask.t, ok, ms: Math.round((realNow() - began) * 10) / 10 });
|
|
316
|
+
if (!now.playing && !busy.framing)
|
|
317
|
+
tellTexts();
|
|
318
|
+
};
|
|
319
|
+
const failed = (error) => {
|
|
320
|
+
renderState.ok = false;
|
|
321
|
+
renderState.error = error;
|
|
322
|
+
reportError('render', error);
|
|
323
|
+
};
|
|
324
|
+
const finish = (q) => {
|
|
325
|
+
if (!q) {
|
|
326
|
+
done(renderState.ok);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
q.then(() => done(true), (error) => {
|
|
330
|
+
failed(error);
|
|
331
|
+
done(false);
|
|
332
|
+
});
|
|
333
|
+
};
|
|
334
|
+
// 'presented' follows a sample this draw began, and the moment on show drawn again, unless one is still to come or a pull holds the stage.
|
|
335
|
+
const again = afterSample(sampled, onShow, () => !pending && !busy.framing);
|
|
336
|
+
if (!again) {
|
|
337
|
+
finish(drawn);
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
drawn?.then(undefined, failed);
|
|
341
|
+
void again.then((a) => finish(a.q));
|
|
342
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AskedLook, LayerLook } from '../../protocol.ts';
|
|
2
|
+
import type { DrawMoment } from './retouch.ts';
|
|
3
|
+
/** As many classes as the record can hold: it is held to those it names, so fewer is no fault. */
|
|
4
|
+
export declare function classesFor(names: readonly string[]): string;
|
|
5
|
+
/**
|
|
6
|
+
* How the film itself draws the thing an id names in the stretch on show, read with no mark on the stage at second
|
|
7
|
+
* `at` and at the moments `tell` looks at. A value the film changes among them is null; so are the fill and corners of
|
|
8
|
+
* what never paints a box, and the ink and type of what is no line of words. null: nothing could be told of an entry
|
|
9
|
+
* of the scene, no such thing stands there, another node takes its place, or the film's render gives promises. The
|
|
10
|
+
* caller draws the frame again.
|
|
11
|
+
*/
|
|
12
|
+
export declare function ask(scene: string, id: string, lo: number, hi: number, at: number, draw: DrawMoment): AskedLook | null;
|
|
13
|
+
/**
|
|
14
|
+
* How the film itself draws an element now, whatever is laid on it, for the layers' rows. `cls`, `kin` and `at` are
|
|
15
|
+
* the caller's to set. null: nothing could be told of an entry of the scene.
|
|
16
|
+
*/
|
|
17
|
+
export declare function lookOn(el: Element, lo: number, hi: number, scene: string | null): LayerLook | null;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { RETOUCH_PROPERTIES } from '@open-artifact/motion-core';
|
|
2
|
+
import { inOwnColors } from "../snapshot/serialize.js";
|
|
3
|
+
import { PAINT, PAINT_KEYS, SHAPE, fills, isArtWords, isPart, isWords, paints, showsPaint } from "../layers/parts.js";
|
|
4
|
+
import { KEYS, OF_BOX, hues, seenLook } from "./look.js";
|
|
5
|
+
import { stageOf } from "./retouch.js";
|
|
6
|
+
import { fits, kinOf, like, peers, standsAt } from "./seat.js";
|
|
7
|
+
import { ID, blind, home, lapsedOn, marks, toldAt, unmark } from "./state.js";
|
|
8
|
+
import { TYPE_KEYS, familyHead, offerType, typeSeen } from "./type-style.js";
|
|
9
|
+
const LOOKS = 10;
|
|
10
|
+
const MOST_CLASS_CHARS = 200;
|
|
11
|
+
const colour = (value) => (typeof value === 'string' ? value : null);
|
|
12
|
+
const number = (value) => (typeof value === 'number' ? value : null);
|
|
13
|
+
const isProperty = (name) => RETOUCH_PROPERTIES.some((each) => each === name);
|
|
14
|
+
/** As many classes as the record can hold: it is held to those it names, so fewer is no fault. */
|
|
15
|
+
export function classesFor(names) {
|
|
16
|
+
return names.reduce((all, name) => (all.length + name.length < MOST_CLASS_CHARS ? (all ? all + ' ' : '') + name : all), '');
|
|
17
|
+
}
|
|
18
|
+
function mostRadius(el) {
|
|
19
|
+
const box = el instanceof HTMLElement ? [el.offsetWidth, el.offsetHeight] : [0, 0];
|
|
20
|
+
return Math.round(Math.min(box[0] ?? 0, box[1] ?? 0) / 2);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* How the film itself draws the thing an id names in the stretch on show, read with no mark on the stage at second
|
|
24
|
+
* `at` and at the moments `tell` looks at. A value the film changes among them is null; so are the fill and corners of
|
|
25
|
+
* what never paints a box, and the ink and type of what is no line of words. null: nothing could be told of an entry
|
|
26
|
+
* of the scene, no such thing stands there, another node takes its place, or the film's render gives promises. The
|
|
27
|
+
* caller draws the frame again.
|
|
28
|
+
*/
|
|
29
|
+
export function ask(scene, id, lo, hi, at, draw) {
|
|
30
|
+
const stage = stageOf();
|
|
31
|
+
const m = ID.exec(id);
|
|
32
|
+
if (!stage || !m || m[1] !== scene || blind(scene, lo) || !getComputedStyle(stage).display)
|
|
33
|
+
return null;
|
|
34
|
+
const path = m[2].split('.').map(Number);
|
|
35
|
+
const tag = m[3];
|
|
36
|
+
const here = () => {
|
|
37
|
+
const x = standsAt(stage, path);
|
|
38
|
+
return x && fits(x, tag, []) ? x : null;
|
|
39
|
+
};
|
|
40
|
+
const shown = here();
|
|
41
|
+
const mine = shown ? marks(shown) : undefined;
|
|
42
|
+
const lapsed = shown ? lapsedOn(shown).filter(isProperty) : [];
|
|
43
|
+
unmark();
|
|
44
|
+
const drawn = draw(at);
|
|
45
|
+
const el = drawn !== false && drawn !== null ? here() : null;
|
|
46
|
+
if (!el)
|
|
47
|
+
return null;
|
|
48
|
+
const memo = {};
|
|
49
|
+
const cs = getComputedStyle(el);
|
|
50
|
+
const read = inOwnColors(() => ({ all: like(stage, peers(stage, memo, tag), [], memo), now: seenLook(cs, el).values, first: hues(cs, el), boxed: paints(cs, el), worded: isWords(el) }));
|
|
51
|
+
const now = read.now;
|
|
52
|
+
let boxed = read.boxed;
|
|
53
|
+
let cls = Array.from(el.classList);
|
|
54
|
+
const most = mostRadius(el);
|
|
55
|
+
const family = familyHead(cs);
|
|
56
|
+
const type = typeSeen(cs);
|
|
57
|
+
offerType(cs, el, type);
|
|
58
|
+
const changed = new Set();
|
|
59
|
+
if (!read.worded) {
|
|
60
|
+
now.ink = null;
|
|
61
|
+
for (const key of TYPE_KEYS)
|
|
62
|
+
type[key] = null;
|
|
63
|
+
}
|
|
64
|
+
for (let i = 0; i < LOOKS; i++) {
|
|
65
|
+
const s = draw(lo + ((hi - lo) * i) / (LOOKS - 1));
|
|
66
|
+
if (s === null)
|
|
67
|
+
return null;
|
|
68
|
+
const x = s !== false ? here() : null;
|
|
69
|
+
if (x && x !== el && el.isConnected)
|
|
70
|
+
return null;
|
|
71
|
+
const xs = x ? getComputedStyle(x) : null;
|
|
72
|
+
if (!x || !xs || xs.display === 'none')
|
|
73
|
+
continue;
|
|
74
|
+
const h = inOwnColors(() => {
|
|
75
|
+
boxed = boxed || paints(xs, x);
|
|
76
|
+
return hues(xs, x);
|
|
77
|
+
});
|
|
78
|
+
cls = cls.filter((name) => x.classList.contains(name));
|
|
79
|
+
for (const key of KEYS)
|
|
80
|
+
if (h[key] !== read.first[key])
|
|
81
|
+
changed.add(key);
|
|
82
|
+
}
|
|
83
|
+
if (!boxed)
|
|
84
|
+
for (const key of OF_BOX)
|
|
85
|
+
changed.add(key);
|
|
86
|
+
for (const key of changed)
|
|
87
|
+
now[key] = null;
|
|
88
|
+
for (const key of TYPE_KEYS)
|
|
89
|
+
if (changed.has(key))
|
|
90
|
+
type[key] = null;
|
|
91
|
+
const kept = classesFor(cls);
|
|
92
|
+
return {
|
|
93
|
+
...type,
|
|
94
|
+
cls: kept,
|
|
95
|
+
kin: kinOf(stage, read.all, el, kept.split(' ').filter(Boolean), memo),
|
|
96
|
+
at: at,
|
|
97
|
+
fill: colour(now.fill),
|
|
98
|
+
ink: colour(now.ink),
|
|
99
|
+
radius: number(now.radius),
|
|
100
|
+
most,
|
|
101
|
+
size: number(now.size),
|
|
102
|
+
hidden: now.hidden === 0 ? 0 : null,
|
|
103
|
+
entry: mine ? mine.id : null,
|
|
104
|
+
home: !!mine && home(mine, lo, hi),
|
|
105
|
+
lapsed,
|
|
106
|
+
family,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* How the film itself draws an element now, whatever is laid on it, for the layers' rows. `cls`, `kin` and `at` are
|
|
111
|
+
* the caller's to set. null: nothing could be told of an entry of the scene.
|
|
112
|
+
*/
|
|
113
|
+
export function lookOn(el, lo, hi, scene) {
|
|
114
|
+
if (scene !== null && blind(scene, lo))
|
|
115
|
+
return null;
|
|
116
|
+
const cs = getComputedStyle(el);
|
|
117
|
+
const now = seenLook(cs, el).values;
|
|
118
|
+
const e = marks(el);
|
|
119
|
+
const lapsed = lapsedOn(el).filter(isProperty);
|
|
120
|
+
// No colour is offered where another would not show now: on a clear paint, or on a stroke that has no width.
|
|
121
|
+
for (const key of PAINT_KEYS) {
|
|
122
|
+
const property = PAINT[key];
|
|
123
|
+
if (!showsPaint(cs.getPropertyValue(property), cs.getPropertyValue(property + '-opacity')) || (property === 'stroke' && !(parseFloat(cs.strokeWidth) > 0)))
|
|
124
|
+
now[key] = null;
|
|
125
|
+
}
|
|
126
|
+
const told = e ? toldAt(e, lo) : null;
|
|
127
|
+
if (e)
|
|
128
|
+
for (const key of KEYS) {
|
|
129
|
+
const pair = e.pairs[key];
|
|
130
|
+
if (pair && !lapsed.some((name) => name === key))
|
|
131
|
+
now[key] = told?.verdict.own[key] ?? pair.was;
|
|
132
|
+
}
|
|
133
|
+
const loose = !!(e && (e.print || isArtWords(el)) && told && !told.seat.sure && told.seat.worded);
|
|
134
|
+
// A hide that the film's own style attribute has ended: the same pair saved again would change nothing.
|
|
135
|
+
if (lapsed.includes('hidden') && !loose)
|
|
136
|
+
now.hidden = null;
|
|
137
|
+
return {
|
|
138
|
+
cls: el.getAttribute('class') ?? '',
|
|
139
|
+
kin: null,
|
|
140
|
+
at: 0,
|
|
141
|
+
fill: colour(now.fill),
|
|
142
|
+
ink: colour(now.ink),
|
|
143
|
+
radius: number(now.radius),
|
|
144
|
+
most: mostRadius(el),
|
|
145
|
+
size: number(now.size),
|
|
146
|
+
hidden: now.hidden === 0 ? 0 : null,
|
|
147
|
+
svgfill: colour(now.svgfill),
|
|
148
|
+
svgstroke: colour(now.svgstroke),
|
|
149
|
+
// The shape's fill shows even where no colour is offered for it, so the page calls the stroke's row Stroke, not Color.
|
|
150
|
+
...(isPart(el) && SHAPE.test(el.tagName) && fills(cs, el) ? { filled: true } : {}),
|
|
151
|
+
entry: e ? e.id : null,
|
|
152
|
+
loose,
|
|
153
|
+
home: !!e && home(e, lo, hi),
|
|
154
|
+
lapsed,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { Corner, Key, Value } from './look.ts';
|
|
2
|
+
export interface Pair {
|
|
3
|
+
was: Value;
|
|
4
|
+
v: Value;
|
|
5
|
+
}
|
|
6
|
+
/** What judging an entry's thing found: whether each of its pairs holds, and the film's own value each is held to. */
|
|
7
|
+
export interface Verdict {
|
|
8
|
+
round: Corner[];
|
|
9
|
+
/** The thing is an svg text, whose ink is laid as its fill. */
|
|
10
|
+
art: boolean;
|
|
11
|
+
own: Partial<Record<Key, Value>>;
|
|
12
|
+
holds: Partial<Record<Key, boolean>>;
|
|
13
|
+
}
|
|
14
|
+
/** Where an entry's thing was found. */
|
|
15
|
+
export interface Seat {
|
|
16
|
+
el: Element;
|
|
17
|
+
/** Found by its print, not its turn. */
|
|
18
|
+
sure: boolean;
|
|
19
|
+
/** A hidden g found by its parts once its print was on nothing; `had`, its print then, finds it again. */
|
|
20
|
+
held?: boolean;
|
|
21
|
+
had?: string | null;
|
|
22
|
+
worded: boolean;
|
|
23
|
+
/** Its turn among like things, of how many; n -1: found by `far`, the node alone counts. */
|
|
24
|
+
k: number;
|
|
25
|
+
n: number;
|
|
26
|
+
/** Its print now, if nothing else of its tag has it. */
|
|
27
|
+
print: string | null;
|
|
28
|
+
/** The words it had at the entry's own moment; a later look counts only while it has them. */
|
|
29
|
+
says?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface Told {
|
|
32
|
+
verdict: Verdict;
|
|
33
|
+
seat: Seat;
|
|
34
|
+
/** What is laid on the element, as its data-film-laid says it. */
|
|
35
|
+
laid: string;
|
|
36
|
+
lapsed: string;
|
|
37
|
+
}
|
|
38
|
+
/** One entry of the record as this stage lays it. */
|
|
39
|
+
export interface Entry {
|
|
40
|
+
id: string;
|
|
41
|
+
/** Its own moment, in its stretch's own seconds. */
|
|
42
|
+
at: number;
|
|
43
|
+
/**
|
|
44
|
+
* The verdicts by the start of the stretch they were reached in. Absent: not told yet. null: nothing could be told
|
|
45
|
+
* in this load. false: its thing was not there.
|
|
46
|
+
*/
|
|
47
|
+
told: Map<number, Told | null | false>;
|
|
48
|
+
scene: string;
|
|
49
|
+
tag: string;
|
|
50
|
+
cls: string[];
|
|
51
|
+
kin: string;
|
|
52
|
+
k: number;
|
|
53
|
+
n: number;
|
|
54
|
+
print: string | null;
|
|
55
|
+
/** The hashes a hide on a g inside an svg is also found by (`parts.ts`). */
|
|
56
|
+
parts: string[] | null;
|
|
57
|
+
pairs: Partial<Record<Key, Pair>>;
|
|
58
|
+
}
|
|
59
|
+
/** One like thing on the stage: an element of a tag, its classes as they were read, and its print once made. */
|
|
60
|
+
export interface Peer {
|
|
61
|
+
el: Element;
|
|
62
|
+
cls: string[];
|
|
63
|
+
print: string | null;
|
|
64
|
+
}
|
|
65
|
+
/** What is known of the stage as drawn at one moment, made as it is needed. */
|
|
66
|
+
export interface ReadMemo {
|
|
67
|
+
all?: Element[];
|
|
68
|
+
art?: Element[];
|
|
69
|
+
tags?: Map<string, Peer[]>;
|
|
70
|
+
turns?: Map<Element, string>;
|
|
71
|
+
words?: Map<Element, string>;
|
|
72
|
+
drawn?: Map<Element, string>;
|
|
73
|
+
/** For `parts.ts`: the paint each holder lends, each piece's hash, and the stage's shapes tallied. */
|
|
74
|
+
lent?: Map<Element, string>;
|
|
75
|
+
written?: Map<Element, string>;
|
|
76
|
+
pieces?: Map<string, number>;
|
|
77
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Entry, Verdict } from './entry.ts';
|
|
2
|
+
/** Each scene's box as it came up, with the classes in it, so a class counts as the element's own alike in every runner. */
|
|
3
|
+
export declare const boxes: Array<{
|
|
4
|
+
node: HTMLElement;
|
|
5
|
+
names: Set<string>;
|
|
6
|
+
}>;
|
|
7
|
+
/**
|
|
8
|
+
* Whether a style attribute's text, read anew, lists the declarations el.style has, in whatever order. Not once a
|
|
9
|
+
* longhand is set over a shorthand holding a var() and the film has written to el.style: taken off, it could not be
|
|
10
|
+
* put back.
|
|
11
|
+
*/
|
|
12
|
+
export declare function intact(el: Element, text: string): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Reads how the film would draw the element but for what is its own: its style attribute, its id, each class nothing
|
|
15
|
+
* else has, and on an svg text its paint and font attributes. `style` goes in place of its style attribute; null is
|
|
16
|
+
* given back where that cannot be done.
|
|
17
|
+
*/
|
|
18
|
+
export declare function bare<T>(stage: HTMLElement, el: Element, style: string | null, read: () => T): T | null;
|
|
19
|
+
/**
|
|
20
|
+
* Judges the pairs of entry `e` on `el`. `so`: the verdict so far; a later look only turns a yes into a no. `must`:
|
|
21
|
+
* at the entry's own moment; at others an element that is not displayed is passed over.
|
|
22
|
+
*/
|
|
23
|
+
export declare function judge(stage: HTMLElement, el: Element, e: Entry, so: Verdict | null, must: boolean): Verdict | null;
|
|
24
|
+
/** What of an entry holds (`good`) or has lapsed, as the marks say it. The film's own choice of round corners takes the new radius; if none is round, all four do. */
|
|
25
|
+
export declare function marksOf(e: Entry, verdict: Verdict, good: boolean): string;
|