@file-viewer/renderer-spreadsheet 3.3.5 → 3.3.7

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.en.md CHANGED
@@ -37,9 +37,17 @@ const options = {
37
37
  - Supports multiple sheets, horizontally scrollable sheet tabs, merged cells, row and column sizing, borders, fills, alignment, text color, Office 365 and WPS in-cell images, workbook drawing images, double-click image previews, the global zoom provider, and optional header drag column resizing.
38
38
  - TIFF drawings in XLSX files load the MIT-licensed UTIF.js decoder only when needed and are converted to PNG in the browser. Ordinary spreadsheets do not load the TIFF decoder.
39
39
  - Uses virtual rendering for interaction. Host components usually hide full-document print for spreadsheets to avoid printing only the current viewport.
40
+ - XLSX previews keep the rows and columns saved in each worksheet’s frozen panes visible while scrolling.
41
+ - Open password-protected Excel files in place. The renderer supports OOXML Agile AES and Standard AES, plus BIFF8 RC4 CryptoAPI and ASCII-password XOR. AES and RC4 CryptoAPI require Web Crypto in a secure browser context.
40
42
  - XLSX uses saved default and explicit column widths and point-based row heights. CSV/TSV retains content auto-fit and supports large decoded text without creating a second UTF-8 byte array.
41
43
  - Column units follow the workbook's Normal style. SimSun/NSimSun digit advances are converted from points before rounding; unmeasured custom fonts retain the standard fallback, so exact geometry can depend on the font.
42
44
 
45
+ ## Password-protected Excel files
46
+
47
+ Enter the workbook password in the preview. A wrong password can be retried, and cancelling offers a way to start again. The file is decrypted in memory in the selected parser, and downloads continue to return the original file. Reopening an encrypted workbook starts a new password request.
48
+
49
+ Set `options.spreadsheet.password` to supply a first attempt, or use `options.spreadsheet.requestPassword` to supply your own prompt. The callback receives `filename`, `attempt`, `reason` and an optional `error`. Return `null` or `undefined` to cancel. Extensible encryption, classic RC4 and BIFF before version 8 show an unsupported status.
50
+
43
51
  ## Fill the viewport for small Excel sheets
44
52
 
45
53
  `options.spreadsheet.fillViewport` defaults to `true` for spreadsheet formats, including Excel and CSV / TSV. Small and empty sheets show blank column headers (A / B / …), row numbers and grid cells using the worksheet's default sizes. Padding recalculates on resize, zoom and sheet changes, stays virtual, and never stretches existing cells or changes workbook data. Set it to `false` to show only the used range.
package/README.md CHANGED
@@ -37,9 +37,17 @@ const options = {
37
37
  - Supports multiple sheets, horizontally scrollable sheet tabs, merged cells, row and column sizing, borders, fills, alignment, text color, Office 365 and WPS in-cell images, workbook drawing images, double-click image previews, the global zoom provider, and optional header drag column resizing.
38
38
  - TIFF drawings in XLSX files load the MIT-licensed UTIF.js decoder only when needed and are converted to PNG in the browser. Ordinary spreadsheets do not load the TIFF decoder.
39
39
  - Uses virtual rendering for interaction. Host components usually hide full-document print for spreadsheets to avoid printing only the current viewport.
40
+ - XLSX previews keep the rows and columns saved in each worksheet’s frozen panes visible while scrolling.
41
+ - Open password-protected Excel files in place. The renderer supports OOXML Agile AES and Standard AES, plus BIFF8 RC4 CryptoAPI and ASCII-password XOR. AES and RC4 CryptoAPI require Web Crypto in a secure browser context.
40
42
  - XLSX uses saved default and explicit column widths and point-based row heights. CSV/TSV retains content auto-fit and supports large decoded text without creating a second UTF-8 byte array.
41
43
  - Column units follow the workbook's Normal style. SimSun/NSimSun digit advances are converted from points before rounding; unmeasured custom fonts retain the standard fallback, so exact geometry can depend on the font.
42
44
 
45
+ ## Password-protected Excel files
46
+
47
+ Enter the workbook password in the preview. A wrong password can be retried, and cancelling offers a way to start again. The file is decrypted in memory in the selected parser, and downloads continue to return the original file. Reopening an encrypted workbook starts a new password request.
48
+
49
+ Set `options.spreadsheet.password` to supply a first attempt, or use `options.spreadsheet.requestPassword` to supply your own prompt. The callback receives `filename`, `attempt`, `reason` and an optional `error`. Return `null` or `undefined` to cancel. Extensible encryption, classic RC4 and BIFF before version 8 show an unsupported status.
50
+
43
51
  ## Fill the viewport for small Excel sheets
44
52
 
45
53
  `options.spreadsheet.fillViewport` defaults to `true` for spreadsheet formats, including Excel and CSV / TSV. Small and empty sheets show blank column headers (A / B / …), row numbers and grid cells using the worksheet's default sizes. Padding recalculates on resize, zoom and sheet changes, stays virtual, and never stretches existing cells or changes workbook data. Set it to `false` to show only the used range.
package/README.zh-CN.md CHANGED
@@ -37,9 +37,17 @@ const options = {
37
37
  - 支持多 sheet、横向滚动标签栏、合并单元格、列宽/行高、边框、填充、对齐、文本颜色、Office 365 / WPS 单元格内嵌图片、workbook drawing 图片、图片双击大图预览、统一缩放 provider 和可选表头拖拽调整列宽。
38
38
  - XLSX drawing 中的 TIFF 图片会按需加载 MIT 许可的 UTIF.js,在浏览器内转换为 PNG;普通表格不会加载 TIFF 解码器。
39
39
  - 表格使用虚拟渲染,适合交互预览;完整打印按钮通常由上层能力判断隐藏,避免只打印当前视口。
40
+ - XLSX 预览读取每张工作表保存的冻结窗格,滚动时保留冻结的顶部行和左侧列。
41
+ - Excel 可在预览中输入打开密码。支持 OOXML 的 Agile AES、Standard AES,以及 BIFF8 的 RC4 CryptoAPI 和使用 ASCII 密码的 XOR。AES 和 RC4 CryptoAPI 需要浏览器安全上下文中的 Web Crypto。
40
42
  - XLSX 保留文件保存的默认列宽、显式列宽和以磅记录的行高;CSV/TSV 继续按内容调整列宽,大文本解析避免重复创建完整 UTF-8 字节数组。
41
43
  - 列宽单位以工作簿 Normal 样式为基准。宋体、新宋体的数字宽度先从磅转换为像素,再进行取整;尚未测定的自定义字体沿用标准回退,实际尺寸可能受字体影响。
42
44
 
45
+ ## 预览带打开密码的 Excel
46
+
47
+ 在预览区输入工作簿密码。输错可以重试,取消后可以重新输入。解密在当前解析路径的内存中完成,下载仍提供原文件,再次打开文件会重新开始密码流程。
48
+
49
+ 通过 `options.spreadsheet.password` 提供首次尝试的密码,或用 `options.spreadsheet.requestPassword` 接管密码输入。回调接收 `filename`、`attempt`、`reason` 和可选的 `error`,返回 `null` 或 `undefined` 取消。Extensible 加密、经典 RC4 和低于 BIFF8 的版本会显示暂不支持。
50
+
43
51
  ## 小内容 Excel 填满视口
44
52
 
45
53
  `options.spreadsheet.fillViewport` 默认 `true`,适用于 Excel、CSV / TSV 等表格格式。按工作表默认行高、列宽补充空白列标题(A / B / …)、行号和网格,让小表或空 Sheet 填满当前预览区域。容器 resize、缩放和切 Sheet 时重新计算,补充部分沿用虚拟画布,不生成整张 Excel 空表,不拉伸已有单元格,也不改变工作簿数据。设为 `false` 可只显示已用区域。
@@ -0,0 +1,26 @@
1
+ import type { SheetImage } from './worker/type.js';
2
+ type Bounds = Pick<SheetImage, 'left' | 'top' | 'width' | 'height'>;
3
+ export interface DrawingPlacement<T> extends Bounds {
4
+ drawing: T;
5
+ clip?: {
6
+ left: number;
7
+ top: number;
8
+ right: number;
9
+ bottom: number;
10
+ };
11
+ }
12
+ export declare function getDrawingPlacements<T>(drawing: T, bounds: Bounds, viewport: {
13
+ width: number;
14
+ height: number;
15
+ scrollX: number;
16
+ scrollY: number;
17
+ }, frozenWidth: number, frozenHeight: number): DrawingPlacement<T>[];
18
+ export declare function getDrawingPlacementStyle(placement: DrawingPlacement<unknown>): {
19
+ left: string;
20
+ top: string;
21
+ width: string;
22
+ height: string;
23
+ clipPath: string;
24
+ };
25
+ export declare function drawingContainsPoint(placement: DrawingPlacement<unknown>, x: number, y: number): boolean;
26
+ export {};
@@ -0,0 +1,48 @@
1
+ export function getDrawingPlacements(drawing, bounds, viewport, frozenWidth, frozenHeight) {
2
+ if (!frozenWidth && !frozenHeight) {
3
+ const left = bounds.left - viewport.scrollX;
4
+ const top = bounds.top - viewport.scrollY;
5
+ const margin = 240;
6
+ return left + bounds.width >= -margin && left <= viewport.width + margin &&
7
+ top + bounds.height >= -margin && top <= viewport.height + margin
8
+ ? [{ drawing, ...bounds, left, top }]
9
+ : [];
10
+ }
11
+ const horizontal = frozenWidth > 0
12
+ ? [[0, frozenWidth, 0], [frozenWidth, viewport.width, viewport.scrollX]]
13
+ : [[0, viewport.width, viewport.scrollX]];
14
+ const vertical = frozenHeight > 0
15
+ ? [[0, frozenHeight, 0], [frozenHeight, viewport.height, viewport.scrollY]]
16
+ : [[0, viewport.height, viewport.scrollY]];
17
+ return horizontal.flatMap(([minX, maxX, x]) => vertical.flatMap(([minY, maxY, y]) => {
18
+ const left = bounds.left - x;
19
+ const top = bounds.top - y;
20
+ const clip = {
21
+ left: Math.max(left, minX),
22
+ top: Math.max(top, minY),
23
+ right: Math.min(left + bounds.width, maxX),
24
+ bottom: Math.min(top + bounds.height, maxY),
25
+ };
26
+ return clip.right > clip.left && clip.bottom > clip.top
27
+ ? [{ drawing, ...bounds, left, top, clip }]
28
+ : [];
29
+ }));
30
+ }
31
+ export function getDrawingPlacementStyle(placement) {
32
+ const { left, top, width, height, clip } = placement;
33
+ return {
34
+ left: `${left}px`,
35
+ top: `${top}px`,
36
+ width: `${width}px`,
37
+ height: `${height}px`,
38
+ clipPath: clip
39
+ ? `inset(${clip.top - top}px ${left + width - clip.right}px ${top + height - clip.bottom}px ${clip.left - left}px)`
40
+ : '',
41
+ };
42
+ }
43
+ export function drawingContainsPoint(placement, x, y) {
44
+ var _a, _b, _c, _d;
45
+ const { left, top, width, height, clip } = placement;
46
+ return x >= ((_a = clip === null || clip === void 0 ? void 0 : clip.left) !== null && _a !== void 0 ? _a : left) && x <= ((_b = clip === null || clip === void 0 ? void 0 : clip.right) !== null && _b !== void 0 ? _b : left + width) &&
47
+ y >= ((_c = clip === null || clip === void 0 ? void 0 : clip.top) !== null && _c !== void 0 ? _c : top) && y <= ((_d = clip === null || clip === void 0 ? void 0 : clip.bottom) !== null && _d !== void 0 ? _d : top + height);
48
+ }
@@ -0,0 +1,4 @@
1
+ export declare function installFrozenRows(table: unknown, getRequestedCount: () => number): {
2
+ count: number;
3
+ height: number;
4
+ };
@@ -0,0 +1,117 @@
1
+ function clipCellHitTest(cell, minY, maxY) {
2
+ if (cell.drawY >= minY && cell.drawY + cell.visibleHeight <= maxY)
3
+ return;
4
+ for (const hitTest of ['isInside', 'isInsideVisible']) {
5
+ const original = cell[hitTest].bind(cell);
6
+ cell[hitTest] = (x, y) => y >= minY && y < maxY && original(x, y);
7
+ }
8
+ }
9
+ export function installFrozenRows(table, getRequestedCount) {
10
+ const { body, ctx, overlayer } = table;
11
+ const layout = { count: 0, height: 0 };
12
+ if (!body || typeof body.update !== 'function' || typeof body.draw !== 'function')
13
+ return layout;
14
+ const update = body.update.bind(body);
15
+ const draw = body.draw.bind(body);
16
+ let frozen = [];
17
+ let scrolling = [];
18
+ if (typeof (overlayer === null || overlayer === void 0 ? void 0 : overlayer.getBody) === 'function') {
19
+ const getBodyOverlay = overlayer.getBody.bind(overlayer);
20
+ overlayer.getBody = () => {
21
+ const overlay = getBodyOverlay();
22
+ if (!layout.height)
23
+ return overlay;
24
+ overlay.views = overlay.views.flatMap(pane => {
25
+ const frozenCells = [];
26
+ const scrollingCells = [];
27
+ for (const cell of pane.cells) {
28
+ const cells = cell.cellType === 'body' && cell.rowIndex < layout.count ? frozenCells : scrollingCells;
29
+ cells.push(cell);
30
+ }
31
+ const cut = `${layout.height - Number.parseFloat(pane.style.top)}px`;
32
+ return [
33
+ { ...pane, cells: scrollingCells, style: { ...pane.style, clipPath: `inset(${cut} 0 0)` } },
34
+ { ...pane, cells: frozenCells, style: { ...pane.style, clipPath: `inset(0 0 calc(100% - ${cut}))` } },
35
+ ].filter(view => view.cells.length);
36
+ });
37
+ return overlay;
38
+ };
39
+ }
40
+ body.update = () => {
41
+ update();
42
+ layout.count = 0;
43
+ layout.height = 0;
44
+ frozen = [];
45
+ scrolling = [];
46
+ const requestedCount = Math.min(getRequestedCount(), ctx.body.data.length);
47
+ const sample = body.renderRows[0];
48
+ if (!requestedCount || !sample || ctx.body.visibleHeight <= 0)
49
+ return;
50
+ const positions = ctx.database;
51
+ const limit = ctx.body.visibleHeight - Math.min(24, ctx.body.visibleHeight / 4);
52
+ let low = 0;
53
+ let high = requestedCount;
54
+ while (low < high) {
55
+ const mid = Math.ceil((low + high) / 2);
56
+ if (positions.getPositionForRowIndex(mid - 1).bottom <= limit)
57
+ low = mid;
58
+ else
59
+ high = mid - 1;
60
+ }
61
+ if (!low)
62
+ return;
63
+ layout.count = low;
64
+ layout.height = positions.getPositionForRowIndex(low - 1).bottom;
65
+ const cut = ctx.body.y + layout.height;
66
+ const end = ctx.body.y + ctx.body.visibleHeight;
67
+ scrolling = body.renderRows.filter(row => row.rowIndex >= low);
68
+ for (let index = 0; index < low; index += 1) {
69
+ const { top, height } = positions.getPositionForRowIndex(index);
70
+ if (height <= 0.1)
71
+ continue;
72
+ const row = Reflect.construct(sample.constructor, [
73
+ ctx, index, 0, ctx.body.y + top + ctx.scrollY, ctx.header.width, height, ctx.body.data[index],
74
+ ]);
75
+ row.cells.forEach(cell => clipCellHitTest(cell, ctx.body.y, cut));
76
+ frozen.push(row);
77
+ }
78
+ for (const row of scrolling) {
79
+ row.cells.forEach(cell => clipCellHitTest(cell, cut, end));
80
+ }
81
+ body.renderRows = [...frozen, ...scrolling];
82
+ ctx.body.renderRows = body.renderRows;
83
+ };
84
+ body.draw = () => {
85
+ if (!layout.height) {
86
+ draw();
87
+ return;
88
+ }
89
+ const canvas = ctx.canvasElement.getContext('2d');
90
+ if (!canvas)
91
+ return;
92
+ const allRows = body.renderRows;
93
+ const top = ctx.body.y;
94
+ try {
95
+ for (const [rows, y, height] of [
96
+ [scrolling, top + layout.height, ctx.body.visibleHeight - layout.height],
97
+ [frozen, top, layout.height],
98
+ ]) {
99
+ body.renderRows = rows;
100
+ canvas.save();
101
+ try {
102
+ canvas.beginPath();
103
+ canvas.rect(0, y, ctx.body.visibleWidth, height);
104
+ canvas.clip();
105
+ draw();
106
+ }
107
+ finally {
108
+ canvas.restore();
109
+ }
110
+ }
111
+ }
112
+ finally {
113
+ body.renderRows = allRows;
114
+ }
115
+ };
116
+ return layout;
117
+ }
@@ -0,0 +1,7 @@
1
+ import type { createFileViewerTranslator, FileViewerSpreadsheetPasswordRequestReason } from '@file-viewer/core';
2
+ export declare const spreadsheetPasswordStyle = "\n.excel-wrapper .excel-password-dialog{position:absolute;inset:0;z-index:1250;display:grid;place-items:center;overflow:auto;padding:16px;background:rgba(15,23,42,.56)}\n.excel-wrapper .excel-password-dialog[hidden]{display:none}\n.excel-wrapper .excel-password-card{display:grid;gap:14px;width:min(100%,380px);padding:22px;border-radius:14px;background:#fff;color:#172033;box-shadow:0 20px 54px rgba(0,0,0,.25)}\n.excel-wrapper .excel-password-card h2,.excel-wrapper .excel-password-card p{margin:0}\n.excel-wrapper .excel-password-card h2{font-size:17px;line-height:1.35}\n.excel-wrapper .excel-password-card input{min-width:0;padding:10px 12px;border:1px solid #94a3b8;border-radius:8px;background:transparent;color:inherit;font:inherit}\n.excel-wrapper .excel-password-card [role='alert']{font-size:13px;color:#b42318}\n.excel-wrapper .excel-password-actions{display:flex;flex-wrap:wrap;justify-content:flex-end;gap:8px}\n.excel-wrapper .excel-password-actions button,.excel-wrapper .excel-password-retry{padding:7px 11px;border:1px solid currentColor;border-radius:8px;background:transparent;color:inherit;font:inherit;cursor:pointer}\n.excel-wrapper .excel-password-actions button[type='submit']{border-color:#16653f;background:#16653f;color:#fff}\n.excel-wrapper .excel-password-retry{margin-inline-start:10px}\n.excel-wrapper .excel-password-card :focus-visible,.excel-wrapper .excel-password-retry:focus-visible{outline:2px solid #27845c;outline-offset:2px}\n.excel-wrapper[data-spreadsheet-theme='dark'] .excel-password-card{background:#172033;color:#f8fafc}\n.excel-wrapper[data-spreadsheet-theme='dark'] .excel-password-card [role='alert']{color:#fca5a5}\n";
3
+ export declare function createSpreadsheetPasswordPrompt(document: Document, t: ReturnType<typeof createFileViewerTranslator>): {
4
+ element: HTMLDivElement;
5
+ request(nextReason: FileViewerSpreadsheetPasswordRequestReason): Promise<string | null>;
6
+ close: (password?: string | null) => void;
7
+ };
@@ -0,0 +1,94 @@
1
+ export const spreadsheetPasswordStyle = `
2
+ .excel-wrapper .excel-password-dialog{position:absolute;inset:0;z-index:1250;display:grid;place-items:center;overflow:auto;padding:16px;background:rgba(15,23,42,.56)}
3
+ .excel-wrapper .excel-password-dialog[hidden]{display:none}
4
+ .excel-wrapper .excel-password-card{display:grid;gap:14px;width:min(100%,380px);padding:22px;border-radius:14px;background:#fff;color:#172033;box-shadow:0 20px 54px rgba(0,0,0,.25)}
5
+ .excel-wrapper .excel-password-card h2,.excel-wrapper .excel-password-card p{margin:0}
6
+ .excel-wrapper .excel-password-card h2{font-size:17px;line-height:1.35}
7
+ .excel-wrapper .excel-password-card input{min-width:0;padding:10px 12px;border:1px solid #94a3b8;border-radius:8px;background:transparent;color:inherit;font:inherit}
8
+ .excel-wrapper .excel-password-card [role='alert']{font-size:13px;color:#b42318}
9
+ .excel-wrapper .excel-password-actions{display:flex;flex-wrap:wrap;justify-content:flex-end;gap:8px}
10
+ .excel-wrapper .excel-password-actions button,.excel-wrapper .excel-password-retry{padding:7px 11px;border:1px solid currentColor;border-radius:8px;background:transparent;color:inherit;font:inherit;cursor:pointer}
11
+ .excel-wrapper .excel-password-actions button[type='submit']{border-color:#16653f;background:#16653f;color:#fff}
12
+ .excel-wrapper .excel-password-retry{margin-inline-start:10px}
13
+ .excel-wrapper .excel-password-card :focus-visible,.excel-wrapper .excel-password-retry:focus-visible{outline:2px solid #27845c;outline-offset:2px}
14
+ .excel-wrapper[data-spreadsheet-theme='dark'] .excel-password-card{background:#172033;color:#f8fafc}
15
+ .excel-wrapper[data-spreadsheet-theme='dark'] .excel-password-card [role='alert']{color:#fca5a5}
16
+ `;
17
+ export function createSpreadsheetPasswordPrompt(document, t) {
18
+ const element = document.createElement('div');
19
+ element.className = 'excel-password-dialog';
20
+ element.hidden = true;
21
+ element.setAttribute('role', 'dialog');
22
+ element.setAttribute('aria-modal', 'true');
23
+ t.attr(element, 'aria-label', 'spreadsheet.password.title');
24
+ const form = document.createElement('form');
25
+ form.className = 'excel-password-card';
26
+ const heading = t.text(document.createElement('h2'), 'spreadsheet.password.title');
27
+ const input = document.createElement('input');
28
+ input.type = 'password';
29
+ input.autocomplete = 'off';
30
+ t.attr(input, 'aria-label', 'spreadsheet.password.title');
31
+ const message = document.createElement('p');
32
+ message.setAttribute('role', 'alert');
33
+ const actions = document.createElement('div');
34
+ actions.className = 'excel-password-actions';
35
+ const cancel = t.text(document.createElement('button'), 'archive.password.cancel');
36
+ cancel.type = 'button';
37
+ const submit = t.text(document.createElement('button'), 'archive.password.confirm');
38
+ submit.type = 'submit';
39
+ actions.append(cancel, submit);
40
+ form.append(heading, input, message, actions);
41
+ element.append(form);
42
+ let resolvePending;
43
+ let previousFocus = null;
44
+ let reason = 'encrypted';
45
+ const close = (password = null) => {
46
+ const complete = resolvePending;
47
+ resolvePending = undefined;
48
+ input.value = '';
49
+ element.hidden = true;
50
+ if (previousFocus === null || previousFocus === void 0 ? void 0 : previousFocus.isConnected)
51
+ previousFocus.focus({ preventScroll: true });
52
+ previousFocus = null;
53
+ complete === null || complete === void 0 ? void 0 : complete(password);
54
+ };
55
+ form.addEventListener('submit', event => {
56
+ event.preventDefault();
57
+ close(input.value);
58
+ });
59
+ cancel.addEventListener('click', () => close());
60
+ element.addEventListener('keydown', event => {
61
+ if (event.key === 'Escape') {
62
+ event.preventDefault();
63
+ event.stopPropagation();
64
+ close();
65
+ }
66
+ if (event.key !== 'Tab')
67
+ return;
68
+ if (event.shiftKey && event.target === input) {
69
+ event.preventDefault();
70
+ submit.focus();
71
+ }
72
+ else if (!event.shiftKey && event.target === submit) {
73
+ event.preventDefault();
74
+ input.focus();
75
+ }
76
+ });
77
+ return {
78
+ element,
79
+ request(nextReason) {
80
+ reason = nextReason;
81
+ const activeElement = document.activeElement;
82
+ previousFocus = activeElement && 'focus' in activeElement ? activeElement : null;
83
+ t.bind(message, node => {
84
+ node.textContent = reason === 'invalid-password' ? t('spreadsheet.password.invalid')
85
+ : reason === 'read-failed' ? t('spreadsheet.password.decryptFailed')
86
+ : '';
87
+ });
88
+ element.hidden = false;
89
+ input.focus({ preventScroll: true });
90
+ return new Promise(resolve => { resolvePending = resolve; });
91
+ },
92
+ close,
93
+ };
94
+ }
@@ -1,11 +1,12 @@
1
1
  import type { Align, Column, VerticalAlign } from 'e-virt-table';
2
- import type { CellMerge, SheetRichTextRun } from './worker/type.js';
2
+ import type { CellMerge, SheetFreezePane, SheetRichTextRun } from './worker/type.js';
3
3
  export declare const WINDOW_SIZE = 500;
4
4
  export declare const PREFETCH_AHEAD = 3;
5
5
  export declare const PREFETCH_BEHIND = 1;
6
6
  export declare const INDEX_COLUMN_KEY = "__index";
7
7
  export declare const ROW_KEY_FIELD = "__k";
8
8
  export declare const ROW_STATE_FIELD = "__s";
9
+ export declare const getOrdinaryWindowSize: (columns: number) => number;
9
10
  export interface SheetDefaults {
10
11
  rowHeight: number;
11
12
  colWidth: number;
@@ -46,7 +47,10 @@ export interface VirtualSheetState {
46
47
  active: boolean;
47
48
  totalRows: number;
48
49
  totalCols: number;
50
+ windowSize: number;
49
51
  indexOffset: number;
52
+ freeze?: SheetFreezePane;
53
+ visibleFrozenColumns?: number;
50
54
  defaults: SheetDefaults;
51
55
  dataKeys: string[];
52
56
  rows: VirtualRow[];
@@ -74,15 +78,16 @@ interface CollectWindowStartsOptions {
74
78
  far?: boolean;
75
79
  startRow: number;
76
80
  totalRows: number;
81
+ windowSize?: number;
77
82
  }
78
- export declare const createEmptyVirtualState: () => VirtualSheetState;
83
+ export declare const createEmptyVirtualState: (windowSize?: number) => VirtualSheetState;
79
84
  export declare const displayCellKey: (row: number, col: number) => string;
80
85
  export declare const getDataKey: (index: number) => string;
81
86
  export declare const getRowState: (row?: VirtualRow | null) => RowStateValue;
82
87
  export declare const buildRows: (count: number) => VirtualRow[];
83
- export declare const getMaxWindowStart: (totalRows: number) => number;
84
- export declare const clampWindowStart: (startRow?: number, totalRows?: number) => number;
85
- export declare const getWindowStart: (row?: number, totalRows?: number) => number;
86
- export declare const collectWindowStarts: ({ startRow, endRow, direction, totalRows, far }: CollectWindowStartsOptions) => number[];
87
- export declare const markWindowState: (rows: VirtualRow[], totalRows: number, windowStart: number, nextState: RowStateValue) => void;
88
+ export declare const getMaxWindowStart: (totalRows: number, windowSize?: number) => number;
89
+ export declare const clampWindowStart: (startRow?: number, totalRows?: number, windowSize?: number) => number;
90
+ export declare const getWindowStart: (row?: number, totalRows?: number, windowSize?: number) => number;
91
+ export declare const collectWindowStarts: ({ startRow, endRow, direction, totalRows, windowSize, far }: CollectWindowStartsOptions) => number[];
92
+ export declare const markWindowState: (rows: VirtualRow[], totalRows: number, windowStart: number, nextState: RowStateValue, windowSize?: number) => void;
88
93
  export {};
@@ -1,9 +1,11 @@
1
+ import { ORDINARY_GRID_BUDGET } from './sourceRegion.js';
1
2
  export const WINDOW_SIZE = 500;
2
3
  export const PREFETCH_AHEAD = 3;
3
4
  export const PREFETCH_BEHIND = 1;
4
5
  export const INDEX_COLUMN_KEY = '__index';
5
6
  export const ROW_KEY_FIELD = '__k';
6
7
  export const ROW_STATE_FIELD = '__s';
8
+ export const getOrdinaryWindowSize = (columns) => Math.min(WINDOW_SIZE, Math.max(1, Math.floor(ORDINARY_GRID_BUDGET.windowCells / Math.max(1, columns))));
7
9
  export const DEFAULT_SHEET_DEFAULTS = {
8
10
  rowHeight: 20,
9
11
  colWidth: 64
@@ -13,10 +15,11 @@ export const RowState = {
13
15
  Loading: 1,
14
16
  Loaded: 2
15
17
  };
16
- export const createEmptyVirtualState = () => ({
18
+ export const createEmptyVirtualState = (windowSize = WINDOW_SIZE) => ({
17
19
  active: false,
18
20
  totalRows: 0,
19
21
  totalCols: 0,
22
+ windowSize,
20
23
  indexOffset: 0,
21
24
  defaults: { ...DEFAULT_SHEET_DEFAULTS },
22
25
  dataKeys: [],
@@ -58,39 +61,39 @@ export const buildRows = (count) => {
58
61
  }
59
62
  return rows;
60
63
  };
61
- export const getMaxWindowStart = (totalRows) => {
64
+ export const getMaxWindowStart = (totalRows, windowSize = WINDOW_SIZE) => {
62
65
  if (!totalRows) {
63
66
  return 0;
64
67
  }
65
- return Math.floor(Math.max(totalRows - 1, 0) / WINDOW_SIZE) * WINDOW_SIZE;
68
+ return Math.floor(Math.max(totalRows - 1, 0) / windowSize) * windowSize;
66
69
  };
67
- export const clampWindowStart = (startRow = 0, totalRows = 0) => {
68
- return Math.min(Math.max(startRow, 0), getMaxWindowStart(totalRows));
70
+ export const clampWindowStart = (startRow = 0, totalRows = 0, windowSize = WINDOW_SIZE) => {
71
+ return Math.min(Math.max(startRow, 0), getMaxWindowStart(totalRows, windowSize));
69
72
  };
70
- export const getWindowStart = (row = 0, totalRows = 0) => {
71
- const start = Math.floor(Math.max(row, 0) / WINDOW_SIZE) * WINDOW_SIZE;
72
- return clampWindowStart(start, totalRows);
73
+ export const getWindowStart = (row = 0, totalRows = 0, windowSize = WINDOW_SIZE) => {
74
+ const start = Math.floor(Math.max(row, 0) / windowSize) * windowSize;
75
+ return clampWindowStart(start, totalRows, windowSize);
73
76
  };
74
- export const collectWindowStarts = ({ startRow, endRow, direction, totalRows, far = false }) => {
77
+ export const collectWindowStarts = ({ startRow, endRow, direction, totalRows, windowSize = WINDOW_SIZE, far = false }) => {
75
78
  const starts = new Set();
76
- const firstWindow = getWindowStart(startRow, totalRows);
77
- const lastWindow = getWindowStart(endRow, totalRows);
78
- for (let current = firstWindow; current <= lastWindow; current += WINDOW_SIZE) {
79
+ const firstWindow = getWindowStart(startRow, totalRows, windowSize);
80
+ const lastWindow = getWindowStart(endRow, totalRows, windowSize);
81
+ for (let current = firstWindow; current <= lastWindow; current += windowSize) {
79
82
  starts.add(current);
80
83
  }
81
84
  const ahead = far ? PREFETCH_AHEAD + 1 : PREFETCH_AHEAD;
82
85
  const behind = far ? PREFETCH_BEHIND + 1 : PREFETCH_BEHIND;
83
86
  const anchor = direction > 0 ? lastWindow : firstWindow;
84
87
  for (let step = 1; step <= ahead; step += 1) {
85
- starts.add(clampWindowStart(anchor + direction * step * WINDOW_SIZE, totalRows));
88
+ starts.add(clampWindowStart(anchor + direction * step * windowSize, totalRows, windowSize));
86
89
  }
87
90
  for (let step = 1; step <= behind; step += 1) {
88
- starts.add(clampWindowStart(anchor - direction * step * WINDOW_SIZE, totalRows));
91
+ starts.add(clampWindowStart(anchor - direction * step * windowSize, totalRows, windowSize));
89
92
  }
90
93
  return Array.from(starts);
91
94
  };
92
- export const markWindowState = (rows, totalRows, windowStart, nextState) => {
93
- const endRow = Math.min(windowStart + WINDOW_SIZE, totalRows);
95
+ export const markWindowState = (rows, totalRows, windowStart, nextState, windowSize = WINDOW_SIZE) => {
96
+ const endRow = Math.min(windowStart + windowSize, totalRows);
94
97
  for (let rowIndex = windowStart; rowIndex < endRow; rowIndex += 1) {
95
98
  const row = rows[rowIndex];
96
99
  if (!row) {
@@ -37,6 +37,10 @@ export declare const buildColumns: (ws: SheetModel, mode?: FileViewerSpreadsheet
37
37
  dataKeys: string[];
38
38
  };
39
39
  export declare const getDisplayColumns: (columns: Column[], zoomScale?: number) => Column[];
40
+ export declare const getSpreadsheetDisplayColumns: (columns: Column[], zoomScale: number, viewportWidth: number) => {
41
+ columns: Column[];
42
+ frozenColumns: number;
43
+ };
40
44
  export declare const getSearchColumnLeft: (columns: Column[], key: string) => number | undefined;
41
45
  export declare const createTextLayer: (documentRef: Document, value: unknown, style: CellStyleCache, padding: number) => HTMLSpanElement;
42
46
  export declare const createAutoHeightProbe: (documentRef: Document, value: unknown, style: CellStyleCache, width: number, zoom: number) => HTMLSpanElement;