@joplo-app/kit 0.2.18 → 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.
- package/dist/asset.d.ts +1 -1
- package/dist/asset.js +8 -5
- package/dist/index.d.ts +68 -49
- package/dist/index.js +31 -33
- package/dist/node.d.ts +5 -1
- package/dist/node.js +5 -2
- package/dist/plugin.d.ts +558 -0
- package/dist/plugin.js +73 -0
- package/dist/props.d.ts +28 -0
- package/dist/props.js +1 -0
- package/dist/renderer-style.d.ts +36 -0
- package/dist/renderer-style.js +107 -0
- package/dist/renderer.d.ts +138 -0
- package/dist/renderer.js +31 -0
- package/package.json +17 -6
- package/dist/ui.d.ts +0 -346
- package/dist/ui.js +0 -192
package/dist/asset.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/** 单个文件的上限:再大会拖慢看板加载并撑大发布包,应先压缩。 */
|
|
2
2
|
export declare const ASSET_MAX_BYTES: number;
|
|
3
|
-
/**
|
|
3
|
+
/** 读入图片或二进制资源,返回 data URI(用于 <Image src={…}>,也可以写进 style 的 backgroundImage: `url(${asset(…)})`)。 */
|
|
4
4
|
export declare function asset(path: string, from?: string): string;
|
package/dist/asset.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* asset('./photo.jpg')
|
|
2
|
+
* asset('./photo.jpg'):把项目里的图片、GLB 或音频读成 data URI,内嵌进演示(本地看板、build、share 都带着它,不依赖外网)。
|
|
3
3
|
* 路径相对于调用 asset() 的源文件,和 import 一样。作者模块在 Node 里执行,这里按需取 node:fs,
|
|
4
4
|
* 不在模块顶层静态导入,免得别处只为类型引用 kit 时牵出 Node 依赖。
|
|
5
5
|
*/
|
|
6
6
|
import { callsite } from "./node.js";
|
|
7
7
|
const MIME = {
|
|
8
|
+
glb: 'model/gltf-binary',
|
|
9
|
+
mp3: 'audio/mpeg', wav: 'audio/wav', ogg: 'audio/ogg', m4a: 'audio/mp4', flac: 'audio/flac',
|
|
8
10
|
jpg: 'image/jpeg',
|
|
9
11
|
jpeg: 'image/jpeg',
|
|
10
12
|
png: 'image/png',
|
|
@@ -21,7 +23,7 @@ function builtin(name) {
|
|
|
21
23
|
throw new Error('asset() runs while Joplo loads the project in Node (22.3 or newer)');
|
|
22
24
|
return get(name);
|
|
23
25
|
}
|
|
24
|
-
/**
|
|
26
|
+
/** 读入图片或二进制资源,返回 data URI(用于 <Image src={…}>,也可以写进 style 的 backgroundImage: `url(${asset(…)})`)。 */
|
|
25
27
|
export function asset(path, from) {
|
|
26
28
|
const fs = builtin('node:fs');
|
|
27
29
|
const p = builtin('node:path');
|
|
@@ -31,7 +33,7 @@ export function asset(path, from) {
|
|
|
31
33
|
const ext = p.extname(file).slice(1).toLowerCase();
|
|
32
34
|
const mime = MIME[ext];
|
|
33
35
|
if (!mime)
|
|
34
|
-
throw new Error(`asset("${path}"): unsupported
|
|
36
|
+
throw new Error(`asset("${path}"): unsupported asset type ".${ext}" (use ${Object.keys(MIME).join(', ')})`);
|
|
35
37
|
let size;
|
|
36
38
|
try {
|
|
37
39
|
const st = fs.statSync(file);
|
|
@@ -42,7 +44,8 @@ export function asset(path, from) {
|
|
|
42
44
|
catch {
|
|
43
45
|
throw new Error(`asset("${path}"): file not found at ${file} (paths are relative to the file that calls asset())`);
|
|
44
46
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
const limit = mime.startsWith('image/') ? ASSET_MAX_BYTES : 50 * 1024 * 1024;
|
|
48
|
+
if (size > limit)
|
|
49
|
+
throw new Error(`asset("${path}"): ${Math.round(size / 1024)} KB is over the ${limit / 1024 / 1024} MB limit; compress or resize the asset first`);
|
|
47
50
|
return `data:${mime};base64,${Buffer.from(fs.readFileSync(file)).toString('base64')}`;
|
|
48
51
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,9 +10,11 @@
|
|
|
10
10
|
* 所有函数只返回数据;画板不会执行这些代码,只消费编译出的 IR。
|
|
11
11
|
*/
|
|
12
12
|
import { type Bind, type CondExpr, type JNode } from './node.js';
|
|
13
|
-
export { $, and, empty, eq, Fragment, neq, not, notEmpty, oneOf, or, Outlet, Slot } from './node.js';
|
|
13
|
+
export { Custom, $, and, empty, eq, Fragment, neq, not, notEmpty, oneOf, or, Outlet, Slot } from './node.js';
|
|
14
14
|
export type { Bind, CondExpr, JNode } from './node.js';
|
|
15
15
|
export { asset } from './asset.js';
|
|
16
|
+
import type { PluginDef } from './plugin.js';
|
|
17
|
+
export type { PluginDef } from './plugin.js';
|
|
16
18
|
type Json = string | number | boolean | null | Json[] | {
|
|
17
19
|
[k: string]: Json;
|
|
18
20
|
};
|
|
@@ -46,6 +48,7 @@ export type VoiceConfig = {
|
|
|
46
48
|
* locales(D84):内容语言,第一个是源文件的语言(默认语言),其余的译文在 locales/<语言>.json(原文 → 译文)。
|
|
47
49
|
* 可选:en、zh-CN、zh-TW、ja、ko、es、fr、de、pt-BR、ru。加一种语言:npx joplo i18n add <语言>。
|
|
48
50
|
*/
|
|
51
|
+
/** plugins(D86):启用的插件(npm 包的默认导出,`plugins: [scene3d]`(包 @joplo-app/plugin-3d 的默认导出));用法见 npx joplo skill <插件 id>。 */
|
|
49
52
|
export type ConfigDef = {
|
|
50
53
|
kind: 'config';
|
|
51
54
|
name: string;
|
|
@@ -56,6 +59,7 @@ export type ConfigDef = {
|
|
|
56
59
|
autoFocus?: boolean;
|
|
57
60
|
voice?: VoiceConfig;
|
|
58
61
|
locales?: string[];
|
|
62
|
+
plugins?: PluginDef[];
|
|
59
63
|
source?: string;
|
|
60
64
|
};
|
|
61
65
|
export declare const config: (c: Omit<ConfigDef, "kind" | "source">) => ConfigDef;
|
|
@@ -195,12 +199,7 @@ export type EffectDef = {
|
|
|
195
199
|
kind: 'effect';
|
|
196
200
|
type: 'explain';
|
|
197
201
|
text: string;
|
|
198
|
-
} | {
|
|
199
|
-
kind: 'effect';
|
|
200
|
-
type: 'trace';
|
|
201
|
-
ids: string[];
|
|
202
|
-
mode: 'ok' | 'fail' | 'skip';
|
|
203
|
-
} | {
|
|
202
|
+
} | import('./plugin.js').PluginEffectDef | {
|
|
204
203
|
kind: 'effect';
|
|
205
204
|
type: 'stream';
|
|
206
205
|
path: string;
|
|
@@ -239,21 +238,11 @@ export type EffectDef = {
|
|
|
239
238
|
kind: 'effect';
|
|
240
239
|
type: 'narrate';
|
|
241
240
|
text: string;
|
|
242
|
-
} | {
|
|
243
|
-
kind: 'effect';
|
|
244
|
-
type: 'camera';
|
|
245
|
-
targets: string[];
|
|
246
|
-
pad?: number;
|
|
247
|
-
zoom?: number;
|
|
248
|
-
ms?: number;
|
|
249
241
|
};
|
|
250
242
|
/** 标注气泡放在目标的哪一侧;不写时自动选画面里放得下的一侧(右、左、下、上)。 */
|
|
251
243
|
export type CalloutSide = 'top' | 'right' | 'bottom' | 'left';
|
|
252
244
|
export declare const set: (target: Bind, value: Json) => EffectDef;
|
|
253
|
-
/**
|
|
254
|
-
* 一次改多处:patch($.data, { cam: 'chat', score: 3 }) 等于对每个键各写一个 set()。
|
|
255
|
-
* 嵌套对象整体替换(与 set 相同);步骤参数里直接展开数组即可:.system('…', patch($.data, {…}), hold(3))。
|
|
256
|
-
*/
|
|
245
|
+
/** Several ordinary set effects. Values replace whole nested objects; accepts the namespace or a nested bind. */
|
|
257
246
|
export declare const patch: (target: Bind | Record<string, unknown>, values: Record<string, Json>) => EffectDef[];
|
|
258
247
|
export declare const push: (target: Bind, value: Json) => EffectDef;
|
|
259
248
|
/** 与 sonner 一致:toast('…')、toast.success('…')、toast.error('…')。 */
|
|
@@ -287,19 +276,6 @@ export declare const uses: (...rules: string[]) => EffectDef;
|
|
|
287
276
|
* 没有声明 layers 的方案:shot 在路径页面里聚焦。
|
|
288
277
|
*/
|
|
289
278
|
export declare const shot: (...targets: string[]) => EffectDef;
|
|
290
|
-
/** camera() 的选项:pad 取景留白(设计像素,默认 48);zoom 最大放大倍数(默认 3);ms 镜头运动时长(默认 1200)。 */
|
|
291
|
-
export type CameraOpts = {
|
|
292
|
-
pad?: number;
|
|
293
|
-
zoom?: number;
|
|
294
|
-
ms?: number;
|
|
295
|
-
};
|
|
296
|
-
/**
|
|
297
|
-
* 画布镜头:<Canvas> 里的镜头对准这些元素(取它们合起来的范围,按画布的设计尺寸等比放进画面),平滑推、拉、摇,不画焦点框。
|
|
298
|
-
* 镜头位置会保留到下一次 camera();camera() 不带元素 = 回到整张画布。导演会切到目标所在的层。
|
|
299
|
-
* .system('读入', camera('tape', 'machine'))
|
|
300
|
-
* .system('全景', camera({ ms: 2000 }))
|
|
301
|
-
*/
|
|
302
|
-
export declare const camera: (...args: (string | CameraOpts)[]) => EffectDef;
|
|
303
279
|
/**
|
|
304
280
|
* 解说:这一步补充的一句话,显示在画面下方字幕区的第二行(说明下方、小一号);建议不超过 48 个字(check 会提示)。
|
|
305
281
|
* 自动播放时这一步停留的时长也按说明加解说的字数计算。不改变状态。
|
|
@@ -356,20 +332,6 @@ export declare const callout: (target: string, text: string, opts?: {
|
|
|
356
332
|
* .system('对比两种结果', '左边是旧流程,右边是新流程', hold(5))
|
|
357
333
|
*/
|
|
358
334
|
export declare const hold: (seconds: number) => EffectDef;
|
|
359
|
-
/**
|
|
360
|
-
* 调用链(D48):这一步沿 Diagram 的连线走了哪条路径。节点与连线的 state 由每一步的 trace 自动推算,不用再手写 set / state 绑定:
|
|
361
|
-
* 本步 trace 到的是 active,之前 trace 过、本步没再 trace 的是 ok,trace.fail 的是 error(保持到之后又被 trace 成功),
|
|
362
|
-
* trace.skip 的是 dim,从未涉及的是 idle;节点或连线上显式写的 state 优先。
|
|
363
|
-
* 参数是节点 id 或连线 id:trace('brain', 'biz', 'local') 是 brain→biz、biz→local 两段;每段要有对应的连线,
|
|
364
|
-
* 方向 from→to 或 to→from 都算(反向时流动的小点逆向走);同一方向有多条连线时写连线 id:trace('e_brain_biz')。
|
|
365
|
-
* trace 同时相当于一个 shot(节点作为镜头目标,顺序有意义);同一步再写 shot 时两者合并。
|
|
366
|
-
*/
|
|
367
|
-
export declare const trace: ((...ids: string[]) => EffectDef) & {
|
|
368
|
-
/** 这段失败:连线和终点节点标为 error(保持到场景结束,除非之后又被 trace 成功)。 */
|
|
369
|
-
fail: (...ids: string[]) => EffectDef;
|
|
370
|
-
/** 这次没被调用:节点(以及它们之间的连线)标为 dim;不移动镜头。 */
|
|
371
|
-
skip: (...ids: string[]) => EffectDef;
|
|
372
|
-
};
|
|
373
335
|
/**
|
|
374
336
|
* 层级(视角,D43 / T-layers):一个完全独立的画面,有自己的 JSX 树,单独渲染、按自己的布局占满舞台。
|
|
375
337
|
* 各层共享同一份场景状态(ui / data / inputs),切层时步骤不变。需要全景就自己声明一个 overview 层。
|
|
@@ -392,9 +354,9 @@ export declare const layer: (title: string, tree: JNode | JNode[], opts?: {
|
|
|
392
354
|
role?: string;
|
|
393
355
|
icon?: LayerIcon;
|
|
394
356
|
}) => LayerDef;
|
|
395
|
-
/** 步骤参数:字符串是字幕(可省略,省略时自动生成),其余是效果。 */
|
|
396
357
|
/** 步骤参数:字幕、效果,或一组效果(patch() 返回数组,直接传入即可)。 */
|
|
397
|
-
|
|
358
|
+
/** Helpers can compose other helpers (for example patch plus timing effects). */
|
|
359
|
+
export type StepArg = string | EffectDef | readonly StepArg[];
|
|
398
360
|
/**
|
|
399
361
|
* 过渡卡(D56)的内容:整屏一句大字,用于开场、收尾、时间跳跃(「3 天后」)和换人。
|
|
400
362
|
* sub:小一号的补充;points:收尾时列几条要点;role:换到哪个人(feature.roles 的键),卡片显示这个人,
|
|
@@ -405,6 +367,7 @@ export type CardOpts = {
|
|
|
405
367
|
points?: string[];
|
|
406
368
|
role?: string;
|
|
407
369
|
};
|
|
370
|
+
export type CardArg = CardOpts | EffectDef | readonly CardArg[];
|
|
408
371
|
export type StepDef = {
|
|
409
372
|
/** Stable identity within this scenario; independent of the playback position. */
|
|
410
373
|
key?: string;
|
|
@@ -412,6 +375,29 @@ export type StepDef = {
|
|
|
412
375
|
action: {
|
|
413
376
|
type: 'click';
|
|
414
377
|
target: string;
|
|
378
|
+
} | {
|
|
379
|
+
type: 'drag';
|
|
380
|
+
target: string;
|
|
381
|
+
to: string | {
|
|
382
|
+
x: number;
|
|
383
|
+
y: number;
|
|
384
|
+
};
|
|
385
|
+
} | {
|
|
386
|
+
type: 'hover';
|
|
387
|
+
target: string;
|
|
388
|
+
ms: number;
|
|
389
|
+
} | {
|
|
390
|
+
type: 'scroll';
|
|
391
|
+
target: string;
|
|
392
|
+
to: string | {
|
|
393
|
+
x: number;
|
|
394
|
+
y: number;
|
|
395
|
+
};
|
|
396
|
+
} | {
|
|
397
|
+
type: 'plugin';
|
|
398
|
+
name: string;
|
|
399
|
+
target: string;
|
|
400
|
+
data: Record<string, unknown>;
|
|
415
401
|
} | {
|
|
416
402
|
type: 'type';
|
|
417
403
|
target: string;
|
|
@@ -441,6 +427,8 @@ export type StepDef = {
|
|
|
441
427
|
source?: string;
|
|
442
428
|
};
|
|
443
429
|
export type FlowOpts = {
|
|
430
|
+
/** Cross-scenario action confirmation lands before the match by default; after consumes it once. */
|
|
431
|
+
actionEntry?: 'before' | 'after';
|
|
444
432
|
/** 覆盖的情况(feature.cases 的键)。 */
|
|
445
433
|
cases?: string[];
|
|
446
434
|
/** 模拟结果标签,例如“模拟失败”。缺省按 outcome 生成。 */
|
|
@@ -451,10 +439,12 @@ export type FlowOpts = {
|
|
|
451
439
|
/** 在 option.state 之上覆盖的初始状态。 */
|
|
452
440
|
state?: StateInit;
|
|
453
441
|
/**
|
|
454
|
-
* 接着另一个场景演(同一方案的场景键):初始状态 = 那个场景最后一步之后的状态(路径、ui / data / inputs
|
|
442
|
+
* 接着另一个场景演(同一方案的场景键):初始状态 = 那个场景最后一步之后的状态(路径、ui / data / inputs、导演层),
|
|
455
443
|
* 再叠上这里的 state。讲解片的章节、长流程的分段都用它,每一段从上一段结尾的画面开始,不用手抄状态。
|
|
456
444
|
*/
|
|
457
445
|
from?: string;
|
|
446
|
+
/** false:保留手动/分支访问,但从发布站连续播放序列中排除;该场景播完停下。 */
|
|
447
|
+
autoplay?: boolean;
|
|
458
448
|
/** 从哪一层开始(layers 的键);缺省为第一层,写了 from 时为那个场景结尾的导演层。 */
|
|
459
449
|
layer?: string;
|
|
460
450
|
description?: string;
|
|
@@ -471,6 +461,17 @@ export declare class Flow {
|
|
|
471
461
|
/** Give the preceding step a stable key. Keep it when editing or moving the same action. */
|
|
472
462
|
key(key: string): this;
|
|
473
463
|
click(target: string, ...args: StepArg[]): this;
|
|
464
|
+
drag(target: string, to: string | {
|
|
465
|
+
x: number;
|
|
466
|
+
y: number;
|
|
467
|
+
}, ...args: StepArg[]): this;
|
|
468
|
+
hover(target: string, ms?: number, ...args: StepArg[]): this;
|
|
469
|
+
scroll(target: string, to: string | {
|
|
470
|
+
x: number;
|
|
471
|
+
y: number;
|
|
472
|
+
}, ...args: StepArg[]): this;
|
|
473
|
+
/** Namespaced plugin action; payload and matching are declared by its plugin. */
|
|
474
|
+
act(name: string, target: string, data: Record<string, unknown>, ...args: StepArg[]): this;
|
|
474
475
|
type(target: string, value: string, ...args: StepArg[]): this;
|
|
475
476
|
select(target: string, value: string, ...args: StepArg[]): this;
|
|
476
477
|
toggle(target: string, value: boolean, ...args: StepArg[]): this;
|
|
@@ -484,12 +485,28 @@ export declare class Flow {
|
|
|
484
485
|
* .card('出发前一天', set($.data.weather, 'rain'))
|
|
485
486
|
* .card('这个方案确认了', { points: ['行程单可以分享', '天气变了会主动提醒'] })
|
|
486
487
|
*/
|
|
487
|
-
card(title: string, ...rest:
|
|
488
|
+
card(title: string, ...rest: CardArg[]): this;
|
|
488
489
|
/** 系统事件,例如“请求成功(模拟)”。 */
|
|
489
490
|
system(name: string, ...args: StepArg[]): this;
|
|
490
491
|
}
|
|
491
492
|
/** 一条演示路径。 */
|
|
492
493
|
export declare const flow: (name: string, opts?: FlowOpts) => Flow;
|
|
494
|
+
export declare const free: {
|
|
495
|
+
click: (target: string, ...args: StepArg[]) => StepDef;
|
|
496
|
+
type: (target: string, value: string, ...args: StepArg[]) => StepDef;
|
|
497
|
+
select: (target: string, value: string, ...args: StepArg[]) => StepDef;
|
|
498
|
+
toggle: (target: string, value: boolean, ...args: StepArg[]) => StepDef;
|
|
499
|
+
drag: (target: string, to: string | {
|
|
500
|
+
x: number;
|
|
501
|
+
y: number;
|
|
502
|
+
}, ...args: StepArg[]) => StepDef;
|
|
503
|
+
hover: (target: string, ms?: number, ...args: StepArg[]) => StepDef;
|
|
504
|
+
scroll: (target: string, to: string | {
|
|
505
|
+
x: number;
|
|
506
|
+
y: number;
|
|
507
|
+
}, ...args: StepArg[]) => StepDef;
|
|
508
|
+
act: (name: string, target: string, data: Record<string, unknown>, ...args: StepArg[]) => StepDef;
|
|
509
|
+
};
|
|
493
510
|
export type OptionDef = {
|
|
494
511
|
kind: 'option';
|
|
495
512
|
name: string;
|
|
@@ -507,8 +524,10 @@ export type OptionDef = {
|
|
|
507
524
|
coverage?: Record<string, CoverageDecl>;
|
|
508
525
|
/** 层级(视角):每层一个独立画面 { client: layer('客户端视角', <ClientView />), backend: layer('后端流转', <Arch />) }。 */
|
|
509
526
|
layers?: Record<string, LayerDef>;
|
|
527
|
+
free?: Record<string, StepDef>;
|
|
510
528
|
scenarios: Record<string, Flow>;
|
|
511
529
|
source?: string;
|
|
512
530
|
};
|
|
513
531
|
export declare const option: (o: Omit<OptionDef, "kind" | "source">) => OptionDef;
|
|
514
532
|
export type { CondExpr as Condition };
|
|
533
|
+
export type { JoploProps } from './props.js';
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* 所有函数只返回数据;画板不会执行这些代码,只消费编译出的 IR。
|
|
11
11
|
*/
|
|
12
12
|
import { bindPath, callsite, isBind } from "./node.js";
|
|
13
|
-
export { $, and, empty, eq, Fragment, neq, not, notEmpty, oneOf, or, Outlet, Slot } from "./node.js";
|
|
13
|
+
export { Custom, $, and, empty, eq, Fragment, neq, not, notEmpty, oneOf, or, Outlet, Slot } from "./node.js";
|
|
14
14
|
export { asset } from "./asset.js";
|
|
15
15
|
export const config = (c) => ({ kind: 'config', ...c, source: callsite() });
|
|
16
16
|
export const layout = (tree) => ({ kind: 'layout', tree, source: callsite() });
|
|
@@ -46,11 +46,8 @@ export const notApplicable = (reason) => ({ kind: 'coverage', status: 'not_appli
|
|
|
46
46
|
export const excluded = (reason) => ({ kind: 'coverage', status: 'excluded', reason });
|
|
47
47
|
const pathOf = (b) => (isBind(b) ? bindPath(b) : b);
|
|
48
48
|
export const set = (target, value) => ({ kind: 'effect', type: 'set', path: pathOf(target), value });
|
|
49
|
-
/**
|
|
50
|
-
|
|
51
|
-
* 嵌套对象整体替换(与 set 相同);步骤参数里直接展开数组即可:.system('…', patch($.data, {…}), hold(3))。
|
|
52
|
-
*/
|
|
53
|
-
export const patch = (target, values) => Object.entries(values).map(([k, v]) => ({ kind: 'effect', type: 'set', path: `${pathOf(target)}.${k}`, value: v }));
|
|
49
|
+
/** Several ordinary set effects. Values replace whole nested objects; accepts the namespace or a nested bind. */
|
|
50
|
+
export const patch = (target, values) => Object.entries(values).map(([key, value]) => ({ kind: 'effect', type: 'set', path: `${pathOf(target)}.${key}`, value }));
|
|
54
51
|
export const push = (target, value) => ({ kind: 'effect', type: 'append', path: pathOf(target), value });
|
|
55
52
|
/** 与 sonner 一致:toast('…')、toast.success('…')、toast.error('…')。 */
|
|
56
53
|
export const toast = Object.assign((text) => ({ kind: 'effect', type: 'toast', text, tone: 'info' }), {
|
|
@@ -80,17 +77,6 @@ export const uses = (...rules) => ({ kind: 'effect', type: 'uses', rules });
|
|
|
80
77
|
* 没有声明 layers 的方案:shot 在路径页面里聚焦。
|
|
81
78
|
*/
|
|
82
79
|
export const shot = (...targets) => ({ kind: 'effect', type: 'shot', targets });
|
|
83
|
-
/**
|
|
84
|
-
* 画布镜头:<Canvas> 里的镜头对准这些元素(取它们合起来的范围,按画布的设计尺寸等比放进画面),平滑推、拉、摇,不画焦点框。
|
|
85
|
-
* 镜头位置会保留到下一次 camera();camera() 不带元素 = 回到整张画布。导演会切到目标所在的层。
|
|
86
|
-
* .system('读入', camera('tape', 'machine'))
|
|
87
|
-
* .system('全景', camera({ ms: 2000 }))
|
|
88
|
-
*/
|
|
89
|
-
export const camera = (...args) => {
|
|
90
|
-
const targets = args.filter((a) => typeof a === 'string');
|
|
91
|
-
const o = Object.assign({}, ...args.filter((a) => typeof a === 'object' && a !== null));
|
|
92
|
-
return { kind: 'effect', type: 'camera', targets, ...(o.pad !== undefined ? { pad: o.pad } : {}), ...(o.zoom !== undefined ? { zoom: o.zoom } : {}), ...(o.ms !== undefined ? { ms: o.ms } : {}) };
|
|
93
|
-
};
|
|
94
80
|
/**
|
|
95
81
|
* 解说:这一步补充的一句话,显示在画面下方字幕区的第二行(说明下方、小一号);建议不超过 48 个字(check 会提示)。
|
|
96
82
|
* 自动播放时这一步停留的时长也按说明加解说的字数计算。不改变状态。
|
|
@@ -148,22 +134,9 @@ export const callout = (target, text, opts = {}) => ({ kind: 'effect', type: 'ca
|
|
|
148
134
|
* .system('对比两种结果', '左边是旧流程,右边是新流程', hold(5))
|
|
149
135
|
*/
|
|
150
136
|
export const hold = (seconds) => ({ kind: 'effect', type: 'hold', seconds });
|
|
151
|
-
/**
|
|
152
|
-
* 调用链(D48):这一步沿 Diagram 的连线走了哪条路径。节点与连线的 state 由每一步的 trace 自动推算,不用再手写 set / state 绑定:
|
|
153
|
-
* 本步 trace 到的是 active,之前 trace 过、本步没再 trace 的是 ok,trace.fail 的是 error(保持到之后又被 trace 成功),
|
|
154
|
-
* trace.skip 的是 dim,从未涉及的是 idle;节点或连线上显式写的 state 优先。
|
|
155
|
-
* 参数是节点 id 或连线 id:trace('brain', 'biz', 'local') 是 brain→biz、biz→local 两段;每段要有对应的连线,
|
|
156
|
-
* 方向 from→to 或 to→from 都算(反向时流动的小点逆向走);同一方向有多条连线时写连线 id:trace('e_brain_biz')。
|
|
157
|
-
* trace 同时相当于一个 shot(节点作为镜头目标,顺序有意义);同一步再写 shot 时两者合并。
|
|
158
|
-
*/
|
|
159
|
-
export const trace = Object.assign((...ids) => ({ kind: 'effect', type: 'trace', ids, mode: 'ok' }), {
|
|
160
|
-
/** 这段失败:连线和终点节点标为 error(保持到场景结束,除非之后又被 trace 成功)。 */
|
|
161
|
-
fail: (...ids) => ({ kind: 'effect', type: 'trace', ids, mode: 'fail' }),
|
|
162
|
-
/** 这次没被调用:节点(以及它们之间的连线)标为 dim;不移动镜头。 */
|
|
163
|
-
skip: (...ids) => ({ kind: 'effect', type: 'trace', ids, mode: 'skip' }),
|
|
164
|
-
});
|
|
165
137
|
/** opts.role:这一层是谁的画面(feature.roles 的键,D56);画面角落显示这个人的名牌,层级标签带上头像。 */
|
|
166
138
|
export const layer = (title, tree, opts = {}) => ({ kind: 'layer', title, tree, ...opts, source: callsite() });
|
|
139
|
+
const flattenArgs = (args) => args.flat(Infinity);
|
|
167
140
|
export class Flow {
|
|
168
141
|
name;
|
|
169
142
|
opts;
|
|
@@ -176,7 +149,7 @@ export class Flow {
|
|
|
176
149
|
this.source = callsite(4);
|
|
177
150
|
}
|
|
178
151
|
add(kind, action, args) {
|
|
179
|
-
const flat = args
|
|
152
|
+
const flat = flattenArgs(args);
|
|
180
153
|
const caption = flat.find((a) => typeof a === 'string');
|
|
181
154
|
const effects = flat.filter((a) => typeof a !== 'string');
|
|
182
155
|
this.steps.push({ kind, action, ...(caption ? { caption } : {}), effects, source: callsite(4) });
|
|
@@ -195,6 +168,19 @@ export class Flow {
|
|
|
195
168
|
click(target, ...args) {
|
|
196
169
|
return this.add('user', { type: 'click', target }, args);
|
|
197
170
|
}
|
|
171
|
+
drag(target, to, ...args) {
|
|
172
|
+
return this.add('user', { type: 'drag', target, to }, args);
|
|
173
|
+
}
|
|
174
|
+
hover(target, ms = 500, ...args) {
|
|
175
|
+
return this.add('user', { type: 'hover', target, ms }, args);
|
|
176
|
+
}
|
|
177
|
+
scroll(target, to, ...args) {
|
|
178
|
+
return this.add('user', { type: 'scroll', target, to }, args);
|
|
179
|
+
}
|
|
180
|
+
/** Namespaced plugin action; payload and matching are declared by its plugin. */
|
|
181
|
+
act(name, target, data, ...args) {
|
|
182
|
+
return this.add('user', { type: 'plugin', name, target, data }, args);
|
|
183
|
+
}
|
|
198
184
|
type(target, value, ...args) {
|
|
199
185
|
return this.add('user', { type: 'type', target, value }, args);
|
|
200
186
|
}
|
|
@@ -219,7 +205,7 @@ export class Flow {
|
|
|
219
205
|
* .card('这个方案确认了', { points: ['行程单可以分享', '天气变了会主动提醒'] })
|
|
220
206
|
*/
|
|
221
207
|
card(title, ...rest) {
|
|
222
|
-
const args = rest
|
|
208
|
+
const args = flattenArgs(rest);
|
|
223
209
|
const effects = args.filter((a) => a.kind === 'effect');
|
|
224
210
|
const opts = Object.assign({}, ...args.filter((a) => a.kind !== 'effect'));
|
|
225
211
|
const { sub, points, role } = opts;
|
|
@@ -234,4 +220,16 @@ export class Flow {
|
|
|
234
220
|
}
|
|
235
221
|
/** 一条演示路径。 */
|
|
236
222
|
export const flow = (name, opts = {}) => new Flow(name, opts);
|
|
223
|
+
/** Unordered local reactions; the compiler permits only local state effects. */
|
|
224
|
+
const reaction = (build) => ({ ...build(new Flow('free', {})).steps[0], source: callsite(4) });
|
|
225
|
+
export const free = {
|
|
226
|
+
click: (target, ...args) => reaction(f => f.click(target, ...args)),
|
|
227
|
+
type: (target, value, ...args) => reaction(f => f.type(target, value, ...args)),
|
|
228
|
+
select: (target, value, ...args) => reaction(f => f.select(target, value, ...args)),
|
|
229
|
+
toggle: (target, value, ...args) => reaction(f => f.toggle(target, value, ...args)),
|
|
230
|
+
drag: (target, to, ...args) => reaction(f => f.drag(target, to, ...args)),
|
|
231
|
+
hover: (target, ms = 500, ...args) => reaction(f => f.hover(target, ms, ...args)),
|
|
232
|
+
scroll: (target, to, ...args) => reaction(f => f.scroll(target, to, ...args)),
|
|
233
|
+
act: (name, target, data, ...args) => reaction(f => f.act(name, target, data, ...args)),
|
|
234
|
+
};
|
|
237
235
|
export const option = (o) => ({ kind: 'option', ...o, source: callsite() });
|
package/dist/node.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ export type CondExpr = {
|
|
|
14
14
|
export type JNode = {
|
|
15
15
|
readonly [NODE]: true;
|
|
16
16
|
type: string;
|
|
17
|
+
/** Author-only package provenance for missing-plugin diagnostics. */
|
|
18
|
+
packageName?: string;
|
|
17
19
|
props: Record<string, unknown>;
|
|
18
20
|
children: JChild[];
|
|
19
21
|
/** jsxDEV 提供的源位置(绝对路径:行:列),编译器会改成项目相对路径。 */
|
|
@@ -23,12 +25,14 @@ export type JChild = JNode | string | number | boolean | null | undefined | Bind
|
|
|
23
25
|
/** 目录组件的标记函数。 */
|
|
24
26
|
export type ComponentMarker = ((props: Record<string, unknown>) => never) & {
|
|
25
27
|
readonly [COMPONENT]: string;
|
|
28
|
+
readonly packageName?: string;
|
|
26
29
|
};
|
|
27
|
-
export declare function component(name: string): ComponentMarker;
|
|
30
|
+
export declare function component(name: string, packageName?: string): ComponentMarker;
|
|
28
31
|
export declare const isNode: (v: unknown) => v is JNode;
|
|
29
32
|
export declare const isBind: (v: unknown) => v is Bind;
|
|
30
33
|
export declare const bindPath: (b: Bind) => string;
|
|
31
34
|
export declare const Fragment: ComponentMarker;
|
|
35
|
+
export declare const Custom: ComponentMarker;
|
|
32
36
|
/** 布局或页面中的插槽:方案把元素堆叠到这里。 */
|
|
33
37
|
export declare const Slot: (props: {
|
|
34
38
|
name: string;
|
package/dist/node.js
CHANGED
|
@@ -5,18 +5,21 @@
|
|
|
5
5
|
export const NODE = Symbol.for('joplo.node');
|
|
6
6
|
export const COMPONENT = Symbol.for('joplo.component');
|
|
7
7
|
export const BIND = Symbol.for('joplo.bind');
|
|
8
|
-
export function component(name) {
|
|
8
|
+
export function component(name, packageName) {
|
|
9
9
|
const fn = (() => {
|
|
10
10
|
throw new Error(`${name} is a Joplo component marker and can only be used in JSX`);
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(fn, COMPONENT, { value: name });
|
|
13
13
|
Object.defineProperty(fn, 'displayName', { value: name });
|
|
14
|
+
if (packageName)
|
|
15
|
+
Object.defineProperty(fn, 'packageName', { value: packageName });
|
|
14
16
|
return fn;
|
|
15
17
|
}
|
|
16
18
|
export const isNode = (v) => typeof v === 'object' && v !== null && v[NODE] === true;
|
|
17
19
|
export const isBind = (v) => (typeof v === 'object' || typeof v === 'function') && v !== null && typeof v[BIND] === 'string';
|
|
18
20
|
export const bindPath = (b) => b[BIND];
|
|
19
21
|
export const Fragment = component('#fragment');
|
|
22
|
+
export const Custom = component('Custom');
|
|
20
23
|
/** 布局或页面中的插槽:方案把元素堆叠到这里。 */
|
|
21
24
|
export const Slot = component('#slot');
|
|
22
25
|
/** 布局中页面内容的位置。 */
|
|
@@ -31,7 +34,7 @@ export function createNode(type, rawProps, source) {
|
|
|
31
34
|
if (typeof type === 'function') {
|
|
32
35
|
const name = type[COMPONENT];
|
|
33
36
|
if (name)
|
|
34
|
-
return mk(name, props, children, src);
|
|
37
|
+
return { ...mk(name, props, children, src), ...(type.packageName ? { packageName: type.packageName } : {}) };
|
|
35
38
|
// 作者自定义的函数组件:收集时展开
|
|
36
39
|
const out = type({ ...props, children });
|
|
37
40
|
if (isNode(out)) {
|