@protomaze/demo-engine 0.1.2 → 0.1.4

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/README.md CHANGED
@@ -49,8 +49,12 @@ await engine.mount();
49
49
  ```
50
50
 
51
51
  Or put the library in the app's own panel: `<DemoLibrary engine={engine} />` (in its own shadow
52
- root: the app's styles stay out). Everything else - the studio, the bars while playing and
53
- recording, effects - the engine renders over the app, in the top layer.
52
+ root: the app's styles stay out): every demo with Play, Present and Guide, the studio and the rest a
53
+ click away, the voice and language behind its settings button. What starting something needs is
54
+ asked as it starts, in a dialog over the app - a video's size, shape, quality and music; a
55
+ recording's microphone; a booth's demos; where the presenter's screen goes - and its Start is the
56
+ click sound and filming need. Everything else - the studio, the bars while playing and recording,
57
+ effects - the engine renders over the app, in the top layer.
54
58
 
55
59
  From code: `engine.play(demo, { from })`, `engine.guide(demo)`, `engine.film(demo)`,
56
60
  `engine.record()`, `engine.loop(demos, { idle, reset: 'reload' })`, `engine.check(demo)`,
@@ -160,6 +164,12 @@ plan, every step to go to, big controls. `engine.openPresenter({ onTop: true })`
160
164
  always on top (Chrome's Document Picture-in-Picture). `mountPresenter(engine, document)` puts it in
161
165
  a window or frame of the app's own. A clicker works in either window.
162
166
 
167
+ **On a phone**: the presenter's screen also opens on a phone, by its QR code (in Present's dialog,
168
+ and on the presenter's screen). The phone needs nothing installed and need not reach the app: a
169
+ small relay (`remote/`, a Cloudflare Worker, the Protomaze one by default; `remote: { relay }` for
170
+ another, `false` for none) passes messages between the two, encrypted end to end with a key that
171
+ travels only in the QR code's link.
172
+
163
173
  A presenter's clicker sends PageDown and PageUp: "Wait for the presenter after each step" makes
164
174
  a pitch. Guided, the viewer does each click, entry and choice; "Do it for me" lets the demo. Looped,
165
175
  a visitor's touch hands the app over; after `idle` it plays on, from the app's start (or a reload).
@@ -56,6 +56,15 @@ export type DemoEngineOptions = {
56
56
  * tokens, no model to download. None where it has none.
57
57
  */
58
58
  narration?: (demo: Demo) => string | undefined;
59
+ /**
60
+ * The presenter's screen on a phone, by QR code, through a relay that passes end-to-end encrypted
61
+ * messages (`remote/` in this repo): its origin, the Protomaze relay by default; false for none.
62
+ */
63
+ remote?: {
64
+ relay?: string;
65
+ } | false;
66
+ /** The app's own theme now: kept with a video, shown on its line. */
67
+ appTheme?: () => 'light' | 'dark';
59
68
  };
60
69
  /** What the engine is doing: one thing at a time. */
61
70
  export type Session = {
@@ -81,12 +90,33 @@ export type Session = {
81
90
  checking: boolean;
82
91
  guided: boolean;
83
92
  looping: boolean;
93
+ presenting: boolean;
84
94
  player: Player;
85
95
  } & PlayState) | ({
86
96
  mode: 'recording';
87
97
  filming: boolean;
88
98
  microphone: boolean;
89
99
  } & RecordState);
100
+ /** What starting something asks first (`openDialog`): a video's size and sound, a booth's demos, a presentation's screen. */
101
+ export type DialogRequest = {
102
+ kind: 'film';
103
+ demo: Demo;
104
+ } | {
105
+ kind: 'record';
106
+ into?: Demo;
107
+ after?: number;
108
+ } | {
109
+ kind: 'loop';
110
+ demos: Demo[];
111
+ } | {
112
+ kind: 'present';
113
+ demo: Demo;
114
+ from?: number;
115
+ } | {
116
+ kind: 'video';
117
+ demo: Demo;
118
+ video: DemoVideo;
119
+ };
90
120
  /** A demo the engine knows: come with the app, edited here, or made here. */
91
121
  export type DemoEntry = {
92
122
  demo: KeptDemo;
@@ -126,6 +156,16 @@ export type EngineState = {
126
156
  };
127
157
  /** A moment's note in the bar while playing: input held back. */
128
158
  hint?: string;
159
+ /** The phone remote, open: its link and QR code, and how many are connected (the phone: 2). */
160
+ remote?: {
161
+ url: string;
162
+ svg: string;
163
+ peers: number;
164
+ };
165
+ /** What is asked before something starts. */
166
+ dialog?: DialogRequest;
167
+ /** The library: its demos or its settings; the launcher's floating one shows while set. */
168
+ library?: 'demos' | 'settings';
129
169
  };
130
170
  export type LoopOptions = {
131
171
  /** ms of no input before the loop plays again, after a visitor. Default the setting, 30 s. */
@@ -175,6 +215,9 @@ export declare class DemoEngine {
175
215
  private looping;
176
216
  private musicLoaded;
177
217
  private packs;
218
+ private remoteLink;
219
+ private remoteSent;
220
+ private remoteTimer;
178
221
  constructor(options: DemoEngineOptions);
179
222
  getState: () => EngineState;
180
223
  subscribe: (listener: () => void) => (() => void);
@@ -256,8 +299,17 @@ export declare class DemoEngine {
256
299
  }): Promise<boolean>;
257
300
  /** Keys pressed in another window of the engine's (the presenter's): a clicker's go to whichever is in front. */
258
301
  presenterKey(event: KeyboardEvent): void;
259
- /** Presents it: waiting after each step, the presenter's screen open beside it. From a click. */
260
- present(demo: Demo, options?: Partial<PlayOptions>): Promise<PlayResult | undefined>;
302
+ /** Presents it: asks where the presenter's screen goes (a window, on top, the phone), then plays it waiting after each step. */
303
+ present(demo: Demo, options?: {
304
+ from?: number;
305
+ }): void;
306
+ /** Asks what starting something needs to know, then starts it from its Start: film, record, loop, present. */
307
+ openDialog(dialog: DialogRequest): void;
308
+ closeDialog(): void;
309
+ /** The library, at its settings: voices, languages, subtitles. */
310
+ openSettings(): void;
311
+ /** The library's view; undefined closes the launcher's floating one. */
312
+ showLibrary(view: 'demos' | 'settings' | undefined): void;
261
313
  /** To a step of what plays (0-based): forward or back. False where it cannot (filmed). */
262
314
  goTo(step: number): boolean;
263
315
  /**
@@ -267,6 +319,19 @@ export declare class DemoEngine {
267
319
  guide(demo: Demo, options?: Partial<PlayOptions>): Promise<PlayResult | undefined>;
268
320
  /** Guided: the demo does what the viewer was to do. */
269
321
  doItForMe(): void;
322
+ /**
323
+ * The presenter's screen on a phone: a room at the relay, its QR code in `state.remote`. The phone
324
+ * sees the script, notes, next step and clocks, and drives the demo as the presenter's keys do.
325
+ */
326
+ openRemote(): Promise<{
327
+ url: string;
328
+ svg: string;
329
+ }>;
330
+ closeRemote(): void;
331
+ private fromRemote;
332
+ /** The state, to the phone, if it changed - or `tick`, every second while playing, for its clocks. */
333
+ private toRemote;
334
+ private remoteState;
270
335
  /** The demo's narration pack: made here (kept in this browser), else the app's (`narration`); none without. */
271
336
  pack(demo: Demo): Promise<NarrationPack | undefined>;
272
337
  /**
@@ -317,6 +382,8 @@ export declare class DemoEngine {
317
382
  }): Promise<DemoVideo | undefined>;
318
383
  private filmNow;
319
384
  private filmQuality;
385
+ /** How a video is made now: the app's theme and language, the voice, the narration's language, subtitles. */
386
+ private look;
320
387
  /** What was said, timed: Whisper in the browser, or ElevenLabs with the key. */
321
388
  transcribe(audio: Blob, language?: string): Promise<Subtitle[]>;
322
389
  /**
@@ -1 +1 @@
1
- import{copyOf as e,languagesOf as t,newDemo as s,sayOf as i,scenarioOf as o,sentences as n}from"../model/Demo.js";import{parseSubtitles as a,toSrt as r,toVtt as h}from"../model/Subtitles.js";import{actionTime as p,estimate as d}from"../model/Timing.js";import{parseDemo as c,validate as l}from"../model/Validate.js";import{Hand as g}from"../page/Input.js";import{Overlay as m}from"../page/Overlay.js";import{Targets as u}from"../page/Targets.js";import{Speech as y}from"../speech/Speech.js";import{narrationFor as f,transcribe as w}from"../speech/Transcribe.js";import{Store as v}from"../store/Store.js";import{demoFromLink as k,download as b,fileName as S,linkTo as P,shareFiles as x}from"../store/Share.js";import{extensionOf as T,recordMicrophone as j,startFilming as E,videoSize as $}from"../video/Film.js";import{renderMusic as M}from"../speech/Music.js";import{readPack as R,writePack as K}from"../speech/Pack.js";import{Player as N}from"./Player.js";import{Recorder as L}from"./Recorder.js";import{readAction as B}from"./Read.js";import{mountUI as D}from"../ui/EngineUI.js";import{agentTools as F}from"../agent/Agent.js";import{openPresenter as I}from"../ui/Presenter.js";import{DEFAULT_SETTINGS as O,loadSettings as A,saveSettings as C}from"./Settings.js";const J=["pointerdown","pointerup","pointermove","pointerover","pointerout","mousedown","mouseup","mousemove","mouseover","mouseout","click","dblclick","contextmenu","wheel","touchstart","touchmove","touchend","keydown","keyup","keypress"];export class DemoEngine{constructor(e){this.options=e,this.listeners=new Set,this.packs=new Map,this.getState=()=>this.state,this.subscribe=e=>(this.listeners.add(e),()=>this.listeners.delete(e)),this.hintTimer=0,this.targets=new u({...e.targets,labels:e.labels}),this.overlay=new m(e.overlay),this.hand=new g(this.overlay.cursor,()=>this.player?.speedNow??1),this.settingsKey=`protomaze-demo-engine:${e.app}:settings`,this.state={session:{mode:"idle"},settings:A(this.settingsKey),speech:{}},this.speech=new y(()=>this.state.settings.speech,()=>this.set({speech:{...this.speech.state}})),this.store=new v(`protomaze-demo-engine:${e.app}`),this.store.subscribe(()=>this.emit()),this.plugins=e.plugins??[]}emit(){this.state={...this.state},this.listeners.forEach(e=>e())}set(e){this.state={...this.state,...e},this.listeners.forEach(e=>e())}setSession(e){this.set({session:e})}updateSession(e,t){this.state.session.mode===e&&this.setSession({...this.state.session,...t})}say(e,t=!1){this.set({message:e?{text:e,error:t}:void 0})}changeSettings(e){const t={...this.state.settings,...e};C(this.settingsKey,t),this.set({settings:t}),e.music?.on&&this.loadMusic().catch(()=>{})}language(){const e=this.state.settings.language;return"page"!==e?e:this.options.language?.()??this.options.languages?.[0]??(navigator.language.split("-")[0]||"en")}languages(){return this.options.languages??[this.language()]}pluginKinds(){return this.plugins.flatMap(e=>Object.keys(e.actions??{}))}pluginAction(e){return this.plugins.map(t=>t.actions?.[e]).find(Boolean)}read(e,t){return B(e,this.options.labels,this.plugins,t)}async mount(){if(this.unmount)return;this.overlay.mount();const e=D(this),t=e=>this.key(e);window.addEventListener("keydown",t,!0);const s=e=>this.gate(e);J.forEach(e=>window.addEventListener(e,s,{capture:!0,passive:!1})),this.state.settings.music.on&&this.loadMusic().catch(()=>{});const i=!1===this.options.agent?void 0:this.options.agent??"demoEngine";i&&(window[i]=F(this)),this.unmount=()=>{e(),window.removeEventListener("keydown",t,!0),J.forEach(e=>window.removeEventListener(e,s,{capture:!0})),i&&delete window[i],this.overlay.unmount()},await this.arrived()}destroy(){this.stopLoop(),this.stop(),this.unmount?.(),this.unmount=void 0}async arrived(){const e=sessionStorage.getItem(this.pendingKey());if(sessionStorage.removeItem(this.pendingKey()),e){const{demo:t,verb:s,from:i,loop:o}=JSON.parse(e);return"loop"===s&&o?void this.loop(o.demos,{gap:o.gap,idle:o.idle,reset:o.reload?"reload":void 0},o.index):this.whenClicked(t.title,"film"===s?"Film":"Play",()=>"film"===s?this.film(t):this.play(t,{from:i}),!0)}const t=await k();if(t){const e=l(t,this.pluginKinds());return e.length?this.say(`The link's demo: ${e[0].path} ${e[0].message}`,!0):(await this.save(t),this.say(`"${t.title}" came with the link: it is kept here.`),this.openStudio(t))}const s=new URL(window.location.href),i=s.searchParams.get("demo");if(i){s.searchParams.delete("demo"),window.history.replaceState(window.history.state,"",s.toString());const e=(await this.entries()).find(e=>e.demo.id===i);e&&this.whenClicked(e.demo.title,"Play",()=>this.play(e.demo),!0)}}gate(e){const t=this.state.session;if(!e.isTrusted||"playing"!==t.mode||t.paused||t.looping)return;const s=e.composedPath();if(s.includes(this.overlay.host))return;if(t.guided&&t.instruction){const i=t.player.viewerTarget();if(i&&(s.includes(i)||e instanceof KeyboardEvent&&i.contains(document.activeElement)))return;if(!i&&e instanceof KeyboardEvent)return}const i=e.defaultPrevented;e.cancelable&&e.preventDefault(),e.stopImmediatePropagation(),i||"pointerdown"!==e.type&&"keydown"!==e.type&&"wheel"!==e.type||this.hint(t.guided?'Only the ringed part now: or "Do it for me"':"Playing: Space pauses, and the app is yours then. Esc stops.")}hint(e){window.clearTimeout(this.hintTimer),this.set({hint:e}),this.hintTimer=window.setTimeout(()=>this.set({hint:void 0}),3e3)}pendingKey(){return`protomaze-demo-engine:${this.options.app}:pending`}key(e){if(!e.isTrusted)return;const t=e.composedPath(),s=t.some(e=>e instanceof HTMLElement&&(e.isContentEditable||e.matches("input, textarea, select"))),i=t.includes(this.overlay.host),o=this.state.session,n=()=>{e.preventDefault(),e.stopPropagation()};if("ready"!==o.mode)if("recording"!==o.mode){if("l"===e.key.toLowerCase()&&e.ctrlKey&&e.shiftKey&&this.looping)return n(),this.stopLoop();if(!("playing"!==o.mode||o.looping||o.checking||s&&(i||o.guided&&o.instruction))){if("Escape"===e.key)this.stop();else if(" "===e.key||"b"===e.key||"."===e.key)this.togglePause();else if("ArrowRight"===e.key||"Enter"===e.key||"PageDown"===e.key)o.player.next();else if("ArrowLeft"===e.key||"PageUp"===e.key)o.player.back();else if("Home"===e.key)o.player.goTo(0);else if("End"===e.key)o.player.goTo(o.steps-1);else{if(!/^[1-9]$/.test(e.key)||e.ctrlKey||e.metaKey||e.altKey)return;o.player.goTo(Number(e.key)-1)}n()}}else"Escape"!==e.key||s||(n(),this.stopRecording?.());else"Escape"===e.key&&(n(),o.cancel())}async entries(){return await this.store.ready(),this.entriesNow()}entriesNow(){const{demos:e,videos:t}=this.store.get(),s=new Map(e.map(e=>[e.id,e])),i=this.language(),n=(this.options.demos??[]).map(e=>"demo"in e?e:{demo:e,scenario:void 0});return[...n.map(({demo:e,scenario:n})=>{const a=s.get(e.id);return a?{demo:a,scenario:a.scenario??n??o(a,i),origin:"edited",video:t.get(e.id)}:{demo:e,scenario:n??o(e,i),origin:"app",video:t.get(e.id)}}),...e.filter(e=>!n.some(t=>t.demo.id===e.id)).map(e=>({demo:e,scenario:e.scenario??o(e,i),origin:"here",video:t.get(e.id)}))]}async save(t){const s=l(t,this.pluginKinds());if(s.length)throw new Error(`Not a demo: ${s.map(e=>`${e.path} ${e.message}`).join("; ")}`);await this.store.saveDemo(e(t))}async remove(e){await this.store.deleteDemo(e),this.state.studio?.demo.id===e&&this.closeStudio()}parse(e){return c(e,this.pluginKinds())}create(e){return s(e,this.options.start?.current())}openStudio(t){this.set({studio:{demo:e(t),opened:Date.now()}})}closeStudio(){this.set({studio:void 0})}activated(){const e=navigator.userActivation;return!e||e.isActive}whenClicked(e,t,s,i=!1){const o=()=>{this.setSession({mode:"idle"}),this.speech.wake(),s().catch(e=>this.say(e.message,!0))};if(!i&&this.activated())return o();this.setSession({mode:"ready",title:e,verb:t,go:o,cancel:()=>this.setSession({mode:"idle"})})}async goToStart(e,t,s,i){if(!e.start||!this.options.start)return!0;sessionStorage.setItem(this.pendingKey(),JSON.stringify({demo:e,verb:t,from:s,loop:i}));return"reload"!==await this.options.start.go(e.start)&&(sessionStorage.removeItem(this.pendingKey()),!0)}busy(){return"idle"!==this.state.session.mode&&"ready"!==this.state.session.mode}play(e,t={}){return new Promise(s=>this.whenClicked(e.title,"Play",async()=>{if(this.busy())return s(void 0);if(this.say(void 0),!await this.goToStart(e,"play",t.from))return s(void 0);const i=await this.run(e,t);s(i)}))}async run(e,t={}){const{settings:s}=this.state,i=t.language??this.language(),o=s.music.on&&!t.checking&&!t.guided&&await Promise.race([this.loadMusic(),new Promise(e=>setTimeout(()=>e(!1),t.filming?6e4:1500))]);this.speech.setPack(s.usePacks?await this.pack(e):void 0);const n=new N(e,{language:i,subtitles:s.subtitles,waitForPresenter:s.waitForPresenter&&!t.looping,catchUp:s.catchUp,music:Boolean(o),...t},{hand:this.hand,targets:this.targets,overlay:this.overlay,speech:this.speech,plugins:this.plugins,ready:this.options.ready,read:(e,t)=>this.read(e,t),reset:async()=>!e.start||!this.options.start||"reload"!==await this.options.start.go(e.start),update:e=>this.updateSession("playing",e)});this.setSession({mode:"playing",title:e.title,demo:e,steps:e.steps.length,filming:Boolean(t.filming),checking:Boolean(t.checking),guided:Boolean(t.guided),looping:Boolean(t.looping),player:n,step:t.from??0,caption:"",paused:!1,waiting:!1,catchingUp:!1}),this.player=n;const a=await n.play().finally(()=>this.player=void 0);return this.setSession({mode:"idle"}),t.checking||a.navigated||(this.set({lastRun:{json:JSON.stringify(e),language:i,timing:a.timing}}),a.error&&"Stopped."!==a.error&&this.say(a.error,!0)),a}stop(){const e=this.state.session;"playing"===e.mode&&e.player.stop(),"recording"===e.mode&&this.stopRecording?.(),"ready"!==e.mode&&"preparing"!==e.mode||this.setSession({mode:"idle"})}togglePause(){const e=this.state.session;"playing"===e.mode&&(e.paused?e.player.resume():e.player.pause())}resume(){const e=this.state.session;"playing"===e.mode&&e.player.resume()}next(){const e=this.state.session;"playing"===e.mode&&e.player.next()}back(){const e=this.state.session;"playing"===e.mode&&e.player.back()}openPresenter(e={}){return I(this,e)}presenterKey(e){this.key(e)}present(e,t={}){const s=this.play(e,{...t,waitForPresenter:!0});return this.openPresenter(),s}goTo(e){const t=this.state.session;return"playing"===t.mode&&t.player.goTo(e)}guide(e,t={}){return this.play(e,{...t,guided:!0})}doItForMe(){const e=this.state.session;"playing"===e.mode&&e.player.doItForMe()}pack(e){let t=this.packs.get(e.id);return t||(t=(async()=>{const t=await this.store.asset(`narration:${e.id}`);if(t)return R(await t.arrayBuffer());const s=this.options.narration?.(e);if(!s)return;const i=await fetch(s);return i.ok?R(await i.arrayBuffer()):void 0})().catch(()=>{}),this.packs.set(e.id,t)),t}async makePack(e,s=()=>{}){const i=await this.pack(e);this.speech.setPack(i);const o=t(e).flatMap(t=>e.steps.flatMap(e=>n(e.say[t]??"").map(e=>({language:t,text:e})))),a=o.filter((e,t)=>o.findIndex(t=>t.language===e.language&&t.text===e.text)===t),r=[];for(const e of a)s(r.length,a.length),r.push({...await this.speech.packable(e.text,e.language),...e});s(r.length,a.length);const h=K(e.id,r);return await this.store.saveAsset(`narration:${e.id}`,h),this.packs.delete(e.id),h}async downloadPack(e){try{const t=await this.makePack(e,(e,t)=>this.say(`Making the narration pack: ${e} / ${t}`));b(t,`${e.id}.narration.zip`),this.say(`Narration pack: ${Math.round(t.size/1e5)/10} MB, kept here too. Check it in beside ${e.id}.demo.json, for every viewer.`)}catch(e){this.say(`Narration pack: ${e.message}`,!0)}}async dropPack(e){await this.store.saveAsset(`narration:${e.id}`,void 0),this.packs.delete(e.id)}async setMusic(e){await this.store.saveAsset("music",e),this.musicLoaded=void 0;const{music:t}=this.state.settings;this.changeSettings({music:e?{...t,on:!0,track:"file",name:e.name??"music"}:{...t,track:"calm",name:void 0}})}async loadMusic(){const{music:e}=this.state.settings,t="file"===e.track?`file:${e.name}`:e.track;if(this.musicLoaded!==t){if("file"===e.track){const t=await this.store.asset("music");if(!t)return!1;await this.speech.setMusic(t,e.volume).catch(()=>{})}else this.speech.setMusicBuffer(await M(e.track),e.volume);this.musicLoaded=t}return this.speech.setMusicVolume(e.volume),this.speech.hasMusic}async listenToMusic(e=20){if(this.speech.wake(),!await this.loadMusic())return()=>{};this.speech.startMusic();const t=setTimeout(()=>this.speech.stopMusic(),1e3*e);return()=>{clearTimeout(t),this.speech.stopMusic(.6)}}async loop(e,t={},s=0){if(0===e.length)return;this.stopLoop();let i=!1,o=0,n=s;const a=t.idle??this.state.settings.loopIdle,r=t.gap??1500,h=e.map(e=>e.title),p=e=>{if(!e.isTrusted||e.composedPath().includes(this.overlay.host))return;o=performance.now();const t=this.state.session;"playing"===t.mode&&t.looping&&t.player.stop(!0)},d=["pointerdown","keydown","wheel","touchstart"];d.forEach(e=>window.addEventListener(e,p,{capture:!0,passive:!0}));this.looping={demos:e,options:t,stop:()=>{i=!0,d.forEach(e=>window.removeEventListener(e,p,{capture:!0}));const e=this.state.session;"playing"===e.mode&&e.looping&&e.player.stop(),this.set({loop:void 0})}};const c=e=>new Promise(t=>setTimeout(t,e));for(;!i;){const s=e[n%e.length];this.set({loop:{titles:h,index:n%e.length,visitor:!1}});if(!await this.goToStart(s,"loop",void 0,{demos:e,index:n%e.length,gap:t.gap,idle:t.idle,reload:"reload"===t.reset})||i)return;const p=await this.run(s,{looping:!0,catchUp:!1});if(i)break;if(p.error&&performance.now()-o<1e3){for(;!i&&performance.now()-o<a;)this.set({loop:{titles:h,index:n%e.length,visitor:!0,resumesAt:Date.now()+a-(performance.now()-o)}}),await c(1e3);if(i)break;if("reload"===t.reset)return sessionStorage.setItem(this.pendingKey(),JSON.stringify({demo:s,verb:"loop",loop:{demos:e,index:n%e.length,gap:t.gap,idle:t.idle,reload:!0}})),window.location.reload();await(t.reset?.())}else n++,await c(r)}}stopLoop(){this.looping?.stop(),this.looping=void 0}elapsed(){const e=this.state.session;return"playing"===e.mode?e.player.elapsed():void 0}async check(e,t={}){const s=l(e,this.pluginKinds());if(s.length)return{ok:!1,problems:s,failures:[],duration:0,error:"Not a valid demo"};if(this.busy())return{ok:!1,problems:s,failures:[],duration:0,error:`Busy: ${this.state.session.mode}`};if(!1!==t.fromStart&&e.start&&this.options.start){if("reload"===await this.options.start.go(e.start))return{ok:!1,problems:s,failures:[],duration:0,error:"Its start reloads the page: check again once it is back"}}const i=await this.run(e,{...t,speed:t.speed??8,keepGoing:!0,checking:!0,catchUp:!0,subtitles:!1}),o=i.failures.map(t=>({...t,action:e.steps[t.step].actions[t.index]}));return{ok:!i.error&&0===o.length,error:i.error,failures:o,problems:s,duration:i.timing.duration}}timing(e,t=this.language()){const s=this.state.lastRun;return s&&s.language===t&&s.json===JSON.stringify(e)&&s.timing.steps.length===e.steps.length?s.timing:d(e,{language:t,sayTime:e=>this.speech.duration(e,t),actionTime:e=>{const t=this.pluginAction(e.do);return t?.duration?.(e)??p(e)}})}film(e,t={}){return new Promise(s=>this.whenClicked(e.title,"Film",async()=>this.busy()?s(void 0):(this.say(void 0),await this.goToStart(e,"film")?void s(await this.filmNow(e,t)):s(void 0))))}async filmNow(e,t){const s=t.language??this.language();let o=!1;const a=await E({soundtrack:this.speech.soundtrack(),microphone:t.microphone,crop:this.options.filmElement?.(),...this.filmQuality(),onEnded:()=>{o=!0,this.stop()}});let r;try{const t=e.steps.flatMap(e=>n(i(e,s)));this.setSession({mode:"preparing",title:e.title,text:"Preparing the narration"}),await this.speech.prepare(t,s,(e,t)=>this.updateSession("preparing",{text:`Preparing the narration: ${e} / ${t}`})),o||"preparing"!==this.state.session.mode||(r=await this.run(e,{language:s,filming:a}))}finally{"preparing"===this.state.session.mode&&this.setSession({mode:"idle"})}const{video:p,voice:d}=await a.stop();if(!r||r.error)return void this.say("Stopped."!==r?.error&&r?`Filming failed: ${r.error}`:"Filming stopped: nothing kept.",Boolean(r?.error&&"Stopped."!==r.error));let c=r.timing.cues;d&&"off"===this.state.settings.speech.voice&&(this.setSession({mode:"preparing",title:e.title,text:"Transcribing what was said"}),c=await this.transcribe(d,s).catch(()=>c),this.setSession({mode:"idle"}));const l={id:e.id,blob:p,at:Date.now(),json:JSON.stringify(e),vtt:h(c),timing:r.timing,language:s,...d?{voice:d}:{}};return await this.store.saveVideo(l),this.say(`Filmed "${e.title}": ${Math.round(p.size/1e6)} MB, kept here.`),l}filmQuality(){const{frameRate:e,bitrate:t,lines:s,aspect:i,fit:o}=this.state.settings.film;return{frameRate:e,bitrate:t,fit:o,...s?{size:$(s,i)}:{}}}async transcribe(e,t=this.language()){const{settings:s}=this.state;return w(e,{language:t,with:s.transcriber,model:s.whisperModel,elevenLabsKey:s.speech.elevenlabs.key,progress:e=>this.set({speech:e<1?{loading:e}:{}})})}record(e={}){return new Promise(t=>this.whenClicked(e.into?.title??"New demo","Record",async()=>{if(this.busy())return t();this.say(void 0),await this.recordNow(e,t)}))}async recordNow(t,i){const{settings:o}=this.state,n=this.language();let a,r;try{o.filmRecording?a=await E({soundtrack:this.speech.soundtrack(),microphone:o.microphone,crop:this.options.filmElement?.(),...this.filmQuality(),onEnded:()=>{this.stopRecording?.()}}):o.microphone&&(r=await j())}catch(e){return this.say(`Could not start: ${e.message}`,!0),i()}const p=this.options.start?.current(),d=new L(this.targets,this.plugins,n,e=>this.updateSession("recording",e));a?.resume();const c=performance.now();this.setSession({mode:"recording",filming:Boolean(a),microphone:Boolean(r||a&&o.microphone),step:0,caption:"",actions:0}),this.nextStepRecording=()=>d.nextStep(),this.sayRecording=e=>d.say(e),this.stopRecording=async()=>{this.stopRecording=this.nextStepRecording=this.sayRecording=void 0;const l=Boolean(r||a&&o.microphone),g=d.stop(l),m=performance.now()-c;this.setSession({mode:"preparing",title:"Recording",text:"Keeping what was recorded"});try{const[i,o]=await Promise.all([r?.stop(),a?.stop()]),d=i??o?.voice;let c=[];if(d){this.updateSession("preparing",{text:"Transcribing what was said"});try{c=await this.transcribe(d,n);const e=f(g.stepStarts,c);g.steps.forEach((t,s)=>{!t.say[n]&&e[s]&&(t.say[n]=e[s])})}catch(e){this.say(`Transcribing failed: ${e.message}`,!0)}}const l=g.steps.filter(e=>e.actions.length>0||Object.values(e.say).some(Boolean)),u=t.into?e(t.into):{...s("Recorded demo",p),steps:[]},y=t.after??u.steps.length-1,w={...u,steps:[...u.steps.slice(0,y+1),...l,...u.steps.slice(y+1)]};0===w.steps.length&&w.steps.push({say:{},actions:[]}),o&&await this.store.saveVideo({id:w.id,blob:o.video,at:Date.now(),json:JSON.stringify(w),vtt:h(c),language:n,timing:{duration:m,steps:g.stepStarts.map((e,t)=>({step:t,start:e,end:g.stepStarts[t+1]??m})),cues:c.map(e=>({...e,step:0})),actions:[]},...o.voice?{voice:o.voice}:{}}),this.setSession({mode:"idle"}),this.say(`Recorded ${l.length} step${1===l.length?"":"s"}${o?", and filmed":""}.`),t.into&&this.state.studio?.demo.id===t.into.id?this.set({studio:{...this.state.studio,recorded:{steps:w.steps,at:Date.now()}}}):this.openStudio(w)}catch(e){this.setSession({mode:"idle"}),this.say(e.message,!0)}i()}}nextStep(){this.nextStepRecording?.()}narrate(e){this.sayRecording?.(e)}async finishRecording(){await(this.stopRecording?.())}link(e){return P(e)}downloadDemo(e,t="json"){if("md"===t)return b(e.scenario??o(e,this.language()),S(e.id,"md"),"text/markdown");const{scenario:s,savedAt:i,...n}=e;b(JSON.stringify(n,null,2)+"\n",S(e.id,"demo.json"),"application/json")}downloadVideo(e,t,s=!1){return"vtt"===s?b(e.vtt,S(t,"vtt"),"text/vtt"):"srt"===s?b(r(a(e.vtt)),S(t,"srt"),"application/x-subrip"):void b(e.blob,S(t,T(e.blob)))}shareVideo(e,t){return x([new File([e.blob],S(t,T(e.blob)),{type:e.blob.type}),new File([e.vtt],S(t,"vtt"),{type:"text/vtt"})],t)}languagesOf(e){return t(e)}}export{O as DEFAULT_SETTINGS};
1
+ import{copyOf as e,languagesOf as t,newDemo as s,sayOf as i,scenarioOf as o,sentences as n}from"../model/Demo.js";import{parseSubtitles as a,toSrt as r,toVtt as h}from"../model/Subtitles.js";import{actionTime as p,estimate as l}from"../model/Timing.js";import{parseDemo as d,validate as c}from"../model/Validate.js";import{Hand as m}from"../page/Input.js";import{Overlay as g}from"../page/Overlay.js";import{Targets as u}from"../page/Targets.js";import{Speech as y}from"../speech/Speech.js";import{narrationFor as f,transcribe as w}from"../speech/Transcribe.js";import{Store as v}from"../store/Store.js";import{demoFromLink as k,download as S,fileName as b,linkTo as P,shareFiles as T}from"../store/Share.js";import{extensionOf as x,recordMicrophone as E,startFilming as R,videoSize as j}from"../video/Film.js";import{renderMusic as $}from"../speech/Music.js";import{readPack as M,writePack as L}from"../speech/Pack.js";import{Player as K}from"./Player.js";import{Recorder as N}from"./Recorder.js";import{readAction as B}from"./Read.js";import{mountUI as D}from"../ui/EngineUI.js";import{agentTools as I}from"../agent/Agent.js";import{openPresenter as O}from"../ui/Presenter.js";import{DEFAULT_RELAY as A,qrSvg as F,RemoteLink as C}from"../remote/Remote.js";import{DEFAULT_SETTINGS as J,loadSettings as U,saveSettings as z}from"./Settings.js";const V=["pointerdown","pointerup","pointermove","pointerover","pointerout","mousedown","mouseup","mousemove","mouseover","mouseout","click","dblclick","contextmenu","wheel","touchstart","touchmove","touchend","keydown","keyup","keypress"];export class DemoEngine{constructor(e){this.options=e,this.listeners=new Set,this.packs=new Map,this.remoteSent="",this.remoteTimer=0,this.getState=()=>this.state,this.subscribe=e=>(this.listeners.add(e),()=>this.listeners.delete(e)),this.hintTimer=0,this.targets=new u({...e.targets,labels:e.labels}),this.overlay=new g(e.overlay),this.hand=new m(this.overlay.cursor,()=>this.player?.speedNow??1),this.settingsKey=`protomaze-demo-engine:${e.app}:settings`,this.state={session:{mode:"idle"},settings:U(this.settingsKey),speech:{}},this.speech=new y(()=>this.state.settings.speech,()=>this.set({speech:{...this.speech.state}})),this.store=new v(`protomaze-demo-engine:${e.app}`),this.store.subscribe(()=>this.emit()),this.plugins=e.plugins??[]}emit(){this.state={...this.state},this.listeners.forEach(e=>e()),this.toRemote()}set(e){this.state={...this.state,...e},this.listeners.forEach(e=>e()),this.toRemote()}setSession(e){this.set({session:e})}updateSession(e,t){this.state.session.mode===e&&this.setSession({...this.state.session,...t})}say(e,t=!1){this.set({message:e?{text:e,error:t}:void 0})}changeSettings(e){const t={...this.state.settings,...e};z(this.settingsKey,t),this.set({settings:t}),e.music?.on&&this.loadMusic().catch(()=>{})}language(){const e=this.state.settings.language;return"page"!==e?e:this.options.language?.()??this.options.languages?.[0]??(navigator.language.split("-")[0]||"en")}languages(){return this.options.languages??[this.language()]}pluginKinds(){return this.plugins.flatMap(e=>Object.keys(e.actions??{}))}pluginAction(e){return this.plugins.map(t=>t.actions?.[e]).find(Boolean)}read(e,t){return B(e,this.options.labels,this.plugins,t)}async mount(){if(this.unmount)return;this.overlay.mount();const e=D(this),t=e=>this.key(e);window.addEventListener("keydown",t,!0);const s=e=>this.gate(e);V.forEach(e=>window.addEventListener(e,s,{capture:!0,passive:!1})),this.state.settings.music.on&&this.loadMusic().catch(()=>{});const i=!1===this.options.agent?void 0:this.options.agent??"demoEngine";i&&(window[i]=I(this)),this.unmount=()=>{e(),window.removeEventListener("keydown",t,!0),V.forEach(e=>window.removeEventListener(e,s,{capture:!0})),i&&delete window[i],this.overlay.unmount()},await this.arrived()}destroy(){this.closeRemote(),this.stopLoop(),this.stop(),this.unmount?.(),this.unmount=void 0}async arrived(){const e=sessionStorage.getItem(this.pendingKey());if(sessionStorage.removeItem(this.pendingKey()),e){const{demo:t,verb:s,from:i,loop:o}=JSON.parse(e);return"loop"===s&&o?void this.loop(o.demos,{gap:o.gap,idle:o.idle,reset:o.reload?"reload":void 0},o.index):this.whenClicked(t.title,"film"===s?"Film":"Play",()=>"film"===s?this.film(t):this.play(t,{from:i}),!0)}const t=await k();if(t){const e=c(t,this.pluginKinds());return e.length?this.say(`The link's demo: ${e[0].path} ${e[0].message}`,!0):(await this.save(t),this.say(`"${t.title}" came with the link: it is kept here.`),this.openStudio(t))}const s=new URL(window.location.href),i=s.searchParams.get("demo");if(i){s.searchParams.delete("demo"),window.history.replaceState(window.history.state,"",s.toString());const e=(await this.entries()).find(e=>e.demo.id===i);e&&this.whenClicked(e.demo.title,"Play",()=>this.play(e.demo),!0)}}gate(e){const t=this.state.session;if(!e.isTrusted||"playing"!==t.mode||t.paused||t.looping)return;const s=e.composedPath();if(s.includes(this.overlay.host))return;if(t.guided&&t.instruction){const i=t.player.viewerTarget();if(i&&(s.includes(i)||e instanceof KeyboardEvent&&i.contains(document.activeElement)))return;if(!i&&e instanceof KeyboardEvent)return}const i=e.defaultPrevented;e.cancelable&&e.preventDefault(),e.stopImmediatePropagation(),i||"pointerdown"!==e.type&&"keydown"!==e.type&&"wheel"!==e.type||this.hint(t.guided?'Only the ringed part now: or "Do it for me"':"Playing: Space pauses, and the app is yours then. Esc stops.")}hint(e){window.clearTimeout(this.hintTimer),this.set({hint:e}),this.hintTimer=window.setTimeout(()=>this.set({hint:void 0}),3e3)}pendingKey(){return`protomaze-demo-engine:${this.options.app}:pending`}key(e){if(!e.isTrusted)return;const t=e.composedPath(),s=t.some(e=>e instanceof HTMLElement&&(e.isContentEditable||e.matches("input, textarea, select"))),i=t.includes(this.overlay.host),o=this.state.session,n=()=>{e.preventDefault(),e.stopPropagation()};if("ready"!==o.mode)if("recording"!==o.mode){if("l"===e.key.toLowerCase()&&e.ctrlKey&&e.shiftKey&&this.looping)return n(),this.stopLoop();if(!("playing"!==o.mode||o.looping||o.checking||s&&(i||o.guided&&o.instruction))){if("Escape"===e.key)this.stop();else if(" "===e.key||"b"===e.key||"."===e.key)this.togglePause();else if("ArrowRight"===e.key||"Enter"===e.key||"PageDown"===e.key)o.player.next();else if("ArrowLeft"===e.key||"PageUp"===e.key)o.player.back();else if("Home"===e.key)o.player.goTo(0);else if("End"===e.key)o.player.goTo(o.steps-1);else{if(!/^[1-9]$/.test(e.key)||e.ctrlKey||e.metaKey||e.altKey)return;o.player.goTo(Number(e.key)-1)}n()}}else"Escape"!==e.key||s||(n(),this.stopRecording?.());else"Escape"===e.key&&(n(),o.cancel())}async entries(){return await this.store.ready(),this.entriesNow()}entriesNow(){const{demos:e,videos:t}=this.store.get(),s=new Map(e.map(e=>[e.id,e])),i=this.language(),n=(this.options.demos??[]).map(e=>"demo"in e?e:{demo:e,scenario:void 0});return[...n.map(({demo:e,scenario:n})=>{const a=s.get(e.id);return a?{demo:a,scenario:a.scenario??n??o(a,i),origin:"edited",video:t.get(e.id)}:{demo:e,scenario:n??o(e,i),origin:"app",video:t.get(e.id)}}),...e.filter(e=>!n.some(t=>t.demo.id===e.id)).map(e=>({demo:e,scenario:e.scenario??o(e,i),origin:"here",video:t.get(e.id)}))]}async save(t){const s=c(t,this.pluginKinds());if(s.length)throw new Error(`Not a demo: ${s.map(e=>`${e.path} ${e.message}`).join("; ")}`);await this.store.saveDemo(e(t))}async remove(e){await this.store.deleteDemo(e),this.state.studio?.demo.id===e&&this.closeStudio()}parse(e){return d(e,this.pluginKinds())}create(e){return s(e,this.options.start?.current())}openStudio(t){this.set({studio:{demo:e(t),opened:Date.now()}})}closeStudio(){this.set({studio:void 0})}activated(){const e=navigator.userActivation;return!e||e.isActive}whenClicked(e,t,s,i=!1){const o=()=>{this.setSession({mode:"idle"}),this.speech.wake(),s().catch(e=>this.say(e.message,!0))};if(!i&&this.activated())return o();this.setSession({mode:"ready",title:e,verb:t,go:o,cancel:()=>this.setSession({mode:"idle"})})}async goToStart(e,t,s,i){if(!e.start||!this.options.start)return!0;sessionStorage.setItem(this.pendingKey(),JSON.stringify({demo:e,verb:t,from:s,loop:i}));return"reload"!==await this.options.start.go(e.start)&&(sessionStorage.removeItem(this.pendingKey()),!0)}busy(){return"idle"!==this.state.session.mode&&"ready"!==this.state.session.mode}play(e,t={}){return new Promise(s=>this.whenClicked(e.title,"Play",async()=>{if(this.busy())return s(void 0);if(this.say(void 0),!await this.goToStart(e,"play",t.from))return s(void 0);const i=await this.run(e,t);s(i)}))}async run(e,t={}){const{settings:s}=this.state,i=t.language??this.language(),o=s.music.on&&!t.checking&&!t.guided&&await Promise.race([this.loadMusic(),new Promise(e=>setTimeout(()=>e(!1),t.filming?6e4:1500))]);this.speech.setPack(s.usePacks?await this.pack(e):void 0);const n=new K(e,{language:i,subtitles:s.subtitles,waitForPresenter:s.waitForPresenter&&!t.looping,catchUp:s.catchUp,music:Boolean(o),...t},{hand:this.hand,targets:this.targets,overlay:this.overlay,speech:this.speech,plugins:this.plugins,ready:this.options.ready,read:(e,t)=>this.read(e,t),reset:async()=>!e.start||!this.options.start||"reload"!==await this.options.start.go(e.start),update:e=>this.updateSession("playing",e)});this.setSession({mode:"playing",title:e.title,demo:e,steps:e.steps.length,filming:Boolean(t.filming),checking:Boolean(t.checking),guided:Boolean(t.guided),looping:Boolean(t.looping),presenting:Boolean(t.presenting),player:n,step:t.from??0,caption:"",paused:!1,waiting:!1,catchingUp:!1}),this.player=n;const a=await n.play().finally(()=>this.player=void 0);return this.setSession({mode:"idle"}),t.checking||a.navigated||(this.set({lastRun:{json:JSON.stringify(e),language:i,timing:a.timing}}),a.error&&"Stopped."!==a.error&&this.say(a.error,!0)),a}stop(){const e=this.state.session;"playing"===e.mode&&e.player.stop(),"recording"===e.mode&&this.stopRecording?.(),"ready"!==e.mode&&"preparing"!==e.mode||this.setSession({mode:"idle"})}togglePause(){const e=this.state.session;"playing"===e.mode&&(e.paused?e.player.resume():e.player.pause())}resume(){const e=this.state.session;"playing"===e.mode&&e.player.resume()}next(){const e=this.state.session;"playing"===e.mode&&e.player.next()}back(){const e=this.state.session;"playing"===e.mode&&e.player.back()}openPresenter(e={}){return O(this,e)}presenterKey(e){this.key(e)}present(e,t={}){this.openDialog({kind:"present",demo:e,from:t.from})}openDialog(e){this.set({dialog:e,...this.state.library&&this.options.launcher?{library:void 0}:{}})}closeDialog(){this.set({dialog:void 0})}openSettings(){this.set({library:"settings"})}showLibrary(e){this.set({library:e})}goTo(e){const t=this.state.session;return"playing"===t.mode&&t.player.goTo(e)}guide(e,t={}){return this.play(e,{...t,guided:!0})}doItForMe(){const e=this.state.session;"playing"===e.mode&&e.player.doItForMe()}async openRemote(){if(!1===this.options.remote)throw new Error("No phone remote in this app");if(this.state.remote)return this.state.remote;const e=this.options.remote?.relay??A;this.remoteLink=await C.open(e,{command:e=>this.fromRemote(e),hello:()=>this.remoteSent="",peers:e=>this.state.remote&&this.set({remote:{...this.state.remote,peers:e}})});const t={url:this.remoteLink.url,svg:F(this.remoteLink.url),peers:0};return this.set({remote:t}),this.remoteTimer=window.setInterval(()=>this.toRemote(!0),1e3),t}closeRemote(){window.clearInterval(this.remoteTimer),this.remoteLink?.close(),this.remoteLink=void 0,this.remoteSent="",this.set({remote:void 0})}fromRemote(e){const t=this.state.session;"playing"===t.mode&&("next"===e.do?t.player.next():"back"===e.do?t.player.back():"goto"===e.do&&void 0!==e.step?t.player.goTo(e.step):"stop"===e.do?this.stop():"toggle"===e.do&&(t.waiting?t.player.next():this.togglePause()))}toRemote(e=!1){if(!this.remoteLink)return;const t=this.remoteState(),{at:s,elapsed:i,stepElapsed:o,...n}=t,a=JSON.stringify(n);(a!==this.remoteSent||e&&t.playing)&&(this.remoteSent=a,this.remoteLink.send(t))}remoteState(){const e=this.state.session,t=Date.now();if("playing"!==e.mode||e.checking)return{playing:!1,title:"",steps:[],step:0,caption:"",paused:!1,waiting:!1,filming:!1,elapsed:0,stepElapsed:0,planned:0,at:t};const s=this.language(),o=this.timing(e.demo,s),a=o.steps.find(t=>t.step===e.step),r=e.player.elapsed();return{playing:!0,title:e.demo.title,steps:e.demo.steps.map((e,t)=>({title:e.title??`Step ${t+1}`,script:n(i(e,s)),...e.notes?{notes:e.notes}:{}})),step:e.step,caption:e.caption,paused:e.paused,waiting:e.waiting,filming:e.filming,elapsed:r,stepElapsed:r-e.player.stepStartedAt,planned:o.duration,...a?{plannedStep:a.end-a.start}:{},at:t}}pack(e){let t=this.packs.get(e.id);return t||(t=(async()=>{const t=await this.store.asset(`narration:${e.id}`);if(t)return M(await t.arrayBuffer());const s=this.options.narration?.(e);if(!s)return;const i=await fetch(s);return i.ok?M(await i.arrayBuffer()):void 0})().catch(()=>{}),this.packs.set(e.id,t)),t}async makePack(e,s=()=>{}){const i=await this.pack(e);this.speech.setPack(i);const o=t(e).flatMap(t=>e.steps.flatMap(e=>n(e.say[t]??"").map(e=>({language:t,text:e})))),a=o.filter((e,t)=>o.findIndex(t=>t.language===e.language&&t.text===e.text)===t),r=[];for(const e of a)s(r.length,a.length),r.push({...await this.speech.packable(e.text,e.language),...e});s(r.length,a.length);const h=L(e.id,r);return await this.store.saveAsset(`narration:${e.id}`,h),this.packs.delete(e.id),h}async downloadPack(e){try{const t=await this.makePack(e,(e,t)=>this.say(`Making the narration pack: ${e} / ${t}`));S(t,`${e.id}.narration.zip`),this.say(`Narration pack: ${Math.round(t.size/1e5)/10} MB, kept here too. Check it in beside ${e.id}.demo.json, for every viewer.`)}catch(e){this.say(`Narration pack: ${e.message}`,!0)}}async dropPack(e){await this.store.saveAsset(`narration:${e.id}`,void 0),this.packs.delete(e.id)}async setMusic(e){await this.store.saveAsset("music",e),this.musicLoaded=void 0;const{music:t}=this.state.settings;this.changeSettings({music:e?{...t,on:!0,track:"file",name:e.name??"music"}:{...t,track:"calm",name:void 0}})}async loadMusic(){const{music:e}=this.state.settings,t="file"===e.track?`file:${e.name}`:e.track;if(this.musicLoaded!==t){if("file"===e.track){const t=await this.store.asset("music");if(!t)return!1;await this.speech.setMusic(t,e.volume).catch(()=>{})}else this.speech.setMusicBuffer(await $(e.track),e.volume);this.musicLoaded=t}return this.speech.setMusicVolume(e.volume),this.speech.hasMusic}async listenToMusic(e=20){if(this.speech.wake(),!await this.loadMusic())return()=>{};this.speech.startMusic();const t=setTimeout(()=>this.speech.stopMusic(),1e3*e);return()=>{clearTimeout(t),this.speech.stopMusic(.6)}}async loop(e,t={},s=0){if(0===e.length)return;this.stopLoop();let i=!1,o=0,n=s;const a=t.idle??this.state.settings.loopIdle,r=t.gap??1500,h=e.map(e=>e.title),p=e=>{if(!e.isTrusted||e.composedPath().includes(this.overlay.host))return;o=performance.now();const t=this.state.session;"playing"===t.mode&&t.looping&&t.player.stop(!0)},l=["pointerdown","keydown","wheel","touchstart"];l.forEach(e=>window.addEventListener(e,p,{capture:!0,passive:!0}));this.looping={demos:e,options:t,stop:()=>{i=!0,l.forEach(e=>window.removeEventListener(e,p,{capture:!0}));const e=this.state.session;"playing"===e.mode&&e.looping&&e.player.stop(),this.set({loop:void 0})}};const d=e=>new Promise(t=>setTimeout(t,e));for(;!i;){const s=e[n%e.length];this.set({loop:{titles:h,index:n%e.length,visitor:!1}});if(!await this.goToStart(s,"loop",void 0,{demos:e,index:n%e.length,gap:t.gap,idle:t.idle,reload:"reload"===t.reset})||i)return;const p=await this.run(s,{looping:!0,catchUp:!1});if(i)break;if(p.error&&performance.now()-o<1e3){for(;!i&&performance.now()-o<a;)this.set({loop:{titles:h,index:n%e.length,visitor:!0,resumesAt:Date.now()+a-(performance.now()-o)}}),await d(1e3);if(i)break;if("reload"===t.reset)return sessionStorage.setItem(this.pendingKey(),JSON.stringify({demo:s,verb:"loop",loop:{demos:e,index:n%e.length,gap:t.gap,idle:t.idle,reload:!0}})),window.location.reload();await(t.reset?.())}else n++,await d(r)}}stopLoop(){this.looping?.stop(),this.looping=void 0}elapsed(){const e=this.state.session;return"playing"===e.mode?e.player.elapsed():void 0}async check(e,t={}){const s=c(e,this.pluginKinds());if(s.length)return{ok:!1,problems:s,failures:[],duration:0,error:"Not a valid demo"};if(this.busy())return{ok:!1,problems:s,failures:[],duration:0,error:`Busy: ${this.state.session.mode}`};if(!1!==t.fromStart&&e.start&&this.options.start){if("reload"===await this.options.start.go(e.start))return{ok:!1,problems:s,failures:[],duration:0,error:"Its start reloads the page: check again once it is back"}}const i=await this.run(e,{...t,speed:t.speed??8,keepGoing:!0,checking:!0,catchUp:!0,subtitles:!1}),o=i.failures.map(t=>({...t,action:e.steps[t.step].actions[t.index]}));return{ok:!i.error&&0===o.length,error:i.error,failures:o,problems:s,duration:i.timing.duration}}timing(e,t=this.language()){const s=this.state.lastRun;return s&&s.language===t&&s.json===JSON.stringify(e)&&s.timing.steps.length===e.steps.length?s.timing:l(e,{language:t,sayTime:e=>this.speech.duration(e,t),actionTime:e=>{const t=this.pluginAction(e.do);return t?.duration?.(e)??p(e)}})}film(e,t={}){return new Promise(s=>this.whenClicked(e.title,"Film",async()=>this.busy()?s(void 0):(this.say(void 0),await this.goToStart(e,"film")?void s(await this.filmNow(e,t)):s(void 0))))}async filmNow(e,t){const s=t.language??this.language();let o=!1;const a=await R({soundtrack:this.speech.soundtrack(),microphone:t.microphone,crop:this.options.filmElement?.(),...this.filmQuality(),onEnded:()=>{o=!0,this.stop()}});let r;try{const t=e.steps.flatMap(e=>n(i(e,s)));this.setSession({mode:"preparing",title:e.title,text:"Preparing the narration"}),await this.speech.prepare(t,s,(e,t)=>this.updateSession("preparing",{text:`Preparing the narration: ${e} / ${t}`})),o||"preparing"!==this.state.session.mode||(r=await this.run(e,{language:s,filming:a}))}finally{"preparing"===this.state.session.mode&&this.setSession({mode:"idle"})}const{video:p,voice:l}=await a.stop();if(!r||r.error)return void this.say("Stopped."!==r?.error&&r?`Filming failed: ${r.error}`:"Filming stopped: nothing kept.",Boolean(r?.error&&"Stopped."!==r.error));let d=r.timing.cues;l&&"off"===this.state.settings.speech.voice&&(this.setSession({mode:"preparing",title:e.title,text:"Transcribing what was said"}),d=await this.transcribe(l,s).catch(()=>d),this.setSession({mode:"idle"}));const c={id:e.id,blob:p,at:Date.now(),json:JSON.stringify(e),vtt:h(d),timing:r.timing,language:s,look:this.look(s),...l?{voice:l}:{}};return await this.store.saveVideo(c),this.say(`Filmed "${e.title}": ${Math.round(p.size/1e6)} MB, kept here.`),c}filmQuality(){const{frameRate:e,bitrate:t,lines:s,aspect:i,fit:o}=this.state.settings.film;return{frameRate:e,bitrate:t,fit:o,...s?{size:j(s,i)}:{}}}look(e){const{settings:t}=this.state,s=this.options.appTheme?.(),i=this.options.language?.();return{...s?{theme:s}:{},...i?{locale:i}:{},voice:t.speech.voice,language:e,subtitles:t.subtitles}}async transcribe(e,t=this.language()){const{settings:s}=this.state;return w(e,{language:t,with:s.transcriber,model:s.whisperModel,elevenLabsKey:s.speech.elevenlabs.key,progress:e=>this.set({speech:e<1?{loading:e}:{}})})}record(e={}){return new Promise(t=>this.whenClicked(e.into?.title??"New demo","Record",async()=>{if(this.busy())return t();this.say(void 0),await this.recordNow(e,t)}))}async recordNow(t,i){const{settings:o}=this.state,n=this.language();let a,r;try{o.filmRecording?a=await R({soundtrack:this.speech.soundtrack(),microphone:o.microphone,crop:this.options.filmElement?.(),...this.filmQuality(),onEnded:()=>{this.stopRecording?.()}}):o.microphone&&(r=await E())}catch(e){return this.say(`Could not start: ${e.message}`,!0),i()}const p=this.options.start?.current(),l=new N(this.targets,this.plugins,n,e=>this.updateSession("recording",e));a?.resume();const d=performance.now();this.setSession({mode:"recording",filming:Boolean(a),microphone:Boolean(r||a&&o.microphone),step:0,caption:"",actions:0}),this.nextStepRecording=()=>l.nextStep(),this.sayRecording=e=>l.say(e),this.stopRecording=async()=>{this.stopRecording=this.nextStepRecording=this.sayRecording=void 0;const c=Boolean(r||a&&o.microphone),m=l.stop(c),g=performance.now()-d;this.setSession({mode:"preparing",title:"Recording",text:"Keeping what was recorded"});try{const[i,o]=await Promise.all([r?.stop(),a?.stop()]),l=i??o?.voice;let d=[];if(l){this.updateSession("preparing",{text:"Transcribing what was said"});try{d=await this.transcribe(l,n);const e=f(m.stepStarts,d);m.steps.forEach((t,s)=>{!t.say[n]&&e[s]&&(t.say[n]=e[s])})}catch(e){this.say(`Transcribing failed: ${e.message}`,!0)}}const c=m.steps.filter(e=>e.actions.length>0||Object.values(e.say).some(Boolean)),u=t.into?e(t.into):{...s("Recorded demo",p),steps:[]},y=t.after??u.steps.length-1,w={...u,steps:[...u.steps.slice(0,y+1),...c,...u.steps.slice(y+1)]};0===w.steps.length&&w.steps.push({say:{},actions:[]}),o&&await this.store.saveVideo({id:w.id,blob:o.video,at:Date.now(),json:JSON.stringify(w),vtt:h(d),language:n,look:{...this.look(n),voice:"off",subtitles:!1},timing:{duration:g,steps:m.stepStarts.map((e,t)=>({step:t,start:e,end:m.stepStarts[t+1]??g})),cues:d.map(e=>({...e,step:0})),actions:[]},...o.voice?{voice:o.voice}:{}}),this.setSession({mode:"idle"}),this.say(`Recorded ${c.length} step${1===c.length?"":"s"}${o?", and filmed":""}.`),t.into&&this.state.studio?.demo.id===t.into.id?this.set({studio:{...this.state.studio,recorded:{steps:w.steps,at:Date.now()}}}):this.openStudio(w)}catch(e){this.setSession({mode:"idle"}),this.say(e.message,!0)}i()}}nextStep(){this.nextStepRecording?.()}narrate(e){this.sayRecording?.(e)}async finishRecording(){await(this.stopRecording?.())}link(e){return P(e)}downloadDemo(e,t="json"){if("md"===t)return S(e.scenario??o(e,this.language()),b(e.id,"md"),"text/markdown");const{scenario:s,savedAt:i,...n}=e;S(JSON.stringify(n,null,2)+"\n",b(e.id,"demo.json"),"application/json")}downloadVideo(e,t,s=!1){return"vtt"===s?S(e.vtt,b(t,"vtt"),"text/vtt"):"srt"===s?S(r(a(e.vtt)),b(t,"srt"),"application/x-subrip"):void S(e.blob,b(t,x(e.blob)))}shareVideo(e,t){return T([new File([e.blob],b(t,x(e.blob)),{type:e.blob.type}),new File([e.vtt],b(t,"vtt"),{type:"text/vtt"})],t)}languagesOf(e){return t(e)}}export{J as DEFAULT_SETTINGS};
@@ -27,6 +27,8 @@ export type PlayOptions = {
27
27
  guided?: boolean;
28
28
  /** The music bed under the narration (`Speech.setMusic`). */
29
29
  music?: boolean;
30
+ /** Presented: the bar offers the presenter's screen. */
31
+ presenting?: boolean;
30
32
  };
31
33
  export type PlayResult = {
32
34
  /** When what happened, ms from the start: the subtitles are its cues. */
@@ -45,6 +45,8 @@ export type DemoSettings = {
45
45
  loopIdle: number;
46
46
  /** A demo's narration pack, where it has one, before any voice: made once, played by everyone. */
47
47
  usePacks: boolean;
48
+ /** Presenting, the presenter's screen: a window, always on top, the phone, or none. */
49
+ presenterScreen: 'window' | 'onTop' | 'phone' | 'none';
48
50
  };
49
51
  export declare const DEFAULT_SETTINGS: DemoSettings;
50
52
  export declare function loadSettings(key: string): DemoSettings;
@@ -1 +1 @@
1
- import{DEFAULT_SPEECH as e}from"../speech/Speech.js";export const DEFAULT_SETTINGS={speech:e,language:"page",subtitles:!0,waitForPresenter:!1,catchUp:!0,microphone:!1,filmRecording:!1,transcriber:"whisper",whisperModel:"base",music:{on:!1,volume:.18,track:"calm"},film:{frameRate:30,bitrate:8,lines:1080,aspect:"16:9",fit:"fit"},loopIdle:3e4,usePacks:!0};export function loadSettings(t){try{const s=JSON.parse(localStorage.getItem(t)??"{}");return{...DEFAULT_SETTINGS,...s,speech:{...e,...s.speech,elevenlabs:{...e.elevenlabs,...s.speech?.elevenlabs}},music:{...DEFAULT_SETTINGS.music,...s.music?.name?{track:"file"}:{},...s.music},film:{...DEFAULT_SETTINGS.film,...s.film}}}catch{return DEFAULT_SETTINGS}}export function saveSettings(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch{}}
1
+ import{DEFAULT_SPEECH as e}from"../speech/Speech.js";export const DEFAULT_SETTINGS={speech:e,language:"page",subtitles:!0,waitForPresenter:!1,catchUp:!0,microphone:!1,filmRecording:!1,transcriber:"whisper",whisperModel:"base",music:{on:!1,volume:.18,track:"calm"},film:{frameRate:30,bitrate:8,lines:1080,aspect:"16:9",fit:"fit"},loopIdle:3e4,usePacks:!0,presenterScreen:"window"};export function loadSettings(t){try{const s=JSON.parse(localStorage.getItem(t)??"{}");return{...DEFAULT_SETTINGS,...s,speech:{...e,...s.speech,elevenlabs:{...e.elevenlabs,...s.speech?.elevenlabs}},music:{...DEFAULT_SETTINGS.music,...s.music?.name?{track:"file"}:{},...s.music},film:{...DEFAULT_SETTINGS.film,...s.film}}}catch{return DEFAULT_SETTINGS}}export function saveSettings(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch{}}
package/index.d.ts CHANGED
@@ -20,7 +20,8 @@ export * from './store/Store';
20
20
  export * from './store/Share';
21
21
  export * from './agent/Agent';
22
22
  export { GUIDE } from './agent/Guide';
23
- export { DemoLibrary, Library, Narration, Recording, Shadow } from './ui/Library';
23
+ export { DemoLibrary, Library, Settings, Shadow } from './ui/Library';
24
+ export { Dialog } from './ui/Dialogs';
24
25
  export { Studio } from './ui/Studio';
25
26
  export { Timeline } from './ui/Timeline';
26
27
  export { openPresenter, mountPresenter } from './ui/Presenter';
package/index.js CHANGED
@@ -1 +1 @@
1
- export*from"./model/Demo.js";export*from"./model/Timing.js";export*from"./model/Subtitles.js";export*from"./model/Validate.js";export*from"./engine/DemoEngine.js";export*from"./engine/Player.js";export*from"./engine/Recorder.js";export*from"./engine/Plugin.js";export*from"./engine/Settings.js";export*from"./page/Targets.js";export*from"./page/Input.js";export*from"./page/Overlay.js";export*from"./speech/Speech.js";export*from"./speech/Transcribe.js";export*from"./speech/Pack.js";export*from"./speech/Music.js";export*from"./store/Zip.js";export*from"./video/Film.js";export*from"./store/Store.js";export*from"./store/Share.js";export*from"./agent/Agent.js";export{GUIDE}from"./agent/Guide.js";export{DemoLibrary,Library,Narration,Recording,Shadow}from"./ui/Library.js";export{Studio}from"./ui/Studio.js";export{Timeline}from"./ui/Timeline.js";export{openPresenter,mountPresenter}from"./ui/Presenter.js";export{useEngine,useDemos}from"./ui/Hooks.js";export{UI_CSS}from"./ui/Styles.js";
1
+ export*from"./model/Demo.js";export*from"./model/Timing.js";export*from"./model/Subtitles.js";export*from"./model/Validate.js";export*from"./engine/DemoEngine.js";export*from"./engine/Player.js";export*from"./engine/Recorder.js";export*from"./engine/Plugin.js";export*from"./engine/Settings.js";export*from"./page/Targets.js";export*from"./page/Input.js";export*from"./page/Overlay.js";export*from"./speech/Speech.js";export*from"./speech/Transcribe.js";export*from"./speech/Pack.js";export*from"./speech/Music.js";export*from"./store/Zip.js";export*from"./video/Film.js";export*from"./store/Store.js";export*from"./store/Share.js";export*from"./agent/Agent.js";export{GUIDE}from"./agent/Guide.js";export{DemoLibrary,Library,Settings,Shadow}from"./ui/Library.js";export{Dialog}from"./ui/Dialogs.js";export{Studio}from"./ui/Studio.js";export{Timeline}from"./ui/Timeline.js";export{openPresenter,mountPresenter}from"./ui/Presenter.js";export{useEngine,useDemos}from"./ui/Hooks.js";export{UI_CSS}from"./ui/Styles.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protomaze/demo-engine",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Protomaze Demo Engine: record, edit, narrate, play and film demos of a web app, in the browser",
5
5
  "repository": {
6
6
  "type": "git",
@@ -35,7 +35,8 @@
35
35
  ],
36
36
  "author": "Tom Crauwels",
37
37
  "dependencies": {
38
- "@protomaze/time": "^1.16.1"
38
+ "@protomaze/time": "^1.16.1",
39
+ "qrcode-generator": "^2.0.4"
39
40
  },
40
41
  "peerDependencies": {
41
42
  "react": "^18.2.0",
@@ -0,0 +1,66 @@
1
+ /**
2
+ * The presenter's screen on a phone: a QR code opens it at the relay, which passes messages between
3
+ * this page and the phone and sees nothing - they are encrypted end to end with a key that travels
4
+ * only in the QR code's link (after `#`, never sent to a server). See `remote/README.md`.
5
+ */
6
+ export declare const DEFAULT_RELAY = "https://remote.protomaze.com";
7
+ /** What the phone shows. */
8
+ export type RemoteState = {
9
+ /** False: nothing plays; the rest describes the last demo, or is empty. */
10
+ playing: boolean;
11
+ title: string;
12
+ steps: {
13
+ title: string;
14
+ script: string[];
15
+ notes?: string;
16
+ }[];
17
+ step: number;
18
+ caption: string;
19
+ paused: boolean;
20
+ /** Paused for the presenter after a step: "Continue". */
21
+ waiting: boolean;
22
+ /** Back and go-to do nothing then. */
23
+ filming: boolean;
24
+ elapsed: number;
25
+ stepElapsed: number;
26
+ planned: number;
27
+ plannedStep?: number;
28
+ /** Date.now() when sent: the phone's clocks run on from it unless paused. */
29
+ at: number;
30
+ };
31
+ export type RemoteCommand = {
32
+ do: 'next' | 'back' | 'toggle' | 'stop' | 'goto';
33
+ step?: number;
34
+ };
35
+ /** A QR code, as SVG markup: dark modules on white, a quiet zone around. */
36
+ export declare function qrSvg(text: string, size?: number): string;
37
+ /**
38
+ * A room at the relay, its key, and the link to it. Sends the state as it changes; hands commands
39
+ * from the phone over; reconnects when the connection drops.
40
+ */
41
+ export declare class RemoteLink {
42
+ private relay;
43
+ private room;
44
+ private key;
45
+ private handlers;
46
+ /** What the QR code holds: the phone page, with the room and key after `#`. */
47
+ readonly url: string;
48
+ peers: number;
49
+ private socket;
50
+ private closed;
51
+ private retry;
52
+ private last;
53
+ private constructor();
54
+ static open(relay: string, handlers: {
55
+ command(command: RemoteCommand): void;
56
+ hello(): void;
57
+ peers(count: number): void;
58
+ }): Promise<RemoteLink>;
59
+ private connect;
60
+ private setPeers;
61
+ private receive;
62
+ private post;
63
+ /** The state, to the phone: as it changes, and every second while playing. */
64
+ send(state: RemoteState): void;
65
+ close(): void;
66
+ }
@@ -0,0 +1 @@
1
+ import t from"qrcode-generator";export const DEFAULT_RELAY="https://remote.protomaze.com";const e=t=>btoa(String.fromCharCode(...t)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""),s=t=>Uint8Array.from(atob(t.replace(/-/g,"+").replace(/_/g,"/")),t=>t.charCodeAt(0));export function qrSvg(e,s=240){const r=t(0,"M");r.addData(e),r.make();const o=r.getModuleCount(),i=o+8;let a="";for(let t=0;t<o;t++)for(let e=0;e<o;e++)r.isDark(t,e)&&(a+=`M${e+4},${t+4}h1v1h-1z`);return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${i} ${i}" width="${s}" height="${s}" shape-rendering="crispEdges"><rect width="${i}" height="${i}" fill="#fff"/><path d="${a}" fill="#000"/></svg>`}export class RemoteLink{constructor(t,e,s,r,o){this.relay=t,this.room=e,this.key=s,this.handlers=o,this.peers=0,this.closed=!1,this.retry=0,this.url=`${t.replace(/\/$/,"")}/#r=${e}&k=${r}`,this.connect()}static async open(t,s){if(!window.isSecureContext||!crypto.subtle)throw new Error("The phone remote needs the app on https (or localhost): browsers encrypt only there");const r=e(crypto.getRandomValues(new Uint8Array(16))),o=crypto.getRandomValues(new Uint8Array(32)),i=await crypto.subtle.importKey("raw",o,"AES-GCM",!1,["encrypt","decrypt"]);return new RemoteLink(t,r,i,e(o),s)}connect(){if(this.closed)return;const t=new WebSocket(`${this.relay.replace(/\/$/,"").replace(/^http/,"ws")}/room/${this.room}`);this.socket=t,t.onopen=()=>this.retry=0,t.onmessage=t=>{this.receive(String(t.data))},t.onclose=t=>{if(this.setPeers(0),4e3!==t.code&&4001!==t.code||(this.closed=!0),this.closed)return;const e=Math.min(15e3,500*2**this.retry++);setTimeout(()=>this.connect(),e)}}setPeers(t){t>this.peers&&this.last&&this.post({type:"state",state:{...this.last,at:Date.now()}}),this.peers=t,this.handlers.peers(t)}async receive(t){let e,r;try{e=JSON.parse(t)}catch{return}if("peers"===e.relay)return this.setPeers(Number(e.count)||0);if(e.iv&&e.data){try{const t=await crypto.subtle.decrypt({name:"AES-GCM",iv:s(e.iv)},this.key,s(e.data));r=JSON.parse((new TextDecoder).decode(t))}catch{return}"hello"===r.type?(this.handlers.hello(),this.last&&this.post({type:"state",state:{...this.last,at:Date.now()}})):"command"===r.type&&this.handlers.command({do:r.do,...void 0!==r.step?{step:r.step}:{}})}}async post(t){if(this.socket?.readyState!==WebSocket.OPEN)return;const s=crypto.getRandomValues(new Uint8Array(12)),r=await crypto.subtle.encrypt({name:"AES-GCM",iv:s},this.key,(new TextEncoder).encode(JSON.stringify(t)));this.socket.send(JSON.stringify({iv:e(s),data:e(new Uint8Array(r))}))}send(t){this.last=t,this.post({type:"state",state:t})}close(){this.closed=!0,this.post({type:"bye"}).finally(()=>this.socket?.close())}}
package/store/Store.d.ts CHANGED
@@ -21,6 +21,14 @@ export type DemoVideo = {
21
21
  language?: Language;
22
22
  /** The presenter's own voice, recorded beside it: to transcribe. */
23
23
  voice?: Blob;
24
+ /** How it was made, for its line in the library: the app's theme and language, the voice, the narration's language, subtitles in the picture. */
25
+ look?: {
26
+ theme?: 'light' | 'dark';
27
+ locale?: string;
28
+ voice: 'free' | 'elevenlabs' | 'system' | 'off';
29
+ language: string;
30
+ subtitles: boolean;
31
+ };
24
32
  };
25
33
  type Kept = {
26
34
  demos: KeptDemo[];
@@ -0,0 +1,15 @@
1
+ import type { DemoEngine, DialogRequest } from '../engine/DemoEngine';
2
+ /**
3
+ * What starting something needs to know, asked as it starts and nowhere else: a video's size and
4
+ * music, a recording's microphone, a booth's demos, a presentation's screen. Its Start is a click
5
+ * in the app's window: sound, filming and windows may start from it.
6
+ */
7
+ export declare function Dialog({ engine, request, theme }: {
8
+ engine: DemoEngine;
9
+ request: DialogRequest;
10
+ theme: 'light' | 'dark';
11
+ }): JSX.Element;
12
+ /** How a video was made, at a glance: the app's theme and language, the voice and its language, subtitles. */
13
+ export declare function VideoLook({ video }: {
14
+ video: import('../store/Store').DemoVideo;
15
+ }): JSX.Element | null;
package/ui/Dialogs.js ADDED
@@ -0,0 +1 @@
1
+ import e,{useEffect as t,useState as n}from"react";import{MUSIC_TRACKS as a}from"../speech/Music.js";import{pickFile as l}from"../store/Share.js";import{extensionOf as o,videoSize as r}from"../video/Film.js";import{Flag as i,Flagged as s}from"./Flag.js";import{useEngine as c}from"./Hooks.js";import{Button as m,Check as d,Icon as p,Labelled as h,Segmented as u}from"./Kit.js";export function Dialog({engine:n,request:a,theme:l}){const o=()=>n.closeDialog();return t(()=>{const e=e=>"Escape"===e.key&&o();return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]),e.createElement("div",{className:"pde dialog-backdrop","data-theme":l,onPointerDown:e=>e.target===e.currentTarget&&o()},e.createElement("div",{className:"dialog"+("video"===a.kind?" wide":""),role:"dialog"},"film"===a.kind&&e.createElement(f,{engine:n,request:a}),"record"===a.kind&&e.createElement(b,{engine:n,request:a}),"loop"===a.kind&&e.createElement(k,{engine:n,request:a}),"present"===a.kind&&e.createElement(N,{engine:n,request:a}),"video"===a.kind&&e.createElement(y,{engine:n,request:a})))}function g({icon:t,title:n,children:a,start:l,onStart:o,disabled:r,engine:i}){return e.createElement(e.Fragment,null,e.createElement("div",{className:"row"},e.createElement(p,{name:t}),e.createElement("h2",{className:"grow"},n),e.createElement(m,{icon:"close",kind:"bare",title:"Close (Esc)",onClick:()=>i.closeDialog()})),e.createElement("div",{className:"col",style:{gap:14}},a),e.createElement("div",{className:"row",style:{justifyContent:"flex-end"}},e.createElement(m,{onClick:()=>i.closeDialog()},"Cancel"),e.createElement(m,{kind:"primary",icon:t,disabled:r,onClick:o},l)))}function E({engine:t}){const{settings:n}=c(t),a=n.speech.voice,l="off"===a?"No voice: subtitles only":"system"===a?"The browser's voice: not heard in videos":"elevenlabs"===a?"ElevenLabs":`Free voices: ${t.languages().map(e=>`${e} ${(t.speech.freeVoice(e)??"none").split(":")[1]??""}`).join(", ")}`;return e.createElement("div",{className:"row small"},e.createElement(p,{name:"listen"}),e.createElement("span",{className:"grow muted"},l,". A narration pack plays first where the demo has one."),e.createElement(m,{small:!0,kind:"bare",onClick:()=>{t.closeDialog(),t.openSettings()}},"Change"))}function v({engine:o}){const{settings:r}=c(o),{music:i}=r,[s,d]=n();t(()=>()=>s?.(),[s]);return e.createElement("div",{className:"col"},e.createElement("div",{className:"row",style:{flexWrap:"wrap",alignItems:"flex-end"}},e.createElement(h,{label:"Music"},e.createElement("select",{className:"field",value:i.on?i.track:"none",onChange:e=>(e=>{if(s?.(),d(void 0),"none"===e)return o.changeSettings({music:{...i,on:!1}});"pick"!==e?o.changeSettings({music:{...i,on:!0,track:e}}):l("audio/*").then(e=>e&&o.setMusic(e))})(e.target.value)},e.createElement("option",{value:"none"},"None"),a.map(t=>e.createElement("option",{key:t.id,value:t.id},t.name)),i.name&&e.createElement("option",{value:"file"},i.name),e.createElement("option",{value:"pick"},"Your own file…"))),i.on&&e.createElement(e.Fragment,null,e.createElement(m,{small:!0,icon:s?"stop":"listen",onClick:()=>{(async()=>{if(s)return s(),d(void 0);d(()=>()=>{});const e=await o.listenToMusic(20);d(()=>e)})()}},s?"Stop":"Listen"),e.createElement(h,{label:`Volume ${Math.round(100*i.volume)} %`},e.createElement("input",{type:"range",min:.02,max:.6,step:.01,value:i.volume,onChange:e=>{o.changeSettings({music:{...i,volume:Number(e.target.value)}}),o.speech.setMusicVolume(Number(e.target.value))}})))),i.on&&e.createElement("span",{className:"small muted"},"file"===i.track?"Your own file":`${a.find(e=>e.id===i.track)?.hint}: composed by the engine, free to use anywhere`,". Quieter while the narration speaks."))}function w({engine:t}){const{settings:n}=c(t),{film:a}=n,l=e=>t.changeSettings({film:{...a,...e}}),o=a.lines?r(a.lines,a.aspect):void 0,i={width:Math.round(innerWidth*devicePixelRatio),height:Math.round(innerHeight*devicePixelRatio)};return e.createElement("div",{className:"col"},e.createElement("div",{className:"row",style:{flexWrap:"wrap",alignItems:"flex-end"}},e.createElement(h,{label:"Size"},e.createElement("select",{className:"field",value:a.lines,onChange:e=>l({lines:Number(e.target.value)})},e.createElement("option",{value:0},"The tab's own (",i.width,"×",i.height,")"),[720,1080,1440,2160].map(t=>{const{width:n,height:l}=r(t,a.aspect);return e.createElement("option",{key:t,value:t},2160===t?"4K":`${t}p`," (",n,"×",l,")")}))),a.lines>0&&e.createElement(e.Fragment,null,e.createElement(h,{label:"Shape"},e.createElement("select",{className:"field",value:a.aspect,onChange:e=>l({aspect:e.target.value})},e.createElement("option",{value:"16:9"},"16:9 landscape"),e.createElement("option",{value:"9:16"},"9:16 portrait"),e.createElement("option",{value:"1:1"},"1:1 square"))),e.createElement(h,{label:"The tab"},e.createElement("select",{className:"field",value:a.fit,onChange:e=>l({fit:e.target.value})},e.createElement("option",{value:"fit"},"Whole, with bars"),e.createElement("option",{value:"fill"},"Filling it, edges cut")))),e.createElement(h,{label:"Quality"},e.createElement("select",{className:"field",value:`${a.frameRate}/${a.bitrate}`,onChange:e=>{const[t,n]=e.target.value.split("/").map(Number);l({frameRate:t,bitrate:n})}},e.createElement("option",{value:"30/4"},"Small"),e.createElement("option",{value:"30/8"},"Good"),e.createElement("option",{value:"60/16"},"High, 60 fps"),e.createElement("option",{value:"60/25"},"Master, 60 fps"),!["30/4","30/8","60/16","60/25"].includes(`${a.frameRate}/${a.bitrate}`)&&e.createElement("option",{value:`${a.frameRate}/${a.bitrate}`},a.frameRate," fps, ",a.bitrate," Mb/s")))),o&&(o.width>1.05*i.width||o.height>1.05*i.height)&&e.createElement("span",{className:"small muted"},"The tab is ",i.width,"×",i.height,": ",o.width,"×",o.height," scales it up, a little soft. A bigger window keeps it sharp."))}function f({engine:t,request:a}){const[l,o]=n(t.language()),[r,i]=n(!1),c=Array.from(new Set([...t.languagesOf(a.demo),...t.languages()]));return e.createElement(g,{engine:t,icon:"film",title:e.createElement(e.Fragment,null,"Film “",a.demo.title,"”"),start:"Start filming",onStart:()=>{t.closeDialog(),t.film(a.demo,{language:l,microphone:r})}},e.createElement("section",{className:"section"},e.createElement("h3",null,"Picture"),e.createElement(w,{engine:t})),e.createElement("section",{className:"section"},e.createElement("h3",null,"Sound"),c.length>1&&e.createElement(h,{label:"Narration in"},e.createElement(u,{value:l,onChange:o,options:c.map(t=>[t,e.createElement(s,{key:t,language:t})])})),e.createElement(E,{engine:t}),e.createElement(v,{engine:t}),e.createElement(d,{label:"My microphone too: my own commentary over it",checked:r,onChange:i})),e.createElement("span",{className:"small muted"},"The browser asks which tab to share: this one. Subtitles come with the video; it is kept here, to download and share."))}function b({engine:t,request:n}){const{settings:a}=c(t),l=n.into?e.createElement(e.Fragment,null,"Record into “",n.into.title,"”",void 0!==n.after?`, after step ${n.after+1}`:""):"Record a new demo";return e.createElement(g,{engine:t,icon:"record",title:l,start:"Start recording",onStart:()=>{t.closeDialog(),t.record({into:n.into,after:n.after})}},e.createElement("span",{className:"muted"},"Do on the page what the demo should show: clicks, typing, choices are recorded as steps' actions."),e.createElement("section",{className:"section"},e.createElement(d,{label:e.createElement(e.Fragment,null,e.createElement(p,{name:"mic"})," My voice becomes the narration"),checked:a.microphone,onChange:e=>t.changeSettings({microphone:e})}),a.microphone&&e.createElement("div",{className:"row",style:{flexWrap:"wrap"}},e.createElement(h,{label:"Speech to text"},e.createElement("select",{className:"field",value:`${a.transcriber}/${a.whisperModel}`,onChange:e=>{const[n,a]=e.target.value.split("/");t.changeSettings({transcriber:n,whisperModel:a})}},e.createElement("option",{value:"whisper/tiny"},"In the browser, quick"),e.createElement("option",{value:"whisper/base"},"In the browser, good"),e.createElement("option",{value:"whisper/small"},"In the browser, best (slower)"),e.createElement("option",{value:`elevenlabs/${a.whisperModel}`},"ElevenLabs Scribe (your key)")))),e.createElement(d,{label:e.createElement(e.Fragment,null,e.createElement(p,{name:"film"})," Film it too"),checked:a.filmRecording,onChange:e=>t.changeSettings({filmRecording:e})}),a.filmRecording&&e.createElement(w,{engine:t})),e.createElement("span",{className:"small muted"},"While recording: Alt+N starts the next step, Alt+H records a hover where the pointer is, Esc stops."))}function k({engine:t,request:a}){const{settings:l}=c(t),o=t.entriesNow().map(e=>e.demo),[r,i]=n(()=>new Set(a.demos.map(e=>e.id))),[s,m]=n(!1),p=o.filter(e=>r.has(e.id));return e.createElement(g,{engine:t,icon:"loop",title:"Loop at a booth",start:"Start the loop",disabled:0===p.length,onStart:()=>{t.closeDialog(),t.loop(p,{reset:s?"reload":void 0})}},e.createElement("section",{className:"section"},e.createElement("h3",null,"Demos, one after the other"),o.map(t=>e.createElement(d,{key:t.id,label:t.title,checked:r.has(t.id),onChange:e=>{const n=new Set(r);e?n.add(t.id):n.delete(t.id),i(n)}}))),e.createElement("section",{className:"section"},e.createElement("h3",null,"Visitors"),e.createElement("span",{className:"small muted"},"A visitor's touch stops the demo and hands the app over; without input, it plays again."),e.createElement("div",{className:"row",style:{flexWrap:"wrap"}},e.createElement(h,{label:"Plays again after"},e.createElement("select",{className:"field",value:l.loopIdle,onChange:e=>t.changeSettings({loopIdle:Number(e.target.value)})},[10,20,30,60,120].map(t=>e.createElement("option",{key:t,value:1e3*t},t," s idle"))))),e.createElement(d,{label:"Reload the page after each visitor: the app afresh",checked:s,onChange:m})),e.createElement("section",{className:"section"},e.createElement("h3",null,"Sound"),e.createElement(E,{engine:t}),e.createElement(v,{engine:t})),e.createElement("span",{className:"small muted"},"Sound needs one click on the page, or a browser started to allow it (Chrome: --autoplay-policy=no-user-gesture-required). Ctrl+Shift+L stops the loop."))}function N({engine:a,request:l}){const o=c(a),{settings:r}=o,i=r.presenterScreen,[s,h]=n();t(()=>{"phone"!==i||o.remote||a.openRemote().catch(e=>h(e.message))},[i]);return e.createElement(g,{engine:a,icon:"present",title:e.createElement(e.Fragment,null,"Present “",l.demo.title,"”"),start:"Start presenting",onStart:()=>{a.closeDialog(),a.play(l.demo,{from:l.from,waitForPresenter:r.waitForPresenter,presenting:!0}),"window"!==i&&"onTop"!==i||a.openPresenter({onTop:"onTop"===i})}},e.createElement("section",{className:"section"},e.createElement("h3",null,"The presenter's screen"),e.createElement("div",{className:"choices"},[["window","present","A window","On this computer, beside the projected app"],["onTop","maximize","Always on top","A small window over everything"],["phone","share","My phone","Scan a QR code: no app needed"],["none","close","None","The bar and a clicker"]].map(([t,n,l,o])=>e.createElement("button",{key:t,type:"button",className:"choice"+(i===t?" on":""),onClick:()=>(e=>a.changeSettings({presenterScreen:e}))(t)},e.createElement(p,{name:n}),e.createElement("strong",null,l),e.createElement("span",{className:"small muted"},o)))),"phone"===i&&e.createElement("div",{className:"row",style:{alignItems:"flex-start",gap:16}},o.remote?e.createElement("div",{className:"qr",dangerouslySetInnerHTML:{__html:o.remote.svg}}):e.createElement("div",{className:"qr muted small"},s??"Opening a room…"),e.createElement("div",{className:"col small"},e.createElement("strong",null,o.remote&&o.remote.peers>1?"● The phone is connected":"Scan it with the phone"),e.createElement("span",{className:"muted"},"The script, your notes, what comes next and the controls show there. Encrypted end to end: the relay passes on what it cannot read."),o.remote&&e.createElement(m,{small:!0,kind:"bare",onClick:()=>a.closeRemote()},"Close the phone's link")))),e.createElement(d,{label:"Wait for me after each step (→ or a clicker goes on)",checked:r.waitForPresenter,onChange:e=>a.changeSettings({waitForPresenter:e})}),e.createElement("span",{className:"small muted"},"Keys: Space pauses, → or PageDown next, ← or PageUp back, 1-9 a step, Esc stops."))}function y({engine:a,request:l}){const{demo:r,video:i}=l,[s]=n(()=>({video:URL.createObjectURL(i.blob),vtt:URL.createObjectURL(new Blob([i.vtt],{type:"text/vtt"}))}));return t(()=>()=>{URL.revokeObjectURL(s.video),URL.revokeObjectURL(s.vtt)},[]),e.createElement(e.Fragment,null,e.createElement("div",{className:"row"},e.createElement(p,{name:"film"}),e.createElement("h2",{className:"grow"},r.title),e.createElement(m,{icon:"close",kind:"bare",title:"Close (Esc)",onClick:()=>a.closeDialog()})),e.createElement("video",{src:s.video,controls:!0,autoPlay:!0,style:{width:"100%",maxHeight:"70vh",background:"#000",borderRadius:8}},!i.look?.subtitles&&e.createElement("track",{kind:"subtitles",src:s.vtt,srcLang:i.language??"en",label:"Narration",default:!0})),e.createElement("div",{className:"row"},e.createElement(VideoLook,{video:i}),e.createElement("span",{className:"grow small muted"},new Date(i.at).toLocaleString()," · ",Math.round(i.blob.size/1e5)/10," MB · ",o(i.blob).toUpperCase()),e.createElement(m,{small:!0,icon:"download",onClick:()=>a.downloadVideo(i,r.title)},"Video"),e.createElement(m,{small:!0,icon:"subtitles",onClick:()=>a.downloadVideo(i,r.title,"vtt")},"Subtitles"),e.createElement(m,{small:!0,kind:"danger",icon:"delete",onClick:()=>{window.confirm("Delete this video?")&&(a.store.deleteVideo(i.id),a.closeDialog())}},"Delete")))}const S={free:["voice","Free voices"],elevenlabs:["premium","ElevenLabs"],system:["computer","The browser's voice"],off:["novoice","No voice"]};export function VideoLook({video:t}){const n=t.look;if(!n)return null;const[a,l]=S[n.voice]??S.off;return e.createElement("span",{className:"row look",style:{gap:6}},n.theme&&e.createElement("span",{title:"dark"===n.theme?"The app dark":"The app light"},e.createElement(p,{name:"dark"===n.theme?"dark":"light"})),n.locale&&e.createElement("span",{title:`The app in ${n.locale}`},e.createElement(i,{language:n.locale})),e.createElement("span",{title:`Narration: ${l}`},e.createElement(p,{name:a})),"off"!==n.voice&&e.createElement("span",{title:`Narration in ${n.language}`},e.createElement(i,{language:n.language})),n.subtitles&&e.createElement("span",{title:"Subtitles in the picture"},e.createElement(p,{name:"subtitles"})))}
package/ui/EngineUI.js CHANGED
@@ -1 +1 @@
1
- import e,{useEffect as t,useState as a}from"react";import{createRoot as n}from"react-dom/client";import{useEngine as l}from"./Hooks.js";import{Button as i,Icon as o,Menu as s,useTheme as r}from"./Kit.js";import{Library as m}from"./Library.js";import{Studio as c}from"./Studio.js";import{UI_CSS as d}from"./Styles.js";export function mountUI(t){t.overlay.addStyles(d);const a=n(t.overlay.ui);return a.render(e.createElement(p,{engine:t})),()=>a.unmount()}function p({engine:t}){const n=l(t),d=r(t.options.theme??"dark"),[p,h]=a(!1),{session:E}=n,f="playing"===E.mode&&(E.filming&&!E.paused||E.looping)||"recording"===E.mode&&E.filming;return e.createElement(e.Fragment,null,"ready"===E.mode&&e.createElement("div",{className:"pde ready","data-theme":d,onClick:e=>e.target===e.currentTarget&&E.cancel()},e.createElement("div",{className:"box"},e.createElement(i,{icon:"Film"===E.verb?"film":"Record"===E.verb?"record":"play",kind:"primary",autoFocus:!0,onClick:E.go},E.verb," “",E.title,"”"),e.createElement("div",{className:"small muted"},"A click here, in the app's window, lets it speak","Play"===E.verb?"":" and be filmed","."),e.createElement(i,{kind:"bare",onClick:E.cancel},"Cancel"))),"preparing"===E.mode&&e.createElement("div",{className:"pde bar","data-theme":d},e.createElement("span",null,E.title),e.createElement("span",{className:"muted"},E.text),void 0!==n.speech.loading&&e.createElement("span",{className:"muted"},Math.round(100*n.speech.loading)," %"),e.createElement(i,{icon:"stop",small:!0,kind:"bare",title:"Stop",onClick:()=>t.stop()})),"playing"===E.mode&&!E.checking&&!f&&e.createElement("div",{className:"pde bar","data-theme":d},E.filming&&e.createElement("span",{className:"dot",title:"Filming: paused time is left out"}),e.createElement("span",{className:"ellipsis",style:{maxWidth:320}},E.title),!E.filming&&e.createElement(i,{icon:"back",small:!0,kind:"bare",title:"Back: this step again; pressed early, the one before (←, PageUp)",onClick:()=>t.back()}),E.filming?e.createElement("span",{className:"muted"},`${E.step+1} / ${E.steps}`):e.createElement(s,{title:"Go to a step (1-9, Home, End)",icon:"expand",label:e.createElement("span",{className:"muted"},E.catchingUp?`… ${E.step+1}`:`${E.step+1} / ${E.steps}`),align:"left",items:E.demo.steps.map((a,n)=>({label:e.createElement("span",{style:{fontWeight:n===E.step?700:400}},`${n+1}. ${a.title??(Object.values(a.say).find(Boolean)??"").slice(0,48)}`),onClick:()=>t.goTo(n)}))}),void 0!==n.speech.loading&&e.createElement("span",{className:"muted small",title:"Downloaded once, then kept by the browser: subtitles meanwhile"},"voice ",Math.round(100*n.speech.loading)," %"),n.hint&&e.createElement("span",{className:"small",style:{color:"var(--accent)"}},n.hint),E.paused&&!E.waiting&&!n.hint&&e.createElement("span",{className:"muted small",title:"What you do now, the demo goes on from"},"paused: the app is yours"),E.guided&&E.instruction&&e.createElement("span",{className:"ellipsis",style:{maxWidth:360,fontWeight:600}},E.instruction),E.guided&&E.instruction&&e.createElement(i,{icon:"flash",title:"The demo does it",onClick:()=>t.doItForMe()},"Do it for me"),e.createElement(i,{icon:E.paused?"play":"pause",kind:E.paused?"primary":void 0,title:"Space",onClick:()=>E.waiting?t.next():t.togglePause()},E.waiting?"Continue":E.paused?"Resume":"Pause"),!E.waiting&&e.createElement(i,{icon:"right",title:"Next step (→, PageDown)",onClick:()=>t.next()}),e.createElement(i,{icon:"present",kind:"bare",title:"The presenter's screen, in a window of its own",onClick:()=>{t.openPresenter()}}),e.createElement(i,{icon:"stop",title:"Esc",onClick:()=>t.stop()},E.guided?"Exit":"Stop")),n.loop?.visitor&&e.createElement("div",{className:"pde bar","data-theme":d,style:{top:"auto",bottom:12,left:"auto",right:12,transform:"none",padding:"4px 6px 4px 12px",opacity:.85}},e.createElement(o,{name:"loop"}),e.createElement("span",{className:"small muted"},"The demo plays again after ",Math.round(t.getState().settings.loopIdle/1e3)," s without input"),e.createElement(i,{icon:"stop",small:!0,kind:"bare",title:"Stop the loop (Ctrl+Shift+L)",onClick:()=>t.stopLoop()})),"recording"===E.mode&&e.createElement(u,{engine:t,theme:d,filmed:E.filming}),n.message&&"idle"===E.mode&&e.createElement(g,{engine:t,theme:d,text:n.message.text,error:n.message.error}),n.studio&&!f&&e.createElement(c,{key:n.studio.opened,engine:t,theme:d}),t.options.launcher&&"idle"===E.mode&&!n.loop&&!n.studio&&e.createElement(e.Fragment,null,e.createElement("div",{className:"pde launcher","data-theme":d},e.createElement(i,{kind:p?"primary":void 0,onClick:()=>h(!p)},e.createElement(o,{name:"demos"}),"Demos")),p&&e.createElement(m,{engine:t,theme:d,floating:!0})))}function u({engine:t,theme:a,filmed:n}){const{session:o}=l(t);return"recording"!==o.mode?null:n?e.createElement("div",{className:"pde bar","data-theme":a,style:{top:"auto",bottom:12,padding:"4px 6px 4px 10px"}},e.createElement("span",{className:"dot"}),e.createElement("span",{className:"small muted"},"Step ",o.step+1),e.createElement(i,{icon:"right",small:!0,kind:"bare",title:"Next step (Alt+N)",onClick:()=>t.nextStep()}),e.createElement(i,{icon:"stop",small:!0,kind:"bare",title:"Stop (Esc)",onClick:()=>{t.finishRecording()}})):e.createElement("div",{className:"pde bar","data-theme":a},e.createElement("span",{className:"dot"}),e.createElement("span",null,"Step ",o.step+1),e.createElement("span",{className:"muted small"},o.actions," action",1===o.actions?"":"s",o.microphone?" · 🎙 listening":""),!o.microphone&&e.createElement("input",{className:"field",style:{width:340},placeholder:"This step's narration (or leave it for later)",value:o.caption,onChange:e=>t.narrate(e.target.value)}),e.createElement(i,{icon:"right",title:"Alt+N",onClick:()=>t.nextStep()},"Next step"),e.createElement(i,{icon:"stop",kind:"primary",title:"Esc",onClick:()=>{t.finishRecording()}},"Stop"),e.createElement("span",{className:"small muted"},"Alt+H: hover here"))}function g({engine:a,theme:n,text:l,error:o}){return t(()=>{if(o)return;const e=setTimeout(()=>a.say(void 0),6e3);return()=>clearTimeout(e)},[l]),e.createElement("div",{className:"pde toast"+(o?" error":""),"data-theme":n,style:{bottom:a.getState().studio?"auto":24,top:a.getState().studio?70:"auto"}},e.createElement("span",{className:"grow"},l),e.createElement(i,{icon:"close",small:!0,kind:"bare",title:"Close",onClick:()=>a.say(void 0)}))}
1
+ import e,{useEffect as t}from"react";import{createRoot as a}from"react-dom/client";import{useEngine as n}from"./Hooks.js";import{Button as l,Icon as i,Menu as o,useTheme as s}from"./Kit.js";import{Library as r}from"./Library.js";import{Dialog as m}from"./Dialogs.js";import{Studio as c}from"./Studio.js";import{UI_CSS as d}from"./Styles.js";export function mountUI(t){t.overlay.addStyles(d);const n=a(t.overlay.ui);return n.render(e.createElement(p,{engine:t})),()=>n.unmount()}function p({engine:t}){const a=n(t),d=s(t.options.theme??"dark"),{session:p}=a,h="playing"===p.mode&&(p.filming&&!p.paused||p.looping)||"recording"===p.mode&&p.filming;return e.createElement(e.Fragment,null,"ready"===p.mode&&e.createElement("div",{className:"pde ready","data-theme":d,onClick:e=>e.target===e.currentTarget&&p.cancel()},e.createElement("div",{className:"box"},e.createElement(l,{icon:"Film"===p.verb?"film":"Record"===p.verb?"record":"play",kind:"primary",autoFocus:!0,onClick:p.go},p.verb," “",p.title,"”"),e.createElement("div",{className:"small muted"},"A click here, in the app's window, lets it speak","Play"===p.verb?"":" and be filmed","."),e.createElement(l,{kind:"bare",onClick:p.cancel},"Cancel"))),"preparing"===p.mode&&e.createElement("div",{className:"pde bar","data-theme":d},e.createElement("span",null,p.title),e.createElement("span",{className:"muted"},p.text),void 0!==a.speech.loading&&e.createElement("span",{className:"muted"},Math.round(100*a.speech.loading)," %"),e.createElement(l,{icon:"stop",small:!0,kind:"bare",title:"Stop",onClick:()=>t.stop()})),"playing"===p.mode&&!p.checking&&!h&&e.createElement("div",{className:"pde bar","data-theme":d},p.filming&&e.createElement("span",{className:"dot",title:"Filming: paused time is left out"}),e.createElement("span",{className:"ellipsis",style:{maxWidth:320}},p.title),!p.filming&&e.createElement(l,{icon:"back",small:!0,kind:"bare",title:"Back: this step again; pressed early, the one before (←, PageUp)",onClick:()=>t.back()}),p.filming?e.createElement("span",{className:"muted"},`${p.step+1} / ${p.steps}`):e.createElement(o,{title:"Go to a step (1-9, Home, End)",icon:"expand",label:e.createElement("span",{className:"muted"},p.catchingUp?`… ${p.step+1}`:`${p.step+1} / ${p.steps}`),align:"left",items:p.demo.steps.map((a,n)=>({label:e.createElement("span",{style:{fontWeight:n===p.step?700:400}},`${n+1}. ${a.title??(Object.values(a.say).find(Boolean)??"").slice(0,48)}`),onClick:()=>t.goTo(n)}))}),void 0!==a.speech.loading&&e.createElement("span",{className:"muted small",title:"Downloaded once, then kept by the browser: subtitles meanwhile"},"voice ",Math.round(100*a.speech.loading)," %"),a.hint&&e.createElement("span",{className:"small",style:{color:"var(--accent)"}},a.hint),p.paused&&!p.waiting&&!a.hint&&e.createElement("span",{className:"muted small",title:"What you do now, the demo goes on from"},"paused: the app is yours"),p.guided&&p.instruction&&e.createElement("span",{className:"ellipsis",style:{maxWidth:360,fontWeight:600}},p.instruction),p.guided&&p.instruction&&e.createElement(l,{icon:"flash",title:"The demo does it",onClick:()=>t.doItForMe()},"Do it for me"),e.createElement(l,{icon:p.paused?"play":"pause",kind:p.paused?"primary":void 0,title:"Space",onClick:()=>p.waiting?t.next():t.togglePause()},p.waiting?"Continue":p.paused?"Resume":"Pause"),!p.waiting&&e.createElement(l,{icon:"right",title:"Next step (→, PageDown)",onClick:()=>t.next()}),p.presenting&&e.createElement(l,{icon:"present",kind:"bare",title:"The presenter's screen, in a window of its own",onClick:()=>{t.openPresenter()}}),e.createElement(l,{icon:"stop",title:"Esc",onClick:()=>t.stop()},p.guided?"Exit":"Stop")),a.loop?.visitor&&e.createElement("div",{className:"pde bar","data-theme":d,style:{top:"auto",bottom:12,left:"auto",right:12,transform:"none",padding:"4px 6px 4px 12px",opacity:.85}},e.createElement(i,{name:"loop"}),e.createElement("span",{className:"small muted"},"The demo plays again after ",Math.round(t.getState().settings.loopIdle/1e3)," s without input"),e.createElement(l,{icon:"stop",small:!0,kind:"bare",title:"Stop the loop (Ctrl+Shift+L)",onClick:()=>t.stopLoop()})),"recording"===p.mode&&e.createElement(u,{engine:t,theme:d,filmed:p.filming}),a.message&&"idle"===p.mode&&e.createElement(g,{engine:t,theme:d,text:a.message.text,error:a.message.error}),a.studio&&!h&&e.createElement(c,{key:a.studio.opened,engine:t,theme:d}),t.options.launcher&&"idle"===p.mode&&!a.loop&&!a.studio&&e.createElement(e.Fragment,null,e.createElement("div",{className:"pde launcher","data-theme":d},e.createElement(l,{kind:a.library?"primary":void 0,onClick:()=>t.showLibrary(a.library?void 0:"demos")},e.createElement(i,{name:"demos"}),"Demos")),a.library&&e.createElement(r,{engine:t,theme:d,floating:!0})),a.dialog&&"idle"===p.mode&&e.createElement(m,{engine:t,request:a.dialog,theme:d}))}function u({engine:t,theme:a,filmed:i}){const{session:o}=n(t);return"recording"!==o.mode?null:i?e.createElement("div",{className:"pde bar","data-theme":a,style:{top:"auto",bottom:12,padding:"4px 6px 4px 10px"}},e.createElement("span",{className:"dot"}),e.createElement("span",{className:"small muted"},"Step ",o.step+1),e.createElement(l,{icon:"right",small:!0,kind:"bare",title:"Next step (Alt+N)",onClick:()=>t.nextStep()}),e.createElement(l,{icon:"stop",small:!0,kind:"bare",title:"Stop (Esc)",onClick:()=>{t.finishRecording()}})):e.createElement("div",{className:"pde bar","data-theme":a},e.createElement("span",{className:"dot"}),e.createElement("span",null,"Step ",o.step+1),e.createElement("span",{className:"muted small"},o.actions," action",1===o.actions?"":"s",o.microphone?" · 🎙 listening":""),!o.microphone&&e.createElement("input",{className:"field",style:{width:340},placeholder:"This step's narration (or leave it for later)",value:o.caption,onChange:e=>t.narrate(e.target.value)}),e.createElement(l,{icon:"right",title:"Alt+N",onClick:()=>t.nextStep()},"Next step"),e.createElement(l,{icon:"stop",kind:"primary",title:"Esc",onClick:()=>{t.finishRecording()}},"Stop"),e.createElement("span",{className:"small muted"},"Alt+H: hover here"))}function g({engine:a,theme:n,text:i,error:o}){return t(()=>{if(o)return;const e=setTimeout(()=>a.say(void 0),6e3);return()=>clearTimeout(e)},[i]),e.createElement("div",{className:"pde toast"+(o?" error":""),"data-theme":n,style:{bottom:a.getState().studio?"auto":24,top:a.getState().studio?70:"auto"}},e.createElement("span",{className:"grow"},i),e.createElement(l,{icon:"close",small:!0,kind:"bare",title:"Close",onClick:()=>a.say(void 0)}))}
package/ui/Flag.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ /** A language as its flag - the UK's for English - the page's as a globe, others as their code. */
3
+ export declare function Flag({ language }: {
4
+ language: string;
5
+ }): JSX.Element;
6
+ /** A language's own name for itself: "English", "Deutsch". */
7
+ export declare function languageName(language: string): string;
8
+ /** A flag and a name side by side. */
9
+ export declare function Flagged({ language, children }: {
10
+ language: string;
11
+ children?: React.ReactNode;
12
+ }): JSX.Element;
package/ui/Flag.js ADDED
@@ -0,0 +1 @@
1
+ import e from"react";import{Icon as t}from"./Kit.js";const a={width:18,height:12,flexShrink:0,display:"block",borderRadius:2,boxShadow:"0 0 0 1px rgba(128,128,128,.35)"},r=(t,r)=>e.createElement("svg",{viewBox:r?`0 0 ${t.length} 2`:`0 0 3 ${t.length}`,preserveAspectRatio:"none",style:a},t.map((t,a)=>r?e.createElement("rect",{key:a,x:a,width:"1",height:"2",fill:t}):e.createElement("rect",{key:a,y:a,width:"3",height:"1",fill:t}))),n={en:()=>e.createElement("svg",{viewBox:"0 0 60 30",preserveAspectRatio:"xMidYMid slice",style:a},e.createElement("rect",{width:"60",height:"30",fill:"#012169"}),e.createElement("path",{d:"M0,0 L60,30 M60,0 L0,30",stroke:"#fff",strokeWidth:"6"}),e.createElement("path",{d:"M0,0 L60,30 M60,0 L0,30",stroke:"#C8102E",strokeWidth:"2"}),e.createElement("path",{d:"M30,0 v30 M0,15 h60",stroke:"#fff",strokeWidth:"10"}),e.createElement("path",{d:"M30,0 v30 M0,15 h60",stroke:"#C8102E",strokeWidth:"6"})),de:()=>r(["#000","#DD0000","#FFCE00"],!1),nl:()=>r(["#AE1C28","#fff","#21468B"],!1),fr:()=>r(["#0055A4","#fff","#EF4135"],!0),it:()=>r(["#009246","#fff","#CE2B37"],!0),es:()=>r(["#AA151B","#F1BF00","#F1BF00","#AA151B"],!1)};export function Flag({language:a}){if("page"===a)return e.createElement(t,{name:"language"});const r=n[a.toLowerCase().split(/[-_]/)[0]];return r?r():e.createElement("span",{className:"badge",style:{fontSize:10,padding:"0 4px"}},a.toUpperCase())}export function languageName(e){try{const t=new Intl.DisplayNames([e],{type:"language"}).of(e);return t?t.charAt(0).toUpperCase()+t.slice(1):e}catch{return e}}export function Flagged({language:t,children:a}){return e.createElement("span",{className:"row",style:{gap:6,display:"inline-flex"}},e.createElement(Flag,{language:t}),a??languageName(t))}
package/ui/Kit.d.ts CHANGED
@@ -41,6 +41,13 @@ declare const PATHS: {
41
41
  readonly music: "M12 3v10.55c-.59-.34-1.27-.55-2-.55-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z";
42
42
  readonly back: "M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z";
43
43
  readonly present: "M21 3H3c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h5v2h8v-2h5c1.1 0 1.99-.9 1.99-2L23 5c0-1.1-.9-2-2-2zm0 14H3V5h18v12z";
44
+ readonly light: "M12 7a5 5 0 1 0 0 10 5 5 0 0 0 0-10zM2 13h2a1 1 0 0 0 0-2H2a1 1 0 0 0 0 2zm18 0h2a1 1 0 0 0 0-2h-2a1 1 0 0 0 0 2zM11 2v2a1 1 0 0 0 2 0V2a1 1 0 0 0-2 0zm0 18v2a1 1 0 0 0 2 0v-2a1 1 0 0 0-2 0zM5.99 4.58a1 1 0 0 0-1.41 1.41l1.06 1.06a1 1 0 0 0 1.41-1.41L5.99 4.58zm12.37 12.37a1 1 0 0 0-1.41 1.41l1.06 1.06a1 1 0 0 0 1.41-1.41l-1.06-1.06zm1.06-10.96a1 1 0 0 0-1.41-1.41l-1.06 1.06a1 1 0 0 0 1.41 1.41l1.06-1.06zM7.05 18.36a1 1 0 0 0-1.41-1.41l-1.06 1.06a1 1 0 0 0 1.41 1.41l1.06-1.06z";
45
+ readonly dark: "M12 3a9 9 0 1 0 9 9c0-.46-.04-.92-.1-1.36a5.39 5.39 0 0 1-4.4 2.26 5.4 5.4 0 0 1-3.14-9.8c-.44-.06-.9-.1-1.36-.1z";
46
+ readonly voice: "M9 13c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4zm6.08-7.95c.84 1.18.84 2.71 0 3.89l1.68 1.69c2.02-2.02 2.02-5.07 0-7.27l-1.68 1.69zM20.07 2l-1.63 1.63c2.77 3.02 2.77 7.56 0 10.74L20.07 16c3.9-3.89 3.91-9.95 0-14z";
47
+ readonly premium: "M7 18h2V6H7v12zm4 4h2V2h-2v20zm-8-8h2v-4H3v4zm12 4h2V6h-2v12zm4-8v4h2v-4h-2z";
48
+ readonly novoice: "M9 13c2.21 0 4-1.79 4-4 0-.55-.11-1.07-.31-1.55L7.45 12.69c.48.2 1 .31 1.55.31zM2.81 2.81 1.39 4.22l3.08 3.08A4 4 0 0 0 5 9c0 .74.2 1.43.55 2.02L1 19v2h14.17l4.61 4.61 1.41-1.41L2.81 2.81zM20.07 2l-1.63 1.63c2.77 3.02 2.77 7.56 0 10.74L20.07 16c3.9-3.89 3.91-9.95 0-14z";
49
+ readonly computer: "M20 18c1.1 0 1.99-.9 1.99-2L22 6c0-1.1-.9-2-2-2H4c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2H0v2h24v-2h-4zM4 6h16v10H4V6z";
50
+ readonly language: "M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zm6.93 6h-2.95a15.65 15.65 0 0 0-1.38-3.56A8.03 8.03 0 0 1 18.92 8zM12 4.04c.83 1.2 1.48 2.53 1.91 3.96h-3.82c.43-1.43 1.08-2.76 1.91-3.96zM4.26 14C4.1 13.36 4 12.69 4 12s.1-1.36.26-2h3.38c-.08.66-.14 1.32-.14 2s.06 1.34.14 2H4.26zm.82 2h2.95c.32 1.25.78 2.45 1.38 3.56A8 8 0 0 1 5.08 16zm2.95-8H5.08a8 8 0 0 1 4.33-3.56A15.65 15.65 0 0 0 8.03 8zM12 19.96c-.83-1.2-1.48-2.53-1.91-3.96h3.82c-.43 1.43-1.08 2.76-1.91 3.96zM14.34 14H9.66c-.09-.66-.16-1.32-.16-2s.07-1.35.16-2h4.68c.09.65.16 1.32.16 2s-.07 1.34-.16 2zm.25 5.56c.6-1.11 1.06-2.31 1.38-3.56h2.95a8.03 8.03 0 0 1-4.33 3.56zM16.36 14c.08-.66.14-1.32.14-2s-.06-1.34-.14-2h3.38c.16.64.26 1.31.26 2s-.1 1.36-.26 2h-3.38z";
44
51
  };
45
52
  export type IconName = keyof typeof PATHS;
46
53
  export declare function Icon({ name }: {
package/ui/Kit.js CHANGED
@@ -1 +1 @@
1
- import e,{useEffect as t,useRef as c,useState as n}from"react";const l={play:"M8 5v14l11-7z",pause:"M6 19h4V5H6v14zm8-14v14h4V5h-4z",stop:"M6 6h12v12H6z",record:"M12 4a8 8 0 1 0 0 16a8 8 0 0 0 0-16z",film:"M18 4l2 4h-3l-2-4h-2l2 4h-3l-2-4H8l2 4H7L5 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V4h-4z",mic:"M12 14c1.66 0 2.99-1.34 2.99-3L15 5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3zm5.3-3c0 3-2.54 5.1-5.3 5.1S6.7 14 6.7 11H5c0 3.41 2.72 6.23 6 6.72V21h2v-3.28c3.28-.48 6-3.3 6-6.72h-1.7z",save:"M17 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V7l-4-4zm-5 16c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm3-10H5V5h10v4z",close:"M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z",add:"M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z",delete:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z",up:"M4 12l1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8-8 8z",down:"M20 12l-1.41-1.41L13 16.17V4h-2v12.17l-5.58-5.59L4 12l8 8 8-8z",link:"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z",download:"M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z",upload:"M9 16h6v-6h4l-7-7-7 7h4zm-4 2h14v2H5z",share:"M18 16.08c-.76 0-1.44.3-1.96.77L8.91 12.7c.05-.23.09-.46.09-.7s-.04-.47-.09-.7l7.05-4.11c.54.5 1.25.81 2.04.81 1.66 0 3-1.34 3-3s-1.34-3-3-3-3 1.34-3 3c0 .24.04.47.09.7L8.04 9.81C7.5 9.31 6.79 9 6 9c-1.66 0-3 1.34-3 3s1.34 3 3 3c.79 0 1.5-.31 2.04-.81l7.12 4.16c-.05.21-.08.43-.08.65 0 1.61 1.31 2.92 2.92 2.92s2.92-1.31 2.92-2.92-1.31-2.92-2.92-2.92z",edit:"M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04a.996.996 0 0 0 0-1.41l-2.34-2.34a.996.996 0 0 0-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z",pick:"M12 8c-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4-1.79-4-4-4zm8.94 3A8.994 8.994 0 0 0 13 3.06V1h-2v2.06A8.994 8.994 0 0 0 3.06 11H1v2h2.06A8.994 8.994 0 0 0 11 20.94V23h2v-2.06A8.994 8.994 0 0 0 20.94 13H23v-2h-2.06zM12 19c-3.87 0-7-3.13-7-7s3.13-7 7-7 7 3.13 7 7-3.13 7-7 7z",show:"M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z",undo:"M12.5 8c-2.65 0-5.05.99-6.9 2.6L2 7v9h9l-3.62-3.62c1.39-1.16 3.16-1.88 5.12-1.88 3.54 0 6.55 2.31 7.6 5.5l2.37-.78C21.08 11.03 17.15 8 12.5 8z",redo:"M18.4 10.6C16.55 8.99 14.15 8 11.5 8c-4.65 0-8.58 3.03-9.96 7.22L3.9 16c1.05-3.19 4.05-5.5 7.6-5.5 1.95 0 3.73.72 5.12 1.88L13 16h9V7l-3.6 3.6z",copy:"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z",code:"M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4z",tune:"M3 17v2h6v-2H3zM3 5v2h10V5H3zm10 16v-2h8v-2h-8v-2h-2v6h2zM7 9v2H3v2h4v2h2V9H7zm14 4v-2H11v2h10zm-6-4h2V7h4V5h-4V3h-2v6z",more:"M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z",check:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z",listen:"M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z",first:"M6 6h2v12H6zm3.5 6l8.5 6V6z",demos:"M10 8v8l5-4-5-4zm9-5H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V5h14v14z",expand:"M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6z",right:"M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z",subtitles:"M20 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zM4 12h4v2H4v-2zm10 6H4v-2h10v2zm6 0h-4v-2h4v2zm0-4H10v-2h10v2z",minimize:"M6 19h12v2H6z",maximize:"M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z",duplicate:"M15 1H4c-1.1 0-2 .9-2 2v13h2V3h11V1zm-1 4l6 6v10c0 1.1-.9 2-2 2H7.99C6.89 23 6 22.1 6 21l.01-14c0-1.1.89-2 1.99-2h6zm-1 7h5.5L13 6.5V12z",flash:"M7 2v11h3v9l7-12h-4l4-8z",guide:"M5 13.18v4L12 21l7-3.82v-4L12 17l-7-3.82zM12 3L1 9l11 6 9-4.91V17h2V9L12 3z",loop:"M7 7h10v3l4-4-4-4v3H5v6h2V7zm10 10H7v-3l-4 4 4 4v-3h12v-6h-2v4z",music:"M12 3v10.55c-.59-.34-1.27-.55-2-.55-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z",back:"M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z",present:"M21 3H3c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h5v2h8v-2h5c1.1 0 1.99-.9 1.99-2L23 5c0-1.1-.9-2-2-2zm0 14H3V5h18v12z"};export function Icon({name:t}){return e.createElement("svg",{className:"i",viewBox:"0 0 24 24","aria-hidden":"true"},e.createElement("path",{d:l[t]}))}export function Button({icon:t,kind:c,on:n,small:l,className:a,children:h,...o}){const r=t&&!h,i=["btn",r&&"icon",c,n&&"on",l&&"small",a].filter(Boolean).join(" ");return e.createElement("button",{type:"button",className:i,"aria-label":r?o.title:void 0,...o},t&&e.createElement(Icon,{name:t}),h)}export function Labelled({label:t,children:c,className:n}){return e.createElement("label",{className:["labelled",n].filter(Boolean).join(" ")},e.createElement("span",null,t),c)}export function Check({label:t,checked:c,onChange:n,title:l}){return e.createElement("label",{className:"check",title:l},e.createElement("input",{type:"checkbox",checked:c,onChange:e=>n(e.target.checked)}),t)}export function Segmented({value:t,options:c,onChange:n}){return e.createElement("div",{className:"segmented"},c.map(([c,l,a])=>e.createElement("button",{key:c,type:"button",className:c===t?"on":"",title:a,onClick:()=>n(c)},l)))}export function NumberField({value:c,onChange:l,placeholder:a,title:h,width:o=80}){const[r,i]=n(void 0===c?"":String(c));return t(()=>{Number(r)===c||""===r&&void 0===c||i(void 0===c?"":String(c))},[c]),e.createElement("input",{className:"field",style:{width:o},inputMode:"numeric",placeholder:a,title:h,value:r,onChange:e=>{i(e.target.value);const t=e.target.value.trim();""===t?l(void 0):Number.isFinite(Number(t))&&l(Number(t))}})}export function JsonField({value:l,onChange:a,className:h,rows:o=1}){const r=JSON.stringify(l),[i,v]=n(r??""),[s,m]=n(!1),z=c(r);t(()=>{r!==z.current&&(z.current=r,v(r??""),m(!1))},[r]);const d=o>1?"textarea":"input";return e.createElement(d,{className:["field","mono",s&&"wrong",h].filter(Boolean).join(" "),rows:o>1?o:void 0,value:i,onChange:e=>{v(e.target.value);try{const t=""===e.target.value.trim()?void 0:JSON.parse(e.target.value);z.current=JSON.stringify(t),m(!1),a(t)}catch{m(!0)}}})}export function Menu({icon:l="more",label:a,title:h,items:o,align:r="right"}){const[i,v]=n(!1),s=c(null);return t(()=>{if(!i)return;const e=e=>{e.composedPath().includes(s.current)||v(!1)},t=s.current.getRootNode();return t.addEventListener("pointerdown",e,!0),()=>t.removeEventListener("pointerdown",e,!0)},[i]),e.createElement("span",{ref:s,style:{position:"relative",display:"inline-flex"}},e.createElement(Button,{icon:l,title:h,kind:a?void 0:"bare",on:i,onClick:()=>v(!i)},a),i&&e.createElement("div",{className:"menu",style:{top:"calc(100% + 4px)",[r]:0}},o.filter(Boolean).map((t,c)=>t&&"heading"in t?e.createElement("div",{key:c,className:"heading"},t.heading):t&&e.createElement("button",{key:c,type:"button",className:"item",disabled:t.disabled,onClick:()=>{v(!1),t.onClick()}},t.icon&&e.createElement(Icon,{name:t.icon}),t.label))))}export function useTheme(e="dark"){const c="function"==typeof matchMedia?matchMedia("(prefers-color-scheme: dark)"):void 0,[l,a]=n(c?.matches??!0);return t(()=>{if(!c)return;const e=()=>a(c.matches);return c.addEventListener("change",e),()=>c.removeEventListener("change",e)},[]),"auto"===e?l?"dark":"light":e}
1
+ import e,{useEffect as c,useRef as t,useState as l}from"react";const n={play:"M8 5v14l11-7z",pause:"M6 19h4V5H6v14zm8-14v14h4V5h-4z",stop:"M6 6h12v12H6z",record:"M12 4a8 8 0 1 0 0 16a8 8 0 0 0 0-16z",film:"M18 4l2 4h-3l-2-4h-2l2 4h-3l-2-4H8l2 4H7L5 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V4h-4z",mic:"M12 14c1.66 0 2.99-1.34 2.99-3L15 5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3zm5.3-3c0 3-2.54 5.1-5.3 5.1S6.7 14 6.7 11H5c0 3.41 2.72 6.23 6 6.72V21h2v-3.28c3.28-.48 6-3.3 6-6.72h-1.7z",save:"M17 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V7l-4-4zm-5 16c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm3-10H5V5h10v4z",close:"M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z",add:"M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z",delete:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z",up:"M4 12l1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8-8 8z",down:"M20 12l-1.41-1.41L13 16.17V4h-2v12.17l-5.58-5.59L4 12l8 8 8-8z",link:"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z",download:"M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z",upload:"M9 16h6v-6h4l-7-7-7 7h4zm-4 2h14v2H5z",share:"M18 16.08c-.76 0-1.44.3-1.96.77L8.91 12.7c.05-.23.09-.46.09-.7s-.04-.47-.09-.7l7.05-4.11c.54.5 1.25.81 2.04.81 1.66 0 3-1.34 3-3s-1.34-3-3-3-3 1.34-3 3c0 .24.04.47.09.7L8.04 9.81C7.5 9.31 6.79 9 6 9c-1.66 0-3 1.34-3 3s1.34 3 3 3c.79 0 1.5-.31 2.04-.81l7.12 4.16c-.05.21-.08.43-.08.65 0 1.61 1.31 2.92 2.92 2.92s2.92-1.31 2.92-2.92-1.31-2.92-2.92-2.92z",edit:"M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04a.996.996 0 0 0 0-1.41l-2.34-2.34a.996.996 0 0 0-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z",pick:"M12 8c-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4-1.79-4-4-4zm8.94 3A8.994 8.994 0 0 0 13 3.06V1h-2v2.06A8.994 8.994 0 0 0 3.06 11H1v2h2.06A8.994 8.994 0 0 0 11 20.94V23h2v-2.06A8.994 8.994 0 0 0 20.94 13H23v-2h-2.06zM12 19c-3.87 0-7-3.13-7-7s3.13-7 7-7 7 3.13 7 7-3.13 7-7 7z",show:"M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z",undo:"M12.5 8c-2.65 0-5.05.99-6.9 2.6L2 7v9h9l-3.62-3.62c1.39-1.16 3.16-1.88 5.12-1.88 3.54 0 6.55 2.31 7.6 5.5l2.37-.78C21.08 11.03 17.15 8 12.5 8z",redo:"M18.4 10.6C16.55 8.99 14.15 8 11.5 8c-4.65 0-8.58 3.03-9.96 7.22L3.9 16c1.05-3.19 4.05-5.5 7.6-5.5 1.95 0 3.73.72 5.12 1.88L13 16h9V7l-3.6 3.6z",copy:"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z",code:"M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4z",tune:"M3 17v2h6v-2H3zM3 5v2h10V5H3zm10 16v-2h8v-2h-8v-2h-2v6h2zM7 9v2H3v2h4v2h2V9H7zm14 4v-2H11v2h10zm-6-4h2V7h4V5h-4V3h-2v6z",more:"M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z",check:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z",listen:"M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z",first:"M6 6h2v12H6zm3.5 6l8.5 6V6z",demos:"M10 8v8l5-4-5-4zm9-5H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V5h14v14z",expand:"M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6z",right:"M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z",subtitles:"M20 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zM4 12h4v2H4v-2zm10 6H4v-2h10v2zm6 0h-4v-2h4v2zm0-4H10v-2h10v2z",minimize:"M6 19h12v2H6z",maximize:"M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z",duplicate:"M15 1H4c-1.1 0-2 .9-2 2v13h2V3h11V1zm-1 4l6 6v10c0 1.1-.9 2-2 2H7.99C6.89 23 6 22.1 6 21l.01-14c0-1.1.89-2 1.99-2h6zm-1 7h5.5L13 6.5V12z",flash:"M7 2v11h3v9l7-12h-4l4-8z",guide:"M5 13.18v4L12 21l7-3.82v-4L12 17l-7-3.82zM12 3L1 9l11 6 9-4.91V17h2V9L12 3z",loop:"M7 7h10v3l4-4-4-4v3H5v6h2V7zm10 10H7v-3l-4 4 4 4v-3h12v-6h-2v4z",music:"M12 3v10.55c-.59-.34-1.27-.55-2-.55-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z",back:"M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z",present:"M21 3H3c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h5v2h8v-2h5c1.1 0 1.99-.9 1.99-2L23 5c0-1.1-.9-2-2-2zm0 14H3V5h18v12z",light:"M12 7a5 5 0 1 0 0 10 5 5 0 0 0 0-10zM2 13h2a1 1 0 0 0 0-2H2a1 1 0 0 0 0 2zm18 0h2a1 1 0 0 0 0-2h-2a1 1 0 0 0 0 2zM11 2v2a1 1 0 0 0 2 0V2a1 1 0 0 0-2 0zm0 18v2a1 1 0 0 0 2 0v-2a1 1 0 0 0-2 0zM5.99 4.58a1 1 0 0 0-1.41 1.41l1.06 1.06a1 1 0 0 0 1.41-1.41L5.99 4.58zm12.37 12.37a1 1 0 0 0-1.41 1.41l1.06 1.06a1 1 0 0 0 1.41-1.41l-1.06-1.06zm1.06-10.96a1 1 0 0 0-1.41-1.41l-1.06 1.06a1 1 0 0 0 1.41 1.41l1.06-1.06zM7.05 18.36a1 1 0 0 0-1.41-1.41l-1.06 1.06a1 1 0 0 0 1.41 1.41l1.06-1.06z",dark:"M12 3a9 9 0 1 0 9 9c0-.46-.04-.92-.1-1.36a5.39 5.39 0 0 1-4.4 2.26 5.4 5.4 0 0 1-3.14-9.8c-.44-.06-.9-.1-1.36-.1z",voice:"M9 13c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4zm6.08-7.95c.84 1.18.84 2.71 0 3.89l1.68 1.69c2.02-2.02 2.02-5.07 0-7.27l-1.68 1.69zM20.07 2l-1.63 1.63c2.77 3.02 2.77 7.56 0 10.74L20.07 16c3.9-3.89 3.91-9.95 0-14z",premium:"M7 18h2V6H7v12zm4 4h2V2h-2v20zm-8-8h2v-4H3v4zm12 4h2V6h-2v12zm4-8v4h2v-4h-2z",novoice:"M9 13c2.21 0 4-1.79 4-4 0-.55-.11-1.07-.31-1.55L7.45 12.69c.48.2 1 .31 1.55.31zM2.81 2.81 1.39 4.22l3.08 3.08A4 4 0 0 0 5 9c0 .74.2 1.43.55 2.02L1 19v2h14.17l4.61 4.61 1.41-1.41L2.81 2.81zM20.07 2l-1.63 1.63c2.77 3.02 2.77 7.56 0 10.74L20.07 16c3.9-3.89 3.91-9.95 0-14z",computer:"M20 18c1.1 0 1.99-.9 1.99-2L22 6c0-1.1-.9-2-2-2H4c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2H0v2h24v-2h-4zM4 6h16v10H4V6z",language:"M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zm6.93 6h-2.95a15.65 15.65 0 0 0-1.38-3.56A8.03 8.03 0 0 1 18.92 8zM12 4.04c.83 1.2 1.48 2.53 1.91 3.96h-3.82c.43-1.43 1.08-2.76 1.91-3.96zM4.26 14C4.1 13.36 4 12.69 4 12s.1-1.36.26-2h3.38c-.08.66-.14 1.32-.14 2s.06 1.34.14 2H4.26zm.82 2h2.95c.32 1.25.78 2.45 1.38 3.56A8 8 0 0 1 5.08 16zm2.95-8H5.08a8 8 0 0 1 4.33-3.56A15.65 15.65 0 0 0 8.03 8zM12 19.96c-.83-1.2-1.48-2.53-1.91-3.96h3.82c-.43 1.43-1.08 2.76-1.91 3.96zM14.34 14H9.66c-.09-.66-.16-1.32-.16-2s.07-1.35.16-2h4.68c.09.65.16 1.32.16 2s-.07 1.34-.16 2zm.25 5.56c.6-1.11 1.06-2.31 1.38-3.56h2.95a8.03 8.03 0 0 1-4.33 3.56zM16.36 14c.08-.66.14-1.32.14-2s-.06-1.34-.14-2h3.38c.16.64.26 1.31.26 2s-.1 1.36-.26 2h-3.38z"};export function Icon({name:c}){return e.createElement("svg",{className:"i",viewBox:"0 0 24 24","aria-hidden":"true"},e.createElement("path",{d:n[c]}))}export function Button({icon:c,kind:t,on:l,small:n,className:a,children:h,...v}){const o=c&&!h,r=["btn",o&&"icon",t,l&&"on",n&&"small",a].filter(Boolean).join(" ");return e.createElement("button",{type:"button",className:r,"aria-label":o?v.title:void 0,...v},c&&e.createElement(Icon,{name:c}),h)}export function Labelled({label:c,children:t,className:l}){return e.createElement("label",{className:["labelled",l].filter(Boolean).join(" ")},e.createElement("span",null,c),t)}export function Check({label:c,checked:t,onChange:l,title:n}){return e.createElement("label",{className:"check",title:n},e.createElement("input",{type:"checkbox",checked:t,onChange:e=>l(e.target.checked)}),c)}export function Segmented({value:c,options:t,onChange:l}){return e.createElement("div",{className:"segmented"},t.map(([t,n,a])=>e.createElement("button",{key:t,type:"button",className:t===c?"on":"",title:a,onClick:()=>l(t)},n)))}export function NumberField({value:t,onChange:n,placeholder:a,title:h,width:v=80}){const[o,r]=l(void 0===t?"":String(t));return c(()=>{Number(o)===t||""===o&&void 0===t||r(void 0===t?"":String(t))},[t]),e.createElement("input",{className:"field",style:{width:v},inputMode:"numeric",placeholder:a,title:h,value:o,onChange:e=>{r(e.target.value);const c=e.target.value.trim();""===c?n(void 0):Number.isFinite(Number(c))&&n(Number(c))}})}export function JsonField({value:n,onChange:a,className:h,rows:v=1}){const o=JSON.stringify(n),[r,i]=l(o??""),[m,z]=l(!1),s=t(o);c(()=>{o!==s.current&&(s.current=o,i(o??""),z(!1))},[o]);const M=v>1?"textarea":"input";return e.createElement(M,{className:["field","mono",m&&"wrong",h].filter(Boolean).join(" "),rows:v>1?v:void 0,value:r,onChange:e=>{i(e.target.value);try{const c=""===e.target.value.trim()?void 0:JSON.parse(e.target.value);s.current=JSON.stringify(c),z(!1),a(c)}catch{z(!0)}}})}export function Menu({icon:n="more",label:a,title:h,items:v,align:o="right"}){const[r,i]=l(!1),m=t(null);return c(()=>{if(!r)return;const e=e=>{e.composedPath().includes(m.current)||i(!1)},c=m.current.getRootNode();return c.addEventListener("pointerdown",e,!0),()=>c.removeEventListener("pointerdown",e,!0)},[r]),e.createElement("span",{ref:m,style:{position:"relative",display:"inline-flex"}},e.createElement(Button,{icon:n,title:h,kind:a?void 0:"bare",on:r,onClick:()=>i(!r)},a),r&&e.createElement("div",{className:"menu",style:{top:"calc(100% + 4px)",[o]:0}},v.filter(Boolean).map((c,t)=>c&&"heading"in c?e.createElement("div",{key:t,className:"heading"},c.heading):c&&e.createElement("button",{key:t,type:"button",className:"item",disabled:c.disabled,onClick:()=>{i(!1),c.onClick()}},c.icon&&e.createElement(Icon,{name:c.icon}),c.label))))}export function useTheme(e="dark"){const t="function"==typeof matchMedia?matchMedia("(prefers-color-scheme: dark)"):void 0,[n,a]=l(t?.matches??!0);return c(()=>{if(!t)return;const e=()=>a(t.matches);return t.addEventListener("change",e),()=>t.removeEventListener("change",e)},[]),"auto"===e?n?"dark":"light":e}
package/ui/Library.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { ReactNode } from 'react';
2
2
  import type { DemoEngine } from '../engine/DemoEngine';
3
3
  /**
4
- * Every demo - play, film, edit, share - and how they play and record here: voices, languages,
5
- * subtitles. For the app's own panel (a Development tab); in its own shadow root, so the app's
4
+ * Every demo - play, present, guide, film, edit, share - and, behind its settings button, how they
5
+ * sound here. For the app's own panel (a Development tab); in its own shadow root, so the app's
6
6
  * styles stay out.
7
7
  */
8
8
  export declare function DemoLibrary({ engine, theme }: {
@@ -18,15 +18,7 @@ export declare function Library({ engine, theme, floating }: {
18
18
  theme: 'light' | 'dark';
19
19
  floating?: boolean;
20
20
  }): JSX.Element;
21
- /** For videos, pitches and booths: the music bed, the video's size and quality, the loop's patience. */
22
- export declare function Production({ engine }: {
23
- engine: DemoEngine;
24
- }): JSX.Element;
25
- /** How narration sounds: the voice, the language, subtitles. */
26
- export declare function Narration({ engine }: {
27
- engine: DemoEngine;
28
- }): JSX.Element;
29
- /** How recording goes: microphone, filming, transcribing. */
30
- export declare function Recording({ engine }: {
21
+ /** How demos sound and show here: the voice, the language, subtitles. The rest is asked as it starts. */
22
+ export declare function Settings({ engine }: {
31
23
  engine: DemoEngine;
32
24
  }): JSX.Element;
package/ui/Library.js CHANGED
@@ -1 +1 @@
1
- import e,{useEffect as t,useLayoutEffect as a,useRef as n,useState as l}from"react";import{createPortal as o}from"react-dom";import{clock as i}from"../model/Timing.js";import{elevenLabsVoices as s,KOKORO_VOICES as r,piperVoices as c}from"../speech/Speech.js";import{MUSIC_TRACKS as m}from"../speech/Music.js";import{videoSize as d}from"../video/Film.js";import{pickFile as p}from"../store/Share.js";import{useDemos as h,useEngine as g}from"./Hooks.js";import{Button as u,Check as E,Icon as v,Labelled as b,Menu as f,Segmented as w,useTheme as y}from"./Kit.js";import{UI_CSS as k}from"./Styles.js";const N=[["free","Free","Neural voices in the browser, no key: Kokoro for English, Piper for ~40 languages. Downloaded once (80-330 MB), then kept."],["elevenlabs","ElevenLabs","Premium voices with your own key. Each sentence is paid for once, then kept in this browser."],["system","System","The browser's own voices: instant, but videos don't hear them."],["off","Off","Subtitles only, timed to reading."]];export function DemoLibrary({engine:t,theme:a}){const n=y(a??t.options.theme??"auto");return e.createElement(Shadow,null,e.createElement(Library,{engine:t,theme:n}))}export function Shadow({children:t}){const i=n(null),[s,r]=l();return a(()=>{const e=i.current,t=e.shadowRoot??e.attachShadow({mode:"open"});if(!t.querySelector("style[data-pde]")){const a=e.ownerDocument.createElement("style");a.setAttribute("data-pde",""),a.textContent=k,t.append(a)}r(t)},[]),e.createElement("div",{ref:i,"data-demo-ignore":!0,style:{display:"contents"}},s&&o(t,s))}export function Library({engine:t,theme:a,floating:n}){const l=g(t),o=h(t),i="idle"!==l.session.mode,s=async e=>{const{demo:a,problems:n}=t.parse(e);if(!a)return t.say(`Not a demo: ${n.slice(0,3).map(e=>`${e.path||"demo"} ${e.message}`).join("; ")}`,!0);await t.save(a),t.openStudio(a)};return e.createElement("div",{className:"pde library"+(n?" floating":""),"data-theme":a,"data-demo-ignore":!0},l.message&&e.createElement("div",{className:"small "+(l.message.error?"error":"muted")},l.message.text),e.createElement("section",{className:"section"},e.createElement("h3",null,"Demos"),0===o.length&&e.createElement("div",{className:"small muted"},"None yet: record one, or ask an AI to make one (demoEngine.help())."),o.map(a=>e.createElement(S,{key:a.demo.id,engine:t,entry:a,busy:i})),e.createElement("div",{className:"row",style:{flexWrap:"wrap"}},l.loop?e.createElement(u,{icon:"stop",onClick:()=>t.stopLoop()},"Stop the loop"):e.createElement(u,{icon:"loop",disabled:i||0===o.length,title:"Every demo, one after the other, again and again: an expo booth",onClick:()=>{t.loop(o.map(e=>e.demo))}},"Loop all"),e.createElement(u,{icon:"record",disabled:i,onClick:()=>{t.record()},style:{color:"var(--danger)"}},"Record"),e.createElement(u,{icon:"add",disabled:i,onClick:()=>t.openStudio(t.create())},"New"),e.createElement(u,{icon:"upload",onClick:()=>{p().then(e=>e?.text()).then(e=>{if(e)return s(e)})}},"Import"),e.createElement(u,{icon:"copy",title:"Paste a demo’s JSON",onClick:()=>{navigator.clipboard.readText().then(s,()=>t.say("Could not read the clipboard",!0))}},"Paste"))),e.createElement(Narration,{engine:t}),e.createElement(Production,{engine:t}),e.createElement(Recording,{engine:t}))}export function Production({engine:t}){const{settings:a}=g(t),{music:n,film:o}=a,[i,s]=l(),r=n.on?n.track:"none",c=o.lines?d(o.lines,o.aspect):void 0,h={width:Math.round(innerWidth*devicePixelRatio),height:Math.round(innerHeight*devicePixelRatio)};return e.createElement("section",{className:"section"},e.createElement("h3",null,"Production"),e.createElement("div",{className:"row",style:{flexWrap:"wrap",gap:10,alignItems:"flex-end"}},e.createElement(b,{label:"Music"},e.createElement("select",{className:"field",value:r,onChange:e=>(e=>{if(i?.(),s(void 0),"none"===e)return t.changeSettings({music:{...n,on:!1}});"pick"!==e?t.changeSettings({music:{...n,on:!0,track:e}}):p("audio/*").then(e=>e&&t.setMusic(e))})(e.target.value)},e.createElement("option",{value:"none"},"None"),m.map(t=>e.createElement("option",{key:t.id,value:t.id,title:t.hint},t.name)),n.name&&e.createElement("option",{value:"file"},n.name),e.createElement("option",{value:"pick"},"Your own file…"))),e.createElement(u,{small:!0,icon:i?"stop":"listen",disabled:!n.on,onClick:()=>{(async()=>{if(i)return i(),s(void 0);const e=await t.listenToMusic(20);s(()=>e),setTimeout(()=>s(void 0),2e4)})()}},i?"Stop":"Listen"),e.createElement(b,{label:`Volume ${Math.round(100*n.volume)} %`},e.createElement("input",{type:"range",min:.02,max:.6,step:.01,value:n.volume,disabled:!n.on,onChange:e=>{t.changeSettings({music:{...n,volume:Number(e.target.value)}}),t.speech.setMusicVolume(Number(e.target.value))}}))),e.createElement("div",{className:"small muted"},n.on&&"file"!==n.track?`${m.find(e=>e.id===n.track)?.hint}. Composed by the engine: free to use anywhere. `:"","Under the narration, quieter while it speaks; in videos too."),e.createElement("div",{className:"row",style:{flexWrap:"wrap",gap:10}},e.createElement(b,{label:"Video size"},e.createElement("select",{className:"field",value:o.lines,onChange:e=>t.changeSettings({film:{...o,lines:Number(e.target.value)}})},e.createElement("option",{value:0},"The tab's own (",h.width,"×",h.height,")"),[720,1080,1440,2160].map(t=>{const{width:a,height:n}=d(t,o.aspect);return e.createElement("option",{key:t,value:t},2160===t?"4K":`${t}p`," (",a,"×",n,")")}))),o.lines>0&&e.createElement(e.Fragment,null,e.createElement(b,{label:"Shape"},e.createElement("select",{className:"field",value:o.aspect,onChange:e=>t.changeSettings({film:{...o,aspect:e.target.value}})},e.createElement("option",{value:"16:9"},"16:9 landscape"),e.createElement("option",{value:"9:16"},"9:16 portrait"),e.createElement("option",{value:"1:1"},"1:1 square"))),e.createElement(b,{label:"The tab"},e.createElement("select",{className:"field",value:o.fit,onChange:e=>t.changeSettings({film:{...o,fit:e.target.value}})},e.createElement("option",{value:"fit"},"Whole, with bars"),e.createElement("option",{value:"fill"},"Filling it, edges cut")))),e.createElement(b,{label:"Frames"},e.createElement("select",{className:"field",value:o.frameRate,onChange:e=>t.changeSettings({film:{...o,frameRate:Number(e.target.value)}})},e.createElement("option",{value:30},"30 a second"),e.createElement("option",{value:60},"60 a second"))),e.createElement(b,{label:"Quality"},e.createElement("select",{className:"field",value:o.bitrate,onChange:e=>t.changeSettings({film:{...o,bitrate:Number(e.target.value)}})},e.createElement("option",{value:4},"Small (4 Mb/s)"),e.createElement("option",{value:8},"Good (8 Mb/s)"),e.createElement("option",{value:16},"High (16 Mb/s)"),e.createElement("option",{value:25},"Master (25 Mb/s)")))),c&&(c.width>1.05*h.width||c.height>1.05*h.height)&&e.createElement("div",{className:"small muted"},"The tab is ",h.width,"×",h.height,": a ",c.width,"×",c.height," video scales it up, a little soft. A bigger window, or a screen with more pixels, keeps it sharp."),e.createElement("div",{className:"row",style:{flexWrap:"wrap",gap:10}},e.createElement(b,{label:"Loop: plays again after"},e.createElement("select",{className:"field",value:a.loopIdle,onChange:e=>t.changeSettings({loopIdle:Number(e.target.value)})},[10,20,30,60,120].map(t=>e.createElement("option",{key:t,value:1e3*t},t," s idle"))))))}function S({engine:t,entry:a,busy:n}){const{demo:l,origin:o,video:s}=a,r=i(t.timing(l).duration);return e.createElement("div",{className:"demo"},e.createElement("div",{className:"row"},e.createElement("span",{className:"title grow ellipsis",title:l.description},l.title),"app"!==o&&e.createElement("span",{className:"badge"},"edited"===o?"edited here":"made here"),s&&e.createElement("span",{className:"badge accent",title:`Filmed ${new Date(s.at).toLocaleString()}`},"video")),l.description&&e.createElement("div",{className:"small muted"},l.description),e.createElement("div",{className:"row"},e.createElement("span",{className:"small muted grow"},l.steps.length," steps · ~",r," · ",t.languagesOf(l).join(", ")||"no narration"),e.createElement(u,{icon:"play",small:!0,kind:"primary",title:"Play",disabled:n,onClick:()=>{t.play(l)}}),e.createElement(u,{icon:"film",small:!0,title:"Film: a video with narration and subtitles",disabled:n,onClick:()=>{t.film(l)}}),e.createElement(u,{icon:"edit",small:!0,title:"Open in the studio",onClick:()=>t.openStudio(l)}),e.createElement(f,{title:"More",items:[{heading:"Play"},{label:"Present: waits after each step, the presenter's screen beside it",icon:"present",disabled:n,onClick:()=>{t.present(l)}},{label:"Guide: the viewer does it",icon:"guide",disabled:n,onClick:()=>{t.guide(l)}},{label:"Loop it: an expo booth",icon:"loop",disabled:n,onClick:()=>{t.loop([l])}},{heading:"Share"},{label:"Copy a link with the demo",icon:"link",onClick:()=>{t.link(l).then(e=>navigator.clipboard.writeText(e)).then(()=>t.say("Link copied."))}},{label:"Download .demo.json",icon:"download",onClick:()=>t.downloadDemo(l)},{label:"Download scenario .md",icon:"download",onClick:()=>t.downloadDemo({...l,scenario:a.scenario},"md")},{label:"Narration pack (.zip)",icon:"listen",onClick:()=>{t.downloadPack(l)}},s&&{heading:"Video"},s&&{label:"Download the video",icon:"film",onClick:()=>t.downloadVideo(s,l.title)},s&&{label:"Subtitles .vtt",icon:"subtitles",onClick:()=>t.downloadVideo(s,l.title,"vtt")},s&&{label:"Subtitles .srt",icon:"subtitles",onClick:()=>t.downloadVideo(s,l.title,"srt")},s&&{label:"Share…",icon:"share",onClick:()=>{t.shareVideo(s,l.title).then(e=>!e&&t.say("No share sheet here: download it instead."))}},{heading:"Demo"},{label:"Clone",icon:"duplicate",onClick:()=>t.openStudio({...t.create(`${l.title} (copy)`),...JSON.parse(JSON.stringify(l)),id:t.create(l.title).id,title:`${l.title} (copy)`})},"edited"===o&&{label:"Revert to the app’s version",icon:"undo",onClick:()=>window.confirm("Drop the changes kept here?")&&void t.remove(l.id)},"here"===o&&{label:"Delete",icon:"delete",onClick:()=>window.confirm(`Delete "${l.title}"?`)&&void t.remove(l.id)}]})))}export function Narration({engine:t}){const{settings:a,speech:n}=g(t),l=a.speech.voice,o=t.language(),i=e=>t.changeSettings({speech:{...a.speech,...e}});return e.createElement("section",{className:"section"},e.createElement("h3",null,"Narration"),e.createElement(w,{value:l,onChange:e=>i({voice:e}),options:N.map(([e,t,a])=>[e,t,a])}),e.createElement("div",{className:"small muted"},N.find(([e])=>e===l)?.[2]),"free"===l&&e.createElement(C,{engine:t}),"elevenlabs"===l&&e.createElement(x,{engine:t}),"system"===l&&e.createElement(P,{engine:t,language:o}),e.createElement("div",{className:"row",style:{flexWrap:"wrap",gap:12}},e.createElement(b,{label:"Language"},e.createElement("select",{className:"field",value:a.language,onChange:e=>t.changeSettings({language:e.target.value})},e.createElement("option",{value:"page"},"The page's (",t.options.language?.()??o,")"),t.languages().map(t=>e.createElement("option",{key:t,value:t},t)))),e.createElement(b,{label:`Speed ${a.speech.rate.toFixed(2)}×`},e.createElement("input",{type:"range",min:.7,max:1.4,step:.05,value:a.speech.rate,onChange:e=>i({rate:Number(e.target.value)})}))),e.createElement("div",{className:"row",style:{flexWrap:"wrap",gap:12}},e.createElement(E,{label:"Subtitles",checked:a.subtitles,onChange:e=>t.changeSettings({subtitles:e})}),e.createElement(E,{label:"Wait for the presenter after each step",checked:a.waitForPresenter,onChange:e=>t.changeSettings({waitForPresenter:e})}),e.createElement(E,{label:"From a step: catch up first",title:"Earlier steps' actions quickly, so the app is where the step expects it",checked:a.catchUp,onChange:e=>t.changeSettings({catchUp:e})}),e.createElement(E,{label:"The demo's narration pack, where it has one",title:"Its audio made once and checked in: no key, no download; what changed since, the voice says",checked:a.usePacks,onChange:e=>t.changeSettings({usePacks:e})})),e.createElement("div",{className:"small muted"},"Playing: Space pauses, → or PageDown goes on, ← or PageUp goes back, 1-9, Home and End go to a step, Esc stops: a presenter's clicker works."),void 0!==n.loading&&e.createElement("div",{className:"col",style:{gap:2}},e.createElement("span",{className:"small muted"},"Downloading a model: ",Math.round(100*n.loading)," %"),e.createElement("div",{className:"progress"},e.createElement("div",{style:{width:100*n.loading+"%"}}))),n.error&&e.createElement("div",{className:"small error"},"Voice: ",n.error))}function C({engine:a}){const{settings:n}=g(a),[o,i]=l([]);return t(()=>{c().then(i,()=>i([]))},[]),e.createElement("div",{className:"col"},a.languages().map(t=>{const l=a.speech.freeVoice(t)??"",i=t.split(/[-_]/)[0],s=o.filter(e=>e.language.split("_")[0]===i);return e.createElement(b,{key:t,label:`Voice for ${t}`},e.createElement("select",{className:"field",value:l,onChange:e=>a.changeSettings({speech:{...n.speech,free:{...n.speech.free,[t]:e.target.value}}})},!l&&e.createElement("option",{value:""},"None: choose one"),"en"===i&&e.createElement("optgroup",{label:"Kokoro"},r.map(t=>e.createElement("option",{key:t.id,value:`kokoro:${t.id}`},t.name))),e.createElement("optgroup",{label:"Piper"},l.startsWith("piper:")&&!s.some(e=>`piper:${e.id}`===l)&&e.createElement("option",{value:l},l.slice(6)),s.map(t=>e.createElement("option",{key:t.id,value:`piper:${t.id}`},t.name)))))}))}function x({engine:a}){const{settings:n}=g(a),{key:o,voice:i}=n.speech.elevenlabs,[r,c]=l([]),m=e=>a.changeSettings({speech:{...n.speech,elevenlabs:{...n.speech.elevenlabs,...e}}});return t(()=>{o&&s(o).then(c,()=>c([]))},[o]),e.createElement("div",{className:"row"},e.createElement(b,{label:"API key, kept in this browser",className:"grow"},e.createElement("input",{className:"field",type:"password",autoComplete:"off",value:o,onChange:e=>m({key:e.target.value.trim()})})),r.length>0&&e.createElement(b,{label:"Voice",className:"grow"},e.createElement("select",{className:"field",value:r.some(e=>e.id===i)?i:"",onChange:e=>m({voice:e.target.value})},r.map(t=>e.createElement("option",{key:t.id,value:t.id},t.name)))))}function P({engine:a,language:n}){const{settings:o}=g(a),[i,s]=l(()=>speechSynthesis.getVoices());t(()=>{const e=()=>s(speechSynthesis.getVoices());return speechSynthesis.addEventListener("voiceschanged",e),()=>speechSynthesis.removeEventListener("voiceschanged",e)},[]);const r=i.filter(e=>e.lang.toLowerCase().startsWith(n.toLowerCase().split("-")[0]));return e.createElement(b,{label:`Voice for ${n}`},e.createElement("select",{className:"field",value:o.speech.system[n]??"",onChange:e=>a.changeSettings({speech:{...o.speech,system:{...o.speech.system,[n]:e.target.value}}})},e.createElement("option",{value:""},"The default"),r.map(t=>e.createElement("option",{key:t.name,value:t.name},t.name))))}export function Recording({engine:t}){const{settings:a}=g(t);return e.createElement("section",{className:"section"},e.createElement("h3",null,"Recording"),e.createElement("div",{className:"row",style:{flexWrap:"wrap",gap:12}},e.createElement(E,{label:e.createElement(e.Fragment,null,e.createElement(v,{name:"mic"})," Microphone: what I say becomes the narration"),checked:a.microphone,onChange:e=>t.changeSettings({microphone:e})}),e.createElement(E,{label:e.createElement(e.Fragment,null,e.createElement(v,{name:"film"})," Film it too"),checked:a.filmRecording,onChange:e=>t.changeSettings({filmRecording:e})})),a.microphone&&e.createElement("div",{className:"row",style:{flexWrap:"wrap"}},e.createElement(b,{label:"Speech to text"},e.createElement("select",{className:"field",value:a.transcriber,onChange:e=>t.changeSettings({transcriber:e.target.value})},e.createElement("option",{value:"whisper"},"Whisper, in the browser (private, free)"),e.createElement("option",{value:"elevenlabs"},"ElevenLabs Scribe (your key)"))),"whisper"===a.transcriber&&e.createElement(b,{label:"Model"},e.createElement("select",{className:"field",value:a.whisperModel,onChange:e=>t.changeSettings({whisperModel:e.target.value})},e.createElement("option",{value:"tiny"},"tiny: quick"),e.createElement("option",{value:"base"},"base"),e.createElement("option",{value:"small"},"small: best")))),e.createElement("div",{className:"small muted"},"Recording: Alt+N starts the next step, Alt+H records a hover where the pointer is, Esc stops."))}
1
+ import e,{useEffect as t,useLayoutEffect as a,useRef as n,useState as o}from"react";import{createPortal as l}from"react-dom";import{clock as i}from"../model/Timing.js";import{elevenLabsVoices as s,KOKORO_VOICES as r,piperVoices as c}from"../speech/Speech.js";import{pickFile as m}from"../store/Share.js";import{useDemos as d,useEngine as p}from"./Hooks.js";import{Button as g,Check as h,Icon as u,Labelled as E,Menu as b,Segmented as k,useTheme as v}from"./Kit.js";import{Flagged as y}from"./Flag.js";import{VideoLook as w}from"./Dialogs.js";import{UI_CSS as f}from"./Styles.js";const N=[["free","Free","Neural voices in the browser, no key: Kokoro for English, Piper for ~40 languages. Downloaded once (80-330 MB), then kept."],["elevenlabs","ElevenLabs","Premium voices with your own key. Each sentence is paid for once, then kept in this browser."],["system","System","The browser's own voices: instant, but videos don't hear them."],["off","Off","Subtitles only, timed to reading."]];export function DemoLibrary({engine:t,theme:a}){const n=v(a??t.options.theme??"auto");return e.createElement(Shadow,null,e.createElement(Library,{engine:t,theme:n}))}export function Shadow({children:t}){const i=n(null),[s,r]=o();return a(()=>{const e=i.current,t=e.shadowRoot??e.attachShadow({mode:"open"});if(!t.querySelector("style[data-pde]")){const a=e.ownerDocument.createElement("style");a.setAttribute("data-pde",""),a.textContent=f,t.append(a)}r(t)},[]),e.createElement("div",{ref:i,"data-demo-ignore":!0,style:{display:"contents"}},s&&l(t,s))}export function Library({engine:t,theme:a,floating:n}){const o=p(t),l=d(t),i="idle"!==o.session.mode,s=o.library??"demos",r=async e=>{const{demo:a,problems:n}=t.parse(e);if(!a)return t.say(`Not a demo: ${n.slice(0,3).map(e=>`${e.path||"demo"} ${e.message}`).join("; ")}`,!0);await t.save(a),t.openStudio(a)};return"settings"===s?e.createElement("div",{className:"pde library"+(n?" floating":""),"data-theme":a,"data-demo-ignore":!0},e.createElement("div",{className:"row"},e.createElement(g,{icon:"back",kind:"bare",title:"Back to the demos",onClick:()=>t.showLibrary(n?"demos":void 0)}),e.createElement("h2",{className:"grow"},"Settings")),e.createElement(Settings,{engine:t})):e.createElement("div",{className:"pde library"+(n?" floating":""),"data-theme":a,"data-demo-ignore":!0},e.createElement("div",{className:"row"},e.createElement("h2",{className:"grow"},"Demos"),o.loop&&e.createElement(g,{small:!0,icon:"stop",onClick:()=>t.stopLoop()},"Stop the loop"),e.createElement(b,{title:"Make a demo",icon:"add",label:"New",items:[{label:"Record one: do it on the page",icon:"record",disabled:i,onClick:()=>t.openDialog({kind:"record"})},{label:"Start empty, in the studio",icon:"edit",onClick:()=>t.openStudio(t.create())},{label:"Import a .demo.json",icon:"upload",onClick:()=>{m().then(e=>e?.text()).then(e=>{if(e)return r(e)})}},{label:"Paste its JSON",icon:"copy",onClick:()=>{navigator.clipboard.readText().then(r,()=>t.say("Could not read the clipboard",!0))}}]}),e.createElement(g,{icon:"tune",kind:"bare",title:"Settings: voices, languages, subtitles",onClick:()=>t.openSettings()})),o.message&&e.createElement("div",{className:"small "+(o.message.error?"error":"muted")},o.message.text),0===l.length&&e.createElement("div",{className:"small muted"},"None yet: record one (New), or ask an AI to make one (it starts with demoEngine.help())."),l.map(a=>e.createElement(S,{key:a.demo.id,engine:t,entry:a,busy:i})),l.length>1&&e.createElement(g,{kind:"bare",icon:"loop",disabled:i,onClick:()=>t.openDialog({kind:"loop",demos:l.map(e=>e.demo)})},"Loop them all at a booth…"))}function S({engine:t,entry:a,busy:n}){const{demo:o,origin:l,video:s}=a,r=i(t.timing(o).duration);return e.createElement("div",{className:"demo"},e.createElement("div",{className:"row"},e.createElement("span",{className:"title grow ellipsis",title:o.description},o.title),"app"!==l&&e.createElement("span",{className:"badge"},"edited"===l?"edited here":"made here")),o.description&&e.createElement("div",{className:"small muted"},o.description),e.createElement("div",{className:"small muted"},o.steps.length," steps · ~",r,t.languagesOf(o).length?` · ${t.languagesOf(o).join(", ")}`:""),e.createElement("div",{className:"row"},e.createElement(g,{icon:"play",small:!0,kind:"primary",disabled:n,onClick:()=>{t.play(o)}},"Play"),e.createElement(g,{icon:"present",small:!0,disabled:n,title:"Step by step, the presenter’s screen beside it",onClick:()=>t.present(o)},"Present"),e.createElement(g,{icon:"guide",small:!0,disabled:n,title:"The viewer does each step: a tutorial",onClick:()=>{t.guide(o)}},"Guide"),e.createElement("span",{className:"grow"}),e.createElement(g,{icon:"edit",small:!0,kind:"bare",title:"Edit in the studio",onClick:()=>t.openStudio(o)}),e.createElement(b,{title:"More",items:[{label:"Film a video…",icon:"film",disabled:n,onClick:()=>t.openDialog({kind:"film",demo:o})},{label:"Loop at a booth…",icon:"loop",disabled:n,onClick:()=>t.openDialog({kind:"loop",demos:[o]})},s&&{label:"The video’s subtitles .srt",icon:"subtitles",onClick:()=>t.downloadVideo(s,o.title,"srt")},s&&{label:"Share the video…",icon:"share",onClick:()=>{t.shareVideo(s,o.title).then(e=>!e&&t.say("No share sheet here: download it instead."))}},{heading:"Share the demo"},{label:"Copy a link with the demo",icon:"link",onClick:()=>{t.link(o).then(e=>navigator.clipboard.writeText(e)).then(()=>t.say("Link copied."))}},{label:"Download .demo.json",icon:"download",onClick:()=>t.downloadDemo(o)},{label:"Download scenario .md",icon:"download",onClick:()=>t.downloadDemo({...o,scenario:a.scenario},"md")},{label:"Narration pack (.zip)",icon:"listen",onClick:()=>{t.downloadPack(o)}},{heading:"This demo"},{label:"Clone",icon:"duplicate",onClick:()=>t.openStudio({...JSON.parse(JSON.stringify(o)),id:t.create(o.title).id,title:`${o.title} (copy)`})},"edited"===l&&{label:"Revert to the app’s version",icon:"undo",onClick:()=>window.confirm("Drop the changes kept here?")&&void t.remove(o.id)},"here"===l&&{label:"Delete",icon:"delete",onClick:()=>window.confirm(`Delete "${o.title}"?`)&&void t.remove(o.id)}]})),s&&e.createElement("div",{className:"row video-line"},e.createElement(u,{name:"film"}),e.createElement(w,{video:s}),e.createElement("span",{className:"grow small muted ellipsis",title:new Date(s.at).toLocaleString()},new Date(s.at).toLocaleDateString(),s.json!==JSON.stringify(o)&&s.json!==JSON.stringify({...o,scenario:void 0})?" · older version":""),e.createElement(g,{icon:"play",small:!0,kind:"bare",title:"Watch",onClick:()=>t.openDialog({kind:"video",demo:o,video:s})}),e.createElement(g,{icon:"download",small:!0,kind:"bare",title:s.look?.subtitles?"Download":"Download, with its subtitles beside it",onClick:()=>{t.downloadVideo(s,o.title),s.look?.subtitles||t.downloadVideo(s,o.title,"vtt")}}),e.createElement(g,{icon:"delete",small:!0,kind:"bare",title:"Delete the video",onClick:()=>{window.confirm("Delete this video?")&&t.store.deleteVideo(s.id)}})))}export function Settings({engine:t}){const{settings:a,speech:n}=p(t),o=a.speech.voice,l=t.language(),i=e=>t.changeSettings({speech:{...a.speech,...e}});return e.createElement(e.Fragment,null,e.createElement("section",{className:"section"},e.createElement("h3",null,"Voice"),e.createElement(k,{value:o,onChange:e=>i({voice:e}),options:N.map(([e,t,a])=>[e,t,a])}),"free"===o&&e.createElement(C,{engine:t}),"elevenlabs"===o&&e.createElement(D,{engine:t}),"system"===o&&e.createElement(L,{engine:t,language:l}),e.createElement(E,{label:`Speed ${a.speech.rate.toFixed(2)}×`},e.createElement("input",{type:"range",min:.7,max:1.4,step:.05,value:a.speech.rate,onChange:e=>i({rate:Number(e.target.value)})})),void 0!==n.loading&&e.createElement("div",{className:"col",style:{gap:2}},e.createElement("span",{className:"small muted"},"Downloading a model: ",Math.round(100*n.loading)," %"),e.createElement("div",{className:"progress"},e.createElement("div",{style:{width:100*n.loading+"%"}}))),n.error&&e.createElement("div",{className:"small error"},"Voice: ",n.error)),e.createElement("section",{className:"section"},e.createElement("h3",null,"Language and subtitles"),e.createElement(E,{label:"Narration in"},e.createElement(k,{value:a.language,onChange:e=>t.changeSettings({language:e}),options:[["page",e.createElement(y,{key:"page",language:"page"},"The page's"),`The page's language: ${t.options.language?.()??l} now`],...t.languages().map(t=>[t,e.createElement(y,{key:t,language:t})])]})),e.createElement(h,{label:"Subtitles",checked:a.subtitles,onChange:e=>t.changeSettings({subtitles:e})}),e.createElement(h,{label:"A demo's narration pack, where it has one",title:"Its audio made once and checked in: no key, no download; what changed since, the voice says",checked:a.usePacks,onChange:e=>t.changeSettings({usePacks:e})})),e.createElement("section",{className:"section"},e.createElement("h3",null,"Playing from a step"),e.createElement(h,{label:"Earlier steps first, quickly: the app where the step expects it",checked:a.catchUp,onChange:e=>t.changeSettings({catchUp:e})})),e.createElement("div",{className:"small muted"},"Playing: Space pauses, → or PageDown goes on, ← or PageUp goes back, 1-9 a step, Esc stops. Videos, recordings, booths and presentations ask what they need as they start."))}function C({engine:a}){const{settings:n}=p(a),[l,i]=o([]);return t(()=>{c().then(i,()=>i([]))},[]),e.createElement("div",{className:"col"},a.languages().map(t=>{const o=a.speech.freeVoice(t)??"",i=t.split(/[-_]/)[0],s=l.filter(e=>e.language.split("_")[0]===i);return e.createElement(E,{key:t,label:`Voice for ${t}`},e.createElement("select",{className:"field",value:o,onChange:e=>a.changeSettings({speech:{...n.speech,free:{...n.speech.free,[t]:e.target.value}}})},!o&&e.createElement("option",{value:""},"None: choose one"),"en"===i&&e.createElement("optgroup",{label:"Kokoro"},r.map(t=>e.createElement("option",{key:t.id,value:`kokoro:${t.id}`},t.name))),e.createElement("optgroup",{label:"Piper"},o.startsWith("piper:")&&!s.some(e=>`piper:${e.id}`===o)&&e.createElement("option",{value:o},o.slice(6)),s.map(t=>e.createElement("option",{key:t.id,value:`piper:${t.id}`},t.name)))))}))}function D({engine:a}){const{settings:n}=p(a),{key:l,voice:i}=n.speech.elevenlabs,[r,c]=o([]),m=e=>a.changeSettings({speech:{...n.speech,elevenlabs:{...n.speech.elevenlabs,...e}}});return t(()=>{l&&s(l).then(c,()=>c([]))},[l]),e.createElement("div",{className:"row"},e.createElement(E,{label:"API key, kept in this browser",className:"grow"},e.createElement("input",{className:"field",type:"password",autoComplete:"off",value:l,onChange:e=>m({key:e.target.value.trim()})})),r.length>0&&e.createElement(E,{label:"Voice",className:"grow"},e.createElement("select",{className:"field",value:r.some(e=>e.id===i)?i:"",onChange:e=>m({voice:e.target.value})},r.map(t=>e.createElement("option",{key:t.id,value:t.id},t.name)))))}function L({engine:a,language:n}){const{settings:l}=p(a),[i,s]=o(()=>speechSynthesis.getVoices());t(()=>{const e=()=>s(speechSynthesis.getVoices());return speechSynthesis.addEventListener("voiceschanged",e),()=>speechSynthesis.removeEventListener("voiceschanged",e)},[]);const r=i.filter(e=>e.lang.toLowerCase().startsWith(n.toLowerCase().split("-")[0]));return e.createElement(E,{label:`Voice for ${n}`},e.createElement("select",{className:"field",value:l.speech.system[n]??"",onChange:e=>a.changeSettings({speech:{...l.speech,system:{...l.speech.system,[n]:e.target.value}}})},e.createElement("option",{value:""},"The default"),r.map(t=>e.createElement("option",{key:t.name,value:t.name},t.name))))}
package/ui/Presenter.js CHANGED
@@ -1 +1 @@
1
- import e,{useEffect as t,useState as n}from"react";import{createRoot as r}from"react-dom/client";import{sayOf as a,sentences as s}from"../model/Demo.js";import{clock as p}from"../model/Timing.js";import{useEngine as o}from"./Hooks.js";import{Button as i}from"./Kit.js";import{UI_CSS as l}from"./Styles.js";export async function openPresenter(e,{onTop:t=!1}={}){let n=null;const r=window.documentPictureInPicture;if(t&&r&&(n=await r.requestWindow({width:460,height:380}).catch(()=>null)),n||(n=window.open("","protomaze-demo-presenter","popup,width=1000,height=700")),!n)return!1;if(n.document.getElementById("pde-presenter"))return n.focus(),!0;n.document.title="Presenter";const a=mountPresenter(e,n.document,{compact:t&&Boolean(r)});return n.addEventListener("pagehide",a,{once:!0}),!0}export function mountPresenter(t,n,{compact:a=!1}={}){const s=n.createElement("style");s.textContent=l+"\nhtml, body { margin: 0; height: 100%; background: #17181c; }\n.pde.presenter { position: fixed; inset: 0; display: grid; grid-template-rows: auto 1fr auto; gap: 14px; padding: 16px 20px; background: var(--bg); font-size: 16px; }\n.pde.presenter .top { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }\n.pde.presenter .clock { font: 600 30px ui-monospace, monospace; }\n.pde.presenter .clock small { font-size: 14px; color: var(--muted); font-weight: 400; margin-left: 6px; }\n.pde.presenter .middle { display: grid; grid-template-columns: 1fr 260px; gap: 18px; min-height: 0; }\n.pde.presenter .now { overflow: auto; display: flex; flex-direction: column; gap: 12px; min-height: 0; }\n.pde.presenter h2 { margin: 0; font-size: 22px; }\n.pde.presenter .script p { margin: 0 0 10px; font-size: 26px; line-height: 1.45; color: var(--muted); }\n.pde.presenter .script p.on { color: var(--fg); }\n.pde.presenter .script p.said { opacity: .55; }\n.pde.presenter .notes { border-left: 4px solid var(--accent); padding: 8px 14px; background: var(--panel); white-space: pre-wrap; font-size: 18px; border-radius: 0 8px 8px 0; }\n.pde.presenter .next { border-top: 1px solid var(--line); padding-top: 10px; color: var(--muted); }\n.pde.presenter .steps { overflow: auto; display: flex; flex-direction: column; gap: 2px; border-left: 1px solid var(--line); padding-left: 12px; }\n.pde.presenter .steps button { text-align: left; border: 0; background: none; padding: 6px 8px; border-radius: 6px; cursor: pointer; color: var(--muted); font-size: 14px; }\n.pde.presenter .steps button.on { background: var(--raised); color: var(--fg); box-shadow: inset 3px 0 0 var(--accent); }\n.pde.presenter .controls { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }\n.pde.presenter .controls .btn { height: 64px; min-width: 96px; font-size: 18px; border-radius: 12px; }\n.pde.presenter .controls .btn svg.i { width: 28px; height: 28px; }\n.pde.presenter.compact { padding: 10px; gap: 8px; font-size: 14px; }\n.pde.presenter.compact .middle { grid-template-columns: 1fr; }\n.pde.presenter.compact .steps { display: none; }\n.pde.presenter.compact .script p { font-size: 18px; }\n.pde.presenter.compact .controls .btn { height: 44px; min-width: 56px; }\n.pde.presenter .idle { display: flex; flex-direction: column; gap: 8px; overflow: auto; }\n",n.head.append(s);const p=n.createElement("div");p.id="pde-presenter",p.setAttribute("data-demo-ignore",""),n.body.append(p);const o=r(p);o.render(e.createElement(c,{engine:t,compact:a}));const i=e=>t.presenterKey(e);return n.defaultView?.addEventListener("keydown",i,!0),()=>{n.defaultView?.removeEventListener("keydown",i,!0),o.unmount(),p.remove(),s.remove()}}function c({engine:r,compact:l}){const c=o(r),[,d]=n(0);t(()=>{const e=setInterval(()=>d(e=>e+1),500);return()=>clearInterval(e)},[]);const m=c.session,u="pde presenter"+(l?" compact":"");if("playing"!==m.mode||m.checking)return e.createElement("div",{className:u,"data-theme":"dark"},e.createElement("div",{className:"top"},e.createElement("h2",null,"Presenter"),e.createElement("span",{className:"muted"},"ready"===m.mode?"Waiting for a click in the app’s window":"Nothing plays")),e.createElement("div",{className:"idle"},e.createElement("span",{className:"muted"},"Start a demo in the app (Present waits after each step). Its script, your notes and the controls show here; a clicker works in either window."),r.entriesNow().map(({demo:t})=>e.createElement("div",{key:t.id,className:"row"},e.createElement("span",{className:"grow"},t.title),e.createElement(i,{icon:"present",onClick:()=>{r.play(t,{waitForPresenter:!0})}},"Present")))),e.createElement("div",null));const{demo:g,step:x,player:f}=m,h=g.steps[x],w=g.steps[x+1],E=r.language(),v=h?s(a(h,E)):[],y=v.indexOf(m.caption),b=f.elapsed(),N=b-f.stepStartedAt,k=r.timing(g,E),P=k.steps.find(e=>e.step===x);return e.createElement("div",{className:u,"data-theme":"dark"},e.createElement("div",{className:"top"},e.createElement("span",{className:"clock"},p(b),e.createElement("small",null,"/ ",p(k.duration))),e.createElement("span",{className:"clock",style:{fontSize:20}},p(N),e.createElement("small",null,"step",P?`, ~${p(P.end-P.start)}`:"")),e.createElement("span",{className:"grow"}),e.createElement("span",{className:"muted"},g.title),e.createElement("span",{className:"badge accent"},x+1," / ",g.steps.length),m.waiting&&e.createElement("span",{className:"badge"},"waiting for you"),m.paused&&!m.waiting&&e.createElement("span",{className:"badge"},"paused"),m.catchingUp&&e.createElement("span",{className:"badge"},"catching up")),e.createElement("div",{className:"middle"},e.createElement("div",{className:"now"},e.createElement("h2",null,h?.title??`Step ${x+1}`),e.createElement("div",{className:"script"},v.length?v.map((t,n)=>e.createElement("p",{key:n,className:n===y?"on":y>=0&&n<y?"said":""},t)):e.createElement("p",null,"No narration: in your own words.")),h?.notes&&e.createElement("div",{className:"notes"},h.notes),w&&e.createElement("div",{className:"next"},e.createElement("strong",null,"Next: ",w.title??`step ${x+2}`),e.createElement("div",null,s(a(w,E))[0]??""))),e.createElement("div",{className:"steps"},g.steps.map((t,n)=>e.createElement("button",{key:n,type:"button",className:n===x?"on":"",disabled:m.filming,onClick:()=>r.goTo(n)},n+1,". ",t.title??(s(a(t,E))[0]??"").slice(0,40))))),e.createElement("div",{className:"controls"},e.createElement(i,{icon:"back",title:"This step again; pressed early, the one before (←, PageUp)",disabled:m.filming,onClick:()=>r.back()}),e.createElement(i,{icon:m.paused?"play":"pause",kind:"primary",onClick:()=>m.waiting?r.next():r.togglePause()},m.waiting?"Continue":m.paused?"Resume":"Pause"),e.createElement(i,{icon:"right",title:"Next step (→, PageDown)",onClick:()=>r.next()}),e.createElement(i,{icon:"stop",title:"Stop (Esc)",onClick:()=>r.stop()})))}
1
+ import e,{useEffect as t,useState as n}from"react";import{createRoot as r}from"react-dom/client";import{sayOf as a,sentences as s}from"../model/Demo.js";import{clock as o}from"../model/Timing.js";import{useEngine as p}from"./Hooks.js";import{Button as l}from"./Kit.js";import{UI_CSS as i}from"./Styles.js";export async function openPresenter(e,{onTop:t=!1}={}){let n=null;const r=window.documentPictureInPicture;if(t&&r&&(n=await r.requestWindow({width:460,height:380}).catch(()=>null)),n||(n=window.open("","protomaze-demo-presenter","popup,width=1000,height=700")),!n)return!1;if(n.document.getElementById("pde-presenter"))return n.focus(),!0;n.document.title="Presenter";const a=mountPresenter(e,n.document,{compact:t&&Boolean(r)});return n.addEventListener("pagehide",a,{once:!0}),!0}export function mountPresenter(t,n,{compact:a=!1}={}){const s=n.createElement("style");s.textContent=i+"\nhtml, body { margin: 0; height: 100%; background: #17181c; }\n.pde.presenter { position: fixed; inset: 0; display: grid; grid-template-rows: auto 1fr auto; gap: 14px; padding: 16px 20px; background: var(--bg); font-size: 16px; }\n.pde.presenter .top { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }\n.pde.presenter .clock { font: 600 30px ui-monospace, monospace; }\n.pde.presenter .clock small { font-size: 14px; color: var(--muted); font-weight: 400; margin-left: 6px; }\n.pde.presenter .middle { display: grid; grid-template-columns: 1fr 260px; gap: 18px; min-height: 0; }\n.pde.presenter .now { overflow: auto; display: flex; flex-direction: column; gap: 12px; min-height: 0; }\n.pde.presenter h2 { margin: 0; font-size: 22px; }\n.pde.presenter .script p { margin: 0 0 10px; font-size: 26px; line-height: 1.45; color: var(--muted); }\n.pde.presenter .script p.on { color: var(--fg); }\n.pde.presenter .script p.said { opacity: .55; }\n.pde.presenter .notes { border-left: 4px solid var(--accent); padding: 8px 14px; background: var(--panel); white-space: pre-wrap; font-size: 18px; border-radius: 0 8px 8px 0; }\n.pde.presenter .next { border-top: 1px solid var(--line); padding-top: 10px; color: var(--muted); }\n.pde.presenter .steps { overflow: auto; display: flex; flex-direction: column; gap: 2px; border-left: 1px solid var(--line); padding-left: 12px; }\n.pde.presenter .steps button { text-align: left; border: 0; background: none; padding: 6px 8px; border-radius: 6px; cursor: pointer; color: var(--muted); font-size: 14px; }\n.pde.presenter .steps button.on { background: var(--raised); color: var(--fg); box-shadow: inset 3px 0 0 var(--accent); }\n.pde.presenter .controls { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }\n.pde.presenter .controls .btn { height: 64px; min-width: 96px; font-size: 18px; border-radius: 12px; }\n.pde.presenter .controls .btn svg.i { width: 28px; height: 28px; }\n.pde.presenter.compact { padding: 10px; gap: 8px; font-size: 14px; }\n.pde.presenter.compact .middle { grid-template-columns: 1fr; }\n.pde.presenter.compact .steps { display: none; }\n.pde.presenter.compact .script p { font-size: 18px; }\n.pde.presenter.compact .controls .btn { height: 44px; min-width: 56px; }\n.pde.presenter .idle { display: flex; flex-direction: column; gap: 8px; overflow: auto; }\n",n.head.append(s);const o=n.createElement("div");o.id="pde-presenter",o.setAttribute("data-demo-ignore",""),n.body.append(o);const p=r(o);p.render(e.createElement(u,{engine:t,compact:a}));const l=e=>t.presenterKey(e);return n.defaultView?.addEventListener("keydown",l,!0),()=>{n.defaultView?.removeEventListener("keydown",l,!0),p.unmount(),o.remove(),s.remove()}}const c=e=>e<2;function d({engine:t}){const{remote:n}=p(t);return n?e.createElement(l,{small:!0,kind:"bare",icon:"share",title:"Close the phone link",onClick:()=>t.closeRemote()},n.peers>1?"● Phone":"Phone…"):e.createElement(l,{small:!0,kind:"bare",icon:"share",title:"The presenter's screen on a phone, by QR code",onClick:()=>{t.openRemote()}},"Phone")}function m({engine:t}){const{remote:n}=p(t);return n?e.createElement("div",{className:"row",style:{position:"absolute",top:64,right:20,zIndex:2,alignItems:"flex-start",gap:12,padding:12,borderRadius:12,background:"var(--panel)",boxShadow:"var(--shadow)"}},e.createElement("div",{className:"qr",dangerouslySetInnerHTML:{__html:n.svg}}),e.createElement("div",{className:"col small",style:{width:180}},e.createElement("strong",null,"Scan it with your phone"),e.createElement("span",{className:"muted"},"This screen on the phone: script, notes, controls. Encrypted end to end."),e.createElement(l,{small:!0,onClick:()=>t.closeRemote()},"Close"))):null}function u({engine:r,compact:i}){const u=p(r),[,g]=n(0);t(()=>{const e=setInterval(()=>g(e=>e+1),500);return()=>clearInterval(e)},[]);const h=u.session,x="pde presenter"+(i?" compact":"");if("playing"!==h.mode||h.checking)return e.createElement("div",{className:x,"data-theme":"dark"},e.createElement("div",{className:"top"},e.createElement("h2",null,"Presenter"),e.createElement("span",{className:"muted"},"ready"===h.mode?"Waiting for a click in the app’s window":"Nothing plays")),e.createElement("div",{className:"idle"},e.createElement("span",{className:"muted"},"Start a demo in the app (Present waits after each step). Its script, your notes and the controls show here; a clicker works in either window."),r.entriesNow().map(({demo:t})=>e.createElement("div",{key:t.id,className:"row"},e.createElement("span",{className:"grow"},t.title),e.createElement(l,{icon:"present",onClick:()=>{r.play(t,{waitForPresenter:!0})}},"Present")))),e.createElement("div",null));const{demo:f,step:E,player:w}=h,v=f.steps[E],y=f.steps[E+1],b=r.language(),k=v?s(a(v,b)):[],N=k.indexOf(h.caption),P=w.elapsed(),C=P-w.stepStartedAt,z=r.timing(f,b),S=z.steps.find(e=>e.step===E);return e.createElement("div",{className:x,"data-theme":"dark"},e.createElement("div",{className:"top"},e.createElement("span",{className:"clock"},o(P),e.createElement("small",null,"/ ",o(z.duration))),e.createElement("span",{className:"clock",style:{fontSize:20}},o(C),e.createElement("small",null,"step",S?`, ~${o(S.end-S.start)}`:"")),e.createElement("span",{className:"grow"}),e.createElement("span",{className:"muted"},f.title),e.createElement("span",{className:"badge accent"},E+1," / ",f.steps.length),h.waiting&&e.createElement("span",{className:"badge"},"waiting for you"),h.paused&&!h.waiting&&e.createElement("span",{className:"badge"},"paused"),h.catchingUp&&e.createElement("span",{className:"badge"},"catching up"),!1!==r.options.remote&&e.createElement(d,{engine:r})),u.remote&&c(u.remote.peers)&&e.createElement(m,{engine:r}),e.createElement("div",{className:"middle"},e.createElement("div",{className:"now"},e.createElement("h2",null,v?.title??`Step ${E+1}`),e.createElement("div",{className:"script"},k.length?k.map((t,n)=>e.createElement("p",{key:n,className:n===N?"on":N>=0&&n<N?"said":""},t)):e.createElement("p",null,"No narration: in your own words.")),v?.notes&&e.createElement("div",{className:"notes"},v.notes),y&&e.createElement("div",{className:"next"},e.createElement("strong",null,"Next: ",y.title??`step ${E+2}`),e.createElement("div",null,s(a(y,b))[0]??""))),e.createElement("div",{className:"steps"},f.steps.map((t,n)=>e.createElement("button",{key:n,type:"button",className:n===E?"on":"",disabled:h.filming,onClick:()=>r.goTo(n)},n+1,". ",t.title??(s(a(t,b))[0]??"").slice(0,40))))),e.createElement("div",{className:"controls"},e.createElement(l,{icon:"back",title:"This step again; pressed early, the one before (←, PageUp)",disabled:h.filming,onClick:()=>r.back()}),e.createElement(l,{icon:h.paused?"play":"pause",kind:"primary",onClick:()=>h.waiting?r.next():r.togglePause()},h.waiting?"Continue":h.paused?"Resume":"Pause"),e.createElement(l,{icon:"right",title:"Next step (→, PageDown)",onClick:()=>r.next()}),e.createElement(l,{icon:"stop",title:"Stop (Esc)",onClick:()=>r.stop()})))}
package/ui/Studio.js CHANGED
@@ -1 +1 @@
1
- import e,{useEffect as t,useMemo as a,useRef as n,useState as i}from"react";import{copyOf as o,sayOf as l,scenarioOf as s,sentences as r}from"../model/Demo.js";import{clock as c}from"../model/Timing.js";import{fileName as d}from"../store/Share.js";import{recordMicrophone as m}from"../video/Film.js";import{ActionRow as p,addActionItems as h,readAction as g}from"./Actions.js";import{useEngine as u}from"./Hooks.js";import{Button as v,Check as f,Menu as w,NumberField as E,Segmented as k}from"./Kit.js";import{Timeline as y}from"./Timeline.js";const b="protomaze-demo-engine:studio-height";export function Studio({engine:d,theme:m}){const S=u(d),D=S.studio,[j,$]=i(()=>o(D.demo)),[L,O]=i(()=>JSON.stringify(D.demo)),T=n({back:[],forward:[]}),[R,M]=i(0),[J,U]=i(),[A,P]=i("steps"),[F,V]=i({json:"",scenario:""}),[z,B]=i(),[W,H]=i(new Map),[K,q]=i(()=>Number(localStorage.getItem(b))||Math.round(.46*innerHeight)),[I,Y]=i(!1),[G,Z]=i(!1),[Q,X]=i(!1),[_,ee]=i(()=>d.language()),te=S.session,ae="idle"!==te.mode,ne="playing"!==te.mode||te.checking?void 0:te,ie=j.steps,oe=Math.min(R,Math.max(0,ie.length-1)),le=ne&&ne.demo.id===j.id?ne.step:oe,se=JSON.stringify(j)!==L,re=a(()=>Array.from(new Set([...d.languages(),...d.languagesOf(j)])),[j]),ce=d.entriesNow().find(e=>e.demo.id===j.id),de=d.timing(j,_),me=S.lastRun?.json===JSON.stringify(j)&&S.lastRun.language===_,pe=(e,t=!0)=>{t&&(T.current.back.push(j),T.current.back.length>200&&T.current.back.shift(),T.current.forward=[]),$(e)},he=()=>{const e=T.current.back.pop();e&&(T.current.forward.push(j),$(e))},ge=()=>{const e=T.current.forward.pop();e&&(T.current.back.push(j),$(e))},ue=e=>pe({...j,...e}),ve=e=>ue({steps:e}),fe=e=>ve(ie.map((t,a)=>a===oe?e:t));t(()=>{D.recorded&&pe({...j,steps:D.recorded.steps})},[D.recorded?.at]);const we=()=>{const{demo:e,problems:t}=d.parse(F.json);if(e)return B(void 0),{...e,scenario:F.scenario};B(t.slice(0,4).map(e=>`${e.path||"demo"}: ${e.message}`).join(" · "))},Ee=async()=>{const e="text"===A?we():j;if(e)try{await d.save(e),$(e),O(JSON.stringify(e)),d.say(`Saved "${e.title}".`)}catch(e){d.say(e.message,!0)}},ke=e=>{d.play(j,{from:e,language:_})},ye=e=>{const t=oe+e;if(t<0||t>=ie.length)return;const a=[...ie];[a[oe],a[t]]=[a[t],a[oe]],ve(a),M(t)},be=I||Q||"recording"===te.mode||Boolean(ne),Ne=ie[oe],Ce=e=>{const t=de.steps.find(t=>t.step===e);return t?`${((t.end-t.start)/1e3).toFixed(1)} s`:""};return e.createElement("div",{className:"pde studio"+(be?" collapsed":""),"data-theme":m,"data-demo-ignore":!0,onKeyDown:e=>{if(!(e.ctrlKey||e.metaKey))return;const t=e.key.toLowerCase();"s"===t?(e.preventDefault(),Ee()):"z"!==t||e.shiftKey||"text"===A?("y"===t||"z"===t&&e.shiftKey)&&"text"!==A&&(e.preventDefault(),ge()):(e.preventDefault(),he())},style:{height:be?void 0:K,display:Q?"none":void 0}},e.createElement("div",{className:"grip",onPointerDown:e=>{const t=e.clientY,a=K,n=e=>q(Math.max(180,Math.min(innerHeight-40,a+t-e.clientY))),i=()=>{window.removeEventListener("pointermove",n),window.removeEventListener("pointerup",i),q(e=>(localStorage.setItem(b,String(e)),e))};window.addEventListener("pointermove",n),window.addEventListener("pointerup",i)}}),e.createElement("div",{className:"head"},e.createElement("input",{className:"field",style:{width:240,fontWeight:600},value:j.title,title:"Title",onChange:e=>ue({title:e.target.value})}),e.createElement("input",{className:"field grow",style:{minWidth:120},placeholder:"Description: who it is for, what it shows",value:j.description??"",onChange:e=>ue({description:e.target.value})}),re.length>1&&e.createElement("select",{className:"field",title:"The language played, and timed",value:_,onChange:e=>ee(e.target.value)},re.map(t=>e.createElement("option",{key:t,value:t},t))),e.createElement("div",{className:"sep"}),!ne&&e.createElement(e.Fragment,null,e.createElement(v,{icon:"first",title:"Play from the start",disabled:ae,onClick:()=>ke(0)}),e.createElement(v,{icon:"play",kind:"primary",title:`Play from step ${oe+1}`,disabled:ae,onClick:()=>ke(oe)})),!ne&&e.createElement(w,{title:"Present, guide, loop",icon:"present",items:[{label:`Present from step ${oe+1}: waits after each step, the presenter's screen beside it`,icon:"present",disabled:ae,onClick:()=>{d.present(j,{from:oe,language:_})}},{label:"The presenter's screen, always on top",icon:"present",onClick:()=>{d.openPresenter({onTop:!0})}},{label:`Guide from step ${oe+1}: the viewer does it`,icon:"guide",disabled:ae,onClick:()=>{d.guide(j,{from:oe,language:_})}},{label:"Loop it: an expo booth",icon:"loop",disabled:ae,onClick:()=>{d.loop([j])}}]}),ne&&e.createElement(e.Fragment,null,e.createElement(v,{icon:ne.paused?"play":"pause",kind:"primary",title:ne.waiting?"Continue":ne.paused?"Resume":"Pause",onClick:()=>ne.waiting?d.next():d.togglePause()}),e.createElement(v,{icon:"right",title:"Next step",onClick:()=>d.next()}),e.createElement(v,{icon:"stop",title:"Stop",onClick:()=>d.stop()})),e.createElement(v,{icon:"record",title:`Record new steps after step ${oe+1}`,disabled:ae,onClick:()=>{d.record({into:j,after:oe})},style:{color:"var(--danger)"}}),e.createElement(v,{icon:"film",title:"Film it: a video with narration and subtitles",disabled:ae,onClick:()=>{d.film(j,{language:_})}}),e.createElement(v,{icon:"check",title:"Check: plays it fast and silent, and marks what fails",disabled:ae,onClick:()=>{(async()=>{const e=await d.check(j);H(new Map(e.failures.map(e=>[`${e.step}.${e.index}`,e.error]))),e.ok?d.say(`Every step plays: ${c(e.duration)} at speed.`):d.say(e.failures.length?`${e.failures.length} action${1===e.failures.length?"":"s"} failed: in red.`:e.error??"Failed",!0);const t=e.failures[0];t&&(M(t.step),U(t.index))})()}}),e.createElement("div",{className:"sep"}),e.createElement(v,{icon:"undo",kind:"bare",title:"Undo (Ctrl+Z)",disabled:0===T.current.back.length,onClick:he}),e.createElement(v,{icon:"redo",kind:"bare",title:"Redo (Ctrl+Y)",disabled:0===T.current.forward.length,onClick:ge}),e.createElement(v,{icon:"save",kind:se?"primary":void 0,title:"Save here (Ctrl+S)",onClick:()=>{Ee()}},se?"Save":"Saved"),e.createElement(w,{title:"Share, export",icon:"share",items:[{label:"Download .demo.json",icon:"download",onClick:()=>d.downloadDemo(j)},{label:"Download scenario .md",icon:"download",onClick:()=>d.downloadDemo(j,"md")},{label:"Copy a link with the demo",icon:"link",onClick:()=>{d.link(j).then(e=>navigator.clipboard.writeText(e)).then(()=>d.say("Link copied: it opens the app with this demo."))}},{label:"Copy JSON",icon:"copy",onClick:()=>{navigator.clipboard.writeText(JSON.stringify({...j,scenario:void 0,savedAt:void 0},null,2)).then(()=>d.say("JSON copied."))}},{label:"Narration pack (.zip): no key, no download, for every viewer",icon:"listen",onClick:()=>{d.downloadPack(j)}},ce?.video&&{label:"Download the video",icon:"film",onClick:()=>d.downloadVideo(ce.video,j.title)},{heading:"This demo"},"edited"===ce?.origin&&{label:"Revert to the app’s version",icon:"undo",onClick:()=>{window.confirm("Drop the changes kept here?")&&d.remove(j.id)}},"here"===ce?.origin&&{label:"Delete",icon:"delete",onClick:()=>{window.confirm(`Delete "${j.title}"?`)&&d.remove(j.id)}}]}),e.createElement(k,{value:A,onChange:e=>{if(e!==A){if("text"===A){const e=we();if(!e)return;JSON.stringify(e)!==JSON.stringify(j)&&pe(e)}"text"===e&&(()=>{const{scenario:e,savedAt:t,...a}=j;V({json:JSON.stringify(a,null,2),scenario:j.scenario??s(j,_)}),B(void 0)})(),P(e)}},options:[["steps","Steps"],["text","Text"],["video","Video",ce?.video?"Its last video":"Not filmed yet"]]}),e.createElement(v,{icon:I?"maximize":"minimize",kind:"bare",title:I?"Unfold":"Fold",onClick:()=>Y(!I)}),e.createElement(v,{icon:"close",kind:"bare",title:"Close",onClick:()=>{se&&!window.confirm("Close without saving?")||d.closeStudio()}})),e.createElement(y,{demo:j,timing:de,measured:me,step:le,action:J,theme:m,accent:"#ffb300",playhead:ne&&ne.demo.id===j.id?()=>d.elapsed():void 0,read:e=>g(d,e),onPick:(e,t)=>{ne&&ne.demo.id===j.id&&d.goTo(e)||(M(e),U(t),I&&Y(!1))}}),z&&e.createElement("div",{className:"error small",style:{padding:"4px 12px"}},z),e.createElement("div",{className:"body"},"text"!==A&&e.createElement("div",{className:"steps"},ie.map((t,a)=>e.createElement("div",{key:a,className:["step",a===oe&&!G&&"on",ne&&a===le&&"playing"].filter(Boolean).join(" "),onClick:()=>{M(a),U(void 0),Z(!1),function(e){if("video"!==A)return;const t=ce?.video?.timing?.steps.find(t=>t.step===e),a=document.querySelector("protomaze-demo-engine")?.shadowRoot?.querySelector("video");t&&a&&(a.currentTime=t.start/1e3)}(a)}},e.createElement("span",{className:"n"},a+1),e.createElement("div",{className:"col grow",style:{gap:2}},e.createElement("div",{className:"row"},e.createElement("span",{className:"grow ellipsis",style:{fontWeight:500}},t.title||function(e,t){return r(l(e,t))[0]}(t,_)||"Untitled"),e.createElement("span",{className:"small muted"},Ce(a))),t.title&&e.createElement("span",{className:"say"},l(t,_)),e.createElement("span",{className:"small muted"},t.actions.length," action",1===t.actions.length?"":"s",t.pause?" · waits":"")))),e.createElement(v,{icon:"add",small:!0,onClick:()=>{ve([...ie.slice(0,oe+1),{say:{},actions:[]},...ie.slice(oe+1)]),M(oe+1),Z(!1)}},"New step"),e.createElement("div",{className:["step",G&&"on"].filter(Boolean).join(" "),style:{marginTop:6},onClick:()=>{Z(!0),U(void 0)},title:"Done after the demo, quickly and unseen, so the app is as it found it"},e.createElement("span",{className:"n"},"↺"),e.createElement("div",{className:"col grow",style:{gap:2}},e.createElement("span",{style:{fontWeight:500}},"Cleanup"),e.createElement("span",{className:"small muted"},(j.cleanup??[]).length," action",1===(j.cleanup??[]).length?"":"s"," after it, unseen")))),"steps"===A&&G&&e.createElement("div",{className:"pane"},e.createElement("div",{className:"row"},e.createElement("strong",{className:"grow"},"Cleanup"),e.createElement(w,{title:"Add an action",icon:"add",label:"Add",items:h(d,e=>{ue({cleanup:[...j.cleanup??[],e]}),U((j.cleanup??[]).length)})})),e.createElement("div",{className:"small muted"},"Done after the demo - when it ends, or is stopped - quickly and unseen: filters cleared, what it opened closed, what it changed changed back. So it plays again, and the next one starts where it expects. What the app cannot undo itself, its start resets (the app's ",e.createElement("span",{className:"mono"},"start.go"),")."),(j.cleanup??[]).map((t,a)=>e.createElement(p,{key:`cleanup.${a}`,engine:d,action:t,index:a,count:(j.cleanup??[]).length,open:J===a,sentences:[],onOpen:()=>U(J===a?void 0:a),onChange:e=>ue({cleanup:(j.cleanup??[]).map((t,n)=>n===a?e:t)}),onMove:e=>{const t=[...j.cleanup??[]],n=a+e;n<0||n>=t.length||([t[a],t[n]]=[t[n],t[a]],ue({cleanup:t}),U(n))},onDuplicate:()=>ue({cleanup:[...(j.cleanup??[]).slice(0,a+1),o(t),...(j.cleanup??[]).slice(a+1)]}),onDelete:()=>{ue({cleanup:(j.cleanup??[]).filter((e,t)=>t!==a)}),U(void 0)},picking:X}))),"steps"===A&&Ne&&!G&&e.createElement(e.Fragment,null,e.createElement("div",{className:"pane"},e.createElement("div",{className:"row"},e.createElement("strong",{className:"grow"},"Step ",oe+1," of ",ie.length),e.createElement(v,{icon:"up",small:!0,kind:"bare",title:"Earlier",disabled:0===oe,onClick:()=>ye(-1)}),e.createElement(v,{icon:"down",small:!0,kind:"bare",title:"Later",disabled:oe===ie.length-1,onClick:()=>ye(1)}),e.createElement(v,{icon:"duplicate",small:!0,kind:"bare",title:"Duplicate",onClick:()=>{ve([...ie.slice(0,oe+1),o(Ne),...ie.slice(oe+1)]),M(oe+1)}}),e.createElement(v,{icon:"delete",small:!0,kind:"bare",title:"Delete this step",disabled:ie.length<2,onClick:()=>{ve(ie.filter((e,t)=>t!==oe)),M(Math.max(0,oe-1))}})),e.createElement("input",{className:"field",placeholder:"Title, for the editor and the timeline",value:Ne.title??"",onChange:e=>fe(N(Ne,"title",e.target.value||void 0))}),re.map(t=>e.createElement(C,{key:t,engine:d,language:t,text:Ne.say[t]??"",onChange:e=>fe({...Ne,say:N(Ne.say,t,e||void 0)})})),e.createElement("textarea",{className:"field",rows:2,placeholder:"Notes for the presenter: on their screen only, never said or shown",value:Ne.notes??"",onChange:e=>fe(N(Ne,"notes",e.target.value||void 0))}),e.createElement("div",{className:"row",style:{flexWrap:"wrap",gap:12}},e.createElement("span",{className:"small muted"},"Hold after, ms"),e.createElement(E,{value:Ne.hold,width:70,placeholder:"0",onChange:e=>fe(N(Ne,"hold",e))}),e.createElement(f,{label:"Wait for the presenter after it",checked:Boolean(Ne.pause),onChange:e=>fe(N(Ne,"pause",e||void 0))}),e.createElement("span",{className:"small muted"},Ce(oe)))),e.createElement("div",{className:"pane",style:{flex:1.3}},e.createElement("div",{className:"row"},e.createElement("strong",{className:"grow"},"Actions"),e.createElement("span",{className:"small muted"},"played one after the other, while the narration speaks"),e.createElement(w,{title:"Add an action",icon:"add",label:"Add",items:h(d,e=>{fe({...Ne,actions:[...Ne.actions,e]}),U(Ne.actions.length)})})),0===Ne.actions.length&&e.createElement("div",{className:"muted small"},"None yet: add one, or record them (●) by doing them on the page."),Ne.actions.map((t,a)=>e.createElement(p,{key:`${oe}.${a}`,engine:d,action:t,index:a,count:Ne.actions.length,open:J===a,error:W.get(`${oe}.${a}`),sentences:r(l(Ne,_)),onOpen:()=>U(J===a?void 0:a),onChange:e=>((e,t)=>fe({...ie[oe],actions:ie[oe].actions.map((a,n)=>n===e?t:a)}))(a,e),onMove:e=>((e,t)=>{const a=e+t,n=[...ie[oe].actions];a<0||a>=n.length||([n[e],n[a]]=[n[a],n[e]],fe({...ie[oe],actions:n}),U(a))})(a,e),onDuplicate:()=>fe({...Ne,actions:[...Ne.actions.slice(0,a+1),o(t),...Ne.actions.slice(a+1)]}),onDelete:()=>{fe({...Ne,actions:Ne.actions.filter((e,t)=>t!==a)}),U(void 0)},picking:X})))),"text"===A&&e.createElement("div",{className:"pane",style:{flexDirection:"row"}},e.createElement("textarea",{className:"field mono grow",spellCheck:!1,value:F.json,onChange:e=>V({...F,json:e.target.value})}),e.createElement("textarea",{className:"field mono grow",spellCheck:!1,value:F.scenario,placeholder:"The scenario, for people (.md)",onChange:e=>V({...F,scenario:e.target.value})})),"video"===A&&e.createElement(x,{engine:d,draft:j})))}function N(e,t,a){const n={...e,[t]:a};return void 0===a&&delete n[t],n}function C({engine:t,language:a,text:n,onChange:o}){const[l,s]=i(),[c,d]=i(),[p,h]=i(),g=r(n);return e.createElement("div",{className:"col",style:{gap:4}},e.createElement("div",{className:"row"},e.createElement("span",{className:"badge accent"},a),e.createElement("span",{className:"small muted grow"},g.length," sentence",1===g.length?"":"s",c?` · ${c}`:""),e.createElement(v,{icon:p?"stop":"listen",small:!0,kind:"bare",title:p?"Stop":"Listen, in the voice chosen",disabled:!n.trim(),onClick:()=>{(async()=>{if(p)return p();let e=!1,i=()=>{};h(()=>()=>{e=!0,i()}),t.speech.wake();for(const o of r(n)){if(e)break;d("Making the voice…");const n=await t.speech.say(o,a).catch(e=>{t.say(e.message,!0)});if(d(void 0),!n)break;i=n.stop,await n.done}d(void 0),h(void 0)})()}}),e.createElement(v,{icon:l?"stop":"mic",small:!0,kind:"bare",on:Boolean(l),title:l?"Stop, and write what was said":"Dictate: speak, then stop",onClick:()=>{(async()=>{if(l){s(void 0),d("Transcribing…");try{const e=(await t.transcribe(await l.stop(),a)).map(e=>e.text).join(" ").trim();e&&o([n.trim(),e].filter(Boolean).join(" "))}catch(e){t.say(e.message,!0)}d(void 0)}else try{s(await m())}catch(e){t.say(`Microphone: ${e.message}`,!0)}})()},style:l?{color:"var(--danger)"}:void 0})),e.createElement("textarea",{className:"field",rows:3,placeholder:`Narration (${a}): what the viewer should notice, a sentence a subtitle`,value:n,onChange:e=>o(e.target.value)}))}function x({engine:n,draft:i}){const o=n.entriesNow().find(e=>e.demo.id===i.id),l=o?.video,s=a(()=>l&&{video:URL.createObjectURL(l.blob),vtt:URL.createObjectURL(new Blob([l.vtt],{type:"text/vtt"}))},[l]);if(t(()=>()=>{s&&(URL.revokeObjectURL(s.video),URL.revokeObjectURL(s.vtt))},[s]),!l||!s)return e.createElement("div",{className:"pane muted"},"Not filmed yet: film it (the film button) to make a video with narration and subtitles, kept here.");const r=l.json!==JSON.stringify({...i,scenario:void 0,savedAt:void 0})&&l.json!==JSON.stringify(i);return e.createElement("div",{className:"pane",style:{flexDirection:"row"}},e.createElement("div",{className:"grow",style:{minHeight:0,display:"flex"}},e.createElement("video",{src:s.video,controls:!0,style:{maxHeight:"100%"}},e.createElement("track",{kind:"subtitles",src:s.vtt,srcLang:l.language??"en",label:"Narration",default:!0}))),e.createElement("div",{className:"col",style:{width:240}},e.createElement("span",{className:"small muted"},new Date(l.at).toLocaleString()," · ",Math.round(l.blob.size/1e5)/10," MB · ",l.blob.type.split(";")[0]),r&&e.createElement("span",{className:"small error"},"Filmed from an older version of the demo."),e.createElement(v,{icon:"download",onClick:()=>n.downloadVideo(l,i.title)},"Video"),e.createElement(v,{icon:"subtitles",onClick:()=>n.downloadVideo(l,i.title,"vtt")},"Subtitles .vtt"),e.createElement(v,{icon:"subtitles",onClick:()=>n.downloadVideo(l,i.title,"srt")},"Subtitles .srt"),e.createElement(v,{icon:"share",onClick:()=>{n.shareVideo(l,i.title).then(e=>!e&&n.say("No share sheet here: download it instead."))}},"Share…"),l.voice&&e.createElement(v,{icon:"download",onClick:()=>n.downloadVideo({...l,blob:l.voice},`${i.title} voice`)},"The presenter's voice"),e.createElement(v,{icon:"delete",kind:"danger",onClick:()=>{n.store.deleteVideo(l.id)}},"Delete the video"),e.createElement("span",{className:"small muted"},d(i.title,l.blob.type.includes("mp4")?"mp4":"webm"))))}
1
+ import e,{useEffect as t,useMemo as a,useRef as n,useState as i}from"react";import{copyOf as l,sayOf as o,scenarioOf as s,sentences as r}from"../model/Demo.js";import{clock as c}from"../model/Timing.js";import{fileName as d}from"../store/Share.js";import{recordMicrophone as m}from"../video/Film.js";import{ActionRow as p,addActionItems as h,readAction as g}from"./Actions.js";import{useEngine as u}from"./Hooks.js";import{Button as v,Check as f,JsonField as E,Labelled as w,Menu as k,NumberField as y,Segmented as b}from"./Kit.js";import{Timeline as N}from"./Timeline.js";const C="protomaze-demo-engine:studio-height";export function Studio({engine:d,theme:m}){const j=u(d),$=j.studio,[O,L]=i(()=>l($.demo)),[R,T]=i(()=>JSON.stringify($.demo)),M=n({back:[],forward:[]}),[A,J]=i(0),[B,U]=i(),[F,P]=i("steps"),[V,z]=i({json:"",scenario:""}),[W,H]=i(),[I,K]=i(new Map),[q,Y]=i(()=>Number(localStorage.getItem(C))||Math.round(.46*innerHeight)),[G,Z]=i(!1),[Q,X]=i(!1),[_,ee]=i(!1),[te,ae]=i(!1),[ne,ie]=i(()=>d.language()),le=j.session,oe="idle"!==le.mode,se="playing"!==le.mode||le.checking?void 0:le,re=O.steps,ce=Math.min(A,Math.max(0,re.length-1)),de=se&&se.demo.id===O.id?se.step:ce,me=JSON.stringify(O)!==R,pe=a(()=>Array.from(new Set([...d.languages(),...d.languagesOf(O)])),[O]),he=d.entriesNow().find(e=>e.demo.id===O.id),ge=d.timing(O,ne),ue=j.lastRun?.json===JSON.stringify(O)&&j.lastRun.language===ne,ve=(e,t=!0)=>{t&&(M.current.back.push(O),M.current.back.length>200&&M.current.back.shift(),M.current.forward=[]),L(e)},fe=()=>{const e=M.current.back.pop();e&&(M.current.forward.push(O),L(e))},Ee=()=>{const e=M.current.forward.pop();e&&(M.current.back.push(O),L(e))},we=e=>ve({...O,...e}),ke=e=>we({steps:e}),ye=e=>ke(re.map((t,a)=>a===ce?e:t));t(()=>{$.recorded&&ve({...O,steps:$.recorded.steps})},[$.recorded?.at]);const be=()=>{const{demo:e,problems:t}=d.parse(V.json);if(e)return H(void 0),{...e,scenario:V.scenario};H(t.slice(0,4).map(e=>`${e.path||"demo"}: ${e.message}`).join(" · "))},Ne=async()=>{const e="text"===F?be():O;if(e)try{await d.save(e),L(e),T(JSON.stringify(e)),d.say(`Saved "${e.title}".`)}catch(e){d.say(e.message,!0)}},Ce=e=>{d.play(O,{from:e,language:ne})},xe=e=>{const t=ce+e;if(t<0||t>=re.length)return;const a=[...re];[a[ce],a[t]]=[a[t],a[ce]],ke(a),J(t)},Se=G||te||"recording"===le.mode||Boolean(se),De=re[ce],je=e=>{const t=ge.steps.find(t=>t.step===e);return t?`${((t.end-t.start)/1e3).toFixed(1)} s`:""};return e.createElement("div",{className:"pde studio"+(Se?" collapsed":""),"data-theme":m,"data-demo-ignore":!0,onKeyDown:e=>{if(!(e.ctrlKey||e.metaKey))return;const t=e.key.toLowerCase();"s"===t?(e.preventDefault(),Ne()):"z"!==t||e.shiftKey||"text"===F?("y"===t||"z"===t&&e.shiftKey)&&"text"!==F&&(e.preventDefault(),Ee()):(e.preventDefault(),fe())},style:{height:Se?void 0:q,display:te?"none":void 0}},e.createElement("div",{className:"grip",onPointerDown:e=>{const t=e.clientY,a=q,n=e=>Y(Math.max(180,Math.min(innerHeight-40,a+t-e.clientY))),i=()=>{window.removeEventListener("pointermove",n),window.removeEventListener("pointerup",i),Y(e=>(localStorage.setItem(C,String(e)),e))};window.addEventListener("pointermove",n),window.addEventListener("pointerup",i)}}),e.createElement("div",{className:"head"},e.createElement("input",{className:"field title",value:O.title,title:"Title",onChange:e=>we({title:e.target.value})}),e.createElement("div",{className:"sep"}),!se&&e.createElement(e.Fragment,null,e.createElement(v,{icon:"play",kind:"primary",disabled:oe,title:`Play from step ${ce+1}`,onClick:()=>Ce(ce)},"Play"),e.createElement(k,{title:"Play from the start, present, guide, loop",icon:"expand",align:"left",items:[{label:"From the start",icon:"first",disabled:oe,onClick:()=>Ce(0)},{label:`Present from step ${ce+1}…`,icon:"present",disabled:oe,onClick:()=>d.present(O,{from:ce})},{label:`Guide from step ${ce+1}: the viewer does it`,icon:"guide",disabled:oe,onClick:()=>{d.guide(O,{from:ce,language:ne})}},{label:"Loop at a booth…",icon:"loop",disabled:oe,onClick:()=>d.openDialog({kind:"loop",demos:[O]})},...pe.length>1?[{heading:"Narration in"},...pe.map(e=>({label:`${e===ne?"● ":""}${e}`,onClick:()=>ie(e)}))]:[]]}),e.createElement(v,{icon:"record",title:`Record new steps after step ${ce+1}…`,disabled:oe,onClick:()=>d.openDialog({kind:"record",into:O,after:ce}),style:{color:"var(--danger)"}}),e.createElement(v,{icon:"film",title:"Film a video…",disabled:oe,onClick:()=>d.openDialog({kind:"film",demo:O})}),e.createElement(v,{icon:"check",title:"Check: plays it fast and silent, and marks what fails",disabled:oe,onClick:()=>{(async()=>{const e=await d.check(O);K(new Map(e.failures.map(e=>[`${e.step}.${e.index}`,e.error]))),e.ok?d.say(`Every step plays: ${c(e.duration)} at speed.`):d.say(e.failures.length?`${e.failures.length} action${1===e.failures.length?"":"s"} failed: in red.`:e.error??"Failed",!0);const t=e.failures[0];t&&(J(t.step),U(t.index))})()}})),se&&e.createElement(e.Fragment,null,e.createElement(v,{icon:se.paused?"play":"pause",kind:"primary",onClick:()=>se.waiting?d.next():d.togglePause()},se.waiting?"Continue":se.paused?"Resume":"Pause"),e.createElement(v,{icon:"back",title:"Back (←)",onClick:()=>d.back()}),e.createElement(v,{icon:"right",title:"Next step (→)",onClick:()=>d.next()}),e.createElement(v,{icon:"stop",title:"Stop (Esc)",onClick:()=>d.stop()})),e.createElement("span",{className:"grow"}),e.createElement(v,{icon:"undo",kind:"bare",title:"Undo (Ctrl+Z)",disabled:0===M.current.back.length,onClick:fe}),e.createElement(v,{icon:"redo",kind:"bare",title:"Redo (Ctrl+Y)",disabled:0===M.current.forward.length,onClick:Ee}),e.createElement(v,{icon:"save",kind:me?"primary":void 0,title:"Save here (Ctrl+S)",onClick:()=>{Ne()}},me?"Save":"Saved"),e.createElement(k,{title:"Share, export",icon:"share",items:[{label:"Copy a link with the demo",icon:"link",onClick:()=>{d.link(O).then(e=>navigator.clipboard.writeText(e)).then(()=>d.say("Link copied: it opens the app with this demo."))}},{label:"Download .demo.json",icon:"download",onClick:()=>d.downloadDemo(O)},{label:"Download scenario .md",icon:"download",onClick:()=>d.downloadDemo(O,"md")},{label:"Copy JSON",icon:"copy",onClick:()=>{navigator.clipboard.writeText(JSON.stringify({...O,scenario:void 0,savedAt:void 0},null,2)).then(()=>d.say("JSON copied."))}},{label:"Narration pack (.zip): no key, no download, for every viewer",icon:"listen",onClick:()=>{d.downloadPack(O)}},he?.video&&{label:"Download the video",icon:"film",onClick:()=>d.downloadVideo(he.video,O.title)},("edited"===he?.origin||"here"===he?.origin)&&{heading:"This demo"},"edited"===he?.origin&&{label:"Revert to the app’s version",icon:"undo",onClick:()=>{window.confirm("Drop the changes kept here?")&&d.remove(O.id)}},"here"===he?.origin&&{label:"Delete",icon:"delete",onClick:()=>{window.confirm(`Delete "${O.title}"?`)&&d.remove(O.id)}}]}),e.createElement(b,{value:F,onChange:e=>{if(e!==F){if("text"===F){const e=be();if(!e)return;JSON.stringify(e)!==JSON.stringify(O)&&ve(e)}"text"===e&&(()=>{const{scenario:e,savedAt:t,...a}=O;z({json:JSON.stringify(a,null,2),scenario:O.scenario??s(O,ne)}),H(void 0)})(),P(e)}},options:[["steps","Steps"],["text","Text"],["video","Video",he?.video?"Its last video":"Not filmed yet"]]}),e.createElement(v,{icon:G?"maximize":"minimize",kind:"bare",title:G?"Unfold":"Fold",onClick:()=>Z(!G)}),e.createElement(v,{icon:"close",kind:"bare",title:"Close",onClick:()=>{me&&!window.confirm("Close without saving?")||d.closeStudio()}})),e.createElement(N,{demo:O,timing:ge,measured:ue,step:de,action:B,theme:m,accent:"#ffb300",playhead:se&&se.demo.id===O.id?()=>d.elapsed():void 0,read:e=>g(d,e),onPick:(e,t)=>{se&&se.demo.id===O.id&&d.goTo(e)||(J(e),U(t),G&&Z(!1))}}),W&&e.createElement("div",{className:"error small",style:{padding:"4px 12px"}},W),e.createElement("div",{className:"body"},"text"!==F&&e.createElement("div",{className:"steps"},e.createElement("div",{className:["step",_&&"on"].filter(Boolean).join(" "),style:{marginBottom:4},onClick:()=>{ee(!0),X(!1),U(void 0)},title:"Its title, who it is for, where it starts"},e.createElement("span",{className:"n"},"i"),e.createElement("div",{className:"col grow",style:{gap:2}},e.createElement("span",{style:{fontWeight:500}},"About this demo"),e.createElement("span",{className:"say"},O.description||"Who it is for, what it shows"))),re.map((t,a)=>e.createElement("div",{key:a,className:["step",a===ce&&!Q&&!_&&"on",se&&a===de&&"playing"].filter(Boolean).join(" "),onClick:()=>{J(a),U(void 0),X(!1),ee(!1),function(e){if("video"!==F)return;const t=he?.video?.timing?.steps.find(t=>t.step===e),a=document.querySelector("protomaze-demo-engine")?.shadowRoot?.querySelector("video");t&&a&&(a.currentTime=t.start/1e3)}(a)}},e.createElement("span",{className:"n"},a+1),e.createElement("div",{className:"col grow",style:{gap:2}},e.createElement("div",{className:"row"},e.createElement("span",{className:"grow ellipsis",style:{fontWeight:500}},t.title||function(e,t){return r(o(e,t))[0]}(t,ne)||"Untitled"),e.createElement("span",{className:"small muted"},je(a))),t.title&&e.createElement("span",{className:"say"},o(t,ne)),e.createElement("span",{className:"small muted"},t.actions.length," action",1===t.actions.length?"":"s",t.pause?" · waits":"")))),e.createElement(v,{icon:"add",small:!0,onClick:()=>{ke([...re.slice(0,ce+1),{say:{},actions:[]},...re.slice(ce+1)]),J(ce+1),X(!1)}},"New step"),e.createElement("div",{className:["step",Q&&"on"].filter(Boolean).join(" "),style:{marginTop:6},onClick:()=>{X(!0),ee(!1),U(void 0)},title:"Done after the demo, quickly and unseen, so the app is as it found it"},e.createElement("span",{className:"n"},"↺"),e.createElement("div",{className:"col grow",style:{gap:2}},e.createElement("span",{style:{fontWeight:500}},"Cleanup"),e.createElement("span",{className:"small muted"},(O.cleanup??[]).length," action",1===(O.cleanup??[]).length?"":"s"," after it, unseen")))),"steps"===F&&_&&e.createElement("div",{className:"pane"},e.createElement("strong",null,"About this demo"),e.createElement(w,{label:"Title"},e.createElement("input",{className:"field",value:O.title,onChange:e=>we({title:e.target.value})})),e.createElement(w,{label:"Description: who it is for, what it shows"},e.createElement("textarea",{className:"field",rows:3,value:O.description??"",onChange:e=>we({description:e.target.value})})),e.createElement(w,{label:"Its start: where the app is when it plays (the app's start.go)"},e.createElement(E,{value:O.start,onChange:e=>we({start:e&&"object"==typeof e?e:void 0})})),e.createElement("span",{className:"small muted"},"Id: ",e.createElement("span",{className:"mono"},O.id)," · ",re.length," steps · ",d.languagesOf(O).join(", ")||"no narration yet")),"steps"===F&&Q&&e.createElement("div",{className:"pane"},e.createElement("div",{className:"row"},e.createElement("strong",{className:"grow"},"Cleanup"),e.createElement(k,{title:"Add an action",icon:"add",label:"Add",items:h(d,e=>{we({cleanup:[...O.cleanup??[],e]}),U((O.cleanup??[]).length)})})),e.createElement("div",{className:"small muted"},"Done after the demo - when it ends, or is stopped - quickly and unseen: filters cleared, what it opened closed, what it changed changed back. So it plays again, and the next one starts where it expects. What the app cannot undo itself, its start resets (the app's ",e.createElement("span",{className:"mono"},"start.go"),")."),(O.cleanup??[]).map((t,a)=>e.createElement(p,{key:`cleanup.${a}`,engine:d,action:t,index:a,count:(O.cleanup??[]).length,open:B===a,sentences:[],onOpen:()=>U(B===a?void 0:a),onChange:e=>we({cleanup:(O.cleanup??[]).map((t,n)=>n===a?e:t)}),onMove:e=>{const t=[...O.cleanup??[]],n=a+e;n<0||n>=t.length||([t[a],t[n]]=[t[n],t[a]],we({cleanup:t}),U(n))},onDuplicate:()=>we({cleanup:[...(O.cleanup??[]).slice(0,a+1),l(t),...(O.cleanup??[]).slice(a+1)]}),onDelete:()=>{we({cleanup:(O.cleanup??[]).filter((e,t)=>t!==a)}),U(void 0)},picking:ae}))),"steps"===F&&De&&!Q&&!_&&e.createElement(e.Fragment,null,e.createElement("div",{className:"pane"},e.createElement("div",{className:"row"},e.createElement("strong",{className:"grow"},"Step ",ce+1," of ",re.length),e.createElement(v,{icon:"up",small:!0,kind:"bare",title:"Earlier",disabled:0===ce,onClick:()=>xe(-1)}),e.createElement(v,{icon:"down",small:!0,kind:"bare",title:"Later",disabled:ce===re.length-1,onClick:()=>xe(1)}),e.createElement(v,{icon:"duplicate",small:!0,kind:"bare",title:"Duplicate",onClick:()=>{ke([...re.slice(0,ce+1),l(De),...re.slice(ce+1)]),J(ce+1)}}),e.createElement(v,{icon:"delete",small:!0,kind:"bare",title:"Delete this step",disabled:re.length<2,onClick:()=>{ke(re.filter((e,t)=>t!==ce)),J(Math.max(0,ce-1))}})),e.createElement("input",{className:"field",placeholder:"Title, for the editor and the timeline",value:De.title??"",onChange:e=>ye(x(De,"title",e.target.value||void 0))}),pe.map(t=>e.createElement(S,{key:t,engine:d,language:t,text:De.say[t]??"",onChange:e=>ye({...De,say:x(De.say,t,e||void 0)})})),e.createElement("textarea",{className:"field",rows:2,placeholder:"Notes for the presenter: on their screen only, never said or shown",value:De.notes??"",onChange:e=>ye(x(De,"notes",e.target.value||void 0))}),e.createElement("div",{className:"row",style:{flexWrap:"wrap",gap:12}},e.createElement("span",{className:"small muted"},"Hold after, ms"),e.createElement(y,{value:De.hold,width:70,placeholder:"0",onChange:e=>ye(x(De,"hold",e))}),e.createElement(f,{label:"Wait for the presenter after it",checked:Boolean(De.pause),onChange:e=>ye(x(De,"pause",e||void 0))}),e.createElement("span",{className:"small muted"},je(ce)))),e.createElement("div",{className:"pane",style:{flex:1.3}},e.createElement("div",{className:"row"},e.createElement("strong",{className:"grow"},"Actions"),e.createElement("span",{className:"small muted"},"played one after the other, while the narration speaks"),e.createElement(k,{title:"Add an action",icon:"add",label:"Add",items:h(d,e=>{ye({...De,actions:[...De.actions,e]}),U(De.actions.length)})})),0===De.actions.length&&e.createElement("div",{className:"muted small"},"None yet: add one, or record them (●) by doing them on the page."),De.actions.map((t,a)=>e.createElement(p,{key:`${ce}.${a}`,engine:d,action:t,index:a,count:De.actions.length,open:B===a,error:I.get(`${ce}.${a}`),sentences:r(o(De,ne)),onOpen:()=>U(B===a?void 0:a),onChange:e=>((e,t)=>ye({...re[ce],actions:re[ce].actions.map((a,n)=>n===e?t:a)}))(a,e),onMove:e=>((e,t)=>{const a=e+t,n=[...re[ce].actions];a<0||a>=n.length||([n[e],n[a]]=[n[a],n[e]],ye({...re[ce],actions:n}),U(a))})(a,e),onDuplicate:()=>ye({...De,actions:[...De.actions.slice(0,a+1),l(t),...De.actions.slice(a+1)]}),onDelete:()=>{ye({...De,actions:De.actions.filter((e,t)=>t!==a)}),U(void 0)},picking:ae})))),"text"===F&&e.createElement("div",{className:"pane",style:{flexDirection:"row"}},e.createElement("textarea",{className:"field mono grow",spellCheck:!1,value:V.json,onChange:e=>z({...V,json:e.target.value})}),e.createElement("textarea",{className:"field mono grow",spellCheck:!1,value:V.scenario,placeholder:"The scenario, for people (.md)",onChange:e=>z({...V,scenario:e.target.value})})),"video"===F&&e.createElement(D,{engine:d,draft:O})))}function x(e,t,a){const n={...e,[t]:a};return void 0===a&&delete n[t],n}function S({engine:t,language:a,text:n,onChange:l}){const[o,s]=i(),[c,d]=i(),[p,h]=i(),g=r(n);return e.createElement("div",{className:"col",style:{gap:4}},e.createElement("div",{className:"row"},e.createElement("span",{className:"badge accent"},a),e.createElement("span",{className:"small muted grow"},g.length," sentence",1===g.length?"":"s",c?` · ${c}`:""),e.createElement(v,{icon:p?"stop":"listen",small:!0,kind:"bare",title:p?"Stop":"Listen, in the voice chosen",disabled:!n.trim(),onClick:()=>{(async()=>{if(p)return p();let e=!1,i=()=>{};h(()=>()=>{e=!0,i()}),t.speech.wake();for(const l of r(n)){if(e)break;d("Making the voice…");const n=await t.speech.say(l,a).catch(e=>{t.say(e.message,!0)});if(d(void 0),!n)break;i=n.stop,await n.done}d(void 0),h(void 0)})()}}),e.createElement(v,{icon:o?"stop":"mic",small:!0,kind:"bare",on:Boolean(o),title:o?"Stop, and write what was said":"Dictate: speak, then stop",onClick:()=>{(async()=>{if(o){s(void 0),d("Transcribing…");try{const e=(await t.transcribe(await o.stop(),a)).map(e=>e.text).join(" ").trim();e&&l([n.trim(),e].filter(Boolean).join(" "))}catch(e){t.say(e.message,!0)}d(void 0)}else try{s(await m())}catch(e){t.say(`Microphone: ${e.message}`,!0)}})()},style:o?{color:"var(--danger)"}:void 0})),e.createElement("textarea",{className:"field",rows:3,placeholder:`Narration (${a}): what the viewer should notice, a sentence a subtitle`,value:n,onChange:e=>l(e.target.value)}))}function D({engine:n,draft:i}){const l=n.entriesNow().find(e=>e.demo.id===i.id),o=l?.video,s=a(()=>o&&{video:URL.createObjectURL(o.blob),vtt:URL.createObjectURL(new Blob([o.vtt],{type:"text/vtt"}))},[o]);if(t(()=>()=>{s&&(URL.revokeObjectURL(s.video),URL.revokeObjectURL(s.vtt))},[s]),!o||!s)return e.createElement("div",{className:"pane muted"},"Not filmed yet: film it (the film button) to make a video with narration and subtitles, kept here.");const r=o.json!==JSON.stringify({...i,scenario:void 0,savedAt:void 0})&&o.json!==JSON.stringify(i);return e.createElement("div",{className:"pane",style:{flexDirection:"row"}},e.createElement("div",{className:"grow",style:{minHeight:0,display:"flex"}},e.createElement("video",{src:s.video,controls:!0,style:{maxHeight:"100%"}},e.createElement("track",{kind:"subtitles",src:s.vtt,srcLang:o.language??"en",label:"Narration",default:!0}))),e.createElement("div",{className:"col",style:{width:240}},e.createElement("span",{className:"small muted"},new Date(o.at).toLocaleString()," · ",Math.round(o.blob.size/1e5)/10," MB · ",o.blob.type.split(";")[0]),r&&e.createElement("span",{className:"small error"},"Filmed from an older version of the demo."),e.createElement(v,{icon:"download",onClick:()=>n.downloadVideo(o,i.title)},"Video"),e.createElement(v,{icon:"subtitles",onClick:()=>n.downloadVideo(o,i.title,"vtt")},"Subtitles .vtt"),e.createElement(v,{icon:"subtitles",onClick:()=>n.downloadVideo(o,i.title,"srt")},"Subtitles .srt"),e.createElement(v,{icon:"share",onClick:()=>{n.shareVideo(o,i.title).then(e=>!e&&n.say("No share sheet here: download it instead."))}},"Share…"),o.voice&&e.createElement(v,{icon:"download",onClick:()=>n.downloadVideo({...o,blob:o.voice},`${i.title} voice`)},"The presenter's voice"),e.createElement(v,{icon:"delete",kind:"danger",onClick:()=>{n.store.deleteVideo(o.id)}},"Delete the video"),e.createElement("span",{className:"small muted"},d(i.title,o.blob.type.includes("mp4")?"mp4":"webm"))))}
package/ui/Styles.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  /** The engine's UI: one stylesheet in its shadow roots, themed by `data-theme` on `.pde`. */
2
- export declare const UI_CSS = "\n.pde { --bg: #17181c; --panel: #1f2026; --raised: #2a2c33; --line: #3a3c45; --fg: #e9eaee; --muted: #9a9caa; --accent: #ffb300;\n --accent-fg: #1a1200; --danger: #ff5a5f; --ok: #3ecf8e; --focus: #7aa7ff; --shadow: 0 10px 40px rgba(0,0,0,.45);\n font: 13px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; color: var(--fg); box-sizing: border-box; }\n.pde[data-theme=\"light\"] { --bg: #f6f6f8; --panel: #ffffff; --raised: #eef0f4; --line: #d6d8de; --fg: #1b1c20; --muted: #6a6c78;\n --accent: #e09b00; --accent-fg: #1a1200; --shadow: 0 10px 40px rgba(0,0,0,.18); }\n.pde *, .pde *::before, .pde *::after { box-sizing: border-box; }\n.pde button, .pde input, .pde textarea, .pde select { font: inherit; color: inherit; }\n.pde :focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }\n.pde ::-webkit-scrollbar { width: 10px; height: 10px; }\n.pde ::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; border: 2px solid transparent; background-clip: padding-box; }\n\n.pde .row { display: flex; align-items: center; gap: 6px; min-width: 0; }\n.pde .col { display: flex; flex-direction: column; gap: 6px; min-width: 0; }\n.pde .grow { flex: 1; min-width: 0; }\n.pde .muted { color: var(--muted); }\n.pde .small { font-size: 12px; }\n.pde .mono { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; font-size: 12px; }\n.pde .error { color: var(--danger); }\n.pde .ok { color: var(--ok); }\n.pde .ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.pde .sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 4px; }\n.pde .badge { padding: 1px 6px; border-radius: 9px; background: var(--raised); color: var(--muted); font-size: 11px; white-space: nowrap; }\n.pde .badge.accent { background: color-mix(in srgb, var(--accent) 25%, transparent); color: var(--fg); }\n\n.pde .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 6px;\n border: 1px solid var(--line); background: var(--raised); cursor: pointer; white-space: nowrap; user-select: none; }\n.pde .btn:hover:not(:disabled) { border-color: var(--muted); }\n.pde .btn:disabled { opacity: .45; cursor: default; }\n.pde .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }\n.pde .btn.danger { color: var(--danger); }\n.pde .btn.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }\n.pde .icon { width: 28px; padding: 0; }\n.pde .icon.bare { border-color: transparent; background: transparent; }\n.pde .icon.bare:hover:not(:disabled) { background: var(--raised); border-color: transparent; }\n.pde .icon.small { width: 22px; height: 22px; }\n.pde svg.i { width: 18px; height: 18px; fill: currentColor; flex: none; }\n.pde .small svg.i, .pde .icon.small svg.i { width: 15px; height: 15px; }\n\n.pde .field { height: 28px; padding: 0 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); min-width: 0; }\n.pde textarea.field { height: auto; padding: 6px 8px; resize: vertical; min-height: 54px; line-height: 1.45; }\n.pde select.field { padding-right: 4px; }\n.pde .field:hover { border-color: var(--muted); }\n.pde .field.wrong { border-color: var(--danger); }\n.pde label.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; }\n.pde label.check input { accent-color: var(--accent); margin: 0; }\n.pde .labelled { display: flex; flex-direction: column; gap: 2px; min-width: 0; }\n.pde .labelled > span { font-size: 11px; color: var(--muted); }\n\n.pde .menu { position: absolute; z-index: 10; min-width: 200px; padding: 4px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line);\n box-shadow: var(--shadow); display: flex; flex-direction: column; }\n.pde .menu .item { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 5px; cursor: pointer; border: 0; background: none; text-align: left; white-space: nowrap; }\n.pde .menu .item:hover:not(:disabled) { background: var(--raised); }\n.pde .menu .item:disabled { opacity: .45; cursor: default; }\n.pde .menu .heading { padding: 6px 10px 2px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }\n\n/* Bars over the app while playing and recording */\n.pde.bar { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 14px;\n border-radius: 999px; background: var(--panel); box-shadow: var(--shadow); pointer-events: auto; white-space: nowrap; max-width: calc(100vw - 32px); }\n.pde .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1.2s ease-in-out infinite; flex: none; }\n@keyframes blink { 50% { opacity: .35; } }\n.pde.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: min(720px, calc(100vw - 32px)); padding: 10px 12px 10px 16px;\n border-radius: 10px; background: var(--panel); box-shadow: var(--shadow); pointer-events: auto; display: flex; gap: 10px; align-items: center; }\n.pde.toast.error { border-left: 4px solid var(--danger); }\n.pde.ready { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.45); pointer-events: auto; }\n.pde.ready .box { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 28px 32px; border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); max-width: 440px; text-align: center; }\n.pde.ready .btn.primary { height: 44px; padding: 0 22px; font-size: 16px; border-radius: 22px; }\n\n/* The launcher and floating library */\n.pde.launcher { position: fixed; left: 16px; bottom: 16px; pointer-events: auto; }\n.pde.launcher > .btn { height: 36px; border-radius: 18px; padding: 0 14px; box-shadow: var(--shadow); }\n.pde.floating { position: fixed; left: 16px; bottom: 60px; width: min(440px, calc(100vw - 32px)); max-height: min(72vh, 760px); overflow: auto;\n border-radius: 12px; background: var(--panel); box-shadow: var(--shadow); pointer-events: auto; border: 1px solid var(--line); }\n\n/* The library */\n.pde.library { display: flex; flex-direction: column; gap: 10px; padding: 12px; background: var(--panel); }\n.pde .section { display: flex; flex-direction: column; gap: 8px; }\n.pde .section > h3 { margin: 0; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }\n.pde .demo { display: flex; flex-direction: column; gap: 4px; padding: 8px 10px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); position: relative; }\n.pde .demo .title { font-weight: 600; }\n.pde .segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; flex-wrap: wrap; }\n.pde .segmented button { border: 0; border-right: 1px solid var(--line); background: var(--bg); padding: 4px 10px; cursor: pointer; display: inline-flex; gap: 5px; align-items: center; }\n.pde .segmented button:last-child { border-right: 0; }\n.pde .segmented button.on { background: var(--raised); box-shadow: inset 0 -2px 0 var(--accent); }\n.pde .progress { height: 4px; border-radius: 2px; background: var(--raised); overflow: hidden; }\n.pde .progress > div { height: 100%; background: var(--accent); transition: width 200ms; }\n\n/* The studio */\n.pde.studio { position: fixed; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; background: var(--panel); pointer-events: auto;\n box-shadow: 0 -8px 30px rgba(0,0,0,.35); border-top: 1px solid var(--line); }\n.pde.studio .grip { position: absolute; top: -4px; left: 0; right: 0; height: 8px; cursor: ns-resize; }\n.pde.studio .head { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }\n.pde.studio .timeline { position: relative; height: 150px; flex: none; border-bottom: 1px solid var(--line); background: var(--bg); }\n.pde.studio .timeline .lanes { position: absolute; left: 0; top: 0; bottom: 0; width: 104px; font-size: 11px; color: var(--muted); pointer-events: none; z-index: 2; }\n.pde.studio .timeline .lanes > div { position: absolute; right: 10px; }\n.pde.studio .timeline .slider { position: absolute; left: 104px; right: 0; top: 0; bottom: 0; }\n.pde.studio .timeline .clock { position: absolute; left: 6px; bottom: 5px; z-index: 3; font: 600 10px ui-monospace, monospace; white-space: nowrap; }\n.pde.studio .body { display: flex; flex: 1; min-height: 0; }\n.pde.studio .steps { width: 260px; flex: none; overflow: auto; border-right: 1px solid var(--line); padding: 6px; display: flex; flex-direction: column; gap: 4px; }\n.pde.studio .step { display: flex; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; align-items: flex-start; }\n.pde.studio .step:hover { background: var(--raised); }\n.pde.studio .step.on { background: var(--raised); border-color: var(--accent); }\n.pde.studio .step.playing { box-shadow: inset 3px 0 0 var(--ok); }\n.pde.studio .step .n { font: 600 12px ui-monospace, monospace; color: var(--muted); width: 20px; flex: none; padding-top: 1px; }\n.pde.studio .step .say { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--muted); font-size: 12px; }\n.pde.studio .pane { flex: 1; min-width: 0; overflow: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; }\n.pde.studio .pane + .pane { border-left: 1px solid var(--line); }\n.pde.studio .action { border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }\n.pde.studio .action.on { border-color: var(--accent); }\n.pde.studio .action.failed { border-color: var(--danger); }\n.pde.studio .action > .row { padding: 4px 6px; }\n.pde.studio .action .kind { font: 600 11px ui-monospace, monospace; padding: 2px 6px; border-radius: 4px; background: var(--raised); flex: none; }\n.pde.studio .action .kind.present { background: color-mix(in srgb, var(--accent) 22%, transparent); }\n.pde.studio .action .details { padding: 8px 10px 10px; border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }\n.pde.studio .action .details .wide { grid-column: 1 / -1; }\n.pde.studio .collapsed .body, .pde.studio .collapsed .grip { display: none; }\n.pde.studio video { width: 100%; max-height: 100%; background: #000; border-radius: 6px; }\n";
2
+ export declare const UI_CSS = "\n.pde { --bg: #17181c; --panel: #1f2026; --raised: #2a2c33; --line: #3a3c45; --fg: #e9eaee; --muted: #9a9caa; --accent: #ffb300;\n --accent-fg: #1a1200; --danger: #ff5a5f; --ok: #3ecf8e; --focus: #7aa7ff; --shadow: 0 10px 40px rgba(0,0,0,.45);\n font: 13px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; color: var(--fg); box-sizing: border-box; }\n.pde[data-theme=\"light\"] { --bg: #f6f6f8; --panel: #ffffff; --raised: #eef0f4; --line: #d6d8de; --fg: #1b1c20; --muted: #6a6c78;\n --accent: #e09b00; --accent-fg: #1a1200; --shadow: 0 10px 40px rgba(0,0,0,.18); }\n.pde *, .pde *::before, .pde *::after { box-sizing: border-box; }\n.pde button, .pde input, .pde textarea, .pde select { font: inherit; color: inherit; }\n.pde :focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }\n.pde ::-webkit-scrollbar { width: 10px; height: 10px; }\n.pde ::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; border: 2px solid transparent; background-clip: padding-box; }\n\n.pde .row { display: flex; align-items: center; gap: 6px; min-width: 0; }\n.pde .col { display: flex; flex-direction: column; gap: 6px; min-width: 0; }\n.pde .grow { flex: 1; min-width: 0; }\n.pde .muted { color: var(--muted); }\n.pde .small { font-size: 12px; }\n.pde .mono { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; font-size: 12px; }\n.pde .error { color: var(--danger); }\n.pde .ok { color: var(--ok); }\n.pde .ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.pde .sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 4px; }\n.pde .badge { padding: 1px 6px; border-radius: 9px; background: var(--raised); color: var(--muted); font-size: 11px; white-space: nowrap; }\n.pde .badge.accent { background: color-mix(in srgb, var(--accent) 25%, transparent); color: var(--fg); }\n\n.pde .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 6px;\n border: 1px solid var(--line); background: var(--raised); cursor: pointer; white-space: nowrap; user-select: none; }\n.pde .btn:hover:not(:disabled) { border-color: var(--muted); }\n.pde .btn:disabled { opacity: .45; cursor: default; }\n.pde .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }\n.pde .btn.danger { color: var(--danger); }\n.pde .btn.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }\n.pde .icon { width: 28px; padding: 0; }\n.pde .icon.bare { border-color: transparent; background: transparent; }\n.pde .icon.bare:hover:not(:disabled) { background: var(--raised); border-color: transparent; }\n.pde .icon.small { width: 22px; height: 22px; }\n.pde svg.i { width: 18px; height: 18px; fill: currentColor; flex: none; }\n.pde .small svg.i, .pde .icon.small svg.i { width: 15px; height: 15px; }\n\n.pde .field { height: 28px; padding: 0 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); min-width: 0; }\n.pde textarea.field { height: auto; padding: 6px 8px; resize: vertical; min-height: 54px; line-height: 1.45; }\n.pde select.field { padding-right: 4px; }\n.pde .field:hover { border-color: var(--muted); }\n.pde .field.wrong { border-color: var(--danger); }\n.pde label.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; }\n.pde label.check input { accent-color: var(--accent); margin: 0; }\n.pde .labelled { display: flex; flex-direction: column; gap: 2px; min-width: 0; }\n.pde .labelled > span { font-size: 11px; color: var(--muted); }\n\n.pde .menu { position: absolute; z-index: 10; min-width: 200px; padding: 4px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line);\n box-shadow: var(--shadow); display: flex; flex-direction: column; }\n.pde .menu .item { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 5px; cursor: pointer; border: 0; background: none; text-align: left; white-space: nowrap; }\n.pde .menu .item:hover:not(:disabled) { background: var(--raised); }\n.pde .menu .item:disabled { opacity: .45; cursor: default; }\n.pde .menu .heading { padding: 6px 10px 2px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }\n\n/* Bars over the app while playing and recording */\n.pde.bar { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 14px;\n border-radius: 999px; background: var(--panel); box-shadow: var(--shadow); pointer-events: auto; white-space: nowrap; max-width: calc(100vw - 32px); }\n.pde .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1.2s ease-in-out infinite; flex: none; }\n@keyframes blink { 50% { opacity: .35; } }\n.pde.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: min(720px, calc(100vw - 32px)); padding: 10px 12px 10px 16px;\n border-radius: 10px; background: var(--panel); box-shadow: var(--shadow); pointer-events: auto; display: flex; gap: 10px; align-items: center; }\n.pde.toast.error { border-left: 4px solid var(--danger); }\n.pde.ready { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.45); pointer-events: auto; }\n.pde.ready .box { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 28px 32px; border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); max-width: 440px; text-align: center; }\n.pde.ready .btn.primary { height: 44px; padding: 0 22px; font-size: 16px; border-radius: 22px; }\n\n/* The launcher and floating library */\n.pde.launcher { position: fixed; left: 16px; bottom: 16px; pointer-events: auto; }\n.pde.launcher > .btn { height: 36px; border-radius: 18px; padding: 0 14px; box-shadow: var(--shadow); }\n.pde.floating { position: fixed; left: 16px; bottom: 60px; width: min(440px, calc(100vw - 32px)); max-height: min(72vh, 760px); overflow: auto;\n border-radius: 12px; background: var(--panel); box-shadow: var(--shadow); pointer-events: auto; border: 1px solid var(--line); }\n\n/* Dialogs: what starting something asks */\n.pde.dialog-backdrop { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.45); pointer-events: auto; padding: 16px; }\n.pde .dialog { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; display: flex; flex-direction: column; gap: 16px; padding: 18px 20px;\n border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); border: 1px solid var(--line); }\n.pde h2 { margin: 0; font-size: 16px; font-weight: 600; }\n.pde .choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 8px; }\n.pde .choice { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 10px; border-radius: 10px; border: 1px solid var(--line);\n background: var(--bg); cursor: pointer; text-align: left; }\n.pde .choice.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }\n.pde .qr { width: 180px; height: 180px; flex: none; border-radius: 8px; overflow: hidden; background: #fff; display: flex; align-items: center; justify-content: center; }\n.pde .qr svg { width: 100%; height: 100%; }\n.pde .dialog.wide { width: min(960px, 100%); }\n.pde .demo .video-line { border-top: 1px solid var(--line); padding-top: 6px; margin-top: 2px; gap: 6px; }\n.pde .look svg.i { width: 15px; height: 15px; opacity: .8; }\n\n/* The library */\n.pde.library { display: flex; flex-direction: column; gap: 10px; padding: 12px; background: var(--panel); }\n.pde .section { display: flex; flex-direction: column; gap: 8px; }\n.pde .section > h3 { margin: 0; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }\n.pde .demo { display: flex; flex-direction: column; gap: 4px; padding: 8px 10px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); position: relative; }\n.pde .demo .title { font-weight: 600; }\n.pde .segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; flex-wrap: wrap; }\n.pde .segmented button { border: 0; border-right: 1px solid var(--line); background: var(--bg); padding: 4px 10px; cursor: pointer; display: inline-flex; gap: 5px; align-items: center; }\n.pde .segmented button:last-child { border-right: 0; }\n.pde .segmented button.on { background: var(--raised); box-shadow: inset 0 -2px 0 var(--accent); }\n.pde .progress { height: 4px; border-radius: 2px; background: var(--raised); overflow: hidden; }\n.pde .progress > div { height: 100%; background: var(--accent); transition: width 200ms; }\n\n/* The studio */\n.pde.studio { position: fixed; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; background: var(--panel); pointer-events: auto;\n box-shadow: 0 -8px 30px rgba(0,0,0,.35); border-top: 1px solid var(--line); }\n.pde.studio .grip { position: absolute; top: -4px; left: 0; right: 0; height: 8px; cursor: ns-resize; }\n.pde.studio .head { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }\n.pde.studio .head .field.title { width: min(320px, 30vw); font-weight: 600; }\n.pde.studio .timeline { position: relative; height: 150px; flex: none; border-bottom: 1px solid var(--line); background: var(--bg); }\n.pde.studio .timeline .lanes { position: absolute; left: 0; top: 0; bottom: 0; width: 104px; font-size: 11px; color: var(--muted); pointer-events: none; z-index: 2; }\n.pde.studio .timeline .lanes > div { position: absolute; right: 10px; }\n.pde.studio .timeline .slider { position: absolute; left: 104px; right: 0; top: 0; bottom: 0; }\n.pde.studio .timeline .clock { position: absolute; left: 6px; bottom: 5px; z-index: 3; font: 600 10px ui-monospace, monospace; white-space: nowrap; }\n.pde.studio .body { display: flex; flex: 1; min-height: 0; }\n.pde.studio .steps { width: 260px; flex: none; overflow: auto; border-right: 1px solid var(--line); padding: 6px; display: flex; flex-direction: column; gap: 4px; }\n.pde.studio .step { display: flex; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; align-items: flex-start; }\n.pde.studio .step:hover { background: var(--raised); }\n.pde.studio .step.on { background: var(--raised); border-color: var(--accent); }\n.pde.studio .step.playing { box-shadow: inset 3px 0 0 var(--ok); }\n.pde.studio .step .n { font: 600 12px ui-monospace, monospace; color: var(--muted); width: 20px; flex: none; padding-top: 1px; }\n.pde.studio .step .say { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--muted); font-size: 12px; }\n.pde.studio .pane { flex: 1; min-width: 0; overflow: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; }\n.pde.studio .pane + .pane { border-left: 1px solid var(--line); }\n.pde.studio .action { border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }\n.pde.studio .action.on { border-color: var(--accent); }\n.pde.studio .action.failed { border-color: var(--danger); }\n.pde.studio .action > .row { padding: 4px 6px; }\n.pde.studio .action .kind { font: 600 11px ui-monospace, monospace; padding: 2px 6px; border-radius: 4px; background: var(--raised); flex: none; }\n.pde.studio .action .kind.present { background: color-mix(in srgb, var(--accent) 22%, transparent); }\n.pde.studio .action .details { padding: 8px 10px 10px; border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }\n.pde.studio .action .details .wide { grid-column: 1 / -1; }\n.pde.studio .collapsed .body, .pde.studio .collapsed .grip { display: none; }\n.pde.studio video { width: 100%; max-height: 100%; background: #000; border-radius: 6px; }\n";
package/ui/Styles.js CHANGED
@@ -1 +1 @@
1
- export const UI_CSS="\n.pde { --bg: #17181c; --panel: #1f2026; --raised: #2a2c33; --line: #3a3c45; --fg: #e9eaee; --muted: #9a9caa; --accent: #ffb300;\n --accent-fg: #1a1200; --danger: #ff5a5f; --ok: #3ecf8e; --focus: #7aa7ff; --shadow: 0 10px 40px rgba(0,0,0,.45);\n font: 13px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; color: var(--fg); box-sizing: border-box; }\n.pde[data-theme=\"light\"] { --bg: #f6f6f8; --panel: #ffffff; --raised: #eef0f4; --line: #d6d8de; --fg: #1b1c20; --muted: #6a6c78;\n --accent: #e09b00; --accent-fg: #1a1200; --shadow: 0 10px 40px rgba(0,0,0,.18); }\n.pde *, .pde *::before, .pde *::after { box-sizing: border-box; }\n.pde button, .pde input, .pde textarea, .pde select { font: inherit; color: inherit; }\n.pde :focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }\n.pde ::-webkit-scrollbar { width: 10px; height: 10px; }\n.pde ::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; border: 2px solid transparent; background-clip: padding-box; }\n\n.pde .row { display: flex; align-items: center; gap: 6px; min-width: 0; }\n.pde .col { display: flex; flex-direction: column; gap: 6px; min-width: 0; }\n.pde .grow { flex: 1; min-width: 0; }\n.pde .muted { color: var(--muted); }\n.pde .small { font-size: 12px; }\n.pde .mono { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; font-size: 12px; }\n.pde .error { color: var(--danger); }\n.pde .ok { color: var(--ok); }\n.pde .ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.pde .sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 4px; }\n.pde .badge { padding: 1px 6px; border-radius: 9px; background: var(--raised); color: var(--muted); font-size: 11px; white-space: nowrap; }\n.pde .badge.accent { background: color-mix(in srgb, var(--accent) 25%, transparent); color: var(--fg); }\n\n.pde .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 6px;\n border: 1px solid var(--line); background: var(--raised); cursor: pointer; white-space: nowrap; user-select: none; }\n.pde .btn:hover:not(:disabled) { border-color: var(--muted); }\n.pde .btn:disabled { opacity: .45; cursor: default; }\n.pde .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }\n.pde .btn.danger { color: var(--danger); }\n.pde .btn.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }\n.pde .icon { width: 28px; padding: 0; }\n.pde .icon.bare { border-color: transparent; background: transparent; }\n.pde .icon.bare:hover:not(:disabled) { background: var(--raised); border-color: transparent; }\n.pde .icon.small { width: 22px; height: 22px; }\n.pde svg.i { width: 18px; height: 18px; fill: currentColor; flex: none; }\n.pde .small svg.i, .pde .icon.small svg.i { width: 15px; height: 15px; }\n\n.pde .field { height: 28px; padding: 0 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); min-width: 0; }\n.pde textarea.field { height: auto; padding: 6px 8px; resize: vertical; min-height: 54px; line-height: 1.45; }\n.pde select.field { padding-right: 4px; }\n.pde .field:hover { border-color: var(--muted); }\n.pde .field.wrong { border-color: var(--danger); }\n.pde label.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; }\n.pde label.check input { accent-color: var(--accent); margin: 0; }\n.pde .labelled { display: flex; flex-direction: column; gap: 2px; min-width: 0; }\n.pde .labelled > span { font-size: 11px; color: var(--muted); }\n\n.pde .menu { position: absolute; z-index: 10; min-width: 200px; padding: 4px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line);\n box-shadow: var(--shadow); display: flex; flex-direction: column; }\n.pde .menu .item { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 5px; cursor: pointer; border: 0; background: none; text-align: left; white-space: nowrap; }\n.pde .menu .item:hover:not(:disabled) { background: var(--raised); }\n.pde .menu .item:disabled { opacity: .45; cursor: default; }\n.pde .menu .heading { padding: 6px 10px 2px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }\n\n/* Bars over the app while playing and recording */\n.pde.bar { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 14px;\n border-radius: 999px; background: var(--panel); box-shadow: var(--shadow); pointer-events: auto; white-space: nowrap; max-width: calc(100vw - 32px); }\n.pde .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1.2s ease-in-out infinite; flex: none; }\n@keyframes blink { 50% { opacity: .35; } }\n.pde.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: min(720px, calc(100vw - 32px)); padding: 10px 12px 10px 16px;\n border-radius: 10px; background: var(--panel); box-shadow: var(--shadow); pointer-events: auto; display: flex; gap: 10px; align-items: center; }\n.pde.toast.error { border-left: 4px solid var(--danger); }\n.pde.ready { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.45); pointer-events: auto; }\n.pde.ready .box { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 28px 32px; border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); max-width: 440px; text-align: center; }\n.pde.ready .btn.primary { height: 44px; padding: 0 22px; font-size: 16px; border-radius: 22px; }\n\n/* The launcher and floating library */\n.pde.launcher { position: fixed; left: 16px; bottom: 16px; pointer-events: auto; }\n.pde.launcher > .btn { height: 36px; border-radius: 18px; padding: 0 14px; box-shadow: var(--shadow); }\n.pde.floating { position: fixed; left: 16px; bottom: 60px; width: min(440px, calc(100vw - 32px)); max-height: min(72vh, 760px); overflow: auto;\n border-radius: 12px; background: var(--panel); box-shadow: var(--shadow); pointer-events: auto; border: 1px solid var(--line); }\n\n/* The library */\n.pde.library { display: flex; flex-direction: column; gap: 10px; padding: 12px; background: var(--panel); }\n.pde .section { display: flex; flex-direction: column; gap: 8px; }\n.pde .section > h3 { margin: 0; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }\n.pde .demo { display: flex; flex-direction: column; gap: 4px; padding: 8px 10px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); position: relative; }\n.pde .demo .title { font-weight: 600; }\n.pde .segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; flex-wrap: wrap; }\n.pde .segmented button { border: 0; border-right: 1px solid var(--line); background: var(--bg); padding: 4px 10px; cursor: pointer; display: inline-flex; gap: 5px; align-items: center; }\n.pde .segmented button:last-child { border-right: 0; }\n.pde .segmented button.on { background: var(--raised); box-shadow: inset 0 -2px 0 var(--accent); }\n.pde .progress { height: 4px; border-radius: 2px; background: var(--raised); overflow: hidden; }\n.pde .progress > div { height: 100%; background: var(--accent); transition: width 200ms; }\n\n/* The studio */\n.pde.studio { position: fixed; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; background: var(--panel); pointer-events: auto;\n box-shadow: 0 -8px 30px rgba(0,0,0,.35); border-top: 1px solid var(--line); }\n.pde.studio .grip { position: absolute; top: -4px; left: 0; right: 0; height: 8px; cursor: ns-resize; }\n.pde.studio .head { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }\n.pde.studio .timeline { position: relative; height: 150px; flex: none; border-bottom: 1px solid var(--line); background: var(--bg); }\n.pde.studio .timeline .lanes { position: absolute; left: 0; top: 0; bottom: 0; width: 104px; font-size: 11px; color: var(--muted); pointer-events: none; z-index: 2; }\n.pde.studio .timeline .lanes > div { position: absolute; right: 10px; }\n.pde.studio .timeline .slider { position: absolute; left: 104px; right: 0; top: 0; bottom: 0; }\n.pde.studio .timeline .clock { position: absolute; left: 6px; bottom: 5px; z-index: 3; font: 600 10px ui-monospace, monospace; white-space: nowrap; }\n.pde.studio .body { display: flex; flex: 1; min-height: 0; }\n.pde.studio .steps { width: 260px; flex: none; overflow: auto; border-right: 1px solid var(--line); padding: 6px; display: flex; flex-direction: column; gap: 4px; }\n.pde.studio .step { display: flex; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; align-items: flex-start; }\n.pde.studio .step:hover { background: var(--raised); }\n.pde.studio .step.on { background: var(--raised); border-color: var(--accent); }\n.pde.studio .step.playing { box-shadow: inset 3px 0 0 var(--ok); }\n.pde.studio .step .n { font: 600 12px ui-monospace, monospace; color: var(--muted); width: 20px; flex: none; padding-top: 1px; }\n.pde.studio .step .say { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--muted); font-size: 12px; }\n.pde.studio .pane { flex: 1; min-width: 0; overflow: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; }\n.pde.studio .pane + .pane { border-left: 1px solid var(--line); }\n.pde.studio .action { border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }\n.pde.studio .action.on { border-color: var(--accent); }\n.pde.studio .action.failed { border-color: var(--danger); }\n.pde.studio .action > .row { padding: 4px 6px; }\n.pde.studio .action .kind { font: 600 11px ui-monospace, monospace; padding: 2px 6px; border-radius: 4px; background: var(--raised); flex: none; }\n.pde.studio .action .kind.present { background: color-mix(in srgb, var(--accent) 22%, transparent); }\n.pde.studio .action .details { padding: 8px 10px 10px; border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }\n.pde.studio .action .details .wide { grid-column: 1 / -1; }\n.pde.studio .collapsed .body, .pde.studio .collapsed .grip { display: none; }\n.pde.studio video { width: 100%; max-height: 100%; background: #000; border-radius: 6px; }\n";
1
+ export const UI_CSS="\n.pde { --bg: #17181c; --panel: #1f2026; --raised: #2a2c33; --line: #3a3c45; --fg: #e9eaee; --muted: #9a9caa; --accent: #ffb300;\n --accent-fg: #1a1200; --danger: #ff5a5f; --ok: #3ecf8e; --focus: #7aa7ff; --shadow: 0 10px 40px rgba(0,0,0,.45);\n font: 13px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; color: var(--fg); box-sizing: border-box; }\n.pde[data-theme=\"light\"] { --bg: #f6f6f8; --panel: #ffffff; --raised: #eef0f4; --line: #d6d8de; --fg: #1b1c20; --muted: #6a6c78;\n --accent: #e09b00; --accent-fg: #1a1200; --shadow: 0 10px 40px rgba(0,0,0,.18); }\n.pde *, .pde *::before, .pde *::after { box-sizing: border-box; }\n.pde button, .pde input, .pde textarea, .pde select { font: inherit; color: inherit; }\n.pde :focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }\n.pde ::-webkit-scrollbar { width: 10px; height: 10px; }\n.pde ::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; border: 2px solid transparent; background-clip: padding-box; }\n\n.pde .row { display: flex; align-items: center; gap: 6px; min-width: 0; }\n.pde .col { display: flex; flex-direction: column; gap: 6px; min-width: 0; }\n.pde .grow { flex: 1; min-width: 0; }\n.pde .muted { color: var(--muted); }\n.pde .small { font-size: 12px; }\n.pde .mono { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; font-size: 12px; }\n.pde .error { color: var(--danger); }\n.pde .ok { color: var(--ok); }\n.pde .ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.pde .sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 4px; }\n.pde .badge { padding: 1px 6px; border-radius: 9px; background: var(--raised); color: var(--muted); font-size: 11px; white-space: nowrap; }\n.pde .badge.accent { background: color-mix(in srgb, var(--accent) 25%, transparent); color: var(--fg); }\n\n.pde .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 6px;\n border: 1px solid var(--line); background: var(--raised); cursor: pointer; white-space: nowrap; user-select: none; }\n.pde .btn:hover:not(:disabled) { border-color: var(--muted); }\n.pde .btn:disabled { opacity: .45; cursor: default; }\n.pde .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }\n.pde .btn.danger { color: var(--danger); }\n.pde .btn.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }\n.pde .icon { width: 28px; padding: 0; }\n.pde .icon.bare { border-color: transparent; background: transparent; }\n.pde .icon.bare:hover:not(:disabled) { background: var(--raised); border-color: transparent; }\n.pde .icon.small { width: 22px; height: 22px; }\n.pde svg.i { width: 18px; height: 18px; fill: currentColor; flex: none; }\n.pde .small svg.i, .pde .icon.small svg.i { width: 15px; height: 15px; }\n\n.pde .field { height: 28px; padding: 0 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); min-width: 0; }\n.pde textarea.field { height: auto; padding: 6px 8px; resize: vertical; min-height: 54px; line-height: 1.45; }\n.pde select.field { padding-right: 4px; }\n.pde .field:hover { border-color: var(--muted); }\n.pde .field.wrong { border-color: var(--danger); }\n.pde label.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; }\n.pde label.check input { accent-color: var(--accent); margin: 0; }\n.pde .labelled { display: flex; flex-direction: column; gap: 2px; min-width: 0; }\n.pde .labelled > span { font-size: 11px; color: var(--muted); }\n\n.pde .menu { position: absolute; z-index: 10; min-width: 200px; padding: 4px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line);\n box-shadow: var(--shadow); display: flex; flex-direction: column; }\n.pde .menu .item { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 5px; cursor: pointer; border: 0; background: none; text-align: left; white-space: nowrap; }\n.pde .menu .item:hover:not(:disabled) { background: var(--raised); }\n.pde .menu .item:disabled { opacity: .45; cursor: default; }\n.pde .menu .heading { padding: 6px 10px 2px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }\n\n/* Bars over the app while playing and recording */\n.pde.bar { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 14px;\n border-radius: 999px; background: var(--panel); box-shadow: var(--shadow); pointer-events: auto; white-space: nowrap; max-width: calc(100vw - 32px); }\n.pde .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1.2s ease-in-out infinite; flex: none; }\n@keyframes blink { 50% { opacity: .35; } }\n.pde.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: min(720px, calc(100vw - 32px)); padding: 10px 12px 10px 16px;\n border-radius: 10px; background: var(--panel); box-shadow: var(--shadow); pointer-events: auto; display: flex; gap: 10px; align-items: center; }\n.pde.toast.error { border-left: 4px solid var(--danger); }\n.pde.ready { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.45); pointer-events: auto; }\n.pde.ready .box { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 28px 32px; border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); max-width: 440px; text-align: center; }\n.pde.ready .btn.primary { height: 44px; padding: 0 22px; font-size: 16px; border-radius: 22px; }\n\n/* The launcher and floating library */\n.pde.launcher { position: fixed; left: 16px; bottom: 16px; pointer-events: auto; }\n.pde.launcher > .btn { height: 36px; border-radius: 18px; padding: 0 14px; box-shadow: var(--shadow); }\n.pde.floating { position: fixed; left: 16px; bottom: 60px; width: min(440px, calc(100vw - 32px)); max-height: min(72vh, 760px); overflow: auto;\n border-radius: 12px; background: var(--panel); box-shadow: var(--shadow); pointer-events: auto; border: 1px solid var(--line); }\n\n/* Dialogs: what starting something asks */\n.pde.dialog-backdrop { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.45); pointer-events: auto; padding: 16px; }\n.pde .dialog { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; display: flex; flex-direction: column; gap: 16px; padding: 18px 20px;\n border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); border: 1px solid var(--line); }\n.pde h2 { margin: 0; font-size: 16px; font-weight: 600; }\n.pde .choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 8px; }\n.pde .choice { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 10px; border-radius: 10px; border: 1px solid var(--line);\n background: var(--bg); cursor: pointer; text-align: left; }\n.pde .choice.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }\n.pde .qr { width: 180px; height: 180px; flex: none; border-radius: 8px; overflow: hidden; background: #fff; display: flex; align-items: center; justify-content: center; }\n.pde .qr svg { width: 100%; height: 100%; }\n.pde .dialog.wide { width: min(960px, 100%); }\n.pde .demo .video-line { border-top: 1px solid var(--line); padding-top: 6px; margin-top: 2px; gap: 6px; }\n.pde .look svg.i { width: 15px; height: 15px; opacity: .8; }\n\n/* The library */\n.pde.library { display: flex; flex-direction: column; gap: 10px; padding: 12px; background: var(--panel); }\n.pde .section { display: flex; flex-direction: column; gap: 8px; }\n.pde .section > h3 { margin: 0; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }\n.pde .demo { display: flex; flex-direction: column; gap: 4px; padding: 8px 10px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); position: relative; }\n.pde .demo .title { font-weight: 600; }\n.pde .segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; flex-wrap: wrap; }\n.pde .segmented button { border: 0; border-right: 1px solid var(--line); background: var(--bg); padding: 4px 10px; cursor: pointer; display: inline-flex; gap: 5px; align-items: center; }\n.pde .segmented button:last-child { border-right: 0; }\n.pde .segmented button.on { background: var(--raised); box-shadow: inset 0 -2px 0 var(--accent); }\n.pde .progress { height: 4px; border-radius: 2px; background: var(--raised); overflow: hidden; }\n.pde .progress > div { height: 100%; background: var(--accent); transition: width 200ms; }\n\n/* The studio */\n.pde.studio { position: fixed; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; background: var(--panel); pointer-events: auto;\n box-shadow: 0 -8px 30px rgba(0,0,0,.35); border-top: 1px solid var(--line); }\n.pde.studio .grip { position: absolute; top: -4px; left: 0; right: 0; height: 8px; cursor: ns-resize; }\n.pde.studio .head { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }\n.pde.studio .head .field.title { width: min(320px, 30vw); font-weight: 600; }\n.pde.studio .timeline { position: relative; height: 150px; flex: none; border-bottom: 1px solid var(--line); background: var(--bg); }\n.pde.studio .timeline .lanes { position: absolute; left: 0; top: 0; bottom: 0; width: 104px; font-size: 11px; color: var(--muted); pointer-events: none; z-index: 2; }\n.pde.studio .timeline .lanes > div { position: absolute; right: 10px; }\n.pde.studio .timeline .slider { position: absolute; left: 104px; right: 0; top: 0; bottom: 0; }\n.pde.studio .timeline .clock { position: absolute; left: 6px; bottom: 5px; z-index: 3; font: 600 10px ui-monospace, monospace; white-space: nowrap; }\n.pde.studio .body { display: flex; flex: 1; min-height: 0; }\n.pde.studio .steps { width: 260px; flex: none; overflow: auto; border-right: 1px solid var(--line); padding: 6px; display: flex; flex-direction: column; gap: 4px; }\n.pde.studio .step { display: flex; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; align-items: flex-start; }\n.pde.studio .step:hover { background: var(--raised); }\n.pde.studio .step.on { background: var(--raised); border-color: var(--accent); }\n.pde.studio .step.playing { box-shadow: inset 3px 0 0 var(--ok); }\n.pde.studio .step .n { font: 600 12px ui-monospace, monospace; color: var(--muted); width: 20px; flex: none; padding-top: 1px; }\n.pde.studio .step .say { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--muted); font-size: 12px; }\n.pde.studio .pane { flex: 1; min-width: 0; overflow: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; }\n.pde.studio .pane + .pane { border-left: 1px solid var(--line); }\n.pde.studio .action { border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }\n.pde.studio .action.on { border-color: var(--accent); }\n.pde.studio .action.failed { border-color: var(--danger); }\n.pde.studio .action > .row { padding: 4px 6px; }\n.pde.studio .action .kind { font: 600 11px ui-monospace, monospace; padding: 2px 6px; border-radius: 4px; background: var(--raised); flex: none; }\n.pde.studio .action .kind.present { background: color-mix(in srgb, var(--accent) 22%, transparent); }\n.pde.studio .action .details { padding: 8px 10px 10px; border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }\n.pde.studio .action .details .wide { grid-column: 1 / -1; }\n.pde.studio .collapsed .body, .pde.studio .collapsed .grip { display: none; }\n.pde.studio video { width: 100%; max-height: 100%; background: #000; border-radius: 6px; }\n";