@evotecit/officeimo 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1222 -2
- package/bundles/officeimo-canopyx.js +11741 -0
- package/bundles/officeimo-canopyx.mjs +11639 -0
- package/bundles/officeimo-csv.js +1264 -0
- package/bundles/officeimo-csv.mjs +1239 -0
- package/bundles/officeimo-datatables.js +12018 -0
- package/bundles/officeimo-datatables.mjs +11915 -0
- package/bundles/officeimo-execution.js +1513 -0
- package/bundles/officeimo-execution.mjs +1489 -0
- package/bundles/officeimo-pdf.js +7009 -0
- package/bundles/officeimo-pdf.mjs +6946 -0
- package/bundles/officeimo-xlsx.js +5344 -0
- package/bundles/officeimo-xlsx.mjs +5290 -0
- package/bundles/officeimo.js +11468 -0
- package/bundles/officeimo.mjs +11369 -0
- package/dist/core/dates.d.ts +1 -0
- package/dist/core/dates.js +16 -0
- package/dist/core/errors.d.ts +12 -0
- package/dist/core/errors.js +31 -0
- package/dist/core/grouped-report.d.ts +87 -0
- package/dist/core/grouped-report.js +252 -0
- package/dist/core/index.d.ts +74 -0
- package/dist/core/index.js +37 -0
- package/dist/core/iteration.d.ts +7 -0
- package/dist/core/iteration.js +149 -0
- package/dist/core/limits.d.ts +7 -0
- package/dist/core/limits.js +56 -0
- package/dist/core/links.d.ts +5 -0
- package/dist/core/links.js +14 -0
- package/dist/core/presentation.d.ts +29 -0
- package/dist/core/presentation.js +59 -0
- package/dist/core/progress.d.ts +1 -0
- package/dist/core/progress.js +10 -0
- package/dist/core/sinks.d.ts +33 -0
- package/dist/core/sinks.js +102 -0
- package/dist/core/table.d.ts +8 -0
- package/dist/core/table.js +1 -0
- package/dist/core/value-text.d.ts +7 -0
- package/dist/core/value-text.js +13 -0
- package/dist/csv/index.d.ts +44 -0
- package/dist/csv/index.js +133 -0
- package/dist/csv/options.d.ts +1 -0
- package/dist/csv/options.js +8 -0
- package/dist/csv/structured-rows.d.ts +3 -0
- package/dist/csv/structured-rows.js +15 -0
- package/dist/execution/host.d.ts +5 -0
- package/dist/execution/host.js +164 -0
- package/dist/execution/index.d.ts +3 -0
- package/dist/execution/index.js +2 -0
- package/dist/execution/protocol.d.ts +48 -0
- package/dist/execution/protocol.js +173 -0
- package/dist/execution/types.d.ts +42 -0
- package/dist/execution/types.js +1 -0
- package/dist/execution/worker.d.ts +3 -0
- package/dist/execution/worker.js +147 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +14 -0
- package/dist/integrations/canopyx/dates.d.ts +1 -0
- package/dist/integrations/canopyx/dates.js +34 -0
- package/dist/integrations/canopyx/index.d.ts +10 -0
- package/dist/integrations/canopyx/index.js +45 -0
- package/dist/integrations/canopyx/source.d.ts +3 -0
- package/dist/integrations/canopyx/source.js +122 -0
- package/dist/integrations/canopyx/types.d.ts +83 -0
- package/dist/integrations/canopyx/types.js +1 -0
- package/dist/integrations/datatables/api.d.ts +1 -0
- package/dist/integrations/datatables/api.js +27 -0
- package/dist/integrations/datatables/headings.d.ts +1 -0
- package/dist/integrations/datatables/headings.js +65 -0
- package/dist/integrations/datatables/index.d.ts +12 -0
- package/dist/integrations/datatables/index.js +167 -0
- package/dist/integrations/datatables/snapshot.d.ts +3 -0
- package/dist/integrations/datatables/snapshot.js +206 -0
- package/dist/integrations/datatables/types.d.ts +98 -0
- package/dist/integrations/datatables/types.js +1 -0
- package/dist/integrations/options.d.ts +13 -0
- package/dist/integrations/options.js +34 -0
- package/dist/internal/capture.d.ts +4 -0
- package/dist/internal/capture.js +14 -0
- package/dist/internal/columns.d.ts +27 -0
- package/dist/internal/columns.js +1 -0
- package/dist/internal/crc32.d.ts +6 -0
- package/dist/internal/crc32.js +17 -0
- package/dist/internal/export-values.d.ts +3 -0
- package/dist/internal/export-values.js +14 -0
- package/dist/internal/rows.d.ts +6 -0
- package/dist/internal/rows.js +77 -0
- package/dist/internal/table-spans.d.ts +11 -0
- package/dist/internal/table-spans.js +58 -0
- package/dist/internal/totals.d.ts +15 -0
- package/dist/internal/totals.js +42 -0
- package/dist/opc/index.d.ts +67 -0
- package/dist/opc/index.js +233 -0
- package/dist/opc/properties.d.ts +15 -0
- package/dist/opc/properties.js +18 -0
- package/dist/opc/uri.d.ts +5 -0
- package/dist/opc/uri.js +41 -0
- package/dist/pdf/annotations.d.ts +1 -0
- package/dist/pdf/annotations.js +38 -0
- package/dist/pdf/binary.d.ts +6 -0
- package/dist/pdf/binary.js +24 -0
- package/dist/pdf/document-drawings.d.ts +15 -0
- package/dist/pdf/document-drawings.js +237 -0
- package/dist/pdf/document-grouped.d.ts +1 -0
- package/dist/pdf/document-grouped.js +244 -0
- package/dist/pdf/document-images.d.ts +19 -0
- package/dist/pdf/document-images.js +125 -0
- package/dist/pdf/document-types.d.ts +160 -0
- package/dist/pdf/document-types.js +1 -0
- package/dist/pdf/document-vectors.d.ts +11 -0
- package/dist/pdf/document-vectors.js +77 -0
- package/dist/pdf/document.d.ts +9 -0
- package/dist/pdf/document.js +270 -0
- package/dist/pdf/drawing-types.d.ts +53 -0
- package/dist/pdf/drawing-types.js +1 -0
- package/dist/pdf/font-resources.d.ts +43 -0
- package/dist/pdf/font-resources.js +202 -0
- package/dist/pdf/font-support.d.ts +1 -0
- package/dist/pdf/font-support.js +60 -0
- package/dist/pdf/font.d.ts +17 -0
- package/dist/pdf/font.js +56 -0
- package/dist/pdf/grouped-table.d.ts +6 -0
- package/dist/pdf/grouped-table.js +40 -0
- package/dist/pdf/grouped-types.d.ts +34 -0
- package/dist/pdf/grouped-types.js +1 -0
- package/dist/pdf/grouped.d.ts +10 -0
- package/dist/pdf/grouped.js +37 -0
- package/dist/pdf/index.d.ts +22 -0
- package/dist/pdf/index.js +8 -0
- package/dist/pdf/inline-text.d.ts +30 -0
- package/dist/pdf/inline-text.js +183 -0
- package/dist/pdf/inline-types.d.ts +15 -0
- package/dist/pdf/inline-types.js +1 -0
- package/dist/pdf/list-layout.d.ts +6 -0
- package/dist/pdf/list-layout.js +49 -0
- package/dist/pdf/objects.d.ts +2 -0
- package/dist/pdf/objects.js +320 -0
- package/dist/pdf/outlines.d.ts +1 -0
- package/dist/pdf/outlines.js +55 -0
- package/dist/pdf/page-context.d.ts +1 -0
- package/dist/pdf/page-context.js +12 -0
- package/dist/pdf/pages.d.ts +1 -0
- package/dist/pdf/pages.js +678 -0
- package/dist/pdf/paragraph-layout.d.ts +21 -0
- package/dist/pdf/paragraph-layout.js +71 -0
- package/dist/pdf/paragraph-styles.d.ts +1 -0
- package/dist/pdf/paragraph-styles.js +66 -0
- package/dist/pdf/png.d.ts +9 -0
- package/dist/pdf/png.js +259 -0
- package/dist/pdf/preflight.d.ts +7 -0
- package/dist/pdf/preflight.js +32 -0
- package/dist/pdf/presentation-settings.d.ts +5 -0
- package/dist/pdf/presentation-settings.js +28 -0
- package/dist/pdf/providers/harfbuzz.d.ts +60 -0
- package/dist/pdf/providers/harfbuzz.js +112 -0
- package/dist/pdf/providers/unicode13-profile.d.ts +2 -0
- package/dist/pdf/providers/unicode13-profile.js +115 -0
- package/dist/pdf/section-types.d.ts +15 -0
- package/dist/pdf/section-types.js +40 -0
- package/dist/pdf/session.d.ts +25 -0
- package/dist/pdf/session.js +55 -0
- package/dist/pdf/settings.d.ts +17 -0
- package/dist/pdf/settings.js +196 -0
- package/dist/pdf/shaped-text.d.ts +5 -0
- package/dist/pdf/shaped-text.js +205 -0
- package/dist/pdf/standard-widths.d.ts +1 -0
- package/dist/pdf/standard-widths.js +317 -0
- package/dist/pdf/structure-parent-tree.d.ts +1 -0
- package/dist/pdf/structure-parent-tree.js +57 -0
- package/dist/pdf/structure.d.ts +6 -0
- package/dist/pdf/structure.js +302 -0
- package/dist/pdf/table-band-flow.d.ts +34 -0
- package/dist/pdf/table-band-flow.js +129 -0
- package/dist/pdf/table-band-plan.d.ts +10 -0
- package/dist/pdf/table-band-plan.js +83 -0
- package/dist/pdf/table-layout.d.ts +75 -0
- package/dist/pdf/table-layout.js +217 -0
- package/dist/pdf/table-structure.d.ts +1 -0
- package/dist/pdf/table-structure.js +108 -0
- package/dist/pdf/text-shaping-types.d.ts +39 -0
- package/dist/pdf/text-shaping-types.js +1 -0
- package/dist/pdf/text.d.ts +13 -0
- package/dist/pdf/text.js +101 -0
- package/dist/pdf/truetype-subset.d.ts +5 -0
- package/dist/pdf/truetype-subset.js +217 -0
- package/dist/pdf/truetype.d.ts +1 -0
- package/dist/pdf/truetype.js +235 -0
- package/dist/pdf/types.d.ts +171 -0
- package/dist/pdf/types.js +1 -0
- package/dist/pdf/write.d.ts +6 -0
- package/dist/pdf/write.js +57 -0
- package/dist/pdf/xref.d.ts +1 -0
- package/dist/pdf/xref.js +30 -0
- package/dist/xlsx/attachments.d.ts +30 -0
- package/dist/xlsx/attachments.js +67 -0
- package/dist/xlsx/chart-bindings.d.ts +1 -0
- package/dist/xlsx/chart-bindings.js +122 -0
- package/dist/xlsx/chart-types.d.ts +73 -0
- package/dist/xlsx/chart-types.js +1 -0
- package/dist/xlsx/chart-xml.d.ts +2 -0
- package/dist/xlsx/chart-xml.js +103 -0
- package/dist/xlsx/charts.d.ts +1 -0
- package/dist/xlsx/charts.js +159 -0
- package/dist/xlsx/conditional-formatting.d.ts +1 -0
- package/dist/xlsx/conditional-formatting.js +158 -0
- package/dist/xlsx/conditional-types.d.ts +64 -0
- package/dist/xlsx/conditional-types.js +1 -0
- package/dist/xlsx/data-row-ranges.d.ts +5 -0
- package/dist/xlsx/data-row-ranges.js +39 -0
- package/dist/xlsx/differential-styles.d.ts +1 -0
- package/dist/xlsx/differential-styles.js +102 -0
- package/dist/xlsx/formula.d.ts +8 -0
- package/dist/xlsx/formula.js +104 -0
- package/dist/xlsx/grouped-layout.d.ts +61 -0
- package/dist/xlsx/grouped-layout.js +79 -0
- package/dist/xlsx/grouped.d.ts +16 -0
- package/dist/xlsx/grouped.js +161 -0
- package/dist/xlsx/index.d.ts +24 -0
- package/dist/xlsx/index.js +10 -0
- package/dist/xlsx/layout.d.ts +1 -0
- package/dist/xlsx/layout.js +186 -0
- package/dist/xlsx/options.d.ts +1 -0
- package/dist/xlsx/options.js +16 -0
- package/dist/xlsx/portable.d.ts +27 -0
- package/dist/xlsx/portable.js +44 -0
- package/dist/xlsx/preservation.d.ts +1 -0
- package/dist/xlsx/preservation.js +60 -0
- package/dist/xlsx/ranges.d.ts +1 -0
- package/dist/xlsx/ranges.js +24 -0
- package/dist/xlsx/regions.d.ts +1 -0
- package/dist/xlsx/regions.js +97 -0
- package/dist/xlsx/structured-rows.d.ts +11 -0
- package/dist/xlsx/structured-rows.js +28 -0
- package/dist/xlsx/style-xml.d.ts +1 -0
- package/dist/xlsx/style-xml.js +6 -0
- package/dist/xlsx/styles.d.ts +70 -0
- package/dist/xlsx/styles.js +203 -0
- package/dist/xlsx/table.d.ts +12 -0
- package/dist/xlsx/table.js +35 -0
- package/dist/xlsx/types.d.ts +180 -0
- package/dist/xlsx/types.js +1 -0
- package/dist/xlsx/validation-types.d.ts +18 -0
- package/dist/xlsx/validation-types.js +1 -0
- package/dist/xlsx/validation.d.ts +1 -0
- package/dist/xlsx/validation.js +92 -0
- package/dist/xlsx/values.d.ts +13 -0
- package/dist/xlsx/values.js +87 -0
- package/dist/xlsx/workbook.d.ts +50 -0
- package/dist/xlsx/workbook.js +452 -0
- package/dist/xlsx/worksheet.d.ts +71 -0
- package/dist/xlsx/worksheet.js +700 -0
- package/dist/xlsx/write.d.ts +15 -0
- package/dist/xlsx/write.js +47 -0
- package/dist/xml/index.d.ts +24 -0
- package/dist/xml/index.js +74 -0
- package/dist/zip/entry.d.ts +39 -0
- package/dist/zip/entry.js +122 -0
- package/dist/zip/index.d.ts +44 -0
- package/dist/zip/index.js +248 -0
- package/package.json +104 -4
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
export function checkAbort(signal) {
|
|
2
|
+
if (signal?.aborted)
|
|
3
|
+
throw signal.reason;
|
|
4
|
+
}
|
|
5
|
+
/** Race a pending producer or sink operation without leaving abort listeners behind. */
|
|
6
|
+
export function withAbort(promise, signal) {
|
|
7
|
+
if (!signal)
|
|
8
|
+
return Promise.resolve(promise);
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
const cleanup = () => signal.removeEventListener("abort", abort);
|
|
11
|
+
const abort = () => { cleanup(); reject(signal.reason); };
|
|
12
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
13
|
+
Promise.resolve(promise).then(value => { cleanup(); resolve(value); }, error => { cleanup(); reject(error); });
|
|
14
|
+
if (signal.aborted)
|
|
15
|
+
abort();
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/** Consume once; return the iterator on failure or cancellation. Pass the signal to I/O producers too. */
|
|
19
|
+
export async function* inputRows(input, signal) {
|
|
20
|
+
checkAbort(signal);
|
|
21
|
+
const iterator = input?.[Symbol.asyncIterator]?.() ?? input?.[Symbol.iterator]?.();
|
|
22
|
+
if (!iterator)
|
|
23
|
+
throw new TypeError("Rows must be a synchronous or asynchronous iterable.");
|
|
24
|
+
let done = false, failed = false;
|
|
25
|
+
try {
|
|
26
|
+
while (true) {
|
|
27
|
+
checkAbort(signal);
|
|
28
|
+
const item = await withAbort(Promise.resolve(iterator.next()), signal);
|
|
29
|
+
checkAbort(signal);
|
|
30
|
+
if (item.done) {
|
|
31
|
+
done = true;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
yield item.value;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
failed = true;
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
if (!done && iterator.return) {
|
|
43
|
+
try {
|
|
44
|
+
const returned = iterator.return();
|
|
45
|
+
if (signal?.aborted || failed)
|
|
46
|
+
Promise.resolve(returned).catch(() => { });
|
|
47
|
+
else
|
|
48
|
+
await withAbort(Promise.resolve(returned), signal);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (!signal?.aborted && !failed)
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const rowConsumers = new WeakMap();
|
|
58
|
+
/** @internal Keep bounded pages as ordinary async rows, with direct batch consumption for owned writers. */
|
|
59
|
+
export function rowsFromBatches(batches) {
|
|
60
|
+
let consumed = false;
|
|
61
|
+
const claim = () => { if (consumed)
|
|
62
|
+
throw new TypeError("A row source can be consumed only once."); consumed = true; };
|
|
63
|
+
const rows = { [Symbol.asyncIterator]() { claim(); return iterate(); } };
|
|
64
|
+
async function* iterate() { for await (const batch of inputRows(batches))
|
|
65
|
+
yield* batch; }
|
|
66
|
+
rowConsumers.set(rows, (signal, accept) => {
|
|
67
|
+
claim();
|
|
68
|
+
return consumeRows(batches, signal, batch => consumeRows(batch, signal, accept));
|
|
69
|
+
});
|
|
70
|
+
return rows;
|
|
71
|
+
}
|
|
72
|
+
/** @internal Concatenate headings, body and footer without another per-row async delegation. */
|
|
73
|
+
export function concatRows(...sources) {
|
|
74
|
+
const rows = { async *[Symbol.asyncIterator]() { for (const source of sources)
|
|
75
|
+
yield* source; } };
|
|
76
|
+
rowConsumers.set(rows, async (signal, accept) => { for (const source of sources)
|
|
77
|
+
await consumeRows(source, signal, accept); });
|
|
78
|
+
return rows;
|
|
79
|
+
}
|
|
80
|
+
/** @internal Consume synchronous work without an async-generator and per-row Promise.
|
|
81
|
+
* Async producers, promised values and destination backpressure keep the same cancellation/return contract. */
|
|
82
|
+
export async function consumeRows(input, signal, accept) {
|
|
83
|
+
checkAbort(signal);
|
|
84
|
+
const consume = rowConsumers.get(input);
|
|
85
|
+
if (consume)
|
|
86
|
+
return consume(signal, accept);
|
|
87
|
+
const iterator = input?.[Symbol.asyncIterator]?.() ?? input?.[Symbol.iterator]?.();
|
|
88
|
+
if (!iterator)
|
|
89
|
+
throw new TypeError("Rows must be a synchronous or asynchronous iterable.");
|
|
90
|
+
let done = false;
|
|
91
|
+
try {
|
|
92
|
+
while (true) {
|
|
93
|
+
checkAbort(signal);
|
|
94
|
+
let item = iterator.next();
|
|
95
|
+
const next = item;
|
|
96
|
+
if (typeof next?.then === "function")
|
|
97
|
+
item = await withAbort(next, signal);
|
|
98
|
+
checkAbort(signal);
|
|
99
|
+
const result = item;
|
|
100
|
+
if (result.done) {
|
|
101
|
+
done = true;
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
let value = result.value;
|
|
105
|
+
if (typeof value?.then === "function")
|
|
106
|
+
value = await withAbort(value, signal);
|
|
107
|
+
checkAbort(signal);
|
|
108
|
+
const pending = accept(value);
|
|
109
|
+
if (pending !== undefined)
|
|
110
|
+
await withAbort(pending, signal);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
if (!done && iterator.return) {
|
|
115
|
+
// Any exit before exhaustion is a producer/consumer failure or cancellation.
|
|
116
|
+
// Observe cleanup, but an unresponsive return must not replace or hold the original failure.
|
|
117
|
+
try {
|
|
118
|
+
void Promise.resolve(iterator.return()).catch(() => { });
|
|
119
|
+
}
|
|
120
|
+
catch { /* Preserve the original failure. */ }
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
let taskDeadline;
|
|
125
|
+
const taskBudgetMs = 32;
|
|
126
|
+
/** @internal Start a new write phase without carrying an idle operation's expired deadline. */
|
|
127
|
+
export function beginTask() { taskDeadline = performance.now() + taskBudgetMs; }
|
|
128
|
+
/** @internal Pipeline stages share the last completed yield instead of pausing back-to-back. */
|
|
129
|
+
export function taskYieldDue() {
|
|
130
|
+
const now = performance.now();
|
|
131
|
+
taskDeadline ??= now + taskBudgetMs;
|
|
132
|
+
return now >= taskDeadline;
|
|
133
|
+
}
|
|
134
|
+
/** Yield a task so input, rendering and cancellation can run without nested timer delays. */
|
|
135
|
+
export function pause() {
|
|
136
|
+
const scheduler = globalThis.scheduler;
|
|
137
|
+
// A normal-priority task keeps the export progressing beside a busy host.
|
|
138
|
+
// It has no boosted continuation; due input and cancellation can still run.
|
|
139
|
+
if (typeof scheduler?.postTask === "function")
|
|
140
|
+
return scheduler.postTask(() => {
|
|
141
|
+
taskDeadline = performance.now() + taskBudgetMs;
|
|
142
|
+
}, { priority: "user-visible" });
|
|
143
|
+
return new Promise(resolve => {
|
|
144
|
+
setTimeout(function finish() {
|
|
145
|
+
taskDeadline = performance.now() + taskBudgetMs;
|
|
146
|
+
resolve();
|
|
147
|
+
}, 0);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Hard ceilings: rows are data rows per sheet; cells and text are totals including headers. */
|
|
2
|
+
export interface ExportLimits {
|
|
3
|
+
readonly maxRows?: number;
|
|
4
|
+
readonly maxCells?: number;
|
|
5
|
+
readonly maxTextCharacters?: number;
|
|
6
|
+
readonly maxOutputBytes?: number;
|
|
7
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { OfficeIMOError } from "./errors.js";
|
|
2
|
+
import { captureFields } from "../internal/capture.js";
|
|
3
|
+
/** @internal Check before accepting the next value or chunk. */
|
|
4
|
+
export class ExportBudget {
|
|
5
|
+
cells = 0;
|
|
6
|
+
text = 0;
|
|
7
|
+
reservedCells = 0;
|
|
8
|
+
reservedText = 0;
|
|
9
|
+
limits;
|
|
10
|
+
constructor(limits = {}) {
|
|
11
|
+
if (!limits || typeof limits !== "object" || Array.isArray(limits))
|
|
12
|
+
throw new TypeError("Export limits must be an object.");
|
|
13
|
+
// Capture before validation. Supported class getters are ordinary structural
|
|
14
|
+
// options too, and an accessor must not change the ceiling after validation.
|
|
15
|
+
const captured = captureFields(limits, ["maxRows", "maxCells", "maxTextCharacters", "maxOutputBytes"]);
|
|
16
|
+
for (const [key, value] of Object.entries(captured))
|
|
17
|
+
if (value !== undefined && (!Number.isSafeInteger(value) || value < 0))
|
|
18
|
+
throw new RangeError(key + " must be a nonnegative safe integer.");
|
|
19
|
+
this.limits = Object.freeze(captured);
|
|
20
|
+
}
|
|
21
|
+
check(kind, value) {
|
|
22
|
+
const maximum = this.limits[kind];
|
|
23
|
+
if (maximum !== undefined && value > maximum)
|
|
24
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", kind + " exceeded (" + value + " > " + maximum + ").");
|
|
25
|
+
}
|
|
26
|
+
row(count) { this.check("maxRows", count); }
|
|
27
|
+
reserve(cells, characters) {
|
|
28
|
+
this.check("maxCells", this.cells + this.reservedCells + cells);
|
|
29
|
+
this.check("maxTextCharacters", this.text + this.reservedText + characters);
|
|
30
|
+
this.reservedCells += cells;
|
|
31
|
+
this.reservedText += characters;
|
|
32
|
+
}
|
|
33
|
+
release(cells, characters) { this.reservedCells -= cells; this.reservedText -= characters; }
|
|
34
|
+
cell(value, reservedCharacters) {
|
|
35
|
+
if (reservedCharacters !== undefined)
|
|
36
|
+
this.release(1, reservedCharacters);
|
|
37
|
+
// Immutable limits cannot acquire a ceiling later. Avoid per-cell accounting
|
|
38
|
+
// when neither emitted-cell nor text totals are observable by a resource cap.
|
|
39
|
+
if (this.limits.maxCells === undefined && this.limits.maxTextCharacters === undefined)
|
|
40
|
+
return;
|
|
41
|
+
this.check("maxCells", this.cells + this.reservedCells + 1);
|
|
42
|
+
const length = typeof value === "string" ? value.length : 0;
|
|
43
|
+
this.check("maxTextCharacters", this.text + this.reservedText + length);
|
|
44
|
+
this.cells++;
|
|
45
|
+
this.text += length;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** @internal Ownership stays with the caller. */
|
|
49
|
+
export function boundedSink(sink, budget) {
|
|
50
|
+
let bytes = 0;
|
|
51
|
+
return { write(chunk) {
|
|
52
|
+
budget.check("maxOutputBytes", bytes + chunk.length);
|
|
53
|
+
bytes += chunk.length;
|
|
54
|
+
return sink.write(chunk);
|
|
55
|
+
} };
|
|
56
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** @internal One target policy shared by document writers and portable cells. */
|
|
2
|
+
export function copyExportLink(link) {
|
|
3
|
+
if (!link || typeof link !== "object")
|
|
4
|
+
throw new TypeError("Hyperlinks require an absolute HTTP, HTTPS or mailto target without whitespace or controls.");
|
|
5
|
+
const { target, tooltip } = link;
|
|
6
|
+
if (typeof target !== "string" || !/^(?:https?:\/\/|mailto:)/i.test(target) || /[\u0000-\u0020\u007f]/.test(target))
|
|
7
|
+
throw new TypeError("Hyperlinks require an absolute HTTP, HTTPS or mailto target without whitespace or controls.");
|
|
8
|
+
const url = new URL(target);
|
|
9
|
+
if ((url.protocol === "http:" || url.protocol === "https:") && (!url.hostname || url.username || url.password))
|
|
10
|
+
throw new TypeError("Hyperlink HTTP targets need a host and must not contain credentials.");
|
|
11
|
+
if (tooltip !== undefined && typeof tooltip !== "string")
|
|
12
|
+
throw new TypeError("Hyperlink tooltip must be text.");
|
|
13
|
+
return Object.freeze({ target: url.href, ...(tooltip === undefined ? {} : { tooltip }) });
|
|
14
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Alignment, CellValue } from "./index.js";
|
|
2
|
+
import type { ExportLink } from "./links.js";
|
|
3
|
+
/** Portable presentation selected by the report producer, without workbook-local indexes. */
|
|
4
|
+
export interface CellPresentation {
|
|
5
|
+
readonly background?: string;
|
|
6
|
+
readonly color?: string;
|
|
7
|
+
readonly bold?: boolean;
|
|
8
|
+
readonly italic?: boolean;
|
|
9
|
+
readonly wrapText?: boolean;
|
|
10
|
+
readonly alignment?: Alignment;
|
|
11
|
+
readonly numberFormat?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ExportCellOptions {
|
|
14
|
+
/** Display text for PDF, CSV's display mode and bounded width sampling; typed values remain authoritative. */
|
|
15
|
+
readonly text?: string;
|
|
16
|
+
readonly presentation?: CellPresentation;
|
|
17
|
+
/** XLSX/PDF retain the external link. CSV emits ordinary value/display text. */
|
|
18
|
+
readonly link?: ExportLink;
|
|
19
|
+
}
|
|
20
|
+
/** One resolved value/presentation decision that can be reused across exports. Strings remain literal data. */
|
|
21
|
+
export declare class ExportCell {
|
|
22
|
+
readonly value: CellValue;
|
|
23
|
+
static [Symbol.hasInstance](value: unknown): boolean;
|
|
24
|
+
readonly text: string | undefined;
|
|
25
|
+
readonly presentation: Readonly<CellPresentation> | undefined;
|
|
26
|
+
readonly link: Readonly<ExportLink> | undefined;
|
|
27
|
+
constructor(value: CellValue, options?: ExportCellOptions);
|
|
28
|
+
}
|
|
29
|
+
export type ExportValue = CellValue | ExportCell;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { isDate } from "./dates.js";
|
|
2
|
+
import { copyExportLink } from "./links.js";
|
|
3
|
+
const exportCellBrand = Symbol.for("@evotecit/officeimo/ExportCell");
|
|
4
|
+
/** @internal Capture only portable scalar presentation fields before retaining or cloning a cell. */
|
|
5
|
+
export function copyCellPresentation(value) {
|
|
6
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
7
|
+
throw new TypeError("Cell presentation must be an object.");
|
|
8
|
+
const result = {};
|
|
9
|
+
for (const key of ["background", "color", "numberFormat", "bold", "italic", "wrapText", "alignment"]) {
|
|
10
|
+
const field = value[key];
|
|
11
|
+
if (field === undefined)
|
|
12
|
+
continue;
|
|
13
|
+
if (["bold", "italic", "wrapText"].includes(key)) {
|
|
14
|
+
if (typeof field !== "boolean")
|
|
15
|
+
throw new TypeError("Cell presentation " + key + " must be boolean.");
|
|
16
|
+
}
|
|
17
|
+
else if (typeof field !== "string")
|
|
18
|
+
throw new TypeError("Cell presentation " + key + " must be text.");
|
|
19
|
+
if (key === "alignment" && !["left", "center", "right", "fill", "justify", "distributed"].includes(field))
|
|
20
|
+
throw new TypeError("Invalid cell presentation alignment.");
|
|
21
|
+
result[key] = field;
|
|
22
|
+
}
|
|
23
|
+
return Object.freeze(result);
|
|
24
|
+
}
|
|
25
|
+
/** One resolved value/presentation decision that can be reused across exports. Strings remain literal data. */
|
|
26
|
+
export class ExportCell {
|
|
27
|
+
value;
|
|
28
|
+
static [Symbol.hasInstance](value) { return !!value && typeof value === "object" && value[exportCellBrand] === true; }
|
|
29
|
+
text;
|
|
30
|
+
presentation;
|
|
31
|
+
link;
|
|
32
|
+
constructor(value, options = {}) {
|
|
33
|
+
this.value = value;
|
|
34
|
+
const { text, presentation, link } = options;
|
|
35
|
+
if (text !== undefined && typeof text !== "string")
|
|
36
|
+
throw new TypeError("Display text must be a string.");
|
|
37
|
+
assertScalar(value);
|
|
38
|
+
this.text = text;
|
|
39
|
+
this.presentation = presentation === undefined ? undefined : copyCellPresentation(presentation);
|
|
40
|
+
this.link = link === undefined ? undefined : copyExportLink(link);
|
|
41
|
+
Object.defineProperty(this, exportCellBrand, { value: true });
|
|
42
|
+
Object.freeze(this);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** @internal Reject async formatters while observing their rejection immediately. */
|
|
46
|
+
export function assertScalar(value) {
|
|
47
|
+
const kind = typeof value;
|
|
48
|
+
if (value == null || kind === "string" || kind === "number" || kind === "boolean" || isDate(value))
|
|
49
|
+
return;
|
|
50
|
+
if (typeof value.then === "function")
|
|
51
|
+
void Promise.resolve(value).catch(() => { });
|
|
52
|
+
throw new TypeError("Export values and formatter results must be synchronous strings, numbers, booleans, Dates or null.");
|
|
53
|
+
}
|
|
54
|
+
/** @internal Validate selected values before a destination interprets presentation. */
|
|
55
|
+
export function assertExportValue(value) {
|
|
56
|
+
if (value !== null && typeof value === "object" && value instanceof ExportCell)
|
|
57
|
+
return;
|
|
58
|
+
assertScalar(value);
|
|
59
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** @internal Notify synchronously; observe an accidental promise before rejecting its unsupported use. */
|
|
2
|
+
export function notifyProgress(callback, progress) {
|
|
3
|
+
if (!callback)
|
|
4
|
+
return;
|
|
5
|
+
const result = callback(progress);
|
|
6
|
+
if (result && typeof result.then === "function") {
|
|
7
|
+
void Promise.resolve(result).catch(() => { });
|
|
8
|
+
throw new TypeError("onProgress must be synchronous.");
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Writes must resolve only after the sink accepts bytes. Ownership stays with the caller. */
|
|
2
|
+
export interface ByteSink {
|
|
3
|
+
write(bytes: Uint8Array): void | Promise<void>;
|
|
4
|
+
}
|
|
5
|
+
/** A caller-owned byte destination. WritableStream locks are borrowed only for the operation. */
|
|
6
|
+
export type OutputDestination = ByteSink | WritableStream<Uint8Array>;
|
|
7
|
+
export type ByteWriter = (bytes: Uint8Array) => void | Promise<void>;
|
|
8
|
+
export type ByteSource = Uint8Array | Iterable<Uint8Array> | AsyncIterable<Uint8Array>;
|
|
9
|
+
/** Collects output only; it does not retain source rows or XML strings. */
|
|
10
|
+
export declare class BlobByteSink implements ByteSink {
|
|
11
|
+
private parts;
|
|
12
|
+
private state;
|
|
13
|
+
private result;
|
|
14
|
+
write(bytes: Uint8Array): void;
|
|
15
|
+
toBlob(type?: string): Blob;
|
|
16
|
+
discard(): void;
|
|
17
|
+
}
|
|
18
|
+
/** Bounded UTF-8 batches, preserving surrogate pairs across append boundaries. */
|
|
19
|
+
export declare class ChunkedTextSink {
|
|
20
|
+
private readonly sink;
|
|
21
|
+
private readonly signal?;
|
|
22
|
+
readonly chunkSize: number;
|
|
23
|
+
private text;
|
|
24
|
+
private readonly encoder;
|
|
25
|
+
constructor(sink: ByteSink, signal?: AbortSignal | undefined, chunkSize?: number);
|
|
26
|
+
append(value: string): boolean;
|
|
27
|
+
/** Flush full text, keeping a trailing high surrogate until the next append. */
|
|
28
|
+
flush(final?: boolean): Promise<void>;
|
|
29
|
+
write(text: string): Promise<void>;
|
|
30
|
+
close(): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
/** Feed a byte source into a caller-owned sink with backpressure and cancellation. */
|
|
33
|
+
export declare function writeBytes(source: ByteSource, sink: ByteSink, signal?: AbortSignal): Promise<void>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { checkAbort, consumeRows, withAbort, pause, taskYieldDue } from "./iteration.js";
|
|
2
|
+
import { OfficeIMOError } from "./errors.js";
|
|
3
|
+
/** @internal Borrow a stream writer without closing or aborting the caller's destination. */
|
|
4
|
+
export async function withDestination(destination, operation) {
|
|
5
|
+
// Native streams can belong to another browser realm; constructor identity is not portable.
|
|
6
|
+
if (destination && typeof destination.getWriter === "function") {
|
|
7
|
+
const writer = destination.getWriter();
|
|
8
|
+
// Native streams may retain accepted chunks after write resolves.
|
|
9
|
+
try {
|
|
10
|
+
return await operation({ write: bytes => writer.write(new Uint8Array(bytes)) });
|
|
11
|
+
}
|
|
12
|
+
finally {
|
|
13
|
+
writer.releaseLock();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (!destination || typeof destination.write !== "function")
|
|
17
|
+
throw new TypeError("Destination must be a ByteSink or WritableStream.");
|
|
18
|
+
return operation(destination);
|
|
19
|
+
}
|
|
20
|
+
/** Collects output only; it does not retain source rows or XML strings. */
|
|
21
|
+
export class BlobByteSink {
|
|
22
|
+
parts = [];
|
|
23
|
+
state = "open";
|
|
24
|
+
result;
|
|
25
|
+
write(bytes) {
|
|
26
|
+
if (this.state !== "open")
|
|
27
|
+
throw new OfficeIMOError("INVALID_STATE", "Byte sink is closed.");
|
|
28
|
+
// A caller may reuse its input buffer as soon as write resolves.
|
|
29
|
+
this.parts.push(new Uint8Array(bytes));
|
|
30
|
+
}
|
|
31
|
+
toBlob(type = "application/octet-stream") {
|
|
32
|
+
if (this.state === "discarded")
|
|
33
|
+
throw new OfficeIMOError("INVALID_STATE", "Byte sink was discarded.");
|
|
34
|
+
this.state = "closed";
|
|
35
|
+
if (!this.result) {
|
|
36
|
+
this.result = new Blob(this.parts, { type });
|
|
37
|
+
this.parts = [];
|
|
38
|
+
}
|
|
39
|
+
return this.result.type === type ? this.result : new Blob([this.result], { type });
|
|
40
|
+
}
|
|
41
|
+
/** @internal Transfer buffered compressor chunks without a Blob read in the worker. */
|
|
42
|
+
takeChunks() {
|
|
43
|
+
if (this.state !== "open")
|
|
44
|
+
throw new OfficeIMOError("INVALID_STATE", "Byte sink is closed.");
|
|
45
|
+
const parts = this.parts;
|
|
46
|
+
this.parts = [];
|
|
47
|
+
this.state = "discarded";
|
|
48
|
+
return parts;
|
|
49
|
+
}
|
|
50
|
+
discard() { this.parts = []; this.result = undefined; this.state = "discarded"; }
|
|
51
|
+
}
|
|
52
|
+
/** Bounded UTF-8 batches, preserving surrogate pairs across append boundaries. */
|
|
53
|
+
export class ChunkedTextSink {
|
|
54
|
+
sink;
|
|
55
|
+
signal;
|
|
56
|
+
chunkSize;
|
|
57
|
+
text = "";
|
|
58
|
+
encoder = new TextEncoder();
|
|
59
|
+
constructor(sink, signal, chunkSize = 32768) {
|
|
60
|
+
this.sink = sink;
|
|
61
|
+
this.signal = signal;
|
|
62
|
+
this.chunkSize = chunkSize;
|
|
63
|
+
if (!Number.isInteger(chunkSize) || chunkSize < 2)
|
|
64
|
+
throw new RangeError("Text chunk size must be at least 2.");
|
|
65
|
+
}
|
|
66
|
+
append(value) {
|
|
67
|
+
checkAbort(this.signal);
|
|
68
|
+
this.text += value;
|
|
69
|
+
return this.text.length >= this.chunkSize || taskYieldDue();
|
|
70
|
+
}
|
|
71
|
+
/** Flush full text, keeping a trailing high surrogate until the next append. */
|
|
72
|
+
async flush(final = false) {
|
|
73
|
+
checkAbort(this.signal);
|
|
74
|
+
while (this.text.length) {
|
|
75
|
+
let end = Math.min(this.text.length, this.chunkSize);
|
|
76
|
+
if (/[\ud800-\udbff]/.test(this.text[end - 1]) && (end < this.text.length || !final))
|
|
77
|
+
end--;
|
|
78
|
+
if (!end)
|
|
79
|
+
break;
|
|
80
|
+
const bytes = this.encoder.encode(this.text.slice(0, end));
|
|
81
|
+
this.text = this.text.slice(end);
|
|
82
|
+
await withAbort(Promise.resolve(this.sink.write(bytes)), this.signal);
|
|
83
|
+
if (taskYieldDue())
|
|
84
|
+
await pause();
|
|
85
|
+
checkAbort(this.signal);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async write(text) { if (this.append(text))
|
|
89
|
+
await this.flush(); }
|
|
90
|
+
async close() { await this.flush(true); }
|
|
91
|
+
}
|
|
92
|
+
/** Feed a byte source into a caller-owned sink with backpressure and cancellation. */
|
|
93
|
+
export async function writeBytes(source, sink, signal) {
|
|
94
|
+
await consumeRows(source instanceof Uint8Array ? [source] : source, signal, bytes => {
|
|
95
|
+
if (!(bytes instanceof Uint8Array))
|
|
96
|
+
throw new TypeError("Byte sources must yield Uint8Array chunks.");
|
|
97
|
+
const pending = sink.write(bytes);
|
|
98
|
+
if (taskYieldDue())
|
|
99
|
+
return Promise.resolve(pending).then(() => { checkAbort(signal); return pause(); });
|
|
100
|
+
return pending;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ExportValue } from "./presentation.js";
|
|
2
|
+
/** A heading/footer anchor. Covered matrix positions are null; rows have the declared column count. */
|
|
3
|
+
export interface TableSpanCell {
|
|
4
|
+
readonly value: ExportValue;
|
|
5
|
+
readonly columnSpan?: number;
|
|
6
|
+
readonly rowSpan?: number;
|
|
7
|
+
}
|
|
8
|
+
export type TableSpanRows = readonly (readonly (TableSpanCell | null)[])[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Explicit display strings for boolean values. XLSX boolean cell types remain unchanged. */
|
|
2
|
+
export interface BooleanText {
|
|
3
|
+
readonly true: string;
|
|
4
|
+
readonly false: string;
|
|
5
|
+
}
|
|
6
|
+
/** Compatibility display policy; hosts can supply labels without changing typed source values. */
|
|
7
|
+
export declare const defaultBooleanText: Readonly<BooleanText>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Compatibility display policy; hosts can supply labels without changing typed source values. */
|
|
2
|
+
export const defaultBooleanText = Object.freeze({ true: "True", false: "False" });
|
|
3
|
+
/** @internal Capture display policy once, before source iteration or asynchronous output. */
|
|
4
|
+
export function captureBooleanText(input) {
|
|
5
|
+
if (input === undefined)
|
|
6
|
+
return defaultBooleanText;
|
|
7
|
+
if (!input || typeof input !== "object")
|
|
8
|
+
throw new TypeError("booleanText must contain true and false strings.");
|
|
9
|
+
const yes = input.true, no = input.false;
|
|
10
|
+
if (typeof yes !== "string" || typeof no !== "string")
|
|
11
|
+
throw new TypeError("booleanText must contain true and false strings.");
|
|
12
|
+
return Object.freeze({ true: yes, false: no });
|
|
13
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { OutputDestination } from "../core/sinks.js";
|
|
2
|
+
import type { CellValue, Column, StreamOptions, ExportResult, TableSpanRows } from "../core/index.js";
|
|
3
|
+
import type { BooleanText } from "../core/value-text.js";
|
|
4
|
+
export type { BooleanText } from "../core/value-text.js";
|
|
5
|
+
export { saveBlob } from "../core/index.js";
|
|
6
|
+
export { ExportCell } from "../core/presentation.js";
|
|
7
|
+
export type { CellValue, Column, ColumnValueContext, Row, Rows, StreamOptions, ExportProgress, ExportResult, OutputDestination, ExportValue, CellPresentation } from "../core/index.js";
|
|
8
|
+
export interface CsvValueContext {
|
|
9
|
+
/** Zero-based data position, excluding the header. */
|
|
10
|
+
readonly rowIndex: number;
|
|
11
|
+
readonly columnIndex: number;
|
|
12
|
+
readonly column: Column;
|
|
13
|
+
readonly values: readonly CellValue[];
|
|
14
|
+
}
|
|
15
|
+
export type CsvColumn<T = never> = Column<T> & {
|
|
16
|
+
readonly style?: never;
|
|
17
|
+
/** Formatting happens before formula protection and RFC quoting. Return a scalar, never pre-escaped CSV. */
|
|
18
|
+
readonly valueFormatter?: (value: CellValue, context: CsvValueContext) => CellValue;
|
|
19
|
+
};
|
|
20
|
+
export interface CsvOptions<T = never> extends StreamOptions {
|
|
21
|
+
readonly columns: readonly CsvColumn<T>[];
|
|
22
|
+
/** Raw typed values by default. Display mode uses ExportCell.text when supplied. */
|
|
23
|
+
readonly valueMode?: "raw" | "display";
|
|
24
|
+
readonly delimiter?: "," | ";" | "\t";
|
|
25
|
+
readonly lineEnding?: "\r\n" | "\n" | "\r";
|
|
26
|
+
readonly bom?: boolean;
|
|
27
|
+
readonly includeHeader?: boolean;
|
|
28
|
+
/** Replaces the ordinary leaf header; each physical matrix row is emitted. */
|
|
29
|
+
readonly headerRows?: TableSpanRows;
|
|
30
|
+
/** Appended report metadata, excluded from data-row progress and completion counts. */
|
|
31
|
+
readonly footer?: {
|
|
32
|
+
readonly rows: TableSpanRows;
|
|
33
|
+
};
|
|
34
|
+
/** Required when an emitted header/footer spans cells. Repeat fills covered positions; anchors leaves them empty. */
|
|
35
|
+
readonly spanMode?: "repeat" | "anchors";
|
|
36
|
+
readonly formulaInjectionProtection?: boolean;
|
|
37
|
+
readonly quote?: "minimal" | "all" | "strings";
|
|
38
|
+
readonly nullValue?: string;
|
|
39
|
+
/** Display policy only; defaults to the explicit compatibility strings True and False. */
|
|
40
|
+
readonly booleanText?: BooleanText;
|
|
41
|
+
}
|
|
42
|
+
/** Stream UTF-8 to a caller-owned sink; a failing/cancelled destination owns partial-byte disposal. */
|
|
43
|
+
export declare function writeCsvTo<T extends object>(rows: Iterable<T> | AsyncIterable<T>, destination: OutputDestination, options: CsvOptions<NoInfer<T>>): Promise<ExportResult>;
|
|
44
|
+
export declare function writeCsv<T extends object>(rows: Iterable<T> | AsyncIterable<T>, options: CsvOptions<NoInfer<T>>): Promise<Blob>;
|