Remove voiceover from the Mobile SDK explorer
Drops speechSynthesis narration, the per-module mute toggle, and the spoken tab-click announcement. Each module's timing reverts to its original snappy pace (e.g. Location zones: 32s -> 11s), since the longer durations were only there to give the voice room to finish. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -25,162 +25,112 @@ type Spec = { dur: number; steps: Step[] }
|
||||
|
||||
const SCRIPTS: Record<string, Spec> = {
|
||||
score: {
|
||||
dur: 26546,
|
||||
dur: 7200,
|
||||
steps: [
|
||||
{ t: 0, s: 0, cap: 'Guardian opens with the score from the last check — <b>81</b>.' },
|
||||
{ t: 4711, s: 1, cap: 'Re-scanning all nine protection modules on device.', add: [['.js-ring', 'scanning']] },
|
||||
{ t: 7909, s: 2, cap: '<b>Device trust</b> — verified, patch level current.' },
|
||||
{ t: 11107, s: 3, cap: '<b>Apps & permissions</b> — no risky grants detected.' },
|
||||
{ t: 14683, s: 4, cap: '<b>Wi-Fi security</b> — BT-T5F97X assessed as low risk.' },
|
||||
{ t: 18259, s: 5, cap: 'Score recomputed and the delta shown: <b>81 → 93</b>.', rm: [['.js-ring', 'scanning']], num: [['.js-score', 81, 93, 900]], ring: [['.js-arc', 81, 93, 900]] },
|
||||
{ t: 22213, cap: 'Ranked remediation sits behind one tap — no dead ends.', flash: [['.js-improve', 'glow', 900]] },
|
||||
{ t: 800, s: 1, cap: 'Re-scanning all nine protection modules on device.', add: [['.js-ring', 'scanning']] },
|
||||
{ t: 2200, s: 2, cap: '<b>Device trust</b> — verified, patch level current.' },
|
||||
{ t: 3200, s: 3, cap: '<b>Apps & permissions</b> — no risky grants detected.' },
|
||||
{ t: 4200, s: 4, cap: '<b>Wi-Fi security</b> — BT-T5F97X assessed as low risk.' },
|
||||
{ t: 5000, s: 5, cap: 'Score recomputed and the delta shown: <b>81 → 93</b>.', rm: [['.js-ring', 'scanning']], num: [['.js-score', 81, 93, 900]], ring: [['.js-arc', 81, 93, 900]] },
|
||||
{ t: 6300, cap: 'Ranked remediation sits behind one tap — no dead ends.', flash: [['.js-improve', 'glow', 900]] },
|
||||
],
|
||||
},
|
||||
protection: {
|
||||
dur: 17503,
|
||||
dur: 6800,
|
||||
steps: [
|
||||
{ t: 0, s: 0, cap: 'The Protection tab covers the connection itself.' },
|
||||
{ t: 3198, s: 1, cap: "DNS filter reports the day's blocks.", num: [['.js-n', 0, 40, 1100]] },
|
||||
{ t: 6018, s: 2, cap: 'Call screening — <b>no scam calls today</b>.' },
|
||||
{ t: 9216, s: 3, cap: 'SIM integrity — no carrier or slot change detected.' },
|
||||
{ t: 13170, cap: 'Any card taps through to its full timestamped event log.', flash: [['.js-sb', 'tap', 1300]] },
|
||||
{ t: 700, s: 1, cap: "DNS filter reports the day's blocks.", num: [['.js-n', 0, 40, 1100]] },
|
||||
{ t: 2500, s: 2, cap: 'Call screening — <b>no scam calls today</b>.' },
|
||||
{ t: 3700, s: 3, cap: 'SIM integrity — no carrier or slot change detected.' },
|
||||
{ t: 5000, cap: 'Any card taps through to its full timestamped event log.', flash: [['.js-sb', 'tap', 1300]] },
|
||||
],
|
||||
},
|
||||
dns: {
|
||||
dur: 22591,
|
||||
dur: 8600,
|
||||
steps: [
|
||||
{ t: 0, s: 0, cap: '285 blocked of 1,116 lookups so far today.' },
|
||||
{ t: 3576, s: 1, cap: 'User taps a link in a WhatsApp group message.', set: [['.js-chip', 'Resolving…']], add: [['.js-chip', 'wait'], ['.js-chip', 'pulse']] },
|
||||
{ t: 7530, s: 2, cap: '<b>whtaspp-group.pages.dev</b> — typosquat, matched in 40 ms.', set: [['.js-chip', 'Blocked']], rm: [['.js-chip', 'wait'], ['.js-chip', 'pulse']] },
|
||||
{ t: 10728, s: 3, cap: 'Connection never opens. The block is logged and shown to the user.', add: [['.js-newrow', 'in'], ['.js-newrow', 'hot']], num: [['.js-blocked', 285, 288, 800], ['.js-req', 1116, 1119, 800]] },
|
||||
{ t: 15817, s: 4, cap: 'Counts refresh on demand.', flash: [['.js-refresh', 'press', 300]], rm: [['.js-newrow', 'hot']] },
|
||||
{ t: 17880, cap: 'Every verdict is also available to your fraud platform by webhook.' },
|
||||
{ t: 900, s: 1, cap: 'User taps a link in a WhatsApp group message.', set: [['.js-chip', 'Resolving…']], add: [['.js-chip', 'wait'], ['.js-chip', 'pulse']] },
|
||||
{ t: 2300, s: 2, cap: '<b>whtaspp-group.pages.dev</b> — typosquat, matched in 40 ms.', set: [['.js-chip', 'Blocked']], rm: [['.js-chip', 'wait'], ['.js-chip', 'pulse']] },
|
||||
{ t: 3100, s: 3, cap: 'Connection never opens. The block is logged and shown to the user.', add: [['.js-newrow', 'in'], ['.js-newrow', 'hot']], num: [['.js-blocked', 285, 288, 800], ['.js-req', 1116, 1119, 800]] },
|
||||
{ t: 5000, s: 4, cap: 'Counts refresh on demand.', flash: [['.js-refresh', 'press', 300]], rm: [['.js-newrow', 'hot']] },
|
||||
{ t: 6400, cap: 'Every verdict is also available to your fraud platform by webhook.' },
|
||||
],
|
||||
},
|
||||
calls: {
|
||||
dur: 24654,
|
||||
dur: 9200,
|
||||
steps: [
|
||||
{ t: 0, s: 0, cap: 'Home screen. An unknown number starts ringing.' },
|
||||
{ t: 3198, s: 1, cap: 'Inbound call from <b>07813996004</b> — reputation lookup fires.', add: [['.js-verdict', 'pulse']] },
|
||||
{ t: 6774, s: 2, cap: 'Verdict returned <i>before answer</i>: likely scam, confidence 91.', set: [['.js-verdict', 'Likely scam · 91']], add: [['.js-verdict', 'bad']], rm: [['.js-verdict', 'pulse']] },
|
||||
{ t: 10350, s: 3, cap: 'Call ends. Guardian asks how it went.' },
|
||||
{ t: 13548, s: 4, cap: 'One tap: the user labels it <b>Scam</b>.', flash: [['.js-scam', 'hit', 1400]] },
|
||||
{ t: 16746, s: 5, cap: 'Report accepted and folded into the shared reputation graph.' },
|
||||
{ t: 20700, s: 6, cap: 'Detection sharpens for every other subscriber on your network.' },
|
||||
{ t: 700, s: 1, cap: 'Inbound call from <b>07813996004</b> — reputation lookup fires.', add: [['.js-verdict', 'pulse']] },
|
||||
{ t: 2100, s: 2, cap: 'Verdict returned <i>before answer</i>: likely scam, confidence 91.', set: [['.js-verdict', 'Likely scam · 91']], add: [['.js-verdict', 'bad']], rm: [['.js-verdict', 'pulse']] },
|
||||
{ t: 3700, s: 3, cap: 'Call ends. Guardian asks how it went.' },
|
||||
{ t: 5300, s: 4, cap: 'One tap: the user labels it <b>Scam</b>.', flash: [['.js-scam', 'hit', 1400]] },
|
||||
{ t: 6500, s: 5, cap: 'Report accepted and folded into the shared reputation graph.' },
|
||||
{ t: 7700, s: 6, cap: 'Detection sharpens for every other subscriber on your network.' },
|
||||
],
|
||||
},
|
||||
sim: {
|
||||
dur: 18431,
|
||||
dur: 6600,
|
||||
steps: [
|
||||
{ t: 0, s: 0, cap: 'Screen opens and reads phone state.', add: [['.js-simh', 'pulse']] },
|
||||
{ t: 2820, s: 1, cap: 'Read completes — <b>no SIM changes detected</b>.', set: [['.js-simh', 'No SIM changes detected'], ['.js-simp', 'No SIM changes detected.']], rm: [['.js-simh', 'pulse']], flash: [['.js-simh', 'swap', 600]] },
|
||||
{ t: 6018, s: 2, cap: 'Carrier recorded: <b>EE</b>.' },
|
||||
{ t: 7703, s: 3, cap: 'Slot configuration: single SIM.' },
|
||||
{ t: 9766, s: 4, cap: 'Change history: none on record.' },
|
||||
{ t: 12207, cap: 'Had this changed, the alert would go to the recovery email — not this screen.' },
|
||||
{ t: 1500, s: 1, cap: 'Read completes — <b>no SIM changes detected</b>.', set: [['.js-simh', 'No SIM changes detected'], ['.js-simp', 'No SIM changes detected.']], rm: [['.js-simh', 'pulse']], flash: [['.js-simh', 'swap', 600]] },
|
||||
{ t: 2500, s: 2, cap: 'Carrier recorded: <b>EE</b>.' },
|
||||
{ t: 3300, s: 3, cap: 'Slot configuration: single SIM.' },
|
||||
{ t: 4100, s: 4, cap: 'Change history: none on record.' },
|
||||
{ t: 5200, cap: 'Had this changed, the alert would go to the recovery email — not this screen.' },
|
||||
],
|
||||
},
|
||||
perms: {
|
||||
dur: 25789,
|
||||
dur: 8400,
|
||||
steps: [
|
||||
{ t: 0, s: 0, cap: 'User taps <b>Scan again</b>.', flash: [['.js-scan', 'press', 300]] },
|
||||
{ t: 2063, s: 1, cap: 'Scanning installed apps for the grants fraudsters abuse.' },
|
||||
{ t: 5639, s: 2, cap: '<b>Microphone</b> — high risk. 1 app holds it, 1 to review.' },
|
||||
{ t: 10350, s: 3, cap: '<b>Phone state</b> — medium. Can read your number and call state.' },
|
||||
{ t: 15061, s: 4, cap: '<b>Contacts</b> — medium, and 1 app still to review.' },
|
||||
{ t: 19015, s: 5, cap: '<b>Post notifications</b> — low risk, already accepted.' },
|
||||
{ t: 22213, cap: 'Ranked by how fraud actually works, not alphabetically.' },
|
||||
{ t: 900, s: 1, cap: 'Scanning installed apps for the grants fraudsters abuse.' },
|
||||
{ t: 2400, s: 2, cap: '<b>Microphone</b> — high risk. 1 app holds it, 1 to review.' },
|
||||
{ t: 3400, s: 3, cap: '<b>Phone state</b> — medium. Can read your number and call state.' },
|
||||
{ t: 4400, s: 4, cap: '<b>Contacts</b> — medium, and 1 app still to review.' },
|
||||
{ t: 5400, s: 5, cap: '<b>Post notifications</b> — low risk, already accepted.' },
|
||||
{ t: 6600, cap: 'Ranked by how fraud actually works, not alphabetically.' },
|
||||
],
|
||||
},
|
||||
zones: {
|
||||
dur: 32013,
|
||||
dur: 11200,
|
||||
steps: [
|
||||
{ t: 0, s: 0, cap: 'Empty map. No zones configured yet.' },
|
||||
{ t: 2820, s: 1, cap: "User drops a pin and draws the boundary — <b>Jakarta Town Hall</b>." },
|
||||
{ t: 7909, s: 2, cap: 'Radius set to <b>200 m</b>. The geofence is armed.', num: [['.js-rad', 0, 200, 700]] },
|
||||
{ t: 11863, s: 3, cap: "Zone saved. It now appears in the user's list." },
|
||||
{ t: 15817, s: 4, cap: 'They arrive — an enter event is logged, timestamped.', add: [['.js-noev', 'gone']] },
|
||||
{ t: 19771, s: 5, cap: 'Later, they cross back out of the boundary.' },
|
||||
{ t: 23347, s: 6, cap: 'Guardian notifies the parent the moment they leave the zone.' },
|
||||
{ t: 27680, cap: 'The same signal drives impossible-travel checks for your fraud engine.' },
|
||||
{ t: 800, s: 1, cap: "User drops a pin and draws the boundary — <b>Jakarta Town Hall</b>." },
|
||||
{ t: 2000, s: 2, cap: 'Radius set to <b>200 m</b>. The geofence is armed.', num: [['.js-rad', 0, 200, 700]] },
|
||||
{ t: 3300, s: 3, cap: "Zone saved. It now appears in the user's list." },
|
||||
{ t: 4700, s: 4, cap: 'They arrive — an enter event is logged, timestamped.', add: [['.js-noev', 'gone']] },
|
||||
{ t: 6800, s: 5, cap: 'Later, they cross back out of the boundary.' },
|
||||
{ t: 8300, s: 6, cap: 'Guardian notifies the parent the moment they leave the zone.' },
|
||||
{ t: 10100, cap: 'The same signal drives impossible-travel checks for your fraud engine.' },
|
||||
],
|
||||
},
|
||||
identity: {
|
||||
dur: 19771,
|
||||
dur: 7400,
|
||||
steps: [
|
||||
{ t: 0, s: 0, cap: 'Both identity checks are long-running and start on open.', add: [['.js-locb', 'pulse'], ['.js-idb', 'pulse']] },
|
||||
{ t: 3954, s: 1, cap: 'Location analysis resolves — <b>no unusual travel detected</b>.', set: [['.js-locb', 'Good'], ['.js-locp', 'No unusual travel detected.']], add: [['.js-locb', 'good']], rm: [['.js-locb', 'pulse'], ['.js-locb', 'wait']], flash: [['.js-locb', 'swap', 600]] },
|
||||
{ t: 7530, s: 2, cap: 'Breach monitoring resolves — <b>1 monitored identity, no breaches</b>.', set: [['.js-idb', 'Good'], ['.js-idp', '1 monitored identity — no breaches found.']], add: [['.js-idb', 'good']], rm: [['.js-idb', 'pulse'], ['.js-idb', 'wait']], flash: [['.js-idb', 'swap', 600]] },
|
||||
{ t: 11484, cap: 'Re-checked continuously as new breach corpora land.' },
|
||||
{ t: 14682, cap: 'A positive finding escalates by webhook — not just an on-device toast.' },
|
||||
{ t: 1100, s: 1, cap: 'Location analysis resolves — <b>no unusual travel detected</b>.', set: [['.js-locb', 'Good'], ['.js-locp', 'No unusual travel detected.']], add: [['.js-locb', 'good']], rm: [['.js-locb', 'pulse'], ['.js-locb', 'wait']], flash: [['.js-locb', 'swap', 600]] },
|
||||
{ t: 3000, s: 2, cap: 'Breach monitoring resolves — <b>1 monitored identity, no breaches</b>.', set: [['.js-idb', 'Good'], ['.js-idp', '1 monitored identity — no breaches found.']], add: [['.js-idb', 'good']], rm: [['.js-idb', 'pulse'], ['.js-idb', 'wait']], flash: [['.js-idb', 'swap', 600]] },
|
||||
{ t: 4700, cap: 'Re-checked continuously as new breach corpora land.' },
|
||||
{ t: 6000, cap: 'A positive finding escalates by webhook — not just an on-device toast.' },
|
||||
],
|
||||
},
|
||||
settings: {
|
||||
dur: 29572,
|
||||
dur: 9400,
|
||||
steps: [
|
||||
{ t: 0, s: 0, cap: 'Every module is opt-in and starts off.' },
|
||||
{ t: 3198, s: 1, cap: '<b>Safe browsing</b> on — DNS-level phishing protection.', add: [['.js-sw1', 'on']] },
|
||||
{ t: 6396, s: 2, cap: '<b>Scam call warnings</b> on.', add: [['.js-sw2', 'on']] },
|
||||
{ t: 8459, s: 3, cap: '<b>SIM & carrier</b> on — and the reason for phone-state access is stated.', add: [['.js-sw3', 'on']] },
|
||||
{ t: 13926, s: 4, cap: "A stolen phone can't warn you on its own screen — so alerts go out-of-band.", type: [['.js-email', 'jason.reid@icloud.com', 1500]], add: [['.js-email', 'filled']] },
|
||||
{ t: 20150, s: 5, cap: 'Address verified by code. That channel now carries SIM and location alerts.', flash: [['.js-send', 'press', 300]] },
|
||||
{ t: 25239, cap: 'Consent is revocable per module, and every string is localisable.' },
|
||||
{ t: 800, s: 1, cap: '<b>Safe browsing</b> on — DNS-level phishing protection.', add: [['.js-sw1', 'on']] },
|
||||
{ t: 2000, s: 2, cap: '<b>Scam call warnings</b> on.', add: [['.js-sw2', 'on']] },
|
||||
{ t: 3200, s: 3, cap: '<b>SIM & carrier</b> on — and the reason for phone-state access is stated.', add: [['.js-sw3', 'on']] },
|
||||
{ t: 4500, s: 4, cap: "A stolen phone can't warn you on its own screen — so alerts go out-of-band.", type: [['.js-email', 'jason.reid@icloud.com', 1500]], add: [['.js-email', 'filled']] },
|
||||
{ t: 6800, s: 5, cap: 'Address verified by code. That channel now carries SIM and location alerts.', flash: [['.js-send', 'press', 300]] },
|
||||
{ t: 7900, cap: 'Consent is revocable per module, and every string is localisable.' },
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
const fmt = (ms: number) => '0:' + String(Math.floor(ms / 1000)).padStart(2, '0')
|
||||
|
||||
/** Strips markup/entities from a caption so it can be handed to speechSynthesis. */
|
||||
function captionToText(html: string): string {
|
||||
const div = document.createElement('div')
|
||||
div.innerHTML = html
|
||||
return (div.textContent || '').trim()
|
||||
}
|
||||
|
||||
type MutedRef = { current: boolean }
|
||||
|
||||
/** Speaks plain text with a soft, natural tone, resolving `onDone` once the
|
||||
* utterance actually finishes (or errors) — never on a guessed timeout, so
|
||||
* callers can advance only once the voice has truly caught up. */
|
||||
function speakText(text: string, onDone?: () => void): void {
|
||||
const finish = () => onDone?.()
|
||||
const synth = window.speechSynthesis
|
||||
if (!text || !synth) { finish(); return }
|
||||
let done = false
|
||||
const once = () => { if (done) return; done = true; finish() }
|
||||
let started = false
|
||||
const speakNow = () => {
|
||||
if (started) return
|
||||
started = true
|
||||
synth.cancel()
|
||||
const u = new SpeechSynthesisUtterance(text)
|
||||
u.lang = 'en-GB'; u.rate = 1; u.pitch = 0.92; u.volume = 0.78
|
||||
u.onend = once
|
||||
u.onerror = once
|
||||
const vs = synth.getVoices()
|
||||
const v = vs.find((x) => /en-GB/i.test(x.lang) && /natural|neural|online/i.test(x.name) && /libby|sonia|hazel|serena/i.test(x.name))
|
||||
|| vs.find((x) => /en-GB/i.test(x.lang) && /natural|neural|online/i.test(x.name))
|
||||
|| vs.find((x) => /en-GB/i.test(x.lang) && /libby|sonia|hazel|serena/i.test(x.name))
|
||||
|| vs.find((x) => /en-GB/i.test(x.lang) && /female|google uk english female|samantha/i.test(x.name))
|
||||
|| vs.find((x) => /en-GB/i.test(x.lang))
|
||||
|| vs.find((x) => /female|zira|samantha|susan|karen/i.test(x.name) && /^en/i.test(x.lang))
|
||||
|| vs.find((x) => /^en/i.test(x.lang))
|
||||
if (v) u.voice = v
|
||||
synth.speak(u)
|
||||
}
|
||||
// getVoices() often returns an empty list on the very first call — the
|
||||
// browser loads voices asynchronously.
|
||||
if (synth.getVoices().length === 0) {
|
||||
const onReady = () => { synth.removeEventListener('voiceschanged', onReady); speakNow() }
|
||||
synth.addEventListener('voiceschanged', onReady)
|
||||
// Safety net: if voiceschanged never fires (some browsers), speak anyway.
|
||||
setTimeout(() => { if (!done && synth.getVoices().length === 0) speakNow() }, 400)
|
||||
} else {
|
||||
speakNow()
|
||||
}
|
||||
}
|
||||
|
||||
class Reel {
|
||||
root: ParentNode
|
||||
p: HTMLElement
|
||||
@@ -197,18 +147,15 @@ class Reel {
|
||||
t = 0
|
||||
i = 0
|
||||
playing = false
|
||||
playToken = 0
|
||||
pendingUnstick: (() => void) | null = null
|
||||
raf = 0
|
||||
reduced: boolean
|
||||
muted: MutedRef
|
||||
|
||||
constructor(panel: HTMLElement, spec: Spec, reduced: boolean, muted: MutedRef) {
|
||||
constructor(panel: HTMLElement, spec: Spec, reduced: boolean) {
|
||||
this.root = panel
|
||||
this.p = panel
|
||||
this.ap = panel.querySelector('.ap')!
|
||||
this.spec = spec
|
||||
this.reduced = reduced
|
||||
this.muted = muted
|
||||
this.fill = panel.querySelector('.reel-fill')!
|
||||
this.cap = panel.querySelector('.reel-cap')!
|
||||
this.el = panel.querySelector('.js-el')!
|
||||
@@ -227,17 +174,11 @@ class Reel {
|
||||
q(sel: string) { return this.ap.querySelector<HTMLElement>(sel) }
|
||||
remember(elx: Element) { if (!this.base.has(elx)) this.base.set(elx, elx.textContent || '') }
|
||||
clear() {
|
||||
this.playToken++
|
||||
cancelAnimationFrame(this.raf)
|
||||
this.timers.forEach(clearTimeout); this.timers = []
|
||||
this.tweens.forEach((id) => cancelAnimationFrame(id)); this.tweens = []
|
||||
this.applied.forEach(([elx, c]) => elx.classList.remove(c)); this.applied = []
|
||||
this.base.forEach((txt, elx) => { elx.textContent = txt })
|
||||
try { window.speechSynthesis?.cancel() } catch { /* noop */ }
|
||||
}
|
||||
/** Speaks a caption's plain text, calling onDone once it actually finishes. */
|
||||
speak(html: string, onDone?: () => void) {
|
||||
if (this.reduced || this.muted.current) { onDone?.(); return }
|
||||
speakText(captionToText(html), onDone)
|
||||
}
|
||||
reset() {
|
||||
this.clear(); this.t = 0; this.i = 0; this.playing = false
|
||||
@@ -284,76 +225,34 @@ class Reel {
|
||||
;(st.ring || []).forEach(([s, , b]) => { const elx = this.q(s); if (elx) elx.setAttribute('stroke-dashoffset', off(b).toFixed(2)) })
|
||||
;(st.type || []).forEach(([s, txt]) => { const elx = this.q(s); if (elx) { this.remember(elx); elx.textContent = txt } })
|
||||
})
|
||||
if (last && last.cap) { this.cap.innerHTML = last.cap; this.speak(last.cap) }
|
||||
if (last && last.cap) this.cap.innerHTML = last.cap
|
||||
this.paint()
|
||||
}
|
||||
paint() {
|
||||
this.fill.style.width = (100 * this.t / this.spec.dur).toFixed(1) + '%'
|
||||
this.el.textContent = fmt(Math.min(this.t, this.spec.dur))
|
||||
}
|
||||
/** Advances step by step, waiting for each caption's voiceover to actually
|
||||
* finish (plus a small settle beat) before moving on — so playback paces
|
||||
* itself to the voice instead of a fixed guess at how long speech takes. */
|
||||
async play() {
|
||||
play() {
|
||||
if (this.playing) return
|
||||
if (this.t >= this.spec.dur) this.reset()
|
||||
this.playing = true; this.pp.textContent = '▮▮'
|
||||
const token = ++this.playToken
|
||||
const steps = this.spec.steps
|
||||
while (this.playing && token === this.playToken && this.i < steps.length) {
|
||||
const st = steps[this.i]
|
||||
this.apply(st)
|
||||
const nextT = this.i + 1 < steps.length ? steps[this.i + 1].t : this.spec.dur
|
||||
this.i++
|
||||
this.t = st.t
|
||||
let prev = performance.now()
|
||||
const loop = (now: number) => {
|
||||
if (!this.playing) return
|
||||
this.t += now - prev; prev = now
|
||||
const steps = this.spec.steps
|
||||
while (this.i < steps.length && steps[this.i].t <= this.t) { this.apply(steps[this.i]); this.i++ }
|
||||
this.paint()
|
||||
const minGap = Math.max(500, (nextT - st.t) * 0.3)
|
||||
await this.awaitStep(st.cap, minGap, token)
|
||||
if (token !== this.playToken) return
|
||||
}
|
||||
if (token !== this.playToken || !this.playing) return
|
||||
this.t = this.spec.dur
|
||||
this.paint()
|
||||
this.playing = false; this.pp.textContent = '↻'
|
||||
this.timers.push(setTimeout(() => { if (token === this.playToken) { this.reset(); this.play() } }, 1100))
|
||||
}
|
||||
/** Resolves once a step's voiceover finishes (or the minimum visual dwell
|
||||
* time elapses, if muted/reduced-motion/no caption) — always resolves. A
|
||||
* safety timer guards against a stuck browser voice engine, and `skipSpeech`
|
||||
* lets an explicit user action (e.g. muting) unstick it immediately, since
|
||||
* speechSynthesis.cancel() doesn't reliably fire end/error in every browser. */
|
||||
awaitStep(cap: string | undefined, minGap: number, token: number): Promise<void> {
|
||||
return new Promise((resolve) => {
|
||||
const startedAt = performance.now()
|
||||
let settled = false
|
||||
const settle = () => {
|
||||
if (settled) return
|
||||
settled = true
|
||||
this.pendingUnstick = null
|
||||
const remaining = minGap - (performance.now() - startedAt)
|
||||
if (remaining > 0) this.timers.push(setTimeout(resolve, remaining))
|
||||
else resolve()
|
||||
}
|
||||
this.pendingUnstick = settle
|
||||
const text = cap ? captionToText(cap) : ''
|
||||
if (!text || this.reduced || this.muted.current) {
|
||||
this.timers.push(setTimeout(settle, minGap))
|
||||
if (this.t >= this.spec.dur) {
|
||||
this.playing = false; this.pp.textContent = '↻'
|
||||
this.timers.push(setTimeout(() => { this.reset(); this.play() }, 1100))
|
||||
return
|
||||
}
|
||||
speakText(text, () => { if (token === this.playToken) settle() })
|
||||
this.timers.push(setTimeout(settle, minGap + 5000))
|
||||
})
|
||||
}
|
||||
/** Cancels any speech in flight and immediately unblocks a pending step
|
||||
* wait — used when the user mutes mid-playback. */
|
||||
skipSpeech() {
|
||||
try { window.speechSynthesis?.cancel() } catch { /* noop */ }
|
||||
this.pendingUnstick?.()
|
||||
}
|
||||
pause() {
|
||||
this.playing = false; this.pp.textContent = '▶'
|
||||
try { window.speechSynthesis?.cancel() } catch { /* noop */ }
|
||||
this.raf = requestAnimationFrame(loop)
|
||||
}
|
||||
this.raf = requestAnimationFrame(loop)
|
||||
}
|
||||
pause() { this.playing = false; this.pp.textContent = '▶'; cancelAnimationFrame(this.raf) }
|
||||
toggle() { this.playing ? this.pause() : this.play() }
|
||||
destroy() { this.clear() }
|
||||
}
|
||||
@@ -369,34 +268,12 @@ export default function MobileSdkExplorer() {
|
||||
if (!root) return
|
||||
|
||||
const reduced = matchMedia('(prefers-reduced-motion:reduce)').matches
|
||||
const muted: MutedRef = { current: false }
|
||||
const reels: Record<string, Reel> = {}
|
||||
root.querySelectorAll<HTMLElement>('.panel').forEach((p) => {
|
||||
const k = p.dataset.p
|
||||
if (k && SCRIPTS[k]) reels[k] = new Reel(p, SCRIPTS[k], reduced, muted)
|
||||
if (k && SCRIPTS[k]) reels[k] = new Reel(p, SCRIPTS[k], reduced)
|
||||
})
|
||||
|
||||
// Mute is shared across every panel's own button — muting on one tab
|
||||
// keeps the next tab muted too.
|
||||
const muteBtns = [...root.querySelectorAll<HTMLButtonElement>('.js-mute')]
|
||||
const syncMuteUI = () => {
|
||||
muteBtns.forEach((b) => {
|
||||
b.textContent = muted.current ? '🔇' : '🔊'
|
||||
b.classList.toggle('muted', muted.current)
|
||||
const label = muted.current ? 'Unmute voiceover' : 'Mute voiceover'
|
||||
b.setAttribute('aria-label', label)
|
||||
b.title = label
|
||||
})
|
||||
}
|
||||
muteBtns.forEach((b) => {
|
||||
b.onclick = () => {
|
||||
muted.current = !muted.current
|
||||
if (muted.current) { reels[cur]?.skipSpeech() }
|
||||
syncMuteUI()
|
||||
}
|
||||
})
|
||||
syncMuteUI()
|
||||
|
||||
const tabs = [...root.querySelectorAll<HTMLButtonElement>('.tab')]
|
||||
const panels = [...root.querySelectorAll<HTMLElement>('.panel')]
|
||||
let cur = 'score'
|
||||
@@ -406,13 +283,8 @@ export default function MobileSdkExplorer() {
|
||||
Object.entries(reels).forEach(([n, r]) => { if (n !== k) { r.pause(); r.reset() } })
|
||||
cur = k
|
||||
// Switching tabs only stages the reel — playback waits for an explicit
|
||||
// tap on that reel's own play button — but announce the module by voice
|
||||
// right away so a click always gets a spoken response.
|
||||
// tap on that reel's own play button.
|
||||
reels[k]?.reset()
|
||||
if (!reduced && !muted.current) {
|
||||
const headline = panels.find((p) => p.dataset.p === k)?.querySelector('.copy h3')?.textContent
|
||||
if (headline) speakText(headline)
|
||||
}
|
||||
}
|
||||
const onTabClick = (t: HTMLButtonElement) => () => {
|
||||
if (t.dataset.p) show(t.dataset.p)
|
||||
@@ -441,9 +313,7 @@ export default function MobileSdkExplorer() {
|
||||
io.disconnect()
|
||||
tabsEl?.removeEventListener('keydown', onKeydown)
|
||||
tabs.forEach((t) => { t.onclick = null })
|
||||
muteBtns.forEach((b) => { b.onclick = null })
|
||||
Object.values(reels).forEach((r) => r.destroy())
|
||||
try { window.speechSynthesis?.cancel() } catch { /* noop */ }
|
||||
}
|
||||
}, [])
|
||||
|
||||
|
||||
@@ -75,8 +75,6 @@
|
||||
.bd-mse .reel-btn:hover { background: var(--mse-accent-2); }
|
||||
.bd-mse .reel-btn.ghost { background: transparent; color: var(--mse-text-2); font-size: 14px; }
|
||||
.bd-mse .reel-btn.ghost:hover { background: var(--mse-surface-2); color: var(--mse-text); }
|
||||
.bd-mse .reel-btn.js-mute { font-size: 12px; }
|
||||
.bd-mse .reel-btn.js-mute.muted { color: var(--mse-text-mute); }
|
||||
.bd-mse .reel-track { flex: 1; height: 4px; border-radius: 100px; background: var(--mse-border-strong); position: relative; cursor: pointer; }
|
||||
.bd-mse .reel-fill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 100px; background: var(--mse-accent); transition: width .35s ease; }
|
||||
.bd-mse .reel-time { font-family: 'Ubuntu Mono', monospace; font-size: .72rem; color: var(--mse-text-mute); flex-shrink: 0; letter-spacing: -.3px; }
|
||||
|
||||
@@ -54,9 +54,7 @@
|
||||
<button class="reel-btn js-pp" aria-label="Pause">▮▮</button>
|
||||
<div class="reel-track js-track"><div class="reel-fill"></div></div>
|
||||
<span class="reel-time"><span class="js-el">0:00</span>/<span class="js-du">0:07</span></span>
|
||||
<button class="reel-btn ghost js-rs" aria-label="Restart">↻</button>
|
||||
<button class="reel-btn ghost js-mute" aria-label="Mute voiceover" title="Mute voiceover">🔊</button>
|
||||
</div>
|
||||
<button class="reel-btn ghost js-rs" aria-label="Restart">↻</button> </div>
|
||||
<p class="reel-cap"></p>
|
||||
</div>
|
||||
<div class="copy">
|
||||
@@ -117,9 +115,7 @@
|
||||
<button class="reel-btn js-pp" aria-label="Pause">▮▮</button>
|
||||
<div class="reel-track js-track"><div class="reel-fill"></div></div>
|
||||
<span class="reel-time"><span class="js-el">0:00</span>/<span class="js-du">0:07</span></span>
|
||||
<button class="reel-btn ghost js-rs" aria-label="Restart">↻</button>
|
||||
<button class="reel-btn ghost js-mute" aria-label="Mute voiceover" title="Mute voiceover">🔊</button>
|
||||
</div>
|
||||
<button class="reel-btn ghost js-rs" aria-label="Restart">↻</button> </div>
|
||||
<p class="reel-cap"></p>
|
||||
</div>
|
||||
<div class="copy">
|
||||
@@ -174,9 +170,7 @@
|
||||
<button class="reel-btn js-pp" aria-label="Pause">▮▮</button>
|
||||
<div class="reel-track js-track"><div class="reel-fill"></div></div>
|
||||
<span class="reel-time"><span class="js-el">0:00</span>/<span class="js-du">0:08</span></span>
|
||||
<button class="reel-btn ghost js-rs" aria-label="Restart">↻</button>
|
||||
<button class="reel-btn ghost js-mute" aria-label="Mute voiceover" title="Mute voiceover">🔊</button>
|
||||
</div>
|
||||
<button class="reel-btn ghost js-rs" aria-label="Restart">↻</button> </div>
|
||||
<p class="reel-cap"></p>
|
||||
</div>
|
||||
<div class="copy">
|
||||
@@ -244,9 +238,7 @@
|
||||
<button class="reel-btn js-pp" aria-label="Pause">▮▮</button>
|
||||
<div class="reel-track js-track"><div class="reel-fill"></div></div>
|
||||
<span class="reel-time"><span class="js-el">0:00</span>/<span class="js-du">0:09</span></span>
|
||||
<button class="reel-btn ghost js-rs" aria-label="Restart">↻</button>
|
||||
<button class="reel-btn ghost js-mute" aria-label="Mute voiceover" title="Mute voiceover">🔊</button>
|
||||
</div>
|
||||
<button class="reel-btn ghost js-rs" aria-label="Restart">↻</button> </div>
|
||||
<p class="reel-cap"></p>
|
||||
</div>
|
||||
<div class="copy">
|
||||
@@ -295,9 +287,7 @@
|
||||
<button class="reel-btn js-pp" aria-label="Pause">▮▮</button>
|
||||
<div class="reel-track js-track"><div class="reel-fill"></div></div>
|
||||
<span class="reel-time"><span class="js-el">0:00</span>/<span class="js-du">0:06</span></span>
|
||||
<button class="reel-btn ghost js-rs" aria-label="Restart">↻</button>
|
||||
<button class="reel-btn ghost js-mute" aria-label="Mute voiceover" title="Mute voiceover">🔊</button>
|
||||
</div>
|
||||
<button class="reel-btn ghost js-rs" aria-label="Restart">↻</button> </div>
|
||||
<p class="reel-cap"></p>
|
||||
</div>
|
||||
<div class="copy">
|
||||
@@ -343,9 +333,7 @@
|
||||
<button class="reel-btn js-pp" aria-label="Pause">▮▮</button>
|
||||
<div class="reel-track js-track"><div class="reel-fill"></div></div>
|
||||
<span class="reel-time"><span class="js-el">0:00</span>/<span class="js-du">0:08</span></span>
|
||||
<button class="reel-btn ghost js-rs" aria-label="Restart">↻</button>
|
||||
<button class="reel-btn ghost js-mute" aria-label="Mute voiceover" title="Mute voiceover">🔊</button>
|
||||
</div>
|
||||
<button class="reel-btn ghost js-rs" aria-label="Restart">↻</button> </div>
|
||||
<p class="reel-cap"></p>
|
||||
</div>
|
||||
<div class="copy">
|
||||
@@ -431,9 +419,7 @@
|
||||
<button class="reel-btn js-pp" aria-label="Pause">▮▮</button>
|
||||
<div class="reel-track js-track"><div class="reel-fill"></div></div>
|
||||
<span class="reel-time"><span class="js-el">0:00</span>/<span class="js-du">0:08</span></span>
|
||||
<button class="reel-btn ghost js-rs" aria-label="Restart">↻</button>
|
||||
<button class="reel-btn ghost js-mute" aria-label="Mute voiceover" title="Mute voiceover">🔊</button>
|
||||
</div>
|
||||
<button class="reel-btn ghost js-rs" aria-label="Restart">↻</button> </div>
|
||||
<p class="reel-cap"></p>
|
||||
</div>
|
||||
<div class="copy">
|
||||
@@ -499,9 +485,7 @@
|
||||
<button class="reel-btn js-pp" aria-label="Pause">▮▮</button>
|
||||
<div class="reel-track js-track"><div class="reel-fill"></div></div>
|
||||
<span class="reel-time"><span class="js-el">0:00</span>/<span class="js-du">0:07</span></span>
|
||||
<button class="reel-btn ghost js-rs" aria-label="Restart">↻</button>
|
||||
<button class="reel-btn ghost js-mute" aria-label="Mute voiceover" title="Mute voiceover">🔊</button>
|
||||
</div>
|
||||
<button class="reel-btn ghost js-rs" aria-label="Restart">↻</button> </div>
|
||||
<p class="reel-cap"></p>
|
||||
</div>
|
||||
<div class="copy">
|
||||
@@ -573,9 +557,7 @@
|
||||
<button class="reel-btn js-pp" aria-label="Pause">▮▮</button>
|
||||
<div class="reel-track js-track"><div class="reel-fill"></div></div>
|
||||
<span class="reel-time"><span class="js-el">0:00</span>/<span class="js-du">0:09</span></span>
|
||||
<button class="reel-btn ghost js-rs" aria-label="Restart">↻</button>
|
||||
<button class="reel-btn ghost js-mute" aria-label="Mute voiceover" title="Mute voiceover">🔊</button>
|
||||
</div>
|
||||
<button class="reel-btn ghost js-rs" aria-label="Restart">↻</button> </div>
|
||||
<p class="reel-cap"></p>
|
||||
</div>
|
||||
<div class="copy">
|
||||
|
||||
Reference in New Issue
Block a user