@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.
- package/dist/agent-skill.d.ts +7 -7
- package/dist/agent-skill.js +28 -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 -327
- 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 +171 -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 -31
- package/dist/pace.d.ts +10 -5
- package/dist/pace.js +12 -5
- package/dist/playback.d.ts +57 -0
- package/dist/playback.js +317 -0
- package/dist/player.d.ts +9 -180
- package/dist/player.js +8 -618
- 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 +118 -76
- package/dist/schema.js +52 -37
- 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 +4 -0
- package/package.json +15 -3
|
@@ -6,7 +6,14 @@ import type { Scene, Project } from '../schema.js';
|
|
|
6
6
|
import type { PluginInfo } from '../catalog.js';
|
|
7
7
|
export type CompileOptions = {
|
|
8
8
|
onResource?: (request: ResourceRequest) => void;
|
|
9
|
+
/** 本机资源的元数据,按这次编译里的资源 id。 */
|
|
9
10
|
resourceInfo?: Record<string, LocalResourceInfo>;
|
|
11
|
+
/** 按请求内容(插件、编译器、输入)查元数据:上一次编译已经检查过的资源第一遍就能用上,宿主不必为了它再编译一遍。resourceInfo 里有的优先。 */
|
|
12
|
+
resourceInfoFor?: (request: {
|
|
13
|
+
plugin: string;
|
|
14
|
+
compiler: string;
|
|
15
|
+
input: string;
|
|
16
|
+
}) => LocalResourceInfo | undefined;
|
|
10
17
|
pluginOptions?: Record<string, Record<string, unknown>>;
|
|
11
18
|
};
|
|
12
19
|
export declare function enabledPlugins(configured: unknown): unknown[];
|
|
@@ -28,6 +35,15 @@ export declare class PluginCompiler {
|
|
|
28
35
|
})[]>;
|
|
29
36
|
private resourceIds;
|
|
30
37
|
private resourceOwners;
|
|
38
|
+
private resourceRequests;
|
|
39
|
+
/**
|
|
40
|
+
* 钩子输入的只读副本,按画面根节点缓存:画面在派生(derive)之后不再变,同一棵树给每个效果、每一步、每个插件
|
|
41
|
+
* 用同一份深冻结的副本,不为每次钩子调用整棵重拷。只在这一次编译内有效。
|
|
42
|
+
*/
|
|
43
|
+
private frozenRoots;
|
|
44
|
+
private frozenRoot;
|
|
45
|
+
private frozenScenes;
|
|
46
|
+
private infoOf;
|
|
31
47
|
readonly defs: Map<string, PluginDef>;
|
|
32
48
|
readonly info: Record<string, PluginInfo>;
|
|
33
49
|
constructor(configured: unknown, report: PluginReport, source?: string, options?: CompileOptions);
|
package/dist/plugins/compiler.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PluginAction } from "../schema.js";
|
|
2
|
-
import { ElementTraitsSchema, InheritSchema } from "../traits.js";
|
|
2
|
+
import { ElementTraitsSchema, InheritSchema, PluginInspectFieldSchema, PluginTextSchema } from "../traits.js";
|
|
3
3
|
import { advanceMedia } from "../media.js";
|
|
4
|
-
import {
|
|
4
|
+
import { commitGapMs } from "../step-plan.js";
|
|
5
5
|
import { jsonData, snapshot, object, strings, syncResult, authoringData, materialize, errorMessage } from "./data.js";
|
|
6
6
|
/** Node-side plugin host. Callbacks never enter IR or the player. */
|
|
7
7
|
import { isNode } from '@joplo-app/kit/node';
|
|
@@ -34,6 +34,26 @@ export class PluginCompiler {
|
|
|
34
34
|
mediaCommands = new Map();
|
|
35
35
|
resourceIds = new Map();
|
|
36
36
|
resourceOwners = new Map();
|
|
37
|
+
resourceRequests = new Map();
|
|
38
|
+
/**
|
|
39
|
+
* 钩子输入的只读副本,按画面根节点缓存:画面在派生(derive)之后不再变,同一棵树给每个效果、每一步、每个插件
|
|
40
|
+
* 用同一份深冻结的副本,不为每次钩子调用整棵重拷。只在这一次编译内有效。
|
|
41
|
+
*/
|
|
42
|
+
frozenRoots = new WeakMap();
|
|
43
|
+
frozenRoot(root) {
|
|
44
|
+
let hit = this.frozenRoots.get(root);
|
|
45
|
+
if (!hit)
|
|
46
|
+
this.frozenRoots.set(root, (hit = snapshot(root)));
|
|
47
|
+
return hit;
|
|
48
|
+
}
|
|
49
|
+
frozenScenes(scenes) {
|
|
50
|
+
const list = scenes.map(s => Object.freeze({ id: s.id, root: this.frozenRoot(s.root) }));
|
|
51
|
+
return { roots: Object.freeze(list.map(s => s.root)), scenes: Object.freeze(list) };
|
|
52
|
+
}
|
|
53
|
+
infoOf(id) {
|
|
54
|
+
const request = this.resourceRequests.get(id);
|
|
55
|
+
return this.options.resourceInfo?.[id] ?? (request ? this.options.resourceInfoFor?.(request) : undefined);
|
|
56
|
+
}
|
|
37
57
|
defs = new Map();
|
|
38
58
|
info = {};
|
|
39
59
|
constructor(configured, report, source, options = {}) {
|
|
@@ -57,8 +77,10 @@ export class PluginCompiler {
|
|
|
57
77
|
}
|
|
58
78
|
this.defs.set(p.id, p);
|
|
59
79
|
const properties = this.envelope(p, p.properties ?? {}, source);
|
|
80
|
+
// 清单不合格的插件整个不启用:不留下只注册了一半(有钩子、没有组件信息)的状态
|
|
60
81
|
if (!object(properties)) {
|
|
61
82
|
this.invalid(p, source);
|
|
83
|
+
this.defs.delete(p.id);
|
|
62
84
|
continue;
|
|
63
85
|
}
|
|
64
86
|
for (const [key, spec] of Object.entries(properties)) {
|
|
@@ -102,8 +124,18 @@ export class PluginCompiler {
|
|
|
102
124
|
this.themes[`${p.id}:${name}`] = css;
|
|
103
125
|
}
|
|
104
126
|
const checked = {};
|
|
127
|
+
const shown = {};
|
|
105
128
|
for (const [name, c] of Object.entries(p.components)) {
|
|
106
129
|
const type = `${p.id}:${name}`;
|
|
130
|
+
// 看板里给人看的名字与检查抽屉的信息行:纯数据,校验后进 dev IR(发布与评审版在编译末尾去掉)
|
|
131
|
+
if (c.label !== undefined || c.inspect !== undefined) {
|
|
132
|
+
const label = c.label === undefined ? undefined : PluginTextSchema.safeParse(this.envelope(p, c.label, source));
|
|
133
|
+
const inspect = c.inspect === undefined ? undefined : PluginInspectFieldSchema.array().safeParse(this.envelope(p, c.inspect, source));
|
|
134
|
+
if (label && !label.success || inspect && !inspect.success)
|
|
135
|
+
report('PLUGIN_INVALID', `Plugin ${p.id}: invalid label or inspect declaration for ${name}`, source);
|
|
136
|
+
else
|
|
137
|
+
shown[name] = { ...(label?.success ? { label: label.data } : {}), ...(inspect?.success ? { inspect: inspect.data } : {}) };
|
|
138
|
+
}
|
|
107
139
|
if (c.traits !== undefined) {
|
|
108
140
|
const parsed = ElementTraitsSchema.safeParse(this.envelope(p, c.traits, source));
|
|
109
141
|
if (!parsed.success)
|
|
@@ -125,7 +157,7 @@ export class PluginCompiler {
|
|
|
125
157
|
this.intrinsic.set(c.intrinsic, type);
|
|
126
158
|
}
|
|
127
159
|
}
|
|
128
|
-
this.info[p.id] = { ...(Object.keys(actions).length ? { actions } : {}), ...(object(themes) && Object.keys(themes).length ? { themes: themes } : {}), ...(Object.keys(properties).length ? { properties: properties } : {}), ...(p.data ? { data: this.envelope(p, p.data, source) } : {}), id: p.id, title: p.title, ...(p.version ? { version: p.version } : {}), components: Object.fromEntries(Object.entries(p.components).map(([name, c]) => [name, { ...(checked[name] ? { traits: checked[name] } : {}), ...(c?.interactive ? { interactive: true } : {}), ...(c?.parent ? { parent: c.parent } : {}), ...(c?.needsId ? { needsId: true } : {}), ...(c?.selfEvident ? { selfEvident: true } : {}) }])) };
|
|
160
|
+
this.info[p.id] = { ...(Object.keys(actions).length ? { actions } : {}), ...(object(themes) && Object.keys(themes).length ? { themes: themes } : {}), ...(Object.keys(properties).length ? { properties: properties } : {}), ...(p.data ? { data: this.envelope(p, p.data, source) } : {}), id: p.id, title: p.title, ...(p.version ? { version: p.version } : {}), components: Object.fromEntries(Object.entries(p.components).map(([name, c]) => [name, { ...shown[name], ...(checked[name] ? { traits: checked[name] } : {}), ...(c?.interactive ? { interactive: true } : {}), ...(c?.parent ? { parent: c.parent } : {}), ...(c?.needsId ? { needsId: true } : {}), ...(c?.selfEvident ? { selfEvident: true } : {}) }])) };
|
|
129
161
|
}
|
|
130
162
|
}
|
|
131
163
|
run(p, hook, at, fn) {
|
|
@@ -175,6 +207,7 @@ export class PluginCompiler {
|
|
|
175
207
|
id = `resource-${this.resourceIds.size}`;
|
|
176
208
|
this.resourceIds.set(key, id);
|
|
177
209
|
this.resourceOwners.set(id, plugin);
|
|
210
|
+
this.resourceRequests.set(id, { plugin, compiler, input });
|
|
178
211
|
this.options.onResource?.({ id, plugin, compiler, input, source });
|
|
179
212
|
}
|
|
180
213
|
return `joplo-resource:${id}`;
|
|
@@ -265,7 +298,8 @@ export class PluginCompiler {
|
|
|
265
298
|
return undefined;
|
|
266
299
|
}
|
|
267
300
|
return this.run(p, 'effect', source, () => {
|
|
268
|
-
const
|
|
301
|
+
const frozen = this.frozenScenes(scenes);
|
|
302
|
+
const result = this.output(p, p.compile.effect(snapshot(effect), { roots: frozen.roots, scenes: frozen.scenes, data: snapshot(data), source, report: this.report, resourceInfo: id => this.resourceOwners.get(id) === p.id ? snapshot(this.infoOf(id)) : undefined, resource: request => {
|
|
269
303
|
request = materialize(request);
|
|
270
304
|
if (!request || typeof request.compiler !== 'string' || !/^[a-z][a-z0-9-]*$/.test(request.compiler) || typeof request.input !== 'string' || Object.keys(request).some(k => k !== 'compiler' && k !== 'input'))
|
|
271
305
|
throw new Error('resource requires compiler and text input');
|
|
@@ -275,6 +309,7 @@ export class PluginCompiler {
|
|
|
275
309
|
id = `resource-${this.resourceIds.size}`;
|
|
276
310
|
this.resourceIds.set(key, id);
|
|
277
311
|
this.resourceOwners.set(id, p.id);
|
|
312
|
+
this.resourceRequests.set(id, { plugin: p.id, compiler: request.compiler, input: request.input });
|
|
278
313
|
this.options.onResource?.({ id, plugin: p.id, compiler: request.compiler, input: request.input, ...(source ? { source } : {}) });
|
|
279
314
|
}
|
|
280
315
|
return id;
|
|
@@ -326,10 +361,11 @@ export class PluginCompiler {
|
|
|
326
361
|
for (const sc of Object.values(project.scenarios))
|
|
327
362
|
visit(sc);
|
|
328
363
|
for (const sc of order) {
|
|
329
|
-
const
|
|
330
|
-
const
|
|
364
|
+
const work = project.works[sc.workId];
|
|
365
|
+
const isolated = !work?.featureId && !work?.routes.length;
|
|
366
|
+
const { roots, scenes } = this.frozenScenes(Object.values(project.scenes).filter(s => s.workId === sc.workId || !isolated && s.workId == null));
|
|
331
367
|
const prev = sc.from ? project.scenarios[sc.from] : undefined;
|
|
332
|
-
let media = prev && ended.has(prev.id) ? advanceMedia(ended.get(prev.id), prev.steps
|
|
368
|
+
let media = prev && ended.has(prev.id) ? advanceMedia(ended.get(prev.id), commitGapMs(project, prev.steps, prev.steps.length - 1)) : {};
|
|
333
369
|
const hasMedia = Object.keys(media).length > 0 || sc.steps.some(step => this.mediaCommands.has(step.id));
|
|
334
370
|
let previousState;
|
|
335
371
|
let state = initialState(project, sc.id);
|
|
@@ -344,7 +380,8 @@ export class PluginCompiler {
|
|
|
344
380
|
const target = i ? sc.steps[i - 1] : sc;
|
|
345
381
|
const ext = { ...target.ext };
|
|
346
382
|
if (i) {
|
|
347
|
-
|
|
383
|
+
// 配乐锚点:上一次提交(i = 1 时是场景开始)到这一步提交之间的计划时长(stepPlan:停留 / 朗读估算 + 这一步的操作演示)
|
|
384
|
+
media = advanceMedia(media, commitGapMs(project, sc.steps, i - 2));
|
|
348
385
|
for (const c of this.mediaCommands.get(sc.steps[i - 1].id) ?? []) {
|
|
349
386
|
const key = `${c.plugin}:${c.track}`;
|
|
350
387
|
const current = media[key];
|
|
@@ -372,9 +409,11 @@ export class PluginCompiler {
|
|
|
372
409
|
}
|
|
373
410
|
if (hasMedia)
|
|
374
411
|
target.media = structuredClone(media);
|
|
412
|
+
// 这一步的状态冻结一次,所有插件的 frame 钩子共用(resolveProps 也读这一份,不为每次取值再拷状态)
|
|
413
|
+
const frozenState = snapshot(state), frozenPrevious = snapshot(previousState);
|
|
375
414
|
for (const p of this.defs.values()) {
|
|
376
415
|
if (p.compile?.frame) {
|
|
377
|
-
const value = this.run(p, 'frame', target.source, () => this.output(p, p.compile.frame({ roots
|
|
416
|
+
const value = this.run(p, 'frame', target.source, () => this.output(p, p.compile.frame({ roots, scenes, state: frozenState, previousState: frozenPrevious, resolveProps: (node, previous) => resolveProps(node, previous && frozenPrevious ? frozenPrevious : frozenState), data: snapshot(target.ext?.[p.id]), previousData: snapshot(previousData[p.id]), position: i, report: this.report }), target.source));
|
|
378
417
|
if (value !== undefined)
|
|
379
418
|
ext[p.id] = value;
|
|
380
419
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Project, Step } from './schema.js';
|
|
2
|
+
import { type PlayState } from './scene-query.js';
|
|
3
|
+
/** 某一步的镜头:导演层与每个层级当前对准的元素(空数组 = 这一层的整体)。 */
|
|
4
|
+
export type Camera = {
|
|
5
|
+
directorLayer: string;
|
|
6
|
+
perLayer: Record<string, string[]>;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* 第 position 步之后的镜头。纯函数:只由步骤上的 shots / directorLayer 推导,不进入 ui / data / inputs。
|
|
10
|
+
* 初始导演层 = 第一个声明的层级(没有层级时是路径页面 @page),各层都是整体。
|
|
11
|
+
* 没有 shot 的步骤沿用上一步;shot()(@director)让当时的导演层回到整体。
|
|
12
|
+
* 手动、逐步、自动播放、回放、renderStep、视频录制和发布站都用它。
|
|
13
|
+
*/
|
|
14
|
+
export declare function cameraAt(project: Project, scenarioId: string, position: number): Camera;
|
|
15
|
+
/** cameraAt 的不缓存版本:编译器在 IR 还没定稿时用。 */
|
|
16
|
+
export declare function cameraOf(project: Project, scenarioId: string, position: number): Camera;
|
|
17
|
+
/** 第 position 步之后用户看到的画面:有层级时是导演层(或手动选的层)的画面,否则是状态里的路径画面。 */
|
|
18
|
+
export declare function displaySceneId(project: Project, scenarioId: string, position: number, layer?: string | null): string;
|
|
19
|
+
/** 第 index 步(0 起)的镜头是否改变了某一层(“只重放这一层”时,不变的步骤快速带过)。 */
|
|
20
|
+
export declare function stepTouchesLayer(project: Project, scenarioId: string, index: number, layer: string): boolean;
|
|
21
|
+
export type CardAction = Extract<Step['action'], {
|
|
22
|
+
type: 'card';
|
|
23
|
+
}>;
|
|
24
|
+
export type RoleInfo = {
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
desc: string;
|
|
28
|
+
color: string;
|
|
29
|
+
};
|
|
30
|
+
/** 第 position 步之后是否停在一张过渡卡上(最近执行的一步是过渡卡);是则返回卡片内容。 */
|
|
31
|
+
export declare function cardAt(project: Project, scenarioId: string | null | undefined, position: number): CardAction | null;
|
|
32
|
+
/** 方案所属功能里可引用的角色(有 id 的)。 */
|
|
33
|
+
export declare function roleOf(project: Project, workId: string | null | undefined, roleId: string | null | undefined): RoleInfo | null;
|
|
34
|
+
/** 某个画面是谁的(层级声明了 role 时);路径页面与没有角色的层级返回 null。 */
|
|
35
|
+
export declare function roleOfScene(project: Project, sceneId: string | null | undefined): RoleInfo | null;
|
|
36
|
+
/** 第 index 步(0 起)流式输出的状态路径与文字。 */
|
|
37
|
+
export declare function streamsOf(step: Step | undefined): {
|
|
38
|
+
path: string;
|
|
39
|
+
value: string;
|
|
40
|
+
pace?: 'voice';
|
|
41
|
+
}[];
|
|
42
|
+
/** 一段流式输出怎么出字:keep 个字一开始就在(原来的值),其余的字在 ms 毫秒(1×)里逐字出现。 */
|
|
43
|
+
export type StreamPlan = {
|
|
44
|
+
path: string;
|
|
45
|
+
value: string;
|
|
46
|
+
keep: number;
|
|
47
|
+
ms: number;
|
|
48
|
+
pace?: 'voice';
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* 这一步的流式输出怎么出字(D56,D100)。prev 是这一步之前的状态;不知道时传 null(整段重新出,用于估算)。
|
|
52
|
+
* - 接着往后写:新值以原来的值开头时,原有的字直接显示,只有新加的字逐字出现;
|
|
53
|
+
* - pace: 'voice':新加的字在这一步朗读(narrate ?? say)的估算时长里出完,读到哪写到哪;没有朗读时退回按字数。
|
|
54
|
+
*/
|
|
55
|
+
export declare function streamPlan(step: Step | undefined, prev: Pick<PlayState, 'ui' | 'data' | 'inputs'> | null): StreamPlan[];
|
|
56
|
+
/** 动作和业务效果完全相同的公共前缀步数;字幕、镜头、分叉等展示信息不参与。 */
|
|
57
|
+
export declare function commonPrefix(a: readonly Pick<Step, 'action' | 'effects'>[], b: readonly Pick<Step, 'action' | 'effects'>[]): number;
|
|
58
|
+
export declare function forksAt(project: Project, scenarioId: string | null | undefined, position: number): Step['forks'];
|
|
59
|
+
/** 与 Toast 一样只显示最近一步,目标是否可见由当前显示画面决定。 */
|
|
60
|
+
export declare function marksAt(project: Project, scenarioId: string | null | undefined, position: number): Step['marks'];
|
|
61
|
+
export type StateChange = {
|
|
62
|
+
path: string;
|
|
63
|
+
before: unknown;
|
|
64
|
+
after: unknown;
|
|
65
|
+
};
|
|
66
|
+
/** 对比 core 回放产生的相邻状态:对象按叶子展开,数组作为一个值;不包含动画、Toast 等展示状态。 */
|
|
67
|
+
export declare function changedAt(project: Project, scenarioId: string | null | undefined, position: number): StateChange[];
|
|
68
|
+
/** 已定位的一步的路线;字幕也用这一个投影入口。 */
|
|
69
|
+
export declare function forksOf(step: Step | undefined): Step['forks'];
|
|
70
|
+
/** 按键记录的 IR 入口:静态取最近一步,动画预览与键帽分词由 web 负责。 */
|
|
71
|
+
export declare function keyboardActionOf(step: Step | undefined): Extract<Step['action'], {
|
|
72
|
+
type: 'type' | 'press';
|
|
73
|
+
}> | null;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { rolesOf } from "./entries.js";
|
|
2
|
+
/**
|
|
3
|
+
* 演示投影(纯函数):第 k 步之后观众看到什么——导演镜头、显示哪一层的画面、过渡卡、角色、流式输出的出字计划、
|
|
4
|
+
* 分叉、标注,以及这一步改了哪些状态。只读 IR 与回放出的状态,不推进状态。
|
|
5
|
+
*/
|
|
6
|
+
import { DIRECTOR_LAYER, PAGE_LAYER } from "./catalog.js";
|
|
7
|
+
import { streamMs, voicePacedMs } from "./pace.js";
|
|
8
|
+
import { layersOf, layersWithNode, readPath } from "./scene-query.js";
|
|
9
|
+
import { stateAt, timelineMemo, timelineState } from "./playback.js";
|
|
10
|
+
/**
|
|
11
|
+
* 第 position 步之后的镜头。纯函数:只由步骤上的 shots / directorLayer 推导,不进入 ui / data / inputs。
|
|
12
|
+
* 初始导演层 = 第一个声明的层级(没有层级时是路径页面 @page),各层都是整体。
|
|
13
|
+
* 没有 shot 的步骤沿用上一步;shot()(@director)让当时的导演层回到整体。
|
|
14
|
+
* 手动、逐步、自动播放、回放、renderStep、视频录制和发布站都用它。
|
|
15
|
+
*/
|
|
16
|
+
export function cameraAt(project, scenarioId, position) {
|
|
17
|
+
const sc = project.scenarios[scenarioId];
|
|
18
|
+
if (!sc)
|
|
19
|
+
return cameraOf(project, scenarioId, position);
|
|
20
|
+
const cameras = timelineMemo(project, sc, 'cameras', () => camerasOf(project, sc));
|
|
21
|
+
const c = cameras[Math.max(0, Math.min(Number.isFinite(position) ? Math.trunc(position) : 0, sc.steps.length))];
|
|
22
|
+
return { directorLayer: c.directorLayer, perLayer: Object.fromEntries(Object.entries(c.perLayer).map(([k, v]) => [k, [...v]])) };
|
|
23
|
+
}
|
|
24
|
+
/** 每个位置(0..步数)的镜头,一次遍历算完。 */
|
|
25
|
+
function camerasOf(project, sc) {
|
|
26
|
+
const layers = layersOf(project, sc.id);
|
|
27
|
+
let directorLayer = (sc.initial.layer && layers.some((l) => l.id === sc.initial.layer) ? sc.initial.layer : layers[0]?.id) ?? PAGE_LAYER;
|
|
28
|
+
let perLayer = {};
|
|
29
|
+
const out = [{ directorLayer, perLayer }];
|
|
30
|
+
for (const st of sc.steps) {
|
|
31
|
+
if (st.directorLayer)
|
|
32
|
+
directorLayer = st.directorLayer;
|
|
33
|
+
if (st.shots?.length) {
|
|
34
|
+
perLayer = { ...perLayer };
|
|
35
|
+
for (const s of st.shots)
|
|
36
|
+
perLayer[s.layer === DIRECTOR_LAYER ? directorLayer : s.layer] = [...s.targets];
|
|
37
|
+
}
|
|
38
|
+
out.push({ directorLayer, perLayer });
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
/** cameraAt 的不缓存版本:编译器在 IR 还没定稿时用。 */
|
|
43
|
+
export function cameraOf(project, scenarioId, position) {
|
|
44
|
+
const sc = project.scenarios[scenarioId];
|
|
45
|
+
if (!sc)
|
|
46
|
+
return { directorLayer: layersOf(project, scenarioId)[0]?.id ?? PAGE_LAYER, perLayer: {} };
|
|
47
|
+
const c = camerasOf(project, sc)[Math.max(0, Math.min(Number.isFinite(position) ? Math.trunc(position) : 0, sc.steps.length))];
|
|
48
|
+
return { directorLayer: c.directorLayer, perLayer: Object.fromEntries(Object.entries(c.perLayer).map(([k, v]) => [k, [...v]])) };
|
|
49
|
+
}
|
|
50
|
+
/** 第 position 步之后用户看到的画面:有层级时是导演层(或手动选的层)的画面,否则是状态里的路径画面。 */
|
|
51
|
+
export function displaySceneId(project, scenarioId, position, layer) {
|
|
52
|
+
const layers = layersOf(project, scenarioId);
|
|
53
|
+
const state = stateAt(project, scenarioId, position);
|
|
54
|
+
if (!layers.length)
|
|
55
|
+
return state.sceneId;
|
|
56
|
+
const want = layer && layers.some((l) => l.id === layer) ? layer : cameraAt(project, scenarioId, position).directorLayer;
|
|
57
|
+
return (layers.find((l) => l.id === want) ?? layers[0]).sceneId;
|
|
58
|
+
}
|
|
59
|
+
/** 第 index 步(0 起)的镜头是否改变了某一层(“只重放这一层”时,不变的步骤快速带过)。 */
|
|
60
|
+
export function stepTouchesLayer(project, scenarioId, index, layer) {
|
|
61
|
+
const st = project.scenarios[scenarioId]?.steps[index];
|
|
62
|
+
if (!st)
|
|
63
|
+
return false;
|
|
64
|
+
if ((st.shots ?? []).some((s) => s.layer === layer || (s.layer === DIRECTOR_LAYER && cameraAt(project, scenarioId, index + 1).directorLayer === layer)))
|
|
65
|
+
return true;
|
|
66
|
+
// 操作目标在这一层的步骤也算(要看着它被点)
|
|
67
|
+
return 'target' in st.action && layersWithNode(project, scenarioId, st.action.target).includes(layer);
|
|
68
|
+
}
|
|
69
|
+
/** 第 position 步之后是否停在一张过渡卡上(最近执行的一步是过渡卡);是则返回卡片内容。 */
|
|
70
|
+
export function cardAt(project, scenarioId, position) {
|
|
71
|
+
const st = scenarioId ? project.scenarios[scenarioId]?.steps[position - 1] : undefined;
|
|
72
|
+
return st && st.action.type === 'card' ? st.action : null;
|
|
73
|
+
}
|
|
74
|
+
/** 方案所属功能里可引用的角色(有 id 的)。 */
|
|
75
|
+
export function roleOf(project, workId, roleId) {
|
|
76
|
+
if (!workId || !roleId)
|
|
77
|
+
return null;
|
|
78
|
+
const r = rolesOf(project, workId).find(x => x.id === roleId);
|
|
79
|
+
return r && r.id ? { id: r.id, name: r.name, desc: r.desc, color: r.color } : null;
|
|
80
|
+
}
|
|
81
|
+
/** 某个画面是谁的(层级声明了 role 时);路径页面与没有角色的层级返回 null。 */
|
|
82
|
+
export function roleOfScene(project, sceneId) {
|
|
83
|
+
const scene = sceneId ? project.scenes[sceneId] : undefined;
|
|
84
|
+
if (!scene?.layer || !scene.workId)
|
|
85
|
+
return null;
|
|
86
|
+
return roleOf(project, scene.workId, project.works[scene.workId]?.layers[scene.layer]?.role);
|
|
87
|
+
}
|
|
88
|
+
/** 第 index 步(0 起)流式输出的状态路径与文字。 */
|
|
89
|
+
export function streamsOf(step) {
|
|
90
|
+
return (step?.effects ?? []).flatMap((e) => (e.type === 'stream' ? [{ path: e.path, value: e.value, ...(e.pace ? { pace: e.pace } : {}) }] : []));
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* 这一步的流式输出怎么出字(D56,D100)。prev 是这一步之前的状态;不知道时传 null(整段重新出,用于估算)。
|
|
94
|
+
* - 接着往后写:新值以原来的值开头时,原有的字直接显示,只有新加的字逐字出现;
|
|
95
|
+
* - pace: 'voice':新加的字在这一步朗读(narrate ?? say)的估算时长里出完,读到哪写到哪;没有朗读时退回按字数。
|
|
96
|
+
*/
|
|
97
|
+
export function streamPlan(step, prev) {
|
|
98
|
+
return streamsOf(step).map((s) => {
|
|
99
|
+
const before = prev ? readPath(prev, s.path) : undefined;
|
|
100
|
+
const keep = typeof before === 'string' && before && s.value.startsWith(before) ? [...before].length : 0;
|
|
101
|
+
const fresh = [...s.value].slice(keep).join('');
|
|
102
|
+
const voiced = s.pace === 'voice' ? voicePacedMs(step?.narrate ?? step?.say) : 0;
|
|
103
|
+
return { path: s.path, value: s.value, keep, ms: fresh ? (voiced || streamMs(fresh)) : 0, ...(s.pace ? { pace: s.pace } : {}) };
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
// ---------- 分叉、标注与变化(D56 P1) ----------
|
|
107
|
+
/** 动作和业务效果完全相同的公共前缀步数;字幕、镜头、分叉等展示信息不参与。 */
|
|
108
|
+
export function commonPrefix(a, b) {
|
|
109
|
+
let n = 0;
|
|
110
|
+
while (n < Math.min(a.length, b.length) && sameValue(a[n].action, b[n].action) && sameValue(a[n].effects, b[n].effects))
|
|
111
|
+
n++;
|
|
112
|
+
return n;
|
|
113
|
+
}
|
|
114
|
+
function sameValue(a, b) {
|
|
115
|
+
if (Object.is(a, b))
|
|
116
|
+
return true;
|
|
117
|
+
if (!a || !b || typeof a !== 'object' || typeof b !== 'object')
|
|
118
|
+
return false;
|
|
119
|
+
if (Array.isArray(a) || Array.isArray(b))
|
|
120
|
+
return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((v, i) => sameValue(v, b[i]));
|
|
121
|
+
const ak = Object.keys(a), bk = Object.keys(b);
|
|
122
|
+
return ak.length === bk.length && ak.every(k => Object.hasOwn(b, k) && sameValue(a[k], b[k]));
|
|
123
|
+
}
|
|
124
|
+
export function forksAt(project, scenarioId, position) {
|
|
125
|
+
return forksOf(scenarioId ? project.scenarios[scenarioId]?.steps[position - 1] : undefined);
|
|
126
|
+
}
|
|
127
|
+
/** 与 Toast 一样只显示最近一步,目标是否可见由当前显示画面决定。 */
|
|
128
|
+
export function marksAt(project, scenarioId, position) {
|
|
129
|
+
return (scenarioId ? project.scenarios[scenarioId]?.steps[position - 1]?.marks : undefined) ?? [];
|
|
130
|
+
}
|
|
131
|
+
/** 对比 core 回放产生的相邻状态:对象按叶子展开,数组作为一个值;不包含动画、Toast 等展示状态。 */
|
|
132
|
+
export function changedAt(project, scenarioId, position) {
|
|
133
|
+
const sc = scenarioId ? project.scenarios[scenarioId] : undefined;
|
|
134
|
+
if (!sc || !Number.isInteger(position) || position <= 0 || position > sc.steps.length)
|
|
135
|
+
return [];
|
|
136
|
+
const before = timelineState(project, sc, position - 1);
|
|
137
|
+
const after = timelineState(project, sc, position);
|
|
138
|
+
const out = [];
|
|
139
|
+
const object = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
140
|
+
const diff = (path, a, b) => {
|
|
141
|
+
if (sameValue(a, b))
|
|
142
|
+
return;
|
|
143
|
+
if ((object(a) || a === undefined) && (object(b) || b === undefined) && (object(a) || object(b))) {
|
|
144
|
+
const keys = [...new Set([...Object.keys(a ?? {}), ...Object.keys(b ?? {})])].sort();
|
|
145
|
+
if (keys.length) {
|
|
146
|
+
for (const k of keys)
|
|
147
|
+
diff(`${path}.${k}`, a?.[k], b?.[k]);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
out.push({ path, before: structuredClone(a), after: structuredClone(b) });
|
|
152
|
+
};
|
|
153
|
+
for (const root of ['ui', 'data', 'inputs'])
|
|
154
|
+
diff(root, before[root], after[root]);
|
|
155
|
+
return out;
|
|
156
|
+
}
|
|
157
|
+
/** 已定位的一步的路线;字幕也用这一个投影入口。 */
|
|
158
|
+
export function forksOf(step) { return step?.forks ?? []; }
|
|
159
|
+
/** 按键记录的 IR 入口:静态取最近一步,动画预览与键帽分词由 web 负责。 */
|
|
160
|
+
export function keyboardActionOf(step) {
|
|
161
|
+
const a = step?.action;
|
|
162
|
+
return a?.type === 'type' || a?.type === 'press' ? a : null;
|
|
163
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** 发布边界:本地作品可以完整保留在 dev,但不能成为其他作品的公开依赖。 */
|
|
2
|
+
import type { Project, SceneNode } from './schema.js';
|
|
3
|
+
export declare function localOnlyWorks(project: Project): Set<string>;
|
|
4
|
+
export declare function assertExportableEntry(project: Project, featureId: string): void;
|
|
5
|
+
/** 先裁掉完整贡献子树,再算父元素标签,避免祖先标签把子树文字重新带回来。 */
|
|
6
|
+
export declare function withoutLocalContributions(node: SceneNode, local: ReadonlySet<string>): SceneNode | null;
|
|
7
|
+
/** id 可跨作品复用:仅保护在公开画面里没有独立出现的本地元素。 */
|
|
8
|
+
export declare function localOnlyElementIds(project: Project, local: ReadonlySet<string>): Set<string>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { JoploError } from "./result.js";
|
|
2
|
+
export function localOnlyWorks(project) {
|
|
3
|
+
const ids = new Set();
|
|
4
|
+
for (const w of Object.values(project.works)) {
|
|
5
|
+
if (w.featureId)
|
|
6
|
+
continue;
|
|
7
|
+
const slices = Object.values(project.scenarios).some(s => s.workId === w.id);
|
|
8
|
+
if (w.draft || !slices)
|
|
9
|
+
ids.add(w.id);
|
|
10
|
+
}
|
|
11
|
+
return ids;
|
|
12
|
+
}
|
|
13
|
+
export function assertExportableEntry(project, featureId) {
|
|
14
|
+
const w = project.works[featureId];
|
|
15
|
+
if (!w || w.featureId)
|
|
16
|
+
return;
|
|
17
|
+
if (w.draft)
|
|
18
|
+
throw new JoploError('USAGE', `Work "${featureId}" is a draft and cannot be published or reviewed. Remove draft: true when it is ready`);
|
|
19
|
+
if (!Object.values(project.scenarios).some(s => s.workId === w.id))
|
|
20
|
+
throw new JoploError('USAGE', `Work "${featureId}" has no slices and cannot be published or reviewed. Add at least one flow() or chapter() in scenarios`);
|
|
21
|
+
}
|
|
22
|
+
/** 先裁掉完整贡献子树,再算父元素标签,避免祖先标签把子树文字重新带回来。 */
|
|
23
|
+
export function withoutLocalContributions(node, local) {
|
|
24
|
+
if (node.from && local.has(node.from))
|
|
25
|
+
return null;
|
|
26
|
+
if (!node.children)
|
|
27
|
+
return node;
|
|
28
|
+
return { ...node, children: node.children.map(n => withoutLocalContributions(n, local)).filter((n) => n !== null) };
|
|
29
|
+
}
|
|
30
|
+
/** id 可跨作品复用:仅保护在公开画面里没有独立出现的本地元素。 */
|
|
31
|
+
export function localOnlyElementIds(project, local) {
|
|
32
|
+
if (!local.size)
|
|
33
|
+
return new Set();
|
|
34
|
+
const privateIds = new Set(), publicIds = new Set();
|
|
35
|
+
const walk = (node, owned) => {
|
|
36
|
+
const privateOwner = node.from ? local.has(node.from) : owned;
|
|
37
|
+
(privateOwner ? privateIds : publicIds).add(node.id);
|
|
38
|
+
node.children?.forEach(n => walk(n, privateOwner));
|
|
39
|
+
};
|
|
40
|
+
for (const scene of Object.values(project.scenes))
|
|
41
|
+
walk(scene.root, local.has(scene.workId ?? '') || local.has(project.routes[scene.route]?.addedBy ?? ''));
|
|
42
|
+
for (const id of publicIds)
|
|
43
|
+
privateIds.delete(id);
|
|
44
|
+
return privateIds;
|
|
45
|
+
}
|
package/dist/result.d.ts
CHANGED
package/dist/review.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { Project } from './schema.js';
|
|
2
|
-
|
|
2
|
+
/** 2(D103):features[].options → works、optionId → workId、scenarios[].featureId 可为 null、新增顶层 works(独立作品)。清单的结构变了就升,云端按版本号严格解析。 */
|
|
3
|
+
export declare const REVIEW_MANIFEST_VERSION: 2;
|
|
3
4
|
/** 契约 8.1:评审清单 JSON(UTF-8)最多 512 KiB。 */
|
|
4
5
|
export declare const REVIEW_MANIFEST_MAX_BYTES: number;
|
|
5
6
|
/** 字段上限(客户端截断;SaaS 的 zod 校验至少要接受这些值)。 */
|
|
6
7
|
export declare const REVIEW_LIMITS: {
|
|
7
8
|
readonly features: 100;
|
|
8
9
|
/** 每个功能的方案数。 */
|
|
9
|
-
readonly
|
|
10
|
+
readonly works: 20;
|
|
10
11
|
/** 每个功能的规则数(功能级 + 方案级)。 */
|
|
11
12
|
readonly rules: 300;
|
|
12
13
|
readonly questions: 100;
|
|
@@ -22,7 +23,7 @@ export declare const REVIEW_LIMITS: {
|
|
|
22
23
|
readonly text: {
|
|
23
24
|
readonly name: 200;
|
|
24
25
|
readonly goal: 2000;
|
|
25
|
-
readonly
|
|
26
|
+
readonly summary: 2000;
|
|
26
27
|
readonly tradeoff: 500;
|
|
27
28
|
readonly rule: 2000;
|
|
28
29
|
readonly question: 2000;
|
|
@@ -35,21 +36,28 @@ export type ReviewManifestMode = 'publish' | 'review';
|
|
|
35
36
|
export type ReviewManifest = {
|
|
36
37
|
v: typeof REVIEW_MANIFEST_VERSION;
|
|
37
38
|
mode: ReviewManifestMode;
|
|
39
|
+
/** 参与清单的独立作品,按 entryIds 排序;功能下的作品在 features[].works。 */
|
|
40
|
+
works: {
|
|
41
|
+
id: string;
|
|
42
|
+
key: string;
|
|
43
|
+
title: string;
|
|
44
|
+
summary: string;
|
|
45
|
+
}[];
|
|
38
46
|
features: {
|
|
39
47
|
id: string;
|
|
40
48
|
name: string;
|
|
41
49
|
goal: string;
|
|
42
50
|
pick: string | null;
|
|
43
|
-
|
|
51
|
+
works: {
|
|
44
52
|
id: string;
|
|
45
53
|
key: string;
|
|
46
|
-
|
|
47
|
-
|
|
54
|
+
title: string;
|
|
55
|
+
summary: string;
|
|
48
56
|
tradeoffs: string[];
|
|
49
57
|
}[];
|
|
50
58
|
rules: {
|
|
51
59
|
id: string;
|
|
52
|
-
|
|
60
|
+
workId: string | null;
|
|
53
61
|
text: string;
|
|
54
62
|
origin: string;
|
|
55
63
|
confirmation: string;
|
|
@@ -57,15 +65,15 @@ export type ReviewManifest = {
|
|
|
57
65
|
}[];
|
|
58
66
|
questions: {
|
|
59
67
|
id: string;
|
|
60
|
-
|
|
68
|
+
workId: string | null;
|
|
61
69
|
text: string;
|
|
62
70
|
severity: 'blocker' | 'major' | 'minor';
|
|
63
71
|
}[];
|
|
64
72
|
}[];
|
|
65
73
|
scenarios: {
|
|
66
74
|
id: string;
|
|
67
|
-
featureId: string;
|
|
68
|
-
|
|
75
|
+
featureId: string | null;
|
|
76
|
+
workId: string;
|
|
69
77
|
name: string;
|
|
70
78
|
steps: {
|
|
71
79
|
id: string;
|