@joplo-app/server 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.
- package/dist/asset-usage.d.ts +48 -0
- package/dist/asset-usage.js +174 -0
- package/dist/audio-timing.d.ts +14 -0
- package/dist/audio-timing.js +66 -0
- package/dist/build.js +15 -2
- package/dist/capture.d.ts +15 -0
- package/dist/capture.js +49 -0
- package/dist/checkpoint.d.ts +10 -0
- package/dist/checkpoint.js +75 -0
- package/dist/contract.d.ts +63 -1
- package/dist/dev.d.ts +1 -0
- package/dist/dev.js +15 -7
- package/dist/export.d.ts +6 -0
- package/dist/export.js +5 -2
- package/dist/film.d.ts +12 -1
- package/dist/film.js +231 -25
- package/dist/index.d.ts +7 -1
- package/dist/index.js +5 -1
- package/dist/layout-audit-browser.js +114 -0
- package/dist/layout-audit.d.ts +94 -0
- package/dist/layout-audit.js +86 -0
- package/dist/local-resources.d.ts +5 -0
- package/dist/local-resources.js +32 -6
- package/dist/media-check.d.ts +7 -1
- package/dist/media-check.js +44 -3
- package/dist/output-file.d.ts +3 -0
- package/dist/output-file.js +23 -0
- package/dist/project.d.ts +5 -1
- package/dist/project.js +20 -4
- package/dist/render.d.ts +2 -0
- package/dist/render.js +24 -10
- package/dist/resources-run.d.ts +1 -0
- package/dist/resources-run.js +23 -2
- package/dist/timeline.d.ts +76 -0
- package/dist/timeline.js +143 -0
- package/dist/video-format.d.ts +2 -0
- package/dist/video-format.js +12 -0
- package/dist/vite-shared.d.ts +1 -1
- package/dist/vite-shared.js +2 -2
- package/dist/voice-http.d.ts +1 -0
- package/dist/voice-http.js +8 -2
- package/dist/voice-run.d.ts +17 -1
- package/dist/voice-run.js +71 -9
- package/dist/voice.d.ts +1 -0
- package/dist/voice.js +10 -2
- package/dist/watch-config.d.ts +3 -0
- package/dist/watch-config.js +10 -0
- package/package.json +4 -4
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/* Browser-only read-only geometry audit; source-injected to avoid transpiler helpers. */
|
|
2
|
+
(options) => {
|
|
3
|
+
const root = document.querySelector('[data-jexport],[data-jshot],[data-jrender]') || document.querySelector('[data-joplo-stage]');
|
|
4
|
+
if (!root) throw new Error('Layout audit has no render surface');
|
|
5
|
+
const box = r => ({ x: r.left ?? r.x, y: r.top ?? r.y, width: r.width, height: r.height });
|
|
6
|
+
const right = r => r.x + r.width, bottom = r => r.y + r.height;
|
|
7
|
+
const outside = (a, b) => a.x < b.x - 1 || a.y < b.y - 1 || right(a) > right(b) + 1 || bottom(a) > bottom(b) + 1;
|
|
8
|
+
const intersection = (a, b) => Math.max(0, Math.min(right(a), right(b)) - Math.max(a.x, b.x)) * Math.max(0, Math.min(bottom(a), bottom(b)) - Math.max(a.y, b.y));
|
|
9
|
+
const unknowns = [], rootBox = box(root.getBoundingClientRect());
|
|
10
|
+
const matches = selector => Array.from(root.querySelectorAll(selector)).concat(root.matches(selector) ? [root] : []);
|
|
11
|
+
const area = value => {
|
|
12
|
+
if (typeof value !== 'string') return { ...value, x: rootBox.x + value.x, y: rootBox.y + value.y };
|
|
13
|
+
const elements = matches(value);
|
|
14
|
+
if (elements.length !== 1) throw new Error(`Layout area ${value} must match exactly one element inside the render surface`);
|
|
15
|
+
return box(elements[0].getBoundingClientRect());
|
|
16
|
+
};
|
|
17
|
+
const content = options.content ? area(options.content) : options.crop ? area(options.crop) : rootBox;
|
|
18
|
+
if (content.width <= 0 || content.height <= 0 || outside(content, rootBox)) throw new Error('Layout content area must be inside the render surface');
|
|
19
|
+
const safeAreas = (options.safeAreas ?? []).map(area);
|
|
20
|
+
const exclude = (options.exclude ?? []).flatMap(matches);
|
|
21
|
+
const ignored = el => exclude.some(x => x === el || x.contains(el));
|
|
22
|
+
const styledVisible = el => {
|
|
23
|
+
for (let e = el; e; e = e.parentElement) {
|
|
24
|
+
const s = getComputedStyle(e);
|
|
25
|
+
if (s.display === 'none' || s.visibility === 'hidden' || s.visibility === 'collapse' || Number(s.opacity) === 0 || e.hasAttribute('hidden')) return false;
|
|
26
|
+
if (e === root) break;
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
};
|
|
30
|
+
const identity = el => {
|
|
31
|
+
const owner = el.closest('[data-jid]:not([data-jtype="#text"])');
|
|
32
|
+
return { elementId: owner?.getAttribute('data-jid') ?? null, source: owner?.getAttribute('data-jat') ?? null, tag: el.tagName.toLowerCase() };
|
|
33
|
+
};
|
|
34
|
+
const unsupportedClip = el => {
|
|
35
|
+
for (let e = el; e; e = e.parentElement) {
|
|
36
|
+
const s = getComputedStyle(e), matrix = s.transform === 'none' ? null : new DOMMatrixReadOnly(s.transform);
|
|
37
|
+
if (s.clipPath !== 'none' || s.maskImage !== 'none' || (matrix && (Math.abs(matrix.b) > .0001 || Math.abs(matrix.c) > .0001))) return true;
|
|
38
|
+
if (e === root) break;
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
};
|
|
42
|
+
const important = [...new Set((options.important ?? []).flatMap(selector => {
|
|
43
|
+
const found = matches(selector);
|
|
44
|
+
if (!found.length) unknowns.push({ elementId: null, source: null, reason: `Important selector ${selector} matched no rendered elements; visibility is unknown` });
|
|
45
|
+
return found;
|
|
46
|
+
}))].filter(el => !ignored(el));
|
|
47
|
+
const importantSet = important.filter(styledVisible);
|
|
48
|
+
for (const el of important.filter(el => !styledVisible(el))) unknowns.push({ ...identity(el), reason: 'Important element is hidden or transparent at this sample; no visible geometry claim is made' });
|
|
49
|
+
const isImportant = el => importantSet.some(x => x === el || x.contains(el));
|
|
50
|
+
const findings = [], textBoxes = [], seen = new Set(), unknownOwners = new Set();
|
|
51
|
+
const add = (code, el, rect, detail, other) => {
|
|
52
|
+
const id = identity(el), key = `${code}:${id.elementId}:${detail}`;
|
|
53
|
+
if (seen.has(key)) return;
|
|
54
|
+
seen.add(key); findings.push({ code, severity: 'warning', ...id, box: rect, detail, ...(other ? { relatedBox: other } : {}) });
|
|
55
|
+
};
|
|
56
|
+
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
57
|
+
let node, count = 0;
|
|
58
|
+
while ((node = walker.nextNode())) {
|
|
59
|
+
if (++count > 5000) break;
|
|
60
|
+
if (!node.textContent?.trim()) continue;
|
|
61
|
+
const el = node.parentElement;
|
|
62
|
+
if (!el || ignored(el) || !styledVisible(el) || /^(script|style|noscript)$/.test(el.tagName.toLowerCase())) continue;
|
|
63
|
+
if (unsupportedClip(el)) {
|
|
64
|
+
const owner = identity(el);
|
|
65
|
+
if (!unknownOwners.has(owner.elementId)) { unknownOwners.add(owner.elementId); unknowns.push({ ...owner, reason: 'Rotation, mask or nonrectangular clipping makes exact text visibility unknown; inspect the evidence' }); }
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const range = document.createRange(); range.selectNodeContents(node);
|
|
69
|
+
for (const r of range.getClientRects()) {
|
|
70
|
+
if (r.width < .1 || r.height < .1) continue;
|
|
71
|
+
const rect = box(r); textBoxes.push({ ...identity(el), box: rect, text: node.textContent.trim().slice(0, 100) });
|
|
72
|
+
if (outside(rect, content)) add('TEXT_OUTSIDE_CONTENT', el, rect, 'Rendered text line exceeds the declared content frame', content);
|
|
73
|
+
for (let parent = el; parent && parent !== root.parentElement; parent = parent.parentElement) {
|
|
74
|
+
const style = getComputedStyle(parent), clipX = /hidden|clip|auto|scroll/.test(style.overflowX), clipY = /hidden|clip|auto|scroll/.test(style.overflowY);
|
|
75
|
+
if (!clipX && !clipY) continue;
|
|
76
|
+
const r = parent.getBoundingClientRect(), sx = parent.offsetWidth ? r.width / parent.offsetWidth : 1, sy = parent.offsetHeight ? r.height / parent.offsetHeight : 1;
|
|
77
|
+
const boundary = { x: r.left + parent.clientLeft * sx, y: r.top + parent.clientTop * sy, width: parent.clientWidth * sx, height: parent.clientHeight * sy };
|
|
78
|
+
if ((clipX && (rect.x < boundary.x - 1 || right(rect) > right(boundary) + 1)) || (clipY && (rect.y < boundary.y - 1 || bottom(rect) > bottom(boundary) + 1))) {
|
|
79
|
+
add('TEXT_CLIPPED', el, rect, 'Rendered text line crosses an ancestor padding-box clipping boundary', boundary); break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (isImportant(el)) for (const region of safeAreas) if (intersection(rect, region) > 1) add('IMPORTANT_IN_SAFE_AREA', el, rect, 'Declared important text intersects a reserved safe area', region);
|
|
83
|
+
}
|
|
84
|
+
range.detach();
|
|
85
|
+
}
|
|
86
|
+
const elements = importantSet.slice(0, 500).map(el => ({ el, ...identity(el), box: box(el.getBoundingClientRect()) }));
|
|
87
|
+
for (let i = 0; i < elements.length; i++) {
|
|
88
|
+
const a = elements[i];
|
|
89
|
+
if (a.box.width <= 0 || a.box.height <= 0) continue;
|
|
90
|
+
if (unsupportedClip(a.el)) { unknowns.push({ ...identity(a.el), reason: 'Declared important geometry has rotation/masking; visibility is unknown' }); continue; }
|
|
91
|
+
if (outside(a.box, content)) add('IMPORTANT_OUTSIDE_CONTENT', a.el, a.box, 'Declared important element exceeds the content frame', content);
|
|
92
|
+
for (const region of safeAreas) if (intersection(a.box, region) > 1) add('IMPORTANT_IN_SAFE_AREA', a.el, a.box, 'Declared important element intersects a reserved safe area', region);
|
|
93
|
+
for (let j = i + 1; j < elements.length; j++) {
|
|
94
|
+
const b = elements[j];
|
|
95
|
+
if (a.el.contains(b.el) || b.el.contains(a.el)) continue;
|
|
96
|
+
const overlap = intersection(a.box, b.box), smaller = Math.min(a.box.width * a.box.height, b.box.width * b.box.height);
|
|
97
|
+
if (smaller > 0 && overlap / smaller > .1) add('POSSIBLE_OCCLUSION', a.el, a.box, `Geometry-only heuristic overlaps ${b.elementId ?? b.tag}; paint order and actual occlusion are not proven`, b.box);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const phases = [];
|
|
101
|
+
for (const animation of root.getAnimations({ subtree: true })) {
|
|
102
|
+
if (animation.id !== 'jenter') continue;
|
|
103
|
+
const current = animation.currentTime, end = animation.effect?.getComputedTiming().endTime;
|
|
104
|
+
if (typeof current === 'number' && typeof end === 'number' && Number.isFinite(end) && end >= current) phases.push({ phase: 'enter-end', afterMs: end - current });
|
|
105
|
+
}
|
|
106
|
+
for (const el of [...root.querySelectorAll('[data-joplo-audit-phases]'), ...(root.hasAttribute('data-joplo-audit-phases') ? [root] : [])]) {
|
|
107
|
+
try {
|
|
108
|
+
const hints = JSON.parse(el.getAttribute('data-joplo-audit-phases'));
|
|
109
|
+
if (!Number.isFinite(hints.clockMs) || !Array.isArray(hints.phases)) throw new Error();
|
|
110
|
+
for (const hint of hints.phases) if (['camera-end', 'camera-waypoint', 'drift-mid', 'drift-end'].includes(hint.phase) && Number.isFinite(hint.atMs) && hint.atMs >= hints.clockMs) phases.push({ phase: hint.phase, afterMs: hint.atMs - hints.clockMs });
|
|
111
|
+
} catch { unknowns.push({ ...identity(el), reason: 'Invalid plugin audit phase hints were ignored' }); }
|
|
112
|
+
}
|
|
113
|
+
return { root: rootBox, content, safeAreas, elements: elements.map(({ el, ...rest }) => rest), textBoxes, findings, unknowns, phases, truncated: count > 5000 || important.length > 500, coordinates: 'page-css-pixels', fonts: { status: document.fonts.status, families: [...new Set(textBoxes.map(t => t.elementId).filter(Boolean).map(id => { const el = root.querySelector(`[data-jid="${CSS.escape(id)}"]`); return el ? getComputedStyle(el).fontFamily : ''; }))] } };
|
|
114
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { Page } from 'playwright-core';
|
|
2
|
+
import { type Project } from '@joplo-app/core';
|
|
3
|
+
import type { ExportCrop } from './contract.js';
|
|
4
|
+
export type LayoutAuditOptions = {
|
|
5
|
+
content?: ExportCrop;
|
|
6
|
+
safeAreas?: ExportCrop[];
|
|
7
|
+
important?: string[];
|
|
8
|
+
exclude?: string[]; /** Interval between diagnostic probes in engine milliseconds, 20–1000 (default 250). */
|
|
9
|
+
everyMs?: number;
|
|
10
|
+
};
|
|
11
|
+
export type LayoutBox = {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
};
|
|
17
|
+
export type LayoutFinding = {
|
|
18
|
+
code: 'TEXT_OUTSIDE_CONTENT' | 'TEXT_CLIPPED' | 'IMPORTANT_IN_SAFE_AREA' | 'IMPORTANT_OUTSIDE_CONTENT' | 'POSSIBLE_OCCLUSION';
|
|
19
|
+
severity: 'warning';
|
|
20
|
+
elementId: string | null;
|
|
21
|
+
source: string | null;
|
|
22
|
+
tag: string;
|
|
23
|
+
box: LayoutBox;
|
|
24
|
+
relatedBox?: LayoutBox;
|
|
25
|
+
detail: string;
|
|
26
|
+
};
|
|
27
|
+
type Identity = {
|
|
28
|
+
elementId: string | null;
|
|
29
|
+
source: string | null;
|
|
30
|
+
tag?: string;
|
|
31
|
+
};
|
|
32
|
+
type Geometry = {
|
|
33
|
+
coordinates: 'page-css-pixels';
|
|
34
|
+
root: LayoutBox;
|
|
35
|
+
content: LayoutBox;
|
|
36
|
+
safeAreas: LayoutBox[];
|
|
37
|
+
elements: (Identity & {
|
|
38
|
+
box: LayoutBox;
|
|
39
|
+
})[];
|
|
40
|
+
textBoxes: (Identity & {
|
|
41
|
+
box: LayoutBox;
|
|
42
|
+
text: string;
|
|
43
|
+
})[];
|
|
44
|
+
findings: LayoutFinding[];
|
|
45
|
+
unknowns: (Identity & {
|
|
46
|
+
reason: string;
|
|
47
|
+
})[];
|
|
48
|
+
phases: {
|
|
49
|
+
phase: string;
|
|
50
|
+
afterMs: number;
|
|
51
|
+
}[];
|
|
52
|
+
fonts: {
|
|
53
|
+
status: string;
|
|
54
|
+
families: string[];
|
|
55
|
+
};
|
|
56
|
+
truncated: boolean;
|
|
57
|
+
};
|
|
58
|
+
export type LayoutAuditSample = Omit<Geometry, 'phases'> & {
|
|
59
|
+
phaseHints?: Geometry['phases'];
|
|
60
|
+
atMs: number | null;
|
|
61
|
+
timeBasis: 'engine-clock' | 'static-final-state';
|
|
62
|
+
phases: string[];
|
|
63
|
+
scenarioId: string;
|
|
64
|
+
position: number;
|
|
65
|
+
stepId: string | null;
|
|
66
|
+
workId: string | null;
|
|
67
|
+
evidence: string | null;
|
|
68
|
+
};
|
|
69
|
+
export type LayoutAuditResult = {
|
|
70
|
+
path: string;
|
|
71
|
+
findings: number;
|
|
72
|
+
samples: number;
|
|
73
|
+
};
|
|
74
|
+
export declare function layoutAuditOptions(value: boolean | LayoutAuditOptions): LayoutAuditOptions;
|
|
75
|
+
export declare function auditLayout(page: Page, options: LayoutAuditOptions, crop?: ExportCrop): Promise<Geometry>;
|
|
76
|
+
export declare function writeLayoutReport(file: string, samples: LayoutAuditSample[], overwrite?: boolean, sampleToleranceMs?: number | null): LayoutAuditResult;
|
|
77
|
+
export declare function layoutReportPath(out: string): string;
|
|
78
|
+
export declare function createLayoutAuditSession(config: {
|
|
79
|
+
out: string;
|
|
80
|
+
project: Project;
|
|
81
|
+
crop?: ExportCrop;
|
|
82
|
+
options: boolean | LayoutAuditOptions;
|
|
83
|
+
overwrite?: boolean;
|
|
84
|
+
sampleMs: number;
|
|
85
|
+
}): {
|
|
86
|
+
sample(page: Page, frame: {
|
|
87
|
+
atMs: number;
|
|
88
|
+
scenarioId: string;
|
|
89
|
+
position: number;
|
|
90
|
+
jpg: string;
|
|
91
|
+
}): Promise<void>;
|
|
92
|
+
finish(): LayoutAuditResult;
|
|
93
|
+
};
|
|
94
|
+
export {};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/** Browser geometry diagnostics. No Core layout rules, resource generation or automatic edits. */
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { JoploError } from '@joplo-app/core';
|
|
5
|
+
const browserSource = fs.readFileSync(path.join(import.meta.dirname, 'layout-audit-browser.js'), 'utf8').replace(/^\/\*[\s\S]*?\*\/\s*/, '');
|
|
6
|
+
function area(value) {
|
|
7
|
+
if (typeof value === 'string')
|
|
8
|
+
return value.trim().length > 0;
|
|
9
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
10
|
+
return false;
|
|
11
|
+
const v = value;
|
|
12
|
+
return Object.keys(v).every(k => ['x', 'y', 'width', 'height'].includes(k)) && ['x', 'y', 'width', 'height'].every(k => typeof v[k] === 'number' && Number.isFinite(v[k])) && v.width > 0 && v.height > 0;
|
|
13
|
+
}
|
|
14
|
+
export function layoutAuditOptions(value) {
|
|
15
|
+
const options = value === true ? {} : value;
|
|
16
|
+
if (!options || typeof options !== 'object' || Array.isArray(options) || Object.keys(options).some(k => !['content', 'safeAreas', 'important', 'exclude', 'everyMs'].includes(k)))
|
|
17
|
+
throw new JoploError('USAGE', 'Invalid layout audit options');
|
|
18
|
+
if (options.content !== undefined && !area(options.content) || options.safeAreas !== undefined && (!Array.isArray(options.safeAreas) || !options.safeAreas.every(area)))
|
|
19
|
+
throw new JoploError('USAGE', 'Layout content/safe areas must be CSS selectors or finite positive CSS rectangles');
|
|
20
|
+
if (options.everyMs !== undefined && (!Number.isFinite(options.everyMs) || options.everyMs < 20 || options.everyMs > 1000))
|
|
21
|
+
throw new JoploError('USAGE', 'Layout audit everyMs must be 20–1000 engine milliseconds');
|
|
22
|
+
for (const key of ['important', 'exclude'])
|
|
23
|
+
if (options[key] !== undefined && (!Array.isArray(options[key]) || !options[key].every(selector => typeof selector === 'string' && selector.trim())))
|
|
24
|
+
throw new JoploError('USAGE', `Layout audit ${key} must contain CSS selectors`);
|
|
25
|
+
return options;
|
|
26
|
+
}
|
|
27
|
+
export async function auditLayout(page, options, crop) {
|
|
28
|
+
layoutAuditOptions(options);
|
|
29
|
+
await page.evaluate(() => document.fonts.ready);
|
|
30
|
+
try {
|
|
31
|
+
return await page.evaluate(`(${browserSource})(${JSON.stringify({ ...options, crop })})`);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
throw new JoploError('RENDER_FAILED', `Layout geometry audit failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function writeLayoutReport(file, samples, overwrite = false, sampleToleranceMs = null) {
|
|
38
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
39
|
+
const report = { schemaVersion: 1, kind: 'layout-audit', sampling: 'actual-rendered-css-geometry', sampleToleranceMs, findings: samples.reduce((n, s) => n + s.findings.length, 0), samples, limitations: [
|
|
40
|
+
'Bounds are page CSS pixels after actual fonts and transforms. Evidence may be cropped/scaled; root/content bounds provide the coordinate origin. Static samples have no engine timestamp and do not verify motion.',
|
|
41
|
+
'Importance is explicitly selected, never inferred from semantic meaning. Excluded decorations and intentional overlaps are not diagnosed. Geometry overlap is only a warning and does not prove paint occlusion.',
|
|
42
|
+
'No contrast, screen-reader, reading-order or copyright assessment. Rotation, masks and nonrectangular clipping remain unknown. Transparent/hidden important elements are reported as unknown rather than guessed visible.',
|
|
43
|
+
'Playback samples use the existing export engine clock. Commit and declared plugin/entry phase deadlines are observed on the export sample grid within sampleToleranceMs; phases interrupted by a later step or absent from plugin hints are not guaranteed. Unobserved intervals can contain additional problems.',
|
|
44
|
+
] };
|
|
45
|
+
fs.writeFileSync(file, JSON.stringify(report, null, 2), overwrite ? undefined : { flag: 'wx' });
|
|
46
|
+
return { path: file, findings: report.findings, samples: samples.length };
|
|
47
|
+
}
|
|
48
|
+
export function layoutReportPath(out) { return out.replace(/\.[^.]+$/, '') + '.layout.json'; }
|
|
49
|
+
export function createLayoutAuditSession(config) {
|
|
50
|
+
const options = layoutAuditOptions(config.options), reportPath = layoutReportPath(config.out), samples = [];
|
|
51
|
+
if (config.sampleMs > 50)
|
|
52
|
+
throw new JoploError('USAGE', 'Motion layout audit requires sampleMs <= 50 to observe commit and animation phases');
|
|
53
|
+
if (fs.existsSync(reportPath) && !config.overwrite)
|
|
54
|
+
throw new JoploError('USAGE', `Layout report already exists: ${reportPath}`);
|
|
55
|
+
let nextInterval = 0, previous = '', pending = [];
|
|
56
|
+
return {
|
|
57
|
+
async sample(page, frame) {
|
|
58
|
+
const identity = `${frame.scenarioId}#${frame.position}`, changed = identity !== previous;
|
|
59
|
+
if (changed)
|
|
60
|
+
pending = [];
|
|
61
|
+
const due = pending.filter(p => p.identity === identity && p.atMs <= frame.atMs + .01);
|
|
62
|
+
pending = pending.filter(p => !due.includes(p));
|
|
63
|
+
if (!changed && !due.length && frame.atMs < nextInterval)
|
|
64
|
+
return;
|
|
65
|
+
const measured = await auditLayout(page, options, config.crop);
|
|
66
|
+
const phaseNames = [...new Set([...(changed ? [frame.position ? 'post-commit' : 'initial'] : []), ...due.map(p => p.phase), ...(!changed && !due.length ? ['interval'] : [])])];
|
|
67
|
+
for (const hint of measured.phases) {
|
|
68
|
+
const atMs = frame.atMs + hint.afterMs;
|
|
69
|
+
if (hint.afterMs > .01 && !pending.some(p => p.identity === identity && p.phase === hint.phase && Math.abs(p.atMs - atMs) <= config.sampleMs))
|
|
70
|
+
pending.push({ atMs, phase: hint.phase, identity });
|
|
71
|
+
}
|
|
72
|
+
let evidence = null;
|
|
73
|
+
if (measured.findings.length || measured.unknowns.length) {
|
|
74
|
+
const directory = config.out.replace(/\.[^.]+$/, '') + '.layout-evidence';
|
|
75
|
+
fs.mkdirSync(directory, { recursive: true });
|
|
76
|
+
evidence = path.join(directory, `${String(Math.round(frame.atMs)).padStart(8, '0')}.jpg`);
|
|
77
|
+
fs.writeFileSync(evidence, Buffer.from(frame.jpg, 'base64'), config.overwrite ? undefined : { flag: 'wx' });
|
|
78
|
+
}
|
|
79
|
+
const scenario = config.project.scenarios[frame.scenarioId];
|
|
80
|
+
samples.push({ ...measured, phaseHints: measured.phases, phases: phaseNames, atMs: frame.atMs, timeBasis: 'engine-clock', scenarioId: frame.scenarioId, position: frame.position, stepId: scenario?.steps[frame.position - 1]?.id ?? null, workId: scenario?.workId ?? null, evidence });
|
|
81
|
+
previous = identity;
|
|
82
|
+
nextInterval = frame.atMs + (options.everyMs ?? 250);
|
|
83
|
+
},
|
|
84
|
+
finish() { return writeLayoutReport(reportPath, samples, config.overwrite, config.sampleMs); },
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -28,6 +28,11 @@ export declare class LocalResources {
|
|
|
28
28
|
info?: LocalResourceInfo;
|
|
29
29
|
diagnostic?: Diagnostic;
|
|
30
30
|
}>;
|
|
31
|
+
/** Read existing prepared metadata only; never generate resources or incur provider spend. */
|
|
32
|
+
prepared(request: ResourceRequest): Promise<{
|
|
33
|
+
bytes: number;
|
|
34
|
+
audio?: import('@joplo-app/kit/plugin').AudioRegion;
|
|
35
|
+
} | null>;
|
|
31
36
|
ensure(request: ResourceRequest, limits?: {
|
|
32
37
|
timeoutMs?: number;
|
|
33
38
|
maxBytes?: number;
|
package/dist/local-resources.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** Node-only resource host. Work runs in a disposable process, never the browser. */
|
|
2
2
|
import fs from 'node:fs';
|
|
3
|
+
import { mediaBudgetDiagnostics } from "./media-check.js";
|
|
3
4
|
import { PluginKeyStore, compilerEnvironment } from "./plugin-keys.js";
|
|
4
5
|
import { joploHome } from "./home.js";
|
|
5
6
|
import path from 'node:path';
|
|
@@ -7,6 +8,11 @@ import crypto from 'node:crypto';
|
|
|
7
8
|
import { spawn } from 'node:child_process';
|
|
8
9
|
import { build } from 'vite';
|
|
9
10
|
import { AudioRegionSchema, nodeResourceIds as referencedResources, mediaResourceIds } from '@joplo-app/core';
|
|
11
|
+
function encodedBudget(result, request) {
|
|
12
|
+
if (result.url?.startsWith('data:audio/') && (result.bytes ?? 0) > 4 * 1048576)
|
|
13
|
+
return { ...result, diagnostic: { severity: 'warning', source: 'structure', code: 'MEDIA_ENCODE_BUDGET', at: request.source, message: `${request.plugin}/${request.id}: encoded audio is ${result.bytes} bytes (${(result.bytes / 1048576).toFixed(2)} MiB), exceeding the independent 4 MiB encoded cache. Transcode large WAV/PCM to FLAC or another smaller supported format; the 50 MiB local artifact limit is not a playback budget.` } };
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
10
16
|
const inflight = new Map();
|
|
11
17
|
const digest = (s) => crypto.createHash('sha256').update(s).digest('hex');
|
|
12
18
|
const LIMIT = 50 * 1024 * 1024;
|
|
@@ -143,9 +149,9 @@ export class LocalResources {
|
|
|
143
149
|
const script = `import {pathToFileURL} from 'node:url';
|
|
144
150
|
let s=''; for await(const c of process.stdin)s+=c; const r=JSON.parse(s);
|
|
145
151
|
try { const c=(await import(pathToFileURL(r.entry).href)).default.compilers[r.compiler];
|
|
146
|
-
process.stdout.write(JSON.stringify({info:await c.inspect(r.input,{directory:r.directory})}));
|
|
152
|
+
process.stdout.write(JSON.stringify({info:await c.inspect(r.input,{directory:r.directory,projectDir:r.projectDir})}));
|
|
147
153
|
}catch(e){process.stdout.write(JSON.stringify({error:String(e.message)}));process.exitCode=1;}`;
|
|
148
|
-
const child = spawn(process.execPath, ['--input-type=module', '-e', script], { cwd: job, stdio: ['pipe', 'pipe', 'ignore'], detached: process.platform !== 'win32' });
|
|
154
|
+
const child = spawn(process.execPath, ['--input-type=module', '-e', script], { cwd: job, env: compilerEnvironment(), stdio: ['pipe', 'pipe', 'ignore'], detached: process.platform !== 'win32' });
|
|
149
155
|
let output = '', settled = false;
|
|
150
156
|
const finish = (error, value) => {
|
|
151
157
|
if (settled)
|
|
@@ -178,7 +184,7 @@ export class LocalResources {
|
|
|
178
184
|
finish(e);
|
|
179
185
|
} });
|
|
180
186
|
child.stdin.on('error', () => { });
|
|
181
|
-
child.stdin.end(JSON.stringify({ entry, compiler: request.compiler, input: request.input, directory: job }));
|
|
187
|
+
child.stdin.end(JSON.stringify({ entry, compiler: request.compiler, input: request.input, directory: job, projectDir: this.directory }));
|
|
182
188
|
});
|
|
183
189
|
const tmp = `${cache}.${crypto.randomUUID()}.tmp`;
|
|
184
190
|
fs.writeFileSync(tmp, JSON.stringify(info));
|
|
@@ -193,6 +199,25 @@ export class LocalResources {
|
|
|
193
199
|
return { diagnostic: { severity: 'warning', source: 'structure', code: 'LOCAL_RESOURCE_INSPECTION_FAILED', message: `${request.plugin}/${request.compiler}: ${e.message}`, at: request.source?.replace(this.directory + path.sep, '') ?? 'joplo.config.ts:1:1' } };
|
|
194
200
|
}
|
|
195
201
|
}
|
|
202
|
+
/** Read existing prepared metadata only; never generate resources or incur provider spend. */
|
|
203
|
+
async prepared(request) {
|
|
204
|
+
try {
|
|
205
|
+
const code = await this.bundle(request.plugin), description = await this.describe(request);
|
|
206
|
+
if (description.persistent)
|
|
207
|
+
return null;
|
|
208
|
+
const key = digest(JSON.stringify([request.plugin, request.compiler, code, request.input]));
|
|
209
|
+
const saved = JSON.parse(fs.readFileSync(path.join(this.directory, '.joplo', 'resources', `${key}.json`), 'utf8'));
|
|
210
|
+
if (!Number.isInteger(saved.bytes) || saved.bytes < 0 || typeof saved.url !== 'string')
|
|
211
|
+
return null;
|
|
212
|
+
const data = /^data:audio\/[^;,]+;base64,/.exec(saved.url);
|
|
213
|
+
if (!data)
|
|
214
|
+
return null;
|
|
215
|
+
return { bytes: Buffer.byteLength(saved.url.slice(data[0].length), 'base64'), ...(saved.audio ? { audio: AudioRegionSchema.parse(saved.audio) } : {}) };
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
196
221
|
async ensure(request, limits = {}) {
|
|
197
222
|
const warning = (code, message) => ({ diagnostic: { severity: code === 'LOCAL_RESOURCE_ATTRIBUTION_MISSING' ? 'error' : 'warning', source: 'structure', code, message: `${request.plugin}/${request.compiler}: ${message}`, at: request.source ? request.source.replace(this.directory + path.sep, '') : 'joplo.config.ts:1:1' } });
|
|
198
223
|
try {
|
|
@@ -224,7 +249,7 @@ export class LocalResources {
|
|
|
224
249
|
};
|
|
225
250
|
const hit = cached();
|
|
226
251
|
if (hit)
|
|
227
|
-
return hit;
|
|
252
|
+
return encodedBudget(hit, request);
|
|
228
253
|
const lock = `${cache}:${maxBytes}:${!!limits.allowSpend}:${limits.timeoutMs ?? 30000}`;
|
|
229
254
|
const existing = inflight.get(lock);
|
|
230
255
|
if (existing) {
|
|
@@ -237,7 +262,7 @@ export class LocalResources {
|
|
|
237
262
|
try {
|
|
238
263
|
const hit = cached();
|
|
239
264
|
if (hit)
|
|
240
|
-
return hit;
|
|
265
|
+
return encodedBudget(hit, request);
|
|
241
266
|
const entry = path.join(dir, `${digest(code)}.mjs`);
|
|
242
267
|
if (!fs.existsSync(entry)) {
|
|
243
268
|
const tmp = `${entry}.${crypto.randomUUID()}.tmp`;
|
|
@@ -303,7 +328,7 @@ export class LocalResources {
|
|
|
303
328
|
fs.writeFileSync(tmp, JSON.stringify({ url, bytes: result.bytes, audio: result.audio, credit: result.credit, license: result.license }));
|
|
304
329
|
fs.renameSync(tmp, cache);
|
|
305
330
|
}
|
|
306
|
-
return { url, bytes: result.bytes, audio: result.audio, credit: result.credit, license: result.license };
|
|
331
|
+
return encodedBudget({ url, bytes: result.bytes, audio: result.audio, credit: result.credit, license: result.license }, request);
|
|
307
332
|
}
|
|
308
333
|
catch (e) {
|
|
309
334
|
const err = e;
|
|
@@ -370,6 +395,7 @@ export async function inlineResources(project, requests, host) {
|
|
|
370
395
|
}
|
|
371
396
|
if (rawBytes)
|
|
372
397
|
diagnostics.push({ severity: 'info', source: 'structure', code: 'MEDIA_BUDGET', message: `All audio: ${rawBytes} raw bytes, ${embeddedBytes} embedded base64/data-URI bytes` });
|
|
398
|
+
diagnostics.push(...mediaBudgetDiagnostics(project, audioInfo));
|
|
373
399
|
return { assets, audioInfo, diagnostics, credits: [...credits], licenses: [...licenses], rawBytes, embeddedBytes };
|
|
374
400
|
}
|
|
375
401
|
export { nodeResourceIds as referencedResources, resolveResourceProps } from '@joplo-app/core';
|
package/dist/media-check.d.ts
CHANGED
|
@@ -2,8 +2,14 @@ import { type Diagnostic, type Project } from '@joplo-app/core';
|
|
|
2
2
|
import type { LocalResourceInfo, ResourceRequest } from '@joplo-app/kit/plugin';
|
|
3
3
|
import type { LocalResources } from './local-resources.js';
|
|
4
4
|
export declare function inspectResources(project: Project | null, requests: ResourceRequest[], host: LocalResources): Promise<{
|
|
5
|
-
resourceInfo: Record<string, LocalResourceInfo
|
|
5
|
+
resourceInfo: Record<string, LocalResourceInfo & {
|
|
6
|
+
encodedBytes?: number;
|
|
7
|
+
}>;
|
|
6
8
|
diagnostics: Diagnostic[];
|
|
7
9
|
}>;
|
|
8
10
|
/** Measure uninterrupted runs, not each individual step. Stop/replacement ends a run. */
|
|
9
11
|
export declare function mediaDiagnostics(project: Project, info: Record<string, LocalResourceInfo>): Diagnostic[];
|
|
12
|
+
/** PCM memory is charged per resource, including both sides of an active crossfade. */
|
|
13
|
+
export declare function mediaBudgetDiagnostics(project: Project, info: Record<string, (LocalResourceInfo | import('@joplo-app/kit/plugin').AudioRegion) & {
|
|
14
|
+
encodedBytes?: number;
|
|
15
|
+
}>): Diagnostic[];
|
package/dist/media-check.js
CHANGED
|
@@ -7,8 +7,9 @@ export async function inspectResources(project, requests, host) {
|
|
|
7
7
|
for (const request of requests)
|
|
8
8
|
if (used.has(request.id)) {
|
|
9
9
|
const result = await host.inspect(request);
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const prepared = await host.prepared(request);
|
|
11
|
+
if (result.info || prepared)
|
|
12
|
+
resourceInfo[request.id] = { ...result.info, ...(prepared?.audio ? { ...prepared.audio, durationMs: prepared.audio.contentFrames / prepared.audio.sourceSampleRate * 1000 } : {}), ...(prepared ? { encodedBytes: prepared.bytes } : {}) };
|
|
12
13
|
if (result.diagnostic)
|
|
13
14
|
diagnostics.push(result.diagnostic);
|
|
14
15
|
}
|
|
@@ -16,7 +17,7 @@ export async function inspectResources(project, requests, host) {
|
|
|
16
17
|
}
|
|
17
18
|
/** Measure uninterrupted runs, not each individual step. Stop/replacement ends a run. */
|
|
18
19
|
export function mediaDiagnostics(project, info) {
|
|
19
|
-
const diagnostics =
|
|
20
|
+
const diagnostics = mediaBudgetDiagnostics(project, info);
|
|
20
21
|
for (const sc of Object.values(project.scenarios)) {
|
|
21
22
|
const runs = new Map();
|
|
22
23
|
const finish = (key) => {
|
|
@@ -56,3 +57,43 @@ export function mediaDiagnostics(project, info) {
|
|
|
56
57
|
}
|
|
57
58
|
return diagnostics;
|
|
58
59
|
}
|
|
60
|
+
/** PCM memory is charged per resource, including both sides of an active crossfade. */
|
|
61
|
+
export function mediaBudgetDiagnostics(project, info) {
|
|
62
|
+
const out = [], budget = 32 * 1024 * 1024;
|
|
63
|
+
const encodedSeen = new Set();
|
|
64
|
+
for (const sc of Object.values(project.scenarios))
|
|
65
|
+
for (const [position, snapshot, at] of [[0, sc.media, undefined], ...sc.steps.map((s, i) => [i + 1, s.media, s.source])]) {
|
|
66
|
+
const ids = [...new Set(Object.values(snapshot ?? {}).filter(t => (t.stopAfterMs ?? 1) > 0 && (t.endAfterMs ?? 1) > 0).map(t => t.resource))].sort();
|
|
67
|
+
const known = ids.filter(id => info[id]?.encodedBytes !== undefined), bytes = known.reduce((n, id) => n + info[id].encodedBytes, 0), key = ids.join(',');
|
|
68
|
+
if (bytes > 4 * 1048576 && !encodedSeen.has(key)) {
|
|
69
|
+
encodedSeen.add(key);
|
|
70
|
+
out.push({ code: 'MEDIA_ENCODE_BUDGET', severity: 'warning', source: 'structure', at, message: `${sc.id} position ${position}: planned simultaneous encoded audio [${ids.join(', ')}] needs ${bytes} bytes (${(bytes / 1048576).toFixed(2)} MiB), exceeding the 4 MiB encoded cache${known.length < ids.length ? '; additional resources unknown' : ''}. Transcode large WAV/PCM to lossless FLAC or another smaller supported format; the decoded 32 MiB budget is independent.` });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
for (const sc of Object.values(project.scenarios)) {
|
|
74
|
+
const seen = new Set();
|
|
75
|
+
for (const [position, snapshot, at] of [[0, sc.media, undefined], ...sc.steps.map((s, i) => [i + 1, s.media, s.source])]) {
|
|
76
|
+
const ids = [...new Set(Object.values(snapshot ?? {}).filter(t => (t.stopAfterMs === undefined || t.stopAfterMs > 0) && (t.endAfterMs === undefined || t.endAfterMs > 0)).map(t => t.resource))].sort();
|
|
77
|
+
const key = ids.join(',');
|
|
78
|
+
if (!key || seen.has(key))
|
|
79
|
+
continue;
|
|
80
|
+
seen.add(key);
|
|
81
|
+
let known = 0;
|
|
82
|
+
const bytes = (rate) => ids.reduce((sum, id) => {
|
|
83
|
+
const m = info[id];
|
|
84
|
+
if (!m)
|
|
85
|
+
return sum;
|
|
86
|
+
const seconds = 'decodedFrames' in m ? m.decodedFrames / m.sourceSampleRate : (m.durationMs ?? 0) / 1000;
|
|
87
|
+
if (seconds > 0 && rate === 48000)
|
|
88
|
+
known++;
|
|
89
|
+
return sum + Math.ceil(seconds * rate) * ('channels' in m ? m.channels : 2) * 4;
|
|
90
|
+
}, 0);
|
|
91
|
+
const at48 = bytes(48000), at96 = bytes(96000);
|
|
92
|
+
const code = at48 > budget ? 'MEDIA_DECODE_BUDGET' : at96 > budget ? 'MEDIA_DECODE_HEADROOM' : null;
|
|
93
|
+
if (code)
|
|
94
|
+
out.push({ code, severity: 'warning', source: 'structure', at,
|
|
95
|
+
message: `${sc.id} position ${position}: planned simultaneous audio [${ids.join(', ')}] needs ${(at48 / 1048576).toFixed(2)} MiB at 48 kHz and ${(at96 / 1048576).toFixed(2)} MiB at 96 kHz (32 MiB decoded budget${known < ids.length ? '; some resources unknown' : ''}). Shorten overlapping tracks or avoid crossfading them; snapshot overlap is planned (actual narration can change retirement timing); device sample rate and decoder padding affect usage.` });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** Publish only complete files; exclusive link avoids an overwrite race between CLI processes. */
|
|
2
|
+
export declare function commitOutput(temporary: string, destination: string, overwrite?: boolean): Promise<void>;
|
|
3
|
+
export declare function writeOutput(destination: string, bytes: Uint8Array | string, overwrite?: boolean): Promise<void>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
/** Publish only complete files; exclusive link avoids an overwrite race between CLI processes. */
|
|
5
|
+
export async function commitOutput(temporary, destination, overwrite = false) {
|
|
6
|
+
if (overwrite)
|
|
7
|
+
await fs.rename(temporary, destination);
|
|
8
|
+
else {
|
|
9
|
+
await fs.link(temporary, destination);
|
|
10
|
+
await fs.unlink(temporary);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export async function writeOutput(destination, bytes, overwrite = false) {
|
|
14
|
+
await fs.mkdir(path.dirname(destination), { recursive: true });
|
|
15
|
+
const temporary = path.join(path.dirname(destination), `.${path.basename(destination)}.${randomUUID()}.tmp`);
|
|
16
|
+
try {
|
|
17
|
+
await fs.writeFile(temporary, bytes, { flag: 'wx' });
|
|
18
|
+
await commitOutput(temporary, destination, overwrite);
|
|
19
|
+
}
|
|
20
|
+
finally {
|
|
21
|
+
await fs.rm(temporary, { force: true });
|
|
22
|
+
}
|
|
23
|
+
}
|
package/dist/project.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export type CompileOutcome = {
|
|
|
11
11
|
home: string | null;
|
|
12
12
|
/** 启用的插件(D86):插件 id → 运行时入口的绝对路径(看板按它载入,build 按它打包)。 */
|
|
13
13
|
pluginRuntimes: Record<string, string>;
|
|
14
|
+
watchIgnore?: string[];
|
|
14
15
|
resources?: {
|
|
15
16
|
requests: ResourceRequest[];
|
|
16
17
|
host: LocalResources;
|
|
@@ -18,7 +19,10 @@ export type CompileOutcome = {
|
|
|
18
19
|
};
|
|
19
20
|
/** config({ plugins }) 里每个插件的运行时入口(编译器另外校验清单;这里只取存在的文件)。 */
|
|
20
21
|
export declare function pluginRuntimesOf(plugins: unknown): Record<string, string>;
|
|
21
|
-
export declare function compileProject(server: ViteDevServer, projectDir: string, mode: CompileMode
|
|
22
|
+
export declare function compileProject(server: ViteDevServer, projectDir: string, mode: CompileMode, options?: {
|
|
23
|
+
work?: string;
|
|
24
|
+
voiceDefault?: string | null;
|
|
25
|
+
}): Promise<CompileOutcome>;
|
|
22
26
|
/** 让项目源文件在下次载入时重新转译、重新求值。 */
|
|
23
27
|
export declare function invalidateProjectModules(server: ViteDevServer, projectDir: string): void;
|
|
24
28
|
export { discoverFiles };
|
package/dist/project.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* dev(看板、截图)与 build(发布站)共用这一条路径。
|
|
4
4
|
*/
|
|
5
5
|
import fs from 'node:fs';
|
|
6
|
+
import { readAudioTiming } from "./audio-timing.js";
|
|
7
|
+
import { watchConfigDiagnostics } from "./watch-config.js";
|
|
6
8
|
import path from 'node:path';
|
|
7
9
|
import { inspectResources, mediaDiagnostics } from "./media-check.js";
|
|
8
10
|
import { LocalResources, referencedResources } from "./local-resources.js";
|
|
@@ -51,7 +53,7 @@ function jsxRuntimeMissing(e) {
|
|
|
51
53
|
return /\.(tsx|jsx)$/.test(file) && !file.split(path.sep).includes('node_modules') ? file : false;
|
|
52
54
|
}
|
|
53
55
|
const JSX_HINT = "was compiled without Joplo's JSX runtime. TSX outside the project uses the JSX settings of its nearest tsconfig.json: give that folder a tsconfig.json with jsx: \"react-jsxdev\" and jsxImportSource: \"@joplo-app/kit\", or start the file with /** @jsxRuntime automatic */ /** @jsxImportSource @joplo-app/kit */";
|
|
54
|
-
export async function compileProject(server, projectDir, mode) {
|
|
56
|
+
export async function compileProject(server, projectDir, mode, options = {}) {
|
|
55
57
|
const errorAt = new Map(); // 载入失败的文件(绝对路径)→ 精确位置
|
|
56
58
|
const importer = async (abs) => {
|
|
57
59
|
try {
|
|
@@ -74,7 +76,7 @@ export async function compileProject(server, projectDir, mode) {
|
|
|
74
76
|
throw e instanceof Error ? e : new Error(msg);
|
|
75
77
|
}
|
|
76
78
|
};
|
|
77
|
-
const loaded = await loadAuthoring(projectDir, importer);
|
|
79
|
+
const loaded = await loadAuthoring(projectDir, importer, options);
|
|
78
80
|
const rel = (abs) => path.relative(projectDir, abs).split(path.sep).join('/');
|
|
79
81
|
const byRel = new Map([...errorAt].map(([abs, at]) => [rel(abs), at]));
|
|
80
82
|
const seen = new Set();
|
|
@@ -100,6 +102,7 @@ export async function compileProject(server, projectDir, mode) {
|
|
|
100
102
|
}
|
|
101
103
|
if (!loaded.authoring)
|
|
102
104
|
return { project: null, diagnostics, home: null, pluginRuntimes: {} };
|
|
105
|
+
diagnostics.push(...watchConfigDiagnostics(loaded.authoring.config.watch, loaded.authoring.config.source));
|
|
103
106
|
const home = loaded.authoring.config.home ?? null;
|
|
104
107
|
const pluginRuntimes = pluginRuntimesOf(loaded.authoring.config.plugins);
|
|
105
108
|
if (diagnostics.some((d) => d.severity === 'error'))
|
|
@@ -137,16 +140,29 @@ export async function compileProject(server, projectDir, mode) {
|
|
|
137
140
|
const checked = inspected;
|
|
138
141
|
knownInfo.set(projectDir, new Map(requests.flatMap(request => checked.resourceInfo[request.id] ? [[requestKey(request), checked.resourceInfo[request.id]]] : [])));
|
|
139
142
|
const resources = { requests, host };
|
|
140
|
-
diagnostics.push(...inspected.diagnostics
|
|
143
|
+
diagnostics.push(...inspected.diagnostics);
|
|
141
144
|
const missing = Object.keys(r.project?.plugins ?? {}).filter((id) => !pluginRuntimes[id]);
|
|
142
145
|
const extra = missing.map((id) => ({ severity: 'error', code: 'PLUGIN_RUNTIME_MISSING', message: `Plugin ${id}: runtime file not found; reinstall the plugin package`, source: 'reference', at: `${loaded.authoring.config.file}:1:1` }));
|
|
146
|
+
const timingAssets = { ...r.project?.mediaAssets };
|
|
147
|
+
const timingInfo = { ...r.project?.mediaInfo };
|
|
143
148
|
for (const request of requests)
|
|
144
149
|
if (referencedResources(r.project).has(request.id)) {
|
|
145
150
|
const result = await resources.host.ensure(request);
|
|
146
151
|
if (result.diagnostic)
|
|
147
152
|
diagnostics.push(result.diagnostic);
|
|
153
|
+
if (result.url)
|
|
154
|
+
timingAssets[request.id] = result.url;
|
|
155
|
+
if (result.audio)
|
|
156
|
+
timingInfo[request.id] = result.audio;
|
|
148
157
|
}
|
|
149
|
-
|
|
158
|
+
if (r.project && Object.values(r.project.scenarios).some(sc => sc.steps.some(st => st.audio || st.holdFor))) {
|
|
159
|
+
const timing = await readAudioTiming(projectDir, { ...r.project, mediaAssets: timingAssets, mediaInfo: timingInfo }, { voiceConfig: loaded.authoring.config.voice, defaultProfile: options.voiceDefault });
|
|
160
|
+
diagnostics.push(...timing.diagnostics);
|
|
161
|
+
r = compile(loaded.authoring, mode, { resourceInfo: inspected.resourceInfo, audioDurationFor: timing.audioDurationFor, voiceDurationFor: timing.voiceDurationFor });
|
|
162
|
+
}
|
|
163
|
+
if (r.project)
|
|
164
|
+
diagnostics.push(...mediaDiagnostics(r.project, inspected.resourceInfo));
|
|
165
|
+
return { watchIgnore: loaded.authoring.config.watch?.ignore, project: extra.length || diagnostics.some(d => d.severity === 'error') ? null : r.project, diagnostics: [...diagnostics, ...r.diagnostics, ...extra], home, pluginRuntimes, resources };
|
|
150
166
|
}
|
|
151
167
|
const requestKey = (request) => JSON.stringify([request.plugin, request.compiler, request.input]);
|
|
152
168
|
/** 项目目录 → 上一次编译检查到的资源元数据(按请求内容)。只是让第一遍编译用得上的提示;每次编译仍会重新检查并核对。 */
|
package/dist/render.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export { loadPlaywright, type PlaywrightModule } from './export-runtime.js';
|
|
|
6
6
|
/** 浏览器启动失败时的一行提示(托管运行时与项目里的 Playwright 都适用:重装 Joplo 自己的导出组件)。 */
|
|
7
7
|
export declare function launchHint(e: unknown): string;
|
|
8
8
|
export declare function launch({ chromium }: PlaywrightModule): Promise<Browser>;
|
|
9
|
+
/** 截图不得覆盖项目源文件或 .joplo/(即使传了 overwrite)。 */
|
|
10
|
+
export declare function assertNotProjectData(projectDir: string, out: string): void;
|
|
9
11
|
/**
|
|
10
12
|
* 渲染路由的参数(纯函数):主题必填(调用方缺省时传项目主题);字体与线条(D55)只在指定且合法时带上,
|
|
11
13
|
* 缺省 = 跟随主题,与 D55 之前的截图一致。
|