@a3s-lab/office 0.31.0 → 0.32.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.
- package/README.md +6 -3
- package/dist/0~4808.js +1 -1
- package/dist/0~4980.js +1 -1
- package/dist/0~7240.js +1 -1
- package/dist/0~7614.js +1 -1
- package/dist/0~document-editor.js +1085 -4
- package/dist/0~spreadsheet-editor.js +2 -1
- package/dist/0~work-docx-export.js +1 -1
- package/dist/0~work-docx-import.js +10 -27
- package/dist/0~work-docx-large-document-import.js +1 -1
- package/dist/0~work-office-diagnostics.js +3 -3
- package/dist/0~work-pptx-import.js +1 -1
- package/dist/{1544.js → 3266.js} +17 -1862
- package/dist/4121.js +13 -0
- package/dist/4166.js +3848 -0
- package/dist/{6282.js → 4174.js} +383 -10
- package/dist/9333.js +1849 -0
- package/dist/core.js +5259 -4
- package/dist/index.js +3 -3
- package/dist/internal/features/work/editors/document-compare-dialog.d.ts +14 -0
- package/dist/internal/features/work/editors/document-toolbar.d.ts +3 -1
- package/dist/internal/features/work/editors/use-document-comparison.d.ts +9 -0
- package/dist/internal/features/work/work-document-changes.d.ts +5 -0
- package/dist/internal/features/work/work-document-compare-diff.d.ts +38 -0
- package/dist/internal/features/work/work-document-compare-stability.d.ts +5 -0
- package/dist/internal/features/work/work-document-compare.d.ts +27 -0
- package/dist/office-kernel.wasm +0 -0
- package/dist/styles.css +194 -0
- package/docs/latest/en/browser-editor-architecture.md +23 -0
- package/package.json +6 -3
- package/dist/4104.js +0 -9336
package/dist/9333.js
ADDED
|
@@ -0,0 +1,1849 @@
|
|
|
1
|
+
import { directChild, directChildren, attribute, firstDescendant } from "./4121.js";
|
|
2
|
+
import { sparseMatrixColumnCount, cloneSparseMatrix, sparseArrayIndexes, sparseArrayEntries as spreadsheet_sparse_sparseArrayEntries, formatSpreadsheetCellRanges, parseSpreadsheetCellRanges as work_spreadsheet_ranges_parseSpreadsheetCellRanges } from "./8715.js";
|
|
3
|
+
function* xlsxWorksheetCellEntries(worksheet) {
|
|
4
|
+
if (Array.isArray(worksheet)) {
|
|
5
|
+
for(let row = 0; row < worksheet.length; row += 1){
|
|
6
|
+
const cells = worksheet[row];
|
|
7
|
+
if (Array.isArray(cells)) for(let column = 0; column < cells.length; column += 1){
|
|
8
|
+
const cell = cells[column];
|
|
9
|
+
if (!(!cell || 'object' != typeof cell || Array.isArray(cell))) yield {
|
|
10
|
+
address: xlsxCellAddress(row, column),
|
|
11
|
+
cell: cell,
|
|
12
|
+
column,
|
|
13
|
+
row
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
for (const [address, cell] of Object.entries(worksheet)){
|
|
20
|
+
if (address.startsWith('!') || !cell || 'object' != typeof cell) continue;
|
|
21
|
+
const position = decodeXlsxCellAddress(address);
|
|
22
|
+
if (position) yield {
|
|
23
|
+
address,
|
|
24
|
+
cell: cell,
|
|
25
|
+
...position
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function xlsxCellAddress(row, column) {
|
|
30
|
+
let value = column + 1;
|
|
31
|
+
let label = '';
|
|
32
|
+
while(value > 0){
|
|
33
|
+
value -= 1;
|
|
34
|
+
label = String.fromCharCode(65 + value % 26) + label;
|
|
35
|
+
value = Math.floor(value / 26);
|
|
36
|
+
}
|
|
37
|
+
return `${label}${row + 1}`;
|
|
38
|
+
}
|
|
39
|
+
function decodeXlsxCellAddress(address) {
|
|
40
|
+
const match = /^([A-Za-z]+)([1-9][0-9]*)$/.exec(address);
|
|
41
|
+
if (!match) return null;
|
|
42
|
+
let column = 0;
|
|
43
|
+
for (const character of match[1].toUpperCase())column = 26 * column + character.charCodeAt(0) - 64;
|
|
44
|
+
const row = Number(match[2]);
|
|
45
|
+
if (!Number.isSafeInteger(row) || row <= 0) return null;
|
|
46
|
+
return {
|
|
47
|
+
column: column - 1,
|
|
48
|
+
row: row - 1
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const spreadsheetFormulaHistoryIgnoredKeys = new Set([
|
|
52
|
+
'ct',
|
|
53
|
+
'm',
|
|
54
|
+
'v'
|
|
55
|
+
]);
|
|
56
|
+
function sameSpreadsheetHistoryValue(left, right) {
|
|
57
|
+
if (left === right) return true;
|
|
58
|
+
if (null === left || null === right || typeof left !== typeof right) return false;
|
|
59
|
+
const leftFormulaCell = spreadsheetFormulaCell(left);
|
|
60
|
+
const rightFormulaCell = spreadsheetFormulaCell(right);
|
|
61
|
+
if (leftFormulaCell || rightFormulaCell) return Boolean(leftFormulaCell && rightFormulaCell && sameSpreadsheetFormulaHistoryCell(leftFormulaCell, rightFormulaCell));
|
|
62
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
63
|
+
if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) return false;
|
|
64
|
+
const leftKeys = Object.keys(left).filter((key)=>void 0 !== left[Number(key)]);
|
|
65
|
+
const rightKeys = Object.keys(right).filter((key)=>void 0 !== right[Number(key)]);
|
|
66
|
+
return leftKeys.length === rightKeys.length && leftKeys.every((key)=>Object.hasOwn(right, key) && sameSpreadsheetHistoryValue(left[Number(key)], right[Number(key)]));
|
|
67
|
+
}
|
|
68
|
+
if ('object' != typeof left || 'object' != typeof right) return false;
|
|
69
|
+
const leftRecord = left;
|
|
70
|
+
const rightRecord = right;
|
|
71
|
+
const leftKeys = Object.keys(leftRecord).filter((key)=>void 0 !== leftRecord[key]);
|
|
72
|
+
const rightKeys = Object.keys(rightRecord).filter((key)=>void 0 !== rightRecord[key]);
|
|
73
|
+
return leftKeys.length === rightKeys.length && leftKeys.every((key)=>sameSpreadsheetHistoryValue(leftRecord[key], rightRecord[key]));
|
|
74
|
+
}
|
|
75
|
+
function spreadsheetFormulaCell(value) {
|
|
76
|
+
return value && 'object' == typeof value && 'string' == typeof value.f ? value : null;
|
|
77
|
+
}
|
|
78
|
+
function sameSpreadsheetFormulaHistoryCell(left, right) {
|
|
79
|
+
const leftRecord = left;
|
|
80
|
+
const rightRecord = right;
|
|
81
|
+
const leftKeys = Object.keys(leftRecord).filter((key)=>!spreadsheetFormulaHistoryIgnoredKeys.has(key) && void 0 !== leftRecord[key]);
|
|
82
|
+
const rightKeys = Object.keys(rightRecord).filter((key)=>!spreadsheetFormulaHistoryIgnoredKeys.has(key) && void 0 !== rightRecord[key]);
|
|
83
|
+
return leftKeys.length === rightKeys.length && leftKeys.every((key)=>sameSpreadsheetHistoryValue(leftRecord[key], rightRecord[key])) && sameSpreadsheetHistoryValue(spreadsheetFormulaHistoryCellType(left.ct), spreadsheetFormulaHistoryCellType(right.ct));
|
|
84
|
+
}
|
|
85
|
+
function spreadsheetFormulaHistoryCellType(cellType) {
|
|
86
|
+
if (!cellType) return;
|
|
87
|
+
const { fa, t: _type, ...retainedCellType } = cellType;
|
|
88
|
+
const normalized = {
|
|
89
|
+
...retainedCellType,
|
|
90
|
+
...fa && 'General' !== fa ? {
|
|
91
|
+
fa
|
|
92
|
+
} : {}
|
|
93
|
+
};
|
|
94
|
+
return Object.keys(normalized).length ? normalized : void 0;
|
|
95
|
+
}
|
|
96
|
+
const borderChildOrder = [
|
|
97
|
+
'start',
|
|
98
|
+
'end',
|
|
99
|
+
'left',
|
|
100
|
+
'right',
|
|
101
|
+
'top',
|
|
102
|
+
'bottom',
|
|
103
|
+
'diagonal',
|
|
104
|
+
'vertical',
|
|
105
|
+
'horizontal',
|
|
106
|
+
'extLst'
|
|
107
|
+
];
|
|
108
|
+
function ensureXlsxStyleCollection(document, name, anchors) {
|
|
109
|
+
const root = document.documentElement;
|
|
110
|
+
const existing = directChild(root, name);
|
|
111
|
+
if (existing) return existing;
|
|
112
|
+
const collection = document.createElementNS(root.namespaceURI, name);
|
|
113
|
+
root.insertBefore(collection, directChildren(root).find((child)=>anchors.includes(child.localName)) ?? null);
|
|
114
|
+
return collection;
|
|
115
|
+
}
|
|
116
|
+
function defaultXlsxFill(document, patternType) {
|
|
117
|
+
const fill = document.createElementNS(document.documentElement.namespaceURI, 'fill');
|
|
118
|
+
const pattern = document.createElementNS(document.documentElement.namespaceURI, 'patternFill');
|
|
119
|
+
pattern.setAttribute('patternType', patternType);
|
|
120
|
+
fill.append(pattern);
|
|
121
|
+
return fill;
|
|
122
|
+
}
|
|
123
|
+
function defaultXlsxBorder(document) {
|
|
124
|
+
const border = document.createElementNS(document.documentElement.namespaceURI, 'border');
|
|
125
|
+
for (const name of [
|
|
126
|
+
'left',
|
|
127
|
+
'right',
|
|
128
|
+
'top',
|
|
129
|
+
'bottom',
|
|
130
|
+
'diagonal'
|
|
131
|
+
])border.append(document.createElementNS(document.documentElement.namespaceURI, name));
|
|
132
|
+
return border;
|
|
133
|
+
}
|
|
134
|
+
function setXlsxBorderLine(document, border, name, line) {
|
|
135
|
+
removeXlsxChildren(border, name);
|
|
136
|
+
const element = document.createElementNS(document.documentElement.namespaceURI, name);
|
|
137
|
+
if (line) {
|
|
138
|
+
element.setAttribute('style', line.style);
|
|
139
|
+
const color = xlsxRgbColor(line.color);
|
|
140
|
+
if (color) {
|
|
141
|
+
const child = document.createElementNS(document.documentElement.namespaceURI, 'color');
|
|
142
|
+
child.setAttribute('rgb', color);
|
|
143
|
+
element.append(child);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
insertXlsxOrderedChild(border, element, borderChildOrder);
|
|
147
|
+
}
|
|
148
|
+
function writeXlsxAlignment(document, xf, style) {
|
|
149
|
+
let alignment = directChild(xf, 'alignment');
|
|
150
|
+
if (!alignment) {
|
|
151
|
+
alignment = document.createElementNS(document.documentElement.namespaceURI, 'alignment');
|
|
152
|
+
xf.insertBefore(alignment, directChildren(xf).find((child)=>[
|
|
153
|
+
'protection',
|
|
154
|
+
'extLst'
|
|
155
|
+
].includes(child.localName)) ?? null);
|
|
156
|
+
}
|
|
157
|
+
if (void 0 !== style.horizontal) alignment.setAttribute('horizontal', style.horizontal);
|
|
158
|
+
if (void 0 !== style.vertical) alignment.setAttribute('vertical', style.vertical);
|
|
159
|
+
if (void 0 !== style.wrapText) alignment.setAttribute('wrapText', style.wrapText ? '1' : '0');
|
|
160
|
+
if (void 0 !== style.textRotation && Number.isInteger(style.textRotation) && (style.textRotation >= 0 && style.textRotation <= 180 || 255 === style.textRotation)) alignment.setAttribute('textRotation', String(style.textRotation));
|
|
161
|
+
}
|
|
162
|
+
function setXlsxValueChild(document, parent, name, value, order) {
|
|
163
|
+
removeXlsxChildren(parent, name);
|
|
164
|
+
const child = document.createElementNS(document.documentElement.namespaceURI, name);
|
|
165
|
+
child.setAttribute('val', value);
|
|
166
|
+
insertXlsxOrderedChild(parent, child, order);
|
|
167
|
+
}
|
|
168
|
+
function setXlsxColorChild(document, parent, color, order) {
|
|
169
|
+
removeXlsxChildren(parent, 'color');
|
|
170
|
+
const child = document.createElementNS(document.documentElement.namespaceURI, 'color');
|
|
171
|
+
child.setAttribute('rgb', color);
|
|
172
|
+
insertXlsxOrderedChild(parent, child, order);
|
|
173
|
+
}
|
|
174
|
+
function setXlsxToggleChild(document, parent, name, enabled, order) {
|
|
175
|
+
removeXlsxChildren(parent, name);
|
|
176
|
+
if (!enabled) return;
|
|
177
|
+
const child = document.createElementNS(document.documentElement.namespaceURI, name);
|
|
178
|
+
child.setAttribute('val', '1');
|
|
179
|
+
insertXlsxOrderedChild(parent, child, order);
|
|
180
|
+
}
|
|
181
|
+
function setXlsxUnderlineChild(document, parent, style, order) {
|
|
182
|
+
removeXlsxChildren(parent, 'u');
|
|
183
|
+
if ('none' === style) return;
|
|
184
|
+
const child = document.createElementNS(document.documentElement.namespaceURI, 'u');
|
|
185
|
+
child.setAttribute('val', style);
|
|
186
|
+
insertXlsxOrderedChild(parent, child, order);
|
|
187
|
+
}
|
|
188
|
+
function xlsxRgbColor(value) {
|
|
189
|
+
if ('string' != typeof value) return null;
|
|
190
|
+
const color = value.trim().replace('#', '').toUpperCase();
|
|
191
|
+
if (/^[0-9A-F]{6}$/.test(color)) return `FF${color}`;
|
|
192
|
+
if (/^[0-9A-F]{8}$/.test(color)) return color;
|
|
193
|
+
if (/^[0-9A-F]{3}$/.test(color)) return `FF${[
|
|
194
|
+
...color
|
|
195
|
+
].map((character)=>character.repeat(2)).join('')}`;
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
function removeXlsxChildren(parent, name) {
|
|
199
|
+
for (const child of directChildren(parent, name))child.remove();
|
|
200
|
+
}
|
|
201
|
+
function insertXlsxOrderedChild(parent, child, order) {
|
|
202
|
+
const requested = order.indexOf(child.localName);
|
|
203
|
+
const anchor = directChildren(parent).find((candidate)=>order.indexOf(candidate.localName) > requested);
|
|
204
|
+
parent.insertBefore(child, anchor ?? null);
|
|
205
|
+
}
|
|
206
|
+
const defaultThemeColors = [
|
|
207
|
+
'ffffff',
|
|
208
|
+
'000000',
|
|
209
|
+
'e7e6e6',
|
|
210
|
+
'44546a',
|
|
211
|
+
'4472c4',
|
|
212
|
+
'ed7d31',
|
|
213
|
+
'a5a5a5',
|
|
214
|
+
'ffc000',
|
|
215
|
+
'5b9bd5',
|
|
216
|
+
'70ad47',
|
|
217
|
+
'0563c1',
|
|
218
|
+
'954f72'
|
|
219
|
+
];
|
|
220
|
+
const themeColorNames = [
|
|
221
|
+
'lt1',
|
|
222
|
+
'dk1',
|
|
223
|
+
'lt2',
|
|
224
|
+
'dk2',
|
|
225
|
+
'accent1',
|
|
226
|
+
'accent2',
|
|
227
|
+
'accent3',
|
|
228
|
+
'accent4',
|
|
229
|
+
'accent5',
|
|
230
|
+
'accent6',
|
|
231
|
+
'hlink',
|
|
232
|
+
'folHlink'
|
|
233
|
+
];
|
|
234
|
+
const defaultIndexedColors = [
|
|
235
|
+
'000000',
|
|
236
|
+
'ffffff',
|
|
237
|
+
'ff0000',
|
|
238
|
+
'00ff00',
|
|
239
|
+
'0000ff',
|
|
240
|
+
'ffff00',
|
|
241
|
+
'ff00ff',
|
|
242
|
+
'00ffff',
|
|
243
|
+
'000000',
|
|
244
|
+
'ffffff',
|
|
245
|
+
'ff0000',
|
|
246
|
+
'00ff00',
|
|
247
|
+
'0000ff',
|
|
248
|
+
'ffff00',
|
|
249
|
+
'ff00ff',
|
|
250
|
+
'00ffff',
|
|
251
|
+
'800000',
|
|
252
|
+
'008000',
|
|
253
|
+
'000080',
|
|
254
|
+
'808000',
|
|
255
|
+
'800080',
|
|
256
|
+
'008080',
|
|
257
|
+
'c0c0c0',
|
|
258
|
+
'808080',
|
|
259
|
+
'9999ff',
|
|
260
|
+
'993366',
|
|
261
|
+
'ffffcc',
|
|
262
|
+
'ccffff',
|
|
263
|
+
'660066',
|
|
264
|
+
'ff8080',
|
|
265
|
+
'0066cc',
|
|
266
|
+
'ccccff',
|
|
267
|
+
'000080',
|
|
268
|
+
'ff00ff',
|
|
269
|
+
'ffff00',
|
|
270
|
+
'00ffff',
|
|
271
|
+
'800080',
|
|
272
|
+
'800000',
|
|
273
|
+
'008080',
|
|
274
|
+
'0000ff',
|
|
275
|
+
'00ccff',
|
|
276
|
+
'ccffff',
|
|
277
|
+
'ccffcc',
|
|
278
|
+
'ffff99',
|
|
279
|
+
'99ccff',
|
|
280
|
+
'ff99cc',
|
|
281
|
+
'cc99ff',
|
|
282
|
+
'ffcc99',
|
|
283
|
+
'3366ff',
|
|
284
|
+
'33cccc',
|
|
285
|
+
'99cc00',
|
|
286
|
+
'ffcc00',
|
|
287
|
+
'ff9900',
|
|
288
|
+
'ff6600',
|
|
289
|
+
'666699',
|
|
290
|
+
'969696',
|
|
291
|
+
'003366',
|
|
292
|
+
'339966',
|
|
293
|
+
'003300',
|
|
294
|
+
'333300',
|
|
295
|
+
'993300',
|
|
296
|
+
'993366',
|
|
297
|
+
'333399',
|
|
298
|
+
'333333'
|
|
299
|
+
];
|
|
300
|
+
function createXlsxColorResolver(styles, theme) {
|
|
301
|
+
return {
|
|
302
|
+
indexed: styles ? readIndexedColors(styles) : defaultIndexedColors,
|
|
303
|
+
theme: readThemeColors(theme)
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
function resolveXlsxColor(element, resolver) {
|
|
307
|
+
if (!element) return;
|
|
308
|
+
const direct = normalizedHexColor(attribute(element, 'rgb'));
|
|
309
|
+
const themeIndex = boundedInteger(attribute(element, 'theme'), 11);
|
|
310
|
+
const indexed = boundedInteger(attribute(element, 'indexed'), 65535);
|
|
311
|
+
const automatic = booleanAttribute(element, 'auto');
|
|
312
|
+
const source = direct ?? (null === themeIndex ? void 0 : resolver.theme[themeIndex]) ?? (null === indexed ? void 0 : resolver.indexed[indexed]) ?? (automatic ? '000000' : void 0);
|
|
313
|
+
if (!source) return;
|
|
314
|
+
const tint = Number(attribute(element, 'tint'));
|
|
315
|
+
return `#${Number.isFinite(tint) && tint >= -1 && tint <= 1 ? tintXlsxColor(source, tint) : source}`;
|
|
316
|
+
}
|
|
317
|
+
function readThemeColors(theme) {
|
|
318
|
+
if (!theme) return defaultThemeColors;
|
|
319
|
+
const scheme = firstDescendant(theme, 'clrScheme');
|
|
320
|
+
if (!scheme) return defaultThemeColors;
|
|
321
|
+
return themeColorNames.map((name, index)=>{
|
|
322
|
+
const entry = directChild(scheme, name);
|
|
323
|
+
const color = entry ? drawingColor(directChildren(entry)[0]) : void 0;
|
|
324
|
+
return color ?? defaultThemeColors[index];
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
function readIndexedColors(styles) {
|
|
328
|
+
const indexed = firstDescendant(styles, 'indexedColors');
|
|
329
|
+
if (!indexed) return defaultIndexedColors;
|
|
330
|
+
const colors = directChildren(indexed, 'rgbColor').map((element)=>normalizedHexColor(attribute(element, 'rgb')));
|
|
331
|
+
return colors.every(Boolean) ? colors : defaultIndexedColors;
|
|
332
|
+
}
|
|
333
|
+
function drawingColor(element) {
|
|
334
|
+
if (!element) return;
|
|
335
|
+
return normalizedHexColor('sysClr' === element.localName ? attribute(element, 'lastClr') : attribute(element, 'val'));
|
|
336
|
+
}
|
|
337
|
+
function tintXlsxColor(color, tint) {
|
|
338
|
+
const [hue, saturation, lightness] = rgbToHsl([
|
|
339
|
+
0,
|
|
340
|
+
2,
|
|
341
|
+
4
|
|
342
|
+
].map((offset)=>Number.parseInt(color.slice(offset, offset + 2), 16) / 255));
|
|
343
|
+
const tintedLightness = tint < 0 ? lightness * (1 + tint) : 1 - (1 - lightness) * (1 - tint);
|
|
344
|
+
return hslToRgb(hue, saturation, tintedLightness).map((channel)=>Math.round(255 * channel)).map((channel)=>channel.toString(16).padStart(2, '0')).join('');
|
|
345
|
+
}
|
|
346
|
+
function rgbToHsl([red, green, blue]) {
|
|
347
|
+
const maximum = Math.max(red, green, blue);
|
|
348
|
+
const minimum = Math.min(red, green, blue);
|
|
349
|
+
const delta = maximum - minimum;
|
|
350
|
+
const lightness = (maximum + minimum) / 2;
|
|
351
|
+
if (0 === delta) return [
|
|
352
|
+
0,
|
|
353
|
+
0,
|
|
354
|
+
lightness
|
|
355
|
+
];
|
|
356
|
+
const saturation = delta / (1 - Math.abs(2 * lightness - 1));
|
|
357
|
+
const hue = maximum === red ? ((green - blue) / delta + (green < blue ? 6 : 0)) / 6 : maximum === green ? ((blue - red) / delta + 2) / 6 : ((red - green) / delta + 4) / 6;
|
|
358
|
+
return [
|
|
359
|
+
hue,
|
|
360
|
+
saturation,
|
|
361
|
+
lightness
|
|
362
|
+
];
|
|
363
|
+
}
|
|
364
|
+
function hslToRgb(hue, saturation, lightness) {
|
|
365
|
+
if (0 === saturation) return [
|
|
366
|
+
lightness,
|
|
367
|
+
lightness,
|
|
368
|
+
lightness
|
|
369
|
+
];
|
|
370
|
+
const chroma = 2 * saturation * (lightness < 0.5 ? lightness : 1 - lightness);
|
|
371
|
+
const minimum = lightness - chroma / 2;
|
|
372
|
+
const channels = [
|
|
373
|
+
minimum,
|
|
374
|
+
minimum,
|
|
375
|
+
minimum
|
|
376
|
+
];
|
|
377
|
+
const sector = 6 * hue;
|
|
378
|
+
switch(Math.floor(sector)){
|
|
379
|
+
case 0:
|
|
380
|
+
case 6:
|
|
381
|
+
channels[0] += chroma;
|
|
382
|
+
channels[1] += chroma * sector;
|
|
383
|
+
break;
|
|
384
|
+
case 1:
|
|
385
|
+
channels[0] += chroma * (2 - sector);
|
|
386
|
+
channels[1] += chroma;
|
|
387
|
+
break;
|
|
388
|
+
case 2:
|
|
389
|
+
channels[1] += chroma;
|
|
390
|
+
channels[2] += chroma * (sector - 2);
|
|
391
|
+
break;
|
|
392
|
+
case 3:
|
|
393
|
+
channels[1] += chroma * (4 - sector);
|
|
394
|
+
channels[2] += chroma;
|
|
395
|
+
break;
|
|
396
|
+
case 4:
|
|
397
|
+
channels[0] += chroma * (sector - 4);
|
|
398
|
+
channels[2] += chroma;
|
|
399
|
+
break;
|
|
400
|
+
case 5:
|
|
401
|
+
channels[0] += chroma;
|
|
402
|
+
channels[2] += chroma * (6 - sector);
|
|
403
|
+
break;
|
|
404
|
+
}
|
|
405
|
+
return channels;
|
|
406
|
+
}
|
|
407
|
+
function normalizedHexColor(value) {
|
|
408
|
+
if (!value || !/^[0-9a-f]{6,8}$/i.test(value)) return;
|
|
409
|
+
return value.slice(-6).toLowerCase();
|
|
410
|
+
}
|
|
411
|
+
function boundedInteger(value, maximum) {
|
|
412
|
+
if (null === value || !/^\d+$/.test(value)) return null;
|
|
413
|
+
const parsed = Number(value);
|
|
414
|
+
return Number.isSafeInteger(parsed) && parsed <= maximum ? parsed : null;
|
|
415
|
+
}
|
|
416
|
+
function booleanAttribute(element, name) {
|
|
417
|
+
const value = attribute(element, name)?.trim().toLowerCase();
|
|
418
|
+
return '1' === value || 'true' === value || 'on' === value;
|
|
419
|
+
}
|
|
420
|
+
const THEME_COLOR_NAMES = [
|
|
421
|
+
'lt1',
|
|
422
|
+
'dk1',
|
|
423
|
+
'lt2',
|
|
424
|
+
'dk2',
|
|
425
|
+
'accent1',
|
|
426
|
+
'accent2',
|
|
427
|
+
'accent3',
|
|
428
|
+
'accent4',
|
|
429
|
+
'accent5',
|
|
430
|
+
'accent6',
|
|
431
|
+
'hlink',
|
|
432
|
+
'folHlink'
|
|
433
|
+
];
|
|
434
|
+
const MAX_INDEXED_COLOR = 255;
|
|
435
|
+
function readXlsxSemanticColorOrigin(element, colors) {
|
|
436
|
+
if (!element || attribute(element, 'rgb')) return;
|
|
437
|
+
const renderedColor = resolveXlsxColor(element, colors);
|
|
438
|
+
if (!renderedColor) return;
|
|
439
|
+
const tint = boundedTint(attribute(element, 'tint'));
|
|
440
|
+
const theme = work_xlsx_cell_style_origin_boundedInteger(attribute(element, 'theme'), THEME_COLOR_NAMES.length - 1);
|
|
441
|
+
if (null !== theme && colors.theme[theme]) return {
|
|
442
|
+
kind: 'theme',
|
|
443
|
+
baseColor: `#${colors.theme[theme]}`,
|
|
444
|
+
index: theme,
|
|
445
|
+
renderedColor,
|
|
446
|
+
...null === tint ? {} : {
|
|
447
|
+
tint
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
const indexed = work_xlsx_cell_style_origin_boundedInteger(attribute(element, 'indexed'), MAX_INDEXED_COLOR);
|
|
451
|
+
if (null !== indexed && colors.indexed[indexed]) return {
|
|
452
|
+
kind: 'indexed',
|
|
453
|
+
baseColor: `#${colors.indexed[indexed]}`,
|
|
454
|
+
index: indexed,
|
|
455
|
+
renderedColor,
|
|
456
|
+
...null === tint ? {} : {
|
|
457
|
+
tint
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
if (xlsxBooleanAttribute(element, 'auto')) return {
|
|
461
|
+
kind: 'automatic',
|
|
462
|
+
baseColor: '#000000',
|
|
463
|
+
renderedColor,
|
|
464
|
+
...null === tint ? {} : {
|
|
465
|
+
tint
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
function withXlsxCellStyleOrigin(cell, origin) {
|
|
470
|
+
return origin && xlsxCellStyleOriginHasValues(origin) ? {
|
|
471
|
+
...cell,
|
|
472
|
+
a3sXlsxStyleOrigin: origin
|
|
473
|
+
} : cell;
|
|
474
|
+
}
|
|
475
|
+
function xlsxCellStyleOrigin(cell) {
|
|
476
|
+
const candidate = cell?.a3sXlsxStyleOrigin;
|
|
477
|
+
if (!isRecord(candidate)) return;
|
|
478
|
+
const fontColor = normalizeXlsxSemanticColorOrigin(candidate.fontColor);
|
|
479
|
+
const fillColor = normalizeXlsxSemanticColorOrigin(candidate.fillColor);
|
|
480
|
+
const borderColors = normalizedBorderColors(candidate.borderColors);
|
|
481
|
+
const origin = {
|
|
482
|
+
...fontColor ? {
|
|
483
|
+
fontColor
|
|
484
|
+
} : {},
|
|
485
|
+
...fillColor ? {
|
|
486
|
+
fillColor
|
|
487
|
+
} : {},
|
|
488
|
+
...borderColors ? {
|
|
489
|
+
borderColors
|
|
490
|
+
} : {}
|
|
491
|
+
};
|
|
492
|
+
return xlsxCellStyleOriginHasValues(origin) ? origin : void 0;
|
|
493
|
+
}
|
|
494
|
+
function xlsxSemanticColorMatchesValue(origin, value) {
|
|
495
|
+
return normalizedColor(value) === origin.renderedColor.toLowerCase();
|
|
496
|
+
}
|
|
497
|
+
function xlsxColorElementMatchesOrigin(element, origin) {
|
|
498
|
+
if (!element || attribute(element, 'rgb')) return false;
|
|
499
|
+
if ('theme' === origin.kind) {
|
|
500
|
+
if (attribute(element, 'theme') !== String(origin.index)) return false;
|
|
501
|
+
} else if ('indexed' === origin.kind) {
|
|
502
|
+
if (attribute(element, 'indexed') !== String(origin.index)) return false;
|
|
503
|
+
} else if (!xlsxBooleanAttribute(element, 'auto')) return false;
|
|
504
|
+
const tint = boundedTint(attribute(element, 'tint'));
|
|
505
|
+
return tint === (origin.tint ?? null);
|
|
506
|
+
}
|
|
507
|
+
function applyXlsxSemanticColorOrigin(element, origin) {
|
|
508
|
+
for (const name of [
|
|
509
|
+
'rgb',
|
|
510
|
+
'theme',
|
|
511
|
+
'indexed',
|
|
512
|
+
'auto',
|
|
513
|
+
'tint'
|
|
514
|
+
])element.removeAttribute(name);
|
|
515
|
+
if ('theme' === origin.kind) element.setAttribute('theme', String(origin.index));
|
|
516
|
+
else if ('indexed' === origin.kind) element.setAttribute('indexed', String(origin.index));
|
|
517
|
+
else element.setAttribute('auto', '1');
|
|
518
|
+
if (void 0 !== origin.tint) element.setAttribute('tint', String(origin.tint));
|
|
519
|
+
}
|
|
520
|
+
function xlsxSemanticColorOriginKey(origin) {
|
|
521
|
+
return origin ? `${origin.kind}:${'index' in origin ? origin.index : ''}:${origin.baseColor}:${origin.renderedColor}:${origin.tint ?? ''}` : '';
|
|
522
|
+
}
|
|
523
|
+
function xlsxSemanticColorOriginSupported(origin, palette) {
|
|
524
|
+
if ('automatic' === origin.kind) return true;
|
|
525
|
+
return palette?.[origin.kind].get(origin.index)?.toLowerCase() === origin.baseColor.toLowerCase();
|
|
526
|
+
}
|
|
527
|
+
function prepareXlsxSemanticPalette(styles, theme, colors) {
|
|
528
|
+
const candidates = semanticPaletteCandidates(colors);
|
|
529
|
+
const supportedTheme = new Map();
|
|
530
|
+
let themeChanged = false;
|
|
531
|
+
const scheme = theme ? firstDescendant(theme, 'clrScheme') : void 0;
|
|
532
|
+
for (const [index, color] of candidates.theme){
|
|
533
|
+
const name = THEME_COLOR_NAMES[index];
|
|
534
|
+
const entry = name && scheme ? directChild(scheme, name) : void 0;
|
|
535
|
+
if (entry) {
|
|
536
|
+
themeChanged = writeThemeColor(entry, color) || themeChanged;
|
|
537
|
+
supportedTheme.set(index, color);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
const supportedIndexed = new Map();
|
|
541
|
+
let stylesChanged = false;
|
|
542
|
+
if (candidates.indexed.size) {
|
|
543
|
+
const colors = ensureXlsxStyleCollection(styles, 'colors', [
|
|
544
|
+
'extLst'
|
|
545
|
+
]);
|
|
546
|
+
let indexedColors = directChild(colors, 'indexedColors');
|
|
547
|
+
if (!indexedColors) {
|
|
548
|
+
indexedColors = styles.createElementNS(styles.documentElement.namespaceURI, 'indexedColors');
|
|
549
|
+
colors.prepend(indexedColors);
|
|
550
|
+
stylesChanged = true;
|
|
551
|
+
}
|
|
552
|
+
const resolver = createXlsxColorResolver(styles, theme);
|
|
553
|
+
const highestIndex = Math.max(...candidates.indexed.keys());
|
|
554
|
+
while(directChildren(indexedColors, 'rgbColor').length <= highestIndex){
|
|
555
|
+
const index = directChildren(indexedColors, 'rgbColor').length;
|
|
556
|
+
const element = styles.createElementNS(styles.documentElement.namespaceURI, 'rgbColor');
|
|
557
|
+
element.setAttribute('rgb', `FF${(resolver.indexed[index] ?? '000000').toUpperCase()}`);
|
|
558
|
+
indexedColors.append(element);
|
|
559
|
+
stylesChanged = true;
|
|
560
|
+
}
|
|
561
|
+
const entries = directChildren(indexedColors, 'rgbColor');
|
|
562
|
+
for (const [index, color] of candidates.indexed){
|
|
563
|
+
const expected = `FF${color.slice(1).toUpperCase()}`;
|
|
564
|
+
const entry = entries[index];
|
|
565
|
+
if (entry) {
|
|
566
|
+
if (attribute(entry, 'rgb')?.toUpperCase() !== expected) {
|
|
567
|
+
entry.setAttribute('rgb', expected);
|
|
568
|
+
stylesChanged = true;
|
|
569
|
+
}
|
|
570
|
+
supportedIndexed.set(index, color);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
return {
|
|
575
|
+
palette: {
|
|
576
|
+
indexed: supportedIndexed,
|
|
577
|
+
theme: supportedTheme
|
|
578
|
+
},
|
|
579
|
+
stylesChanged,
|
|
580
|
+
themeChanged
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
function semanticPaletteCandidates(colors) {
|
|
584
|
+
const theme = new Map();
|
|
585
|
+
const indexed = new Map();
|
|
586
|
+
const themeConflicts = new Set();
|
|
587
|
+
const indexedConflicts = new Set();
|
|
588
|
+
for (const color of colors){
|
|
589
|
+
if ('automatic' === color.kind) continue;
|
|
590
|
+
const target = 'theme' === color.kind ? theme : indexed;
|
|
591
|
+
const conflicts = 'theme' === color.kind ? themeConflicts : indexedConflicts;
|
|
592
|
+
const current = target.get(color.index);
|
|
593
|
+
if (current && current.toLowerCase() !== color.baseColor.toLowerCase()) conflicts.add(color.index);
|
|
594
|
+
else if (!current) target.set(color.index, color.baseColor);
|
|
595
|
+
}
|
|
596
|
+
for (const index of themeConflicts)theme.delete(index);
|
|
597
|
+
for (const index of indexedConflicts)indexed.delete(index);
|
|
598
|
+
return {
|
|
599
|
+
indexed,
|
|
600
|
+
theme
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
function xlsxCellStyleOriginSemanticColors(origin) {
|
|
604
|
+
return [
|
|
605
|
+
origin.fontColor,
|
|
606
|
+
origin.fillColor,
|
|
607
|
+
...Object.values(origin.borderColors ?? {})
|
|
608
|
+
].filter((value)=>Boolean(value));
|
|
609
|
+
}
|
|
610
|
+
function writeThemeColor(entry, color) {
|
|
611
|
+
const current = directChildren(entry)[0];
|
|
612
|
+
if (current?.localName === 'srgbClr' && attribute(current, 'val')?.toLowerCase() === color.slice(1).toLowerCase()) return false;
|
|
613
|
+
for (const child of directChildren(entry))child.remove();
|
|
614
|
+
const qualifiedName = entry.prefix ? `${entry.prefix}:srgbClr` : 'srgbClr';
|
|
615
|
+
const replacement = entry.ownerDocument.createElementNS(entry.namespaceURI, qualifiedName);
|
|
616
|
+
replacement.setAttribute('val', color.slice(1).toUpperCase());
|
|
617
|
+
entry.append(replacement);
|
|
618
|
+
return true;
|
|
619
|
+
}
|
|
620
|
+
function normalizedBorderColors(value) {
|
|
621
|
+
if (!isRecord(value)) return;
|
|
622
|
+
const result = {};
|
|
623
|
+
for (const side of [
|
|
624
|
+
'bottom',
|
|
625
|
+
'diagonal',
|
|
626
|
+
'left',
|
|
627
|
+
'right',
|
|
628
|
+
'top'
|
|
629
|
+
]){
|
|
630
|
+
const color = normalizeXlsxSemanticColorOrigin(value[side]);
|
|
631
|
+
if (color) result[side] = color;
|
|
632
|
+
}
|
|
633
|
+
return Object.keys(result).length ? result : void 0;
|
|
634
|
+
}
|
|
635
|
+
function normalizeXlsxSemanticColorOrigin(value) {
|
|
636
|
+
if (!isRecord(value)) return;
|
|
637
|
+
const baseColor = normalizedColor(value.baseColor);
|
|
638
|
+
const renderedColor = normalizedColor(value.renderedColor);
|
|
639
|
+
const tint = normalizedTint(value.tint);
|
|
640
|
+
if (!baseColor || !renderedColor || void 0 === tint) return;
|
|
641
|
+
if ('automatic' === value.kind) return {
|
|
642
|
+
kind: 'automatic',
|
|
643
|
+
baseColor,
|
|
644
|
+
renderedColor,
|
|
645
|
+
...null === tint ? {} : {
|
|
646
|
+
tint
|
|
647
|
+
}
|
|
648
|
+
};
|
|
649
|
+
const maximum = 'theme' === value.kind ? THEME_COLOR_NAMES.length - 1 : MAX_INDEXED_COLOR;
|
|
650
|
+
const index = boundedNumber(value.index, maximum);
|
|
651
|
+
if ('theme' !== value.kind && 'indexed' !== value.kind || null === index) return;
|
|
652
|
+
return {
|
|
653
|
+
kind: value.kind,
|
|
654
|
+
baseColor,
|
|
655
|
+
index,
|
|
656
|
+
renderedColor,
|
|
657
|
+
...null === tint ? {} : {
|
|
658
|
+
tint
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
function xlsxCellStyleOriginHasValues(origin) {
|
|
663
|
+
return Boolean(origin.fontColor || origin.fillColor || Object.keys(origin.borderColors ?? {}).length);
|
|
664
|
+
}
|
|
665
|
+
function normalizedColor(value) {
|
|
666
|
+
const rgb = xlsxRgbColor(value);
|
|
667
|
+
return rgb ? `#${rgb.slice(-6).toLowerCase()}` : null;
|
|
668
|
+
}
|
|
669
|
+
function normalizedTint(value) {
|
|
670
|
+
if (void 0 === value) return null;
|
|
671
|
+
return 'number' == typeof value && Number.isFinite(value) && value >= -1 && value <= 1 ? value : void 0;
|
|
672
|
+
}
|
|
673
|
+
function boundedTint(value) {
|
|
674
|
+
if (null === value) return null;
|
|
675
|
+
const tint = Number(value);
|
|
676
|
+
return Number.isFinite(tint) && tint >= -1 && tint <= 1 ? tint : null;
|
|
677
|
+
}
|
|
678
|
+
function work_xlsx_cell_style_origin_boundedInteger(value, maximum) {
|
|
679
|
+
if (null === value || !/^\d+$/.test(value)) return null;
|
|
680
|
+
return boundedNumber(Number(value), maximum);
|
|
681
|
+
}
|
|
682
|
+
function boundedNumber(value, maximum) {
|
|
683
|
+
return 'number' == typeof value && Number.isSafeInteger(value) && value >= 0 && value <= maximum ? value : null;
|
|
684
|
+
}
|
|
685
|
+
function xlsxBooleanAttribute(element, name) {
|
|
686
|
+
const value = attribute(element, name)?.trim().toLowerCase();
|
|
687
|
+
return '1' === value || 'true' === value || 'on' === value;
|
|
688
|
+
}
|
|
689
|
+
function isRecord(value) {
|
|
690
|
+
return 'object' == typeof value && null !== value && !Array.isArray(value);
|
|
691
|
+
}
|
|
692
|
+
const XLSX_GRADIENT_FILL_CELL_KEY = 'a3sXlsxGradientFill';
|
|
693
|
+
const MAX_XLSX_GRADIENT_STOPS = 256;
|
|
694
|
+
function readXlsxGradientFill(element, colors) {
|
|
695
|
+
if (!element) return;
|
|
696
|
+
const type = attribute(element, 'type') ?? 'linear';
|
|
697
|
+
if ('linear' !== type && 'path' !== type) return;
|
|
698
|
+
const children = directChildren(element);
|
|
699
|
+
if (children.length < 2 || children.length > MAX_XLSX_GRADIENT_STOPS || children.some((child)=>'stop' !== child.localName)) return;
|
|
700
|
+
const stops = [];
|
|
701
|
+
for (const stop of children){
|
|
702
|
+
const position = unitInterval(attribute(stop, 'position'));
|
|
703
|
+
const stopChildren = directChildren(stop);
|
|
704
|
+
const colorElement = stopChildren[0];
|
|
705
|
+
if (null === position || 1 !== stopChildren.length || colorElement?.localName !== 'color') return;
|
|
706
|
+
const renderedColor = resolveXlsxColor(colorElement, colors);
|
|
707
|
+
const color = work_xlsx_gradient_fill_normalizedColor(renderedColor);
|
|
708
|
+
if (!color || (stops.at(-1)?.position ?? 0) > position) return;
|
|
709
|
+
const colorOrigin = readXlsxSemanticColorOrigin(colorElement, colors);
|
|
710
|
+
stops.push({
|
|
711
|
+
color,
|
|
712
|
+
...colorOrigin ? {
|
|
713
|
+
colorOrigin
|
|
714
|
+
} : {},
|
|
715
|
+
position
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
if ('linear' === type) {
|
|
719
|
+
const degree = optionalFiniteNumber(attribute(element, 'degree'), 0);
|
|
720
|
+
return null === degree ? void 0 : {
|
|
721
|
+
degree,
|
|
722
|
+
stops,
|
|
723
|
+
type
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
const left = optionalUnitInterval(attribute(element, 'left'), 0);
|
|
727
|
+
const right = optionalUnitInterval(attribute(element, 'right'), 0);
|
|
728
|
+
const top = optionalUnitInterval(attribute(element, 'top'), 0);
|
|
729
|
+
const bottom = optionalUnitInterval(attribute(element, 'bottom'), 0);
|
|
730
|
+
if (null === left || null === right || null === top || null === bottom || left > right || top > bottom) return;
|
|
731
|
+
return {
|
|
732
|
+
bottom,
|
|
733
|
+
left,
|
|
734
|
+
right,
|
|
735
|
+
stops,
|
|
736
|
+
top,
|
|
737
|
+
type
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
function withXlsxGradientFill(cell, fill) {
|
|
741
|
+
const normalized = normalizeXlsxGradientFill(fill);
|
|
742
|
+
return normalized ? {
|
|
743
|
+
...cell,
|
|
744
|
+
[XLSX_GRADIENT_FILL_CELL_KEY]: normalized
|
|
745
|
+
} : cell;
|
|
746
|
+
}
|
|
747
|
+
function deleteXlsxGradientFill(cell) {
|
|
748
|
+
delete cell[XLSX_GRADIENT_FILL_CELL_KEY];
|
|
749
|
+
}
|
|
750
|
+
function xlsxGradientFill(cell) {
|
|
751
|
+
return normalizeXlsxGradientFill(cell?.[XLSX_GRADIENT_FILL_CELL_KEY]);
|
|
752
|
+
}
|
|
753
|
+
function activeXlsxGradientFill(cell) {
|
|
754
|
+
const fill = xlsxGradientFill(cell);
|
|
755
|
+
return fill && work_xlsx_gradient_fill_normalizedColor(cell?.bg) === xlsxGradientFillFallbackColor(fill) ? fill : void 0;
|
|
756
|
+
}
|
|
757
|
+
function normalizeXlsxGradientFill(value) {
|
|
758
|
+
if (!work_xlsx_gradient_fill_isRecord(value) || !Array.isArray(value.stops)) return;
|
|
759
|
+
if (value.stops.length < 2 || value.stops.length > MAX_XLSX_GRADIENT_STOPS) return;
|
|
760
|
+
const stops = [];
|
|
761
|
+
for (const valueStop of value.stops){
|
|
762
|
+
if (!work_xlsx_gradient_fill_isRecord(valueStop)) return;
|
|
763
|
+
const position = normalizedUnitInterval(valueStop.position);
|
|
764
|
+
const color = work_xlsx_gradient_fill_normalizedColor(valueStop.color);
|
|
765
|
+
if (null === position || !color || (stops.at(-1)?.position ?? 0) > position) return;
|
|
766
|
+
const colorOrigin = normalizeXlsxSemanticColorOrigin(valueStop.colorOrigin);
|
|
767
|
+
stops.push({
|
|
768
|
+
color,
|
|
769
|
+
...colorOrigin ? {
|
|
770
|
+
colorOrigin
|
|
771
|
+
} : {},
|
|
772
|
+
position
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
if ('linear' === value.type) {
|
|
776
|
+
const degree = finiteNumber(value.degree);
|
|
777
|
+
return null === degree ? void 0 : {
|
|
778
|
+
degree,
|
|
779
|
+
stops,
|
|
780
|
+
type: 'linear'
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
if ('path' !== value.type) return;
|
|
784
|
+
const left = normalizedUnitInterval(value.left);
|
|
785
|
+
const right = normalizedUnitInterval(value.right);
|
|
786
|
+
const top = normalizedUnitInterval(value.top);
|
|
787
|
+
const bottom = normalizedUnitInterval(value.bottom);
|
|
788
|
+
if (null === left || null === right || null === top || null === bottom || left > right || top > bottom) return;
|
|
789
|
+
return {
|
|
790
|
+
bottom,
|
|
791
|
+
left,
|
|
792
|
+
right,
|
|
793
|
+
stops,
|
|
794
|
+
top,
|
|
795
|
+
type: 'path'
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
function xlsxGradientFillFallbackColor(fill) {
|
|
799
|
+
return fill.stops[0]?.color ?? '#ffffff';
|
|
800
|
+
}
|
|
801
|
+
function xlsxGradientFillSemanticColors(fill) {
|
|
802
|
+
return (fill?.stops ?? []).flatMap((stop)=>stop.colorOrigin ? [
|
|
803
|
+
stop.colorOrigin
|
|
804
|
+
] : []);
|
|
805
|
+
}
|
|
806
|
+
function xlsxGradientFillKey(fill) {
|
|
807
|
+
if (!fill) return '';
|
|
808
|
+
const geometry = 'linear' === fill.type ? `linear:${fill.degree}` : `path:${fill.left}:${fill.right}:${fill.top}:${fill.bottom}`;
|
|
809
|
+
return `${geometry}:${fill.stops.map((stop)=>`${stop.position}:${stop.color}:${xlsxSemanticColorOriginKey(stop.colorOrigin)}`).join('|')}`;
|
|
810
|
+
}
|
|
811
|
+
function unitInterval(value) {
|
|
812
|
+
if (null === value || !value.trim()) return null;
|
|
813
|
+
return normalizedUnitInterval(Number(value));
|
|
814
|
+
}
|
|
815
|
+
function optionalUnitInterval(value, fallback) {
|
|
816
|
+
return null === value ? fallback : unitInterval(value);
|
|
817
|
+
}
|
|
818
|
+
function normalizedUnitInterval(value) {
|
|
819
|
+
return 'number' == typeof value && Number.isFinite(value) && value >= 0 && value <= 1 ? value : null;
|
|
820
|
+
}
|
|
821
|
+
function optionalFiniteNumber(value, fallback) {
|
|
822
|
+
if (null === value) return fallback;
|
|
823
|
+
if (!value.trim()) return null;
|
|
824
|
+
return finiteNumber(Number(value));
|
|
825
|
+
}
|
|
826
|
+
function finiteNumber(value) {
|
|
827
|
+
return 'number' == typeof value && Number.isFinite(value) ? value : null;
|
|
828
|
+
}
|
|
829
|
+
function work_xlsx_gradient_fill_normalizedColor(value) {
|
|
830
|
+
const rgb = xlsxRgbColor(value);
|
|
831
|
+
return rgb ? `#${rgb.slice(-6).toLowerCase()}` : null;
|
|
832
|
+
}
|
|
833
|
+
function work_xlsx_gradient_fill_isRecord(value) {
|
|
834
|
+
return 'object' == typeof value && null !== value && !Array.isArray(value);
|
|
835
|
+
}
|
|
836
|
+
const XLSX_PATTERN_FILL_CELL_KEY = 'a3sXlsxPatternFill';
|
|
837
|
+
const xlsxPatternFillTypes = [
|
|
838
|
+
'darkDown',
|
|
839
|
+
'darkGray',
|
|
840
|
+
'darkGrid',
|
|
841
|
+
'darkHorizontal',
|
|
842
|
+
'darkTrellis',
|
|
843
|
+
'darkUp',
|
|
844
|
+
'darkVertical',
|
|
845
|
+
'gray0625',
|
|
846
|
+
'gray125',
|
|
847
|
+
'lightDown',
|
|
848
|
+
'lightGray',
|
|
849
|
+
'lightGrid',
|
|
850
|
+
'lightHorizontal',
|
|
851
|
+
'lightTrellis',
|
|
852
|
+
'lightUp',
|
|
853
|
+
'lightVertical',
|
|
854
|
+
'mediumGray'
|
|
855
|
+
];
|
|
856
|
+
const xlsxPatternFillTypeSet = new Set(xlsxPatternFillTypes);
|
|
857
|
+
function readXlsxPatternFill(pattern, colors) {
|
|
858
|
+
if (!pattern) return;
|
|
859
|
+
const patternType = attribute(pattern, 'patternType');
|
|
860
|
+
if (!patternType || !isXlsxPatternFillType(patternType)) return;
|
|
861
|
+
const foreground = directChild(pattern, 'fgColor');
|
|
862
|
+
const background = directChild(pattern, 'bgColor');
|
|
863
|
+
const foregroundColor = foreground ? resolveXlsxColor(foreground, colors) : '#000000';
|
|
864
|
+
const backgroundColor = background ? resolveXlsxColor(background, colors) : '#ffffff';
|
|
865
|
+
const normalizedForegroundColor = work_xlsx_pattern_fill_normalizedColor(foregroundColor);
|
|
866
|
+
const normalizedBackgroundColor = work_xlsx_pattern_fill_normalizedColor(backgroundColor);
|
|
867
|
+
if (!normalizedForegroundColor || !normalizedBackgroundColor) return;
|
|
868
|
+
const foregroundColorOrigin = readXlsxSemanticColorOrigin(foreground, colors);
|
|
869
|
+
const backgroundColorOrigin = readXlsxSemanticColorOrigin(background, colors);
|
|
870
|
+
return {
|
|
871
|
+
backgroundColor: normalizedBackgroundColor,
|
|
872
|
+
...backgroundColorOrigin ? {
|
|
873
|
+
backgroundColorOrigin
|
|
874
|
+
} : {},
|
|
875
|
+
foregroundColor: normalizedForegroundColor,
|
|
876
|
+
...foregroundColorOrigin ? {
|
|
877
|
+
foregroundColorOrigin
|
|
878
|
+
} : {},
|
|
879
|
+
patternType
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
function withXlsxPatternFill(cell, fill) {
|
|
883
|
+
const normalized = normalizeXlsxPatternFill(fill);
|
|
884
|
+
return normalized ? {
|
|
885
|
+
...cell,
|
|
886
|
+
[XLSX_PATTERN_FILL_CELL_KEY]: normalized
|
|
887
|
+
} : cell;
|
|
888
|
+
}
|
|
889
|
+
function deleteXlsxPatternFill(cell) {
|
|
890
|
+
delete cell[XLSX_PATTERN_FILL_CELL_KEY];
|
|
891
|
+
}
|
|
892
|
+
function xlsxPatternFill(cell) {
|
|
893
|
+
return normalizeXlsxPatternFill(cell?.[XLSX_PATTERN_FILL_CELL_KEY]);
|
|
894
|
+
}
|
|
895
|
+
function activeXlsxPatternFill(cell) {
|
|
896
|
+
const fill = xlsxPatternFill(cell);
|
|
897
|
+
return fill && work_xlsx_pattern_fill_normalizedColor(cell?.bg) === fill.backgroundColor ? fill : void 0;
|
|
898
|
+
}
|
|
899
|
+
function normalizeXlsxPatternFill(value) {
|
|
900
|
+
if (!work_xlsx_pattern_fill_isRecord(value) || !isXlsxPatternFillType(value.patternType)) return;
|
|
901
|
+
const foregroundColor = work_xlsx_pattern_fill_normalizedColor(value.foregroundColor);
|
|
902
|
+
const backgroundColor = work_xlsx_pattern_fill_normalizedColor(value.backgroundColor);
|
|
903
|
+
if (!foregroundColor || !backgroundColor) return;
|
|
904
|
+
const foregroundColorOrigin = normalizeXlsxSemanticColorOrigin(value.foregroundColorOrigin);
|
|
905
|
+
const backgroundColorOrigin = normalizeXlsxSemanticColorOrigin(value.backgroundColorOrigin);
|
|
906
|
+
return {
|
|
907
|
+
backgroundColor,
|
|
908
|
+
...backgroundColorOrigin ? {
|
|
909
|
+
backgroundColorOrigin
|
|
910
|
+
} : {},
|
|
911
|
+
foregroundColor,
|
|
912
|
+
...foregroundColorOrigin ? {
|
|
913
|
+
foregroundColorOrigin
|
|
914
|
+
} : {},
|
|
915
|
+
patternType: value.patternType
|
|
916
|
+
};
|
|
917
|
+
}
|
|
918
|
+
function xlsxPatternFillSemanticColors(fill) {
|
|
919
|
+
return fill ? [
|
|
920
|
+
fill.foregroundColorOrigin,
|
|
921
|
+
fill.backgroundColorOrigin
|
|
922
|
+
].filter((value)=>Boolean(value)) : [];
|
|
923
|
+
}
|
|
924
|
+
function xlsxPatternFillKey(fill) {
|
|
925
|
+
return fill ? [
|
|
926
|
+
fill.patternType,
|
|
927
|
+
fill.foregroundColor,
|
|
928
|
+
xlsxSemanticColorOriginKey(fill.foregroundColorOrigin),
|
|
929
|
+
fill.backgroundColor,
|
|
930
|
+
xlsxSemanticColorOriginKey(fill.backgroundColorOrigin)
|
|
931
|
+
].join(':') : '';
|
|
932
|
+
}
|
|
933
|
+
function isXlsxPatternFillType(value) {
|
|
934
|
+
return 'string' == typeof value && xlsxPatternFillTypeSet.has(value);
|
|
935
|
+
}
|
|
936
|
+
function work_xlsx_pattern_fill_normalizedColor(value) {
|
|
937
|
+
const rgb = xlsxRgbColor(value);
|
|
938
|
+
return rgb ? `#${rgb.slice(-6).toLowerCase()}` : null;
|
|
939
|
+
}
|
|
940
|
+
function work_xlsx_pattern_fill_isRecord(value) {
|
|
941
|
+
return 'object' == typeof value && null !== value && !Array.isArray(value);
|
|
942
|
+
}
|
|
943
|
+
const SPREADSHEET_SHOWN_COMMENT_CELLS_PROPERTY = '__a3sShownCommentCells';
|
|
944
|
+
const spreadsheetMatrixProfiles = new WeakMap();
|
|
945
|
+
function freezeImportedSpreadsheetCell(cell) {
|
|
946
|
+
const gradientFill = cell[XLSX_GRADIENT_FILL_CELL_KEY];
|
|
947
|
+
if (gradientFill && 'object' == typeof gradientFill) {
|
|
948
|
+
const stops = gradientFill.stops;
|
|
949
|
+
if (Array.isArray(stops)) {
|
|
950
|
+
for (const stop of stops)if (stop && 'object' == typeof stop) {
|
|
951
|
+
freezeObject(stop.colorOrigin);
|
|
952
|
+
freezeObject(stop);
|
|
953
|
+
}
|
|
954
|
+
Object.freeze(stops);
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
freezeObject(gradientFill);
|
|
958
|
+
const patternFill = cell[XLSX_PATTERN_FILL_CELL_KEY];
|
|
959
|
+
if (patternFill && 'object' == typeof patternFill) {
|
|
960
|
+
const record = patternFill;
|
|
961
|
+
freezeObject(record.foregroundColorOrigin);
|
|
962
|
+
freezeObject(record.backgroundColorOrigin);
|
|
963
|
+
}
|
|
964
|
+
freezeObject(patternFill);
|
|
965
|
+
freezeObject(cell.mc);
|
|
966
|
+
freezeObject(cell.ct?.s);
|
|
967
|
+
freezeObject(cell.ct);
|
|
968
|
+
freezeObject(cell.ps);
|
|
969
|
+
freezeObject(cell.hl);
|
|
970
|
+
freezeObject(cell.spl);
|
|
971
|
+
return Object.freeze(cell);
|
|
972
|
+
}
|
|
973
|
+
function registerImportedSpreadsheetMatrix(data, options) {
|
|
974
|
+
data.length = Math.max(data.length, options.rowCount);
|
|
975
|
+
data[0] ??= [];
|
|
976
|
+
for (const rowIndex of sparseArrayIndexes(data)){
|
|
977
|
+
const row = data[rowIndex];
|
|
978
|
+
if (row) {
|
|
979
|
+
row.length = Math.max(row.length, options.columnCount);
|
|
980
|
+
Object.freeze(row);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
registerSpreadsheetMatrixProfile(data, options);
|
|
984
|
+
}
|
|
985
|
+
function registerDerivedSpreadsheetMatrix(data, source, changes) {
|
|
986
|
+
const sourceProfile = spreadsheetMatrixProfiles.get(source);
|
|
987
|
+
if (!sourceProfile?.fortuneReady) return false;
|
|
988
|
+
const formulaCells = new Map(sourceProfile.formulaCells.map(({ column, row })=>[
|
|
989
|
+
spreadsheetCoordinateKey(row, column),
|
|
990
|
+
{
|
|
991
|
+
column,
|
|
992
|
+
row
|
|
993
|
+
}
|
|
994
|
+
]));
|
|
995
|
+
const shownCommentCells = new Map(sourceProfile.shownCommentCells.map(({ c, r })=>[
|
|
996
|
+
spreadsheetCoordinateKey(r, c),
|
|
997
|
+
{
|
|
998
|
+
c,
|
|
999
|
+
r
|
|
1000
|
+
}
|
|
1001
|
+
]));
|
|
1002
|
+
let populatedCellCount = sourceProfile.populatedCellCount;
|
|
1003
|
+
let protectionCellKey = sourceProfile.protectionCellKey;
|
|
1004
|
+
let protectionCells;
|
|
1005
|
+
for (const { column, current, previous, row } of changes){
|
|
1006
|
+
const coordinateKey = spreadsheetCoordinateKey(row, column);
|
|
1007
|
+
if (null == previous && null != current) populatedCellCount += 1;
|
|
1008
|
+
if (null != previous && null == current) populatedCellCount -= 1;
|
|
1009
|
+
if (current?.f) formulaCells.set(coordinateKey, {
|
|
1010
|
+
column,
|
|
1011
|
+
row
|
|
1012
|
+
});
|
|
1013
|
+
else formulaCells.delete(coordinateKey);
|
|
1014
|
+
if (current?.ps?.isShow) shownCommentCells.set(coordinateKey, {
|
|
1015
|
+
c: column,
|
|
1016
|
+
r: row
|
|
1017
|
+
});
|
|
1018
|
+
else shownCommentCells.delete(coordinateKey);
|
|
1019
|
+
if (spreadsheetProtectionSignature(previous) !== spreadsheetProtectionSignature(current)) {
|
|
1020
|
+
protectionCells ??= spreadsheetProtectionCells(protectionCellKey);
|
|
1021
|
+
const signature = spreadsheetProtectionSignature(current);
|
|
1022
|
+
if (null === signature) protectionCells.delete(coordinateKey);
|
|
1023
|
+
else protectionCells.set(coordinateKey, signature);
|
|
1024
|
+
}
|
|
1025
|
+
const changedRow = data[row];
|
|
1026
|
+
if (changedRow && !Object.isFrozen(changedRow)) Object.freeze(changedRow);
|
|
1027
|
+
}
|
|
1028
|
+
if (protectionCells) protectionCellKey = Array.from(protectionCells, ([coordinate, value])=>({
|
|
1029
|
+
coordinate,
|
|
1030
|
+
value
|
|
1031
|
+
})).sort((left, right)=>compareSpreadsheetCoordinates(left.coordinate, right.coordinate)).map(({ coordinate, value })=>`${coordinate}:${value}`).join(',');
|
|
1032
|
+
registerSpreadsheetMatrixProfile(data, {
|
|
1033
|
+
columnCount: Math.max(sourceProfile.columnCount, ...changes.map(({ column, row })=>Math.max(column + 1, data[row]?.length ?? 0))),
|
|
1034
|
+
formulaCells: Array.from(formulaCells.values()).sort(compareSpreadsheetCells),
|
|
1035
|
+
fortuneReady: true,
|
|
1036
|
+
populatedCellCount: Math.max(0, populatedCellCount),
|
|
1037
|
+
protectionCellKey,
|
|
1038
|
+
rowCount: Math.max(sourceProfile.rowCount, data.length, ...changes.map(({ row })=>row + 1)),
|
|
1039
|
+
shownCommentCells: Array.from(shownCommentCells.values()).sort((left, right)=>left.r - right.r || left.c - right.c)
|
|
1040
|
+
}, {
|
|
1041
|
+
historyRoot: sourceProfile.historyRoot,
|
|
1042
|
+
historyState: changes.some(({ current, previous })=>!sameSpreadsheetHistoryValue(current, previous)) ? Object.freeze({}) : sourceProfile.historyState
|
|
1043
|
+
});
|
|
1044
|
+
return true;
|
|
1045
|
+
}
|
|
1046
|
+
function spreadsheetMatrixProfile(data) {
|
|
1047
|
+
return data ? spreadsheetMatrixProfiles.get(data) : void 0;
|
|
1048
|
+
}
|
|
1049
|
+
function attachSpreadsheetShownCommentCells(data, cells) {
|
|
1050
|
+
Object.defineProperty(data, SPREADSHEET_SHOWN_COMMENT_CELLS_PROPERTY, {
|
|
1051
|
+
configurable: false,
|
|
1052
|
+
enumerable: false,
|
|
1053
|
+
value: cells,
|
|
1054
|
+
writable: false
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
function registerSpreadsheetMatrixProfile(data, options, history) {
|
|
1058
|
+
const initialHistoryState = Object.freeze({});
|
|
1059
|
+
const profile = Object.freeze({
|
|
1060
|
+
columnCount: options.columnCount,
|
|
1061
|
+
formulaCells: Object.freeze(options.formulaCells.map((cell)=>Object.freeze({
|
|
1062
|
+
...cell
|
|
1063
|
+
}))),
|
|
1064
|
+
fortuneReady: options.fortuneReady,
|
|
1065
|
+
historyRoot: history?.historyRoot ?? initialHistoryState,
|
|
1066
|
+
historyState: history?.historyState ?? initialHistoryState,
|
|
1067
|
+
populatedCellCount: options.populatedCellCount,
|
|
1068
|
+
protectionCellKey: options.protectionCellKey,
|
|
1069
|
+
rowCount: options.rowCount,
|
|
1070
|
+
shownCommentCells: Object.freeze(options.shownCommentCells.map((cell)=>Object.freeze({
|
|
1071
|
+
...cell
|
|
1072
|
+
})))
|
|
1073
|
+
});
|
|
1074
|
+
attachSpreadsheetShownCommentCells(data, profile.shownCommentCells);
|
|
1075
|
+
Object.freeze(data);
|
|
1076
|
+
spreadsheetMatrixProfiles.set(data, profile);
|
|
1077
|
+
}
|
|
1078
|
+
function spreadsheetProtectionCells(value) {
|
|
1079
|
+
const cells = new Map();
|
|
1080
|
+
for (const entry of value.split(',')){
|
|
1081
|
+
if (!entry) continue;
|
|
1082
|
+
const separator = entry.indexOf(':');
|
|
1083
|
+
if (!(separator <= 0)) cells.set(entry.slice(0, separator), entry.slice(separator + 1));
|
|
1084
|
+
}
|
|
1085
|
+
return cells;
|
|
1086
|
+
}
|
|
1087
|
+
function spreadsheetProtectionSignature(cell) {
|
|
1088
|
+
const hidden = cell?.hi;
|
|
1089
|
+
if (cell?.lo === void 0 && void 0 === hidden) return null;
|
|
1090
|
+
return `${cell?.lo ?? ''}:${hidden ?? ''}`;
|
|
1091
|
+
}
|
|
1092
|
+
function spreadsheetCoordinateKey(row, column) {
|
|
1093
|
+
return `${row}_${column}`;
|
|
1094
|
+
}
|
|
1095
|
+
function compareSpreadsheetCoordinates(left, right) {
|
|
1096
|
+
const [leftRow = 0, leftColumn = 0] = left.split('_').map(Number);
|
|
1097
|
+
const [rightRow = 0, rightColumn = 0] = right.split('_').map(Number);
|
|
1098
|
+
return leftRow - rightRow || leftColumn - rightColumn;
|
|
1099
|
+
}
|
|
1100
|
+
function compareSpreadsheetCells(left, right) {
|
|
1101
|
+
return left.row - right.row || left.column - right.column;
|
|
1102
|
+
}
|
|
1103
|
+
function freezeObject(value) {
|
|
1104
|
+
if (value && 'object' == typeof value) Object.freeze(value);
|
|
1105
|
+
}
|
|
1106
|
+
const DEFAULT_PROTECTION_HINT = '此工作表已受保护。若要更改锁定的单元格,请先取消工作表保护。';
|
|
1107
|
+
function defaultSheetProtectionAuthority(enabled = false) {
|
|
1108
|
+
return {
|
|
1109
|
+
sheet: enabled ? 1 : 0,
|
|
1110
|
+
selectLockedCells: 1,
|
|
1111
|
+
selectunLockedCells: 1,
|
|
1112
|
+
formatCells: 0,
|
|
1113
|
+
formatColumns: 0,
|
|
1114
|
+
formatRows: 0,
|
|
1115
|
+
insertColumns: 0,
|
|
1116
|
+
insertRows: 0,
|
|
1117
|
+
insertHyperlinks: 0,
|
|
1118
|
+
deleteColumns: 0,
|
|
1119
|
+
deleteRows: 0,
|
|
1120
|
+
sort: 0,
|
|
1121
|
+
filter: 0,
|
|
1122
|
+
usePivotTablereports: 0,
|
|
1123
|
+
editObjects: 0,
|
|
1124
|
+
editScenarios: 0,
|
|
1125
|
+
hintText: '',
|
|
1126
|
+
defaultSheetHintText: DEFAULT_PROTECTION_HINT,
|
|
1127
|
+
allowRangeList: [],
|
|
1128
|
+
cellProtectionRanges: []
|
|
1129
|
+
};
|
|
1130
|
+
}
|
|
1131
|
+
function sheetProtectionAuthority(sheet) {
|
|
1132
|
+
return normalizeSheetProtectionAuthority(sheet.config?.authority);
|
|
1133
|
+
}
|
|
1134
|
+
function normalizeSheetProtectionAuthority(source) {
|
|
1135
|
+
const defaults = defaultSheetProtectionAuthority();
|
|
1136
|
+
if (!source || 'object' != typeof source) return defaults;
|
|
1137
|
+
const authority = source;
|
|
1138
|
+
return {
|
|
1139
|
+
sheet: flag(authority.sheet, defaults.sheet),
|
|
1140
|
+
selectLockedCells: flag(authority.selectLockedCells, defaults.selectLockedCells),
|
|
1141
|
+
selectunLockedCells: flag(authority.selectunLockedCells, defaults.selectunLockedCells),
|
|
1142
|
+
formatCells: flag(authority.formatCells, defaults.formatCells),
|
|
1143
|
+
formatColumns: flag(authority.formatColumns, defaults.formatColumns),
|
|
1144
|
+
formatRows: flag(authority.formatRows, defaults.formatRows),
|
|
1145
|
+
insertColumns: flag(authority.insertColumns, defaults.insertColumns),
|
|
1146
|
+
insertRows: flag(authority.insertRows, defaults.insertRows),
|
|
1147
|
+
insertHyperlinks: flag(authority.insertHyperlinks, defaults.insertHyperlinks),
|
|
1148
|
+
deleteColumns: flag(authority.deleteColumns, defaults.deleteColumns),
|
|
1149
|
+
deleteRows: flag(authority.deleteRows, defaults.deleteRows),
|
|
1150
|
+
sort: flag(authority.sort, defaults.sort),
|
|
1151
|
+
filter: flag(authority.filter, defaults.filter),
|
|
1152
|
+
usePivotTablereports: flag(authority.usePivotTablereports, defaults.usePivotTablereports),
|
|
1153
|
+
editObjects: flag(authority.editObjects, defaults.editObjects),
|
|
1154
|
+
editScenarios: flag(authority.editScenarios, defaults.editScenarios),
|
|
1155
|
+
hintText: stringValue(authority.hintText),
|
|
1156
|
+
defaultSheetHintText: stringValue(authority.defaultSheetHintText) || DEFAULT_PROTECTION_HINT,
|
|
1157
|
+
allowRangeList: editableRangeList(authority.allowRangeList),
|
|
1158
|
+
cellProtectionRanges: cellProtectionRangeList(authority.cellProtectionRanges),
|
|
1159
|
+
xlsxAttributes: stringRecord(authority.xlsxAttributes)
|
|
1160
|
+
};
|
|
1161
|
+
}
|
|
1162
|
+
function importedSheetProtectionAuthority(authority, cellProtectionRanges) {
|
|
1163
|
+
if (!authority && !cellProtectionRanges.length) return;
|
|
1164
|
+
const normalized = normalizeSheetProtectionAuthority(authority);
|
|
1165
|
+
normalized.cellProtectionRanges = [
|
|
1166
|
+
...cellProtectionRanges,
|
|
1167
|
+
...normalized.allowRangeList.filter((range)=>!editableRangeRequiresCredentials(range)).flatMap((range)=>work_spreadsheet_ranges_parseSpreadsheetCellRanges(range.sqref) ?? []).map((range)=>({
|
|
1168
|
+
range,
|
|
1169
|
+
locked: false,
|
|
1170
|
+
hidden: false
|
|
1171
|
+
}))
|
|
1172
|
+
];
|
|
1173
|
+
return normalized;
|
|
1174
|
+
}
|
|
1175
|
+
function withSheetProtection(sheet, enabled) {
|
|
1176
|
+
const authority = sheetProtectionAuthority(sheet);
|
|
1177
|
+
authority.sheet = enabled ? 1 : 0;
|
|
1178
|
+
return withAuthority(sheet, authority);
|
|
1179
|
+
}
|
|
1180
|
+
function withSheetSelectionPermissions(sheet, permissions) {
|
|
1181
|
+
const authority = sheetProtectionAuthority(sheet);
|
|
1182
|
+
if (void 0 !== permissions.selectLockedCells) authority.selectLockedCells = permissions.selectLockedCells ? 1 : 0;
|
|
1183
|
+
if (void 0 !== permissions.selectUnlockedCells) authority.selectunLockedCells = permissions.selectUnlockedCells ? 1 : 0;
|
|
1184
|
+
return withAuthority(sheet, authority);
|
|
1185
|
+
}
|
|
1186
|
+
function withEditableRange(sheet, index, editableRange) {
|
|
1187
|
+
const authority = sheetProtectionAuthority(sheet);
|
|
1188
|
+
const nextRange = {
|
|
1189
|
+
name: editableRange.name.trim(),
|
|
1190
|
+
sqref: canonicalRangeReference(editableRange.sqref),
|
|
1191
|
+
hintText: editableRange.hintText?.trim() || void 0,
|
|
1192
|
+
xlsxAttributes: editableRange.xlsxAttributes
|
|
1193
|
+
};
|
|
1194
|
+
if (null !== index && authority.allowRangeList[index]) authority.allowRangeList[index] = nextRange;
|
|
1195
|
+
else authority.allowRangeList.push(nextRange);
|
|
1196
|
+
const ranges = work_spreadsheet_ranges_parseSpreadsheetCellRanges(nextRange.sqref) ?? [];
|
|
1197
|
+
const next = withCellProtection(sheet, ranges, false);
|
|
1198
|
+
const nextAuthority = sheetProtectionAuthority(next);
|
|
1199
|
+
nextAuthority.allowRangeList = authority.allowRangeList;
|
|
1200
|
+
return withAuthority(next, nextAuthority);
|
|
1201
|
+
}
|
|
1202
|
+
function withoutEditableRange(sheet, index) {
|
|
1203
|
+
const authority = sheetProtectionAuthority(sheet);
|
|
1204
|
+
const removed = authority.allowRangeList[index];
|
|
1205
|
+
if (!removed) return sheet;
|
|
1206
|
+
authority.allowRangeList.splice(index, 1);
|
|
1207
|
+
const removedRanges = work_spreadsheet_ranges_parseSpreadsheetCellRanges(removed.sqref) ?? [];
|
|
1208
|
+
let next = withCellProtection(sheet, removedRanges, true);
|
|
1209
|
+
for (const editableRange of authority.allowRangeList)if (!editableRangeRequiresCredentials(editableRange)) next = withCellProtection(next, work_spreadsheet_ranges_parseSpreadsheetCellRanges(editableRange.sqref) ?? [], false);
|
|
1210
|
+
const nextAuthority = sheetProtectionAuthority(next);
|
|
1211
|
+
nextAuthority.allowRangeList = authority.allowRangeList;
|
|
1212
|
+
return withAuthority(next, nextAuthority);
|
|
1213
|
+
}
|
|
1214
|
+
function withCellProtection(sheet, ranges, locked, hidden = false) {
|
|
1215
|
+
if (!ranges.length) return sheet;
|
|
1216
|
+
const data = cloneSparseMatrix(sheet.data);
|
|
1217
|
+
let rowCount = Math.max(sheet.row ?? 0, data.length);
|
|
1218
|
+
let columnCount = Math.max(sheet.column ?? 0, sparseMatrixColumnCount(data));
|
|
1219
|
+
for (const range of ranges){
|
|
1220
|
+
rowCount = Math.max(rowCount, range.row[1] + 1);
|
|
1221
|
+
columnCount = Math.max(columnCount, range.column[1] + 1);
|
|
1222
|
+
for (const [row, values] of spreadsheet_sparse_sparseArrayEntries(data))if (!(row < range.row[0]) && !(row > range.row[1])) for (const [column, source] of spreadsheet_sparse_sparseArrayEntries(values)){
|
|
1223
|
+
if (column < range.column[0] || column > range.column[1]) continue;
|
|
1224
|
+
const cell = {
|
|
1225
|
+
...source ?? {}
|
|
1226
|
+
};
|
|
1227
|
+
cell.lo = locked ? 1 : 0;
|
|
1228
|
+
if (hidden) cell.hi = 1;
|
|
1229
|
+
else if (void 0 !== cell.hi) delete cell.hi;
|
|
1230
|
+
data[row][column] = cell;
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
normalizeMatrix(data, rowCount, columnCount);
|
|
1234
|
+
const authority = sheetProtectionAuthority(sheet);
|
|
1235
|
+
authority.cellProtectionRanges.push(...ranges.map((range)=>({
|
|
1236
|
+
range,
|
|
1237
|
+
locked,
|
|
1238
|
+
hidden
|
|
1239
|
+
})));
|
|
1240
|
+
return withAuthority({
|
|
1241
|
+
...sheet,
|
|
1242
|
+
row: rowCount,
|
|
1243
|
+
column: columnCount,
|
|
1244
|
+
data
|
|
1245
|
+
}, authority);
|
|
1246
|
+
}
|
|
1247
|
+
function editableRangeRequiresCredentials(range) {
|
|
1248
|
+
const attributes = range.xlsxAttributes ?? {};
|
|
1249
|
+
return Boolean(attributes.password || attributes.hashValue || attributes.saltValue || attributes.securityDescriptor || attributes.securitydescriptor);
|
|
1250
|
+
}
|
|
1251
|
+
function sheetHasProtectionState(sheet) {
|
|
1252
|
+
const authority = sheetProtectionAuthority(sheet);
|
|
1253
|
+
if (1 === authority.sheet || authority.allowRangeList.length || Object.keys(authority.xlsxAttributes ?? {}).length) return true;
|
|
1254
|
+
return (sheet.data ?? []).some((row)=>row.some((cell)=>cell?.lo !== void 0 || cell?.hi !== void 0));
|
|
1255
|
+
}
|
|
1256
|
+
function protectedSheetCount(sheets) {
|
|
1257
|
+
return sheets.filter((sheet)=>1 === sheetProtectionAuthority(sheet).sheet).length;
|
|
1258
|
+
}
|
|
1259
|
+
function unlockedCellCount(sheet) {
|
|
1260
|
+
return (sheet.data ?? []).reduce((total, row)=>total + row.reduce((rowTotal, cell)=>rowTotal + (cell?.lo === 0 ? 1 : 0), 0), 0);
|
|
1261
|
+
}
|
|
1262
|
+
function spreadsheetProtectionKey(sheets) {
|
|
1263
|
+
return sheets.map((sheet)=>{
|
|
1264
|
+
const authority = sheetProtectionAuthority(sheet);
|
|
1265
|
+
const profile = spreadsheetMatrixProfile(sheet.data);
|
|
1266
|
+
let protectionCellKey = profile?.protectionCellKey;
|
|
1267
|
+
if (void 0 === protectionCellKey) {
|
|
1268
|
+
const cells = [];
|
|
1269
|
+
for (const [row, values] of spreadsheet_sparse_sparseArrayEntries(sheet.data))for (const [column, cell] of spreadsheet_sparse_sparseArrayEntries(values)){
|
|
1270
|
+
const hidden = cell?.hi;
|
|
1271
|
+
if (cell?.lo !== void 0 || void 0 !== hidden) cells.push(`${row}_${column}:${cell?.lo ?? ''}:${hidden ?? ''}`);
|
|
1272
|
+
}
|
|
1273
|
+
protectionCellKey = cells.join(',');
|
|
1274
|
+
}
|
|
1275
|
+
return `${sheet.id ?? sheet.name}:${JSON.stringify(authority)}:${protectionCellKey}`;
|
|
1276
|
+
}).join('|');
|
|
1277
|
+
}
|
|
1278
|
+
function editableRangeCellCount(ranges) {
|
|
1279
|
+
return ranges.reduce((total, range)=>total + (range.row[1] - range.row[0] + 1) * (range.column[1] - range.column[0] + 1), 0);
|
|
1280
|
+
}
|
|
1281
|
+
function withAuthority(sheet, authority) {
|
|
1282
|
+
return {
|
|
1283
|
+
...sheet,
|
|
1284
|
+
config: {
|
|
1285
|
+
...sheet.config ?? {},
|
|
1286
|
+
authority
|
|
1287
|
+
}
|
|
1288
|
+
};
|
|
1289
|
+
}
|
|
1290
|
+
function editableRangeList(value) {
|
|
1291
|
+
if (!Array.isArray(value)) return [];
|
|
1292
|
+
return value.flatMap((item, index)=>{
|
|
1293
|
+
if (!item || 'object' != typeof item) return [];
|
|
1294
|
+
const range = item;
|
|
1295
|
+
const sqref = stringValue(range.sqref);
|
|
1296
|
+
if (!sqref || !work_spreadsheet_ranges_parseSpreadsheetCellRanges(sqref)) return [];
|
|
1297
|
+
return [
|
|
1298
|
+
{
|
|
1299
|
+
name: stringValue(range.name) || `Range ${index + 1}`,
|
|
1300
|
+
sqref: canonicalRangeReference(sqref),
|
|
1301
|
+
hintText: stringValue(range.hintText) || void 0,
|
|
1302
|
+
xlsxAttributes: stringRecord(range.xlsxAttributes)
|
|
1303
|
+
}
|
|
1304
|
+
];
|
|
1305
|
+
});
|
|
1306
|
+
}
|
|
1307
|
+
function canonicalRangeReference(value) {
|
|
1308
|
+
const ranges = work_spreadsheet_ranges_parseSpreadsheetCellRanges(value);
|
|
1309
|
+
return ranges ? formatSpreadsheetCellRanges(ranges) : value.trim();
|
|
1310
|
+
}
|
|
1311
|
+
function normalizeMatrix(data, rows, columns) {
|
|
1312
|
+
data.length = Math.max(data.length, rows);
|
|
1313
|
+
for (const [, row] of spreadsheet_sparse_sparseArrayEntries(data))row.length = Math.max(row.length, columns);
|
|
1314
|
+
}
|
|
1315
|
+
function cellProtectionRangeList(value) {
|
|
1316
|
+
if (!Array.isArray(value)) return [];
|
|
1317
|
+
return value.flatMap((item)=>{
|
|
1318
|
+
if (!item || 'object' != typeof item) return [];
|
|
1319
|
+
const candidate = item;
|
|
1320
|
+
const range = candidate.range;
|
|
1321
|
+
if (!range || !Array.isArray(range.row) || !Array.isArray(range.column) || range.row.length < 2 || range.column.length < 2 || ![
|
|
1322
|
+
...range.row,
|
|
1323
|
+
...range.column
|
|
1324
|
+
].every((index)=>Number.isSafeInteger(index) && index >= 0)) return [];
|
|
1325
|
+
return [
|
|
1326
|
+
{
|
|
1327
|
+
range: {
|
|
1328
|
+
row: [
|
|
1329
|
+
Math.min(range.row[0], range.row[1]),
|
|
1330
|
+
Math.max(range.row[0], range.row[1])
|
|
1331
|
+
],
|
|
1332
|
+
column: [
|
|
1333
|
+
Math.min(range.column[0], range.column[1]),
|
|
1334
|
+
Math.max(range.column[0], range.column[1])
|
|
1335
|
+
]
|
|
1336
|
+
},
|
|
1337
|
+
locked: false !== candidate.locked,
|
|
1338
|
+
hidden: true === candidate.hidden
|
|
1339
|
+
}
|
|
1340
|
+
];
|
|
1341
|
+
});
|
|
1342
|
+
}
|
|
1343
|
+
function flag(value, fallback) {
|
|
1344
|
+
if (1 === value || true === value || '1' === value) return 1;
|
|
1345
|
+
if (0 === value || false === value || '0' === value) return 0;
|
|
1346
|
+
return fallback;
|
|
1347
|
+
}
|
|
1348
|
+
function stringValue(value) {
|
|
1349
|
+
return 'string' == typeof value ? value : '';
|
|
1350
|
+
}
|
|
1351
|
+
function stringRecord(value) {
|
|
1352
|
+
if (!value || 'object' != typeof value || Array.isArray(value)) return;
|
|
1353
|
+
const entries = Object.entries(value).filter((entry)=>'string' == typeof entry[1]);
|
|
1354
|
+
return entries.length ? Object.fromEntries(entries) : void 0;
|
|
1355
|
+
}
|
|
1356
|
+
const SPREADSHEET_CONDITIONAL_COMPARISON_OPERATORS = [
|
|
1357
|
+
'greaterThan',
|
|
1358
|
+
'greaterThanOrEqual',
|
|
1359
|
+
'lessThan',
|
|
1360
|
+
'lessThanOrEqual',
|
|
1361
|
+
'equal',
|
|
1362
|
+
'notEqual',
|
|
1363
|
+
'between',
|
|
1364
|
+
'notBetween'
|
|
1365
|
+
];
|
|
1366
|
+
function isSpreadsheetConditionalComparisonOperator(value) {
|
|
1367
|
+
return SPREADSHEET_CONDITIONAL_COMPARISON_OPERATORS.some((operator)=>operator === value);
|
|
1368
|
+
}
|
|
1369
|
+
function spreadsheetConditionalComparisonNeedsUpperValue(operator) {
|
|
1370
|
+
return 'between' === operator || 'notBetween' === operator;
|
|
1371
|
+
}
|
|
1372
|
+
const DEFAULT_DATA_BAR_MIN_LENGTH = 10;
|
|
1373
|
+
const DEFAULT_DATA_BAR_MAX_LENGTH = 90;
|
|
1374
|
+
function defaultSpreadsheetColorScaleThresholds(colorCount) {
|
|
1375
|
+
return 3 === colorCount ? [
|
|
1376
|
+
{
|
|
1377
|
+
type: 'min'
|
|
1378
|
+
},
|
|
1379
|
+
{
|
|
1380
|
+
type: 'percentile',
|
|
1381
|
+
value: 50
|
|
1382
|
+
},
|
|
1383
|
+
{
|
|
1384
|
+
type: 'max'
|
|
1385
|
+
}
|
|
1386
|
+
] : [
|
|
1387
|
+
{
|
|
1388
|
+
type: 'min'
|
|
1389
|
+
},
|
|
1390
|
+
{
|
|
1391
|
+
type: 'max'
|
|
1392
|
+
}
|
|
1393
|
+
];
|
|
1394
|
+
}
|
|
1395
|
+
function defaultSpreadsheetDataBarOptions() {
|
|
1396
|
+
return {
|
|
1397
|
+
thresholds: [
|
|
1398
|
+
{
|
|
1399
|
+
type: 'min'
|
|
1400
|
+
},
|
|
1401
|
+
{
|
|
1402
|
+
type: 'max'
|
|
1403
|
+
}
|
|
1404
|
+
],
|
|
1405
|
+
showValue: true,
|
|
1406
|
+
minLength: DEFAULT_DATA_BAR_MIN_LENGTH,
|
|
1407
|
+
maxLength: DEFAULT_DATA_BAR_MAX_LENGTH
|
|
1408
|
+
};
|
|
1409
|
+
}
|
|
1410
|
+
function normalizeSpreadsheetConditionalThreshold(value) {
|
|
1411
|
+
if (!value || 'object' != typeof value || Array.isArray(value)) return null;
|
|
1412
|
+
const source = value;
|
|
1413
|
+
if (![
|
|
1414
|
+
'min',
|
|
1415
|
+
'max',
|
|
1416
|
+
'num',
|
|
1417
|
+
'percent',
|
|
1418
|
+
'percentile'
|
|
1419
|
+
].includes(String(source.type))) return null;
|
|
1420
|
+
const type = source.type;
|
|
1421
|
+
if ('min' === type || 'max' === type) return {
|
|
1422
|
+
type
|
|
1423
|
+
};
|
|
1424
|
+
if ('number' != typeof source.value || !Number.isFinite(source.value)) return null;
|
|
1425
|
+
return {
|
|
1426
|
+
type,
|
|
1427
|
+
value: source.value
|
|
1428
|
+
};
|
|
1429
|
+
}
|
|
1430
|
+
function normalizeSpreadsheetConditionalVisualOptions(value, expectedThresholdCount, kind) {
|
|
1431
|
+
if (!value || 'object' != typeof value || Array.isArray(value)) return null;
|
|
1432
|
+
const source = value;
|
|
1433
|
+
if (!Array.isArray(source.thresholds) || source.thresholds.length !== expectedThresholdCount) return null;
|
|
1434
|
+
const thresholds = source.thresholds.map(normalizeSpreadsheetConditionalThreshold);
|
|
1435
|
+
if (thresholds.some((threshold)=>!threshold)) return null;
|
|
1436
|
+
if ('colorScale' === kind) return {
|
|
1437
|
+
thresholds: thresholds
|
|
1438
|
+
};
|
|
1439
|
+
const minLength = source.minLength ?? DEFAULT_DATA_BAR_MIN_LENGTH;
|
|
1440
|
+
const maxLength = source.maxLength ?? DEFAULT_DATA_BAR_MAX_LENGTH;
|
|
1441
|
+
if ('number' != typeof minLength || !Number.isFinite(minLength) || minLength < 0 || minLength > 100 || 'number' != typeof maxLength || !Number.isFinite(maxLength) || maxLength < 0 || maxLength > 100 || minLength > maxLength) return null;
|
|
1442
|
+
return {
|
|
1443
|
+
thresholds: thresholds,
|
|
1444
|
+
showValue: false !== source.showValue,
|
|
1445
|
+
minLength,
|
|
1446
|
+
maxLength
|
|
1447
|
+
};
|
|
1448
|
+
}
|
|
1449
|
+
function spreadsheetConditionalThresholdValue(threshold, sourceValues) {
|
|
1450
|
+
const values = sourceValues.filter(Number.isFinite).sort((left, right)=>left - right);
|
|
1451
|
+
if (!values.length) return null;
|
|
1452
|
+
const minimum = values[0];
|
|
1453
|
+
const maximum = values.at(-1);
|
|
1454
|
+
if ('min' === threshold.type) return minimum;
|
|
1455
|
+
if ('max' === threshold.type) return maximum;
|
|
1456
|
+
if ('num' === threshold.type) return threshold.value ?? null;
|
|
1457
|
+
const percentage = threshold.value;
|
|
1458
|
+
if (void 0 === percentage || !Number.isFinite(percentage)) return null;
|
|
1459
|
+
if ('percent' === threshold.type) return minimum + (maximum - minimum) * percentage / 100;
|
|
1460
|
+
const position = Math.max(0, Math.min(100, percentage)) / 100 * (values.length - 1);
|
|
1461
|
+
const lower = Math.floor(position);
|
|
1462
|
+
const upper = Math.ceil(position);
|
|
1463
|
+
if (lower === upper) return values[lower];
|
|
1464
|
+
return values[lower] + (values[upper] - values[lower]) * (position - lower);
|
|
1465
|
+
}
|
|
1466
|
+
function spreadsheetConditionalThresholdsEqual(left, right) {
|
|
1467
|
+
return left.length === right.length && left.every((threshold, index)=>threshold.type === right[index]?.type && threshold.value === right[index]?.value);
|
|
1468
|
+
}
|
|
1469
|
+
const SPREADSHEET_CONDITIONAL_ICON_SETS = [
|
|
1470
|
+
{
|
|
1471
|
+
name: '3Arrows',
|
|
1472
|
+
label: '三向彩色箭头',
|
|
1473
|
+
count: 3
|
|
1474
|
+
},
|
|
1475
|
+
{
|
|
1476
|
+
name: '3ArrowsGray',
|
|
1477
|
+
label: '三向灰色箭头',
|
|
1478
|
+
count: 3
|
|
1479
|
+
},
|
|
1480
|
+
{
|
|
1481
|
+
name: '3Flags',
|
|
1482
|
+
label: '三色旗帜',
|
|
1483
|
+
count: 3
|
|
1484
|
+
},
|
|
1485
|
+
{
|
|
1486
|
+
name: '3TrafficLights1',
|
|
1487
|
+
label: '三色交通灯(实心)',
|
|
1488
|
+
count: 3
|
|
1489
|
+
},
|
|
1490
|
+
{
|
|
1491
|
+
name: '3TrafficLights2',
|
|
1492
|
+
label: '三色交通灯(边框)',
|
|
1493
|
+
count: 3
|
|
1494
|
+
},
|
|
1495
|
+
{
|
|
1496
|
+
name: '3Signs',
|
|
1497
|
+
label: '三色标志',
|
|
1498
|
+
count: 3
|
|
1499
|
+
},
|
|
1500
|
+
{
|
|
1501
|
+
name: '3Symbols',
|
|
1502
|
+
label: '三色符号(圆形)',
|
|
1503
|
+
count: 3
|
|
1504
|
+
},
|
|
1505
|
+
{
|
|
1506
|
+
name: '3Symbols2',
|
|
1507
|
+
label: '三色符号',
|
|
1508
|
+
count: 3
|
|
1509
|
+
},
|
|
1510
|
+
{
|
|
1511
|
+
name: '4Arrows',
|
|
1512
|
+
label: '四向彩色箭头',
|
|
1513
|
+
count: 4
|
|
1514
|
+
},
|
|
1515
|
+
{
|
|
1516
|
+
name: '4ArrowsGray',
|
|
1517
|
+
label: '四向灰色箭头',
|
|
1518
|
+
count: 4
|
|
1519
|
+
},
|
|
1520
|
+
{
|
|
1521
|
+
name: '4RedToBlack',
|
|
1522
|
+
label: '红到黑圆点',
|
|
1523
|
+
count: 4
|
|
1524
|
+
},
|
|
1525
|
+
{
|
|
1526
|
+
name: '4Rating',
|
|
1527
|
+
label: '四级评分',
|
|
1528
|
+
count: 4
|
|
1529
|
+
},
|
|
1530
|
+
{
|
|
1531
|
+
name: '4TrafficLights',
|
|
1532
|
+
label: '四色交通灯',
|
|
1533
|
+
count: 4
|
|
1534
|
+
},
|
|
1535
|
+
{
|
|
1536
|
+
name: '5Arrows',
|
|
1537
|
+
label: '五向彩色箭头',
|
|
1538
|
+
count: 5
|
|
1539
|
+
},
|
|
1540
|
+
{
|
|
1541
|
+
name: '5ArrowsGray',
|
|
1542
|
+
label: '五向灰色箭头',
|
|
1543
|
+
count: 5
|
|
1544
|
+
},
|
|
1545
|
+
{
|
|
1546
|
+
name: '5Rating',
|
|
1547
|
+
label: '五级评分',
|
|
1548
|
+
count: 5
|
|
1549
|
+
},
|
|
1550
|
+
{
|
|
1551
|
+
name: '5Quarters',
|
|
1552
|
+
label: '五级圆饼',
|
|
1553
|
+
count: 5
|
|
1554
|
+
}
|
|
1555
|
+
];
|
|
1556
|
+
const COLOR_3 = [
|
|
1557
|
+
'#c62828',
|
|
1558
|
+
'#f9a825',
|
|
1559
|
+
'#2e7d32'
|
|
1560
|
+
];
|
|
1561
|
+
const COLOR_4 = [
|
|
1562
|
+
'#c62828',
|
|
1563
|
+
'#ef6c00',
|
|
1564
|
+
'#7cb342',
|
|
1565
|
+
'#2e7d32'
|
|
1566
|
+
];
|
|
1567
|
+
const COLOR_5 = [
|
|
1568
|
+
'#c62828',
|
|
1569
|
+
'#ef6c00',
|
|
1570
|
+
'#f9a825',
|
|
1571
|
+
'#7cb342',
|
|
1572
|
+
'#2e7d32'
|
|
1573
|
+
];
|
|
1574
|
+
function isSpreadsheetConditionalIconSetName(value) {
|
|
1575
|
+
return SPREADSHEET_CONDITIONAL_ICON_SETS.some((item)=>item.name === value);
|
|
1576
|
+
}
|
|
1577
|
+
function spreadsheetConditionalIconSetCount(iconSet) {
|
|
1578
|
+
return SPREADSHEET_CONDITIONAL_ICON_SETS.find((item)=>item.name === iconSet).count;
|
|
1579
|
+
}
|
|
1580
|
+
function defaultSpreadsheetConditionalIconThresholds(iconSet) {
|
|
1581
|
+
const count = spreadsheetConditionalIconSetCount(iconSet);
|
|
1582
|
+
return Array.from({
|
|
1583
|
+
length: count
|
|
1584
|
+
}, (_, index)=>0 === index ? {
|
|
1585
|
+
type: 'min',
|
|
1586
|
+
gte: true
|
|
1587
|
+
} : {
|
|
1588
|
+
type: 'percent',
|
|
1589
|
+
value: Math.round(100 * index / count),
|
|
1590
|
+
gte: true
|
|
1591
|
+
});
|
|
1592
|
+
}
|
|
1593
|
+
function normalizeSpreadsheetConditionalIconSetFormat(value) {
|
|
1594
|
+
if (!value || 'object' != typeof value || Array.isArray(value)) return null;
|
|
1595
|
+
const source = value;
|
|
1596
|
+
if (!isSpreadsheetConditionalIconSetName(source.iconSet) || !Array.isArray(source.thresholds)) return null;
|
|
1597
|
+
const count = spreadsheetConditionalIconSetCount(source.iconSet);
|
|
1598
|
+
if (source.thresholds.length !== count) return null;
|
|
1599
|
+
const thresholds = source.thresholds.map(normalizeThreshold);
|
|
1600
|
+
if (thresholds.some((threshold)=>!threshold)) return null;
|
|
1601
|
+
return {
|
|
1602
|
+
iconSet: source.iconSet,
|
|
1603
|
+
showValue: false !== source.showValue,
|
|
1604
|
+
reverse: true === source.reverse,
|
|
1605
|
+
percent: false !== source.percent,
|
|
1606
|
+
thresholds: thresholds
|
|
1607
|
+
};
|
|
1608
|
+
}
|
|
1609
|
+
function spreadsheetConditionalIconForValue(sourceFormat, value, sourceValues) {
|
|
1610
|
+
const format = normalizeSpreadsheetConditionalIconSetFormat(sourceFormat);
|
|
1611
|
+
const values = sourceValues.filter(Number.isFinite);
|
|
1612
|
+
if (!format || !Number.isFinite(value) || !values.length) return null;
|
|
1613
|
+
const count = spreadsheetConditionalIconSetCount(format.iconSet);
|
|
1614
|
+
let level = 0;
|
|
1615
|
+
for(let index = 1; index < count; index += 1){
|
|
1616
|
+
const threshold = format.thresholds[index];
|
|
1617
|
+
const cutoff = spreadsheetConditionalThresholdValue(threshold, values);
|
|
1618
|
+
if (null === cutoff) return null;
|
|
1619
|
+
if (threshold.gte ? value >= cutoff : value > cutoff) level = index;
|
|
1620
|
+
}
|
|
1621
|
+
return {
|
|
1622
|
+
iconSet: format.iconSet,
|
|
1623
|
+
index: format.reverse ? count - 1 - level : level,
|
|
1624
|
+
count,
|
|
1625
|
+
showValue: format.showValue
|
|
1626
|
+
};
|
|
1627
|
+
}
|
|
1628
|
+
function spreadsheetConditionalIconAppearance(icon) {
|
|
1629
|
+
const index = Math.max(0, Math.min(icon.count - 1, icon.index));
|
|
1630
|
+
const definition = SPREADSHEET_CONDITIONAL_ICON_SETS.find((item)=>item.name === icon.iconSet);
|
|
1631
|
+
const label = `${definition.label} ${index + 1}/${icon.count}`;
|
|
1632
|
+
if (icon.iconSet.includes('Arrows')) {
|
|
1633
|
+
const glyphs = 3 === icon.count ? [
|
|
1634
|
+
'↓',
|
|
1635
|
+
'→',
|
|
1636
|
+
'↑'
|
|
1637
|
+
] : 4 === icon.count ? [
|
|
1638
|
+
'↓',
|
|
1639
|
+
'↘',
|
|
1640
|
+
'↗',
|
|
1641
|
+
'↑'
|
|
1642
|
+
] : [
|
|
1643
|
+
'↓',
|
|
1644
|
+
'↘',
|
|
1645
|
+
'→',
|
|
1646
|
+
'↗',
|
|
1647
|
+
'↑'
|
|
1648
|
+
];
|
|
1649
|
+
return {
|
|
1650
|
+
glyph: glyphs[index],
|
|
1651
|
+
color: icon.iconSet.includes('Gray') ? '#606a78' : work_spreadsheet_conditional_icons_palette(icon.count)[index],
|
|
1652
|
+
label
|
|
1653
|
+
};
|
|
1654
|
+
}
|
|
1655
|
+
if ('3Flags' === icon.iconSet) return {
|
|
1656
|
+
glyph: '⚑',
|
|
1657
|
+
color: COLOR_3[index],
|
|
1658
|
+
label
|
|
1659
|
+
};
|
|
1660
|
+
if (icon.iconSet.includes('TrafficLights')) return {
|
|
1661
|
+
glyph: '3TrafficLights2' === icon.iconSet ? '◉' : '●',
|
|
1662
|
+
color: work_spreadsheet_conditional_icons_palette(icon.count)[index],
|
|
1663
|
+
label
|
|
1664
|
+
};
|
|
1665
|
+
if ('3Signs' === icon.iconSet) return {
|
|
1666
|
+
glyph: [
|
|
1667
|
+
'◆',
|
|
1668
|
+
'▲',
|
|
1669
|
+
'●'
|
|
1670
|
+
][index],
|
|
1671
|
+
color: COLOR_3[index],
|
|
1672
|
+
label
|
|
1673
|
+
};
|
|
1674
|
+
if ('3Symbols' === icon.iconSet || '3Symbols2' === icon.iconSet) return {
|
|
1675
|
+
glyph: [
|
|
1676
|
+
'✕',
|
|
1677
|
+
'!',
|
|
1678
|
+
'✓'
|
|
1679
|
+
][index],
|
|
1680
|
+
color: COLOR_3[index],
|
|
1681
|
+
label
|
|
1682
|
+
};
|
|
1683
|
+
if ('4RedToBlack' === icon.iconSet) return {
|
|
1684
|
+
glyph: '●',
|
|
1685
|
+
color: [
|
|
1686
|
+
'#c62828',
|
|
1687
|
+
'#e45b4f',
|
|
1688
|
+
'#697386',
|
|
1689
|
+
'#111827'
|
|
1690
|
+
][index],
|
|
1691
|
+
label
|
|
1692
|
+
};
|
|
1693
|
+
if ('4Rating' === icon.iconSet) return {
|
|
1694
|
+
glyph: [
|
|
1695
|
+
'▁',
|
|
1696
|
+
'▃',
|
|
1697
|
+
'▆',
|
|
1698
|
+
'█'
|
|
1699
|
+
][index],
|
|
1700
|
+
color: '#54708f',
|
|
1701
|
+
label
|
|
1702
|
+
};
|
|
1703
|
+
if ('5Rating' === icon.iconSet) return {
|
|
1704
|
+
glyph: [
|
|
1705
|
+
'▁',
|
|
1706
|
+
'▂',
|
|
1707
|
+
'▄',
|
|
1708
|
+
'▆',
|
|
1709
|
+
'█'
|
|
1710
|
+
][index],
|
|
1711
|
+
color: '#54708f',
|
|
1712
|
+
label
|
|
1713
|
+
};
|
|
1714
|
+
return {
|
|
1715
|
+
glyph: [
|
|
1716
|
+
'○',
|
|
1717
|
+
'◔',
|
|
1718
|
+
'◑',
|
|
1719
|
+
'◕',
|
|
1720
|
+
'●'
|
|
1721
|
+
][index],
|
|
1722
|
+
color: '#54708f',
|
|
1723
|
+
label
|
|
1724
|
+
};
|
|
1725
|
+
}
|
|
1726
|
+
function drawSpreadsheetConditionalIcon(context, bounds, icon, background, maskValue = !icon.showValue) {
|
|
1727
|
+
const width = bounds.endX - bounds.startX;
|
|
1728
|
+
const height = bounds.endY - bounds.startY;
|
|
1729
|
+
if (width < 6 || height < 6) return;
|
|
1730
|
+
const appearance = spreadsheetConditionalIconAppearance(icon);
|
|
1731
|
+
context.save();
|
|
1732
|
+
context.beginPath();
|
|
1733
|
+
context.rect(bounds.startX + 1, bounds.startY + 1, Math.max(0, width - 3), Math.max(0, height - 3));
|
|
1734
|
+
context.clip();
|
|
1735
|
+
if (maskValue) {
|
|
1736
|
+
context.fillStyle = background;
|
|
1737
|
+
context.fillRect(bounds.startX + 1, bounds.startY + 1, Math.max(0, width - 3), Math.max(0, height - 3));
|
|
1738
|
+
}
|
|
1739
|
+
const size = Math.max(9, Math.min(16, height - 5));
|
|
1740
|
+
context.fillStyle = appearance.color;
|
|
1741
|
+
context.font = `700 ${size}px "Arial Unicode MS", "Segoe UI Symbol", sans-serif`;
|
|
1742
|
+
context.textAlign = 'left';
|
|
1743
|
+
context.textBaseline = 'middle';
|
|
1744
|
+
context.fillText(appearance.glyph, bounds.startX + 4, bounds.startY + height / 2);
|
|
1745
|
+
context.restore();
|
|
1746
|
+
}
|
|
1747
|
+
function normalizeThreshold(value) {
|
|
1748
|
+
if (!value || 'object' != typeof value || Array.isArray(value)) return null;
|
|
1749
|
+
const source = value;
|
|
1750
|
+
const threshold = normalizeSpreadsheetConditionalThreshold(source);
|
|
1751
|
+
return threshold ? {
|
|
1752
|
+
...threshold,
|
|
1753
|
+
gte: false !== source.gte
|
|
1754
|
+
} : null;
|
|
1755
|
+
}
|
|
1756
|
+
function work_spreadsheet_conditional_icons_palette(count) {
|
|
1757
|
+
if (3 === count) return COLOR_3;
|
|
1758
|
+
if (4 === count) return COLOR_4;
|
|
1759
|
+
return COLOR_5;
|
|
1760
|
+
}
|
|
1761
|
+
function effectiveSpreadsheetHeaderFooterSections(sections) {
|
|
1762
|
+
return {
|
|
1763
|
+
left: sections?.left ?? '',
|
|
1764
|
+
center: sections?.center ?? '',
|
|
1765
|
+
right: sections?.right ?? ''
|
|
1766
|
+
};
|
|
1767
|
+
}
|
|
1768
|
+
const DEFAULT_MARGINS = {
|
|
1769
|
+
top: 19.05,
|
|
1770
|
+
right: 17.78,
|
|
1771
|
+
bottom: 19.05,
|
|
1772
|
+
left: 17.78,
|
|
1773
|
+
header: 7.62,
|
|
1774
|
+
footer: 7.62
|
|
1775
|
+
};
|
|
1776
|
+
const PAPER_DIMENSIONS = {
|
|
1777
|
+
a3: {
|
|
1778
|
+
width: 297,
|
|
1779
|
+
height: 420
|
|
1780
|
+
},
|
|
1781
|
+
a4: {
|
|
1782
|
+
width: 210,
|
|
1783
|
+
height: 297
|
|
1784
|
+
},
|
|
1785
|
+
a5: {
|
|
1786
|
+
width: 148,
|
|
1787
|
+
height: 210
|
|
1788
|
+
},
|
|
1789
|
+
letter: {
|
|
1790
|
+
width: 215.9,
|
|
1791
|
+
height: 279.4
|
|
1792
|
+
},
|
|
1793
|
+
legal: {
|
|
1794
|
+
width: 215.9,
|
|
1795
|
+
height: 355.6
|
|
1796
|
+
},
|
|
1797
|
+
tabloid: {
|
|
1798
|
+
width: 279.4,
|
|
1799
|
+
height: 431.8
|
|
1800
|
+
}
|
|
1801
|
+
};
|
|
1802
|
+
PAPER_DIMENSIONS.a4.height, DEFAULT_MARGINS.left, DEFAULT_MARGINS.right;
|
|
1803
|
+
PAPER_DIMENSIONS.a4.width, DEFAULT_MARGINS.top, DEFAULT_MARGINS.bottom;
|
|
1804
|
+
function effectiveSpreadsheetPageSetup(pageSetup) {
|
|
1805
|
+
return {
|
|
1806
|
+
paperSize: normalizeSpreadsheetPaperSize(pageSetup?.paperSize),
|
|
1807
|
+
orientation: pageSetup?.orientation === 'portrait' ? 'portrait' : 'landscape',
|
|
1808
|
+
scale: work_spreadsheet_page_setup_boundedInteger(pageSetup?.scale, 10, 400, 100),
|
|
1809
|
+
fitToPage: Boolean(pageSetup?.fitToPage),
|
|
1810
|
+
fitToWidth: work_spreadsheet_page_setup_boundedInteger(pageSetup?.fitToWidth, 0, 32767, 1),
|
|
1811
|
+
fitToHeight: work_spreadsheet_page_setup_boundedInteger(pageSetup?.fitToHeight, 0, 32767, 0),
|
|
1812
|
+
horizontalCentered: Boolean(pageSetup?.horizontalCentered),
|
|
1813
|
+
verticalCentered: Boolean(pageSetup?.verticalCentered),
|
|
1814
|
+
header: effectiveSpreadsheetHeaderFooterSections(pageSetup?.header),
|
|
1815
|
+
footer: effectiveSpreadsheetHeaderFooterSections(pageSetup?.footer),
|
|
1816
|
+
pageNumberStart: work_spreadsheet_page_setup_boundedInteger(pageSetup?.pageNumberStart, 1, 32767, 1),
|
|
1817
|
+
pageOrder: pageSetup?.pageOrder === 'downThenOver' ? 'downThenOver' : 'overThenDown',
|
|
1818
|
+
scaleWithDocument: pageSetup?.scaleWithDocument !== false,
|
|
1819
|
+
alignWithMargins: pageSetup?.alignWithMargins !== false,
|
|
1820
|
+
margins: {
|
|
1821
|
+
top: work_spreadsheet_page_setup_boundedNumber(pageSetup?.margins?.top, 0, 100, DEFAULT_MARGINS.top),
|
|
1822
|
+
right: work_spreadsheet_page_setup_boundedNumber(pageSetup?.margins?.right, 0, 100, DEFAULT_MARGINS.right),
|
|
1823
|
+
bottom: work_spreadsheet_page_setup_boundedNumber(pageSetup?.margins?.bottom, 0, 100, DEFAULT_MARGINS.bottom),
|
|
1824
|
+
left: work_spreadsheet_page_setup_boundedNumber(pageSetup?.margins?.left, 0, 100, DEFAULT_MARGINS.left),
|
|
1825
|
+
header: work_spreadsheet_page_setup_boundedNumber(pageSetup?.margins?.header, 0, 100, DEFAULT_MARGINS.header),
|
|
1826
|
+
footer: work_spreadsheet_page_setup_boundedNumber(pageSetup?.margins?.footer, 0, 100, DEFAULT_MARGINS.footer)
|
|
1827
|
+
}
|
|
1828
|
+
};
|
|
1829
|
+
}
|
|
1830
|
+
function normalizeSpreadsheetPaperSize(value) {
|
|
1831
|
+
switch(value){
|
|
1832
|
+
case 'a3':
|
|
1833
|
+
case 'a4':
|
|
1834
|
+
case 'a5':
|
|
1835
|
+
case 'letter':
|
|
1836
|
+
case 'legal':
|
|
1837
|
+
case 'tabloid':
|
|
1838
|
+
return value;
|
|
1839
|
+
default:
|
|
1840
|
+
return 'a4';
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
function work_spreadsheet_page_setup_boundedInteger(value, minimum, maximum, fallback) {
|
|
1844
|
+
return Math.trunc(work_spreadsheet_page_setup_boundedNumber(value, minimum, maximum, fallback));
|
|
1845
|
+
}
|
|
1846
|
+
function work_spreadsheet_page_setup_boundedNumber(value, minimum, maximum, fallback) {
|
|
1847
|
+
return 'number' == typeof value && Number.isFinite(value) && value >= minimum && value <= maximum ? value : fallback;
|
|
1848
|
+
}
|
|
1849
|
+
export { DEFAULT_PROTECTION_HINT, SPREADSHEET_CONDITIONAL_COMPARISON_OPERATORS, SPREADSHEET_CONDITIONAL_ICON_SETS, XLSX_GRADIENT_FILL_CELL_KEY, XLSX_PATTERN_FILL_CELL_KEY, activeXlsxGradientFill, activeXlsxPatternFill, applyXlsxSemanticColorOrigin, attachSpreadsheetShownCommentCells, createXlsxColorResolver, decodeXlsxCellAddress, defaultSpreadsheetColorScaleThresholds, defaultSpreadsheetConditionalIconThresholds, defaultSpreadsheetDataBarOptions, defaultXlsxBorder, defaultXlsxFill, deleteXlsxGradientFill, deleteXlsxPatternFill, drawSpreadsheetConditionalIcon, editableRangeCellCount, editableRangeRequiresCredentials, effectiveSpreadsheetPageSetup, ensureXlsxStyleCollection, freezeImportedSpreadsheetCell, importedSheetProtectionAuthority, isSpreadsheetConditionalComparisonOperator, isSpreadsheetConditionalIconSetName, normalizeSheetProtectionAuthority, normalizeSpreadsheetConditionalIconSetFormat, normalizeSpreadsheetConditionalVisualOptions, normalizeSpreadsheetPaperSize, normalizeXlsxGradientFill, normalizeXlsxPatternFill, normalizeXlsxSemanticColorOrigin, prepareXlsxSemanticPalette, protectedSheetCount, readXlsxGradientFill, readXlsxPatternFill, readXlsxSemanticColorOrigin, registerDerivedSpreadsheetMatrix, registerImportedSpreadsheetMatrix, resolveXlsxColor, sameSpreadsheetHistoryValue, setXlsxBorderLine, setXlsxColorChild, setXlsxToggleChild, setXlsxUnderlineChild, setXlsxValueChild, sheetHasProtectionState, sheetProtectionAuthority, spreadsheetConditionalComparisonNeedsUpperValue, spreadsheetConditionalIconForValue, spreadsheetConditionalIconSetCount, spreadsheetConditionalThresholdValue, spreadsheetConditionalThresholdsEqual, spreadsheetMatrixProfile, spreadsheetProtectionKey, unlockedCellCount, withEditableRange, withSheetProtection, withSheetSelectionPermissions, withXlsxCellStyleOrigin, withXlsxGradientFill, withXlsxPatternFill, withoutEditableRange, writeXlsxAlignment, xlsxCellAddress, xlsxCellStyleOrigin, xlsxCellStyleOriginSemanticColors, xlsxColorElementMatchesOrigin, xlsxGradientFillFallbackColor, xlsxGradientFillKey, xlsxGradientFillSemanticColors, xlsxPatternFillKey, xlsxPatternFillSemanticColors, xlsxPatternFillTypes, xlsxRgbColor, xlsxSemanticColorMatchesValue, xlsxSemanticColorOriginKey, xlsxSemanticColorOriginSupported, xlsxWorksheetCellEntries };
|