@shbernal/ts-xlsx 2.1.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/bytes.d.ts +7 -0
- package/dist/bytes.js +22 -0
- package/dist/core/address.d.ts +60 -2
- package/dist/core/address.js +40 -24
- package/dist/core/autofilter.d.ts +5 -4
- package/dist/core/autofilter.js +34 -35
- package/dist/core/axis-handle.d.ts +10 -0
- package/dist/core/axis-handle.js +17 -0
- package/dist/core/cell.d.ts +25 -0
- package/dist/core/cell.js +9 -3
- package/dist/core/clone.d.ts +29 -0
- package/dist/core/clone.js +24 -0
- package/dist/core/color-resolution.js +2 -4
- package/dist/core/column.d.ts +5 -1
- package/dist/core/column.js +34 -35
- package/dist/core/comment-thread.js +2 -1
- package/dist/core/conditional-formatting-overlay.d.ts +2 -1
- package/dist/core/conditional-formatting-overlay.js +2 -2
- package/dist/core/conditional-formatting.d.ts +14 -6
- package/dist/core/conditional-formatting.js +45 -43
- package/dist/core/containers.d.ts +12 -0
- package/dist/core/containers.js +5 -0
- package/dist/core/data-validation-overlay.d.ts +2 -1
- package/dist/core/data-validation-overlay.js +4 -4
- package/dist/core/data-validation.d.ts +9 -3
- package/dist/core/data-validation.js +21 -18
- package/dist/core/date-format.d.ts +20 -0
- package/dist/core/date-format.js +160 -0
- package/dist/core/date.d.ts +43 -8
- package/dist/core/date.js +18 -2
- package/dist/core/formula.d.ts +26 -0
- package/dist/core/formula.js +20 -4
- package/dist/core/grid-edits.d.ts +2 -3
- package/dist/core/grid-edits.js +69 -70
- package/dist/core/grid-shift.d.ts +58 -9
- package/dist/core/grid-shift.js +26 -4
- package/dist/core/image.d.ts +14 -10
- package/dist/core/image.js +9 -9
- package/dist/core/internal.d.ts +8 -2
- package/dist/core/limits.d.ts +23 -0
- package/dist/core/limits.js +4 -0
- package/dist/core/merge-index.d.ts +31 -0
- package/dist/core/merge-index.js +60 -0
- package/dist/core/merge.d.ts +5 -14
- package/dist/core/merge.js +18 -27
- package/dist/core/page-setup.d.ts +72 -2
- package/dist/core/page-setup.js +34 -8
- package/dist/core/pivot-table.d.ts +1 -1
- package/dist/core/pivot-table.js +67 -53
- package/dist/core/protection.js +2 -11
- package/dist/core/range.js +34 -30
- package/dist/core/row-input.js +2 -2
- package/dist/core/row.d.ts +5 -1
- package/dist/core/row.js +22 -23
- package/dist/core/style.d.ts +134 -75
- package/dist/core/style.js +112 -53
- package/dist/core/table-style.d.ts +1 -1
- package/dist/core/table-style.js +4 -4
- package/dist/core/table.d.ts +28 -10
- package/dist/core/table.js +54 -39
- package/dist/core/theme.js +6 -5
- package/dist/core/used-extent.d.ts +44 -0
- package/dist/core/used-extent.js +102 -0
- package/dist/core/value.d.ts +9 -0
- package/dist/core/value.js +36 -34
- package/dist/core/workbook-media.d.ts +34 -0
- package/dist/core/workbook-media.js +44 -0
- package/dist/core/workbook-styles.d.ts +67 -1
- package/dist/core/workbook-vba.js +3 -2
- package/dist/core/workbook.d.ts +23 -2
- package/dist/core/workbook.js +24 -40
- package/dist/core/worksheet-comments.d.ts +2 -1
- package/dist/core/worksheet-comments.js +20 -13
- package/dist/core/worksheet-merges.d.ts +44 -0
- package/dist/core/worksheet-merges.js +59 -0
- package/dist/core/worksheet-model.d.ts +9 -1
- package/dist/core/worksheet-model.js +24 -9
- package/dist/core/worksheet.d.ts +72 -12
- package/dist/core/worksheet.js +68 -70
- package/dist/customui/ribbon.js +6 -7
- package/dist/entries/core.d.ts +18 -13
- package/dist/entries/core.js +12 -6
- package/dist/entries/xlsx.d.ts +1 -1
- package/dist/errors.d.ts +64 -0
- package/dist/errors.js +22 -0
- package/dist/hex.d.ts +8 -0
- package/dist/hex.js +3 -0
- package/dist/io/csv/delimiter.d.ts +9 -0
- package/dist/io/csv/delimiter.js +6 -0
- package/dist/io/csv/read.js +11 -4
- package/dist/io/csv/write.d.ts +9 -2
- package/dist/io/csv/write.js +9 -38
- package/dist/io/opc/inflate.js +15 -1
- package/dist/io/opc/namespaces.d.ts +16 -0
- package/dist/io/opc/namespaces.js +4 -0
- package/dist/io/opc/part-paths.d.ts +10 -0
- package/dist/io/opc/part-paths.js +16 -1
- package/dist/io/opc/read-opc.d.ts +69 -10
- package/dist/io/opc/read-opc.js +49 -55
- package/dist/io/opc/read-options.d.ts +5 -1
- package/dist/io/opc/rels.d.ts +1 -6
- package/dist/io/opc/rels.js +1 -4
- package/dist/io/opc/sniff-format.d.ts +3 -3
- package/dist/io/opc/sniff-format.js +2 -2
- package/dist/io/style/xf-style.d.ts +48 -2
- package/dist/io/style/xf-style.js +14 -0
- package/dist/io/xlsb/formula.d.ts +2 -2
- package/dist/io/xlsb/formula.js +49 -34
- package/dist/io/xlsb/primitives.js +8 -14
- package/dist/io/xlsb/ptg-functions.d.ts +19 -10
- package/dist/io/xlsb/ptg-functions.js +385 -596
- package/dist/io/xlsb/read-styles.js +50 -83
- package/dist/io/xlsb/read-worksheet.d.ts +20 -1
- package/dist/io/xlsb/read-worksheet.js +73 -89
- package/dist/io/xlsb/read.d.ts +6 -3
- package/dist/io/xlsb/read.js +47 -29
- package/dist/io/xlsb/record-stream.d.ts +30 -0
- package/dist/io/xlsb/record-stream.js +20 -0
- package/dist/io/xlsb/record-types.d.ts +1 -5
- package/dist/io/xlsb/record-types.js +1 -5
- package/dist/io/xlsx/cell-accumulator.d.ts +9 -2
- package/dist/io/xlsx/cell-accumulator.js +32 -9
- package/dist/io/xlsx/cell-style-resolution.d.ts +25 -0
- package/dist/io/xlsx/cell-style-resolution.js +29 -0
- package/dist/io/xlsx/cell-value.d.ts +5 -3
- package/dist/io/xlsx/cell-value.js +13 -15
- package/dist/io/xlsx/color-xml.js +3 -2
- package/dist/io/xlsx/column-budget.d.ts +26 -0
- package/dist/io/xlsx/column-budget.js +22 -0
- package/dist/io/xlsx/comments.d.ts +6 -2
- package/dist/io/xlsx/comments.js +36 -31
- package/dist/io/xlsx/conditional-formatting.d.ts +9 -5
- package/dist/io/xlsx/conditional-formatting.js +51 -46
- package/dist/io/xlsx/data-validation.d.ts +9 -7
- package/dist/io/xlsx/data-validation.js +38 -35
- package/dist/io/xlsx/edit-vba.d.ts +7 -2
- package/dist/io/xlsx/edit-vba.js +15 -29
- package/dist/io/xlsx/font-xml.d.ts +7 -0
- package/dist/io/xlsx/font-xml.js +104 -0
- package/dist/io/xlsx/hyperlinks.d.ts +41 -7
- package/dist/io/xlsx/hyperlinks.js +40 -28
- package/dist/io/xlsx/images.js +24 -25
- package/dist/io/xlsx/namespaces.d.ts +16 -0
- package/dist/io/xlsx/namespaces.js +7 -0
- package/dist/io/xlsx/package-plan.d.ts +23 -3
- package/dist/io/xlsx/package-plan.js +66 -25
- package/dist/io/xlsx/part-names.d.ts +41 -0
- package/dist/io/xlsx/part-names.js +46 -0
- package/dist/io/xlsx/pivot.js +8 -7
- package/dist/io/xlsx/read-parts.d.ts +59 -0
- package/dist/io/xlsx/read-parts.js +252 -0
- package/dist/io/xlsx/read-pivot.js +3 -1
- package/dist/io/xlsx/read-repair.d.ts +26 -0
- package/dist/io/xlsx/read-repair.js +39 -0
- package/dist/io/xlsx/{rich-runs.d.ts → read-rich-runs.d.ts} +1 -1
- package/dist/io/xlsx/{rich-runs.js → read-rich-runs.js} +7 -3
- package/dist/io/xlsx/read-rows.d.ts +18 -5
- package/dist/io/xlsx/read-rows.js +50 -37
- package/dist/io/xlsx/read-shared-strings.js +5 -3
- package/dist/io/xlsx/read-styles.d.ts +1 -6
- package/dist/io/xlsx/read-styles.js +65 -109
- package/dist/io/xlsx/read-workbook-xml.d.ts +36 -0
- package/dist/io/xlsx/read-workbook-xml.js +170 -0
- package/dist/io/xlsx/read-worksheet.d.ts +11 -1
- package/dist/io/xlsx/read-worksheet.js +51 -193
- package/dist/io/xlsx/read.d.ts +5 -13
- package/dist/io/xlsx/read.js +111 -436
- package/dist/io/xlsx/rich-text.js +1 -1
- package/dist/io/xlsx/row-position.d.ts +18 -0
- package/dist/io/xlsx/row-position.js +11 -0
- package/dist/io/xlsx/row-xml.d.ts +128 -0
- package/dist/io/xlsx/row-xml.js +203 -0
- package/dist/io/xlsx/shared-formulas.js +2 -2
- package/dist/io/xlsx/sheet-properties.d.ts +10 -1
- package/dist/io/xlsx/sheet-properties.js +166 -37
- package/dist/io/xlsx/style-elements.d.ts +43 -0
- package/dist/io/xlsx/style-elements.js +156 -0
- package/dist/io/xlsx/styles.d.ts +12 -3
- package/dist/io/xlsx/styles.js +5 -204
- package/dist/io/xlsx/tables.js +11 -14
- package/dist/io/xlsx/theme-xml.d.ts +26 -4
- package/dist/io/xlsx/theme-xml.js +107 -69
- package/dist/io/xlsx/threaded-comments.d.ts +8 -10
- package/dist/io/xlsx/threaded-comments.js +3 -1
- package/dist/io/xlsx/workbook-xml.d.ts +54 -4
- package/dist/io/xlsx/workbook-xml.js +84 -57
- package/dist/io/xlsx/worksheet-xml.d.ts +23 -70
- package/dist/io/xlsx/worksheet-xml.js +59 -242
- package/dist/io/xlsx/write-stream.d.ts +71 -16
- package/dist/io/xlsx/write-stream.js +79 -41
- package/dist/io/xlsx/write.d.ts +6 -2
- package/dist/io/xlsx/write.js +217 -153
- package/dist/rel-type.d.ts +16 -0
- package/dist/rel-type.js +6 -0
- package/dist/token-set.d.ts +28 -0
- package/dist/token-set.js +7 -0
- package/dist/vba/bytes.d.ts +14 -5
- package/dist/vba/bytes.js +16 -6
- package/dist/vba/cfb-format.d.ts +32 -0
- package/dist/vba/cfb-format.js +13 -0
- package/dist/vba/cfb-writer.d.ts +9 -0
- package/dist/vba/cfb-writer.js +28 -25
- package/dist/vba/cfb.d.ts +13 -1
- package/dist/vba/cfb.js +73 -57
- package/dist/vba/codepage.js +2 -1
- package/dist/vba/errors.d.ts +7 -0
- package/dist/vba/ms-ovba.js +79 -23
- package/dist/vba/project-editor.js +35 -40
- package/dist/vba/project.d.ts +11 -1
- package/dist/vba/project.js +40 -21
- package/dist/vba/vba-encoding.js +5 -6
- package/dist/xml/xml-attrs.d.ts +37 -0
- package/dist/xml/xml-attrs.js +30 -0
- package/dist/xml/xml-chars.d.ts +40 -0
- package/dist/xml/xml-chars.js +12 -0
- package/dist/xml/xml-namespaces.d.ts +31 -0
- package/dist/xml/xml-namespaces.js +50 -0
- package/dist/xml/xml-read.d.ts +128 -81
- package/dist/xml/xml-read.js +161 -178
- package/dist/xml/xml-scan.d.ts +78 -0
- package/dist/xml/xml-scan.js +180 -0
- package/dist/xml/xml.d.ts +29 -28
- package/dist/xml/xml.js +24 -24
- package/package.json +13 -9
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type Alignment, type Border, type Fill, type Protection } from '../../core/style.ts';
|
|
2
|
+
import type { DifferentialStyle } from '../../core/workbook-styles.ts';
|
|
3
|
+
export declare const CUSTOM_NUMFMT_BASE = 164;
|
|
4
|
+
export declare const DEFAULT_FONT_BODY = "<sz val=\"11\"/><color theme=\"1\"/><name val=\"Calibri\"/><family val=\"2\"/><scheme val=\"minor\"/>";
|
|
5
|
+
export declare const DEFAULT_BORDER = "<border><left/><right/><top/><bottom/><diagonal/></border>";
|
|
6
|
+
export interface CellFormat {
|
|
7
|
+
readonly fillId: number;
|
|
8
|
+
readonly numFmtId: number;
|
|
9
|
+
readonly fontId: number;
|
|
10
|
+
readonly borderId: number;
|
|
11
|
+
readonly alignment: string;
|
|
12
|
+
readonly protection: string;
|
|
13
|
+
readonly quotePrefix: boolean;
|
|
14
|
+
readonly xfId: number;
|
|
15
|
+
}
|
|
16
|
+
export declare const DEFAULT_FORMAT: CellFormat;
|
|
17
|
+
export declare function formatSignature(format: CellFormat): string;
|
|
18
|
+
/**
|
|
19
|
+
* Whether a format is the do-nothing default: no facet, General number format, no quote prefix, and
|
|
20
|
+
* linked to the Normal named style. Such a cellXfs entry adds nothing, so its owner needs no `s`.
|
|
21
|
+
*
|
|
22
|
+
* Asked of the signature rather than field by field, because the two questions have to be answered
|
|
23
|
+
* from the same field set and both answer silently when they are not. A facet the signature forgets
|
|
24
|
+
* makes two distinct formats intern to one entry, and every cell carrying the facet quietly loses it;
|
|
25
|
+
* a facet *this* forgets forces a spurious entry and an `s` attribute onto every cell in the book.
|
|
26
|
+
* Neither is a type error, and neither is visible in the file until someone compares two of them.
|
|
27
|
+
*/
|
|
28
|
+
export declare function isDefaultFormat(format: CellFormat): boolean;
|
|
29
|
+
export declare function xfXml(format: CellFormat, xfId: number | null): string;
|
|
30
|
+
export declare function cellStyleTag(entry: {
|
|
31
|
+
name: string;
|
|
32
|
+
builtinId?: number;
|
|
33
|
+
xfId: number;
|
|
34
|
+
}): string;
|
|
35
|
+
export declare function alignmentAttrs(alignment: Alignment): string;
|
|
36
|
+
export declare function protectionAttrs(protection: Protection): string;
|
|
37
|
+
export declare function tableStyleName(fragment: string): string;
|
|
38
|
+
export declare function dxfXml(style: DifferentialStyle): string;
|
|
39
|
+
export declare function borderXml(border: Border): string;
|
|
40
|
+
export declare function fillSignature(fill: Fill): string;
|
|
41
|
+
export declare function patternFillXml(fill: Fill, { solidBgFallback }: {
|
|
42
|
+
solidBgFallback: boolean;
|
|
43
|
+
}): string;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { ALIGNMENT_FACETS, isBorderStyle, isFillPatternType, } from '../../core/style.js';
|
|
2
|
+
import { decodeEntities } from '../../xml/xml-scan.js';
|
|
3
|
+
import { checkedToken, escapeAttr, escapeFormatCode, numberText } from '../../xml/xml.js';
|
|
4
|
+
import { colorAttrs } from './color-xml.js';
|
|
5
|
+
import { fontXml } from './font-xml.js';
|
|
6
|
+
export const CUSTOM_NUMFMT_BASE = 164;
|
|
7
|
+
export const DEFAULT_FONT_BODY = '<sz val="11"/><color theme="1"/><name val="Calibri"/><family val="2"/><scheme val="minor"/>';
|
|
8
|
+
export const DEFAULT_BORDER = '<border><left/><right/><top/><bottom/><diagonal/></border>';
|
|
9
|
+
export const DEFAULT_FORMAT = {
|
|
10
|
+
fillId: 0,
|
|
11
|
+
numFmtId: 0,
|
|
12
|
+
fontId: 0,
|
|
13
|
+
borderId: 0,
|
|
14
|
+
alignment: '',
|
|
15
|
+
protection: '',
|
|
16
|
+
quotePrefix: false,
|
|
17
|
+
xfId: 0,
|
|
18
|
+
};
|
|
19
|
+
export function formatSignature(format) {
|
|
20
|
+
return (`fill:${format.fillId}|numFmt:${format.numFmtId}|font:${format.fontId}|border:${format.borderId}|` +
|
|
21
|
+
`align:${format.alignment}|protect:${format.protection}|quote:${format.quotePrefix}|xfId:${format.xfId}`);
|
|
22
|
+
}
|
|
23
|
+
const DEFAULT_FORMAT_SIGNATURE = formatSignature(DEFAULT_FORMAT);
|
|
24
|
+
export function isDefaultFormat(format) {
|
|
25
|
+
return formatSignature(format) === DEFAULT_FORMAT_SIGNATURE;
|
|
26
|
+
}
|
|
27
|
+
export function xfXml(format, xfId) {
|
|
28
|
+
const applyNumberFormat = format.numFmtId !== 0 ? ' applyNumberFormat="1"' : '';
|
|
29
|
+
const applyFont = format.fontId !== 0 ? ' applyFont="1"' : '';
|
|
30
|
+
const applyFill = format.fillId !== 0 ? ' applyFill="1"' : '';
|
|
31
|
+
const applyBorder = format.borderId !== 0 ? ' applyBorder="1"' : '';
|
|
32
|
+
const applyAlignment = format.alignment !== '' ? ' applyAlignment="1"' : '';
|
|
33
|
+
const applyProtection = format.protection !== '' ? ' applyProtection="1"' : '';
|
|
34
|
+
const quotePrefix = format.quotePrefix ? ' quotePrefix="1"' : '';
|
|
35
|
+
const xfIdAttr = xfId === null ? '' : ` xfId="${xfId}"`;
|
|
36
|
+
const open = `<xf numFmtId="${format.numFmtId}" fontId="${format.fontId}" fillId="${format.fillId}" ` +
|
|
37
|
+
`borderId="${format.borderId}"${xfIdAttr}${quotePrefix}` +
|
|
38
|
+
`${applyNumberFormat}${applyFont}${applyFill}${applyBorder}${applyAlignment}${applyProtection}`;
|
|
39
|
+
const body = (format.alignment === '' ? '' : `<alignment ${format.alignment}/>`) +
|
|
40
|
+
(format.protection === '' ? '' : `<protection ${format.protection}/>`);
|
|
41
|
+
return body === '' ? `${open}/>` : `${open}>${body}</xf>`;
|
|
42
|
+
}
|
|
43
|
+
export function cellStyleTag(entry) {
|
|
44
|
+
const builtin = entry.builtinId === undefined ? '' : ` builtinId="${entry.builtinId}"`;
|
|
45
|
+
return `<cellStyle name="${escapeAttr(entry.name)}" xfId="${entry.xfId}"${builtin}/>`;
|
|
46
|
+
}
|
|
47
|
+
export function alignmentAttrs(alignment) {
|
|
48
|
+
const parts = [];
|
|
49
|
+
for (const facet of ALIGNMENT_FACETS) {
|
|
50
|
+
switch (facet.kind) {
|
|
51
|
+
case 'token': {
|
|
52
|
+
const value = alignment[facet.key];
|
|
53
|
+
if (value === undefined || value === facet.omit)
|
|
54
|
+
break;
|
|
55
|
+
parts.push(`${facet.key}="${checkedToken(value, facet.isValid, facet.label)}"`);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
case 'number': {
|
|
59
|
+
const value = alignment[facet.key];
|
|
60
|
+
if (value === undefined || value === 0)
|
|
61
|
+
break;
|
|
62
|
+
parts.push(`${facet.key}="${numberText(value)}"`);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
case 'flag':
|
|
66
|
+
if (alignment[facet.key])
|
|
67
|
+
parts.push(`${facet.key}="1"`);
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return parts.join(' ');
|
|
72
|
+
}
|
|
73
|
+
export function protectionAttrs(protection) {
|
|
74
|
+
const parts = [];
|
|
75
|
+
if (protection.locked === false)
|
|
76
|
+
parts.push('locked="0"');
|
|
77
|
+
if (protection.hidden === true)
|
|
78
|
+
parts.push('hidden="1"');
|
|
79
|
+
return parts.join(' ');
|
|
80
|
+
}
|
|
81
|
+
export function tableStyleName(fragment) {
|
|
82
|
+
return decodeEntities(/<tableStyle\b[^>]*\bname="([^"]*)"/.exec(fragment)?.[1] ?? '');
|
|
83
|
+
}
|
|
84
|
+
export function dxfXml(style) {
|
|
85
|
+
const parts = [];
|
|
86
|
+
if (style.font !== undefined) {
|
|
87
|
+
const font = fontXml(style.font);
|
|
88
|
+
if (font !== '')
|
|
89
|
+
parts.push(`<font>${font}</font>`);
|
|
90
|
+
}
|
|
91
|
+
if (typeof style.numFmt === 'string' && style.numFmt !== '') {
|
|
92
|
+
parts.push(`<numFmt numFmtId="${CUSTOM_NUMFMT_BASE}" formatCode="${escapeFormatCode(style.numFmt)}"/>`);
|
|
93
|
+
}
|
|
94
|
+
if (style.fill !== undefined)
|
|
95
|
+
parts.push(patternFillXml(style.fill, { solidBgFallback: false }));
|
|
96
|
+
if (style.border !== undefined)
|
|
97
|
+
parts.push(borderXml(style.border));
|
|
98
|
+
return `<dxf>${parts.join('')}</dxf>`;
|
|
99
|
+
}
|
|
100
|
+
function gradientFillXml(fill) {
|
|
101
|
+
const attrs = (fill.gradient === 'path' ? ' type="path"' : '') +
|
|
102
|
+
(fill.degree ? ` degree="${numberText(fill.degree)}"` : '') +
|
|
103
|
+
insetAttr('left', fill.left) +
|
|
104
|
+
insetAttr('right', fill.right) +
|
|
105
|
+
insetAttr('top', fill.top) +
|
|
106
|
+
insetAttr('bottom', fill.bottom);
|
|
107
|
+
const stops = fill.stops
|
|
108
|
+
.map((stop) => `<stop position="${numberText(stop.position)}"><color ${colorAttrs(stop.color)}/></stop>`)
|
|
109
|
+
.join('');
|
|
110
|
+
return `<gradientFill${attrs}>${stops}</gradientFill>`;
|
|
111
|
+
}
|
|
112
|
+
function insetAttr(name, value) {
|
|
113
|
+
return value ? ` ${name}="${numberText(value)}"` : '';
|
|
114
|
+
}
|
|
115
|
+
export function borderXml(border) {
|
|
116
|
+
const attrs = (border.diagonalUp ? ' diagonalUp="1"' : '') + (border.diagonalDown ? ' diagonalDown="1"' : '');
|
|
117
|
+
return (`<border${attrs}>` +
|
|
118
|
+
edgeXml('left', border.left) +
|
|
119
|
+
edgeXml('right', border.right) +
|
|
120
|
+
edgeXml('top', border.top) +
|
|
121
|
+
edgeXml('bottom', border.bottom) +
|
|
122
|
+
edgeXml('diagonal', border.diagonal) +
|
|
123
|
+
'</border>');
|
|
124
|
+
}
|
|
125
|
+
function edgeXml(tag, edge) {
|
|
126
|
+
if (edge === undefined)
|
|
127
|
+
return `<${tag}/>`;
|
|
128
|
+
const style = checkedToken(edge.style, isBorderStyle, 'border style');
|
|
129
|
+
if (edge.color === undefined)
|
|
130
|
+
return `<${tag} style="${style}"/>`;
|
|
131
|
+
return `<${tag} style="${style}"><color ${colorAttrs(edge.color)}/></${tag}>`;
|
|
132
|
+
}
|
|
133
|
+
export function fillSignature(fill) {
|
|
134
|
+
if (fill.type === 'gradient') {
|
|
135
|
+
const stops = fill.stops.map((s) => `${s.position}:${colorSignature(s.color)}`).join(',');
|
|
136
|
+
return `grad|${fill.gradient}|${fill.degree ?? ''}|${fill.left ?? ''}/${fill.right ?? ''}/${fill.top ?? ''}/${fill.bottom ?? ''}|${stops}`;
|
|
137
|
+
}
|
|
138
|
+
return `${fill.pattern}|${colorSignature(fill.fgColor)}|${colorSignature(fill.bgColor)}`;
|
|
139
|
+
}
|
|
140
|
+
function colorSignature(color) {
|
|
141
|
+
if (color === undefined)
|
|
142
|
+
return '';
|
|
143
|
+
return `${color.argb ?? ''}/${color.theme ?? ''}/${color.tint ?? ''}/${color.indexed ?? ''}`;
|
|
144
|
+
}
|
|
145
|
+
export function patternFillXml(fill, { solidBgFallback }) {
|
|
146
|
+
if (fill.type === 'gradient')
|
|
147
|
+
return `<fill>${gradientFillXml(fill)}</fill>`;
|
|
148
|
+
const fg = fill.fgColor ? `<fgColor ${colorAttrs(fill.fgColor)}/>` : '';
|
|
149
|
+
const bg = fill.bgColor
|
|
150
|
+
? `<bgColor ${colorAttrs(fill.bgColor)}/>`
|
|
151
|
+
: solidBgFallback && fill.pattern === 'solid'
|
|
152
|
+
? '<bgColor indexed="64"/>'
|
|
153
|
+
: '';
|
|
154
|
+
const pattern = checkedToken(fill.pattern, isFillPatternType, 'fill pattern');
|
|
155
|
+
return `<fill><patternFill patternType="${pattern}">${fg}${bg}</patternFill></fill>`;
|
|
156
|
+
}
|
package/dist/io/xlsx/styles.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Font } from '../../core/style.ts';
|
|
2
2
|
import { type TableStyle } from '../../core/table-style.ts';
|
|
3
|
+
import type { DifferentialStyle, NamedCellStyle, TableStyleTable } from '../../core/workbook-styles.ts';
|
|
3
4
|
import type { XfStyle } from '../style/xf-style.ts';
|
|
4
|
-
/** What a {@link StyleRegistry} needs from its workbook before any style is interned.
|
|
5
|
+
/** What a {@link StyleRegistry} needs from its workbook before any style is interned.
|
|
6
|
+
*/
|
|
5
7
|
export interface StyleRegistryOptions {
|
|
6
8
|
/**
|
|
7
9
|
* The font every cell naming none of its own renders in, emitted as id 0. Take it from
|
|
@@ -22,6 +24,14 @@ export interface StyleRegistryOptions {
|
|
|
22
24
|
*/
|
|
23
25
|
readonly declaredDefaultFont?: Font;
|
|
24
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* The interned style table one written package is built against: every distinct fill, number format,
|
|
29
|
+
* font, border and xf, each handed back as the stable index a cell's `s` attribute names.
|
|
30
|
+
*
|
|
31
|
+
* One workbook, one registry. The streaming writer is why that is worth saying: it interns a row's
|
|
32
|
+
* styles at the moment the row is flushed, long before `xl/styles.xml` is emitted, so the ids already
|
|
33
|
+
* baked into those rows are only correct if the very same registry emits the part.
|
|
34
|
+
*/
|
|
25
35
|
export declare class StyleRegistry {
|
|
26
36
|
#private;
|
|
27
37
|
constructor(options?: StyleRegistryOptions);
|
|
@@ -94,4 +104,3 @@ export declare class StyleRegistry {
|
|
|
94
104
|
/** Serialise the accumulated table into a complete, valid styles.xml part. */
|
|
95
105
|
toXml(): string;
|
|
96
106
|
}
|
|
97
|
-
export declare function fontXml(font: Font, nameTag?: 'name' | 'rFont'): string;
|
package/dist/io/xlsx/styles.js
CHANGED
|
@@ -1,25 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {} from '../../core/style.js';
|
|
2
2
|
import { TABLE_STYLE_ELEMENT_TYPES } from '../../core/table-style.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { colorAttrs } from './color-xml.js';
|
|
3
|
+
import { escapeAttr, escapeFormatCode, numAttr, XML_DECLARATION } from '../../xml/xml.js';
|
|
4
|
+
import { fontXml } from './font-xml.js';
|
|
6
5
|
import { MARKUP_COMPATIBILITY_NS, SPREADSHEETML_NS } from './namespaces.js';
|
|
6
|
+
import { alignmentAttrs, borderXml, cellStyleTag, CUSTOM_NUMFMT_BASE, DEFAULT_BORDER, DEFAULT_FONT_BODY, DEFAULT_FORMAT, dxfXml, fillSignature, formatSignature, isDefaultFormat, patternFillXml, protectionAttrs, tableStyleName, xfXml, } from './style-elements.js';
|
|
7
7
|
const RESERVED_FILL_COUNT = 2;
|
|
8
8
|
const RESERVED_FONT_COUNT = 1;
|
|
9
|
-
const CUSTOM_NUMFMT_BASE = 164;
|
|
10
9
|
const RESERVED_BORDER_COUNT = 1;
|
|
11
|
-
const DEFAULT_FONT_BODY = '<sz val="11"/><color theme="1"/><name val="Calibri"/><family val="2"/><scheme val="minor"/>';
|
|
12
|
-
const DEFAULT_BORDER = '<border><left/><right/><top/><bottom/><diagonal/></border>';
|
|
13
|
-
const DEFAULT_FORMAT = {
|
|
14
|
-
fillId: 0,
|
|
15
|
-
numFmtId: 0,
|
|
16
|
-
fontId: 0,
|
|
17
|
-
borderId: 0,
|
|
18
|
-
alignment: '',
|
|
19
|
-
protection: '',
|
|
20
|
-
quotePrefix: false,
|
|
21
|
-
xfId: 0,
|
|
22
|
-
};
|
|
23
10
|
class InternTable {
|
|
24
11
|
#entries = [];
|
|
25
12
|
#idByKey = new Map();
|
|
@@ -137,7 +124,7 @@ export class StyleRegistry {
|
|
|
137
124
|
const element = style.elements[type];
|
|
138
125
|
if (element === undefined)
|
|
139
126
|
return [];
|
|
140
|
-
const size = element.size
|
|
127
|
+
const size = element.size === 1 ? '' : numAttr('size', element.size);
|
|
141
128
|
return [
|
|
142
129
|
`<tableStyleElement type="${type}"${size} dxfId="${this.differentialStyleId(element)}"/>`,
|
|
143
130
|
];
|
|
@@ -245,189 +232,3 @@ export class StyleRegistry {
|
|
|
245
232
|
return `<numFmts count="${this.#numFmts.size}">${entries}</numFmts>`;
|
|
246
233
|
}
|
|
247
234
|
}
|
|
248
|
-
function isDefaultFormat(format) {
|
|
249
|
-
return (format.fillId === 0 &&
|
|
250
|
-
format.numFmtId === 0 &&
|
|
251
|
-
format.fontId === 0 &&
|
|
252
|
-
format.borderId === 0 &&
|
|
253
|
-
format.alignment === '' &&
|
|
254
|
-
format.protection === '' &&
|
|
255
|
-
!format.quotePrefix &&
|
|
256
|
-
format.xfId === 0);
|
|
257
|
-
}
|
|
258
|
-
function formatSignature(format) {
|
|
259
|
-
return (`fill:${format.fillId}|numFmt:${format.numFmtId}|font:${format.fontId}|border:${format.borderId}|` +
|
|
260
|
-
`align:${format.alignment}|protect:${format.protection}|quote:${format.quotePrefix}|xfId:${format.xfId}`);
|
|
261
|
-
}
|
|
262
|
-
function xfXml(format, xfId) {
|
|
263
|
-
const applyNumberFormat = format.numFmtId !== 0 ? ' applyNumberFormat="1"' : '';
|
|
264
|
-
const applyFont = format.fontId !== 0 ? ' applyFont="1"' : '';
|
|
265
|
-
const applyFill = format.fillId !== 0 ? ' applyFill="1"' : '';
|
|
266
|
-
const applyBorder = format.borderId !== 0 ? ' applyBorder="1"' : '';
|
|
267
|
-
const applyAlignment = format.alignment !== '' ? ' applyAlignment="1"' : '';
|
|
268
|
-
const applyProtection = format.protection !== '' ? ' applyProtection="1"' : '';
|
|
269
|
-
const quotePrefix = format.quotePrefix ? ' quotePrefix="1"' : '';
|
|
270
|
-
const xfIdAttr = xfId === null ? '' : ` xfId="${xfId}"`;
|
|
271
|
-
const open = `<xf numFmtId="${format.numFmtId}" fontId="${format.fontId}" fillId="${format.fillId}" ` +
|
|
272
|
-
`borderId="${format.borderId}"${xfIdAttr}${quotePrefix}` +
|
|
273
|
-
`${applyNumberFormat}${applyFont}${applyFill}${applyBorder}${applyAlignment}${applyProtection}`;
|
|
274
|
-
const body = (format.alignment === '' ? '' : `<alignment ${format.alignment}/>`) +
|
|
275
|
-
(format.protection === '' ? '' : `<protection ${format.protection}/>`);
|
|
276
|
-
return body === '' ? `${open}/>` : `${open}>${body}</xf>`;
|
|
277
|
-
}
|
|
278
|
-
function cellStyleTag(entry) {
|
|
279
|
-
const builtin = entry.builtinId === undefined ? '' : ` builtinId="${entry.builtinId}"`;
|
|
280
|
-
return `<cellStyle name="${escapeAttr(entry.name)}" xfId="${entry.xfId}"${builtin}/>`;
|
|
281
|
-
}
|
|
282
|
-
function alignmentAttrs(alignment) {
|
|
283
|
-
const parts = [];
|
|
284
|
-
if (alignment.horizontal !== undefined && alignment.horizontal !== 'general') {
|
|
285
|
-
parts.push(`horizontal="${checkedToken(alignment.horizontal, isHorizontalAlignment, 'horizontal alignment')}"`);
|
|
286
|
-
}
|
|
287
|
-
if (alignment.vertical !== undefined) {
|
|
288
|
-
parts.push(`vertical="${checkedToken(alignment.vertical, isVerticalAlignment, 'vertical alignment')}"`);
|
|
289
|
-
}
|
|
290
|
-
if (alignment.textRotation !== undefined && alignment.textRotation !== 0) {
|
|
291
|
-
parts.push(`textRotation="${numberText(alignment.textRotation)}"`);
|
|
292
|
-
}
|
|
293
|
-
if (alignment.wrapText)
|
|
294
|
-
parts.push('wrapText="1"');
|
|
295
|
-
if (alignment.indent !== undefined && alignment.indent !== 0) {
|
|
296
|
-
parts.push(`indent="${numberText(alignment.indent)}"`);
|
|
297
|
-
}
|
|
298
|
-
if (alignment.shrinkToFit)
|
|
299
|
-
parts.push('shrinkToFit="1"');
|
|
300
|
-
if (alignment.readingOrder !== undefined && alignment.readingOrder !== 0) {
|
|
301
|
-
parts.push(`readingOrder="${numberText(alignment.readingOrder)}"`);
|
|
302
|
-
}
|
|
303
|
-
return parts.join(' ');
|
|
304
|
-
}
|
|
305
|
-
function protectionAttrs(protection) {
|
|
306
|
-
const parts = [];
|
|
307
|
-
if (protection.locked === false)
|
|
308
|
-
parts.push('locked="0"');
|
|
309
|
-
if (protection.hidden === true)
|
|
310
|
-
parts.push('hidden="1"');
|
|
311
|
-
return parts.join(' ');
|
|
312
|
-
}
|
|
313
|
-
function tableStyleName(fragment) {
|
|
314
|
-
return decodeEntities(/<tableStyle\b[^>]*\bname="([^"]*)"/.exec(fragment)?.[1] ?? '');
|
|
315
|
-
}
|
|
316
|
-
export function fontXml(font, nameTag = 'name') {
|
|
317
|
-
const parts = [];
|
|
318
|
-
if (font.bold)
|
|
319
|
-
parts.push('<b/>');
|
|
320
|
-
if (font.italic)
|
|
321
|
-
parts.push('<i/>');
|
|
322
|
-
if (font.strike)
|
|
323
|
-
parts.push('<strike/>');
|
|
324
|
-
if (font.outline)
|
|
325
|
-
parts.push('<outline/>');
|
|
326
|
-
const underline = underlineXml(font.underline);
|
|
327
|
-
if (underline !== '')
|
|
328
|
-
parts.push(underline);
|
|
329
|
-
if (font.vertAlign !== undefined) {
|
|
330
|
-
parts.push(`<vertAlign val="${checkedToken(font.vertAlign, isFontVerticalAlignment, 'font vertical alignment')}"/>`);
|
|
331
|
-
}
|
|
332
|
-
if (font.size !== undefined)
|
|
333
|
-
parts.push(`<sz val="${numberText(font.size)}"/>`);
|
|
334
|
-
if (font.color !== undefined)
|
|
335
|
-
parts.push(`<color ${colorAttrs(font.color)}/>`);
|
|
336
|
-
if (font.name !== undefined)
|
|
337
|
-
parts.push(`<${nameTag} val="${escapeAttr(font.name)}"/>`);
|
|
338
|
-
if (font.family !== undefined)
|
|
339
|
-
parts.push(`<family val="${numberText(font.family)}"/>`);
|
|
340
|
-
if (font.charset !== undefined)
|
|
341
|
-
parts.push(`<charset val="${numberText(font.charset)}"/>`);
|
|
342
|
-
if (font.scheme !== undefined && font.scheme !== 'none')
|
|
343
|
-
parts.push(`<scheme val="${checkedToken(font.scheme, isFontScheme, 'font scheme')}"/>`);
|
|
344
|
-
return parts.join('');
|
|
345
|
-
}
|
|
346
|
-
function dxfXml(style) {
|
|
347
|
-
const parts = [];
|
|
348
|
-
if (style.font !== undefined) {
|
|
349
|
-
const font = fontXml(style.font);
|
|
350
|
-
if (font !== '')
|
|
351
|
-
parts.push(`<font>${font}</font>`);
|
|
352
|
-
}
|
|
353
|
-
if (typeof style.numFmt === 'string' && style.numFmt !== '') {
|
|
354
|
-
parts.push(`<numFmt numFmtId="${CUSTOM_NUMFMT_BASE}" formatCode="${escapeFormatCode(style.numFmt)}"/>`);
|
|
355
|
-
}
|
|
356
|
-
if (style.fill !== undefined)
|
|
357
|
-
parts.push(patternFillXml(style.fill, { solidBgFallback: false }));
|
|
358
|
-
if (style.border !== undefined)
|
|
359
|
-
parts.push(borderXml(style.border));
|
|
360
|
-
return `<dxf>${parts.join('')}</dxf>`;
|
|
361
|
-
}
|
|
362
|
-
function gradientFillXml(fill) {
|
|
363
|
-
const attrs = (fill.gradient === 'path' ? ' type="path"' : '') +
|
|
364
|
-
(fill.degree ? ` degree="${numberText(fill.degree)}"` : '') +
|
|
365
|
-
insetAttr('left', fill.left) +
|
|
366
|
-
insetAttr('right', fill.right) +
|
|
367
|
-
insetAttr('top', fill.top) +
|
|
368
|
-
insetAttr('bottom', fill.bottom);
|
|
369
|
-
const stops = fill.stops
|
|
370
|
-
.map((stop) => `<stop position="${numberText(stop.position)}"><color ${colorAttrs(stop.color)}/></stop>`)
|
|
371
|
-
.join('');
|
|
372
|
-
return `<gradientFill${attrs}>${stops}</gradientFill>`;
|
|
373
|
-
}
|
|
374
|
-
function insetAttr(name, value) {
|
|
375
|
-
return value ? ` ${name}="${numberText(value)}"` : '';
|
|
376
|
-
}
|
|
377
|
-
function underlineXml(underline) {
|
|
378
|
-
if (underline === undefined || underline === false || underline === 'none')
|
|
379
|
-
return '';
|
|
380
|
-
if (underline === true || underline === 'single')
|
|
381
|
-
return '<u/>';
|
|
382
|
-
return `<u val="${checkedToken(underline, isNamedUnderlineStyle, 'underline style')}"/>`;
|
|
383
|
-
}
|
|
384
|
-
function borderXml(border) {
|
|
385
|
-
const attrs = (border.diagonalUp ? ' diagonalUp="1"' : '') + (border.diagonalDown ? ' diagonalDown="1"' : '');
|
|
386
|
-
return (`<border${attrs}>` +
|
|
387
|
-
edgeXml('left', border.left) +
|
|
388
|
-
edgeXml('right', border.right) +
|
|
389
|
-
edgeXml('top', border.top) +
|
|
390
|
-
edgeXml('bottom', border.bottom) +
|
|
391
|
-
edgeXml('diagonal', border.diagonal) +
|
|
392
|
-
'</border>');
|
|
393
|
-
}
|
|
394
|
-
function edgeXml(tag, edge) {
|
|
395
|
-
if (edge === undefined)
|
|
396
|
-
return `<${tag}/>`;
|
|
397
|
-
const style = checkedToken(edge.style, isBorderStyle, 'border style');
|
|
398
|
-
if (edge.color === undefined)
|
|
399
|
-
return `<${tag} style="${style}"/>`;
|
|
400
|
-
return `<${tag} style="${style}"><color ${colorAttrs(edge.color)}/></${tag}>`;
|
|
401
|
-
}
|
|
402
|
-
function escapeFormatCode(code) {
|
|
403
|
-
assertRepresentable(code);
|
|
404
|
-
return code
|
|
405
|
-
.replace(/&/g, '&')
|
|
406
|
-
.replace(/</g, '<')
|
|
407
|
-
.replace(/>/g, '>')
|
|
408
|
-
.replace(/"/g, '"');
|
|
409
|
-
}
|
|
410
|
-
function fillSignature(fill) {
|
|
411
|
-
if (fill.type === 'gradient') {
|
|
412
|
-
const stops = fill.stops.map((s) => `${s.position}:${colorSignature(s.color)}`).join(',');
|
|
413
|
-
return `grad|${fill.gradient}|${fill.degree ?? ''}|${fill.left ?? ''}/${fill.right ?? ''}/${fill.top ?? ''}/${fill.bottom ?? ''}|${stops}`;
|
|
414
|
-
}
|
|
415
|
-
return `${fill.pattern}|${colorSignature(fill.fgColor)}|${colorSignature(fill.bgColor)}`;
|
|
416
|
-
}
|
|
417
|
-
function colorSignature(color) {
|
|
418
|
-
if (color === undefined)
|
|
419
|
-
return '';
|
|
420
|
-
return `${color.argb ?? ''}/${color.theme ?? ''}/${color.tint ?? ''}/${color.indexed ?? ''}`;
|
|
421
|
-
}
|
|
422
|
-
function patternFillXml(fill, { solidBgFallback }) {
|
|
423
|
-
if (fill.type === 'gradient')
|
|
424
|
-
return `<fill>${gradientFillXml(fill)}</fill>`;
|
|
425
|
-
const fg = fill.fgColor ? `<fgColor ${colorAttrs(fill.fgColor)}/>` : '';
|
|
426
|
-
const bg = fill.bgColor
|
|
427
|
-
? `<bgColor ${colorAttrs(fill.bgColor)}/>`
|
|
428
|
-
: solidBgFallback && fill.pattern === 'solid'
|
|
429
|
-
? '<bgColor indexed="64"/>'
|
|
430
|
-
: '';
|
|
431
|
-
const pattern = checkedToken(fill.pattern, isFillPatternType, 'fill pattern');
|
|
432
|
-
return `<fill><patternFill patternType="${pattern}">${fg}${bg}</patternFill></fill>`;
|
|
433
|
-
}
|
package/dist/io/xlsx/tables.js
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
import { encodeAddress, tryDecodeRange } from '../../core/address.js';
|
|
1
|
+
import { encodeAddress, MAX_COLUMN, tryDecodeRange } from '../../core/address.js';
|
|
2
2
|
import { isTotalsRowFunction, } from '../../core/table.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { numInteger } from '../../xml/xml-attrs.js';
|
|
4
|
+
import { parseXml, TextCapture } from '../../xml/xml-read.js';
|
|
5
|
+
import { boolPresent, localName } from '../../xml/xml-scan.js';
|
|
6
|
+
import { boolAttr, checkedToken, escapeAttr, escapeText, XML_DECLARATION } from '../../xml/xml.js';
|
|
5
7
|
import { NS } from './relationships.js';
|
|
6
8
|
export function tableXml(table, id) {
|
|
7
9
|
const name = escapeAttr(table.name);
|
|
8
10
|
const displayName = escapeAttr(table.displayName);
|
|
9
11
|
const headerRowCount = table.headerRow ? '' : ' headerRowCount="0"';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
else if (table.totalsRowShown !== undefined) {
|
|
15
|
-
totals = ` totalsRowShown="${table.totalsRowShown ? '1' : '0'}"`;
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
totals = '';
|
|
19
|
-
}
|
|
12
|
+
const totals = table.totalsRow
|
|
13
|
+
? ' totalsRowCount="1"'
|
|
14
|
+
: boolAttr('totalsRowShown', table.totalsRowShown);
|
|
20
15
|
const autoFilter = table.autoFilterRef !== undefined ? `<autoFilter ref="${table.autoFilterRef}"/>` : '';
|
|
21
16
|
const columns = table.columns.map((column, i) => tableColumnXml(column, i + 1)).join('');
|
|
22
17
|
return (XML_DECLARATION +
|
|
@@ -48,7 +43,7 @@ function tableColumnXml(column, id) {
|
|
|
48
43
|
attrs += ` totalsRowLabel="${escapeAttr(column.totalsRowLabel)}"`;
|
|
49
44
|
}
|
|
50
45
|
if (column.totalsRowFunction !== undefined) {
|
|
51
|
-
attrs += ` totalsRowFunction="${
|
|
46
|
+
attrs += ` totalsRowFunction="${checkedToken(column.totalsRowFunction, isTotalsRowFunction, 'totals row function')}"`;
|
|
52
47
|
}
|
|
53
48
|
if (column.totalsRowFormula !== undefined) {
|
|
54
49
|
return `<tableColumn ${attrs}><totalsRowFormula>${escapeText(column.totalsRowFormula)}</totalsRowFormula></tableColumn>`;
|
|
@@ -135,6 +130,8 @@ export function parseTable(xml) {
|
|
|
135
130
|
const { top, left, bottom } = decoded;
|
|
136
131
|
if (top === undefined || left === undefined || bottom === undefined)
|
|
137
132
|
return undefined;
|
|
133
|
+
if (left + columns.length - 1 > MAX_COLUMN)
|
|
134
|
+
return undefined;
|
|
138
135
|
const headerRow = headerRowCount !== 0;
|
|
139
136
|
const totalsRow = totalsRowCount > 0;
|
|
140
137
|
const dataRows = bottom - top + 1 - (headerRow ? 1 : 0) - (totalsRow ? 1 : 0);
|
|
@@ -1,16 +1,29 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { AssertNever } from '../../core/internal.ts';
|
|
2
|
+
import { type ThemeColorScheme, type ThemeColorSlot, type ThemeFontScheme, type ThemeOverrides } from '../../core/theme.ts';
|
|
2
3
|
/**
|
|
3
4
|
* Extract the colour scheme from a theme part. Returns only the slots the part actually declares in a
|
|
4
5
|
* colour model this reader understands; an unrecognised one is dropped rather than guessed at, so a
|
|
5
6
|
* caller can tell "the theme says nothing here" from "the theme says black".
|
|
6
7
|
*
|
|
7
|
-
* Reads the `<
|
|
8
|
-
* neither participates in resolving a colour, and scanning the whole part would let
|
|
8
|
+
* Reads the `<clrScheme>` block alone. A theme carries a font scheme and a format scheme too, but
|
|
9
|
+
* neither participates in resolving a colour, and scanning the whole part would let an `<srgbClr>`
|
|
9
10
|
* buried in a gradient stop masquerade as a scheme slot.
|
|
10
11
|
*/
|
|
11
12
|
export declare function parseThemeColorScheme(themeXml: string): ThemeColorScheme;
|
|
12
|
-
/** Extract the major/minor latin typefaces from a theme part's `<
|
|
13
|
+
/** Extract the major/minor latin typefaces from a theme part's `<fontScheme>`. */
|
|
13
14
|
export declare function parseThemeFontScheme(themeXml: string): ThemeFontScheme;
|
|
15
|
+
declare const SCHEME_ELEMENT_ORDER: readonly ["dk1", "lt1", "dk2", "lt2", "accent1", "accent2", "accent3", "accent4", "accent5", "accent6", "hlink", "folHlink"];
|
|
16
|
+
/**
|
|
17
|
+
* The half of the proof the list above owes: `satisfies` covers "no invented slot", this covers "no
|
|
18
|
+
* omission". A slot missing here is not a slot written in the wrong place -- it is a slot dropped
|
|
19
|
+
* from every rewritten `<a:clrScheme>`, verbatim source element and all, so a caller who authored it
|
|
20
|
+
* gets back a theme that silently does not carry it.
|
|
21
|
+
*
|
|
22
|
+
* This is the one list in the library where the schema order and the index order differ, which makes
|
|
23
|
+
* it the one a new slot is least likely to be added to by hand. `DEFAULT_THEME_COLOR_SCHEME` proves
|
|
24
|
+
* the same completeness on the model side.
|
|
25
|
+
*/
|
|
26
|
+
export type EverySlotIsInSchemaOrder = AssertNever<Exclude<ThemeColorSlot, (typeof SCHEME_ELEMENT_ORDER)[number]>>;
|
|
14
27
|
/**
|
|
15
28
|
* Apply authored colour/font overrides to a theme part, returning the new part text.
|
|
16
29
|
*
|
|
@@ -24,6 +37,14 @@ export declare function parseThemeFontScheme(themeXml: string): ThemeFontScheme;
|
|
|
24
37
|
* its value. That matters for `dk1`/`lt1`, which Excel writes as `<a:sysClr val="windowText"
|
|
25
38
|
* lastClr="000000"/>`: rewriting those as `<a:srgbClr>` would pin them to one machine's resolved
|
|
26
39
|
* window colours and break dark-mode following.
|
|
40
|
+
*
|
|
41
|
+
* The edit is made by *offset*, not by pattern. What it replaces was three container-scanning regular
|
|
42
|
+
* expressions in the one file whose own header condemns that pattern, on a path a preserved source
|
|
43
|
+
* theme's bytes reach: `[\s\S]*?` terminated on a `</clrScheme>` inside a comment, `[^>]*` missed a
|
|
44
|
+
* `<latin typeface="X"></latin>` and dropped the override silently, and the DrawingML prefix -- read
|
|
45
|
+
* out of the part's own root element, where an NCName may legally contain `.` and `-` -- was
|
|
46
|
+
* interpolated into the pattern unescaped. {@link elementRange} answers the same question with the
|
|
47
|
+
* scanner, and splicing at its offsets is what makes an unoverridden part come back byte for byte.
|
|
27
48
|
*/
|
|
28
49
|
export declare function applyThemeOverrides(baseXml: string, overrides: ThemeOverrides): string;
|
|
29
50
|
/**
|
|
@@ -35,3 +56,4 @@ export declare function applyThemeOverrides(baseXml: string, overrides: ThemeOve
|
|
|
35
56
|
* built from scratch rather than read from a file.
|
|
36
57
|
*/
|
|
37
58
|
export declare const DEFAULT_THEME_XML: string;
|
|
59
|
+
export {};
|