@a3s-lab/office 0.25.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/README.md +76 -2
  2. package/dist/0~4595.js +16 -2
  3. package/dist/0~5093.js +463 -201
  4. package/dist/0~6090.js +77 -77
  5. package/dist/{0~2805.js → 0~7043.js} +305 -2
  6. package/dist/0~document-editor.js +2451 -985
  7. package/dist/0~spreadsheet-editor.js +22113 -20117
  8. package/dist/0~work-docx-export.js +492 -10
  9. package/dist/0~work-docx-import.js +171 -98
  10. package/dist/0~work-office-diagnostics.js +198 -4
  11. package/dist/{164.js → 1544.js} +1412 -1055
  12. package/dist/4104.js +145 -29
  13. package/dist/6282.js +1920 -544
  14. package/dist/9424.js +16 -0
  15. package/dist/core.js +1 -1
  16. package/dist/index.js +1 -1
  17. package/dist/internal/features/work/editors/document-command-catalog.d.ts +102 -0
  18. package/dist/internal/features/work/editors/document-font-dialog-model.d.ts +83 -0
  19. package/dist/internal/features/work/editors/document-font-dialog-script-font-model.d.ts +18 -0
  20. package/dist/internal/features/work/editors/document-font-dialog.d.ts +9 -0
  21. package/dist/internal/features/work/editors/document-home-ribbon.d.ts +2 -1
  22. package/dist/internal/features/work/editors/document-page-chrome-editor.d.ts +6 -0
  23. package/dist/internal/features/work/editors/document-page-chrome-ribbon.d.ts +2 -1
  24. package/dist/internal/features/work/editors/document-strike-ribbon.d.ts +7 -0
  25. package/dist/internal/features/work/editors/document-text-case-ribbon.d.ts +4 -0
  26. package/dist/internal/features/work/editors/document-toolbar.d.ts +3 -1
  27. package/dist/internal/features/work/editors/document-underline-ribbon.d.ts +9 -0
  28. package/dist/internal/features/work/editors/document-wps-shortcuts.d.ts +1 -0
  29. package/dist/internal/features/work/editors/spreadsheet-cell-fill-format.d.ts +11 -0
  30. package/dist/internal/features/work/editors/spreadsheet-cell-format.d.ts +2 -1
  31. package/dist/internal/features/work/editors/spreadsheet-command-controller.d.ts +18 -9
  32. package/dist/internal/features/work/editors/spreadsheet-format-cells-dialog-model.d.ts +13 -2
  33. package/dist/internal/features/work/editors/spreadsheet-format-cells-fill-panel.d.ts +13 -0
  34. package/dist/internal/features/work/editors/spreadsheet-format-cells-fill-preview.d.ts +6 -0
  35. package/dist/internal/features/work/editors/spreadsheet-format-painter.d.ts +1 -1
  36. package/dist/internal/features/work/editors/spreadsheet-operation-projection.d.ts +6 -0
  37. package/dist/internal/features/work/editors/spreadsheet-rich-text-dom-selection.d.ts +11 -0
  38. package/dist/internal/features/work/editors/spreadsheet-rich-text-paste.d.ts +22 -0
  39. package/dist/internal/features/work/editors/spreadsheet-rich-text-selection-controller.d.ts +38 -0
  40. package/dist/internal/features/work/editors/spreadsheet-rich-text-selection-format.d.ts +26 -0
  41. package/dist/internal/features/work/editors/work-office-chrome.d.ts +9 -1
  42. package/dist/internal/features/work/work-css-color.d.ts +1 -0
  43. package/dist/internal/features/work/work-document-character-formatting.d.ts +16 -1
  44. package/dist/internal/features/work/work-document-character-position.d.ts +9 -0
  45. package/dist/internal/features/work/work-document-character-scale.d.ts +8 -0
  46. package/dist/internal/features/work/work-document-character-spacing.d.ts +8 -0
  47. package/dist/internal/features/work/work-document-emphasis.d.ts +7 -0
  48. package/dist/internal/features/work/work-document-equations.d.ts +2 -1
  49. package/dist/internal/features/work/work-document-format-changes.d.ts +16 -2
  50. package/dist/internal/features/work/work-document-hidden-text.d.ts +5 -0
  51. package/dist/internal/features/work/work-document-kerning.d.ts +10 -0
  52. package/dist/internal/features/work/work-document-paragraph-shading.d.ts +1 -1
  53. package/dist/internal/features/work/work-document-script-font-extension.d.ts +2 -0
  54. package/dist/internal/features/work/work-document-script-fonts.d.ts +51 -0
  55. package/dist/internal/features/work/work-document-strike.d.ts +21 -0
  56. package/dist/internal/features/work/work-document-text-case.d.ts +10 -0
  57. package/dist/internal/features/work/work-document-underline.d.ts +37 -0
  58. package/dist/internal/features/work/work-document-word-line-metrics.d.ts +12 -0
  59. package/dist/internal/features/work/work-docx-character-position.d.ts +2 -0
  60. package/dist/internal/features/work/work-docx-character-scale.d.ts +2 -0
  61. package/dist/internal/features/work/work-docx-character-spacing.d.ts +4 -0
  62. package/dist/internal/features/work/work-docx-emphasis-diagnostics.d.ts +3 -0
  63. package/dist/internal/features/work/work-docx-emphasis.d.ts +14 -0
  64. package/dist/internal/features/work/work-docx-hidden-text-diagnostics.d.ts +3 -0
  65. package/dist/internal/features/work/work-docx-hidden-text-export.d.ts +16 -0
  66. package/dist/internal/features/work/work-docx-hidden-text.d.ts +11 -0
  67. package/dist/internal/features/work/work-docx-kerning-diagnostics.d.ts +3 -0
  68. package/dist/internal/features/work/work-docx-kerning.d.ts +14 -0
  69. package/dist/internal/features/work/work-docx-run-fonts-diagnostics.d.ts +3 -0
  70. package/dist/internal/features/work/work-docx-run-fonts-export.d.ts +14 -0
  71. package/dist/internal/features/work/work-docx-run-fonts.d.ts +13 -0
  72. package/dist/internal/features/work/work-docx-run-formatting-import.d.ts +23 -2
  73. package/dist/internal/features/work/work-docx-run-script-font-import.d.ts +9 -0
  74. package/dist/internal/features/work/work-docx-strike.d.ts +8 -0
  75. package/dist/internal/features/work/work-docx-theme-reference.d.ts +1 -1
  76. package/dist/internal/features/work/work-docx-twips.d.ts +6 -0
  77. package/dist/internal/features/work/work-docx-underline.d.ts +3 -0
  78. package/dist/internal/features/work/work-spreadsheet-gradient-fill-canvas.d.ts +10 -0
  79. package/dist/internal/features/work/work-spreadsheet-native-fill-canvas.d.ts +8 -0
  80. package/dist/internal/features/work/work-spreadsheet-pattern-fill-canvas.d.ts +8 -0
  81. package/dist/internal/features/work/work-xlsx-cell-style-origin.d.ts +2 -1
  82. package/dist/internal/features/work/work-xlsx-cell-style-writer.d.ts +3 -0
  83. package/dist/internal/features/work/work-xlsx-cell-styles.d.ts +4 -0
  84. package/dist/internal/features/work/work-xlsx-gradient-fill.d.ts +31 -0
  85. package/dist/internal/features/work/work-xlsx-native-fill.d.ts +17 -0
  86. package/dist/internal/features/work/work-xlsx-pattern-fill.d.ts +21 -0
  87. package/dist/internal/features/work/work-xlsx-rich-text-edit.d.ts +28 -0
  88. package/dist/internal/features/work/work-xlsx-rich-text-model.d.ts +40 -0
  89. package/dist/internal/features/work/work-xlsx-rich-text.d.ts +4 -18
  90. package/dist/office-kernel.wasm +0 -0
  91. package/dist/styles.css +770 -80
  92. package/docs/latest/en/browser-editor-architecture.md +37 -0
  93. package/package.json +32 -1
@@ -1713,1081 +1713,1351 @@ function spreadsheetFormulaHistoryCellType(cellType) {
1713
1713
  };
1714
1714
  return Object.keys(normalized).length ? normalized : void 0;
1715
1715
  }
1716
- const SPREADSHEET_SHOWN_COMMENT_CELLS_PROPERTY = '__a3sShownCommentCells';
1717
- const spreadsheetMatrixProfiles = new WeakMap();
1718
- function freezeImportedSpreadsheetCell(cell) {
1719
- freezeObject(cell.mc);
1720
- freezeObject(cell.ct?.s);
1721
- freezeObject(cell.ct);
1722
- freezeObject(cell.ps);
1723
- freezeObject(cell.hl);
1724
- freezeObject(cell.spl);
1725
- return Object.freeze(cell);
1716
+ const borderChildOrder = [
1717
+ 'start',
1718
+ 'end',
1719
+ 'left',
1720
+ 'right',
1721
+ 'top',
1722
+ 'bottom',
1723
+ 'diagonal',
1724
+ 'vertical',
1725
+ 'horizontal',
1726
+ 'extLst'
1727
+ ];
1728
+ function ensureXlsxStyleCollection(document, name, anchors) {
1729
+ const root = document.documentElement;
1730
+ const existing = directChild(root, name);
1731
+ if (existing) return existing;
1732
+ const collection = document.createElementNS(root.namespaceURI, name);
1733
+ root.insertBefore(collection, directChildren(root).find((child)=>anchors.includes(child.localName)) ?? null);
1734
+ return collection;
1726
1735
  }
1727
- function registerImportedSpreadsheetMatrix(data, options) {
1728
- data.length = Math.max(data.length, options.rowCount);
1729
- data[0] ??= [];
1730
- for (const rowIndex of sparseArrayIndexes(data)){
1731
- const row = data[rowIndex];
1732
- if (row) {
1733
- row.length = Math.max(row.length, options.columnCount);
1734
- Object.freeze(row);
1735
- }
1736
- }
1737
- registerSpreadsheetMatrixProfile(data, options);
1736
+ function defaultXlsxFill(document, patternType) {
1737
+ const fill = document.createElementNS(document.documentElement.namespaceURI, 'fill');
1738
+ const pattern = document.createElementNS(document.documentElement.namespaceURI, 'patternFill');
1739
+ pattern.setAttribute('patternType', patternType);
1740
+ fill.append(pattern);
1741
+ return fill;
1738
1742
  }
1739
- function registerDerivedSpreadsheetMatrix(data, source, changes) {
1740
- const sourceProfile = spreadsheetMatrixProfiles.get(source);
1741
- if (!sourceProfile?.fortuneReady) return false;
1742
- const formulaCells = new Map(sourceProfile.formulaCells.map(({ column, row })=>[
1743
- spreadsheetCoordinateKey(row, column),
1744
- {
1745
- column,
1746
- row
1747
- }
1748
- ]));
1749
- const shownCommentCells = new Map(sourceProfile.shownCommentCells.map(({ c, r })=>[
1750
- spreadsheetCoordinateKey(r, c),
1751
- {
1752
- c,
1753
- r
1754
- }
1755
- ]));
1756
- let populatedCellCount = sourceProfile.populatedCellCount;
1757
- let protectionCellKey = sourceProfile.protectionCellKey;
1758
- let protectionCells;
1759
- for (const { column, current, previous, row } of changes){
1760
- const coordinateKey = spreadsheetCoordinateKey(row, column);
1761
- if (null == previous && null != current) populatedCellCount += 1;
1762
- if (null != previous && null == current) populatedCellCount -= 1;
1763
- if (current?.f) formulaCells.set(coordinateKey, {
1764
- column,
1765
- row
1766
- });
1767
- else formulaCells.delete(coordinateKey);
1768
- if (current?.ps?.isShow) shownCommentCells.set(coordinateKey, {
1769
- c: column,
1770
- r: row
1771
- });
1772
- else shownCommentCells.delete(coordinateKey);
1773
- if (spreadsheetProtectionSignature(previous) !== spreadsheetProtectionSignature(current)) {
1774
- protectionCells ??= spreadsheetProtectionCells(protectionCellKey);
1775
- const signature = spreadsheetProtectionSignature(current);
1776
- if (null === signature) protectionCells.delete(coordinateKey);
1777
- else protectionCells.set(coordinateKey, signature);
1743
+ function defaultXlsxBorder(document) {
1744
+ const border = document.createElementNS(document.documentElement.namespaceURI, 'border');
1745
+ for (const name of [
1746
+ 'left',
1747
+ 'right',
1748
+ 'top',
1749
+ 'bottom',
1750
+ 'diagonal'
1751
+ ])border.append(document.createElementNS(document.documentElement.namespaceURI, name));
1752
+ return border;
1753
+ }
1754
+ function setXlsxBorderLine(document, border, name, line) {
1755
+ removeXlsxChildren(border, name);
1756
+ const element = document.createElementNS(document.documentElement.namespaceURI, name);
1757
+ if (line) {
1758
+ element.setAttribute('style', line.style);
1759
+ const color = xlsxRgbColor(line.color);
1760
+ if (color) {
1761
+ const child = document.createElementNS(document.documentElement.namespaceURI, 'color');
1762
+ child.setAttribute('rgb', color);
1763
+ element.append(child);
1778
1764
  }
1779
- const changedRow = data[row];
1780
- if (changedRow && !Object.isFrozen(changedRow)) Object.freeze(changedRow);
1781
1765
  }
1782
- if (protectionCells) protectionCellKey = Array.from(protectionCells, ([coordinate, value])=>({
1783
- coordinate,
1784
- value
1785
- })).sort((left, right)=>compareSpreadsheetCoordinates(left.coordinate, right.coordinate)).map(({ coordinate, value })=>`${coordinate}:${value}`).join(',');
1786
- registerSpreadsheetMatrixProfile(data, {
1787
- columnCount: Math.max(sourceProfile.columnCount, ...changes.map(({ column, row })=>Math.max(column + 1, data[row]?.length ?? 0))),
1788
- formulaCells: Array.from(formulaCells.values()).sort(compareSpreadsheetCells),
1789
- fortuneReady: true,
1790
- populatedCellCount: Math.max(0, populatedCellCount),
1791
- protectionCellKey,
1792
- rowCount: Math.max(sourceProfile.rowCount, data.length, ...changes.map(({ row })=>row + 1)),
1793
- shownCommentCells: Array.from(shownCommentCells.values()).sort((left, right)=>left.r - right.r || left.c - right.c)
1794
- }, {
1795
- historyRoot: sourceProfile.historyRoot,
1796
- historyState: changes.some(({ current, previous })=>!sameSpreadsheetHistoryValue(current, previous)) ? Object.freeze({}) : sourceProfile.historyState
1797
- });
1798
- return true;
1799
- }
1800
- function spreadsheetMatrixProfile(data) {
1801
- return data ? spreadsheetMatrixProfiles.get(data) : void 0;
1802
- }
1803
- function attachSpreadsheetShownCommentCells(data, cells) {
1804
- Object.defineProperty(data, SPREADSHEET_SHOWN_COMMENT_CELLS_PROPERTY, {
1805
- configurable: false,
1806
- enumerable: false,
1807
- value: cells,
1808
- writable: false
1809
- });
1810
- }
1811
- function registerSpreadsheetMatrixProfile(data, options, history) {
1812
- const initialHistoryState = Object.freeze({});
1813
- const profile = Object.freeze({
1814
- columnCount: options.columnCount,
1815
- formulaCells: Object.freeze(options.formulaCells.map((cell)=>Object.freeze({
1816
- ...cell
1817
- }))),
1818
- fortuneReady: options.fortuneReady,
1819
- historyRoot: history?.historyRoot ?? initialHistoryState,
1820
- historyState: history?.historyState ?? initialHistoryState,
1821
- populatedCellCount: options.populatedCellCount,
1822
- protectionCellKey: options.protectionCellKey,
1823
- rowCount: options.rowCount,
1824
- shownCommentCells: Object.freeze(options.shownCommentCells.map((cell)=>Object.freeze({
1825
- ...cell
1826
- })))
1827
- });
1828
- attachSpreadsheetShownCommentCells(data, profile.shownCommentCells);
1829
- Object.freeze(data);
1830
- spreadsheetMatrixProfiles.set(data, profile);
1766
+ insertXlsxOrderedChild(border, element, borderChildOrder);
1831
1767
  }
1832
- function spreadsheetProtectionCells(value) {
1833
- const cells = new Map();
1834
- for (const entry of value.split(',')){
1835
- if (!entry) continue;
1836
- const separator = entry.indexOf(':');
1837
- if (!(separator <= 0)) cells.set(entry.slice(0, separator), entry.slice(separator + 1));
1768
+ function writeXlsxAlignment(document, xf, style) {
1769
+ let alignment = directChild(xf, 'alignment');
1770
+ if (!alignment) {
1771
+ alignment = document.createElementNS(document.documentElement.namespaceURI, 'alignment');
1772
+ xf.insertBefore(alignment, directChildren(xf).find((child)=>[
1773
+ 'protection',
1774
+ 'extLst'
1775
+ ].includes(child.localName)) ?? null);
1838
1776
  }
1839
- return cells;
1777
+ if (void 0 !== style.horizontal) alignment.setAttribute('horizontal', style.horizontal);
1778
+ if (void 0 !== style.vertical) alignment.setAttribute('vertical', style.vertical);
1779
+ if (void 0 !== style.wrapText) alignment.setAttribute('wrapText', style.wrapText ? '1' : '0');
1780
+ if (void 0 !== style.textRotation && Number.isInteger(style.textRotation) && (style.textRotation >= 0 && style.textRotation <= 180 || 255 === style.textRotation)) alignment.setAttribute('textRotation', String(style.textRotation));
1840
1781
  }
1841
- function spreadsheetProtectionSignature(cell) {
1842
- const hidden = cell?.hi;
1843
- if (cell?.lo === void 0 && void 0 === hidden) return null;
1844
- return `${cell?.lo ?? ''}:${hidden ?? ''}`;
1782
+ function setXlsxValueChild(document, parent, name, value, order) {
1783
+ removeXlsxChildren(parent, name);
1784
+ const child = document.createElementNS(document.documentElement.namespaceURI, name);
1785
+ child.setAttribute('val', value);
1786
+ insertXlsxOrderedChild(parent, child, order);
1845
1787
  }
1846
- function spreadsheetCoordinateKey(row, column) {
1847
- return `${row}_${column}`;
1788
+ function setXlsxColorChild(document, parent, color, order) {
1789
+ removeXlsxChildren(parent, 'color');
1790
+ const child = document.createElementNS(document.documentElement.namespaceURI, 'color');
1791
+ child.setAttribute('rgb', color);
1792
+ insertXlsxOrderedChild(parent, child, order);
1848
1793
  }
1849
- function compareSpreadsheetCoordinates(left, right) {
1850
- const [leftRow = 0, leftColumn = 0] = left.split('_').map(Number);
1851
- const [rightRow = 0, rightColumn = 0] = right.split('_').map(Number);
1852
- return leftRow - rightRow || leftColumn - rightColumn;
1794
+ function setXlsxToggleChild(document, parent, name, enabled, order) {
1795
+ removeXlsxChildren(parent, name);
1796
+ if (!enabled) return;
1797
+ const child = document.createElementNS(document.documentElement.namespaceURI, name);
1798
+ child.setAttribute('val', '1');
1799
+ insertXlsxOrderedChild(parent, child, order);
1853
1800
  }
1854
- function compareSpreadsheetCells(left, right) {
1855
- return left.row - right.row || left.column - right.column;
1801
+ function setXlsxUnderlineChild(document, parent, style, order) {
1802
+ removeXlsxChildren(parent, 'u');
1803
+ if ('none' === style) return;
1804
+ const child = document.createElementNS(document.documentElement.namespaceURI, 'u');
1805
+ child.setAttribute('val', style);
1806
+ insertXlsxOrderedChild(parent, child, order);
1856
1807
  }
1857
- function freezeObject(value) {
1858
- if (value && 'object' == typeof value) Object.freeze(value);
1808
+ function xlsxRgbColor(value) {
1809
+ if ('string' != typeof value) return null;
1810
+ const color = value.trim().replace('#', '').toUpperCase();
1811
+ if (/^[0-9A-F]{6}$/.test(color)) return `FF${color}`;
1812
+ if (/^[0-9A-F]{8}$/.test(color)) return color;
1813
+ if (/^[0-9A-F]{3}$/.test(color)) return `FF${[
1814
+ ...color
1815
+ ].map((character)=>character.repeat(2)).join('')}`;
1816
+ return null;
1859
1817
  }
1860
- const DEFAULT_PROTECTION_HINT = '此工作表已受保护。若要更改锁定的单元格,请先取消工作表保护。';
1861
- function defaultSheetProtectionAuthority(enabled = false) {
1862
- return {
1863
- sheet: enabled ? 1 : 0,
1864
- selectLockedCells: 1,
1865
- selectunLockedCells: 1,
1866
- formatCells: 0,
1867
- formatColumns: 0,
1868
- formatRows: 0,
1869
- insertColumns: 0,
1870
- insertRows: 0,
1871
- insertHyperlinks: 0,
1872
- deleteColumns: 0,
1873
- deleteRows: 0,
1874
- sort: 0,
1875
- filter: 0,
1876
- usePivotTablereports: 0,
1877
- editObjects: 0,
1878
- editScenarios: 0,
1879
- hintText: '',
1880
- defaultSheetHintText: DEFAULT_PROTECTION_HINT,
1881
- allowRangeList: [],
1882
- cellProtectionRanges: []
1883
- };
1818
+ function removeXlsxChildren(parent, name) {
1819
+ for (const child of directChildren(parent, name))child.remove();
1884
1820
  }
1885
- function sheetProtectionAuthority(sheet) {
1886
- return normalizeSheetProtectionAuthority(sheet.config?.authority);
1821
+ function insertXlsxOrderedChild(parent, child, order) {
1822
+ const requested = order.indexOf(child.localName);
1823
+ const anchor = directChildren(parent).find((candidate)=>order.indexOf(candidate.localName) > requested);
1824
+ parent.insertBefore(child, anchor ?? null);
1887
1825
  }
1888
- function normalizeSheetProtectionAuthority(source) {
1889
- const defaults = defaultSheetProtectionAuthority();
1890
- if (!source || 'object' != typeof source) return defaults;
1891
- const authority = source;
1826
+ const defaultThemeColors = [
1827
+ 'ffffff',
1828
+ '000000',
1829
+ 'e7e6e6',
1830
+ '44546a',
1831
+ '4472c4',
1832
+ 'ed7d31',
1833
+ 'a5a5a5',
1834
+ 'ffc000',
1835
+ '5b9bd5',
1836
+ '70ad47',
1837
+ '0563c1',
1838
+ '954f72'
1839
+ ];
1840
+ const themeColorNames = [
1841
+ 'lt1',
1842
+ 'dk1',
1843
+ 'lt2',
1844
+ 'dk2',
1845
+ 'accent1',
1846
+ 'accent2',
1847
+ 'accent3',
1848
+ 'accent4',
1849
+ 'accent5',
1850
+ 'accent6',
1851
+ 'hlink',
1852
+ 'folHlink'
1853
+ ];
1854
+ const defaultIndexedColors = [
1855
+ '000000',
1856
+ 'ffffff',
1857
+ 'ff0000',
1858
+ '00ff00',
1859
+ '0000ff',
1860
+ 'ffff00',
1861
+ 'ff00ff',
1862
+ '00ffff',
1863
+ '000000',
1864
+ 'ffffff',
1865
+ 'ff0000',
1866
+ '00ff00',
1867
+ '0000ff',
1868
+ 'ffff00',
1869
+ 'ff00ff',
1870
+ '00ffff',
1871
+ '800000',
1872
+ '008000',
1873
+ '000080',
1874
+ '808000',
1875
+ '800080',
1876
+ '008080',
1877
+ 'c0c0c0',
1878
+ '808080',
1879
+ '9999ff',
1880
+ '993366',
1881
+ 'ffffcc',
1882
+ 'ccffff',
1883
+ '660066',
1884
+ 'ff8080',
1885
+ '0066cc',
1886
+ 'ccccff',
1887
+ '000080',
1888
+ 'ff00ff',
1889
+ 'ffff00',
1890
+ '00ffff',
1891
+ '800080',
1892
+ '800000',
1893
+ '008080',
1894
+ '0000ff',
1895
+ '00ccff',
1896
+ 'ccffff',
1897
+ 'ccffcc',
1898
+ 'ffff99',
1899
+ '99ccff',
1900
+ 'ff99cc',
1901
+ 'cc99ff',
1902
+ 'ffcc99',
1903
+ '3366ff',
1904
+ '33cccc',
1905
+ '99cc00',
1906
+ 'ffcc00',
1907
+ 'ff9900',
1908
+ 'ff6600',
1909
+ '666699',
1910
+ '969696',
1911
+ '003366',
1912
+ '339966',
1913
+ '003300',
1914
+ '333300',
1915
+ '993300',
1916
+ '993366',
1917
+ '333399',
1918
+ '333333'
1919
+ ];
1920
+ function createXlsxColorResolver(styles, theme) {
1892
1921
  return {
1893
- sheet: flag(authority.sheet, defaults.sheet),
1894
- selectLockedCells: flag(authority.selectLockedCells, defaults.selectLockedCells),
1895
- selectunLockedCells: flag(authority.selectunLockedCells, defaults.selectunLockedCells),
1896
- formatCells: flag(authority.formatCells, defaults.formatCells),
1897
- formatColumns: flag(authority.formatColumns, defaults.formatColumns),
1898
- formatRows: flag(authority.formatRows, defaults.formatRows),
1899
- insertColumns: flag(authority.insertColumns, defaults.insertColumns),
1900
- insertRows: flag(authority.insertRows, defaults.insertRows),
1901
- insertHyperlinks: flag(authority.insertHyperlinks, defaults.insertHyperlinks),
1902
- deleteColumns: flag(authority.deleteColumns, defaults.deleteColumns),
1903
- deleteRows: flag(authority.deleteRows, defaults.deleteRows),
1904
- sort: flag(authority.sort, defaults.sort),
1905
- filter: flag(authority.filter, defaults.filter),
1906
- usePivotTablereports: flag(authority.usePivotTablereports, defaults.usePivotTablereports),
1907
- editObjects: flag(authority.editObjects, defaults.editObjects),
1908
- editScenarios: flag(authority.editScenarios, defaults.editScenarios),
1909
- hintText: stringValue(authority.hintText),
1910
- defaultSheetHintText: stringValue(authority.defaultSheetHintText) || DEFAULT_PROTECTION_HINT,
1911
- allowRangeList: editableRangeList(authority.allowRangeList),
1912
- cellProtectionRanges: cellProtectionRangeList(authority.cellProtectionRanges),
1913
- xlsxAttributes: stringRecord(authority.xlsxAttributes)
1922
+ indexed: styles ? readIndexedColors(styles) : defaultIndexedColors,
1923
+ theme: readThemeColors(theme)
1924
+ };
1925
+ }
1926
+ function resolveXlsxColor(element, resolver) {
1927
+ if (!element) return;
1928
+ const direct = normalizedHexColor(attribute(element, 'rgb'));
1929
+ const themeIndex = boundedInteger(attribute(element, 'theme'), 11);
1930
+ const indexed = boundedInteger(attribute(element, 'indexed'), 65535);
1931
+ const automatic = booleanAttribute(element, 'auto');
1932
+ const source = direct ?? (null === themeIndex ? void 0 : resolver.theme[themeIndex]) ?? (null === indexed ? void 0 : resolver.indexed[indexed]) ?? (automatic ? '000000' : void 0);
1933
+ if (!source) return;
1934
+ const tint = Number(attribute(element, 'tint'));
1935
+ return `#${Number.isFinite(tint) && tint >= -1 && tint <= 1 ? tintXlsxColor(source, tint) : source}`;
1936
+ }
1937
+ function readThemeColors(theme) {
1938
+ if (!theme) return defaultThemeColors;
1939
+ const scheme = firstDescendant(theme, 'clrScheme');
1940
+ if (!scheme) return defaultThemeColors;
1941
+ return themeColorNames.map((name, index)=>{
1942
+ const entry = directChild(scheme, name);
1943
+ const color = entry ? drawingColor(directChildren(entry)[0]) : void 0;
1944
+ return color ?? defaultThemeColors[index];
1945
+ });
1946
+ }
1947
+ function readIndexedColors(styles) {
1948
+ const indexed = firstDescendant(styles, 'indexedColors');
1949
+ if (!indexed) return defaultIndexedColors;
1950
+ const colors = directChildren(indexed, 'rgbColor').map((element)=>normalizedHexColor(attribute(element, 'rgb')));
1951
+ return colors.every(Boolean) ? colors : defaultIndexedColors;
1952
+ }
1953
+ function drawingColor(element) {
1954
+ if (!element) return;
1955
+ return normalizedHexColor('sysClr' === element.localName ? attribute(element, 'lastClr') : attribute(element, 'val'));
1956
+ }
1957
+ function tintXlsxColor(color, tint) {
1958
+ const [hue, saturation, lightness] = rgbToHsl([
1959
+ 0,
1960
+ 2,
1961
+ 4
1962
+ ].map((offset)=>Number.parseInt(color.slice(offset, offset + 2), 16) / 255));
1963
+ const tintedLightness = tint < 0 ? lightness * (1 + tint) : 1 - (1 - lightness) * (1 - tint);
1964
+ return hslToRgb(hue, saturation, tintedLightness).map((channel)=>Math.round(255 * channel)).map((channel)=>channel.toString(16).padStart(2, '0')).join('');
1965
+ }
1966
+ function rgbToHsl([red, green, blue]) {
1967
+ const maximum = Math.max(red, green, blue);
1968
+ const minimum = Math.min(red, green, blue);
1969
+ const delta = maximum - minimum;
1970
+ const lightness = (maximum + minimum) / 2;
1971
+ if (0 === delta) return [
1972
+ 0,
1973
+ 0,
1974
+ lightness
1975
+ ];
1976
+ const saturation = delta / (1 - Math.abs(2 * lightness - 1));
1977
+ const hue = maximum === red ? ((green - blue) / delta + (green < blue ? 6 : 0)) / 6 : maximum === green ? ((blue - red) / delta + 2) / 6 : ((red - green) / delta + 4) / 6;
1978
+ return [
1979
+ hue,
1980
+ saturation,
1981
+ lightness
1982
+ ];
1983
+ }
1984
+ function hslToRgb(hue, saturation, lightness) {
1985
+ if (0 === saturation) return [
1986
+ lightness,
1987
+ lightness,
1988
+ lightness
1989
+ ];
1990
+ const chroma = 2 * saturation * (lightness < 0.5 ? lightness : 1 - lightness);
1991
+ const minimum = lightness - chroma / 2;
1992
+ const channels = [
1993
+ minimum,
1994
+ minimum,
1995
+ minimum
1996
+ ];
1997
+ const sector = 6 * hue;
1998
+ switch(Math.floor(sector)){
1999
+ case 0:
2000
+ case 6:
2001
+ channels[0] += chroma;
2002
+ channels[1] += chroma * sector;
2003
+ break;
2004
+ case 1:
2005
+ channels[0] += chroma * (2 - sector);
2006
+ channels[1] += chroma;
2007
+ break;
2008
+ case 2:
2009
+ channels[1] += chroma;
2010
+ channels[2] += chroma * (sector - 2);
2011
+ break;
2012
+ case 3:
2013
+ channels[1] += chroma * (4 - sector);
2014
+ channels[2] += chroma;
2015
+ break;
2016
+ case 4:
2017
+ channels[0] += chroma * (sector - 4);
2018
+ channels[2] += chroma;
2019
+ break;
2020
+ case 5:
2021
+ channels[0] += chroma;
2022
+ channels[2] += chroma * (6 - sector);
2023
+ break;
2024
+ }
2025
+ return channels;
2026
+ }
2027
+ function normalizedHexColor(value) {
2028
+ if (!value || !/^[0-9a-f]{6,8}$/i.test(value)) return;
2029
+ return value.slice(-6).toLowerCase();
2030
+ }
2031
+ function boundedInteger(value, maximum) {
2032
+ if (null === value || !/^\d+$/.test(value)) return null;
2033
+ const parsed = Number(value);
2034
+ return Number.isSafeInteger(parsed) && parsed <= maximum ? parsed : null;
2035
+ }
2036
+ function booleanAttribute(element, name) {
2037
+ const value = attribute(element, name)?.trim().toLowerCase();
2038
+ return '1' === value || 'true' === value || 'on' === value;
2039
+ }
2040
+ const THEME_COLOR_NAMES = [
2041
+ 'lt1',
2042
+ 'dk1',
2043
+ 'lt2',
2044
+ 'dk2',
2045
+ 'accent1',
2046
+ 'accent2',
2047
+ 'accent3',
2048
+ 'accent4',
2049
+ 'accent5',
2050
+ 'accent6',
2051
+ 'hlink',
2052
+ 'folHlink'
2053
+ ];
2054
+ const MAX_INDEXED_COLOR = 255;
2055
+ function readXlsxSemanticColorOrigin(element, colors) {
2056
+ if (!element || attribute(element, 'rgb')) return;
2057
+ const renderedColor = resolveXlsxColor(element, colors);
2058
+ if (!renderedColor) return;
2059
+ const tint = boundedTint(attribute(element, 'tint'));
2060
+ const theme = work_xlsx_cell_style_origin_boundedInteger(attribute(element, 'theme'), THEME_COLOR_NAMES.length - 1);
2061
+ if (null !== theme && colors.theme[theme]) return {
2062
+ kind: 'theme',
2063
+ baseColor: `#${colors.theme[theme]}`,
2064
+ index: theme,
2065
+ renderedColor,
2066
+ ...null === tint ? {} : {
2067
+ tint
2068
+ }
2069
+ };
2070
+ const indexed = work_xlsx_cell_style_origin_boundedInteger(attribute(element, 'indexed'), MAX_INDEXED_COLOR);
2071
+ if (null !== indexed && colors.indexed[indexed]) return {
2072
+ kind: 'indexed',
2073
+ baseColor: `#${colors.indexed[indexed]}`,
2074
+ index: indexed,
2075
+ renderedColor,
2076
+ ...null === tint ? {} : {
2077
+ tint
2078
+ }
2079
+ };
2080
+ if (xlsxBooleanAttribute(element, 'auto')) return {
2081
+ kind: 'automatic',
2082
+ baseColor: '#000000',
2083
+ renderedColor,
2084
+ ...null === tint ? {} : {
2085
+ tint
2086
+ }
2087
+ };
2088
+ }
2089
+ function withXlsxCellStyleOrigin(cell, origin) {
2090
+ return origin && xlsxCellStyleOriginHasValues(origin) ? {
2091
+ ...cell,
2092
+ a3sXlsxStyleOrigin: origin
2093
+ } : cell;
2094
+ }
2095
+ function xlsxCellStyleOrigin(cell) {
2096
+ const candidate = cell?.a3sXlsxStyleOrigin;
2097
+ if (!isRecord(candidate)) return;
2098
+ const fontColor = normalizeXlsxSemanticColorOrigin(candidate.fontColor);
2099
+ const fillColor = normalizeXlsxSemanticColorOrigin(candidate.fillColor);
2100
+ const borderColors = normalizedBorderColors(candidate.borderColors);
2101
+ const origin = {
2102
+ ...fontColor ? {
2103
+ fontColor
2104
+ } : {},
2105
+ ...fillColor ? {
2106
+ fillColor
2107
+ } : {},
2108
+ ...borderColors ? {
2109
+ borderColors
2110
+ } : {}
1914
2111
  };
2112
+ return xlsxCellStyleOriginHasValues(origin) ? origin : void 0;
1915
2113
  }
1916
- function importedSheetProtectionAuthority(authority, cellProtectionRanges) {
1917
- if (!authority && !cellProtectionRanges.length) return;
1918
- const normalized = normalizeSheetProtectionAuthority(authority);
1919
- normalized.cellProtectionRanges = [
1920
- ...cellProtectionRanges,
1921
- ...normalized.allowRangeList.filter((range)=>!editableRangeRequiresCredentials(range)).flatMap((range)=>work_spreadsheet_ranges_parseSpreadsheetCellRanges(range.sqref) ?? []).map((range)=>({
1922
- range,
1923
- locked: false,
1924
- hidden: false
1925
- }))
1926
- ];
1927
- return normalized;
2114
+ function xlsxSemanticColorMatchesValue(origin, value) {
2115
+ return work_xlsx_cell_style_origin_normalizedColor(value) === origin.renderedColor.toLowerCase();
1928
2116
  }
1929
- function withSheetProtection(sheet, enabled) {
1930
- const authority = sheetProtectionAuthority(sheet);
1931
- authority.sheet = enabled ? 1 : 0;
1932
- return withAuthority(sheet, authority);
2117
+ function xlsxColorElementMatchesOrigin(element, origin) {
2118
+ if (!element || attribute(element, 'rgb')) return false;
2119
+ if ('theme' === origin.kind) {
2120
+ if (attribute(element, 'theme') !== String(origin.index)) return false;
2121
+ } else if ('indexed' === origin.kind) {
2122
+ if (attribute(element, 'indexed') !== String(origin.index)) return false;
2123
+ } else if (!xlsxBooleanAttribute(element, 'auto')) return false;
2124
+ const tint = boundedTint(attribute(element, 'tint'));
2125
+ return tint === (origin.tint ?? null);
1933
2126
  }
1934
- function withSheetSelectionPermissions(sheet, permissions) {
1935
- const authority = sheetProtectionAuthority(sheet);
1936
- if (void 0 !== permissions.selectLockedCells) authority.selectLockedCells = permissions.selectLockedCells ? 1 : 0;
1937
- if (void 0 !== permissions.selectUnlockedCells) authority.selectunLockedCells = permissions.selectUnlockedCells ? 1 : 0;
1938
- return withAuthority(sheet, authority);
2127
+ function applyXlsxSemanticColorOrigin(element, origin) {
2128
+ for (const name of [
2129
+ 'rgb',
2130
+ 'theme',
2131
+ 'indexed',
2132
+ 'auto',
2133
+ 'tint'
2134
+ ])element.removeAttribute(name);
2135
+ if ('theme' === origin.kind) element.setAttribute('theme', String(origin.index));
2136
+ else if ('indexed' === origin.kind) element.setAttribute('indexed', String(origin.index));
2137
+ else element.setAttribute('auto', '1');
2138
+ if (void 0 !== origin.tint) element.setAttribute('tint', String(origin.tint));
1939
2139
  }
1940
- function withEditableRange(sheet, index, editableRange) {
1941
- const authority = sheetProtectionAuthority(sheet);
1942
- const nextRange = {
1943
- name: editableRange.name.trim(),
1944
- sqref: canonicalRangeReference(editableRange.sqref),
1945
- hintText: editableRange.hintText?.trim() || void 0,
1946
- xlsxAttributes: editableRange.xlsxAttributes
1947
- };
1948
- if (null !== index && authority.allowRangeList[index]) authority.allowRangeList[index] = nextRange;
1949
- else authority.allowRangeList.push(nextRange);
1950
- const ranges = work_spreadsheet_ranges_parseSpreadsheetCellRanges(nextRange.sqref) ?? [];
1951
- const next = withCellProtection(sheet, ranges, false);
1952
- const nextAuthority = sheetProtectionAuthority(next);
1953
- nextAuthority.allowRangeList = authority.allowRangeList;
1954
- return withAuthority(next, nextAuthority);
2140
+ function xlsxSemanticColorOriginKey(origin) {
2141
+ return origin ? `${origin.kind}:${'index' in origin ? origin.index : ''}:${origin.baseColor}:${origin.renderedColor}:${origin.tint ?? ''}` : '';
1955
2142
  }
1956
- function withoutEditableRange(sheet, index) {
1957
- const authority = sheetProtectionAuthority(sheet);
1958
- const removed = authority.allowRangeList[index];
1959
- if (!removed) return sheet;
1960
- authority.allowRangeList.splice(index, 1);
1961
- const removedRanges = work_spreadsheet_ranges_parseSpreadsheetCellRanges(removed.sqref) ?? [];
1962
- let next = withCellProtection(sheet, removedRanges, true);
1963
- for (const editableRange of authority.allowRangeList)if (!editableRangeRequiresCredentials(editableRange)) next = withCellProtection(next, work_spreadsheet_ranges_parseSpreadsheetCellRanges(editableRange.sqref) ?? [], false);
1964
- const nextAuthority = sheetProtectionAuthority(next);
1965
- nextAuthority.allowRangeList = authority.allowRangeList;
1966
- return withAuthority(next, nextAuthority);
2143
+ function xlsxSemanticColorOriginSupported(origin, palette) {
2144
+ if ('automatic' === origin.kind) return true;
2145
+ return palette?.[origin.kind].get(origin.index)?.toLowerCase() === origin.baseColor.toLowerCase();
1967
2146
  }
1968
- function withCellProtection(sheet, ranges, locked, hidden = false) {
1969
- if (!ranges.length) return sheet;
1970
- const data = cloneSparseMatrix(sheet.data);
1971
- let rowCount = Math.max(sheet.row ?? 0, data.length);
1972
- let columnCount = Math.max(sheet.column ?? 0, sparseMatrixColumnCount(data));
1973
- for (const range of ranges){
1974
- rowCount = Math.max(rowCount, range.row[1] + 1);
1975
- columnCount = Math.max(columnCount, range.column[1] + 1);
1976
- 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)){
1977
- if (column < range.column[0] || column > range.column[1]) continue;
1978
- const cell = {
1979
- ...source ?? {}
1980
- };
1981
- cell.lo = locked ? 1 : 0;
1982
- if (hidden) cell.hi = 1;
1983
- else if (void 0 !== cell.hi) delete cell.hi;
1984
- data[row][column] = cell;
2147
+ function prepareXlsxSemanticPalette(styles, theme, colors) {
2148
+ const candidates = semanticPaletteCandidates(colors);
2149
+ const supportedTheme = new Map();
2150
+ let themeChanged = false;
2151
+ const scheme = theme ? firstDescendant(theme, 'clrScheme') : void 0;
2152
+ for (const [index, color] of candidates.theme){
2153
+ const name = THEME_COLOR_NAMES[index];
2154
+ const entry = name && scheme ? directChild(scheme, name) : void 0;
2155
+ if (entry) {
2156
+ themeChanged = writeThemeColor(entry, color) || themeChanged;
2157
+ supportedTheme.set(index, color);
1985
2158
  }
1986
2159
  }
1987
- normalizeMatrix(data, rowCount, columnCount);
1988
- const authority = sheetProtectionAuthority(sheet);
1989
- authority.cellProtectionRanges.push(...ranges.map((range)=>({
1990
- range,
1991
- locked,
1992
- hidden
1993
- })));
1994
- return withAuthority({
1995
- ...sheet,
1996
- row: rowCount,
1997
- column: columnCount,
1998
- data
1999
- }, authority);
2160
+ const supportedIndexed = new Map();
2161
+ let stylesChanged = false;
2162
+ if (candidates.indexed.size) {
2163
+ const colors = ensureXlsxStyleCollection(styles, 'colors', [
2164
+ 'extLst'
2165
+ ]);
2166
+ let indexedColors = directChild(colors, 'indexedColors');
2167
+ if (!indexedColors) {
2168
+ indexedColors = styles.createElementNS(styles.documentElement.namespaceURI, 'indexedColors');
2169
+ colors.prepend(indexedColors);
2170
+ stylesChanged = true;
2171
+ }
2172
+ const resolver = createXlsxColorResolver(styles, theme);
2173
+ const highestIndex = Math.max(...candidates.indexed.keys());
2174
+ while(directChildren(indexedColors, 'rgbColor').length <= highestIndex){
2175
+ const index = directChildren(indexedColors, 'rgbColor').length;
2176
+ const element = styles.createElementNS(styles.documentElement.namespaceURI, 'rgbColor');
2177
+ element.setAttribute('rgb', `FF${(resolver.indexed[index] ?? '000000').toUpperCase()}`);
2178
+ indexedColors.append(element);
2179
+ stylesChanged = true;
2180
+ }
2181
+ const entries = directChildren(indexedColors, 'rgbColor');
2182
+ for (const [index, color] of candidates.indexed){
2183
+ const expected = `FF${color.slice(1).toUpperCase()}`;
2184
+ const entry = entries[index];
2185
+ if (entry) {
2186
+ if (attribute(entry, 'rgb')?.toUpperCase() !== expected) {
2187
+ entry.setAttribute('rgb', expected);
2188
+ stylesChanged = true;
2189
+ }
2190
+ supportedIndexed.set(index, color);
2191
+ }
2192
+ }
2193
+ }
2194
+ return {
2195
+ palette: {
2196
+ indexed: supportedIndexed,
2197
+ theme: supportedTheme
2198
+ },
2199
+ stylesChanged,
2200
+ themeChanged
2201
+ };
2000
2202
  }
2001
- function editableRangeRequiresCredentials(range) {
2002
- const attributes = range.xlsxAttributes ?? {};
2003
- return Boolean(attributes.password || attributes.hashValue || attributes.saltValue || attributes.securityDescriptor || attributes.securitydescriptor);
2203
+ function semanticPaletteCandidates(colors) {
2204
+ const theme = new Map();
2205
+ const indexed = new Map();
2206
+ const themeConflicts = new Set();
2207
+ const indexedConflicts = new Set();
2208
+ for (const color of colors){
2209
+ if ('automatic' === color.kind) continue;
2210
+ const target = 'theme' === color.kind ? theme : indexed;
2211
+ const conflicts = 'theme' === color.kind ? themeConflicts : indexedConflicts;
2212
+ const current = target.get(color.index);
2213
+ if (current && current.toLowerCase() !== color.baseColor.toLowerCase()) conflicts.add(color.index);
2214
+ else if (!current) target.set(color.index, color.baseColor);
2215
+ }
2216
+ for (const index of themeConflicts)theme.delete(index);
2217
+ for (const index of indexedConflicts)indexed.delete(index);
2218
+ return {
2219
+ indexed,
2220
+ theme
2221
+ };
2004
2222
  }
2005
- function sheetHasProtectionState(sheet) {
2006
- const authority = sheetProtectionAuthority(sheet);
2007
- if (1 === authority.sheet || authority.allowRangeList.length || Object.keys(authority.xlsxAttributes ?? {}).length) return true;
2008
- return (sheet.data ?? []).some((row)=>row.some((cell)=>cell?.lo !== void 0 || cell?.hi !== void 0));
2223
+ function xlsxCellStyleOriginSemanticColors(origin) {
2224
+ return [
2225
+ origin.fontColor,
2226
+ origin.fillColor,
2227
+ ...Object.values(origin.borderColors ?? {})
2228
+ ].filter((value)=>Boolean(value));
2009
2229
  }
2010
- function protectedSheetCount(sheets) {
2011
- return sheets.filter((sheet)=>1 === sheetProtectionAuthority(sheet).sheet).length;
2230
+ function writeThemeColor(entry, color) {
2231
+ const current = directChildren(entry)[0];
2232
+ if (current?.localName === 'srgbClr' && attribute(current, 'val')?.toLowerCase() === color.slice(1).toLowerCase()) return false;
2233
+ for (const child of directChildren(entry))child.remove();
2234
+ const qualifiedName = entry.prefix ? `${entry.prefix}:srgbClr` : 'srgbClr';
2235
+ const replacement = entry.ownerDocument.createElementNS(entry.namespaceURI, qualifiedName);
2236
+ replacement.setAttribute('val', color.slice(1).toUpperCase());
2237
+ entry.append(replacement);
2238
+ return true;
2012
2239
  }
2013
- function unlockedCellCount(sheet) {
2014
- return (sheet.data ?? []).reduce((total, row)=>total + row.reduce((rowTotal, cell)=>rowTotal + (cell?.lo === 0 ? 1 : 0), 0), 0);
2240
+ function normalizedBorderColors(value) {
2241
+ if (!isRecord(value)) return;
2242
+ const result = {};
2243
+ for (const side of [
2244
+ 'bottom',
2245
+ 'diagonal',
2246
+ 'left',
2247
+ 'right',
2248
+ 'top'
2249
+ ]){
2250
+ const color = normalizeXlsxSemanticColorOrigin(value[side]);
2251
+ if (color) result[side] = color;
2252
+ }
2253
+ return Object.keys(result).length ? result : void 0;
2015
2254
  }
2016
- function spreadsheetProtectionKey(sheets) {
2017
- return sheets.map((sheet)=>{
2018
- const authority = sheetProtectionAuthority(sheet);
2019
- const profile = spreadsheetMatrixProfile(sheet.data);
2020
- let protectionCellKey = profile?.protectionCellKey;
2021
- if (void 0 === protectionCellKey) {
2022
- const cells = [];
2023
- for (const [row, values] of spreadsheet_sparse_sparseArrayEntries(sheet.data))for (const [column, cell] of spreadsheet_sparse_sparseArrayEntries(values)){
2024
- const hidden = cell?.hi;
2025
- if (cell?.lo !== void 0 || void 0 !== hidden) cells.push(`${row}_${column}:${cell?.lo ?? ''}:${hidden ?? ''}`);
2026
- }
2027
- protectionCellKey = cells.join(',');
2255
+ function normalizeXlsxSemanticColorOrigin(value) {
2256
+ if (!isRecord(value)) return;
2257
+ const baseColor = work_xlsx_cell_style_origin_normalizedColor(value.baseColor);
2258
+ const renderedColor = work_xlsx_cell_style_origin_normalizedColor(value.renderedColor);
2259
+ const tint = normalizedTint(value.tint);
2260
+ if (!baseColor || !renderedColor || void 0 === tint) return;
2261
+ if ('automatic' === value.kind) return {
2262
+ kind: 'automatic',
2263
+ baseColor,
2264
+ renderedColor,
2265
+ ...null === tint ? {} : {
2266
+ tint
2028
2267
  }
2029
- return `${sheet.id ?? sheet.name}:${JSON.stringify(authority)}:${protectionCellKey}`;
2030
- }).join('|');
2031
- }
2032
- function editableRangeCellCount(ranges) {
2033
- return ranges.reduce((total, range)=>total + (range.row[1] - range.row[0] + 1) * (range.column[1] - range.column[0] + 1), 0);
2034
- }
2035
- function withAuthority(sheet, authority) {
2268
+ };
2269
+ const maximum = 'theme' === value.kind ? THEME_COLOR_NAMES.length - 1 : MAX_INDEXED_COLOR;
2270
+ const index = boundedNumber(value.index, maximum);
2271
+ if ('theme' !== value.kind && 'indexed' !== value.kind || null === index) return;
2036
2272
  return {
2037
- ...sheet,
2038
- config: {
2039
- ...sheet.config ?? {},
2040
- authority
2273
+ kind: value.kind,
2274
+ baseColor,
2275
+ index,
2276
+ renderedColor,
2277
+ ...null === tint ? {} : {
2278
+ tint
2041
2279
  }
2042
2280
  };
2043
2281
  }
2044
- function editableRangeList(value) {
2045
- if (!Array.isArray(value)) return [];
2046
- return value.flatMap((item, index)=>{
2047
- if (!item || 'object' != typeof item) return [];
2048
- const range = item;
2049
- const sqref = stringValue(range.sqref);
2050
- if (!sqref || !work_spreadsheet_ranges_parseSpreadsheetCellRanges(sqref)) return [];
2051
- return [
2052
- {
2053
- name: stringValue(range.name) || `Range ${index + 1}`,
2054
- sqref: canonicalRangeReference(sqref),
2055
- hintText: stringValue(range.hintText) || void 0,
2056
- xlsxAttributes: stringRecord(range.xlsxAttributes)
2057
- }
2058
- ];
2059
- });
2060
- }
2061
- function canonicalRangeReference(value) {
2062
- const ranges = work_spreadsheet_ranges_parseSpreadsheetCellRanges(value);
2063
- return ranges ? formatSpreadsheetCellRanges(ranges) : value.trim();
2282
+ function xlsxCellStyleOriginHasValues(origin) {
2283
+ return Boolean(origin.fontColor || origin.fillColor || Object.keys(origin.borderColors ?? {}).length);
2064
2284
  }
2065
- function normalizeMatrix(data, rows, columns) {
2066
- data.length = Math.max(data.length, rows);
2067
- for (const [, row] of spreadsheet_sparse_sparseArrayEntries(data))row.length = Math.max(row.length, columns);
2285
+ function work_xlsx_cell_style_origin_normalizedColor(value) {
2286
+ const rgb = xlsxRgbColor(value);
2287
+ return rgb ? `#${rgb.slice(-6).toLowerCase()}` : null;
2068
2288
  }
2069
- function cellProtectionRangeList(value) {
2070
- if (!Array.isArray(value)) return [];
2071
- return value.flatMap((item)=>{
2072
- if (!item || 'object' != typeof item) return [];
2073
- const candidate = item;
2074
- const range = candidate.range;
2075
- if (!range || !Array.isArray(range.row) || !Array.isArray(range.column) || range.row.length < 2 || range.column.length < 2 || ![
2076
- ...range.row,
2077
- ...range.column
2078
- ].every((index)=>Number.isSafeInteger(index) && index >= 0)) return [];
2079
- return [
2080
- {
2081
- range: {
2082
- row: [
2083
- Math.min(range.row[0], range.row[1]),
2084
- Math.max(range.row[0], range.row[1])
2085
- ],
2086
- column: [
2087
- Math.min(range.column[0], range.column[1]),
2088
- Math.max(range.column[0], range.column[1])
2089
- ]
2090
- },
2091
- locked: false !== candidate.locked,
2092
- hidden: true === candidate.hidden
2093
- }
2094
- ];
2095
- });
2289
+ function normalizedTint(value) {
2290
+ if (void 0 === value) return null;
2291
+ return 'number' == typeof value && Number.isFinite(value) && value >= -1 && value <= 1 ? value : void 0;
2096
2292
  }
2097
- function flag(value, fallback) {
2098
- if (1 === value || true === value || '1' === value) return 1;
2099
- if (0 === value || false === value || '0' === value) return 0;
2100
- return fallback;
2293
+ function boundedTint(value) {
2294
+ if (null === value) return null;
2295
+ const tint = Number(value);
2296
+ return Number.isFinite(tint) && tint >= -1 && tint <= 1 ? tint : null;
2101
2297
  }
2102
- function stringValue(value) {
2103
- return 'string' == typeof value ? value : '';
2298
+ function work_xlsx_cell_style_origin_boundedInteger(value, maximum) {
2299
+ if (null === value || !/^\d+$/.test(value)) return null;
2300
+ return boundedNumber(Number(value), maximum);
2104
2301
  }
2105
- function stringRecord(value) {
2106
- if (!value || 'object' != typeof value || Array.isArray(value)) return;
2107
- const entries = Object.entries(value).filter((entry)=>'string' == typeof entry[1]);
2108
- return entries.length ? Object.fromEntries(entries) : void 0;
2302
+ function boundedNumber(value, maximum) {
2303
+ return 'number' == typeof value && Number.isSafeInteger(value) && value >= 0 && value <= maximum ? value : null;
2109
2304
  }
2110
- const MILLISECONDS_PER_DAY = 86400000;
2111
- function normalizeSpreadsheetDateValidationBoundary(value, uses1904DateSystem = false) {
2112
- const trimmed = value.trim().replace(/^=/, '');
2113
- const iso = normalizeIsoDate(trimmed);
2114
- if (iso) return iso;
2115
- const formula = /^DATE\((\d{4}),\s*(\d{1,2}),\s*(\d{1,2})\)$/i.exec(trimmed);
2116
- if (formula) return normalizeIsoDate(`${formula[1]}-${String(formula[2]).padStart(2, '0')}-${String(formula[3]).padStart(2, '0')}`);
2117
- const serial = Number(trimmed);
2118
- if (!Number.isInteger(serial) || serial < 0) return null;
2119
- if (!uses1904DateSystem && (0 === serial || 60 === serial)) return null;
2120
- const adjustedSerial = uses1904DateSystem ? serial : serial > 60 ? serial - 1 : serial;
2121
- const epoch = uses1904DateSystem ? Date.UTC(1904, 0, 1) : Date.UTC(1899, 11, 31);
2122
- return isoDateFromTimestamp(epoch + adjustedSerial * MILLISECONDS_PER_DAY);
2305
+ function xlsxBooleanAttribute(element, name) {
2306
+ const value = attribute(element, name)?.trim().toLowerCase();
2307
+ return '1' === value || 'true' === value || 'on' === value;
2123
2308
  }
2124
- function spreadsheetDateValidationFormula(value) {
2125
- const normalized = normalizeIsoDate(value.trim());
2126
- if (!normalized) return value.trim().replace(/^=/, '');
2127
- const [year, month, day] = normalized.split('-');
2128
- return `DATE(${year},${Number(month)},${Number(day)})`;
2309
+ function isRecord(value) {
2310
+ return 'object' == typeof value && null !== value && !Array.isArray(value);
2129
2311
  }
2130
- function normalizeIsoDate(value) {
2131
- const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
2132
- if (!match) return null;
2133
- const timestamp = Date.UTC(Number(match[1]), Number(match[2]) - 1, Number(match[3]));
2134
- const normalized = isoDateFromTimestamp(timestamp);
2135
- return normalized === value ? normalized : null;
2312
+ const XLSX_GRADIENT_FILL_CELL_KEY = 'a3sXlsxGradientFill';
2313
+ const MAX_XLSX_GRADIENT_STOPS = 256;
2314
+ function readXlsxGradientFill(element, colors) {
2315
+ if (!element) return;
2316
+ const type = attribute(element, 'type') ?? 'linear';
2317
+ if ('linear' !== type && 'path' !== type) return;
2318
+ const children = directChildren(element);
2319
+ if (children.length < 2 || children.length > MAX_XLSX_GRADIENT_STOPS || children.some((child)=>'stop' !== child.localName)) return;
2320
+ const stops = [];
2321
+ for (const stop of children){
2322
+ const position = unitInterval(attribute(stop, 'position'));
2323
+ const stopChildren = directChildren(stop);
2324
+ const colorElement = stopChildren[0];
2325
+ if (null === position || 1 !== stopChildren.length || colorElement?.localName !== 'color') return;
2326
+ const renderedColor = resolveXlsxColor(colorElement, colors);
2327
+ const color = work_xlsx_gradient_fill_normalizedColor(renderedColor);
2328
+ if (!color || (stops.at(-1)?.position ?? 0) > position) return;
2329
+ const colorOrigin = readXlsxSemanticColorOrigin(colorElement, colors);
2330
+ stops.push({
2331
+ color,
2332
+ ...colorOrigin ? {
2333
+ colorOrigin
2334
+ } : {},
2335
+ position
2336
+ });
2337
+ }
2338
+ if ('linear' === type) {
2339
+ const degree = optionalFiniteNumber(attribute(element, 'degree'), 0);
2340
+ return null === degree ? void 0 : {
2341
+ degree,
2342
+ stops,
2343
+ type
2344
+ };
2345
+ }
2346
+ const left = optionalUnitInterval(attribute(element, 'left'), 0);
2347
+ const right = optionalUnitInterval(attribute(element, 'right'), 0);
2348
+ const top = optionalUnitInterval(attribute(element, 'top'), 0);
2349
+ const bottom = optionalUnitInterval(attribute(element, 'bottom'), 0);
2350
+ if (null === left || null === right || null === top || null === bottom || left > right || top > bottom) return;
2351
+ return {
2352
+ bottom,
2353
+ left,
2354
+ right,
2355
+ stops,
2356
+ top,
2357
+ type
2358
+ };
2136
2359
  }
2137
- function isoDateFromTimestamp(timestamp) {
2138
- const date = new Date(timestamp);
2139
- const year = date.getUTCFullYear();
2140
- if (!Number.isFinite(timestamp) || year < 1900 || year > 9999) return null;
2141
- return `${String(year).padStart(4, '0')}-${String(date.getUTCMonth() + 1).padStart(2, '0')}-${String(date.getUTCDate()).padStart(2, '0')}`;
2360
+ function withXlsxGradientFill(cell, fill) {
2361
+ const normalized = normalizeXlsxGradientFill(fill);
2362
+ return normalized ? {
2363
+ ...cell,
2364
+ [XLSX_GRADIENT_FILL_CELL_KEY]: normalized
2365
+ } : cell;
2142
2366
  }
2143
- const A3S_DIAGONAL_BORDER_KEY = 'a3sDiagonal';
2144
- function spreadsheetDiagonalBorderFromCellValue(value) {
2145
- if (!isRecord(value)) return;
2146
- const metadata = value[A3S_DIAGONAL_BORDER_KEY];
2147
- if (isRecord(metadata)) {
2148
- const up = metadata.up;
2149
- const down = metadata.down;
2150
- const line = spreadsheetDiagonalBorderLine(metadata.line);
2151
- if ('boolean' == typeof up && 'boolean' == typeof down) {
2152
- if (!up && !down) return null;
2153
- if (line) return {
2154
- down,
2155
- line,
2156
- up
2157
- };
2158
- }
2367
+ function deleteXlsxGradientFill(cell) {
2368
+ delete cell[XLSX_GRADIENT_FILL_CELL_KEY];
2369
+ }
2370
+ function xlsxGradientFill(cell) {
2371
+ return normalizeXlsxGradientFill(cell?.[XLSX_GRADIENT_FILL_CELL_KEY]);
2372
+ }
2373
+ function activeXlsxGradientFill(cell) {
2374
+ const fill = xlsxGradientFill(cell);
2375
+ return fill && work_xlsx_gradient_fill_normalizedColor(cell?.bg) === xlsxGradientFillFallbackColor(fill) ? fill : void 0;
2376
+ }
2377
+ function normalizeXlsxGradientFill(value) {
2378
+ if (!work_xlsx_gradient_fill_isRecord(value) || !Array.isArray(value.stops)) return;
2379
+ if (value.stops.length < 2 || value.stops.length > MAX_XLSX_GRADIENT_STOPS) return;
2380
+ const stops = [];
2381
+ for (const valueStop of value.stops){
2382
+ if (!work_xlsx_gradient_fill_isRecord(valueStop)) return;
2383
+ const position = normalizedUnitInterval(valueStop.position);
2384
+ const color = work_xlsx_gradient_fill_normalizedColor(valueStop.color);
2385
+ if (null === position || !color || (stops.at(-1)?.position ?? 0) > position) return;
2386
+ const colorOrigin = normalizeXlsxSemanticColorOrigin(valueStop.colorOrigin);
2387
+ stops.push({
2388
+ color,
2389
+ ...colorOrigin ? {
2390
+ colorOrigin
2391
+ } : {},
2392
+ position
2393
+ });
2159
2394
  }
2160
- if (null === value.s) return null;
2161
- const legacyLine = spreadsheetDiagonalBorderLine(value.s);
2162
- return legacyLine ? {
2163
- down: true,
2164
- line: legacyLine,
2165
- up: false
2166
- } : void 0;
2167
- }
2168
- function spreadsheetCellValueWithDiagonalBorder(value, border) {
2169
- const next = {
2170
- ...value
2171
- };
2172
- delete next.s;
2173
- delete next[A3S_DIAGONAL_BORDER_KEY];
2174
- if (!border) return next;
2175
- const line = {
2176
- ...border.line
2177
- };
2178
- next[A3S_DIAGONAL_BORDER_KEY] = {
2179
- down: border.down,
2180
- line,
2181
- up: border.up
2395
+ if ('linear' === value.type) {
2396
+ const degree = finiteNumber(value.degree);
2397
+ return null === degree ? void 0 : {
2398
+ degree,
2399
+ stops,
2400
+ type: 'linear'
2401
+ };
2402
+ }
2403
+ if ('path' !== value.type) return;
2404
+ const left = normalizedUnitInterval(value.left);
2405
+ const right = normalizedUnitInterval(value.right);
2406
+ const top = normalizedUnitInterval(value.top);
2407
+ const bottom = normalizedUnitInterval(value.bottom);
2408
+ if (null === left || null === right || null === top || null === bottom || left > right || top > bottom) return;
2409
+ return {
2410
+ bottom,
2411
+ left,
2412
+ right,
2413
+ stops,
2414
+ top,
2415
+ type: 'path'
2182
2416
  };
2183
- if (border.down) next.s = line;
2184
- return next;
2185
2417
  }
2186
- function spreadsheetDiagonalBorderLine(value) {
2187
- if (!isRecord(value)) return null;
2188
- return 'string' == typeof value.color && 'string' == typeof value.style ? {
2189
- color: value.color,
2190
- style: value.style
2191
- } : null;
2418
+ function xlsxGradientFillFallbackColor(fill) {
2419
+ return fill.stops[0]?.color ?? '#ffffff';
2192
2420
  }
2193
- function isRecord(value) {
2194
- return Boolean(value && 'object' == typeof value && !Array.isArray(value));
2421
+ function xlsxGradientFillSemanticColors(fill) {
2422
+ return (fill?.stops ?? []).flatMap((stop)=>stop.colorOrigin ? [
2423
+ stop.colorOrigin
2424
+ ] : []);
2195
2425
  }
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;
2426
+ function xlsxGradientFillKey(fill) {
2427
+ if (!fill) return '';
2428
+ const geometry = 'linear' === fill.type ? `linear:${fill.degree}` : `path:${fill.left}:${fill.right}:${fill.top}:${fill.bottom}`;
2429
+ return `${geometry}:${fill.stops.map((stop)=>`${stop.position}:${stop.color}:${xlsxSemanticColorOriginKey(stop.colorOrigin)}`).join('|')}`;
2215
2430
  }
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;
2431
+ function unitInterval(value) {
2432
+ if (null === value || !value.trim()) return null;
2433
+ return normalizedUnitInterval(Number(value));
2222
2434
  }
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;
2435
+ function optionalUnitInterval(value, fallback) {
2436
+ return null === value ? fallback : unitInterval(value);
2233
2437
  }
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);
2438
+ function normalizedUnitInterval(value) {
2439
+ return 'number' == typeof value && Number.isFinite(value) && value >= 0 && value <= 1 ? value : null;
2247
2440
  }
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));
2441
+ function optionalFiniteNumber(value, fallback) {
2442
+ if (null === value) return fallback;
2443
+ if (!value.trim()) return null;
2444
+ return finiteNumber(Number(value));
2261
2445
  }
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);
2446
+ function finiteNumber(value) {
2447
+ return 'number' == typeof value && Number.isFinite(value) ? value : null;
2267
2448
  }
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);
2449
+ function work_xlsx_gradient_fill_normalizedColor(value) {
2450
+ const rgb = xlsxRgbColor(value);
2451
+ return rgb ? `#${rgb.slice(-6).toLowerCase()}` : null;
2273
2452
  }
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);
2453
+ function work_xlsx_gradient_fill_isRecord(value) {
2454
+ return 'object' == typeof value && null !== value && !Array.isArray(value);
2455
+ }
2456
+ const XLSX_PATTERN_FILL_CELL_KEY = 'a3sXlsxPatternFill';
2457
+ const xlsxPatternFillTypes = [
2458
+ 'darkDown',
2459
+ 'darkGray',
2460
+ 'darkGrid',
2461
+ 'darkHorizontal',
2462
+ 'darkTrellis',
2463
+ 'darkUp',
2464
+ 'darkVertical',
2465
+ 'gray0625',
2466
+ 'gray125',
2467
+ 'lightDown',
2468
+ 'lightGray',
2469
+ 'lightGrid',
2470
+ 'lightHorizontal',
2471
+ 'lightTrellis',
2472
+ 'lightUp',
2473
+ 'lightVertical',
2474
+ 'mediumGray'
2475
+ ];
2476
+ const xlsxPatternFillTypeSet = new Set(xlsxPatternFillTypes);
2477
+ function readXlsxPatternFill(pattern, colors) {
2478
+ if (!pattern) return;
2479
+ const patternType = attribute(pattern, 'patternType');
2480
+ if (!patternType || !isXlsxPatternFillType(patternType)) return;
2481
+ const foreground = directChild(pattern, 'fgColor');
2482
+ const background = directChild(pattern, 'bgColor');
2483
+ const foregroundColor = foreground ? resolveXlsxColor(foreground, colors) : '#000000';
2484
+ const backgroundColor = background ? resolveXlsxColor(background, colors) : '#ffffff';
2485
+ const normalizedForegroundColor = work_xlsx_pattern_fill_normalizedColor(foregroundColor);
2486
+ const normalizedBackgroundColor = work_xlsx_pattern_fill_normalizedColor(backgroundColor);
2487
+ if (!normalizedForegroundColor || !normalizedBackgroundColor) return;
2488
+ const foregroundColorOrigin = readXlsxSemanticColorOrigin(foreground, colors);
2489
+ const backgroundColorOrigin = readXlsxSemanticColorOrigin(background, colors);
2490
+ return {
2491
+ backgroundColor: normalizedBackgroundColor,
2492
+ ...backgroundColorOrigin ? {
2493
+ backgroundColorOrigin
2494
+ } : {},
2495
+ foregroundColor: normalizedForegroundColor,
2496
+ ...foregroundColorOrigin ? {
2497
+ foregroundColorOrigin
2498
+ } : {},
2499
+ patternType
2500
+ };
2280
2501
  }
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);
2502
+ function withXlsxPatternFill(cell, fill) {
2503
+ const normalized = normalizeXlsxPatternFill(fill);
2504
+ return normalized ? {
2505
+ ...cell,
2506
+ [XLSX_PATTERN_FILL_CELL_KEY]: normalized
2507
+ } : cell;
2287
2508
  }
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;
2509
+ function deleteXlsxPatternFill(cell) {
2510
+ delete cell[XLSX_PATTERN_FILL_CELL_KEY];
2297
2511
  }
2298
- function removeXlsxChildren(parent, name) {
2299
- for (const child of directChildren(parent, name))child.remove();
2512
+ function xlsxPatternFill(cell) {
2513
+ return normalizeXlsxPatternFill(cell?.[XLSX_PATTERN_FILL_CELL_KEY]);
2300
2514
  }
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);
2515
+ function activeXlsxPatternFill(cell) {
2516
+ const fill = xlsxPatternFill(cell);
2517
+ return fill && work_xlsx_pattern_fill_normalizedColor(cell?.bg) === fill.backgroundColor ? fill : void 0;
2305
2518
  }
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) {
2519
+ function normalizeXlsxPatternFill(value) {
2520
+ if (!work_xlsx_pattern_fill_isRecord(value) || !isXlsxPatternFillType(value.patternType)) return;
2521
+ const foregroundColor = work_xlsx_pattern_fill_normalizedColor(value.foregroundColor);
2522
+ const backgroundColor = work_xlsx_pattern_fill_normalizedColor(value.backgroundColor);
2523
+ if (!foregroundColor || !backgroundColor) return;
2524
+ const foregroundColorOrigin = normalizeXlsxSemanticColorOrigin(value.foregroundColorOrigin);
2525
+ const backgroundColorOrigin = normalizeXlsxSemanticColorOrigin(value.backgroundColorOrigin);
2401
2526
  return {
2402
- indexed: styles ? readIndexedColors(styles) : defaultIndexedColors,
2403
- theme: readThemeColors(theme)
2527
+ backgroundColor,
2528
+ ...backgroundColorOrigin ? {
2529
+ backgroundColorOrigin
2530
+ } : {},
2531
+ foregroundColor,
2532
+ ...foregroundColorOrigin ? {
2533
+ foregroundColorOrigin
2534
+ } : {},
2535
+ patternType: value.patternType
2404
2536
  };
2405
2537
  }
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}`;
2538
+ function xlsxPatternFillSemanticColors(fill) {
2539
+ return fill ? [
2540
+ fill.foregroundColorOrigin,
2541
+ fill.backgroundColorOrigin
2542
+ ].filter((value)=>Boolean(value)) : [];
2543
+ }
2544
+ function xlsxPatternFillKey(fill) {
2545
+ return fill ? [
2546
+ fill.patternType,
2547
+ fill.foregroundColor,
2548
+ xlsxSemanticColorOriginKey(fill.foregroundColorOrigin),
2549
+ fill.backgroundColor,
2550
+ xlsxSemanticColorOriginKey(fill.backgroundColorOrigin)
2551
+ ].join(':') : '';
2552
+ }
2553
+ function isXlsxPatternFillType(value) {
2554
+ return 'string' == typeof value && xlsxPatternFillTypeSet.has(value);
2555
+ }
2556
+ function work_xlsx_pattern_fill_normalizedColor(value) {
2557
+ const rgb = xlsxRgbColor(value);
2558
+ return rgb ? `#${rgb.slice(-6).toLowerCase()}` : null;
2416
2559
  }
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];
2560
+ function work_xlsx_pattern_fill_isRecord(value) {
2561
+ return 'object' == typeof value && null !== value && !Array.isArray(value);
2562
+ }
2563
+ const SPREADSHEET_SHOWN_COMMENT_CELLS_PROPERTY = '__a3sShownCommentCells';
2564
+ const spreadsheetMatrixProfiles = new WeakMap();
2565
+ function freezeImportedSpreadsheetCell(cell) {
2566
+ const gradientFill = cell[XLSX_GRADIENT_FILL_CELL_KEY];
2567
+ if (gradientFill && 'object' == typeof gradientFill) {
2568
+ const stops = gradientFill.stops;
2569
+ if (Array.isArray(stops)) {
2570
+ for (const stop of stops)if (stop && 'object' == typeof stop) {
2571
+ freezeObject(stop.colorOrigin);
2572
+ freezeObject(stop);
2573
+ }
2574
+ Object.freeze(stops);
2575
+ }
2576
+ }
2577
+ freezeObject(gradientFill);
2578
+ const patternFill = cell[XLSX_PATTERN_FILL_CELL_KEY];
2579
+ if (patternFill && 'object' == typeof patternFill) {
2580
+ const record = patternFill;
2581
+ freezeObject(record.foregroundColorOrigin);
2582
+ freezeObject(record.backgroundColorOrigin);
2583
+ }
2584
+ freezeObject(patternFill);
2585
+ freezeObject(cell.mc);
2586
+ freezeObject(cell.ct?.s);
2587
+ freezeObject(cell.ct);
2588
+ freezeObject(cell.ps);
2589
+ freezeObject(cell.hl);
2590
+ freezeObject(cell.spl);
2591
+ return Object.freeze(cell);
2592
+ }
2593
+ function registerImportedSpreadsheetMatrix(data, options) {
2594
+ data.length = Math.max(data.length, options.rowCount);
2595
+ data[0] ??= [];
2596
+ for (const rowIndex of sparseArrayIndexes(data)){
2597
+ const row = data[rowIndex];
2598
+ if (row) {
2599
+ row.length = Math.max(row.length, options.columnCount);
2600
+ Object.freeze(row);
2601
+ }
2602
+ }
2603
+ registerSpreadsheetMatrixProfile(data, options);
2604
+ }
2605
+ function registerDerivedSpreadsheetMatrix(data, source, changes) {
2606
+ const sourceProfile = spreadsheetMatrixProfiles.get(source);
2607
+ if (!sourceProfile?.fortuneReady) return false;
2608
+ const formulaCells = new Map(sourceProfile.formulaCells.map(({ column, row })=>[
2609
+ spreadsheetCoordinateKey(row, column),
2610
+ {
2611
+ column,
2612
+ row
2613
+ }
2614
+ ]));
2615
+ const shownCommentCells = new Map(sourceProfile.shownCommentCells.map(({ c, r })=>[
2616
+ spreadsheetCoordinateKey(r, c),
2617
+ {
2618
+ c,
2619
+ r
2620
+ }
2621
+ ]));
2622
+ let populatedCellCount = sourceProfile.populatedCellCount;
2623
+ let protectionCellKey = sourceProfile.protectionCellKey;
2624
+ let protectionCells;
2625
+ for (const { column, current, previous, row } of changes){
2626
+ const coordinateKey = spreadsheetCoordinateKey(row, column);
2627
+ if (null == previous && null != current) populatedCellCount += 1;
2628
+ if (null != previous && null == current) populatedCellCount -= 1;
2629
+ if (current?.f) formulaCells.set(coordinateKey, {
2630
+ column,
2631
+ row
2632
+ });
2633
+ else formulaCells.delete(coordinateKey);
2634
+ if (current?.ps?.isShow) shownCommentCells.set(coordinateKey, {
2635
+ c: column,
2636
+ r: row
2637
+ });
2638
+ else shownCommentCells.delete(coordinateKey);
2639
+ if (spreadsheetProtectionSignature(previous) !== spreadsheetProtectionSignature(current)) {
2640
+ protectionCells ??= spreadsheetProtectionCells(protectionCellKey);
2641
+ const signature = spreadsheetProtectionSignature(current);
2642
+ if (null === signature) protectionCells.delete(coordinateKey);
2643
+ else protectionCells.set(coordinateKey, signature);
2644
+ }
2645
+ const changedRow = data[row];
2646
+ if (changedRow && !Object.isFrozen(changedRow)) Object.freeze(changedRow);
2647
+ }
2648
+ if (protectionCells) protectionCellKey = Array.from(protectionCells, ([coordinate, value])=>({
2649
+ coordinate,
2650
+ value
2651
+ })).sort((left, right)=>compareSpreadsheetCoordinates(left.coordinate, right.coordinate)).map(({ coordinate, value })=>`${coordinate}:${value}`).join(',');
2652
+ registerSpreadsheetMatrixProfile(data, {
2653
+ columnCount: Math.max(sourceProfile.columnCount, ...changes.map(({ column, row })=>Math.max(column + 1, data[row]?.length ?? 0))),
2654
+ formulaCells: Array.from(formulaCells.values()).sort(compareSpreadsheetCells),
2655
+ fortuneReady: true,
2656
+ populatedCellCount: Math.max(0, populatedCellCount),
2657
+ protectionCellKey,
2658
+ rowCount: Math.max(sourceProfile.rowCount, data.length, ...changes.map(({ row })=>row + 1)),
2659
+ shownCommentCells: Array.from(shownCommentCells.values()).sort((left, right)=>left.r - right.r || left.c - right.c)
2660
+ }, {
2661
+ historyRoot: sourceProfile.historyRoot,
2662
+ historyState: changes.some(({ current, previous })=>!sameSpreadsheetHistoryValue(current, previous)) ? Object.freeze({}) : sourceProfile.historyState
2663
+ });
2664
+ return true;
2665
+ }
2666
+ function spreadsheetMatrixProfile(data) {
2667
+ return data ? spreadsheetMatrixProfiles.get(data) : void 0;
2668
+ }
2669
+ function attachSpreadsheetShownCommentCells(data, cells) {
2670
+ Object.defineProperty(data, SPREADSHEET_SHOWN_COMMENT_CELLS_PROPERTY, {
2671
+ configurable: false,
2672
+ enumerable: false,
2673
+ value: cells,
2674
+ writable: false
2675
+ });
2676
+ }
2677
+ function registerSpreadsheetMatrixProfile(data, options, history) {
2678
+ const initialHistoryState = Object.freeze({});
2679
+ const profile = Object.freeze({
2680
+ columnCount: options.columnCount,
2681
+ formulaCells: Object.freeze(options.formulaCells.map((cell)=>Object.freeze({
2682
+ ...cell
2683
+ }))),
2684
+ fortuneReady: options.fortuneReady,
2685
+ historyRoot: history?.historyRoot ?? initialHistoryState,
2686
+ historyState: history?.historyState ?? initialHistoryState,
2687
+ populatedCellCount: options.populatedCellCount,
2688
+ protectionCellKey: options.protectionCellKey,
2689
+ rowCount: options.rowCount,
2690
+ shownCommentCells: Object.freeze(options.shownCommentCells.map((cell)=>Object.freeze({
2691
+ ...cell
2692
+ })))
2425
2693
  });
2694
+ attachSpreadsheetShownCommentCells(data, profile.shownCommentCells);
2695
+ Object.freeze(data);
2696
+ spreadsheetMatrixProfiles.set(data, profile);
2426
2697
  }
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;
2698
+ function spreadsheetProtectionCells(value) {
2699
+ const cells = new Map();
2700
+ for (const entry of value.split(',')){
2701
+ if (!entry) continue;
2702
+ const separator = entry.indexOf(':');
2703
+ if (!(separator <= 0)) cells.set(entry.slice(0, separator), entry.slice(separator + 1));
2704
+ }
2705
+ return cells;
2432
2706
  }
2433
- function drawingColor(element) {
2434
- if (!element) return;
2435
- return normalizedHexColor('sysClr' === element.localName ? attribute(element, 'lastClr') : attribute(element, 'val'));
2707
+ function spreadsheetProtectionSignature(cell) {
2708
+ const hidden = cell?.hi;
2709
+ if (cell?.lo === void 0 && void 0 === hidden) return null;
2710
+ return `${cell?.lo ?? ''}:${hidden ?? ''}`;
2436
2711
  }
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('');
2712
+ function spreadsheetCoordinateKey(row, column) {
2713
+ return `${row}_${column}`;
2445
2714
  }
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
- ];
2715
+ function compareSpreadsheetCoordinates(left, right) {
2716
+ const [leftRow = 0, leftColumn = 0] = left.split('_').map(Number);
2717
+ const [rightRow = 0, rightColumn = 0] = right.split('_').map(Number);
2718
+ return leftRow - rightRow || leftColumn - rightColumn;
2463
2719
  }
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;
2720
+ function compareSpreadsheetCells(left, right) {
2721
+ return left.row - right.row || left.column - right.column;
2506
2722
  }
2507
- function normalizedHexColor(value) {
2508
- if (!value || !/^[0-9a-f]{6,8}$/i.test(value)) return;
2509
- return value.slice(-6).toLowerCase();
2723
+ function freezeObject(value) {
2724
+ if (value && 'object' == typeof value) Object.freeze(value);
2510
2725
  }
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;
2726
+ const DEFAULT_PROTECTION_HINT = '此工作表已受保护。若要更改锁定的单元格,请先取消工作表保护。';
2727
+ function defaultSheetProtectionAuthority(enabled = false) {
2728
+ return {
2729
+ sheet: enabled ? 1 : 0,
2730
+ selectLockedCells: 1,
2731
+ selectunLockedCells: 1,
2732
+ formatCells: 0,
2733
+ formatColumns: 0,
2734
+ formatRows: 0,
2735
+ insertColumns: 0,
2736
+ insertRows: 0,
2737
+ insertHyperlinks: 0,
2738
+ deleteColumns: 0,
2739
+ deleteRows: 0,
2740
+ sort: 0,
2741
+ filter: 0,
2742
+ usePivotTablereports: 0,
2743
+ editObjects: 0,
2744
+ editScenarios: 0,
2745
+ hintText: '',
2746
+ defaultSheetHintText: DEFAULT_PROTECTION_HINT,
2747
+ allowRangeList: [],
2748
+ cellProtectionRanges: []
2749
+ };
2515
2750
  }
2516
- function booleanAttribute(element, name) {
2517
- const value = attribute(element, name)?.trim().toLowerCase();
2518
- return '1' === value || 'true' === value || 'on' === value;
2751
+ function sheetProtectionAuthority(sheet) {
2752
+ return normalizeSheetProtectionAuthority(sheet.config?.authority);
2519
2753
  }
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
- }
2754
+ function normalizeSheetProtectionAuthority(source) {
2755
+ const defaults = defaultSheetProtectionAuthority();
2756
+ if (!source || 'object' != typeof source) return defaults;
2757
+ const authority = source;
2758
+ return {
2759
+ sheet: flag(authority.sheet, defaults.sheet),
2760
+ selectLockedCells: flag(authority.selectLockedCells, defaults.selectLockedCells),
2761
+ selectunLockedCells: flag(authority.selectunLockedCells, defaults.selectunLockedCells),
2762
+ formatCells: flag(authority.formatCells, defaults.formatCells),
2763
+ formatColumns: flag(authority.formatColumns, defaults.formatColumns),
2764
+ formatRows: flag(authority.formatRows, defaults.formatRows),
2765
+ insertColumns: flag(authority.insertColumns, defaults.insertColumns),
2766
+ insertRows: flag(authority.insertRows, defaults.insertRows),
2767
+ insertHyperlinks: flag(authority.insertHyperlinks, defaults.insertHyperlinks),
2768
+ deleteColumns: flag(authority.deleteColumns, defaults.deleteColumns),
2769
+ deleteRows: flag(authority.deleteRows, defaults.deleteRows),
2770
+ sort: flag(authority.sort, defaults.sort),
2771
+ filter: flag(authority.filter, defaults.filter),
2772
+ usePivotTablereports: flag(authority.usePivotTablereports, defaults.usePivotTablereports),
2773
+ editObjects: flag(authority.editObjects, defaults.editObjects),
2774
+ editScenarios: flag(authority.editScenarios, defaults.editScenarios),
2775
+ hintText: stringValue(authority.hintText),
2776
+ defaultSheetHintText: stringValue(authority.defaultSheetHintText) || DEFAULT_PROTECTION_HINT,
2777
+ allowRangeList: editableRangeList(authority.allowRangeList),
2778
+ cellProtectionRanges: cellProtectionRangeList(authority.cellProtectionRanges),
2779
+ xlsxAttributes: stringRecord(authority.xlsxAttributes)
2567
2780
  };
2568
2781
  }
2569
- function withXlsxCellStyleOrigin(cell, origin) {
2570
- return origin && xlsxCellStyleOriginHasValues(origin) ? {
2571
- ...cell,
2572
- a3sXlsxStyleOrigin: origin
2573
- } : cell;
2782
+ function importedSheetProtectionAuthority(authority, cellProtectionRanges) {
2783
+ if (!authority && !cellProtectionRanges.length) return;
2784
+ const normalized = normalizeSheetProtectionAuthority(authority);
2785
+ normalized.cellProtectionRanges = [
2786
+ ...cellProtectionRanges,
2787
+ ...normalized.allowRangeList.filter((range)=>!editableRangeRequiresCredentials(range)).flatMap((range)=>work_spreadsheet_ranges_parseSpreadsheetCellRanges(range.sqref) ?? []).map((range)=>({
2788
+ range,
2789
+ locked: false,
2790
+ hidden: false
2791
+ }))
2792
+ ];
2793
+ return normalized;
2574
2794
  }
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
- } : {}
2795
+ function withSheetProtection(sheet, enabled) {
2796
+ const authority = sheetProtectionAuthority(sheet);
2797
+ authority.sheet = enabled ? 1 : 0;
2798
+ return withAuthority(sheet, authority);
2799
+ }
2800
+ function withSheetSelectionPermissions(sheet, permissions) {
2801
+ const authority = sheetProtectionAuthority(sheet);
2802
+ if (void 0 !== permissions.selectLockedCells) authority.selectLockedCells = permissions.selectLockedCells ? 1 : 0;
2803
+ if (void 0 !== permissions.selectUnlockedCells) authority.selectunLockedCells = permissions.selectUnlockedCells ? 1 : 0;
2804
+ return withAuthority(sheet, authority);
2805
+ }
2806
+ function withEditableRange(sheet, index, editableRange) {
2807
+ const authority = sheetProtectionAuthority(sheet);
2808
+ const nextRange = {
2809
+ name: editableRange.name.trim(),
2810
+ sqref: canonicalRangeReference(editableRange.sqref),
2811
+ hintText: editableRange.hintText?.trim() || void 0,
2812
+ xlsxAttributes: editableRange.xlsxAttributes
2591
2813
  };
2592
- return xlsxCellStyleOriginHasValues(origin) ? origin : void 0;
2814
+ if (null !== index && authority.allowRangeList[index]) authority.allowRangeList[index] = nextRange;
2815
+ else authority.allowRangeList.push(nextRange);
2816
+ const ranges = work_spreadsheet_ranges_parseSpreadsheetCellRanges(nextRange.sqref) ?? [];
2817
+ const next = withCellProtection(sheet, ranges, false);
2818
+ const nextAuthority = sheetProtectionAuthority(next);
2819
+ nextAuthority.allowRangeList = authority.allowRangeList;
2820
+ return withAuthority(next, nextAuthority);
2593
2821
  }
2594
- function xlsxSemanticColorMatchesValue(origin, value) {
2595
- return work_xlsx_cell_style_origin_normalizedColor(value) === origin.renderedColor.toLowerCase();
2822
+ function withoutEditableRange(sheet, index) {
2823
+ const authority = sheetProtectionAuthority(sheet);
2824
+ const removed = authority.allowRangeList[index];
2825
+ if (!removed) return sheet;
2826
+ authority.allowRangeList.splice(index, 1);
2827
+ const removedRanges = work_spreadsheet_ranges_parseSpreadsheetCellRanges(removed.sqref) ?? [];
2828
+ let next = withCellProtection(sheet, removedRanges, true);
2829
+ for (const editableRange of authority.allowRangeList)if (!editableRangeRequiresCredentials(editableRange)) next = withCellProtection(next, work_spreadsheet_ranges_parseSpreadsheetCellRanges(editableRange.sqref) ?? [], false);
2830
+ const nextAuthority = sheetProtectionAuthority(next);
2831
+ nextAuthority.allowRangeList = authority.allowRangeList;
2832
+ return withAuthority(next, nextAuthority);
2596
2833
  }
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);
2834
+ function withCellProtection(sheet, ranges, locked, hidden = false) {
2835
+ if (!ranges.length) return sheet;
2836
+ const data = cloneSparseMatrix(sheet.data);
2837
+ let rowCount = Math.max(sheet.row ?? 0, data.length);
2838
+ let columnCount = Math.max(sheet.column ?? 0, sparseMatrixColumnCount(data));
2839
+ for (const range of ranges){
2840
+ rowCount = Math.max(rowCount, range.row[1] + 1);
2841
+ columnCount = Math.max(columnCount, range.column[1] + 1);
2842
+ 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)){
2843
+ if (column < range.column[0] || column > range.column[1]) continue;
2844
+ const cell = {
2845
+ ...source ?? {}
2846
+ };
2847
+ cell.lo = locked ? 1 : 0;
2848
+ if (hidden) cell.hi = 1;
2849
+ else if (void 0 !== cell.hi) delete cell.hi;
2850
+ data[row][column] = cell;
2851
+ }
2852
+ }
2853
+ normalizeMatrix(data, rowCount, columnCount);
2854
+ const authority = sheetProtectionAuthority(sheet);
2855
+ authority.cellProtectionRanges.push(...ranges.map((range)=>({
2856
+ range,
2857
+ locked,
2858
+ hidden
2859
+ })));
2860
+ return withAuthority({
2861
+ ...sheet,
2862
+ row: rowCount,
2863
+ column: columnCount,
2864
+ data
2865
+ }, authority);
2606
2866
  }
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));
2867
+ function editableRangeRequiresCredentials(range) {
2868
+ const attributes = range.xlsxAttributes ?? {};
2869
+ return Boolean(attributes.password || attributes.hashValue || attributes.saltValue || attributes.securityDescriptor || attributes.securitydescriptor);
2619
2870
  }
2620
- function xlsxSemanticColorOriginKey(origin) {
2621
- return origin ? `${origin.kind}:${'index' in origin ? origin.index : ''}:${origin.baseColor}:${origin.renderedColor}:${origin.tint ?? ''}` : '';
2871
+ function sheetHasProtectionState(sheet) {
2872
+ const authority = sheetProtectionAuthority(sheet);
2873
+ if (1 === authority.sheet || authority.allowRangeList.length || Object.keys(authority.xlsxAttributes ?? {}).length) return true;
2874
+ return (sheet.data ?? []).some((row)=>row.some((cell)=>cell?.lo !== void 0 || cell?.hi !== void 0));
2622
2875
  }
2623
- function xlsxSemanticColorOriginSupported(origin, palette) {
2624
- if ('automatic' === origin.kind) return true;
2625
- return palette?.[origin.kind].get(origin.index)?.toLowerCase() === origin.baseColor.toLowerCase();
2876
+ function protectedSheetCount(sheets) {
2877
+ return sheets.filter((sheet)=>1 === sheetProtectionAuthority(sheet).sheet).length;
2626
2878
  }
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);
2879
+ function unlockedCellCount(sheet) {
2880
+ return (sheet.data ?? []).reduce((total, row)=>total + row.reduce((rowTotal, cell)=>rowTotal + (cell?.lo === 0 ? 1 : 0), 0), 0);
2881
+ }
2882
+ function spreadsheetProtectionKey(sheets) {
2883
+ return sheets.map((sheet)=>{
2884
+ const authority = sheetProtectionAuthority(sheet);
2885
+ const profile = spreadsheetMatrixProfile(sheet.data);
2886
+ let protectionCellKey = profile?.protectionCellKey;
2887
+ if (void 0 === protectionCellKey) {
2888
+ const cells = [];
2889
+ for (const [row, values] of spreadsheet_sparse_sparseArrayEntries(sheet.data))for (const [column, cell] of spreadsheet_sparse_sparseArrayEntries(values)){
2890
+ const hidden = cell?.hi;
2891
+ if (cell?.lo !== void 0 || void 0 !== hidden) cells.push(`${row}_${column}:${cell?.lo ?? ''}:${hidden ?? ''}`);
2671
2892
  }
2893
+ protectionCellKey = cells.join(',');
2672
2894
  }
2673
- }
2674
- return {
2675
- palette: {
2676
- indexed: supportedIndexed,
2677
- theme: supportedTheme
2678
- },
2679
- stylesChanged,
2680
- themeChanged
2681
- };
2895
+ return `${sheet.id ?? sheet.name}:${JSON.stringify(authority)}:${protectionCellKey}`;
2896
+ }).join('|');
2682
2897
  }
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);
2898
+ function editableRangeCellCount(ranges) {
2899
+ return ranges.reduce((total, range)=>total + (range.row[1] - range.row[0] + 1) * (range.column[1] - range.column[0] + 1), 0);
2900
+ }
2901
+ function withAuthority(sheet, authority) {
2698
2902
  return {
2699
- indexed,
2700
- theme
2903
+ ...sheet,
2904
+ config: {
2905
+ ...sheet.config ?? {},
2906
+ authority
2907
+ }
2701
2908
  };
2702
2909
  }
2703
- function xlsxCellStyleOriginColors(origin) {
2704
- return [
2705
- origin.fontColor,
2706
- origin.fillColor,
2707
- ...Object.values(origin.borderColors ?? {})
2708
- ].filter((value)=>Boolean(value));
2910
+ function editableRangeList(value) {
2911
+ if (!Array.isArray(value)) return [];
2912
+ return value.flatMap((item, index)=>{
2913
+ if (!item || 'object' != typeof item) return [];
2914
+ const range = item;
2915
+ const sqref = stringValue(range.sqref);
2916
+ if (!sqref || !work_spreadsheet_ranges_parseSpreadsheetCellRanges(sqref)) return [];
2917
+ return [
2918
+ {
2919
+ name: stringValue(range.name) || `Range ${index + 1}`,
2920
+ sqref: canonicalRangeReference(sqref),
2921
+ hintText: stringValue(range.hintText) || void 0,
2922
+ xlsxAttributes: stringRecord(range.xlsxAttributes)
2923
+ }
2924
+ ];
2925
+ });
2709
2926
  }
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;
2927
+ function canonicalRangeReference(value) {
2928
+ const ranges = work_spreadsheet_ranges_parseSpreadsheetCellRanges(value);
2929
+ return ranges ? formatSpreadsheetCellRanges(ranges) : value.trim();
2930
+ }
2931
+ function normalizeMatrix(data, rows, columns) {
2932
+ data.length = Math.max(data.length, rows);
2933
+ for (const [, row] of spreadsheet_sparse_sparseArrayEntries(data))row.length = Math.max(row.length, columns);
2934
+ }
2935
+ function cellProtectionRangeList(value) {
2936
+ if (!Array.isArray(value)) return [];
2937
+ return value.flatMap((item)=>{
2938
+ if (!item || 'object' != typeof item) return [];
2939
+ const candidate = item;
2940
+ const range = candidate.range;
2941
+ if (!range || !Array.isArray(range.row) || !Array.isArray(range.column) || range.row.length < 2 || range.column.length < 2 || ![
2942
+ ...range.row,
2943
+ ...range.column
2944
+ ].every((index)=>Number.isSafeInteger(index) && index >= 0)) return [];
2945
+ return [
2946
+ {
2947
+ range: {
2948
+ row: [
2949
+ Math.min(range.row[0], range.row[1]),
2950
+ Math.max(range.row[0], range.row[1])
2951
+ ],
2952
+ column: [
2953
+ Math.min(range.column[0], range.column[1]),
2954
+ Math.max(range.column[0], range.column[1])
2955
+ ]
2956
+ },
2957
+ locked: false !== candidate.locked,
2958
+ hidden: true === candidate.hidden
2959
+ }
2960
+ ];
2961
+ });
2962
+ }
2963
+ function flag(value, fallback) {
2964
+ if (1 === value || true === value || '1' === value) return 1;
2965
+ if (0 === value || false === value || '0' === value) return 0;
2966
+ return fallback;
2719
2967
  }
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;
2968
+ function stringValue(value) {
2969
+ return 'string' == typeof value ? value : '';
2734
2970
  }
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
- };
2971
+ function stringRecord(value) {
2972
+ if (!value || 'object' != typeof value || Array.isArray(value)) return;
2973
+ const entries = Object.entries(value).filter((entry)=>'string' == typeof entry[1]);
2974
+ return entries.length ? Object.fromEntries(entries) : void 0;
2761
2975
  }
2762
- function xlsxCellStyleOriginHasValues(origin) {
2763
- return Boolean(origin.fontColor || origin.fillColor || Object.keys(origin.borderColors ?? {}).length);
2976
+ const MILLISECONDS_PER_DAY = 86400000;
2977
+ function normalizeSpreadsheetDateValidationBoundary(value, uses1904DateSystem = false) {
2978
+ const trimmed = value.trim().replace(/^=/, '');
2979
+ const iso = normalizeIsoDate(trimmed);
2980
+ if (iso) return iso;
2981
+ const formula = /^DATE\((\d{4}),\s*(\d{1,2}),\s*(\d{1,2})\)$/i.exec(trimmed);
2982
+ if (formula) return normalizeIsoDate(`${formula[1]}-${String(formula[2]).padStart(2, '0')}-${String(formula[3]).padStart(2, '0')}`);
2983
+ const serial = Number(trimmed);
2984
+ if (!Number.isInteger(serial) || serial < 0) return null;
2985
+ if (!uses1904DateSystem && (0 === serial || 60 === serial)) return null;
2986
+ const adjustedSerial = uses1904DateSystem ? serial : serial > 60 ? serial - 1 : serial;
2987
+ const epoch = uses1904DateSystem ? Date.UTC(1904, 0, 1) : Date.UTC(1899, 11, 31);
2988
+ return isoDateFromTimestamp(epoch + adjustedSerial * MILLISECONDS_PER_DAY);
2764
2989
  }
2765
- function work_xlsx_cell_style_origin_normalizedColor(value) {
2766
- const rgb = xlsxRgbColor(value);
2767
- return rgb ? `#${rgb.slice(-6).toLowerCase()}` : null;
2990
+ function spreadsheetDateValidationFormula(value) {
2991
+ const normalized = normalizeIsoDate(value.trim());
2992
+ if (!normalized) return value.trim().replace(/^=/, '');
2993
+ const [year, month, day] = normalized.split('-');
2994
+ return `DATE(${year},${Number(month)},${Number(day)})`;
2768
2995
  }
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;
2996
+ function normalizeIsoDate(value) {
2997
+ const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
2998
+ if (!match) return null;
2999
+ const timestamp = Date.UTC(Number(match[1]), Number(match[2]) - 1, Number(match[3]));
3000
+ const normalized = isoDateFromTimestamp(timestamp);
3001
+ return normalized === value ? normalized : null;
2772
3002
  }
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;
3003
+ function isoDateFromTimestamp(timestamp) {
3004
+ const date = new Date(timestamp);
3005
+ const year = date.getUTCFullYear();
3006
+ if (!Number.isFinite(timestamp) || year < 1900 || year > 9999) return null;
3007
+ return `${String(year).padStart(4, '0')}-${String(date.getUTCMonth() + 1).padStart(2, '0')}-${String(date.getUTCDate()).padStart(2, '0')}`;
2777
3008
  }
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);
3009
+ const A3S_DIAGONAL_BORDER_KEY = 'a3sDiagonal';
3010
+ function spreadsheetDiagonalBorderFromCellValue(value) {
3011
+ if (!work_spreadsheet_diagonal_borders_isRecord(value)) return;
3012
+ const metadata = value[A3S_DIAGONAL_BORDER_KEY];
3013
+ if (work_spreadsheet_diagonal_borders_isRecord(metadata)) {
3014
+ const up = metadata.up;
3015
+ const down = metadata.down;
3016
+ const line = spreadsheetDiagonalBorderLine(metadata.line);
3017
+ if ('boolean' == typeof up && 'boolean' == typeof down) {
3018
+ if (!up && !down) return null;
3019
+ if (line) return {
3020
+ down,
3021
+ line,
3022
+ up
3023
+ };
3024
+ }
3025
+ }
3026
+ if (null === value.s) return null;
3027
+ const legacyLine = spreadsheetDiagonalBorderLine(value.s);
3028
+ return legacyLine ? {
3029
+ down: true,
3030
+ line: legacyLine,
3031
+ up: false
3032
+ } : void 0;
2781
3033
  }
2782
- function boundedNumber(value, maximum) {
2783
- return 'number' == typeof value && Number.isSafeInteger(value) && value >= 0 && value <= maximum ? value : null;
3034
+ function spreadsheetCellValueWithDiagonalBorder(value, border) {
3035
+ const next = {
3036
+ ...value
3037
+ };
3038
+ delete next.s;
3039
+ delete next[A3S_DIAGONAL_BORDER_KEY];
3040
+ if (!border) return next;
3041
+ const line = {
3042
+ ...border.line
3043
+ };
3044
+ next[A3S_DIAGONAL_BORDER_KEY] = {
3045
+ down: border.down,
3046
+ line,
3047
+ up: border.up
3048
+ };
3049
+ if (border.down) next.s = line;
3050
+ return next;
2784
3051
  }
2785
- function xlsxBooleanAttribute(element, name) {
2786
- const value = attribute(element, name)?.trim().toLowerCase();
2787
- return '1' === value || 'true' === value || 'on' === value;
3052
+ function spreadsheetDiagonalBorderLine(value) {
3053
+ if (!work_spreadsheet_diagonal_borders_isRecord(value)) return null;
3054
+ return 'string' == typeof value.color && 'string' == typeof value.style ? {
3055
+ color: value.color,
3056
+ style: value.style
3057
+ } : null;
2788
3058
  }
2789
- function work_xlsx_cell_style_origin_isRecord(value) {
2790
- return 'object' == typeof value && null !== value && !Array.isArray(value);
3059
+ function work_spreadsheet_diagonal_borders_isRecord(value) {
3060
+ return Boolean(value && 'object' == typeof value && !Array.isArray(value));
2791
3061
  }
2792
3062
  const spreadsheetTextOrientationIds = [
2793
3063
  'horizontal',
@@ -3037,6 +3307,34 @@ function nonNegativeInteger(value) {
3037
3307
  const parsed = Number(value);
3038
3308
  return Number.isSafeInteger(parsed) ? parsed : null;
3039
3309
  }
3310
+ const xlsxNativeFillCellKeys = [
3311
+ XLSX_PATTERN_FILL_CELL_KEY,
3312
+ XLSX_GRADIENT_FILL_CELL_KEY
3313
+ ];
3314
+ function activeXlsxNativeFill(cell) {
3315
+ const gradient = activeXlsxGradientFill(cell);
3316
+ const pattern = activeXlsxPatternFill(cell);
3317
+ if (Boolean(gradient) === Boolean(pattern)) return;
3318
+ return gradient ? {
3319
+ kind: 'gradient',
3320
+ value: gradient
3321
+ } : {
3322
+ kind: 'pattern',
3323
+ value: pattern
3324
+ };
3325
+ }
3326
+ function deleteXlsxNativeFills(cell) {
3327
+ deleteXlsxGradientFill(cell);
3328
+ deleteXlsxPatternFill(cell);
3329
+ }
3330
+ function xlsxNativeFillSemanticColors(fill) {
3331
+ if (!fill) return [];
3332
+ return 'gradient' === fill.kind ? xlsxGradientFillSemanticColors(fill.value) : xlsxPatternFillSemanticColors(fill.value);
3333
+ }
3334
+ function xlsxNativeFillKey(fill) {
3335
+ if (!fill) return '';
3336
+ return 'gradient' === fill.kind ? `gradient:${xlsxGradientFillKey(fill.value)}` : `pattern:${xlsxPatternFillKey(fill.value)}`;
3337
+ }
3040
3338
  const SPREADSHEET_CONDITIONAL_COMPARISON_OPERATORS = [
3041
3339
  'greaterThan',
3042
3340
  'greaterThanOrEqual',
@@ -3532,19 +3830,136 @@ function work_spreadsheet_page_setup_boundedNumber(value, minimum, maximum, fall
3532
3830
  }
3533
3831
  const MAX_XLSX_RICH_TEXT_CELL_CHARACTERS = 32767;
3534
3832
  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;
3833
+ const MAX_XLSX_RICH_TEXT_FONT_NAME_CHARACTERS = 128;
3834
+ const MAX_XLSX_RICH_TEXT_FONT_SIZE = 409;
3835
+ function normalizeXlsxRichTextEditSource(cell) {
3836
+ if (cell?.f) return null;
3837
+ if (cell) {
3838
+ const rich = normalizeXlsxRichTextCell(cell);
3839
+ if (rich) return rich;
3840
+ }
3841
+ const text = cell?.v;
3842
+ if (void 0 !== text && ('string' != typeof text || text.length > MAX_XLSX_RICH_TEXT_CELL_CHARACTERS || !validXlsxRichText(text))) return null;
3843
+ const value = text ?? '';
3844
+ return {
3845
+ runs: value ? [
3846
+ xlsxRichTextBaseRun(cell, value)
3847
+ ] : [],
3848
+ text: value
3849
+ };
3850
+ }
3851
+ function xlsxRichTextBaseRun(cell, text) {
3852
+ const run = {
3853
+ v: text
3854
+ };
3855
+ if (1 === Number(cell?.bl)) run.bl = 1;
3856
+ if (1 === Number(cell?.it)) run.it = 1;
3857
+ if (1 === Number(cell?.cl)) run.cl = 1;
3858
+ const underline = Number(cell?.un);
3859
+ if (Number.isSafeInteger(underline) && underline >= 1 && underline <= 4) run.un = underline;
3860
+ if ('string' == typeof cell?.ff && cell.ff.trim() && cell.ff.trim().length <= MAX_XLSX_RICH_TEXT_FONT_NAME_CHARACTERS) run.ff = cell.ff.trim();
3861
+ const size = Number(cell?.fs);
3862
+ if (Number.isFinite(size) && size >= 1 && size <= MAX_XLSX_RICH_TEXT_FONT_SIZE) run.fs = size;
3863
+ const color = normalizeXlsxRichTextColor(cell?.fc);
3864
+ if (color) {
3865
+ run.fc = color;
3866
+ const origin = normalizeXlsxSemanticColorOrigin(xlsxCellStyleOrigin(cell ?? {})?.fontColor);
3867
+ if (origin && xlsxSemanticColorMatchesValue(origin, color)) run.a3sXlsxColorOrigin = origin;
3868
+ }
3869
+ return run;
3870
+ }
3871
+ function normalizeXlsxRichTextCell(cell) {
3872
+ if (cell.f || cell.ct?.t !== 'inlineStr' || !Array.isArray(cell.ct.s)) return null;
3873
+ if (!cell.ct.s.length || cell.ct.s.length > MAX_XLSX_RICH_TEXT_RUNS_PER_CELL) return null;
3874
+ const runs = [];
3875
+ let characterCount = 0;
3876
+ for (const candidate of cell.ct.s){
3877
+ const run = normalizeXlsxRichTextRun(candidate);
3878
+ if (!run) return null;
3879
+ if (run.v) {
3880
+ characterCount += run.v.length;
3881
+ if (characterCount > MAX_XLSX_RICH_TEXT_CELL_CHARACTERS) return null;
3882
+ runs.push(run);
3883
+ }
3884
+ }
3885
+ const text = runs.map((run)=>run.v).join('');
3886
+ return runs.length && text ? {
3887
+ runs,
3888
+ text
3889
+ } : null;
3890
+ }
3891
+ function normalizeXlsxRichTextRun(value) {
3892
+ if (!work_xlsx_rich_text_model_isRecord(value) || 'string' != typeof value.v || !validXlsxRichText(value.v)) return null;
3893
+ const run = {
3894
+ v: value.v
3895
+ };
3896
+ copyToggle(value, run, 'bl');
3897
+ copyToggle(value, run, 'it');
3898
+ copyToggle(value, run, 'cl');
3899
+ if ('string' == typeof value.ff && value.ff.trim() && value.ff.trim().length <= MAX_XLSX_RICH_TEXT_FONT_NAME_CHARACTERS) run.ff = value.ff.trim();
3900
+ if ('number' == typeof value.fs && Number.isFinite(value.fs) && value.fs >= 1 && value.fs <= MAX_XLSX_RICH_TEXT_FONT_SIZE) run.fs = value.fs;
3901
+ const color = normalizeXlsxRichTextColor(value.fc);
3902
+ if (color) run.fc = color;
3903
+ const underline = Number(value.un);
3904
+ if (Number.isSafeInteger(underline) && underline >= 0 && underline <= 4 && void 0 !== value.un) run.un = underline;
3905
+ const colorOrigin = normalizeXlsxSemanticColorOrigin(value.a3sXlsxColorOrigin);
3906
+ if (colorOrigin) run.a3sXlsxColorOrigin = colorOrigin;
3907
+ return run;
3908
+ }
3909
+ function normalizeXlsxRichTextColor(value) {
3910
+ const rgb = xlsxRgbColor(value);
3911
+ return rgb ? `#${rgb.slice(-6).toLowerCase()}` : null;
3912
+ }
3913
+ function coalesceXlsxRichTextRuns(source) {
3914
+ const result = [];
3915
+ for (const run of source){
3916
+ if (!run.v) continue;
3917
+ const previous = result.at(-1);
3918
+ if (previous && sameXlsxRichTextRunStyle(previous, run)) previous.v += run.v;
3919
+ else result.push({
3920
+ ...run
3921
+ });
3922
+ }
3923
+ return result;
3924
+ }
3925
+ function sameXlsxRichTextRunStyle(left, right) {
3926
+ return left.bl === right.bl && left.cl === right.cl && left.fc === right.fc && left.ff === right.ff && left.fs === right.fs && left.it === right.it && left.un === right.un && JSON.stringify(left.a3sXlsxColorOrigin) === JSON.stringify(right.a3sXlsxColorOrigin);
3927
+ }
3928
+ function validXlsxRichText(value) {
3929
+ for(let index = 0; index < value.length; index += 1){
3930
+ const code = value.charCodeAt(index);
3931
+ if (0x09 !== code && 0x0a !== code && 0x0d !== code && (!(code >= 0x20) || !(code <= 0xd7ff)) && (!(code >= 0xe000) || !(code <= 0xfffd))) {
3932
+ if (isHighSurrogate(code) && index + 1 < value.length && isLowSurrogate(value.charCodeAt(index + 1))) {
3933
+ index += 1;
3934
+ continue;
3935
+ }
3936
+ return false;
3937
+ }
3938
+ }
3939
+ return true;
3940
+ }
3941
+ function isHighSurrogate(value) {
3942
+ return value >= 0xd800 && value <= 0xdbff;
3943
+ }
3944
+ function isLowSurrogate(value) {
3945
+ return value >= 0xdc00 && value <= 0xdfff;
3946
+ }
3947
+ function copyToggle(source, target, key) {
3948
+ if (1 === Number(source[key])) target[key] = 1;
3949
+ else if (0 === Number(source[key]) && void 0 !== source[key]) target[key] = 0;
3950
+ }
3951
+ function work_xlsx_rich_text_model_isRecord(value) {
3952
+ return 'object' == typeof value && null !== value && !Array.isArray(value);
3953
+ }
3537
3954
  const MAX_XLSX_SHARED_RICH_TEXT_ITEMS = 10000;
3538
- const MAX_XLSX_FONT_NAME_CHARACTERS = 128;
3539
- const MAX_XLSX_FONT_SIZE = 409;
3540
3955
  function createXlsxRichTextReadContext(options) {
3541
3956
  const colors = createXlsxColorResolver(options.styles, options.theme);
3542
3957
  const sharedStrings = readRichSharedStrings(options.sharedStrings, colors);
3543
3958
  return {
3544
3959
  colors,
3545
3960
  hasRichSharedStrings: sharedStrings.size > 0,
3546
- remainingCells: MAX_XLSX_RICH_TEXT_CELLS,
3547
- remainingRuns: MAX_XLSX_RICH_TEXT_RUNS,
3961
+ remainingCells: 10000,
3962
+ remainingRuns: 100000,
3548
3963
  sharedStrings
3549
3964
  };
3550
3965
  }
@@ -3573,7 +3988,7 @@ function readXlsxRichTextCells(worksheet, context) {
3573
3988
  ...run
3574
3989
  }));
3575
3990
  const text = runs.map((run)=>run.v).join('');
3576
- if (text && !(text.length > MAX_XLSX_RICH_TEXT_CELL_CHARACTERS)) {
3991
+ if (text && !(text.length > 32767)) {
3577
3992
  context.remainingCells -= 1;
3578
3993
  context.remainingRuns -= runs.length;
3579
3994
  result.push({
@@ -3604,8 +4019,8 @@ function applyImportedXlsxRichText(cell, richText) {
3604
4019
  function patchSpreadsheetRichTextFontRuns(cell, patch) {
3605
4020
  if (!fontPatchHasValues(patch) || cell.ct?.t !== 'inlineStr') return cell;
3606
4021
  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);
4022
+ if (!Array.isArray(source) || !source.length || source.some((run)=>!work_xlsx_rich_text_isRecord(run) || 'string' != typeof run.v || !validXlsxRichText(run.v))) return cell;
4023
+ const normalizedColor = void 0 === patch.fontColor ? void 0 : normalizeXlsxRichTextColor(patch.fontColor);
3609
4024
  const runs = source.map((run)=>{
3610
4025
  const next = {
3611
4026
  ...run
@@ -3631,15 +4046,15 @@ function patchSpreadsheetRichTextFontRuns(cell, patch) {
3631
4046
  };
3632
4047
  }
3633
4048
  function xlsxRichTextCellText(cell) {
3634
- return normalizeRichTextCell(cell)?.text ?? null;
4049
+ return normalizeXlsxRichTextCell(cell)?.text ?? null;
3635
4050
  }
3636
4051
  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;
4052
+ for (const [, row] of spreadsheet_sparse_sparseArrayEntries(sheet.data))for (const [, cell] of spreadsheet_sparse_sparseArrayEntries(row))if (cell && normalizeXlsxRichTextCell(cell)) return true;
3638
4053
  return false;
3639
4054
  }
3640
4055
  function xlsxRichTextStyleOrigins(sheet) {
3641
4056
  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 ?? []){
4057
+ for (const [, row] of spreadsheet_sparse_sparseArrayEntries(sheet.data))for (const [, cell] of spreadsheet_sparse_sparseArrayEntries(row))if (cell) for (const run of normalizeXlsxRichTextCell(cell)?.runs ?? []){
3643
4058
  const fontColor = normalizeXlsxSemanticColorOrigin(run.a3sXlsxColorOrigin);
3644
4059
  if (fontColor && run.fc && xlsxSemanticColorMatchesValue(fontColor, run.fc)) origins.push({
3645
4060
  fontColor
@@ -3657,12 +4072,12 @@ function writeXlsxRichTextCells(worksheet, sheet, semanticPalette) {
3657
4072
  ]
3658
4073
  ] : [];
3659
4074
  }));
3660
- let remainingCells = MAX_XLSX_RICH_TEXT_CELLS;
3661
- let remainingRuns = MAX_XLSX_RICH_TEXT_RUNS;
4075
+ let remainingCells = 10000;
4076
+ let remainingRuns = 100000;
3662
4077
  for (const [row, values] of spreadsheet_sparse_sparseArrayEntries(sheet.data))for (const [column, cell] of spreadsheet_sparse_sparseArrayEntries(values)){
3663
4078
  if (remainingCells <= 0 || remainingRuns <= 0) return;
3664
4079
  if (!cell) continue;
3665
- const richText = normalizeRichTextCell(cell);
4080
+ const richText = normalizeXlsxRichTextCell(cell);
3666
4081
  if (!richText || richText.runs.length > remainingRuns) continue;
3667
4082
  const element = elements.get(xlsxCellAddress(row, column));
3668
4083
  if (element) {
@@ -3677,9 +4092,9 @@ function readRichSharedStrings(document, colors) {
3677
4092
  const result = new Map();
3678
4093
  let parsedRuns = 0;
3679
4094
  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;
4095
+ if (result.size >= MAX_XLSX_SHARED_RICH_TEXT_ITEMS || parsedRuns >= 100000) break;
3681
4096
  const runs = readRichTextRuns(item, colors);
3682
- if (runs && !(parsedRuns + runs.length > MAX_XLSX_RICH_TEXT_RUNS)) {
4097
+ if (runs && !(parsedRuns + runs.length > 100000)) {
3683
4098
  result.set(index, runs);
3684
4099
  parsedRuns += runs.length;
3685
4100
  }
@@ -3688,7 +4103,7 @@ function readRichSharedStrings(document, colors) {
3688
4103
  }
3689
4104
  function readRichTextRuns(container, colors) {
3690
4105
  const elements = directChildren(container, 'r');
3691
- if (directChild(container, 't') || !elements.length || elements.length > MAX_XLSX_RICH_TEXT_RUNS_PER_CELL) return null;
4106
+ if (directChild(container, 't') || !elements.length || elements.length > 512) return null;
3692
4107
  const runs = [];
3693
4108
  let characterCount = 0;
3694
4109
  for (const element of elements){
@@ -3697,7 +4112,7 @@ function readRichTextRuns(container, colors) {
3697
4112
  const value = textElement.textContent ?? '';
3698
4113
  if (value) {
3699
4114
  characterCount += value.length;
3700
- if (characterCount > MAX_XLSX_RICH_TEXT_CELL_CHARACTERS || !validXmlText(value)) return null;
4115
+ if (characterCount > 32767 || !validXlsxRichText(value)) return null;
3701
4116
  runs.push(readRichTextRun(element, value, colors));
3702
4117
  }
3703
4118
  }
@@ -3713,12 +4128,12 @@ function readRichTextRun(element, value, colors) {
3713
4128
  };
3714
4129
  const font = directChild(properties, 'rFont') ?? directChild(properties, 'name');
3715
4130
  const fontName = attribute(font ?? properties, 'val')?.trim();
3716
- if (fontName && fontName.length <= MAX_XLSX_FONT_NAME_CHARACTERS) run.ff = fontName;
4131
+ if (fontName && fontName.length <= 128) run.ff = fontName;
3717
4132
  if (work_xlsx_rich_text_xlsxToggleEnabled(directChild(properties, 'b'))) run.bl = 1;
3718
4133
  if (work_xlsx_rich_text_xlsxToggleEnabled(directChild(properties, 'i'))) run.it = 1;
3719
4134
  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;
4135
+ const size = work_xlsx_rich_text_finiteNumber(attribute(directChild(properties, 'sz') ?? properties, 'val'));
4136
+ if (null !== size && size >= 1 && size <= 409) run.fs = size;
3722
4137
  const underline = directChild(properties, 'u');
3723
4138
  if (underline) {
3724
4139
  const value = spreadsheetUnderlineCellValueFromXlsx(attribute(underline, 'val'));
@@ -3731,47 +4146,6 @@ function readRichTextRun(element, value, colors) {
3731
4146
  if (colorOrigin) run.a3sXlsxColorOrigin = colorOrigin;
3732
4147
  return run;
3733
4148
  }
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
4149
  function writeRichTextCell(element, richText, semanticPalette) {
3776
4150
  for (const child of directChildren(element))if ('v' === child.localName || 'is' === child.localName) child.remove();
3777
4151
  element.setAttribute('t', 'inlineStr');
@@ -3825,16 +4199,12 @@ function writeRichTextRunProperties(document, run, semanticPalette) {
3825
4199
  function fontPatchHasValues(patch) {
3826
4200
  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
4201
  }
3828
- function normalizedColorValue(value) {
3829
- const rgb = xlsxRgbColor(value);
3830
- return rgb ? `#${rgb.slice(-6).toLowerCase()}` : null;
3831
- }
3832
4202
  function work_xlsx_rich_text_xlsxToggleEnabled(element) {
3833
4203
  if (!element) return false;
3834
4204
  const value = attribute(element, 'val')?.trim().toLowerCase();
3835
4205
  return '0' !== value && 'false' !== value && 'off' !== value;
3836
4206
  }
3837
- function finiteNumber(value) {
4207
+ function work_xlsx_rich_text_finiteNumber(value) {
3838
4208
  if (null === value || !value.trim()) return null;
3839
4209
  const parsed = Number(value);
3840
4210
  return Number.isFinite(parsed) ? parsed : null;
@@ -3844,20 +4214,7 @@ function work_xlsx_rich_text_nonNegativeInteger(value) {
3844
4214
  const parsed = Number(value);
3845
4215
  return Number.isSafeInteger(parsed) ? parsed : null;
3846
4216
  }
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
4217
  function work_xlsx_rich_text_isRecord(value) {
3861
4218
  return 'object' == typeof value && null !== value && !Array.isArray(value);
3862
4219
  }
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 };
4220
+ export { DEFAULT_PROTECTION_HINT, SPREADSHEET_CONDITIONAL_COMPARISON_OPERATORS, SPREADSHEET_CONDITIONAL_ICON_SETS, activeXlsxNativeFill, activeXlsxSemanticColorOrigin, applyImportedXlsxRichText, applyXlsxSemanticColorOrigin, attachSpreadsheetShownCommentCells, coalesceXlsxRichTextRuns, createWorkOfficeSpreadsheetCollaborationBinding as createOfficeSpreadsheetCollaborationBinding, createXlsxColorResolver, createXlsxRichTextReadContext, defaultSpreadsheetColorScaleThresholds, defaultSpreadsheetConditionalIconThresholds, defaultSpreadsheetDataBarOptions, defaultXlsxBorder, defaultXlsxFill, deleteXlsxNativeFills, directXlsxAlignment, directXlsxFontStyle, drawSpreadsheetConditionalIcon, editableRangeCellCount, editableRangeRequiresCredentials, effectiveSpreadsheetPageSetup, ensureXlsxStyleCollection, freezeImportedSpreadsheetCell, hasXlsxDirectFontStyle, importedSheetProtectionAuthority, initializeWorkOfficeSpreadsheetCollaboration as initializeOfficeSpreadsheetCollaboration, isHighSurrogate, isLowSurrogate, isSpreadsheetConditionalComparisonOperator, isSpreadsheetConditionalIconSetName, isSpreadsheetTextOrientationId, isSpreadsheetUnderlineStyle, normalizeSheetProtectionAuthority, normalizeSpreadsheetConditionalIconSetFormat, normalizeSpreadsheetConditionalVisualOptions, normalizeSpreadsheetDateValidationBoundary, normalizeSpreadsheetPaperSize, normalizeXlsxGradientFill, normalizeXlsxPatternFill, normalizeXlsxRichTextCell, normalizeXlsxRichTextColor, normalizeXlsxRichTextEditSource, normalizeXlsxRichTextRun, normalizeXlsxSemanticColorOrigin, patchSpreadsheetRichTextFontRuns, prepareXlsxSemanticPalette, protectedSheetCount, readWorkOfficeSpreadsheetCollaboration as readOfficeSpreadsheetCollaboration, readXlsxGradientFill, readXlsxPatternFill, readXlsxRichTextCells, readXlsxSemanticColorOrigin, registerDerivedSpreadsheetMatrix, registerImportedSpreadsheetMatrix, replaceWorkOfficeSpreadsheetCollaboration as replaceOfficeSpreadsheetCollaboration, resolveXlsxColor, sameSpreadsheetHistoryValue, sameXlsxRichTextRunStyle, 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, validXlsxRichText, withEditableRange, withSheetProtection, withSheetSelectionPermissions, withXlsxCellStyleOrigin, withXlsxGradientFill, withXlsxPatternFill, withoutEditableRange, work_xlsx_cell_style_values_xlsxBooleanAttribute, writeXlsxAlignment, writeXlsxRichTextCells, xlsxAlignmentMatches, xlsxBorderLineMatches, xlsxCellStyleOrigin, xlsxCellStyleOriginSemanticColors, xlsxColorElementMatchesOrigin, xlsxColorMatches, xlsxGradientFillFallbackColor, xlsxGradientFillKey, xlsxNativeFillCellKeys, xlsxNativeFillKey, xlsxNativeFillSemanticColors, xlsxPatternFillTypes, xlsxRgbColor, xlsxRichTextCellText, xlsxRichTextStyleOrigins, xlsxSemanticColorMatchesValue, xlsxSemanticColorOriginKey, xlsxStyleCollectionIndex, xlsxToggleEnabled, xlsxUnderlineStyle, xlsxWorksheetCellEntries };