@file-viewer/core 2.0.10 → 2.1.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.
Files changed (114) hide show
  1. package/README.en.md +2 -2
  2. package/README.md +2 -2
  3. package/dist/config/options.d.ts +1 -1
  4. package/dist/config/options.js +1 -1
  5. package/dist/contracts/types.d.ts +71 -1
  6. package/dist/headless.d.ts +2 -2
  7. package/dist/headless.js +1 -1
  8. package/dist/index.d.ts +9 -6
  9. package/dist/index.js +105 -48
  10. package/dist/platform/assets.d.ts +3 -1
  11. package/dist/platform/assets.js +18 -2
  12. package/dist/registry/capabilities.d.ts +2 -2
  13. package/dist/registry/capabilities.js +2 -1
  14. package/dist/registry/formats.d.ts +20 -7
  15. package/dist/registry/formats.js +14 -5
  16. package/dist/registry/registry.d.ts +8 -1
  17. package/dist/registry/registry.js +29 -0
  18. package/dist/renderers/image.js +1 -10
  19. package/dist/renderers/index.d.ts +320 -2
  20. package/dist/renderers/index.js +27 -157
  21. package/dist/viewer/createViewer.js +86 -3
  22. package/package.json +17 -44
  23. package/dist/renderers/archive.d.ts +0 -2
  24. package/dist/renderers/archive.js +0 -547
  25. package/dist/renderers/archiveCache.d.ts +0 -10
  26. package/dist/renderers/archiveCache.js +0 -96
  27. package/dist/renderers/archiveFallback.d.ts +0 -7
  28. package/dist/renderers/archiveFallback.js +0 -166
  29. package/dist/renderers/archiveShared.d.ts +0 -23
  30. package/dist/renderers/archiveShared.js +0 -71
  31. package/dist/renderers/audio.d.ts +0 -8
  32. package/dist/renderers/audio.js +0 -219
  33. package/dist/renderers/cad.d.ts +0 -2
  34. package/dist/renderers/cad.js +0 -446
  35. package/dist/renderers/code.d.ts +0 -11
  36. package/dist/renderers/code.js +0 -233
  37. package/dist/renderers/data.d.ts +0 -7
  38. package/dist/renderers/data.js +0 -370
  39. package/dist/renderers/drawing.d.ts +0 -10
  40. package/dist/renderers/drawing.js +0 -882
  41. package/dist/renderers/eda.d.ts +0 -2
  42. package/dist/renderers/eda.js +0 -434
  43. package/dist/renderers/edaParser.d.ts +0 -77
  44. package/dist/renderers/edaParser.js +0 -569
  45. package/dist/renderers/email.d.ts +0 -2
  46. package/dist/renderers/email.js +0 -463
  47. package/dist/renderers/epub.d.ts +0 -2
  48. package/dist/renderers/epub.js +0 -331
  49. package/dist/renderers/geo.d.ts +0 -2
  50. package/dist/renderers/geo.js +0 -284
  51. package/dist/renderers/markdown.d.ts +0 -2
  52. package/dist/renderers/markdown.js +0 -83
  53. package/dist/renderers/model.d.ts +0 -2
  54. package/dist/renderers/model.js +0 -567
  55. package/dist/renderers/ofd.d.ts +0 -2
  56. package/dist/renderers/ofd.js +0 -256
  57. package/dist/renderers/openDocument.d.ts +0 -2
  58. package/dist/renderers/openDocument.js +0 -122
  59. package/dist/renderers/pdf.d.ts +0 -3
  60. package/dist/renderers/pdf.js +0 -1001
  61. package/dist/renderers/pdfStyles.d.ts +0 -1
  62. package/dist/renderers/pdfStyles.js +0 -1
  63. package/dist/renderers/pptx.d.ts +0 -2
  64. package/dist/renderers/pptx.js +0 -217
  65. package/dist/renderers/spreadsheet/state.d.ts +0 -80
  66. package/dist/renderers/spreadsheet/state.js +0 -96
  67. package/dist/renderers/spreadsheet/view.d.ts +0 -25
  68. package/dist/renderers/spreadsheet/view.js +0 -833
  69. package/dist/renderers/spreadsheet/worker/index.d.ts +0 -2
  70. package/dist/renderers/spreadsheet/worker/index.js +0 -1
  71. package/dist/renderers/spreadsheet/worker/sheetjs/SheetJsModel.d.ts +0 -73
  72. package/dist/renderers/spreadsheet/worker/sheetjs/SheetJsModel.js +0 -623
  73. package/dist/renderers/spreadsheet/worker/sheetjs/color.d.ts +0 -2
  74. package/dist/renderers/spreadsheet/worker/sheetjs/color.js +0 -73
  75. package/dist/renderers/spreadsheet/worker/sheetjs/index.d.ts +0 -1
  76. package/dist/renderers/spreadsheet/worker/sheetjs/index.js +0 -1
  77. package/dist/renderers/spreadsheet/worker/sheetjs/parser.d.ts +0 -18
  78. package/dist/renderers/spreadsheet/worker/sheetjs/parser.js +0 -106
  79. package/dist/renderers/spreadsheet/worker/sheetjs/sheet.worker.d.ts +0 -1
  80. package/dist/renderers/spreadsheet/worker/sheetjs/sheet.worker.js +0 -11
  81. package/dist/renderers/spreadsheet/worker/type.d.ts +0 -57
  82. package/dist/renderers/spreadsheet/worker/type.js +0 -1
  83. package/dist/renderers/spreadsheet.d.ts +0 -3
  84. package/dist/renderers/spreadsheet.js +0 -929
  85. package/dist/renderers/typst.d.ts +0 -8
  86. package/dist/renderers/typst.js +0 -547
  87. package/dist/renderers/umd/parser.d.ts +0 -30
  88. package/dist/renderers/umd/parser.js +0 -408
  89. package/dist/renderers/umd.d.ts +0 -2
  90. package/dist/renderers/umd.js +0 -297
  91. package/dist/renderers/video.d.ts +0 -8
  92. package/dist/renderers/video.js +0 -108
  93. package/dist/renderers/wordDoc.d.ts +0 -5
  94. package/dist/renderers/wordDoc.js +0 -284
  95. package/dist/renderers/wordDocx.d.ts +0 -5
  96. package/dist/renderers/wordDocx.js +0 -985
  97. package/dist/renderers/wordDocx.worker.d.ts +0 -1
  98. package/dist/renderers/wordDocx.worker.js +0 -96
  99. package/vendor/ofd/dltech/jbig2/arithmetic_decoder.js +0 -183
  100. package/vendor/ofd/dltech/jbig2/ccitt.js +0 -1070
  101. package/vendor/ofd/dltech/jbig2/compatibility.js +0 -12
  102. package/vendor/ofd/dltech/jbig2/core_utils.js +0 -180
  103. package/vendor/ofd/dltech/jbig2/is_node.js +0 -27
  104. package/vendor/ofd/dltech/jbig2/jbig2.js +0 -2589
  105. package/vendor/ofd/dltech/jbig2/jbig2_stream.js +0 -81
  106. package/vendor/ofd/dltech/jbig2/primitives.js +0 -387
  107. package/vendor/ofd/dltech/jbig2/stream.js +0 -1348
  108. package/vendor/ofd/dltech/jbig2/util.js +0 -972
  109. package/vendor/ofd/dltech/ofd/ofd.d.ts +0 -11
  110. package/vendor/ofd/dltech/ofd/ofd.js +0 -100
  111. package/vendor/ofd/dltech/ofd/ofd_parser.js +0 -395
  112. package/vendor/ofd/dltech/ofd/ofd_render.js +0 -473
  113. package/vendor/ofd/dltech/ofd/ofd_util.js +0 -350
  114. package/vendor/ofd/dltech/ofd/pipeline.js +0 -26
@@ -1,2 +0,0 @@
1
- export { createSpreadsheetParserContext, handleSpreadsheetWorkerRequest } from './sheetjs';
2
- export type { default as SheetJsModel } from './sheetjs/SheetJsModel';
@@ -1 +0,0 @@
1
- export { createSpreadsheetParserContext, handleSpreadsheetWorkerRequest } from './sheetjs/index.js';
@@ -1,73 +0,0 @@
1
- import type { WorkSheet } from 'styled-exceljs';
2
- import type { CellMerge, SheetColumn, SheetModel, SheetStructure, SheetWindow } from '../type';
3
- export declare const defaults: {
4
- rowHeight: number;
5
- colWidth: number;
6
- };
7
- interface SheetSliceOptions {
8
- startRow?: number;
9
- pageSize?: number;
10
- totalRows?: number;
11
- totalCols?: number;
12
- }
13
- type SheetCellMeta = {
14
- className?: string;
15
- style: Record<string, string>;
16
- };
17
- export default class SheetJsModel implements SheetModel {
18
- private readonly _ws;
19
- private readonly _startRow;
20
- private readonly _pageSize;
21
- private readonly _totalRows?;
22
- private readonly _totalCols?;
23
- private static readonly defaults;
24
- private _data;
25
- private _cell;
26
- private _merge;
27
- private _rowHeights;
28
- private _colWidths;
29
- private _autoFitColumns;
30
- private _columns;
31
- private _structure;
32
- private _meta;
33
- private readonly range;
34
- static create(ws: WorkSheet, options?: SheetSliceOptions): SheetJsModel;
35
- private constructor();
36
- private get ws();
37
- get defaults(): {
38
- rowHeight: number;
39
- colWidth: number;
40
- };
41
- get data(): string[][];
42
- get cell(): Record<string, SheetCellMeta>;
43
- get merge(): CellMerge[];
44
- get columns(): SheetColumn[];
45
- get structure(): SheetStructure;
46
- get rowHeights(): number | number[];
47
- get colWidths(): number | number[];
48
- get meta(): SheetWindow;
49
- private get totalRows();
50
- private get totalCols();
51
- private get startRow();
52
- private get endRow();
53
- private get denseRows();
54
- private getCellAt;
55
- private getAxisOffset;
56
- private getMarkerLeft;
57
- private getMarkerTop;
58
- private getImages;
59
- private getAllMerge;
60
- private getData;
61
- private getCell;
62
- private getMerge;
63
- private getRowHeights;
64
- private getAllRowHeights;
65
- private getAutoFitColumns;
66
- private get autoFitColumns();
67
- private getColumnMeta;
68
- private getColWidths;
69
- private getColumns;
70
- private getStructure;
71
- toObject(): object;
72
- }
73
- export {};
@@ -1,623 +0,0 @@
1
- import { utils } from 'styled-exceljs';
2
- import { getTintColor, indexedColors } from './color.js';
3
- const EXCEL_DEFAULT_COLUMN_WIDTH = 8.43;
4
- const EXCEL_DEFAULT_ROW_HEIGHT_PT = 15;
5
- const EXCEL_DEFAULT_TEXT_COLOR = '#202124';
6
- const EMU_PER_PIXEL = 9525;
7
- const DEFAULT_IMAGE_WIDTH = 480;
8
- const DEFAULT_IMAGE_HEIGHT = 288;
9
- const AUTO_FIT_MIN_WIDTH = 24;
10
- const AUTO_FIT_PADDING = 8;
11
- const toFiniteNumber = (value) => {
12
- return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
13
- };
14
- const getDefaultColumnWidth = () => {
15
- var _a;
16
- const converter = utils.col_width_to_px;
17
- const value = typeof converter === 'function' ? converter(EXCEL_DEFAULT_COLUMN_WIDTH) : undefined;
18
- return Math.ceil((_a = toFiniteNumber(value)) !== null && _a !== void 0 ? _a : 64);
19
- };
20
- const getDefaultRowHeight = () => {
21
- var _a;
22
- const converter = utils.row_height_to_px;
23
- const value = typeof converter === 'function' ? converter(EXCEL_DEFAULT_ROW_HEIGHT_PT) : undefined;
24
- return Math.ceil((_a = toFiniteNumber(value)) !== null && _a !== void 0 ? _a : 20);
25
- };
26
- export const defaults = {
27
- rowHeight: getDefaultRowHeight(),
28
- colWidth: getDefaultColumnWidth()
29
- };
30
- const cellKey = (row, col) => {
31
- return `${row}-${col}`;
32
- };
33
- const formatCellValue = (cell) => {
34
- if (!cell) {
35
- return '';
36
- }
37
- if (cell.w !== undefined && cell.w !== null) {
38
- return `${cell.w}`;
39
- }
40
- if (cell.v === undefined || cell.v === null) {
41
- return '';
42
- }
43
- if (cell.t === 'd' && cell.v instanceof Date) {
44
- return cell.v.toLocaleDateString();
45
- }
46
- return `${cell.v}`;
47
- };
48
- const getColumnPixelWidth = (column) => {
49
- if (!column) {
50
- return undefined;
51
- }
52
- if (column.hidden) {
53
- return 0;
54
- }
55
- // styled-exceljs 在 browserPixels 模式下会优先输出 wpx,这是最接近浏览器渲染的列宽。
56
- const wpx = toFiniteNumber(column.wpx);
57
- if (wpx !== undefined && wpx >= 0) {
58
- return Math.ceil(wpx);
59
- }
60
- const width = toFiniteNumber(column.width);
61
- if (width === 0) {
62
- return 0;
63
- }
64
- if (width !== undefined && width > 0) {
65
- const converter = utils.col_width_to_px;
66
- const converted = typeof converter === 'function' ? toFiniteNumber(converter(width)) : undefined;
67
- if (converted !== undefined) {
68
- return Math.ceil(converted);
69
- }
70
- return Math.ceil(width * (column.MDW || 7));
71
- }
72
- const wch = toFiniteNumber(column.wch);
73
- if (wch === 0) {
74
- return 0;
75
- }
76
- if (wch !== undefined && wch > 0) {
77
- return Math.ceil(wch * (column.MDW || 7) + 5);
78
- }
79
- return undefined;
80
- };
81
- const getVectorSize = (sizes, index, fallback) => {
82
- var _a;
83
- if (typeof sizes === 'number') {
84
- return sizes;
85
- }
86
- return (_a = sizes === null || sizes === void 0 ? void 0 : sizes[index]) !== null && _a !== void 0 ? _a : fallback;
87
- };
88
- const emuToPixels = (value) => {
89
- return (value || 0) / EMU_PER_PIXEL;
90
- };
91
- const hasColumnWidth = (column) => {
92
- var _a, _b, _c;
93
- if (!column) {
94
- return false;
95
- }
96
- if (column.hidden) {
97
- return true;
98
- }
99
- return (((_a = toFiniteNumber(column.wpx)) !== null && _a !== void 0 ? _a : -1) >= 0 ||
100
- ((_b = toFiniteNumber(column.width)) !== null && _b !== void 0 ? _b : -1) >= 0 ||
101
- ((_c = toFiniteNumber(column.wch)) !== null && _c !== void 0 ? _c : -1) >= 0);
102
- };
103
- const getRowPixelHeight = (rowMeta) => {
104
- if (!rowMeta) {
105
- return undefined;
106
- }
107
- if (rowMeta.hidden) {
108
- return 0;
109
- }
110
- const hpx = toFiniteNumber(rowMeta.hpx);
111
- if (hpx !== undefined && hpx >= 0) {
112
- return Math.ceil(hpx);
113
- }
114
- const hpt = toFiniteNumber(rowMeta.hpt);
115
- if (hpt !== undefined && hpt >= 0) {
116
- const converter = utils.row_height_to_px;
117
- const converted = typeof converter === 'function' ? toFiniteNumber(converter(hpt)) : undefined;
118
- return Math.ceil(converted !== null && converted !== void 0 ? converted : hpt * 96 / 72);
119
- }
120
- return undefined;
121
- };
122
- const normalizeHorizontalAlign = (value) => {
123
- switch (`${value || ''}`) {
124
- case 'left':
125
- return 'Left';
126
- case 'center':
127
- case 'centerContinuous':
128
- case 'distributed':
129
- case 'justify':
130
- return 'Center';
131
- case 'right':
132
- return 'Right';
133
- default:
134
- return undefined;
135
- }
136
- };
137
- const normalizeVerticalAlign = (value) => {
138
- switch (`${value || ''}`) {
139
- case 'top':
140
- return 'Top';
141
- case 'center':
142
- case 'middle':
143
- case 'distributed':
144
- case 'justify':
145
- return 'Middle';
146
- case 'bottom':
147
- return 'Bottom';
148
- default:
149
- return undefined;
150
- }
151
- };
152
- const alignToClassName = (alignment) => {
153
- if (!alignment) {
154
- return '';
155
- }
156
- const classNames = [
157
- normalizeHorizontalAlign(alignment.horizontal),
158
- normalizeVerticalAlign(alignment.vertical)
159
- ].filter(Boolean).map(value => `ht${value}`);
160
- if (alignment.wrapText) {
161
- classNames.push('htWrap');
162
- }
163
- if (alignment.shrinkToFit) {
164
- classNames.push('htShrink');
165
- }
166
- return classNames.join(' ');
167
- };
168
- const normalizeColor = (color) => {
169
- if (!color) {
170
- return undefined;
171
- }
172
- const tintedRgb = color.raw_rgb && typeof color.tint === 'number'
173
- ? getTintColor(color.raw_rgb, color.tint)
174
- : undefined;
175
- const rgb = color.rgb || tintedRgb || color.raw_rgb;
176
- if (typeof rgb === 'string' && rgb) {
177
- const clean = rgb.startsWith('#') ? rgb.slice(1) : rgb;
178
- const value = clean.length > 6 ? clean.slice(-6) : clean;
179
- return `#${value}`;
180
- }
181
- const indexed = typeof color.indexed === 'number' ? color.indexed : color.index;
182
- if (typeof indexed === 'number') {
183
- const value = indexedColors[indexed];
184
- if (value) {
185
- return `#${value.slice(-6)}`;
186
- }
187
- }
188
- return undefined;
189
- };
190
- const isAutomaticPaletteColor = (color) => {
191
- if (!color) {
192
- return false;
193
- }
194
- const indexed = typeof color.indexed === 'number' ? color.indexed : color.index;
195
- return indexed === 32767;
196
- };
197
- const normalizeFontColor = (color) => {
198
- // BIFF/XLS 会把“自动字体色”解析成 indexed 32767,部分文件还会附带
199
- // FFFFFF 的 rgb 值。Excel 实际显示为默认黑色,不能当成显式白色。
200
- if (isAutomaticPaletteColor(color)) {
201
- return EXCEL_DEFAULT_TEXT_COLOR;
202
- }
203
- return normalizeColor(color);
204
- };
205
- const borderWidthFromStyle = (borderStyle) => {
206
- switch (borderStyle) {
207
- case 'hair':
208
- return '0.5px';
209
- case 'medium':
210
- case 'mediumDashed':
211
- case 'mediumDashDot':
212
- case 'mediumDashDotDot':
213
- return '2px';
214
- case 'thick':
215
- case 'double':
216
- return '3px';
217
- default:
218
- return '1px';
219
- }
220
- };
221
- const borderStyleToCss = (borderStyle) => {
222
- switch (borderStyle) {
223
- case 'dashed':
224
- case 'mediumDashed':
225
- case 'dashDot':
226
- case 'mediumDashDot':
227
- case 'dashDotDot':
228
- case 'mediumDashDotDot':
229
- case 'slantDashDot':
230
- return 'dashed';
231
- case 'dotted':
232
- return 'dotted';
233
- case 'double':
234
- return 'double';
235
- default:
236
- return 'solid';
237
- }
238
- };
239
- const mergeStyle = (...styles) => {
240
- const result = {};
241
- styles.forEach((style) => {
242
- if (!style) {
243
- return;
244
- }
245
- Object.entries(style).forEach(([key, value]) => {
246
- if (value && typeof value === 'object' && !Array.isArray(value)) {
247
- result[key] = {
248
- ...(result[key] && typeof result[key] === 'object' ? result[key] : {}),
249
- ...value
250
- };
251
- return;
252
- }
253
- result[key] = value;
254
- });
255
- });
256
- return Object.keys(result).length ? result : undefined;
257
- };
258
- const getCellStyle = (cellStyle) => {
259
- const style = {};
260
- const fill = (cellStyle === null || cellStyle === void 0 ? void 0 : cellStyle.fill) || {};
261
- const fillColor = normalizeColor((cellStyle === null || cellStyle === void 0 ? void 0 : cellStyle.fgColor) || fill.fgColor || (cellStyle === null || cellStyle === void 0 ? void 0 : cellStyle.bgColor) || fill.bgColor);
262
- const patternType = (cellStyle === null || cellStyle === void 0 ? void 0 : cellStyle.patternType) || fill.patternType;
263
- if (fillColor && patternType !== 'none') {
264
- style.backgroundColor = fillColor;
265
- }
266
- const font = (cellStyle === null || cellStyle === void 0 ? void 0 : cellStyle.font) || {};
267
- const fontColor = normalizeFontColor(font.color || (cellStyle === null || cellStyle === void 0 ? void 0 : cellStyle.color));
268
- if (fontColor) {
269
- style.color = fontColor;
270
- }
271
- if (font.italic || (cellStyle === null || cellStyle === void 0 ? void 0 : cellStyle.italic)) {
272
- style.fontStyle = 'italic';
273
- }
274
- if (font.bold || (cellStyle === null || cellStyle === void 0 ? void 0 : cellStyle.bold)) {
275
- style.fontWeight = 'bold';
276
- }
277
- const fontSize = font.sz || (cellStyle === null || cellStyle === void 0 ? void 0 : cellStyle.sz);
278
- if (fontSize) {
279
- style.fontSize = `${fontSize}px`;
280
- }
281
- const fontName = font.name || (cellStyle === null || cellStyle === void 0 ? void 0 : cellStyle.name);
282
- if (fontName) {
283
- style.fontFamily = fontName;
284
- }
285
- const border = cellStyle === null || cellStyle === void 0 ? void 0 : cellStyle.border;
286
- if (border) {
287
- ;
288
- ['top', 'right', 'bottom', 'left'].forEach((side) => {
289
- const borderItem = border[side];
290
- if (!(borderItem === null || borderItem === void 0 ? void 0 : borderItem.style) || borderItem.style === 'none') {
291
- return;
292
- }
293
- const prefix = `border${side.charAt(0).toUpperCase()}${side.slice(1)}`;
294
- style[`${prefix}Width`] = borderWidthFromStyle(borderItem.style);
295
- style[`${prefix}Style`] = borderStyleToCss(borderItem.style);
296
- style[`${prefix}Color`] = normalizeColor(borderItem.color) || '#000000';
297
- });
298
- }
299
- return Object.keys(style).length ? style : undefined;
300
- };
301
- const fixMatrix = (data, colLen) => {
302
- for (const row of data) {
303
- for (let index = 0; index < colLen; index += 1) {
304
- if (row[index] === undefined || row[index] === null) {
305
- row[index] = '';
306
- }
307
- }
308
- }
309
- return data;
310
- };
311
- class SheetJsModel {
312
- static create(ws, options = {}) {
313
- return new SheetJsModel(ws, options);
314
- }
315
- constructor(ws, options) {
316
- this._ws = ws;
317
- this._startRow = Math.max(options.startRow || 0, 0);
318
- this._pageSize = Math.max(options.pageSize || 500, 1);
319
- this._totalRows = options.totalRows;
320
- this._totalCols = options.totalCols;
321
- const { '!ref': refs } = ws;
322
- this.range = utils.decode_range(refs || 'A1');
323
- }
324
- get ws() {
325
- return this._ws;
326
- }
327
- get defaults() {
328
- return SheetJsModel.defaults;
329
- }
330
- get data() {
331
- var _a;
332
- return (_a = this._data) !== null && _a !== void 0 ? _a : (this._data = this.getData());
333
- }
334
- get cell() {
335
- var _a;
336
- return (_a = this._cell) !== null && _a !== void 0 ? _a : (this._cell = this.getCell());
337
- }
338
- get merge() {
339
- var _a;
340
- return (_a = this._merge) !== null && _a !== void 0 ? _a : (this._merge = this.getMerge());
341
- }
342
- get columns() {
343
- var _a;
344
- return (_a = this._columns) !== null && _a !== void 0 ? _a : (this._columns = this.getColumns());
345
- }
346
- get structure() {
347
- var _a;
348
- return (_a = this._structure) !== null && _a !== void 0 ? _a : (this._structure = this.getStructure());
349
- }
350
- get rowHeights() {
351
- var _a;
352
- return (_a = this._rowHeights) !== null && _a !== void 0 ? _a : (this._rowHeights = this.getRowHeights());
353
- }
354
- get colWidths() {
355
- var _a;
356
- return (_a = this._colWidths) !== null && _a !== void 0 ? _a : (this._colWidths = this.getColWidths());
357
- }
358
- get meta() {
359
- var _a;
360
- return (_a = this._meta) !== null && _a !== void 0 ? _a : (this._meta = {
361
- startRow: this.startRow,
362
- endRow: this.endRow,
363
- pageSize: this._pageSize,
364
- totalRows: this.totalRows,
365
- totalCols: this.totalCols
366
- });
367
- }
368
- get totalRows() {
369
- var _a;
370
- return (_a = this._totalRows) !== null && _a !== void 0 ? _a : this.range.e.r + 1;
371
- }
372
- get totalCols() {
373
- var _a;
374
- return (_a = this._totalCols) !== null && _a !== void 0 ? _a : this.range.e.c + 1;
375
- }
376
- get startRow() {
377
- return Math.min(this._startRow, Math.max(this.totalRows - 1, 0));
378
- }
379
- get endRow() {
380
- return Math.min(this.startRow + this._pageSize, this.totalRows);
381
- }
382
- get denseRows() {
383
- const worksheet = this.ws;
384
- if (Array.isArray(worksheet)) {
385
- return worksheet;
386
- }
387
- return Array.isArray(worksheet['!data']) ? worksheet['!data'] : undefined;
388
- }
389
- getCellAt(row, col) {
390
- var _a;
391
- const rows = this.denseRows;
392
- if (rows) {
393
- return (_a = rows[row]) === null || _a === void 0 ? void 0 : _a[col];
394
- }
395
- return this.ws[utils.encode_cell({ r: row, c: col })];
396
- }
397
- getAxisOffset(index, sizes, fallback) {
398
- let offset = 0;
399
- for (let current = 0; current < index; current += 1) {
400
- offset += getVectorSize(sizes, current, fallback);
401
- }
402
- return offset;
403
- }
404
- getMarkerLeft(marker) {
405
- if (!marker) {
406
- return 0;
407
- }
408
- return this.getAxisOffset(marker.col || 0, this.getColWidths(), this.defaults.colWidth) + emuToPixels(marker.colOff);
409
- }
410
- getMarkerTop(marker) {
411
- if (!marker) {
412
- return 0;
413
- }
414
- return this.getAxisOffset(marker.row || 0, this.getAllRowHeights(), this.defaults.rowHeight) + emuToPixels(marker.rowOff);
415
- }
416
- getImages() {
417
- const drawings = this.ws['!drawings'];
418
- const images = (drawings === null || drawings === void 0 ? void 0 : drawings.images) || [];
419
- if (!images.length) {
420
- return undefined;
421
- }
422
- const result = images.flatMap((image, index) => {
423
- var _a, _b, _c, _d, _e;
424
- const anchor = image.anchor;
425
- if (!image.dataURI || !anchor) {
426
- return [];
427
- }
428
- const from = anchor.from;
429
- const left = from ? this.getMarkerLeft(from) : emuToPixels((_a = anchor.pos) === null || _a === void 0 ? void 0 : _a.x);
430
- const top = from ? this.getMarkerTop(from) : emuToPixels((_b = anchor.pos) === null || _b === void 0 ? void 0 : _b.y);
431
- const right = anchor.to ? this.getMarkerLeft(anchor.to) : left + emuToPixels((_c = anchor.ext) === null || _c === void 0 ? void 0 : _c.cx);
432
- const bottom = anchor.to ? this.getMarkerTop(anchor.to) : top + emuToPixels((_d = anchor.ext) === null || _d === void 0 ? void 0 : _d.cy);
433
- return [{
434
- id: image.id || ((_e = image.objectId) === null || _e === void 0 ? void 0 : _e.toString()) || image.target || `image-${index + 1}`,
435
- src: image.dataURI,
436
- contentType: image.contentType,
437
- left: Math.max(0, left),
438
- top: Math.max(0, top),
439
- width: Math.max(1, right > left ? right - left : DEFAULT_IMAGE_WIDTH),
440
- height: Math.max(1, bottom > top ? bottom - top : DEFAULT_IMAGE_HEIGHT),
441
- row: (from === null || from === void 0 ? void 0 : from.row) || 0,
442
- col: (from === null || from === void 0 ? void 0 : from.col) || 0
443
- }];
444
- });
445
- return result.length ? result : undefined;
446
- }
447
- getAllMerge() {
448
- const sheet = this.ws;
449
- const { '!merges': merges = [] } = sheet;
450
- return merges.map((merge) => {
451
- const { r: top, c: left } = merge.s;
452
- const { r: bottom, c: right } = merge.e;
453
- return {
454
- row: top,
455
- col: left,
456
- rowspan: bottom - top + 1,
457
- colspan: right - left + 1
458
- };
459
- });
460
- }
461
- getData() {
462
- const result = [];
463
- const rows = this.denseRows;
464
- for (let rowIndex = this.startRow; rowIndex < this.endRow; rowIndex += 1) {
465
- const row = rows === null || rows === void 0 ? void 0 : rows[rowIndex];
466
- const values = row
467
- ? row.slice(0, this.totalCols).map(cell => formatCellValue(cell))
468
- : Array.from({ length: this.totalCols }, (_, colIndex) => formatCellValue(this.getCellAt(rowIndex, colIndex)));
469
- result.push(values);
470
- }
471
- return fixMatrix(result, this.totalCols);
472
- }
473
- getCell() {
474
- var _a, _b;
475
- const result = {};
476
- const { '!cols': cols = [], '!rows': rows = [] } = this.ws;
477
- for (let rowIndex = this.startRow; rowIndex < this.endRow; rowIndex += 1) {
478
- for (let colIndex = 0; colIndex < this.totalCols; colIndex += 1) {
479
- const cell = this.getCellAt(rowIndex, colIndex);
480
- const rawStyle = mergeStyle((_a = cols[colIndex]) === null || _a === void 0 ? void 0 : _a.s, (_b = rows[rowIndex]) === null || _b === void 0 ? void 0 : _b.s, cell === null || cell === void 0 ? void 0 : cell.s);
481
- const className = alignToClassName(rawStyle === null || rawStyle === void 0 ? void 0 : rawStyle.alignment);
482
- const style = getCellStyle(rawStyle);
483
- if (!className && !style) {
484
- continue;
485
- }
486
- result[cellKey(rowIndex - this.startRow, colIndex)] = {
487
- ...(className ? { className } : {}),
488
- style: style || {}
489
- };
490
- }
491
- }
492
- return result;
493
- }
494
- getMerge() {
495
- return this.getAllMerge().flatMap((merge) => {
496
- const bottom = merge.row + merge.rowspan - 1;
497
- if (bottom < this.startRow || merge.row >= this.endRow || merge.row < this.startRow) {
498
- return [];
499
- }
500
- return {
501
- ...merge,
502
- row: merge.row - this.startRow
503
- };
504
- });
505
- }
506
- getRowHeights() {
507
- const { rowHeight } = this.defaults;
508
- const { '!rows': rows = [] } = this.ws;
509
- const heights = [];
510
- if (rows.length && this.endRow > this.startRow) {
511
- for (let absoluteRow = this.startRow; absoluteRow < this.endRow; absoluteRow += 1) {
512
- const height = getRowPixelHeight(rows[absoluteRow]);
513
- if (height !== undefined) {
514
- heights[absoluteRow - this.startRow] = height;
515
- }
516
- }
517
- }
518
- if (heights.length === 1) {
519
- return heights[0];
520
- }
521
- return heights.length ? heights : rowHeight;
522
- }
523
- // 整表行高必须按绝对行号下发,否则拖动滚动条时隐藏行和特殊行高会造成高度跳变。
524
- getAllRowHeights() {
525
- const { '!rows': rows = [] } = this.ws;
526
- const heights = [];
527
- if (rows.length) {
528
- for (let absoluteRow = 0; absoluteRow < this.totalRows; absoluteRow += 1) {
529
- const height = getRowPixelHeight(rows[absoluteRow]);
530
- if (height !== undefined) {
531
- heights[absoluteRow] = height;
532
- }
533
- }
534
- }
535
- return heights.length ? heights : undefined;
536
- }
537
- getAutoFitColumns() {
538
- const autoFitColumns = utils.auto_fit_columns || utils.autofit_columns;
539
- if (typeof autoFitColumns !== 'function') {
540
- return undefined;
541
- }
542
- try {
543
- // 自动列宽只作为缺失列宽的兜底。合并标题和 Excel 溢出文本不应该反向撑开基础列宽。
544
- return autoFitColumns(this.ws, {
545
- set: false,
546
- skipHidden: true,
547
- includeMerged: false,
548
- minPx: AUTO_FIT_MIN_WIDTH,
549
- padding: AUTO_FIT_PADDING
550
- });
551
- }
552
- catch (error) {
553
- console.warn('[file-viewer] Excel 自动列宽计算失败,已回退到原始列宽。', error);
554
- return undefined;
555
- }
556
- }
557
- get autoFitColumns() {
558
- if (this._autoFitColumns === undefined) {
559
- this._autoFitColumns = this.getAutoFitColumns() || null;
560
- }
561
- return this._autoFitColumns || undefined;
562
- }
563
- getColumnMeta(sourceCols, colIndex) {
564
- var _a;
565
- const sourceColumn = sourceCols[colIndex];
566
- if (hasColumnWidth(sourceColumn)) {
567
- return sourceColumn;
568
- }
569
- // 没有显式列宽时,再使用 styled-exceljs 的内容测量兜底,避免报表类标题污染原始宽度。
570
- return ((_a = this.autoFitColumns) === null || _a === void 0 ? void 0 : _a[colIndex]) || sourceColumn;
571
- }
572
- getColWidths() {
573
- const { colWidth } = this.defaults;
574
- const { '!cols': sourceCols = [] } = this.ws;
575
- const widths = [];
576
- for (let colIndex = 0; colIndex < this.totalCols; colIndex += 1) {
577
- const width = getColumnPixelWidth(this.getColumnMeta(sourceCols, colIndex));
578
- if (width !== undefined) {
579
- widths[colIndex] = width;
580
- }
581
- }
582
- return widths.length ? widths : colWidth;
583
- }
584
- getColumns() {
585
- const { '!cols': sourceCols = [] } = this.ws;
586
- return Array.from({ length: this.totalCols }, (_, index) => {
587
- var _a;
588
- const column = this.getColumnMeta(sourceCols, index);
589
- return {
590
- key: index + 1,
591
- title: utils.encode_col(index),
592
- hidden: !!(column === null || column === void 0 ? void 0 : column.hidden),
593
- editor: false,
594
- className: alignToClassName((_a = column === null || column === void 0 ? void 0 : column.s) === null || _a === void 0 ? void 0 : _a.alignment),
595
- renderer: 'styleRender'
596
- };
597
- });
598
- }
599
- getStructure() {
600
- return {
601
- merge: this.getAllMerge(),
602
- colWidths: this.getColWidths(),
603
- rowHeights: this.getAllRowHeights(),
604
- columns: this.getColumns(),
605
- images: this.getImages()
606
- };
607
- }
608
- toObject() {
609
- const { defaults, data, cell, merge, rowHeights, colWidths, columns, meta } = this;
610
- return {
611
- defaults,
612
- data,
613
- cell,
614
- merge,
615
- rowHeights,
616
- colWidths,
617
- columns,
618
- meta
619
- };
620
- }
621
- }
622
- SheetJsModel.defaults = defaults;
623
- export default SheetJsModel;
@@ -1,2 +0,0 @@
1
- export declare const indexedColors: string[];
2
- export declare function getTintColor(hex: string, tint: number): string;