beatsheet 0.0.0-stage → 0.2.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 (68) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +63 -2
  3. package/bin/beatsheet.js +14 -0
  4. package/bin/register-fallback.mjs +23 -0
  5. package/bin/resolve-fallback.mjs +83 -0
  6. package/package.json +45 -4
  7. package/player/env.d.ts +5 -0
  8. package/player/gallery-audio.ts +147 -0
  9. package/player/gallery-css.ts +144 -0
  10. package/player/gallery-detail.ts +385 -0
  11. package/player/gallery-music.ts +257 -0
  12. package/player/gallery-pick-state.ts +167 -0
  13. package/player/gallery-pick.ts +749 -0
  14. package/player/gallery-sounds.ts +137 -0
  15. package/player/gallery-state.ts +457 -0
  16. package/player/gallery.ts +612 -0
  17. package/player/index.html +49 -0
  18. package/player/main.ts +83 -0
  19. package/skill/SKILL.md +658 -0
  20. package/skill/examples/library/assets/tour/avatar-mk.svg +1 -0
  21. package/skill/examples/library/assets/tour/dashboard-insights.svg +1 -0
  22. package/skill/examples/library/assets/tour/dashboard.svg +1 -0
  23. package/skill/examples/library/assets/tour/settings.svg +1 -0
  24. package/skill/examples/library/library-tour.plan.md +32 -0
  25. package/skill/examples/library/library-tour.video.json +268 -0
  26. package/skill/reference/scene-techniques.md +306 -0
  27. package/skill/scripts/beats.ts +34 -0
  28. package/skill/scripts/catalogue.ts +120 -0
  29. package/skill/scripts/frames.ts +105 -0
  30. package/src/args.ts +344 -0
  31. package/src/cli.ts +95 -0
  32. package/src/commands.ts +812 -0
  33. package/src/default-project.config.ts +9 -0
  34. package/src/index.ts +47 -0
  35. package/src/packages.ts +17 -0
  36. package/src/paths.ts +32 -0
  37. package/src/project.ts +200 -0
  38. package/src/render/browser.ts +185 -0
  39. package/src/render/capture.ts +320 -0
  40. package/src/render/ffmpeg.ts +229 -0
  41. package/src/render/gif-info.ts +61 -0
  42. package/src/render/render.ts +220 -0
  43. package/src/samples.ts +557 -0
  44. package/src/server/api.ts +494 -0
  45. package/src/server/jobs.ts +210 -0
  46. package/src/server/security.ts +47 -0
  47. package/src/server/server.ts +191 -0
  48. package/src/server/sse.ts +76 -0
  49. package/src/server/static.ts +127 -0
  50. package/src/server/vite.ts +100 -0
  51. package/src/skill.ts +111 -0
  52. package/src/snap.ts +212 -0
  53. package/src/speech.ts +689 -0
  54. package/src/svg-text.ts +136 -0
  55. package/src/voicefx.ts +311 -0
  56. package/studio/3rdpartylicenses.txt +287 -0
  57. package/studio/favicon.ico +0 -0
  58. package/studio/icons/apple-touch-icon.png +0 -0
  59. package/studio/icons/icon-192.png +0 -0
  60. package/studio/icons/icon-512.png +0 -0
  61. package/studio/icons/icon.svg +1 -0
  62. package/studio/icons/maskable-512.png +0 -0
  63. package/studio/index.html +18 -0
  64. package/studio/main-KMYDBWZH.js +15 -0
  65. package/studio/manifest.webmanifest +17 -0
  66. package/studio/offline.html +92 -0
  67. package/studio/styles-NJ2CULOW.css +1 -0
  68. package/studio/sw.js +71 -0
@@ -0,0 +1,167 @@
1
+ /**
2
+ * Pure helpers of the gallery page in the studio's add-scene picker (/player/?mode=gallery&pick=1):
3
+ * URL state, the type search, keyboard moves between tiles, and the messages to and from the studio
4
+ * (GalleryToStudio / StudioToGallery in @beatsheet/core). No DOM here, so they run in Node tests
5
+ * (packages/cli/test/gallery-pick.test.ts).
6
+ */
7
+ import {
8
+ FORMATS,
9
+ type FormatId,
10
+ type GalleryToStudio,
11
+ type ResolvedSample,
12
+ type SceneType,
13
+ type StudioToGallery,
14
+ } from '@beatsheet/core';
15
+ import { sceneEntry } from './gallery-state';
16
+
17
+ /** True for the picker's URL: ?mode=gallery&pick=1. */
18
+ export function isPickMode(search: string): boolean {
19
+ const params = new URLSearchParams(search);
20
+ return params.get('mode') === 'gallery' && params.get('pick') === '1';
21
+ }
22
+
23
+ // ---------------------------------------------------------------------------
24
+ // URL state (the hash): format and search survive a hot reload of the page
25
+ // ---------------------------------------------------------------------------
26
+
27
+ export const PICK_FORMATS = Object.keys(FORMATS) as FormatId[];
28
+
29
+ export interface PickState {
30
+ format: FormatId;
31
+ query: string;
32
+ }
33
+
34
+ export function isFormatId(value: unknown): value is FormatId {
35
+ return typeof value === 'string' && (PICK_FORMATS as readonly string[]).includes(value);
36
+ }
37
+
38
+ /** '#format=4:5&q=code' -> state; unknown formats fall back to 16:9. */
39
+ export function parsePickState(hash: string): PickState {
40
+ const params = new URLSearchParams(hash.replace(/^#/, ''));
41
+ const format = params.get('format');
42
+ return { format: isFormatId(format) ? format : '16:9', query: params.get('q') ?? '' };
43
+ }
44
+
45
+ export function serializePickState(state: PickState): string {
46
+ const params = new URLSearchParams();
47
+ params.set('format', state.format);
48
+ if (state.query) params.set('q', state.query);
49
+ return `#${params.toString()}`;
50
+ }
51
+
52
+ // ---------------------------------------------------------------------------
53
+ // Search
54
+ // ---------------------------------------------------------------------------
55
+
56
+ /** The types every word of the query appears in (id, title or description), in project order. */
57
+ export function filterPickTypes(types: readonly SceneType[], query: string): SceneType[] {
58
+ const words = query.toLowerCase().split(/\s+/).filter(Boolean);
59
+ if (!words.length) return types.slice();
60
+ return types.filter((t) => {
61
+ const text = [t.id, t.title, t.description ?? ''].join(' ').toLowerCase();
62
+ return words.every((w) => text.includes(w));
63
+ });
64
+ }
65
+
66
+ // ---------------------------------------------------------------------------
67
+ // Keyboard
68
+ // ---------------------------------------------------------------------------
69
+
70
+ export interface TileRect {
71
+ left: number;
72
+ top: number;
73
+ width: number;
74
+ height: number;
75
+ }
76
+
77
+ /**
78
+ * The tile a key moves to from `current` (tiles in reading order): ArrowLeft/Right the previous or
79
+ * next, ArrowUp/Down the nearest tile (by centre x) in the row above or below, Home/End the first or
80
+ * last. Stays put at the edges; -1 when there are no tiles.
81
+ */
82
+ export function nextTileIndex(rects: readonly TileRect[], current: number, key: string): number {
83
+ const n = rects.length;
84
+ if (!n) return -1;
85
+ if (current < 0 || current >= n) return 0;
86
+ switch (key) {
87
+ case 'ArrowRight':
88
+ return Math.min(n - 1, current + 1);
89
+ case 'ArrowLeft':
90
+ return Math.max(0, current - 1);
91
+ case 'Home':
92
+ return 0;
93
+ case 'End':
94
+ return n - 1;
95
+ case 'ArrowDown':
96
+ case 'ArrowUp': {
97
+ const c = rects[current] as TileRect;
98
+ const down = key === 'ArrowDown';
99
+ const others = rects
100
+ .map((r, i) => ({ r, i }))
101
+ .filter(({ r }) => (down ? r.top >= c.top + c.height / 2 : r.top + r.height / 2 <= c.top));
102
+ if (!others.length) return current;
103
+ const rowTop = down ? Math.min(...others.map((o) => o.r.top)) : Math.max(...others.map((o) => o.r.top));
104
+ const cx = c.left + c.width / 2;
105
+ let best = -1;
106
+ let bestDist = Infinity;
107
+ for (const o of others) {
108
+ if (Math.abs(o.r.top - rowTop) > 4) continue;
109
+ const d = Math.abs(o.r.left + o.r.width / 2 - cx);
110
+ if (d < bestDist) {
111
+ best = o.i;
112
+ bestDist = d;
113
+ }
114
+ }
115
+ return best < 0 ? current : best;
116
+ }
117
+ default:
118
+ return current;
119
+ }
120
+ }
121
+
122
+ /** '1'..'9' -> the sample index on a focused tile (or -1). */
123
+ export function sampleIndexForKey(key: string, count: number): number {
124
+ if (!/^[1-9]$/.test(key)) return -1;
125
+ const i = Number(key) - 1;
126
+ return i < count ? i : -1;
127
+ }
128
+
129
+ // ---------------------------------------------------------------------------
130
+ // Labels
131
+ // ---------------------------------------------------------------------------
132
+
133
+ /** The accessible name of a tile: what it is and what Enter does. */
134
+ export function tileLabel(type: Pick<SceneType, 'title' | 'id'>, sample: Pick<ResolvedSample, 'title' | 'id'>, samples: number): string {
135
+ const which = sample.id === 'default' ? 'default sample' : `sample ${sample.title}`;
136
+ return `${type.title} (${type.id}), ${which}${samples > 1 ? `, ${samples} samples` : ''}. Enter adds it.`;
137
+ }
138
+
139
+ /** '3 beats' / '1 beat'. */
140
+ export function beatLabel(count: number): string {
141
+ return `${count} ${count === 1 ? 'beat' : 'beats'}`;
142
+ }
143
+
144
+ // ---------------------------------------------------------------------------
145
+ // Messages
146
+ // ---------------------------------------------------------------------------
147
+
148
+ /** The pick: the existing 'add-scene' message with the sample id. */
149
+ export function pickMessage(typeId: string, sample: Pick<ResolvedSample, 'id' | 'props' | 'duration'>): GalleryToStudio {
150
+ return { source: 'beatsheet-gallery', type: 'add-scene', scene: sceneEntry(typeId, sample), sampleId: sample.id };
151
+ }
152
+
153
+ /** Esc in the page: the studio closes the overlay. */
154
+ export const PICK_CLOSE: GalleryToStudio = { source: 'beatsheet-gallery', type: 'pick-close' };
155
+
156
+ /**
157
+ * A studio message to this page, or null: only from the parent window (the studio embedding the
158
+ * page), of this origin, with a known shape ('pause', or 'pick-open' with a known format).
159
+ */
160
+ export function readStudioMessage(e: { source: unknown; origin: string; data: unknown }, parent: unknown, origin: string): StudioToGallery | null {
161
+ if (e.source !== parent || e.origin !== origin) return null;
162
+ const d = e.data as { source?: unknown; type?: unknown; format?: unknown } | null;
163
+ if (!d || typeof d !== 'object' || d.source !== 'beatsheet-studio') return null;
164
+ if (d.type === 'pause') return { source: 'beatsheet-studio', type: 'pause' };
165
+ if (d.type === 'pick-open' && isFormatId(d.format)) return { source: 'beatsheet-studio', type: 'pick-open', format: d.format };
166
+ return null;
167
+ }