inkoxide 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,7 +19,7 @@ automatically (as optional dependencies) for the current platform:
19
19
  | macOS x64 | `@inkoxide/darwin-x64` |
20
20
  | Windows x64 | `@inkoxide/win32-x64-msvc` |
21
21
 
22
- Linux glibc builds need glibc 2.35 or newer. Node.js 18 or newer.
22
+ Linux glibc builds need glibc 2.35 or newer. Node.js 22 or newer; ES modules only.
23
23
  Other platforms: build from source with `scripts/build-node.sh`, which
24
24
  puts `inkoxide.<platform>.node` next to the loader.
25
25
 
@@ -52,5 +52,9 @@ try {
52
52
  console.log(validate(JSON.stringify(doc)));
53
53
  ```
54
54
 
55
- Options, defaults and error codes are typed in `index.d.ts` and described
56
- in `docs/API.md`. Schema reference: `docs/SCHEMA.md` and `schema/EXAMPLES.md`.
55
+ Options, defaults and error codes are typed in `index.d.ts` and described in the
56
+ [API reference](https://github.com/eddiesr93/inkoxide/blob/main/docs/API.md). The document
57
+ format is in the [schema reference](https://github.com/eddiesr93/inkoxide/blob/main/docs/SCHEMA.md)
58
+ and the [example documents](https://github.com/eddiesr93/inkoxide/blob/main/packages/schema/EXAMPLES.md).
59
+ To write documents as React components, use
60
+ [`@inkoxide/render`](https://www.npmjs.com/package/@inkoxide/render).
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // Public contract of the `inkoxide` npm package. Hand-written; keep in
2
- // sync with crates/node/src/lib.rs and npm/index.js.
2
+ // sync with crates/node/src/lib.rs and index.js.
3
3
 
4
4
  /**
5
5
  * Codes of document problems, from `validate` and from a failed `render`
package/index.js CHANGED
@@ -1,9 +1,12 @@
1
- 'use strict';
2
1
  // Loader for the native binding plus the JS-side error type. Hand-written
3
2
  // and reviewed together with index.d.ts (the public contract).
4
3
 
5
- const { existsSync } = require('node:fs');
6
- const { join } = require('node:path');
4
+ import { existsSync } from 'node:fs';
5
+ import { createRequire } from 'node:module';
6
+ import { fileURLToPath } from 'node:url';
7
+
8
+ // Native addons (.node files) load through require, also from an ES module.
9
+ const require = createRequire(import.meta.url);
7
10
 
8
11
  function isMusl() {
9
12
  if (process.platform !== 'linux') return false;
@@ -24,7 +27,7 @@ function platformTriple() {
24
27
 
25
28
  function loadNative() {
26
29
  const triple = platformTriple();
27
- const local = join(__dirname, `inkoxide.${triple}.node`);
30
+ const local = fileURLToPath(new URL(`inkoxide.${triple}.node`, import.meta.url));
28
31
  if (existsSync(local)) return require(local);
29
32
  try {
30
33
  return require(`@inkoxide/${triple}`);
@@ -38,7 +41,7 @@ function loadNative() {
38
41
 
39
42
  const native = loadNative();
40
43
 
41
- class InkoxideError extends Error {
44
+ export class InkoxideError extends Error {
42
45
  constructor(code, path, message) {
43
46
  super(path ? `${code} at ${path}: ${message}` : `${code}: ${message}`);
44
47
  this.name = 'InkoxideError';
@@ -101,26 +104,22 @@ function toUint8Array(b) {
101
104
  return new Uint8Array(b.buffer, b.byteOffset, b.byteLength);
102
105
  }
103
106
 
104
- // Plain `exports.x =` assignments so ESM `import { render } from 'inkoxide'`
105
- // sees named exports.
106
- exports.InkoxideError = InkoxideError;
107
- exports.registerFont = (id, data) => call(native.registerFont, [id, data]);
108
- exports.unregisterFont = (id) => call(native.unregisterFont, [id]);
109
- exports.registerHyphenationPatterns = (lang, data) =>
107
+ export const registerFont = (id, data) => call(native.registerFont, [id, data]);
108
+ export const unregisterFont = (id) => call(native.unregisterFont, [id]);
109
+ export const registerHyphenationPatterns = (lang, data) =>
110
110
  call(native.registerHyphenationPatterns, [lang, data]);
111
- exports.unregisterHyphenationPatterns = (lang) =>
112
- call(native.unregisterHyphenationPatterns, [lang]);
113
- exports.validate = (doc, format, images) =>
111
+ export const unregisterHyphenationPatterns = (lang) => call(native.unregisterHyphenationPatterns, [lang]);
112
+ export const validate = (doc, format, images) =>
114
113
  call(native.validate, [doc, format ?? undefined, images ?? undefined]);
115
- exports.render = async (doc, options) => {
114
+ export const render = async (doc, options) => {
116
115
  try {
117
116
  return toUint8Array(await native.render(doc, options ?? undefined));
118
117
  } catch (e) {
119
118
  throw wrapError(e);
120
119
  }
121
120
  };
122
- exports.renderSync = (doc, options) =>
121
+ export const renderSync = (doc, options) =>
123
122
  toUint8Array(call(native.renderSync, [doc, options ?? undefined]));
124
- exports.version = () => call(native.version, []);
125
- // Test hook (not public API): a panic behind the native boundary.
126
- Object.defineProperty(exports, '__testPanic', { value: () => call(native.__testPanic, []) });
123
+ export const version = () => call(native.version, []);
124
+ // Test hook, not public API and not in index.d.ts: a panic behind the native boundary.
125
+ export const __testPanic = () => call(native.__testPanic, []);
package/package.json CHANGED
@@ -1,27 +1,36 @@
1
1
  {
2
2
  "name": "inkoxide",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Native PDF layout and rendering engine: declarative document tree in, PDF bytes out.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "git+https://github.com/eddiesr93/inkoxide.git"
8
+ "url": "git+https://github.com/eddiesr93/inkoxide.git",
9
+ "directory": "packages/inkoxide"
9
10
  },
11
+ "type": "module",
10
12
  "main": "index.js",
11
13
  "types": "index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./index.d.ts",
17
+ "default": "./index.js"
18
+ },
19
+ "./package.json": "./package.json"
20
+ },
12
21
  "files": [
13
22
  "index.js",
14
23
  "index.d.ts"
15
24
  ],
16
25
  "engines": {
17
- "node": ">= 18"
26
+ "node": ">=22"
18
27
  },
19
28
  "optionalDependencies": {
20
- "@inkoxide/linux-x64-gnu": "0.1.0",
21
- "@inkoxide/linux-x64-musl": "0.1.0",
22
- "@inkoxide/linux-arm64-gnu": "0.1.0",
23
- "@inkoxide/darwin-arm64": "0.1.0",
24
- "@inkoxide/darwin-x64": "0.1.0",
25
- "@inkoxide/win32-x64-msvc": "0.1.0"
29
+ "@inkoxide/linux-x64-gnu": "0.2.0",
30
+ "@inkoxide/linux-x64-musl": "0.2.0",
31
+ "@inkoxide/linux-arm64-gnu": "0.2.0",
32
+ "@inkoxide/darwin-arm64": "0.2.0",
33
+ "@inkoxide/darwin-x64": "0.2.0",
34
+ "@inkoxide/win32-x64-msvc": "0.2.0"
26
35
  }
27
36
  }