@openartifactsai/motion-stage 0.0.0-stage → 0.23.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +5 -2
  4. package/package.json +70 -4
  5. package/src/build.d.ts +18 -0
  6. package/src/build.js +73 -0
  7. package/src/host.d.ts +37 -0
  8. package/src/host.js +76 -0
  9. package/src/index.d.ts +11 -0
  10. package/src/index.js +6 -0
  11. package/src/layers.d.ts +30 -0
  12. package/src/layers.js +56 -0
  13. package/src/offline/audio.d.ts +19 -0
  14. package/src/offline/audio.js +20 -0
  15. package/src/offline/data.d.ts +26 -0
  16. package/src/offline/data.js +71 -0
  17. package/src/offline/main.d.ts +9 -0
  18. package/src/offline/main.js +52 -0
  19. package/src/offline/player.d.ts +23 -0
  20. package/src/offline/player.js +157 -0
  21. package/src/protocol/clip-guards.d.ts +5 -0
  22. package/src/protocol/clip-guards.js +22 -0
  23. package/src/protocol/guards.d.ts +6 -0
  24. package/src/protocol/guards.js +257 -0
  25. package/src/protocol/layer-guards.d.ts +7 -0
  26. package/src/protocol/layer-guards.js +100 -0
  27. package/src/protocol/layers.d.ts +135 -0
  28. package/src/protocol/layers.js +1 -0
  29. package/src/protocol/types.d.ts +340 -0
  30. package/src/protocol/types.js +7 -0
  31. package/src/protocol.d.ts +2 -0
  32. package/src/protocol.js +2 -0
  33. package/src/raster.d.ts +4 -0
  34. package/src/raster.js +2 -0
  35. package/src/runtime/assets.d.ts +19 -0
  36. package/src/runtime/assets.js +63 -0
  37. package/src/runtime/caption-box.d.ts +3 -0
  38. package/src/runtime/caption-box.js +16 -0
  39. package/src/runtime/captions.d.ts +31 -0
  40. package/src/runtime/captions.js +115 -0
  41. package/src/runtime/clip-captions.d.ts +9 -0
  42. package/src/runtime/clip-captions.js +27 -0
  43. package/src/runtime/clips.d.ts +83 -0
  44. package/src/runtime/clips.js +259 -0
  45. package/src/runtime/console.d.ts +13 -0
  46. package/src/runtime/console.js +99 -0
  47. package/src/runtime/cut.d.ts +7 -0
  48. package/src/runtime/cut.js +63 -0
  49. package/src/runtime/determinism.d.ts +12 -0
  50. package/src/runtime/determinism.js +47 -0
  51. package/src/runtime/film.d.ts +43 -0
  52. package/src/runtime/film.js +31 -0
  53. package/src/runtime/focus.d.ts +8 -0
  54. package/src/runtime/focus.js +71 -0
  55. package/src/runtime/fonts.d.ts +22 -0
  56. package/src/runtime/fonts.js +109 -0
  57. package/src/runtime/frame.d.ts +9 -0
  58. package/src/runtime/frame.js +140 -0
  59. package/src/runtime/fx/backdrop.d.ts +60 -0
  60. package/src/runtime/fx/backdrop.js +264 -0
  61. package/src/runtime/fx/color.d.ts +19 -0
  62. package/src/runtime/fx/color.js +84 -0
  63. package/src/runtime/fx/css-color.d.ts +6 -0
  64. package/src/runtime/fx/css-color.js +44 -0
  65. package/src/runtime/fx/curve.d.ts +12 -0
  66. package/src/runtime/fx/curve.js +34 -0
  67. package/src/runtime/fx/gl.d.ts +29 -0
  68. package/src/runtime/fx/gl.js +207 -0
  69. package/src/runtime/fx/glsl.d.ts +35 -0
  70. package/src/runtime/fx/glsl.js +113 -0
  71. package/src/runtime/fx/index.d.ts +23 -0
  72. package/src/runtime/fx/index.js +151 -0
  73. package/src/runtime/fx/key.d.ts +11 -0
  74. package/src/runtime/fx/key.js +21 -0
  75. package/src/runtime/fx/numbers.d.ts +14 -0
  76. package/src/runtime/fx/numbers.js +57 -0
  77. package/src/runtime/fx/pace.d.ts +17 -0
  78. package/src/runtime/fx/pace.js +26 -0
  79. package/src/runtime/fx/paint.d.ts +28 -0
  80. package/src/runtime/fx/paint.js +150 -0
  81. package/src/runtime/guard.d.ts +4 -0
  82. package/src/runtime/guard.js +141 -0
  83. package/src/runtime/hand-titles/index.d.ts +9 -0
  84. package/src/runtime/hand-titles/index.js +73 -0
  85. package/src/runtime/hand-titles/layer.d.ts +20 -0
  86. package/src/runtime/hand-titles/layer.js +118 -0
  87. package/src/runtime/hand-titles/place.d.ts +27 -0
  88. package/src/runtime/hand-titles/place.js +45 -0
  89. package/src/runtime/held-store.d.ts +35 -0
  90. package/src/runtime/held-store.js +63 -0
  91. package/src/runtime/held.d.ts +19 -0
  92. package/src/runtime/held.js +225 -0
  93. package/src/runtime/kit/camera.d.ts +59 -0
  94. package/src/runtime/kit/camera.js +81 -0
  95. package/src/runtime/kit/chip.d.ts +25 -0
  96. package/src/runtime/kit/chip.js +75 -0
  97. package/src/runtime/kit/count.d.ts +37 -0
  98. package/src/runtime/kit/count.js +100 -0
  99. package/src/runtime/kit/cursor.d.ts +46 -0
  100. package/src/runtime/kit/cursor.js +108 -0
  101. package/src/runtime/kit/dom.d.ts +14 -0
  102. package/src/runtime/kit/dom.js +46 -0
  103. package/src/runtime/kit/geometry.d.ts +24 -0
  104. package/src/runtime/kit/geometry.js +56 -0
  105. package/src/runtime/kit/index.d.ts +113 -0
  106. package/src/runtime/kit/index.js +157 -0
  107. package/src/runtime/kit/mark-strokes.d.ts +65 -0
  108. package/src/runtime/kit/mark-strokes.js +226 -0
  109. package/src/runtime/kit/marks.d.ts +21 -0
  110. package/src/runtime/kit/marks.js +165 -0
  111. package/src/runtime/kit/math.d.ts +23 -0
  112. package/src/runtime/kit/math.js +35 -0
  113. package/src/runtime/kit/paper.d.ts +7 -0
  114. package/src/runtime/kit/paper.js +27 -0
  115. package/src/runtime/kit/random.d.ts +8 -0
  116. package/src/runtime/kit/random.js +32 -0
  117. package/src/runtime/kit/text-fx.d.ts +18 -0
  118. package/src/runtime/kit/text-fx.js +55 -0
  119. package/src/runtime/kit/typing.d.ts +21 -0
  120. package/src/runtime/kit/typing.js +42 -0
  121. package/src/runtime/laid/layer.d.ts +44 -0
  122. package/src/runtime/laid/layer.js +370 -0
  123. package/src/runtime/layers/describe.d.ts +41 -0
  124. package/src/runtime/layers/describe.js +327 -0
  125. package/src/runtime/layers/item.d.ts +123 -0
  126. package/src/runtime/layers/item.js +150 -0
  127. package/src/runtime/layers/parts.d.ts +53 -0
  128. package/src/runtime/layers/parts.js +158 -0
  129. package/src/runtime/layers/rows.d.ts +4 -0
  130. package/src/runtime/layers/rows.js +233 -0
  131. package/src/runtime/layers/scan.d.ts +24 -0
  132. package/src/runtime/layers/scan.js +204 -0
  133. package/src/runtime/layers/walk.d.ts +16 -0
  134. package/src/runtime/layers/walk.js +337 -0
  135. package/src/runtime/load.d.ts +10 -0
  136. package/src/runtime/load.js +267 -0
  137. package/src/runtime/main.d.ts +1 -0
  138. package/src/runtime/main.js +90 -0
  139. package/src/runtime/modules.d.ts +23 -0
  140. package/src/runtime/modules.js +53 -0
  141. package/src/runtime/port.d.ts +8 -0
  142. package/src/runtime/port.js +46 -0
  143. package/src/runtime/questions.d.ts +24 -0
  144. package/src/runtime/questions.js +162 -0
  145. package/src/runtime/recut.d.ts +81 -0
  146. package/src/runtime/recut.js +325 -0
  147. package/src/runtime/render.d.ts +80 -0
  148. package/src/runtime/render.js +358 -0
  149. package/src/runtime/retouch/ask.d.ts +17 -0
  150. package/src/runtime/retouch/ask.js +171 -0
  151. package/src/runtime/retouch/entry.d.ts +77 -0
  152. package/src/runtime/retouch/entry.js +1 -0
  153. package/src/runtime/retouch/judge.d.ts +25 -0
  154. package/src/runtime/retouch/judge.js +209 -0
  155. package/src/runtime/retouch/look.d.ts +39 -0
  156. package/src/runtime/retouch/look.js +135 -0
  157. package/src/runtime/retouch/own-styles.d.ts +19 -0
  158. package/src/runtime/retouch/own-styles.js +141 -0
  159. package/src/runtime/retouch/parts.d.ts +22 -0
  160. package/src/runtime/retouch/parts.js +166 -0
  161. package/src/runtime/retouch/retouch.d.ts +37 -0
  162. package/src/runtime/retouch/retouch.js +238 -0
  163. package/src/runtime/retouch/seat.d.ts +40 -0
  164. package/src/runtime/retouch/seat.js +228 -0
  165. package/src/runtime/retouch/state.d.ts +37 -0
  166. package/src/runtime/retouch/state.js +153 -0
  167. package/src/runtime/retouch/type-style.d.ts +19 -0
  168. package/src/runtime/retouch/type-style.js +111 -0
  169. package/src/runtime/scan.d.ts +2 -0
  170. package/src/runtime/scan.js +49 -0
  171. package/src/runtime/scenes/card.d.ts +12 -0
  172. package/src/runtime/scenes/card.js +56 -0
  173. package/src/runtime/scenes/install.d.ts +69 -0
  174. package/src/runtime/scenes/install.js +528 -0
  175. package/src/runtime/scenes/read.d.ts +27 -0
  176. package/src/runtime/scenes/read.js +73 -0
  177. package/src/runtime/scenes/scoped.d.ts +13 -0
  178. package/src/runtime/scenes/scoped.js +46 -0
  179. package/src/runtime/score.d.ts +32 -0
  180. package/src/runtime/score.js +262 -0
  181. package/src/runtime/sketch/pen.d.ts +3 -0
  182. package/src/runtime/sketch/pen.js +371 -0
  183. package/src/runtime/sketch/strokes.d.ts +41 -0
  184. package/src/runtime/sketch/strokes.js +187 -0
  185. package/src/runtime/snapshot/draw.d.ts +14 -0
  186. package/src/runtime/snapshot/draw.js +125 -0
  187. package/src/runtime/snapshot/hold-first-draw.d.ts +12 -0
  188. package/src/runtime/snapshot/hold-first-draw.js +128 -0
  189. package/src/runtime/snapshot/lift.d.ts +41 -0
  190. package/src/runtime/snapshot/lift.js +161 -0
  191. package/src/runtime/snapshot/plate.d.ts +20 -0
  192. package/src/runtime/snapshot/plate.js +79 -0
  193. package/src/runtime/snapshot/serialize.d.ts +51 -0
  194. package/src/runtime/snapshot/serialize.js +286 -0
  195. package/src/runtime/snapshot/styles.d.ts +8 -0
  196. package/src/runtime/snapshot/styles.js +109 -0
  197. package/src/runtime/snapshot/xml.d.ts +6 -0
  198. package/src/runtime/snapshot/xml.js +110 -0
  199. package/src/runtime/stage-size.d.ts +7 -0
  200. package/src/runtime/stage-size.js +3 -0
  201. package/src/runtime/stage.d.ts +27 -0
  202. package/src/runtime/stage.js +154 -0
  203. package/src/runtime/stretch.d.ts +13 -0
  204. package/src/runtime/stretch.js +16 -0
  205. package/src/runtime/texts.d.ts +24 -0
  206. package/src/runtime/texts.js +211 -0
  207. package/src/runtime/video-sync.d.ts +51 -0
  208. package/src/runtime/video-sync.js +218 -0
  209. package/src/stills.d.ts +90 -0
  210. package/src/stills.js +329 -0
  211. package/src/tools/film.d.ts +13 -0
  212. package/src/tools/film.js +116 -0
  213. package/src/tools/levels.d.ts +8 -0
  214. package/src/tools/levels.js +28 -0
  215. package/src/tools/main.d.ts +1 -0
  216. package/src/tools/main.js +223 -0
  217. package/src/tools/score.d.ts +4 -0
  218. package/src/tools/score.js +35 -0
  219. package/src/tools/types.d.ts +84 -0
  220. package/src/tools/types.js +2 -0
  221. package/src/tools.d.ts +6 -0
  222. package/src/tools.js +4 -0
  223. package/src/virtual.d.ts +11 -0
  224. package/src/vite.d.ts +8 -0
  225. package/src/vite.js +43 -0
@@ -0,0 +1,53 @@
1
+ export declare const SKIP: RegExp;
2
+ export declare const PHRASE: RegExp;
3
+ export declare const UNIT: RegExp;
4
+ /** A g holds parts, each other tag is one part. Whatever else stands in an svg (defs, a mask, a nested svg) is passed over. */
5
+ export declare const ART: RegExp;
6
+ /** The parts that paint themselves. */
7
+ export declare const SHAPE: RegExp;
8
+ /** The two colours of a shape a person can change, each with the property it is laid as. */
9
+ export declare const PAINT: {
10
+ readonly svgfill: "fill";
11
+ readonly svgstroke: "stroke";
12
+ };
13
+ export type PaintKey = keyof typeof PAINT;
14
+ export declare const PAINT_KEYS: readonly PaintKey[];
15
+ /** The element's own inline style, where it has one. */
16
+ export declare function styleOf(el: Element): CSSStyleDeclaration | null;
17
+ /** A rough scene's pen strokes, which are no thing of the film's. */
18
+ export declare const isPen: (node: Node) => boolean;
19
+ /** The held picture of the scene before, laid over the stage while a scene comes on: the player's, never a layer. */
20
+ export declare const HELD_ATTRIBUTE = "data-film-held";
21
+ export declare const isHeld: (node: Node) => boolean;
22
+ /**
23
+ * The film's own elements under `el`: a thing is known by its place among them. A caption is passed over: the stage's
24
+ * own goes to the end only after a frame is drawn, so it can stand ahead of what the film added meanwhile.
25
+ */
26
+ export declare function kidsOf(el: Element | Node): Element[];
27
+ export declare function alphaOf(colour: string): number;
28
+ /** It paints a box: a background, a shadow or a border that shows. Read inside `inOwnColors`. */
29
+ export declare function paints(cs: CSSStyleDeclaration, el: Element): boolean;
30
+ /** A part of an svg drawing. The kit's hand-drawn marks are none: their order and number differ from runner to runner. */
31
+ export declare const isPart: (el: Element | Node | null) => el is Element;
32
+ export declare const isArtWords: (el: Element) => boolean;
33
+ /**
34
+ * What an element's own attributes say of how it is drawn: tag, id, classes, link and paint, not its shape or place,
35
+ * which most films change from frame to frame. `blur`: numbers in its id and classes count for nothing.
36
+ */
37
+ export declare function saidOf(el: Element, blur?: boolean): string;
38
+ /** The same of a part and all the parts under it. `memo` lasts while the stage stands as drawn. */
39
+ export declare function drawnAs(el: Element, blur: boolean, memo: Map<Element, string>): string;
40
+ /** A paint shows at all: a colour or a pattern, not see-through. */
41
+ export declare function showsPaint(paint: string, opacity: string): boolean;
42
+ /** A filled shape, or a use of one: only such a part can be the Background. */
43
+ export declare function fills(cs: CSSStyleDeclaration, el: Element): boolean;
44
+ /** A use, an image, a foreignObject and a g read as one thing always count: what they show is not theirs to paint. */
45
+ export declare function inks(cs: CSSStyleDeclaration, el: Element): boolean;
46
+ export declare function ownText(el: Element): boolean;
47
+ /** A line of words: text, and nothing under it but spans and the like. Spans that paint with no text beside them are things of their own. */
48
+ export declare function isWords(el: Element): boolean;
49
+ /** A declared value that uses a var(), with each fallback taken out that uses none itself; null: it uses none, or a var() is not closed. */
50
+ export declare function drawnValue(text: string): string | null;
51
+ /** What of a person's change is laid on the element (the retouch marks). */
52
+ export declare const laidOn: (el: Element, what: string) => boolean;
53
+ export declare const hiddenByHand: (el: Element) => boolean;
@@ -0,0 +1,158 @@
1
+ /*
2
+ * The parts of a thing on the picture that both the reading of the layers and a person's changes by hand go by.
3
+ * A thing is one element of the film's; inside an inline svg, a part of the drawing.
4
+ */
5
+ export const SKIP = /^(style|script|template|link|meta|title)$/i;
6
+ export const PHRASE = /^(span|em|b|i|strong|u|a|br|small|sub|sup|mark|s|code|wbr|tspan)$/i;
7
+ export const UNIT = /^(img|svg|canvas|video|picture)$/i;
8
+ /** A g holds parts, each other tag is one part. Whatever else stands in an svg (defs, a mask, a nested svg) is passed over. */
9
+ export const ART = /^(g|path|rect|circle|ellipse|line|polyline|polygon|text|use|image|foreignObject)$/i;
10
+ /** The parts that paint themselves. */
11
+ export const SHAPE = /^(path|rect|circle|ellipse|line|polyline|polygon)$/i;
12
+ /** The two colours of a shape a person can change, each with the property it is laid as. */
13
+ export const PAINT = { svgfill: 'fill', svgstroke: 'stroke' };
14
+ export const PAINT_KEYS = ['svgfill', 'svgstroke'];
15
+ const SVG_NS = 'http://www.w3.org/2000/svg';
16
+ const SIDES = ['top', 'right', 'bottom', 'left'];
17
+ /** The element's own inline style, where it has one. */
18
+ export function styleOf(el) {
19
+ return el instanceof HTMLElement || el instanceof SVGElement ? el.style : null;
20
+ }
21
+ /** A rough scene's pen strokes, which are no thing of the film's. */
22
+ export const isPen = (node) => node instanceof Element && node.hasAttribute('data-sketch-pen');
23
+ /** The held picture of the scene before, laid over the stage while a scene comes on: the player's, never a layer. */
24
+ export const HELD_ATTRIBUTE = 'data-film-held';
25
+ export const isHeld = (node) => node instanceof Element && node.hasAttribute(HELD_ATTRIBUTE);
26
+ /**
27
+ * The film's own elements under `el`: a thing is known by its place among them. A caption is passed over: the stage's
28
+ * own goes to the end only after a frame is drawn, so it can stand ahead of what the film added meanwhile.
29
+ */
30
+ export function kidsOf(el) {
31
+ const out = [];
32
+ if (!(el instanceof Element))
33
+ return out;
34
+ for (let child = el.firstElementChild; child; child = child.nextElementSibling)
35
+ if (!isPen(child) && !isHeld(child) && !SKIP.test(child.tagName) && !child.classList.contains('film-caption') && !child.hasAttribute('data-film-title') && !child.hasAttribute('data-film-placed'))
36
+ out.push(child);
37
+ return out;
38
+ }
39
+ export function alphaOf(colour) {
40
+ if (!colour || colour === 'transparent')
41
+ return 0;
42
+ const rgba = /^rgba\((.+)\)$/.exec(colour);
43
+ const slash = colour.indexOf('/');
44
+ return rgba ? parseFloat(rgba[1].split(',')[3] ?? '1') : slash > 0 ? parseFloat(colour.slice(slash + 1)) : 1;
45
+ }
46
+ /** It paints a box: a background, a shadow or a border that shows. Read inside `inOwnColors`. */
47
+ export function paints(cs, el) {
48
+ if (/\b(edge|fill)\b/.test(el.getAttribute('data-sketch') ?? ''))
49
+ return true;
50
+ const set = (value) => !!value && value !== 'none';
51
+ const inWords = cs.backgroundClip === 'text' || cs.getPropertyValue('-webkit-background-clip') === 'text';
52
+ if (set(cs.boxShadow) || (!inWords && (set(cs.backgroundImage) || alphaOf(cs.backgroundColor) > 0.03)))
53
+ return true;
54
+ return SIDES.some((side) => parseFloat(cs.getPropertyValue(`border-${side}-width`)) > 0 &&
55
+ cs.getPropertyValue(`border-${side}-style`) !== 'none' &&
56
+ alphaOf(cs.getPropertyValue(`border-${side}-color`)) > 0.03);
57
+ }
58
+ /** A part of an svg drawing. The kit's hand-drawn marks are none: their order and number differ from runner to runner. */
59
+ export const isPart = (el) => el instanceof Element && el.namespaceURI === SVG_NS && ART.test(el.tagName) && !el.hasAttribute('data-film-mark');
60
+ export const isArtWords = (el) => isPart(el) && /^text$/i.test(el.tagName);
61
+ /**
62
+ * What an element's own attributes say of how it is drawn: tag, id, classes, link and paint, not its shape or place,
63
+ * which most films change from frame to frame. `blur`: numbers in its id and classes count for nothing.
64
+ */
65
+ export function saidOf(el, blur = false) {
66
+ const own = el.id + ' ' + (el.getAttribute('class') ?? '');
67
+ const style = styleOf(el);
68
+ return [el.tagName, blur ? own.replace(/\d+/g, '#') : own]
69
+ .concat(['href', 'fill', 'stroke', 'stroke-width', 'color'].map((name) => el.getAttribute(name) ?? ''))
70
+ .concat(style ? [style.fill, style.stroke, style.color] : [])
71
+ .join(' ');
72
+ }
73
+ /** The same of a part and all the parts under it. `memo` lasts while the stage stands as drawn. */
74
+ export function drawnAs(el, blur, memo) {
75
+ const known = memo.get(el);
76
+ if (known !== undefined)
77
+ return known;
78
+ const out = saidOf(el, blur) +
79
+ kidsOf(el)
80
+ .filter(isPart)
81
+ .map((child) => '(' + drawnAs(child, blur, memo) + ')')
82
+ .join('');
83
+ memo.set(el, out);
84
+ return out;
85
+ }
86
+ /** A paint shows at all: a colour or a pattern, not see-through. */
87
+ export function showsPaint(paint, opacity) {
88
+ const o = parseFloat(opacity);
89
+ return !!paint && paint !== 'none' && (/^url\(/.test(paint) ? 1 : alphaOf(paint)) * (isNaN(o) ? 1 : o) > 0.03;
90
+ }
91
+ /** A filled shape, or a use of one: only such a part can be the Background. */
92
+ export function fills(cs, el) {
93
+ if (/^use$/i.test(el.tagName)) {
94
+ const id = (el.getAttribute('href') ?? el.getAttribute('xlink:href') ?? '').slice(1);
95
+ const to = id ? el.ownerDocument.getElementById(id) : null;
96
+ if (to)
97
+ return !/^use$/i.test(to.tagName) && fills(getComputedStyle(to), to);
98
+ }
99
+ return !/^(g|use|image|foreignObject|line)$/i.test(el.tagName) && showsPaint(cs.fill, cs.fillOpacity);
100
+ }
101
+ /** A use, an image, a foreignObject and a g read as one thing always count: what they show is not theirs to paint. */
102
+ export function inks(cs, el) {
103
+ return /^(g|use|image|foreignObject)$/i.test(el.tagName) || fills(cs, el) || (parseFloat(cs.strokeWidth) > 0 && showsPaint(cs.stroke, cs.strokeOpacity));
104
+ }
105
+ export function ownText(el) {
106
+ for (let node = el.firstChild; node; node = node.nextSibling)
107
+ if (node instanceof Text && /\S/.test(node.data))
108
+ return true;
109
+ return false;
110
+ }
111
+ /** A line of words: text, and nothing under it but spans and the like. Spans that paint with no text beside them are things of their own. */
112
+ export function isWords(el) {
113
+ // kit.h's holder has no box, so what is in it is read for itself.
114
+ if (styleOf(el)?.display === 'contents')
115
+ return false;
116
+ const all = el.getElementsByTagName('*');
117
+ // The tag first: it settles nearly every case, and a walk up to look for a pen is dear.
118
+ for (const each of Array.from(all))
119
+ if (!PHRASE.test(each.tagName) && !each.closest('[data-sketch-pen]'))
120
+ return false;
121
+ if (!/\S/.test(el.textContent ?? ''))
122
+ return false;
123
+ if (ownText(el))
124
+ return true;
125
+ for (const each of Array.from(all))
126
+ if (PHRASE.test(each.tagName) && paints(getComputedStyle(each), each))
127
+ return false;
128
+ return true;
129
+ }
130
+ /** A declared value that uses a var(), with each fallback taken out that uses none itself; null: it uses none, or a var() is not closed. */
131
+ export function drawnValue(text) {
132
+ if (!/var\(/i.test(text))
133
+ return null;
134
+ let out = '';
135
+ let any = false;
136
+ for (let i = 0; i < text.length;) {
137
+ const found = /[\w-]/.test(text[i - 1] ?? '') ? null : /^var\(\s*(--[^\s,)]+)\s*/i.exec(text.slice(i));
138
+ if (!found) {
139
+ out += text[i++];
140
+ continue;
141
+ }
142
+ let deep = 1;
143
+ let j = i + 4;
144
+ for (; j < text.length && deep; j++)
145
+ deep += text[j] === '(' ? 1 : text[j] === ')' ? -1 : 0;
146
+ if (deep)
147
+ return null;
148
+ const rest = text.slice(i + found[0].length, j - 1);
149
+ const back = rest[0] === ',' ? drawnValue(rest.slice(1).trim()) : null;
150
+ out += 'var(' + found[1] + (back ? ', ' + back : '') + ')';
151
+ i = j;
152
+ any = true;
153
+ }
154
+ return any ? out : null;
155
+ }
156
+ /** What of a person's change is laid on the element (the retouch marks). */
157
+ export const laidOn = (el, what) => (el.getAttribute('data-film-laid') ?? '').split(' ').includes(what);
158
+ export const hiddenByHand = (el) => laidOn(el, 'hidden');
@@ -0,0 +1,4 @@
1
+ import type { Stretch } from './describe.js';
2
+ import type { Item, Layer } from './item.js';
3
+ /** The rows of a reading, in the order they come on, the ground last, before the cut of what each shows. */
4
+ export declare function buildRows(s: Stretch, els: Map<string, Item>): Layer[];
@@ -0,0 +1,233 @@
1
+ import { beneath, inOrder, lead, measures, stays } from "./describe.js";
2
+ import { MOST, pinned } from "./item.js";
3
+ import { SHAPE, drawnAs } from "./parts.js";
4
+ import { markOdd } from "./walk.js";
5
+ const ALIKE = 4;
6
+ const BRIEF_S = 0.15;
7
+ const MOST_KIDS = 12;
8
+ /** The rows of a reading, in the order they come on, the ground last, before the cut of what each shows. */
9
+ export function buildRows(s, els) {
10
+ const { W, H, from, to } = s;
11
+ // Inside an svg the rows follow the drawing's own tree.
12
+ const below = new Map();
13
+ const all = new Map();
14
+ for (const it of els.values())
15
+ if (it.art)
16
+ below.set(it.up, (below.get(it.up) ?? []).concat(it));
17
+ /** All that is drawn of it: a g that was shut in the course of the reading counts with the parts read before that. */
18
+ const inked = (it) => {
19
+ let got = all.get(it);
20
+ if (!got) {
21
+ got = (below.get(it) ?? []).reduce((some, c) => some.concat(inked(c)), it.cand && it.shown ? [it] : []).sort(inOrder);
22
+ all.set(it, got);
23
+ }
24
+ return got;
25
+ };
26
+ const { isFull, swelled, grown, describe } = measures(s, inked);
27
+ const heads = new Map();
28
+ const order = [];
29
+ for (const it of els.values()) {
30
+ if (!it.cand || it.shown === 0 || it.art)
31
+ continue;
32
+ /*
33
+ * It belongs to the nearest thing above it that moves, that the film named, that paints a box round it, or that a
34
+ * person changed or hid; unless it is such a thing itself. A thing as large as the stage looks for no holder, and is
35
+ * no holder, unless a hand-set Scale made it that large.
36
+ */
37
+ let head = it;
38
+ if ((!isFull(it) || grown(it)) && !it.moved && !it.named && !(it.easel && it.big && !beneath(it)))
39
+ for (let up = it.up; up; up = up.up)
40
+ if ((!isFull(up) || swelled(up) || grown(up)) && (up.moved || up.named || up.paint || stays(up))) {
41
+ head = up;
42
+ break;
43
+ }
44
+ let group = heads.get(head);
45
+ if (!group) {
46
+ group = [];
47
+ heads.set(head, group);
48
+ order.push(head);
49
+ }
50
+ group.push(it);
51
+ it.head = head;
52
+ }
53
+ order.sort(inOrder);
54
+ const lasting = (l) => l.long >= Math.min(BRIEF_S, (to - from) / 4);
55
+ let list = order
56
+ .map((head) => {
57
+ const parts = (heads.get(head) ?? []).sort(inOrder);
58
+ const l = describe(head, parts);
59
+ /*
60
+ * What it holds, without the box it paints round them. A full row lists up to MOST of those, and each of them lists
61
+ * what it holds in turn; a kid that holds things also has a row of its own under the same id.
62
+ */
63
+ const under = (p) => {
64
+ const k = describe(p, [p]);
65
+ const own = (heads.get(p) ?? []).filter((q) => q !== p);
66
+ if (own.length && !(own.length === 1 && own[0]?.easel))
67
+ k.kids = own
68
+ .sort(inOrder)
69
+ .map(under)
70
+ .filter(lasting)
71
+ .filter((c, i) => i < MOST || pinned(c));
72
+ return k;
73
+ };
74
+ if (parts.length > 1)
75
+ l.kids = parts
76
+ .filter((p) => p !== head)
77
+ .map(l.full ? under : (p) => describe(p, [p]))
78
+ .filter(lasting)
79
+ .filter((k, i) => i < (l.full ? MOST : MOST_KIDS) || (pinned(k) && (l.full || !(heads.get(k.it) ?? []).some((q) => q !== k.it))));
80
+ return l;
81
+ })
82
+ .filter(lasting);
83
+ // Four or more alike side by side (a grid's cells, a list's rows) are one layer, which holds them.
84
+ const drawnNow = new Map();
85
+ const alike = (l) => l.kind === 'ground'
86
+ ? null
87
+ : l.it.path.slice(0, -1).join('.') +
88
+ '|' +
89
+ l.kind +
90
+ '|' +
91
+ (l.it.el.getAttribute('class') ?? '').replace(/\d+/g, '#') +
92
+ '|' +
93
+ l.it.el.tagName +
94
+ (l.it.art ? '|' + (l.name.replace(/\d+/g, '#') || drawnAs(l.it.el, true, drawnNow)) : '');
95
+ const fold = (rows) => {
96
+ const folded = [];
97
+ const packs = new Map();
98
+ for (const l of rows) {
99
+ const k = alike(l);
100
+ if (k)
101
+ packs.set(k, (packs.get(k) ?? []).concat(l));
102
+ }
103
+ for (const l of rows) {
104
+ const k = alike(l);
105
+ const pack = k ? (packs.get(k) ?? [l]) : [l];
106
+ if (pack.length < ALIKE) {
107
+ folded.push(l);
108
+ continue;
109
+ }
110
+ if (pack[0] !== l)
111
+ continue;
112
+ let every = [];
113
+ for (const p of pack) {
114
+ every = every.concat(p.parts);
115
+ if (!p.it.art && !p.full)
116
+ p.kids = p.kids.filter(pinned);
117
+ }
118
+ const g = describe(l.it, every);
119
+ // "*": the pack, as against its first member, whose place and tag it is called by.
120
+ g.id += '*';
121
+ g.pack = true;
122
+ g.kind = 'group';
123
+ g.round = false;
124
+ g.drawn = '';
125
+ g.full = false;
126
+ g.name = pack.every((p) => p.name === l.name) ? l.name : '';
127
+ g.many = pack.length;
128
+ g.keep = pack.some(pinned);
129
+ g.at = pack[pack.length - 1]?.at ?? g.at;
130
+ g.kids = l.it.art ? pack : pack.filter((p, i) => i < MOST_KIDS || pinned(p));
131
+ folded.push(g);
132
+ }
133
+ return folded;
134
+ };
135
+ // A speck that is on at no look has no row; one that only begins so (a line that grows) has.
136
+ for (const it of els.values())
137
+ if (it.speck && !it.shown)
138
+ markOdd(it);
139
+ const heldBy = (it) => (below.get(it) ?? []).filter((c) => inked(c).length).sort(inOrder);
140
+ const groups = (c) => heldBy(c).some((x) => !x.cand);
141
+ /*
142
+ * A g that is no thing on the picture, like any wrapper: at some look as large as the stage; or over half of it and
143
+ * holding other groups (a camera, a world); or alone in its holder, if it holds groups itself or its holder has a row.
144
+ */
145
+ const wraps = (c, alone, bare) => !c.cand && !stays(c) && (c.big || (groups(c) && c.most >= (W * H) / 2) || (alone && (!bare || groups(c))));
146
+ /*
147
+ * A row takes what it holds, if that is more than one thing or must keep its row. A g that holds only things alike
148
+ * stands for them, as a pack does; an svg does not. sole: the one shape that is all a row holds, unless a person hid it.
149
+ */
150
+ const hold = (l, held) => {
151
+ let kids = held;
152
+ const only = kids[0];
153
+ if (l.it.art && kids.length === 1 && only?.pack) {
154
+ l.many = only.many;
155
+ kids = only.kids;
156
+ }
157
+ const one = kids[0];
158
+ if (kids.length === 1 && one && !one.pack && SHAPE.test(one.it.el.tagName) && !one.it.own)
159
+ l.sole = one;
160
+ else if (kids.length > 1 || kids.some((k) => k.pack || pinned(k)))
161
+ l.kids = kids;
162
+ return l;
163
+ };
164
+ const rowsIn = (up, bare) => {
165
+ const held = heldBy(up);
166
+ return held
167
+ .reduce((rows, c) => {
168
+ if (wraps(c, held.length === 1, bare))
169
+ return rows.concat(rowsIn(c, bare));
170
+ const l = describe(c, inked(c));
171
+ const only = heldBy(c);
172
+ const sole = only.length === 1 ? only[0] : undefined;
173
+ if (sole)
174
+ l.name = l.name || describe(sole, l.parts).name;
175
+ return rows.concat(hold(l, c.easel ? fold(rowsIn(c, false)) : []));
176
+ }, [])
177
+ .filter(lasting);
178
+ };
179
+ /*
180
+ * An svg as large as the stage is such a wrapper too, if what it holds fits the list beside the other rows: else its
181
+ * row stays and holds them ('drawing'). A smaller one keeps its row, which holds its parts.
182
+ */
183
+ const wide = (l) => !!l.it.easel && l.it.big && !stays(l.it);
184
+ let others = Math.min(MOST, fold(list.filter((l) => !wide(l))).length);
185
+ const down = (k) => k.kids.reduce((a, c) => a.concat(down(c)), [k]);
186
+ list = list.reduce((every, l) => {
187
+ let rows = wide(l) ? fold(rowsIn(l.it, true)) : [];
188
+ if (wide(l) && rows.length + others > 2 * MOST) {
189
+ hold(l, rows);
190
+ l.drawn = 'drawing';
191
+ rows = [];
192
+ others++;
193
+ }
194
+ others += rows.length;
195
+ // A box that paints round one svg has two rows under one id; each holds the svg's parts, which count once.
196
+ for (const k of down(l)) {
197
+ if (k.it.art)
198
+ continue;
199
+ const own = heads.get(k.it) ?? [];
200
+ const e = k.it.easel ? k.it : own.length === 1 && own[0]?.easel ? own[0] : null;
201
+ if (e && !k.kids.length && !rows.length) {
202
+ hold(k, fold(rowsIn(e, false)));
203
+ k.svg = e;
204
+ k.inked = inked(e).filter((p) => p !== e);
205
+ if (!k.parts.includes(e))
206
+ k.texts = k.texts
207
+ .concat(lead(k.inked.filter((p) => p.text).map((p) => p.text)))
208
+ .slice(0, MOST);
209
+ }
210
+ }
211
+ return every.concat(rows.length ? rows : l);
212
+ }, []);
213
+ const folded = fold(list);
214
+ const lvl = new Map();
215
+ // below: the level at which the box's row will stand once a change pins it under what holds it.
216
+ for (const p of folded) {
217
+ lvl.set(p.it, 1);
218
+ if (p.pack)
219
+ for (const m of p.kids)
220
+ lvl.set(m.it, 2);
221
+ }
222
+ for (const l of folded)
223
+ if (l.svg && l.it.head && l.it.head !== l.it)
224
+ l.below = (lvl.get(l.it.head) ?? 2) + 1;
225
+ // As they come on; the ground last.
226
+ folded.forEach((l, i) => {
227
+ l.n = i;
228
+ });
229
+ list = folded.sort((a, b) => Number(a.kind === 'ground') - Number(b.kind === 'ground') || (a.spans[0]?.[0] ?? 0) - (b.spans[0]?.[0] ?? 0) || a.n - b.n);
230
+ // MOST of them, what is pinned first, and beside those the rows of drawings, which were let in only as far as they fit.
231
+ let room = MOST - list.filter((l) => !l.it.art && pinned(l)).length;
232
+ return list.filter((l) => l.it.art || pinned(l) || room-- > 0);
233
+ }
@@ -0,0 +1,24 @@
1
+ import type { LayersReport } from '../../protocol.js';
2
+ import type { LookSys } from './describe.js';
3
+ export interface ScanSys extends LookSys {
4
+ stage: HTMLElement;
5
+ /** Draws a played moment at once; throws where it cannot. */
6
+ render(t: number): void;
7
+ /** The record's entries for the stretch on show that find nothing. */
8
+ lost(): string[];
9
+ /** Of those, the hides whose thing is hidden by another entry all the same. */
10
+ underHide(): string[];
11
+ }
12
+ export interface LayersAsk {
13
+ seq: number;
14
+ from: number;
15
+ to: number;
16
+ at: number;
17
+ scene: string | null;
18
+ }
19
+ export declare const forgetReading: () => void;
20
+ /**
21
+ * Reads the layers of a stretch: what is on the picture, when, how it comes and goes, and how the film draws it at the
22
+ * moment on show. `gone`: a newer question has come, or none is wanted any more; the reading then ends with null.
23
+ */
24
+ export declare function scanLayers(d: LayersAsk, sys: ScanSys, gone: () => boolean): Promise<LayersReport | null>;