@joplo-app/core 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-skill.d.ts +7 -7
- package/dist/agent-skill.js +29 -25
- package/dist/authoring-works.d.ts +8 -0
- package/dist/authoring-works.js +46 -0
- package/dist/catalog.d.ts +2 -0
- package/dist/compile.d.ts +6 -3
- package/dist/compile.js +415 -340
- package/dist/content-i18n.js +9 -9
- package/dist/embed.d.ts +5 -5
- package/dist/embed.js +7 -7
- package/dist/entries.d.ts +63 -0
- package/dist/entries.js +78 -0
- package/dist/feature-diff.d.ts +7 -7
- package/dist/feature-diff.js +18 -17
- package/dist/features.d.ts +3 -3
- package/dist/features.js +3 -3
- package/dist/focus-check.js +2 -2
- package/dist/focus.d.ts +1 -5
- package/dist/focus.js +13 -35
- package/dist/guide.js +157 -67
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/load.js +42 -11
- package/dist/local-review-files.js +17 -4
- package/dist/local-review.d.ts +8 -7
- package/dist/local-review.js +7 -6
- package/dist/outline.d.ts +21 -13
- package/dist/outline.js +27 -32
- package/dist/pace.d.ts +3 -4
- package/dist/pace.js +3 -4
- package/dist/playback.d.ts +57 -0
- package/dist/playback.js +317 -0
- package/dist/player.d.ts +9 -195
- package/dist/player.js +8 -633
- package/dist/playground.d.ts +1 -1
- package/dist/playground.js +4 -4
- package/dist/plugins/compiler.d.ts +16 -0
- package/dist/plugins/compiler.js +48 -9
- package/dist/presentation.d.ts +73 -0
- package/dist/presentation.js +163 -0
- package/dist/publication.d.ts +8 -0
- package/dist/publication.js +45 -0
- package/dist/result.d.ts +1 -1
- package/dist/review.d.ts +18 -10
- package/dist/review.js +62 -23
- package/dist/runtime.d.ts +2 -0
- package/dist/runtime.js +2 -0
- package/dist/scene-query.d.ts +77 -0
- package/dist/scene-query.js +246 -0
- package/dist/schema-issues.js +1 -1
- package/dist/schema.d.ts +108 -76
- package/dist/schema.js +48 -36
- package/dist/scope.d.ts +9 -9
- package/dist/scope.js +82 -49
- package/dist/selection.d.ts +1 -1
- package/dist/sequencing.d.ts +6 -0
- package/dist/sequencing.js +21 -0
- package/dist/step-plan.d.ts +55 -0
- package/dist/step-plan.js +90 -0
- package/dist/traits.d.ts +10 -0
- package/dist/traits.js +3 -0
- package/dist/validate.d.ts +1 -1
- package/dist/validate.js +75 -65
- package/dist/voice.js +2 -1
- package/package.json +15 -3
package/dist/scope.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { entriesOf, entryOf, rolesOf } from "./entries.js";
|
|
2
|
+
import { assertExportableEntry, localOnlyWorks, localOnlyElementIds } from "./publication.js";
|
|
1
3
|
import { pruneMediaAssets } from "./media.js";
|
|
2
4
|
import { scopePluginData } from "./plugin-data.js";
|
|
3
5
|
/**
|
|
@@ -11,21 +13,22 @@ import { scopePluginData } from "./plugin-data.js";
|
|
|
11
13
|
* dev、publish、review 三种 IR 都能裁剪:share 用它裁剪发布 IR(上传的文件)和 dev IR(评审清单、预览图)。
|
|
12
14
|
*/
|
|
13
15
|
import { pruneMessages } from "./content-i18n.js";
|
|
14
|
-
import {
|
|
16
|
+
import { featuresOf } from "./features.js";
|
|
15
17
|
import { JoploError } from "./result.js";
|
|
16
|
-
export const hasScope = (r) => !!r && ((r.scenarios?.length ?? 0) > 0 || (r.
|
|
18
|
+
export const hasScope = (r) => !!r && ((r.scenarios?.length ?? 0) > 0 || (r.entryIds?.length ?? 0) > 0);
|
|
17
19
|
export const scopeKey = (scenarios, mode) => `${mode === 'review' ? 'review:' : ''}${[...scenarios].sort().join(',')}`;
|
|
18
|
-
/** 演示顺序:按功能顺序(
|
|
20
|
+
/** 演示顺序:按功能顺序(entryIds),同一功能里按 IR 顺序。 */
|
|
19
21
|
function demoOrder(project) {
|
|
20
|
-
const rank = new Map(
|
|
22
|
+
const rank = new Map(project.entryIds.map((id, i) => [id, i]));
|
|
21
23
|
const all = Object.values(project.scenarios);
|
|
22
|
-
const r = (
|
|
23
|
-
return all.map((s, i) => ({ s, i })).sort((a, b) => r(a.s.
|
|
24
|
+
const r = (workId) => rank.get(project.works[workId]?.featureId ?? workId) ?? rank.size;
|
|
25
|
+
return all.map((s, i) => ({ s, i })).sort((a, b) => r(a.s.workId) - r(b.s.workId) || a.i - b.i).map(({ s }) => s.id);
|
|
24
26
|
}
|
|
25
27
|
/** 在给定模式下可分享的场景:publish 只有各功能选定方案的场景。 */
|
|
26
28
|
function shareable(project, mode) {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
+
const local = localOnlyWorks(project);
|
|
30
|
+
const picked = new Set(featuresOf(project).map((f) => f.pick).filter((p) => !!p));
|
|
31
|
+
return Object.values(project.scenarios).filter((s) => !local.has(s.workId) && (mode === 'review' || !project.works[s.workId]?.featureId || picked.has(s.workId))).map((s) => s.id);
|
|
29
32
|
}
|
|
30
33
|
function listLines(project, ids) {
|
|
31
34
|
const shown = ids.slice(0, 20).map((id) => ` ${id} ${project.scenarios[id]?.name ?? ''}`);
|
|
@@ -37,33 +40,35 @@ function listLines(project, ids) {
|
|
|
37
40
|
export function resolveScope(project, request, mode) {
|
|
38
41
|
const ok = new Set(shareable(project, mode));
|
|
39
42
|
const out = new Set();
|
|
40
|
-
for (const fid of request.
|
|
43
|
+
for (const fid of request.entryIds ?? []) {
|
|
41
44
|
const f = project.features[fid];
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
const entry = entryOf(project, fid);
|
|
46
|
+
if (!entry) {
|
|
47
|
+
const known = entriesOf(project).map((x) => x.id).join(', ') || 'none';
|
|
48
|
+
throw new JoploError('NOT_FOUND', `Unknown entry "${fid}"${mode === 'publish' ? ', or it has no picked work' : ''}. Entries: ${known}`, { details: { scope: 'entry', id: fid } });
|
|
45
49
|
}
|
|
46
|
-
|
|
50
|
+
assertExportableEntry(project, fid);
|
|
51
|
+
const opts = f ? mode === 'review' ? f.workIds : f.pick ? [f.pick] : [] : [fid];
|
|
47
52
|
if (!opts.length)
|
|
48
|
-
throw new JoploError('USAGE', `Feature "${fid}" has no picked
|
|
53
|
+
throw new JoploError('USAGE', `Feature "${fid}" has no picked work, so nothing of it is published. Pick an alternative (feature.pick), or share the review version (--review)`, { details: { scope: 'entry', id: fid } });
|
|
49
54
|
for (const s of Object.values(project.scenarios))
|
|
50
|
-
if (opts.includes(s.
|
|
55
|
+
if (opts.includes(s.workId))
|
|
51
56
|
out.add(s.id);
|
|
52
57
|
}
|
|
53
58
|
for (const sid of request.scenarios ?? []) {
|
|
54
59
|
const s = project.scenarios[sid];
|
|
60
|
+
if (s)
|
|
61
|
+
assertExportableEntry(project, project.works[s.workId]?.featureId ?? s.workId);
|
|
55
62
|
if (s && ok.has(sid)) {
|
|
56
63
|
out.add(sid);
|
|
57
64
|
continue;
|
|
58
65
|
}
|
|
59
66
|
if (s) {
|
|
60
|
-
const o = project.
|
|
61
|
-
throw new JoploError('USAGE', `Scenario ${sid} belongs to
|
|
67
|
+
const o = project.works[s.workId];
|
|
68
|
+
throw new JoploError('USAGE', `Scenario ${sid} belongs to work ${s.workId}, which is not the picked work of feature "${o?.featureId ?? '?'}"; only picked works are published. Pick it, or share the review version (--review)`, { details: { scope: 'scenario', id: sid } });
|
|
62
69
|
}
|
|
63
|
-
const tail = sid.split('.').pop() ?? sid;
|
|
64
|
-
const head = sid.split('.')[0] ?? sid;
|
|
65
70
|
const all = [...ok];
|
|
66
|
-
const near = all.filter((id) => id.
|
|
71
|
+
const near = all.filter((id) => id.includes(sid) || sid.includes(id));
|
|
67
72
|
const hint = near.length ? `Did you mean:${listLines(project, near)}` : `Scenarios you can share:${listLines(project, all)}`;
|
|
68
73
|
throw new JoploError('NOT_FOUND', `Unknown scenario ${sid}. ${hint}\nNothing was built or uploaded`, { details: { scope: 'scenario', id: sid } });
|
|
69
74
|
}
|
|
@@ -100,11 +105,23 @@ function idsIn(n, out = []) {
|
|
|
100
105
|
* 裁剪到给定场景(先用 resolveScope 解析)。返回新的 IR(输入不变)和范围说明。
|
|
101
106
|
*/
|
|
102
107
|
export function scopeProject(project, scenarioIds, mode = project.mode === 'review' ? 'review' : 'publish') {
|
|
108
|
+
const local = localOnlyWorks(project);
|
|
109
|
+
const privateElements = localOnlyElementIds(project, local);
|
|
110
|
+
for (const id of scenarioIds) {
|
|
111
|
+
const s = project.scenarios[id];
|
|
112
|
+
if (s)
|
|
113
|
+
assertExportableEntry(project, project.works[s.workId]?.featureId ?? s.workId);
|
|
114
|
+
if (s?.from && local.has(project.scenarios[s.from]?.workId ?? ''))
|
|
115
|
+
throw new JoploError('USAGE', 'A shared slice cannot continue a draft or empty work');
|
|
116
|
+
}
|
|
103
117
|
const S = new Set(scenarioIds.filter((id) => project.scenarios[id]));
|
|
104
118
|
if (!S.size)
|
|
105
119
|
throw new JoploError('USAGE', 'The scope has no scenarios; nothing to share');
|
|
106
|
-
const
|
|
107
|
-
|
|
120
|
+
for (const sid of S)
|
|
121
|
+
if (project.scenarios[sid].steps.some(st => stepRefs(st).some(id => privateElements.has(id))))
|
|
122
|
+
throw new JoploError('USAGE', 'A shared slice cannot reference draft or private elements');
|
|
123
|
+
const O = new Set([...S].map((id) => project.scenarios[id].workId));
|
|
124
|
+
const F = new Set([...O].map((id) => project.works[id]?.featureId).filter((f) => !!f));
|
|
108
125
|
// 引用:元素 id → 引用它的场景
|
|
109
126
|
const refBy = new Map();
|
|
110
127
|
for (const sid of S)
|
|
@@ -119,6 +136,9 @@ export function scopeProject(project, scenarioIds, mode = project.mode === 'revi
|
|
|
119
136
|
const useScene = (id, sid) => {
|
|
120
137
|
if (!project.scenes[id])
|
|
121
138
|
return;
|
|
139
|
+
const scene = project.scenes[id];
|
|
140
|
+
if (local.has(scene.workId ?? '') || local.has(project.routes[scene.route]?.addedBy ?? ''))
|
|
141
|
+
throw new JoploError('USAGE', 'A shared slice cannot use a draft or empty work page');
|
|
122
142
|
const set = sceneBy.get(id) ?? new Set();
|
|
123
143
|
set.add(sid);
|
|
124
144
|
sceneBy.set(id, set);
|
|
@@ -130,13 +150,14 @@ export function scopeProject(project, scenarioIds, mode = project.mode === 'revi
|
|
|
130
150
|
for (const e of st.effects)
|
|
131
151
|
if (e.type === 'navigate')
|
|
132
152
|
useScene(e.sceneId, sid);
|
|
133
|
-
for (const l of Object.values(project.
|
|
153
|
+
for (const l of Object.values(project.works[s.workId]?.layers ?? {}))
|
|
134
154
|
useScene(l.sceneId, sid);
|
|
135
155
|
}
|
|
136
156
|
const borrowed = [];
|
|
137
|
-
const
|
|
138
|
-
const fid = project.
|
|
139
|
-
|
|
157
|
+
const entryOwnerOf = (workId) => {
|
|
158
|
+
const fid = project.works[workId]?.featureId ?? workId;
|
|
159
|
+
const entry = entryOf(project, fid);
|
|
160
|
+
return { entryId: fid, entryTitle: entry?.title ?? fid };
|
|
140
161
|
};
|
|
141
162
|
/** 借用的子树:整条保留,去掉所有指向范围外方案的 from。 */
|
|
142
163
|
const strip = (n) => {
|
|
@@ -144,13 +165,18 @@ export function scopeProject(project, scenarioIds, mode = project.mode === 'revi
|
|
|
144
165
|
return { ...rest, ...(from !== undefined && O.has(from) ? { from } : {}), ...(children ? { children: children.map(strip) } : {}) };
|
|
145
166
|
};
|
|
146
167
|
const prune = (n, scene, users) => {
|
|
168
|
+
if (n.from && local.has(n.from)) {
|
|
169
|
+
if (idsIn(n).some(id => refBy.has(id)))
|
|
170
|
+
throw new JoploError('USAGE', 'A shared slice cannot borrow draft or private elements');
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
147
173
|
if (n.from !== undefined && !O.has(n.from)) {
|
|
148
174
|
const ids = idsIn(n);
|
|
149
175
|
const refs = ids.filter((id) => refBy.has(id));
|
|
150
176
|
if (!refs.length)
|
|
151
177
|
return null;
|
|
152
178
|
const who = new Set(refs.flatMap((id) => [...refBy.get(id)]).filter((sid) => users.has(sid)));
|
|
153
|
-
borrowed.push({ kind: 'element', ...
|
|
179
|
+
borrowed.push({ kind: 'element', ...entryOwnerOf(n.from), workId: n.from, elementId: n.id, route: scene.route, refs, scenarios: [...(who.size ? who : users)] });
|
|
154
180
|
return strip(n);
|
|
155
181
|
}
|
|
156
182
|
if (!n.children)
|
|
@@ -162,7 +188,10 @@ export function scopeProject(project, scenarioIds, mode = project.mode === 'revi
|
|
|
162
188
|
const users = sceneBy.get(id);
|
|
163
189
|
if (!users)
|
|
164
190
|
continue;
|
|
165
|
-
|
|
191
|
+
const root = prune(scene.root, scene, users);
|
|
192
|
+
if (!root && local.has(scene.root.from ?? ''))
|
|
193
|
+
throw new JoploError('USAGE', 'A shared slice cannot use a draft or private stage');
|
|
194
|
+
scenes[id] = { ...scene, root: root ?? scene.root };
|
|
166
195
|
}
|
|
167
196
|
// 路径:只留用得到的画面的路径;别的功能新增的页面按借用保留
|
|
168
197
|
const routes = {};
|
|
@@ -172,7 +201,7 @@ export function scopeProject(project, scenarioIds, mode = project.mode === 'revi
|
|
|
172
201
|
continue;
|
|
173
202
|
if (r.addedBy && !O.has(r.addedBy)) {
|
|
174
203
|
const users = new Set(Object.entries(scenes).filter(([, s]) => s.route === p).flatMap(([id]) => [...(sceneBy.get(id) ?? [])]));
|
|
175
|
-
borrowed.push({ kind: 'page', ...
|
|
204
|
+
borrowed.push({ kind: 'page', ...entryOwnerOf(r.addedBy), workId: r.addedBy, route: p, scenarios: [...users] });
|
|
176
205
|
const { addedBy: _a, ...rest } = r;
|
|
177
206
|
routes[p] = rest;
|
|
178
207
|
}
|
|
@@ -182,7 +211,7 @@ export function scopeProject(project, scenarioIds, mode = project.mode === 'revi
|
|
|
182
211
|
// 画面之间不会互相借用页面以外的东西;同一元素在多个画面被借用时合并成一条
|
|
183
212
|
const seen = new Set();
|
|
184
213
|
const merged = borrowed.filter((b) => {
|
|
185
|
-
const k = b.kind === 'element' ? `e|${b.
|
|
214
|
+
const k = b.kind === 'element' ? `e|${b.workId}|${b.elementId}|${b.route}` : `p|${b.route}`;
|
|
186
215
|
if (seen.has(k))
|
|
187
216
|
return false;
|
|
188
217
|
seen.add(k);
|
|
@@ -196,30 +225,34 @@ export function scopeProject(project, scenarioIds, mode = project.mode === 'revi
|
|
|
196
225
|
const { from, ...rest } = s;
|
|
197
226
|
scenarios[sid] = { ...rest, ...(from && S.has(from) ? { from } : {}), steps: s.steps.map((st) => (st.forks.some((f) => !S.has(f.scenarioId)) ? { ...st, forks: st.forks.filter((f) => S.has(f.scenarioId)) } : st)) };
|
|
198
227
|
}
|
|
199
|
-
const
|
|
200
|
-
for (const [id, o] of Object.entries(project.
|
|
228
|
+
const works = {};
|
|
229
|
+
for (const [id, o] of Object.entries(project.works)) {
|
|
201
230
|
if (!O.has(id))
|
|
202
231
|
continue;
|
|
203
|
-
const
|
|
204
|
-
.filter(([cid]) => F.has(project.cases[cid]?.featureId ?? cid.split('.')[0] ?? ''))
|
|
205
|
-
.map(([cid, c]) => [cid, { ...c, scenarioIds: c.scenarioIds.filter((x) => S.has(x)) }]));
|
|
206
|
-
const retained = new Set(Object.values(scenes).filter(s => s.optionId === id || s.optionId === null).flatMap(s => idsIn(s.root)));
|
|
232
|
+
const retained = new Set(Object.values(scenes).filter(s => s.workId === id || s.workId === null).flatMap(s => idsIn(s.root)));
|
|
207
233
|
const free = o.free ? Object.fromEntries(Object.entries(o.free).filter(([, reaction]) => {
|
|
208
234
|
const a = reaction.action;
|
|
209
235
|
return 'target' in a && retained.has(a.target) && (!('to' in a) || typeof a.to !== 'string' || retained.has(a.to));
|
|
210
236
|
})) : undefined;
|
|
211
|
-
|
|
237
|
+
works[id] = { ...o, ...(free ? { free } : {}) };
|
|
212
238
|
}
|
|
213
239
|
const features = {};
|
|
214
|
-
for (const f of
|
|
240
|
+
for (const f of featuresOf(project)) {
|
|
215
241
|
if (!F.has(f.id))
|
|
216
242
|
continue;
|
|
217
|
-
const
|
|
218
|
-
|
|
243
|
+
const workIds = f.workIds.filter((x) => O.has(x));
|
|
244
|
+
const alternatives = Object.fromEntries(workIds.map(id => {
|
|
245
|
+
const alternative = f.alternatives[id];
|
|
246
|
+
const coverage = Object.fromEntries(Object.entries(alternative.coverage)
|
|
247
|
+
.filter(([cid]) => F.has(project.cases[cid]?.featureId ?? ''))
|
|
248
|
+
.map(([cid, c]) => [cid, { ...c, scenarioIds: c.scenarioIds.filter(sid => S.has(sid)) }]));
|
|
249
|
+
return [id, { ...alternative, coverage }];
|
|
250
|
+
}));
|
|
251
|
+
features[f.id] = { ...f, workIds, alternatives, pick: f.pick && O.has(f.pick) ? f.pick : null };
|
|
219
252
|
}
|
|
220
|
-
const
|
|
221
|
-
const inF = (x) => F.has(x.featureId) && (x.
|
|
222
|
-
const roleIds = new Set(
|
|
253
|
+
const entryIds = project.entryIds.filter((id) => F.has(id) || O.has(id));
|
|
254
|
+
const inF = (x) => F.has(x.featureId) && (x.workId === undefined || O.has(x.workId));
|
|
255
|
+
const roleIds = new Set([...O].flatMap(id => rolesOf(project, id).map((r) => r.id).filter((r) => !!r)));
|
|
223
256
|
const onlyRoles = (r) => Object.fromEntries(Object.entries(r).filter(([k]) => roleIds.has(k)));
|
|
224
257
|
const keepRoles = (v) => v && (v.roles || v.locales)
|
|
225
258
|
? {
|
|
@@ -234,10 +267,10 @@ export function scopeProject(project, scenarioIds, mode = project.mode === 'revi
|
|
|
234
267
|
description: '',
|
|
235
268
|
routes,
|
|
236
269
|
features,
|
|
237
|
-
|
|
270
|
+
entryIds,
|
|
238
271
|
cases: Object.fromEntries(Object.entries(project.cases).filter(([, c]) => F.has(c.featureId))),
|
|
239
|
-
|
|
240
|
-
rules: Object.fromEntries(Object.entries(project.rules).filter(([, r]) => inF(r))),
|
|
272
|
+
works,
|
|
273
|
+
rules: Object.fromEntries(Object.entries(project.rules).filter(([, r]) => inF(r)).map(([id, r]) => [id, { ...r, elementIds: r.elementIds.filter(element => !privateElements.has(element)) }])),
|
|
241
274
|
scenes,
|
|
242
275
|
scenarios,
|
|
243
276
|
issues: Object.fromEntries(Object.entries(project.issues).filter(([, i]) => inF(i))),
|
|
@@ -246,11 +279,11 @@ export function scopeProject(project, scenarioIds, mode = project.mode === 'revi
|
|
|
246
279
|
};
|
|
247
280
|
const ids = Object.keys(scenarios);
|
|
248
281
|
// 译文只留范围内用得到的(D84):别的功能的文字不随范围分享出去
|
|
249
|
-
return { project: pruneMediaAssets(pruneMessages(scopePluginData(out))), info: { key: scopeKey(ids, mode), scenarios: ids,
|
|
282
|
+
return { project: pruneMediaAssets(pruneMessages(scopePluginData(out))), info: { key: scopeKey(ids, mode), scenarios: ids, entryIds: out.entryIds, borrowed: merged } };
|
|
250
283
|
}
|
|
251
284
|
/** 一条借用的说明(英文,CLI 与看板共用)。 */
|
|
252
285
|
export function borrowedLine(b) {
|
|
253
286
|
return b.kind === 'element'
|
|
254
|
-
? `${b.
|
|
255
|
-
: `${b.
|
|
287
|
+
? `${b.entryTitle} › element "${b.elementId}" on ${b.route} (referenced by ${b.refs.join(', ')})`
|
|
288
|
+
: `${b.entryTitle} › page ${b.route} (the scenario navigates there)`;
|
|
256
289
|
}
|
package/dist/selection.d.ts
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** 所有作品共用的章节接续解析;不修改作者对象,不在消费端重推默认值。 */
|
|
2
|
+
import { Flow, type Chapter } from '@joplo-app/kit';
|
|
3
|
+
export declare function resolveSlices(slices: Record<string, Flow | Chapter>, label: string, report: (code: string, message: string, at?: string) => void): {
|
|
4
|
+
scenarios: Record<string, Flow>;
|
|
5
|
+
linear: boolean;
|
|
6
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** 所有作品共用的章节接续解析;不修改作者对象,不在消费端重推默认值。 */
|
|
2
|
+
import { Flow } from '@joplo-app/kit';
|
|
3
|
+
export function resolveSlices(slices, label, report) {
|
|
4
|
+
const all = Object.values(slices);
|
|
5
|
+
const linear = all.some(s => s.kind === 'chapter');
|
|
6
|
+
if (!linear)
|
|
7
|
+
return { scenarios: slices, linear: false };
|
|
8
|
+
if (all.some(s => s.kind !== 'chapter'))
|
|
9
|
+
report('WORK_SLICES_MIXED', `${label} mixes chapter() and flow(); use one slice style throughout the work`, all.find(s => s.kind !== 'chapter')?.source);
|
|
10
|
+
const scenarios = {};
|
|
11
|
+
let previous;
|
|
12
|
+
for (const [key, slice] of Object.entries(slices)) {
|
|
13
|
+
const raw = slice.kind === 'chapter' ? slice.chapterOptions : slice.opts;
|
|
14
|
+
const from = raw.from === undefined ? previous : raw.from;
|
|
15
|
+
const { from: _from, ...rest } = raw;
|
|
16
|
+
const opts = { ...rest, ...(from !== null && from !== undefined ? { from } : {}) };
|
|
17
|
+
scenarios[key] = Object.assign(new Flow(slice.name, opts), { steps: slice.steps, source: slice.source });
|
|
18
|
+
previous = key;
|
|
19
|
+
}
|
|
20
|
+
return { scenarios, linear };
|
|
21
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Project, Step } from './schema.js';
|
|
2
|
+
/** 操作演示各段的时长(引擎毫秒)。 */
|
|
3
|
+
export declare const ACTION_TIMING: {
|
|
4
|
+
readonly cursorMove: 550;
|
|
5
|
+
readonly ripple: 260;
|
|
6
|
+
readonly typeChar: 45;
|
|
7
|
+
readonly selectHold: 420;
|
|
8
|
+
readonly toggleHold: 200;
|
|
9
|
+
readonly systemHold: 900;
|
|
10
|
+
/** 拖动、滚动,以及没有声明 durationMs 的插件动作。 */
|
|
11
|
+
readonly gesture: 800;
|
|
12
|
+
readonly afterStep: 300;
|
|
13
|
+
readonly reducedStep: 450;
|
|
14
|
+
readonly quickStep: 300;
|
|
15
|
+
/** 先切层 / 取景再移动鼠标:等新画面淡入、镜头到位。 */
|
|
16
|
+
readonly layerSwitch: number;
|
|
17
|
+
};
|
|
18
|
+
export type StepPlan = {
|
|
19
|
+
/** 提交之前:鼠标移到目标。 */
|
|
20
|
+
cursorMs: number;
|
|
21
|
+
/** 提交之前:按下的波纹(没有目标的操作是它的固定停顿)。 */
|
|
22
|
+
rippleMs: number;
|
|
23
|
+
/** 提交之前:手势本身(逐字输入、拖动、悬停、滚动、插件动作、系统事件停顿)。 */
|
|
24
|
+
gestureMs: number;
|
|
25
|
+
/** 提交之前合计 = cursorMs + rippleMs + gestureMs。 */
|
|
26
|
+
leadMs: number;
|
|
27
|
+
/** 提交之后的收尾(鼠标停一下);算在 dwellMs 里面。 */
|
|
28
|
+
settleMs: number;
|
|
29
|
+
/** 提交之后至少停留:作者 hold、插件效果时长、阅读 / 镜头 / 流式输出中最长的,不短于 settleMs。 */
|
|
30
|
+
dwellMs: number;
|
|
31
|
+
/** 朗读估算(narrate ?? say,含换气);没有为 0。 */
|
|
32
|
+
voiceMs: number;
|
|
33
|
+
/** 这一步合计 = leadMs + max(dwellMs, voiceMs)。 */
|
|
34
|
+
totalMs: number;
|
|
35
|
+
};
|
|
36
|
+
export type StepPlanOptions = {
|
|
37
|
+
/** 停留时要读的文字;缺省为 stepTexts(step)(英文兜底字幕)。界面传当前语言的字幕。 */
|
|
38
|
+
texts?: (string | null | undefined)[];
|
|
39
|
+
/** 减少动态效果:不移动鼠标、不逐字输入,每步一个固定的短停顿。 */
|
|
40
|
+
reduced?: boolean;
|
|
41
|
+
/** 演示时移动鼠标(缺省 true);观众自己点出来的这一步之后接的系统事件为 false。 */
|
|
42
|
+
cursor?: boolean;
|
|
43
|
+
/** 已经用提交前的状态算好的流式输出时长(D100);缺省按整段重新出估算。 */
|
|
44
|
+
streamMs?: number;
|
|
45
|
+
};
|
|
46
|
+
/** 一步停留时要读的文字:说明、explain,过渡卡再加副标题与要点。 */
|
|
47
|
+
export declare function stepTexts(step: Pick<Step, 'caption' | 'explain' | 'action'>): (string | undefined)[];
|
|
48
|
+
export declare function stepPlan(project: Pick<Project, 'plugins'>, step: Step, o?: StepPlanOptions): StepPlan;
|
|
49
|
+
/** 一个场景按 1× 自动播放大约多久(毫秒):每一步 stepPlan 的合计之和。 */
|
|
50
|
+
export declare function scenarioPlanMs(project: Pick<Project, 'plugins'>, steps: readonly Step[], texts?: (step: Step) => (string | null | undefined)[]): number;
|
|
51
|
+
/**
|
|
52
|
+
* 两次提交之间的时间(引擎毫秒,1×):第 index 步(0 起;-1 = 场景开始)提交之后,到下一步提交(最后一步之后 = 到场景播完)。
|
|
53
|
+
* 配乐快照按它推进:快照记录的是每一步提交那一刻的状态。
|
|
54
|
+
*/
|
|
55
|
+
export declare function commitGapMs(project: Pick<Project, 'plugins'>, steps: readonly Step[], index: number): number;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 一步的时间计划(纯函数):演示控制器、封面“约 M 秒”、`joplo outline`、check 的时长告警、配乐锚点与媒体检查共用这一份。
|
|
3
|
+
*
|
|
4
|
+
* 时间一律是引擎毫秒(1×):倍速由引擎时钟统一缩放,这里不出现速度。
|
|
5
|
+
* 一步 = 提交之前演示这次操作(leadMs:鼠标移动、波纹、手势 / 逐字输入)+ 提交之后停留(dwellMs,与朗读取较长者)。
|
|
6
|
+
*
|
|
7
|
+
* 只在运行时才知道的两项不在计划里:切层 / 把目标框进画面的引导(看观众当时在哪一层、镜头在哪),
|
|
8
|
+
* 以及朗读的真实时长(计划里是 voiceMs 估算;自动播放以真实读完为准)。
|
|
9
|
+
*/
|
|
10
|
+
import { pluginActionSpec } from "./actions.js";
|
|
11
|
+
import { CAMERA_MS, stepDwell, voiceMs } from "./pace.js";
|
|
12
|
+
import { streamPlan } from "./player.js";
|
|
13
|
+
/** 操作演示各段的时长(引擎毫秒)。 */
|
|
14
|
+
export const ACTION_TIMING = {
|
|
15
|
+
cursorMove: 550,
|
|
16
|
+
ripple: 260,
|
|
17
|
+
typeChar: 45,
|
|
18
|
+
selectHold: 420,
|
|
19
|
+
toggleHold: 200,
|
|
20
|
+
systemHold: 900,
|
|
21
|
+
/** 拖动、滚动,以及没有声明 durationMs 的插件动作。 */
|
|
22
|
+
gesture: 800,
|
|
23
|
+
afterStep: 300,
|
|
24
|
+
reducedStep: 450,
|
|
25
|
+
quickStep: 300,
|
|
26
|
+
/** 先切层 / 取景再移动鼠标:等新画面淡入、镜头到位。 */
|
|
27
|
+
layerSwitch: CAMERA_MS + 150,
|
|
28
|
+
};
|
|
29
|
+
/** 一步停留时要读的文字:说明、explain,过渡卡再加副标题与要点。 */
|
|
30
|
+
export function stepTexts(step) {
|
|
31
|
+
return [step.caption, step.explain, ...(step.action.type === 'card' ? [step.action.sub, ...(step.action.points ?? [])] : [])];
|
|
32
|
+
}
|
|
33
|
+
export function stepPlan(project, step, o = {}) {
|
|
34
|
+
const T = ACTION_TIMING;
|
|
35
|
+
const a = step.action;
|
|
36
|
+
const reduced = !!o.reduced;
|
|
37
|
+
const cursor = o.cursor !== false;
|
|
38
|
+
let cursorMs = 0, rippleMs = 0, gestureMs = 0;
|
|
39
|
+
if (a.type === 'card') {
|
|
40
|
+
// 过渡卡:直接提交,停留由 dwell 负责
|
|
41
|
+
}
|
|
42
|
+
else if (a.type === 'press')
|
|
43
|
+
gestureMs = reduced ? T.reducedStep : T.selectHold;
|
|
44
|
+
else if (step.kind === 'system' || a.type === 'event')
|
|
45
|
+
gestureMs = reduced ? T.reducedStep : T.systemHold;
|
|
46
|
+
else if (reduced)
|
|
47
|
+
gestureMs = T.reducedStep;
|
|
48
|
+
else if ('target' in a) {
|
|
49
|
+
cursorMs = cursor ? T.cursorMove : 0;
|
|
50
|
+
rippleMs = T.ripple;
|
|
51
|
+
if (a.type === 'drag' || a.type === 'scroll')
|
|
52
|
+
gestureMs = T.gesture;
|
|
53
|
+
else if (a.type === 'hover')
|
|
54
|
+
gestureMs = a.ms;
|
|
55
|
+
else if (a.type === 'plugin')
|
|
56
|
+
gestureMs = pluginActionSpec(project, a.name)?.durationMs ?? T.gesture;
|
|
57
|
+
else if (a.type === 'type')
|
|
58
|
+
gestureMs = [...a.value].length * T.typeChar;
|
|
59
|
+
else if (a.type === 'select')
|
|
60
|
+
gestureMs = T.selectHold;
|
|
61
|
+
else if (a.type === 'toggle')
|
|
62
|
+
gestureMs = T.toggleHold;
|
|
63
|
+
}
|
|
64
|
+
else
|
|
65
|
+
rippleMs = T.ripple;
|
|
66
|
+
const settleMs = cursor && !reduced ? T.afterStep : 0;
|
|
67
|
+
const streamMs = o.streamMs ?? Math.max(0, ...streamPlan(step, null).map((x) => x.ms));
|
|
68
|
+
const read = reduced
|
|
69
|
+
? T.reducedStep
|
|
70
|
+
: stepDwell({ texts: o.texts ?? stepTexts(step), paced: step.hold !== undefined, cameraMoved: step.shots.length > 0 || !!step.directorLayer, streamMs });
|
|
71
|
+
// hold 是看的时间,不是动画:减少动态效果时同样保留
|
|
72
|
+
const dwellMs = Math.max(step.hold ?? 0, step.effectHold ?? 0, read, settleMs);
|
|
73
|
+
const voice = voiceMs(step.narrate ?? step.say);
|
|
74
|
+
const leadMs = cursorMs + rippleMs + gestureMs;
|
|
75
|
+
return { cursorMs, rippleMs, gestureMs, leadMs, settleMs, dwellMs, voiceMs: voice, totalMs: leadMs + Math.max(dwellMs, voice) };
|
|
76
|
+
}
|
|
77
|
+
/** 一个场景按 1× 自动播放大约多久(毫秒):每一步 stepPlan 的合计之和。 */
|
|
78
|
+
export function scenarioPlanMs(project, steps, texts) {
|
|
79
|
+
return steps.reduce((sum, step) => sum + stepPlan(project, step, texts ? { texts: texts(step) } : {}).totalMs, 0);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 两次提交之间的时间(引擎毫秒,1×):第 index 步(0 起;-1 = 场景开始)提交之后,到下一步提交(最后一步之后 = 到场景播完)。
|
|
83
|
+
* 配乐快照按它推进:快照记录的是每一步提交那一刻的状态。
|
|
84
|
+
*/
|
|
85
|
+
export function commitGapMs(project, steps, index) {
|
|
86
|
+
const prev = index >= 0 ? steps[index] : undefined;
|
|
87
|
+
const next = steps[index + 1];
|
|
88
|
+
const after = prev ? (() => { const p = stepPlan(project, prev); return Math.max(p.dwellMs, p.voiceMs); })() : 0;
|
|
89
|
+
return after + (next ? stepPlan(project, next).leadMs : 0);
|
|
90
|
+
}
|
package/dist/traits.d.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { ElementTraits } from '@joplo-app/kit/plugin';
|
|
3
3
|
export declare const ElementTraitsSchema: z.ZodType<ElementTraits>;
|
|
4
|
+
/** 给人看的文字(看板用):英文,或带 en 的「语言 → 文字」。 */
|
|
5
|
+
export declare const PluginTextSchema: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>;
|
|
6
|
+
export declare const PluginInspectFieldSchema: z.ZodObject<{
|
|
7
|
+
label: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>;
|
|
8
|
+
props: z.ZodArray<z.ZodString>;
|
|
9
|
+
join: z.ZodOptional<z.ZodString>;
|
|
10
|
+
values: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>>;
|
|
11
|
+
flags: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>>;
|
|
12
|
+
fallback: z.ZodOptional<z.ZodString>;
|
|
13
|
+
}, z.core.$strict>;
|
|
4
14
|
export declare const InheritSchema: z.ZodArray<z.ZodObject<{
|
|
5
15
|
target: z.ZodString;
|
|
6
16
|
props: z.ZodArray<z.ZodString>;
|
package/dist/traits.js
CHANGED
|
@@ -23,4 +23,7 @@ export const ElementTraitsSchema = z.strictObject({
|
|
|
23
23
|
text: z.array(key).optional(),
|
|
24
24
|
textPaths: z.array(keys).optional(),
|
|
25
25
|
});
|
|
26
|
+
/** 给人看的文字(看板用):英文,或带 en 的「语言 → 文字」。 */
|
|
27
|
+
export const PluginTextSchema = z.union([z.string().min(1), z.record(z.string(), z.string().min(1)).refine((v) => typeof v.en === 'string', 'needs an en text')]);
|
|
28
|
+
export const PluginInspectFieldSchema = z.strictObject({ label: PluginTextSchema, props: z.array(z.string().min(1)).min(1), join: z.string().optional(), values: z.record(z.string(), PluginTextSchema).optional(), flags: z.record(z.string(), PluginTextSchema).optional(), fallback: z.string().optional() });
|
|
26
29
|
export const InheritSchema = z.array(z.strictObject({ target: key, props: keys }));
|
package/dist/validate.d.ts
CHANGED