takumi-pdf 0.10.0 → 0.11.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 +28 -16
- package/bundlers/node.d.ts +1 -0
- package/dist/export.cjs +54 -44
- package/dist/export.d.cts +2 -1
- package/dist/export.d.mts +2 -1
- package/dist/export.mjs +53 -46
- package/dist/primitives.cjs +48 -0
- package/dist/primitives.d.cts +32 -0
- package/dist/primitives.d.mts +32 -0
- package/dist/primitives.mjs +45 -0
- package/package.json +12 -3
- package/pkg/takumi_pdf_wasm_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ bun add takumi-pdf
|
|
|
30
30
|
```tsx
|
|
31
31
|
import { writeFile } from "node:fs/promises";
|
|
32
32
|
import { googleFonts } from "@takumi-rs/helpers";
|
|
33
|
-
import { render } from "takumi-pdf";
|
|
33
|
+
import { PageNumber, TotalPages, render } from "takumi-pdf";
|
|
34
34
|
|
|
35
35
|
const pdf = await render(
|
|
36
36
|
<main tw="flex flex-col gap-4">
|
|
@@ -45,7 +45,7 @@ const pdf = await render(
|
|
|
45
45
|
fonts: await googleFonts(["Inter"]),
|
|
46
46
|
footer: (
|
|
47
47
|
<div tw="flex w-full justify-center text-[10px] text-gray-500">
|
|
48
|
-
Page <
|
|
48
|
+
Page <PageNumber /> of <TotalPages />
|
|
49
49
|
</div>
|
|
50
50
|
),
|
|
51
51
|
},
|
|
@@ -74,28 +74,22 @@ const pdf = await render(report, {
|
|
|
74
74
|
|
|
75
75
|
## Headers and footers
|
|
76
76
|
|
|
77
|
-
Headers and footers repeat on every page.
|
|
77
|
+
Headers and footers repeat on every page. `<PageNumber />` and `<TotalPages />` place the counters; the `format` prop picks a CSS counter style.
|
|
78
78
|
|
|
79
79
|
```tsx
|
|
80
|
+
import { PageNumber, TotalPages } from "takumi-pdf";
|
|
81
|
+
|
|
80
82
|
const pdf = await render(report, {
|
|
81
83
|
footer: (
|
|
82
84
|
<div style={{ fontSize: 12 }}>
|
|
83
|
-
|
|
85
|
+
第 <PageNumber format="trad-chinese-informal" /> 頁,共{" "}
|
|
86
|
+
<TotalPages format="trad-chinese-informal" /> 頁
|
|
84
87
|
</div>
|
|
85
88
|
),
|
|
86
89
|
});
|
|
87
90
|
```
|
|
88
91
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
```tsx
|
|
92
|
-
footer: (
|
|
93
|
-
<div style={{ fontSize: 12 }}>
|
|
94
|
-
第 <span className="pageNumber trad-chinese-informal" /> 頁,共{" "}
|
|
95
|
-
<span className="totalPages trad-chinese-informal" /> 頁
|
|
96
|
-
</div>
|
|
97
|
-
),
|
|
98
|
-
```
|
|
92
|
+
The primitives render class hooks, the same `pageNumber` / `totalPages` names Chromium's print templates use, so HTML input writes `<span class="pageNumber"></span>` directly.
|
|
99
93
|
|
|
100
94
|
| Counter style | Example |
|
|
101
95
|
| ------------------------------------------- | ------------- |
|
|
@@ -166,9 +160,27 @@ const pdf = await render(
|
|
|
166
160
|
| `break-inside: avoid` | Keeps the element on one page when it fits. |
|
|
167
161
|
| `box-decoration-break: clone` | Repeats borders and backgrounds on every page fragment. |
|
|
168
162
|
|
|
163
|
+
## Tables
|
|
164
|
+
|
|
165
|
+
`<table>` markup lays out on shared column tracks, so column x positions stay identical across pages. A `<thead>` paints again at the top of every page its table continues onto, when it is at most a quarter of the page tall and no header cell spans into the body.
|
|
166
|
+
|
|
167
|
+
```tsx
|
|
168
|
+
const pdf = await render(
|
|
169
|
+
<table>
|
|
170
|
+
<thead>
|
|
171
|
+
<tr>
|
|
172
|
+
<th>Name</th>
|
|
173
|
+
<th>Qty</th>
|
|
174
|
+
</tr>
|
|
175
|
+
</thead>
|
|
176
|
+
<tbody>{rows}</tbody>
|
|
177
|
+
</table>,
|
|
178
|
+
);
|
|
179
|
+
```
|
|
180
|
+
|
|
169
181
|
## Links, outline, and metadata
|
|
170
182
|
|
|
171
|
-
Anchors with an `href` become clickable link annotations. `outline: true` builds PDF bookmarks from `h1` through `h6` headings. `metadata` fills the document properties:
|
|
183
|
+
Anchors with an `href` become clickable link annotations. `<TargetPageNumber />` prints the page a link's target lands on, which is what a table of contents needs. `outline: true` builds PDF bookmarks from `h1` through `h6` headings. `metadata` fills the document properties:
|
|
172
184
|
|
|
173
185
|
```tsx
|
|
174
186
|
const pdf = await render(report, {
|
|
@@ -188,7 +200,7 @@ Omit `metadata` to keep output byte-identical across runs.
|
|
|
188
200
|
|
|
189
201
|
Output is **tagged by default**: HTML semantics (`h1` through `h6`, `p`, `img` with `alt`, `a`, lists) become a PDF structure tree, like Chromium's print-to-PDF. Set `tagged: "ua1"` to validate against PDF/UA-1, or `tagged: false` to drop the tree when file size matters more than accessibility.
|
|
190
202
|
|
|
191
|
-
`<table>` markup
|
|
203
|
+
`<table>` markup lays out and paints, but carries no `Table` structure elements yet.
|
|
192
204
|
|
|
193
205
|
`pdfa` renders archival output. Validation runs during rendering. A document that cannot conform fails with the violated rule instead of writing a broken file. Every level, and PDF/UA-1, passes [veraPDF](https://verapdf.org).
|
|
194
206
|
|
package/bundlers/node.d.ts
CHANGED
package/dist/export.cjs
CHANGED
|
@@ -2,6 +2,7 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
+
const require_primitives = require("./primitives.cjs");
|
|
5
6
|
let _takumi_rs_helpers_html = require("@takumi-rs/helpers/html");
|
|
6
7
|
let _takumi_rs_helpers_jsx = require("@takumi-rs/helpers/jsx");
|
|
7
8
|
let _takumi_rs_helpers_renderer = require("@takumi-rs/helpers/renderer");
|
|
@@ -135,10 +136,10 @@ function __wbg_get_imports() {
|
|
|
135
136
|
__proto__: null,
|
|
136
137
|
"./takumi_pdf_wasm_bg.js": {
|
|
137
138
|
__proto__: null,
|
|
138
|
-
|
|
139
|
+
__wbg_Error_408e67f47ca7b58b: function(arg0, arg1) {
|
|
139
140
|
return addHeapObject(Error(getStringFromWasm0(arg0, arg1)));
|
|
140
141
|
},
|
|
141
|
-
|
|
142
|
+
__wbg_Number_3890faa6d3ff057d: function(arg0) {
|
|
142
143
|
return Number(getObject(arg0));
|
|
143
144
|
},
|
|
144
145
|
__wbg_String_8564e559799eccda: function(arg0, arg1) {
|
|
@@ -147,55 +148,55 @@ function __wbg_get_imports() {
|
|
|
147
148
|
getDataViewMemory0().setInt32(arg0 + 4, len1, true);
|
|
148
149
|
getDataViewMemory0().setInt32(arg0 + 0, ptr1, true);
|
|
149
150
|
},
|
|
150
|
-
|
|
151
|
+
__wbg___wbindgen_bigint_get_as_i64_c4ecf48528083721: function(arg0, arg1) {
|
|
151
152
|
const v = getObject(arg1);
|
|
152
153
|
const ret = typeof v === "bigint" ? v : void 0;
|
|
153
154
|
getDataViewMemory0().setBigInt64(arg0 + 8, isLikeNone(ret) ? BigInt(0) : ret, true);
|
|
154
155
|
getDataViewMemory0().setInt32(arg0 + 0, !isLikeNone(ret), true);
|
|
155
156
|
},
|
|
156
|
-
|
|
157
|
+
__wbg___wbindgen_boolean_get_c9c83ebd41b34df3: function(arg0) {
|
|
157
158
|
const v = getObject(arg0);
|
|
158
159
|
const ret = typeof v === "boolean" ? v : void 0;
|
|
159
160
|
return isLikeNone(ret) ? 16777215 : ret ? 1 : 0;
|
|
160
161
|
},
|
|
161
|
-
|
|
162
|
+
__wbg___wbindgen_debug_string_a57024b9c6e4a48b: function(arg0, arg1) {
|
|
162
163
|
const ptr1 = passStringToWasm0(debugString(getObject(arg1)), wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
163
164
|
const len1 = WASM_VECTOR_LEN;
|
|
164
165
|
getDataViewMemory0().setInt32(arg0 + 4, len1, true);
|
|
165
166
|
getDataViewMemory0().setInt32(arg0 + 0, ptr1, true);
|
|
166
167
|
},
|
|
167
|
-
|
|
168
|
+
__wbg___wbindgen_in_ac983077f137f2e6: function(arg0, arg1) {
|
|
168
169
|
return getObject(arg0) in getObject(arg1);
|
|
169
170
|
},
|
|
170
|
-
|
|
171
|
+
__wbg___wbindgen_is_bigint_8ffbbef442139384: function(arg0) {
|
|
171
172
|
return typeof getObject(arg0) === "bigint";
|
|
172
173
|
},
|
|
173
|
-
|
|
174
|
+
__wbg___wbindgen_is_function_5e4570eb24ffa122: function(arg0) {
|
|
174
175
|
return typeof getObject(arg0) === "function";
|
|
175
176
|
},
|
|
176
|
-
|
|
177
|
+
__wbg___wbindgen_is_object_a2790eb24c211ea0: function(arg0) {
|
|
177
178
|
const val = getObject(arg0);
|
|
178
179
|
return typeof val === "object" && val !== null;
|
|
179
180
|
},
|
|
180
|
-
|
|
181
|
+
__wbg___wbindgen_is_string_e6f02f0ea5f20a32: function(arg0) {
|
|
181
182
|
return typeof getObject(arg0) === "string";
|
|
182
183
|
},
|
|
183
|
-
|
|
184
|
+
__wbg___wbindgen_is_undefined_6cff064c44e0d823: function(arg0) {
|
|
184
185
|
return getObject(arg0) === void 0;
|
|
185
186
|
},
|
|
186
|
-
|
|
187
|
+
__wbg___wbindgen_jsval_eq_0a18949a61670320: function(arg0, arg1) {
|
|
187
188
|
return getObject(arg0) === getObject(arg1);
|
|
188
189
|
},
|
|
189
|
-
|
|
190
|
+
__wbg___wbindgen_jsval_loose_eq_acf2776254a8d832: function(arg0, arg1) {
|
|
190
191
|
return getObject(arg0) == getObject(arg1);
|
|
191
192
|
},
|
|
192
|
-
|
|
193
|
+
__wbg___wbindgen_number_get_136b9679cab35cfb: function(arg0, arg1) {
|
|
193
194
|
const obj = getObject(arg1);
|
|
194
195
|
const ret = typeof obj === "number" ? obj : void 0;
|
|
195
196
|
getDataViewMemory0().setFloat64(arg0 + 8, isLikeNone(ret) ? 0 : ret, true);
|
|
196
197
|
getDataViewMemory0().setInt32(arg0 + 0, !isLikeNone(ret), true);
|
|
197
198
|
},
|
|
198
|
-
|
|
199
|
+
__wbg___wbindgen_string_get_d154f1e671052120: function(arg0, arg1) {
|
|
199
200
|
const obj = getObject(arg1);
|
|
200
201
|
const ret = typeof obj === "string" ? obj : void 0;
|
|
201
202
|
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
@@ -203,30 +204,30 @@ function __wbg_get_imports() {
|
|
|
203
204
|
getDataViewMemory0().setInt32(arg0 + 4, len1, true);
|
|
204
205
|
getDataViewMemory0().setInt32(arg0 + 0, ptr1, true);
|
|
205
206
|
},
|
|
206
|
-
|
|
207
|
+
__wbg___wbindgen_throw_bb96b2010945f0bc: function(arg0, arg1) {
|
|
207
208
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
208
209
|
},
|
|
209
|
-
|
|
210
|
+
__wbg_call_1c5886ab9c57d1c7: function() {
|
|
210
211
|
return handleError(function(arg0, arg1) {
|
|
211
212
|
return addHeapObject(getObject(arg0).call(getObject(arg1)));
|
|
212
213
|
}, arguments);
|
|
213
214
|
},
|
|
214
|
-
|
|
215
|
+
__wbg_done_669171204c3dcae2: function(arg0) {
|
|
215
216
|
return getObject(arg0).done;
|
|
216
217
|
},
|
|
217
|
-
|
|
218
|
+
__wbg_entries_7774d489e1da5f4f: function(arg0) {
|
|
218
219
|
return addHeapObject(Object.entries(getObject(arg0)));
|
|
219
220
|
},
|
|
220
|
-
|
|
221
|
+
__wbg_get_c0c8f8d7da0c03dd: function(arg0, arg1) {
|
|
221
222
|
const ret = getObject(arg0)[arg1 >>> 0];
|
|
222
223
|
return addHeapObject(ret);
|
|
223
224
|
},
|
|
224
|
-
|
|
225
|
+
__wbg_get_d173c0308df22d37: function() {
|
|
225
226
|
return handleError(function(arg0, arg1) {
|
|
226
227
|
return addHeapObject(Reflect.get(getObject(arg0), getObject(arg1)));
|
|
227
228
|
}, arguments);
|
|
228
229
|
},
|
|
229
|
-
|
|
230
|
+
__wbg_get_unchecked_e20b893aeafc3fca: function(arg0, arg1) {
|
|
230
231
|
const ret = getObject(arg0)[arg1 >>> 0];
|
|
231
232
|
return addHeapObject(ret);
|
|
232
233
|
},
|
|
@@ -234,7 +235,7 @@ function __wbg_get_imports() {
|
|
|
234
235
|
const ret = getObject(arg0)[getObject(arg1)];
|
|
235
236
|
return addHeapObject(ret);
|
|
236
237
|
},
|
|
237
|
-
|
|
238
|
+
__wbg_instanceof_ArrayBuffer_993d02d2d254cad1: function(arg0) {
|
|
238
239
|
let result;
|
|
239
240
|
try {
|
|
240
241
|
result = getObject(arg0) instanceof ArrayBuffer;
|
|
@@ -243,7 +244,7 @@ function __wbg_get_imports() {
|
|
|
243
244
|
}
|
|
244
245
|
return result;
|
|
245
246
|
},
|
|
246
|
-
|
|
247
|
+
__wbg_instanceof_Map_9a4d6ead180ae3a9: function(arg0) {
|
|
247
248
|
let result;
|
|
248
249
|
try {
|
|
249
250
|
result = getObject(arg0) instanceof Map;
|
|
@@ -252,7 +253,7 @@ function __wbg_get_imports() {
|
|
|
252
253
|
}
|
|
253
254
|
return result;
|
|
254
255
|
},
|
|
255
|
-
|
|
256
|
+
__wbg_instanceof_Uint8Array_f935dbb0aa7cdeed: function(arg0) {
|
|
256
257
|
let result;
|
|
257
258
|
try {
|
|
258
259
|
result = getObject(arg0) instanceof Uint8Array;
|
|
@@ -261,53 +262,53 @@ function __wbg_get_imports() {
|
|
|
261
262
|
}
|
|
262
263
|
return result;
|
|
263
264
|
},
|
|
264
|
-
|
|
265
|
+
__wbg_isArray_6339f732981044bf: function(arg0) {
|
|
265
266
|
return Array.isArray(getObject(arg0));
|
|
266
267
|
},
|
|
267
|
-
|
|
268
|
+
__wbg_isSafeInteger_f3d6cd19ccfe4512: function(arg0) {
|
|
268
269
|
return Number.isSafeInteger(getObject(arg0));
|
|
269
270
|
},
|
|
270
|
-
|
|
271
|
+
__wbg_iterator_5cebbb86e33c6dd6: function() {
|
|
271
272
|
const ret = Symbol.iterator;
|
|
272
273
|
return addHeapObject(ret);
|
|
273
274
|
},
|
|
274
|
-
|
|
275
|
+
__wbg_length_36bd29c6848c2144: function(arg0) {
|
|
275
276
|
return getObject(arg0).length;
|
|
276
277
|
},
|
|
277
|
-
|
|
278
|
+
__wbg_length_ecfa2c63d3d0d82c: function(arg0) {
|
|
278
279
|
return getObject(arg0).length;
|
|
279
280
|
},
|
|
280
|
-
|
|
281
|
+
__wbg_new_116be93542d39019: function() {
|
|
281
282
|
return addHeapObject(new Array());
|
|
282
283
|
},
|
|
283
|
-
|
|
284
|
+
__wbg_new_358857d90afd5a2d: function(arg0, arg1) {
|
|
284
285
|
return addHeapObject(new Error(getStringFromWasm0(arg0, arg1)));
|
|
285
286
|
},
|
|
286
|
-
|
|
287
|
+
__wbg_new_77cc4f4f472aeb81: function(arg0) {
|
|
287
288
|
return addHeapObject(new Uint8Array(getObject(arg0)));
|
|
288
289
|
},
|
|
289
|
-
|
|
290
|
+
__wbg_new_ebe3e0f6837f0879: function() {
|
|
290
291
|
return addHeapObject(/* @__PURE__ */ new Object());
|
|
291
292
|
},
|
|
292
|
-
|
|
293
|
-
const ret = getObject(arg0).next;
|
|
294
|
-
return addHeapObject(ret);
|
|
295
|
-
},
|
|
296
|
-
__wbg_next_71f2aa1cb3d1e37e: function() {
|
|
293
|
+
__wbg_next_42cf16ee0dafc9e2: function() {
|
|
297
294
|
return handleError(function(arg0) {
|
|
298
295
|
return addHeapObject(getObject(arg0).next());
|
|
299
296
|
}, arguments);
|
|
300
297
|
},
|
|
301
|
-
|
|
298
|
+
__wbg_next_8f26b64fa5e9f64b: function(arg0) {
|
|
299
|
+
const ret = getObject(arg0).next;
|
|
300
|
+
return addHeapObject(ret);
|
|
301
|
+
},
|
|
302
|
+
__wbg_prototypesetcall_de8e0d9553586985: function(arg0, arg1, arg2) {
|
|
302
303
|
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
|
|
303
304
|
},
|
|
304
305
|
__wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
|
|
305
306
|
getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
|
|
306
307
|
},
|
|
307
|
-
|
|
308
|
+
__wbg_set_a80955eb93b145c6: function(arg0, arg1, arg2) {
|
|
308
309
|
getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
|
|
309
310
|
},
|
|
310
|
-
|
|
311
|
+
__wbg_value_1e2369fab29b420e: function(arg0) {
|
|
311
312
|
const ret = getObject(arg0).value;
|
|
312
313
|
return addHeapObject(ret);
|
|
313
314
|
},
|
|
@@ -493,10 +494,11 @@ function __wbg_finalize_init(instance, module) {
|
|
|
493
494
|
}
|
|
494
495
|
async function __wbg_load(module, imports) {
|
|
495
496
|
if (typeof Response === "function" && module instanceof Response) {
|
|
497
|
+
if (!module.ok) throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
|
|
496
498
|
if (typeof WebAssembly.instantiateStreaming === "function") try {
|
|
497
499
|
return await WebAssembly.instantiateStreaming(module, imports);
|
|
498
500
|
} catch (e) {
|
|
499
|
-
if (
|
|
501
|
+
if (expectedResponseType(module.type) && module.headers.get("Content-Type") !== "application/wasm") console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
500
502
|
else throw e;
|
|
501
503
|
}
|
|
502
504
|
const bytes = await module.arrayBuffer();
|
|
@@ -578,6 +580,7 @@ var PdfRenderer = class {
|
|
|
578
580
|
source: [
|
|
579
581
|
main.node,
|
|
580
582
|
...bands,
|
|
583
|
+
_takumi_rs_helpers.LIST_MARKER_CHARACTERS,
|
|
581
584
|
counterCharacters([main.node, ...bands].flatMap((tree) => classNames(tree)))
|
|
582
585
|
]
|
|
583
586
|
}), images, fontFamilies);
|
|
@@ -612,7 +615,11 @@ var PdfRenderer = class {
|
|
|
612
615
|
const main = await resolveNode(node);
|
|
613
616
|
const resources = await this.fonts.resolveResources(fonts && (0, _takumi_rs_helpers.subsetFonts)({
|
|
614
617
|
fonts,
|
|
615
|
-
source: [
|
|
618
|
+
source: [
|
|
619
|
+
main.node,
|
|
620
|
+
_takumi_rs_helpers.LIST_MARKER_CHARACTERS,
|
|
621
|
+
counterCharacters(classNames(main.node))
|
|
622
|
+
]
|
|
616
623
|
}), images, fontFamilies);
|
|
617
624
|
const sheets = [...stylesheets ?? [], ...main.stylesheets];
|
|
618
625
|
return this.inner.measure(main.node, {
|
|
@@ -643,7 +650,10 @@ function measure(node, options) {
|
|
|
643
650
|
return shared.measure(node, options);
|
|
644
651
|
}
|
|
645
652
|
//#endregion
|
|
653
|
+
exports.PageNumber = require_primitives.PageNumber;
|
|
646
654
|
exports.PdfRenderer = PdfRenderer;
|
|
655
|
+
exports.TargetPageNumber = require_primitives.TargetPageNumber;
|
|
656
|
+
exports.TotalPages = require_primitives.TotalPages;
|
|
647
657
|
exports.default = __wbg_init;
|
|
648
658
|
exports.initSync = initSync;
|
|
649
659
|
exports.measure = measure;
|
package/dist/export.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CounterProps, CounterStyle, PageNumber, TargetPageNumber, TotalPages } from "./primitives.cjs";
|
|
1
2
|
import { FontLoader, FontLoader as FontLoader$1, ImagesInput, ImagesInput as ImagesInput$1, RegisteredFamilyLike } from "@takumi-rs/helpers/renderer";
|
|
2
3
|
import { Node, ReactElementLike } from "@takumi-rs/helpers";
|
|
3
4
|
import { ReactNode } from "react";
|
|
@@ -309,4 +310,4 @@ declare function render(node: NodeInput, options?: RenderOptions): Promise<Uint8
|
|
|
309
310
|
/** Measures with a lazily created shared {@link PdfRenderer}. */
|
|
310
311
|
declare function measure(node: NodeInput, options?: MeasureOptions): Promise<MeasuredSize>;
|
|
311
312
|
//#endregion
|
|
312
|
-
export { ArchivalAttachment, Attachment, Dimensions, type FontLoader, type ImagesInput, MeasureOptions, MeasuredSize, NodeInput, PageMargin, PageMarginSide, PageSize, PageSizeName, PdfMetadata, PdfRenderer, RenderOptions, ViewportInput, XmpProperty, XmpSchema, __wbg_init as default, initSync, measure, render };
|
|
313
|
+
export { ArchivalAttachment, Attachment, type CounterProps, type CounterStyle, Dimensions, type FontLoader, type ImagesInput, MeasureOptions, MeasuredSize, NodeInput, PageMargin, PageMarginSide, PageNumber, PageSize, PageSizeName, PdfMetadata, PdfRenderer, RenderOptions, TargetPageNumber, TotalPages, ViewportInput, XmpProperty, XmpSchema, __wbg_init as default, initSync, measure, render };
|
package/dist/export.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CounterProps, CounterStyle, PageNumber, TargetPageNumber, TotalPages } from "./primitives.mjs";
|
|
1
2
|
import { FontLoader, FontLoader as FontLoader$1, ImagesInput, ImagesInput as ImagesInput$1, RegisteredFamilyLike } from "@takumi-rs/helpers/renderer";
|
|
2
3
|
import { Node, ReactElementLike } from "@takumi-rs/helpers";
|
|
3
4
|
import { ReactNode } from "react";
|
|
@@ -309,4 +310,4 @@ declare function render(node: NodeInput, options?: RenderOptions): Promise<Uint8
|
|
|
309
310
|
/** Measures with a lazily created shared {@link PdfRenderer}. */
|
|
310
311
|
declare function measure(node: NodeInput, options?: MeasureOptions): Promise<MeasuredSize>;
|
|
311
312
|
//#endregion
|
|
312
|
-
export { ArchivalAttachment, Attachment, Dimensions, type FontLoader, type ImagesInput, MeasureOptions, MeasuredSize, NodeInput, PageMargin, PageMarginSide, PageSize, PageSizeName, PdfMetadata, PdfRenderer, RenderOptions, ViewportInput, XmpProperty, XmpSchema, __wbg_init as default, initSync, measure, render };
|
|
313
|
+
export { ArchivalAttachment, Attachment, type CounterProps, type CounterStyle, Dimensions, type FontLoader, type ImagesInput, MeasureOptions, MeasuredSize, NodeInput, PageMargin, PageMarginSide, PageNumber, PageSize, PageSizeName, PdfMetadata, PdfRenderer, RenderOptions, TargetPageNumber, TotalPages, ViewportInput, XmpProperty, XmpSchema, __wbg_init as default, initSync, measure, render };
|
package/dist/export.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { PageNumber, TargetPageNumber, TotalPages } from "./primitives.mjs";
|
|
1
2
|
import { fromHtml } from "@takumi-rs/helpers/html";
|
|
2
3
|
import { fromJsx } from "@takumi-rs/helpers/jsx";
|
|
3
4
|
import { FontRegistry } from "@takumi-rs/helpers/renderer";
|
|
4
|
-
import { subsetFonts } from "@takumi-rs/helpers";
|
|
5
|
+
import { LIST_MARKER_CHARACTERS, subsetFonts } from "@takumi-rs/helpers";
|
|
5
6
|
//#region pkg/takumi_pdf_wasm.js
|
|
6
7
|
/**
|
|
7
8
|
* A PDF renderer holding registered fonts and a decoded-resource cache.
|
|
@@ -131,10 +132,10 @@ function __wbg_get_imports() {
|
|
|
131
132
|
__proto__: null,
|
|
132
133
|
"./takumi_pdf_wasm_bg.js": {
|
|
133
134
|
__proto__: null,
|
|
134
|
-
|
|
135
|
+
__wbg_Error_408e67f47ca7b58b: function(arg0, arg1) {
|
|
135
136
|
return addHeapObject(Error(getStringFromWasm0(arg0, arg1)));
|
|
136
137
|
},
|
|
137
|
-
|
|
138
|
+
__wbg_Number_3890faa6d3ff057d: function(arg0) {
|
|
138
139
|
return Number(getObject(arg0));
|
|
139
140
|
},
|
|
140
141
|
__wbg_String_8564e559799eccda: function(arg0, arg1) {
|
|
@@ -143,55 +144,55 @@ function __wbg_get_imports() {
|
|
|
143
144
|
getDataViewMemory0().setInt32(arg0 + 4, len1, true);
|
|
144
145
|
getDataViewMemory0().setInt32(arg0 + 0, ptr1, true);
|
|
145
146
|
},
|
|
146
|
-
|
|
147
|
+
__wbg___wbindgen_bigint_get_as_i64_c4ecf48528083721: function(arg0, arg1) {
|
|
147
148
|
const v = getObject(arg1);
|
|
148
149
|
const ret = typeof v === "bigint" ? v : void 0;
|
|
149
150
|
getDataViewMemory0().setBigInt64(arg0 + 8, isLikeNone(ret) ? BigInt(0) : ret, true);
|
|
150
151
|
getDataViewMemory0().setInt32(arg0 + 0, !isLikeNone(ret), true);
|
|
151
152
|
},
|
|
152
|
-
|
|
153
|
+
__wbg___wbindgen_boolean_get_c9c83ebd41b34df3: function(arg0) {
|
|
153
154
|
const v = getObject(arg0);
|
|
154
155
|
const ret = typeof v === "boolean" ? v : void 0;
|
|
155
156
|
return isLikeNone(ret) ? 16777215 : ret ? 1 : 0;
|
|
156
157
|
},
|
|
157
|
-
|
|
158
|
+
__wbg___wbindgen_debug_string_a57024b9c6e4a48b: function(arg0, arg1) {
|
|
158
159
|
const ptr1 = passStringToWasm0(debugString(getObject(arg1)), wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
159
160
|
const len1 = WASM_VECTOR_LEN;
|
|
160
161
|
getDataViewMemory0().setInt32(arg0 + 4, len1, true);
|
|
161
162
|
getDataViewMemory0().setInt32(arg0 + 0, ptr1, true);
|
|
162
163
|
},
|
|
163
|
-
|
|
164
|
+
__wbg___wbindgen_in_ac983077f137f2e6: function(arg0, arg1) {
|
|
164
165
|
return getObject(arg0) in getObject(arg1);
|
|
165
166
|
},
|
|
166
|
-
|
|
167
|
+
__wbg___wbindgen_is_bigint_8ffbbef442139384: function(arg0) {
|
|
167
168
|
return typeof getObject(arg0) === "bigint";
|
|
168
169
|
},
|
|
169
|
-
|
|
170
|
+
__wbg___wbindgen_is_function_5e4570eb24ffa122: function(arg0) {
|
|
170
171
|
return typeof getObject(arg0) === "function";
|
|
171
172
|
},
|
|
172
|
-
|
|
173
|
+
__wbg___wbindgen_is_object_a2790eb24c211ea0: function(arg0) {
|
|
173
174
|
const val = getObject(arg0);
|
|
174
175
|
return typeof val === "object" && val !== null;
|
|
175
176
|
},
|
|
176
|
-
|
|
177
|
+
__wbg___wbindgen_is_string_e6f02f0ea5f20a32: function(arg0) {
|
|
177
178
|
return typeof getObject(arg0) === "string";
|
|
178
179
|
},
|
|
179
|
-
|
|
180
|
+
__wbg___wbindgen_is_undefined_6cff064c44e0d823: function(arg0) {
|
|
180
181
|
return getObject(arg0) === void 0;
|
|
181
182
|
},
|
|
182
|
-
|
|
183
|
+
__wbg___wbindgen_jsval_eq_0a18949a61670320: function(arg0, arg1) {
|
|
183
184
|
return getObject(arg0) === getObject(arg1);
|
|
184
185
|
},
|
|
185
|
-
|
|
186
|
+
__wbg___wbindgen_jsval_loose_eq_acf2776254a8d832: function(arg0, arg1) {
|
|
186
187
|
return getObject(arg0) == getObject(arg1);
|
|
187
188
|
},
|
|
188
|
-
|
|
189
|
+
__wbg___wbindgen_number_get_136b9679cab35cfb: function(arg0, arg1) {
|
|
189
190
|
const obj = getObject(arg1);
|
|
190
191
|
const ret = typeof obj === "number" ? obj : void 0;
|
|
191
192
|
getDataViewMemory0().setFloat64(arg0 + 8, isLikeNone(ret) ? 0 : ret, true);
|
|
192
193
|
getDataViewMemory0().setInt32(arg0 + 0, !isLikeNone(ret), true);
|
|
193
194
|
},
|
|
194
|
-
|
|
195
|
+
__wbg___wbindgen_string_get_d154f1e671052120: function(arg0, arg1) {
|
|
195
196
|
const obj = getObject(arg1);
|
|
196
197
|
const ret = typeof obj === "string" ? obj : void 0;
|
|
197
198
|
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
@@ -199,30 +200,30 @@ function __wbg_get_imports() {
|
|
|
199
200
|
getDataViewMemory0().setInt32(arg0 + 4, len1, true);
|
|
200
201
|
getDataViewMemory0().setInt32(arg0 + 0, ptr1, true);
|
|
201
202
|
},
|
|
202
|
-
|
|
203
|
+
__wbg___wbindgen_throw_bb96b2010945f0bc: function(arg0, arg1) {
|
|
203
204
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
204
205
|
},
|
|
205
|
-
|
|
206
|
+
__wbg_call_1c5886ab9c57d1c7: function() {
|
|
206
207
|
return handleError(function(arg0, arg1) {
|
|
207
208
|
return addHeapObject(getObject(arg0).call(getObject(arg1)));
|
|
208
209
|
}, arguments);
|
|
209
210
|
},
|
|
210
|
-
|
|
211
|
+
__wbg_done_669171204c3dcae2: function(arg0) {
|
|
211
212
|
return getObject(arg0).done;
|
|
212
213
|
},
|
|
213
|
-
|
|
214
|
+
__wbg_entries_7774d489e1da5f4f: function(arg0) {
|
|
214
215
|
return addHeapObject(Object.entries(getObject(arg0)));
|
|
215
216
|
},
|
|
216
|
-
|
|
217
|
+
__wbg_get_c0c8f8d7da0c03dd: function(arg0, arg1) {
|
|
217
218
|
const ret = getObject(arg0)[arg1 >>> 0];
|
|
218
219
|
return addHeapObject(ret);
|
|
219
220
|
},
|
|
220
|
-
|
|
221
|
+
__wbg_get_d173c0308df22d37: function() {
|
|
221
222
|
return handleError(function(arg0, arg1) {
|
|
222
223
|
return addHeapObject(Reflect.get(getObject(arg0), getObject(arg1)));
|
|
223
224
|
}, arguments);
|
|
224
225
|
},
|
|
225
|
-
|
|
226
|
+
__wbg_get_unchecked_e20b893aeafc3fca: function(arg0, arg1) {
|
|
226
227
|
const ret = getObject(arg0)[arg1 >>> 0];
|
|
227
228
|
return addHeapObject(ret);
|
|
228
229
|
},
|
|
@@ -230,7 +231,7 @@ function __wbg_get_imports() {
|
|
|
230
231
|
const ret = getObject(arg0)[getObject(arg1)];
|
|
231
232
|
return addHeapObject(ret);
|
|
232
233
|
},
|
|
233
|
-
|
|
234
|
+
__wbg_instanceof_ArrayBuffer_993d02d2d254cad1: function(arg0) {
|
|
234
235
|
let result;
|
|
235
236
|
try {
|
|
236
237
|
result = getObject(arg0) instanceof ArrayBuffer;
|
|
@@ -239,7 +240,7 @@ function __wbg_get_imports() {
|
|
|
239
240
|
}
|
|
240
241
|
return result;
|
|
241
242
|
},
|
|
242
|
-
|
|
243
|
+
__wbg_instanceof_Map_9a4d6ead180ae3a9: function(arg0) {
|
|
243
244
|
let result;
|
|
244
245
|
try {
|
|
245
246
|
result = getObject(arg0) instanceof Map;
|
|
@@ -248,7 +249,7 @@ function __wbg_get_imports() {
|
|
|
248
249
|
}
|
|
249
250
|
return result;
|
|
250
251
|
},
|
|
251
|
-
|
|
252
|
+
__wbg_instanceof_Uint8Array_f935dbb0aa7cdeed: function(arg0) {
|
|
252
253
|
let result;
|
|
253
254
|
try {
|
|
254
255
|
result = getObject(arg0) instanceof Uint8Array;
|
|
@@ -257,53 +258,53 @@ function __wbg_get_imports() {
|
|
|
257
258
|
}
|
|
258
259
|
return result;
|
|
259
260
|
},
|
|
260
|
-
|
|
261
|
+
__wbg_isArray_6339f732981044bf: function(arg0) {
|
|
261
262
|
return Array.isArray(getObject(arg0));
|
|
262
263
|
},
|
|
263
|
-
|
|
264
|
+
__wbg_isSafeInteger_f3d6cd19ccfe4512: function(arg0) {
|
|
264
265
|
return Number.isSafeInteger(getObject(arg0));
|
|
265
266
|
},
|
|
266
|
-
|
|
267
|
+
__wbg_iterator_5cebbb86e33c6dd6: function() {
|
|
267
268
|
const ret = Symbol.iterator;
|
|
268
269
|
return addHeapObject(ret);
|
|
269
270
|
},
|
|
270
|
-
|
|
271
|
+
__wbg_length_36bd29c6848c2144: function(arg0) {
|
|
271
272
|
return getObject(arg0).length;
|
|
272
273
|
},
|
|
273
|
-
|
|
274
|
+
__wbg_length_ecfa2c63d3d0d82c: function(arg0) {
|
|
274
275
|
return getObject(arg0).length;
|
|
275
276
|
},
|
|
276
|
-
|
|
277
|
+
__wbg_new_116be93542d39019: function() {
|
|
277
278
|
return addHeapObject(new Array());
|
|
278
279
|
},
|
|
279
|
-
|
|
280
|
+
__wbg_new_358857d90afd5a2d: function(arg0, arg1) {
|
|
280
281
|
return addHeapObject(new Error(getStringFromWasm0(arg0, arg1)));
|
|
281
282
|
},
|
|
282
|
-
|
|
283
|
+
__wbg_new_77cc4f4f472aeb81: function(arg0) {
|
|
283
284
|
return addHeapObject(new Uint8Array(getObject(arg0)));
|
|
284
285
|
},
|
|
285
|
-
|
|
286
|
+
__wbg_new_ebe3e0f6837f0879: function() {
|
|
286
287
|
return addHeapObject(/* @__PURE__ */ new Object());
|
|
287
288
|
},
|
|
288
|
-
|
|
289
|
-
const ret = getObject(arg0).next;
|
|
290
|
-
return addHeapObject(ret);
|
|
291
|
-
},
|
|
292
|
-
__wbg_next_71f2aa1cb3d1e37e: function() {
|
|
289
|
+
__wbg_next_42cf16ee0dafc9e2: function() {
|
|
293
290
|
return handleError(function(arg0) {
|
|
294
291
|
return addHeapObject(getObject(arg0).next());
|
|
295
292
|
}, arguments);
|
|
296
293
|
},
|
|
297
|
-
|
|
294
|
+
__wbg_next_8f26b64fa5e9f64b: function(arg0) {
|
|
295
|
+
const ret = getObject(arg0).next;
|
|
296
|
+
return addHeapObject(ret);
|
|
297
|
+
},
|
|
298
|
+
__wbg_prototypesetcall_de8e0d9553586985: function(arg0, arg1, arg2) {
|
|
298
299
|
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
|
|
299
300
|
},
|
|
300
301
|
__wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
|
|
301
302
|
getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
|
|
302
303
|
},
|
|
303
|
-
|
|
304
|
+
__wbg_set_a80955eb93b145c6: function(arg0, arg1, arg2) {
|
|
304
305
|
getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
|
|
305
306
|
},
|
|
306
|
-
|
|
307
|
+
__wbg_value_1e2369fab29b420e: function(arg0) {
|
|
307
308
|
const ret = getObject(arg0).value;
|
|
308
309
|
return addHeapObject(ret);
|
|
309
310
|
},
|
|
@@ -489,10 +490,11 @@ function __wbg_finalize_init(instance, module) {
|
|
|
489
490
|
}
|
|
490
491
|
async function __wbg_load(module, imports) {
|
|
491
492
|
if (typeof Response === "function" && module instanceof Response) {
|
|
493
|
+
if (!module.ok) throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
|
|
492
494
|
if (typeof WebAssembly.instantiateStreaming === "function") try {
|
|
493
495
|
return await WebAssembly.instantiateStreaming(module, imports);
|
|
494
496
|
} catch (e) {
|
|
495
|
-
if (
|
|
497
|
+
if (expectedResponseType(module.type) && module.headers.get("Content-Type") !== "application/wasm") console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
496
498
|
else throw e;
|
|
497
499
|
}
|
|
498
500
|
const bytes = await module.arrayBuffer();
|
|
@@ -574,6 +576,7 @@ var PdfRenderer = class {
|
|
|
574
576
|
source: [
|
|
575
577
|
main.node,
|
|
576
578
|
...bands,
|
|
579
|
+
LIST_MARKER_CHARACTERS,
|
|
577
580
|
counterCharacters([main.node, ...bands].flatMap((tree) => classNames(tree)))
|
|
578
581
|
]
|
|
579
582
|
}), images, fontFamilies);
|
|
@@ -608,7 +611,11 @@ var PdfRenderer = class {
|
|
|
608
611
|
const main = await resolveNode(node);
|
|
609
612
|
const resources = await this.fonts.resolveResources(fonts && subsetFonts({
|
|
610
613
|
fonts,
|
|
611
|
-
source: [
|
|
614
|
+
source: [
|
|
615
|
+
main.node,
|
|
616
|
+
LIST_MARKER_CHARACTERS,
|
|
617
|
+
counterCharacters(classNames(main.node))
|
|
618
|
+
]
|
|
612
619
|
}), images, fontFamilies);
|
|
613
620
|
const sheets = [...stylesheets ?? [], ...main.stylesheets];
|
|
614
621
|
return this.inner.measure(main.node, {
|
|
@@ -639,4 +646,4 @@ function measure(node, options) {
|
|
|
639
646
|
return shared.measure(node, options);
|
|
640
647
|
}
|
|
641
648
|
//#endregion
|
|
642
|
-
export { PdfRenderer, __wbg_init as default, initSync, measure, render };
|
|
649
|
+
export { PageNumber, PdfRenderer, TargetPageNumber, TotalPages, __wbg_init as default, initSync, measure, render };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/primitives.ts
|
|
3
|
+
const ELEMENT = Symbol.for("react.transitional.element");
|
|
4
|
+
function counter(hook, { format, className, ...rest }) {
|
|
5
|
+
return element("span", {
|
|
6
|
+
...rest,
|
|
7
|
+
className: [
|
|
8
|
+
hook,
|
|
9
|
+
format,
|
|
10
|
+
className
|
|
11
|
+
].filter(Boolean).join(" ")
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function element(type, props) {
|
|
15
|
+
return Object.assign({
|
|
16
|
+
type,
|
|
17
|
+
props,
|
|
18
|
+
key: null
|
|
19
|
+
}, { $$typeof: ELEMENT });
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The number of the page this element lands on. Meaningful inside a `header`
|
|
23
|
+
* or `footer` band (or a `position: fixed` box), where it renumbers per page.
|
|
24
|
+
*/
|
|
25
|
+
function PageNumber(props = {}) {
|
|
26
|
+
return counter("pageNumber", props);
|
|
27
|
+
}
|
|
28
|
+
/** The document's total page count. Same placement rules as {@link PageNumber}. */
|
|
29
|
+
function TotalPages(props = {}) {
|
|
30
|
+
return counter("totalPages", props);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The number of the page a link's target element lands on, for cross
|
|
34
|
+
* references like "see page 12" and tables of contents. Without `href` it
|
|
35
|
+
* reads the nearest enclosing `<a>`; with one it renders its own link.
|
|
36
|
+
*/
|
|
37
|
+
function TargetPageNumber({ href, ...props }) {
|
|
38
|
+
const span = counter("targetPageNumber", props);
|
|
39
|
+
if (href === void 0) return span;
|
|
40
|
+
return element("a", {
|
|
41
|
+
href,
|
|
42
|
+
children: span
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
exports.PageNumber = PageNumber;
|
|
47
|
+
exports.TargetPageNumber = TargetPageNumber;
|
|
48
|
+
exports.TotalPages = TotalPages;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CSSProperties, ReactElement } from "react";
|
|
2
|
+
//#region src/primitives.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* A `@counter-style` name the page counters can format in, matching the set
|
|
5
|
+
* the renderer's `@counter-style` substitution knows.
|
|
6
|
+
*/
|
|
7
|
+
type CounterStyle = "decimal" | "decimal-leading-zero" | "lower-roman" | "upper-roman" | "lower-alpha" | "lower-latin" | "upper-alpha" | "upper-latin" | "lower-greek" | "hiragana" | "katakana" | "trad-chinese-informal" | "cjk-ideographic" | "cjk-decimal" | "arabic-indic" | "bengali" | "cambodian" | "khmer" | "devanagari" | "gujarati" | "gurmukhi" | "kannada" | "lao" | "malayalam" | "mongolian" | "myanmar" | "oriya" | "persian" | "urdu" | "tamil" | "telugu" | "thai" | "tibetan";
|
|
8
|
+
/** Props shared by the page counter primitives. */
|
|
9
|
+
type CounterProps = {
|
|
10
|
+
/** Counter style the number formats in. Defaults to decimal. */
|
|
11
|
+
format?: CounterStyle;
|
|
12
|
+
className?: string;
|
|
13
|
+
style?: CSSProperties;
|
|
14
|
+
tw?: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The number of the page this element lands on. Meaningful inside a `header`
|
|
18
|
+
* or `footer` band (or a `position: fixed` box), where it renumbers per page.
|
|
19
|
+
*/
|
|
20
|
+
declare function PageNumber(props?: CounterProps): ReactElement;
|
|
21
|
+
/** The document's total page count. Same placement rules as {@link PageNumber}. */
|
|
22
|
+
declare function TotalPages(props?: CounterProps): ReactElement;
|
|
23
|
+
/**
|
|
24
|
+
* The number of the page a link's target element lands on, for cross
|
|
25
|
+
* references like "see page 12" and tables of contents. Without `href` it
|
|
26
|
+
* reads the nearest enclosing `<a>`; with one it renders its own link.
|
|
27
|
+
*/
|
|
28
|
+
declare function TargetPageNumber({ href, ...props }: CounterProps & {
|
|
29
|
+
href?: string;
|
|
30
|
+
}): ReactElement;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { CounterProps, CounterStyle, PageNumber, TargetPageNumber, TotalPages };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CSSProperties, ReactElement } from "react";
|
|
2
|
+
//#region src/primitives.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* A `@counter-style` name the page counters can format in, matching the set
|
|
5
|
+
* the renderer's `@counter-style` substitution knows.
|
|
6
|
+
*/
|
|
7
|
+
type CounterStyle = "decimal" | "decimal-leading-zero" | "lower-roman" | "upper-roman" | "lower-alpha" | "lower-latin" | "upper-alpha" | "upper-latin" | "lower-greek" | "hiragana" | "katakana" | "trad-chinese-informal" | "cjk-ideographic" | "cjk-decimal" | "arabic-indic" | "bengali" | "cambodian" | "khmer" | "devanagari" | "gujarati" | "gurmukhi" | "kannada" | "lao" | "malayalam" | "mongolian" | "myanmar" | "oriya" | "persian" | "urdu" | "tamil" | "telugu" | "thai" | "tibetan";
|
|
8
|
+
/** Props shared by the page counter primitives. */
|
|
9
|
+
type CounterProps = {
|
|
10
|
+
/** Counter style the number formats in. Defaults to decimal. */
|
|
11
|
+
format?: CounterStyle;
|
|
12
|
+
className?: string;
|
|
13
|
+
style?: CSSProperties;
|
|
14
|
+
tw?: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The number of the page this element lands on. Meaningful inside a `header`
|
|
18
|
+
* or `footer` band (or a `position: fixed` box), where it renumbers per page.
|
|
19
|
+
*/
|
|
20
|
+
declare function PageNumber(props?: CounterProps): ReactElement;
|
|
21
|
+
/** The document's total page count. Same placement rules as {@link PageNumber}. */
|
|
22
|
+
declare function TotalPages(props?: CounterProps): ReactElement;
|
|
23
|
+
/**
|
|
24
|
+
* The number of the page a link's target element lands on, for cross
|
|
25
|
+
* references like "see page 12" and tables of contents. Without `href` it
|
|
26
|
+
* reads the nearest enclosing `<a>`; with one it renders its own link.
|
|
27
|
+
*/
|
|
28
|
+
declare function TargetPageNumber({ href, ...props }: CounterProps & {
|
|
29
|
+
href?: string;
|
|
30
|
+
}): ReactElement;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { CounterProps, CounterStyle, PageNumber, TargetPageNumber, TotalPages };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region src/primitives.ts
|
|
2
|
+
const ELEMENT = Symbol.for("react.transitional.element");
|
|
3
|
+
function counter(hook, { format, className, ...rest }) {
|
|
4
|
+
return element("span", {
|
|
5
|
+
...rest,
|
|
6
|
+
className: [
|
|
7
|
+
hook,
|
|
8
|
+
format,
|
|
9
|
+
className
|
|
10
|
+
].filter(Boolean).join(" ")
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
function element(type, props) {
|
|
14
|
+
return Object.assign({
|
|
15
|
+
type,
|
|
16
|
+
props,
|
|
17
|
+
key: null
|
|
18
|
+
}, { $$typeof: ELEMENT });
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The number of the page this element lands on. Meaningful inside a `header`
|
|
22
|
+
* or `footer` band (or a `position: fixed` box), where it renumbers per page.
|
|
23
|
+
*/
|
|
24
|
+
function PageNumber(props = {}) {
|
|
25
|
+
return counter("pageNumber", props);
|
|
26
|
+
}
|
|
27
|
+
/** The document's total page count. Same placement rules as {@link PageNumber}. */
|
|
28
|
+
function TotalPages(props = {}) {
|
|
29
|
+
return counter("totalPages", props);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The number of the page a link's target element lands on, for cross
|
|
33
|
+
* references like "see page 12" and tables of contents. Without `href` it
|
|
34
|
+
* reads the nearest enclosing `<a>`; with one it renders its own link.
|
|
35
|
+
*/
|
|
36
|
+
function TargetPageNumber({ href, ...props }) {
|
|
37
|
+
const span = counter("targetPageNumber", props);
|
|
38
|
+
if (href === void 0) return span;
|
|
39
|
+
return element("a", {
|
|
40
|
+
href,
|
|
41
|
+
children: span
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { PageNumber, TargetPageNumber, TotalPages };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "takumi-pdf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Render paged PDFs from JSX, HTML, and CSS. No headless browser.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chromium-free",
|
|
@@ -98,6 +98,16 @@
|
|
|
98
98
|
"types": "./bundlers/node.d.ts",
|
|
99
99
|
"default": "./bundlers/next.mjs"
|
|
100
100
|
},
|
|
101
|
+
"./primitives": {
|
|
102
|
+
"import": {
|
|
103
|
+
"types": "./dist/primitives.d.mts",
|
|
104
|
+
"default": "./dist/primitives.mjs"
|
|
105
|
+
},
|
|
106
|
+
"require": {
|
|
107
|
+
"types": "./dist/primitives.d.cts",
|
|
108
|
+
"default": "./dist/primitives.cjs"
|
|
109
|
+
}
|
|
110
|
+
},
|
|
101
111
|
"./no-init": {
|
|
102
112
|
"import": {
|
|
103
113
|
"types": "./dist/export.d.mts",
|
|
@@ -126,11 +136,10 @@
|
|
|
126
136
|
"scripts": {
|
|
127
137
|
"build": "wasm-pack build ../takumi-pdf-wasm --no-pack --release --out-dir ../takumi-pdf-js/pkg --target web && bun build:js",
|
|
128
138
|
"build:js": "tsdown",
|
|
129
|
-
"build:debug": "wasm-pack build ../takumi-pdf-wasm --no-pack --dev --out-dir ../takumi-pdf-js/pkg --target web && bun build:js",
|
|
130
139
|
"publish-lint": "attw --pack . && publint --strict ."
|
|
131
140
|
},
|
|
132
141
|
"dependencies": {
|
|
133
|
-
"@takumi-rs/helpers": "2.
|
|
142
|
+
"@takumi-rs/helpers": "2.10.0"
|
|
134
143
|
},
|
|
135
144
|
"devDependencies": {
|
|
136
145
|
"@types/bun": "^1.3.14",
|
|
Binary file
|