@rentnerkev/pdf 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +135 -2
- package/THIRD_PARTY_NOTICES.md +152 -0
- package/dist/components/Types/host.d.ts +3 -0
- package/dist/components/Types/host.d.ts.map +1 -0
- package/dist/components/Types/host.js +2 -0
- package/dist/components/Types/host.js.map +1 -0
- package/dist/components/Types/props.d.ts +504 -0
- package/dist/components/Types/props.d.ts.map +1 -0
- package/dist/components/Types/props.js +2 -0
- package/dist/components/Types/props.js.map +1 -0
- package/dist/components/components.d.ts +87 -0
- package/dist/components/components.d.ts.map +1 -0
- package/dist/components/components.js +86 -0
- package/dist/components/components.js.map +1 -0
- package/dist/components/host.d.ts +7 -0
- package/dist/components/host.d.ts.map +1 -0
- package/dist/components/host.js +15 -0
- package/dist/components/host.js.map +1 -0
- package/dist/engine/Types/backend.d.ts +120 -0
- package/dist/engine/Types/backend.d.ts.map +1 -0
- package/dist/engine/Types/backend.js +2 -0
- package/dist/engine/Types/backend.js.map +1 -0
- package/dist/engine/Types/engine.d.ts +192 -0
- package/dist/engine/Types/engine.d.ts.map +1 -0
- package/dist/engine/Types/engine.js +2 -0
- package/dist/engine/Types/engine.js.map +1 -0
- package/dist/engine/Types/errors.d.ts +16 -0
- package/dist/engine/Types/errors.d.ts.map +1 -0
- package/dist/engine/Types/errors.js +2 -0
- package/dist/engine/Types/errors.js.map +1 -0
- package/dist/engine/Types/limits.d.ts +55 -0
- package/dist/engine/Types/limits.d.ts.map +1 -0
- package/dist/engine/Types/limits.js +2 -0
- package/dist/engine/Types/limits.js.map +1 -0
- package/dist/engine/Types/render-options.d.ts +71 -0
- package/dist/engine/Types/render-options.d.ts.map +1 -0
- package/dist/engine/Types/render-options.js +2 -0
- package/dist/engine/Types/render-options.js.map +1 -0
- package/dist/engine/Types/render-result.d.ts +80 -0
- package/dist/engine/Types/render-result.d.ts.map +1 -0
- package/dist/engine/Types/render-result.js +2 -0
- package/dist/engine/Types/render-result.js.map +1 -0
- package/dist/engine/abort.d.ts +23 -0
- package/dist/engine/abort.d.ts.map +1 -0
- package/dist/engine/abort.js +71 -0
- package/dist/engine/abort.js.map +1 -0
- package/dist/engine/assets.d.ts +22 -0
- package/dist/engine/assets.d.ts.map +1 -0
- package/dist/engine/assets.js +40 -0
- package/dist/engine/assets.js.map +1 -0
- package/dist/engine/backend.d.ts +16 -0
- package/dist/engine/backend.d.ts.map +1 -0
- package/dist/engine/backend.js +43 -0
- package/dist/engine/backend.js.map +1 -0
- package/dist/engine/backends/native.d.ts +11 -0
- package/dist/engine/backends/native.d.ts.map +1 -0
- package/dist/engine/backends/native.js +62 -0
- package/dist/engine/backends/native.js.map +1 -0
- package/dist/engine/backends/wasm.d.ts +16 -0
- package/dist/engine/backends/wasm.d.ts.map +1 -0
- package/dist/engine/backends/wasm.js +216 -0
- package/dist/engine/backends/wasm.js.map +1 -0
- package/dist/engine/channel.d.ts +41 -0
- package/dist/engine/channel.d.ts.map +1 -0
- package/dist/engine/channel.js +140 -0
- package/dist/engine/channel.js.map +1 -0
- package/dist/engine/create-engine.d.ts +8 -0
- package/dist/engine/create-engine.d.ts.map +1 -0
- package/dist/engine/create-engine.js +120 -0
- package/dist/engine/create-engine.js.map +1 -0
- package/dist/engine/default-fonts.d.ts +9 -0
- package/dist/engine/default-fonts.d.ts.map +1 -0
- package/dist/engine/default-fonts.js +42 -0
- package/dist/engine/default-fonts.js.map +1 -0
- package/dist/engine/encode.d.ts +9 -0
- package/dist/engine/encode.d.ts.map +1 -0
- package/dist/engine/encode.js +199 -0
- package/dist/engine/encode.js.map +1 -0
- package/dist/engine/errors.d.ts +37 -0
- package/dist/engine/errors.d.ts.map +1 -0
- package/dist/engine/errors.js +71 -0
- package/dist/engine/errors.js.map +1 -0
- package/dist/engine/fonts.d.ts +9 -0
- package/dist/engine/fonts.d.ts.map +1 -0
- package/dist/engine/fonts.js +14 -0
- package/dist/engine/fonts.js.map +1 -0
- package/dist/engine/lifecycle.d.ts +40 -0
- package/dist/engine/lifecycle.d.ts.map +1 -0
- package/dist/engine/lifecycle.js +104 -0
- package/dist/engine/lifecycle.js.map +1 -0
- package/dist/engine/markup.d.ts +13 -0
- package/dist/engine/markup.d.ts.map +1 -0
- package/dist/engine/markup.js +14 -0
- package/dist/engine/markup.js.map +1 -0
- package/dist/engine/options.d.ts +12 -0
- package/dist/engine/options.d.ts.map +1 -0
- package/dist/engine/options.js +71 -0
- package/dist/engine/options.js.map +1 -0
- package/dist/engine/pdf-bytes.d.ts +8 -0
- package/dist/engine/pdf-bytes.d.ts.map +1 -0
- package/dist/engine/pdf-bytes.js +9 -0
- package/dist/engine/pdf-bytes.js.map +1 -0
- package/dist/engine/prepare.d.ts +17 -0
- package/dist/engine/prepare.d.ts.map +1 -0
- package/dist/engine/prepare.js +44 -0
- package/dist/engine/prepare.js.map +1 -0
- package/dist/engine/render-many.d.ts +14 -0
- package/dist/engine/render-many.d.ts.map +1 -0
- package/dist/engine/render-many.js +156 -0
- package/dist/engine/render-many.js.map +1 -0
- package/dist/engine/render-result.d.ts +12 -0
- package/dist/engine/render-result.d.ts.map +1 -0
- package/dist/engine/render-result.js +62 -0
- package/dist/engine/render-result.js.map +1 -0
- package/dist/engine/render-stream.d.ts +7 -0
- package/dist/engine/render-stream.d.ts.map +1 -0
- package/dist/engine/render-stream.js +56 -0
- package/dist/engine/render-stream.js.map +1 -0
- package/dist/engine/render.d.ts +15 -0
- package/dist/engine/render.d.ts.map +1 -0
- package/dist/engine/render.js +23 -0
- package/dist/engine/render.js.map +1 -0
- package/dist/fonts/NotoSans-Bold.ttf +0 -0
- package/dist/fonts/NotoSans-BoldItalic.ttf +0 -0
- package/dist/fonts/NotoSans-Italic.ttf +0 -0
- package/dist/fonts/NotoSans-Regular.ttf +0 -0
- package/dist/fonts/OFL.txt +94 -0
- package/dist/fonts/sources.json +32 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/ir/Types/input.d.ts +111 -0
- package/dist/ir/Types/input.d.ts.map +1 -0
- package/dist/ir/Types/input.js +2 -0
- package/dist/ir/Types/input.js.map +1 -0
- package/dist/ir/factories.d.ts +108 -0
- package/dist/ir/factories.d.ts.map +1 -0
- package/dist/ir/factories.js +410 -0
- package/dist/ir/factories.js.map +1 -0
- package/dist/ir/ir.generated.d.ts +811 -0
- package/dist/ir/ir.generated.d.ts.map +1 -0
- package/dist/ir/ir.generated.js +4 -0
- package/dist/ir/ir.generated.js.map +1 -0
- package/dist/ir/version.d.ts +9 -0
- package/dist/ir/version.d.ts.map +1 -0
- package/dist/ir/version.js +13 -0
- package/dist/ir/version.js.map +1 -0
- package/dist/jsx/Types/context.d.ts +24 -0
- package/dist/jsx/Types/context.d.ts.map +1 -0
- package/dist/jsx/Types/context.js +2 -0
- package/dist/jsx/Types/context.js.map +1 -0
- package/dist/jsx/Types/element.d.ts +30 -0
- package/dist/jsx/Types/element.d.ts.map +1 -0
- package/dist/jsx/Types/element.js +2 -0
- package/dist/jsx/Types/element.js.map +1 -0
- package/dist/jsx/Types/evaluate.d.ts +61 -0
- package/dist/jsx/Types/evaluate.d.ts.map +1 -0
- package/dist/jsx/Types/evaluate.js +2 -0
- package/dist/jsx/Types/evaluate.js.map +1 -0
- package/dist/jsx/Types/jsx.d.ts +16 -0
- package/dist/jsx/Types/jsx.d.ts.map +1 -0
- package/dist/jsx/Types/jsx.js +2 -0
- package/dist/jsx/Types/jsx.js.map +1 -0
- package/dist/jsx/context.d.ts +21 -0
- package/dist/jsx/context.d.ts.map +1 -0
- package/dist/jsx/context.js +49 -0
- package/dist/jsx/context.js.map +1 -0
- package/dist/jsx/element.d.ts +10 -0
- package/dist/jsx/element.d.ts.map +1 -0
- package/dist/jsx/element.js +19 -0
- package/dist/jsx/element.js.map +1 -0
- package/dist/jsx/evaluate.d.ts +16 -0
- package/dist/jsx/evaluate.d.ts.map +1 -0
- package/dist/jsx/evaluate.js +616 -0
- package/dist/jsx/evaluate.js.map +1 -0
- package/dist/jsx/source.d.ts +13 -0
- package/dist/jsx/source.d.ts.map +1 -0
- package/dist/jsx/source.js +49 -0
- package/dist/jsx/source.js.map +1 -0
- package/dist/jsx-dev-runtime.d.ts +9 -0
- package/dist/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/jsx-dev-runtime.js +24 -0
- package/dist/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx-runtime.d.ts +12 -0
- package/dist/jsx-runtime.d.ts.map +1 -0
- package/dist/jsx-runtime.js +15 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/native/binding.generated.d.ts +227 -0
- package/dist/native/loader.d.ts +22 -0
- package/dist/native/loader.d.ts.map +1 -0
- package/dist/native/loader.js +98 -0
- package/dist/native/loader.js.map +1 -0
- package/dist/native/rentnerpdf.linux-arm64-gnu.node +0 -0
- package/dist/native/rentnerpdf.linux-arm64-musl.node +0 -0
- package/dist/native/rentnerpdf.linux-x64-gnu.node +0 -0
- package/dist/native/rentnerpdf.linux-x64-musl.node +0 -0
- package/dist/native/rentnerpdf.win32-arm64-msvc.node +0 -0
- package/dist/native/rentnerpdf.win32-x64-msvc.node +0 -0
- package/dist/node.d.ts +3 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +6 -0
- package/dist/node.js.map +1 -0
- package/dist/react/Types/preview.d.ts +74 -0
- package/dist/react/Types/preview.d.ts.map +1 -0
- package/dist/react/Types/preview.js +2 -0
- package/dist/react/Types/preview.js.map +1 -0
- package/dist/react/Types/render.d.ts +24 -0
- package/dist/react/Types/render.d.ts.map +1 -0
- package/dist/react/Types/render.js +2 -0
- package/dist/react/Types/render.js.map +1 -0
- package/dist/react/attributes.d.ts +8 -0
- package/dist/react/attributes.d.ts.map +1 -0
- package/dist/react/attributes.js +44 -0
- package/dist/react/attributes.js.map +1 -0
- package/dist/react/components.d.ts +60 -0
- package/dist/react/components.d.ts.map +1 -0
- package/dist/react/components.js +266 -0
- package/dist/react/components.js.map +1 -0
- package/dist/react/pdf-preview.d.ts +16 -0
- package/dist/react/pdf-preview.d.ts.map +1 -0
- package/dist/react/pdf-preview.js +26 -0
- package/dist/react/pdf-preview.js.map +1 -0
- package/dist/react/pdf-render.d.ts +15 -0
- package/dist/react/pdf-render.d.ts.map +1 -0
- package/dist/react/pdf-render.js +60 -0
- package/dist/react/pdf-render.js.map +1 -0
- package/dist/react/registry.d.ts +44 -0
- package/dist/react/registry.d.ts.map +1 -0
- package/dist/react/registry.js +105 -0
- package/dist/react/registry.js.map +1 -0
- package/dist/react/render.d.ts +36 -0
- package/dist/react/render.d.ts.map +1 -0
- package/dist/react/render.js +212 -0
- package/dist/react/render.js.map +1 -0
- package/dist/react/same-document.d.ts +8 -0
- package/dist/react/same-document.d.ts.map +1 -0
- package/dist/react/same-document.js +59 -0
- package/dist/react/same-document.js.map +1 -0
- package/dist/react/static.d.ts +13 -0
- package/dist/react/static.d.ts.map +1 -0
- package/dist/react/static.js +65 -0
- package/dist/react/static.js.map +1 -0
- package/dist/react/use-pdf.d.ts +25 -0
- package/dist/react/use-pdf.d.ts.map +1 -0
- package/dist/react/use-pdf.js +59 -0
- package/dist/react/use-pdf.js.map +1 -0
- package/dist/react.d.ts +9 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +10 -0
- package/dist/react.js.map +1 -0
- package/dist/tailwind/Types/merge-config.d.ts +28 -0
- package/dist/tailwind/Types/merge-config.d.ts.map +1 -0
- package/dist/tailwind/Types/merge-config.js +2 -0
- package/dist/tailwind/Types/merge-config.js.map +1 -0
- package/dist/tailwind/merge-config.d.ts +45 -0
- package/dist/tailwind/merge-config.d.ts.map +1 -0
- package/dist/tailwind/merge-config.js +46 -0
- package/dist/tailwind/merge-config.js.map +1 -0
- package/dist/tailwind-merge.d.ts +3 -0
- package/dist/tailwind-merge.d.ts.map +1 -0
- package/dist/tailwind-merge.js +4 -0
- package/dist/tailwind-merge.js.map +1 -0
- package/dist/tailwind.css +61 -0
- package/dist/theme/Types/css-imports.d.ts +38 -0
- package/dist/theme/Types/css-imports.d.ts.map +1 -0
- package/dist/theme/Types/css-imports.js +2 -0
- package/dist/theme/Types/css-imports.js.map +1 -0
- package/dist/theme/Types/theme.d.ts +70 -0
- package/dist/theme/Types/theme.d.ts.map +1 -0
- package/dist/theme/Types/theme.js +2 -0
- package/dist/theme/Types/theme.js.map +1 -0
- package/dist/theme/Types/warnings.d.ts +9 -0
- package/dist/theme/Types/warnings.d.ts.map +1 -0
- package/dist/theme/Types/warnings.js +2 -0
- package/dist/theme/Types/warnings.js.map +1 -0
- package/dist/theme/css-imports.d.ts +11 -0
- package/dist/theme/css-imports.d.ts.map +1 -0
- package/dist/theme/css-imports.js +138 -0
- package/dist/theme/css-imports.js.map +1 -0
- package/dist/theme/normalize.d.ts +15 -0
- package/dist/theme/normalize.d.ts.map +1 -0
- package/dist/theme/normalize.js +51 -0
- package/dist/theme/normalize.js.map +1 -0
- package/dist/theme/package-imports.d.ts +16 -0
- package/dist/theme/package-imports.d.ts.map +1 -0
- package/dist/theme/package-imports.js +90 -0
- package/dist/theme/package-imports.js.map +1 -0
- package/dist/theme/theme-from-css-file.d.ts +35 -0
- package/dist/theme/theme-from-css-file.d.ts.map +1 -0
- package/dist/theme/theme-from-css-file.js +223 -0
- package/dist/theme/theme-from-css-file.js.map +1 -0
- package/dist/theme/theme-from-css.d.ts +28 -0
- package/dist/theme/theme-from-css.d.ts.map +1 -0
- package/dist/theme/theme-from-css.js +62 -0
- package/dist/theme/theme-from-css.js.map +1 -0
- package/dist/theme/warnings.d.ts +13 -0
- package/dist/theme/warnings.d.ts.map +1 -0
- package/dist/theme/warnings.js +34 -0
- package/dist/theme/warnings.js.map +1 -0
- package/dist/vite/Types/plugin.d.ts +47 -0
- package/dist/vite/Types/plugin.d.ts.map +1 -0
- package/dist/vite/Types/plugin.js +5 -0
- package/dist/vite/Types/plugin.js.map +1 -0
- package/dist/vite/plugin.d.ts +30 -0
- package/dist/vite/plugin.d.ts.map +1 -0
- package/dist/vite/plugin.js +80 -0
- package/dist/vite/plugin.js.map +1 -0
- package/dist/vite.d.ts +3 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +6 -0
- package/dist/vite.js.map +1 -0
- package/dist/wasm/binding.generated.d.ts +259 -0
- package/dist/wasm/loader.d.ts +17 -0
- package/dist/wasm/loader.d.ts.map +1 -0
- package/dist/wasm/loader.js +74 -0
- package/dist/wasm/loader.js.map +1 -0
- package/dist/wasm/pkg/rentnerpdf_wasm.d.ts +259 -0
- package/dist/wasm/pkg/rentnerpdf_wasm.js +883 -0
- package/dist/wasm/pkg/rentnerpdf_wasm_bg.wasm +0 -0
- package/dist/wasm/pkg/rentnerpdf_wasm_bg.wasm.d.ts +40 -0
- package/dist/worker/Types/connection.d.ts +25 -0
- package/dist/worker/Types/connection.d.ts.map +1 -0
- package/dist/worker/Types/connection.js +2 -0
- package/dist/worker/Types/connection.js.map +1 -0
- package/dist/worker/Types/protocol.d.ts +62 -0
- package/dist/worker/Types/protocol.d.ts.map +1 -0
- package/dist/worker/Types/protocol.js +2 -0
- package/dist/worker/Types/protocol.js.map +1 -0
- package/dist/worker/Types/worker-engine.d.ts +91 -0
- package/dist/worker/Types/worker-engine.d.ts.map +1 -0
- package/dist/worker/Types/worker-engine.js +2 -0
- package/dist/worker/Types/worker-engine.js.map +1 -0
- package/dist/worker/client.d.ts +20 -0
- package/dist/worker/client.d.ts.map +1 -0
- package/dist/worker/client.js +131 -0
- package/dist/worker/client.js.map +1 -0
- package/dist/worker/connection.d.ts +5 -0
- package/dist/worker/connection.d.ts.map +1 -0
- package/dist/worker/connection.js +119 -0
- package/dist/worker/connection.js.map +1 -0
- package/dist/worker/protocol.d.ts +24 -0
- package/dist/worker/protocol.d.ts.map +1 -0
- package/dist/worker/protocol.js +71 -0
- package/dist/worker/protocol.js.map +1 -0
- package/dist/worker/serve.d.ts +26 -0
- package/dist/worker/serve.d.ts.map +1 -0
- package/dist/worker/serve.js +119 -0
- package/dist/worker/serve.js.map +1 -0
- package/dist/worker.d.ts +4 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +8 -0
- package/dist/worker.js.map +1 -0
- package/package.json +80 -5
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** A top-level `@import` statement of a stylesheet. */
|
|
2
|
+
export interface CssImport {
|
|
3
|
+
/** The URL or specifier, such as `./theme.css` or `@rentnerkev/table/theme.css`. */
|
|
4
|
+
readonly specifier: string;
|
|
5
|
+
/** Whether it was written as `url(…)`. */
|
|
6
|
+
readonly url: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* The media query list after the specifier, without `layer(…)`,
|
|
9
|
+
* `supports(…)` and Tailwind's `source(…)`, `theme(…)` and `prefix(…)`;
|
|
10
|
+
* empty when absent.
|
|
11
|
+
*/
|
|
12
|
+
readonly media: string;
|
|
13
|
+
}
|
|
14
|
+
/** An `@rentnerkev/<package>/<path>` import, split. */
|
|
15
|
+
export interface PackageImport {
|
|
16
|
+
/** The package name, such as `@rentnerkev/table`. */
|
|
17
|
+
readonly name: string;
|
|
18
|
+
/** The file inside the package, such as `theme.css`. */
|
|
19
|
+
readonly path: string;
|
|
20
|
+
}
|
|
21
|
+
/** An import resolved to a real file and the root its own imports stay in. */
|
|
22
|
+
export interface ResolvedImport {
|
|
23
|
+
readonly file: string;
|
|
24
|
+
readonly root: string;
|
|
25
|
+
}
|
|
26
|
+
/** How `themeFromCssFile()` treats an import. */
|
|
27
|
+
export type ImportKind =
|
|
28
|
+
/** `./x.css` or `../x.css`, below the importer's root. */
|
|
29
|
+
'relative'
|
|
30
|
+
/** `@rentnerkev/<package>/<file>.css`, resolved from the importer. */
|
|
31
|
+
| 'package'
|
|
32
|
+
/** Built into the engine: `tailwindcss` and `@rentnerkev/pdf/tailwind.css`. */
|
|
33
|
+
| 'built-in'
|
|
34
|
+
/** Remote URLs and other packages: never read, no warning. */
|
|
35
|
+
| 'skipped'
|
|
36
|
+
/** Absolute paths and `file:` URLs: never read, with a warning. */
|
|
37
|
+
| 'refused';
|
|
38
|
+
//# sourceMappingURL=css-imports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-imports.d.ts","sourceRoot":"","sources":["../../../web/src/theme/Types/css-imports.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,MAAM,WAAW,SAAS;IACtB,oFAAoF;IACpF,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,0CAA0C;IAC1C,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAA;IACrB;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACzB;AAED,uDAAuD;AACvD,MAAM,WAAW,aAAa;IAC1B,qDAAqD;IACrD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,wDAAwD;IACxD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACxB;AAED,8EAA8E;AAC9E,MAAM,WAAW,cAAc;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACxB;AAED,iDAAiD;AACjD,MAAM,MAAM,UAAU;AAClB,0DAA0D;AACxD,UAAU;AACZ,sEAAsE;GACpE,SAAS;AACX,+EAA+E;GAC7E,UAAU;AACZ,8DAA8D;GAC5D,SAAS;AACX,mEAAmE;GACjE,SAAS,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-imports.js","sourceRoot":"","sources":["../../../web/src/theme/Types/css-imports.ts"],"names":[],"mappings":"","sourcesContent":["/** A top-level `@import` statement of a stylesheet. */\nexport interface CssImport {\n /** The URL or specifier, such as `./theme.css` or `@rentnerkev/table/theme.css`. */\n readonly specifier: string\n /** Whether it was written as `url(…)`. */\n readonly url: boolean\n /**\n * The media query list after the specifier, without `layer(…)`,\n * `supports(…)` and Tailwind's `source(…)`, `theme(…)` and `prefix(…)`;\n * empty when absent.\n */\n readonly media: string\n}\n\n/** An `@rentnerkev/<package>/<path>` import, split. */\nexport interface PackageImport {\n /** The package name, such as `@rentnerkev/table`. */\n readonly name: string\n /** The file inside the package, such as `theme.css`. */\n readonly path: string\n}\n\n/** An import resolved to a real file and the root its own imports stay in. */\nexport interface ResolvedImport {\n readonly file: string\n readonly root: string\n}\n\n/** How `themeFromCssFile()` treats an import. */\nexport type ImportKind =\n /** `./x.css` or `../x.css`, below the importer's root. */\n | 'relative'\n /** `@rentnerkev/<package>/<file>.css`, resolved from the importer. */\n | 'package'\n /** Built into the engine: `tailwindcss` and `@rentnerkev/pdf/tailwind.css`. */\n | 'built-in'\n /** Remote URLs and other packages: never read, no warning. */\n | 'skipped'\n /** Absolute paths and `file:` URLs: never read, with a warning. */\n | 'refused'\n"]}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { RenderWarning } from '../../engine/Types/render-result.ts';
|
|
2
|
+
/** One app stylesheet of a {@link Theme}. */
|
|
3
|
+
export interface ThemeStylesheet {
|
|
4
|
+
/** The CSS text; the engine reads `@theme`, `:root` and scope rules. */
|
|
5
|
+
readonly css: string;
|
|
6
|
+
/**
|
|
7
|
+
* Selectors whose custom properties override `:root` ones, for example
|
|
8
|
+
* `.rentner-pdf`: an app keeps dark web tokens on `:root` and paper
|
|
9
|
+
* tokens for PDFs in one stylesheet.
|
|
10
|
+
*/
|
|
11
|
+
readonly scopes: readonly string[];
|
|
12
|
+
/** Where the CSS came from, such as a file path; warnings use it as path. */
|
|
13
|
+
readonly source?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* App CSS as the source of design tokens (D-22), from `themeFromCss()` or
|
|
17
|
+
* `themeFromCssFile()` (`@rentnerkev/pdf/node`). Pass it to
|
|
18
|
+
* `createEngine({ theme })`. Plain, serializable data.
|
|
19
|
+
*/
|
|
20
|
+
export interface Theme {
|
|
21
|
+
/** The stylesheets in order; later ones win. */
|
|
22
|
+
readonly stylesheets: readonly ThemeStylesheet[];
|
|
23
|
+
/**
|
|
24
|
+
* `INVALID_THEME` warnings found while collecting the stylesheets, such
|
|
25
|
+
* as an import that was not followed. The engine adds the problems it
|
|
26
|
+
* finds in the CSS itself (`Engine.themeWarnings`).
|
|
27
|
+
*/
|
|
28
|
+
readonly warnings: readonly RenderWarning[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* JS overrides: custom properties applied after every stylesheet, like a
|
|
32
|
+
* final `@theme` block that also beats `:root` and scope tokens.
|
|
33
|
+
* `'initial'` removes a variable, `'--color-*': 'initial'` a namespace.
|
|
34
|
+
*/
|
|
35
|
+
export type ThemeVariables = Readonly<Record<`--${string}`, string | number>>;
|
|
36
|
+
/**
|
|
37
|
+
* `EngineOptions.theme`: a theme, JS overrides or a list of both. Every
|
|
38
|
+
* stylesheet applies before every override, in list order.
|
|
39
|
+
*/
|
|
40
|
+
export type ThemeInput = Theme | ThemeVariables | readonly (Theme | ThemeVariables)[];
|
|
41
|
+
export interface ThemeFromCssOptions {
|
|
42
|
+
/**
|
|
43
|
+
* Selectors whose custom properties override `:root` ones. Defaults to
|
|
44
|
+
* `['.rentner-pdf']`; `[]` reads `@theme` and `:root` only.
|
|
45
|
+
*/
|
|
46
|
+
readonly scopes?: readonly string[];
|
|
47
|
+
/** A name for the CSS in warnings, such as its file path. */
|
|
48
|
+
readonly source?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface ThemeFromCssFileOptions {
|
|
51
|
+
/**
|
|
52
|
+
* Selectors whose custom properties override `:root` ones, in every
|
|
53
|
+
* file. Defaults to `['.rentner-pdf']`.
|
|
54
|
+
*/
|
|
55
|
+
readonly scopes?: readonly string[];
|
|
56
|
+
/**
|
|
57
|
+
* The directory relative `@import`s must stay in. Defaults to the
|
|
58
|
+
* directory of the entry file; files of `@rentnerkev/*` packages stay
|
|
59
|
+
* in their package.
|
|
60
|
+
*/
|
|
61
|
+
readonly root?: string;
|
|
62
|
+
}
|
|
63
|
+
/** A theme as both backends receive it. */
|
|
64
|
+
export interface BackendTheme {
|
|
65
|
+
readonly stylesheets: readonly ThemeStylesheet[];
|
|
66
|
+
readonly variables: readonly (readonly [name: string, value: string])[];
|
|
67
|
+
/** Root font size in CSS pixels; `undefined` keeps 16. */
|
|
68
|
+
readonly rootFontSize: number | undefined;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=theme.d.ts.map
|
|
@@ -0,0 +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,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,CAAA;AAE7E;;;GAGG;AACH,MAAM,MAAM,UAAU,GAClB,KAAK,GAAG,cAAc,GAAG,SAAS,CAAC,KAAK,GAAG,cAAc,CAAC,EAAE,CAAA;AAEhE,MAAM,WAAW,mBAAmB;IAChC;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACnC,6DAA6D;IAC7D,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAC3B;AAED,MAAM,WAAW,uBAAuB;IACpC;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACnC;;;;OAIG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CACzB;AAED,2CAA2C;AAC3C,MAAM,WAAW,YAAY;IACzB,QAAQ,CAAC,WAAW,EAAE,SAAS,eAAe,EAAE,CAAA;IAChD,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,EAAE,CAAA;IACvE,0DAA0D;IAC1D,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAA;CAC5C"}
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RenderWarning } from '../../engine/Types/render-result.ts';
|
|
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
|
+
}
|
|
9
|
+
//# sourceMappingURL=warnings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"warnings.d.ts","sourceRoot":"","sources":["../../../web/src/theme/Types/warnings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AAExE,0CAA0C;AAC1C,MAAM,WAAW,gBAAgB;IAC7B,2EAA2E;IAC3E,QAAQ,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAA;IACjE,wEAAwE;IACxE,QAAQ,CAAC,IAAI,EAAE,MAAM,SAAS,aAAa,EAAE,CAAA;CAChD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"warnings.js","sourceRoot":"","sources":["../../../web/src/theme/Types/warnings.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"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CssImport, ImportKind } from './Types/css-imports.ts';
|
|
2
|
+
/**
|
|
3
|
+
* The top-level `@import` statements of a stylesheet, in order. Comments,
|
|
4
|
+
* strings and blocks are skipped; nothing is fetched.
|
|
5
|
+
*/
|
|
6
|
+
export declare function cssImports(css: string): CssImport[];
|
|
7
|
+
/** Whether an import's media query list applies to paper. */
|
|
8
|
+
export declare const appliesToPrint: (media: string) => boolean;
|
|
9
|
+
/** How `themeFromCssFile()` treats an import specifier. */
|
|
10
|
+
export declare function importKind({ specifier, url }: CssImport): ImportKind;
|
|
11
|
+
//# sourceMappingURL=css-imports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-imports.d.ts","sourceRoot":"","sources":["../../web/src/theme/css-imports.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AA6DnE;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,CAyCnD;AAED,6DAA6D;AAC7D,eAAO,MAAM,cAAc,UAAW,MAAM,KAAG,OAUe,CAAA;AAE9D,2DAA2D;AAC3D,wBAAgB,UAAU,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,EAAE,SAAS,GAAG,UAAU,CA4BpE"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
const isSpace = (character) => character !== undefined && /\s/.test(character);
|
|
2
|
+
/** The index after a string starting at `start` (its quote). */
|
|
3
|
+
const skipString = (css, start) => {
|
|
4
|
+
const quote = css[start];
|
|
5
|
+
let index = start + 1;
|
|
6
|
+
while (index < css.length && css[index] !== quote) {
|
|
7
|
+
index += css[index] === '\\' ? 2 : 1;
|
|
8
|
+
}
|
|
9
|
+
return Math.min(index + 1, css.length);
|
|
10
|
+
};
|
|
11
|
+
/** The index after a comment starting at `start`, or the end of the text. */
|
|
12
|
+
const skipComment = (css, start) => {
|
|
13
|
+
const end = css.indexOf('*/', start + 2);
|
|
14
|
+
return end === -1 ? css.length : end + 2;
|
|
15
|
+
};
|
|
16
|
+
/** Reads a string literal's content; an unterminated one runs to the end. */
|
|
17
|
+
const unquote = (literal) => literal.length > 1 && literal.endsWith(literal.charAt(0))
|
|
18
|
+
? literal.slice(1, -1)
|
|
19
|
+
: literal.slice(1);
|
|
20
|
+
/** Splits `url(x) layer(base) print` into the specifier and the rest. */
|
|
21
|
+
const parsePrelude = (prelude) => {
|
|
22
|
+
const text = prelude.trim();
|
|
23
|
+
let specifier;
|
|
24
|
+
let rest;
|
|
25
|
+
let url = false;
|
|
26
|
+
if (text.startsWith('"') || text.startsWith("'")) {
|
|
27
|
+
const end = skipString(text, 0);
|
|
28
|
+
specifier = unquote(text.slice(0, end));
|
|
29
|
+
rest = text.slice(end);
|
|
30
|
+
}
|
|
31
|
+
else if (/^url\(/i.test(text)) {
|
|
32
|
+
const close = text.indexOf(')');
|
|
33
|
+
if (close === -1)
|
|
34
|
+
return undefined;
|
|
35
|
+
const inner = text.slice(4, close).trim();
|
|
36
|
+
specifier =
|
|
37
|
+
inner.startsWith('"') || inner.startsWith("'")
|
|
38
|
+
? unquote(inner)
|
|
39
|
+
: inner;
|
|
40
|
+
rest = text.slice(close + 1);
|
|
41
|
+
url = true;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
const media = rest
|
|
47
|
+
.replace(/\b(?:layer|supports|source|theme|prefix)\((?:[^()]|\([^()]*\))*\)/gi, ' ')
|
|
48
|
+
.replace(/\blayer\b/gi, ' ')
|
|
49
|
+
.trim()
|
|
50
|
+
.replace(/\s+/g, ' ');
|
|
51
|
+
return { specifier, url, media };
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* The top-level `@import` statements of a stylesheet, in order. Comments,
|
|
55
|
+
* strings and blocks are skipped; nothing is fetched.
|
|
56
|
+
*/
|
|
57
|
+
export function cssImports(css) {
|
|
58
|
+
const imports = [];
|
|
59
|
+
let depth = 0;
|
|
60
|
+
let index = 0;
|
|
61
|
+
while (index < css.length) {
|
|
62
|
+
const character = css[index];
|
|
63
|
+
if (character === '/' && css[index + 1] === '*') {
|
|
64
|
+
index = skipComment(css, index);
|
|
65
|
+
}
|
|
66
|
+
else if (character === '"' || character === "'") {
|
|
67
|
+
index = skipString(css, index);
|
|
68
|
+
}
|
|
69
|
+
else if (character === '{') {
|
|
70
|
+
depth += 1;
|
|
71
|
+
index += 1;
|
|
72
|
+
}
|
|
73
|
+
else if (character === '}') {
|
|
74
|
+
depth = Math.max(0, depth - 1);
|
|
75
|
+
index += 1;
|
|
76
|
+
}
|
|
77
|
+
else if (depth === 0 &&
|
|
78
|
+
character === '@' &&
|
|
79
|
+
css.slice(index + 1, index + 7).toLowerCase() === 'import' &&
|
|
80
|
+
(isSpace(css[index + 7]) ||
|
|
81
|
+
css[index + 7] === '"' ||
|
|
82
|
+
css[index + 7] === "'" ||
|
|
83
|
+
css[index + 7] === 'u')) {
|
|
84
|
+
let end = index + 7;
|
|
85
|
+
while (end < css.length && css[end] !== ';' && css[end] !== '{') {
|
|
86
|
+
if (css[end] === '"' || css[end] === "'")
|
|
87
|
+
end = skipString(css, end);
|
|
88
|
+
else if (css[end] === '/' && css[end + 1] === '*')
|
|
89
|
+
end = skipComment(css, end);
|
|
90
|
+
else
|
|
91
|
+
end += 1;
|
|
92
|
+
}
|
|
93
|
+
const parsed = parsePrelude(css.slice(index + 7, end));
|
|
94
|
+
if (parsed !== undefined)
|
|
95
|
+
imports.push(parsed);
|
|
96
|
+
index = end;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
index += 1;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return imports;
|
|
103
|
+
}
|
|
104
|
+
/** Whether an import's media query list applies to paper. */
|
|
105
|
+
export const appliesToPrint = (media) => media === '' ||
|
|
106
|
+
media
|
|
107
|
+
.split(',')
|
|
108
|
+
.map((query) => query
|
|
109
|
+
.trim()
|
|
110
|
+
.toLowerCase()
|
|
111
|
+
.replace(/^only\s+/, ''))
|
|
112
|
+
.some((query) => query === 'print' || query === 'all');
|
|
113
|
+
/** How `themeFromCssFile()` treats an import specifier. */
|
|
114
|
+
export function importKind({ specifier, url }) {
|
|
115
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(specifier) &&
|
|
116
|
+
!/^[a-z]:[\\/]/i.test(specifier)) {
|
|
117
|
+
return specifier.toLowerCase().startsWith('file:')
|
|
118
|
+
? 'refused'
|
|
119
|
+
: 'skipped';
|
|
120
|
+
}
|
|
121
|
+
if (specifier.startsWith('/') ||
|
|
122
|
+
specifier.startsWith('\\') ||
|
|
123
|
+
/^[a-z]:[\\/]/i.test(specifier)) {
|
|
124
|
+
return 'refused';
|
|
125
|
+
}
|
|
126
|
+
if (specifier.startsWith('./') || specifier.startsWith('../')) {
|
|
127
|
+
return 'relative';
|
|
128
|
+
}
|
|
129
|
+
if (url)
|
|
130
|
+
return 'relative';
|
|
131
|
+
if (specifier === 'tailwindcss' ||
|
|
132
|
+
specifier.startsWith('tailwindcss/') ||
|
|
133
|
+
specifier === '@rentnerkev/pdf/tailwind.css') {
|
|
134
|
+
return 'built-in';
|
|
135
|
+
}
|
|
136
|
+
return specifier.startsWith('@rentnerkev/') ? 'package' : 'skipped';
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=css-imports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-imports.js","sourceRoot":"","sources":["../../web/src/theme/css-imports.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,GAAG,CAAC,SAA6B,EAAW,EAAE,CACvD,SAAS,KAAK,SAAS,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;AAEnD,gEAAgE;AAChE,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,KAAa,EAAU,EAAE;IACtD,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,CAAA;IACxB,IAAI,KAAK,GAAG,KAAK,GAAG,CAAC,CAAA;IACrB,OAAO,KAAK,GAAG,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,KAAK,EAAE,CAAC;QAChD,KAAK,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACxC,CAAC;IACD,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;AAC1C,CAAC,CAAA;AAED,6EAA6E;AAC7E,MAAM,WAAW,GAAG,CAAC,GAAW,EAAE,KAAa,EAAU,EAAE;IACvD,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI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C,UAAU,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5D,OAAO,UAAU,CAAA;IACrB,CAAC;IACD,IAAI,GAAG;QAAE,OAAO,UAAU,CAAA;IAC1B,IACI,SAAS,KAAK,aAAa;QAC3B,SAAS,CAAC,UAAU,CAAC,cAAc,CAAC;QACpC,SAAS,KAAK,8BAA8B,EAC9C,CAAC;QACC,OAAO,UAAU,CAAA;IACrB,CAAC;IACD,OAAO,SAAS,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAA;AACvE,CAAC","sourcesContent":["import type { CssImport, ImportKind } from './Types/css-imports.ts'\n\nconst isSpace = (character: string | undefined): boolean =>\n character !== undefined && /\\s/.test(character)\n\n/** The index after a string starting at `start` (its quote). */\nconst skipString = (css: string, start: number): number => {\n const quote = css[start]\n let index = start + 1\n while (index < css.length && css[index] !== quote) {\n index += css[index] === '\\\\' ? 2 : 1\n }\n return Math.min(index + 1, css.length)\n}\n\n/** The index after a comment starting at `start`, or the end of the text. */\nconst skipComment = (css: string, start: number): number => {\n const end = css.indexOf('*/', start + 2)\n return end === -1 ? css.length : end + 2\n}\n\n/** Reads a string literal's content; an unterminated one runs to the end. */\nconst unquote = (literal: string): string =>\n literal.length > 1 && literal.endsWith(literal.charAt(0))\n ? literal.slice(1, -1)\n : literal.slice(1)\n\n/** Splits `url(x) layer(base) print` into the specifier and the rest. */\nconst parsePrelude = (prelude: string): CssImport | undefined => {\n const text = prelude.trim()\n let specifier: string\n let rest: string\n let url = false\n if (text.startsWith('\"') || text.startsWith(\"'\")) {\n const end = skipString(text, 0)\n specifier = unquote(text.slice(0, end))\n rest = text.slice(end)\n } else if (/^url\\(/i.test(text)) {\n const close = text.indexOf(')')\n if (close === -1) return undefined\n const inner = text.slice(4, close).trim()\n specifier =\n inner.startsWith('\"') || inner.startsWith(\"'\")\n ? unquote(inner)\n : inner\n rest = text.slice(close + 1)\n url = true\n } else {\n return undefined\n }\n const media = rest\n .replace(\n /\\b(?:layer|supports|source|theme|prefix)\\((?:[^()]|\\([^()]*\\))*\\)/gi,\n ' ',\n )\n .replace(/\\blayer\\b/gi, ' ')\n .trim()\n .replace(/\\s+/g, ' ')\n return { specifier, url, media }\n}\n\n/**\n * The top-level `@import` statements of a stylesheet, in order. Comments,\n * strings and blocks are skipped; nothing is fetched.\n */\nexport function cssImports(css: string): CssImport[] {\n const imports: CssImport[] = []\n let depth = 0\n let index = 0\n while (index < css.length) {\n const character = css[index]\n if (character === '/' && css[index + 1] === '*') {\n index = skipComment(css, index)\n } else if (character === '\"' || character === \"'\") {\n index = skipString(css, index)\n } else if (character === '{') {\n depth += 1\n index += 1\n } else if (character === '}') {\n depth = Math.max(0, depth - 1)\n index += 1\n } else if (\n depth === 0 &&\n character === '@' &&\n css.slice(index + 1, index + 7).toLowerCase() === 'import' &&\n (isSpace(css[index + 7]) ||\n css[index + 7] === '\"' ||\n css[index + 7] === \"'\" ||\n css[index + 7] === 'u')\n ) {\n let end = index + 7\n while (end < css.length && css[end] !== ';' && css[end] !== '{') {\n if (css[end] === '\"' || css[end] === \"'\")\n end = skipString(css, end)\n else if (css[end] === '/' && css[end + 1] === '*')\n end = skipComment(css, end)\n else end += 1\n }\n const parsed = parsePrelude(css.slice(index + 7, end))\n if (parsed !== undefined) imports.push(parsed)\n index = end\n } else {\n index += 1\n }\n }\n return imports\n}\n\n/** Whether an import's media query list applies to paper. */\nexport const appliesToPrint = (media: string): boolean =>\n media === '' ||\n media\n .split(',')\n .map((query) =>\n query\n .trim()\n .toLowerCase()\n .replace(/^only\\s+/, ''),\n )\n .some((query) => query === 'print' || query === 'all')\n\n/** How `themeFromCssFile()` treats an import specifier. */\nexport function importKind({ specifier, url }: CssImport): ImportKind {\n if (\n /^[a-z][a-z0-9+.-]*:/i.test(specifier) &&\n !/^[a-z]:[\\\\/]/i.test(specifier)\n ) {\n return specifier.toLowerCase().startsWith('file:')\n ? 'refused'\n : 'skipped'\n }\n if (\n specifier.startsWith('/') ||\n specifier.startsWith('\\\\') ||\n /^[a-z]:[\\\\/]/i.test(specifier)\n ) {\n return 'refused'\n }\n if (specifier.startsWith('./') || specifier.startsWith('../')) {\n return 'relative'\n }\n if (url) return 'relative'\n if (\n specifier === 'tailwindcss' ||\n specifier.startsWith('tailwindcss/') ||\n specifier === '@rentnerkev/pdf/tailwind.css'\n ) {\n return 'built-in'\n }\n return specifier.startsWith('@rentnerkev/') ? 'package' : 'skipped'\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { RenderWarning } from '../engine/Types/render-result.ts';
|
|
2
|
+
import type { BackendTheme, ThemeInput } from './Types/theme.ts';
|
|
3
|
+
/** `EngineOptions.theme` and `rootFontSize` as the backends receive them. */
|
|
4
|
+
export interface NormalizedTheme {
|
|
5
|
+
/** `undefined` when the built-in theme applies unchanged. */
|
|
6
|
+
readonly backend: BackendTheme | undefined;
|
|
7
|
+
/** Warnings found while collecting the stylesheets (imports). */
|
|
8
|
+
readonly warnings: readonly RenderWarning[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Flattens a theme input: all stylesheets in list order, then all JS
|
|
12
|
+
* overrides in list order (later values win).
|
|
13
|
+
*/
|
|
14
|
+
export declare function normalizeTheme(input: ThemeInput | undefined, rootFontSize: number | undefined): NormalizedTheme;
|
|
15
|
+
//# sourceMappingURL=normalize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../web/src/theme/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AACrE,OAAO,KAAK,EACR,YAAY,EAEZ,UAAU,EAEb,MAAM,kBAAkB,CAAA;AAezB,6EAA6E;AAC7E,MAAM,WAAW,eAAe;IAC5B,6DAA6D;IAC7D,QAAQ,CAAC,OAAO,EAAE,YAAY,GAAG,SAAS,CAAA;IAC1C,iEAAiE;IACjE,QAAQ,CAAC,QAAQ,EAAE,SAAS,aAAa,EAAE,CAAA;CAC9C;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC1B,KAAK,EAAE,UAAU,GAAG,SAAS,EAC7B,YAAY,EAAE,MAAM,GAAG,SAAS,GACjC,eAAe,CAsCjB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const isTheme = (input) => Array.isArray(input.stylesheets);
|
|
2
|
+
const variableValue = (name, value) => {
|
|
3
|
+
if (typeof value === 'string')
|
|
4
|
+
return value;
|
|
5
|
+
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
6
|
+
return String(value);
|
|
7
|
+
}
|
|
8
|
+
throw new TypeError(`theme variable ${name} must be a string or a finite number`);
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Flattens a theme input: all stylesheets in list order, then all JS
|
|
12
|
+
* overrides in list order (later values win).
|
|
13
|
+
*/
|
|
14
|
+
export function normalizeTheme(input, rootFontSize) {
|
|
15
|
+
if (rootFontSize !== undefined && typeof rootFontSize !== 'number') {
|
|
16
|
+
throw new TypeError('rootFontSize must be a number of CSS pixels');
|
|
17
|
+
}
|
|
18
|
+
const parts = input === undefined
|
|
19
|
+
? []
|
|
20
|
+
: Array.isArray(input)
|
|
21
|
+
? input
|
|
22
|
+
: [input];
|
|
23
|
+
const stylesheets = [];
|
|
24
|
+
const variables = [];
|
|
25
|
+
const warnings = [];
|
|
26
|
+
for (const part of parts) {
|
|
27
|
+
if (typeof part !== 'object' || part === null) {
|
|
28
|
+
throw new TypeError('theme must be a theme from themeFromCss(), an object of CSS variables or a list of both');
|
|
29
|
+
}
|
|
30
|
+
if (isTheme(part)) {
|
|
31
|
+
// Loops instead of spreading: a spread of a long list throws.
|
|
32
|
+
for (const stylesheet of part.stylesheets)
|
|
33
|
+
stylesheets.push(stylesheet);
|
|
34
|
+
for (const warning of part.warnings ?? [])
|
|
35
|
+
warnings.push(warning);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
for (const [name, value] of Object.entries(part)) {
|
|
39
|
+
variables.push([name, variableValue(name, value)]);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const changed = stylesheets.length > 0 ||
|
|
44
|
+
variables.length > 0 ||
|
|
45
|
+
rootFontSize !== undefined;
|
|
46
|
+
return {
|
|
47
|
+
backend: changed ? { stylesheets, variables, rootFontSize } : undefined,
|
|
48
|
+
warnings,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=normalize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../../web/src/theme/normalize.ts"],"names":[],"mappings":"AAQA,MAAM,OAAO,GAAG,CAAC,KAA6B,EAAkB,EAAE,CAC9D,KAAK,CAAC,OAAO,CAAE,KAAwB,CAAC,WAAW,CAAC,CAAA;AAExD,MAAM,aAAa,GAAG,CAAC,IAAY,EAAE,KAAc,EAAU,EAAE;IAC3D,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC3C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACtD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;IACxB,CAAC;IACD,MAAM,IAAI,SAAS,CACf,kBAAkB,IAAI,sCAAsC,CAC/D,CAAA;AACL,CAAC,CAAA;AAUD;;;GAGG;AACH,MAAM,UAAU,cAAc,CAC1B,KAA6B,EAC7B,YAAgC;IAEhC,IAAI,YAAY,KAAK,SAAS,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;QACjE,MAAM,IAAI,SAAS,CAAC,6CAA6C,CAAC,CAAA;IACtE,CAAC;IACD,MAAM,KAAK,GACP,KAAK,KAAK,SAAS;QACf,CAAC,CAAC,EAAE;QAC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Content":["import type { RenderWarning } from '../engine/Types/render-result.ts'\nimport type {\n BackendTheme,\n Theme,\n ThemeInput,\n ThemeVariables,\n} from './Types/theme.ts'\n\nconst isTheme = (input: Theme | ThemeVariables): input is Theme =>\n Array.isArray((input as Partial<Theme>).stylesheets)\n\nconst variableValue = (name: string, value: unknown): string => {\n if (typeof value === 'string') return value\n if (typeof value === 'number' && Number.isFinite(value)) {\n return String(value)\n }\n throw new TypeError(\n `theme variable ${name} must be a string or a finite number`,\n )\n}\n\n/** `EngineOptions.theme` and `rootFontSize` as the backends receive them. */\nexport interface NormalizedTheme {\n /** `undefined` when the built-in theme applies unchanged. */\n readonly backend: BackendTheme | undefined\n /** Warnings found while collecting the stylesheets (imports). */\n readonly warnings: readonly RenderWarning[]\n}\n\n/**\n * Flattens a theme input: all stylesheets in list order, then all JS\n * overrides in list order (later values win).\n */\nexport function normalizeTheme(\n input: ThemeInput | undefined,\n rootFontSize: number | undefined,\n): NormalizedTheme {\n if (rootFontSize !== undefined && typeof rootFontSize !== 'number') {\n throw new TypeError('rootFontSize must be a number of CSS pixels')\n }\n const parts: readonly (Theme | ThemeVariables)[] =\n input === undefined\n ? []\n : Array.isArray(input)\n ? input\n : [input as Theme | ThemeVariables]\n const stylesheets: BackendTheme['stylesheets'][number][] = []\n const variables: [string, string][] = []\n const warnings: RenderWarning[] = []\n for (const part of parts) {\n if (typeof part !== 'object' || part === null) {\n throw new TypeError(\n 'theme must be a theme from themeFromCss(), an object of CSS variables or a list of both',\n )\n }\n if (isTheme(part)) {\n // Loops instead of spreading: a spread of a long list throws.\n for (const stylesheet of part.stylesheets)\n stylesheets.push(stylesheet)\n for (const warning of part.warnings ?? []) warnings.push(warning)\n } else {\n for (const [name, value] of Object.entries(part)) {\n variables.push([name, variableValue(name, value)])\n }\n }\n }\n const changed =\n stylesheets.length > 0 ||\n variables.length > 0 ||\n rootFontSize !== undefined\n return {\n backend: changed ? { stylesheets, variables, rootFontSize } : undefined,\n warnings,\n }\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
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;
|
|
9
|
+
/**
|
|
10
|
+
* Resolves an `@rentnerkev/*` CSS import like Node from the importing file
|
|
11
|
+
* and confines it to that package: the resolved real path must be a `.css`
|
|
12
|
+
* file inside the directory of the nearest `package.json` that names the
|
|
13
|
+
* package. Returns the file and that directory, or why it is refused.
|
|
14
|
+
*/
|
|
15
|
+
export declare function resolvePackageImport(specifier: string, importer: string): Promise<ResolvedImport | string>;
|
|
16
|
+
//# sourceMappingURL=package-imports.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { readFile, realpath } from 'node:fs/promises';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { dirname, join, relative, isAbsolute } from 'node:path';
|
|
4
|
+
/** `@rentnerkev/<name>/<path>`; the name as npm allows it. */
|
|
5
|
+
const PACKAGE_SPECIFIER = /^@rentnerkev\/([a-z0-9][a-z0-9._-]*)\/(.+)$/i;
|
|
6
|
+
/** How far up from an imported file its `package.json` may be. */
|
|
7
|
+
const MAX_PACKAGE_LEVELS = 8;
|
|
8
|
+
/** Bytes of a `package.json` that are read to check its name. */
|
|
9
|
+
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
|
+
/**
|
|
19
|
+
* The package and file of an `@rentnerkev/*` import; `undefined` for
|
|
20
|
+
* specifiers with empty, `.` or `..` segments or backslashes, which could
|
|
21
|
+
* leave the package (Node's resolver normalizes them against
|
|
22
|
+
* `node_modules`).
|
|
23
|
+
*/
|
|
24
|
+
export function parsePackageImport(specifier) {
|
|
25
|
+
const match = PACKAGE_SPECIFIER.exec(specifier);
|
|
26
|
+
const name = match?.[1];
|
|
27
|
+
const path = match?.[2];
|
|
28
|
+
if (name === undefined || path === undefined || path.includes('\\')) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
const segments = path.split('/');
|
|
32
|
+
if (segments.some((segment) => segment === '' || segment === '.' || segment === '..')) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
return { name: `@rentnerkev/${name}`, path };
|
|
36
|
+
}
|
|
37
|
+
/** The name in a `package.json`, or `undefined` if it cannot be read. */
|
|
38
|
+
const manifestName = async (directory) => {
|
|
39
|
+
try {
|
|
40
|
+
const text = await readFile(join(directory, 'package.json'), 'utf8');
|
|
41
|
+
if (text.length > MAX_MANIFEST_BYTES)
|
|
42
|
+
return undefined;
|
|
43
|
+
const manifest = JSON.parse(text);
|
|
44
|
+
if (typeof manifest !== 'object' || manifest === null)
|
|
45
|
+
return undefined;
|
|
46
|
+
const name = Reflect.get(manifest, 'name');
|
|
47
|
+
return typeof name === 'string' ? name : undefined;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Resolves an `@rentnerkev/*` CSS import like Node from the importing file
|
|
55
|
+
* and confines it to that package: the resolved real path must be a `.css`
|
|
56
|
+
* file inside the directory of the nearest `package.json` that names the
|
|
57
|
+
* package. Returns the file and that directory, or why it is refused.
|
|
58
|
+
*/
|
|
59
|
+
export async function resolvePackageImport(specifier, importer) {
|
|
60
|
+
const parsed = parsePackageImport(specifier);
|
|
61
|
+
if (parsed === undefined || !parsed.path.toLowerCase().endsWith('.css')) {
|
|
62
|
+
return 'only .css files of @rentnerkev packages are read';
|
|
63
|
+
}
|
|
64
|
+
let file;
|
|
65
|
+
try {
|
|
66
|
+
file = await realpath(createRequire(importer).resolve(specifier));
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return 'the package or file is not installed';
|
|
70
|
+
}
|
|
71
|
+
if (!file.toLowerCase().endsWith('.css')) {
|
|
72
|
+
return 'only .css files of @rentnerkev packages are read';
|
|
73
|
+
}
|
|
74
|
+
let directory = dirname(file);
|
|
75
|
+
for (let level = 0; level < MAX_PACKAGE_LEVELS; level += 1) {
|
|
76
|
+
// oxlint-disable-next-line no-await-in-loop -- each level is checked only when the one below has no matching package.json
|
|
77
|
+
const name = await manifestName(directory);
|
|
78
|
+
if (name !== undefined) {
|
|
79
|
+
return name === parsed.name && isInside(directory, file)
|
|
80
|
+
? { file, root: directory }
|
|
81
|
+
: `it resolves outside the package ${parsed.name}`;
|
|
82
|
+
}
|
|
83
|
+
const parent = dirname(directory);
|
|
84
|
+
if (parent === directory)
|
|
85
|
+
break;
|
|
86
|
+
directory = parent;
|
|
87
|
+
}
|
|
88
|
+
return `it resolves outside the package ${parsed.name}`;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=package-imports.js.map
|
|
@@ -0,0 +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;AACjE,MAAM,kBAAkB,GAAG,GAAG,GAAG,IAAI,CAAA;AAErC,MAAM,QAAQ,GAAG,CAAC,SAAiB,EAAE,IAAY,EAAW,EAAE;IAC1D,MAAM,KAAK,GAAG,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,CAAA;IACvC,OAAO,CACH,KAAK,KAAK,EAAE;QACZ,CAAC,KAAK,KAAK,IAAI;YACX,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC;YACzB,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC;YACxB,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAC1B,CAAA;AACL,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAC9B,SAAiB;IAEjB,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,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AW,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACtE,OAAO,kDAAkD,CAAA;IAC7D,CAAC;IACD,IAAI,IAAY,CAAA;IAChB,IAAI,CAAC;QACD,IAAI,GAAG,MAAM,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAA;IACrE,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,sCAAsC,CAAA;IACjD,CAAC;IACD,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,QAAQ,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,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"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
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;
|
|
4
|
+
/** Nesting of `@import`s below the entry file. */
|
|
5
|
+
export declare const MAX_IMPORT_DEPTH = 16;
|
|
6
|
+
/** Bytes of one file; the engine reads at most 4 MiB of a stylesheet anyway. */
|
|
7
|
+
export declare const MAX_THEME_FILE_BYTES: number;
|
|
8
|
+
/** Bytes of all files of one theme. */
|
|
9
|
+
export declare const MAX_THEME_BYTES: number;
|
|
10
|
+
/** `@import` rules of one file that are followed; the rest are not resolved. */
|
|
11
|
+
export declare const MAX_IMPORTS_PER_FILE = 256;
|
|
12
|
+
/**
|
|
13
|
+
* Reads design tokens from a CSS file and the files it imports, such as the
|
|
14
|
+
* app's Tailwind CSS entry (D-22). Relative `@import`s (`./theme.css`) are
|
|
15
|
+
* followed inside `root` (default: the entry's directory), and imports of
|
|
16
|
+
* `@rentnerkev/*` packages (`@rentnerkev/table/theme.css`) are resolved
|
|
17
|
+
* like Node resolves modules from the importing file and confined to that
|
|
18
|
+
* package. Tailwind itself and `@rentnerkev/pdf/tailwind.css` are built
|
|
19
|
+
* into the engine; other packages and URLs are never read. Only regular
|
|
20
|
+
* `.css` files are read, each file once, with limits on file count,
|
|
21
|
+
* imports, depth and size.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { themeFromCssFile } from '@rentnerkev/pdf/node'
|
|
25
|
+
*
|
|
26
|
+
* const engine = await createEngine({
|
|
27
|
+
* theme: await themeFromCssFile('src/styles.css'),
|
|
28
|
+
* })
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* The entry file must exist; problems with imported files and the CSS are
|
|
32
|
+
* warnings (`theme.warnings`, `engine.themeWarnings`).
|
|
33
|
+
*/
|
|
34
|
+
export declare function themeFromCssFile(path: string, options?: ThemeFromCssFileOptions): Promise<Theme>;
|
|
35
|
+
//# sourceMappingURL=theme-from-css-file.d.ts.map
|
|
@@ -0,0 +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"}
|