@phil65/demoreel 0.0.0-stage → 0.1.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 (93) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +163 -2
  3. package/THIRD_PARTY_NOTICES.md +31 -0
  4. package/dist/args.d.ts +41 -0
  5. package/dist/args.js +230 -0
  6. package/dist/cli.d.ts +2 -0
  7. package/dist/cli.js +279 -0
  8. package/dist/compose.d.ts +73 -0
  9. package/dist/compose.js +144 -0
  10. package/dist/env.d.ts +38 -0
  11. package/dist/env.js +182 -0
  12. package/dist/idle.d.ts +42 -0
  13. package/dist/idle.js +97 -0
  14. package/dist/index.d.ts +14 -0
  15. package/dist/index.js +13 -0
  16. package/dist/init.d.ts +19 -0
  17. package/dist/init.js +92 -0
  18. package/dist/layout.d.ts +52 -0
  19. package/dist/layout.js +55 -0
  20. package/dist/load.d.ts +2 -0
  21. package/dist/load.js +76 -0
  22. package/dist/marks.d.ts +69 -0
  23. package/dist/marks.js +152 -0
  24. package/dist/motion.d.ts +15 -0
  25. package/dist/motion.js +49 -0
  26. package/dist/openscreen/project.js +793 -0
  27. package/dist/openscreen.d.ts +14 -0
  28. package/dist/openscreen.js +41 -0
  29. package/dist/project.d.ts +143 -0
  30. package/dist/project.js +144 -0
  31. package/dist/record.d.ts +53 -0
  32. package/dist/record.js +111 -0
  33. package/dist/recorder.d.ts +40 -0
  34. package/dist/recorder.js +141 -0
  35. package/dist/render.d.ts +58 -0
  36. package/dist/render.js +139 -0
  37. package/dist/renderer/assets/CanvasPool-CHSHS1-v.js +23 -0
  38. package/dist/renderer/assets/Cursor_App-Starting-zEGhqPJj.svg +8 -0
  39. package/dist/renderer/assets/Cursor_Cross-BuZZnB_U.svg +5 -0
  40. package/dist/renderer/assets/Cursor_Default-DkmrqhKh.svg +5 -0
  41. package/dist/renderer/assets/Cursor_Hand-(Grabbing)-B-Qy-RsV.svg +5 -0
  42. package/dist/renderer/assets/Cursor_Hand-(Open)-DGrW1tFF.svg +5 -0
  43. package/dist/renderer/assets/Cursor_Hand-(Pointing)-Byy2KbtA.svg +5 -0
  44. package/dist/renderer/assets/Cursor_Help-D5NcyFpT.svg +8 -0
  45. package/dist/renderer/assets/Cursor_Move-CerM5f-0.svg +5 -0
  46. package/dist/renderer/assets/Cursor_Not-Allowed-3rttFVa5.svg +7 -0
  47. package/dist/renderer/assets/Cursor_Resize-North-East-South-West-CBd4tbCA.svg +5 -0
  48. package/dist/renderer/assets/Cursor_Resize-North-South-DOxgUIwF.svg +5 -0
  49. package/dist/renderer/assets/Cursor_Resize-North-West-South-East-hzXJFJ2_.svg +5 -0
  50. package/dist/renderer/assets/Cursor_Resize-West-East-rDJgc6AZ.svg +5 -0
  51. package/dist/renderer/assets/Cursor_Text-Cursor-Cn9rFLjY.svg +5 -0
  52. package/dist/renderer/assets/Cursor_Up-Arrow-CYyEN-dA.svg +4 -0
  53. package/dist/renderer/assets/Cursor_Wait-CK8tq-9y.svg +6 -0
  54. package/dist/renderer/assets/RenderTargetSystem-EAUH9iQk.js +404 -0
  55. package/dist/renderer/assets/browserAll-aHn2isHo.js +14 -0
  56. package/dist/renderer/assets/canvasUtils-n5g2f3_X.js +1 -0
  57. package/dist/renderer/assets/getTexelRangeRects-yD6MQ0xy.js +195 -0
  58. package/dist/renderer/assets/getTextureBatchBindGroup-Bwvgbco6.js +1 -0
  59. package/dist/renderer/assets/gif.worker-CjkyQP34.js +3 -0
  60. package/dist/renderer/assets/index-BwP6rH7I.js +556 -0
  61. package/dist/renderer/assets/init-C2Za5NQh.js +83 -0
  62. package/dist/renderer/assets/webworkerAll-JSSmbaR2.js +1 -0
  63. package/dist/renderer/index.html +13 -0
  64. package/dist/renderer/wallpapers/wallpaper1.jpg +0 -0
  65. package/dist/renderer/wallpapers/wallpaper12.jpg +0 -0
  66. package/dist/renderer/wallpapers/wallpaper5.jpg +0 -0
  67. package/dist/renderer/wasm/web-demuxer.wasm +0 -0
  68. package/dist/scene.d.ts +147 -0
  69. package/dist/scene.js +441 -0
  70. package/dist/server.d.ts +12 -0
  71. package/dist/server.js +116 -0
  72. package/dist/sheet.d.ts +37 -0
  73. package/dist/sheet.js +98 -0
  74. package/dist/types.d.ts +102 -0
  75. package/dist/types.js +2 -0
  76. package/dist/zoom.d.ts +55 -0
  77. package/dist/zoom.js +172 -0
  78. package/examples/demo-app/index.html +99 -0
  79. package/examples/local-demo.ts +21 -0
  80. package/licenses/colord.txt +21 -0
  81. package/licenses/earcut.txt +15 -0
  82. package/licenses/eventemitter3.txt +21 -0
  83. package/licenses/gif.js.txt +1 -0
  84. package/licenses/ismobilejs.txt +21 -0
  85. package/licenses/mediabunny.txt +373 -0
  86. package/licenses/motion-dom.txt +21 -0
  87. package/licenses/motion-utils.txt +21 -0
  88. package/licenses/openscreen.txt +21 -0
  89. package/licenses/parse-svg-path.txt +23 -0
  90. package/licenses/pixi-filters.txt +21 -0
  91. package/licenses/pixi.js.txt +21 -0
  92. package/licenses/web-demuxer.txt +21 -0
  93. package/package.json +74 -4
@@ -0,0 +1,69 @@
1
+ import { type NormRect, type StageLayout } from "./layout.ts";
2
+ import { type LookOptions } from "./project.ts";
3
+ import type { ActionRecord, Caption, SpeedRegion, TrimRegion, Viewport, ZoomRegion } from "./types.ts";
4
+ export interface MarkPoint {
5
+ t: number;
6
+ x: number;
7
+ y: number;
8
+ label?: string | null;
9
+ kind?: string | null;
10
+ duration?: number;
11
+ }
12
+ export interface MarkRegion {
13
+ start: number;
14
+ end: number;
15
+ x?: number | null;
16
+ y?: number | null;
17
+ w?: number | null;
18
+ h?: number | null;
19
+ label?: string | null;
20
+ kind?: string | null;
21
+ }
22
+ export interface MarkSpan extends MarkRegion {
23
+ label: string;
24
+ }
25
+ export interface Marks {
26
+ frame?: {
27
+ width: number;
28
+ height: number;
29
+ } | null;
30
+ points: MarkPoint[];
31
+ regions: MarkRegion[];
32
+ spans: MarkSpan[];
33
+ }
34
+ export interface MarksInput {
35
+ viewport: Viewport;
36
+ durationMs: number;
37
+ actions: ActionRecord[];
38
+ captions: Caption[];
39
+ zoomRegions: ZoomRegion[];
40
+ trimRegions?: TrimRegion[];
41
+ speedRegions?: SpeedRegion[];
42
+ layout: StageLayout;
43
+ look: Pick<LookOptions, "captionPosition">;
44
+ }
45
+ export interface TargetRect {
46
+ action: ActionRecord;
47
+ /** Recording ms. */
48
+ startMs: number;
49
+ endMs: number;
50
+ /** Output-frame rect (clipped), sampled once the cursor has landed. */
51
+ rect: NormRect;
52
+ }
53
+ /** Action target boxes in output-frame coordinates (padding + zoom camera applied). */
54
+ export declare function targetRects(input: Pick<MarksInput, "actions" | "viewport" | "layout" | "zoomRegions">): TargetRect[];
55
+ /**
56
+ * Resolves `captionPosition: "auto"`: bottom, unless the caption would cover a target active
57
+ * while it is shown (with 400 ms slack); then top, if that overlaps less.
58
+ */
59
+ export declare function placeCaptions(captions: Caption[], targets: TargetRect[], position: LookOptions["captionPosition"]): Caption[];
60
+ /** Approximate zoom progress (0-1) of a region at recording time t. */
61
+ export declare function zoomProgress(r: ZoomRegion, t: number): number;
62
+ /** The camera at time t: the dominant zoom region and its progress. */
63
+ export declare function cameraAt(regions: ZoomRegion[], t: number): {
64
+ region: ZoomRegion;
65
+ p: number;
66
+ } | null;
67
+ /** Stage rect -> output-frame rect under the camera at time t (OpenScreen computeZoomTransform). */
68
+ export declare function applyCamera(rect: NormRect, regions: ZoomRegion[], t: number): NormRect;
69
+ export declare function buildMarks(input: MarksInput): Marks;
package/dist/marks.js ADDED
@@ -0,0 +1,152 @@
1
+ /**
2
+ * framesheet marks (schema: github.com/phil65/framesheet/schema/marks.schema.json) for the
3
+ * rendered video: clicks as points, action targets / highlights / zooms as regions, captions as
4
+ * spans. Times are seconds of the *output* (after trim/speed regions); coordinates are
5
+ * fractions of the output frame, i.e. mapped through the padding layout and the zoom camera,
6
+ * so `framesheet inspect out.mp4 --marks marks.json` draws them where they appear.
7
+ */
8
+ import { sourceToOutputMs } from "./idle.js";
9
+ import { clipUnit, DEPTH_SCALES, boxToStage, clampFocus, toStage } from "./layout.js";
10
+ import { captionRect } from "./project.js";
11
+ /** Action target boxes in output-frame coordinates (padding + zoom camera applied). */
12
+ export function targetRects(input) {
13
+ const out = [];
14
+ for (const a of input.actions) {
15
+ if (!a.box || a.kind === "zoom")
16
+ continue;
17
+ // Sample the camera once the cursor has landed (zoom is then (nearly) complete).
18
+ const t = Math.min(a.endMs, a.arriveMs + 300);
19
+ const rect = clipUnit(applyCamera(boxToStage(input.layout, input.viewport, a.box), input.zoomRegions, t));
20
+ if (rect)
21
+ out.push({ action: a, startMs: a.kind === "highlight" ? a.startMs : a.arriveMs, endMs: a.endMs, rect });
22
+ }
23
+ return out;
24
+ }
25
+ const overlapArea = (a, b) => Math.max(0, Math.min(a.x + a.w, b.x + b.w) - Math.max(a.x, b.x)) * Math.max(0, Math.min(a.y + a.h, b.y + b.h) - Math.max(a.y, b.y));
26
+ /**
27
+ * Resolves `captionPosition: "auto"`: bottom, unless the caption would cover a target active
28
+ * while it is shown (with 400 ms slack); then top, if that overlaps less.
29
+ */
30
+ export function placeCaptions(captions, targets, position) {
31
+ return captions.map((c) => {
32
+ if (position !== "auto")
33
+ return { ...c, position };
34
+ const active = targets.filter((t) => t.endMs >= c.startMs - 400 && t.startMs <= c.endMs + 400);
35
+ const cost = (p) => {
36
+ const r = captionRect(p);
37
+ const box = { x: r.x / 100, y: r.y / 100, w: r.width / 100, h: r.height / 100 };
38
+ return active.reduce((n, t) => n + overlapArea(t.rect, box), 0);
39
+ };
40
+ const bottom = cost("bottom");
41
+ return { ...c, position: bottom > 0 && cost("top") < bottom ? "top" : "bottom" };
42
+ });
43
+ }
44
+ const ZOOM_IN_BEFORE_MS = 1022;
45
+ const ZOOM_IN_AFTER_MS = 500;
46
+ const ZOOM_OUT_MS = 1016;
47
+ const smooth = (x) => {
48
+ const t = Math.min(1, Math.max(0, x));
49
+ return t * t * (3 - 2 * t);
50
+ };
51
+ /** Approximate zoom progress (0-1) of a region at recording time t. */
52
+ export function zoomProgress(r, t) {
53
+ const inStart = r.startMs - ZOOM_IN_BEFORE_MS;
54
+ if (t <= inStart || t >= r.endMs + ZOOM_OUT_MS)
55
+ return 0;
56
+ if (t < r.startMs + ZOOM_IN_AFTER_MS)
57
+ return smooth((t - inStart) / (ZOOM_IN_BEFORE_MS + ZOOM_IN_AFTER_MS));
58
+ if (t <= r.endMs)
59
+ return 1;
60
+ return 1 - smooth((t - r.endMs) / ZOOM_OUT_MS);
61
+ }
62
+ /** The camera at time t: the dominant zoom region and its progress. */
63
+ export function cameraAt(regions, t) {
64
+ let best = null;
65
+ for (const r of regions) {
66
+ const p = zoomProgress(r, t);
67
+ if (p > 0 && (!best || p > best.p))
68
+ best = { region: r, p };
69
+ }
70
+ return best;
71
+ }
72
+ /** Stage rect -> output-frame rect under the camera at time t (OpenScreen computeZoomTransform). */
73
+ export function applyCamera(rect, regions, t) {
74
+ const cam = cameraAt(regions, t);
75
+ if (!cam)
76
+ return rect;
77
+ const s = DEPTH_SCALES[cam.region.depth];
78
+ const f = clampFocus(cam.region.focus, s);
79
+ const scale = 1 + (s - 1) * cam.p;
80
+ const ox = (0.5 - f.cx * s) * cam.p;
81
+ const oy = (0.5 - f.cy * s) * cam.p;
82
+ return { x: rect.x * scale + ox, y: rect.y * scale + oy, w: rect.w * scale, h: rect.h * scale };
83
+ }
84
+ const r4 = (v) => Math.round(v * 10000) / 10000;
85
+ const r3 = (v) => Math.round(v * 1000) / 1000;
86
+ function describe(a) {
87
+ const what = a.label ?? (a.text ? `"${a.text}"` : undefined);
88
+ return what ? `${a.kind} ${what}` : a.kind;
89
+ }
90
+ export function buildMarks(input) {
91
+ const { viewport: vp, layout, zoomRegions: zr } = input;
92
+ const out = (ms) => r3(Math.max(0, sourceToOutputMs(ms, input.trimRegions, input.speedRegions)) / 1000);
93
+ const endS = out(input.durationMs);
94
+ const box = (rect) => (rect ? { x: r4(rect.x), y: r4(rect.y), w: r4(rect.w), h: r4(rect.h) } : null);
95
+ const marks = { points: [], regions: [], spans: [] };
96
+ for (const t of targetRects(input)) {
97
+ const start = out(t.startMs);
98
+ marks.regions.push({
99
+ start,
100
+ end: Math.min(endS, Math.max(start, out(t.endMs))),
101
+ ...box(t.rect),
102
+ label: describe(t.action),
103
+ kind: t.action.kind === "highlight" ? "highlight" : "target",
104
+ });
105
+ }
106
+ for (const a of input.actions) {
107
+ if (a.point && (a.kind === "click" || a.kind === "type")) {
108
+ const t = a.kind === "click" ? a.endMs : a.arriveMs;
109
+ const p = applyCamera({ ...toStage(layout, vp, a.point), w: 0, h: 0 }, zr, t);
110
+ if (p.x >= 0 && p.x <= 1 && p.y >= 0 && p.y <= 1) {
111
+ marks.points.push({
112
+ t: Math.min(endS, out(t)),
113
+ x: r4(p.x),
114
+ y: r4(p.y),
115
+ label: describe(a),
116
+ kind: a.kind,
117
+ ...(a.kind === "type" ? { duration: r3(Math.max(0, out(a.endMs) - out(a.arriveMs))) } : {}),
118
+ });
119
+ }
120
+ }
121
+ }
122
+ for (const z of zr) {
123
+ const start = out(z.startMs);
124
+ marks.regions.push({
125
+ start,
126
+ end: Math.max(start, Math.min(endS, out(z.endMs))),
127
+ label: `zoom ${DEPTH_SCALES[z.depth]}x (${z.source ?? "auto"})`,
128
+ kind: "zoom",
129
+ });
130
+ }
131
+ for (const s of input.speedRegions ?? []) {
132
+ marks.regions.push({ start: out(s.startMs), end: out(s.endMs), label: `${s.speed}x`, kind: "speed" });
133
+ }
134
+ for (const cap of input.captions) {
135
+ const c = captionRect(cap.position ?? input.look.captionPosition);
136
+ const start = out(cap.startMs);
137
+ marks.spans.push({
138
+ start,
139
+ end: Math.max(start, Math.min(endS, out(cap.endMs))),
140
+ label: cap.text,
141
+ kind: "caption",
142
+ x: c.x / 100,
143
+ y: c.y / 100,
144
+ w: c.width / 100,
145
+ h: c.height / 100,
146
+ });
147
+ }
148
+ marks.points.sort((a, b) => a.t - b.t);
149
+ marks.regions.sort((a, b) => a.start - b.start);
150
+ marks.spans.sort((a, b) => a.start - b.start);
151
+ return marks;
152
+ }
@@ -0,0 +1,15 @@
1
+ /** Human-like cursor paths: eased cubic Bezier with a slight arc, duration from distance (Fitts-ish). */
2
+ export interface Point {
3
+ x: number;
4
+ y: number;
5
+ }
6
+ export declare function easeInOutCubic(t: number): number;
7
+ /** Ease that accelerates quickly and settles slowly, which reads as "aimed" movement. */
8
+ export declare function easeOutQuint(t: number): number;
9
+ export declare function easeAimed(t: number): number;
10
+ /** Movement duration in ms for a given distance and target size. */
11
+ export declare function travelDuration(distance: number, targetSize?: number, speed?: number): number;
12
+ /** Deterministic pseudo-random so re-renders of a scenario produce the same motion. */
13
+ export declare function mulberry32(seed: number): () => number;
14
+ export declare function makePath(from: Point, to: Point, rand: () => number): (t: number) => Point;
15
+ export declare const sleep: (ms: number) => Promise<unknown>;
package/dist/motion.js ADDED
@@ -0,0 +1,49 @@
1
+ /** Human-like cursor paths: eased cubic Bezier with a slight arc, duration from distance (Fitts-ish). */
2
+ export function easeInOutCubic(t) {
3
+ return t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2;
4
+ }
5
+ /** Ease that accelerates quickly and settles slowly, which reads as "aimed" movement. */
6
+ export function easeOutQuint(t) {
7
+ return 1 - (1 - t) ** 5;
8
+ }
9
+ export function easeAimed(t) {
10
+ // blend: smooth start (cubic in-out) with a long settle (quint out)
11
+ return 0.45 * easeInOutCubic(t) + 0.55 * easeOutQuint(t);
12
+ }
13
+ /** Movement duration in ms for a given distance and target size. */
14
+ export function travelDuration(distance, targetSize = 40, speed = 1) {
15
+ if (distance < 2)
16
+ return 0;
17
+ const fitts = 260 + 170 * Math.log2(distance / Math.max(targetSize, 8) + 1);
18
+ return Math.round(Math.min(1400, Math.max(320, fitts)) / speed);
19
+ }
20
+ /** Deterministic pseudo-random so re-renders of a scenario produce the same motion. */
21
+ export function mulberry32(seed) {
22
+ let a = seed >>> 0;
23
+ return () => {
24
+ a = (a + 0x6d2b79f5) >>> 0;
25
+ let t = a;
26
+ t = Math.imul(t ^ (t >>> 15), t | 1);
27
+ t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
28
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
29
+ };
30
+ }
31
+ export function makePath(from, to, rand) {
32
+ const dx = to.x - from.x;
33
+ const dy = to.y - from.y;
34
+ const dist = Math.hypot(dx, dy);
35
+ // perpendicular unit vector
36
+ const nx = dist > 0 ? -dy / dist : 0;
37
+ const ny = dist > 0 ? dx / dist : 0;
38
+ const arc = dist * (0.06 + rand() * 0.08) * (rand() < 0.5 ? -1 : 1);
39
+ const c1 = { x: from.x + dx * 0.3 + nx * arc, y: from.y + dy * 0.3 + ny * arc };
40
+ const c2 = { x: from.x + dx * 0.75 + nx * arc * 0.4, y: from.y + dy * 0.75 + ny * arc * 0.4 };
41
+ return (t) => {
42
+ const u = 1 - t;
43
+ return {
44
+ x: u * u * u * from.x + 3 * u * u * t * c1.x + 3 * u * t * t * c2.x + t * t * t * to.x,
45
+ y: u * u * u * from.y + 3 * u * u * t * c1.y + 3 * u * t * t * c2.y + t * t * t * to.y,
46
+ };
47
+ };
48
+ }
49
+ export const sleep = (ms) => new Promise((r) => setTimeout(r, Math.max(0, ms)));