gutterpress 0.11.23-alpha.7 → 0.11.23-beta.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/README.md +2 -0
- package/dist/{README-syg2hn83.md → README-8rct3axy.md} +2 -2
- package/dist/api/index.d.ts +3 -3
- package/dist/api/index.js +7 -5
- package/dist/{build-w572wq10.js → build-dg8a566j.js} +8 -7
- package/dist/{cli-eatdqx3z.js → cli-1fy1pm9d.js} +1 -1
- package/dist/cli-65gy8ask.js +82 -0
- package/dist/{cli-3cvq3n1c.js → cli-989eg8jz.js} +186 -83
- package/dist/{cli-6pv84kf3.js → cli-e31jshz6.js} +6 -84
- package/dist/{cli-58fsk6d7.js → cli-k087gj0p.js} +66 -34
- package/dist/{cli-5ba6bm6z.js → cli-s1zt779w.js} +1 -1
- package/dist/{cli-wyg7qstd.js → cli-ttj95aex.js} +3 -3
- package/dist/{cli-mmgtqnmr.js → cli-vhav8g82.js} +1 -1
- package/dist/cli.js +12 -12
- package/dist/{doctor-2f3zqmza.js → doctor-g4a42tcz.js} +3 -3
- package/dist/engine/shared/page-vars.d.ts +32 -0
- package/dist/{engine-4rabsgwq.js → engine-jvkcahr1.js} +2 -1
- package/dist/{engine-wm4fggac.js → engine-wgkaqjsc.js} +3 -3
- package/dist/{ext-0cgky8n3.js → ext-w9d5ftcg.js} +8 -7
- package/dist/{extension-restore-vghc58vx.js → extension-restore-5x4mj79d.js} +3 -3
- package/dist/{extension-restore-e7je32pr.js → extension-restore-as0g38p1.js} +5 -4
- package/dist/{gutterpress-viewer-mafsby5k.js → gutterpress-viewer-ze691rrd.js} +52 -13
- package/dist/{index-2vxzxyyj.js → index-798jt0qc.js} +9 -9
- package/dist/{index-fp7xwvpr.js → index-a4j3xcfp.js} +3 -3
- package/dist/{index-nfysshcc.js → index-c6y0p7jy.js} +249 -139
- package/dist/{index-wm4x7xbf.js → index-fk2kpf2t.js} +58 -26
- package/dist/{index-hphcn7th.js → index-rj5vrhz6.js} +5 -85
- package/dist/index-tayzfr9c.js +99 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +233 -6
- package/dist/lib/book-css.d.ts +56 -0
- package/dist/lib/markdown/assemble.d.ts +58 -0
- package/dist/lib/publish/google-drive.d.ts +12 -4
- package/dist/lib/publish/manifest-publish.d.ts +6 -0
- package/dist/lib/publish/providers/gdrive-folder.d.ts +30 -0
- package/dist/lib/publish/run-publish.d.ts +6 -1
- package/dist/lib/publish/types.d.ts +52 -5
- package/dist/lib/remote-auth/converge-merge.d.ts +3 -3
- package/dist/lib/remote-auth/sync-messages.d.ts +2 -2
- package/dist/lib/root-tokens.d.ts +76 -0
- package/dist/lib/version-changes.d.ts +12 -12
- package/dist/{manifest-79zsgkpn.yaml → manifest-0vwaskj2.yaml} +1 -1
- package/dist/{manifest-2kc56wvw.yaml → manifest-aya31jwt.yaml} +1 -1
- package/dist/{manifest-41ddzm13.yaml → manifest-mffah3hr.yaml} +1 -1
- package/dist/{manifest-sqzm4681.yaml → manifest-wbcv8cbp.yaml} +2 -2
- package/dist/{manifest.schema-93sd7zje.json → manifest.schema-0jgj0jt1.json} +1 -1
- package/dist/{new-88rkrv71.js → new-jtk028rf.js} +8 -7
- package/dist/{page-rules-ytj9p04v.css → page-rules-vnja6grt.css} +2 -2
- package/dist/{plugins-3aj0wc5h.js → plugins-bcbe7xs8.js} +1 -1
- package/dist/{plugins-sprxsz5d.js → plugins-zsm6wv79.js} +3 -3
- package/dist/{preflight-11dg1qkk.js → preflight-cs6mj1d6.js} +8 -7
- package/dist/{preview-nftp782j.js → preview-d1j1g4qf.js} +8 -7
- package/dist/{publish-6tgxfck9.js → publish-7yw4jyrt.js} +24 -8
- package/dist/render.js +65 -24
- package/dist/schema/manifest.types.d.ts +2 -1
- package/dist/{tokens-n82t4k9h.css → tokens-a7grv940.css} +4 -5
- package/dist/{validate-pktqrye5.js → validate-rkcdnzhw.js} +8 -7
- package/package.json +1 -1
- package/dist/index-46ycxe6r.js +0 -18
|
@@ -19,7 +19,10 @@ import {
|
|
|
19
19
|
stringValueAt,
|
|
20
20
|
toFolioPage,
|
|
21
21
|
wantsRecto
|
|
22
|
-
} from "./index-
|
|
22
|
+
} from "./index-798jt0qc.js";
|
|
23
|
+
import {
|
|
24
|
+
round3
|
|
25
|
+
} from "./index-tayzfr9c.js";
|
|
23
26
|
import {
|
|
24
27
|
launchChromium
|
|
25
28
|
} from "./index-bt0qws5c.js";
|
|
@@ -86,6 +89,33 @@ function marginBoxesOnEdges(edges) {
|
|
|
86
89
|
return Object.entries(owners).filter(([, own]) => own.some((e) => edges.includes(e))).map(([name]) => name);
|
|
87
90
|
}
|
|
88
91
|
|
|
92
|
+
// src/engine/shared/page-vars.ts
|
|
93
|
+
var decls = (pairs) => pairs.map(([name, n]) => `--gp-page-${name}: ${round3(n)}pt;`).join(" ");
|
|
94
|
+
function pageDecls(model, name) {
|
|
95
|
+
const { width, height, margin } = resolvePage(model, { name, pseudos: ["right"] }).geometry;
|
|
96
|
+
return decls([
|
|
97
|
+
["width", width],
|
|
98
|
+
["height", height],
|
|
99
|
+
["margin-top", margin.top],
|
|
100
|
+
["margin-bottom", margin.bottom],
|
|
101
|
+
["margin-inside", margin.left],
|
|
102
|
+
["margin-outside", margin.right]
|
|
103
|
+
]);
|
|
104
|
+
}
|
|
105
|
+
function pageGeometryVarsCss(model, area) {
|
|
106
|
+
const bookWide = decls([
|
|
107
|
+
["bleed", area?.bleed ?? 0],
|
|
108
|
+
["safe", area?.safe ?? 0],
|
|
109
|
+
["gutter", area?.gutter ?? 0],
|
|
110
|
+
["art-safe", area?.artSafe ?? 0]
|
|
111
|
+
]);
|
|
112
|
+
return [
|
|
113
|
+
`:root { ${pageDecls(model)} ${bookWide} }`,
|
|
114
|
+
...model.pageAssignments.map((a) => `${a.selector} { ${pageDecls(model, a.page)} }`)
|
|
115
|
+
].join(`
|
|
116
|
+
`);
|
|
117
|
+
}
|
|
118
|
+
|
|
89
119
|
// src/engine/shared/content-value.ts
|
|
90
120
|
var FUNC = /^([a-z-]+)\(/i;
|
|
91
121
|
function parseContent(value) {
|
|
@@ -442,9 +472,9 @@ function pseudoVariants(model) {
|
|
|
442
472
|
function consumedStrings(model) {
|
|
443
473
|
const names = new Set;
|
|
444
474
|
for (const rule of model.pageRules)
|
|
445
|
-
for (const
|
|
446
|
-
if (
|
|
447
|
-
for (const part of parseContent(
|
|
475
|
+
for (const decls2 of Object.values(rule.marginBoxes))
|
|
476
|
+
if (decls2.content) {
|
|
477
|
+
for (const part of parseContent(decls2.content))
|
|
448
478
|
if (part.type === "string")
|
|
449
479
|
names.add(part.name);
|
|
450
480
|
}
|
|
@@ -788,7 +818,8 @@ async function build(opts) {
|
|
|
788
818
|
key: root.key
|
|
789
819
|
});
|
|
790
820
|
}
|
|
791
|
-
const printArea =
|
|
821
|
+
const printArea = await page.evaluate(`window.__gp.printArea()`);
|
|
822
|
+
const geometryVarsCss = pageGeometryVarsCss(model, printArea);
|
|
792
823
|
const pinStyle = (group, pseudos) => pinRootStyle(resolvePage(model, { name: group.authorPage, pseudos }).geometry.margin, printArea, pseudos.includes("left") ? "verso" : "recto", group.edges, group.padding);
|
|
793
824
|
if (pinGroups.size) {
|
|
794
825
|
const lines = [];
|
|
@@ -808,11 +839,11 @@ async function build(opts) {
|
|
|
808
839
|
const body = [];
|
|
809
840
|
for (const [prop, value] of Object.entries(rule.decls))
|
|
810
841
|
body.push(` ${prop}: ${value};`);
|
|
811
|
-
for (const [box,
|
|
842
|
+
for (const [box, decls2] of Object.entries(rule.marginBoxes)) {
|
|
812
843
|
if (relocated.has(box.slice(1)))
|
|
813
844
|
continue;
|
|
814
845
|
body.push(` ${box} {`);
|
|
815
|
-
for (const [prop, value] of Object.entries(
|
|
846
|
+
for (const [prop, value] of Object.entries(decls2))
|
|
816
847
|
body.push(` ${prop}: ${value};`);
|
|
817
848
|
body.push(` }`);
|
|
818
849
|
}
|
|
@@ -855,11 +886,12 @@ ${pinCss}`);
|
|
|
855
886
|
const minContentHeightPx = Math.min(contentHeightPt(), ...model.pageNames.map((name) => contentHeightPt(name))) * 96 / 72;
|
|
856
887
|
const pageVarsCss = [
|
|
857
888
|
`:root { --gp-content-h: ${contentHeightPx}px; }`,
|
|
858
|
-
...model.pageAssignments.map((a) => `${a.selector} { --gp-content-h: ${namedContentHeightsPx[a.page] ?? contentHeightPx}px; }`)
|
|
889
|
+
...model.pageAssignments.map((a) => `${a.selector} { --gp-content-h: ${namedContentHeightsPx[a.page] ?? contentHeightPx}px; }`),
|
|
890
|
+
geometryVarsCss
|
|
859
891
|
].join(`
|
|
860
892
|
`);
|
|
861
893
|
await page.evaluate(`window.__gp.addCss("gp-page-vars", ${JSON.stringify(pageVarsCss)})`);
|
|
862
|
-
log(`page geometry published (--gp-content-h: ${Math.round(contentHeightPx)}px)`);
|
|
894
|
+
log(`page geometry published (--gp-content-h: ${Math.round(contentHeightPx)}px, --gp-page-*)`);
|
|
863
895
|
const relocationBoxes = (group, pseudos) => {
|
|
864
896
|
const ctx = resolvePage(model, { name: group.authorPage, pseudos });
|
|
865
897
|
return marginBoxesOnEdges(group.edges).map((name) => [name, ctx.marginBoxes[`@${name}`]]).filter((pair) => {
|
|
@@ -1063,8 +1095,8 @@ ${mapCss}`;
|
|
|
1063
1095
|
const g = ctx.geometry;
|
|
1064
1096
|
const eff = flushMargins(g.margin, group.edges);
|
|
1065
1097
|
const boxes = [];
|
|
1066
|
-
for (const [name,
|
|
1067
|
-
const text = evaluate(
|
|
1098
|
+
for (const [name, decls2] of relocationBoxes(group, pseudos)) {
|
|
1099
|
+
const text = evaluate(decls2.content, {
|
|
1068
1100
|
page: toFolioPage(physical, pageValues),
|
|
1069
1101
|
pages: pageCount,
|
|
1070
1102
|
strings: (n, w) => stringValueAt(byName.get(n) ?? [], physical, parseWhich(w)),
|
|
@@ -1076,13 +1108,13 @@ ${mapCss}`;
|
|
|
1076
1108
|
if (!text) {
|
|
1077
1109
|
if (!relocationDiagnosed.has(name)) {
|
|
1078
1110
|
relocationDiagnosed.add(name);
|
|
1079
|
-
diagnose("engine.pin.margin-box", `@${name} sits on an edge a pinned image frees, and its content could not be ` + `re-homed into the page (unsupported content value: ${
|
|
1111
|
+
diagnose("engine.pin.margin-box", `@${name} sits on an edge a pinned image frees, and its content could not be ` + `re-homed into the page (unsupported content value: ${decls2.content}). It will ` + `not print on that page — simplify the box's content, or pin the image to another edge.`);
|
|
1080
1112
|
}
|
|
1081
1113
|
continue;
|
|
1082
1114
|
}
|
|
1083
1115
|
const r = marginBoxRectPt(name, g);
|
|
1084
1116
|
const outDecls = {};
|
|
1085
|
-
for (const [prop, value] of Object.entries(
|
|
1117
|
+
for (const [prop, value] of Object.entries(decls2)) {
|
|
1086
1118
|
if (prop.toLowerCase() === "content" || isIgnoredMarginBoxProperty(prop))
|
|
1087
1119
|
continue;
|
|
1088
1120
|
outDecls[prop] = value;
|
|
@@ -1717,10 +1749,10 @@ function counterStyleCss(model, sources, pageMap, pageCount, resetSites = [], ha
|
|
|
1717
1749
|
return "";
|
|
1718
1750
|
const pairs = new Map;
|
|
1719
1751
|
for (const rule of model.pageRules) {
|
|
1720
|
-
for (const
|
|
1721
|
-
if (!
|
|
1752
|
+
for (const decls2 of Object.values(rule.marginBoxes)) {
|
|
1753
|
+
if (!decls2.content)
|
|
1722
1754
|
continue;
|
|
1723
|
-
for (const part of parseContent(
|
|
1755
|
+
for (const part of parseContent(decls2.content)) {
|
|
1724
1756
|
if (part.type !== "string" || !byName.has(part.name))
|
|
1725
1757
|
continue;
|
|
1726
1758
|
const which = parseWhich(part.which);
|
|
@@ -1759,13 +1791,13 @@ function counterStyleCss(model, sources, pageMap, pageCount, resetSites = [], ha
|
|
|
1759
1791
|
for (const pseudos of variants) {
|
|
1760
1792
|
const resolved = resolvePage(model, { name, pseudos });
|
|
1761
1793
|
const lines = [];
|
|
1762
|
-
for (const [box,
|
|
1763
|
-
if (!
|
|
1794
|
+
for (const [box, decls2] of Object.entries(resolved.marginBoxes)) {
|
|
1795
|
+
if (!decls2.content)
|
|
1764
1796
|
continue;
|
|
1765
|
-
const hasString = /\bstring\s*\(/.test(
|
|
1766
|
-
const hasPageCounter = pageValues && /\bcounter\(\s*page\b(?!s)/.test(
|
|
1797
|
+
const hasString = /\bstring\s*\(/.test(decls2.content);
|
|
1798
|
+
const hasPageCounter = pageValues && /\bcounter\(\s*page\b(?!s)/.test(decls2.content);
|
|
1767
1799
|
const needsRewrite = hasString || hasPageCounter;
|
|
1768
|
-
lines.push(` ${box} { content: ${needsRewrite ? rewrite(
|
|
1800
|
+
lines.push(` ${box} { content: ${needsRewrite ? rewrite(decls2.content) : decls2.content}; }`);
|
|
1769
1801
|
}
|
|
1770
1802
|
if (!lines.length)
|
|
1771
1803
|
continue;
|
|
@@ -1779,13 +1811,13 @@ ${lines.join(`
|
|
|
1779
1811
|
if (hasBlank) {
|
|
1780
1812
|
const blank = resolvePage(model, { pseudos: ["blank"] });
|
|
1781
1813
|
const lines = [];
|
|
1782
|
-
for (const [box,
|
|
1783
|
-
if (!
|
|
1814
|
+
for (const [box, decls2] of Object.entries(blank.marginBoxes)) {
|
|
1815
|
+
if (!decls2.content)
|
|
1784
1816
|
continue;
|
|
1785
|
-
const hasString = /\bstring\s*\(/.test(
|
|
1786
|
-
const hasPageCounter = pageValues && /\bcounter\(\s*page\b(?!s)/.test(
|
|
1817
|
+
const hasString = /\bstring\s*\(/.test(decls2.content);
|
|
1818
|
+
const hasPageCounter = pageValues && /\bcounter\(\s*page\b(?!s)/.test(decls2.content);
|
|
1787
1819
|
const needsRewrite = hasString || hasPageCounter;
|
|
1788
|
-
lines.push(` ${box} { content: ${needsRewrite ? rewrite(
|
|
1820
|
+
lines.push(` ${box} { content: ${needsRewrite ? rewrite(decls2.content) : decls2.content}; }`);
|
|
1789
1821
|
}
|
|
1790
1822
|
out.push(`@page ${BLANK_PAGE} {
|
|
1791
1823
|
${lines.length ? lines.join(`
|
|
@@ -14,11 +14,12 @@ import {
|
|
|
14
14
|
readExtensionMeta,
|
|
15
15
|
resolveExtension,
|
|
16
16
|
slugify
|
|
17
|
-
} from "./index-
|
|
17
|
+
} from "./index-a4j3xcfp.js";
|
|
18
18
|
import {
|
|
19
19
|
BuildError,
|
|
20
|
-
EXIT_CODES
|
|
21
|
-
|
|
20
|
+
EXIT_CODES,
|
|
21
|
+
isNonNegativePoints
|
|
22
|
+
} from "./index-tayzfr9c.js";
|
|
22
23
|
import {
|
|
23
24
|
EXTENSIONS_DIR,
|
|
24
25
|
VENDORED_NPM_DIR,
|
|
@@ -91,87 +92,6 @@ import { existsSync, statSync } from "node:fs";
|
|
|
91
92
|
import { resolve, dirname } from "node:path";
|
|
92
93
|
import { parse as parseYaml, YAMLParseError } from "yaml";
|
|
93
94
|
|
|
94
|
-
// src/engine/shared/print-area.ts
|
|
95
|
-
function isPositivePoints(value) {
|
|
96
|
-
return typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
97
|
-
}
|
|
98
|
-
function isNonNegativePoints(value) {
|
|
99
|
-
return typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
100
|
-
}
|
|
101
|
-
var round3 = (n) => Math.round(n * 1000) / 1000;
|
|
102
|
-
function cssLength(pt) {
|
|
103
|
-
const inches = round3(pt / 72);
|
|
104
|
-
return Math.abs(inches * 72 - pt) < 0.000001 ? `${inches}in` : `${round3(pt)}pt`;
|
|
105
|
-
}
|
|
106
|
-
function formatPageSize(page) {
|
|
107
|
-
return `${cssLength(page.width)} ${cssLength(page.height)}`;
|
|
108
|
-
}
|
|
109
|
-
function printAreaMeta(page) {
|
|
110
|
-
const area = JSON.stringify({
|
|
111
|
-
width: page.width,
|
|
112
|
-
height: page.height,
|
|
113
|
-
bleed: page.bleed ?? 0,
|
|
114
|
-
safe: page.safe ?? 0,
|
|
115
|
-
artSafe: page.artSafe,
|
|
116
|
-
gutter: page.gutter,
|
|
117
|
-
preset: page.preset,
|
|
118
|
-
spec: page.spec
|
|
119
|
-
});
|
|
120
|
-
return `<meta name="gp-print-area" content='${area.replace(/&/g, "&").replace(/'/g, "'")}'>`;
|
|
121
|
-
}
|
|
122
|
-
function pageBoxes(area, side, scale = 1) {
|
|
123
|
-
const w = area.width * scale;
|
|
124
|
-
const h = area.height * scale;
|
|
125
|
-
const b = Math.max(0, area.bleed) * scale;
|
|
126
|
-
const s = Math.max(0, area.safe) * scale;
|
|
127
|
-
const a = Math.max(0, area.artSafe) * scale;
|
|
128
|
-
const g = Math.max(0, area.gutter) * scale;
|
|
129
|
-
const [textLeft, textRight] = side === "verso" ? [s, g] : [g, s];
|
|
130
|
-
const [artLeft, artRight] = side === "verso" ? [a, g] : [g, a];
|
|
131
|
-
const trim = { x: side === "verso" ? b : 0, y: b, w: Math.max(0, w - b), h: Math.max(0, h - 2 * b) };
|
|
132
|
-
return {
|
|
133
|
-
sheet: { x: 0, y: 0, w, h },
|
|
134
|
-
trim,
|
|
135
|
-
safe: {
|
|
136
|
-
x: trim.x + textLeft,
|
|
137
|
-
y: trim.y + s,
|
|
138
|
-
w: Math.max(0, trim.w - textLeft - textRight),
|
|
139
|
-
h: Math.max(0, trim.h - 2 * s)
|
|
140
|
-
},
|
|
141
|
-
safeArt: {
|
|
142
|
-
x: trim.x + artLeft,
|
|
143
|
-
y: trim.y + a,
|
|
144
|
-
w: Math.max(0, trim.w - artLeft - artRight),
|
|
145
|
-
h: Math.max(0, trim.h - 2 * a)
|
|
146
|
-
},
|
|
147
|
-
bleed: b
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
var SEVERITY = { inside: 0, unsafe: 1, bleed: 2, "off-page": 3 };
|
|
151
|
-
function judgeRect(r, boxes, rule, tol = 0) {
|
|
152
|
-
const { sheet, trim } = boxes;
|
|
153
|
-
const safe = rule === "art" ? boxes.safeArt : boxes.safe;
|
|
154
|
-
const sides = [
|
|
155
|
-
["left", -r.x, -safe.x, -trim.x, -sheet.x],
|
|
156
|
-
["right", r.x + r.w, safe.x + safe.w, trim.x + trim.w, sheet.x + sheet.w],
|
|
157
|
-
["top", -r.y, -safe.y, -trim.y, -sheet.y],
|
|
158
|
-
["bottom", r.y + r.h, safe.y + safe.h, trim.y + trim.h, sheet.y + sheet.h]
|
|
159
|
-
];
|
|
160
|
-
let worst = { kind: "inside", gap: 0, need: 0, edge: null };
|
|
161
|
-
let beyond = 0;
|
|
162
|
-
for (const [edge, ink, limit, trimEdge, sheetEdge] of sides) {
|
|
163
|
-
const past = ink - limit;
|
|
164
|
-
if (past <= tol || rule === "art" && ink >= sheetEdge - tol)
|
|
165
|
-
continue;
|
|
166
|
-
const kind = ink > sheetEdge + tol ? "off-page" : ink > trimEdge + tol ? "bleed" : "unsafe";
|
|
167
|
-
if (SEVERITY[kind] > SEVERITY[worst.kind] || kind === worst.kind && past > beyond) {
|
|
168
|
-
worst = { kind, gap: trimEdge - ink, need: trimEdge - limit, edge };
|
|
169
|
-
beyond = past;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return worst;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
95
|
// src/constants.ts
|
|
176
96
|
var NETWORK = {
|
|
177
97
|
DEFAULT_PORT: 3579
|
|
@@ -2318,4 +2238,4 @@ async function restoreForCommand(dir, options) {
|
|
|
2318
2238
|
log.warn(problem);
|
|
2319
2239
|
}
|
|
2320
2240
|
|
|
2321
|
-
export {
|
|
2241
|
+
export { DEBOUNCE, UsageError, resolvePort, PRESET_IDS, PRESETS, TARGETS, TARGET_IDS, publishTargetFor, resolveTargets, applyDefaultPdfStrictChecks, MANIFEST_FILENAMES, hasProjectManifest, loadManifest, loadManifestWithPath, resolveConfig, resolveConfigForTarget, MARGIN_EDGES, validatePageMargin, FriendlyHttpError, withFetchTimeout, loadManifestDoc, writeManifestDoc, scalarString, DEFAULT_NPM_REGISTRY, npmRegistryUrl, ensureProjectGitignore, sameExtension, listProjectExtensions, describeExtension, extensionConfigFor, setExtensionEnabled, reorderExtensions, removeExtension, addExtension, listNpmVersions, checkExtensionUpdates, updateExtensions, listBundledExtensions, uniqueExtensionId, validateProjectExtensions, readExtensionCss, readEntryCss, restorePinnedExtensions, restoreFailureMessage, restoreOfflineMessage, restoreForCommand };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// src/lib/build-error.ts
|
|
2
|
+
var EXIT_CODES = {
|
|
3
|
+
OK: 0,
|
|
4
|
+
FINDINGS: 1,
|
|
5
|
+
USAGE: 2,
|
|
6
|
+
PIPELINE: 3
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
class BuildError extends Error {
|
|
10
|
+
exitCode;
|
|
11
|
+
constructor(message, exitCode = EXIT_CODES.PIPELINE, options) {
|
|
12
|
+
super(message, options);
|
|
13
|
+
this.name = "BuildError";
|
|
14
|
+
this.exitCode = exitCode;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// src/engine/shared/print-area.ts
|
|
19
|
+
function isPositivePoints(value) {
|
|
20
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
21
|
+
}
|
|
22
|
+
function isNonNegativePoints(value) {
|
|
23
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
24
|
+
}
|
|
25
|
+
var round3 = (n) => Math.round(n * 1000) / 1000;
|
|
26
|
+
function cssLength(pt) {
|
|
27
|
+
const inches = round3(pt / 72);
|
|
28
|
+
return Math.abs(inches * 72 - pt) < 0.000001 ? `${inches}in` : `${round3(pt)}pt`;
|
|
29
|
+
}
|
|
30
|
+
function formatPageSize(page) {
|
|
31
|
+
return `${cssLength(page.width)} ${cssLength(page.height)}`;
|
|
32
|
+
}
|
|
33
|
+
function printAreaMeta(page) {
|
|
34
|
+
const area = JSON.stringify({
|
|
35
|
+
width: page.width,
|
|
36
|
+
height: page.height,
|
|
37
|
+
bleed: page.bleed ?? 0,
|
|
38
|
+
safe: page.safe ?? 0,
|
|
39
|
+
artSafe: page.artSafe,
|
|
40
|
+
gutter: page.gutter,
|
|
41
|
+
preset: page.preset,
|
|
42
|
+
spec: page.spec
|
|
43
|
+
});
|
|
44
|
+
return `<meta name="gp-print-area" content='${area.replace(/&/g, "&").replace(/'/g, "'")}'>`;
|
|
45
|
+
}
|
|
46
|
+
function pageBoxes(area, side, scale = 1) {
|
|
47
|
+
const w = area.width * scale;
|
|
48
|
+
const h = area.height * scale;
|
|
49
|
+
const b = Math.max(0, area.bleed) * scale;
|
|
50
|
+
const s = Math.max(0, area.safe) * scale;
|
|
51
|
+
const a = Math.max(0, area.artSafe) * scale;
|
|
52
|
+
const g = Math.max(0, area.gutter) * scale;
|
|
53
|
+
const [textLeft, textRight] = side === "verso" ? [s, g] : [g, s];
|
|
54
|
+
const [artLeft, artRight] = side === "verso" ? [a, g] : [g, a];
|
|
55
|
+
const trim = { x: side === "verso" ? b : 0, y: b, w: Math.max(0, w - b), h: Math.max(0, h - 2 * b) };
|
|
56
|
+
return {
|
|
57
|
+
sheet: { x: 0, y: 0, w, h },
|
|
58
|
+
trim,
|
|
59
|
+
safe: {
|
|
60
|
+
x: trim.x + textLeft,
|
|
61
|
+
y: trim.y + s,
|
|
62
|
+
w: Math.max(0, trim.w - textLeft - textRight),
|
|
63
|
+
h: Math.max(0, trim.h - 2 * s)
|
|
64
|
+
},
|
|
65
|
+
safeArt: {
|
|
66
|
+
x: trim.x + artLeft,
|
|
67
|
+
y: trim.y + a,
|
|
68
|
+
w: Math.max(0, trim.w - artLeft - artRight),
|
|
69
|
+
h: Math.max(0, trim.h - 2 * a)
|
|
70
|
+
},
|
|
71
|
+
bleed: b
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
var SEVERITY = { inside: 0, unsafe: 1, bleed: 2, "off-page": 3 };
|
|
75
|
+
function judgeRect(r, boxes, rule, tol = 0) {
|
|
76
|
+
const { sheet, trim } = boxes;
|
|
77
|
+
const safe = rule === "art" ? boxes.safeArt : boxes.safe;
|
|
78
|
+
const sides = [
|
|
79
|
+
["left", -r.x, -safe.x, -trim.x, -sheet.x],
|
|
80
|
+
["right", r.x + r.w, safe.x + safe.w, trim.x + trim.w, sheet.x + sheet.w],
|
|
81
|
+
["top", -r.y, -safe.y, -trim.y, -sheet.y],
|
|
82
|
+
["bottom", r.y + r.h, safe.y + safe.h, trim.y + trim.h, sheet.y + sheet.h]
|
|
83
|
+
];
|
|
84
|
+
let worst = { kind: "inside", gap: 0, need: 0, edge: null };
|
|
85
|
+
let beyond = 0;
|
|
86
|
+
for (const [edge, ink, limit, trimEdge, sheetEdge] of sides) {
|
|
87
|
+
const past = ink - limit;
|
|
88
|
+
if (past <= tol || rule === "art" && ink >= sheetEdge - tol)
|
|
89
|
+
continue;
|
|
90
|
+
const kind = ink > sheetEdge + tol ? "off-page" : ink > trimEdge + tol ? "bleed" : "unsafe";
|
|
91
|
+
if (SEVERITY[kind] > SEVERITY[worst.kind] || kind === worst.kind && past > beyond) {
|
|
92
|
+
worst = { kind, gap: trimEdge - ink, need: trimEdge - limit, edge };
|
|
93
|
+
beyond = past;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return worst;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export { isPositivePoints, isNonNegativePoints, round3, cssLength, formatPageSize, printAreaMeta, pageBoxes, judgeRect, EXIT_CODES, BuildError };
|
package/dist/index.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ export type { PlatformAdapter, FileStat, FileWriteResult } from "./platform.ts";
|
|
|
26
26
|
export { inspectImage } from "./lib/image-inspect.ts";
|
|
27
27
|
export type { ImageInfo, ColorSpace } from "./lib/image-inspect.ts";
|
|
28
28
|
export { checkCss } from "./lib/printsafe.ts";
|
|
29
|
+
export { readBookCss, bookTokenEdits } from "./lib/book-css.ts";
|
|
30
|
+
export type { BookCss, BookCssChunk, CssChunk, CssChunkOrigin, RootToken, StylesheetEdit, TokenUpdate, } from "./lib/book-css.ts";
|
|
29
31
|
export { BUILD_DIAGNOSTIC_CODES } from "./engine/compiler/build.ts";
|
|
30
32
|
export type { BuildDiagnostic, BuildDiagnosticCode } from "./engine/compiler/build.ts";
|
|
31
33
|
export type { PrintSafeWarning } from "./lib/printsafe.ts";
|