@biunow/agent-biutalk 0.0.0-stage → 1.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.
- package/bin/server.js +355 -0
- package/engine/AGENTS.md +1414 -0
- package/engine/CLAUDE.md +1 -0
- package/engine/LICENSE +21 -0
- package/engine/README.md +216 -0
- package/engine/bin/explainroo.js +19 -0
- package/engine/dev/audio-lab.mjs +268 -0
- package/engine/docs/media/contact-sheet.jpg +0 -0
- package/engine/docs/media/dns-poster.jpg +0 -0
- package/engine/docs/media/intro-poster.jpg +0 -0
- package/engine/docs/media/logo-dark.png +0 -0
- package/engine/docs/media/logo-light.png +0 -0
- package/engine/docs/media/looks-dark.webp +0 -0
- package/engine/docs/media/looks-light.webp +0 -0
- package/engine/docs/media/product-demo.webp +0 -0
- package/engine/docs/media/rebase-poster.jpg +0 -0
- package/engine/docs/media/sizes-dark.webp +0 -0
- package/engine/docs/media/sizes-light.webp +0 -0
- package/engine/engine/audio/dsp.js +69 -0
- package/engine/engine/audio/instruments.js +147 -0
- package/engine/engine/audio/music.js +576 -0
- package/engine/engine/audio/pcm.js +93 -0
- package/engine/engine/audio/rng.js +40 -0
- package/engine/engine/audio/sfx.js +287 -0
- package/engine/engine/audio/soundtrack.js +201 -0
- package/engine/engine/audio/synth.js +721 -0
- package/engine/engine/audio/theory.js +105 -0
- package/engine/engine/audio/wav.js +47 -0
- package/engine/engine/captions.js +131 -0
- package/engine/engine/clips.js +107 -0
- package/engine/engine/code.js +179 -0
- package/engine/engine/director.js +475 -0
- package/engine/engine/frame.html +135 -0
- package/engine/engine/icons/LICENSE-lucide.txt +43 -0
- package/engine/engine/icons/lucide-tags.json +1 -0
- package/engine/engine/icons/lucide.json +1 -0
- package/engine/engine/layout.js +69 -0
- package/engine/engine/pathdata.js +234 -0
- package/engine/engine/pen.js +240 -0
- package/engine/engine/player.html +67 -0
- package/engine/engine/player.js +219 -0
- package/engine/engine/readability.js +9 -0
- package/engine/engine/runtime.js +690 -0
- package/engine/engine/stage.js +2247 -0
- package/engine/engine/studio.html +216 -0
- package/engine/engine/text.js +81 -0
- package/engine/engine/themes.js +360 -0
- package/engine/engine/transitions.js +161 -0
- package/engine/engine/ui.js +1042 -0
- package/engine/engine/upload.js +32 -0
- package/engine/engine/util.js +204 -0
- package/engine/examples/callbacks-to-async-await/code-versions.js +34 -0
- package/engine/examples/callbacks-to-async-await/scenes.js +106 -0
- package/engine/examples/callbacks-to-async-await/script.md +22 -0
- package/engine/examples/callbacks-to-async-await/video.json +16 -0
- package/engine/examples/circle-area/scenes.js +228 -0
- package/engine/examples/circle-area/script.md +37 -0
- package/engine/examples/circle-area/video.json +14 -0
- package/engine/examples/explainroo-intro/scenes.js +133 -0
- package/engine/examples/explainroo-intro/script.md +27 -0
- package/engine/examples/explainroo-intro/video.json +8 -0
- package/engine/examples/how-dns-works/scenes.js +130 -0
- package/engine/examples/how-dns-works/script.md +28 -0
- package/engine/examples/how-dns-works/video.json +8 -0
- package/engine/examples/leap-years/scenes.js +156 -0
- package/engine/examples/leap-years/script.md +25 -0
- package/engine/examples/leap-years/video.json +16 -0
- package/engine/examples/leap-years-ja/scenes.js +194 -0
- package/engine/examples/leap-years-ja/script.md +32 -0
- package/engine/examples/leap-years-ja/video.json +17 -0
- package/engine/examples/merge-vs-rebase/scenes.js +129 -0
- package/engine/examples/merge-vs-rebase/script.md +22 -0
- package/engine/examples/merge-vs-rebase/video.json +8 -0
- package/engine/examples/password-storage-zh/scenes.js +185 -0
- package/engine/examples/password-storage-zh/script.md +25 -0
- package/engine/examples/password-storage-zh/video.json +19 -0
- package/engine/examples/sqlite-demo/README.md +19 -0
- package/engine/examples/sqlite-demo/scenes.js +423 -0
- package/engine/examples/sqlite-demo/script.md +35 -0
- package/engine/examples/sqlite-demo/video.json +17 -0
- package/engine/examples/unspar-demo/assets/fonts/Figtree-400.woff2 +0 -0
- package/engine/examples/unspar-demo/assets/fonts/Figtree-500.woff2 +0 -0
- package/engine/examples/unspar-demo/assets/fonts/Figtree-600.woff2 +0 -0
- package/engine/examples/unspar-demo/assets/fonts/Figtree-700.woff2 +0 -0
- package/engine/examples/unspar-demo/assets/fonts/Figtree-OFL.txt +93 -0
- package/engine/examples/unspar-demo/assets/unspar-logo.svg +23 -0
- package/engine/examples/unspar-demo/scenes.js +367 -0
- package/engine/examples/unspar-demo/script.md +25 -0
- package/engine/examples/unspar-demo/video.json +21 -0
- package/engine/examples/why-is-the-sky-blue-es/scenes.js +160 -0
- package/engine/examples/why-is-the-sky-blue-es/script.md +22 -0
- package/engine/examples/why-is-the-sky-blue-es/video.json +15 -0
- package/engine/fonts/ArchitectsDaughter-400-latin-ext.woff2 +0 -0
- package/engine/fonts/ArchitectsDaughter-400-latin.woff2 +0 -0
- package/engine/fonts/CabinSketch-400-latin.woff2 +0 -0
- package/engine/fonts/CabinSketch-700-latin.woff2 +0 -0
- package/engine/fonts/InstrumentSerif-400-italic-latin-ext.woff2 +0 -0
- package/engine/fonts/InstrumentSerif-400-italic-latin.woff2 +0 -0
- package/engine/fonts/InstrumentSerif-400-normal-latin-ext.woff2 +0 -0
- package/engine/fonts/InstrumentSerif-400-normal-latin.woff2 +0 -0
- package/engine/fonts/Inter-400-latin-ext.woff2 +0 -0
- package/engine/fonts/Inter-400-latin.woff2 +0 -0
- package/engine/fonts/JetBrainsMono-400-latin-ext.woff2 +0 -0
- package/engine/fonts/JetBrainsMono-400-latin.woff2 +0 -0
- package/engine/fonts/Kalam-400-latin-ext.woff2 +0 -0
- package/engine/fonts/Kalam-400-latin.woff2 +0 -0
- package/engine/fonts/Kalam-700-latin-ext.woff2 +0 -0
- package/engine/fonts/Kalam-700-latin.woff2 +0 -0
- package/engine/fonts/NotoSansDevanagari-400.ttf +0 -0
- package/engine/fonts/NotoSansDevanagari-700.ttf +0 -0
- package/engine/fonts/PatrickHand-400-latin-ext.woff2 +0 -0
- package/engine/fonts/PatrickHand-400-latin.woff2 +0 -0
- package/engine/fonts/PlusJakartaSans-600-latin-ext.woff2 +0 -0
- package/engine/fonts/PlusJakartaSans-600-latin.woff2 +0 -0
- package/engine/fonts/SpaceGrotesk-500-latin-ext.woff2 +0 -0
- package/engine/fonts/SpaceGrotesk-500-latin.woff2 +0 -0
- package/engine/fonts/fonts.json +216 -0
- package/engine/fonts/licenses/ArchitectsDaughter-OFL.txt +93 -0
- package/engine/fonts/licenses/CabinSketch-OFL.txt +93 -0
- package/engine/fonts/licenses/InstrumentSerif-OFL.txt +93 -0
- package/engine/fonts/licenses/Inter-OFL.txt +93 -0
- package/engine/fonts/licenses/JetBrainsMono-OFL.txt +93 -0
- package/engine/fonts/licenses/Kalam-OFL.txt +93 -0
- package/engine/fonts/licenses/NotoSansDevanagari-OFL.txt +118 -0
- package/engine/fonts/licenses/PatrickHand-OFL.txt +93 -0
- package/engine/fonts/licenses/PlusJakartaSans-OFL.txt +93 -0
- package/engine/fonts/licenses/SpaceGrotesk-OFL.txt +93 -0
- package/engine/package-lock.json +1201 -0
- package/engine/package.json +67 -0
- package/engine/scripts/build-icons.mjs +74 -0
- package/engine/scripts/fetch-fonts.mjs +68 -0
- package/engine/skills/explainroo/SKILL.md +51 -0
- package/engine/src/align.js +357 -0
- package/engine/src/browser.js +121 -0
- package/engine/src/capture.js +315 -0
- package/engine/src/chapters.js +32 -0
- package/engine/src/cli.js +421 -0
- package/engine/src/clips.js +19 -0
- package/engine/src/elevenlabs.js +90 -0
- package/engine/src/env.js +16 -0
- package/engine/src/export.js +187 -0
- package/engine/src/ffmpeg.js +103 -0
- package/engine/src/fonts.js +86 -0
- package/engine/src/g2p.py +76 -0
- package/engine/src/images.js +151 -0
- package/engine/src/licenses/misaki-Apache-2.0.txt +201 -0
- package/engine/src/math.js +83 -0
- package/engine/src/models.js +161 -0
- package/engine/src/phonemes.js +162 -0
- package/engine/src/pipeline.js +63 -0
- package/engine/src/project.js +331 -0
- package/engine/src/qa.js +186 -0
- package/engine/src/recordings.js +89 -0
- package/engine/src/render.js +156 -0
- package/engine/src/script.js +266 -0
- package/engine/src/server.js +288 -0
- package/engine/src/subtitles.js +78 -0
- package/engine/src/timeline.js +55 -0
- package/engine/src/voice.js +240 -0
- package/engine/src/wav.js +98 -0
- package/engine/templates/starter/scenes.js +31 -0
- package/engine/templates/starter/script.md +14 -0
- package/engine/test/align.test.js +108 -0
- package/engine/test/brand.test.js +41 -0
- package/engine/test/browser.test.js +89 -0
- package/engine/test/camera-browser.test.js +225 -0
- package/engine/test/caption-phrases.test.js +35 -0
- package/engine/test/capture-browser.test.js +90 -0
- package/engine/test/capture-fixture.js +46 -0
- package/engine/test/capture.test.js +62 -0
- package/engine/test/chapters.test.js +41 -0
- package/engine/test/cjk-browser.test.js +101 -0
- package/engine/test/cjk.test.js +232 -0
- package/engine/test/cli-exit.test.js +25 -0
- package/engine/test/cli.test.js +116 -0
- package/engine/test/clips-browser.test.js +125 -0
- package/engine/test/clips.test.js +67 -0
- package/engine/test/code-morph-browser.test.js +99 -0
- package/engine/test/code-morph.test.js +110 -0
- package/engine/test/contrast-browser.test.js +63 -0
- package/engine/test/contrast.test.js +80 -0
- package/engine/test/director.test.js +316 -0
- package/engine/test/engine-pure.test.js +29 -0
- package/engine/test/export-browser.test.js +224 -0
- package/engine/test/export.test.js +96 -0
- package/engine/test/fixtures/capture.html +55 -0
- package/engine/test/formats-pace.test.js +104 -0
- package/engine/test/languages-browser.test.js +78 -0
- package/engine/test/languages.test.js +140 -0
- package/engine/test/looks-browser.test.js +109 -0
- package/engine/test/looks-preview.test.js +57 -0
- package/engine/test/looks.test.js +130 -0
- package/engine/test/math-browser.test.js +114 -0
- package/engine/test/math.test.js +54 -0
- package/engine/test/multi-size-browser.test.js +133 -0
- package/engine/test/multi-size.test.js +116 -0
- package/engine/test/phonemes.test.js +92 -0
- package/engine/test/readability-browser.test.js +36 -0
- package/engine/test/readability.test.js +20 -0
- package/engine/test/render-options.test.js +52 -0
- package/engine/test/script.test.js +67 -0
- package/engine/test/server.test.js +256 -0
- package/engine/test/stills-browser.test.js +70 -0
- package/engine/test/subtitles.test.js +83 -0
- package/engine/test/timeline.test.js +31 -0
- package/engine/test/transparent-browser.test.js +123 -0
- package/engine/test/ui-kit.test.js +96 -0
- package/engine/test/upload-browser.test.js +55 -0
- package/engine/test/voice-providers.test.js +338 -0
- package/lib/host.mjs +480 -0
- package/manifest.json +54 -0
- package/package.json +8 -4
- package/skills/biutalk/SKILL.md +21 -0
- package/studio/app.js +209 -0
- package/studio/assert-panel-permit.mjs +67 -0
- package/studio/composer.css +354 -0
- package/studio/composer.js +169 -0
- package/studio/index.html +82 -0
- package/studio/looks/blueprint.svg +21 -0
- package/studio/looks/chalk.svg +15 -0
- package/studio/looks/clean.svg +20 -0
- package/studio/looks/editorial.svg +18 -0
- package/studio/looks/midnight.svg +17 -0
- package/studio/looks/paper.svg +11 -0
- package/studio/select-menu.js +268 -0
- package/studio/styles.css +4 -0
- package/README.md +0 -3
|
@@ -0,0 +1,1042 @@
|
|
|
1
|
+
// The UI kit behind s.ui: crisp app screens for product demos. Cards,
|
|
2
|
+
// buttons, fields, dropdowns, toggles, status pills, a mouse cursor that
|
|
3
|
+
// clicks and types, and serif headlines that blur in word by word.
|
|
4
|
+
//
|
|
5
|
+
// Everything is drawn in the frame's design space, so s.camera() can zoom
|
|
6
|
+
// into it. Times are scene seconds, spoken words or "#marks", and pace
|
|
7
|
+
// applies, like everywhere else. Colors, fonts and the logo come from
|
|
8
|
+
// "brand" in video.json.
|
|
9
|
+
|
|
10
|
+
import { SceneError } from './stage.js';
|
|
11
|
+
|
|
12
|
+
const clamp = (v, a = 0, b = 1) => Math.max(a, Math.min(b, v));
|
|
13
|
+
const lerp = (a, b, p) => a + (b - a) * p;
|
|
14
|
+
const outCubic = (p) => 1 - Math.pow(1 - p, 3);
|
|
15
|
+
const inOutCubic = (p) => (p < 0.5 ? 4 * p * p * p : 1 - Math.pow(-2 * p + 2, 3) / 2);
|
|
16
|
+
const outBack = (p) => 1 + 2.70158 * Math.pow(p - 1, 3) + 1.70158 * Math.pow(p - 1, 2);
|
|
17
|
+
// 0 -> 1 -> 0 over p in 0..1, for a press.
|
|
18
|
+
const bell = (p) => (p <= 0 || p >= 1 ? 0 : Math.sin(Math.PI * p));
|
|
19
|
+
|
|
20
|
+
function rgb(hex) {
|
|
21
|
+
const n = parseInt(hex.slice(1), 16);
|
|
22
|
+
return [(n >> 16) & 255, (n >> 8) & 255, n & 255];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function mix(a, b, p) {
|
|
26
|
+
const A = rgb(a);
|
|
27
|
+
const B = rgb(b);
|
|
28
|
+
const h = (i) => Math.round(lerp(A[i], B[i], p)).toString(16).padStart(2, '0');
|
|
29
|
+
return `#${h(0)}${h(1)}${h(2)}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const TONES = {
|
|
33
|
+
gray: { bg: '#f2f4f7', fg: '#344054', ring: '#d0d5dd' },
|
|
34
|
+
blue: { bg: '#eff8ff', fg: '#175cd3', ring: '#b2ddff' },
|
|
35
|
+
yellow: { bg: '#fffaeb', fg: '#b54708', ring: '#fedf89' },
|
|
36
|
+
green: { bg: '#ecfdf3', fg: '#067647', ring: '#abefc6' },
|
|
37
|
+
red: { bg: '#fef3f2', fg: '#b42318', ring: '#fecdca' },
|
|
38
|
+
purple: { bg: '#f4f3ff', fg: '#5925dc', ring: '#d9d6fe' },
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// Faint cards scattered around the edges, for depth behind the UI.
|
|
42
|
+
const FLOATERS = [
|
|
43
|
+
{ x: 0.078, y: 0.157, r: -7 }, { x: 0.917, y: 0.139, r: 6 }, { x: 0.057, y: 0.519, r: 4 },
|
|
44
|
+
{ x: 0.943, y: 0.556, r: -5 }, { x: 0.12, y: 0.87, r: 8 }, { x: 0.88, y: 0.889, r: -8 },
|
|
45
|
+
{ x: 0.365, y: 0.954, r: 3 }, { x: 0.635, y: 0.037, r: -3 },
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
// While a hidden s.group() runs (to collect timing and sounds), the kit must
|
|
49
|
+
// not draw: these canvas calls are skipped then, everything else goes through.
|
|
50
|
+
const DRAW_CALLS = new Set(['fill', 'stroke', 'fillText', 'strokeText', 'drawImage', 'fillRect', 'strokeRect', 'clearRect', 'putImageData']);
|
|
51
|
+
|
|
52
|
+
export class UI {
|
|
53
|
+
constructor(s) {
|
|
54
|
+
this.s = s;
|
|
55
|
+
const th = s.theme;
|
|
56
|
+
const b = s.engine.config.brand || {};
|
|
57
|
+
const accent = b.accent ?? th.colors[th.accent];
|
|
58
|
+
this.font = b.font ?? 'Inter';
|
|
59
|
+
this.headlineFont = b.headline ?? 'Instrument Serif';
|
|
60
|
+
this.logoSrc = b.logo ?? null;
|
|
61
|
+
// App screens are light; `ink` is for text drawn straight on the background.
|
|
62
|
+
this.colors = {
|
|
63
|
+
accent,
|
|
64
|
+
accentDark: mix(accent, '#000000', 0.16),
|
|
65
|
+
accentTint: mix(accent, '#ffffff', 0.91),
|
|
66
|
+
accentRing: mix(accent, '#ffffff', 0.55),
|
|
67
|
+
background: b.background ?? th.bg,
|
|
68
|
+
ink: b.ink ?? th.ink,
|
|
69
|
+
text: '#18202c',
|
|
70
|
+
soft: '#526071',
|
|
71
|
+
muted: '#667085',
|
|
72
|
+
faint: '#98a2b3',
|
|
73
|
+
line: '#e4e7ec',
|
|
74
|
+
field: '#d0d5dd',
|
|
75
|
+
surface: '#ffffff',
|
|
76
|
+
panel: '#f5f7fb',
|
|
77
|
+
// brand.colors overrides any of these, for example warm grays.
|
|
78
|
+
...(b.colors || {}),
|
|
79
|
+
};
|
|
80
|
+
this._layer = 0;
|
|
81
|
+
this._layers = 0;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// The canvas, or a stand-in that draws nothing while a group is hidden.
|
|
85
|
+
get c() {
|
|
86
|
+
if (!(this.s._suppress > 0)) return this.s.ctx;
|
|
87
|
+
if (!this._quiet) {
|
|
88
|
+
const real = this.s.ctx;
|
|
89
|
+
this._quiet = new Proxy(real, {
|
|
90
|
+
get(target, key) {
|
|
91
|
+
if (DRAW_CALLS.has(key)) return () => {};
|
|
92
|
+
const v = target[key];
|
|
93
|
+
return typeof v === 'function' ? v.bind(target) : v;
|
|
94
|
+
},
|
|
95
|
+
set(target, key, value) {
|
|
96
|
+
target[key] = value;
|
|
97
|
+
return true;
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return this._quiet;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
get hidden() {
|
|
105
|
+
return this.s._suppress > 0;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Scale of the current transform. Canvas shadows and blur filters work in
|
|
109
|
+
// device pixels, so they are multiplied by this to zoom with the camera.
|
|
110
|
+
get k() {
|
|
111
|
+
const m = this.c.getTransform();
|
|
112
|
+
return Math.hypot(m.a, m.b);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
at(v) {
|
|
116
|
+
return this.s.time(v);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
_p(at, dur, easing = 'out') {
|
|
120
|
+
return this.s.p(at, dur, easing);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
fontString(size, weight = 400, family = this.font, italic = false) {
|
|
124
|
+
return `${italic ? 'italic ' : ''}${weight} ${size}px "${family}", Inter, "Noto Sans Devanagari", "Noto Sans JP", "Noto Sans SC", sans-serif`;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
_family(f) {
|
|
128
|
+
if (!f || f === 'ui') return this.font;
|
|
129
|
+
if (f === 'headline') return this.headlineFont;
|
|
130
|
+
return f;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// An entrance, so `check` knows something new appears and a sound can play.
|
|
134
|
+
_enter(at, dur, sfx) {
|
|
135
|
+
this.s._record('ui', at, dur, { sfx: sfx ?? null });
|
|
136
|
+
// Arriving parts get motion blur in the final render.
|
|
137
|
+
if (this.s.t >= at && this.s.t < at + dur / this.s.pace) this.s.engine.moving = true;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// ---------- surfaces ----------
|
|
141
|
+
|
|
142
|
+
backdrop(color = this.colors.background) {
|
|
143
|
+
const c = this.c;
|
|
144
|
+
c.save();
|
|
145
|
+
c.setTransform(this.s.engine.scale, 0, 0, this.s.engine.scale, 0, 0);
|
|
146
|
+
c.fillStyle = color;
|
|
147
|
+
c.fillRect(0, 0, this.s.W, this.s.H);
|
|
148
|
+
c.restore();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Faint app cards drifting around the edges, out of focus. Each card is
|
|
152
|
+
// blurred once and reused, because a blur filter on every frame is slow.
|
|
153
|
+
// The floating cards are decoration. The camera does not count them as
|
|
154
|
+
// part of the picture.
|
|
155
|
+
floaters(o = {}) {
|
|
156
|
+
const pause = this.c.__inkPause;
|
|
157
|
+
pause?.(true);
|
|
158
|
+
try {
|
|
159
|
+
return this._floaters(o);
|
|
160
|
+
} finally {
|
|
161
|
+
pause?.(false);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
_floaters(o = {}) {
|
|
166
|
+
const s = this.s;
|
|
167
|
+
const c = this.c;
|
|
168
|
+
const tint = o.tint ?? 'card';
|
|
169
|
+
const cache = (s.engine._uiSprites ??= new Map());
|
|
170
|
+
FLOATERS.forEach((f, i) => {
|
|
171
|
+
const key = `${i % 3}|${tint}`;
|
|
172
|
+
if (!cache.has(key)) cache.set(key, this._floaterSprite(i, tint));
|
|
173
|
+
const dx = Math.sin(s.T * 0.25 + i * 1.7) * 14;
|
|
174
|
+
const dy = Math.cos(s.T * 0.3 + i * 2.1) * 12;
|
|
175
|
+
c.save();
|
|
176
|
+
c.globalAlpha *= o.alpha ?? 0.55;
|
|
177
|
+
c.translate(f.x * s.W + dx, f.y * s.H + dy);
|
|
178
|
+
c.rotate((f.r * Math.PI) / 180);
|
|
179
|
+
c.drawImage(cache.get(key), -210, -140, 420, 280);
|
|
180
|
+
c.restore();
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
_floaterSprite(i, tint) {
|
|
185
|
+
const k = 2;
|
|
186
|
+
const cv = new OffscreenCanvas(420 * k, 280 * k);
|
|
187
|
+
const c = cv.getContext('2d');
|
|
188
|
+
c.scale(k, k);
|
|
189
|
+
c.translate(210, 140);
|
|
190
|
+
c.scale(0.62, 0.62);
|
|
191
|
+
const bar = (x, y, w) => {
|
|
192
|
+
c.beginPath();
|
|
193
|
+
c.roundRect(x, y, w, 10, 5);
|
|
194
|
+
c.fill();
|
|
195
|
+
};
|
|
196
|
+
if (tint === 'white') {
|
|
197
|
+
c.fillStyle = 'rgba(255, 255, 255, 0.9)';
|
|
198
|
+
c.beginPath();
|
|
199
|
+
c.roundRect(-150, -80, 300, 160, 16);
|
|
200
|
+
c.fill();
|
|
201
|
+
c.fillStyle = 'rgba(255, 255, 255, 0.55)';
|
|
202
|
+
} else {
|
|
203
|
+
c.shadowColor = 'rgba(16, 24, 40, 0.08)';
|
|
204
|
+
c.shadowBlur = 24 * k;
|
|
205
|
+
c.shadowOffsetY = 8 * k;
|
|
206
|
+
c.fillStyle = '#ffffff';
|
|
207
|
+
c.beginPath();
|
|
208
|
+
c.roundRect(-150, -80, 300, 160, 16);
|
|
209
|
+
c.fill();
|
|
210
|
+
c.shadowColor = 'transparent';
|
|
211
|
+
c.strokeStyle = this.colors.line;
|
|
212
|
+
c.lineWidth = 1.5;
|
|
213
|
+
c.stroke();
|
|
214
|
+
c.fillStyle = ['#dbe7ff', '#fde7d9', '#dcfae6'][i % 3];
|
|
215
|
+
c.beginPath();
|
|
216
|
+
c.arc(-112, -44, 16, 0, Math.PI * 2);
|
|
217
|
+
c.fill();
|
|
218
|
+
c.fillStyle = '#e4e8ef';
|
|
219
|
+
}
|
|
220
|
+
bar(-84, -52, 170);
|
|
221
|
+
[0, 1, 2].forEach((j) => bar(-122, -4 + j * 22, [240, 220, 150][j]));
|
|
222
|
+
const out = new OffscreenCanvas(420 * k, 280 * k);
|
|
223
|
+
const oc = out.getContext('2d');
|
|
224
|
+
oc.filter = `blur(${1.6 * k}px)`;
|
|
225
|
+
oc.drawImage(cv, 0, 0);
|
|
226
|
+
return out;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
card(x, y, w, h, o = {}) {
|
|
230
|
+
const c = this.c;
|
|
231
|
+
const r = o.r ?? 18;
|
|
232
|
+
const k = this.k;
|
|
233
|
+
c.save();
|
|
234
|
+
c.globalAlpha *= o.alpha ?? 1;
|
|
235
|
+
c.beginPath();
|
|
236
|
+
c.roundRect(x, y, w, h, r);
|
|
237
|
+
c.fillStyle = o.fill ?? this.colors.surface;
|
|
238
|
+
if (o.shadow !== false) {
|
|
239
|
+
const lift = o.lift ?? 1;
|
|
240
|
+
c.shadowColor = `rgba(16, 24, 40, ${0.05 * lift})`;
|
|
241
|
+
c.shadowBlur = 3 * k;
|
|
242
|
+
c.shadowOffsetY = 1 * k;
|
|
243
|
+
c.fill();
|
|
244
|
+
c.shadowColor = `rgba(16, 24, 40, ${0.09 * lift})`;
|
|
245
|
+
c.shadowBlur = 48 * lift * k;
|
|
246
|
+
c.shadowOffsetY = 18 * lift * k;
|
|
247
|
+
}
|
|
248
|
+
c.fill();
|
|
249
|
+
c.shadowColor = 'transparent';
|
|
250
|
+
if (o.border !== false) {
|
|
251
|
+
c.strokeStyle = o.border ?? this.colors.line;
|
|
252
|
+
c.lineWidth = o.borderWidth ?? 1.5;
|
|
253
|
+
c.stroke();
|
|
254
|
+
}
|
|
255
|
+
c.restore();
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// A card that pops up at `at`, then fn(x, y, w, h) draws inside it.
|
|
259
|
+
// Returns the entrance progress (0 before `at`).
|
|
260
|
+
panel(x, y, w, h, o = {}, fn) {
|
|
261
|
+
if (typeof o === 'function') [o, fn] = [{}, o];
|
|
262
|
+
const s = this.s;
|
|
263
|
+
const a = this.at(o.at ?? 0);
|
|
264
|
+
const dur = o.dur ?? 0.6;
|
|
265
|
+
this._enter(a, dur, o.sfx);
|
|
266
|
+
s._logLayout('panel', a, o.out === undefined ? Infinity : this.at(o.out), x + w / 2, y + h / 2, w, h);
|
|
267
|
+
if (s.t < a) return 0;
|
|
268
|
+
const p = clamp((s.t - a) / (dur / s.pace));
|
|
269
|
+
const q = o.out !== undefined ? this._p(o.out, o.outDur ?? 0.35, 'in') : 0;
|
|
270
|
+
if (q >= 1) return p;
|
|
271
|
+
const c = this.c;
|
|
272
|
+
const sc = lerp(o.from ?? 0.94, 1, outBack(p)) * (1 - 0.03 * q);
|
|
273
|
+
// A panel tells the camera its own place and time, so what it holds is
|
|
274
|
+
// not measured again as a loose drawing.
|
|
275
|
+
const pause = c.__inkPause;
|
|
276
|
+
pause?.(true);
|
|
277
|
+
c.save();
|
|
278
|
+
c.globalAlpha *= clamp(p * 2.5) * (1 - q);
|
|
279
|
+
c.translate(x + w / 2, y + h / 2 + (1 - outCubic(p)) * (o.rise ?? 30));
|
|
280
|
+
c.scale(sc, sc);
|
|
281
|
+
c.translate(-(x + w / 2), -(y + h / 2));
|
|
282
|
+
try {
|
|
283
|
+
this.card(x, y, w, h, o);
|
|
284
|
+
if (fn) fn(x, y, w, h);
|
|
285
|
+
} finally {
|
|
286
|
+
c.restore();
|
|
287
|
+
pause?.(false);
|
|
288
|
+
}
|
|
289
|
+
return p;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// A panel with a browser bar and an address. fn gets the page area.
|
|
293
|
+
browser(x, y, w, h, o = {}, fn) {
|
|
294
|
+
if (typeof o === 'function') [o, fn] = [{}, o];
|
|
295
|
+
const bar = o.bar ?? 50;
|
|
296
|
+
return this.panel(x, y, w, h, o, () => {
|
|
297
|
+
const c = this.c;
|
|
298
|
+
c.save();
|
|
299
|
+
c.beginPath();
|
|
300
|
+
c.roundRect(x, y, w, bar, [o.r ?? 18, o.r ?? 18, 0, 0]);
|
|
301
|
+
c.fillStyle = '#f2f4f7';
|
|
302
|
+
c.fill();
|
|
303
|
+
['#f97066', '#fdb022', '#32d583'].forEach((col, i) => {
|
|
304
|
+
c.beginPath();
|
|
305
|
+
c.arc(x + 28 + i * 22, y + bar / 2, 7, 0, Math.PI * 2);
|
|
306
|
+
c.fillStyle = col;
|
|
307
|
+
c.fill();
|
|
308
|
+
});
|
|
309
|
+
c.beginPath();
|
|
310
|
+
c.roundRect(x + 110, y + 11, w - 140, bar - 22, (bar - 22) / 2);
|
|
311
|
+
c.fillStyle = '#ffffff';
|
|
312
|
+
c.fill();
|
|
313
|
+
c.restore();
|
|
314
|
+
if (o.url) this.text(o.url, x + 128, y + bar / 2 + 1, { size: o.urlSize ?? 17, color: this.colors.muted, maxW: w - 170 });
|
|
315
|
+
if (fn) fn(x, y + bar, w, h - bar);
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// A dialog over a dimmed frame. Everything drawn in fn sits on top of
|
|
320
|
+
// what is below, so `check` does not report it as overlapping.
|
|
321
|
+
modal(x, y, w, h, o = {}, fn) {
|
|
322
|
+
if (typeof o === 'function') [o, fn] = [{}, o];
|
|
323
|
+
const s = this.s;
|
|
324
|
+
const a = this.at(o.at ?? 0);
|
|
325
|
+
if (s.t < a) return 0;
|
|
326
|
+
const q = o.out !== undefined ? this._p(o.out, 0.3, 'in') : 0;
|
|
327
|
+
if (q >= 1) return 1;
|
|
328
|
+
const p = this._p(a, 0.35);
|
|
329
|
+
const c = this.c;
|
|
330
|
+
if (o.dim !== false) {
|
|
331
|
+
c.save();
|
|
332
|
+
c.setTransform(s.engine.scale, 0, 0, s.engine.scale, 0, 0);
|
|
333
|
+
c.fillStyle = `rgba(16, 24, 40, ${(o.dim ?? 0.28) * p * (1 - q)})`;
|
|
334
|
+
c.fillRect(0, 0, s.W, s.H);
|
|
335
|
+
c.restore();
|
|
336
|
+
}
|
|
337
|
+
return this.over(() => this.panel(x, y, w, h, { r: 20, lift: 1.4, ...o, at: a, dur: 0.45 }, fn));
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// A short message card that slides up, like "Saved" or "Sent".
|
|
341
|
+
toast(label, o = {}) {
|
|
342
|
+
const a = this.at(o.at ?? 0);
|
|
343
|
+
const s = this.s;
|
|
344
|
+
if (s.t < a) return;
|
|
345
|
+
if (o.out !== undefined && s.t >= this.at(o.out) + 0.4) return;
|
|
346
|
+
const size = o.size ?? 22;
|
|
347
|
+
const w = this.measure(label, size, 600) + (o.icon === false ? 64 : 100);
|
|
348
|
+
const x = (o.x ?? s.W / 2) - w / 2;
|
|
349
|
+
const y = o.y ?? s.H - 150;
|
|
350
|
+
const tone = TONES[o.tone ?? 'green'] || TONES.green;
|
|
351
|
+
this.over(() => {
|
|
352
|
+
this.panel(x, y, w, 72, { at: a, out: o.out, r: 16, lift: 0.9, rise: 40, from: 0.9, sfx: o.sfx === undefined ? 'chime' : o.sfx }, () => {
|
|
353
|
+
let tx = x + 32;
|
|
354
|
+
if (o.icon !== false) {
|
|
355
|
+
this.icon(o.icon ?? 'circle-check', x + 40, y + 36, 30, tone.fg, 2.2);
|
|
356
|
+
tx = x + 70;
|
|
357
|
+
}
|
|
358
|
+
this.text(label, tx, y + 37, { size, weight: 600 });
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// Brand color spreading from a point until it fills the frame.
|
|
364
|
+
wipe(at, o = {}) {
|
|
365
|
+
const s = this.s;
|
|
366
|
+
const a = this.at(at);
|
|
367
|
+
if (s.t < a) return 0;
|
|
368
|
+
if (o.sfx !== null) s.sfx(o.sfx ?? 'swipe', a);
|
|
369
|
+
const p = this._p(a, o.dur ?? 0.7, 'inOut');
|
|
370
|
+
const x = o.x ?? s.W / 2;
|
|
371
|
+
const y = o.y ?? s.H / 2;
|
|
372
|
+
const c = this.c;
|
|
373
|
+
c.save();
|
|
374
|
+
c.beginPath();
|
|
375
|
+
c.arc(x, y, lerp(0, Math.hypot(Math.max(x, s.W - x), Math.max(y, s.H - y)) + 20, p), 0, Math.PI * 2);
|
|
376
|
+
c.fillStyle = o.color ?? this.colors.accent;
|
|
377
|
+
c.fill();
|
|
378
|
+
c.restore();
|
|
379
|
+
return p;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// Scales something in around (cx, cy) with a little overshoot at `at`.
|
|
383
|
+
pop(at, cx, cy, fn, o = {}) {
|
|
384
|
+
const s = this.s;
|
|
385
|
+
const a = this.at(at);
|
|
386
|
+
this._enter(a, o.dur ?? 0.45, o.sfx);
|
|
387
|
+
if (s.t < a) return 0;
|
|
388
|
+
const p = this._p(a, o.dur ?? 0.45, 'outBack');
|
|
389
|
+
const c = this.c;
|
|
390
|
+
c.save();
|
|
391
|
+
c.globalAlpha *= clamp(p * 2);
|
|
392
|
+
c.translate(cx, cy);
|
|
393
|
+
const sc = lerp(o.from ?? 0.7, 1, p);
|
|
394
|
+
c.scale(sc, sc);
|
|
395
|
+
c.translate(-cx, -cy);
|
|
396
|
+
fn(p);
|
|
397
|
+
c.restore();
|
|
398
|
+
return p;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// Draws fn as a layer on top of what is already there (menus, dialogs).
|
|
402
|
+
// Each call is its own layer, so `check` does not report text in one
|
|
403
|
+
// layer as overlapping text in another.
|
|
404
|
+
over(fn) {
|
|
405
|
+
const prev = this._layer;
|
|
406
|
+
this._layer = ++this._layers;
|
|
407
|
+
try {
|
|
408
|
+
return fn();
|
|
409
|
+
} finally {
|
|
410
|
+
this._layer = prev;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// ---------- text ----------
|
|
415
|
+
|
|
416
|
+
_log(str, x, y, w, size, align, base) {
|
|
417
|
+
if (!str.trim() || this.hidden) return;
|
|
418
|
+
const x0 = align === 'center' ? x - w / 2 : align === 'right' ? x - w : x;
|
|
419
|
+
const [t, b] = base === 'top' ? [0, 1.2] : base === 'alphabetic' ? [-0.8, 0.22] : [-0.6, 0.6];
|
|
420
|
+
this.s._logText({ text: str, x0, y0: y + t * size, x1: x0 + w, y1: y + b * size, size, fg: null, bg: null, ui: this._layer + 1, zoomed: this.s._camMoved });
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
text(str, x, y, o = {}) {
|
|
424
|
+
const c = this.c;
|
|
425
|
+
const size = o.size ?? 22;
|
|
426
|
+
c.save();
|
|
427
|
+
c.font = this.fontString(size, o.weight ?? 400, this._family(o.font), o.italic);
|
|
428
|
+
c.fillStyle = o.color ?? this.colors.text;
|
|
429
|
+
const align = o.align ?? 'left';
|
|
430
|
+
const base = o.base ?? 'middle';
|
|
431
|
+
c.textAlign = align;
|
|
432
|
+
c.textBaseline = base;
|
|
433
|
+
c.letterSpacing = `${o.tracking ?? 0}px`;
|
|
434
|
+
c.globalAlpha *= o.alpha ?? 1;
|
|
435
|
+
let t = String(str);
|
|
436
|
+
if (o.maxW && c.measureText(t).width > o.maxW) {
|
|
437
|
+
while (t.length > 1 && c.measureText(t + '…').width > o.maxW) t = t.slice(0, -1);
|
|
438
|
+
t = t.trimEnd() + '…';
|
|
439
|
+
}
|
|
440
|
+
c.fillText(t, x, y);
|
|
441
|
+
const w = c.measureText(t).width;
|
|
442
|
+
if (o.check !== false) this._log(t, x, y, w, size, align, base);
|
|
443
|
+
c.restore();
|
|
444
|
+
return w;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
measure(str, size, weight = 400, font, italic = false, tracking = 0) {
|
|
448
|
+
const c = this.c;
|
|
449
|
+
c.save();
|
|
450
|
+
c.font = this.fontString(size, weight, this._family(font), italic);
|
|
451
|
+
c.letterSpacing = `${tracking}px`;
|
|
452
|
+
const w = c.measureText(String(str)).width;
|
|
453
|
+
c.restore();
|
|
454
|
+
return w;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// Wraps text to maxW and draws it from the top. Returns the height.
|
|
458
|
+
para(str, x, y, maxW, o = {}) {
|
|
459
|
+
const size = o.size ?? 22;
|
|
460
|
+
const lh = o.lh ?? size * 1.45;
|
|
461
|
+
const lines = this._wrap(str, maxW, size, o.weight ?? 400, o.font).filter((l, i, a) => l || i < a.length - 1);
|
|
462
|
+
lines.forEach((l, i) => this.text(l, x, y + i * lh, { ...o, base: 'top' }));
|
|
463
|
+
return lines.length * lh;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// Small uppercase label above a heading.
|
|
467
|
+
eyebrow(str, x, y, o = {}) {
|
|
468
|
+
return this.text(String(str).toUpperCase(), x, y, { size: 17, weight: 700, color: this.colors.accent, tracking: 2.2, ...o });
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// A headline that blurs in word by word, in the headline font. Wrap words
|
|
472
|
+
// in *stars* to set them in the accent color, in italic unless
|
|
473
|
+
// italic: false (for a brand font without an italic).
|
|
474
|
+
// A headline reports its own place and time to the camera.
|
|
475
|
+
headline(str, x, y, o = {}) {
|
|
476
|
+
const pause = this.c.__inkPause;
|
|
477
|
+
pause?.(true);
|
|
478
|
+
try {
|
|
479
|
+
return this._headline(str, x, y, o);
|
|
480
|
+
} finally {
|
|
481
|
+
pause?.(false);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
_headline(str, x, y, o = {}) {
|
|
486
|
+
const s = this.s;
|
|
487
|
+
const c = this.c;
|
|
488
|
+
const size = o.size ?? 96;
|
|
489
|
+
const family = this._family(o.font ?? 'headline');
|
|
490
|
+
const tracking = o.tracking ?? -1;
|
|
491
|
+
const tokens = [];
|
|
492
|
+
let italic = false;
|
|
493
|
+
for (const raw of String(str).split(' ')) {
|
|
494
|
+
let w = raw;
|
|
495
|
+
const starts = w.startsWith('*');
|
|
496
|
+
if (starts) w = w.slice(1);
|
|
497
|
+
const ends = w.endsWith('*');
|
|
498
|
+
if (ends) w = w.slice(0, -1);
|
|
499
|
+
if (starts) italic = true;
|
|
500
|
+
tokens.push({ w, italic, accent: italic });
|
|
501
|
+
if (ends) italic = false;
|
|
502
|
+
}
|
|
503
|
+
if (o.italic === false) tokens.forEach((t) => (t.italic = false));
|
|
504
|
+
const widths = tokens.map((t) => this.measure(t.w, size, o.weight ?? 400, family, t.italic, tracking));
|
|
505
|
+
const space = this.measure(' ', size, 400, family) * 0.9;
|
|
506
|
+
const total = widths.reduce((a, b) => a + b, 0) + space * (tokens.length - 1);
|
|
507
|
+
let cx = o.align === 'left' ? x : o.align === 'right' ? x - total : x - total / 2;
|
|
508
|
+
const a = this.at(o.at ?? 0);
|
|
509
|
+
s._logLayout('headline', a, o.out === undefined ? Infinity : this.at(o.out), cx + total / 2, y - size * 0.35, total, size * 1.1);
|
|
510
|
+
const stagger = (o.stagger ?? 0.07) / s.pace;
|
|
511
|
+
const dur = (o.dur ?? 0.7) / s.pace;
|
|
512
|
+
this._enter(a, dur + stagger * tokens.length, o.sfx);
|
|
513
|
+
const k = this.k;
|
|
514
|
+
tokens.forEach((t, i) => {
|
|
515
|
+
const e = outCubic(clamp((s.t - (a + i * stagger)) / dur));
|
|
516
|
+
const q = o.out !== undefined ? this._p(this.at(o.out) + i * stagger * 0.4, 0.35, 'in') : 0;
|
|
517
|
+
const alpha = e * (1 - q);
|
|
518
|
+
if (alpha > 0.002) {
|
|
519
|
+
const blur = (1 - e) * 14 + q * 10;
|
|
520
|
+
c.save();
|
|
521
|
+
if (blur > 0.3) c.filter = `blur(${(blur * k).toFixed(2)}px)`;
|
|
522
|
+
this.text(t.w, cx, y + (1 - e) * 22 - q * 14, {
|
|
523
|
+
size,
|
|
524
|
+
font: family,
|
|
525
|
+
italic: t.italic,
|
|
526
|
+
weight: o.weight ?? 400,
|
|
527
|
+
color: t.accent ? o.accent ?? this.colors.accent : o.color ?? this.colors.ink,
|
|
528
|
+
alpha,
|
|
529
|
+
tracking,
|
|
530
|
+
base: 'alphabetic',
|
|
531
|
+
});
|
|
532
|
+
c.restore();
|
|
533
|
+
}
|
|
534
|
+
cx += widths[i] + space;
|
|
535
|
+
});
|
|
536
|
+
return total;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// ---------- controls ----------
|
|
540
|
+
|
|
541
|
+
// tone: gray, blue, yellow, green, red, purple or accent.
|
|
542
|
+
pill(label, x, y, tone = 'gray', o = {}) {
|
|
543
|
+
const T = tone === 'accent' ? { bg: this.colors.accentTint, fg: this.colors.accentDark, ring: this.colors.accentRing } : TONES[tone];
|
|
544
|
+
if (!T) throw new SceneError(`pill tone must be one of ${Object.keys(TONES).join(', ')} or accent, not "${tone}"`);
|
|
545
|
+
const size = o.size ?? 17;
|
|
546
|
+
const dot = o.dot ?? false;
|
|
547
|
+
const padX = size * 0.75;
|
|
548
|
+
const h = size * 1.75;
|
|
549
|
+
const w = this.measure(label, size, 600) + padX * 2 + (dot ? size * 0.85 : 0);
|
|
550
|
+
const c = this.c;
|
|
551
|
+
const left = o.align === 'right' ? x - w : o.align === 'center' ? x - w / 2 : x;
|
|
552
|
+
c.save();
|
|
553
|
+
c.globalAlpha *= o.alpha ?? 1;
|
|
554
|
+
c.beginPath();
|
|
555
|
+
c.roundRect(left, y - h / 2, w, h, h / 2);
|
|
556
|
+
c.fillStyle = T.bg;
|
|
557
|
+
c.fill();
|
|
558
|
+
c.strokeStyle = T.ring;
|
|
559
|
+
c.lineWidth = 1.5;
|
|
560
|
+
c.stroke();
|
|
561
|
+
let tx = left + padX;
|
|
562
|
+
if (dot) {
|
|
563
|
+
const pulse = o.pulse ? 0.5 + 0.5 * Math.sin(this.s.t * 6) : 1;
|
|
564
|
+
c.save();
|
|
565
|
+
c.beginPath();
|
|
566
|
+
c.arc(tx + size * 0.25, y, size * 0.25, 0, Math.PI * 2);
|
|
567
|
+
c.fillStyle = T.fg;
|
|
568
|
+
c.globalAlpha *= 0.45 + 0.55 * pulse;
|
|
569
|
+
c.fill();
|
|
570
|
+
c.restore();
|
|
571
|
+
tx += size * 0.85;
|
|
572
|
+
}
|
|
573
|
+
this.text(label, tx, y + 0.5, { size, weight: 600, color: T.fg });
|
|
574
|
+
c.restore();
|
|
575
|
+
return w;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
// variant: primary, secondary or ghost. press: 0..1, from u.press(at).
|
|
579
|
+
// color: another fill for a primary button. caps: uppercase label.
|
|
580
|
+
button(label, x, y, w, h, o = {}) {
|
|
581
|
+
const c = this.c;
|
|
582
|
+
const v = o.variant ?? 'primary';
|
|
583
|
+
const press = o.press ?? 0;
|
|
584
|
+
const hover = o.hover ?? 0;
|
|
585
|
+
const C = this.colors;
|
|
586
|
+
const fill = o.color ?? C.accent;
|
|
587
|
+
if (o.caps) label = String(label).toUpperCase();
|
|
588
|
+
c.save();
|
|
589
|
+
c.globalAlpha *= o.alpha ?? 1;
|
|
590
|
+
c.translate(x + w / 2, y + h / 2);
|
|
591
|
+
c.scale(1 - 0.04 * press, 1 - 0.04 * press);
|
|
592
|
+
c.translate(-(x + w / 2), -(y + h / 2));
|
|
593
|
+
c.beginPath();
|
|
594
|
+
c.roundRect(x, y, w, h, o.r ?? 12);
|
|
595
|
+
if (v === 'primary') {
|
|
596
|
+
const k = this.k;
|
|
597
|
+
const [r, g, b] = rgb(fill);
|
|
598
|
+
c.shadowColor = `rgba(${r}, ${g}, ${b}, ${0.28 * (1 - press)})`;
|
|
599
|
+
c.shadowBlur = 16 * k;
|
|
600
|
+
c.shadowOffsetY = 6 * k;
|
|
601
|
+
c.fillStyle = mix(fill, '#000000', 0.16 * clamp(hover + press));
|
|
602
|
+
c.fill();
|
|
603
|
+
} else if (v === 'secondary') {
|
|
604
|
+
c.fillStyle = mix('#ffffff', '#f2f4f7', clamp(hover + press));
|
|
605
|
+
c.fill();
|
|
606
|
+
c.strokeStyle = C.field;
|
|
607
|
+
c.lineWidth = 1.5;
|
|
608
|
+
c.stroke();
|
|
609
|
+
} else if (hover + press > 0) {
|
|
610
|
+
c.fillStyle = `rgba(16, 24, 40, ${0.05 * clamp(hover + press)})`;
|
|
611
|
+
c.fill();
|
|
612
|
+
}
|
|
613
|
+
c.shadowColor = 'transparent';
|
|
614
|
+
const size = o.size ?? (o.caps ? 18 : 21);
|
|
615
|
+
const tracking = o.caps ? 1.6 : 0;
|
|
616
|
+
const color = v === 'primary' ? '#ffffff' : v === 'ghost' ? C.accent : C.text;
|
|
617
|
+
const labelW = this.measure(label, size, 600, undefined, false, tracking);
|
|
618
|
+
const iconSize = size * 1.05;
|
|
619
|
+
const gap = o.icon || o.loading ? iconSize + 10 : 0;
|
|
620
|
+
let lx = x + w / 2 - (labelW + gap) / 2;
|
|
621
|
+
if (o.loading) {
|
|
622
|
+
this.spinner(lx + iconSize / 2, y + h / 2, iconSize / 2.4, color);
|
|
623
|
+
lx += gap;
|
|
624
|
+
} else if (o.icon) {
|
|
625
|
+
this.icon(o.icon, lx + iconSize / 2, y + h / 2, iconSize, color, 2.2);
|
|
626
|
+
lx += gap;
|
|
627
|
+
}
|
|
628
|
+
this.text(label, lx, y + h / 2 + 0.5, { size, weight: 600, color, tracking });
|
|
629
|
+
c.restore();
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
input(x, y, w, h, o = {}) {
|
|
633
|
+
const c = this.c;
|
|
634
|
+
const C = this.colors;
|
|
635
|
+
const focus = o.focus ?? 0;
|
|
636
|
+
const size = o.size ?? 21;
|
|
637
|
+
c.save();
|
|
638
|
+
c.globalAlpha *= o.alpha ?? 1;
|
|
639
|
+
if (o.label) this.text(o.label, x, y - 24, { size: 19, weight: 600 });
|
|
640
|
+
if (focus > 0) {
|
|
641
|
+
const [r, g, b] = rgb(C.accent);
|
|
642
|
+
c.beginPath();
|
|
643
|
+
c.roundRect(x - 4, y - 4, w + 8, h + 8, 14);
|
|
644
|
+
c.fillStyle = `rgba(${r}, ${g}, ${b}, ${0.16 * focus})`;
|
|
645
|
+
c.fill();
|
|
646
|
+
}
|
|
647
|
+
c.beginPath();
|
|
648
|
+
c.roundRect(x, y, w, h, 11);
|
|
649
|
+
c.fillStyle = '#ffffff';
|
|
650
|
+
c.fill();
|
|
651
|
+
c.strokeStyle = mix(C.field, C.accent, focus);
|
|
652
|
+
c.lineWidth = 1.5;
|
|
653
|
+
c.stroke();
|
|
654
|
+
const pad = 18;
|
|
655
|
+
let tx = x + pad;
|
|
656
|
+
if (o.icon) {
|
|
657
|
+
this.icon(o.icon, tx + 11, y + h / 2, 22, C.faint, 2);
|
|
658
|
+
tx += 34;
|
|
659
|
+
}
|
|
660
|
+
const room = w - (tx - x) - pad - (o.room ?? 0);
|
|
661
|
+
const value = o.value ?? '';
|
|
662
|
+
if (value) this.text(value, tx, y + h / 2 + 0.5, { size, maxW: room });
|
|
663
|
+
else if (o.placeholder) this.text(o.placeholder, tx, y + h / 2 + 0.5, { size, color: C.faint, maxW: room });
|
|
664
|
+
if (o.caret && focus > 0.5 && Math.floor(this.s.t * 2.2) % 2 === 0) {
|
|
665
|
+
const cx = tx + (value ? Math.min(this.measure(value, size), room) : 0) + 2;
|
|
666
|
+
c.fillStyle = C.text;
|
|
667
|
+
c.fillRect(cx, y + h / 2 - size * 0.6, 2, size * 1.2);
|
|
668
|
+
}
|
|
669
|
+
c.restore();
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
// A multi-line field: the value wraps inside it, with a caret at the end.
|
|
673
|
+
textarea(x, y, w, h, o = {}) {
|
|
674
|
+
const size = o.size ?? 21;
|
|
675
|
+
const lh = o.lh ?? size * 1.45;
|
|
676
|
+
this.input(x, y, w, h, { label: o.label, focus: o.focus, alpha: o.alpha, size });
|
|
677
|
+
const pad = 18;
|
|
678
|
+
const value = o.value ?? '';
|
|
679
|
+
if (!value && o.placeholder) {
|
|
680
|
+
this.para(o.placeholder, x + pad, y + pad, w - pad * 2, { size, lh, color: this.colors.faint });
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
const lines = this._wrap(value, w - pad * 2, size, o.weight ?? 400);
|
|
684
|
+
lines.forEach((l, i) => this.text(l, x + pad, y + pad + i * lh, { size, base: 'top' }));
|
|
685
|
+
if (o.caret && (o.focus ?? 0) > 0.5 && Math.floor(this.s.t * 2.2) % 2 === 0) {
|
|
686
|
+
const last = lines[lines.length - 1] ?? '';
|
|
687
|
+
const c = this.c;
|
|
688
|
+
c.fillStyle = this.colors.text;
|
|
689
|
+
c.fillRect(x + pad + this.measure(last, size) + 2, y + pad + (lines.length - 1) * lh + (lh - size * 1.2) / 2, 2, size * 1.2);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
_wrap(str, maxW, size, weight = 400, font) {
|
|
694
|
+
const lines = [];
|
|
695
|
+
for (const para of String(str).split('\n')) {
|
|
696
|
+
let cur = '';
|
|
697
|
+
for (const w of para.split(/\s+/).filter(Boolean)) {
|
|
698
|
+
const next = cur ? cur + ' ' + w : w;
|
|
699
|
+
if (cur && this.measure(next, size, weight, font) > maxW) {
|
|
700
|
+
lines.push(cur);
|
|
701
|
+
cur = w;
|
|
702
|
+
} else cur = next;
|
|
703
|
+
}
|
|
704
|
+
lines.push(cur);
|
|
705
|
+
}
|
|
706
|
+
return lines;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
// The part of `str` shown by now when it appears word by word from `at`,
|
|
710
|
+
// like an AI reply streaming in (wps: words per second).
|
|
711
|
+
stream(str, at, wps = 9) {
|
|
712
|
+
const words = String(str).split(/(\s+)/);
|
|
713
|
+
const n = Math.floor(Math.max(0, this.s.t - this.at(at)) * wps * this.s.pace);
|
|
714
|
+
let shown = 0;
|
|
715
|
+
let out = '';
|
|
716
|
+
for (const part of words) {
|
|
717
|
+
if (/\S/.test(part)) {
|
|
718
|
+
if (shown >= n) break;
|
|
719
|
+
shown++;
|
|
720
|
+
}
|
|
721
|
+
out += part;
|
|
722
|
+
}
|
|
723
|
+
return out.trimEnd();
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
// A dropdown. open 0..1 shows the menu below it, hover is the index of the
|
|
727
|
+
// highlighted option, selected gets a check. Returns each option row's
|
|
728
|
+
// center y, for pointing the cursor at it.
|
|
729
|
+
select(x, y, w, h, o = {}) {
|
|
730
|
+
const C = this.colors;
|
|
731
|
+
const open = o.open ?? 0;
|
|
732
|
+
this.input(x, y, w, h, { label: o.label, value: o.value, placeholder: o.placeholder, focus: o.focus ?? open, alpha: o.alpha, size: o.size, room: 30 });
|
|
733
|
+
this.icon('chevron-down', x + w - 30, y + h / 2, 24, C.muted, 2);
|
|
734
|
+
const rowH = o.rowH ?? 54;
|
|
735
|
+
const opts = o.options ?? [];
|
|
736
|
+
const my = y + h + 12;
|
|
737
|
+
const rows = opts.map((_, i) => my + 8 + i * rowH + rowH / 2);
|
|
738
|
+
if (open <= 0.001) return rows;
|
|
739
|
+
const c = this.c;
|
|
740
|
+
this.over(() => {
|
|
741
|
+
c.save();
|
|
742
|
+
c.globalAlpha *= clamp(open * 1.6) * (o.alpha ?? 1);
|
|
743
|
+
c.translate(x + w / 2, my);
|
|
744
|
+
c.scale(1, lerp(0.92, 1, outCubic(open)));
|
|
745
|
+
c.translate(-(x + w / 2), -my);
|
|
746
|
+
this.card(x, my, w, opts.length * rowH + 16, { r: 14, lift: 0.8 });
|
|
747
|
+
opts.forEach((label, i) => {
|
|
748
|
+
const ry = my + 8 + i * rowH;
|
|
749
|
+
if (o.hover === i) {
|
|
750
|
+
c.beginPath();
|
|
751
|
+
c.roundRect(x + 8, ry, w - 16, rowH, 9);
|
|
752
|
+
c.fillStyle = C.accentTint;
|
|
753
|
+
c.fill();
|
|
754
|
+
}
|
|
755
|
+
const chosen = o.selected === i;
|
|
756
|
+
this.text(label, x + 24, ry + rowH / 2 + 0.5, { size: o.size ?? 21, weight: chosen ? 600 : 400, color: chosen ? C.accent : C.text, maxW: w - 80 });
|
|
757
|
+
if (chosen) this.icon('check', x + w - 34, ry + rowH / 2, 22, C.accent, 2.4);
|
|
758
|
+
});
|
|
759
|
+
c.restore();
|
|
760
|
+
});
|
|
761
|
+
return rows;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
toggle(x, y, on, o = {}) {
|
|
765
|
+
const c = this.c;
|
|
766
|
+
const w = o.w ?? 64;
|
|
767
|
+
const h = o.h ?? 36;
|
|
768
|
+
const p = clamp(on);
|
|
769
|
+
c.save();
|
|
770
|
+
c.globalAlpha *= o.alpha ?? 1;
|
|
771
|
+
c.beginPath();
|
|
772
|
+
c.roundRect(x, y - h / 2, w, h, h / 2);
|
|
773
|
+
c.fillStyle = mix('#e4e7ec', this.colors.accent, p);
|
|
774
|
+
c.fill();
|
|
775
|
+
const r = h / 2 - 4;
|
|
776
|
+
const kx = lerp(x + 4 + r, x + w - 4 - r, outBack(p));
|
|
777
|
+
const k = this.k;
|
|
778
|
+
c.shadowColor = 'rgba(16, 24, 40, 0.18)';
|
|
779
|
+
c.shadowBlur = 6 * k;
|
|
780
|
+
c.shadowOffsetY = 2 * k;
|
|
781
|
+
c.beginPath();
|
|
782
|
+
c.arc(kx, y, r, 0, Math.PI * 2);
|
|
783
|
+
c.fillStyle = '#ffffff';
|
|
784
|
+
c.fill();
|
|
785
|
+
c.restore();
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
checkbox(x, y, on, o = {}) {
|
|
789
|
+
const c = this.c;
|
|
790
|
+
const size = o.size ?? 26;
|
|
791
|
+
const p = clamp(on);
|
|
792
|
+
c.save();
|
|
793
|
+
c.globalAlpha *= o.alpha ?? 1;
|
|
794
|
+
c.beginPath();
|
|
795
|
+
c.roundRect(x - size / 2, y - size / 2, size, size, 7);
|
|
796
|
+
c.fillStyle = mix('#ffffff', this.colors.accent, p);
|
|
797
|
+
c.fill();
|
|
798
|
+
c.strokeStyle = mix(this.colors.field, this.colors.accent, p);
|
|
799
|
+
c.lineWidth = 1.5;
|
|
800
|
+
c.stroke();
|
|
801
|
+
if (p > 0.05) {
|
|
802
|
+
c.globalAlpha *= clamp(p * 2);
|
|
803
|
+
this.icon('check', x, y, size * 0.72, '#ffffff', 3.2);
|
|
804
|
+
}
|
|
805
|
+
c.restore();
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
radio(x, y, on, o = {}) {
|
|
809
|
+
const c = this.c;
|
|
810
|
+
const r = (o.size ?? 26) / 2;
|
|
811
|
+
const p = clamp(on);
|
|
812
|
+
c.save();
|
|
813
|
+
c.globalAlpha *= o.alpha ?? 1;
|
|
814
|
+
c.beginPath();
|
|
815
|
+
c.arc(x, y, r, 0, Math.PI * 2);
|
|
816
|
+
c.fillStyle = '#ffffff';
|
|
817
|
+
c.fill();
|
|
818
|
+
c.strokeStyle = mix(this.colors.field, this.colors.accent, p);
|
|
819
|
+
c.lineWidth = 2;
|
|
820
|
+
c.stroke();
|
|
821
|
+
if (p > 0) {
|
|
822
|
+
c.beginPath();
|
|
823
|
+
c.arc(x, y, r * 0.55 * outBack(p), 0, Math.PI * 2);
|
|
824
|
+
c.fillStyle = this.colors.accent;
|
|
825
|
+
c.fill();
|
|
826
|
+
}
|
|
827
|
+
c.restore();
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
// A selectable option chip. It grows by its check mark when selected, so
|
|
831
|
+
// leave that room (u.chipWidth(label, o, true)) next to it.
|
|
832
|
+
chip(label, x, y, o = {}) {
|
|
833
|
+
const c = this.c;
|
|
834
|
+
const C = this.colors;
|
|
835
|
+
const size = o.size ?? 20;
|
|
836
|
+
const sel = clamp(o.selected ?? 0);
|
|
837
|
+
const h = size * 2.2;
|
|
838
|
+
const w = this.measure(label, size, 500) + size * 1.6 + sel * size * 1.1;
|
|
839
|
+
c.save();
|
|
840
|
+
c.globalAlpha *= o.alpha ?? 1;
|
|
841
|
+
c.beginPath();
|
|
842
|
+
c.roundRect(x, y - h / 2, w, h, h / 2);
|
|
843
|
+
c.fillStyle = mix('#ffffff', C.accentTint, sel);
|
|
844
|
+
c.fill();
|
|
845
|
+
c.strokeStyle = mix(C.field, C.accent, sel);
|
|
846
|
+
c.lineWidth = 1.5 + sel;
|
|
847
|
+
c.stroke();
|
|
848
|
+
let tx = x + size * 0.8;
|
|
849
|
+
if (sel > 0.05) {
|
|
850
|
+
c.save();
|
|
851
|
+
c.globalAlpha *= sel;
|
|
852
|
+
this.icon('check', tx + size * 0.4, y, size * 0.85, C.accent, 2.6);
|
|
853
|
+
c.restore();
|
|
854
|
+
tx += sel * size * 1.1;
|
|
855
|
+
}
|
|
856
|
+
this.text(label, tx, y + 0.5, { size, weight: sel > 0.5 ? 600 : 500, color: mix(C.text, C.accent, sel) });
|
|
857
|
+
c.restore();
|
|
858
|
+
return w;
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
chipWidth(label, o = {}, selected = false) {
|
|
862
|
+
const size = o.size ?? 20;
|
|
863
|
+
return this.measure(label, size, selected ? 600 : 500) + size * 1.6 + (selected ? size * 1.1 : 0);
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
spinner(x, y, r, color = this.colors.accent) {
|
|
867
|
+
const c = this.c;
|
|
868
|
+
const a = this.s.t * 7;
|
|
869
|
+
c.save();
|
|
870
|
+
c.lineWidth = Math.max(2, r * 0.32);
|
|
871
|
+
c.lineCap = 'round';
|
|
872
|
+
c.strokeStyle = color;
|
|
873
|
+
c.globalAlpha *= 0.25;
|
|
874
|
+
c.beginPath();
|
|
875
|
+
c.arc(x, y, r, 0, Math.PI * 2);
|
|
876
|
+
c.stroke();
|
|
877
|
+
c.globalAlpha /= 0.25;
|
|
878
|
+
c.beginPath();
|
|
879
|
+
c.arc(x, y, r, a, a + Math.PI * 0.6);
|
|
880
|
+
c.stroke();
|
|
881
|
+
c.restore();
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
progress(x, y, w, p, o = {}) {
|
|
885
|
+
const c = this.c;
|
|
886
|
+
const h = o.h ?? 10;
|
|
887
|
+
c.save();
|
|
888
|
+
c.beginPath();
|
|
889
|
+
c.roundRect(x, y - h / 2, w, h, h / 2);
|
|
890
|
+
c.fillStyle = '#eaecf0';
|
|
891
|
+
c.fill();
|
|
892
|
+
if (p > 0) {
|
|
893
|
+
c.beginPath();
|
|
894
|
+
c.roundRect(x, y - h / 2, Math.max(h, w * clamp(p)), h, h / 2);
|
|
895
|
+
c.fillStyle = o.color ?? this.colors.accent;
|
|
896
|
+
c.fill();
|
|
897
|
+
}
|
|
898
|
+
c.restore();
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
avatar(x, y, r, initials = '', o = {}) {
|
|
902
|
+
const c = this.c;
|
|
903
|
+
c.save();
|
|
904
|
+
c.beginPath();
|
|
905
|
+
c.arc(x, y, r, 0, Math.PI * 2);
|
|
906
|
+
c.fillStyle = o.bg ?? this.colors.accentTint;
|
|
907
|
+
c.fill();
|
|
908
|
+
if (o.image) {
|
|
909
|
+
const img = this.s.engine.image(o.image);
|
|
910
|
+
c.clip();
|
|
911
|
+
const side = Math.min(img.naturalWidth, img.naturalHeight);
|
|
912
|
+
c.drawImage(img, (img.naturalWidth - side) / 2, (img.naturalHeight - side) / 2, side, side, x - r, y - r, r * 2, r * 2);
|
|
913
|
+
}
|
|
914
|
+
c.restore();
|
|
915
|
+
if (initials && !o.image) this.text(initials, x, y + 1, { size: Math.max(17, r * 0.8), weight: 600, color: o.color ?? this.colors.accent, align: 'center' });
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
icon(name, x, y, size, color = this.colors.text, weight = 2) {
|
|
919
|
+
if (this.hidden) return;
|
|
920
|
+
this.s._iconAt(name, x, y, size, color, 1, 1, weight);
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
// Grey bars standing in for text, for article bodies and backgrounds.
|
|
924
|
+
lines(x, y, w, n, o = {}) {
|
|
925
|
+
const c = this.c;
|
|
926
|
+
const gap = o.gap ?? 22;
|
|
927
|
+
c.save();
|
|
928
|
+
c.fillStyle = o.color ?? '#e9edf3';
|
|
929
|
+
for (let i = 0; i < n; i++) {
|
|
930
|
+
const lw = i === n - 1 ? w * (o.last ?? 0.6) : w * (0.88 + 0.12 * Math.abs(Math.sin(i * 7.3 + (o.seed ?? 0))));
|
|
931
|
+
c.beginPath();
|
|
932
|
+
c.roundRect(x, y + i * gap, lw, o.h ?? 9, (o.h ?? 9) / 2);
|
|
933
|
+
c.fill();
|
|
934
|
+
}
|
|
935
|
+
c.restore();
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
// The brand logo (brand.logo in video.json, or o.src), w wide, centered on
|
|
939
|
+
// (x, y) unless align is "left". Returns its height.
|
|
940
|
+
logo(x, y, w, o = {}) {
|
|
941
|
+
const src = o.src ?? this.logoSrc;
|
|
942
|
+
if (!src) throw new SceneError('u.logo() needs a logo: set "brand": { "logo": "assets/logo.svg" } in video.json or pass { src }');
|
|
943
|
+
const img = this.s.engine.image(src);
|
|
944
|
+
const h = (w * img.naturalHeight) / img.naturalWidth;
|
|
945
|
+
const c = this.c;
|
|
946
|
+
c.save();
|
|
947
|
+
c.globalAlpha *= o.alpha ?? 1;
|
|
948
|
+
c.drawImage(img, o.align === 'left' ? x : x - w / 2, y - h / 2, w, h);
|
|
949
|
+
c.restore();
|
|
950
|
+
return h;
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
// ---------- the cursor ----------
|
|
954
|
+
|
|
955
|
+
// keys: [{ at, x, y }, ...]. The first key places the cursor; each later
|
|
956
|
+
// one with x, y glides it there starting at `at` (dur, default 0.7 s). A
|
|
957
|
+
// key with click: true presses at `at` and plays a click. Draw the cursor
|
|
958
|
+
// last so it sits on top. Returns { x, y, press } or null before it shows.
|
|
959
|
+
cursor(keys, o = {}) {
|
|
960
|
+
const s = this.s;
|
|
961
|
+
const first = keys[0];
|
|
962
|
+
const start = this.at(first.at ?? 0);
|
|
963
|
+
let x = first.x;
|
|
964
|
+
let y = first.y;
|
|
965
|
+
let press = 0;
|
|
966
|
+
const ripples = [];
|
|
967
|
+
for (let i = 1; i < keys.length; i++) {
|
|
968
|
+
const k = keys[i];
|
|
969
|
+
const a = this.at(k.at);
|
|
970
|
+
if (k.click) s.sfx('click', a, { gain: 0.9 });
|
|
971
|
+
if (s.t < a) continue;
|
|
972
|
+
if (k.x !== undefined) {
|
|
973
|
+
const p = inOutCubic(clamp((s.t - a) / ((k.dur ?? 0.7) / s.pace)));
|
|
974
|
+
if (p > 0 && p < 1) s.engine.moving = true;
|
|
975
|
+
// A slight arc looks like a hand moved it.
|
|
976
|
+
const dx = k.x - x;
|
|
977
|
+
const dy = k.y - y;
|
|
978
|
+
const arc = Math.sin(Math.PI * p) * (k.arc ?? 0.08);
|
|
979
|
+
const nx = lerp(x, k.x, p) - dy * arc;
|
|
980
|
+
y = lerp(y, k.y, p) + dx * arc;
|
|
981
|
+
x = nx;
|
|
982
|
+
}
|
|
983
|
+
if (k.click) {
|
|
984
|
+
const since = s.t - a;
|
|
985
|
+
press = Math.max(press, bell(since / (0.26 / s.pace)));
|
|
986
|
+
if (since < 0.6 / s.pace) ripples.push({ x, y, p: since / (0.6 / s.pace) });
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
if (s.t < start) return null;
|
|
990
|
+
const c = this.c;
|
|
991
|
+
const [r, g, b] = rgb(this.colors.accent);
|
|
992
|
+
for (const rp of ripples) {
|
|
993
|
+
c.save();
|
|
994
|
+
c.beginPath();
|
|
995
|
+
c.arc(rp.x, rp.y, lerp(6, 38, outCubic(rp.p)), 0, Math.PI * 2);
|
|
996
|
+
c.fillStyle = `rgba(${r}, ${g}, ${b}, ${0.22 * (1 - rp.p)})`;
|
|
997
|
+
c.fill();
|
|
998
|
+
c.restore();
|
|
999
|
+
}
|
|
1000
|
+
let alpha = clamp((s.t - start) / 0.25);
|
|
1001
|
+
if (o.out !== undefined) alpha *= 1 - this._p(o.out, 0.3, 'in');
|
|
1002
|
+
if (alpha <= 0) return { x, y, press };
|
|
1003
|
+
const size = (o.size ?? 34) * (1 - 0.14 * press);
|
|
1004
|
+
c.save();
|
|
1005
|
+
c.globalAlpha *= alpha;
|
|
1006
|
+
c.translate(x, y);
|
|
1007
|
+
c.scale(size / 24, size / 24);
|
|
1008
|
+
const k = this.k;
|
|
1009
|
+
c.shadowColor = 'rgba(0, 0, 0, 0.28)';
|
|
1010
|
+
c.shadowBlur = 5 * k;
|
|
1011
|
+
c.shadowOffsetY = 2 * k;
|
|
1012
|
+
const arrow = new Path2D('M1 1 L1 19.5 L5.6 15.3 L8.7 22.4 L11.9 21 L8.9 14.1 L15 14.1 Z');
|
|
1013
|
+
c.lineJoin = 'round';
|
|
1014
|
+
c.strokeStyle = '#ffffff';
|
|
1015
|
+
c.lineWidth = 3;
|
|
1016
|
+
c.stroke(arrow);
|
|
1017
|
+
c.shadowColor = 'transparent';
|
|
1018
|
+
c.fillStyle = '#101828';
|
|
1019
|
+
c.fill(arrow);
|
|
1020
|
+
c.restore();
|
|
1021
|
+
return { x, y, press };
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
// How far a click at `at` presses a button right now (0..1..0).
|
|
1025
|
+
press(at) {
|
|
1026
|
+
return bell((this.s.t - this.at(at)) / (0.26 / this.s.pace));
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
// The part of `str` typed by now, starting at `at`, with typing sounds
|
|
1030
|
+
// (o.gain, or o.sfx: false for none; keep long typing quiet under the voice).
|
|
1031
|
+
typed(str, at, cps = 17, o = {}) {
|
|
1032
|
+
const a = this.at(at);
|
|
1033
|
+
const dur = str.length / cps / this.s.pace;
|
|
1034
|
+
if (o.sfx !== false) this.s.sfx('type', a, { dur, gain: o.gain ?? 0.55 });
|
|
1035
|
+
return str.slice(0, Math.floor(clamp((this.s.t - a) / dur) * str.length));
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
// A number counting from `from` to `to`, starting at `at`.
|
|
1039
|
+
count(to, at, dur = 1, from = 0) {
|
|
1040
|
+
return Math.round(lerp(from, to, outCubic(this._p(at, dur, 'linear'))));
|
|
1041
|
+
}
|
|
1042
|
+
}
|