@joplo-app/core 0.7.1 → 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.
- package/dist/agent-skill.d.ts +1 -1
- package/dist/agent-skill.js +2 -0
- package/dist/compile.js +182 -9
- package/dist/guide.js +55 -12
- package/dist/load.d.ts +3 -1
- package/dist/load.js +14 -4
- package/dist/media.js +9 -1
- package/dist/outline.d.ts +5 -0
- package/dist/outline.js +2 -1
- package/dist/playground.d.ts +6 -1
- package/dist/playground.js +23 -2
- package/dist/plugins/compiler.d.ts +16 -0
- package/dist/plugins/compiler.js +48 -12
- package/dist/schema.d.ts +63 -0
- package/dist/schema.js +5 -0
- package/dist/scope.js +5 -0
- package/dist/step-plan.d.ts +6 -0
- package/dist/step-plan.js +19 -4
- package/dist/validate.js +5 -0
- package/dist/voice.d.ts +1 -0
- package/dist/voice.js +4 -4
- package/package.json +2 -2
package/dist/plugins/compiler.js
CHANGED
|
@@ -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,10 @@ 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', 'oneShot', 'durationMs'].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)
|
|
23
27
|
&& (value.oneShot === undefined || typeof value.oneShot === 'boolean')
|
|
24
28
|
&& (value.durationMs === undefined || typeof value.durationMs === 'number' && Number.isFinite(value.durationMs) && value.durationMs > 0)
|
|
25
29
|
&& (!value.oneShot || value.loop !== true && typeof value.durationMs === 'number' && value.durationMs > (typeof value.offsetMs === 'number' ? value.offsetMs : 0))
|
|
@@ -57,6 +61,26 @@ export class PluginCompiler {
|
|
|
57
61
|
const request = this.resourceRequests.get(id);
|
|
58
62
|
return this.options.resourceInfo?.[id] ?? (request ? this.options.resourceInfoFor?.(request) : undefined);
|
|
59
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
|
+
}
|
|
60
84
|
defs = new Map();
|
|
61
85
|
info = {};
|
|
62
86
|
constructor(configured, report, source, options = {}) {
|
|
@@ -198,9 +222,11 @@ export class PluginCompiler {
|
|
|
198
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);
|
|
199
223
|
}
|
|
200
224
|
}
|
|
201
|
-
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);
|
|
202
228
|
if (Array.isArray(value))
|
|
203
|
-
return value.map(v => this.resourceProps(v, source));
|
|
229
|
+
return value.map(v => this.resourceProps(v, source, context));
|
|
204
230
|
if (!object(value))
|
|
205
231
|
return value;
|
|
206
232
|
if (value.kind === 'local-resource') {
|
|
@@ -220,7 +246,7 @@ export class PluginCompiler {
|
|
|
220
246
|
}
|
|
221
247
|
return `joplo-resource:${id}`;
|
|
222
248
|
}
|
|
223
|
-
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' : '')])) };
|
|
224
250
|
}
|
|
225
251
|
node(node, ids) {
|
|
226
252
|
node = { ...node, props: this.resourceProps(node.props, node.source) };
|
|
@@ -356,6 +382,7 @@ export class PluginCompiler {
|
|
|
356
382
|
frames(project) {
|
|
357
383
|
// 接力(flow({ from }),D92):先算被接力的一章,下一章第 0 步继承它结尾的配乐(推进它最后一步的停留估算)
|
|
358
384
|
const ended = new Map();
|
|
385
|
+
const retiringKeys = new Set();
|
|
359
386
|
const order = [];
|
|
360
387
|
const visit = (sc, seen = new Set()) => {
|
|
361
388
|
if (order.includes(sc) || seen.has(sc.id))
|
|
@@ -393,16 +420,20 @@ export class PluginCompiler {
|
|
|
393
420
|
for (const [eventIndex, c] of (this.mediaCommands.get(sc.steps[i - 1].id) ?? []).entries()) {
|
|
394
421
|
const key = `${c.plugin}:${c.track}${c.action === 'play' && c.oneShot ? `@${sc.steps[i - 1].id}:${eventIndex}` : ''}`;
|
|
395
422
|
const current = media[key];
|
|
396
|
-
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) {
|
|
397
424
|
// 同一首再 play:继续播放(含取消正在进行的淡出),只更新音量与循环
|
|
398
|
-
const { stopAfterMs: _fading, ...kept } = current;
|
|
399
|
-
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 } : {}) };
|
|
400
427
|
}
|
|
401
428
|
else if (c.action === 'play') {
|
|
402
429
|
// 换曲:有 fadeMs 时旧曲换到「轨道>旧资源」键上同时淡出,与新曲交叉,中间没有静音
|
|
403
|
-
if (current && c.fadeMs)
|
|
404
|
-
|
|
405
|
-
|
|
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) } : {}) };
|
|
406
437
|
}
|
|
407
438
|
else {
|
|
408
439
|
for (const k of Object.keys(media))
|
|
@@ -413,6 +444,11 @@ export class PluginCompiler {
|
|
|
413
444
|
delete media[k];
|
|
414
445
|
}
|
|
415
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
|
+
}
|
|
416
452
|
}
|
|
417
453
|
}
|
|
418
454
|
if (hasMedia)
|
|
@@ -421,7 +457,7 @@ export class PluginCompiler {
|
|
|
421
457
|
const frozenState = snapshot(state), frozenPrevious = snapshot(previousState);
|
|
422
458
|
for (const p of this.defs.values()) {
|
|
423
459
|
if (p.compile?.frame) {
|
|
424
|
-
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));
|
|
425
461
|
if (value !== undefined)
|
|
426
462
|
ext[p.id] = value;
|
|
427
463
|
}
|
package/dist/schema.d.ts
CHANGED
|
@@ -231,6 +231,11 @@ 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;
|
|
@@ -243,6 +248,11 @@ export declare const Step: z.ZodObject<{
|
|
|
243
248
|
resource: z.ZodString;
|
|
244
249
|
offsetMs: z.ZodNumber;
|
|
245
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>;
|
|
246
256
|
volume: z.ZodNumber;
|
|
247
257
|
loop: z.ZodBoolean;
|
|
248
258
|
fadeInMs: z.ZodNumber;
|
|
@@ -411,6 +421,17 @@ export declare const Step: z.ZodObject<{
|
|
|
411
421
|
sayRole: z.ZodOptional<z.ZodString>;
|
|
412
422
|
narrate: z.ZodOptional<z.ZodString>;
|
|
413
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>>;
|
|
414
435
|
systemLead: z.ZodOptional<z.ZodNumber>;
|
|
415
436
|
source: z.ZodOptional<z.ZodString>;
|
|
416
437
|
}, z.core.$strict>;
|
|
@@ -426,6 +447,11 @@ export declare const Scenario: z.ZodObject<{
|
|
|
426
447
|
resource: z.ZodString;
|
|
427
448
|
offsetMs: z.ZodNumber;
|
|
428
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>;
|
|
429
455
|
volume: z.ZodNumber;
|
|
430
456
|
loop: z.ZodBoolean;
|
|
431
457
|
fadeInMs: z.ZodNumber;
|
|
@@ -461,6 +487,11 @@ export declare const Scenario: z.ZodObject<{
|
|
|
461
487
|
resource: z.ZodString;
|
|
462
488
|
offsetMs: z.ZodNumber;
|
|
463
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>;
|
|
464
495
|
volume: z.ZodNumber;
|
|
465
496
|
loop: z.ZodBoolean;
|
|
466
497
|
fadeInMs: z.ZodNumber;
|
|
@@ -629,6 +660,17 @@ export declare const Scenario: z.ZodObject<{
|
|
|
629
660
|
sayRole: z.ZodOptional<z.ZodString>;
|
|
630
661
|
narrate: z.ZodOptional<z.ZodString>;
|
|
631
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>>;
|
|
632
674
|
systemLead: z.ZodOptional<z.ZodNumber>;
|
|
633
675
|
source: z.ZodOptional<z.ZodString>;
|
|
634
676
|
}, z.core.$strict>>>;
|
|
@@ -1368,6 +1410,11 @@ export declare const Project: z.ZodObject<{
|
|
|
1368
1410
|
resource: z.ZodString;
|
|
1369
1411
|
offsetMs: z.ZodNumber;
|
|
1370
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>;
|
|
1371
1418
|
volume: z.ZodNumber;
|
|
1372
1419
|
loop: z.ZodBoolean;
|
|
1373
1420
|
fadeInMs: z.ZodNumber;
|
|
@@ -1403,6 +1450,11 @@ export declare const Project: z.ZodObject<{
|
|
|
1403
1450
|
resource: z.ZodString;
|
|
1404
1451
|
offsetMs: z.ZodNumber;
|
|
1405
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>;
|
|
1406
1458
|
volume: z.ZodNumber;
|
|
1407
1459
|
loop: z.ZodBoolean;
|
|
1408
1460
|
fadeInMs: z.ZodNumber;
|
|
@@ -1571,6 +1623,17 @@ export declare const Project: z.ZodObject<{
|
|
|
1571
1623
|
sayRole: z.ZodOptional<z.ZodString>;
|
|
1572
1624
|
narrate: z.ZodOptional<z.ZodString>;
|
|
1573
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>>;
|
|
1574
1637
|
systemLead: z.ZodOptional<z.ZodNumber>;
|
|
1575
1638
|
source: z.ZodOptional<z.ZodString>;
|
|
1576
1639
|
}, z.core.$strict>>>;
|
package/dist/schema.js
CHANGED
|
@@ -113,6 +113,7 @@ 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
|
+
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(),
|
|
116
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({
|
|
@@ -163,6 +164,10 @@ export const Step = z.strictObject({
|
|
|
163
164
|
narrate: z.string().min(1).optional(),
|
|
164
165
|
/** Explicit silence from narrate(false); suppresses narration, dialogue and caption fallback. */
|
|
165
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(),
|
|
166
171
|
/** System-step lead before commit, in milliseconds. */
|
|
167
172
|
systemLead: z.number().int().min(0).max(30_000).optional(),
|
|
168
173
|
source: Source,
|
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) => {
|
package/dist/step-plan.d.ts
CHANGED
|
@@ -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 = {
|
|
@@ -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
|
|
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
|
-
|
|
73
|
-
|
|
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
|
@@ -38,12 +38,12 @@ export function spokenLine(step, caption, speaker) {
|
|
|
38
38
|
if (step.mute)
|
|
39
39
|
return { text: '', role: null };
|
|
40
40
|
if (step.narrate?.trim())
|
|
41
|
-
return { text: step.narrate.trim(), role: null };
|
|
41
|
+
return { text: step.narrate.trim(), role: null, ...(step.audio ? { audio: step.audio } : {}) };
|
|
42
42
|
if (step.say?.trim())
|
|
43
|
-
return { text: step.say.trim(), role: speaker };
|
|
43
|
+
return { text: step.say.trim(), role: speaker, ...(step.audio ? { audio: step.audio } : {}) };
|
|
44
44
|
if (step.action.type === 'card')
|
|
45
|
-
return { text: joinSpoken([step.action.title, step.action.sub]), role: null };
|
|
46
|
-
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 } : {}) };
|
|
47
47
|
}
|
|
48
48
|
/** 这一步要读的文字(不关心是谁读)。 */
|
|
49
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.7.
|
|
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.7.
|
|
38
|
+
"@joplo-app/kit": "0.7.2",
|
|
39
39
|
"zod": "4.6.7"
|
|
40
40
|
},
|
|
41
41
|
"engines": {
|