@joplo-app/core 0.4.1 → 0.6.0

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.
Files changed (65) hide show
  1. package/dist/agent-skill.d.ts +7 -7
  2. package/dist/agent-skill.js +28 -25
  3. package/dist/authoring-works.d.ts +8 -0
  4. package/dist/authoring-works.js +46 -0
  5. package/dist/catalog.d.ts +2 -0
  6. package/dist/compile.d.ts +6 -3
  7. package/dist/compile.js +415 -327
  8. package/dist/content-i18n.js +9 -9
  9. package/dist/embed.d.ts +5 -5
  10. package/dist/embed.js +7 -7
  11. package/dist/entries.d.ts +63 -0
  12. package/dist/entries.js +78 -0
  13. package/dist/feature-diff.d.ts +7 -7
  14. package/dist/feature-diff.js +18 -17
  15. package/dist/features.d.ts +3 -3
  16. package/dist/features.js +3 -3
  17. package/dist/focus-check.js +2 -2
  18. package/dist/focus.d.ts +1 -5
  19. package/dist/focus.js +13 -35
  20. package/dist/guide.js +171 -67
  21. package/dist/index.d.ts +2 -0
  22. package/dist/index.js +2 -0
  23. package/dist/load.js +42 -11
  24. package/dist/local-review-files.js +17 -4
  25. package/dist/local-review.d.ts +8 -7
  26. package/dist/local-review.js +7 -6
  27. package/dist/outline.d.ts +21 -13
  28. package/dist/outline.js +27 -31
  29. package/dist/pace.d.ts +10 -5
  30. package/dist/pace.js +12 -5
  31. package/dist/playback.d.ts +57 -0
  32. package/dist/playback.js +317 -0
  33. package/dist/player.d.ts +9 -180
  34. package/dist/player.js +8 -618
  35. package/dist/playground.d.ts +1 -1
  36. package/dist/playground.js +4 -4
  37. package/dist/plugins/compiler.d.ts +16 -0
  38. package/dist/plugins/compiler.js +48 -9
  39. package/dist/presentation.d.ts +73 -0
  40. package/dist/presentation.js +163 -0
  41. package/dist/publication.d.ts +8 -0
  42. package/dist/publication.js +45 -0
  43. package/dist/result.d.ts +1 -1
  44. package/dist/review.d.ts +18 -10
  45. package/dist/review.js +62 -23
  46. package/dist/runtime.d.ts +2 -0
  47. package/dist/runtime.js +2 -0
  48. package/dist/scene-query.d.ts +77 -0
  49. package/dist/scene-query.js +246 -0
  50. package/dist/schema-issues.js +1 -1
  51. package/dist/schema.d.ts +118 -76
  52. package/dist/schema.js +52 -37
  53. package/dist/scope.d.ts +9 -9
  54. package/dist/scope.js +82 -49
  55. package/dist/selection.d.ts +1 -1
  56. package/dist/sequencing.d.ts +6 -0
  57. package/dist/sequencing.js +21 -0
  58. package/dist/step-plan.d.ts +55 -0
  59. package/dist/step-plan.js +90 -0
  60. package/dist/traits.d.ts +10 -0
  61. package/dist/traits.js +3 -0
  62. package/dist/validate.d.ts +1 -1
  63. package/dist/validate.js +75 -65
  64. package/dist/voice.js +4 -0
  65. package/package.json +15 -3
@@ -0,0 +1,317 @@
1
+ /**
2
+ * 回放(纯函数的状态转换):手动体验、逐步查看、自动播放、回放校验和渲染截图全部调用这里,
3
+ * 不允许任何一方另写一套按钮逻辑(PRD 8.4)。
4
+ *
5
+ * 位置(position)语义:0 = 场景初始状态;k = 已执行前 k 个步骤之后的状态。
6
+ * “上一步”通过取第 k-1 个位置的状态实现,因此恢复的是业务可见状态,而不是撤销动画。
7
+ */
8
+ import { pluginActionSpec, validActionData } from "./actions.js";
9
+ import { isInteractiveType, matchChoice, nodeLabel } from "./catalog.js";
10
+ import { JoploError } from "./result.js";
11
+ import { choicesOf, findNode, getScenario, getScene, isNodeDisabled, isNodeVisible, resolveValue, sceneOfTarget } from "./scene-query.js";
12
+ // ---------- 状态转换 ----------
13
+ export function initialState(project, scenarioId) {
14
+ const sc = getScenario(project, scenarioId);
15
+ getScene(project, sc.initial.sceneId);
16
+ return {
17
+ scenarioId,
18
+ position: 0,
19
+ sceneId: sc.initial.sceneId,
20
+ ui: structuredClone(sc.initial.ui),
21
+ data: structuredClone(sc.initial.data),
22
+ inputs: structuredClone(sc.initial.inputs),
23
+ toasts: [],
24
+ completed: null,
25
+ sceneStack: [],
26
+ };
27
+ }
28
+ export class PlaybackError extends JoploError {
29
+ constructor(message, diagnostic) {
30
+ super('PLAYBACK_FAILED', message, { diagnostics: [diagnostic] });
31
+ }
32
+ }
33
+ function setPath(state, path, value, mode) {
34
+ const [root, ...rest] = path.split('.');
35
+ const base = (root === 'ui' ? state.ui : root === 'data' ? state.data : state.inputs);
36
+ if (rest.length === 0)
37
+ throw new Error(`Cannot replace an entire state root: ${path}`);
38
+ let cur = base;
39
+ for (const key of rest.slice(0, -1)) {
40
+ const next = cur[key];
41
+ if (next === null || typeof next !== 'object' || Array.isArray(next))
42
+ cur[key] = {};
43
+ cur = cur[key];
44
+ }
45
+ const last = rest[rest.length - 1];
46
+ if (mode === 'set')
47
+ cur[last] = structuredClone(value);
48
+ else {
49
+ const arr = cur[last];
50
+ cur[last] = [...(Array.isArray(arr) ? arr : []), structuredClone(value)];
51
+ }
52
+ }
53
+ /**
54
+ * 校验当前步骤能否在给定状态下执行;返回诊断(null 表示可执行)。
55
+ * 手动体验时,UI 也用它判断用户点击的是不是“当前步骤的目标”。
56
+ */
57
+ export function checkStep(project, scenario, state, step) {
58
+ const d = checkStepInner(project, scenario, state, step);
59
+ if (d && step.source)
60
+ d.at = step.source;
61
+ return d;
62
+ }
63
+ function checkStepInner(project, scenario, state, step) {
64
+ const ref = { kind: 'step', id: step.id, workId: scenario.workId, scenarioId: scenario.id, stepId: step.id };
65
+ if (state.completed)
66
+ return { severity: 'error', code: 'ALREADY_COMPLETED', message: `Scenario has ended; cannot execute step ${step.id}`, source: 'replay', ref };
67
+ const a = step.action;
68
+ if (a.type === 'event' || a.type === 'card' || a.type === 'press')
69
+ return null;
70
+ if (a.type === 'back') {
71
+ return state.sceneStack.length === 0
72
+ ? { severity: 'error', code: 'NOTHING_TO_GO_BACK', message: `Step ${step.id} goes back, but there is no previous stage`, source: 'replay', ref }
73
+ : null;
74
+ }
75
+ const scene = sceneOfTarget(project, scenario, state, a.target);
76
+ if (!scene)
77
+ return { severity: 'error', code: 'MISSING_SCENE', message: `Current stage ${state.sceneId} does not exist`, source: 'replay', ref };
78
+ const hit = findNode(scene, a.target);
79
+ if (!hit)
80
+ return { severity: 'error', code: 'MISSING_TARGET', message: `Step ${step.id} target ${a.target} is not in the current stage ${scene.id}`, source: 'replay', ref };
81
+ const { node } = hit;
82
+ if (!isNodeVisible(scene, a.target, state))
83
+ return { severity: 'error', code: 'TARGET_HIDDEN', message: `Step ${step.id} target "${nodeLabel(node)}" is currently hidden`, source: 'replay', ref };
84
+ if (isNodeDisabled(node, state))
85
+ return { severity: 'error', code: 'TARGET_DISABLED', message: `Step ${step.id} target "${nodeLabel(node)}" is currently disabled`, source: 'replay', ref };
86
+ if (a.type === 'click' && !isInteractiveType(node.type, project.plugins))
87
+ return { severity: 'error', code: 'NOT_INTERACTIVE', message: `Step ${step.id} clicks ${node.type} "${nodeLabel(node)}", which is not interactive`, source: 'replay', ref };
88
+ if ((a.type === 'type' || a.type === 'select' || a.type === 'toggle') && !node.traits?.input)
89
+ return { severity: 'error', code: 'NOT_A_FIELD', message: `Step ${step.id} ${a.type} action target ${node.type} cannot accept input`, source: 'replay', ref };
90
+ if ((a.type === 'drag' || a.type === 'scroll') && typeof a.to === 'string' && !findNode(scene, a.to))
91
+ return { severity: 'error', code: 'ACTION_DESTINATION_MISSING', message: `Step ${step.id} destination ${a.to} is missing`, source: 'replay', ref };
92
+ if (a.type === 'scroll' && typeof a.to === 'string' && !findNode({ ...scene, root: node }, a.to))
93
+ return { severity: 'error', code: 'ACTION_DESTINATION_INVALID', message: `Step ${step.id} scroll destination ${a.to} is outside ${a.target}`, source: 'replay', ref };
94
+ if (a.type === 'plugin') {
95
+ const spec = pluginActionSpec(project, a.name);
96
+ if (!spec || !validActionData(spec, a.data) || spec.targets && !spec.targets.includes(node.type))
97
+ return { severity: 'error', code: 'ACTION_DATA_INVALID', message: `Step ${step.id} has an unknown or invalid plugin action ${a.name}`, source: 'replay', ref };
98
+ }
99
+ if (a.type === 'select') {
100
+ const choices = choicesOf(node, state);
101
+ if (choices && !matchChoice(choices, a.value))
102
+ return {
103
+ severity: 'error',
104
+ code: 'UNKNOWN_CHOICE',
105
+ message: `Step ${step.id} field "${nodeLabel(node)}" cannot select "${a.value}"; it is not an available choice (available: ${choices.map((c) => (c.label === c.value ? c.value : `${c.label}/${c.value}`)).join(', ')})`,
106
+ source: 'replay',
107
+ ref,
108
+ };
109
+ }
110
+ return null;
111
+ }
112
+ /** select 动作写入的值:匹配到选项时存 value(动作可写 value 或 label);declared element 切换数组中的一项。 */
113
+ function selectedValue(project, state, target, raw) {
114
+ const sc = project.scenarios[state.scenarioId];
115
+ const scene = sc ? sceneOfTarget(project, sc, state, target) : project.scenes[state.sceneId];
116
+ const node = scene ? findNode(scene, target)?.node : undefined;
117
+ if (!node)
118
+ return raw;
119
+ const choices = choicesOf(node, state);
120
+ const value = (choices && matchChoice(choices, raw)?.value) ?? raw;
121
+ if (node.traits?.input !== 'multiple')
122
+ return value;
123
+ const cur = state.inputs[target] ?? resolveValue(node.props?.value ?? node.props?.defaultValue, state);
124
+ const list = Array.isArray(cur) ? cur.map(String) : [];
125
+ return list.includes(value) ? list.filter((x) => x !== value) : [...list, value];
126
+ }
127
+ /** 执行 scenario.steps[state.position],返回新状态(不修改入参)。 */
128
+ export function applyStep(project, scenario, state) {
129
+ const step = scenario.steps[state.position];
130
+ if (!step)
131
+ throw new JoploError('PLAYBACK_FAILED', `Scenario ${scenario.id} has no step ${state.position + 1}`);
132
+ const problem = checkStep(project, scenario, state, step);
133
+ if (problem)
134
+ throw new PlaybackError(problem.message, problem);
135
+ const next = structuredClone(state);
136
+ next.toasts = [];
137
+ const a = step.action;
138
+ if (a.type === 'type' || a.type === 'toggle')
139
+ next.inputs[a.target] = a.value;
140
+ if (a.type === 'select')
141
+ next.inputs[a.target] = selectedValue(project, state, a.target, a.value);
142
+ if (a.type === 'back')
143
+ next.sceneId = next.sceneStack.pop();
144
+ step.effects.forEach((e, i) => {
145
+ const ref = { kind: 'step', id: step.id, workId: scenario.workId, scenarioId: scenario.id, stepId: step.id, path: `effects[${i}]` };
146
+ switch (e.type) {
147
+ case 'set':
148
+ setPath(next, e.path, e.value, 'set');
149
+ break;
150
+ case 'append':
151
+ setPath(next, e.path, e.value, 'append');
152
+ break;
153
+ case 'stream':
154
+ setPath(next, e.path, e.value, 'set');
155
+ break;
156
+ case 'toast':
157
+ next.toasts.push({ id: `${step.id}_${i}`, text: e.text, tone: e.tone });
158
+ break;
159
+ case 'navigate': {
160
+ const target = project.scenes[e.sceneId];
161
+ // 发布 IR 只有发布视图(`@/路径`,workId 为 null);dev / review 里跳转目标必须属于同一方案(D68 修复:以前发布站一跳转就报错)
162
+ if (!target || (target.workId !== scenario.workId && !(project.mode === 'publish' && target.workId === null)))
163
+ throw new PlaybackError(`Step ${step.id} navigates to a stage that is missing or outside this work: ${e.sceneId}`, {
164
+ severity: 'error',
165
+ code: 'MISSING_SCENE',
166
+ message: `Navigation target stage ${e.sceneId} is missing or outside work ${scenario.workId}`,
167
+ source: 'replay',
168
+ ref,
169
+ });
170
+ next.sceneStack.push(next.sceneId);
171
+ next.sceneId = e.sceneId;
172
+ break;
173
+ }
174
+ case 'complete':
175
+ next.completed = { text: e.text, outcome: e.outcome };
176
+ break;
177
+ }
178
+ });
179
+ next.position = state.position + 1;
180
+ return next;
181
+ }
182
+ function checkPosition(sc, scenarioId, position) {
183
+ if (!Number.isInteger(position) || position < 0 || position > sc.steps.length)
184
+ throw new JoploError('NOT_FOUND', `Position ${position} is outside scenario ${scenarioId} range 0..${sc.steps.length}`);
185
+ }
186
+ /** 从初始状态重放到指定位置,不读也不写缓存。编译器在 IR 还没定稿(之后还会改场景的初始状态)时用它。 */
187
+ export function replayTo(project, scenarioId, position) {
188
+ const sc = getScenario(project, scenarioId);
189
+ checkPosition(sc, scenarioId, position);
190
+ let s = initialState(project, scenarioId);
191
+ while (s.position < position)
192
+ s = applyStep(project, sc, s);
193
+ return s;
194
+ }
195
+ const timelines = new WeakMap();
196
+ function timelineOf(project, sc) {
197
+ let byScenario = timelines.get(project);
198
+ if (!byScenario)
199
+ timelines.set(project, (byScenario = new Map()));
200
+ let t = byScenario.get(sc.id);
201
+ if (!t || t.scenario !== sc || t.steps !== sc.steps || t.initial !== sc.initial)
202
+ byScenario.set(sc.id, (t = { scenario: sc, steps: sc.steps, initial: sc.initial, states: [], memo: new Map() }));
203
+ return t;
204
+ }
205
+ /** 挂在同一条时间线上的派生结果(例如每个位置的镜头):与状态一起缓存、一起作废。 */
206
+ export function timelineMemo(project, sc, key, compute) {
207
+ const t = timelineOf(project, sc);
208
+ if (!t.memo.has(key))
209
+ t.memo.set(key, compute());
210
+ return t.memo.get(key);
211
+ }
212
+ /** 时间线上第 position 步之后的状态(共享对象,调用方不得修改);这一步或之前的步骤回放失败时抛出当时的错误。 */
213
+ export function timelineState(project, sc, position) {
214
+ const t = timelineOf(project, sc);
215
+ if (!t.states.length)
216
+ t.states.push(initialState(project, sc.id));
217
+ while (t.states.length <= position) {
218
+ if (t.error !== undefined)
219
+ throw t.error;
220
+ try {
221
+ t.states.push(applyStep(project, sc, t.states[t.states.length - 1]));
222
+ }
223
+ catch (e) {
224
+ t.error = e ?? new JoploError('PLAYBACK_FAILED', 'Step failed');
225
+ throw t.error;
226
+ }
227
+ }
228
+ return t.states[position];
229
+ }
230
+ /** 第 position 步之后的状态(从时间线缓存取,返回独立副本)。 */
231
+ export function stateAt(project, scenarioId, position) {
232
+ const sc = getScenario(project, scenarioId);
233
+ checkPosition(sc, scenarioId, position);
234
+ return structuredClone(timelineState(project, sc, position));
235
+ }
236
+ /** 时间线上每个位置的状态(0..步数);回放失败之后的位置为 null。共享对象,只读。 */
237
+ export function timelineStates(project, scenarioId) {
238
+ const sc = project.scenarios[scenarioId];
239
+ if (!sc)
240
+ return [];
241
+ const out = [];
242
+ for (let k = 0; k <= sc.steps.length; k++) {
243
+ try {
244
+ out.push(timelineState(project, sc, k));
245
+ }
246
+ catch {
247
+ out.push(null);
248
+ }
249
+ }
250
+ return out;
251
+ }
252
+ /** 步骤 ID → 该步骤执行之后的位置。 */
253
+ export function positionAfterStep(project, scenarioId, stepId) {
254
+ const sc = getScenario(project, scenarioId);
255
+ const i = sc.steps.findIndex((s) => s.id === stepId);
256
+ if (i < 0)
257
+ throw new JoploError('NOT_FOUND', `Step ${stepId} is not in scenario ${scenarioId}`);
258
+ return i + 1;
259
+ }
260
+ /** 完整回放一个场景,收集诊断而不抛出。供校验器使用。 */
261
+ export function replay(project, scenarioId) {
262
+ let sc;
263
+ let s;
264
+ try {
265
+ sc = getScenario(project, scenarioId);
266
+ s = initialState(project, scenarioId);
267
+ }
268
+ catch (e) {
269
+ return { finalState: null, reached: 0, diagnostics: [toDiagnostic(e, { kind: 'scenario', id: scenarioId })] };
270
+ }
271
+ while (s.position < sc.steps.length) {
272
+ try {
273
+ s = applyStep(project, sc, s);
274
+ }
275
+ catch (e) {
276
+ return { finalState: s, reached: s.position, diagnostics: [toDiagnostic(e, { kind: 'scenario', id: scenarioId, scenarioId })] };
277
+ }
278
+ }
279
+ return { finalState: s, reached: s.position, diagnostics: [] };
280
+ }
281
+ function toDiagnostic(e, ref) {
282
+ if (e instanceof JoploError && e.diagnostics[0])
283
+ return e.diagnostics[0];
284
+ return { severity: 'error', code: e instanceof JoploError ? e.code : 'PLAYBACK_FAILED', message: e instanceof Error ? e.message : String(e), source: 'replay', ref };
285
+ }
286
+ /** 禁用原因的当前文字:字面量原样返回;绑定(`$ui.x`)读当前状态;空或不是文字时为 null(界面用默认说明)。 */
287
+ export function disabledReasonOf(node, state) {
288
+ const v = node.disabledReason === undefined ? undefined : resolveValue(node.disabledReason, state);
289
+ return typeof v === 'string' && v.trim() ? v : typeof v === 'number' ? String(v) : null;
290
+ }
291
+ /**
292
+ * 演示模式下用户点击了某个元素:判断应推进步骤,还是提示“当前演示未覆盖”(PRD 8.2、AC-19)。
293
+ * 流程外点击绝不能被解释为成功。
294
+ */
295
+ export function explainClick(project, state, nodeId, sceneId) {
296
+ const sc = getScenario(project, state.scenarioId);
297
+ // sceneId:用户正在看的画面(有层级的方案是某一层的画面);缺省为状态里的路径画面
298
+ const scene = getScene(project, sceneId ?? state.sceneId);
299
+ const hit = findNode(scene, nodeId);
300
+ if (!hit)
301
+ return { kind: 'static' };
302
+ const { node } = hit;
303
+ const label = nodeLabel(node);
304
+ if (isNodeDisabled(node, state))
305
+ return { kind: 'disabled', reason: disabledReasonOf(node, state) };
306
+ const current = sc.steps[state.position];
307
+ const targetOf = (s) => ('target' in s.action ? s.action.target : null);
308
+ if (current && !state.completed && targetOf(current) === nodeId && checkStep(project, sc, state, current) === null)
309
+ return { kind: 'advance' };
310
+ if (!isInteractiveType(node.type, project.plugins))
311
+ return { kind: 'static' };
312
+ if (node.unmodeled)
313
+ return { kind: 'unmodeled', label };
314
+ if (sc.steps.some((s) => targetOf(s) === nodeId))
315
+ return { kind: 'out_of_order', label, expectedCaption: current && !state.completed ? current.caption : null };
316
+ return { kind: 'not_covered', label };
317
+ }
package/dist/player.d.ts CHANGED
@@ -1,181 +1,10 @@
1
1
  /**
2
- * 播放器:纯函数的状态转换。手动体验、逐步查看、自动播放、回放校验和渲染截图
3
- * 全部调用这里,不允许任何一方另写一套按钮逻辑(PRD 8.4)。
4
- *
5
- * 位置(position)语义:0 = 场景初始状态;k = 已执行前 k 个步骤之后的状态。
6
- * “上一步”通过从初始状态重放到 k-1 实现,因此恢复的是业务可见状态,而不是撤销动画。
7
- */
8
- import { type Choice } from './catalog.js';
9
- import type { Condition, LayerIcon, Project, Scenario, Scene, SceneNode, Step } from './schema.js';
10
- import { JoploError, type Diagnostic } from './result.js';
11
- export type Toast = {
12
- id: string;
13
- text: string;
14
- tone: 'success' | 'error' | 'info';
15
- };
16
- export type PlayState = {
17
- scenarioId: string;
18
- /** 已执行的步骤数。 */
19
- position: number;
20
- sceneId: string;
21
- ui: Record<string, unknown>;
22
- data: Record<string, unknown>;
23
- inputs: Record<string, unknown>;
24
- /** 最近一个步骤产生的 Toast;下一步开始时清空,保证“上一步”可复现。 */
25
- toasts: Toast[];
26
- completed: null | {
27
- text: string;
28
- outcome: 'success' | 'failure' | 'cancelled';
29
- };
30
- /** 画面栈,用于 back 动作。 */
31
- sceneStack: string[];
32
- };
33
- export declare function getScenario(project: Project, scenarioId: string): Scenario;
34
- export declare function getScene(project: Project, sceneId: string): Scene;
35
- export declare function walkNodes(root: SceneNode, visit: (node: SceneNode, ancestors: SceneNode[]) => void): void;
36
- /** 返回节点及其祖先链(自根向下,不含自身);找不到返回 null。 */
37
- export declare function findNode(scene: Scene, nodeId: string): {
38
- node: SceneNode;
39
- ancestors: SceneNode[];
40
- } | null;
41
- export declare function readPath(state: Pick<PlayState, 'ui' | 'data' | 'inputs'>, path: string): unknown;
42
- /**
43
- * 属性值若是 `$ui.x` 形式的整值绑定,则从状态读取;对象与数组逐项解析
44
- * (例如 declared element 的 navbar={{ collapsed: { mobile: $.ui.navClosed } }});其余原样返回。
45
- */
46
- export declare function resolveValue(value: unknown, state: Pick<PlayState, 'ui' | 'data' | 'inputs'>): unknown;
47
- export declare function resolveProps(node: SceneNode, state: Pick<PlayState, 'ui' | 'data' | 'inputs'>): Record<string, unknown>;
48
- export declare function evaluateCondition(cond: Condition, state: Pick<PlayState, 'ui' | 'data' | 'inputs'>): boolean;
49
- /** 画面的舞台宽度(由页面的 viewport 决定)。 */
50
- export declare function sceneWidth(scene: Pick<Scene, 'viewport'>): number;
51
- /**
52
- * 节点自身是否显示:when、declared element 的 opened(兼容旧写法 open),
53
- * 以及给定舞台宽度时的 visibleFrom / hiddenFrom。
54
- */
55
- export declare function isSelfVisible(node: SceneNode, state: PlayState, width?: number): boolean;
56
- export type LayoutRegion = {
57
- size: number;
58
- collapsed: boolean;
59
- mobile: boolean;
60
- };
61
- /** Declarative layout regions share the same width/state interpretation in drawing and playback. */
62
- export declare function layoutRegions(node: SceneNode, state: Pick<PlayState, 'ui' | 'data' | 'inputs'>, width: number): Record<string, LayoutRegion | null>;
63
- /** 节点在画面中是否可见:自身与所有祖先都可见;按画面宽度计算断点与 declared element 收起。 */
64
- export declare function isNodeVisible(scene: Scene, nodeId: string, state: PlayState, width?: number): boolean;
65
- /** Enumerate declared data, descendant values, or a numeric range. No declaration means unconstrained input. */
66
- export declare function choicesOf(node: SceneNode, state: Pick<PlayState, 'ui' | 'data' | 'inputs'>): Choice[] | null;
67
- export declare function isNodeDisabled(node: SceneNode, state: PlayState): boolean;
68
- export declare function initialState(project: Project, scenarioId: string): PlayState;
69
- export declare class PlaybackError extends JoploError {
70
- constructor(message: string, diagnostic: Diagnostic);
71
- }
72
- /**
73
- * 校验当前步骤能否在给定状态下执行;返回诊断(null 表示可执行)。
74
- * 手动体验时,UI 也用它判断用户点击的是不是“当前步骤的目标”。
75
- */
76
- export declare function checkStep(project: Project, scenario: Scenario, state: PlayState, step: Step): Diagnostic | null;
77
- /** 执行 scenario.steps[state.position],返回新状态(不修改入参)。 */
78
- export declare function applyStep(project: Project, scenario: Scenario, state: PlayState): PlayState;
79
- /** 从初始状态重放到指定位置。 */
80
- export declare function stateAt(project: Project, scenarioId: string, position: number): PlayState;
81
- /** 步骤 ID → 该步骤执行之后的位置。 */
82
- export declare function positionAfterStep(project: Project, scenarioId: string, stepId: string): number;
83
- /** 完整回放一个场景,收集诊断而不抛出。供校验器使用。 */
84
- export declare function replay(project: Project, scenarioId: string): {
85
- finalState: PlayState | null;
86
- reached: number;
87
- diagnostics: Diagnostic[];
88
- };
89
- export type ClickVerdict = {
90
- kind: 'advance';
91
- } | {
92
- kind: 'disabled';
93
- reason: string | null;
94
- } | {
95
- kind: 'unmodeled';
96
- label: string;
97
- } | {
98
- kind: 'out_of_order';
99
- label: string;
100
- expectedCaption: string | null;
101
- } | {
102
- kind: 'not_covered';
103
- label: string;
104
- } | {
105
- kind: 'static';
106
- };
107
- /** 禁用原因的当前文字:字面量原样返回;绑定(`$ui.x`)读当前状态;空或不是文字时为 null(界面用默认说明)。 */
108
- export declare function disabledReasonOf(node: SceneNode, state: Pick<PlayState, 'ui' | 'data' | 'inputs'>): string | null;
109
- /**
110
- * 演示模式下用户点击了某个元素:判断应推进步骤,还是提示“当前演示未覆盖”(PRD 8.2、AC-19)。
111
- * 流程外点击绝不能被解释为成功。
112
- */
113
- export declare function explainClick(project: Project, state: PlayState, nodeId: string, sceneId?: string): ClickVerdict;
114
- /** 方案的层级(源码顺序):每层一个完全独立的画面。没有声明时为空,演示照常显示路径页面。 */
115
- export declare function layersOf(project: Project, scenarioId: string | null): {
116
- id: string;
117
- title: string;
118
- sceneId: string;
119
- icon: LayerIcon;
120
- }[];
121
- /** 包含某个元素的层级(多层都有同名 id 时都返回)。 */
122
- export declare function layersWithNode(project: Project, scenarioId: string, nodeId: string): string[];
123
- /**
124
- * 步骤目标所在的画面:有层级的方案在各层画面里找(优先当前可见的那一层),否则是状态里的路径画面。
125
- * 回放校验、select 取值都用它。
126
- */
127
- export declare function sceneOfTarget(project: Project, scenario: Scenario, state: PlayState, target: string): Scene | undefined;
128
- /** 某一步的镜头:导演层与每个层级当前对准的元素(空数组 = 这一层的整体)。 */
129
- export type Camera = {
130
- directorLayer: string;
131
- perLayer: Record<string, string[]>;
132
- };
133
- /**
134
- * 第 position 步之后的镜头。纯函数:只由步骤上的 shots / directorLayer 推导,不进入 ui / data / inputs。
135
- * 初始导演层 = 第一个声明的层级(没有层级时是路径页面 @page),各层都是整体。
136
- * 没有 shot 的步骤沿用上一步;shot()(@director)让当时的导演层回到整体。
137
- * 手动、逐步、自动播放、回放、renderStep、视频录制和发布站都用它。
138
- */
139
- export declare function cameraAt(project: Project, scenarioId: string, position: number): Camera;
140
- /** 第 position 步之后用户看到的画面:有层级时是导演层(或手动选的层)的画面,否则是状态里的路径画面。 */
141
- export declare function displaySceneId(project: Project, scenarioId: string, position: number, layer?: string | null): string;
142
- /** 第 index 步(0 起)的镜头是否改变了某一层(“只重放这一层”时,不变的步骤快速带过)。 */
143
- export declare function stepTouchesLayer(project: Project, scenarioId: string, index: number, layer: string): boolean;
144
- export type CardAction = Extract<Step['action'], {
145
- type: 'card';
146
- }>;
147
- export type RoleInfo = {
148
- id: string;
149
- name: string;
150
- desc: string;
151
- color: string;
152
- };
153
- /** 第 position 步之后是否停在一张过渡卡上(最近执行的一步是过渡卡);是则返回卡片内容。 */
154
- export declare function cardAt(project: Project, scenarioId: string | null | undefined, position: number): CardAction | null;
155
- /** 方案所属功能里可引用的角色(有 id 的)。 */
156
- export declare function roleOf(project: Project, optionId: string | null | undefined, roleId: string | null | undefined): RoleInfo | null;
157
- /** 某个画面是谁的(层级声明了 role 时);路径页面与没有角色的层级返回 null。 */
158
- export declare function roleOfScene(project: Project, sceneId: string | null | undefined): RoleInfo | null;
159
- /** 第 index 步(0 起)流式输出的状态路径与文字。 */
160
- export declare function streamsOf(step: Step | undefined): {
161
- path: string;
162
- value: string;
163
- }[];
164
- /** 动作和业务效果完全相同的公共前缀步数;字幕、镜头、分叉等展示信息不参与。 */
165
- export declare function commonPrefix(a: readonly Pick<Step, 'action' | 'effects'>[], b: readonly Pick<Step, 'action' | 'effects'>[]): number;
166
- export declare function forksAt(project: Project, scenarioId: string | null | undefined, position: number): Step['forks'];
167
- /** 与 Toast 一样只显示最近一步,目标是否可见由当前显示画面决定。 */
168
- export declare function marksAt(project: Project, scenarioId: string | null | undefined, position: number): Step['marks'];
169
- export type StateChange = {
170
- path: string;
171
- before: unknown;
172
- after: unknown;
173
- };
174
- /** 对比 core 回放产生的相邻状态:对象按叶子展开,数组作为一个值;不包含动画、Toast 等展示状态。 */
175
- export declare function changedAt(project: Project, scenarioId: string | null | undefined, position: number): StateChange[];
176
- /** 已定位的一步的路线;字幕也用这一个投影入口。 */
177
- export declare function forksOf(step: Step | undefined): Step['forks'];
178
- /** 按键记录的 IR 入口:静态取最近一步,动画预览与键帽分词由 web 负责。 */
179
- export declare function keyboardActionOf(step: Step | undefined): Extract<Step['action'], {
180
- type: 'type' | 'press';
181
- }> | null;
2
+ * 播放器的出口(为导入方保留一个名字),实现分三个模块:
3
+ * - scene-query.ts:画面查询——查找元素、取属性的值、可见与禁用、选项与分栏、层级;
4
+ * - playback.ts:回放——状态转换(applyStep)、时间线缓存(stateAt)、回放校验、解释一次点击;
5
+ * - presentation.ts:演示投影——镜头、过渡卡、角色、流式输出、分叉、标注、状态变化。
6
+ * 依赖方向:scene-query ← playback ← presentation。
7
+ */
8
+ export * from './scene-query.js';
9
+ export * from './playback.js';
10
+ export * from './presentation.js';