@file-viewer/renderer-spreadsheet 3.3.6 → 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,5 +1,5 @@
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;
@@ -49,6 +49,8 @@ export interface VirtualSheetState {
49
49
  totalCols: number;
50
50
  windowSize: number;
51
51
  indexOffset: number;
52
+ freeze?: SheetFreezePane;
53
+ visibleFrozenColumns?: number;
52
54
  defaults: SheetDefaults;
53
55
  dataKeys: string[];
54
56
  rows: VirtualRow[];
@@ -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;
@@ -34,6 +34,8 @@ const BORDER_STYLE_PRIORITY = {
34
34
  const HEADER_FONT = `bold 12px ${TABLE_FONT_FAMILY}`;
35
35
  const BODY_FONT = `${TABLE_FONT_SIZE}px ${TABLE_FONT_FAMILY}`;
36
36
  const MAX_OVERFLOW_SCAN_COLS = 32;
37
+ const MIN_SCROLLABLE_PANE_WIDTH = 24;
38
+ const VERTICAL_SCROLLBAR_TRACK_WIDTH = 14;
37
39
  let measureCanvas;
38
40
  const textWidthCache = new Map();
39
41
  const normalizeZoomScale = (scale = 1) => {
@@ -270,9 +272,10 @@ export const detectIndexOffset = (ws, mode = 'source') => {
270
272
  return 1;
271
273
  };
272
274
  export const buildColumns = (ws, mode = 'source') => {
273
- var _a;
275
+ var _a, _b, _c;
274
276
  const columnsMeta = getSheetColumnsMeta(ws);
275
277
  const colWidths = getSheetColWidths(ws);
278
+ const frozenColumns = ((_b = (_a = ws.structure) === null || _a === void 0 ? void 0 : _a.freeze) === null || _b === void 0 ? void 0 : _b.columns) || 0;
276
279
  const columns = [{
277
280
  key: INDEX_COLUMN_KEY,
278
281
  title: mode === 'legacy-records' ? '#' : '',
@@ -290,7 +293,7 @@ export const buildColumns = (ws, mode = 'source') => {
290
293
  overflowTooltipHeaderShow: false
291
294
  }];
292
295
  const dataKeys = [];
293
- for (let index = 0; index < (((_a = ws.meta) === null || _a === void 0 ? void 0 : _a.totalCols) || 0); index += 1) {
296
+ for (let index = 0; index < (((_c = ws.meta) === null || _c === void 0 ? void 0 : _c.totalCols) || 0); index += 1) {
294
297
  const key = getDataKey(index);
295
298
  const column = columnsMeta === null || columnsMeta === void 0 ? void 0 : columnsMeta[index];
296
299
  const width = getColumnWidth(colWidths, index, ws.defaults.colWidth);
@@ -302,6 +305,7 @@ export const buildColumns = (ws, mode = 'source') => {
302
305
  title: (column === null || column === void 0 ? void 0 : column.title) || `${index + 1}`,
303
306
  width: hidden ? 0 : Math.max(Math.ceil(width), 1),
304
307
  hide: hidden,
308
+ ...(index < frozenColumns ? { fixed: 'left' } : {}),
305
309
  widthFillDisable: true,
306
310
  renderType: 'both',
307
311
  headerAlign: 'center',
@@ -344,6 +348,28 @@ export const getDisplayColumns = (columns, zoomScale = 1) => {
344
348
  }
345
349
  return columns.map(column => scaleColumn(column, normalizedScale));
346
350
  };
351
+ export const getSpreadsheetDisplayColumns = (columns, zoomScale, viewportWidth) => {
352
+ const display = getDisplayColumns(columns, zoomScale);
353
+ const available = viewportWidth > 0
354
+ ? Math.max(0, viewportWidth - VERTICAL_SCROLLBAR_TRACK_WIDTH - MIN_SCROLLABLE_PANE_WIDTH)
355
+ : Infinity;
356
+ let fixedWidth = getRenderColumnWidth(display[0]);
357
+ let frozenColumns = 0;
358
+ for (let index = 1; index < display.length; index += 1) {
359
+ const column = display[index];
360
+ if (column.fixed !== 'left')
361
+ break;
362
+ const nextWidth = fixedWidth + (column.hide ? 0 : getRenderColumnWidth(column));
363
+ if (frozenColumns === index - 1 && nextWidth <= available) {
364
+ fixedWidth = nextWidth;
365
+ frozenColumns = index;
366
+ }
367
+ else {
368
+ delete column.fixed;
369
+ }
370
+ }
371
+ return { columns: display, frozenColumns };
372
+ };
347
373
  export const getSearchColumnLeft = (columns, key) => {
348
374
  let left = 0;
349
375
  const visit = (list) => {
@@ -517,11 +543,15 @@ const isBlankOverflowTarget = (virtualState, row, rowIndex, dataColIndex) => {
517
543
  }
518
544
  return !hasRenderableValue(row[getDataKey(dataColIndex)]);
519
545
  };
546
+ const getFrozenColumnCount = (state) => { var _a, _b, _c; return (_c = (_a = state.visibleFrozenColumns) !== null && _a !== void 0 ? _a : (_b = state.freeze) === null || _b === void 0 ? void 0 : _b.columns) !== null && _c !== void 0 ? _c : 0; };
520
547
  const collectOverflowRoom = (virtualState, row, rowIndex, dataColIndex, direction) => {
521
548
  let room = 0;
549
+ const freeze = getFrozenColumnCount(virtualState);
550
+ const insideFrozenPane = dataColIndex < freeze;
522
551
  for (let step = 1; step <= MAX_OVERFLOW_SCAN_COLS; step += 1) {
523
552
  const nextColIndex = dataColIndex + step * direction;
524
- if (nextColIndex < 0 || nextColIndex >= virtualState.totalCols) {
553
+ if (nextColIndex < 0 || nextColIndex >= virtualState.totalCols ||
554
+ (nextColIndex < freeze) !== insideFrozenPane) {
525
555
  break;
526
556
  }
527
557
  if (!isBlankOverflowTarget(virtualState, row, rowIndex, nextColIndex)) {
@@ -582,9 +612,11 @@ const getLeftOverflowMirror = (virtualState, row, rowIndex, targetDataColIndex,
582
612
  if (!targetWidth) {
583
613
  return undefined;
584
614
  }
615
+ const freeze = getFrozenColumnCount(virtualState);
616
+ const firstPaneColumn = targetDataColIndex < freeze ? 0 : freeze;
585
617
  for (let step = 1; step <= MAX_OVERFLOW_SCAN_COLS; step += 1) {
586
618
  const sourceDataColIndex = targetDataColIndex - step;
587
- if (sourceDataColIndex < 0) {
619
+ if (sourceDataColIndex < firstPaneColumn) {
588
620
  break;
589
621
  }
590
622
  const sourceColumn = virtualState.columns[sourceDataColIndex + 1];
@@ -908,14 +940,21 @@ export const createTableConfig = ({ hostHeight, darkMode = false, resizableColum
908
940
  const scaledCellWidth = scaleNumber(sheetDefaults.colWidth, normalizedScale);
909
941
  const headerStyle = getIndexCellStyle(normalizedScale, darkMode);
910
942
  const loadingStyle = getLoadingCellStyle(normalizedScale, darkMode);
911
- let firstVisibleColumn = 1;
943
+ const frozenColumns = getFrozenColumnCount(virtualState);
944
+ let firstVisibleColumn = frozenColumns + 1;
912
945
  const getProjectedMerge = (rowIndex, colIndex, column) => {
913
946
  const cellKey = getCellCacheKey(rowIndex, colIndex, column);
914
- const anchorKey = virtualState.mergeCoveredMap.get(cellKey);
915
- const merge = anchorKey ? virtualState.mergeStartMap.get(anchorKey) : undefined;
947
+ const anchorKey = virtualState.mergeCoveredMap.get(cellKey) || cellKey;
948
+ const merge = virtualState.mergeStartMap.get(anchorKey);
916
949
  const displayCol = getDataColumnIndex(column, colIndex) + 1;
917
- if (!merge || merge.row !== rowIndex || displayCol !== firstVisibleColumn ||
918
- merge.col >= displayCol || displayCol >= merge.col + merge.colspan) {
950
+ if (!merge || merge.row !== rowIndex) {
951
+ return undefined;
952
+ }
953
+ const mergeEnd = merge.col + merge.colspan;
954
+ const frozenSegment = displayCol === merge.col && merge.col <= frozenColumns && mergeEnd > frozenColumns + 1;
955
+ const scrollingSegment = displayCol === firstVisibleColumn && displayCol > frozenColumns &&
956
+ merge.col < displayCol && displayCol < mergeEnd;
957
+ if (!frozenSegment && !scrollingSegment) {
919
958
  return undefined;
920
959
  }
921
960
  let width = 0;
@@ -927,11 +966,12 @@ export const createTableConfig = ({ hostHeight, darkMode = false, resizableColum
927
966
  if (col < displayCol)
928
967
  offsetLeft += scaledWidth;
929
968
  }
930
- return { merge, anchorKey: anchorKey, width, offsetLeft, colspan: merge.col + merge.colspan - displayCol };
969
+ const segmentEnd = frozenSegment ? frozenColumns + 1 : mergeEnd;
970
+ return { merge, anchorKey, width, offsetLeft, colspan: segmentEnd - displayCol, frozenSegment };
931
971
  };
932
972
  const spanMethod = ({ rowIndex, colIndex, column, visibleLeafColumns }) => {
933
973
  if (visibleLeafColumns === null || visibleLeafColumns === void 0 ? void 0 : visibleLeafColumns.length) {
934
- const visibleDataColumns = visibleLeafColumns.filter(item => item.key !== INDEX_COLUMN_KEY && isVisibleDataColumn(item));
974
+ const visibleDataColumns = visibleLeafColumns.filter(item => item.key !== INDEX_COLUMN_KEY && !item.fixed && isVisibleDataColumn(item));
935
975
  if (visibleDataColumns.length) {
936
976
  firstVisibleColumn = Math.min(...visibleDataColumns.map(item => getDataColumnIndex(item, 1) + 1));
937
977
  }
@@ -994,7 +1034,8 @@ export const createTableConfig = ({ hostHeight, darkMode = false, resizableColum
994
1034
  : undefined;
995
1035
  const match = searchCell === null || searchCell === void 0 ? void 0 : searchCell(rowIndex, dataColIndex);
996
1036
  const renderText = shouldRenderTextInOverlay(style, column) || !!overflowLayout || !!mirror || !!match;
997
- const comment = commentsByCell.get(cellKey);
1037
+ const hasFrozenAnchor = projected && !projected.frozenSegment && projected.merge.col <= frozenColumns;
1038
+ const comment = hasFrozenAnchor ? undefined : commentsByCell.get(cellKey);
998
1039
  if (!hasBorder(style) && !renderText && !comment) {
999
1040
  return undefined;
1000
1041
  }
@@ -1009,7 +1050,9 @@ export const createTableConfig = ({ hostHeight, darkMode = false, resizableColum
1009
1050
  const collapsedStyle = hasBorder(style)
1010
1051
  ? getCollapsedBorderStyle(virtualState, rowIndex, dataColIndex, baseStyle, normalizedScale)
1011
1052
  : baseStyle;
1012
- renderCellOverlay(cellEl, projected ? { ...collapsedStyle, borderLeft: undefined } : collapsedStyle, (mirror === null || mirror === void 0 ? void 0 : mirror.style) || collapsedStyle, mirror ? mirror.value : renderValue, renderText, (mirror === null || mirror === void 0 ? void 0 : mirror.overflowLayout) || overflowLayout, normalizedScale);
1053
+ renderCellOverlay(cellEl, (projected === null || projected === void 0 ? void 0 : projected.frozenSegment)
1054
+ ? { ...collapsedStyle, borderRight: undefined }
1055
+ : projected ? { ...collapsedStyle, borderLeft: undefined } : collapsedStyle, (mirror === null || mirror === void 0 ? void 0 : mirror.style) || collapsedStyle, mirror ? mirror.value : renderValue, renderText, (mirror === null || mirror === void 0 ? void 0 : mirror.overflowLayout) || overflowLayout, normalizedScale);
1013
1056
  if (comment) {
1014
1057
  cellEl.style.pointerEvents = 'auto';
1015
1058
  const indicator = cellEl.ownerDocument.createElement('button');
@@ -1076,6 +1119,7 @@ export const createTableConfig = ({ hostHeight, darkMode = false, resizableColum
1076
1119
  EDIT_BG_COLOR: darkMode ? '#18212f' : '#ffffff',
1077
1120
  PLACEHOLDER_COLOR: darkMode ? '#94a3b8' : '#8a94a3',
1078
1121
  SCROLLER_COLOR: darkMode ? '#475569' : '#c1c7d0',
1122
+ SCROLLER_TRACK_SIZE: VERTICAL_SCROLLBAR_TRACK_WIDTH,
1079
1123
  SCROLLER_FOCUS_COLOR: darkMode ? '#64748b' : '#9aa0a6',
1080
1124
  SELECT_ROW_COL_BG_COLOR: EXCEL_GREEN_SOFT,
1081
1125
  SELECT_AREA_COLOR: 'rgba(33, 163, 102, 0.14)',
@@ -775,12 +775,16 @@ class SheetJsModel {
775
775
  });
776
776
  }
777
777
  getStructure() {
778
- var _a;
778
+ var _a, _b, _c, _d;
779
+ const layout = this.ws['!fileViewerLayout'];
780
+ const rows = Math.min((_b = (_a = layout === null || layout === void 0 ? void 0 : layout.freeze) === null || _a === void 0 ? void 0 : _a.rows) !== null && _b !== void 0 ? _b : 0, this.totalRows);
781
+ const columns = Math.min((_d = (_c = layout === null || layout === void 0 ? void 0 : layout.freeze) === null || _c === void 0 ? void 0 : _c.columns) !== null && _d !== void 0 ? _d : 0, this.totalCols);
779
782
  return {
780
783
  merge: this.getAllMerge(),
781
784
  colWidths: this.getColWidths(),
782
785
  rowHeights: this.getAllRowHeights(),
783
- rowSizing: (_a = this.ws['!fileViewerLayout']) === null || _a === void 0 ? void 0 : _a.rowSizing,
786
+ rowSizing: layout === null || layout === void 0 ? void 0 : layout.rowSizing,
787
+ ...(rows || columns ? { freeze: { rows, columns } } : {}),
784
788
  columns: this.getColumns(),
785
789
  images: this.getImages(),
786
790
  charts: this.getCharts()
@@ -0,0 +1,6 @@
1
+ export type SpreadsheetEncryptionErrorCode = 'encrypted' | 'invalid-password' | 'unsupported-encryption';
2
+ export declare class SpreadsheetEncryptionError extends Error {
3
+ readonly code: SpreadsheetEncryptionErrorCode;
4
+ constructor(code: SpreadsheetEncryptionErrorCode);
5
+ }
6
+ export declare function decryptSpreadsheetPackage(data: ArrayBuffer, fileType: string | undefined, password?: string, signal?: AbortSignal): Promise<ArrayBuffer>;