@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
@@ -1,3 +1,6 @@
1
+ import { pluginActionSpec } from "./actions.js";
2
+ import { pluginSpec } from "./catalog.js";
3
+ import { mapSlotTexts, mapTextPaths } from "./plugin-data.js";
1
4
  /** 内容语言 = 界面支持的 10 种语言(与网页、服务端的 locale 列表一致)。 */
2
5
  export const CONTENT_LOCALES = ['en', 'zh-CN', 'zh-TW', 'ja', 'ko', 'es', 'fr', 'de', 'pt-BR', 'ru'];
3
6
  export const isContentLocale = (v) => typeof v === 'string' && CONTENT_LOCALES.includes(v);
@@ -10,7 +13,6 @@ const STRUCTURAL = new Set(['from', 'to', 'accessor', 'target', 'href', 'src', '
10
13
  /** 选项、列表项(数组里的对象)的 value 是选项的身份:照常按同一张表换(和状态值、选择动作的值一致),但收集时当作普通属性(像 id 的单词不收)。 */
11
14
  const ITEM_VALUE = 'value';
12
15
  /** 显示文字的属性:收集时不跳过单个英文词(英文项目的按钮名就是一个词)。其余属性里的单个 ASCII 词多半是枚举(sm、blue),不收。 */
13
- const DISPLAY_PROPS = new Set(['text', 'label', 'title', 'description', 'placeholder', 'aria-label', 'alt', 'error', 'hint', 'caption', 'message', 'content', 'subtitle', 'tooltip', 'leftSection', 'rightSection', 'name', 'value', 'data', 'records', 'labels', 'emptyText', 'actionLabel', 'sub', 'badge', 'status', 'items']);
14
16
  /** 每一行都是邮箱或网址:不翻译。 */
15
17
  const addressLike = (s) => s.split('\n').every((l) => /^\s*([^\s@]+@[^\s@]+|https?:\/\/\S+)\s*$/.test(l));
16
18
  /** 有没有字母(任何文字):纯数字、符号不翻译。 */
@@ -47,16 +49,16 @@ function mapCondition(c, visit) {
47
49
  return { not: mapCondition(c.not, visit) };
48
50
  return c;
49
51
  }
50
- function mapNode(n, visit) {
51
- const out = { ...n };
52
+ function mapNode(n, visit, plugins) {
53
+ const out = { ...n, ...(n.ext ? { ext: mapSlotTexts(n.ext, plugins, 'node', s => visit(s, 'text', n.source)) } : {}) };
52
54
  if (n.props) {
53
55
  const props = {};
54
56
  for (const [k, v] of Object.entries(n.props))
55
- props[k] = STRUCTURAL.has(k) ? v : mapDeep(v, (s, _p, itemValue) => visit(s, DISPLAY_PROPS.has(k) && !itemValue ? 'text' : 'prop', n.source), '');
56
- out.props = props;
57
+ props[k] = STRUCTURAL.has(k) || !(n.type === '#text' && k === 'text' || pluginSpec(plugins, n.type)?.traits?.text?.includes(k)) ? v : mapDeep(v, (s, _p, itemValue) => visit(s, !itemValue ? 'text' : 'prop', n.source), '');
58
+ out.props = mapTextPaths(props, pluginSpec(plugins, n.type)?.traits?.textPaths ?? [], s => isBinding(s) ? s : visit(s, 'text', n.source));
57
59
  }
58
60
  if (n.children)
59
- out.children = n.children.map((c) => mapNode(c, visit));
61
+ out.children = n.children.map((c) => mapNode(c, visit, plugins));
60
62
  if (n.when)
61
63
  out.when = mapCondition(n.when, visit);
62
64
  if (n.disabled && typeof n.disabled === 'object')
@@ -72,14 +74,15 @@ function mapNode(n, visit) {
72
74
  }
73
75
  const t = (s, visit, at) => (s ? visit(s, 'text', at) : s);
74
76
  const stateMap = (v, base, visit) => mapDeep(v, (s, p) => visit(s, 'state', undefined, `${base}${p}`), '');
75
- function mapStep(st, visit) {
76
- const at = st.source;
77
- const a = st.action;
78
- const action = a.type === 'card' ? { ...a, title: visit(a.title, 'text', at), ...(a.sub ? { sub: visit(a.sub, 'text', at) } : {}), ...(a.points ? { points: a.points.map((p) => visit(p, 'text', at)) } : {}) }
77
+ function mapAction(a, visit, plugins, at) {
78
+ return a.type === 'card' ? { ...a, title: visit(a.title, 'text', at), ...(a.sub ? { sub: visit(a.sub, 'text', at) } : {}), ...(a.points ? { points: a.points.map((p) => visit(p, 'text', at)) } : {}) }
79
79
  : a.type === 'type' || a.type === 'select' ? { ...a, value: visit(a.value, 'typed', at) }
80
80
  : a.type === 'event' ? { ...a, name: visit(a.name, 'text', at) }
81
- : a;
82
- const effects = st.effects.map((e) => {
81
+ : a.type === 'plugin' ? { ...a, data: Object.fromEntries(Object.entries(a.data).map(([key, value]) => [key, typeof value === 'string' && pluginActionSpec({ plugins }, a.name)?.fields[key]?.text ? visit(value, 'typed', at) : value])) }
82
+ : a;
83
+ }
84
+ function mapEffects(effects, visit, at) {
85
+ return effects.map((e) => {
83
86
  if (e.type === 'set' || e.type === 'append')
84
87
  return { ...e, value: stateMap(e.value, e.path, visit) };
85
88
  if (e.type === 'stream')
@@ -88,8 +91,14 @@ function mapStep(st, visit) {
88
91
  return { ...e, text: visit(e.text, 'text', at) };
89
92
  return e;
90
93
  });
94
+ }
95
+ function mapStep(st, visit, plugins) {
96
+ const at = st.source;
97
+ const action = mapAction(st.action, visit, plugins, at);
98
+ const effects = mapEffects(st.effects, visit, at);
91
99
  return {
92
100
  ...st,
101
+ ...(st.ext ? { ext: mapSlotTexts(st.ext, plugins, 'step', s => visit(s, 'text', st.source)) } : {}),
93
102
  action,
94
103
  // 自动字幕是英文兜底,网页按 captionAuto 生成;只换它引用的元素名和值
95
104
  caption: st.captionAuto ? st.caption : visit(st.caption, 'text', at),
@@ -103,16 +112,17 @@ function mapStep(st, visit) {
103
112
  forks: st.forks.map((f) => ({ ...f, label: visit(f.label, 'text', at) })),
104
113
  };
105
114
  }
106
- function mapScenario(sc, visit) {
115
+ function mapScenario(sc, visit, plugins) {
107
116
  const at = sc.source;
108
117
  return {
109
118
  ...sc,
119
+ ...(sc.ext ? { ext: mapSlotTexts(sc.ext, plugins, 'step', s => visit(s, 'text', sc.source)) } : {}),
110
120
  name: visit(sc.name, 'text', at),
111
121
  description: t(sc.description, visit, at) ?? '',
112
122
  ...(sc.expected !== undefined ? { expected: t(sc.expected, visit, at) ?? '' } : {}),
113
123
  mock: sc.mock.auto ? sc.mock : { ...sc.mock, label: visit(sc.mock.label, 'text', at) },
114
124
  initial: { ...sc.initial, ui: stateMap(sc.initial.ui, 'ui', visit), data: stateMap(sc.initial.data, 'data', visit), inputs: stateMap(sc.initial.inputs, 'inputs', visit) },
115
- steps: sc.steps.map((st) => mapStep(st, visit)),
125
+ steps: sc.steps.map((st) => mapStep(st, visit, plugins)),
116
126
  };
117
127
  }
118
128
  /** 对 IR 里所有作者内容字符串调用 visit,返回替换后的新 IR(不改原对象)。 */
@@ -128,6 +138,7 @@ function mapProject(p, visit) {
128
138
  features: obj(p.features, (f) => ({ ...f, name: visit(f.name, 'text', f.source), goal: visit(f.goal, 'text', f.source), roles: arr(f.roles, (r) => ({ ...r, name: visit(r.name, 'text', f.source), ...(r.desc ? { desc: visit(r.desc, 'text', f.source) } : {}) })), constraints: arr(f.constraints, (c) => ({ ...c, text: visit(c.text, 'text', f.source) })) })),
129
139
  options: obj(p.options, (o) => ({
130
140
  ...o,
141
+ ...(o.free ? { free: obj(o.free, r => ({ ...r, action: mapAction(r.action, visit, p.plugins, r.source), effects: mapEffects(r.effects, visit, r.source) })) } : {}),
131
142
  name: visit(o.name, 'text', o.source),
132
143
  idea: visit(o.idea, 'text', o.source),
133
144
  ...(o.decisionFocus !== undefined ? { decisionFocus: t(o.decisionFocus, visit, o.source) ?? '' } : {}),
@@ -139,8 +150,8 @@ function mapProject(p, visit) {
139
150
  cases: obj(p.cases, (c) => ({ ...c, title: visit(c.title, 'text', c.source), expected: t(c.expected, visit, c.source) ?? '' })),
140
151
  rules: obj(p.rules, (r) => ({ ...r, text: visit(r.text, 'text', r.source) })),
141
152
  issues: obj(p.issues, (q) => ({ ...q, text: visit(q.text, 'text', q.source) })),
142
- scenes: obj(p.scenes, (s) => ({ ...s, root: mapNode(s.root, visit) })),
143
- scenarios: obj(p.scenarios, (s) => mapScenario(s, visit)),
153
+ scenes: obj(p.scenes, (s) => ({ ...s, root: mapNode(s.root, visit, p.plugins) })),
154
+ scenarios: obj(p.scenarios, (s) => mapScenario(s, visit, p.plugins)),
144
155
  };
145
156
  }
146
157
  /** 画面里显示出来的状态路径(文字、属性、禁用原因里的绑定)。 */
@@ -28,8 +28,8 @@ export declare const DiffStep: z.ZodObject<{
28
28
  match: z.ZodEnum<{
29
29
  action: "action";
30
30
  key: "key";
31
- none: "none";
32
31
  content: "content";
32
+ none: "none";
33
33
  uncertain: "uncertain";
34
34
  }>;
35
35
  reasons: z.ZodArray<z.ZodString>;
@@ -81,8 +81,8 @@ export declare const DiffScenario: z.ZodObject<{
81
81
  match: z.ZodEnum<{
82
82
  action: "action";
83
83
  key: "key";
84
- none: "none";
85
84
  content: "content";
85
+ none: "none";
86
86
  uncertain: "uncertain";
87
87
  }>;
88
88
  reasons: z.ZodArray<z.ZodString>;
@@ -156,8 +156,8 @@ export declare const FeatureDiffManifest: z.ZodObject<{
156
156
  match: z.ZodEnum<{
157
157
  action: "action";
158
158
  key: "key";
159
- none: "none";
160
159
  content: "content";
160
+ none: "none";
161
161
  uncertain: "uncertain";
162
162
  }>;
163
163
  reasons: z.ZodArray<z.ZodString>;
@@ -1,3 +1,5 @@
1
+ import { projectThemes } from "./themes.js";
2
+ import { jsonData } from "./plugins/data.js";
1
3
  /** Public feature comparison. Positional ids are addresses, never cross-version identities. */
2
4
  import { z } from 'zod';
3
5
  import { Project } from "./schema.js";
@@ -41,14 +43,14 @@ export function canonical(value) {
41
43
  const stepContent = ({ id: _id, key: _key, source: _source, ruleIds: _rules, ...rest }) => rest;
42
44
  const identity = (s) => {
43
45
  const a = s.action;
44
- return canonical([s.kind, a.type, 'target' in a ? a.target : 'name' in a ? a.name : 'keys' in a ? a.keys : 'title' in a ? a.title : null]);
46
+ return canonical([s.kind, a.type, ...(a.type === 'plugin' ? [a.name] : []), 'target' in a ? a.target : 'name' in a ? a.name : 'keys' in a ? a.keys : 'title' in a ? a.title : null]);
45
47
  };
46
48
  const ref = (s, index) => ({ id: s.id, position: index + 1, ...(s.key ? { key: s.key } : {}), caption: s.caption.slice(0, 300) });
47
49
  /** Presentation-only step fields, grouped into reader-facing reasons. Unlisted content changes fall back to 'presentation'. */
48
50
  const PRESENTATION = [
49
51
  ['caption', ['caption', 'captionAuto']], ['explain', ['explain']], ['camera', ['shots', 'directorLayer']],
50
52
  ['annotations', ['marks', 'cues', 'callouts']], ['voice', ['say', 'narrate']], ['timing', ['hold']],
51
- ['trace', ['traces']], ['forks', ['forks']], ['kind', ['kind']],
53
+ ['plugin-data', ['ext']], ['forks', ['forks']], ['kind', ['kind']],
52
54
  ];
53
55
  const KIND_ORDER = { state: 0, message: 1, outcome: 2 };
54
56
  const shown = (v) => (typeof v === 'string' ? v : canonical(v)).slice(0, 200);
@@ -163,7 +165,14 @@ export function compareSteps(before, after) {
163
165
  }
164
166
  /** Refuse private IR instead of projecting potentially private unknown fields into a public comparison. */
165
167
  export function readPublicProject(value) {
166
- const parsed = Project.safeParse(value);
168
+ let input;
169
+ try {
170
+ input = jsonData(value);
171
+ }
172
+ catch {
173
+ throw new JoploError('INVALID_SCHEMA', 'Invalid public playback IR; expected finite JSON');
174
+ }
175
+ const parsed = Project.safeParse(input);
167
176
  if (!parsed.success)
168
177
  throw new JoploError('INVALID_SCHEMA', 'Invalid public playback IR; rebuild both versions with a compatible CLI');
169
178
  const p = parsed.data;
@@ -194,6 +203,11 @@ function sceneInputs(p, s) {
194
203
  ids.add(e.sceneId);
195
204
  return [...ids].sort().map(id => p.scenes[id] ?? { missing: id });
196
205
  }
206
+ function actionContracts(p, s) {
207
+ const actions = [...s.steps.map(st => st.action), ...Object.values(p.options[s.optionId]?.free ?? {}).map(r => r.action)];
208
+ const names = [...new Set(actions.flatMap(a => a.type === 'plugin' ? [a.name] : []))].sort();
209
+ return names.map(name => { const [id, key] = name.split(':'); return [name, p.plugins?.[id]?.actions?.[key]]; });
210
+ }
197
211
  export function featureDiff(before, after, source = {}) {
198
212
  if ([source.baseSha, source.headSha].some(sha => sha !== undefined && !GitSha.safeParse(sha).success))
199
213
  throw new JoploError('USAGE', 'Source SHAs must be normalized 40-character hexadecimal git commits');
@@ -211,12 +225,20 @@ export function featureDiff(before, after, source = {}) {
211
225
  let status = !old ? 'added' : !next ? 'removed' : 'unchanged';
212
226
  if (old && next) {
213
227
  const bo = b.options[old.optionId], bf = b.features[bo.featureId];
214
- if (canonical(old.initial) !== canonical(next.initial))
228
+ if (canonical([old.initial, old.ext]) !== canonical([next.initial, next.ext]))
215
229
  reasons.push('initial-state');
216
230
  if (canonical(sceneInputs(b, old)) !== canonical(sceneInputs(a, next)))
217
231
  reasons.push('scenes');
218
- if (canonical([b.theme, b.themes, b.autoFocus]) !== canonical([a.theme, a.themes, a.autoFocus]))
232
+ if (canonical([b.theme, projectThemes(b), b.autoFocus]) !== canonical([a.theme, projectThemes(a), a.autoFocus]))
219
233
  reasons.push('theme');
234
+ if (canonical(bo?.free) !== canonical(option?.free))
235
+ reasons.push('free-reactions');
236
+ if ((old.actionEntry ?? 'before') !== (next.actionEntry ?? 'before'))
237
+ reasons.push('action-entry');
238
+ if ((old.autoplay !== false) !== (next.autoplay !== false))
239
+ reasons.push('autoplay');
240
+ if (canonical(actionContracts(b, old)) !== canonical(actionContracts(a, next)))
241
+ reasons.push('action-contracts');
220
242
  if (canonical([bo?.layers, bf?.roles]) !== canonical([option?.layers, feature.roles]))
221
243
  reasons.push('layers-roles');
222
244
  if (canonical([old.name, old.description, old.expected, old.mock, bf?.name, bf?.goal, bo?.name, bo?.idea]) !== canonical([next.name, next.description, next.expected, next.mock, feature.name, feature.goal, option?.name, option?.idea]))
@@ -229,7 +251,7 @@ export function featureDiff(before, after, source = {}) {
229
251
  result.summary[group].push(`${feature.name} / ${s.name}`.slice(0, 200));
230
252
  }
231
253
  // Project metadata / unused shared scenes still changed even when no scenario can display it.
232
- if (canonical([b.name, b.description, b.features, b.options, b.scenes, b.theme, b.themes, b.routes, b.featureIds, b.autoFocus]) !== canonical([a.name, a.description, a.features, a.options, a.scenes, a.theme, a.themes, a.routes, a.featureIds, a.autoFocus]))
254
+ if (canonical([b.name, b.description, b.features, b.options, b.scenes, b.theme, projectThemes(b), b.routes, b.featureIds, b.autoFocus]) !== canonical([a.name, a.description, a.features, a.options, a.scenes, a.theme, projectThemes(a), a.routes, a.featureIds, a.autoFocus]))
233
255
  result.reasons.push('project-presentation');
234
256
  result.status = result.scenarios.some(s => s.status === 'uncertain') ? 'uncertain' : result.reasons.length || result.scenarios.some(s => s.status !== 'unchanged') ? 'changed' : 'unchanged';
235
257
  return FeatureDiffManifest.parse(result);
package/dist/focus.d.ts CHANGED
@@ -4,6 +4,8 @@ export declare const HOLD_MIN_SECONDS = 0.5;
4
4
  export declare const HOLD_MAX_SECONDS = 30;
5
5
  /** 默认揭晓最多提示几处;更多时不提示。 */
6
6
  export declare const REVEAL_MAX = 3;
7
+ /** 自带遮罩、出现时本身就是焦点的浮层:默认揭晓不再画提示。 */
8
+ /** 自己会突出本步变化的组件(D56)。 */
7
9
  export type FocusSubject = 'cover' | 'card' | 'scene' | 'elements' | 'toast' | 'caption';
8
10
  export type FocusState = {
9
11
  /** 观众此刻该看的东西。 */
@@ -26,7 +28,7 @@ export type FocusState = {
26
28
  };
27
29
  type Vis = Pick<PlayState, 'ui' | 'data' | 'inputs'>;
28
30
  /**
29
- * 画面里此刻可见的元素 id(与 isNodeVisible 同一套规则:when、浮层 opened、断点、AppShell 收起),一次自上而下算完。
31
+ * 画面里此刻可见的元素 id(与 isNodeVisible 同一套规则:when、浮层 opened、断点、layout 收起),一次自上而下算完。
30
32
  */
31
33
  export declare function visibleIds(scene: Scene, state: Vis, width?: number): Set<string>;
32
34
  /** 整个场景每个位置(0..步数)的焦点;按项目对象缓存(热更新换了项目对象就重新算)。 */
package/dist/focus.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 叙事焦点(D70):每一步观众该看哪里(焦点对象),以及用什么形式呈现。纯函数,与 cameraAt / diagramStateAt 同级:
2
+ * 叙事焦点(D70):每一步观众该看哪里(焦点对象),以及用什么形式呈现。纯函数,与 cameraAt 同级:
3
3
  * 看板、发布站(含嵌入、评审)、renderStep 截图、视频录制、check 都读这一份。
4
4
  *
5
5
  * 焦点对象(subject)按优先级:
@@ -13,30 +13,20 @@
13
13
  * caption 画面上没有新东西,只看字幕(source = none)。
14
14
  *
15
15
  * 呈现:作者写的提示原样给出;默认只有“结果揭晓”(reveal):本步新出现或变化、观众容易错过的元素轻轻脉冲一次,
16
- * 不移动镜头、不压暗、不拦截点击。克制规则:弹窗 / 抽屉自带遮罩不提示;DataCard / StateFlow 自己会突出变化;
16
+ * 不移动镜头、不压暗、不拦截点击。克制规则:弹窗 / 抽屉自带遮罩不提示;自行显示变化的元素 自己会突出变化;
17
17
  * 一次变化超过 REVEAL_MAX 处不提示(整块都变了,让观众自己看);作者写了任何焦点时不加默认提示;换页、换层不提示;
18
18
  * 同一个元素连续变化、或往同一个容器里连续追加(终端、聊天记录一行行出现)时,只在第一次提示。
19
19
  * config({ autoFocus: false }) 关掉默认呈现(reveal 恒为空);焦点对象仍照常推导,check 用它判断“长时间没有焦点”。
20
20
  */
21
- import { DIRECTOR_LAYER, GATED_CONTAINERS, PAGE_LAYER, childWidth } from "./catalog.js";
22
- import { diagramsIn } from "./diagram/index.js";
23
- import { appShellLayout, applyStep, cameraAt, initialState, isNodeDisabled, isSelfVisible, layersOf, resolveProps, sceneWidth } from "./player.js";
21
+ import { DIRECTOR_LAYER, PAGE_LAYER, childWidth, pluginSpec } from "./catalog.js";
22
+ import { layoutRegions, applyStep, cameraAt, initialState, isNodeDisabled, isSelfVisible, layersOf, resolveProps, sceneWidth } from "./player.js";
24
23
  export const HOLD_MIN_SECONDS = 0.5;
25
24
  export const HOLD_MAX_SECONDS = 30;
26
25
  /** 默认揭晓最多提示几处;更多时不提示。 */
27
26
  export const REVEAL_MAX = 3;
28
- /** 自带遮罩、出现时本身就是焦点的浮层:默认揭晓不再画提示。 */
29
- const SELF_EVIDENT = GATED_CONTAINERS;
30
- /** 自己会突出本步变化的组件(D56)。 */
31
- const SELF_CHANGING = new Set(['DataCard', 'StateFlow']);
32
- /**
33
- * 关系类图表(D69)也自己呈现变化:新元素淡入、连线沿路径画出、trace / value 点亮。默认的结果揭晓不再叠一圈
34
- * (连线的外接矩形是一大块,状态机 value 变化会框住整张图),集成 0.2.8 的组合规则。
35
- */
36
- const DIAGRAM_FAMILY = /^(Diagram|StateMachine|Sequence)(\.|$)/;
37
27
  const EMPTY = (layer, subject = 'caption') => ({ subject, source: 'none', targets: [], layer, spotlight: [], highlight: [], numbered: [], callouts: [], reveal: [], holdMs: 0 });
38
28
  /**
39
- * 画面里此刻可见的元素 id(与 isNodeVisible 同一套规则:when、浮层 opened、断点、AppShell 收起),一次自上而下算完。
29
+ * 画面里此刻可见的元素 id(与 isNodeVisible 同一套规则:when、浮层 opened、断点、layout 收起),一次自上而下算完。
40
30
  */
41
31
  export function visibleIds(scene, state, width = sceneWidth(scene)) {
42
32
  const out = new Set();
@@ -44,27 +34,26 @@ export function visibleIds(scene, state, width = sceneWidth(scene)) {
44
34
  const rec = (n, w, shell) => {
45
35
  if (!isSelfVisible(n, ps, w))
46
36
  return;
47
- const sh = n.type === 'AppShell' ? { node: n, width: w } : shell;
48
- if (sh && (n.type === 'AppShell.Navbar' || n.type === 'AppShell.Aside')) {
49
- const l = appShellLayout(sh.node.props, state, sh.width);
50
- if ((n.type === 'AppShell.Navbar' ? l.navbar : l.aside)?.collapsed)
37
+ const sh = n.traits?.layout ? { node: n, width: w } : shell;
38
+ if (sh && n.traits?.region) {
39
+ if (layoutRegions(sh.node, state, sh.width)[n.traits.region]?.collapsed)
51
40
  return;
52
41
  }
53
42
  out.add(n.id);
54
- const cw = childWidth(n.type, w, n.props);
43
+ const cw = childWidth(n, w, resolveProps(n, state));
55
44
  for (const c of n.children ?? [])
56
45
  rec(c, cw, sh);
57
46
  };
58
47
  rec(scene.root, width, null);
59
48
  return out;
60
49
  }
61
- function changedElements(scene, before, after) {
50
+ function changedElements(scene, before, after, plugins) {
62
51
  const vb = visibleIds(scene, before);
63
52
  const va = visibleIds(scene, after);
64
53
  const hits = [];
65
54
  const parents = new Map();
66
55
  const add = (n, appended) => { if (n && !hits.some((h) => h.id === n.id))
67
- hits.push({ id: n.id, type: n.type, parent: parents.get(n.id) ?? null, appended: appended && n.type !== '#text' }); };
56
+ hits.push({ id: n.id, type: n.type, selfEvident: n.traits?.selfEvident || pluginSpec(plugins, n.type)?.selfEvident, parent: parents.get(n.id) ?? null, appended: appended && n.type !== '#text' }); };
68
57
  const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
69
58
  const rec = (n, parent) => {
70
59
  parents.set(n.id, parent?.id ?? null);
@@ -109,9 +98,7 @@ function explicitTargets(step, layer) {
109
98
  s.targets.forEach(add);
110
99
  }
111
100
  // trace 的焦点对象与镜头目标相同(D69 的 Trace.targets:时序图是消息那一行;旧 IR 没有时按 nodes)
112
- for (const t of step.traces ?? [])
113
- if (t.mode !== 'skip')
114
- (t.targets ?? t.nodes).forEach(add);
101
+ (step.focusTargets ?? []).forEach(add);
115
102
  for (const c of step.cues ?? [])
116
103
  c.targets.forEach(add);
117
104
  for (const c of step.callouts ?? [])
@@ -209,7 +196,7 @@ export function focusTimeline(project, scenarioId) {
209
196
  }
210
197
  // 本步新出现或变化的元素;用户自己操作的元素(及其内部)不算,鼠标已经在那里
211
198
  const target = actionTarget && scene ? findIn(scene.root, actionTarget) : null;
212
- const hits = scene ? changedElements(scene, before, after).filter((h) => !(target && findIn(target, h.id))) : [];
199
+ const hits = scene ? changedElements(scene, before, after, project.plugins).filter((h) => !(target && findIn(target, h.id))) : [];
213
200
  for (const h of hits) {
214
201
  prevChanged.add(h.id);
215
202
  if (h.appended && h.parent)
@@ -223,7 +210,7 @@ export function focusTimeline(project, scenarioId) {
223
210
  // 连续性:同一个元素上一步刚变过;或者往上一步刚追加过的同一个容器里再追加(终端、聊天记录一行行出现)。
224
211
  // 观众已经在看那里,不再重复提示
225
212
  const repeated = (h) => lastChanged.has(h.id) || (h.appended && !!h.parent && lastChanged.has(`^${h.parent}`));
226
- const shown = hits.filter((h) => !SELF_EVIDENT.has(h.type) && !SELF_CHANGING.has(h.type) && !DIAGRAM_FAMILY.test(h.type) && !repeated(h));
213
+ const shown = hits.filter((h) => !h.selfEvident && !repeated(h));
227
214
  if (auto && shown.length <= REVEAL_MAX)
228
215
  f.reveal = shown.map((h) => h.id);
229
216
  }
@@ -246,14 +233,9 @@ export function inShotFrame(root, id, frameTargets) {
246
233
  if (n && findIn(n, id))
247
234
  return true;
248
235
  }
249
- const diagrams = diagramsIn(root);
250
236
  for (const f of frameTargets)
251
- for (const d of diagrams) {
252
- if (d.groupsOf.get(f)?.[0] === id)
253
- return true;
254
- if (d.type === 'Sequence' && d.edges.some((e) => e.id === f && (e.from === id || e.to === id)))
255
- return true;
256
- }
237
+ if (findIn(root, f)?.framing?.include?.includes(id))
238
+ return true;
257
239
  return false;
258
240
  }
259
241
  /**
package/dist/guide.d.ts CHANGED
@@ -1,15 +1,13 @@
1
1
  import { SKILL_TOPICS } from './agent-skill.js';
2
+ import type { PluginDef } from '@joplo-app/kit/plugin';
2
3
  export { SKILL_TOPICS };
3
4
  export type SkillTopic = (typeof SKILL_TOPICS)[number]['name'];
4
- /** CLI 传入其 package.json 版本;行数来自同一次生成的主题正文。 */
5
- export declare function skillIndex(version: string, docs?: Readonly<Record<string, string>> | null): string;
6
- export declare function nearestSkillTopic(input: string): SkillTopic;
7
- /** docs 是组件目录提供的可选一行提示,不在这里维护另一份组件或属性清单。 */
8
- export declare function skillTopic(topic: string, docs?: Readonly<Record<string, string>> | null): string;
9
- /** 兼容旧入口:与 joplo skill authoring 输出完全相同。 */
10
- export declare function guide(): string;
11
- /**
12
- * `npx joplo components <名字…>`(D68):所列组件(含它的子组件,例如 Menu → Menu.Item)的属性提示、行为分组和示例。
13
- * 名字不区分大小写;不认识的名字报 USAGE 并给出最接近的名字。
14
- */
15
- export declare function componentDetails(names: readonly string[]): string;
5
+ export type PluginSkillSource = Pick<PluginDef, 'id' | 'title' | 'version' | 'description' | 'components' | 'skill' | 'skillTopics' | 'packageName'>;
6
+ export declare function skillIndex(version: string): string;
7
+ export declare function nearestSkillTopic(input: string): string;
8
+ export declare function skillTopic(topic: string): string;
9
+ export declare function pluginSkillIndex(plugins: readonly PluginSkillSource[]): string;
10
+ export declare function findPluginTopic(topic: string, plugins: readonly PluginSkillSource[]): PluginSkillSource | null;
11
+ export declare function pluginSkillTopic(p: PluginSkillSource, topic?: string): string;
12
+ export declare function componentIndex(plugins: readonly PluginSkillSource[]): string;
13
+ export declare function componentDetails(names: readonly string[], plugins: readonly PluginSkillSource[]): string;