@joplo-app/core 0.2.18 → 0.4.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/actions.d.ts +6 -0
- package/dist/actions.js +34 -0
- package/dist/agent-skill.d.ts +9 -15
- package/dist/agent-skill.js +41 -44
- package/dist/auto-caption.d.ts +3 -0
- package/dist/auto-caption.js +33 -0
- package/dist/catalog.d.ts +39 -47
- package/dist/catalog.js +27 -334
- package/dist/compile.d.ts +2 -8
- package/dist/compile.js +230 -393
- package/dist/content-i18n.js +27 -16
- package/dist/feature-diff.d.ts +9 -9
- package/dist/feature-diff.js +28 -6
- package/dist/focus.d.ts +6 -2
- package/dist/focus.js +28 -36
- package/dist/guide.d.ts +10 -12
- package/dist/guide.js +372 -594
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/media.d.ts +10 -0
- package/dist/media.js +43 -0
- package/dist/node.d.ts +1 -2
- package/dist/node.js +1 -2
- package/dist/outline.js +1 -1
- package/dist/pace.d.ts +4 -1
- package/dist/pace.js +7 -3
- package/dist/player.d.ts +8 -41
- package/dist/player.js +83 -147
- package/dist/playground.d.ts +38 -0
- package/dist/playground.js +111 -0
- package/dist/plugin-data.d.ts +11 -0
- package/dist/plugin-data.js +96 -0
- package/dist/plugins/compiler.d.ts +67 -0
- package/dist/plugins/compiler.js +434 -0
- package/dist/plugins/data.d.ts +12 -0
- package/dist/plugins/data.js +120 -0
- package/dist/result.d.ts +1 -1
- package/dist/result.js +1 -0
- package/dist/runtime.d.ts +22 -0
- package/dist/runtime.js +18 -0
- package/dist/schema.d.ts +593 -112
- package/dist/schema.js +62 -52
- package/dist/scope.js +14 -5
- package/dist/step-identity.d.ts +1 -1
- package/dist/step-identity.js +1 -1
- package/dist/themes.d.ts +7 -0
- package/dist/themes.js +5 -0
- package/dist/traits.d.ts +7 -0
- package/dist/traits.js +26 -0
- package/dist/validate.js +17 -4
- package/package.json +7 -4
- package/dist/diagram/elk.d.ts +0 -6
- package/dist/diagram/elk.js +0 -56
- package/dist/diagram/graph-layout.d.ts +0 -123
- package/dist/diagram/graph-layout.js +0 -620
- package/dist/diagram/index.d.ts +0 -41
- package/dist/diagram/index.js +0 -92
- package/dist/diagram/model.d.ts +0 -217
- package/dist/diagram/model.js +0 -189
- package/dist/diagram/sequence-layout.d.ts +0 -12
- package/dist/diagram/sequence-layout.js +0 -185
package/dist/index.d.ts
CHANGED
|
@@ -16,10 +16,12 @@ export * from './scope.js';
|
|
|
16
16
|
export * from './agent-skill.js';
|
|
17
17
|
export * from './pace.js';
|
|
18
18
|
export * from './outline.js';
|
|
19
|
-
export * from './diagram/index.js';
|
|
20
19
|
export * from './voice.js';
|
|
21
20
|
export * from './content-i18n.js';
|
|
22
21
|
export * from './local-review.js';
|
|
23
22
|
export * from './feature-diff.js';
|
|
24
23
|
export * from './step-identity.js';
|
|
25
24
|
export * from './auto-caption.js';
|
|
25
|
+
export { nodeResourceIds, resolveResourceProps, mediaAt, advanceMedia, mediaResourceIds, pruneMediaAssets } from './media.js';
|
|
26
|
+
export { projectThemes } from './themes.js';
|
|
27
|
+
export * from './playground.js';
|
package/dist/index.js
CHANGED
|
@@ -16,10 +16,12 @@ export * from "./scope.js";
|
|
|
16
16
|
export * from "./agent-skill.js";
|
|
17
17
|
export * from "./pace.js";
|
|
18
18
|
export * from "./outline.js";
|
|
19
|
-
export * from "./diagram/index.js";
|
|
20
19
|
export * from "./voice.js";
|
|
21
20
|
export * from "./content-i18n.js";
|
|
22
21
|
export * from "./local-review.js";
|
|
23
22
|
export * from "./feature-diff.js";
|
|
24
23
|
export * from "./step-identity.js";
|
|
25
24
|
export * from "./auto-caption.js";
|
|
25
|
+
export { nodeResourceIds, resolveResourceProps, mediaAt, advanceMedia, mediaResourceIds, pruneMediaAssets } from "./media.js";
|
|
26
|
+
export { projectThemes } from "./themes.js";
|
|
27
|
+
export * from "./playground.js";
|
package/dist/media.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MediaSnapshot } from '@joplo-app/kit/plugin';
|
|
2
|
+
import type { Project } from './schema.js';
|
|
3
|
+
/** Pure clock projection. Neither resource compilation nor plugin semantics run here. */
|
|
4
|
+
export declare function advanceMedia(snapshot: MediaSnapshot, elapsedMs: number): MediaSnapshot;
|
|
5
|
+
export declare function mediaAt(project: Project, scenarioId: string, position: number, elapsedMs?: number): MediaSnapshot;
|
|
6
|
+
export declare function mediaResourceIds(project: Pick<Project, 'scenarios'>): Set<string>;
|
|
7
|
+
export declare function pruneMediaAssets<T extends Project>(project: T): T;
|
|
8
|
+
/** Node-local references are data only; the input and compiler stay on the author machine. */
|
|
9
|
+
export declare function nodeResourceIds(value: unknown, out?: Set<string>): Set<string>;
|
|
10
|
+
export declare function resolveResourceProps<T>(value: T, urls: Readonly<Record<string, string>>): T;
|
package/dist/media.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** Pure clock projection. Neither resource compilation nor plugin semantics run here. */
|
|
2
|
+
export function advanceMedia(snapshot, elapsedMs) {
|
|
3
|
+
const elapsed = Math.max(0, elapsedMs);
|
|
4
|
+
return Object.fromEntries(Object.entries(snapshot).flatMap(([id, t]) => t.stopAfterMs !== undefined && elapsed >= t.stopAfterMs ? [] : [[id, { ...t, offsetMs: t.offsetMs + elapsed, ...(t.stopAfterMs !== undefined ? { stopAfterMs: t.stopAfterMs - elapsed, volume: t.volume * (1 - elapsed / t.stopAfterMs) } : {}) }]]));
|
|
5
|
+
}
|
|
6
|
+
export function mediaAt(project, scenarioId, position, elapsedMs = 0) {
|
|
7
|
+
const sc = project.scenarios[scenarioId];
|
|
8
|
+
const snapshot = position ? sc?.steps[position - 1]?.media : sc?.media;
|
|
9
|
+
return advanceMedia(snapshot ?? {}, elapsedMs);
|
|
10
|
+
}
|
|
11
|
+
export function mediaResourceIds(project) {
|
|
12
|
+
return new Set(Object.values(project.scenarios).flatMap(sc => [sc, ...sc.steps].flatMap(s => Object.values(s.media ?? {}).map(t => t.resource))));
|
|
13
|
+
}
|
|
14
|
+
export function pruneMediaAssets(project) {
|
|
15
|
+
if (!project.mediaAssets)
|
|
16
|
+
return project;
|
|
17
|
+
const used = mediaResourceIds(project);
|
|
18
|
+
for (const id of nodeResourceIds(project))
|
|
19
|
+
used.add(id);
|
|
20
|
+
return { ...project, ...(project.mediaInfo ? { mediaInfo: Object.fromEntries(Object.entries(project.mediaInfo).filter(([id]) => used.has(id))) } : {}), mediaAssets: Object.fromEntries(Object.entries(project.mediaAssets).filter(([id]) => used.has(id))) };
|
|
21
|
+
}
|
|
22
|
+
/** Node-local references are data only; the input and compiler stay on the author machine. */
|
|
23
|
+
export function nodeResourceIds(value, out = new Set()) {
|
|
24
|
+
if (typeof value === 'string' && value.startsWith('joplo-resource:'))
|
|
25
|
+
out.add(value.slice(15));
|
|
26
|
+
else if (Array.isArray(value))
|
|
27
|
+
for (const v of value)
|
|
28
|
+
nodeResourceIds(v, out);
|
|
29
|
+
else if (value && typeof value === 'object')
|
|
30
|
+
for (const [k, v] of Object.entries(value))
|
|
31
|
+
if (k !== 'mediaAssets')
|
|
32
|
+
nodeResourceIds(v, out);
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
export function resolveResourceProps(value, urls) {
|
|
36
|
+
if (typeof value === 'string' && value.startsWith('joplo-resource:'))
|
|
37
|
+
return (urls[value.slice(15)] ?? '');
|
|
38
|
+
if (Array.isArray(value))
|
|
39
|
+
return value.map(v => resolveResourceProps(v, urls));
|
|
40
|
+
if (value && typeof value === 'object')
|
|
41
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, resolveResourceProps(v, urls)]));
|
|
42
|
+
return value;
|
|
43
|
+
}
|
package/dist/node.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/** 仅限 Node 端的入口(文件系统加载)。浏览器端只用 `@joplo-app/core`。 */
|
|
2
2
|
export * from './load.js';
|
|
3
3
|
export * from './local-review-files.js';
|
|
4
|
-
|
|
5
|
-
export { elkLayout, runElk } from './diagram/elk.js';
|
|
4
|
+
export { enabledPlugins } from './plugins/compiler.js';
|
package/dist/node.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/** 仅限 Node 端的入口(文件系统加载)。浏览器端只用 `@joplo-app/core`。 */
|
|
2
2
|
export * from "./load.js";
|
|
3
3
|
export * from "./local-review-files.js";
|
|
4
|
-
|
|
5
|
-
export { elkLayout, runElk } from "./diagram/elk.js";
|
|
4
|
+
export { enabledPlugins } from "./plugins/compiler.js";
|
package/dist/outline.js
CHANGED
|
@@ -14,7 +14,7 @@ export function stepTexts(step) {
|
|
|
14
14
|
}
|
|
15
15
|
/** 一个场景按 1× 自动播放大约多久(毫秒):每一步取 hold、阅读停留(stepDwell)与旁白朗读估算(narrate / say)中最长的,再求和。 */
|
|
16
16
|
export function scenarioEstimateMs(scenario) {
|
|
17
|
-
return scenario.steps.reduce((sum, step) => sum + Math.max(holdMsOf(step), voiceMs(step.narrate ?? step.say), stepDwell({ texts: stepTexts(step), cameraMoved: step.shots.length > 0 || !!step.directorLayer, streams: step.effects.flatMap((e) => (e.type === 'stream' ? [e.value] : [])) })), 0);
|
|
17
|
+
return scenario.steps.reduce((sum, step) => sum + Math.max(holdMsOf(step), voiceMs(step.narrate ?? step.say), stepDwell({ texts: stepTexts(step), paced: step.hold !== undefined, cameraMoved: step.shots.length > 0 || !!step.directorLayer, streams: step.effects.flatMap((e) => (e.type === 'stream' ? [e.value] : [])) })), 0);
|
|
18
18
|
}
|
|
19
19
|
export function outline(project, opts = {}) {
|
|
20
20
|
if (opts.optionId && !Object.hasOwn(project.options, opts.optionId))
|
package/dist/pace.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ export declare function streamMs(text: string, speed?: number): number;
|
|
|
20
20
|
export declare function readChars(...texts: (string | null | undefined)[]): number;
|
|
21
21
|
/** 保留 readChars 的非空白字符口径,宽字符 125ms、拉丁字符 1000/15ms;先截断阅读时间,再应用倍速。 */
|
|
22
22
|
export declare function readingMs(...texts: (string | null | undefined)[]): number;
|
|
23
|
+
/** 不套 3 秒下限的阅读时间(作者用 hold 掌握节奏时,D92):仍按字数,最多 MAX_READ_MS。 */
|
|
24
|
+
export declare function rawReadingMs(...texts: (string | null | undefined)[]): number;
|
|
23
25
|
/**
|
|
24
26
|
* 这一步提交之后至少停留多久(毫秒)。
|
|
25
27
|
* text:说明与解说;cameraMoved:这一步镜头有变化(切层或换焦点);dotMs:本步 active 连线上小点跑一圈的最长时间(没有为 0)。
|
|
@@ -29,7 +31,8 @@ export declare function stepDwell(o: {
|
|
|
29
31
|
speed?: number;
|
|
30
32
|
cameraMoved?: boolean;
|
|
31
33
|
dotMs?: number; /** 本步流式输出的文字(D56):等它们出完再加阅读时间。 */
|
|
32
|
-
streams?: string[];
|
|
34
|
+
streams?: string[]; /** 作者写了 hold(D92):节奏由作者掌握,阅读时间不套 3 秒下限(仍按字数)。 */
|
|
35
|
+
paced?: boolean;
|
|
33
36
|
}): number;
|
|
34
37
|
/** 朗读估算(旁白 / 台词):中日韩约每秒 4.5 字、拉丁文字约每秒 13 个非空白字符(约 2.5 词),读完再留 0.45 秒换气。 */
|
|
35
38
|
export declare const VOICE_CJK_MS = 220;
|
package/dist/pace.js
CHANGED
|
@@ -35,6 +35,10 @@ export function readChars(...texts) {
|
|
|
35
35
|
}
|
|
36
36
|
/** 保留 readChars 的非空白字符口径,宽字符 125ms、拉丁字符 1000/15ms;先截断阅读时间,再应用倍速。 */
|
|
37
37
|
export function readingMs(...texts) {
|
|
38
|
+
return Math.min(MAX_READ_MS, Math.max(MIN_DWELL, rawReadingMs(...texts)));
|
|
39
|
+
}
|
|
40
|
+
/** 不套 3 秒下限的阅读时间(作者用 hold 掌握节奏时,D92):仍按字数,最多 MAX_READ_MS。 */
|
|
41
|
+
export function rawReadingMs(...texts) {
|
|
38
42
|
let ms = 0;
|
|
39
43
|
for (const t of texts)
|
|
40
44
|
if (t)
|
|
@@ -43,7 +47,7 @@ export function readingMs(...texts) {
|
|
|
43
47
|
continue;
|
|
44
48
|
ms += (ch.codePointAt(0) ?? 0) > 0x2e80 ? MS_PER_CHAR : LATIN_MS_PER_CHAR;
|
|
45
49
|
}
|
|
46
|
-
return Math.min(MAX_READ_MS,
|
|
50
|
+
return Math.min(MAX_READ_MS, ms);
|
|
47
51
|
}
|
|
48
52
|
/**
|
|
49
53
|
* 这一步提交之后至少停留多久(毫秒)。
|
|
@@ -51,12 +55,12 @@ export function readingMs(...texts) {
|
|
|
51
55
|
*/
|
|
52
56
|
export function stepDwell(o) {
|
|
53
57
|
const speed = o.speed && o.speed > 0 ? o.speed : 1;
|
|
54
|
-
const read = readingMs(...o.texts) / speed;
|
|
58
|
+
const read = (o.paced ? rawReadingMs(...o.texts) : readingMs(...o.texts)) / speed;
|
|
55
59
|
const cam = o.cameraMoved ? CAMERA_MS + SETTLE : 0;
|
|
56
60
|
const dots = o.dotMs && o.dotMs > 0 ? o.dotMs + SETTLE : 0;
|
|
57
61
|
// 流式输出:先等最长的一段出完,再留出读完它的时间(按出完之后再读一遍的一半计)
|
|
58
62
|
const longest = Math.max(0, ...(o.streams ?? []).map((t) => streamMs(t, speed)));
|
|
59
|
-
const streamed = longest ? longest + Math.max(MIN_DWELL / speed, read / 2) : 0;
|
|
63
|
+
const streamed = longest ? longest + Math.max((o.paced ? 0 : MIN_DWELL) / speed, read / 2) : 0;
|
|
60
64
|
return Math.round(Math.max(read, cam, dots, streamed));
|
|
61
65
|
}
|
|
62
66
|
/** 朗读估算(旁白 / 台词):中日韩约每秒 4.5 字、拉丁文字约每秒 13 个非空白字符(约 2.5 词),读完再留 0.45 秒换气。 */
|
package/dist/player.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ export declare function findNode(scene: Scene, nodeId: string): {
|
|
|
41
41
|
export declare function readPath(state: Pick<PlayState, 'ui' | 'data' | 'inputs'>, path: string): unknown;
|
|
42
42
|
/**
|
|
43
43
|
* 属性值若是 `$ui.x` 形式的整值绑定,则从状态读取;对象与数组逐项解析
|
|
44
|
-
* (例如
|
|
44
|
+
* (例如 declared element 的 navbar={{ collapsed: { mobile: $.ui.navClosed } }});其余原样返回。
|
|
45
45
|
*/
|
|
46
46
|
export declare function resolveValue(value: unknown, state: Pick<PlayState, 'ui' | 'data' | 'inputs'>): unknown;
|
|
47
47
|
export declare function resolveProps(node: SceneNode, state: Pick<PlayState, 'ui' | 'data' | 'inputs'>): Record<string, unknown>;
|
|
@@ -49,37 +49,20 @@ export declare function evaluateCondition(cond: Condition, state: Pick<PlayState
|
|
|
49
49
|
/** 画面的舞台宽度(由页面的 viewport 决定)。 */
|
|
50
50
|
export declare function sceneWidth(scene: Pick<Scene, 'viewport'>): number;
|
|
51
51
|
/**
|
|
52
|
-
* 节点自身是否显示:when、
|
|
52
|
+
* 节点自身是否显示:when、declared element 的 opened(兼容旧写法 open),
|
|
53
53
|
* 以及给定舞台宽度时的 visibleFrom / hiddenFrom。
|
|
54
54
|
*/
|
|
55
55
|
export declare function isSelfVisible(node: SceneNode, state: PlayState, width?: number): boolean;
|
|
56
|
-
export type
|
|
56
|
+
export type LayoutRegion = {
|
|
57
57
|
size: number;
|
|
58
58
|
collapsed: boolean;
|
|
59
|
+
mobile: boolean;
|
|
59
60
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
navbar: ShellRegion | null;
|
|
64
|
-
aside: ShellRegion | null;
|
|
65
|
-
padding: unknown;
|
|
66
|
-
mobile: {
|
|
67
|
-
navbar: boolean;
|
|
68
|
-
aside: boolean;
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
* AppShell 在给定舞台宽度下的布局:窄于 navbar/aside 的 breakpoint 时为“移动布局”,
|
|
73
|
-
* 默认收起(collapsed.mobile 未写时视为 true,写 false 或绑定为假时展开);宽于断点时按 collapsed.desktop(默认展开)。
|
|
74
|
-
* 渲染器与播放器共用,保证“看得见”和“能操作”一致。
|
|
75
|
-
*/
|
|
76
|
-
export declare function appShellLayout(props: Record<string, unknown> | undefined, state: Pick<PlayState, 'ui' | 'data' | 'inputs'>, width: number): ShellLayout;
|
|
77
|
-
/** 节点在画面中是否可见:自身与所有祖先都可见;按画面宽度计算断点与 AppShell 收起。 */
|
|
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 收起。 */
|
|
78
64
|
export declare function isNodeVisible(scene: Scene, nodeId: string, state: PlayState, width?: number): boolean;
|
|
79
|
-
/**
|
|
80
|
-
* 可选项:Select / MultiSelect / SegmentedControl 读 data;Radio.Group 读子 Radio;Tabs 读 Tabs.Tab;
|
|
81
|
-
* Accordion 读 Accordion.Item;Pagination 为 1..total。没有可枚举选项时返回 null(select 动作不做限制)。
|
|
82
|
-
*/
|
|
65
|
+
/** Enumerate declared data, descendant values, or a numeric range. No declaration means unconstrained input. */
|
|
83
66
|
export declare function choicesOf(node: SceneNode, state: Pick<PlayState, 'ui' | 'data' | 'inputs'>): Choice[] | null;
|
|
84
67
|
export declare function isNodeDisabled(node: SceneNode, state: PlayState): boolean;
|
|
85
68
|
export declare function initialState(project: Project, scenarioId: string): PlayState;
|
|
@@ -158,22 +141,6 @@ export declare function cameraAt(project: Project, scenarioId: string, position:
|
|
|
158
141
|
export declare function displaySceneId(project: Project, scenarioId: string, position: number, layer?: string | null): string;
|
|
159
142
|
/** 第 index 步(0 起)的镜头是否改变了某一层(“只重放这一层”时,不变的步骤快速带过)。 */
|
|
160
143
|
export declare function stepTouchesLayer(project: Project, scenarioId: string, index: number, layer: string): boolean;
|
|
161
|
-
export type DiagramState = 'idle' | 'active' | 'ok' | 'error' | 'dim';
|
|
162
|
-
/** 元素 id → 推算的 state;reverse = 这条连线本步逆向走(流动的小点从 to 走向 from)。没出现的 id 是 idle。 */
|
|
163
|
-
export type DiagramStates = Record<string, {
|
|
164
|
-
state: DiagramState;
|
|
165
|
-
reverse?: boolean;
|
|
166
|
-
}>;
|
|
167
|
-
/**
|
|
168
|
-
* 第 position 步之后 Diagram 的状态(纯函数,与 cameraAt 同级;回放、renderStep、视频、发布站都用它):
|
|
169
|
-
* - 本步 trace 到的:active;之前 trace 过、本步没再 trace 的:ok;
|
|
170
|
-
* - trace.fail:路径上的连线与终点节点 error(起点等其余节点 active),保持到之后又被 trace 成功;
|
|
171
|
-
* - trace.skip:路径上的节点与连线 dim(保持到之后又被 trace);
|
|
172
|
-
* - 从未涉及的:idle(不在结果里)。
|
|
173
|
-
* - 分组(D69):路径经过的节点所在的各级分组同样 active → ok;trace.fail 时终点所在的最内层分组 error;trace.skip 不改分组。
|
|
174
|
-
* 节点或连线上显式写的 state 优先于推算结果(由渲染器处理)。
|
|
175
|
-
*/
|
|
176
|
-
export declare function diagramStateAt(project: Project, scenarioId: string | null | undefined, position: number): DiagramStates;
|
|
177
144
|
export type CardAction = Extract<Step['action'], {
|
|
178
145
|
type: 'card';
|
|
179
146
|
}>;
|
package/dist/player.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { pluginActionSpec, validActionData } from "./actions.js";
|
|
1
2
|
/**
|
|
2
3
|
* 播放器:纯函数的状态转换。手动体验、逐步查看、自动播放、回放校验和渲染截图
|
|
3
4
|
* 全部调用这里,不允许任何一方另写一套按钮逻辑(PRD 8.4)。
|
|
@@ -5,7 +6,7 @@
|
|
|
5
6
|
* 位置(position)语义:0 = 场景初始状态;k = 已执行前 k 个步骤之后的状态。
|
|
6
7
|
* “上一步”通过从初始状态重放到 k-1 实现,因此恢复的是业务可见状态,而不是撤销动画。
|
|
7
8
|
*/
|
|
8
|
-
import { DIRECTOR_LAYER,
|
|
9
|
+
import { DIRECTOR_LAYER, PAGE_LAYER, isInteractiveType, VIEWPORT_SIZE, atWidth, childWidth, breakpointPx, choicesFromData, hiddenAtWidth, matchChoice, nodeLabel } from "./catalog.js";
|
|
9
10
|
import { JoploError } from "./result.js";
|
|
10
11
|
// ---------- 查找 ----------
|
|
11
12
|
export function getScenario(project, scenarioId) {
|
|
@@ -52,7 +53,7 @@ export function readPath(state, path) {
|
|
|
52
53
|
const BINDING = /^\$((?:ui|data|inputs)(?:\.[A-Za-z0-9_-]+)*)$/;
|
|
53
54
|
/**
|
|
54
55
|
* 属性值若是 `$ui.x` 形式的整值绑定,则从状态读取;对象与数组逐项解析
|
|
55
|
-
* (例如
|
|
56
|
+
* (例如 declared element 的 navbar={{ collapsed: { mobile: $.ui.navClosed } }});其余原样返回。
|
|
56
57
|
*/
|
|
57
58
|
export function resolveValue(value, state) {
|
|
58
59
|
if (typeof value === 'string') {
|
|
@@ -114,14 +115,14 @@ export function sceneWidth(scene) {
|
|
|
114
115
|
return VIEWPORT_SIZE[scene.viewport === 'mobile' ? 'mobile' : 'desktop'].width;
|
|
115
116
|
}
|
|
116
117
|
/**
|
|
117
|
-
* 节点自身是否显示:when、
|
|
118
|
+
* 节点自身是否显示:when、declared element 的 opened(兼容旧写法 open),
|
|
118
119
|
* 以及给定舞台宽度时的 visibleFrom / hiddenFrom。
|
|
119
120
|
*/
|
|
120
121
|
export function isSelfVisible(node, state, width) {
|
|
121
122
|
if (node.when && !evaluateCondition(node.when, state))
|
|
122
123
|
return false;
|
|
123
|
-
if (
|
|
124
|
-
const opened = node.
|
|
124
|
+
if (node.traits?.gate) {
|
|
125
|
+
const opened = node.traits.gate.map(key => node.props?.[key]).find(v => v !== undefined);
|
|
125
126
|
if (!resolveValue(opened, state))
|
|
126
127
|
return false;
|
|
127
128
|
}
|
|
@@ -129,43 +130,27 @@ export function isSelfVisible(node, state, width) {
|
|
|
129
130
|
return false;
|
|
130
131
|
return true;
|
|
131
132
|
}
|
|
132
|
-
/**
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return { size: num(o.height, 60), collapsed: Boolean(resolveValue(o.collapsed, state)) };
|
|
152
|
-
};
|
|
153
|
-
const mobile = { navbar: false, aside: false };
|
|
154
|
-
const side = (key) => {
|
|
155
|
-
const o = obj(p[key]);
|
|
156
|
-
if (!o)
|
|
157
|
-
return null;
|
|
158
|
-
const bp = breakpointPx(o.breakpoint);
|
|
159
|
-
const isMobile = bp !== null && width < bp;
|
|
160
|
-
mobile[key] = isMobile;
|
|
161
|
-
const col = resolveValue(o.collapsed, state);
|
|
162
|
-
const c = col && typeof col === 'object' ? col : {};
|
|
163
|
-
const collapsed = isMobile ? (c.mobile === undefined ? true : Boolean(c.mobile)) : Boolean(c.desktop);
|
|
164
|
-
return { size: num(o.width, key === 'navbar' ? 260 : 300), collapsed };
|
|
165
|
-
};
|
|
166
|
-
return { header: bar('header'), footer: bar('footer'), navbar: side('navbar'), aside: side('aside'), padding: p.padding, mobile };
|
|
133
|
+
/** Declarative layout regions share the same width/state interpretation in drawing and playback. */
|
|
134
|
+
export function layoutRegions(node, state, width) {
|
|
135
|
+
const regions = {};
|
|
136
|
+
for (const [key, spec] of Object.entries(node.traits?.layout ?? {})) {
|
|
137
|
+
const value = resolveValue(atWidth(node.props?.[key], width), state);
|
|
138
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
139
|
+
regions[key] = null;
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
const props = value;
|
|
143
|
+
const bp = spec.breakpoint ? breakpointPx(props.breakpoint) : null;
|
|
144
|
+
const mobile = bp !== null && width < bp;
|
|
145
|
+
const collapsed = resolveValue(props.collapsed, state);
|
|
146
|
+
const config = collapsed && typeof collapsed === 'object' ? collapsed : {};
|
|
147
|
+
const rawSize = atWidth(resolveValue(props[spec.size], state), width);
|
|
148
|
+
const size = typeof rawSize === 'number' && Number.isFinite(rawSize) ? rawSize : typeof rawSize === 'string' && /^\d+(px)?$/.test(rawSize) ? Number.parseInt(rawSize, 10) : spec.defaultSize;
|
|
149
|
+
regions[key] = { size, mobile, collapsed: spec.breakpoint ? (mobile ? config.mobile === undefined || Boolean(config.mobile) : Boolean(config.desktop)) : Boolean(collapsed) };
|
|
150
|
+
}
|
|
151
|
+
return regions;
|
|
167
152
|
}
|
|
168
|
-
/** 节点在画面中是否可见:自身与所有祖先都可见;按画面宽度计算断点与
|
|
153
|
+
/** 节点在画面中是否可见:自身与所有祖先都可见;按画面宽度计算断点与 declared element 收起。 */
|
|
169
154
|
export function isNodeVisible(scene, nodeId, state, width = sceneWidth(scene)) {
|
|
170
155
|
const hit = findNode(scene, nodeId);
|
|
171
156
|
if (!hit)
|
|
@@ -173,69 +158,63 @@ export function isNodeVisible(scene, nodeId, state, width = sceneWidth(scene)) {
|
|
|
173
158
|
let shell = null;
|
|
174
159
|
let shellWidth = width;
|
|
175
160
|
let w = width;
|
|
176
|
-
|
|
161
|
+
const chain = [...hit.ancestors, hit.node];
|
|
162
|
+
for (const [index, n] of chain.entries()) {
|
|
177
163
|
if (!isSelfVisible(n, state, w))
|
|
178
164
|
return false;
|
|
179
|
-
|
|
165
|
+
const gate = n.traits?.selectionGate;
|
|
166
|
+
if (gate) {
|
|
167
|
+
const ancestors = chain.slice(0, index).reverse();
|
|
168
|
+
const owner = ancestors.find(a => a.type === gate.owner);
|
|
169
|
+
const item = gate.item ? ancestors.find(a => a.type === gate.item) : n;
|
|
170
|
+
if (!owner || !item)
|
|
171
|
+
return false;
|
|
172
|
+
let selected = state.inputs[owner.id] !== undefined ? state.inputs[owner.id] : resolveValue(owner.props?.value ?? owner.props?.defaultValue, state);
|
|
173
|
+
if (gate.fallbackFirst && (selected === undefined || selected === null || selected === ''))
|
|
174
|
+
selected = choicesOf(owner, state)?.[0]?.value;
|
|
175
|
+
const value = String(resolveValue(item.props?.[gate.value], state) ?? '');
|
|
176
|
+
if (Array.isArray(selected) ? !selected.map(String).includes(value) : selected === undefined || selected === null || String(selected) !== value)
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
if (n.traits?.layout) {
|
|
180
180
|
shell = n;
|
|
181
181
|
shellWidth = w;
|
|
182
182
|
}
|
|
183
|
-
if (shell &&
|
|
184
|
-
const
|
|
185
|
-
const r = n.type === 'AppShell.Navbar' ? l.navbar : l.aside;
|
|
183
|
+
if (shell && n.traits?.region) {
|
|
184
|
+
const r = layoutRegions(shell, state, shellWidth)[n.traits.region];
|
|
186
185
|
if (r?.collapsed)
|
|
187
186
|
return false;
|
|
188
187
|
}
|
|
189
|
-
w = childWidth(n
|
|
188
|
+
w = childWidth(n, w, resolveProps(n, state));
|
|
190
189
|
}
|
|
191
190
|
return true;
|
|
192
191
|
}
|
|
193
|
-
/**
|
|
194
|
-
* 可选项:Select / MultiSelect / SegmentedControl 读 data;Radio.Group 读子 Radio;Tabs 读 Tabs.Tab;
|
|
195
|
-
* Accordion 读 Accordion.Item;Pagination 为 1..total。没有可枚举选项时返回 null(select 动作不做限制)。
|
|
196
|
-
*/
|
|
192
|
+
/** Enumerate declared data, descendant values, or a numeric range. No declaration means unconstrained input. */
|
|
197
193
|
export function choicesOf(node, state) {
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
const out = [];
|
|
202
|
-
walkNodes(node, (n) => {
|
|
203
|
-
if (n !== node && types.includes(n.type))
|
|
204
|
-
out.push(n);
|
|
205
|
-
});
|
|
206
|
-
return out;
|
|
207
|
-
};
|
|
194
|
+
const spec = node.traits?.choices;
|
|
195
|
+
if (!spec)
|
|
196
|
+
return null;
|
|
208
197
|
const p = node.props ?? {};
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
case 'Radio.Group':
|
|
218
|
-
case 'Tabs':
|
|
219
|
-
case 'Accordion': {
|
|
220
|
-
const items = node.type === 'Radio.Group' ? ['Radio', 'Radio.Card'] : node.type === 'Tabs' ? ['Tabs.Tab'] : ['Accordion.Item'];
|
|
221
|
-
const c = desc(items)
|
|
222
|
-
.filter((n) => n.props?.value !== undefined)
|
|
223
|
-
.map((n) => {
|
|
224
|
-
const value = String(resolveValue(n.props.value, state));
|
|
225
|
-
const lbl = n.props?.label;
|
|
226
|
-
const control = node.type === 'Accordion' ? (n.children ?? []).find((x) => x.type === 'Accordion.Control') : n;
|
|
227
|
-
const t = typeof lbl === 'string' ? lbl : control ? text(control).trim() : '';
|
|
228
|
-
return { value, label: t || value };
|
|
229
|
-
});
|
|
230
|
-
return c.length ? c : null;
|
|
231
|
-
}
|
|
232
|
-
case 'Pagination': {
|
|
233
|
-
const total = Number(resolveValue(p.total, state));
|
|
234
|
-
return Number.isInteger(total) && total > 0 ? Array.from({ length: total }, (_, i) => ({ value: String(i + 1), label: String(i + 1) })) : null;
|
|
235
|
-
}
|
|
236
|
-
default:
|
|
237
|
-
return null;
|
|
198
|
+
if ('prop' in spec) {
|
|
199
|
+
const choices = choicesFromData(resolveValue(p[spec.prop], state));
|
|
200
|
+
return choices.length ? choices : null;
|
|
201
|
+
}
|
|
202
|
+
if ('range' in spec) {
|
|
203
|
+
const total = Number(resolveValue(p[spec.range], state));
|
|
204
|
+
return Number.isInteger(total) && total > 0 ? Array.from({ length: total }, (_, i) => ({ value: String(i + 1), label: String(i + 1) })) : null;
|
|
238
205
|
}
|
|
206
|
+
const text = (n) => n.type === '#text' ? String(resolveValue(n.props?.text, state) ?? '') : (n.children ?? []).map(text).join('');
|
|
207
|
+
const choices = [];
|
|
208
|
+
walkNodes(node, n => {
|
|
209
|
+
if (n === node || !spec.descendants.includes(n.type) || n.props?.[spec.value ?? 'value'] === undefined)
|
|
210
|
+
return;
|
|
211
|
+
const value = String(resolveValue(n.props[spec.value ?? 'value'], state));
|
|
212
|
+
const label = n.props[spec.label ?? 'label'];
|
|
213
|
+
const control = spec.labelChild ? n.children?.find(c => c.type === spec.labelChild) : n;
|
|
214
|
+
const display = typeof label === 'string' ? label : control ? text(control).trim() : '';
|
|
215
|
+
choices.push({ value, label: display || value });
|
|
216
|
+
});
|
|
217
|
+
return choices.length ? choices : null;
|
|
239
218
|
}
|
|
240
219
|
export function isNodeDisabled(node, state) {
|
|
241
220
|
if (node.disabled === undefined)
|
|
@@ -318,10 +297,19 @@ function checkStepInner(project, scenario, state, step) {
|
|
|
318
297
|
return { severity: 'error', code: 'TARGET_HIDDEN', message: `Step ${step.id} target "${nodeLabel(node)}" is currently hidden`, source: 'replay', ref };
|
|
319
298
|
if (isNodeDisabled(node, state))
|
|
320
299
|
return { severity: 'error', code: 'TARGET_DISABLED', message: `Step ${step.id} target "${nodeLabel(node)}" is currently disabled`, source: 'replay', ref };
|
|
321
|
-
if (a.type === 'click' && !
|
|
300
|
+
if (a.type === 'click' && !isInteractiveType(node.type, project.plugins))
|
|
322
301
|
return { severity: 'error', code: 'NOT_INTERACTIVE', message: `Step ${step.id} clicks ${node.type} "${nodeLabel(node)}", which is not interactive`, source: 'replay', ref };
|
|
323
|
-
if (a.type
|
|
302
|
+
if ((a.type === 'type' || a.type === 'select' || a.type === 'toggle') && !node.traits?.input)
|
|
324
303
|
return { severity: 'error', code: 'NOT_A_FIELD', message: `Step ${step.id} ${a.type} action target ${node.type} cannot accept input`, source: 'replay', ref };
|
|
304
|
+
if ((a.type === 'drag' || a.type === 'scroll') && typeof a.to === 'string' && !findNode(scene, a.to))
|
|
305
|
+
return { severity: 'error', code: 'ACTION_DESTINATION_MISSING', message: `Step ${step.id} destination ${a.to} is missing`, source: 'replay', ref };
|
|
306
|
+
if (a.type === 'scroll' && typeof a.to === 'string' && !findNode({ ...scene, root: node }, a.to))
|
|
307
|
+
return { severity: 'error', code: 'ACTION_DESTINATION_INVALID', message: `Step ${step.id} scroll destination ${a.to} is outside ${a.target}`, source: 'replay', ref };
|
|
308
|
+
if (a.type === 'plugin') {
|
|
309
|
+
const spec = pluginActionSpec(project, a.name);
|
|
310
|
+
if (!spec || !validActionData(spec, a.data) || spec.targets && !spec.targets.includes(node.type))
|
|
311
|
+
return { severity: 'error', code: 'ACTION_DATA_INVALID', message: `Step ${step.id} has an unknown or invalid plugin action ${a.name}`, source: 'replay', ref };
|
|
312
|
+
}
|
|
325
313
|
if (a.type === 'select') {
|
|
326
314
|
const choices = choicesOf(node, state);
|
|
327
315
|
if (choices && !matchChoice(choices, a.value))
|
|
@@ -335,7 +323,7 @@ function checkStepInner(project, scenario, state, step) {
|
|
|
335
323
|
}
|
|
336
324
|
return null;
|
|
337
325
|
}
|
|
338
|
-
/** select 动作写入的值:匹配到选项时存 value(动作可写 value 或 label);
|
|
326
|
+
/** select 动作写入的值:匹配到选项时存 value(动作可写 value 或 label);declared element 切换数组中的一项。 */
|
|
339
327
|
function selectedValue(project, state, target, raw) {
|
|
340
328
|
const sc = project.scenarios[state.scenarioId];
|
|
341
329
|
const scene = sc ? sceneOfTarget(project, sc, state, target) : project.scenes[state.sceneId];
|
|
@@ -344,7 +332,7 @@ function selectedValue(project, state, target, raw) {
|
|
|
344
332
|
return raw;
|
|
345
333
|
const choices = choicesOf(node, state);
|
|
346
334
|
const value = (choices && matchChoice(choices, raw)?.value) ?? raw;
|
|
347
|
-
if (node.
|
|
335
|
+
if (node.traits?.input !== 'multiple')
|
|
348
336
|
return value;
|
|
349
337
|
const cur = state.inputs[target] ?? resolveValue(node.props?.value ?? node.props?.defaultValue, state);
|
|
350
338
|
const list = Array.isArray(cur) ? cur.map(String) : [];
|
|
@@ -473,7 +461,7 @@ export function explainClick(project, state, nodeId, sceneId) {
|
|
|
473
461
|
const targetOf = (s) => ('target' in s.action ? s.action.target : null);
|
|
474
462
|
if (current && !state.completed && targetOf(current) === nodeId && checkStep(project, sc, state, current) === null)
|
|
475
463
|
return { kind: 'advance' };
|
|
476
|
-
if (!
|
|
464
|
+
if (!isInteractiveType(node.type, project.plugins))
|
|
477
465
|
return { kind: 'static' };
|
|
478
466
|
if (node.unmodeled)
|
|
479
467
|
return { kind: 'unmodeled', label };
|
|
@@ -548,58 +536,6 @@ export function stepTouchesLayer(project, scenarioId, index, layer) {
|
|
|
548
536
|
// 操作目标在这一层的步骤也算(要看着它被点)
|
|
549
537
|
return 'target' in st.action && layersWithNode(project, scenarioId, st.action.target).includes(layer);
|
|
550
538
|
}
|
|
551
|
-
/**
|
|
552
|
-
* 第 position 步之后 Diagram 的状态(纯函数,与 cameraAt 同级;回放、renderStep、视频、发布站都用它):
|
|
553
|
-
* - 本步 trace 到的:active;之前 trace 过、本步没再 trace 的:ok;
|
|
554
|
-
* - trace.fail:路径上的连线与终点节点 error(起点等其余节点 active),保持到之后又被 trace 成功;
|
|
555
|
-
* - trace.skip:路径上的节点与连线 dim(保持到之后又被 trace);
|
|
556
|
-
* - 从未涉及的:idle(不在结果里)。
|
|
557
|
-
* - 分组(D69):路径经过的节点所在的各级分组同样 active → ok;trace.fail 时终点所在的最内层分组 error;trace.skip 不改分组。
|
|
558
|
-
* 节点或连线上显式写的 state 优先于推算结果(由渲染器处理)。
|
|
559
|
-
*/
|
|
560
|
-
export function diagramStateAt(project, scenarioId, position) {
|
|
561
|
-
const sc = scenarioId ? project.scenarios[scenarioId] : undefined;
|
|
562
|
-
const out = {};
|
|
563
|
-
if (!sc)
|
|
564
|
-
return out;
|
|
565
|
-
const n = Math.max(0, Math.min(position, sc.steps.length));
|
|
566
|
-
for (let i = 0; i < n; i++) {
|
|
567
|
-
for (const v of Object.values(out)) {
|
|
568
|
-
if (v.state === 'active') {
|
|
569
|
-
v.state = 'ok';
|
|
570
|
-
delete v.reverse;
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
for (const t of sc.steps[i].traces ?? []) {
|
|
574
|
-
if (t.mode === 'skip') {
|
|
575
|
-
for (const id of t.nodes)
|
|
576
|
-
out[id] = { state: 'dim' };
|
|
577
|
-
for (const e of t.edges)
|
|
578
|
-
out[e.id] = { state: 'dim' };
|
|
579
|
-
}
|
|
580
|
-
else if (t.mode === 'fail') {
|
|
581
|
-
const last = t.nodes[t.nodes.length - 1];
|
|
582
|
-
for (const id of t.groups ?? [])
|
|
583
|
-
out[id] = { state: 'active' };
|
|
584
|
-
for (const id of t.errorGroups ?? [])
|
|
585
|
-
out[id] = { state: 'error' };
|
|
586
|
-
for (const id of t.nodes)
|
|
587
|
-
out[id] = { state: id === last ? 'error' : 'active' };
|
|
588
|
-
for (const e of t.edges)
|
|
589
|
-
out[e.id] = { state: 'error' };
|
|
590
|
-
}
|
|
591
|
-
else {
|
|
592
|
-
for (const id of t.groups ?? [])
|
|
593
|
-
out[id] = { state: 'active' };
|
|
594
|
-
for (const id of t.nodes)
|
|
595
|
-
out[id] = { state: 'active' };
|
|
596
|
-
for (const e of t.edges)
|
|
597
|
-
out[e.id] = e.reverse ? { state: 'active', reverse: true } : { state: 'active' };
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
return out;
|
|
602
|
-
}
|
|
603
539
|
/** 第 position 步之后是否停在一张过渡卡上(最近执行的一步是过渡卡);是则返回卡片内容。 */
|
|
604
540
|
export function cardAt(project, scenarioId, position) {
|
|
605
541
|
const st = scenarioId ? project.scenarios[scenarioId]?.steps[position - 1] : undefined;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Action, Effect, Project } from './schema.js';
|
|
2
|
+
import { explainClick, type PlayState } from './player.js';
|
|
3
|
+
export type LocalEffect = Extract<Effect, {
|
|
4
|
+
type: 'set' | 'append' | 'toast';
|
|
5
|
+
}>;
|
|
6
|
+
/** Only local deltas. Dropping this object restores the exact scripted state. Never serialized in IR or URLs. */
|
|
7
|
+
export type Playground = {
|
|
8
|
+
effects: LocalEffect[];
|
|
9
|
+
};
|
|
10
|
+
export type ActionEntry = {
|
|
11
|
+
scenarioId: string;
|
|
12
|
+
position: number;
|
|
13
|
+
sceneId: string;
|
|
14
|
+
action: Action;
|
|
15
|
+
};
|
|
16
|
+
export type ActionVerdict = {
|
|
17
|
+
kind: 'advance';
|
|
18
|
+
} | {
|
|
19
|
+
kind: 'switch';
|
|
20
|
+
candidates: ActionEntry[];
|
|
21
|
+
} | {
|
|
22
|
+
kind: 'free';
|
|
23
|
+
effects: LocalEffect[];
|
|
24
|
+
} | {
|
|
25
|
+
kind: 'hint';
|
|
26
|
+
verdict: ReturnType<typeof explainClick>;
|
|
27
|
+
};
|
|
28
|
+
export { actionMatches, pluginActionSpec, validActionData } from './actions.js';
|
|
29
|
+
/** Index only positions whose prefix replays and whose action is available there. */
|
|
30
|
+
export declare function actionIndex(project: Project, optionId: string): ActionEntry[];
|
|
31
|
+
export declare function arbitrateAction(project: Project, timeline: PlayState, action: Action, opts?: {
|
|
32
|
+
layer?: Playground | null;
|
|
33
|
+
sceneId?: string;
|
|
34
|
+
index?: readonly ActionEntry[];
|
|
35
|
+
native?: Action;
|
|
36
|
+
}): ActionVerdict;
|
|
37
|
+
export declare function applyPlayground(layer: Playground | null, effects: readonly LocalEffect[]): Playground;
|
|
38
|
+
export declare function playgroundState(timeline: PlayState, layer: Playground | null): PlayState;
|