@betteroffice/xlsx 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -20
- package/dist/chunk-4LMGHPXC.js +4 -0
- package/dist/collaboration.d.ts +59 -3
- package/dist/collaboration.js +1 -1
- package/dist/generated/xlsx_wasm_bg.wasm +0 -0
- package/dist/headless.d.ts +29 -1
- package/dist/headless.js +1 -1
- package/dist/index.d.ts +91 -7
- package/dist/index.js +1 -1
- package/dist/{types-RWuztdjw.d.ts → types-C24EBcAP.d.ts} +42 -1
- package/package.json +1 -1
- package/dist/chunk-II4BZDSC.js +0 -4
package/README.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
# @betteroffice/xlsx
|
|
2
2
|
|
|
3
3
|
Framework-free core for the BetterOffice XLSX editor — the Rust engine (parse,
|
|
4
|
-
calc, render) compiled to WebAssembly, plus display-list, viewport, hit-test,
|
|
5
|
-
accessibility helpers.
|
|
4
|
+
calc, render) compiled to WebAssembly, plus display-list, viewport, hit-test,
|
|
5
|
+
and accessibility helpers.
|
|
6
6
|
|
|
7
|
-
> **
|
|
7
|
+
> **Early (`0.0.x`).** The core surfaces — opening/saving documents, the editor
|
|
8
|
+
> components, collaboration — are settling and unlikely to change shape. Smaller
|
|
9
|
+
> APIs may still move between releases; breaking changes are always listed in
|
|
10
|
+
> the changelog.
|
|
8
11
|
|
|
9
12
|
```bash
|
|
10
13
|
bun add @betteroffice/xlsx
|
|
@@ -12,32 +15,62 @@ bun add @betteroffice/xlsx
|
|
|
12
15
|
|
|
13
16
|
Most apps want the turnkey React component in
|
|
14
17
|
[`@betteroffice/xlsx-react`](https://www.npmjs.com/package/@betteroffice/xlsx-react).
|
|
15
|
-
Reach for this package directly to render a spreadsheet onto your own canvas
|
|
18
|
+
Reach for this package directly to render a spreadsheet onto your own canvas or
|
|
19
|
+
to drive a workbook headlessly.
|
|
16
20
|
|
|
17
|
-
##
|
|
21
|
+
## Open, render, edit, save
|
|
18
22
|
|
|
19
23
|
```ts
|
|
20
|
-
import { initWasm, openWorkbook } from "@betteroffice/xlsx";
|
|
24
|
+
import { initWasm, openWorkbook, paintDisplayList } from "@betteroffice/xlsx";
|
|
21
25
|
|
|
22
26
|
await initWasm();
|
|
23
|
-
const
|
|
24
|
-
|
|
27
|
+
const workbook = openWorkbook(new Uint8Array(await file.arrayBuffer()));
|
|
28
|
+
|
|
29
|
+
const ctx = canvas.getContext("2d")!;
|
|
30
|
+
const dpr = devicePixelRatio;
|
|
31
|
+
canvas.width = 800 * dpr;
|
|
32
|
+
canvas.height = 600 * dpr;
|
|
33
|
+
const frame = workbook.displayList({ x: 0, y: 0, width: 800, height: 600 });
|
|
34
|
+
paintDisplayList(ctx, frame, dpr);
|
|
35
|
+
|
|
36
|
+
workbook.editCell(0, 9, 2, "=SUM(C1:C9)"); // recalcs dependents
|
|
37
|
+
const bytes = workbook.save();
|
|
25
38
|
```
|
|
26
39
|
|
|
27
|
-
`initWasm()` fetches the packaged wasm asset once in browsers. Pass wasm bytes
|
|
28
|
-
a precompiled `WebAssembly.Module` explicitly in runtimes that cannot fetch
|
|
29
|
-
asset URL.
|
|
40
|
+
`initWasm()` fetches the packaged wasm asset once in browsers. Pass wasm bytes
|
|
41
|
+
or a precompiled `WebAssembly.Module` explicitly in runtimes that cannot fetch
|
|
42
|
+
the asset URL.
|
|
30
43
|
|
|
31
|
-
|
|
44
|
+
Around the handle, the package exports the helpers a custom grid needs:
|
|
45
|
+
`cellAtPoint` / `cellRect` / `rangeRect` (hit-testing), the viewport math,
|
|
46
|
+
`buildA11yGrid` (accessibility tree), and `toTsv` / `fromTsv` (clipboard). The
|
|
47
|
+
handle itself covers styling (`patchRangeStyle`, `setNumberFormat`), undo/redo,
|
|
48
|
+
and PNG export (`renderPng` / `renderRangePng`; guard with
|
|
49
|
+
`isPngExportAvailable`).
|
|
32
50
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
51
|
+
## AI agents / human-in-the-loop
|
|
52
|
+
|
|
53
|
+
An agent stages edits as a proposal instead of applying them; a human reviews
|
|
54
|
+
per-cell before/after previews and accepts or rejects. Accepting applies the
|
|
55
|
+
proposal as one undo step and recalcs dependents, and throws
|
|
56
|
+
`StaleProposalError` if the workbook drifted under the proposal since it was
|
|
57
|
+
staged.
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { isProposalsAvailable } from "@betteroffice/xlsx";
|
|
61
|
+
|
|
62
|
+
if (isProposalsAvailable()) {
|
|
63
|
+
const proposal = workbook.propose("copilot", "add totals", [
|
|
64
|
+
{ sheet: 0, row: 9, col: 2, input: "=SUM(C1:C9)" },
|
|
65
|
+
]);
|
|
66
|
+
workbook.listProposals(); // pending proposals, oldest first
|
|
67
|
+
workbook.acceptProposal(proposal.id); // or workbook.rejectProposal(proposal.id)
|
|
68
|
+
}
|
|
69
|
+
```
|
|
36
70
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
`buildA11yGrid`, and `toTsv` / `fromTsv` (clipboard).
|
|
71
|
+
The React editor paints pending proposals as in-cell tracked-change ghosts with
|
|
72
|
+
an accept/reject panel. Guard with `isProposalsAvailable()` against cores built
|
|
73
|
+
without the feature.
|
|
41
74
|
|
|
42
75
|
## Collaboration
|
|
43
76
|
|
|
@@ -53,7 +86,9 @@ import {
|
|
|
53
86
|
await initWasm();
|
|
54
87
|
const workbook = openWorkbook(bytes, { collaborative: true });
|
|
55
88
|
const transport: CollaborationTransport = createTransport();
|
|
56
|
-
const provider = new CollaborationProvider(workbook, transport
|
|
89
|
+
const provider = new CollaborationProvider(workbook, transport, {
|
|
90
|
+
user: { name: "Ada" }, // identity for this peer's selection flag
|
|
91
|
+
});
|
|
57
92
|
provider.connect();
|
|
58
93
|
|
|
59
94
|
function dispose() {
|
|
@@ -74,4 +109,10 @@ Collaborative sessions currently support cell content, formulas, styles, column
|
|
|
74
109
|
widths, and row heights. Structural edits and inverse-op undo are rejected until
|
|
75
110
|
they have stable axis identities and a Yrs-aware undo manager.
|
|
76
111
|
|
|
112
|
+
## Development
|
|
113
|
+
|
|
114
|
+
The generated `.wasm` binary is intentionally not committed. From the repository
|
|
115
|
+
root, install `wasm-pack` 0.15.0 and run `bun run build:xlsx-wasm`. Package builds,
|
|
116
|
+
tests, demo startup, and CI run this step automatically.
|
|
117
|
+
|
|
77
118
|
Docs: https://betteroffice.dev · Apache-2.0.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
function I(e){return Math.max(0,e.length-1)}function D(e){return e.length>0?e[e.length-1]:0}function C(e,t,n){return Math.max(t,Math.min(n,e))}function L(e,t,n,r){let o=n,l=r;for(;o<l;){let c=o+l+1>>1;e[c]<=t?o=c:l=c-1;}return o}function M(e,t,n,r){let o=I(e);if(o===0)return {first:0,last:-1};let l=C(Math.trunc(t),0,o);if(l>=o)return {first:0,last:-1};let c=e[l]-e[0],i=e[l]+Math.max(0,n),s=Math.max(0,r-c),a=i+s,f=L(e,i,l,o-1);if(e[f+1]<=i||s===0)return {first:0,last:-1};let x=L(e,a,f,o-1);return {first:f,last:x}}function V(e,t,n){return {cols:M(t,e.frozenCols,e.scrollX,e.width),rows:M(n,e.frozenRows,e.scrollY,e.height)}}function T(e,t,n){let r=I(e),o=C(Math.trunc(t),0,r),l=D(e)-e[o],c=Math.max(0,n-(e[o]-e[0]));return Math.max(0,l-c)}function z(e,t,n){let r=C(e.scrollX,0,T(t,e.frozenCols,e.width)),o=C(e.scrollY,0,T(n,e.frozenRows,e.height));return r===e.scrollX&&o===e.scrollY?e:{...e,scrollX:r,scrollY:o}}function _(e,t){let n=new Array(e+1);for(let r=0;r<=e;r++)n[r]=r*t;return n}function A(e,t,n){return Math.max(t,Math.min(n,e))}function u(e){return {anchor:{...e},focus:{...e}}}function y(e){return {top:Math.min(e.anchor.row,e.focus.row),bottom:Math.max(e.anchor.row,e.focus.row),left:Math.min(e.anchor.col,e.focus.col),right:Math.max(e.anchor.col,e.focus.col)}}function $(e,t){let n=y(e);return t.row>=n.top&&t.row<=n.bottom&&t.col>=n.left&&t.col<=n.right}function U(e){let t=y(e);return (t.bottom-t.top+1)*(t.right-t.left+1)}function S(e,t,n){let r=n?{row:A(t.row,0,n.rows-1),col:A(t.col,0,n.cols-1)}:{...t};return {anchor:{...e.anchor},focus:r}}function W(e,t){switch(e){case "up":return {row:-t,col:0};case "down":return {row:t,col:0};case "left":return {row:0,col:-t};case "right":return {row:0,col:t}}}function h(e,t,n){let{limits:r}=n,o=n.step??1,l=W(t,o),c={row:A(e.focus.row+l.row,0,r.rows-1),col:A(e.focus.col+l.col,0,r.cols-1)};return n.extend?S(e,c):u(c)}var B={ArrowUp:"up",ArrowDown:"down",ArrowLeft:"left",ArrowRight:"right"};function R(e){return !!(e.metaKey||e.ctrlKey)}function X(e,t,n){switch(t){case "up":return {row:0,col:e.col};case "down":return {row:n.rows-1,col:e.col};case "left":return {row:e.row,col:0};case "right":return {row:e.row,col:n.cols-1}}}function m(e){return {type:"move",selection:e}}function Y(e,t,n){let{row:r,col:o}=e.focus;return !t&&o>=n.cols-1?u({row:Math.min(r+1,n.rows-1),col:0}):t&&o<=0?u({row:Math.max(r-1,0),col:n.cols-1}):u({row:r,col:o+(t?-1:1)})}function N(e){return e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey}function j(e,t,n){let r=B[t.key];if(r){if(R(t)){let o=X(e.focus,r,n);return m(t.shiftKey?S(e,o,n):u(o))}return m(h(e,r,{extend:t.shiftKey,limits:n}))}switch(t.key){case "Tab":return m(Y(e,!!t.shiftKey,n));case "Enter":return m(h(e,t.shiftKey?"up":"down",{extend:false,limits:n}));case "Home":return m(R(t)?u({row:0,col:0}):u({row:e.focus.row,col:0}));case "End":return m(R(t)?u({row:n.rows-1,col:n.cols-1}):u({row:e.focus.row,col:n.cols-1}));case "PageDown":return m(h(e,"down",{extend:t.shiftKey,step:n.rowsPerPage,limits:n}));case "PageUp":return m(h(e,"up",{extend:t.shiftKey,step:n.rowsPerPage,limits:n}));case "F2":return {type:"startEdit"};case "Delete":case "Backspace":return {type:"clear"}}return (t.key==="a"||t.key==="A")&&R(t)?m({anchor:{row:0,col:0},focus:{row:n.rows-1,col:n.cols-1}}):N(t)?{type:"startEdit",initialInput:t.key}:{type:"none"}}function E(e,t){let n=e.length-1;if(n<=0||t<e[0]||t>=e[n])return -1;let r=0,o=n-1;for(;r<o;){let l=r+o+1>>1;e[l]<=t?r=l:o=l-1;}return r}function we(e,t,n){if(!e)return null;let r=E(e.colOffsets,t),o=E(e.rowOffsets,n);return r<0||o<0?null:{row:e.rowIndices?.[o]??e.startRow+o,col:e.colIndices?.[r]??e.startCol+r}}function v(e,t,n,r){if(t){let l=0,c=t.length-1;for(;l<=c;){let i=l+c>>1,s=t[i];if(s===r)return i;s<r?l=i+1:c=i-1;}return -1}let o=r-e;return o>=0&&o<n.length-1?o:-1}function he(e,t,n){if(!e)return null;let r=v(e.startCol,e.colIndices,e.colOffsets,n),o=v(e.startRow,e.rowIndices,e.rowOffsets,t);return r<0||o<0?null:{x:e.colOffsets[r],y:e.rowOffsets[o],w:e.colOffsets[r+1]-e.colOffsets[r],h:e.rowOffsets[o+1]-e.rowOffsets[o]}}function q(e,t,n){return t?.[n]??e+n}function K(e,t,n,r,o){let l=-1,c=-1;for(let i=0;i<n;i++){let s=q(e,t,i);if(!(s<r)){if(s>o)break;l<0&&(l=i),c=i;}}return l<0?null:[l,c]}function be(e,t){if(!e)return null;let n=e.colOffsets.length-1,r=e.rowOffsets.length-1;if(n<=0||r<=0)return null;let o=K(e.startCol,e.colIndices,n,t.left,t.right),l=K(e.startRow,e.rowIndices,r,t.top,t.bottom);if(!o||!l)return null;let[c,i]=o,[s,a]=l;return {x:e.colOffsets[c],y:e.rowOffsets[s],w:e.colOffsets[i+1]-e.colOffsets[c],h:e.rowOffsets[a+1]-e.rowOffsets[s]}}function ye(e,t,n){return e.hyperlinks?.find(r=>t>=r.top&&t<=r.bottom&&n>=r.left&&n<=r.right)??null}function ge(e){if(!e.externalTarget)return null;let t;try{t=new URL(e.externalTarget);}catch{return null}return ["http:","https:","mailto:","tel:"].includes(t.protocol)?(e.location&&!t.hash&&(t.hash=e.location.replace(/^#/,"")),t.href):null}function xe(e,t){let n=e.replace(/^#/,""),r=n.lastIndexOf("!"),o=r<0?t:n.slice(0,r),l=(r<0?n:n.slice(r+1)).split(":",1)[0],c=/^\$?([A-Za-z]{1,3})\$?([1-9]\d*)$/.exec(l);if(!c)return null;let i=0;for(let f of c[1].toUpperCase())i=i*26+f.charCodeAt(0)-64;let s=Number(c[2]);if(i<1||i>16384||s<1||s>1048576)return null;let a=o.startsWith("'")&&o.endsWith("'")?o.slice(1,-1).replace(/''/g,"'"):o;return a?{sheetName:a,row:s-1,col:i-1}:null}var J=new Set(["=","+","-","@"]);function Z(e){let t=e.charCodeAt(0);return J.has(e[0])||t===9||t===13||t===10}function Q(e){return /[\t\n\r"]/.test(e)?`"${e.replace(/"/g,'""')}"`:e}function ee(e){let t=!e.isFormula&&e.input.length>0&&Z(e.input);return Q(t?`'${e.input}`:e.input)}function Ae(e){return e.map(t=>t.map(ee).join(" ")).join(`\r
|
|
2
|
+
`)}function Se(e){let t=[],n=[],r="",o=false,l=0,c=()=>{n.push(r),r="";},i=()=>{c(),t.push(n),n=[];};for(;l<e.length;){let s=e[l];if(o){if(s==='"'){if(e[l+1]==='"'){r+='"',l+=2;continue}o=false,l+=1;continue}r+=s,l+=1;continue}if(s==='"'){o=true,l+=1;continue}if(s===" "){c(),l+=1;continue}if(s==="\r"){i(),e[l+1]===`
|
|
3
|
+
`&&(l+=1),l+=1;continue}if(s===`
|
|
4
|
+
`){i(),l+=1;continue}r+=s,l+=1;}return (r.length>0||n.length>0)&&i(),t}function H(e){let t=e,n="";do n=String.fromCharCode(65+t%26)+n,t=Math.floor(t/26)-1;while(t>=0);return n}function te(e,t){return `${H(t)}${e+1}`}function O(e,t){return e.replace(/\{(\w+)\}/g,(n,r)=>String(t[r]??""))}function P(e,t){return `${Math.round(e*1e3)},${Math.round(t*1e3)}`}function ne(e){let t=new Map;for(let n of e.commands)n.op==="text"&&n.clip&&!n.ghost&&t.set(P(n.clip.x,n.clip.y),n.text);return t}function re(e,t,n){return e?t>=e.top&&t<=e.bottom&&n>=e.left&&n<=e.right:false}function g(e,t,n){return t?.[n]??e+n}function oe(e,t,n,r,o,l){let c=g(e.startRow,e.rowIndices,t),i=g(e.startCol,e.colIndices,n),s=te(c,i),f=r.length===0?o?l.emptyCellLabelSelected:l.emptyCellLabel:o?l.cellLabelSelected:l.cellLabel;return {row:c,col:i,address:s,text:r,selected:o,label:O(f,{address:s,value:r})}}function Me(e,t,n,r){let o=e.grid,l=O(r.gridLabel,{sheet:n});if(!o)return {label:l,sheetName:n,columnHeaders:[],rows:[]};let c=o.colOffsets.length-1,i=o.rowOffsets.length-1,s=t?y(t):null,a=ne(e),f=[];for(let p=0;p<c;p++){let w=g(o.startCol,o.colIndices,p),b=H(w);f.push({col:w,text:b,label:O(r.columnHeaderLabel,{column:b})});}let x=[];for(let p=0;p<i;p++){let w=g(o.startRow,o.rowIndices,p),b=[];for(let d=0;d<c;d++){let k=P(o.colOffsets[d],o.rowOffsets[p]),F=a.get(k)??"",G=g(o.startCol,o.colIndices,d);b.push(oe(o,p,d,F,re(s,w,G),r));}x.push({row:w,header:O(r.rowHeaderLabel,{row:w+1}),cells:b});}return {label:l,sheetName:n,columnHeaders:f,rows:x}}export{I as a,D as b,M as c,V as d,z as e,_ as f,u as g,y as h,$ as i,U as j,S as k,h as l,j as m,we as n,he as o,be as p,ye as q,ge as r,xe as s,Ae as t,Se as u,Me as v};
|
package/dist/collaboration.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CollaborationReplica, a as CollaborationTransport, b as CollaborationProviderOptions, c as CollaborationStatus, d as CollaborationStatusListener, e as CollaborationErrorListener } from './types-
|
|
2
|
-
export {
|
|
1
|
+
import { C as CollaborationReplica, a as CollaborationTransport, b as CollaborationProviderOptions, c as CollaborationStatus, A as AwarenessPeer, d as CollaborationStatusListener, e as CollaborationErrorListener, f as AwarenessListener, g as AwarenessCursor, h as AwarenessPayload, i as AwarenessUpdate, j as CollaborationUserOptions, k as CollaborationUser } from './types-C24EBcAP.js';
|
|
2
|
+
export { l as AwarenessCell, m as AwarenessState, n as CollaborationAwareness, o as CollaborationError, p as CollaborationErrorCode, q as CollaborationStatusChange, r as CollaborationTransportEvent, s as CollaborationUpdateOrigin } from './types-C24EBcAP.js';
|
|
3
3
|
|
|
4
4
|
declare class CollaborationProvider {
|
|
5
5
|
private readonly replica;
|
|
@@ -9,6 +9,9 @@ declare class CollaborationProvider {
|
|
|
9
9
|
private readonly maxPendingBytes;
|
|
10
10
|
private readonly statusListeners;
|
|
11
11
|
private readonly errorListeners;
|
|
12
|
+
private readonly awarenessListeners;
|
|
13
|
+
private readonly awarenessStore;
|
|
14
|
+
private readonly awarenessUser;
|
|
12
15
|
private readonly pendingFrames;
|
|
13
16
|
private unsubscribeReplica;
|
|
14
17
|
private unsubscribeTransport;
|
|
@@ -25,16 +28,27 @@ declare class CollaborationProvider {
|
|
|
25
28
|
private isFlushing;
|
|
26
29
|
private transportCleanup;
|
|
27
30
|
private statusRevision;
|
|
31
|
+
private awarenessClock;
|
|
32
|
+
private reportedClockExhaustion;
|
|
33
|
+
private awarenessCursor;
|
|
34
|
+
private lastAwarenessSentAt;
|
|
35
|
+
private awarenessBroadcastTimer;
|
|
36
|
+
private awarenessHeartbeatTimer;
|
|
37
|
+
private awarenessExpiryTimer;
|
|
38
|
+
private hasPublishedAwarenessForOpen;
|
|
28
39
|
constructor(replica: CollaborationReplica, transport: CollaborationTransport, options?: CollaborationProviderOptions);
|
|
29
40
|
get status(): CollaborationStatus;
|
|
30
41
|
get synced(): boolean;
|
|
31
42
|
get pendingBytes(): number;
|
|
43
|
+
get peers(): readonly AwarenessPeer[];
|
|
32
44
|
connect(): void;
|
|
33
45
|
private startConnection;
|
|
34
46
|
disconnect(): void;
|
|
35
47
|
destroy(): void;
|
|
36
48
|
onStatus(listener: CollaborationStatusListener): () => void;
|
|
37
49
|
onError(listener: CollaborationErrorListener): () => void;
|
|
50
|
+
onAwareness(listener: AwarenessListener): () => void;
|
|
51
|
+
setCursor(cursor: AwarenessCursor | null): void;
|
|
38
52
|
private isCurrent;
|
|
39
53
|
private failConnection;
|
|
40
54
|
private takeTransportSubscription;
|
|
@@ -45,7 +59,13 @@ declare class CollaborationProvider {
|
|
|
45
59
|
private respondToSyncStep1;
|
|
46
60
|
private applyRemoteUpdate;
|
|
47
61
|
private forwardLocalUpdate;
|
|
62
|
+
private publishAwareness;
|
|
63
|
+
private startAwarenessTimers;
|
|
64
|
+
private stopAwarenessTimers;
|
|
65
|
+
private clearAwarenessPeers;
|
|
66
|
+
private emitAwareness;
|
|
48
67
|
private sendFrame;
|
|
68
|
+
private sendBestEffort;
|
|
49
69
|
private queueFrame;
|
|
50
70
|
private flushPending;
|
|
51
71
|
private clearPending;
|
|
@@ -53,4 +73,40 @@ declare class CollaborationProvider {
|
|
|
53
73
|
private report;
|
|
54
74
|
}
|
|
55
75
|
|
|
56
|
-
|
|
76
|
+
declare const AWARENESS_BROADCAST_INTERVAL_MS = 80;
|
|
77
|
+
declare const AWARENESS_HEARTBEAT_INTERVAL_MS = 20000;
|
|
78
|
+
declare const AWARENESS_PEER_TIMEOUT_MS = 45000;
|
|
79
|
+
declare const AWARENESS_LABEL_DURATION_MS = 3000;
|
|
80
|
+
declare const XLSX_MAX_ROWS = 1048576;
|
|
81
|
+
declare const XLSX_MAX_COLUMNS = 16384;
|
|
82
|
+
declare const MAX_TRACKED_AWARENESS_PEERS = 1024;
|
|
83
|
+
declare const AWARENESS_COLORS: readonly ["#0B57D0", "#B3261E", "#146C2E", "#6B4EFF", "#8E24AA", "#00639B", "#8E4E00", "#7D5260"];
|
|
84
|
+
interface AwarenessPeerEntry {
|
|
85
|
+
clock: number;
|
|
86
|
+
state: AwarenessPayload | null;
|
|
87
|
+
lastSeen: number;
|
|
88
|
+
cursorMovedAt: number;
|
|
89
|
+
}
|
|
90
|
+
type AwarenessPeerStore = Map<number, AwarenessPeerEntry>;
|
|
91
|
+
interface ApplyAwarenessUpdateOptions {
|
|
92
|
+
maxPeers?: number;
|
|
93
|
+
onPeersDiscarded?: (count: number) => void;
|
|
94
|
+
}
|
|
95
|
+
interface ResolvedAwarenessCursor {
|
|
96
|
+
sheetIndex: number;
|
|
97
|
+
range: {
|
|
98
|
+
top: number;
|
|
99
|
+
left: number;
|
|
100
|
+
bottom: number;
|
|
101
|
+
right: number;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
declare function colorForClientId(clientId: number): string;
|
|
105
|
+
declare function normalizeAwarenessColor(color: unknown, clientId: number): string;
|
|
106
|
+
declare function normalizeCollaborationUser(user: CollaborationUserOptions | undefined, clientId: number): CollaborationUser;
|
|
107
|
+
declare function applyAwarenessUpdates(store: AwarenessPeerStore, updates: readonly AwarenessUpdate[], localClientId: number, now: number, options?: ApplyAwarenessUpdateOptions): boolean;
|
|
108
|
+
declare function expireAwarenessPeers(store: AwarenessPeerStore, now: number, timeout?: number): boolean;
|
|
109
|
+
declare function awarenessPeers(store: AwarenessPeerStore): AwarenessPeer[];
|
|
110
|
+
declare function resolveAwarenessCursor(cursor: AwarenessCursor, sheetIds: readonly string[], rows?: number, columns?: number): ResolvedAwarenessCursor | null;
|
|
111
|
+
|
|
112
|
+
export { AWARENESS_BROADCAST_INTERVAL_MS, AWARENESS_COLORS, AWARENESS_HEARTBEAT_INTERVAL_MS, AWARENESS_LABEL_DURATION_MS, AWARENESS_PEER_TIMEOUT_MS, type ApplyAwarenessUpdateOptions, AwarenessCursor, AwarenessListener, AwarenessPayload, AwarenessPeer, type AwarenessPeerEntry, type AwarenessPeerStore, AwarenessUpdate, CollaborationErrorListener, CollaborationProvider, CollaborationProviderOptions, CollaborationReplica, CollaborationStatus, CollaborationStatusListener, CollaborationTransport, CollaborationUser, CollaborationUserOptions, MAX_TRACKED_AWARENESS_PEERS, type ResolvedAwarenessCursor, XLSX_MAX_COLUMNS, XLSX_MAX_ROWS, applyAwarenessUpdates, awarenessPeers, colorForClientId, expireAwarenessPeers, normalizeAwarenessColor, normalizeCollaborationUser, resolveAwarenessCursor };
|
package/dist/collaboration.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {a as a$1}from'./chunk-O2XFH626.js';var w=Number.MAX_SAFE_INTEGER,c=class extends Error{constructor(t){super(t),this.name="ProtocolError";}},d=class{constructor(t){a$1(this,"bytes",t);a$1(this,"offset",0);}get done(){return this.offset===this.bytes.byteLength}readVarUint(){let t=0,e=1,r=0;for(;;){if(this.offset>=this.bytes.byteLength)throw new c("Truncated varUint");let n=this.bytes[this.offset++],o=n&127;if(o>Math.floor((w-t)/e))throw new c("varUint exceeds Number.MAX_SAFE_INTEGER");if(t+=o*e,r+=1,(n&128)===0){if(r>1&&o===0)throw new c("Non-canonical varUint");return t}if(r>=8)throw new c("varUint exceeds Number.MAX_SAFE_INTEGER");e*=128;}}readVarUint8Array(){let t=this.readVarUint(),e=this.bytes.byteLength-this.offset;if(t>e)throw new c("Truncated varUint8Array");let r=this.bytes.slice(this.offset,this.offset+t);return this.offset+=t,r}readVarString(){let t=this.readVarUint8Array();try{return new TextDecoder("utf-8",{fatal:!0}).decode(t)}catch(e){throw new c(`Invalid UTF-8 string${e instanceof Error?`: ${e.message}`:""}`)}}};function h(s){if(!Number.isSafeInteger(s)||s<0)throw new c("varUint value must be a non-negative safe integer");let t=[],e=s;for(;e>=128;)t.push(e%128|128),e=Math.floor(e/128);return t.push(e),Uint8Array.from(t)}function E(s,t){let e=0;for(let o of s)if(e+=o.byteLength,e>t)throw new c(`Frame exceeds ${t} bytes`);let r=new Uint8Array(e),n=0;for(let o of s)r.set(o,n),n+=o.byteLength;return r}function y(s,t,e){return E([h(0),h(s),h(t.byteLength),t],e)}function C(s,t=67108880){return y(0,s,t)}function S(s,t=67108880){return y(1,s,t)}function A(s,t=67108880){return y(2,s,t)}function g(s=67108880){let t=Uint8Array.of(0);return E([h(1),h(t.byteLength),t],s)}function v(s,t=67108880,e=4096){if(!(s instanceof Uint8Array))throw new c("Frame must be a Uint8Array");if(s.byteLength===0)throw new c("Frame is empty");if(s.byteLength>t)throw new c(`Frame exceeds ${t} bytes`);if(!Number.isSafeInteger(e)||e<1)throw new c("Message limit must be a positive integer");let r=new d(s),n=[];for(;!r.done;){if(n.length>=e)throw new c(`Frame exceeds ${e} messages`);let o=r.readVarUint();switch(o){case 0:{let p=r.readVarUint(),l=r.readVarUint8Array();if(p===0)n.push({type:"sync-step-1",stateVector:l});else if(p===1)n.push({type:"sync-step-2",update:l});else if(p===2)n.push({type:"update",update:l});else throw new c(`Unknown sync message type ${p}`);break}case 1:n.push({type:"awareness",update:r.readVarUint8Array()});break;case 2:{let p=r.readVarUint();if(p!==0)throw new c(`Unknown auth message type ${p}`);n.push({type:"auth",reason:r.readVarString()});break}case 3:n.push({type:"query-awareness"});break;default:throw new c(`Unknown top-level message type ${o}`)}}return n}var u=class extends Error{constructor(e,r,n){super(r);a$1(this,"code");a$1(this,"cause");this.name="CollaborationError",this.code=e,this.cause=n;}};var _=67108880;function f(s,t,e){if(!Number.isSafeInteger(t)||t<(e?0:1))throw new RangeError(`${s} must be ${e?"a non-negative":"a positive"} integer`);return t}function F(s){return s instanceof Error&&s.message?s.message:typeof s=="string"&&s?s:"Unknown error"}function a(s,t,e){return e instanceof u?e:new u(s,`${t}: ${F(e)}`,e)}function b(s,t){if(!(s instanceof Uint8Array))throw new TypeError(`${t} must return a Uint8Array`);return s.slice()}var m=class{constructor(t,e,r={}){a$1(this,"replica");a$1(this,"transport");a$1(this,"maxFrameBytes");a$1(this,"maxMessagesPerFrame");a$1(this,"maxPendingBytes");a$1(this,"statusListeners",new Map);a$1(this,"errorListeners",new Map);a$1(this,"pendingFrames",[]);a$1(this,"unsubscribeReplica");a$1(this,"unsubscribeTransport",()=>{});a$1(this,"hasTransportSubscription",false);a$1(this,"connectionStatus","disconnected");a$1(this,"isSynced",false);a$1(this,"wantsConnection",false);a$1(this,"isOpen",false);a$1(this,"isDestroyed",false);a$1(this,"epoch",0);a$1(this,"connectAttempt",0);a$1(this,"nextListenerId",0);a$1(this,"queuedBytes",0);a$1(this,"isFlushing",false);a$1(this,"transportCleanup");a$1(this,"statusRevision",0);this.replica=t,this.transport=e,this.maxFrameBytes=f("maxFrameBytes",r.maxFrameBytes??67108880,false),this.maxMessagesPerFrame=f("maxMessagesPerFrame",r.maxMessagesPerFrame??4096,false),this.maxPendingBytes=f("maxPendingBytes",r.maxPendingBytes??_,true);try{this.unsubscribeReplica=t.onUpdate((n,o)=>{o==="local"&&this.forwardLocalUpdate(n);});}catch(n){throw a("replica","Failed to observe replica updates",n)}}get status(){return this.connectionStatus}get synced(){return this.isSynced}get pendingBytes(){return this.queuedBytes}connect(){this.isDestroyed||this.isOpen||this.connectionStatus==="connecting"||(this.wantsConnection=true,this.setStatus("connecting",false),!(this.transportCleanup||this.isDestroyed||!this.wantsConnection)&&this.startConnection());}startConnection(){if(this.isDestroyed||!this.wantsConnection||this.isOpen||this.transportCleanup)return;let t=this.hasTransportSubscription?this.epoch:++this.epoch,e=++this.connectAttempt;if(this.setStatus("connecting",false),!!this.isCurrent(t)){if(!this.hasTransportSubscription){let r;try{if(r=this.transport.onEvent(n=>this.handleTransportEvent(t,n)),typeof r!="function")throw new TypeError("Transport event subscription must return a function")}catch(n){this.failConnection(t,a("transport","Failed to subscribe to transport events",n));return}if(!this.isCurrent(t)){try{r();}catch(n){this.isDestroyed||this.report(a("transport","Failed to unsubscribe from stale transport events",n));}return}this.unsubscribeTransport=r,this.hasTransportSubscription=true;}try{let r=this.transport.connect();r&&r.catch(n=>{this.isCurrent(t)&&this.connectAttempt===e&&this.failConnection(t,a("transport","Transport connect failed",n));});}catch(r){this.failConnection(t,a("transport","Transport connect failed",r));}}}disconnect(){if(this.isDestroyed||!(this.wantsConnection||this.isOpen||this.hasTransportSubscription||this.connectionStatus!=="disconnected"))return;this.wantsConnection=false,this.isOpen=false,this.epoch+=1,this.connectAttempt+=1;let e=this.takeTransportSubscription();this.clearPending();let r=this.cleanupTransport(e,true);this.setStatus("disconnected",false);for(let n of r)this.report(n);}destroy(){if(this.isDestroyed)return;let t=this.wantsConnection||this.isOpen||this.hasTransportSubscription||this.connectionStatus==="connecting"||this.connectionStatus==="connected";this.isDestroyed=true,this.wantsConnection=false,this.isOpen=false,this.epoch+=1,this.connectAttempt+=1;let e=this.takeTransportSubscription();this.clearPending();let r=this.cleanupTransport(e,t);this.setStatus("destroyed",false);for(let n of r)this.report(n);try{this.unsubscribeReplica();}catch(n){this.report(a("replica","Failed to unsubscribe from replica updates",n));}this.unsubscribeReplica=()=>{},this.statusListeners.clear(),this.errorListeners.clear();}onStatus(t){if(this.isDestroyed)return ()=>{};if(typeof t!="function")throw new TypeError("status listener must be a function");let e=this.nextListenerId++;return this.statusListeners.set(e,t),()=>this.statusListeners.delete(e)}onError(t){if(this.isDestroyed)return ()=>{};if(typeof t!="function")throw new TypeError("error listener must be a function");let e=this.nextListenerId++;return this.errorListeners.set(e,t),()=>this.errorListeners.delete(e)}isCurrent(t){return !this.isDestroyed&&this.wantsConnection&&t===this.epoch}failConnection(t,e){if(!this.isCurrent(t))return;this.wantsConnection=false,this.isOpen=false,this.epoch+=1,this.connectAttempt+=1;let r=this.takeTransportSubscription();this.clearPending();let n=this.cleanupTransport(r,true);this.setStatus("disconnected",false),this.report(e);for(let o of n)this.report(o);}takeTransportSubscription(){let t=this.unsubscribeTransport;return this.unsubscribeTransport=()=>{},this.hasTransportSubscription=false,t}cleanupTransport(t,e){let r=[];try{t();}catch(n){r.push(a("transport","Failed to unsubscribe from transport events",n));}if(!e||this.transportCleanup)return r;try{let n=this.transport.disconnect();if(n){let o=!1,p=Promise.resolve(n).catch(l=>{o=!0,this.isDestroyed||this.report(a("transport","Transport disconnect failed",l));}).finally(()=>{this.transportCleanup===p&&(this.transportCleanup=void 0,!this.isDestroyed&&(o?(this.wantsConnection=!1,this.setStatus("disconnected",!1)):this.wantsConnection&&this.startConnection()));});this.transportCleanup=p;}}catch(n){r.push(a("transport","Transport disconnect failed",n));}return r}handleTransportEvent(t,e){if(this.isCurrent(t))switch(e.type){case "open":this.handleOpen(t);break;case "message":this.isOpen&&this.handleMessage(t,e.data);break;case "close":this.isOpen=false,this.connectAttempt+=1,this.clearPending(),this.setStatus("disconnected",false);break;case "error":this.failConnection(t,a("transport","Transport error",e.error));break;case "drain":this.isOpen&&this.flushPending();break;default:this.failConnection(t,new u("transport","Unknown transport event"));}}handleOpen(t){if(this.isOpen||(this.isOpen=true,this.clearPending(),this.setStatus("connected",false),!this.isCurrent(t)||!this.isOpen))return;let e;try{e=b(this.replica.encodeStateVector(),"encodeStateVector");}catch(r){this.failConnection(t,a("replica","Failed to encode replica state vector",r));return}try{this.sendFrame(C(e,this.maxFrameBytes));}catch(r){this.failConnection(t,a("protocol","Failed to encode SyncStep1",r));}}handleMessage(t,e){let r;try{if(!(e instanceof Uint8Array))throw new TypeError("Frame must be a Uint8Array");if(e.byteLength>this.maxFrameBytes)throw new RangeError(`Frame exceeds ${this.maxFrameBytes} bytes`);r=v(e,this.maxFrameBytes,this.maxMessagesPerFrame);}catch(n){this.failConnection(t,a("protocol","Invalid collaboration frame",n));return}for(let n of r){if(!this.isCurrent(t)||!this.isOpen)return;switch(n.type){case "sync-step-1":this.respondToSyncStep1(t,n.stateVector);break;case "sync-step-2":this.applyRemoteUpdate(t,n.update)&&this.isCurrent(t)&&this.setStatus("connected",true);break;case "update":this.applyRemoteUpdate(t,n.update);break;case "awareness":break;case "auth":this.failConnection(t,new u("protocol",n.reason?`Authentication denied: ${n.reason}`:"Authentication denied"));return;case "query-awareness":try{this.sendFrame(g(this.maxFrameBytes));}catch(o){this.failConnection(t,a("protocol","Failed to encode awareness response",o));return}break}}}respondToSyncStep1(t,e){let r;try{r=b(this.replica.encodeStateAsUpdate(e.slice()),"encodeStateAsUpdate");}catch(n){this.failConnection(t,a("replica","Failed to encode replica update",n));return}try{this.sendFrame(S(r,this.maxFrameBytes));}catch(n){this.failConnection(t,a("protocol","Failed to encode SyncStep2",n));}}applyRemoteUpdate(t,e){try{return this.replica.applyUpdate(e.slice()),!0}catch(r){return this.failConnection(t,a("replica","Failed to apply remote update",r)),false}}forwardLocalUpdate(t){if(this.isDestroyed||!this.isOpen||!this.wantsConnection)return;let e=this.epoch,r;try{r=b(t,"Replica update");}catch(n){this.failConnection(e,a("replica","Invalid replica update",n));return}try{this.sendFrame(A(r,this.maxFrameBytes));}catch(n){this.failConnection(e,a("protocol","Failed to encode update",n));}}sendFrame(t){if(!this.isOpen||this.isDestroyed||!this.wantsConnection)return;let e=this.epoch;if(this.pendingFrames.length>0){this.queueFrame(e,t);return}let r;try{r=this.transport.send(t.slice());}catch(n){this.failConnection(e,a("transport","Transport send failed",n));return}if(typeof r!="boolean"){this.failConnection(e,new u("transport","Transport send must return a boolean"));return}!r&&this.isCurrent(e)&&this.isOpen&&this.queueFrame(e,t);}queueFrame(t,e){if(e.byteLength>this.maxPendingBytes-this.queuedBytes){this.failConnection(t,new u("backpressure",`Pending collaboration data exceeds ${this.maxPendingBytes} bytes`));return}let r=e.slice();this.pendingFrames.push(r),this.queuedBytes+=r.byteLength;}flushPending(){if(!this.isFlushing){this.isFlushing=true;try{for(;this.isOpen&&!this.isDestroyed&&this.pendingFrames.length>0;){let t=this.epoch,e=this.pendingFrames[0],r;try{r=this.transport.send(e.slice());}catch(n){this.failConnection(t,a("transport","Transport send failed",n));return}if(typeof r!="boolean"){this.failConnection(t,new u("transport","Transport send must return a boolean"));return}if(!r||!this.isOpen||this.pendingFrames[0]!==e)return;this.pendingFrames.shift(),this.queuedBytes-=e.byteLength;}}finally{this.isFlushing=false;}}}clearPending(){this.pendingFrames.length=0,this.queuedBytes=0;}setStatus(t,e){if(this.connectionStatus===t&&this.isSynced===e)return;this.connectionStatus=t,this.isSynced=e;let r=++this.statusRevision,n={status:t,synced:e};for(let[o,p]of [...this.statusListeners]){if(this.statusRevision!==r)return;if(this.statusListeners.get(o)===p)try{p(n);}catch{}}}report(t){for(let[e,r]of [...this.errorListeners])if(this.errorListeners.get(e)===r)try{r(t);}catch{}}};export{u as CollaborationError,m as CollaborationProvider};
|
|
1
|
+
import {a}from'./chunk-O2XFH626.js';var v=80,U=2e4,_=45e3,oe=3e3,ie=1048576,ce=16384;var x=1024,T=["#0B57D0","#B3261E","#146C2E","#6B4EFF","#8E24AA","#00639B","#8E4E00","#7D5260"];function X(r){return r?{sheet:r.sheet,anchor:{...r.anchor},head:{...r.head}}:null}function le(r){return {user:{...r.user},cursor:X(r.cursor)}}function V(r,e){return !r||!e?r===e:r.sheet===e.sheet&&r.anchor.row===e.anchor.row&&r.anchor.col===e.anchor.col&&r.head.row===e.head.row&&r.head.col===e.head.col}function ue(r,e){return !r||!e?r===e:r.user.name===e.user.name&&r.user.color===e.user.color&&V(r.cursor,e.cursor)}function $(r){return T[r%T.length]}function E(r,e){if(typeof r!="string"||!/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.test(r))return $(e);let t=r.slice(1).toUpperCase();return t.length===6?`#${t}`:`#${t[0]}${t[0]}${t[1]}${t[1]}${t[2]}${t[2]}`}function P(r,e){return {name:r?.name.trim().slice(0,128)||"Anonymous",color:E(r?.color,e)}}function R(r,e,t,s,n={}){let a=n.maxPeers??1024;if(!Number.isSafeInteger(a)||a<1)throw new RangeError("Awareness peer limit must be a positive integer");let c=false,l=0;for(let p of e){if(p.clientId===t)continue;let d=r.get(p.clientId);if(d&&p.clock<d.clock)continue;if(d&&p.clock===d.clock){d.lastSeen=s;continue}if(!d&&r.size>=a){l+=1;continue}let m=p.state?.cursor!=null&&(!d?.state||!V(d.state.cursor,p.state.cursor)),f=p.state?le(p.state):null;c||(c=!ue(d?.state??null,f)),r.set(p.clientId,{clock:p.clock,state:f,lastSeen:s,cursorMovedAt:m?s:d?.cursorMovedAt??0});}return l>0&&n.onPeersDiscarded?.(l),c}function L(r,e,t=45e3){let s=false;for(let[n,a]of r)e-a.lastSeen<t||(s||(s=a.state!==null),r.delete(n));return s}function M(r){let e=[];for(let[t,s]of r)s.state&&e.push({clientId:t,clock:s.clock,user:{...s.state.user},cursor:X(s.state.cursor),lastSeen:s.lastSeen,cursorMovedAt:s.cursorMovedAt});return e.sort((t,s)=>t.clientId-s.clientId),e}function pe(r,e,t=1048576,s=16384){let n=e.indexOf(r.sheet);return n<0||t<1||s<1||[r.anchor,r.head].some(({row:c,col:l})=>!Number.isSafeInteger(c)||!Number.isSafeInteger(l)||c<0||l<0||c>=t||l>=s)?null:{sheetIndex:n,range:{top:Math.min(r.anchor.row,r.head.row),left:Math.min(r.anchor.col,r.head.col),bottom:Math.max(r.anchor.row,r.head.row),right:Math.max(r.anchor.col,r.head.col)}}}var w=16777216,F=4096,b=1024,H=0,G=1,de=2,Y=3,z=0,K=1,j=2,fe=0,Ae=Number.MAX_SAFE_INTEGER,i=class extends Error{constructor(e){super(e),this.name="ProtocolError";}},C=class{constructor(e){a(this,"bytes",e);a(this,"offset",0);}get done(){return this.offset===this.bytes.byteLength}readVarUint(){let e=0,t=1,s=0;for(;;){if(this.offset>=this.bytes.byteLength)throw new i("Truncated varUint");let n=this.bytes[this.offset++],a=n&127;if(a>Math.floor((Ae-e)/t))throw new i("varUint exceeds Number.MAX_SAFE_INTEGER");if(e+=a*t,s+=1,(n&128)===0){if(s>1&&a===0)throw new i("Non-canonical varUint");return e}if(s>=8)throw new i("varUint exceeds Number.MAX_SAFE_INTEGER");t*=128;}}readVarUint8Array(){let e=this.readVarUint(),t=this.bytes.byteLength-this.offset;if(e>t)throw new i("Truncated varUint8Array");let s=this.bytes.slice(this.offset,this.offset+e);return this.offset+=e,s}readVarString(){let e=this.readVarUint8Array();try{return new TextDecoder("utf-8",{fatal:!0}).decode(e)}catch(t){throw new i(`Invalid UTF-8 string${t instanceof Error?`: ${t.message}`:""}`)}}};function A(r){if(!Number.isSafeInteger(r)||r<0)throw new i("varUint value must be a non-negative safe integer");let e=[],t=r;for(;t>=128;)e.push(t%128|128),t=Math.floor(t/128);return e.push(t),Uint8Array.from(e)}function g(r,e){let t=0;for(let a of r)if(t+=a.byteLength,t>e)throw new i(`Frame exceeds ${e} bytes`);let s=new Uint8Array(t),n=0;for(let a of r)s.set(a,n),n+=a.byteLength;return s}function we(r){let e=new TextEncoder().encode(r);return [A(e.byteLength),e]}function S(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)}function q(r){if(!S(r))throw new i("Awareness cell must be an object");let{row:e,col:t}=r;if(!Number.isSafeInteger(e)||!Number.isSafeInteger(t)||e<0||t<0)throw new i("Awareness cell coordinates must be non-negative safe integers");return {row:e,col:t}}function J(r,e){if(r===null)return null;if(!S(r)||!S(r.user))throw new i("Awareness state must contain a user");let{name:t,color:s}=r.user;if(typeof t!="string"||t.length===0||t.length>128)throw new i(`Awareness user name must contain 1 to ${128} characters`);let n=E(s,e),a=r.cursor;if(a==null)return {user:{name:t,color:n},cursor:null};if(!S(a)||typeof a.sheet!="string")throw new i("Awareness cursor must contain a sheet identifier");if(a.sheet.length===0||a.sheet.length>256)throw new i(`Awareness sheet identifier must contain 1 to ${256} characters`);return {user:{name:t,color:n},cursor:{sheet:a.sheet,anchor:q(a.anchor),head:q(a.head)}}}function N(r,e,t){return g([A(H),A(r),A(e.byteLength),e],t)}function Q(r,e=w){return N(z,r,e)}function Z(r,e=w){return N(K,r,e)}function ee(r,e=w){return N(j,r,e)}function te(r,e=w){if(r.length>b)throw new i(`Awareness update exceeds ${b} states`);let t=[A(r.length)];for(let n of r){if(!Number.isSafeInteger(n.clientId)||n.clientId<=0)throw new i("Awareness clientId must be a positive safe integer");if(!Number.isSafeInteger(n.clock)||n.clock<0)throw new i("Awareness clock must be a non-negative safe integer");let a=J(n.state,n.clientId);t.push(A(n.clientId),A(n.clock),...we(JSON.stringify(a)));}let s=g(t,e);return g([A(G),A(s.byteLength),s],e)}function re(r=w){return g([A(Y)],r)}function se(r,e=b,t){if(!(r instanceof Uint8Array))throw new i("Awareness update must be a Uint8Array");if(!Number.isSafeInteger(e)||e<1)throw new i("Awareness state limit must be a positive integer");let s=new C(r),n=s.readVarUint();if(n>e){let l=new i(`Awareness update exceeds ${e} states`);if(!t)throw l;t(l);}let a=[],c=Math.min(n,e);for(let l=0;l<c;l++){let p,d,m;try{p=s.readVarUint(),d=s.readVarUint(),m=s.readVarString();}catch(f){if(!t)throw f;return t(new i(`Awareness entry ${l+1} could not be decoded: ${f instanceof Error?f.message:"Unknown error"}`)),a}try{if(p<=0)throw new i("Awareness clientId must be a positive safe integer");let f=JSON.parse(m);a.push({clientId:p,clock:d,state:J(f,p)});}catch(f){let D=f instanceof i?f:new i(`Invalid awareness JSON${f instanceof Error?`: ${f.message}`:""}`);if(!t)throw D;t(new i(`Awareness entry ${l+1} discarded: ${D.message}`));}}if(n<=e&&!s.done){let l=new i("Trailing awareness update data");if(!t)throw l;t(l);}return a}function ne(r,e=w,t=F){if(!(r instanceof Uint8Array))throw new i("Frame must be a Uint8Array");if(r.byteLength===0)throw new i("Frame is empty");if(r.byteLength>e)throw new i(`Frame exceeds ${e} bytes`);if(!Number.isSafeInteger(t)||t<1)throw new i("Message limit must be a positive integer");let s=new C(r),n=[];for(;!s.done;){if(n.length>=t)throw new i(`Frame exceeds ${t} messages`);let a=s.readVarUint();switch(a){case H:{let c=s.readVarUint(),l=s.readVarUint8Array();if(c===z)n.push({type:"sync-step-1",stateVector:l});else if(c===K)n.push({type:"sync-step-2",update:l});else if(c===j)n.push({type:"update",update:l});else throw new i(`Unknown sync message type ${c}`);break}case G:n.push({type:"awareness",update:s.readVarUint8Array()});break;case de:{let c=s.readVarUint();if(c!==fe)throw new i(`Unknown auth message type ${c}`);n.push({type:"auth",reason:s.readVarString()});break}case Y:n.push({type:"query-awareness"});break;default:throw new i(`Unknown top-level message type ${a}`)}}return n}var h=class extends Error{constructor(t,s,n){super(s);a(this,"code");a(this,"cause");this.name="CollaborationError",this.code=t,this.cause=n;}};var ye=w,be=1e3;function O(r,e,t){if(!Number.isSafeInteger(e)||e<(t?0:1))throw new RangeError(`${r} must be ${t?"a non-negative":"a positive"} integer`);return e}function me(r){return r instanceof Error&&r.message?r.message:typeof r=="string"&&r?r:"Unknown error"}function u(r,e,t){return t instanceof h?t:new h(r,`${e}: ${me(t)}`,t)}function I(r,e){if(!(r instanceof Uint8Array))throw new TypeError(`${e} must return a Uint8Array`);return r.slice()}function B(r){r.unref?.();}function ae(r){return !!r&&Number.isSafeInteger(r.row)&&r.row>=0&&Number.isSafeInteger(r.col)&&r.col>=0}function Ee(r){return typeof r.sheet=="string"&&r.sheet.length>0&&r.sheet.length<=256&&ae(r.anchor)&&ae(r.head)}var k=class{constructor(e,t,s={}){a(this,"replica");a(this,"transport");a(this,"maxFrameBytes");a(this,"maxMessagesPerFrame");a(this,"maxPendingBytes");a(this,"statusListeners",new Map);a(this,"errorListeners",new Map);a(this,"awarenessListeners",new Map);a(this,"awarenessStore",new Map);a(this,"awarenessUser");a(this,"pendingFrames",[]);a(this,"unsubscribeReplica");a(this,"unsubscribeTransport",()=>{});a(this,"hasTransportSubscription",false);a(this,"connectionStatus","disconnected");a(this,"isSynced",false);a(this,"wantsConnection",false);a(this,"isOpen",false);a(this,"isDestroyed",false);a(this,"epoch",0);a(this,"connectAttempt",0);a(this,"nextListenerId",0);a(this,"queuedBytes",0);a(this,"isFlushing",false);a(this,"transportCleanup");a(this,"statusRevision",0);a(this,"awarenessClock",0);a(this,"reportedClockExhaustion",false);a(this,"awarenessCursor",null);a(this,"lastAwarenessSentAt",Number.NEGATIVE_INFINITY);a(this,"awarenessBroadcastTimer");a(this,"awarenessHeartbeatTimer");a(this,"awarenessExpiryTimer");a(this,"hasPublishedAwarenessForOpen",false);this.replica=e,this.transport=t,this.maxFrameBytes=O("maxFrameBytes",s.maxFrameBytes??w,false),this.maxMessagesPerFrame=O("maxMessagesPerFrame",s.maxMessagesPerFrame??F,false),this.maxPendingBytes=O("maxPendingBytes",s.maxPendingBytes??ye,true),this.awarenessUser=P(s.user,e.clientId);try{this.unsubscribeReplica=e.onUpdate((n,a)=>{a==="local"&&this.forwardLocalUpdate(n);});}catch(n){throw u("replica","Failed to observe replica updates",n)}}get status(){return this.connectionStatus}get synced(){return this.isSynced}get pendingBytes(){return this.queuedBytes}get peers(){return M(this.awarenessStore)}connect(){this.isDestroyed||this.isOpen||this.connectionStatus==="connecting"||(this.wantsConnection=true,this.setStatus("connecting",false),!(this.transportCleanup||this.isDestroyed||!this.wantsConnection)&&this.startConnection());}startConnection(){if(this.isDestroyed||!this.wantsConnection||this.isOpen||this.transportCleanup)return;let e=this.hasTransportSubscription?this.epoch:++this.epoch,t=++this.connectAttempt;if(this.setStatus("connecting",false),!!this.isCurrent(e)){if(!this.hasTransportSubscription){let s;try{if(s=this.transport.onEvent(n=>this.handleTransportEvent(e,n)),typeof s!="function")throw new TypeError("Transport event subscription must return a function")}catch(n){this.failConnection(e,u("transport","Failed to subscribe to transport events",n));return}if(!this.isCurrent(e)){try{s();}catch(n){this.isDestroyed||this.report(u("transport","Failed to unsubscribe from stale transport events",n));}return}this.unsubscribeTransport=s,this.hasTransportSubscription=true;}try{let s=this.transport.connect();s&&s.catch(n=>{this.isCurrent(e)&&this.connectAttempt===t&&this.failConnection(e,u("transport","Transport connect failed",n));});}catch(s){this.failConnection(e,u("transport","Transport connect failed",s));}}}disconnect(){if(this.isDestroyed||!(this.wantsConnection||this.isOpen||this.hasTransportSubscription||this.connectionStatus!=="disconnected"))return;this.clearPending(),this.publishAwareness(null,"best-effort"),this.stopAwarenessTimers(),this.clearAwarenessPeers(),this.hasPublishedAwarenessForOpen=false,this.wantsConnection=false,this.isOpen=false,this.epoch+=1,this.connectAttempt+=1;let t=this.takeTransportSubscription(),s=this.cleanupTransport(t,true);this.setStatus("disconnected",false);for(let n of s)this.report(n);}destroy(){if(this.isDestroyed)return;let e=this.wantsConnection||this.isOpen||this.hasTransportSubscription||this.connectionStatus==="connecting"||this.connectionStatus==="connected";this.clearPending(),this.publishAwareness(null,"best-effort"),this.stopAwarenessTimers(),this.clearAwarenessPeers(),this.hasPublishedAwarenessForOpen=false,this.isDestroyed=true,this.wantsConnection=false,this.isOpen=false,this.epoch+=1,this.connectAttempt+=1;let t=this.takeTransportSubscription(),s=this.cleanupTransport(t,e);this.setStatus("destroyed",false);for(let n of s)this.report(n);try{this.unsubscribeReplica();}catch(n){this.report(u("replica","Failed to unsubscribe from replica updates",n));}this.unsubscribeReplica=()=>{},this.statusListeners.clear(),this.errorListeners.clear(),this.awarenessListeners.clear();}onStatus(e){if(this.isDestroyed)return ()=>{};if(typeof e!="function")throw new TypeError("status listener must be a function");let t=this.nextListenerId++;return this.statusListeners.set(t,e),()=>this.statusListeners.delete(t)}onError(e){if(this.isDestroyed)return ()=>{};if(typeof e!="function")throw new TypeError("error listener must be a function");let t=this.nextListenerId++;return this.errorListeners.set(t,e),()=>this.errorListeners.delete(t)}onAwareness(e){if(this.isDestroyed)return ()=>{};if(typeof e!="function")throw new TypeError("awareness listener must be a function");let t=this.nextListenerId++;this.awarenessListeners.set(t,e);try{e(this.peers);}catch{}return ()=>this.awarenessListeners.delete(t)}setCursor(e){if(this.isDestroyed)return;let t=e?Ee(e):false;if(this.awarenessCursor=e&&t?{sheet:e.sheet,anchor:{...e.anchor},head:{...e.head}}:null,e&&!t&&this.report(new h("protocol",`Awareness cursor needs a sheet identifier of 1 to ${256} characters and non-negative cell coordinates; cursor dropped`)),!this.isOpen||!this.wantsConnection)return;let s=80-(Date.now()-this.lastAwarenessSentAt);if(s<=0){this.publishAwareness();return}this.awarenessBroadcastTimer||(this.awarenessBroadcastTimer=setTimeout(()=>{this.awarenessBroadcastTimer=void 0,this.publishAwareness();},s),B(this.awarenessBroadcastTimer));}isCurrent(e){return !this.isDestroyed&&this.wantsConnection&&e===this.epoch}failConnection(e,t){if(!this.isCurrent(e))return;this.stopAwarenessTimers(),this.clearAwarenessPeers(),this.hasPublishedAwarenessForOpen=false,this.wantsConnection=false,this.isOpen=false,this.epoch+=1,this.connectAttempt+=1;let s=this.takeTransportSubscription();this.clearPending();let n=this.cleanupTransport(s,true);this.setStatus("disconnected",false),this.report(t);for(let a of n)this.report(a);}takeTransportSubscription(){let e=this.unsubscribeTransport;return this.unsubscribeTransport=()=>{},this.hasTransportSubscription=false,e}cleanupTransport(e,t){let s=[];try{e();}catch(n){s.push(u("transport","Failed to unsubscribe from transport events",n));}if(!t||this.transportCleanup)return s;try{let n=this.transport.disconnect();if(n){let a=!1,c=Promise.resolve(n).catch(l=>{a=!0,this.isDestroyed||this.report(u("transport","Transport disconnect failed",l));}).finally(()=>{this.transportCleanup===c&&(this.transportCleanup=void 0,!this.isDestroyed&&(a?(this.wantsConnection=!1,this.setStatus("disconnected",!1)):this.wantsConnection&&this.startConnection()));});this.transportCleanup=c;}}catch(n){s.push(u("transport","Transport disconnect failed",n));}return s}handleTransportEvent(e,t){if(this.isCurrent(e))switch(t.type){case "open":this.handleOpen(e);break;case "message":this.isOpen&&this.handleMessage(e,t.data);break;case "close":this.stopAwarenessTimers(),this.clearAwarenessPeers(),this.hasPublishedAwarenessForOpen=false,this.isOpen=false,this.connectAttempt+=1,this.clearPending(),this.setStatus("disconnected",false);break;case "error":this.failConnection(e,u("transport","Transport error",t.error));break;case "drain":this.isOpen&&this.flushPending();break;default:this.failConnection(e,new h("transport","Unknown transport event"));}}handleOpen(e){if(this.isOpen||(this.isOpen=true,this.hasPublishedAwarenessForOpen=false,this.clearPending(),this.setStatus("connected",false),!this.isCurrent(e)||!this.isOpen))return;let t;try{t=I(this.replica.encodeStateVector(),"encodeStateVector");}catch(s){this.failConnection(e,u("replica","Failed to encode replica state vector",s));return}try{this.sendFrame(Q(t,this.maxFrameBytes));}catch(s){this.failConnection(e,u("protocol","Failed to encode collaboration handshake",s));return}if(!(!this.isCurrent(e)||!this.isOpen)){try{this.sendFrame(re(this.maxFrameBytes));}catch(s){this.report(u("protocol","Failed to encode awareness query",s));}!this.isCurrent(e)||!this.isOpen||(this.hasPublishedAwarenessForOpen||this.publishAwareness(),!(!this.isCurrent(e)||!this.isOpen)&&this.startAwarenessTimers());}}handleMessage(e,t){let s;try{if(!(t instanceof Uint8Array))throw new TypeError("Frame must be a Uint8Array");if(t.byteLength>this.maxFrameBytes)throw new RangeError(`Frame exceeds ${this.maxFrameBytes} bytes`);s=ne(t,this.maxFrameBytes,this.maxMessagesPerFrame);}catch(n){this.failConnection(e,u("protocol","Invalid collaboration frame",n));return}for(let n of s){if(!this.isCurrent(e)||!this.isOpen)return;switch(n.type){case "sync-step-1":this.respondToSyncStep1(e,n.stateVector);break;case "sync-step-2":this.applyRemoteUpdate(e,n.update)&&this.isCurrent(e)&&this.setStatus("connected",true);break;case "update":this.applyRemoteUpdate(e,n.update);break;case "awareness":try{let a=[],c=0,l=R(this.awarenessStore,se(n.update,b,p=>a.push(p)),this.replica.clientId,Date.now(),{onPeersDiscarded:p=>{c=p;}});for(let p of a)this.report(u("protocol","Invalid awareness update",p));if(c>0&&this.report(new h("protocol",`${c} awareness ${c===1?"entry was":"entries were"} discarded because the tracked peer limit of ${1024} was reached`)),!this.isCurrent(e)||!this.isOpen)return;l&&this.emitAwareness();}catch(a){this.report(u("protocol","Invalid awareness update",a));}break;case "auth":this.failConnection(e,new h("protocol",n.reason?`Authentication denied: ${n.reason}`:"Authentication denied"));return;case "query-awareness":this.publishAwareness();break}}}respondToSyncStep1(e,t){let s;try{s=I(this.replica.encodeStateAsUpdate(t.slice()),"encodeStateAsUpdate");}catch(n){this.failConnection(e,u("replica","Failed to encode replica update",n));return}try{this.sendFrame(Z(s,this.maxFrameBytes));}catch(n){this.failConnection(e,u("protocol","Failed to encode SyncStep2",n));}}applyRemoteUpdate(e,t){try{return this.replica.applyUpdate(t.slice()),!0}catch(s){return this.failConnection(e,u("replica","Failed to apply remote update",s)),false}}forwardLocalUpdate(e){if(this.isDestroyed||!this.isOpen||!this.wantsConnection)return;let t=this.epoch,s;try{s=I(e,"Replica update");}catch(n){this.failConnection(t,u("replica","Invalid replica update",n));return}try{this.sendFrame(ee(s,this.maxFrameBytes));}catch(n){this.failConnection(t,u("protocol","Failed to encode update",n));}}publishAwareness(e="current",t="queued"){if(!(!this.isOpen||this.isDestroyed||!this.wantsConnection)){if(this.awarenessBroadcastTimer&&(clearTimeout(this.awarenessBroadcastTimer),this.awarenessBroadcastTimer=void 0),this.awarenessClock>=Number.MAX_SAFE_INTEGER){t==="queued"&&!this.reportedClockExhaustion&&(this.reportedClockExhaustion=true,this.report(new h("protocol","Awareness clock exhausted")));return}this.awarenessClock+=1;try{this.hasPublishedAwarenessForOpen=!0;let s=te([{clientId:this.replica.clientId,clock:this.awarenessClock,state:e===null?null:{user:this.awarenessUser,cursor:this.awarenessCursor}}],this.maxFrameBytes);t==="best-effort"?this.sendBestEffort(s):this.sendFrame(s),this.lastAwarenessSentAt=Date.now();}catch(s){t==="queued"&&this.report(u("protocol","Failed to encode awareness update",s));}}}startAwarenessTimers(){this.stopAwarenessTimers(),this.awarenessHeartbeatTimer=setInterval(()=>{this.publishAwareness();},2e4),this.awarenessExpiryTimer=setInterval(()=>{L(this.awarenessStore,Date.now(),45e3)&&this.emitAwareness();},be),B(this.awarenessHeartbeatTimer),B(this.awarenessExpiryTimer);}stopAwarenessTimers(){this.awarenessBroadcastTimer&&clearTimeout(this.awarenessBroadcastTimer),this.awarenessHeartbeatTimer&&clearInterval(this.awarenessHeartbeatTimer),this.awarenessExpiryTimer&&clearInterval(this.awarenessExpiryTimer),this.awarenessBroadcastTimer=void 0,this.awarenessHeartbeatTimer=void 0,this.awarenessExpiryTimer=void 0;}clearAwarenessPeers(){if(this.awarenessStore.size===0)return;let e=this.peers.length>0;this.awarenessStore.clear(),e&&this.emitAwareness();}emitAwareness(){let e=this.peers;for(let[t,s]of [...this.awarenessListeners])if(this.awarenessListeners.get(t)===s)try{s(e);}catch{}}sendFrame(e){if(!this.isOpen||this.isDestroyed||!this.wantsConnection)return;let t=this.epoch;if(this.pendingFrames.length>0){this.queueFrame(t,e);return}let s;try{s=this.transport.send(e.slice());}catch(n){this.failConnection(t,u("transport","Transport send failed",n));return}if(typeof s!="boolean"){this.failConnection(t,new h("transport","Transport send must return a boolean"));return}!s&&this.isCurrent(t)&&this.isOpen&&this.queueFrame(t,e);}sendBestEffort(e){try{this.transport.send(e.slice());}catch{}}queueFrame(e,t){if(t.byteLength>this.maxPendingBytes-this.queuedBytes){this.failConnection(e,new h("backpressure",`Pending collaboration data exceeds ${this.maxPendingBytes} bytes`));return}let s=t.slice();this.pendingFrames.push(s),this.queuedBytes+=s.byteLength;}flushPending(){if(!this.isFlushing){this.isFlushing=true;try{for(;this.isOpen&&!this.isDestroyed&&this.pendingFrames.length>0;){let e=this.epoch,t=this.pendingFrames[0],s;try{s=this.transport.send(t.slice());}catch(n){this.failConnection(e,u("transport","Transport send failed",n));return}if(typeof s!="boolean"){this.failConnection(e,new h("transport","Transport send must return a boolean"));return}if(!s||!this.isOpen||this.pendingFrames[0]!==t)return;this.pendingFrames.shift(),this.queuedBytes-=t.byteLength;}}finally{this.isFlushing=false;}}}clearPending(){this.pendingFrames.length=0,this.queuedBytes=0;}setStatus(e,t){if(this.connectionStatus===e&&this.isSynced===t)return;this.connectionStatus=e,this.isSynced=t;let s=++this.statusRevision,n={status:e,synced:t};for(let[a,c]of [...this.statusListeners]){if(this.statusRevision!==s)return;if(this.statusListeners.get(a)===c)try{c(n);}catch{}}}report(e){for(let[t,s]of [...this.errorListeners])if(this.errorListeners.get(t)===s)try{s(e);}catch{}}};export{v as AWARENESS_BROADCAST_INTERVAL_MS,T as AWARENESS_COLORS,U as AWARENESS_HEARTBEAT_INTERVAL_MS,oe as AWARENESS_LABEL_DURATION_MS,_ as AWARENESS_PEER_TIMEOUT_MS,h as CollaborationError,k as CollaborationProvider,x as MAX_TRACKED_AWARENESS_PEERS,ce as XLSX_MAX_COLUMNS,ie as XLSX_MAX_ROWS,R as applyAwarenessUpdates,M as awarenessPeers,$ as colorForClientId,L as expireAwarenessPeers,E as normalizeAwarenessColor,P as normalizeCollaborationUser,pe as resolveAwarenessCursor};
|
|
Binary file
|
package/dist/headless.d.ts
CHANGED
|
@@ -75,8 +75,15 @@ interface TextCmd {
|
|
|
75
75
|
italic?: boolean;
|
|
76
76
|
underline?: boolean;
|
|
77
77
|
strike?: boolean;
|
|
78
|
+
highlight?: string;
|
|
79
|
+
dashedUnderline?: boolean;
|
|
78
80
|
/** css/font family from the style font; the backend falls back to its default. */
|
|
79
81
|
fontFamily?: string;
|
|
82
|
+
/**
|
|
83
|
+
* Preview text that is not the cell's committed value (a proposal ghost's
|
|
84
|
+
* `new` text). Painted normally, but excluded from a11y text recovery.
|
|
85
|
+
*/
|
|
86
|
+
ghost?: boolean;
|
|
80
87
|
}
|
|
81
88
|
/**
|
|
82
89
|
* One draw command; discriminated on `op`.
|
|
@@ -96,9 +103,20 @@ type DrawCmd = FillRectCmd | LineCmd | TextCmd;
|
|
|
96
103
|
interface GridMeta {
|
|
97
104
|
startRow: number;
|
|
98
105
|
startCol: number;
|
|
106
|
+
rowIndices?: number[];
|
|
107
|
+
colIndices?: number[];
|
|
99
108
|
rowOffsets: number[];
|
|
100
109
|
colOffsets: number[];
|
|
101
110
|
}
|
|
111
|
+
interface HyperlinkRegion {
|
|
112
|
+
top: number;
|
|
113
|
+
left: number;
|
|
114
|
+
bottom: number;
|
|
115
|
+
right: number;
|
|
116
|
+
externalTarget?: string;
|
|
117
|
+
location?: string;
|
|
118
|
+
tooltip?: string;
|
|
119
|
+
}
|
|
102
120
|
/**
|
|
103
121
|
* A full frame to paint: logical size plus the ordered command stream. `grid`
|
|
104
122
|
* is optional so a synthetic or pre-grid-metadata frame still type-checks; the
|
|
@@ -109,6 +127,7 @@ interface DisplayList {
|
|
|
109
127
|
height: number;
|
|
110
128
|
commands: DrawCmd[];
|
|
111
129
|
grid?: GridMeta;
|
|
130
|
+
hyperlinks?: HyperlinkRegion[];
|
|
112
131
|
}
|
|
113
132
|
|
|
114
133
|
/**
|
|
@@ -345,6 +364,15 @@ declare function cellRect(grid: GridMeta | undefined, row: number, col: number):
|
|
|
345
364
|
*/
|
|
346
365
|
declare function rangeRect(grid: GridMeta | undefined, range: CellRange): Rect | null;
|
|
347
366
|
|
|
367
|
+
interface HyperlinkDestination {
|
|
368
|
+
sheetName: string;
|
|
369
|
+
row: number;
|
|
370
|
+
col: number;
|
|
371
|
+
}
|
|
372
|
+
declare function hyperlinkAtCell(displayList: DisplayList, row: number, col: number): HyperlinkRegion | null;
|
|
373
|
+
declare function safeExternalHyperlink(link: HyperlinkRegion): string | null;
|
|
374
|
+
declare function parseHyperlinkLocation(location: string, currentSheet: string): HyperlinkDestination | null;
|
|
375
|
+
|
|
348
376
|
/**
|
|
349
377
|
* Pure TSV codec for clipboard interchange, in the Excel dialect (tab-separated
|
|
350
378
|
* fields, CRLF rows, `"`-quoted fields with doubled embedded quotes). No DOM —
|
|
@@ -455,4 +483,4 @@ interface A11yGrid {
|
|
|
455
483
|
*/
|
|
456
484
|
declare function buildA11yGrid(displayList: DisplayList, selection: Selection | null, sheetName: string, t: A11yStrings): A11yGrid;
|
|
457
485
|
|
|
458
|
-
export { type A11yCell, type A11yColumnHeader, type A11yGrid, type A11yRow, type A11yStrings, type CellAddr, type CellInput, type CellRange, type Direction, type DisplayList, type DrawCmd, type FillRectCmd, type GridMeta, type KeyInput, type LineCmd, type MoveOpts, type Rect, type Selection, type SelectionAction, type SelectionLimits, type TextAlign, type TextCmd, type TrackOffsets, type ViewportState, type VisibleCells, type VisibleRange, buildA11yGrid, cellAtPoint, cellCount, cellRect, clampScroll, extendTo, fromTsv, moveFocus, normalizeRange, rangeContains, rangeRect, selectionAt, selectionKeyReducer, toTsv, totalExtent, trackCount, uniformOffsets, visibleCells, visibleRange };
|
|
486
|
+
export { type A11yCell, type A11yColumnHeader, type A11yGrid, type A11yRow, type A11yStrings, type CellAddr, type CellInput, type CellRange, type Direction, type DisplayList, type DrawCmd, type FillRectCmd, type GridMeta, type HyperlinkDestination, type HyperlinkRegion, type KeyInput, type LineCmd, type MoveOpts, type Rect, type Selection, type SelectionAction, type SelectionLimits, type TextAlign, type TextCmd, type TrackOffsets, type ViewportState, type VisibleCells, type VisibleRange, buildA11yGrid, cellAtPoint, cellCount, cellRect, clampScroll, extendTo, fromTsv, hyperlinkAtCell, moveFocus, normalizeRange, parseHyperlinkLocation, rangeContains, rangeRect, safeExternalHyperlink, selectionAt, selectionKeyReducer, toTsv, totalExtent, trackCount, uniformOffsets, visibleCells, visibleRange };
|
package/dist/headless.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{
|
|
1
|
+
export{v as buildA11yGrid,n as cellAtPoint,j as cellCount,o as cellRect,e as clampScroll,k as extendTo,u as fromTsv,q as hyperlinkAtCell,l as moveFocus,h as normalizeRange,s as parseHyperlinkLocation,i as rangeContains,p as rangeRect,r as safeExternalHyperlink,g as selectionAt,m as selectionKeyReducer,t as toTsv,b as totalExtent,a as trackCount,f as uniformOffsets,d as visibleCells,c as visibleRange}from'./chunk-4LMGHPXC.js';import'./chunk-O2XFH626.js';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DisplayList } from './headless.js';
|
|
2
|
-
export { A11yCell, A11yColumnHeader, A11yGrid, A11yRow, A11yStrings, CellAddr, CellInput, CellRange, Direction, DrawCmd, FillRectCmd, GridMeta, KeyInput, LineCmd, MoveOpts, Rect, Selection, SelectionAction, SelectionLimits, TextAlign, TextCmd, TrackOffsets, ViewportState, VisibleCells, VisibleRange, buildA11yGrid, cellAtPoint, cellCount, cellRect, clampScroll, extendTo, fromTsv, moveFocus, normalizeRange, rangeContains, rangeRect, selectionAt, selectionKeyReducer, toTsv, totalExtent, trackCount, uniformOffsets, visibleCells, visibleRange } from './headless.js';
|
|
3
|
-
import { C as CollaborationReplica,
|
|
2
|
+
export { A11yCell, A11yColumnHeader, A11yGrid, A11yRow, A11yStrings, CellAddr, CellInput, CellRange, Direction, DrawCmd, FillRectCmd, GridMeta, HyperlinkDestination, HyperlinkRegion, KeyInput, LineCmd, MoveOpts, Rect, Selection, SelectionAction, SelectionLimits, TextAlign, TextCmd, TrackOffsets, ViewportState, VisibleCells, VisibleRange, buildA11yGrid, cellAtPoint, cellCount, cellRect, clampScroll, extendTo, fromTsv, hyperlinkAtCell, moveFocus, normalizeRange, parseHyperlinkLocation, rangeContains, rangeRect, safeExternalHyperlink, selectionAt, selectionKeyReducer, toTsv, totalExtent, trackCount, uniformOffsets, visibleCells, visibleRange } from './headless.js';
|
|
3
|
+
import { C as CollaborationReplica, s as CollaborationUpdateOrigin } from './types-C24EBcAP.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Canvas2D backend for the display list — the browser paint target.
|
|
@@ -29,8 +29,8 @@ type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Modul
|
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
* A scrolled window into a sheet
|
|
33
|
-
*
|
|
32
|
+
* A scrolled window into a sheet. `x`/`y` are content-pixel offsets into the
|
|
33
|
+
* non-frozen body. Mirrors the Rust `Viewport`.
|
|
34
34
|
*/
|
|
35
35
|
interface Viewport {
|
|
36
36
|
x: number;
|
|
@@ -39,14 +39,23 @@ interface Viewport {
|
|
|
39
39
|
height: number;
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
|
-
* Chrome-facing sheet metadata: tab names, active index, and the
|
|
43
|
-
* content extent of the active sheet. Mirrors the Rust `SheetInfo`.
|
|
42
|
+
* Chrome-facing sheet metadata: stable IDs, tab names, active index, and the
|
|
43
|
+
* scrollable content extent of the active sheet. Mirrors the Rust `SheetInfo`.
|
|
44
44
|
*/
|
|
45
45
|
interface SheetInfo {
|
|
46
|
+
sheetIds: string[];
|
|
46
47
|
sheetNames: string[];
|
|
47
48
|
activeSheet: number;
|
|
48
49
|
contentWidth: number;
|
|
49
50
|
contentHeight: number;
|
|
51
|
+
frozenRows: number;
|
|
52
|
+
frozenCols: number;
|
|
53
|
+
initialScrollX: number;
|
|
54
|
+
initialScrollY: number;
|
|
55
|
+
}
|
|
56
|
+
interface CellPosition {
|
|
57
|
+
x: number;
|
|
58
|
+
y: number;
|
|
50
59
|
}
|
|
51
60
|
/**
|
|
52
61
|
* Result of any mutating call: whether it changed the workbook and the
|
|
@@ -66,6 +75,72 @@ interface EditResult {
|
|
|
66
75
|
interface CalculationStatus {
|
|
67
76
|
limitedCells: string[];
|
|
68
77
|
}
|
|
78
|
+
type NumberFormat = 'automatic' | 'plainText' | 'number' | 'percent' | 'scientific' | 'currency' | 'date' | 'time' | 'custom';
|
|
79
|
+
type BorderPreset = 'all' | 'inner' | 'horizontal' | 'vertical' | 'outer' | 'left' | 'top' | 'right' | 'bottom' | 'none';
|
|
80
|
+
type BorderStyle = 'solid' | 'dashed' | 'dotted' | 'double';
|
|
81
|
+
type HorizontalAlignment = 'left' | 'center' | 'right';
|
|
82
|
+
type VerticalAlignment = 'top' | 'middle' | 'bottom';
|
|
83
|
+
type TextWrapping = 'overflow' | 'wrap' | 'clip';
|
|
84
|
+
type StyleProperty = 'bold' | 'italic' | 'strikethrough' | 'fontFamily' | 'fontSize' | 'textColor' | 'fillColor' | 'borders' | 'horizontalAlignment' | 'verticalAlignment' | 'textWrapping';
|
|
85
|
+
interface BorderPatch {
|
|
86
|
+
preset?: BorderPreset;
|
|
87
|
+
style?: BorderStyle;
|
|
88
|
+
color?: string;
|
|
89
|
+
}
|
|
90
|
+
interface RangeStylePatch {
|
|
91
|
+
bold?: boolean;
|
|
92
|
+
italic?: boolean;
|
|
93
|
+
strikethrough?: boolean;
|
|
94
|
+
fontFamily?: string;
|
|
95
|
+
fontSize?: number;
|
|
96
|
+
textColor?: string;
|
|
97
|
+
fillColor?: string;
|
|
98
|
+
border?: BorderPatch;
|
|
99
|
+
horizontalAlignment?: HorizontalAlignment;
|
|
100
|
+
verticalAlignment?: VerticalAlignment;
|
|
101
|
+
textWrapping?: TextWrapping;
|
|
102
|
+
clear?: StyleProperty[];
|
|
103
|
+
}
|
|
104
|
+
type NumberFormatMutation = Exclude<NumberFormat, 'custom'> | 'increaseDecimal' | 'decreaseDecimal' | {
|
|
105
|
+
type: 'custom';
|
|
106
|
+
pattern: string;
|
|
107
|
+
};
|
|
108
|
+
interface SelectionFormatting {
|
|
109
|
+
numberFormat?: NumberFormat;
|
|
110
|
+
numberFormatPattern?: string;
|
|
111
|
+
fontFamily?: string;
|
|
112
|
+
fontSize?: number;
|
|
113
|
+
bold?: boolean;
|
|
114
|
+
italic?: boolean;
|
|
115
|
+
strikethrough?: boolean;
|
|
116
|
+
textColor?: string;
|
|
117
|
+
fillColor?: string;
|
|
118
|
+
borderPreset?: BorderPreset;
|
|
119
|
+
borderStyle?: BorderStyle;
|
|
120
|
+
borderColor?: string;
|
|
121
|
+
horizontalAlignment?: HorizontalAlignment;
|
|
122
|
+
verticalAlignment?: VerticalAlignment;
|
|
123
|
+
textWrapping?: TextWrapping;
|
|
124
|
+
}
|
|
125
|
+
interface CapturedFormat {
|
|
126
|
+
rows: number;
|
|
127
|
+
columns: number;
|
|
128
|
+
formats: unknown[];
|
|
129
|
+
}
|
|
130
|
+
interface CellPoint {
|
|
131
|
+
row: number;
|
|
132
|
+
col: number;
|
|
133
|
+
}
|
|
134
|
+
interface MergedRange {
|
|
135
|
+
start: CellPoint;
|
|
136
|
+
end: CellPoint;
|
|
137
|
+
}
|
|
138
|
+
interface HistoryState {
|
|
139
|
+
canUndo: boolean;
|
|
140
|
+
canRedo: boolean;
|
|
141
|
+
undoDepth: number;
|
|
142
|
+
redoDepth: number;
|
|
143
|
+
}
|
|
69
144
|
type WorkbookUpdateOrigin = CollaborationUpdateOrigin;
|
|
70
145
|
type WorkbookUpdateListener = (update: Uint8Array, origin: WorkbookUpdateOrigin) => void;
|
|
71
146
|
interface OpenWorkbookOptions {
|
|
@@ -97,6 +172,7 @@ interface CellInputEdit {
|
|
|
97
172
|
*/
|
|
98
173
|
interface ProposalEdit extends CellInputEdit {
|
|
99
174
|
sheet: number;
|
|
175
|
+
numberFormat?: NumberFormatMutation;
|
|
100
176
|
}
|
|
101
177
|
/**
|
|
102
178
|
* One cell of a pending proposal: where it lands and the *formatted display
|
|
@@ -165,8 +241,16 @@ interface WorkbookHandle extends CollaborationReplica {
|
|
|
165
241
|
redo(): EditResult;
|
|
166
242
|
/** the editable view of one cell (formula bar / in-cell editor prefill). */
|
|
167
243
|
cell(sheet: number, row: number, col: number): CellEdit;
|
|
244
|
+
cellPosition(sheet: number, row: number, col: number): CellPosition;
|
|
168
245
|
/** row-major editable views for a range, e.g. "A1:C3" (clipboard copy). */
|
|
169
246
|
rangeCells(sheet: number, range: string): CellEdit[][];
|
|
247
|
+
patchRangeStyle(sheet: number, range: string, patch: RangeStylePatch): EditResult;
|
|
248
|
+
setNumberFormat(sheet: number, range: string, format: NumberFormatMutation): EditResult;
|
|
249
|
+
selectionFormatting(sheet: number, range: string): SelectionFormatting;
|
|
250
|
+
captureFormat(sheet: number, range: string): CapturedFormat;
|
|
251
|
+
applyFormat(sheet: number, range: string, format: CapturedFormat): EditResult;
|
|
252
|
+
mergedRanges(sheet: number, range: string): MergedRange[];
|
|
253
|
+
historyState(): HistoryState;
|
|
170
254
|
/**
|
|
171
255
|
* render the current sheet viewport to png bytes via the native raster
|
|
172
256
|
* backend — the same display list the canvas paints, rasterized server-side.
|
|
@@ -238,4 +322,4 @@ declare function openWorkbook(bytes: Uint8Array, options?: OpenWorkbookOptions):
|
|
|
238
322
|
*/
|
|
239
323
|
declare function wasmVersion(): string;
|
|
240
324
|
|
|
241
|
-
export { type CalculationStatus, type CellEdit, type CellInputEdit, DisplayList, type EditResult, type OpenWorkbookOptions, type Proposal, type ProposalCell, type ProposalEdit, type SheetInfo, StaleProposalError, type Viewport, type WasmInitInput, type WorkbookHandle, type WorkbookUpdateListener, type WorkbookUpdateOrigin, initWasm, isPngExportAvailable, isProposalsAvailable, isWasmAvailable, openWorkbook, paintDisplayList, wasmVersion };
|
|
325
|
+
export { type BorderPatch, type BorderPreset, type BorderStyle, type CalculationStatus, type CapturedFormat, type CellEdit, type CellInputEdit, type CellPoint, type CellPosition, DisplayList, type EditResult, type HistoryState, type HorizontalAlignment, type MergedRange, type NumberFormat, type NumberFormatMutation, type OpenWorkbookOptions, type Proposal, type ProposalCell, type ProposalEdit, type RangeStylePatch, type SelectionFormatting, type SheetInfo, StaleProposalError, type StyleProperty, type TextWrapping, type VerticalAlignment, type Viewport, type WasmInitInput, type WorkbookHandle, type WorkbookUpdateListener, type WorkbookUpdateOrigin, initWasm, isPngExportAvailable, isProposalsAvailable, isWasmAvailable, openWorkbook, paintDisplayList, wasmVersion };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{s as buildA11yGrid,n as cellAtPoint,j as cellCount,o as cellRect,e as clampScroll,k as extendTo,r as fromTsv,l as moveFocus,h as normalizeRange,i as rangeContains,p as rangeRect,g as selectionAt,m as selectionKeyReducer,q as toTsv,b as totalExtent,a as trackCount,f as uniformOffsets,d as visibleCells,c as visibleRange}from'./chunk-II4BZDSC.js';import {a}from'./chunk-O2XFH626.js';var ge={left:"left",center:"center",right:"right"},we={dashed:[4,2],dotted:[1,2]};function ye(r,e,t){r.save(),r.setTransform(t,0,0,t,0,0),r.clearRect(0,0,e.width,e.height);for(let n of e.commands)he(r,n);r.restore();}function he(r,e){switch(e.op){case "fillRect":r.fillStyle=e.color,r.fillRect(e.x,e.y,e.w,e.h);return;case "line":me(r,e);return;case "text":xe(r,e);return}}function me(r,e){if(r.strokeStyle=e.color,e.style==="double"){let t=Math.max(e.width*.8,.8),n=Math.abs(e.y1-e.y2)<=Math.abs(e.x1-e.x2),[o,s]=n?[0,t]:[t,0];r.lineWidth=Math.max(e.width*.6,.5),D(r,e.x1-o,e.y1-s,e.x2-o,e.y2-s),D(r,e.x1+o,e.y1+s,e.x2+o,e.y2+s);return}r.lineWidth=e.width,r.save(),r.setLineDash(e.style?we[e.style]:[]),D(r,e.x1,e.y1,e.x2,e.y2),r.restore();}function D(r,e,t,n,o){r.beginPath(),r.moveTo(e,t),r.lineTo(n,o),r.stroke();}function xe(r,e){r.save(),e.clip&&(r.beginPath(),r.rect(e.clip.x,e.clip.y,e.clip.w,e.clip.h),r.clip()),r.fillStyle=e.color,r.font=ve(e),r.textAlign=ge[e.align??"left"],r.textBaseline="alphabetic",r.fillText(e.text,e.x,e.y),(e.underline||e.strike)&&Ce(r,e),r.restore();}function ve(r){let e=r.italic?"italic ":"",t=r.bold?"bold ":"",n=r.fontFamily??"sans-serif";return `${e}${t}${r.fontSize}px ${n}`}function Ce(r,e){let t=r.measureText(e.text).width,n=e.align??"left",o=n==="right"?e.x-t:n==="center"?e.x-t/2:e.x,s=Math.max(e.fontSize*.05,.5);r.fillStyle=e.color,e.underline&&r.fillRect(o,e.y+e.fontSize*.1,t,s),e.strike&&r.fillRect(o,e.y-e.fontSize*.26,t,s);}var x=class r{static __wrap(e){let t=Object.create(r.prototype);return t.__wbg_ptr=e,M.register(t,t.__wbg_ptr,t),t}__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,M.unregister(this),e}free(){let e=this.__destroy_into_raw();i.__wbg_xlsxdocument_free(e,0);}acceptProposalJson(e){let t,n;try{let f=y(e,i.__wbindgen_malloc,i.__wbindgen_realloc),c=p,a=i.xlsxdocument_acceptProposalJson(this.__wbg_ptr,f,c);var o=a[0],s=a[1];if(a[3])throw o=0,s=0,_(a[2]);return t=o,n=s,b(o,s)}finally{i.__wbindgen_free(t,n,1);}}applyOpsJson(e){let t,n;try{let f=y(e,i.__wbindgen_malloc,i.__wbindgen_realloc),c=p,a=i.xlsxdocument_applyOpsJson(this.__wbg_ptr,f,c);var o=a[0],s=a[1];if(a[3])throw o=0,s=0,_(a[2]);return t=o,n=s,b(o,s)}finally{i.__wbindgen_free(t,n,1);}}applyUpdateJson(e){let t,n;try{let f=k(e,i.__wbindgen_malloc),c=p,a=i.xlsxdocument_applyUpdateJson(this.__wbg_ptr,f,c);var o=a[0],s=a[1];if(a[3])throw o=0,s=0,_(a[2]);return t=o,n=s,b(o,s)}finally{i.__wbindgen_free(t,n,1);}}calculationStatusJson(){let e,t;try{let s=i.xlsxdocument_calculationStatusJson(this.__wbg_ptr);var n=s[0],o=s[1];if(s[3])throw n=0,o=0,_(s[2]);return e=n,t=o,b(n,o)}finally{i.__wbindgen_free(e,t,1);}}cellJson(e){let t,n;try{let f=y(e,i.__wbindgen_malloc,i.__wbindgen_realloc),c=p,a=i.xlsxdocument_cellJson(this.__wbg_ptr,f,c);var o=a[0],s=a[1];if(a[3])throw o=0,s=0,_(a[2]);return t=o,n=s,b(o,s)}finally{i.__wbindgen_free(t,n,1);}}clearUpdateObservation(){i.xlsxdocument_clearUpdateObservation(this.__wbg_ptr);}get clientId(){return i.xlsxdocument_clientId(this.__wbg_ptr)}displayListJson(e){let t,n;try{let f=y(e,i.__wbindgen_malloc,i.__wbindgen_realloc),c=p,a=i.xlsxdocument_displayListJson(this.__wbg_ptr,f,c);var o=a[0],s=a[1];if(a[3])throw o=0,s=0,_(a[2]);return t=o,n=s,b(o,s)}finally{i.__wbindgen_free(t,n,1);}}drainUpdateEvent(){let e=i.xlsxdocument_drainUpdateEvent(this.__wbg_ptr);if(e[3])throw _(e[2]);var t=m(e[0],e[1]).slice();return i.__wbindgen_free(e[0],e[1]*1,1),t}editCellJson(e){let t,n;try{let f=y(e,i.__wbindgen_malloc,i.__wbindgen_realloc),c=p,a=i.xlsxdocument_editCellJson(this.__wbg_ptr,f,c);var o=a[0],s=a[1];if(a[3])throw o=0,s=0,_(a[2]);return t=o,n=s,b(o,s)}finally{i.__wbindgen_free(t,n,1);}}editCellsJson(e){let t,n;try{let f=y(e,i.__wbindgen_malloc,i.__wbindgen_realloc),c=p,a=i.xlsxdocument_editCellsJson(this.__wbg_ptr,f,c);var o=a[0],s=a[1];if(a[3])throw o=0,s=0,_(a[2]);return t=o,n=s,b(o,s)}finally{i.__wbindgen_free(t,n,1);}}encodeDiff(e){let t=k(e,i.__wbindgen_malloc),n=p,o=i.xlsxdocument_encodeDiff(this.__wbg_ptr,t,n);if(o[3])throw _(o[2]);var s=m(o[0],o[1]).slice();return i.__wbindgen_free(o[0],o[1]*1,1),s}encodeStateAsUpdate(){let e=i.xlsxdocument_encodeStateAsUpdate(this.__wbg_ptr);var t=m(e[0],e[1]).slice();return i.__wbindgen_free(e[0],e[1]*1,1),t}encodeStateVector(){let e=i.xlsxdocument_encodeStateVector(this.__wbg_ptr);var t=m(e[0],e[1]).slice();return i.__wbindgen_free(e[0],e[1]*1,1),t}listProposalsJson(){let e,t;try{let s=i.xlsxdocument_listProposalsJson(this.__wbg_ptr);var n=s[0],o=s[1];if(s[3])throw n=0,o=0,_(s[2]);return e=n,t=o,b(n,o)}finally{i.__wbindgen_free(e,t,1);}}static open(e){let t=k(e,i.__wbindgen_malloc),n=p,o=i.xlsxdocument_open(t,n);if(o[2])throw _(o[1]);return r.__wrap(o[0])}static openCollaborative(e,t){let n=k(e,i.__wbindgen_malloc),o=p,s=i.xlsxdocument_openCollaborative(n,o,t);if(s[2])throw _(s[1]);return r.__wrap(s[0])}proposeJson(e){let t,n;try{let f=y(e,i.__wbindgen_malloc,i.__wbindgen_realloc),c=p,a=i.xlsxdocument_proposeJson(this.__wbg_ptr,f,c);var o=a[0],s=a[1];if(a[3])throw o=0,s=0,_(a[2]);return t=o,n=s,b(o,s)}finally{i.__wbindgen_free(t,n,1);}}rangeCellsJson(e){let t,n;try{let f=y(e,i.__wbindgen_malloc,i.__wbindgen_realloc),c=p,a=i.xlsxdocument_rangeCellsJson(this.__wbg_ptr,f,c);var o=a[0],s=a[1];if(a[3])throw o=0,s=0,_(a[2]);return t=o,n=s,b(o,s)}finally{i.__wbindgen_free(t,n,1);}}redoJson(){let e,t;try{let s=i.xlsxdocument_redoJson(this.__wbg_ptr);var n=s[0],o=s[1];if(s[3])throw n=0,o=0,_(s[2]);return e=n,t=o,b(n,o)}finally{i.__wbindgen_free(e,t,1);}}rejectProposalJson(e){let t,n;try{let f=y(e,i.__wbindgen_malloc,i.__wbindgen_realloc),c=p,a=i.xlsxdocument_rejectProposalJson(this.__wbg_ptr,f,c);var o=a[0],s=a[1];if(a[3])throw o=0,s=0,_(a[2]);return t=o,n=s,b(o,s)}finally{i.__wbindgen_free(t,n,1);}}renderPng(e){let t=y(e,i.__wbindgen_malloc,i.__wbindgen_realloc),n=p,o=i.xlsxdocument_renderPng(this.__wbg_ptr,t,n);if(o[3])throw _(o[2]);var s=m(o[0],o[1]).slice();return i.__wbindgen_free(o[0],o[1]*1,1),s}renderRangePng(e){let t=y(e,i.__wbindgen_malloc,i.__wbindgen_realloc),n=p,o=i.xlsxdocument_renderRangePng(this.__wbg_ptr,t,n);if(o[3])throw _(o[2]);var s=m(o[0],o[1]).slice();return i.__wbindgen_free(o[0],o[1]*1,1),s}saveBytes(){let e=i.xlsxdocument_saveBytes(this.__wbg_ptr);if(e[3])throw _(e[2]);var t=m(e[0],e[1]).slice();return i.__wbindgen_free(e[0],e[1]*1,1),t}setActiveSheet(e){let t=i.xlsxdocument_setActiveSheet(this.__wbg_ptr,e);if(t[1])throw _(t[0])}sheetInfoJson(){let e,t;try{let s=i.xlsxdocument_sheetInfoJson(this.__wbg_ptr);var n=s[0],o=s[1];if(s[3])throw n=0,o=0,_(s[2]);return e=n,t=o,b(n,o)}finally{i.__wbindgen_free(e,t,1);}}startUpdateObservation(){let e=i.xlsxdocument_startUpdateObservation(this.__wbg_ptr);if(e[1])throw _(e[0])}undoJson(){let e,t;try{let s=i.xlsxdocument_undoJson(this.__wbg_ptr);var n=s[0],o=s[1];if(s[3])throw n=0,o=0,_(s[2]);return e=n,t=o,b(n,o)}finally{i.__wbindgen_free(e,t,1);}}static version(){let e,t;try{let n=i.xlsxdocument_version();return e=n[0],t=n[1],b(n[0],n[1])}finally{i.__wbindgen_free(e,t,1);}}};Symbol.dispose&&(x.prototype[Symbol.dispose]=x.prototype.free);function Se(){return {__proto__:null,"./xlsx_wasm_bg.js":{__proto__:null,__wbg___wbindgen_string_get_b0ca35b86a603356:function(e,t){let n=t,o=typeof n=="string"?n:void 0;var s=Ee(o)?0:y(o,i.__wbindgen_malloc,i.__wbindgen_realloc),f=p;F().setInt32(e+4,f,true),F().setInt32(e+0,s,true);},__wbg___wbindgen_throw_344f42d3211c4765:function(e,t){throw new Error(b(e,t))},__wbg_getRandomValues_3f44b700395062e5:function(){return L(function(e,t){globalThis.crypto.getRandomValues(m(e,t));},arguments)},__wbg_get_78f252d074a84d0b:function(){return L(function(e,t){return Reflect.get(e,t)},arguments)},__wbg_get_unchecked_6e0ad6d2a41b06f6:function(e,t){return e[t>>>0]},__wbg_instanceof_Object_33f20e6f12439f3e:function(e){let t;try{t=e instanceof Object;}catch{t=false;}return t},__wbg_keys_58421f8f96795607:function(e){return Object.keys(e)},__wbg_length_1f0964f4a5e2c6d8:function(e){return e.length},__wbg_length_370319915dc99107:function(e){return e.length},__wbg_new_cd45aabdf6073e84:function(e){return new Uint8Array(e)},__wbg_new_da52cf8fe3429cb2:function(){return new Object},__wbg_new_from_slice_77cdfb7977362f3c:function(e,t){return new Uint8Array(m(e,t))},__wbg_now_86c0d4ba3fa605b8:function(){return Date.now()},__wbg_prototypesetcall_4770620bbe4688a0:function(e,t,n){Uint8Array.prototype.set.call(m(e,t),n);},__wbg_set_8535240470bf2500:function(){return L(function(e,t,n){return Reflect.set(e,t,n)},arguments)},__wbindgen_cast_0000000000000001:function(e,t){return b(e,t)},__wbindgen_init_externref_table:function(){let e=i.__wbindgen_externrefs,t=e.grow(4);e.set(0,void 0),e.set(t+0,void 0),e.set(t+1,null),e.set(t+2,true),e.set(t+3,false);}}}}var M=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>i.__wbg_xlsxdocument_free(r,1));function Ae(r){let e=i.__externref_table_alloc();return i.__wbindgen_externrefs.set(e,r),e}function m(r,e){return r=r>>>0,C().subarray(r/1,r/1+e)}var v=null;function F(){return (v===null||v.buffer.detached===true||v.buffer.detached===void 0&&v.buffer!==i.memory.buffer)&&(v=new DataView(i.memory.buffer)),v}function b(r,e){return Je(r>>>0,e)}var S=null;function C(){return (S===null||S.byteLength===0)&&(S=new Uint8Array(i.memory.buffer)),S}function L(r,e){try{return r.apply(this,e)}catch(t){let n=Ae(t);i.__wbindgen_exn_store(n);}}function Ee(r){return r==null}function k(r,e){let t=e(r.length*1,1)>>>0;return C().set(r,t/1),p=r.length,t}function y(r,e,t){if(t===void 0){let c=A.encode(r),a=e(c.length,1)>>>0;return C().subarray(a,a+c.length).set(c),p=c.length,a}let n=r.length,o=e(n,1)>>>0,s=C(),f=0;for(;f<n;f++){let c=r.charCodeAt(f);if(c>127)break;s[o+f]=c;}if(f!==n){f!==0&&(r=r.slice(f)),o=t(o,n,n=f+r.length*3,1)>>>0;let c=C().subarray(o+f,o+n),a=A.encodeInto(r,c);f+=a.written,o=t(o,n,f,1)>>>0;}return p=f,o}function _(r){let e=i.__wbindgen_externrefs.get(r);return i.__externref_table_dealloc(r),e}var O=new TextDecoder("utf-8",{ignoreBOM:true,fatal:true});O.decode();var Re=2146435072,N=0;function Je(r,e){return N+=e,N>=Re&&(O=new TextDecoder("utf-8",{ignoreBOM:true,fatal:true}),O.decode(),N=e),O.decode(C().subarray(r,r+e))}var A=new TextEncoder;"encodeInto"in A||(A.encodeInto=function(r,e){let t=A.encode(r);return e.set(t),{read:r.length,written:t.length}});var p=0,i;function ke(r,e){return i=r.exports,v=null,S=null,i.__wbindgen_start(),i}async function Oe(r,e){if(typeof Response=="function"&&r instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(r,e)}catch(o){if(r.ok&&t(r.type)&&r.headers.get("Content-Type")!=="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",o);else throw o}let n=await r.arrayBuffer();return await WebAssembly.instantiate(n,e)}else {let n=await WebAssembly.instantiate(r,e);return n instanceof WebAssembly.Instance?{instance:n,module:r}:n}function t(n){switch(n){case "basic":case "cors":case "default":return true}return false}}async function B(r){if(i!==void 0)return i;if(r!==void 0&&(Object.getPrototypeOf(r)===Object.prototype?{module_or_path:r}=r:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),r===void 0)throw new Error("xlsx-wasm requires an explicit module or URL");let e=Se();(typeof r=="string"||typeof Request=="function"&&r instanceof Request||typeof URL=="function"&&r instanceof URL)&&(r=fetch(r));let{instance:t,module:n}=await Oe(await r,e);return ke(t)}var P=class extends Error{constructor(t){super(`stale: ${t.join(", ")}`);a(this,"cells");this.name="StaleProposalError",this.cells=t;}},H="stale: ";function Pe(r){let e=r.slice(H.length).split(",").map(t=>t.trim()).filter(t=>t.length>0);return new P(e)}var V=false,E;function Te(r=new URL("./generated/xlsx_wasm_bg.wasm",import.meta.url)){return V?Promise.resolve():E||(E=B({module_or_path:r}).then(()=>{V=true;},e=>{throw E=void 0,R(e)}),E)}function q(){if(!V)throw new Error("xlsx wasm is not initialized; call initWasm() first")}function R(r){return r instanceof Error?r:new Error(typeof r=="string"?r:String(r))}function We(){return typeof WebAssembly=="object"}function De(){return typeof x.prototype.renderPng=="function"}function Le(){return typeof x.prototype.proposeJson=="function"}function Ne(r,e={}){q();let t=Ve(e),n;try{n=t===void 0?x.open(r):x.openCollaborative(r,t);}catch(l){throw R(l)}let o=new Map,s=[],f=0,c=false,a=false,J=0,T=false;function j(){if(c)throw new Error("workbook handle is disposed")}function G(){if(!(c||T||J!==0)){T=true;try{for(;!c&&s.length>0;){let l=s.shift();if(!l)break;for(let[d,u]of [...o]){if(c)return;if(o.get(d)===u)try{u(l.update.slice(),l.origin);}catch{}}}}finally{T=false,c&&(s.length=0);}}}function X(){if(!(!a||c))for(;;){let l=n.drainUpdateEvent();if(l.byteLength===0)return;let d=l[0];if(d!==0&&d!==1)throw new Error(`xlsx wasm returned unknown update origin ${d}`);s.push({update:l.slice(1),origin:d===0?"local":"remote"});}}function g(l,d=false){j(),J+=1;try{let u,w,U=!1;try{u=l();}catch(W){w=W,U=!0;}if(d)try{X();}catch(W){U||(w=W,U=!0);}if(U)throw R(w);return u}finally{J-=1,J===0&&G();}}function I(l){return g(l,true)}function h(l,d=false){return g(()=>JSON.parse(l()),d)}function $(){a||(g(()=>n.startUpdateObservation()),a=true);}function K(){!a||o.size>0||c||(s.length=0,g(()=>n.clearUpdateObservation()),a=false);}return {get clientId(){return g(()=>n.clientId)},encodeStateVector(){return g(()=>n.encodeStateVector().slice())},encodeStateAsUpdate(l){return g(()=>l===void 0?n.encodeStateAsUpdate().slice():n.encodeDiff(l.slice()).slice())},applyUpdate(l){return h(()=>n.applyUpdateJson(l.slice()),true)},onUpdate(l){if(j(),typeof l!="function")throw new TypeError("update listener must be a function");let d=f++;o.set(d,l);try{$();}catch(w){throw o.delete(d),w}let u=true;return ()=>{u&&(u=false,o.delete(d),K());}},sheetInfo(){return h(()=>n.sheetInfoJson())},calculationStatus(){return g(()=>{let l=n.calculationStatusJson;return typeof l!="function"?{limitedCells:[]}:JSON.parse(l.call(n))})},displayList(l){return h(()=>n.displayListJson(JSON.stringify(l)))},setActiveSheet(l){I(()=>n.setActiveSheet(l));},editCell(l,d,u,w){return h(()=>n.editCellJson(JSON.stringify({sheet:l,row:d,col:u,input:w})),true)},editCells(l,d){return h(()=>n.editCellsJson(JSON.stringify({sheet:l,edits:d})),true)},applyOps(l){return h(()=>n.applyOpsJson(JSON.stringify({ops:l})),true)},undo(){return h(()=>n.undoJson(),true)},redo(){return h(()=>n.redoJson(),true)},cell(l,d,u){return h(()=>n.cellJson(JSON.stringify({sheet:l,row:d,col:u})))},rangeCells(l,d){return h(()=>n.rangeCellsJson(JSON.stringify({sheet:l,range:d}))).cells},renderPng(l){return g(()=>{let d=n.renderPng;if(typeof d!="function")throw new Error("png export not in this build");return d.call(n,JSON.stringify(l)).slice()})},renderRangePng(l){return g(()=>{let d=n.renderRangePng;if(typeof d!="function")throw new Error("png export not in this build");return d.call(n,JSON.stringify(l??{})).slice()})},save(){return g(()=>n.saveBytes().slice())},propose(l,d,u){return I(()=>{let w=n.proposeJson;if(typeof w!="function")throw new Error("proposals not in this build");return JSON.parse(w.call(n,JSON.stringify({agentId:l,note:d,edits:u})))})},listProposals(){return g(()=>{let l=n.listProposalsJson;return typeof l!="function"?[]:JSON.parse(l.call(n)).proposals})},acceptProposal(l,d){try{return I(()=>{let u=n.acceptProposalJson;if(typeof u!="function")throw new Error("proposals not in this build");return JSON.parse(u.call(n,JSON.stringify({id:l,force:d?.force??!1})))})}catch(u){let w=u instanceof Error?u.message:typeof u=="string"?u:String(u);throw w.startsWith(H)?Pe(w):R(u)}},rejectProposal(l){return I(()=>{let d=n.rejectProposalJson;return typeof d!="function"?false:JSON.parse(d.call(n,JSON.stringify({id:l}))).removed})},isProposalsAvailable(){return g(()=>typeof n.proposeJson=="function")},dispose(){if(c)return;c=true,o.clear(),s.length=0;let l;if(a){try{n.clearUpdateObservation();}catch(d){l=d;}a=false;}try{n.free();}catch(d){l??(l=d);}if(l!==void 0)throw R(l)}}}function Ve(r){if(!r.collaborative){if(r.clientId!==void 0)throw new TypeError("clientId requires collaborative mode");return}if(r.clientId!==void 0){if(!Number.isSafeInteger(r.clientId)||r.clientId<=0||r.clientId>Number.MAX_SAFE_INTEGER)throw new RangeError("clientId must be a nonzero safe integer");return r.clientId}let e=globalThis.crypto;if(!e||typeof e.getRandomValues!="function")throw new Error("crypto.getRandomValues is required to generate a collaboration client ID");let t=new Uint32Array(2),n;do e.getRandomValues(t),n=(t[0]&2097151)*4294967296+t[1];while(n===0);return n}function je(){return q(),x.version()}export{P as StaleProposalError,Te as initWasm,De as isPngExportAvailable,Le as isProposalsAvailable,We as isWasmAvailable,Ne as openWorkbook,ye as paintDisplayList,je as wasmVersion};
|
|
1
|
+
export{v as buildA11yGrid,n as cellAtPoint,j as cellCount,o as cellRect,e as clampScroll,k as extendTo,u as fromTsv,q as hyperlinkAtCell,l as moveFocus,h as normalizeRange,s as parseHyperlinkLocation,i as rangeContains,p as rangeRect,r as safeExternalHyperlink,g as selectionAt,m as selectionKeyReducer,t as toTsv,b as totalExtent,a as trackCount,f as uniformOffsets,d as visibleCells,c as visibleRange}from'./chunk-4LMGHPXC.js';import {a}from'./chunk-O2XFH626.js';var he={left:"left",center:"center",right:"right"},xe={dashed:[4,2],dotted:[1,2]};function ve(o,e,n){o.save(),o.setTransform(n,0,0,n,0,0),o.clearRect(0,0,e.width,e.height);for(let t of e.commands)Se(o,t);o.restore();}function Se(o,e){switch(e.op){case "fillRect":o.fillStyle=e.color,o.fillRect(e.x,e.y,e.w,e.h);return;case "line":Ce(o,e);return;case "text":Re(o,e);return}}function Ce(o,e){if(o.strokeStyle=e.color,e.style==="double"){let n=Math.max(e.width*.8,.8),t=Math.abs(e.y1-e.y2)<=Math.abs(e.x1-e.x2),[r,i]=t?[0,n]:[n,0];o.lineWidth=Math.max(e.width*.6,.5),U(o,e.x1-r,e.y1-i,e.x2-r,e.y2-i),U(o,e.x1+r,e.y1+i,e.x2+r,e.y2+i);return}o.lineWidth=e.width,o.save(),o.setLineDash(e.style?xe[e.style]:[]),U(o,e.x1,e.y1,e.x2,e.y2),o.restore();}function U(o,e,n,t,r){o.beginPath(),o.moveTo(e,n),o.lineTo(t,r),o.stroke();}function Re(o,e){o.save(),e.clip&&(o.beginPath(),o.rect(e.clip.x,e.clip.y,e.clip.w,e.clip.h),o.clip()),o.fillStyle=e.color,o.font=Je(e),o.textAlign=he[e.align??"left"],o.textBaseline="alphabetic",e.highlight&&Pe(o,e),o.fillStyle=e.color,o.fillText(e.text,e.x,e.y),(e.underline||e.strike||e.dashedUnderline)&&Ae(o,e),o.restore();}function Je(o){let e=o.italic?"italic ":"",n=o.bold?"bold ":"",t=o.fontFamily?`"${o.fontFamily}", sans-serif`:"sans-serif";return `${e}${n}${o.fontSize}px ${t}`}function Ae(o,e){let n=o.measureText(e.text).width,t=e.align??"left",r=t==="right"?e.x-n:t==="center"?e.x-n/2:e.x,i=Math.max(e.fontSize*.05,.5);o.fillStyle=e.color,e.underline&&o.fillRect(r,e.y+e.fontSize*.1,n,i),e.strike&&o.fillRect(r,e.y-e.fontSize*.26,n,i),e.dashedUnderline&&(o.save(),o.strokeStyle=e.color,o.lineWidth=i,o.setLineDash([3,2]),U(o,r,e.y+e.fontSize*.1,r+n,e.y+e.fontSize*.1),o.restore());}function Pe(o,e){let n=o.measureText(e.text),t=n.width,r=e.align??"left",i=r==="right"?e.x-t:r==="center"?e.x-t/2:e.x,d=n.actualBoundingBoxAscent||e.fontSize*.8,c=n.actualBoundingBoxDescent||e.fontSize*.2;o.fillStyle=e.highlight,o.fillRect(i-2,e.y-d-1,t+4,d+c+2);}var x=class o{static __wrap(e){let n=Object.create(o.prototype);return n.__wbg_ptr=e,V.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,V.unregister(this),e}free(){let e=this.__destroy_into_raw();s.__wbg_xlsxdocument_free(e,0);}acceptProposalJson(e){let n,t;try{let d=b(e,s.__wbindgen_malloc,s.__wbindgen_realloc),c=g,a=s.xlsxdocument_acceptProposalJson(this.__wbg_ptr,d,c);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,_(a[2]);return n=r,t=i,p(r,i)}finally{s.__wbindgen_free(n,t,1);}}applyFormatJson(e){let n,t;try{let d=b(e,s.__wbindgen_malloc,s.__wbindgen_realloc),c=g,a=s.xlsxdocument_applyFormatJson(this.__wbg_ptr,d,c);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,_(a[2]);return n=r,t=i,p(r,i)}finally{s.__wbindgen_free(n,t,1);}}applyOpsJson(e){let n,t;try{let d=b(e,s.__wbindgen_malloc,s.__wbindgen_realloc),c=g,a=s.xlsxdocument_applyOpsJson(this.__wbg_ptr,d,c);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,_(a[2]);return n=r,t=i,p(r,i)}finally{s.__wbindgen_free(n,t,1);}}applyUpdateJson(e){let n,t;try{let d=I(e,s.__wbindgen_malloc),c=g,a=s.xlsxdocument_applyUpdateJson(this.__wbg_ptr,d,c);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,_(a[2]);return n=r,t=i,p(r,i)}finally{s.__wbindgen_free(n,t,1);}}calculationStatusJson(){let e,n;try{let i=s.xlsxdocument_calculationStatusJson(this.__wbg_ptr);var t=i[0],r=i[1];if(i[3])throw t=0,r=0,_(i[2]);return e=t,n=r,p(t,r)}finally{s.__wbindgen_free(e,n,1);}}captureFormatJson(e){let n,t;try{let d=b(e,s.__wbindgen_malloc,s.__wbindgen_realloc),c=g,a=s.xlsxdocument_captureFormatJson(this.__wbg_ptr,d,c);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,_(a[2]);return n=r,t=i,p(r,i)}finally{s.__wbindgen_free(n,t,1);}}cellJson(e){let n,t;try{let d=b(e,s.__wbindgen_malloc,s.__wbindgen_realloc),c=g,a=s.xlsxdocument_cellJson(this.__wbg_ptr,d,c);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,_(a[2]);return n=r,t=i,p(r,i)}finally{s.__wbindgen_free(n,t,1);}}cellPositionJson(e){let n,t;try{let d=b(e,s.__wbindgen_malloc,s.__wbindgen_realloc),c=g,a=s.xlsxdocument_cellPositionJson(this.__wbg_ptr,d,c);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,_(a[2]);return n=r,t=i,p(r,i)}finally{s.__wbindgen_free(n,t,1);}}clearUpdateObservation(){s.xlsxdocument_clearUpdateObservation(this.__wbg_ptr);}get clientId(){return s.xlsxdocument_clientId(this.__wbg_ptr)}displayListJson(e){let n,t;try{let d=b(e,s.__wbindgen_malloc,s.__wbindgen_realloc),c=g,a=s.xlsxdocument_displayListJson(this.__wbg_ptr,d,c);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,_(a[2]);return n=r,t=i,p(r,i)}finally{s.__wbindgen_free(n,t,1);}}drainUpdateEvent(){let e=s.xlsxdocument_drainUpdateEvent(this.__wbg_ptr);if(e[3])throw _(e[2]);var n=h(e[0],e[1]).slice();return s.__wbindgen_free(e[0],e[1]*1,1),n}editCellJson(e){let n,t;try{let d=b(e,s.__wbindgen_malloc,s.__wbindgen_realloc),c=g,a=s.xlsxdocument_editCellJson(this.__wbg_ptr,d,c);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,_(a[2]);return n=r,t=i,p(r,i)}finally{s.__wbindgen_free(n,t,1);}}editCellsJson(e){let n,t;try{let d=b(e,s.__wbindgen_malloc,s.__wbindgen_realloc),c=g,a=s.xlsxdocument_editCellsJson(this.__wbg_ptr,d,c);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,_(a[2]);return n=r,t=i,p(r,i)}finally{s.__wbindgen_free(n,t,1);}}encodeDiff(e){let n=I(e,s.__wbindgen_malloc),t=g,r=s.xlsxdocument_encodeDiff(this.__wbg_ptr,n,t);if(r[3])throw _(r[2]);var i=h(r[0],r[1]).slice();return s.__wbindgen_free(r[0],r[1]*1,1),i}encodeStateAsUpdate(){let e=s.xlsxdocument_encodeStateAsUpdate(this.__wbg_ptr);var n=h(e[0],e[1]).slice();return s.__wbindgen_free(e[0],e[1]*1,1),n}encodeStateVector(){let e=s.xlsxdocument_encodeStateVector(this.__wbg_ptr);var n=h(e[0],e[1]).slice();return s.__wbindgen_free(e[0],e[1]*1,1),n}historyStateJson(){let e,n;try{let i=s.xlsxdocument_historyStateJson(this.__wbg_ptr);var t=i[0],r=i[1];if(i[3])throw t=0,r=0,_(i[2]);return e=t,n=r,p(t,r)}finally{s.__wbindgen_free(e,n,1);}}listProposalsJson(){let e,n;try{let i=s.xlsxdocument_listProposalsJson(this.__wbg_ptr);var t=i[0],r=i[1];if(i[3])throw t=0,r=0,_(i[2]);return e=t,n=r,p(t,r)}finally{s.__wbindgen_free(e,n,1);}}mergedRangesJson(e){let n,t;try{let d=b(e,s.__wbindgen_malloc,s.__wbindgen_realloc),c=g,a=s.xlsxdocument_mergedRangesJson(this.__wbg_ptr,d,c);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,_(a[2]);return n=r,t=i,p(r,i)}finally{s.__wbindgen_free(n,t,1);}}static open(e){let n=I(e,s.__wbindgen_malloc),t=g,r=s.xlsxdocument_open(n,t);if(r[2])throw _(r[1]);return o.__wrap(r[0])}static openCollaborative(e,n){let t=I(e,s.__wbindgen_malloc),r=g,i=s.xlsxdocument_openCollaborative(t,r,n);if(i[2])throw _(i[1]);return o.__wrap(i[0])}patchRangeStyleJson(e){let n,t;try{let d=b(e,s.__wbindgen_malloc,s.__wbindgen_realloc),c=g,a=s.xlsxdocument_patchRangeStyleJson(this.__wbg_ptr,d,c);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,_(a[2]);return n=r,t=i,p(r,i)}finally{s.__wbindgen_free(n,t,1);}}proposeJson(e){let n,t;try{let d=b(e,s.__wbindgen_malloc,s.__wbindgen_realloc),c=g,a=s.xlsxdocument_proposeJson(this.__wbg_ptr,d,c);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,_(a[2]);return n=r,t=i,p(r,i)}finally{s.__wbindgen_free(n,t,1);}}rangeCellsJson(e){let n,t;try{let d=b(e,s.__wbindgen_malloc,s.__wbindgen_realloc),c=g,a=s.xlsxdocument_rangeCellsJson(this.__wbg_ptr,d,c);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,_(a[2]);return n=r,t=i,p(r,i)}finally{s.__wbindgen_free(n,t,1);}}redoJson(){let e,n;try{let i=s.xlsxdocument_redoJson(this.__wbg_ptr);var t=i[0],r=i[1];if(i[3])throw t=0,r=0,_(i[2]);return e=t,n=r,p(t,r)}finally{s.__wbindgen_free(e,n,1);}}rejectProposalJson(e){let n,t;try{let d=b(e,s.__wbindgen_malloc,s.__wbindgen_realloc),c=g,a=s.xlsxdocument_rejectProposalJson(this.__wbg_ptr,d,c);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,_(a[2]);return n=r,t=i,p(r,i)}finally{s.__wbindgen_free(n,t,1);}}renderPng(e){let n=b(e,s.__wbindgen_malloc,s.__wbindgen_realloc),t=g,r=s.xlsxdocument_renderPng(this.__wbg_ptr,n,t);if(r[3])throw _(r[2]);var i=h(r[0],r[1]).slice();return s.__wbindgen_free(r[0],r[1]*1,1),i}renderRangePng(e){let n=b(e,s.__wbindgen_malloc,s.__wbindgen_realloc),t=g,r=s.xlsxdocument_renderRangePng(this.__wbg_ptr,n,t);if(r[3])throw _(r[2]);var i=h(r[0],r[1]).slice();return s.__wbindgen_free(r[0],r[1]*1,1),i}saveBytes(){let e=s.xlsxdocument_saveBytes(this.__wbg_ptr);if(e[3])throw _(e[2]);var n=h(e[0],e[1]).slice();return s.__wbindgen_free(e[0],e[1]*1,1),n}selectionFormattingJson(e){let n,t;try{let d=b(e,s.__wbindgen_malloc,s.__wbindgen_realloc),c=g,a=s.xlsxdocument_selectionFormattingJson(this.__wbg_ptr,d,c);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,_(a[2]);return n=r,t=i,p(r,i)}finally{s.__wbindgen_free(n,t,1);}}setActiveSheet(e){let n=s.xlsxdocument_setActiveSheet(this.__wbg_ptr,e);if(n[1])throw _(n[0])}setRangeNumberFormatJson(e){let n,t;try{let d=b(e,s.__wbindgen_malloc,s.__wbindgen_realloc),c=g,a=s.xlsxdocument_setRangeNumberFormatJson(this.__wbg_ptr,d,c);var r=a[0],i=a[1];if(a[3])throw r=0,i=0,_(a[2]);return n=r,t=i,p(r,i)}finally{s.__wbindgen_free(n,t,1);}}sheetInfoJson(){let e,n;try{let i=s.xlsxdocument_sheetInfoJson(this.__wbg_ptr);var t=i[0],r=i[1];if(i[3])throw t=0,r=0,_(i[2]);return e=t,n=r,p(t,r)}finally{s.__wbindgen_free(e,n,1);}}startUpdateObservation(){let e=s.xlsxdocument_startUpdateObservation(this.__wbg_ptr);if(e[1])throw _(e[0])}undoJson(){let e,n;try{let i=s.xlsxdocument_undoJson(this.__wbg_ptr);var t=i[0],r=i[1];if(i[3])throw t=0,r=0,_(i[2]);return e=t,n=r,p(t,r)}finally{s.__wbindgen_free(e,n,1);}}static version(){let e,n;try{let t=s.xlsxdocument_version();return e=t[0],n=t[1],p(t[0],t[1])}finally{s.__wbindgen_free(e,n,1);}}};Symbol.dispose&&(x.prototype[Symbol.dispose]=x.prototype.free);function Ee(){return {__proto__:null,"./xlsx_wasm_bg.js":{__proto__:null,__wbg___wbindgen_string_get_b0ca35b86a603356:function(e,n){let t=n,r=typeof t=="string"?t:void 0;var i=Oe(r)?0:b(r,s.__wbindgen_malloc,s.__wbindgen_realloc),d=g;B().setInt32(e+4,d,true),B().setInt32(e+0,i,true);},__wbg___wbindgen_throw_344f42d3211c4765:function(e,n){throw new Error(p(e,n))},__wbg_getRandomValues_3f44b700395062e5:function(){return N(function(e,n){globalThis.crypto.getRandomValues(h(e,n));},arguments)},__wbg_get_78f252d074a84d0b:function(){return N(function(e,n){return Reflect.get(e,n)},arguments)},__wbg_get_unchecked_6e0ad6d2a41b06f6:function(e,n){return e[n>>>0]},__wbg_instanceof_Object_33f20e6f12439f3e:function(e){let n;try{n=e instanceof Object;}catch{n=false;}return n},__wbg_keys_58421f8f96795607:function(e){return Object.keys(e)},__wbg_length_1f0964f4a5e2c6d8:function(e){return e.length},__wbg_length_370319915dc99107:function(e){return e.length},__wbg_new_cd45aabdf6073e84:function(e){return new Uint8Array(e)},__wbg_new_da52cf8fe3429cb2:function(){return new Object},__wbg_new_from_slice_77cdfb7977362f3c:function(e,n){return new Uint8Array(h(e,n))},__wbg_now_86c0d4ba3fa605b8:function(){return Date.now()},__wbg_prototypesetcall_4770620bbe4688a0:function(e,n,t){Uint8Array.prototype.set.call(h(e,n),t);},__wbg_set_8535240470bf2500:function(){return N(function(e,n,t){return Reflect.set(e,n,t)},arguments)},__wbindgen_cast_0000000000000001:function(e,n){return p(e,n)},__wbindgen_init_externref_table:function(){let e=s.__wbindgen_externrefs,n=e.grow(4);e.set(0,void 0),e.set(n+0,void 0),e.set(n+1,null),e.set(n+2,true),e.set(n+3,false);}}}}var V=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(o=>s.__wbg_xlsxdocument_free(o,1));function ke(o){let e=s.__externref_table_alloc();return s.__wbindgen_externrefs.set(e,o),e}function h(o,e){return o=o>>>0,R().subarray(o/1,o/1+e)}var S=null;function B(){return (S===null||S.buffer.detached===true||S.buffer.detached===void 0&&S.buffer!==s.memory.buffer)&&(S=new DataView(s.memory.buffer)),S}function p(o,e){return Ie(o>>>0,e)}var J=null;function R(){return (J===null||J.byteLength===0)&&(J=new Uint8Array(s.memory.buffer)),J}function N(o,e){try{return o.apply(this,e)}catch(n){let t=ke(n);s.__wbindgen_exn_store(t);}}function Oe(o){return o==null}function I(o,e){let n=e(o.length*1,1)>>>0;return R().set(o,n/1),g=o.length,n}function b(o,e,n){if(n===void 0){let c=A.encode(o),a=e(c.length,1)>>>0;return R().subarray(a,a+c.length).set(c),g=c.length,a}let t=o.length,r=e(t,1)>>>0,i=R(),d=0;for(;d<t;d++){let c=o.charCodeAt(d);if(c>127)break;i[r+d]=c;}if(d!==t){d!==0&&(o=o.slice(d)),r=n(r,t,t=d+o.length*3,1)>>>0;let c=R().subarray(r+d,r+t),a=A.encodeInto(o,c);d+=a.written,r=n(r,t,d,1)>>>0;}return g=d,r}function _(o){let e=s.__wbindgen_externrefs.get(o);return s.__externref_table_dealloc(o),e}var T=new TextDecoder("utf-8",{ignoreBOM:true,fatal:true});T.decode();var Ue=2146435072,D=0;function Ie(o,e){return D+=e,D>=Ue&&(T=new TextDecoder("utf-8",{ignoreBOM:true,fatal:true}),T.decode(),D=e),T.decode(R().subarray(o,o+e))}var A=new TextEncoder;"encodeInto"in A||(A.encodeInto=function(o,e){let n=A.encode(o);return e.set(n),{read:o.length,written:n.length}});var g=0,s;function We(o,e){return s=o.exports,S=null,J=null,s.__wbindgen_start(),s}async function Ne(o,e){if(typeof Response=="function"&&o instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(o,e)}catch(r){if(o.ok&&n(o.type)&&o.headers.get("Content-Type")!=="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",r);else throw r}let t=await o.arrayBuffer();return await WebAssembly.instantiate(t,e)}else {let t=await WebAssembly.instantiate(o,e);return t instanceof WebAssembly.Instance?{instance:t,module:o}:t}function n(t){switch(t){case "basic":case "cors":case "default":return true}return false}}async function j(o){if(s!==void 0)return s;if(o!==void 0&&(Object.getPrototypeOf(o)===Object.prototype?{module_or_path:o}=o:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),o===void 0)throw new Error("xlsx-wasm requires an explicit module or URL");let e=Ee();(typeof o=="string"||typeof Request=="function"&&o instanceof Request||typeof URL=="function"&&o instanceof URL)&&(o=fetch(o));let{instance:n,module:t}=await Ne(await o,e);return We(n)}var F=class extends Error{constructor(n){super(`stale: ${n.join(", ")}`);a(this,"cells");this.name="StaleProposalError",this.cells=n;}},H="stale: ";function De(o){let e=o.slice(H.length).split(",").map(n=>n.trim()).filter(n=>n.length>0);return new F(e)}var z=false,P;function ze(o=new URL("./generated/xlsx_wasm_bg.wasm",import.meta.url)){return z?Promise.resolve():P||(P=j({module_or_path:o}).then(()=>{z=true;},e=>{throw P=void 0,E(e)}),P)}function X(){if(!z)throw new Error("xlsx wasm is not initialized; call initWasm() first")}function E(o){return o instanceof Error?o:new Error(typeof o=="string"?o:String(o))}function Le(){return typeof WebAssembly=="object"}function Me(){return typeof x.prototype.renderPng=="function"}function Ve(){return typeof x.prototype.proposeJson=="function"}function Be(o,e={}){X();let n=je(e),t;try{t=n===void 0?x.open(o):x.openCollaborative(o,n);}catch(l){throw E(l)}let r=new Map,i=[],d=0,c=false,a=false,k=0,W=false;function L(){if(c)throw new Error("workbook handle is disposed")}function $(){if(!(c||W||k!==0)){W=true;try{for(;!c&&i.length>0;){let l=i.shift();if(!l)break;for(let[u,f]of [...r]){if(c)return;if(r.get(u)===f)try{f(l.update.slice(),l.origin);}catch{}}}}finally{W=false,c&&(i.length=0);}}}function q(){if(!(!a||c))for(;;){let l=t.drainUpdateEvent();if(l.byteLength===0)return;let u=l[0];if(u!==0&&u!==1)throw new Error(`xlsx wasm returned unknown update origin ${u}`);i.push({update:l.slice(1),origin:u===0?"local":"remote"});}}function m(l,u=false){L(),k+=1;try{let f,w,C=!1;try{f=l();}catch(v){w=v,C=!0;}if(u)try{q();}catch(v){C||(w=v,C=!0);}if(C)throw E(w);return f}finally{k-=1,k===0&&$();}}function O(l){return m(l,true)}function y(l,u=false){return m(()=>JSON.parse(l()),u)}function G(){a||(m(()=>t.startUpdateObservation()),a=true);}function K(){!a||r.size>0||c||(i.length=0,m(()=>t.clearUpdateObservation()),a=false);}return {get clientId(){return m(()=>t.clientId)},encodeStateVector(){return m(()=>t.encodeStateVector().slice())},encodeStateAsUpdate(l){return m(()=>l===void 0?t.encodeStateAsUpdate().slice():t.encodeDiff(l.slice()).slice())},applyUpdate(l){return y(()=>t.applyUpdateJson(l.slice()),true)},onUpdate(l){if(L(),typeof l!="function")throw new TypeError("update listener must be a function");let u=d++;r.set(u,l);try{G();}catch(w){throw r.delete(u),w}let f=true;return ()=>{f&&(f=false,r.delete(u),K());}},sheetInfo(){return y(()=>t.sheetInfoJson())},calculationStatus(){return m(()=>{let l=t.calculationStatusJson;return typeof l!="function"?{limitedCells:[]}:JSON.parse(l.call(t))})},displayList(l){return y(()=>t.displayListJson(JSON.stringify(l)))},setActiveSheet(l){O(()=>t.setActiveSheet(l));},editCell(l,u,f,w){return y(()=>t.editCellJson(JSON.stringify({sheet:l,row:u,col:f,input:w})),true)},editCells(l,u){return y(()=>t.editCellsJson(JSON.stringify({sheet:l,edits:u})),true)},applyOps(l){return y(()=>t.applyOpsJson(JSON.stringify({ops:l})),true)},undo(){return y(()=>t.undoJson(),true)},redo(){return y(()=>t.redoJson(),true)},cell(l,u,f){return y(()=>t.cellJson(JSON.stringify({sheet:l,row:u,col:f})))},cellPosition(l,u,f){return y(()=>t.cellPositionJson(JSON.stringify({sheet:l,row:u,col:f})))},rangeCells(l,u){return y(()=>t.rangeCellsJson(JSON.stringify({sheet:l,range:u}))).cells},patchRangeStyle(l,u,f){return y(()=>t.patchRangeStyleJson(JSON.stringify({sheet:l,range:u,patch:f})),true)},setNumberFormat(l,u,f){let w=typeof f=="string"?{type:f}:f;return y(()=>t.setRangeNumberFormatJson(JSON.stringify({sheet:l,range:u,format:w})),true)},selectionFormatting(l,u){return y(()=>t.selectionFormattingJson(JSON.stringify({sheet:l,range:u})))},captureFormat(l,u){return y(()=>t.captureFormatJson(JSON.stringify({sheet:l,range:u})))},applyFormat(l,u,f){return y(()=>t.applyFormatJson(JSON.stringify({sheet:l,range:u,format:f})),true)},mergedRanges(l,u){return y(()=>t.mergedRangesJson(JSON.stringify({sheet:l,range:u}))).ranges},historyState(){return y(()=>t.historyStateJson())},renderPng(l){return m(()=>{let u=t.renderPng;if(typeof u!="function")throw new Error("png export not in this build");return u.call(t,JSON.stringify(l)).slice()})},renderRangePng(l){return m(()=>{let u=t.renderRangePng;if(typeof u!="function")throw new Error("png export not in this build");return u.call(t,JSON.stringify(l??{})).slice()})},save(){return m(()=>t.saveBytes().slice())},propose(l,u,f){return O(()=>{let w=t.proposeJson;if(typeof w!="function")throw new Error("proposals not in this build");let C=f.map(({numberFormat:v,...Y})=>({...Y,...v===void 0?{}:{numberFormat:typeof v=="string"?{type:v}:v}}));return JSON.parse(w.call(t,JSON.stringify({agentId:l,note:u,edits:C})))})},listProposals(){return m(()=>{let l=t.listProposalsJson;return typeof l!="function"?[]:JSON.parse(l.call(t)).proposals})},acceptProposal(l,u){try{return O(()=>{let f=t.acceptProposalJson;if(typeof f!="function")throw new Error("proposals not in this build");return JSON.parse(f.call(t,JSON.stringify({id:l,force:u?.force??!1})))})}catch(f){let w=f instanceof Error?f.message:typeof f=="string"?f:String(f);throw w.startsWith(H)?De(w):E(f)}},rejectProposal(l){return O(()=>{let u=t.rejectProposalJson;return typeof u!="function"?false:JSON.parse(u.call(t,JSON.stringify({id:l}))).removed})},isProposalsAvailable(){return m(()=>typeof t.proposeJson=="function")},dispose(){if(c)return;c=true,r.clear(),i.length=0;let l;if(a){try{t.clearUpdateObservation();}catch(u){l=u;}a=false;}try{t.free();}catch(u){l??(l=u);}if(l!==void 0)throw E(l)}}}function je(o){if(!o.collaborative){if(o.clientId!==void 0)throw new TypeError("clientId requires collaborative mode");return}if(o.clientId!==void 0){if(!Number.isSafeInteger(o.clientId)||o.clientId<=0||o.clientId>Number.MAX_SAFE_INTEGER)throw new RangeError("clientId must be a nonzero safe integer");return o.clientId}let e=globalThis.crypto;if(!e||typeof e.getRandomValues!="function")throw new Error("crypto.getRandomValues is required to generate a collaboration client ID");let n=new Uint32Array(2),t;do e.getRandomValues(n),t=(n[0]&2097151)*4294967296+n[1];while(t===0);return t}function He(){return X(),x.version()}export{F as StaleProposalError,ze as initWasm,Me as isPngExportAvailable,Ve as isProposalsAvailable,Le as isWasmAvailable,Be as openWorkbook,ve as paintDisplayList,He as wasmVersion};
|
|
@@ -33,6 +33,45 @@ interface CollaborationStatusChange {
|
|
|
33
33
|
status: CollaborationStatus;
|
|
34
34
|
synced: boolean;
|
|
35
35
|
}
|
|
36
|
+
interface CollaborationUser {
|
|
37
|
+
name: string;
|
|
38
|
+
color: string;
|
|
39
|
+
}
|
|
40
|
+
interface CollaborationUserOptions {
|
|
41
|
+
name: string;
|
|
42
|
+
color?: string;
|
|
43
|
+
}
|
|
44
|
+
interface AwarenessCell {
|
|
45
|
+
row: number;
|
|
46
|
+
col: number;
|
|
47
|
+
}
|
|
48
|
+
interface AwarenessCursor {
|
|
49
|
+
sheet: string;
|
|
50
|
+
anchor: AwarenessCell;
|
|
51
|
+
head: AwarenessCell;
|
|
52
|
+
}
|
|
53
|
+
interface AwarenessPayload {
|
|
54
|
+
user: CollaborationUser;
|
|
55
|
+
cursor: AwarenessCursor | null;
|
|
56
|
+
}
|
|
57
|
+
interface AwarenessState extends AwarenessPayload {
|
|
58
|
+
clientId: number;
|
|
59
|
+
clock: number;
|
|
60
|
+
}
|
|
61
|
+
interface AwarenessUpdate {
|
|
62
|
+
clientId: number;
|
|
63
|
+
clock: number;
|
|
64
|
+
state: AwarenessPayload | null;
|
|
65
|
+
}
|
|
66
|
+
interface AwarenessPeer extends AwarenessState {
|
|
67
|
+
lastSeen: number;
|
|
68
|
+
cursorMovedAt: number;
|
|
69
|
+
}
|
|
70
|
+
interface CollaborationAwareness {
|
|
71
|
+
readonly peers: readonly AwarenessPeer[];
|
|
72
|
+
setCursor(cursor: AwarenessCursor | null): void;
|
|
73
|
+
onAwareness(listener: AwarenessListener): () => void;
|
|
74
|
+
}
|
|
36
75
|
type CollaborationErrorCode = 'backpressure' | 'protocol' | 'replica' | 'transport';
|
|
37
76
|
declare class CollaborationError extends Error {
|
|
38
77
|
readonly code: CollaborationErrorCode;
|
|
@@ -43,8 +82,10 @@ interface CollaborationProviderOptions {
|
|
|
43
82
|
maxFrameBytes?: number;
|
|
44
83
|
maxMessagesPerFrame?: number;
|
|
45
84
|
maxPendingBytes?: number;
|
|
85
|
+
user?: CollaborationUserOptions;
|
|
46
86
|
}
|
|
47
87
|
type CollaborationStatusListener = (change: CollaborationStatusChange) => void;
|
|
48
88
|
type CollaborationErrorListener = (error: CollaborationError) => void;
|
|
89
|
+
type AwarenessListener = (peers: readonly AwarenessPeer[]) => void;
|
|
49
90
|
|
|
50
|
-
export { type CollaborationReplica as C, type CollaborationTransport as a, type CollaborationProviderOptions as b, type CollaborationStatus as c, type CollaborationStatusListener as d, type CollaborationErrorListener as e,
|
|
91
|
+
export { type AwarenessPeer as A, type CollaborationReplica as C, type CollaborationTransport as a, type CollaborationProviderOptions as b, type CollaborationStatus as c, type CollaborationStatusListener as d, type CollaborationErrorListener as e, type AwarenessListener as f, type AwarenessCursor as g, type AwarenessPayload as h, type AwarenessUpdate as i, type CollaborationUserOptions as j, type CollaborationUser as k, type AwarenessCell as l, type AwarenessState as m, type CollaborationAwareness as n, CollaborationError as o, type CollaborationErrorCode as p, type CollaborationStatusChange as q, type CollaborationTransportEvent as r, type CollaborationUpdateOrigin as s };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@betteroffice/xlsx",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "Excel-faithful XLSX spreadsheet editor and viewer core — full OOXML fidelity, real-time human + AI agent collaboration. Framework-free (Rust/Wasm).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"xlsx",
|
package/dist/chunk-II4BZDSC.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
function L(t){return Math.max(0,t.length-1)}function D(t){return t.length>0?t[t.length-1]:0}function x(t,e,n){return Math.max(e,Math.min(n,t))}function E(t,e,n,o){let r=n,l=o;for(;r<l;){let c=r+l+1>>1;t[c]<=e?r=c:l=c-1;}return r}function M(t,e,n,o){let r=L(t);if(r===0)return {first:0,last:-1};let l=x(Math.trunc(e),0,r);if(l>=r)return {first:0,last:-1};let c=t[l]-t[0],i=t[l]+Math.max(0,n),s=Math.max(0,o-c),p=i+s,m=E(t,i,l,r-1);if(t[m+1]<=i||s===0)return {first:0,last:-1};let C=E(t,p,m,r-1);return {first:m,last:C}}function V(t,e,n){return {cols:M(e,t.frozenCols,t.scrollX,t.width),rows:M(n,t.frozenRows,t.scrollY,t.height)}}function T(t,e,n){let o=L(t),r=x(Math.trunc(e),0,o),l=D(t)-t[r],c=Math.max(0,n-(t[r]-t[0]));return Math.max(0,l-c)}function z(t,e,n){let o=x(t.scrollX,0,T(e,t.frozenCols,t.width)),r=x(t.scrollY,0,T(n,t.frozenRows,t.height));return o===t.scrollX&&r===t.scrollY?t:{...t,scrollX:o,scrollY:r}}function H(t,e){let n=new Array(t+1);for(let o=0;o<=t;o++)n[o]=o*e;return n}function S(t,e,n){return Math.max(e,Math.min(n,t))}function u(t){return {anchor:{...t},focus:{...t}}}function y(t){return {top:Math.min(t.anchor.row,t.focus.row),bottom:Math.max(t.anchor.row,t.focus.row),left:Math.min(t.anchor.col,t.focus.col),right:Math.max(t.anchor.col,t.focus.col)}}function _(t,e){let n=y(t);return e.row>=n.top&&e.row<=n.bottom&&e.col>=n.left&&e.col<=n.right}function $(t){let e=y(t);return (e.bottom-e.top+1)*(e.right-e.left+1)}function A(t,e,n){let o=n?{row:S(e.row,0,n.rows-1),col:S(e.col,0,n.cols-1)}:{...e};return {anchor:{...t.anchor},focus:o}}function k(t,e){switch(t){case "up":return {row:-e,col:0};case "down":return {row:e,col:0};case "left":return {row:0,col:-e};case "right":return {row:0,col:e}}}function b(t,e,n){let{limits:o}=n,r=n.step??1,l=k(e,r),c={row:S(t.focus.row+l.row,0,o.rows-1),col:S(t.focus.col+l.col,0,o.cols-1)};return n.extend?A(t,c):u(c)}var B={ArrowUp:"up",ArrowDown:"down",ArrowLeft:"left",ArrowRight:"right"};function g(t){return !!(t.metaKey||t.ctrlKey)}function X(t,e,n){switch(e){case "up":return {row:0,col:t.col};case "down":return {row:n.rows-1,col:t.col};case "left":return {row:t.row,col:0};case "right":return {row:t.row,col:n.cols-1}}}function a(t){return {type:"move",selection:t}}function Y(t,e,n){let{row:o,col:r}=t.focus;return !e&&r>=n.cols-1?u({row:Math.min(o+1,n.rows-1),col:0}):e&&r<=0?u({row:Math.max(o-1,0),col:n.cols-1}):u({row:o,col:r+(e?-1:1)})}function W(t){return t.key.length===1&&!t.ctrlKey&&!t.metaKey&&!t.altKey}function j(t,e,n){let o=B[e.key];if(o){if(g(e)){let r=X(t.focus,o,n);return a(e.shiftKey?A(t,r,n):u(r))}return a(b(t,o,{extend:e.shiftKey,limits:n}))}switch(e.key){case "Tab":return a(Y(t,!!e.shiftKey,n));case "Enter":return a(b(t,e.shiftKey?"up":"down",{extend:false,limits:n}));case "Home":return a(g(e)?u({row:0,col:0}):u({row:t.focus.row,col:0}));case "End":return a(g(e)?u({row:n.rows-1,col:n.cols-1}):u({row:t.focus.row,col:n.cols-1}));case "PageDown":return a(b(t,"down",{extend:e.shiftKey,step:n.rowsPerPage,limits:n}));case "PageUp":return a(b(t,"up",{extend:e.shiftKey,step:n.rowsPerPage,limits:n}));case "F2":return {type:"startEdit"};case "Delete":case "Backspace":return {type:"clear"}}return (e.key==="a"||e.key==="A")&&g(e)?a({anchor:{row:0,col:0},focus:{row:n.rows-1,col:n.cols-1}}):W(e)?{type:"startEdit",initialInput:e.key}:{type:"none"}}function I(t,e){let n=t.length-1;if(n<=0||e<t[0]||e>=t[n])return -1;let o=0,r=n-1;for(;o<r;){let l=o+r+1>>1;t[l]<=e?o=l:r=l-1;}return o}function at(t,e,n){if(!t)return null;let o=I(t.colOffsets,e),r=I(t.rowOffsets,n);return o<0||r<0?null:{row:t.startRow+r,col:t.startCol+o}}function K(t,e,n){let o=n-t;return o>=0&&o<e.length-1?o:-1}function mt(t,e,n){if(!t)return null;let o=K(t.startCol,t.colOffsets,n),r=K(t.startRow,t.rowOffsets,e);return o<0||r<0?null:{x:t.colOffsets[o],y:t.rowOffsets[r],w:t.colOffsets[o+1]-t.colOffsets[o],h:t.rowOffsets[r+1]-t.rowOffsets[r]}}function R(t,e,n){return Math.max(0,Math.min(e-1,n-t))}function pt(t,e){if(!t)return null;let n=t.colOffsets.length-1,o=t.rowOffsets.length-1;if(n<=0||o<=0)return null;let r=t.startCol+n-1,l=t.startRow+o-1;if(e.right<t.startCol||e.left>r||e.bottom<t.startRow||e.top>l)return null;let c=R(t.startCol,n,e.left),i=R(t.startCol,n,e.right),s=R(t.startRow,o,e.top),p=R(t.startRow,o,e.bottom);return {x:t.colOffsets[c],y:t.rowOffsets[s],w:t.colOffsets[i+1]-t.colOffsets[c],h:t.rowOffsets[p+1]-t.rowOffsets[s]}}var U=new Set(["=","+","-","@"]);function q(t){let e=t.charCodeAt(0);return U.has(t[0])||e===9||e===13||e===10}function J(t){return /[\t\n\r"]/.test(t)?`"${t.replace(/"/g,'""')}"`:t}function N(t){let e=!t.isFormula&&t.input.length>0&&q(t.input);return J(e?`'${t.input}`:t.input)}function bt(t){return t.map(e=>e.map(N).join(" ")).join(`\r
|
|
2
|
-
`)}function ht(t){let e=[],n=[],o="",r=false,l=0,c=()=>{n.push(o),o="";},i=()=>{c(),e.push(n),n=[];};for(;l<t.length;){let s=t[l];if(r){if(s==='"'){if(t[l+1]==='"'){o+='"',l+=2;continue}r=false,l+=1;continue}o+=s,l+=1;continue}if(s==='"'){r=true,l+=1;continue}if(s===" "){c(),l+=1;continue}if(s==="\r"){i(),t[l+1]===`
|
|
3
|
-
`&&(l+=1),l+=1;continue}if(s===`
|
|
4
|
-
`){i(),l+=1;continue}o+=s,l+=1;}return (o.length>0||n.length>0)&&i(),e}function v(t){let e=t,n="";do n=String.fromCharCode(65+e%26)+n,e=Math.floor(e/26)-1;while(e>=0);return n}function Q(t,e){return `${v(e)}${t+1}`}function O(t,e){return t.replace(/\{(\w+)\}/g,(n,o)=>String(e[o]??""))}function P(t,e){return `${Math.round(t*1e3)},${Math.round(e*1e3)}`}function Z(t){let e=new Map;for(let n of t.commands)n.op==="text"&&n.clip&&e.set(P(n.clip.x,n.clip.y),n.text);return e}function tt(t,e,n){return t?e>=t.top&&e<=t.bottom&&n>=t.left&&n<=t.right:false}function et(t,e,n,o,r,l){let c=t.startRow+e,i=t.startCol+n,s=Q(c,i),m=o.length===0?r?l.emptyCellLabelSelected:l.emptyCellLabel:r?l.cellLabelSelected:l.cellLabel;return {row:c,col:i,address:s,text:o,selected:r,label:O(m,{address:s,value:o})}}function Ct(t,e,n,o){let r=t.grid,l=O(o.gridLabel,{sheet:n});if(!r)return {label:l,sheetName:n,columnHeaders:[],rows:[]};let c=r.colOffsets.length-1,i=r.rowOffsets.length-1,s=e?y(e):null,p=Z(t),m=[];for(let f=0;f<c;f++){let w=r.startCol+f,h=v(w);m.push({col:w,text:h,label:O(o.columnHeaderLabel,{column:h})});}let C=[];for(let f=0;f<i;f++){let w=r.startRow+f,h=[];for(let d=0;d<c;d++){let F=P(r.colOffsets[d],r.rowOffsets[f]),G=p.get(F)??"";h.push(et(r,f,d,G,tt(s,w,r.startCol+d),o));}C.push({row:w,header:O(o.rowHeaderLabel,{row:w+1}),cells:h});}return {label:l,sheetName:n,columnHeaders:m,rows:C}}export{L as a,D as b,M as c,V as d,z as e,H as f,u as g,y as h,_ as i,$ as j,A as k,b as l,j as m,at as n,mt as o,pt as p,bt as q,ht as r,Ct as s};
|