@joplo-app/kit 0.6.1 → 0.7.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 CHANGED
@@ -1,4 +1,17 @@
1
1
  /** 单个文件的上限:再大会拖慢看板加载并撑大发布包,应先压缩。 */
2
2
  export declare const ASSET_MAX_BYTES: number;
3
+ /** Node-only provenance captured while loading author modules; never serialized into playback IR. */
4
+ export type AssetLoad = {
5
+ file: string;
6
+ source?: string;
7
+ mime: string;
8
+ bytes: number;
9
+ data: string;
10
+ };
11
+ /** Async-local isolation prevents concurrent project reports from sharing paths or bytes. */
12
+ export declare function captureAssetLoads<T>(run: () => Promise<T>): Promise<{
13
+ value: T;
14
+ assets: AssetLoad[];
15
+ }>;
3
16
  /** 读入图片或二进制资源,返回 data URI(用于 <Image src={…}>,也可以写进 style 的 backgroundImage: `url(${asset(…)})`)。 */
4
17
  export declare function asset(path: string, from?: string): string;
package/dist/asset.js CHANGED
@@ -27,6 +27,18 @@ function builtin(name) {
27
27
  throw new Error('asset() runs while Joplo loads the project in Node (22.3 or newer)');
28
28
  return get(name);
29
29
  }
30
+ const CAPTURE = Symbol.for('joplo.asset.capture');
31
+ /** Async-local isolation prevents concurrent project reports from sharing paths or bytes. */
32
+ export async function captureAssetLoads(run) {
33
+ const globals = globalThis;
34
+ if (!globals[CAPTURE]) {
35
+ const { AsyncLocalStorage } = builtin('node:async_hooks');
36
+ globals[CAPTURE] = new AsyncLocalStorage();
37
+ }
38
+ const assets = [];
39
+ const value = await globals[CAPTURE].run(assets, run);
40
+ return { value, assets };
41
+ }
30
42
  /** 读入图片或二进制资源,返回 data URI(用于 <Image src={…}>,也可以写进 style 的 backgroundImage: `url(${asset(…)})`)。 */
31
43
  export function asset(path, from) {
32
44
  const fs = builtin('node:fs');
@@ -51,5 +63,7 @@ export function asset(path, from) {
51
63
  const limit = mime.startsWith('image/') ? ASSET_MAX_BYTES : 50 * 1024 * 1024;
52
64
  if (size > limit)
53
65
  throw new Error(`asset("${path}"): ${Math.round(size / 1024)} KB is over the ${limit / 1024 / 1024} MB limit; compress or resize the asset first`);
54
- return `data:${mime};base64,${Buffer.from(fs.readFileSync(file)).toString('base64')}`;
66
+ const data = `data:${mime};base64,${Buffer.from(fs.readFileSync(file)).toString('base64')}`;
67
+ globalThis[CAPTURE]?.getStore()?.push({ file, source: callsite(), mime, bytes: size, data });
68
+ return data;
55
69
  }
package/dist/index.d.ts CHANGED
@@ -11,9 +11,9 @@
11
11
  * 所有函数只返回数据;画板不会执行这些代码,只消费编译出的 IR。
12
12
  */
13
13
  import { type Bind, type CondExpr, type JNode } from './node.js';
14
- export { Custom, $, and, empty, eq, Fragment, neq, not, notEmpty, oneOf, or, Outlet, Slot } from './node.js';
14
+ export { isNode, isBind, bindPath, Custom, $, and, empty, eq, Fragment, neq, not, notEmpty, oneOf, or, Outlet, Slot } from './node.js';
15
15
  export type { Bind, CondExpr, JNode } from './node.js';
16
- export { asset } from './asset.js';
16
+ export { asset, captureAssetLoads, type AssetLoad } from './asset.js';
17
17
  import type { PluginDef } from './plugin.js';
18
18
  export type { PluginDef } from './plugin.js';
19
19
  type Json = string | number | boolean | null | Json[] | {
@@ -51,7 +51,10 @@ export type VoiceConfig = {
51
51
  */
52
52
  /** plugins(D86):启用的插件(npm 包的默认导出,`plugins: [scene3d]`(包 @joplo-app/plugin-3d 的默认导出));用法见 npx joplo skill <插件 id>。 */
53
53
  export type ConfigDef = {
54
- kind: 'config';
54
+ kind: 'config'; /** Project-relative output paths excluded from dev watching; restart dev after changing. */
55
+ watch?: {
56
+ ignore?: string[];
57
+ };
55
58
  name: string;
56
59
  description?: string;
57
60
  theme?: string;
@@ -240,7 +243,7 @@ export type EffectDef = {
240
243
  } | {
241
244
  kind: 'effect';
242
245
  type: 'narrate';
243
- text: string;
246
+ text: string | false;
244
247
  };
245
248
  /** 标注气泡放在目标的哪一侧;不写时自动选画面里放得下的一侧(右、左、下、上)。 */
246
249
  export type CalloutSide = 'top' | 'right' | 'bottom' | 'left';
@@ -293,7 +296,7 @@ export declare const explain: (text: string) => EffectDef;
293
296
  /**
294
297
  * 旁白(D74):讲解人用旁白的声音说的话,像在给同事介绍功能,不是把字幕念出来。和字幕分开存。
295
298
  * 朗读的优先级:narrate() > say()(角色台词)> 字幕(过渡卡读标题和副标题);explain 不读。字幕兜底时也用旁白的声音。
296
- * 自动播放会等它读完再进下一步。
299
+ * 自动播放会等它读完再进下一步。narrate(false) 显式静音整步(包括 say 与字幕兜底);空字符串不是静音。
297
300
  *
298
301
  * 写法(详见 npx joplo skill story 第 6 节):
299
302
  * - 一句只做一件事:交代、指点、承接或收束;说字幕说不出的意图、原因、结果,不重复字幕;
@@ -303,7 +306,7 @@ export declare const explain: (text: string) => EffectDef;
303
306
  * .click('share', '小雨把行程单分享给阿杰', narrate('行程用链接发给阿杰,他不用装 App。'))
304
307
  * .card('现在是阿杰', { role: 'ajie' }, narrate('换到阿杰这边,他只收到一条消息。'))
305
308
  */
306
- export declare const narrate: (text: string) => EffectDef;
309
+ export declare const narrate: (text: string | false) => EffectDef;
307
310
  /**
308
311
  * 角色台词(D74):这一步里角色亲口说的话,用这个角色的声音读(feature.roles 与层级的 role;没有角色时用旁白的声音)。
309
312
  * 写第一人称、像真人说话:.click('can_go', '阿杰回复:我能去', say('我能去!'))。
@@ -537,6 +540,10 @@ export type WorkDef = {
537
540
  kind: 'work';
538
541
  title: string;
539
542
  summary: string;
543
+ /** System-step lead before commit, in seconds (0–30); omitted preserves 0.9s. */
544
+ pace?: {
545
+ systemLead?: number;
546
+ };
540
547
  /** stage 与 layers 二选一。 */
541
548
  stage?: JNode;
542
549
  layers?: Record<string, LayerDef>;
package/dist/index.js CHANGED
@@ -11,8 +11,8 @@
11
11
  * 所有函数只返回数据;画板不会执行这些代码,只消费编译出的 IR。
12
12
  */
13
13
  import { bindPath, callsite, isBind } from "./node.js";
14
- export { Custom, $, and, empty, eq, Fragment, neq, not, notEmpty, oneOf, or, Outlet, Slot } from "./node.js";
15
- export { asset } from "./asset.js";
14
+ export { isNode, isBind, bindPath, Custom, $, and, empty, eq, Fragment, neq, not, notEmpty, oneOf, or, Outlet, Slot } from "./node.js";
15
+ export { asset, captureAssetLoads } from "./asset.js";
16
16
  export const config = (c) => ({ kind: 'config', ...c, source: callsite() });
17
17
  export const layout = (tree) => ({ kind: 'layout', tree, source: callsite() });
18
18
  export const page = (meta, tree) => ({
@@ -90,7 +90,7 @@ export const explain = (text) => ({ kind: 'effect', type: 'explain', text });
90
90
  /**
91
91
  * 旁白(D74):讲解人用旁白的声音说的话,像在给同事介绍功能,不是把字幕念出来。和字幕分开存。
92
92
  * 朗读的优先级:narrate() > say()(角色台词)> 字幕(过渡卡读标题和副标题);explain 不读。字幕兜底时也用旁白的声音。
93
- * 自动播放会等它读完再进下一步。
93
+ * 自动播放会等它读完再进下一步。narrate(false) 显式静音整步(包括 say 与字幕兜底);空字符串不是静音。
94
94
  *
95
95
  * 写法(详见 npx joplo skill story 第 6 节):
96
96
  * - 一句只做一件事:交代、指点、承接或收束;说字幕说不出的意图、原因、结果,不重复字幕;
package/dist/plugin.d.ts CHANGED
@@ -234,6 +234,7 @@ export type LocalResourceInfo = {
234
234
  durationMs?: number;
235
235
  markers?: Record<string, number>;
236
236
  parts?: Record<string, number>;
237
+ partDurationsMs?: Record<string, number>;
237
238
  credit?: string;
238
239
  };
239
240
  /** Numeric decoded-audio region; encoded guard/delay/padding never count as music time. */
@@ -289,6 +290,8 @@ export type MediaCommand = {
289
290
  track: string;
290
291
  action: 'play';
291
292
  resource: string;
293
+ oneShot?: boolean;
294
+ durationMs?: number;
292
295
  offsetMs?: number;
293
296
  volume?: number;
294
297
  loop?: boolean;
@@ -308,6 +311,7 @@ export type MediaSnapshot = Record<string, {
308
311
  loop: boolean;
309
312
  fadeInMs: number;
310
313
  stopAfterMs?: number;
314
+ endAfterMs?: number;
311
315
  }>;
312
316
  export type MediaDriver = {
313
317
  update(frame: {
@@ -428,6 +432,11 @@ export declare function definePlugin(p: Omit<PluginDef, 'kind' | 'runtime' | 'ap
428
432
  local?: string | URL;
429
433
  }): PluginDef;
430
434
  export declare const isPluginDef: (v: unknown) => v is PluginDef;
435
+ /**
436
+ * config({ plugins }) 的一项为什么不是可用的插件清单(#60);是合格的清单时返回 null。
437
+ * 报错点名第几项与它实际是什么:插件包的默认导出多数是清单,少数是工厂函数(例如 alda(scores)),忘了调用最常见。
438
+ */
439
+ export declare function pluginEntryProblem(v: unknown, index: number): string | null;
431
440
  /** 组件类型名:`<插件 id>:<组件名>`。 */
432
441
  export declare const pluginType: (pluginId: string, name: string) => string;
433
442
  type Marker = (props: JoploProps) => any;
package/dist/plugin.js CHANGED
@@ -81,6 +81,26 @@ export function definePlugin(p) {
81
81
  return { ...p, kind: 'plugin', apiVersion: PLUGIN_API_VERSION, runtime: fileOf(p.runtime), local: p.local ? fileOf(p.local) : undefined };
82
82
  }
83
83
  export const isPluginDef = (v) => typeof v === 'object' && v !== null && v.kind === 'plugin' && typeof v.id === 'string';
84
+ /**
85
+ * config({ plugins }) 的一项为什么不是可用的插件清单(#60);是合格的清单时返回 null。
86
+ * 报错点名第几项与它实际是什么:插件包的默认导出多数是清单,少数是工厂函数(例如 alda(scores)),忘了调用最常见。
87
+ */
88
+ export function pluginEntryProblem(v, index) {
89
+ const at = `config.plugins[${index}]`;
90
+ if (typeof v === 'function') {
91
+ const name = v.name;
92
+ const call = typeof name === 'string' && /^[A-Za-z_$][\w$]*$/.test(name) ? `${name}(…)` : 'the factory with its options';
93
+ return `${at} is a function${typeof name === 'string' && name ? ` (${name})` : ''}, not a plugin manifest. This plugin's default export is a factory: call it, e.g. plugins: [${call}] (npx joplo skill plugins)`;
94
+ }
95
+ if (typeof v !== 'object' || v === null)
96
+ return `${at} is ${v === null ? 'null' : typeof v}, not a plugin manifest; list the plugin packages' default exports (npx joplo skill plugins)`;
97
+ const p = v;
98
+ if (p.kind !== 'plugin' || typeof p.id !== 'string')
99
+ return `${at} is an object that is not a Joplo plugin manifest (manifests come from a plugin package's default export, made with definePlugin)`;
100
+ if (p.apiVersion !== PLUGIN_API_VERSION)
101
+ return `${at} (${p.id}) targets plugin API ${String(p.apiVersion)}; this Joplo supports API ${PLUGIN_API_VERSION}. Update the plugin package to the same version as joplo`;
102
+ return null;
103
+ }
84
104
  /** 组件类型名:`<插件 id>:<组件名>`。 */
85
105
  export const pluginType = (pluginId, name) => `${pluginId}:${name}`;
86
106
  /** 插件组件的 JSX 标记:`export const Scene3D = Object.assign(pluginComponent(plugin, 'Scene'), { Target: pluginComponent(plugin, 'Target') })`。 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joplo-app/kit",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Joplo 创作 SDK:用 work、切片与步骤编写可播放、可上手体验的作品;功能评审为作品添加方案比较、情况与规则;含 JSX 运行时(收集为数据,不作为 React 执行)",
5
5
  "license": "PolyForm-Shield-1.0.0",
6
6
  "type": "module",