@file-viewer/renderer-spreadsheet 2.2.5 → 2.2.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/dist/spreadsheet/view.d.ts +2 -0
- package/dist/spreadsheet/view.js +5 -1
- package/dist/spreadsheet/worker/sheetjs/chartParser.js +9 -11
- package/dist/spreadsheet/worker/sheetjs/index.d.ts +1 -1
- package/dist/spreadsheet/worker/sheetjs/index.js +1 -1
- package/dist/spreadsheet/worker/sheetjs/parser.d.ts +34 -0
- package/dist/spreadsheet/worker/sheetjs/parser.js +102 -7
- package/dist/spreadsheet.js +113 -7
- package/dist/worker/sheet.worker.js +28 -28
- package/package.json +4 -3
|
@@ -2,6 +2,8 @@ import type { Column, ConfigType } from 'e-virt-table';
|
|
|
2
2
|
import type { SheetModel } from './worker/type.js';
|
|
3
3
|
import { type CellStyleCache, type SheetDefaults, type VirtualSheetState } from './state.js';
|
|
4
4
|
export declare const INDEX_COLUMN_WIDTH = 68;
|
|
5
|
+
export declare const SPREADSHEET_MIN_ZOOM = 0.25;
|
|
6
|
+
export declare const SPREADSHEET_MAX_ZOOM = 2.5;
|
|
5
7
|
export declare const HEADER_HEIGHT = 34;
|
|
6
8
|
export declare const RESIZABLE_COLUMN_MIN_WIDTH = 40;
|
|
7
9
|
export declare const RESIZABLE_ROW_MIN_HEIGHT = 18;
|
package/dist/spreadsheet/view.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import tinycolor from 'tinycolor2';
|
|
2
2
|
import { displayCellKey, getDataKey, getRowState, INDEX_COLUMN_KEY, ROW_KEY_FIELD, RowState } from './state.js';
|
|
3
3
|
export const INDEX_COLUMN_WIDTH = 68;
|
|
4
|
+
export const SPREADSHEET_MIN_ZOOM = 0.25;
|
|
5
|
+
export const SPREADSHEET_MAX_ZOOM = 2.5;
|
|
4
6
|
const TABLE_FONT_FAMILY = 'Aptos, Calibri, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif';
|
|
5
7
|
const TABLE_FONT_SIZE = 11;
|
|
6
8
|
const MIN_RENDERABLE_ROW_HEIGHT = 8;
|
|
@@ -35,7 +37,9 @@ const MAX_OVERFLOW_SCAN_COLS = 32;
|
|
|
35
37
|
let measureCanvas;
|
|
36
38
|
const textWidthCache = new Map();
|
|
37
39
|
const normalizeZoomScale = (scale = 1) => {
|
|
38
|
-
return Number.isFinite(scale)
|
|
40
|
+
return Number.isFinite(scale)
|
|
41
|
+
? Math.min(SPREADSHEET_MAX_ZOOM, Math.max(SPREADSHEET_MIN_ZOOM, scale))
|
|
42
|
+
: 1;
|
|
39
43
|
};
|
|
40
44
|
const scaleNumber = (value, zoomScale) => {
|
|
41
45
|
return Math.max(1, Math.round(value * normalizeZoomScale(zoomScale)));
|
|
@@ -295,17 +295,15 @@ export const parseSpreadsheetCharts = async (data) => {
|
|
|
295
295
|
if (!name || !(worksheetRelationship === null || worksheetRelationship === void 0 ? void 0 : worksheetRelationship.type.endsWith(WORKSHEET_RELATIONSHIP_SUFFIX))) {
|
|
296
296
|
continue;
|
|
297
297
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
.map((
|
|
307
|
-
.filter((relationship) => relationship === null || relationship === void 0 ? void 0 : relationship.type.endsWith(DRAWING_RELATIONSHIP_SUFFIX))
|
|
308
|
-
.map((relationship) => relationship.target);
|
|
298
|
+
// A worksheet can expand to hundreds of megabytes even when the drawing
|
|
299
|
+
// relationship part is only a few hundred bytes. Loading sheetN.xml as a
|
|
300
|
+
// string here duplicates the cell parser's work and can exceed V8's string
|
|
301
|
+
// limit before chart parsing starts. Drawing relationships already carry
|
|
302
|
+
// the typed targets needed by the chart parser, so discover them directly.
|
|
303
|
+
const worksheetRelationships = await loadRelationships(zip, worksheetRelationship.target);
|
|
304
|
+
const drawingParts = Array.from(new Set(worksheetRelationships
|
|
305
|
+
.filter((relationship) => relationship.type.endsWith(DRAWING_RELATIONSHIP_SUFFIX))
|
|
306
|
+
.map((relationship) => relationship.target)));
|
|
309
307
|
const charts = (await Promise.all(drawingParts.map((part) => parseDrawingCharts(zip, part)))).flat();
|
|
310
308
|
if (charts.length) {
|
|
311
309
|
result[name] = charts;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { createSpreadsheetParserContext, handleSpreadsheetWorkerRequest } from './parser.js';
|
|
1
|
+
export { createSpreadsheetParserContext, getWorksheetDisplayBounds, handleSpreadsheetWorkerRequest, type WorksheetDisplayBounds } from './parser.js';
|
|
2
2
|
export { decodeSpreadsheetText, isTextSpreadsheetSource, isValidUtf8, prepareSpreadsheetReadInput, type DecodedSpreadsheetText, type PreparedSpreadsheetReadInput, type SpreadsheetTextEncoding, type SpreadsheetTextSource, } from './textEncoding.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { createSpreadsheetParserContext, handleSpreadsheetWorkerRequest } from './parser.js';
|
|
1
|
+
export { createSpreadsheetParserContext, getWorksheetDisplayBounds, handleSpreadsheetWorkerRequest } from './parser.js';
|
|
2
2
|
export { decodeSpreadsheetText, isTextSpreadsheetSource, isValidUtf8, prepareSpreadsheetReadInput, } from './textEncoding.js';
|
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import type { WorkBook } from 'styled-exceljs';
|
|
2
2
|
import { type SpreadsheetTextSource } from './textEncoding.js';
|
|
3
3
|
import type { SheetChartDefinition, SheetDefinition } from '../type.js';
|
|
4
|
+
interface DrawingMarkerLike {
|
|
5
|
+
row?: number;
|
|
6
|
+
col?: number;
|
|
7
|
+
}
|
|
8
|
+
interface DrawingImageLike {
|
|
9
|
+
anchor?: {
|
|
10
|
+
from?: DrawingMarkerLike;
|
|
11
|
+
to?: DrawingMarkerLike;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
interface WorksheetWithDrawings {
|
|
15
|
+
'!drawings'?: {
|
|
16
|
+
images?: DrawingImageLike[];
|
|
17
|
+
};
|
|
18
|
+
}
|
|
4
19
|
export interface SpreadsheetParserContext {
|
|
5
20
|
workbook: WorkBook | null;
|
|
6
21
|
sheets: SheetDefinition[];
|
|
@@ -15,6 +30,25 @@ export interface SpreadsheetWorkerResponse {
|
|
|
15
30
|
payload?: Record<string, any>;
|
|
16
31
|
}
|
|
17
32
|
export declare const createSpreadsheetParserContext: () => SpreadsheetParserContext;
|
|
33
|
+
interface WorksheetRangeLike extends WorksheetWithDrawings {
|
|
34
|
+
'!ref'?: string;
|
|
35
|
+
'!data'?: Array<Array<unknown> | undefined>;
|
|
36
|
+
'!merges'?: Array<{
|
|
37
|
+
e?: DrawingMarkerLike;
|
|
38
|
+
}>;
|
|
39
|
+
[key: string]: unknown;
|
|
40
|
+
}
|
|
41
|
+
export interface WorksheetDisplayBounds {
|
|
42
|
+
rowCount: number;
|
|
43
|
+
colCount: number;
|
|
44
|
+
declaredRowCount: number;
|
|
45
|
+
declaredColCount: number;
|
|
46
|
+
observedRowCount: number;
|
|
47
|
+
observedColCount: number;
|
|
48
|
+
trimmed: boolean;
|
|
49
|
+
}
|
|
50
|
+
export declare const getWorksheetDisplayBounds: (worksheet: WorksheetRangeLike | undefined, charts: SheetChartDefinition[] | undefined) => WorksheetDisplayBounds;
|
|
18
51
|
export declare const parseSpreadsheetWorkbook: (context: SpreadsheetParserContext, data: ArrayBuffer, source?: SpreadsheetTextSource) => Promise<SpreadsheetWorkerResponse[]>;
|
|
19
52
|
export declare const parseSpreadsheetSheet: (context: SpreadsheetParserContext, payload?: Record<string, any>) => SpreadsheetWorkerResponse[];
|
|
20
53
|
export declare const handleSpreadsheetWorkerRequest: (context: SpreadsheetParserContext, request: SpreadsheetWorkerRequest) => SpreadsheetWorkerResponse[] | Promise<SpreadsheetWorkerResponse[]>;
|
|
54
|
+
export {};
|
|
@@ -60,6 +60,100 @@ const getChartBounds = (charts) => {
|
|
|
60
60
|
colCount: 0,
|
|
61
61
|
});
|
|
62
62
|
};
|
|
63
|
+
const EMPTY_RANGE_ROW_LIMIT = 1000;
|
|
64
|
+
const EMPTY_RANGE_COLUMN_LIMIT = 256;
|
|
65
|
+
const RANGE_ROW_SLACK = 256;
|
|
66
|
+
const RANGE_COLUMN_SLACK = 64;
|
|
67
|
+
const RANGE_GROWTH_FACTOR = 4;
|
|
68
|
+
const getCellBounds = (worksheet) => {
|
|
69
|
+
const bounds = { rowCount: 0, colCount: 0 };
|
|
70
|
+
if (!worksheet)
|
|
71
|
+
return bounds;
|
|
72
|
+
const denseRows = Array.isArray(worksheet)
|
|
73
|
+
? worksheet
|
|
74
|
+
: worksheet['!data'];
|
|
75
|
+
if (Array.isArray(denseRows)) {
|
|
76
|
+
for (const rowKey of Object.keys(denseRows)) {
|
|
77
|
+
const rowIndex = Number(rowKey);
|
|
78
|
+
const row = denseRows[rowIndex];
|
|
79
|
+
if (!Number.isInteger(rowIndex) || rowIndex < 0 || !Array.isArray(row))
|
|
80
|
+
continue;
|
|
81
|
+
for (const colKey of Object.keys(row)) {
|
|
82
|
+
const colIndex = Number(colKey);
|
|
83
|
+
if (!Number.isInteger(colIndex) || colIndex < 0 || row[colIndex] == null)
|
|
84
|
+
continue;
|
|
85
|
+
bounds.rowCount = Math.max(bounds.rowCount, rowIndex + 1);
|
|
86
|
+
bounds.colCount = Math.max(bounds.colCount, colIndex + 1);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return bounds;
|
|
90
|
+
}
|
|
91
|
+
for (const key of Object.keys(worksheet)) {
|
|
92
|
+
if (key.startsWith('!') || !/^[A-Z]+[1-9][0-9]*$/i.test(key) || worksheet[key] == null)
|
|
93
|
+
continue;
|
|
94
|
+
try {
|
|
95
|
+
const cell = utils.decode_cell(key);
|
|
96
|
+
bounds.rowCount = Math.max(bounds.rowCount, cell.r + 1);
|
|
97
|
+
bounds.colCount = Math.max(bounds.colCount, cell.c + 1);
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
// Ignore non-cell extension keys exposed by third-party workbook producers.
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return bounds;
|
|
104
|
+
};
|
|
105
|
+
const getMergeBounds = (worksheet) => {
|
|
106
|
+
return ((worksheet === null || worksheet === void 0 ? void 0 : worksheet['!merges']) || []).reduce((bounds, merge) => {
|
|
107
|
+
var _a, _b, _c, _d, _e, _f;
|
|
108
|
+
const row = Number((_b = (_a = merge.e) === null || _a === void 0 ? void 0 : _a.row) !== null && _b !== void 0 ? _b : (_c = merge.e) === null || _c === void 0 ? void 0 : _c.r);
|
|
109
|
+
const col = Number((_e = (_d = merge.e) === null || _d === void 0 ? void 0 : _d.col) !== null && _e !== void 0 ? _e : (_f = merge.e) === null || _f === void 0 ? void 0 : _f.c);
|
|
110
|
+
return {
|
|
111
|
+
rowCount: Number.isFinite(row) ? Math.max(bounds.rowCount, row + 1) : bounds.rowCount,
|
|
112
|
+
colCount: Number.isFinite(col) ? Math.max(bounds.colCount, col + 1) : bounds.colCount,
|
|
113
|
+
};
|
|
114
|
+
}, { rowCount: 0, colCount: 0 });
|
|
115
|
+
};
|
|
116
|
+
const reconcileDeclaredRange = (declaredCount, observedCount, slack, emptyLimit) => {
|
|
117
|
+
if (observedCount <= 0) {
|
|
118
|
+
return Math.min(Math.max(declaredCount, 1), emptyLimit);
|
|
119
|
+
}
|
|
120
|
+
const plausibleLimit = Math.max(observedCount + slack, observedCount * RANGE_GROWTH_FACTOR);
|
|
121
|
+
return declaredCount <= plausibleLimit
|
|
122
|
+
? Math.max(declaredCount, observedCount)
|
|
123
|
+
: observedCount;
|
|
124
|
+
};
|
|
125
|
+
export const getWorksheetDisplayBounds = (worksheet, charts) => {
|
|
126
|
+
let declaredRowCount = 0;
|
|
127
|
+
let declaredColCount = 0;
|
|
128
|
+
const ref = worksheet === null || worksheet === void 0 ? void 0 : worksheet['!ref'];
|
|
129
|
+
if (ref) {
|
|
130
|
+
try {
|
|
131
|
+
const range = utils.decode_range(ref);
|
|
132
|
+
declaredRowCount = range.e.r + 1;
|
|
133
|
+
declaredColCount = range.e.c + 1;
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
// Invalid producer dimensions must not block content-based recovery.
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const cellBounds = getCellBounds(worksheet);
|
|
140
|
+
const mergeBounds = getMergeBounds(worksheet);
|
|
141
|
+
const drawingBounds = getDrawingBounds(worksheet);
|
|
142
|
+
const chartBounds = getChartBounds(charts);
|
|
143
|
+
const observedRowCount = Math.max(cellBounds.rowCount, mergeBounds.rowCount, drawingBounds.rowCount, chartBounds.rowCount);
|
|
144
|
+
const observedColCount = Math.max(cellBounds.colCount, mergeBounds.colCount, drawingBounds.colCount, chartBounds.colCount);
|
|
145
|
+
const rowCount = reconcileDeclaredRange(declaredRowCount, observedRowCount, RANGE_ROW_SLACK, EMPTY_RANGE_ROW_LIMIT);
|
|
146
|
+
const colCount = reconcileDeclaredRange(declaredColCount, observedColCount, RANGE_COLUMN_SLACK, EMPTY_RANGE_COLUMN_LIMIT);
|
|
147
|
+
return {
|
|
148
|
+
rowCount,
|
|
149
|
+
colCount,
|
|
150
|
+
declaredRowCount,
|
|
151
|
+
declaredColCount,
|
|
152
|
+
observedRowCount,
|
|
153
|
+
observedColCount,
|
|
154
|
+
trimmed: rowCount < declaredRowCount || colCount < declaredColCount,
|
|
155
|
+
};
|
|
156
|
+
};
|
|
63
157
|
const parseSheets = (context) => {
|
|
64
158
|
var _a;
|
|
65
159
|
const workbook = context.workbook;
|
|
@@ -70,19 +164,20 @@ const parseSheets = (context) => {
|
|
|
70
164
|
context.sheets = workbook.SheetNames.reduce((result, name, sourceIndex) => {
|
|
71
165
|
var _a;
|
|
72
166
|
const worksheet = workbook.Sheets[name];
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
const chartBounds = getChartBounds(context.charts[name]);
|
|
76
|
-
if (!ref && !drawingBounds.rowCount && !drawingBounds.colCount && !chartBounds.rowCount && !chartBounds.colCount) {
|
|
167
|
+
const bounds = getWorksheetDisplayBounds(worksheet, context.charts[name]);
|
|
168
|
+
if (!(worksheet === null || worksheet === void 0 ? void 0 : worksheet['!ref']) && !bounds.observedRowCount && !bounds.observedColCount) {
|
|
77
169
|
return result;
|
|
78
170
|
}
|
|
79
|
-
|
|
171
|
+
if (bounds.trimmed) {
|
|
172
|
+
console.warn(`[file-viewer] Ignored pathological worksheet dimensions for ${name}: `
|
|
173
|
+
+ `${bounds.declaredRowCount}x${bounds.declaredColCount} -> ${bounds.rowCount}x${bounds.colCount}.`);
|
|
174
|
+
}
|
|
80
175
|
result.push({
|
|
81
176
|
id: result.length,
|
|
82
177
|
name,
|
|
83
178
|
hidden: !!((_a = workbookSheets[sourceIndex]) === null || _a === void 0 ? void 0 : _a.Hidden),
|
|
84
|
-
rowCount:
|
|
85
|
-
colCount:
|
|
179
|
+
rowCount: bounds.rowCount,
|
|
180
|
+
colCount: bounds.colCount,
|
|
86
181
|
});
|
|
87
182
|
return result;
|
|
88
183
|
}, []);
|
package/dist/spreadsheet.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { createFileViewerWorkerController, createFileViewerTranslator, createFileViewerZoomChangeEmitter as createZoomChangeEmitter, registerFileViewerZoomProvider, resolveFileViewerColorScheme, resolveFileViewerRuntimeAssetBaseUrl, resolveFileViewerSpreadsheetWorkerUrl, unregisterFileViewerZoomProvider, } from '@file-viewer/core';
|
|
1
|
+
import { createFileViewerWorkerController, createFileViewerTranslator, createFileViewerZoomChangeEmitter as createZoomChangeEmitter, registerFileViewerZoomProvider, resolveFileViewerColorScheme, resolveFileViewerFitScale, resolveFileViewerRuntimeAssetBaseUrl, resolveFileViewerSpreadsheetWorkerUrl, unregisterFileViewerZoomProvider, } from '@file-viewer/core';
|
|
2
2
|
import { renderSpreadsheetChart } from './spreadsheet/chartRenderer.js';
|
|
3
3
|
import { buildRows, clampWindowStart, collectWindowStarts, createEmptyVirtualState, DEFAULT_SHEET_DEFAULTS, displayCellKey, getDataKey, INDEX_COLUMN_KEY, markWindowState, ROW_STATE_FIELD, RowState, WINDOW_SIZE, } from './spreadsheet/state.js';
|
|
4
|
-
import { buildColumns, createTableConfig, detectIndexOffset, getDisplayColumns, getRowHeight, HEADER_HEIGHT, INDEX_COLUMN_WIDTH, normalizeCellStyle, normalizeRowHeight, RESIZABLE_COLUMN_MIN_WIDTH, RESIZABLE_ROW_MIN_HEIGHT, } from './spreadsheet/view.js';
|
|
4
|
+
import { buildColumns, createTableConfig, detectIndexOffset, getDisplayColumns, getRowHeight, HEADER_HEIGHT, INDEX_COLUMN_WIDTH, normalizeCellStyle, normalizeRowHeight, RESIZABLE_COLUMN_MIN_WIDTH, RESIZABLE_ROW_MIN_HEIGHT, SPREADSHEET_MAX_ZOOM, SPREADSHEET_MIN_ZOOM, } from './spreadsheet/view.js';
|
|
5
5
|
const EXCEL_IMAGE_SCROLLBAR_GUARD = 18;
|
|
6
6
|
const DEFAULT_SPREADSHEET_WORKER_AUTO_THRESHOLD = 1 * 1024 * 1024;
|
|
7
7
|
const E_VIRT_TABLE_STYLE_MARKERS = [
|
|
@@ -452,7 +452,7 @@ const setHidden = (element, hidden) => {
|
|
|
452
452
|
element.classList.toggle('hidden', hidden);
|
|
453
453
|
};
|
|
454
454
|
const clampZoom = (value) => {
|
|
455
|
-
return Math.min(
|
|
455
|
+
return Math.min(SPREADSHEET_MAX_ZOOM, Math.max(SPREADSHEET_MIN_ZOOM, Number(value.toFixed(2))));
|
|
456
456
|
};
|
|
457
457
|
const serializeSpreadsheetCopyCell = (value) => {
|
|
458
458
|
if (value === null || value === undefined) {
|
|
@@ -630,6 +630,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
630
630
|
let sheetSessionId = 0;
|
|
631
631
|
let disposed = false;
|
|
632
632
|
let hasNotifiedFirstPaint = false;
|
|
633
|
+
let hasAppliedDefaultInitialFit = false;
|
|
633
634
|
const resizableColumns = ((_f = (_e = context === null || context === void 0 ? void 0 : context.options) === null || _e === void 0 ? void 0 : _e.spreadsheet) === null || _f === void 0 ? void 0 : _f.resizableColumns) === true;
|
|
634
635
|
const resizableRows = ((_h = (_g = context === null || context === void 0 ? void 0 : context.options) === null || _g === void 0 ? void 0 : _g.spreadsheet) === null || _h === void 0 ? void 0 : _h.resizableRows) === true;
|
|
635
636
|
const controller = createFileViewerWorkerController(createSpreadsheetWorkerFactory(target, buffer.byteLength, context), { logErrors: false });
|
|
@@ -685,11 +686,11 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
685
686
|
const getZoomState = () => ({
|
|
686
687
|
scale: zoom,
|
|
687
688
|
label: `${Math.round(zoom * 100)}%`,
|
|
688
|
-
canZoomIn: zoom <
|
|
689
|
-
canZoomOut: zoom >
|
|
689
|
+
canZoomIn: zoom < SPREADSHEET_MAX_ZOOM,
|
|
690
|
+
canZoomOut: zoom > SPREADSHEET_MIN_ZOOM,
|
|
690
691
|
canReset: zoom !== 1,
|
|
691
|
-
minScale:
|
|
692
|
-
maxScale:
|
|
692
|
+
minScale: SPREADSHEET_MIN_ZOOM,
|
|
693
|
+
maxScale: SPREADSHEET_MAX_ZOOM,
|
|
693
694
|
});
|
|
694
695
|
const getImageViewportScrollbarGuard = () => {
|
|
695
696
|
const tableContainer = tableHost.querySelector('.e-virt-table-container');
|
|
@@ -829,11 +830,114 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
829
830
|
renderChrome();
|
|
830
831
|
return getZoomState();
|
|
831
832
|
};
|
|
833
|
+
const getSpreadsheetContentSize = () => {
|
|
834
|
+
const contentWidth = virtualState.columns.reduce((sum, column) => {
|
|
835
|
+
const candidate = column;
|
|
836
|
+
if (candidate.hide) {
|
|
837
|
+
return sum;
|
|
838
|
+
}
|
|
839
|
+
const width = Number(candidate.width);
|
|
840
|
+
return sum + (Number.isFinite(width) && width > 0 ? width : sheetDefaults.colWidth);
|
|
841
|
+
}, 0);
|
|
842
|
+
const defaultRowHeight = normalizeRowHeight(sheetDefaults.rowHeight, DEFAULT_SHEET_DEFAULTS.rowHeight);
|
|
843
|
+
let explicitHeight = 0;
|
|
844
|
+
let explicitRows = 0;
|
|
845
|
+
virtualState.rowHeightCache.forEach((height) => {
|
|
846
|
+
explicitHeight += normalizeRowHeight(height, defaultRowHeight);
|
|
847
|
+
explicitRows += 1;
|
|
848
|
+
});
|
|
849
|
+
const contentHeight = HEADER_HEIGHT + explicitHeight +
|
|
850
|
+
Math.max(0, virtualState.totalRows - explicitRows) * defaultRowHeight;
|
|
851
|
+
return { contentWidth, contentHeight };
|
|
852
|
+
};
|
|
853
|
+
const resolveSpreadsheetScale = (request) => {
|
|
854
|
+
var _a, _b;
|
|
855
|
+
const content = getSpreadsheetContentSize();
|
|
856
|
+
const autoMode = request.mode === 'auto';
|
|
857
|
+
const viewportWidth = request.viewportWidth || tableHost.clientWidth || 0;
|
|
858
|
+
const viewportHeight = request.viewportHeight || tableHost.clientHeight || 0;
|
|
859
|
+
if (viewportWidth <= 0 || viewportHeight <= 0) {
|
|
860
|
+
return undefined;
|
|
861
|
+
}
|
|
862
|
+
return resolveFileViewerFitScale({
|
|
863
|
+
mode: autoMode ? 'width' : request.mode,
|
|
864
|
+
viewportWidth,
|
|
865
|
+
viewportHeight,
|
|
866
|
+
contentWidth: content.contentWidth,
|
|
867
|
+
contentHeight: content.contentHeight,
|
|
868
|
+
currentScale: zoom,
|
|
869
|
+
minScale: (_a = request.minScale) !== null && _a !== void 0 ? _a : SPREADSHEET_MIN_ZOOM,
|
|
870
|
+
maxScale: (_b = request.maxScale) !== null && _b !== void 0 ? _b : (autoMode ? 1 : SPREADSHEET_MAX_ZOOM),
|
|
871
|
+
});
|
|
872
|
+
};
|
|
873
|
+
const fitSpreadsheet = (request) => {
|
|
874
|
+
if (!virtualState.active || !virtualState.columns.length) {
|
|
875
|
+
return {
|
|
876
|
+
applied: false,
|
|
877
|
+
mode: request.mode,
|
|
878
|
+
resize: request.resize,
|
|
879
|
+
source: request.source,
|
|
880
|
+
reason: 'pending',
|
|
881
|
+
provider: 'zoom',
|
|
882
|
+
};
|
|
883
|
+
}
|
|
884
|
+
const scale = resolveSpreadsheetScale(request);
|
|
885
|
+
if (!scale) {
|
|
886
|
+
return {
|
|
887
|
+
applied: false,
|
|
888
|
+
mode: request.mode,
|
|
889
|
+
resize: request.resize,
|
|
890
|
+
source: request.source,
|
|
891
|
+
reason: 'unmeasurable',
|
|
892
|
+
provider: 'zoom',
|
|
893
|
+
};
|
|
894
|
+
}
|
|
895
|
+
const state = setZoom(scale);
|
|
896
|
+
return {
|
|
897
|
+
applied: true,
|
|
898
|
+
mode: request.mode,
|
|
899
|
+
resize: request.resize,
|
|
900
|
+
scale: state.scale,
|
|
901
|
+
source: request.source,
|
|
902
|
+
provider: 'zoom',
|
|
903
|
+
};
|
|
904
|
+
};
|
|
905
|
+
const applyDefaultInitialFit = () => {
|
|
906
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
907
|
+
const explicitInitialScale = Number((_c = (_b = (_a = context === null || context === void 0 ? void 0 : context.options) === null || _a === void 0 ? void 0 : _a.initialViewState) === null || _b === void 0 ? void 0 : _b.scale) !== null && _c !== void 0 ? _c : (_f = (_e = (_d = context === null || context === void 0 ? void 0 : context.options) === null || _d === void 0 ? void 0 : _d.initialViewState) === null || _e === void 0 ? void 0 : _e.zoom) === null || _f === void 0 ? void 0 : _f.scale);
|
|
908
|
+
if (hasAppliedDefaultInitialFit ||
|
|
909
|
+
((_g = context === null || context === void 0 ? void 0 : context.options) === null || _g === void 0 ? void 0 : _g.fit) !== undefined ||
|
|
910
|
+
(Number.isFinite(explicitInitialScale) && explicitInitialScale > 0)) {
|
|
911
|
+
hasAppliedDefaultInitialFit = true;
|
|
912
|
+
return;
|
|
913
|
+
}
|
|
914
|
+
const scale = resolveSpreadsheetScale({
|
|
915
|
+
mode: 'auto',
|
|
916
|
+
resize: 'initial',
|
|
917
|
+
padding: 0,
|
|
918
|
+
source: 'initial',
|
|
919
|
+
reason: 'initial',
|
|
920
|
+
viewportWidth: tableHost.clientWidth || target.clientWidth || 0,
|
|
921
|
+
viewportHeight: tableHost.clientHeight || target.clientHeight || 0,
|
|
922
|
+
container: tableHost,
|
|
923
|
+
});
|
|
924
|
+
if (!scale || scale >= zoom) {
|
|
925
|
+
if (scale) {
|
|
926
|
+
hasAppliedDefaultInitialFit = true;
|
|
927
|
+
}
|
|
928
|
+
return;
|
|
929
|
+
}
|
|
930
|
+
zoom = clampZoom(scale);
|
|
931
|
+
syncScaledRowHeights();
|
|
932
|
+
zoomEmitter.emit();
|
|
933
|
+
hasAppliedDefaultInitialFit = true;
|
|
934
|
+
};
|
|
832
935
|
registerFileViewerZoomProvider(root, {
|
|
833
936
|
zoomIn: () => setZoom(zoom + 0.1),
|
|
834
937
|
zoomOut: () => setZoom(zoom - 0.1),
|
|
835
938
|
resetZoom: () => setZoom(1),
|
|
836
939
|
setZoom,
|
|
940
|
+
fit: fitSpreadsheet,
|
|
837
941
|
getState: getZoomState,
|
|
838
942
|
subscribe: zoomEmitter.subscribe,
|
|
839
943
|
});
|
|
@@ -1014,6 +1118,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1014
1118
|
if (rect.width <= 0 || rect.height <= 0) {
|
|
1015
1119
|
return;
|
|
1016
1120
|
}
|
|
1121
|
+
applyDefaultInitialFit();
|
|
1017
1122
|
syncTableLayout();
|
|
1018
1123
|
};
|
|
1019
1124
|
const scheduleStableFirstPaintRefresh = () => {
|
|
@@ -1297,6 +1402,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1297
1402
|
applySheetStructure(ws);
|
|
1298
1403
|
applyWindowRows(ws);
|
|
1299
1404
|
applyWindowCells(ws);
|
|
1405
|
+
applyDefaultInitialFit();
|
|
1300
1406
|
virtualState.loadedWindows.add(meta.startRow);
|
|
1301
1407
|
virtualState.loadingWindows.delete(meta.startRow);
|
|
1302
1408
|
syncWindowStats();
|