@rentnerkev/pdf 0.1.1 → 1.0.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/README.md CHANGED
@@ -10,14 +10,13 @@
10
10
  <a href="https://github.com/RentnerKev/RentnerPDF/actions/workflows/ci.yml"><img src="https://github.com/RentnerKev/RentnerPDF/actions/workflows/ci.yml/badge.svg?branch=main" alt="CI"></a>
11
11
  <a href="https://github.com/RentnerKev/RentnerPDF/actions/workflows/codeql.yml"><img src="https://github.com/RentnerKev/RentnerPDF/actions/workflows/codeql.yml/badge.svg?branch=main" alt="CodeQL"></a>
12
12
  <a href="https://scorecard.dev/viewer/?uri=github.com/RentnerKev/RentnerPDF"><img src="https://api.scorecard.dev/projects/github.com/RentnerKev/RentnerPDF/badge" alt="OpenSSF Scorecard"></a>
13
- <img src="https://img.shields.io/badge/status-pre--release-orange" alt="Status: pre-release">
14
13
  <a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" alt="MIT license"></a>
15
14
  </p>
16
15
 
17
16
  RentnerPDF is a PDF engine for JavaScript and TypeScript with a Rust core. Describe documents with React-style components and Tailwind-style `className` utilities; the engine lays them out with real pagination and writes standards-ready PDFs – natively on Node.js and Bun, and via WebAssembly on macOS and in browsers.
18
17
 
19
18
  > [!IMPORTANT]
20
- > RentnerPDF `0.1.1` is the candidate for the first npm release. One package, `@rentnerkev/pdf`, includes the TypeScript API, six native bindings and WebAssembly. The TypeScript API and IR v1 freeze with `1.0.0`. The worker engine, React preview, Vite plugin and `renderToStream()` remain experimental until promoted. [Development](#development) · [Install](docs/usage.md#install) · [Roadmap](docs/planning/10-roadmap.md)
19
+ > RentnerPDF `1.0.0` stabilizes the documented TypeScript API and IR v1 under SemVer. The npm package `@rentnerkev/pdf` includes six native bindings and WebAssembly. The worker engine, React preview, Vite plugin and `renderToStream()` are experimental. [Development](#development) · [Install](docs/usage.md#install) · [1.1.0 milestone](https://github.com/RentnerKev/RentnerPDF/milestone/1)
21
20
 
22
21
  ## Features
23
22
 
@@ -96,10 +95,27 @@ await writeFile('invoice.pdf', pdf)
96
95
  | [Recipes](docs/recipes/README.md) | Node.js, Bun, TanStack Start, Next.js, ZUGFeRD/Factur-X invoices |
97
96
  | [Tailwind support matrix](docs/tailwind-support.md) | Every utility and what it does on paper |
98
97
  | [Benchmarks](docs/benchmarks.md) | Every scenario against React-PDF and pdfmake, how to reproduce it; re-measured weekly |
99
- | [Planning](docs/planning/README.md) | Architecture, decisions and roadmap |
98
+ | [IR versioning](docs/usage.md#ir-versioning) | IR compatibility, validation, and evolution |
99
+ | [Local documentation for tools](docs/usage.md#local-documentation-for-tools) | `@rentnerkev/pdf/ai`: guides and declarations of the installed version for AI agents |
100
100
 
101
101
  The [playground](docs/usage.md#playground) is a local JSX editor with a live PDF preview: `bun run build:wasm`, then `bun run playground:dev`.
102
102
 
103
+ ## AI and MCP access
104
+
105
+ AI agents and local tools read the installed version through `@rentnerkev/pdf/ai`: the README, the usage guide, package metadata and the public TypeScript declarations, without loading an engine or React and without network access. [Local documentation for tools](docs/usage.md#local-documentation-for-tools) shows the five read-only helpers. Keep the entry in Node.js or Bun tooling.
106
+
107
+ The [RentnerPackages website](https://packages.rentner.dev/docs/pdf) also serves the RentnerPDF documentation through a public read-only MCP server and [llms.txt](https://packages.rentner.dev/llms.txt). It needs no account and uses the website's documentation snapshot; prefer the installed `/ai` entry when the versions differ.
108
+
109
+ ```json
110
+ {
111
+ "mcpServers": {
112
+ "rentnerPackages": {
113
+ "url": "https://packages.rentner.dev/mcp"
114
+ }
115
+ }
116
+ }
117
+ ```
118
+
103
119
  ## Development
104
120
 
105
121
  Requirements: [Bun](https://bun.com) 1.4.5 and [rustup](https://rustup.rs). The Rust toolchain is pinned in `core/rust-toolchain.toml`.
@@ -122,7 +138,6 @@ The WebAssembly tests load the local build from `bun run build:wasm` (wasm-bindg
122
138
  | `core/` | Rust workspace: `rentnerpdf` (engine), `rentnerpdf-napi` (Node-API), `rentnerpdf-wasm` (WebAssembly) |
123
139
  | `.github/` | Workflows, automation scripts and their tests |
124
140
  | `docs` | Usage guide, migration guides, recipes, Tailwind support matrix, benchmarks |
125
- | `docs/planning` | Architecture and planning documents |
126
141
 
127
142
  See [CONTRIBUTING](.github/CONTRIBUTING.md) for the full workflow.
128
143
 
package/dist/ai.d.ts ADDED
@@ -0,0 +1,53 @@
1
+ export interface PackageInfo {
2
+ name: string;
3
+ version: string;
4
+ description: string;
5
+ license: string;
6
+ homepage: string;
7
+ repository: {
8
+ type: string;
9
+ url: string;
10
+ };
11
+ exports: Record<string, string | {
12
+ types?: string;
13
+ import?: string;
14
+ default?: string;
15
+ }>;
16
+ peerDependencies: Record<string, string>;
17
+ }
18
+ export interface PackageDocument {
19
+ path: string;
20
+ content: string;
21
+ }
22
+ export interface PackageApi {
23
+ package: string;
24
+ version: string;
25
+ subpaths: Record<string, string>;
26
+ declarations: PackageDocument[];
27
+ }
28
+ export interface PackageSearchMatch {
29
+ path: string;
30
+ line: number;
31
+ text: string;
32
+ }
33
+ export interface PackageExample {
34
+ language: string;
35
+ code: string;
36
+ }
37
+ /** Read installed-package metadata without importing its UI entry point. */
38
+ export declare function getPackageInfo(): PackageInfo;
39
+ /** Only these two explicitly packaged documents can be read. */
40
+ export declare function getPackageDocumentation(document?: 'readme' | 'usage'): PackageDocument;
41
+ /** Return export entry declarations and their local declaration dependencies.
42
+ * The AI entry itself is excluded. No module is executed and callers cannot
43
+ * supply file paths. Symbols must be exported by a selected public entry.
44
+ */
45
+ export declare function getPackageApi(options?: {
46
+ subpath?: string;
47
+ symbol?: string;
48
+ }): PackageApi;
49
+ /** Literal, case-insensitive search of the packaged guides. */
50
+ export declare function searchPackageDocumentation(query: string): PackageSearchMatch[];
51
+ /** Code examples come directly from the installed version's usage guide. */
52
+ export declare function getPackageExamples(): PackageExample[];
53
+ //# sourceMappingURL=ai.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai.d.ts","sourceRoot":"","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E,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAO,GACpD,UAAU,CAoGZ;AAED,+DAA+D;AAC/D,wBAAgB,0BAA0B,CACtC,KAAK,EAAE,MAAM,GACd,kBAAkB,EAAE,CAatB;AAED,4EAA4E;AAC5E,wBAAgB,kBAAkB,IAAI,cAAc,EAAE,CASrD"}
package/dist/ai.js ADDED
@@ -0,0 +1,139 @@
1
+ import { readFileSync, realpathSync } from 'node:fs';
2
+ import { isAbsolute, relative, sep } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ const packageRoot = new URL('../', import.meta.url);
5
+ /** Read installed-package metadata without importing its UI entry point. */
6
+ export function getPackageInfo() {
7
+ const manifest = JSON.parse(readFileSync(new URL('package.json', packageRoot), 'utf8'));
8
+ return {
9
+ name: manifest.name,
10
+ version: manifest.version,
11
+ description: manifest.description,
12
+ license: manifest.license,
13
+ homepage: manifest.homepage,
14
+ repository: manifest.repository,
15
+ exports: manifest.exports,
16
+ peerDependencies: manifest.peerDependencies,
17
+ };
18
+ }
19
+ /** Only these two explicitly packaged documents can be read. */
20
+ export function getPackageDocumentation(document = 'usage') {
21
+ if (document !== 'readme' && document !== 'usage') {
22
+ throw new Error('Unknown package document');
23
+ }
24
+ const path = document === 'readme' ? 'README.md' : 'docs/usage.md';
25
+ return { path, content: readFileSync(new URL(path, packageRoot), 'utf8') };
26
+ }
27
+ /** Return export entry declarations and their local declaration dependencies.
28
+ * The AI entry itself is excluded. No module is executed and callers cannot
29
+ * supply file paths. Symbols must be exported by a selected public entry.
30
+ */
31
+ export function getPackageApi(options = {}) {
32
+ const info = getPackageInfo();
33
+ const subpaths = {};
34
+ for (const [subpath, entry] of Object.entries(info.exports)) {
35
+ if (subpath !== './ai' && typeof entry !== 'string' && entry.types) {
36
+ subpaths[subpath] = entry.types;
37
+ }
38
+ }
39
+ if (options.subpath !== undefined &&
40
+ !Object.hasOwn(subpaths, options.subpath)) {
41
+ throw new Error(`Unknown public subpath: ${options.subpath}`);
42
+ }
43
+ if (options.symbol !== undefined &&
44
+ !/^[A-Za-z_$][\w$]*$/.test(options.symbol)) {
45
+ throw new Error('Invalid public symbol');
46
+ }
47
+ const selected = options.subpath === undefined
48
+ ? subpaths
49
+ : { [options.subpath]: subpaths[options.subpath] };
50
+ const declarations = new Map();
51
+ const publicNames = new Set();
52
+ function readDeclaration(path) {
53
+ const url = new URL(path, packageRoot);
54
+ const distRoot = new URL('dist/', packageRoot).href;
55
+ if (!url.href.startsWith(distRoot) || !url.pathname.endsWith('.d.ts')) {
56
+ throw new Error('Declaration must remain inside packaged dist');
57
+ }
58
+ const location = relative(realpathSync(new URL('dist/', packageRoot)), realpathSync(fileURLToPath(url)));
59
+ if (isAbsolute(location) ||
60
+ location === '..' ||
61
+ location.startsWith('..' + sep)) {
62
+ throw new Error('Declaration must remain inside packaged dist');
63
+ }
64
+ const existing = declarations.get(url.href);
65
+ if (existing)
66
+ return existing.content;
67
+ const content = readFileSync(url, 'utf8');
68
+ declarations.set(url.href, {
69
+ path: decodeURIComponent(url.href.slice(packageRoot.href.length)),
70
+ content,
71
+ });
72
+ for (const match of content.matchAll(/(?:from\s*|import\s*\()(['"])(\.[^'"]+)\1/g)) {
73
+ const target = match[2].replace(/\.(?:tsx?|jsx?)$/, '.d.ts');
74
+ readDeclaration(new URL(target, url).href);
75
+ }
76
+ return content;
77
+ }
78
+ const publicEntries = new Set();
79
+ function collectPublicNames(path) {
80
+ const url = new URL(path, packageRoot);
81
+ if (publicEntries.has(url.href))
82
+ return;
83
+ publicEntries.add(url.href);
84
+ const content = readDeclaration(path);
85
+ for (const match of content.matchAll(/export\s+(?:declare\s+)?(?:abstract\s+)?(?:const|let|var|function|class|interface|type|enum)\s+([\w$]+)/g)) {
86
+ publicNames.add(match[1]);
87
+ }
88
+ for (const match of content.matchAll(/export\s+(?:type\s+)?\{([^}]+)\}/g)) {
89
+ for (const item of match[1].split(',')) {
90
+ const name = item
91
+ .trim()
92
+ .replace(/^type\s+/, '')
93
+ .split(/\s+as\s+/)
94
+ .at(-1);
95
+ if (name)
96
+ publicNames.add(name.trim());
97
+ }
98
+ }
99
+ for (const match of content.matchAll(/export\s+(?:type\s+)?\*\s+from\s*(['"])(\.[^'"]+)\1/g)) {
100
+ collectPublicNames(new URL(match[2].replace(/\.(?:tsx?|jsx?)$/, '.d.ts'), url)
101
+ .href);
102
+ }
103
+ }
104
+ for (const path of Object.values(selected))
105
+ collectPublicNames(path);
106
+ if (options.symbol !== undefined && !publicNames.has(options.symbol)) {
107
+ throw new Error(`Unknown public symbol: ${options.symbol}`);
108
+ }
109
+ return {
110
+ package: info.name,
111
+ version: info.version,
112
+ subpaths: selected,
113
+ declarations: [...declarations.values()],
114
+ };
115
+ }
116
+ /** Literal, case-insensitive search of the packaged guides. */
117
+ export function searchPackageDocumentation(query) {
118
+ const needle = query.trim().toLowerCase();
119
+ if (!needle)
120
+ return [];
121
+ return ['readme', 'usage'].flatMap((name) => {
122
+ const document = getPackageDocumentation(name);
123
+ return document.content
124
+ .split('\n')
125
+ .flatMap((text, index) => text.toLowerCase().includes(needle)
126
+ ? [{ path: document.path, line: index + 1, text }]
127
+ : []);
128
+ });
129
+ }
130
+ /** Code examples come directly from the installed version's usage guide. */
131
+ export function getPackageExamples() {
132
+ return [
133
+ ...getPackageDocumentation().content.matchAll(/```([^\n]*)\n([\s\S]*?)```/g),
134
+ ].map((match) => ({
135
+ language: match[1].trim(),
136
+ code: match[2].trimEnd(),
137
+ }));
138
+ }
139
+ //# sourceMappingURL=ai.js.map
package/dist/ai.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai.js","sourceRoot":"","sources":["../web/src/ai.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACpD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AACrD,OAAO,EAAE,aAA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ACJ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACd,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAE,CAAC,IAAI,EAAE;QAC1B,IAAI,EAAE,KAAK,CAAC,CAAC,CAAE,CAAC,OAAO,EAAE;KAC5B,CAAC,CAAC,CAAA;AACP,CAAC","sourcesContent":["import { readFileSync, realpathSync } from 'node:fs'\nimport { isAbsolute, relative, sep } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nexport interface PackageInfo {\n name: string\n version: string\n description: string\n license: string\n homepage: string\n repository: { type: string; url: string }\n exports: Record<\n string,\n string | { types?: string; import?: string; default?: string }\n >\n peerDependencies: Record<string, string>\n}\n\nexport interface PackageDocument {\n path: string\n content: string\n}\n\nexport interface PackageApi {\n package: string\n version: string\n subpaths: Record<string, string>\n declarations: PackageDocument[]\n}\n\nexport interface PackageSearchMatch {\n path: string\n line: number\n text: string\n}\n\nexport interface PackageExample {\n language: string\n code: string\n}\n\nconst packageRoot = new URL('../', import.meta.url)\n\n/** Read installed-package metadata without importing its UI entry point. */\nexport function getPackageInfo(): PackageInfo {\n const manifest = JSON.parse(\n readFileSync(new URL('package.json', packageRoot), 'utf8'),\n ) as PackageInfo\n return {\n name: manifest.name,\n version: manifest.version,\n description: manifest.description,\n license: manifest.license,\n homepage: manifest.homepage,\n repository: manifest.repository,\n exports: manifest.exports,\n peerDependencies: manifest.peerDependencies,\n }\n}\n\n/** Only these two explicitly packaged documents can be read. */\nexport function getPackageDocumentation(\n document: 'readme' | 'usage' = 'usage',\n): PackageDocument {\n if (document !== 'readme' && document !== 'usage') {\n throw new Error('Unknown package document')\n }\n const path = document === 'readme' ? 'README.md' : 'docs/usage.md'\n return { path, content: readFileSync(new URL(path, packageRoot), 'utf8') }\n}\n\n/** Return export entry declarations and their local declaration dependencies.\n * The AI entry itself is excluded. No module is executed and callers cannot\n * supply file paths. Symbols must be exported by a selected public entry.\n */\nexport function getPackageApi(\n options: { subpath?: string; symbol?: string } = {},\n): PackageApi {\n const info = getPackageInfo()\n const subpaths: Record<string, string> = {}\n for (const [subpath, entry] of Object.entries(info.exports)) {\n if (subpath !== './ai' && typeof entry !== 'string' && entry.types) {\n subpaths[subpath] = entry.types\n }\n }\n if (\n options.subpath !== undefined &&\n !Object.hasOwn(subpaths, options.subpath)\n ) {\n throw new Error(`Unknown public subpath: ${options.subpath}`)\n }\n if (\n options.symbol !== undefined &&\n !/^[A-Za-z_$][\\w$]*$/.test(options.symbol)\n ) {\n throw new Error('Invalid public symbol')\n }\n const selected =\n options.subpath === undefined\n ? subpaths\n : { [options.subpath]: subpaths[options.subpath]! }\n const declarations = new Map<string, PackageDocument>()\n const publicNames = new Set<string>()\n function readDeclaration(path: string): string {\n const url = new URL(path, packageRoot)\n const distRoot = new URL('dist/', packageRoot).href\n if (!url.href.startsWith(distRoot) || !url.pathname.endsWith('.d.ts')) {\n throw new Error('Declaration must remain inside packaged dist')\n }\n const location = relative(\n realpathSync(new URL('dist/', packageRoot)),\n realpathSync(fileURLToPath(url)),\n )\n if (\n isAbsolute(location) ||\n location === '..' ||\n location.startsWith('..' + sep)\n ) {\n throw new Error('Declaration must remain inside packaged dist')\n }\n const existing = declarations.get(url.href)\n if (existing) return existing.content\n const content = readFileSync(url, 'utf8')\n declarations.set(url.href, {\n path: decodeURIComponent(url.href.slice(packageRoot.href.length)),\n content,\n })\n for (const match of content.matchAll(\n /(?:from\\s*|import\\s*\\()(['\"])(\\.[^'\"]+)\\1/g,\n )) {\n const target = match[2]!.replace(/\\.(?:tsx?|jsx?)$/, '.d.ts')\n readDeclaration(new URL(target, url).href)\n }\n return content\n }\n const publicEntries = new Set<string>()\n function collectPublicNames(path: string): void {\n const url = new URL(path, packageRoot)\n if (publicEntries.has(url.href)) return\n publicEntries.add(url.href)\n const content = readDeclaration(path)\n for (const match of content.matchAll(\n /export\\s+(?:declare\\s+)?(?:abstract\\s+)?(?:const|let|var|function|class|interface|type|enum)\\s+([\\w$]+)/g,\n )) {\n publicNames.add(match[1]!)\n }\n for (const match of content.matchAll(\n /export\\s+(?:type\\s+)?\\{([^}]+)\\}/g,\n )) {\n for (const item of match[1]!.split(',')) {\n const name = item\n .trim()\n .replace(/^type\\s+/, '')\n .split(/\\s+as\\s+/)\n .at(-1)\n if (name) publicNames.add(name.trim())\n }\n }\n for (const match of content.matchAll(\n /export\\s+(?:type\\s+)?\\*\\s+from\\s*(['\"])(\\.[^'\"]+)\\1/g,\n )) {\n collectPublicNames(\n new URL(match[2]!.replace(/\\.(?:tsx?|jsx?)$/, '.d.ts'), url)\n .href,\n )\n }\n }\n for (const path of Object.values(selected)) collectPublicNames(path)\n if (options.symbol !== undefined && !publicNames.has(options.symbol)) {\n throw new Error(`Unknown public symbol: ${options.symbol}`)\n }\n return {\n package: info.name,\n version: info.version,\n subpaths: selected,\n declarations: [...declarations.values()],\n }\n}\n\n/** Literal, case-insensitive search of the packaged guides. */\nexport function searchPackageDocumentation(\n query: string,\n): PackageSearchMatch[] {\n const needle = query.trim().toLowerCase()\n if (!needle) return []\n return (['readme', 'usage'] as const).flatMap((name) => {\n const document = getPackageDocumentation(name)\n return document.content\n .split('\\n')\n .flatMap((text, index) =>\n text.toLowerCase().includes(needle)\n ? [{ path: document.path, line: index + 1, text }]\n : [],\n )\n })\n}\n\n/** Code examples come directly from the installed version's usage guide. */\nexport function getPackageExamples(): PackageExample[] {\n return [\n ...getPackageDocumentation().content.matchAll(\n /```([^\\n]*)\\n([\\s\\S]*?)```/g,\n ),\n ].map((match) => ({\n language: match[1]!.trim(),\n code: match[2]!.trimEnd(),\n }))\n}\n"]}