@nxgt/material-core 0.1.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 (138) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +335 -0
  3. package/dist/chunks/index-0xc5q9tp.js +81 -0
  4. package/dist/chunks/index-0xc5q9tp.js.map +10 -0
  5. package/dist/chunks/index-2gcgcmc0.js +36 -0
  6. package/dist/chunks/index-2gcgcmc0.js.map +10 -0
  7. package/dist/chunks/index-3ca6xe71.js +36 -0
  8. package/dist/chunks/index-3ca6xe71.js.map +10 -0
  9. package/dist/chunks/index-5r6rzp43.js +90 -0
  10. package/dist/chunks/index-5r6rzp43.js.map +10 -0
  11. package/dist/chunks/index-6tn0wjsb.js +13 -0
  12. package/dist/chunks/index-6tn0wjsb.js.map +10 -0
  13. package/dist/chunks/index-8gf9e2d4.js +76 -0
  14. package/dist/chunks/index-8gf9e2d4.js.map +11 -0
  15. package/dist/chunks/index-eh0e5ex7.js +61 -0
  16. package/dist/chunks/index-eh0e5ex7.js.map +10 -0
  17. package/dist/chunks/index-g7rh8fpv.js +57 -0
  18. package/dist/chunks/index-g7rh8fpv.js.map +10 -0
  19. package/dist/chunks/index-h3vjydz7.js +113 -0
  20. package/dist/chunks/index-h3vjydz7.js.map +10 -0
  21. package/dist/chunks/index-paaaedrm.js +37 -0
  22. package/dist/chunks/index-paaaedrm.js.map +10 -0
  23. package/dist/chunks/index-w3ajz57t.js +72 -0
  24. package/dist/chunks/index-w3ajz57t.js.map +10 -0
  25. package/dist/chunks/index-z3yjh0a8.js +642 -0
  26. package/dist/chunks/index-z3yjh0a8.js.map +18 -0
  27. package/dist/index.d.ts +21 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +133 -0
  30. package/dist/index.js.map +9 -0
  31. package/dist/lib/currency-digits.d.ts +8 -0
  32. package/dist/lib/currency-digits.d.ts.map +1 -0
  33. package/dist/lib/currency-digits.js +24 -0
  34. package/dist/lib/currency-digits.js.map +10 -0
  35. package/dist/lib/field-blur-layers.d.ts +35 -0
  36. package/dist/lib/field-blur-layers.d.ts.map +1 -0
  37. package/dist/lib/field-blur-layers.js +52 -0
  38. package/dist/lib/field-blur-layers.js.map +10 -0
  39. package/dist/lib/pdf-download.d.ts +36 -0
  40. package/dist/lib/pdf-download.d.ts.map +1 -0
  41. package/dist/lib/pdf-download.js +15 -0
  42. package/dist/lib/pdf-download.js.map +9 -0
  43. package/dist/lib/pdf-file-name.d.ts +10 -0
  44. package/dist/lib/pdf-file-name.d.ts.map +1 -0
  45. package/dist/lib/pdf-file-name.js +12 -0
  46. package/dist/lib/pdf-file-name.js.map +9 -0
  47. package/dist/lib/pdf-source.d.ts +58 -0
  48. package/dist/lib/pdf-source.d.ts.map +1 -0
  49. package/dist/lib/pdf-source.js +21 -0
  50. package/dist/lib/pdf-source.js.map +9 -0
  51. package/dist/lib/print-format.utils.d.ts +72 -0
  52. package/dist/lib/print-format.utils.d.ts.map +1 -0
  53. package/dist/lib/print-format.utils.js +14 -0
  54. package/dist/lib/print-format.utils.js.map +9 -0
  55. package/dist/lib/print-fraction-digits.d.ts +13 -0
  56. package/dist/lib/print-fraction-digits.d.ts.map +1 -0
  57. package/dist/lib/print-fraction-digits.js +11 -0
  58. package/dist/lib/print-fraction-digits.js.map +9 -0
  59. package/dist/lib/print-table.utils.d.ts +69 -0
  60. package/dist/lib/print-table.utils.d.ts.map +1 -0
  61. package/dist/lib/print-table.utils.js +15 -0
  62. package/dist/lib/print-table.utils.js.map +9 -0
  63. package/dist/lib/print-value.utils.d.ts +41 -0
  64. package/dist/lib/print-value.utils.d.ts.map +1 -0
  65. package/dist/lib/print-value.utils.js +13 -0
  66. package/dist/lib/print-value.utils.js.map +9 -0
  67. package/dist/pdf/file-loader.d.ts +19 -0
  68. package/dist/pdf/file-loader.d.ts.map +1 -0
  69. package/dist/pdf/file-loader.js +11 -0
  70. package/dist/pdf/file-loader.js.map +9 -0
  71. package/dist/pdf/http.d.ts +23 -0
  72. package/dist/pdf/http.d.ts.map +1 -0
  73. package/dist/pdf/http.js +13 -0
  74. package/dist/pdf/http.js.map +9 -0
  75. package/dist/pdf/index.d.ts +12 -0
  76. package/dist/pdf/index.d.ts.map +1 -0
  77. package/dist/pdf/index.js +99 -0
  78. package/dist/pdf/index.js.map +9 -0
  79. package/dist/pdf/model/builders.d.ts +59 -0
  80. package/dist/pdf/model/builders.d.ts.map +1 -0
  81. package/dist/pdf/model/data-table.d.ts +25 -0
  82. package/dist/pdf/model/data-table.d.ts.map +1 -0
  83. package/dist/pdf/model/index.d.ts +5 -0
  84. package/dist/pdf/model/index.d.ts.map +1 -0
  85. package/dist/pdf/model/index.js +60 -0
  86. package/dist/pdf/model/index.js.map +9 -0
  87. package/dist/pdf/model/nodes.d.ts +135 -0
  88. package/dist/pdf/model/nodes.d.ts.map +1 -0
  89. package/dist/pdf/model/theme.d.ts +17 -0
  90. package/dist/pdf/model/theme.d.ts.map +1 -0
  91. package/dist/pdf/model/types.d.ts +124 -0
  92. package/dist/pdf/model/types.d.ts.map +1 -0
  93. package/dist/pdf/render/context.d.ts +51 -0
  94. package/dist/pdf/render/context.d.ts.map +1 -0
  95. package/dist/pdf/render/document.d.ts +22 -0
  96. package/dist/pdf/render/document.d.ts.map +1 -0
  97. package/dist/pdf/render/index.d.ts +9 -0
  98. package/dist/pdf/render/index.d.ts.map +1 -0
  99. package/dist/pdf/render/index.js +44 -0
  100. package/dist/pdf/render/index.js.map +9 -0
  101. package/dist/pdf/render/nodes/blocks.d.ts +20 -0
  102. package/dist/pdf/render/nodes/blocks.d.ts.map +1 -0
  103. package/dist/pdf/render/nodes/header.d.ts +15 -0
  104. package/dist/pdf/render/nodes/header.d.ts.map +1 -0
  105. package/dist/pdf/render/nodes/layout.d.ts +45 -0
  106. package/dist/pdf/render/nodes/layout.d.ts.map +1 -0
  107. package/dist/pdf/render/nodes/table.d.ts +15 -0
  108. package/dist/pdf/render/nodes/table.d.ts.map +1 -0
  109. package/dist/pdf/render/page.d.ts +31 -0
  110. package/dist/pdf/render/page.d.ts.map +1 -0
  111. package/dist/pdf/render/render-node.d.ts +11 -0
  112. package/dist/pdf/render/render-node.d.ts.map +1 -0
  113. package/dist/pdf/render/styles.d.ts +304 -0
  114. package/dist/pdf/render/styles.d.ts.map +1 -0
  115. package/dist/pdf-viewer/index.d.ts +14 -0
  116. package/dist/pdf-viewer/index.d.ts.map +1 -0
  117. package/dist/pdf-viewer/index.js +380 -0
  118. package/dist/pdf-viewer/index.js.map +15 -0
  119. package/dist/pdf-viewer/pdf-document-search.d.ts +44 -0
  120. package/dist/pdf-viewer/pdf-document-search.d.ts.map +1 -0
  121. package/dist/pdf-viewer/pdf-escape.d.ts +7 -0
  122. package/dist/pdf-viewer/pdf-escape.d.ts.map +1 -0
  123. package/dist/pdf-viewer/pdf-page-geometry.d.ts +62 -0
  124. package/dist/pdf-viewer/pdf-page-geometry.d.ts.map +1 -0
  125. package/dist/pdf-viewer/pdf-page-sizes.d.ts +38 -0
  126. package/dist/pdf-viewer/pdf-page-sizes.d.ts.map +1 -0
  127. package/dist/pdf-viewer/pdf-scroll-spy.d.ts +43 -0
  128. package/dist/pdf-viewer/pdf-scroll-spy.d.ts.map +1 -0
  129. package/dist/pdf-viewer/pdf-text-search.d.ts +26 -0
  130. package/dist/pdf-viewer/pdf-text-search.d.ts.map +1 -0
  131. package/dist/vite/index.d.ts +81 -0
  132. package/dist/vite/index.d.ts.map +1 -0
  133. package/dist/vite/index.js +31 -0
  134. package/dist/vite/index.js.map +10 -0
  135. package/docs/README.md +9 -0
  136. package/docs/roadmap.md +35 -0
  137. package/docs/troubleshooting.md +105 -0
  138. package/package.json +187 -0
@@ -0,0 +1,43 @@
1
+ /** A vertical extent on screen, as `getBoundingClientRect` gives it. */
2
+ export type PdfBox = {
3
+ top: number;
4
+ bottom: number;
5
+ };
6
+ /**
7
+ * The page with the most of itself on screen, the first one on a tie; once
8
+ * scrolled to the end, the last page on screen, however little of it shows.
9
+ */
10
+ export declare function mostVisiblePage(view: PdfBox & {
11
+ atEnd: boolean;
12
+ }, pages: Iterable<readonly [number, PdfBox]>): number | null;
13
+ /**
14
+ * Scrolls the page area around `node`, and nothing else: `scrollIntoView`
15
+ * would scroll the host page too. `block` puts `node` at the area's top or
16
+ * centre.
17
+ */
18
+ export declare function scrollIntoArea(node: Element, block: 'start' | 'center', behavior?: ScrollBehavior): void;
19
+ /**
20
+ * Keeps `node` at the top of the page area while the pages above it change
21
+ * size (the zoom fitting to page sizes still arriving), until the user
22
+ * scrolls, taps, clicks or types in the page area, or the returned function
23
+ * is called. `beforeScroll` runs before each correction.
24
+ */
25
+ export declare function pinToPage(node: () => Element | null | undefined, beforeScroll: () => void): () => void;
26
+ /**
27
+ * Reports the page most on screen as the reader's page area (`root`)
28
+ * scrolls. `hold`
29
+ * ignores scrolling until it has stopped for `idleMs`: the reader calls it
30
+ * before scrolling to a page itself, so the pages it passes on the way are
31
+ * not reported.
32
+ */
33
+ export declare function createScrollSpy(root: () => HTMLElement | null | undefined, pages: () => ReadonlyMap<number, HTMLElement>, onPage: (page: number) => void, idleMs?: number): {
34
+ hold(): void;
35
+ stop(): void;
36
+ };
37
+ /**
38
+ * Scrolls a page's match to the middle of the page area once the page has
39
+ * drawn its mark, polling each frame for up to `timeout` ms; `beforeScroll`
40
+ * runs first. Returns a function that stops waiting.
41
+ */
42
+ export declare function revealHit(findPage: () => ParentNode | null | undefined, hit: number, beforeScroll?: () => void, timeout?: number): () => void;
43
+ //# sourceMappingURL=pdf-scroll-spy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf-scroll-spy.d.ts","sourceRoot":"","sources":["../../src/pdf-viewer/pdf-scroll-spy.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,MAAM,MAAM,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAErD;;;GAGG;AACH,wBAAgB,eAAe,CAC9B,IAAI,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,EACjC,KAAK,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GACxC,MAAM,GAAG,IAAI,CAkBf;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC7B,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,OAAO,GAAG,QAAQ,EACzB,QAAQ,GAAE,cAAyB,QASnC;AAUD;;;;;GAKG;AACH,wBAAgB,SAAS,CACxB,IAAI,EAAE,MAAM,OAAO,GAAG,IAAI,GAAG,SAAS,EACtC,YAAY,EAAE,MAAM,IAAI,cA4BxB;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC9B,IAAI,EAAE,MAAM,WAAW,GAAG,IAAI,GAAG,SAAS,EAC1C,KAAK,EAAE,MAAM,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,EAC7C,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EAC9B,MAAM,SAAM;;;EAiEZ;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CACxB,QAAQ,EAAE,MAAM,UAAU,GAAG,IAAI,GAAG,SAAS,EAC7C,GAAG,EAAE,MAAM,EACX,YAAY,GAAE,MAAM,IAAe,EACnC,OAAO,SAAO,cAgBd"}
@@ -0,0 +1,26 @@
1
+ /** One item of `page.getTextContent()`: marked-content items have no `str`. */
2
+ export type PdfTextItem = {
3
+ str?: string;
4
+ hasEOL?: boolean;
5
+ };
6
+ /** A page's text, and where each text item starts in it. */
7
+ export type PdfPageText = {
8
+ text: string;
9
+ starts: number[];
10
+ };
11
+ /** A match in a page's text: `end` is exclusive. */
12
+ export type PdfTextRange = {
13
+ start: number;
14
+ end: number;
15
+ };
16
+ /** Joins the items' text, a line break after each item that ends a line. */
17
+ export declare function pageTextFromItems(items: readonly PdfTextItem[]): PdfPageText;
18
+ /** Every match of `query` in `text`, ignoring case, accents and spacing. */
19
+ export declare function findTextMatches(text: string, query: string): PdfTextRange[];
20
+ /**
21
+ * One text item's HTML, its part of each match wrapped in
22
+ * `<mark class="pdf-highlight" data-hit="…">`. A match across items gets a
23
+ * mark in each; the current one also carries `data-current`.
24
+ */
25
+ export declare function highlightItemHtml(str: string, itemStart: number, matches: readonly PdfTextRange[], current?: number): string;
26
+ //# sourceMappingURL=pdf-text-search.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf-text-search.d.ts","sourceRoot":"","sources":["../../src/pdf-viewer/pdf-text-search.ts"],"names":[],"mappings":"AAEA,+EAA+E;AAC/E,MAAM,MAAM,WAAW,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAE7D,4DAA4D;AAC5D,MAAM,MAAM,WAAW,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAE7D,oDAAoD;AACpD,MAAM,MAAM,YAAY,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1D,4EAA4E;AAC5E,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,GAAG,WAAW,CAS5E;AAiCD,4EAA4E;AAC5E,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,EAAE,CAa3E;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAChC,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,SAAS,YAAY,EAAE,EAChC,OAAO,SAAK,UAgBZ"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Build-time helpers for the apps that consume this library.
3
+ *
4
+ * This entry is the odd one out: everything else here runs in a browser or in
5
+ * an SSR server, and the `/vite` entry is Node code that runs inside a
6
+ * consumer's `vite.config.ts` (or a Nuxt app's Nitro build). It is here anyway
7
+ * because the problem it solves is this package's to own — a consumer should
8
+ * not have to rediscover it — and because there is exactly one copy of the fix
9
+ * to maintain, shared by `@nxgt/material` and `@nxgt/material-vue`.
10
+ *
11
+ * It imports nothing at runtime: `Plugin` is a type, erased by the compiler, so
12
+ * the built `dist/vite.js` has no dependency on `vite` at all.
13
+ */
14
+ import type { Plugin } from 'vite';
15
+ /**
16
+ * Bundles pdfkit's fourteen standard fonts instead of leaving them to a
17
+ * `require` that cannot work in a bundle.
18
+ *
19
+ * **Only needed by an app that renders PDFs** (`@nxgt/material/print`, or
20
+ * `@nxgt/material-vue/pdf`). No other entry reaches `@react-pdf/renderer`, so
21
+ * an app that does not print never sees this at all.
22
+ * If you do print, read on, because the failure is spectacular and silent until
23
+ * production.
24
+ *
25
+ * Both are built on `@react-pdf/renderer`, which is built on
26
+ * `pdfkit`, whose node build ends with:
27
+ *
28
+ * ```js
29
+ * const require$1 = createRequire(import.meta.url);
30
+ * registerStdFontLoaders({ Helvetica: () => require$1('#standard-fonts/Helvetica'), … });
31
+ * ```
32
+ *
33
+ * `#standard-fonts/*` is a package-`imports` entry **private to pdfkit**, and
34
+ * that is a RUNTIME call, not an import — so no bundler resolves it. Bundle
35
+ * pdfkit into an SSR server (`ssr.noExternal`) and the literal survives into the
36
+ * output, where `createRequire` is rooted at the build directory and the importer
37
+ * is no longer inside pdfkit. The server then throws on **every request**,
38
+ * `/health` included:
39
+ *
40
+ * ```
41
+ * error: Cannot find module '#standard-fonts/Helvetica' from '…/build/app.js'
42
+ * ```
43
+ *
44
+ * A compose healthcheck that fetches a route never goes healthy either, so the
45
+ * container looks like it is failing to start rather than failing to serve.
46
+ *
47
+ * This plugin rewrites those calls into static imports of
48
+ * `./standard-fonts/<name>.mjs`, so the font data lands in the bundle and the
49
+ * server stays self-contained. Use it when the runtime image has **no
50
+ * `node_modules`** — a single-file `bun build` artifact copied alone into the
51
+ * image. When the image does keep `node_modules`, the lighter answer is to leave
52
+ * the library external instead (`--external` it in the bundle step, and keep it
53
+ * out of `ssr.noExternal`), which also keeps ~12 MB of
54
+ * pdfkit out of the artifact. In Nuxt, `nxgtMaterial: { pdf: {
55
+ * bundleStandardFonts: true } }` adds this plugin to the Nitro build.
56
+ *
57
+ * ```ts
58
+ * // `@nxgt/material/vite` in a React app: the same function
59
+ * import { pdfkitStandardFonts } from '@nxgt/material-vue/vite';
60
+ * import { defineConfig } from 'vite';
61
+ *
62
+ * export default defineConfig({
63
+ * plugins: [pdfkitStandardFonts()],
64
+ * ssr: { noExternal: ['@nxgt/material-vue', '@nxgt/material-core'] },
65
+ * });
66
+ * ```
67
+ *
68
+ * Two things that look like fixes and are not:
69
+ *
70
+ * - **`resolve.alias`** mapping `#standard-fonts/` to `pdfkit/standard-fonts/`.
71
+ * An alias rewrites specifiers the resolver is *asked* about; this one is a
72
+ * string handed to `createRequire` at runtime, which the resolver never sees.
73
+ * - **`--external pdfkit`**. It is a transitive dependency, so the runtime cannot
74
+ * resolve it from the app's own directory: `Cannot find package 'pdfkit'`.
75
+ *
76
+ * The plugin throws if a `#standard-fonts/` reference survives the rewrite, so a
77
+ * future pdfkit that changes the shape of those calls fails the build instead of
78
+ * the first request.
79
+ */
80
+ export declare function pdfkitStandardFonts(): Plugin;
81
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vite/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgEG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CA6C5C"}
@@ -0,0 +1,31 @@
1
+ // src/vite/index.ts
2
+ function pdfkitStandardFonts() {
3
+ const CALL = /[A-Za-z_$][\w$]*\(\s*(['"])#standard-fonts\/(\w+)\1\s*\)/g;
4
+ return {
5
+ name: "nxgt-material:pdfkit-standard-fonts",
6
+ enforce: "pre",
7
+ transform(code, id) {
8
+ if (!id.includes("pdfkit") || !code.includes("#standard-fonts/")) {
9
+ return null;
10
+ }
11
+ const fonts = new Set;
12
+ const out = code.replace(CALL, (_match, _quote, font) => {
13
+ fonts.add(font);
14
+ return `__stdFont_${font}`;
15
+ });
16
+ if (out.includes("#standard-fonts/")) {
17
+ this.error(`${id} still references '#standard-fonts/' after the transform — ` + "pdfkit changed how it loads its standard fonts. See the doc " + "comment on pdfkitStandardFonts() in the /vite entry.");
18
+ }
19
+ const imports = [...fonts].map((font) => `import __stdFont_${font} from './standard-fonts/${font}.mjs';`).join(`
20
+ `);
21
+ return { code: `${imports}
22
+ ${out}`, map: null };
23
+ }
24
+ };
25
+ }
26
+ export {
27
+ pdfkitStandardFonts
28
+ };
29
+
30
+ //# debugId=03891F2267D73DE964756E2164756E21
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/vite/index.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * Build-time helpers for the apps that consume this library.\n *\n * This entry is the odd one out: everything else here runs in a browser or in\n * an SSR server, and the `/vite` entry is Node code that runs inside a\n * consumer's `vite.config.ts` (or a Nuxt app's Nitro build). It is here anyway\n * because the problem it solves is this package's to own — a consumer should\n * not have to rediscover it — and because there is exactly one copy of the fix\n * to maintain, shared by `@nxgt/material` and `@nxgt/material-vue`.\n *\n * It imports nothing at runtime: `Plugin` is a type, erased by the compiler, so\n * the built `dist/vite.js` has no dependency on `vite` at all.\n */\n\nimport type { Plugin } from 'vite';\n\n/**\n * Bundles pdfkit's fourteen standard fonts instead of leaving them to a\n * `require` that cannot work in a bundle.\n *\n * **Only needed by an app that renders PDFs** (`@nxgt/material/print`, or\n * `@nxgt/material-vue/pdf`). No other entry reaches `@react-pdf/renderer`, so\n * an app that does not print never sees this at all.\n * If you do print, read on, because the failure is spectacular and silent until\n * production.\n *\n * Both are built on `@react-pdf/renderer`, which is built on\n * `pdfkit`, whose node build ends with:\n *\n * ```js\n * const require$1 = createRequire(import.meta.url);\n * registerStdFontLoaders({ Helvetica: () => require$1('#standard-fonts/Helvetica'), … });\n * ```\n *\n * `#standard-fonts/*` is a package-`imports` entry **private to pdfkit**, and\n * that is a RUNTIME call, not an import — so no bundler resolves it. Bundle\n * pdfkit into an SSR server (`ssr.noExternal`) and the literal survives into the\n * output, where `createRequire` is rooted at the build directory and the importer\n * is no longer inside pdfkit. The server then throws on **every request**,\n * `/health` included:\n *\n * ```\n * error: Cannot find module '#standard-fonts/Helvetica' from '…/build/app.js'\n * ```\n *\n * A compose healthcheck that fetches a route never goes healthy either, so the\n * container looks like it is failing to start rather than failing to serve.\n *\n * This plugin rewrites those calls into static imports of\n * `./standard-fonts/<name>.mjs`, so the font data lands in the bundle and the\n * server stays self-contained. Use it when the runtime image has **no\n * `node_modules`** — a single-file `bun build` artifact copied alone into the\n * image. When the image does keep `node_modules`, the lighter answer is to leave\n * the library external instead (`--external` it in the bundle step, and keep it\n * out of `ssr.noExternal`), which also keeps ~12 MB of\n * pdfkit out of the artifact. In Nuxt, `nxgtMaterial: { pdf: {\n * bundleStandardFonts: true } }` adds this plugin to the Nitro build.\n *\n * ```ts\n * // `@nxgt/material/vite` in a React app: the same function\n * import { pdfkitStandardFonts } from '@nxgt/material-vue/vite';\n * import { defineConfig } from 'vite';\n *\n * export default defineConfig({\n * plugins: [pdfkitStandardFonts()],\n * ssr: { noExternal: ['@nxgt/material-vue', '@nxgt/material-core'] },\n * });\n * ```\n *\n * Two things that look like fixes and are not:\n *\n * - **`resolve.alias`** mapping `#standard-fonts/` to `pdfkit/standard-fonts/`.\n * An alias rewrites specifiers the resolver is *asked* about; this one is a\n * string handed to `createRequire` at runtime, which the resolver never sees.\n * - **`--external pdfkit`**. It is a transitive dependency, so the runtime cannot\n * resolve it from the app's own directory: `Cannot find package 'pdfkit'`.\n *\n * The plugin throws if a `#standard-fonts/` reference survives the rewrite, so a\n * future pdfkit that changes the shape of those calls fails the build instead of\n * the first request.\n */\nexport function pdfkitStandardFonts(): Plugin {\n\t/**\n\t * Any call whose only argument is that literal. Deliberately not pinned to\n\t * `require$1`, which is a name rollup generated for pdfkit's own build and is\n\t * free to change on any release — there is nothing else one can do with a\n\t * `#standard-fonts/*` specifier but require it.\n\t */\n\tconst CALL = /[A-Za-z_$][\\w$]*\\(\\s*(['\"])#standard-fonts\\/(\\w+)\\1\\s*\\)/g;\n\n\treturn {\n\t\tname: 'nxgt-material:pdfkit-standard-fonts',\n\t\tenforce: 'pre',\n\t\ttransform(code, id) {\n\t\t\tif (!id.includes('pdfkit') || !code.includes('#standard-fonts/')) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst fonts = new Set<string>();\n\t\t\tconst out = code.replace(CALL, (_match, _quote, font: string) => {\n\t\t\t\tfonts.add(font);\n\t\t\t\treturn `__stdFont_${font}`;\n\t\t\t});\n\n\t\t\t// Fail the build rather than ship a server that dies on its first\n\t\t\t// request: an unmatched occurrence means pdfkit changed the shape of\n\t\t\t// these calls, and the whole point of this plugin is that nothing\n\t\t\t// downstream notices the difference until runtime.\n\t\t\tif (out.includes('#standard-fonts/')) {\n\t\t\t\tthis.error(\n\t\t\t\t\t`${id} still references '#standard-fonts/' after the transform — ` +\n\t\t\t\t\t\t'pdfkit changed how it loads its standard fonts. See the doc ' +\n\t\t\t\t\t\t'comment on pdfkitStandardFonts() in the /vite entry.',\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst imports = [...fonts]\n\t\t\t\t.map(\n\t\t\t\t\t(font) =>\n\t\t\t\t\t\t`import __stdFont_${font} from './standard-fonts/${font}.mjs';`,\n\t\t\t\t)\n\t\t\t\t.join('\\n');\n\n\t\t\treturn { code: `${imports}\\n${out}`, map: null };\n\t\t},\n\t};\n}\n"
6
+ ],
7
+ "mappings": ";AAiFO,SAAS,mBAAmB,GAAW;AAAA,EAO7C,MAAM,OAAO;AAAA,EAEb,OAAO;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,IACT,SAAS,CAAC,MAAM,IAAI;AAAA,MACnB,IAAI,CAAC,GAAG,SAAS,QAAQ,KAAK,CAAC,KAAK,SAAS,kBAAkB,GAAG;AAAA,QACjE,OAAO;AAAA,MACR;AAAA,MAEA,MAAM,QAAQ,IAAI;AAAA,MAClB,MAAM,MAAM,KAAK,QAAQ,MAAM,CAAC,QAAQ,QAAQ,SAAiB;AAAA,QAChE,MAAM,IAAI,IAAI;AAAA,QACd,OAAO,aAAa;AAAA,OACpB;AAAA,MAMD,IAAI,IAAI,SAAS,kBAAkB,GAAG;AAAA,QACrC,KAAK,MACJ,GAAG,kEACF,iEACA,sDACF;AAAA,MACD;AAAA,MAEA,MAAM,UAAU,CAAC,GAAG,KAAK,EACvB,IACA,CAAC,SACA,oBAAoB,+BAA+B,YACrD,EACC,KAAK;AAAA,CAAI;AAAA,MAEX,OAAO,EAAE,MAAM,GAAG;AAAA,EAAY,OAAO,KAAK,KAAK;AAAA;AAAA,EAEjD;AAAA;",
8
+ "debugId": "03891F2267D73DE964756E2164756E21",
9
+ "names": []
10
+ }
package/docs/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # Documentation
2
+
3
+ `@nxgt/material-core`'s pages beyond the [README](../README.md), which has
4
+ one example per subpath.
5
+
6
+ | Page | Read it when |
7
+ | --- | --- |
8
+ | [Troubleshooting](troubleshooting.md) | an import, a render or a build fails with a message: the message is the heading |
9
+ | [Roadmap](roadmap.md) | you want to know what is coming, or whether something was already ruled out |
@@ -0,0 +1,35 @@
1
+ # Roadmap
2
+
3
+ Where `@nxgt/material-core` is going. A direction, not a commitment: the
4
+ version an item shipped in is the only number on this page.
5
+
6
+ ## Now
7
+
8
+ - **A first release, 0.1.0.** What `@nxgt/material` and `@nxgt/material-vue`
9
+ shared file by file — the PDF model and renderer, the print formatters, the
10
+ PDF file helpers, the PDF reader's framework-free modules (`/pdf-viewer`:
11
+ search, geometry, page sizes, scroll spy), the currency digits, the fields'
12
+ blur layers and the fonts plugin — is this one package, and both libraries
13
+ depend on it.
14
+
15
+ ## Next
16
+
17
+ - **What the two libraries still keep twice.** The upload constraints (once
18
+ their translation function no longer names each library's own message
19
+ keys), pdf.js's inlined note icons (they need an asset build core does not
20
+ have yet) and the `material.*` translation bundle, which still differs by
21
+ one prefix (`doc.callout.*`, React only).
22
+
23
+ ## Later
24
+
25
+ - **1.0**, once the model's `version: 1` is frozen: when another renderer
26
+ draws the same documents, as the React printing guide (`@nxgt/material`'s
27
+ `docs/guides/printing.md`) says.
28
+
29
+ ## Not planned
30
+
31
+ - **Components.** This package stays framework-free: React components are in
32
+ `@nxgt/material`, Vue ones in `@nxgt/material-vue`.
33
+ - **Test helpers.** Reading a rendered PDF back and the fake DOM the
34
+ libraries' tests use are the repository's own, in a private package that is
35
+ never published.
@@ -0,0 +1,105 @@
1
+ # Troubleshooting
2
+
3
+ Every heading is the message as it is printed; a name inside it (a node, a
4
+ file) is an example — search for the words around it.
5
+
6
+ **Install**
7
+
8
+ - [`Cannot find package '@react-pdf/renderer'`](#cannot-find-package-react-pdfrenderer)
9
+
10
+ **Rendering**
11
+
12
+ - [`[pdf] Unknown node type "chart".`](#pdf-unknown-node-type-chart)
13
+ - [`[pdf] No renderer for the custom node "signature": …`](#pdf-no-renderer-for-the-custom-node-signature-)
14
+ - [`[pdf] Unsupported document version 2: this version renders version 1.`](#pdf-unsupported-document-version-2-this-version-renders-version-1)
15
+
16
+ **PDF files**
17
+
18
+ - [`PdfReader cannot open …: pass a URL, a Blob, an ArrayBuffer, a Uint8Array or { url, httpHeaders }.`](#pdfreader-cannot-open--pass-a-url-a-blob-an-arraybuffer-a-uint8array-or--url-httpheaders-)
19
+
20
+ **Build**
21
+
22
+ - [`… still references '#standard-fonts/' after the transform — …`](#-still-references-standard-fonts-after-the-transform--)
23
+ - [`Cannot find module '#standard-fonts/Helvetica' from '…'`](#cannot-find-module-standard-fontshelvetica-from-)
24
+
25
+ ## Install
26
+
27
+ ### `Cannot find package '@react-pdf/renderer'`
28
+
29
+ **When:** importing `@nxgt/material-core/pdf` or `/pdf/render`, before any of
30
+ your code runs. Node prints `Cannot find package '@react-pdf/renderer'
31
+ imported from …`, Bun `Cannot find module '@react-pdf/renderer' from '…'`;
32
+ with the renderer installed and `react` missing, the name is `'react'`.
33
+ **Why:** `react` and `@react-pdf/renderer` are optional peers, so no install
34
+ adds them, and the renderer imports both statically. The other subpaths,
35
+ `/pdf/model` included, import neither.
36
+ **Fix:** install them where you render, or import only the model where you
37
+ build documents:
38
+
39
+ ```sh
40
+ bun add react @react-pdf/renderer@^4.9
41
+ ```
42
+
43
+ ```ts
44
+ import { pdfDocument, text } from '@nxgt/material-core/pdf/model'; // no peer needed
45
+ ```
46
+
47
+ ## Rendering
48
+
49
+ ### `[pdf] Unknown node type "chart".`
50
+
51
+ The renderer met a node whose `type` it does not know: a document built by a
52
+ newer version of the model, or a typo in hand-written JSON. Build documents
53
+ with the builders of `@nxgt/material-core/pdf/model` (or the libraries'
54
+ `/print` and `/pdf`), which only make known nodes, or use a `custom` node for
55
+ your own:
56
+
57
+ ```ts
58
+ import { pdfDocument } from '@nxgt/material-core/pdf/model';
59
+
60
+ pdfDocument({ pages: [{ body: [{ type: 'custom', name: 'chart', props: { id: 7 } }] }] });
61
+ ```
62
+
63
+ ### `[pdf] No renderer for the custom node "signature": …`
64
+
65
+ A `{ type: 'custom', name: 'signature' }` node was rendered without a
66
+ renderer of that name. Pass one in `custom` when rendering:
67
+
68
+ ```ts
69
+ renderPdfElement(doc, {
70
+ custom: { signature: (props, ctx) => /* react-pdf elements */ null },
71
+ });
72
+ ```
73
+
74
+ ### `[pdf] Unsupported document version 2: this version renders version 1.`
75
+
76
+ The document's `version` is not 1. Documents are versioned so that one sent
77
+ as JSON and rendered elsewhere is refused instead of mis-rendered; build it
78
+ with `pdfDocument()`, which sets the version this renderer reads.
79
+
80
+ ## PDF files
81
+
82
+ ### `PdfReader cannot open …: pass a URL, a Blob, an ArrayBuffer, a Uint8Array or { url, httpHeaders }.`
83
+
84
+ `toPdfjsSource` (behind both libraries' `PdfReader`) was given something that
85
+ is not a PDF source — often `undefined` from a query that has not answered
86
+ yet, or a `Response` instead of its bytes:
87
+
88
+ ```ts
89
+ const bytes = await (await fetch(url)).arrayBuffer(); // not the Response
90
+ ```
91
+
92
+ ## Build
93
+
94
+ ### `… still references '#standard-fonts/' after the transform — …`
95
+
96
+ `pdfkitStandardFonts()` found a `#standard-fonts/` reference it could not
97
+ rewrite: pdfkit changed how it loads its fonts. The build fails on purpose,
98
+ rather than the server at its first request. Pin the previous
99
+ `@react-pdf/renderer` (and so pdfkit) and open an issue.
100
+
101
+ ### `Cannot find module '#standard-fonts/Helvetica' from '…'`
102
+
103
+ A server bundle that contains pdfkit, run without `node_modules`. Add
104
+ `pdfkitStandardFonts()` to that build (see the README's `/vite` section), or
105
+ keep the library external so pdfkit loads from `node_modules`.
package/package.json ADDED
@@ -0,0 +1,187 @@
1
+ {
2
+ "name": "@nxgt/material-core",
3
+ "version": "0.1.0",
4
+ "description": "The framework-free core of @nxgt/material and @nxgt/material-vue: the PDF document model and its react-pdf renderer, print formatters, PDF file helpers, the PDF viewer's pure modules, the currency digits, the field-blur layers and the pdfkit fonts Vite plugin",
5
+ "license": "MIT",
6
+ "bugs": {
7
+ "email": "stevegires@gmail.com"
8
+ },
9
+ "type": "module",
10
+ "main": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "files": [
13
+ "dist",
14
+ "docs",
15
+ "README.md",
16
+ "package.json",
17
+ "LICENSE"
18
+ ],
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js",
23
+ "default": "./dist/index.js"
24
+ },
25
+ "./pdf": {
26
+ "types": "./dist/pdf/index.d.ts",
27
+ "import": "./dist/pdf/index.js",
28
+ "default": "./dist/pdf/index.js"
29
+ },
30
+ "./pdf/model": {
31
+ "types": "./dist/pdf/model/index.d.ts",
32
+ "import": "./dist/pdf/model/index.js",
33
+ "default": "./dist/pdf/model/index.js"
34
+ },
35
+ "./pdf/render": {
36
+ "types": "./dist/pdf/render/index.d.ts",
37
+ "import": "./dist/pdf/render/index.js",
38
+ "default": "./dist/pdf/render/index.js"
39
+ },
40
+ "./pdf/http": {
41
+ "types": "./dist/pdf/http.d.ts",
42
+ "import": "./dist/pdf/http.js",
43
+ "default": "./dist/pdf/http.js"
44
+ },
45
+ "./pdf/file-loader": {
46
+ "types": "./dist/pdf/file-loader.d.ts",
47
+ "import": "./dist/pdf/file-loader.js",
48
+ "default": "./dist/pdf/file-loader.js"
49
+ },
50
+ "./print-format": {
51
+ "types": "./dist/lib/print-format.utils.d.ts",
52
+ "import": "./dist/lib/print-format.utils.js",
53
+ "default": "./dist/lib/print-format.utils.js"
54
+ },
55
+ "./print-fraction-digits": {
56
+ "types": "./dist/lib/print-fraction-digits.d.ts",
57
+ "import": "./dist/lib/print-fraction-digits.js",
58
+ "default": "./dist/lib/print-fraction-digits.js"
59
+ },
60
+ "./print-value": {
61
+ "types": "./dist/lib/print-value.utils.d.ts",
62
+ "import": "./dist/lib/print-value.utils.js",
63
+ "default": "./dist/lib/print-value.utils.js"
64
+ },
65
+ "./print-table": {
66
+ "types": "./dist/lib/print-table.utils.d.ts",
67
+ "import": "./dist/lib/print-table.utils.js",
68
+ "default": "./dist/lib/print-table.utils.js"
69
+ },
70
+ "./pdf-source": {
71
+ "types": "./dist/lib/pdf-source.d.ts",
72
+ "import": "./dist/lib/pdf-source.js",
73
+ "default": "./dist/lib/pdf-source.js"
74
+ },
75
+ "./pdf-file-name": {
76
+ "types": "./dist/lib/pdf-file-name.d.ts",
77
+ "import": "./dist/lib/pdf-file-name.js",
78
+ "default": "./dist/lib/pdf-file-name.js"
79
+ },
80
+ "./pdf-download": {
81
+ "types": "./dist/lib/pdf-download.d.ts",
82
+ "import": "./dist/lib/pdf-download.js",
83
+ "default": "./dist/lib/pdf-download.js"
84
+ },
85
+ "./currency-digits": {
86
+ "types": "./dist/lib/currency-digits.d.ts",
87
+ "import": "./dist/lib/currency-digits.js",
88
+ "default": "./dist/lib/currency-digits.js"
89
+ },
90
+ "./field-blur-layers": {
91
+ "types": "./dist/lib/field-blur-layers.d.ts",
92
+ "import": "./dist/lib/field-blur-layers.js",
93
+ "default": "./dist/lib/field-blur-layers.js"
94
+ },
95
+ "./pdf-viewer": {
96
+ "types": "./dist/pdf-viewer/index.d.ts",
97
+ "import": "./dist/pdf-viewer/index.js",
98
+ "default": "./dist/pdf-viewer/index.js"
99
+ },
100
+ "./vite": {
101
+ "types": "./dist/vite/index.d.ts",
102
+ "import": "./dist/vite/index.js",
103
+ "default": "./dist/vite/index.js"
104
+ },
105
+ "./package.json": "./package.json"
106
+ },
107
+ "sideEffects": false,
108
+ "keywords": [
109
+ "pdf",
110
+ "react-pdf",
111
+ "print",
112
+ "pdf-viewer",
113
+ "formatting",
114
+ "vite-plugin",
115
+ "framework-agnostic",
116
+ "typescript"
117
+ ],
118
+ "repository": {
119
+ "type": "git",
120
+ "url": "git+https://github.com/softistx/nxgt-material.git",
121
+ "directory": "packages/core"
122
+ },
123
+ "publishConfig": {
124
+ "registry": "https://registry.npmjs.org",
125
+ "access": "public"
126
+ },
127
+ "scripts": {
128
+ "build": "bun run ../../build.ts",
129
+ "postbuild": "bun run verify:ssr && bun run verify:dts",
130
+ "prepack": "bun run verify:dts",
131
+ "test": "vitest run",
132
+ "test:scripts": "bun test ./scripts/",
133
+ "typecheck": "tsc --noEmit",
134
+ "verify:ssr": "bun scripts/verify-ssr-safe.ts",
135
+ "verify:dts": "bun scripts/verify-dts.ts"
136
+ },
137
+ "nxgt": {
138
+ "entrypoints": [
139
+ "src/index.ts",
140
+ "src/pdf/index.ts",
141
+ "src/pdf/model/index.ts",
142
+ "src/pdf/render/index.ts",
143
+ "src/pdf/http.ts",
144
+ "src/pdf/file-loader.ts",
145
+ "src/lib/print-format.utils.ts",
146
+ "src/lib/print-fraction-digits.ts",
147
+ "src/lib/print-value.utils.ts",
148
+ "src/lib/print-table.utils.ts",
149
+ "src/lib/pdf-source.ts",
150
+ "src/lib/pdf-file-name.ts",
151
+ "src/lib/pdf-download.ts",
152
+ "src/lib/currency-digits.ts",
153
+ "src/lib/field-blur-layers.ts",
154
+ "src/pdf-viewer/index.ts",
155
+ "src/vite/index.ts"
156
+ ]
157
+ },
158
+ "dependencies": {
159
+ "intl-messageformat": "^11.2.14"
160
+ },
161
+ "devDependencies": {
162
+ "@nxgt/material-testing": "0.0.0",
163
+ "@react-pdf/renderer": "^4.9.0",
164
+ "@types/bun": "^1.4.2",
165
+ "@types/react": "^19.2.17",
166
+ "react": "^19.2.8",
167
+ "typescript": "~6.0.3",
168
+ "vite": "8.1.5",
169
+ "vitest": "^4.1.10"
170
+ },
171
+ "peerDependencies": {
172
+ "@react-pdf/renderer": "^4.9.0",
173
+ "react": "^18.2.0 || ^19.0.0",
174
+ "vite": "^6.0.0 || ^7.0.0 || ^8.0.0"
175
+ },
176
+ "peerDependenciesMeta": {
177
+ "@react-pdf/renderer": {
178
+ "optional": true
179
+ },
180
+ "react": {
181
+ "optional": true
182
+ },
183
+ "vite": {
184
+ "optional": true
185
+ }
186
+ }
187
+ }