@protomaze/demo-engine 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -2
- package/agent/Assistant.d.ts +83 -0
- package/agent/Assistant.js +1 -0
- package/engine/DemoEngine.d.ts +12 -0
- package/engine/DemoEngine.js +1 -1
- package/engine/Settings.d.ts +3 -0
- package/engine/Settings.js +1 -1
- package/index.d.ts +2 -0
- package/index.js +1 -1
- package/package.json +2 -1
- package/ui/Assistant.d.ts +9 -0
- package/ui/Assistant.js +1 -0
- package/ui/EngineUI.js +1 -1
- package/ui/Kit.d.ts +2 -0
- package/ui/Kit.js +1 -1
- package/ui/Library.js +1 -1
- package/ui/Studio.js +1 -1
- package/ui/Styles.d.ts +1 -1
- package/ui/Styles.js +1 -1
package/README.md
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Demos of a web app, made and played in the app itself, in the browser: no backend.
|
|
4
4
|
|
|
5
|
-
- **Make**: by
|
|
6
|
-
|
|
5
|
+
- **Make**: by asking Claude in the app, in words ("a one-minute tour of the orders"); by any AI that
|
|
6
|
+
runs JavaScript in the page (`window.demoEngine`); by recording what you do (and say); or by hand
|
|
7
|
+
in the studio, on a `@protomaze/time` timeline.
|
|
7
8
|
- **Narrate**: text to speech in the browser (Kokoro, Piper: free, no key) or ElevenLabs; speech to
|
|
8
9
|
text (Whisper in the browser, or ElevenLabs) turns what you said into narration and subtitles.
|
|
9
10
|
A **narration pack** keeps a demo's finished audio, so every viewer hears it without a key, tokens
|
|
@@ -56,6 +57,15 @@ recording's microphone; a booth's demos; where the presenter's screen goes - and
|
|
|
56
57
|
click sound and filming need. Everything else - the studio, the bars while playing and recording,
|
|
57
58
|
effects - the engine renders over the app, in the top layer.
|
|
58
59
|
|
|
60
|
+
**Ask Claude** (New → Ask Claude, a demo's ⋯ menu, the studio's ✦ button): people say what a demo
|
|
61
|
+
should show, or how to change, clone or translate one. Claude works in the app as they watch - looks
|
|
62
|
+
at the page, walks the path, writes the narration in every language, checks the demo twice, saves it
|
|
63
|
+
and opens it in the studio - with the tools an AI has on `window.demoEngine`. It runs in the browser
|
|
64
|
+
with the person's own Anthropic API key (kept in local storage, billed to them; the panel shows the
|
|
65
|
+
tokens and about what they cost): the app needs no backend, only `connect-src https://api.anthropic.com`
|
|
66
|
+
where it has a Content-Security-Policy. Claude Opus 5.5 at high effort, with the API's own fallback on
|
|
67
|
+
a refusal. `assistant: false` hides it.
|
|
68
|
+
|
|
59
69
|
From code: `engine.play(demo, { from })`, `engine.guide(demo)`, `engine.film(demo)`,
|
|
60
70
|
`engine.record()`, `engine.loop(demos, { idle, reset: 'reload' })`, `engine.check(demo)`,
|
|
61
71
|
`engine.openStudio(demo)`, `engine.link(demo)`. Sound and filming need a click in the app's window:
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { Demo } from '../model/Demo';
|
|
2
|
+
import type { DemoEngine } from '../engine/DemoEngine';
|
|
3
|
+
/** One line of the conversation, as the panel shows it. */
|
|
4
|
+
export type AssistantEntry = {
|
|
5
|
+
kind: 'you';
|
|
6
|
+
text: string;
|
|
7
|
+
} | {
|
|
8
|
+
kind: 'claude';
|
|
9
|
+
text: string;
|
|
10
|
+
}
|
|
11
|
+
/** A tool Claude used: what it did, in words. */
|
|
12
|
+
| {
|
|
13
|
+
kind: 'did';
|
|
14
|
+
text: string;
|
|
15
|
+
ok: boolean;
|
|
16
|
+
} | {
|
|
17
|
+
kind: 'error';
|
|
18
|
+
text: string;
|
|
19
|
+
};
|
|
20
|
+
export type AssistantState = {
|
|
21
|
+
open: boolean;
|
|
22
|
+
entries: AssistantEntry[];
|
|
23
|
+
working: boolean;
|
|
24
|
+
/** The demo asked about: named with each question. */
|
|
25
|
+
about?: {
|
|
26
|
+
id: string;
|
|
27
|
+
title: string;
|
|
28
|
+
};
|
|
29
|
+
/** Tokens this conversation: input, written to the cache, read from it, output. */
|
|
30
|
+
usage: Usage;
|
|
31
|
+
};
|
|
32
|
+
export type Usage = {
|
|
33
|
+
input: number;
|
|
34
|
+
written: number;
|
|
35
|
+
cached: number;
|
|
36
|
+
output: number;
|
|
37
|
+
};
|
|
38
|
+
/** About what a conversation cost, in US dollars, where the model's prices are known (per million tokens). */
|
|
39
|
+
export declare function costOf(usage: Usage, model: string): number | undefined;
|
|
40
|
+
export type ClaudeSettings = {
|
|
41
|
+
/** The person's own Anthropic API key, kept in this browser. */
|
|
42
|
+
key: string;
|
|
43
|
+
model: string;
|
|
44
|
+
effort: 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
45
|
+
};
|
|
46
|
+
export declare const DEFAULT_CLAUDE: ClaudeSettings;
|
|
47
|
+
export declare const EMPTY_ASSISTANT: AssistantState;
|
|
48
|
+
/**
|
|
49
|
+
* Claude, in the app: asked in words, it makes, clones and changes demos with the tools an AI has on
|
|
50
|
+
* `window.demoEngine` - looks at the page, tries the path, writes, checks, saves, opens it in the
|
|
51
|
+
* studio. From the browser, with the person's own Anthropic API key: no backend.
|
|
52
|
+
*/
|
|
53
|
+
export declare class Assistant {
|
|
54
|
+
private engine;
|
|
55
|
+
private settings;
|
|
56
|
+
private changed;
|
|
57
|
+
state: AssistantState;
|
|
58
|
+
private messages;
|
|
59
|
+
private abort;
|
|
60
|
+
private tools;
|
|
61
|
+
constructor(engine: DemoEngine, settings: () => ClaudeSettings, changed: (state: AssistantState) => void);
|
|
62
|
+
private update;
|
|
63
|
+
private add;
|
|
64
|
+
open(about?: Demo): void;
|
|
65
|
+
close(): void;
|
|
66
|
+
/** What the next questions are about; undefined for nothing in particular. */
|
|
67
|
+
setAbout(about: {
|
|
68
|
+
id: string;
|
|
69
|
+
title: string;
|
|
70
|
+
} | undefined): void;
|
|
71
|
+
/** A new conversation. */
|
|
72
|
+
clear(): void;
|
|
73
|
+
stop(): void;
|
|
74
|
+
/** Asks Claude; it works until it is done, stopped, or out of turns. */
|
|
75
|
+
ask(question: string): Promise<void>;
|
|
76
|
+
/** The conversation as the API takes it: a last turn's tool calls answered, or that turn dropped. */
|
|
77
|
+
private repair;
|
|
78
|
+
private count;
|
|
79
|
+
private system;
|
|
80
|
+
/** One tool call: run, its result as data, and a line saying what it did. */
|
|
81
|
+
private use;
|
|
82
|
+
private run;
|
|
83
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{describeTarget as e}from"../engine/Player.js";import{agentTools as t}from"./Agent.js";import{GUIDE as s}from"./Guide.js";const o={input:0,written:0,cached:0,output:0};export function costOf(e,t){const s={"claude-opus-5-5":[4,5,.2,20]}[t];if(s)return(e.input*s[0]+e.written*s[1]+e.cached*s[2]+e.output*s[3])/1e6}export const DEFAULT_CLAUDE={key:"",model:"claude-opus-5-5",effort:"high"};export const EMPTY_ASSISTANT={open:!1,entries:[],working:!1,usage:o};const a=/^claude-(opus-5|fable-5|sonnet-5-5|mythos-5)/,i=4e4,n={type:"object",description:"A whole demo, in the format the guide gives."},r=[["languages","The languages narration is written in (write: write every one), and the one it plays in now (plays).",{}],["start","Where the app is now, as a demo's `start`: a demo made now starts there. null if the app has none.",{}],["page","What is on the page to act on: targets ready for actions, with labels, states and boxes; also headings and open dialogs. `within` a css region, `query` text in the labels, `limit` at most (250).",{within:{type:"string"},query:{type:"string"},limit:{type:"integer"}}],["find","How many elements a target names, whether the one it means shows, its label and box.",{target:{type:"object",description:"A target: { css, text?, key?, index? } - see the guide.",properties:{css:{type:"string"},text:{type:"string"},key:{type:"string"},index:{type:"integer"}},required:["css"]}},["target"]],["describe","The target for an element: the first matching `css`, or the one at viewport point `x`, `y` (px).",{css:{type:"string"},x:{type:"number"},y:{type:"number"}}],["try","Does one action now, quickly, as a demo would (click, hover, type, key, select, drag, scroll, waitFor): to walk the path a demo takes and test its targets. Says what appeared and what went. It really happens in the app.",{action:{type:"object",description:"One action, as in a demo step."}},["action"]],["demos","The demos there are: id, title, steps, languages, duration, origin ('app': the app's own; 'edited': the app's, changed here; 'here': made here).",{}],["get","A demo, whole, by id: to read, clone or change it.",{id:{type:"string"}},["id"]],["validate","What is wrong with a demo's shape, [] if nothing. `check` plays it.",{demo:n},["demo"]],["estimate","How long a demo plays, about, and each step: a `demo`, or the `id` of a saved one.",{demo:n,id:{type:"string"}}],["check","Plays a demo fast and silent from its start, going past what fails, its cleanup after: a `demo`, or the `id` of a saved one. `ok` twice in a row: it plays, and undoes itself. `from`, `to`: steps, 0-based.",{demo:n,id:{type:"string"},from:{type:"integer"},to:{type:"integer"}}],["save","Keeps a demo in this browser: it shows in the library. The id of an app's demo changes that one, here, until removed: give a copy its own id.",{demo:n},["demo"]],["open","Opens a saved demo in the studio, for the person to see, play, tune and film: do it when a demo is done.",{id:{type:"string"}},["id"]]].map(([e,t,s,o])=>({name:e,description:t,input_schema:{type:"object",properties:s,...o?{required:o}:{}},eager_input_streaming:!0}));export class Assistant{constructor(e,s,o){this.engine=e,this.settings=s,this.changed=o,this.state=EMPTY_ASSISTANT,this.messages=[],this.tools=t(e)}update(e){this.state={...this.state,...e},this.changed(this.state)}add(e){this.update({entries:[...this.state.entries,e]})}open(e){this.update({open:!0,...e?{about:{id:e.id,title:e.title}}:{}})}close(){this.update({open:!1})}setAbout(e){this.update({about:e})}clear(){this.state.working||(this.messages=[],this.update({entries:[],usage:o}))}stop(){this.abort?.abort();const e=this.engine.getState().session;"playing"===e.mode&&e.checking&&this.engine.stop()}async ask(e){const t=e.trim();if(!t||this.state.working)return;const{key:s,model:o,effort:i}=this.settings();if(!s)return void this.add({kind:"error",text:"Add your Anthropic API key first."});const n=this.state.about?`\n\n(About the demo "${this.state.about.title}", id "${this.state.about.id}".)`:"";this.add({kind:"you",text:t}),this.messages.push({role:"user",content:t+n});const d=new AbortController;let h;this.abort=d,this.update({working:!0});try{h=await(import("@anthropic-ai/sdk"));const e=new h.Anthropic({apiKey:s,dangerouslyAllowBrowser:!0});let t=0;for(let s=0;s<60&&!d.signal.aborted;s++){const s=e.beta.messages.stream({model:o,max_tokens:64e3,output_config:{effort:i},cache_control:{type:"ephemeral"},system:this.system(),tools:r,messages:this.messages,...a.test(o)?{betas:["server-side-fallback-2026-07-01"],fallbacks:"default"}:{}},{signal:d.signal});let n,l=-1;s.on("text",(e,t)=>{const s=[...this.state.entries];l<0?(l=s.length,s.push({kind:"claude",text:t})):s[l]={kind:"claude",text:t},this.update({entries:s})});try{n=await s.finalMessage(),t=0}catch(e){if(e instanceof h.APIError||d.signal.aborted||t++>=2)throw e;continue}this.count(n.usage);const c=n.content.filter(e=>"text"===e.type).map(e=>e.text.trim()).filter(Boolean);if(l<0&&c.forEach(e=>this.add({kind:"claude",text:e})),"refusal"===n.stop_reason){this.add({kind:"error",text:"Claude declined this request."});break}const p=n.content.filter(e=>"tool_use"===e.type);if("pause_turn"===n.stop_reason){this.messages.push({role:"assistant",content:n.content});continue}if(0===p.length){this.messages.push({role:"assistant",content:n.content});break}if("max_tokens"===n.stop_reason){this.add({kind:"error",text:"The answer was cut off: ask for a smaller piece."});break}this.messages.push({role:"assistant",content:n.content});const u=[];for(const e of p)d.signal.aborted?u.push({type:"tool_result",tool_use_id:e.id,is_error:!0,content:"Stopped by the person."}):u.push(await this.use(e));this.messages.push({role:"user",content:u})}d.signal.aborted&&this.add({kind:"error",text:"Stopped."})}catch(e){d.signal.aborted||h&&e instanceof h.APIUserAbortError?this.add({kind:"error",text:"Stopped."}):h&&e instanceof h.AuthenticationError?this.add({kind:"error",text:"The API key was refused: check it in Key."}):h&&e instanceof h.RateLimitError?this.add({kind:"error",text:"Too many requests for now: try again in a minute."}):h&&e instanceof h.APIError?this.add({kind:"error",text:`Claude: ${e.status??""} ${e.message}`.trim()}):this.add({kind:"error",text:`Claude could not be reached: ${e.message}`})}finally{this.repair(),this.abort=void 0,this.update({working:!1})}}repair(){const e=this.messages[this.messages.length-1];"assistant"===e?.role&&Array.isArray(e.content)&&e.content.some(e=>"tool_use"===e.type)&&this.messages.pop()}count(e){const{input:t,written:s,cached:o,output:a}=this.state.usage;this.update({usage:{input:t+e.input_tokens,written:s+(e.cache_creation_input_tokens??0),cached:o+(e.cache_read_input_tokens??0),output:a+e.output_tokens}})}system(){const e=this.engine.options.app;return`You are Claude, working inside a web app${e?` ("${e}")`:""} for the person using it, through its demo engine. They asked you, in the app's "Ask Claude" panel, to make, clone or change demos of the app. You see the app only through your tools; the person watches the app while you work.\n\nYour tools are the ones the guide below calls on window.demoEngine: page, find, describe, try, demos, get, validate, estimate, check, save, open, languages, start. Call them as tools, not as JavaScript; help() is this guide.\n\n- try really acts in the app, with the person's data and session. Walk only the path a demo takes. Do not delete, send, pay, publish, or change settings or data beyond what the demo shows, unless the person asked for exactly that; when a demo would need it, say so and ask first.\n- A copy of a demo gets an id of its own. Save over a demo's id only to change that demo.\n- Check a demo until it is ok twice in a row (the second run proves its cleanup), save it, then open it in the studio.\n- Reply in the person's language, briefly: what you made or changed, how long it plays, anything that did not work. They see each tool you use, so do not list them.\n\n<guide>\n${s}\n</guide>`}async use(e){const t=e.input??{};try{const{result:s,did:o,ok:a}=await this.run(e.name,t);this.add({kind:"did",text:o,ok:a});let n=JSON.stringify(s??null);return n.length>i&&(n=`${n.slice(0,i)}\n[Cut at 40000 characters: narrow it down (page: query, within or limit).]`),{type:"tool_result",tool_use_id:e.id,content:n,...a?{}:{is_error:!0}}}catch(t){return this.add({kind:"did",text:`${e.name}: ${t.message}`,ok:!1}),{type:"tool_result",tool_use_id:e.id,is_error:!0,content:t.message}}}async run(t,s){const o=this.tools,a=e=>"string"==typeof s[e]?s[e]:void 0,i=e=>"number"==typeof s[e]?s[e]:void 0,n=e=>s[e]&&"object"==typeof s[e]?s[e]:void 0,r=n("demo"),d=()=>{const e=r??a("id");if(!e)throw new Error("Give a demo or an id");return e},h=async e=>`“${"string"==typeof e?(await o.get(e).catch(()=>{}))?.title??e:e.title}”`;switch(t){case"languages":return{result:o.languages(),did:"Read the languages",ok:!0};case"start":return{result:o.start(),did:"Noted where the app is",ok:!0};case"page":{const e=a("query"),t=a("within");return{result:o.page({query:e,within:t,limit:i("limit")}),did:`Looked at the page${e?` for “${e}”`:""}${t?` in ${t}`:""}`,ok:!0}}case"find":{const t=n("target");if(!t)throw new Error("Give a target");const s=o.find(t);return{result:s,did:`Looked for ${e(t)}: ${s.matches?s.shown?"there":"not showing":"none"}`,ok:!0}}case"describe":{const e=a("css"),[t,s]=[i("x"),i("y")],n=e??(void 0!==t&&void 0!==s?[t,s]:void 0);if(!n)throw new Error("Give css, or x and y");const r=o.describe(n);return{result:r,did:"Named "+(r.label?`“${r.label}”`:`a ${r.tag}`),ok:!0}}case"try":{const t=n("action");if(!t||"string"!=typeof t.do)throw new Error("Give an action: { do, ... }");const s=await o.try(t),a="target"in t&&t.target?` ${e(t.target)}`:"";return{result:s,did:`Tried: ${t.do}${a}${s.ok?"":` (${s.error})`}`,ok:s.ok}}case"demos":return{result:await o.demos(),did:"Listed the demos",ok:!0};case"get":{const e=a("id");if(!e)throw new Error("Give an id");const t=await o.get(e);return{result:t,did:`Read “${t.title}”`,ok:!0}}case"validate":{if(!r)throw new Error("Give a demo");const e=o.validate(r);return{result:e,did:e.length?`Its shape: ${e.length} problem${1===e.length?"":"s"}`:"Its shape: fine",ok:0===e.length}}case"estimate":{const e=d(),t=await o.estimate(e);return{result:t,did:`Timed ${await h(e)}: ${t.duration}`,ok:!0}}case"check":{const e=d(),t=await o.check(e,{from:i("from"),to:i("to")}),s=t.failures.length+t.problems.length;return{result:t,did:`Played ${await h(e)} through: ${t.ok?"ok":t.error??`${s} failed`}`,ok:t.ok}}case"save":{if(!r)throw new Error("Give a demo");const e=await o.save(r);return{result:e,did:e.ok?`Saved “${r.title}”`:`Not saved: ${e.problems?.length} problems`,ok:e.ok}}case"open":{const e=a("id");if(!e)throw new Error("Give an id");const t=await o.open(e),s=(await o.get(e)).title;return this.update({about:{id:e,title:s}}),{result:t,did:`Opened “${s}” in the studio`,ok:!0}}default:throw new Error(`No tool "${t}"`)}}}
|
package/engine/DemoEngine.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { NarrationPack } from '../speech/Pack';
|
|
|
11
11
|
import { PlayOptions, Player, PlayResult, PlayState } from './Player';
|
|
12
12
|
import type { DemoPlugin } from './Plugin';
|
|
13
13
|
import { RecordState } from './Recorder';
|
|
14
|
+
import { Assistant, AssistantState } from '../agent/Assistant';
|
|
14
15
|
import { DEFAULT_SETTINGS, DemoSettings } from './Settings';
|
|
15
16
|
export type DemoStart = {
|
|
16
17
|
/** Where the app is now, as a demo recorded here starts. */
|
|
@@ -48,6 +49,11 @@ export type DemoEngineOptions = {
|
|
|
48
49
|
theme?: 'light' | 'dark' | 'auto';
|
|
49
50
|
/** Tools for an AI on `window[agent]`: 'demoEngine' by default; false for none. */
|
|
50
51
|
agent?: string | false;
|
|
52
|
+
/**
|
|
53
|
+
* "Ask Claude": people make, clone and change demos in words, in the app, with their own
|
|
54
|
+
* Anthropic API key (kept in their browser; the app needs no backend). On by default; false for none.
|
|
55
|
+
*/
|
|
56
|
+
assistant?: boolean;
|
|
51
57
|
/** A "Demos" button on the page opening the library: for apps without a panel of their own. */
|
|
52
58
|
launcher?: boolean;
|
|
53
59
|
/**
|
|
@@ -166,6 +172,8 @@ export type EngineState = {
|
|
|
166
172
|
dialog?: DialogRequest;
|
|
167
173
|
/** The library: its demos or its settings; the launcher's floating one shows while set. */
|
|
168
174
|
library?: 'demos' | 'settings';
|
|
175
|
+
/** "Ask Claude": its panel, conversation and tokens. */
|
|
176
|
+
assistant: AssistantState;
|
|
169
177
|
};
|
|
170
178
|
export type LoopOptions = {
|
|
171
179
|
/** ms of no input before the loop plays again, after a visitor. Default the setting, 30 s. */
|
|
@@ -204,6 +212,8 @@ export declare class DemoEngine {
|
|
|
204
212
|
readonly speech: Speech;
|
|
205
213
|
readonly store: Store;
|
|
206
214
|
readonly plugins: DemoPlugin[];
|
|
215
|
+
/** "Ask Claude": demos made and changed in words. */
|
|
216
|
+
readonly assistant: Assistant;
|
|
207
217
|
private state;
|
|
208
218
|
private listeners;
|
|
209
219
|
private settingsKey;
|
|
@@ -310,6 +320,8 @@ export declare class DemoEngine {
|
|
|
310
320
|
openSettings(): void;
|
|
311
321
|
/** The library's view; undefined closes the launcher's floating one. */
|
|
312
322
|
showLibrary(view: 'demos' | 'settings' | undefined): void;
|
|
323
|
+
/** "Ask Claude"'s panel; `about` a demo, named with each question. Not where the app turned it off. */
|
|
324
|
+
openAssistant(about?: Demo): void;
|
|
313
325
|
/** To a step of what plays (0-based): forward or back. False where it cannot (filmed). */
|
|
314
326
|
goTo(step: number): boolean;
|
|
315
327
|
/**
|
package/engine/DemoEngine.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{copyOf as e,languagesOf as t,newDemo as s,sayOf as i,scenarioOf as o,sentences as n}from"../model/Demo.js";import{parseSubtitles as a,toSrt as r,toVtt as h}from"../model/Subtitles.js";import{actionTime as p,estimate as l}from"../model/Timing.js";import{parseDemo as d,validate as c}from"../model/Validate.js";import{Hand as m}from"../page/Input.js";import{Overlay as g}from"../page/Overlay.js";import{stillPage as u}from"../page/Still.js";import{Targets as y}from"../page/Targets.js";import{Speech as f}from"../speech/Speech.js";import{narrationFor as w,transcribe as v}from"../speech/Transcribe.js";import{Store as k}from"../store/Store.js";import{demoFromLink as S,download as b,fileName as P,linkTo as T,shareFiles as x}from"../store/Share.js";import{extensionOf as E,recordMicrophone as R,startFilming as j,videoSize as $}from"../video/Film.js";import{renderMusic as M}from"../speech/Music.js";import{readPack as L,writePack as K}from"../speech/Pack.js";import{Player as N}from"./Player.js";import{Recorder as B}from"./Recorder.js";import{readAction as D}from"./Read.js";import{mountUI as I}from"../ui/EngineUI.js";import{agentTools as O}from"../agent/Agent.js";import{openPresenter as A}from"../ui/Presenter.js";import{DEFAULT_RELAY as F,qrSvg as C,RemoteLink as J}from"../remote/Remote.js";import{DEFAULT_SETTINGS as U,loadSettings as z,saveSettings as V}from"./Settings.js";const Q=["pointerdown","pointerup","pointermove","pointerover","pointerout","mousedown","mouseup","mousemove","mouseover","mouseout","click","dblclick","contextmenu","wheel","touchstart","touchmove","touchend","keydown","keyup","keypress"];export class DemoEngine{constructor(e){this.options=e,this.listeners=new Set,this.packs=new Map,this.remoteSent="",this.remoteTimer=0,this.getState=()=>this.state,this.subscribe=e=>(this.listeners.add(e),()=>this.listeners.delete(e)),this.hintTimer=0,this.targets=new y({...e.targets,labels:e.labels}),this.overlay=new g(e.overlay),this.hand=new m(this.overlay.cursor,()=>this.player?.speedNow??1),this.settingsKey=`protomaze-demo-engine:${e.app}:settings`,this.state={session:{mode:"idle"},settings:z(this.settingsKey),speech:{}},this.speech=new f(()=>this.state.settings.speech,()=>this.set({speech:{...this.speech.state}})),this.store=new k(`protomaze-demo-engine:${e.app}`),this.store.subscribe(()=>this.emit()),this.plugins=e.plugins??[]}emit(){this.state={...this.state},this.listeners.forEach(e=>e()),this.toRemote()}set(e){this.state={...this.state,...e},this.listeners.forEach(e=>e()),this.toRemote()}setSession(e){this.set({session:e})}updateSession(e,t){this.state.session.mode===e&&this.setSession({...this.state.session,...t})}say(e,t=!1){this.set({message:e?{text:e,error:t}:void 0})}changeSettings(e){const t={...this.state.settings,...e};V(this.settingsKey,t),this.set({settings:t}),e.music?.on&&this.loadMusic().catch(()=>{})}language(){const e=this.state.settings.language;return"page"!==e?e:this.options.language?.()??this.options.languages?.[0]??(navigator.language.split("-")[0]||"en")}languages(){return this.options.languages??[this.language()]}pluginKinds(){return this.plugins.flatMap(e=>Object.keys(e.actions??{}))}pluginAction(e){return this.plugins.map(t=>t.actions?.[e]).find(Boolean)}read(e,t){return D(e,this.options.labels,this.plugins,t)}async mount(){if(this.unmount)return;this.overlay.mount();const e=I(this),t=e=>this.key(e);window.addEventListener("keydown",t,!0);const s=e=>this.gate(e);Q.forEach(e=>window.addEventListener(e,s,{capture:!0,passive:!1})),this.state.settings.music.on&&this.loadMusic().catch(()=>{});const i=!1===this.options.agent?void 0:this.options.agent??"demoEngine";i&&(window[i]=O(this)),this.unmount=()=>{e(),window.removeEventListener("keydown",t,!0),Q.forEach(e=>window.removeEventListener(e,s,{capture:!0})),i&&delete window[i],this.overlay.unmount()},await this.arrived()}destroy(){this.closeRemote(),this.stopLoop(),this.stop(),this.unmount?.(),this.unmount=void 0}async arrived(){const e=sessionStorage.getItem(this.pendingKey());if(sessionStorage.removeItem(this.pendingKey()),e){const{demo:t,verb:s,from:i,loop:o}=JSON.parse(e);return"loop"===s&&o?void this.loop(o.demos,{gap:o.gap,idle:o.idle,reset:o.reload?"reload":void 0},o.index):this.whenClicked(t.title,"film"===s?"Film":"Play",()=>"film"===s?this.film(t):this.play(t,{from:i}),!0)}const t=await S();if(t){const e=c(t,this.pluginKinds());return e.length?this.say(`The link's demo: ${e[0].path} ${e[0].message}`,!0):(await this.save(t),this.say(`"${t.title}" came with the link: it is kept here.`),this.openStudio(t))}const s=new URL(window.location.href),i=s.searchParams.get("demo");if(i){s.searchParams.delete("demo"),window.history.replaceState(window.history.state,"",s.toString());const e=(await this.entries()).find(e=>e.demo.id===i);e&&this.whenClicked(e.demo.title,"Play",()=>this.play(e.demo),!0)}}gate(e){const t=this.state.session;if(!e.isTrusted||"playing"!==t.mode||t.paused||t.looping)return;const s=e.composedPath();if(s.includes(this.overlay.host))return;if(t.guided&&t.instruction){const i=t.player.viewerTarget();if(i&&(s.includes(i)||e instanceof KeyboardEvent&&i.contains(document.activeElement)))return;if(!i&&e instanceof KeyboardEvent)return}const i=e.defaultPrevented;e.cancelable&&e.preventDefault(),e.stopImmediatePropagation(),i||"pointerdown"!==e.type&&"keydown"!==e.type&&"wheel"!==e.type||this.hint(t.guided?'Only the ringed part now: or "Do it for me"':"Playing: Space pauses, and the app is yours then. Esc stops.")}hint(e){window.clearTimeout(this.hintTimer),this.set({hint:e}),this.hintTimer=window.setTimeout(()=>this.set({hint:void 0}),3e3)}pendingKey(){return`protomaze-demo-engine:${this.options.app}:pending`}key(e){if(!e.isTrusted)return;const t=e.composedPath(),s=t.some(e=>e instanceof HTMLElement&&(e.isContentEditable||e.matches("input, textarea, select"))),i=t.includes(this.overlay.host),o=this.state.session,n=()=>{e.preventDefault(),e.stopPropagation()};if("ready"!==o.mode)if("recording"!==o.mode){if("l"===e.key.toLowerCase()&&e.ctrlKey&&e.shiftKey&&this.looping)return n(),this.stopLoop();if(!("playing"!==o.mode||o.looping||o.checking||s&&(i||o.guided&&o.instruction))){if("Escape"===e.key)this.stop();else if(" "===e.key||"b"===e.key||"."===e.key)this.togglePause();else if("ArrowRight"===e.key||"Enter"===e.key||"PageDown"===e.key)o.player.next();else if("ArrowLeft"===e.key||"PageUp"===e.key)o.player.back();else if("Home"===e.key)o.player.goTo(0);else if("End"===e.key)o.player.goTo(o.steps-1);else{if(!/^[1-9]$/.test(e.key)||e.ctrlKey||e.metaKey||e.altKey)return;o.player.goTo(Number(e.key)-1)}n()}}else"Escape"!==e.key||s||(n(),this.stopRecording?.());else"Escape"===e.key&&(n(),o.cancel())}async entries(){return await this.store.ready(),this.entriesNow()}entriesNow(){const{demos:e,videos:t}=this.store.get(),s=new Map(e.map(e=>[e.id,e])),i=this.language(),n=(this.options.demos??[]).map(e=>"demo"in e?e:{demo:e,scenario:void 0});return[...n.map(({demo:e,scenario:n})=>{const a=s.get(e.id);return a?{demo:a,scenario:a.scenario??n??o(a,i),origin:"edited",video:t.get(e.id)}:{demo:e,scenario:n??o(e,i),origin:"app",video:t.get(e.id)}}),...e.filter(e=>!n.some(t=>t.demo.id===e.id)).map(e=>({demo:e,scenario:e.scenario??o(e,i),origin:"here",video:t.get(e.id)}))]}async save(t){const s=c(t,this.pluginKinds());if(s.length)throw new Error(`Not a demo: ${s.map(e=>`${e.path} ${e.message}`).join("; ")}`);await this.store.saveDemo(e(t))}async remove(e){await this.store.deleteDemo(e),this.state.studio?.demo.id===e&&this.closeStudio()}parse(e){return d(e,this.pluginKinds())}create(e){return s(e,this.options.start?.current())}openStudio(t){this.set({studio:{demo:e(t),opened:Date.now()}})}closeStudio(){this.set({studio:void 0})}activated(){const e=navigator.userActivation;return!e||e.isActive}whenClicked(e,t,s,i=!1){const o=()=>{this.setSession({mode:"idle"}),this.speech.wake(),s().catch(e=>this.say(e.message,!0))};if(!i&&this.activated())return o();this.setSession({mode:"ready",title:e,verb:t,go:o,cancel:()=>this.setSession({mode:"idle"})})}async goToStart(e,t,s,i){if(!e.start||!this.options.start)return!0;sessionStorage.setItem(this.pendingKey(),JSON.stringify({demo:e,verb:t,from:s,loop:i}));return"reload"!==await this.options.start.go(e.start)&&(sessionStorage.removeItem(this.pendingKey()),!0)}busy(){return"idle"!==this.state.session.mode&&"ready"!==this.state.session.mode}play(e,t={}){return new Promise(s=>this.whenClicked(e.title,"Play",async()=>{if(this.busy())return s(void 0);if(this.say(void 0),!await this.goToStart(e,"play",t.from))return s(void 0);const i=await this.run(e,t);s(i)}))}async run(e,t={}){const{settings:s}=this.state,i=t.language??this.language(),o=s.music.on&&!t.checking&&!t.guided&&await Promise.race([this.loadMusic(),new Promise(e=>setTimeout(()=>e(!1),t.filming?6e4:1500))]);this.speech.setPack(s.usePacks?await this.pack(e):void 0);const n=new N(e,{language:i,subtitles:s.subtitles,waitForPresenter:s.waitForPresenter&&!t.looping,catchUp:s.catchUp,music:Boolean(o),...t},{hand:this.hand,targets:this.targets,overlay:this.overlay,speech:this.speech,plugins:this.plugins,ready:this.options.ready,read:(e,t)=>this.read(e,t),reset:async()=>!e.start||!this.options.start||"reload"!==await this.options.start.go(e.start),update:e=>this.updateSession("playing",e)});this.setSession({mode:"playing",title:e.title,demo:e,steps:e.steps.length,filming:Boolean(t.filming),checking:Boolean(t.checking),guided:Boolean(t.guided),looping:Boolean(t.looping),presenting:Boolean(t.presenting),player:n,step:t.from??0,caption:"",paused:!1,waiting:!1,catchingUp:!1}),this.player=n;const a=await n.play().finally(()=>this.player=void 0);return this.setSession({mode:"idle"}),t.checking||a.navigated||(this.set({lastRun:{json:JSON.stringify(e),language:i,timing:a.timing}}),a.error&&"Stopped."!==a.error&&this.say(a.error,!0)),a}stop(){const e=this.state.session;"playing"===e.mode&&e.player.stop(),"recording"===e.mode&&this.stopRecording?.(),"ready"!==e.mode&&"preparing"!==e.mode||this.setSession({mode:"idle"})}togglePause(){const e=this.state.session;"playing"===e.mode&&(e.paused?e.player.resume():e.player.pause())}resume(){const e=this.state.session;"playing"===e.mode&&e.player.resume()}next(){const e=this.state.session;"playing"===e.mode&&e.player.next()}back(){const e=this.state.session;"playing"===e.mode&&e.player.back()}openPresenter(e={}){return A(this,e)}presenterKey(e){this.key(e)}present(e,t={}){this.openDialog({kind:"present",demo:e,from:t.from})}openDialog(e){this.set({dialog:e,...this.state.library&&this.options.launcher?{library:void 0}:{}})}closeDialog(){this.set({dialog:void 0})}openSettings(){this.set({library:"settings"})}showLibrary(e){this.set({library:e})}goTo(e){const t=this.state.session;return"playing"===t.mode&&t.player.goTo(e)}guide(e,t={}){return this.play(e,{...t,guided:!0})}doItForMe(){const e=this.state.session;"playing"===e.mode&&e.player.doItForMe()}async openRemote(){if(!1===this.options.remote)throw new Error("No phone remote in this app");if(this.state.remote)return this.state.remote;const e=this.options.remote?.relay??F;this.remoteLink=await J.open(e,{command:e=>this.fromRemote(e),hello:()=>this.remoteSent="",peers:e=>this.state.remote&&this.set({remote:{...this.state.remote,peers:e}})});const t={url:this.remoteLink.url,svg:C(this.remoteLink.url),peers:0};return this.set({remote:t}),this.remoteTimer=window.setInterval(()=>this.toRemote(!0),1e3),t}closeRemote(){window.clearInterval(this.remoteTimer),this.remoteLink?.close(),this.remoteLink=void 0,this.remoteSent="",this.set({remote:void 0})}fromRemote(e){const t=this.state.session;"playing"===t.mode&&("next"===e.do?t.player.next():"back"===e.do?t.player.back():"goto"===e.do&&void 0!==e.step?t.player.goTo(e.step):"stop"===e.do?this.stop():"toggle"===e.do&&(t.waiting?t.player.next():this.togglePause()))}toRemote(e=!1){if(!this.remoteLink)return;const t=this.remoteState(),{at:s,elapsed:i,stepElapsed:o,...n}=t,a=JSON.stringify(n);(a!==this.remoteSent||e&&t.playing)&&(this.remoteSent=a,this.remoteLink.send(t))}remoteState(){const e=this.state.session,t=Date.now();if("playing"!==e.mode||e.checking)return{playing:!1,title:"",steps:[],step:0,caption:"",paused:!1,waiting:!1,filming:!1,elapsed:0,stepElapsed:0,planned:0,at:t};const s=this.language(),o=this.timing(e.demo,s),a=o.steps.find(t=>t.step===e.step),r=e.player.elapsed();return{playing:!0,title:e.demo.title,steps:e.demo.steps.map((e,t)=>({title:e.title??`Step ${t+1}`,script:n(i(e,s)),...e.notes?{notes:e.notes}:{}})),step:e.step,caption:e.caption,paused:e.paused,waiting:e.waiting,filming:e.filming,elapsed:r,stepElapsed:r-e.player.stepStartedAt,planned:o.duration,...a?{plannedStep:a.end-a.start}:{},at:t}}pack(e){let t=this.packs.get(e.id);return t||(t=(async()=>{const t=await this.store.asset(`narration:${e.id}`);if(t)return L(await t.arrayBuffer());const s=this.options.narration?.(e);if(!s)return;const i=await fetch(s);return i.ok?L(await i.arrayBuffer()):void 0})().catch(()=>{}),this.packs.set(e.id,t)),t}async makePack(e,s=()=>{}){const i=await this.pack(e);this.speech.setPack(i);const o=t(e).flatMap(t=>e.steps.flatMap(e=>n(e.say[t]??"").map(e=>({language:t,text:e})))),a=o.filter((e,t)=>o.findIndex(t=>t.language===e.language&&t.text===e.text)===t),r=[];for(const e of a)s(r.length,a.length),r.push({...await this.speech.packable(e.text,e.language),...e});s(r.length,a.length);const h=K(e.id,r);return await this.store.saveAsset(`narration:${e.id}`,h),this.packs.delete(e.id),h}async downloadPack(e){try{const t=await this.makePack(e,(e,t)=>this.say(`Making the narration pack: ${e} / ${t}`));b(t,`${e.id}.narration.zip`),this.say(`Narration pack: ${Math.round(t.size/1e5)/10} MB, kept here too. Check it in beside ${e.id}.demo.json, for every viewer.`)}catch(e){this.say(`Narration pack: ${e.message}`,!0)}}async dropPack(e){await this.store.saveAsset(`narration:${e.id}`,void 0),this.packs.delete(e.id)}async setMusic(e){await this.store.saveAsset("music",e),this.musicLoaded=void 0;const{music:t}=this.state.settings;this.changeSettings({music:e?{...t,on:!0,track:"file",name:e.name??"music"}:{...t,track:"calm",name:void 0}})}async loadMusic(){const{music:e}=this.state.settings,t="file"===e.track?`file:${e.name}`:e.track;if(this.musicLoaded!==t){if("file"===e.track){const t=await this.store.asset("music");if(!t)return!1;await this.speech.setMusic(t,e.volume).catch(()=>{})}else this.speech.setMusicBuffer(await M(e.track),e.volume);this.musicLoaded=t}return this.speech.setMusicVolume(e.volume),this.speech.hasMusic}async listenToMusic(e=20){if(this.speech.wake(),!await this.loadMusic())return()=>{};this.speech.startMusic();const t=setTimeout(()=>this.speech.stopMusic(),1e3*e);return()=>{clearTimeout(t),this.speech.stopMusic(.6)}}async loop(e,t={},s=0){if(0===e.length)return;this.stopLoop();let i=!1,o=0,n=s;const a=t.idle??this.state.settings.loopIdle,r=t.gap??1500,h=e.map(e=>e.title),p=e=>{if(!e.isTrusted||e.composedPath().includes(this.overlay.host))return;o=performance.now();const t=this.state.session;"playing"===t.mode&&t.looping&&t.player.stop(!0)},l=["pointerdown","keydown","wheel","touchstart"];l.forEach(e=>window.addEventListener(e,p,{capture:!0,passive:!0}));this.looping={demos:e,options:t,stop:()=>{i=!0,l.forEach(e=>window.removeEventListener(e,p,{capture:!0}));const e=this.state.session;"playing"===e.mode&&e.looping&&e.player.stop(),this.set({loop:void 0})}};const d=e=>new Promise(t=>setTimeout(t,e));for(;!i;){const s=e[n%e.length];this.set({loop:{titles:h,index:n%e.length,visitor:!1}});if(!await this.goToStart(s,"loop",void 0,{demos:e,index:n%e.length,gap:t.gap,idle:t.idle,reload:"reload"===t.reset})||i)return;const p=await this.run(s,{looping:!0,catchUp:!1});if(i)break;if(p.error&&performance.now()-o<1e3){for(;!i&&performance.now()-o<a;)this.set({loop:{titles:h,index:n%e.length,visitor:!0,resumesAt:Date.now()+a-(performance.now()-o)}}),await d(1e3);if(i)break;if("reload"===t.reset)return sessionStorage.setItem(this.pendingKey(),JSON.stringify({demo:s,verb:"loop",loop:{demos:e,index:n%e.length,gap:t.gap,idle:t.idle,reload:!0}})),window.location.reload();await(t.reset?.())}else n++,await d(r)}}stopLoop(){this.looping?.stop(),this.looping=void 0}elapsed(){const e=this.state.session;return"playing"===e.mode?e.player.elapsed():void 0}async check(e,t={}){const s=c(e,this.pluginKinds());if(s.length)return{ok:!1,problems:s,failures:[],duration:0,error:"Not a valid demo"};if(this.busy())return{ok:!1,problems:s,failures:[],duration:0,error:`Busy: ${this.state.session.mode}`};const{animations:i,fromStart:o,...n}=t,a=i?()=>{}:u();try{if(!1!==o&&e.start&&this.options.start){if("reload"===await this.options.start.go(e.start))return{ok:!1,problems:s,failures:[],duration:0,error:"Its start reloads the page: check again once it is back"}}const t=await this.run(e,{...n,speed:n.speed??8,keepGoing:!0,checking:!0,catchUp:!0,subtitles:!1}),i=t.failures.map(t=>({...t,action:e.steps[t.step].actions[t.index]}));return{ok:!t.error&&0===i.length,error:t.error,failures:i,problems:s,duration:t.timing.duration}}finally{a()}}timing(e,t=this.language()){const s=this.state.lastRun;return s&&s.language===t&&s.json===JSON.stringify(e)&&s.timing.steps.length===e.steps.length?s.timing:l(e,{language:t,sayTime:e=>this.speech.duration(e,t),actionTime:e=>{const t=this.pluginAction(e.do);return t?.duration?.(e)??p(e)}})}film(e,t={}){return new Promise(s=>this.whenClicked(e.title,"Film",async()=>this.busy()?s(void 0):(this.say(void 0),await this.goToStart(e,"film")?void s(await this.filmNow(e,t)):s(void 0))))}async filmNow(e,t){const s=t.language??this.language();let o=!1;const a=await j({soundtrack:this.speech.soundtrack(),microphone:t.microphone,crop:this.options.filmElement?.(),...this.filmQuality(),onEnded:()=>{o=!0,this.stop()}});let r;try{const t=e.steps.flatMap(e=>n(i(e,s)));this.setSession({mode:"preparing",title:e.title,text:"Preparing the narration"}),await this.speech.prepare(t,s,(e,t)=>this.updateSession("preparing",{text:`Preparing the narration: ${e} / ${t}`})),o||"preparing"!==this.state.session.mode||(r=await this.run(e,{language:s,filming:a}))}finally{"preparing"===this.state.session.mode&&this.setSession({mode:"idle"})}const{video:p,voice:l}=await a.stop();if(!r||r.error)return void this.say("Stopped."!==r?.error&&r?`Filming failed: ${r.error}`:"Filming stopped: nothing kept.",Boolean(r?.error&&"Stopped."!==r.error));let d=r.timing.cues;l&&"off"===this.state.settings.speech.voice&&(this.setSession({mode:"preparing",title:e.title,text:"Transcribing what was said"}),d=await this.transcribe(l,s).catch(()=>d),this.setSession({mode:"idle"}));const c={id:e.id,blob:p,at:Date.now(),json:JSON.stringify(e),vtt:h(d),timing:r.timing,language:s,look:this.look(s),...l?{voice:l}:{}};return await this.store.saveVideo(c),this.say(`Filmed "${e.title}": ${Math.round(p.size/1e6)} MB, kept here.`),c}filmQuality(){const{frameRate:e,bitrate:t,lines:s,aspect:i,fit:o}=this.state.settings.film;return{frameRate:e,bitrate:t,fit:o,...s?{size:$(s,i)}:{}}}look(e){const{settings:t}=this.state,s=this.options.appTheme?.(),i=this.options.language?.();return{...s?{theme:s}:{},...i?{locale:i}:{},voice:t.speech.voice,language:e,subtitles:t.subtitles}}async transcribe(e,t=this.language()){const{settings:s}=this.state;return v(e,{language:t,with:s.transcriber,model:s.whisperModel,elevenLabsKey:s.speech.elevenlabs.key,progress:e=>this.set({speech:e<1?{loading:e}:{}})})}record(e={}){return new Promise(t=>this.whenClicked(e.into?.title??"New demo","Record",async()=>{if(this.busy())return t();this.say(void 0),await this.recordNow(e,t)}))}async recordNow(t,i){const{settings:o}=this.state,n=this.language();let a,r;try{o.filmRecording?a=await j({soundtrack:this.speech.soundtrack(),microphone:o.microphone,crop:this.options.filmElement?.(),...this.filmQuality(),onEnded:()=>{this.stopRecording?.()}}):o.microphone&&(r=await R())}catch(e){return this.say(`Could not start: ${e.message}`,!0),i()}const p=this.options.start?.current(),l=new B(this.targets,this.plugins,n,e=>this.updateSession("recording",e));a?.resume();const d=performance.now();this.setSession({mode:"recording",filming:Boolean(a),microphone:Boolean(r||a&&o.microphone),step:0,caption:"",actions:0}),this.nextStepRecording=()=>l.nextStep(),this.sayRecording=e=>l.say(e),this.stopRecording=async()=>{this.stopRecording=this.nextStepRecording=this.sayRecording=void 0;const c=Boolean(r||a&&o.microphone),m=l.stop(c),g=performance.now()-d;this.setSession({mode:"preparing",title:"Recording",text:"Keeping what was recorded"});try{const[i,o]=await Promise.all([r?.stop(),a?.stop()]),l=i??o?.voice;let d=[];if(l){this.updateSession("preparing",{text:"Transcribing what was said"});try{d=await this.transcribe(l,n);const e=w(m.stepStarts,d);m.steps.forEach((t,s)=>{!t.say[n]&&e[s]&&(t.say[n]=e[s])})}catch(e){this.say(`Transcribing failed: ${e.message}`,!0)}}const c=m.steps.filter(e=>e.actions.length>0||Object.values(e.say).some(Boolean)),u=t.into?e(t.into):{...s("Recorded demo",p),steps:[]},y=t.after??u.steps.length-1,f={...u,steps:[...u.steps.slice(0,y+1),...c,...u.steps.slice(y+1)]};0===f.steps.length&&f.steps.push({say:{},actions:[]}),o&&await this.store.saveVideo({id:f.id,blob:o.video,at:Date.now(),json:JSON.stringify(f),vtt:h(d),language:n,look:{...this.look(n),voice:"off",subtitles:!1},timing:{duration:g,steps:m.stepStarts.map((e,t)=>({step:t,start:e,end:m.stepStarts[t+1]??g})),cues:d.map(e=>({...e,step:0})),actions:[]},...o.voice?{voice:o.voice}:{}}),this.setSession({mode:"idle"}),this.say(`Recorded ${c.length} step${1===c.length?"":"s"}${o?", and filmed":""}.`),t.into&&this.state.studio?.demo.id===t.into.id?this.set({studio:{...this.state.studio,recorded:{steps:f.steps,at:Date.now()}}}):this.openStudio(f)}catch(e){this.setSession({mode:"idle"}),this.say(e.message,!0)}i()}}nextStep(){this.nextStepRecording?.()}narrate(e){this.sayRecording?.(e)}async finishRecording(){await(this.stopRecording?.())}link(e){return T(e)}downloadDemo(e,t="json"){if("md"===t)return b(e.scenario??o(e,this.language()),P(e.id,"md"),"text/markdown");const{scenario:s,savedAt:i,...n}=e;b(JSON.stringify(n,null,2)+"\n",P(e.id,"demo.json"),"application/json")}downloadVideo(e,t,s=!1){return"vtt"===s?b(e.vtt,P(t,"vtt"),"text/vtt"):"srt"===s?b(r(a(e.vtt)),P(t,"srt"),"application/x-subrip"):void b(e.blob,P(t,E(e.blob)))}shareVideo(e,t){return x([new File([e.blob],P(t,E(e.blob)),{type:e.blob.type}),new File([e.vtt],P(t,"vtt"),{type:"text/vtt"})],t)}languagesOf(e){return t(e)}}export{U as DEFAULT_SETTINGS};
|
|
1
|
+
import{copyOf as t,languagesOf as e,newDemo as s,sayOf as i,scenarioOf as o,sentences as n}from"../model/Demo.js";import{parseSubtitles as a,toSrt as r,toVtt as h}from"../model/Subtitles.js";import{actionTime as p,estimate as l}from"../model/Timing.js";import{parseDemo as d,validate as c}from"../model/Validate.js";import{Hand as m}from"../page/Input.js";import{Overlay as g}from"../page/Overlay.js";import{stillPage as u}from"../page/Still.js";import{Targets as y}from"../page/Targets.js";import{Speech as f}from"../speech/Speech.js";import{narrationFor as w,transcribe as v}from"../speech/Transcribe.js";import{Store as k}from"../store/Store.js";import{demoFromLink as S,download as b,fileName as P,linkTo as T,shareFiles as x}from"../store/Share.js";import{extensionOf as E,recordMicrophone as R,startFilming as j,videoSize as $}from"../video/Film.js";import{renderMusic as M}from"../speech/Music.js";import{readPack as L,writePack as K}from"../speech/Pack.js";import{Player as N}from"./Player.js";import{Recorder as B}from"./Recorder.js";import{readAction as D}from"./Read.js";import{mountUI as A}from"../ui/EngineUI.js";import{agentTools as I}from"../agent/Agent.js";import{Assistant as O,EMPTY_ASSISTANT as F}from"../agent/Assistant.js";import{openPresenter as C}from"../ui/Presenter.js";import{DEFAULT_RELAY as J,qrSvg as U,RemoteLink as z}from"../remote/Remote.js";import{DEFAULT_SETTINGS as V,loadSettings as Q,saveSettings as H}from"./Settings.js";const G=["pointerdown","pointerup","pointermove","pointerover","pointerout","mousedown","mouseup","mousemove","mouseover","mouseout","click","dblclick","contextmenu","wheel","touchstart","touchmove","touchend","keydown","keyup","keypress"];export class DemoEngine{constructor(t){this.options=t,this.listeners=new Set,this.packs=new Map,this.remoteSent="",this.remoteTimer=0,this.getState=()=>this.state,this.subscribe=t=>(this.listeners.add(t),()=>this.listeners.delete(t)),this.hintTimer=0,this.targets=new y({...t.targets,labels:t.labels}),this.overlay=new g(t.overlay),this.hand=new m(this.overlay.cursor,()=>this.player?.speedNow??1),this.settingsKey=`protomaze-demo-engine:${t.app}:settings`,this.state={session:{mode:"idle"},settings:Q(this.settingsKey),speech:{},assistant:F},this.assistant=new O(this,()=>this.state.settings.claude,t=>this.set({assistant:t})),this.speech=new f(()=>this.state.settings.speech,()=>this.set({speech:{...this.speech.state}})),this.store=new k(`protomaze-demo-engine:${t.app}`),this.store.subscribe(()=>this.emit()),this.plugins=t.plugins??[]}emit(){this.state={...this.state},this.listeners.forEach(t=>t()),this.toRemote()}set(t){this.state={...this.state,...t},this.listeners.forEach(t=>t()),this.toRemote()}setSession(t){this.set({session:t})}updateSession(t,e){this.state.session.mode===t&&this.setSession({...this.state.session,...e})}say(t,e=!1){this.set({message:t?{text:t,error:e}:void 0})}changeSettings(t){const e={...this.state.settings,...t};H(this.settingsKey,e),this.set({settings:e}),t.music?.on&&this.loadMusic().catch(()=>{})}language(){const t=this.state.settings.language;return"page"!==t?t:this.options.language?.()??this.options.languages?.[0]??(navigator.language.split("-")[0]||"en")}languages(){return this.options.languages??[this.language()]}pluginKinds(){return this.plugins.flatMap(t=>Object.keys(t.actions??{}))}pluginAction(t){return this.plugins.map(e=>e.actions?.[t]).find(Boolean)}read(t,e){return D(t,this.options.labels,this.plugins,e)}async mount(){if(this.unmount)return;this.overlay.mount();const t=A(this),e=t=>this.key(t);window.addEventListener("keydown",e,!0);const s=t=>this.gate(t);G.forEach(t=>window.addEventListener(t,s,{capture:!0,passive:!1})),this.state.settings.music.on&&this.loadMusic().catch(()=>{});const i=!1===this.options.agent?void 0:this.options.agent??"demoEngine";i&&(window[i]=I(this)),this.unmount=()=>{t(),window.removeEventListener("keydown",e,!0),G.forEach(t=>window.removeEventListener(t,s,{capture:!0})),i&&delete window[i],this.overlay.unmount()},await this.arrived()}destroy(){this.closeRemote(),this.stopLoop(),this.stop(),this.unmount?.(),this.unmount=void 0}async arrived(){const t=sessionStorage.getItem(this.pendingKey());if(sessionStorage.removeItem(this.pendingKey()),t){const{demo:e,verb:s,from:i,loop:o}=JSON.parse(t);return"loop"===s&&o?void this.loop(o.demos,{gap:o.gap,idle:o.idle,reset:o.reload?"reload":void 0},o.index):this.whenClicked(e.title,"film"===s?"Film":"Play",()=>"film"===s?this.film(e):this.play(e,{from:i}),!0)}const e=await S();if(e){const t=c(e,this.pluginKinds());return t.length?this.say(`The link's demo: ${t[0].path} ${t[0].message}`,!0):(await this.save(e),this.say(`"${e.title}" came with the link: it is kept here.`),this.openStudio(e))}const s=new URL(window.location.href),i=s.searchParams.get("demo");if(i){s.searchParams.delete("demo"),window.history.replaceState(window.history.state,"",s.toString());const t=(await this.entries()).find(t=>t.demo.id===i);t&&this.whenClicked(t.demo.title,"Play",()=>this.play(t.demo),!0)}}gate(t){const e=this.state.session;if(!t.isTrusted||"playing"!==e.mode||e.paused||e.looping)return;const s=t.composedPath();if(s.includes(this.overlay.host))return;if(e.guided&&e.instruction){const i=e.player.viewerTarget();if(i&&(s.includes(i)||t instanceof KeyboardEvent&&i.contains(document.activeElement)))return;if(!i&&t instanceof KeyboardEvent)return}const i=t.defaultPrevented;t.cancelable&&t.preventDefault(),t.stopImmediatePropagation(),i||"pointerdown"!==t.type&&"keydown"!==t.type&&"wheel"!==t.type||this.hint(e.guided?'Only the ringed part now: or "Do it for me"':"Playing: Space pauses, and the app is yours then. Esc stops.")}hint(t){window.clearTimeout(this.hintTimer),this.set({hint:t}),this.hintTimer=window.setTimeout(()=>this.set({hint:void 0}),3e3)}pendingKey(){return`protomaze-demo-engine:${this.options.app}:pending`}key(t){if(!t.isTrusted)return;const e=t.composedPath(),s=e.some(t=>t instanceof HTMLElement&&(t.isContentEditable||t.matches("input, textarea, select"))),i=e.includes(this.overlay.host),o=this.state.session,n=()=>{t.preventDefault(),t.stopPropagation()};if("ready"!==o.mode)if("recording"!==o.mode){if("l"===t.key.toLowerCase()&&t.ctrlKey&&t.shiftKey&&this.looping)return n(),this.stopLoop();if(!("playing"!==o.mode||o.looping||o.checking||s&&(i||o.guided&&o.instruction))){if("Escape"===t.key)this.stop();else if(" "===t.key||"b"===t.key||"."===t.key)this.togglePause();else if("ArrowRight"===t.key||"Enter"===t.key||"PageDown"===t.key)o.player.next();else if("ArrowLeft"===t.key||"PageUp"===t.key)o.player.back();else if("Home"===t.key)o.player.goTo(0);else if("End"===t.key)o.player.goTo(o.steps-1);else{if(!/^[1-9]$/.test(t.key)||t.ctrlKey||t.metaKey||t.altKey)return;o.player.goTo(Number(t.key)-1)}n()}}else"Escape"!==t.key||s||(n(),this.stopRecording?.());else"Escape"===t.key&&(n(),o.cancel())}async entries(){return await this.store.ready(),this.entriesNow()}entriesNow(){const{demos:t,videos:e}=this.store.get(),s=new Map(t.map(t=>[t.id,t])),i=this.language(),n=(this.options.demos??[]).map(t=>"demo"in t?t:{demo:t,scenario:void 0});return[...n.map(({demo:t,scenario:n})=>{const a=s.get(t.id);return a?{demo:a,scenario:a.scenario??n??o(a,i),origin:"edited",video:e.get(t.id)}:{demo:t,scenario:n??o(t,i),origin:"app",video:e.get(t.id)}}),...t.filter(t=>!n.some(e=>e.demo.id===t.id)).map(t=>({demo:t,scenario:t.scenario??o(t,i),origin:"here",video:e.get(t.id)}))]}async save(e){const s=c(e,this.pluginKinds());if(s.length)throw new Error(`Not a demo: ${s.map(t=>`${t.path} ${t.message}`).join("; ")}`);await this.store.saveDemo(t(e))}async remove(t){await this.store.deleteDemo(t),this.state.studio?.demo.id===t&&this.closeStudio()}parse(t){return d(t,this.pluginKinds())}create(t){return s(t,this.options.start?.current())}openStudio(e){this.set({studio:{demo:t(e),opened:Date.now()}})}closeStudio(){this.set({studio:void 0})}activated(){const t=navigator.userActivation;return!t||t.isActive}whenClicked(t,e,s,i=!1){const o=()=>{this.setSession({mode:"idle"}),this.speech.wake(),s().catch(t=>this.say(t.message,!0))};if(!i&&this.activated())return o();this.setSession({mode:"ready",title:t,verb:e,go:o,cancel:()=>this.setSession({mode:"idle"})})}async goToStart(t,e,s,i){if(!t.start||!this.options.start)return!0;sessionStorage.setItem(this.pendingKey(),JSON.stringify({demo:t,verb:e,from:s,loop:i}));return"reload"!==await this.options.start.go(t.start)&&(sessionStorage.removeItem(this.pendingKey()),!0)}busy(){return"idle"!==this.state.session.mode&&"ready"!==this.state.session.mode}play(t,e={}){return new Promise(s=>this.whenClicked(t.title,"Play",async()=>{if(this.busy())return s(void 0);if(this.say(void 0),!await this.goToStart(t,"play",e.from))return s(void 0);const i=await this.run(t,e);s(i)}))}async run(t,e={}){const{settings:s}=this.state,i=e.language??this.language(),o=s.music.on&&!e.checking&&!e.guided&&await Promise.race([this.loadMusic(),new Promise(t=>setTimeout(()=>t(!1),e.filming?6e4:1500))]);this.speech.setPack(s.usePacks?await this.pack(t):void 0);const n=new N(t,{language:i,subtitles:s.subtitles,waitForPresenter:s.waitForPresenter&&!e.looping,catchUp:s.catchUp,music:Boolean(o),...e},{hand:this.hand,targets:this.targets,overlay:this.overlay,speech:this.speech,plugins:this.plugins,ready:this.options.ready,read:(t,e)=>this.read(t,e),reset:async()=>!t.start||!this.options.start||"reload"!==await this.options.start.go(t.start),update:t=>this.updateSession("playing",t)});this.setSession({mode:"playing",title:t.title,demo:t,steps:t.steps.length,filming:Boolean(e.filming),checking:Boolean(e.checking),guided:Boolean(e.guided),looping:Boolean(e.looping),presenting:Boolean(e.presenting),player:n,step:e.from??0,caption:"",paused:!1,waiting:!1,catchingUp:!1}),this.player=n;const a=await n.play().finally(()=>this.player=void 0);return this.setSession({mode:"idle"}),e.checking||a.navigated||(this.set({lastRun:{json:JSON.stringify(t),language:i,timing:a.timing}}),a.error&&"Stopped."!==a.error&&this.say(a.error,!0)),a}stop(){const t=this.state.session;"playing"===t.mode&&t.player.stop(),"recording"===t.mode&&this.stopRecording?.(),"ready"!==t.mode&&"preparing"!==t.mode||this.setSession({mode:"idle"})}togglePause(){const t=this.state.session;"playing"===t.mode&&(t.paused?t.player.resume():t.player.pause())}resume(){const t=this.state.session;"playing"===t.mode&&t.player.resume()}next(){const t=this.state.session;"playing"===t.mode&&t.player.next()}back(){const t=this.state.session;"playing"===t.mode&&t.player.back()}openPresenter(t={}){return C(this,t)}presenterKey(t){this.key(t)}present(t,e={}){this.openDialog({kind:"present",demo:t,from:e.from})}openDialog(t){this.set({dialog:t,...this.state.library&&this.options.launcher?{library:void 0}:{}})}closeDialog(){this.set({dialog:void 0})}openSettings(){this.set({library:"settings"})}showLibrary(t){this.set({library:t})}openAssistant(t){!1!==this.options.assistant&&this.assistant.open(t)}goTo(t){const e=this.state.session;return"playing"===e.mode&&e.player.goTo(t)}guide(t,e={}){return this.play(t,{...e,guided:!0})}doItForMe(){const t=this.state.session;"playing"===t.mode&&t.player.doItForMe()}async openRemote(){if(!1===this.options.remote)throw new Error("No phone remote in this app");if(this.state.remote)return this.state.remote;const t=this.options.remote?.relay??J;this.remoteLink=await z.open(t,{command:t=>this.fromRemote(t),hello:()=>this.remoteSent="",peers:t=>this.state.remote&&this.set({remote:{...this.state.remote,peers:t}})});const e={url:this.remoteLink.url,svg:U(this.remoteLink.url),peers:0};return this.set({remote:e}),this.remoteTimer=window.setInterval(()=>this.toRemote(!0),1e3),e}closeRemote(){window.clearInterval(this.remoteTimer),this.remoteLink?.close(),this.remoteLink=void 0,this.remoteSent="",this.set({remote:void 0})}fromRemote(t){const e=this.state.session;"playing"===e.mode&&("next"===t.do?e.player.next():"back"===t.do?e.player.back():"goto"===t.do&&void 0!==t.step?e.player.goTo(t.step):"stop"===t.do?this.stop():"toggle"===t.do&&(e.waiting?e.player.next():this.togglePause()))}toRemote(t=!1){if(!this.remoteLink)return;const e=this.remoteState(),{at:s,elapsed:i,stepElapsed:o,...n}=e,a=JSON.stringify(n);(a!==this.remoteSent||t&&e.playing)&&(this.remoteSent=a,this.remoteLink.send(e))}remoteState(){const t=this.state.session,e=Date.now();if("playing"!==t.mode||t.checking)return{playing:!1,title:"",steps:[],step:0,caption:"",paused:!1,waiting:!1,filming:!1,elapsed:0,stepElapsed:0,planned:0,at:e};const s=this.language(),o=this.timing(t.demo,s),a=o.steps.find(e=>e.step===t.step),r=t.player.elapsed();return{playing:!0,title:t.demo.title,steps:t.demo.steps.map((t,e)=>({title:t.title??`Step ${e+1}`,script:n(i(t,s)),...t.notes?{notes:t.notes}:{}})),step:t.step,caption:t.caption,paused:t.paused,waiting:t.waiting,filming:t.filming,elapsed:r,stepElapsed:r-t.player.stepStartedAt,planned:o.duration,...a?{plannedStep:a.end-a.start}:{},at:e}}pack(t){let e=this.packs.get(t.id);return e||(e=(async()=>{const e=await this.store.asset(`narration:${t.id}`);if(e)return L(await e.arrayBuffer());const s=this.options.narration?.(t);if(!s)return;const i=await fetch(s);return i.ok?L(await i.arrayBuffer()):void 0})().catch(()=>{}),this.packs.set(t.id,e)),e}async makePack(t,s=()=>{}){const i=await this.pack(t);this.speech.setPack(i);const o=e(t).flatMap(e=>t.steps.flatMap(t=>n(t.say[e]??"").map(t=>({language:e,text:t})))),a=o.filter((t,e)=>o.findIndex(e=>e.language===t.language&&e.text===t.text)===e),r=[];for(const t of a)s(r.length,a.length),r.push({...await this.speech.packable(t.text,t.language),...t});s(r.length,a.length);const h=K(t.id,r);return await this.store.saveAsset(`narration:${t.id}`,h),this.packs.delete(t.id),h}async downloadPack(t){try{const e=await this.makePack(t,(t,e)=>this.say(`Making the narration pack: ${t} / ${e}`));b(e,`${t.id}.narration.zip`),this.say(`Narration pack: ${Math.round(e.size/1e5)/10} MB, kept here too. Check it in beside ${t.id}.demo.json, for every viewer.`)}catch(t){this.say(`Narration pack: ${t.message}`,!0)}}async dropPack(t){await this.store.saveAsset(`narration:${t.id}`,void 0),this.packs.delete(t.id)}async setMusic(t){await this.store.saveAsset("music",t),this.musicLoaded=void 0;const{music:e}=this.state.settings;this.changeSettings({music:t?{...e,on:!0,track:"file",name:t.name??"music"}:{...e,track:"calm",name:void 0}})}async loadMusic(){const{music:t}=this.state.settings,e="file"===t.track?`file:${t.name}`:t.track;if(this.musicLoaded!==e){if("file"===t.track){const e=await this.store.asset("music");if(!e)return!1;await this.speech.setMusic(e,t.volume).catch(()=>{})}else this.speech.setMusicBuffer(await M(t.track),t.volume);this.musicLoaded=e}return this.speech.setMusicVolume(t.volume),this.speech.hasMusic}async listenToMusic(t=20){if(this.speech.wake(),!await this.loadMusic())return()=>{};this.speech.startMusic();const e=setTimeout(()=>this.speech.stopMusic(),1e3*t);return()=>{clearTimeout(e),this.speech.stopMusic(.6)}}async loop(t,e={},s=0){if(0===t.length)return;this.stopLoop();let i=!1,o=0,n=s;const a=e.idle??this.state.settings.loopIdle,r=e.gap??1500,h=t.map(t=>t.title),p=t=>{if(!t.isTrusted||t.composedPath().includes(this.overlay.host))return;o=performance.now();const e=this.state.session;"playing"===e.mode&&e.looping&&e.player.stop(!0)},l=["pointerdown","keydown","wheel","touchstart"];l.forEach(t=>window.addEventListener(t,p,{capture:!0,passive:!0}));this.looping={demos:t,options:e,stop:()=>{i=!0,l.forEach(t=>window.removeEventListener(t,p,{capture:!0}));const t=this.state.session;"playing"===t.mode&&t.looping&&t.player.stop(),this.set({loop:void 0})}};const d=t=>new Promise(e=>setTimeout(e,t));for(;!i;){const s=t[n%t.length];this.set({loop:{titles:h,index:n%t.length,visitor:!1}});if(!await this.goToStart(s,"loop",void 0,{demos:t,index:n%t.length,gap:e.gap,idle:e.idle,reload:"reload"===e.reset})||i)return;const p=await this.run(s,{looping:!0,catchUp:!1});if(i)break;if(p.error&&performance.now()-o<1e3){for(;!i&&performance.now()-o<a;)this.set({loop:{titles:h,index:n%t.length,visitor:!0,resumesAt:Date.now()+a-(performance.now()-o)}}),await d(1e3);if(i)break;if("reload"===e.reset)return sessionStorage.setItem(this.pendingKey(),JSON.stringify({demo:s,verb:"loop",loop:{demos:t,index:n%t.length,gap:e.gap,idle:e.idle,reload:!0}})),window.location.reload();await(e.reset?.())}else n++,await d(r)}}stopLoop(){this.looping?.stop(),this.looping=void 0}elapsed(){const t=this.state.session;return"playing"===t.mode?t.player.elapsed():void 0}async check(t,e={}){const s=c(t,this.pluginKinds());if(s.length)return{ok:!1,problems:s,failures:[],duration:0,error:"Not a valid demo"};if(this.busy())return{ok:!1,problems:s,failures:[],duration:0,error:`Busy: ${this.state.session.mode}`};const{animations:i,fromStart:o,...n}=e,a=i?()=>{}:u();try{if(!1!==o&&t.start&&this.options.start){if("reload"===await this.options.start.go(t.start))return{ok:!1,problems:s,failures:[],duration:0,error:"Its start reloads the page: check again once it is back"}}const e=await this.run(t,{...n,speed:n.speed??8,keepGoing:!0,checking:!0,catchUp:!0,subtitles:!1}),i=e.failures.map(e=>({...e,action:t.steps[e.step].actions[e.index]}));return{ok:!e.error&&0===i.length,error:e.error,failures:i,problems:s,duration:e.timing.duration}}finally{a()}}timing(t,e=this.language()){const s=this.state.lastRun;return s&&s.language===e&&s.json===JSON.stringify(t)&&s.timing.steps.length===t.steps.length?s.timing:l(t,{language:e,sayTime:t=>this.speech.duration(t,e),actionTime:t=>{const e=this.pluginAction(t.do);return e?.duration?.(t)??p(t)}})}film(t,e={}){return new Promise(s=>this.whenClicked(t.title,"Film",async()=>this.busy()?s(void 0):(this.say(void 0),await this.goToStart(t,"film")?void s(await this.filmNow(t,e)):s(void 0))))}async filmNow(t,e){const s=e.language??this.language();let o=!1;const a=await j({soundtrack:this.speech.soundtrack(),microphone:e.microphone,crop:this.options.filmElement?.(),...this.filmQuality(),onEnded:()=>{o=!0,this.stop()}});let r;try{const e=t.steps.flatMap(t=>n(i(t,s)));this.setSession({mode:"preparing",title:t.title,text:"Preparing the narration"}),await this.speech.prepare(e,s,(t,e)=>this.updateSession("preparing",{text:`Preparing the narration: ${t} / ${e}`})),o||"preparing"!==this.state.session.mode||(r=await this.run(t,{language:s,filming:a}))}finally{"preparing"===this.state.session.mode&&this.setSession({mode:"idle"})}const{video:p,voice:l}=await a.stop();if(!r||r.error)return void this.say("Stopped."!==r?.error&&r?`Filming failed: ${r.error}`:"Filming stopped: nothing kept.",Boolean(r?.error&&"Stopped."!==r.error));let d=r.timing.cues;l&&"off"===this.state.settings.speech.voice&&(this.setSession({mode:"preparing",title:t.title,text:"Transcribing what was said"}),d=await this.transcribe(l,s).catch(()=>d),this.setSession({mode:"idle"}));const c={id:t.id,blob:p,at:Date.now(),json:JSON.stringify(t),vtt:h(d),timing:r.timing,language:s,look:this.look(s),...l?{voice:l}:{}};return await this.store.saveVideo(c),this.say(`Filmed "${t.title}": ${Math.round(p.size/1e6)} MB, kept here.`),c}filmQuality(){const{frameRate:t,bitrate:e,lines:s,aspect:i,fit:o}=this.state.settings.film;return{frameRate:t,bitrate:e,fit:o,...s?{size:$(s,i)}:{}}}look(t){const{settings:e}=this.state,s=this.options.appTheme?.(),i=this.options.language?.();return{...s?{theme:s}:{},...i?{locale:i}:{},voice:e.speech.voice,language:t,subtitles:e.subtitles}}async transcribe(t,e=this.language()){const{settings:s}=this.state;return v(t,{language:e,with:s.transcriber,model:s.whisperModel,elevenLabsKey:s.speech.elevenlabs.key,progress:t=>this.set({speech:t<1?{loading:t}:{}})})}record(t={}){return new Promise(e=>this.whenClicked(t.into?.title??"New demo","Record",async()=>{if(this.busy())return e();this.say(void 0),await this.recordNow(t,e)}))}async recordNow(e,i){const{settings:o}=this.state,n=this.language();let a,r;try{o.filmRecording?a=await j({soundtrack:this.speech.soundtrack(),microphone:o.microphone,crop:this.options.filmElement?.(),...this.filmQuality(),onEnded:()=>{this.stopRecording?.()}}):o.microphone&&(r=await R())}catch(t){return this.say(`Could not start: ${t.message}`,!0),i()}const p=this.options.start?.current(),l=new B(this.targets,this.plugins,n,t=>this.updateSession("recording",t));a?.resume();const d=performance.now();this.setSession({mode:"recording",filming:Boolean(a),microphone:Boolean(r||a&&o.microphone),step:0,caption:"",actions:0}),this.nextStepRecording=()=>l.nextStep(),this.sayRecording=t=>l.say(t),this.stopRecording=async()=>{this.stopRecording=this.nextStepRecording=this.sayRecording=void 0;const c=Boolean(r||a&&o.microphone),m=l.stop(c),g=performance.now()-d;this.setSession({mode:"preparing",title:"Recording",text:"Keeping what was recorded"});try{const[i,o]=await Promise.all([r?.stop(),a?.stop()]),l=i??o?.voice;let d=[];if(l){this.updateSession("preparing",{text:"Transcribing what was said"});try{d=await this.transcribe(l,n);const t=w(m.stepStarts,d);m.steps.forEach((e,s)=>{!e.say[n]&&t[s]&&(e.say[n]=t[s])})}catch(t){this.say(`Transcribing failed: ${t.message}`,!0)}}const c=m.steps.filter(t=>t.actions.length>0||Object.values(t.say).some(Boolean)),u=e.into?t(e.into):{...s("Recorded demo",p),steps:[]},y=e.after??u.steps.length-1,f={...u,steps:[...u.steps.slice(0,y+1),...c,...u.steps.slice(y+1)]};0===f.steps.length&&f.steps.push({say:{},actions:[]}),o&&await this.store.saveVideo({id:f.id,blob:o.video,at:Date.now(),json:JSON.stringify(f),vtt:h(d),language:n,look:{...this.look(n),voice:"off",subtitles:!1},timing:{duration:g,steps:m.stepStarts.map((t,e)=>({step:e,start:t,end:m.stepStarts[e+1]??g})),cues:d.map(t=>({...t,step:0})),actions:[]},...o.voice?{voice:o.voice}:{}}),this.setSession({mode:"idle"}),this.say(`Recorded ${c.length} step${1===c.length?"":"s"}${o?", and filmed":""}.`),e.into&&this.state.studio?.demo.id===e.into.id?this.set({studio:{...this.state.studio,recorded:{steps:f.steps,at:Date.now()}}}):this.openStudio(f)}catch(t){this.setSession({mode:"idle"}),this.say(t.message,!0)}i()}}nextStep(){this.nextStepRecording?.()}narrate(t){this.sayRecording?.(t)}async finishRecording(){await(this.stopRecording?.())}link(t){return T(t)}downloadDemo(t,e="json"){if("md"===e)return b(t.scenario??o(t,this.language()),P(t.id,"md"),"text/markdown");const{scenario:s,savedAt:i,...n}=t;b(JSON.stringify(n,null,2)+"\n",P(t.id,"demo.json"),"application/json")}downloadVideo(t,e,s=!1){return"vtt"===s?b(t.vtt,P(e,"vtt"),"text/vtt"):"srt"===s?b(r(a(t.vtt)),P(e,"srt"),"application/x-subrip"):void b(t.blob,P(e,E(t.blob)))}shareVideo(t,e){return x([new File([t.blob],P(e,E(t.blob)),{type:t.blob.type}),new File([t.vtt],P(e,"vtt"),{type:"text/vtt"})],e)}languagesOf(t){return e(t)}}export{V as DEFAULT_SETTINGS};
|
package/engine/Settings.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ClaudeSettings } from '../agent/Assistant';
|
|
1
2
|
import type { Language } from '../model/Demo';
|
|
2
3
|
import { SpeechSettings } from '../speech/Speech';
|
|
3
4
|
import type { MusicTrack } from '../speech/Music';
|
|
@@ -47,6 +48,8 @@ export type DemoSettings = {
|
|
|
47
48
|
usePacks: boolean;
|
|
48
49
|
/** Presenting, the presenter's screen: a window, always on top, the phone, or none. */
|
|
49
50
|
presenterScreen: 'window' | 'onTop' | 'phone' | 'none';
|
|
51
|
+
/** "Ask Claude": the person's own API key, the model, how hard it thinks. */
|
|
52
|
+
claude: ClaudeSettings;
|
|
50
53
|
};
|
|
51
54
|
export declare const DEFAULT_SETTINGS: DemoSettings;
|
|
52
55
|
export declare function loadSettings(key: string): DemoSettings;
|
package/engine/Settings.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{DEFAULT_CLAUDE as e}from"../agent/Assistant.js";import{DEFAULT_SPEECH as t}from"../speech/Speech.js";export const DEFAULT_SETTINGS={speech:t,language:"page",subtitles:!0,waitForPresenter:!1,catchUp:!0,microphone:!1,filmRecording:!1,transcriber:"whisper",whisperModel:"base",music:{on:!1,volume:.18,track:"calm"},film:{frameRate:30,bitrate:8,lines:1080,aspect:"16:9",fit:"fit"},loopIdle:3e4,usePacks:!0,presenterScreen:"window",claude:e};export function loadSettings(s){try{const c=JSON.parse(localStorage.getItem(s)??"{}");return{...DEFAULT_SETTINGS,...c,speech:{...t,...c.speech,elevenlabs:{...t.elevenlabs,...c.speech?.elevenlabs}},music:{...DEFAULT_SETTINGS.music,...c.music?.name?{track:"file"}:{},...c.music},film:{...DEFAULT_SETTINGS.film,...c.film},claude:{...e,...c.claude}}}catch{return DEFAULT_SETTINGS}}export function saveSettings(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch{}}
|
package/index.d.ts
CHANGED
|
@@ -19,10 +19,12 @@ export * from './video/Film';
|
|
|
19
19
|
export * from './store/Store';
|
|
20
20
|
export * from './store/Share';
|
|
21
21
|
export * from './agent/Agent';
|
|
22
|
+
export * from './agent/Assistant';
|
|
22
23
|
export { GUIDE } from './agent/Guide';
|
|
23
24
|
export { DemoLibrary, Library, Settings, Shadow } from './ui/Library';
|
|
24
25
|
export { Dialog } from './ui/Dialogs';
|
|
25
26
|
export { Studio } from './ui/Studio';
|
|
27
|
+
export { AssistantPanel } from './ui/Assistant';
|
|
26
28
|
export { Timeline } from './ui/Timeline';
|
|
27
29
|
export { openPresenter, mountPresenter } from './ui/Presenter';
|
|
28
30
|
export { useEngine, useDemos } from './ui/Hooks';
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./model/Demo.js";export*from"./model/Timing.js";export*from"./model/Subtitles.js";export*from"./model/Validate.js";export*from"./engine/DemoEngine.js";export*from"./engine/Player.js";export*from"./engine/Recorder.js";export*from"./engine/Plugin.js";export*from"./engine/Settings.js";export*from"./page/Targets.js";export*from"./page/Input.js";export*from"./page/Overlay.js";export*from"./speech/Speech.js";export*from"./speech/Transcribe.js";export*from"./speech/Pack.js";export*from"./speech/Music.js";export*from"./store/Zip.js";export*from"./video/Film.js";export*from"./store/Store.js";export*from"./store/Share.js";export*from"./agent/Agent.js";export{GUIDE}from"./agent/Guide.js";export{DemoLibrary,Library,Settings,Shadow}from"./ui/Library.js";export{Dialog}from"./ui/Dialogs.js";export{Studio}from"./ui/Studio.js";export{Timeline}from"./ui/Timeline.js";export{openPresenter,mountPresenter}from"./ui/Presenter.js";export{useEngine,useDemos}from"./ui/Hooks.js";export{UI_CSS}from"./ui/Styles.js";
|
|
1
|
+
export*from"./model/Demo.js";export*from"./model/Timing.js";export*from"./model/Subtitles.js";export*from"./model/Validate.js";export*from"./engine/DemoEngine.js";export*from"./engine/Player.js";export*from"./engine/Recorder.js";export*from"./engine/Plugin.js";export*from"./engine/Settings.js";export*from"./page/Targets.js";export*from"./page/Input.js";export*from"./page/Overlay.js";export*from"./speech/Speech.js";export*from"./speech/Transcribe.js";export*from"./speech/Pack.js";export*from"./speech/Music.js";export*from"./store/Zip.js";export*from"./video/Film.js";export*from"./store/Store.js";export*from"./store/Share.js";export*from"./agent/Agent.js";export*from"./agent/Assistant.js";export{GUIDE}from"./agent/Guide.js";export{DemoLibrary,Library,Settings,Shadow}from"./ui/Library.js";export{Dialog}from"./ui/Dialogs.js";export{Studio}from"./ui/Studio.js";export{AssistantPanel}from"./ui/Assistant.js";export{Timeline}from"./ui/Timeline.js";export{openPresenter,mountPresenter}from"./ui/Presenter.js";export{useEngine,useDemos}from"./ui/Hooks.js";export{UI_CSS}from"./ui/Styles.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protomaze/demo-engine",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "Protomaze Demo Engine: record, edit, narrate, play and film demos of a web app, in the browser",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
],
|
|
36
36
|
"author": "Tom Crauwels",
|
|
37
37
|
"dependencies": {
|
|
38
|
+
"@anthropic-ai/sdk": "^1.12.0",
|
|
38
39
|
"@protomaze/time": "^1.16.1",
|
|
39
40
|
"qrcode-generator": "^2.0.4"
|
|
40
41
|
},
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DemoEngine } from '../engine/DemoEngine';
|
|
2
|
+
/**
|
|
3
|
+
* "Ask Claude": a demo made, cloned or changed in words. Claude works in the app as the person
|
|
4
|
+
* watches - each thing it does a line here - and opens what it made in the studio.
|
|
5
|
+
*/
|
|
6
|
+
export declare function AssistantPanel({ engine, theme }: {
|
|
7
|
+
engine: DemoEngine;
|
|
8
|
+
theme: 'light' | 'dark';
|
|
9
|
+
}): JSX.Element;
|
package/ui/Assistant.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e,{useEffect as t,useRef as a,useState as s}from"react";import{costOf as n}from"../agent/Assistant.js";import{useDemos as l,useEngine as r}from"./Hooks.js";import{Button as i,Icon as o}from"./Kit.js";export function AssistantPanel({engine:d,theme:u}){const{assistant:p,settings:h,studio:k}=r(d),E=l(d),{working:g,about:v,usage:y}=p,f=h.claude.key,[N,b]=s(""),[A,w]=s(!f),C=a(null),x=a(null),$=p.entries[p.entries.length-1],I=k?.opened;t(()=>{k&&d.assistant.setAbout({id:k.demo.id,title:k.demo.title})},[I]),t(()=>{C.current?.scrollTo({top:C.current.scrollHeight})},[p.entries.length,"claude"===$?.kind?$.text.length:0,g]),t(()=>{f&&x.current?.focus()},[f]);const K=(e=N)=>{e.trim()&&!g&&f&&(d.assistant.ask(e),b(""))},P=E[0]?.demo,S=["Make a one-minute tour of this page",...v?[`Make “${v.title}” shorter and punchier`,`Add a step to “${v.title}” that shows …`]:[],...!v&&P?[`Clone “${P.title}” as a 30-second teaser`]:[]],j=n(y,h.claude.model),D=y.input+y.written+y.cached;return e.createElement("div",{className:"pde assistant"+(k?" over-studio":""),"data-theme":u,"data-demo-ignore":!0},e.createElement("div",{className:"row"},e.createElement(o,{name:"spark"}),e.createElement("h2",{className:"grow"},"Ask Claude"),e.createElement(i,{small:!0,kind:A?"primary":"bare",title:"Your Anthropic API key",onClick:()=>w(!A)},"Key"),e.createElement(i,{icon:"add",kind:"bare",title:"A new conversation",disabled:g||0===p.entries.length,onClick:()=>d.assistant.clear()}),e.createElement(i,{icon:"close",kind:"bare",title:"Close: the conversation stays",onClick:()=>d.assistant.close()})),A&&e.createElement("div",{className:"col",style:{gap:4}},e.createElement("input",{className:"field",type:"password",autoComplete:"off",placeholder:"sk-ant-…",value:f,"aria-label":"Anthropic API key",onChange:e=>d.changeSettings({claude:{...h.claude,key:e.target.value.trim()}})}),e.createElement("div",{className:"small muted"},"Your own Anthropic API key, from the Claude Console. It stays in this browser; Claude's requests go from here to Anthropic, billed to it."),f&&e.createElement(i,{small:!0,onClick:()=>w(!1)},"Done")),e.createElement("div",{className:"entries",ref:C},0===p.entries.length&&e.createElement("div",{className:"col",style:{gap:6}},e.createElement("div",{className:"small muted"},"Say what the demo should show. Claude looks at the app, walks the path, writes the narration, checks it plays, and opens it in the studio. You see each step it takes."),e.createElement("div",{className:"suggest"},S.map(t=>e.createElement(i,{key:t,small:!0,kind:"bare",disabled:!f,onClick:()=>{b(t),x.current?.focus()}},t)))),p.entries.map((t,a)=>e.createElement(c,{key:a,entry:t})),g&&e.createElement("div",{className:"small muted working"},e.createElement("span",{className:"dot"}),"Working…")),v&&e.createElement("div",{className:"about small"},e.createElement("span",{className:"muted"},"About"),e.createElement("span",{className:"ellipsis grow"},"“",v.title,"”"),e.createElement(i,{icon:"close",small:!0,kind:"bare",title:"About nothing in particular",onClick:()=>d.assistant.setAbout(void 0)})),e.createElement("div",{className:"ask"},e.createElement("textarea",{ref:x,className:"field",rows:2,placeholder:f?"A one-minute tour of the orders, for new team members…":"Add your API key first (Key)",value:N,disabled:!f,onChange:e=>b(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),K())}}),g?e.createElement(i,{icon:"stop",onClick:()=>d.assistant.stop()},"Stop"):e.createElement(i,{icon:"send",kind:"primary",title:"Ask (Enter)",disabled:!N.trim()||!f,onClick:()=>K()})),D+y.output>0&&e.createElement("div",{className:"small muted",title:"This conversation, so far"},m(D)," tokens in (",m(y.cached)," from cache) · ",m(y.output)," out",void 0!==j?` · about $${j.toFixed(2)}`:""))}function c({entry:t}){switch(t.kind){case"you":return e.createElement("div",{className:"you"},t.text);case"claude":return e.createElement("div",{className:"claude"},t.text);case"did":return e.createElement("div",{className:"did"+(t.ok?"":" failed")},e.createElement("span",null,t.ok?"✓":"✕"),e.createElement("span",null,t.text));case"error":return e.createElement("div",{className:"small error"},t.text)}}function m(e){return e<1e3?String(e):`${(e/1e3).toFixed(e<1e4?1:0)}k`}
|
package/ui/EngineUI.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e,{useEffect as t}from"react";import{createRoot as a}from"react-dom/client";import{useEngine as n}from"./Hooks.js";import{Button as
|
|
1
|
+
import e,{useEffect as t}from"react";import{createRoot as a}from"react-dom/client";import{useEngine as n}from"./Hooks.js";import{Button as i,Icon as l,Menu as o,useTheme as s}from"./Kit.js";import{Library as r}from"./Library.js";import{AssistantPanel as m}from"./Assistant.js";import{Dialog as c}from"./Dialogs.js";import{Studio as d}from"./Studio.js";import{UI_CSS as p}from"./Styles.js";export function mountUI(t){t.overlay.addStyles(p);const n=a(t.overlay.ui);return n.render(e.createElement(u,{engine:t})),()=>n.unmount()}function u({engine:t}){const a=n(t),p=s(t.options.theme??"dark"),{session:u}=a,E="playing"===u.mode&&(u.filming&&!u.paused||u.looping)||"recording"===u.mode&&u.filming;return e.createElement(e.Fragment,null,"ready"===u.mode&&e.createElement("div",{className:"pde ready","data-theme":p,onClick:e=>e.target===e.currentTarget&&u.cancel()},e.createElement("div",{className:"box"},e.createElement(i,{icon:"Film"===u.verb?"film":"Record"===u.verb?"record":"play",kind:"primary",autoFocus:!0,onClick:u.go},u.verb," “",u.title,"”"),e.createElement("div",{className:"small muted"},"A click here, in the app's window, lets it speak","Play"===u.verb?"":" and be filmed","."),e.createElement(i,{kind:"bare",onClick:u.cancel},"Cancel"))),"preparing"===u.mode&&e.createElement("div",{className:"pde bar","data-theme":p},e.createElement("span",null,u.title),e.createElement("span",{className:"muted"},u.text),void 0!==a.speech.loading&&e.createElement("span",{className:"muted"},Math.round(100*a.speech.loading)," %"),e.createElement(i,{icon:"stop",small:!0,kind:"bare",title:"Stop",onClick:()=>t.stop()})),"playing"===u.mode&&!u.checking&&!E&&e.createElement("div",{className:"pde bar","data-theme":p},u.filming&&e.createElement("span",{className:"dot",title:"Filming: paused time is left out"}),e.createElement("span",{className:"ellipsis",style:{maxWidth:320}},u.title),!u.filming&&e.createElement(i,{icon:"back",small:!0,kind:"bare",title:"Back: this step again; pressed early, the one before (←, PageUp)",onClick:()=>t.back()}),u.filming?e.createElement("span",{className:"muted"},`${u.step+1} / ${u.steps}`):e.createElement(o,{title:"Go to a step (1-9, Home, End)",icon:"expand",label:e.createElement("span",{className:"muted"},u.catchingUp?`… ${u.step+1}`:`${u.step+1} / ${u.steps}`),align:"left",items:u.demo.steps.map((a,n)=>({label:e.createElement("span",{style:{fontWeight:n===u.step?700:400}},`${n+1}. ${a.title??(Object.values(a.say).find(Boolean)??"").slice(0,48)}`),onClick:()=>t.goTo(n)}))}),void 0!==a.speech.loading&&e.createElement("span",{className:"muted small",title:"Downloaded once, then kept by the browser: subtitles meanwhile"},"voice ",Math.round(100*a.speech.loading)," %"),a.hint&&e.createElement("span",{className:"small",style:{color:"var(--accent)"}},a.hint),u.paused&&!u.waiting&&!a.hint&&e.createElement("span",{className:"muted small",title:"What you do now, the demo goes on from"},"paused: the app is yours"),u.guided&&u.instruction&&e.createElement("span",{className:"ellipsis",style:{maxWidth:360,fontWeight:600}},u.instruction),u.guided&&u.instruction&&e.createElement(i,{icon:"flash",title:"The demo does it",onClick:()=>t.doItForMe()},"Do it for me"),e.createElement(i,{icon:u.paused?"play":"pause",kind:u.paused?"primary":void 0,title:"Space",onClick:()=>u.waiting?t.next():t.togglePause()},u.waiting?"Continue":u.paused?"Resume":"Pause"),!u.waiting&&e.createElement(i,{icon:"right",title:"Next step (→, PageDown)",onClick:()=>t.next()}),u.presenting&&e.createElement(i,{icon:"present",kind:"bare",title:"The presenter's screen, in a window of its own",onClick:()=>{t.openPresenter()}}),e.createElement(i,{icon:"stop",title:"Esc",onClick:()=>t.stop()},u.guided?"Exit":"Stop")),a.loop?.visitor&&e.createElement("div",{className:"pde bar","data-theme":p,style:{top:"auto",bottom:12,left:"auto",right:12,transform:"none",padding:"4px 6px 4px 12px",opacity:.85}},e.createElement(l,{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"===u.mode&&e.createElement(g,{engine:t,theme:p,filmed:u.filming}),a.message&&"idle"===u.mode&&e.createElement(h,{engine:t,theme:p,text:a.message.text,error:a.message.error}),a.studio&&!E&&e.createElement(d,{key:a.studio.opened,engine:t,theme:p}),a.assistant.open&&!1!==t.options.assistant&&("idle"===u.mode||"playing"===u.mode&&u.checking)&&e.createElement(m,{engine:t,theme:p}),t.options.launcher&&"idle"===u.mode&&!a.loop&&!a.studio&&e.createElement(e.Fragment,null,e.createElement("div",{className:"pde launcher","data-theme":p},e.createElement(i,{kind:a.library?"primary":void 0,onClick:()=>t.showLibrary(a.library?void 0:"demos")},e.createElement(l,{name:"demos"}),"Demos")),a.library&&e.createElement(r,{engine:t,theme:p,floating:!0})),a.dialog&&"idle"===u.mode&&e.createElement(c,{engine:t,request:a.dialog,theme:p}))}function g({engine:t,theme:a,filmed:l}){const{session:o}=n(t);return"recording"!==o.mode?null:l?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 h({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/Kit.d.ts
CHANGED
|
@@ -36,6 +36,8 @@ declare const PATHS: {
|
|
|
36
36
|
readonly maximize: "M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z";
|
|
37
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
38
|
readonly flash: "M7 2v11h3v9l7-12h-4l4-8z";
|
|
39
|
+
readonly spark: "M19 9l1.25-2.75L23 5l-2.75-1.25L19 1l-1.25 2.75L15 5l2.75 1.25L19 9zm-7.5.5L9 4 6.5 9.5 1 12l5.5 2.5L9 20l2.5-5.5L17 12l-5.5-2.5zM19 15l-1.25 2.75L15 19l2.75 1.25L19 23l1.25-2.75L23 19l-2.75-1.25L19 15z";
|
|
40
|
+
readonly send: "M2.01 21L23 12 2.01 3 2 10l15 2-15 2z";
|
|
39
41
|
readonly guide: "M5 13.18v4L12 21l7-3.82v-4L12 17l-7-3.82zM12 3L1 9l11 6 9-4.91V17h2V9L12 3z";
|
|
40
42
|
readonly loop: "M7 7h10v3l4-4-4-4v3H5v6h2V7zm10 10H7v-3l-4 4 4 4v-3h12v-6h-2v4z";
|
|
41
43
|
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";
|
package/ui/Kit.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e,{useEffect as c,useRef as t,useState as l}from"react";const n={play:"M8 5v14l11-7z",pause:"M6 19h4V5H6v14zm8-14v14h4V5h-4z",stop:"M6 6h12v12H6z",record:"M12 4a8 8 0 1 0 0 16a8 8 0 0 0 0-16z",film:"M18 4l2 4h-3l-2-4h-2l2 4h-3l-2-4H8l2 4H7L5 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V4h-4z",mic:"M12 14c1.66 0 2.99-1.34 2.99-3L15 5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3zm5.3-3c0 3-2.54 5.1-5.3 5.1S6.7 14 6.7 11H5c0 3.41 2.72 6.23 6 6.72V21h2v-3.28c3.28-.48 6-3.3 6-6.72h-1.7z",save:"M17 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V7l-4-4zm-5 16c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm3-10H5V5h10v4z",close:"M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z",add:"M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z",delete:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z",up:"M4 12l1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8-8 8z",down:"M20 12l-1.41-1.41L13 16.17V4h-2v12.17l-5.58-5.59L4 12l8 8 8-8z",link:"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z",download:"M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z",upload:"M9 16h6v-6h4l-7-7-7 7h4zm-4 2h14v2H5z",share:"M18 16.08c-.76 0-1.44.3-1.96.77L8.91 12.7c.05-.23.09-.46.09-.7s-.04-.47-.09-.7l7.05-4.11c.54.5 1.25.81 2.04.81 1.66 0 3-1.34 3-3s-1.34-3-3-3-3 1.34-3 3c0 .24.04.47.09.7L8.04 9.81C7.5 9.31 6.79 9 6 9c-1.66 0-3 1.34-3 3s1.34 3 3 3c.79 0 1.5-.31 2.04-.81l7.12 4.16c-.05.21-.08.43-.08.65 0 1.61 1.31 2.92 2.92 2.92s2.92-1.31 2.92-2.92-1.31-2.92-2.92-2.92z",edit:"M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04a.996.996 0 0 0 0-1.41l-2.34-2.34a.996.996 0 0 0-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z",pick:"M12 8c-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4-1.79-4-4-4zm8.94 3A8.994 8.994 0 0 0 13 3.06V1h-2v2.06A8.994 8.994 0 0 0 3.06 11H1v2h2.06A8.994 8.994 0 0 0 11 20.94V23h2v-2.06A8.994 8.994 0 0 0 20.94 13H23v-2h-2.06zM12 19c-3.87 0-7-3.13-7-7s3.13-7 7-7 7 3.13 7 7-3.13 7-7 7z",show:"M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z",undo:"M12.5 8c-2.65 0-5.05.99-6.9 2.6L2 7v9h9l-3.62-3.62c1.39-1.16 3.16-1.88 5.12-1.88 3.54 0 6.55 2.31 7.6 5.5l2.37-.78C21.08 11.03 17.15 8 12.5 8z",redo:"M18.4 10.6C16.55 8.99 14.15 8 11.5 8c-4.65 0-8.58 3.03-9.96 7.22L3.9 16c1.05-3.19 4.05-5.5 7.6-5.5 1.95 0 3.73.72 5.12 1.88L13 16h9V7l-3.6 3.6z",copy:"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z",code:"M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4z",tune:"M3 17v2h6v-2H3zM3 5v2h10V5H3zm10 16v-2h8v-2h-8v-2h-2v6h2zM7 9v2H3v2h4v2h2V9H7zm14 4v-2H11v2h10zm-6-4h2V7h4V5h-4V3h-2v6z",more:"M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z",check:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z",listen:"M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z",first:"M6 6h2v12H6zm3.5 6l8.5 6V6z",demos:"M10 8v8l5-4-5-4zm9-5H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V5h14v14z",expand:"M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6z",right:"M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z",subtitles:"M20 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zM4 12h4v2H4v-2zm10 6H4v-2h10v2zm6 0h-4v-2h4v2zm0-4H10v-2h10v2z",minimize:"M6 19h12v2H6z",maximize:"M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z",duplicate:"M15 1H4c-1.1 0-2 .9-2 2v13h2V3h11V1zm-1 4l6 6v10c0 1.1-.9 2-2 2H7.99C6.89 23 6 22.1 6 21l.01-14c0-1.1.89-2 1.99-2h6zm-1 7h5.5L13 6.5V12z",flash:"M7 2v11h3v9l7-12h-4l4-8z",guide:"M5 13.18v4L12 21l7-3.82v-4L12 17l-7-3.82zM12 3L1 9l11 6 9-4.91V17h2V9L12 3z",loop:"M7 7h10v3l4-4-4-4v3H5v6h2V7zm10 10H7v-3l-4 4 4 4v-3h12v-6h-2v4z",music:"M12 3v10.55c-.59-.34-1.27-.55-2-.55-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z",back:"M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z",present:"M21 3H3c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h5v2h8v-2h5c1.1 0 1.99-.9 1.99-2L23 5c0-1.1-.9-2-2-2zm0 14H3V5h18v12z",light:"M12 7a5 5 0 1 0 0 10 5 5 0 0 0 0-10zM2 13h2a1 1 0 0 0 0-2H2a1 1 0 0 0 0 2zm18 0h2a1 1 0 0 0 0-2h-2a1 1 0 0 0 0 2zM11 2v2a1 1 0 0 0 2 0V2a1 1 0 0 0-2 0zm0 18v2a1 1 0 0 0 2 0v-2a1 1 0 0 0-2 0zM5.99 4.58a1 1 0 0 0-1.41 1.41l1.06 1.06a1 1 0 0 0 1.41-1.41L5.99 4.58zm12.37 12.37a1 1 0 0 0-1.41 1.41l1.06 1.06a1 1 0 0 0 1.41-1.41l-1.06-1.06zm1.06-10.96a1 1 0 0 0-1.41-1.41l-1.06 1.06a1 1 0 0 0 1.41 1.41l1.06-1.06zM7.05 18.36a1 1 0 0 0-1.41-1.41l-1.06 1.06a1 1 0 0 0 1.41 1.41l1.06-1.06z",dark:"M12 3a9 9 0 1 0 9 9c0-.46-.04-.92-.1-1.36a5.39 5.39 0 0 1-4.4 2.26 5.4 5.4 0 0 1-3.14-9.8c-.44-.06-.9-.1-1.36-.1z",voice:"M9 13c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4zm6.08-7.95c.84 1.18.84 2.71 0 3.89l1.68 1.69c2.02-2.02 2.02-5.07 0-7.27l-1.68 1.69zM20.07 2l-1.63 1.63c2.77 3.02 2.77 7.56 0 10.74L20.07 16c3.9-3.89 3.91-9.95 0-14z",premium:"M7 18h2V6H7v12zm4 4h2V2h-2v20zm-8-8h2v-4H3v4zm12 4h2V6h-2v12zm4-8v4h2v-4h-2z",novoice:"M9 13c2.21 0 4-1.79 4-4 0-.55-.11-1.07-.31-1.55L7.45 12.69c.48.2 1 .31 1.55.31zM2.81 2.81 1.39 4.22l3.08 3.08A4 4 0 0 0 5 9c0 .74.2 1.43.55 2.02L1 19v2h14.17l4.61 4.61 1.41-1.41L2.81 2.81zM20.07 2l-1.63 1.63c2.77 3.02 2.77 7.56 0 10.74L20.07 16c3.9-3.89 3.91-9.95 0-14z",computer:"M20 18c1.1 0 1.99-.9 1.99-2L22 6c0-1.1-.9-2-2-2H4c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2H0v2h24v-2h-4zM4 6h16v10H4V6z",language:"M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zm6.93 6h-2.95a15.65 15.65 0 0 0-1.38-3.56A8.03 8.03 0 0 1 18.92 8zM12 4.04c.83 1.2 1.48 2.53 1.91 3.96h-3.82c.43-1.43 1.08-2.76 1.91-3.96zM4.26 14C4.1 13.36 4 12.69 4 12s.1-1.36.26-2h3.38c-.08.66-.14 1.32-.14 2s.06 1.34.14 2H4.26zm.82 2h2.95c.32 1.25.78 2.45 1.38 3.56A8 8 0 0 1 5.08 16zm2.95-8H5.08a8 8 0 0 1 4.33-3.56A15.65 15.65 0 0 0 8.03 8zM12 19.96c-.83-1.2-1.48-2.53-1.91-3.96h3.82c-.43 1.43-1.08 2.76-1.91 3.96zM14.34 14H9.66c-.09-.66-.16-1.32-.16-2s.07-1.35.16-2h4.68c.09.65.16 1.32.16 2s-.07 1.34-.16 2zm.25 5.56c.6-1.11 1.06-2.31 1.38-3.56h2.95a8.03 8.03 0 0 1-4.33 3.56zM16.36 14c.08-.66.14-1.32.14-2s-.06-1.34-.14-2h3.38c.16.64.26 1.31.26 2s-.1 1.36-.26 2h-3.38z"};export function Icon({name:c}){return e.createElement("svg",{className:"i",viewBox:"0 0 24 24","aria-hidden":"true"},e.createElement("path",{d:n[c]}))}export function Button({icon:c,kind:t,on:l,small:n,className:a,children:h,...v}){const o=c&&!h,r=["btn",o&&"icon",t,l&&"on",n&&"small",a].filter(Boolean).join(" ");return e.createElement("button",{type:"button",className:r,"aria-label":o?v.title:void 0,...v},c&&e.createElement(Icon,{name:c}),h)}export function Labelled({label:c,children:t,className:l}){return e.createElement("label",{className:["labelled",l].filter(Boolean).join(" ")},e.createElement("span",null,c),t)}export function Check({label:c,checked:t,onChange:l,title:n}){return e.createElement("label",{className:"check",title:n},e.createElement("input",{type:"checkbox",checked:t,onChange:e=>l(e.target.checked)}),c)}export function Segmented({value:c,options:t,onChange:l}){return e.createElement("div",{className:"segmented"},t.map(([t,n,a])=>e.createElement("button",{key:t,type:"button",className:t===c?"on":"",title:a,onClick:()=>l(t)},n)))}export function NumberField({value:t,onChange:n,placeholder:a,title:h,width:v=80}){const[o,r]=l(void 0===t?"":String(t));return c(()=>{Number(o)===t||""===o&&void 0===t||r(void 0===t?"":String(t))},[t]),e.createElement("input",{className:"field",style:{width:v},inputMode:"numeric",placeholder:a,title:h,value:o,onChange:e=>{r(e.target.value);const c=e.target.value.trim();""===c?n(void 0):Number.isFinite(Number(c))&&n(Number(c))}})}export function JsonField({value:n,onChange:a,className:h,rows:v=1}){const o=JSON.stringify(n),[r,i]=l(o??""),[m,z]=l(!1),s=t(o);c(()=>{o!==s.current&&(s.current=o,i(o??""),z(!1))},[o]);const M=v>1?"textarea":"input";return e.createElement(M,{className:["field","mono",m&&"wrong",h].filter(Boolean).join(" "),rows:v>1?v:void 0,value:r,onChange:e=>{i(e.target.value);try{const c=""===e.target.value.trim()?void 0:JSON.parse(e.target.value);s.current=JSON.stringify(c),z(!1),a(c)}catch{z(!0)}}})}export function Menu({icon:n="more",label:a,title:h,items:v,align:o="right"}){const[r,i]=l(!1),m=t(null);return c(()=>{if(!r)return;const e=e=>{e.composedPath().includes(m.current)||i(!1)},c=m.current.getRootNode();return c.addEventListener("pointerdown",e,!0),()=>c.removeEventListener("pointerdown",e,!0)},[r]),e.createElement("span",{ref:m,style:{position:"relative",display:"inline-flex"}},e.createElement(Button,{icon:n,title:h,kind:a?void 0:"bare",on:r,onClick:()=>i(!r)},a),r&&e.createElement("div",{className:"menu",style:{top:"calc(100% + 4px)",[o]:0}},v.filter(Boolean).map((c,t)=>c&&"heading"in c?e.createElement("div",{key:t,className:"heading"},c.heading):c&&e.createElement("button",{key:t,type:"button",className:"item",disabled:c.disabled,onClick:()=>{i(!1),c.onClick()}},c.icon&&e.createElement(Icon,{name:c.icon}),c.label))))}export function useTheme(e="dark"){const t="function"==typeof matchMedia?matchMedia("(prefers-color-scheme: dark)"):void 0,[n,a]=l(t?.matches??!0);return c(()=>{if(!t)return;const e=()=>a(t.matches);return t.addEventListener("change",e),()=>t.removeEventListener("change",e)},[]),"auto"===e?n?"dark":"light":e}
|
|
1
|
+
import e,{useEffect as c,useRef as t,useState as l}from"react";const n={play:"M8 5v14l11-7z",pause:"M6 19h4V5H6v14zm8-14v14h4V5h-4z",stop:"M6 6h12v12H6z",record:"M12 4a8 8 0 1 0 0 16a8 8 0 0 0 0-16z",film:"M18 4l2 4h-3l-2-4h-2l2 4h-3l-2-4H8l2 4H7L5 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V4h-4z",mic:"M12 14c1.66 0 2.99-1.34 2.99-3L15 5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3zm5.3-3c0 3-2.54 5.1-5.3 5.1S6.7 14 6.7 11H5c0 3.41 2.72 6.23 6 6.72V21h2v-3.28c3.28-.48 6-3.3 6-6.72h-1.7z",save:"M17 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V7l-4-4zm-5 16c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm3-10H5V5h10v4z",close:"M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z",add:"M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z",delete:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z",up:"M4 12l1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8-8 8z",down:"M20 12l-1.41-1.41L13 16.17V4h-2v12.17l-5.58-5.59L4 12l8 8 8-8z",link:"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z",download:"M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z",upload:"M9 16h6v-6h4l-7-7-7 7h4zm-4 2h14v2H5z",share:"M18 16.08c-.76 0-1.44.3-1.96.77L8.91 12.7c.05-.23.09-.46.09-.7s-.04-.47-.09-.7l7.05-4.11c.54.5 1.25.81 2.04.81 1.66 0 3-1.34 3-3s-1.34-3-3-3-3 1.34-3 3c0 .24.04.47.09.7L8.04 9.81C7.5 9.31 6.79 9 6 9c-1.66 0-3 1.34-3 3s1.34 3 3 3c.79 0 1.5-.31 2.04-.81l7.12 4.16c-.05.21-.08.43-.08.65 0 1.61 1.31 2.92 2.92 2.92s2.92-1.31 2.92-2.92-1.31-2.92-2.92-2.92z",edit:"M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04a.996.996 0 0 0 0-1.41l-2.34-2.34a.996.996 0 0 0-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z",pick:"M12 8c-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4-1.79-4-4-4zm8.94 3A8.994 8.994 0 0 0 13 3.06V1h-2v2.06A8.994 8.994 0 0 0 3.06 11H1v2h2.06A8.994 8.994 0 0 0 11 20.94V23h2v-2.06A8.994 8.994 0 0 0 20.94 13H23v-2h-2.06zM12 19c-3.87 0-7-3.13-7-7s3.13-7 7-7 7 3.13 7 7-3.13 7-7 7z",show:"M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z",undo:"M12.5 8c-2.65 0-5.05.99-6.9 2.6L2 7v9h9l-3.62-3.62c1.39-1.16 3.16-1.88 5.12-1.88 3.54 0 6.55 2.31 7.6 5.5l2.37-.78C21.08 11.03 17.15 8 12.5 8z",redo:"M18.4 10.6C16.55 8.99 14.15 8 11.5 8c-4.65 0-8.58 3.03-9.96 7.22L3.9 16c1.05-3.19 4.05-5.5 7.6-5.5 1.95 0 3.73.72 5.12 1.88L13 16h9V7l-3.6 3.6z",copy:"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z",code:"M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4z",tune:"M3 17v2h6v-2H3zM3 5v2h10V5H3zm10 16v-2h8v-2h-8v-2h-2v6h2zM7 9v2H3v2h4v2h2V9H7zm14 4v-2H11v2h10zm-6-4h2V7h4V5h-4V3h-2v6z",more:"M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z",check:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z",listen:"M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z",first:"M6 6h2v12H6zm3.5 6l8.5 6V6z",demos:"M10 8v8l5-4-5-4zm9-5H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V5h14v14z",expand:"M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6z",right:"M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z",subtitles:"M20 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zM4 12h4v2H4v-2zm10 6H4v-2h10v2zm6 0h-4v-2h4v2zm0-4H10v-2h10v2z",minimize:"M6 19h12v2H6z",maximize:"M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z",duplicate:"M15 1H4c-1.1 0-2 .9-2 2v13h2V3h11V1zm-1 4l6 6v10c0 1.1-.9 2-2 2H7.99C6.89 23 6 22.1 6 21l.01-14c0-1.1.89-2 1.99-2h6zm-1 7h5.5L13 6.5V12z",flash:"M7 2v11h3v9l7-12h-4l4-8z",spark:"M19 9l1.25-2.75L23 5l-2.75-1.25L19 1l-1.25 2.75L15 5l2.75 1.25L19 9zm-7.5.5L9 4 6.5 9.5 1 12l5.5 2.5L9 20l2.5-5.5L17 12l-5.5-2.5zM19 15l-1.25 2.75L15 19l2.75 1.25L19 23l1.25-2.75L23 19l-2.75-1.25L19 15z",send:"M2.01 21L23 12 2.01 3 2 10l15 2-15 2z",guide:"M5 13.18v4L12 21l7-3.82v-4L12 17l-7-3.82zM12 3L1 9l11 6 9-4.91V17h2V9L12 3z",loop:"M7 7h10v3l4-4-4-4v3H5v6h2V7zm10 10H7v-3l-4 4 4 4v-3h12v-6h-2v4z",music:"M12 3v10.55c-.59-.34-1.27-.55-2-.55-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z",back:"M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z",present:"M21 3H3c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h5v2h8v-2h5c1.1 0 1.99-.9 1.99-2L23 5c0-1.1-.9-2-2-2zm0 14H3V5h18v12z",light:"M12 7a5 5 0 1 0 0 10 5 5 0 0 0 0-10zM2 13h2a1 1 0 0 0 0-2H2a1 1 0 0 0 0 2zm18 0h2a1 1 0 0 0 0-2h-2a1 1 0 0 0 0 2zM11 2v2a1 1 0 0 0 2 0V2a1 1 0 0 0-2 0zm0 18v2a1 1 0 0 0 2 0v-2a1 1 0 0 0-2 0zM5.99 4.58a1 1 0 0 0-1.41 1.41l1.06 1.06a1 1 0 0 0 1.41-1.41L5.99 4.58zm12.37 12.37a1 1 0 0 0-1.41 1.41l1.06 1.06a1 1 0 0 0 1.41-1.41l-1.06-1.06zm1.06-10.96a1 1 0 0 0-1.41-1.41l-1.06 1.06a1 1 0 0 0 1.41 1.41l1.06-1.06zM7.05 18.36a1 1 0 0 0-1.41-1.41l-1.06 1.06a1 1 0 0 0 1.41 1.41l1.06-1.06z",dark:"M12 3a9 9 0 1 0 9 9c0-.46-.04-.92-.1-1.36a5.39 5.39 0 0 1-4.4 2.26 5.4 5.4 0 0 1-3.14-9.8c-.44-.06-.9-.1-1.36-.1z",voice:"M9 13c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4zm6.08-7.95c.84 1.18.84 2.71 0 3.89l1.68 1.69c2.02-2.02 2.02-5.07 0-7.27l-1.68 1.69zM20.07 2l-1.63 1.63c2.77 3.02 2.77 7.56 0 10.74L20.07 16c3.9-3.89 3.91-9.95 0-14z",premium:"M7 18h2V6H7v12zm4 4h2V2h-2v20zm-8-8h2v-4H3v4zm12 4h2V6h-2v12zm4-8v4h2v-4h-2z",novoice:"M9 13c2.21 0 4-1.79 4-4 0-.55-.11-1.07-.31-1.55L7.45 12.69c.48.2 1 .31 1.55.31zM2.81 2.81 1.39 4.22l3.08 3.08A4 4 0 0 0 5 9c0 .74.2 1.43.55 2.02L1 19v2h14.17l4.61 4.61 1.41-1.41L2.81 2.81zM20.07 2l-1.63 1.63c2.77 3.02 2.77 7.56 0 10.74L20.07 16c3.9-3.89 3.91-9.95 0-14z",computer:"M20 18c1.1 0 1.99-.9 1.99-2L22 6c0-1.1-.9-2-2-2H4c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2H0v2h24v-2h-4zM4 6h16v10H4V6z",language:"M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zm6.93 6h-2.95a15.65 15.65 0 0 0-1.38-3.56A8.03 8.03 0 0 1 18.92 8zM12 4.04c.83 1.2 1.48 2.53 1.91 3.96h-3.82c.43-1.43 1.08-2.76 1.91-3.96zM4.26 14C4.1 13.36 4 12.69 4 12s.1-1.36.26-2h3.38c-.08.66-.14 1.32-.14 2s.06 1.34.14 2H4.26zm.82 2h2.95c.32 1.25.78 2.45 1.38 3.56A8 8 0 0 1 5.08 16zm2.95-8H5.08a8 8 0 0 1 4.33-3.56A15.65 15.65 0 0 0 8.03 8zM12 19.96c-.83-1.2-1.48-2.53-1.91-3.96h3.82c-.43 1.43-1.08 2.76-1.91 3.96zM14.34 14H9.66c-.09-.66-.16-1.32-.16-2s.07-1.35.16-2h4.68c.09.65.16 1.32.16 2s-.07 1.34-.16 2zm.25 5.56c.6-1.11 1.06-2.31 1.38-3.56h2.95a8.03 8.03 0 0 1-4.33 3.56zM16.36 14c.08-.66.14-1.32.14-2s-.06-1.34-.14-2h3.38c.16.64.26 1.31.26 2s-.1 1.36-.26 2h-3.38z"};export function Icon({name:c}){return e.createElement("svg",{className:"i",viewBox:"0 0 24 24","aria-hidden":"true"},e.createElement("path",{d:n[c]}))}export function Button({icon:c,kind:t,on:l,small:n,className:a,children:h,...v}){const o=c&&!h,r=["btn",o&&"icon",t,l&&"on",n&&"small",a].filter(Boolean).join(" ");return e.createElement("button",{type:"button",className:r,"aria-label":o?v.title:void 0,...v},c&&e.createElement(Icon,{name:c}),h)}export function Labelled({label:c,children:t,className:l}){return e.createElement("label",{className:["labelled",l].filter(Boolean).join(" ")},e.createElement("span",null,c),t)}export function Check({label:c,checked:t,onChange:l,title:n}){return e.createElement("label",{className:"check",title:n},e.createElement("input",{type:"checkbox",checked:t,onChange:e=>l(e.target.checked)}),c)}export function Segmented({value:c,options:t,onChange:l}){return e.createElement("div",{className:"segmented"},t.map(([t,n,a])=>e.createElement("button",{key:t,type:"button",className:t===c?"on":"",title:a,onClick:()=>l(t)},n)))}export function NumberField({value:t,onChange:n,placeholder:a,title:h,width:v=80}){const[o,r]=l(void 0===t?"":String(t));return c(()=>{Number(o)===t||""===o&&void 0===t||r(void 0===t?"":String(t))},[t]),e.createElement("input",{className:"field",style:{width:v},inputMode:"numeric",placeholder:a,title:h,value:o,onChange:e=>{r(e.target.value);const c=e.target.value.trim();""===c?n(void 0):Number.isFinite(Number(c))&&n(Number(c))}})}export function JsonField({value:n,onChange:a,className:h,rows:v=1}){const o=JSON.stringify(n),[r,i]=l(o??""),[z,m]=l(!1),s=t(o);c(()=>{o!==s.current&&(s.current=o,i(o??""),m(!1))},[o]);const M=v>1?"textarea":"input";return e.createElement(M,{className:["field","mono",z&&"wrong",h].filter(Boolean).join(" "),rows:v>1?v:void 0,value:r,onChange:e=>{i(e.target.value);try{const c=""===e.target.value.trim()?void 0:JSON.parse(e.target.value);s.current=JSON.stringify(c),m(!1),a(c)}catch{m(!0)}}})}export function Menu({icon:n="more",label:a,title:h,items:v,align:o="right"}){const[r,i]=l(!1),z=t(null);return c(()=>{if(!r)return;const e=e=>{e.composedPath().includes(z.current)||i(!1)},c=z.current.getRootNode();return c.addEventListener("pointerdown",e,!0),()=>c.removeEventListener("pointerdown",e,!0)},[r]),e.createElement("span",{ref:z,style:{position:"relative",display:"inline-flex"}},e.createElement(Button,{icon:n,title:h,kind:a?void 0:"bare",on:r,onClick:()=>i(!r)},a),r&&e.createElement("div",{className:"menu",style:{top:"calc(100% + 4px)",[o]:0}},v.filter(Boolean).map((c,t)=>c&&"heading"in c?e.createElement("div",{key:t,className:"heading"},c.heading):c&&e.createElement("button",{key:t,type:"button",className:"item",disabled:c.disabled,onClick:()=>{i(!1),c.onClick()}},c.icon&&e.createElement(Icon,{name:c.icon}),c.label))))}export function useTheme(e="dark"){const t="function"==typeof matchMedia?matchMedia("(prefers-color-scheme: dark)"):void 0,[n,a]=l(t?.matches??!0);return c(()=>{if(!t)return;const e=()=>a(t.matches);return t.addEventListener("change",e),()=>t.removeEventListener("change",e)},[]),"auto"===e?n?"dark":"light":e}
|
package/ui/Library.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e,{useEffect as t,useLayoutEffect as a,useRef as n,useState as o}from"react";import{createPortal as l}from"react-dom";import{clock as i}from"../model/Timing.js";import{elevenLabsVoices as s,KOKORO_VOICES as r,piperVoices as c}from"../speech/Speech.js";import{pickFile as m}from"../store/Share.js";import{useDemos as d,useEngine as p}from"./Hooks.js";import{Button as g,Check as h,Icon as u,Labelled as E,Menu as v,Segmented as b,useTheme as k}from"./Kit.js";import{Flagged as y}from"./Flag.js";import{VideoLook as w}from"./Dialogs.js";import{UI_CSS as f}from"./Styles.js";const N=[["free","Free","Neural voices in the browser, no key: Kokoro for English, Piper for ~40 languages. Downloaded once (80-330 MB), then kept."],["elevenlabs","ElevenLabs","Premium voices with your own key. Each sentence is paid for once, then kept in this browser."],["system","System","The browser's own voices: instant, but videos don't hear them."],["off","Off","Subtitles only, timed to reading."]];export function DemoLibrary({engine:t,theme:a}){const n=k(a??t.options.theme??"auto");return e.createElement(Shadow,null,e.createElement(Library,{engine:t,theme:n}))}export function Shadow({children:t}){const i=n(null),[s,r]=o();return a(()=>{const e=i.current,t=e.shadowRoot??e.attachShadow({mode:"open"});if(!t.querySelector("style[data-pde]")){const a=e.ownerDocument.createElement("style");a.setAttribute("data-pde",""),a.textContent=f,t.append(a)}r(t)},[]),e.createElement("div",{ref:i,"data-demo-ignore":!0,style:{display:"contents"}},s&&l(t,s))}export function Library({engine:t,theme:a,floating:n}){const o=p(t),l=d(t),i="idle"!==o.session.mode,s=o.library??"demos",r=async e=>{const{demo:a,problems:n}=t.parse(e);if(!a)return t.say(`Not a demo: ${n.slice(0,3).map(e=>`${e.path||"demo"} ${e.message}`).join("; ")}`,!0);await t.save(a),t.openStudio(a)};return"settings"===s?e.createElement("div",{className:"pde library"+(n?" floating":""),"data-theme":a,"data-demo-ignore":!0},e.createElement("div",{className:"row"},e.createElement(g,{icon:"back",kind:"bare",title:"Back to the demos",onClick:()=>t.showLibrary(n?"demos":void 0)}),e.createElement("h2",{className:"grow"},"Settings")),e.createElement(Settings,{engine:t})):e.createElement("div",{className:"pde library"+(n?" floating":""),"data-theme":a,"data-demo-ignore":!0},e.createElement("div",{className:"row"},e.createElement("h2",{className:"grow"},"Demos"),o.loop&&e.createElement(g,{small:!0,icon:"stop",onClick:()=>t.stopLoop()},"Stop the loop"),e.createElement(v,{title:"Make a demo",icon:"add",label:"New",items:[{label:"Record one: do it on the page",icon:"record",disabled:i,onClick:()=>t.openDialog({kind:"record"})},{label:"Start empty, in the studio",icon:"edit",onClick:()=>t.openStudio(t.create())},{label:"Import a .demo.json",icon:"upload",onClick:()=>{m().then(e=>e?.text()).then(e=>{if(e)return r(e)})}},{label:"Paste its JSON",icon:"copy",onClick:()=>{navigator.clipboard.readText().then(r,()=>t.say("Could not read the clipboard",!0))}}]}),e.createElement(g,{icon:"tune",kind:"bare",title:"Settings: voices, languages, subtitles",onClick:()=>t.openSettings()})),o.message&&e.createElement("div",{className:"small "+(o.message.error?"error":"muted")},o.message.text),0===l.length&&e.createElement("div",{className:"small muted"},"None yet: record one (New), or ask an AI to make one (it starts with demoEngine.help())."),l.map(a=>e.createElement(C,{key:a.demo.id,engine:t,entry:a,busy:i})),l.length>1&&e.createElement(g,{kind:"bare",icon:"loop",disabled:i,onClick:()=>t.openDialog({kind:"loop",demos:l.map(e=>e.demo)})},"Loop them all at a booth…"))}function C({engine:t,entry:a,busy:n}){const{demo:o,origin:l,video:s}=a,r=i(t.timing(o).duration);return e.createElement("div",{className:"demo"},e.createElement("div",{className:"row"},e.createElement("span",{className:"title grow ellipsis",title:o.description},o.title),"app"!==l&&e.createElement("span",{className:"badge"},"edited"===l?"edited here":"made here")),o.description&&e.createElement("div",{className:"small muted"},o.description),e.createElement("div",{className:"small muted"},o.steps.length," steps · ~",r,t.languagesOf(o).length?` · ${t.languagesOf(o).join(", ")}`:""),e.createElement("div",{className:"row"},e.createElement(g,{icon:"play",small:!0,kind:"primary",disabled:n,onClick:()=>{t.play(o)}},"Play"),e.createElement(g,{icon:"present",small:!0,disabled:n,title:"Step by step, the presenter’s screen beside it",onClick:()=>t.present(o)},"Present"),e.createElement(g,{icon:"guide",small:!0,disabled:n,title:"The viewer does each step: a tutorial",onClick:()=>{t.guide(o)}},"Guide"),e.createElement("span",{className:"grow"}),e.createElement(g,{icon:"edit",small:!0,kind:"bare",title:"Edit in the studio",onClick:()=>t.openStudio(o)}),e.createElement(v,{title:"More",items:[{label:"Film a video…",icon:"film",disabled:n,onClick:()=>t.openDialog({kind:"film",demo:o})},{label:"Loop at a booth…",icon:"loop",disabled:n,onClick:()=>t.openDialog({kind:"loop",demos:[o]})},s&&{label:"The video’s subtitles .srt",icon:"subtitles",onClick:()=>t.downloadVideo(s,o.title,"srt")},s&&{label:"Share the video…",icon:"share",onClick:()=>{t.shareVideo(s,o.title).then(e=>!e&&t.say("No share sheet here: download it instead."))}},{heading:"Share the demo"},{label:"Copy a link with the demo",icon:"link",onClick:()=>{t.link(o).then(e=>navigator.clipboard.writeText(e)).then(()=>t.say("Link copied."))}},{label:"Download .demo.json",icon:"download",onClick:()=>t.downloadDemo(o)},{label:"Download scenario .md",icon:"download",onClick:()=>t.downloadDemo({...o,scenario:a.scenario},"md")},{label:"Narration pack (.zip)",icon:"listen",onClick:()=>{t.downloadPack(o)}},{heading:"This demo"},{label:"Clone",icon:"duplicate",onClick:()=>t.openStudio({...JSON.parse(JSON.stringify(o)),id:t.create(o.title).id,title:`${o.title} (copy)`})},"edited"===l&&{label:"Revert to the app’s version",icon:"undo",onClick:()=>window.confirm("Drop the changes kept here?")&&void t.remove(o.id)},"here"===l&&{label:"Delete",icon:"delete",onClick:()=>window.confirm(`Delete "${o.title}"?`)&&void t.remove(o.id)}]})),s&&e.createElement("div",{className:"row video-line"},e.createElement(u,{name:"film"}),e.createElement(w,{video:s}),e.createElement("span",{className:"grow small muted ellipsis",title:new Date(s.at).toLocaleString()},new Date(s.at).toLocaleDateString(),s.json!==JSON.stringify(o)&&s.json!==JSON.stringify({...o,scenario:void 0})?" · older version":""),e.createElement(g,{icon:"play",small:!0,kind:"bare",title:"Watch",onClick:()=>t.openDialog({kind:"video",demo:o,video:s})}),e.createElement(g,{icon:"download",small:!0,kind:"bare",title:s.look?.subtitles?"Download":"Download, with its subtitles beside it",onClick:()=>{t.downloadVideo(s,o.title),s.look?.subtitles||t.downloadVideo(s,o.title,"vtt")}}),e.createElement(g,{icon:"delete",small:!0,kind:"bare",title:"Delete the video",onClick:()=>{window.confirm("Delete this video?")&&t.store.deleteVideo(s.id)}})))}export function Settings({engine:t}){const{settings:a,speech:n}=p(t),o=a.speech.voice,l=t.language(),i=e=>t.changeSettings({speech:{...a.speech,...e}});return e.createElement(e.Fragment,null,e.createElement("section",{className:"section"},e.createElement("h3",null,"Voice"),e.createElement(b,{value:o,onChange:e=>i({voice:e}),options:N.map(([e,t,a])=>[e,t,a])}),"free"===o&&e.createElement(S,{engine:t}),"elevenlabs"===o&&e.createElement(D,{engine:t}),"system"===o&&e.createElement(L,{engine:t,language:l}),e.createElement(E,{label:`Speed ${a.speech.rate.toFixed(2)}×`},e.createElement("input",{type:"range",min:.7,max:1.4,step:.05,value:a.speech.rate,onChange:e=>i({rate:Number(e.target.value)})})),void 0!==n.loading&&e.createElement("div",{className:"col",style:{gap:2}},e.createElement("span",{className:"small muted"},"Downloading a model: ",Math.round(100*n.loading)," %"),e.createElement("div",{className:"progress"},e.createElement("div",{style:{width:100*n.loading+"%"}}))),n.error&&e.createElement("div",{className:"small error"},"Voice: ",n.error)),e.createElement("section",{className:"section"},e.createElement("h3",null,"Language and subtitles"),e.createElement(E,{label:"Narration in"},e.createElement(b,{value:a.language,onChange:e=>t.changeSettings({language:e}),options:[["page",e.createElement(y,{key:"page",language:"page"},"The page's"),`The page's language: ${t.options.language?.()??l} now`],...t.languages().map(t=>[t,e.createElement(y,{key:t,language:t})])]})),e.createElement(h,{label:"Subtitles",checked:a.subtitles,onChange:e=>t.changeSettings({subtitles:e})}),e.createElement(h,{label:"A demo's narration pack, where it has one",title:"Its audio made once and checked in: no key, no download; what changed since, the voice says",checked:a.usePacks,onChange:e=>t.changeSettings({usePacks:e})})),e.createElement("section",{className:"section"},e.createElement("h3",null,"Playing from a step"),e.createElement(h,{label:"Earlier steps first, quickly: the app where the step expects it",checked:a.catchUp,onChange:e=>t.changeSettings({catchUp:e})})),e.createElement("div",{className:"small muted"},"Playing: Space pauses, → or PageDown goes on, ← or PageUp goes back, 1-9 a step, Esc stops. Videos, recordings, booths and presentations ask what they need as they start."))}function S({engine:a}){const{settings:n}=p(a),[l,i]=o([]);return t(()=>{c().then(i,()=>i([]))},[]),e.createElement("div",{className:"col"},a.languages().map(t=>{const o=a.speech.freeVoice(t)??"",i=t.split(/[-_]/)[0],s=l.filter(e=>e.language.split("_")[0]===i);return e.createElement(E,{key:t,label:`Voice for ${t}`},e.createElement("select",{className:"field",value:o,onChange:e=>a.changeSettings({speech:{...n.speech,free:{...n.speech.free,[t]:e.target.value}}})},!o&&e.createElement("option",{value:""},"None: choose one"),"en"===i&&e.createElement("optgroup",{label:"Kokoro"},r.map(t=>e.createElement("option",{key:t.id,value:`kokoro:${t.id}`},t.name))),e.createElement("optgroup",{label:"Piper"},o.startsWith("piper:")&&!s.some(e=>`piper:${e.id}`===o)&&e.createElement("option",{value:o},o.slice(6)),s.map(t=>e.createElement("option",{key:t.id,value:`piper:${t.id}`},t.name)))))}))}function D({engine:a}){const{settings:n}=p(a),{key:l,voices:i={}}=n.speech.elevenlabs,[r,c]=o([]),m=e=>a.changeSettings({speech:{...n.speech,elevenlabs:{...n.speech.elevenlabs,...e}}});t(()=>{l&&s(l).then(c,()=>c([]))},[l]);const d=a.languages();return e.createElement("div",{className:"col"},e.createElement(E,{label:"API key, kept in this browser"},e.createElement("input",{className:"field",type:"password",autoComplete:"off",value:l,onChange:e=>m({key:e.target.value.trim()})})),r.length>0&&d.map((t,n)=>{const o=a.speech.elevenLabsVoice(t),l=t.toLowerCase().split(/[-_]/)[0],s=r.filter(e=>e.languages.includes(l)),c=r.filter(e=>!e.languages.includes(l)),d=function(e){try{return new Intl.DisplayNames(["en"],{type:"language"}).of(e)??e}catch{return e}}(l);return e.createElement(E,{key:t,label:`Voice for ${d}`},e.createElement("select",{className:"field",value:o,onChange:e=>m({voices:{...i,[t]:e.target.value},...0===n?{voice:e.target.value}:{}})},!r.some(e=>e.id===o)&&e.createElement("option",{value:o},o),s.length>0&&e.createElement("optgroup",{label:`Checked for ${d}`},s.map(t=>e.createElement("option",{key:t.id,value:t.id},t.name))),e.createElement("optgroup",{label:s.length>0?"Other voices: they speak it too":`Every voice speaks ${d}`},c.map(t=>e.createElement("option",{key:t.id,value:t.id},t.name)))))}))}function L({engine:a,language:n}){const{settings:l}=p(a),[i,s]=o(()=>speechSynthesis.getVoices());t(()=>{const e=()=>s(speechSynthesis.getVoices());return speechSynthesis.addEventListener("voiceschanged",e),()=>speechSynthesis.removeEventListener("voiceschanged",e)},[]);const r=i.filter(e=>e.lang.toLowerCase().startsWith(n.toLowerCase().split("-")[0]));return e.createElement(E,{label:`Voice for ${n}`},e.createElement("select",{className:"field",value:l.speech.system[n]??"",onChange:e=>a.changeSettings({speech:{...l.speech,system:{...l.speech.system,[n]:e.target.value}}})},e.createElement("option",{value:""},"The default"),r.map(t=>e.createElement("option",{key:t.name,value:t.name},t.name))))}
|
|
1
|
+
import e,{useEffect as t,useLayoutEffect as a,useRef as n,useState as o}from"react";import{createPortal as l}from"react-dom";import{clock as i}from"../model/Timing.js";import{elevenLabsVoices as s,KOKORO_VOICES as r,piperVoices as c}from"../speech/Speech.js";import{pickFile as m}from"../store/Share.js";import{useDemos as d,useEngine as p}from"./Hooks.js";import{Button as g,Check as h,Icon as u,Labelled as E,Menu as k,Segmented as b,useTheme as v}from"./Kit.js";import{Flagged as y}from"./Flag.js";import{VideoLook as w}from"./Dialogs.js";import{UI_CSS as f}from"./Styles.js";const C=[["free","Free","Neural voices in the browser, no key: Kokoro for English, Piper for ~40 languages. Downloaded once (80-330 MB), then kept."],["elevenlabs","ElevenLabs","Premium voices with your own key. Each sentence is paid for once, then kept in this browser."],["system","System","The browser's own voices: instant, but videos don't hear them."],["off","Off","Subtitles only, timed to reading."]];export function DemoLibrary({engine:t,theme:a}){const n=v(a??t.options.theme??"auto");return e.createElement(Shadow,null,e.createElement(Library,{engine:t,theme:n}))}export function Shadow({children:t}){const i=n(null),[s,r]=o();return a(()=>{const e=i.current,t=e.shadowRoot??e.attachShadow({mode:"open"});if(!t.querySelector("style[data-pde]")){const a=e.ownerDocument.createElement("style");a.setAttribute("data-pde",""),a.textContent=f,t.append(a)}r(t)},[]),e.createElement("div",{ref:i,"data-demo-ignore":!0,style:{display:"contents"}},s&&l(t,s))}export function Library({engine:t,theme:a,floating:n}){const o=p(t),l=d(t),i="idle"!==o.session.mode,s=o.library??"demos",r=async e=>{const{demo:a,problems:n}=t.parse(e);if(!a)return t.say(`Not a demo: ${n.slice(0,3).map(e=>`${e.path||"demo"} ${e.message}`).join("; ")}`,!0);await t.save(a),t.openStudio(a)};return"settings"===s?e.createElement("div",{className:"pde library"+(n?" floating":""),"data-theme":a,"data-demo-ignore":!0},e.createElement("div",{className:"row"},e.createElement(g,{icon:"back",kind:"bare",title:"Back to the demos",onClick:()=>t.showLibrary(n?"demos":void 0)}),e.createElement("h2",{className:"grow"},"Settings")),e.createElement(Settings,{engine:t})):e.createElement("div",{className:"pde library"+(n?" floating":""),"data-theme":a,"data-demo-ignore":!0},e.createElement("div",{className:"row"},e.createElement("h2",{className:"grow"},"Demos"),o.loop&&e.createElement(g,{small:!0,icon:"stop",onClick:()=>t.stopLoop()},"Stop the loop"),e.createElement(k,{title:"Make a demo",icon:"add",label:"New",items:[!1!==t.options.assistant&&{label:"Ask Claude: say what it should show",icon:"spark",onClick:()=>t.openAssistant()},{label:"Record one: do it on the page",icon:"record",disabled:i,onClick:()=>t.openDialog({kind:"record"})},{label:"Start empty, in the studio",icon:"edit",onClick:()=>t.openStudio(t.create())},{label:"Import a .demo.json",icon:"upload",onClick:()=>{m().then(e=>e?.text()).then(e=>{if(e)return r(e)})}},{label:"Paste its JSON",icon:"copy",onClick:()=>{navigator.clipboard.readText().then(r,()=>t.say("Could not read the clipboard",!0))}}]}),e.createElement(g,{icon:"tune",kind:"bare",title:"Settings: voices, languages, subtitles",onClick:()=>t.openSettings()})),o.message&&e.createElement("div",{className:"small "+(o.message.error?"error":"muted")},o.message.text),0===l.length&&e.createElement("div",{className:"small muted"},!1!==t.options.assistant?"None yet: New → Ask Claude, or record one.":"None yet: record one (New)."),l.map(a=>e.createElement(N,{key:a.demo.id,engine:t,entry:a,busy:i})),l.length>1&&e.createElement(g,{kind:"bare",icon:"loop",disabled:i,onClick:()=>t.openDialog({kind:"loop",demos:l.map(e=>e.demo)})},"Loop them all at a booth…"))}function N({engine:t,entry:a,busy:n}){const{demo:o,origin:l,video:s}=a,r=i(t.timing(o).duration);return e.createElement("div",{className:"demo"},e.createElement("div",{className:"row"},e.createElement("span",{className:"title grow ellipsis",title:o.description},o.title),"app"!==l&&e.createElement("span",{className:"badge"},"edited"===l?"edited here":"made here")),o.description&&e.createElement("div",{className:"small muted"},o.description),e.createElement("div",{className:"small muted"},o.steps.length," steps · ~",r,t.languagesOf(o).length?` · ${t.languagesOf(o).join(", ")}`:""),e.createElement("div",{className:"row"},e.createElement(g,{icon:"play",small:!0,kind:"primary",disabled:n,onClick:()=>{t.play(o)}},"Play"),e.createElement(g,{icon:"present",small:!0,disabled:n,title:"Step by step, the presenter’s screen beside it",onClick:()=>t.present(o)},"Present"),e.createElement(g,{icon:"guide",small:!0,disabled:n,title:"The viewer does each step: a tutorial",onClick:()=>{t.guide(o)}},"Guide"),e.createElement("span",{className:"grow"}),e.createElement(g,{icon:"edit",small:!0,kind:"bare",title:"Edit in the studio",onClick:()=>t.openStudio(o)}),e.createElement(k,{title:"More",items:[{label:"Film a video…",icon:"film",disabled:n,onClick:()=>t.openDialog({kind:"film",demo:o})},{label:"Loop at a booth…",icon:"loop",disabled:n,onClick:()=>t.openDialog({kind:"loop",demos:[o]})},s&&{label:"The video’s subtitles .srt",icon:"subtitles",onClick:()=>t.downloadVideo(s,o.title,"srt")},s&&{label:"Share the video…",icon:"share",onClick:()=>{t.shareVideo(s,o.title).then(e=>!e&&t.say("No share sheet here: download it instead."))}},{heading:"Share the demo"},{label:"Copy a link with the demo",icon:"link",onClick:()=>{t.link(o).then(e=>navigator.clipboard.writeText(e)).then(()=>t.say("Link copied."))}},{label:"Download .demo.json",icon:"download",onClick:()=>t.downloadDemo(o)},{label:"Download scenario .md",icon:"download",onClick:()=>t.downloadDemo({...o,scenario:a.scenario},"md")},{label:"Narration pack (.zip)",icon:"listen",onClick:()=>{t.downloadPack(o)}},{heading:"This demo"},{label:"Clone",icon:"duplicate",onClick:()=>t.openStudio({...JSON.parse(JSON.stringify(o)),id:t.create(o.title).id,title:`${o.title} (copy)`})},!1!==t.options.assistant&&{label:"Ask Claude about it: change, clone, translate",icon:"spark",onClick:()=>t.openAssistant(o)},"edited"===l&&{label:"Revert to the app’s version",icon:"undo",onClick:()=>window.confirm("Drop the changes kept here?")&&void t.remove(o.id)},"here"===l&&{label:"Delete",icon:"delete",onClick:()=>window.confirm(`Delete "${o.title}"?`)&&void t.remove(o.id)}]})),s&&e.createElement("div",{className:"row video-line"},e.createElement(u,{name:"film"}),e.createElement(w,{video:s}),e.createElement("span",{className:"grow small muted ellipsis",title:new Date(s.at).toLocaleString()},new Date(s.at).toLocaleDateString(),s.json!==JSON.stringify(o)&&s.json!==JSON.stringify({...o,scenario:void 0})?" · older version":""),e.createElement(g,{icon:"play",small:!0,kind:"bare",title:"Watch",onClick:()=>t.openDialog({kind:"video",demo:o,video:s})}),e.createElement(g,{icon:"download",small:!0,kind:"bare",title:s.look?.subtitles?"Download":"Download, with its subtitles beside it",onClick:()=>{t.downloadVideo(s,o.title),s.look?.subtitles||t.downloadVideo(s,o.title,"vtt")}}),e.createElement(g,{icon:"delete",small:!0,kind:"bare",title:"Delete the video",onClick:()=>{window.confirm("Delete this video?")&&t.store.deleteVideo(s.id)}})))}export function Settings({engine:t}){const{settings:a,speech:n}=p(t),o=a.speech.voice,l=t.language(),i=e=>t.changeSettings({speech:{...a.speech,...e}});return e.createElement(e.Fragment,null,e.createElement("section",{className:"section"},e.createElement("h3",null,"Voice"),e.createElement(b,{value:o,onChange:e=>i({voice:e}),options:C.map(([e,t,a])=>[e,t,a])}),"free"===o&&e.createElement(S,{engine:t}),"elevenlabs"===o&&e.createElement(D,{engine:t}),"system"===o&&e.createElement(L,{engine:t,language:l}),e.createElement(E,{label:`Speed ${a.speech.rate.toFixed(2)}×`},e.createElement("input",{type:"range",min:.7,max:1.4,step:.05,value:a.speech.rate,onChange:e=>i({rate:Number(e.target.value)})})),void 0!==n.loading&&e.createElement("div",{className:"col",style:{gap:2}},e.createElement("span",{className:"small muted"},"Downloading a model: ",Math.round(100*n.loading)," %"),e.createElement("div",{className:"progress"},e.createElement("div",{style:{width:100*n.loading+"%"}}))),n.error&&e.createElement("div",{className:"small error"},"Voice: ",n.error)),e.createElement("section",{className:"section"},e.createElement("h3",null,"Language and subtitles"),e.createElement(E,{label:"Narration in"},e.createElement(b,{value:a.language,onChange:e=>t.changeSettings({language:e}),options:[["page",e.createElement(y,{key:"page",language:"page"},"The page's"),`The page's language: ${t.options.language?.()??l} now`],...t.languages().map(t=>[t,e.createElement(y,{key:t,language:t})])]})),e.createElement(h,{label:"Subtitles",checked:a.subtitles,onChange:e=>t.changeSettings({subtitles:e})}),e.createElement(h,{label:"A demo's narration pack, where it has one",title:"Its audio made once and checked in: no key, no download; what changed since, the voice says",checked:a.usePacks,onChange:e=>t.changeSettings({usePacks:e})})),e.createElement("section",{className:"section"},e.createElement("h3",null,"Playing from a step"),e.createElement(h,{label:"Earlier steps first, quickly: the app where the step expects it",checked:a.catchUp,onChange:e=>t.changeSettings({catchUp:e})})),e.createElement("div",{className:"small muted"},"Playing: Space pauses, → or PageDown goes on, ← or PageUp goes back, 1-9 a step, Esc stops. Videos, recordings, booths and presentations ask what they need as they start."))}function S({engine:a}){const{settings:n}=p(a),[l,i]=o([]);return t(()=>{c().then(i,()=>i([]))},[]),e.createElement("div",{className:"col"},a.languages().map(t=>{const o=a.speech.freeVoice(t)??"",i=t.split(/[-_]/)[0],s=l.filter(e=>e.language.split("_")[0]===i);return e.createElement(E,{key:t,label:`Voice for ${t}`},e.createElement("select",{className:"field",value:o,onChange:e=>a.changeSettings({speech:{...n.speech,free:{...n.speech.free,[t]:e.target.value}}})},!o&&e.createElement("option",{value:""},"None: choose one"),"en"===i&&e.createElement("optgroup",{label:"Kokoro"},r.map(t=>e.createElement("option",{key:t.id,value:`kokoro:${t.id}`},t.name))),e.createElement("optgroup",{label:"Piper"},o.startsWith("piper:")&&!s.some(e=>`piper:${e.id}`===o)&&e.createElement("option",{value:o},o.slice(6)),s.map(t=>e.createElement("option",{key:t.id,value:`piper:${t.id}`},t.name)))))}))}function D({engine:a}){const{settings:n}=p(a),{key:l,voices:i={}}=n.speech.elevenlabs,[r,c]=o([]),m=e=>a.changeSettings({speech:{...n.speech,elevenlabs:{...n.speech.elevenlabs,...e}}});t(()=>{l&&s(l).then(c,()=>c([]))},[l]);const d=a.languages();return e.createElement("div",{className:"col"},e.createElement(E,{label:"API key, kept in this browser"},e.createElement("input",{className:"field",type:"password",autoComplete:"off",value:l,onChange:e=>m({key:e.target.value.trim()})})),r.length>0&&d.map((t,n)=>{const o=a.speech.elevenLabsVoice(t),l=t.toLowerCase().split(/[-_]/)[0],s=r.filter(e=>e.languages.includes(l)),c=r.filter(e=>!e.languages.includes(l)),d=function(e){try{return new Intl.DisplayNames(["en"],{type:"language"}).of(e)??e}catch{return e}}(l);return e.createElement(E,{key:t,label:`Voice for ${d}`},e.createElement("select",{className:"field",value:o,onChange:e=>m({voices:{...i,[t]:e.target.value},...0===n?{voice:e.target.value}:{}})},!r.some(e=>e.id===o)&&e.createElement("option",{value:o},o),s.length>0&&e.createElement("optgroup",{label:`Checked for ${d}`},s.map(t=>e.createElement("option",{key:t.id,value:t.id},t.name))),e.createElement("optgroup",{label:s.length>0?"Other voices: they speak it too":`Every voice speaks ${d}`},c.map(t=>e.createElement("option",{key:t.id,value:t.id},t.name)))))}))}function L({engine:a,language:n}){const{settings:l}=p(a),[i,s]=o(()=>speechSynthesis.getVoices());t(()=>{const e=()=>s(speechSynthesis.getVoices());return speechSynthesis.addEventListener("voiceschanged",e),()=>speechSynthesis.removeEventListener("voiceschanged",e)},[]);const r=i.filter(e=>e.lang.toLowerCase().startsWith(n.toLowerCase().split("-")[0]));return e.createElement(E,{label:`Voice for ${n}`},e.createElement("select",{className:"field",value:l.speech.system[n]??"",onChange:e=>a.changeSettings({speech:{...l.speech,system:{...l.speech.system,[n]:e.target.value}}})},e.createElement("option",{value:""},"The default"),r.map(t=>e.createElement("option",{key:t.name,value:t.name},t.name))))}
|
package/ui/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,JsonField as E,Labelled as w,Menu as k,NumberField as y,Segmented as b}from"./Kit.js";import{Timeline as N}from"./Timeline.js";const C="protomaze-demo-engine:studio-height";export function Studio({engine:d,theme:m}){const j=u(d),$=j.studio,[O,L]=i(()=>l($.demo)),[R,T]=i(()=>JSON.stringify($.demo)),M=n({back:[],forward:[]}),[A,J]=i(0),[B,U]=i(),[F,P]=i("steps"),[V,z]=i({json:"",scenario:""}),[W,H]=i(),[I,K]=i(new Map),[q,Y]=i(()=>Number(localStorage.getItem(C))||Math.round(.46*innerHeight)),[G,Z]=i(!1),[Q,X]=i(!1),[_,ee]=i(!1),[te,ae]=i(!1),[ne,ie]=i(()=>d.language()),le=j.session,oe="idle"!==le.mode,se="playing"!==le.mode||le.checking?void 0:le,re=O.steps,ce=Math.min(A,Math.max(0,re.length-1)),de=se&&se.demo.id===O.id?se.step:ce,me=JSON.stringify(O)!==R,pe=a(()=>Array.from(new Set([...d.languages(),...d.languagesOf(O)])),[O]),he=d.entriesNow().find(e=>e.demo.id===O.id),ge=d.timing(O,ne),ue=j.lastRun?.json===JSON.stringify(O)&&j.lastRun.language===ne,ve=(e,t=!0)=>{t&&(M.current.back.push(O),M.current.back.length>200&&M.current.back.shift(),M.current.forward=[]),L(e)},fe=()=>{const e=M.current.back.pop();e&&(M.current.forward.push(O),L(e))},Ee=()=>{const e=M.current.forward.pop();e&&(M.current.back.push(O),L(e))},we=e=>ve({...O,...e}),ke=e=>we({steps:e}),ye=e=>ke(re.map((t,a)=>a===ce?e:t));t(()=>{$.recorded&&ve({...O,steps:$.recorded.steps})},[$.recorded?.at]);const be=()=>{const{demo:e,problems:t}=d.parse(V.json);if(e)return H(void 0),{...e,scenario:V.scenario};H(t.slice(0,4).map(e=>`${e.path||"demo"}: ${e.message}`).join(" · "))},Ne=async()=>{const e="text"===F?be():O;if(e)try{await d.save(e),L(e),T(JSON.stringify(e)),d.say(`Saved "${e.title}".`)}catch(e){d.say(e.message,!0)}},Ce=e=>{d.play(O,{from:e,language:ne})},xe=e=>{const t=ce+e;if(t<0||t>=re.length)return;const a=[...re];[a[ce],a[t]]=[a[t],a[ce]],ke(a),J(t)},Se=G||te||"recording"===le.mode||Boolean(se),De=re[ce],je=e=>{const t=ge.steps.find(t=>t.step===e);return t?`${((t.end-t.start)/1e3).toFixed(1)} s`:""};return e.createElement("div",{className:"pde studio"+(Se?" collapsed":""),"data-theme":m,"data-demo-ignore":!0,onKeyDown:e=>{if(!(e.ctrlKey||e.metaKey))return;const t=e.key.toLowerCase();"s"===t?(e.preventDefault(),Ne()):"z"!==t||e.shiftKey||"text"===F?("y"===t||"z"===t&&e.shiftKey)&&"text"!==F&&(e.preventDefault(),Ee()):(e.preventDefault(),fe())},style:{height:Se?void 0:q,display:te?"none":void 0}},e.createElement("div",{className:"grip",onPointerDown:e=>{const t=e.clientY,a=q,n=e=>Y(Math.max(180,Math.min(innerHeight-40,a+t-e.clientY))),i=()=>{window.removeEventListener("pointermove",n),window.removeEventListener("pointerup",i),Y(e=>(localStorage.setItem(C,String(e)),e))};window.addEventListener("pointermove",n),window.addEventListener("pointerup",i)}}),e.createElement("div",{className:"head"},e.createElement("input",{className:"field title",value:O.title,title:"Title",onChange:e=>we({title:e.target.value})}),e.createElement("div",{className:"sep"}),!se&&e.createElement(e.Fragment,null,e.createElement(v,{icon:"play",kind:"primary",disabled:oe,title:`Play from step ${ce+1}`,onClick:()=>Ce(ce)},"Play"),e.createElement(k,{title:"Play from the start, present, guide, loop",icon:"expand",align:"left",items:[{label:"From the start",icon:"first",disabled:oe,onClick:()=>Ce(0)},{label:`Present from step ${ce+1}…`,icon:"present",disabled:oe,onClick:()=>d.present(O,{from:ce})},{label:`Guide from step ${ce+1}: the viewer does it`,icon:"guide",disabled:oe,onClick:()=>{d.guide(O,{from:ce,language:ne})}},{label:"Loop at a booth…",icon:"loop",disabled:oe,onClick:()=>d.openDialog({kind:"loop",demos:[O]})},...pe.length>1?[{heading:"Narration in"},...pe.map(e=>({label:`${e===ne?"● ":""}${e}`,onClick:()=>ie(e)}))]:[]]}),e.createElement(v,{icon:"record",title:`Record new steps after step ${ce+1}…`,disabled:oe,onClick:()=>d.openDialog({kind:"record",into:O,after:ce}),style:{color:"var(--danger)"}}),e.createElement(v,{icon:"film",title:"Film a video…",disabled:oe,onClick:()=>d.openDialog({kind:"film",demo:O})}),e.createElement(v,{icon:"check",title:"Check: plays it fast and silent, and marks what fails",disabled:oe,onClick:()=>{(async()=>{const e=await d.check(O);K(new Map(e.failures.map(e=>[`${e.step}.${e.index}`,e.error]))),e.ok?d.say(`Every step plays: ${c(e.duration)} at speed.`):d.say(e.failures.length?`${e.failures.length} action${1===e.failures.length?"":"s"} failed: in red.`:e.error??"Failed",!0);const t=e.failures[0];t&&(J(t.step),U(t.index))})()}})),se&&e.createElement(e.Fragment,null,e.createElement(v,{icon:se.paused?"play":"pause",kind:"primary",onClick:()=>se.waiting?d.next():d.togglePause()},se.waiting?"Continue":se.paused?"Resume":"Pause"),e.createElement(v,{icon:"back",title:"Back (←)",onClick:()=>d.back()}),e.createElement(v,{icon:"right",title:"Next step (→)",onClick:()=>d.next()}),e.createElement(v,{icon:"stop",title:"Stop (Esc)",onClick:()=>d.stop()})),e.createElement("span",{className:"grow"}),e.createElement(v,{icon:"undo",kind:"bare",title:"Undo (Ctrl+Z)",disabled:0===M.current.back.length,onClick:fe}),e.createElement(v,{icon:"redo",kind:"bare",title:"Redo (Ctrl+Y)",disabled:0===M.current.forward.length,onClick:Ee}),e.createElement(v,{icon:"save",kind:me?"primary":void 0,title:"Save here (Ctrl+S)",onClick:()=>{Ne()}},me?"Save":"Saved"),e.createElement(k,{title:"Share, export",icon:"share",items:[{label:"Copy a link with the demo",icon:"link",onClick:()=>{d.link(O).then(e=>navigator.clipboard.writeText(e)).then(()=>d.say("Link copied: it opens the app with this demo."))}},{label:"Download .demo.json",icon:"download",onClick:()=>d.downloadDemo(O)},{label:"Download scenario .md",icon:"download",onClick:()=>d.downloadDemo(O,"md")},{label:"Copy JSON",icon:"copy",onClick:()=>{navigator.clipboard.writeText(JSON.stringify({...O,scenario:void 0,savedAt:void 0},null,2)).then(()=>d.say("JSON copied."))}},{label:"Narration pack (.zip): no key, no download, for every viewer",icon:"listen",onClick:()=>{d.downloadPack(O)}},he?.video&&{label:"Download the video",icon:"film",onClick:()=>d.downloadVideo(he.video,O.title)},("edited"===he?.origin||"here"===he?.origin)&&{heading:"This demo"},"edited"===he?.origin&&{label:"Revert to the app’s version",icon:"undo",onClick:()=>{window.confirm("Drop the changes kept here?")&&d.remove(O.id)}},"here"===he?.origin&&{label:"Delete",icon:"delete",onClick:()=>{window.confirm(`Delete "${O.title}"?`)&&d.remove(O.id)}}]}),e.createElement(b,{value:F,onChange:e=>{if(e!==F){if("text"===F){const e=be();if(!e)return;JSON.stringify(e)!==JSON.stringify(O)&&ve(e)}"text"===e&&(()=>{const{scenario:e,savedAt:t,...a}=O;z({json:JSON.stringify(a,null,2),scenario:O.scenario??s(O,ne)}),H(void 0)})(),P(e)}},options:[["steps","Steps"],["text","Text"],["video","Video",he?.video?"Its last video":"Not filmed yet"]]}),e.createElement(v,{icon:G?"maximize":"minimize",kind:"bare",title:G?"Unfold":"Fold",onClick:()=>Z(!G)}),e.createElement(v,{icon:"close",kind:"bare",title:"Close",onClick:()=>{me&&!window.confirm("Close without saving?")||d.closeStudio()}})),e.createElement(N,{demo:O,timing:ge,measured:ue,step:de,action:B,theme:m,accent:"#ffb300",playhead:se&&se.demo.id===O.id?()=>d.elapsed():void 0,read:e=>g(d,e),onPick:(e,t)=>{se&&se.demo.id===O.id&&d.goTo(e)||(J(e),U(t),G&&Z(!1))}}),W&&e.createElement("div",{className:"error small",style:{padding:"4px 12px"}},W),e.createElement("div",{className:"body"},"text"!==F&&e.createElement("div",{className:"steps"},e.createElement("div",{className:["step",_&&"on"].filter(Boolean).join(" "),style:{marginBottom:4},onClick:()=>{ee(!0),X(!1),U(void 0)},title:"Its title, who it is for, where it starts"},e.createElement("span",{className:"n"},"i"),e.createElement("div",{className:"col grow",style:{gap:2}},e.createElement("span",{style:{fontWeight:500}},"About this demo"),e.createElement("span",{className:"say"},O.description||"Who it is for, what it shows"))),re.map((t,a)=>e.createElement("div",{key:a,className:["step",a===ce&&!Q&&!_&&"on",se&&a===de&&"playing"].filter(Boolean).join(" "),onClick:()=>{J(a),U(void 0),X(!1),ee(!1),function(e){if("video"!==F)return;const t=he?.video?.timing?.steps.find(t=>t.step===e),a=document.querySelector("protomaze-demo-engine")?.shadowRoot?.querySelector("video");t&&a&&(a.currentTime=t.start/1e3)}(a)}},e.createElement("span",{className:"n"},a+1),e.createElement("div",{className:"col grow",style:{gap:2}},e.createElement("div",{className:"row"},e.createElement("span",{className:"grow ellipsis",style:{fontWeight:500}},t.title||function(e,t){return r(o(e,t))[0]}(t,ne)||"Untitled"),e.createElement("span",{className:"small muted"},je(a))),t.title&&e.createElement("span",{className:"say"},o(t,ne)),e.createElement("span",{className:"small muted"},t.actions.length," action",1===t.actions.length?"":"s",t.pause?" · waits":"")))),e.createElement(v,{icon:"add",small:!0,onClick:()=>{ke([...re.slice(0,ce+1),{say:{},actions:[]},...re.slice(ce+1)]),J(ce+1),X(!1)}},"New step"),e.createElement("div",{className:["step",Q&&"on"].filter(Boolean).join(" "),style:{marginTop:6},onClick:()=>{X(!0),ee(!1),U(void 0)},title:"Done after the demo, quickly and unseen, so the app is as it found it"},e.createElement("span",{className:"n"},"↺"),e.createElement("div",{className:"col grow",style:{gap:2}},e.createElement("span",{style:{fontWeight:500}},"Cleanup"),e.createElement("span",{className:"small muted"},(O.cleanup??[]).length," action",1===(O.cleanup??[]).length?"":"s"," after it, unseen")))),"steps"===F&&_&&e.createElement("div",{className:"pane"},e.createElement("strong",null,"About this demo"),e.createElement(w,{label:"Title"},e.createElement("input",{className:"field",value:O.title,onChange:e=>we({title:e.target.value})})),e.createElement(w,{label:"Description: who it is for, what it shows"},e.createElement("textarea",{className:"field",rows:3,value:O.description??"",onChange:e=>we({description:e.target.value})})),e.createElement(w,{label:"Its start: where the app is when it plays (the app's start.go)"},e.createElement(E,{value:O.start,onChange:e=>we({start:e&&"object"==typeof e?e:void 0})})),e.createElement("span",{className:"small muted"},"Id: ",e.createElement("span",{className:"mono"},O.id)," · ",re.length," steps · ",d.languagesOf(O).join(", ")||"no narration yet")),"steps"===F&&Q&&e.createElement("div",{className:"pane"},e.createElement("div",{className:"row"},e.createElement("strong",{className:"grow"},"Cleanup"),e.createElement(k,{title:"Add an action",icon:"add",label:"Add",items:h(d,e=>{we({cleanup:[...O.cleanup??[],e]}),U((O.cleanup??[]).length)})})),e.createElement("div",{className:"small muted"},"Done after the demo - when it ends, or is stopped - quickly and unseen: filters cleared, what it opened closed, what it changed changed back. So it plays again, and the next one starts where it expects. What the app cannot undo itself, its start resets (the app's ",e.createElement("span",{className:"mono"},"start.go"),")."),(O.cleanup??[]).map((t,a)=>e.createElement(p,{key:`cleanup.${a}`,engine:d,action:t,index:a,count:(O.cleanup??[]).length,open:B===a,sentences:[],onOpen:()=>U(B===a?void 0:a),onChange:e=>we({cleanup:(O.cleanup??[]).map((t,n)=>n===a?e:t)}),onMove:e=>{const t=[...O.cleanup??[]],n=a+e;n<0||n>=t.length||([t[a],t[n]]=[t[n],t[a]],we({cleanup:t}),U(n))},onDuplicate:()=>we({cleanup:[...(O.cleanup??[]).slice(0,a+1),l(t),...(O.cleanup??[]).slice(a+1)]}),onDelete:()=>{we({cleanup:(O.cleanup??[]).filter((e,t)=>t!==a)}),U(void 0)},picking:ae}))),"steps"===F&&De&&!Q&&!_&&e.createElement(e.Fragment,null,e.createElement("div",{className:"pane"},e.createElement("div",{className:"row"},e.createElement("strong",{className:"grow"},"Step ",ce+1," of ",re.length),e.createElement(v,{icon:"up",small:!0,kind:"bare",title:"Earlier",disabled:0===ce,onClick:()=>xe(-1)}),e.createElement(v,{icon:"down",small:!0,kind:"bare",title:"Later",disabled:ce===re.length-1,onClick:()=>xe(1)}),e.createElement(v,{icon:"duplicate",small:!0,kind:"bare",title:"Duplicate",onClick:()=>{ke([...re.slice(0,ce+1),l(De),...re.slice(ce+1)]),J(ce+1)}}),e.createElement(v,{icon:"delete",small:!0,kind:"bare",title:"Delete this step",disabled:re.length<2,onClick:()=>{ke(re.filter((e,t)=>t!==ce)),J(Math.max(0,ce-1))}})),e.createElement("input",{className:"field",placeholder:"Title, for the editor and the timeline",value:De.title??"",onChange:e=>ye(x(De,"title",e.target.value||void 0))}),pe.map(t=>e.createElement(S,{key:t,engine:d,language:t,text:De.say[t]??"",onChange:e=>ye({...De,say:x(De.say,t,e||void 0)})})),e.createElement("textarea",{className:"field",rows:2,placeholder:"Notes for the presenter: on their screen only, never said or shown",value:De.notes??"",onChange:e=>ye(x(De,"notes",e.target.value||void 0))}),e.createElement("div",{className:"row",style:{flexWrap:"wrap",gap:12}},e.createElement("span",{className:"small muted"},"Hold after, ms"),e.createElement(y,{value:De.hold,width:70,placeholder:"0",onChange:e=>ye(x(De,"hold",e))}),e.createElement(f,{label:"Wait for the presenter after it",checked:Boolean(De.pause),onChange:e=>ye(x(De,"pause",e||void 0))}),e.createElement("span",{className:"small muted"},je(ce)))),e.createElement("div",{className:"pane",style:{flex:1.3}},e.createElement("div",{className:"row"},e.createElement("strong",{className:"grow"},"Actions"),e.createElement("span",{className:"small muted"},"played one after the other, while the narration speaks"),e.createElement(k,{title:"Add an action",icon:"add",label:"Add",items:h(d,e=>{ye({...De,actions:[...De.actions,e]}),U(De.actions.length)})})),0===De.actions.length&&e.createElement("div",{className:"muted small"},"None yet: add one, or record them (●) by doing them on the page."),De.actions.map((t,a)=>e.createElement(p,{key:`${ce}.${a}`,engine:d,action:t,index:a,count:De.actions.length,open:B===a,error:I.get(`${ce}.${a}`),sentences:r(o(De,ne)),onOpen:()=>U(B===a?void 0:a),onChange:e=>((e,t)=>ye({...re[ce],actions:re[ce].actions.map((a,n)=>n===e?t:a)}))(a,e),onMove:e=>((e,t)=>{const a=e+t,n=[...re[ce].actions];a<0||a>=n.length||([n[e],n[a]]=[n[a],n[e]],ye({...re[ce],actions:n}),U(a))})(a,e),onDuplicate:()=>ye({...De,actions:[...De.actions.slice(0,a+1),l(t),...De.actions.slice(a+1)]}),onDelete:()=>{ye({...De,actions:De.actions.filter((e,t)=>t!==a)}),U(void 0)},picking:ae})))),"text"===F&&e.createElement("div",{className:"pane",style:{flexDirection:"row"}},e.createElement("textarea",{className:"field mono grow",spellCheck:!1,value:V.json,onChange:e=>z({...V,json:e.target.value})}),e.createElement("textarea",{className:"field mono grow",spellCheck:!1,value:V.scenario,placeholder:"The scenario, for people (.md)",onChange:e=>z({...V,scenario:e.target.value})})),"video"===F&&e.createElement(D,{engine:d,draft:O})))}function x(e,t,a){const n={...e,[t]:a};return void 0===a&&delete n[t],n}function S({engine:t,language:a,text:n,onChange:l}){const[o,s]=i(),[c,d]=i(),[p,h]=i(),g=r(n);return e.createElement("div",{className:"col",style:{gap:4}},e.createElement("div",{className:"row"},e.createElement("span",{className:"badge accent"},a),e.createElement("span",{className:"small muted grow"},g.length," sentence",1===g.length?"":"s",c?` · ${c}`:""),e.createElement(v,{icon:p?"stop":"listen",small:!0,kind:"bare",title:p?"Stop":"Listen, in the voice chosen",disabled:!n.trim(),onClick:()=>{(async()=>{if(p)return p();let e=!1,i=()=>{};h(()=>()=>{e=!0,i()}),t.speech.wake();for(const l of r(n)){if(e)break;d("Making the voice…");const n=await t.speech.say(l,a).catch(e=>{t.say(e.message,!0)});if(d(void 0),!n)break;i=n.stop,await n.done}d(void 0),h(void 0)})()}}),e.createElement(v,{icon:o?"stop":"mic",small:!0,kind:"bare",on:Boolean(o),title:o?"Stop, and write what was said":"Dictate: speak, then stop",onClick:()=>{(async()=>{if(o){s(void 0),d("Transcribing…");try{const e=(await t.transcribe(await o.stop(),a)).map(e=>e.text).join(" ").trim();e&&l([n.trim(),e].filter(Boolean).join(" "))}catch(e){t.say(e.message,!0)}d(void 0)}else try{s(await m())}catch(e){t.say(`Microphone: ${e.message}`,!0)}})()},style:o?{color:"var(--danger)"}:void 0})),e.createElement("textarea",{className:"field",rows:3,placeholder:`Narration (${a}): what the viewer should notice, a sentence a subtitle`,value:n,onChange:e=>l(e.target.value)}))}function D({engine:n,draft:i}){const l=n.entriesNow().find(e=>e.demo.id===i.id),o=l?.video,s=a(()=>o&&{video:URL.createObjectURL(o.blob),vtt:URL.createObjectURL(new Blob([o.vtt],{type:"text/vtt"}))},[o]);if(t(()=>()=>{s&&(URL.revokeObjectURL(s.video),URL.revokeObjectURL(s.vtt))},[s]),!o||!s)return e.createElement("div",{className:"pane muted"},"Not filmed yet: film it (the film button) to make a video with narration and subtitles, kept here.");const r=o.json!==JSON.stringify({...i,scenario:void 0,savedAt:void 0})&&o.json!==JSON.stringify(i);return e.createElement("div",{className:"pane",style:{flexDirection:"row"}},e.createElement("div",{className:"grow",style:{minHeight:0,display:"flex"}},e.createElement("video",{src:s.video,controls:!0,style:{maxHeight:"100%"}},e.createElement("track",{kind:"subtitles",src:s.vtt,srcLang:o.language??"en",label:"Narration",default:!0}))),e.createElement("div",{className:"col",style:{width:240}},e.createElement("span",{className:"small muted"},new Date(o.at).toLocaleString()," · ",Math.round(o.blob.size/1e5)/10," MB · ",o.blob.type.split(";")[0]),r&&e.createElement("span",{className:"small error"},"Filmed from an older version of the demo."),e.createElement(v,{icon:"download",onClick:()=>n.downloadVideo(o,i.title)},"Video"),e.createElement(v,{icon:"subtitles",onClick:()=>n.downloadVideo(o,i.title,"vtt")},"Subtitles .vtt"),e.createElement(v,{icon:"subtitles",onClick:()=>n.downloadVideo(o,i.title,"srt")},"Subtitles .srt"),e.createElement(v,{icon:"share",onClick:()=>{n.shareVideo(o,i.title).then(e=>!e&&n.say("No share sheet here: download it instead."))}},"Share…"),o.voice&&e.createElement(v,{icon:"download",onClick:()=>n.downloadVideo({...o,blob:o.voice},`${i.title} voice`)},"The presenter's voice"),e.createElement(v,{icon:"delete",kind:"danger",onClick:()=>{n.store.deleteVideo(o.id)}},"Delete the video"),e.createElement("span",{className:"small muted"},d(i.title,o.blob.type.includes("mp4")?"mp4":"webm"))))}
|
|
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,JsonField as E,Labelled as w,Menu as k,NumberField as y,Segmented as b}from"./Kit.js";import{Timeline as N}from"./Timeline.js";const C="protomaze-demo-engine:studio-height";export function Studio({engine:d,theme:m}){const j=u(d),$=j.studio,[O,L]=i(()=>o($.demo)),[R,T]=i(()=>JSON.stringify($.demo)),A=n({back:[],forward:[]}),[M,J]=i(0),[B,U]=i(),[F,P]=i("steps"),[V,z]=i({json:"",scenario:""}),[W,H]=i(),[I,K]=i(new Map),[q,Y]=i(()=>Number(localStorage.getItem(C))||Math.round(.46*innerHeight)),[G,Z]=i(!1),[Q,X]=i(!1),[_,ee]=i(!1),[te,ae]=i(!1),[ne,ie]=i(()=>d.language()),oe=j.session,le="idle"!==oe.mode,se="playing"!==oe.mode||oe.checking?void 0:oe,re=O.steps,ce=Math.min(M,Math.max(0,re.length-1)),de=se&&se.demo.id===O.id?se.step:ce,me=JSON.stringify(O)!==R,pe=a(()=>Array.from(new Set([...d.languages(),...d.languagesOf(O)])),[O]),he=d.entriesNow().find(e=>e.demo.id===O.id),ge=d.timing(O,ne),ue=j.lastRun?.json===JSON.stringify(O)&&j.lastRun.language===ne,ve=(e,t=!0)=>{t&&(A.current.back.push(O),A.current.back.length>200&&A.current.back.shift(),A.current.forward=[]),L(e)},fe=()=>{const e=A.current.back.pop();e&&(A.current.forward.push(O),L(e))},Ee=()=>{const e=A.current.forward.pop();e&&(A.current.back.push(O),L(e))},we=e=>ve({...O,...e}),ke=e=>we({steps:e}),ye=e=>ke(re.map((t,a)=>a===ce?e:t));t(()=>{$.recorded&&ve({...O,steps:$.recorded.steps})},[$.recorded?.at]);const be=()=>{const{demo:e,problems:t}=d.parse(V.json);if(e)return H(void 0),{...e,scenario:V.scenario};H(t.slice(0,4).map(e=>`${e.path||"demo"}: ${e.message}`).join(" · "))},Ne=async()=>{const e="text"===F?be():O;if(e)try{await d.save(e),L(e),T(JSON.stringify(e)),d.say(`Saved "${e.title}".`)}catch(e){d.say(e.message,!0)}},Ce=e=>{d.play(O,{from:e,language:ne})},xe=e=>{const t=ce+e;if(t<0||t>=re.length)return;const a=[...re];[a[ce],a[t]]=[a[t],a[ce]],ke(a),J(t)},Se=G||te||"recording"===oe.mode||Boolean(se),De=re[ce],je=e=>{const t=ge.steps.find(t=>t.step===e);return t?`${((t.end-t.start)/1e3).toFixed(1)} s`:""};return e.createElement("div",{className:"pde studio"+(Se?" collapsed":""),"data-theme":m,"data-demo-ignore":!0,onKeyDown:e=>{if(!(e.ctrlKey||e.metaKey))return;const t=e.key.toLowerCase();"s"===t?(e.preventDefault(),Ne()):"z"!==t||e.shiftKey||"text"===F?("y"===t||"z"===t&&e.shiftKey)&&"text"!==F&&(e.preventDefault(),Ee()):(e.preventDefault(),fe())},style:{height:Se?void 0:q,display:te?"none":void 0}},e.createElement("div",{className:"grip",onPointerDown:e=>{const t=e.clientY,a=q,n=e=>Y(Math.max(180,Math.min(innerHeight-40,a+t-e.clientY))),i=()=>{window.removeEventListener("pointermove",n),window.removeEventListener("pointerup",i),Y(e=>(localStorage.setItem(C,String(e)),e))};window.addEventListener("pointermove",n),window.addEventListener("pointerup",i)}}),e.createElement("div",{className:"head"},e.createElement("input",{className:"field title",value:O.title,title:"Title",onChange:e=>we({title:e.target.value})}),e.createElement("div",{className:"sep"}),!se&&e.createElement(e.Fragment,null,e.createElement(v,{icon:"play",kind:"primary",disabled:le,title:`Play from step ${ce+1}`,onClick:()=>Ce(ce)},"Play"),e.createElement(k,{title:"Play from the start, present, guide, loop",icon:"expand",align:"left",items:[{label:"From the start",icon:"first",disabled:le,onClick:()=>Ce(0)},{label:`Present from step ${ce+1}…`,icon:"present",disabled:le,onClick:()=>d.present(O,{from:ce})},{label:`Guide from step ${ce+1}: the viewer does it`,icon:"guide",disabled:le,onClick:()=>{d.guide(O,{from:ce,language:ne})}},{label:"Loop at a booth…",icon:"loop",disabled:le,onClick:()=>d.openDialog({kind:"loop",demos:[O]})},...pe.length>1?[{heading:"Narration in"},...pe.map(e=>({label:`${e===ne?"● ":""}${e}`,onClick:()=>ie(e)}))]:[]]}),e.createElement(v,{icon:"record",title:`Record new steps after step ${ce+1}…`,disabled:le,onClick:()=>d.openDialog({kind:"record",into:O,after:ce}),style:{color:"var(--danger)"}}),e.createElement(v,{icon:"film",title:"Film a video…",disabled:le,onClick:()=>d.openDialog({kind:"film",demo:O})}),e.createElement(v,{icon:"check",title:"Check: plays it fast and silent, and marks what fails",disabled:le,onClick:()=>{(async()=>{const e=await d.check(O);K(new Map(e.failures.map(e=>[`${e.step}.${e.index}`,e.error]))),e.ok?d.say(`Every step plays: ${c(e.duration)} at speed.`):d.say(e.failures.length?`${e.failures.length} action${1===e.failures.length?"":"s"} failed: in red.`:e.error??"Failed",!0);const t=e.failures[0];t&&(J(t.step),U(t.index))})()}}),!1!==d.options.assistant&&e.createElement(v,{icon:"spark",title:"Ask Claude to change this demo, in words",onClick:()=>d.openAssistant(O)})),se&&e.createElement(e.Fragment,null,e.createElement(v,{icon:se.paused?"play":"pause",kind:"primary",onClick:()=>se.waiting?d.next():d.togglePause()},se.waiting?"Continue":se.paused?"Resume":"Pause"),e.createElement(v,{icon:"back",title:"Back (←)",onClick:()=>d.back()}),e.createElement(v,{icon:"right",title:"Next step (→)",onClick:()=>d.next()}),e.createElement(v,{icon:"stop",title:"Stop (Esc)",onClick:()=>d.stop()})),e.createElement("span",{className:"grow"}),e.createElement(v,{icon:"undo",kind:"bare",title:"Undo (Ctrl+Z)",disabled:0===A.current.back.length,onClick:fe}),e.createElement(v,{icon:"redo",kind:"bare",title:"Redo (Ctrl+Y)",disabled:0===A.current.forward.length,onClick:Ee}),e.createElement(v,{icon:"save",kind:me?"primary":void 0,title:"Save here (Ctrl+S)",onClick:()=>{Ne()}},me?"Save":"Saved"),e.createElement(k,{title:"Share, export",icon:"share",items:[{label:"Copy a link with the demo",icon:"link",onClick:()=>{d.link(O).then(e=>navigator.clipboard.writeText(e)).then(()=>d.say("Link copied: it opens the app with this demo."))}},{label:"Download .demo.json",icon:"download",onClick:()=>d.downloadDemo(O)},{label:"Download scenario .md",icon:"download",onClick:()=>d.downloadDemo(O,"md")},{label:"Copy JSON",icon:"copy",onClick:()=>{navigator.clipboard.writeText(JSON.stringify({...O,scenario:void 0,savedAt:void 0},null,2)).then(()=>d.say("JSON copied."))}},{label:"Narration pack (.zip): no key, no download, for every viewer",icon:"listen",onClick:()=>{d.downloadPack(O)}},he?.video&&{label:"Download the video",icon:"film",onClick:()=>d.downloadVideo(he.video,O.title)},("edited"===he?.origin||"here"===he?.origin)&&{heading:"This demo"},"edited"===he?.origin&&{label:"Revert to the app’s version",icon:"undo",onClick:()=>{window.confirm("Drop the changes kept here?")&&d.remove(O.id)}},"here"===he?.origin&&{label:"Delete",icon:"delete",onClick:()=>{window.confirm(`Delete "${O.title}"?`)&&d.remove(O.id)}}]}),e.createElement(b,{value:F,onChange:e=>{if(e!==F){if("text"===F){const e=be();if(!e)return;JSON.stringify(e)!==JSON.stringify(O)&&ve(e)}"text"===e&&(()=>{const{scenario:e,savedAt:t,...a}=O;z({json:JSON.stringify(a,null,2),scenario:O.scenario??s(O,ne)}),H(void 0)})(),P(e)}},options:[["steps","Steps"],["text","Text"],["video","Video",he?.video?"Its last video":"Not filmed yet"]]}),e.createElement(v,{icon:G?"maximize":"minimize",kind:"bare",title:G?"Unfold":"Fold",onClick:()=>Z(!G)}),e.createElement(v,{icon:"close",kind:"bare",title:"Close",onClick:()=>{me&&!window.confirm("Close without saving?")||d.closeStudio()}})),e.createElement(N,{demo:O,timing:ge,measured:ue,step:de,action:B,theme:m,accent:"#ffb300",playhead:se&&se.demo.id===O.id?()=>d.elapsed():void 0,read:e=>g(d,e),onPick:(e,t)=>{se&&se.demo.id===O.id&&d.goTo(e)||(J(e),U(t),G&&Z(!1))}}),W&&e.createElement("div",{className:"error small",style:{padding:"4px 12px"}},W),e.createElement("div",{className:"body"},"text"!==F&&e.createElement("div",{className:"steps"},e.createElement("div",{className:["step",_&&"on"].filter(Boolean).join(" "),style:{marginBottom:4},onClick:()=>{ee(!0),X(!1),U(void 0)},title:"Its title, who it is for, where it starts"},e.createElement("span",{className:"n"},"i"),e.createElement("div",{className:"col grow",style:{gap:2}},e.createElement("span",{style:{fontWeight:500}},"About this demo"),e.createElement("span",{className:"say"},O.description||"Who it is for, what it shows"))),re.map((t,a)=>e.createElement("div",{key:a,className:["step",a===ce&&!Q&&!_&&"on",se&&a===de&&"playing"].filter(Boolean).join(" "),onClick:()=>{J(a),U(void 0),X(!1),ee(!1),function(e){if("video"!==F)return;const t=he?.video?.timing?.steps.find(t=>t.step===e),a=document.querySelector("protomaze-demo-engine")?.shadowRoot?.querySelector("video");t&&a&&(a.currentTime=t.start/1e3)}(a)}},e.createElement("span",{className:"n"},a+1),e.createElement("div",{className:"col grow",style:{gap:2}},e.createElement("div",{className:"row"},e.createElement("span",{className:"grow ellipsis",style:{fontWeight:500}},t.title||function(e,t){return r(l(e,t))[0]}(t,ne)||"Untitled"),e.createElement("span",{className:"small muted"},je(a))),t.title&&e.createElement("span",{className:"say"},l(t,ne)),e.createElement("span",{className:"small muted"},t.actions.length," action",1===t.actions.length?"":"s",t.pause?" · waits":"")))),e.createElement(v,{icon:"add",small:!0,onClick:()=>{ke([...re.slice(0,ce+1),{say:{},actions:[]},...re.slice(ce+1)]),J(ce+1),X(!1)}},"New step"),e.createElement("div",{className:["step",Q&&"on"].filter(Boolean).join(" "),style:{marginTop:6},onClick:()=>{X(!0),ee(!1),U(void 0)},title:"Done after the demo, quickly and unseen, so the app is as it found it"},e.createElement("span",{className:"n"},"↺"),e.createElement("div",{className:"col grow",style:{gap:2}},e.createElement("span",{style:{fontWeight:500}},"Cleanup"),e.createElement("span",{className:"small muted"},(O.cleanup??[]).length," action",1===(O.cleanup??[]).length?"":"s"," after it, unseen")))),"steps"===F&&_&&e.createElement("div",{className:"pane"},e.createElement("strong",null,"About this demo"),e.createElement(w,{label:"Title"},e.createElement("input",{className:"field",value:O.title,onChange:e=>we({title:e.target.value})})),e.createElement(w,{label:"Description: who it is for, what it shows"},e.createElement("textarea",{className:"field",rows:3,value:O.description??"",onChange:e=>we({description:e.target.value})})),e.createElement(w,{label:"Its start: where the app is when it plays (the app's start.go)"},e.createElement(E,{value:O.start,onChange:e=>we({start:e&&"object"==typeof e?e:void 0})})),e.createElement("span",{className:"small muted"},"Id: ",e.createElement("span",{className:"mono"},O.id)," · ",re.length," steps · ",d.languagesOf(O).join(", ")||"no narration yet")),"steps"===F&&Q&&e.createElement("div",{className:"pane"},e.createElement("div",{className:"row"},e.createElement("strong",{className:"grow"},"Cleanup"),e.createElement(k,{title:"Add an action",icon:"add",label:"Add",items:h(d,e=>{we({cleanup:[...O.cleanup??[],e]}),U((O.cleanup??[]).length)})})),e.createElement("div",{className:"small muted"},"Done after the demo - when it ends, or is stopped - quickly and unseen: filters cleared, what it opened closed, what it changed changed back. So it plays again, and the next one starts where it expects. What the app cannot undo itself, its start resets (the app's ",e.createElement("span",{className:"mono"},"start.go"),")."),(O.cleanup??[]).map((t,a)=>e.createElement(p,{key:`cleanup.${a}`,engine:d,action:t,index:a,count:(O.cleanup??[]).length,open:B===a,sentences:[],onOpen:()=>U(B===a?void 0:a),onChange:e=>we({cleanup:(O.cleanup??[]).map((t,n)=>n===a?e:t)}),onMove:e=>{const t=[...O.cleanup??[]],n=a+e;n<0||n>=t.length||([t[a],t[n]]=[t[n],t[a]],we({cleanup:t}),U(n))},onDuplicate:()=>we({cleanup:[...(O.cleanup??[]).slice(0,a+1),o(t),...(O.cleanup??[]).slice(a+1)]}),onDelete:()=>{we({cleanup:(O.cleanup??[]).filter((e,t)=>t!==a)}),U(void 0)},picking:ae}))),"steps"===F&&De&&!Q&&!_&&e.createElement(e.Fragment,null,e.createElement("div",{className:"pane"},e.createElement("div",{className:"row"},e.createElement("strong",{className:"grow"},"Step ",ce+1," of ",re.length),e.createElement(v,{icon:"up",small:!0,kind:"bare",title:"Earlier",disabled:0===ce,onClick:()=>xe(-1)}),e.createElement(v,{icon:"down",small:!0,kind:"bare",title:"Later",disabled:ce===re.length-1,onClick:()=>xe(1)}),e.createElement(v,{icon:"duplicate",small:!0,kind:"bare",title:"Duplicate",onClick:()=>{ke([...re.slice(0,ce+1),o(De),...re.slice(ce+1)]),J(ce+1)}}),e.createElement(v,{icon:"delete",small:!0,kind:"bare",title:"Delete this step",disabled:re.length<2,onClick:()=>{ke(re.filter((e,t)=>t!==ce)),J(Math.max(0,ce-1))}})),e.createElement("input",{className:"field",placeholder:"Title, for the editor and the timeline",value:De.title??"",onChange:e=>ye(x(De,"title",e.target.value||void 0))}),pe.map(t=>e.createElement(S,{key:t,engine:d,language:t,text:De.say[t]??"",onChange:e=>ye({...De,say:x(De.say,t,e||void 0)})})),e.createElement("textarea",{className:"field",rows:2,placeholder:"Notes for the presenter: on their screen only, never said or shown",value:De.notes??"",onChange:e=>ye(x(De,"notes",e.target.value||void 0))}),e.createElement("div",{className:"row",style:{flexWrap:"wrap",gap:12}},e.createElement("span",{className:"small muted"},"Hold after, ms"),e.createElement(y,{value:De.hold,width:70,placeholder:"0",onChange:e=>ye(x(De,"hold",e))}),e.createElement(f,{label:"Wait for the presenter after it",checked:Boolean(De.pause),onChange:e=>ye(x(De,"pause",e||void 0))}),e.createElement("span",{className:"small muted"},je(ce)))),e.createElement("div",{className:"pane",style:{flex:1.3}},e.createElement("div",{className:"row"},e.createElement("strong",{className:"grow"},"Actions"),e.createElement("span",{className:"small muted"},"played one after the other, while the narration speaks"),e.createElement(k,{title:"Add an action",icon:"add",label:"Add",items:h(d,e=>{ye({...De,actions:[...De.actions,e]}),U(De.actions.length)})})),0===De.actions.length&&e.createElement("div",{className:"muted small"},"None yet: add one, or record them (●) by doing them on the page."),De.actions.map((t,a)=>e.createElement(p,{key:`${ce}.${a}`,engine:d,action:t,index:a,count:De.actions.length,open:B===a,error:I.get(`${ce}.${a}`),sentences:r(l(De,ne)),onOpen:()=>U(B===a?void 0:a),onChange:e=>((e,t)=>ye({...re[ce],actions:re[ce].actions.map((a,n)=>n===e?t:a)}))(a,e),onMove:e=>((e,t)=>{const a=e+t,n=[...re[ce].actions];a<0||a>=n.length||([n[e],n[a]]=[n[a],n[e]],ye({...re[ce],actions:n}),U(a))})(a,e),onDuplicate:()=>ye({...De,actions:[...De.actions.slice(0,a+1),o(t),...De.actions.slice(a+1)]}),onDelete:()=>{ye({...De,actions:De.actions.filter((e,t)=>t!==a)}),U(void 0)},picking:ae})))),"text"===F&&e.createElement("div",{className:"pane",style:{flexDirection:"row"}},e.createElement("textarea",{className:"field mono grow",spellCheck:!1,value:V.json,onChange:e=>z({...V,json:e.target.value})}),e.createElement("textarea",{className:"field mono grow",spellCheck:!1,value:V.scenario,placeholder:"The scenario, for people (.md)",onChange:e=>z({...V,scenario:e.target.value})})),"video"===F&&e.createElement(D,{engine:d,draft:O})))}function x(e,t,a){const n={...e,[t]:a};return void 0===a&&delete n[t],n}function S({engine:t,language:a,text:n,onChange: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 D({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"))))}
|
package/ui/Styles.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** The engine's UI: one stylesheet in its shadow roots, themed by `data-theme` on `.pde`. */
|
|
2
|
-
export declare const UI_CSS = "\n.pde { --bg: #17181c; --panel: #1f2026; --raised: #2a2c33; --line: #3a3c45; --fg: #e9eaee; --muted: #9a9caa; --accent: #ffb300;\n --accent-fg: #1a1200; --danger: #ff5a5f; --ok: #3ecf8e; --focus: #7aa7ff; --shadow: 0 10px 40px rgba(0,0,0,.45);\n font: 13px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; color: var(--fg); box-sizing: border-box; }\n.pde[data-theme=\"light\"] { --bg: #f6f6f8; --panel: #ffffff; --raised: #eef0f4; --line: #d6d8de; --fg: #1b1c20; --muted: #6a6c78;\n --accent: #e09b00; --accent-fg: #1a1200; --shadow: 0 10px 40px rgba(0,0,0,.18); }\n.pde *, .pde *::before, .pde *::after { box-sizing: border-box; }\n.pde button, .pde input, .pde textarea, .pde select { font: inherit; color: inherit; }\n.pde :focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }\n.pde ::-webkit-scrollbar { width: 10px; height: 10px; }\n.pde ::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; border: 2px solid transparent; background-clip: padding-box; }\n\n.pde .row { display: flex; align-items: center; gap: 6px; min-width: 0; }\n.pde .col { display: flex; flex-direction: column; gap: 6px; min-width: 0; }\n.pde .grow { flex: 1; min-width: 0; }\n.pde .muted { color: var(--muted); }\n.pde .small { font-size: 12px; }\n.pde .mono { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; font-size: 12px; }\n.pde .error { color: var(--danger); }\n.pde .ok { color: var(--ok); }\n.pde .ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.pde .sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 4px; }\n.pde .badge { padding: 1px 6px; border-radius: 9px; background: var(--raised); color: var(--muted); font-size: 11px; white-space: nowrap; }\n.pde .badge.accent { background: color-mix(in srgb, var(--accent) 25%, transparent); color: var(--fg); }\n\n.pde .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 6px;\n border: 1px solid var(--line); background: var(--raised); cursor: pointer; white-space: nowrap; user-select: none; }\n.pde .btn:hover:not(:disabled) { border-color: var(--muted); }\n.pde .btn:disabled { opacity: .45; cursor: default; }\n.pde .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }\n.pde .btn.danger { color: var(--danger); }\n.pde .btn.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }\n.pde .icon { width: 28px; padding: 0; }\n.pde .icon.bare { border-color: transparent; background: transparent; }\n.pde .icon.bare:hover:not(:disabled) { background: var(--raised); border-color: transparent; }\n.pde .icon.small { width: 22px; height: 22px; }\n.pde svg.i { width: 18px; height: 18px; fill: currentColor; flex: none; }\n.pde .small svg.i, .pde .icon.small svg.i { width: 15px; height: 15px; }\n\n.pde .field { height: 28px; padding: 0 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); min-width: 0; }\n.pde textarea.field { height: auto; padding: 6px 8px; resize: vertical; min-height: 54px; line-height: 1.45; }\n.pde select.field { padding-right: 4px; }\n.pde .field:hover { border-color: var(--muted); }\n.pde .field.wrong { border-color: var(--danger); }\n.pde label.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; }\n.pde label.check input { accent-color: var(--accent); margin: 0; }\n.pde .labelled { display: flex; flex-direction: column; gap: 2px; min-width: 0; }\n.pde .labelled > span { font-size: 11px; color: var(--muted); }\n\n.pde .menu { position: absolute; z-index: 10; min-width: 200px; padding: 4px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line);\n box-shadow: var(--shadow); display: flex; flex-direction: column; }\n.pde .menu .item { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 5px; cursor: pointer; border: 0; background: none; text-align: left; white-space: nowrap; }\n.pde .menu .item:hover:not(:disabled) { background: var(--raised); }\n.pde .menu .item:disabled { opacity: .45; cursor: default; }\n.pde .menu .heading { padding: 6px 10px 2px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }\n\n/* Bars over the app while playing and recording */\n.pde.bar { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 14px;\n border-radius: 999px; background: var(--panel); box-shadow: var(--shadow); pointer-events: auto; white-space: nowrap; max-width: calc(100vw - 32px); }\n.pde .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1.2s ease-in-out infinite; flex: none; }\n@keyframes blink { 50% { opacity: .35; } }\n.pde.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: min(720px, calc(100vw - 32px)); padding: 10px 12px 10px 16px;\n border-radius: 10px; background: var(--panel); box-shadow: var(--shadow); pointer-events: auto; display: flex; gap: 10px; align-items: center; }\n.pde.toast.error { border-left: 4px solid var(--danger); }\n.pde.ready { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.45); pointer-events: auto; }\n.pde.ready .box { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 28px 32px; border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); max-width: 440px; text-align: center; }\n.pde.ready .btn.primary { height: 44px; padding: 0 22px; font-size: 16px; border-radius: 22px; }\n\n/* The launcher and floating library */\n.pde.launcher { position: fixed; left: 16px; bottom: 16px; pointer-events: auto; }\n.pde.launcher > .btn { height: 36px; border-radius: 18px; padding: 0 14px; box-shadow: var(--shadow); }\n.pde.floating { position: fixed; left: 16px; bottom: 60px; width: min(440px, calc(100vw - 32px)); max-height: min(72vh, 760px); overflow: auto;\n border-radius: 12px; background: var(--panel); box-shadow: var(--shadow); pointer-events: auto; border: 1px solid var(--line); }\n\n/* Dialogs: what starting something asks */\n.pde.dialog-backdrop { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.45); pointer-events: auto; padding: 16px; }\n.pde .dialog { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; display: flex; flex-direction: column; gap: 16px; padding: 18px 20px;\n border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); border: 1px solid var(--line); }\n.pde h2 { margin: 0; font-size: 16px; font-weight: 600; }\n.pde .choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 8px; }\n.pde .choice { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 10px; border-radius: 10px; border: 1px solid var(--line);\n background: var(--bg); cursor: pointer; text-align: left; }\n.pde .choice.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }\n.pde .qr { width: 180px; height: 180px; flex: none; border-radius: 8px; overflow: hidden; background: #fff; display: flex; align-items: center; justify-content: center; }\n.pde .qr svg { width: 100%; height: 100%; }\n.pde .dialog.wide { width: min(960px, 100%); }\n.pde .demo .video-line { border-top: 1px solid var(--line); padding-top: 6px; margin-top: 2px; gap: 6px; }\n.pde .look svg.i { width: 15px; height: 15px; opacity: .8; }\n\n/* The library */\n.pde.library { display: flex; flex-direction: column; gap: 10px; padding: 12px; background: var(--panel); }\n.pde .section { display: flex; flex-direction: column; gap: 8px; }\n.pde .section > h3 { margin: 0; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }\n.pde .demo { display: flex; flex-direction: column; gap: 4px; padding: 8px 10px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); position: relative; }\n.pde .demo .title { font-weight: 600; }\n.pde .segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; flex-wrap: wrap; }\n.pde .segmented button { border: 0; border-right: 1px solid var(--line); background: var(--bg); padding: 4px 10px; cursor: pointer; display: inline-flex; gap: 5px; align-items: center; }\n.pde .segmented button:last-child { border-right: 0; }\n.pde .segmented button.on { background: var(--raised); box-shadow: inset 0 -2px 0 var(--accent); }\n.pde .progress { height: 4px; border-radius: 2px; background: var(--raised); overflow: hidden; }\n.pde .progress > div { height: 100%; background: var(--accent); transition: width 200ms; }\n\n/* The studio */\n.pde.studio { position: fixed; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; background: var(--panel); pointer-events: auto;\n box-shadow: 0 -8px 30px rgba(0,0,0,.35); border-top: 1px solid var(--line); }\n.pde.studio .grip { position: absolute; top: -4px; left: 0; right: 0; height: 8px; cursor: ns-resize; }\n.pde.studio .head { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }\n.pde.studio .head .field.title { width: min(320px, 30vw); font-weight: 600; }\n.pde.studio .timeline { position: relative; height: 150px; flex: none; border-bottom: 1px solid var(--line); background: var(--bg); }\n.pde.studio .timeline .lanes { position: absolute; left: 0; top: 0; bottom: 0; width: 104px; font-size: 11px; color: var(--muted); pointer-events: none; z-index: 2; }\n.pde.studio .timeline .lanes > div { position: absolute; right: 10px; }\n.pde.studio .timeline .slider { position: absolute; left: 104px; right: 0; top: 0; bottom: 0; }\n.pde.studio .timeline .clock { position: absolute; left: 6px; bottom: 5px; z-index: 3; font: 600 10px ui-monospace, monospace; white-space: nowrap; }\n.pde.studio .body { display: flex; flex: 1; min-height: 0; }\n.pde.studio .steps { width: 260px; flex: none; overflow: auto; border-right: 1px solid var(--line); padding: 6px; display: flex; flex-direction: column; gap: 4px; }\n.pde.studio .step { display: flex; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; align-items: flex-start; }\n.pde.studio .step:hover { background: var(--raised); }\n.pde.studio .step.on { background: var(--raised); border-color: var(--accent); }\n.pde.studio .step.playing { box-shadow: inset 3px 0 0 var(--ok); }\n.pde.studio .step .n { font: 600 12px ui-monospace, monospace; color: var(--muted); width: 20px; flex: none; padding-top: 1px; }\n.pde.studio .step .say { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--muted); font-size: 12px; }\n.pde.studio .pane { flex: 1; min-width: 0; overflow: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; }\n.pde.studio .pane + .pane { border-left: 1px solid var(--line); }\n.pde.studio .action { border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }\n.pde.studio .action.on { border-color: var(--accent); }\n.pde.studio .action.failed { border-color: var(--danger); }\n.pde.studio .action > .row { padding: 4px 6px; }\n.pde.studio .action .kind { font: 600 11px ui-monospace, monospace; padding: 2px 6px; border-radius: 4px; background: var(--raised); flex: none; }\n.pde.studio .action .kind.present { background: color-mix(in srgb, var(--accent) 22%, transparent); }\n.pde.studio .action .details { padding: 8px 10px 10px; border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }\n.pde.studio .action .details .wide { grid-column: 1 / -1; }\n.pde.studio .collapsed .body, .pde.studio .collapsed .grip { display: none; }\n.pde.studio video { width: 100%; max-height: 100%; background: #000; border-radius: 6px; }\n";
|
|
2
|
+
export declare const UI_CSS = "\n.pde { --bg: #17181c; --panel: #1f2026; --raised: #2a2c33; --line: #3a3c45; --fg: #e9eaee; --muted: #9a9caa; --accent: #ffb300;\n --accent-fg: #1a1200; --danger: #ff5a5f; --ok: #3ecf8e; --focus: #7aa7ff; --shadow: 0 10px 40px rgba(0,0,0,.45);\n font: 13px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; color: var(--fg); box-sizing: border-box; }\n.pde[data-theme=\"light\"] { --bg: #f6f6f8; --panel: #ffffff; --raised: #eef0f4; --line: #d6d8de; --fg: #1b1c20; --muted: #6a6c78;\n --accent: #e09b00; --accent-fg: #1a1200; --shadow: 0 10px 40px rgba(0,0,0,.18); }\n.pde *, .pde *::before, .pde *::after { box-sizing: border-box; }\n.pde button, .pde input, .pde textarea, .pde select { font: inherit; color: inherit; }\n.pde :focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }\n.pde ::-webkit-scrollbar { width: 10px; height: 10px; }\n.pde ::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; border: 2px solid transparent; background-clip: padding-box; }\n\n.pde .row { display: flex; align-items: center; gap: 6px; min-width: 0; }\n.pde .col { display: flex; flex-direction: column; gap: 6px; min-width: 0; }\n.pde .grow { flex: 1; min-width: 0; }\n.pde .muted { color: var(--muted); }\n.pde .small { font-size: 12px; }\n.pde .mono { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; font-size: 12px; }\n.pde .error { color: var(--danger); }\n.pde .ok { color: var(--ok); }\n.pde .ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.pde .sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 4px; }\n.pde .badge { padding: 1px 6px; border-radius: 9px; background: var(--raised); color: var(--muted); font-size: 11px; white-space: nowrap; }\n.pde .badge.accent { background: color-mix(in srgb, var(--accent) 25%, transparent); color: var(--fg); }\n\n.pde .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 6px;\n border: 1px solid var(--line); background: var(--raised); cursor: pointer; white-space: nowrap; user-select: none; }\n.pde .btn:hover:not(:disabled) { border-color: var(--muted); }\n.pde .btn:disabled { opacity: .45; cursor: default; }\n.pde .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }\n.pde .btn.danger { color: var(--danger); }\n.pde .btn.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }\n.pde .icon { width: 28px; padding: 0; }\n.pde .icon.bare { border-color: transparent; background: transparent; }\n.pde .icon.bare:hover:not(:disabled) { background: var(--raised); border-color: transparent; }\n.pde .icon.small { width: 22px; height: 22px; }\n.pde svg.i { width: 18px; height: 18px; fill: currentColor; flex: none; }\n.pde .small svg.i, .pde .icon.small svg.i { width: 15px; height: 15px; }\n\n.pde .field { height: 28px; padding: 0 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); min-width: 0; }\n.pde textarea.field { height: auto; padding: 6px 8px; resize: vertical; min-height: 54px; line-height: 1.45; }\n.pde select.field { padding-right: 4px; }\n.pde .field:hover { border-color: var(--muted); }\n.pde .field.wrong { border-color: var(--danger); }\n.pde label.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; }\n.pde label.check input { accent-color: var(--accent); margin: 0; }\n.pde .labelled { display: flex; flex-direction: column; gap: 2px; min-width: 0; }\n.pde .labelled > span { font-size: 11px; color: var(--muted); }\n\n.pde .menu { position: absolute; z-index: 10; min-width: 200px; padding: 4px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line);\n box-shadow: var(--shadow); display: flex; flex-direction: column; }\n.pde .menu .item { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 5px; cursor: pointer; border: 0; background: none; text-align: left; white-space: nowrap; }\n.pde .menu .item:hover:not(:disabled) { background: var(--raised); }\n.pde .menu .item:disabled { opacity: .45; cursor: default; }\n.pde .menu .heading { padding: 6px 10px 2px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }\n\n/* Bars over the app while playing and recording */\n.pde.bar { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 14px;\n border-radius: 999px; background: var(--panel); box-shadow: var(--shadow); pointer-events: auto; white-space: nowrap; max-width: calc(100vw - 32px); }\n.pde .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1.2s ease-in-out infinite; flex: none; }\n@keyframes blink { 50% { opacity: .35; } }\n.pde.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: min(720px, calc(100vw - 32px)); padding: 10px 12px 10px 16px;\n border-radius: 10px; background: var(--panel); box-shadow: var(--shadow); pointer-events: auto; display: flex; gap: 10px; align-items: center; }\n.pde.toast.error { border-left: 4px solid var(--danger); }\n.pde.ready { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.45); pointer-events: auto; }\n.pde.ready .box { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 28px 32px; border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); max-width: 440px; text-align: center; }\n.pde.ready .btn.primary { height: 44px; padding: 0 22px; font-size: 16px; border-radius: 22px; }\n\n/* The launcher and floating library */\n.pde.launcher { position: fixed; left: 16px; bottom: 16px; pointer-events: auto; }\n.pde.launcher > .btn { height: 36px; border-radius: 18px; padding: 0 14px; box-shadow: var(--shadow); }\n.pde.floating { position: fixed; left: 16px; bottom: 60px; width: min(440px, calc(100vw - 32px)); max-height: min(72vh, 760px); overflow: auto;\n border-radius: 12px; background: var(--panel); box-shadow: var(--shadow); pointer-events: auto; border: 1px solid var(--line); }\n\n/* Dialogs: what starting something asks */\n.pde.dialog-backdrop { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.45); pointer-events: auto; padding: 16px; }\n.pde .dialog { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; display: flex; flex-direction: column; gap: 16px; padding: 18px 20px;\n border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); border: 1px solid var(--line); }\n.pde h2 { margin: 0; font-size: 16px; font-weight: 600; }\n.pde .choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 8px; }\n.pde .choice { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 10px; border-radius: 10px; border: 1px solid var(--line);\n background: var(--bg); cursor: pointer; text-align: left; }\n.pde .choice.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }\n.pde .qr { width: 180px; height: 180px; flex: none; border-radius: 8px; overflow: hidden; background: #fff; display: flex; align-items: center; justify-content: center; }\n.pde .qr svg { width: 100%; height: 100%; }\n.pde .dialog.wide { width: min(960px, 100%); }\n.pde .demo .video-line { border-top: 1px solid var(--line); padding-top: 6px; margin-top: 2px; gap: 6px; }\n.pde .look svg.i { width: 15px; height: 15px; opacity: .8; }\n\n/* The library */\n.pde.library { display: flex; flex-direction: column; gap: 10px; padding: 12px; background: var(--panel); }\n.pde .section { display: flex; flex-direction: column; gap: 8px; }\n.pde .section > h3 { margin: 0; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }\n.pde .demo { display: flex; flex-direction: column; gap: 4px; padding: 8px 10px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); position: relative; }\n.pde .demo .title { font-weight: 600; }\n.pde .segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; flex-wrap: wrap; }\n.pde .segmented button { border: 0; border-right: 1px solid var(--line); background: var(--bg); padding: 4px 10px; cursor: pointer; display: inline-flex; gap: 5px; align-items: center; }\n.pde .segmented button:last-child { border-right: 0; }\n.pde .segmented button.on { background: var(--raised); box-shadow: inset 0 -2px 0 var(--accent); }\n.pde .progress { height: 4px; border-radius: 2px; background: var(--raised); overflow: hidden; }\n.pde .progress > div { height: 100%; background: var(--accent); transition: width 200ms; }\n\n/* Ask Claude: top right, over the app; above the studio when it is open */\n.pde.assistant { position: fixed; top: 16px; right: 16px; width: min(400px, calc(100vw - 32px)); max-height: calc(100vh - 32px); display: flex; flex-direction: column; gap: 8px;\n padding: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); pointer-events: auto; }\n.pde.assistant.over-studio { max-height: 48vh; }\n.pde.assistant h2 { font-size: 14px; margin: 0; }\n.pde.assistant .entries { flex: 1; min-height: 40px; overflow: auto; display: flex; flex-direction: column; gap: 6px; padding-right: 2px; }\n.pde.assistant .you { align-self: flex-end; max-width: 88%; padding: 6px 10px; border-radius: 10px 10px 2px 10px; background: var(--raised); white-space: pre-wrap; }\n.pde.assistant .claude { white-space: pre-wrap; line-height: 1.45; }\n.pde.assistant .did { display: flex; gap: 6px; align-items: baseline; font-size: 12px; color: var(--muted); }\n.pde.assistant .did > span:first-child { color: var(--ok); flex: none; }\n.pde.assistant .did.failed > span:first-child { color: var(--danger); }\n.pde.assistant .working { display: flex; align-items: center; gap: 6px; }\n.pde.assistant .working .dot { background: var(--accent); width: 8px; height: 8px; }\n.pde.assistant .suggest { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }\n.pde.assistant .suggest .btn { text-align: left; height: auto; padding: 3px 6px; color: var(--accent); }\n.pde.assistant .about { display: flex; align-items: center; gap: 6px; padding: 2px 4px 2px 8px; border-radius: 6px; background: var(--raised); }\n.pde.assistant .ask { display: flex; gap: 6px; align-items: flex-end; }\n.pde.assistant .ask textarea { flex: 1; resize: none; min-height: 44px; }\n\n/* The studio */\n.pde.studio { position: fixed; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; background: var(--panel); pointer-events: auto;\n box-shadow: 0 -8px 30px rgba(0,0,0,.35); border-top: 1px solid var(--line); }\n.pde.studio .grip { position: absolute; top: -4px; left: 0; right: 0; height: 8px; cursor: ns-resize; }\n.pde.studio .head { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }\n.pde.studio .head .field.title { width: min(320px, 30vw); font-weight: 600; }\n.pde.studio .timeline { position: relative; height: 150px; flex: none; border-bottom: 1px solid var(--line); background: var(--bg); }\n.pde.studio .timeline .lanes { position: absolute; left: 0; top: 0; bottom: 0; width: 104px; font-size: 11px; color: var(--muted); pointer-events: none; z-index: 2; }\n.pde.studio .timeline .lanes > div { position: absolute; right: 10px; }\n.pde.studio .timeline .slider { position: absolute; left: 104px; right: 0; top: 0; bottom: 0; }\n.pde.studio .timeline .clock { position: absolute; left: 6px; bottom: 5px; z-index: 3; font: 600 10px ui-monospace, monospace; white-space: nowrap; }\n.pde.studio .body { display: flex; flex: 1; min-height: 0; }\n.pde.studio .steps { width: 260px; flex: none; overflow: auto; border-right: 1px solid var(--line); padding: 6px; display: flex; flex-direction: column; gap: 4px; }\n.pde.studio .step { display: flex; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; align-items: flex-start; }\n.pde.studio .step:hover { background: var(--raised); }\n.pde.studio .step.on { background: var(--raised); border-color: var(--accent); }\n.pde.studio .step.playing { box-shadow: inset 3px 0 0 var(--ok); }\n.pde.studio .step .n { font: 600 12px ui-monospace, monospace; color: var(--muted); width: 20px; flex: none; padding-top: 1px; }\n.pde.studio .step .say { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--muted); font-size: 12px; }\n.pde.studio .pane { flex: 1; min-width: 0; overflow: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; }\n.pde.studio .pane + .pane { border-left: 1px solid var(--line); }\n.pde.studio .action { border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }\n.pde.studio .action.on { border-color: var(--accent); }\n.pde.studio .action.failed { border-color: var(--danger); }\n.pde.studio .action > .row { padding: 4px 6px; }\n.pde.studio .action .kind { font: 600 11px ui-monospace, monospace; padding: 2px 6px; border-radius: 4px; background: var(--raised); flex: none; }\n.pde.studio .action .kind.present { background: color-mix(in srgb, var(--accent) 22%, transparent); }\n.pde.studio .action .details { padding: 8px 10px 10px; border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }\n.pde.studio .action .details .wide { grid-column: 1 / -1; }\n.pde.studio .collapsed .body, .pde.studio .collapsed .grip { display: none; }\n.pde.studio video { width: 100%; max-height: 100%; background: #000; border-radius: 6px; }\n";
|
package/ui/Styles.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const UI_CSS="\n.pde { --bg: #17181c; --panel: #1f2026; --raised: #2a2c33; --line: #3a3c45; --fg: #e9eaee; --muted: #9a9caa; --accent: #ffb300;\n --accent-fg: #1a1200; --danger: #ff5a5f; --ok: #3ecf8e; --focus: #7aa7ff; --shadow: 0 10px 40px rgba(0,0,0,.45);\n font: 13px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; color: var(--fg); box-sizing: border-box; }\n.pde[data-theme=\"light\"] { --bg: #f6f6f8; --panel: #ffffff; --raised: #eef0f4; --line: #d6d8de; --fg: #1b1c20; --muted: #6a6c78;\n --accent: #e09b00; --accent-fg: #1a1200; --shadow: 0 10px 40px rgba(0,0,0,.18); }\n.pde *, .pde *::before, .pde *::after { box-sizing: border-box; }\n.pde button, .pde input, .pde textarea, .pde select { font: inherit; color: inherit; }\n.pde :focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }\n.pde ::-webkit-scrollbar { width: 10px; height: 10px; }\n.pde ::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; border: 2px solid transparent; background-clip: padding-box; }\n\n.pde .row { display: flex; align-items: center; gap: 6px; min-width: 0; }\n.pde .col { display: flex; flex-direction: column; gap: 6px; min-width: 0; }\n.pde .grow { flex: 1; min-width: 0; }\n.pde .muted { color: var(--muted); }\n.pde .small { font-size: 12px; }\n.pde .mono { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; font-size: 12px; }\n.pde .error { color: var(--danger); }\n.pde .ok { color: var(--ok); }\n.pde .ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.pde .sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 4px; }\n.pde .badge { padding: 1px 6px; border-radius: 9px; background: var(--raised); color: var(--muted); font-size: 11px; white-space: nowrap; }\n.pde .badge.accent { background: color-mix(in srgb, var(--accent) 25%, transparent); color: var(--fg); }\n\n.pde .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 6px;\n border: 1px solid var(--line); background: var(--raised); cursor: pointer; white-space: nowrap; user-select: none; }\n.pde .btn:hover:not(:disabled) { border-color: var(--muted); }\n.pde .btn:disabled { opacity: .45; cursor: default; }\n.pde .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }\n.pde .btn.danger { color: var(--danger); }\n.pde .btn.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }\n.pde .icon { width: 28px; padding: 0; }\n.pde .icon.bare { border-color: transparent; background: transparent; }\n.pde .icon.bare:hover:not(:disabled) { background: var(--raised); border-color: transparent; }\n.pde .icon.small { width: 22px; height: 22px; }\n.pde svg.i { width: 18px; height: 18px; fill: currentColor; flex: none; }\n.pde .small svg.i, .pde .icon.small svg.i { width: 15px; height: 15px; }\n\n.pde .field { height: 28px; padding: 0 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); min-width: 0; }\n.pde textarea.field { height: auto; padding: 6px 8px; resize: vertical; min-height: 54px; line-height: 1.45; }\n.pde select.field { padding-right: 4px; }\n.pde .field:hover { border-color: var(--muted); }\n.pde .field.wrong { border-color: var(--danger); }\n.pde label.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; }\n.pde label.check input { accent-color: var(--accent); margin: 0; }\n.pde .labelled { display: flex; flex-direction: column; gap: 2px; min-width: 0; }\n.pde .labelled > span { font-size: 11px; color: var(--muted); }\n\n.pde .menu { position: absolute; z-index: 10; min-width: 200px; padding: 4px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line);\n box-shadow: var(--shadow); display: flex; flex-direction: column; }\n.pde .menu .item { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 5px; cursor: pointer; border: 0; background: none; text-align: left; white-space: nowrap; }\n.pde .menu .item:hover:not(:disabled) { background: var(--raised); }\n.pde .menu .item:disabled { opacity: .45; cursor: default; }\n.pde .menu .heading { padding: 6px 10px 2px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }\n\n/* Bars over the app while playing and recording */\n.pde.bar { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 14px;\n border-radius: 999px; background: var(--panel); box-shadow: var(--shadow); pointer-events: auto; white-space: nowrap; max-width: calc(100vw - 32px); }\n.pde .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1.2s ease-in-out infinite; flex: none; }\n@keyframes blink { 50% { opacity: .35; } }\n.pde.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: min(720px, calc(100vw - 32px)); padding: 10px 12px 10px 16px;\n border-radius: 10px; background: var(--panel); box-shadow: var(--shadow); pointer-events: auto; display: flex; gap: 10px; align-items: center; }\n.pde.toast.error { border-left: 4px solid var(--danger); }\n.pde.ready { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.45); pointer-events: auto; }\n.pde.ready .box { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 28px 32px; border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); max-width: 440px; text-align: center; }\n.pde.ready .btn.primary { height: 44px; padding: 0 22px; font-size: 16px; border-radius: 22px; }\n\n/* The launcher and floating library */\n.pde.launcher { position: fixed; left: 16px; bottom: 16px; pointer-events: auto; }\n.pde.launcher > .btn { height: 36px; border-radius: 18px; padding: 0 14px; box-shadow: var(--shadow); }\n.pde.floating { position: fixed; left: 16px; bottom: 60px; width: min(440px, calc(100vw - 32px)); max-height: min(72vh, 760px); overflow: auto;\n border-radius: 12px; background: var(--panel); box-shadow: var(--shadow); pointer-events: auto; border: 1px solid var(--line); }\n\n/* Dialogs: what starting something asks */\n.pde.dialog-backdrop { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.45); pointer-events: auto; padding: 16px; }\n.pde .dialog { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; display: flex; flex-direction: column; gap: 16px; padding: 18px 20px;\n border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); border: 1px solid var(--line); }\n.pde h2 { margin: 0; font-size: 16px; font-weight: 600; }\n.pde .choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 8px; }\n.pde .choice { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 10px; border-radius: 10px; border: 1px solid var(--line);\n background: var(--bg); cursor: pointer; text-align: left; }\n.pde .choice.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }\n.pde .qr { width: 180px; height: 180px; flex: none; border-radius: 8px; overflow: hidden; background: #fff; display: flex; align-items: center; justify-content: center; }\n.pde .qr svg { width: 100%; height: 100%; }\n.pde .dialog.wide { width: min(960px, 100%); }\n.pde .demo .video-line { border-top: 1px solid var(--line); padding-top: 6px; margin-top: 2px; gap: 6px; }\n.pde .look svg.i { width: 15px; height: 15px; opacity: .8; }\n\n/* The library */\n.pde.library { display: flex; flex-direction: column; gap: 10px; padding: 12px; background: var(--panel); }\n.pde .section { display: flex; flex-direction: column; gap: 8px; }\n.pde .section > h3 { margin: 0; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }\n.pde .demo { display: flex; flex-direction: column; gap: 4px; padding: 8px 10px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); position: relative; }\n.pde .demo .title { font-weight: 600; }\n.pde .segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; flex-wrap: wrap; }\n.pde .segmented button { border: 0; border-right: 1px solid var(--line); background: var(--bg); padding: 4px 10px; cursor: pointer; display: inline-flex; gap: 5px; align-items: center; }\n.pde .segmented button:last-child { border-right: 0; }\n.pde .segmented button.on { background: var(--raised); box-shadow: inset 0 -2px 0 var(--accent); }\n.pde .progress { height: 4px; border-radius: 2px; background: var(--raised); overflow: hidden; }\n.pde .progress > div { height: 100%; background: var(--accent); transition: width 200ms; }\n\n/* The studio */\n.pde.studio { position: fixed; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; background: var(--panel); pointer-events: auto;\n box-shadow: 0 -8px 30px rgba(0,0,0,.35); border-top: 1px solid var(--line); }\n.pde.studio .grip { position: absolute; top: -4px; left: 0; right: 0; height: 8px; cursor: ns-resize; }\n.pde.studio .head { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }\n.pde.studio .head .field.title { width: min(320px, 30vw); font-weight: 600; }\n.pde.studio .timeline { position: relative; height: 150px; flex: none; border-bottom: 1px solid var(--line); background: var(--bg); }\n.pde.studio .timeline .lanes { position: absolute; left: 0; top: 0; bottom: 0; width: 104px; font-size: 11px; color: var(--muted); pointer-events: none; z-index: 2; }\n.pde.studio .timeline .lanes > div { position: absolute; right: 10px; }\n.pde.studio .timeline .slider { position: absolute; left: 104px; right: 0; top: 0; bottom: 0; }\n.pde.studio .timeline .clock { position: absolute; left: 6px; bottom: 5px; z-index: 3; font: 600 10px ui-monospace, monospace; white-space: nowrap; }\n.pde.studio .body { display: flex; flex: 1; min-height: 0; }\n.pde.studio .steps { width: 260px; flex: none; overflow: auto; border-right: 1px solid var(--line); padding: 6px; display: flex; flex-direction: column; gap: 4px; }\n.pde.studio .step { display: flex; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; align-items: flex-start; }\n.pde.studio .step:hover { background: var(--raised); }\n.pde.studio .step.on { background: var(--raised); border-color: var(--accent); }\n.pde.studio .step.playing { box-shadow: inset 3px 0 0 var(--ok); }\n.pde.studio .step .n { font: 600 12px ui-monospace, monospace; color: var(--muted); width: 20px; flex: none; padding-top: 1px; }\n.pde.studio .step .say { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--muted); font-size: 12px; }\n.pde.studio .pane { flex: 1; min-width: 0; overflow: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; }\n.pde.studio .pane + .pane { border-left: 1px solid var(--line); }\n.pde.studio .action { border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }\n.pde.studio .action.on { border-color: var(--accent); }\n.pde.studio .action.failed { border-color: var(--danger); }\n.pde.studio .action > .row { padding: 4px 6px; }\n.pde.studio .action .kind { font: 600 11px ui-monospace, monospace; padding: 2px 6px; border-radius: 4px; background: var(--raised); flex: none; }\n.pde.studio .action .kind.present { background: color-mix(in srgb, var(--accent) 22%, transparent); }\n.pde.studio .action .details { padding: 8px 10px 10px; border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }\n.pde.studio .action .details .wide { grid-column: 1 / -1; }\n.pde.studio .collapsed .body, .pde.studio .collapsed .grip { display: none; }\n.pde.studio video { width: 100%; max-height: 100%; background: #000; border-radius: 6px; }\n";
|
|
1
|
+
export const UI_CSS="\n.pde { --bg: #17181c; --panel: #1f2026; --raised: #2a2c33; --line: #3a3c45; --fg: #e9eaee; --muted: #9a9caa; --accent: #ffb300;\n --accent-fg: #1a1200; --danger: #ff5a5f; --ok: #3ecf8e; --focus: #7aa7ff; --shadow: 0 10px 40px rgba(0,0,0,.45);\n font: 13px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; color: var(--fg); box-sizing: border-box; }\n.pde[data-theme=\"light\"] { --bg: #f6f6f8; --panel: #ffffff; --raised: #eef0f4; --line: #d6d8de; --fg: #1b1c20; --muted: #6a6c78;\n --accent: #e09b00; --accent-fg: #1a1200; --shadow: 0 10px 40px rgba(0,0,0,.18); }\n.pde *, .pde *::before, .pde *::after { box-sizing: border-box; }\n.pde button, .pde input, .pde textarea, .pde select { font: inherit; color: inherit; }\n.pde :focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }\n.pde ::-webkit-scrollbar { width: 10px; height: 10px; }\n.pde ::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; border: 2px solid transparent; background-clip: padding-box; }\n\n.pde .row { display: flex; align-items: center; gap: 6px; min-width: 0; }\n.pde .col { display: flex; flex-direction: column; gap: 6px; min-width: 0; }\n.pde .grow { flex: 1; min-width: 0; }\n.pde .muted { color: var(--muted); }\n.pde .small { font-size: 12px; }\n.pde .mono { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; font-size: 12px; }\n.pde .error { color: var(--danger); }\n.pde .ok { color: var(--ok); }\n.pde .ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.pde .sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 4px; }\n.pde .badge { padding: 1px 6px; border-radius: 9px; background: var(--raised); color: var(--muted); font-size: 11px; white-space: nowrap; }\n.pde .badge.accent { background: color-mix(in srgb, var(--accent) 25%, transparent); color: var(--fg); }\n\n.pde .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 6px;\n border: 1px solid var(--line); background: var(--raised); cursor: pointer; white-space: nowrap; user-select: none; }\n.pde .btn:hover:not(:disabled) { border-color: var(--muted); }\n.pde .btn:disabled { opacity: .45; cursor: default; }\n.pde .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }\n.pde .btn.danger { color: var(--danger); }\n.pde .btn.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }\n.pde .icon { width: 28px; padding: 0; }\n.pde .icon.bare { border-color: transparent; background: transparent; }\n.pde .icon.bare:hover:not(:disabled) { background: var(--raised); border-color: transparent; }\n.pde .icon.small { width: 22px; height: 22px; }\n.pde svg.i { width: 18px; height: 18px; fill: currentColor; flex: none; }\n.pde .small svg.i, .pde .icon.small svg.i { width: 15px; height: 15px; }\n\n.pde .field { height: 28px; padding: 0 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); min-width: 0; }\n.pde textarea.field { height: auto; padding: 6px 8px; resize: vertical; min-height: 54px; line-height: 1.45; }\n.pde select.field { padding-right: 4px; }\n.pde .field:hover { border-color: var(--muted); }\n.pde .field.wrong { border-color: var(--danger); }\n.pde label.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; }\n.pde label.check input { accent-color: var(--accent); margin: 0; }\n.pde .labelled { display: flex; flex-direction: column; gap: 2px; min-width: 0; }\n.pde .labelled > span { font-size: 11px; color: var(--muted); }\n\n.pde .menu { position: absolute; z-index: 10; min-width: 200px; padding: 4px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line);\n box-shadow: var(--shadow); display: flex; flex-direction: column; }\n.pde .menu .item { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 5px; cursor: pointer; border: 0; background: none; text-align: left; white-space: nowrap; }\n.pde .menu .item:hover:not(:disabled) { background: var(--raised); }\n.pde .menu .item:disabled { opacity: .45; cursor: default; }\n.pde .menu .heading { padding: 6px 10px 2px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }\n\n/* Bars over the app while playing and recording */\n.pde.bar { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 14px;\n border-radius: 999px; background: var(--panel); box-shadow: var(--shadow); pointer-events: auto; white-space: nowrap; max-width: calc(100vw - 32px); }\n.pde .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1.2s ease-in-out infinite; flex: none; }\n@keyframes blink { 50% { opacity: .35; } }\n.pde.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: min(720px, calc(100vw - 32px)); padding: 10px 12px 10px 16px;\n border-radius: 10px; background: var(--panel); box-shadow: var(--shadow); pointer-events: auto; display: flex; gap: 10px; align-items: center; }\n.pde.toast.error { border-left: 4px solid var(--danger); }\n.pde.ready { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.45); pointer-events: auto; }\n.pde.ready .box { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 28px 32px; border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); max-width: 440px; text-align: center; }\n.pde.ready .btn.primary { height: 44px; padding: 0 22px; font-size: 16px; border-radius: 22px; }\n\n/* The launcher and floating library */\n.pde.launcher { position: fixed; left: 16px; bottom: 16px; pointer-events: auto; }\n.pde.launcher > .btn { height: 36px; border-radius: 18px; padding: 0 14px; box-shadow: var(--shadow); }\n.pde.floating { position: fixed; left: 16px; bottom: 60px; width: min(440px, calc(100vw - 32px)); max-height: min(72vh, 760px); overflow: auto;\n border-radius: 12px; background: var(--panel); box-shadow: var(--shadow); pointer-events: auto; border: 1px solid var(--line); }\n\n/* Dialogs: what starting something asks */\n.pde.dialog-backdrop { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.45); pointer-events: auto; padding: 16px; }\n.pde .dialog { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; display: flex; flex-direction: column; gap: 16px; padding: 18px 20px;\n border-radius: 14px; background: var(--panel); box-shadow: var(--shadow); border: 1px solid var(--line); }\n.pde h2 { margin: 0; font-size: 16px; font-weight: 600; }\n.pde .choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 8px; }\n.pde .choice { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 10px; border-radius: 10px; border: 1px solid var(--line);\n background: var(--bg); cursor: pointer; text-align: left; }\n.pde .choice.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }\n.pde .qr { width: 180px; height: 180px; flex: none; border-radius: 8px; overflow: hidden; background: #fff; display: flex; align-items: center; justify-content: center; }\n.pde .qr svg { width: 100%; height: 100%; }\n.pde .dialog.wide { width: min(960px, 100%); }\n.pde .demo .video-line { border-top: 1px solid var(--line); padding-top: 6px; margin-top: 2px; gap: 6px; }\n.pde .look svg.i { width: 15px; height: 15px; opacity: .8; }\n\n/* The library */\n.pde.library { display: flex; flex-direction: column; gap: 10px; padding: 12px; background: var(--panel); }\n.pde .section { display: flex; flex-direction: column; gap: 8px; }\n.pde .section > h3 { margin: 0; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }\n.pde .demo { display: flex; flex-direction: column; gap: 4px; padding: 8px 10px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); position: relative; }\n.pde .demo .title { font-weight: 600; }\n.pde .segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; flex-wrap: wrap; }\n.pde .segmented button { border: 0; border-right: 1px solid var(--line); background: var(--bg); padding: 4px 10px; cursor: pointer; display: inline-flex; gap: 5px; align-items: center; }\n.pde .segmented button:last-child { border-right: 0; }\n.pde .segmented button.on { background: var(--raised); box-shadow: inset 0 -2px 0 var(--accent); }\n.pde .progress { height: 4px; border-radius: 2px; background: var(--raised); overflow: hidden; }\n.pde .progress > div { height: 100%; background: var(--accent); transition: width 200ms; }\n\n/* Ask Claude: top right, over the app; above the studio when it is open */\n.pde.assistant { position: fixed; top: 16px; right: 16px; width: min(400px, calc(100vw - 32px)); max-height: calc(100vh - 32px); display: flex; flex-direction: column; gap: 8px;\n padding: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); pointer-events: auto; }\n.pde.assistant.over-studio { max-height: 48vh; }\n.pde.assistant h2 { font-size: 14px; margin: 0; }\n.pde.assistant .entries { flex: 1; min-height: 40px; overflow: auto; display: flex; flex-direction: column; gap: 6px; padding-right: 2px; }\n.pde.assistant .you { align-self: flex-end; max-width: 88%; padding: 6px 10px; border-radius: 10px 10px 2px 10px; background: var(--raised); white-space: pre-wrap; }\n.pde.assistant .claude { white-space: pre-wrap; line-height: 1.45; }\n.pde.assistant .did { display: flex; gap: 6px; align-items: baseline; font-size: 12px; color: var(--muted); }\n.pde.assistant .did > span:first-child { color: var(--ok); flex: none; }\n.pde.assistant .did.failed > span:first-child { color: var(--danger); }\n.pde.assistant .working { display: flex; align-items: center; gap: 6px; }\n.pde.assistant .working .dot { background: var(--accent); width: 8px; height: 8px; }\n.pde.assistant .suggest { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }\n.pde.assistant .suggest .btn { text-align: left; height: auto; padding: 3px 6px; color: var(--accent); }\n.pde.assistant .about { display: flex; align-items: center; gap: 6px; padding: 2px 4px 2px 8px; border-radius: 6px; background: var(--raised); }\n.pde.assistant .ask { display: flex; gap: 6px; align-items: flex-end; }\n.pde.assistant .ask textarea { flex: 1; resize: none; min-height: 44px; }\n\n/* The studio */\n.pde.studio { position: fixed; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; background: var(--panel); pointer-events: auto;\n box-shadow: 0 -8px 30px rgba(0,0,0,.35); border-top: 1px solid var(--line); }\n.pde.studio .grip { position: absolute; top: -4px; left: 0; right: 0; height: 8px; cursor: ns-resize; }\n.pde.studio .head { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }\n.pde.studio .head .field.title { width: min(320px, 30vw); font-weight: 600; }\n.pde.studio .timeline { position: relative; height: 150px; flex: none; border-bottom: 1px solid var(--line); background: var(--bg); }\n.pde.studio .timeline .lanes { position: absolute; left: 0; top: 0; bottom: 0; width: 104px; font-size: 11px; color: var(--muted); pointer-events: none; z-index: 2; }\n.pde.studio .timeline .lanes > div { position: absolute; right: 10px; }\n.pde.studio .timeline .slider { position: absolute; left: 104px; right: 0; top: 0; bottom: 0; }\n.pde.studio .timeline .clock { position: absolute; left: 6px; bottom: 5px; z-index: 3; font: 600 10px ui-monospace, monospace; white-space: nowrap; }\n.pde.studio .body { display: flex; flex: 1; min-height: 0; }\n.pde.studio .steps { width: 260px; flex: none; overflow: auto; border-right: 1px solid var(--line); padding: 6px; display: flex; flex-direction: column; gap: 4px; }\n.pde.studio .step { display: flex; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; align-items: flex-start; }\n.pde.studio .step:hover { background: var(--raised); }\n.pde.studio .step.on { background: var(--raised); border-color: var(--accent); }\n.pde.studio .step.playing { box-shadow: inset 3px 0 0 var(--ok); }\n.pde.studio .step .n { font: 600 12px ui-monospace, monospace; color: var(--muted); width: 20px; flex: none; padding-top: 1px; }\n.pde.studio .step .say { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--muted); font-size: 12px; }\n.pde.studio .pane { flex: 1; min-width: 0; overflow: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; }\n.pde.studio .pane + .pane { border-left: 1px solid var(--line); }\n.pde.studio .action { border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }\n.pde.studio .action.on { border-color: var(--accent); }\n.pde.studio .action.failed { border-color: var(--danger); }\n.pde.studio .action > .row { padding: 4px 6px; }\n.pde.studio .action .kind { font: 600 11px ui-monospace, monospace; padding: 2px 6px; border-radius: 4px; background: var(--raised); flex: none; }\n.pde.studio .action .kind.present { background: color-mix(in srgb, var(--accent) 22%, transparent); }\n.pde.studio .action .details { padding: 8px 10px 10px; border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }\n.pde.studio .action .details .wide { grid-column: 1 / -1; }\n.pde.studio .collapsed .body, .pde.studio .collapsed .grip { display: none; }\n.pde.studio video { width: 100%; max-height: 100%; background: #000; border-radius: 6px; }\n";
|