@joplo-app/core 0.2.17 → 0.3.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 (64) hide show
  1. package/dist/actions.d.ts +6 -0
  2. package/dist/actions.js +34 -0
  3. package/dist/agent-skill.d.ts +10 -13
  4. package/dist/agent-skill.js +52 -31
  5. package/dist/auto-caption.d.ts +22 -0
  6. package/dist/auto-caption.js +166 -0
  7. package/dist/catalog.d.ts +38 -41
  8. package/dist/catalog.js +26 -317
  9. package/dist/compile.d.ts +2 -8
  10. package/dist/compile.js +302 -353
  11. package/dist/content-i18n.js +27 -16
  12. package/dist/feature-diff.d.ts +3 -3
  13. package/dist/feature-diff.js +28 -6
  14. package/dist/focus.d.ts +3 -1
  15. package/dist/focus.js +16 -34
  16. package/dist/guide.d.ts +10 -12
  17. package/dist/guide.js +419 -519
  18. package/dist/index.d.ts +4 -1
  19. package/dist/index.js +4 -1
  20. package/dist/media.d.ts +10 -0
  21. package/dist/media.js +43 -0
  22. package/dist/node.d.ts +1 -2
  23. package/dist/node.js +1 -2
  24. package/dist/outline.d.ts +1 -1
  25. package/dist/outline.js +3 -3
  26. package/dist/pace.d.ts +9 -1
  27. package/dist/pace.js +23 -3
  28. package/dist/player.d.ts +8 -41
  29. package/dist/player.js +85 -148
  30. package/dist/playground.d.ts +38 -0
  31. package/dist/playground.js +111 -0
  32. package/dist/plugin-data.d.ts +11 -0
  33. package/dist/plugin-data.js +96 -0
  34. package/dist/plugins/compiler.d.ts +66 -0
  35. package/dist/plugins/compiler.js +428 -0
  36. package/dist/plugins/data.d.ts +12 -0
  37. package/dist/plugins/data.js +120 -0
  38. package/dist/result.d.ts +1 -1
  39. package/dist/result.js +1 -0
  40. package/dist/runtime.d.ts +22 -0
  41. package/dist/runtime.js +18 -0
  42. package/dist/schema.d.ts +566 -82
  43. package/dist/schema.js +65 -53
  44. package/dist/scope.js +14 -5
  45. package/dist/step-identity.d.ts +1 -1
  46. package/dist/step-identity.js +1 -1
  47. package/dist/themes.d.ts +7 -0
  48. package/dist/themes.js +5 -0
  49. package/dist/traits.d.ts +7 -0
  50. package/dist/traits.js +26 -0
  51. package/dist/validate.js +17 -4
  52. package/dist/voice.d.ts +8 -2
  53. package/dist/voice.js +14 -2
  54. package/package.json +7 -4
  55. package/dist/diagram/elk.d.ts +0 -6
  56. package/dist/diagram/elk.js +0 -56
  57. package/dist/diagram/graph-layout.d.ts +0 -123
  58. package/dist/diagram/graph-layout.js +0 -620
  59. package/dist/diagram/index.d.ts +0 -41
  60. package/dist/diagram/index.js +0 -92
  61. package/dist/diagram/model.d.ts +0 -217
  62. package/dist/diagram/model.js +0 -189
  63. package/dist/diagram/sequence-layout.d.ts +0 -12
  64. package/dist/diagram/sequence-layout.js +0 -185
package/dist/schema.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { ElementTraitsSchema } from "./traits.js";
1
2
  /**
2
3
  * Joplo IR(schemaVersion 2):由 TSX 源文件编译得到的中间表示,不是作者直接编辑的格式。
3
4
  * 权威源是项目文件夹里的 TSX/TS 文件(ADR-0002);渲染器、播放器、校验器、构建只消费这里的 IR。
@@ -5,9 +6,16 @@
5
6
  * 带 `source` 的对象记录其来源 `相对路径:行:列`,用于选中元素、诊断定位,让 Agent 只读写那一处。
6
7
  */
7
8
  import { z } from 'zod';
8
- import { COMPONENT_TYPES } from "./catalog.js";
9
+ import { COMPONENT_TYPES, PLUGIN_TYPE } from "./catalog.js";
9
10
  /** 层级标签的预设图标(标签压窄时靠它认出是哪一层)。不写时:手机视口 mobile,其余 window。 */
10
11
  export const LAYER_ICONS = ['window', 'browser', 'mobile', 'desktop', 'terminal', 'chat', 'agent', 'server', 'data', 'email', 'doc', 'flow'];
12
+ const DataPath = z.array(z.string().min(1));
13
+ const ScopeRule = z.lazy(() => z.strictObject({
14
+ path: DataPath, kind: z.enum(['map', 'items', 'values', 'reference']), domain: z.enum(['element', 'scene']).optional(),
15
+ prefix: z.string().optional(), references: z.array(DataPath).optional(), children: z.array(ScopeRule).optional(),
16
+ }));
17
+ const SlotSpec = z.strictObject({ text: z.array(DataPath).optional(), scope: z.union([z.literal('global'), z.array(ScopeRule)]).optional() });
18
+ const DataSpec = z.strictObject({ node: SlotSpec.optional(), step: SlotSpec.optional() });
11
19
  export const SCHEMA_VERSION = 2;
12
20
  /** 作者可写的 ID(对象键、元素 id)。 */
13
21
  export const Id = z.string().regex(/^[A-Za-z][A-Za-z0-9_-]{0,63}$/, 'ID must start with a letter and contain only letters, digits, underscores, and hyphens');
@@ -29,40 +37,10 @@ export const Condition = z.lazy(() => z.union([
29
37
  z.strictObject({ or: z.array(Condition) }),
30
38
  z.strictObject({ not: Condition }),
31
39
  ]));
32
- // ---------- 图表布局(D69):编译期算好,渲染器只读 ----------
33
- const Num = z.number().finite();
34
- const BoxS = z.strictObject({ x: Num, y: Num, w: Num, h: Num });
35
- const PointS = z.strictObject({ x: Num, y: Num });
36
- const Boxes = z.record(z.string(), BoxS);
37
- export const DiagramLayoutSchema = z.union([
38
- z.strictObject({
39
- kind: z.literal('graph'),
40
- engine: z.enum(['elk', 'grid']),
41
- direction: z.enum(['right', 'down']).optional(),
42
- width: Num,
43
- height: Num,
44
- nodes: Boxes,
45
- groups: Boxes,
46
- titles: Boxes,
47
- edges: z.record(z.string(), z.strictObject({ points: z.array(PointS), label: BoxS.nullable() })),
48
- starts: Boxes.optional(),
49
- }),
50
- z.strictObject({
51
- kind: z.literal('sequence'),
52
- width: Num,
53
- height: Num,
54
- actors: Boxes,
55
- lifelines: z.record(z.string(), z.strictObject({ x: Num, y1: Num, y2: Num })),
56
- messages: z.record(z.string(), z.strictObject({ points: z.array(PointS), label: BoxS.nullable(), n: z.number().int(), self: z.boolean() })),
57
- groups: Boxes,
58
- titles: Boxes,
59
- blocks: Boxes,
60
- blockTitles: Boxes,
61
- }),
62
- ]);
63
40
  export const SceneNode = z.lazy(() => z.strictObject({
64
41
  id: z.string().min(1),
65
- type: z.enum(COMPONENT_TYPES),
42
+ type: z.union([z.enum(COMPONENT_TYPES), z.string().regex(PLUGIN_TYPE)]),
43
+ traits: ElementTraitsSchema.optional(),
66
44
  props: z.record(z.string(), Json).optional(),
67
45
  children: z.array(SceneNode).optional(),
68
46
  when: Condition.optional(),
@@ -72,7 +50,8 @@ export const SceneNode = z.lazy(() => z.strictObject({
72
50
  note: z.string().optional(),
73
51
  redact: z.union([z.boolean(), Condition]).optional(),
74
52
  from: z.string().optional(),
75
- layout: DiagramLayoutSchema.optional(),
53
+ ext: z.record(z.string(), Json).optional(),
54
+ framing: z.strictObject({ include: z.array(z.string()).optional(), kind: z.enum(['root', 'group', 'block', 'content', 'edge', 'row']).optional() }).optional(),
76
55
  source: Source,
77
56
  }));
78
57
  /** 一个画面 = 某个方案上下文中的一个路径:布局 + 页面 + 堆叠进来的功能元素。 */
@@ -88,8 +67,18 @@ export const Scene = z.strictObject({
88
67
  layer: z.string().optional(),
89
68
  });
90
69
  // ---------- 步骤与场景 ----------
70
+ const ActionPoint = z.strictObject({ x: z.number().finite(), y: z.number().finite() });
71
+ export const PluginAction = z.strictObject({
72
+ caption: z.string().min(1), durationMs: z.number().finite().positive().max(30000),
73
+ fields: z.record(z.string().regex(/^[A-Za-z][A-Za-z0-9_]*$/).refine(k => !['__proto__', 'prototype', 'constructor'].includes(k)), z.strictObject({ type: z.enum(['string', 'number', 'boolean']), min: z.number().finite().optional(), max: z.number().finite().optional(), tolerance: z.number().finite().nonnegative().optional(), text: z.boolean().optional() }).refine(f => (f.min === undefined || f.max === undefined || f.min <= f.max) && (f.type === 'number' || f.min === undefined && f.max === undefined && f.tolerance === undefined) && (!f.text || f.type === 'string'))),
74
+ targets: z.array(z.string().min(1)).optional(),
75
+ });
91
76
  export const Action = z.discriminatedUnion('type', [
92
77
  z.strictObject({ type: z.literal('click'), target: Id }),
78
+ z.strictObject({ type: z.literal('drag'), target: Id, to: z.union([Id, ActionPoint]) }),
79
+ z.strictObject({ type: z.literal('hover'), target: Id, ms: z.number().finite().nonnegative().max(30000) }),
80
+ z.strictObject({ type: z.literal('scroll'), target: Id, to: z.union([Id, ActionPoint.refine(p => p.x >= 0 && p.y >= 0)]) }),
81
+ z.strictObject({ type: z.literal('plugin'), name: z.string().regex(/^[a-z][a-z0-9-]*:[a-z][a-zA-Z0-9-]*$/), target: Id, data: z.record(z.string(), Json) }),
93
82
  z.strictObject({ type: z.literal('type'), target: Id, value: z.string() }),
94
83
  z.strictObject({ type: z.literal('select'), target: Id, value: z.string() }),
95
84
  z.strictObject({ type: z.literal('toggle'), target: Id, value: z.boolean() }),
@@ -108,20 +97,6 @@ export const Effect = z.discriminatedUnion('type', [
108
97
  /** 流式输出(D56):状态上等同 set;播放到这一步时绑定它的文字逐字出现。 */
109
98
  z.strictObject({ type: z.literal('stream'), path: StatePath, value: z.string() }),
110
99
  ]);
111
- /**
112
- * 调用链(D48):这一步 trace 的一条路径。nodes 按路径顺序;edges 是路径上的连线,reverse = 沿连线的 to→from 方向走。
113
- * mode:ok = 正常调用(本步 active,之后 ok);fail = 失败(连线与终点节点 error);skip = 没被调用(dim)。
114
- */
115
- export const Trace = z.strictObject({
116
- mode: z.enum(['ok', 'fail', 'skip']),
117
- nodes: z.array(z.string().min(1)),
118
- edges: z.array(z.strictObject({ id: z.string().min(1), reverse: z.boolean().default(false) })),
119
- /** 路径经过的分组(节点所在的各级分组,D69):fail 时 errorGroups 是终点所在的分组。没有分组时省略(IR 与旧版相同)。 */
120
- groups: z.array(z.string().min(1)).optional(),
121
- errorGroups: z.array(z.string().min(1)).optional(),
122
- /** 镜头目标:架构图 / 状态机是路径上的节点,时序图是消息(一行一行的)。旧 IR 没有,按 nodes 处理。 */
123
- targets: z.array(z.string().min(1)).optional(),
124
- });
125
100
  /** 镜头(D43):这一步在某个层级里对准哪些元素;targets 为空 = 这一层的整体。 */
126
101
  export const Shot = z.strictObject({ layer: z.string().min(1), targets: z.array(z.string().min(1)) });
127
102
  export const Fork = z.strictObject({ label: z.string().min(1), scenarioId: Qid, at: z.number().int().nonnegative() });
@@ -135,16 +110,21 @@ export const Cue = z.strictObject({ kind: z.enum(CUE_KINDS), targets: z.array(z.
135
110
  /** 标注气泡(D70):指向元素的一句话;side 不写时由渲染器选放得下的一侧。 */
136
111
  export const CALLOUT_SIDES = ['top', 'right', 'bottom', 'left'];
137
112
  export const Callout = z.strictObject({ target: z.string().min(1), text: z.string().min(1), side: z.enum(CALLOUT_SIDES).optional() });
113
+ export const MediaSnapshot = z.record(z.string(), z.strictObject({
114
+ plugin: z.string().min(1), resource: z.string().min(1), offsetMs: z.number().nonnegative(), startOffsetMs: z.number().nonnegative().optional(),
115
+ volume: z.number().min(0).max(1), loop: z.boolean(), fadeInMs: z.number().nonnegative(), stopAfterMs: z.number().nonnegative().optional(),
116
+ }));
138
117
  export const Step = z.strictObject({
118
+ media: MediaSnapshot.optional(),
139
119
  id: Qid,
140
- /** Author identity, unique within a scenario. id remains the legacy playback address. */
120
+ /** Author identity, unique within a scenario. id remains the playback address. */
141
121
  key: Id.optional(),
142
122
  kind: z.enum(['user', 'system', 'card']),
143
123
  action: Action,
144
124
  caption: z.string().min(1),
145
125
  /** Generated caption metadata; caption remains the English fallback for tools. */
146
126
  captionAuto: z.strictObject({
147
- kind: z.enum(['click', 'type', 'select', 'check', 'uncheck', 'switch_on', 'switch_off', 'back', 'press']),
127
+ kind: z.enum(['click', 'type', 'select', 'check', 'uncheck', 'switch_on', 'switch_off', 'back', 'press', 'drag', 'hover', 'scroll']),
148
128
  label: z.string(),
149
129
  value: z.string().optional(),
150
130
  keys: z.string().optional(),
@@ -157,8 +137,11 @@ export const Step = z.strictObject({
157
137
  directorLayer: z.string().nullable().default(null),
158
138
  /** 较长的解说(来自 explain(),多个按换行连接):字幕区第二行显示(说明下方、小一号);发布站保留。 */
159
139
  explain: z.string().min(1).optional(),
160
- /** 这一步的调用链(来自 trace()):Diagram 节点与连线的 state 由 diagramStateAt 从它推算;发布站保留。 */
161
- traces: z.array(Trace).default([]),
140
+ /** 插件效果降级后的逐步快照。 */
141
+ ext: z.record(z.string(), Json).optional(),
142
+ /** 插件效果贡献的显式焦点与引用(scope 校验)。 */
143
+ focusTargets: z.array(z.string()).optional(),
144
+ references: z.array(z.string()).optional(),
162
145
  /** 分叉是演示信息,发布保留;at 在编译时比较动作与业务效果的公共前缀。 */
163
146
  forks: z.array(Fork).default([]),
164
147
  /** 本步标注,不累积,不参与状态转换。 */
@@ -176,6 +159,14 @@ export const Step = z.strictObject({
176
159
  source: Source,
177
160
  });
178
161
  export const Scenario = z.strictObject({
162
+ /** Optional chapters remain selectable but do not join sequential autoplay. */
163
+ autoplay: z.boolean().optional(),
164
+ /** Where a confirmed cross-scenario action enters; autoplay is unaffected. */
165
+ actionEntry: z.enum(['before', 'after']).optional(),
166
+ /** flow({ from }) 接力的上一个场景(D92):连续播放时一镜到底接上,不倒计时、不重置画面与配乐。 */
167
+ from: Qid.optional(),
168
+ media: MediaSnapshot.optional(),
169
+ ext: z.record(z.string(), Json).optional(),
179
170
  id: Qid,
180
171
  optionId: Qid,
181
172
  name: z.string().min(1),
@@ -187,6 +178,8 @@ export const Scenario = z.strictObject({
187
178
  ui: z.record(z.string(), Json).default({}),
188
179
  data: z.record(z.string(), Json).default({}),
189
180
  inputs: z.record(z.string(), Json).default({}),
181
+ /** 起始导演层(flow({ layer }),或 flow({ from }) 接力时那个场景结尾的导演层);缺省为第一层。 */
182
+ layer: z.string().optional(),
190
183
  }),
191
184
  steps: z.array(Step).default([]),
192
185
  expected: z.string().default(''),
@@ -234,7 +227,9 @@ export const Coverage = z.strictObject({
234
227
  /** derived = 编译器根据场景推导;declared = 作者在源文件中声明。 */
235
228
  basis: z.enum(['derived', 'declared']).default('declared'),
236
229
  });
230
+ export const FreeReaction = z.strictObject({ action: Action, effects: z.array(Effect).default([]), source: Source });
237
231
  export const Option = z.strictObject({
232
+ free: z.record(Id, FreeReaction).optional(),
238
233
  id: Qid,
239
234
  featureId: Id,
240
235
  /** 文件名,例如 `a-modal`。 */
@@ -303,9 +298,13 @@ export const VoiceIndex = z.strictObject({
303
298
  narrator: z.string().min(1).nullable(),
304
299
  roles: z.record(z.string(), z.string().min(1)).default({}),
305
300
  clips: z.record(z.string(), z.string().min(1)).default({}),
301
+ /** 混合来源更新:clipKey(角色 id 或空串, 文字) → 实际声音指纹;音频键仍使用真实指纹。 */
302
+ overrides: z.record(z.string(), z.string().min(1)).optional(),
306
303
  /** 内容语言(D84)→ 这种语言的旁白与角色指纹;没有的语言用上面的默认声音。 */
307
- locales: z.record(z.string(), z.strictObject({ narrator: z.string().min(1).nullable(), roles: z.record(z.string(), z.string().min(1)).default({}) })).optional(),
304
+ locales: z.record(z.string(), z.strictObject({ narrator: z.string().min(1).nullable(), roles: z.record(z.string(), z.string().min(1)).default({}), overrides: z.record(z.string(), z.string().min(1)).optional() })).optional(),
308
305
  });
306
+ /** Only calibrated numeric playback data may cross the author/public boundary. */
307
+ export const AudioRegionSchema = z.strictObject({ sourceSampleRate: z.number().positive(), cycleFrames: z.number().int().positive(), contentStartFrame: z.number().int().nonnegative(), contentFrames: z.number().int().positive(), decodedFrames: z.number().int().positive(), encoderDelayFrames: z.number().int().nonnegative(), paddingFrames: z.number().int().nonnegative(), channels: z.number().int().min(1).max(2) }).refine(v => v.contentStartFrame + v.contentFrames <= v.decodedFrames && v.cycleFrames <= v.contentFrames, 'Audio region exceeds decoded samples');
309
308
  export const Project = z.strictObject({
310
309
  schemaVersion: z.literal(SCHEMA_VERSION),
311
310
  name: z.string().min(1),
@@ -316,8 +315,21 @@ export const Project = z.strictObject({
316
315
  autoFocus: z.boolean().optional(),
317
316
  voiceConfig: VoiceConfig.optional(),
318
317
  voiceIndex: VoiceIndex.optional(),
318
+ mediaAssets: z.record(z.string(), z.string()).optional(),
319
+ mediaInfo: z.record(z.string(), AudioRegionSchema).optional(),
319
320
  /** 作者内容多语言(D84):只有 config 写了 locales 才有。messages 只含非默认语言、这份 IR 用得到的译文;stale 只在 dev IR。 */
320
321
  i18n: ContentI18nSchema.optional(),
322
+ /** 启用的插件(D86):插件 id → 名称、版本与组件声明(可操作、父组件)。运行时代码不在 IR 里,由看板 / 发布站另外载入。 */
323
+ plugins: z.record(z.string(), z.strictObject({
324
+ actions: z.record(z.string(), PluginAction).optional(),
325
+ themes: z.record(z.string(), z.string()).optional(),
326
+ properties: z.record(z.string(), z.strictObject({ type: z.enum(['string', 'number', 'boolean']), attribute: z.string().regex(/^data-jp-[a-z0-9-]+$/).optional(), min: z.number().optional(), max: z.number().optional(), nonempty: z.boolean().optional(), values: z.array(z.string()).optional() })).optional(),
327
+ data: DataSpec.optional(),
328
+ id: z.string().min(1),
329
+ title: z.string(),
330
+ version: z.string().optional(),
331
+ components: z.record(z.string(), z.strictObject({ interactive: z.boolean().optional(), parent: z.string().optional(), needsId: z.boolean().optional(), selfEvident: z.boolean().optional(), traits: ElementTraitsSchema.optional() })),
332
+ })).optional(),
321
333
  /** 作者主题(D51):主题名 → CSS 原文(themes/<name>.css);渲染时自动限定在舞台范围内。发布站同样打包。 */
322
334
  themes: z.record(z.string(), z.string()).default({}),
323
335
  /** dev = 含全部方案(本地看板);publish = 只含选定方案,且去掉创作侧信息(D33);review = 评审版:全部方案,同样去掉创作侧信息(D63)。 */
package/dist/scope.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { pruneMediaAssets } from "./media.js";
2
+ import { scopePluginData } from "./plugin-data.js";
1
3
  /**
2
4
  * 按场景保密分享(D75):把编译好的 IR 裁剪到若干场景。
3
5
  *
@@ -75,6 +77,8 @@ export function stepRefs(st) {
75
77
  const out = [];
76
78
  if ('target' in st.action)
77
79
  out.push(st.action.target);
80
+ if ((st.action.type === 'drag' || st.action.type === 'scroll') && typeof st.action.to === 'string')
81
+ out.push(st.action.to);
78
82
  for (const s of st.shots)
79
83
  out.push(...s.targets);
80
84
  for (const m of st.marks)
@@ -83,8 +87,7 @@ export function stepRefs(st) {
83
87
  out.push(...c.targets);
84
88
  for (const c of st.callouts ?? [])
85
89
  out.push(c.target);
86
- for (const t of st.traces)
87
- out.push(...t.nodes, ...t.edges.map((e) => e.id), ...(t.groups ?? []), ...(t.errorGroups ?? []), ...(t.targets ?? []));
90
+ out.push(...st.references ?? []);
88
91
  return out;
89
92
  }
90
93
  function idsIn(n, out = []) {
@@ -190,7 +193,8 @@ export function scopeProject(project, scenarioIds, mode = project.mode === 'revi
190
193
  if (!S.has(sid))
191
194
  continue;
192
195
  const s = project.scenarios[sid];
193
- scenarios[sid] = { ...s, steps: s.steps.map((st) => (st.forks.some((f) => !S.has(f.scenarioId)) ? { ...st, forks: st.forks.filter((f) => S.has(f.scenarioId)) } : st)) };
196
+ const { from, ...rest } = s;
197
+ scenarios[sid] = { ...rest, ...(from && S.has(from) ? { from } : {}), steps: s.steps.map((st) => (st.forks.some((f) => !S.has(f.scenarioId)) ? { ...st, forks: st.forks.filter((f) => S.has(f.scenarioId)) } : st)) };
194
198
  }
195
199
  const options = {};
196
200
  for (const [id, o] of Object.entries(project.options)) {
@@ -199,7 +203,12 @@ export function scopeProject(project, scenarioIds, mode = project.mode === 'revi
199
203
  const coverage = Object.fromEntries(Object.entries(o.coverage)
200
204
  .filter(([cid]) => F.has(project.cases[cid]?.featureId ?? cid.split('.')[0] ?? ''))
201
205
  .map(([cid, c]) => [cid, { ...c, scenarioIds: c.scenarioIds.filter((x) => S.has(x)) }]));
202
- options[id] = { ...o, coverage };
206
+ const retained = new Set(Object.values(scenes).filter(s => s.optionId === id || s.optionId === null).flatMap(s => idsIn(s.root)));
207
+ const free = o.free ? Object.fromEntries(Object.entries(o.free).filter(([, reaction]) => {
208
+ const a = reaction.action;
209
+ return 'target' in a && retained.has(a.target) && (!('to' in a) || typeof a.to !== 'string' || retained.has(a.to));
210
+ })) : undefined;
211
+ options[id] = { ...o, coverage, ...(free ? { free } : {}) };
203
212
  }
204
213
  const features = {};
205
214
  for (const f of orderedFeatures(project)) {
@@ -237,7 +246,7 @@ export function scopeProject(project, scenarioIds, mode = project.mode === 'revi
237
246
  };
238
247
  const ids = Object.keys(scenarios);
239
248
  // 译文只留范围内用得到的(D84):别的功能的文字不随范围分享出去
240
- return { project: pruneMessages(out), info: { key: scopeKey(ids, mode), scenarios: ids, features: Object.keys(features), borrowed: merged } };
249
+ return { project: pruneMediaAssets(pruneMessages(scopePluginData(out))), info: { key: scopeKey(ids, mode), scenarios: ids, features: Object.keys(features), borrowed: merged } };
241
250
  }
242
251
  /** 一条借用的说明(英文,CLI 与看板共用)。 */
243
252
  export function borrowedLine(b) {
@@ -1,4 +1,4 @@
1
- /** Stable author identities are separate from public playback IR for strict legacy readers. */
1
+ /** Stable author identities are separate from public playback IR to keep author identity metadata separate from runtime state. */
2
2
  import { z } from 'zod';
3
3
  import { Project } from './schema.js';
4
4
  export declare const StepIdentity: z.ZodObject<{
@@ -1,4 +1,4 @@
1
- /** Stable author identities are separate from public playback IR for strict legacy readers. */
1
+ /** Stable author identities are separate from public playback IR to keep author identity metadata separate from runtime state. */
2
2
  import { z } from 'zod';
3
3
  import { Id, Project, Qid, SCHEMA_VERSION } from "./schema.js";
4
4
  import { JoploError } from "./result.js";
@@ -0,0 +1,7 @@
1
+ /** Combine plugin-owned CSS with author CSS; author themes keep their existing IR semantics. */
2
+ export declare function projectThemes(project: {
3
+ themes?: Record<string, string>;
4
+ plugins?: Record<string, {
5
+ themes?: Record<string, string>;
6
+ }>;
7
+ } | null | undefined): Record<string, string>;
package/dist/themes.js ADDED
@@ -0,0 +1,5 @@
1
+ /** Combine plugin-owned CSS with author CSS; author themes keep their existing IR semantics. */
2
+ export function projectThemes(project) {
3
+ const pluginThemes = Object.fromEntries(Object.entries(project?.plugins ?? {}).flatMap(([id, plugin]) => Object.entries(plugin.themes ?? {}).map(([name, css]) => [`${id}:${name}`, css])));
4
+ return { ...pluginThemes, ...project?.themes };
5
+ }
@@ -0,0 +1,7 @@
1
+ import { z } from 'zod';
2
+ import type { ElementTraits } from '@joplo-app/kit/plugin';
3
+ export declare const ElementTraitsSchema: z.ZodType<ElementTraits>;
4
+ export declare const InheritSchema: z.ZodArray<z.ZodObject<{
5
+ target: z.ZodString;
6
+ props: z.ZodArray<z.ZodString>;
7
+ }, z.core.$strict>>;
package/dist/traits.js ADDED
@@ -0,0 +1,26 @@
1
+ import { z } from 'zod';
2
+ const key = z.string().min(1).refine(s => !['__proto__', 'prototype', 'constructor'].includes(s));
3
+ const keys = z.array(key).min(1);
4
+ export const ElementTraitsSchema = z.strictObject({
5
+ native: z.strictObject({ action: z.enum(['type', 'toggle', 'select']), prop: key, deselect: z.boolean().optional() }).optional(),
6
+ draggable: z.boolean().optional(),
7
+ hover: z.boolean().optional(),
8
+ selectionGate: z.strictObject({ owner: key, item: key.optional(), value: key, fallbackFirst: z.boolean().optional() }).optional(),
9
+ disabledPresentation: z.boolean().optional(),
10
+ frame: z.boolean().optional(),
11
+ input: z.enum(['single', 'multiple']).optional(),
12
+ gate: keys.optional(),
13
+ choices: z.union([
14
+ z.strictObject({ prop: key }),
15
+ z.strictObject({ descendants: keys, value: key.optional(), label: key.optional(), labelChild: key.optional() }),
16
+ z.strictObject({ range: key }),
17
+ ]).optional(),
18
+ toggleCaption: z.literal('check').optional(),
19
+ selfEvident: z.boolean().optional(),
20
+ layout: z.record(key, z.strictObject({ size: key, defaultSize: z.number().finite().nonnegative(), breakpoint: z.boolean().optional() })).optional(),
21
+ region: key.optional(),
22
+ childWidth: z.strictObject({ value: z.number().finite().positive(), when: z.strictObject({ prop: key, value: z.union([z.string(), z.number().finite(), z.boolean()]), width: z.number().finite().positive() }).optional() }).optional(),
23
+ text: z.array(key).optional(),
24
+ textPaths: z.array(keys).optional(),
25
+ });
26
+ export const InheritSchema = z.array(z.strictObject({ target: key, props: keys }));
package/dist/validate.js CHANGED
@@ -1,6 +1,7 @@
1
+ import { pluginSpec } from "./catalog.js";
1
2
  import { orderedFeatures } from "./features.js";
2
3
  import { Project } from "./schema.js";
3
- import { CAPTION_MAX, CARD_POINTS_MAX, DESCRIPTION_MAX, EXPLAIN_MAX, SAY_MAX, INTERACTIVE_TYPES, SCENARIO_MS_MAX, captionLength } from "./catalog.js";
4
+ import { CAPTION_MAX, CARD_POINTS_MAX, DESCRIPTION_MAX, EXPLAIN_MAX, SAY_MAX, isInteractiveType, SCENARIO_MS_MAX, captionLength } from "./catalog.js";
4
5
  import { scenarioEstimateMs } from "./outline.js";
5
6
  import { walkNodes, findNode, replay } from "./player.js";
6
7
  import { JoploError } from "./result.js";
@@ -135,6 +136,16 @@ export function validate(project, opts = { mode: 'all' }) {
135
136
  }
136
137
  }
137
138
  }
139
+ for (const option of Object.values(p.options))
140
+ for (const reaction of Object.values(option.free ?? {})) {
141
+ if (!('target' in reaction.action))
142
+ continue;
143
+ for (const scene of Object.values(p.scenes).filter(s => s.optionId === option.id || s.optionId === null)) {
144
+ const hit = findNode(scene, reaction.action.target)?.node;
145
+ if (hit && (!hit.from || hit.from === option.id))
146
+ bound.add(identity(hit));
147
+ }
148
+ }
138
149
  for (const s of Object.values(p.scenes).filter(s => included(s.optionId))) {
139
150
  const value = { id: s.id, optionId: s.optionId ?? undefined, source: s.root.source ?? (s.optionId ? p.options[s.optionId]?.source : undefined) };
140
151
  ref(p.scenes[s.id] === s, `Stage key does not match ID: ${s.id}`, value, 'scene');
@@ -143,14 +154,16 @@ export function validate(project, opts = { mode: 'all' }) {
143
154
  ref(p.routes[s.route], `Stage route does not exist: ${s.route}`, value, 'scene');
144
155
  const ids = new Set();
145
156
  walkNodes(s.root, n => {
157
+ if (pluginSpec(p.plugins, n.type)?.needsId && n.id.startsWith('_'))
158
+ emit('error', 'MISSING_ID', `<${n.type}> requires an author id; recompile after adding id`, n.source, { kind: 'element', id: n.id });
146
159
  const r = { kind: 'element', id: n.id, optionId: n.from ?? s.optionId ?? undefined };
147
160
  if (ids.has(n.id))
148
161
  emit('error', 'DUPLICATE_ELEMENT', `Duplicate element ID in stage: ${n.id}`, n.source, r, 'reference');
149
162
  ids.add(n.id);
150
- // Indicator 的 disabled 只是隐藏角标(Mantine 的含义),不是“不能用”,不要求原因
151
- if (n.disabled !== undefined && n.disabled !== false && !n.disabledReason?.trim() && n.type !== 'Indicator')
163
+ // Plugins may declare disabled as presentation-only, which requires no unavailability reason.
164
+ if (n.disabled !== undefined && n.disabled !== false && !n.disabledReason?.trim() && !n.traits?.disabledPresentation)
152
165
  emit('warning', 'DISABLED_WITHOUT_REASON', `Disabled element has no reason: ${n.id}. Add disabledReason="…" (for example disabledReason="Only admins can invite"), or bind it to state like disabled: disabledReason={$.ui.sendHint}`, n.source, r);
153
- if (INTERACTIVE_TYPES.has(n.type) && !bound.has(identity(n)) && !(n.disabled === true && n.disabledReason?.trim()) && !n.unmodeled)
166
+ if (isInteractiveType(n.type, project.plugins) && !bound.has(identity(n)) && !(n.disabled === true && n.disabledReason?.trim()) && !n.unmodeled)
154
167
  emit('warning', 'UNBOUND_INTERACTIVE', `Interactive element has no demo step: ${n.id}; bind a step, disable with a reason, or mark unmodeled`, n.source, r);
155
168
  });
156
169
  }
package/dist/voice.d.ts CHANGED
@@ -23,8 +23,14 @@ export declare function narrationText(step: Step, caption: string): string;
23
23
  export declare function speakerRoleAt(project: Project, scenarioId: string, index: number): string | null;
24
24
  /** 音频片段的键:声音指纹 + 规整后的朗读文字(空白合并)。 */
25
25
  export declare function clipKey(fingerprint: string, text: string): string;
26
- /** 某个角色(null = 旁白)用哪个声音指纹;角色没有单独的声音时用旁白的。 */
26
+ /** 某个角色(null = 旁白)的声音;传文字时优先该语言索引中的片段覆盖,再用角色 / 旁白指纹。 */
27
27
  export declare function voiceFingerprint(voices: {
28
28
  narrator: string | null;
29
29
  roles: Record<string, string>;
30
- }, roleId: string | null): string | null;
30
+ overrides?: Record<string, string>;
31
+ }, roleId: string | null, text?: string): string | null;
32
+ /**
33
+ * 托管朗读的计费字数(D85,与 Cloud 一致):规整空白后的朗读文字按 Array.from 计(一个 emoji、一个汉字都算 1 个字)。
34
+ * 看板的“约 X 字”、`joplo voice --dry-run` 的估算与服务端的扣费用同一个算法。
35
+ */
36
+ export declare function spokenChars(text: string): number;
package/dist/voice.js CHANGED
@@ -73,7 +73,19 @@ export function clipKey(fingerprint, text) {
73
73
  const s = `${fingerprint}\n${text.replace(/\s+/g, ' ').trim()}`;
74
74
  return `c${cyrb53(s, 1).toString(16).padStart(14, '0')}${cyrb53(s, 7).toString(16).padStart(14, '0')}`;
75
75
  }
76
- /** 某个角色(null = 旁白)用哪个声音指纹;角色没有单独的声音时用旁白的。 */
77
- export function voiceFingerprint(voices, roleId) {
76
+ /** 某个角色(null = 旁白)的声音;传文字时优先该语言索引中的片段覆盖,再用角色 / 旁白指纹。 */
77
+ export function voiceFingerprint(voices, roleId, text) {
78
+ if (text !== undefined) {
79
+ const override = voices.overrides?.[clipKey(roleId ?? '', text)];
80
+ if (override)
81
+ return override;
82
+ }
78
83
  return (roleId ? voices.roles[roleId] : undefined) ?? voices.narrator;
79
84
  }
85
+ /**
86
+ * 托管朗读的计费字数(D85,与 Cloud 一致):规整空白后的朗读文字按 Array.from 计(一个 emoji、一个汉字都算 1 个字)。
87
+ * 看板的“约 X 字”、`joplo voice --dry-run` 的估算与服务端的扣费用同一个算法。
88
+ */
89
+ export function spokenChars(text) {
90
+ return Array.from(text.replace(/\s+/g, ' ').trim()).length;
91
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joplo-app/core",
3
- "version": "0.2.17",
3
+ "version": "0.3.0",
4
4
  "description": "Joplo 编译器、校验器与播放器(IR v2)",
5
5
  "license": "PolyForm-Shield-1.0.0",
6
6
  "type": "module",
@@ -13,14 +13,17 @@
13
13
  "types": "./dist/node.d.ts",
14
14
  "default": "./dist/node.js"
15
15
  },
16
- "./package.json": "./package.json"
16
+ "./package.json": "./package.json",
17
+ "./runtime": {
18
+ "types": "./dist/runtime.d.ts",
19
+ "default": "./dist/runtime.js"
20
+ }
17
21
  },
18
22
  "files": [
19
23
  "dist"
20
24
  ],
21
25
  "dependencies": {
22
- "@joplo-app/kit": "0.2.17",
23
- "elkjs": "0.12.1",
26
+ "@joplo-app/kit": "0.3.0",
24
27
  "zod": "4.6.7"
25
28
  },
26
29
  "engines": {
@@ -1,6 +0,0 @@
1
- import { type ElkRun, type LayoutGoal } from './graph-layout.js';
2
- import { type GraphLayout, type GraphStructure } from './model.js';
3
- /** 同步运行一次 ELK 布局;ELK 报错时抛出 Error。 */
4
- export declare const runElk: ElkRun;
5
- /** 编译期的图表布局引擎:传给 compile(src, mode, { layout: elkLayout })。goal = 目标外框比例(舞台比例)。 */
6
- export declare function elkLayout(s: GraphStructure, goal?: LayoutGoal): GraphLayout;
@@ -1,56 +0,0 @@
1
- /**
2
- * 仅限 Node:同步运行 elkjs(Eclipse Layout Kernel 的 JS 版,EPL-2.0),给编译期的图表布局用(D69)。
3
- *
4
- * elkjs 的公开 API 是异步的(Web Worker 或 setTimeout 模拟的 FakeWorker),但它的 Dispatcher 本身是同步的:
5
- * 直接调用 FakeWorker.dispatcher.saveDispatch,回调在同一个调用栈里返回结果。这样 compile() 保持同步,
6
- * check、dev、build 的调用方式都不变。elkjs 固定版本(package.json 精确版本),这个内部接口由测试守住。
7
- *
8
- * elkjs 只在这里加载:浏览器端(看板、发布站)不打包它,发布站只读 IR 里写好的坐标。
9
- */
10
- import { createRequire } from 'node:module';
11
- import { DEFAULT_ASPECT, layoutGraph } from "./graph-layout.js";
12
- import { structureKey } from "./model.js";
13
- let worker = null;
14
- function elkWorker() {
15
- if (worker)
16
- return worker;
17
- const require = createRequire(import.meta.url);
18
- const mod = require('elkjs/lib/elk-worker.min.js');
19
- const w = new mod.Worker();
20
- w.onmessage = () => { };
21
- w.dispatcher.saveDispatch({ data: { id: 0, cmd: 'register', algorithms: ['layered'] } });
22
- worker = w;
23
- return w;
24
- }
25
- /** 同步运行一次 ELK 布局;ELK 报错时抛出 Error。 */
26
- export const runElk = (graph) => {
27
- const w = elkWorker();
28
- let out = null;
29
- w.onmessage = (e) => {
30
- out = e.data;
31
- };
32
- w.dispatcher.saveDispatch({ data: { id: 1, cmd: 'layout', graph, layoutOptions: {}, options: {} } });
33
- const res = out;
34
- if (!res)
35
- throw new Error('ELK did not return a layout');
36
- if (res.error) {
37
- const e = res.error;
38
- throw new Error(String(e.message ?? e.g ?? e).split('\n')[0].slice(0, 300));
39
- }
40
- return res.data;
41
- };
42
- /** 按结构缓存(dev 每次保存都重新编译,结构没变的图不再跑 ELK)。 */
43
- const cache = new Map();
44
- const CACHE_MAX = 300;
45
- /** 编译期的图表布局引擎:传给 compile(src, mode, { layout: elkLayout })。goal = 目标外框比例(舞台比例)。 */
46
- export function elkLayout(s, goal = { aspect: DEFAULT_ASPECT }) {
47
- const key = `${goal.aspect.toFixed(3)}|${goal.width ?? ''}|${goal.height ?? ''}|${structureKey(s)}`;
48
- const hit = cache.get(key);
49
- if (hit)
50
- return structuredClone(hit);
51
- const l = layoutGraph(structuredClone(s), runElk, goal);
52
- cache.set(key, l);
53
- if (cache.size > CACHE_MAX)
54
- cache.delete(cache.keys().next().value);
55
- return structuredClone(l);
56
- }