@joplo-app/core 0.2.18 → 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/actions.d.ts +6 -0
- package/dist/actions.js +34 -0
- package/dist/agent-skill.d.ts +9 -15
- package/dist/agent-skill.js +41 -44
- package/dist/auto-caption.d.ts +3 -0
- package/dist/auto-caption.js +33 -0
- package/dist/catalog.d.ts +39 -47
- package/dist/catalog.js +27 -334
- package/dist/compile.d.ts +2 -8
- package/dist/compile.js +230 -393
- package/dist/content-i18n.js +27 -16
- package/dist/feature-diff.d.ts +9 -9
- package/dist/feature-diff.js +28 -6
- package/dist/focus.d.ts +6 -2
- package/dist/focus.js +28 -36
- package/dist/guide.d.ts +10 -12
- package/dist/guide.js +372 -594
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/media.d.ts +10 -0
- package/dist/media.js +43 -0
- package/dist/node.d.ts +1 -2
- package/dist/node.js +1 -2
- package/dist/outline.js +1 -1
- package/dist/pace.d.ts +4 -1
- package/dist/pace.js +7 -3
- package/dist/player.d.ts +8 -41
- package/dist/player.js +83 -147
- package/dist/playground.d.ts +38 -0
- package/dist/playground.js +111 -0
- package/dist/plugin-data.d.ts +11 -0
- package/dist/plugin-data.js +96 -0
- package/dist/plugins/compiler.d.ts +67 -0
- package/dist/plugins/compiler.js +434 -0
- package/dist/plugins/data.d.ts +12 -0
- package/dist/plugins/data.js +120 -0
- package/dist/result.d.ts +1 -1
- package/dist/result.js +1 -0
- package/dist/runtime.d.ts +22 -0
- package/dist/runtime.js +18 -0
- package/dist/schema.d.ts +593 -112
- package/dist/schema.js +62 -52
- package/dist/scope.js +14 -5
- package/dist/step-identity.d.ts +1 -1
- package/dist/step-identity.js +1 -1
- package/dist/themes.d.ts +7 -0
- package/dist/themes.js +5 -0
- package/dist/traits.d.ts +7 -0
- package/dist/traits.js +26 -0
- package/dist/validate.js +17 -4
- package/package.json +7 -4
- package/dist/diagram/elk.d.ts +0 -6
- package/dist/diagram/elk.js +0 -56
- package/dist/diagram/graph-layout.d.ts +0 -123
- package/dist/diagram/graph-layout.js +0 -620
- package/dist/diagram/index.d.ts +0 -41
- package/dist/diagram/index.js +0 -92
- package/dist/diagram/model.d.ts +0 -217
- package/dist/diagram/model.js +0 -189
- package/dist/diagram/sequence-layout.d.ts +0 -12
- package/dist/diagram/sequence-layout.js +0 -185
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/** D88: interaction semantics are data-only. The timeline is never mutated by this module. */
|
|
2
|
+
import { actionMatches, pluginActionSpec } from "./actions.js";
|
|
3
|
+
import { applyStep, checkStep, choicesOf, explainClick, findNode, initialState, isNodeDisabled, isNodeVisible, resolveValue, sceneOfTarget } from "./player.js";
|
|
4
|
+
import { matchChoice } from "./catalog.js";
|
|
5
|
+
export { actionMatches, pluginActionSpec, validActionData } from "./actions.js";
|
|
6
|
+
/** Index only positions whose prefix replays and whose action is available there. */
|
|
7
|
+
export function actionIndex(project, optionId) {
|
|
8
|
+
const entries = [];
|
|
9
|
+
for (const sc of Object.values(project.scenarios)) {
|
|
10
|
+
if (sc.optionId !== optionId)
|
|
11
|
+
continue;
|
|
12
|
+
try {
|
|
13
|
+
let state = initialState(project, sc.id);
|
|
14
|
+
for (const [position, step] of sc.steps.entries()) {
|
|
15
|
+
if (step.kind === 'user' && 'target' in step.action && !checkStep(project, sc, state, step)) {
|
|
16
|
+
const scene = sceneOfTarget(project, sc, state, step.action.target);
|
|
17
|
+
if (scene)
|
|
18
|
+
entries.push({ scenarioId: sc.id, position, sceneId: scene.id, action: step.action });
|
|
19
|
+
}
|
|
20
|
+
state = applyStep(project, sc, state);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch { /* No entries beyond an invalid prefix. */ }
|
|
24
|
+
}
|
|
25
|
+
return entries;
|
|
26
|
+
}
|
|
27
|
+
function canonicalAction(action, scene, state) {
|
|
28
|
+
if (action.type !== 'select' || !scene)
|
|
29
|
+
return action;
|
|
30
|
+
const node = findNode(scene, action.target)?.node;
|
|
31
|
+
const choices = node && choicesOf(node, state);
|
|
32
|
+
return choices ? { ...action, value: matchChoice(choices, action.value)?.value ?? action.value } : action;
|
|
33
|
+
}
|
|
34
|
+
function nativeEffects(scene, state, action) {
|
|
35
|
+
if (!('target' in action) || !('value' in action))
|
|
36
|
+
return [];
|
|
37
|
+
const node = findNode(scene, action.target)?.node;
|
|
38
|
+
const native = node?.traits?.native;
|
|
39
|
+
if (!node || !native || native.action !== action.type || isNodeDisabled(node, state) || !isNodeVisible(scene, node.id, state))
|
|
40
|
+
return [];
|
|
41
|
+
let value = action.value;
|
|
42
|
+
if (action.type === 'select') {
|
|
43
|
+
const choices = choicesOf(node, state);
|
|
44
|
+
if (choices && !matchChoice(choices, action.value))
|
|
45
|
+
return [];
|
|
46
|
+
value = choices ? matchChoice(choices, action.value).value : action.value;
|
|
47
|
+
const current = state.inputs[node.id] ?? resolveValue(node.props?.[native.prop] ?? node.props?.defaultValue, state);
|
|
48
|
+
if (node.traits?.input === 'multiple' || resolveValue(node.props?.multiple, state) === true) {
|
|
49
|
+
const list = Array.isArray(current) ? current : [];
|
|
50
|
+
value = list.includes(value) ? list.filter(v => v !== value) : [...list, value];
|
|
51
|
+
}
|
|
52
|
+
else if (native.deselect && current === value)
|
|
53
|
+
value = null;
|
|
54
|
+
}
|
|
55
|
+
const effects = [{ type: 'set', path: `inputs.${node.id}`, value }];
|
|
56
|
+
const binding = node.props?.[native.prop];
|
|
57
|
+
if (typeof binding === 'string' && /^\$(ui|data|inputs)\.[A-Za-z0-9_.-]+$/.test(binding))
|
|
58
|
+
effects.push({ type: 'set', path: binding.slice(1), value });
|
|
59
|
+
return effects;
|
|
60
|
+
}
|
|
61
|
+
export function arbitrateAction(project, timeline, action, opts = {}) {
|
|
62
|
+
const scenario = project.scenarios[timeline.scenarioId];
|
|
63
|
+
const scene = project.scenes[opts.sceneId ?? timeline.sceneId];
|
|
64
|
+
if (!scenario || !scene)
|
|
65
|
+
return { kind: 'hint', verdict: { kind: 'static' } };
|
|
66
|
+
const view = playgroundState(timeline, opts.layer ?? null);
|
|
67
|
+
const inputs = [action, ...(opts.native ? [opts.native] : [])];
|
|
68
|
+
// Input is accepted only from a visible, enabled target in the displayed local view.
|
|
69
|
+
const available = (input) => !('target' in input) || !!findNode(scene, input.target) && isNodeVisible(scene, input.target, view) && !isNodeDisabled(findNode(scene, input.target).node, view);
|
|
70
|
+
const matches = (expected) => inputs.some(input => available(input) && actionMatches(canonicalAction(expected, scene, view), canonicalAction(input, scene, view), expected.type === 'plugin' ? pluginActionSpec(project, expected.name) : undefined));
|
|
71
|
+
const next = scenario.steps[timeline.position];
|
|
72
|
+
if (next && !timeline.completed && matches(next.action) && !checkStep(project, scenario, timeline, next))
|
|
73
|
+
return { kind: 'advance' };
|
|
74
|
+
const candidates = (opts.index ?? actionIndex(project, scenario.optionId)).filter(entry => entry.scenarioId !== scenario.id && entry.sceneId === scene.id && matches(entry.action));
|
|
75
|
+
if (candidates.length)
|
|
76
|
+
return { kind: 'switch', candidates };
|
|
77
|
+
const reaction = Object.values(project.options[scenario.optionId]?.free ?? {}).find(r => matches(r.action));
|
|
78
|
+
const native = nativeEffects(scene, view, opts.native ?? action);
|
|
79
|
+
const nativeFocus = action.type === 'click' && available(action) && !!findNode(scene, action.target)?.node.traits?.native;
|
|
80
|
+
if (reaction || native.length || nativeFocus)
|
|
81
|
+
return { kind: 'free', effects: [...native, ...(reaction?.effects.filter((e) => e.type === 'set' || e.type === 'append' || e.type === 'toast') ?? [])] };
|
|
82
|
+
const hint = 'target' in action ? explainClick(project, timeline, action.target, scene.id) : { kind: 'static' };
|
|
83
|
+
// Legacy explainClick intentionally accepts a target alone; never let it bypass action matching.
|
|
84
|
+
return { kind: 'hint', verdict: hint.kind === 'advance' ? { kind: 'out_of_order', label: '', expectedCaption: next?.caption ?? null } : hint };
|
|
85
|
+
}
|
|
86
|
+
export function applyPlayground(layer, effects) {
|
|
87
|
+
return { effects: [...(layer?.effects ?? []), ...structuredClone(effects)] };
|
|
88
|
+
}
|
|
89
|
+
export function playgroundState(timeline, layer) {
|
|
90
|
+
if (!layer || !layer.effects.length)
|
|
91
|
+
return timeline;
|
|
92
|
+
const view = structuredClone(timeline);
|
|
93
|
+
for (const [i, effect] of layer.effects.entries()) {
|
|
94
|
+
if (effect.type === 'toast') {
|
|
95
|
+
view.toasts = [{ id: `free-${i}`, text: effect.text, tone: effect.tone }];
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const [root, ...keys] = effect.path.split('.');
|
|
99
|
+
if (!['ui', 'data', 'inputs'].includes(root) || !keys.length || keys.some(k => ['__proto__', 'constructor', 'prototype'].includes(k)))
|
|
100
|
+
continue;
|
|
101
|
+
let object = view[root];
|
|
102
|
+
for (const key of keys.slice(0, -1)) {
|
|
103
|
+
if (!object[key] || typeof object[key] !== 'object' || Array.isArray(object[key]))
|
|
104
|
+
object[key] = {};
|
|
105
|
+
object = object[key];
|
|
106
|
+
}
|
|
107
|
+
const key = keys.at(-1);
|
|
108
|
+
object[key] = effect.type === 'append' ? [...(Array.isArray(object[key]) ? object[key] : []), structuredClone(effect.value)] : structuredClone(effect.value);
|
|
109
|
+
}
|
|
110
|
+
return view;
|
|
111
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Pure IR operations for declared plugin data. No plugin callback is executed here. */
|
|
2
|
+
import type { PluginDataSpec } from '@joplo-app/kit/plugin';
|
|
3
|
+
import type { Project } from './schema.js';
|
|
4
|
+
type Table = Record<string, {
|
|
5
|
+
data?: PluginDataSpec;
|
|
6
|
+
}> | undefined;
|
|
7
|
+
/** Shared path projection for slot text and declared component display properties. */
|
|
8
|
+
export declare function mapTextPaths(value: unknown, paths: readonly (readonly string[])[], visit: (s: string) => string): unknown;
|
|
9
|
+
export declare function mapSlotTexts(ext: Record<string, unknown> | undefined, plugins: Table, slot: 'node' | 'step', visit: (s: string) => string): Record<string, unknown> | undefined;
|
|
10
|
+
export declare function scopePluginData(project: Project): Project;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { JoploError } from "./result.js";
|
|
2
|
+
const obj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
3
|
+
function atPath(value, path, transform) {
|
|
4
|
+
if (!path.length)
|
|
5
|
+
return transform(value);
|
|
6
|
+
const [key, ...rest] = path;
|
|
7
|
+
if (Array.isArray(value))
|
|
8
|
+
return value.map((v, i) => key === '*' || key === String(i) ? atPath(v, rest, transform) : v);
|
|
9
|
+
if (obj(value))
|
|
10
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, key === '*' || key === k ? atPath(v, rest, transform) : v]));
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
function values(value, path, required) {
|
|
14
|
+
if (!path.length)
|
|
15
|
+
return [value];
|
|
16
|
+
const [key, ...rest] = path;
|
|
17
|
+
if (Array.isArray(value) || obj(value)) {
|
|
18
|
+
if (key === '*')
|
|
19
|
+
return Object.values(value).flatMap(v => values(v, rest, required));
|
|
20
|
+
if (Object.hasOwn(value, key))
|
|
21
|
+
return values(value[key], rest, required);
|
|
22
|
+
}
|
|
23
|
+
if (required)
|
|
24
|
+
throw new JoploError('PLUGIN_SCOPE_UNSUPPORTED', 'Missing scene identity in a stage ownership path');
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
/** Shared path projection for slot text and declared component display properties. */
|
|
28
|
+
export function mapTextPaths(value, paths, visit) {
|
|
29
|
+
return paths.reduce((v, path) => atPath(v, path, s => typeof s === 'string' ? visit(s) : s), value);
|
|
30
|
+
}
|
|
31
|
+
export function mapSlotTexts(ext, plugins, slot, visit) {
|
|
32
|
+
if (!ext)
|
|
33
|
+
return ext;
|
|
34
|
+
return Object.fromEntries(Object.entries(ext).map(([id, value]) => [id, mapTextPaths(value, plugins?.[id]?.data?.[slot]?.text ?? [], visit)]));
|
|
35
|
+
}
|
|
36
|
+
export function scopePluginData(project) {
|
|
37
|
+
const ids = new Map();
|
|
38
|
+
const collect = (n, set) => { set.add(n.id); n.children?.forEach(c => collect(c, set)); };
|
|
39
|
+
for (const scene of Object.values(project.scenes)) {
|
|
40
|
+
const set = new Set();
|
|
41
|
+
collect(scene.root, set);
|
|
42
|
+
ids.set(scene.id, set);
|
|
43
|
+
}
|
|
44
|
+
const unsupported = (message) => { throw new JoploError('PLUGIN_SCOPE_UNSUPPORTED', message); };
|
|
45
|
+
const rules = (value, specs, scene) => specs.reduce((data, rule) => atPath(data, rule.path, v => {
|
|
46
|
+
const allowed = rule.domain === 'scene' ? new Set(ids.keys()) : scene && ids.get(scene);
|
|
47
|
+
if (!allowed)
|
|
48
|
+
return unsupported('Element scope projection requires an unambiguous owning stage; declare a scene-domain map or items parent');
|
|
49
|
+
const identity = (id) => {
|
|
50
|
+
if (typeof id !== 'string' || !id)
|
|
51
|
+
return unsupported('Scope projection requires a nonempty scene/element identity');
|
|
52
|
+
const normalized = rule.prefix && id.startsWith(rule.prefix) ? id.slice(rule.prefix.length) : id;
|
|
53
|
+
if (!normalized)
|
|
54
|
+
return unsupported('Scope projection requires a nonempty scene/element identity after removing its prefix');
|
|
55
|
+
return normalized;
|
|
56
|
+
};
|
|
57
|
+
const keep = (id) => allowed.has(identity(id));
|
|
58
|
+
if (rule.kind === 'reference')
|
|
59
|
+
return v === null || keep(v) ? v : null;
|
|
60
|
+
if (rule.kind === 'map' && obj(v))
|
|
61
|
+
return Object.fromEntries(Object.entries(v).filter(([k]) => keep(k)).map(([k, item]) => [k, rules(item, rule.children ?? [], rule.domain === 'scene' ? identity(k) : scene)]));
|
|
62
|
+
if (rule.kind === 'values' && Array.isArray(v))
|
|
63
|
+
return v.filter(keep);
|
|
64
|
+
if (rule.kind === 'items' && Array.isArray(v))
|
|
65
|
+
return v.flatMap(item => {
|
|
66
|
+
const refs = (rule.references ?? [['id']]).map(path => values(item, path, rule.domain === 'scene'));
|
|
67
|
+
const identities = refs.flat().map(identity);
|
|
68
|
+
if (!identities.length)
|
|
69
|
+
return unsupported('Scope items must declare their scene/element identity');
|
|
70
|
+
if (rule.domain === 'scene') {
|
|
71
|
+
if (refs.some(matches => !matches.length) || new Set(identities).size !== 1)
|
|
72
|
+
return unsupported('Scene-domain items require exactly one owning stage');
|
|
73
|
+
const owner = identities[0];
|
|
74
|
+
return allowed.has(owner) ? [rules(item, rule.children ?? [], owner)] : [];
|
|
75
|
+
}
|
|
76
|
+
return identities.every(id => allowed.has(id)) ? [rules(item, rule.children ?? [], scene)] : [];
|
|
77
|
+
});
|
|
78
|
+
return unsupported(`Invalid ${rule.kind} scope data for scene/element projection`);
|
|
79
|
+
}), value);
|
|
80
|
+
const ext = (input, slot, scene) => {
|
|
81
|
+
if (!input)
|
|
82
|
+
return input;
|
|
83
|
+
return Object.fromEntries(Object.entries(input).map(([id, value]) => {
|
|
84
|
+
const spec = project.plugins?.[id]?.data?.[slot]?.scope;
|
|
85
|
+
if (!spec)
|
|
86
|
+
throw new JoploError('PLUGIN_SCOPE_UNSUPPORTED', `Plugin ${id} has ${slot} data without a scope projection; declare its scope rules before sharing a subset`);
|
|
87
|
+
return [id, spec === 'global' ? value : rules(value, spec, scene)];
|
|
88
|
+
}));
|
|
89
|
+
};
|
|
90
|
+
const node = (n, scene) => ({ ...n, ...(n.ext ? { ext: ext(n.ext, 'node', scene) } : {}), ...(n.children ? { children: n.children.map(c => node(c, scene)) } : {}) });
|
|
91
|
+
return {
|
|
92
|
+
...project,
|
|
93
|
+
scenes: Object.fromEntries(Object.entries(project.scenes).map(([id, scene]) => [id, { ...scene, root: node(scene.root, id) }])),
|
|
94
|
+
scenarios: Object.fromEntries(Object.entries(project.scenarios).map(([id, sc]) => [id, { ...sc, ...(sc.ext ? { ext: ext(sc.ext, 'step') } : {}), steps: sc.steps.map(st => ({ ...st, ...(st.ext ? { ext: ext(st.ext, 'step') } : {}) })) }])),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { MediaCommand, ResourceRequest, LocalResourceInfo } from '@joplo-app/kit/plugin';
|
|
2
|
+
/** Node-side plugin host. Callbacks never enter IR or the player. */
|
|
3
|
+
import { type JNode } from '@joplo-app/kit/node';
|
|
4
|
+
import { type PluginDef, type PluginEffectDef, type PluginReport } from '@joplo-app/kit/plugin';
|
|
5
|
+
import type { Scene, Project } from '../schema.js';
|
|
6
|
+
import type { PluginInfo } from '../catalog.js';
|
|
7
|
+
export type CompileOptions = {
|
|
8
|
+
onResource?: (request: ResourceRequest) => void;
|
|
9
|
+
resourceInfo?: Record<string, LocalResourceInfo>;
|
|
10
|
+
pluginOptions?: Record<string, Record<string, unknown>>;
|
|
11
|
+
};
|
|
12
|
+
export declare function enabledPlugins(configured: unknown): unknown[];
|
|
13
|
+
export declare class PluginCompiler {
|
|
14
|
+
private report;
|
|
15
|
+
private options;
|
|
16
|
+
readonly intrinsic: Map<string, string>;
|
|
17
|
+
readonly inherits: Map<string, {
|
|
18
|
+
target: string;
|
|
19
|
+
props: string[];
|
|
20
|
+
}[]>;
|
|
21
|
+
readonly themes: Record<string, string>;
|
|
22
|
+
readonly properties: Map<string, {
|
|
23
|
+
plugin: PluginDef;
|
|
24
|
+
spec: import("@joplo-app/kit/plugin").PluginPropertySpec;
|
|
25
|
+
}>;
|
|
26
|
+
readonly mediaCommands: Map<string, (MediaCommand & {
|
|
27
|
+
plugin: string;
|
|
28
|
+
})[]>;
|
|
29
|
+
private resourceIds;
|
|
30
|
+
private resourceOwners;
|
|
31
|
+
readonly defs: Map<string, PluginDef>;
|
|
32
|
+
readonly info: Record<string, PluginInfo>;
|
|
33
|
+
constructor(configured: unknown, report: PluginReport, source?: string, options?: CompileOptions);
|
|
34
|
+
private run;
|
|
35
|
+
private output;
|
|
36
|
+
private validateProperties;
|
|
37
|
+
private resourceProps;
|
|
38
|
+
node(node: JNode, ids: ReadonlyMap<string, string | undefined>): JNode;
|
|
39
|
+
derive(scene: Scene): void;
|
|
40
|
+
effect(effect: PluginEffectDef, scenes: readonly Scene[], data: unknown, source?: string): {
|
|
41
|
+
references?: string[] | undefined;
|
|
42
|
+
targets?: string[] | undefined;
|
|
43
|
+
data?: {} | null | undefined;
|
|
44
|
+
media?: ({
|
|
45
|
+
plugin: string;
|
|
46
|
+
track: string;
|
|
47
|
+
action: "play";
|
|
48
|
+
resource: string;
|
|
49
|
+
offsetMs?: number;
|
|
50
|
+
volume?: number;
|
|
51
|
+
loop?: boolean;
|
|
52
|
+
fadeMs?: number;
|
|
53
|
+
} | {
|
|
54
|
+
plugin: string;
|
|
55
|
+
track: string;
|
|
56
|
+
action: "stop";
|
|
57
|
+
fadeMs?: number;
|
|
58
|
+
})[] | undefined;
|
|
59
|
+
holdMs?: number | undefined;
|
|
60
|
+
directorTarget?: string | undefined;
|
|
61
|
+
writes?: import("@joplo-app/kit/plugin").PluginWrite[] | undefined;
|
|
62
|
+
} | undefined;
|
|
63
|
+
frames(project: Project): void;
|
|
64
|
+
private invalid;
|
|
65
|
+
private envelope;
|
|
66
|
+
private checkData;
|
|
67
|
+
}
|