@pretextbook/pretext-html 0.10.1 → 0.12.0
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 +61 -0
- package/assets/preview-html.xsl +13 -1
- package/dist/{cli-C3B-AvUy.js → cli-BkTQ4BJP.js} +418 -372
- package/dist/cli.d.ts +7 -0
- package/dist/cli.js +3 -2
- package/dist/index.browser.d.ts +2 -0
- package/dist/index.browser.js +468 -333
- package/dist/index.d.ts +2 -0
- package/dist/index.js +30 -24
- package/dist/printout.d.ts +140 -0
- package/dist/printout.js +122 -0
- package/dist/renderer.d.ts +30 -0
- package/package.json +9 -1
package/README.md
CHANGED
|
@@ -259,6 +259,67 @@ Two further notes:
|
|
|
259
259
|
to a live deck — deliver it as a fresh document (`webview.html = …`, not an
|
|
260
260
|
in-place rewrite) for the change to take.
|
|
261
261
|
|
|
262
|
+
### Print preview (worksheets and handouts)
|
|
263
|
+
|
|
264
|
+
A worksheet or handout is written to be printed, and PreTeXt lays one out very
|
|
265
|
+
differently on paper than on screen: paginated to a paper size, headers and
|
|
266
|
+
footers per sheet, solutions dropped, and every `<workspace>` grown to the
|
|
267
|
+
height the author asked for — which is the only way to see how much room a
|
|
268
|
+
student really gets. A built page reaches that layout through a URL query
|
|
269
|
+
parameter (`?printpreview=<id>`), which an in-memory preview has nowhere to put.
|
|
270
|
+
|
|
271
|
+
```js
|
|
272
|
+
import { renderHtml } from "@pretextbook/pretext-html";
|
|
273
|
+
// dependency-free subpath, like ./theme and ./reveal:
|
|
274
|
+
import { injectPrintPreview } from "@pretextbook/pretext-html/printout";
|
|
275
|
+
|
|
276
|
+
const { html, printouts, rootPrintout } = await renderHtml({
|
|
277
|
+
sourcePath: "source/worksheet-3.ptx",
|
|
278
|
+
fragment: true,
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
printouts; // [{ id: "ws-3", type: "Worksheet", number: "3",
|
|
282
|
+
// title: "Counting", label: "Worksheet 3: Counting" }]
|
|
283
|
+
rootPrintout; // "ws-3" — this document *is* a printout, so open it on paper
|
|
284
|
+
|
|
285
|
+
// Enter (or leave) the layout later — no re-render, just re-inject:
|
|
286
|
+
const onPaper = injectPrintPreview(html, "ws-3");
|
|
287
|
+
const onScreen = injectPrintPreview(html); // back to the ordinary page
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
`printouts` lists what the page offers, ready for a menu; `rootPrintout` is set
|
|
291
|
+
only when the rendered document is a printout rather than merely containing
|
|
292
|
+
some, which is the case worth defaulting to. Passing `printPreview: "<id>"` to
|
|
293
|
+
`renderHtml` bakes the layout in at render time instead.
|
|
294
|
+
|
|
295
|
+
Three things to know if you embed this:
|
|
296
|
+
|
|
297
|
+
- **State the layout on every delivery, off included.** The injected bridge
|
|
298
|
+
keeps its answer on a window property, and a host that rewrites its document
|
|
299
|
+
in place (`document.open`/`write`/`close`) keeps the same `Window` — so a page
|
|
300
|
+
delivered without a bridge inherits whatever the previous one said. Call
|
|
301
|
+
`injectPrintPreview` on the way to the panel, every time.
|
|
302
|
+
- **An unknown id is treated as "off".** pretext-core.js swaps in the print
|
|
303
|
+
stylesheet _before_ it looks the element up, so a stale id would strand the
|
|
304
|
+
reader on a print-styled page with nothing on it.
|
|
305
|
+
- **The transformation is one-way.** It runs once, from a DOMContentLoaded
|
|
306
|
+
handler, and rearranges the DOM destructively; leaving print preview means
|
|
307
|
+
re-delivering the pristine HTML, not undoing anything.
|
|
308
|
+
- **The print layout is always light**, whatever theme you asked for. Paper is,
|
|
309
|
+
and `print-worksheet.css` carries no dark palette — only a few incidental
|
|
310
|
+
`.dark-mode` rules — so the injection removes the `dark-mode` class and sets
|
|
311
|
+
`data-darkmode="disabled"`, which both pretext-core.js and the theme bridge
|
|
312
|
+
honour (a later `previewThemeMessage` cannot undo it). It also states the page
|
|
313
|
+
background explicitly: the print stylesheet paints none, expecting the theme
|
|
314
|
+
it replaced to have done it, so an embedded page would otherwise show its
|
|
315
|
+
host's backdrop through black print text. The ordinary page is untouched and
|
|
316
|
+
keeps its theme.
|
|
317
|
+
|
|
318
|
+
The print stylesheet is fetched from the CDN when the layout is entered, and
|
|
319
|
+
pretext-core.js waits for its `load` event before continuing — so with no
|
|
320
|
+
network the page stops part-way, unstyled. That is upstream's flow, unchanged
|
|
321
|
+
here.
|
|
322
|
+
|
|
262
323
|
## Requirements
|
|
263
324
|
|
|
264
325
|
- **Node ≥ 24** launched with **`--experimental-wasm-jspi`** (WebAssembly
|
package/assets/preview-html.xsl
CHANGED
|
@@ -232,7 +232,19 @@
|
|
|
232
232
|
<!-- somewhere unrelated. See PRINTOUT_LINK_OVERRIDE in refresh-xsl.mjs. -->
|
|
233
233
|
<xsl:template match="*" mode="standalone-printout-links">
|
|
234
234
|
<div class="print-links">
|
|
235
|
-
<a class="print-link" style="opacity:0.45;cursor:default" aria-disabled="true" title="Print preview
|
|
235
|
+
<a class="print-link" style="opacity:0.45;cursor:default;pointer-events:none" aria-disabled="true" title="Print preview: select this printout from the live preview's own controls">
|
|
236
|
+
<xsl:attribute name="data-printout">
|
|
237
|
+
<xsl:apply-templates select="." mode="html-id"/>
|
|
238
|
+
</xsl:attribute>
|
|
239
|
+
<xsl:attribute name="data-printout-type">
|
|
240
|
+
<xsl:apply-templates select="." mode="type-name"/>
|
|
241
|
+
</xsl:attribute>
|
|
242
|
+
<xsl:attribute name="data-printout-number">
|
|
243
|
+
<xsl:apply-templates select="." mode="number"/>
|
|
244
|
+
</xsl:attribute>
|
|
245
|
+
<xsl:attribute name="data-printout-title">
|
|
246
|
+
<xsl:apply-templates select="." mode="title-simple"/>
|
|
247
|
+
</xsl:attribute>
|
|
236
248
|
<xsl:call-template name="insert-symbol">
|
|
237
249
|
<xsl:with-param name="name" select="'print'"/>
|
|
238
250
|
</xsl:call-template>
|