@joplo-app/kit 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/index.d.ts CHANGED
@@ -5,7 +5,8 @@
5
5
  * layouts/<id>.tsx layout(<div>…<Outlet/>…</div>)
6
6
  * routes/<path>/page.tsx page({ title }, <…/>) 文件夹路径 = 页面路径
7
7
  * features/<f>/feature.ts feature({ name, goal, cases, rules, pick })
8
- * features/<f>/options/<o>.tsx option({ name, idea, on, routes, state, scenarios })
8
+ * features/<f>/works/<w>.tsx work({ title, summary, on, routes, state, scenarios })
9
+ * works/<key>.tsx work({ title, summary, stage, scenarios })
9
10
  *
10
11
  * 所有函数只返回数据;画板不会执行这些代码,只消费编译出的 IR。
11
12
  */
@@ -149,7 +150,7 @@ export type FeatureDef = {
149
150
  cases: Record<string, CaseDef>;
150
151
  rules?: Record<string, RuleDef>;
151
152
  questions?: Record<string, QuestionDef>;
152
- /** 选定的方案(options/ 下的文件名);build 只发布它。 */
153
+ /** 选定的方案(works/ 下的文件名);build 只发布它。 */
153
154
  pick?: string | null;
154
155
  source?: string;
155
156
  };
@@ -204,6 +205,7 @@ export type EffectDef = {
204
205
  type: 'stream';
205
206
  path: string;
206
207
  value: string;
208
+ pace?: 'voice';
207
209
  } | {
208
210
  kind: 'effect';
209
211
  type: 'fork';
@@ -234,6 +236,7 @@ export type EffectDef = {
234
236
  kind: 'effect';
235
237
  type: 'say';
236
238
  text: string;
239
+ role?: string;
237
240
  } | {
238
241
  kind: 'effect';
239
242
  type: 'narrate';
@@ -255,8 +258,13 @@ export declare const toast: ((text: string) => EffectDef) & {
255
258
  * 流式输出(D56):和 set 一样把文字写进状态,播放到这一步时绑定它的文字逐字出现(像模型在输出)。
256
259
  * 跳到这一步、截图、发布站静态查看时直接显示全文。自动播放会等输出完再进下一步。
257
260
  * .system('助手回复', stream($.ui.reply, '周六晴,推荐去白河营地……'))
261
+ * 接着往后写(D100):新值以原来的值开头时,原有的字直接显示,只有新加的字逐字出现(语音转写、日志追加)。
262
+ * opts.pace: 'voice':新加的字跟着这一步的朗读(narrate / say)出,读到哪写到哪;默认按模型输出的速度。
263
+ * .system('说', '“日程安排。”', stream($.ui.spoken, '附上新的日程安排。', { pace: 'voice' }), say('日程安排。', { role: 'me' }))
258
264
  */
259
- export declare const stream: (target: Bind, text: string) => EffectDef;
265
+ export declare const stream: (target: Bind, text: string, opts?: {
266
+ pace?: "voice";
267
+ }) => EffectDef;
260
268
  /** 本步的另一条故事路线;目标是同一方案的场景键,自动播放仍走主线。 */
261
269
  export declare const fork: (label: string, scenario: string) => EffectDef;
262
270
  /** 本步手绘标注(下一步消失);目标隐藏或不在当前层时不画。 */
@@ -268,7 +276,7 @@ export declare const mark: (target: string, opts?: {
268
276
  export declare const go: (route: string) => EffectDef;
269
277
  /** 场景结束。 */
270
278
  export declare const done: (text: string, outcome?: "success" | "failure" | "cancelled") => EffectDef;
271
- /** 这一步依据哪些规则(option 或 feature 中的规则键)。 */
279
+ /** 这一步依据哪些规则(work 或 feature 中的规则键)。 */
272
280
  export declare const uses: (...rules: string[]) => EffectDef;
273
281
  /**
274
282
  * 镜头(D43):这一步要看哪些元素。每个 id 在包含它的层级里解析(多层都有同名 id 时各层都生效),只影响那些层级的镜头;
@@ -300,8 +308,12 @@ export declare const narrate: (text: string) => EffectDef;
300
308
  * 角色台词(D74):这一步里角色亲口说的话,用这个角色的声音读(feature.roles 与层级的 role;没有角色时用旁白的声音)。
301
309
  * 写第一人称、像真人说话:.click('can_go', '阿杰回复:我能去', say('我能去!'))。
302
310
  * 同一步写了 narrate() 时只读旁白。讲解、过渡、总结请用 narrate()。
311
+ * opts.role(D100):写明是谁在说(feature.roles 的键)。系统步骤没有“操作的人”,要角色的声音时必须写;
312
+ * 操作步骤写了也以它为准:.system('说', '“帮我写一封”', say('帮我写一封', { role: 'me' }))。
303
313
  */
304
- export declare const say: (text: string) => EffectDef;
314
+ export declare const say: (text: string, opts?: {
315
+ role?: string;
316
+ }) => EffectDef;
305
317
  /**
306
318
  * 聚光:这一步只照亮这些元素,画面其余部分压暗(不遮挡、不拦截点击,下一步要点的元素也保持明亮)。
307
319
  * 用于“这一屏信息很多,此刻只看这一块”。
@@ -436,7 +448,7 @@ export type FlowOpts = {
436
448
  outcome?: 'success' | 'failure' | 'denied' | 'other';
437
449
  /** 起始路径;缺省为方案 on/routes 中的第一个路径。 */
438
450
  start?: string;
439
- /** 在 option.state 之上覆盖的初始状态。 */
451
+ /** 在 work.state 之上覆盖的初始状态。 */
440
452
  state?: StateInit;
441
453
  /**
442
454
  * 接着另一个场景演(同一方案的场景键):初始状态 = 那个场景最后一步之后的状态(路径、ui / data / inputs、导演层),
@@ -450,13 +462,13 @@ export type FlowOpts = {
450
462
  description?: string;
451
463
  expected?: string;
452
464
  };
453
- export declare class Flow {
465
+ export declare class Flow<Kind extends 'flow' | 'chapter' = 'flow'> {
454
466
  readonly name: string;
455
467
  readonly opts: FlowOpts;
456
- readonly kind = "flow";
468
+ readonly kind: Kind;
457
469
  readonly steps: StepDef[];
458
470
  readonly source: string | undefined;
459
- constructor(name: string, opts: FlowOpts);
471
+ constructor(name: string, opts: FlowOpts, kind?: Kind);
460
472
  private add;
461
473
  /** Give the preceding step a stable key. Keep it when editing or moving the same action. */
462
474
  key(key: string): this;
@@ -507,27 +519,49 @@ export declare const free: {
507
519
  }, ...args: StepArg[]) => StepDef;
508
520
  act: (name: string, target: string, data: Record<string, unknown>, ...args: StepArg[]) => StepDef;
509
521
  };
510
- export type OptionDef = {
511
- kind: 'option';
512
- name: string;
513
- idea: string;
514
- /** 这个方案主要改变了哪项设计决策。 */
515
- focus?: string;
516
- tradeoffs?: string[];
517
- /** 堆叠到已有路径:{ '/members': { 'header.actions': <Button/>, overlay: <Dialog/> } } */
522
+ export type { CondExpr as Condition };
523
+ export type { JoploProps } from './props.js';
524
+ export type ChapterOpts = Omit<FlowOpts, 'from'> & {
525
+ /** 缺省接声明顺序里的上一章;null 从初始状态重新开始。只在编译时解析。 */
526
+ from?: string | null;
527
+ };
528
+ export declare class Chapter extends Flow<'chapter'> {
529
+ readonly chapterOptions: ChapterOpts;
530
+ readonly source: string | undefined;
531
+ constructor(title: string, chapterOptions?: ChapterOpts);
532
+ }
533
+ /** 任意作品中的一章:步骤、效果和插件能力与 flow() 相同。 */
534
+ export declare const chapter: (title: string, opts?: ChapterOpts) => Chapter;
535
+ export type WorkDef = {
536
+ /** 两处都可用:作品内容、画面、状态与切片。 */
537
+ kind: 'work';
538
+ title: string;
539
+ summary: string;
540
+ /** stage 与 layers 二选一。 */
541
+ stage?: JNode;
542
+ layers?: Record<string, LayerDef>;
543
+ /** 复用项目页面的插槽与新增页面;两种位置共用同一编译路径。 */
518
544
  on?: Record<string, Record<string, JNode | JNode[]>>;
519
- /** 本方案新增的路径。 */
520
545
  routes?: Record<string, PageDef>;
546
+ /** 只对 stage 生效。 */
547
+ viewport?: 'desktop' | 'mobile';
521
548
  state?: StateInit;
549
+ free?: Record<string, StepDef>;
550
+ scenarios: Record<string, Flow | Chapter>;
551
+ source?: string;
552
+ /** 只在功能下面:设计评审信息与规则。 */
553
+ focus?: string;
554
+ tradeoffs?: string[];
522
555
  rules?: Record<string, RuleDef>;
523
556
  questions?: Record<string, QuestionDef>;
524
557
  coverage?: Record<string, CoverageDecl>;
525
- /** 层级(视角):每层一个独立画面 { client: layer('客户端视角', <ClientView />), backend: layer('后端流转', <Arch />) }。 */
526
- layers?: Record<string, LayerDef>;
527
- free?: Record<string, StepDef>;
528
- scenarios: Record<string, Flow>;
529
- source?: string;
558
+ /** 只在独立作品:受众、角色、草稿与首页排序。 */
559
+ /** 给观众看的受众说明,参与作者内容翻译。空字符串等于未写。 */
560
+ audience?: string;
561
+ roles?: Record<string, RoleDef>;
562
+ /** 草稿只进入 dev IR。 */
563
+ draft?: boolean;
564
+ order?: number;
530
565
  };
531
- export declare const option: (o: Omit<OptionDef, "kind" | "source">) => OptionDef;
532
- export type { CondExpr as Condition };
533
- export type { JoploProps } from './props.js';
566
+ /** 一件作品;键来自所在 works/<key>.tsx 的文件名。结构错误由编译器带源位置报告。 */
567
+ export declare const work: (f: Omit<WorkDef, "kind" | "source">) => WorkDef;
package/dist/index.js CHANGED
@@ -5,7 +5,8 @@
5
5
  * layouts/<id>.tsx layout(<div>…<Outlet/>…</div>)
6
6
  * routes/<path>/page.tsx page({ title }, <…/>) 文件夹路径 = 页面路径
7
7
  * features/<f>/feature.ts feature({ name, goal, cases, rules, pick })
8
- * features/<f>/options/<o>.tsx option({ name, idea, on, routes, state, scenarios })
8
+ * features/<f>/works/<w>.tsx work({ title, summary, on, routes, state, scenarios })
9
+ * works/<key>.tsx work({ title, summary, stage, scenarios })
9
10
  *
10
11
  * 所有函数只返回数据;画板不会执行这些代码,只消费编译出的 IR。
11
12
  */
@@ -59,8 +60,11 @@ export const toast = Object.assign((text) => ({ kind: 'effect', type: 'toast', t
59
60
  * 流式输出(D56):和 set 一样把文字写进状态,播放到这一步时绑定它的文字逐字出现(像模型在输出)。
60
61
  * 跳到这一步、截图、发布站静态查看时直接显示全文。自动播放会等输出完再进下一步。
61
62
  * .system('助手回复', stream($.ui.reply, '周六晴,推荐去白河营地……'))
63
+ * 接着往后写(D100):新值以原来的值开头时,原有的字直接显示,只有新加的字逐字出现(语音转写、日志追加)。
64
+ * opts.pace: 'voice':新加的字跟着这一步的朗读(narrate / say)出,读到哪写到哪;默认按模型输出的速度。
65
+ * .system('说', '“日程安排。”', stream($.ui.spoken, '附上新的日程安排。', { pace: 'voice' }), say('日程安排。', { role: 'me' }))
62
66
  */
63
- export const stream = (target, text) => ({ kind: 'effect', type: 'stream', path: pathOf(target), value: text });
67
+ export const stream = (target, text, opts = {}) => ({ kind: 'effect', type: 'stream', path: pathOf(target), value: text, ...(opts.pace !== undefined ? { pace: opts.pace } : {}) });
64
68
  /** 本步的另一条故事路线;目标是同一方案的场景键,自动播放仍走主线。 */
65
69
  export const fork = (label, scenario) => ({ kind: 'effect', type: 'fork', label, scenario });
66
70
  /** 本步手绘标注(下一步消失);目标隐藏或不在当前层时不画。 */
@@ -69,7 +73,7 @@ export const mark = (target, opts = {}) => ({ kind: 'effect', type: 'mark', targ
69
73
  export const go = (route) => ({ kind: 'effect', type: 'go', route });
70
74
  /** 场景结束。 */
71
75
  export const done = (text, outcome = 'success') => ({ kind: 'effect', type: 'complete', text, outcome });
72
- /** 这一步依据哪些规则(option 或 feature 中的规则键)。 */
76
+ /** 这一步依据哪些规则(work 或 feature 中的规则键)。 */
73
77
  export const uses = (...rules) => ({ kind: 'effect', type: 'uses', rules });
74
78
  /**
75
79
  * 镜头(D43):这一步要看哪些元素。每个 id 在包含它的层级里解析(多层都有同名 id 时各层都生效),只影响那些层级的镜头;
@@ -101,8 +105,10 @@ export const narrate = (text) => ({ kind: 'effect', type: 'narrate', text });
101
105
  * 角色台词(D74):这一步里角色亲口说的话,用这个角色的声音读(feature.roles 与层级的 role;没有角色时用旁白的声音)。
102
106
  * 写第一人称、像真人说话:.click('can_go', '阿杰回复:我能去', say('我能去!'))。
103
107
  * 同一步写了 narrate() 时只读旁白。讲解、过渡、总结请用 narrate()。
108
+ * opts.role(D100):写明是谁在说(feature.roles 的键)。系统步骤没有“操作的人”,要角色的声音时必须写;
109
+ * 操作步骤写了也以它为准:.system('说', '“帮我写一封”', say('帮我写一封', { role: 'me' }))。
104
110
  */
105
- export const say = (text) => ({ kind: 'effect', type: 'say', text });
111
+ export const say = (text, opts = {}) => ({ kind: 'effect', type: 'say', text, ...(opts.role !== undefined ? { role: opts.role } : {}) });
106
112
  // ---------- 焦点与呈现形式(D70):这一步观众看哪里、用什么形式看 ----------
107
113
  // 镜头(shot)负责“取景”:推近、跟随。下面这些只负责“强调”:都不推近镜头;目标不在当前镜头里时,镜头先退回整层。
108
114
  // 都只作用于这一步(下一步消失),跳到任意一步、前后翻、回放结果一致。
@@ -140,12 +146,13 @@ const flattenArgs = (args) => args.flat(Infinity);
140
146
  export class Flow {
141
147
  name;
142
148
  opts;
143
- kind = 'flow';
149
+ kind;
144
150
  steps = [];
145
151
  source;
146
- constructor(name, opts) {
152
+ constructor(name, opts, kind = 'flow') {
147
153
  this.name = name;
148
154
  this.opts = opts;
155
+ this.kind = kind;
149
156
  this.source = callsite(4);
150
157
  }
151
158
  add(kind, action, args) {
@@ -232,4 +239,17 @@ export const free = {
232
239
  scroll: (target, to, ...args) => reaction(f => f.scroll(target, to, ...args)),
233
240
  act: (name, target, data, ...args) => reaction(f => f.act(name, target, data, ...args)),
234
241
  };
235
- export const option = (o) => ({ kind: 'option', ...o, source: callsite() });
242
+ export class Chapter extends Flow {
243
+ chapterOptions;
244
+ source;
245
+ constructor(title, chapterOptions = {}) {
246
+ const { from, ...opts } = chapterOptions;
247
+ super(title, { ...opts, ...(typeof from === 'string' ? { from } : {}) }, 'chapter');
248
+ this.chapterOptions = chapterOptions;
249
+ this.source = callsite(4);
250
+ }
251
+ }
252
+ /** 任意作品中的一章:步骤、效果和插件能力与 flow() 相同。 */
253
+ export const chapter = (title, opts = {}) => new Chapter(title, opts);
254
+ /** 一件作品;键来自所在 works/<key>.tsx 的文件名。结构错误由编译器带源位置报告。 */
255
+ export const work = (f) => ({ kind: 'work', ...f, source: callsite() });
package/dist/node.d.ts CHANGED
@@ -63,6 +63,6 @@ export declare const or: (...xs: Operand[]) => CondExpr;
63
63
  export declare const isCond: (v: unknown) => v is CondExpr;
64
64
  /** 把 Bind 或条件表达式转成 IR 条件。 */
65
65
  export declare const toCondition: (x: unknown) => unknown;
66
- /** 取调用者位置,用于给 feature/option/flow 步骤记录源位置。 */
66
+ /** 取调用者位置,用于给 feature/work/flow 步骤记录源位置。 */
67
67
  export declare function callsite(depth?: number): string | undefined;
68
68
  export {};
package/dist/node.js CHANGED
@@ -91,7 +91,7 @@ export const or = (...xs) => cond({ or: xs.map(asCond) });
91
91
  export const isCond = (v) => typeof v === 'object' && v !== null && '$cond' in v;
92
92
  /** 把 Bind 或条件表达式转成 IR 条件。 */
93
93
  export const toCondition = (x) => (isBind(x) ? { truthy: bindPath(x) } : isCond(x) ? x.$cond : x);
94
- /** 取调用者位置,用于给 feature/option/flow 步骤记录源位置。 */
94
+ /** 取调用者位置,用于给 feature/work/flow 步骤记录源位置。 */
95
95
  export function callsite(depth = 3) {
96
96
  const line = new Error().stack?.split('\n')[depth];
97
97
  const m = line && /\(?((?:file:\/\/)?[^()\s]+?):(\d+):(\d+)\)?\s*$/.exec(line);
package/dist/plugin.d.ts CHANGED
@@ -20,16 +20,38 @@ import type { JoploProps } from './props.js';
20
20
  export type { JoploProps } from './props.js';
21
21
  /** 插件接口版本:v2 宿主同时兼容 v1 的 mount 运行时。 */
22
22
  export declare const PLUGIN_API_VERSION: 2;
23
- /** Serializable element behavior. The compiler copies it to nodes; playback reads only IR. */
24
- export type ElementTraits = {
25
- /** Native local value behavior; never writes timeline state. */
23
+ /**
24
+ * 元素特性——稳定层:任何插件都可以声明。编译器把它抄到节点上,播放只读 IR。
25
+ * 改动这里的字段要升插件接口版本(PLUGIN_API_VERSION)。
26
+ */
27
+ export type PublicTraits = {
28
+ /** 显示用的属性:参与翻译、自动字幕与元素的显示名。 */
29
+ text?: string[];
30
+ /** 嵌套在属性里的显示文字的路径;* 表示数组的每一项或对象的每个值。 */
31
+ textPaths?: string[][];
32
+ /** 自己表现状态变化,不叠加自动 reveal。 */
33
+ selfEvident?: boolean;
34
+ /** 观众可以拖动(自由体验里跟随指针;脚本的 drag 步骤照常演示)。 */
35
+ draggable?: boolean;
36
+ /** 悬停是一种有意义的操作(hover 步骤、自由体验里的悬停反应)。 */
37
+ hover?: boolean;
38
+ /** 组件原生的本机取值行为(输入、开关、选择):只改观众本机的游玩层,不写时间线状态。 */
26
39
  native?: {
27
40
  action: 'type' | 'toggle' | 'select';
28
41
  prop: string;
29
42
  deselect?: boolean;
30
43
  };
31
- draggable?: boolean;
32
- hover?: boolean;
44
+ /** 接受 type / toggle / select 步骤的输入类元素:single = 一个值,multiple = 多选。 */
45
+ input?: 'single' | 'multiple';
46
+ /** 自带外框的容器(窗口、设备、编辑器):镜头对准里面的元素时,取景以这个外框为界。 */
47
+ frame?: boolean;
48
+ };
49
+ /**
50
+ * 元素特性——标准库内部层:把标准 UI 组件原来写在引擎里的行为(选项推导、面板门控、分栏折叠、子视口宽度、
51
+ * 禁用外观、输入类别)改成清单数据后的形状。只有仓库内与引擎同版本发布的标准库(ui / diagram / content)使用,
52
+ * 字段会跟着标准库的需要变,不保证兼容;第三方与二方插件不要依赖。
53
+ */
54
+ export type StandardLibraryTraits = {
33
55
  /** Visibility of a panel selected by an ancestor value control. */
34
56
  selectionGate?: {
35
57
  owner: string;
@@ -37,8 +59,6 @@ export type ElementTraits = {
37
59
  value: string;
38
60
  fallbackFirst?: boolean;
39
61
  };
40
- input?: 'single' | 'multiple';
41
- frame?: boolean;
42
62
  disabledPresentation?: boolean;
43
63
  /** First defined property controls visibility of this node and its descendants. */
44
64
  gate?: string[];
@@ -53,7 +73,6 @@ export type ElementTraits = {
53
73
  range: string;
54
74
  };
55
75
  toggleCaption?: 'check';
56
- selfEvident?: boolean;
57
76
  /** Region names are arbitrary plugin-owned properties on the layout node. */
58
77
  layout?: Record<string, {
59
78
  size: string;
@@ -69,13 +88,29 @@ export type ElementTraits = {
69
88
  width: number;
70
89
  };
71
90
  };
72
- /** Display properties; nested item values retain their identity semantics. */
73
- text?: string[];
74
- /** Exact nested display strings; * selects array items or object values. */
75
- textPaths?: string[][];
91
+ };
92
+ /** 编译器与 IR 里的元素特性 = 稳定层 + 标准库内部层。 */
93
+ export type ElementTraits = PublicTraits & StandardLibraryTraits;
94
+ /** 给人看的文字:英文,或「语言 → 文字」(必须有 en;看板按界面语言取,没有时退回 en)。 */
95
+ export type PluginText = string | Record<string, string>;
96
+ /**
97
+ * 看板检查抽屉里这个组件的一行专属信息:把几个属性的当前值连起来显示。
98
+ * values:属性值 → 显示文字(例如状态名);flags:某个布尔属性为 true 时追加的文字;fallback:属性没写时当作哪个值。
99
+ */
100
+ export type PluginInspectField = {
101
+ label: PluginText;
102
+ props: string[];
103
+ join?: string;
104
+ values?: Record<string, PluginText>;
105
+ flags?: Record<string, PluginText>;
106
+ fallback?: string;
76
107
  };
77
108
  /** 插件组件的声明:编译、检查、技能都只读这里,不执行运行时代码。 */
78
109
  export type PluginComponentSpec = {
110
+ /** 看板里给人看的组件名(检查抽屉)。只进 dev IR,发布与评审版不带。 */
111
+ label?: PluginText;
112
+ /** 检查抽屉里的专属信息行。只进 dev IR。 */
113
+ inspect?: PluginInspectField[];
79
114
  /** 一行用法(`npx joplo skill <插件>` 列出),例如 'focus, height; root of a 3D scene'。 */
80
115
  doc: string;
81
116
  example?: string;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * 渲染服务——第一方内部层:只给仓库内的标准库(ui / diagram / content)用,和引擎同版本发布,不保证兼容。
3
+ * 这些是把标准组件原来写在引擎里的能力(手绘描边、响应式取值、选项与分栏推导、主题外观)交还给插件用的通道,
4
+ * 形状跟着标准库的需要变。第三方与二方插件只用 `@joplo-app/kit/renderer`(稳定层)。
5
+ */
6
+ import type { ReactNode } from 'react';
7
+ import { type RendererContext, type RendererServices } from './renderer.js';
8
+ export declare const useR: RendererServices['useR'];
9
+ export declare const useStroke: () => "rough" | "clean";
10
+ export declare const useLook: () => {
11
+ theme: string;
12
+ font: string | null;
13
+ style: Record<string, string> | undefined;
14
+ };
15
+ export declare const Rough: (p: any) => ReactNode;
16
+ export declare const RoughPath: (p: any) => ReactNode;
17
+ export declare const roundRectPath: RendererServices['roundRectPath'];
18
+ export declare const RendererContextProvider: (props: {
19
+ value: Pick<RendererContext, "width" | "dialogLayer">;
20
+ children?: ReactNode;
21
+ }) => ReactNode;
22
+ export declare const atWidth: RendererServices['atWidth'];
23
+ export declare const childWidth: RendererServices['childWidth'];
24
+ export declare const choicesOf: RendererServices['choicesOf'];
25
+ export declare const layoutRegions: RendererServices['layoutRegions'];
26
+ export declare const resolveValue: RendererServices['resolveValue'];
27
+ export declare const styleOf: RendererServices['styleOf'];
@@ -0,0 +1,14 @@
1
+ import { rendererHost as host } from "./renderer.js";
2
+ export const useR = (...args) => host().useR(...args);
3
+ export const useStroke = () => host().useStroke();
4
+ export const useLook = () => host().useLook();
5
+ export const Rough = (p) => host().Rough(p);
6
+ export const RoughPath = (p) => host().RoughPath(p);
7
+ export const roundRectPath = (...args) => host().roundRectPath(...args);
8
+ export const RendererContextProvider = (props) => host().RendererContextProvider(props);
9
+ export const atWidth = (...args) => host().atWidth(...args);
10
+ export const childWidth = (...args) => host().childWidth(...args);
11
+ export const choicesOf = (...args) => host().choicesOf(...args);
12
+ export const layoutRegions = (...args) => host().layoutRegions(...args);
13
+ export const resolveValue = (...args) => host().resolveValue(...args);
14
+ export const styleOf = (...args) => host().styleOf(...args);
@@ -1,4 +1,12 @@
1
- /** Browser renderer services supplied by the host, shared by React content packages. */
1
+ /**
2
+ * 渲染服务(浏览器端,由宿主注入)——稳定层。
3
+ *
4
+ * 任何插件的运行时都可以依赖这里的导出:读渲染上下文与引擎时钟、给根元素加上引擎要的属性、渲染子节点、
5
+ * 取属性的当前值、量元素位置。改动这里的签名要升插件接口版本(PLUGIN_API_VERSION)。
6
+ *
7
+ * 只给仓库内标准库(ui / diagram / content)用的服务(手绘描边、响应式取值、选项与分栏推导、外观)在
8
+ * `@joplo-app/kit/renderer-internal`,不保证兼容,第三方与二方插件不要依赖。
9
+ */
2
10
  import type { CSSProperties, ReactNode, ComponentType } from 'react';
3
11
  import type { ActionDispatch, EngineFrame, ActionPresentation, PluginIRNode, PluginState } from './plugin.js';
4
12
  export type NodeProps = {
@@ -64,6 +72,8 @@ export type RendererServices = {
64
72
  styleOf(props: Record<string, unknown>, width: number): CSSProperties;
65
73
  nodeLabel(node: PluginIRNode): string;
66
74
  useCtx(): RendererContext;
75
+ /** Subscribe to every engine clock frame (D99). Only per-frame presenters need it; useCtx().clock changes only on run / pause / speed, with live time fields. */
76
+ useEngineFrame(enabled?: boolean): EngineFrame | undefined;
67
77
  useI18n(): {
68
78
  t: {
69
79
  stage: Record<string, unknown>;
@@ -98,41 +108,31 @@ export type RendererServices = {
98
108
  walkNodes(n: PluginIRNode, visit: (node: PluginIRNode) => void): void;
99
109
  };
100
110
  export declare function registerRendererServices(services: RendererServices): void;
111
+ /** 宿主注入的全部服务。插件不要直接用它:稳定层从本模块导入,内部层从 renderer-internal 导入。 */
112
+ export declare const rendererHost: () => RendererServices;
101
113
  export declare const useCtx: () => RendererContext;
114
+ export declare const useEngineFrame: (enabled?: boolean) => Readonly<{
115
+ timeMs: number;
116
+ elapsedMs: number;
117
+ rawMs: number;
118
+ running: boolean;
119
+ speed: number;
120
+ paused?: boolean;
121
+ }> | undefined;
102
122
  export declare const useI18n: <Messages extends Record<string, unknown>>() => {
103
123
  t: {
104
124
  stage: Messages;
105
125
  };
106
126
  };
107
- export declare const useR: RendererServices['useR'];
108
127
  export declare const useRoot: RendererServices['useRoot'];
109
128
  export declare const useRootAttrs: RendererServices['useRootAttrs'];
110
- export declare const useStroke: () => "rough" | "clean";
111
129
  export declare const RenderNode: (p: {
112
130
  node: PluginIRNode;
113
131
  }) => ReactNode;
114
- export declare const Rough: (p: any) => ReactNode;
115
- export declare const RoughPath: (p: any) => ReactNode;
116
- export declare const roundRectPath: RendererServices['roundRectPath'];
117
132
  export declare const rectOf: RendererServices['rectOf'];
118
133
  export declare const resolveProps: RendererServices['resolveProps'];
119
134
  export declare const isSelfVisible: RendererServices['isSelfVisible'];
120
135
  export declare const walkNodes: RendererServices['walkNodes'];
121
- export declare const RendererContextProvider: (props: {
122
- value: Pick<RendererContext, "width" | "dialogLayer">;
123
- children?: ReactNode;
124
- }) => ReactNode;
125
- export declare const useLook: () => {
126
- theme: string;
127
- font: string | null;
128
- style: Record<string, string> | undefined;
129
- };
130
- export declare const atWidth: RendererServices['atWidth'];
131
- export declare const childWidth: RendererServices['childWidth'];
132
- export declare const choicesOf: RendererServices['choicesOf'];
133
- export declare const layoutRegions: RendererServices['layoutRegions'];
134
- export declare const resolveValue: RendererServices['resolveValue'];
135
- export declare const styleOf: RendererServices['styleOf'];
136
136
  export declare const nodeLabel: RendererServices['nodeLabel'];
137
137
  /** Clocked drawing primitives provided by the host; no plugin animation timers. */
138
138
  export declare const motion: Record<keyof import("react").JSX.IntrinsicElements, ComponentType<any>>;
package/dist/renderer.js CHANGED
@@ -1,31 +1,21 @@
1
1
  const KEY = Symbol.for('joplo.renderer.services.v2');
2
2
  const global = globalThis;
3
3
  export function registerRendererServices(services) { global[KEY] = Object.freeze(services); }
4
- const host = () => { if (!global[KEY])
4
+ /** 宿主注入的全部服务。插件不要直接用它:稳定层从本模块导入,内部层从 renderer-internal 导入。 */
5
+ export const rendererHost = () => { if (!global[KEY])
5
6
  throw new Error('Joplo renderer services are not initialized'); return global[KEY]; };
7
+ const host = rendererHost;
6
8
  export const useCtx = () => host().useCtx();
9
+ export const useEngineFrame = (enabled = true) => host().useEngineFrame(enabled);
7
10
  export const useI18n = () => host().useI18n();
8
- export const useR = (...args) => host().useR(...args);
9
11
  export const useRoot = (...args) => host().useRoot(...args);
10
12
  export const useRootAttrs = (...args) => host().useRootAttrs(...args);
11
- export const useStroke = () => host().useStroke();
12
13
  // Function components delegate to the host's identical React context, adding no DOM wrapper.
13
14
  export const RenderNode = (p) => host().RenderNode(p);
14
- export const Rough = (p) => host().Rough(p);
15
- export const RoughPath = (p) => host().RoughPath(p);
16
- export const roundRectPath = (...args) => host().roundRectPath(...args);
17
15
  export const rectOf = (...args) => host().rectOf(...args);
18
16
  export const resolveProps = (...args) => host().resolveProps(...args);
19
17
  export const isSelfVisible = (...args) => host().isSelfVisible(...args);
20
18
  export const walkNodes = (...args) => host().walkNodes(...args);
21
- export const RendererContextProvider = (props) => host().RendererContextProvider(props);
22
- export const useLook = () => host().useLook();
23
- export const atWidth = (...args) => host().atWidth(...args);
24
- export const childWidth = (...args) => host().childWidth(...args);
25
- export const choicesOf = (...args) => host().choicesOf(...args);
26
- export const layoutRegions = (...args) => host().layoutRegions(...args);
27
- export const resolveValue = (...args) => host().resolveValue(...args);
28
- export const styleOf = (...args) => host().styleOf(...args);
29
19
  export const nodeLabel = (...args) => host().nodeLabel(...args);
30
20
  /** Clocked drawing primitives provided by the host; no plugin animation timers. */
31
21
  export const motion = new Proxy({}, { get: (_target, key) => host().motion[key] });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@joplo-app/kit",
3
- "version": "0.4.1",
4
- "description": "Joplo 创作 SDK:组件、feature/option/flow 与 JSX 运行时(收集成数据,不作为 React 执行)",
3
+ "version": "0.6.0",
4
+ "description": "Joplo 创作 SDK:用 work、切片与步骤编写可播放、可上手体验的作品;功能评审为作品添加方案比较、情况与规则;含 JSX 运行时(收集为数据,不作为 React 执行)",
5
5
  "license": "PolyForm-Shield-1.0.0",
6
6
  "type": "module",
7
7
  "exports": {
@@ -30,6 +30,10 @@
30
30
  "types": "./dist/renderer.d.ts",
31
31
  "default": "./dist/renderer.js"
32
32
  },
33
+ "./renderer-internal": {
34
+ "types": "./dist/renderer-internal.d.ts",
35
+ "default": "./dist/renderer-internal.js"
36
+ },
33
37
  "./renderer-style": {
34
38
  "types": "./dist/renderer-style.d.ts",
35
39
  "default": "./dist/renderer-style.js"