@beyondwork/xlsx-substrate-bindings 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.md +31 -0
- package/dist/ai/index.d.ts +2 -0
- package/dist/ai/index.js +1 -0
- package/dist/ai/types.d.ts +320 -0
- package/dist/ai/types.js +23 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +72 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.js +1 -0
- package/dist/runtime/types.d.ts +1379 -0
- package/dist/runtime/types.js +15 -0
- package/dist/shared.d.ts +69 -0
- package/dist/shared.js +1 -0
- package/dist/ui/index.d.ts +2 -0
- package/dist/ui/index.js +1 -0
- package/dist/ui/types.d.ts +765 -0
- package/dist/ui/types.js +12 -0
- package/dist/wasm/bridge-contract.d.ts +541 -0
- package/dist/wasm/bridge-contract.js +862 -0
- package/dist/wasm/chart-test-fixture.d.ts +19 -0
- package/dist/wasm/chart-test-fixture.js +42 -0
- package/dist/wasm/index.d.ts +9 -0
- package/dist/wasm/index.js +67 -0
- package/dist/wasm/media-test-fixture.d.ts +44 -0
- package/dist/wasm/media-test-fixture.js +160 -0
- package/dist/wasm/session-router.d.ts +98 -0
- package/dist/wasm/session-router.js +184 -0
- package/dist/wasm/sheet-window-binary-reference.d.ts +9 -0
- package/dist/wasm/sheet-window-binary-reference.js +308 -0
- package/dist/wasm/sheet-window-binary.d.ts +279 -0
- package/dist/wasm/sheet-window-binary.js +636 -0
- package/dist/wasm/volatile-test-fixture.d.ts +7 -0
- package/dist/wasm/volatile-test-fixture.js +35 -0
- package/dist/wasm/web.d.ts +59 -0
- package/dist/wasm/web.js +60 -0
- package/generated/wasm/package.json +3 -0
- package/generated/wasm/sheet-window-binary.mjs +482 -0
- package/generated/wasm/snippets/ironcalc_base-89b4f49381e1e289/inline0.js +45 -0
- package/generated/wasm/xlsx_substrate_wasm.d.ts +336 -0
- package/generated/wasm/xlsx_substrate_wasm.js +2108 -0
- package/generated/wasm/xlsx_substrate_wasm_bg.wasm +0 -0
- package/generated/wasm/xlsx_substrate_wasm_bg.wasm.d.ts +105 -0
- package/generated/wasm-web/package.json +3 -0
- package/generated/wasm-web/snippets/ironcalc_base-89b4f49381e1e289/inline0.js +42 -0
- package/generated/wasm-web/xlsx_substrate_wasm.d.ts +466 -0
- package/generated/wasm-web/xlsx_substrate_wasm.js +2109 -0
- package/generated/wasm-web/xlsx_substrate_wasm_bg.wasm +0 -0
- package/generated/wasm-web/xlsx_substrate_wasm_bg.wasm.d.ts +105 -0
- package/package.json +41 -3
- package/README.md +0 -3
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type RawXlsxWasmModule, type XlsxWasmBridgeLoadResult } from "./bridge-contract.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Accepted wasm sources for the web glue's init entry point
|
|
4
|
+
* (wasm-bindgen `--target web`): URL/string/Request/Response stream through
|
|
5
|
+
* `WebAssembly.instantiateStreaming` (with the glue's built-in MIME-type
|
|
6
|
+
* fallback); BufferSource/Module instantiate directly.
|
|
7
|
+
*/
|
|
8
|
+
export type XlsxWasmWebInitSource = URL | string | Request | Response | BufferSource | WebAssembly.Module;
|
|
9
|
+
/**
|
|
10
|
+
* Shape of the `--target web` glue module namespace: the same raw bridge
|
|
11
|
+
* exports as the nodejs artifact plus the wasm-bindgen web-target init
|
|
12
|
+
* entry points (`default` async init and `initSync`).
|
|
13
|
+
*/
|
|
14
|
+
export interface RawXlsxWasmWebModule extends RawXlsxWasmModule {
|
|
15
|
+
readonly default: (init?: {
|
|
16
|
+
module_or_path?: XlsxWasmWebInitSource;
|
|
17
|
+
}) => Promise<unknown>;
|
|
18
|
+
readonly initSync?: (init: {
|
|
19
|
+
module: BufferSource | WebAssembly.Module;
|
|
20
|
+
}) => unknown;
|
|
21
|
+
}
|
|
22
|
+
export interface XlsxWasmWebLoadRequest {
|
|
23
|
+
/**
|
|
24
|
+
* The imported `generated/wasm-web/xlsx_substrate_wasm.js` module
|
|
25
|
+
* namespace. The host adapter performs the ESM import (statically from
|
|
26
|
+
* its own bundle or via a same-origin dynamic import it owns) — the
|
|
27
|
+
* bindings package never resolves artifact URLs itself.
|
|
28
|
+
*/
|
|
29
|
+
readonly glueModule: RawXlsxWasmWebModule;
|
|
30
|
+
/**
|
|
31
|
+
* Explicit wasm source. Always pass one — never rely on the glue's
|
|
32
|
+
* `import.meta.url`-relative default, which would encode a fetch the
|
|
33
|
+
* host did not choose.
|
|
34
|
+
*/
|
|
35
|
+
readonly wasmSource: XlsxWasmWebInitSource;
|
|
36
|
+
/**
|
|
37
|
+
* Browser analogue of `XLSX_WASM_REQUIRED=1` (browsers have no
|
|
38
|
+
* `process.env`): when true, every not-mounted outcome throws instead of
|
|
39
|
+
* returning a soft result. Defaults to false.
|
|
40
|
+
*/
|
|
41
|
+
readonly required?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Instantiate and mount the XLSX wasm bridge from the web-target artifact.
|
|
45
|
+
*
|
|
46
|
+
* Feature-detects WebAssembly, runs the glue's async init against the
|
|
47
|
+
* host-supplied source, then applies the exact same mount gate as the
|
|
48
|
+
* Node.js loader (`validateRawXlsxWasmModule`) and wraps the raw module
|
|
49
|
+
* with the shared `createXlsxWasmBridge` — the returned `XlsxWasmBridge`
|
|
50
|
+
* surface is identical across both artifacts.
|
|
51
|
+
*
|
|
52
|
+
* Init is once-per-document: the wasm-bindgen web glue holds module-level
|
|
53
|
+
* instance state, so repeated calls reuse the already-initialized module
|
|
54
|
+
* (subsequent `wasmSource` values are ignored by the glue). EP3-2 note:
|
|
55
|
+
* Conductor's `/api` responses are no-store; the wasm asset must be served
|
|
56
|
+
* from a cacheable route (or preloaded by the host) before the mirror
|
|
57
|
+
* session ships, or every boot re-downloads the multi-megabyte module.
|
|
58
|
+
*/
|
|
59
|
+
export declare function loadXlsxWasmBridgeWeb(request: XlsxWasmWebLoadRequest): Promise<XlsxWasmBridgeLoadResult>;
|
package/dist/wasm/web.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Browser loader for the `--target web` ESM wasm artifact in
|
|
2
|
+
// `generated/wasm-web/` (EP3-1). Browser-safe by construction: zero `node:`
|
|
3
|
+
// imports and zero static references to the gitignored generated artifacts.
|
|
4
|
+
// Per `docs/architecture/xlsx/00-overview.md` §Implementation Split, the
|
|
5
|
+
// HOST adapter owns bytes and asset URLs: it performs the ESM import of the
|
|
6
|
+
// glue module and supplies an explicit wasm source (same-origin URL,
|
|
7
|
+
// Response, or preloaded bytes). This keeps the bindings package free of
|
|
8
|
+
// dynamic remote imports — self-contained for Beyond Work iframe
|
|
9
|
+
// deployments where the wasm bytes are host-supplied, never CDN-fetched.
|
|
10
|
+
import { createXlsxWasmBridge, validateRawXlsxWasmModule } from "./bridge-contract.js";
|
|
11
|
+
/**
|
|
12
|
+
* Instantiate and mount the XLSX wasm bridge from the web-target artifact.
|
|
13
|
+
*
|
|
14
|
+
* Feature-detects WebAssembly, runs the glue's async init against the
|
|
15
|
+
* host-supplied source, then applies the exact same mount gate as the
|
|
16
|
+
* Node.js loader (`validateRawXlsxWasmModule`) and wraps the raw module
|
|
17
|
+
* with the shared `createXlsxWasmBridge` — the returned `XlsxWasmBridge`
|
|
18
|
+
* surface is identical across both artifacts.
|
|
19
|
+
*
|
|
20
|
+
* Init is once-per-document: the wasm-bindgen web glue holds module-level
|
|
21
|
+
* instance state, so repeated calls reuse the already-initialized module
|
|
22
|
+
* (subsequent `wasmSource` values are ignored by the glue). EP3-2 note:
|
|
23
|
+
* Conductor's `/api` responses are no-store; the wasm asset must be served
|
|
24
|
+
* from a cacheable route (or preloaded by the host) before the mirror
|
|
25
|
+
* session ships, or every boot re-downloads the multi-megabyte module.
|
|
26
|
+
*/
|
|
27
|
+
export async function loadXlsxWasmBridgeWeb(request) {
|
|
28
|
+
const required = request.required === true;
|
|
29
|
+
const notMounted = (reason) => {
|
|
30
|
+
if (required) {
|
|
31
|
+
throw new Error(reason);
|
|
32
|
+
}
|
|
33
|
+
return { wasmBinding: "not-mounted", reason };
|
|
34
|
+
};
|
|
35
|
+
if (typeof WebAssembly !== "object" ||
|
|
36
|
+
WebAssembly === null ||
|
|
37
|
+
typeof WebAssembly.instantiate !== "function") {
|
|
38
|
+
return notMounted("WebAssembly is unavailable in this environment");
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
await request.glueModule.default({ module_or_path: request.wasmSource });
|
|
42
|
+
const validation = validateRawXlsxWasmModule(request.glueModule);
|
|
43
|
+
if (!validation.ok) {
|
|
44
|
+
return notMounted(validation.reason);
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
wasmBinding: "mounted",
|
|
48
|
+
bridge: createXlsxWasmBridge(request.glueModule, validation.status)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (required) {
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
wasmBinding: "not-mounted",
|
|
57
|
+
reason: error instanceof Error ? error.message : String(error)
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
// GENERATED by scripts/build-wasm.mjs from src/wasm/sheet-window-binary.ts — do not edit.
|
|
2
|
+
export const SHEET_WINDOW_BINARY_SCHEMA_ID = "xlsx-sheet-window-binary/1";
|
|
3
|
+
export const SHEET_WINDOW_BINARY_MAGIC = 0x31575358;
|
|
4
|
+
export const SHEET_WINDOW_BINARY_VERSION = 1;
|
|
5
|
+
export const SHEET_WINDOW_BINARY_HEADER_BYTES = 32;
|
|
6
|
+
export const SHEET_WINDOW_BINARY_SECTION_ENTRY_BYTES = 16;
|
|
7
|
+
export const SHEET_WINDOW_SECTION_ROWS = 1;
|
|
8
|
+
export const SHEET_WINDOW_SECTION_COLS = 2;
|
|
9
|
+
export const SHEET_WINDOW_SECTION_CELLS = 3;
|
|
10
|
+
export const SHEET_WINDOW_SECTION_PAINT_ROWS = 4;
|
|
11
|
+
export const SHEET_WINDOW_SECTION_PAINT_COLS = 5;
|
|
12
|
+
export const SHEET_WINDOW_SECTION_RECTS = 6;
|
|
13
|
+
export const SHEET_WINDOW_SECTION_PAINT_CELLS = 7;
|
|
14
|
+
export const SHEET_WINDOW_SECTION_STRTAB = 8;
|
|
15
|
+
export const SHEET_WINDOW_SECTION_STRBLOB = 9;
|
|
16
|
+
export const SHEET_WINDOW_LINE_RECORD_BYTES = 24;
|
|
17
|
+
export const SHEET_WINDOW_CELL_RECORD_BYTES = 96;
|
|
18
|
+
export const SHEET_WINDOW_PAINT_LINE_RECORD_BYTES = 32;
|
|
19
|
+
export const SHEET_WINDOW_RECT_RECORD_BYTES = 48;
|
|
20
|
+
export const SHEET_WINDOW_PAINT_CELL_RECORD_BYTES = 32;
|
|
21
|
+
export const SHEET_WINDOW_STRTAB_ENTRY_BYTES = 8;
|
|
22
|
+
export const SHEET_WINDOW_U32_NONE = 0xffffffff;
|
|
23
|
+
export const SHEET_WINDOW_OUTLINE_NONE = 0xff;
|
|
24
|
+
export const SHEET_WINDOW_MARKER_SEPARATOR = "\u001f";
|
|
25
|
+
export const SHEET_WINDOW_FLAG_PAINT_GEOMETRY = 0x0001;
|
|
26
|
+
const utf8Decoder = new TextDecoder("utf-8", {
|
|
27
|
+
fatal: true
|
|
28
|
+
});
|
|
29
|
+
class SheetWindowStringTable {
|
|
30
|
+
view;
|
|
31
|
+
bytes;
|
|
32
|
+
strtab;
|
|
33
|
+
blob;
|
|
34
|
+
cache;
|
|
35
|
+
markerCache = new Map();
|
|
36
|
+
constructor(view, bytes, strtab, blob){
|
|
37
|
+
this.view = view;
|
|
38
|
+
this.bytes = bytes;
|
|
39
|
+
this.strtab = strtab;
|
|
40
|
+
this.blob = blob;
|
|
41
|
+
this.cache = new Array(strtab.recordCount);
|
|
42
|
+
}
|
|
43
|
+
at(id) {
|
|
44
|
+
if (id === 0) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
if (id >= this.strtab.recordCount) {
|
|
48
|
+
throw new Error(`sheet-window binary: string id ${id} out of range (${this.strtab.recordCount})`);
|
|
49
|
+
}
|
|
50
|
+
const cached = this.cache[id];
|
|
51
|
+
if (cached !== undefined) {
|
|
52
|
+
return cached;
|
|
53
|
+
}
|
|
54
|
+
const entryOffset = this.strtab.byteOffset + id * SHEET_WINDOW_STRTAB_ENTRY_BYTES;
|
|
55
|
+
const blobOffset = this.view.getUint32(entryOffset, true);
|
|
56
|
+
const byteLen = this.view.getUint32(entryOffset + 4, true);
|
|
57
|
+
if (blobOffset + byteLen > this.blob.byteLen) {
|
|
58
|
+
throw new Error(`sheet-window binary: string id ${id} escapes the blob section`);
|
|
59
|
+
}
|
|
60
|
+
const start = this.blob.byteOffset + blobOffset;
|
|
61
|
+
const decoded = utf8Decoder.decode(this.bytes.subarray(start, start + byteLen));
|
|
62
|
+
this.cache[id] = decoded;
|
|
63
|
+
return decoded;
|
|
64
|
+
}
|
|
65
|
+
required(id, field) {
|
|
66
|
+
const value = this.at(id);
|
|
67
|
+
if (value === undefined) {
|
|
68
|
+
throw new Error(`sheet-window binary: required string field ${field} was absent (id 0)`);
|
|
69
|
+
}
|
|
70
|
+
return value;
|
|
71
|
+
}
|
|
72
|
+
markers(id) {
|
|
73
|
+
if (id === 0) {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
const cached = this.markerCache.get(id);
|
|
77
|
+
if (cached !== undefined) {
|
|
78
|
+
return cached;
|
|
79
|
+
}
|
|
80
|
+
const joined = this.required(id, "postureMarkers");
|
|
81
|
+
const split = Object.freeze(joined.split(SHEET_WINDOW_MARKER_SEPARATOR));
|
|
82
|
+
this.markerCache.set(id, split);
|
|
83
|
+
return split;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function defineLazy(target, key, compute, recover) {
|
|
87
|
+
Object.defineProperty(target, key, {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
configurable: true,
|
|
90
|
+
get () {
|
|
91
|
+
let value;
|
|
92
|
+
try {
|
|
93
|
+
value = compute();
|
|
94
|
+
} catch (error) {
|
|
95
|
+
const recovered = recover?.(error);
|
|
96
|
+
if (recovered === undefined) {
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
value = recovered.value;
|
|
100
|
+
}
|
|
101
|
+
Object.defineProperty(target, key, {
|
|
102
|
+
enumerable: true,
|
|
103
|
+
configurable: true,
|
|
104
|
+
writable: false,
|
|
105
|
+
value
|
|
106
|
+
});
|
|
107
|
+
return value;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
const SHEET_WINDOW_VERTICAL_ALIGNMENTS = [
|
|
112
|
+
undefined,
|
|
113
|
+
"top",
|
|
114
|
+
"middle",
|
|
115
|
+
"bottom"
|
|
116
|
+
];
|
|
117
|
+
const CellStr = {
|
|
118
|
+
CellId: 0,
|
|
119
|
+
DisplayText: 1,
|
|
120
|
+
ValueKind: 2,
|
|
121
|
+
FormulaText: 3,
|
|
122
|
+
DisplayFingerprint: 4,
|
|
123
|
+
StyleRef: 5,
|
|
124
|
+
DisplayFormatPosture: 6,
|
|
125
|
+
FormatCode: 7,
|
|
126
|
+
FillColor: 8,
|
|
127
|
+
FontColor: 9,
|
|
128
|
+
FontName: 10,
|
|
129
|
+
FontSizePoints: 11,
|
|
130
|
+
DisplayTextColor: 12,
|
|
131
|
+
HorizontalAlignment: 13,
|
|
132
|
+
MergeRole: 14,
|
|
133
|
+
Editability: 15
|
|
134
|
+
};
|
|
135
|
+
function requireSection(ctx, id, label) {
|
|
136
|
+
const section = ctx.sections.get(id);
|
|
137
|
+
if (!section) {
|
|
138
|
+
throw new Error(`sheet-window binary: missing required section ${label} (${id})`);
|
|
139
|
+
}
|
|
140
|
+
return section;
|
|
141
|
+
}
|
|
142
|
+
function assertStride(section, expected, label) {
|
|
143
|
+
if (section.recordCount === 0) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (section.recordCount * expected !== section.byteLen) {
|
|
147
|
+
throw new Error(`sheet-window binary: section ${label} stride mismatch — ${section.byteLen} bytes for ${section.recordCount} records (expected ${expected} B/record)`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function decodeLineSection(ctx, sectionId, kind) {
|
|
151
|
+
const label = kind === "row" ? "ROWS" : "COLS";
|
|
152
|
+
const section = requireSection(ctx, sectionId, label);
|
|
153
|
+
assertStride(section, SHEET_WINDOW_LINE_RECORD_BYTES, label);
|
|
154
|
+
const { view, strings } = ctx;
|
|
155
|
+
const out = new Array(section.recordCount);
|
|
156
|
+
for(let i = 0; i < section.recordCount; i++){
|
|
157
|
+
const o = section.byteOffset + i * SHEET_WINDOW_LINE_RECORD_BYTES;
|
|
158
|
+
const line = view.getUint32(o, true);
|
|
159
|
+
const metric = strings.required(view.getUint32(o + 4, true), kind === "row" ? "heightPoints" : "width");
|
|
160
|
+
const precision = strings.required(view.getUint32(o + 8, true), "precision");
|
|
161
|
+
const hiddenPosture = strings.at(view.getUint32(o + 12, true));
|
|
162
|
+
const flags = view.getUint8(o + 16);
|
|
163
|
+
const outlineRaw = view.getUint8(o + 17);
|
|
164
|
+
out[i] = kind === "row" ? {
|
|
165
|
+
row: line,
|
|
166
|
+
heightPoints: metric,
|
|
167
|
+
hidden: (flags & 0x01) !== 0,
|
|
168
|
+
customHeight: (flags & 0x02) !== 0,
|
|
169
|
+
precision,
|
|
170
|
+
outlineLevel: outlineRaw === SHEET_WINDOW_OUTLINE_NONE ? undefined : outlineRaw,
|
|
171
|
+
collapsed: (flags & 0x04) !== 0,
|
|
172
|
+
hiddenPosture
|
|
173
|
+
} : {
|
|
174
|
+
column: line,
|
|
175
|
+
width: metric,
|
|
176
|
+
hidden: (flags & 0x01) !== 0,
|
|
177
|
+
customWidth: (flags & 0x02) !== 0,
|
|
178
|
+
precision,
|
|
179
|
+
outlineLevel: outlineRaw === SHEET_WINDOW_OUTLINE_NONE ? undefined : outlineRaw,
|
|
180
|
+
collapsed: (flags & 0x04) !== 0,
|
|
181
|
+
hiddenPosture
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
return out;
|
|
185
|
+
}
|
|
186
|
+
function decodeCells(ctx) {
|
|
187
|
+
const section = requireSection(ctx, SHEET_WINDOW_SECTION_CELLS, "CELLS");
|
|
188
|
+
assertStride(section, SHEET_WINDOW_CELL_RECORD_BYTES, "CELLS");
|
|
189
|
+
const { view, strings, rest } = ctx;
|
|
190
|
+
const mergedRanges = rest.mergedRanges;
|
|
191
|
+
const rareCells = rest.rareCells ?? [];
|
|
192
|
+
const out = new Array(section.recordCount);
|
|
193
|
+
for(let i = 0; i < section.recordCount; i++){
|
|
194
|
+
const o = section.byteOffset + i * SHEET_WINDOW_CELL_RECORD_BYTES;
|
|
195
|
+
const str = (slot)=>view.getUint32(o + 8 + slot * 4, true);
|
|
196
|
+
const numFmtRaw = view.getUint32(o + 72, true);
|
|
197
|
+
const flags = view.getUint16(o + 76, true);
|
|
198
|
+
const mergedRangeIdx = view.getUint32(o + 80, true);
|
|
199
|
+
const rareIdx = view.getUint32(o + 84, true);
|
|
200
|
+
const markersId = view.getUint32(o + 88, true);
|
|
201
|
+
const rare = rareIdx === SHEET_WINDOW_U32_NONE ? undefined : rareCells[rareIdx];
|
|
202
|
+
if (rareIdx !== SHEET_WINDOW_U32_NONE && rare === undefined) {
|
|
203
|
+
throw new Error(`sheet-window binary: cell ${i} references missing rareCells[${rareIdx}]`);
|
|
204
|
+
}
|
|
205
|
+
const merged = mergedRangeIdx === SHEET_WINDOW_U32_NONE ? undefined : mergedRanges[mergedRangeIdx];
|
|
206
|
+
if (mergedRangeIdx !== SHEET_WINDOW_U32_NONE && merged === undefined) {
|
|
207
|
+
throw new Error(`sheet-window binary: cell ${i} references missing mergedRanges[${mergedRangeIdx}]`);
|
|
208
|
+
}
|
|
209
|
+
const cell = {
|
|
210
|
+
address: {
|
|
211
|
+
row: view.getUint32(o, true),
|
|
212
|
+
column: view.getUint32(o + 4, true)
|
|
213
|
+
},
|
|
214
|
+
cellId: strings.at(str(CellStr.CellId)),
|
|
215
|
+
selectionHandle: rare?.selectionHandle,
|
|
216
|
+
displayText: strings.at(str(CellStr.DisplayText)),
|
|
217
|
+
valueKind: strings.at(str(CellStr.ValueKind)),
|
|
218
|
+
formulaText: strings.at(str(CellStr.FormulaText)),
|
|
219
|
+
displayFingerprint: strings.at(str(CellStr.DisplayFingerprint)),
|
|
220
|
+
styleRef: strings.at(str(CellStr.StyleRef)),
|
|
221
|
+
displayFormatPosture: strings.at(str(CellStr.DisplayFormatPosture)),
|
|
222
|
+
numFmtId: numFmtRaw === SHEET_WINDOW_U32_NONE ? undefined : numFmtRaw,
|
|
223
|
+
formatCode: strings.at(str(CellStr.FormatCode)),
|
|
224
|
+
bold: (flags & 0x0001) !== 0,
|
|
225
|
+
italic: (flags & 0x0002) !== 0,
|
|
226
|
+
underline: (flags & 0x0004) !== 0
|
|
227
|
+
};
|
|
228
|
+
const fillColor = strings.at(str(CellStr.FillColor));
|
|
229
|
+
if (fillColor !== undefined) cell.fillColor = fillColor;
|
|
230
|
+
const fontColor = strings.at(str(CellStr.FontColor));
|
|
231
|
+
if (fontColor !== undefined) cell.fontColor = fontColor;
|
|
232
|
+
const fontName = strings.at(str(CellStr.FontName));
|
|
233
|
+
if (fontName !== undefined) cell.fontName = fontName;
|
|
234
|
+
const fontSizePoints = strings.at(str(CellStr.FontSizePoints));
|
|
235
|
+
if (fontSizePoints !== undefined) cell.fontSizePoints = fontSizePoints;
|
|
236
|
+
const displayTextColor = strings.at(str(CellStr.DisplayTextColor));
|
|
237
|
+
if (displayTextColor !== undefined) cell.displayTextColor = displayTextColor;
|
|
238
|
+
const horizontalAlignment = strings.at(str(CellStr.HorizontalAlignment));
|
|
239
|
+
if (horizontalAlignment !== undefined) cell.horizontalAlignment = horizontalAlignment;
|
|
240
|
+
const verticalAlignment = SHEET_WINDOW_VERTICAL_ALIGNMENTS[flags >> 8 & 0x03];
|
|
241
|
+
if (verticalAlignment !== undefined) cell.verticalAlignment = verticalAlignment;
|
|
242
|
+
if ((flags & 0x0008) !== 0) cell.wrapText = true;
|
|
243
|
+
if ((flags & 0x0010) !== 0) cell.borderTop = true;
|
|
244
|
+
if ((flags & 0x0020) !== 0) cell.borderRight = true;
|
|
245
|
+
if ((flags & 0x0040) !== 0) cell.borderBottom = true;
|
|
246
|
+
if ((flags & 0x0080) !== 0) cell.borderLeft = true;
|
|
247
|
+
cell.mergeRole = strings.required(str(CellStr.MergeRole), "mergeRole");
|
|
248
|
+
cell.mergeOwner = merged ? {
|
|
249
|
+
...merged.owner
|
|
250
|
+
} : undefined;
|
|
251
|
+
cell.mergeRange = merged ? {
|
|
252
|
+
start: {
|
|
253
|
+
...merged.sourceRange.start
|
|
254
|
+
},
|
|
255
|
+
end: {
|
|
256
|
+
...merged.sourceRange.end
|
|
257
|
+
}
|
|
258
|
+
} : undefined;
|
|
259
|
+
cell.editability = strings.required(str(CellStr.Editability), "editability");
|
|
260
|
+
cell.blockers = rare?.blockers ? [
|
|
261
|
+
...rare.blockers
|
|
262
|
+
] : [];
|
|
263
|
+
cell.postureMarkers = rare?.postureMarkers ?? strings.markers(markersId);
|
|
264
|
+
if (rare?.hyperlink !== undefined) cell.hyperlink = rare.hyperlink;
|
|
265
|
+
out[i] = cell;
|
|
266
|
+
}
|
|
267
|
+
return out;
|
|
268
|
+
}
|
|
269
|
+
function decodePaintLines(ctx, sectionId, kind) {
|
|
270
|
+
const label = kind === "row" ? "PAINT_ROWS" : "PAINT_COLS";
|
|
271
|
+
const section = requireSection(ctx, sectionId, label);
|
|
272
|
+
assertStride(section, SHEET_WINDOW_PAINT_LINE_RECORD_BYTES, label);
|
|
273
|
+
const { view, strings } = ctx;
|
|
274
|
+
const out = new Array(section.recordCount);
|
|
275
|
+
for(let i = 0; i < section.recordCount; i++){
|
|
276
|
+
const o = section.byteOffset + i * SHEET_WINDOW_PAINT_LINE_RECORD_BYTES;
|
|
277
|
+
const line = view.getUint32(o, true);
|
|
278
|
+
const precision = strings.required(view.getUint32(o + 4, true), "precision");
|
|
279
|
+
const hidden = (view.getUint8(o + 8) & 0x01) !== 0;
|
|
280
|
+
const offsetPx = view.getFloat64(o + 16, true);
|
|
281
|
+
const sizePx = view.getFloat64(o + 24, true);
|
|
282
|
+
out[i] = kind === "row" ? {
|
|
283
|
+
row: line,
|
|
284
|
+
offsetPx,
|
|
285
|
+
sizePx,
|
|
286
|
+
hidden,
|
|
287
|
+
precision
|
|
288
|
+
} : {
|
|
289
|
+
column: line,
|
|
290
|
+
offsetPx,
|
|
291
|
+
sizePx,
|
|
292
|
+
hidden,
|
|
293
|
+
precision
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
return out;
|
|
297
|
+
}
|
|
298
|
+
function decodeRects(ctx) {
|
|
299
|
+
const section = requireSection(ctx, SHEET_WINDOW_SECTION_RECTS, "RECTS");
|
|
300
|
+
assertStride(section, SHEET_WINDOW_RECT_RECORD_BYTES, "RECTS");
|
|
301
|
+
const { view, strings } = ctx;
|
|
302
|
+
const out = new Array(section.recordCount);
|
|
303
|
+
for(let i = 0; i < section.recordCount; i++){
|
|
304
|
+
const o = section.byteOffset + i * SHEET_WINDOW_RECT_RECORD_BYTES;
|
|
305
|
+
const kind = strings.required(view.getUint32(o + 32, true), "coordinateSpace.kind");
|
|
306
|
+
const region = strings.at(view.getUint32(o + 36, true));
|
|
307
|
+
out[i] = {
|
|
308
|
+
xPx: view.getFloat64(o, true),
|
|
309
|
+
yPx: view.getFloat64(o + 8, true),
|
|
310
|
+
widthPx: view.getFloat64(o + 16, true),
|
|
311
|
+
heightPx: view.getFloat64(o + 24, true),
|
|
312
|
+
coordinateSpace: region === undefined ? {
|
|
313
|
+
kind
|
|
314
|
+
} : {
|
|
315
|
+
kind,
|
|
316
|
+
region
|
|
317
|
+
},
|
|
318
|
+
precision: strings.required(view.getUint32(o + 40, true), "precision")
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
return out;
|
|
322
|
+
}
|
|
323
|
+
function decodePaintCells(ctx, rects) {
|
|
324
|
+
const section = requireSection(ctx, SHEET_WINDOW_SECTION_PAINT_CELLS, "PAINT_CELLS");
|
|
325
|
+
assertStride(section, SHEET_WINDOW_PAINT_CELL_RECORD_BYTES, "PAINT_CELLS");
|
|
326
|
+
const { view, strings } = ctx;
|
|
327
|
+
const out = new Array(section.recordCount);
|
|
328
|
+
for(let i = 0; i < section.recordCount; i++){
|
|
329
|
+
const o = section.byteOffset + i * SHEET_WINDOW_PAINT_CELL_RECORD_BYTES;
|
|
330
|
+
const rectStart = view.getUint32(o + 8, true);
|
|
331
|
+
const rectCount = view.getUint16(o + 12, true);
|
|
332
|
+
if (rectStart + rectCount > rects.length) {
|
|
333
|
+
throw new Error(`sheet-window binary: paint cell ${i} references rects beyond the pool`);
|
|
334
|
+
}
|
|
335
|
+
const ownerRow = view.getUint32(o + 20, true);
|
|
336
|
+
const ownerCol = view.getUint32(o + 24, true);
|
|
337
|
+
out[i] = {
|
|
338
|
+
address: {
|
|
339
|
+
row: view.getUint32(o, true),
|
|
340
|
+
column: view.getUint32(o + 4, true)
|
|
341
|
+
},
|
|
342
|
+
rects: rects.slice(rectStart, rectStart + rectCount),
|
|
343
|
+
hidden: (view.getUint8(o + 14) & 0x01) !== 0,
|
|
344
|
+
precision: strings.required(view.getUint32(o + 16, true), "precision"),
|
|
345
|
+
mergeOwner: ownerRow === SHEET_WINDOW_U32_NONE ? undefined : {
|
|
346
|
+
row: ownerRow,
|
|
347
|
+
column: ownerCol
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
return out;
|
|
352
|
+
}
|
|
353
|
+
export function decodeSheetWindowBinary(env, options) {
|
|
354
|
+
if (env.schemaId !== SHEET_WINDOW_BINARY_SCHEMA_ID) {
|
|
355
|
+
throw new Error(`sheet-window binary: unknown schemaId ${env.schemaId}`);
|
|
356
|
+
}
|
|
357
|
+
let bytes = env.bytes instanceof Uint8Array ? env.bytes : Uint8Array.from(env.bytes);
|
|
358
|
+
const backing = bytes.buffer;
|
|
359
|
+
const plainFixedBacking = backing instanceof ArrayBuffer && backing.resizable !== true;
|
|
360
|
+
if (!plainFixedBacking || bytes.byteOffset !== 0 || bytes.byteLength !== backing.byteLength) {
|
|
361
|
+
bytes = bytes.slice();
|
|
362
|
+
}
|
|
363
|
+
if (bytes.byteLength < SHEET_WINDOW_BINARY_HEADER_BYTES) {
|
|
364
|
+
throw new Error(`sheet-window binary: truncated header (${bytes.byteLength} bytes)`);
|
|
365
|
+
}
|
|
366
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
367
|
+
if (view.getUint32(0, true) !== SHEET_WINDOW_BINARY_MAGIC) {
|
|
368
|
+
throw new Error("sheet-window binary: bad magic (expected XSW1 little-endian)");
|
|
369
|
+
}
|
|
370
|
+
const version = view.getUint16(4, true);
|
|
371
|
+
if (version !== SHEET_WINDOW_BINARY_VERSION) {
|
|
372
|
+
throw new Error(`sheet-window binary: unsupported version ${version}`);
|
|
373
|
+
}
|
|
374
|
+
const flags = view.getUint16(6, true);
|
|
375
|
+
const sectionCount = view.getUint32(8, true);
|
|
376
|
+
const totalByteLen = view.getUint32(12, true);
|
|
377
|
+
if (totalByteLen > bytes.byteLength) {
|
|
378
|
+
throw new Error(`sheet-window binary: totalByteLen ${totalByteLen} exceeds buffer ${bytes.byteLength}`);
|
|
379
|
+
}
|
|
380
|
+
const tableEnd = SHEET_WINDOW_BINARY_HEADER_BYTES + sectionCount * SHEET_WINDOW_BINARY_SECTION_ENTRY_BYTES;
|
|
381
|
+
if (tableEnd > totalByteLen) {
|
|
382
|
+
throw new Error("sheet-window binary: section table escapes the buffer");
|
|
383
|
+
}
|
|
384
|
+
const sections = new Map();
|
|
385
|
+
for(let i = 0; i < sectionCount; i++){
|
|
386
|
+
const o = SHEET_WINDOW_BINARY_HEADER_BYTES + i * SHEET_WINDOW_BINARY_SECTION_ENTRY_BYTES;
|
|
387
|
+
const sectionId = view.getUint32(o, true);
|
|
388
|
+
const byteOffset = view.getUint32(o + 4, true);
|
|
389
|
+
const byteLen = view.getUint32(o + 8, true);
|
|
390
|
+
if (byteOffset + byteLen > totalByteLen) {
|
|
391
|
+
throw new Error(`sheet-window binary: section ${sectionId} escapes the buffer`);
|
|
392
|
+
}
|
|
393
|
+
sections.set(sectionId, {
|
|
394
|
+
byteOffset,
|
|
395
|
+
byteLen,
|
|
396
|
+
recordCount: view.getUint32(o + 12, true)
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
const strtab = sections.get(SHEET_WINDOW_SECTION_STRTAB);
|
|
400
|
+
const blob = sections.get(SHEET_WINDOW_SECTION_STRBLOB);
|
|
401
|
+
if (!strtab || !blob) {
|
|
402
|
+
throw new Error("sheet-window binary: missing required string sections (STRTAB/STRBLOB)");
|
|
403
|
+
}
|
|
404
|
+
assertStride(strtab, SHEET_WINDOW_STRTAB_ENTRY_BYTES, "STRTAB");
|
|
405
|
+
const strings = new SheetWindowStringTable(view, bytes, strtab, blob);
|
|
406
|
+
const rest = env.rest;
|
|
407
|
+
const ctx = {
|
|
408
|
+
view,
|
|
409
|
+
strings,
|
|
410
|
+
sections,
|
|
411
|
+
rest
|
|
412
|
+
};
|
|
413
|
+
const paintGeometryPresent = (flags & SHEET_WINDOW_FLAG_PAINT_GEOMETRY) !== 0;
|
|
414
|
+
const { rareCells: _rareCells, paintGeometryPresent: _pgPresent, paintGeometryActiveSelection, paintGeometryObjects, paintGeometrySparklines, paintGeometry: nestedPaintGeometry, encodeMs: _encodeMs, ...readbackRest } = rest;
|
|
415
|
+
const onSectionDecodeError = options?.onSectionDecodeError;
|
|
416
|
+
const recoverSection = onSectionDecodeError ? (key)=>(error)=>{
|
|
417
|
+
const substitute = onSectionDecodeError(error);
|
|
418
|
+
return substitute === undefined ? undefined : {
|
|
419
|
+
value: substitute[key]
|
|
420
|
+
};
|
|
421
|
+
} : undefined;
|
|
422
|
+
const out = {
|
|
423
|
+
...readbackRest
|
|
424
|
+
};
|
|
425
|
+
const defineLazySection = (key, compute)=>{
|
|
426
|
+
defineLazy(out, key, compute, recoverSection?.(key));
|
|
427
|
+
};
|
|
428
|
+
defineLazySection("rows", ()=>decodeLineSection(ctx, SHEET_WINDOW_SECTION_ROWS, "row"));
|
|
429
|
+
defineLazySection("columns", ()=>decodeLineSection(ctx, SHEET_WINDOW_SECTION_COLS, "column"));
|
|
430
|
+
defineLazySection("cells", ()=>decodeCells(ctx));
|
|
431
|
+
defineLazySection("paintGeometry", ()=>{
|
|
432
|
+
if (!paintGeometryPresent) {
|
|
433
|
+
return undefined;
|
|
434
|
+
}
|
|
435
|
+
const rects = decodeRects(ctx);
|
|
436
|
+
const geometry = {
|
|
437
|
+
rows: decodePaintLines(ctx, SHEET_WINDOW_SECTION_PAINT_ROWS, "row"),
|
|
438
|
+
columns: decodePaintLines(ctx, SHEET_WINDOW_SECTION_PAINT_COLS, "column"),
|
|
439
|
+
cells: decodePaintCells(ctx, rects),
|
|
440
|
+
activeSelection: nestedPaintGeometry?.activeSelection ?? paintGeometryActiveSelection,
|
|
441
|
+
objects: nestedPaintGeometry?.objects ?? paintGeometryObjects ?? [],
|
|
442
|
+
sparklines: nestedPaintGeometry?.sparklines ?? paintGeometrySparklines ?? []
|
|
443
|
+
};
|
|
444
|
+
return geometry;
|
|
445
|
+
});
|
|
446
|
+
return out;
|
|
447
|
+
}
|
|
448
|
+
export function createSheetWindowDecodedReader(deps) {
|
|
449
|
+
let disabled = false;
|
|
450
|
+
const warn = deps.warn ?? ((message, error)=>{
|
|
451
|
+
console.warn(message, error instanceof Error ? error.message : error);
|
|
452
|
+
});
|
|
453
|
+
const disable = (error)=>{
|
|
454
|
+
if (disabled) {
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
disabled = true;
|
|
458
|
+
warn(`xlsx ${SHEET_WINDOW_BINARY_SCHEMA_ID} decode failed; permanently falling back to the JSON sheet-window export for this bridge instance:`, error);
|
|
459
|
+
};
|
|
460
|
+
return (...args)=>{
|
|
461
|
+
const readBinary = deps.readBinary;
|
|
462
|
+
if (readBinary && !disabled) {
|
|
463
|
+
let recovered;
|
|
464
|
+
try {
|
|
465
|
+
return decodeSheetWindowBinary(readBinary(...args), {
|
|
466
|
+
onSectionDecodeError: (error)=>{
|
|
467
|
+
disable(error);
|
|
468
|
+
try {
|
|
469
|
+
recovered ??= deps.readJson(...args);
|
|
470
|
+
return recovered;
|
|
471
|
+
} catch {
|
|
472
|
+
return undefined;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
} catch (error) {
|
|
477
|
+
disable(error);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
return deps.readJson(...args);
|
|
481
|
+
};
|
|
482
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
|
|
2
|
+
const _fmtCache = new Map();
|
|
3
|
+
function getFormatter(tz) {
|
|
4
|
+
let f = _fmtCache.get(tz);
|
|
5
|
+
if (!f) {
|
|
6
|
+
f = new Intl.DateTimeFormat('en-US', {
|
|
7
|
+
timeZone: tz, year: 'numeric', month: '2-digit', day: '2-digit',
|
|
8
|
+
hour: '2-digit', minute: '2-digit', second: '2-digit', hourCycle: 'h23'
|
|
9
|
+
});
|
|
10
|
+
_fmtCache.set(tz, f);
|
|
11
|
+
}
|
|
12
|
+
return f;
|
|
13
|
+
}
|
|
14
|
+
function ic_tz_validate(name) {
|
|
15
|
+
try { getFormatter(name); return true; }
|
|
16
|
+
catch(_) { return false; }
|
|
17
|
+
}
|
|
18
|
+
function ic_tz_all() {
|
|
19
|
+
try {
|
|
20
|
+
const list = Intl.supportedValuesOf('timeZone');
|
|
21
|
+
|
|
22
|
+
const zones = new Set(list);
|
|
23
|
+
|
|
24
|
+
const extras = [ 'UTC', 'GMT' ];
|
|
25
|
+
|
|
26
|
+
for (const tz of extras) {
|
|
27
|
+
zones.add(tz);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return Array.from(zones);
|
|
31
|
+
} catch(e) {
|
|
32
|
+
// no support
|
|
33
|
+
console.log(e);
|
|
34
|
+
return [ ];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function ic_tz_parts(ms, tz) {
|
|
38
|
+
const p = {};
|
|
39
|
+
for (const x of getFormatter(tz).formatToParts(new Date(ms))) p[x.type] = x.value | 0;
|
|
40
|
+
return [p.year, p.month, p.day, p.hour, p.minute, p.second];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
exports.ic_tz_validate = ic_tz_validate;
|
|
44
|
+
exports.ic_tz_all = ic_tz_all;
|
|
45
|
+
exports.ic_tz_parts = ic_tz_parts;
|