@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,153 @@
|
|
|
1
|
+
import { parseRetouchedRecord } from '@open-artifact/motion-core';
|
|
2
|
+
import { PAINT, PAINT_KEYS, SHAPE } from "../layers/parts.js";
|
|
3
|
+
import { CORNERS, KEYS } from "./look.js";
|
|
4
|
+
import { TYPE_KEYS, typeRule } from "./type-style.js";
|
|
5
|
+
/*
|
|
6
|
+
* What a person did by hand to the look of things, as this stage lays it. After each frame is drawn the thing's
|
|
7
|
+
* element is marked with attributes, and one sheet in the stage styles what is marked. So the live view, the
|
|
8
|
+
* thumbnails, an export and a still made offline all show it; the film's own code and inline styles are not touched,
|
|
9
|
+
* and come back when the mark goes.
|
|
10
|
+
*/
|
|
11
|
+
/** Which entry marks the element. */
|
|
12
|
+
export const MARK = 'data-film-over';
|
|
13
|
+
/** What of it is laid on the element: its keys; for the radius, the corners that take it; for an svg text's ink, "paint". */
|
|
14
|
+
export const LAID = 'data-film-laid';
|
|
15
|
+
/** What of it no longer counts. */
|
|
16
|
+
export const LAPSED = 'data-film-lapsed';
|
|
17
|
+
export const ID = /^([a-z][a-z0-9-]{0,31}):(\d{1,3}(?:\.\d{1,3}){0,23})\/([a-z][a-z0-9-]{0,31})$/;
|
|
18
|
+
const KIN = /^(\d{1,4})\/(\d{1,4})(?:\/([0-9a-z]{1,7}))?$/;
|
|
19
|
+
export const state = {
|
|
20
|
+
list: [],
|
|
21
|
+
/** The elements this stage marked at its last pass: a mark a film's copy of a node brings along does not count. */
|
|
22
|
+
marked: [],
|
|
23
|
+
sheet: null,
|
|
24
|
+
};
|
|
25
|
+
/** The record's entries as this stage lays them; the record is parsed again, since this is the trust boundary for the sheet. */
|
|
26
|
+
export function entriesOf(record) {
|
|
27
|
+
const out = [];
|
|
28
|
+
for (const layer of parseRetouchedRecord({ v: 1, layers: record.layers }).layers) {
|
|
29
|
+
const id = ID.exec(layer.id);
|
|
30
|
+
const kin = KIN.exec(layer.kin);
|
|
31
|
+
if (!id || !kin)
|
|
32
|
+
continue;
|
|
33
|
+
const tag = id[3];
|
|
34
|
+
const entry = {
|
|
35
|
+
id: layer.id,
|
|
36
|
+
at: layer.at,
|
|
37
|
+
told: new Map(),
|
|
38
|
+
scene: id[1],
|
|
39
|
+
tag,
|
|
40
|
+
cls: layer.cls.split(/\s+/).filter(Boolean),
|
|
41
|
+
kin: layer.kin,
|
|
42
|
+
k: Number(kin[1]),
|
|
43
|
+
n: Number(kin[2]),
|
|
44
|
+
print: kin[3] ?? null,
|
|
45
|
+
parts: layer.parts ? layer.parts.split('.') : null,
|
|
46
|
+
pairs: {},
|
|
47
|
+
};
|
|
48
|
+
for (const key of KEYS) {
|
|
49
|
+
const pair = layer[key];
|
|
50
|
+
if (!pair)
|
|
51
|
+
continue;
|
|
52
|
+
if ((key === 'svgfill' || key === 'svgstroke') && !SHAPE.test(tag))
|
|
53
|
+
continue;
|
|
54
|
+
entry.pairs[key] = { was: pair.was, v: pair.v };
|
|
55
|
+
}
|
|
56
|
+
// With no pair it lays it changes nothing.
|
|
57
|
+
if (KEYS.some((key) => entry.pairs[key]))
|
|
58
|
+
out.push(entry);
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
/** The sheet's text. Of a pair only `v` reaches it, a colour, a number or a word out of a closed set; no selector is made of anything in the record. */
|
|
63
|
+
export function rulesText(list) {
|
|
64
|
+
return list
|
|
65
|
+
.map((e, n) => {
|
|
66
|
+
const at = (what) => '[' + MARK + '="' + n + '"][' + LAID + '~="' + what + '"]';
|
|
67
|
+
// Twice: in a layer it also wins over every rule of the film's that says !important outside one; a browser that knows no layers takes the first.
|
|
68
|
+
const twice = (rule) => rule + '@layer film-laid{' + rule + '}';
|
|
69
|
+
const colour = (key) => String(e.pairs[key]?.v ?? '').toLowerCase();
|
|
70
|
+
let out = '';
|
|
71
|
+
if (e.pairs.fill)
|
|
72
|
+
out += at('fill') + '{background-image:none!important;background-color:' + colour('fill') + '!important}';
|
|
73
|
+
if (e.pairs.ink)
|
|
74
|
+
out += twice(at('ink') + '{color:' + colour('ink') + '!important}') + twice(at('paint') + '{fill:' + colour('ink') + '!important}');
|
|
75
|
+
// The property, not a transform: the film's own transform, and the point it turns on, go on counting.
|
|
76
|
+
if (e.pairs.size)
|
|
77
|
+
out += at('size') + '{scale:' + Number(e.pairs.size.v) + '!important}';
|
|
78
|
+
if (e.pairs.radius)
|
|
79
|
+
for (const corner of CORNERS)
|
|
80
|
+
out += at(corner) + '{border-' + corner + '-radius:' + Number(e.pairs.radius.v) + 'px!important}';
|
|
81
|
+
// Visibility keeps its room, so nothing round it moves; on all under it too, since a child that says visible would otherwise show.
|
|
82
|
+
if (e.pairs.hidden)
|
|
83
|
+
out += at('hidden') + ',' + at('hidden') + ' *{visibility:hidden!important}';
|
|
84
|
+
for (const key of TYPE_KEYS) {
|
|
85
|
+
const pair = e.pairs[key];
|
|
86
|
+
if (pair)
|
|
87
|
+
out += twice(at(key) + '{' + typeRule(key, pair.v) + '}');
|
|
88
|
+
}
|
|
89
|
+
for (const key of PAINT_KEYS)
|
|
90
|
+
if (e.pairs[key])
|
|
91
|
+
out += twice(at(key) + '{' + PAINT[key] + ':' + colour(key) + '!important}');
|
|
92
|
+
return out;
|
|
93
|
+
})
|
|
94
|
+
.join('\n');
|
|
95
|
+
}
|
|
96
|
+
export function unmark() {
|
|
97
|
+
for (const el of state.marked) {
|
|
98
|
+
el.removeAttribute(MARK);
|
|
99
|
+
el.removeAttribute(LAID);
|
|
100
|
+
el.removeAttribute(LAPSED);
|
|
101
|
+
}
|
|
102
|
+
state.marked = [];
|
|
103
|
+
}
|
|
104
|
+
/** The entry that marks an element. */
|
|
105
|
+
export function marks(el) {
|
|
106
|
+
if (!state.marked.includes(el))
|
|
107
|
+
return undefined;
|
|
108
|
+
const i = el.getAttribute(MARK);
|
|
109
|
+
return i !== null && /^\d+$/.test(i) ? state.list[Number(i)] : undefined;
|
|
110
|
+
}
|
|
111
|
+
export const lapsedOn = (el) => (el.getAttribute(LAPSED) ?? '').split(' ').filter(Boolean);
|
|
112
|
+
export function toldAt(e, lo) {
|
|
113
|
+
const told = e.told.get(lo);
|
|
114
|
+
return told ? told : null;
|
|
115
|
+
}
|
|
116
|
+
/** Of an entry of the scene nothing could be told in this load: which element is its own is not known, so no look is told of any. */
|
|
117
|
+
export const blind = (scene, lo) => state.list.some((e) => e.scene === scene && e.told.get(lo) === null);
|
|
118
|
+
/** An entry's own moment lies in the stretch: a scene's always does, since it counts from the scene's start. */
|
|
119
|
+
export const home = (e, lo, hi) => e.scene !== 'film' || (e.at >= lo && e.at < hi);
|
|
120
|
+
/**
|
|
121
|
+
* One found otherwise keeps an element from one found by its parts, and one found by its print from one found by its
|
|
122
|
+
* turn; else the later in the record, changed last, takes it.
|
|
123
|
+
*/
|
|
124
|
+
export function takes(e, w, lo) {
|
|
125
|
+
const a = toldAt(e, lo)?.seat;
|
|
126
|
+
const b = toldAt(w, lo)?.seat;
|
|
127
|
+
if (!a?.held !== !b?.held)
|
|
128
|
+
return !a?.held;
|
|
129
|
+
return !!a?.sure || !b?.sure;
|
|
130
|
+
}
|
|
131
|
+
/** Of entries seated on one node one is laid; the others, which apply passes over and lost names. */
|
|
132
|
+
export function beaten(scene, lo) {
|
|
133
|
+
const by = new Map();
|
|
134
|
+
const out = [];
|
|
135
|
+
for (const e of state.list) {
|
|
136
|
+
const told = e.scene === scene ? toldAt(e, lo) : null;
|
|
137
|
+
if (!told)
|
|
138
|
+
continue;
|
|
139
|
+
const w = by.get(told.seat.el);
|
|
140
|
+
if (w && !takes(e, w, lo)) {
|
|
141
|
+
out.push(e);
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (w)
|
|
145
|
+
out.push(w);
|
|
146
|
+
by.set(told.seat.el, e);
|
|
147
|
+
}
|
|
148
|
+
return out;
|
|
149
|
+
}
|
|
150
|
+
/** All of an entry that a verdict on it rests on: not `v`. */
|
|
151
|
+
export function basis(e) {
|
|
152
|
+
return JSON.stringify([e.id, e.cls, e.kin, e.parts, e.at, ...KEYS.map((key) => e.pairs[key]?.was ?? null)]);
|
|
153
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { TypeLook } from '../../protocol.ts';
|
|
2
|
+
export declare const TYPE_KEYS: readonly ["weight", "italic", "px", "leading", "tracking", "align"];
|
|
3
|
+
export type TypeKey = (typeof TYPE_KEYS)[number];
|
|
4
|
+
/** The CSS property each is read off. */
|
|
5
|
+
export declare const TYPE_PROPS: Record<TypeKey, readonly string[]>;
|
|
6
|
+
/** The head of its font stack; '': none that is a plain name. */
|
|
7
|
+
export declare function familyHead(cs: CSSStyleDeclaration): string;
|
|
8
|
+
/** How the film sets the words now; null for what the record cannot hold. */
|
|
9
|
+
export declare function typeSeen(cs: CSSStyleDeclaration): TypeLook;
|
|
10
|
+
/**
|
|
11
|
+
* What a change would not show on is not offered. For offering alone: a pair that was saved goes on counting by what
|
|
12
|
+
* the film gives, though the line may come to fill its box at some moment.
|
|
13
|
+
*/
|
|
14
|
+
export declare function offerType(cs: CSSStyleDeclaration, el: Element, now: TypeLook): void;
|
|
15
|
+
/** What the film itself changes in the course of a stretch is not offered: compared look to look. */
|
|
16
|
+
export declare function typeHues(cs: CSSStyleDeclaration): Record<TypeKey, string>;
|
|
17
|
+
export declare function sameType(key: TypeKey, now: string | number | null, was: string | number): boolean;
|
|
18
|
+
/** The declaration that lays value `v`. The record was parsed by the core, so `v` is within its bounds. */
|
|
19
|
+
export declare function typeRule(key: TypeKey, v: string | number): string;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { TEXT_ALIGNS, TEXT_STYLE_BOUNDS } from '@open-artifact/motion-core';
|
|
2
|
+
/*
|
|
3
|
+
* The type of a line of words as a person sets it by hand: read off an element, held to a saved pair and written into
|
|
4
|
+
* the retouch sheet. A typeface picked for one line is not laid on this stage.
|
|
5
|
+
*/
|
|
6
|
+
export const TYPE_KEYS = ['weight', 'italic', 'px', 'leading', 'tracking', 'align'];
|
|
7
|
+
/** The CSS property each is read off. */
|
|
8
|
+
export const TYPE_PROPS = {
|
|
9
|
+
weight: ['font-weight'],
|
|
10
|
+
italic: ['font-style'],
|
|
11
|
+
px: ['font-size'],
|
|
12
|
+
leading: ['line-height'],
|
|
13
|
+
tracking: ['letter-spacing'],
|
|
14
|
+
align: ['text-align'],
|
|
15
|
+
};
|
|
16
|
+
/** How close two readings must be to count as the same: engines round differently. */
|
|
17
|
+
const NEAR = { weight: 0.5, px: 0.05, leading: 0.005, tracking: 0.002 };
|
|
18
|
+
const within = (bounds) => (value) => typeof value === 'number' && Number.isFinite(value) && value >= bounds[0] && value <= bounds[1];
|
|
19
|
+
const isAlign = (value) => TEXT_ALIGNS.some((align) => align === value);
|
|
20
|
+
const round = (n, to) => Math.round(n * to) / to;
|
|
21
|
+
const spacing = (cs) => (cs.letterSpacing === 'normal' ? 0 : round(parseFloat(cs.letterSpacing) / parseFloat(cs.fontSize), 1000));
|
|
22
|
+
const leadingOf = (cs) => (cs.lineHeight === 'normal' ? 'normal' : round(parseFloat(cs.lineHeight) / parseFloat(cs.fontSize), 1000));
|
|
23
|
+
/** The head of its font stack; '': none that is a plain name. */
|
|
24
|
+
export function familyHead(cs) {
|
|
25
|
+
const head = (cs.fontFamily.split(',')[0] ?? '').trim().replace(/^["']|["']$/g, '');
|
|
26
|
+
return /^[A-Za-z0-9 _-]{1,64}$/.test(head) ? head : '';
|
|
27
|
+
}
|
|
28
|
+
/** How the film sets the words now; null for what the record cannot hold. */
|
|
29
|
+
export function typeSeen(cs) {
|
|
30
|
+
const weight = cs.fontWeight === 'bold' ? 700 : cs.fontWeight === 'normal' ? 400 : parseFloat(cs.fontWeight);
|
|
31
|
+
const said = cs.textAlign.replace(/^-webkit-/, '');
|
|
32
|
+
const rtl = cs.direction === 'rtl';
|
|
33
|
+
const align = said === 'start' ? (rtl ? 'right' : 'left') : said === 'end' ? (rtl ? 'left' : 'right') : said;
|
|
34
|
+
const leading = leadingOf(cs);
|
|
35
|
+
const px = round(parseFloat(cs.fontSize), 100);
|
|
36
|
+
const tracking = spacing(cs);
|
|
37
|
+
return {
|
|
38
|
+
weight: within(TEXT_STYLE_BOUNDS.weight.was)(weight) ? weight : null,
|
|
39
|
+
italic: /^(italic|oblique)/.test(cs.fontStyle) ? 1 : 0,
|
|
40
|
+
px: within(TEXT_STYLE_BOUNDS.px.was)(px) ? px : null,
|
|
41
|
+
leading: leading === 'normal' || within(TEXT_STYLE_BOUNDS.leading.was)(leading) ? leading : null,
|
|
42
|
+
tracking: within(TEXT_STYLE_BOUNDS.tracking.was)(tracking) ? tracking : null,
|
|
43
|
+
align: isAlign(align) ? align : null,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/** Whether another text-align would move anything: the box lays out lines of its own, and has more than one, or one shorter than it is wide. */
|
|
47
|
+
function loose(cs, el) {
|
|
48
|
+
if (!/^(block|inline-block|list-item|table-cell|flow-root)$/.test(cs.display) || !(el instanceof HTMLElement))
|
|
49
|
+
return false;
|
|
50
|
+
const range = document.createRange();
|
|
51
|
+
const tops = [];
|
|
52
|
+
range.selectNodeContents(el);
|
|
53
|
+
for (const rect of Array.from(range.getClientRects()))
|
|
54
|
+
if (rect.width > 0 && tops.every((top) => Math.abs(top - rect.top) > rect.height / 2))
|
|
55
|
+
tops.push(rect.top);
|
|
56
|
+
const inner = el.offsetWidth > 0 ? (el.getBoundingClientRect().width * (el.clientWidth - parseFloat(cs.paddingLeft) - parseFloat(cs.paddingRight))) / el.offsetWidth : 0;
|
|
57
|
+
return tops.length > 1 || range.getBoundingClientRect().width < inner * 0.98;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* What a change would not show on is not offered. For offering alone: a pair that was saved goes on counting by what
|
|
61
|
+
* the film gives, though the line may come to fill its box at some moment.
|
|
62
|
+
*/
|
|
63
|
+
export function offerType(cs, el, now) {
|
|
64
|
+
// Words in an svg have no line box: neither text-align nor line-height moves them.
|
|
65
|
+
const art = el.namespaceURI === 'http://www.w3.org/2000/svg';
|
|
66
|
+
if (art || !loose(cs, el))
|
|
67
|
+
now.align = null;
|
|
68
|
+
if (art)
|
|
69
|
+
now.leading = null;
|
|
70
|
+
// An svg's units may put the size outside what a person may give, and the Size field could not return to it.
|
|
71
|
+
if (art && now.px !== null && !within(TEXT_STYLE_BOUNDS.px.v)(now.px))
|
|
72
|
+
now.px = null;
|
|
73
|
+
}
|
|
74
|
+
/** What the film itself changes in the course of a stretch is not offered: compared look to look. */
|
|
75
|
+
export function typeHues(cs) {
|
|
76
|
+
return {
|
|
77
|
+
weight: cs.fontWeight,
|
|
78
|
+
italic: cs.fontStyle,
|
|
79
|
+
px: cs.fontSize,
|
|
80
|
+
leading: String(leadingOf(cs)),
|
|
81
|
+
tracking: String(spacing(cs)),
|
|
82
|
+
align: cs.textAlign,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export function sameType(key, now, was) {
|
|
86
|
+
const near = NEAR[key];
|
|
87
|
+
if (now === null)
|
|
88
|
+
return false;
|
|
89
|
+
return near === undefined || typeof now !== 'number' || typeof was !== 'number' ? now === was : Math.abs(now - was) <= near;
|
|
90
|
+
}
|
|
91
|
+
/** The declaration that lays value `v`. The record was parsed by the core, so `v` is within its bounds. */
|
|
92
|
+
export function typeRule(key, v) {
|
|
93
|
+
switch (key) {
|
|
94
|
+
case 'weight':
|
|
95
|
+
return 'font-weight:' + Number(v) + '!important';
|
|
96
|
+
case 'italic':
|
|
97
|
+
return 'font-style:' + (v ? 'italic' : 'normal') + '!important';
|
|
98
|
+
case 'px':
|
|
99
|
+
return 'font-size:' + Number(v) + 'px!important';
|
|
100
|
+
case 'leading':
|
|
101
|
+
return 'line-height:' + Number(v) + '!important';
|
|
102
|
+
case 'tracking':
|
|
103
|
+
return 'letter-spacing:' + Number(v) + 'em!important';
|
|
104
|
+
case 'align':
|
|
105
|
+
return 'text-align:' + (typeof v === 'string' && isAlign(v) ? v : 'left') + '!important';
|
|
106
|
+
default: {
|
|
107
|
+
const never = key;
|
|
108
|
+
return never;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { stageParts } from "./stage.js";
|
|
2
|
+
const told = new Set();
|
|
3
|
+
const CSS_URL = /url\(\s*(?:"([^"\\]*(?:\\[\s\S][^"\\]*)*)|'([^'\\]*(?:\\[\s\S][^'\\]*)*)|([^'")\s]*))/g;
|
|
4
|
+
function once(key, message) {
|
|
5
|
+
if (told.has(key))
|
|
6
|
+
return;
|
|
7
|
+
told.add(key);
|
|
8
|
+
console.error('raster-safety: ' + message);
|
|
9
|
+
}
|
|
10
|
+
const isOutside = (url) => url !== '' && !url.startsWith('data:') && !url.startsWith('#');
|
|
11
|
+
/** What on the stage an exported frame cannot show, said once each; and focus a film asked for, taken back. */
|
|
12
|
+
export function scanStage() {
|
|
13
|
+
const parts = stageParts();
|
|
14
|
+
if (!parts)
|
|
15
|
+
return;
|
|
16
|
+
const { stage, fontStyle } = parts;
|
|
17
|
+
for (const image of stage.querySelectorAll('img')) {
|
|
18
|
+
const source = image.getAttribute('src') ?? '';
|
|
19
|
+
if (source && !source.startsWith('data:'))
|
|
20
|
+
once('img:' + source.slice(0, 40), '<img src> must be a data: URL (kit.assets.url): "' + source.slice(0, 60) + '" will not appear in exported frames');
|
|
21
|
+
}
|
|
22
|
+
if (stage.querySelector('iframe'))
|
|
23
|
+
once('iframe', '<iframe> inside the stage cannot be exported');
|
|
24
|
+
if (stage.querySelector('link[rel=stylesheet]'))
|
|
25
|
+
once('link', 'external stylesheets are blocked; put CSS in a module and kit.css() it');
|
|
26
|
+
for (const focused of stage.querySelectorAll('[autofocus]'))
|
|
27
|
+
focused.removeAttribute('autofocus');
|
|
28
|
+
for (const node of stage.querySelectorAll('*')) {
|
|
29
|
+
if (node.scrollTop || node.scrollLeft) {
|
|
30
|
+
once('scroll', 'an element is scrolled (scrollTop/scrollLeft); exported frames ignore scroll offsets, so animate a translateY instead');
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const texts = [];
|
|
35
|
+
for (const styled of stage.querySelectorAll('[style*="url("]'))
|
|
36
|
+
texts.push(styled.getAttribute('style') ?? '');
|
|
37
|
+
for (const sheet of stage.querySelectorAll('style'))
|
|
38
|
+
if (sheet !== fontStyle)
|
|
39
|
+
texts.push(sheet.textContent ?? '');
|
|
40
|
+
for (const text of texts) {
|
|
41
|
+
for (const match of text.matchAll(CSS_URL)) {
|
|
42
|
+
const url = (match[1] ?? match[2] ?? match[3] ?? '').trim();
|
|
43
|
+
if (isOutside(url)) {
|
|
44
|
+
once('cssurl', 'CSS uses url(' + url.slice(0, 40) + ') that is not a data: URL; it will not load here (inline it as an asset data: URL or drop the rule)');
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const LIGHT_INK = "rgba(255,255,255,.72)";
|
|
2
|
+
export declare const DARK_INK = "rgba(0,0,0,.64)";
|
|
3
|
+
export type CardInk = typeof LIGHT_INK | typeof DARK_INK;
|
|
4
|
+
type Rgb = [number, number, number];
|
|
5
|
+
/** The ground's red, green and blue, if it is an opaque colour the canvas reads (not a gradient, not var()). */
|
|
6
|
+
export declare function groundRgb(context: CanvasRenderingContext2D, ground: string): Rgb | null;
|
|
7
|
+
export declare const greyOf: (rgb: Rgb) => number;
|
|
8
|
+
/** The ink for a card on `rgb`, which is the card's ground as shown (greyed already where it is). */
|
|
9
|
+
export declare function cardInk(rgb: Rgb): CardInk;
|
|
10
|
+
/** The card ink on whatever the canvas makes of the ground: an unreadable ground counts as its fallback. */
|
|
11
|
+
export declare function inkOn(context: CanvasRenderingContext2D, ground: string, greyed: boolean): CardInk;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* A scene that is not written yet, or failed, shows a card with its name on the film's ground. The ink is white or
|
|
3
|
+
* black, whichever stands out more (WCAG contrast) from the ground as the card shows it, greyed or not; at these
|
|
4
|
+
* strengths it is at least 3 to 1 on every ground the canvas can read.
|
|
5
|
+
*/
|
|
6
|
+
export const LIGHT_INK = 'rgba(255,255,255,.72)';
|
|
7
|
+
export const DARK_INK = 'rgba(0,0,0,.64)';
|
|
8
|
+
/** How the canvas spells a colour: most CSS colours become #rrggbb or rgba(). What it cannot read leaves `failing`. */
|
|
9
|
+
function spelled(context, ground, failing) {
|
|
10
|
+
const before = context.fillStyle;
|
|
11
|
+
context.fillStyle = failing;
|
|
12
|
+
context.fillStyle = ground;
|
|
13
|
+
const spelling = String(context.fillStyle);
|
|
14
|
+
context.fillStyle = before;
|
|
15
|
+
return spelling;
|
|
16
|
+
}
|
|
17
|
+
/** The ground's red, green and blue, if it is an opaque colour the canvas reads (not a gradient, not var()). */
|
|
18
|
+
export function groundRgb(context, ground) {
|
|
19
|
+
const spelling = spelled(context, ground, '#ffffff');
|
|
20
|
+
if (spelling !== spelled(context, ground, '#000000'))
|
|
21
|
+
return null;
|
|
22
|
+
const found = /^#(..)(..)(..)$/.exec(spelling);
|
|
23
|
+
if (!found)
|
|
24
|
+
return null;
|
|
25
|
+
return [parseInt(found[1] ?? '0', 16), parseInt(found[2] ?? '0', 16), parseInt(found[3] ?? '0', 16)];
|
|
26
|
+
}
|
|
27
|
+
export const greyOf = (rgb) => 0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2];
|
|
28
|
+
function luminance(rgb) {
|
|
29
|
+
const weights = [0.2126, 0.7152, 0.0722];
|
|
30
|
+
return rgb.reduce((sum, channel, i) => {
|
|
31
|
+
const x = channel / 255;
|
|
32
|
+
return sum + (weights[i] ?? 0) * (x <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4));
|
|
33
|
+
}, 0.05);
|
|
34
|
+
}
|
|
35
|
+
/** The ink for a card on `rgb`, which is the card's ground as shown (greyed already where it is). */
|
|
36
|
+
export function cardInk(rgb) {
|
|
37
|
+
const apart = (shade, alpha) => {
|
|
38
|
+
const mixed = [rgb[0] * (1 - alpha) + shade * alpha, rgb[1] * (1 - alpha) + shade * alpha, rgb[2] * (1 - alpha) + shade * alpha];
|
|
39
|
+
const ratio = luminance(mixed) / luminance(rgb);
|
|
40
|
+
return ratio > 1 ? ratio : 1 / ratio;
|
|
41
|
+
};
|
|
42
|
+
return apart(255, 0.72) >= apart(0, 0.64) ? LIGHT_INK : DARK_INK;
|
|
43
|
+
}
|
|
44
|
+
/** The card ink on whatever the canvas makes of the ground: an unreadable ground counts as its fallback. */
|
|
45
|
+
export function inkOn(context, ground, greyed) {
|
|
46
|
+
let rgb = groundRgb(context, ground);
|
|
47
|
+
if (!rgb) {
|
|
48
|
+
const parts = (spelled(context, ground, '#ffffff').match(/[\d.]+/g) ?? ['255', '255', '255']).map(Number);
|
|
49
|
+
rgb = [parts[0] ?? 255, parts[1] ?? 255, parts[2] ?? 255];
|
|
50
|
+
}
|
|
51
|
+
if (greyed) {
|
|
52
|
+
const grey = greyOf(rgb);
|
|
53
|
+
rgb = [grey, grey, grey];
|
|
54
|
+
}
|
|
55
|
+
return cardInk(rgb);
|
|
56
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { RenderMode, SceneReport } from '../../protocol.ts';
|
|
2
|
+
import type { Kit } from '../kit/index.ts';
|
|
3
|
+
/** Outlines a rough scene's box as pen strokes; gives back the pen that draws them again after each render. */
|
|
4
|
+
export type Sketcher = (box: HTMLElement, id: string) => () => void;
|
|
5
|
+
export interface SceneSystem {
|
|
6
|
+
/** Runs a js module with `kit` in reach (`own`: strict, in a scope of its own); gives back what it threw, or null. */
|
|
7
|
+
run(name: string, kit: Kit, own: boolean): unknown;
|
|
8
|
+
reseed(seed: number): void;
|
|
9
|
+
/** Hears what deferred code throws while the film loads. */
|
|
10
|
+
late(handler: ((error: unknown) => void) | null): void;
|
|
11
|
+
now(): number;
|
|
12
|
+
/** Gives the fx canvas its own width again; done by the film it would count as a touch of the canvas. */
|
|
13
|
+
resetFx(): void;
|
|
14
|
+
/** This viewer gets narration. */
|
|
15
|
+
voice: boolean;
|
|
16
|
+
/** Told each scene's box once the scene has come up. */
|
|
17
|
+
box(node: HTMLElement): void;
|
|
18
|
+
sketch: Sketcher | null;
|
|
19
|
+
mode(): RenderMode;
|
|
20
|
+
}
|
|
21
|
+
export interface SceneApi {
|
|
22
|
+
scene(id: unknown, definition: unknown): void;
|
|
23
|
+
score(write: unknown): void;
|
|
24
|
+
narration(speak: unknown): void;
|
|
25
|
+
scenes(): SceneCut;
|
|
26
|
+
}
|
|
27
|
+
/** What `kit.scenes()` gives the film to set as window.CUT. */
|
|
28
|
+
export interface SceneCut {
|
|
29
|
+
width: number;
|
|
30
|
+
height: number;
|
|
31
|
+
fps: number;
|
|
32
|
+
duration: number;
|
|
33
|
+
background: string;
|
|
34
|
+
chapters: Array<{
|
|
35
|
+
t: number;
|
|
36
|
+
label: string;
|
|
37
|
+
}>;
|
|
38
|
+
init(): Promise<void>;
|
|
39
|
+
render(t: number): unknown;
|
|
40
|
+
score?: (builder: unknown) => void;
|
|
41
|
+
narration?: unknown;
|
|
42
|
+
}
|
|
43
|
+
/** A film written one scene at a time. Adds kit.scene, kit.scenes, kit.score and kit.narration. */
|
|
44
|
+
export declare function installScenes(kit: Kit, sys: SceneSystem): {
|
|
45
|
+
api: SceneApi;
|
|
46
|
+
states: () => SceneReport[] | null;
|
|
47
|
+
};
|