@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,100 @@
1
+ import { eo, lerp, seg } from "./math.js";
2
+ const SEPARATORS = ".,'’   ";
3
+ const RUN = /\d+(?:[.,'’   ]\d+)*/g;
4
+ const SPLIT = /[.,'’   ]/;
5
+ const MOST_DIGITS = 15;
6
+ /** Every part after the first is three digits, and the first is one to three digits that is not a leading zero. */
7
+ const inThrees = (parts) => parts.length > 1 && (parts[0] ?? '').length <= 3 && !(parts[0] ?? '').startsWith('0') && parts.slice(1).every((part) => part.length === 3);
8
+ /** How a run of digits and separators reads: its whole digits, thousands separator, decimal mark and decimals; null when it is no one number. */
9
+ function readRun(run) {
10
+ const parts = run.split(SPLIT);
11
+ const marks = [...run].filter((char) => SEPARATORS.includes(char));
12
+ if (marks.length === 0)
13
+ return { whole: run, group: '', mark: '', decimals: '' };
14
+ const last = marks[marks.length - 1] ?? '';
15
+ const decimalMark = last === '.' || last === ',';
16
+ // "3.142" and "0,125": one mark that cannot be a thousands separator is a decimal mark.
17
+ if (marks.length === 1 && decimalMark && (last === '.' || !inThrees(parts)))
18
+ return { whole: parts[0] ?? '', group: '', mark: last, decimals: parts[1] ?? '' };
19
+ if (marks.every((char) => char === last) && inThrees(parts))
20
+ return { whole: parts.join(''), group: last, mark: '', decimals: '' };
21
+ const groups = marks.slice(0, -1);
22
+ const group = groups[0] ?? '';
23
+ if (decimalMark && group !== last && groups.every((char) => char === group) && inThrees(parts.slice(0, -1)))
24
+ return { whole: parts.slice(0, -1).join(''), group, mark: last, decimals: parts[parts.length - 1] ?? '' };
25
+ return null;
26
+ }
27
+ /**
28
+ * The figure in `text`, or null where there is none to count: no number or more than one, one joined to a word (Q3,
29
+ * B2B), a label (Top 10), an ordinal (1st), more than fifteen digits, or a year standing alone (2026) unless `years`.
30
+ */
31
+ export function readFigure(text, years = false) {
32
+ const runs = [...text.matchAll(RUN)];
33
+ const found = runs[0];
34
+ if (runs.length !== 1 || found === undefined)
35
+ return null;
36
+ const read = readRun(found[0]);
37
+ if (read === null || read.whole.length + read.decimals.length > MOST_DIGITS)
38
+ return null;
39
+ let before = text.slice(0, found.index);
40
+ const after = text.slice(found.index + found[0].length);
41
+ const sign = before.endsWith('-') || before.endsWith('−') ? before.slice(-1) : '';
42
+ if (sign)
43
+ before = before.slice(0, -1);
44
+ if (/[\p{L}\p{N}]$/u.test(before))
45
+ return null;
46
+ if ((before.match(/\p{L}/gu) ?? []).length > 2)
47
+ return null;
48
+ if (/^(st|nd|rd|th)(?!\p{L})/iu.test(after))
49
+ return null;
50
+ const value = Number(read.whole + (read.decimals ? '.' + read.decimals : '')) * (sign ? -1 : 1);
51
+ // A year stands alone: nothing after it but the end of the line or a stop, and no currency before it.
52
+ const lonely = /^(?:\s*$|[.,;:!?)\]"'’”])/u.test(after) && !/\p{Sc}/u.test(before);
53
+ if (!years && !sign && !read.group && !read.decimals && read.whole.length === 4 && value >= 1900 && value <= 2100 && lonely)
54
+ return null;
55
+ return {
56
+ before,
57
+ sign,
58
+ group: read.group,
59
+ mark: read.mark,
60
+ places: read.decimals.length,
61
+ after,
62
+ value,
63
+ pad: read.whole.length > 1 && read.whole.startsWith('0') ? read.whole.length : 0,
64
+ };
65
+ }
66
+ /** `value` written as the figure is: its places, separators, padding and the words around it. Never "-0". */
67
+ export function writeFigure(figure, value) {
68
+ const [whole = '0', decimals = ''] = Math.abs(value).toFixed(figure.places).split('.');
69
+ const digits = whole.padStart(figure.pad, '0');
70
+ const grouped = figure.group ? digits.replace(/\B(?=(\d{3})+$)/g, figure.group) : digits;
71
+ const negative = value < 0 && /[1-9]/.test(whole + decimals);
72
+ return figure.before + (negative ? figure.sign || '-' : '') + grouped + (decimals ? figure.mark + decimals : '') + figure.after;
73
+ }
74
+ const counted = new WeakMap();
75
+ /**
76
+ * Counts the figure in `el`'s words from `from` to itself between t0 and t1, and gives what it shows. Its words are
77
+ * read the first time; words that something else writes later (a person's retype) are read again. An element with
78
+ * child elements, or words with no figure, is never written to. Anything not a finite number shows the words.
79
+ */
80
+ export function count(el, t, t0, t1, options = {}) {
81
+ if (el === null || typeof el !== 'object' || typeof el.textContent !== 'string')
82
+ return '';
83
+ const now = el.textContent;
84
+ const leaves = el.children.length === 0;
85
+ let kept = counted.get(el);
86
+ if (kept === undefined || (now !== kept.text && now !== kept.shown)) {
87
+ kept = { text: now, figure: leaves ? readFigure(now, options.from !== undefined && options.from !== null) : null, shown: now };
88
+ counted.set(el, kept);
89
+ }
90
+ const { figure } = kept;
91
+ const x = t1 > t0 ? seg(t, t0, t1) : 1;
92
+ const ease = typeof options.ease === 'function' ? options.ease : eo;
93
+ const from = options.from !== undefined && options.from !== null ? Number(options.from) : figure ? figure.value / 2 : NaN;
94
+ const value = figure !== null && x < 1 ? lerp(from, figure.value, ease(x)) : NaN;
95
+ const shown = figure !== null && Math.abs(value) < 1e15 ? writeFigure(figure, value) : kept.text;
96
+ if (figure !== null && leaves && el.textContent !== shown)
97
+ el.textContent = shown;
98
+ kept.shown = shown;
99
+ return shown;
100
+ }
@@ -0,0 +1,46 @@
1
+ import type { Point } from './paper.js';
2
+ export declare const CURSOR_ARROW = "<svg width=\"30\" height=\"30\" viewBox=\"0 0 24 24\"><path d=\"M5.2 2.9v17.4l4.3-4.1 2.7 6.2 2.9-1.25-2.65-6.05h5.85z\" fill=\"#111\" stroke=\"#fff\" stroke-width=\"1.35\" stroke-linejoin=\"round\"/></svg>";
3
+ export declare const CURSOR_EW = "<svg width=\"46\" height=\"46\" viewBox=\"0 0 24 24\" style=\"margin:-23px 0 0 -23px\"><path d=\"M2.5 12l4.2-4.2v2.7h10.6V7.8L21.5 12l-4.2 4.2v-2.7H6.7v2.7z\" fill=\"#111\" stroke=\"#fff\" stroke-width=\"1.2\" stroke-linejoin=\"round\"/></svg>";
4
+ export declare const CURSOR_NESW = "<svg width=\"46\" height=\"46\" viewBox=\"0 0 24 24\" style=\"margin:-23px 0 0 -23px\"><g transform=\"rotate(-45 12 12)\"><path d=\"M2.5 12l4.2-4.2v2.7h10.6V7.8L21.5 12l-4.2 4.2v-2.7H6.7v2.7z\" fill=\"#111\" stroke=\"#fff\" stroke-width=\"1.2\" stroke-linejoin=\"round\"/></g></svg>";
5
+ export declare const CURSOR_NWSE = "<svg width=\"46\" height=\"46\" viewBox=\"0 0 24 24\" style=\"margin:-23px 0 0 -23px\"><g transform=\"rotate(45 12 12)\"><path d=\"M2.5 12l4.2-4.2v2.7h10.6V7.8L21.5 12l-4.2 4.2v-2.7H6.7v2.7z\" fill=\"#111\" stroke=\"#fff\" stroke-width=\"1.2\" stroke-linejoin=\"round\"/></g></svg>";
6
+ export declare const CURSOR_COPY = "<svg width=\"40\" height=\"40\" viewBox=\"0 0 32 32\"><path d=\"M5.2 2.9v17.4l4.3-4.1 2.7 6.2 2.9-1.25-2.65-6.05h5.85z\" fill=\"#111\" stroke=\"#fff\" stroke-width=\"1.35\" stroke-linejoin=\"round\"/><circle cx=\"22.5\" cy=\"22\" r=\"7\" fill=\"#34c84a\" stroke=\"#fff\" stroke-width=\"1.6\"/><path d=\"M22.5 18.2v7.6M18.7 22h7.6\" stroke=\"#fff\" stroke-width=\"2\" stroke-linecap=\"round\"/></svg>";
7
+ export declare const CURSOR_TEXT = "<svg width=\"30\" height=\"34\" viewBox=\"0 0 24 28\" style=\"margin:-17px 0 0 -12px\"><path d=\"M8 3h3.2c.5 0 .8.3.8.8V24.2c0 .5-.3.8-.8.8H8M16 3h-3.2c-.5 0-.8.3-.8.8M16 25h-3.2c-.5 0-.8-.3-.8-.8M9.5 14h5\" fill=\"none\" stroke=\"#fff\" stroke-width=\"3.2\" stroke-linecap=\"round\"/><path d=\"M8 3h3.2c.5 0 .8.3.8.8V24.2c0 .5-.3.8-.8.8H8M16 3h-3.2c-.5 0-.8.3-.8.8M16 25h-3.2c-.5 0-.8-.3-.8-.8M9.5 14h5\" fill=\"none\" stroke=\"#111\" stroke-width=\"1.3\" stroke-linecap=\"round\"/></svg>";
8
+ /** `kit.cursors`: glyphs a film passes to `kit.cursor(...)` or a cursor's `shapes`. */
9
+ export declare const CURSORS: {
10
+ readonly arrow: "<svg width=\"30\" height=\"30\" viewBox=\"0 0 24 24\"><path d=\"M5.2 2.9v17.4l4.3-4.1 2.7 6.2 2.9-1.25-2.65-6.05h5.85z\" fill=\"#111\" stroke=\"#fff\" stroke-width=\"1.35\" stroke-linejoin=\"round\"/></svg>";
11
+ readonly ew: "<svg width=\"46\" height=\"46\" viewBox=\"0 0 24 24\" style=\"margin:-23px 0 0 -23px\"><path d=\"M2.5 12l4.2-4.2v2.7h10.6V7.8L21.5 12l-4.2 4.2v-2.7H6.7v2.7z\" fill=\"#111\" stroke=\"#fff\" stroke-width=\"1.2\" stroke-linejoin=\"round\"/></svg>";
12
+ readonly nesw: "<svg width=\"46\" height=\"46\" viewBox=\"0 0 24 24\" style=\"margin:-23px 0 0 -23px\"><g transform=\"rotate(-45 12 12)\"><path d=\"M2.5 12l4.2-4.2v2.7h10.6V7.8L21.5 12l-4.2 4.2v-2.7H6.7v2.7z\" fill=\"#111\" stroke=\"#fff\" stroke-width=\"1.2\" stroke-linejoin=\"round\"/></g></svg>";
13
+ readonly nwse: "<svg width=\"46\" height=\"46\" viewBox=\"0 0 24 24\" style=\"margin:-23px 0 0 -23px\"><g transform=\"rotate(45 12 12)\"><path d=\"M2.5 12l4.2-4.2v2.7h10.6V7.8L21.5 12l-4.2 4.2v-2.7H6.7v2.7z\" fill=\"#111\" stroke=\"#fff\" stroke-width=\"1.2\" stroke-linejoin=\"round\"/></g></svg>";
14
+ readonly copy: "<svg width=\"40\" height=\"40\" viewBox=\"0 0 32 32\"><path d=\"M5.2 2.9v17.4l4.3-4.1 2.7 6.2 2.9-1.25-2.65-6.05h5.85z\" fill=\"#111\" stroke=\"#fff\" stroke-width=\"1.35\" stroke-linejoin=\"round\"/><circle cx=\"22.5\" cy=\"22\" r=\"7\" fill=\"#34c84a\" stroke=\"#fff\" stroke-width=\"1.6\"/><path d=\"M22.5 18.2v7.6M18.7 22h7.6\" stroke=\"#fff\" stroke-width=\"2\" stroke-linecap=\"round\"/></svg>";
15
+ readonly text: "<svg width=\"30\" height=\"34\" viewBox=\"0 0 24 28\" style=\"margin:-17px 0 0 -12px\"><path d=\"M8 3h3.2c.5 0 .8.3.8.8V24.2c0 .5-.3.8-.8.8H8M16 3h-3.2c-.5 0-.8.3-.8.8M16 25h-3.2c-.5 0-.8-.3-.8-.8M9.5 14h5\" fill=\"none\" stroke=\"#fff\" stroke-width=\"3.2\" stroke-linecap=\"round\"/><path d=\"M8 3h3.2c.5 0 .8.3.8.8V24.2c0 .5-.3.8-.8.8H8M16 3h-3.2c-.5 0-.8.3-.8.8M16 25h-3.2c-.5 0-.8-.3-.8-.8M9.5 14h5\" fill=\"none\" stroke=\"#111\" stroke-width=\"1.3\" stroke-linecap=\"round\"/></svg>";
16
+ };
17
+ /** A cursor for the stage: a press ring and a glyph, the arrow or the SVG markup the film passes. */
18
+ export declare function cursorElement(glyph: string | undefined): HTMLElement;
19
+ export interface CursorKey {
20
+ t: number;
21
+ at: Point | (() => Point);
22
+ /** How far the path bows sideways, as a share of its length. */
23
+ bow?: number;
24
+ /** Move at an even pace instead of easing. */
25
+ lin?: boolean;
26
+ }
27
+ export interface CursorShape {
28
+ spans: Array<[number, number]>;
29
+ gfx: string;
30
+ }
31
+ /** keys [{t, at, bow?, lin?}], clicks [t…], holds [[a, b]…], ewSpans and shapes pick the glyph. */
32
+ export declare class Cursor {
33
+ el: HTMLElement;
34
+ gfx: HTMLElement | null;
35
+ ring: HTMLElement | null;
36
+ keys: CursorKey[];
37
+ clicks: number[];
38
+ holds: Array<[number, number]>;
39
+ ewSpans: Array<[number, number]>;
40
+ shapes: CursorShape[];
41
+ cur: string;
42
+ visible: (t: number) => number;
43
+ constructor(el: HTMLElement);
44
+ pos(t: number): Point;
45
+ render(t: number): void;
46
+ }
@@ -0,0 +1,108 @@
1
+ import { eio, eo, lerp, seg } from "./math.js";
2
+ export const CURSOR_ARROW = `<svg width="30" height="30" viewBox="0 0 24 24"><path d="M5.2 2.9v17.4l4.3-4.1 2.7 6.2 2.9-1.25-2.65-6.05h5.85z" fill="#111" stroke="#fff" stroke-width="1.35" stroke-linejoin="round"/></svg>`;
3
+ const DOUBLE_ARROW = `<path d="M2.5 12l4.2-4.2v2.7h10.6V7.8L21.5 12l-4.2 4.2v-2.7H6.7v2.7z" fill="#111" stroke="#fff" stroke-width="1.2" stroke-linejoin="round"/>`;
4
+ export const CURSOR_EW = `<svg width="46" height="46" viewBox="0 0 24 24" style="margin:-23px 0 0 -23px">${DOUBLE_ARROW}</svg>`;
5
+ export const CURSOR_NESW = `<svg width="46" height="46" viewBox="0 0 24 24" style="margin:-23px 0 0 -23px"><g transform="rotate(-45 12 12)">${DOUBLE_ARROW}</g></svg>`;
6
+ export const CURSOR_NWSE = `<svg width="46" height="46" viewBox="0 0 24 24" style="margin:-23px 0 0 -23px"><g transform="rotate(45 12 12)">${DOUBLE_ARROW}</g></svg>`;
7
+ export const CURSOR_COPY = `<svg width="40" height="40" viewBox="0 0 32 32"><path d="M5.2 2.9v17.4l4.3-4.1 2.7 6.2 2.9-1.25-2.65-6.05h5.85z" fill="#111" stroke="#fff" stroke-width="1.35" stroke-linejoin="round"/><circle cx="22.5" cy="22" r="7" fill="#34c84a" stroke="#fff" stroke-width="1.6"/><path d="M22.5 18.2v7.6M18.7 22h7.6" stroke="#fff" stroke-width="2" stroke-linecap="round"/></svg>`;
8
+ const I_BEAM = 'M8 3h3.2c.5 0 .8.3.8.8V24.2c0 .5-.3.8-.8.8H8M16 3h-3.2c-.5 0-.8.3-.8.8M16 25h-3.2c-.5 0-.8-.3-.8-.8M9.5 14h5';
9
+ export const CURSOR_TEXT = `<svg width="30" height="34" viewBox="0 0 24 28" style="margin:-17px 0 0 -12px"><path d="${I_BEAM}" fill="none" stroke="#fff" stroke-width="3.2" stroke-linecap="round"/><path d="${I_BEAM}" fill="none" stroke="#111" stroke-width="1.3" stroke-linecap="round"/></svg>`;
10
+ /** `kit.cursors`: glyphs a film passes to `kit.cursor(...)` or a cursor's `shapes`. */
11
+ export const CURSORS = {
12
+ arrow: CURSOR_ARROW,
13
+ ew: CURSOR_EW,
14
+ nesw: CURSOR_NESW,
15
+ nwse: CURSOR_NWSE,
16
+ copy: CURSOR_COPY,
17
+ text: CURSOR_TEXT,
18
+ };
19
+ /** A cursor for the stage: a press ring and a glyph, the arrow or the SVG markup the film passes. */
20
+ export function cursorElement(glyph) {
21
+ const box = document.createElement('div');
22
+ box.className = 'film-cursor';
23
+ box.style.cssText = 'position:absolute;left:0;top:0;width:0;height:0;z-index:2147483646;pointer-events:none';
24
+ box.innerHTML =
25
+ '<div class="cursor-ring" style="position:absolute;left:-22px;top:-22px;width:44px;height:44px;border-radius:50%;border:3px solid rgba(20,20,19,.55);opacity:0"></div>' +
26
+ '<div class="cursor-gfx" style="position:absolute;left:-4px;top:-3px;transform-origin:4px 3px">' +
27
+ (glyph || CURSOR_ARROW) +
28
+ '</div>';
29
+ return box;
30
+ }
31
+ /** keys [{t, at, bow?, lin?}], clicks [t…], holds [[a, b]…], ewSpans and shapes pick the glyph. */
32
+ export class Cursor {
33
+ el;
34
+ gfx;
35
+ ring;
36
+ keys = [];
37
+ clicks = [];
38
+ holds = [];
39
+ ewSpans = [];
40
+ shapes = [];
41
+ cur = '';
42
+ visible = () => 1;
43
+ constructor(el) {
44
+ this.el = el;
45
+ this.gfx = el.querySelector('.cursor-gfx');
46
+ this.ring = el.querySelector('.cursor-ring');
47
+ }
48
+ pos(t) {
49
+ const keys = this.keys;
50
+ const place = (key) => (typeof key.at === 'function' ? key.at() : key.at);
51
+ const first = keys[0];
52
+ const last = keys[keys.length - 1];
53
+ if (!first || !last)
54
+ return [-100, -100];
55
+ if (t <= first.t)
56
+ return place(first);
57
+ for (let i = 0; i < keys.length - 1; i++) {
58
+ const a = keys[i];
59
+ const b = keys[i + 1];
60
+ if (!a || !b || !(t >= a.t && t < b.t))
61
+ continue;
62
+ const p = b.lin ? seg(t, a.t, b.t) : eio(seg(t, a.t, b.t));
63
+ const from = place(a);
64
+ const to = place(b);
65
+ let x = lerp(from[0], to[0], p);
66
+ let y = lerp(from[1], to[1], p);
67
+ if (b.bow) {
68
+ const bend = Math.sin(Math.PI * p) * b.bow;
69
+ x += -(to[1] - from[1]) * bend;
70
+ y += (to[0] - from[0]) * bend;
71
+ }
72
+ return [x, y];
73
+ }
74
+ return place(last);
75
+ }
76
+ render(t) {
77
+ const opacity = this.visible(t);
78
+ this.el.style.display = opacity > 0.001 ? '' : 'none';
79
+ if (opacity <= 0.001)
80
+ return;
81
+ const [x, y] = this.pos(t);
82
+ this.el.style.opacity = String(opacity);
83
+ this.el.style.transform = `translate(${x}px, ${y}px)`;
84
+ const within = ([a, b]) => t >= a && t < b;
85
+ const shape = this.shapes.find((s) => s.spans.some(within));
86
+ const glyph = shape ? shape.gfx : this.ewSpans.some(within) ? CURSOR_EW : CURSOR_ARROW;
87
+ if (glyph !== this.cur && this.gfx) {
88
+ this.gfx.innerHTML = glyph;
89
+ this.cur = glyph;
90
+ }
91
+ let press = 0;
92
+ let ringAge = 9;
93
+ for (const click of this.clicks) {
94
+ const age = t - click;
95
+ if (age >= 0 && age < ringAge)
96
+ ringAge = age;
97
+ if (age >= -0.04 && age < 0.14)
98
+ press = 1;
99
+ }
100
+ const held = this.holds.some(within);
101
+ if (this.gfx)
102
+ this.gfx.style.transform = `scale(${press || held ? 0.86 : 1})`;
103
+ if (this.ring) {
104
+ this.ring.style.opacity = String(ringAge < 0.4 ? 0.55 * (1 - ringAge / 0.4) : 0);
105
+ this.ring.style.transform = `scale(${lerp(0.35, 1, eo(ringAge / 0.4))})`;
106
+ }
107
+ }
108
+ }
@@ -0,0 +1,14 @@
1
+ export interface ElementProps {
2
+ class?: string;
3
+ style?: string | Record<string, string>;
4
+ text?: string;
5
+ html?: string;
6
+ attrs?: Record<string, string>;
7
+ [property: string]: unknown;
8
+ }
9
+ /**
10
+ * The element `html` makes, or for several roots a box-less parent holding them all: display:contents leaves
11
+ * a flex or grid parent's layout alone, and a fragment would empty once appended. A trailing `<style>` is dropped.
12
+ */
13
+ export declare function h(html: string): Element | null;
14
+ export declare function el(tag: string, props?: ElementProps | null, children?: Array<Node | string | null | undefined>): HTMLElement;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * The element `html` makes, or for several roots a box-less parent holding them all: display:contents leaves
3
+ * a flex or grid parent's layout alone, and a fragment would empty once appended. A trailing `<style>` is dropped.
4
+ */
5
+ export function h(html) {
6
+ const template = document.createElement('template');
7
+ template.innerHTML = String(html).trim();
8
+ const content = template.content;
9
+ const drawn = [...content.children].filter((child) => !/^(style|script)$/i.test(child.tagName));
10
+ if (content.childElementCount < 2 || (drawn.length < 2 && drawn[0] === content.firstElementChild))
11
+ return content.firstElementChild;
12
+ const holder = document.createElement('div');
13
+ holder.style.display = 'contents';
14
+ holder.setAttribute('data-kit-holder', '');
15
+ holder.appendChild(content);
16
+ return holder;
17
+ }
18
+ export function el(tag, props = null, children = []) {
19
+ const node = document.createElement(tag);
20
+ for (const [key, value] of Object.entries(props ?? {})) {
21
+ if (value === null || value === undefined)
22
+ continue;
23
+ if (key === 'class')
24
+ node.className = String(value);
25
+ else if (key === 'style' && typeof value === 'object') {
26
+ for (const [name, rule] of Object.entries(value))
27
+ Reflect.set(node.style, name, rule);
28
+ }
29
+ else if (key === 'style')
30
+ node.style.cssText = String(value);
31
+ else if (key === 'text')
32
+ node.textContent = String(value);
33
+ else if (key === 'html')
34
+ node.innerHTML = String(value);
35
+ else if (key === 'attrs' && typeof value === 'object') {
36
+ for (const [name, attribute] of Object.entries(value))
37
+ node.setAttribute(name, String(attribute));
38
+ }
39
+ else
40
+ Reflect.set(node, key, value);
41
+ }
42
+ for (const child of children ?? [])
43
+ if (child !== null && child !== undefined)
44
+ node.appendChild(typeof child === 'string' ? document.createTextNode(child) : child);
45
+ return node;
46
+ }
@@ -0,0 +1,24 @@
1
+ import type { CameraState } from './camera.js';
2
+ import type { Point } from './paper.js';
3
+ export interface StageRect {
4
+ x: number;
5
+ y: number;
6
+ w: number;
7
+ h: number;
8
+ }
9
+ /** A node's box in stage px, as seen: the frame's fit undone, a camera's zoom kept. */
10
+ export declare function srect(node: Element | Range): StageRect;
11
+ export declare const center: (node: Element | Range, dx?: number, dy?: number) => (() => Point);
12
+ /** A stage box as it was before a gliding camera's slant, from the box the browser reports for it. */
13
+ export declare function unslanted<Box extends StageRect>(box: Box, state: CameraState): Box;
14
+ /** A node's box in a camera's own scene space, where marks and a cursor inside the camera are placed. */
15
+ export declare const camrect: (node: Element | Range, camera: {
16
+ state: CameraState;
17
+ }) => StageRect;
18
+ /** The stage box of the last line of `phrase` inside `el`'s text, or null where it is not shown yet. */
19
+ export declare function phraseRect(el: Element | null, phrase: string): (StageRect & {
20
+ lines: number;
21
+ }) | null;
22
+ export declare function phraseCamRect(el: Element | null, phrase: string, camera: {
23
+ state: CameraState;
24
+ }): StageRect | null;
@@ -0,0 +1,56 @@
1
+ import { stageElement, stageSize } from "../stage-size.js";
2
+ const stageBox = () => stageElement()?.getBoundingClientRect() ?? new DOMRect();
3
+ /** A node's box in stage px, as seen: the frame's fit undone, a camera's zoom kept. */
4
+ export function srect(node) {
5
+ const box = node.getBoundingClientRect();
6
+ const stage = stageBox();
7
+ const k = stageSize.fit;
8
+ return { x: (box.left - stage.left) / k, y: (box.top - stage.top) / k, w: box.width / k, h: box.height / k };
9
+ }
10
+ export const center = (node, dx = 0, dy = 0) => () => {
11
+ const box = srect(node);
12
+ return [box.x + box.w / 2 + dx, box.y + box.h / 2 + dy];
13
+ };
14
+ /** A stage box as it was before a gliding camera's slant, from the box the browser reports for it. */
15
+ export function unslanted(box, state) {
16
+ const slant = state.slant;
17
+ if (slant === undefined)
18
+ return box;
19
+ const my = stageSize.height / 2;
20
+ const h = (box.h - box.w * slant.tan) / slant.taller;
21
+ return { ...box, y: my + (box.y - my - (box.x - stageSize.width / 2) * slant.tan) / slant.taller, h };
22
+ }
23
+ const unzoomed = (seen, camera) => {
24
+ const c = camera.state;
25
+ const box = unslanted(seen, c);
26
+ return { x: (box.x - c.tx) / c.z, y: (box.y - c.ty) / c.z, w: box.w / c.z, h: box.h / c.z };
27
+ };
28
+ /** A node's box in a camera's own scene space, where marks and a cursor inside the camera are placed. */
29
+ export const camrect = (node, camera) => unzoomed(srect(node), camera);
30
+ /** The stage box of the last line of `phrase` inside `el`'s text, or null where it is not shown yet. */
31
+ export function phraseRect(el, phrase) {
32
+ if (!el)
33
+ return null;
34
+ const walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT);
35
+ for (let node = walker.nextNode(); node; node = walker.nextNode()) {
36
+ const text = node instanceof Text ? node.data : '';
37
+ const index = text.indexOf(phrase);
38
+ if (index < 0)
39
+ continue;
40
+ const range = document.createRange();
41
+ range.setStart(node, index);
42
+ range.setEnd(node, index + phrase.length);
43
+ const rects = [...range.getClientRects()];
44
+ const last = rects[rects.length - 1];
45
+ if (!last)
46
+ return null;
47
+ const stage = stageBox();
48
+ const k = stageSize.fit;
49
+ return { x: (last.left - stage.left) / k, y: (last.top - stage.top) / k, w: last.width / k, h: last.height / k, lines: rects.length };
50
+ }
51
+ return null;
52
+ }
53
+ export function phraseCamRect(el, phrase, camera) {
54
+ const box = phraseRect(el, phrase);
55
+ return box ? unzoomed(box, camera) : null;
56
+ }
@@ -0,0 +1,113 @@
1
+ import type { AssetStore } from '../assets.js';
2
+ import type { StackName } from '../fonts.js';
3
+ import type { PlateOptions } from '../snapshot/plate.js';
4
+ import { Camera } from './camera.js';
5
+ import type { ChipOptions, ShowOptions, SpotlightOptions } from './chip.js';
6
+ import type { CountOptions } from './count.js';
7
+ import { CURSORS, Cursor } from './cursor.js';
8
+ import { el, h } from './dom.js';
9
+ import { camrect, center, phraseCamRect, phraseRect, srect } from './geometry.js';
10
+ import type { StageRect } from './geometry.js';
11
+ import { Marks } from './marks.js';
12
+ import * as math from './math.js';
13
+ import { cutPaper, polyLerp, polyStr } from './paper.js';
14
+ import { rng, vnoise } from './random.js';
15
+ import { TextFx } from './text-fx.js';
16
+ import { esc, streamed } from './typing.js';
17
+ import type { Typist } from './typing.js';
18
+ export declare const KIT_VERSION = 2;
19
+ export interface VideoOptions {
20
+ loop?: boolean;
21
+ /** Film seconds at which the clip comes on (in a scene, from the scene's beginning). */
22
+ start?: number;
23
+ /** The clip's own second it starts from. */
24
+ from?: number;
25
+ /** Film seconds it plays for; by default to its end. */
26
+ dur?: number;
27
+ /** Its seconds per film second, 0.25 to 4. */
28
+ speed?: number;
29
+ /** Its own sound plays too (a level from 0 to 1, or true for 1), to its scene's end at most. */
30
+ sound?: boolean | number;
31
+ /** What is said in it, `at` a second of the clip: shown over the film like the narration's captions. */
32
+ captions?: ReadonlyArray<{
33
+ at: number;
34
+ dur: number;
35
+ text: string;
36
+ }>;
37
+ /** The language its words are in, as a tag like "es"; its captions say so. */
38
+ lang?: string;
39
+ class?: string;
40
+ style?: string;
41
+ }
42
+ /**
43
+ * The cut's whole world. A film made of scenes adds `scene`, `scenes`, `score` and `narration` (scenes/install.ts);
44
+ * each scene sees a copy of it on its own clock and in its own box.
45
+ */
46
+ export interface Kit {
47
+ version: number;
48
+ readonly W: number;
49
+ readonly H: number;
50
+ readonly stage: HTMLElement;
51
+ readonly fx: CanvasRenderingContext2D;
52
+ readonly fxCanvas: HTMLCanvasElement;
53
+ el: typeof el;
54
+ h: typeof h;
55
+ esc: typeof esc;
56
+ css(text: string): HTMLStyleElement;
57
+ module(name: string): string | null;
58
+ json(name: string): unknown;
59
+ exec(name: string): void;
60
+ modules(): string[];
61
+ assets: AssetStore;
62
+ cursors: typeof CURSORS;
63
+ fonts: Record<StackName, string>;
64
+ typing: {
65
+ times: number[];
66
+ };
67
+ clamp01: typeof math.clamp01;
68
+ clamp: typeof math.clamp;
69
+ seg: typeof math.seg;
70
+ lerp: typeof math.lerp;
71
+ eo: typeof math.eo;
72
+ ei: typeof math.ei;
73
+ eio: typeof math.eio;
74
+ eoq: typeof math.eoq;
75
+ eox: typeof math.eox;
76
+ eob: typeof math.eob;
77
+ spring: typeof math.spring;
78
+ step: typeof math.step;
79
+ pulse: typeof math.pulse;
80
+ smoothstep: typeof math.smoothstep;
81
+ breathe: typeof math.breathe;
82
+ rng: typeof rng;
83
+ vnoise: typeof vnoise;
84
+ typist(text: string, start: number, cps: number, seed?: number): Typist;
85
+ streamed: typeof streamed;
86
+ srect: typeof srect;
87
+ center: typeof center;
88
+ camrect: typeof camrect;
89
+ phraseRect: typeof phraseRect;
90
+ phraseCamRect: typeof phraseCamRect;
91
+ Camera: typeof Camera;
92
+ Cursor: typeof Cursor;
93
+ Marks: typeof Marks;
94
+ TextFx: typeof TextFx;
95
+ cutPaper: typeof cutPaper;
96
+ polyLerp: typeof polyLerp;
97
+ polyStr: typeof polyStr;
98
+ video(source: string, options?: VideoOptions): HTMLVideoElement;
99
+ seek(video: HTMLVideoElement, second: number): void;
100
+ count(el: Element, t: number, t0: number, t1: number, options?: CountOptions): string;
101
+ cursor(glyph?: string): Cursor;
102
+ svgLayer(): SVGSVGElement;
103
+ chip(text: string, options?: ChipOptions): HTMLElement;
104
+ show(node: HTMLElement, t: number, tIn: number, tOut?: number | null, options?: ShowOptions): number;
105
+ spotlight(rect: StageRect | null, amount: number, options?: SpotlightOptions): void;
106
+ raster(html: string | Node, options?: PlateOptions): Promise<HTMLCanvasElement>;
107
+ plateStats(): {
108
+ count: number;
109
+ bytes: number;
110
+ };
111
+ }
112
+ export declare const typingClock: () => number[];
113
+ export declare function makeKit(): Kit;