@a3s-lab/office 0.24.0 → 0.25.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.
@@ -1,6 +1,6 @@
1
1
  import { workOfficeCollaborationJsonEqual, canonicalWorkOfficeCollaborationJson, isWorkOfficeCollaborationRecord, cloneWorkOfficeCollaborationJson } from "./4650.js";
2
2
  import { initializeWorkOfficeCollaborationMetadata, assertWorkOfficeCollaborationEditable, OfficeCollaborationError as WorkOfficeCollaborationError, readOfficeCollaborationMetadata as readWorkOfficeCollaborationMetadata, registerWorkOfficeCollaborationInitializer, markWorkOfficeCollaborationInitialized, assertWorkOfficeCollaborationOrigin } from "./9787.js";
3
- import { OFFICE_KERNEL_SPREADSHEET_MAX_ROWS } from "./5184.js";
3
+ import { directChild, directChildren, descendants, OFFICE_KERNEL_SPREADSHEET_MAX_ROWS, attribute, firstDescendant } from "./5184.js";
4
4
  import { sparseMatrixColumnCount, cloneSparseMatrix, sparseArrayEntries as spreadsheet_sparse_sparseArrayEntries, formatSpreadsheetCellRanges, isValidSpreadsheetDefinedName, parseSpreadsheetCellRanges as work_spreadsheet_ranges_parseSpreadsheetCellRanges, sparseArrayIndexes } from "./8715.js";
5
5
  import { patchWorkOfficeCollaborationFlatJsonMap, readWorkOfficeCollaborationFlatJsonMap } from "./7060.js";
6
6
  import * as __rspack_external_yjs from "yjs";
@@ -1620,6 +1620,54 @@ function assertInitializedSpreadsheetSession(session) {
1620
1620
  if (metadata?.initialized) return;
1621
1621
  throw new WorkOfficeCollaborationError('office.collaboration.not_initialized', 'The Spreadsheet collaboration session has not been initialized.');
1622
1622
  }
1623
+ function* xlsxWorksheetCellEntries(worksheet) {
1624
+ if (Array.isArray(worksheet)) {
1625
+ for(let row = 0; row < worksheet.length; row += 1){
1626
+ const cells = worksheet[row];
1627
+ if (Array.isArray(cells)) for(let column = 0; column < cells.length; column += 1){
1628
+ const cell = cells[column];
1629
+ if (!(!cell || 'object' != typeof cell || Array.isArray(cell))) yield {
1630
+ address: xlsxCellAddress(row, column),
1631
+ cell: cell,
1632
+ column,
1633
+ row
1634
+ };
1635
+ }
1636
+ }
1637
+ return;
1638
+ }
1639
+ for (const [address, cell] of Object.entries(worksheet)){
1640
+ if (address.startsWith('!') || !cell || 'object' != typeof cell) continue;
1641
+ const position = decodeXlsxCellAddress(address);
1642
+ if (position) yield {
1643
+ address,
1644
+ cell: cell,
1645
+ ...position
1646
+ };
1647
+ }
1648
+ }
1649
+ function xlsxCellAddress(row, column) {
1650
+ let value = column + 1;
1651
+ let label = '';
1652
+ while(value > 0){
1653
+ value -= 1;
1654
+ label = String.fromCharCode(65 + value % 26) + label;
1655
+ value = Math.floor(value / 26);
1656
+ }
1657
+ return `${label}${row + 1}`;
1658
+ }
1659
+ function decodeXlsxCellAddress(address) {
1660
+ const match = /^([A-Za-z]+)([1-9][0-9]*)$/.exec(address);
1661
+ if (!match) return null;
1662
+ let column = 0;
1663
+ for (const character of match[1].toUpperCase())column = 26 * column + character.charCodeAt(0) - 64;
1664
+ const row = Number(match[2]);
1665
+ if (!Number.isSafeInteger(row) || row <= 0) return null;
1666
+ return {
1667
+ column: column - 1,
1668
+ row: row - 1
1669
+ };
1670
+ }
1623
1671
  const spreadsheetFormulaHistoryIgnoredKeys = new Set([
1624
1672
  'ct',
1625
1673
  'm',
@@ -2145,6 +2193,602 @@ function spreadsheetDiagonalBorderLine(value) {
2145
2193
  function isRecord(value) {
2146
2194
  return Boolean(value && 'object' == typeof value && !Array.isArray(value));
2147
2195
  }
2196
+ const borderChildOrder = [
2197
+ 'start',
2198
+ 'end',
2199
+ 'left',
2200
+ 'right',
2201
+ 'top',
2202
+ 'bottom',
2203
+ 'diagonal',
2204
+ 'vertical',
2205
+ 'horizontal',
2206
+ 'extLst'
2207
+ ];
2208
+ function ensureXlsxStyleCollection(document, name, anchors) {
2209
+ const root = document.documentElement;
2210
+ const existing = directChild(root, name);
2211
+ if (existing) return existing;
2212
+ const collection = document.createElementNS(root.namespaceURI, name);
2213
+ root.insertBefore(collection, directChildren(root).find((child)=>anchors.includes(child.localName)) ?? null);
2214
+ return collection;
2215
+ }
2216
+ function defaultXlsxFill(document, patternType) {
2217
+ const fill = document.createElementNS(document.documentElement.namespaceURI, 'fill');
2218
+ const pattern = document.createElementNS(document.documentElement.namespaceURI, 'patternFill');
2219
+ pattern.setAttribute('patternType', patternType);
2220
+ fill.append(pattern);
2221
+ return fill;
2222
+ }
2223
+ function defaultXlsxBorder(document) {
2224
+ const border = document.createElementNS(document.documentElement.namespaceURI, 'border');
2225
+ for (const name of [
2226
+ 'left',
2227
+ 'right',
2228
+ 'top',
2229
+ 'bottom',
2230
+ 'diagonal'
2231
+ ])border.append(document.createElementNS(document.documentElement.namespaceURI, name));
2232
+ return border;
2233
+ }
2234
+ function setXlsxBorderLine(document, border, name, line) {
2235
+ removeXlsxChildren(border, name);
2236
+ const element = document.createElementNS(document.documentElement.namespaceURI, name);
2237
+ if (line) {
2238
+ element.setAttribute('style', line.style);
2239
+ const color = xlsxRgbColor(line.color);
2240
+ if (color) {
2241
+ const child = document.createElementNS(document.documentElement.namespaceURI, 'color');
2242
+ child.setAttribute('rgb', color);
2243
+ element.append(child);
2244
+ }
2245
+ }
2246
+ insertXlsxOrderedChild(border, element, borderChildOrder);
2247
+ }
2248
+ function writeXlsxAlignment(document, xf, style) {
2249
+ let alignment = directChild(xf, 'alignment');
2250
+ if (!alignment) {
2251
+ alignment = document.createElementNS(document.documentElement.namespaceURI, 'alignment');
2252
+ xf.insertBefore(alignment, directChildren(xf).find((child)=>[
2253
+ 'protection',
2254
+ 'extLst'
2255
+ ].includes(child.localName)) ?? null);
2256
+ }
2257
+ if (void 0 !== style.horizontal) alignment.setAttribute('horizontal', style.horizontal);
2258
+ if (void 0 !== style.vertical) alignment.setAttribute('vertical', style.vertical);
2259
+ if (void 0 !== style.wrapText) alignment.setAttribute('wrapText', style.wrapText ? '1' : '0');
2260
+ if (void 0 !== style.textRotation && Number.isInteger(style.textRotation) && (style.textRotation >= 0 && style.textRotation <= 180 || 255 === style.textRotation)) alignment.setAttribute('textRotation', String(style.textRotation));
2261
+ }
2262
+ function setXlsxValueChild(document, parent, name, value, order) {
2263
+ removeXlsxChildren(parent, name);
2264
+ const child = document.createElementNS(document.documentElement.namespaceURI, name);
2265
+ child.setAttribute('val', value);
2266
+ insertXlsxOrderedChild(parent, child, order);
2267
+ }
2268
+ function setXlsxColorChild(document, parent, color, order) {
2269
+ removeXlsxChildren(parent, 'color');
2270
+ const child = document.createElementNS(document.documentElement.namespaceURI, 'color');
2271
+ child.setAttribute('rgb', color);
2272
+ insertXlsxOrderedChild(parent, child, order);
2273
+ }
2274
+ function setXlsxToggleChild(document, parent, name, enabled, order) {
2275
+ removeXlsxChildren(parent, name);
2276
+ if (!enabled) return;
2277
+ const child = document.createElementNS(document.documentElement.namespaceURI, name);
2278
+ child.setAttribute('val', '1');
2279
+ insertXlsxOrderedChild(parent, child, order);
2280
+ }
2281
+ function setXlsxUnderlineChild(document, parent, style, order) {
2282
+ removeXlsxChildren(parent, 'u');
2283
+ if ('none' === style) return;
2284
+ const child = document.createElementNS(document.documentElement.namespaceURI, 'u');
2285
+ child.setAttribute('val', style);
2286
+ insertXlsxOrderedChild(parent, child, order);
2287
+ }
2288
+ function xlsxRgbColor(value) {
2289
+ if ('string' != typeof value) return null;
2290
+ const color = value.trim().replace('#', '').toUpperCase();
2291
+ if (/^[0-9A-F]{6}$/.test(color)) return `FF${color}`;
2292
+ if (/^[0-9A-F]{8}$/.test(color)) return color;
2293
+ if (/^[0-9A-F]{3}$/.test(color)) return `FF${[
2294
+ ...color
2295
+ ].map((character)=>character.repeat(2)).join('')}`;
2296
+ return null;
2297
+ }
2298
+ function removeXlsxChildren(parent, name) {
2299
+ for (const child of directChildren(parent, name))child.remove();
2300
+ }
2301
+ function insertXlsxOrderedChild(parent, child, order) {
2302
+ const requested = order.indexOf(child.localName);
2303
+ const anchor = directChildren(parent).find((candidate)=>order.indexOf(candidate.localName) > requested);
2304
+ parent.insertBefore(child, anchor ?? null);
2305
+ }
2306
+ const defaultThemeColors = [
2307
+ 'ffffff',
2308
+ '000000',
2309
+ 'e7e6e6',
2310
+ '44546a',
2311
+ '4472c4',
2312
+ 'ed7d31',
2313
+ 'a5a5a5',
2314
+ 'ffc000',
2315
+ '5b9bd5',
2316
+ '70ad47',
2317
+ '0563c1',
2318
+ '954f72'
2319
+ ];
2320
+ const themeColorNames = [
2321
+ 'lt1',
2322
+ 'dk1',
2323
+ 'lt2',
2324
+ 'dk2',
2325
+ 'accent1',
2326
+ 'accent2',
2327
+ 'accent3',
2328
+ 'accent4',
2329
+ 'accent5',
2330
+ 'accent6',
2331
+ 'hlink',
2332
+ 'folHlink'
2333
+ ];
2334
+ const defaultIndexedColors = [
2335
+ '000000',
2336
+ 'ffffff',
2337
+ 'ff0000',
2338
+ '00ff00',
2339
+ '0000ff',
2340
+ 'ffff00',
2341
+ 'ff00ff',
2342
+ '00ffff',
2343
+ '000000',
2344
+ 'ffffff',
2345
+ 'ff0000',
2346
+ '00ff00',
2347
+ '0000ff',
2348
+ 'ffff00',
2349
+ 'ff00ff',
2350
+ '00ffff',
2351
+ '800000',
2352
+ '008000',
2353
+ '000080',
2354
+ '808000',
2355
+ '800080',
2356
+ '008080',
2357
+ 'c0c0c0',
2358
+ '808080',
2359
+ '9999ff',
2360
+ '993366',
2361
+ 'ffffcc',
2362
+ 'ccffff',
2363
+ '660066',
2364
+ 'ff8080',
2365
+ '0066cc',
2366
+ 'ccccff',
2367
+ '000080',
2368
+ 'ff00ff',
2369
+ 'ffff00',
2370
+ '00ffff',
2371
+ '800080',
2372
+ '800000',
2373
+ '008080',
2374
+ '0000ff',
2375
+ '00ccff',
2376
+ 'ccffff',
2377
+ 'ccffcc',
2378
+ 'ffff99',
2379
+ '99ccff',
2380
+ 'ff99cc',
2381
+ 'cc99ff',
2382
+ 'ffcc99',
2383
+ '3366ff',
2384
+ '33cccc',
2385
+ '99cc00',
2386
+ 'ffcc00',
2387
+ 'ff9900',
2388
+ 'ff6600',
2389
+ '666699',
2390
+ '969696',
2391
+ '003366',
2392
+ '339966',
2393
+ '003300',
2394
+ '333300',
2395
+ '993300',
2396
+ '993366',
2397
+ '333399',
2398
+ '333333'
2399
+ ];
2400
+ function createXlsxColorResolver(styles, theme) {
2401
+ return {
2402
+ indexed: styles ? readIndexedColors(styles) : defaultIndexedColors,
2403
+ theme: readThemeColors(theme)
2404
+ };
2405
+ }
2406
+ function resolveXlsxColor(element, resolver) {
2407
+ if (!element) return;
2408
+ const direct = normalizedHexColor(attribute(element, 'rgb'));
2409
+ const themeIndex = boundedInteger(attribute(element, 'theme'), 11);
2410
+ const indexed = boundedInteger(attribute(element, 'indexed'), 65535);
2411
+ const automatic = booleanAttribute(element, 'auto');
2412
+ const source = direct ?? (null === themeIndex ? void 0 : resolver.theme[themeIndex]) ?? (null === indexed ? void 0 : resolver.indexed[indexed]) ?? (automatic ? '000000' : void 0);
2413
+ if (!source) return;
2414
+ const tint = Number(attribute(element, 'tint'));
2415
+ return `#${Number.isFinite(tint) && tint >= -1 && tint <= 1 ? tintXlsxColor(source, tint) : source}`;
2416
+ }
2417
+ function readThemeColors(theme) {
2418
+ if (!theme) return defaultThemeColors;
2419
+ const scheme = firstDescendant(theme, 'clrScheme');
2420
+ if (!scheme) return defaultThemeColors;
2421
+ return themeColorNames.map((name, index)=>{
2422
+ const entry = directChild(scheme, name);
2423
+ const color = entry ? drawingColor(directChildren(entry)[0]) : void 0;
2424
+ return color ?? defaultThemeColors[index];
2425
+ });
2426
+ }
2427
+ function readIndexedColors(styles) {
2428
+ const indexed = firstDescendant(styles, 'indexedColors');
2429
+ if (!indexed) return defaultIndexedColors;
2430
+ const colors = directChildren(indexed, 'rgbColor').map((element)=>normalizedHexColor(attribute(element, 'rgb')));
2431
+ return colors.every(Boolean) ? colors : defaultIndexedColors;
2432
+ }
2433
+ function drawingColor(element) {
2434
+ if (!element) return;
2435
+ return normalizedHexColor('sysClr' === element.localName ? attribute(element, 'lastClr') : attribute(element, 'val'));
2436
+ }
2437
+ function tintXlsxColor(color, tint) {
2438
+ const [hue, saturation, lightness] = rgbToHsl([
2439
+ 0,
2440
+ 2,
2441
+ 4
2442
+ ].map((offset)=>Number.parseInt(color.slice(offset, offset + 2), 16) / 255));
2443
+ const tintedLightness = tint < 0 ? lightness * (1 + tint) : 1 - (1 - lightness) * (1 - tint);
2444
+ return hslToRgb(hue, saturation, tintedLightness).map((channel)=>Math.round(255 * channel)).map((channel)=>channel.toString(16).padStart(2, '0')).join('');
2445
+ }
2446
+ function rgbToHsl([red, green, blue]) {
2447
+ const maximum = Math.max(red, green, blue);
2448
+ const minimum = Math.min(red, green, blue);
2449
+ const delta = maximum - minimum;
2450
+ const lightness = (maximum + minimum) / 2;
2451
+ if (0 === delta) return [
2452
+ 0,
2453
+ 0,
2454
+ lightness
2455
+ ];
2456
+ const saturation = delta / (1 - Math.abs(2 * lightness - 1));
2457
+ const hue = maximum === red ? ((green - blue) / delta + (green < blue ? 6 : 0)) / 6 : maximum === green ? ((blue - red) / delta + 2) / 6 : ((red - green) / delta + 4) / 6;
2458
+ return [
2459
+ hue,
2460
+ saturation,
2461
+ lightness
2462
+ ];
2463
+ }
2464
+ function hslToRgb(hue, saturation, lightness) {
2465
+ if (0 === saturation) return [
2466
+ lightness,
2467
+ lightness,
2468
+ lightness
2469
+ ];
2470
+ const chroma = 2 * saturation * (lightness < 0.5 ? lightness : 1 - lightness);
2471
+ const minimum = lightness - chroma / 2;
2472
+ const channels = [
2473
+ minimum,
2474
+ minimum,
2475
+ minimum
2476
+ ];
2477
+ const sector = 6 * hue;
2478
+ switch(Math.floor(sector)){
2479
+ case 0:
2480
+ case 6:
2481
+ channels[0] += chroma;
2482
+ channels[1] += chroma * sector;
2483
+ break;
2484
+ case 1:
2485
+ channels[0] += chroma * (2 - sector);
2486
+ channels[1] += chroma;
2487
+ break;
2488
+ case 2:
2489
+ channels[1] += chroma;
2490
+ channels[2] += chroma * (sector - 2);
2491
+ break;
2492
+ case 3:
2493
+ channels[1] += chroma * (4 - sector);
2494
+ channels[2] += chroma;
2495
+ break;
2496
+ case 4:
2497
+ channels[0] += chroma * (sector - 4);
2498
+ channels[2] += chroma;
2499
+ break;
2500
+ case 5:
2501
+ channels[0] += chroma;
2502
+ channels[2] += chroma * (6 - sector);
2503
+ break;
2504
+ }
2505
+ return channels;
2506
+ }
2507
+ function normalizedHexColor(value) {
2508
+ if (!value || !/^[0-9a-f]{6,8}$/i.test(value)) return;
2509
+ return value.slice(-6).toLowerCase();
2510
+ }
2511
+ function boundedInteger(value, maximum) {
2512
+ if (null === value || !/^\d+$/.test(value)) return null;
2513
+ const parsed = Number(value);
2514
+ return Number.isSafeInteger(parsed) && parsed <= maximum ? parsed : null;
2515
+ }
2516
+ function booleanAttribute(element, name) {
2517
+ const value = attribute(element, name)?.trim().toLowerCase();
2518
+ return '1' === value || 'true' === value || 'on' === value;
2519
+ }
2520
+ const THEME_COLOR_NAMES = [
2521
+ 'lt1',
2522
+ 'dk1',
2523
+ 'lt2',
2524
+ 'dk2',
2525
+ 'accent1',
2526
+ 'accent2',
2527
+ 'accent3',
2528
+ 'accent4',
2529
+ 'accent5',
2530
+ 'accent6',
2531
+ 'hlink',
2532
+ 'folHlink'
2533
+ ];
2534
+ const MAX_INDEXED_COLOR = 255;
2535
+ function readXlsxSemanticColorOrigin(element, colors) {
2536
+ if (!element || attribute(element, 'rgb')) return;
2537
+ const renderedColor = resolveXlsxColor(element, colors);
2538
+ if (!renderedColor) return;
2539
+ const tint = boundedTint(attribute(element, 'tint'));
2540
+ const theme = work_xlsx_cell_style_origin_boundedInteger(attribute(element, 'theme'), THEME_COLOR_NAMES.length - 1);
2541
+ if (null !== theme && colors.theme[theme]) return {
2542
+ kind: 'theme',
2543
+ baseColor: `#${colors.theme[theme]}`,
2544
+ index: theme,
2545
+ renderedColor,
2546
+ ...null === tint ? {} : {
2547
+ tint
2548
+ }
2549
+ };
2550
+ const indexed = work_xlsx_cell_style_origin_boundedInteger(attribute(element, 'indexed'), MAX_INDEXED_COLOR);
2551
+ if (null !== indexed && colors.indexed[indexed]) return {
2552
+ kind: 'indexed',
2553
+ baseColor: `#${colors.indexed[indexed]}`,
2554
+ index: indexed,
2555
+ renderedColor,
2556
+ ...null === tint ? {} : {
2557
+ tint
2558
+ }
2559
+ };
2560
+ if (xlsxBooleanAttribute(element, 'auto')) return {
2561
+ kind: 'automatic',
2562
+ baseColor: '#000000',
2563
+ renderedColor,
2564
+ ...null === tint ? {} : {
2565
+ tint
2566
+ }
2567
+ };
2568
+ }
2569
+ function withXlsxCellStyleOrigin(cell, origin) {
2570
+ return origin && xlsxCellStyleOriginHasValues(origin) ? {
2571
+ ...cell,
2572
+ a3sXlsxStyleOrigin: origin
2573
+ } : cell;
2574
+ }
2575
+ function xlsxCellStyleOrigin(cell) {
2576
+ const candidate = cell?.a3sXlsxStyleOrigin;
2577
+ if (!work_xlsx_cell_style_origin_isRecord(candidate)) return;
2578
+ const fontColor = normalizeXlsxSemanticColorOrigin(candidate.fontColor);
2579
+ const fillColor = normalizeXlsxSemanticColorOrigin(candidate.fillColor);
2580
+ const borderColors = normalizedBorderColors(candidate.borderColors);
2581
+ const origin = {
2582
+ ...fontColor ? {
2583
+ fontColor
2584
+ } : {},
2585
+ ...fillColor ? {
2586
+ fillColor
2587
+ } : {},
2588
+ ...borderColors ? {
2589
+ borderColors
2590
+ } : {}
2591
+ };
2592
+ return xlsxCellStyleOriginHasValues(origin) ? origin : void 0;
2593
+ }
2594
+ function xlsxSemanticColorMatchesValue(origin, value) {
2595
+ return work_xlsx_cell_style_origin_normalizedColor(value) === origin.renderedColor.toLowerCase();
2596
+ }
2597
+ function xlsxColorElementMatchesOrigin(element, origin) {
2598
+ if (!element || attribute(element, 'rgb')) return false;
2599
+ if ('theme' === origin.kind) {
2600
+ if (attribute(element, 'theme') !== String(origin.index)) return false;
2601
+ } else if ('indexed' === origin.kind) {
2602
+ if (attribute(element, 'indexed') !== String(origin.index)) return false;
2603
+ } else if (!xlsxBooleanAttribute(element, 'auto')) return false;
2604
+ const tint = boundedTint(attribute(element, 'tint'));
2605
+ return tint === (origin.tint ?? null);
2606
+ }
2607
+ function applyXlsxSemanticColorOrigin(element, origin) {
2608
+ for (const name of [
2609
+ 'rgb',
2610
+ 'theme',
2611
+ 'indexed',
2612
+ 'auto',
2613
+ 'tint'
2614
+ ])element.removeAttribute(name);
2615
+ if ('theme' === origin.kind) element.setAttribute('theme', String(origin.index));
2616
+ else if ('indexed' === origin.kind) element.setAttribute('indexed', String(origin.index));
2617
+ else element.setAttribute('auto', '1');
2618
+ if (void 0 !== origin.tint) element.setAttribute('tint', String(origin.tint));
2619
+ }
2620
+ function xlsxSemanticColorOriginKey(origin) {
2621
+ return origin ? `${origin.kind}:${'index' in origin ? origin.index : ''}:${origin.baseColor}:${origin.renderedColor}:${origin.tint ?? ''}` : '';
2622
+ }
2623
+ function xlsxSemanticColorOriginSupported(origin, palette) {
2624
+ if ('automatic' === origin.kind) return true;
2625
+ return palette?.[origin.kind].get(origin.index)?.toLowerCase() === origin.baseColor.toLowerCase();
2626
+ }
2627
+ function prepareXlsxSemanticPalette(styles, theme, origins) {
2628
+ const candidates = semanticPaletteCandidates(origins);
2629
+ const supportedTheme = new Map();
2630
+ let themeChanged = false;
2631
+ const scheme = theme ? firstDescendant(theme, 'clrScheme') : void 0;
2632
+ for (const [index, color] of candidates.theme){
2633
+ const name = THEME_COLOR_NAMES[index];
2634
+ const entry = name && scheme ? directChild(scheme, name) : void 0;
2635
+ if (entry) {
2636
+ themeChanged = writeThemeColor(entry, color) || themeChanged;
2637
+ supportedTheme.set(index, color);
2638
+ }
2639
+ }
2640
+ const supportedIndexed = new Map();
2641
+ let stylesChanged = false;
2642
+ if (candidates.indexed.size) {
2643
+ const colors = ensureXlsxStyleCollection(styles, 'colors', [
2644
+ 'extLst'
2645
+ ]);
2646
+ let indexedColors = directChild(colors, 'indexedColors');
2647
+ if (!indexedColors) {
2648
+ indexedColors = styles.createElementNS(styles.documentElement.namespaceURI, 'indexedColors');
2649
+ colors.prepend(indexedColors);
2650
+ stylesChanged = true;
2651
+ }
2652
+ const resolver = createXlsxColorResolver(styles, theme);
2653
+ const highestIndex = Math.max(...candidates.indexed.keys());
2654
+ while(directChildren(indexedColors, 'rgbColor').length <= highestIndex){
2655
+ const index = directChildren(indexedColors, 'rgbColor').length;
2656
+ const element = styles.createElementNS(styles.documentElement.namespaceURI, 'rgbColor');
2657
+ element.setAttribute('rgb', `FF${(resolver.indexed[index] ?? '000000').toUpperCase()}`);
2658
+ indexedColors.append(element);
2659
+ stylesChanged = true;
2660
+ }
2661
+ const entries = directChildren(indexedColors, 'rgbColor');
2662
+ for (const [index, color] of candidates.indexed){
2663
+ const expected = `FF${color.slice(1).toUpperCase()}`;
2664
+ const entry = entries[index];
2665
+ if (entry) {
2666
+ if (attribute(entry, 'rgb')?.toUpperCase() !== expected) {
2667
+ entry.setAttribute('rgb', expected);
2668
+ stylesChanged = true;
2669
+ }
2670
+ supportedIndexed.set(index, color);
2671
+ }
2672
+ }
2673
+ }
2674
+ return {
2675
+ palette: {
2676
+ indexed: supportedIndexed,
2677
+ theme: supportedTheme
2678
+ },
2679
+ stylesChanged,
2680
+ themeChanged
2681
+ };
2682
+ }
2683
+ function semanticPaletteCandidates(origins) {
2684
+ const theme = new Map();
2685
+ const indexed = new Map();
2686
+ const themeConflicts = new Set();
2687
+ const indexedConflicts = new Set();
2688
+ for (const origin of origins)for (const color of xlsxCellStyleOriginColors(origin)){
2689
+ if ('automatic' === color.kind) continue;
2690
+ const target = 'theme' === color.kind ? theme : indexed;
2691
+ const conflicts = 'theme' === color.kind ? themeConflicts : indexedConflicts;
2692
+ const current = target.get(color.index);
2693
+ if (current && current.toLowerCase() !== color.baseColor.toLowerCase()) conflicts.add(color.index);
2694
+ else if (!current) target.set(color.index, color.baseColor);
2695
+ }
2696
+ for (const index of themeConflicts)theme.delete(index);
2697
+ for (const index of indexedConflicts)indexed.delete(index);
2698
+ return {
2699
+ indexed,
2700
+ theme
2701
+ };
2702
+ }
2703
+ function xlsxCellStyleOriginColors(origin) {
2704
+ return [
2705
+ origin.fontColor,
2706
+ origin.fillColor,
2707
+ ...Object.values(origin.borderColors ?? {})
2708
+ ].filter((value)=>Boolean(value));
2709
+ }
2710
+ function writeThemeColor(entry, color) {
2711
+ const current = directChildren(entry)[0];
2712
+ if (current?.localName === 'srgbClr' && attribute(current, 'val')?.toLowerCase() === color.slice(1).toLowerCase()) return false;
2713
+ for (const child of directChildren(entry))child.remove();
2714
+ const qualifiedName = entry.prefix ? `${entry.prefix}:srgbClr` : 'srgbClr';
2715
+ const replacement = entry.ownerDocument.createElementNS(entry.namespaceURI, qualifiedName);
2716
+ replacement.setAttribute('val', color.slice(1).toUpperCase());
2717
+ entry.append(replacement);
2718
+ return true;
2719
+ }
2720
+ function normalizedBorderColors(value) {
2721
+ if (!work_xlsx_cell_style_origin_isRecord(value)) return;
2722
+ const result = {};
2723
+ for (const side of [
2724
+ 'bottom',
2725
+ 'diagonal',
2726
+ 'left',
2727
+ 'right',
2728
+ 'top'
2729
+ ]){
2730
+ const color = normalizeXlsxSemanticColorOrigin(value[side]);
2731
+ if (color) result[side] = color;
2732
+ }
2733
+ return Object.keys(result).length ? result : void 0;
2734
+ }
2735
+ function normalizeXlsxSemanticColorOrigin(value) {
2736
+ if (!work_xlsx_cell_style_origin_isRecord(value)) return;
2737
+ const baseColor = work_xlsx_cell_style_origin_normalizedColor(value.baseColor);
2738
+ const renderedColor = work_xlsx_cell_style_origin_normalizedColor(value.renderedColor);
2739
+ const tint = normalizedTint(value.tint);
2740
+ if (!baseColor || !renderedColor || void 0 === tint) return;
2741
+ if ('automatic' === value.kind) return {
2742
+ kind: 'automatic',
2743
+ baseColor,
2744
+ renderedColor,
2745
+ ...null === tint ? {} : {
2746
+ tint
2747
+ }
2748
+ };
2749
+ const maximum = 'theme' === value.kind ? THEME_COLOR_NAMES.length - 1 : MAX_INDEXED_COLOR;
2750
+ const index = boundedNumber(value.index, maximum);
2751
+ if ('theme' !== value.kind && 'indexed' !== value.kind || null === index) return;
2752
+ return {
2753
+ kind: value.kind,
2754
+ baseColor,
2755
+ index,
2756
+ renderedColor,
2757
+ ...null === tint ? {} : {
2758
+ tint
2759
+ }
2760
+ };
2761
+ }
2762
+ function xlsxCellStyleOriginHasValues(origin) {
2763
+ return Boolean(origin.fontColor || origin.fillColor || Object.keys(origin.borderColors ?? {}).length);
2764
+ }
2765
+ function work_xlsx_cell_style_origin_normalizedColor(value) {
2766
+ const rgb = xlsxRgbColor(value);
2767
+ return rgb ? `#${rgb.slice(-6).toLowerCase()}` : null;
2768
+ }
2769
+ function normalizedTint(value) {
2770
+ if (void 0 === value) return null;
2771
+ return 'number' == typeof value && Number.isFinite(value) && value >= -1 && value <= 1 ? value : void 0;
2772
+ }
2773
+ function boundedTint(value) {
2774
+ if (null === value) return null;
2775
+ const tint = Number(value);
2776
+ return Number.isFinite(tint) && tint >= -1 && tint <= 1 ? tint : null;
2777
+ }
2778
+ function work_xlsx_cell_style_origin_boundedInteger(value, maximum) {
2779
+ if (null === value || !/^\d+$/.test(value)) return null;
2780
+ return boundedNumber(Number(value), maximum);
2781
+ }
2782
+ function boundedNumber(value, maximum) {
2783
+ return 'number' == typeof value && Number.isSafeInteger(value) && value >= 0 && value <= maximum ? value : null;
2784
+ }
2785
+ function xlsxBooleanAttribute(element, name) {
2786
+ const value = attribute(element, name)?.trim().toLowerCase();
2787
+ return '1' === value || 'true' === value || 'on' === value;
2788
+ }
2789
+ function work_xlsx_cell_style_origin_isRecord(value) {
2790
+ return 'object' == typeof value && null !== value && !Array.isArray(value);
2791
+ }
2148
2792
  const spreadsheetTextOrientationIds = [
2149
2793
  'horizontal',
2150
2794
  'angleCounterclockwise',
@@ -2309,6 +2953,90 @@ function spreadsheetUnderlineCellValueFromSheetJs(value) {
2309
2953
  if (isSpreadsheetUnderlineStyle(value)) return spreadsheetUnderlineCellValue(value);
2310
2954
  return spreadsheetUnderlineCellValue(spreadsheetUnderlineStyle(value));
2311
2955
  }
2956
+ function hasXlsxDirectFontStyle(cell) {
2957
+ return Boolean(void 0 !== cell.bl || void 0 !== cell.it || void 0 !== cell.un || void 0 !== cell.cl || void 0 !== cell.ff || void 0 !== cell.fs || void 0 !== cell.fc);
2958
+ }
2959
+ function directXlsxFontStyle(cell) {
2960
+ const color = void 0 !== cell.fc ? xlsxRgbColor(cell.fc) : null;
2961
+ return {
2962
+ ...void 0 !== cell.bl ? {
2963
+ bold: 1 === Number(cell.bl)
2964
+ } : {},
2965
+ ...color ? {
2966
+ color
2967
+ } : {},
2968
+ ...void 0 !== cell.it ? {
2969
+ italic: 1 === Number(cell.it)
2970
+ } : {},
2971
+ ...'string' == typeof cell.ff && cell.ff.trim() ? {
2972
+ name: cell.ff.trim()
2973
+ } : {},
2974
+ ...'number' == typeof cell.fs && Number.isFinite(cell.fs) && cell.fs > 0 ? {
2975
+ size: cell.fs
2976
+ } : {},
2977
+ ...void 0 !== cell.cl ? {
2978
+ strike: 1 === Number(cell.cl)
2979
+ } : {},
2980
+ ...void 0 !== cell.un ? {
2981
+ underline: spreadsheetUnderlineStyle(cell.un)
2982
+ } : {}
2983
+ };
2984
+ }
2985
+ function directXlsxAlignment(cell) {
2986
+ const alignment = {};
2987
+ if (void 0 !== cell.ht) alignment.horizontal = 0 === Number(cell.ht) ? 'center' : 2 === Number(cell.ht) ? 'right' : 'left';
2988
+ if (void 0 !== cell.vt) alignment.vertical = 0 === Number(cell.vt) ? 'center' : 1 === Number(cell.vt) ? 'top' : 'bottom';
2989
+ if (void 0 !== cell.tb) alignment.wrapText = '2' === cell.tb;
2990
+ const rotation = spreadsheetTextOrientationXlsxValueFromCell(cell);
2991
+ if (null !== rotation) alignment.textRotation = rotation;
2992
+ return Object.keys(alignment).length ? alignment : null;
2993
+ }
2994
+ function xlsxStyleCollectionIndex(collection, childName, value) {
2995
+ const index = nonNegativeInteger(value) ?? 0;
2996
+ return directChildren(collection, childName)[index] ? index : 0;
2997
+ }
2998
+ function xlsxColorMatches(element, value, colors, fallback) {
2999
+ const rgb = xlsxRgbColor(value);
3000
+ const resolved = resolveXlsxColor(element, colors) ?? fallback;
3001
+ return Boolean(rgb && resolved && `#${rgb.slice(-6).toLowerCase()}` === resolved.toLowerCase());
3002
+ }
3003
+ function xlsxToggleEnabled(element) {
3004
+ if (!element) return false;
3005
+ const value = attribute(element, 'val')?.trim().toLowerCase();
3006
+ return '0' !== value && 'false' !== value && 'off' !== value;
3007
+ }
3008
+ function xlsxUnderlineStyle(element) {
3009
+ return element ? spreadsheetUnderlineStyle(spreadsheetUnderlineCellValueFromXlsx(attribute(element, 'val'))) : 'none';
3010
+ }
3011
+ function xlsxBorderLineMatches(element, line, colors, semanticColor) {
3012
+ const style = element ? attribute(element, 'style') : null;
3013
+ if (!line) return !style;
3014
+ return style === line.style && (semanticColor ? xlsxColorElementMatchesOrigin(element ? directChild(element, 'color') : void 0, semanticColor) : xlsxColorMatches(element ? directChild(element, 'color') : void 0, line.color, colors, '#000000'));
3015
+ }
3016
+ function activeXlsxSemanticColorOrigin(origin, value, palette) {
3017
+ return origin && xlsxSemanticColorMatchesValue(origin, value) && xlsxSemanticColorOriginSupported(origin, palette) ? origin : void 0;
3018
+ }
3019
+ function work_xlsx_cell_style_values_xlsxBooleanAttribute(element, name) {
3020
+ if (!element) return false;
3021
+ const value = attribute(element, name)?.trim().toLowerCase();
3022
+ return '1' === value || 'true' === value || 'on' === value;
3023
+ }
3024
+ function xlsxAlignmentMatches(xf, style) {
3025
+ const alignment = directChild(xf, 'alignment');
3026
+ if (void 0 !== style.horizontal && attribute(alignment ?? xf, 'horizontal') !== style.horizontal) return false;
3027
+ if (void 0 !== style.vertical && attribute(alignment ?? xf, 'vertical') !== style.vertical) return false;
3028
+ if (void 0 !== style.wrapText && (!alignment || null === attribute(alignment, 'wrapText') || work_xlsx_cell_style_values_xlsxBooleanAttribute(alignment, 'wrapText') !== style.wrapText)) return false;
3029
+ if (void 0 !== style.textRotation) {
3030
+ const rotation = nonNegativeInteger(alignment ? attribute(alignment, 'textRotation') : null);
3031
+ if (rotation !== style.textRotation) return false;
3032
+ }
3033
+ return true;
3034
+ }
3035
+ function nonNegativeInteger(value) {
3036
+ if (null === value || !/^\d+$/.test(value)) return null;
3037
+ const parsed = Number(value);
3038
+ return Number.isSafeInteger(parsed) ? parsed : null;
3039
+ }
2312
3040
  const SPREADSHEET_CONDITIONAL_COMPARISON_OPERATORS = [
2313
3041
  'greaterThan',
2314
3042
  'greaterThanOrEqual',
@@ -2604,7 +3332,7 @@ function spreadsheetConditionalIconAppearance(icon) {
2604
3332
  ];
2605
3333
  return {
2606
3334
  glyph: glyphs[index],
2607
- color: icon.iconSet.includes('Gray') ? '#606a78' : palette(icon.count)[index],
3335
+ color: icon.iconSet.includes('Gray') ? '#606a78' : work_spreadsheet_conditional_icons_palette(icon.count)[index],
2608
3336
  label
2609
3337
  };
2610
3338
  }
@@ -2615,7 +3343,7 @@ function spreadsheetConditionalIconAppearance(icon) {
2615
3343
  };
2616
3344
  if (icon.iconSet.includes('TrafficLights')) return {
2617
3345
  glyph: '3TrafficLights2' === icon.iconSet ? '◉' : '●',
2618
- color: palette(icon.count)[index],
3346
+ color: work_spreadsheet_conditional_icons_palette(icon.count)[index],
2619
3347
  label
2620
3348
  };
2621
3349
  if ('3Signs' === icon.iconSet) return {
@@ -2709,7 +3437,7 @@ function normalizeThreshold(value) {
2709
3437
  gte: false !== source.gte
2710
3438
  } : null;
2711
3439
  }
2712
- function palette(count) {
3440
+ function work_spreadsheet_conditional_icons_palette(count) {
2713
3441
  if (3 === count) return COLOR_3;
2714
3442
  if (4 === count) return COLOR_4;
2715
3443
  return COLOR_5;
@@ -2761,25 +3489,25 @@ function effectiveSpreadsheetPageSetup(pageSetup) {
2761
3489
  return {
2762
3490
  paperSize: normalizeSpreadsheetPaperSize(pageSetup?.paperSize),
2763
3491
  orientation: pageSetup?.orientation === 'portrait' ? 'portrait' : 'landscape',
2764
- scale: boundedInteger(pageSetup?.scale, 10, 400, 100),
3492
+ scale: work_spreadsheet_page_setup_boundedInteger(pageSetup?.scale, 10, 400, 100),
2765
3493
  fitToPage: Boolean(pageSetup?.fitToPage),
2766
- fitToWidth: boundedInteger(pageSetup?.fitToWidth, 0, 32767, 1),
2767
- fitToHeight: boundedInteger(pageSetup?.fitToHeight, 0, 32767, 0),
3494
+ fitToWidth: work_spreadsheet_page_setup_boundedInteger(pageSetup?.fitToWidth, 0, 32767, 1),
3495
+ fitToHeight: work_spreadsheet_page_setup_boundedInteger(pageSetup?.fitToHeight, 0, 32767, 0),
2768
3496
  horizontalCentered: Boolean(pageSetup?.horizontalCentered),
2769
3497
  verticalCentered: Boolean(pageSetup?.verticalCentered),
2770
3498
  header: effectiveSpreadsheetHeaderFooterSections(pageSetup?.header),
2771
3499
  footer: effectiveSpreadsheetHeaderFooterSections(pageSetup?.footer),
2772
- pageNumberStart: boundedInteger(pageSetup?.pageNumberStart, 1, 32767, 1),
3500
+ pageNumberStart: work_spreadsheet_page_setup_boundedInteger(pageSetup?.pageNumberStart, 1, 32767, 1),
2773
3501
  pageOrder: pageSetup?.pageOrder === 'downThenOver' ? 'downThenOver' : 'overThenDown',
2774
3502
  scaleWithDocument: pageSetup?.scaleWithDocument !== false,
2775
3503
  alignWithMargins: pageSetup?.alignWithMargins !== false,
2776
3504
  margins: {
2777
- top: boundedNumber(pageSetup?.margins?.top, 0, 100, DEFAULT_MARGINS.top),
2778
- right: boundedNumber(pageSetup?.margins?.right, 0, 100, DEFAULT_MARGINS.right),
2779
- bottom: boundedNumber(pageSetup?.margins?.bottom, 0, 100, DEFAULT_MARGINS.bottom),
2780
- left: boundedNumber(pageSetup?.margins?.left, 0, 100, DEFAULT_MARGINS.left),
2781
- header: boundedNumber(pageSetup?.margins?.header, 0, 100, DEFAULT_MARGINS.header),
2782
- footer: boundedNumber(pageSetup?.margins?.footer, 0, 100, DEFAULT_MARGINS.footer)
3505
+ top: work_spreadsheet_page_setup_boundedNumber(pageSetup?.margins?.top, 0, 100, DEFAULT_MARGINS.top),
3506
+ right: work_spreadsheet_page_setup_boundedNumber(pageSetup?.margins?.right, 0, 100, DEFAULT_MARGINS.right),
3507
+ bottom: work_spreadsheet_page_setup_boundedNumber(pageSetup?.margins?.bottom, 0, 100, DEFAULT_MARGINS.bottom),
3508
+ left: work_spreadsheet_page_setup_boundedNumber(pageSetup?.margins?.left, 0, 100, DEFAULT_MARGINS.left),
3509
+ header: work_spreadsheet_page_setup_boundedNumber(pageSetup?.margins?.header, 0, 100, DEFAULT_MARGINS.header),
3510
+ footer: work_spreadsheet_page_setup_boundedNumber(pageSetup?.margins?.footer, 0, 100, DEFAULT_MARGINS.footer)
2783
3511
  }
2784
3512
  };
2785
3513
  }
@@ -2796,10 +3524,340 @@ function normalizeSpreadsheetPaperSize(value) {
2796
3524
  return 'a4';
2797
3525
  }
2798
3526
  }
2799
- function boundedInteger(value, minimum, maximum, fallback) {
2800
- return Math.trunc(boundedNumber(value, minimum, maximum, fallback));
3527
+ function work_spreadsheet_page_setup_boundedInteger(value, minimum, maximum, fallback) {
3528
+ return Math.trunc(work_spreadsheet_page_setup_boundedNumber(value, minimum, maximum, fallback));
2801
3529
  }
2802
- function boundedNumber(value, minimum, maximum, fallback) {
3530
+ function work_spreadsheet_page_setup_boundedNumber(value, minimum, maximum, fallback) {
2803
3531
  return 'number' == typeof value && Number.isFinite(value) && value >= minimum && value <= maximum ? value : fallback;
2804
3532
  }
2805
- export { DEFAULT_PROTECTION_HINT, SPREADSHEET_CONDITIONAL_COMPARISON_OPERATORS, SPREADSHEET_CONDITIONAL_ICON_SETS, attachSpreadsheetShownCommentCells, createWorkOfficeSpreadsheetCollaborationBinding as createOfficeSpreadsheetCollaborationBinding, defaultSpreadsheetColorScaleThresholds, defaultSpreadsheetConditionalIconThresholds, defaultSpreadsheetDataBarOptions, drawSpreadsheetConditionalIcon, editableRangeCellCount, editableRangeRequiresCredentials, effectiveSpreadsheetPageSetup, freezeImportedSpreadsheetCell, importedSheetProtectionAuthority, initializeWorkOfficeSpreadsheetCollaboration as initializeOfficeSpreadsheetCollaboration, isSpreadsheetConditionalComparisonOperator, isSpreadsheetConditionalIconSetName, isSpreadsheetTextOrientationId, isSpreadsheetUnderlineStyle, normalizeSheetProtectionAuthority, normalizeSpreadsheetConditionalIconSetFormat, normalizeSpreadsheetConditionalVisualOptions, normalizeSpreadsheetDateValidationBoundary, normalizeSpreadsheetPaperSize, protectedSheetCount, readWorkOfficeSpreadsheetCollaboration as readOfficeSpreadsheetCollaboration, registerDerivedSpreadsheetMatrix, registerImportedSpreadsheetMatrix, replaceWorkOfficeSpreadsheetCollaboration as replaceOfficeSpreadsheetCollaboration, sameSpreadsheetHistoryValue, sheetHasProtectionState, sheetProtectionAuthority, spreadsheetCellValueWithDiagonalBorder, spreadsheetConditionalComparisonNeedsUpperValue, spreadsheetConditionalIconForValue, spreadsheetConditionalIconSetCount, spreadsheetConditionalThresholdValue, spreadsheetConditionalThresholdsEqual, spreadsheetDateValidationFormula, spreadsheetDiagonalBorderFromCellValue, spreadsheetExplicitTextOrientationFromCell, spreadsheetMatrixProfile, spreadsheetProtectionKey, spreadsheetTextOrientationCellStyle, spreadsheetTextOrientationChoiceFromCell, spreadsheetTextOrientationFromAngle, spreadsheetTextOrientationFromCell, spreadsheetTextOrientationFromChoice, spreadsheetTextOrientationFromXlsx, spreadsheetTextOrientationXlsxValueFromCell, spreadsheetUnderlineCellValue, spreadsheetUnderlineCellValueFromSheetJs, spreadsheetUnderlineCellValueFromXlsx, spreadsheetUnderlineStyle, spreadsheetVisibleTextRotationFromCell, unlockedCellCount, withEditableRange, withSheetProtection, withSheetSelectionPermissions, withoutEditableRange };
3533
+ const MAX_XLSX_RICH_TEXT_CELL_CHARACTERS = 32767;
3534
+ const MAX_XLSX_RICH_TEXT_RUNS_PER_CELL = 512;
3535
+ const MAX_XLSX_RICH_TEXT_CELLS = 10000;
3536
+ const MAX_XLSX_RICH_TEXT_RUNS = 100000;
3537
+ const MAX_XLSX_SHARED_RICH_TEXT_ITEMS = 10000;
3538
+ const MAX_XLSX_FONT_NAME_CHARACTERS = 128;
3539
+ const MAX_XLSX_FONT_SIZE = 409;
3540
+ function createXlsxRichTextReadContext(options) {
3541
+ const colors = createXlsxColorResolver(options.styles, options.theme);
3542
+ const sharedStrings = readRichSharedStrings(options.sharedStrings, colors);
3543
+ return {
3544
+ colors,
3545
+ hasRichSharedStrings: sharedStrings.size > 0,
3546
+ remainingCells: MAX_XLSX_RICH_TEXT_CELLS,
3547
+ remainingRuns: MAX_XLSX_RICH_TEXT_RUNS,
3548
+ sharedStrings
3549
+ };
3550
+ }
3551
+ function readXlsxRichTextCells(worksheet, context) {
3552
+ const result = [];
3553
+ const seen = new Set();
3554
+ for (const element of descendants(worksheet, 'c')){
3555
+ if (context.remainingCells <= 0 || context.remainingRuns <= 0) break;
3556
+ if (directChild(element, 'f')) continue;
3557
+ const reference = attribute(element, 'r');
3558
+ if (!reference) continue;
3559
+ const coordinate = decodeXlsxCellAddress(reference);
3560
+ if (!coordinate || coordinate.column > 16383 || coordinate.row > 1048575 || seen.has(reference)) continue;
3561
+ seen.add(reference);
3562
+ const type = attribute(element, 't');
3563
+ let source = null;
3564
+ if ('s' === type) {
3565
+ const index = work_xlsx_rich_text_nonNegativeInteger(directChild(element, 'v')?.textContent);
3566
+ source = null === index ? null : context.sharedStrings.get(index) ?? null;
3567
+ } else if ('inlineStr' === type) {
3568
+ const inlineString = directChild(element, 'is');
3569
+ source = inlineString ? readRichTextRuns(inlineString, context.colors) : null;
3570
+ }
3571
+ if (!source?.length || source.length > context.remainingRuns) continue;
3572
+ const runs = source.map((run)=>({
3573
+ ...run
3574
+ }));
3575
+ const text = runs.map((run)=>run.v).join('');
3576
+ if (text && !(text.length > MAX_XLSX_RICH_TEXT_CELL_CHARACTERS)) {
3577
+ context.remainingCells -= 1;
3578
+ context.remainingRuns -= runs.length;
3579
+ result.push({
3580
+ ...coordinate,
3581
+ runs,
3582
+ text
3583
+ });
3584
+ }
3585
+ }
3586
+ return result;
3587
+ }
3588
+ function applyImportedXlsxRichText(cell, richText) {
3589
+ if (!richText) return cell;
3590
+ const next = {
3591
+ ...cell,
3592
+ ct: {
3593
+ ...cell.ct,
3594
+ s: richText.runs.map((run)=>({
3595
+ ...run
3596
+ })),
3597
+ t: 'inlineStr'
3598
+ },
3599
+ v: richText.text
3600
+ };
3601
+ delete next.m;
3602
+ return next;
3603
+ }
3604
+ function patchSpreadsheetRichTextFontRuns(cell, patch) {
3605
+ if (!fontPatchHasValues(patch) || cell.ct?.t !== 'inlineStr') return cell;
3606
+ const source = cell.ct.s;
3607
+ if (!Array.isArray(source) || !source.length || source.some((run)=>!work_xlsx_rich_text_isRecord(run) || 'string' != typeof run.v || !validXmlText(run.v))) return cell;
3608
+ const normalizedColor = void 0 === patch.fontColor ? void 0 : normalizedColorValue(patch.fontColor);
3609
+ const runs = source.map((run)=>{
3610
+ const next = {
3611
+ ...run
3612
+ };
3613
+ if (void 0 !== patch.fontFamily) next.ff = patch.fontFamily.trim();
3614
+ if (void 0 !== patch.fontSize) next.fs = patch.fontSize;
3615
+ if (void 0 !== normalizedColor) {
3616
+ next.fc = normalizedColor;
3617
+ delete next.a3sXlsxColorOrigin;
3618
+ }
3619
+ if (void 0 !== patch.bold) next.bl = patch.bold ? 1 : 0;
3620
+ if (void 0 !== patch.italic) next.it = patch.italic ? 1 : 0;
3621
+ if (void 0 !== patch.underline) next.un = spreadsheetUnderlineCellValue(patch.underline);
3622
+ if (void 0 !== patch.strike) next.cl = patch.strike ? 1 : 0;
3623
+ return next;
3624
+ });
3625
+ return {
3626
+ ...cell,
3627
+ ct: {
3628
+ ...cell.ct,
3629
+ s: runs
3630
+ }
3631
+ };
3632
+ }
3633
+ function xlsxRichTextCellText(cell) {
3634
+ return normalizeRichTextCell(cell)?.text ?? null;
3635
+ }
3636
+ function sheetHasXlsxRichTextCells(sheet) {
3637
+ for (const [, row] of spreadsheet_sparse_sparseArrayEntries(sheet.data))for (const [, cell] of spreadsheet_sparse_sparseArrayEntries(row))if (cell && normalizeRichTextCell(cell)) return true;
3638
+ return false;
3639
+ }
3640
+ function xlsxRichTextStyleOrigins(sheet) {
3641
+ const origins = [];
3642
+ for (const [, row] of spreadsheet_sparse_sparseArrayEntries(sheet.data))for (const [, cell] of spreadsheet_sparse_sparseArrayEntries(row))if (cell) for (const run of normalizeRichTextCell(cell)?.runs ?? []){
3643
+ const fontColor = normalizeXlsxSemanticColorOrigin(run.a3sXlsxColorOrigin);
3644
+ if (fontColor && run.fc && xlsxSemanticColorMatchesValue(fontColor, run.fc)) origins.push({
3645
+ fontColor
3646
+ });
3647
+ }
3648
+ return origins;
3649
+ }
3650
+ function writeXlsxRichTextCells(worksheet, sheet, semanticPalette) {
3651
+ const elements = new Map(descendants(worksheet, 'c').flatMap((element)=>{
3652
+ const reference = attribute(element, 'r');
3653
+ return reference ? [
3654
+ [
3655
+ reference,
3656
+ element
3657
+ ]
3658
+ ] : [];
3659
+ }));
3660
+ let remainingCells = MAX_XLSX_RICH_TEXT_CELLS;
3661
+ let remainingRuns = MAX_XLSX_RICH_TEXT_RUNS;
3662
+ for (const [row, values] of spreadsheet_sparse_sparseArrayEntries(sheet.data))for (const [column, cell] of spreadsheet_sparse_sparseArrayEntries(values)){
3663
+ if (remainingCells <= 0 || remainingRuns <= 0) return;
3664
+ if (!cell) continue;
3665
+ const richText = normalizeRichTextCell(cell);
3666
+ if (!richText || richText.runs.length > remainingRuns) continue;
3667
+ const element = elements.get(xlsxCellAddress(row, column));
3668
+ if (element) {
3669
+ writeRichTextCell(element, richText, semanticPalette);
3670
+ remainingCells -= 1;
3671
+ remainingRuns -= richText.runs.length;
3672
+ }
3673
+ }
3674
+ }
3675
+ function readRichSharedStrings(document, colors) {
3676
+ if (!document) return new Map();
3677
+ const result = new Map();
3678
+ let parsedRuns = 0;
3679
+ for (const [index, item] of directChildren(document.documentElement, 'si').entries()){
3680
+ if (result.size >= MAX_XLSX_SHARED_RICH_TEXT_ITEMS || parsedRuns >= MAX_XLSX_RICH_TEXT_RUNS) break;
3681
+ const runs = readRichTextRuns(item, colors);
3682
+ if (runs && !(parsedRuns + runs.length > MAX_XLSX_RICH_TEXT_RUNS)) {
3683
+ result.set(index, runs);
3684
+ parsedRuns += runs.length;
3685
+ }
3686
+ }
3687
+ return result;
3688
+ }
3689
+ function readRichTextRuns(container, colors) {
3690
+ const elements = directChildren(container, 'r');
3691
+ if (directChild(container, 't') || !elements.length || elements.length > MAX_XLSX_RICH_TEXT_RUNS_PER_CELL) return null;
3692
+ const runs = [];
3693
+ let characterCount = 0;
3694
+ for (const element of elements){
3695
+ const textElement = directChild(element, 't');
3696
+ if (!textElement || textElement.children.length || 1 !== directChildren(element, 't').length) return null;
3697
+ const value = textElement.textContent ?? '';
3698
+ if (value) {
3699
+ characterCount += value.length;
3700
+ if (characterCount > MAX_XLSX_RICH_TEXT_CELL_CHARACTERS || !validXmlText(value)) return null;
3701
+ runs.push(readRichTextRun(element, value, colors));
3702
+ }
3703
+ }
3704
+ return runs.length ? runs : null;
3705
+ }
3706
+ function readRichTextRun(element, value, colors) {
3707
+ const properties = directChild(element, 'rPr');
3708
+ if (!properties) return {
3709
+ v: value
3710
+ };
3711
+ const run = {
3712
+ v: value
3713
+ };
3714
+ const font = directChild(properties, 'rFont') ?? directChild(properties, 'name');
3715
+ const fontName = attribute(font ?? properties, 'val')?.trim();
3716
+ if (fontName && fontName.length <= MAX_XLSX_FONT_NAME_CHARACTERS) run.ff = fontName;
3717
+ if (work_xlsx_rich_text_xlsxToggleEnabled(directChild(properties, 'b'))) run.bl = 1;
3718
+ if (work_xlsx_rich_text_xlsxToggleEnabled(directChild(properties, 'i'))) run.it = 1;
3719
+ if (work_xlsx_rich_text_xlsxToggleEnabled(directChild(properties, 'strike'))) run.cl = 1;
3720
+ const size = finiteNumber(attribute(directChild(properties, 'sz') ?? properties, 'val'));
3721
+ if (null !== size && size >= 1 && size <= MAX_XLSX_FONT_SIZE) run.fs = size;
3722
+ const underline = directChild(properties, 'u');
3723
+ if (underline) {
3724
+ const value = spreadsheetUnderlineCellValueFromXlsx(attribute(underline, 'val'));
3725
+ if (value) run.un = value;
3726
+ }
3727
+ const colorElement = directChild(properties, 'color');
3728
+ const color = resolveXlsxColor(colorElement, colors);
3729
+ if (color) run.fc = color;
3730
+ const colorOrigin = readXlsxSemanticColorOrigin(colorElement, colors);
3731
+ if (colorOrigin) run.a3sXlsxColorOrigin = colorOrigin;
3732
+ return run;
3733
+ }
3734
+ function normalizeRichTextCell(cell) {
3735
+ if (cell.f || cell.ct?.t !== 'inlineStr' || !Array.isArray(cell.ct.s)) return null;
3736
+ if (!cell.ct.s.length || cell.ct.s.length > MAX_XLSX_RICH_TEXT_RUNS_PER_CELL) return null;
3737
+ const runs = [];
3738
+ let characterCount = 0;
3739
+ for (const candidate of cell.ct.s){
3740
+ const run = normalizeRichTextRun(candidate);
3741
+ if (!run) return null;
3742
+ if (run.v) {
3743
+ characterCount += run.v.length;
3744
+ if (characterCount > MAX_XLSX_RICH_TEXT_CELL_CHARACTERS) return null;
3745
+ runs.push(run);
3746
+ }
3747
+ }
3748
+ const text = runs.map((run)=>run.v).join('');
3749
+ return runs.length && text ? {
3750
+ runs,
3751
+ text
3752
+ } : null;
3753
+ }
3754
+ function normalizeRichTextRun(value) {
3755
+ if (!work_xlsx_rich_text_isRecord(value) || 'string' != typeof value.v || !validXmlText(value.v)) return null;
3756
+ const run = {
3757
+ v: value.v
3758
+ };
3759
+ if (1 === Number(value.bl)) run.bl = 1;
3760
+ else if (0 === Number(value.bl) && void 0 !== value.bl) run.bl = 0;
3761
+ if (1 === Number(value.it)) run.it = 1;
3762
+ else if (0 === Number(value.it) && void 0 !== value.it) run.it = 0;
3763
+ if (1 === Number(value.cl)) run.cl = 1;
3764
+ else if (0 === Number(value.cl) && void 0 !== value.cl) run.cl = 0;
3765
+ if ('string' == typeof value.ff && value.ff.trim() && value.ff.trim().length <= MAX_XLSX_FONT_NAME_CHARACTERS) run.ff = value.ff.trim();
3766
+ if ('number' == typeof value.fs && Number.isFinite(value.fs) && value.fs >= 1 && value.fs <= MAX_XLSX_FONT_SIZE) run.fs = value.fs;
3767
+ const color = normalizedColorValue(value.fc);
3768
+ if (color) run.fc = color;
3769
+ const underline = Number(value.un);
3770
+ if (Number.isSafeInteger(underline) && underline >= 0 && underline <= 4 && void 0 !== value.un) run.un = underline;
3771
+ const colorOrigin = normalizeXlsxSemanticColorOrigin(value.a3sXlsxColorOrigin);
3772
+ if (colorOrigin) run.a3sXlsxColorOrigin = colorOrigin;
3773
+ return run;
3774
+ }
3775
+ function writeRichTextCell(element, richText, semanticPalette) {
3776
+ for (const child of directChildren(element))if ('v' === child.localName || 'is' === child.localName) child.remove();
3777
+ element.setAttribute('t', 'inlineStr');
3778
+ const document = element.ownerDocument;
3779
+ const namespace = document.documentElement.namespaceURI;
3780
+ const inlineString = document.createElementNS(namespace, 'is');
3781
+ for (const run of richText.runs){
3782
+ const runElement = document.createElementNS(namespace, 'r');
3783
+ const properties = writeRichTextRunProperties(document, run, semanticPalette);
3784
+ if (properties) runElement.append(properties);
3785
+ const text = document.createElementNS(namespace, 't');
3786
+ if (/^\s|\s$/.test(run.v)) text.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
3787
+ text.textContent = run.v;
3788
+ runElement.append(text);
3789
+ inlineString.append(runElement);
3790
+ }
3791
+ element.insertBefore(inlineString, directChildren(element).find((child)=>'extLst' === child.localName) ?? null);
3792
+ }
3793
+ function writeRichTextRunProperties(document, run, semanticPalette) {
3794
+ const namespace = document.documentElement.namespaceURI;
3795
+ const properties = document.createElementNS(namespace, 'rPr');
3796
+ const appendValue = (name, value)=>{
3797
+ const element = document.createElementNS(namespace, name);
3798
+ element.setAttribute('val', value);
3799
+ properties.append(element);
3800
+ };
3801
+ const appendToggle = (name, enabled)=>{
3802
+ if (!enabled) return;
3803
+ const element = document.createElementNS(namespace, name);
3804
+ element.setAttribute('val', '1');
3805
+ properties.append(element);
3806
+ };
3807
+ if (run.ff) appendValue('rFont', run.ff);
3808
+ appendToggle('b', 1 === run.bl);
3809
+ appendToggle('i', 1 === run.it);
3810
+ appendToggle('strike', 1 === run.cl);
3811
+ if (run.fc) {
3812
+ const color = document.createElementNS(namespace, 'color');
3813
+ const semanticOrigin = activeXlsxSemanticColorOrigin(normalizeXlsxSemanticColorOrigin(run.a3sXlsxColorOrigin), run.fc, semanticPalette);
3814
+ if (semanticOrigin) applyXlsxSemanticColorOrigin(color, semanticOrigin);
3815
+ else {
3816
+ const rgb = xlsxRgbColor(run.fc);
3817
+ if (rgb) color.setAttribute('rgb', rgb);
3818
+ }
3819
+ if (color.attributes.length) properties.append(color);
3820
+ }
3821
+ if (void 0 !== run.fs) appendValue('sz', String(run.fs));
3822
+ if (void 0 !== run.un && 0 !== run.un) appendValue('u', spreadsheetUnderlineStyle(run.un));
3823
+ return properties.children.length ? properties : null;
3824
+ }
3825
+ function fontPatchHasValues(patch) {
3826
+ return void 0 !== patch.fontFamily || void 0 !== patch.fontSize || void 0 !== patch.fontColor || void 0 !== patch.bold || void 0 !== patch.italic || void 0 !== patch.underline || void 0 !== patch.strike;
3827
+ }
3828
+ function normalizedColorValue(value) {
3829
+ const rgb = xlsxRgbColor(value);
3830
+ return rgb ? `#${rgb.slice(-6).toLowerCase()}` : null;
3831
+ }
3832
+ function work_xlsx_rich_text_xlsxToggleEnabled(element) {
3833
+ if (!element) return false;
3834
+ const value = attribute(element, 'val')?.trim().toLowerCase();
3835
+ return '0' !== value && 'false' !== value && 'off' !== value;
3836
+ }
3837
+ function finiteNumber(value) {
3838
+ if (null === value || !value.trim()) return null;
3839
+ const parsed = Number(value);
3840
+ return Number.isFinite(parsed) ? parsed : null;
3841
+ }
3842
+ function work_xlsx_rich_text_nonNegativeInteger(value) {
3843
+ if (null == value || !/^\d+$/.test(value.trim())) return null;
3844
+ const parsed = Number(value);
3845
+ return Number.isSafeInteger(parsed) ? parsed : null;
3846
+ }
3847
+ function validXmlText(value) {
3848
+ for(let index = 0; index < value.length; index += 1){
3849
+ const code = value.charCodeAt(index);
3850
+ if (0x09 !== code && 0x0a !== code && 0x0d !== code && (!(code >= 0x20) || !(code <= 0xd7ff)) && (!(code >= 0xe000) || !(code <= 0xfffd))) {
3851
+ if (code >= 0xd800 && code <= 0xdbff && index + 1 < value.length && value.charCodeAt(index + 1) >= 0xdc00 && value.charCodeAt(index + 1) <= 0xdfff) {
3852
+ index += 1;
3853
+ continue;
3854
+ }
3855
+ return false;
3856
+ }
3857
+ }
3858
+ return true;
3859
+ }
3860
+ function work_xlsx_rich_text_isRecord(value) {
3861
+ return 'object' == typeof value && null !== value && !Array.isArray(value);
3862
+ }
3863
+ export { DEFAULT_PROTECTION_HINT, SPREADSHEET_CONDITIONAL_COMPARISON_OPERATORS, SPREADSHEET_CONDITIONAL_ICON_SETS, activeXlsxSemanticColorOrigin, applyImportedXlsxRichText, applyXlsxSemanticColorOrigin, attachSpreadsheetShownCommentCells, createWorkOfficeSpreadsheetCollaborationBinding as createOfficeSpreadsheetCollaborationBinding, createXlsxColorResolver, createXlsxRichTextReadContext, defaultSpreadsheetColorScaleThresholds, defaultSpreadsheetConditionalIconThresholds, defaultSpreadsheetDataBarOptions, defaultXlsxBorder, defaultXlsxFill, directXlsxAlignment, directXlsxFontStyle, drawSpreadsheetConditionalIcon, editableRangeCellCount, editableRangeRequiresCredentials, effectiveSpreadsheetPageSetup, ensureXlsxStyleCollection, freezeImportedSpreadsheetCell, hasXlsxDirectFontStyle, importedSheetProtectionAuthority, initializeWorkOfficeSpreadsheetCollaboration as initializeOfficeSpreadsheetCollaboration, isSpreadsheetConditionalComparisonOperator, isSpreadsheetConditionalIconSetName, isSpreadsheetTextOrientationId, isSpreadsheetUnderlineStyle, normalizeSheetProtectionAuthority, normalizeSpreadsheetConditionalIconSetFormat, normalizeSpreadsheetConditionalVisualOptions, normalizeSpreadsheetDateValidationBoundary, normalizeSpreadsheetPaperSize, patchSpreadsheetRichTextFontRuns, prepareXlsxSemanticPalette, protectedSheetCount, readWorkOfficeSpreadsheetCollaboration as readOfficeSpreadsheetCollaboration, readXlsxRichTextCells, readXlsxSemanticColorOrigin, registerDerivedSpreadsheetMatrix, registerImportedSpreadsheetMatrix, replaceWorkOfficeSpreadsheetCollaboration as replaceOfficeSpreadsheetCollaboration, resolveXlsxColor, sameSpreadsheetHistoryValue, setXlsxBorderLine, setXlsxColorChild, setXlsxToggleChild, setXlsxUnderlineChild, setXlsxValueChild, sheetHasProtectionState, sheetHasXlsxRichTextCells, sheetProtectionAuthority, spreadsheetCellValueWithDiagonalBorder, spreadsheetConditionalComparisonNeedsUpperValue, spreadsheetConditionalIconForValue, spreadsheetConditionalIconSetCount, spreadsheetConditionalThresholdValue, spreadsheetConditionalThresholdsEqual, spreadsheetDateValidationFormula, spreadsheetDiagonalBorderFromCellValue, spreadsheetExplicitTextOrientationFromCell, spreadsheetMatrixProfile, spreadsheetProtectionKey, spreadsheetTextOrientationCellStyle, spreadsheetTextOrientationChoiceFromCell, spreadsheetTextOrientationFromAngle, spreadsheetTextOrientationFromCell, spreadsheetTextOrientationFromChoice, spreadsheetTextOrientationFromXlsx, spreadsheetUnderlineCellValue, spreadsheetUnderlineCellValueFromSheetJs, spreadsheetUnderlineCellValueFromXlsx, spreadsheetUnderlineStyle, spreadsheetVisibleTextRotationFromCell, unlockedCellCount, withEditableRange, withSheetProtection, withSheetSelectionPermissions, withXlsxCellStyleOrigin, withoutEditableRange, work_xlsx_cell_style_values_xlsxBooleanAttribute, writeXlsxAlignment, writeXlsxRichTextCells, xlsxAlignmentMatches, xlsxBorderLineMatches, xlsxCellStyleOrigin, xlsxColorElementMatchesOrigin, xlsxColorMatches, xlsxRgbColor, xlsxRichTextCellText, xlsxRichTextStyleOrigins, xlsxSemanticColorOriginKey, xlsxStyleCollectionIndex, xlsxToggleEnabled, xlsxUnderlineStyle, xlsxWorksheetCellEntries };