@joplo-app/kit 0.3.0 → 0.4.1

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.js CHANGED
@@ -14,6 +14,10 @@ const MIME = {
14
14
  webp: 'image/webp',
15
15
  avif: 'image/avif',
16
16
  svg: 'image/svg+xml',
17
+ // 媒体插件(D96 / D98):视频片段与 Lottie 动画 JSON
18
+ mp4: 'video/mp4',
19
+ webm: 'video/webm',
20
+ json: 'application/json',
17
21
  };
18
22
  /** 单个文件的上限:再大会拖慢看板加载并撑大发布包,应先压缩。 */
19
23
  export const ASSET_MAX_BYTES = 2 * 1024 * 1024;
package/dist/plugin.d.ts CHANGED
@@ -164,7 +164,8 @@ export type PluginCompileHooks = {
164
164
  references?: string[];
165
165
  writes?: PluginWrite[];
166
166
  directorTarget?: string;
167
- media?: MediaCommand[];
167
+ media?: MediaCommand[]; /** 这一步至少停留多久(引擎毫秒,0–60000,D98):逐字打代码、播放片段等比阅读更长的效果。 */
168
+ holdMs?: number;
168
169
  } | void;
169
170
  /** 编译器回放基础效果后,计算第 0 步及每一步的完整绘制快照。 */
170
171
  frame?: (ctx: {
@@ -328,6 +329,13 @@ export type PluginWrite = {
328
329
  path: string;
329
330
  value: unknown;
330
331
  };
332
+ /** 发布素材(D98):构建时 IR 里的 data URL 素材写成 ./assets/<sha256>.<扩展名>,页面按相对路径引用。 */
333
+ export declare const SITE_ASSET_PREFIX = "./assets/";
334
+ /**
335
+ * src 是不是作者用 asset() 嵌入的素材(不是随手写的远程地址):data URL、看板的本机素材地址(/__joplo/p/<项目>/binary/…),
336
+ * 或构建产物里的素材文件(./assets/<sha256>.<扩展名>)。kind 限定类型。是就原样返回 src,否则 null。
337
+ */
338
+ export declare function embeddedAsset(src: unknown, kind?: 'image' | 'model' | 'audio' | 'video' | 'json'): string | null;
331
339
  /** Data-only action contract. Payload fields are exact; numeric tolerance is used only for gestures. */
332
340
  export type PluginActionSpec = {
333
341
  caption: string;
package/dist/plugin.js CHANGED
@@ -22,6 +22,28 @@ const ID = /^[a-z][a-z0-9-]*$/;
22
22
  const NAME = /^[A-Za-z][A-Za-z0-9]*(\.[A-Za-z][A-Za-z0-9]*)*$/;
23
23
  export const pluginEffect = (plugin, name, payload) => ({ kind: 'effect', type: 'plugin', plugin, name, payload });
24
24
  export const localResource = (plugin, compiler, input) => ({ kind: 'local-resource', plugin, compiler, input });
25
+ /** 发布素材(D98):构建时 IR 里的 data URL 素材写成 ./assets/<sha256>.<扩展名>,页面按相对路径引用。 */
26
+ export const SITE_ASSET_PREFIX = './assets/';
27
+ const ASSET_KIND_EXT = { image: ['png', 'jpg', 'gif', 'webp', 'svg', 'avif'], model: ['glb'], audio: ['mp3', 'wav', 'ogg', 'flac', 'm4a', 'aac'], video: ['mp4', 'webm'], json: ['json'] };
28
+ const ASSET_KIND_MIME = { image: /^image\//, model: /^model\/gltf-binary$/, audio: /^audio\//, video: /^video\//, json: /^application\/json$/ };
29
+ /**
30
+ * src 是不是作者用 asset() 嵌入的素材(不是随手写的远程地址):data URL、看板的本机素材地址(/__joplo/p/<项目>/binary/…),
31
+ * 或构建产物里的素材文件(./assets/<sha256>.<扩展名>)。kind 限定类型。是就原样返回 src,否则 null。
32
+ */
33
+ export function embeddedAsset(src, kind) {
34
+ if (typeof src !== 'string' || !src)
35
+ return null;
36
+ const data = /^data:([a-z0-9.+/-]+)[;,]/i.exec(src);
37
+ if (data)
38
+ return !kind || ASSET_KIND_MIME[kind].test(data[1].toLowerCase()) ? src : null;
39
+ const file = /^(?:\.\/assets\/[0-9a-f]{64}|\/__joplo\/p\/[^/]+\/binary\/[0-9a-f]{64})\.([a-z0-9]+)$/.exec(src);
40
+ if (!file)
41
+ return null;
42
+ const ext = file[1];
43
+ if (src.startsWith('/__joplo/') && ext === 'audio')
44
+ return !kind || kind === 'audio' ? src : null;
45
+ return !kind || ASSET_KIND_EXT[kind].includes(ext) ? src : null;
46
+ }
25
47
  function fileOf(u) {
26
48
  const s = typeof u === 'string' ? u : u.href;
27
49
  if (!s.startsWith('file:'))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joplo-app/kit",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "Joplo 创作 SDK:组件、feature/option/flow 与 JSX 运行时(收集成数据,不作为 React 执行)",
5
5
  "license": "PolyForm-Shield-1.0.0",
6
6
  "type": "module",