@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
package/dist/scheduler.js
CHANGED
|
@@ -39,6 +39,12 @@ export class Scheduler {
|
|
|
39
39
|
#yieldToUrgent;
|
|
40
40
|
#pending = new Map();
|
|
41
41
|
#running = new Map();
|
|
42
|
+
/**
|
|
43
|
+
* Started jobs that were aborted and have not settled yet. Out of `#running`, so a
|
|
44
|
+
* new request for the same key starts afresh instead of joining a job on its way
|
|
45
|
+
* out; still counted against the limit, since they still hold a slot until then.
|
|
46
|
+
*/
|
|
47
|
+
#aborting = new Set();
|
|
42
48
|
#seq = 0;
|
|
43
49
|
constructor(limit, options = {}) {
|
|
44
50
|
this.#limit = Math.max(1, limit);
|
|
@@ -48,7 +54,7 @@ export class Scheduler {
|
|
|
48
54
|
return this.#pending.size;
|
|
49
55
|
}
|
|
50
56
|
get runningCount() {
|
|
51
|
-
return this.#running.size;
|
|
57
|
+
return this.#running.size + this.#aborting.size;
|
|
52
58
|
}
|
|
53
59
|
#hasMoreUrgentRunning(priority) {
|
|
54
60
|
for (const entry of this.#running.values()) {
|
|
@@ -90,6 +96,8 @@ export class Scheduler {
|
|
|
90
96
|
finishedAt: 0,
|
|
91
97
|
seq: this.#seq++,
|
|
92
98
|
run: job.run,
|
|
99
|
+
abortable: job.abortable ?? false,
|
|
100
|
+
controller: null,
|
|
93
101
|
waiters: 1,
|
|
94
102
|
started: false,
|
|
95
103
|
resolve,
|
|
@@ -122,10 +130,18 @@ export class Scheduler {
|
|
|
122
130
|
return;
|
|
123
131
|
detached = true;
|
|
124
132
|
entry.waiters--;
|
|
125
|
-
if (entry.waiters > 0
|
|
133
|
+
if (entry.waiters > 0)
|
|
134
|
+
return;
|
|
135
|
+
if (!entry.started) {
|
|
136
|
+
this.#pending.delete(entry.key);
|
|
137
|
+
entry.reject(new AbortError(reason));
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (!entry.controller || this.#running.get(entry.key) !== entry)
|
|
126
141
|
return;
|
|
127
|
-
this.#
|
|
128
|
-
|
|
142
|
+
this.#running.delete(entry.key);
|
|
143
|
+
this.#aborting.add(entry);
|
|
144
|
+
entry.controller.abort(new AbortError(reason));
|
|
129
145
|
},
|
|
130
146
|
};
|
|
131
147
|
}
|
|
@@ -137,7 +153,7 @@ export class Scheduler {
|
|
|
137
153
|
* binary heap need re-heapification on every change, which is a rich source of bugs.
|
|
138
154
|
*/
|
|
139
155
|
#drain() {
|
|
140
|
-
while (this
|
|
156
|
+
while (this.runningCount < this.#limit && this.#pending.size > 0) {
|
|
141
157
|
let next;
|
|
142
158
|
for (const entry of this.#pending.values()) {
|
|
143
159
|
if (!next ||
|
|
@@ -156,10 +172,12 @@ export class Scheduler {
|
|
|
156
172
|
this.#running.set(next.key, next);
|
|
157
173
|
next.started = true;
|
|
158
174
|
next.startedAt = performance.now();
|
|
175
|
+
if (next.abortable)
|
|
176
|
+
next.controller = new AbortController();
|
|
159
177
|
// Stamp the finish time before settling, so `timing` is already populated by
|
|
160
178
|
// the time an awaiting caller resumes — a `.finally()` would run after them.
|
|
161
179
|
next
|
|
162
|
-
.run()
|
|
180
|
+
.run(next.controller?.signal)
|
|
163
181
|
.then((value) => {
|
|
164
182
|
next.finishedAt = performance.now();
|
|
165
183
|
next.resolve(value);
|
|
@@ -168,7 +186,8 @@ export class Scheduler {
|
|
|
168
186
|
next.reject(error);
|
|
169
187
|
})
|
|
170
188
|
.finally(() => {
|
|
171
|
-
this.#
|
|
189
|
+
if (!this.#aborting.delete(next))
|
|
190
|
+
this.#running.delete(next.key);
|
|
172
191
|
this.#drain();
|
|
173
192
|
});
|
|
174
193
|
}
|
package/dist/scheduler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,6EAA6E;AAC7E,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,6EAA6E;AAC7E,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAmElC;;;;;GAKG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnC,6BAA6B;IACX,IAAI,GAAG,YAAY,CAAC;IACtC,YAAY,MAAM,GAAG,WAAW;QAC9B,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;CACF;AAiBD;;;;;;;GAOG;AACH,MAAM,OAAO,SAAS;IACX,MAAM,CAAS;IACf,cAAc,CAAU;IACxB,QAAQ,GAAG,IAAI,GAAG,EAA0B,CAAC;IAC7C,QAAQ,GAAG,IAAI,GAAG,EAA0B,CAAC;IACtD;;;;OAIG;IACM,SAAS,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YACtB,CAAC,EACD,CAAC,KAAK,EAAE,EAAE;gBACR,IAAI,CAAC,UAAU,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;gBACpC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACrB,CAAC,CACF;iBACA,OAAO,CAAC,GAAG,EAAE;gBACZ,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC;oBAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBACjE,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,CAAC,CAAC,CAAC;QACP,CAAC;IACH,CAAC;CACF"}
|
package/dist/sheets.d.ts
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import type { Sheet as NativeSheet, Workbook as NativeWorkbook } from '@build-qube/papyra-native';
|
|
2
|
+
import { CellWindow, type MergedRange } from './cells.js';
|
|
3
|
+
import { type CellStyle, type SheetLayout } from './styles.js';
|
|
4
|
+
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
|
+
/**
|
|
63
|
+
* What a {@link Sheet} reads: papyra's own addon, or another host holding the file —
|
|
64
|
+
* a Tauri app's, through `@build-qube/papyra-tauri`. `window` stays synchronous, so a
|
|
65
|
+
* remote host answers it from cells it already fetched.
|
|
66
|
+
*/
|
|
67
|
+
export type SheetSource = Pick<NativeSheet, 'name' | 'rows' | 'cols' | 'truncated' | 'merges' | 'styles' | 'layout' | 'window'>;
|
|
68
|
+
/** What a {@link Workbook} reads, in the addon's shapes. See {@link SheetSource}. */
|
|
69
|
+
export interface WorkbookSource extends Pick<NativeWorkbook, 'format' | 'sheets' | 'encoding' | 'delimiter'> {
|
|
70
|
+
/** Parse one sheet. */
|
|
71
|
+
sheet(index: number): Promise<SheetSource>;
|
|
72
|
+
/** Free the workbook where it is held. Absent where the garbage collector does. */
|
|
73
|
+
close?(): Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* `openWorkbook` over any {@link WorkbookSource}: the bytes, the `.tsv` rule and the
|
|
77
|
+
* typed errors, whoever does the parsing.
|
|
78
|
+
*
|
|
79
|
+
* @internal For papyra's own `openWorkbook` and other hosts'.
|
|
80
|
+
*/
|
|
81
|
+
export declare function openWorkbookWith(load: (bytes: Uint8Array, options: WorkbookOptions) => Promise<WorkbookSource>, source: PdfSource, options?: WorkbookOptions): Promise<Workbook>;
|
|
82
|
+
/** An opened spreadsheet. Get one from `openWorkbook`. */
|
|
83
|
+
export declare class Workbook {
|
|
84
|
+
#private;
|
|
85
|
+
/** The container actually read. */
|
|
86
|
+
readonly format: WorkbookFormat;
|
|
87
|
+
/** Every sheet in tab order, hidden ones included. */
|
|
88
|
+
readonly sheets: readonly SheetInfo[];
|
|
89
|
+
/**
|
|
90
|
+
* CSV and TSV only: the encoding the text was decoded from, e.g.
|
|
91
|
+
* `'windows-1252'`. Worth showing when it was guessed — a wrong guess reads as
|
|
92
|
+
* mojibake, and {@link WorkbookOptions.encoding} is the fix.
|
|
93
|
+
*/
|
|
94
|
+
readonly encoding: string | undefined;
|
|
95
|
+
/** CSV and TSV only: the delimiter, given or sniffed. */
|
|
96
|
+
readonly delimiter: string | undefined;
|
|
97
|
+
/** @internal — construct via `openWorkbook`. */
|
|
98
|
+
constructor(native: WorkbookSource);
|
|
99
|
+
/**
|
|
100
|
+
* Read one sheet, by index or by name.
|
|
101
|
+
*
|
|
102
|
+
* The first call parses the sheet, off the JS thread; later calls for the same
|
|
103
|
+
* sheet share that result.
|
|
104
|
+
*/
|
|
105
|
+
sheet(which: number | string): Promise<Sheet>;
|
|
106
|
+
/**
|
|
107
|
+
* Free the workbook. A no-op for papyra's own, which the garbage collector frees; a
|
|
108
|
+
* host holding it — a Tauri app's — frees it now, and would otherwise keep it until
|
|
109
|
+
* the page reloads. Sheets already read keep their cells.
|
|
110
|
+
*/
|
|
111
|
+
close(): Promise<void>;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* One sheet, parsed and held in Rust. Read it a window at a time.
|
|
115
|
+
*
|
|
116
|
+
* Coordinates are the sheet's own and 0-based: row 0 is the row Excel labels 1, and
|
|
117
|
+
* a sheet whose data starts at F10 still reports ten rows and six columns, so a grid
|
|
118
|
+
* draws the data where its author put it.
|
|
119
|
+
*/
|
|
120
|
+
export declare class Sheet {
|
|
121
|
+
#private;
|
|
122
|
+
/** The name on the sheet's tab. */
|
|
123
|
+
readonly name: string;
|
|
124
|
+
/** One past the last row holding a value or covered by a merge. */
|
|
125
|
+
readonly rows: number;
|
|
126
|
+
/**
|
|
127
|
+
* The sheet held more cells than {@link WorkbookOptions.maxCells}, and this is
|
|
128
|
+
* its first whole rows. Worth saying on screen: the rest of the file is not here.
|
|
129
|
+
*/
|
|
130
|
+
readonly truncated: boolean;
|
|
131
|
+
/** One past the last column holding a value or covered by a merge. */
|
|
132
|
+
readonly cols: number;
|
|
133
|
+
/**
|
|
134
|
+
* Merged regions. The value lives in each one's top-left cell; the others are
|
|
135
|
+
* empty. Always empty for `.xlsb` and `.ods`, which calamine does not read
|
|
136
|
+
* merges from.
|
|
137
|
+
*/
|
|
138
|
+
readonly merges: readonly MergedRange[];
|
|
139
|
+
/**
|
|
140
|
+
* The styles {@link CellWindow.style} indexes into, with the default at 0.
|
|
141
|
+
* xlsx only: empty for every other format, whose cells all read as style 0.
|
|
142
|
+
*/
|
|
143
|
+
readonly styles: readonly CellStyle[];
|
|
144
|
+
/**
|
|
145
|
+
* Column widths and row heights as the author set them. xlsx only; for anything
|
|
146
|
+
* else a grid sizes columns itself.
|
|
147
|
+
*/
|
|
148
|
+
readonly layout: SheetLayout | undefined;
|
|
149
|
+
/** @internal — construct via {@link Workbook.sheet}. */
|
|
150
|
+
constructor(native: SheetSource);
|
|
151
|
+
/**
|
|
152
|
+
* Read a rectangle of cells, clamped to the sheet.
|
|
153
|
+
*
|
|
154
|
+
* Synchronous, because the sheet is already parsed and the cost is the size of
|
|
155
|
+
* the window. Ask for what is on screen plus some overscan, not the whole sheet:
|
|
156
|
+
* a screenful is a few thousand cells and well under a millisecond.
|
|
157
|
+
*/
|
|
158
|
+
window(range: WindowRange): CellWindow;
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=sheets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sheets.d.ts","sourceRoot":"","sources":["../src/sheets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,IAAI,WAAW,EACpB,QAAQ,IAAI,cAAc,EAC3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,KAAK,WAAW,EAAkB,MAAM,YAAY,CAAC;AAG1E,OAAO,EACL,KAAK,SAAS,EACd,KAAK,WAAW,EAGjB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG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,MAAM,EAAE,SAAS,SAAS,EAAE,CAAC;IACtC;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,CAAC;IAGzC,wDAAwD;IACxD,YAAY,MAAM,EAAE,WAAW,EAS9B;IAED;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,UAAU,CAWrC;CACF"}
|
package/dist/sheets.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { CellWindow, toMergedRanges } from './cells.js';
|
|
2
|
+
import { rethrowLoadError } from './errors.js';
|
|
3
|
+
import { toBytes } from './source.js';
|
|
4
|
+
import { toCellStyle, toSheetLayout, } from './styles.js';
|
|
5
|
+
/**
|
|
6
|
+
* `openWorkbook` over any {@link WorkbookSource}: the bytes, the `.tsv` rule and the
|
|
7
|
+
* typed errors, whoever does the parsing.
|
|
8
|
+
*
|
|
9
|
+
* @internal For papyra's own `openWorkbook` and other hosts'.
|
|
10
|
+
*/
|
|
11
|
+
export async function openWorkbookWith(load, source, options = {}) {
|
|
12
|
+
const bytes = await toBytes(source);
|
|
13
|
+
const format = options.format ?? formatFromName(source);
|
|
14
|
+
try {
|
|
15
|
+
return new Workbook(await load(bytes, { ...options, format }));
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
rethrowLoadError(error);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A `File` named `.tsv` is TSV whatever its contents sniff as.
|
|
23
|
+
*
|
|
24
|
+
* Only that one extension is trusted. The binary formats announce themselves in
|
|
25
|
+
* their first bytes, and a `.xls` downloaded from a web app is as often an HTML
|
|
26
|
+
* table or a CSV as it is BIFF — believing the name would refuse a readable file.
|
|
27
|
+
*/
|
|
28
|
+
function formatFromName(source) {
|
|
29
|
+
const name = source.name;
|
|
30
|
+
return typeof name === 'string' && /\.(tsv|tab)$/i.test(name)
|
|
31
|
+
? 'tsv'
|
|
32
|
+
: undefined;
|
|
33
|
+
}
|
|
34
|
+
/** An opened spreadsheet. Get one from `openWorkbook`. */
|
|
35
|
+
export class Workbook {
|
|
36
|
+
/** The container actually read. */
|
|
37
|
+
format;
|
|
38
|
+
/** Every sheet in tab order, hidden ones included. */
|
|
39
|
+
sheets;
|
|
40
|
+
/**
|
|
41
|
+
* CSV and TSV only: the encoding the text was decoded from, e.g.
|
|
42
|
+
* `'windows-1252'`. Worth showing when it was guessed — a wrong guess reads as
|
|
43
|
+
* mojibake, and {@link WorkbookOptions.encoding} is the fix.
|
|
44
|
+
*/
|
|
45
|
+
encoding;
|
|
46
|
+
/** CSV and TSV only: the delimiter, given or sniffed. */
|
|
47
|
+
delimiter;
|
|
48
|
+
#native;
|
|
49
|
+
#sheets = new Map();
|
|
50
|
+
/** @internal — construct via `openWorkbook`. */
|
|
51
|
+
constructor(native) {
|
|
52
|
+
this.#native = native;
|
|
53
|
+
this.format = native.format;
|
|
54
|
+
this.sheets = native.sheets.map((s) => ({
|
|
55
|
+
name: s.name,
|
|
56
|
+
kind: s.kind,
|
|
57
|
+
visibility: s.visibility,
|
|
58
|
+
}));
|
|
59
|
+
this.encoding = native.encoding ?? undefined;
|
|
60
|
+
this.delimiter = native.delimiter ?? undefined;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Read one sheet, by index or by name.
|
|
64
|
+
*
|
|
65
|
+
* The first call parses the sheet, off the JS thread; later calls for the same
|
|
66
|
+
* sheet share that result.
|
|
67
|
+
*/
|
|
68
|
+
sheet(which) {
|
|
69
|
+
const index = typeof which === 'number'
|
|
70
|
+
? which
|
|
71
|
+
: this.sheets.findIndex((s) => s.name === which);
|
|
72
|
+
if (!Number.isInteger(index) || index < 0 || index >= this.sheets.length) {
|
|
73
|
+
return Promise.reject(new RangeError(`papyra: no sheet ${JSON.stringify(which)}`));
|
|
74
|
+
}
|
|
75
|
+
let sheet = this.#sheets.get(index);
|
|
76
|
+
if (!sheet) {
|
|
77
|
+
sheet = this.#native.sheet(index).then((native) => new Sheet(native));
|
|
78
|
+
// A failed read is not cached, so a retry gets a fresh attempt.
|
|
79
|
+
sheet.catch(() => this.#sheets.delete(index));
|
|
80
|
+
this.#sheets.set(index, sheet);
|
|
81
|
+
}
|
|
82
|
+
return sheet;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Free the workbook. A no-op for papyra's own, which the garbage collector frees; a
|
|
86
|
+
* host holding it — a Tauri app's — frees it now, and would otherwise keep it until
|
|
87
|
+
* the page reloads. Sheets already read keep their cells.
|
|
88
|
+
*/
|
|
89
|
+
async close() {
|
|
90
|
+
await this.#native.close?.();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* One sheet, parsed and held in Rust. Read it a window at a time.
|
|
95
|
+
*
|
|
96
|
+
* Coordinates are the sheet's own and 0-based: row 0 is the row Excel labels 1, and
|
|
97
|
+
* a sheet whose data starts at F10 still reports ten rows and six columns, so a grid
|
|
98
|
+
* draws the data where its author put it.
|
|
99
|
+
*/
|
|
100
|
+
export class Sheet {
|
|
101
|
+
/** The name on the sheet's tab. */
|
|
102
|
+
name;
|
|
103
|
+
/** One past the last row holding a value or covered by a merge. */
|
|
104
|
+
rows;
|
|
105
|
+
/**
|
|
106
|
+
* The sheet held more cells than {@link WorkbookOptions.maxCells}, and this is
|
|
107
|
+
* its first whole rows. Worth saying on screen: the rest of the file is not here.
|
|
108
|
+
*/
|
|
109
|
+
truncated;
|
|
110
|
+
/** One past the last column holding a value or covered by a merge. */
|
|
111
|
+
cols;
|
|
112
|
+
/**
|
|
113
|
+
* Merged regions. The value lives in each one's top-left cell; the others are
|
|
114
|
+
* empty. Always empty for `.xlsb` and `.ods`, which calamine does not read
|
|
115
|
+
* merges from.
|
|
116
|
+
*/
|
|
117
|
+
merges;
|
|
118
|
+
/**
|
|
119
|
+
* The styles {@link CellWindow.style} indexes into, with the default at 0.
|
|
120
|
+
* xlsx only: empty for every other format, whose cells all read as style 0.
|
|
121
|
+
*/
|
|
122
|
+
styles;
|
|
123
|
+
/**
|
|
124
|
+
* Column widths and row heights as the author set them. xlsx only; for anything
|
|
125
|
+
* else a grid sizes columns itself.
|
|
126
|
+
*/
|
|
127
|
+
layout;
|
|
128
|
+
#native;
|
|
129
|
+
/** @internal — construct via {@link Workbook.sheet}. */
|
|
130
|
+
constructor(native) {
|
|
131
|
+
this.#native = native;
|
|
132
|
+
this.name = native.name;
|
|
133
|
+
this.rows = native.rows;
|
|
134
|
+
this.truncated = native.truncated;
|
|
135
|
+
this.cols = native.cols;
|
|
136
|
+
this.merges = toMergedRanges(native.merges);
|
|
137
|
+
this.styles = native.styles.map(toCellStyle);
|
|
138
|
+
this.layout = native.layout ? toSheetLayout(native.layout) : undefined;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Read a rectangle of cells, clamped to the sheet.
|
|
142
|
+
*
|
|
143
|
+
* Synchronous, because the sheet is already parsed and the cost is the size of
|
|
144
|
+
* the window. Ask for what is on screen plus some overscan, not the whole sheet:
|
|
145
|
+
* a screenful is a few thousand cells and well under a millisecond.
|
|
146
|
+
*/
|
|
147
|
+
window(range) {
|
|
148
|
+
// The bindings take u32s, which a negative overscan would wrap rather than clamp.
|
|
149
|
+
const at = (n) => Math.max(0, Math.floor(n));
|
|
150
|
+
return new CellWindow(this.#native.window(at(range.rowStart), at(range.rowEnd), at(range.colStart ?? 0), at(range.colEnd ?? this.cols)));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=sheets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sheets.js","sourceRoot":"","sources":["../src/sheets.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAoB,cAAc,EAAE,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAGL,WAAW,EACX,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C,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACrD,OAAO,IAAI,UAAU,CACnB,IAAI,CAAC,OAAO,CAAC,MAAM,CACjB,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,EAClB,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,EAChB,EAAE,CAAC,KAAK,CAAC,QAAQ,IAAI,CAAC,CAAC,EACvB,EAAE,CAAC,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,CAC9B,CACF,CAAC;IACJ,CAAC;CACF"}
|
package/dist/source.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { PdfSource } from './types.js';
|
|
|
3
3
|
* Normalise any accepted input to bytes.
|
|
4
4
|
*
|
|
5
5
|
* Accepts `File` and `Blob` so an `<input type="file">` value can be passed straight
|
|
6
|
-
* through, which is the common case in a viewer.
|
|
6
|
+
* through, which is the common case in a viewer. An engine's loader starts here.
|
|
7
7
|
*/
|
|
8
8
|
export declare function toBytes(source: PdfSource): Promise<Uint8Array>;
|
|
9
9
|
//# sourceMappingURL=source.d.ts.map
|
package/dist/source.js
CHANGED
|
@@ -5,7 +5,7 @@ function isBlob(value) {
|
|
|
5
5
|
* Normalise any accepted input to bytes.
|
|
6
6
|
*
|
|
7
7
|
* Accepts `File` and `Blob` so an `<input type="file">` value can be passed straight
|
|
8
|
-
* through, which is the common case in a viewer.
|
|
8
|
+
* through, which is the common case in a viewer. An engine's loader starts here.
|
|
9
9
|
*/
|
|
10
10
|
export async function toBytes(source) {
|
|
11
11
|
if (source instanceof Uint8Array)
|
package/dist/text.d.ts
CHANGED
|
@@ -108,7 +108,12 @@ export interface Rect {
|
|
|
108
108
|
/** Height. */
|
|
109
109
|
readonly height: number;
|
|
110
110
|
}
|
|
111
|
-
/**
|
|
111
|
+
/**
|
|
112
|
+
* A page's text as the bindings report it, as a {@link PageText}.
|
|
113
|
+
*
|
|
114
|
+
* Exported for engines whose host answers in the native bindings' shapes, as
|
|
115
|
+
* `tauri-plugin-papyra` does, so they normalise exactly as papyra's own engine does.
|
|
116
|
+
*/
|
|
112
117
|
export declare function toPageText(page: number, native: NativePageText): PageText;
|
|
113
118
|
/** Every character on the page a search can see. */
|
|
114
119
|
export declare function pageString(text: PageText): string;
|
package/dist/text.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../src/text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,IAAI,cAAc,EAE3B,MAAM,2BAA2B,CAAC;AAEnC;;;;;;;GAOG;AACH,MAAM,WAAW,QAAQ;IACvB,wEAAwE;IACxE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAC/B,gCAAgC;IAChC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,gCAAgC;IAChC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,gFAAgF;IAChF,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,yCAAyC;IACzC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,sDAAsD;IACtD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,iCAAiC;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;;;;;;;;;;;;;;;OAgBG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,QAAQ;IACvB,qDAAqD;IACrD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAC;IACpC;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;CAClC;AAED,+EAA+E;AAC/E,MAAM,WAAW,IAAI;IACnB,m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AAE,MAAM,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,QAAQ,CAMzE;AAED,oDAAoD;AACpD,wBAAgB,UAAU,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAEjD;AAED,yEAAyE;AACzE,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAMpD;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAyBzE;AAED,wDAAwD;AACxD,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAM3C;AAED,kEAAkE;AAClE,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAOzD;AAED,kEAAkE;AAClE,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAWzD"}
|
package/dist/text.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* A page's text as the bindings report it, as a {@link PageText}.
|
|
3
|
+
*
|
|
4
|
+
* Exported for engines whose host answers in the native bindings' shapes, as
|
|
5
|
+
* `tauri-plugin-papyra` does, so they normalise exactly as papyra's own engine does.
|
|
6
|
+
*/
|
|
2
7
|
export function toPageText(page, native) {
|
|
3
8
|
return {
|
|
4
9
|
page,
|
package/dist/text.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","sourceRoot":"","sources":["../src/text.ts"],"names":[],"mappings":"AAsHA
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../src/text.ts"],"names":[],"mappings":"AAsHA;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,I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+1,97 @@
|
|
|
1
|
+
import type { TiffRenderOptions as NativeTiffRenderOptions, TiffPageInfo } from '@build-qube/papyra-native';
|
|
2
|
+
import type { PageBitmap, RenderedPage } from './types.js';
|
|
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;
|
|
53
|
+
/**
|
|
54
|
+
* What a {@link TiffImage} reads: papyra's own addon, or another host holding the
|
|
55
|
+
* file — a Tauri app's, through `@build-qube/papyra-tauri`.
|
|
56
|
+
*/
|
|
57
|
+
export interface TiffSource<P extends PageBitmap = RenderedPage> {
|
|
58
|
+
/** Every page, in the addon's shape. */
|
|
59
|
+
readonly pages: readonly TiffPageInfo[];
|
|
60
|
+
/** Decode one page at no more than the given size. */
|
|
61
|
+
renderPage(index: number, options?: NativeTiffRenderOptions): Promise<P>;
|
|
62
|
+
/** Free the file where it is held. Absent where the garbage collector does. */
|
|
63
|
+
close?(): Promise<void>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* An opened TIFF. Get one from `openTiff`.
|
|
67
|
+
*
|
|
68
|
+
* `P` is what a page decodes to: RGBA from papyra's own addon, and an `ImageBitmap`
|
|
69
|
+
* too from a host that sends pages as PNG.
|
|
70
|
+
*/
|
|
71
|
+
export declare class TiffImage<P extends PageBitmap = RenderedPage> {
|
|
72
|
+
#private;
|
|
73
|
+
/**
|
|
74
|
+
* Every page, in file order. A reduced-resolution copy of a page — a thumbnail, a
|
|
75
|
+
* pyramid level — is not a page and is left out.
|
|
76
|
+
*/
|
|
77
|
+
readonly pages: readonly TiffPage[];
|
|
78
|
+
/** @internal — construct via `openTiff`. */
|
|
79
|
+
constructor(native: TiffSource<P>);
|
|
80
|
+
/** How many pages there are. */
|
|
81
|
+
get pageCount(): number;
|
|
82
|
+
/**
|
|
83
|
+
* Decode one page to RGBA, upright, at no more than `options` allows.
|
|
84
|
+
*
|
|
85
|
+
* Paint the result with `paintToCanvas`, or encode it with `encode`, exactly as a
|
|
86
|
+
* rendered PDF page. Each call decodes the page again; keep the result if it will
|
|
87
|
+
* be shown again.
|
|
88
|
+
*/
|
|
89
|
+
renderPage(index: number, options?: TiffRenderOptions): Promise<P>;
|
|
90
|
+
/**
|
|
91
|
+
* Free the file. A no-op for papyra's own, which the garbage collector frees; a
|
|
92
|
+
* host holding it — a Tauri app's — frees it now, and would otherwise keep it until
|
|
93
|
+
* the page reloads.
|
|
94
|
+
*/
|
|
95
|
+
close(): Promise<void>;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=tiff-image.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tiff-image.d.ts","sourceRoot":"","sources":["../src/tiff-image.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,IAAI,uBAAuB,EAC5C,YAAY,EACb,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE3D;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GACvB,MAAM,GACN,WAAW,GACX,UAAU,GACV,UAAU,GACV,KAAK,GACL,UAAU,GACV,MAAM,GACN,SAAS,GACT,UAAU,GACV,OAAO,CAAC;AAEZ,uFAAuF;AACvF,MAAM,WAAW,QAAQ;IACvB,2CAA2C;IAC3C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,4CAA4C;IAC5C,QAAQ,CAAC,MAAM,EAAE,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