reamkit 1.13.0 → 1.15.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 +34 -8
- package/dist/esm/core/converter/facade.d.ts +8 -1
- package/dist/esm/core/converter/facade.js +34 -8
- package/dist/esm/core/converter/ream.d.ts +1 -0
- package/dist/esm/core/converter/ream.js +13 -8
- package/dist/esm/core/document-model/types.d.ts +2 -0
- package/dist/esm/core/ir/features.d.ts +1 -0
- package/dist/esm/core/ir/features.js +1 -0
- package/dist/esm/core/ir/sheet.d.ts +42 -3
- package/dist/esm/core/ole/cfb.d.ts +19 -0
- package/dist/esm/core/ole/cfb.js +158 -0
- package/dist/esm/core/spreadsheet-model/index.d.ts +1 -1
- package/dist/esm/core/spreadsheet-model/types.d.ts +81 -1
- package/dist/esm/excel/activex-parser.d.ts +9 -0
- package/dist/esm/excel/activex-parser.js +188 -0
- package/dist/esm/excel/comments-parser.d.ts +4 -0
- package/dist/esm/excel/comments-parser.js +104 -0
- package/dist/esm/excel/conditional-format.d.ts +5 -3
- package/dist/esm/excel/conditional-format.js +248 -12
- package/dist/esm/excel/form-control-parser.d.ts +6 -0
- package/dist/esm/excel/form-control-parser.js +29 -0
- package/dist/esm/excel/formula/context.d.ts +11 -0
- package/dist/esm/excel/formula/dates.d.ts +11 -0
- package/dist/esm/excel/formula/dates.js +46 -0
- package/dist/esm/excel/formula/eval.d.ts +11 -0
- package/dist/esm/excel/formula/eval.js +196 -0
- package/dist/esm/excel/formula/functions.d.ts +7 -0
- package/dist/esm/excel/formula/functions.js +1359 -0
- package/dist/esm/excel/formula/index.d.ts +14 -0
- package/dist/esm/excel/formula/index.js +17 -0
- package/dist/esm/excel/formula/lexer.d.ts +8 -0
- package/dist/esm/excel/formula/lexer.js +163 -0
- package/dist/esm/excel/formula/parser.d.ts +57 -0
- package/dist/esm/excel/formula/parser.js +274 -0
- package/dist/esm/excel/formula/value.d.ts +52 -0
- package/dist/esm/excel/formula/value.js +102 -0
- package/dist/esm/excel/header-footer.d.ts +2 -0
- package/dist/esm/excel/header-footer.js +127 -0
- package/dist/esm/excel/index.d.ts +1 -1
- package/dist/esm/excel/number-format.d.ts +2 -0
- package/dist/esm/excel/number-format.js +5 -1
- package/dist/esm/excel/print-model.d.ts +7 -2
- package/dist/esm/excel/print-model.js +123 -16
- package/dist/esm/excel/shared-strings-parser.d.ts +6 -1
- package/dist/esm/excel/shared-strings-parser.js +91 -12
- package/dist/esm/excel/sheet-drawing.d.ts +13 -1
- package/dist/esm/excel/sheet-drawing.js +47 -14
- package/dist/esm/excel/sheet-shape-parser.d.ts +4 -0
- package/dist/esm/excel/sheet-shape-parser.js +96 -0
- package/dist/esm/excel/sheet-to-flow.d.ts +4 -1
- package/dist/esm/excel/sheet-to-flow.js +170 -3
- package/dist/esm/excel/styles-parser.js +37 -0
- package/dist/esm/excel/worksheet-parser.js +191 -1
- package/dist/esm/excel/xls/biff-chart.d.ts +8 -0
- package/dist/esm/excel/xls/biff-chart.js +121 -0
- package/dist/esm/excel/xls/biff-reader.d.ts +4 -0
- package/dist/esm/excel/xls/biff-reader.js +1418 -0
- package/dist/esm/excel/xls/biff-styles.d.ts +8 -0
- package/dist/esm/excel/xls/biff-styles.js +299 -0
- package/dist/esm/excel/xls/escher.d.ts +24 -0
- package/dist/esm/excel/xls/escher.js +171 -0
- package/dist/esm/excel/xls/xls-reader.d.ts +3 -0
- package/dist/esm/excel/xls/xls-reader.js +30 -0
- package/dist/esm/excel/xlsx-reader.d.ts +2 -1
- package/dist/esm/excel/xlsx-reader.js +134 -16
- package/dist/esm/excel/xlsx-to-pdf.d.ts +1 -0
- package/dist/esm/excel/xlsx-to-pdf.js +2 -2
- package/dist/esm/excel/xlsx-writer.js +12 -2
- package/dist/esm/layout/styled-layout.js +29 -0
- package/dist/esm/pptx/ppt/ppt-reader.d.ts +4 -0
- package/dist/esm/pptx/ppt/ppt-reader.js +337 -0
- package/dist/esm/pptx/ppt/ppt-text.d.ts +69 -0
- package/dist/esm/pptx/ppt/ppt-text.js +756 -0
- package/dist/esm/pptx/slide-parser.d.ts +4 -2
- package/dist/esm/pptx/slide-parser.js +1 -1
- package/dist/esm/word/doc/doc-reader.d.ts +4 -0
- package/dist/esm/word/doc/doc-reader.js +421 -0
- package/dist/esm/word/doc/doc-text.d.ts +79 -0
- package/dist/esm/word/doc/doc-text.js +706 -0
- package/package.json +1 -1
|
@@ -59,6 +59,10 @@ export interface ParsedWorksheet {
|
|
|
59
59
|
readonly drawingRelId?: string;
|
|
60
60
|
readonly conditionalFormats?: ReadonlyArray<ConditionalFormat>;
|
|
61
61
|
readonly dataValidations?: ReadonlyArray<DataValidation>;
|
|
62
|
+
readonly hyperlinks?: ReadonlyArray<HyperlinkRef>;
|
|
63
|
+
readonly headerFooter?: HeaderFooter;
|
|
64
|
+
readonly formControls?: ReadonlyArray<FormControlRef>;
|
|
65
|
+
readonly oleObjects?: ReadonlyArray<OleObjectRef>;
|
|
62
66
|
readonly sparklines?: ReadonlyArray<ParsedSparkline>;
|
|
63
67
|
readonly tablePartRelIds?: ReadonlyArray<string>;
|
|
64
68
|
readonly tables?: ReadonlyArray<ExcelTable>;
|
|
@@ -128,6 +132,9 @@ export interface XlsxBorder {
|
|
|
128
132
|
readonly right?: XlsxBorderEdge;
|
|
129
133
|
readonly bottom?: XlsxBorderEdge;
|
|
130
134
|
readonly left?: XlsxBorderEdge;
|
|
135
|
+
readonly diagonal?: XlsxBorderEdge;
|
|
136
|
+
readonly diagonalUp?: boolean;
|
|
137
|
+
readonly diagonalDown?: boolean;
|
|
131
138
|
}
|
|
132
139
|
export type XlsxHorizontalAlign = 'left' | 'center' | 'right' | 'fill' | 'justify' | 'centerContinuous' | 'distributed';
|
|
133
140
|
export type XlsxVerticalAlign = 'top' | 'center' | 'bottom' | 'justify' | 'distributed';
|
|
@@ -135,6 +142,9 @@ export interface XlsxCellAlignment {
|
|
|
135
142
|
readonly horizontal?: XlsxHorizontalAlign;
|
|
136
143
|
readonly vertical?: XlsxVerticalAlign;
|
|
137
144
|
readonly wrapText?: boolean;
|
|
145
|
+
readonly indent?: number;
|
|
146
|
+
readonly textRotation?: number;
|
|
147
|
+
readonly shrinkToFit?: boolean;
|
|
138
148
|
}
|
|
139
149
|
export interface XlsxCellXf {
|
|
140
150
|
readonly numFmtId: number;
|
|
@@ -199,11 +209,81 @@ export interface CfRuleIconSet {
|
|
|
199
209
|
readonly cfvos: ReadonlyArray<Cfvo>;
|
|
200
210
|
readonly reverse?: boolean;
|
|
201
211
|
}
|
|
202
|
-
export
|
|
212
|
+
export interface CfRuleTop10 {
|
|
213
|
+
readonly type: 'top10';
|
|
214
|
+
readonly priority: number;
|
|
215
|
+
readonly rank: number;
|
|
216
|
+
readonly percent: boolean;
|
|
217
|
+
readonly bottom: boolean;
|
|
218
|
+
readonly dxfId: number;
|
|
219
|
+
}
|
|
220
|
+
export interface CfRuleAboveAverage {
|
|
221
|
+
readonly type: 'aboveAverage';
|
|
222
|
+
readonly priority: number;
|
|
223
|
+
readonly aboveAverage: boolean;
|
|
224
|
+
readonly equalAverage: boolean;
|
|
225
|
+
readonly stdDev?: number;
|
|
226
|
+
readonly dxfId: number;
|
|
227
|
+
}
|
|
228
|
+
export interface CfRuleDupUnique {
|
|
229
|
+
readonly type: 'duplicateValues' | 'uniqueValues';
|
|
230
|
+
readonly priority: number;
|
|
231
|
+
readonly dxfId: number;
|
|
232
|
+
}
|
|
233
|
+
export interface CfRuleText {
|
|
234
|
+
readonly type: 'containsText' | 'notContainsText' | 'beginsWith' | 'endsWith';
|
|
235
|
+
readonly priority: number;
|
|
236
|
+
readonly text: string;
|
|
237
|
+
readonly dxfId: number;
|
|
238
|
+
readonly formula?: string;
|
|
239
|
+
}
|
|
240
|
+
export interface CfRuleExpression {
|
|
241
|
+
readonly type: 'expression';
|
|
242
|
+
readonly priority: number;
|
|
243
|
+
readonly formula: string;
|
|
244
|
+
readonly dxfId: number;
|
|
245
|
+
}
|
|
246
|
+
export type TimePeriodKind = 'today' | 'yesterday' | 'tomorrow' | 'last7Days' | 'thisWeek' | 'lastWeek' | 'nextWeek' | 'thisMonth' | 'lastMonth' | 'nextMonth';
|
|
247
|
+
export interface CfRuleTimePeriod {
|
|
248
|
+
readonly type: 'timePeriod';
|
|
249
|
+
readonly priority: number;
|
|
250
|
+
readonly timePeriod: TimePeriodKind;
|
|
251
|
+
readonly dxfId: number;
|
|
252
|
+
readonly formula?: string;
|
|
253
|
+
}
|
|
254
|
+
export type CfRule = CfRuleCellIs | CfRuleColorScale | CfRuleDataBar | CfRuleIconSet | CfRuleTop10 | CfRuleAboveAverage | CfRuleDupUnique | CfRuleText | CfRuleExpression | CfRuleTimePeriod;
|
|
203
255
|
export interface ConditionalFormat {
|
|
204
256
|
readonly ranges: ReadonlyArray<MergedRange>;
|
|
205
257
|
readonly rules: ReadonlyArray<CfRule>;
|
|
206
258
|
}
|
|
259
|
+
export interface HyperlinkRef {
|
|
260
|
+
readonly ref: string;
|
|
261
|
+
readonly relId?: string;
|
|
262
|
+
readonly location?: string;
|
|
263
|
+
readonly display?: string;
|
|
264
|
+
readonly tooltip?: string;
|
|
265
|
+
}
|
|
266
|
+
export interface HeaderFooter {
|
|
267
|
+
readonly oddHeader?: string;
|
|
268
|
+
readonly oddFooter?: string;
|
|
269
|
+
}
|
|
270
|
+
export interface FormControlRef {
|
|
271
|
+
readonly name?: string;
|
|
272
|
+
readonly relId: string;
|
|
273
|
+
}
|
|
274
|
+
export interface OleObjectRef {
|
|
275
|
+
readonly progId?: string;
|
|
276
|
+
readonly relId: string;
|
|
277
|
+
}
|
|
278
|
+
export interface SheetRichRun {
|
|
279
|
+
readonly text: string;
|
|
280
|
+
readonly bold?: boolean;
|
|
281
|
+
readonly italic?: boolean;
|
|
282
|
+
readonly underline?: boolean;
|
|
283
|
+
readonly colorHex?: string;
|
|
284
|
+
readonly sizePt?: number;
|
|
285
|
+
readonly vertAlign?: 'superscript' | 'subscript';
|
|
286
|
+
}
|
|
207
287
|
export type DataValidationType = 'none' | 'whole' | 'decimal' | 'list' | 'date' | 'time' | 'textLength' | 'custom';
|
|
208
288
|
export interface DataValidation {
|
|
209
289
|
readonly type: DataValidationType;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface ActiveXProps {
|
|
2
|
+
readonly caption?: string;
|
|
3
|
+
readonly value?: string;
|
|
4
|
+
readonly groupName?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function parseActiveX(data: Uint8Array): ActiveXProps;
|
|
7
|
+
export declare function activeXType(progId: string | undefined): string;
|
|
8
|
+
export declare function activeXBinRelId(xmlData: Uint8Array): string | undefined;
|
|
9
|
+
export declare function parseActiveXBin(data: Uint8Array): ActiveXProps;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { XMLParser } from "fast-xml-parser";
|
|
2
|
+
//#region src/excel/activex-parser.ts
|
|
3
|
+
var decoder = new TextDecoder("utf-8");
|
|
4
|
+
var parser = new XMLParser({
|
|
5
|
+
ignoreAttributes: false,
|
|
6
|
+
attributeNamePrefix: "@_",
|
|
7
|
+
parseAttributeValue: false,
|
|
8
|
+
removeNSPrefix: true
|
|
9
|
+
});
|
|
10
|
+
function parseActiveX(data) {
|
|
11
|
+
const ocx = asObject(parser.parse(decoder.decode(data))["ocx"]);
|
|
12
|
+
if (!ocx) return {};
|
|
13
|
+
const props = /* @__PURE__ */ new Map();
|
|
14
|
+
for (const pr of toArray(ocx["ocxPr"])) {
|
|
15
|
+
const o = asObject(pr);
|
|
16
|
+
const name = o && strAttr(o, "name");
|
|
17
|
+
const value = o && strAttr(o, "value");
|
|
18
|
+
if (name) props.set(name.toLowerCase(), value ?? "");
|
|
19
|
+
}
|
|
20
|
+
const caption = props.get("caption");
|
|
21
|
+
const value = props.get("value");
|
|
22
|
+
const groupName = props.get("groupname");
|
|
23
|
+
return {
|
|
24
|
+
...caption !== void 0 ? { caption } : {},
|
|
25
|
+
...value !== void 0 ? { value } : {},
|
|
26
|
+
...groupName !== void 0 ? { groupName } : {}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function activeXType(progId) {
|
|
30
|
+
switch ((/Forms\.(\w+)\.\d+/i.exec(progId ?? "")?.[1] ?? "").toLowerCase()) {
|
|
31
|
+
case "checkbox": return "checkbox";
|
|
32
|
+
case "optionbutton": return "option";
|
|
33
|
+
case "commandbutton": return "button";
|
|
34
|
+
case "togglebutton": return "toggle";
|
|
35
|
+
case "textbox": return "textbox";
|
|
36
|
+
case "combobox": return "combo";
|
|
37
|
+
case "listbox": return "list";
|
|
38
|
+
case "label": return "label";
|
|
39
|
+
case "spinbutton": return "spin";
|
|
40
|
+
case "scrollbar": return "scroll";
|
|
41
|
+
case "frame": return "frame";
|
|
42
|
+
default: return "control";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function asObject(v) {
|
|
46
|
+
return v && typeof v === "object" && !Array.isArray(v) ? v : void 0;
|
|
47
|
+
}
|
|
48
|
+
function toArray(v) {
|
|
49
|
+
return Array.isArray(v) ? v : v !== void 0 && v !== null ? [v] : [];
|
|
50
|
+
}
|
|
51
|
+
function strAttr(obj, key) {
|
|
52
|
+
const v = obj[`@_${key}`];
|
|
53
|
+
return typeof v === "string" ? v : void 0;
|
|
54
|
+
}
|
|
55
|
+
function activeXBinRelId(xmlData) {
|
|
56
|
+
const ocx = asObject(parser.parse(decoder.decode(xmlData))["ocx"]);
|
|
57
|
+
if (!ocx) return void 0;
|
|
58
|
+
const persistence = strAttr(ocx, "persistence");
|
|
59
|
+
if (persistence !== "persistStreamInit" && persistence !== "persistStream" && persistence !== "persistStorage") return;
|
|
60
|
+
return strAttr(ocx, "id");
|
|
61
|
+
}
|
|
62
|
+
var CFB_MAGIC = [
|
|
63
|
+
208,
|
|
64
|
+
207,
|
|
65
|
+
17,
|
|
66
|
+
224,
|
|
67
|
+
161,
|
|
68
|
+
177,
|
|
69
|
+
26,
|
|
70
|
+
225
|
|
71
|
+
];
|
|
72
|
+
var MORPH_DATA_BLOCK_1 = [
|
|
73
|
+
[0, 4],
|
|
74
|
+
[1, 4],
|
|
75
|
+
[2, 4],
|
|
76
|
+
[3, 4],
|
|
77
|
+
[4, 1],
|
|
78
|
+
[5, 1],
|
|
79
|
+
[6, 1],
|
|
80
|
+
[7, 1],
|
|
81
|
+
[9, 2],
|
|
82
|
+
[10, 4],
|
|
83
|
+
[11, 2],
|
|
84
|
+
[12, 2],
|
|
85
|
+
[13, 2],
|
|
86
|
+
[14, 2],
|
|
87
|
+
[15, 2],
|
|
88
|
+
[16, 1],
|
|
89
|
+
[17, 1],
|
|
90
|
+
[18, 1],
|
|
91
|
+
[20, 1],
|
|
92
|
+
[21, 1]
|
|
93
|
+
];
|
|
94
|
+
var MORPH_DATA_BLOCK_2 = [
|
|
95
|
+
[24, 4],
|
|
96
|
+
[25, 4],
|
|
97
|
+
[26, 4],
|
|
98
|
+
[27, 2],
|
|
99
|
+
[28, 2],
|
|
100
|
+
[29, 2]
|
|
101
|
+
];
|
|
102
|
+
var BIT_F_SIZE = 8;
|
|
103
|
+
var BIT_F_VALUE = 22;
|
|
104
|
+
var BIT_F_CAPTION = 23;
|
|
105
|
+
var BIT_F_GROUP_NAME = 32;
|
|
106
|
+
var MORPH_MAJOR_VERSION = 2;
|
|
107
|
+
var ONE_8 = new TextDecoder("windows-1252");
|
|
108
|
+
var UTF16 = new TextDecoder("utf-16le");
|
|
109
|
+
function u16le(d, i) {
|
|
110
|
+
return d[i] | d[i + 1] << 8;
|
|
111
|
+
}
|
|
112
|
+
function u32le(d, i) {
|
|
113
|
+
return (d[i] | d[i + 1] << 8 | d[i + 2] << 16 | d[i + 3] << 24) >>> 0;
|
|
114
|
+
}
|
|
115
|
+
function parseActiveXBin(data) {
|
|
116
|
+
if (data.length >= 8 && CFB_MAGIC.every((b, i) => data[i] === b)) return {};
|
|
117
|
+
let off;
|
|
118
|
+
if (data.length >= 18 && data[16] === 0 && data[17] === MORPH_MAJOR_VERSION) off = 16;
|
|
119
|
+
else if (data.length >= 2 && data[0] === 0 && data[1] === MORPH_MAJOR_VERSION) off = 0;
|
|
120
|
+
if (off === void 0) return {};
|
|
121
|
+
let p = off + 2;
|
|
122
|
+
if (p + 10 > data.length) return {};
|
|
123
|
+
const cb = u16le(data, p);
|
|
124
|
+
p += 2;
|
|
125
|
+
const blockEnd = Math.min(data.length, p + cb);
|
|
126
|
+
const propLo = u32le(data, p);
|
|
127
|
+
const propHi = u32le(data, p + 4);
|
|
128
|
+
p += 8;
|
|
129
|
+
const dataStart = p;
|
|
130
|
+
const bit = (b) => (b < 32 ? propLo >>> b & 1 : propHi >>> b - 32 & 1) === 1;
|
|
131
|
+
const align = (n) => {
|
|
132
|
+
p += (n - (p - dataStart) % n) % n;
|
|
133
|
+
};
|
|
134
|
+
for (const [b, size] of MORPH_DATA_BLOCK_1) if (bit(b)) {
|
|
135
|
+
align(size);
|
|
136
|
+
p += size;
|
|
137
|
+
}
|
|
138
|
+
const readCount = () => {
|
|
139
|
+
align(4);
|
|
140
|
+
if (p + 4 > blockEnd) return void 0;
|
|
141
|
+
const v = u32le(data, p);
|
|
142
|
+
p += 4;
|
|
143
|
+
return v;
|
|
144
|
+
};
|
|
145
|
+
let valueCount;
|
|
146
|
+
let captionCount;
|
|
147
|
+
let groupCount;
|
|
148
|
+
if (bit(BIT_F_VALUE)) {
|
|
149
|
+
valueCount = readCount();
|
|
150
|
+
if (valueCount === void 0) return {};
|
|
151
|
+
}
|
|
152
|
+
if (bit(BIT_F_CAPTION)) {
|
|
153
|
+
captionCount = readCount();
|
|
154
|
+
if (captionCount === void 0) return {};
|
|
155
|
+
}
|
|
156
|
+
for (const [b, size] of MORPH_DATA_BLOCK_2) if (bit(b)) {
|
|
157
|
+
align(size);
|
|
158
|
+
p += size;
|
|
159
|
+
}
|
|
160
|
+
if (bit(BIT_F_GROUP_NAME)) {
|
|
161
|
+
groupCount = readCount();
|
|
162
|
+
if (groupCount === void 0) return {};
|
|
163
|
+
}
|
|
164
|
+
if (bit(BIT_F_SIZE)) {
|
|
165
|
+
align(4);
|
|
166
|
+
p += 8;
|
|
167
|
+
}
|
|
168
|
+
const readString = (count) => {
|
|
169
|
+
if (count === void 0) return void 0;
|
|
170
|
+
align(4);
|
|
171
|
+
const len = count & 2147483647;
|
|
172
|
+
if (len === 0) return "";
|
|
173
|
+
if (p + len > blockEnd) return void 0;
|
|
174
|
+
const slice = data.subarray(p, p + len);
|
|
175
|
+
p += len;
|
|
176
|
+
return (count & 2147483648) !== 0 ? ONE_8.decode(slice) : UTF16.decode(slice);
|
|
177
|
+
};
|
|
178
|
+
const value = readString(valueCount);
|
|
179
|
+
const caption = readString(captionCount);
|
|
180
|
+
const groupName = readString(groupCount);
|
|
181
|
+
return {
|
|
182
|
+
...caption !== void 0 && caption !== "" ? { caption } : {},
|
|
183
|
+
...value !== void 0 && value !== "" ? { value } : {},
|
|
184
|
+
...groupName !== void 0 && groupName !== "" ? { groupName } : {}
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
//#endregion
|
|
188
|
+
export { activeXBinRelId, activeXType, parseActiveX, parseActiveXBin };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SheetComment } from '../core/ir/sheet.js';
|
|
2
|
+
export declare function parseLegacyComments(data: Uint8Array): Array<SheetComment>;
|
|
3
|
+
export declare function parsePersons(data: Uint8Array): Map<string, string>;
|
|
4
|
+
export declare function parseThreadedComments(data: Uint8Array, persons: ReadonlyMap<string, string>): Array<SheetComment>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { XMLParser } from "fast-xml-parser";
|
|
2
|
+
//#region src/excel/comments-parser.ts
|
|
3
|
+
var decoder = new TextDecoder("utf-8");
|
|
4
|
+
var parser = new XMLParser({
|
|
5
|
+
ignoreAttributes: false,
|
|
6
|
+
attributeNamePrefix: "@_",
|
|
7
|
+
textNodeName: "#text",
|
|
8
|
+
parseAttributeValue: false,
|
|
9
|
+
parseTagValue: false,
|
|
10
|
+
trimValues: false,
|
|
11
|
+
removeNSPrefix: true
|
|
12
|
+
});
|
|
13
|
+
function parseLegacyComments(data) {
|
|
14
|
+
const root = asObject(parser.parse(decoder.decode(data))["comments"]);
|
|
15
|
+
if (!root) return [];
|
|
16
|
+
const authors = toArray(asObject(root["authors"])?.["author"]).map((a) => textOf(a));
|
|
17
|
+
const out = [];
|
|
18
|
+
for (const c of toArray(asObject(root["commentList"])?.["comment"])) {
|
|
19
|
+
const obj = asObject(c);
|
|
20
|
+
if (!obj) continue;
|
|
21
|
+
const ref = strAttr(obj, "ref");
|
|
22
|
+
if (!ref) continue;
|
|
23
|
+
const authorIdx = Number(strAttr(obj, "authorId"));
|
|
24
|
+
const author = Number.isInteger(authorIdx) ? authors[authorIdx] : void 0;
|
|
25
|
+
const text = stripAuthorPrefix(richText(obj["text"]), author);
|
|
26
|
+
if (text.length === 0 && !author) continue;
|
|
27
|
+
out.push({
|
|
28
|
+
ref,
|
|
29
|
+
...author ? { author } : {},
|
|
30
|
+
text,
|
|
31
|
+
threaded: false
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
function parsePersons(data) {
|
|
37
|
+
const root = asObject(parser.parse(decoder.decode(data))["personList"]);
|
|
38
|
+
const map = /* @__PURE__ */ new Map();
|
|
39
|
+
if (!root) return map;
|
|
40
|
+
for (const p of toArray(root["person"])) {
|
|
41
|
+
const obj = asObject(p);
|
|
42
|
+
const id = obj ? strAttr(obj, "id") : void 0;
|
|
43
|
+
const name = obj ? strAttr(obj, "displayName") : void 0;
|
|
44
|
+
if (id && name) map.set(id, name);
|
|
45
|
+
}
|
|
46
|
+
return map;
|
|
47
|
+
}
|
|
48
|
+
function parseThreadedComments(data, persons) {
|
|
49
|
+
const root = asObject(parser.parse(decoder.decode(data))["ThreadedComments"]);
|
|
50
|
+
if (!root) return [];
|
|
51
|
+
const out = [];
|
|
52
|
+
for (const c of toArray(root["threadedComment"])) {
|
|
53
|
+
const obj = asObject(c);
|
|
54
|
+
if (!obj) continue;
|
|
55
|
+
const ref = strAttr(obj, "ref");
|
|
56
|
+
if (!ref) continue;
|
|
57
|
+
const personId = strAttr(obj, "personId");
|
|
58
|
+
const author = personId ? persons.get(personId) : void 0;
|
|
59
|
+
const text = textOf(obj["text"]);
|
|
60
|
+
if (text.length === 0) continue;
|
|
61
|
+
out.push({
|
|
62
|
+
ref,
|
|
63
|
+
...author ? { author } : {},
|
|
64
|
+
text,
|
|
65
|
+
threaded: true
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
function richText(node) {
|
|
71
|
+
const obj = asObject(node);
|
|
72
|
+
if (!obj) return textOf(node);
|
|
73
|
+
const direct = textOf(obj["t"]);
|
|
74
|
+
if (direct) return direct;
|
|
75
|
+
return toArray(obj["r"]).map((r) => textOf(asObject(r)?.["t"])).join("");
|
|
76
|
+
}
|
|
77
|
+
function stripAuthorPrefix(text, author) {
|
|
78
|
+
if (!author) return text;
|
|
79
|
+
const prefix = `${author}:`;
|
|
80
|
+
if (text.startsWith(prefix)) return text.slice(prefix.length).replace(/^\s+/, "");
|
|
81
|
+
return text;
|
|
82
|
+
}
|
|
83
|
+
function asObject(v) {
|
|
84
|
+
return v && typeof v === "object" && !Array.isArray(v) ? v : void 0;
|
|
85
|
+
}
|
|
86
|
+
function toArray(v) {
|
|
87
|
+
return Array.isArray(v) ? v : v !== void 0 ? [v] : [];
|
|
88
|
+
}
|
|
89
|
+
function strAttr(obj, key) {
|
|
90
|
+
const v = obj[`@_${key}`];
|
|
91
|
+
return typeof v === "string" ? v : void 0;
|
|
92
|
+
}
|
|
93
|
+
function textOf(node) {
|
|
94
|
+
if (typeof node === "string") return node;
|
|
95
|
+
if (typeof node === "number") return String(node);
|
|
96
|
+
const obj = asObject(node);
|
|
97
|
+
if (!obj) return "";
|
|
98
|
+
const inner = obj["#text"];
|
|
99
|
+
if (typeof inner === "string") return inner;
|
|
100
|
+
if (typeof inner === "number") return String(inner);
|
|
101
|
+
return "";
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
104
|
+
export { parseLegacyComments, parsePersons, parseThreadedComments };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CellIcon } from '../core/document-model/index.js';
|
|
2
|
-
import { ConditionalFormat, WorksheetCell, XlsxStyles } from '../core/spreadsheet-model/index.js';
|
|
2
|
+
import { ConditionalFormat, DefinedName, WorksheetCell, XlsxStyles } from '../core/spreadsheet-model/index.js';
|
|
3
3
|
export interface CfOverride {
|
|
4
4
|
readonly fillHex?: string;
|
|
5
5
|
readonly fontColorHex?: string;
|
|
@@ -12,5 +12,7 @@ export interface CfOverride {
|
|
|
12
12
|
};
|
|
13
13
|
readonly icon?: CellIcon;
|
|
14
14
|
}
|
|
15
|
-
export type CellConditionalFormatter = (row: number, col: number, numericValue: number | undefined) => CfOverride | undefined;
|
|
16
|
-
export declare function buildConditionalFormatter(conditionalFormats: ReadonlyArray<ConditionalFormat> | undefined, styles: XlsxStyles, cells: ReadonlyArray<WorksheetCell
|
|
15
|
+
export type CellConditionalFormatter = (row: number, col: number, numericValue: number | undefined, text: string | undefined) => CfOverride | undefined;
|
|
16
|
+
export declare function buildConditionalFormatter(conditionalFormats: ReadonlyArray<ConditionalFormat> | undefined, styles: XlsxStyles, cells: ReadonlyArray<WorksheetCell>, resolveText?: (cell: WorksheetCell) => string, date1904?: boolean, now?: Date, sheetGrids?: ReadonlyMap<string, {
|
|
17
|
+
readonly cells: ReadonlyArray<WorksheetCell>;
|
|
18
|
+
}>, currentSheet?: string, definedNames?: ReadonlyArray<DefinedName>): CellConditionalFormatter | undefined;
|