@joplo-app/core 0.6.2 → 0.7.2

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.
@@ -1,12 +1,13 @@
1
1
  import { PluginAction } from "../schema.js";
2
2
  import { ElementTraitsSchema, InheritSchema, PluginInspectFieldSchema, PluginTextSchema } from "../traits.js";
3
3
  import { advanceMedia } from "../media.js";
4
+ import { clipKey } from "../voice.js";
4
5
  import { commitGapMs } from "../step-plan.js";
5
6
  import { jsonData, snapshot, object, strings, syncResult, authoringData, materialize, errorMessage } from "./data.js";
6
7
  /** Node-side plugin host. Callbacks never enter IR or the player. */
7
8
  import { isNode } from '@joplo-app/kit/node';
8
9
  import { pluginEntryProblem } from '@joplo-app/kit/plugin';
9
- import { initialState, applyStep, resolveProps } from "../player.js";
10
+ import { initialState, applyStep, resolveProps, isNodeVisible } from "../player.js";
10
11
  export function enabledPlugins(configured) {
11
12
  return Array.isArray(configured) ? configured : [];
12
13
  }
@@ -19,7 +20,13 @@ function validMediaCommand(value, plugin, owners) {
19
20
  return Object.keys(value).every(k => ['track', 'action', 'fadeMs'].includes(k));
20
21
  if (value.action !== 'play' || typeof value.resource !== 'string' || owners.get(value.resource) !== plugin)
21
22
  return false;
22
- return Object.keys(value).every(k => ['track', 'action', 'resource', 'volume', 'loop', 'fadeMs', 'offsetMs'].includes(k))
23
+ return Object.keys(value).every(k => ['track', 'action', 'resource', 'volume', 'loop', 'fadeMs', 'offsetMs', 'oneShot', 'durationMs', 'startDelayMs', 'duck', 'maxRetiring'].includes(k))
24
+ && (value.startDelayMs === undefined || typeof value.startDelayMs === 'number' && Number.isFinite(value.startDelayMs) && value.startDelayMs >= 0 && value.startDelayMs <= 60000)
25
+ && (value.duck === undefined || typeof value.duck === 'boolean')
26
+ && (value.maxRetiring === undefined || typeof value.maxRetiring === 'number' && Number.isSafeInteger(value.maxRetiring) && value.maxRetiring >= 0 && value.maxRetiring <= 32)
27
+ && (value.oneShot === undefined || typeof value.oneShot === 'boolean')
28
+ && (value.durationMs === undefined || typeof value.durationMs === 'number' && Number.isFinite(value.durationMs) && value.durationMs > 0)
29
+ && (!value.oneShot || value.loop !== true && typeof value.durationMs === 'number' && value.durationMs > (typeof value.offsetMs === 'number' ? value.offsetMs : 0))
23
30
  && (value.offsetMs === undefined || typeof value.offsetMs === 'number' && Number.isFinite(value.offsetMs) && value.offsetMs >= 0)
24
31
  && (value.volume === undefined || typeof value.volume === 'number' && value.volume >= 0 && value.volume <= 1)
25
32
  && (value.loop === undefined || typeof value.loop === 'boolean');
@@ -54,6 +61,26 @@ export class PluginCompiler {
54
61
  const request = this.resourceRequests.get(id);
55
62
  return this.options.resourceInfo?.[id] ?? (request ? this.options.resourceInfoFor?.(request) : undefined);
56
63
  }
64
+ embeddedAudio = {};
65
+ voiceDuration(stepId) { return this.options.voiceDurationFor?.(stepId); }
66
+ audioSource(value, source) {
67
+ if (typeof value === 'string' && /^data:audio\/[^;,]+;base64,[A-Za-z0-9+/=]+$/.test(value)) {
68
+ const id = `audio-${clipKey('embedded-audio', value)}`;
69
+ this.embeddedAudio[id] = value;
70
+ return `joplo-resource:${id}`;
71
+ }
72
+ const result = this.resourceProps(value, source);
73
+ if (typeof result !== 'string' || !/^joplo-resource:resource-\d+$/.test(result)) {
74
+ this.report('AUDIO_SOURCE_INVALID', 'Audio must be asset() audio data or a localResource() reference; paths and remote URLs are not implicit downloads', source);
75
+ return '';
76
+ }
77
+ return result;
78
+ }
79
+ audioDuration(source) {
80
+ const id = source.slice('joplo-resource:'.length);
81
+ const n = this.embeddedAudio[id] ? this.options.audioDurationFor?.(this.embeddedAudio[id]) : this.options.audioDurationFor?.(source) ?? this.infoOf(id)?.durationMs;
82
+ return typeof n === 'number' && Number.isFinite(n) && n > 0 ? n : undefined;
83
+ }
57
84
  defs = new Map();
58
85
  info = {};
59
86
  constructor(configured, report, source, options = {}) {
@@ -195,9 +222,11 @@ export class PluginCompiler {
195
222
  this.report('PLUGIN_PROPERTY_INVALID', `Plugin ${plugin.id}: ${key} requires a literal ${spec.type}${spec.min !== undefined ? ` >= ${spec.min}` : ''}${spec.max !== undefined ? ` <= ${spec.max}` : ''}${spec.nonempty ? ' (nonempty)' : ''}${spec.values ? ` (one of ${spec.values.join(', ')})` : ''}`, node.source);
196
223
  }
197
224
  }
198
- resourceProps(value, source) {
225
+ resourceProps(value, source, context = '') {
226
+ if (typeof value === 'string' && (context === 'url' && value === '[object Object]' || context === 'css' && /url\(\s*["']?\[object Object\]["']?\s*\)/i.test(value)))
227
+ this.report('LOCAL_RESOURCE_STRINGIFIED', 'A resource URL contains [object Object]: an object was interpolated into a string. Pass localResource(...) directly to a resource-aware prop; resource references cannot be embedded in CSS strings.', source);
199
228
  if (Array.isArray(value))
200
- return value.map(v => this.resourceProps(v, source));
229
+ return value.map(v => this.resourceProps(v, source, context));
201
230
  if (!object(value))
202
231
  return value;
203
232
  if (value.kind === 'local-resource') {
@@ -217,7 +246,7 @@ export class PluginCompiler {
217
246
  }
218
247
  return `joplo-resource:${id}`;
219
248
  }
220
- return { ...value, ...Object.fromEntries(Object.entries(value).map(([k, v]) => [k, this.resourceProps(v, source)])) };
249
+ return { ...value, ...Object.fromEntries(Object.entries(value).map(([k, v]) => [k, this.resourceProps(v, source, context === 'css' || k === 'style' ? 'css' : ['src', 'href', 'poster'].includes(k) ? 'url' : '')])) };
221
250
  }
222
251
  node(node, ids) {
223
252
  node = { ...node, props: this.resourceProps(node.props, node.source) };
@@ -353,6 +382,7 @@ export class PluginCompiler {
353
382
  frames(project) {
354
383
  // 接力(flow({ from }),D92):先算被接力的一章,下一章第 0 步继承它结尾的配乐(推进它最后一步的停留估算)
355
384
  const ended = new Map();
385
+ const retiringKeys = new Set();
356
386
  const order = [];
357
387
  const visit = (sc, seen = new Set()) => {
358
388
  if (order.includes(sc) || seen.has(sc.id))
@@ -387,19 +417,23 @@ export class PluginCompiler {
387
417
  if (i) {
388
418
  // 配乐锚点:上一次提交(i = 1 时是场景开始)到这一步提交之间的计划时长(stepPlan:停留 / 朗读估算 + 这一步的操作演示)
389
419
  media = advanceMedia(media, commitGapMs(project, sc.steps, i - 2));
390
- for (const c of this.mediaCommands.get(sc.steps[i - 1].id) ?? []) {
391
- const key = `${c.plugin}:${c.track}`;
420
+ for (const [eventIndex, c] of (this.mediaCommands.get(sc.steps[i - 1].id) ?? []).entries()) {
421
+ const key = `${c.plugin}:${c.track}${c.action === 'play' && c.oneShot ? `@${sc.steps[i - 1].id}:${eventIndex}` : ''}`;
392
422
  const current = media[key];
393
- if (c.action === 'play' && current?.resource === c.resource && c.offsetMs === undefined) {
423
+ if (c.action === 'play' && current?.resource === c.resource && c.offsetMs === undefined && c.startDelayMs === undefined) {
394
424
  // 同一首再 play:继续播放(含取消正在进行的淡出),只更新音量与循环
395
- const { stopAfterMs: _fading, ...kept } = current;
396
- media[key] = { ...kept, volume: c.volume ?? 1, loop: c.loop ?? false };
425
+ const { stopAfterMs: _fading, duck: _duck, maxRetiring: _limit, ...kept } = current;
426
+ media[key] = { ...kept, volume: c.volume ?? 1, loop: c.loop ?? false, ...(c.duck !== undefined ? { duck: c.duck } : {}), ...(c.maxRetiring !== undefined ? { maxRetiring: c.maxRetiring } : {}) };
397
427
  }
398
428
  else if (c.action === 'play') {
399
429
  // 换曲:有 fadeMs 时旧曲换到「轨道>旧资源」键上同时淡出,与新曲交叉,中间没有静音
400
- if (current && c.fadeMs)
401
- media[`${key}>${current.resource}`] = { ...current, stopAfterMs: Math.min(current.stopAfterMs ?? c.fadeMs, c.fadeMs) };
402
- media[key] = { plugin: c.plugin, resource: c.resource, offsetMs: c.offsetMs ?? 0, ...(c.offsetMs !== undefined ? { startOffsetMs: c.offsetMs } : {}), volume: c.volume ?? 1, loop: c.loop ?? false, fadeInMs: c.fadeMs ?? 0 };
430
+ if (current && c.fadeMs) {
431
+ const old = `${key}>${current.resource}`;
432
+ const retiring = retiringKeys.has(old) ? `${old}@${sc.steps[i - 1].id}:${eventIndex}` : old;
433
+ retiringKeys.add(old);
434
+ media[retiring] = { ...current, stopAfterMs: Math.min(current.stopAfterMs ?? c.fadeMs, c.fadeMs) };
435
+ }
436
+ media[key] = { plugin: c.plugin, resource: c.resource, offsetMs: c.offsetMs ?? 0, ...(c.startDelayMs !== undefined ? { startDelayMs: c.startDelayMs, delayRemainingMs: c.startDelayMs, startEventId: `${sc.steps[i - 1].id}:${eventIndex}` } : {}), ...(c.duck !== undefined ? { duck: c.duck } : {}), ...(c.maxRetiring !== undefined ? { maxRetiring: c.maxRetiring } : {}), ...(c.offsetMs !== undefined ? { startOffsetMs: c.offsetMs } : {}), volume: c.volume ?? 1, loop: c.loop ?? false, fadeInMs: c.fadeMs ?? 0, ...(c.oneShot ? { endAfterMs: c.durationMs - (c.offsetMs ?? 0) } : {}) };
403
437
  }
404
438
  else {
405
439
  for (const k of Object.keys(media))
@@ -410,6 +444,11 @@ export class PluginCompiler {
410
444
  delete media[k];
411
445
  }
412
446
  }
447
+ if (c.action === 'play' && c.maxRetiring !== undefined) {
448
+ const retiring = Object.keys(media).filter(k => k.startsWith(`${key}>`));
449
+ for (const old of retiring.slice(0, Math.max(0, retiring.length - c.maxRetiring)))
450
+ delete media[old];
451
+ }
413
452
  }
414
453
  }
415
454
  if (hasMedia)
@@ -418,7 +457,7 @@ export class PluginCompiler {
418
457
  const frozenState = snapshot(state), frozenPrevious = snapshot(previousState);
419
458
  for (const p of this.defs.values()) {
420
459
  if (p.compile?.frame) {
421
- const value = this.run(p, 'frame', target.source, () => this.output(p, p.compile.frame({ roots, scenes, state: frozenState, previousState: frozenPrevious, resolveProps: (node, previous) => resolveProps(node, previous && frozenPrevious ? frozenPrevious : frozenState), data: snapshot(target.ext?.[p.id]), previousData: snapshot(previousData[p.id]), position: i, report: this.report }), target.source));
460
+ const value = this.run(p, 'frame', target.source, () => this.output(p, p.compile.frame({ roots, scenes, state: frozenState, previousState: frozenPrevious, resolveProps: (node, previous) => resolveProps(node, previous && frozenPrevious ? frozenPrevious : frozenState), isVisible: (sceneId, nodeId) => scenes.some(s => s.id === sceneId) && isNodeVisible(project.scenes[sceneId], nodeId, frozenState), data: snapshot(target.ext?.[p.id]), previousData: snapshot(previousData[p.id]), position: i, report: this.report }), target.source));
422
461
  if (value !== undefined)
423
462
  ext[p.id] = value;
424
463
  }
@@ -99,7 +99,7 @@ export function streamPlan(step, prev) {
99
99
  const before = prev ? readPath(prev, s.path) : undefined;
100
100
  const keep = typeof before === 'string' && before && s.value.startsWith(before) ? [...before].length : 0;
101
101
  const fresh = [...s.value].slice(keep).join('');
102
- const voiced = s.pace === 'voice' ? voicePacedMs(step?.narrate ?? step?.say) : 0;
102
+ const voiced = s.pace === 'voice' && !step?.mute ? voicePacedMs(step?.narrate ?? step?.say) : 0;
103
103
  return { path: s.path, value: s.value, keep, ms: fresh ? (voiced || streamMs(fresh)) : 0, ...(s.pace ? { pace: s.pace } : {}) };
104
104
  });
105
105
  }
package/dist/schema.d.ts CHANGED
@@ -231,10 +231,16 @@ export declare const MediaSnapshot: z.ZodRecord<z.ZodString, z.ZodObject<{
231
231
  resource: z.ZodString;
232
232
  offsetMs: z.ZodNumber;
233
233
  startOffsetMs: z.ZodOptional<z.ZodNumber>;
234
+ startDelayMs: z.ZodOptional<z.ZodNumber>;
235
+ delayRemainingMs: z.ZodOptional<z.ZodNumber>;
236
+ startEventId: z.ZodOptional<z.ZodString>;
237
+ duck: z.ZodOptional<z.ZodBoolean>;
238
+ maxRetiring: z.ZodOptional<z.ZodNumber>;
234
239
  volume: z.ZodNumber;
235
240
  loop: z.ZodBoolean;
236
241
  fadeInMs: z.ZodNumber;
237
242
  stopAfterMs: z.ZodOptional<z.ZodNumber>;
243
+ endAfterMs: z.ZodOptional<z.ZodNumber>;
238
244
  }, z.core.$strict>>;
239
245
  export declare const Step: z.ZodObject<{
240
246
  media: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
@@ -242,10 +248,16 @@ export declare const Step: z.ZodObject<{
242
248
  resource: z.ZodString;
243
249
  offsetMs: z.ZodNumber;
244
250
  startOffsetMs: z.ZodOptional<z.ZodNumber>;
251
+ startDelayMs: z.ZodOptional<z.ZodNumber>;
252
+ delayRemainingMs: z.ZodOptional<z.ZodNumber>;
253
+ startEventId: z.ZodOptional<z.ZodString>;
254
+ duck: z.ZodOptional<z.ZodBoolean>;
255
+ maxRetiring: z.ZodOptional<z.ZodNumber>;
245
256
  volume: z.ZodNumber;
246
257
  loop: z.ZodBoolean;
247
258
  fadeInMs: z.ZodNumber;
248
259
  stopAfterMs: z.ZodOptional<z.ZodNumber>;
260
+ endAfterMs: z.ZodOptional<z.ZodNumber>;
249
261
  }, z.core.$strict>>>;
250
262
  id: z.ZodString;
251
263
  key: z.ZodOptional<z.ZodString>;
@@ -408,6 +420,19 @@ export declare const Step: z.ZodObject<{
408
420
  say: z.ZodOptional<z.ZodString>;
409
421
  sayRole: z.ZodOptional<z.ZodString>;
410
422
  narrate: z.ZodOptional<z.ZodString>;
423
+ mute: z.ZodOptional<z.ZodLiteral<true>>;
424
+ audio: z.ZodOptional<z.ZodString>;
425
+ holdFor: z.ZodOptional<z.ZodObject<{
426
+ kind: z.ZodEnum<{
427
+ voice: "voice";
428
+ audio: "audio";
429
+ }>;
430
+ audio: z.ZodOptional<z.ZodString>;
431
+ padMs: z.ZodNumber;
432
+ durationMs: z.ZodOptional<z.ZodNumber>;
433
+ durationKey: z.ZodOptional<z.ZodString>;
434
+ }, z.core.$strict>>;
435
+ systemLead: z.ZodOptional<z.ZodNumber>;
411
436
  source: z.ZodOptional<z.ZodString>;
412
437
  }, z.core.$strict>;
413
438
  export declare const Scenario: z.ZodObject<{
@@ -422,10 +447,16 @@ export declare const Scenario: z.ZodObject<{
422
447
  resource: z.ZodString;
423
448
  offsetMs: z.ZodNumber;
424
449
  startOffsetMs: z.ZodOptional<z.ZodNumber>;
450
+ startDelayMs: z.ZodOptional<z.ZodNumber>;
451
+ delayRemainingMs: z.ZodOptional<z.ZodNumber>;
452
+ startEventId: z.ZodOptional<z.ZodString>;
453
+ duck: z.ZodOptional<z.ZodBoolean>;
454
+ maxRetiring: z.ZodOptional<z.ZodNumber>;
425
455
  volume: z.ZodNumber;
426
456
  loop: z.ZodBoolean;
427
457
  fadeInMs: z.ZodNumber;
428
458
  stopAfterMs: z.ZodOptional<z.ZodNumber>;
459
+ endAfterMs: z.ZodOptional<z.ZodNumber>;
429
460
  }, z.core.$strict>>>;
430
461
  ext: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
431
462
  id: z.ZodString;
@@ -456,10 +487,16 @@ export declare const Scenario: z.ZodObject<{
456
487
  resource: z.ZodString;
457
488
  offsetMs: z.ZodNumber;
458
489
  startOffsetMs: z.ZodOptional<z.ZodNumber>;
490
+ startDelayMs: z.ZodOptional<z.ZodNumber>;
491
+ delayRemainingMs: z.ZodOptional<z.ZodNumber>;
492
+ startEventId: z.ZodOptional<z.ZodString>;
493
+ duck: z.ZodOptional<z.ZodBoolean>;
494
+ maxRetiring: z.ZodOptional<z.ZodNumber>;
459
495
  volume: z.ZodNumber;
460
496
  loop: z.ZodBoolean;
461
497
  fadeInMs: z.ZodNumber;
462
498
  stopAfterMs: z.ZodOptional<z.ZodNumber>;
499
+ endAfterMs: z.ZodOptional<z.ZodNumber>;
463
500
  }, z.core.$strict>>>;
464
501
  id: z.ZodString;
465
502
  key: z.ZodOptional<z.ZodString>;
@@ -622,6 +659,19 @@ export declare const Scenario: z.ZodObject<{
622
659
  say: z.ZodOptional<z.ZodString>;
623
660
  sayRole: z.ZodOptional<z.ZodString>;
624
661
  narrate: z.ZodOptional<z.ZodString>;
662
+ mute: z.ZodOptional<z.ZodLiteral<true>>;
663
+ audio: z.ZodOptional<z.ZodString>;
664
+ holdFor: z.ZodOptional<z.ZodObject<{
665
+ kind: z.ZodEnum<{
666
+ voice: "voice";
667
+ audio: "audio";
668
+ }>;
669
+ audio: z.ZodOptional<z.ZodString>;
670
+ padMs: z.ZodNumber;
671
+ durationMs: z.ZodOptional<z.ZodNumber>;
672
+ durationKey: z.ZodOptional<z.ZodString>;
673
+ }, z.core.$strict>>;
674
+ systemLead: z.ZodOptional<z.ZodNumber>;
625
675
  source: z.ZodOptional<z.ZodString>;
626
676
  }, z.core.$strict>>>;
627
677
  expected: z.ZodDefault<z.ZodString>;
@@ -1360,10 +1410,16 @@ export declare const Project: z.ZodObject<{
1360
1410
  resource: z.ZodString;
1361
1411
  offsetMs: z.ZodNumber;
1362
1412
  startOffsetMs: z.ZodOptional<z.ZodNumber>;
1413
+ startDelayMs: z.ZodOptional<z.ZodNumber>;
1414
+ delayRemainingMs: z.ZodOptional<z.ZodNumber>;
1415
+ startEventId: z.ZodOptional<z.ZodString>;
1416
+ duck: z.ZodOptional<z.ZodBoolean>;
1417
+ maxRetiring: z.ZodOptional<z.ZodNumber>;
1363
1418
  volume: z.ZodNumber;
1364
1419
  loop: z.ZodBoolean;
1365
1420
  fadeInMs: z.ZodNumber;
1366
1421
  stopAfterMs: z.ZodOptional<z.ZodNumber>;
1422
+ endAfterMs: z.ZodOptional<z.ZodNumber>;
1367
1423
  }, z.core.$strict>>>;
1368
1424
  ext: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
1369
1425
  id: z.ZodString;
@@ -1394,10 +1450,16 @@ export declare const Project: z.ZodObject<{
1394
1450
  resource: z.ZodString;
1395
1451
  offsetMs: z.ZodNumber;
1396
1452
  startOffsetMs: z.ZodOptional<z.ZodNumber>;
1453
+ startDelayMs: z.ZodOptional<z.ZodNumber>;
1454
+ delayRemainingMs: z.ZodOptional<z.ZodNumber>;
1455
+ startEventId: z.ZodOptional<z.ZodString>;
1456
+ duck: z.ZodOptional<z.ZodBoolean>;
1457
+ maxRetiring: z.ZodOptional<z.ZodNumber>;
1397
1458
  volume: z.ZodNumber;
1398
1459
  loop: z.ZodBoolean;
1399
1460
  fadeInMs: z.ZodNumber;
1400
1461
  stopAfterMs: z.ZodOptional<z.ZodNumber>;
1462
+ endAfterMs: z.ZodOptional<z.ZodNumber>;
1401
1463
  }, z.core.$strict>>>;
1402
1464
  id: z.ZodString;
1403
1465
  key: z.ZodOptional<z.ZodString>;
@@ -1560,6 +1622,19 @@ export declare const Project: z.ZodObject<{
1560
1622
  say: z.ZodOptional<z.ZodString>;
1561
1623
  sayRole: z.ZodOptional<z.ZodString>;
1562
1624
  narrate: z.ZodOptional<z.ZodString>;
1625
+ mute: z.ZodOptional<z.ZodLiteral<true>>;
1626
+ audio: z.ZodOptional<z.ZodString>;
1627
+ holdFor: z.ZodOptional<z.ZodObject<{
1628
+ kind: z.ZodEnum<{
1629
+ voice: "voice";
1630
+ audio: "audio";
1631
+ }>;
1632
+ audio: z.ZodOptional<z.ZodString>;
1633
+ padMs: z.ZodNumber;
1634
+ durationMs: z.ZodOptional<z.ZodNumber>;
1635
+ durationKey: z.ZodOptional<z.ZodString>;
1636
+ }, z.core.$strict>>;
1637
+ systemLead: z.ZodOptional<z.ZodNumber>;
1563
1638
  source: z.ZodOptional<z.ZodString>;
1564
1639
  }, z.core.$strict>>>;
1565
1640
  expected: z.ZodDefault<z.ZodString>;
package/dist/schema.js CHANGED
@@ -113,7 +113,8 @@ export const CALLOUT_SIDES = ['top', 'right', 'bottom', 'left'];
113
113
  export const Callout = z.strictObject({ target: z.string().min(1), text: z.string().min(1), side: z.enum(CALLOUT_SIDES).optional() });
114
114
  export const MediaSnapshot = z.record(z.string(), z.strictObject({
115
115
  plugin: z.string().min(1), resource: z.string().min(1), offsetMs: z.number().nonnegative(), startOffsetMs: z.number().nonnegative().optional(),
116
- volume: z.number().min(0).max(1), loop: z.boolean(), fadeInMs: z.number().nonnegative(), stopAfterMs: z.number().nonnegative().optional(),
116
+ startDelayMs: z.number().min(0).max(60000).optional(), delayRemainingMs: z.number().min(0).max(60000).optional(), startEventId: z.string().min(1).optional(), duck: z.boolean().optional(), maxRetiring: z.number().int().min(0).max(32).optional(),
117
+ volume: z.number().min(0).max(1), loop: z.boolean(), fadeInMs: z.number().nonnegative(), stopAfterMs: z.number().nonnegative().optional(), endAfterMs: z.number().nonnegative().optional(),
117
118
  }));
118
119
  export const Step = z.strictObject({
119
120
  media: MediaSnapshot.optional(),
@@ -161,6 +162,14 @@ export const Step = z.strictObject({
161
162
  sayRole: z.string().min(1).optional(),
162
163
  /** 旁白(D74,来自 narrate()):用旁白的声音读,优先于台词和字幕;没有时省略。发布站保留。 */
163
164
  narrate: z.string().min(1).optional(),
165
+ /** Explicit silence from narrate(false); suppresses narration, dialogue and caption fallback. */
166
+ mute: z.literal(true).optional(),
167
+ /** Selected pre-existing narration/dialogue audio; never sent to a TTS provider. */
168
+ audio: z.string().regex(/^joplo-resource:[a-z0-9-]+$/).optional(),
169
+ /** Explicit audio-derived dwell. Duration excludes pad; absent duration means estimated. */
170
+ holdFor: z.strictObject({ kind: z.enum(['voice', 'audio']), audio: z.string().regex(/^joplo-resource:[a-z0-9-]+$/).optional(), padMs: z.number().finite().min(0).max(30000), durationMs: z.number().finite().positive().optional(), durationKey: z.string().min(1).optional() }).refine(h => h.kind === 'audio' ? !!h.audio : h.audio === undefined, 'audio-derived hold requires exactly its audio reference').refine(h => (h.durationMs === undefined) === (h.durationKey === undefined), 'measured duration requires a matching identity').optional(),
171
+ /** System-step lead before commit, in milliseconds. */
172
+ systemLead: z.number().int().min(0).max(30_000).optional(),
164
173
  source: Source,
165
174
  });
166
175
  export const Scenario = z.strictObject({
package/dist/scope.js CHANGED
@@ -152,6 +152,11 @@ export function scopeProject(project, scenarioIds, mode = project.mode === 'revi
152
152
  useScene(e.sceneId, sid);
153
153
  for (const l of Object.values(project.works[s.workId]?.layers ?? {}))
154
154
  useScene(l.sceneId, sid);
155
+ // 本地反应(元素 onClick 的 go)能到达的页面:观众接管后点得过去,范围发布也要带上
156
+ for (const r of Object.values(project.works[s.workId]?.free ?? {}))
157
+ for (const e of r.effects)
158
+ if (e.type === 'navigate')
159
+ useScene(e.sceneId, sid);
155
160
  }
156
161
  const borrowed = [];
157
162
  const entryOwnerOf = (workId) => {
@@ -32,6 +32,9 @@ export type StepPlan = {
32
32
  voiceMs: number;
33
33
  /** 这一步合计 = leadMs + max(dwellMs, voiceMs)。 */
34
34
  totalMs: number;
35
+ /** Explicit timing source, absent for legacy plans. */
36
+ timingSource?: 'measured' | 'estimated';
37
+ audioMs?: number;
35
38
  };
36
39
  export type StepPlanOptions = {
37
40
  /** 停留时要读的文字;缺省为 stepTexts(step)(英文兜底字幕)。界面传当前语言的字幕。 */
@@ -42,6 +45,9 @@ export type StepPlanOptions = {
42
45
  cursor?: boolean;
43
46
  /** 已经用提交前的状态算好的流式输出时长(D100);缺省按整段重新出估算。 */
44
47
  streamMs?: number;
48
+ audioDurationMs?: number;
49
+ /** Runtime is already waiting for actual narration.done; do not also wait its estimate. */
50
+ voiceActive?: boolean;
45
51
  };
46
52
  /** 一步停留时要读的文字:说明、explain,过渡卡再加副标题与要点。 */
47
53
  export declare function stepTexts(step: Pick<Step, 'caption' | 'explain' | 'action'>): (string | undefined)[];
package/dist/step-plan.js CHANGED
@@ -9,6 +9,7 @@
9
9
  */
10
10
  import { pluginActionSpec } from "./actions.js";
11
11
  import { CAMERA_MS, stepDwell, voiceMs } from "./pace.js";
12
+ import { VOICE_BREATH_MS, narrationText } from "./voice.js";
12
13
  import { streamPlan } from "./player.js";
13
14
  /** 操作演示各段的时长(引擎毫秒)。 */
14
15
  export const ACTION_TIMING = {
@@ -42,7 +43,7 @@ export function stepPlan(project, step, o = {}) {
42
43
  else if (a.type === 'press')
43
44
  gestureMs = reduced ? T.reducedStep : T.selectHold;
44
45
  else if (step.kind === 'system' || a.type === 'event')
45
- gestureMs = reduced ? T.reducedStep : T.systemHold;
46
+ gestureMs = step.systemLead ?? (reduced ? T.reducedStep : T.systemHold);
46
47
  else if (reduced)
47
48
  gestureMs = T.reducedStep;
48
49
  else if ('target' in a) {
@@ -65,14 +66,28 @@ export function stepPlan(project, step, o = {}) {
65
66
  rippleMs = T.ripple;
66
67
  const settleMs = cursor && !reduced ? T.afterStep : 0;
67
68
  const streamMs = o.streamMs ?? Math.max(0, ...streamPlan(step, null).map((x) => x.ms));
68
- const read = reduced
69
+ const dynamic = step.holdFor;
70
+ const read = dynamic ? Math.max(streamMs, step.shots.length > 0 || step.directorLayer ? CAMERA_MS + 200 : 0) : reduced
69
71
  ? T.reducedStep
70
72
  : stepDwell({ texts: o.texts ?? stepTexts(step), paced: step.hold !== undefined, cameraMoved: step.shots.length > 0 || !!step.directorLayer, streamMs });
71
73
  // hold 是看的时间,不是动画:减少动态效果时同样保留
72
- const dwellMs = Math.max(step.hold ?? 0, step.effectHold ?? 0, read, settleMs);
73
- const voice = voiceMs(step.narrate ?? step.say);
74
+ let dwellMs = Math.max(step.hold ?? 0, step.effectHold ?? 0, read, settleMs);
75
+ let voice = voiceMs(step.mute ? undefined : step.narrate ?? step.say);
76
+ let audioMs;
77
+ let timingSource;
78
+ if (dynamic) {
79
+ const measured = o.audioDurationMs ?? dynamic.durationMs;
80
+ timingSource = measured !== undefined ? 'measured' : 'estimated';
81
+ const estimate = Math.max(0, voiceMs(narrationText(step, step.caption)) - VOICE_BREATH_MS);
82
+ audioMs = (measured ?? estimate) + dynamic.padMs;
83
+ // voiceMs already includes the old breath: replace it, never add pad twice.
84
+ if (dynamic.kind === 'voice')
85
+ voice = step.mute || o.voiceActive ? 0 : audioMs;
86
+ }
87
+ if (dynamic)
88
+ dwellMs = Math.max(dwellMs, dynamic.kind === 'voice' && (step.mute || o.voiceActive) ? 0 : audioMs ?? 0);
74
89
  const leadMs = cursorMs + rippleMs + gestureMs;
75
- return { cursorMs, rippleMs, gestureMs, leadMs, settleMs, dwellMs, voiceMs: voice, totalMs: leadMs + Math.max(dwellMs, voice) };
90
+ return { cursorMs, rippleMs, gestureMs, leadMs, settleMs, dwellMs, voiceMs: voice, totalMs: leadMs + Math.max(dwellMs, voice), ...(timingSource ? { timingSource, audioMs } : {}) };
76
91
  }
77
92
  /** 一个场景按 1× 自动播放大约多久(毫秒):每一步 stepPlan 的合计之和。 */
78
93
  export function scenarioPlanMs(project, steps, texts) {
package/dist/validate.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { stepPlan } from "./step-plan.js";
1
2
  import { pluginSpec } from "./catalog.js";
2
3
  import { entryOf, playSequence, scenariosOf } from "./entries.js";
3
4
  import { featuresOf } from "./features.js";
@@ -195,6 +196,10 @@ export function validate(project, opts = { mode: 'all' }) {
195
196
  if (ms > SCENARIO_MS_MAX)
196
197
  emit('info', 'SCENARIO_TOO_LONG', `${chapter ?? 'Scenario'} "${sc.name}" plays about ${Math.round(ms / 1000)} s at 1× (${sc.steps.length} steps; recommended maximum: ${SCENARIO_MS_MAX / 1000} s). ${chapter ? 'One chapter tells one thing: split it into chapters' : 'One scenario tells one thing: split it into scenarios (for example the happy path and each recovery)'}, or branch with fork(); run npx joplo outline to see the pacing`, sc.source, sr);
197
198
  for (const st of sc.steps) {
199
+ if (st.holdFor) {
200
+ const timing = stepPlan(p, st);
201
+ emit('info', timing.timingSource === 'measured' ? 'AUDIO_TIMING_MEASURED' : 'AUDIO_TIMING_ESTIMATED', `${st.id}: ${timing.timingSource} ${st.holdFor.kind} timing, ${((timing.audioMs ?? 0) / 1000).toFixed(3)} s including ${(st.holdFor.padMs / 1000).toFixed(3)} s pad; no audio is generated by check`, st.source, sr);
202
+ }
198
203
  const value = { ...st, workId: sc.workId };
199
204
  ref(!stepIds.has(st.id), `Duplicate step ID: ${st.id}`, value, 'step');
200
205
  stepIds.add(st.id);
package/dist/voice.d.ts CHANGED
@@ -16,6 +16,7 @@ export declare function joinSpoken(parts: (string | null | undefined)[]): string
16
16
  export declare function spokenLine(step: Step, caption: string, speaker: string | null): {
17
17
  text: string;
18
18
  role: string | null;
19
+ audio?: string;
19
20
  };
20
21
  /** 这一步要读的文字(不关心是谁读)。 */
21
22
  export declare function narrationText(step: Step, caption: string): string;
package/dist/voice.js CHANGED
@@ -35,13 +35,15 @@ export function joinSpoken(parts) {
35
35
  * speaker 是这一步的说话角色(speakerRoleAt)。text 为空串表示这一步不读;role 为 null 表示旁白。
36
36
  */
37
37
  export function spokenLine(step, caption, speaker) {
38
+ if (step.mute)
39
+ return { text: '', role: null };
38
40
  if (step.narrate?.trim())
39
- return { text: step.narrate.trim(), role: null };
41
+ return { text: step.narrate.trim(), role: null, ...(step.audio ? { audio: step.audio } : {}) };
40
42
  if (step.say?.trim())
41
- return { text: step.say.trim(), role: speaker };
43
+ return { text: step.say.trim(), role: speaker, ...(step.audio ? { audio: step.audio } : {}) };
42
44
  if (step.action.type === 'card')
43
- return { text: joinSpoken([step.action.title, step.action.sub]), role: null };
44
- return { text: caption.trim(), role: null };
45
+ return { text: joinSpoken([step.action.title, step.action.sub]), role: null, ...(step.audio ? { audio: step.audio } : {}) };
46
+ return { text: caption.trim(), role: null, ...(step.audio ? { audio: step.audio } : {}) };
45
47
  }
46
48
  /** 这一步要读的文字(不关心是谁读)。 */
47
49
  export function narrationText(step, caption) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joplo-app/core",
3
- "version": "0.6.2",
3
+ "version": "0.7.2",
4
4
  "description": "Joplo 作品引擎:编译、校验与确定性播放,支持独立作品和功能方案评审",
5
5
  "license": "PolyForm-Shield-1.0.0",
6
6
  "type": "module",
@@ -35,7 +35,7 @@
35
35
  "dist"
36
36
  ],
37
37
  "dependencies": {
38
- "@joplo-app/kit": "0.6.2",
38
+ "@joplo-app/kit": "0.7.2",
39
39
  "zod": "4.6.7"
40
40
  },
41
41
  "engines": {