@rentnerkev/pdf 1.0.0 → 1.0.2

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 (195) hide show
  1. package/README.md +23 -7
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/dist/ai.d.ts +53 -0
  4. package/dist/ai.d.ts.map +1 -0
  5. package/dist/ai.js +144 -0
  6. package/dist/ai.js.map +1 -0
  7. package/dist/components/Types/props.d.ts +2 -2
  8. package/dist/components/components.d.ts +5 -5
  9. package/dist/components/components.d.ts.map +1 -1
  10. package/dist/components/components.js +16 -16
  11. package/dist/components/components.js.map +1 -1
  12. package/dist/components/host.d.ts +2 -2
  13. package/dist/engine/Types/backend.d.ts +5 -5
  14. package/dist/engine/Types/engine.d.ts +8 -8
  15. package/dist/engine/Types/errors.d.ts +2 -2
  16. package/dist/engine/Types/render-options.d.ts +1 -1
  17. package/dist/engine/Types/render-result.d.ts +1 -1
  18. package/dist/engine/abort.d.ts +2 -2
  19. package/dist/engine/abort.d.ts.map +1 -1
  20. package/dist/engine/abort.js +2 -2
  21. package/dist/engine/abort.js.map +1 -1
  22. package/dist/engine/assets.d.ts +4 -3
  23. package/dist/engine/assets.d.ts.map +1 -1
  24. package/dist/engine/assets.js +19 -11
  25. package/dist/engine/assets.js.map +1 -1
  26. package/dist/engine/backend.d.ts +5 -5
  27. package/dist/engine/backend.d.ts.map +1 -1
  28. package/dist/engine/backend.js +12 -9
  29. package/dist/engine/backend.js.map +1 -1
  30. package/dist/engine/backends/native.d.ts +2 -2
  31. package/dist/engine/backends/wasm.d.ts +2 -2
  32. package/dist/engine/backends/wasm.d.ts.map +1 -1
  33. package/dist/engine/backends/wasm.js +12 -4
  34. package/dist/engine/backends/wasm.js.map +1 -1
  35. package/dist/engine/channel.d.ts +5 -8
  36. package/dist/engine/channel.d.ts.map +1 -1
  37. package/dist/engine/channel.js +71 -43
  38. package/dist/engine/channel.js.map +1 -1
  39. package/dist/engine/create-engine.d.ts +1 -1
  40. package/dist/engine/create-engine.d.ts.map +1 -1
  41. package/dist/engine/create-engine.js +11 -5
  42. package/dist/engine/create-engine.js.map +1 -1
  43. package/dist/engine/default-fonts.d.ts.map +1 -1
  44. package/dist/engine/default-fonts.js +24 -17
  45. package/dist/engine/default-fonts.js.map +1 -1
  46. package/dist/engine/encode.d.ts +5 -4
  47. package/dist/engine/encode.d.ts.map +1 -1
  48. package/dist/engine/encode.js +15 -10
  49. package/dist/engine/encode.js.map +1 -1
  50. package/dist/engine/errors.d.ts +3 -3
  51. package/dist/engine/fonts.d.ts +1 -1
  52. package/dist/engine/markup.d.ts +3 -3
  53. package/dist/engine/options.d.ts +2 -2
  54. package/dist/engine/prepare.d.ts +4 -4
  55. package/dist/engine/render-many.d.ts +3 -3
  56. package/dist/engine/render-result.d.ts +9 -3
  57. package/dist/engine/render-result.d.ts.map +1 -1
  58. package/dist/engine/render-result.js +8 -1
  59. package/dist/engine/render-result.js.map +1 -1
  60. package/dist/engine/render-stream.d.ts +1 -1
  61. package/dist/engine/render.d.ts +3 -3
  62. package/dist/index.d.ts +24 -24
  63. package/dist/ir/Types/input.d.ts +1 -1
  64. package/dist/ir/factories.d.ts +3 -3
  65. package/dist/ir/factories.d.ts.map +1 -1
  66. package/dist/ir/factories.js +8 -3
  67. package/dist/ir/factories.js.map +1 -1
  68. package/dist/ir/page-variants.d.ts +3 -0
  69. package/dist/ir/page-variants.d.ts.map +1 -0
  70. package/dist/ir/page-variants.js +3 -0
  71. package/dist/ir/page-variants.js.map +1 -0
  72. package/dist/jsx/Types/context.d.ts +1 -1
  73. package/dist/jsx/Types/evaluate.d.ts +4 -4
  74. package/dist/jsx/Types/jsx.d.ts +1 -1
  75. package/dist/jsx/context.d.ts +1 -1
  76. package/dist/jsx/element.d.ts +1 -1
  77. package/dist/jsx/evaluate.d.ts +3 -3
  78. package/dist/jsx/evaluate.d.ts.map +1 -1
  79. package/dist/jsx/evaluate.js +20 -52
  80. package/dist/jsx/evaluate.js.map +1 -1
  81. package/dist/jsx/source.d.ts +1 -1
  82. package/dist/jsx-dev-runtime.d.ts +3 -3
  83. package/dist/jsx-runtime.d.ts +3 -3
  84. package/dist/native/loader.d.ts.map +1 -1
  85. package/dist/native/loader.js +33 -27
  86. package/dist/native/loader.js.map +1 -1
  87. package/dist/native/rentnerpdf.linux-arm64-gnu.node +0 -0
  88. package/dist/native/rentnerpdf.linux-arm64-musl.node +0 -0
  89. package/dist/native/rentnerpdf.linux-x64-gnu.node +0 -0
  90. package/dist/native/rentnerpdf.linux-x64-musl.node +0 -0
  91. package/dist/native/rentnerpdf.win32-arm64-msvc.node +0 -0
  92. package/dist/native/rentnerpdf.win32-x64-msvc.node +0 -0
  93. package/dist/node.d.ts +2 -2
  94. package/dist/react/Types/preview.d.ts +16 -11
  95. package/dist/react/Types/preview.d.ts.map +1 -1
  96. package/dist/react/Types/preview.js.map +1 -1
  97. package/dist/react/Types/render.d.ts +1 -1
  98. package/dist/react/components.d.ts +4 -4
  99. package/dist/react/components.d.ts.map +1 -1
  100. package/dist/react/components.js +23 -23
  101. package/dist/react/components.js.map +1 -1
  102. package/dist/react/pdf-preview.d.ts +3 -2
  103. package/dist/react/pdf-preview.d.ts.map +1 -1
  104. package/dist/react/pdf-preview.js +2 -1
  105. package/dist/react/pdf-preview.js.map +1 -1
  106. package/dist/react/pdf-render.d.ts +4 -4
  107. package/dist/react/pdf-render.d.ts.map +1 -1
  108. package/dist/react/pdf-render.js +20 -12
  109. package/dist/react/pdf-render.js.map +1 -1
  110. package/dist/react/registry.d.ts +3 -3
  111. package/dist/react/registry.d.ts.map +1 -1
  112. package/dist/react/registry.js +6 -3
  113. package/dist/react/registry.js.map +1 -1
  114. package/dist/react/render.d.ts +4 -4
  115. package/dist/react/render.d.ts.map +1 -1
  116. package/dist/react/render.js +36 -54
  117. package/dist/react/render.js.map +1 -1
  118. package/dist/react/same-document.d.ts +2 -1
  119. package/dist/react/same-document.d.ts.map +1 -1
  120. package/dist/react/same-document.js +7 -1
  121. package/dist/react/same-document.js.map +1 -1
  122. package/dist/react/static.d.ts +5 -0
  123. package/dist/react/static.d.ts.map +1 -1
  124. package/dist/react/static.js +20 -16
  125. package/dist/react/static.js.map +1 -1
  126. package/dist/react/use-pdf.d.ts +5 -5
  127. package/dist/react/use-pdf.d.ts.map +1 -1
  128. package/dist/react/use-pdf.js +81 -14
  129. package/dist/react/use-pdf.js.map +1 -1
  130. package/dist/react.d.ts +8 -8
  131. package/dist/tailwind-merge.d.ts +2 -2
  132. package/dist/theme/Types/theme.d.ts +8 -1
  133. package/dist/theme/Types/theme.d.ts.map +1 -1
  134. package/dist/theme/Types/theme.js.map +1 -1
  135. package/dist/theme/css-imports.d.ts +1 -1
  136. package/dist/theme/normalize.d.ts +2 -2
  137. package/dist/theme/package-imports.d.ts +1 -8
  138. package/dist/theme/package-imports.d.ts.map +1 -1
  139. package/dist/theme/package-imports.js +4 -11
  140. package/dist/theme/package-imports.js.map +1 -1
  141. package/dist/theme/paths.d.ts +6 -0
  142. package/dist/theme/paths.d.ts.map +1 -0
  143. package/dist/theme/paths.js +13 -0
  144. package/dist/theme/paths.js.map +1 -0
  145. package/dist/theme/theme-from-css-file.d.ts +1 -3
  146. package/dist/theme/theme-from-css-file.d.ts.map +1 -1
  147. package/dist/theme/theme-from-css-file.js +16 -21
  148. package/dist/theme/theme-from-css-file.js.map +1 -1
  149. package/dist/theme/theme-from-css.d.ts +1 -1
  150. package/dist/theme/warnings.d.ts +1 -4
  151. package/dist/theme/warnings.d.ts.map +1 -1
  152. package/dist/theme/warnings.js +1 -1
  153. package/dist/theme/warnings.js.map +1 -1
  154. package/dist/vite/plugin.d.ts +3 -6
  155. package/dist/vite/plugin.d.ts.map +1 -1
  156. package/dist/vite/plugin.js +17 -7
  157. package/dist/vite/plugin.js.map +1 -1
  158. package/dist/vite.d.ts +2 -2
  159. package/dist/wasm/binding.generated.d.ts +19 -14
  160. package/dist/wasm/loader.d.ts.map +1 -1
  161. package/dist/wasm/loader.js +11 -3
  162. package/dist/wasm/loader.js.map +1 -1
  163. package/dist/wasm/node-path.d.ts +3 -0
  164. package/dist/wasm/node-path.d.ts.map +1 -0
  165. package/dist/wasm/node-path.js +4 -0
  166. package/dist/wasm/node-path.js.map +1 -0
  167. package/dist/wasm/pkg/rentnerpdf_wasm.d.ts +19 -14
  168. package/dist/wasm/pkg/rentnerpdf_wasm.js +39 -75
  169. package/dist/wasm/pkg/rentnerpdf_wasm_bg.wasm +0 -0
  170. package/dist/wasm/pkg/rentnerpdf_wasm_bg.wasm.d.ts +8 -7
  171. package/dist/worker/Types/connection.d.ts +1 -1
  172. package/dist/worker/Types/protocol.d.ts +2 -2
  173. package/dist/worker/Types/worker-engine.d.ts +3 -3
  174. package/dist/worker/client.d.ts +1 -1
  175. package/dist/worker/client.d.ts.map +1 -1
  176. package/dist/worker/client.js +10 -10
  177. package/dist/worker/client.js.map +1 -1
  178. package/dist/worker/connection.d.ts +2 -2
  179. package/dist/worker/protocol.d.ts +2 -2
  180. package/dist/worker/protocol.js.map +1 -1
  181. package/dist/worker/serve.d.ts +3 -5
  182. package/dist/worker/serve.d.ts.map +1 -1
  183. package/dist/worker/serve.js +1 -1
  184. package/dist/worker/serve.js.map +1 -1
  185. package/dist/worker.d.ts +3 -3
  186. package/docs/usage.md +1606 -0
  187. package/package.json +9 -1
  188. package/dist/engine/pdf-bytes.d.ts +0 -8
  189. package/dist/engine/pdf-bytes.d.ts.map +0 -1
  190. package/dist/engine/pdf-bytes.js +0 -9
  191. package/dist/engine/pdf-bytes.js.map +0 -1
  192. package/dist/theme/Types/warnings.d.ts +0 -9
  193. package/dist/theme/Types/warnings.d.ts.map +0 -1
  194. package/dist/theme/Types/warnings.js +0 -2
  195. package/dist/theme/Types/warnings.js.map +0 -1
@@ -1,3 +1,3 @@
1
- export { isLineCount, rentnerPdfMergeConfig } from './tailwind/merge-config.ts';
2
- export type { ClassDefinition, ClassValidator, RentnerPdfClassGroupId, RentnerPdfMergeConfig, } from './tailwind/Types/merge-config.ts';
1
+ export { isLineCount, rentnerPdfMergeConfig } from './tailwind/merge-config.js';
2
+ export type { ClassDefinition, ClassValidator, RentnerPdfClassGroupId, RentnerPdfMergeConfig, } from './tailwind/Types/merge-config.js';
3
3
  //# sourceMappingURL=tailwind-merge.d.ts.map
@@ -1,4 +1,11 @@
1
- import type { RenderWarning } from '../../engine/Types/render-result.ts';
1
+ import type { RenderWarning } from '../../engine/Types/render-result.js';
2
+ /** The warnings of one theme, bounded. */
3
+ export interface ThemeWarningList {
4
+ /** Adds an `INVALID_THEME` warning, or counts it once the list is full. */
5
+ readonly add: (message: string, path: string | undefined) => void;
6
+ /** The warnings, followed by a summary of the ones that did not fit. */
7
+ readonly list: () => readonly RenderWarning[];
8
+ }
2
9
  /** One app stylesheet of a {@link Theme}. */
3
10
  export interface ThemeStylesheet {
4
11
  /** The CSS text; the engine reads `@theme`, `:root` and scope rules. */
@@ -1 +1 @@
1
- {"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../../web/src/theme/Types/theme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AAExE,6CAA6C;AAC7C,MAAM,WAAW,eAAe;IAC5B,wEAAwE;IACxE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;IAClC,6EAA6E;IAC7E,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAC3B;AAED;;;;GAIG;AACH,MAAM,WAAW,KAAK;IAClB,gDAAgD;IAChD,QAAQ,CAAC,WAAW,EAAE,SAAS,eAAe,EAAE,CAAA;IAChD;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,SAAS,aAAa,EAAE,CAAA;CAC9C;AAED;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC,KAAK,MAAM,EA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,MAAM,GAAG,SAAS,CAAA;CAC5C"}
@@ -1 +1 @@
1
- {"version":3,"file":"theme.js","sourceRoot":"","sources":["../../../web/src/theme/Types/theme.ts"],"names":[],"mappings":"","sourcesContent":["import type { RenderWarning } from '../../engine/Types/render-result.ts'\n\n/** One app stylesheet of a {@link Theme}. */\nexport interface ThemeStylesheet {\n /** The CSS text; the engine reads `@theme`, `:root` and scope rules. */\n readonly css: string\n /**\n * Selectors whose custom properties override `:root` ones, for example\n * `.rentner-pdf`: an app keeps dark web tokens on `:root` and paper\n * tokens for PDFs in one stylesheet.\n */\n readonly scopes: readonly string[]\n /** Where the CSS came from, such as a file path; warnings use it as path. */\n readonly source?: string\n}\n\n/**\n * App CSS as the source of design tokens (D-22), from `themeFromCss()` or\n * `themeFromCssFile()` (`@rentnerkev/pdf/node`). Pass it to\n * `createEngine({ theme })`. Plain, serializable data.\n */\nexport interface Theme {\n /** The stylesheets in order; later ones win. */\n readonly stylesheets: readonly ThemeStylesheet[]\n /**\n * `INVALID_THEME` warnings found while collecting the stylesheets, such\n * as an import that was not followed. The engine adds the problems it\n * finds in the CSS itself (`Engine.themeWarnings`).\n */\n readonly warnings: readonly RenderWarning[]\n}\n\n/**\n * JS overrides: custom properties applied after every stylesheet, like a\n * final `@theme` block that also beats `:root` and scope tokens.\n * `'initial'` removes a variable, `'--color-*': 'initial'` a namespace.\n */\nexport type ThemeVariables = Readonly<Record<`--${string}`, string | number>>\n\n/**\n * `EngineOptions.theme`: a theme, JS overrides or a list of both. Every\n * stylesheet applies before every override, in list order.\n */\nexport type ThemeInput =\n Theme | ThemeVariables | readonly (Theme | ThemeVariables)[]\n\nexport interface ThemeFromCssOptions {\n /**\n * Selectors whose custom properties override `:root` ones. Defaults to\n * `['.rentner-pdf']`; `[]` reads `@theme` and `:root` only.\n */\n readonly scopes?: readonly string[]\n /** A name for the CSS in warnings, such as its file path. */\n readonly source?: string\n}\n\nexport interface ThemeFromCssFileOptions {\n /**\n * Selectors whose custom properties override `:root` ones, in every\n * file. Defaults to `['.rentner-pdf']`.\n */\n readonly scopes?: readonly string[]\n /**\n * The directory relative `@import`s must stay in. Defaults to the\n * directory of the entry file; files of `@rentnerkev/*` packages stay\n * in their package.\n */\n readonly root?: string\n}\n\n/** A theme as both backends receive it. */\nexport interface BackendTheme {\n readonly stylesheets: readonly ThemeStylesheet[]\n readonly variables: readonly (readonly [name: string, value: string])[]\n /** Root font size in CSS pixels; `undefined` keeps 16. */\n readonly rootFontSize: number | undefined\n}\n"]}
1
+ {"version":3,"file":"theme.js","sourceRoot":"","sources":["../../../web/src/theme/Types/theme.ts"],"names":[],"mappings":"","sourcesContent":["import type { RenderWarning } from '../../engine/Types/render-result.ts'\n\n/** The warnings of one theme, bounded. */\nexport interface ThemeWarningList {\n /** Adds an `INVALID_THEME` warning, or counts it once the list is full. */\n readonly add: (message: string, path: string | undefined) => void\n /** The warnings, followed by a summary of the ones that did not fit. */\n readonly list: () => readonly RenderWarning[]\n}\n\n/** One app stylesheet of a {@link Theme}. */\nexport interface ThemeStylesheet {\n /** The CSS text; the engine reads `@theme`, `:root` and scope rules. */\n readonly css: string\n /**\n * Selectors whose custom properties override `:root` ones, for example\n * `.rentner-pdf`: an app keeps dark web tokens on `:root` and paper\n * tokens for PDFs in one stylesheet.\n */\n readonly scopes: readonly string[]\n /** Where the CSS came from, such as a file path; warnings use it as path. */\n readonly source?: string\n}\n\n/**\n * App CSS as the source of design tokens (D-22), from `themeFromCss()` or\n * `themeFromCssFile()` (`@rentnerkev/pdf/node`). Pass it to\n * `createEngine({ theme })`. Plain, serializable data.\n */\nexport interface Theme {\n /** The stylesheets in order; later ones win. */\n readonly stylesheets: readonly ThemeStylesheet[]\n /**\n * `INVALID_THEME` warnings found while collecting the stylesheets, such\n * as an import that was not followed. The engine adds the problems it\n * finds in the CSS itself (`Engine.themeWarnings`).\n */\n readonly warnings: readonly RenderWarning[]\n}\n\n/**\n * JS overrides: custom properties applied after every stylesheet, like a\n * final `@theme` block that also beats `:root` and scope tokens.\n * `'initial'` removes a variable, `'--color-*': 'initial'` a namespace.\n */\nexport type ThemeVariables = Readonly<Record<`--${string}`, string | number>>\n\n/**\n * `EngineOptions.theme`: a theme, JS overrides or a list of both. Every\n * stylesheet applies before every override, in list order.\n */\nexport type ThemeInput =\n Theme | ThemeVariables | readonly (Theme | ThemeVariables)[]\n\nexport interface ThemeFromCssOptions {\n /**\n * Selectors whose custom properties override `:root` ones. Defaults to\n * `['.rentner-pdf']`; `[]` reads `@theme` and `:root` only.\n */\n readonly scopes?: readonly string[]\n /** A name for the CSS in warnings, such as its file path. */\n readonly source?: string\n}\n\nexport interface ThemeFromCssFileOptions {\n /**\n * Selectors whose custom properties override `:root` ones, in every\n * file. Defaults to `['.rentner-pdf']`.\n */\n readonly scopes?: readonly string[]\n /**\n * The directory relative `@import`s must stay in. Defaults to the\n * directory of the entry file; files of `@rentnerkev/*` packages stay\n * in their package.\n */\n readonly root?: string\n}\n\n/** A theme as both backends receive it. */\nexport interface BackendTheme {\n readonly stylesheets: readonly ThemeStylesheet[]\n readonly variables: readonly (readonly [name: string, value: string])[]\n /** Root font size in CSS pixels; `undefined` keeps 16. */\n readonly rootFontSize: number | undefined\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { CssImport, ImportKind } from './Types/css-imports.ts';
1
+ import type { CssImport, ImportKind } from './Types/css-imports.js';
2
2
  /**
3
3
  * The top-level `@import` statements of a stylesheet, in order. Comments,
4
4
  * strings and blocks are skipped; nothing is fetched.
@@ -1,5 +1,5 @@
1
- import type { RenderWarning } from '../engine/Types/render-result.ts';
2
- import type { BackendTheme, ThemeInput } from './Types/theme.ts';
1
+ import type { RenderWarning } from '../engine/Types/render-result.js';
2
+ import type { BackendTheme, ThemeInput } from './Types/theme.js';
3
3
  /** `EngineOptions.theme` and `rootFontSize` as the backends receive them. */
4
4
  export interface NormalizedTheme {
5
5
  /** `undefined` when the built-in theme applies unchanged. */
@@ -1,11 +1,4 @@
1
- import type { PackageImport, ResolvedImport } from './Types/css-imports.ts';
2
- /**
3
- * The package and file of an `@rentnerkev/*` import; `undefined` for
4
- * specifiers with empty, `.` or `..` segments or backslashes, which could
5
- * leave the package (Node's resolver normalizes them against
6
- * `node_modules`).
7
- */
8
- export declare function parsePackageImport(specifier: string): PackageImport | undefined;
1
+ import type { ResolvedImport } from './Types/css-imports.js';
9
2
  /**
10
3
  * Resolves an `@rentnerkev/*` CSS import like Node from the importing file
11
4
  * and confines it to that package: the resolved real path must be a `.css`
@@ -1 +1 @@
1
- {"version":3,"file":"package-imports.d.ts","sourceRoot":"","sources":["../../web/src/theme/package-imports.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAsB3E;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAC9B,SAAS,EAAE,MAAM,GAClB,aAAa,GAAG,SAAS,CAgB3B;AAgBD;;;;;GAKG;AACH,wBAAsB,oBAAoB,CACtC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACjB,OAAO,CAAC,cAAc,GAAG,MAAM,CAAC,CA4BlC"}
1
+ {"version":3,"file":"package-imports.d.ts","sourceRoot":"","sources":["../../web/src/theme/package-imports.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAiB,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAiD3E;;;;;GAKG;AACH,wBAAsB,oBAAoB,CACtC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACjB,OAAO,CAAC,cAAc,GAAG,MAAM,CAAC,CA4BlC"}
@@ -1,27 +1,20 @@
1
1
  import { readFile, realpath } from 'node:fs/promises';
2
2
  import { createRequire } from 'node:module';
3
- import { dirname, join, relative, isAbsolute } from 'node:path';
3
+ import { dirname, join } from 'node:path';
4
+ import { isInside } from './paths.js';
4
5
  /** `@rentnerkev/<name>/<path>`; the name as npm allows it. */
5
6
  const PACKAGE_SPECIFIER = /^@rentnerkev\/([a-z0-9][a-z0-9._-]*)\/(.+)$/i;
6
7
  /** How far up from an imported file its `package.json` may be. */
7
8
  const MAX_PACKAGE_LEVELS = 8;
8
9
  /** Bytes of a `package.json` that are read to check its name. */
9
10
  const MAX_MANIFEST_BYTES = 256 * 1024;
10
- const isInside = (directory, path) => {
11
- const local = relative(directory, path);
12
- return (local === '' ||
13
- (local !== '..' &&
14
- !local.startsWith('..\\') &&
15
- !local.startsWith('../') &&
16
- !isAbsolute(local)));
17
- };
18
11
  /**
19
12
  * The package and file of an `@rentnerkev/*` import; `undefined` for
20
13
  * specifiers with empty, `.` or `..` segments or backslashes, which could
21
14
  * leave the package (Node's resolver normalizes them against
22
15
  * `node_modules`).
23
16
  */
24
- export function parsePackageImport(specifier) {
17
+ function parsePackageImport(specifier) {
25
18
  const match = PACKAGE_SPECIFIER.exec(specifier);
26
19
  const name = match?.[1];
27
20
  const path = match?.[2];
@@ -76,7 +69,7 @@ export async function resolvePackageImport(specifier, importer) {
76
69
  // oxlint-disable-next-line no-await-in-loop -- each level is checked only when the one below has no matching package.json
77
70
  const name = await manifestName(directory);
78
71
  if (name !== undefined) {
79
- return name === parsed.name && isInside(directory, file)
72
+ return name === parsed.name && isInside(directory, file, 'portable')
80
73
  ? { file, root: directory }
81
74
  : `it resolves outside the package ${parsed.name}`;
82
75
  }
@@ -1 +1 @@
1
- {"version":3,"file":"package-imports.js","sourceRoot":"","sources":["../../web/src/theme/package-imports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAG/D,8DAA8D;AAC9D,MAAM,iBAAiB,GAAG,8CAA8C,CAAA;AAExE,kEAAkE;AAClE,MAAM,kBAAkB,GAAG,CAAC,CAAA;AAE5B,iEAAiE;A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OAAO,CAAC,IAAI,CAAC,CAAA;IAC7B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,kBAAkB,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACzD,0HAA0H;QAC1H,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,SAAS,CAAC,CAAA;QAC1C,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACrB,OAAO,IAAI,KAAK,MAAM,CAAC,IAAI,IAAI,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;gBACpD,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE;gBAC3B,CAAC,CAAC,mCAAmC,MAAM,CAAC,IAAI,EAAE,CAAA;QAC1D,CAAC;QACD,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;QACjC,IAAI,MAAM,KAAK,SAAS;YAAE,MAAK;QAC/B,SAAS,GAAG,MAAM,CAAA;IACtB,CAAC;IACD,OAAO,mCAAmC,MAAM,CAAC,IAAI,EAAE,CAAA;AAC3D,CAAC","sourcesContent":["import { readFile, realpath } from 'node:fs/promises'\nimport { createRequire } from 'node:module'\nimport { dirname, join, relative, isAbsolute } from 'node:path'\nimport type { PackageImport, ResolvedImport } from './Types/css-imports.ts'\n\n/** `@rentnerkev/<name>/<path>`; the name as npm allows it. */\nconst PACKAGE_SPECIFIER = /^@rentnerkev\\/([a-z0-9][a-z0-9._-]*)\\/(.+)$/i\n\n/** How far up from an imported file its `package.json` may be. */\nconst MAX_PACKAGE_LEVELS = 8\n\n/** Bytes of a `package.json` that are read to check its name. */\nconst MAX_MANIFEST_BYTES = 256 * 1024\n\nconst isInside = (directory: string, path: string): boolean => {\n const local = relative(directory, path)\n return (\n local === '' ||\n (local !== '..' &&\n !local.startsWith('..\\\\') &&\n !local.startsWith('../') &&\n !isAbsolute(local))\n )\n}\n\n/**\n * The package and file of an `@rentnerkev/*` import; `undefined` for\n * specifiers with empty, `.` or `..` segments or backslashes, which could\n * leave the package (Node's resolver normalizes them against\n * `node_modules`).\n */\nexport function parsePackageImport(\n specifier: string,\n): PackageImport | undefined {\n const match = PACKAGE_SPECIFIER.exec(specifier)\n const name = match?.[1]\n const path = match?.[2]\n if (name === undefined || path === undefined || path.includes('\\\\')) {\n return undefined\n }\n const segments = path.split('/')\n if (\n segments.some(\n (segment) => segment === '' || segment === '.' || segment === '..',\n )\n ) {\n return undefined\n }\n return { name: `@rentnerkev/${name}`, path }\n}\n\n/** The name in a `package.json`, or `undefined` if it cannot be read. */\nconst manifestName = async (directory: string): Promise<string | undefined> => {\n try {\n const text = await readFile(join(directory, 'package.json'), 'utf8')\n if (text.length > MAX_MANIFEST_BYTES) return undefined\n const manifest: unknown = JSON.parse(text)\n if (typeof manifest !== 'object' || manifest === null) return undefined\n const name: unknown = Reflect.get(manifest, 'name')\n return typeof name === 'string' ? name : undefined\n } catch {\n return undefined\n }\n}\n\n/**\n * Resolves an `@rentnerkev/*` CSS import like Node from the importing file\n * and confines it to that package: the resolved real path must be a `.css`\n * file inside the directory of the nearest `package.json` that names the\n * package. Returns the file and that directory, or why it is refused.\n */\nexport async function resolvePackageImport(\n specifier: string,\n importer: string,\n): Promise<ResolvedImport | string> {\n const parsed = parsePackageImport(specifier)\n if (parsed === undefined || !parsed.path.toLowerCase().endsWith('.css')) {\n return 'only .css files of @rentnerkev packages are read'\n }\n let file: string\n try {\n file = await realpath(createRequire(importer).resolve(specifier))\n } catch {\n return 'the package or file is not installed'\n }\n if (!file.toLowerCase().endsWith('.css')) {\n return 'only .css files of @rentnerkev packages are read'\n }\n let directory = dirname(file)\n for (let level = 0; level < MAX_PACKAGE_LEVELS; level += 1) {\n // oxlint-disable-next-line no-await-in-loop -- each level is checked only when the one below has no matching package.json\n const name = await manifestName(directory)\n if (name !== undefined) {\n return name === parsed.name && isInside(directory, file)\n ? { file, root: directory }\n : `it resolves outside the package ${parsed.name}`\n }\n const parent = dirname(directory)\n if (parent === directory) break\n directory = parent\n }\n return `it resolves outside the package ${parsed.name}`\n}\n"]}
1
+ {"version":3,"file":"package-imports.js","sourceRoot":"","sources":["../../web/src/theme/package-imports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAGrC,8DAA8D;AAC9D,MAAM,iBAAiB,GAAG,8CAA8C,CAAA;AAExE,kEAAkE;AAClE,MAAM,kBAAkB,GAAG,CAAC,CAAA;AAE5B,iEAAiE;AACjE,MAAM,kBAAkB,GAAG,GAAG,GAAG,IAAI,CAAA;AAErC;;;;;GAKG;AACH,SAAS,kBAAkB,CAAC,SAAiB;IACzC,MAAM,KAAK,GAAG,iBAAiB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IAC/C,MAAM,IAAI,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,CAAA;IACvB,MAAM,IAAI,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,CAAA;IACvB,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAClE,OAAO,SAAS,CAAA;IACpB,CAAC;IACD,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAChC,IACI,QAAQ,CAAC,IAAI,CACT,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,KAAK,EAAE,IAAI,OAAO,KAAK,GAAG,IAAI,OAAO,KAAK,IAAI,CACrE,EACH,CAAC;QACC,OAAO,SAAS,CAAA;IACpB,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,eAAe,IAAI,EAAE,EAAE,IAAI,EAAE,CAAA;AAChD,CAAC;AA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CAAC,MAAM,CAAC,EAAE,CAAC;QACvC,OAAO,kDAAkD,CAAA;IAC7D,CAAC;IACD,IAAI,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC7B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,kBAAkB,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACzD,0HAA0H;QAC1H,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,SAAS,CAAC,CAAA;QAC1C,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACrB,OAAO,IAAI,KAAK,MAAM,CAAC,IAAI,IAAI,QAAQ,CAAC,SAAS,EAAE,IAAI,EAAE,UAAU,CAAC;gBAChE,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE;gBAC3B,CAAC,CAAC,mCAAmC,MAAM,CAAC,IAAI,EAAE,CAAA;QAC1D,CAAC;QACD,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;QACjC,IAAI,MAAM,KAAK,SAAS;YAAE,MAAK;QAC/B,SAAS,GAAG,MAAM,CAAA;IACtB,CAAC;IACD,OAAO,mCAAmC,MAAM,CAAC,IAAI,EAAE,CAAA;AAC3D,CAAC","sourcesContent":["import { readFile, realpath } from 'node:fs/promises'\nimport { createRequire } from 'node:module'\nimport { dirname, join } from 'node:path'\nimport { isInside } from './paths.ts'\nimport type { PackageImport, ResolvedImport } from './Types/css-imports.ts'\n\n/** `@rentnerkev/<name>/<path>`; the name as npm allows it. */\nconst PACKAGE_SPECIFIER = /^@rentnerkev\\/([a-z0-9][a-z0-9._-]*)\\/(.+)$/i\n\n/** How far up from an imported file its `package.json` may be. */\nconst MAX_PACKAGE_LEVELS = 8\n\n/** Bytes of a `package.json` that are read to check its name. */\nconst MAX_MANIFEST_BYTES = 256 * 1024\n\n/**\n * The package and file of an `@rentnerkev/*` import; `undefined` for\n * specifiers with empty, `.` or `..` segments or backslashes, which could\n * leave the package (Node's resolver normalizes them against\n * `node_modules`).\n */\nfunction parsePackageImport(specifier: string): PackageImport | undefined {\n const match = PACKAGE_SPECIFIER.exec(specifier)\n const name = match?.[1]\n const path = match?.[2]\n if (name === undefined || path === undefined || path.includes('\\\\')) {\n return undefined\n }\n const segments = path.split('/')\n if (\n segments.some(\n (segment) => segment === '' || segment === '.' || segment === '..',\n )\n ) {\n return undefined\n }\n return { name: `@rentnerkev/${name}`, path }\n}\n\n/** The name in a `package.json`, or `undefined` if it cannot be read. */\nconst manifestName = async (directory: string): Promise<string | undefined> => {\n try {\n const text = await readFile(join(directory, 'package.json'), 'utf8')\n if (text.length > MAX_MANIFEST_BYTES) return undefined\n const manifest: unknown = JSON.parse(text)\n if (typeof manifest !== 'object' || manifest === null) return undefined\n const name: unknown = Reflect.get(manifest, 'name')\n return typeof name === 'string' ? name : undefined\n } catch {\n return undefined\n }\n}\n\n/**\n * Resolves an `@rentnerkev/*` CSS import like Node from the importing file\n * and confines it to that package: the resolved real path must be a `.css`\n * file inside the directory of the nearest `package.json` that names the\n * package. Returns the file and that directory, or why it is refused.\n */\nexport async function resolvePackageImport(\n specifier: string,\n importer: string,\n): Promise<ResolvedImport | string> {\n const parsed = parsePackageImport(specifier)\n if (parsed === undefined || !parsed.path.toLowerCase().endsWith('.css')) {\n return 'only .css files of @rentnerkev packages are read'\n }\n let file: string\n try {\n file = await realpath(createRequire(importer).resolve(specifier))\n } catch {\n return 'the package or file is not installed'\n }\n if (!file.toLowerCase().endsWith('.css')) {\n return 'only .css files of @rentnerkev packages are read'\n }\n let directory = dirname(file)\n for (let level = 0; level < MAX_PACKAGE_LEVELS; level += 1) {\n // oxlint-disable-next-line no-await-in-loop -- each level is checked only when the one below has no matching package.json\n const name = await manifestName(directory)\n if (name !== undefined) {\n return name === parsed.name && isInside(directory, file, 'portable')\n ? { file, root: directory }\n : `it resolves outside the package ${parsed.name}`\n }\n const parent = dirname(directory)\n if (parent === directory) break\n directory = parent\n }\n return `it resolves outside the package ${parsed.name}`\n}\n"]}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Whether a path stays inside a directory, including the directory itself.
3
+ * The portable check also rejects a parent segment written with a backslash.
4
+ */
5
+ export declare const isInside: (directory: string, path: string, separators?: 'native' | 'portable') => boolean;
6
+ //# sourceMappingURL=paths.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../web/src/theme/paths.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,QAAQ,cACN,MAAM,QACX,MAAM,eACA,QAAQ,GAAG,UAAU,KAClC,OAQF,CAAA"}
@@ -0,0 +1,13 @@
1
+ import { isAbsolute, relative, sep } from 'node:path';
2
+ /**
3
+ * Whether a path stays inside a directory, including the directory itself.
4
+ * The portable check also rejects a parent segment written with a backslash.
5
+ */
6
+ export const isInside = (directory, path, separators = 'native') => {
7
+ const local = relative(directory, path);
8
+ return (local !== '..' &&
9
+ !local.startsWith(`..${sep}`) &&
10
+ !(separators === 'portable' && local.startsWith('..\\')) &&
11
+ !isAbsolute(local));
12
+ };
13
+ //# sourceMappingURL=paths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.js","sourceRoot":"","sources":["../../web/src/theme/paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAErD;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CACpB,SAAiB,EACjB,IAAY,EACZ,UAAU,GAA0B,QAAQ,EACrC,EAAE;IACT,MAAM,KAAK,GAAG,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,CAAA;IACvC,OAAO,CACH,KAAK,KAAK,IAAI;QACd,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,GAAG,EAAE,CAAC;QAC7B,CAAC,CAAC,UAAU,KAAK,UAAU,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACxD,CAAC,UAAU,CAAC,KAAK,CAAC,CACrB,CAAA;AACL,CAAC,CAAA","sourcesContent":["import { isAbsolute, relative, sep } from 'node:path'\n\n/**\n * Whether a path stays inside a directory, including the directory itself.\n * The portable check also rejects a parent segment written with a backslash.\n */\nexport const isInside = (\n directory: string,\n path: string,\n separators: 'native' | 'portable' = 'native',\n): boolean => {\n const local = relative(directory, path)\n return (\n local !== '..' &&\n !local.startsWith(`..${sep}`) &&\n !(separators === 'portable' && local.startsWith('..\\\\')) &&\n !isAbsolute(local)\n )\n}\n"]}
@@ -1,6 +1,4 @@
1
- import type { Theme, ThemeFromCssFileOptions } from './Types/theme.ts';
2
- /** Files one theme reads, the entry included (07 – Security). */
3
- export declare const MAX_THEME_FILES = 64;
1
+ import type { Theme, ThemeFromCssFileOptions } from './Types/theme.js';
4
2
  /** Nesting of `@import`s below the entry file. */
5
3
  export declare const MAX_IMPORT_DEPTH = 16;
6
4
  /** Bytes of one file; the engine reads at most 4 MiB of a stylesheet anyway. */
@@ -1 +1 @@
1
- {"version":3,"file":"theme-from-css-file.d.ts","sourceRoot":"","sources":["../../web/src/theme/theme-from-css-file.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACR,KAAK,EACL,uBAAuB,EAE1B,MAAM,kBAAkB,CAAA;AAIzB,iEAAiE;AACjE,eAAO,MAAM,eAAe,KAAK,CAAA;AACjC,kDAAkD;AAClD,eAAO,MAAM,gBAAgB,KAAK,CAAA;AAClC,gFAAgF;AAChF,eAAO,MAAM,oBAAoB,QAAkB,CAAA;AACnD,uCAAuC;AACvC,eAAO,MAAM,eAAe,QAAmB,CAAA;AAC/C,gFAAgF;AAChF,eAAO,MAAM,oBAAoB,MAAM,CAAA;AAoNvC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,gBAAgB,CAClC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,uBAA4B,GACtC,OAAO,CAAC,KAAK,CAAC,CAsBhB"}
1
+ {"version":3,"file":"theme-from-css-file.d.ts","sourceRoot":"","sources":["../../web/src/theme/theme-from-css-file.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACR,KAAK,EACL,uBAAuB,EAG1B,MAAM,kBAAkB,CAAA;AAKzB,kDAAkD;AAClD,eAAO,MAAM,gBAAgB,KAAK,CAAA;AAClC,gFAAgF;AAChF,eAAO,MAAM,oBAAoB,QAAkB,CAAA;AACnD,uCAAuC;AACvC,eAAO,MAAM,eAAe,QAAmB,CAAA;AAC/C,gFAAgF;AAChF,eAAO,MAAM,oBAAoB,MAAM,CAAA;AAgNvC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,gBAAgB,CAClC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,uBAA4B,GACtC,OAAO,CAAC,KAAK,CAAC,CAsBhB"}
@@ -2,10 +2,11 @@ import { open, realpath } from 'node:fs/promises';
2
2
  import { dirname, isAbsolute, relative, resolve, sep } from 'node:path';
3
3
  import { appliesToPrint, cssImports, importKind } from './css-imports.js';
4
4
  import { resolvePackageImport } from './package-imports.js';
5
+ import { isInside } from './paths.js';
5
6
  import { themeScopes, themeStylesheet } from './theme-from-css.js';
6
7
  import { themeWarningList } from './warnings.js';
7
8
  /** Files one theme reads, the entry included (07 – Security). */
8
- export const MAX_THEME_FILES = 64;
9
+ const MAX_THEME_FILES = 64;
9
10
  /** Nesting of `@import`s below the entry file. */
10
11
  export const MAX_IMPORT_DEPTH = 16;
11
12
  /** Bytes of one file; the engine reads at most 4 MiB of a stylesheet anyway. */
@@ -22,11 +23,6 @@ const display = (path) => {
22
23
  : path;
23
24
  return shown.split(sep).join('/');
24
25
  };
25
- const isInside = (directory, path) => {
26
- const local = relative(directory, path);
27
- return (local === '' ||
28
- (local !== '..' && !local.startsWith(`..${sep}`) && !isAbsolute(local)));
29
- };
30
26
  /**
31
27
  * Reads a regular file through one handle, so the size check and the read
32
28
  * see the same file: at most `limit` bytes, plus one to notice a file that
@@ -43,9 +39,14 @@ const readLimited = async (file, limit) => {
43
39
  });
44
40
  if (stats.size > limit)
45
41
  return tooLarge(`${stats.size} bytes`);
46
- const buffer = Buffer.allocUnsafe(limit + 1);
42
+ let buffer = Buffer.allocUnsafe(stats.size + 1);
47
43
  let read = 0;
48
- while (read < buffer.length) {
44
+ while (read <= limit) {
45
+ if (read === buffer.length) {
46
+ const next = Buffer.allocUnsafe(Math.min(limit + 1, Math.max(4096, buffer.length * 2)));
47
+ buffer.copy(next);
48
+ buffer = next;
49
+ }
49
50
  // oxlint-disable-next-line no-await-in-loop -- each read continues where the previous one stopped
50
51
  const { bytesRead } = await handle.read(buffer, read, buffer.length - read, read);
51
52
  if (bytesRead === 0)
@@ -68,10 +69,9 @@ const errorCode = (error) => {
68
69
  return typeof code === 'string' ? code : 'unknown error';
69
70
  };
70
71
  /** Resolves an import to a real file and the root its imports must stay in. */
71
- const resolveImport = async (cssImport, importer, root) => {
72
- const { specifier } = cssImport;
72
+ const resolveImport = async (specifier, kind, importer, root) => {
73
73
  const refused = (reason) => `\`@import '${specifier}'\` is not followed: ${reason}`;
74
- switch (importKind(cssImport)) {
74
+ switch (kind) {
75
75
  case 'relative': {
76
76
  const target = specifier.split(/[?#]/, 1)[0] ?? specifier;
77
77
  if (!target.toLowerCase().endsWith('.css')) {
@@ -98,9 +98,6 @@ const resolveImport = async (cssImport, importer, root) => {
98
98
  }
99
99
  case 'refused':
100
100
  return refused('absolute paths and file: URLs are never read; use a relative path');
101
- case 'built-in':
102
- case 'skipped':
103
- return undefined;
104
101
  }
105
102
  };
106
103
  /** Reads one file and, before it, the files it imports (CSS order). */
@@ -137,16 +134,16 @@ async function readFile(reader, file, root, depth) {
137
134
  for (const cssImport of cssImports(css)) {
138
135
  if (!appliesToPrint(cssImport.media))
139
136
  continue;
140
- if (importKind(cssImport) === 'built-in')
141
- continue;
142
- if (importKind(cssImport) === 'skipped')
137
+ const kind = importKind(cssImport);
138
+ if (kind === 'built-in' || kind === 'skipped')
143
139
  continue;
140
+ const { specifier } = cssImport;
144
141
  followed += 1;
145
142
  if (followed > MAX_IMPORTS_PER_FILE) {
146
143
  reader.warnings.add(`the file has more than ${MAX_IMPORTS_PER_FILE} @import rules; the rest are not followed`, path);
147
144
  break;
148
145
  }
149
- const notFollowed = (reason) => reader.warnings.add(`\`@import '${cssImport.specifier}'\` is not followed: ${reason}`, path);
146
+ const notFollowed = (reason) => reader.warnings.add(`\`@import '${specifier}'\` is not followed: ${reason}`, path);
150
147
  // The limits are checked before an import is resolved, so a file
151
148
  // with thousands of imports cannot make the file system work.
152
149
  if (depth + 1 > MAX_IMPORT_DEPTH) {
@@ -158,9 +155,7 @@ async function readFile(reader, file, root, depth) {
158
155
  continue;
159
156
  }
160
157
  // oxlint-disable-next-line no-await-in-loop -- imports are read one after another in CSS order
161
- const resolved = await resolveImport(cssImport, file, root);
162
- if (resolved === undefined)
163
- continue;
158
+ const resolved = await resolveImport(specifier, kind, file, root);
164
159
  if (typeof resolved === 'string') {
165
160
  reader.warnings.add(resolved, path);
166
161
  continue;
@@ -1 +1 @@
1
- {"version":3,"file":"theme-from-css-file.js","sourceRoot":"","sources":["../../web/src/theme/theme-from-css-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AACvE,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAQlE,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAEhD,iEAAiE;AACjE,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAA;AACjC,kDAAkD;AAClD,MAAM,CAAC,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AE,EAAE,CAAC;QAC1C,MAAM,IAAI,SAAS,CAAC,wCAAwC,CAAC,CAAA;IACjE,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;IAC3C,MAAM,IAAI,GACN,OAAO,CAAC,IAAI,KAAK,SAAS;QACtB,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;QAChB,CAAC,CAAC,MAAM,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;IAC/C,MAAM,MAAM,GAAW;QACnB,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC;QACnC,WAAW,EAAE,EAAE;QACf,QAAQ,EAAE,gBAAgB,EAAE;QAC5B,OAAO,EAAE,IAAI,GAAG,EAAE;QAClB,KAAK,EAAE,EAAE;QACT,KAAK,EAAE,CAAC;KACX,CAAA;IACD,MAAM,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IACvC,OAAO,MAAM,CAAC,MAAM,CAAC;QACjB,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC;QAC9C,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE;KACnC,CAAC,CAAA;AACN,CAAC","sourcesContent":["import { open, realpath } from 'node:fs/promises'\nimport { dirname, isAbsolute, relative, resolve, sep } from 'node:path'\nimport { appliesToPrint, cssImports, importKind } from './css-imports.ts'\nimport { resolvePackageImport } from './package-imports.ts'\nimport { themeScopes, themeStylesheet } from './theme-from-css.ts'\nimport type { CssImport, ResolvedImport } from './Types/css-imports.ts'\nimport type {\n Theme,\n ThemeFromCssFileOptions,\n ThemeStylesheet,\n} from './Types/theme.ts'\nimport type { ThemeWarningList } from './Types/warnings.ts'\nimport { themeWarningList } from './warnings.ts'\n\n/** Files one theme reads, the entry included (07 – Security). */\nexport const MAX_THEME_FILES = 64\n/** Nesting of `@import`s below the entry file. */\nexport const MAX_IMPORT_DEPTH = 16\n/** Bytes of one file; the engine reads at most 4 MiB of a stylesheet anyway. */\nexport const MAX_THEME_FILE_BYTES = 4 * 1024 * 1024\n/** Bytes of all files of one theme. */\nexport const MAX_THEME_BYTES = 16 * 1024 * 1024\n/** `@import` rules of one file that are followed; the rest are not resolved. */\nexport const MAX_IMPORTS_PER_FILE = 256\n\ninterface Reader {\n readonly scopes: readonly string[]\n readonly stylesheets: ThemeStylesheet[]\n readonly warnings: ThemeWarningList\n /** Real paths already read: diamonds are read once, cycles are cut. */\n readonly visited: Set<string>\n /** Real paths of the files being read, for cycle detection. */\n readonly stack: string[]\n bytes: number\n}\n\n/** A file path for warnings: relative to the working directory when inside it. */\nconst display = (path: string): string => {\n const local = relative(process.cwd(), path)\n const shown =\n local !== '' && !local.startsWith('..') && !isAbsolute(local)\n ? local\n : path\n return shown.split(sep).join('/')\n}\n\nconst isInside = (directory: string, path: string): boolean => {\n const local = relative(directory, path)\n return (\n local === '' ||\n (local !== '..' && !local.startsWith(`..${sep}`) && !isAbsolute(local))\n )\n}\n\n/** A file's text and byte count, or why it is not read. */\ntype LimitedRead =\n | { readonly css: string; readonly bytes: number }\n | { readonly refused: string }\n\n/**\n * Reads a regular file through one handle, so the size check and the read\n * see the same file: at most `limit` bytes, plus one to notice a file that\n * grew after its size was taken.\n */\nconst readLimited = async (\n file: string,\n limit: number,\n): Promise<LimitedRead> => {\n const handle = await open(file, 'r')\n try {\n const stats = await handle.stat()\n if (!stats.isFile()) return { refused: 'it is not a regular file' }\n const tooLarge = (size: string) => ({\n refused: `the file has ${size}; themes read at most ${MAX_THEME_FILE_BYTES} bytes per file and ${MAX_THEME_BYTES} in all, so it is skipped`,\n })\n if (stats.size > limit) return tooLarge(`${stats.size} bytes`)\n const buffer = Buffer.allocUnsafe(limit + 1)\n let read = 0\n while (read < buffer.length) {\n // oxlint-disable-next-line no-await-in-loop -- each read continues where the previous one stopped\n const { bytesRead } = await handle.read(\n buffer,\n read,\n buffer.length - read,\n read,\n )\n if (bytesRead === 0) break\n read += bytesRead\n }\n if (read > limit) return tooLarge(`more than ${limit} bytes`)\n return { css: buffer.toString('utf8', 0, read), bytes: read }\n } finally {\n await handle.close()\n }\n}\n\n/** An error's code (`ENOENT`) without the paths its message contains. */\nconst errorCode = (error: unknown): string => {\n const code: unknown =\n typeof error === 'object' && error !== null\n ? Reflect.get(error, 'code')\n : undefined\n return typeof code === 'string' ? code : 'unknown error'\n}\n\n/** Resolves an import to a real file and the root its imports must stay in. */\nconst resolveImport = async (\n cssImport: CssImport,\n importer: string,\n root: string,\n): Promise<ResolvedImport | string | undefined> => {\n const { specifier } = cssImport\n const refused = (reason: string) =>\n `\\`@import '${specifier}'\\` is not followed: ${reason}`\n switch (importKind(cssImport)) {\n case 'relative': {\n const target = specifier.split(/[?#]/, 1)[0] ?? specifier\n if (!target.toLowerCase().endsWith('.css')) {\n return refused('only .css files are read')\n }\n const leaves = refused(\n `it leaves ${display(root)} (set the \\`root\\` option to allow it)`,\n )\n // Checked before the file system is asked, so a refused path\n // does not reveal whether it exists; symlinks are checked below.\n const path = resolve(dirname(importer), target)\n if (!isInside(root, path)) return leaves\n let file: string\n try {\n file = await realpath(path)\n } catch (error) {\n return refused(`the file cannot be read (${errorCode(error)})`)\n }\n return isInside(root, file) ? { file, root } : leaves\n }\n case 'package': {\n const resolved = await resolvePackageImport(specifier, importer)\n return typeof resolved === 'string' ? refused(resolved) : resolved\n }\n case 'refused':\n return refused(\n 'absolute paths and file: URLs are never read; use a relative path',\n )\n case 'built-in':\n case 'skipped':\n return undefined\n }\n}\n\n/** Reads one file and, before it, the files it imports (CSS order). */\nasync function readTheme(\n reader: Reader,\n file: string,\n root: string,\n depth: number,\n): Promise<void> {\n reader.visited.add(file)\n reader.stack.push(file)\n try {\n await readFile(reader, file, root, depth)\n } finally {\n reader.stack.pop()\n }\n}\n\nasync function readFile(\n reader: Reader,\n file: string,\n root: string,\n depth: number,\n): Promise<void> {\n const path = display(file)\n const limit = Math.min(MAX_THEME_FILE_BYTES, MAX_THEME_BYTES - reader.bytes)\n let read: LimitedRead\n try {\n read = await readLimited(file, limit)\n } catch (error) {\n // Only a missing entry file throws; imported files are warnings.\n if (depth === 0) throw error\n read = { refused: `the file cannot be read (${errorCode(error)})` }\n }\n if ('refused' in read) {\n reader.warnings.add(read.refused, path)\n return\n }\n const { css } = read\n reader.bytes += read.bytes\n let followed = 0\n for (const cssImport of cssImports(css)) {\n if (!appliesToPrint(cssImport.media)) continue\n if (importKind(cssImport) === 'built-in') continue\n if (importKind(cssImport) === 'skipped') continue\n followed += 1\n if (followed > MAX_IMPORTS_PER_FILE) {\n reader.warnings.add(\n `the file has more than ${MAX_IMPORTS_PER_FILE} @import rules; the rest are not followed`,\n path,\n )\n break\n }\n const notFollowed = (reason: string) =>\n reader.warnings.add(\n `\\`@import '${cssImport.specifier}'\\` is not followed: ${reason}`,\n path,\n )\n // The limits are checked before an import is resolved, so a file\n // with thousands of imports cannot make the file system work.\n if (depth + 1 > MAX_IMPORT_DEPTH) {\n notFollowed(`imports nest deeper than ${MAX_IMPORT_DEPTH} levels`)\n continue\n }\n if (reader.visited.size >= MAX_THEME_FILES) {\n notFollowed(`a theme reads at most ${MAX_THEME_FILES} files`)\n continue\n }\n // oxlint-disable-next-line no-await-in-loop -- imports are read one after another in CSS order\n const resolved = await resolveImport(cssImport, file, root)\n if (resolved === undefined) continue\n if (typeof resolved === 'string') {\n reader.warnings.add(resolved, path)\n continue\n }\n if (reader.stack.includes(resolved.file)) {\n notFollowed(\n 'it imports a file that is already being read (a cycle)',\n )\n continue\n }\n if (reader.visited.has(resolved.file)) continue\n // oxlint-disable-next-line no-await-in-loop -- an import's files come before the next import's\n await readTheme(reader, resolved.file, resolved.root, depth + 1)\n }\n reader.stylesheets.push(themeStylesheet(css, reader.scopes, path))\n}\n\n/**\n * Reads design tokens from a CSS file and the files it imports, such as the\n * app's Tailwind CSS entry (D-22). Relative `@import`s (`./theme.css`) are\n * followed inside `root` (default: the entry's directory), and imports of\n * `@rentnerkev/*` packages (`@rentnerkev/table/theme.css`) are resolved\n * like Node resolves modules from the importing file and confined to that\n * package. Tailwind itself and `@rentnerkev/pdf/tailwind.css` are built\n * into the engine; other packages and URLs are never read. Only regular\n * `.css` files are read, each file once, with limits on file count,\n * imports, depth and size.\n *\n * ```ts\n * import { themeFromCssFile } from '@rentnerkev/pdf/node'\n *\n * const engine = await createEngine({\n * theme: await themeFromCssFile('src/styles.css'),\n * })\n * ```\n *\n * The entry file must exist; problems with imported files and the CSS are\n * warnings (`theme.warnings`, `engine.themeWarnings`).\n */\nexport async function themeFromCssFile(\n path: string,\n options: ThemeFromCssFileOptions = {},\n): Promise<Theme> {\n if (typeof path !== 'string' || path === '') {\n throw new TypeError('themeFromCssFile() expects a file path')\n }\n const entry = await realpath(resolve(path))\n const root =\n options.root === undefined\n ? dirname(entry)\n : await realpath(resolve(options.root))\n const reader: Reader = {\n scopes: themeScopes(options.scopes),\n stylesheets: [],\n warnings: themeWarningList(),\n visited: new Set(),\n stack: [],\n bytes: 0,\n }\n await readTheme(reader, entry, root, 0)\n return Object.freeze({\n stylesheets: Object.freeze(reader.stylesheets),\n warnings: reader.warnings.list(),\n })\n}\n"]}
1
+ {"version":3,"file":"theme-from-css-file.js","sourceRoot":"","sources":["../../web/src/theme/theme-from-css-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AACvE,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,WAAW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AE;IAErC,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;QAC1C,MAAM,IAAI,SAAS,CAAC,wCAAwC,CAAC,CAAA;IACjE,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;IAC3C,MAAM,IAAI,GACN,OAAO,CAAC,IAAI,KAAK,SAAS;QACtB,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;QAChB,CAAC,CAAC,MAAM,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;IAC/C,MAAM,MAAM,GAAW;QACnB,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC;QACnC,WAAW,EAAE,EAAE;QACf,QAAQ,EAAE,gBAAgB,EAAE;QAC5B,OAAO,EAAE,IAAI,GAAG,EAAE;QAClB,KAAK,EAAE,EAAE;QACT,KAAK,EAAE,CAAC;KACX,CAAA;IACD,MAAM,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IACvC,OAAO,MAAM,CAAC,MAAM,CAAC;QACjB,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC;QAC9C,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE;KACnC,CAAC,CAAA;AACN,CAAC","sourcesContent":["import { open, realpath } from 'node:fs/promises'\nimport { dirname, isAbsolute, relative, resolve, sep } from 'node:path'\nimport { appliesToPrint, cssImports, importKind } from './css-imports.ts'\nimport { resolvePackageImport } from './package-imports.ts'\nimport { isInside } from './paths.ts'\nimport { themeScopes, themeStylesheet } from './theme-from-css.ts'\nimport type { ImportKind, ResolvedImport } from './Types/css-imports.ts'\nimport type {\n Theme,\n ThemeFromCssFileOptions,\n ThemeStylesheet,\n ThemeWarningList,\n} from './Types/theme.ts'\nimport { themeWarningList } from './warnings.ts'\n\n/** Files one theme reads, the entry included (07 – Security). */\nconst MAX_THEME_FILES = 64\n/** Nesting of `@import`s below the entry file. */\nexport const MAX_IMPORT_DEPTH = 16\n/** Bytes of one file; the engine reads at most 4 MiB of a stylesheet anyway. */\nexport const MAX_THEME_FILE_BYTES = 4 * 1024 * 1024\n/** Bytes of all files of one theme. */\nexport const MAX_THEME_BYTES = 16 * 1024 * 1024\n/** `@import` rules of one file that are followed; the rest are not resolved. */\nexport const MAX_IMPORTS_PER_FILE = 256\n\ninterface Reader {\n readonly scopes: readonly string[]\n readonly stylesheets: ThemeStylesheet[]\n readonly warnings: ThemeWarningList\n /** Real paths already read: diamonds are read once, cycles are cut. */\n readonly visited: Set<string>\n /** Real paths of the files being read, for cycle detection. */\n readonly stack: string[]\n bytes: number\n}\n\n/** A file path for warnings: relative to the working directory when inside it. */\nconst display = (path: string): string => {\n const local = relative(process.cwd(), path)\n const shown =\n local !== '' && !local.startsWith('..') && !isAbsolute(local)\n ? local\n : path\n return shown.split(sep).join('/')\n}\n\n/** A file's text and byte count, or why it is not read. */\ntype LimitedRead =\n | { readonly css: string; readonly bytes: number }\n | { readonly refused: string }\n\n/**\n * Reads a regular file through one handle, so the size check and the read\n * see the same file: at most `limit` bytes, plus one to notice a file that\n * grew after its size was taken.\n */\nconst readLimited = async (\n file: string,\n limit: number,\n): Promise<LimitedRead> => {\n const handle = await open(file, 'r')\n try {\n const stats = await handle.stat()\n if (!stats.isFile()) return { refused: 'it is not a regular file' }\n const tooLarge = (size: string) => ({\n refused: `the file has ${size}; themes read at most ${MAX_THEME_FILE_BYTES} bytes per file and ${MAX_THEME_BYTES} in all, so it is skipped`,\n })\n if (stats.size > limit) return tooLarge(`${stats.size} bytes`)\n let buffer = Buffer.allocUnsafe(stats.size + 1)\n let read = 0\n while (read <= limit) {\n if (read === buffer.length) {\n const next = Buffer.allocUnsafe(\n Math.min(limit + 1, Math.max(4096, buffer.length * 2)),\n )\n buffer.copy(next)\n buffer = next\n }\n // oxlint-disable-next-line no-await-in-loop -- each read continues where the previous one stopped\n const { bytesRead } = await handle.read(\n buffer,\n read,\n buffer.length - read,\n read,\n )\n if (bytesRead === 0) break\n read += bytesRead\n }\n if (read > limit) return tooLarge(`more than ${limit} bytes`)\n return { css: buffer.toString('utf8', 0, read), bytes: read }\n } finally {\n await handle.close()\n }\n}\n\n/** An error's code (`ENOENT`) without the paths its message contains. */\nconst errorCode = (error: unknown): string => {\n const code: unknown =\n typeof error === 'object' && error !== null\n ? Reflect.get(error, 'code')\n : undefined\n return typeof code === 'string' ? code : 'unknown error'\n}\n\n/** Resolves an import to a real file and the root its imports must stay in. */\nconst resolveImport = async (\n specifier: string,\n kind: Exclude<ImportKind, 'built-in' | 'skipped'>,\n importer: string,\n root: string,\n): Promise<ResolvedImport | string> => {\n const refused = (reason: string) =>\n `\\`@import '${specifier}'\\` is not followed: ${reason}`\n switch (kind) {\n case 'relative': {\n const target = specifier.split(/[?#]/, 1)[0] ?? specifier\n if (!target.toLowerCase().endsWith('.css')) {\n return refused('only .css files are read')\n }\n const leaves = refused(\n `it leaves ${display(root)} (set the \\`root\\` option to allow it)`,\n )\n // Checked before the file system is asked, so a refused path\n // does not reveal whether it exists; symlinks are checked below.\n const path = resolve(dirname(importer), target)\n if (!isInside(root, path)) return leaves\n let file: string\n try {\n file = await realpath(path)\n } catch (error) {\n return refused(`the file cannot be read (${errorCode(error)})`)\n }\n return isInside(root, file) ? { file, root } : leaves\n }\n case 'package': {\n const resolved = await resolvePackageImport(specifier, importer)\n return typeof resolved === 'string' ? refused(resolved) : resolved\n }\n case 'refused':\n return refused(\n 'absolute paths and file: URLs are never read; use a relative path',\n )\n }\n}\n\n/** Reads one file and, before it, the files it imports (CSS order). */\nasync function readTheme(\n reader: Reader,\n file: string,\n root: string,\n depth: number,\n): Promise<void> {\n reader.visited.add(file)\n reader.stack.push(file)\n try {\n await readFile(reader, file, root, depth)\n } finally {\n reader.stack.pop()\n }\n}\n\nasync function readFile(\n reader: Reader,\n file: string,\n root: string,\n depth: number,\n): Promise<void> {\n const path = display(file)\n const limit = Math.min(MAX_THEME_FILE_BYTES, MAX_THEME_BYTES - reader.bytes)\n let read: LimitedRead\n try {\n read = await readLimited(file, limit)\n } catch (error) {\n // Only a missing entry file throws; imported files are warnings.\n if (depth === 0) throw error\n read = { refused: `the file cannot be read (${errorCode(error)})` }\n }\n if ('refused' in read) {\n reader.warnings.add(read.refused, path)\n return\n }\n const { css } = read\n reader.bytes += read.bytes\n let followed = 0\n for (const cssImport of cssImports(css)) {\n if (!appliesToPrint(cssImport.media)) continue\n const kind = importKind(cssImport)\n if (kind === 'built-in' || kind === 'skipped') continue\n const { specifier } = cssImport\n followed += 1\n if (followed > MAX_IMPORTS_PER_FILE) {\n reader.warnings.add(\n `the file has more than ${MAX_IMPORTS_PER_FILE} @import rules; the rest are not followed`,\n path,\n )\n break\n }\n const notFollowed = (reason: string) =>\n reader.warnings.add(\n `\\`@import '${specifier}'\\` is not followed: ${reason}`,\n path,\n )\n // The limits are checked before an import is resolved, so a file\n // with thousands of imports cannot make the file system work.\n if (depth + 1 > MAX_IMPORT_DEPTH) {\n notFollowed(`imports nest deeper than ${MAX_IMPORT_DEPTH} levels`)\n continue\n }\n if (reader.visited.size >= MAX_THEME_FILES) {\n notFollowed(`a theme reads at most ${MAX_THEME_FILES} files`)\n continue\n }\n // oxlint-disable-next-line no-await-in-loop -- imports are read one after another in CSS order\n const resolved = await resolveImport(specifier, kind, file, root)\n if (typeof resolved === 'string') {\n reader.warnings.add(resolved, path)\n continue\n }\n if (reader.stack.includes(resolved.file)) {\n notFollowed(\n 'it imports a file that is already being read (a cycle)',\n )\n continue\n }\n if (reader.visited.has(resolved.file)) continue\n // oxlint-disable-next-line no-await-in-loop -- an import's files come before the next import's\n await readTheme(reader, resolved.file, resolved.root, depth + 1)\n }\n reader.stylesheets.push(themeStylesheet(css, reader.scopes, path))\n}\n\n/**\n * Reads design tokens from a CSS file and the files it imports, such as the\n * app's Tailwind CSS entry (D-22). Relative `@import`s (`./theme.css`) are\n * followed inside `root` (default: the entry's directory), and imports of\n * `@rentnerkev/*` packages (`@rentnerkev/table/theme.css`) are resolved\n * like Node resolves modules from the importing file and confined to that\n * package. Tailwind itself and `@rentnerkev/pdf/tailwind.css` are built\n * into the engine; other packages and URLs are never read. Only regular\n * `.css` files are read, each file once, with limits on file count,\n * imports, depth and size.\n *\n * ```ts\n * import { themeFromCssFile } from '@rentnerkev/pdf/node'\n *\n * const engine = await createEngine({\n * theme: await themeFromCssFile('src/styles.css'),\n * })\n * ```\n *\n * The entry file must exist; problems with imported files and the CSS are\n * warnings (`theme.warnings`, `engine.themeWarnings`).\n */\nexport async function themeFromCssFile(\n path: string,\n options: ThemeFromCssFileOptions = {},\n): Promise<Theme> {\n if (typeof path !== 'string' || path === '') {\n throw new TypeError('themeFromCssFile() expects a file path')\n }\n const entry = await realpath(resolve(path))\n const root =\n options.root === undefined\n ? dirname(entry)\n : await realpath(resolve(options.root))\n const reader: Reader = {\n scopes: themeScopes(options.scopes),\n stylesheets: [],\n warnings: themeWarningList(),\n visited: new Set(),\n stack: [],\n bytes: 0,\n }\n await readTheme(reader, entry, root, 0)\n return Object.freeze({\n stylesheets: Object.freeze(reader.stylesheets),\n warnings: reader.warnings.list(),\n })\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { Theme, ThemeFromCssOptions, ThemeStylesheet } from './Types/theme.ts';
1
+ import type { Theme, ThemeFromCssOptions, ThemeStylesheet } from './Types/theme.js';
2
2
  /**
3
3
  * The scope selectors `themeFromCss()` and `themeFromCssFile()` read when
4
4
  * none are given: custom properties on `.rentner-pdf` override `:root` ones.
@@ -1,13 +1,10 @@
1
- import type { RenderWarning } from '../engine/Types/render-result.ts';
2
- import type { ThemeWarningList } from './Types/warnings.ts';
1
+ import type { ThemeWarningList } from './Types/theme.js';
3
2
  /**
4
3
  * Warnings one theme collects at most; the rest are summed up in a last
5
4
  * warning, so hostile CSS with many imports cannot grow the list (or make
6
5
  * spreading it throw) without bound.
7
6
  */
8
7
  export declare const MAX_THEME_WARNINGS = 100;
9
- /** An `INVALID_THEME` warning, optionally at a stylesheet. */
10
- export declare const themeWarning: (message: string, path: string | undefined) => RenderWarning;
11
8
  /** A list of at most [`MAX_THEME_WARNINGS`] warnings and a summary. */
12
9
  export declare function themeWarningList(): ThemeWarningList;
13
10
  //# sourceMappingURL=warnings.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"warnings.d.ts","sourceRoot":"","sources":["../../web/src/theme/warnings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAE3D;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,MAAM,CAAA;AAErC,8DAA8D;AAC9D,eAAO,MAAM,YAAY,YACZ,MAAM,QACT,MAAM,GAAG,SAAS,KACzB,aAKG,CAAA;AAEN,uEAAuE;AACvE,wBAAgB,gBAAgB,IAAI,gBAAgB,CAwBnD"}
1
+ {"version":3,"file":"warnings.d.ts","sourceRoot":"","sources":["../../web/src/theme/warnings.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAExD;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,MAAM,CAAA;AAarC,uEAAuE;AACvE,wBAAgB,gBAAgB,IAAI,gBAAgB,CAwBnD"}
@@ -5,7 +5,7 @@
5
5
  */
6
6
  export const MAX_THEME_WARNINGS = 100;
7
7
  /** An `INVALID_THEME` warning, optionally at a stylesheet. */
8
- export const themeWarning = (message, path) => Object.freeze({
8
+ const themeWarning = (message, path) => Object.freeze({
9
9
  code: 'INVALID_THEME',
10
10
  message,
11
11
  ...(path === undefined ? {} : { path }),
@@ -1 +1 @@
1
- {"version":3,"file":"warnings.js","sourceRoot":"","sources":["../../web/src/theme/warnings.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAA;AAErC,8DAA8D;AAC9D,MAAM,CAAC,MAAM,YAAY,GAAG,CACxB,OAAe,EACf,IAAwB,EACX,EAAE,CACf,MAAM,CAAC,MAAM,CAAC;IACV,IAAI,EAAE,eAAwB;IAC9B,OAAO;IACP,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;CAC1C,CAAC,CAAA;AAEN,uEAAuE;AACvE,MAAM,UAAU,gBAAgB;IAC5B,MAAM,QAAQ,GAAoB,EAAE,CAAA;IACpC,IAAI,OAAO,GAAG,CAAC,CAAA;IACf,OAAO;QACH,GAAG,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE;YACnB,IAAI,QAAQ,CAAC,MAAM,GAAG,kBAAkB,EAAE,CAAC;gBACvC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAA;YAC9C,CAAC;iBAAM,CAAC;gBACJ,OAAO,IAAI,CAAC,CAAA;YAChB,CAAC;QACL,CAAC;QACD,IAAI,EAAE,GAAG,EAAE,CACP,MAAM,CAAC,MAAM,CACT,OAAO,KAAK,CAAC;YACT,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC;YACf,CAAC,CAAC;gBACI,GAAG,QAAQ;gBACX,YAAY,CACR,GAAG,OAAO,qCAAqC,EAC/C,SAAS,CACZ;aACJ,CACV;KACR,CAAA;AACL,CAAC","sourcesContent":["import type { RenderWarning } from '../engine/Types/render-result.ts'\nimport type { ThemeWarningList } from './Types/warnings.ts'\n\n/**\n * Warnings one theme collects at most; the rest are summed up in a last\n * warning, so hostile CSS with many imports cannot grow the list (or make\n * spreading it throw) without bound.\n */\nexport const MAX_THEME_WARNINGS = 100\n\n/** An `INVALID_THEME` warning, optionally at a stylesheet. */\nexport const themeWarning = (\n message: string,\n path: string | undefined,\n): RenderWarning =>\n Object.freeze({\n code: 'INVALID_THEME' as const,\n message,\n ...(path === undefined ? {} : { path }),\n })\n\n/** A list of at most [`MAX_THEME_WARNINGS`] warnings and a summary. */\nexport function themeWarningList(): ThemeWarningList {\n const warnings: RenderWarning[] = []\n let dropped = 0\n return {\n add: (message, path) => {\n if (warnings.length < MAX_THEME_WARNINGS) {\n warnings.push(themeWarning(message, path))\n } else {\n dropped += 1\n }\n },\n list: () =>\n Object.freeze(\n dropped === 0\n ? [...warnings]\n : [\n ...warnings,\n themeWarning(\n `${dropped} more theme warnings are not listed`,\n undefined,\n ),\n ],\n ),\n }\n}\n"]}
1
+ {"version":3,"file":"warnings.js","sourceRoot":"","sources":["../../web/src/theme/warnings.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAA;AAErC,8DAA8D;AAC9D,MAAM,YAAY,GAAG,CACjB,OAAe,EACf,IAAwB,EACX,EAAE,CACf,MAAM,CAAC,MAAM,CAAC;IACV,IAAI,EAAE,eAAwB;IAC9B,OAAO;IACP,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;CAC1C,CAAC,CAAA;AAEN,uEAAuE;AACvE,MAAM,UAAU,gBAAgB;IAC5B,MAAM,QAAQ,GAAoB,EAAE,CAAA;IACpC,IAAI,OAAO,GAAG,CAAC,CAAA;IACf,OAAO;QACH,GAAG,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE;YACnB,IAAI,QAAQ,CAAC,MAAM,GAAG,kBAAkB,EAAE,CAAC;gBACvC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAA;YAC9C,CAAC;iBAAM,CAAC;gBACJ,OAAO,IAAI,CAAC,CAAA;YAChB,CAAC;QACL,CAAC;QACD,IAAI,EAAE,GAAG,EAAE,CACP,MAAM,CAAC,MAAM,CACT,OAAO,KAAK,CAAC;YACT,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC;YACf,CAAC,CAAC;gBACI,GAAG,QAAQ;gBACX,YAAY,CACR,GAAG,OAAO,qCAAqC,EAC/C,SAAS,CACZ;aACJ,CACV;KACR,CAAA;AACL,CAAC","sourcesContent":["import type { RenderWarning } from '../engine/Types/render-result.ts'\nimport type { ThemeWarningList } from './Types/theme.ts'\n\n/**\n * Warnings one theme collects at most; the rest are summed up in a last\n * warning, so hostile CSS with many imports cannot grow the list (or make\n * spreading it throw) without bound.\n */\nexport const MAX_THEME_WARNINGS = 100\n\n/** An `INVALID_THEME` warning, optionally at a stylesheet. */\nconst themeWarning = (\n message: string,\n path: string | undefined,\n): RenderWarning =>\n Object.freeze({\n code: 'INVALID_THEME' as const,\n message,\n ...(path === undefined ? {} : { path }),\n })\n\n/** A list of at most [`MAX_THEME_WARNINGS`] warnings and a summary. */\nexport function themeWarningList(): ThemeWarningList {\n const warnings: RenderWarning[] = []\n let dropped = 0\n return {\n add: (message, path) => {\n if (warnings.length < MAX_THEME_WARNINGS) {\n warnings.push(themeWarning(message, path))\n } else {\n dropped += 1\n }\n },\n list: () =>\n Object.freeze(\n dropped === 0\n ? [...warnings]\n : [\n ...warnings,\n themeWarning(\n `${dropped} more theme warnings are not listed`,\n undefined,\n ),\n ],\n ),\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { NitroLike, RentnerPdfViteOptions, RentnerPdfVitePlugin } from './Types/plugin.ts';
1
+ import type { RentnerPdfViteOptions, RentnerPdfVitePlugin } from './Types/plugin.js';
2
2
  /**
3
3
  * Packages Nitro must keep out of its server bundle and copy to
4
4
  * `.output/server/node_modules`: the engine reads its fonts and native
@@ -6,16 +6,13 @@ import type { NitroLike, RentnerPdfViteOptions, RentnerPdfVitePlugin } from './T
6
6
  * React (`react-dom/static` from one copy, hooks from another fail).
7
7
  */
8
8
  export declare const NITRO_TRACE_DEPS: readonly string[];
9
- /** Adds the server packages to Nitro's `traceDeps`, once each. */
10
- export declare function addNitroTraceDeps({ options }: NitroLike): void;
11
- /** The build error for an engine import in a client bundle. */
12
- export declare const clientImportMessage: (source: string, importer: string | undefined) => string;
13
9
  /**
14
10
  * The optional Vite plugin (D-23). In Nitro builds (TanStack Start, Nitro
15
11
  * with Vite) it keeps `@rentnerkev/pdf`, `react` and `react-dom` external
16
12
  * and traced into the server output; in client builds it turns an engine
17
13
  * import into a build error (`client: 'allow'` permits WebAssembly
18
- * rendering in the browser; `@rentnerkev/pdf/node` always fails).
14
+ * rendering in the browser; `@rentnerkev/pdf/node` and `@rentnerkev/pdf/ai`
15
+ * always fail in client builds).
19
16
  *
20
17
  * ```ts
21
18
  * import { rentnerPdf } from '@rentnerkev/pdf/vite'
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../web/src/vite/plugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACR,SAAS,EACT,qBAAqB,EACrB,oBAAoB,EAEvB,MAAM,mBAAmB,CAAA;AAQ1B;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,mBAI3B,CAAA;AAaF,kEAAkE;AAClE,wBAAgB,iBAAiB,CAAC,EAAE,OAAO,EAAE,EAAE,SAAS,GAAG,IAAI,CAS9D;AAKD,+DAA+D;AAC/D,eAAO,MAAM,mBAAmB,WACpB,MAAM,YACJ,MAAM,GAAG,SAAS,KAC7B,MAC8Q,CAAA;AAEjR;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CACtB,OAAO,GAAE,qBAA0B,GACpC,oBAAoB,CA8BtB"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../web/src/vite/plugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAER,qBAAqB,EACrB,oBAAoB,EAEvB,MAAM,mBAAmB,CAAA;AAQ1B;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,mBAI3B,CAAA;AAyCF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,UAAU,CACtB,OAAO,GAAE,qBAA0B,GACpC,oBAAoB,CA8BtB"}
@@ -3,7 +3,7 @@ import { join } from 'node:path';
3
3
  /** Entry points that load the engine (native on servers, WebAssembly in browsers). */
4
4
  const engineEntries = new Set(['@rentnerkev/pdf', '@rentnerkev/pdf/react']);
5
5
  /** Entry points that read files; never part of a client bundle. */
6
- const serverEntries = new Set(['@rentnerkev/pdf/node']);
6
+ const serverEntries = new Set(['@rentnerkev/pdf/node', '@rentnerkev/pdf/ai']);
7
7
  /**
8
8
  * Packages Nitro must keep out of its server bundle and copy to
9
9
  * `.output/server/node_modules`: the engine reads its fonts and native
@@ -15,9 +15,9 @@ export const NITRO_TRACE_DEPS = Object.freeze([
15
15
  'react',
16
16
  'react-dom',
17
17
  ]);
18
- const installed = (rootDir, name) => {
18
+ const installed = (require, name) => {
19
19
  try {
20
- createRequire(join(rootDir, 'package.json')).resolve(`${name}/package.json`);
20
+ require.resolve(`${name}/package.json`);
21
21
  return true;
22
22
  }
23
23
  catch {
@@ -25,22 +25,32 @@ const installed = (rootDir, name) => {
25
25
  }
26
26
  };
27
27
  /** Adds the server packages to Nitro's `traceDeps`, once each. */
28
- export function addNitroTraceDeps({ options }) {
28
+ function addNitroTraceDeps({ options }) {
29
29
  const rootDir = options.rootDir ?? process.cwd();
30
+ // Resolve against the application that owns the Nitro build.
31
+ let require;
32
+ try {
33
+ require = createRequire(join(rootDir, 'package.json'));
34
+ }
35
+ catch {
36
+ // A root without a valid absolute path cannot resolve React.
37
+ }
30
38
  const traceDeps = options.traceDeps ?? [];
31
39
  const additions = NITRO_TRACE_DEPS.filter((name) => !traceDeps.includes(name) &&
32
- (name === '@rentnerkev/pdf' || installed(rootDir, name)));
40
+ (name === '@rentnerkev/pdf' ||
41
+ (require !== undefined && installed(require, name))));
33
42
  options.traceDeps = [...traceDeps, ...additions];
34
43
  }
35
44
  const allowHint = "; to render on WebAssembly in the browser on purpose, use rentnerPdf({ client: 'allow' }).";
36
45
  /** The build error for an engine import in a client bundle. */
37
- export const clientImportMessage = (source, importer) => `${importer ?? 'A module'} imports ${source} into a client bundle. RentnerPDF renders on the server: import it from server functions, server routes or other server-only modules. Type-only imports (\`import type\`) are fine${serverEntries.has(source) ? '.' : allowHint}`;
46
+ const clientImportMessage = (source, importer) => `${importer ?? 'A module'} imports ${source} into a client bundle. RentnerPDF renders on the server: import it from server functions, server routes or other server-only modules. Type-only imports (\`import type\`) are fine${serverEntries.has(source) ? '.' : allowHint}`;
38
47
  /**
39
48
  * The optional Vite plugin (D-23). In Nitro builds (TanStack Start, Nitro
40
49
  * with Vite) it keeps `@rentnerkev/pdf`, `react` and `react-dom` external
41
50
  * and traced into the server output; in client builds it turns an engine
42
51
  * import into a build error (`client: 'allow'` permits WebAssembly
43
- * rendering in the browser; `@rentnerkev/pdf/node` always fails).
52
+ * rendering in the browser; `@rentnerkev/pdf/node` and `@rentnerkev/pdf/ai`
53
+ * always fail in client builds).
44
54
  *
45
55
  * ```ts
46
56
  * import { rentnerPdf } from '@rentnerkev/pdf/vite'
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../web/src/vite/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAQhC,sFAAsF;AACtF,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,iBAAiB,EAAE,uBAAuB,CAAC,CAAC,CAAA;AAE3E,mEAAmE;AACnE,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAA;AAEvD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC1C,iBAAiB;IACjB,OAAO;IACP,WAAW;CACd,CAAC,CAAA;AAEF,MAAM,SAAS,GAAG,CAAC,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,CAAC,GAAG,aAAa,EAAE,GAAG,aAAa,CAAC,CAAC,CAAA;IACvD,IAAI,KAAK,GAAG,KAAK,CAAA;IACjB,OAAO;QACH,IAAI,EAAE,YAAY;QAClB,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,iBAAiB,EAAE;QACvD,cAAc,CAAC,MAAM;YACjB,KAAK,GAAG,MAAM,CAAC,OAAO,KAAK,OAAO,CAAA;QACtC,CAAC;QACD,SAAS,CAEL,MAAc,EACd,QAA4B,EAC5B,cAA2C;YAE3C,4DAA4D;YAC5D,8DAA8D;YAC9D,IAAI,CAAC,KAAK,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC;gBAAE,OAAO,IAAI,CAAA;YAC/C,MAAM,MAAM,GACR,IAAI,CAAC,WAAW,KAAK,SAAS;gBAC1B,CAAC,CAAC,cAAc,EAAE,GAAG,KAAK,IAAI;gBAC9B,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,KAAK,QAAQ,CAAA;YACvD,IAAI,MAAM;gBAAE,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAA;YAC7D,OAAO,IAAI,CAAA;QACf,CAAC;KACJ,CAAA;AACL,CAAC","sourcesContent":["import { createRequire } from 'node:module'\nimport { join } from 'node:path'\nimport type {\n NitroLike,\n RentnerPdfViteOptions,\n RentnerPdfVitePlugin,\n ResolveContextLike,\n} from './Types/plugin.ts'\n\n/** Entry points that load the engine (native on servers, WebAssembly in browsers). */\nconst engineEntries = new Set(['@rentnerkev/pdf', '@rentnerkev/pdf/react'])\n\n/** Entry points that read files; never part of a client bundle. */\nconst serverEntries = new Set(['@rentnerkev/pdf/node'])\n\n/**\n * Packages Nitro must keep out of its server bundle and copy to\n * `.output/server/node_modules`: the engine reads its fonts and native\n * addon next to its own files, and the React path must share the app's\n * React (`react-dom/static` from one copy, hooks from another fail).\n */\nexport const NITRO_TRACE_DEPS = Object.freeze([\n '@rentnerkev/pdf',\n 'react',\n 'react-dom',\n])\n\nconst installed = (rootDir: string, name: string): boolean => {\n try {\n createRequire(join(rootDir, 'package.json')).resolve(\n `${name}/package.json`,\n )\n return true\n } catch {\n return false\n }\n}\n\n/** Adds the server packages to Nitro's `traceDeps`, once each. */\nexport function addNitroTraceDeps({ options }: NitroLike): void {\n const rootDir = options.rootDir ?? process.cwd()\n const traceDeps = options.traceDeps ?? []\n const additions = NITRO_TRACE_DEPS.filter(\n (name) =>\n !traceDeps.includes(name) &&\n (name === '@rentnerkev/pdf' || installed(rootDir, name)),\n )\n options.traceDeps = [...traceDeps, ...additions]\n}\n\nconst allowHint =\n \"; to render on WebAssembly in the browser on purpose, use rentnerPdf({ client: 'allow' }).\"\n\n/** The build error for an engine import in a client bundle. */\nexport const clientImportMessage = (\n source: string,\n importer: string | undefined,\n): string =>\n `${importer ?? 'A module'} imports ${source} into a client bundle. RentnerPDF renders on the server: import it from server functions, server routes or other server-only modules. Type-only imports (\\`import type\\`) are fine${serverEntries.has(source) ? '.' : allowHint}`\n\n/**\n * The optional Vite plugin (D-23). In Nitro builds (TanStack Start, Nitro\n * with Vite) it keeps `@rentnerkev/pdf`, `react` and `react-dom` external\n * and traced into the server output; in client builds it turns an engine\n * import into a build error (`client: 'allow'` permits WebAssembly\n * rendering in the browser; `@rentnerkev/pdf/node` always fails).\n *\n * ```ts\n * import { rentnerPdf } from '@rentnerkev/pdf/vite'\n *\n * export default defineConfig({ plugins: [rentnerPdf(), tanstackStart(), nitro()] })\n * ```\n *\n * @experimental Exempt from SemVer in 1.x until promoted: it follows\n * Nitro's module API, which still changes quickly.\n */\nexport function rentnerPdf(\n options: RentnerPdfViteOptions = {},\n): RentnerPdfVitePlugin {\n const guarded =\n options.client === 'allow'\n ? serverEntries\n : new Set([...engineEntries, ...serverEntries])\n let build = false\n return {\n name: 'rentnerpdf',\n enforce: 'pre',\n nitro: { name: 'rentnerpdf', setup: addNitroTraceDeps },\n configResolved(config) {\n build = config.command === 'build'\n },\n resolveId(\n this: ResolveContextLike,\n source: string,\n importer: string | undefined,\n resolveOptions?: { readonly ssr?: boolean },\n ) {\n // Only builds: the dev server's dependency scan also visits\n // server-only files that the framework compiler strips later.\n if (!build || !guarded.has(source)) return null\n const client =\n this.environment === undefined\n ? resolveOptions?.ssr !== true\n : this.environment.config.consumer === 'client'\n if (client) this.error(clientImportMessage(source, importer))\n return null\n },\n }\n}\n"]}
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../web/src/vite/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAQhC,sFAAsF;AACtF,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,iBAAiB,EAAE,uBAAuB,CAAC,CAAC,CAAA;AAE3E,mEAAmE;AACnE,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,sBAAsB,EAAE,oBAAoB,CAAC,CAAC,CAAA;AAE7E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC1C,iBAAiB;IACjB,OAAO;IACP,WAAW;CACd,CAAC,CAAA;AAEF,MAAM,SAAS,GAAG,CAAC,OAAuB,EAAE,IAAY,EAAW,EAAE;IACjE,IAAI,CAAC;QACD,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,eAAe,CAAC,CAAA;QACvC,OAAO,IAAI,CAAA;IACf,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,KAAK,CAAA;IAChB,CAAC;AACL,CAAC,CAAA;AAED,kEAAkE;AAClE,SAAS,iBAAiB,CAAC,EAAE,OAAO,EAAa;IAC7C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,CAAA;IAChD,6DAA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E,KAAK,EAAE,iBAAiB,EAAE;QACvD,cAAc,CAAC,MAAM;YACjB,KAAK,GAAG,MAAM,CAAC,OAAO,KAAK,OAAO,CAAA;QACtC,CAAC;QACD,SAAS,CAEL,MAAc,EACd,QAA4B,EAC5B,cAA2C;YAE3C,4DAA4D;YAC5D,8DAA8D;YAC9D,IAAI,CAAC,KAAK,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC;gBAAE,OAAO,IAAI,CAAA;YAC/C,MAAM,MAAM,GACR,IAAI,CAAC,WAAW,KAAK,SAAS;gBAC1B,CAAC,CAAC,cAAc,EAAE,GAAG,KAAK,IAAI;gBAC9B,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,KAAK,QAAQ,CAAA;YACvD,IAAI,MAAM;gBAAE,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAA;YAC7D,OAAO,IAAI,CAAA;QACf,CAAC;KACJ,CAAA;AACL,CAAC","sourcesContent":["import { createRequire } from 'node:module'\nimport { join } from 'node:path'\nimport type {\n NitroLike,\n RentnerPdfViteOptions,\n RentnerPdfVitePlugin,\n ResolveContextLike,\n} from './Types/plugin.ts'\n\n/** Entry points that load the engine (native on servers, WebAssembly in browsers). */\nconst engineEntries = new Set(['@rentnerkev/pdf', '@rentnerkev/pdf/react'])\n\n/** Entry points that read files; never part of a client bundle. */\nconst serverEntries = new Set(['@rentnerkev/pdf/node', '@rentnerkev/pdf/ai'])\n\n/**\n * Packages Nitro must keep out of its server bundle and copy to\n * `.output/server/node_modules`: the engine reads its fonts and native\n * addon next to its own files, and the React path must share the app's\n * React (`react-dom/static` from one copy, hooks from another fail).\n */\nexport const NITRO_TRACE_DEPS = Object.freeze([\n '@rentnerkev/pdf',\n 'react',\n 'react-dom',\n])\n\nconst installed = (require: NodeJS.Require, name: string): boolean => {\n try {\n require.resolve(`${name}/package.json`)\n return true\n } catch {\n return false\n }\n}\n\n/** Adds the server packages to Nitro's `traceDeps`, once each. */\nfunction addNitroTraceDeps({ options }: NitroLike): void {\n const rootDir = options.rootDir ?? process.cwd()\n // Resolve against the application that owns the Nitro build.\n let require: NodeJS.Require | undefined\n try {\n require = createRequire(join(rootDir, 'package.json'))\n } catch {\n // A root without a valid absolute path cannot resolve React.\n }\n const traceDeps = options.traceDeps ?? []\n const additions = NITRO_TRACE_DEPS.filter(\n (name) =>\n !traceDeps.includes(name) &&\n (name === '@rentnerkev/pdf' ||\n (require !== undefined && installed(require, name))),\n )\n options.traceDeps = [...traceDeps, ...additions]\n}\n\nconst allowHint =\n \"; to render on WebAssembly in the browser on purpose, use rentnerPdf({ client: 'allow' }).\"\n\n/** The build error for an engine import in a client bundle. */\nconst clientImportMessage = (\n source: string,\n importer: string | undefined,\n): string =>\n `${importer ?? 'A module'} imports ${source} into a client bundle. RentnerPDF renders on the server: import it from server functions, server routes or other server-only modules. Type-only imports (\\`import type\\`) are fine${serverEntries.has(source) ? '.' : allowHint}`\n\n/**\n * The optional Vite plugin (D-23). In Nitro builds (TanStack Start, Nitro\n * with Vite) it keeps `@rentnerkev/pdf`, `react` and `react-dom` external\n * and traced into the server output; in client builds it turns an engine\n * import into a build error (`client: 'allow'` permits WebAssembly\n * rendering in the browser; `@rentnerkev/pdf/node` and `@rentnerkev/pdf/ai`\n * always fail in client builds).\n *\n * ```ts\n * import { rentnerPdf } from '@rentnerkev/pdf/vite'\n *\n * export default defineConfig({ plugins: [rentnerPdf(), tanstackStart(), nitro()] })\n * ```\n *\n * @experimental Exempt from SemVer in 1.x until promoted: it follows\n * Nitro's module API, which still changes quickly.\n */\nexport function rentnerPdf(\n options: RentnerPdfViteOptions = {},\n): RentnerPdfVitePlugin {\n const guarded =\n options.client === 'allow'\n ? serverEntries\n : new Set([...engineEntries, ...serverEntries])\n let build = false\n return {\n name: 'rentnerpdf',\n enforce: 'pre',\n nitro: { name: 'rentnerpdf', setup: addNitroTraceDeps },\n configResolved(config) {\n build = config.command === 'build'\n },\n resolveId(\n this: ResolveContextLike,\n source: string,\n importer: string | undefined,\n resolveOptions?: { readonly ssr?: boolean },\n ) {\n // Only builds: the dev server's dependency scan also visits\n // server-only files that the framework compiler strips later.\n if (!build || !guarded.has(source)) return null\n const client =\n this.environment === undefined\n ? resolveOptions?.ssr !== true\n : this.environment.config.consumer === 'client'\n if (client) this.error(clientImportMessage(source, importer))\n return null\n },\n }\n}\n"]}
package/dist/vite.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { rentnerPdf } from './vite/plugin.ts';
2
- export type { RentnerPdfViteOptions, RentnerPdfVitePlugin, } from './vite/Types/plugin.ts';
1
+ export { rentnerPdf } from './vite/plugin.js';
2
+ export type { RentnerPdfViteOptions, RentnerPdfVitePlugin, } from './vite/Types/plugin.js';
3
3
  //# sourceMappingURL=vite.d.ts.map