@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/plugin.d.ts
ADDED
|
@@ -0,0 +1,558 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 插件(D87):社区维护的 npm 包,给 Joplo 增加组件。引擎(步骤、状态、镜头、提示、朗读、导出、发布)不变,
|
|
3
|
+
* 插件只负责“这个组件长什么样、观众怎么和它互动”。一个插件包有两部分:
|
|
4
|
+
*
|
|
5
|
+
* 1. 入口(Node 端载入,编译钩子只在编译期运行):`definePlugin({...})` 的清单、组件标记、给 Agent 读的技能正文。
|
|
6
|
+
* 作者在 joplo.config.ts 写 `plugins: [scene3d]` 启用;`npx joplo skill <插件 id>` 输出它的技能。
|
|
7
|
+
* 2. 运行时(浏览器端):`defineRuntime({...})`,看板、截图、导出视频与发布站载入,负责把组件画出来。
|
|
8
|
+
* 运行时支持 mount 或 React 组件;React 共享宿主实例,其余依赖(例如 three)自行打包,发布站内联。
|
|
9
|
+
*
|
|
10
|
+
* 不变量(插件与引擎的契约):
|
|
11
|
+
* - 业务状态只由引擎的步骤推进;插件只读 ctx,不能改状态。观众在插件里点了什么,调用 ctx.click(id),
|
|
12
|
+
* 和点 DOM 元素一样交给引擎判断(这一步该不该点、点了发生什么)。
|
|
13
|
+
* - 能被步骤、镜头、提示、圈注、检查引用的子元素,都要在 DOM 里放一个锚点,带上 node.attrs(data-jid 等)
|
|
14
|
+
* 并摆在它在画面上的位置;引擎的光标、镜头、聚光、圈注、⌥+单击检查都按锚点定位。
|
|
15
|
+
* - 同一个 ctx 画出的结果相同(截图、视频可复现);frame.animate 为 false 时不播放过渡;
|
|
16
|
+
* 资源没准备好时用 ctx.hold() 让截图等待。
|
|
17
|
+
*/
|
|
18
|
+
import { type JNode } from './node.js';
|
|
19
|
+
import type { JoploProps } from './props.js';
|
|
20
|
+
export type { JoploProps } from './props.js';
|
|
21
|
+
/** 插件接口版本:v2 宿主同时兼容 v1 的 mount 运行时。 */
|
|
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. */
|
|
26
|
+
native?: {
|
|
27
|
+
action: 'type' | 'toggle' | 'select';
|
|
28
|
+
prop: string;
|
|
29
|
+
deselect?: boolean;
|
|
30
|
+
};
|
|
31
|
+
draggable?: boolean;
|
|
32
|
+
hover?: boolean;
|
|
33
|
+
/** Visibility of a panel selected by an ancestor value control. */
|
|
34
|
+
selectionGate?: {
|
|
35
|
+
owner: string;
|
|
36
|
+
item?: string;
|
|
37
|
+
value: string;
|
|
38
|
+
fallbackFirst?: boolean;
|
|
39
|
+
};
|
|
40
|
+
input?: 'single' | 'multiple';
|
|
41
|
+
frame?: boolean;
|
|
42
|
+
disabledPresentation?: boolean;
|
|
43
|
+
/** First defined property controls visibility of this node and its descendants. */
|
|
44
|
+
gate?: string[];
|
|
45
|
+
choices?: {
|
|
46
|
+
prop: string;
|
|
47
|
+
} | {
|
|
48
|
+
descendants: string[];
|
|
49
|
+
value?: string;
|
|
50
|
+
label?: string;
|
|
51
|
+
labelChild?: string;
|
|
52
|
+
} | {
|
|
53
|
+
range: string;
|
|
54
|
+
};
|
|
55
|
+
toggleCaption?: 'check';
|
|
56
|
+
selfEvident?: boolean;
|
|
57
|
+
/** Region names are arbitrary plugin-owned properties on the layout node. */
|
|
58
|
+
layout?: Record<string, {
|
|
59
|
+
size: string;
|
|
60
|
+
defaultSize: number;
|
|
61
|
+
breakpoint?: boolean;
|
|
62
|
+
}>;
|
|
63
|
+
region?: string;
|
|
64
|
+
childWidth?: {
|
|
65
|
+
value: number;
|
|
66
|
+
when?: {
|
|
67
|
+
prop: string;
|
|
68
|
+
value: string | number | boolean;
|
|
69
|
+
width: number;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
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[][];
|
|
76
|
+
};
|
|
77
|
+
/** 插件组件的声明:编译、检查、技能都只读这里,不执行运行时代码。 */
|
|
78
|
+
export type PluginComponentSpec = {
|
|
79
|
+
/** 一行用法(`npx joplo skill <插件>` 列出),例如 'focus, height; root of a 3D scene'。 */
|
|
80
|
+
doc: string;
|
|
81
|
+
example?: string;
|
|
82
|
+
/** Condense compound parts into one family row in the components overview. */
|
|
83
|
+
catalogFamily?: boolean;
|
|
84
|
+
/** Direct JSX string tags mapped to this component by the compiler. */
|
|
85
|
+
intrinsic?: string;
|
|
86
|
+
traits?: ElementTraits;
|
|
87
|
+
/** Compile-time property forwarding, stopping at a nested owner of the same type. */
|
|
88
|
+
inherit?: {
|
|
89
|
+
target: string;
|
|
90
|
+
props: string[];
|
|
91
|
+
}[];
|
|
92
|
+
/** 可操作:必须有 id,并且要有演示步骤、禁用原因或 unmodeled(和 Button 一样)。 */
|
|
93
|
+
interactive?: boolean;
|
|
94
|
+
/** 必须具有作者 id(不要求可操作)。 */
|
|
95
|
+
needsId?: boolean;
|
|
96
|
+
/** 自己表现状态变化,不叠加自动 reveal。 */
|
|
97
|
+
selfEvident?: boolean;
|
|
98
|
+
/** 只能写在哪个组件里面(同一插件的组件名,例如 'Scene');写在别处时 check 报错。 */
|
|
99
|
+
parent?: string;
|
|
100
|
+
};
|
|
101
|
+
/** 编译钩子只在 Node 端调用;传入的数据不是运行时对象。 */
|
|
102
|
+
export type PluginReport = (code: string, message: string, at?: string, severity?: 'error' | 'warning' | 'info') => void;
|
|
103
|
+
export type PluginIRNode = {
|
|
104
|
+
id: string;
|
|
105
|
+
type: string;
|
|
106
|
+
props?: Record<string, unknown>;
|
|
107
|
+
children?: PluginIRNode[];
|
|
108
|
+
source?: string;
|
|
109
|
+
ext?: Record<string, unknown>;
|
|
110
|
+
traits?: ElementTraits;
|
|
111
|
+
framing?: {
|
|
112
|
+
include?: string[];
|
|
113
|
+
kind?: 'root' | 'group' | 'block' | 'content' | 'edge' | 'row';
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
export type PluginEffectDef = {
|
|
117
|
+
kind: 'effect';
|
|
118
|
+
type: 'plugin';
|
|
119
|
+
plugin: string;
|
|
120
|
+
name: string;
|
|
121
|
+
payload: unknown;
|
|
122
|
+
};
|
|
123
|
+
export declare const pluginEffect: (plugin: string, name: string, payload: unknown) => PluginEffectDef;
|
|
124
|
+
export type PluginState = {
|
|
125
|
+
readonly ui: Readonly<Record<string, unknown>>;
|
|
126
|
+
readonly data: Readonly<Record<string, unknown>>;
|
|
127
|
+
readonly inputs: Readonly<Record<string, unknown>>;
|
|
128
|
+
};
|
|
129
|
+
export type PluginScene = {
|
|
130
|
+
id: string;
|
|
131
|
+
root: PluginIRNode;
|
|
132
|
+
};
|
|
133
|
+
export type PluginDerived = {
|
|
134
|
+
data?: unknown;
|
|
135
|
+
framing?: Record<string, NonNullable<PluginIRNode['framing']>>;
|
|
136
|
+
};
|
|
137
|
+
export type PluginCompileHooks = {
|
|
138
|
+
/** 子节点转换完后调用;可校验根结构、提供默认 id 与规范化属性。 */
|
|
139
|
+
node?: (node: Readonly<JNode>, ctx: {
|
|
140
|
+
ids: ReadonlyMap<string, string | undefined>;
|
|
141
|
+
report: PluginReport;
|
|
142
|
+
}) => JNode | void;
|
|
143
|
+
/** 每个根节点的静态派生数据,错误由宿主隔离。 */
|
|
144
|
+
derive?: (node: Readonly<PluginIRNode>, ctx: {
|
|
145
|
+
viewport: 'desktop' | 'mobile';
|
|
146
|
+
report: PluginReport;
|
|
147
|
+
options: Readonly<Record<string, unknown>>;
|
|
148
|
+
}) => PluginDerived | void;
|
|
149
|
+
/** 一个作者效果降级为数据及内核原语。targets 贡献普通取景;directorTarget 只选择层。writes 按作者顺序生成 set;data 是同一步之前的降级结果。 */
|
|
150
|
+
effect?: (effect: PluginEffectDef, ctx: {
|
|
151
|
+
roots: readonly PluginIRNode[];
|
|
152
|
+
scenes: readonly PluginScene[];
|
|
153
|
+
data: unknown;
|
|
154
|
+
report: PluginReport;
|
|
155
|
+
source?: string;
|
|
156
|
+
resourceInfo: (id: string) => LocalResourceInfo | undefined;
|
|
157
|
+
resource: (request: {
|
|
158
|
+
compiler: string;
|
|
159
|
+
input: string;
|
|
160
|
+
}) => string;
|
|
161
|
+
}) => {
|
|
162
|
+
data?: unknown;
|
|
163
|
+
targets?: string[];
|
|
164
|
+
references?: string[];
|
|
165
|
+
writes?: PluginWrite[];
|
|
166
|
+
directorTarget?: string;
|
|
167
|
+
media?: MediaCommand[];
|
|
168
|
+
} | void;
|
|
169
|
+
/** 编译器回放基础效果后,计算第 0 步及每一步的完整绘制快照。 */
|
|
170
|
+
frame?: (ctx: {
|
|
171
|
+
roots: readonly PluginIRNode[];
|
|
172
|
+
scenes: readonly PluginScene[];
|
|
173
|
+
state: PluginState;
|
|
174
|
+
previousState?: PluginState;
|
|
175
|
+
resolveProps: (node: PluginIRNode, previous?: boolean) => Record<string, unknown>;
|
|
176
|
+
data: unknown;
|
|
177
|
+
previousData: unknown;
|
|
178
|
+
position: number;
|
|
179
|
+
report: PluginReport;
|
|
180
|
+
}) => unknown;
|
|
181
|
+
};
|
|
182
|
+
/** Author-only requests never enter IR. Local compilers run in a bounded Node process. */
|
|
183
|
+
export type ResourceRequest = {
|
|
184
|
+
id: string;
|
|
185
|
+
plugin: string;
|
|
186
|
+
compiler: string;
|
|
187
|
+
input: string;
|
|
188
|
+
source?: string;
|
|
189
|
+
};
|
|
190
|
+
export declare const localResource: (plugin: string, compiler: string, input: string) => {
|
|
191
|
+
kind: "local-resource";
|
|
192
|
+
plugin: string;
|
|
193
|
+
compiler: string;
|
|
194
|
+
input: string;
|
|
195
|
+
};
|
|
196
|
+
/** Inspection runs only on the author machine; none of this metadata is automatically published. */
|
|
197
|
+
export type LocalResourceInfo = {
|
|
198
|
+
durationMs?: number;
|
|
199
|
+
markers?: Record<string, number>;
|
|
200
|
+
parts?: Record<string, number>;
|
|
201
|
+
credit?: string;
|
|
202
|
+
};
|
|
203
|
+
/** Numeric decoded-audio region; encoded guard/delay/padding never count as music time. */
|
|
204
|
+
export type AudioRegion = {
|
|
205
|
+
sourceSampleRate: number;
|
|
206
|
+
cycleFrames: number;
|
|
207
|
+
contentStartFrame: number;
|
|
208
|
+
contentFrames: number;
|
|
209
|
+
decodedFrames: number;
|
|
210
|
+
encoderDelayFrames: number;
|
|
211
|
+
paddingFrames: number;
|
|
212
|
+
channels: number;
|
|
213
|
+
};
|
|
214
|
+
export type LocalArtifact = {
|
|
215
|
+
bytes: Uint8Array;
|
|
216
|
+
audio?: AudioRegion;
|
|
217
|
+
credit?: string;
|
|
218
|
+
license?: string;
|
|
219
|
+
};
|
|
220
|
+
export type LocalCompiler = {
|
|
221
|
+
requiresAttribution?: boolean;
|
|
222
|
+
version: string;
|
|
223
|
+
mime: string;
|
|
224
|
+
timeoutMs?: number;
|
|
225
|
+
inspect?: (input: string, ctx: {
|
|
226
|
+
directory: string;
|
|
227
|
+
}) => Promise<LocalResourceInfo>;
|
|
228
|
+
persistent?: boolean;
|
|
229
|
+
estimate?: (input: string) => {
|
|
230
|
+
credits: number;
|
|
231
|
+
};
|
|
232
|
+
compile(input: string, ctx: {
|
|
233
|
+
directory: string;
|
|
234
|
+
projectDir?: string;
|
|
235
|
+
keys: Readonly<Record<string, string>>; /** Writable cache private to this plugin: JOPLO_HOME/plugins/<plugin>/cache. Never the whole JOPLO_HOME (other plugins' keys live there). */
|
|
236
|
+
cacheDir: string;
|
|
237
|
+
allowSpend?: boolean;
|
|
238
|
+
maxBytes: number;
|
|
239
|
+
}): Promise<Uint8Array | LocalArtifact> | Uint8Array | LocalArtifact;
|
|
240
|
+
};
|
|
241
|
+
/** Local-only credential metadata. Never put secret values in this declaration. */
|
|
242
|
+
export type PluginKey = {
|
|
243
|
+
id: string;
|
|
244
|
+
title: string;
|
|
245
|
+
description: string;
|
|
246
|
+
url: string;
|
|
247
|
+
env: string;
|
|
248
|
+
};
|
|
249
|
+
export type PluginLocal = {
|
|
250
|
+
compilers: Record<string, LocalCompiler>;
|
|
251
|
+
};
|
|
252
|
+
export type MediaCommand = {
|
|
253
|
+
track: string;
|
|
254
|
+
action: 'play';
|
|
255
|
+
resource: string;
|
|
256
|
+
offsetMs?: number;
|
|
257
|
+
volume?: number;
|
|
258
|
+
loop?: boolean;
|
|
259
|
+
fadeMs?: number;
|
|
260
|
+
} | {
|
|
261
|
+
track: string;
|
|
262
|
+
action: 'stop';
|
|
263
|
+
fadeMs?: number;
|
|
264
|
+
};
|
|
265
|
+
/** Full state at a step boundary; elapsed time is in unscaled engine milliseconds. */
|
|
266
|
+
export type MediaSnapshot = Record<string, {
|
|
267
|
+
plugin: string;
|
|
268
|
+
resource: string;
|
|
269
|
+
offsetMs: number;
|
|
270
|
+
startOffsetMs?: number;
|
|
271
|
+
volume: number;
|
|
272
|
+
loop: boolean;
|
|
273
|
+
fadeInMs: number;
|
|
274
|
+
stopAfterMs?: number;
|
|
275
|
+
}>;
|
|
276
|
+
export type MediaDriver = {
|
|
277
|
+
update(frame: {
|
|
278
|
+
offsetMs: number;
|
|
279
|
+
volume: number;
|
|
280
|
+
loop: boolean;
|
|
281
|
+
speed: number;
|
|
282
|
+
playing: boolean;
|
|
283
|
+
}): void;
|
|
284
|
+
destroy(): void;
|
|
285
|
+
};
|
|
286
|
+
export type MediaFactory = (ctx: {
|
|
287
|
+
audio: AudioContext;
|
|
288
|
+
destination: AudioNode;
|
|
289
|
+
bytes: Uint8Array;
|
|
290
|
+
audioInfo?: AudioRegion;
|
|
291
|
+
}) => MediaDriver | Promise<MediaDriver>;
|
|
292
|
+
export type PluginDataSchema = {
|
|
293
|
+
safeParse(value: unknown): {
|
|
294
|
+
success: boolean;
|
|
295
|
+
error?: {
|
|
296
|
+
message: string;
|
|
297
|
+
};
|
|
298
|
+
};
|
|
299
|
+
};
|
|
300
|
+
/** Paths are segment arrays; * visits array items/object values, never their keys. */
|
|
301
|
+
export type PluginScopeRule = {
|
|
302
|
+
path: string[];
|
|
303
|
+
kind: 'map' | 'items' | 'values' | 'reference';
|
|
304
|
+
domain?: 'element' | 'scene';
|
|
305
|
+
prefix?: string;
|
|
306
|
+
references?: string[][];
|
|
307
|
+
children?: PluginScopeRule[];
|
|
308
|
+
};
|
|
309
|
+
export type PluginSlotSpec = {
|
|
310
|
+
text?: string[][];
|
|
311
|
+
scope?: 'global' | PluginScopeRule[];
|
|
312
|
+
};
|
|
313
|
+
export type PluginDataSpec = {
|
|
314
|
+
node?: PluginSlotSpec;
|
|
315
|
+
step?: PluginSlotSpec;
|
|
316
|
+
};
|
|
317
|
+
/** Literal properties on any author element; DOM names must belong to this plugin's data-jp-<id>- namespace. */
|
|
318
|
+
export type PluginPropertySpec = {
|
|
319
|
+
type: 'string' | 'number' | 'boolean';
|
|
320
|
+
attribute?: string;
|
|
321
|
+
min?: number;
|
|
322
|
+
max?: number;
|
|
323
|
+
nonempty?: boolean;
|
|
324
|
+
/** 字符串属性的可选值(预设名,D92):作者写了别的值时 check 报 PLUGIN_PROPERTY_INVALID 并列出可选值。 */
|
|
325
|
+
values?: string[];
|
|
326
|
+
};
|
|
327
|
+
export type PluginWrite = {
|
|
328
|
+
path: string;
|
|
329
|
+
value: unknown;
|
|
330
|
+
};
|
|
331
|
+
/** Data-only action contract. Payload fields are exact; numeric tolerance is used only for gestures. */
|
|
332
|
+
export type PluginActionSpec = {
|
|
333
|
+
caption: string;
|
|
334
|
+
durationMs: number;
|
|
335
|
+
fields: Record<string, {
|
|
336
|
+
type: 'string' | 'number' | 'boolean';
|
|
337
|
+
min?: number;
|
|
338
|
+
max?: number;
|
|
339
|
+
tolerance?: number;
|
|
340
|
+
text?: boolean;
|
|
341
|
+
}>;
|
|
342
|
+
targets?: string[];
|
|
343
|
+
};
|
|
344
|
+
export type PluginDef = {
|
|
345
|
+
actions?: Record<string, PluginActionSpec>;
|
|
346
|
+
/** Theme name → CSS source. Host publishes them as <plugin>:<name>. */
|
|
347
|
+
themes?: Record<string, string>;
|
|
348
|
+
/** Compile-time literal properties; copied to resolved DOM anchors by the host. */
|
|
349
|
+
properties?: Record<string, PluginPropertySpec>;
|
|
350
|
+
kind: 'plugin';
|
|
351
|
+
data?: PluginDataSpec;
|
|
352
|
+
compile?: PluginCompileHooks;
|
|
353
|
+
schemas?: {
|
|
354
|
+
node?: PluginDataSchema;
|
|
355
|
+
step?: PluginDataSchema;
|
|
356
|
+
};
|
|
357
|
+
/** 小写字母开头,组件类型名为 `<id>:<组件名>`,例如 scene3d:Scene。 */
|
|
358
|
+
id: string;
|
|
359
|
+
apiVersion: typeof PLUGIN_API_VERSION;
|
|
360
|
+
title: string;
|
|
361
|
+
description?: string;
|
|
362
|
+
/** 插件包的版本(展示用)。 */
|
|
363
|
+
version?: string;
|
|
364
|
+
components: Record<string, PluginComponentSpec>;
|
|
365
|
+
/** 给 Agent 读的用法(Markdown):何时用、怎么写、和步骤怎样配合、常见的坑。 */
|
|
366
|
+
skill?: string;
|
|
367
|
+
/** Additional versioned agent guides, keyed by topic. No runtime/IR content. */
|
|
368
|
+
skillTopics?: Record<string, {
|
|
369
|
+
description: string;
|
|
370
|
+
body: string;
|
|
371
|
+
}>;
|
|
372
|
+
/** Published author package; used for discovery and missing-plugin recovery. */
|
|
373
|
+
packageName?: string;
|
|
374
|
+
/** 运行时入口的绝对路径(definePlugin 接受 `new URL('./runtime.js', import.meta.url)`)。 */
|
|
375
|
+
runtime: string;
|
|
376
|
+
/** Node-only entry; excluded from browser bundles and IR. */
|
|
377
|
+
local?: string;
|
|
378
|
+
/** Host resolves only these keys for this plugin’s local compiler, after spending permission. */
|
|
379
|
+
keys?: readonly PluginKey[];
|
|
380
|
+
};
|
|
381
|
+
/** 插件入口:返回清单与编译钩子。id、组件名、接口版本不对时直接抛错(启用插件时就能看到)。 */
|
|
382
|
+
export declare function definePlugin(p: Omit<PluginDef, 'kind' | 'runtime' | 'apiVersion' | 'local'> & {
|
|
383
|
+
apiVersion?: typeof PLUGIN_API_VERSION;
|
|
384
|
+
runtime: string | URL;
|
|
385
|
+
local?: string | URL;
|
|
386
|
+
}): PluginDef;
|
|
387
|
+
export declare const isPluginDef: (v: unknown) => v is PluginDef;
|
|
388
|
+
/** 组件类型名:`<插件 id>:<组件名>`。 */
|
|
389
|
+
export declare const pluginType: (pluginId: string, name: string) => string;
|
|
390
|
+
type Marker = (props: JoploProps) => any;
|
|
391
|
+
/** 插件组件的 JSX 标记:`export const Scene3D = Object.assign(pluginComponent(plugin, 'Scene'), { Target: pluginComponent(plugin, 'Target') })`。 */
|
|
392
|
+
export declare function pluginComponent(plugin: PluginDef, name: string): Marker;
|
|
393
|
+
/** 插件组件在画面里的一个元素(根或子元素),属性已按当前状态取值。 */
|
|
394
|
+
export type PluginNode = {
|
|
395
|
+
id: string;
|
|
396
|
+
/** 完整类型名,例如 scene3d:Target。 */
|
|
397
|
+
type: string;
|
|
398
|
+
/** 插件里的组件名,例如 Target。 */
|
|
399
|
+
name: string;
|
|
400
|
+
props: Record<string, unknown>;
|
|
401
|
+
label: string;
|
|
402
|
+
/** when 条件此刻是否成立(不成立的子元素也会给出,插件决定隐藏还是淡出)。 */
|
|
403
|
+
visible: boolean;
|
|
404
|
+
disabled: boolean;
|
|
405
|
+
disabledReason: string | null;
|
|
406
|
+
interactive: boolean;
|
|
407
|
+
/** 放在代表这个元素的 DOM 锚点上(data-jid 等),引擎靠它定位与检查。 */
|
|
408
|
+
attrs: Record<string, string>;
|
|
409
|
+
children: PluginNode[];
|
|
410
|
+
ext?: Record<string, unknown>;
|
|
411
|
+
};
|
|
412
|
+
/** Browser input carries data only. A recognizer reports intent; the engine decides what it means. */
|
|
413
|
+
export type ActionGesture = {
|
|
414
|
+
type: 'click';
|
|
415
|
+
} | {
|
|
416
|
+
type: 'type' | 'select';
|
|
417
|
+
value: string;
|
|
418
|
+
} | {
|
|
419
|
+
type: 'toggle';
|
|
420
|
+
value: boolean;
|
|
421
|
+
} | {
|
|
422
|
+
type: 'drag' | 'scroll';
|
|
423
|
+
to: string | {
|
|
424
|
+
x: number;
|
|
425
|
+
y: number;
|
|
426
|
+
};
|
|
427
|
+
} | {
|
|
428
|
+
type: 'hover';
|
|
429
|
+
ms: number;
|
|
430
|
+
} | {
|
|
431
|
+
type: 'plugin';
|
|
432
|
+
name: string;
|
|
433
|
+
data: Record<string, unknown>;
|
|
434
|
+
};
|
|
435
|
+
export type AudienceAction = ActionGesture & {
|
|
436
|
+
target: string;
|
|
437
|
+
};
|
|
438
|
+
export type EngineFrame = Readonly<{
|
|
439
|
+
timeMs: number;
|
|
440
|
+
elapsedMs: number;
|
|
441
|
+
rawMs: number;
|
|
442
|
+
running: boolean;
|
|
443
|
+
speed: number;
|
|
444
|
+
paused?: boolean;
|
|
445
|
+
}>;
|
|
446
|
+
export type ActionPresentation = {
|
|
447
|
+
action: import('./index.js').StepDef['action'];
|
|
448
|
+
progress: number;
|
|
449
|
+
};
|
|
450
|
+
export type ActionDispatch = (id: string, action: ActionGesture, native?: AudienceAction) => void;
|
|
451
|
+
/** 演示此刻的情况:只读。 */
|
|
452
|
+
export type PluginFrame = {
|
|
453
|
+
/** Only time source for demonstrations. Missing in old hosts; draw the final state then. */
|
|
454
|
+
clock?: EngineFrame;
|
|
455
|
+
gesture?: ActionPresentation | null;
|
|
456
|
+
playground?: boolean;
|
|
457
|
+
/** Changes when local view state must be discarded (play, jump, reset, scene change). */
|
|
458
|
+
resetKey?: string;
|
|
459
|
+
/** Viewer inputs on this stage so far (D92). When it changes, settle in-flight presentation (enter/exit, overlays) before the input is handled; an ordinary pause from player controls does not change it. Missing in old hosts. */
|
|
460
|
+
inputs?: number;
|
|
461
|
+
/** demo = 体验与播放;review = 审阅(点击用于检查元素)。 */
|
|
462
|
+
mode: string;
|
|
463
|
+
/** false:截图、导出、跳转,直接画到终点,不播放过渡。 */
|
|
464
|
+
animate: boolean;
|
|
465
|
+
scenarioId: string;
|
|
466
|
+
/** Fully qualified stage identity; element ids are only unique inside this stage. */
|
|
467
|
+
sceneId: string;
|
|
468
|
+
/** 已经执行的步数。 */
|
|
469
|
+
position: number;
|
|
470
|
+
/** 镜头此刻对准的元素 id;null = 没有聚焦。 */
|
|
471
|
+
focus: readonly string[] | null;
|
|
472
|
+
/** 下一步要操作的元素 id(手动体验时可以提示观众);null = 没有。 */
|
|
473
|
+
nextTarget: string | null;
|
|
474
|
+
selectedId: string | null;
|
|
475
|
+
/** 当前主题名;主题变化时插件应重新读取 css() 的颜色。 */
|
|
476
|
+
theme: string;
|
|
477
|
+
};
|
|
478
|
+
export type ComponentCtx = {
|
|
479
|
+
node: PluginNode;
|
|
480
|
+
/** 未解析的 IR 节点(几何与容器组合使用)。 */
|
|
481
|
+
model: PluginIRNode;
|
|
482
|
+
/** 当前步骤编译好的插件快照(第 0 步取 scenario.ext)。 */
|
|
483
|
+
ext: Readonly<Record<string, unknown>>;
|
|
484
|
+
/** React 容器可直接返回子节点;nodes 按 id 选择 model 子树(含文本节点);传入 container 时由宿主 portal 渲染。 */
|
|
485
|
+
renderChildren: (nodes?: readonly Pick<PluginNode, 'id'>[], container?: Element) => any;
|
|
486
|
+
frame: PluginFrame;
|
|
487
|
+
/** 读取主题变量,例如 css('--jp-ink')、css('--jp-accent')。 */
|
|
488
|
+
css: (name: string) => string;
|
|
489
|
+
/** 观众点了某个子元素(例如 3D 物体):和点 DOM 元素一样交给引擎判断。坐标是视口坐标(MouseEvent.clientX/Y);altKey 照抄指针事件(⌥+单击 = 检查元素)。 */
|
|
490
|
+
act?: ActionDispatch;
|
|
491
|
+
/** Report the pointer's raycast hit (null on leave). The host owns declared hover dwell and playback gating. */
|
|
492
|
+
hover?: (id: string | null) => void;
|
|
493
|
+
click: (id: string, at?: {
|
|
494
|
+
clientX: number;
|
|
495
|
+
clientY: number;
|
|
496
|
+
altKey?: boolean;
|
|
497
|
+
}) => void;
|
|
498
|
+
/** 截图、导出前要等待的工作(加载模型、首帧渲染):返回一个 done 函数,完成后调用。 */
|
|
499
|
+
hold: () => () => void;
|
|
500
|
+
};
|
|
501
|
+
export type ComponentInstance = {
|
|
502
|
+
update(ctx: ComponentCtx): void;
|
|
503
|
+
destroy(): void;
|
|
504
|
+
};
|
|
505
|
+
export type RuntimeComponent = {
|
|
506
|
+
mount(el: HTMLElement, ctx: ComponentCtx): ComponentInstance;
|
|
507
|
+
react?: never;
|
|
508
|
+
} | {
|
|
509
|
+
react: (props: {
|
|
510
|
+
ctx: ComponentCtx;
|
|
511
|
+
}) => any;
|
|
512
|
+
mount?: never;
|
|
513
|
+
};
|
|
514
|
+
/** Runs after the host commits a stage layout. Read-only drawing data, never state transitions. */
|
|
515
|
+
export type PluginObservation = {
|
|
516
|
+
frame: PluginFrame;
|
|
517
|
+
ext: Readonly<Record<string, unknown>>;
|
|
518
|
+
};
|
|
519
|
+
export type PluginObserver = {
|
|
520
|
+
update(context: PluginObservation): void;
|
|
521
|
+
destroy(): void;
|
|
522
|
+
};
|
|
523
|
+
export type PluginObserve = (root: HTMLElement, context: PluginObservation) => PluginObserver;
|
|
524
|
+
/** Browser-only viewport decoration; no playback state or authoring code. */
|
|
525
|
+
export type ViewportDecoration = {
|
|
526
|
+
insets: {
|
|
527
|
+
x: number;
|
|
528
|
+
y: number;
|
|
529
|
+
};
|
|
530
|
+
size(width: number, height: number): {
|
|
531
|
+
width: number;
|
|
532
|
+
height: number;
|
|
533
|
+
};
|
|
534
|
+
react: import('react').ComponentType<{
|
|
535
|
+
width: number;
|
|
536
|
+
height: number;
|
|
537
|
+
scale?: number;
|
|
538
|
+
seed?: string;
|
|
539
|
+
children?: import('react').ReactNode;
|
|
540
|
+
}>;
|
|
541
|
+
};
|
|
542
|
+
export type PluginRuntime = {
|
|
543
|
+
id: string;
|
|
544
|
+
apiVersion: typeof PLUGIN_API_VERSION;
|
|
545
|
+
components: Record<string, RuntimeComponent>;
|
|
546
|
+
viewports?: Record<string, ViewportDecoration>;
|
|
547
|
+
media?: MediaFactory;
|
|
548
|
+
observe?: PluginObserve;
|
|
549
|
+
};
|
|
550
|
+
/** 插件运行时:mount 适配框架无关渲染;react 接收 ctx,由宿主 React 树渲染。 */
|
|
551
|
+
export declare function defineRuntime(r: {
|
|
552
|
+
id: string;
|
|
553
|
+
apiVersion?: typeof PLUGIN_API_VERSION;
|
|
554
|
+
components: Record<string, RuntimeComponent>;
|
|
555
|
+
viewports?: Record<string, ViewportDecoration>;
|
|
556
|
+
media?: MediaFactory;
|
|
557
|
+
observe?: PluginObserve;
|
|
558
|
+
}): PluginRuntime;
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 插件(D87):社区维护的 npm 包,给 Joplo 增加组件。引擎(步骤、状态、镜头、提示、朗读、导出、发布)不变,
|
|
3
|
+
* 插件只负责“这个组件长什么样、观众怎么和它互动”。一个插件包有两部分:
|
|
4
|
+
*
|
|
5
|
+
* 1. 入口(Node 端载入,编译钩子只在编译期运行):`definePlugin({...})` 的清单、组件标记、给 Agent 读的技能正文。
|
|
6
|
+
* 作者在 joplo.config.ts 写 `plugins: [scene3d]` 启用;`npx joplo skill <插件 id>` 输出它的技能。
|
|
7
|
+
* 2. 运行时(浏览器端):`defineRuntime({...})`,看板、截图、导出视频与发布站载入,负责把组件画出来。
|
|
8
|
+
* 运行时支持 mount 或 React 组件;React 共享宿主实例,其余依赖(例如 three)自行打包,发布站内联。
|
|
9
|
+
*
|
|
10
|
+
* 不变量(插件与引擎的契约):
|
|
11
|
+
* - 业务状态只由引擎的步骤推进;插件只读 ctx,不能改状态。观众在插件里点了什么,调用 ctx.click(id),
|
|
12
|
+
* 和点 DOM 元素一样交给引擎判断(这一步该不该点、点了发生什么)。
|
|
13
|
+
* - 能被步骤、镜头、提示、圈注、检查引用的子元素,都要在 DOM 里放一个锚点,带上 node.attrs(data-jid 等)
|
|
14
|
+
* 并摆在它在画面上的位置;引擎的光标、镜头、聚光、圈注、⌥+单击检查都按锚点定位。
|
|
15
|
+
* - 同一个 ctx 画出的结果相同(截图、视频可复现);frame.animate 为 false 时不播放过渡;
|
|
16
|
+
* 资源没准备好时用 ctx.hold() 让截图等待。
|
|
17
|
+
*/
|
|
18
|
+
import { component } from "./node.js";
|
|
19
|
+
/** 插件接口版本:v2 宿主同时兼容 v1 的 mount 运行时。 */
|
|
20
|
+
export const PLUGIN_API_VERSION = 2;
|
|
21
|
+
const ID = /^[a-z][a-z0-9-]*$/;
|
|
22
|
+
const NAME = /^[A-Za-z][A-Za-z0-9]*(\.[A-Za-z][A-Za-z0-9]*)*$/;
|
|
23
|
+
export const pluginEffect = (plugin, name, payload) => ({ kind: 'effect', type: 'plugin', plugin, name, payload });
|
|
24
|
+
export const localResource = (plugin, compiler, input) => ({ kind: 'local-resource', plugin, compiler, input });
|
|
25
|
+
function fileOf(u) {
|
|
26
|
+
const s = typeof u === 'string' ? u : u.href;
|
|
27
|
+
if (!s.startsWith('file:'))
|
|
28
|
+
return s;
|
|
29
|
+
const p = decodeURIComponent(new URL(s).pathname);
|
|
30
|
+
return /^\/[A-Za-z]:\//.test(p) ? p.slice(1) : p;
|
|
31
|
+
}
|
|
32
|
+
/** 插件入口:返回清单与编译钩子。id、组件名、接口版本不对时直接抛错(启用插件时就能看到)。 */
|
|
33
|
+
export function definePlugin(p) {
|
|
34
|
+
if (!ID.test(p.id))
|
|
35
|
+
throw new Error(`Joplo plugin id "${p.id}" must be lowercase letters, digits, and -, starting with a letter`);
|
|
36
|
+
if (p.apiVersion !== undefined && p.apiVersion !== PLUGIN_API_VERSION)
|
|
37
|
+
throw new Error(`Joplo plugin ${p.id} targets plugin API ${p.apiVersion}; this Joplo supports ${PLUGIN_API_VERSION}`);
|
|
38
|
+
if (p.keys) {
|
|
39
|
+
const ids = new Set();
|
|
40
|
+
for (const key of p.keys) {
|
|
41
|
+
if (!ID.test(key.id) || ids.has(key.id) || !key.title?.trim() || !key.description?.trim() || !/^[A-Z][A-Z0-9_]*$/.test(key.env) || !/^https:\/\//.test(key.url))
|
|
42
|
+
throw new Error(`Plugin ${p.id}: invalid key declaration`);
|
|
43
|
+
ids.add(key.id);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (p.skillTopics)
|
|
47
|
+
for (const [key, topic] of Object.entries(p.skillTopics)) {
|
|
48
|
+
if (!/^[a-z][a-z0-9-]*$/.test(key) || !topic || typeof topic.description !== 'string' || !topic.description.trim() || typeof topic.body !== 'string' || !topic.body.trim())
|
|
49
|
+
throw new Error(`Plugin ${p.id}: invalid skill topic ${key}`);
|
|
50
|
+
}
|
|
51
|
+
if (p.packageName && !/^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+$/.test(p.packageName))
|
|
52
|
+
throw new Error(`Plugin ${p.id}: invalid author package name`);
|
|
53
|
+
for (const [name, spec] of Object.entries(p.components)) {
|
|
54
|
+
if (!NAME.test(name) || /^[a-z]/.test(name) && spec.intrinsic !== name)
|
|
55
|
+
throw new Error(`Joplo plugin ${p.id}: component name "${name}" must be PascalCase (dots for compound parts)`);
|
|
56
|
+
if (spec.parent !== undefined && !p.components[spec.parent])
|
|
57
|
+
throw new Error(`Joplo plugin ${p.id}: ${name}.parent "${spec.parent}" is not a component of this plugin`);
|
|
58
|
+
}
|
|
59
|
+
return { ...p, kind: 'plugin', apiVersion: PLUGIN_API_VERSION, runtime: fileOf(p.runtime), local: p.local ? fileOf(p.local) : undefined };
|
|
60
|
+
}
|
|
61
|
+
export const isPluginDef = (v) => typeof v === 'object' && v !== null && v.kind === 'plugin' && typeof v.id === 'string';
|
|
62
|
+
/** 组件类型名:`<插件 id>:<组件名>`。 */
|
|
63
|
+
export const pluginType = (pluginId, name) => `${pluginId}:${name}`;
|
|
64
|
+
/** 插件组件的 JSX 标记:`export const Scene3D = Object.assign(pluginComponent(plugin, 'Scene'), { Target: pluginComponent(plugin, 'Target') })`。 */
|
|
65
|
+
export function pluginComponent(plugin, name) {
|
|
66
|
+
if (!plugin.components[name])
|
|
67
|
+
throw new Error(`Joplo plugin ${plugin.id} has no component ${name}`);
|
|
68
|
+
return component(pluginType(plugin.id, name), plugin.packageName);
|
|
69
|
+
}
|
|
70
|
+
/** 插件运行时:mount 适配框架无关渲染;react 接收 ctx,由宿主 React 树渲染。 */
|
|
71
|
+
export function defineRuntime(r) {
|
|
72
|
+
return { ...r, apiVersion: PLUGIN_API_VERSION };
|
|
73
|
+
}
|
package/dist/props.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Bind, CondExpr, JChild } from './node.js';
|
|
2
|
+
type Responsive<T> = T | {
|
|
3
|
+
base?: T;
|
|
4
|
+
xs?: T;
|
|
5
|
+
sm?: T;
|
|
6
|
+
md?: T;
|
|
7
|
+
lg?: T;
|
|
8
|
+
xl?: T;
|
|
9
|
+
};
|
|
10
|
+
type Size = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
11
|
+
export type JoploProps = {
|
|
12
|
+
id?: string;
|
|
13
|
+
when?: Bind | CondExpr;
|
|
14
|
+
disabled?: boolean | Bind | CondExpr;
|
|
15
|
+
/** 字面量,或绑定状态(disabledReason={$.ui.sendHint}),和 disabled 一样跟着状态变。 */
|
|
16
|
+
disabledReason?: string | Bind;
|
|
17
|
+
unmodeled?: boolean;
|
|
18
|
+
note?: string;
|
|
19
|
+
/** 敏感信息(D70):内容模糊显示、布局不变;可以写条件(redact={not($.ui.revealed)}),点“显示”后再看清。 */
|
|
20
|
+
redact?: boolean | Bind | CondExpr;
|
|
21
|
+
visibleFrom?: Size;
|
|
22
|
+
hiddenFrom?: Size;
|
|
23
|
+
/** 逃生口:Tailwind 类名。优先使用布局组件与样式属性。 */
|
|
24
|
+
className?: string;
|
|
25
|
+
children?: JChild;
|
|
26
|
+
[prop: string]: unknown;
|
|
27
|
+
};
|
|
28
|
+
export type { Responsive };
|
package/dist/props.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|