@pretextbook/pretext-html 0.1.1 → 0.3.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.
Files changed (121) hide show
  1. package/README.md +82 -1
  2. package/assets/preview-html.xsl +0 -0
  3. package/assets/upstream.json +0 -0
  4. package/assets/xsl/README.md +0 -0
  5. package/assets/xsl/entities.ent +0 -0
  6. package/assets/xsl/extract-asymptote.xsl +0 -0
  7. package/assets/xsl/extract-biblio-csl.xsl +0 -0
  8. package/assets/xsl/extract-datafile.xsl +0 -0
  9. package/assets/xsl/extract-dynamic.xsl +0 -0
  10. package/assets/xsl/extract-identity.xsl +0 -0
  11. package/assets/xsl/extract-interactive.xsl +0 -0
  12. package/assets/xsl/extract-latex-image.xsl +0 -0
  13. package/assets/xsl/extract-mermaid.xsl +0 -0
  14. package/assets/xsl/extract-mom.xsl +0 -0
  15. package/assets/xsl/extract-pg.xsl +0 -0
  16. package/assets/xsl/extract-prefigure.xsl +0 -0
  17. package/assets/xsl/extract-qrcode.xsl +0 -0
  18. package/assets/xsl/extract-runestone-page-template.xsl +0 -0
  19. package/assets/xsl/extract-sageplot.xsl +0 -0
  20. package/assets/xsl/extract-stack.xsl +0 -0
  21. package/assets/xsl/extract-trace.xsl +0 -0
  22. package/assets/xsl/extract-youtube.xsl +0 -0
  23. package/assets/xsl/html-symbols.xsl +0 -0
  24. package/assets/xsl/latex/pretext-latex-AIM.xsl +0 -0
  25. package/assets/xsl/latex/pretext-latex-CLP.xsl +0 -0
  26. package/assets/xsl/latex/pretext-latex-chaos.xsl +0 -0
  27. package/assets/xsl/latex/pretext-latex-dyslexic-font.xsl +0 -0
  28. package/assets/xsl/latex/pretext-latex-guide.xsl +0 -0
  29. package/assets/xsl/latex/pretext-latex-texstyle.xsl +0 -0
  30. package/assets/xsl/localizations/README.md +0 -0
  31. package/assets/xsl/localizations/af-ZA.xml +0 -0
  32. package/assets/xsl/localizations/bg-BG.xml +0 -0
  33. package/assets/xsl/localizations/ca-ES.xml +0 -0
  34. package/assets/xsl/localizations/cs-CZ.xml +0 -0
  35. package/assets/xsl/localizations/de-DE.xml +0 -0
  36. package/assets/xsl/localizations/en-US.xml +0 -0
  37. package/assets/xsl/localizations/es-ES.xml +0 -0
  38. package/assets/xsl/localizations/fi-FI.xml +0 -0
  39. package/assets/xsl/localizations/fr-CA.xml +0 -0
  40. package/assets/xsl/localizations/fr-FR.xml +0 -0
  41. package/assets/xsl/localizations/hu-HU.xml +0 -0
  42. package/assets/xsl/localizations/it-IT.xml +0 -0
  43. package/assets/xsl/localizations/ku-CKB.xml +0 -0
  44. package/assets/xsl/localizations/localizations.xml +0 -0
  45. package/assets/xsl/localizations/nl-NL.xml +0 -0
  46. package/assets/xsl/localizations/pt-BR.xml +0 -0
  47. package/assets/xsl/localizations/pt-PT.xml +0 -0
  48. package/assets/xsl/localizations/zh-HANS.xml +0 -0
  49. package/assets/xsl/pretext-assembly.xsl +0 -0
  50. package/assets/xsl/pretext-basic-html.xsl +0 -0
  51. package/assets/xsl/pretext-beamer.xsl +0 -0
  52. package/assets/xsl/pretext-braille-preprint.xsl +0 -0
  53. package/assets/xsl/pretext-common.xsl +0 -0
  54. package/assets/xsl/pretext-dynamic.xsl +0 -0
  55. package/assets/xsl/pretext-epub.xsl +0 -0
  56. package/assets/xsl/pretext-fo.xsl +0 -0
  57. package/assets/xsl/pretext-html.xsl +0 -0
  58. package/assets/xsl/pretext-json-manifest.xsl +0 -0
  59. package/assets/xsl/pretext-jupyter.xsl +0 -0
  60. package/assets/xsl/pretext-latex-classic.xsl +0 -0
  61. package/assets/xsl/pretext-latex-common.xsl +0 -0
  62. package/assets/xsl/pretext-latex.xsl +0 -0
  63. package/assets/xsl/pretext-litprog.xsl +0 -0
  64. package/assets/xsl/pretext-merge.xsl +0 -0
  65. package/assets/xsl/pretext-numbers.xsl +0 -0
  66. package/assets/xsl/pretext-revealjs.xsl +0 -0
  67. package/assets/xsl/pretext-runestone-fitb.xsl +0 -0
  68. package/assets/xsl/pretext-runestone-static.xsl +0 -0
  69. package/assets/xsl/pretext-runestone.xsl +0 -0
  70. package/assets/xsl/pretext-sage-doctest.xsl +0 -0
  71. package/assets/xsl/pretext-smc.xsl +0 -0
  72. package/assets/xsl/pretext-solution-manual-latex.xsl +0 -0
  73. package/assets/xsl/pretext-text-utilities.xsl +0 -0
  74. package/assets/xsl/pretext-text.xsl +0 -0
  75. package/assets/xsl/pretext-units.xsl +0 -0
  76. package/assets/xsl/pretext-view-source.xsl +0 -0
  77. package/assets/xsl/pretext-ww-problem-sets.xsl +0 -0
  78. package/assets/xsl/publisher-variables.xsl +0 -0
  79. package/assets/xsl/support/README.md +0 -0
  80. package/assets/xsl/support/extract-math.xsl +0 -0
  81. package/assets/xsl/support/package-math.xsl +0 -0
  82. package/assets/xsl/support/play-button/README.md +0 -0
  83. package/assets/xsl/support/play-button/play-button.png +0 -0
  84. package/assets/xsl/support/play-button/play-button.svg +0 -0
  85. package/assets/xsl/support/pretext-pg-macros.xsl +0 -0
  86. package/assets/xsl/support/webpack_static_imports.xml +0 -0
  87. package/assets/xsl/tests/README.md +0 -0
  88. package/assets/xsl/tests/null.xml +0 -0
  89. package/assets/xsl/tests/pretext-text-utilities-test.xsl +0 -0
  90. package/assets/xsl/utilities/README.md +0 -0
  91. package/assets/xsl/utilities/author-report.xsl +0 -0
  92. package/assets/xsl/utilities/deprecate-autoname.sed +0 -0
  93. package/assets/xsl/utilities/deprecate-index.sed +0 -0
  94. package/assets/xsl/utilities/fix-deprecations.xsl +0 -0
  95. package/assets/xsl/utilities/pretext-enhanced-source.xsl +0 -0
  96. package/assets/xsl/utilities/report-publisher-variables.xsl +0 -0
  97. package/assets/xsl/xml-to-json.xsl +0 -0
  98. package/assets/xsl/xml-to-string.xsl +0 -0
  99. package/assets/xsl-bundle.json +1 -0
  100. package/dist/assets.d.ts +43 -0
  101. package/dist/assets.js +76 -0
  102. package/dist/cli-CzoinNle.js +639 -0
  103. package/dist/cli.d.ts +0 -0
  104. package/dist/cli.js +1 -1
  105. package/dist/host.browser.d.ts +29 -0
  106. package/dist/host.d.ts +41 -0
  107. package/dist/index.browser.d.ts +29 -0
  108. package/dist/index.browser.js +701 -0
  109. package/dist/index.d.ts +8 -0
  110. package/dist/index.js +20 -13
  111. package/dist/internal/posix-path.d.ts +59 -0
  112. package/dist/missing-asset.d.ts +31 -0
  113. package/dist/mounts.d.ts +18 -0
  114. package/dist/publication.d.ts +27 -0
  115. package/dist/renderer.d.ts +33 -1
  116. package/dist/sourcemap.d.ts +0 -0
  117. package/dist/theme.d.ts +0 -0
  118. package/dist/theme.js +0 -0
  119. package/dist/xinclude.d.ts +0 -0
  120. package/package.json +17 -3
  121. package/dist/cli-BQizBK0N.js +0 -555
package/dist/index.js CHANGED
@@ -1,16 +1,23 @@
1
- import { d as i, f as a, a as s, i as t, r as l, m, x as o } from "./cli-BQizBK0N.js";
2
- import { PREVIEW_THEME_MESSAGE as p, injectThemeBridge as E, isPreviewTheme as d, previewThemeMessage as f, themeBridgeScript as c } from "./theme.js";
1
+ import { d as r, f as i, a as t, i as a, r as l, m as o, s as m, b as n, x as d } from "./cli-CzoinNle.js";
2
+ import { describeAsset as c, missingAssetPlaceholder as f, missingAssetSvg as g, rewriteAssetUrls as A } from "./assets.js";
3
+ import { PREVIEW_THEME_MESSAGE as h, injectThemeBridge as S, isPreviewTheme as b, previewThemeMessage as u, themeBridgeScript as x } from "./theme.js";
3
4
  export {
4
- p as PREVIEW_THEME_MESSAGE,
5
- i as defaultXslDir,
6
- a as findSourceMapEntry,
7
- s as forcePortablePublication,
8
- E as injectThemeBridge,
9
- t as isJspiAvailable,
10
- d as isPreviewTheme,
11
- f as previewThemeMessage,
5
+ h as PREVIEW_THEME_MESSAGE,
6
+ r as defaultXslDir,
7
+ c as describeAsset,
8
+ i as findSourceMapEntry,
9
+ t as forcePortablePublication,
10
+ S as injectThemeBridge,
11
+ a as isJspiAvailable,
12
+ b as isPreviewTheme,
13
+ f as missingAssetPlaceholder,
14
+ g as missingAssetSvg,
15
+ u as previewThemeMessage,
12
16
  l as renderHtml,
13
- m as runCli,
14
- c as themeBridgeScript,
15
- o as xpathStringLiteral
17
+ A as rewriteAssetUrls,
18
+ o as runCli,
19
+ m as setAssetsBase,
20
+ n as setMountReader,
21
+ x as themeBridgeScript,
22
+ d as xpathStringLiteral
16
23
  };
@@ -0,0 +1,59 @@
1
+ /**
2
+ * A posix-only stand-in for `node:path`, substituted for it when this package
3
+ * is built for the browser (see vite.config.ts).
4
+ *
5
+ * This is safe because none of the paths this package computes ever reach a
6
+ * real filesystem: libxslt-wasm is compiled with FILESYSTEM=0, so every path
7
+ * ends up as either a key in the mount table or a segment of a
8
+ * `*.ptx.invalid` URL (see mounts.ts). They are virtual paths, and virtual
9
+ * paths are posix paths — a browser caller passes `sourcePath: "/main.ptx"`
10
+ * and means exactly what it says.
11
+ *
12
+ * Only the handful of functions this package actually uses are implemented.
13
+ */
14
+ export declare const sep = "/";
15
+ /**
16
+ * Collapse `.` and `..` segments. An absolute path clamps at the root
17
+ * (`/a/../../b` → `/b`), which is what makes the containment checks in
18
+ * mounts.ts and xinclude.ts safe against `..` traversal.
19
+ */
20
+ export declare function normalize(p: string): string;
21
+ /**
22
+ * Resolve right-to-left until an absolute path is found. With no absolute
23
+ * segment the result is rooted at `/` rather than at a process cwd — there is
24
+ * no cwd in a browser, and a virtual path is meaningless relative to one.
25
+ */
26
+ export declare function resolve(...segments: string[]): string;
27
+ export declare function join(...segments: string[]): string;
28
+ export declare function dirname(p: string): string;
29
+ export declare function relative(from: string, to: string): string;
30
+ /**
31
+ * `path.posix` self-reference: on posix, `path` and `path.posix` are the same
32
+ * thing, and call sites that reach for `path.posix.normalize` to be explicit
33
+ * should keep working.
34
+ */
35
+ export declare const posix: {
36
+ sep: string;
37
+ normalize: typeof normalize;
38
+ resolve: typeof resolve;
39
+ join: typeof join;
40
+ dirname: typeof dirname;
41
+ relative: typeof relative;
42
+ };
43
+ declare const _default: {
44
+ sep: string;
45
+ normalize: typeof normalize;
46
+ resolve: typeof resolve;
47
+ join: typeof join;
48
+ dirname: typeof dirname;
49
+ relative: typeof relative;
50
+ posix: {
51
+ sep: string;
52
+ normalize: typeof normalize;
53
+ resolve: typeof resolve;
54
+ join: typeof join;
55
+ dirname: typeof dirname;
56
+ relative: typeof relative;
57
+ };
58
+ };
59
+ export default _default;
@@ -0,0 +1,31 @@
1
+ import { AssetKind } from './assets.js';
2
+ /** What a missing asset is, in the terms an author would recognise. */
3
+ export interface MissingAsset {
4
+ kind: AssetKind;
5
+ /**
6
+ * For generated assets, the producing tool — `latex-image`, `sageplot`,
7
+ * `asymptote`, `prefigure` — which under managed directories is literally
8
+ * the first path segment, and is also the `pretext generate` target. For
9
+ * external assets, a coarse media word derived from the extension.
10
+ */
11
+ assetType: string;
12
+ /** Basename, for display. */
13
+ fileName: string;
14
+ }
15
+ /**
16
+ * Classify an asset path. Generated paths are `<tool>/<name>` under managed
17
+ * directories; a path with no directory segment predates that scheme, so there
18
+ * is no tool name to report.
19
+ */
20
+ export declare function describeAsset(kind: AssetKind, relPath: string): MissingAsset;
21
+ /** Render the placeholder as standalone SVG markup. */
22
+ export declare function missingAssetSvg(asset: MissingAsset): string;
23
+ /**
24
+ * The placeholder as a `data:` URI, ready to drop into an `img` `src`.
25
+ *
26
+ * Percent-encoded rather than base64 so the `data-ptx-missing` marker stays
27
+ * greppable in the emitted page (see the module comment), and so the payload
28
+ * stays readable when someone views source. Only the characters that would
29
+ * break a URI or an HTML attribute are escaped.
30
+ */
31
+ export declare function missingAssetPlaceholder(kind: AssetKind, relPath: string): string;
package/dist/mounts.d.ts CHANGED
@@ -10,11 +10,29 @@
10
10
  * reserved `.invalid` TLD and serve them from local directories or in-memory
11
11
  * strings. No HTTP server, no real network traffic.
12
12
  */
13
+ /**
14
+ * Reads `relPath` (posix, leading "/") beneath mount root `root`, or resolves
15
+ * `undefined` when it is missing or escapes the mount. `root` is opaque: a
16
+ * directory under Node, a base URL in a browser, whatever an embedder's own
17
+ * reader wants.
18
+ */
19
+ export type MountReader = (root: string, relPath: string) => Promise<Uint8Array | string | undefined>;
20
+ /**
21
+ * Replace how mounted files are read. Lets an embedder serve the stylesheets
22
+ * from somewhere the platform seam does not cover — an in-memory map, a zip,
23
+ * a VS Code webview resource URI — without patching `globalThis.fetch`.
24
+ * Also how scripts/build-xsl-bundle.mjs records which files a render touches.
25
+ */
26
+ export declare function setMountReader(reader: MountReader): void;
13
27
  /** Install the shim (idempotent). Must run before libxslt-wasm loads anything. */
14
28
  export declare function installFetchShim(): void;
15
29
  /**
16
30
  * Serve `dir` under a unique fake origin. Returns the base URL
17
31
  * (e.g. `http://mnt1.ptx.invalid`); resource paths append to it.
32
+ *
33
+ * `dir` is stored verbatim and handed back to the {@link MountReader}, which
34
+ * owns its interpretation — under Node a directory path, in a browser a base
35
+ * URL.
18
36
  */
19
37
  export declare function mountDirectory(dir: string): string;
20
38
  export declare function unmountDirectory(baseUrl: string): void;
@@ -14,3 +14,30 @@
14
14
  * forced, preserving everything else from `publicationXml` when given.
15
15
  */
16
16
  export declare function forcePortablePublication(publicationXml?: string): string;
17
+ /**
18
+ * Where a project's images live, as declared by
19
+ * `<source><directories external generated/></source>`.
20
+ *
21
+ * Both paths are relative to the directory of the *main* source file — the one
22
+ * holding `<pretext>` — not to whichever file is being rendered. See
23
+ * RenderOptions.mainSourcePath.
24
+ */
25
+ export interface AssetDirectories {
26
+ /** e.g. "../assets/" — trailing slash, relative to the main source dir. */
27
+ external?: string;
28
+ /** e.g. "../generated-assets/" — likewise. */
29
+ generated?: string;
30
+ /**
31
+ * True when the publication declares both attributes ("managed
32
+ * directories"). Only then does PreTeXt emit asset URLs under the fixed
33
+ * `external/` and `generated/` prefixes that {@link rewriteAssetUrls} keys
34
+ * on; legacy projects emit bare or `images/`-prefixed paths that cannot be
35
+ * told apart from anything else, so the preview leaves them alone.
36
+ */
37
+ managed: boolean;
38
+ }
39
+ /**
40
+ * Read the asset directories from a publication file, falling back to the
41
+ * defaults baked into MINIMAL_PUBLICATION when none is supplied.
42
+ */
43
+ export declare function readAssetDirectories(publicationXml?: string): AssetDirectories;
@@ -3,6 +3,19 @@ import { PreviewTheme } from './theme.js';
3
3
  export interface RenderOptions {
4
4
  /** Path to the root PreTeXt source file (typically source/main.ptx). */
5
5
  sourcePath: string;
6
+ /**
7
+ * Path to the project's *main* source file — the one holding `<pretext>`.
8
+ * Defaults to `sourcePath`, which is correct whenever a complete document is
9
+ * being rendered.
10
+ *
11
+ * PreTeXt anchors the publication file's relative asset directories
12
+ * (`source/directories/@external|@generated`) at this file's directory, and
13
+ * so does every `document()` the stylesheets make. Rendering a fragment from
14
+ * a subdirectory therefore needs it: previewing `source/chapters/ch1.ptx`
15
+ * must still resolve `../generated-assets/` from `source/`, not from
16
+ * `source/chapters/`. Without it, generated images silently render empty.
17
+ */
18
+ mainSourcePath?: string;
6
19
  /**
7
20
  * Source text to transform instead of reading `sourcePath` from disk.
8
21
  * `sourcePath` is still used to resolve relative xi:includes. Lets callers
@@ -77,8 +90,24 @@ export interface RenderResult {
77
90
  html: string;
78
91
  /** Present when RenderOptions.sourceMap was set. */
79
92
  sourceMap?: PtxSourceMap;
93
+ /**
94
+ * Absolute directories that the `external/` and `generated/` URL prefixes in
95
+ * `html` refer to, resolved from the publication file against the main
96
+ * source file's directory. Feed these to `rewriteAssetUrls` to point the
97
+ * page at assets the host can actually serve (see assets.ts).
98
+ *
99
+ * Absent for legacy projects that declare neither directory: those emit bare
100
+ * or `images/`-prefixed URLs that cannot be identified reliably.
101
+ */
102
+ assetDirs?: {
103
+ external: string;
104
+ generated: string;
105
+ };
80
106
  }
81
- /** Vendored stylesheets shipped with this package. */
107
+ /**
108
+ * Vendored stylesheets shipped with this package. A directory under Node, a
109
+ * base URL in the browser build — either way, a mount root (see host.ts).
110
+ */
82
111
  export declare function defaultXslDir(): string;
83
112
  export declare function isJspiAvailable(): boolean;
84
113
  /** Quote a string as an XPath 1.0 string literal. */
@@ -90,5 +119,8 @@ export declare function xpathStringLiteral(value: string): string;
90
119
  * per-section rendering: roughly 100ms for a small article, a few seconds for
91
120
  * a 150-section book. Generated assets (latex-image, sageplot, …) are not
92
121
  * produced — those require the Python toolchain.
122
+ *
123
+ * Concurrent calls are safe but not parallel: they queue and run one at a
124
+ * time (see {@link renderQueue}).
93
125
  */
94
126
  export declare function renderHtml(options: RenderOptions): Promise<RenderResult>;
File without changes
package/dist/theme.d.ts CHANGED
File without changes
package/dist/theme.js CHANGED
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pretextbook/pretext-html",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "description": "Convert PreTeXt documents to HTML in pure JavaScript using the official PreTeXt XSLT stylesheets via libxslt-wasm. No Python or PreTeXt installation required.",
5
5
  "author": "Oscar Levin",
6
6
  "license": "MIT",
@@ -20,6 +20,9 @@
20
20
  "*": {
21
21
  "theme": [
22
22
  "./dist/theme.d.ts"
23
+ ],
24
+ "assets": [
25
+ "./dist/assets.d.ts"
23
26
  ]
24
27
  }
25
28
  },
@@ -28,6 +31,10 @@
28
31
  },
29
32
  "exports": {
30
33
  ".": {
34
+ "browser": {
35
+ "types": "./dist/index.browser.d.ts",
36
+ "default": "./dist/index.browser.js"
37
+ },
31
38
  "types": "./dist/index.d.ts",
32
39
  "import": "./dist/index.js",
33
40
  "default": "./dist/index.js"
@@ -37,6 +44,11 @@
37
44
  "import": "./dist/theme.js",
38
45
  "default": "./dist/theme.js"
39
46
  },
47
+ "./assets": {
48
+ "types": "./dist/assets.d.ts",
49
+ "import": "./dist/assets.js",
50
+ "default": "./dist/assets.js"
51
+ },
40
52
  "./cli": "./dist/cli.js"
41
53
  },
42
54
  "sideEffects": false,
@@ -46,9 +58,11 @@
46
58
  "cli.mjs"
47
59
  ],
48
60
  "scripts": {
49
- "build": "vite build",
61
+ "build": "vite build && npm run build:browser && npm run build-xsl-bundle",
62
+ "build:browser": "vite build --mode browser",
50
63
  "test": "vitest run",
51
- "refresh-xsl": "node scripts/refresh-xsl.mjs"
64
+ "refresh-xsl": "node scripts/refresh-xsl.mjs",
65
+ "build-xsl-bundle": "node --experimental-wasm-jspi scripts/build-xsl-bundle.mjs"
52
66
  },
53
67
  "dependencies": {
54
68
  "@pretextbook/libxslt-wasm": "^0.1.1",