@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,97 @@
|
|
|
1
|
+
import { MAX_RETOUCHED_LAYERS, RETOUCH_PROPERTIES, TEXT_ALIGNS, isRetouchParts, parseRetouchLayer } from '@open-artifact/motion-core';
|
|
2
|
+
const isFields = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
3
|
+
const isNumber = (value) => typeof value === 'number' && Number.isFinite(value);
|
|
4
|
+
const isString = (value) => typeof value === 'string';
|
|
5
|
+
const isBoolean = (value) => typeof value === 'boolean';
|
|
6
|
+
const isNullable = (value, is) => value === null || is(value);
|
|
7
|
+
const isListOf = (value, is) => Array.isArray(value) && value.every(is);
|
|
8
|
+
const isNumberPair = (value) => Array.isArray(value) && value.length === 2 && value.every(isNumber);
|
|
9
|
+
const isBox = (value) => Array.isArray(value) && value.length === 4 && value.every(isNumber);
|
|
10
|
+
const COLOR = /^#[0-9a-f]{6}([0-9a-f]{2})?$/;
|
|
11
|
+
const isColor = (value) => isString(value) && COLOR.test(value);
|
|
12
|
+
const isOneOf = (all) => (value) => isString(value) && all.includes(value);
|
|
13
|
+
const LAYER_KINDS = ['ground', 'group', 'shape', 'image', 'text'];
|
|
14
|
+
const LAYER_DRAWN = ['', 'graphic', 'drawing', 'group', 'line', 'path', 'polygon'];
|
|
15
|
+
const LAYER_EFFECTS = ['fade', 'grow', 'left', 'right', 'top', 'bottom'];
|
|
16
|
+
const PROPERTIES = RETOUCH_PROPERTIES;
|
|
17
|
+
const ALIGNS = TEXT_ALIGNS;
|
|
18
|
+
function isMotion(value) {
|
|
19
|
+
return isFields(value) && isNullable(value['how'], (how) => isListOf(how, isOneOf(LAYER_EFFECTS))) && isNumber(value['from']) && isNumber(value['to']);
|
|
20
|
+
}
|
|
21
|
+
function isLayerLook(value) {
|
|
22
|
+
return (isFields(value) &&
|
|
23
|
+
isString(value['cls']) &&
|
|
24
|
+
isNullable(value['kin'], isString) &&
|
|
25
|
+
(value['parts'] === undefined || isRetouchParts(value['parts'])) &&
|
|
26
|
+
isNumber(value['at']) &&
|
|
27
|
+
['fill', 'ink', 'svgfill', 'svgstroke'].every((key) => isNullable(value[key], isColor)) &&
|
|
28
|
+
isNullable(value['radius'], isNumber) &&
|
|
29
|
+
isNumber(value['most']) &&
|
|
30
|
+
isNullable(value['size'], isNumber) &&
|
|
31
|
+
(value['hidden'] === 0 || value['hidden'] === null) &&
|
|
32
|
+
(value['filled'] === undefined || value['filled'] === true) &&
|
|
33
|
+
isNullable(value['entry'], isString) &&
|
|
34
|
+
isBoolean(value['loose']) &&
|
|
35
|
+
isBoolean(value['home']) &&
|
|
36
|
+
isListOf(value['lapsed'], isOneOf(PROPERTIES)));
|
|
37
|
+
}
|
|
38
|
+
export function isLayerRow(value) {
|
|
39
|
+
return (isFields(value) &&
|
|
40
|
+
isString(value['id']) &&
|
|
41
|
+
isOneOf(LAYER_KINDS)(value['kind']) &&
|
|
42
|
+
isBoolean(value['round']) &&
|
|
43
|
+
isString(value['name']) &&
|
|
44
|
+
(value['hidden'] === 'held' || value['hidden'] === 'own' || value['hidden'] === false) &&
|
|
45
|
+
isNullable(value['under'], isString) &&
|
|
46
|
+
isBoolean(value['own']) &&
|
|
47
|
+
isNumber(value['many']) &&
|
|
48
|
+
isListOf(value['texts'], isString) &&
|
|
49
|
+
isListOf(value['spans'], isNumberPair) &&
|
|
50
|
+
isNumber(value['at']) &&
|
|
51
|
+
isMotion(value['enter']) &&
|
|
52
|
+
isMotion(value['leave']) &&
|
|
53
|
+
isNullable(value['box'], isBox) &&
|
|
54
|
+
isNullable(value['wordsBox'], isBox) &&
|
|
55
|
+
isNullable(value['look'], isLayerLook) &&
|
|
56
|
+
isListOf(value['kids'], isLayerRow) &&
|
|
57
|
+
isNullable(value['sole'], isLayerRow) &&
|
|
58
|
+
isBoolean(value['whole']) &&
|
|
59
|
+
isOneOf(LAYER_DRAWN)(value['drawn']) &&
|
|
60
|
+
isBoolean(value['full']));
|
|
61
|
+
}
|
|
62
|
+
export function isLayersReport(value) {
|
|
63
|
+
return (isFields(value) &&
|
|
64
|
+
isNumber(value['seq']) &&
|
|
65
|
+
isNumber(value['from']) &&
|
|
66
|
+
isNumber(value['to']) &&
|
|
67
|
+
isNumber(value['at']) &&
|
|
68
|
+
isListOf(value['lost'], isString) &&
|
|
69
|
+
isListOf(value['underHide'], isString) &&
|
|
70
|
+
isNullable(value['rows'], (rows) => isListOf(rows, isLayerRow)));
|
|
71
|
+
}
|
|
72
|
+
export function isAskedLook(value) {
|
|
73
|
+
return (isFields(value) &&
|
|
74
|
+
isNullable(value['weight'], isNumber) &&
|
|
75
|
+
(value['italic'] === 0 || value['italic'] === 1 || value['italic'] === null) &&
|
|
76
|
+
isNullable(value['px'], isNumber) &&
|
|
77
|
+
(value['leading'] === 'normal' || isNullable(value['leading'], isNumber)) &&
|
|
78
|
+
isNullable(value['tracking'], isNumber) &&
|
|
79
|
+
isNullable(value['align'], isOneOf(ALIGNS)) &&
|
|
80
|
+
isString(value['cls']) &&
|
|
81
|
+
isNullable(value['kin'], isString) &&
|
|
82
|
+
isNumber(value['at']) &&
|
|
83
|
+
isNullable(value['fill'], isColor) &&
|
|
84
|
+
isNullable(value['ink'], isColor) &&
|
|
85
|
+
isNullable(value['radius'], isNumber) &&
|
|
86
|
+
isNumber(value['most']) &&
|
|
87
|
+
isNullable(value['size'], isNumber) &&
|
|
88
|
+
(value['hidden'] === 0 || value['hidden'] === null) &&
|
|
89
|
+
isNullable(value['entry'], isString) &&
|
|
90
|
+
isBoolean(value['home']) &&
|
|
91
|
+
isListOf(value['lapsed'], isOneOf(PROPERTIES)) &&
|
|
92
|
+
isString(value['family']));
|
|
93
|
+
}
|
|
94
|
+
/** A record as `parseRetouchedRecord` gives it: each entry one the player would keep. The frame parses it again. */
|
|
95
|
+
export function isRetouchedRecord(value) {
|
|
96
|
+
return isFields(value) && Array.isArray(value['layers']) && value['layers'].length <= MAX_RETOUCHED_LAYERS && value['layers'].every((layer) => parseRetouchLayer(layer) !== null);
|
|
97
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { FilmSeconds, PlaySeconds, RetouchProperty, TextAlign } from '@open-artifact/motion-core';
|
|
2
|
+
export type LayerKind = 'ground' | 'group' | 'shape' | 'image' | 'text';
|
|
3
|
+
/** What the list calls a drawing that has no name of its own; '' where its kind says enough. */
|
|
4
|
+
export type LayerDrawn = '' | 'graphic' | 'drawing' | 'group' | 'line' | 'path' | 'polygon';
|
|
5
|
+
export type LayerEffect = 'fade' | 'grow' | 'left' | 'right' | 'top' | 'bottom';
|
|
6
|
+
/**
|
|
7
|
+
* How a layer comes on or goes, as far as its opacity and its box tell: `how` is null where they cannot (better no
|
|
8
|
+
* word than a wrong one), and empty where it just appears.
|
|
9
|
+
*/
|
|
10
|
+
export interface LayerMotion {
|
|
11
|
+
how: LayerEffect[] | null;
|
|
12
|
+
from: PlaySeconds;
|
|
13
|
+
to: PlaySeconds;
|
|
14
|
+
}
|
|
15
|
+
/** x, y, width and height in film pixels. */
|
|
16
|
+
export type LayerBox = [number, number, number, number];
|
|
17
|
+
/**
|
|
18
|
+
* How the film itself draws a layer at the moment on show, for the controls that change it by hand. A value is null
|
|
19
|
+
* where nothing a person sets would show, or where the film changes it in the course of the stretch.
|
|
20
|
+
*/
|
|
21
|
+
export interface LayerLook {
|
|
22
|
+
/** The classes it has at every moment read, as many as the record can hold. */
|
|
23
|
+
cls: string;
|
|
24
|
+
/** Which it is of how many like elements, and maybe a print of its words (a `RetouchLayer` kin); null: none. */
|
|
25
|
+
kin: string | null;
|
|
26
|
+
/** For a g inside an svg that a hide would hold on: what the hide is also found by (a `RetouchLayer` parts). */
|
|
27
|
+
parts?: string;
|
|
28
|
+
/** The moment of the stretch on show, in the stretch's own seconds (a scene's from its start). */
|
|
29
|
+
at: FilmSeconds;
|
|
30
|
+
fill: string | null;
|
|
31
|
+
ink: string | null;
|
|
32
|
+
radius: number | null;
|
|
33
|
+
/** The largest radius that would still show: half its shorter side. */
|
|
34
|
+
most: number;
|
|
35
|
+
size: number | null;
|
|
36
|
+
hidden: 0 | null;
|
|
37
|
+
svgfill: string | null;
|
|
38
|
+
svgstroke: string | null;
|
|
39
|
+
/** A shape whose fill shows even where no colour is offered for it (a gradient): its stroke is a Stroke, not a Color. */
|
|
40
|
+
filled?: true;
|
|
41
|
+
/** The id of the entry of the record that marks it. */
|
|
42
|
+
entry: string | null;
|
|
43
|
+
/** That entry was found by its turn, not its print, on a thing with words: it may be another thing. */
|
|
44
|
+
loose: boolean;
|
|
45
|
+
/** The entry's own moment lies in the stretch on show. */
|
|
46
|
+
home: boolean;
|
|
47
|
+
/** What of the entry no longer counts here: the film's own style now says otherwise. */
|
|
48
|
+
lapsed: RetouchProperty[];
|
|
49
|
+
}
|
|
50
|
+
export interface LayerRow {
|
|
51
|
+
/** `<stretch>:<place>/<tag>`, with `+` for a node made anew at the same place and `*` for a pack of alike things. */
|
|
52
|
+
id: string;
|
|
53
|
+
kind: LayerKind;
|
|
54
|
+
/** A shape that is round (a dot, a circle). */
|
|
55
|
+
round: boolean;
|
|
56
|
+
name: string;
|
|
57
|
+
/** held: something that holds it was hidden by hand; own: it was. */
|
|
58
|
+
hidden: 'held' | 'own' | false;
|
|
59
|
+
/** The id of what was hidden, where `hidden` is 'held'. */
|
|
60
|
+
under: string | null;
|
|
61
|
+
own: boolean;
|
|
62
|
+
/** How many alike things a pack holds; 0: no pack. */
|
|
63
|
+
many: number;
|
|
64
|
+
texts: string[];
|
|
65
|
+
/** When it is on in the stretch read, as played. Six at most. */
|
|
66
|
+
spans: Array<[PlaySeconds, PlaySeconds]>;
|
|
67
|
+
/** Where to look at it: the first moment it is as solid as it gets and at rest. */
|
|
68
|
+
at: PlaySeconds;
|
|
69
|
+
enter: LayerMotion;
|
|
70
|
+
leave: LayerMotion;
|
|
71
|
+
/** Its box at the moment on show; null: not on the picture then. */
|
|
72
|
+
box: LayerBox | null;
|
|
73
|
+
/** The box round its words alone, for a line of words. */
|
|
74
|
+
wordsBox: LayerBox | null;
|
|
75
|
+
look: LayerLook | null;
|
|
76
|
+
kids: LayerRow[];
|
|
77
|
+
/** The one shape that is all a drawing's row holds: the row's colours are that shape's. */
|
|
78
|
+
sole: LayerRow | null;
|
|
79
|
+
/** Everything the svg draws is listed under the row, so a colour set on the row leaves nothing behind. */
|
|
80
|
+
whole: boolean;
|
|
81
|
+
drawn: LayerDrawn;
|
|
82
|
+
/** As large as the picture, but no Background: only the list picks it. */
|
|
83
|
+
full: boolean;
|
|
84
|
+
}
|
|
85
|
+
export interface LayersReport {
|
|
86
|
+
seq: number;
|
|
87
|
+
from: PlaySeconds;
|
|
88
|
+
to: PlaySeconds;
|
|
89
|
+
/** The moment on show, which the boxes and looks are of. */
|
|
90
|
+
at: PlaySeconds;
|
|
91
|
+
/** The record's entries for the stretch on show that find nothing, or another entry's thing. */
|
|
92
|
+
lost: string[];
|
|
93
|
+
/** Of those, the hides whose thing another entry's hide hides all the same. */
|
|
94
|
+
underHide: string[];
|
|
95
|
+
/** null: no reading (the film is not loaded, a newer question came, or the film's render gives promises). */
|
|
96
|
+
rows: LayerRow[] | null;
|
|
97
|
+
}
|
|
98
|
+
/** How the film itself sets one line of words, as the text style controls read it. null: nothing a person sets would show. */
|
|
99
|
+
export interface TypeLook {
|
|
100
|
+
weight: number | null;
|
|
101
|
+
italic: 0 | 1 | null;
|
|
102
|
+
px: number | null;
|
|
103
|
+
leading: number | 'normal' | null;
|
|
104
|
+
tracking: number | null;
|
|
105
|
+
align: TextAlign | null;
|
|
106
|
+
}
|
|
107
|
+
/** How the film itself draws the thing an id names, read with no change by hand on the stage. */
|
|
108
|
+
export interface AskedLook extends TypeLook {
|
|
109
|
+
cls: string;
|
|
110
|
+
kin: string | null;
|
|
111
|
+
at: FilmSeconds;
|
|
112
|
+
fill: string | null;
|
|
113
|
+
ink: string | null;
|
|
114
|
+
radius: number | null;
|
|
115
|
+
most: number;
|
|
116
|
+
size: number | null;
|
|
117
|
+
hidden: 0 | null;
|
|
118
|
+
entry: string | null;
|
|
119
|
+
home: boolean;
|
|
120
|
+
lapsed: RetouchProperty[];
|
|
121
|
+
/** The head of its font stack; '': none that is a plain name. */
|
|
122
|
+
family: string;
|
|
123
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import type { FilmSeconds, PlaySeconds, RetouchedRecord, ScoreData, ScoreEvent } from '@open-artifact/motion-core';
|
|
2
|
+
import type { AskedLook, LayersReport } from './layers.ts';
|
|
3
|
+
export type * from './layers.ts';
|
|
4
|
+
/** Bumped when a message changes shape; the host refuses a stage that says another. */
|
|
5
|
+
export declare const STAGE_PROTOCOL_VERSION = 2;
|
|
6
|
+
/**
|
|
7
|
+
* The one message the host posts to the frame's window, on the frame's load, carrying the port every later message
|
|
8
|
+
* goes through. The frame takes the first one that comes from its parent and ignores the rest.
|
|
9
|
+
*/
|
|
10
|
+
export declare const STAGE_CONNECT = "video-stage:connect";
|
|
11
|
+
export interface StageConnect {
|
|
12
|
+
type: typeof STAGE_CONNECT;
|
|
13
|
+
version: number;
|
|
14
|
+
}
|
|
15
|
+
export type StageModuleKind = 'js' | 'css' | 'html' | 'json' | 'text';
|
|
16
|
+
export interface StageModule {
|
|
17
|
+
name: string;
|
|
18
|
+
kind: StageModuleKind;
|
|
19
|
+
text: string;
|
|
20
|
+
}
|
|
21
|
+
/** Pictures and fonts arrive as bytes and become data: URLs, which a snapshot can see; a clip arrives as its URL and streams. */
|
|
22
|
+
export interface StageAsset {
|
|
23
|
+
name: string;
|
|
24
|
+
mime: string;
|
|
25
|
+
w: number;
|
|
26
|
+
h: number;
|
|
27
|
+
bytes?: ArrayBuffer;
|
|
28
|
+
url?: string;
|
|
29
|
+
}
|
|
30
|
+
export type StackName = 'sans' | 'serif' | 'mono' | 'display';
|
|
31
|
+
/** A face from the page (shipped with the type, or fetched): woff2 as a data: URL. */
|
|
32
|
+
export interface StageFace {
|
|
33
|
+
family: string;
|
|
34
|
+
url: string;
|
|
35
|
+
weight: string;
|
|
36
|
+
style: string;
|
|
37
|
+
range?: string;
|
|
38
|
+
/** ascent and descent overrides, in percent. */
|
|
39
|
+
box?: [number, number];
|
|
40
|
+
/** One or two characters the face draws, to load a face whose unicode-range leaves out a space. */
|
|
41
|
+
sample?: string;
|
|
42
|
+
}
|
|
43
|
+
export interface StageFaces {
|
|
44
|
+
fonts: StageFace[];
|
|
45
|
+
/** The family that heads each stack, from the film's scenes.json fonts or a person's choice. */
|
|
46
|
+
slots: Partial<Record<StackName, string>>;
|
|
47
|
+
}
|
|
48
|
+
export interface NarrationLimits {
|
|
49
|
+
maxLines: number;
|
|
50
|
+
maxLineSeconds: number;
|
|
51
|
+
}
|
|
52
|
+
export interface StageFilm {
|
|
53
|
+
script: string;
|
|
54
|
+
modules: StageModule[];
|
|
55
|
+
assets: StageAsset[];
|
|
56
|
+
faces: StageFaces | null;
|
|
57
|
+
/** null: this viewer gets no narration, so narration.js is not read. */
|
|
58
|
+
narration: NarrationLimits | null;
|
|
59
|
+
/** How long a snapshot waits for words clipped at its first draw (Firefox). */
|
|
60
|
+
clippedTextWaitMs: number;
|
|
61
|
+
mode: RenderMode;
|
|
62
|
+
}
|
|
63
|
+
/** rough: a scene that says it is rough draws as a grey sketch. final: every written scene draws as it is. */
|
|
64
|
+
export type RenderMode = 'rough' | 'final';
|
|
65
|
+
export interface Chapter<Time extends number> {
|
|
66
|
+
t: Time;
|
|
67
|
+
label: string;
|
|
68
|
+
}
|
|
69
|
+
/** A part of the film (a scene, or a stretch between chapters) on both clocks. */
|
|
70
|
+
export interface FilmPart {
|
|
71
|
+
key: string | null;
|
|
72
|
+
/** The person's name for it, or the film's. */
|
|
73
|
+
label: string;
|
|
74
|
+
/** The film's own name for it. */
|
|
75
|
+
own: string;
|
|
76
|
+
a0: FilmSeconds;
|
|
77
|
+
nat: number;
|
|
78
|
+
p0: PlaySeconds;
|
|
79
|
+
dur: number;
|
|
80
|
+
}
|
|
81
|
+
export type SceneState = 'todo' | 'failed' | 'rough' | 'final';
|
|
82
|
+
export interface SceneReport {
|
|
83
|
+
id: string;
|
|
84
|
+
state: SceneState;
|
|
85
|
+
}
|
|
86
|
+
export interface StageMeta {
|
|
87
|
+
width: number;
|
|
88
|
+
height: number;
|
|
89
|
+
fps: 24 | 30 | 60;
|
|
90
|
+
duration: PlaySeconds;
|
|
91
|
+
filmDuration: FilmSeconds;
|
|
92
|
+
chapters: Chapter<PlaySeconds>[];
|
|
93
|
+
/** null: not a film made of scenes. */
|
|
94
|
+
scenes: SceneReport[] | null;
|
|
95
|
+
/** The stage's computed background colour and image. */
|
|
96
|
+
background: [string, string];
|
|
97
|
+
parts: FilmPart[];
|
|
98
|
+
}
|
|
99
|
+
export interface PlayedScoreEvent extends Omit<ScoreEvent, 't'> {
|
|
100
|
+
t: PlaySeconds;
|
|
101
|
+
}
|
|
102
|
+
/** The score as played: recorded on the film's clock, moved with a person's scene lengths. */
|
|
103
|
+
export interface PlayedScore extends Omit<ScoreData, 'events'> {
|
|
104
|
+
events: PlayedScoreEvent[];
|
|
105
|
+
}
|
|
106
|
+
export interface PlayedNarrationLine {
|
|
107
|
+
at: PlaySeconds;
|
|
108
|
+
dur: number;
|
|
109
|
+
text: string;
|
|
110
|
+
audio: string;
|
|
111
|
+
}
|
|
112
|
+
export interface NarrationReport {
|
|
113
|
+
lines: PlayedNarrationLine[];
|
|
114
|
+
duck: number | null;
|
|
115
|
+
}
|
|
116
|
+
/** One text node on the stage, in document order. A hidden node is told too, without a box. */
|
|
117
|
+
export interface StageText {
|
|
118
|
+
text: string;
|
|
119
|
+
x?: number;
|
|
120
|
+
y?: number;
|
|
121
|
+
w?: number;
|
|
122
|
+
h?: number;
|
|
123
|
+
/** The height of its first line, in film pixels. */
|
|
124
|
+
line?: number;
|
|
125
|
+
/** `<stretch>:<place>`: the line of words it is part of, where the page asked for places. */
|
|
126
|
+
id?: string;
|
|
127
|
+
seen?: boolean;
|
|
128
|
+
}
|
|
129
|
+
export type ConsoleLevel = 'log' | 'info' | 'warn' | 'error';
|
|
130
|
+
export type ErrorPhase = 'load' | 'render';
|
|
131
|
+
export type HostToStage = {
|
|
132
|
+
type: 'load';
|
|
133
|
+
film: StageFilm;
|
|
134
|
+
}
|
|
135
|
+
/** Seek, play and pause: the moment to show and whether the film is playing on from it. */
|
|
136
|
+
| {
|
|
137
|
+
type: 'render';
|
|
138
|
+
seq: number;
|
|
139
|
+
t: PlaySeconds;
|
|
140
|
+
playing: boolean;
|
|
141
|
+
} | {
|
|
142
|
+
type: 'mode';
|
|
143
|
+
mode: RenderMode;
|
|
144
|
+
}
|
|
145
|
+
/** A snapshot of the stage at `t`, `scale` times its size. */
|
|
146
|
+
| {
|
|
147
|
+
type: 'frame';
|
|
148
|
+
seq: number;
|
|
149
|
+
t: PlaySeconds;
|
|
150
|
+
scale: number;
|
|
151
|
+
smallMedia: boolean;
|
|
152
|
+
readFx: boolean;
|
|
153
|
+
smooth: boolean;
|
|
154
|
+
}
|
|
155
|
+
/** Read the stage's text nodes now and after each paused frame (`watch` on), with their places if asked. */
|
|
156
|
+
| {
|
|
157
|
+
type: 'watch';
|
|
158
|
+
on: boolean;
|
|
159
|
+
places: boolean;
|
|
160
|
+
}
|
|
161
|
+
/** Check the stage for what a snapshot cannot show; findings come as console errors. */
|
|
162
|
+
| {
|
|
163
|
+
type: 'scan';
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Read the layers of the stretch `from`–`to`, drawing it many times over, and their boxes and looks at `at`.
|
|
167
|
+
* `scene`: the scene the stretch is, whose class prefix names things; null in a film not made of scenes.
|
|
168
|
+
* `stop`: no reading is wanted any more, so one under way ends unanswered.
|
|
169
|
+
*/
|
|
170
|
+
| {
|
|
171
|
+
type: 'layers';
|
|
172
|
+
seq: number;
|
|
173
|
+
from: PlaySeconds;
|
|
174
|
+
to: PlaySeconds;
|
|
175
|
+
at: PlaySeconds;
|
|
176
|
+
scene: string | null;
|
|
177
|
+
stop: boolean;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* A person's changes by hand to how things look (modules/retouched.json, parsed), laid over the film from the next
|
|
181
|
+
* frame on and drawn at once on the moment on show. null: none.
|
|
182
|
+
*/
|
|
183
|
+
| {
|
|
184
|
+
type: 'retouch';
|
|
185
|
+
record: RetouchedRecord | null;
|
|
186
|
+
}
|
|
187
|
+
/** How the film itself draws the thing `id` names in the stretch on show; `t`: the moment on show, if not the last asked. */
|
|
188
|
+
| {
|
|
189
|
+
type: 'look';
|
|
190
|
+
seq: number;
|
|
191
|
+
id: string;
|
|
192
|
+
t: PlaySeconds | null;
|
|
193
|
+
};
|
|
194
|
+
export type StageToHost = {
|
|
195
|
+
type: 'hello';
|
|
196
|
+
version: number;
|
|
197
|
+
} | {
|
|
198
|
+
type: 'ready';
|
|
199
|
+
meta: StageMeta;
|
|
200
|
+
score: PlayedScore | null;
|
|
201
|
+
narration: NarrationReport | null;
|
|
202
|
+
loadMs: number;
|
|
203
|
+
}
|
|
204
|
+
/** The frame asked for with `seq` (and every one before it) is on show. */
|
|
205
|
+
| {
|
|
206
|
+
type: 'presented';
|
|
207
|
+
seq: number;
|
|
208
|
+
t: PlaySeconds;
|
|
209
|
+
ok: boolean;
|
|
210
|
+
ms: number;
|
|
211
|
+
} | {
|
|
212
|
+
type: 'frame';
|
|
213
|
+
seq: number;
|
|
214
|
+
t: FilmSeconds;
|
|
215
|
+
svg: string;
|
|
216
|
+
pw: number;
|
|
217
|
+
ph: number;
|
|
218
|
+
ms: number;
|
|
219
|
+
}
|
|
220
|
+
/** hold: this frame failed but the next may not. env: the browser's doing (a tab in the background), not the film's. */
|
|
221
|
+
| {
|
|
222
|
+
type: 'frame-error';
|
|
223
|
+
seq: number;
|
|
224
|
+
hold: boolean;
|
|
225
|
+
env: boolean;
|
|
226
|
+
message: string;
|
|
227
|
+
} | {
|
|
228
|
+
type: 'console';
|
|
229
|
+
level: ConsoleLevel;
|
|
230
|
+
text: string;
|
|
231
|
+
} | {
|
|
232
|
+
type: 'error';
|
|
233
|
+
phase: ErrorPhase;
|
|
234
|
+
message: string;
|
|
235
|
+
stack: string;
|
|
236
|
+
}
|
|
237
|
+
/** The frame is about to navigate away: the film is gone. */
|
|
238
|
+
| {
|
|
239
|
+
type: 'navigating';
|
|
240
|
+
} | {
|
|
241
|
+
type: 'texts';
|
|
242
|
+
nodes: StageText[];
|
|
243
|
+
} | {
|
|
244
|
+
type: 'layers';
|
|
245
|
+
report: LayersReport;
|
|
246
|
+
}
|
|
247
|
+
/** null: nothing could be told of it (it is not there, the stage is not displayed, or the film's render gives promises). */
|
|
248
|
+
| {
|
|
249
|
+
type: 'looked';
|
|
250
|
+
seq: number;
|
|
251
|
+
id: string;
|
|
252
|
+
look: AskedLook | null;
|
|
253
|
+
lost: string[];
|
|
254
|
+
}
|
|
255
|
+
/** A person clicked a link on the stage; the frame never follows it, the host decides. */
|
|
256
|
+
| {
|
|
257
|
+
type: 'link';
|
|
258
|
+
href: string;
|
|
259
|
+
};
|
|
260
|
+
export type HostToStageType = HostToStage['type'];
|
|
261
|
+
export type StageToHostType = StageToHost['type'];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Bumped when a message changes shape; the host refuses a stage that says another. */
|
|
2
|
+
export const STAGE_PROTOCOL_VERSION = 2;
|
|
3
|
+
/**
|
|
4
|
+
* The one message the host posts to the frame's window, on the frame's load, carrying the port every later message
|
|
5
|
+
* goes through. The frame takes the first one that comes from its parent and ignores the rest.
|
|
6
|
+
*/
|
|
7
|
+
export const STAGE_CONNECT = 'video-stage:connect';
|
package/src/protocol.js
ADDED
package/src/raster.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { drawSnapshot, whyNoDecode } from './runtime/snapshot/draw.ts';
|
|
2
|
+
export type { SnapshotSource, SnapshotSurface } from './runtime/snapshot/draw.ts';
|
|
3
|
+
export { makeHoldFirstDraw } from './runtime/snapshot/hold-first-draw.ts';
|
|
4
|
+
export type { HoldFirstDraw } from './runtime/snapshot/hold-first-draw.ts';
|
package/src/raster.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { StageAsset } from '../protocol.ts';
|
|
2
|
+
export declare function dataUrl(mime: string, bytes: ArrayBuffer): string;
|
|
3
|
+
/** Pictures and fonts become data: URLs, which a snapshot can see; a clip keeps its URL and streams. */
|
|
4
|
+
export declare function addAssets(list: readonly StageAsset[]): void;
|
|
5
|
+
export declare const assetUrl: (name: string) => string | null;
|
|
6
|
+
export interface AssetStore {
|
|
7
|
+
has(name: string): boolean;
|
|
8
|
+
list(): string[];
|
|
9
|
+
url(name: string): string;
|
|
10
|
+
mime(name: string): string;
|
|
11
|
+
bytes(name: string): Uint8Array | null;
|
|
12
|
+
text(name: string): string | null;
|
|
13
|
+
image(name: string): Promise<HTMLImageElement>;
|
|
14
|
+
size(name: string): {
|
|
15
|
+
w: number;
|
|
16
|
+
h: number;
|
|
17
|
+
} | null;
|
|
18
|
+
}
|
|
19
|
+
export declare const assetStore: AssetStore;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { addFontAsset } from "./fonts.js";
|
|
2
|
+
const assets = new Map();
|
|
3
|
+
const images = new Map();
|
|
4
|
+
const CHUNK = 0x8000;
|
|
5
|
+
export function dataUrl(mime, bytes) {
|
|
6
|
+
const all = new Uint8Array(bytes);
|
|
7
|
+
let text = '';
|
|
8
|
+
for (let i = 0; i < all.length; i += CHUNK)
|
|
9
|
+
text += String.fromCharCode(...all.subarray(i, Math.min(i + CHUNK, all.length)));
|
|
10
|
+
return 'data:' + mime + ';base64,' + btoa(text);
|
|
11
|
+
}
|
|
12
|
+
/** Pictures and fonts become data: URLs, which a snapshot can see; a clip keeps its URL and streams. */
|
|
13
|
+
export function addAssets(list) {
|
|
14
|
+
for (const asset of list) {
|
|
15
|
+
const url = asset.bytes ? dataUrl(asset.mime, asset.bytes) : asset.url;
|
|
16
|
+
if (url === undefined)
|
|
17
|
+
continue;
|
|
18
|
+
assets.set(asset.name, { url, mime: asset.mime, bytes: asset.bytes ?? null, w: asset.w, h: asset.h });
|
|
19
|
+
if (/^font\//.test(asset.mime))
|
|
20
|
+
addFontAsset(asset.name, url);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export const assetUrl = (name) => assets.get(name)?.url ?? null;
|
|
24
|
+
export const assetStore = {
|
|
25
|
+
has: (name) => assets.has(name),
|
|
26
|
+
list: () => [...assets.keys()],
|
|
27
|
+
url(name) {
|
|
28
|
+
const asset = assets.get(name);
|
|
29
|
+
if (asset)
|
|
30
|
+
return asset.url;
|
|
31
|
+
console.error('kit.assets: no asset ' + name);
|
|
32
|
+
return '';
|
|
33
|
+
},
|
|
34
|
+
mime: (name) => assets.get(name)?.mime ?? '',
|
|
35
|
+
bytes(name) {
|
|
36
|
+
const bytes = assets.get(name)?.bytes;
|
|
37
|
+
return bytes ? new Uint8Array(bytes.slice(0)) : null;
|
|
38
|
+
},
|
|
39
|
+
text(name) {
|
|
40
|
+
const bytes = assets.get(name)?.bytes;
|
|
41
|
+
return bytes ? new TextDecoder().decode(bytes) : null;
|
|
42
|
+
},
|
|
43
|
+
image(name) {
|
|
44
|
+
const cached = images.get(name);
|
|
45
|
+
if (cached)
|
|
46
|
+
return cached;
|
|
47
|
+
const asset = assets.get(name);
|
|
48
|
+
if (!asset)
|
|
49
|
+
return Promise.reject(new Error('no asset ' + name));
|
|
50
|
+
const loading = new Promise((resolve, reject) => {
|
|
51
|
+
const image = new Image();
|
|
52
|
+
image.onload = () => resolve(image);
|
|
53
|
+
image.onerror = () => reject(new Error('asset ' + name + ' did not decode'));
|
|
54
|
+
image.src = asset.url;
|
|
55
|
+
});
|
|
56
|
+
images.set(name, loading);
|
|
57
|
+
return loading;
|
|
58
|
+
},
|
|
59
|
+
size(name) {
|
|
60
|
+
const asset = assets.get(name);
|
|
61
|
+
return asset && asset.w ? { w: asset.w, h: asset.h } : null;
|
|
62
|
+
},
|
|
63
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { NarrationLine, PlaySeconds } from '@open-artifact/motion-core';
|
|
2
|
+
import type { NarrationLimits, PlayedNarrationLine } from '../protocol.ts';
|
|
3
|
+
export interface ReadNarration {
|
|
4
|
+
lines: NarrationLine[];
|
|
5
|
+
duck: number | null;
|
|
6
|
+
captions: false | {
|
|
7
|
+
style?: string;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export interface CaptionCue {
|
|
11
|
+
from: PlaySeconds;
|
|
12
|
+
to: PlaySeconds;
|
|
13
|
+
text: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The cut's narration, held to the host's limits: the page applies the same, so a line dropped here is named and
|
|
17
|
+
* not captioned.
|
|
18
|
+
*/
|
|
19
|
+
export declare function readNarration(narration: unknown, duration: number, limits: NarrationLimits): ReadNarration | null;
|
|
20
|
+
/** A line over LONGEST_CUE characters shows in parts of about equal length, split at spaces, each for its share of the line's time. */
|
|
21
|
+
export declare function captionCues(lines: readonly PlayedNarrationLine[]): CaptionCue[];
|
|
22
|
+
export interface CaptionLayer {
|
|
23
|
+
draw(t: PlaySeconds, stage: HTMLElement): void;
|
|
24
|
+
}
|
|
25
|
+
/** `shortSide`, the stage's shorter side, sizes the type. What draw shows depends only on t. */
|
|
26
|
+
export declare function captionLayer(lines: readonly PlayedNarrationLine[], style: string | undefined, shortSide: number, sans: string): CaptionLayer;
|