@protomaze/demo-engine 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +2 -1
- package/README.md +201 -176
- package/agent/Guide.d.ts +1 -1
- package/agent/Guide.js +1 -1
- package/engine/DemoEngine.d.ts +35 -2
- package/engine/DemoEngine.js +1 -1
- package/engine/Player.d.ts +34 -5
- package/engine/Player.js +1 -1
- package/engine/Settings.d.ts +2 -0
- package/engine/Settings.js +1 -1
- package/index.d.ts +4 -0
- package/index.js +1 -1
- package/model/Demo.d.ts +2 -0
- package/model/Validate.js +1 -1
- package/package.json +1 -1
- package/speech/Pack.d.ts +27 -0
- package/speech/Pack.js +1 -0
- package/speech/Speech.d.ts +16 -1
- package/speech/Speech.js +1 -1
- package/store/Zip.d.ts +9 -0
- package/store/Zip.js +1 -0
- package/ui/EngineUI.js +1 -1
- package/ui/Library.js +1 -1
- package/ui/Presenter.d.ts +17 -0
- package/ui/Presenter.js +1 -0
- package/ui/Studio.js +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { DemoEngine } from '../engine/DemoEngine';
|
|
2
|
+
/**
|
|
3
|
+
* The presenter's own screen, in a window of its own - beside the slides' laptop, never in a video -
|
|
4
|
+
* or always on top (Document Picture-in-Picture, where the browser has it). The script with the
|
|
5
|
+
* sentence being said, notes for the presenter, what comes next, the clock, every step to go to.
|
|
6
|
+
* From a click: browsers open windows only then. Returns false where none could be opened.
|
|
7
|
+
*/
|
|
8
|
+
export declare function openPresenter(engine: DemoEngine, { onTop }?: {
|
|
9
|
+
onTop?: boolean;
|
|
10
|
+
}): Promise<boolean>;
|
|
11
|
+
/**
|
|
12
|
+
* The presenter's screen in a document of the app's choosing - a window it opened itself, a frame,
|
|
13
|
+
* its own panel's window - filling it. Its keys, a clicker's, drive the demo. Returns its unmount.
|
|
14
|
+
*/
|
|
15
|
+
export declare function mountPresenter(engine: DemoEngine, doc: Document, { compact }?: {
|
|
16
|
+
compact?: boolean;
|
|
17
|
+
}): () => void;
|
package/ui/Presenter.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e,{useEffect as t,useState as n}from"react";import{createRoot as r}from"react-dom/client";import{sayOf as a,sentences as s}from"../model/Demo.js";import{clock as p}from"../model/Timing.js";import{useEngine as o}from"./Hooks.js";import{Button as i}from"./Kit.js";import{UI_CSS as l}from"./Styles.js";export async function openPresenter(e,{onTop:t=!1}={}){let n=null;const r=window.documentPictureInPicture;if(t&&r&&(n=await r.requestWindow({width:460,height:380}).catch(()=>null)),n||(n=window.open("","protomaze-demo-presenter","popup,width=1000,height=700")),!n)return!1;if(n.document.getElementById("pde-presenter"))return n.focus(),!0;n.document.title="Presenter";const a=mountPresenter(e,n.document,{compact:t&&Boolean(r)});return n.addEventListener("pagehide",a,{once:!0}),!0}export function mountPresenter(t,n,{compact:a=!1}={}){const s=n.createElement("style");s.textContent=l+"\nhtml, body { margin: 0; height: 100%; background: #17181c; }\n.pde.presenter { position: fixed; inset: 0; display: grid; grid-template-rows: auto 1fr auto; gap: 14px; padding: 16px 20px; background: var(--bg); font-size: 16px; }\n.pde.presenter .top { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }\n.pde.presenter .clock { font: 600 30px ui-monospace, monospace; }\n.pde.presenter .clock small { font-size: 14px; color: var(--muted); font-weight: 400; margin-left: 6px; }\n.pde.presenter .middle { display: grid; grid-template-columns: 1fr 260px; gap: 18px; min-height: 0; }\n.pde.presenter .now { overflow: auto; display: flex; flex-direction: column; gap: 12px; min-height: 0; }\n.pde.presenter h2 { margin: 0; font-size: 22px; }\n.pde.presenter .script p { margin: 0 0 10px; font-size: 26px; line-height: 1.45; color: var(--muted); }\n.pde.presenter .script p.on { color: var(--fg); }\n.pde.presenter .script p.said { opacity: .55; }\n.pde.presenter .notes { border-left: 4px solid var(--accent); padding: 8px 14px; background: var(--panel); white-space: pre-wrap; font-size: 18px; border-radius: 0 8px 8px 0; }\n.pde.presenter .next { border-top: 1px solid var(--line); padding-top: 10px; color: var(--muted); }\n.pde.presenter .steps { overflow: auto; display: flex; flex-direction: column; gap: 2px; border-left: 1px solid var(--line); padding-left: 12px; }\n.pde.presenter .steps button { text-align: left; border: 0; background: none; padding: 6px 8px; border-radius: 6px; cursor: pointer; color: var(--muted); font-size: 14px; }\n.pde.presenter .steps button.on { background: var(--raised); color: var(--fg); box-shadow: inset 3px 0 0 var(--accent); }\n.pde.presenter .controls { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }\n.pde.presenter .controls .btn { height: 64px; min-width: 96px; font-size: 18px; border-radius: 12px; }\n.pde.presenter .controls .btn svg.i { width: 28px; height: 28px; }\n.pde.presenter.compact { padding: 10px; gap: 8px; font-size: 14px; }\n.pde.presenter.compact .middle { grid-template-columns: 1fr; }\n.pde.presenter.compact .steps { display: none; }\n.pde.presenter.compact .script p { font-size: 18px; }\n.pde.presenter.compact .controls .btn { height: 44px; min-width: 56px; }\n.pde.presenter .idle { display: flex; flex-direction: column; gap: 8px; overflow: auto; }\n",n.head.append(s);const p=n.createElement("div");p.id="pde-presenter",p.setAttribute("data-demo-ignore",""),n.body.append(p);const o=r(p);o.render(e.createElement(c,{engine:t,compact:a}));const i=e=>t.presenterKey(e);return n.defaultView?.addEventListener("keydown",i,!0),()=>{n.defaultView?.removeEventListener("keydown",i,!0),o.unmount(),p.remove(),s.remove()}}function c({engine:r,compact:l}){const c=o(r),[,d]=n(0);t(()=>{const e=setInterval(()=>d(e=>e+1),500);return()=>clearInterval(e)},[]);const m=c.session,u="pde presenter"+(l?" compact":"");if("playing"!==m.mode||m.checking)return e.createElement("div",{className:u,"data-theme":"dark"},e.createElement("div",{className:"top"},e.createElement("h2",null,"Presenter"),e.createElement("span",{className:"muted"},"ready"===m.mode?"Waiting for a click in the app’s window":"Nothing plays")),e.createElement("div",{className:"idle"},e.createElement("span",{className:"muted"},"Start a demo in the app (Present waits after each step). Its script, your notes and the controls show here; a clicker works in either window."),r.entriesNow().map(({demo:t})=>e.createElement("div",{key:t.id,className:"row"},e.createElement("span",{className:"grow"},t.title),e.createElement(i,{icon:"present",onClick:()=>{r.play(t,{waitForPresenter:!0})}},"Present")))),e.createElement("div",null));const{demo:g,step:x,player:f}=m,h=g.steps[x],w=g.steps[x+1],E=r.language(),v=h?s(a(h,E)):[],y=v.indexOf(m.caption),b=f.elapsed(),N=b-f.stepStartedAt,k=r.timing(g,E),P=k.steps.find(e=>e.step===x);return e.createElement("div",{className:u,"data-theme":"dark"},e.createElement("div",{className:"top"},e.createElement("span",{className:"clock"},p(b),e.createElement("small",null,"/ ",p(k.duration))),e.createElement("span",{className:"clock",style:{fontSize:20}},p(N),e.createElement("small",null,"step",P?`, ~${p(P.end-P.start)}`:"")),e.createElement("span",{className:"grow"}),e.createElement("span",{className:"muted"},g.title),e.createElement("span",{className:"badge accent"},x+1," / ",g.steps.length),m.waiting&&e.createElement("span",{className:"badge"},"waiting for you"),m.paused&&!m.waiting&&e.createElement("span",{className:"badge"},"paused"),m.catchingUp&&e.createElement("span",{className:"badge"},"catching up")),e.createElement("div",{className:"middle"},e.createElement("div",{className:"now"},e.createElement("h2",null,h?.title??`Step ${x+1}`),e.createElement("div",{className:"script"},v.length?v.map((t,n)=>e.createElement("p",{key:n,className:n===y?"on":y>=0&&n<y?"said":""},t)):e.createElement("p",null,"No narration: in your own words.")),h?.notes&&e.createElement("div",{className:"notes"},h.notes),w&&e.createElement("div",{className:"next"},e.createElement("strong",null,"Next: ",w.title??`step ${x+2}`),e.createElement("div",null,s(a(w,E))[0]??""))),e.createElement("div",{className:"steps"},g.steps.map((t,n)=>e.createElement("button",{key:n,type:"button",className:n===x?"on":"",disabled:m.filming,onClick:()=>r.goTo(n)},n+1,". ",t.title??(s(a(t,E))[0]??"").slice(0,40))))),e.createElement("div",{className:"controls"},e.createElement(i,{icon:"back",title:"This step again; pressed early, the one before (←, PageUp)",disabled:m.filming,onClick:()=>r.back()}),e.createElement(i,{icon:m.paused?"play":"pause",kind:"primary",onClick:()=>m.waiting?r.next():r.togglePause()},m.waiting?"Continue":m.paused?"Resume":"Pause"),e.createElement(i,{icon:"right",title:"Next step (→, PageDown)",onClick:()=>r.next()}),e.createElement(i,{icon:"stop",title:"Stop (Esc)",onClick:()=>r.stop()})))}
|
package/ui/Studio.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e,{useEffect as t,useMemo as a,useRef as n,useState as i}from"react";import{copyOf as l,sayOf as o,scenarioOf as s,sentences as r}from"../model/Demo.js";import{clock as c}from"../model/Timing.js";import{fileName as d}from"../store/Share.js";import{recordMicrophone as m}from"../video/Film.js";import{ActionRow as p,addActionItems as h,readAction as g}from"./Actions.js";import{useEngine as u}from"./Hooks.js";import{Button as v,Check as f,Menu as w,NumberField as E,Segmented as y}from"./Kit.js";import{Timeline as k}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:[]}),[M,T]=i(0),[J,U]=i(),[A,F]=i("steps"),[P,V]=i({json:"",scenario:""}),[B,z]=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(M,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)},he=()=>{const e=R.current.back.pop();e&&(R.current.forward.push(j),$(e))},ge=()=>{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 z(void 0),{...e,scenario:P.scenario};z(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)}},ye=e=>{d.play(j,{from:e,language:_})},ke=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),T(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(),ge()):(e.preventDefault(),he())},style:{height:be?void 0:K,display:Q?"none":void 0}},e.createElement("div",{className:"grip",onPointerDown:e=>{const t=e.clientY,a=K,n=e=>q(Math.max(180,Math.min(innerHeight-40,a+t-e.clientY))),i=()=>{window.removeEventListener("pointermove",n),window.removeEventListener("pointerup",i),q(e=>(localStorage.setItem(b,String(e)),e))};window.addEventListener("pointermove",n),window.addEventListener("pointerup",i)}}),e.createElement("div",{className:"head"},e.createElement("input",{className:"field",style:{width:240,fontWeight:600},value:j.title,title:"Title",onChange:e=>ue({title:e.target.value})}),e.createElement("input",{className:"field grow",style:{minWidth:120},placeholder:"Description: who it is for, what it shows",value:j.description??"",onChange:e=>ue({description:e.target.value})}),re.length>1&&e.createElement("select",{className:"field",title:"The language played, and timed",value:_,onChange:e=>ee(e.target.value)},re.map(t=>e.createElement("option",{key:t,value:t},t))),e.createElement("div",{className:"sep"}),!ne&&e.createElement(e.Fragment,null,e.createElement(v,{icon:"first",title:"Play from the start",disabled:ae,onClick:()=>ye(0)}),e.createElement(v,{icon:"play",kind:"primary",title:`Play from step ${le+1}`,disabled:ae,onClick:()=>ye(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&&(T(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:he}),e.createElement(v,{icon:"redo",kind:"bare",title:"Redo (Ctrl+Y)",disabled:0===R.current.forward.length,onClick:ge}),e.createElement(v,{icon:"save",kind:se?"primary":void 0,title:"Save here (Ctrl+S)",onClick:()=>{Ee()}},se?"Save":"Saved"),e.createElement(w,{title:"Share, export",icon:"share",items:[{label:"Download .demo.json",icon:"download",onClick:()=>d.downloadDemo(j)},{label:"Download scenario .md",icon:"download",onClick:()=>d.downloadDemo(j,"md")},{label:"Copy a link with the demo",icon:"link",onClick:()=>{d.link(j).then(e=>navigator.clipboard.writeText(e)).then(()=>d.say("Link copied: it opens the app with this demo."))}},{label:"Copy JSON",icon:"copy",onClick:()=>{navigator.clipboard.writeText(JSON.stringify({...j,scenario:void 0,savedAt:void 0},null,2)).then(()=>d.say("JSON copied."))}},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(y,{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,_)}),z(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(k,{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=>g(d,e),onPick:(e,t)=>{T(e),U(t),I&&Y(!1)}}),B&&e.createElement("div",{className:"error small",style:{padding:"4px 12px"}},B),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:()=>{T(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)]),T(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:h(d,e=>{ue({cleanup:[...j.cleanup??[],e]}),U((j.cleanup??[]).length)})})),e.createElement("div",{className:"small muted"},"Done after the demo - when it ends, or is stopped - quickly and unseen: filters cleared, what it opened closed, what it changed changed back. So it plays again, and the next one starts where it expects. What the app cannot undo itself, its start resets (the app's ",e.createElement("span",{className:"mono"},"start.go"),")."),(j.cleanup??[]).map((t,a)=>e.createElement(p,{key:`cleanup.${a}`,engine:d,action:t,index:a,count:(j.cleanup??[]).length,open:J===a,sentences:[],onOpen:()=>U(J===a?void 0:a),onChange:e=>ue({cleanup:(j.cleanup??[]).map((t,n)=>n===a?e:t)}),onMove:e=>{const t=[...j.cleanup??[]],n=a+e;n<0||n>=t.length||([t[a],t[n]]=[t[n],t[a]],ue({cleanup:t}),U(n))},onDuplicate:()=>ue({cleanup:[...(j.cleanup??[]).slice(0,a+1),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:()=>ke(-1)}),e.createElement(v,{icon:"down",small:!0,kind:"bare",title:"Later",disabled:le===ie.length-1,onClick:()=>ke(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)]),T(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)),T(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:h(d,e=>{fe({...Ne,actions:[...Ne.actions,e]}),U(Ne.actions.length)})})),0===Ne.actions.length&&e.createElement("div",{className:"muted small"},"None yet: add one, or record them (●) by doing them on the page."),Ne.actions.map((t,a)=>e.createElement(p,{key:`${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,h]=i(),g=r(n);return e.createElement("div",{className:"col",style:{gap:4}},e.createElement("div",{className:"row"},e.createElement("span",{className:"badge accent"},a),e.createElement("span",{className:"small muted grow"},g.length," sentence",1===g.length?"":"s",c?` · ${c}`:""),e.createElement(v,{icon:p?"stop":"listen",small:!0,kind:"bare",title:p?"Stop":"Listen, in the voice chosen",disabled:!n.trim(),onClick:()=>{(async()=>{if(p)return p();let e=!1,i=()=>{};h(()=>()=>{e=!0,i()}),t.speech.wake();for(const l of r(n)){if(e)break;d("Making the voice…");const n=await t.speech.say(l,a).catch(e=>{t.say(e.message,!0)});if(d(void 0),!n)break;i=n.stop,await n.done}d(void 0),h(void 0)})()}}),e.createElement(v,{icon:o?"stop":"mic",small:!0,kind:"bare",on:Boolean(o),title:o?"Stop, and write what was said":"Dictate: speak, then stop",onClick:()=>{(async()=>{if(o){s(void 0),d("Transcribing…");try{const e=(await t.transcribe(await o.stop(),a)).map(e=>e.text).join(" ").trim();e&&l([n.trim(),e].filter(Boolean).join(" "))}catch(e){t.say(e.message,!0)}d(void 0)}else try{s(await m())}catch(e){t.say(`Microphone: ${e.message}`,!0)}})()},style:o?{color:"var(--danger)"}:void 0})),e.createElement("textarea",{className:"field",rows:3,placeholder:`Narration (${a}): what the viewer should notice, a sentence a subtitle`,value:n,onChange:e=>l(e.target.value)}))}function 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"))))}
|
|
1
|
+
import e,{useEffect as t,useMemo as a,useRef as n,useState as i}from"react";import{copyOf as o,sayOf as l,scenarioOf as s,sentences as r}from"../model/Demo.js";import{clock as c}from"../model/Timing.js";import{fileName as d}from"../store/Share.js";import{recordMicrophone as m}from"../video/Film.js";import{ActionRow as p,addActionItems as h,readAction as g}from"./Actions.js";import{useEngine as u}from"./Hooks.js";import{Button as v,Check as f,Menu as w,NumberField as E,Segmented as k}from"./Kit.js";import{Timeline as y}from"./Timeline.js";const b="protomaze-demo-engine:studio-height";export function Studio({engine:d,theme:m}){const S=u(d),D=S.studio,[j,$]=i(()=>o(D.demo)),[L,O]=i(()=>JSON.stringify(D.demo)),T=n({back:[],forward:[]}),[R,M]=i(0),[J,U]=i(),[A,P]=i("steps"),[F,V]=i({json:"",scenario:""}),[z,B]=i(),[W,H]=i(new Map),[K,q]=i(()=>Number(localStorage.getItem(b))||Math.round(.46*innerHeight)),[I,Y]=i(!1),[G,Z]=i(!1),[Q,X]=i(!1),[_,ee]=i(()=>d.language()),te=S.session,ae="idle"!==te.mode,ne="playing"!==te.mode||te.checking?void 0:te,ie=j.steps,oe=Math.min(R,Math.max(0,ie.length-1)),le=ne&&ne.demo.id===j.id?ne.step:oe,se=JSON.stringify(j)!==L,re=a(()=>Array.from(new Set([...d.languages(),...d.languagesOf(j)])),[j]),ce=d.entriesNow().find(e=>e.demo.id===j.id),de=d.timing(j,_),me=S.lastRun?.json===JSON.stringify(j)&&S.lastRun.language===_,pe=(e,t=!0)=>{t&&(T.current.back.push(j),T.current.back.length>200&&T.current.back.shift(),T.current.forward=[]),$(e)},he=()=>{const e=T.current.back.pop();e&&(T.current.forward.push(j),$(e))},ge=()=>{const e=T.current.forward.pop();e&&(T.current.back.push(j),$(e))},ue=e=>pe({...j,...e}),ve=e=>ue({steps:e}),fe=e=>ve(ie.map((t,a)=>a===oe?e:t));t(()=>{D.recorded&&pe({...j,steps:D.recorded.steps})},[D.recorded?.at]);const we=()=>{const{demo:e,problems:t}=d.parse(F.json);if(e)return B(void 0),{...e,scenario:F.scenario};B(t.slice(0,4).map(e=>`${e.path||"demo"}: ${e.message}`).join(" · "))},Ee=async()=>{const e="text"===A?we():j;if(e)try{await d.save(e),$(e),O(JSON.stringify(e)),d.say(`Saved "${e.title}".`)}catch(e){d.say(e.message,!0)}},ke=e=>{d.play(j,{from:e,language:_})},ye=e=>{const t=oe+e;if(t<0||t>=ie.length)return;const a=[...ie];[a[oe],a[t]]=[a[t],a[oe]],ve(a),M(t)},be=I||Q||"recording"===te.mode||Boolean(ne),Ne=ie[oe],Ce=e=>{const t=de.steps.find(t=>t.step===e);return t?`${((t.end-t.start)/1e3).toFixed(1)} s`:""};return e.createElement("div",{className:"pde studio"+(be?" collapsed":""),"data-theme":m,"data-demo-ignore":!0,onKeyDown:e=>{if(!(e.ctrlKey||e.metaKey))return;const t=e.key.toLowerCase();"s"===t?(e.preventDefault(),Ee()):"z"!==t||e.shiftKey||"text"===A?("y"===t||"z"===t&&e.shiftKey)&&"text"!==A&&(e.preventDefault(),ge()):(e.preventDefault(),he())},style:{height:be?void 0:K,display:Q?"none":void 0}},e.createElement("div",{className:"grip",onPointerDown:e=>{const t=e.clientY,a=K,n=e=>q(Math.max(180,Math.min(innerHeight-40,a+t-e.clientY))),i=()=>{window.removeEventListener("pointermove",n),window.removeEventListener("pointerup",i),q(e=>(localStorage.setItem(b,String(e)),e))};window.addEventListener("pointermove",n),window.addEventListener("pointerup",i)}}),e.createElement("div",{className:"head"},e.createElement("input",{className:"field",style:{width:240,fontWeight:600},value:j.title,title:"Title",onChange:e=>ue({title:e.target.value})}),e.createElement("input",{className:"field grow",style:{minWidth:120},placeholder:"Description: who it is for, what it shows",value:j.description??"",onChange:e=>ue({description:e.target.value})}),re.length>1&&e.createElement("select",{className:"field",title:"The language played, and timed",value:_,onChange:e=>ee(e.target.value)},re.map(t=>e.createElement("option",{key:t,value:t},t))),e.createElement("div",{className:"sep"}),!ne&&e.createElement(e.Fragment,null,e.createElement(v,{icon:"first",title:"Play from the start",disabled:ae,onClick:()=>ke(0)}),e.createElement(v,{icon:"play",kind:"primary",title:`Play from step ${oe+1}`,disabled:ae,onClick:()=>ke(oe)})),!ne&&e.createElement(w,{title:"Present, guide, loop",icon:"present",items:[{label:`Present from step ${oe+1}: waits after each step, the presenter's screen beside it`,icon:"present",disabled:ae,onClick:()=>{d.present(j,{from:oe,language:_})}},{label:"The presenter's screen, always on top",icon:"present",onClick:()=>{d.openPresenter({onTop:!0})}},{label:`Guide from step ${oe+1}: the viewer does it`,icon:"guide",disabled:ae,onClick:()=>{d.guide(j,{from:oe,language:_})}},{label:"Loop it: an expo booth",icon:"loop",disabled:ae,onClick:()=>{d.loop([j])}}]}),ne&&e.createElement(e.Fragment,null,e.createElement(v,{icon:ne.paused?"play":"pause",kind:"primary",title:ne.waiting?"Continue":ne.paused?"Resume":"Pause",onClick:()=>ne.waiting?d.next():d.togglePause()}),e.createElement(v,{icon:"right",title:"Next step",onClick:()=>d.next()}),e.createElement(v,{icon:"stop",title:"Stop",onClick:()=>d.stop()})),e.createElement(v,{icon:"record",title:`Record new steps after step ${oe+1}`,disabled:ae,onClick:()=>{d.record({into:j,after:oe})},style:{color:"var(--danger)"}}),e.createElement(v,{icon:"film",title:"Film it: a video with narration and subtitles",disabled:ae,onClick:()=>{d.film(j,{language:_})}}),e.createElement(v,{icon:"check",title:"Check: plays it fast and silent, and marks what fails",disabled:ae,onClick:()=>{(async()=>{const e=await d.check(j);H(new Map(e.failures.map(e=>[`${e.step}.${e.index}`,e.error]))),e.ok?d.say(`Every step plays: ${c(e.duration)} at speed.`):d.say(e.failures.length?`${e.failures.length} action${1===e.failures.length?"":"s"} failed: in red.`:e.error??"Failed",!0);const t=e.failures[0];t&&(M(t.step),U(t.index))})()}}),e.createElement("div",{className:"sep"}),e.createElement(v,{icon:"undo",kind:"bare",title:"Undo (Ctrl+Z)",disabled:0===T.current.back.length,onClick:he}),e.createElement(v,{icon:"redo",kind:"bare",title:"Redo (Ctrl+Y)",disabled:0===T.current.forward.length,onClick:ge}),e.createElement(v,{icon:"save",kind:se?"primary":void 0,title:"Save here (Ctrl+S)",onClick:()=>{Ee()}},se?"Save":"Saved"),e.createElement(w,{title:"Share, export",icon:"share",items:[{label:"Download .demo.json",icon:"download",onClick:()=>d.downloadDemo(j)},{label:"Download scenario .md",icon:"download",onClick:()=>d.downloadDemo(j,"md")},{label:"Copy a link with the demo",icon:"link",onClick:()=>{d.link(j).then(e=>navigator.clipboard.writeText(e)).then(()=>d.say("Link copied: it opens the app with this demo."))}},{label:"Copy JSON",icon:"copy",onClick:()=>{navigator.clipboard.writeText(JSON.stringify({...j,scenario:void 0,savedAt:void 0},null,2)).then(()=>d.say("JSON copied."))}},{label:"Narration pack (.zip): no key, no download, for every viewer",icon:"listen",onClick:()=>{d.downloadPack(j)}},ce?.video&&{label:"Download the video",icon:"film",onClick:()=>d.downloadVideo(ce.video,j.title)},{heading:"This demo"},"edited"===ce?.origin&&{label:"Revert to the app’s version",icon:"undo",onClick:()=>{window.confirm("Drop the changes kept here?")&&d.remove(j.id)}},"here"===ce?.origin&&{label:"Delete",icon:"delete",onClick:()=>{window.confirm(`Delete "${j.title}"?`)&&d.remove(j.id)}}]}),e.createElement(k,{value:A,onChange:e=>{if(e!==A){if("text"===A){const e=we();if(!e)return;JSON.stringify(e)!==JSON.stringify(j)&&pe(e)}"text"===e&&(()=>{const{scenario:e,savedAt:t,...a}=j;V({json:JSON.stringify(a,null,2),scenario:j.scenario??s(j,_)}),B(void 0)})(),P(e)}},options:[["steps","Steps"],["text","Text"],["video","Video",ce?.video?"Its last video":"Not filmed yet"]]}),e.createElement(v,{icon:I?"maximize":"minimize",kind:"bare",title:I?"Unfold":"Fold",onClick:()=>Y(!I)}),e.createElement(v,{icon:"close",kind:"bare",title:"Close",onClick:()=>{se&&!window.confirm("Close without saving?")||d.closeStudio()}})),e.createElement(y,{demo:j,timing:de,measured:me,step:le,action:J,theme:m,accent:"#ffb300",playhead:ne&&ne.demo.id===j.id?()=>d.elapsed():void 0,read:e=>g(d,e),onPick:(e,t)=>{ne&&ne.demo.id===j.id&&d.goTo(e)||(M(e),U(t),I&&Y(!1))}}),z&&e.createElement("div",{className:"error small",style:{padding:"4px 12px"}},z),e.createElement("div",{className:"body"},"text"!==A&&e.createElement("div",{className:"steps"},ie.map((t,a)=>e.createElement("div",{key:a,className:["step",a===oe&&!G&&"on",ne&&a===le&&"playing"].filter(Boolean).join(" "),onClick:()=>{M(a),U(void 0),Z(!1),function(e){if("video"!==A)return;const t=ce?.video?.timing?.steps.find(t=>t.step===e),a=document.querySelector("protomaze-demo-engine")?.shadowRoot?.querySelector("video");t&&a&&(a.currentTime=t.start/1e3)}(a)}},e.createElement("span",{className:"n"},a+1),e.createElement("div",{className:"col grow",style:{gap:2}},e.createElement("div",{className:"row"},e.createElement("span",{className:"grow ellipsis",style:{fontWeight:500}},t.title||function(e,t){return r(l(e,t))[0]}(t,_)||"Untitled"),e.createElement("span",{className:"small muted"},Ce(a))),t.title&&e.createElement("span",{className:"say"},l(t,_)),e.createElement("span",{className:"small muted"},t.actions.length," action",1===t.actions.length?"":"s",t.pause?" · waits":"")))),e.createElement(v,{icon:"add",small:!0,onClick:()=>{ve([...ie.slice(0,oe+1),{say:{},actions:[]},...ie.slice(oe+1)]),M(oe+1),Z(!1)}},"New step"),e.createElement("div",{className:["step",G&&"on"].filter(Boolean).join(" "),style:{marginTop:6},onClick:()=>{Z(!0),U(void 0)},title:"Done after the demo, quickly and unseen, so the app is as it found it"},e.createElement("span",{className:"n"},"↺"),e.createElement("div",{className:"col grow",style:{gap:2}},e.createElement("span",{style:{fontWeight:500}},"Cleanup"),e.createElement("span",{className:"small muted"},(j.cleanup??[]).length," action",1===(j.cleanup??[]).length?"":"s"," after it, unseen")))),"steps"===A&&G&&e.createElement("div",{className:"pane"},e.createElement("div",{className:"row"},e.createElement("strong",{className:"grow"},"Cleanup"),e.createElement(w,{title:"Add an action",icon:"add",label:"Add",items:h(d,e=>{ue({cleanup:[...j.cleanup??[],e]}),U((j.cleanup??[]).length)})})),e.createElement("div",{className:"small muted"},"Done after the demo - when it ends, or is stopped - quickly and unseen: filters cleared, what it opened closed, what it changed changed back. So it plays again, and the next one starts where it expects. What the app cannot undo itself, its start resets (the app's ",e.createElement("span",{className:"mono"},"start.go"),")."),(j.cleanup??[]).map((t,a)=>e.createElement(p,{key:`cleanup.${a}`,engine:d,action:t,index:a,count:(j.cleanup??[]).length,open:J===a,sentences:[],onOpen:()=>U(J===a?void 0:a),onChange:e=>ue({cleanup:(j.cleanup??[]).map((t,n)=>n===a?e:t)}),onMove:e=>{const t=[...j.cleanup??[]],n=a+e;n<0||n>=t.length||([t[a],t[n]]=[t[n],t[a]],ue({cleanup:t}),U(n))},onDuplicate:()=>ue({cleanup:[...(j.cleanup??[]).slice(0,a+1),o(t),...(j.cleanup??[]).slice(a+1)]}),onDelete:()=>{ue({cleanup:(j.cleanup??[]).filter((e,t)=>t!==a)}),U(void 0)},picking:X}))),"steps"===A&&Ne&&!G&&e.createElement(e.Fragment,null,e.createElement("div",{className:"pane"},e.createElement("div",{className:"row"},e.createElement("strong",{className:"grow"},"Step ",oe+1," of ",ie.length),e.createElement(v,{icon:"up",small:!0,kind:"bare",title:"Earlier",disabled:0===oe,onClick:()=>ye(-1)}),e.createElement(v,{icon:"down",small:!0,kind:"bare",title:"Later",disabled:oe===ie.length-1,onClick:()=>ye(1)}),e.createElement(v,{icon:"duplicate",small:!0,kind:"bare",title:"Duplicate",onClick:()=>{ve([...ie.slice(0,oe+1),o(Ne),...ie.slice(oe+1)]),M(oe+1)}}),e.createElement(v,{icon:"delete",small:!0,kind:"bare",title:"Delete this step",disabled:ie.length<2,onClick:()=>{ve(ie.filter((e,t)=>t!==oe)),M(Math.max(0,oe-1))}})),e.createElement("input",{className:"field",placeholder:"Title, for the editor and the timeline",value:Ne.title??"",onChange:e=>fe(N(Ne,"title",e.target.value||void 0))}),re.map(t=>e.createElement(C,{key:t,engine:d,language:t,text:Ne.say[t]??"",onChange:e=>fe({...Ne,say:N(Ne.say,t,e||void 0)})})),e.createElement("textarea",{className:"field",rows:2,placeholder:"Notes for the presenter: on their screen only, never said or shown",value:Ne.notes??"",onChange:e=>fe(N(Ne,"notes",e.target.value||void 0))}),e.createElement("div",{className:"row",style:{flexWrap:"wrap",gap:12}},e.createElement("span",{className:"small muted"},"Hold after, ms"),e.createElement(E,{value:Ne.hold,width:70,placeholder:"0",onChange:e=>fe(N(Ne,"hold",e))}),e.createElement(f,{label:"Wait for the presenter after it",checked:Boolean(Ne.pause),onChange:e=>fe(N(Ne,"pause",e||void 0))}),e.createElement("span",{className:"small muted"},Ce(oe)))),e.createElement("div",{className:"pane",style:{flex:1.3}},e.createElement("div",{className:"row"},e.createElement("strong",{className:"grow"},"Actions"),e.createElement("span",{className:"small muted"},"played one after the other, while the narration speaks"),e.createElement(w,{title:"Add an action",icon:"add",label:"Add",items:h(d,e=>{fe({...Ne,actions:[...Ne.actions,e]}),U(Ne.actions.length)})})),0===Ne.actions.length&&e.createElement("div",{className:"muted small"},"None yet: add one, or record them (●) by doing them on the page."),Ne.actions.map((t,a)=>e.createElement(p,{key:`${oe}.${a}`,engine:d,action:t,index:a,count:Ne.actions.length,open:J===a,error:W.get(`${oe}.${a}`),sentences:r(l(Ne,_)),onOpen:()=>U(J===a?void 0:a),onChange:e=>((e,t)=>fe({...ie[oe],actions:ie[oe].actions.map((a,n)=>n===e?t:a)}))(a,e),onMove:e=>((e,t)=>{const a=e+t,n=[...ie[oe].actions];a<0||a>=n.length||([n[e],n[a]]=[n[a],n[e]],fe({...ie[oe],actions:n}),U(a))})(a,e),onDuplicate:()=>fe({...Ne,actions:[...Ne.actions.slice(0,a+1),o(t),...Ne.actions.slice(a+1)]}),onDelete:()=>{fe({...Ne,actions:Ne.actions.filter((e,t)=>t!==a)}),U(void 0)},picking:X})))),"text"===A&&e.createElement("div",{className:"pane",style:{flexDirection:"row"}},e.createElement("textarea",{className:"field mono grow",spellCheck:!1,value:F.json,onChange:e=>V({...F,json:e.target.value})}),e.createElement("textarea",{className:"field mono grow",spellCheck:!1,value:F.scenario,placeholder:"The scenario, for people (.md)",onChange:e=>V({...F,scenario:e.target.value})})),"video"===A&&e.createElement(x,{engine:d,draft:j})))}function N(e,t,a){const n={...e,[t]:a};return void 0===a&&delete n[t],n}function C({engine:t,language:a,text:n,onChange:o}){const[l,s]=i(),[c,d]=i(),[p,h]=i(),g=r(n);return e.createElement("div",{className:"col",style:{gap:4}},e.createElement("div",{className:"row"},e.createElement("span",{className:"badge accent"},a),e.createElement("span",{className:"small muted grow"},g.length," sentence",1===g.length?"":"s",c?` · ${c}`:""),e.createElement(v,{icon:p?"stop":"listen",small:!0,kind:"bare",title:p?"Stop":"Listen, in the voice chosen",disabled:!n.trim(),onClick:()=>{(async()=>{if(p)return p();let e=!1,i=()=>{};h(()=>()=>{e=!0,i()}),t.speech.wake();for(const o of r(n)){if(e)break;d("Making the voice…");const n=await t.speech.say(o,a).catch(e=>{t.say(e.message,!0)});if(d(void 0),!n)break;i=n.stop,await n.done}d(void 0),h(void 0)})()}}),e.createElement(v,{icon:l?"stop":"mic",small:!0,kind:"bare",on:Boolean(l),title:l?"Stop, and write what was said":"Dictate: speak, then stop",onClick:()=>{(async()=>{if(l){s(void 0),d("Transcribing…");try{const e=(await t.transcribe(await l.stop(),a)).map(e=>e.text).join(" ").trim();e&&o([n.trim(),e].filter(Boolean).join(" "))}catch(e){t.say(e.message,!0)}d(void 0)}else try{s(await m())}catch(e){t.say(`Microphone: ${e.message}`,!0)}})()},style:l?{color:"var(--danger)"}:void 0})),e.createElement("textarea",{className:"field",rows:3,placeholder:`Narration (${a}): what the viewer should notice, a sentence a subtitle`,value:n,onChange:e=>o(e.target.value)}))}function x({engine:n,draft:i}){const o=n.entriesNow().find(e=>e.demo.id===i.id),l=o?.video,s=a(()=>l&&{video:URL.createObjectURL(l.blob),vtt:URL.createObjectURL(new Blob([l.vtt],{type:"text/vtt"}))},[l]);if(t(()=>()=>{s&&(URL.revokeObjectURL(s.video),URL.revokeObjectURL(s.vtt))},[s]),!l||!s)return e.createElement("div",{className:"pane muted"},"Not filmed yet: film it (the film button) to make a video with narration and subtitles, kept here.");const r=l.json!==JSON.stringify({...i,scenario:void 0,savedAt:void 0})&&l.json!==JSON.stringify(i);return e.createElement("div",{className:"pane",style:{flexDirection:"row"}},e.createElement("div",{className:"grow",style:{minHeight:0,display:"flex"}},e.createElement("video",{src:s.video,controls:!0,style:{maxHeight:"100%"}},e.createElement("track",{kind:"subtitles",src:s.vtt,srcLang:l.language??"en",label:"Narration",default:!0}))),e.createElement("div",{className:"col",style:{width:240}},e.createElement("span",{className:"small muted"},new Date(l.at).toLocaleString()," · ",Math.round(l.blob.size/1e5)/10," MB · ",l.blob.type.split(";")[0]),r&&e.createElement("span",{className:"small error"},"Filmed from an older version of the demo."),e.createElement(v,{icon:"download",onClick:()=>n.downloadVideo(l,i.title)},"Video"),e.createElement(v,{icon:"subtitles",onClick:()=>n.downloadVideo(l,i.title,"vtt")},"Subtitles .vtt"),e.createElement(v,{icon:"subtitles",onClick:()=>n.downloadVideo(l,i.title,"srt")},"Subtitles .srt"),e.createElement(v,{icon:"share",onClick:()=>{n.shareVideo(l,i.title).then(e=>!e&&n.say("No share sheet here: download it instead."))}},"Share…"),l.voice&&e.createElement(v,{icon:"download",onClick:()=>n.downloadVideo({...l,blob:l.voice},`${i.title} voice`)},"The presenter's voice"),e.createElement(v,{icon:"delete",kind:"danger",onClick:()=>{n.store.deleteVideo(l.id)}},"Delete the video"),e.createElement("span",{className:"small muted"},d(i.title,l.blob.type.includes("mp4")?"mp4":"webm"))))}
|