@betteroffice/xlsx 0.2.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
@@ -1,204 +1,5 @@
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
- clip?: Rect;
36
- }
37
- /**
38
- * Stroke a straight line — gridlines, cell borders, frozen-pane dividers.
39
- */
40
- interface LineCmd {
41
- op: 'line';
42
- x1: number;
43
- y1: number;
44
- x2: number;
45
- y2: number;
46
- width: number;
47
- color: string;
48
- /**
49
- * Stroke pattern. Absent/`undefined` is solid; `'dashed'`/`'dotted'` apply a
50
- * dash pattern; `'double'` draws two thin parallel passes offset by ±. Skip-
51
- * serialized at its default in Rust, so a solid line omits the field.
52
- */
53
- style?: 'dashed' | 'dotted' | 'double';
54
- clip?: Rect;
55
- }
56
- type GeometryPathCommand = {
57
- type: 'move';
58
- x: number;
59
- y: number;
60
- } | {
61
- type: 'line';
62
- x: number;
63
- y: number;
64
- } | {
65
- type: 'quad';
66
- cpx: number;
67
- cpy: number;
68
- x: number;
69
- y: number;
70
- } | {
71
- type: 'cubic';
72
- cp1x: number;
73
- cp1y: number;
74
- cp2x: number;
75
- cp2y: number;
76
- x: number;
77
- y: number;
78
- } | {
79
- type: 'close';
80
- };
81
- interface PathStroke {
82
- color: string;
83
- width: number;
84
- }
85
- interface PathCmd {
86
- op: 'path';
87
- commands: GeometryPathCommand[];
88
- fill: string;
89
- stroke?: PathStroke;
90
- clip?: Rect;
91
- }
92
- /**
93
- * Paint a single-line text run. Spreadsheet cell text is single-line and
94
- * clipped to the cell box, so `clip` is the cell rect and `align` places the
95
- * run within it. Text metrics are owned upstream in Rust.
96
- */
97
- interface TextCmd {
98
- op: 'text';
99
- x: number;
100
- y: number;
101
- text: string;
102
- /** Font size in points. */
103
- fontSize: number;
104
- /** resolved font color (`#rrggbb`); a number-format color prefix wins upstream. */
105
- color: string;
106
- /** clip rectangle; the backend saves/clips/restores around the fill. */
107
- clip?: Rect;
108
- align?: TextAlign;
109
- /**
110
- * Font style facets resolved from the cell's style. All skip-serialized at
111
- * `false` in Rust, so an unstyled run omits them; treat absent as `false`.
112
- */
113
- bold?: boolean;
114
- italic?: boolean;
115
- underline?: boolean;
116
- strike?: boolean;
117
- highlight?: string;
118
- dashedUnderline?: boolean;
119
- /** css/font family from the style font; the backend falls back to its default. */
120
- fontFamily?: string;
121
- /**
122
- * Preview text that is not the cell's committed value (a proposal ghost's
123
- * `new` text). Painted normally, but excluded from a11y text recovery.
124
- */
125
- ghost?: boolean;
126
- chart?: boolean;
127
- }
128
- /**
129
- * One draw command; discriminated on `op`.
130
- */
131
- type DrawCmd = FillRectCmd | LineCmd | PathCmd | TextCmd;
132
- /**
133
- * Grid metadata for the frame: which sheet cells the visible tracks map to and
134
- * their viewport-local pixel boundaries. `rowOffsets[i]`/`colOffsets[i]` is the
135
- * leading edge of the i-th visible row/col in device-independent px from the
136
- * frame origin; both arrays have length `visible count + 1`, the last entry
137
- * being one-past-end (the trailing edge of the last visible track). The pure
138
- * hit-test and a11y seams read this to place clicks and mirror the grid without
139
- * re-deriving geometry.
140
- *
141
- * Hand-mirrored from crates/xlsx-render/src/display_list.rs — keep in sync.
142
- */
143
- interface GridMeta {
144
- startRow: number;
145
- startCol: number;
146
- rowIndices?: number[];
147
- colIndices?: number[];
148
- rowOffsets: number[];
149
- colOffsets: number[];
150
- }
151
- interface HyperlinkRegion {
152
- top: number;
153
- left: number;
154
- bottom: number;
155
- right: number;
156
- externalTarget?: string;
157
- location?: string;
158
- tooltip?: string;
159
- }
160
- /**
161
- * A chart's placement in the frame: the id that addresses it across the wasm
162
- * boundary, what a screen reader reads, whether the renderer managed to draw
163
- * it, its full viewport-local rect and the visible part after pane clipping. A
164
- * chart that degraded to a placeholder still gets a region, so it stays an
165
- * addressable object on the sheet.
166
- *
167
- * Hand-mirrored from crates/xlsx-render/src/display_list.rs — keep in sync.
168
- */
169
- interface ChartRegion {
170
- /**
171
- * the drawing part and the anchor in it, unique within a sheet. Opaque —
172
- * never the chart part's path, which two anchors may share.
173
- */
174
- id: string;
175
- label: string;
176
- /**
177
- * the chart could not be drawn; a neutral box occupies its rect instead.
178
- * skip-serialized at `false` in Rust, so treat absent as `false`.
179
- */
180
- placeholder?: boolean;
181
- rect: Rect;
182
- /** `rect` intersected with the pane band it paints in — the hit area. */
183
- clip: Rect;
184
- /** whether the anchor can be repinned; an absolute one cannot. */
185
- movable: boolean;
186
- }
187
- /** Former name of {@link ChartRegion}, when it carried the label alone. */
188
- type ChartA11yAttrs = ChartRegion;
189
- /**
190
- * A full frame to paint: logical size plus the ordered command stream. `grid`
191
- * is optional so a synthetic or pre-grid-metadata frame still type-checks; the
192
- * hit-test and a11y builders treat its absence as "no addressable cells".
193
- */
194
- interface DisplayList {
195
- width: number;
196
- height: number;
197
- commands: DrawCmd[];
198
- grid?: GridMeta;
199
- hyperlinks?: HyperlinkRegion[];
200
- charts?: ChartRegion[];
201
- }
1
+ import { S as Selection, C as CellAddr, m as SelectionLimits, d as Direction, M as MoveOpts, a as CellRange, K as KeyInput, k as SelectionData, l as SelectionHidden, n as SelectionMerges, j as SelectionAction, f as GridMeta, R as Rect, c as ChartRegion, D as DisplayList, H as HyperlinkRegion } from './types-DdoEoFSX.js';
2
+ export { b as ChartA11yAttrs, e as DrawCmd, F as FillRectCmd, G as GeometryPathCommand, L as LineCmd, P as PathCmd, g as PathStroke, h as PatternFillCmd, i as PatternType, T as TextAlign, o as TextCmd } from './types-DdoEoFSX.js';
202
3
 
203
4
  /**
204
5
  * Pure viewport types shared by the accessibility grid and canvas painter.
@@ -275,90 +76,6 @@ declare function clampScroll(state: ViewportState, colOffsets: TrackOffsets, row
275
76
  */
276
77
  declare function uniformOffsets(count: number, size: number): TrackOffsets;
277
78
 
278
- /**
279
- * Pure selection types. Plain data only — no DOM, no framework — so the model
280
- * is golden-testable. The chrome layer interprets the
281
- * declarative {@link SelectionAction}s the reducer emits.
282
- */
283
- /**
284
- * A single cell coordinate. `row`/`col` are zero-based sheet indices, not px.
285
- */
286
- interface CellAddr {
287
- row: number;
288
- col: number;
289
- }
290
- /**
291
- * An active selection as an anchor/focus pair. `anchor` is the fixed corner
292
- * (where the selection started); `focus` is the moving corner. A collapsed
293
- * selection has `anchor` equal to `focus`.
294
- */
295
- interface Selection {
296
- anchor: CellAddr;
297
- focus: CellAddr;
298
- }
299
- /**
300
- * A normalized, inclusive rectangle of cells. `top <= bottom`, `left <= right`.
301
- * Derived from a {@link Selection} by {@link normalizeRange}; the natural shape
302
- * for hit-testing, overlay rects, and range reads.
303
- */
304
- interface CellRange {
305
- top: number;
306
- left: number;
307
- bottom: number;
308
- right: number;
309
- }
310
- /**
311
- * A cardinal move direction for {@link moveFocus} and arrow-key handling.
312
- */
313
- type Direction = 'up' | 'down' | 'left' | 'right';
314
- /**
315
- * Grid bounds a move must stay inside: the used range is `[0, rows)` × `[0,
316
- * cols)`, and `rowsPerPage` is the viewport height in whole rows for
317
- * PageUp/PageDown steps.
318
- */
319
- interface SelectionLimits {
320
- rows: number;
321
- cols: number;
322
- rowsPerPage: number;
323
- }
324
- /**
325
- * Options for {@link moveFocus}: whether to extend (keep the anchor) or collapse
326
- * to a single cell, how many cells to step, and the grid bounds to clamp into.
327
- */
328
- interface MoveOpts {
329
- extend?: boolean;
330
- step?: number;
331
- limits: SelectionLimits;
332
- }
333
- /**
334
- * A keyboard event reduced to the fields the reducer reads. `metaKey`/`ctrlKey`
335
- * are both accepted so a caller need not normalize mac cmd vs win/linux ctrl.
336
- */
337
- interface KeyInput {
338
- key: string;
339
- shiftKey?: boolean;
340
- metaKey?: boolean;
341
- ctrlKey?: boolean;
342
- altKey?: boolean;
343
- }
344
- /**
345
- * The declarative outcome of a keystroke. The chrome interprets it: `move`
346
- * replaces the selection, `startEdit` opens the in-cell editor (seeding it with
347
- * `initialInput` when a printable key triggered it), `clear` deletes the
348
- * selected cells' contents, and `none` means the key was not handled here.
349
- */
350
- type SelectionAction = {
351
- type: 'move';
352
- selection: Selection;
353
- } | {
354
- type: 'startEdit';
355
- initialInput?: string;
356
- } | {
357
- type: 'clear';
358
- } | {
359
- type: 'none';
360
- };
361
-
362
79
  /**
363
80
  * Selection model: pure transforms over {@link Selection} data. Every function
364
81
  * returns a fresh value and never mutates its input, so state lives with the
@@ -370,7 +87,7 @@ type SelectionAction = {
370
87
  */
371
88
  declare function selectionAt(addr: CellAddr): Selection;
372
89
  /**
373
- * The normalized inclusive rectangle spanned by a selection's anchor and focus.
90
+ * The explicit bounds or normalized rectangle spanned by the endpoints.
374
91
  */
375
92
  declare function normalizeRange(sel: Selection): CellRange;
376
93
  /**
@@ -389,7 +106,9 @@ declare function extendTo(sel: Selection, addr: CellAddr, limits?: SelectionLimi
389
106
  /**
390
107
  * Move the focus one (or `step`) cells in a direction. When `extend` is set the
391
108
  * anchor holds and the range grows; otherwise the whole selection collapses onto
392
- * the new focus. The result is clamped to the grid bounds in `opts.limits`.
109
+ * the new focus. The result is clamped to the grid bounds in `opts.limits`. A
110
+ * merged area counts as one cell: the move starts from its far edge, and a
111
+ * collapsed selection that lands inside one lands on its anchor.
393
112
  */
394
113
  declare function moveFocus(sel: Selection, direction: Direction, opts: MoveOpts): Selection;
395
114
 
@@ -406,7 +125,7 @@ declare function moveFocus(sel: Selection, direction: Direction, opts: MoveOpts)
406
125
  * grid limits. Returns `{ type: 'none' }` for keys this layer does not own so
407
126
  * the chrome can fall through to its own handling.
408
127
  */
409
- declare function selectionKeyReducer(state: Selection, key: KeyInput, limits: SelectionLimits): SelectionAction;
128
+ declare function selectionKeyReducer(state: Selection, key: KeyInput, limits: SelectionLimits, data?: SelectionData, hidden?: SelectionHidden, merges?: SelectionMerges): SelectionAction;
410
129
 
411
130
  /**
412
131
  * Pure hit-testing over a frame's {@link GridMeta}: map a viewport-local point
@@ -458,7 +177,7 @@ declare function parseHyperlinkLocation(location: string, currentSheet: string):
458
177
  * the chrome hands the system clipboard the string this produces and feeds paste
459
178
  * text back through {@link fromTsv}.
460
179
  *
461
- * Security (CLAUDE.md formula-injection contract): a foreign spreadsheet treats
180
+ * Security: a foreign spreadsheet treats
462
181
  * a pasted cell as a formula when its text leads with `=`, `+`, `-`, `@`, or a
463
182
  * control char that can break the field. We defang such *text* with a leading
464
183
  * single quote so it pastes literally — but we export our own real formulas
@@ -568,4 +287,4 @@ interface A11yGrid {
568
287
  */
569
288
  declare function buildA11yGrid(displayList: DisplayList, selection: Selection | null, sheetName: string, t: A11yStrings): A11yGrid;
570
289
 
571
- export { type A11yCell, type A11yChart, type A11yColumnHeader, type A11yGrid, type A11yRow, type A11yStrings, type CellAddr, type CellInput, type CellRange, type ChartA11yAttrs, type ChartRegion, type Direction, type DisplayList, type DrawCmd, type FillRectCmd, type GeometryPathCommand, type GridMeta, type HyperlinkDestination, type HyperlinkRegion, type KeyInput, type LineCmd, type MoveOpts, type PathCmd, type PathStroke, type Rect, type Selection, type SelectionAction, type SelectionLimits, type TextAlign, type TextCmd, type TrackOffsets, type ViewportState, type VisibleCells, type VisibleRange, buildA11yGrid, cellAtPoint, cellCount, cellRect, chartRegionAtPoint, clampScroll, extendTo, fromTsv, hyperlinkAtCell, moveFocus, normalizeRange, parseHyperlinkLocation, rangeContains, rangeRect, safeExternalHyperlink, selectionAt, selectionKeyReducer, toTsv, totalExtent, trackCount, uniformOffsets, visibleCells, visibleRange };
290
+ export { type A11yCell, type A11yChart, type A11yColumnHeader, type A11yGrid, type A11yRow, type A11yStrings, CellAddr, type CellInput, CellRange, ChartRegion, Direction, DisplayList, GridMeta, type HyperlinkDestination, HyperlinkRegion, KeyInput, MoveOpts, Rect, Selection, SelectionAction, SelectionData, SelectionHidden, SelectionLimits, SelectionMerges, type TrackOffsets, type ViewportState, type VisibleCells, type VisibleRange, buildA11yGrid, cellAtPoint, cellCount, cellRect, chartRegionAtPoint, 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{w as buildA11yGrid,o as cellAtPoint,j as cellCount,p as cellRect,n as chartRegionAtPoint,e as clampScroll,k as extendTo,v as fromTsv,r as hyperlinkAtCell,l as moveFocus,h as normalizeRange,t as parseHyperlinkLocation,i as rangeContains,q as rangeRect,s as safeExternalHyperlink,g as selectionAt,m as selectionKeyReducer,u as toTsv,b as totalExtent,a as trackCount,f as uniformOffsets,d as visibleCells,c as visibleRange}from'./chunk-E6PJOEEH.js';import'./chunk-O2XFH626.js';
1
+ export{w as buildA11yGrid,o as cellAtPoint,j as cellCount,p as cellRect,n as chartRegionAtPoint,e as clampScroll,k as extendTo,v as fromTsv,r as hyperlinkAtCell,l as moveFocus,h as normalizeRange,t as parseHyperlinkLocation,i as rangeContains,q as rangeRect,s as safeExternalHyperlink,g as selectionAt,m as selectionKeyReducer,u as toTsv,b as totalExtent,a as trackCount,f as uniformOffsets,d as visibleCells,c as visibleRange}from'./chunk-SXM2HKJL.js';import'./chunk-O2XFH626.js';