@build-qube/papyra 0.4.0 → 0.6.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 +12 -1
- package/dist/attachments.d.ts +6 -1
- package/dist/attachments.d.ts.map +1 -1
- package/dist/attachments.js +6 -1
- package/dist/attachments.js.map +1 -1
- package/dist/cache.d.ts +5 -0
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +8 -0
- package/dist/cache.js.map +1 -1
- package/dist/canvas.d.ts +2 -2
- package/dist/canvas.d.ts.map +1 -1
- package/dist/canvas.js +20 -7
- package/dist/canvas.js.map +1 -1
- package/dist/core.d.ts +57 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +40 -0
- package/dist/core.js.map +1 -0
- package/dist/document.d.ts +28 -20
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +79 -360
- package/dist/document.js.map +1 -1
- package/dist/engine.d.ts +327 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +485 -0
- package/dist/engine.js.map +1 -0
- package/dist/errors.d.ts +2 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +2 -1
- package/dist/errors.js.map +1 -1
- package/dist/fingerprint.d.ts +2 -1
- package/dist/fingerprint.d.ts.map +1 -1
- package/dist/fingerprint.js +2 -1
- package/dist/fingerprint.js.map +1 -1
- package/dist/index.d.ts +6 -31
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -14
- package/dist/index.js.map +1 -1
- package/dist/links.d.ts +6 -1
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +6 -1
- package/dist/links.js.map +1 -1
- package/dist/office.d.ts +85 -0
- package/dist/office.d.ts.map +1 -0
- package/dist/office.js +135 -0
- package/dist/office.js.map +1 -0
- package/dist/papyra-engine.d.ts +68 -0
- package/dist/papyra-engine.d.ts.map +1 -0
- package/dist/papyra-engine.js +173 -0
- package/dist/papyra-engine.js.map +1 -0
- package/dist/runtime.d.ts +7 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +11 -0
- package/dist/runtime.js.map +1 -1
- package/dist/scheduler.d.ts +10 -2
- package/dist/scheduler.d.ts.map +1 -1
- package/dist/scheduler.js +26 -7
- package/dist/scheduler.js.map +1 -1
- package/dist/sheets.d.ts +160 -0
- package/dist/sheets.d.ts.map +1 -0
- package/dist/sheets.js +153 -0
- package/dist/sheets.js.map +1 -0
- package/dist/source.d.ts +1 -1
- package/dist/source.js +1 -1
- package/dist/text.d.ts +6 -1
- package/dist/text.d.ts.map +1 -1
- package/dist/text.js +6 -1
- package/dist/text.js.map +1 -1
- package/dist/tiff-image.d.ts +97 -0
- package/dist/tiff-image.d.ts.map +1 -0
- package/dist/tiff-image.js +65 -0
- package/dist/tiff-image.js.map +1 -0
- package/dist/tiff.d.ts +2 -73
- package/dist/tiff.d.ts.map +1 -1
- package/dist/tiff.js +4 -53
- package/dist/tiff.js.map +1 -1
- package/dist/types.d.ts +22 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/workbook.d.ts +3 -134
- package/dist/workbook.d.ts.map +1 -1
- package/dist/workbook.js +6 -141
- package/dist/workbook.js.map +1 -1
- package/package.json +24 -3
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The default {@link TiffRenderOptions.maxPixels}: 4096 × 4096.
|
|
3
|
+
*
|
|
4
|
+
* It is iOS Safari's canvas limit, and 64 MB of RGBA. A 300-dpi E-size sheet comes out
|
|
5
|
+
* at about 100 dpi under it — readable, with hairlines in grey.
|
|
6
|
+
*/
|
|
7
|
+
export const TIFF_MAX_PIXELS = 4096 * 4096;
|
|
8
|
+
/**
|
|
9
|
+
* An opened TIFF. Get one from `openTiff`.
|
|
10
|
+
*
|
|
11
|
+
* `P` is what a page decodes to: RGBA from papyra's own addon, and an `ImageBitmap`
|
|
12
|
+
* too from a host that sends pages as PNG.
|
|
13
|
+
*/
|
|
14
|
+
export class TiffImage {
|
|
15
|
+
/**
|
|
16
|
+
* Every page, in file order. A reduced-resolution copy of a page — a thumbnail, a
|
|
17
|
+
* pyramid level — is not a page and is left out.
|
|
18
|
+
*/
|
|
19
|
+
pages;
|
|
20
|
+
#native;
|
|
21
|
+
/** @internal — construct via `openTiff`. */
|
|
22
|
+
constructor(native) {
|
|
23
|
+
this.#native = native;
|
|
24
|
+
this.pages = native.pages.map((p) => ({
|
|
25
|
+
width: p.width,
|
|
26
|
+
height: p.height,
|
|
27
|
+
dpi: p.xDpi != null ? { x: p.xDpi, y: p.yDpi ?? p.xDpi } : undefined,
|
|
28
|
+
compression: p.compression,
|
|
29
|
+
bitsPerSample: p.bitsPerSample,
|
|
30
|
+
samplesPerPixel: p.samplesPerPixel,
|
|
31
|
+
orientation: p.orientation,
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
/** How many pages there are. */
|
|
35
|
+
get pageCount() {
|
|
36
|
+
return this.pages.length;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Decode one page to RGBA, upright, at no more than `options` allows.
|
|
40
|
+
*
|
|
41
|
+
* Paint the result with `paintToCanvas`, or encode it with `encode`, exactly as a
|
|
42
|
+
* rendered PDF page. Each call decodes the page again; keep the result if it will
|
|
43
|
+
* be shown again.
|
|
44
|
+
*/
|
|
45
|
+
renderPage(index, options = {}) {
|
|
46
|
+
if (!Number.isInteger(index) || index < 0 || index >= this.pages.length) {
|
|
47
|
+
return Promise.reject(new RangeError(`papyra: no TIFF page ${JSON.stringify(index)}`));
|
|
48
|
+
}
|
|
49
|
+
return this.#native.renderPage(index, {
|
|
50
|
+
maxPixels: options.maxPixels,
|
|
51
|
+
maxWidth: options.maxWidth === undefined
|
|
52
|
+
? undefined
|
|
53
|
+
: Math.max(1, Math.floor(options.maxWidth)),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Free the file. A no-op for papyra's own, which the garbage collector frees; a
|
|
58
|
+
* host holding it — a Tauri app's — frees it now, and would otherwise keep it until
|
|
59
|
+
* the page reloads.
|
|
60
|
+
*/
|
|
61
|
+
async close() {
|
|
62
|
+
await this.#native.close?.();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=tiff-image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tiff-image.js","sourceRoot":"","sources":["../src/tiff-image.ts"],"names":[],"mappings":"AAgEA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,GAAG,IAAI,CAAC;AAe3C;;;;;GAKG;AACH,MAAM,OAAO,SAAS;IACpB;;;OAGG;IACM,KAAK,CAAsB;IAC3B,OAAO,CAAgB;IAEhC,4CAA4C;IAC5C,YAAY,MAAqB;QAC/B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACpC,KAAK,EAAE,CAAC,CAAC,KAAK;YACd,MAAM,EAAE,CAAC,CAAC,MAAM;YAChB,GAAG,EAAE,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS;YACpE,WAAW,EAAE,CAAC,CAAC,WAA8B;YAC7C,aAAa,EAAE,CAAC,CAAC,aAAa;YAC9B,eAAe,EAAE,CAAC,CAAC,eAAe;YAClC,WAAW,EAAE,CAAC,CAAC,WAAW;SAC3B,CAAC,CAAC,CAAC;IACN,CAAC;IAED,gCAAgC;IAChC,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IAC3B,CAAC;IAED;;;;;;OAMG;IACH,UAAU,CAAC,KAAa,EAAE,OAAO,GAAsB,EAAE;QACvD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;YACxE,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,UAAU,CAAC,wBAAwB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAChE,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,EAAE;YACpC,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,QAAQ,EACN,OAAO,CAAC,QAAQ,KAAK,SAAS;gBAC5B,CAAC,CAAC,SAAS;gBACX,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;SAChD,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;IAC/B,CAAC;CACF"}
|
package/dist/tiff.d.ts
CHANGED
|
@@ -1,55 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { PdfSource
|
|
3
|
-
/**
|
|
4
|
-
* How a TIFF page's pixels are stored.
|
|
5
|
-
*
|
|
6
|
-
* The three `ccitt-*` values are fax coding — `ccitt-g4` is what nearly every scanned
|
|
7
|
-
* drawing uses. `old-jpeg` is listed so a page can say what it is, but cannot be
|
|
8
|
-
* rendered.
|
|
9
|
-
*/
|
|
10
|
-
export type TiffCompression = 'none' | 'ccitt-rle' | 'ccitt-g3' | 'ccitt-g4' | 'lzw' | 'old-jpeg' | 'jpeg' | 'deflate' | 'packbits' | 'other';
|
|
11
|
-
/** One page of a TIFF, as it is shown: the file's `Orientation` is already applied. */
|
|
12
|
-
export interface TiffPage {
|
|
13
|
-
/** Width in pixels, at full resolution. */
|
|
14
|
-
readonly width: number;
|
|
15
|
-
/** Height in pixels, at full resolution. */
|
|
16
|
-
readonly height: number;
|
|
17
|
-
/**
|
|
18
|
-
* Resolution in dots per inch, when the file states one. Fax pages are typically
|
|
19
|
-
* 204 by 196, so the two can differ.
|
|
20
|
-
*/
|
|
21
|
-
readonly dpi: {
|
|
22
|
-
/** Horizontal dots per inch. */
|
|
23
|
-
readonly x: number;
|
|
24
|
-
/** Vertical dots per inch. */
|
|
25
|
-
readonly y: number;
|
|
26
|
-
} | undefined;
|
|
27
|
-
/** How the pixels are stored. */
|
|
28
|
-
readonly compression: TiffCompression;
|
|
29
|
-
/** Bits per sample: 1 for a bilevel scan, 8 for most others. */
|
|
30
|
-
readonly bitsPerSample: number;
|
|
31
|
-
/** Samples per pixel: 1 for grey, 3 for RGB, 4 with alpha or for CMYK. */
|
|
32
|
-
readonly samplesPerPixel: number;
|
|
33
|
-
/** TIFF `Orientation`, 1–8. 1 is upright; 6 and 8 are a quarter turn. */
|
|
34
|
-
readonly orientation: number;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Size limits for {@link TiffImage.renderPage}. The page keeps its aspect ratio and
|
|
38
|
-
* is never enlarged.
|
|
39
|
-
*/
|
|
40
|
-
export interface TiffRenderOptions {
|
|
41
|
-
/** The most pixels the result may have. Defaults to {@link TIFF_MAX_PIXELS}. */
|
|
42
|
-
maxPixels?: number;
|
|
43
|
-
/** The widest the result may be, in pixels. */
|
|
44
|
-
maxWidth?: number;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* The default {@link TiffRenderOptions.maxPixels}: 4096 × 4096.
|
|
48
|
-
*
|
|
49
|
-
* It is iOS Safari's canvas limit, and 64 MB of RGBA. A 300-dpi E-size sheet comes out
|
|
50
|
-
* at about 100 dpi under it — readable, with hairlines in grey.
|
|
51
|
-
*/
|
|
52
|
-
export declare const TIFF_MAX_PIXELS: number;
|
|
1
|
+
import { TiffImage } from './tiff-image.js';
|
|
2
|
+
import type { PdfSource } from './types.js';
|
|
53
3
|
/**
|
|
54
4
|
* Open a TIFF: single or multi-page, classic or BigTIFF.
|
|
55
5
|
*
|
|
@@ -71,25 +21,4 @@ export declare const TIFF_MAX_PIXELS: number;
|
|
|
71
21
|
* ```
|
|
72
22
|
*/
|
|
73
23
|
export declare function openTiff(source: PdfSource): Promise<TiffImage>;
|
|
74
|
-
/** An opened TIFF. Get one from {@link openTiff}. */
|
|
75
|
-
export declare class TiffImage {
|
|
76
|
-
#private;
|
|
77
|
-
/**
|
|
78
|
-
* Every page, in file order. A reduced-resolution copy of a page — a thumbnail, a
|
|
79
|
-
* pyramid level — is not a page and is left out.
|
|
80
|
-
*/
|
|
81
|
-
readonly pages: readonly TiffPage[];
|
|
82
|
-
/** @internal — construct via {@link openTiff}. */
|
|
83
|
-
constructor(native: NativeTiffImage);
|
|
84
|
-
/** How many pages there are. */
|
|
85
|
-
get pageCount(): number;
|
|
86
|
-
/**
|
|
87
|
-
* Decode one page to RGBA, upright, at no more than `options` allows.
|
|
88
|
-
*
|
|
89
|
-
* Paint the result with `paintToCanvas`, or encode it with `encode`, exactly as a
|
|
90
|
-
* rendered PDF page. Each call decodes the page again; keep the result if it will
|
|
91
|
-
* be shown again.
|
|
92
|
-
*/
|
|
93
|
-
renderPage(index: number, options?: TiffRenderOptions): Promise<RenderedPage>;
|
|
94
|
-
}
|
|
95
24
|
//# sourceMappingURL=tiff.d.ts.map
|
package/dist/tiff.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tiff.d.ts","sourceRoot":"","sources":["../src/tiff.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tiff.d.ts","sourceRoot":"","sources":["../src/tiff.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAmB,MAAM,iBAAiB,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAIpE"}
|
package/dist/tiff.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import { loadTiff
|
|
1
|
+
import { loadTiff } from '@build-qube/papyra-native';
|
|
2
2
|
import { toBytes } from './source.js';
|
|
3
|
-
|
|
4
|
-
* The default {@link TiffRenderOptions.maxPixels}: 4096 × 4096.
|
|
5
|
-
*
|
|
6
|
-
* It is iOS Safari's canvas limit, and 64 MB of RGBA. A 300-dpi E-size sheet comes out
|
|
7
|
-
* at about 100 dpi under it — readable, with hairlines in grey.
|
|
8
|
-
*/
|
|
9
|
-
export const TIFF_MAX_PIXELS = 4096 * 4096;
|
|
3
|
+
import { TiffImage } from './tiff-image.js';
|
|
10
4
|
/**
|
|
11
5
|
* Open a TIFF: single or multi-page, classic or BigTIFF.
|
|
12
6
|
*
|
|
@@ -29,50 +23,7 @@ export const TIFF_MAX_PIXELS = 4096 * 4096;
|
|
|
29
23
|
*/
|
|
30
24
|
export async function openTiff(source) {
|
|
31
25
|
const bytes = await toBytes(source);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
/** An opened TIFF. Get one from {@link openTiff}. */
|
|
35
|
-
export class TiffImage {
|
|
36
|
-
/**
|
|
37
|
-
* Every page, in file order. A reduced-resolution copy of a page — a thumbnail, a
|
|
38
|
-
* pyramid level — is not a page and is left out.
|
|
39
|
-
*/
|
|
40
|
-
pages;
|
|
41
|
-
#native;
|
|
42
|
-
/** @internal — construct via {@link openTiff}. */
|
|
43
|
-
constructor(native) {
|
|
44
|
-
this.#native = native;
|
|
45
|
-
this.pages = native.pages.map((p) => ({
|
|
46
|
-
width: p.width,
|
|
47
|
-
height: p.height,
|
|
48
|
-
dpi: p.xDpi != null ? { x: p.xDpi, y: p.yDpi ?? p.xDpi } : undefined,
|
|
49
|
-
compression: p.compression,
|
|
50
|
-
bitsPerSample: p.bitsPerSample,
|
|
51
|
-
samplesPerPixel: p.samplesPerPixel,
|
|
52
|
-
orientation: p.orientation,
|
|
53
|
-
}));
|
|
54
|
-
}
|
|
55
|
-
/** How many pages there are. */
|
|
56
|
-
get pageCount() {
|
|
57
|
-
return this.pages.length;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Decode one page to RGBA, upright, at no more than `options` allows.
|
|
61
|
-
*
|
|
62
|
-
* Paint the result with `paintToCanvas`, or encode it with `encode`, exactly as a
|
|
63
|
-
* rendered PDF page. Each call decodes the page again; keep the result if it will
|
|
64
|
-
* be shown again.
|
|
65
|
-
*/
|
|
66
|
-
renderPage(index, options = {}) {
|
|
67
|
-
if (!Number.isInteger(index) || index < 0 || index >= this.pages.length) {
|
|
68
|
-
return Promise.reject(new RangeError(`papyra: no TIFF page ${JSON.stringify(index)}`));
|
|
69
|
-
}
|
|
70
|
-
return this.#native.renderPage(index, {
|
|
71
|
-
maxPixels: options.maxPixels,
|
|
72
|
-
maxWidth: options.maxWidth === undefined
|
|
73
|
-
? undefined
|
|
74
|
-
: Math.max(1, Math.floor(options.maxWidth)),
|
|
75
|
-
});
|
|
76
|
-
}
|
|
26
|
+
// The addon's `RenderedPage` is papyra's, typed by napi as a looser object.
|
|
27
|
+
return new TiffImage((await loadTiff(bytes)));
|
|
77
28
|
}
|
|
78
29
|
//# sourceMappingURL=tiff.js.map
|
package/dist/tiff.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tiff.js","sourceRoot":"","sources":["../src/tiff.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"tiff.js","sourceRoot":"","sources":["../src/tiff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,SAAS,EAAmB,MAAM,iBAAiB,CAAC;AAG7D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,MAAiB;IAC9C,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IACpC,4EAA4E;IAC5E,OAAO,IAAI,SAAS,CAAC,CAAC,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAe,CAAC,CAAC;AAC9D,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { JobHandle } from './scheduler.js';
|
|
1
2
|
import type { MatchOptions } from './search.js';
|
|
2
3
|
/** Anything we can turn into PDF bytes. `File` is a `Blob`, so it is covered. */
|
|
3
4
|
export type PdfSource = Uint8Array | ArrayBuffer | ArrayBufferView | Blob;
|
|
@@ -107,12 +108,21 @@ export interface RenderedPage {
|
|
|
107
108
|
*/
|
|
108
109
|
readonly data: Uint8Array;
|
|
109
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* A rendered page in whichever form its engine produces it.
|
|
113
|
+
*
|
|
114
|
+
* papyra's own engine hands back {@link RenderedPage} — RGBA bytes, painted with
|
|
115
|
+
* `putImageData`. An engine that rasterises somewhere else (pdf.js on an
|
|
116
|
+
* `OffscreenCanvas`, a host process serving images) hands back an `ImageBitmap`,
|
|
117
|
+
* which a canvas draws without a copy. {@link paintToCanvas} takes either.
|
|
118
|
+
*/
|
|
119
|
+
export type PageBitmap = RenderedPage | ImageBitmap;
|
|
110
120
|
/** One result from {@link Document.stream}, tagged with the page it came from. */
|
|
111
|
-
export interface StreamedPage {
|
|
121
|
+
export interface StreamedPage<P extends PageBitmap = RenderedPage> {
|
|
112
122
|
/** Index of the page in the document. */
|
|
113
123
|
readonly page: number;
|
|
114
124
|
/** The rendered pixels. */
|
|
115
|
-
readonly bitmap:
|
|
125
|
+
readonly bitmap: P;
|
|
116
126
|
}
|
|
117
127
|
/** Page dimensions in PDF points (1/72 inch). */
|
|
118
128
|
export interface PageSize {
|
|
@@ -209,4 +219,14 @@ export interface SearchOptions extends MatchOptions {
|
|
|
209
219
|
/** Abort the search. Pages already being extracted are left to finish. */
|
|
210
220
|
signal?: AbortSignal;
|
|
211
221
|
}
|
|
222
|
+
/** A queued render, plus whether it was served from cache without rendering at all. */
|
|
223
|
+
export interface RenderHandle<P extends PageBitmap = RenderedPage> extends JobHandle<P> {
|
|
224
|
+
/**
|
|
225
|
+
* The page was already in the cache and nothing was queued.
|
|
226
|
+
*
|
|
227
|
+
* `promise` still resolves normally, so this only matters for instrumentation —
|
|
228
|
+
* a cache hit costs none of the ~93ms floor a real render does.
|
|
229
|
+
*/
|
|
230
|
+
readonly cached: boolean;
|
|
231
|
+
}
|
|
212
232
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,iFAAiF;AACjF,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,WAAW,GAAG,eAAe,GAAG,IAAI,CAAC;AAE1E,4DAA4D;AAC5D,MAAM,WAAW,aAAa;IAC5B;;;;;;;;OAQG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gDAAgD;IAChD,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,mEAAmE;IACnE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;;;;;;;;;;;OAeG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,6EAA6E;AAC7E,MAAM,WAAW,aAAc,SAAQ,aAAa;IAClD;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,sEAAs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C,CAAC,CAAC;IACpB;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC1B"}
|
package/dist/workbook.d.ts
CHANGED
|
@@ -1,70 +1,11 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { CellWindow, type MergedRange } from './cells.js';
|
|
3
|
-
import { type CellStyle, type SheetLayout } from './styles.js';
|
|
1
|
+
import { type Workbook, type WorkbookOptions } from './sheets.js';
|
|
4
2
|
import type { PdfSource } from './types.js';
|
|
5
|
-
/**
|
|
6
|
-
* The container a workbook was read from.
|
|
7
|
-
*
|
|
8
|
-
* Macro-enabled and template variants read as their base format: an `.xlsm` is
|
|
9
|
-
* `'xlsx'` here, because to a reader that is what it is.
|
|
10
|
-
*/
|
|
11
|
-
export type WorkbookFormat = 'xlsx' | 'xlsb' | 'xls' | 'ods' | 'csv' | 'tsv';
|
|
12
|
-
/** How to read a workbook. Everything is sniffed when left out. */
|
|
13
|
-
export interface WorkbookOptions {
|
|
14
|
-
/**
|
|
15
|
-
* Skip sniffing. Only needed to read a file as TSV that was not named `.tsv` —
|
|
16
|
-
* the binary formats identify themselves, and text is sniffed for its delimiter.
|
|
17
|
-
* `'xlsm'` is accepted and reads as `'xlsx'`.
|
|
18
|
-
*/
|
|
19
|
-
format?: WorkbookFormat | 'xlsm';
|
|
20
|
-
/** CSV and TSV only: the delimiter, a single ASCII character such as `';'`. */
|
|
21
|
-
delimiter?: string;
|
|
22
|
-
/**
|
|
23
|
-
* CSV and TSV only: a WHATWG encoding label, e.g. `'windows-1252'` or
|
|
24
|
-
* `'shift_jis'`. Without one, a byte-order mark decides, then valid UTF-8, then a
|
|
25
|
-
* statistical guess.
|
|
26
|
-
*/
|
|
27
|
-
encoding?: string;
|
|
28
|
-
/**
|
|
29
|
-
* Cells to hold per sheet before truncating it to its first whole rows. Defaults
|
|
30
|
-
* to 8 million — about 400 MB, which a browser tab survives. A sheet that hits it
|
|
31
|
-
* reports {@link Sheet.truncated}.
|
|
32
|
-
*/
|
|
33
|
-
maxCells?: number;
|
|
34
|
-
}
|
|
35
|
-
/** Whether a sheet shows in the application's tab bar. */
|
|
36
|
-
export type SheetVisibility = 'visible' | 'hidden' | 'veryHidden';
|
|
37
|
-
/** What a sheet holds. Only worksheets have cells worth showing. */
|
|
38
|
-
export type SheetKind = 'worksheet' | 'chartsheet' | 'dialog' | 'macro' | 'vba';
|
|
39
|
-
/** A sheet's entry in the workbook, known without reading its cells. */
|
|
40
|
-
export interface SheetInfo {
|
|
41
|
-
/** The name on the sheet's tab. CSV and TSV have one sheet, named `Sheet1`. */
|
|
42
|
-
name: string;
|
|
43
|
-
/** What the sheet holds. */
|
|
44
|
-
kind: SheetKind;
|
|
45
|
-
/**
|
|
46
|
-
* `'hidden'` sheets can be unhidden by the user; `'veryHidden'` ones only by a
|
|
47
|
-
* macro. A viewer usually lists the first and omits the second.
|
|
48
|
-
*/
|
|
49
|
-
visibility: SheetVisibility;
|
|
50
|
-
}
|
|
51
|
-
/** Rows and columns to read, half-open like `Array.prototype.slice`. */
|
|
52
|
-
export interface WindowRange {
|
|
53
|
-
/** First row, 0-based. */
|
|
54
|
-
rowStart: number;
|
|
55
|
-
/** One past the last row. Clamped to the sheet. */
|
|
56
|
-
rowEnd: number;
|
|
57
|
-
/** First column. Defaults to 0. */
|
|
58
|
-
colStart?: number;
|
|
59
|
-
/** One past the last column. Defaults to every column. */
|
|
60
|
-
colEnd?: number;
|
|
61
|
-
}
|
|
62
3
|
/**
|
|
63
4
|
* Open a spreadsheet: Excel (`.xlsx`, `.xlsm`, `.xlsb`, `.xls`), OpenDocument
|
|
64
5
|
* (`.ods`), or delimited text (`.csv`, `.tsv`).
|
|
65
6
|
*
|
|
66
7
|
* Parsing happens in Rust and off the JS thread, and only sheet names are read up
|
|
67
|
-
* front: a sheet's cells are read the first time
|
|
8
|
+
* front: a sheet's cells are read the first time `Workbook.sheet` asks for it.
|
|
68
9
|
*
|
|
69
10
|
* @example
|
|
70
11
|
* ```ts
|
|
@@ -74,79 +15,7 @@ export interface WindowRange {
|
|
|
74
15
|
* cells.text(0, 0); // 'Item'
|
|
75
16
|
* ```
|
|
76
17
|
*
|
|
77
|
-
* @throws
|
|
18
|
+
* @throws `EncryptedWorkbookError` when the workbook is password-protected.
|
|
78
19
|
*/
|
|
79
20
|
export declare function openWorkbook(source: PdfSource, options?: WorkbookOptions): Promise<Workbook>;
|
|
80
|
-
/** An opened spreadsheet. Get one from {@link openWorkbook}. */
|
|
81
|
-
export declare class Workbook {
|
|
82
|
-
#private;
|
|
83
|
-
/** The container actually read. */
|
|
84
|
-
readonly format: WorkbookFormat;
|
|
85
|
-
/** Every sheet in tab order, hidden ones included. */
|
|
86
|
-
readonly sheets: readonly SheetInfo[];
|
|
87
|
-
/**
|
|
88
|
-
* CSV and TSV only: the encoding the text was decoded from, e.g.
|
|
89
|
-
* `'windows-1252'`. Worth showing when it was guessed — a wrong guess reads as
|
|
90
|
-
* mojibake, and {@link WorkbookOptions.encoding} is the fix.
|
|
91
|
-
*/
|
|
92
|
-
readonly encoding: string | undefined;
|
|
93
|
-
/** CSV and TSV only: the delimiter, given or sniffed. */
|
|
94
|
-
readonly delimiter: string | undefined;
|
|
95
|
-
/** @internal — construct via {@link openWorkbook}. */
|
|
96
|
-
constructor(native: NativeWorkbook);
|
|
97
|
-
/**
|
|
98
|
-
* Read one sheet, by index or by name.
|
|
99
|
-
*
|
|
100
|
-
* The first call parses the sheet, off the JS thread; later calls for the same
|
|
101
|
-
* sheet share that result.
|
|
102
|
-
*/
|
|
103
|
-
sheet(which: number | string): Promise<Sheet>;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* One sheet, parsed and held in Rust. Read it a window at a time.
|
|
107
|
-
*
|
|
108
|
-
* Coordinates are the sheet's own and 0-based: row 0 is the row Excel labels 1, and
|
|
109
|
-
* a sheet whose data starts at F10 still reports ten rows and six columns, so a grid
|
|
110
|
-
* draws the data where its author put it.
|
|
111
|
-
*/
|
|
112
|
-
export declare class Sheet {
|
|
113
|
-
#private;
|
|
114
|
-
/** The name on the sheet's tab. */
|
|
115
|
-
readonly name: string;
|
|
116
|
-
/** One past the last row holding a value or covered by a merge. */
|
|
117
|
-
readonly rows: number;
|
|
118
|
-
/**
|
|
119
|
-
* The sheet held more cells than {@link WorkbookOptions.maxCells}, and this is
|
|
120
|
-
* its first whole rows. Worth saying on screen: the rest of the file is not here.
|
|
121
|
-
*/
|
|
122
|
-
readonly truncated: boolean;
|
|
123
|
-
/** One past the last column holding a value or covered by a merge. */
|
|
124
|
-
readonly cols: number;
|
|
125
|
-
/**
|
|
126
|
-
* Merged regions. The value lives in each one's top-left cell; the others are
|
|
127
|
-
* empty. Always empty for `.xlsb` and `.ods`, which calamine does not read
|
|
128
|
-
* merges from.
|
|
129
|
-
*/
|
|
130
|
-
readonly merges: readonly MergedRange[];
|
|
131
|
-
/**
|
|
132
|
-
* The styles {@link CellWindow.style} indexes into, with the default at 0.
|
|
133
|
-
* xlsx only: empty for every other format, whose cells all read as style 0.
|
|
134
|
-
*/
|
|
135
|
-
readonly styles: readonly CellStyle[];
|
|
136
|
-
/**
|
|
137
|
-
* Column widths and row heights as the author set them. xlsx only; for anything
|
|
138
|
-
* else a grid sizes columns itself.
|
|
139
|
-
*/
|
|
140
|
-
readonly layout: SheetLayout | undefined;
|
|
141
|
-
/** @internal — construct via {@link Workbook.sheet}. */
|
|
142
|
-
constructor(native: NativeSheet);
|
|
143
|
-
/**
|
|
144
|
-
* Read a rectangle of cells, clamped to the sheet.
|
|
145
|
-
*
|
|
146
|
-
* Synchronous, because the sheet is already parsed and the cost is the size of
|
|
147
|
-
* the window. Ask for what is on screen plus some overscan, not the whole sheet:
|
|
148
|
-
* a screenful is a few thousand cells and well under a millisecond.
|
|
149
|
-
*/
|
|
150
|
-
window(range: WindowRange): CellWindow;
|
|
151
|
-
}
|
|
152
21
|
//# sourceMappingURL=workbook.d.ts.map
|
package/dist/workbook.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workbook.d.ts","sourceRoot":"","sources":["../src/workbook.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"workbook.d.ts","sourceRoot":"","sources":["../src/workbook.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,eAAe,EACrB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,SAAS,EACjB,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,QAAQ,CAAC,CAEnB"}
|
package/dist/workbook.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { loadWorkbook
|
|
2
|
-
import {
|
|
3
|
-
import { rethrowLoadError } from './errors.js';
|
|
4
|
-
import { toBytes } from './source.js';
|
|
5
|
-
import { toCellStyle, toSheetLayout, } from './styles.js';
|
|
1
|
+
import { loadWorkbook } from '@build-qube/papyra-native';
|
|
2
|
+
import { openWorkbookWith, } from './sheets.js';
|
|
6
3
|
/**
|
|
7
4
|
* Open a spreadsheet: Excel (`.xlsx`, `.xlsm`, `.xlsb`, `.xls`), OpenDocument
|
|
8
5
|
* (`.ods`), or delimited text (`.csv`, `.tsv`).
|
|
9
6
|
*
|
|
10
7
|
* Parsing happens in Rust and off the JS thread, and only sheet names are read up
|
|
11
|
-
* front: a sheet's cells are read the first time
|
|
8
|
+
* front: a sheet's cells are read the first time `Workbook.sheet` asks for it.
|
|
12
9
|
*
|
|
13
10
|
* @example
|
|
14
11
|
* ```ts
|
|
@@ -18,141 +15,9 @@ import { toCellStyle, toSheetLayout, } from './styles.js';
|
|
|
18
15
|
* cells.text(0, 0); // 'Item'
|
|
19
16
|
* ```
|
|
20
17
|
*
|
|
21
|
-
* @throws
|
|
18
|
+
* @throws `EncryptedWorkbookError` when the workbook is password-protected.
|
|
22
19
|
*/
|
|
23
|
-
export
|
|
24
|
-
|
|
25
|
-
const format = options.format ?? formatFromName(source);
|
|
26
|
-
try {
|
|
27
|
-
const native = await loadWorkbook(bytes, { ...options, format });
|
|
28
|
-
return new Workbook(native);
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
rethrowLoadError(error);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* A `File` named `.tsv` is TSV whatever its contents sniff as.
|
|
36
|
-
*
|
|
37
|
-
* Only that one extension is trusted. The binary formats announce themselves in
|
|
38
|
-
* their first bytes, and a `.xls` downloaded from a web app is as often an HTML
|
|
39
|
-
* table or a CSV as it is BIFF — believing the name would refuse a readable file.
|
|
40
|
-
*/
|
|
41
|
-
function formatFromName(source) {
|
|
42
|
-
const name = source.name;
|
|
43
|
-
return typeof name === 'string' && /\.(tsv|tab)$/i.test(name)
|
|
44
|
-
? 'tsv'
|
|
45
|
-
: undefined;
|
|
46
|
-
}
|
|
47
|
-
/** An opened spreadsheet. Get one from {@link openWorkbook}. */
|
|
48
|
-
export class Workbook {
|
|
49
|
-
/** The container actually read. */
|
|
50
|
-
format;
|
|
51
|
-
/** Every sheet in tab order, hidden ones included. */
|
|
52
|
-
sheets;
|
|
53
|
-
/**
|
|
54
|
-
* CSV and TSV only: the encoding the text was decoded from, e.g.
|
|
55
|
-
* `'windows-1252'`. Worth showing when it was guessed — a wrong guess reads as
|
|
56
|
-
* mojibake, and {@link WorkbookOptions.encoding} is the fix.
|
|
57
|
-
*/
|
|
58
|
-
encoding;
|
|
59
|
-
/** CSV and TSV only: the delimiter, given or sniffed. */
|
|
60
|
-
delimiter;
|
|
61
|
-
#native;
|
|
62
|
-
#sheets = new Map();
|
|
63
|
-
/** @internal — construct via {@link openWorkbook}. */
|
|
64
|
-
constructor(native) {
|
|
65
|
-
this.#native = native;
|
|
66
|
-
this.format = native.format;
|
|
67
|
-
this.sheets = native.sheets.map((s) => ({
|
|
68
|
-
name: s.name,
|
|
69
|
-
kind: s.kind,
|
|
70
|
-
visibility: s.visibility,
|
|
71
|
-
}));
|
|
72
|
-
this.encoding = native.encoding ?? undefined;
|
|
73
|
-
this.delimiter = native.delimiter ?? undefined;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Read one sheet, by index or by name.
|
|
77
|
-
*
|
|
78
|
-
* The first call parses the sheet, off the JS thread; later calls for the same
|
|
79
|
-
* sheet share that result.
|
|
80
|
-
*/
|
|
81
|
-
sheet(which) {
|
|
82
|
-
const index = typeof which === 'number'
|
|
83
|
-
? which
|
|
84
|
-
: this.sheets.findIndex((s) => s.name === which);
|
|
85
|
-
if (!Number.isInteger(index) || index < 0 || index >= this.sheets.length) {
|
|
86
|
-
return Promise.reject(new RangeError(`papyra: no sheet ${JSON.stringify(which)}`));
|
|
87
|
-
}
|
|
88
|
-
let sheet = this.#sheets.get(index);
|
|
89
|
-
if (!sheet) {
|
|
90
|
-
sheet = this.#native.sheet(index).then((native) => new Sheet(native));
|
|
91
|
-
// A failed read is not cached, so a retry gets a fresh attempt.
|
|
92
|
-
sheet.catch(() => this.#sheets.delete(index));
|
|
93
|
-
this.#sheets.set(index, sheet);
|
|
94
|
-
}
|
|
95
|
-
return sheet;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* One sheet, parsed and held in Rust. Read it a window at a time.
|
|
100
|
-
*
|
|
101
|
-
* Coordinates are the sheet's own and 0-based: row 0 is the row Excel labels 1, and
|
|
102
|
-
* a sheet whose data starts at F10 still reports ten rows and six columns, so a grid
|
|
103
|
-
* draws the data where its author put it.
|
|
104
|
-
*/
|
|
105
|
-
export class Sheet {
|
|
106
|
-
/** The name on the sheet's tab. */
|
|
107
|
-
name;
|
|
108
|
-
/** One past the last row holding a value or covered by a merge. */
|
|
109
|
-
rows;
|
|
110
|
-
/**
|
|
111
|
-
* The sheet held more cells than {@link WorkbookOptions.maxCells}, and this is
|
|
112
|
-
* its first whole rows. Worth saying on screen: the rest of the file is not here.
|
|
113
|
-
*/
|
|
114
|
-
truncated;
|
|
115
|
-
/** One past the last column holding a value or covered by a merge. */
|
|
116
|
-
cols;
|
|
117
|
-
/**
|
|
118
|
-
* Merged regions. The value lives in each one's top-left cell; the others are
|
|
119
|
-
* empty. Always empty for `.xlsb` and `.ods`, which calamine does not read
|
|
120
|
-
* merges from.
|
|
121
|
-
*/
|
|
122
|
-
merges;
|
|
123
|
-
/**
|
|
124
|
-
* The styles {@link CellWindow.style} indexes into, with the default at 0.
|
|
125
|
-
* xlsx only: empty for every other format, whose cells all read as style 0.
|
|
126
|
-
*/
|
|
127
|
-
styles;
|
|
128
|
-
/**
|
|
129
|
-
* Column widths and row heights as the author set them. xlsx only; for anything
|
|
130
|
-
* else a grid sizes columns itself.
|
|
131
|
-
*/
|
|
132
|
-
layout;
|
|
133
|
-
#native;
|
|
134
|
-
/** @internal — construct via {@link Workbook.sheet}. */
|
|
135
|
-
constructor(native) {
|
|
136
|
-
this.#native = native;
|
|
137
|
-
this.name = native.name;
|
|
138
|
-
this.rows = native.rows;
|
|
139
|
-
this.truncated = native.truncated;
|
|
140
|
-
this.cols = native.cols;
|
|
141
|
-
this.merges = toMergedRanges(native.merges);
|
|
142
|
-
this.styles = native.styles.map(toCellStyle);
|
|
143
|
-
this.layout = native.layout ? toSheetLayout(native.layout) : undefined;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Read a rectangle of cells, clamped to the sheet.
|
|
147
|
-
*
|
|
148
|
-
* Synchronous, because the sheet is already parsed and the cost is the size of
|
|
149
|
-
* the window. Ask for what is on screen plus some overscan, not the whole sheet:
|
|
150
|
-
* a screenful is a few thousand cells and well under a millisecond.
|
|
151
|
-
*/
|
|
152
|
-
window(range) {
|
|
153
|
-
// The bindings take u32s, which a negative overscan would wrap rather than clamp.
|
|
154
|
-
const at = (n) => Math.max(0, Math.floor(n));
|
|
155
|
-
return new CellWindow(this.#native.window(at(range.rowStart), at(range.rowEnd), at(range.colStart ?? 0), at(range.colEnd ?? this.cols)));
|
|
156
|
-
}
|
|
20
|
+
export function openWorkbook(source, options = {}) {
|
|
21
|
+
return openWorkbookWith(loadWorkbook, source, options);
|
|
157
22
|
}
|
|
158
23
|
//# sourceMappingURL=workbook.js.map
|
package/dist/workbook.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workbook.js","sourceRoot":"","sources":["../src/workbook.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"workbook.js","sourceRoot":"","sources":["../src/workbook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EACL,gBAAgB,GAGjB,MAAM,aAAa,CAAC;AAGrB;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,YAAY,CAC1B,MAAiB,EACjB,OAAO,GAAoB,EAAE;IAE7B,OAAO,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AACzD,CAAC"}
|