@betteroffice/xlsx 0.0.2 → 0.0.4
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 +31 -4
- package/dist/generated/xlsx_wasm_bg.wasm +0 -0
- package/dist/index.d.ts +10 -8
- package/dist/index.js +1 -2
- package/package.json +6 -7
- package/dist/chunk-Q26VJ6CE.cjs +0 -4
- package/dist/headless.cjs +0 -1
- package/dist/headless.d.cts +0 -458
- package/dist/index.cjs +0 -2
- package/dist/index.d.cts +0 -216
package/package.json
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@betteroffice/xlsx",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Framework-free core for the BetterOffice xlsx editor: display list, viewport math, wasm loader.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
|
-
"main": "./dist/index.
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
8
|
"module": "./dist/index.js",
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
13
|
-
"import": "./dist/index.js"
|
|
14
|
-
"require": "./dist/index.cjs"
|
|
13
|
+
"import": "./dist/index.js"
|
|
15
14
|
},
|
|
16
15
|
"./headless": {
|
|
17
16
|
"types": "./dist/headless.d.ts",
|
|
18
|
-
"import": "./dist/headless.js"
|
|
19
|
-
"require": "./dist/headless.cjs"
|
|
17
|
+
"import": "./dist/headless.js"
|
|
20
18
|
}
|
|
21
19
|
},
|
|
22
20
|
"files": [
|
|
23
21
|
"dist"
|
|
24
22
|
],
|
|
25
23
|
"scripts": {
|
|
26
|
-
"build": "tsup",
|
|
24
|
+
"build": "bun run build:wasm && tsup",
|
|
25
|
+
"build:wasm": "node ../../scripts/build-xlsx-wasm.mjs",
|
|
27
26
|
"typecheck": "tsc --noEmit -p ."
|
|
28
27
|
},
|
|
29
28
|
"devDependencies": {
|
package/dist/chunk-Q26VJ6CE.cjs
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
'use strict';var V=Object.defineProperty;var z=(t,e,n)=>e in t?V(t,e,{enumerable:true,configurable:true,writable:true,value:n}):t[e]=n;var rt=(t,e,n)=>z(t,typeof e!="symbol"?e+"":e,n);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 H(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 _(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 $(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 k(t,e){let n=y(t);return e.row>=n.top&&e.row<=n.bottom&&e.col>=n.left&&e.col<=n.right}function B(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 X(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=X(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 Y={ArrowUp:"up",ArrowDown:"down",ArrowLeft:"left",ArrowRight:"right"};function g(t){return !!(t.metaKey||t.ctrlKey)}function W(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 j(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 U(t){return t.key.length===1&&!t.ctrlKey&&!t.metaKey&&!t.altKey}function q(t,e,n){let o=Y[e.key];if(o){if(g(e)){let r=W(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(j(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}}):U(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 bt(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 ht(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 dt(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 J=new Set(["=","+","-","@"]);function N(t){let e=t.charCodeAt(0);return J.has(t[0])||e===9||e===13||e===10}function Q(t){return /[\t\n\r"]/.test(t)?`"${t.replace(/"/g,'""')}"`:t}function Z(t){let e=!t.isFormula&&t.input.length>0&&N(t.input);return Q(e?`'${t.input}`:t.input)}function Ct(t){return t.map(e=>e.map(Z).join(" ")).join(`\r
|
|
2
|
-
`)}function xt(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 tt(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 et(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 nt(t,e,n){return t?e>=t.top&&e<=t.bottom&&n>=t.left&&n<=t.right:false}function ot(t,e,n,o,r,l){let c=t.startRow+e,i=t.startCol+n,s=tt(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 gt(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=et(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(ot(r,f,d,G,nt(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}}exports.a=rt;exports.b=L;exports.c=D;exports.d=M;exports.e=H;exports.f=_;exports.g=$;exports.h=u;exports.i=y;exports.j=k;exports.k=B;exports.l=A;exports.m=b;exports.n=q;exports.o=bt;exports.p=ht;exports.q=dt;exports.r=Ct;exports.s=xt;exports.t=gt;
|
package/dist/headless.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
'use strict';var chunkQ26VJ6CE_cjs=require('./chunk-Q26VJ6CE.cjs');Object.defineProperty(exports,"buildA11yGrid",{enumerable:true,get:function(){return chunkQ26VJ6CE_cjs.t}});Object.defineProperty(exports,"cellAtPoint",{enumerable:true,get:function(){return chunkQ26VJ6CE_cjs.o}});Object.defineProperty(exports,"cellCount",{enumerable:true,get:function(){return chunkQ26VJ6CE_cjs.k}});Object.defineProperty(exports,"cellRect",{enumerable:true,get:function(){return chunkQ26VJ6CE_cjs.p}});Object.defineProperty(exports,"clampScroll",{enumerable:true,get:function(){return chunkQ26VJ6CE_cjs.f}});Object.defineProperty(exports,"extendTo",{enumerable:true,get:function(){return chunkQ26VJ6CE_cjs.l}});Object.defineProperty(exports,"fromTsv",{enumerable:true,get:function(){return chunkQ26VJ6CE_cjs.s}});Object.defineProperty(exports,"moveFocus",{enumerable:true,get:function(){return chunkQ26VJ6CE_cjs.m}});Object.defineProperty(exports,"normalizeRange",{enumerable:true,get:function(){return chunkQ26VJ6CE_cjs.i}});Object.defineProperty(exports,"rangeContains",{enumerable:true,get:function(){return chunkQ26VJ6CE_cjs.j}});Object.defineProperty(exports,"rangeRect",{enumerable:true,get:function(){return chunkQ26VJ6CE_cjs.q}});Object.defineProperty(exports,"selectionAt",{enumerable:true,get:function(){return chunkQ26VJ6CE_cjs.h}});Object.defineProperty(exports,"selectionKeyReducer",{enumerable:true,get:function(){return chunkQ26VJ6CE_cjs.n}});Object.defineProperty(exports,"toTsv",{enumerable:true,get:function(){return chunkQ26VJ6CE_cjs.r}});Object.defineProperty(exports,"totalExtent",{enumerable:true,get:function(){return chunkQ26VJ6CE_cjs.c}});Object.defineProperty(exports,"trackCount",{enumerable:true,get:function(){return chunkQ26VJ6CE_cjs.b}});Object.defineProperty(exports,"uniformOffsets",{enumerable:true,get:function(){return chunkQ26VJ6CE_cjs.g}});Object.defineProperty(exports,"visibleCells",{enumerable:true,get:function(){return chunkQ26VJ6CE_cjs.e}});Object.defineProperty(exports,"visibleRange",{enumerable:true,get:function(){return chunkQ26VJ6CE_cjs.d}});
|
package/dist/headless.d.cts
DELETED
|
@@ -1,458 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TS mirror of the Rust display list.
|
|
3
|
-
*
|
|
4
|
-
* Hand-mirrored from crates/xlsx-render/src/display_list.rs — keep in sync.
|
|
5
|
-
* The renderer front-half (Rust) emits a target-agnostic list of draw commands;
|
|
6
|
-
* a backend (Canvas2D in the browser, tiny-skia on servers) executes them. These
|
|
7
|
-
* types are plain data with no DOM or framework dependency so the same list
|
|
8
|
-
* flows across the wasm boundary as JSON and into either backend unchanged.
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Axis-aligned rectangle in device-independent pixels.
|
|
12
|
-
*/
|
|
13
|
-
interface Rect {
|
|
14
|
-
x: number;
|
|
15
|
-
y: number;
|
|
16
|
-
w: number;
|
|
17
|
-
h: number;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Horizontal alignment for a text command, matching the spreadsheet cell
|
|
21
|
-
* alignment values the renderer resolves before emitting.
|
|
22
|
-
*/
|
|
23
|
-
type TextAlign = 'left' | 'center' | 'right';
|
|
24
|
-
/**
|
|
25
|
-
* Fill a solid rectangle — cell backgrounds, selection bands, header fills.
|
|
26
|
-
*/
|
|
27
|
-
interface FillRectCmd {
|
|
28
|
-
op: 'fillRect';
|
|
29
|
-
x: number;
|
|
30
|
-
y: number;
|
|
31
|
-
w: number;
|
|
32
|
-
h: number;
|
|
33
|
-
/** css color string (`#rrggbb`, `rgba(...)`), resolved from theme + tint in Rust. */
|
|
34
|
-
color: string;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Stroke a straight line — gridlines, cell borders, frozen-pane dividers.
|
|
38
|
-
*/
|
|
39
|
-
interface LineCmd {
|
|
40
|
-
op: 'line';
|
|
41
|
-
x1: number;
|
|
42
|
-
y1: number;
|
|
43
|
-
x2: number;
|
|
44
|
-
y2: number;
|
|
45
|
-
width: number;
|
|
46
|
-
color: string;
|
|
47
|
-
/**
|
|
48
|
-
* Stroke pattern. Absent/`undefined` is solid; `'dashed'`/`'dotted'` apply a
|
|
49
|
-
* dash pattern; `'double'` draws two thin parallel passes offset by ±. Skip-
|
|
50
|
-
* serialized at its default in Rust, so a solid line omits the field.
|
|
51
|
-
*/
|
|
52
|
-
style?: 'dashed' | 'dotted' | 'double';
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Paint a single-line text run. Spreadsheet cell text is single-line and
|
|
56
|
-
* clipped to the cell box, so `clip` is the cell rect and `align` places the
|
|
57
|
-
* run within it. Text metrics are owned upstream in Rust.
|
|
58
|
-
*/
|
|
59
|
-
interface TextCmd {
|
|
60
|
-
op: 'text';
|
|
61
|
-
x: number;
|
|
62
|
-
y: number;
|
|
63
|
-
text: string;
|
|
64
|
-
fontSize: number;
|
|
65
|
-
/** resolved font color (`#rrggbb`); a number-format color prefix wins upstream. */
|
|
66
|
-
color: string;
|
|
67
|
-
/** clip rectangle; the backend saves/clips/restores around the fill. */
|
|
68
|
-
clip?: Rect;
|
|
69
|
-
align?: TextAlign;
|
|
70
|
-
/**
|
|
71
|
-
* Font style facets resolved from the cell's style. All skip-serialized at
|
|
72
|
-
* `false` in Rust, so an unstyled run omits them; treat absent as `false`.
|
|
73
|
-
*/
|
|
74
|
-
bold?: boolean;
|
|
75
|
-
italic?: boolean;
|
|
76
|
-
underline?: boolean;
|
|
77
|
-
strike?: boolean;
|
|
78
|
-
/** css/font family from the style font; the backend falls back to its default. */
|
|
79
|
-
fontFamily?: string;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* One draw command; discriminated on `op`.
|
|
83
|
-
*/
|
|
84
|
-
type DrawCmd = FillRectCmd | LineCmd | TextCmd;
|
|
85
|
-
/**
|
|
86
|
-
* Grid metadata for the frame: which sheet cells the visible tracks map to and
|
|
87
|
-
* their viewport-local pixel boundaries. `rowOffsets[i]`/`colOffsets[i]` is the
|
|
88
|
-
* leading edge of the i-th visible row/col in device-independent px from the
|
|
89
|
-
* frame origin; both arrays have length `visible count + 1`, the last entry
|
|
90
|
-
* being one-past-end (the trailing edge of the last visible track). The pure
|
|
91
|
-
* hit-test and a11y seams read this to place clicks and mirror the grid without
|
|
92
|
-
* re-deriving geometry.
|
|
93
|
-
*
|
|
94
|
-
* Hand-mirrored from crates/xlsx-render/src/display_list.rs — keep in sync.
|
|
95
|
-
*/
|
|
96
|
-
interface GridMeta {
|
|
97
|
-
startRow: number;
|
|
98
|
-
startCol: number;
|
|
99
|
-
rowOffsets: number[];
|
|
100
|
-
colOffsets: number[];
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* A full frame to paint: logical size plus the ordered command stream. `grid`
|
|
104
|
-
* is optional so a synthetic or pre-grid-metadata frame still type-checks; the
|
|
105
|
-
* hit-test and a11y builders treat its absence as "no addressable cells".
|
|
106
|
-
*/
|
|
107
|
-
interface DisplayList {
|
|
108
|
-
width: number;
|
|
109
|
-
height: number;
|
|
110
|
-
commands: DrawCmd[];
|
|
111
|
-
grid?: GridMeta;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Pure viewport types. No DOM — this is the compute seam the a11y grid, the
|
|
116
|
-
* canvas painter, and a future Rust port all read from.
|
|
117
|
-
*/
|
|
118
|
-
/**
|
|
119
|
-
* Cumulative pixel offsets for a track axis (columns or rows). `offsets[i]` is
|
|
120
|
-
* the leading edge of track `i`; `offsets.length === trackCount + 1`, so the
|
|
121
|
-
* last element is the total extent. Frozen tracks are the first `frozen` of
|
|
122
|
-
* these — they are pinned and always visible.
|
|
123
|
-
*/
|
|
124
|
-
type TrackOffsets = number[];
|
|
125
|
-
/**
|
|
126
|
-
* Scroll + geometry state driving virtualization. `scrollX/scrollY` are in
|
|
127
|
-
* content pixels of the scrollable (non-frozen) region; `width/height` is the
|
|
128
|
-
* visible viewport in css pixels; `dpr` scales to device pixels at paint time.
|
|
129
|
-
*/
|
|
130
|
-
interface ViewportState {
|
|
131
|
-
scrollX: number;
|
|
132
|
-
scrollY: number;
|
|
133
|
-
width: number;
|
|
134
|
-
height: number;
|
|
135
|
-
dpr: number;
|
|
136
|
-
frozenRows: number;
|
|
137
|
-
frozenCols: number;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* An inclusive track index range. `last < first` (e.g. `{ first: 0, last: -1 }`)
|
|
141
|
-
* denotes an empty range.
|
|
142
|
-
*/
|
|
143
|
-
interface VisibleRange {
|
|
144
|
-
first: number;
|
|
145
|
-
last: number;
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* The visible track window on both axes, frozen tracks excluded (they always
|
|
149
|
-
* render). Feed to the renderer to build the display list for a frame.
|
|
150
|
-
*/
|
|
151
|
-
interface VisibleCells {
|
|
152
|
-
cols: VisibleRange;
|
|
153
|
-
rows: VisibleRange;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Pure viewport math: visible-range computation against cumulative track
|
|
158
|
-
* offsets, and scroll clamping. No DOM, no side effects — every function is a
|
|
159
|
-
* deterministic transform of plain numbers so it is golden-testable and can be
|
|
160
|
-
* mirrored in Rust.
|
|
161
|
-
*/
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Number of tracks described by an offsets array.
|
|
165
|
-
*/
|
|
166
|
-
declare function trackCount(offsets: TrackOffsets): number;
|
|
167
|
-
/**
|
|
168
|
-
* Total pixel extent of a track axis (position of the trailing edge).
|
|
169
|
-
*/
|
|
170
|
-
declare function totalExtent(offsets: TrackOffsets): number;
|
|
171
|
-
/**
|
|
172
|
-
* The inclusive range of scrollable (non-frozen) tracks intersecting the
|
|
173
|
-
* viewport. `frozen` tracks at the head are pinned and excluded here — the
|
|
174
|
-
* scrollable window starts after them and is shortened by their pinned width.
|
|
175
|
-
*/
|
|
176
|
-
declare function visibleRange(offsets: TrackOffsets, frozen: number, scroll: number, viewportExtent: number): VisibleRange;
|
|
177
|
-
/**
|
|
178
|
-
* Visible column and row ranges for a frame, frozen tracks excluded.
|
|
179
|
-
*/
|
|
180
|
-
declare function visibleCells(state: ViewportState, colOffsets: TrackOffsets, rowOffsets: TrackOffsets): VisibleCells;
|
|
181
|
-
/**
|
|
182
|
-
* Clamp a viewport's scroll offsets into the valid range for the given content.
|
|
183
|
-
* Returns the same state when already in range, a corrected copy otherwise.
|
|
184
|
-
*/
|
|
185
|
-
declare function clampScroll(state: ViewportState, colOffsets: TrackOffsets, rowOffsets: TrackOffsets): ViewportState;
|
|
186
|
-
/**
|
|
187
|
-
* Build a uniform offsets array of `count` tracks each `size` px wide.
|
|
188
|
-
*/
|
|
189
|
-
declare function uniformOffsets(count: number, size: number): TrackOffsets;
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Pure selection types. Plain data only — no DOM, no framework — so the model
|
|
193
|
-
* is golden-testable and mirrorable in Rust. The chrome layer interprets the
|
|
194
|
-
* declarative {@link SelectionAction}s the reducer emits.
|
|
195
|
-
*/
|
|
196
|
-
/**
|
|
197
|
-
* A single cell coordinate. `row`/`col` are zero-based sheet indices, not px.
|
|
198
|
-
*/
|
|
199
|
-
interface CellAddr {
|
|
200
|
-
row: number;
|
|
201
|
-
col: number;
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* An active selection as an anchor/focus pair. `anchor` is the fixed corner
|
|
205
|
-
* (where the selection started); `focus` is the moving corner. A collapsed
|
|
206
|
-
* selection has `anchor` equal to `focus`.
|
|
207
|
-
*/
|
|
208
|
-
interface Selection {
|
|
209
|
-
anchor: CellAddr;
|
|
210
|
-
focus: CellAddr;
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* A normalized, inclusive rectangle of cells. `top <= bottom`, `left <= right`.
|
|
214
|
-
* Derived from a {@link Selection} by {@link normalizeRange}; the natural shape
|
|
215
|
-
* for hit-testing, overlay rects, and range reads.
|
|
216
|
-
*/
|
|
217
|
-
interface CellRange {
|
|
218
|
-
top: number;
|
|
219
|
-
left: number;
|
|
220
|
-
bottom: number;
|
|
221
|
-
right: number;
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* A cardinal move direction for {@link moveFocus} and arrow-key handling.
|
|
225
|
-
*/
|
|
226
|
-
type Direction = 'up' | 'down' | 'left' | 'right';
|
|
227
|
-
/**
|
|
228
|
-
* Grid bounds a move must stay inside: the used range is `[0, rows)` × `[0,
|
|
229
|
-
* cols)`, and `rowsPerPage` is the viewport height in whole rows for
|
|
230
|
-
* PageUp/PageDown steps.
|
|
231
|
-
*/
|
|
232
|
-
interface SelectionLimits {
|
|
233
|
-
rows: number;
|
|
234
|
-
cols: number;
|
|
235
|
-
rowsPerPage: number;
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Options for {@link moveFocus}: whether to extend (keep the anchor) or collapse
|
|
239
|
-
* to a single cell, how many cells to step, and the grid bounds to clamp into.
|
|
240
|
-
*/
|
|
241
|
-
interface MoveOpts {
|
|
242
|
-
extend?: boolean;
|
|
243
|
-
step?: number;
|
|
244
|
-
limits: SelectionLimits;
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* A keyboard event reduced to the fields the reducer reads. `metaKey`/`ctrlKey`
|
|
248
|
-
* are both accepted so a caller need not normalize mac cmd vs win/linux ctrl.
|
|
249
|
-
*/
|
|
250
|
-
interface KeyInput {
|
|
251
|
-
key: string;
|
|
252
|
-
shiftKey?: boolean;
|
|
253
|
-
metaKey?: boolean;
|
|
254
|
-
ctrlKey?: boolean;
|
|
255
|
-
altKey?: boolean;
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* The declarative outcome of a keystroke. The chrome interprets it: `move`
|
|
259
|
-
* replaces the selection, `startEdit` opens the in-cell editor (seeding it with
|
|
260
|
-
* `initialInput` when a printable key triggered it), `clear` deletes the
|
|
261
|
-
* selected cells' contents, and `none` means the key was not handled here.
|
|
262
|
-
*/
|
|
263
|
-
type SelectionAction = {
|
|
264
|
-
type: 'move';
|
|
265
|
-
selection: Selection;
|
|
266
|
-
} | {
|
|
267
|
-
type: 'startEdit';
|
|
268
|
-
initialInput?: string;
|
|
269
|
-
} | {
|
|
270
|
-
type: 'clear';
|
|
271
|
-
} | {
|
|
272
|
-
type: 'none';
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Selection model: pure transforms over {@link Selection} data. Every function
|
|
277
|
-
* returns a fresh value and never mutates its input, so state lives with the
|
|
278
|
-
* chrome and this layer stays a deterministic reducer core.
|
|
279
|
-
*/
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* A collapsed selection at a single cell.
|
|
283
|
-
*/
|
|
284
|
-
declare function selectionAt(addr: CellAddr): Selection;
|
|
285
|
-
/**
|
|
286
|
-
* The normalized inclusive rectangle spanned by a selection's anchor and focus.
|
|
287
|
-
*/
|
|
288
|
-
declare function normalizeRange(sel: Selection): CellRange;
|
|
289
|
-
/**
|
|
290
|
-
* Whether a cell falls inside a selection's normalized range.
|
|
291
|
-
*/
|
|
292
|
-
declare function rangeContains(sel: Selection, addr: CellAddr): boolean;
|
|
293
|
-
/**
|
|
294
|
-
* Number of cells covered by a selection.
|
|
295
|
-
*/
|
|
296
|
-
declare function cellCount(sel: Selection): number;
|
|
297
|
-
/**
|
|
298
|
-
* Extend the selection to a new focus, holding the anchor fixed (shift-click /
|
|
299
|
-
* shift-arrow semantics). The address is clamped into the grid when limits pass.
|
|
300
|
-
*/
|
|
301
|
-
declare function extendTo(sel: Selection, addr: CellAddr, limits?: SelectionLimits): Selection;
|
|
302
|
-
/**
|
|
303
|
-
* Move the focus one (or `step`) cells in a direction. When `extend` is set the
|
|
304
|
-
* anchor holds and the range grows; otherwise the whole selection collapses onto
|
|
305
|
-
* the new focus. The result is clamped to the grid bounds in `opts.limits`.
|
|
306
|
-
*/
|
|
307
|
-
declare function moveFocus(sel: Selection, direction: Direction, opts: MoveOpts): Selection;
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* Keyboard reducer: maps a keystroke over the current selection to a
|
|
311
|
-
* declarative {@link SelectionAction}. Pure — it neither mutates state nor
|
|
312
|
-
* touches the DOM; the chrome owns the keydown listener and interprets the
|
|
313
|
-
* action. Excel navigation semantics, with two deliberate choices documented at
|
|
314
|
-
* the F2/Enter handlers below.
|
|
315
|
-
*/
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Reduce a keystroke to a selection action against the current selection and
|
|
319
|
-
* grid limits. Returns `{ type: 'none' }` for keys this layer does not own so
|
|
320
|
-
* the chrome can fall through to its own handling.
|
|
321
|
-
*/
|
|
322
|
-
declare function selectionKeyReducer(state: Selection, key: KeyInput, limits: SelectionLimits): SelectionAction;
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* Pure hit-testing over a frame's {@link GridMeta}: map a viewport-local point
|
|
326
|
-
* to a cell, and map cells/ranges back to their pixel rects for overlay
|
|
327
|
-
* placement. Binary search over the boundary offsets; DOM-free so click
|
|
328
|
-
* handling and the selection overlay share one geometry source with the painter.
|
|
329
|
-
*/
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* The cell under a viewport-local point, or `null` when the point is outside the
|
|
333
|
-
* visible grid (or the frame carries no grid metadata).
|
|
334
|
-
*/
|
|
335
|
-
declare function cellAtPoint(grid: GridMeta | undefined, x: number, y: number): CellAddr | null;
|
|
336
|
-
/**
|
|
337
|
-
* The pixel rect of a single cell in viewport-local coordinates, or `null` when
|
|
338
|
-
* the cell is not within the visible window.
|
|
339
|
-
*/
|
|
340
|
-
declare function cellRect(grid: GridMeta | undefined, row: number, col: number): Rect | null;
|
|
341
|
-
/**
|
|
342
|
-
* The pixel rect covering the visible part of a cell range, clipped to the
|
|
343
|
-
* window. `null` when the range lies entirely outside the visible grid — so the
|
|
344
|
-
* selection overlay is hidden rather than mispainted when scrolled away.
|
|
345
|
-
*/
|
|
346
|
-
declare function rangeRect(grid: GridMeta | undefined, range: CellRange): Rect | null;
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* Pure TSV codec for clipboard interchange, in the Excel dialect (tab-separated
|
|
350
|
-
* fields, CRLF rows, `"`-quoted fields with doubled embedded quotes). No DOM —
|
|
351
|
-
* the chrome hands the system clipboard the string this produces and feeds paste
|
|
352
|
-
* text back through {@link fromTsv}.
|
|
353
|
-
*
|
|
354
|
-
* Security (CLAUDE.md formula-injection contract): a foreign spreadsheet treats
|
|
355
|
-
* a pasted cell as a formula when its text leads with `=`, `+`, `-`, `@`, or a
|
|
356
|
-
* control char that can break the field. We defang such *text* with a leading
|
|
357
|
-
* single quote so it pastes literally — but we export our own real formulas
|
|
358
|
-
* (`isFormula`) verbatim, because faithfully round-tripping a `=SUM(...)` the
|
|
359
|
-
* user actually wrote is the point, and it is our value, not attacker text.
|
|
360
|
-
*/
|
|
361
|
-
/**
|
|
362
|
-
* One source cell as the wasm range read returns it: the raw entered `input`
|
|
363
|
-
* (a `=...` string when `isFormula`) plus whether the model holds it as a
|
|
364
|
-
* formula.
|
|
365
|
-
*/
|
|
366
|
-
interface CellInput {
|
|
367
|
-
input: string;
|
|
368
|
-
isFormula: boolean;
|
|
369
|
-
}
|
|
370
|
-
/**
|
|
371
|
-
* Serialize a row-major grid of cells to a TSV string for the system clipboard,
|
|
372
|
-
* defanging formula-looking text (see the module security note) while exporting
|
|
373
|
-
* genuine formulas as-is.
|
|
374
|
-
*/
|
|
375
|
-
declare function toTsv(cells: CellInput[][]): string;
|
|
376
|
-
/**
|
|
377
|
-
* Parse clipboard TSV back into a row-major grid of raw strings. Handles the
|
|
378
|
-
* Excel dialect: `"`-quoted fields with doubled quotes and embedded tabs/
|
|
379
|
-
* newlines, CRLF or LF rows, and a single trailing newline (which does not add
|
|
380
|
-
* an empty row). The formula-injection guard quote is left in place — it is part
|
|
381
|
-
* of the literal text a defanged cell round-trips to.
|
|
382
|
-
*/
|
|
383
|
-
declare function fromTsv(text: string): string[][];
|
|
384
|
-
|
|
385
|
-
/**
|
|
386
|
-
* Pure a11y types: a serializable mirror of the visible grid the chrome renders
|
|
387
|
-
* as an offscreen `role="grid"` for screen readers. Plain data only — the
|
|
388
|
-
* builder takes label templates as a param rather than importing i18n, so this
|
|
389
|
-
* seam stays dependency-free.
|
|
390
|
-
*/
|
|
391
|
-
/**
|
|
392
|
-
* Label templates the builder interpolates. Field names mirror the `a11y` keys
|
|
393
|
-
* in the framework adapter so a caller can pass localized strings through.
|
|
394
|
-
* Placeholders: `{address}`, `{value}`, `{row}`, `{column}`.
|
|
395
|
-
*/
|
|
396
|
-
interface A11yStrings {
|
|
397
|
-
gridLabel: string;
|
|
398
|
-
cellLabel: string;
|
|
399
|
-
cellLabelSelected: string;
|
|
400
|
-
emptyCellLabel: string;
|
|
401
|
-
emptyCellLabelSelected: string;
|
|
402
|
-
rowHeaderLabel: string;
|
|
403
|
-
columnHeaderLabel: string;
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* One mirrored cell: its address, display text, selection state, and the fully
|
|
407
|
-
* interpolated aria label (e.g. `"B2, 42, selected"`).
|
|
408
|
-
*/
|
|
409
|
-
interface A11yCell {
|
|
410
|
-
row: number;
|
|
411
|
-
col: number;
|
|
412
|
-
address: string;
|
|
413
|
-
text: string;
|
|
414
|
-
selected: boolean;
|
|
415
|
-
label: string;
|
|
416
|
-
}
|
|
417
|
-
/**
|
|
418
|
-
* A column header: the letter (`"A"`) and its aria label (`"Column A"`).
|
|
419
|
-
*/
|
|
420
|
-
interface A11yColumnHeader {
|
|
421
|
-
col: number;
|
|
422
|
-
text: string;
|
|
423
|
-
label: string;
|
|
424
|
-
}
|
|
425
|
-
/**
|
|
426
|
-
* One mirrored row: its 1-based header label and the cells left-to-right.
|
|
427
|
-
*/
|
|
428
|
-
interface A11yRow {
|
|
429
|
-
row: number;
|
|
430
|
-
header: string;
|
|
431
|
-
cells: A11yCell[];
|
|
432
|
-
}
|
|
433
|
-
/**
|
|
434
|
-
* The full offscreen grid mirror for the current frame.
|
|
435
|
-
*/
|
|
436
|
-
interface A11yGrid {
|
|
437
|
-
label: string;
|
|
438
|
-
sheetName: string;
|
|
439
|
-
columnHeaders: A11yColumnHeader[];
|
|
440
|
-
rows: A11yRow[];
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
/**
|
|
444
|
-
* Pure a11y grid builder: turns a display list plus the current selection into a
|
|
445
|
-
* serializable {@link A11yGrid} the chrome renders offscreen for screen readers.
|
|
446
|
-
* Cell text is recovered from the frame's clipped text commands, keyed by cell
|
|
447
|
-
* box origin; geometry and addresses come from the frame's grid metadata. No
|
|
448
|
-
* DOM, no i18n import — label templates arrive as a param.
|
|
449
|
-
*/
|
|
450
|
-
|
|
451
|
-
/**
|
|
452
|
-
* Build the offscreen grid mirror for a frame. Returns an empty grid (no rows)
|
|
453
|
-
* when the frame carries no grid metadata, so the chrome can render nothing
|
|
454
|
-
* rather than guess geometry.
|
|
455
|
-
*/
|
|
456
|
-
declare function buildA11yGrid(displayList: DisplayList, selection: Selection | null, sheetName: string, t: A11yStrings): A11yGrid;
|
|
457
|
-
|
|
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 };
|