gutterpress 0.11.20-alpha.3 → 0.11.20-alpha.5
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/api/index.js +2 -2
- package/dist/{build-a8ycsg80.js → build-8ffhvydf.js} +4 -4
- package/dist/{cli-hn9pk0hp.js → cli-553ce1d4.js} +1 -1
- package/dist/{cli-y9bcya7r.js → cli-6xym15vm.js} +2 -2
- package/dist/{cli-x4p99w8d.js → cli-cyej3p9v.js} +83 -41
- package/dist/{cli-9k2tb493.js → cli-sc5t7c74.js} +116 -43
- package/dist/cli.js +12 -12
- package/dist/{doctor-wbjkrcpc.js → doctor-gyes0hxt.js} +2 -2
- package/dist/engine/compiler/build.d.ts +1 -1
- package/dist/engine/shared/margin-box-support.d.ts +2 -2
- package/dist/engine/shared/pin-edges.d.ts +127 -0
- package/dist/engine/shared/print-area.d.ts +73 -0
- package/dist/{engine-yxnnp3hx.js → engine-4rkhv5ga.js} +1 -1
- package/dist/{engine-fdtv01a2.js → engine-5fw55dfb.js} +2 -2
- package/dist/{ext-pesyrs68.js → ext-x61yptd1.js} +4 -4
- package/dist/{gutterpress-agent-cazqstr1.js → gutterpress-agent-yvd8w8my.js} +79 -13
- package/dist/{gutterpress-viewer-1yse8cx3.js → gutterpress-viewer-w7njnkj7.js} +257 -71
- package/dist/{index-tjvrchxj.js → index-bta8hc2q.js} +225 -152
- package/dist/{index-zagagnwq.js → index-crys9951.js} +3 -3
- package/dist/{index-r87y7wzw.js → index-yw16cfm8.js} +82 -40
- package/dist/index.js +3 -3
- package/dist/lib/extension-manifest.d.ts +13 -0
- package/dist/lib/markdown/assemble.d.ts +13 -3
- package/dist/lib/markdown/gutterpress-css.d.ts +49 -33
- package/dist/lib/markdown/index.d.ts +5 -0
- package/dist/{manifest.schema-c9x8912a.json → manifest.schema-c4wfpg6g.json} +9 -3
- package/dist/{new-8yah8z91.js → new-87dqcxtn.js} +4 -4
- package/dist/{preflight-8ccx4kdc.js → preflight-nb4wndqf.js} +4 -4
- package/dist/preview/file-watcher.d.ts +5 -10
- package/dist/{preview-w7v9w36q.js → preview-7bcr5j2p.js} +4 -4
- package/dist/{publish-g5nh5myh.js → publish-4qfm5ch9.js} +4 -4
- package/dist/render.js +73 -13
- package/dist/schema/manifest.types.d.ts +25 -9
- package/dist/{validate-1yh59x0x.js → validate-dzht9qxk.js} +4 -4
- package/package.json +1 -1
- package/dist/engine/shared/flush.d.ts +0 -59
|
@@ -119,7 +119,38 @@
|
|
|
119
119
|
);
|
|
120
120
|
position: relative;
|
|
121
121
|
width: var(--gp-content-w);
|
|
122
|
-
|
|
122
|
+
/* Exactly one column tall, but DEFINITE only where print's flow root is.
|
|
123
|
+
A page root's percentage height (\`.page { height: 100% }\`) resolves
|
|
124
|
+
against its containing block. In print that is the flow root (\`body\` or
|
|
125
|
+
\`main\`), whose height is auto in an ordinary book, so the percentage
|
|
126
|
+
computes to \`auto\` and MARKER_CSS's min-height cushion sizes the root.
|
|
127
|
+
Here the strip stands in as that containing block, and a plain
|
|
128
|
+
\`height: var(--gp-content-h)\` resolved the percentage to the full column:
|
|
129
|
+
the root ended exactly on the column's edge, and the same percentage
|
|
130
|
+
reached everything else the author's rule matched (\`[data-name="x"]\`
|
|
131
|
+
selects a block AND its heading, so the heading filled the root and the
|
|
132
|
+
paragraph after it spilled into the next column). Mid-run the next root's
|
|
133
|
+
forced break absorbed the spill; a run's LAST root left a blank column —
|
|
134
|
+
a preview page the PDF does not have. Measured on
|
|
135
|
+
examples/with-print-effects with \`height: 100%\` on its page blocks: print
|
|
136
|
+
5pp, viewer 8pp (a pin root is a run of its own, so three runs ended on
|
|
137
|
+
such a root).
|
|
138
|
+
|
|
139
|
+
\`height: 100%\` asks the strip's own containing block the question the
|
|
140
|
+
root asks print's: is the flow root's height definite? Auto there (the
|
|
141
|
+
ordinary book) is auto here, and the root's percentage is auto exactly
|
|
142
|
+
as in print. A definite flow root — \`html, body { height: 100% }\`, where
|
|
143
|
+
print's percentage DOES resolve to the page area — is definite here too
|
|
144
|
+
(measured, the same 5-root book: 6pp in both renderers). Either way the
|
|
145
|
+
min/max pair pins the used height, so the column height, to the content
|
|
146
|
+
height: \`clientHeight\` is still one column.
|
|
147
|
+
|
|
148
|
+
\`decorate.ts\`'s \`.gp-run\` wrapper sizes itself with \`min-height\` for the
|
|
149
|
+
same reason — a definite wrapper would resolve the percentage after the
|
|
150
|
+
run was measured and re-fragment it under its sheets. */
|
|
151
|
+
height: 100%;
|
|
152
|
+
min-height: var(--gp-content-h);
|
|
153
|
+
max-height: var(--gp-content-h);
|
|
123
154
|
column-width: var(--gp-content-w);
|
|
124
155
|
column-gap: var(--gp-col-gap);
|
|
125
156
|
column-fill: auto;
|
|
@@ -1038,10 +1069,12 @@
|
|
|
1038
1069
|
`);
|
|
1039
1070
|
}
|
|
1040
1071
|
|
|
1041
|
-
// src/engine/shared/
|
|
1042
|
-
var
|
|
1043
|
-
|
|
1044
|
-
|
|
1072
|
+
// src/engine/shared/pin-edges.ts
|
|
1073
|
+
var PIN_EDGES = ["top", "right", "bottom", "left"];
|
|
1074
|
+
var EDGE_PIN_SELECTOR = PIN_EDGES.map((edge) => `.gp-pin.gp-${edge}`).join(", ");
|
|
1075
|
+
function pinEdgesIn(root) {
|
|
1076
|
+
const pins = Array.from(root.querySelectorAll(EDGE_PIN_SELECTOR)).filter((pin) => pin.offsetParent === root);
|
|
1077
|
+
return PIN_EDGES.filter((edge) => pins.some((pin) => pin.classList.contains(`gp-${edge}`)));
|
|
1045
1078
|
}
|
|
1046
1079
|
function flushMargins(margin, edges) {
|
|
1047
1080
|
return {
|
|
@@ -1051,6 +1084,58 @@
|
|
|
1051
1084
|
left: edges.includes("left") ? 0 : margin.left
|
|
1052
1085
|
};
|
|
1053
1086
|
}
|
|
1087
|
+
function pinInsets(area, side, edges) {
|
|
1088
|
+
const binding = side === "recto" ? "left" : "right";
|
|
1089
|
+
const inset = (edge) => !area || !edges.includes(edge) ? 0 : edge === binding ? area.gutter : area.bleed + area.artSafe;
|
|
1090
|
+
return { top: inset("top"), right: inset("right"), bottom: inset("bottom"), left: inset("left") };
|
|
1091
|
+
}
|
|
1092
|
+
var NO_PADDING = { top: 0, right: 0, bottom: 0, left: 0 };
|
|
1093
|
+
function pinRootStyle(margin, area, side, edges, padding = NO_PADDING) {
|
|
1094
|
+
const px = (pt) => pt * 96 / 72;
|
|
1095
|
+
const inset = pinInsets(area, side, edges);
|
|
1096
|
+
const style = { "box-decoration-break": "clone" };
|
|
1097
|
+
for (const edge of PIN_EDGES)
|
|
1098
|
+
if (edges.includes(edge))
|
|
1099
|
+
style[`padding-${edge}`] = `${px(margin[edge]) + padding[edge]}px`;
|
|
1100
|
+
for (const edge of PIN_EDGES)
|
|
1101
|
+
style[`--gp-pin-${edge}`] = `${px(inset[edge])}px`;
|
|
1102
|
+
return style;
|
|
1103
|
+
}
|
|
1104
|
+
function paddingOf(cs) {
|
|
1105
|
+
return {
|
|
1106
|
+
top: parseFloat(cs.paddingTop) || 0,
|
|
1107
|
+
right: parseFloat(cs.paddingRight) || 0,
|
|
1108
|
+
bottom: parseFloat(cs.paddingBottom) || 0,
|
|
1109
|
+
left: parseFloat(cs.paddingLeft) || 0
|
|
1110
|
+
};
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
// src/engine/shared/print-area.ts
|
|
1114
|
+
function printAreaFromMeta(doc) {
|
|
1115
|
+
const raw = doc.querySelector('meta[name="gp-print-area"]')?.getAttribute("content");
|
|
1116
|
+
if (!raw)
|
|
1117
|
+
return null;
|
|
1118
|
+
try {
|
|
1119
|
+
const v = JSON.parse(raw);
|
|
1120
|
+
const n = (x) => typeof x === "number" && Number.isFinite(x) && x > 0 ? x : 0;
|
|
1121
|
+
if (!n(v.width) || !n(v.height))
|
|
1122
|
+
return null;
|
|
1123
|
+
const safe = n(v.safe);
|
|
1124
|
+
const spec = v.spec && typeof v.spec.label === "string" && typeof v.spec.url === "string" && /^https?:\/\//i.test(v.spec.url) ? v.spec : undefined;
|
|
1125
|
+
return {
|
|
1126
|
+
width: n(v.width),
|
|
1127
|
+
height: n(v.height),
|
|
1128
|
+
bleed: n(v.bleed),
|
|
1129
|
+
safe,
|
|
1130
|
+
artSafe: typeof v.artSafe === "number" ? n(v.artSafe) : safe,
|
|
1131
|
+
gutter: typeof v.gutter === "number" ? n(v.gutter) : safe,
|
|
1132
|
+
preset: typeof v.preset === "string" ? v.preset : undefined,
|
|
1133
|
+
spec
|
|
1134
|
+
};
|
|
1135
|
+
} catch {
|
|
1136
|
+
return null;
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1054
1139
|
|
|
1055
1140
|
// src/engine/viewer/fragment.ts
|
|
1056
1141
|
var PX_PER_PT = 96 / 72;
|
|
@@ -1160,7 +1245,7 @@
|
|
|
1160
1245
|
continue;
|
|
1161
1246
|
const stripTop = strip.getBoundingClientRect().top;
|
|
1162
1247
|
const edge = prop === "break-after" ? rect.bottom : rect.top;
|
|
1163
|
-
if (columnReserve((edge - stripTop) / cssZoomOf(strip), strip.
|
|
1248
|
+
if (columnReserve((edge - stripTop) / cssZoomOf(strip), stripMetrics(strip).height) === null)
|
|
1164
1249
|
continue;
|
|
1165
1250
|
const spacer = document.createElement("div");
|
|
1166
1251
|
spacer.className = "gp-column-break-spacer";
|
|
@@ -1210,13 +1295,29 @@
|
|
|
1210
1295
|
}
|
|
1211
1296
|
return false;
|
|
1212
1297
|
}
|
|
1213
|
-
function pushRun(runs, page, nodes,
|
|
1214
|
-
const key = (r) => `${r.page ?? ""}\x00${(r.
|
|
1298
|
+
function pushRun(runs, page, nodes, pin) {
|
|
1299
|
+
const key = (r) => `${r.page ?? ""}\x00${(r.pin?.edges ?? []).join(",")}`;
|
|
1215
1300
|
const last = runs[runs.length - 1];
|
|
1216
|
-
if (last && key(last) === key({ page,
|
|
1301
|
+
if (last && key(last) === key({ page, pin })) {
|
|
1217
1302
|
last.nodes.push(...nodes);
|
|
1218
|
-
|
|
1219
|
-
|
|
1303
|
+
if (pin)
|
|
1304
|
+
last.pin.roots.push(...pin.roots);
|
|
1305
|
+
} else
|
|
1306
|
+
runs.push({ page, nodes, pin: pin && { edges: pin.edges, roots: [...pin.roots] } });
|
|
1307
|
+
}
|
|
1308
|
+
var PAGE_ROOT = ".page, .spread";
|
|
1309
|
+
var ownPadding = new WeakMap;
|
|
1310
|
+
function pinRunOf(el) {
|
|
1311
|
+
if (!el.matches(PAGE_ROOT))
|
|
1312
|
+
return;
|
|
1313
|
+
const edges = pinEdgesIn(el);
|
|
1314
|
+
return edges.length ? { edges, roots: [el] } : undefined;
|
|
1315
|
+
}
|
|
1316
|
+
function holdsPinRoot(el) {
|
|
1317
|
+
return Array.from(el.querySelectorAll(EDGE_PIN_SELECTOR)).some((pin) => {
|
|
1318
|
+
const root = pin.offsetParent;
|
|
1319
|
+
return !!root && root !== el && el.contains(root) && root.matches(PAGE_ROOT);
|
|
1320
|
+
});
|
|
1220
1321
|
}
|
|
1221
1322
|
function explodeChildren(container, model) {
|
|
1222
1323
|
const runs = [];
|
|
@@ -1228,7 +1329,7 @@
|
|
|
1228
1329
|
pending = [];
|
|
1229
1330
|
const last = runs[runs.length - 1];
|
|
1230
1331
|
if (last) {
|
|
1231
|
-
pushRun(runs, last.page, held, last.
|
|
1332
|
+
pushRun(runs, last.page, held, last.pin && { edges: last.pin.edges, roots: [] });
|
|
1232
1333
|
return [];
|
|
1233
1334
|
}
|
|
1234
1335
|
if (held.some((n) => (n.textContent ?? "").trim() !== "")) {
|
|
@@ -1245,19 +1346,19 @@
|
|
|
1245
1346
|
const kid = node;
|
|
1246
1347
|
if (kid.classList.contains("gp-layer"))
|
|
1247
1348
|
continue;
|
|
1248
|
-
const
|
|
1349
|
+
const pin = pinRunOf(kid);
|
|
1249
1350
|
const own = directPageName(kid, model);
|
|
1250
1351
|
if (own !== undefined) {
|
|
1251
|
-
pushRun(runs, own, [...carry(), kid],
|
|
1352
|
+
pushRun(runs, own, [...carry(), kid], pin);
|
|
1252
1353
|
continue;
|
|
1253
1354
|
}
|
|
1254
|
-
if (!hasDescendantPageAssignment(kid, model)) {
|
|
1255
|
-
pushRun(runs, undefined, [...carry(), kid],
|
|
1355
|
+
if (!hasDescendantPageAssignment(kid, model) && !holdsPinRoot(kid)) {
|
|
1356
|
+
pushRun(runs, undefined, [...carry(), kid], pin);
|
|
1256
1357
|
continue;
|
|
1257
1358
|
}
|
|
1258
1359
|
const inner = explodeChildren(kid, model);
|
|
1259
1360
|
if (inner.length <= 1) {
|
|
1260
|
-
pushRun(runs, inner[0]?.page, [...carry(), kid]);
|
|
1361
|
+
pushRun(runs, inner[0]?.page, [...carry(), kid], pin ?? inner[0]?.pin);
|
|
1261
1362
|
continue;
|
|
1262
1363
|
}
|
|
1263
1364
|
let lead = carry();
|
|
@@ -1266,7 +1367,7 @@
|
|
|
1266
1367
|
for (const n of r.nodes)
|
|
1267
1368
|
shell.appendChild(n);
|
|
1268
1369
|
kid.before(shell);
|
|
1269
|
-
pushRun(runs, r.page, [...lead, shell],
|
|
1370
|
+
pushRun(runs, r.page, [...lead, shell], pin ? pinRunOf(shell) : r.pin);
|
|
1270
1371
|
lead = [];
|
|
1271
1372
|
}
|
|
1272
1373
|
kid.remove();
|
|
@@ -1323,6 +1424,42 @@
|
|
|
1323
1424
|
delete el.dataset.gpLeadingPageRootDisplayPriority;
|
|
1324
1425
|
}
|
|
1325
1426
|
}
|
|
1427
|
+
function fitVersoPinRoots(model, strips) {
|
|
1428
|
+
const area = printAreaFromMeta(document);
|
|
1429
|
+
const versos = [];
|
|
1430
|
+
for (const strip of strips) {
|
|
1431
|
+
if (!strip.pinEdges || !strip.pinRoots?.length)
|
|
1432
|
+
continue;
|
|
1433
|
+
const edges = strip.pinEdges;
|
|
1434
|
+
const { left, agree } = pageSides(model, strip.page);
|
|
1435
|
+
const verso = agree ? left.margin : strip.geometry.margin;
|
|
1436
|
+
const margin = { ...strip.geometry.margin, left: verso.left, right: verso.right };
|
|
1437
|
+
const shift = pt(strip.versoShift);
|
|
1438
|
+
for (const root of strip.pinRoots) {
|
|
1439
|
+
if (pageOf(root, strips) % 2 !== 1)
|
|
1440
|
+
continue;
|
|
1441
|
+
const style = pinRootStyle(margin, area, "verso", edges, ownPadding.get(root));
|
|
1442
|
+
if (shift && edges.includes("left"))
|
|
1443
|
+
style["margin-left"] = `${shift}px`;
|
|
1444
|
+
if (shift && edges.includes("right"))
|
|
1445
|
+
style["margin-right"] = `${-shift}px`;
|
|
1446
|
+
versos.push({ root, style });
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
for (const { root, style } of versos)
|
|
1450
|
+
for (const [prop, value] of Object.entries(style))
|
|
1451
|
+
root.style.setProperty(prop, value);
|
|
1452
|
+
}
|
|
1453
|
+
function restorePinRoots(doc = document) {
|
|
1454
|
+
for (const el of Array.from(doc.querySelectorAll("[data-gp-pin-style]"))) {
|
|
1455
|
+
const style = el.dataset.gpPinStyle;
|
|
1456
|
+
if (style)
|
|
1457
|
+
el.setAttribute("style", style);
|
|
1458
|
+
else
|
|
1459
|
+
el.removeAttribute("style");
|
|
1460
|
+
delete el.dataset.gpPinStyle;
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1326
1463
|
var SCROLLABLE = /^(auto|scroll|hidden)$/;
|
|
1327
1464
|
function makeOverflowFragmentable(strips) {
|
|
1328
1465
|
const todo = [];
|
|
@@ -1388,21 +1525,16 @@
|
|
|
1388
1525
|
agree: Math.abs(r.w - l.w) < 0.01 && Math.abs(r.h - l.h) < 0.01
|
|
1389
1526
|
};
|
|
1390
1527
|
}
|
|
1391
|
-
function versoShiftPt(model, name
|
|
1528
|
+
function versoShiftPt(model, name) {
|
|
1392
1529
|
const { right, left, agree } = pageSides(model, name);
|
|
1393
|
-
|
|
1394
|
-
return 0;
|
|
1395
|
-
const r = flushMargins(right.margin, flushEdges);
|
|
1396
|
-
const l = flushMargins(left.margin, flushEdges);
|
|
1397
|
-
if (Math.abs(r.left + r.right - (l.left + l.right)) >= 0.01)
|
|
1398
|
-
return 0;
|
|
1399
|
-
return r.left - l.left;
|
|
1530
|
+
return agree ? right.margin.left - left.margin.left : 0;
|
|
1400
1531
|
}
|
|
1401
1532
|
function buildStrips(model, opts = {}, warnings = []) {
|
|
1402
1533
|
const doc = document;
|
|
1403
1534
|
const root = opts.root ?? doc.querySelector("main") ?? doc.body;
|
|
1404
1535
|
const gap = opts.sheetGap ?? 24;
|
|
1405
1536
|
const runs = explodeChildren(root, model);
|
|
1537
|
+
const area = printAreaFromMeta(doc);
|
|
1406
1538
|
const strips = [];
|
|
1407
1539
|
for (const run of runs) {
|
|
1408
1540
|
const geometry = runPageBox(model, run.page, warnings);
|
|
@@ -1410,7 +1542,18 @@
|
|
|
1410
1542
|
strip.className = "gp-strip";
|
|
1411
1543
|
if (run.page)
|
|
1412
1544
|
strip.dataset.page = run.page;
|
|
1413
|
-
const margin = run.
|
|
1545
|
+
const margin = run.pin ? flushMargins(geometry.margin, run.pin.edges) : geometry.margin;
|
|
1546
|
+
if (run.pin) {
|
|
1547
|
+
const { edges, roots } = run.pin;
|
|
1548
|
+
for (const pinRoot of roots)
|
|
1549
|
+
ownPadding.set(pinRoot, paddingOf(getComputedStyle(pinRoot)));
|
|
1550
|
+
for (const pinRoot of roots) {
|
|
1551
|
+
pinRoot.dataset.gpPinStyle ??= pinRoot.getAttribute("style") ?? "";
|
|
1552
|
+
const recto = pinRootStyle(geometry.margin, area, "recto", edges, ownPadding.get(pinRoot));
|
|
1553
|
+
for (const [prop, value] of Object.entries(recto))
|
|
1554
|
+
pinRoot.style.setProperty(prop, value);
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1414
1557
|
const w = pt(geometry.width - margin.left - margin.right);
|
|
1415
1558
|
const h = pt(geometry.height - margin.top - margin.bottom);
|
|
1416
1559
|
strip.style.setProperty("--gp-content-w", `${w}px`);
|
|
@@ -1422,7 +1565,7 @@
|
|
|
1422
1565
|
strip.style.setProperty("--gp-margin-right", `${pt(margin.right)}px`);
|
|
1423
1566
|
strip.style.setProperty("--gp-margin-bottom", `${pt(margin.bottom)}px`);
|
|
1424
1567
|
strip.style.setProperty("--gp-margin-left", `${pt(margin.left)}px`);
|
|
1425
|
-
const rawShift = versoShiftPt(model, run.page
|
|
1568
|
+
const rawShift = versoShiftPt(model, run.page);
|
|
1426
1569
|
const versoShift = Math.abs(rawShift) >= 0.01 ? rawShift : 0;
|
|
1427
1570
|
if (versoShift)
|
|
1428
1571
|
strip.style.setProperty("--gp-verso-shift", `${pt(versoShift)}px`);
|
|
@@ -1433,7 +1576,8 @@
|
|
|
1433
1576
|
el: strip,
|
|
1434
1577
|
page: run.page,
|
|
1435
1578
|
geometry,
|
|
1436
|
-
|
|
1579
|
+
pinEdges: run.pin?.edges,
|
|
1580
|
+
pinRoots: run.pin?.roots,
|
|
1437
1581
|
versoShift,
|
|
1438
1582
|
pages: 0,
|
|
1439
1583
|
offset: 0
|
|
@@ -1485,12 +1629,11 @@
|
|
|
1485
1629
|
let previous = "";
|
|
1486
1630
|
for (let pass = 0;pass < maxPasses; pass++) {
|
|
1487
1631
|
passes = Math.max(passes, pass + 1);
|
|
1488
|
-
const stride =
|
|
1632
|
+
const { stride, height: colBottom } = stripMetrics(strip.el);
|
|
1489
1633
|
const stripLeft = strip.el.getBoundingClientRect().left - strip.el.scrollLeft;
|
|
1490
1634
|
const zoom = cssZoomOf(strip.el);
|
|
1491
1635
|
const colOf = (r) => Math.floor(((r.left - stripLeft) / zoom + 1) / stride);
|
|
1492
1636
|
const stripTop = strip.el.getBoundingClientRect().top;
|
|
1493
|
-
const colBottom = strip.el.clientHeight;
|
|
1494
1637
|
const plans = [];
|
|
1495
1638
|
for (const table of tables) {
|
|
1496
1639
|
const head = repeatingHead(table);
|
|
@@ -1661,7 +1804,7 @@
|
|
|
1661
1804
|
const colGap = parseFloat(cs.columnGap) || 0;
|
|
1662
1805
|
const h = parseFloat(cs.getPropertyValue("--gp-content-h"));
|
|
1663
1806
|
const rowGap = parseFloat(cs.rowGap) || 0;
|
|
1664
|
-
return { stride: w + colGap, rowStride: h + rowGap };
|
|
1807
|
+
return { stride: w + colGap, rowStride: h + rowGap, height: h };
|
|
1665
1808
|
}
|
|
1666
1809
|
function rowStrideOf(strip) {
|
|
1667
1810
|
return stripMetrics(strip).rowStride;
|
|
@@ -1805,6 +1948,7 @@
|
|
|
1805
1948
|
const headers = opts.compensateHeaders === false ? { tables: 0, passes: 0, warnings: [] } : compensateRepeatedHeaders(strips);
|
|
1806
1949
|
const contentPages = measure(strips).totalPages;
|
|
1807
1950
|
const totalPages = padToSignature(strips, contentPages);
|
|
1951
|
+
fitVersoPinRoots(model, strips);
|
|
1808
1952
|
const api = {
|
|
1809
1953
|
model,
|
|
1810
1954
|
strips,
|
|
@@ -1818,6 +1962,7 @@
|
|
|
1818
1962
|
relayout: () => {
|
|
1819
1963
|
restoreFullHeightPageRoots();
|
|
1820
1964
|
restoreScrollContainers();
|
|
1965
|
+
restorePinRoots();
|
|
1821
1966
|
unwrapStrips(strips);
|
|
1822
1967
|
for (const spacer of Array.from(document.querySelectorAll(".gp-recto-spacer, .gp-pad-spacer")))
|
|
1823
1968
|
spacer.remove();
|
|
@@ -1836,6 +1981,7 @@
|
|
|
1836
1981
|
const content = measure(strips).totalPages;
|
|
1837
1982
|
padToSignature(strips, content);
|
|
1838
1983
|
const r = measure(strips);
|
|
1984
|
+
fitVersoPinRoots(model, strips);
|
|
1839
1985
|
api.totalPages = r.totalPages;
|
|
1840
1986
|
api.blankPageIndices = blankPageIndices(strips);
|
|
1841
1987
|
api.paddedPageIndices = pagesAfter(content, r.totalPages);
|
|
@@ -2110,16 +2256,23 @@
|
|
|
2110
2256
|
const b = Math.max(0, area.bleed) * scale;
|
|
2111
2257
|
const s = Math.max(0, area.safe) * scale;
|
|
2112
2258
|
const a = Math.max(0, area.artSafe) * scale;
|
|
2113
|
-
const
|
|
2259
|
+
const g = Math.max(0, area.gutter) * scale;
|
|
2260
|
+
const [textLeft, textRight] = side === "verso" ? [s, g] : [g, s];
|
|
2261
|
+
const [artLeft, artRight] = side === "verso" ? [a, g] : [g, a];
|
|
2114
2262
|
const trim = { x: side === "verso" ? b : 0, y: b, w: Math.max(0, w - b), h: Math.max(0, h - 2 * b) };
|
|
2115
2263
|
return {
|
|
2116
2264
|
sheet: { x: 0, y: 0, w, h },
|
|
2117
2265
|
trim,
|
|
2118
|
-
safe: {
|
|
2266
|
+
safe: {
|
|
2267
|
+
x: trim.x + textLeft,
|
|
2268
|
+
y: trim.y + s,
|
|
2269
|
+
w: Math.max(0, trim.w - textLeft - textRight),
|
|
2270
|
+
h: Math.max(0, trim.h - 2 * s)
|
|
2271
|
+
},
|
|
2119
2272
|
safeArt: {
|
|
2120
|
-
x: trim.x +
|
|
2273
|
+
x: trim.x + artLeft,
|
|
2121
2274
|
y: trim.y + a,
|
|
2122
|
-
w: Math.max(0, trim.w -
|
|
2275
|
+
w: Math.max(0, trim.w - artLeft - artRight),
|
|
2123
2276
|
h: Math.max(0, trim.h - 2 * a)
|
|
2124
2277
|
},
|
|
2125
2278
|
bleed: b
|
|
@@ -2182,33 +2335,9 @@
|
|
|
2182
2335
|
artSafePt: 0,
|
|
2183
2336
|
counts: { text: 0, art: 0, bleed: 0, offPage: 0, intended: 0 }
|
|
2184
2337
|
};
|
|
2185
|
-
function printAreaFromMeta() {
|
|
2186
|
-
const raw = document.querySelector('meta[name="gp-print-area"]')?.getAttribute("content");
|
|
2187
|
-
if (!raw)
|
|
2188
|
-
return null;
|
|
2189
|
-
try {
|
|
2190
|
-
const v = JSON.parse(raw);
|
|
2191
|
-
const n = (x) => typeof x === "number" && Number.isFinite(x) && x > 0 ? x : 0;
|
|
2192
|
-
if (!n(v.width) || !n(v.height))
|
|
2193
|
-
return null;
|
|
2194
|
-
const safe = n(v.safe);
|
|
2195
|
-
const spec = v.spec && typeof v.spec.label === "string" && typeof v.spec.url === "string" && /^https?:\/\//i.test(v.spec.url) ? v.spec : undefined;
|
|
2196
|
-
return {
|
|
2197
|
-
width: n(v.width),
|
|
2198
|
-
height: n(v.height),
|
|
2199
|
-
bleed: n(v.bleed),
|
|
2200
|
-
safe,
|
|
2201
|
-
artSafe: typeof v.artSafe === "number" ? n(v.artSafe) : safe,
|
|
2202
|
-
preset: typeof v.preset === "string" ? v.preset : undefined,
|
|
2203
|
-
spec
|
|
2204
|
-
};
|
|
2205
|
-
} catch {
|
|
2206
|
-
return null;
|
|
2207
|
-
}
|
|
2208
|
-
}
|
|
2209
2338
|
function sheetArea(sheet) {
|
|
2210
2339
|
const px = (name) => parseFloat(sheet.style.getPropertyValue(name)) || 0;
|
|
2211
|
-
return { width: px("--gp-page-w") / PX_PER_PT, height: px("--gp-page-h") / PX_PER_PT, bleed: 0, safe: 0, artSafe: 0 };
|
|
2340
|
+
return { width: px("--gp-page-w") / PX_PER_PT, height: px("--gp-page-h") / PX_PER_PT, bleed: 0, safe: 0, artSafe: 0, gutter: 0 };
|
|
2212
2341
|
}
|
|
2213
2342
|
var OVERLAY_CSS = `
|
|
2214
2343
|
.root {
|
|
@@ -2220,12 +2349,12 @@
|
|
|
2220
2349
|
--gp-ov-bleed-color: #e5484d; /* bleed layer: the band, and (darker) the trim line */
|
|
2221
2350
|
--gp-ov-bleed-alpha: 0.45; /* opacity of the bleed band */
|
|
2222
2351
|
--gp-ov-trim-color: color-mix(in srgb, var(--gp-ov-bleed-color) 60%, #000); /* darker than the band so it reads as an edge */
|
|
2223
|
-
--gp-ov-art-color: #
|
|
2352
|
+
--gp-ov-art-color: #a855f7; /* art layer: the art line (dotted, a second cue) */
|
|
2224
2353
|
--gp-ov-margins-color: #1a9c6b; /* margins layer: the page's own content box */
|
|
2225
2354
|
--gp-ov-flag-width: 2px; /* overflow flag outline */
|
|
2226
2355
|
--gp-ov-warn: #f59e0b; /* leaves the safe area */
|
|
2227
2356
|
--gp-ov-error: #e5484d; /* crosses the trim / leaves the sheet */
|
|
2228
|
-
--gp-ov-intent: #
|
|
2357
|
+
--gp-ov-intent: #ec4899; /* placed on purpose (pink: apart from the purple art line) */
|
|
2229
2358
|
/* The overlay is scaled with the stage, so a 2px line would shrink with the
|
|
2230
2359
|
zoom; dividing by it keeps lines the same width on screen at every zoom. */
|
|
2231
2360
|
--gp-ov-w: calc(var(--gp-ov-width) / var(--gp-ov-z, 1));
|
|
@@ -2295,7 +2424,7 @@
|
|
|
2295
2424
|
.gp-ov-flag[data-kind="intended"] {
|
|
2296
2425
|
outline: var(--gp-ov-flag-w) dotted var(--gp-ov-intent);
|
|
2297
2426
|
}
|
|
2298
|
-
/* the legend: small, fixed in a corner of the viewport, and the one part that takes the pointer (its link) */
|
|
2427
|
+
/* the legend: small, fixed in a corner of the viewport, and the one part that takes the pointer (its link and its fold button) */
|
|
2299
2428
|
.gp-ov-legend {
|
|
2300
2429
|
position: fixed;
|
|
2301
2430
|
right: 12px;
|
|
@@ -2310,8 +2439,33 @@
|
|
|
2310
2439
|
box-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
|
|
2311
2440
|
pointer-events: auto;
|
|
2312
2441
|
}
|
|
2313
|
-
.gp-ov-
|
|
2442
|
+
.gp-ov-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
|
|
2443
|
+
.gp-ov-body { margin-top: 6px; }
|
|
2444
|
+
.gp-ov-body > div + div { margin-top: 3px; }
|
|
2314
2445
|
.gp-ov-legend a { color: #9cc2ff; }
|
|
2446
|
+
/* the fold button: a chevron made of two borders, down while the legend is open, up once it is folded to its header */
|
|
2447
|
+
.gp-ov-toggle {
|
|
2448
|
+
flex: none;
|
|
2449
|
+
display: grid;
|
|
2450
|
+
place-items: center;
|
|
2451
|
+
width: 18px;
|
|
2452
|
+
height: 18px;
|
|
2453
|
+
padding: 0;
|
|
2454
|
+
border: 0;
|
|
2455
|
+
background: none;
|
|
2456
|
+
color: inherit;
|
|
2457
|
+
cursor: pointer;
|
|
2458
|
+
}
|
|
2459
|
+
.gp-ov-toggle:focus-visible { outline: 2px solid #9cc2ff; }
|
|
2460
|
+
.gp-ov-toggle::before {
|
|
2461
|
+
content: "";
|
|
2462
|
+
width: 6px;
|
|
2463
|
+
height: 6px;
|
|
2464
|
+
border: solid currentColor;
|
|
2465
|
+
border-width: 0 2px 2px 0;
|
|
2466
|
+
transform: translateY(-2px) rotate(45deg);
|
|
2467
|
+
}
|
|
2468
|
+
.gp-ov-toggle[aria-expanded="false"]::before { transform: translateY(2px) rotate(-135deg); }
|
|
2315
2469
|
.gp-ov-row { display: flex; align-items: flex-start; gap: 6px; }
|
|
2316
2470
|
.gp-ov-swatch {
|
|
2317
2471
|
flex: none;
|
|
@@ -2459,12 +2613,19 @@
|
|
|
2459
2613
|
var ART_TAGS = new Set(["img", "svg", "video", "canvas"]);
|
|
2460
2614
|
var inches = (px) => +(Math.abs(px) / 96).toFixed(2);
|
|
2461
2615
|
var ptIn = (pt2) => `${+(pt2 / 72).toFixed(3)}in`;
|
|
2616
|
+
var LEGEND_FOLD_KEY = "gutterpress.overlay-legend-collapsed";
|
|
2617
|
+
var legendCollapsed = false;
|
|
2618
|
+
try {
|
|
2619
|
+
legendCollapsed = localStorage.getItem(LEGEND_FOLD_KEY) === "true";
|
|
2620
|
+
} catch {}
|
|
2462
2621
|
function legend(layers, area, summary) {
|
|
2463
2622
|
const el = div("gp-ov-legend");
|
|
2623
|
+
const body = div("gp-ov-body");
|
|
2624
|
+
body.id = "gp-ov-body";
|
|
2464
2625
|
const add = (cls, ...content) => {
|
|
2465
2626
|
const line = div(cls);
|
|
2466
2627
|
line.append(...content);
|
|
2467
|
-
|
|
2628
|
+
body.appendChild(line);
|
|
2468
2629
|
};
|
|
2469
2630
|
const row = (layer, name, text) => {
|
|
2470
2631
|
const swatch = div("gp-ov-swatch");
|
|
@@ -2476,14 +2637,15 @@
|
|
|
2476
2637
|
add("gp-ov-row", swatch, label);
|
|
2477
2638
|
};
|
|
2478
2639
|
const { bleedPt, safePt, artSafePt, counts } = summary;
|
|
2640
|
+
const gutterPt = area?.gutter ?? safePt;
|
|
2479
2641
|
if (layers.bleed) {
|
|
2480
2642
|
row("bleed", "Bleed", bleedPt > 0 ? ` ${ptIn(bleedPt)} — top, bottom, outside; none at the binding` : " — none set (page.bleed in manifest.yaml)");
|
|
2481
2643
|
}
|
|
2482
2644
|
if (layers.safe) {
|
|
2483
|
-
row("safe", "Safe area: text", safePt
|
|
2645
|
+
row("safe", "Safe area: text", safePt <= 0 ? " — none set (page.safe in manifest.yaml)" : gutterPt === safePt ? ` — ${ptIn(safePt)}, every edge` : ` — ${ptIn(safePt)}; ${ptIn(gutterPt)} at the binding`);
|
|
2484
2646
|
}
|
|
2485
2647
|
if (layers.art) {
|
|
2486
|
-
row("art", "Safe area: art", safePt <= 0 && artSafePt <= 0 ? " — none set (page.artSafe in manifest.yaml)" : artSafePt ===
|
|
2648
|
+
row("art", "Safe area: art", safePt <= 0 && artSafePt <= 0 ? " — none set (page.artSafe in manifest.yaml)" : artSafePt === gutterPt ? ` — ${ptIn(artSafePt)}, every edge` : ` — ${ptIn(artSafePt)} top, bottom, outside; ${ptIn(gutterPt)} at the binding`);
|
|
2487
2649
|
}
|
|
2488
2650
|
if (layers.margins)
|
|
2489
2651
|
row("margins", "Page margins", " — your stylesheet's @page margins");
|
|
@@ -2519,6 +2681,30 @@
|
|
|
2519
2681
|
const key = document.documentElement.dataset.overlayKey;
|
|
2520
2682
|
if (key)
|
|
2521
2683
|
add("gp-ov-note", `${key} hides`);
|
|
2684
|
+
const title = document.createElement("b");
|
|
2685
|
+
title.id = "gp-ov-title";
|
|
2686
|
+
title.textContent = "Print overlays";
|
|
2687
|
+
const toggle = document.createElement("button");
|
|
2688
|
+
toggle.type = "button";
|
|
2689
|
+
toggle.className = "gp-ov-toggle";
|
|
2690
|
+
toggle.setAttribute("aria-labelledby", title.id);
|
|
2691
|
+
toggle.setAttribute("aria-controls", body.id);
|
|
2692
|
+
const fold = () => {
|
|
2693
|
+
body.hidden = legendCollapsed;
|
|
2694
|
+
toggle.setAttribute("aria-expanded", String(!legendCollapsed));
|
|
2695
|
+
toggle.title = legendCollapsed ? "Show the legend" : "Hide the legend";
|
|
2696
|
+
};
|
|
2697
|
+
toggle.addEventListener("click", () => {
|
|
2698
|
+
legendCollapsed = !legendCollapsed;
|
|
2699
|
+
try {
|
|
2700
|
+
localStorage.setItem(LEGEND_FOLD_KEY, String(legendCollapsed));
|
|
2701
|
+
} catch {}
|
|
2702
|
+
fold();
|
|
2703
|
+
});
|
|
2704
|
+
fold();
|
|
2705
|
+
const head = div("gp-ov-head");
|
|
2706
|
+
head.append(title, toggle);
|
|
2707
|
+
el.append(head, body);
|
|
2522
2708
|
return el;
|
|
2523
2709
|
}
|
|
2524
2710
|
function paintOverlay(pages, strips, area, layers) {
|
|
@@ -2689,7 +2875,7 @@
|
|
|
2689
2875
|
let overlayPages = [];
|
|
2690
2876
|
let overlaySummary = OVERLAY_OFF;
|
|
2691
2877
|
const paintOverlayNow = () => {
|
|
2692
|
-
overlaySummary = paintOverlay(overlayPages, layout.strips, printAreaFromMeta(), overlayLayers);
|
|
2878
|
+
overlaySummary = paintOverlay(overlayPages, layout.strips, printAreaFromMeta(document), overlayLayers);
|
|
2693
2879
|
window.dispatchEvent(new CustomEvent("gp:overlay", { detail: overlaySummary }));
|
|
2694
2880
|
};
|
|
2695
2881
|
const api = {
|
|
@@ -2938,7 +3124,7 @@
|
|
|
2938
3124
|
overlayPages.push({ index: bookIndex, sheet, strip, padded: ctx.padded });
|
|
2939
3125
|
}
|
|
2940
3126
|
const rows = Math.max(1, Math.ceil((strip.pages + shift) / perRow));
|
|
2941
|
-
run.style.
|
|
3127
|
+
run.style.minHeight = `${rowStride * (rows - 1) + PX_PER_PT * g.height}px`;
|
|
2942
3128
|
run.style.width = `${stride * perRow}px`;
|
|
2943
3129
|
const composed = !!strip.wrapCols && shift === 1 && !first;
|
|
2944
3130
|
run.style.marginTop = composed ? `${-(prevPageH + sheetGap)}px` : "";
|
|
@@ -3026,7 +3212,7 @@
|
|
|
3026
3212
|
}
|
|
3027
3213
|
}
|
|
3028
3214
|
function checkOverflow(strip, out) {
|
|
3029
|
-
const h = strip.el
|
|
3215
|
+
const { height: h } = stripMetrics(strip.el);
|
|
3030
3216
|
for (const el of Array.from(strip.el.querySelectorAll("figure,table,img,pre"))) {
|
|
3031
3217
|
const r = el.getBoundingClientRect();
|
|
3032
3218
|
if (r.height > h + 1) {
|