gutterpress 0.9.0-alpha.2 → 0.10.0-alpha.3

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.
Files changed (138) hide show
  1. package/README.md +18 -4
  2. package/dist/api/index.d.ts +11 -5
  3. package/dist/api/index.js +20 -15
  4. package/dist/assets/preview/scripts/preview-bridge.d.ts +1 -0
  5. package/dist/assets/preview/scripts/preview-interface.d.ts +1 -0
  6. package/dist/{audit-nhn2pjz3.js → audit-xxegv0t0.js} +10 -7
  7. package/dist/{build-san7fv2z.js → build-w0vb6mgq.js} +14 -8
  8. package/dist/checks/source/index.d.ts +1 -0
  9. package/dist/checks/source/layout-markers.d.ts +3 -0
  10. package/dist/checks/source/local-ref-parser.d.ts +28 -0
  11. package/dist/cli-46ycxe6r.js +18 -0
  12. package/dist/{cli-k4bd06sd.js → cli-5czby0dd.js} +4986 -5889
  13. package/dist/cli-c41yr7he.js +241 -0
  14. package/dist/{cli-e5zhb0xs.js → cli-f4rcbt2t.js} +17 -24
  15. package/dist/{cli-najycadg.js → cli-gk3wsdpb.js} +69 -253
  16. package/dist/{index-yzrh708h.js → cli-k1065rkg.js} +2 -5
  17. package/dist/{cli-506tg37g.js → cli-revgt4pr.js} +2 -1
  18. package/dist/{cli-wchtvxvw.js → cli-v5mp7a6q.js} +14 -1
  19. package/dist/cli-yp3p0sf2.js +2343 -0
  20. package/dist/cli.js +20 -18
  21. package/dist/{doctor-hrk0kxxz.js → doctor-ctgn1dnt.js} +4 -2
  22. package/dist/engine/compiler/build.d.ts +139 -0
  23. package/dist/engine/compiler/postprocess.d.ts +23 -0
  24. package/dist/engine/compiler/tier2.d.ts +78 -0
  25. package/dist/engine/shared/cdp.d.ts +104 -0
  26. package/dist/engine/shared/content-value.d.ts +64 -0
  27. package/dist/engine/shared/gcpm-extract.d.ts +119 -0
  28. package/dist/engine/shared/margin-box-support.d.ts +12 -0
  29. package/dist/engine/shared/pdf-inspect.d.ts +24 -0
  30. package/dist/engine/shared/synthesis.d.ts +155 -0
  31. package/dist/engine-eng4xh2q.js +41 -0
  32. package/dist/engine-q5skhgms.js +40 -0
  33. package/dist/gutterpress-agent-1ctgfz92.js +576 -0
  34. package/dist/gutterpress-viewer-cem7dmr5.js +2349 -0
  35. package/dist/index-a4kr77td.js +1907 -0
  36. package/dist/{cli-yzrh708h.js → index-mdefp0y5.js} +1 -1
  37. package/dist/index-mvehxh0e.js +708 -0
  38. package/dist/{index-bynn850m.js → index-s416qpdv.js} +3049 -4015
  39. package/dist/{index-wchtvxvw.js → index-v5mp7a6q.js} +14 -1
  40. package/dist/index.d.ts +3 -1
  41. package/dist/index.js +24 -17
  42. package/dist/lib/asset-inline.d.ts +36 -0
  43. package/dist/lib/browser-pool.d.ts +18 -0
  44. package/dist/lib/build-error.d.ts +1 -1
  45. package/dist/lib/build-preflight.d.ts +35 -2
  46. package/dist/lib/build-runner.d.ts +45 -17
  47. package/dist/lib/build-staging.d.ts +9 -55
  48. package/dist/lib/cli-args.d.ts +8 -0
  49. package/dist/lib/desktop.d.ts +2 -2
  50. package/dist/lib/embedded-assets.d.ts +1 -1
  51. package/dist/lib/engine.d.ts +33 -0
  52. package/dist/lib/ghostscript.d.ts +46 -1
  53. package/dist/lib/markdown/assemble.d.ts +18 -10
  54. package/dist/lib/markdown/gp-pin-scope.d.ts +1 -0
  55. package/dist/lib/markdown/gutterpress-css.d.ts +125 -0
  56. package/dist/lib/markdown/images.d.ts +26 -0
  57. package/dist/lib/markdown/index.d.ts +4 -2
  58. package/dist/lib/markdown/inline-source.d.ts +10 -0
  59. package/dist/lib/markdown/markers.d.ts +32 -0
  60. package/dist/lib/markdown/renderer.d.ts +8 -3
  61. package/dist/lib/markdown/source-range.d.ts +61 -0
  62. package/dist/lib/missing-asset-placeholder.d.ts +52 -0
  63. package/dist/lib/presets.d.ts +1 -1
  64. package/dist/lib/printsafe.d.ts +2 -3
  65. package/dist/lib/remote-auth/converge-merge.d.ts +48 -0
  66. package/dist/lib/remote-auth/image-clash.d.ts +17 -0
  67. package/dist/lib/remote-auth/recovery/classify.d.ts +55 -67
  68. package/dist/lib/remote-auth/recovery/inspect.d.ts +14 -13
  69. package/dist/lib/remote-auth/recovery/locks.d.ts +20 -0
  70. package/dist/lib/remote-auth/recovery/repair.d.ts +29 -0
  71. package/dist/lib/remote-auth/recovery/types.d.ts +8 -204
  72. package/dist/lib/remote-auth/sync-messages.d.ts +2 -3
  73. package/dist/lib/remote-auth/sync-types.d.ts +35 -63
  74. package/dist/lib/remote-auth/sync.d.ts +11 -18
  75. package/dist/lib/remote-auth/transport.d.ts +14 -7
  76. package/dist/lib/theme-import.d.ts +4 -5
  77. package/dist/{lint-96j9hrj4.js → lint-gsh6qwrq.js} +10 -7
  78. package/dist/{manifest.schema-z61rzw44.json → manifest.schema-zxgxnbg7.json} +21 -0
  79. package/dist/{new-8p38wavc.js → new-nkhycqy4.js} +12 -8
  80. package/dist/{plugin-ees6nhkc.js → plugin-129wcs93.js} +10 -7
  81. package/dist/{preflight-1q6c2edh.js → preflight-41hcejg9.js} +10 -7
  82. package/dist/preview/file-watcher.d.ts +13 -17
  83. package/dist/preview/lifecycle.d.ts +1 -1
  84. package/dist/{pagedjs-bridge-vn4hk9fx.js → preview-bridge-fz7vpk8m.js} +8 -0
  85. package/dist/preview-interface-fnqb2y4v.js +1015 -0
  86. package/dist/{preview-y5a2zen1.js → preview-pftsvr9z.js} +16 -9
  87. package/dist/preview-shell-c5mfa3q0.js +346 -0
  88. package/dist/{project-source-p0gn1wd5.js → project-source-ekcyp63q.js} +1 -1
  89. package/dist/{publish-rm9yb3wh.js → publish-dnjvb4jg.js} +10 -7
  90. package/dist/render.d.ts +3 -4
  91. package/dist/render.js +728 -64
  92. package/dist/{repair-zgq7q2g6.js → repair-a3enjttn.js} +45 -79
  93. package/dist/schema/manifest.types.d.ts +38 -0
  94. package/dist/{source-provider-c1rjm2c0.js → source-provider-3tcj6qg2.js} +2 -2
  95. package/dist/source-provider-vanafrt9.js +40 -0
  96. package/dist/{theme-zz2ktzqs.css → theme-h5recz6c.css} +8 -7
  97. package/dist/{theme-570zmh2t.css → theme-j2bagrfx.css} +8 -7
  98. package/dist/{theme-nya4nqh6.css → theme-nn6d53zy.css} +8 -7
  99. package/dist/types.d.ts +7 -0
  100. package/dist/{validate-nr0xa6sa.js → validate-ph1xffqy.js} +10 -7
  101. package/package.json +6 -6
  102. package/dist/cli-yja077f6.js +0 -92
  103. package/dist/git-http-yrb4ag6z.js +0 -17
  104. package/dist/index-yja077f6.js +0 -92
  105. package/dist/lib/markdown/markdown-it-paged.d.ts +0 -30
  106. package/dist/lib/pagedjs-marker.d.ts +0 -42
  107. package/dist/lib/pagedjs.d.ts +0 -26
  108. package/dist/lib/pagination.d.ts +0 -149
  109. package/dist/lib/remote-auth/conflict-resolution.d.ts +0 -29
  110. package/dist/lib/remote-auth/recovery/abort-interrupted-operation.d.ts +0 -103
  111. package/dist/lib/remote-auth/recovery/backup.d.ts +0 -113
  112. package/dist/lib/remote-auth/recovery/context.d.ts +0 -47
  113. package/dist/lib/remote-auth/recovery/dispatch.d.ts +0 -28
  114. package/dist/lib/remote-auth/recovery/failsafe.d.ts +0 -33
  115. package/dist/lib/remote-auth/recovery/manual-guidance.d.ts +0 -28
  116. package/dist/lib/remote-auth/recovery/outcome-mapping.d.ts +0 -59
  117. package/dist/lib/remote-auth/recovery/policy.d.ts +0 -47
  118. package/dist/lib/remote-auth/recovery/recover-auth.d.ts +0 -42
  119. package/dist/lib/remote-auth/recovery/recover-binary-conflict.d.ts +0 -37
  120. package/dist/lib/remote-auth/recovery/recover-corrupt-index.d.ts +0 -40
  121. package/dist/lib/remote-auth/recovery/recover-detached-head.d.ts +0 -70
  122. package/dist/lib/remote-auth/recovery/recover-interrupted-cherry-pick.d.ts +0 -23
  123. package/dist/lib/remote-auth/recovery/recover-interrupted-merge.d.ts +0 -28
  124. package/dist/lib/remote-auth/recovery/recover-interrupted-rebase.d.ts +0 -39
  125. package/dist/lib/remote-auth/recovery/recover-merge-conflict.d.ts +0 -34
  126. package/dist/lib/remote-auth/recovery/recover-missing-git-dir.d.ts +0 -37
  127. package/dist/lib/remote-auth/recovery/recover-missing-objects.d.ts +0 -56
  128. package/dist/lib/remote-auth/recovery/recover-network.d.ts +0 -34
  129. package/dist/lib/remote-auth/recovery/recover-non-fast-forward.d.ts +0 -27
  130. package/dist/lib/remote-auth/recovery/recover-stale-lock.d.ts +0 -68
  131. package/dist/lib/remote-auth/recovery/recover-unrelated-histories.d.ts +0 -44
  132. package/dist/lib/remote-auth/recovery/recover-wrong-remote.d.ts +0 -35
  133. package/dist/lib/remote-auth/resolution-plan.d.ts +0 -64
  134. package/dist/paged.polyfill-n95pbxfn.js +0 -33288
  135. package/dist/pagedjs-interface-qxvzgwd7.js +0 -557
  136. package/dist/preview-shell-6dqexx1m.js +0 -581
  137. /package/dist/assets/{preview/scripts/pagedjs-bridge.d.ts → engine/gutterpress-agent.d.ts} +0 -0
  138. /package/dist/assets/{preview/scripts/pagedjs-interface.d.ts → engine/gutterpress-viewer.d.ts} +0 -0
@@ -0,0 +1,576 @@
1
+ (() => {
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ function __accessProp(key) {
7
+ return this[key];
8
+ }
9
+ var __toCommonJS = (from) => {
10
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
11
+ if (entry)
12
+ return entry;
13
+ entry = __defProp({}, "__esModule", { value: true });
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (var key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(entry, key))
17
+ __defProp(entry, key, {
18
+ get: __accessProp.bind(from, key),
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
+ });
21
+ }
22
+ __moduleCache.set(from, entry);
23
+ return entry;
24
+ };
25
+ var __moduleCache;
26
+ var __returnValue = (v) => v;
27
+ function __exportSetter(name, newValue) {
28
+ this[name] = __returnValue.bind(null, newValue);
29
+ }
30
+ var __export = (target, all) => {
31
+ for (var name in all)
32
+ __defProp(target, name, {
33
+ get: all[name],
34
+ enumerable: true,
35
+ configurable: true,
36
+ set: __exportSetter.bind(all, name)
37
+ });
38
+ };
39
+
40
+ // src/engine/compiler/agent.ts
41
+ var exports_agent = {};
42
+ __export(exports_agent, {
43
+ xrefSites: () => xrefSites,
44
+ targetTexts: () => targetTexts,
45
+ stringSources: () => stringSources,
46
+ setGenerated: () => setGenerated,
47
+ instrument: () => instrument,
48
+ forcedBreakSites: () => forcedBreakSites,
49
+ fillLeaders: () => fillLeaders,
50
+ counterResetSites: () => counterResetSites,
51
+ collectCss: () => collectCss,
52
+ auditContent: () => auditContent,
53
+ applyRectoSpacers: () => applyRectoSpacers,
54
+ addCss: () => addCss
55
+ });
56
+
57
+ // src/engine/shared/synthesis.ts
58
+ var WHICH_VALUES = new Set(["first", "start", "last", "first-except"]);
59
+ var LEADER_RE = /\uE000([^\uE001]*)\uE001/;
60
+ function leaderFillCount(gapPx, gluePx) {
61
+ if (!(gluePx > 0) || !(gapPx > 0))
62
+ return 0;
63
+ return Math.max(0, Math.floor(gapPx / gluePx) - 1);
64
+ }
65
+
66
+ // src/engine/shared/gcpm-extract.ts
67
+ function skipString(css, i) {
68
+ const quote = css[i];
69
+ i++;
70
+ while (i < css.length) {
71
+ if (css[i] === "\\")
72
+ i += 2;
73
+ else if (css[i] === quote)
74
+ return i + 1;
75
+ else
76
+ i++;
77
+ }
78
+ return i;
79
+ }
80
+ function splitTopLevel(s, sep) {
81
+ const out = [];
82
+ let depth = 0;
83
+ let start = 0;
84
+ for (let i = 0;i < s.length; i++) {
85
+ const c = s[i];
86
+ if (c === '"' || c === "'") {
87
+ i = skipString(s, i) - 1;
88
+ continue;
89
+ }
90
+ if (c === "(")
91
+ depth++;
92
+ else if (c === ")")
93
+ depth--;
94
+ else if (c === sep && depth === 0) {
95
+ out.push(s.slice(start, i));
96
+ start = i + 1;
97
+ }
98
+ }
99
+ out.push(s.slice(start));
100
+ return out.map((x) => x.trim()).filter(Boolean);
101
+ }
102
+ var UNITS_PER_PT = {
103
+ pt: 1,
104
+ px: 0.75,
105
+ in: 72,
106
+ pc: 12,
107
+ cm: 72 / 2.54,
108
+ mm: 72 / 25.4,
109
+ q: 72 / 101.6
110
+ };
111
+
112
+ // src/engine/shared/content-value.ts
113
+ var FUNC = /^([a-z-]+)\(/i;
114
+ function parseContent(value) {
115
+ const parts = [];
116
+ let i = 0;
117
+ const s = value.trim();
118
+ while (i < s.length) {
119
+ const c = s[i];
120
+ if (/\s/.test(c)) {
121
+ i++;
122
+ continue;
123
+ }
124
+ if (c === '"' || c === "'") {
125
+ const end = closeString(s, i);
126
+ parts.push({ type: "literal", value: unquote(s.slice(i, end)) });
127
+ i = end;
128
+ continue;
129
+ }
130
+ const rest = s.slice(i);
131
+ const fn = FUNC.exec(rest);
132
+ if (fn && fn[1] !== undefined) {
133
+ const open = i + fn[0].length - 1;
134
+ const close = matchParen(s, open);
135
+ const args = splitTopLevel(s.slice(open + 1, close), ",");
136
+ parts.push(toPart(fn[1].toLowerCase(), args));
137
+ i = close + 1;
138
+ continue;
139
+ }
140
+ const word = /^[^\s"']+/.exec(rest)[0];
141
+ parts.push({ type: "keyword", value: word });
142
+ i += word.length;
143
+ }
144
+ return parts;
145
+ }
146
+ function toPart(name, args) {
147
+ switch (name) {
148
+ case "counter":
149
+ return { type: "counter", name: args[0] ?? "page", style: args[1] ?? "decimal" };
150
+ case "string":
151
+ return { type: "string", name: args[0] ?? "", which: args[1] ?? "first" };
152
+ case "target-counter":
153
+ return {
154
+ type: "target-counter",
155
+ url: args[0] ?? "",
156
+ counter: args[1] ?? "page",
157
+ style: args[2] ?? "decimal"
158
+ };
159
+ case "target-text":
160
+ return { type: "target-text", url: args[0] ?? "", which: args[1] ?? "content" };
161
+ case "leader":
162
+ return { type: "leader", glue: unquote(args[0] ?? '"."') };
163
+ case "attr": {
164
+ const [a, as] = (args[0] ?? "").split(/\s+/);
165
+ return { type: "attr", name: a ?? "", as };
166
+ }
167
+ case "content":
168
+ return { type: "content", which: args[0] ?? "text" };
169
+ default:
170
+ return { type: "keyword", value: `${name}(${args.join(",")})` };
171
+ }
172
+ }
173
+ function closeString(s, i) {
174
+ const q = s[i++];
175
+ while (i < s.length) {
176
+ if (s[i] === "\\")
177
+ i += 2;
178
+ else if (s[i] === q)
179
+ return i + 1;
180
+ else
181
+ i++;
182
+ }
183
+ return i;
184
+ }
185
+ function matchParen(s, open) {
186
+ let depth = 0;
187
+ for (let i = open;i < s.length; i++) {
188
+ const c = s[i];
189
+ if (c === '"' || c === "'") {
190
+ i = closeString(s, i) - 1;
191
+ continue;
192
+ }
193
+ if (c === "(")
194
+ depth++;
195
+ else if (c === ")" && --depth === 0)
196
+ return i;
197
+ }
198
+ return s.length - 1;
199
+ }
200
+ function unquote(s) {
201
+ const t = s.trim();
202
+ if (t.startsWith('"') && t.endsWith('"') || t.startsWith("'") && t.endsWith("'"))
203
+ return t.slice(1, -1).replace(/\\(.)/g, "$1");
204
+ return t;
205
+ }
206
+ function resolveUrlArg(arg, ctx) {
207
+ const m = /^attr\(\s*([\w-]+)(?:\s+url)?\s*\)$/i.exec(arg.trim());
208
+ if (m && m[1] !== undefined)
209
+ return ctx.attr?.(m[1]) ?? "";
210
+ return unquote(arg);
211
+ }
212
+ var ROMAN = [
213
+ [1000, "m"],
214
+ [900, "cm"],
215
+ [500, "d"],
216
+ [400, "cd"],
217
+ [100, "c"],
218
+ [90, "xc"],
219
+ [50, "l"],
220
+ [40, "xl"],
221
+ [10, "x"],
222
+ [9, "ix"],
223
+ [5, "v"],
224
+ [4, "iv"],
225
+ [1, "i"]
226
+ ];
227
+ function formatCounter(n, style = "decimal") {
228
+ switch (style.trim()) {
229
+ case "decimal-leading-zero":
230
+ return n < 10 ? `0${n}` : String(n);
231
+ case "lower-roman":
232
+ case "upper-roman": {
233
+ let v = n;
234
+ let out = "";
235
+ for (const [num, sym] of ROMAN)
236
+ while (v >= num)
237
+ out += sym, v -= num;
238
+ return style === "upper-roman" ? out.toUpperCase() : out;
239
+ }
240
+ case "lower-alpha":
241
+ case "upper-alpha": {
242
+ let v = n;
243
+ let out = "";
244
+ while (v > 0) {
245
+ const r = (v - 1) % 26;
246
+ out = String.fromCharCode(97 + r) + out;
247
+ v = Math.floor((v - 1) / 26);
248
+ }
249
+ return style === "upper-alpha" ? out.toUpperCase() : out;
250
+ }
251
+ case "none":
252
+ return "";
253
+ default:
254
+ return String(n);
255
+ }
256
+ }
257
+ function evaluateContent(parts, ctx) {
258
+ let out = "";
259
+ for (const p of parts) {
260
+ switch (p.type) {
261
+ case "literal":
262
+ out += p.value;
263
+ break;
264
+ case "counter":
265
+ out += formatCounter(p.name === "pages" ? ctx.pages ?? 0 : ctx.page ?? 0, p.style);
266
+ break;
267
+ case "string":
268
+ out += ctx.strings?.(p.name, p.which) ?? "";
269
+ break;
270
+ case "target-counter": {
271
+ const url = resolveUrlArg(p.url, ctx);
272
+ const page = ctx.targetPage?.(url);
273
+ out += page === undefined ? "?" : formatCounter(page, p.style);
274
+ break;
275
+ }
276
+ case "target-text": {
277
+ const url = resolveUrlArg(p.url, ctx);
278
+ out += ctx.targetText?.(url, p.which) ?? "";
279
+ break;
280
+ }
281
+ case "attr":
282
+ out += ctx.attr?.(p.name) ?? "";
283
+ break;
284
+ case "content":
285
+ out += ctx.text ?? "";
286
+ break;
287
+ case "leader":
288
+ out += ctx.leader?.(p.glue) ?? "";
289
+ break;
290
+ case "keyword":
291
+ if (p.value === "normal" || p.value === "none")
292
+ break;
293
+ out += p.value;
294
+ break;
295
+ }
296
+ }
297
+ return out;
298
+ }
299
+ function evaluate(value, ctx) {
300
+ return evaluateContent(parseContent(value), ctx);
301
+ }
302
+
303
+ // src/engine/compiler/agent.ts
304
+ var uid = 0;
305
+ function ensureAnchor(el) {
306
+ if (el.id)
307
+ return el.id;
308
+ const existing = el.firstElementChild;
309
+ if (existing?.tagName === "GP-ANCHOR" && existing.id)
310
+ return existing.id;
311
+ const anchor = document.createElement("gp-anchor");
312
+ anchor.id = `gp-m-${++uid}`;
313
+ anchor.setAttribute("style", "display:inline");
314
+ el.insertBefore(anchor, el.firstChild);
315
+ return anchor.id;
316
+ }
317
+ function anchorHost(id) {
318
+ const el = document.getElementById(id);
319
+ if (!el)
320
+ return null;
321
+ return el.tagName === "GP-ANCHOR" ? el.parentElement : el;
322
+ }
323
+ async function collectCss() {
324
+ let out = "";
325
+ for (const sheet of Array.from(document.styleSheets)) {
326
+ const owner = sheet.ownerNode;
327
+ if (owner?.tagName === "STYLE") {
328
+ out += owner.textContent + `
329
+ `;
330
+ } else if (owner?.tagName === "LINK") {
331
+ try {
332
+ out += await (await fetch(owner.href)).text() + `
333
+ `;
334
+ } catch {}
335
+ }
336
+ }
337
+ return out;
338
+ }
339
+ function stringSources(stringSets) {
340
+ const out = [];
341
+ let order = 0;
342
+ for (const decl of stringSets) {
343
+ let els = [];
344
+ try {
345
+ els = Array.from(document.querySelectorAll(decl.selector));
346
+ } catch {
347
+ continue;
348
+ }
349
+ for (const el of els) {
350
+ const attrs = {};
351
+ for (const a of Array.from(el.attributes))
352
+ attrs[a.name] = a.value;
353
+ const text = decl.value ? evaluate(decl.value, {
354
+ text: (el.textContent ?? "").trim().replace(/\s+/g, " "),
355
+ attr: (n) => el.getAttribute(n) ?? undefined
356
+ }) : (el.textContent ?? "").trim().replace(/\s+/g, " ");
357
+ out.push({
358
+ name: decl.name,
359
+ id: ensureAnchor(el),
360
+ text,
361
+ attrs,
362
+ order: order++
363
+ });
364
+ }
365
+ }
366
+ out.sort((a, b) => {
367
+ const ea = document.getElementById(a.id);
368
+ const eb = document.getElementById(b.id);
369
+ const rel = ea.compareDocumentPosition(eb);
370
+ return rel & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
371
+ });
372
+ return out;
373
+ }
374
+ function forcedBreakSites(decls) {
375
+ const out = [];
376
+ for (const d of decls) {
377
+ let els = [];
378
+ try {
379
+ els = Array.from(document.querySelectorAll(d.selector));
380
+ } catch {
381
+ continue;
382
+ }
383
+ for (const el of els)
384
+ out.push({ id: ensureAnchor(el), prop: d.prop, value: d.value, selector: d.selector });
385
+ }
386
+ return out;
387
+ }
388
+ function counterResetSites(resets) {
389
+ const out = [];
390
+ for (const r of resets) {
391
+ let els = [];
392
+ try {
393
+ els = Array.from(document.querySelectorAll(r.selector));
394
+ } catch {
395
+ continue;
396
+ }
397
+ for (const el of els)
398
+ out.push({ id: ensureAnchor(el), start: r.start, selector: r.selector });
399
+ }
400
+ return out;
401
+ }
402
+ function applyRectoSpacers(ids, pageName) {
403
+ for (const spacer of Array.from(document.querySelectorAll(".gp-recto-spacer")))
404
+ spacer.remove();
405
+ let inserted = 0;
406
+ for (const id of ids) {
407
+ const el = anchorHost(id);
408
+ if (!el)
409
+ continue;
410
+ const spacer = document.createElement("div");
411
+ spacer.className = "gp-recto-spacer";
412
+ spacer.setAttribute("aria-hidden", "true");
413
+ spacer.style.cssText = `break-before: page; break-after: page; height: 0; margin: 0; padding: 0; border: 0; page: ${pageName};`;
414
+ el.before(spacer);
415
+ inserted++;
416
+ }
417
+ return inserted;
418
+ }
419
+ function auditContent(contentHeights, dpiFloor) {
420
+ const out = [];
421
+ const name = (el) => el.tagName.toLowerCase() + (el.id ? `#${el.id}` : "") + (el.className && typeof el.className === "string" ? `.${el.className.split(/\s+/)[0]}` : "");
422
+ const pageContext = (el) => {
423
+ for (let node = el;node; node = node.parentElement) {
424
+ const pageName = getComputedStyle(node).getPropertyValue("page").trim();
425
+ if (pageName && pageName !== "auto") {
426
+ return {
427
+ name: pageName,
428
+ height: contentHeights.named[pageName] ?? contentHeights.default
429
+ };
430
+ }
431
+ }
432
+ return { name: "default", height: contentHeights.default };
433
+ };
434
+ for (const el of Array.from(document.querySelectorAll("figure,img,table,pre,svg,div"))) {
435
+ const h = el.getBoundingClientRect().height;
436
+ const context = pageContext(el);
437
+ if (h > context.height + 1 && el.children.length === 0) {
438
+ out.push({
439
+ kind: "overheight",
440
+ what: name(el),
441
+ detail: `${Math.round(h)}px tall on a ${Math.round(context.height)}px ` + `${context.name === "default" ? "default-page" : `${context.name} page`} content box`
442
+ });
443
+ }
444
+ }
445
+ for (const img of Array.from(document.querySelectorAll("img"))) {
446
+ const rect = img.getBoundingClientRect();
447
+ if (!rect.width || !img.naturalWidth)
448
+ continue;
449
+ const dpi = img.naturalWidth / (rect.width / 96);
450
+ if (dpi < dpiFloor) {
451
+ out.push({
452
+ kind: "low-dpi",
453
+ what: name(img),
454
+ detail: `${img.naturalWidth}px wide printed at ${(rect.width / 96).toFixed(2)}in = ${Math.round(dpi)} DPI`
455
+ });
456
+ }
457
+ }
458
+ return out;
459
+ }
460
+ function targetTexts(ids) {
461
+ const out = {};
462
+ for (const id of ids) {
463
+ const el = anchorHost(id);
464
+ if (el)
465
+ out[id] = (el.textContent ?? "").trim().replace(/\s+/g, " ");
466
+ }
467
+ return out;
468
+ }
469
+ function xrefSites(selectors) {
470
+ const out = [];
471
+ for (const selector of selectors) {
472
+ const base = selector.replace(/::?(after|before)$/, "");
473
+ let els = [];
474
+ try {
475
+ els = Array.from(document.querySelectorAll(base));
476
+ } catch {
477
+ continue;
478
+ }
479
+ for (const el of els) {
480
+ const href = el.getAttribute("href") ?? "";
481
+ out.push({ id: ensureAnchor(el), href, selector });
482
+ }
483
+ }
484
+ return out;
485
+ }
486
+ function instrument(ids) {
487
+ let host = document.getElementById("gp-instrumentation");
488
+ if (!host) {
489
+ host = document.createElement("div");
490
+ host.id = "gp-instrumentation";
491
+ host.style.display = "none";
492
+ document.body.appendChild(host);
493
+ }
494
+ host.textContent = "";
495
+ for (const id of ids) {
496
+ const a = document.createElement("a");
497
+ a.href = `#${id}`;
498
+ a.textContent = ".";
499
+ host.appendChild(a);
500
+ }
501
+ return ids.length;
502
+ }
503
+ function addCss(id, css) {
504
+ let style = document.getElementById(id);
505
+ if (!style) {
506
+ style = document.createElement("style");
507
+ style.id = id;
508
+ document.head.appendChild(style);
509
+ }
510
+ style.textContent = css;
511
+ }
512
+ function fillLeaders(contentWidthPx) {
513
+ const marked = [];
514
+ for (const attr of ["data-gp-after", "data-gp-before"]) {
515
+ for (const el of Array.from(document.querySelectorAll(`[${attr}]`))) {
516
+ const raw = el.getAttribute(attr) ?? "";
517
+ if (LEADER_RE.test(raw))
518
+ marked.push({ el, attr, raw });
519
+ }
520
+ }
521
+ if (!marked.length)
522
+ return 0;
523
+ const prevWidth = document.body.style.width;
524
+ document.body.style.width = `${contentWidthPx}px`;
525
+ const canvas = document.createElement("canvas");
526
+ const cx = canvas.getContext("2d");
527
+ try {
528
+ for (const m of marked)
529
+ m.el.setAttribute(m.attr, m.raw.replace(LEADER_RE, ""));
530
+ document.body.offsetHeight;
531
+ for (const m of marked) {
532
+ const match = LEADER_RE.exec(m.raw);
533
+ const glue = match[1] || ".";
534
+ const host = m.el;
535
+ const block = host.parentElement ?? document.body;
536
+ const blockRect = block.getBoundingClientRect();
537
+ const cs = getComputedStyle(block);
538
+ const contentRight = blockRect.right - parseFloat(cs.paddingRight) - parseFloat(cs.borderRightWidth);
539
+ const rects = host.getClientRects();
540
+ const last = rects.length ? rects[rects.length - 1] : host.getBoundingClientRect();
541
+ cx.font = getComputedStyle(host).font;
542
+ const glueW = cx.measureText(glue).width;
543
+ const n = leaderFillCount(contentRight - last.right, glueW);
544
+ m.el.setAttribute(m.attr, m.raw.replace(LEADER_RE, glue.repeat(n)));
545
+ }
546
+ } finally {
547
+ document.body.style.width = prevWidth;
548
+ }
549
+ return marked.length;
550
+ }
551
+ function setGenerated(entries, css) {
552
+ for (const e of entries) {
553
+ const el = anchorHost(e.id);
554
+ if (el)
555
+ el.setAttribute(`data-gp-${e.where}`, e.text);
556
+ }
557
+ addCss("gp-generated-content", css);
558
+ return entries.length;
559
+ }
560
+ var api = {
561
+ auditContent,
562
+ collectCss,
563
+ forcedBreakSites,
564
+ counterResetSites,
565
+ applyRectoSpacers,
566
+ stringSources,
567
+ xrefSites,
568
+ targetTexts,
569
+ fillLeaders,
570
+ instrument,
571
+ addCss,
572
+ setGenerated
573
+ };
574
+ if (typeof window !== "undefined")
575
+ window.__gp = api;
576
+ })();