@protomaze/demo-engine 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/AGENTS.md +131 -0
  2. package/README.md +192 -2
  3. package/agent/Agent.d.ts +155 -0
  4. package/agent/Agent.js +1 -0
  5. package/agent/Guide.d.ts +2 -0
  6. package/agent/Guide.js +1 -0
  7. package/engine/DemoEngine.d.ts +338 -0
  8. package/engine/DemoEngine.js +1 -0
  9. package/engine/Guided.d.ts +12 -0
  10. package/engine/Guided.js +1 -0
  11. package/engine/Player.d.ts +154 -0
  12. package/engine/Player.js +1 -0
  13. package/engine/Plugin.d.ts +56 -0
  14. package/engine/Plugin.js +1 -0
  15. package/engine/Read.d.ts +5 -0
  16. package/engine/Read.js +1 -0
  17. package/engine/Recorder.d.ts +50 -0
  18. package/engine/Recorder.js +1 -0
  19. package/engine/Settings.d.ts +51 -0
  20. package/engine/Settings.js +1 -0
  21. package/index.d.ts +27 -0
  22. package/index.js +1 -0
  23. package/model/Demo.d.ts +201 -0
  24. package/model/Demo.js +1 -0
  25. package/model/Subtitles.d.ts +12 -0
  26. package/model/Subtitles.js +1 -0
  27. package/model/Timing.d.ts +45 -0
  28. package/model/Timing.js +1 -0
  29. package/model/Validate.d.ts +16 -0
  30. package/model/Validate.js +1 -0
  31. package/package.json +65 -4
  32. package/page/Input.d.ts +67 -0
  33. package/page/Input.js +1 -0
  34. package/page/Overlay.d.ts +110 -0
  35. package/page/Overlay.js +1 -0
  36. package/page/Targets.d.ts +85 -0
  37. package/page/Targets.js +1 -0
  38. package/speech/Music.d.ts +13 -0
  39. package/speech/Music.js +1 -0
  40. package/speech/Pack.d.ts +27 -0
  41. package/speech/Pack.js +1 -0
  42. package/speech/Speech.d.ts +127 -0
  43. package/speech/Speech.js +1 -0
  44. package/speech/Transcribe.d.ts +25 -0
  45. package/speech/Transcribe.js +1 -0
  46. package/speech/Workers.d.ts +22 -0
  47. package/speech/Workers.js +1 -0
  48. package/store/Share.d.ts +19 -0
  49. package/store/Share.js +1 -0
  50. package/store/Store.d.ts +55 -0
  51. package/store/Store.js +1 -0
  52. package/store/Zip.d.ts +9 -0
  53. package/store/Zip.js +1 -0
  54. package/ui/Actions.d.ts +33 -0
  55. package/ui/Actions.js +1 -0
  56. package/ui/EngineUI.d.ts +3 -0
  57. package/ui/EngineUI.js +1 -0
  58. package/ui/Hooks.d.ts +5 -0
  59. package/ui/Hooks.js +1 -0
  60. package/ui/Kit.d.ts +108 -0
  61. package/ui/Kit.js +1 -0
  62. package/ui/Library.d.ts +32 -0
  63. package/ui/Library.js +1 -0
  64. package/ui/Studio.d.ts +10 -0
  65. package/ui/Studio.js +1 -0
  66. package/ui/Styles.d.ts +2 -0
  67. package/ui/Styles.js +1 -0
  68. package/ui/Timeline.d.ts +21 -0
  69. package/ui/Timeline.js +1 -0
  70. package/video/Film.d.ts +61 -0
  71. package/video/Film.js +1 -0
@@ -0,0 +1,55 @@
1
+ import type { Demo, Language } from '../model/Demo';
2
+ import type { Timing } from '../model/Timing';
3
+ /** A demo kept in this browser: recorded, imported, or a checked-in one edited here; with its scenario. */
4
+ export type KeptDemo = Demo & {
5
+ scenario?: string;
6
+ savedAt?: number;
7
+ };
8
+ /** A demo's last video, kept in this browser until its data is cleared. */
9
+ export type DemoVideo = {
10
+ /** The demo's id. */
11
+ id: string;
12
+ blob: Blob;
13
+ /** When made, ms since 1970. */
14
+ at: number;
15
+ /** The demo as it was filmed: a video of an older version says so. */
16
+ json: string;
17
+ /** Its subtitles, as WebVTT. */
18
+ vtt: string;
19
+ /** When what happened in it, ms from its start. */
20
+ timing?: Timing;
21
+ language?: Language;
22
+ /** The presenter's own voice, recorded beside it: to transcribe. */
23
+ voice?: Blob;
24
+ };
25
+ type Kept = {
26
+ demos: KeptDemo[];
27
+ videos: Map<string, DemoVideo>;
28
+ };
29
+ /** Demos and videos kept in this browser (IndexedDB), per app; views are told of every change. */
30
+ export declare class Store {
31
+ private name;
32
+ private kept;
33
+ private listeners;
34
+ private opened;
35
+ private loaded;
36
+ constructor(name: string);
37
+ private open;
38
+ private run;
39
+ /** Read again, and every view told. */
40
+ reload(): Promise<void>;
41
+ /** What is kept now; read on first use. */
42
+ get(): Kept;
43
+ /** Ready once read. */
44
+ ready(): Promise<Kept>;
45
+ subscribe(listener: () => void): () => void;
46
+ saveDemo(demo: KeptDemo): Promise<void>;
47
+ /** A demo goes, and its video with it. */
48
+ deleteDemo(id: string): Promise<void>;
49
+ saveVideo(video: DemoVideo): Promise<void>;
50
+ deleteVideo(id: string): Promise<void>;
51
+ /** A file kept for demos: the music bed. */
52
+ saveAsset(id: string, blob: Blob | undefined): Promise<void>;
53
+ asset(id: string): Promise<Blob | undefined>;
54
+ }
55
+ export {};
package/store/Store.js ADDED
@@ -0,0 +1 @@
1
+ const e="demos",t="videos",s="assets";export class Store{constructor(e){this.name=e,this.kept={demos:[],videos:new Map},this.listeners=new Set,this.loaded=!1}open(){return this.opened??(this.opened=new Promise((a,r)=>{const i=indexedDB.open(this.name,2);i.onupgradeneeded=()=>{const a=i.result;[e,t,s].forEach(e=>a.objectStoreNames.contains(e)||a.createObjectStore(e,{keyPath:"id"}))},i.onsuccess=()=>a(i.result),i.onerror=()=>r(i.error)})),this.opened}async run(e,t,s){const a=s((await this.open()).transaction(e,t?"readwrite":"readonly").objectStore(e));return new Promise((e,t)=>{a.onsuccess=()=>e(a.result),a.onerror=()=>t(a.error)})}async reload(){try{const[s,a]=await Promise.all([this.run(e,!1,e=>e.getAll()),this.run(t,!1,e=>e.getAll())]);this.kept={demos:s.sort((e,t)=>(t.savedAt??0)-(e.savedAt??0)),videos:new Map(a.map(e=>[e.id,e]))}}catch{}this.listeners.forEach(e=>e())}get(){return this.loaded||(this.loaded=!0,this.reload()),this.kept}async ready(){return this.loaded||(this.loaded=!0,await this.reload()),this.kept}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}async saveDemo(t){await this.run(e,!0,e=>e.put({...t,savedAt:Date.now()})),await this.reload()}async deleteDemo(t){await this.run(e,!0,e=>e.delete(t)),await this.deleteVideo(t)}async saveVideo(e){await this.run(t,!0,t=>t.put(e)),await this.reload()}async deleteVideo(e){await this.run(t,!0,t=>t.delete(e)),await this.reload()}async saveAsset(e,t){t?await this.run(s,!0,s=>s.put({id:e,blob:t})):await this.run(s,!0,t=>t.delete(e))}async asset(e){try{return(await this.run(s,!1,t=>t.get(e)))?.blob}catch{return}}}
package/store/Zip.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ /** Zip files, as narration packs are kept: stored, not compressed (audio is already). Read either way. */
2
+ export type ZipEntry = {
3
+ name: string;
4
+ data: Uint8Array;
5
+ };
6
+ /** A zip of these files, stored. */
7
+ export declare function zip(files: ZipEntry[]): Blob;
8
+ /** The files in a zip, by name: stored or deflated (a zip made again elsewhere). */
9
+ export declare function unzip(buffer: ArrayBuffer): Promise<Map<string, Uint8Array>>;
package/store/Zip.js ADDED
@@ -0,0 +1 @@
1
+ let t;function e(e){if(!t){t=new Uint32Array(256);for(let e=0;e<256;e++){let n=e;for(let t=0;t<8;t++)n=1&n?3988292384^n>>>1:n>>>1;t[e]=n>>>0}}let n=4294967295;for(let i=0;i<e.length;i++)n=t[255&(n^e[i])]^n>>>8;return(4294967295^n)>>>0}export function zip(t){const n=new TextEncoder,i=[],r=[];let a=0;for(const s of t){const t=n.encode(s.name),U=e(s.data),o=new DataView(new ArrayBuffer(30));o.setUint32(0,67324752,!0),o.setUint16(4,20,!0),o.setUint16(6,2048,!0),o.setUint16(12,33,!0),o.setUint32(14,U,!0),o.setUint32(18,s.data.length,!0),o.setUint32(22,s.data.length,!0),o.setUint16(26,t.length,!0),i.push(new Uint8Array(o.buffer),t,s.data);const w=new DataView(new ArrayBuffer(46));w.setUint32(0,33639248,!0),w.setUint16(4,20,!0),w.setUint16(6,20,!0),w.setUint16(8,2048,!0),w.setUint16(14,33,!0),w.setUint32(16,U,!0),w.setUint32(20,s.data.length,!0),w.setUint32(24,s.data.length,!0),w.setUint16(28,t.length,!0),w.setUint32(42,a,!0),r.push(new Uint8Array(w.buffer),t),a+=30+t.length+s.data.length}const s=r.reduce((t,e)=>t+e.length,0),U=new DataView(new ArrayBuffer(22));return U.setUint32(0,101010256,!0),U.setUint16(8,t.length,!0),U.setUint16(10,t.length,!0),U.setUint32(12,s,!0),U.setUint32(16,a,!0),new Blob([...i,...r,new Uint8Array(U.buffer)],{type:"application/zip"})}export async function unzip(t){const e=new DataView(t);let n=t.byteLength-22;for(;n>=0&&101010256!==e.getUint32(n,!0);)n--;if(n<0)throw new Error("Not a zip");const i=e.getUint16(n+10,!0);let r=e.getUint32(n+16,!0);const a=new TextDecoder,s=new Map;for(let n=0;n<i;n++){if(33639248!==e.getUint32(r,!0))throw new Error("A broken zip");const n=e.getUint16(r+10,!0),i=e.getUint32(r+20,!0),U=e.getUint16(r+28,!0),o=e.getUint16(r+30,!0),w=e.getUint16(r+32,!0),f=e.getUint32(r+42,!0),l=a.decode(new Uint8Array(t,r+46,U)),g=f+30+e.getUint16(f+26,!0)+e.getUint16(f+28,!0),c=new Uint8Array(t,g,i);if(0===n)s.set(l,c.slice());else if(8===n){const t=new Blob([c.slice()]).stream().pipeThrough(new DecompressionStream("deflate-raw"));s.set(l,new Uint8Array(await new Response(t).arrayBuffer()))}r+=46+U+o+w}return s}
@@ -0,0 +1,33 @@
1
+ import type { DemoEngine } from '../engine/DemoEngine';
2
+ import { DemoAction } from '../model/Demo';
3
+ /** New actions of each kind, to fill in. */
4
+ declare const TEMPLATES: Record<string, DemoAction>;
5
+ /** An action as a sentence. */
6
+ export declare function readAction(engine: DemoEngine, action: DemoAction): string;
7
+ /** The menu adding an action of any kind. */
8
+ export declare function addActionItems(engine: DemoEngine, add: (action: DemoAction) => void): ({
9
+ label: string;
10
+ onClick: () => void;
11
+ } | {
12
+ heading: string;
13
+ })[];
14
+ type Props = {
15
+ engine: DemoEngine;
16
+ action: DemoAction;
17
+ index: number;
18
+ count: number;
19
+ open: boolean;
20
+ error?: string;
21
+ /** Sentences in the step: what `cue` can name. */
22
+ sentences: string[];
23
+ onOpen: () => void;
24
+ onChange: (action: DemoAction) => void;
25
+ onMove: (by: number) => void;
26
+ onDelete: () => void;
27
+ onDuplicate: () => void;
28
+ /** The studio out of the way while a target is picked on the page. */
29
+ picking: (on: boolean) => void;
30
+ };
31
+ /** One action: as it reads, its timing; open, every detail of it. */
32
+ export declare function ActionRow({ engine, action, index, count, open, error, sentences, onOpen, onChange, onMove, onDelete, onDuplicate, picking }: Props): JSX.Element;
33
+ export { TEMPLATES };
package/ui/Actions.js ADDED
@@ -0,0 +1 @@
1
+ import e,{useState as t}from"react";import{describeTarget as a}from"../engine/Player.js";import{BUILT_IN_KINDS as l,INTERACT_KINDS as o,isPresent as r,PRESENT_KINDS as n}from"../model/Demo.js";import{fractionIn as c}from"../page/Targets.js";import{Button as s,Check as i,JsonField as d,Labelled as m,Menu as p,NumberField as h}from"./Kit.js";const u={click:{do:"click",target:{css:"button",text:""}},hover:{do:"hover",target:{css:"button",text:""}},type:{do:"type",target:{css:"input"},text:""},key:{do:"key",key:"Escape"},select:{do:"select",target:{css:"select"},option:""},drag:{do:"drag",target:{css:'[role="slider"]'},to:{at:[1,.5]}},scroll:{do:"scroll",target:{css:"main"}},waitFor:{do:"waitFor",target:{css:'[role="dialog"]'}},spotlight:{do:"spotlight",target:{css:"main"}},ring:{do:"ring",target:{css:"button",text:""}},arrow:{do:"arrow",target:{css:"button",text:""},text:""},callout:{do:"callout",text:"A note",corner:"top-right"},blur:{do:"blur",target:{css:'input[type="email"]'}},card:{do:"card",title:"Title",text:"",for:3e3},zoom:{do:"zoom",target:{css:"main"},scale:1.8},clear:{do:"clear"}},g=new Set(["click","hover","type","select","drag","waitFor","spotlight","ring","arrow","blur","zoom"]);export function readAction(e,t){return e.read(t)}export function addActionItems(e,t){const a=e.pluginKinds(),l=a=>({label:a,onClick:()=>t(JSON.parse(JSON.stringify(e.pluginAction(a)?.template?.()??u[a]??{do:a})))});return[{heading:"Interact"},...o.map(l),{heading:"Present"},...n.map(l),...a.length?[{heading:"App"},...a.map(l)]:[]]}export function ActionRow({engine:o,action:n,index:u,count:v,open:k,error:E,sentences:y,onOpen:w,onChange:x,onMove:f,onDelete:C,onDuplicate:N,picking:T}){const[A,S]=t(),j=n,F=e=>{const t={...n,...e};Object.keys(e).forEach(e=>(void 0===t[e]||""===t[e]||!1===t[e])&&delete t[e]),x(t)},D=l.includes(n.do),B=r(n),O=(t,l,r="Target",n=!1)=>e.createElement("div",{className:"wide col"},e.createElement("div",{className:"row"},e.createElement("span",{className:"small muted",style:{width:52}},r),e.createElement(s,{icon:"pick",small:!0,title:"Pick it on the page",onClick:()=>{(async e=>{T(!0);const t=await o.overlay.pick(e=>o.targets.targetElement(e),e=>a(o.targets.describe(e)));if(T(!1),!t)return;const l=o.targets.describe(t.element),r=t.element.matches('canvas, video, [role="slider"], input[type="range"]')||j.at?c(t.element,t.x,t.y):void 0;F("to"===e?{to:{target:l,...r?{at:r}:{}}}:{target:l,...r?{at:r}:{}})})("To"===r?"to":"target")}}),e.createElement(s,{icon:"show",small:!0,title:"Show it on the page",disabled:!t,onClick:()=>(e=>{if(!e)return;const t=o.targets.matches(e),a=t[e.index??0];S(a?`${t.length} match${1===t.length?"":"es"}`:"Not found here now"),a&&(a.scrollIntoView({block:"nearest",inline:"nearest"}),o.overlay.flash(a))})(t)}),n&&t&&e.createElement(s,{icon:"close",small:!0,kind:"bare",title:"No target",onClick:()=>l(void 0)}),A&&e.createElement("span",{className:"small muted"},A)),t&&e.createElement("div",{className:"row"},e.createElement("input",{className:"field mono grow",title:"CSS selector",placeholder:"css",value:t.css,onChange:e=>l({...t,css:e.target.value})}),e.createElement("input",{className:"field",style:{width:"24%"},title:"Its label: what it shows. Digits match any.",placeholder:"text",value:t.text??"",onChange:e=>l(b({...t,text:e.target.value}))}),e.createElement("input",{className:"field mono",style:{width:"20%"},title:"Its label by the app's locale key: found in every language",placeholder:"key",value:t.key??"",onChange:e=>l(b({...t,key:e.target.value}))}),e.createElement(h,{value:t.index,width:52,placeholder:"#",title:"Which of the matches, from 0",onChange:e=>l(b({...t,index:e}))})),!t&&n&&e.createElement(s,{small:!0,onClick:()=>l({css:"button",text:""})},"Add a target")),P=(t,a)=>e.createElement(m,{label:a},e.createElement("select",{className:"field",value:j[t]??"",onChange:e=>F({[t]:e.target.value||void 0})},e.createElement("option",{value:""},"where there is room"),["top","right","bottom","left"].map(t=>e.createElement("option",{key:t,value:t},t)))),I=(t,a,l=!1)=>e.createElement(m,{label:a,className:l?"wide":void 0},e.createElement("input",{className:"field",value:j[t]??"",onChange:e=>F({[t]:e.target.value})})),$=(t,a,l)=>e.createElement(m,{label:a},e.createElement(h,{value:j[t],width:120,placeholder:l,onChange:e=>F({[t]:e})})),z=(t,a,l="At (x, y in its box)")=>e.createElement(m,{label:l},e.createElement("div",{className:"row"},e.createElement(h,{value:t?.[0],width:60,placeholder:"0.5",onChange:e=>a(void 0===e&&void 0===t?.[1]?void 0:[e??.5,t?.[1]??.5])}),e.createElement(h,{value:t?.[1],width:60,placeholder:"0.5",onChange:e=>a(void 0===e&&void 0===t?.[0]?void 0:[t?.[0]??.5,e??.5])})));return e.createElement("div",{className:["action",k&&"on",E&&"failed"].filter(Boolean).join(" ")},e.createElement("div",{className:"row"},e.createElement(s,{icon:k?"expand":"right",small:!0,kind:"bare",title:k?"Less":"Details",onClick:w}),e.createElement("span",{className:"kind"+(B?" present":"")},n.do),e.createElement("span",{className:"grow ellipsis",title:E??readAction(o,n),onClick:w,style:{cursor:"pointer"}},readAction(o,n),E&&e.createElement("span",{className:"error"}," - ",E)),e.createElement("span",{className:"small muted",title:"ms before it"},"wait"),e.createElement(h,{value:n.wait,width:58,placeholder:"800",title:"ms before it, 800 by default",onChange:e=>F({wait:e})}),e.createElement("select",{className:"field small",style:{width:74},title:"Starts with this sentence of the step's narration",value:n.cue??"",onChange:e=>F({cue:""===e.target.value?void 0:Number(e.target.value)})},e.createElement("option",{value:""},"no cue"),y.map((t,a)=>e.createElement("option",{key:a,value:a,title:t},`cue ${a+1}`)),void 0!==n.cue&&n.cue>=y.length&&e.createElement("option",{value:n.cue},`cue ${n.cue+1}?`)),e.createElement(s,{icon:"play",small:!0,kind:"bare",title:"Try it now",onClick:()=>{o.check({id:"test",title:"Test",steps:[{say:{},actions:[{...n,wait:0}],hold:B?2500:0}]},{speed:1}).then(e=>S(e.ok?"Played":e.failures[0]?.error??e.error))}}),e.createElement(p,{title:"More",items:[{label:"Earlier",icon:"up",disabled:0===u,onClick:()=>f(-1)},{label:"Later",icon:"down",disabled:u===v-1,onClick:()=>f(1)},{label:"Duplicate",icon:"duplicate",onClick:N},{label:"Delete",icon:"delete",onClick:C}]})),k&&e.createElement("div",{className:"details"},(()=>{if(!D){const{do:t,wait:a,cue:l,...o}=j;return e.createElement(m,{label:`${n.do}: its details`,className:"wide"},e.createElement(d,{rows:3,value:o,onChange:e=>e&&"object"==typeof e&&x({do:n.do,...void 0!==j.wait?{wait:j.wait}:{},...void 0!==j.cue?{cue:j.cue}:{},...e})}))}const t=[];switch("callout"===n.do||"key"===n.do||"scroll"===n.do?t.push(O(j.target,e=>F({target:e}),"Target",!0)):g.has(n.do)&&t.push(O(j.target,e=>e&&F({target:e}))),n.do){case"click":t.push(z(j.at,e=>F({at:e}))),t.push(e.createElement("div",{className:"row",key:"mods",style:{flexWrap:"wrap",gap:10}},e.createElement(i,{label:"double",checked:Boolean(j.double),onChange:e=>F({double:e})}),e.createElement(i,{label:"right",checked:Boolean(j.right),onChange:e=>F({right:e})}),["shift","ctrl","alt","meta"].map(t=>e.createElement(i,{key:t,label:t,checked:Boolean(j[t]),onChange:e=>F({[t]:e})}))));break;case"hover":t.push(z(j.at,e=>F({at:e})));break;case"type":t.push(I("text","Text",!0));break;case"key":t.push(I("key","Key or chord: 'Enter', 'Control+K'"));break;case"select":t.push(I("option","Option, by its text or value"));break;case"drag":t.push(z(j.at,e=>F({at:e}),"From (x, y in its box)")),t.push(O(j.to?.target,e=>F({to:b({...j.to,target:e})}),"To",!0)),t.push(z(j.to?.at,e=>F({to:b({...j.to,at:e})}),"To (x, y in its box)"));break;case"scroll":t.push(e.createElement(m,{label:"By (x, y px)",key:"by"},e.createElement(d,{value:j.by,onChange:e=>F({by:e})})));break;case"waitFor":t.push(e.createElement(i,{key:"gone",label:"till it is gone",checked:Boolean(j.gone),onChange:e=>F({gone:e})})),t.push($("timeout","Timeout ms","10000"));break;case"spotlight":t.push(I("text","Note",!0),$("padding","Padding px","8"));break;case"ring":t.push(I("text","Label"),I("color","Colour"),$("padding","Padding px","6")),t.push(e.createElement(m,{label:"Shape",key:"shape"},e.createElement("select",{className:"field",value:j.shape??"box",onChange:e=>F({shape:"box"===e.target.value?void 0:e.target.value})},e.createElement("option",null,"box"),e.createElement("option",null,"circle"))));break;case"arrow":t.push(I("text","Label"),P("from","From"),I("color","Colour"));break;case"callout":t.push(I("text","Text",!0),P("side","Side (with a target)")),t.push(e.createElement(m,{label:"Corner (without)",key:"corner"},e.createElement("select",{className:"field",value:j.corner??"",onChange:e=>F({corner:e.target.value||void 0})},e.createElement("option",{value:""},"top-right"),["top-left","top-right","bottom-left","bottom-right"].map(t=>e.createElement("option",{key:t},t)))));break;case"card":t.push(I("title","Title",!0),I("text","Text",!0));break;case"zoom":t.push($("scale","Scale","1.8"))}return B&&"clear"!==n.do&&t.push($("for","For ms (else the step)","the step")),t.map((t,a)=>e.createElement(e.Fragment,{key:a},t))})()))}function b(e){const t={};return Object.entries(e).forEach(([e,a])=>{void 0!==a&&""!==a&&(t[e]=a)}),t}export{u as TEMPLATES};
@@ -0,0 +1,3 @@
1
+ import type { DemoEngine } from '../engine/DemoEngine';
2
+ /** The engine's own UI, in its overlay: ready to start, bars while playing and recording, messages, the studio. */
3
+ export declare function mountUI(engine: DemoEngine): () => void;
package/ui/EngineUI.js ADDED
@@ -0,0 +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 m}from"./Kit.js";import{Library as r}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=m(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:"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(r,{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)}))}
package/ui/Hooks.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import type { DemoEngine, DemoEntry, EngineState } from '../engine/DemoEngine';
2
+ /** The engine's state, rendering again as it changes. */
3
+ export declare function useEngine(engine: DemoEngine): EngineState;
4
+ /** Every demo the engine knows, as kept now. */
5
+ export declare function useDemos(engine: DemoEngine): DemoEntry[];
package/ui/Hooks.js ADDED
@@ -0,0 +1 @@
1
+ import{useSyncExternalStore as e}from"react";export function useEngine(t){return e(t.subscribe,t.getState)}export function useDemos(e){return useEngine(e),e.entriesNow()}
package/ui/Kit.d.ts ADDED
@@ -0,0 +1,108 @@
1
+ import React, { ReactNode } from 'react';
2
+ declare const PATHS: {
3
+ readonly play: "M8 5v14l11-7z";
4
+ readonly pause: "M6 19h4V5H6v14zm8-14v14h4V5h-4z";
5
+ readonly stop: "M6 6h12v12H6z";
6
+ readonly record: "M12 4a8 8 0 1 0 0 16a8 8 0 0 0 0-16z";
7
+ readonly 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";
8
+ readonly 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";
9
+ readonly 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";
10
+ readonly 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";
11
+ readonly add: "M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z";
12
+ readonly delete: "M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z";
13
+ readonly up: "M4 12l1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8-8 8z";
14
+ readonly down: "M20 12l-1.41-1.41L13 16.17V4h-2v12.17l-5.58-5.59L4 12l8 8 8-8z";
15
+ readonly 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";
16
+ readonly download: "M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z";
17
+ readonly upload: "M9 16h6v-6h4l-7-7-7 7h4zm-4 2h14v2H5z";
18
+ readonly 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";
19
+ readonly 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";
20
+ readonly 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";
21
+ readonly 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";
22
+ readonly 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";
23
+ readonly 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";
24
+ readonly 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";
25
+ readonly 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";
26
+ readonly tune: "M3 17v2h6v-2H3zM3 5v2h10V5H3zm10 16v-2h8v-2h-8v-2h-2v6h2zM7 9v2H3v2h4v2h2V9H7zm14 4v-2H11v2h10zm-6-4h2V7h4V5h-4V3h-2v6z";
27
+ readonly 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";
28
+ readonly check: "M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z";
29
+ readonly 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";
30
+ readonly first: "M6 6h2v12H6zm3.5 6l8.5 6V6z";
31
+ readonly 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";
32
+ readonly expand: "M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6z";
33
+ readonly right: "M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z";
34
+ readonly 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";
35
+ readonly minimize: "M6 19h12v2H6z";
36
+ readonly maximize: "M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z";
37
+ readonly 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";
38
+ readonly flash: "M7 2v11h3v9l7-12h-4l4-8z";
39
+ readonly guide: "M5 13.18v4L12 21l7-3.82v-4L12 17l-7-3.82zM12 3L1 9l11 6 9-4.91V17h2V9L12 3z";
40
+ readonly loop: "M7 7h10v3l4-4-4-4v3H5v6h2V7zm10 10H7v-3l-4 4 4 4v-3h12v-6h-2v4z";
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
+ readonly back: "M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z";
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
+ };
45
+ export type IconName = keyof typeof PATHS;
46
+ export declare function Icon({ name }: {
47
+ name: IconName;
48
+ }): JSX.Element;
49
+ type ButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {
50
+ icon?: IconName;
51
+ kind?: 'primary' | 'danger' | 'bare';
52
+ on?: boolean;
53
+ small?: boolean;
54
+ };
55
+ export declare function Button({ icon, kind, on, small, className, children, ...props }: ButtonProps): JSX.Element;
56
+ /** A labelled control. */
57
+ export declare function Labelled({ label, children, className }: {
58
+ label: string;
59
+ children: ReactNode;
60
+ className?: string;
61
+ }): JSX.Element;
62
+ export declare function Check({ label, checked, onChange, title }: {
63
+ label: ReactNode;
64
+ checked: boolean;
65
+ onChange: (checked: boolean) => void;
66
+ title?: string;
67
+ }): JSX.Element;
68
+ export declare function Segmented<T extends string>({ value, options, onChange }: {
69
+ value: T;
70
+ options: [T, ReactNode, string?][];
71
+ onChange: (value: T) => void;
72
+ }): JSX.Element;
73
+ /**
74
+ * A text field that edits a number, kept as text while typed: empty is undefined.
75
+ */
76
+ export declare function NumberField({ value, onChange, placeholder, title, width }: {
77
+ value: number | undefined;
78
+ onChange: (value: number | undefined) => void;
79
+ placeholder?: string;
80
+ title?: string;
81
+ width?: number;
82
+ }): JSX.Element;
83
+ /** A JSON field: what is typed is applied once it reads. */
84
+ export declare function JsonField({ value, onChange, className, rows }: {
85
+ value: unknown;
86
+ onChange: (value: any) => void;
87
+ className?: string;
88
+ rows?: number;
89
+ }): JSX.Element;
90
+ export type MenuItem = {
91
+ label: ReactNode;
92
+ icon?: IconName;
93
+ onClick: () => void;
94
+ disabled?: boolean;
95
+ } | {
96
+ heading: string;
97
+ } | false | undefined | null;
98
+ /** A button opening a menu below it. */
99
+ export declare function Menu({ icon, label, title, items, align }: {
100
+ icon?: IconName;
101
+ label?: ReactNode;
102
+ title: string;
103
+ items: MenuItem[];
104
+ align?: 'left' | 'right';
105
+ }): JSX.Element;
106
+ /** The theme, 'auto' resolved to the system's. */
107
+ export declare function useTheme(theme?: 'light' | 'dark' | 'auto'): 'light' | 'dark';
108
+ export {};
package/ui/Kit.js ADDED
@@ -0,0 +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}
@@ -0,0 +1,32 @@
1
+ import { ReactNode } from 'react';
2
+ import type { DemoEngine } from '../engine/DemoEngine';
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
6
+ * styles stay out.
7
+ */
8
+ export declare function DemoLibrary({ engine, theme }: {
9
+ engine: DemoEngine;
10
+ theme?: 'light' | 'dark' | 'auto';
11
+ }): JSX.Element;
12
+ /** Renders its children in a shadow root with the engine's styles. */
13
+ export declare function Shadow({ children }: {
14
+ children: ReactNode;
15
+ }): JSX.Element;
16
+ export declare function Library({ engine, theme, floating }: {
17
+ engine: DemoEngine;
18
+ theme: 'light' | 'dark';
19
+ floating?: boolean;
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 }: {
31
+ engine: DemoEngine;
32
+ }): JSX.Element;
package/ui/Library.js ADDED
@@ -0,0 +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 r,KOKORO_VOICES as s,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),[r,s]=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)}s(t)},[]),e.createElement("div",{ref:i,"data-demo-ignore":!0,style:{display:"contents"}},r&&o(t,r))}export function Library({engine:t,theme:a,floating:n}){const l=g(t),o=h(t),i="idle"!==l.session.mode,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 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 r(e)})}},"Import"),e.createElement(u,{icon:"copy",title:"Paste a demo’s JSON",onClick:()=>{navigator.clipboard.readText().then(r,()=>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,r]=l(),s=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:s,onChange:e=>(e=>{if(i?.(),r(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(),r(void 0);const e=await t.listenToMusic(20);r(()=>e),setTimeout(()=>r(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:r}=a,s=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"),r&&e.createElement("span",{className:"badge accent",title:`Filmed ${new Date(r.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 · ~",s," · ",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",icon:"present",disabled:n,onClick:()=>{t.play(l,{waitForPresenter:!0})}},{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)}},r&&{heading:"Video"},r&&{label:"Download the video",icon:"film",onClick:()=>t.downloadVideo(r,l.title)},r&&{label:"Subtitles .vtt",icon:"subtitles",onClick:()=>t.downloadVideo(r,l.title,"vtt")},r&&{label:"Subtitles .srt",icon:"subtitles",onClick:()=>t.downloadVideo(r,l.title,"srt")},r&&{label:"Share…",icon:"share",onClick:()=>{t.shareVideo(r,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],r=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"},s.map(t=>e.createElement("option",{key:t.id,value:`kokoro:${t.id}`},t.name))),e.createElement("optgroup",{label:"Piper"},l.startsWith("piper:")&&!r.some(e=>`piper:${e.id}`===l)&&e.createElement("option",{value:l},l.slice(6)),r.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,[s,c]=l([]),m=e=>a.changeSettings({speech:{...n.speech,elevenlabs:{...n.speech.elevenlabs,...e}}});return t(()=>{o&&r(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()})})),s.length>0&&e.createElement(b,{label:"Voice",className:"grow"},e.createElement("select",{className:"field",value:s.some(e=>e.id===i)?i:"",onChange:e=>m({voice:e.target.value})},s.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,r]=l(()=>speechSynthesis.getVoices());t(()=>{const e=()=>r(speechSynthesis.getVoices());return speechSynthesis.addEventListener("voiceschanged",e),()=>speechSynthesis.removeEventListener("voiceschanged",e)},[]);const s=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"),s.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."))}
package/ui/Studio.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import type { DemoEngine } from '../engine/DemoEngine';
2
+ /**
3
+ * A demo's steps along its timeline - played from, recorded into, filmed - each step's narration
4
+ * in every language and its actions, readable and editable one by one; or the whole as text; or its
5
+ * video. Saved in this browser, over an app's demo of the same id until reverted.
6
+ */
7
+ export declare function Studio({ engine, theme }: {
8
+ engine: DemoEngine;
9
+ theme: 'light' | 'dark';
10
+ }): JSX.Element;
package/ui/Studio.js ADDED
@@ -0,0 +1 @@
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 g,readAction as h}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(()=>l(D.demo)),[L,O]=i(()=>JSON.stringify(D.demo)),R=n({back:[],forward:[]}),[T,M]=i(0),[J,U]=i(),[A,F]=i("steps"),[P,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,le=Math.min(T,Math.max(0,ie.length-1)),oe=ne&&ne.demo.id===j.id?ne.step:le,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&&(R.current.back.push(j),R.current.back.length>200&&R.current.back.shift(),R.current.forward=[]),$(e)},ge=()=>{const e=R.current.back.pop();e&&(R.current.forward.push(j),$(e))},he=()=>{const e=R.current.forward.pop();e&&(R.current.back.push(j),$(e))},ue=e=>pe({...j,...e}),ve=e=>ue({steps:e}),fe=e=>ve(ie.map((t,a)=>a===le?e:t));t(()=>{D.recorded&&pe({...j,steps:D.recorded.steps})},[D.recorded?.at]);const we=()=>{const{demo:e,problems:t}=d.parse(P.json);if(e)return B(void 0),{...e,scenario:P.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=le+e;if(t<0||t>=ie.length)return;const a=[...ie];[a[le],a[t]]=[a[t],a[le]],ve(a),M(t)},be=I||Q||"recording"===te.mode||Boolean(ne),Ne=ie[le],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(),he()):(e.preventDefault(),ge())},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 ${le+1}`,disabled:ae,onClick:()=>ke(le)})),!ne&&e.createElement(w,{title:"Present, guide, loop",icon:"present",items:[{label:`Present from step ${le+1}: waits after each step`,icon:"present",disabled:ae,onClick:()=>{d.play(j,{from:le,language:_,waitForPresenter:!0})}},{label:`Guide from step ${le+1}: the viewer does it`,icon:"guide",disabled:ae,onClick:()=>{d.guide(j,{from:le,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 ${le+1}`,disabled:ae,onClick:()=>{d.record({into:j,after:le})},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===R.current.back.length,onClick:ge}),e.createElement(v,{icon:"redo",kind:"bare",title:"Redo (Ctrl+Y)",disabled:0===R.current.forward.length,onClick:he}),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)})(),F(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:oe,action:J,theme:m,accent:"#ffb300",playhead:ne&&ne.demo.id===j.id?()=>d.elapsed():void 0,read:e=>h(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===le&&!G&&"on",ne&&a===oe&&"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(o(e,t))[0]}(t,_)||"Untitled"),e.createElement("span",{className:"small muted"},Ce(a))),t.title&&e.createElement("span",{className:"say"},o(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,le+1),{say:{},actions:[]},...ie.slice(le+1)]),M(le+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:g(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),l(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 ",le+1," of ",ie.length),e.createElement(v,{icon:"up",small:!0,kind:"bare",title:"Earlier",disabled:0===le,onClick:()=>ye(-1)}),e.createElement(v,{icon:"down",small:!0,kind:"bare",title:"Later",disabled:le===ie.length-1,onClick:()=>ye(1)}),e.createElement(v,{icon:"duplicate",small:!0,kind:"bare",title:"Duplicate",onClick:()=>{ve([...ie.slice(0,le+1),l(Ne),...ie.slice(le+1)]),M(le+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!==le)),M(Math.max(0,le-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("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(le)))),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:g(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:`${le}.${a}`,engine:d,action:t,index:a,count:Ne.actions.length,open:J===a,error:W.get(`${le}.${a}`),sentences:r(o(Ne,_)),onOpen:()=>U(J===a?void 0:a),onChange:e=>((e,t)=>fe({...ie[le],actions:ie[le].actions.map((a,n)=>n===e?t:a)}))(a,e),onMove:e=>((e,t)=>{const a=e+t,n=[...ie[le].actions];a<0||a>=n.length||([n[e],n[a]]=[n[a],n[e]],fe({...ie[le],actions:n}),U(a))})(a,e),onDuplicate:()=>fe({...Ne,actions:[...Ne.actions.slice(0,a+1),l(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:P.json,onChange:e=>V({...P,json:e.target.value})}),e.createElement("textarea",{className:"field mono grow",spellCheck:!1,value:P.scenario,placeholder:"The scenario, for people (.md)",onChange:e=>V({...P,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:l}){const[o,s]=i(),[c,d]=i(),[p,g]=i(),h=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"},h.length," sentence",1===h.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=()=>{};g(()=>()=>{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),g(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 x({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 ADDED
@@ -0,0 +1,2 @@
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";
package/ui/Styles.js ADDED
@@ -0,0 +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";
@@ -0,0 +1,21 @@
1
+ import type { Demo, DemoAction } from '../model/Demo';
2
+ import { Timing } from '../model/Timing';
3
+ export type TimelineProps = {
4
+ demo: Demo;
5
+ timing: Timing;
6
+ /** Whether `timing` was measured, not estimated. */
7
+ measured: boolean;
8
+ step: number;
9
+ action?: number;
10
+ /** ms played, while playing. */
11
+ playhead?: () => number | undefined;
12
+ theme: 'light' | 'dark';
13
+ accent: string;
14
+ read: (action: DemoAction) => string;
15
+ onPick: (step: number, action?: number) => void;
16
+ };
17
+ /**
18
+ * The demo along its time, on a @protomaze/time slider: steps, sentences, actions and effects in
19
+ * lanes; the step being edited selected; a playhead while it plays. Click to go to a step or action.
20
+ */
21
+ export declare function Timeline(props: TimelineProps): JSX.Element;
package/ui/Timeline.js ADDED
@@ -0,0 +1 @@
1
+ import{ThreeIntervalsTimeLayerLoader as e,ThreeTimeSliderEngine as t,TimeSlider as n,TimeSliderIntervalsLayer as a,TimeSliderIntervalsModel as r}from"@protomaze/time";import s,{useEffect as i,useRef as c,useState as o}from"react";import{isPresent as m}from"../model/Demo.js";import{clock as l}from"../model/Timing.js";const d=new Date(2e3,0,1).getTime(),u=[{lane:"steps",name:"Steps",min:.76,max:.98},{lane:"cues",name:"Narration",min:.52,max:.73},{lane:"actions",name:"Actions",min:.27,max:.49},{lane:"effects",name:"Effects",min:.02,max:.24}];export function Timeline(p){const{timing:f,theme:h,accent:x}=p,y=c(null),[T,g]=o(),[E,v]=o(),[w,M]=o(""),b=c(new Map),k=c(new Map),N=c(p);N.current=p,i(()=>{const s=new n({showTicks:!0,theme:h,hover:{tooltip:!1,glow:!0},tickTooltip:!1,selection:{shading:!0,label:!1},selectionEditMode:"never",background:"transparent",font:{family:"system-ui, sans-serif",size:11}}),i=(e,t)=>n=>{const a=b.current.get(n.id),{step:r,action:s}=N.current,i=a&&a.step===r&&("steps"===e||"cues"===e||a.index===s);return{fill:{color:a?.failed?"#ff5a5f":i?N.current.accent:t,opacity:i?.9:"steps"===e&&a.step%2?.45:.6},border:{color:"dark"===h?"#111":"#fff",width:1}}},c={steps:"#6d7bd9",cues:"#3ea6a0",actions:"#8f8fa3",effects:"#c98a2b"};u.forEach(({lane:e,name:t,min:n,max:s})=>{const o=new r;o.name=t,o.minMax=1;const m=new a(o,{name:t,min:n,max:s,styler:i(e,c[e]),yAxis:{visible:!1}});k.current.set(e,{model:o,layer:m})});let o=!1;s.init(y.current,{startTime:d-500,endTime:d+Math.max(5e3,f.duration)+500}).then(async()=>{o||(s.addLayerLoader(new e),await s.setEngine(new t),o||(k.current.forEach(({layer:e})=>s.addLayer(e)),s.showCurrent=!0,g(s)))});const m=[s.on("select",e=>{const t=e.flatMap(e=>e.elements)[0],n=t&&b.current.get(t.id);n&&N.current.onPick(n.step,"actions"===n.lane||"effects"===n.lane?n.index:void 0)}),s.on("hover",e=>{const t=e?.elements.flatMap(e=>e.elements)[0],n=t&&b.current.get(t.id),a=y.current?.getBoundingClientRect();v(n&&e&&a?{x:e.clientX-a.left,y:e.clientY-a.top,text:n.text}:void 0)}),s.on("current",e=>M(l(e-d,!0)))];return()=>{o=!0,m.forEach(e=>e()),s.destroy()}},[]),i(()=>T?.setTheme(h),[T,h]),i(()=>{if(!T)return;const{demo:e,read:t}=p;b.current.clear();const n=new Map(u.map(({lane:e})=>[e,[]])),a=(e,t,a,r,s)=>{b.current.set(t,{lane:e,...s}),n.get(e).push({id:t,name:s.text,t:[d+a,d+Math.max(r-60,a+120)],v:[0,1]})};f.steps.forEach(({step:t,start:n,end:r})=>a("steps",`s${t}`,n,r,{step:t,text:`${t+1}. ${e.steps[t]?.title??""}`.trim()})),f.cues.forEach((e,t)=>a("cues",`c${t}`,e.start,e.end,{step:e.step,text:e.text})),f.actions.forEach(({step:n,index:r,start:s,end:i,error:c})=>{const o=e.steps[n]?.actions[r];o&&a(m(o)?"effects":"actions",`a${n}.${r}`,s,i,{step:n,index:r,text:t(o)+(c?` - ${c}`:""),failed:Boolean(c)})}),k.current.forEach(({model:e},t)=>{e.clear(),function(e){const t=[];return[...e].sort((e,t)=>e.t[0]-t.t[0]).map(e=>{let n=t.findIndex(t=>t<=e.t[0]);return n<0&&(n=t.push(0)-1),t[n]=e.t[1],{...e,v:[n,n+1]}})}(n.get(t)).forEach(t=>e.add(t))}),T.setLimits({startTime:d-2e3,endTime:d+f.duration+2e3})},[T,f,p.demo]),i(()=>{if(!T)return;const e=f.steps.find(e=>e.step===p.step);if(k.current.forEach(({layer:e})=>e.restyle()),!e)return T.clearSelection();T.setSelection([{startTime:d+e.start,endTime:d+e.end}]),N.current.playhead?.()||T.setCurrent(d+e.start);const{startTime:t,endTime:n}=T.getTimeRange();if(d+e.start<t||d+e.end>n){const a=n-t;T.fit({range:{startTime:d+e.start-.1*a,endTime:d+e.start+.9*a},animate:400})}},[T,p.step,p.action,f]);const $=c(0);return i(()=>{!T||Math.abs($.current-f.duration)<1e3||($.current=f.duration,T.fit({range:{startTime:d-500,endTime:d+f.duration+500},animate:300}))},[T,f.duration]),i(()=>{if(!T||!p.playhead)return;let e=0;const t=()=>{const n=N.current.playhead?.();if(void 0!==n){const e=d+n;T.setCurrent(e);const{startTime:t,endTime:a,duration:r}=T.getTimeRange();(e>a-.05*r||e<t)&&T.setTimeRange({startTime:e-.2*r,endTime:e+.8*r})}e=requestAnimationFrame(t)};return e=requestAnimationFrame(t),()=>cancelAnimationFrame(e)},[T,p.playhead]),s.createElement("div",{className:"timeline"},s.createElement("div",{className:"clock",title:p.measured?"As last played":"Estimated: play it to measure"},w||"0:00.0"," ",s.createElement("span",{className:"muted"},"/ ",l(f.duration),p.measured?"":" ~")),s.createElement("div",{className:"lanes"},u.map(({name:e,min:t,max:n})=>s.createElement("div",{key:e,style:{top:126*(1-(t+n)/2)-8}},e))),s.createElement("div",{className:"slider",ref:y,style:{"--accent":x}}),E&&s.createElement("div",{className:"menu small",style:{left:Math.min(E.x+116,(y.current?.clientWidth??600)-140),top:Math.max(4,E.y-44),pointerEvents:"none",minWidth:0,maxWidth:420,padding:"4px 8px",whiteSpace:"normal"}},E.text))}
@@ -0,0 +1,61 @@
1
+ export type FilmOptions = {
2
+ /** What a video hears: the narration (`Speech.soundtrack`). */
3
+ soundtrack: MediaStreamAudioDestinationNode;
4
+ /** The microphone too: a presenter's own commentary. */
5
+ microphone?: boolean;
6
+ /** Only this part of the tab, where the browser crops (Chrome): the app, without a dev panel beside it. */
7
+ crop?: Element;
8
+ frameRate?: number;
9
+ /** Megabits a second. Default 8. */
10
+ bitrate?: number;
11
+ /**
12
+ * The video's size exactly, px: the tab drawn into it, whole with bars (`fit`) or filling it with
13
+ * its edges cut (`fill`). The tab's own size by default.
14
+ */
15
+ size?: {
16
+ width: number;
17
+ height: number;
18
+ };
19
+ fit?: 'fit' | 'fill';
20
+ /** The browser's own "Stop sharing". */
21
+ onEnded?: () => void;
22
+ };
23
+ /** A tab being filmed; held (`pause`) while the demo is: the video leaves that time out. */
24
+ export type Filming = {
25
+ /** performance.now() when the recorder started: time 0 of the video, less what was held. */
26
+ since: number;
27
+ pause(): void;
28
+ resume(): void;
29
+ /** The microphone alone, recorded beside the video, for transcribing; none without one. */
30
+ stop(): Promise<{
31
+ video: Blob;
32
+ voice?: Blob;
33
+ }>;
34
+ };
35
+ /**
36
+ * Films this tab - from a click in it: the browser asks to share it - with the narration, and the
37
+ * microphone if asked, as sound. Starts held: `resume` when what is filmed is ready.
38
+ */
39
+ export declare function startFilming(options: FilmOptions): Promise<Filming>;
40
+ /** Records the microphone alone: a presenter's commentary while recording a demo, not filming it. */
41
+ export declare function recordMicrophone(): Promise<{
42
+ since: number;
43
+ stop(): Promise<Blob>;
44
+ }>;
45
+ /**
46
+ * The captured tab redrawn, frame by frame, on a canvas of exactly `size`: a browser captures a tab
47
+ * at its own size only. Scaled to fit with black bars, or to fill with the edges cut.
48
+ */
49
+ export declare function resizeTrack(track: MediaStreamTrack, size: {
50
+ width: number;
51
+ height: number;
52
+ }, fit: 'fit' | 'fill', frameRate: number): Promise<{
53
+ track: MediaStreamTrack;
54
+ stop: () => void;
55
+ }>;
56
+ /** A video's size from its lines on the short side and its shape; even numbers, as encoders want. */
57
+ export declare function videoSize(lines: number, aspect: '16:9' | '9:16' | '1:1'): {
58
+ width: number;
59
+ height: number;
60
+ };
61
+ export declare function extensionOf(blob: Blob): 'mp4' | 'webm';