@evotecit/officeimo 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +1219 -2
- package/bundles/officeimo-canopyx.js +11286 -0
- package/bundles/officeimo-canopyx.mjs +11185 -0
- package/bundles/officeimo-csv.js +1254 -0
- package/bundles/officeimo-csv.mjs +1229 -0
- package/bundles/officeimo-datatables.js +11572 -0
- package/bundles/officeimo-datatables.mjs +11470 -0
- package/bundles/officeimo-execution.js +1503 -0
- package/bundles/officeimo-execution.mjs +1479 -0
- package/bundles/officeimo-pdf.js +6564 -0
- package/bundles/officeimo-pdf.mjs +6502 -0
- package/bundles/officeimo-xlsx.js +5333 -0
- package/bundles/officeimo-xlsx.mjs +5279 -0
- package/bundles/officeimo.js +11022 -0
- package/bundles/officeimo.mjs +10924 -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 +72 -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 +101 -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 +116 -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 +68 -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 +194 -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 +201 -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 +142 -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 +143 -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 +679 -0
- package/dist/pdf/paragraph-layout.d.ts +19 -0
- package/dist/pdf/paragraph-layout.js +66 -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 +15 -0
- package/dist/pdf/settings.js +171 -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 +250 -0
- package/dist/pdf/table-band-flow.d.ts +34 -0
- package/dist/pdf/table-band-flow.js +114 -0
- package/dist/pdf/table-band-plan.d.ts +10 -0
- package/dist/pdf/table-band-plan.js +85 -0
- package/dist/pdf/table-layout.d.ts +71 -0
- package/dist/pdf/table-layout.js +205 -0
- package/dist/pdf/table-structure.d.ts +1 -0
- package/dist/pdf/table-structure.js +92 -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 +96 -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 +169 -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/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 +86 -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,1479 @@
|
|
|
1
|
+
// Generated by OfficeIMO.JavaScript/scripts/bundles.mjs from tsc output. MIT.
|
|
2
|
+
const _m2 = (() => {
|
|
3
|
+
function checkAbort(signal) {
|
|
4
|
+
if (signal?.aborted)
|
|
5
|
+
throw signal.reason ?? new DOMException("Export cancelled.", "AbortError");
|
|
6
|
+
}
|
|
7
|
+
/** Race a pending producer or sink operation without leaving abort listeners behind. */
|
|
8
|
+
function withAbort(promise, signal) {
|
|
9
|
+
if (!signal)
|
|
10
|
+
return Promise.resolve(promise);
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
const cleanup = () => signal.removeEventListener("abort", abort);
|
|
13
|
+
const abort = () => { cleanup(); reject(signal.reason ?? new DOMException("Export cancelled.", "AbortError")); };
|
|
14
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
15
|
+
Promise.resolve(promise).then(value => { cleanup(); resolve(value); }, error => { cleanup(); reject(error); });
|
|
16
|
+
if (signal.aborted)
|
|
17
|
+
abort();
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/** Consume once; return the iterator on failure or cancellation. Pass the signal to I/O producers too. */
|
|
21
|
+
async function* inputRows(input, signal) {
|
|
22
|
+
checkAbort(signal);
|
|
23
|
+
const iterator = input?.[Symbol.asyncIterator]?.() ?? input?.[Symbol.iterator]?.();
|
|
24
|
+
if (!iterator)
|
|
25
|
+
throw new TypeError("Rows must be a synchronous or asynchronous iterable.");
|
|
26
|
+
let done = false, failed = false;
|
|
27
|
+
try {
|
|
28
|
+
while (true) {
|
|
29
|
+
checkAbort(signal);
|
|
30
|
+
const item = await withAbort(Promise.resolve(iterator.next()), signal);
|
|
31
|
+
checkAbort(signal);
|
|
32
|
+
if (item.done) {
|
|
33
|
+
done = true;
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
yield item.value;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
failed = true;
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
if (!done && iterator.return) {
|
|
45
|
+
try {
|
|
46
|
+
const returned = iterator.return();
|
|
47
|
+
if (signal?.aborted || failed)
|
|
48
|
+
Promise.resolve(returned).catch(() => { });
|
|
49
|
+
else
|
|
50
|
+
await withAbort(Promise.resolve(returned), signal);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
if (!signal?.aborted && !failed)
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const rowConsumers = new WeakMap();
|
|
60
|
+
/** @internal Keep bounded pages as ordinary async rows, with direct batch consumption for owned writers. */
|
|
61
|
+
function rowsFromBatches(batches) {
|
|
62
|
+
let consumed = false;
|
|
63
|
+
const claim = () => { if (consumed)
|
|
64
|
+
throw new TypeError("A row source can be consumed only once."); consumed = true; };
|
|
65
|
+
const rows = { [Symbol.asyncIterator]() { claim(); return iterate(); } };
|
|
66
|
+
async function* iterate() { for await (const batch of inputRows(batches))
|
|
67
|
+
yield* batch; }
|
|
68
|
+
rowConsumers.set(rows, (signal, accept) => {
|
|
69
|
+
claim();
|
|
70
|
+
return consumeRows(batches, signal, batch => consumeRows(batch, signal, accept));
|
|
71
|
+
});
|
|
72
|
+
return rows;
|
|
73
|
+
}
|
|
74
|
+
/** @internal Concatenate headings, body and footer without another per-row async delegation. */
|
|
75
|
+
function concatRows(...sources) {
|
|
76
|
+
const rows = { async *[Symbol.asyncIterator]() { for (const source of sources)
|
|
77
|
+
yield* source; } };
|
|
78
|
+
rowConsumers.set(rows, async (signal, accept) => { for (const source of sources)
|
|
79
|
+
await consumeRows(source, signal, accept); });
|
|
80
|
+
return rows;
|
|
81
|
+
}
|
|
82
|
+
/** @internal Consume synchronous work without an async-generator and per-row Promise.
|
|
83
|
+
* Async producers, promised values and destination backpressure keep the same cancellation/return contract. */
|
|
84
|
+
async function consumeRows(input, signal, accept) {
|
|
85
|
+
checkAbort(signal);
|
|
86
|
+
const consume = rowConsumers.get(input);
|
|
87
|
+
if (consume)
|
|
88
|
+
return consume(signal, accept);
|
|
89
|
+
const iterator = input?.[Symbol.asyncIterator]?.() ?? input?.[Symbol.iterator]?.();
|
|
90
|
+
if (!iterator)
|
|
91
|
+
throw new TypeError("Rows must be a synchronous or asynchronous iterable.");
|
|
92
|
+
let done = false;
|
|
93
|
+
try {
|
|
94
|
+
while (true) {
|
|
95
|
+
checkAbort(signal);
|
|
96
|
+
let item = iterator.next();
|
|
97
|
+
const next = item;
|
|
98
|
+
if (typeof next?.then === "function")
|
|
99
|
+
item = await withAbort(next, signal);
|
|
100
|
+
checkAbort(signal);
|
|
101
|
+
const result = item;
|
|
102
|
+
if (result.done) {
|
|
103
|
+
done = true;
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
let value = result.value;
|
|
107
|
+
if (typeof value?.then === "function")
|
|
108
|
+
value = await withAbort(value, signal);
|
|
109
|
+
checkAbort(signal);
|
|
110
|
+
const pending = accept(value);
|
|
111
|
+
if (pending !== undefined)
|
|
112
|
+
await withAbort(pending, signal);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
if (!done && iterator.return) {
|
|
117
|
+
// Any exit before exhaustion is a producer/consumer failure or cancellation.
|
|
118
|
+
// Observe cleanup, but an unresponsive return must not replace or hold the original failure.
|
|
119
|
+
try {
|
|
120
|
+
void Promise.resolve(iterator.return()).catch(() => { });
|
|
121
|
+
}
|
|
122
|
+
catch { /* Preserve the original failure. */ }
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
let taskDeadline;
|
|
127
|
+
const taskBudgetMs = 32;
|
|
128
|
+
/** @internal Start a new write phase without carrying an idle operation's expired deadline. */
|
|
129
|
+
function beginTask() { taskDeadline = performance.now() + taskBudgetMs; }
|
|
130
|
+
/** @internal Pipeline stages share the last completed yield instead of pausing back-to-back. */
|
|
131
|
+
function taskYieldDue() {
|
|
132
|
+
const now = performance.now();
|
|
133
|
+
taskDeadline ??= now + taskBudgetMs;
|
|
134
|
+
return now >= taskDeadline;
|
|
135
|
+
}
|
|
136
|
+
/** Yield a task so input, rendering and cancellation can run without nested timer delays. */
|
|
137
|
+
function pause() {
|
|
138
|
+
const scheduler = globalThis.scheduler;
|
|
139
|
+
// A normal-priority task keeps the export progressing beside a busy host.
|
|
140
|
+
// It has no boosted continuation; due input and cancellation can still run.
|
|
141
|
+
if (typeof scheduler?.postTask === "function")
|
|
142
|
+
return scheduler.postTask(() => {
|
|
143
|
+
taskDeadline = performance.now() + taskBudgetMs;
|
|
144
|
+
}, { priority: "user-visible" });
|
|
145
|
+
return new Promise(resolve => {
|
|
146
|
+
setTimeout(function finish() {
|
|
147
|
+
taskDeadline = performance.now() + taskBudgetMs;
|
|
148
|
+
resolve();
|
|
149
|
+
}, 0);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
const _exports = Object.freeze({ checkAbort: checkAbort, withAbort: withAbort, inputRows: inputRows, rowsFromBatches: rowsFromBatches, concatRows: concatRows, consumeRows: consumeRows, beginTask: beginTask, taskYieldDue: taskYieldDue, pause: pause });
|
|
153
|
+
return _exports;
|
|
154
|
+
})();
|
|
155
|
+
|
|
156
|
+
const _m4 = (() => {
|
|
157
|
+
const errorBrand = Symbol.for("@evotecit/officeimo/OfficeIMOError");
|
|
158
|
+
const unsupportedBrand = Symbol.for("@evotecit/officeimo/NotSupportedError");
|
|
159
|
+
class OfficeIMOError extends Error {
|
|
160
|
+
code;
|
|
161
|
+
static [Symbol.hasInstance](value) {
|
|
162
|
+
// Inherited checks on user subclasses must retain their own prototype identity.
|
|
163
|
+
if (this !== OfficeIMOError)
|
|
164
|
+
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
165
|
+
return !!value && typeof value === "object" && value[errorBrand] === true;
|
|
166
|
+
}
|
|
167
|
+
constructor(code, message, options) {
|
|
168
|
+
super(message, options);
|
|
169
|
+
this.code = code;
|
|
170
|
+
Object.defineProperty(this, errorBrand, { value: true });
|
|
171
|
+
this.name = "OfficeIMOError";
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
class NotSupportedError extends OfficeIMOError {
|
|
175
|
+
feature;
|
|
176
|
+
static [Symbol.hasInstance](value) {
|
|
177
|
+
if (this !== NotSupportedError)
|
|
178
|
+
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
179
|
+
return !!value && typeof value === "object" && value[unsupportedBrand] === true;
|
|
180
|
+
}
|
|
181
|
+
constructor(feature) {
|
|
182
|
+
super("NOT_SUPPORTED", feature + " is not supported yet.");
|
|
183
|
+
this.feature = feature;
|
|
184
|
+
Object.defineProperty(this, unsupportedBrand, { value: true });
|
|
185
|
+
this.name = "NotSupportedError";
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
const _exports = Object.freeze({ OfficeIMOError: OfficeIMOError, NotSupportedError: NotSupportedError });
|
|
189
|
+
return _exports;
|
|
190
|
+
})();
|
|
191
|
+
|
|
192
|
+
const _m3 = (() => {
|
|
193
|
+
const { checkAbort, consumeRows, withAbort, pause, taskYieldDue } = _m2;
|
|
194
|
+
|
|
195
|
+
const { OfficeIMOError } = _m4;
|
|
196
|
+
|
|
197
|
+
/** @internal Borrow a stream writer without closing or aborting the caller's destination. */
|
|
198
|
+
async function withDestination(destination, operation) {
|
|
199
|
+
// Native streams can belong to another browser realm; constructor identity is not portable.
|
|
200
|
+
if (destination && typeof destination.getWriter === "function") {
|
|
201
|
+
const writer = destination.getWriter();
|
|
202
|
+
try {
|
|
203
|
+
return await operation({ write: bytes => writer.write(bytes) });
|
|
204
|
+
}
|
|
205
|
+
finally {
|
|
206
|
+
writer.releaseLock();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (!destination || typeof destination.write !== "function")
|
|
210
|
+
throw new TypeError("Destination must be a ByteSink or WritableStream.");
|
|
211
|
+
return operation(destination);
|
|
212
|
+
}
|
|
213
|
+
/** Collects output only; it does not retain source rows or XML strings. */
|
|
214
|
+
class BlobByteSink {
|
|
215
|
+
parts = [];
|
|
216
|
+
state = "open";
|
|
217
|
+
result;
|
|
218
|
+
write(bytes) {
|
|
219
|
+
if (this.state !== "open")
|
|
220
|
+
throw new OfficeIMOError("INVALID_STATE", "Byte sink is closed.");
|
|
221
|
+
// A caller may reuse its input buffer as soon as write resolves.
|
|
222
|
+
this.parts.push(new Uint8Array(bytes));
|
|
223
|
+
}
|
|
224
|
+
toBlob(type = "application/octet-stream") {
|
|
225
|
+
if (this.state === "discarded")
|
|
226
|
+
throw new OfficeIMOError("INVALID_STATE", "Byte sink was discarded.");
|
|
227
|
+
this.state = "closed";
|
|
228
|
+
if (!this.result) {
|
|
229
|
+
this.result = new Blob(this.parts, { type });
|
|
230
|
+
this.parts = [];
|
|
231
|
+
}
|
|
232
|
+
return this.result.type === type ? this.result : new Blob([this.result], { type });
|
|
233
|
+
}
|
|
234
|
+
/** @internal Transfer buffered compressor chunks without a Blob read in the worker. */
|
|
235
|
+
takeChunks() {
|
|
236
|
+
if (this.state !== "open")
|
|
237
|
+
throw new OfficeIMOError("INVALID_STATE", "Byte sink is closed.");
|
|
238
|
+
const parts = this.parts;
|
|
239
|
+
this.parts = [];
|
|
240
|
+
this.state = "discarded";
|
|
241
|
+
return parts;
|
|
242
|
+
}
|
|
243
|
+
discard() { this.parts = []; this.result = undefined; this.state = "discarded"; }
|
|
244
|
+
}
|
|
245
|
+
/** Bounded UTF-8 batches, preserving surrogate pairs across append boundaries. */
|
|
246
|
+
class ChunkedTextSink {
|
|
247
|
+
sink;
|
|
248
|
+
signal;
|
|
249
|
+
chunkSize;
|
|
250
|
+
text = "";
|
|
251
|
+
encoder = new TextEncoder();
|
|
252
|
+
constructor(sink, signal, chunkSize = 32768) {
|
|
253
|
+
this.sink = sink;
|
|
254
|
+
this.signal = signal;
|
|
255
|
+
this.chunkSize = chunkSize;
|
|
256
|
+
if (!Number.isInteger(chunkSize) || chunkSize < 2)
|
|
257
|
+
throw new RangeError("Text chunk size must be at least 2.");
|
|
258
|
+
}
|
|
259
|
+
append(value) {
|
|
260
|
+
checkAbort(this.signal);
|
|
261
|
+
this.text += value;
|
|
262
|
+
return this.text.length >= this.chunkSize || taskYieldDue();
|
|
263
|
+
}
|
|
264
|
+
/** Flush full text, keeping a trailing high surrogate until the next append. */
|
|
265
|
+
async flush(final = false) {
|
|
266
|
+
checkAbort(this.signal);
|
|
267
|
+
while (this.text.length) {
|
|
268
|
+
let end = Math.min(this.text.length, this.chunkSize);
|
|
269
|
+
if (/[\ud800-\udbff]/.test(this.text[end - 1]) && (end < this.text.length || !final))
|
|
270
|
+
end--;
|
|
271
|
+
if (!end)
|
|
272
|
+
break;
|
|
273
|
+
const bytes = this.encoder.encode(this.text.slice(0, end));
|
|
274
|
+
this.text = this.text.slice(end);
|
|
275
|
+
await withAbort(Promise.resolve(this.sink.write(bytes)), this.signal);
|
|
276
|
+
if (taskYieldDue())
|
|
277
|
+
await pause();
|
|
278
|
+
checkAbort(this.signal);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
async write(text) { if (this.append(text))
|
|
282
|
+
await this.flush(); }
|
|
283
|
+
async close() { await this.flush(true); }
|
|
284
|
+
}
|
|
285
|
+
/** Feed a byte source into a caller-owned sink with backpressure and cancellation. */
|
|
286
|
+
async function writeBytes(source, sink, signal) {
|
|
287
|
+
await consumeRows(source instanceof Uint8Array ? [source] : source, signal, bytes => {
|
|
288
|
+
if (!(bytes instanceof Uint8Array))
|
|
289
|
+
throw new TypeError("Byte sources must yield Uint8Array chunks.");
|
|
290
|
+
const pending = sink.write(bytes);
|
|
291
|
+
if (taskYieldDue())
|
|
292
|
+
return Promise.resolve(pending).then(() => { checkAbort(signal); return pause(); });
|
|
293
|
+
return pending;
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
const _exports = Object.freeze({ withDestination: withDestination, BlobByteSink: BlobByteSink, ChunkedTextSink: ChunkedTextSink, writeBytes: writeBytes });
|
|
297
|
+
return _exports;
|
|
298
|
+
})();
|
|
299
|
+
|
|
300
|
+
const _m5 = (() => {
|
|
301
|
+
/** @internal Notify synchronously; observe an accidental promise before rejecting its unsupported use. */
|
|
302
|
+
function notifyProgress(callback, progress) {
|
|
303
|
+
if (!callback)
|
|
304
|
+
return;
|
|
305
|
+
const result = callback(progress);
|
|
306
|
+
if (result && typeof result.then === "function") {
|
|
307
|
+
void Promise.resolve(result).catch(() => { });
|
|
308
|
+
throw new TypeError("onProgress must be synchronous.");
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
const _exports = Object.freeze({ notifyProgress: notifyProgress });
|
|
312
|
+
return _exports;
|
|
313
|
+
})();
|
|
314
|
+
|
|
315
|
+
const _m9 = (() => {
|
|
316
|
+
/** @internal Recognize native Date values across iframe realms without trusting a string tag. */
|
|
317
|
+
function isDate(value) {
|
|
318
|
+
if (value === null || typeof value !== "object")
|
|
319
|
+
return false;
|
|
320
|
+
try {
|
|
321
|
+
// Ordinary rows take the cheap negative path. A custom string tag can be an
|
|
322
|
+
// accessor: use the native brand check directly without reading that tag.
|
|
323
|
+
if (!(value instanceof Date) && !(Symbol.toStringTag in value) && Object.prototype.toString.call(value) !== "[object Date]")
|
|
324
|
+
return false;
|
|
325
|
+
Date.prototype.getTime.call(value);
|
|
326
|
+
return true;
|
|
327
|
+
}
|
|
328
|
+
catch {
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
const _exports = Object.freeze({ isDate: isDate });
|
|
333
|
+
return _exports;
|
|
334
|
+
})();
|
|
335
|
+
|
|
336
|
+
const _m10 = (() => {
|
|
337
|
+
/** @internal One target policy shared by document writers and portable cells. */
|
|
338
|
+
function copyExportLink(link) {
|
|
339
|
+
if (!link || typeof link !== "object")
|
|
340
|
+
throw new TypeError("Hyperlinks require an absolute HTTP, HTTPS or mailto target without whitespace or controls.");
|
|
341
|
+
const { target, tooltip } = link;
|
|
342
|
+
if (typeof target !== "string" || !/^(?:https?:\/\/|mailto:)/i.test(target) || /[\u0000-\u0020\u007f]/.test(target))
|
|
343
|
+
throw new TypeError("Hyperlinks require an absolute HTTP, HTTPS or mailto target without whitespace or controls.");
|
|
344
|
+
const url = new URL(target);
|
|
345
|
+
if ((url.protocol === "http:" || url.protocol === "https:") && (!url.hostname || url.username || url.password))
|
|
346
|
+
throw new TypeError("Hyperlink HTTP targets need a host and must not contain credentials.");
|
|
347
|
+
if (tooltip !== undefined && typeof tooltip !== "string")
|
|
348
|
+
throw new TypeError("Hyperlink tooltip must be text.");
|
|
349
|
+
return Object.freeze({ target: url.href, ...(tooltip === undefined ? {} : { tooltip }) });
|
|
350
|
+
}
|
|
351
|
+
const _exports = Object.freeze({ copyExportLink: copyExportLink });
|
|
352
|
+
return _exports;
|
|
353
|
+
})();
|
|
354
|
+
|
|
355
|
+
const _m8 = (() => {
|
|
356
|
+
const { isDate } = _m9;
|
|
357
|
+
|
|
358
|
+
const { copyExportLink } = _m10;
|
|
359
|
+
|
|
360
|
+
const exportCellBrand = Symbol.for("@evotecit/officeimo/ExportCell");
|
|
361
|
+
/** @internal Capture only portable scalar presentation fields before retaining or cloning a cell. */
|
|
362
|
+
function copyCellPresentation(value) {
|
|
363
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
364
|
+
throw new TypeError("Cell presentation must be an object.");
|
|
365
|
+
const result = {};
|
|
366
|
+
for (const key of ["background", "color", "numberFormat", "bold", "italic", "wrapText", "alignment"]) {
|
|
367
|
+
const field = value[key];
|
|
368
|
+
if (field === undefined)
|
|
369
|
+
continue;
|
|
370
|
+
if (["bold", "italic", "wrapText"].includes(key)) {
|
|
371
|
+
if (typeof field !== "boolean")
|
|
372
|
+
throw new TypeError("Cell presentation " + key + " must be boolean.");
|
|
373
|
+
}
|
|
374
|
+
else if (typeof field !== "string")
|
|
375
|
+
throw new TypeError("Cell presentation " + key + " must be text.");
|
|
376
|
+
if (key === "alignment" && !["left", "center", "right", "fill", "justify", "distributed"].includes(field))
|
|
377
|
+
throw new TypeError("Invalid cell presentation alignment.");
|
|
378
|
+
result[key] = field;
|
|
379
|
+
}
|
|
380
|
+
return Object.freeze(result);
|
|
381
|
+
}
|
|
382
|
+
/** One resolved value/presentation decision that can be reused across exports. Strings remain literal data. */
|
|
383
|
+
class ExportCell {
|
|
384
|
+
value;
|
|
385
|
+
static [Symbol.hasInstance](value) { return !!value && typeof value === "object" && value[exportCellBrand] === true; }
|
|
386
|
+
text;
|
|
387
|
+
presentation;
|
|
388
|
+
link;
|
|
389
|
+
constructor(value, options = {}) {
|
|
390
|
+
this.value = value;
|
|
391
|
+
const { text, presentation, link } = options;
|
|
392
|
+
if (text !== undefined && typeof text !== "string")
|
|
393
|
+
throw new TypeError("Display text must be a string.");
|
|
394
|
+
assertScalar(value);
|
|
395
|
+
this.text = text;
|
|
396
|
+
this.presentation = presentation === undefined ? undefined : copyCellPresentation(presentation);
|
|
397
|
+
this.link = link === undefined ? undefined : copyExportLink(link);
|
|
398
|
+
Object.defineProperty(this, exportCellBrand, { value: true });
|
|
399
|
+
Object.freeze(this);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
/** @internal Reject async formatters while observing their rejection immediately. */
|
|
403
|
+
function assertScalar(value) {
|
|
404
|
+
const kind = typeof value;
|
|
405
|
+
if (value == null || kind === "string" || kind === "number" || kind === "boolean" || isDate(value))
|
|
406
|
+
return;
|
|
407
|
+
if (typeof value.then === "function")
|
|
408
|
+
void Promise.resolve(value).catch(() => { });
|
|
409
|
+
throw new TypeError("Export values and formatter results must be synchronous strings, numbers, booleans, Dates or null.");
|
|
410
|
+
}
|
|
411
|
+
/** @internal Validate selected values before a destination interprets presentation. */
|
|
412
|
+
function assertExportValue(value) {
|
|
413
|
+
if (value !== null && typeof value === "object" && value instanceof ExportCell)
|
|
414
|
+
return;
|
|
415
|
+
assertScalar(value);
|
|
416
|
+
}
|
|
417
|
+
const _exports = Object.freeze({ copyCellPresentation: copyCellPresentation, ExportCell: ExportCell, assertScalar: assertScalar, assertExportValue: assertExportValue });
|
|
418
|
+
return _exports;
|
|
419
|
+
})();
|
|
420
|
+
|
|
421
|
+
const _m13 = (() => {
|
|
422
|
+
/** Capture a structural option record before validation or asynchronous work.
|
|
423
|
+
* Own fields and supported prototype accessors are read once. Nested values remain
|
|
424
|
+
* borrowed until their owning format captures or validates them. */
|
|
425
|
+
function captureFields(input, fields) {
|
|
426
|
+
const captured = { ...input };
|
|
427
|
+
for (const field of fields) {
|
|
428
|
+
if (Object.hasOwn(captured, field))
|
|
429
|
+
continue;
|
|
430
|
+
const value = input[field];
|
|
431
|
+
if (value !== undefined)
|
|
432
|
+
captured[field] = value;
|
|
433
|
+
}
|
|
434
|
+
return captured;
|
|
435
|
+
}
|
|
436
|
+
const _exports = Object.freeze({ captureFields: captureFields });
|
|
437
|
+
return _exports;
|
|
438
|
+
})();
|
|
439
|
+
|
|
440
|
+
const _m12 = (() => {
|
|
441
|
+
const { OfficeIMOError } = _m4;
|
|
442
|
+
|
|
443
|
+
const { captureFields } = _m13;
|
|
444
|
+
|
|
445
|
+
/** @internal Check before accepting the next value or chunk. */
|
|
446
|
+
class ExportBudget {
|
|
447
|
+
cells = 0;
|
|
448
|
+
text = 0;
|
|
449
|
+
reservedCells = 0;
|
|
450
|
+
reservedText = 0;
|
|
451
|
+
limits;
|
|
452
|
+
constructor(limits = {}) {
|
|
453
|
+
if (!limits || typeof limits !== "object" || Array.isArray(limits))
|
|
454
|
+
throw new TypeError("Export limits must be an object.");
|
|
455
|
+
// Capture before validation. Supported class getters are ordinary structural
|
|
456
|
+
// options too, and an accessor must not change the ceiling after validation.
|
|
457
|
+
const captured = captureFields(limits, ["maxRows", "maxCells", "maxTextCharacters", "maxOutputBytes"]);
|
|
458
|
+
for (const [key, value] of Object.entries(captured))
|
|
459
|
+
if (value !== undefined && (!Number.isSafeInteger(value) || value < 0))
|
|
460
|
+
throw new RangeError(key + " must be a nonnegative safe integer.");
|
|
461
|
+
this.limits = Object.freeze(captured);
|
|
462
|
+
}
|
|
463
|
+
check(kind, value) {
|
|
464
|
+
const maximum = this.limits[kind];
|
|
465
|
+
if (maximum !== undefined && value > maximum)
|
|
466
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", kind + " exceeded (" + value + " > " + maximum + ").");
|
|
467
|
+
}
|
|
468
|
+
row(count) { this.check("maxRows", count); }
|
|
469
|
+
reserve(cells, characters) {
|
|
470
|
+
this.check("maxCells", this.cells + this.reservedCells + cells);
|
|
471
|
+
this.check("maxTextCharacters", this.text + this.reservedText + characters);
|
|
472
|
+
this.reservedCells += cells;
|
|
473
|
+
this.reservedText += characters;
|
|
474
|
+
}
|
|
475
|
+
release(cells, characters) { this.reservedCells -= cells; this.reservedText -= characters; }
|
|
476
|
+
cell(value, reservedCharacters) {
|
|
477
|
+
if (reservedCharacters !== undefined)
|
|
478
|
+
this.release(1, reservedCharacters);
|
|
479
|
+
// Immutable limits cannot acquire a ceiling later. Avoid per-cell accounting
|
|
480
|
+
// when neither emitted-cell nor text totals are observable by a resource cap.
|
|
481
|
+
if (this.limits.maxCells === undefined && this.limits.maxTextCharacters === undefined)
|
|
482
|
+
return;
|
|
483
|
+
this.check("maxCells", this.cells + this.reservedCells + 1);
|
|
484
|
+
const length = typeof value === "string" ? value.length : 0;
|
|
485
|
+
this.check("maxTextCharacters", this.text + this.reservedText + length);
|
|
486
|
+
this.cells++;
|
|
487
|
+
this.text += length;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
/** @internal Ownership stays with the caller. */
|
|
491
|
+
function boundedSink(sink, budget) {
|
|
492
|
+
let bytes = 0;
|
|
493
|
+
return { write(chunk) {
|
|
494
|
+
budget.check("maxOutputBytes", bytes + chunk.length);
|
|
495
|
+
bytes += chunk.length;
|
|
496
|
+
return sink.write(chunk);
|
|
497
|
+
} };
|
|
498
|
+
}
|
|
499
|
+
const _exports = Object.freeze({ ExportBudget: ExportBudget, boundedSink: boundedSink });
|
|
500
|
+
return _exports;
|
|
501
|
+
})();
|
|
502
|
+
|
|
503
|
+
const _m14 = (() => {
|
|
504
|
+
const { assertExportValue } = _m8;
|
|
505
|
+
|
|
506
|
+
const { checkAbort } = _m2;
|
|
507
|
+
|
|
508
|
+
const { isDate } = _m9;
|
|
509
|
+
|
|
510
|
+
const { captureFields } = _m13;
|
|
511
|
+
|
|
512
|
+
function createRowProjector(columns, worksheet, signal, validate = assertExportValue) {
|
|
513
|
+
const getters = columns.some(column => column.value);
|
|
514
|
+
return (row, rowIndex = 0) => {
|
|
515
|
+
if (Array.isArray(row) && !getters) {
|
|
516
|
+
if (row.length > columns.length)
|
|
517
|
+
throw new RangeError("Row has more values than declared columns.");
|
|
518
|
+
for (const value of row)
|
|
519
|
+
validate(value);
|
|
520
|
+
return row;
|
|
521
|
+
}
|
|
522
|
+
if (!row || typeof row !== "object" || isDate(row))
|
|
523
|
+
throw new TypeError("A row must be an array or object.");
|
|
524
|
+
if (Array.isArray(row) && row.length > columns.length && !columns.every(column => column.value))
|
|
525
|
+
throw new RangeError("Project every column explicitly when selecting from a wider array row.");
|
|
526
|
+
return columns.map((c, columnIndex) => {
|
|
527
|
+
if (c.value) {
|
|
528
|
+
checkAbort(signal);
|
|
529
|
+
const context = { rowIndex, columnIndex, column: c,
|
|
530
|
+
...(worksheet ? { sheetName: worksheet.sheetName, worksheetRow: worksheet.firstDataRow + rowIndex } : {}) };
|
|
531
|
+
const result = c.value(row, context);
|
|
532
|
+
validate(result);
|
|
533
|
+
checkAbort(signal);
|
|
534
|
+
return result;
|
|
535
|
+
}
|
|
536
|
+
if (Array.isArray(row)) {
|
|
537
|
+
const result = row[columnIndex];
|
|
538
|
+
validate(result);
|
|
539
|
+
return result;
|
|
540
|
+
}
|
|
541
|
+
const key = c.key ?? c.header;
|
|
542
|
+
const result = Object.prototype.hasOwnProperty.call(row, key) ? row[key] : undefined;
|
|
543
|
+
validate(result);
|
|
544
|
+
return result;
|
|
545
|
+
});
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
/** @internal Shared metadata fields for full columns and adapter-owned partial overrides. */
|
|
549
|
+
const columnOptionFields = ["header", "key", "value", "width", "type", "format", "wrapText", "alignment", "groups", "style", "valueFormatter"];
|
|
550
|
+
function copyColumns(columns, workbookStyles = false) {
|
|
551
|
+
if (!Array.isArray(columns))
|
|
552
|
+
throw new TypeError("Declare the columns in export order.");
|
|
553
|
+
return columns.map(c => {
|
|
554
|
+
if (!c || typeof c !== "object" && typeof c !== "function")
|
|
555
|
+
throw new TypeError("Each column needs a string header and an optional string key.");
|
|
556
|
+
// Own extension metadata remains available to its format owner. Capture the
|
|
557
|
+
// supported structural fields even when a class exposes prototype getters.
|
|
558
|
+
const captured = captureFields(c, columnOptionFields);
|
|
559
|
+
if (!workbookStyles && captured.style !== undefined)
|
|
560
|
+
throw new TypeError("Workbook-local column styles require the advanced Workbook API; use portable ExportCell presentation.");
|
|
561
|
+
if (typeof captured.header !== "string" || (captured.key !== undefined && typeof captured.key !== "string"))
|
|
562
|
+
throw new TypeError("Each column needs a string header and an optional string key.");
|
|
563
|
+
if (captured.value !== undefined && typeof captured.value !== "function")
|
|
564
|
+
throw new TypeError("Column value getters must be functions.");
|
|
565
|
+
if (captured.groups !== undefined) {
|
|
566
|
+
if (!Array.isArray(captured.groups))
|
|
567
|
+
throw new TypeError("Column groups must be an array of strings.");
|
|
568
|
+
const groups = Array.from(captured.groups);
|
|
569
|
+
if (groups.some(group => typeof group !== "string"))
|
|
570
|
+
throw new TypeError("Column groups must be an array of strings.");
|
|
571
|
+
return { ...captured, groups: Object.freeze(groups) };
|
|
572
|
+
}
|
|
573
|
+
return captured;
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
const _exports = Object.freeze({ createRowProjector: createRowProjector, columnOptionFields: columnOptionFields, copyColumns: copyColumns });
|
|
577
|
+
return _exports;
|
|
578
|
+
})();
|
|
579
|
+
|
|
580
|
+
const _m15 = (() => {
|
|
581
|
+
class NumericAggregate {
|
|
582
|
+
operation;
|
|
583
|
+
count = 0;
|
|
584
|
+
sum = 0;
|
|
585
|
+
mean = 0;
|
|
586
|
+
min = Infinity;
|
|
587
|
+
max = -Infinity;
|
|
588
|
+
constructor(operation) {
|
|
589
|
+
this.operation = operation;
|
|
590
|
+
}
|
|
591
|
+
accept(value) {
|
|
592
|
+
if (!this.operation || typeof value !== "number" || !Number.isFinite(value))
|
|
593
|
+
return;
|
|
594
|
+
this.count++;
|
|
595
|
+
if (this.operation === "sum") {
|
|
596
|
+
this.sum += value;
|
|
597
|
+
if (!Number.isFinite(this.sum))
|
|
598
|
+
throw new RangeError("Numeric total exceeds finite number range.");
|
|
599
|
+
}
|
|
600
|
+
else if (this.operation === "average") {
|
|
601
|
+
const delta = value - this.mean;
|
|
602
|
+
this.mean = this.count === 1 ? value : Number.isFinite(delta) ? this.mean + delta / this.count : this.mean * ((this.count - 1) / this.count) + value / this.count;
|
|
603
|
+
}
|
|
604
|
+
else if (this.operation === "min")
|
|
605
|
+
this.min = Math.min(this.min, value);
|
|
606
|
+
else if (this.operation === "max")
|
|
607
|
+
this.max = Math.max(this.max, value);
|
|
608
|
+
}
|
|
609
|
+
value() {
|
|
610
|
+
return this.operation === "count" ? this.count : this.operation === "sum" ? this.sum : !this.count ? null : this.operation === "average" ? this.mean : this.operation === "min" ? this.min : this.max;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
function createTotals(columns, totals = {}) {
|
|
614
|
+
const keys = columns.map(c => c.key ?? c.header);
|
|
615
|
+
for (const [key, operation] of Object.entries(totals)) {
|
|
616
|
+
if (keys.filter(k => k === key).length !== 1)
|
|
617
|
+
throw new TypeError("Totals need an unambiguous declared column key: " + key);
|
|
618
|
+
if (!["sum", "count", "average", "min", "max"].includes(operation))
|
|
619
|
+
throw new TypeError("Invalid total operation.");
|
|
620
|
+
}
|
|
621
|
+
return keys.map(key => new NumericAggregate(Object.prototype.hasOwnProperty.call(totals, key) ? totals[key] : undefined));
|
|
622
|
+
}
|
|
623
|
+
const _exports = Object.freeze({ NumericAggregate: NumericAggregate, createTotals: createTotals });
|
|
624
|
+
return _exports;
|
|
625
|
+
})();
|
|
626
|
+
|
|
627
|
+
const _m16 = (() => {
|
|
628
|
+
const { ExportCell, assertExportValue } = _m8;
|
|
629
|
+
|
|
630
|
+
const { isDate } = _m9;
|
|
631
|
+
|
|
632
|
+
/** Copy portable values when an operation retains metadata or a projected row beyond its producer's turn. */
|
|
633
|
+
function copyExportValue(value) {
|
|
634
|
+
assertExportValue(value);
|
|
635
|
+
if (isDate(value))
|
|
636
|
+
return new Date(Date.prototype.getTime.call(value));
|
|
637
|
+
if (value instanceof ExportCell) {
|
|
638
|
+
const { value: scalar, text, presentation, link } = value;
|
|
639
|
+
return new ExportCell(isDate(scalar) ? new Date(Date.prototype.getTime.call(scalar)) : scalar, { ...(text === undefined ? {} : { text }), ...(presentation === undefined ? {} : { presentation }),
|
|
640
|
+
...(link === undefined ? {} : { link }) });
|
|
641
|
+
}
|
|
642
|
+
return value;
|
|
643
|
+
}
|
|
644
|
+
const _exports = Object.freeze({ copyExportValue: copyExportValue });
|
|
645
|
+
return _exports;
|
|
646
|
+
})();
|
|
647
|
+
|
|
648
|
+
const _m11 = (() => {
|
|
649
|
+
const { ExportCell, assertScalar } = _m8;
|
|
650
|
+
|
|
651
|
+
const { isDate } = _m9;
|
|
652
|
+
|
|
653
|
+
const { checkAbort, inputRows, pause, taskYieldDue } = _m2;
|
|
654
|
+
|
|
655
|
+
const { ExportBudget } = _m12;
|
|
656
|
+
|
|
657
|
+
const { OfficeIMOError } = _m4;
|
|
658
|
+
|
|
659
|
+
const { copyColumns, createRowProjector } = _m14;
|
|
660
|
+
|
|
661
|
+
const { createTotals } = _m15;
|
|
662
|
+
|
|
663
|
+
const { copyExportValue } = _m16;
|
|
664
|
+
|
|
665
|
+
const sources = new WeakMap();
|
|
666
|
+
/** @internal Writers accept the owned immutable event source rather than trusting caller-authored event protocols. */
|
|
667
|
+
function assertGroupedReportSource(value) {
|
|
668
|
+
if (!value || typeof value !== "object" || !sources.has(value))
|
|
669
|
+
throw new TypeError("Create grouped report sources with createGroupedReport.");
|
|
670
|
+
}
|
|
671
|
+
/** @internal The consuming writer's signal reaches pending source reads as well as destination writes. */
|
|
672
|
+
function groupedReportEvents(source, signal) {
|
|
673
|
+
assertGroupedReportSource(source);
|
|
674
|
+
return { async *[Symbol.asyncIterator]() {
|
|
675
|
+
const operation = groupedReportOperation(source, signal);
|
|
676
|
+
try {
|
|
677
|
+
yield* operation.events;
|
|
678
|
+
}
|
|
679
|
+
finally {
|
|
680
|
+
operation.dispose();
|
|
681
|
+
}
|
|
682
|
+
} };
|
|
683
|
+
}
|
|
684
|
+
/** @internal Share cancellation between original source reads and destination writes; callers dispose in finally. */
|
|
685
|
+
function groupedReportOperation(source, signal) {
|
|
686
|
+
assertGroupedReportSource(source);
|
|
687
|
+
const factory = sources.get(source), linked = linkedSignals(factory.signal, signal);
|
|
688
|
+
return { signal: linked.signal, events: factory.events(linked.signal), dispose: linked.dispose };
|
|
689
|
+
}
|
|
690
|
+
function linkedSignals(source, consumer) {
|
|
691
|
+
if (!source || !consumer || source === consumer)
|
|
692
|
+
return { signal: source ?? consumer, dispose() { } };
|
|
693
|
+
const controller = new AbortController(), abortSource = () => controller.abort(source.reason), abortConsumer = () => controller.abort(consumer.reason);
|
|
694
|
+
source.addEventListener("abort", abortSource, { once: true });
|
|
695
|
+
consumer.addEventListener("abort", abortConsumer, { once: true });
|
|
696
|
+
if (source.aborted)
|
|
697
|
+
abortSource();
|
|
698
|
+
else if (consumer.aborted)
|
|
699
|
+
abortConsumer();
|
|
700
|
+
return { signal: controller.signal, dispose() { source.removeEventListener("abort", abortSource); consumer.removeEventListener("abort", abortConsumer); } };
|
|
701
|
+
}
|
|
702
|
+
function maximum(value, fallback, name) {
|
|
703
|
+
const result = value ?? fallback;
|
|
704
|
+
if (!Number.isSafeInteger(result) || result < 0)
|
|
705
|
+
throw new RangeError(name + " must be a nonnegative safe integer.");
|
|
706
|
+
return result;
|
|
707
|
+
}
|
|
708
|
+
function scalar(value) { return value instanceof ExportCell ? value.value : value; }
|
|
709
|
+
function identity(value) {
|
|
710
|
+
if (value == null)
|
|
711
|
+
return { key: null, id: "null", text: "" };
|
|
712
|
+
if (isDate(value)) {
|
|
713
|
+
const time = Date.prototype.getTime.call(value);
|
|
714
|
+
if (!Number.isFinite(time))
|
|
715
|
+
throw new TypeError("A group key date must be valid.");
|
|
716
|
+
return { key: new Date(time), id: "date:" + time, text: new Date(time).toISOString() };
|
|
717
|
+
}
|
|
718
|
+
if (typeof value === "number" && !Number.isFinite(value))
|
|
719
|
+
throw new TypeError("A numeric group key must be finite.");
|
|
720
|
+
const text = String(value);
|
|
721
|
+
return { key: value, id: typeof value + ":" + text, text };
|
|
722
|
+
}
|
|
723
|
+
function eventKey(value) { return isDate(value) ? new Date(Date.prototype.getTime.call(value)) : value; }
|
|
724
|
+
function result(aggregates) {
|
|
725
|
+
return Object.freeze(aggregates.map(aggregate => aggregate.operation === undefined ? null : aggregate.value()));
|
|
726
|
+
}
|
|
727
|
+
function groupingLevels(input, keys, groupLabel) {
|
|
728
|
+
const selected = typeof input === "string" ? [input] : Array.isArray(input) ? Array.from(input) : undefined;
|
|
729
|
+
if (!selected || selected.length < 1 || selected.length > 4)
|
|
730
|
+
throw new TypeError("groupBy must declare between one and four grouping levels.");
|
|
731
|
+
if (groupLabel !== undefined && typeof groupLabel !== "function")
|
|
732
|
+
throw new TypeError("groupLabel must be a synchronous function.");
|
|
733
|
+
if (groupLabel && selected.length !== 1)
|
|
734
|
+
throw new TypeError("groupLabel is only available for one grouping level; use descriptor labels for a hierarchy.");
|
|
735
|
+
const seen = new Set();
|
|
736
|
+
return Object.freeze(selected.map(level => {
|
|
737
|
+
if (typeof level !== "string" && (!level || typeof level !== "object" || Array.isArray(level)))
|
|
738
|
+
throw new TypeError("A grouping level must name a stable column key or provide a descriptor.");
|
|
739
|
+
// Supported structural fields, including prototype accessors, are captured once.
|
|
740
|
+
const { key, value, label } = typeof level === "string" ? { key: level, value: undefined, label: undefined } : level;
|
|
741
|
+
if (typeof key !== "string" || !key.length || seen.has(key))
|
|
742
|
+
throw new TypeError("Grouping levels need unique, nonempty stable keys.");
|
|
743
|
+
seen.add(key);
|
|
744
|
+
if (value !== undefined && typeof value !== "function")
|
|
745
|
+
throw new TypeError("Grouping value getters must be synchronous functions.");
|
|
746
|
+
if (label !== undefined && typeof label !== "function")
|
|
747
|
+
throw new TypeError("Grouping labels must be synchronous functions.");
|
|
748
|
+
if (label && groupLabel)
|
|
749
|
+
throw new TypeError("Specify either groupLabel or the grouping descriptor label.");
|
|
750
|
+
const column = keys.indexOf(key);
|
|
751
|
+
if (column >= 0 && value !== undefined)
|
|
752
|
+
throw new TypeError("A declared grouping column reuses its projected value; do not provide another value getter.");
|
|
753
|
+
if (column < 0 && value === undefined)
|
|
754
|
+
throw new TypeError("groupBy must name a declared stable column key; hidden grouping fields need an explicit value getter.");
|
|
755
|
+
return Object.freeze({ key, column, value, label: label ?? groupLabel });
|
|
756
|
+
}));
|
|
757
|
+
}
|
|
758
|
+
/** Copy date keys on every event so a consumer cannot mutate later hierarchy decisions. */
|
|
759
|
+
function groupPath(active) {
|
|
760
|
+
return Object.freeze(active.map(({ group }) => Object.freeze({ ...group, key: eventKey(group.key) })));
|
|
761
|
+
}
|
|
762
|
+
function labelText(format, key, fallback) {
|
|
763
|
+
if (!format)
|
|
764
|
+
return fallback;
|
|
765
|
+
const formatted = format(eventKey(key));
|
|
766
|
+
if (typeof formatted?.then === "function")
|
|
767
|
+
void Promise.resolve(formatted).catch(() => { });
|
|
768
|
+
if (typeof formatted !== "string")
|
|
769
|
+
throw new TypeError("Grouping labels must return synchronous text.");
|
|
770
|
+
return formatted;
|
|
771
|
+
}
|
|
772
|
+
/** Group a preordered row source once. Closed-group recurrence within the same parent rejects.
|
|
773
|
+
* Equality is locale independent: strings are exact, numbers and booleans retain their types, dates compare
|
|
774
|
+
* by UTC instant, and null/undefined share one group. No sorting or complete group-body retention occurs. */
|
|
775
|
+
function createGroupedReport(rows, options) {
|
|
776
|
+
if (!options || typeof options !== "object")
|
|
777
|
+
throw new TypeError("Grouped report options are required.");
|
|
778
|
+
// Capture configuration before validation so accessors cannot select different columns in later stages.
|
|
779
|
+
const { columns: selected, groupBy, totals: selectedTotals, groupLabel, maxGroups: requestedGroups, maxGroupKeyCharacters: requestedCharacters, signal: sourceSignal, limits } = options;
|
|
780
|
+
if (limits !== undefined && (!limits || typeof limits !== "object" || Array.isArray(limits)))
|
|
781
|
+
throw new TypeError("Grouped source limits must be an object.");
|
|
782
|
+
if (limits !== undefined && "maxOutputBytes" in limits)
|
|
783
|
+
throw new TypeError("Set maxOutputBytes on the format writer, not the grouped source.");
|
|
784
|
+
if (!Array.isArray(selected) || !selected.length)
|
|
785
|
+
throw new TypeError("A grouped report needs declared columns.");
|
|
786
|
+
const columns = copyColumns(selected);
|
|
787
|
+
const keys = columns.map(column => column.key);
|
|
788
|
+
if (keys.some(key => typeof key !== "string" || key.length === 0) || new Set(keys).size !== keys.length)
|
|
789
|
+
throw new TypeError("Grouped report columns need unique, nonempty stable keys.");
|
|
790
|
+
const levels = groupingLevels(groupBy, keys, groupLabel);
|
|
791
|
+
const totals = Object.freeze({ ...selectedTotals });
|
|
792
|
+
const grand = createTotals(columns, totals);
|
|
793
|
+
for (let column = 0; column < columns.length; column++)
|
|
794
|
+
if (grand[column].operation !== undefined && columns[column].type !== "number")
|
|
795
|
+
throw new TypeError("Grouped numeric totals require a column declared with type:number.");
|
|
796
|
+
const maxGroups = maximum(requestedGroups, 1000, "maxGroups");
|
|
797
|
+
const maxCharacters = maximum(requestedCharacters, 1000000, "maxGroupKeyCharacters");
|
|
798
|
+
const budget = new ExportBudget(limits);
|
|
799
|
+
const portable = Object.freeze(columns.map(column => {
|
|
800
|
+
const { value: _getter, ...metadata } = column;
|
|
801
|
+
return Object.freeze(metadata);
|
|
802
|
+
}));
|
|
803
|
+
for (const column of columns) {
|
|
804
|
+
budget.cell(column.header);
|
|
805
|
+
for (const group of column.groups ?? [])
|
|
806
|
+
budget.reserve(0, group.length);
|
|
807
|
+
Object.freeze(column);
|
|
808
|
+
}
|
|
809
|
+
let consumed = false;
|
|
810
|
+
const eventsFor = (signal) => Object.freeze({ [Symbol.asyncIterator]() {
|
|
811
|
+
if (consumed)
|
|
812
|
+
throw new TypeError("A grouped report source can be consumed only once.");
|
|
813
|
+
consumed = true;
|
|
814
|
+
return iterate(signal);
|
|
815
|
+
} });
|
|
816
|
+
const events = eventsFor(sourceSignal);
|
|
817
|
+
async function* iterate(signal) {
|
|
818
|
+
const project = createRowProjector(columns, undefined, signal);
|
|
819
|
+
const seen = new Set(), active = [];
|
|
820
|
+
let characters = 0, rowCount = 0, groups = 0;
|
|
821
|
+
for await (const input of inputRows(rows, signal)) {
|
|
822
|
+
// Copy positional input once before the shared projector validates and inspects its values.
|
|
823
|
+
const snapshot = Array.isArray(input) ? Array.from(input) : input;
|
|
824
|
+
const projected = project(snapshot, rowCount), values = [];
|
|
825
|
+
for (let column = 0; column < columns.length; column++)
|
|
826
|
+
values.push(copyExportValue(projected[column]) ?? null);
|
|
827
|
+
checkAbort(signal);
|
|
828
|
+
const next = levels.map((level, index) => {
|
|
829
|
+
checkAbort(signal);
|
|
830
|
+
const value = level.column >= 0 ? scalar(values[level.column]) : level.value(snapshot, Object.freeze({ rowIndex: rowCount, level: index, key: level.key }));
|
|
831
|
+
assertScalar(value);
|
|
832
|
+
checkAbort(signal);
|
|
833
|
+
return identity(value);
|
|
834
|
+
});
|
|
835
|
+
budget.row(rowCount + 1);
|
|
836
|
+
for (let column = 0; column < values.length; column++) {
|
|
837
|
+
const value = values[column], raw = scalar(value);
|
|
838
|
+
if (grand[column].operation !== undefined && raw != null && (typeof raw !== "number" || !Number.isFinite(raw)))
|
|
839
|
+
throw new TypeError("Grouped numeric metrics must resolve to finite numbers or null.");
|
|
840
|
+
budget.cell(raw);
|
|
841
|
+
if (value instanceof ExportCell && value.text !== undefined)
|
|
842
|
+
budget.reserve(0, value.text.length);
|
|
843
|
+
}
|
|
844
|
+
let common = 0;
|
|
845
|
+
while (common < active.length && active[common].id === next[common].id)
|
|
846
|
+
common++;
|
|
847
|
+
const pending = [];
|
|
848
|
+
for (let level = common; level < levels.length; level++) {
|
|
849
|
+
const value = next[level], parent = pending.at(-1) ?? active[level - 1];
|
|
850
|
+
// Parent indexes are generated integers, so scalar strings containing delimiters cannot collide.
|
|
851
|
+
const scopedId = (parent?.group.groupIndex ?? -1) + ":" + value.id;
|
|
852
|
+
if (seen.has(scopedId))
|
|
853
|
+
throw new TypeError("Grouped rows must be contiguous; a closed group key occurred again within the same parent.");
|
|
854
|
+
if (groups === maxGroups)
|
|
855
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "maxGroups exceeded.");
|
|
856
|
+
const label = labelText(levels[level].label, value.key, value.text);
|
|
857
|
+
checkAbort(signal);
|
|
858
|
+
const nextCharacters = characters + scopedId.length + label.length;
|
|
859
|
+
if (!Number.isSafeInteger(nextCharacters) || nextCharacters > maxCharacters)
|
|
860
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "maxGroupKeyCharacters exceeded.");
|
|
861
|
+
budget.reserve(0, label.length);
|
|
862
|
+
pending.push({ id: value.id, group: Object.freeze({ groupIndex: groups, key: value.key, label, level }),
|
|
863
|
+
rows: 0, aggregates: createTotals(columns, totals) });
|
|
864
|
+
characters = nextCharacters;
|
|
865
|
+
seen.add(scopedId);
|
|
866
|
+
groups++;
|
|
867
|
+
}
|
|
868
|
+
while (active.length > common) {
|
|
869
|
+
checkAbort(signal);
|
|
870
|
+
const path = groupPath(active), ending = active.pop();
|
|
871
|
+
yield Object.freeze({ kind: "groupEnd", ...path.at(-1), path, rows: ending.rows, totals: result(ending.aggregates) });
|
|
872
|
+
}
|
|
873
|
+
for (const opening of pending) {
|
|
874
|
+
checkAbort(signal);
|
|
875
|
+
active.push(opening);
|
|
876
|
+
const path = groupPath(active);
|
|
877
|
+
yield Object.freeze({ kind: "groupStart", ...path.at(-1), path });
|
|
878
|
+
}
|
|
879
|
+
for (let column = 0; column < values.length; column++) {
|
|
880
|
+
const raw = scalar(values[column]);
|
|
881
|
+
for (const group of active)
|
|
882
|
+
group.aggregates[column].accept(raw);
|
|
883
|
+
grand[column].accept(raw);
|
|
884
|
+
}
|
|
885
|
+
for (const group of active)
|
|
886
|
+
group.rows++;
|
|
887
|
+
checkAbort(signal);
|
|
888
|
+
yield Object.freeze({ kind: "row", values: Object.freeze(values), rowIndex: rowCount,
|
|
889
|
+
groupIndex: active.at(-1).group.groupIndex, path: groupPath(active) });
|
|
890
|
+
rowCount++;
|
|
891
|
+
if (taskYieldDue()) {
|
|
892
|
+
await pause();
|
|
893
|
+
checkAbort(signal);
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
checkAbort(signal);
|
|
897
|
+
while (active.length) {
|
|
898
|
+
checkAbort(signal);
|
|
899
|
+
const path = groupPath(active), ending = active.pop();
|
|
900
|
+
yield Object.freeze({ kind: "groupEnd", ...path.at(-1), path, rows: ending.rows, totals: result(ending.aggregates) });
|
|
901
|
+
}
|
|
902
|
+
checkAbort(signal);
|
|
903
|
+
yield Object.freeze({ kind: "complete", rows: rowCount, groups, totals: result(grand) });
|
|
904
|
+
}
|
|
905
|
+
const source = Object.freeze({ columns: portable, groupBy: Object.freeze(levels.map(level => level.key)), totals, events });
|
|
906
|
+
sources.set(source, { signal: sourceSignal, events: eventsFor });
|
|
907
|
+
return source;
|
|
908
|
+
}
|
|
909
|
+
const _exports = Object.freeze({ assertGroupedReportSource: assertGroupedReportSource, groupedReportEvents: groupedReportEvents, groupedReportOperation: groupedReportOperation, createGroupedReport: createGroupedReport });
|
|
910
|
+
return _exports;
|
|
911
|
+
})();
|
|
912
|
+
|
|
913
|
+
const _m7 = (() => {
|
|
914
|
+
|
|
915
|
+
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
|
|
920
|
+
|
|
921
|
+
|
|
922
|
+
|
|
923
|
+
|
|
924
|
+
const { OfficeIMOError } = _m4;
|
|
925
|
+
|
|
926
|
+
/** Feature detection has no import-time DOM or compressor side effects. */
|
|
927
|
+
function detectFeatures() {
|
|
928
|
+
let deflateRaw = false;
|
|
929
|
+
if (typeof CompressionStream === "function") {
|
|
930
|
+
try {
|
|
931
|
+
new CompressionStream("deflate-raw");
|
|
932
|
+
deflateRaw = true;
|
|
933
|
+
}
|
|
934
|
+
catch { /* stored fallback */ }
|
|
935
|
+
}
|
|
936
|
+
return { blob: typeof Blob === "function", streams: typeof WritableStream === "function", deflateRaw,
|
|
937
|
+
download: typeof document !== "undefined" && typeof URL.createObjectURL === "function" };
|
|
938
|
+
}
|
|
939
|
+
/** Browser download helper. Workers and Node should deliver the Blob themselves. */
|
|
940
|
+
function saveBlob(blob, fileName) {
|
|
941
|
+
if (!(blob instanceof Blob) || typeof fileName !== "string" || !fileName)
|
|
942
|
+
throw new TypeError("A Blob and file name are required.");
|
|
943
|
+
if (typeof document === "undefined" || typeof URL.createObjectURL !== "function")
|
|
944
|
+
throw new OfficeIMOError("PLATFORM_UNAVAILABLE", "saveBlob requires a browser document and object URLs.");
|
|
945
|
+
const url = URL.createObjectURL(blob), link = document.createElement("a");
|
|
946
|
+
try {
|
|
947
|
+
link.href = url;
|
|
948
|
+
link.download = fileName;
|
|
949
|
+
document.body.append(link);
|
|
950
|
+
link.click();
|
|
951
|
+
}
|
|
952
|
+
finally {
|
|
953
|
+
link.remove();
|
|
954
|
+
setTimeout(() => URL.revokeObjectURL(url), 30000);
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
const _exports = Object.freeze({ OfficeIMOError: _m4.OfficeIMOError, NotSupportedError: _m4.NotSupportedError, BlobByteSink: _m3.BlobByteSink, ChunkedTextSink: _m3.ChunkedTextSink, writeBytes: _m3.writeBytes, ExportCell: _m8.ExportCell, createGroupedReport: _m11.createGroupedReport, checkAbort: _m2.checkAbort, withAbort: _m2.withAbort, inputRows: _m2.inputRows, pause: _m2.pause, detectFeatures: detectFeatures, saveBlob: saveBlob });
|
|
958
|
+
return _exports;
|
|
959
|
+
})();
|
|
960
|
+
|
|
961
|
+
const _m6 = (() => {
|
|
962
|
+
const { ExportCell, NotSupportedError, OfficeIMOError } = _m7;
|
|
963
|
+
|
|
964
|
+
const { assertExportValue, assertScalar, copyCellPresentation } = _m8;
|
|
965
|
+
|
|
966
|
+
const { copyExportLink } = _m10;
|
|
967
|
+
|
|
968
|
+
const { isDate } = _m9;
|
|
969
|
+
|
|
970
|
+
const protocol = "@evotecit/officeimo/worker-export/1";
|
|
971
|
+
function message(value) {
|
|
972
|
+
if (!value || typeof value !== "object")
|
|
973
|
+
return undefined;
|
|
974
|
+
const candidate = value;
|
|
975
|
+
return candidate.protocol === protocol && typeof candidate.job === "string" && typeof candidate.kind === "string" ? candidate : undefined;
|
|
976
|
+
}
|
|
977
|
+
function bounds(options) {
|
|
978
|
+
const result = { batchRows: options.batchRows ?? 64, maxBatchCells: options.maxBatchCells ?? 65536,
|
|
979
|
+
maxBatchCharacters: options.maxBatchCharacters ?? 1000000, maxChunkBytes: options.maxChunkBytes ?? 65536,
|
|
980
|
+
maxSetupBytes: options.maxSetupBytes ?? 16 * 1024 * 1024, maxSetupNodes: options.maxSetupNodes ?? 100000 };
|
|
981
|
+
for (const [name, value] of Object.entries(result))
|
|
982
|
+
if (!Number.isSafeInteger(value) || value < 1)
|
|
983
|
+
throw new RangeError(name + " must be a positive safe integer.");
|
|
984
|
+
return Object.freeze(result);
|
|
985
|
+
}
|
|
986
|
+
/** Snapshot portable setup before messaging. Font objects, functions, accessors and cyclic live objects stay in their host. */
|
|
987
|
+
function captureInput(input, limits) {
|
|
988
|
+
let nodes = 0, bytes = 0;
|
|
989
|
+
const ancestors = new Set();
|
|
990
|
+
function accept(additional = 0) {
|
|
991
|
+
bytes += additional;
|
|
992
|
+
if (bytes > limits.maxSetupBytes || ++nodes > limits.maxSetupNodes)
|
|
993
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "Worker configuration exceeds its message budget.");
|
|
994
|
+
}
|
|
995
|
+
function copy(value, depth) {
|
|
996
|
+
if (depth > 32)
|
|
997
|
+
throw new RangeError("Worker configuration nesting exceeds 32 levels.");
|
|
998
|
+
accept(typeof value === "string" ? value.length * 2 : 0);
|
|
999
|
+
if (value == null || ["string", "number", "boolean"].includes(typeof value))
|
|
1000
|
+
return value;
|
|
1001
|
+
if (isDate(value)) {
|
|
1002
|
+
accept(8);
|
|
1003
|
+
return new Date(value.getTime());
|
|
1004
|
+
}
|
|
1005
|
+
if (ArrayBuffer.isView(value) && Object.prototype.toString.call(value) === "[object Uint8Array]") {
|
|
1006
|
+
accept(value.byteLength);
|
|
1007
|
+
return new Uint8Array(value);
|
|
1008
|
+
}
|
|
1009
|
+
if (typeof value !== "object")
|
|
1010
|
+
throw new TypeError("Worker configuration requires portable data without functions or symbols.");
|
|
1011
|
+
if (ancestors.has(value))
|
|
1012
|
+
throw new TypeError("Worker configuration cannot contain cycles.");
|
|
1013
|
+
const prototype = Object.getPrototypeOf(value);
|
|
1014
|
+
const constructor = prototype == null ? undefined : Object.getOwnPropertyDescriptor(prototype, "constructor")?.value;
|
|
1015
|
+
const plain = prototype === null || Object.getPrototypeOf(prototype) === null && typeof constructor === "function" &&
|
|
1016
|
+
Function.prototype.toString.call(constructor) === Function.prototype.toString.call(Object);
|
|
1017
|
+
if (!Array.isArray(value) && !plain)
|
|
1018
|
+
throw new TypeError("Worker configuration supports plain records, arrays, Dates and Uint8Array bytes; reconstruct font instances in the worker.");
|
|
1019
|
+
ancestors.add(value);
|
|
1020
|
+
try {
|
|
1021
|
+
if (Array.isArray(value)) {
|
|
1022
|
+
if (value.length > limits.maxSetupNodes - nodes)
|
|
1023
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "Worker configuration exceeds its message budget.");
|
|
1024
|
+
const snapshot = [];
|
|
1025
|
+
for (let i = 0; i < value.length; i++) {
|
|
1026
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, String(i));
|
|
1027
|
+
if (descriptor && !Object.prototype.hasOwnProperty.call(descriptor, "value"))
|
|
1028
|
+
throw new TypeError("Worker configuration cannot contain accessors.");
|
|
1029
|
+
snapshot.push(copy(descriptor?.value, depth + 1));
|
|
1030
|
+
}
|
|
1031
|
+
return snapshot;
|
|
1032
|
+
}
|
|
1033
|
+
const snapshot = {};
|
|
1034
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
1035
|
+
if (typeof key !== "string")
|
|
1036
|
+
throw new TypeError("Worker configuration keys must be strings.");
|
|
1037
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
1038
|
+
if (!descriptor.enumerable)
|
|
1039
|
+
continue;
|
|
1040
|
+
if (!Object.prototype.hasOwnProperty.call(descriptor, "value"))
|
|
1041
|
+
throw new TypeError("Worker configuration cannot contain accessors.");
|
|
1042
|
+
accept(key.length * 2);
|
|
1043
|
+
Object.defineProperty(snapshot, key, { value: copy(descriptor.value, depth + 1), enumerable: true, configurable: true, writable: true });
|
|
1044
|
+
}
|
|
1045
|
+
return snapshot;
|
|
1046
|
+
}
|
|
1047
|
+
finally {
|
|
1048
|
+
ancestors.delete(value);
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
return copy(input, 0);
|
|
1052
|
+
}
|
|
1053
|
+
function captureRow(row) {
|
|
1054
|
+
if (!Array.isArray(row))
|
|
1055
|
+
throw new TypeError("Worker export rows must be projected arrays.");
|
|
1056
|
+
let characters = 0;
|
|
1057
|
+
const scalar = (value) => {
|
|
1058
|
+
if (typeof value === "string")
|
|
1059
|
+
characters += value.length;
|
|
1060
|
+
return isDate(value) ? new Date(value.getTime()) : value;
|
|
1061
|
+
};
|
|
1062
|
+
const cells = row.map(value => {
|
|
1063
|
+
assertExportValue(value);
|
|
1064
|
+
if (!(value instanceof ExportCell))
|
|
1065
|
+
return { value: scalar(value) };
|
|
1066
|
+
const cellValue = value.value, text = value.text, presentation = value.presentation, link = value.link;
|
|
1067
|
+
assertScalar(cellValue);
|
|
1068
|
+
if (text !== undefined && typeof text !== "string")
|
|
1069
|
+
throw new TypeError("Display text must be a string.");
|
|
1070
|
+
const options = {
|
|
1071
|
+
...(text === undefined ? {} : { text }),
|
|
1072
|
+
...(presentation === undefined ? {} : { presentation: copyCellPresentation(presentation) }),
|
|
1073
|
+
...(link === undefined ? {} : { link: copyExportLink(link) })
|
|
1074
|
+
};
|
|
1075
|
+
characters += text?.length ?? 0;
|
|
1076
|
+
for (const entry of Object.values(options.presentation ?? {}))
|
|
1077
|
+
if (typeof entry === "string")
|
|
1078
|
+
characters += entry.length;
|
|
1079
|
+
characters += (options.link?.target.length ?? 0) + (options.link?.tooltip?.length ?? 0);
|
|
1080
|
+
return { value: scalar(cellValue), options };
|
|
1081
|
+
});
|
|
1082
|
+
return { cells, characters };
|
|
1083
|
+
}
|
|
1084
|
+
function restoreRows(rows, limits) {
|
|
1085
|
+
if (!Array.isArray(rows) || rows.length > limits.batchRows)
|
|
1086
|
+
throw new TypeError("Invalid worker row batch.");
|
|
1087
|
+
let cells = 0, characters = 0;
|
|
1088
|
+
return rows.map(row => {
|
|
1089
|
+
if (!Array.isArray(row))
|
|
1090
|
+
throw new TypeError("Invalid worker row.");
|
|
1091
|
+
if (cells + row.length > limits.maxBatchCells)
|
|
1092
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "Worker row batch exceeds its message budget.");
|
|
1093
|
+
const restored = row.map((cell) => {
|
|
1094
|
+
if (!cell || typeof cell !== "object")
|
|
1095
|
+
throw new TypeError("Invalid worker cell.");
|
|
1096
|
+
const value = cell.options === undefined ? cell.value : new ExportCell(cell.value, cell.options);
|
|
1097
|
+
assertExportValue(value);
|
|
1098
|
+
return value;
|
|
1099
|
+
});
|
|
1100
|
+
const captured = captureRow(restored);
|
|
1101
|
+
cells += row.length;
|
|
1102
|
+
characters += captured.characters;
|
|
1103
|
+
if (cells > limits.maxBatchCells || characters > limits.maxBatchCharacters)
|
|
1104
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "Worker row batch exceeds its message budget.");
|
|
1105
|
+
return restored;
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
function captureProgress(value, limits) {
|
|
1109
|
+
if (!value || !["rows", "complete"].includes(value.phase) || !Number.isSafeInteger(value.rows) || value.rows < 0)
|
|
1110
|
+
throw new TypeError("Invalid worker progress.");
|
|
1111
|
+
for (const key of ["bytes", "sheetRows", "totalRows"])
|
|
1112
|
+
if (value[key] !== undefined && (!Number.isSafeInteger(value[key]) || value[key] < 0))
|
|
1113
|
+
throw new TypeError("Invalid worker progress count.");
|
|
1114
|
+
if (value.sheetName !== undefined && (typeof value.sheetName !== "string" || value.sheetName.length > limits.maxBatchCharacters))
|
|
1115
|
+
throw new TypeError("Invalid or oversized worker sheet name.");
|
|
1116
|
+
return { phase: value.phase, rows: value.rows,
|
|
1117
|
+
...(value.bytes === undefined ? {} : { bytes: value.bytes }), ...(value.sheetRows === undefined ? {} : { sheetRows: value.sheetRows }),
|
|
1118
|
+
...(value.totalRows === undefined ? {} : { totalRows: value.totalRows }), ...(value.sheetName === undefined ? {} : { sheetName: value.sheetName }) };
|
|
1119
|
+
}
|
|
1120
|
+
function wireError(error) {
|
|
1121
|
+
return { name: error instanceof Error ? error.name : "Error", message: error instanceof Error ? error.message : String(error),
|
|
1122
|
+
...(error instanceof OfficeIMOError ? { code: error.code } : {}), ...(error instanceof NotSupportedError ? { feature: error.feature } : {}) };
|
|
1123
|
+
}
|
|
1124
|
+
function restoreError(error) {
|
|
1125
|
+
if (!error || typeof error.message !== "string")
|
|
1126
|
+
return new Error("Worker export failed.");
|
|
1127
|
+
const result = error.code === "NOT_SUPPORTED" && typeof error.feature === "string" ? new NotSupportedError(error.feature)
|
|
1128
|
+
: error.code === undefined ? new Error(error.message) : new OfficeIMOError(error.code, error.message);
|
|
1129
|
+
result.message = error.message;
|
|
1130
|
+
if (typeof error.name === "string")
|
|
1131
|
+
result.name = error.name;
|
|
1132
|
+
return result;
|
|
1133
|
+
}
|
|
1134
|
+
function result(value) {
|
|
1135
|
+
if (!value || [value.rows, value.columns, value.bytes].some(n => !Number.isSafeInteger(n) || n < 0))
|
|
1136
|
+
throw new TypeError("Invalid worker export result.");
|
|
1137
|
+
return { rows: value.rows, columns: value.columns, bytes: value.bytes };
|
|
1138
|
+
}
|
|
1139
|
+
const _exports = Object.freeze({ protocol: protocol, message: message, bounds: bounds, captureInput: captureInput, captureRow: captureRow, restoreRows: restoreRows, captureProgress: captureProgress, wireError: wireError, restoreError: restoreError, result: result });
|
|
1140
|
+
return _exports;
|
|
1141
|
+
})();
|
|
1142
|
+
|
|
1143
|
+
const _m1 = (() => {
|
|
1144
|
+
const { checkAbort, inputRows, withAbort } = _m2;
|
|
1145
|
+
|
|
1146
|
+
const { withDestination } = _m3;
|
|
1147
|
+
|
|
1148
|
+
const { notifyProgress } = _m5;
|
|
1149
|
+
|
|
1150
|
+
const { OfficeIMOError } = _m4;
|
|
1151
|
+
|
|
1152
|
+
const { bounds, captureInput, captureProgress, captureRow, message, protocol, restoreError, result, wireError } = _m6;
|
|
1153
|
+
|
|
1154
|
+
const { captureFields } = _m13;
|
|
1155
|
+
|
|
1156
|
+
const active = new WeakSet();
|
|
1157
|
+
let sequence = 0;
|
|
1158
|
+
/** Execute through a host-owned worker with bounded rows, acknowledged bytes and coalesced progress.
|
|
1159
|
+
* The host owns the worker, source I/O and partial destination bytes. No caller-owned buffer is transferred. */
|
|
1160
|
+
async function executeWorkerExport(endpoint, rows, destination, options = {}) {
|
|
1161
|
+
const captured = captureFields(options, ["input", "signal", "onProgress", "batchRows", "maxBatchCells", "maxBatchCharacters", "maxChunkBytes", "maxSetupBytes", "maxSetupNodes"]);
|
|
1162
|
+
const signal = captured.signal, onProgress = captured.onProgress;
|
|
1163
|
+
checkAbort(signal);
|
|
1164
|
+
const limits = bounds(captured), input = captureInput(captured.input, limits);
|
|
1165
|
+
if (active.has(endpoint))
|
|
1166
|
+
throw new OfficeIMOError("INVALID_STATE", "A worker endpoint already has an active export.");
|
|
1167
|
+
active.add(endpoint);
|
|
1168
|
+
try {
|
|
1169
|
+
return await withDestination(destination, sink => new Promise((resolve, reject) => {
|
|
1170
|
+
const lifetime = new AbortController();
|
|
1171
|
+
const job = "export-" + ++sequence, iterator = inputRows(rows, lifetime.signal);
|
|
1172
|
+
let settled = false, reading = false, writing = false, exhausted = false, acceptedBytes = 0;
|
|
1173
|
+
let pending;
|
|
1174
|
+
const post = (payload) => endpoint.postMessage({ protocol, job, ...payload });
|
|
1175
|
+
function cleanup() {
|
|
1176
|
+
endpoint.removeEventListener("message", receive);
|
|
1177
|
+
endpoint.removeEventListener("error", broken);
|
|
1178
|
+
endpoint.removeEventListener("messageerror", broken);
|
|
1179
|
+
signal?.removeEventListener("abort", aborted);
|
|
1180
|
+
// A producer's stuck or rejected cleanup must not replace or delay export completion.
|
|
1181
|
+
if (!exhausted)
|
|
1182
|
+
void iterator.return(undefined).catch(() => { });
|
|
1183
|
+
pending = undefined;
|
|
1184
|
+
}
|
|
1185
|
+
function fail(error) {
|
|
1186
|
+
if (settled)
|
|
1187
|
+
return;
|
|
1188
|
+
settled = true;
|
|
1189
|
+
// A terminal worker/transport failure must also release a pending producer
|
|
1190
|
+
// when the caller did not supply or abort its own signal.
|
|
1191
|
+
lifetime.abort(error);
|
|
1192
|
+
try {
|
|
1193
|
+
post({ kind: "cancel", error: wireError(error) });
|
|
1194
|
+
}
|
|
1195
|
+
catch { /* A disconnected worker cannot receive cancellation. */ }
|
|
1196
|
+
cleanup();
|
|
1197
|
+
reject(error);
|
|
1198
|
+
}
|
|
1199
|
+
const aborted = () => { try {
|
|
1200
|
+
checkAbort(signal);
|
|
1201
|
+
}
|
|
1202
|
+
catch (error) {
|
|
1203
|
+
fail(error);
|
|
1204
|
+
} };
|
|
1205
|
+
const broken = event => fail(new Error(event.message || "Worker messaging failed."));
|
|
1206
|
+
async function read(id) {
|
|
1207
|
+
if (reading)
|
|
1208
|
+
throw new OfficeIMOError("INVALID_STATE", "Only one worker row request may be pending.");
|
|
1209
|
+
reading = true;
|
|
1210
|
+
try {
|
|
1211
|
+
const batch = [];
|
|
1212
|
+
let cells = 0, characters = 0;
|
|
1213
|
+
while (batch.length < limits.batchRows && !exhausted) {
|
|
1214
|
+
let next = pending;
|
|
1215
|
+
pending = undefined;
|
|
1216
|
+
if (!next) {
|
|
1217
|
+
const item = await withAbort(iterator.next(), lifetime.signal);
|
|
1218
|
+
if (settled)
|
|
1219
|
+
return;
|
|
1220
|
+
if (item.done) {
|
|
1221
|
+
exhausted = true;
|
|
1222
|
+
break;
|
|
1223
|
+
}
|
|
1224
|
+
if (!Array.isArray(item.value) || item.value.length > limits.maxBatchCells)
|
|
1225
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "A worker row exceeds its message cell budget.");
|
|
1226
|
+
next = captureRow(item.value);
|
|
1227
|
+
}
|
|
1228
|
+
if (next.cells.length > limits.maxBatchCells || next.characters > limits.maxBatchCharacters)
|
|
1229
|
+
throw new OfficeIMOError("RESOURCE_LIMIT", "A worker row exceeds its message budget.");
|
|
1230
|
+
if (batch.length && (cells + next.cells.length > limits.maxBatchCells || characters + next.characters > limits.maxBatchCharacters)) {
|
|
1231
|
+
pending = next;
|
|
1232
|
+
break;
|
|
1233
|
+
}
|
|
1234
|
+
batch.push(next.cells);
|
|
1235
|
+
cells += next.cells.length;
|
|
1236
|
+
characters += next.characters;
|
|
1237
|
+
}
|
|
1238
|
+
if (!settled)
|
|
1239
|
+
post({ kind: "rows", id, rows: batch, done: exhausted });
|
|
1240
|
+
}
|
|
1241
|
+
finally {
|
|
1242
|
+
reading = false;
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
async function write(data) {
|
|
1246
|
+
if (writing || !(data.bytes instanceof Uint8Array) || data.bytes.length > limits.maxChunkBytes)
|
|
1247
|
+
throw new OfficeIMOError("INVALID_STATE", "Invalid or overlapping worker output chunk.");
|
|
1248
|
+
writing = true;
|
|
1249
|
+
try {
|
|
1250
|
+
await withAbort(Promise.resolve(sink.write(data.bytes)), lifetime.signal);
|
|
1251
|
+
if (!settled) {
|
|
1252
|
+
acceptedBytes += data.bytes.length;
|
|
1253
|
+
post({ kind: "ack", id: data.id });
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
finally {
|
|
1257
|
+
writing = false;
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
const receive = event => {
|
|
1261
|
+
const data = message(event.data);
|
|
1262
|
+
if (settled || !data || data.job !== job)
|
|
1263
|
+
return;
|
|
1264
|
+
try {
|
|
1265
|
+
if (data.kind === "complete") {
|
|
1266
|
+
const completed = result(data.result);
|
|
1267
|
+
if (writing || reading || completed.bytes !== acceptedBytes)
|
|
1268
|
+
throw new OfficeIMOError("INVALID_STATE", "Worker completion does not match acknowledged output.");
|
|
1269
|
+
settled = true;
|
|
1270
|
+
cleanup();
|
|
1271
|
+
resolve(completed);
|
|
1272
|
+
}
|
|
1273
|
+
else if (data.kind === "failed")
|
|
1274
|
+
fail(restoreError(data.error));
|
|
1275
|
+
else {
|
|
1276
|
+
if (!Number.isSafeInteger(data.id) || data.id < 1)
|
|
1277
|
+
throw new TypeError("Invalid worker request identifier.");
|
|
1278
|
+
if (data.kind === "requestRows")
|
|
1279
|
+
void read(data.id).catch(fail);
|
|
1280
|
+
else if (data.kind === "output")
|
|
1281
|
+
void write(data).catch(fail);
|
|
1282
|
+
else if (data.kind === "progress") {
|
|
1283
|
+
if (!data.progress)
|
|
1284
|
+
throw new TypeError("Invalid worker progress.");
|
|
1285
|
+
notifyProgress(onProgress, captureProgress(data.progress, limits));
|
|
1286
|
+
post({ kind: "ack", id: data.id });
|
|
1287
|
+
}
|
|
1288
|
+
else
|
|
1289
|
+
throw new TypeError("Unexpected worker export message.");
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
catch (error) {
|
|
1293
|
+
fail(error);
|
|
1294
|
+
}
|
|
1295
|
+
};
|
|
1296
|
+
endpoint.addEventListener("message", receive);
|
|
1297
|
+
endpoint.addEventListener("error", broken);
|
|
1298
|
+
endpoint.addEventListener("messageerror", broken);
|
|
1299
|
+
signal?.addEventListener("abort", aborted, { once: true });
|
|
1300
|
+
try {
|
|
1301
|
+
endpoint.start?.();
|
|
1302
|
+
checkAbort(signal);
|
|
1303
|
+
post({ kind: "start", input, bounds: limits });
|
|
1304
|
+
}
|
|
1305
|
+
catch (error) {
|
|
1306
|
+
fail(error);
|
|
1307
|
+
}
|
|
1308
|
+
}));
|
|
1309
|
+
}
|
|
1310
|
+
finally {
|
|
1311
|
+
active.delete(endpoint);
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
const _exports = Object.freeze({ executeWorkerExport: executeWorkerExport });
|
|
1315
|
+
return _exports;
|
|
1316
|
+
})();
|
|
1317
|
+
|
|
1318
|
+
const _m17 = (() => {
|
|
1319
|
+
const { checkAbort, withAbort } = _m2;
|
|
1320
|
+
|
|
1321
|
+
const { OfficeIMOError } = _m4;
|
|
1322
|
+
|
|
1323
|
+
const { bounds, captureInput, captureProgress, message, protocol, restoreError, restoreRows, result, wireError } = _m6;
|
|
1324
|
+
|
|
1325
|
+
const installed = new WeakSet();
|
|
1326
|
+
/** Install reusable transport on a host-created worker. The operation owns format selection and ordinary writer options. */
|
|
1327
|
+
function handleWorkerExports(endpoint, operation) {
|
|
1328
|
+
if (installed.has(endpoint))
|
|
1329
|
+
throw new OfficeIMOError("INVALID_STATE", "A worker export handler is already installed.");
|
|
1330
|
+
if (typeof operation !== "function")
|
|
1331
|
+
throw new TypeError("A worker export operation is required.");
|
|
1332
|
+
installed.add(endpoint);
|
|
1333
|
+
let current;
|
|
1334
|
+
let disposed = false;
|
|
1335
|
+
const post = (job, payload) => endpoint.postMessage({ protocol, job, ...payload });
|
|
1336
|
+
async function run(start) {
|
|
1337
|
+
const controller = new AbortController(), limits = bounds(start.bounds ?? {}), input = captureInput(start.input, limits);
|
|
1338
|
+
const pending = new Map();
|
|
1339
|
+
let sequence = 0, writing = false, claimed = false, latest, progress;
|
|
1340
|
+
const cancel = () => { for (const entry of pending.values())
|
|
1341
|
+
entry.reject(controller.signal.reason); pending.clear(); latest = undefined; };
|
|
1342
|
+
controller.signal.addEventListener("abort", cancel, { once: true });
|
|
1343
|
+
current = { job: start.job, controller, deliver(data) {
|
|
1344
|
+
const entry = pending.get(data.id);
|
|
1345
|
+
if (!entry)
|
|
1346
|
+
return;
|
|
1347
|
+
pending.delete(data.id);
|
|
1348
|
+
entry.resolve(data);
|
|
1349
|
+
} };
|
|
1350
|
+
const ask = (kind, payload = {}) => {
|
|
1351
|
+
checkAbort(controller.signal);
|
|
1352
|
+
return new Promise((resolve, reject) => {
|
|
1353
|
+
const id = ++sequence;
|
|
1354
|
+
pending.set(id, { resolve, reject });
|
|
1355
|
+
try {
|
|
1356
|
+
post(start.job, { kind, id, ...payload });
|
|
1357
|
+
}
|
|
1358
|
+
catch (error) {
|
|
1359
|
+
pending.delete(id);
|
|
1360
|
+
reject(error);
|
|
1361
|
+
}
|
|
1362
|
+
});
|
|
1363
|
+
};
|
|
1364
|
+
function onProgress(value) {
|
|
1365
|
+
checkAbort(controller.signal);
|
|
1366
|
+
latest = captureProgress(value, limits);
|
|
1367
|
+
if (!progress) {
|
|
1368
|
+
progress = (async () => {
|
|
1369
|
+
while (latest) {
|
|
1370
|
+
const next = latest;
|
|
1371
|
+
latest = undefined;
|
|
1372
|
+
await ask("progress", { progress: next });
|
|
1373
|
+
}
|
|
1374
|
+
})().finally(() => { progress = undefined; });
|
|
1375
|
+
void progress.catch(error => controller.abort(error));
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
const rows = { [Symbol.asyncIterator]() {
|
|
1379
|
+
if (claimed)
|
|
1380
|
+
throw new TypeError("Worker rows can be consumed only once.");
|
|
1381
|
+
claimed = true;
|
|
1382
|
+
return (async function* () {
|
|
1383
|
+
while (true) {
|
|
1384
|
+
const batch = await ask("requestRows");
|
|
1385
|
+
if (batch.kind !== "rows" || typeof batch.done !== "boolean")
|
|
1386
|
+
throw new TypeError("Invalid worker row response.");
|
|
1387
|
+
for (const row of restoreRows(batch.rows, limits)) {
|
|
1388
|
+
checkAbort(controller.signal);
|
|
1389
|
+
yield row;
|
|
1390
|
+
}
|
|
1391
|
+
if (batch.done)
|
|
1392
|
+
return;
|
|
1393
|
+
}
|
|
1394
|
+
})();
|
|
1395
|
+
} };
|
|
1396
|
+
const sink = { async write(bytes) {
|
|
1397
|
+
checkAbort(controller.signal);
|
|
1398
|
+
if (writing || !(bytes instanceof Uint8Array))
|
|
1399
|
+
throw new OfficeIMOError("INVALID_STATE", "Await each worker output write.");
|
|
1400
|
+
writing = true;
|
|
1401
|
+
try {
|
|
1402
|
+
for (let offset = 0; offset < bytes.length; offset += limits.maxChunkBytes)
|
|
1403
|
+
// Structured clone copies a view's entire backing buffer. Own exactly
|
|
1404
|
+
// this chunk so a large producer write cannot multiply clone memory.
|
|
1405
|
+
await ask("output", { bytes: new Uint8Array(bytes.subarray(offset, Math.min(bytes.length, offset + limits.maxChunkBytes))) });
|
|
1406
|
+
}
|
|
1407
|
+
finally {
|
|
1408
|
+
writing = false;
|
|
1409
|
+
}
|
|
1410
|
+
} };
|
|
1411
|
+
try {
|
|
1412
|
+
const completed = result(await withAbort(operation({ input, rows, sink, signal: controller.signal, onProgress }), controller.signal));
|
|
1413
|
+
if (progress)
|
|
1414
|
+
await withAbort(progress, controller.signal);
|
|
1415
|
+
if (pending.size)
|
|
1416
|
+
throw new OfficeIMOError("INVALID_STATE", "Await worker row and output operations before completing.");
|
|
1417
|
+
post(start.job, { kind: "complete", result: completed });
|
|
1418
|
+
}
|
|
1419
|
+
catch (error) {
|
|
1420
|
+
controller.abort(error);
|
|
1421
|
+
try {
|
|
1422
|
+
post(start.job, { kind: "failed", error: wireError(error) });
|
|
1423
|
+
}
|
|
1424
|
+
catch { /* A closed endpoint cannot receive a terminal message. */ }
|
|
1425
|
+
}
|
|
1426
|
+
finally {
|
|
1427
|
+
controller.signal.removeEventListener("abort", cancel);
|
|
1428
|
+
cancel();
|
|
1429
|
+
current = undefined;
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
const receive = event => {
|
|
1433
|
+
const data = message(event.data);
|
|
1434
|
+
if (!data || disposed)
|
|
1435
|
+
return;
|
|
1436
|
+
if (data.kind === "start") {
|
|
1437
|
+
if (current) {
|
|
1438
|
+
post(data.job, { kind: "failed", error: wireError(new OfficeIMOError("INVALID_STATE", "The worker already has an active export.")) });
|
|
1439
|
+
return;
|
|
1440
|
+
}
|
|
1441
|
+
void run(data).catch(error => { try {
|
|
1442
|
+
post(data.job, { kind: "failed", error: wireError(error) });
|
|
1443
|
+
}
|
|
1444
|
+
catch { /* Disconnected endpoint. */ } });
|
|
1445
|
+
}
|
|
1446
|
+
else if (data.job === current?.job) {
|
|
1447
|
+
if (data.kind === "cancel")
|
|
1448
|
+
current.controller.abort(restoreError(data.error));
|
|
1449
|
+
else
|
|
1450
|
+
current.deliver(data);
|
|
1451
|
+
}
|
|
1452
|
+
};
|
|
1453
|
+
const broken = event => current?.controller.abort(new Error(event.message || "Worker messaging failed."));
|
|
1454
|
+
endpoint.addEventListener("message", receive);
|
|
1455
|
+
endpoint.addEventListener("error", broken);
|
|
1456
|
+
endpoint.addEventListener("messageerror", broken);
|
|
1457
|
+
endpoint.start?.();
|
|
1458
|
+
return { dispose(reason = new DOMException("Worker export handler disposed.", "AbortError")) {
|
|
1459
|
+
if (disposed)
|
|
1460
|
+
return;
|
|
1461
|
+
disposed = true;
|
|
1462
|
+
current?.controller.abort(reason);
|
|
1463
|
+
endpoint.removeEventListener("message", receive);
|
|
1464
|
+
endpoint.removeEventListener("error", broken);
|
|
1465
|
+
endpoint.removeEventListener("messageerror", broken);
|
|
1466
|
+
installed.delete(endpoint);
|
|
1467
|
+
} };
|
|
1468
|
+
}
|
|
1469
|
+
const _exports = Object.freeze({ handleWorkerExports: handleWorkerExports });
|
|
1470
|
+
return _exports;
|
|
1471
|
+
})();
|
|
1472
|
+
|
|
1473
|
+
const _m0 = (() => {
|
|
1474
|
+
|
|
1475
|
+
const _exports = Object.freeze({ executeWorkerExport: _m1.executeWorkerExport, handleWorkerExports: _m17.handleWorkerExports });
|
|
1476
|
+
return _exports;
|
|
1477
|
+
})();
|
|
1478
|
+
const { executeWorkerExport, handleWorkerExports } = _m0;
|
|
1479
|
+
export { executeWorkerExport, handleWorkerExports };
|