@projektemacher/vivliostyle-batch-cli 0.3.0 → 0.3.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/README.md +5 -0
- package/dist/index.d.ts +19 -1
- package/dist/vivliostyle-batch-cli.js +413 -20
- package/package.json +4 -4
- package/src/metadata.ts +9 -1
- package/src/render/pdf-postprocess.ts +83 -10
- package/src/render/pdf-validate.ts +185 -0
- package/src/render/pdf.ts +56 -2
- package/src/render/srgb.icc +0 -0
- package/src/render/verapdf.ts +56 -0
- package/src/render/xmp.ts +12 -0
- package/src/vivliostyle-cli.ts +88 -10
package/src/vivliostyle-cli.ts
CHANGED
|
@@ -36,9 +36,14 @@ type CliOptions = {
|
|
|
36
36
|
subject?: string;
|
|
37
37
|
keywords?: string;
|
|
38
38
|
language?: string;
|
|
39
|
+
created?: string;
|
|
40
|
+
modified?: string;
|
|
39
41
|
pdfa?: string;
|
|
40
42
|
pdfx?: string;
|
|
41
43
|
iccProfile?: string;
|
|
44
|
+
/** Commander's negatable form of --no-validate. */
|
|
45
|
+
validate?: boolean;
|
|
46
|
+
verapdf?: boolean;
|
|
42
47
|
static: string[];
|
|
43
48
|
scripts: boolean;
|
|
44
49
|
format: string;
|
|
@@ -67,6 +72,8 @@ export type HtmlRewriteOptions = {
|
|
|
67
72
|
dumpDir?: string | null;
|
|
68
73
|
/** Let the browser load references without a local file from the web. */
|
|
69
74
|
fetchMissing?: boolean;
|
|
75
|
+
/** Origins mapped via --asset-base; page-script fetches route to the server. */
|
|
76
|
+
mappedOrigins?: string[];
|
|
70
77
|
/** Delay pagination until the page's own async work finished. */
|
|
71
78
|
settle?: SettleGate | null;
|
|
72
79
|
/** Origin that page-script requests are routed to. */
|
|
@@ -149,6 +156,13 @@ export type RuntimeScriptOptions = {
|
|
|
149
156
|
origin: string;
|
|
150
157
|
documentBaseUrl: string;
|
|
151
158
|
gate: SettleGate | null;
|
|
159
|
+
/**
|
|
160
|
+
* Origins mapped via --asset-base. Page scripts fetch data from these
|
|
161
|
+
* (the blog's sparql/graph components fetch their datasets from the site
|
|
162
|
+
* origin); routing them to the static server keeps builds deterministic
|
|
163
|
+
* instead of silently depending on the live site.
|
|
164
|
+
*/
|
|
165
|
+
mappedOrigins?: string[];
|
|
152
166
|
/**
|
|
153
167
|
* Open every `<details>` element. Vivliostyle loads the page's scripts itself
|
|
154
168
|
* and only re-dispatches `DOMContentLoaded` on the window, so scripts that
|
|
@@ -202,12 +216,13 @@ export function buildSettleGateImage(origin: string): string {
|
|
|
202
216
|
export function buildRuntimeScript(options: RuntimeScriptOptions): string {
|
|
203
217
|
const { origin, documentBaseUrl, gate } = options;
|
|
204
218
|
const expandDetails = options.expandDetails === true ? EXPAND_DETAILS_SNIPPET : "";
|
|
219
|
+
const mappedOrigins = JSON.stringify(options.mappedOrigins ?? []);
|
|
205
220
|
// Vivliostyle paginates incrementally, so collapsed content has to be opened
|
|
206
221
|
// again while it lays the document out, not just once up front.
|
|
207
222
|
const expandDetailsTick = options.expandDetails === true ? "expandDetails(document);" : "";
|
|
208
223
|
|
|
209
224
|
return `(function(){
|
|
210
|
-
var ORIGIN=${JSON.stringify(origin)},BASE=${JSON.stringify(documentBaseUrl)};
|
|
225
|
+
var ORIGIN=${JSON.stringify(origin)},BASE=${JSON.stringify(documentBaseUrl)},MAPPED_ORIGINS=${mappedOrigins};
|
|
211
226
|
var QUIET=${gate?.quietMs ?? 400},DEADLINE=${gate?.deadlineMs ?? 10000},FRAME_GRACE=3000;
|
|
212
227
|
var pending=0,frames=0,last=0,mutations=0,done=false,longtasks=0;
|
|
213
228
|
// Force preserveDrawingBuffer on every WebGL context the page creates:
|
|
@@ -248,7 +263,13 @@ var state=window.__vivSettle={done:false,reason:null,at:0,pending:0,frames:0,mut
|
|
|
248
263
|
function fix(u){
|
|
249
264
|
if(typeof u!=="string"||u==="")return u;
|
|
250
265
|
if(u.slice(0,2)==="//"||u.charAt(0)==="#"||u.charAt(0)==="?")return u;
|
|
251
|
-
if(/^[a-z][a-z0-9+.-]*:/i.test(u))
|
|
266
|
+
if(/^[a-z][a-z0-9+.-]*:/i.test(u)){
|
|
267
|
+
try{
|
|
268
|
+
var mu=new URL(u);
|
|
269
|
+
if(MAPPED_ORIGINS.indexOf(mu.origin)>=0)return ORIGIN+mu.pathname+mu.search+mu.hash;
|
|
270
|
+
}catch(e){}
|
|
271
|
+
return u;
|
|
272
|
+
}
|
|
252
273
|
return u.charAt(0)==="/"?ORIGIN+u:BASE+u;
|
|
253
274
|
}
|
|
254
275
|
|
|
@@ -366,6 +387,10 @@ last=performance.now();
|
|
|
366
387
|
// Deterministic pages (charts, WebGL, OSD fixtures) set __vivReady when
|
|
367
388
|
// painted instead of making the gate guess from network quietness. Shader
|
|
368
389
|
// compile and tile decode finish after the last fetch, so readiness wins.
|
|
390
|
+
// An explicit __vivReady=false holds the quiet path too: async tails (module
|
|
391
|
+
// imports, wasm, deferred timers) emit no network signal, so quietness alone
|
|
392
|
+
// would settle on the pre-paint DOM. The deadline above still bounds it.
|
|
393
|
+
if(window.__vivReady===false){setTimeout(check,50);return;}
|
|
369
394
|
if(window.__vivReady===true&&pending===0&&frames===0){signal("ready");return;}
|
|
370
395
|
if(pending===0&&frames===0&&now-last>=QUIET){signal("quiet");return;}
|
|
371
396
|
setTimeout(check,50);
|
|
@@ -1074,7 +1099,13 @@ export function prepareInputHtmlForBuild(
|
|
|
1074
1099
|
const origin = options.shimOrigin ?? serverBaseUrl;
|
|
1075
1100
|
const documentBaseUrl = options.documentBaseUrl ?? `${origin}/`;
|
|
1076
1101
|
// Only the PDF run expands `<details>`; the preview stays interactive.
|
|
1077
|
-
injectRuntimeScriptInDom(document, {
|
|
1102
|
+
injectRuntimeScriptInDom(document, {
|
|
1103
|
+
origin,
|
|
1104
|
+
documentBaseUrl,
|
|
1105
|
+
gate: options.settle ?? null,
|
|
1106
|
+
mappedOrigins: options.mappedOrigins ?? [],
|
|
1107
|
+
expandDetails: true
|
|
1108
|
+
});
|
|
1078
1109
|
log.trace("prepareInputHtmlForBuild: injected runtime script", { origin, documentBaseUrl, gate: options.settle });
|
|
1079
1110
|
}
|
|
1080
1111
|
|
|
@@ -1397,6 +1428,11 @@ function buildProgram(): Command {
|
|
|
1397
1428
|
"--language <lang>",
|
|
1398
1429
|
"Document language tag (e.g. en, de, ja). Taken from the document or manifest when omitted, falling back to 'de'"
|
|
1399
1430
|
)
|
|
1431
|
+
.option(
|
|
1432
|
+
"--created <date>",
|
|
1433
|
+
"Document creation date (ISO 8601, e.g. 2024-11-18T00:00:00+01:00). Taken from the document's dcterms.created meta tag when omitted"
|
|
1434
|
+
)
|
|
1435
|
+
.option("--modified <date>", "Document modification date (ISO 8601). Taken from the document's dcterms.modified meta tag when omitted")
|
|
1400
1436
|
.option(
|
|
1401
1437
|
"--pdfa <level>",
|
|
1402
1438
|
[
|
|
@@ -1417,6 +1453,21 @@ function buildProgram(): Command {
|
|
|
1417
1453
|
"Same label-only semantics as --pdfa."
|
|
1418
1454
|
].join("\n ")
|
|
1419
1455
|
)
|
|
1456
|
+
.option(
|
|
1457
|
+
"--no-validate",
|
|
1458
|
+
[
|
|
1459
|
+
"Skip the built-in compliance checks run for --pdfa/--pdfx output:",
|
|
1460
|
+
"PDF version of the labeled part, XMP identification, OutputIntent,",
|
|
1461
|
+
"file identifier, embedded fonts and the absence of JavaScript."
|
|
1462
|
+
].join("\n ")
|
|
1463
|
+
)
|
|
1464
|
+
.option(
|
|
1465
|
+
"--verapdf",
|
|
1466
|
+
[
|
|
1467
|
+
"Additionally run the verapdf binary (must be on the PATH) against the",
|
|
1468
|
+
"output and fail the build on full ISO rule-set violations."
|
|
1469
|
+
].join("\n ")
|
|
1470
|
+
)
|
|
1420
1471
|
.option(
|
|
1421
1472
|
"--icc-profile <path>",
|
|
1422
1473
|
[
|
|
@@ -1539,9 +1590,11 @@ function buildProgram(): Command {
|
|
|
1539
1590
|
" • the browser prints that page to PDF, so canvases and iframes stay real content.",
|
|
1540
1591
|
" • Collapsed <details> content is opened for the PDF; the preview keeps the page as it is.",
|
|
1541
1592
|
" • --asset-base localBase is also a fallback root for CSS-referenced assets.",
|
|
1542
|
-
" • PDF metadata (--title/--author/--subject/--keywords/--language)
|
|
1593
|
+
" • PDF metadata (--title/--author/--subject/--keywords/--language/--created/--modified)",
|
|
1543
1594
|
" • values read from the document or the publication manifest; language falls",
|
|
1544
|
-
" • back to 'de'. --pdfa/--pdfx label the output
|
|
1595
|
+
" • back to 'de'. --pdfa/--pdfx label the output; the built-in validation",
|
|
1596
|
+
" • checks the practical subset (--no-validate skips it) and --verapdf runs",
|
|
1597
|
+
" • the full ISO rule set through the verapdf binary."
|
|
1545
1598
|
].join("\n")
|
|
1546
1599
|
);
|
|
1547
1600
|
}
|
|
@@ -1576,7 +1629,7 @@ export function parseArgs(argv: string[]): {
|
|
|
1576
1629
|
// ---------------------------------------------------------------------------
|
|
1577
1630
|
|
|
1578
1631
|
/** Metadata fields the CLI layer resolves before handing them to the renderer. */
|
|
1579
|
-
type MetadataFieldName = "title" | "author" | "subject" | "keywords" | "language";
|
|
1632
|
+
type MetadataFieldName = "title" | "author" | "subject" | "keywords" | "language" | "created" | "modified";
|
|
1580
1633
|
|
|
1581
1634
|
/** ICC profile bytes with the name they get in the PDF's OutputIntent. */
|
|
1582
1635
|
type IccProfile = { bytes: Uint8Array; name: string };
|
|
@@ -1593,6 +1646,10 @@ type RenderParams = {
|
|
|
1593
1646
|
canvasScale?: number;
|
|
1594
1647
|
pdfLabel?: PdfLabel;
|
|
1595
1648
|
iccProfile?: IccProfile;
|
|
1649
|
+
/** Run the built-in compliance checks for the label (default: on). */
|
|
1650
|
+
validate: boolean;
|
|
1651
|
+
/** Additionally run the verapdf binary against the output. */
|
|
1652
|
+
verapdf?: boolean;
|
|
1596
1653
|
};
|
|
1597
1654
|
|
|
1598
1655
|
async function runRender(params: RenderParams): Promise<void> {
|
|
@@ -1610,8 +1667,12 @@ async function runRender(params: RenderParams): Promise<void> {
|
|
|
1610
1667
|
...(params.metaFields.subject === undefined ? {} : { subject: params.metaFields.subject }),
|
|
1611
1668
|
...(params.metaFields.keywords === undefined ? {} : { keywords: params.metaFields.keywords }),
|
|
1612
1669
|
...(params.metaFields.language === undefined ? {} : { language: params.metaFields.language }),
|
|
1670
|
+
...(params.metaFields.created === undefined ? {} : { created: params.metaFields.created }),
|
|
1671
|
+
...(params.metaFields.modified === undefined ? {} : { modified: params.metaFields.modified }),
|
|
1613
1672
|
...(params.pdfLabel === undefined ? {} : { pdfLabel: params.pdfLabel }),
|
|
1614
|
-
...(params.iccProfile === undefined ? {} : { iccProfile: params.iccProfile.bytes, iccProfileName: params.iccProfile.name })
|
|
1673
|
+
...(params.iccProfile === undefined ? {} : { iccProfile: params.iccProfile.bytes, iccProfileName: params.iccProfile.name }),
|
|
1674
|
+
validate: params.validate,
|
|
1675
|
+
...(params.verapdf === undefined ? {} : { verapdf: params.verapdf })
|
|
1615
1676
|
};
|
|
1616
1677
|
|
|
1617
1678
|
log.trace("renderPdf request", request);
|
|
@@ -1721,11 +1782,19 @@ export function resolveIccProfile(options: Pick<CliOptions, "iccProfile">, label
|
|
|
1721
1782
|
* to "de" when no source provides one.
|
|
1722
1783
|
*/
|
|
1723
1784
|
export function resolvePdfMetadata(
|
|
1724
|
-
options: Pick<CliOptions, "title" | "author" | "subject" | "keywords" | "language">,
|
|
1785
|
+
options: Pick<CliOptions, "title" | "author" | "subject" | "keywords" | "language" | "created" | "modified">,
|
|
1725
1786
|
inputAbs: string,
|
|
1726
1787
|
htmlMode: boolean
|
|
1727
1788
|
): DocumentMetadata & { language: string } {
|
|
1728
|
-
const cliFields = pickDefinedStrings(options, [
|
|
1789
|
+
const cliFields = pickDefinedStrings(options, [
|
|
1790
|
+
"title",
|
|
1791
|
+
"author",
|
|
1792
|
+
"subject",
|
|
1793
|
+
"keywords",
|
|
1794
|
+
"language",
|
|
1795
|
+
"created",
|
|
1796
|
+
"modified"
|
|
1797
|
+
]) as DocumentMetadata;
|
|
1729
1798
|
let derived: DocumentMetadata | undefined;
|
|
1730
1799
|
if (htmlMode) {
|
|
1731
1800
|
derived = extractMetadataFromDocument(new JSDOM(readFileSync(inputAbs, "utf-8")).window.document);
|
|
@@ -1844,6 +1913,9 @@ export async function execute(options: CliOptions, extraArgs: string[] = []): Pr
|
|
|
1844
1913
|
if (options.iccProfile !== undefined && pdfLabel === undefined) {
|
|
1845
1914
|
log.warn("[pdf] --icc-profile has no effect without --pdfa or --pdfx");
|
|
1846
1915
|
}
|
|
1916
|
+
if (options.verapdf === true && pdfLabel === undefined) {
|
|
1917
|
+
log.warn("[pdf] --verapdf has no effect without --pdfa or --pdfx");
|
|
1918
|
+
}
|
|
1847
1919
|
const iccProfile = resolveIccProfile(options, pdfLabel);
|
|
1848
1920
|
|
|
1849
1921
|
const fetchMissing = options.fetchMissing === true || options.allowRemote === true;
|
|
@@ -1858,6 +1930,10 @@ export async function execute(options: CliOptions, extraArgs: string[] = []): Pr
|
|
|
1858
1930
|
fetchMissing,
|
|
1859
1931
|
dumpDir: options.dumpHtml ?? null,
|
|
1860
1932
|
settle,
|
|
1933
|
+
// Page scripts fetch their data from the mapped origins (the blog's
|
|
1934
|
+
// sparql/graph components); route those to the static server so builds
|
|
1935
|
+
// stay deterministic instead of hitting the live site.
|
|
1936
|
+
mappedOrigins: [...new Set(assetBases.map((base) => new URL(base.urlBase).origin))],
|
|
1861
1937
|
...(typeof extraConfig.css === "string" ? { css: extraConfig.css } : {}),
|
|
1862
1938
|
...(typeof extraConfig.userStyle === "string" ? { userStyle: extraConfig.userStyle } : {})
|
|
1863
1939
|
};
|
|
@@ -1957,7 +2033,9 @@ export async function execute(options: CliOptions, extraArgs: string[] = []): Pr
|
|
|
1957
2033
|
chromeExecutable: typeof extraConfig.executableBrowser === "string" ? extraConfig.executableBrowser : undefined,
|
|
1958
2034
|
canvasScale,
|
|
1959
2035
|
...(pdfLabel === undefined ? {} : { pdfLabel }),
|
|
1960
|
-
...(iccProfile === undefined ? {} : { iccProfile })
|
|
2036
|
+
...(iccProfile === undefined ? {} : { iccProfile }),
|
|
2037
|
+
validate: options.validate !== false,
|
|
2038
|
+
...(options.verapdf === true ? { verapdf: true } : {})
|
|
1961
2039
|
});
|
|
1962
2040
|
} finally {
|
|
1963
2041
|
htmlResource.cleanup();
|