@joplo-app/core 0.2.8 → 0.2.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/dist/agent-skill.d.ts +1 -1
- package/dist/agent-skill.js +12 -2
- package/dist/catalog.d.ts +2 -0
- package/dist/catalog.js +2 -0
- package/dist/compile.js +52 -0
- package/dist/guide.js +56 -7
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/schema.d.ts +33 -0
- package/dist/schema.js +21 -0
- package/dist/validate.js +7 -1
- package/dist/voice.d.ts +30 -0
- package/dist/voice.js +79 -0
- package/package.json +2 -2
package/dist/agent-skill.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* 原则:薄技能——只放心智模型、起步顺序和最常见的坑,具体 API 指向 `npx joplo skill <主题>`(与项目安装的版本一致)。
|
|
8
8
|
*/
|
|
9
9
|
/** 心智模型:所有入口最先读到的几句话。 */
|
|
10
|
-
export declare const MENTAL_MODEL: readonly ["Joplo is a player for pre-declared scenarios, not a free-form app prototype.", "Inputs show the sample value typed by the current step (read-only); viewers cannot type their own.", "Clicking the highlighted element plays the next declared step; other clicks only show a hint.", "Results and errors come from scenario effects (set, toast, done), not from real logic or a backend.", "Options (A/B) and cases (edge cases) are compared in the local board; only the picked option is published."];
|
|
10
|
+
export declare const MENTAL_MODEL: readonly ["Joplo is a player for pre-declared scenarios, not a free-form app prototype.", "Its job is to show a product feature working through visuals and motion: the real interface operated step by step, state changing on screen, calls traced through diagrams. It is not a slide or PPT tool.", "Inputs show the sample value typed by the current step (read-only); viewers cannot type their own.", "Clicking the highlighted element plays the next declared step; other clicks only show a hint.", "Results and errors come from scenario effects (set, toast, done), not from real logic or a backend.", "Options (A/B) and cases (edge cases) are compared in the local board; only the picked option is published."];
|
|
11
11
|
/** 推荐的起步顺序(X2:先做最小的一条正常流程 + 一条错误恢复流程,在看板里确认交互模型后再扩展)。 */
|
|
12
12
|
export declare const START_ORDER: readonly ["Read npx joplo skill authoring; read cases before asking the user about edge cases; demo and components as needed.", "Plan before coding (npx joplo skill story): audience, one to three points, one line per scenario (Given → When → Then, how it opens and ends; a case's expected is its Then); show the plan to the user. A demo is a story, not a feature tour.", "With minimal code, write one happy path and one error-and-recovery scenario.", "Run npx joplo check, then npx joplo dev; confirm typing, clicks, and layers really behave as intended in the board.", "Extend to every option and every case agreed with the user; run check until 0 errors.", "Give the user the board URL and a short list of what to check, then wait for their feedback."];
|
|
13
13
|
/** 最常见的坑:一句话 + 详细主题。 */
|
package/dist/agent-skill.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
/** 心智模型:所有入口最先读到的几句话。 */
|
|
10
10
|
export const MENTAL_MODEL = [
|
|
11
11
|
'Joplo is a player for pre-declared scenarios, not a free-form app prototype.',
|
|
12
|
+
'Its job is to show a product feature working through visuals and motion: the real interface operated step by step, state changing on screen, calls traced through diagrams. It is not a slide or PPT tool.',
|
|
12
13
|
'Inputs show the sample value typed by the current step (read-only); viewers cannot type their own.',
|
|
13
14
|
'Clicking the highlighted element plays the next declared step; other clicks only show a hint.',
|
|
14
15
|
'Results and errors come from scenario effects (set, toast, done), not from real logic or a backend.',
|
|
@@ -37,7 +38,7 @@ export const PITFALLS = [
|
|
|
37
38
|
/** 中文触发词:技能 description 里的匹配文本,不是 CLI 界面文案(english-output 测试的白名单)。 */
|
|
38
39
|
const ZH_JOPLO = '功能原型、可交互演示、方案对比、给产品 / 设计 / 评审看的演示';
|
|
39
40
|
const ZH_FEEDBACK = '评审有结论了、按评审意见修改演示';
|
|
40
|
-
const JOPLO_DESCRIPTION = `Build clickable, replayable feature demos with Joplo (scripted scenarios in TSX, viewed in a local board) when the user wants a feature prototype, an interactive or clickable demo, an A/B comparison of options or edge cases, or a demo for product, design, or review (${ZH_JOPLO}), including in a repo without joplo.config.ts.`;
|
|
41
|
+
const JOPLO_DESCRIPTION = `Build clickable, replayable feature demos with Joplo (scripted scenarios in TSX, viewed in a local board) when the user wants a feature prototype, an interactive or clickable demo, an A/B comparison of options or edge cases, or a demo for product, design, or review (${ZH_JOPLO}), including in a repo without joplo.config.ts, but not for slide decks or PPT.`;
|
|
41
42
|
const FEEDBACK_DESCRIPTION = `Apply Joplo review results when reviewers have commented on or decided about a Joplo review link and the user says the review has conclusions or asks to update the demo as reviewed (${ZH_FEEDBACK}); pulls decisions with npx joplo feedback and writes them back into the source.`;
|
|
42
43
|
const list = (items) => items.map((s, i) => `${i + 1}. ${s}`);
|
|
43
44
|
function joploBody() {
|
|
@@ -46,9 +47,18 @@ function joploBody() {
|
|
|
46
47
|
'',
|
|
47
48
|
...MENTAL_MODEL,
|
|
48
49
|
'',
|
|
50
|
+
'## Show the product, not slides',
|
|
51
|
+
'Every step is an action on the product and a visible change it causes. If a step could be a bullet on a slide, rebuild it as interface, state, or a trace.',
|
|
52
|
+
'- Feature: not a card listing "enter email / teammate gets a link / joins today"; instead Ana types the email, clicks Send, the row appears as Pending, then Leo\'s layer opens the mail and lands in the space.',
|
|
53
|
+
'- Backend or architecture: not a card "App → API → Queue → Worker"; instead a Diagram where trace() lights each hop as the request moves and trace.fail() shows where it breaks, beside the UI whose status changes with it.',
|
|
54
|
+
'- Comparison: not a pros-and-cons table; instead options A and B each playing the same scenario, compared in the board.',
|
|
55
|
+
'- State or lifecycle: not a paragraph explaining statuses; instead a StateMachine whose current state moves as the user acts.',
|
|
56
|
+
'- Cards only open, close, jump in time, or switch roles; text that explains belongs in captions and explain(). Worked example: npx joplo skill story.',
|
|
57
|
+
'',
|
|
49
58
|
'## When to use',
|
|
50
59
|
'- The user wants to think a feature through before building it: a prototype, clickable demo, A/B options, edge cases, or a walkthrough for product, design, or review.',
|
|
51
60
|
'- Not for production UI code, real backends, or demos where viewers type free input.',
|
|
61
|
+
'- Not for slide decks, pitch decks, or text-and-bullet presentations: with no product behavior to show, use a slides tool instead.',
|
|
52
62
|
'',
|
|
53
63
|
'## Workflow',
|
|
54
64
|
'1. No joplo.config.ts yet: npx joplo@latest init <dir>, or npx joplo@latest init . for the current directory, then npm install there (versions are pinned). Agent and Git files (.git, .gitignore, .agents, .claude, AGENTS.md, skills-lock.json) do not count as content; other existing files need init . --keep, which only adds missing files. init skips these skills when the same version is already installed and never overwrites edited ones. In an existing Joplo project, use its installed npx joplo.',
|
|
@@ -105,7 +115,7 @@ export function agentsBlock() {
|
|
|
105
115
|
return [
|
|
106
116
|
'## Joplo',
|
|
107
117
|
'This project designs features as Joplo demos (joplo.config.ts). Read npx joplo skill first, then the relevant topics: authoring for pages/options/scenarios, story for planning a demo and writing captions, components, cases before asking about edge cases, demo for layers, shots, traces, and captions, focus for where viewers look in each step, diagram for architecture, sequence, and state diagrams.',
|
|
108
|
-
`Mental model: ${MENTAL_MODEL.slice(0,
|
|
118
|
+
`Mental model: ${MENTAL_MODEL.slice(0, 5).join(' ')}`,
|
|
109
119
|
`Start: ${START_ORDER.map((s, i) => `(${i + 1}) ${s}`).join(' ')}`,
|
|
110
120
|
'Pitfalls:',
|
|
111
121
|
...PITFALLS.slice(0, 6).map(([text, topic]) => `- ${text} (npx joplo skill ${topic}).`),
|
package/dist/catalog.d.ts
CHANGED
|
@@ -78,6 +78,8 @@ export declare function captionLength(s: string): number;
|
|
|
78
78
|
/** 说明 / explain 的建议上限(超过时 check 报 CAPTION_TOO_LONG / EXPLAIN_TOO_LONG)。 */
|
|
79
79
|
export declare const CAPTION_MAX = 24;
|
|
80
80
|
export declare const EXPLAIN_MAX = 48;
|
|
81
|
+
/** 旁白 say() 的建议上限(D74,超过时 check 报 SAY_TOO_LONG):读出来约 10 秒。 */
|
|
82
|
+
export declare const SAY_MAX = 80;
|
|
81
83
|
/**
|
|
82
84
|
* 叙事提示(D67,见 docs/research/storytelling-and-demos.md):
|
|
83
85
|
* - 封面说明(flow 的 description):D61 定为 30 字以内,超过时 DESCRIPTION_TOO_LONG;
|
package/dist/catalog.js
CHANGED
|
@@ -344,6 +344,8 @@ export function captionLength(s) {
|
|
|
344
344
|
/** 说明 / explain 的建议上限(超过时 check 报 CAPTION_TOO_LONG / EXPLAIN_TOO_LONG)。 */
|
|
345
345
|
export const CAPTION_MAX = 24;
|
|
346
346
|
export const EXPLAIN_MAX = 48;
|
|
347
|
+
/** 旁白 say() 的建议上限(D74,超过时 check 报 SAY_TOO_LONG):读出来约 10 秒。 */
|
|
348
|
+
export const SAY_MAX = 80;
|
|
347
349
|
/**
|
|
348
350
|
* 叙事提示(D67,见 docs/research/storytelling-and-demos.md):
|
|
349
351
|
* - 封面说明(flow 的 description):D61 定为 30 字以内,超过时 DESCRIPTION_TOO_LONG;
|
package/dist/compile.js
CHANGED
|
@@ -43,6 +43,8 @@ export function compile(src, mode, opts = {}) {
|
|
|
43
43
|
theme: src.config.theme ?? 'sketch',
|
|
44
44
|
// 默认焦点行为(D70):只有作者写了才进 IR(缺省 = 开启),不用这个开关的项目 IR 不变
|
|
45
45
|
...(typeof src.config.autoFocus === 'boolean' ? { autoFocus: src.config.autoFocus } : {}),
|
|
46
|
+
// 朗读配置(D74):只有作者写了才进 IR;build 用它决定带哪些音频,写进站点前由 publishPayload 去掉
|
|
47
|
+
...(voiceConfigOf(src.config.voice) ? { voiceConfig: voiceConfigOf(src.config.voice) } : {}),
|
|
46
48
|
themes: { ...(src.themes ?? {}) },
|
|
47
49
|
mode,
|
|
48
50
|
routes: {},
|
|
@@ -205,6 +207,8 @@ export function compile(src, mode, opts = {}) {
|
|
|
205
207
|
const root = toSceneNode(rootJ, 'root', ids, report, rel);
|
|
206
208
|
return { id: sceneId, optionId: ctx?.qid ?? null, route: route.path, name: `${page.title}${ctx ? ` · ${ctx.def.name}` : ''}`, viewport: page.viewport ?? 'desktop', root };
|
|
207
209
|
};
|
|
210
|
+
if (src.config.voice !== undefined && !voiceConfigOf(src.config.voice, true))
|
|
211
|
+
err('VOICE_CONFIG_INVALID', `config({ voice }) must be { profile?: string, narrator?: string, roles?: { [roleKey]: string } } with non-empty strings; got ${JSON.stringify(src.config.voice)}`, src.config.source ?? `${src.config.file}:1:1`);
|
|
208
212
|
if (src.config.autoFocus !== undefined && typeof src.config.autoFocus !== 'boolean')
|
|
209
213
|
err('AUTOFOCUS_INVALID', `config({ autoFocus }) must be true or false (default true); got ${JSON.stringify(src.config.autoFocus)}`, src.config.source ?? `${src.config.file}:1:1`);
|
|
210
214
|
// 主题(D51):config.theme 必须是内置主题或 themes/<name>.css
|
|
@@ -394,6 +398,8 @@ export function compile(src, mode, opts = {}) {
|
|
|
394
398
|
const effects = [];
|
|
395
399
|
const ruleIds = [];
|
|
396
400
|
const explains = [];
|
|
401
|
+
const says = [];
|
|
402
|
+
const narrates = [];
|
|
397
403
|
const traces = [];
|
|
398
404
|
const forks = [];
|
|
399
405
|
const marks = [];
|
|
@@ -420,6 +426,18 @@ export function compile(src, mode, opts = {}) {
|
|
|
420
426
|
effects.push({ type: 'toast', text: e.text, tone: e.tone });
|
|
421
427
|
else if (e.type === 'shot' || e.type === 'mark' || e.type === 'fork' || e.type === 'cue' || e.type === 'callout' || e.type === 'hold')
|
|
422
428
|
continue; // 镜头与焦点提示不是状态变化,下面单独归类
|
|
429
|
+
else if (e.type === 'say') {
|
|
430
|
+
if (typeof e.text === 'string' && e.text.trim())
|
|
431
|
+
says.push(e.text.trim());
|
|
432
|
+
else
|
|
433
|
+
err('SAY_EMPTY', 'say() needs the line the character speaks, for example say(\'I can make it!\'). Remove it to read the caption instead', st.source);
|
|
434
|
+
}
|
|
435
|
+
else if (e.type === 'narrate') {
|
|
436
|
+
if (typeof e.text === 'string' && e.text.trim())
|
|
437
|
+
narrates.push(e.text.trim());
|
|
438
|
+
else
|
|
439
|
+
err('NARRATE_EMPTY', 'narrate() needs the narrator\'s words, for example narrate(\'She sends Ajie the plan as a link, so he needs no app.\'). Remove it to read say() or the caption instead', st.source);
|
|
440
|
+
}
|
|
423
441
|
else if (e.type === 'explain') {
|
|
424
442
|
if (e.text.trim())
|
|
425
443
|
explains.push(e.text.trim());
|
|
@@ -587,6 +605,8 @@ export function compile(src, mode, opts = {}) {
|
|
|
587
605
|
...(cues.length ? { cues } : {}),
|
|
588
606
|
...(callouts.length ? { callouts } : {}),
|
|
589
607
|
...(holdMs !== undefined ? { hold: holdMs } : {}),
|
|
608
|
+
...(says.length ? { say: says.join(' ') } : {}),
|
|
609
|
+
...(narrates.length ? { narrate: narrates.join(' ') } : {}),
|
|
590
610
|
...(st.source ? { source: rel(st.source) } : {}),
|
|
591
611
|
};
|
|
592
612
|
});
|
|
@@ -1127,3 +1147,35 @@ function stripNotes(n) {
|
|
|
1127
1147
|
for (const c of n.children ?? [])
|
|
1128
1148
|
stripNotes(c);
|
|
1129
1149
|
}
|
|
1150
|
+
/**
|
|
1151
|
+
* config({ voice }) 规整(D74):去掉空白,空对象视为没写。strict = true 时形状不对返回 null(报 VOICE_CONFIG_INVALID)。
|
|
1152
|
+
*/
|
|
1153
|
+
function voiceConfigOf(v, strict = false) {
|
|
1154
|
+
if (v === undefined || v === null)
|
|
1155
|
+
return null;
|
|
1156
|
+
if (typeof v !== 'object' || Array.isArray(v))
|
|
1157
|
+
return null;
|
|
1158
|
+
const o = v;
|
|
1159
|
+
const str = (x) => (typeof x === 'string' && x.trim() ? x.trim() : null);
|
|
1160
|
+
for (const k of Object.keys(o))
|
|
1161
|
+
if (!['profile', 'narrator', 'roles'].includes(k))
|
|
1162
|
+
return null;
|
|
1163
|
+
if (o.profile !== undefined && !str(o.profile))
|
|
1164
|
+
return null;
|
|
1165
|
+
if (o.narrator !== undefined && !str(o.narrator))
|
|
1166
|
+
return null;
|
|
1167
|
+
let roles;
|
|
1168
|
+
if (o.roles !== undefined) {
|
|
1169
|
+
if (!o.roles || typeof o.roles !== 'object' || Array.isArray(o.roles))
|
|
1170
|
+
return null;
|
|
1171
|
+
roles = {};
|
|
1172
|
+
for (const [k, val] of Object.entries(o.roles)) {
|
|
1173
|
+
const s = str(val);
|
|
1174
|
+
if (!s)
|
|
1175
|
+
return null;
|
|
1176
|
+
roles[k] = s;
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
const out = { ...(str(o.profile) ? { profile: str(o.profile) } : {}), ...(str(o.narrator) ? { narrator: str(o.narrator) } : {}), ...(roles && Object.keys(roles).length ? { roles } : {}) };
|
|
1180
|
+
return Object.keys(out).length ? out : strict ? out : null;
|
|
1181
|
+
}
|
package/dist/guide.js
CHANGED
|
@@ -136,14 +136,39 @@ const CONTENT = {
|
|
|
136
136
|
A demo is a short story a viewer follows without you: who wants what, what gets in the way, what the product does, and the visible result.
|
|
137
137
|
It is not a feature tour. Plan it in a few lines before writing TSX, show the plan to the user, then build. Sources: docs/research/storytelling-and-demos.md.
|
|
138
138
|
|
|
139
|
-
## 1.
|
|
139
|
+
## 1. Show the product working, not slides
|
|
140
|
+
Joplo exists to demonstrate product behavior with visuals and motion. It is not a PPT tool: a demo made of text cards and bullet lists has failed, however good the text.
|
|
141
|
+
- Every step = a cause the viewer sees (a click, typing, an incoming message, a system event) + a change it makes (a new row, a status, a toast, a trace, a layer switch).
|
|
142
|
+
- Show, do not tell: a claim like 'invites are fast' becomes the invite happening on screen; 'the queue absorbs spikes' becomes trace() through the queue while the UI stays responsive.
|
|
143
|
+
- Text has a supporting role: captions narrate what is on screen, explain() says why it matters, cards only open, close, jump in time, or switch roles.
|
|
144
|
+
- Pick the visual by what you prove: UI flow → the product screens; who calls whom → Diagram + trace(); time order → Sequence; lifecycle → StateMachine; two answers → options A/B on the same scenario.
|
|
145
|
+
Slide version (wrong): the same points as cards, nothing to operate, nothing changes.
|
|
146
|
+
\`\`\`tsx
|
|
147
|
+
flow('Invite by email', { start: '/members' })
|
|
148
|
+
.card('Invite by email', { points: ['Enter an email', 'Teammate gets a link', 'Joins the same day'] })
|
|
149
|
+
.card('Why it matters', { points: ['Faster onboarding', 'Fewer support tickets'] })
|
|
150
|
+
\`\`\`
|
|
151
|
+
Product version (right): the same points, proven by the interface.
|
|
152
|
+
\`\`\`tsx
|
|
153
|
+
flow('Invite a teammate', { start: '/members' })
|
|
154
|
+
.card('Ana needs Leo in the space today', { sub: 'She is the space admin' })
|
|
155
|
+
.click('btn_invite', 'Ana opens Invite', set($.ui.inviteOpen, true))
|
|
156
|
+
.type('in_email', 'leo@acme.com', 'Ana enters Leo\'s email')
|
|
157
|
+
.click('btn_send', 'The invite is on its way', set($.ui.inviteOpen, false),
|
|
158
|
+
push($.data.pending, { email: 'leo@acme.com', status: 'Pending' }), toast.success('Invite sent to leo@acme.com'))
|
|
159
|
+
.card('Now Leo', { role: 'leo' })
|
|
160
|
+
.click('mail_join', 'Leo opens the link and lands in the space', go('/space'), done('Leo joins the same day'))
|
|
161
|
+
\`\`\`
|
|
162
|
+
Backend behind the same feature: put a Diagram in its own layer and .system('Send mail', 'The mail job runs in the background', trace('api', 'queue', 'mailer'), shot('mailer')); a failure is trace.fail('queue', 'mailer') plus the error the user sees. Full examples: examples/invite, examples/agent-arch.
|
|
163
|
+
|
|
164
|
+
## 2. Plan the demo first (write it in your reply; ask only questions that change it, each with a default)
|
|
140
165
|
- Audience: who watches (product review, design review, a customer, engineers) and what they must decide afterward.
|
|
141
166
|
- One to three points: what viewers must believe after watching. Each point becomes a scenario or an A/B comparison, never a single step.
|
|
142
167
|
- Scene list, one line per scenario: Given (who, where, starting state) → When (the user's actions) → Then (the visible result), plus how it opens and how it ends.
|
|
143
168
|
- Length: a scenario is usually 5–12 steps, about 20–60 s at 1×. check flags one over 90 s; npx joplo outline prints every estimate.
|
|
144
169
|
- Unsure how to frame it? Offer two or three one-line framings and let the user pick.
|
|
145
170
|
|
|
146
|
-
##
|
|
171
|
+
## 3. PM lens: from a need to roles, goal, cases, and scenarios
|
|
147
172
|
Joplo already has the parts of a user story; fill them in that spirit.
|
|
148
173
|
- roles: who it is for, specific ('Space admin', 'Invited teammate'), not 'User'. Use role('Name', { desc }) keys when layers or cards belong to a person; plain names are fine otherwise.
|
|
149
174
|
- goal (the I want + so that): one sentence, who can do what and why, independent of the solution so options A/B are two answers to it.
|
|
@@ -158,7 +183,7 @@ Joplo already has the parts of a user story; fill them in that spirit.
|
|
|
158
183
|
- INVEST check per scenario: Independent (its own start state), Valuable (ends on a visible result), Small (fits the length above), Testable (expected says exactly what appears).
|
|
159
184
|
- Direction still open? Build only the main scenario of options A and B first; add every case after the user picks.
|
|
160
185
|
|
|
161
|
-
##
|
|
186
|
+
## 4. Openings, middles, endings
|
|
162
187
|
- Opening: the first step or an opening .card('…', { sub }) says who is trying to do what and why, in one sentence. No logo, no 'So you open the app'.
|
|
163
188
|
- Middle: each step proves one thing with a visible action and a visible change; the cause must be visible (a click, an incoming message, a time-jump card).
|
|
164
189
|
A screen that changes with no trigger reads as a screensaver. Mock results come from steps: set(), toast(), go().
|
|
@@ -166,7 +191,7 @@ Joplo already has the parts of a user story; fill them in that spirit.
|
|
|
166
191
|
- Transitions: keep something on screen across a change (the same list, the same person); cards only for time jumps, role switches, opening, and ending.
|
|
167
192
|
- Where the viewer looks each moment (one focus per step, spotlight, highlight, callout, numbered, hold): npx joplo skill focus; layers and shots: npx joplo skill demo.
|
|
168
193
|
|
|
169
|
-
##
|
|
194
|
+
## 5. Captions and explain
|
|
170
195
|
- One idea per caption, about 24 units (CJK 1, other characters 0.5). Subject + verb, active voice, the visible action first: 'Ana sends the invite', 'The link expires after 7 days'.
|
|
171
196
|
- explain (about 48 units) says why it matters or what it means; never repeat the caption.
|
|
172
197
|
- System steps are narration of what happened ('The server rejects the address'), not labels ('System event').
|
|
@@ -175,10 +200,28 @@ Joplo already has the parts of a user story; fill them in that spirit.
|
|
|
175
200
|
- Cover text: flow({ description }) is the cover sentence, 30 units at most (DESCRIPTION_TOO_LONG). The cover falls back to the feature goal.
|
|
176
201
|
- Rhythm: every short step waits 3 s, so a run of trivial steps feels like a metronome. Merge trivial steps (type, then click) and give key results an explain.
|
|
177
202
|
|
|
178
|
-
##
|
|
203
|
+
## 6. Narration: narrate() is a presenter talking, not the caption read aloud
|
|
204
|
+
When the board or the published site reads a demo aloud, each step reads, in order of preference: narrate() in the narrator's voice; else say(), the character's own line in that role's voice; else the caption in the narrator's voice (cards read title and sub). A caption read aloud sounds like a screen reader, so give the steps that will be heard a narrate() line, written the way a person walks a colleague through a feature. It may later be recorded by a real voice, so write how people speak.
|
|
205
|
+
- Short first: one sentence, two at most, mostly 3–8 seconds. Cut every word the screen already shows; the viewer is watching.
|
|
206
|
+
- Each line does one job: orient (who, where, what we are about to see), point (what to look at now and why it matters), connect (carry the viewer from the last step: 'Now over to Ajie'), or conclude (what this proved).
|
|
207
|
+
- Say what the caption cannot: the intent, the reason, the consequence. Never repeat the caption word for word; name an on-screen label only when the viewer must find it.
|
|
208
|
+
- Spoken sentences: subject first, active voice, one idea each. Commas and periods are the breaths; no brackets, slashes, arrows, emoji, or markdown.
|
|
209
|
+
- Write numbers, money, times, and versions the way they are said in the demo's language ('four hundred sixty' rather than '¥460'; 'version two' rather than 'v2').
|
|
210
|
+
- Transitions carry the story: role switches, time jumps, and closing cards need a line that tells the viewer why we moved.
|
|
211
|
+
- Plain and concrete, not flowery: no metaphors, slogans, or hype. Vivid means specific: real names, amounts, and times.
|
|
212
|
+
- Not every step needs its own line: a trivial step can keep its short caption, and a character's say() can carry a moment ('Count me in!').
|
|
213
|
+
- say() is first person, what the character would really say; narration about the characters goes in narrate().
|
|
214
|
+
- Open with the person and their goal; close with the one to three points, as speech, not a list read aloud. Write in the demo's language.
|
|
215
|
+
Wrong, it reads the interface: .click('share', 'Xiaoyu shares the itinerary', narrate('Click Share to share the itinerary.'))
|
|
216
|
+
Right, it says why: .click('share', 'Xiaoyu shares the itinerary', narrate('She sends it as a link, so Ajie needs no app.'))
|
|
217
|
+
A character speaking: .click('can_go', 'Ajie replies: I can go', say('Count me in!'))
|
|
218
|
+
Check: read every line aloud in order without looking at the screen. It should sound like one person telling one story, briskly.
|
|
219
|
+
|
|
220
|
+
## 7. Before handing over
|
|
179
221
|
- npx joplo outline: per feature, who it is for, the goal, each case with its expected result and coverage per option, and each scenario's steps, duration, opening and ending.
|
|
180
222
|
- npx joplo check: CAPTION_TOO_LONG, EXPLAIN_TOO_LONG, DESCRIPTION_TOO_LONG, CARD_TEXT_TOO_LONG, SCENARIO_TOO_LONG, HAPPY_PATH_ONLY, CASE_NOT_COVERED (names the expected result).
|
|
181
223
|
- Read only the captions from start to end: do they tell the story? Then look only at key frames (npx joplo render --step-id …): does the screen show it without captions?
|
|
224
|
+
- If the key frames look like slide thumbnails (mostly cards, bullet points, or a screen that never changes), rebuild those steps as actions and visible changes (section 1).
|
|
182
225
|
- Tell the user which cases have no expected result yet and which options do not cover a high-priority case.`,
|
|
183
226
|
authoring: `# Joplo authoring: authoring
|
|
184
227
|
|
|
@@ -314,11 +357,14 @@ What viewers look at in each step, and the lighter forms (spotlight, highlight,
|
|
|
314
357
|
- Backend / architecture / logic: Diagram (relationships, grouped by business domain), Sequence (one call chain in time order), StateMachine (a lifecycle). Read npx joplo skill diagram.
|
|
315
358
|
- Layout is automatic and computed at compile time; nodes never move between steps, also when parts appear with when.
|
|
316
359
|
- Use trace('a','b','c') for the a→b→c call; trace.fail marks failure, trace.skip dims what was not called. Do not manually write node/edge state props or use set() to simulate calls; use trace().
|
|
317
|
-
- shot of a Diagram node keeps its parent group (at least the group title) in frame; shot of a UI card keeps its framed container and zooms at most 1.25
|
|
360
|
+
- shot of a Diagram node keeps its parent group (at least the group title) in frame; shot of a UI card keeps its framed container and zooms at most 1.25×, or more (up to 3×) when its text would be smaller than about 15px on screen, as on a phone layer. See diagram.
|
|
318
361
|
|
|
319
362
|
## Captions and fitting one screen
|
|
320
363
|
- Keep captions within about 24 units and explain('Additional note') within about 48. CJK characters count as 1 each; all others count as 0.5; whitespace is ignored. check warns when exceeded.
|
|
321
364
|
- Captions and explain notes appear below the stage, never over it. Tell one thing per step; move long content to an explanation layer. How to write them, and how to plan openings and endings: story.
|
|
365
|
+
- Narration (D74): the board and published site can read each step aloud during autoplay (viewers turn it on with the speaker button). Without say() the caption is read (cards read title and sub; explain is not read), which sounds like a screen reader. narrate('…') gives a step the narrator's spoken line and say('…') a character's own words, both kept apart from the caption (the caption is for the eye and stays short). How to write them: npx joplo skill story (section 6). Autoplay waits for the voice to finish plus a short breath before the next step.
|
|
366
|
+
Example: .type('email', 'ana@example.com', 'Ana enters the email', narrate('She invites Leo as an editor; the role can change later.')).
|
|
367
|
+
Voices are set up in the board (Voice → Manage providers; keys stay on this machine). config({ voice: { narrator: 'nova', roles: { leo: 'echo' } } }) picks voices per role; generated audio is bundled by build and share.
|
|
322
368
|
- Autoplay reading time: CJK 8 chars/s (125ms each), Latin 15 non-whitespace chars/s; clamp to 3–7 seconds before 0.5× / 1× / 1.5× scaling. Streams, shots and edge waits can exceed 7 seconds. Shots use 700ms ease-out without overshoot.
|
|
323
369
|
- Do not make viewers scroll through a long page. Fit one screen and zoom into details with shots.
|
|
324
370
|
- Each page has one device, desktop by default. page({ viewport: 'mobile' }, tree) uses a Phone frame at a fixed width of 390.
|
|
@@ -481,7 +527,7 @@ Choose by the question: "what is where" → Diagram; "what happens in what order
|
|
|
481
527
|
## Frame with shot (what the camera keeps)
|
|
482
528
|
- shot('kernel') frames the node with its parent group; when the whole group would make text too small, it keeps at least the group title. Viewers always see which domain they are in.
|
|
483
529
|
- A trace with several nodes frames all of them and their group titles. shot('g_run') frames a whole domain; shot() returns to the whole layer.
|
|
484
|
-
- UI cards and panels zoom at most 1.25× and keep their framed container (Card, Paper, Modal, Table, AppShell side…) in view, so neighbours stay visible.
|
|
530
|
+
- UI cards and panels zoom at most 1.25× (more, up to 3×, only when their text would be under about 15px on screen, e.g. a phone layer) and keep their framed container (Card, Paper, Modal, Table, AppShell side…) in view, so neighbours stay visible.
|
|
485
531
|
- Want more context? shot the container or group. Want the reader to compare two places? shot both ids in one step.
|
|
486
532
|
- Do not use zoom to read tiny text: if a diagram needs heavy zoom, split it into layers.
|
|
487
533
|
- Point at a part without zooming: spotlight / highlight / callout (see focus). A callout on the framed node's group or a message's participant stays in the shot.
|
|
@@ -649,6 +695,9 @@ Example: features/invite/options/a.tsx:12:5 warning UNBOUND_INTERACTIVE Inter
|
|
|
649
695
|
- DUPLICATE_ELEMENT: Duplicate element ids within a stage. Change only conflicting ids and update references.
|
|
650
696
|
- CAPTION_TOO_LONG: Shorten the caption to about 24 units: CJK characters count as 1 each, all others as 0.5; whitespace is ignored. One thing per step; move long content to an explanation layer. See demo.
|
|
651
697
|
- EXPLAIN_TOO_LONG: Shorten the explain note to about 48 units, using the same CJK 1 / other 0.5 calculation. Put detailed rationale in a separate explanation layer. See demo.
|
|
698
|
+
- SAY_TOO_LONG / NARRATE_TOO_LONG (warning): a say() or narrate() line over about 80 units (about 10 seconds aloud). Autoplay waits until it is read; say less or split the step.
|
|
699
|
+
- SAY_EMPTY / NARRATE_EMPTY: say() needs the character's words, narrate() the narrator's. Remove it to fall back to the caption.
|
|
700
|
+
- VOICE_CONFIG_INVALID: config({ voice }) takes { profile?, narrator?, roles?: { roleKey: 'voice' } } with non-empty strings. API keys never go in the config.
|
|
652
701
|
- DESCRIPTION_TOO_LONG: flow({ description }) is the scenario cover sentence; keep it within 30 units, one sentence saying what this scenario shows. See story.
|
|
653
702
|
- CARD_TEXT_TOO_LONG (info): a transition card's sub is over 48 units, a point over 24, or more than 4 points. Keep one sentence and a few short points; move details into steps.
|
|
654
703
|
- SCENARIO_TOO_LONG (info): the scenario plays over 90 s at 1×. One scenario tells one thing: split it (happy path, then each recovery) or branch with fork(). npx joplo outline shows the pacing.
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/schema.d.ts
CHANGED
|
@@ -342,6 +342,8 @@ export declare const Step: z.ZodObject<{
|
|
|
342
342
|
}>>;
|
|
343
343
|
}, z.core.$strict>>>;
|
|
344
344
|
hold: z.ZodOptional<z.ZodNumber>;
|
|
345
|
+
say: z.ZodOptional<z.ZodString>;
|
|
346
|
+
narrate: z.ZodOptional<z.ZodString>;
|
|
345
347
|
source: z.ZodOptional<z.ZodString>;
|
|
346
348
|
}, z.core.$strict>;
|
|
347
349
|
export declare const Scenario: z.ZodObject<{
|
|
@@ -508,6 +510,8 @@ export declare const Scenario: z.ZodObject<{
|
|
|
508
510
|
}>>;
|
|
509
511
|
}, z.core.$strict>>>;
|
|
510
512
|
hold: z.ZodOptional<z.ZodNumber>;
|
|
513
|
+
say: z.ZodOptional<z.ZodString>;
|
|
514
|
+
narrate: z.ZodOptional<z.ZodString>;
|
|
511
515
|
source: z.ZodOptional<z.ZodString>;
|
|
512
516
|
}, z.core.$strict>>>;
|
|
513
517
|
expected: z.ZodDefault<z.ZodString>;
|
|
@@ -663,12 +667,37 @@ export declare const Issue: z.ZodObject<{
|
|
|
663
667
|
refs: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
664
668
|
source: z.ZodOptional<z.ZodString>;
|
|
665
669
|
}, z.core.$strict>;
|
|
670
|
+
/** 朗读配置(D74,来自 config({ voice })):只在 dev / review IR 里,发布站去掉。 */
|
|
671
|
+
export declare const VoiceConfig: z.ZodObject<{
|
|
672
|
+
profile: z.ZodOptional<z.ZodString>;
|
|
673
|
+
narrator: z.ZodOptional<z.ZodString>;
|
|
674
|
+
roles: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
675
|
+
}, z.core.$strict>;
|
|
676
|
+
/**
|
|
677
|
+
* 发布站带上的朗读音频(D74,joplo build 写入):voices 是每个声音的指纹(旁白与各角色),
|
|
678
|
+
* clips 的键是 clipKey(指纹, 朗读文字),值是相对站点根目录的音频路径。没有时观众端用浏览器朗读。
|
|
679
|
+
*/
|
|
680
|
+
export declare const VoiceIndex: z.ZodObject<{
|
|
681
|
+
narrator: z.ZodNullable<z.ZodString>;
|
|
682
|
+
roles: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
683
|
+
clips: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
684
|
+
}, z.core.$strict>;
|
|
666
685
|
export declare const Project: z.ZodObject<{
|
|
667
686
|
schemaVersion: z.ZodLiteral<2>;
|
|
668
687
|
name: z.ZodString;
|
|
669
688
|
description: z.ZodDefault<z.ZodString>;
|
|
670
689
|
theme: z.ZodDefault<z.ZodString>;
|
|
671
690
|
autoFocus: z.ZodOptional<z.ZodBoolean>;
|
|
691
|
+
voiceConfig: z.ZodOptional<z.ZodObject<{
|
|
692
|
+
profile: z.ZodOptional<z.ZodString>;
|
|
693
|
+
narrator: z.ZodOptional<z.ZodString>;
|
|
694
|
+
roles: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
695
|
+
}, z.core.$strict>>;
|
|
696
|
+
voiceIndex: z.ZodOptional<z.ZodObject<{
|
|
697
|
+
narrator: z.ZodNullable<z.ZodString>;
|
|
698
|
+
roles: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
699
|
+
clips: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
700
|
+
}, z.core.$strict>>;
|
|
672
701
|
themes: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
673
702
|
mode: z.ZodEnum<{
|
|
674
703
|
publish: "publish";
|
|
@@ -969,6 +998,8 @@ export declare const Project: z.ZodObject<{
|
|
|
969
998
|
}>>;
|
|
970
999
|
}, z.core.$strict>>>;
|
|
971
1000
|
hold: z.ZodOptional<z.ZodNumber>;
|
|
1001
|
+
say: z.ZodOptional<z.ZodString>;
|
|
1002
|
+
narrate: z.ZodOptional<z.ZodString>;
|
|
972
1003
|
source: z.ZodOptional<z.ZodString>;
|
|
973
1004
|
}, z.core.$strict>>>;
|
|
974
1005
|
expected: z.ZodDefault<z.ZodString>;
|
|
@@ -1007,3 +1038,5 @@ export type Fork = z.infer<typeof Fork>;
|
|
|
1007
1038
|
export type Mark = z.infer<typeof Mark>;
|
|
1008
1039
|
export type Cue = z.infer<typeof Cue>;
|
|
1009
1040
|
export type Callout = z.infer<typeof Callout>;
|
|
1041
|
+
export type VoiceConfig = z.infer<typeof VoiceConfig>;
|
|
1042
|
+
export type VoiceIndex = z.infer<typeof VoiceIndex>;
|
package/dist/schema.js
CHANGED
|
@@ -167,6 +167,10 @@ export const Step = z.strictObject({
|
|
|
167
167
|
callouts: z.array(Callout).optional(),
|
|
168
168
|
/** 自动播放时这一步至少停留的毫秒数(D70,来自 hold;未按速度缩放);没有时省略。 */
|
|
169
169
|
hold: z.number().int().positive().max(30_000).optional(),
|
|
170
|
+
/** 角色台词(D74,来自 say(),多个按空格连接):用这一步角色的声音读;没有时省略。发布站保留。 */
|
|
171
|
+
say: z.string().min(1).optional(),
|
|
172
|
+
/** 旁白(D74,来自 narrate()):用旁白的声音读,优先于台词和字幕;没有时省略。发布站保留。 */
|
|
173
|
+
narrate: z.string().min(1).optional(),
|
|
170
174
|
source: Source,
|
|
171
175
|
});
|
|
172
176
|
export const Scenario = z.strictObject({
|
|
@@ -269,6 +273,21 @@ export const Issue = z.strictObject({
|
|
|
269
273
|
refs: z.array(z.string()).default([]),
|
|
270
274
|
source: Source,
|
|
271
275
|
});
|
|
276
|
+
/** 朗读配置(D74,来自 config({ voice })):只在 dev / review IR 里,发布站去掉。 */
|
|
277
|
+
export const VoiceConfig = z.strictObject({
|
|
278
|
+
profile: z.string().min(1).optional(),
|
|
279
|
+
narrator: z.string().min(1).optional(),
|
|
280
|
+
roles: z.record(z.string(), z.string().min(1)).optional(),
|
|
281
|
+
});
|
|
282
|
+
/**
|
|
283
|
+
* 发布站带上的朗读音频(D74,joplo build 写入):voices 是每个声音的指纹(旁白与各角色),
|
|
284
|
+
* clips 的键是 clipKey(指纹, 朗读文字),值是相对站点根目录的音频路径。没有时观众端用浏览器朗读。
|
|
285
|
+
*/
|
|
286
|
+
export const VoiceIndex = z.strictObject({
|
|
287
|
+
narrator: z.string().min(1).nullable(),
|
|
288
|
+
roles: z.record(z.string(), z.string().min(1)).default({}),
|
|
289
|
+
clips: z.record(z.string(), z.string().min(1)).default({}),
|
|
290
|
+
});
|
|
272
291
|
export const Project = z.strictObject({
|
|
273
292
|
schemaVersion: z.literal(SCHEMA_VERSION),
|
|
274
293
|
name: z.string().min(1),
|
|
@@ -277,6 +296,8 @@ export const Project = z.strictObject({
|
|
|
277
296
|
theme: z.string().min(1).default('sketch'),
|
|
278
297
|
/** 默认焦点行为(D70):缺省 = 开启;false = 只按作者写的镜头与提示呈现(config({ autoFocus: false }))。发布站保留。 */
|
|
279
298
|
autoFocus: z.boolean().optional(),
|
|
299
|
+
voiceConfig: VoiceConfig.optional(),
|
|
300
|
+
voiceIndex: VoiceIndex.optional(),
|
|
280
301
|
/** 作者主题(D51):主题名 → CSS 原文(themes/<name>.css);渲染时自动限定在舞台范围内。发布站同样打包。 */
|
|
281
302
|
themes: z.record(z.string(), z.string()).default({}),
|
|
282
303
|
/** dev = 含全部方案(本地看板);publish = 只含选定方案,且去掉创作侧信息(D33);review = 评审版:全部方案,同样去掉创作侧信息(D63)。 */
|
package/dist/validate.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { orderedFeatures } from "./features.js";
|
|
2
2
|
import { Project } from "./schema.js";
|
|
3
|
-
import { CAPTION_MAX, CARD_POINTS_MAX, DESCRIPTION_MAX, EXPLAIN_MAX, INTERACTIVE_TYPES, SCENARIO_MS_MAX, captionLength } from "./catalog.js";
|
|
3
|
+
import { CAPTION_MAX, CARD_POINTS_MAX, DESCRIPTION_MAX, EXPLAIN_MAX, SAY_MAX, INTERACTIVE_TYPES, SCENARIO_MS_MAX, captionLength } from "./catalog.js";
|
|
4
4
|
import { scenarioEstimateMs } from "./outline.js";
|
|
5
5
|
import { walkNodes, findNode, replay } from "./player.js";
|
|
6
6
|
import { JoploError } from "./result.js";
|
|
@@ -205,6 +205,12 @@ export function validate(project, opts = { mode: 'all' }) {
|
|
|
205
205
|
if (el > EXPLAIN_MAX)
|
|
206
206
|
emit('warning', 'EXPLAIN_TOO_LONG', `explain note length is ${el} units (recommended maximum: ${EXPLAIN_MAX}; CJK characters count as 1 each, all others as 0.5; whitespace is not counted). Move long content to a separate explanation layer, for example layers: { why: layer('Design rationale', <Why />) }, then switch to it with shot`, at, r);
|
|
207
207
|
}
|
|
208
|
+
// 朗读(D74):一段大约 SAY_MAX 个“字”读出来约 10 秒,再长观众会等得不耐烦
|
|
209
|
+
for (const [fn, code, text] of [['say', 'SAY_TOO_LONG', st.say], ['narrate', 'NARRATE_TOO_LONG', st.narrate]]) {
|
|
210
|
+
const sl = text ? captionLength(text) : 0;
|
|
211
|
+
if (sl > SAY_MAX)
|
|
212
|
+
emit('warning', code, `${fn}() is ${sl} units (recommended maximum: ${SAY_MAX}, about 10 seconds read aloud; CJK characters count as 1 each, all others as 0.5). Autoplay waits until it is read, so say less or split the step`, at, r);
|
|
213
|
+
}
|
|
208
214
|
}
|
|
209
215
|
}
|
|
210
216
|
focusStructureDiagnostics(p, scenarios, emit); // 焦点提示(D70)
|
package/dist/voice.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Project, Step } from './schema.js';
|
|
2
|
+
/**
|
|
3
|
+
* 默认说话风格(D74):像讲解人介绍功能,而不是朗读;用文字本身的语言、母语口音读(这就是“跟随语言”:
|
|
4
|
+
* 同一个音色读中文就是中文母语的读法,读英文就是英文的读法)。发给支持 instructions 的模型。
|
|
5
|
+
*/
|
|
6
|
+
export declare const DEFAULT_STYLE = "You are the narrator of a short product demo. Speak like a friendly presenter walking a colleague through a new feature: warm, clear and relaxed, at a natural conversational pace, never like reading a list. Pause briefly at commas and between sentences. Read the text in its own language with a natural native accent; never translate it.";
|
|
7
|
+
/** 读完之后、进下一步之前的换气(毫秒,1× 速度)。 */
|
|
8
|
+
export declare const VOICE_BREATH_MS = 450;
|
|
9
|
+
/** 把几句话连成一段朗读:句末没有标点时补一个(中文“。”,其他“.”)。 */
|
|
10
|
+
export declare function joinSpoken(parts: (string | null | undefined)[]): string;
|
|
11
|
+
/**
|
|
12
|
+
* 这一步读什么、用谁的声音(D74):narrate()(旁白的声音)> say()(这一步角色的声音;没有角色时旁白)>
|
|
13
|
+
* 字幕(旁白的声音;过渡卡读标题和副标题)。caption 是这一步在当前语言下显示的字幕(网页用 stepCaption,服务端用 step.caption);
|
|
14
|
+
* speaker 是这一步的说话角色(speakerRoleAt)。text 为空串表示这一步不读;role 为 null 表示旁白。
|
|
15
|
+
*/
|
|
16
|
+
export declare function spokenLine(step: Step, caption: string, speaker: string | null): {
|
|
17
|
+
text: string;
|
|
18
|
+
role: string | null;
|
|
19
|
+
};
|
|
20
|
+
/** 这一步要读的文字(不关心是谁读)。 */
|
|
21
|
+
export declare function narrationText(step: Step, caption: string): string;
|
|
22
|
+
/** 第 index 步(1 起)的说话角色:用户操作取这一步之后导演所在层画面的角色 id;没有角色、系统步骤与过渡卡为 null。say() 用它的声音。 */
|
|
23
|
+
export declare function speakerRoleAt(project: Project, scenarioId: string, index: number): string | null;
|
|
24
|
+
/** 音频片段的键:声音指纹 + 规整后的朗读文字(空白合并)。 */
|
|
25
|
+
export declare function clipKey(fingerprint: string, text: string): string;
|
|
26
|
+
/** 某个角色(null = 旁白)用哪个声音指纹;角色没有单独的声音时用旁白的。 */
|
|
27
|
+
export declare function voiceFingerprint(voices: {
|
|
28
|
+
narrator: string | null;
|
|
29
|
+
roles: Record<string, string>;
|
|
30
|
+
}, roleId: string | null): string | null;
|
package/dist/voice.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 朗读(D74)的纯函数:看板、发布站、服务端(生成与 build)共用。
|
|
3
|
+
*
|
|
4
|
+
* - 读什么:narrationText —— 有 say() 读 say;过渡卡读标题和副标题;其余读字幕(字幕由调用方按当前语言给出,
|
|
5
|
+
* 自动字幕在网页里本地化)。explain 不读。
|
|
6
|
+
* - 谁来读:speakerRoleAt —— 用户操作取这一步导演层画面的角色(与字幕说话人同一来源);系统步骤、过渡卡用旁白。
|
|
7
|
+
* - 音频片段的键:clipKey(声音指纹, 朗读文字)。指纹由服务端按 profile 与音色算出(不含 Key),
|
|
8
|
+
* 同一段文字换了声音或改了字就是新键,旧音频自然失效,不需要另记“过期”。
|
|
9
|
+
* - 节奏:每一步停留 = max(画面停留, 声音时长 + VOICE_BREATH_MS),换气按播放速度缩放。
|
|
10
|
+
*/
|
|
11
|
+
import { cameraAt, layersOf, roleOfScene } from "./player.js";
|
|
12
|
+
/**
|
|
13
|
+
* 默认说话风格(D74):像讲解人介绍功能,而不是朗读;用文字本身的语言、母语口音读(这就是“跟随语言”:
|
|
14
|
+
* 同一个音色读中文就是中文母语的读法,读英文就是英文的读法)。发给支持 instructions 的模型。
|
|
15
|
+
*/
|
|
16
|
+
export const DEFAULT_STYLE = 'You are the narrator of a short product demo. Speak like a friendly presenter walking a colleague through a new feature: warm, clear and relaxed, at a natural conversational pace, never like reading a list. Pause briefly at commas and between sentences. Read the text in its own language with a natural native accent; never translate it.';
|
|
17
|
+
/** 读完之后、进下一步之前的换气(毫秒,1× 速度)。 */
|
|
18
|
+
export const VOICE_BREATH_MS = 450;
|
|
19
|
+
/** 一段文字是不是以中日韩文字为主(决定拼接时用全角句号)。 */
|
|
20
|
+
const mostlyWide = (t) => [...t].filter((ch) => (ch.codePointAt(0) ?? 0) > 0x2e80).length * 2 >= [...t.replace(/\s/g, '')].length;
|
|
21
|
+
/** 全角句号与句末标点(写成转义:源码里不放 CJK 字面量)。 */
|
|
22
|
+
const WIDE_STOP = '\u3002';
|
|
23
|
+
const SENTENCE_END = /[\u3002\uff01\uff1f!?.\u2026:\uff1a;\uff1b,\uff0c]$/;
|
|
24
|
+
/** 把几句话连成一段朗读:句末没有标点时补一个(中文“。”,其他“.”)。 */
|
|
25
|
+
export function joinSpoken(parts) {
|
|
26
|
+
const xs = parts.map((p) => (p ?? '').trim()).filter(Boolean);
|
|
27
|
+
return xs
|
|
28
|
+
.map((p, i) => (i < xs.length - 1 && !SENTENCE_END.test(p) ? p + (mostlyWide(p) ? WIDE_STOP : '.') : p))
|
|
29
|
+
.join(xs.some(mostlyWide) ? '' : ' ');
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 这一步读什么、用谁的声音(D74):narrate()(旁白的声音)> say()(这一步角色的声音;没有角色时旁白)>
|
|
33
|
+
* 字幕(旁白的声音;过渡卡读标题和副标题)。caption 是这一步在当前语言下显示的字幕(网页用 stepCaption,服务端用 step.caption);
|
|
34
|
+
* speaker 是这一步的说话角色(speakerRoleAt)。text 为空串表示这一步不读;role 为 null 表示旁白。
|
|
35
|
+
*/
|
|
36
|
+
export function spokenLine(step, caption, speaker) {
|
|
37
|
+
if (step.narrate?.trim())
|
|
38
|
+
return { text: step.narrate.trim(), role: null };
|
|
39
|
+
if (step.say?.trim())
|
|
40
|
+
return { text: step.say.trim(), role: speaker };
|
|
41
|
+
if (step.action.type === 'card')
|
|
42
|
+
return { text: joinSpoken([step.action.title, step.action.sub]), role: null };
|
|
43
|
+
return { text: caption.trim(), role: null };
|
|
44
|
+
}
|
|
45
|
+
/** 这一步要读的文字(不关心是谁读)。 */
|
|
46
|
+
export function narrationText(step, caption) {
|
|
47
|
+
return spokenLine(step, caption, null).text;
|
|
48
|
+
}
|
|
49
|
+
/** 第 index 步(1 起)的说话角色:用户操作取这一步之后导演所在层画面的角色 id;没有角色、系统步骤与过渡卡为 null。say() 用它的声音。 */
|
|
50
|
+
export function speakerRoleAt(project, scenarioId, index) {
|
|
51
|
+
const step = project.scenarios[scenarioId]?.steps[index - 1];
|
|
52
|
+
if (!step || step.kind !== 'user')
|
|
53
|
+
return null;
|
|
54
|
+
const layer = cameraAt(project, scenarioId, index).directorLayer;
|
|
55
|
+
const sceneId = layersOf(project, scenarioId).find((l) => l.id === layer)?.sceneId;
|
|
56
|
+
return roleOfScene(project, sceneId)?.id ?? null;
|
|
57
|
+
}
|
|
58
|
+
/** 53 位的字符串哈希(cyrb53),两个种子拼成 26 位十六进制;同步、无依赖,网页与服务端结果一致。 */
|
|
59
|
+
function cyrb53(s, seed) {
|
|
60
|
+
let h1 = 0xdeadbeef ^ seed;
|
|
61
|
+
let h2 = 0x41c6ce57 ^ seed;
|
|
62
|
+
for (let i = 0; i < s.length; i++) {
|
|
63
|
+
const ch = s.charCodeAt(i);
|
|
64
|
+
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
65
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
66
|
+
}
|
|
67
|
+
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
|
|
68
|
+
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
|
|
69
|
+
return 4294967296 * (2097151 & h2) + (h1 >>> 0);
|
|
70
|
+
}
|
|
71
|
+
/** 音频片段的键:声音指纹 + 规整后的朗读文字(空白合并)。 */
|
|
72
|
+
export function clipKey(fingerprint, text) {
|
|
73
|
+
const s = `${fingerprint}\n${text.replace(/\s+/g, ' ').trim()}`;
|
|
74
|
+
return `c${cyrb53(s, 1).toString(16).padStart(14, '0')}${cyrb53(s, 7).toString(16).padStart(14, '0')}`;
|
|
75
|
+
}
|
|
76
|
+
/** 某个角色(null = 旁白)用哪个声音指纹;角色没有单独的声音时用旁白的。 */
|
|
77
|
+
export function voiceFingerprint(voices, roleId) {
|
|
78
|
+
return (roleId ? voices.roles[roleId] : undefined) ?? voices.narrator;
|
|
79
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joplo-app/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
4
4
|
"description": "Joplo 编译器、校验器与播放器(IR v2)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"dist"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@joplo-app/kit": "0.2.
|
|
22
|
+
"@joplo-app/kit": "0.2.10",
|
|
23
23
|
"elkjs": "0.12.1",
|
|
24
24
|
"zod": "4.6.7"
|
|
25
25
|
},
|