@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/compile.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { rolesOf, INTERNAL_BLANK_TITLE } from "./entries.js";
|
|
2
|
+
import { validateWork } from "./authoring-works.js";
|
|
3
|
+
import { resolveSlices } from "./sequencing.js";
|
|
1
4
|
import { validActionData, pluginActionSpec } from "./actions.js";
|
|
2
5
|
/**
|
|
3
|
-
* 编译:作者的源文件(经 @joplo-app/kit 收集成数据)→ IR
|
|
6
|
+
* 编译:作者的源文件(经 @joplo-app/kit 收集成数据)→ IR v3。组件词汇对齐 Mantine(D35),见 catalog.ts。
|
|
4
7
|
*
|
|
5
8
|
* 路径优先的堆叠(D28):画面 = 布局 + 页面 + 各功能方案填入插槽的元素。
|
|
6
9
|
* - dev 模式:每个方案在每个路径上各有一个画面 `<方案>@<路径>`,其中其他功能取选定方案,本功能取该方案;
|
|
@@ -8,10 +11,10 @@ import { validActionData, pluginActionSpec } from "./actions.js";
|
|
|
8
11
|
* - publish 模式:只有发布视图;只含选定方案的场景;去掉规则、情况、问题等创作侧信息(D33)。
|
|
9
12
|
* - review 模式(评审版,D63):画面与场景同 dev(所有功能的所有方案),创作侧信息按 publish 的规则去掉。
|
|
10
13
|
*/
|
|
11
|
-
import { isBind, isNode, bindPath, toCondition } from '@joplo-app/kit/node';
|
|
14
|
+
import { createNode, isBind, isNode, bindPath, toCondition } from '@joplo-app/kit/node';
|
|
12
15
|
import { BUILTIN_THEMES, COMPONENT_TYPES, DIRECTOR_LAYER, PAGE_LAYER, isInteractiveType, matchChoice, nodeLabel, pluginSpec, splitPluginType } from "./catalog.js";
|
|
13
16
|
import { HOLD_MAX_SECONDS, HOLD_MIN_SECONDS, inShotFrame } from "./focus.js";
|
|
14
|
-
import {
|
|
17
|
+
import { cameraOf, choicesOf, commonPrefix, replayTo } from "./player.js";
|
|
15
18
|
import { Action, Effect, CALLOUT_SIDES, LAYER_ICONS, Project, SCHEMA_VERSION } from "./schema.js";
|
|
16
19
|
import { schemaDiagnostics } from "./schema-issues.js";
|
|
17
20
|
import { CONTENT_LOCALES, collectMessages, isContentLocale, nearestKey, pruneMessages } from "./content-i18n.js";
|
|
@@ -22,7 +25,7 @@ const OVERLAY = 'overlay';
|
|
|
22
25
|
const MOCK_LABEL = { success: 'Mock success', failure: 'Mock failure', denied: 'Mock permission denied', other: 'Mock' };
|
|
23
26
|
export function compile(src, mode, opts = {}) {
|
|
24
27
|
/** 所有方案都参与(dev、review);创作侧信息要去掉(publish、review)。 */
|
|
25
|
-
const
|
|
28
|
+
const allWorksIncluded = mode !== 'publish';
|
|
26
29
|
const strip = mode !== 'dev';
|
|
27
30
|
const diags = [];
|
|
28
31
|
const rel = (s) => (s ? relSource(src.root, s) : undefined);
|
|
@@ -39,6 +42,31 @@ export function compile(src, mode, opts = {}) {
|
|
|
39
42
|
seenHints.add(key);
|
|
40
43
|
diags.push({ severity, code, message, source: 'structure', ...(at ? { at: rel(at) } : {}) });
|
|
41
44
|
};
|
|
45
|
+
const works = new Map(Object.entries(src.works ?? {}).filter(([key, def]) => {
|
|
46
|
+
if (Object.hasOwn(src.features, key)) {
|
|
47
|
+
report('WORK_ID_CONFLICT', `Work ${key} conflicts with features/${key}; rename the work file or the feature directory`, def?.source);
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
if (mode !== 'dev' && def?.kind === 'work' && def.draft === true) {
|
|
51
|
+
report('WORK_DRAFT_SKIPPED', `Draft work "${def.title}" was skipped; remove draft: true when it is ready to publish or review`, def.source, 'info');
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
if (!validateWork(key, def, false, report, Object.keys(src.routes).length > 0))
|
|
55
|
+
return false;
|
|
56
|
+
if (!Object.keys(def.scenarios).length) {
|
|
57
|
+
report('WORK_EMPTY', `Work "${def.title}" has no slices${mode === 'dev' ? '' : ' and was not published or reviewed'}. Add scenarios: { opening: chapter('Opening').system('Begin', narrate('Your opening line')) }`, def.source, 'info');
|
|
58
|
+
if (mode !== 'dev')
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
}));
|
|
63
|
+
for (const [fid, feature] of Object.entries(src.features))
|
|
64
|
+
for (const [key, def] of Object.entries(feature.works))
|
|
65
|
+
validateWork(`${fid}.${key}`, def, true, report, Object.keys(src.routes).length > 0);
|
|
66
|
+
const localOnly = (fid) => works.has(fid) && (works.get(fid).draft === true || !Object.keys(works.get(fid).scenarios).length);
|
|
67
|
+
const isolated = (fid) => works.has(fid) && works.get(fid).on === undefined && works.get(fid).routes === undefined;
|
|
68
|
+
if (diags.some(d => d.severity === 'error'))
|
|
69
|
+
return { project: null, diagnostics: diags };
|
|
42
70
|
/** flow({ from }) 接力:所有场景编译完后,按回放结果替换初始状态(见文末)。 */
|
|
43
71
|
const pendingFrom = new Map();
|
|
44
72
|
const out = {
|
|
@@ -54,9 +82,9 @@ export function compile(src, mode, opts = {}) {
|
|
|
54
82
|
mode,
|
|
55
83
|
routes: {},
|
|
56
84
|
features: {},
|
|
57
|
-
|
|
85
|
+
entryIds: [],
|
|
58
86
|
cases: {},
|
|
59
|
-
|
|
87
|
+
works: {},
|
|
60
88
|
rules: {},
|
|
61
89
|
scenes: {},
|
|
62
90
|
scenarios: {},
|
|
@@ -70,53 +98,76 @@ export function compile(src, mode, opts = {}) {
|
|
|
70
98
|
const nodeCtx = { plugins, host, report, rel };
|
|
71
99
|
// ---------- 1. 选出参与的方案 ----------
|
|
72
100
|
// 排序只在编译时决定;显式列表不依赖对象键的枚举顺序,发布模式也保留这份演示内容。
|
|
73
|
-
for (const [
|
|
74
|
-
if (
|
|
75
|
-
err('FEATURE_ORDER_INVALID',
|
|
101
|
+
for (const [id, def] of [...Object.entries(src.features).map(([id, f]) => [id, f.def]), ...works]) {
|
|
102
|
+
if (def.order !== undefined && (typeof def.order !== 'number' || !Number.isFinite(def.order)))
|
|
103
|
+
err(works.has(id) ? 'WORK_INVALID' : 'FEATURE_ORDER_INVALID', `${works.has(id) ? 'Work' : 'Feature'} ${id} order must be a finite number; omit it for folder-name order`, def.source ?? `${def.file}:1:1`, { kind: works.has(id) ? 'work' : 'feature', id });
|
|
76
104
|
}
|
|
77
105
|
if (diags.some(d => d.severity === 'error'))
|
|
78
106
|
return { project: null, diagnostics: diags };
|
|
79
107
|
const natural = new Intl.Collator('en', { numeric: true });
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
const picked = new Map();
|
|
86
|
-
for (const
|
|
87
|
-
|
|
88
|
-
|
|
108
|
+
const entryOrder = [...Object.entries(src.features).map(([id, f]) => [id, f.def.order]), ...[...works].map(([id, w]) => [id, w.order])]
|
|
109
|
+
.sort(([a, ao = Infinity], [b, bo = Infinity]) => ao !== bo ? ao - bo : natural.compare(a, b)).map(([id]) => id);
|
|
110
|
+
const features = entryOrder.flatMap(id => src.features[id] ? [[id, src.features[id]]] : []);
|
|
111
|
+
const linearWorks = new Set();
|
|
112
|
+
const allWorks = [];
|
|
113
|
+
const picked = new Map();
|
|
114
|
+
for (const id of entryOrder) {
|
|
115
|
+
const f = src.features[id];
|
|
116
|
+
const definitions = f ? sortedEntries(f.works) : [[id, works.get(id)]];
|
|
117
|
+
for (const [key, raw] of definitions) {
|
|
118
|
+
const qid = f ? `${id}.${key}` : key;
|
|
119
|
+
const slices = resolveSlices(raw.scenarios, `Work ${qid}`, err);
|
|
120
|
+
if (slices.linear)
|
|
121
|
+
linearWorks.add(qid);
|
|
122
|
+
const def = { ...raw, scenarios: slices.scenarios, ...(raw.stage !== undefined ? { layers: { stage: { kind: 'layer', title: raw.title, tree: raw.stage, viewport: raw.viewport, source: raw.source } } } : {}) };
|
|
123
|
+
allWorks.push({ fid: id, key, qid, def });
|
|
124
|
+
}
|
|
125
|
+
if (!f) {
|
|
126
|
+
picked.set(id, allWorks.at(-1));
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
89
129
|
const pick = f.def.pick ?? null;
|
|
90
130
|
if (pick) {
|
|
91
|
-
const
|
|
92
|
-
if (
|
|
93
|
-
picked.set(
|
|
131
|
+
const w = allWorks.find(x => x.fid === id && x.key === pick);
|
|
132
|
+
if (w)
|
|
133
|
+
picked.set(id, w);
|
|
94
134
|
else
|
|
95
|
-
err('UNKNOWN_PICK', `Feature ${
|
|
135
|
+
err('UNKNOWN_PICK', `Feature ${id} pick "${pick}" is not a work under works/`, f.def.source);
|
|
96
136
|
}
|
|
97
137
|
else if (mode === 'publish')
|
|
98
|
-
warn('NOT_PICKED', `Feature "${f.def.name}" has no picked
|
|
138
|
+
warn('NOT_PICKED', `Feature "${f.def.name}" has no picked alternative and will not be published`, f.def.source);
|
|
99
139
|
}
|
|
100
|
-
const included =
|
|
140
|
+
const included = allWorksIncluded ? allWorks : [...picked.values()];
|
|
141
|
+
out.entryIds = entryOrder.filter(id => mode !== 'publish' || picked.has(id));
|
|
101
142
|
const baseRoutes = new Map();
|
|
102
143
|
for (const [path, p] of sortedEntries(src.routes))
|
|
103
144
|
baseRoutes.set(path, { path, page: p });
|
|
104
145
|
const addedRoutes = new Map(); // `${qid}|${path}`
|
|
105
|
-
for (const o of
|
|
146
|
+
for (const o of allWorks) {
|
|
106
147
|
for (const [path, p] of Object.entries(o.def.routes ?? {})) {
|
|
107
148
|
if (!path.startsWith('/'))
|
|
108
149
|
err('BAD_ROUTE', `Route must start with /: ${path}`, o.def.source);
|
|
109
150
|
if (baseRoutes.has(path))
|
|
110
|
-
err('ROUTE_EXISTS', `
|
|
151
|
+
err('ROUTE_EXISTS', `Work ${o.qid} adds route ${path} which already exists in routes/; use on to add elements instead`, p.source ?? o.def.source);
|
|
111
152
|
addedRoutes.set(`${o.qid}|${path}`, { path, page: { ...p, file: o.def.file }, addedBy: o });
|
|
112
153
|
}
|
|
113
154
|
}
|
|
155
|
+
// 只使用 stage / layers 的独立作品从空白画面开始;写了 on / routes 就复用项目页面。
|
|
156
|
+
// IR 的页面标题与画面名要求非空字符串;纯空白保持无可见文字,也不会成为作者翻译项。
|
|
157
|
+
const blankRoute = { path: '/', page: { kind: 'page', title: INTERNAL_BLANK_TITLE, layout: false, tree: createNode('#fragment', {}), file: '' } };
|
|
158
|
+
const hasAddedRoot = [...addedRoutes.values()].some(r => r.path === '/' && !localOnly(r.addedBy.fid) && included.some(o => o.qid === r.addedBy.qid));
|
|
159
|
+
if ((works.size || !baseRoutes.size && !addedRoutes.size) && !baseRoutes.has('/') && !hasAddedRoot)
|
|
160
|
+
baseRoutes.set('/', blankRoute);
|
|
114
161
|
/** 在给定方案上下文(null = 发布视图)中可见的路径。 */
|
|
115
162
|
const routesIn = (ctx) => {
|
|
163
|
+
if (ctx && isolated(ctx.fid))
|
|
164
|
+
return [blankRoute];
|
|
116
165
|
const added = [...addedRoutes.values()].filter((r) => {
|
|
117
166
|
const by = r.addedBy;
|
|
118
167
|
if (ctx && by.qid === ctx.qid)
|
|
119
168
|
return true;
|
|
169
|
+
if (localOnly(by.fid))
|
|
170
|
+
return false;
|
|
120
171
|
if (ctx && by.fid === ctx.fid)
|
|
121
172
|
return false; // 同功能的其他方案
|
|
122
173
|
return picked.get(by.fid)?.qid === by.qid;
|
|
@@ -148,22 +199,22 @@ export function compile(src, mode, opts = {}) {
|
|
|
148
199
|
const fdef = f.def;
|
|
149
200
|
if (mode === 'publish' && !picked.has(fid))
|
|
150
201
|
continue;
|
|
151
|
-
|
|
152
|
-
const caseIds = Object.keys(fdef.cases ?? {}).map((k) => `${fid}.${k}`);
|
|
202
|
+
const caseIds = Object.keys(fdef?.cases ?? {}).map((k) => `${fid}.${k}`);
|
|
153
203
|
out.features[fid] = {
|
|
154
204
|
id: fid,
|
|
155
205
|
name: fdef.name,
|
|
156
206
|
goal: fdef.goal,
|
|
157
|
-
roles:
|
|
207
|
+
roles: compileRoles(fdef.roles),
|
|
158
208
|
constraints: Object.entries(fdef.constraints ?? {}).map(([id, c]) => (typeof c === 'string' ? { id, text: c, hard: true } : { id, text: c.text, hard: c.hard ?? true })),
|
|
159
209
|
caseIds: strip ? [] : caseIds,
|
|
160
|
-
|
|
210
|
+
workIds: included.filter((o) => o.fid === fid).map((o) => o.qid),
|
|
161
211
|
pick: picked.get(fid)?.qid ?? null,
|
|
212
|
+
alternatives: {},
|
|
162
213
|
...(fdef.source ? { source: rel(fdef.source) } : {}),
|
|
163
214
|
};
|
|
164
215
|
if (strip)
|
|
165
216
|
continue;
|
|
166
|
-
for (const [k, c] of Object.entries(fdef
|
|
217
|
+
for (const [k, c] of Object.entries(fdef?.cases ?? {}))
|
|
167
218
|
out.cases[`${fid}.${k}`] = caseOf(`${fid}.${k}`, fid, c, rel(fdef.source));
|
|
168
219
|
for (const [k, r] of Object.entries(fdef.rules ?? {}))
|
|
169
220
|
out.rules[`${fid}.${k}`] = ruleOf(`${fid}.${k}`, fid, undefined, r, rel);
|
|
@@ -172,7 +223,9 @@ export function compile(src, mode, opts = {}) {
|
|
|
172
223
|
}
|
|
173
224
|
// ---------- 4. 画面合成 ----------
|
|
174
225
|
const contributionsFor = (ctx) => {
|
|
175
|
-
|
|
226
|
+
if (ctx && isolated(ctx.fid))
|
|
227
|
+
return [ctx];
|
|
228
|
+
const list = [...picked.values()].filter((o) => !localOnly(o.fid) && (!ctx || o.fid !== ctx.fid));
|
|
176
229
|
if (ctx)
|
|
177
230
|
list.push(ctx);
|
|
178
231
|
return list;
|
|
@@ -205,9 +258,9 @@ export function compile(src, mode, opts = {}) {
|
|
|
205
258
|
for (const slot of contribs.keys()) {
|
|
206
259
|
if (!used.has(slot)) {
|
|
207
260
|
const from = contribs.get(slot)[0].from;
|
|
208
|
-
const o =
|
|
209
|
-
err('UNKNOWN_SLOT', `
|
|
210
|
-
kind: '
|
|
261
|
+
const o = allWorks.find((x) => x.qid === from);
|
|
262
|
+
err('UNKNOWN_SLOT', `Work ${from} adds elements to route ${route.path} slot "${slot}", but the page and layout have no <Slot name="${slot}" />`, o?.def.source, {
|
|
263
|
+
kind: 'work',
|
|
211
264
|
id: from,
|
|
212
265
|
});
|
|
213
266
|
}
|
|
@@ -216,7 +269,7 @@ export function compile(src, mode, opts = {}) {
|
|
|
216
269
|
const rootJ = { ...base, type: base.type, children: [...base.children, ...overlays] };
|
|
217
270
|
const ids = new Map();
|
|
218
271
|
const root = toSceneNode(rootJ, 'root', ids, nodeCtx, null);
|
|
219
|
-
const scene = { id: sceneId,
|
|
272
|
+
const scene = { id: sceneId, workId: ctx?.qid ?? null, route: route.path, name: `${page.title}${ctx ? ` · ${ctx.def.title}` : ''}`, viewport: page.viewport ?? 'desktop', root };
|
|
220
273
|
if (!diags.some(d => d.severity === 'error'))
|
|
221
274
|
host.derive(scene);
|
|
222
275
|
return scene;
|
|
@@ -242,40 +295,44 @@ export function compile(src, mode, opts = {}) {
|
|
|
242
295
|
};
|
|
243
296
|
for (const r of routesIn(null))
|
|
244
297
|
addScene(composeScene(r, null));
|
|
245
|
-
|
|
246
|
-
|
|
298
|
+
for (const o of included)
|
|
299
|
+
if (allWorksIncluded || works.has(o.fid))
|
|
247
300
|
for (const r of routesIn(o))
|
|
248
301
|
addScene(composeScene(r, o));
|
|
249
302
|
// ---------- 5. 方案、场景、覆盖 ----------
|
|
250
303
|
for (const o of included) {
|
|
251
304
|
const { def, fid, qid } = o;
|
|
252
|
-
const fdef = src.features[fid]
|
|
305
|
+
const fdef = src.features[fid]?.def;
|
|
306
|
+
const isStandalone = !fdef;
|
|
307
|
+
const isIsolated = isolated(fid);
|
|
253
308
|
const ctxRoutes = new Set(routesIn(o).map((r) => r.path));
|
|
254
309
|
const touched = [...Object.keys(def.on ?? {}), ...Object.keys(def.routes ?? {})];
|
|
255
310
|
for (const p of Object.keys(def.on ?? {}))
|
|
256
311
|
if (!ctxRoutes.has(p))
|
|
257
|
-
err('UNKNOWN_ROUTE', `
|
|
258
|
-
const sceneOf = (path) => (
|
|
312
|
+
err('UNKNOWN_ROUTE', `Work ${qid} adds elements to an unknown route ${p}`, def.source);
|
|
313
|
+
const sceneOf = (path) => (allWorksIncluded || isStandalone ? `${qid}@${path}` : `@${path}`);
|
|
259
314
|
if (mode === 'dev') {
|
|
260
315
|
for (const [k, r] of Object.entries(def.rules ?? {}))
|
|
261
316
|
out.rules[`${qid}.${k}`] = ruleOf(`${qid}.${k}`, fid, qid, r, rel);
|
|
262
317
|
for (const [k, q] of Object.entries(def.questions ?? {}))
|
|
263
|
-
out.issues[`${qid}.${k}`] = { id: `${qid}.${k}`, featureId: fid,
|
|
318
|
+
out.issues[`${qid}.${k}`] = { id: `${qid}.${k}`, featureId: fid, workId: qid, text: q.text, severity: q.severity, refs: q.refs, ...(q.source ? { source: rel(q.source) } : {}) };
|
|
264
319
|
}
|
|
265
320
|
const ruleQid = (key, at) => {
|
|
266
321
|
if (def.rules?.[key])
|
|
267
322
|
return `${qid}.${key}`;
|
|
268
|
-
if (fdef
|
|
323
|
+
if (fdef?.rules?.[key])
|
|
269
324
|
return `${fid}.${key}`;
|
|
270
|
-
err('UNKNOWN_RULE', `uses("${key}") references an unknown rule (use a key from
|
|
325
|
+
err('UNKNOWN_RULE', `uses("${key}") references an unknown rule (use a key from work.rules or feature.rules)`, at);
|
|
271
326
|
return null;
|
|
272
327
|
};
|
|
273
328
|
/** 可被引用的角色键(D56):feature.roles 写成 { 键: role('名字') } 时才有。 */
|
|
274
|
-
|
|
329
|
+
out.works[qid] = { id: qid, ...(fdef ? { featureId: fid } : {}), roles: fdef ? [] : compileRoles(def.roles) };
|
|
330
|
+
const roleScope = isStandalone ? 'work.roles' : 'feature.roles';
|
|
331
|
+
const roleKeys = new Set(rolesOf(out, qid).flatMap(r => r.id ? [r.id] : []));
|
|
275
332
|
// ---------- 层级(T-layers):每层一个完全独立的画面,单独编译、单独渲染 ----------
|
|
276
333
|
const layers = {};
|
|
277
334
|
const layerScenes = [];
|
|
278
|
-
const layerRoute = touched.find((r) => ctxRoutes.has(r)) ?? src.config.home ?? [...ctxRoutes][0] ?? '/';
|
|
335
|
+
const layerRoute = isIsolated ? '/' : touched.find((r) => ctxRoutes.has(r)) ?? src.config.home ?? [...ctxRoutes][0] ?? '/';
|
|
279
336
|
for (const [lk, ld] of Object.entries(def.layers ?? {})) {
|
|
280
337
|
const at = ld.source ?? def.source;
|
|
281
338
|
if (!/^[A-Za-z_][\w-]*$/.test(lk)) {
|
|
@@ -292,13 +349,13 @@ export function compile(src, mode, opts = {}) {
|
|
|
292
349
|
const ids = new Map();
|
|
293
350
|
const root = toSceneNode(rootJ, `layer_${lk}`, ids, nodeCtx, null);
|
|
294
351
|
const sceneId = `${qid}~${lk}`;
|
|
295
|
-
const scene = { id: sceneId,
|
|
352
|
+
const scene = { id: sceneId, workId: qid, route: layerRoute, name: `${ld.title} · ${def.title}`, viewport: ld.viewport ?? 'desktop', root, layer: lk };
|
|
296
353
|
if (!diags.some(d => d.severity === 'error'))
|
|
297
354
|
host.derive(scene);
|
|
298
355
|
addScene(scene);
|
|
299
356
|
layerScenes.push({ key: lk, scene });
|
|
300
357
|
if (ld.role !== undefined && !roleKeys.has(ld.role))
|
|
301
|
-
err('ROLE_UNKNOWN', `Layer "${ld.title}" role "${ld.role}" is not in
|
|
358
|
+
err('ROLE_UNKNOWN', `Layer "${ld.title}" role "${ld.role}" is not in ${roleScope}${roleKeys.size ? ` (available: ${[...roleKeys].join(', ')})` : ` (${roleScope} must use { key: role('Name') })`}`, at);
|
|
302
359
|
const icon = ld.icon;
|
|
303
360
|
const iconOk = icon !== undefined && LAYER_ICONS.includes(icon);
|
|
304
361
|
if (icon !== undefined && !iconOk)
|
|
@@ -309,7 +366,7 @@ export function compile(src, mode, opts = {}) {
|
|
|
309
366
|
/** 元素在哪些层级里(多层都有同名 id 时都算)。 */
|
|
310
367
|
const layersWith = (id) => layerScenes.filter((l) => findIn(l.scene.root, id)).map((l) => l.key);
|
|
311
368
|
const layerSceneWith = (id) => layerScenes.find((l) => findIn(l.scene.root, id))?.scene;
|
|
312
|
-
const effectRoots = [...layerScenes.map(l => l.scene), ...[...sceneFor.values()].filter(x => x.
|
|
369
|
+
const effectRoots = [...layerScenes.map(l => l.scene), ...[...sceneFor.values()].filter(x => x.workId === qid || !isIsolated && x.workId == null)];
|
|
313
370
|
const scenarioIds = {};
|
|
314
371
|
// flow({ from }) 接力:按依赖顺序编译,被接的场景先编译,记下它结尾的路径与导演层;
|
|
315
372
|
// 接力场景的逐步校验(页面里找目标、焦点提示、镜头、自动字幕)都从那里开始,而不是默认起点
|
|
@@ -338,13 +395,13 @@ export function compile(src, mode, opts = {}) {
|
|
|
338
395
|
const fromEnd = fl.opts.from !== undefined && fl.opts.from !== skey ? scenarioEnd.get(fl.opts.from) : undefined;
|
|
339
396
|
if (fl.opts.from !== undefined && fl.opts.start !== undefined)
|
|
340
397
|
err('FROM_WITH_START', `flow({ from: ${JSON.stringify(fl.opts.from)}, start: ${JSON.stringify(fl.opts.start)} }): a scenario that continues another starts where that one ended; remove start (or remove from to start fresh)`, fl.source);
|
|
341
|
-
const start = fromEnd?.route ?? fl.opts.start ?? touched[0] ?? src.config.home ?? [...ctxRoutes][0];
|
|
398
|
+
const start = fromEnd?.route ?? fl.opts.start ?? (isIsolated ? '/' : touched[0] ?? src.config.home ?? [...ctxRoutes][0]);
|
|
342
399
|
if (!start || !ctxRoutes.has(start)) {
|
|
343
400
|
err('UNKNOWN_ROUTE', `Scenario ${sid} starts at unknown route ${start ?? '(none)'}`, fl.source);
|
|
344
401
|
continue;
|
|
345
402
|
}
|
|
346
403
|
for (const c of fl.opts.cases ?? []) {
|
|
347
|
-
if (!fdef
|
|
404
|
+
if (!fdef?.cases?.[c])
|
|
348
405
|
err('UNKNOWN_CASE', `Scenario ${sid} covers case "${c}", which is not in feature.cases`, fl.source);
|
|
349
406
|
else
|
|
350
407
|
(scenarioIds[c] ??= []).push(sid);
|
|
@@ -354,280 +411,20 @@ export function compile(src, mode, opts = {}) {
|
|
|
354
411
|
let director = fromEnd?.director ?? (hasLayers ? Object.keys(layers)[0] : PAGE_LAYER);
|
|
355
412
|
if (fl.opts.layer !== undefined) {
|
|
356
413
|
if (!hasLayers || !Object.hasOwn(layers, fl.opts.layer))
|
|
357
|
-
err('LAYER_UNKNOWN', `flow({ layer: ${JSON.stringify(fl.opts.layer)} }) is not a layer of
|
|
414
|
+
err('LAYER_UNKNOWN', `flow({ layer: ${JSON.stringify(fl.opts.layer)} }) is not a layer of work ${qid}${hasLayers ? ` (layers: ${Object.keys(layers).join(', ')})` : '; this work declares no layers'}`, fl.source);
|
|
358
415
|
else
|
|
359
416
|
director = fl.opts.layer;
|
|
360
417
|
}
|
|
361
418
|
if (fl.opts.from !== undefined) {
|
|
362
419
|
if (!Object.hasOwn(def.scenarios ?? {}, fl.opts.from) || fl.opts.from === skey)
|
|
363
|
-
err('FROM_UNKNOWN', `flow({ from: ${JSON.stringify(fl.opts.from)} }) must name another scenario key of
|
|
420
|
+
err('FROM_UNKNOWN', isStandalone || linearWorks.has(qid) ? `${linearWorks.has(qid) ? `Chapter ${String(Object.keys(scenarioDefs).indexOf(skey) + 1).padStart(2, '0')}` : `Slice ${skey}`} of ${isStandalone ? `work ${fid}` : `work ${qid}`}: from ${JSON.stringify(fl.opts.from)} must name another slice key (available slices: ${Object.keys(scenarioDefs).join(', ') || 'none'})` : `flow({ from: ${JSON.stringify(fl.opts.from)} }) must name another scenario key of work ${qid} (available: ${Object.keys(def.scenarios ?? {}).filter((k) => k !== skey).join(', ') || 'none'})`, fl.source);
|
|
364
421
|
else
|
|
365
422
|
pendingFrom.set(sid, { from: `${qid}.${fl.opts.from}`, state: fl.opts.state, layer: fl.opts.layer, at: fl.source });
|
|
366
423
|
}
|
|
367
424
|
const stepKeys = new Set();
|
|
368
|
-
const
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
err('STEP_KEY_INVALID', 'Step key must start with a letter and contain at most 64 letters, digits, underscores or hyphens', st.source);
|
|
372
|
-
if (stepKeys.has(st.key))
|
|
373
|
-
err('STEP_KEY_DUPLICATE', `Duplicate step key ${st.key} in ${sid}; use a distinct key for each action`, st.source);
|
|
374
|
-
stepKeys.add(st.key);
|
|
375
|
-
}
|
|
376
|
-
const effects = [];
|
|
377
|
-
const ruleIds = [];
|
|
378
|
-
const explains = [];
|
|
379
|
-
const says = [];
|
|
380
|
-
let sayRole = null;
|
|
381
|
-
const narrates = [];
|
|
382
|
-
/** 插件效果声明的最短停留(D98):同一步取最大值。 */
|
|
383
|
-
let effectHoldMs = 0;
|
|
384
|
-
const ext = {};
|
|
385
|
-
const references = [];
|
|
386
|
-
const pluginFocus = [];
|
|
387
|
-
const directorTargets = [];
|
|
388
|
-
const forks = [];
|
|
389
|
-
const marks = [];
|
|
390
|
-
/** 每个插件效果贡献的节点(作为镜头目标,与 shot 合并)。 */
|
|
391
|
-
const pluginTargets = new Map();
|
|
392
|
-
for (const e of st.effects) {
|
|
393
|
-
if (e.type === 'go') {
|
|
394
|
-
if (!ctxRoutes.has(e.route))
|
|
395
|
-
err('UNKNOWN_ROUTE', `go("${e.route}") navigates to an unknown route`, st.source);
|
|
396
|
-
effects.push({ type: 'navigate', sceneId: sceneOf(e.route) });
|
|
397
|
-
}
|
|
398
|
-
else if (e.type === 'uses') {
|
|
399
|
-
for (const r of e.rules) {
|
|
400
|
-
const q = ruleQid(r, st.source);
|
|
401
|
-
if (q)
|
|
402
|
-
ruleIds.push(q);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
else if (e.type === 'set' || e.type === 'append')
|
|
406
|
-
effects.push({ type: e.type, path: e.path, value: e.value });
|
|
407
|
-
else if (e.type === 'stream') {
|
|
408
|
-
if (e.pace !== undefined && e.pace !== 'voice')
|
|
409
|
-
err('STREAM_PACE_INVALID', `stream() pace must be 'voice' (got ${JSON.stringify(e.pace)}); omit it to stream at model-output speed`, st.source);
|
|
410
|
-
effects.push({ type: 'stream', path: e.path, value: e.value, ...(e.pace === 'voice' ? { pace: 'voice' } : {}) });
|
|
411
|
-
}
|
|
412
|
-
else if (e.type === 'toast')
|
|
413
|
-
effects.push({ type: 'toast', text: e.text, tone: e.tone });
|
|
414
|
-
else if (e.type === 'shot' || e.type === 'mark' || e.type === 'fork' || e.type === 'cue' || e.type === 'callout' || e.type === 'hold')
|
|
415
|
-
continue; // 镜头与焦点提示不是状态变化,下面单独归类
|
|
416
|
-
else if (e.type === 'say') {
|
|
417
|
-
if (e.role !== undefined) {
|
|
418
|
-
if (typeof e.role !== 'string' || !roleKeys.has(e.role))
|
|
419
|
-
err('ROLE_UNKNOWN', `say() role "${String(e.role)}" is not in feature.roles${roleKeys.size ? ` (available: ${[...roleKeys].join(', ')})` : ' (feature.roles must use { key: role(\'Name\') })'}`, st.source);
|
|
420
|
-
else if (sayRole !== null && sayRole !== e.role)
|
|
421
|
-
err('SAY_ROLE_CONFLICT', `One step has say() lines from two roles ("${sayRole}" and "${e.role}"); split them into two steps`, st.source);
|
|
422
|
-
else
|
|
423
|
-
sayRole = e.role;
|
|
424
|
-
}
|
|
425
|
-
if (typeof e.text === 'string' && e.text.trim())
|
|
426
|
-
says.push(e.text.trim());
|
|
427
|
-
else
|
|
428
|
-
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);
|
|
429
|
-
}
|
|
430
|
-
else if (e.type === 'narrate') {
|
|
431
|
-
if (typeof e.text === 'string' && e.text.trim())
|
|
432
|
-
narrates.push(e.text.trim());
|
|
433
|
-
else
|
|
434
|
-
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);
|
|
435
|
-
}
|
|
436
|
-
else if (e.type === 'explain') {
|
|
437
|
-
if (e.text.trim())
|
|
438
|
-
explains.push(e.text.trim());
|
|
439
|
-
}
|
|
440
|
-
else if (e.type === 'plugin') {
|
|
441
|
-
const lowered = host.effect(e, effectRoots.filter(scene => scene.layer || scene.id === sceneOf(stepRouteBefore(fl.steps, i + 1, start))), ext[e.plugin], st.source);
|
|
442
|
-
if (lowered) {
|
|
443
|
-
effects.push(...(lowered.writes ?? []).map(w => ({ type: 'set', path: w.path, value: w.value })));
|
|
444
|
-
if (lowered.directorTarget)
|
|
445
|
-
directorTargets.push(lowered.directorTarget);
|
|
446
|
-
if (lowered.holdMs)
|
|
447
|
-
effectHoldMs = Math.max(effectHoldMs, lowered.holdMs);
|
|
448
|
-
if (lowered.media?.length) {
|
|
449
|
-
const key = `${sid}#${i + 1}`;
|
|
450
|
-
host.mediaCommands.set(key, [...(host.mediaCommands.get(key) ?? []), ...lowered.media]);
|
|
451
|
-
}
|
|
452
|
-
if (lowered.data !== undefined)
|
|
453
|
-
ext[e.plugin] = lowered.data;
|
|
454
|
-
if (lowered.targets?.length) {
|
|
455
|
-
pluginTargets.set(e, lowered.targets);
|
|
456
|
-
pluginFocus.push(...lowered.targets);
|
|
457
|
-
}
|
|
458
|
-
references.push(...lowered.references ?? []);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
else if (e.type === 'complete')
|
|
462
|
-
effects.push({ type: 'complete', text: e.text, outcome: e.outcome });
|
|
463
|
-
else
|
|
464
|
-
err('EFFECT_INVALID', 'Unknown step effect; use a documented effect helper instead of constructing effect objects', st.source);
|
|
465
|
-
}
|
|
466
|
-
const sceneBefore = sceneFor.get(sceneOf(stepRouteBefore(fl.steps, i, start)));
|
|
467
|
-
const sceneAfter = sceneFor.get(sceneOf(stepRouteBefore(fl.steps, i + 1, start)));
|
|
468
|
-
const actionTarget = 'target' in st.action ? st.action.target : null;
|
|
469
|
-
validateNewAction(st.action, hasLayers ? layerScenes.map(l => l.scene) : sceneBefore ? [sceneBefore] : [], out, (code, message) => err(code, message, st.source));
|
|
470
|
-
for (const e of st.effects) {
|
|
471
|
-
if (e.type === 'fork') {
|
|
472
|
-
if (!Object.hasOwn(def.scenarios, e.scenario) || e.scenario === skey)
|
|
473
|
-
err('FORK_UNKNOWN', `Fork target "${e.scenario}" must be another scenario key in the same option`, st.source);
|
|
474
|
-
else if (e.label.trim())
|
|
475
|
-
forks.push({ label: e.label.trim(), scenarioId: `${qid}.${e.scenario}`, at: 0 });
|
|
476
|
-
}
|
|
477
|
-
if (e.type === 'mark') {
|
|
478
|
-
const exists = hasLayers ? layersWith(e.target).length > 0 : !!sceneAfter && !!findIn(sceneAfter.root, e.target);
|
|
479
|
-
if (!exists)
|
|
480
|
-
err('MARK_UNKNOWN', `mark("${e.target}") target is not in ${hasLayers ? 'any layer' : 'the stage for this step'}`, st.source);
|
|
481
|
-
else
|
|
482
|
-
marks.push({ target: e.target, kind: e.kindOf, ...(e.note ? { note: e.note } : {}) });
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
// 焦点提示(D70):spotlight / highlight / numbered / callout / hold。目标与 mark 同样解析:有层级时在任一层,否则在这一步的路径页面
|
|
486
|
-
const focusLayers = (id) => (hasLayers ? layersWith(id) : sceneAfter && findIn(sceneAfter.root, id) ? [PAGE_LAYER] : []);
|
|
487
|
-
const where = hasLayers ? 'any layer' : 'the stage for this step';
|
|
488
|
-
const cueMap = new Map();
|
|
489
|
-
const callouts = [];
|
|
490
|
-
/** 焦点提示的目标(按效果顺序):决定导演层,并判断要不要退回整层镜头。 */
|
|
491
|
-
const focusTargets = [];
|
|
492
|
-
let holdMs;
|
|
493
|
-
const CUE_FN = { spotlight: 'spotlight', highlight: 'highlight', number: 'numbered' };
|
|
494
|
-
for (const e of st.effects) {
|
|
495
|
-
if (e.type === 'cue') {
|
|
496
|
-
const fn = CUE_FN[e.cue] ?? e.cue;
|
|
497
|
-
if (!e.targets.length)
|
|
498
|
-
err('FOCUS_UNKNOWN', `${fn}() requires at least one element id, for example ${fn}('quota_alert')`, st.source);
|
|
499
|
-
for (const id of e.targets) {
|
|
500
|
-
if (!focusLayers(id).length) {
|
|
501
|
-
err('FOCUS_UNKNOWN', `${fn}("${id}") target is not in ${where}`, st.source);
|
|
502
|
-
continue;
|
|
503
|
-
}
|
|
504
|
-
const list = cueMap.get(e.cue) ?? [];
|
|
505
|
-
if (!list.includes(id))
|
|
506
|
-
list.push(id);
|
|
507
|
-
cueMap.set(e.cue, list);
|
|
508
|
-
if (!focusTargets.includes(id))
|
|
509
|
-
focusTargets.push(id);
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
else if (e.type === 'callout') {
|
|
513
|
-
const text = typeof e.text === 'string' ? e.text.trim() : '';
|
|
514
|
-
if (!focusLayers(e.target).length)
|
|
515
|
-
err('FOCUS_UNKNOWN', `callout("${e.target}", …) target is not in ${where}`, st.source);
|
|
516
|
-
else if (!text)
|
|
517
|
-
err('CALLOUT_EMPTY', `callout("${e.target}", …) needs one short sentence, for example callout('${e.target}', 'Share after generation')`, st.source);
|
|
518
|
-
else if (e.side !== undefined && !CALLOUT_SIDES.includes(e.side))
|
|
519
|
-
err('CALLOUT_SIDE_INVALID', `callout("${e.target}", …, { side: ${JSON.stringify(e.side)} }) must be one of ${CALLOUT_SIDES.join(', ')}, or omitted to pick automatically`, st.source);
|
|
520
|
-
else {
|
|
521
|
-
callouts.push({ target: e.target, text, ...(e.side ? { side: e.side } : {}) });
|
|
522
|
-
if (!focusTargets.includes(e.target))
|
|
523
|
-
focusTargets.push(e.target);
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
else if (e.type === 'hold') {
|
|
527
|
-
const sec = e.seconds;
|
|
528
|
-
if (typeof sec !== 'number' || !Number.isFinite(sec) || sec < HOLD_MIN_SECONDS || sec > HOLD_MAX_SECONDS)
|
|
529
|
-
err('HOLD_INVALID', `hold(${String(sec)}) must be between ${HOLD_MIN_SECONDS} and ${HOLD_MAX_SECONDS} seconds`, st.source);
|
|
530
|
-
else
|
|
531
|
-
holdMs = Math.max(holdMs ?? 0, Math.round(sec * 1000));
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
const cues = [...cueMap].map(([kind, targets]) => ({ kind, targets }));
|
|
535
|
-
// 镜头:每个 id 在包含它的层级里解析;第一个 shot 的第一个元素所在层级就是这一步的导演层。
|
|
536
|
-
// 没有声明 layers 的方案:在路径页面里聚焦(伪层级 @page)。
|
|
537
|
-
const perLayer = new Map();
|
|
538
|
-
let directorLayer = null;
|
|
539
|
-
for (const e of st.effects) {
|
|
540
|
-
if (e.type !== 'shot' && !pluginTargets.has(e))
|
|
541
|
-
continue;
|
|
542
|
-
const fromPlugin = e.type !== 'shot';
|
|
543
|
-
const targets = e.type === 'shot' ? e.targets : pluginTargets.get(e);
|
|
544
|
-
if (targets.length === 0) {
|
|
545
|
-
// shot():导演所在层回到整体(不推近)
|
|
546
|
-
const lk = hasLayers ? DIRECTOR_LAYER : PAGE_LAYER;
|
|
547
|
-
if (!perLayer.has(lk))
|
|
548
|
-
perLayer.set(lk, []);
|
|
549
|
-
}
|
|
550
|
-
for (const id of targets) {
|
|
551
|
-
const where = hasLayers ? layersWith(id) : [sceneAfter, sceneBefore].some((sc) => sc && findIn(sc.root, id)) ? [PAGE_LAYER] : [];
|
|
552
|
-
if (!where.length) {
|
|
553
|
-
if (fromPlugin)
|
|
554
|
-
continue; // 插件目标已经校验过;不在这一步的画面里时不移动镜头
|
|
555
|
-
err('SHOT_UNKNOWN', hasLayers ? `shot("${id}") references an element absent from all layers (layers: ${Object.keys(layers).join(', ')})` : `shot("${id}") references an element absent from this step's stage (${sceneAfter?.route ?? sceneBefore?.route ?? '?'})`, st.source);
|
|
556
|
-
continue;
|
|
557
|
-
}
|
|
558
|
-
for (const lk of where) {
|
|
559
|
-
const list = perLayer.get(lk) ?? [];
|
|
560
|
-
if (!list.includes(id))
|
|
561
|
-
list.push(id);
|
|
562
|
-
perLayer.set(lk, list);
|
|
563
|
-
directorLayer ??= lk;
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
// 插件的导演目标只选择层,不自动加入聚焦框或推进视角。
|
|
568
|
-
if (hasLayers && !directorLayer && directorTargets.length)
|
|
569
|
-
directorLayer = layersWith(directorTargets[0])[0] ?? null;
|
|
570
|
-
// 没写 shot、写了焦点提示(D70):导演切到第一个提示目标所在的层(提示要被看见)
|
|
571
|
-
if (hasLayers && !directorLayer && focusTargets.length)
|
|
572
|
-
directorLayer = layersWith(focusTargets[0])[0] ?? null;
|
|
573
|
-
// 没写 shot 的操作步骤:导演切到操作目标所在的层(播放时观众看得到要点的东西)
|
|
574
|
-
if (hasLayers && !directorLayer && actionTarget)
|
|
575
|
-
directorLayer = layersWith(actionTarget)[0] ?? null;
|
|
576
|
-
// 换人的过渡卡(D56):卡片后面导演切到这个人的层级(卡片淡出时已经是 TA 的画面)
|
|
577
|
-
if (st.action.type === 'card' && st.action.role !== undefined) {
|
|
578
|
-
const r = st.action.role;
|
|
579
|
-
if (!roleKeys.has(r))
|
|
580
|
-
err('ROLE_UNKNOWN', `card("${st.action.title}") role "${r}" is not in feature.roles${roleKeys.size ? ` (available: ${[...roleKeys].join(', ')})` : ''}`, st.source);
|
|
581
|
-
else if (hasLayers && !directorLayer)
|
|
582
|
-
directorLayer = Object.entries(layers).find(([, l]) => l.role === r)?.[0] ?? null;
|
|
583
|
-
}
|
|
584
|
-
// 焦点提示不推近镜头(D70):目标不在这一层当前镜头里(inShotFrame:镜头目标本身、它的子元素,或 D69 取景一定带上的
|
|
585
|
-
// 父分组 / 时序图两端参与者)时,这一步补一个整层镜头,
|
|
586
|
-
// 免得提示落在画面外;这一步自己写了这一层的 shot 时以 shot 为准(目标在 shot 外由 check 的 FOCUS_CONFLICT 提示)
|
|
587
|
-
const dirAfter = directorLayer ?? director;
|
|
588
|
-
for (const id of focusTargets) {
|
|
589
|
-
const ls = focusLayers(id);
|
|
590
|
-
const lk = ls.includes(dirAfter) ? dirAfter : ls[0];
|
|
591
|
-
if (!lk || perLayer.has(lk) || (perLayer.has(DIRECTOR_LAYER) && lk === dirAfter))
|
|
592
|
-
continue;
|
|
593
|
-
const now = frame.get(lk) ?? [];
|
|
594
|
-
const scene = hasLayers ? layerScenes.find((l) => l.key === lk)?.scene : sceneAfter;
|
|
595
|
-
if (now.length && !(scene && inShotFrame(scene.root, id, now)))
|
|
596
|
-
perLayer.set(lk, []);
|
|
597
|
-
}
|
|
598
|
-
const shots = [...perLayer].map(([layer, targets]) => ({ layer, targets }));
|
|
599
|
-
if (directorLayer)
|
|
600
|
-
director = directorLayer;
|
|
601
|
-
for (const s of shots)
|
|
602
|
-
frame.set(s.layer === DIRECTOR_LAYER ? director : s.layer, [...s.targets]);
|
|
603
|
-
const generated = st.caption === undefined ? autoCaption(st, (hasLayers && actionTarget ? layerSceneWith(actionTarget) : undefined) ?? sceneBefore, out) : null;
|
|
604
|
-
return {
|
|
605
|
-
id: `${sid}#${i + 1}`,
|
|
606
|
-
...(st.key !== undefined ? { key: st.key } : {}),
|
|
607
|
-
kind: st.kind,
|
|
608
|
-
action: st.action,
|
|
609
|
-
caption: st.caption ?? generated.caption,
|
|
610
|
-
...(generated?.captionAuto ? { captionAuto: generated.captionAuto } : {}),
|
|
611
|
-
effects,
|
|
612
|
-
ruleIds: strip ? [] : ruleIds,
|
|
613
|
-
shots,
|
|
614
|
-
directorLayer,
|
|
615
|
-
...(explains.length ? { explain: explains.join('\n') } : {}),
|
|
616
|
-
...(Object.keys(ext).length ? { ext } : {}),
|
|
617
|
-
...(references.length ? { references: [...new Set(references)] } : {}),
|
|
618
|
-
...(pluginFocus.length ? { focusTargets: [...new Set(pluginFocus)] } : {}),
|
|
619
|
-
forks,
|
|
620
|
-
marks,
|
|
621
|
-
...(cues.length ? { cues } : {}),
|
|
622
|
-
...(callouts.length ? { callouts } : {}),
|
|
623
|
-
...(holdMs !== undefined ? { hold: holdMs } : {}),
|
|
624
|
-
...(effectHoldMs > 0 ? { effectHold: effectHoldMs } : {}),
|
|
625
|
-
...(says.length ? { say: says.join(' ') } : {}),
|
|
626
|
-
...(says.length && sayRole ? { sayRole } : {}),
|
|
627
|
-
...(narrates.length ? { narrate: narrates.join(' ') } : {}),
|
|
628
|
-
...(st.source ? { source: rel(st.source) } : {}),
|
|
629
|
-
};
|
|
630
|
-
});
|
|
425
|
+
const stepContext = { err, rel, strip, host, out, qid, def, ctxRoutes, sceneOf, sceneFor, ruleQid, roleKeys, roleScope, hasLayers, layers, layerScenes, layersWith, layerSceneWith, effectRoots, skey, sid, fl, start, stepKeys, frame, director };
|
|
426
|
+
const steps = fl.steps.map((st, i) => lowerStep(stepContext, st, i));
|
|
427
|
+
director = stepContext.director;
|
|
631
428
|
// 结局(D65):flow 的 outcome 优先;没写时取 done(…, outcome) 的第二个参数(cancelled 记为 other)
|
|
632
429
|
const doneOutcome = [...fl.steps].reverse().flatMap((st) => [...st.effects].reverse()).find((e) => e.type === 'complete')?.outcome;
|
|
633
430
|
const fromDone = doneOutcome === undefined ? undefined : doneOutcome === 'cancelled' ? 'other' : doneOutcome;
|
|
@@ -638,11 +435,11 @@ export function compile(src, mode, opts = {}) {
|
|
|
638
435
|
const sc = {
|
|
639
436
|
...(fl.opts.actionEntry !== undefined ? { actionEntry: fl.opts.actionEntry } : {}),
|
|
640
437
|
id: sid,
|
|
641
|
-
|
|
438
|
+
workId: qid,
|
|
642
439
|
name: fl.name,
|
|
643
440
|
...(fl.opts.autoplay !== undefined ? { autoplay: fl.opts.autoplay } : {}),
|
|
644
441
|
description: fl.opts.description ?? '',
|
|
645
|
-
caseIds: strip ? [] : (fl.opts.cases ?? []).filter((c) => fdef
|
|
442
|
+
caseIds: strip ? [] : (fl.opts.cases ?? []).filter((c) => fdef?.cases?.[c]).map((c) => `${fid}.${c}`),
|
|
646
443
|
mock: { label: fl.opts.mock ?? MOCK_LABEL[outcome], outcome, ...(fl.opts.mock === undefined ? { auto: true } : {}) },
|
|
647
444
|
initial: { sceneId: sceneOf(start), ui: state.ui, data: state.data, inputs: state.inputs, ...(hasLayers && fl.opts.layer !== undefined && Object.hasOwn(layers, fl.opts.layer) ? { layer: fl.opts.layer } : {}) },
|
|
648
445
|
steps,
|
|
@@ -666,7 +463,7 @@ export function compile(src, mode, opts = {}) {
|
|
|
666
463
|
}
|
|
667
464
|
// 所有场景完成后再解析分叉(允许向后声明的场景),不把创作信息参与前缀比较。
|
|
668
465
|
for (const sc of Object.values(out.scenarios)) {
|
|
669
|
-
if (sc.
|
|
466
|
+
if (sc.workId !== qid)
|
|
670
467
|
continue;
|
|
671
468
|
for (const st of sc.steps)
|
|
672
469
|
for (const f of st.forks) {
|
|
@@ -677,7 +474,7 @@ export function compile(src, mode, opts = {}) {
|
|
|
677
474
|
}
|
|
678
475
|
const coverage = {};
|
|
679
476
|
if (mode === 'dev') {
|
|
680
|
-
for (const ck of Object.keys(fdef
|
|
477
|
+
for (const ck of Object.keys(fdef?.cases ?? {})) {
|
|
681
478
|
const decl = def.coverage?.[ck];
|
|
682
479
|
const sids = scenarioIds[ck] ?? [];
|
|
683
480
|
if (decl)
|
|
@@ -688,8 +485,8 @@ export function compile(src, mode, opts = {}) {
|
|
|
688
485
|
coverage[`${fid}.${ck}`] = { status: 'missing', scenarioIds: [], basis: 'derived' };
|
|
689
486
|
}
|
|
690
487
|
for (const ck of Object.keys(def.coverage ?? {}))
|
|
691
|
-
if (!fdef
|
|
692
|
-
err('UNKNOWN_CASE', `
|
|
488
|
+
if (!fdef?.cases?.[ck])
|
|
489
|
+
err('UNKNOWN_CASE', `Work ${qid} coverage declares unknown case "${ck}"`, def.source);
|
|
693
490
|
}
|
|
694
491
|
const free = {};
|
|
695
492
|
for (const [key, reaction] of Object.entries(def.free ?? {})) {
|
|
@@ -698,10 +495,10 @@ export function compile(src, mode, opts = {}) {
|
|
|
698
495
|
err('FREE_ACTION_INVALID', `Free reaction ${key} needs a targeted action`, reaction.source);
|
|
699
496
|
continue;
|
|
700
497
|
}
|
|
701
|
-
const roots = effectRoots.filter(scene => scene.
|
|
498
|
+
const roots = effectRoots.filter(scene => scene.workId === qid || mode === 'publish' && scene.workId === null);
|
|
702
499
|
const target = reaction.action.target;
|
|
703
500
|
if (!roots.some(scene => findIn(scene.root, target)))
|
|
704
|
-
err('FREE_TARGET_MISSING', `Free reaction ${key}: target ${reaction.action.target} is not in
|
|
501
|
+
err('FREE_TARGET_MISSING', `Free reaction ${key}: target ${reaction.action.target} is not in work ${qid}`, reaction.source);
|
|
705
502
|
const targets = roots.map(scene => findIn(scene.root, target)).filter((n) => !!n);
|
|
706
503
|
if (reaction.action.type === 'click' && targets.length && !targets.some(n => isInteractiveType(n.type, out.plugins)))
|
|
707
504
|
err('FREE_ACTION_INVALID', `Free reaction ${key}: ${target} is not interactive`, reaction.source);
|
|
@@ -723,17 +520,20 @@ export function compile(src, mode, opts = {}) {
|
|
|
723
520
|
}
|
|
724
521
|
free[key] = { action: a.data, effects, ...(reaction.source ? { source: rel(reaction.source) } : {}) };
|
|
725
522
|
}
|
|
726
|
-
|
|
523
|
+
if (fdef)
|
|
524
|
+
out.features[fid].alternatives[qid] = { decisionFocus: strip ? '' : def.focus ?? '', tradeoffs: strip ? [] : def.tradeoffs ?? [], coverage };
|
|
525
|
+
out.works[qid] = {
|
|
727
526
|
...(Object.keys(free).length ? { free } : {}),
|
|
728
527
|
id: qid,
|
|
729
|
-
|
|
528
|
+
...(linearWorks.has(qid) ? { sequencing: 'linear' } : {}),
|
|
529
|
+
...(fdef ? { featureId: fid } : {}),
|
|
530
|
+
roles: fdef ? [] : compileRoles(def.roles),
|
|
531
|
+
...(!fdef && def.audience?.trim() ? { audience: def.audience.trim() } : {}),
|
|
532
|
+
...(!fdef && mode === 'dev' && def.draft === true ? { draft: true } : {}),
|
|
730
533
|
key: o.key,
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
decisionFocus: strip ? '' : (def.focus ?? ''),
|
|
734
|
-
tradeoffs: strip ? [] : (def.tradeoffs ?? []),
|
|
534
|
+
title: def.title,
|
|
535
|
+
summary: def.summary,
|
|
735
536
|
routes: touched,
|
|
736
|
-
coverage,
|
|
737
537
|
layers,
|
|
738
538
|
...(def.source ? { source: rel(def.source) } : {}),
|
|
739
539
|
};
|
|
@@ -771,9 +571,9 @@ export function compile(src, mode, opts = {}) {
|
|
|
771
571
|
if (!target || !prev)
|
|
772
572
|
return false;
|
|
773
573
|
try {
|
|
774
|
-
const end =
|
|
775
|
-
const hasLayers = Object.keys(out.
|
|
776
|
-
const layer = p.layer ?? (hasLayers ?
|
|
574
|
+
const end = replayTo(out, p.from, prev.steps.length);
|
|
575
|
+
const hasLayers = Object.keys(out.works[target.workId]?.layers ?? {}).length > 0;
|
|
576
|
+
const layer = p.layer ?? (hasLayers ? cameraOf(out, p.from, prev.steps.length).directorLayer : undefined);
|
|
777
577
|
const merged = mergeState({ ui: end.ui, data: end.data, inputs: end.inputs }, p.state);
|
|
778
578
|
target.initial = { sceneId: end.sceneId, ui: merged.ui, data: merged.data, inputs: merged.inputs, ...(layer ? { layer } : {}) };
|
|
779
579
|
target.from = p.from;
|
|
@@ -797,6 +597,12 @@ export function compile(src, mode, opts = {}) {
|
|
|
797
597
|
return { project: null, diagnostics: diags };
|
|
798
598
|
// ---------- 8. 发布视图与评审版:去掉设计备注与源位置 ----------
|
|
799
599
|
if (strip) {
|
|
600
|
+
// 组件的显示名与检查抽屉信息只给本地看板用
|
|
601
|
+
for (const info of Object.values(plugins))
|
|
602
|
+
for (const c of Object.values(info.components)) {
|
|
603
|
+
delete c.label;
|
|
604
|
+
delete c.inspect;
|
|
605
|
+
}
|
|
800
606
|
for (const s of Object.values(out.scenes))
|
|
801
607
|
stripNotes(s.root);
|
|
802
608
|
stripSources(out);
|
|
@@ -888,10 +694,279 @@ function localeDiagnostics(project, src, diags) {
|
|
|
888
694
|
}
|
|
889
695
|
return stale;
|
|
890
696
|
}
|
|
891
|
-
|
|
892
|
-
|
|
697
|
+
/**
|
|
698
|
+
* 把作者写的一步降级成 IR 的一步:效果归类(状态变化、朗读、镜头、焦点提示、标注、分叉、插件效果)、目标与引用校验、
|
|
699
|
+
* 自动字幕、这一步的镜头与导演层。场景级的上下文(路径、层级、已累积的镜头)经 StepContext 传入;
|
|
700
|
+
* 导演层随步骤推进,写回 c.director。
|
|
701
|
+
*/
|
|
702
|
+
function lowerStep(c, st, i) {
|
|
703
|
+
const { err, rel, strip, host, out, qid, def, ctxRoutes, sceneOf, sceneFor, ruleQid, roleKeys, roleScope, hasLayers, layers, layerScenes, layersWith, layerSceneWith, effectRoots, skey, sid, fl, start, stepKeys, frame } = c;
|
|
704
|
+
let director = c.director;
|
|
705
|
+
if (st.key !== undefined) {
|
|
706
|
+
if (!/^[A-Za-z][A-Za-z0-9_-]{0,63}$/.test(st.key))
|
|
707
|
+
err('STEP_KEY_INVALID', 'Step key must start with a letter and contain at most 64 letters, digits, underscores or hyphens', st.source);
|
|
708
|
+
if (stepKeys.has(st.key))
|
|
709
|
+
err('STEP_KEY_DUPLICATE', `Duplicate step key ${st.key} in ${sid}; use a distinct key for each action`, st.source);
|
|
710
|
+
stepKeys.add(st.key);
|
|
711
|
+
}
|
|
712
|
+
const effects = [];
|
|
713
|
+
const ruleIds = [];
|
|
714
|
+
const explains = [];
|
|
715
|
+
const says = [];
|
|
716
|
+
let sayRole = null;
|
|
717
|
+
const narrates = [];
|
|
718
|
+
/** 插件效果声明的最短停留(D98):同一步取最大值。 */
|
|
719
|
+
let effectHoldMs = 0;
|
|
720
|
+
const ext = {};
|
|
721
|
+
const references = [];
|
|
722
|
+
const pluginFocus = [];
|
|
723
|
+
const directorTargets = [];
|
|
724
|
+
const forks = [];
|
|
725
|
+
const marks = [];
|
|
726
|
+
/** 每个插件效果贡献的节点(作为镜头目标,与 shot 合并)。 */
|
|
727
|
+
const pluginTargets = new Map();
|
|
728
|
+
for (const e of st.effects) {
|
|
729
|
+
if (e.type === 'go') {
|
|
730
|
+
if (!ctxRoutes.has(e.route))
|
|
731
|
+
err('UNKNOWN_ROUTE', `go("${e.route}") navigates to an unknown route`, st.source);
|
|
732
|
+
effects.push({ type: 'navigate', sceneId: sceneOf(e.route) });
|
|
733
|
+
}
|
|
734
|
+
else if (e.type === 'uses') {
|
|
735
|
+
for (const r of e.rules) {
|
|
736
|
+
const q = ruleQid(r, st.source);
|
|
737
|
+
if (q)
|
|
738
|
+
ruleIds.push(q);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
else if (e.type === 'set' || e.type === 'append')
|
|
742
|
+
effects.push({ type: e.type, path: e.path, value: e.value });
|
|
743
|
+
else if (e.type === 'stream') {
|
|
744
|
+
if (e.pace !== undefined && e.pace !== 'voice')
|
|
745
|
+
err('STREAM_PACE_INVALID', `stream() pace must be 'voice' (got ${JSON.stringify(e.pace)}); omit it to stream at model-output speed`, st.source);
|
|
746
|
+
effects.push({ type: 'stream', path: e.path, value: e.value, ...(e.pace === 'voice' ? { pace: 'voice' } : {}) });
|
|
747
|
+
}
|
|
748
|
+
else if (e.type === 'toast')
|
|
749
|
+
effects.push({ type: 'toast', text: e.text, tone: e.tone });
|
|
750
|
+
else if (e.type === 'shot' || e.type === 'mark' || e.type === 'fork' || e.type === 'cue' || e.type === 'callout' || e.type === 'hold')
|
|
751
|
+
continue; // 镜头与焦点提示不是状态变化,下面单独归类
|
|
752
|
+
else if (e.type === 'say') {
|
|
753
|
+
if (e.role !== undefined) {
|
|
754
|
+
if (typeof e.role !== 'string' || !roleKeys.has(e.role))
|
|
755
|
+
err('ROLE_UNKNOWN', `say() role "${String(e.role)}" is not in ${roleScope}${roleKeys.size ? ` (available: ${[...roleKeys].join(', ')})` : ` (${roleScope} must use { key: role('Name') })`}`, st.source);
|
|
756
|
+
else if (sayRole !== null && sayRole !== e.role)
|
|
757
|
+
err('SAY_ROLE_CONFLICT', `One step has say() lines from two roles ("${sayRole}" and "${e.role}"); split them into two steps`, st.source);
|
|
758
|
+
else
|
|
759
|
+
sayRole = e.role;
|
|
760
|
+
}
|
|
761
|
+
if (typeof e.text === 'string' && e.text.trim())
|
|
762
|
+
says.push(e.text.trim());
|
|
763
|
+
else
|
|
764
|
+
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);
|
|
765
|
+
}
|
|
766
|
+
else if (e.type === 'narrate') {
|
|
767
|
+
if (typeof e.text === 'string' && e.text.trim())
|
|
768
|
+
narrates.push(e.text.trim());
|
|
769
|
+
else
|
|
770
|
+
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);
|
|
771
|
+
}
|
|
772
|
+
else if (e.type === 'explain') {
|
|
773
|
+
if (e.text.trim())
|
|
774
|
+
explains.push(e.text.trim());
|
|
775
|
+
}
|
|
776
|
+
else if (e.type === 'plugin') {
|
|
777
|
+
const lowered = host.effect(e, effectRoots.filter(scene => scene.layer || scene.id === sceneOf(stepRouteBefore(fl.steps, i + 1, start))), ext[e.plugin], st.source);
|
|
778
|
+
if (lowered) {
|
|
779
|
+
effects.push(...(lowered.writes ?? []).map(w => ({ type: 'set', path: w.path, value: w.value })));
|
|
780
|
+
if (lowered.directorTarget)
|
|
781
|
+
directorTargets.push(lowered.directorTarget);
|
|
782
|
+
if (lowered.holdMs)
|
|
783
|
+
effectHoldMs = Math.max(effectHoldMs, lowered.holdMs);
|
|
784
|
+
if (lowered.media?.length) {
|
|
785
|
+
const key = `${sid}#${i + 1}`;
|
|
786
|
+
host.mediaCommands.set(key, [...(host.mediaCommands.get(key) ?? []), ...lowered.media]);
|
|
787
|
+
}
|
|
788
|
+
if (lowered.data !== undefined)
|
|
789
|
+
ext[e.plugin] = lowered.data;
|
|
790
|
+
if (lowered.targets?.length) {
|
|
791
|
+
pluginTargets.set(e, lowered.targets);
|
|
792
|
+
pluginFocus.push(...lowered.targets);
|
|
793
|
+
}
|
|
794
|
+
references.push(...lowered.references ?? []);
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
else if (e.type === 'complete')
|
|
798
|
+
effects.push({ type: 'complete', text: e.text, outcome: e.outcome });
|
|
799
|
+
else
|
|
800
|
+
err('EFFECT_INVALID', 'Unknown step effect; use a documented effect helper instead of constructing effect objects', st.source);
|
|
801
|
+
}
|
|
802
|
+
const sceneBefore = sceneFor.get(sceneOf(stepRouteBefore(fl.steps, i, start)));
|
|
803
|
+
const sceneAfter = sceneFor.get(sceneOf(stepRouteBefore(fl.steps, i + 1, start)));
|
|
804
|
+
const actionTarget = 'target' in st.action ? st.action.target : null;
|
|
805
|
+
validateNewAction(st.action, hasLayers ? layerScenes.map(l => l.scene) : sceneBefore ? [sceneBefore] : [], out, (code, message) => err(code, message, st.source));
|
|
806
|
+
for (const e of st.effects) {
|
|
807
|
+
if (e.type === 'fork') {
|
|
808
|
+
if (!Object.hasOwn(def.scenarios, e.scenario) || e.scenario === skey)
|
|
809
|
+
err('FORK_UNKNOWN', `Fork target "${e.scenario}" must be another scenario key in the same work`, st.source);
|
|
810
|
+
else if (e.label.trim())
|
|
811
|
+
forks.push({ label: e.label.trim(), scenarioId: `${qid}.${e.scenario}`, at: 0 });
|
|
812
|
+
}
|
|
813
|
+
if (e.type === 'mark') {
|
|
814
|
+
const exists = hasLayers ? layersWith(e.target).length > 0 : !!sceneAfter && !!findIn(sceneAfter.root, e.target);
|
|
815
|
+
if (!exists)
|
|
816
|
+
err('MARK_UNKNOWN', `mark("${e.target}") target is not in ${hasLayers ? 'any layer' : 'the stage for this step'}`, st.source);
|
|
817
|
+
else
|
|
818
|
+
marks.push({ target: e.target, kind: e.kindOf, ...(e.note ? { note: e.note } : {}) });
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
// 焦点提示(D70):spotlight / highlight / numbered / callout / hold。目标与 mark 同样解析:有层级时在任一层,否则在这一步的路径页面
|
|
822
|
+
const focusLayers = (id) => (hasLayers ? layersWith(id) : sceneAfter && findIn(sceneAfter.root, id) ? [PAGE_LAYER] : []);
|
|
823
|
+
const where = hasLayers ? 'any layer' : 'the stage for this step';
|
|
824
|
+
const cueMap = new Map();
|
|
825
|
+
const callouts = [];
|
|
826
|
+
/** 焦点提示的目标(按效果顺序):决定导演层,并判断要不要退回整层镜头。 */
|
|
827
|
+
const focusTargets = [];
|
|
828
|
+
let holdMs;
|
|
829
|
+
const CUE_FN = { spotlight: 'spotlight', highlight: 'highlight', number: 'numbered' };
|
|
830
|
+
for (const e of st.effects) {
|
|
831
|
+
if (e.type === 'cue') {
|
|
832
|
+
const fn = CUE_FN[e.cue] ?? e.cue;
|
|
833
|
+
if (!e.targets.length)
|
|
834
|
+
err('FOCUS_UNKNOWN', `${fn}() requires at least one element id, for example ${fn}('quota_alert')`, st.source);
|
|
835
|
+
for (const id of e.targets) {
|
|
836
|
+
if (!focusLayers(id).length) {
|
|
837
|
+
err('FOCUS_UNKNOWN', `${fn}("${id}") target is not in ${where}`, st.source);
|
|
838
|
+
continue;
|
|
839
|
+
}
|
|
840
|
+
const list = cueMap.get(e.cue) ?? [];
|
|
841
|
+
if (!list.includes(id))
|
|
842
|
+
list.push(id);
|
|
843
|
+
cueMap.set(e.cue, list);
|
|
844
|
+
if (!focusTargets.includes(id))
|
|
845
|
+
focusTargets.push(id);
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
else if (e.type === 'callout') {
|
|
849
|
+
const text = typeof e.text === 'string' ? e.text.trim() : '';
|
|
850
|
+
if (!focusLayers(e.target).length)
|
|
851
|
+
err('FOCUS_UNKNOWN', `callout("${e.target}", …) target is not in ${where}`, st.source);
|
|
852
|
+
else if (!text)
|
|
853
|
+
err('CALLOUT_EMPTY', `callout("${e.target}", …) needs one short sentence, for example callout('${e.target}', 'Share after generation')`, st.source);
|
|
854
|
+
else if (e.side !== undefined && !CALLOUT_SIDES.includes(e.side))
|
|
855
|
+
err('CALLOUT_SIDE_INVALID', `callout("${e.target}", …, { side: ${JSON.stringify(e.side)} }) must be one of ${CALLOUT_SIDES.join(', ')}, or omitted to pick automatically`, st.source);
|
|
856
|
+
else {
|
|
857
|
+
callouts.push({ target: e.target, text, ...(e.side ? { side: e.side } : {}) });
|
|
858
|
+
if (!focusTargets.includes(e.target))
|
|
859
|
+
focusTargets.push(e.target);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
else if (e.type === 'hold') {
|
|
863
|
+
const sec = e.seconds;
|
|
864
|
+
if (typeof sec !== 'number' || !Number.isFinite(sec) || sec < HOLD_MIN_SECONDS || sec > HOLD_MAX_SECONDS)
|
|
865
|
+
err('HOLD_INVALID', `hold(${String(sec)}) must be between ${HOLD_MIN_SECONDS} and ${HOLD_MAX_SECONDS} seconds`, st.source);
|
|
866
|
+
else
|
|
867
|
+
holdMs = Math.max(holdMs ?? 0, Math.round(sec * 1000));
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
const cues = [...cueMap].map(([kind, targets]) => ({ kind, targets }));
|
|
871
|
+
// 镜头:每个 id 在包含它的层级里解析;第一个 shot 的第一个元素所在层级就是这一步的导演层。
|
|
872
|
+
// 没有声明 layers 的方案:在路径页面里聚焦(伪层级 @page)。
|
|
873
|
+
const perLayer = new Map();
|
|
874
|
+
let directorLayer = null;
|
|
875
|
+
for (const e of st.effects) {
|
|
876
|
+
if (e.type !== 'shot' && !pluginTargets.has(e))
|
|
877
|
+
continue;
|
|
878
|
+
const fromPlugin = e.type !== 'shot';
|
|
879
|
+
const targets = e.type === 'shot' ? e.targets : pluginTargets.get(e);
|
|
880
|
+
if (targets.length === 0) {
|
|
881
|
+
// shot():导演所在层回到整体(不推近)
|
|
882
|
+
const lk = hasLayers ? DIRECTOR_LAYER : PAGE_LAYER;
|
|
883
|
+
if (!perLayer.has(lk))
|
|
884
|
+
perLayer.set(lk, []);
|
|
885
|
+
}
|
|
886
|
+
for (const id of targets) {
|
|
887
|
+
const where = hasLayers ? layersWith(id) : [sceneAfter, sceneBefore].some((sc) => sc && findIn(sc.root, id)) ? [PAGE_LAYER] : [];
|
|
888
|
+
if (!where.length) {
|
|
889
|
+
if (fromPlugin)
|
|
890
|
+
continue; // 插件目标已经校验过;不在这一步的画面里时不移动镜头
|
|
891
|
+
err('SHOT_UNKNOWN', hasLayers ? `shot("${id}") references an element absent from all layers (layers: ${Object.keys(layers).join(', ')})` : `shot("${id}") references an element absent from this step's stage (${sceneAfter?.route ?? sceneBefore?.route ?? '?'})`, st.source);
|
|
892
|
+
continue;
|
|
893
|
+
}
|
|
894
|
+
for (const lk of where) {
|
|
895
|
+
const list = perLayer.get(lk) ?? [];
|
|
896
|
+
if (!list.includes(id))
|
|
897
|
+
list.push(id);
|
|
898
|
+
perLayer.set(lk, list);
|
|
899
|
+
directorLayer ??= lk;
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
// 插件的导演目标只选择层,不自动加入聚焦框或推进视角。
|
|
904
|
+
if (hasLayers && !directorLayer && directorTargets.length)
|
|
905
|
+
directorLayer = layersWith(directorTargets[0])[0] ?? null;
|
|
906
|
+
// 没写 shot、写了焦点提示(D70):导演切到第一个提示目标所在的层(提示要被看见)
|
|
907
|
+
if (hasLayers && !directorLayer && focusTargets.length)
|
|
908
|
+
directorLayer = layersWith(focusTargets[0])[0] ?? null;
|
|
909
|
+
// 没写 shot 的操作步骤:导演切到操作目标所在的层(播放时观众看得到要点的东西)
|
|
910
|
+
if (hasLayers && !directorLayer && actionTarget)
|
|
911
|
+
directorLayer = layersWith(actionTarget)[0] ?? null;
|
|
912
|
+
// 换人的过渡卡(D56):卡片后面导演切到这个人的层级(卡片淡出时已经是 TA 的画面)
|
|
913
|
+
if (st.action.type === 'card' && st.action.role !== undefined) {
|
|
914
|
+
const r = st.action.role;
|
|
915
|
+
if (!roleKeys.has(r))
|
|
916
|
+
err('ROLE_UNKNOWN', `card("${st.action.title}") role "${r}" is not in ${roleScope}${roleKeys.size ? ` (available: ${[...roleKeys].join(', ')})` : ''}`, st.source);
|
|
917
|
+
else if (hasLayers && !directorLayer)
|
|
918
|
+
directorLayer = Object.entries(layers).find(([, l]) => l.role === r)?.[0] ?? null;
|
|
919
|
+
}
|
|
920
|
+
// 焦点提示不推近镜头(D70):目标不在这一层当前镜头里(inShotFrame:镜头目标本身、它的子元素,或 D69 取景一定带上的
|
|
921
|
+
// 父分组 / 时序图两端参与者)时,这一步补一个整层镜头,
|
|
922
|
+
// 免得提示落在画面外;这一步自己写了这一层的 shot 时以 shot 为准(目标在 shot 外由 check 的 FOCUS_CONFLICT 提示)
|
|
923
|
+
const dirAfter = directorLayer ?? director;
|
|
924
|
+
for (const id of focusTargets) {
|
|
925
|
+
const ls = focusLayers(id);
|
|
926
|
+
const lk = ls.includes(dirAfter) ? dirAfter : ls[0];
|
|
927
|
+
if (!lk || perLayer.has(lk) || (perLayer.has(DIRECTOR_LAYER) && lk === dirAfter))
|
|
928
|
+
continue;
|
|
929
|
+
const now = frame.get(lk) ?? [];
|
|
930
|
+
const scene = hasLayers ? layerScenes.find((l) => l.key === lk)?.scene : sceneAfter;
|
|
931
|
+
if (now.length && !(scene && inShotFrame(scene.root, id, now)))
|
|
932
|
+
perLayer.set(lk, []);
|
|
933
|
+
}
|
|
934
|
+
const shots = [...perLayer].map(([layer, targets]) => ({ layer, targets }));
|
|
935
|
+
if (directorLayer)
|
|
936
|
+
director = directorLayer;
|
|
937
|
+
for (const s of shots)
|
|
938
|
+
frame.set(s.layer === DIRECTOR_LAYER ? director : s.layer, [...s.targets]);
|
|
939
|
+
const generated = st.caption === undefined ? autoCaption(st, (hasLayers && actionTarget ? layerSceneWith(actionTarget) : undefined) ?? sceneBefore, out) : null;
|
|
940
|
+
c.director = director;
|
|
941
|
+
return {
|
|
942
|
+
id: `${sid}#${i + 1}`,
|
|
943
|
+
...(st.key !== undefined ? { key: st.key } : {}),
|
|
944
|
+
kind: st.kind,
|
|
945
|
+
action: st.action,
|
|
946
|
+
caption: st.caption ?? generated.caption,
|
|
947
|
+
...(generated?.captionAuto ? { captionAuto: generated.captionAuto } : {}),
|
|
948
|
+
effects,
|
|
949
|
+
ruleIds: strip ? [] : ruleIds,
|
|
950
|
+
shots,
|
|
951
|
+
directorLayer,
|
|
952
|
+
...(explains.length ? { explain: explains.join('\n') } : {}),
|
|
953
|
+
...(Object.keys(ext).length ? { ext } : {}),
|
|
954
|
+
...(references.length ? { references: [...new Set(references)] } : {}),
|
|
955
|
+
...(pluginFocus.length ? { focusTargets: [...new Set(pluginFocus)] } : {}),
|
|
956
|
+
forks,
|
|
957
|
+
marks,
|
|
958
|
+
...(cues.length ? { cues } : {}),
|
|
959
|
+
...(callouts.length ? { callouts } : {}),
|
|
960
|
+
...(holdMs !== undefined ? { hold: holdMs } : {}),
|
|
961
|
+
...(effectHoldMs > 0 ? { effectHold: effectHoldMs } : {}),
|
|
962
|
+
...(says.length ? { say: says.join(' ') } : {}),
|
|
963
|
+
...(says.length && sayRole ? { sayRole } : {}),
|
|
964
|
+
...(narrates.length ? { narrate: narrates.join(' ') } : {}),
|
|
965
|
+
...(st.source ? { source: rel(st.source) } : {}),
|
|
966
|
+
};
|
|
967
|
+
}
|
|
893
968
|
export const ROLE_COLORS = ['#E8590C', '#1971C2', '#2F9E44', '#9C36B5', '#C2255C', '#0C8599'];
|
|
894
|
-
function
|
|
969
|
+
function compileRoles(roles) {
|
|
895
970
|
if (!roles)
|
|
896
971
|
return [];
|
|
897
972
|
const color = (i, c) => c ?? ROLE_COLORS[i % ROLE_COLORS.length];
|
|
@@ -910,12 +985,12 @@ function caseOf(id, featureId, c, source) {
|
|
|
910
985
|
const o = typeof c === 'string' ? { title: c } : c;
|
|
911
986
|
return { id, featureId, title: o.title, dimension: o.dimension ?? 'main', expected: o.expected ?? '', priority: o.priority ?? 'medium', ...(source ? { source } : {}) };
|
|
912
987
|
}
|
|
913
|
-
function ruleOf(id, featureId,
|
|
988
|
+
function ruleOf(id, featureId, workId, r, rel) {
|
|
914
989
|
const caseIds = r.cases.map((c) => (c.includes('.') ? c : `${featureId}.${c}`));
|
|
915
990
|
return {
|
|
916
991
|
id,
|
|
917
992
|
featureId,
|
|
918
|
-
...(
|
|
993
|
+
...(workId ? { workId } : {}),
|
|
919
994
|
text: r.text,
|
|
920
995
|
origin: r.origin,
|
|
921
996
|
confirmation: r.status,
|
|
@@ -991,7 +1066,7 @@ function toSceneNode(n, fallbackId, ids, nc, parentType) {
|
|
|
991
1066
|
if (v === undefined)
|
|
992
1067
|
continue; // 写了属性但值是 undefined(如 description={cond ? '…' : undefined})= 没写
|
|
993
1068
|
if (typeof v === 'function' && !isBind(v)) {
|
|
994
|
-
err('FUNCTION_PROP', `<${n.type}> prop ${k} is a function. Put behavior in the
|
|
1069
|
+
err('FUNCTION_PROP', `<${n.type}> prop ${k} is a function. Put behavior in the work's flow steps instead of event callbacks`, at);
|
|
995
1070
|
continue;
|
|
996
1071
|
}
|
|
997
1072
|
if (isNode(v)) {
|