@file-viewer/doc 2.1.10
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/LICENSE +21 -0
- package/README.en.md +34 -0
- package/README.md +263 -0
- package/dist/core/binary.d.ts +31 -0
- package/dist/core/binary.js +102 -0
- package/dist/core/cfb.d.ts +7 -0
- package/dist/core/cfb.js +286 -0
- package/dist/core/utils.d.ts +19 -0
- package/dist/core/utils.js +129 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4 -0
- package/dist/msdoc/clx.d.ts +18 -0
- package/dist/msdoc/clx.js +172 -0
- package/dist/msdoc/constants.d.ts +73 -0
- package/dist/msdoc/constants.js +73 -0
- package/dist/msdoc/fib.d.ts +4 -0
- package/dist/msdoc/fib.js +125 -0
- package/dist/msdoc/fkp.d.ts +19 -0
- package/dist/msdoc/fkp.js +184 -0
- package/dist/msdoc/fonts.d.ts +2 -0
- package/dist/msdoc/fonts.js +87 -0
- package/dist/msdoc/objects.d.ts +15 -0
- package/dist/msdoc/objects.js +192 -0
- package/dist/msdoc/parser.d.ts +8 -0
- package/dist/msdoc/parser.js +549 -0
- package/dist/msdoc/properties.d.ts +18 -0
- package/dist/msdoc/properties.js +405 -0
- package/dist/msdoc/sprm.d.ts +153 -0
- package/dist/msdoc/sprm.js +500 -0
- package/dist/msdoc/styles.d.ts +10 -0
- package/dist/msdoc/styles.js +214 -0
- package/dist/render/html.d.ts +8 -0
- package/dist/render/html.js +311 -0
- package/dist/types.d.ts +635 -0
- package/dist/types.js +1 -0
- package/dist/viewer.d.ts +8 -0
- package/dist/viewer.js +71 -0
- package/dist/worker-client.d.ts +19 -0
- package/dist/worker-client.js +71 -0
- package/dist/worker.d.ts +1 -0
- package/dist/worker.js +36 -0
- package/package.json +73 -0
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
import { HIGHLIGHT_COLORS } from './constants.js';
|
|
2
|
+
export const SprmCodes = {
|
|
3
|
+
sprmCFRMarkDel: 0x0800,
|
|
4
|
+
sprmCFRMark: 0x0801,
|
|
5
|
+
sprmCFFldVanish: 0x0802,
|
|
6
|
+
sprmCPicLocation: 0x6a03,
|
|
7
|
+
sprmCIbstRMark: 0x4804,
|
|
8
|
+
sprmCDttmRMark: 0x6805,
|
|
9
|
+
sprmCFData: 0x0806,
|
|
10
|
+
sprmCFOle2: 0x080a,
|
|
11
|
+
sprmCHighlight: 0x2a0c,
|
|
12
|
+
sprmCIstd: 0x4a30,
|
|
13
|
+
sprmCPlain: 0x2a33,
|
|
14
|
+
sprmCFBold: 0x0835,
|
|
15
|
+
sprmCFItalic: 0x0836,
|
|
16
|
+
sprmCFStrike: 0x0837,
|
|
17
|
+
sprmCFOutline: 0x0838,
|
|
18
|
+
sprmCFShadow: 0x0839,
|
|
19
|
+
sprmCFSmallCaps: 0x083a,
|
|
20
|
+
sprmCFCaps: 0x083b,
|
|
21
|
+
sprmCFVanish: 0x083c,
|
|
22
|
+
sprmCKul: 0x2a3e,
|
|
23
|
+
sprmCDxaSpace: 0x8840,
|
|
24
|
+
sprmCIco: 0x2a42,
|
|
25
|
+
sprmCHps: 0x4a43,
|
|
26
|
+
sprmCHpsPos: 0x4845,
|
|
27
|
+
sprmCSymbol: 0x6a09,
|
|
28
|
+
sprmCHpsKern: 0x484b,
|
|
29
|
+
sprmCRgFtc0: 0x4a4f,
|
|
30
|
+
sprmCRgFtc1: 0x4a50,
|
|
31
|
+
sprmCRgFtc2: 0x4a51,
|
|
32
|
+
sprmCCharScale: 0x4852,
|
|
33
|
+
sprmCFDStrike: 0x2a53,
|
|
34
|
+
sprmCFImprint: 0x0854,
|
|
35
|
+
sprmCFSpec: 0x0855,
|
|
36
|
+
sprmCFObj: 0x0856,
|
|
37
|
+
sprmCFEmboss: 0x0858,
|
|
38
|
+
sprmCFBiDi: 0x085a,
|
|
39
|
+
sprmCFBoldBi: 0x085c,
|
|
40
|
+
sprmCFItalicBi: 0x085d,
|
|
41
|
+
sprmCFtcBi: 0x4a5e,
|
|
42
|
+
sprmCIcoBi: 0x4a60,
|
|
43
|
+
sprmCHpsBi: 0x4a61,
|
|
44
|
+
sprmPIstd: 0x4600,
|
|
45
|
+
sprmPIstdPermute: 0xc601,
|
|
46
|
+
sprmPIncLvl: 0x2602,
|
|
47
|
+
sprmPJc80: 0x2403,
|
|
48
|
+
sprmPFKeep: 0x2405,
|
|
49
|
+
sprmPFKeepFollow: 0x2406,
|
|
50
|
+
sprmPFPageBreakBefore: 0x2407,
|
|
51
|
+
sprmPIlvl: 0x260a,
|
|
52
|
+
sprmPIlfo: 0x460b,
|
|
53
|
+
sprmPChgTabsPapx: 0xc60d,
|
|
54
|
+
sprmPDxaRight80: 0x840e,
|
|
55
|
+
sprmPDxaLeft80: 0x840f,
|
|
56
|
+
sprmPNest80: 0x4610,
|
|
57
|
+
sprmPDxaLeft180: 0x8411,
|
|
58
|
+
sprmPDyaLine: 0x6412,
|
|
59
|
+
sprmPDyaBefore: 0xa413,
|
|
60
|
+
sprmPDyaAfter: 0xa414,
|
|
61
|
+
sprmPChgTabs: 0xc615,
|
|
62
|
+
sprmPFInTable: 0x2416,
|
|
63
|
+
sprmPFTtp: 0x2417,
|
|
64
|
+
sprmPDxaAbs: 0x8418,
|
|
65
|
+
sprmPDyaAbs: 0x8419,
|
|
66
|
+
sprmPDxaWidth: 0x841a,
|
|
67
|
+
sprmPPc: 0x261b,
|
|
68
|
+
sprmPWr: 0x2423,
|
|
69
|
+
sprmPBrcTop80: 0x6424,
|
|
70
|
+
sprmPBrcLeft80: 0x6425,
|
|
71
|
+
sprmPBrcBottom80: 0x6426,
|
|
72
|
+
sprmPBrcRight80: 0x6427,
|
|
73
|
+
sprmPBrcBetween80: 0x6428,
|
|
74
|
+
sprmPBrcBar80: 0x6629,
|
|
75
|
+
sprmPWHeightAbs: 0x442b,
|
|
76
|
+
sprmPDcs: 0x442c,
|
|
77
|
+
sprmPShd80: 0x442d,
|
|
78
|
+
sprmPDyaFromText: 0x842e,
|
|
79
|
+
sprmPDxaFromText: 0x842f,
|
|
80
|
+
sprmPFLocked: 0x2430,
|
|
81
|
+
sprmPFWidowControl: 0x2431,
|
|
82
|
+
sprmPFBiDi: 0x2441,
|
|
83
|
+
sprmPHugePapx: 0x6646,
|
|
84
|
+
sprmPFAdjustRight: 0x2448,
|
|
85
|
+
sprmPItap: 0x6649,
|
|
86
|
+
sprmPDtap: 0x664a,
|
|
87
|
+
sprmPFInnerTableCell: 0x244b,
|
|
88
|
+
sprmPFInnerTtp: 0x244c,
|
|
89
|
+
sprmPShd: 0xc64d,
|
|
90
|
+
sprmPBrcTop: 0xc64e,
|
|
91
|
+
sprmPBrcLeft: 0xc64f,
|
|
92
|
+
sprmPBrcBottom: 0xc650,
|
|
93
|
+
sprmPBrcRight: 0xc651,
|
|
94
|
+
sprmPBrcBetween: 0xc652,
|
|
95
|
+
sprmPBrcBar: 0xc653,
|
|
96
|
+
sprmPDxcRight: 0x4455,
|
|
97
|
+
sprmPDxcLeft: 0x4456,
|
|
98
|
+
sprmPDxcLeft1: 0x4457,
|
|
99
|
+
sprmPDylBefore: 0x4458,
|
|
100
|
+
sprmPDylAfter: 0x4459,
|
|
101
|
+
sprmPFDyaBeforeAuto: 0x245b,
|
|
102
|
+
sprmPFDyaAfterAuto: 0x245c,
|
|
103
|
+
sprmPDxaRight: 0x845d,
|
|
104
|
+
sprmPDxaLeft: 0x845e,
|
|
105
|
+
sprmPNest: 0x465f,
|
|
106
|
+
sprmPDxaLeft1: 0x8460,
|
|
107
|
+
sprmPJc: 0x2461,
|
|
108
|
+
sprmTJc90: 0x5400,
|
|
109
|
+
sprmTDxaLeft: 0x9601,
|
|
110
|
+
sprmTDxaGapHalf: 0x9602,
|
|
111
|
+
sprmTFCantSplit90: 0x3403,
|
|
112
|
+
sprmTTableHeader: 0x3404,
|
|
113
|
+
sprmTTableBorders80: 0xd605,
|
|
114
|
+
sprmTDyaRowHeight: 0x9407,
|
|
115
|
+
sprmTDefTable: 0xd608,
|
|
116
|
+
sprmTDefTableShd80: 0xd609,
|
|
117
|
+
sprmTTlp: 0x740a,
|
|
118
|
+
sprmTFBiDi: 0x560b,
|
|
119
|
+
sprmTDefTableShd3rd: 0xd60c,
|
|
120
|
+
sprmTPc: 0x360d,
|
|
121
|
+
sprmTDxaAbs: 0x940e,
|
|
122
|
+
sprmTDyaAbs: 0x940f,
|
|
123
|
+
sprmTDxaFromText: 0x9410,
|
|
124
|
+
sprmTDyaFromText: 0x9411,
|
|
125
|
+
sprmTDefTableShd: 0xd612,
|
|
126
|
+
sprmTTableBorders: 0xd613,
|
|
127
|
+
sprmTTableWidth: 0xf614,
|
|
128
|
+
sprmTFAutofit: 0x3615,
|
|
129
|
+
sprmTWidthBefore: 0xf617,
|
|
130
|
+
sprmTWidthAfter: 0xf618,
|
|
131
|
+
sprmTSetBrc80: 0xd620,
|
|
132
|
+
sprmTInsert: 0x7621,
|
|
133
|
+
sprmTDelete: 0x5622,
|
|
134
|
+
sprmTDxaCol: 0x7623,
|
|
135
|
+
sprmTMerge: 0x5624,
|
|
136
|
+
sprmTSplit: 0x5625,
|
|
137
|
+
sprmTTextFlow: 0x7629,
|
|
138
|
+
sprmTVertMerge: 0xd62b,
|
|
139
|
+
sprmTVertAlign: 0xd62c,
|
|
140
|
+
sprmTSetShd: 0xd62d,
|
|
141
|
+
sprmTSetShdOdd: 0xd62e,
|
|
142
|
+
sprmTSetBrc: 0xd62f,
|
|
143
|
+
sprmTCellPadding: 0xd632,
|
|
144
|
+
sprmTCellPaddingDefault: 0xd633,
|
|
145
|
+
sprmTCellWidth: 0xd635,
|
|
146
|
+
sprmTFitText: 0xf636,
|
|
147
|
+
sprmTFCellNoWrap: 0xd639,
|
|
148
|
+
sprmTIstd: 0x563a,
|
|
149
|
+
};
|
|
150
|
+
const VARIABLE_OPERAND_CODES = new Set([
|
|
151
|
+
SprmCodes.sprmPChgTabs,
|
|
152
|
+
SprmCodes.sprmPChgTabsPapx,
|
|
153
|
+
SprmCodes.sprmTDefTable,
|
|
154
|
+
SprmCodes.sprmTTableBorders80,
|
|
155
|
+
SprmCodes.sprmTTableBorders,
|
|
156
|
+
SprmCodes.sprmTDefTableShd,
|
|
157
|
+
SprmCodes.sprmTDefTableShd80,
|
|
158
|
+
SprmCodes.sprmTDefTableShd3rd,
|
|
159
|
+
SprmCodes.sprmTSetBrc80,
|
|
160
|
+
SprmCodes.sprmTSetBrc,
|
|
161
|
+
SprmCodes.sprmTSetShd,
|
|
162
|
+
SprmCodes.sprmTSetShdOdd,
|
|
163
|
+
SprmCodes.sprmTCellPadding,
|
|
164
|
+
SprmCodes.sprmTCellPaddingDefault,
|
|
165
|
+
SprmCodes.sprmTCellWidth,
|
|
166
|
+
SprmCodes.sprmTVertAlign,
|
|
167
|
+
SprmCodes.sprmTVertMerge,
|
|
168
|
+
SprmCodes.sprmTTextFlow,
|
|
169
|
+
SprmCodes.sprmTDxaCol,
|
|
170
|
+
]);
|
|
171
|
+
export function getSprmGroup(sprm) {
|
|
172
|
+
return (sprm >> 13) & 0x7;
|
|
173
|
+
}
|
|
174
|
+
function u16(bytes, offset = 0) {
|
|
175
|
+
if (offset + 2 > bytes.length)
|
|
176
|
+
return 0;
|
|
177
|
+
return (bytes[offset] ?? 0) | ((bytes[offset + 1] ?? 0) << 8);
|
|
178
|
+
}
|
|
179
|
+
function i16(bytes, offset = 0) {
|
|
180
|
+
const value = u16(bytes, offset);
|
|
181
|
+
return value > 0x7fff ? value - 0x10000 : value;
|
|
182
|
+
}
|
|
183
|
+
function u32(bytes, offset = 0) {
|
|
184
|
+
if (offset + 4 > bytes.length)
|
|
185
|
+
return 0;
|
|
186
|
+
return ((bytes[offset] ?? 0)
|
|
187
|
+
| ((bytes[offset + 1] ?? 0) << 8)
|
|
188
|
+
| ((bytes[offset + 2] ?? 0) << 16)
|
|
189
|
+
| (((bytes[offset + 3] ?? 0) << 24) >>> 0)) >>> 0;
|
|
190
|
+
}
|
|
191
|
+
function parseItcFirstLim(bytes, offset = 0) {
|
|
192
|
+
return {
|
|
193
|
+
first: bytes[offset] ?? 0,
|
|
194
|
+
lim: bytes[offset + 1] ?? 0,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
function parseBrc80(bytes, offset = 0) {
|
|
198
|
+
if (offset + 4 > bytes.length)
|
|
199
|
+
return null;
|
|
200
|
+
const brc = u32(bytes, offset) >>> 0;
|
|
201
|
+
const lineWidth = brc & 0xff;
|
|
202
|
+
const borderType = (brc >> 8) & 0xff;
|
|
203
|
+
const color = (brc >> 16) & 0xff;
|
|
204
|
+
return { raw: brc, lineWidth, borderType, color };
|
|
205
|
+
}
|
|
206
|
+
function parseTcgrf(bytes, offset = 0) {
|
|
207
|
+
const value = u16(bytes, offset);
|
|
208
|
+
return {
|
|
209
|
+
raw: value,
|
|
210
|
+
horzMerge: value & 0x3,
|
|
211
|
+
textFlow: (value >> 2) & 0x7,
|
|
212
|
+
vertMerge: (value >> 5) & 0x3,
|
|
213
|
+
vertAlign: (value >> 7) & 0x3,
|
|
214
|
+
ftsWidth: (value >> 9) & 0x7,
|
|
215
|
+
fitText: Boolean(value & (1 << 12)),
|
|
216
|
+
noWrap: Boolean(value & (1 << 13)),
|
|
217
|
+
hideMark: Boolean(value & (1 << 14)),
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function parseTc80(bytes, offset = 0) {
|
|
221
|
+
if (offset + 20 > bytes.length)
|
|
222
|
+
return null;
|
|
223
|
+
return {
|
|
224
|
+
tcgrf: parseTcgrf(bytes, offset),
|
|
225
|
+
wWidth: u16(bytes, offset + 2),
|
|
226
|
+
borders: {
|
|
227
|
+
top: parseBrc80(bytes, offset + 4) || {},
|
|
228
|
+
left: parseBrc80(bytes, offset + 8) || {},
|
|
229
|
+
bottom: parseBrc80(bytes, offset + 12) || {},
|
|
230
|
+
right: parseBrc80(bytes, offset + 16) || {},
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
function parseTDefTableOperand(bytes) {
|
|
235
|
+
if (bytes.length < 3)
|
|
236
|
+
return null;
|
|
237
|
+
const cb = u16(bytes, 0);
|
|
238
|
+
const numberOfColumns = bytes[2] ?? 0;
|
|
239
|
+
let offset = 3;
|
|
240
|
+
const rgdxaCenter = [];
|
|
241
|
+
for (let i = 0; i < numberOfColumns + 1 && offset + 2 <= bytes.length; i += 1) {
|
|
242
|
+
rgdxaCenter.push(i16(bytes, offset));
|
|
243
|
+
offset += 2;
|
|
244
|
+
}
|
|
245
|
+
const cells = [];
|
|
246
|
+
for (let i = 0; i < numberOfColumns && offset + 20 <= bytes.length; i += 1) {
|
|
247
|
+
const cell = parseTc80(bytes, offset);
|
|
248
|
+
if (cell)
|
|
249
|
+
cells.push(cell);
|
|
250
|
+
offset += 20;
|
|
251
|
+
}
|
|
252
|
+
return { cb, numberOfColumns, rgdxaCenter, cells };
|
|
253
|
+
}
|
|
254
|
+
function parseRangeValueOperand(bytes) {
|
|
255
|
+
if (!bytes.length)
|
|
256
|
+
return null;
|
|
257
|
+
const cb = bytes[0] ?? 0;
|
|
258
|
+
return {
|
|
259
|
+
cb,
|
|
260
|
+
range: parseItcFirstLim(bytes, 1),
|
|
261
|
+
value: bytes[3] ?? 0,
|
|
262
|
+
extra: bytes.subarray(4),
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
function parseRangeWidthOperand(bytes) {
|
|
266
|
+
if (!bytes.length)
|
|
267
|
+
return null;
|
|
268
|
+
const cb = bytes[0] ?? 0;
|
|
269
|
+
const width = u16(bytes, 4);
|
|
270
|
+
return {
|
|
271
|
+
cb,
|
|
272
|
+
range: parseItcFirstLim(bytes, 1),
|
|
273
|
+
ftsWidth: bytes[3] ?? 0,
|
|
274
|
+
width,
|
|
275
|
+
wWidth: width,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
function parseRangeBrcOperand(bytes) {
|
|
279
|
+
if (!bytes.length)
|
|
280
|
+
return null;
|
|
281
|
+
return {
|
|
282
|
+
cb: bytes[0] ?? 0,
|
|
283
|
+
range: parseItcFirstLim(bytes, 1),
|
|
284
|
+
border: parseBrc80(bytes, 3) || {},
|
|
285
|
+
extra: bytes.subarray(7),
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
function parseTTableWidth(bytes) {
|
|
289
|
+
if (!bytes.length)
|
|
290
|
+
return null;
|
|
291
|
+
const width = u16(bytes, 1);
|
|
292
|
+
return {
|
|
293
|
+
ftsWidth: bytes[0] ?? 0,
|
|
294
|
+
width,
|
|
295
|
+
wWidth: width,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
function parseTInsertOperand(bytes) {
|
|
299
|
+
if (!bytes.length)
|
|
300
|
+
return null;
|
|
301
|
+
const cb = bytes[0] ?? 0;
|
|
302
|
+
const itc = parseItcFirstLim(bytes, 1);
|
|
303
|
+
const ctc = itc.lim - itc.first;
|
|
304
|
+
let offset = 3;
|
|
305
|
+
const dxaCol = [];
|
|
306
|
+
for (let i = 0; i < ctc && offset + 2 <= bytes.length; i += 1) {
|
|
307
|
+
dxaCol.push(i16(bytes, offset));
|
|
308
|
+
offset += 2;
|
|
309
|
+
}
|
|
310
|
+
const cells = [];
|
|
311
|
+
for (let i = 0; i < ctc && offset + 20 <= bytes.length; i += 1) {
|
|
312
|
+
cells.push(parseTc80(bytes, offset));
|
|
313
|
+
offset += 20;
|
|
314
|
+
}
|
|
315
|
+
return { cb, range: itc, itcFirst: itc.first, ctc, dxaCol, cells };
|
|
316
|
+
}
|
|
317
|
+
export function getSprmOperandLength(buffer, offset, sprm) {
|
|
318
|
+
const spra = (sprm >> 13) & 0x7;
|
|
319
|
+
if (offset >= buffer.length)
|
|
320
|
+
return 0;
|
|
321
|
+
if (sprm === SprmCodes.sprmTDefTable) {
|
|
322
|
+
const cb = u16(buffer, offset);
|
|
323
|
+
return cb ? cb + 1 : 0;
|
|
324
|
+
}
|
|
325
|
+
if (VARIABLE_OPERAND_CODES.has(sprm)) {
|
|
326
|
+
const cb = buffer[offset] ?? 0;
|
|
327
|
+
return cb + 1;
|
|
328
|
+
}
|
|
329
|
+
switch (spra) {
|
|
330
|
+
case 0: return 1;
|
|
331
|
+
case 1: return 1;
|
|
332
|
+
case 2: return 2;
|
|
333
|
+
case 3: return 4;
|
|
334
|
+
case 4: return 2;
|
|
335
|
+
case 5: return 2;
|
|
336
|
+
case 6: {
|
|
337
|
+
const cb = buffer[offset] ?? 0;
|
|
338
|
+
return cb + 1;
|
|
339
|
+
}
|
|
340
|
+
case 7: return 3;
|
|
341
|
+
default: return 0;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
function boolValue(bytes) {
|
|
345
|
+
return Boolean(bytes[0] ?? 0);
|
|
346
|
+
}
|
|
347
|
+
function setMeta(kind, name, value, raw, bytes) {
|
|
348
|
+
return { kind, name, value, raw, operandBytes: bytes };
|
|
349
|
+
}
|
|
350
|
+
export function decodeSprm(sprm, operandBytes) {
|
|
351
|
+
const group = getSprmGroup(sprm);
|
|
352
|
+
const bytes = operandBytes;
|
|
353
|
+
const raw = sprm;
|
|
354
|
+
switch (sprm) {
|
|
355
|
+
case SprmCodes.sprmCPicLocation: return setMeta('char', 'pictureOffset', u32(bytes, 0) >>> 0, raw, bytes);
|
|
356
|
+
case SprmCodes.sprmCFData: return setMeta('char', 'data', boolValue(bytes), raw, bytes);
|
|
357
|
+
case SprmCodes.sprmCFOle2: return setMeta('char', 'ole2', boolValue(bytes), raw, bytes);
|
|
358
|
+
case SprmCodes.sprmCIstd: return setMeta('char', 'charStyleId', u16(bytes, 0), raw, bytes);
|
|
359
|
+
case SprmCodes.sprmCPlain: return setMeta('char', 'plain', boolValue(bytes), raw, bytes);
|
|
360
|
+
case SprmCodes.sprmCFBold: return setMeta('char', 'bold', boolValue(bytes), raw, bytes);
|
|
361
|
+
case SprmCodes.sprmCFItalic: return setMeta('char', 'italic', boolValue(bytes), raw, bytes);
|
|
362
|
+
case SprmCodes.sprmCFStrike: return setMeta('char', 'strike', boolValue(bytes), raw, bytes);
|
|
363
|
+
case SprmCodes.sprmCFOutline: return setMeta('char', 'outline', boolValue(bytes), raw, bytes);
|
|
364
|
+
case SprmCodes.sprmCFShadow: return setMeta('char', 'shadow', boolValue(bytes), raw, bytes);
|
|
365
|
+
case SprmCodes.sprmCFSmallCaps: return setMeta('char', 'smallCaps', boolValue(bytes), raw, bytes);
|
|
366
|
+
case SprmCodes.sprmCFCaps: return setMeta('char', 'caps', boolValue(bytes), raw, bytes);
|
|
367
|
+
case SprmCodes.sprmCFVanish: return setMeta('char', 'hidden', boolValue(bytes), raw, bytes);
|
|
368
|
+
case SprmCodes.sprmCKul: return setMeta('char', 'underline', bytes[0] ?? 0, raw, bytes);
|
|
369
|
+
case SprmCodes.sprmCDxaSpace: return setMeta('char', 'spacing', i16(bytes, 0), raw, bytes);
|
|
370
|
+
case SprmCodes.sprmCIco:
|
|
371
|
+
case SprmCodes.sprmCIcoBi: return setMeta('char', 'colorIndex', bytes[0] ?? 0, raw, bytes);
|
|
372
|
+
case SprmCodes.sprmCHighlight: {
|
|
373
|
+
const index = bytes[0] ?? 0;
|
|
374
|
+
const highlight = { index, color: HIGHLIGHT_COLORS[index] };
|
|
375
|
+
return setMeta('char', 'highlight', highlight, raw, bytes);
|
|
376
|
+
}
|
|
377
|
+
case SprmCodes.sprmCHps:
|
|
378
|
+
case SprmCodes.sprmCHpsBi: return setMeta('char', 'fontSizeHalfPoints', u16(bytes, 0), raw, bytes);
|
|
379
|
+
case SprmCodes.sprmCHpsPos: return setMeta('char', 'positionHalfPoints', i16(bytes, 0), raw, bytes);
|
|
380
|
+
case SprmCodes.sprmCSymbol: return setMeta('char', 'symbol', { font: u16(bytes, 0), charCode: u16(bytes, 2) }, raw, bytes);
|
|
381
|
+
case SprmCodes.sprmCRgFtc0:
|
|
382
|
+
case SprmCodes.sprmCRgFtc1:
|
|
383
|
+
case SprmCodes.sprmCRgFtc2:
|
|
384
|
+
case SprmCodes.sprmCFtcBi: return setMeta('char', 'fontFamilyId', u16(bytes, 0), raw, bytes);
|
|
385
|
+
case SprmCodes.sprmCCharScale: return setMeta('char', 'scale', u16(bytes, 0), raw, bytes);
|
|
386
|
+
case SprmCodes.sprmCFDStrike: return setMeta('char', 'doubleStrike', boolValue(bytes), raw, bytes);
|
|
387
|
+
case SprmCodes.sprmCFImprint: return setMeta('char', 'imprint', boolValue(bytes), raw, bytes);
|
|
388
|
+
case SprmCodes.sprmCFSpec: return setMeta('char', 'special', boolValue(bytes), raw, bytes);
|
|
389
|
+
case SprmCodes.sprmCFObj: return setMeta('char', 'object', boolValue(bytes), raw, bytes);
|
|
390
|
+
case SprmCodes.sprmCFEmboss: return setMeta('char', 'emboss', boolValue(bytes), raw, bytes);
|
|
391
|
+
case SprmCodes.sprmCFBiDi: return setMeta('char', 'rtl', boolValue(bytes), raw, bytes);
|
|
392
|
+
case SprmCodes.sprmCFBoldBi: return setMeta('char', 'boldBi', boolValue(bytes), raw, bytes);
|
|
393
|
+
case SprmCodes.sprmCFItalicBi: return setMeta('char', 'italicBi', boolValue(bytes), raw, bytes);
|
|
394
|
+
case SprmCodes.sprmPIstd: return setMeta('para', 'styleId', u16(bytes, 0), raw, bytes);
|
|
395
|
+
case SprmCodes.sprmPJc80:
|
|
396
|
+
case SprmCodes.sprmPJc: return setMeta('para', 'alignment', bytes[0] ?? 0, raw, bytes);
|
|
397
|
+
case SprmCodes.sprmPFKeep: return setMeta('para', 'keepLines', boolValue(bytes), raw, bytes);
|
|
398
|
+
case SprmCodes.sprmPFKeepFollow: return setMeta('para', 'keepNext', boolValue(bytes), raw, bytes);
|
|
399
|
+
case SprmCodes.sprmPFPageBreakBefore: return setMeta('para', 'pageBreakBefore', boolValue(bytes), raw, bytes);
|
|
400
|
+
case SprmCodes.sprmPIlvl: return setMeta('para', 'listLevel', bytes[0] ?? 0, raw, bytes);
|
|
401
|
+
case SprmCodes.sprmPIlfo: return setMeta('para', 'listId', u16(bytes, 0), raw, bytes);
|
|
402
|
+
case SprmCodes.sprmPDxaRight80:
|
|
403
|
+
case SprmCodes.sprmPDxaRight: return setMeta('para', 'rightIndent', i16(bytes, 0), raw, bytes);
|
|
404
|
+
case SprmCodes.sprmPDxaLeft80:
|
|
405
|
+
case SprmCodes.sprmPDxaLeft: return setMeta('para', 'leftIndent', i16(bytes, 0), raw, bytes);
|
|
406
|
+
case SprmCodes.sprmPDxaLeft180:
|
|
407
|
+
case SprmCodes.sprmPDxaLeft1: return setMeta('para', 'firstLineIndent', i16(bytes, 0), raw, bytes);
|
|
408
|
+
case SprmCodes.sprmPDyaLine: return setMeta('para', 'lineSpacing', i16(bytes, 0), raw, bytes);
|
|
409
|
+
case SprmCodes.sprmPDyaBefore: return setMeta('para', 'spacingBefore', i16(bytes, 0), raw, bytes);
|
|
410
|
+
case SprmCodes.sprmPDyaAfter: return setMeta('para', 'spacingAfter', i16(bytes, 0), raw, bytes);
|
|
411
|
+
case SprmCodes.sprmPFInTable: return setMeta('para', 'inTable', boolValue(bytes), raw, bytes);
|
|
412
|
+
case SprmCodes.sprmPFTtp: return setMeta('para', 'tableRowEnd', boolValue(bytes), raw, bytes);
|
|
413
|
+
case SprmCodes.sprmPDxaAbs: return setMeta('para', 'frameLeft', i16(bytes, 0), raw, bytes);
|
|
414
|
+
case SprmCodes.sprmPDyaAbs: return setMeta('para', 'frameTop', i16(bytes, 0), raw, bytes);
|
|
415
|
+
case SprmCodes.sprmPDxaWidth: return setMeta('para', 'frameWidth', i16(bytes, 0), raw, bytes);
|
|
416
|
+
case SprmCodes.sprmPPc: return setMeta('para', 'framePosition', bytes[0] ?? 0, raw, bytes);
|
|
417
|
+
case SprmCodes.sprmPWr: return setMeta('para', 'frameWrap', bytes[0] ?? 0, raw, bytes);
|
|
418
|
+
case SprmCodes.sprmPBrcTop80:
|
|
419
|
+
case SprmCodes.sprmPBrcTop: return setMeta('para', 'borderTop', parseBrc80(bytes, 0), raw, bytes);
|
|
420
|
+
case SprmCodes.sprmPBrcLeft80:
|
|
421
|
+
case SprmCodes.sprmPBrcLeft: return setMeta('para', 'borderLeft', parseBrc80(bytes, 0), raw, bytes);
|
|
422
|
+
case SprmCodes.sprmPBrcBottom80:
|
|
423
|
+
case SprmCodes.sprmPBrcBottom: return setMeta('para', 'borderBottom', parseBrc80(bytes, 0), raw, bytes);
|
|
424
|
+
case SprmCodes.sprmPBrcRight80:
|
|
425
|
+
case SprmCodes.sprmPBrcRight: return setMeta('para', 'borderRight', parseBrc80(bytes, 0), raw, bytes);
|
|
426
|
+
case SprmCodes.sprmPBrcBetween80:
|
|
427
|
+
case SprmCodes.sprmPBrcBetween: return setMeta('para', 'borderBetween', parseBrc80(bytes, 0), raw, bytes);
|
|
428
|
+
case SprmCodes.sprmPBrcBar80:
|
|
429
|
+
case SprmCodes.sprmPBrcBar: return setMeta('para', 'borderBar', parseBrc80(bytes, 0), raw, bytes);
|
|
430
|
+
case SprmCodes.sprmPWHeightAbs: return setMeta('para', 'frameHeight', i16(bytes, 0), raw, bytes);
|
|
431
|
+
case SprmCodes.sprmPShd80:
|
|
432
|
+
case SprmCodes.sprmPShd: return setMeta('para', 'shading', bytes.slice(), raw, bytes);
|
|
433
|
+
case SprmCodes.sprmPDyaFromText: return setMeta('para', 'distanceFromTextY', i16(bytes, 0), raw, bytes);
|
|
434
|
+
case SprmCodes.sprmPDxaFromText: return setMeta('para', 'distanceFromTextX', i16(bytes, 0), raw, bytes);
|
|
435
|
+
case SprmCodes.sprmPFLocked: return setMeta('para', 'locked', boolValue(bytes), raw, bytes);
|
|
436
|
+
case SprmCodes.sprmPFWidowControl: return setMeta('para', 'widowControl', boolValue(bytes), raw, bytes);
|
|
437
|
+
case SprmCodes.sprmPFBiDi: return setMeta('para', 'rtlPara', boolValue(bytes), raw, bytes);
|
|
438
|
+
case SprmCodes.sprmPFAdjustRight: return setMeta('para', 'adjustRight', boolValue(bytes), raw, bytes);
|
|
439
|
+
case SprmCodes.sprmPItap: return setMeta('para', 'itap', u32(bytes, 0), raw, bytes);
|
|
440
|
+
case SprmCodes.sprmPDtap: return setMeta('para', 'dtap', u32(bytes, 0), raw, bytes);
|
|
441
|
+
case SprmCodes.sprmPFInnerTableCell: return setMeta('para', 'innerTableCell', boolValue(bytes), raw, bytes);
|
|
442
|
+
case SprmCodes.sprmPFInnerTtp: return setMeta('para', 'innerTableRowEnd', boolValue(bytes), raw, bytes);
|
|
443
|
+
case SprmCodes.sprmPFDyaBeforeAuto: return setMeta('para', 'spacingBeforeAuto', boolValue(bytes), raw, bytes);
|
|
444
|
+
case SprmCodes.sprmPFDyaAfterAuto: return setMeta('para', 'spacingAfterAuto', boolValue(bytes), raw, bytes);
|
|
445
|
+
case SprmCodes.sprmTJc90: return setMeta('table', 'alignment', u16(bytes, 0), raw, bytes);
|
|
446
|
+
case SprmCodes.sprmTDxaLeft: return setMeta('table', 'leftIndent', i16(bytes, 0), raw, bytes);
|
|
447
|
+
case SprmCodes.sprmTDxaGapHalf: return setMeta('table', 'gapHalf', u16(bytes, 0), raw, bytes);
|
|
448
|
+
case SprmCodes.sprmTFCantSplit90: return setMeta('table', 'cantSplit', boolValue(bytes), raw, bytes);
|
|
449
|
+
case SprmCodes.sprmTTableHeader: return setMeta('table', 'header', boolValue(bytes), raw, bytes);
|
|
450
|
+
case SprmCodes.sprmTDyaRowHeight: return setMeta('table', 'rowHeight', i16(bytes, 0), raw, bytes);
|
|
451
|
+
case SprmCodes.sprmTDefTable: return setMeta('table', 'defTable', parseTDefTableOperand(bytes), raw, bytes);
|
|
452
|
+
case SprmCodes.sprmTFBiDi: return setMeta('table', 'rtl', boolValue(bytes), raw, bytes);
|
|
453
|
+
case SprmCodes.sprmTPc: return setMeta('table', 'positionCode', bytes[0] ?? 0, raw, bytes);
|
|
454
|
+
case SprmCodes.sprmTDxaAbs: return setMeta('table', 'absLeft', i16(bytes, 0), raw, bytes);
|
|
455
|
+
case SprmCodes.sprmTDyaAbs: return setMeta('table', 'absTop', i16(bytes, 0), raw, bytes);
|
|
456
|
+
case SprmCodes.sprmTDxaFromText: return setMeta('table', 'distanceLeft', i16(bytes, 0), raw, bytes);
|
|
457
|
+
case SprmCodes.sprmTDyaFromText: return setMeta('table', 'distanceTop', i16(bytes, 0), raw, bytes);
|
|
458
|
+
case SprmCodes.sprmTTableWidth: return setMeta('table', 'tableWidth', parseTTableWidth(bytes), raw, bytes);
|
|
459
|
+
case SprmCodes.sprmTFAutofit: return setMeta('table', 'autoFit', boolValue(bytes), raw, bytes);
|
|
460
|
+
case SprmCodes.sprmTWidthBefore: return setMeta('table', 'widthBefore', parseTTableWidth(bytes), raw, bytes);
|
|
461
|
+
case SprmCodes.sprmTWidthAfter: return setMeta('table', 'widthAfter', parseTTableWidth(bytes), raw, bytes);
|
|
462
|
+
case SprmCodes.sprmTInsert: return setMeta('table', 'insertCells', parseTInsertOperand(bytes), raw, bytes);
|
|
463
|
+
case SprmCodes.sprmTDelete: return setMeta('table', 'deleteCells', parseItcFirstLim(bytes, 0), raw, bytes);
|
|
464
|
+
case SprmCodes.sprmTDxaCol: return setMeta('table', 'columnWidth', parseRangeWidthOperand(bytes), raw, bytes);
|
|
465
|
+
case SprmCodes.sprmTMerge: return setMeta('table', 'merge', parseItcFirstLim(bytes, 0), raw, bytes);
|
|
466
|
+
case SprmCodes.sprmTSplit: return setMeta('table', 'split', parseItcFirstLim(bytes, 0), raw, bytes);
|
|
467
|
+
case SprmCodes.sprmTTextFlow: return setMeta('table', 'textFlow', parseRangeValueOperand(bytes), raw, bytes);
|
|
468
|
+
case SprmCodes.sprmTVertMerge: return setMeta('table', 'vertMerge', parseRangeValueOperand(bytes), raw, bytes);
|
|
469
|
+
case SprmCodes.sprmTVertAlign: return setMeta('table', 'vertAlign', parseRangeValueOperand(bytes), raw, bytes);
|
|
470
|
+
case SprmCodes.sprmTSetShd:
|
|
471
|
+
case SprmCodes.sprmTSetShdOdd: return setMeta('table', 'setShading', parseRangeValueOperand(bytes), raw, bytes);
|
|
472
|
+
case SprmCodes.sprmTSetBrc80:
|
|
473
|
+
case SprmCodes.sprmTSetBrc: return setMeta('table', 'setBorder', parseRangeBrcOperand(bytes), raw, bytes);
|
|
474
|
+
case SprmCodes.sprmTCellPadding:
|
|
475
|
+
case SprmCodes.sprmTCellPaddingDefault: return setMeta('table', 'cellPadding', parseRangeWidthOperand(bytes), raw, bytes);
|
|
476
|
+
case SprmCodes.sprmTCellWidth: return setMeta('table', 'cellWidth', parseRangeWidthOperand(bytes), raw, bytes);
|
|
477
|
+
case SprmCodes.sprmTFitText: return setMeta('table', 'fitText', parseRangeValueOperand(bytes), raw, bytes);
|
|
478
|
+
case SprmCodes.sprmTFCellNoWrap: return setMeta('table', 'cellNoWrap', parseRangeValueOperand(bytes), raw, bytes);
|
|
479
|
+
case SprmCodes.sprmTIstd: return setMeta('table', 'styleId', u16(bytes, 0), raw, bytes);
|
|
480
|
+
default: {
|
|
481
|
+
const kind = group === 1 ? 'para' : group === 2 ? 'char' : group === 5 ? 'table' : 'unknown';
|
|
482
|
+
return { kind, name: `sprm_${sprm.toString(16)}`, value: bytes, raw: sprm, operandBytes: bytes };
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
export function decodeGrpprl(buffer, startOffset, endOffset) {
|
|
487
|
+
const properties = [];
|
|
488
|
+
let offset = startOffset;
|
|
489
|
+
while (offset + 2 <= endOffset) {
|
|
490
|
+
const sprm = u16(buffer, offset);
|
|
491
|
+
offset += 2;
|
|
492
|
+
const operandLength = getSprmOperandLength(buffer, offset, sprm);
|
|
493
|
+
if (!operandLength || offset + operandLength > endOffset)
|
|
494
|
+
break;
|
|
495
|
+
const bytes = buffer.subarray(offset, offset + operandLength);
|
|
496
|
+
offset += operandLength;
|
|
497
|
+
properties.push(decodeSprm(sprm, bytes));
|
|
498
|
+
}
|
|
499
|
+
return properties;
|
|
500
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DecodedProperty, FibRgFcLcb, ResolvedStyle, StyleCollection, StyleDefinition } from '../types.js';
|
|
2
|
+
declare function mergePropertyArrays(...arrays: Array<DecodedProperty[] | undefined | null>): DecodedProperty[];
|
|
3
|
+
declare function splitPropertiesByKind(properties: DecodedProperty[]): {
|
|
4
|
+
para: DecodedProperty[];
|
|
5
|
+
char: DecodedProperty[];
|
|
6
|
+
table: DecodedProperty[];
|
|
7
|
+
};
|
|
8
|
+
export declare function parseStyles(tableBytes: Uint8Array, fibRgFcLcb: FibRgFcLcb): StyleCollection;
|
|
9
|
+
export declare function resolveStyle(styleMap: Map<number, StyleDefinition>, istd: number | null | undefined, seen?: Set<number>): ResolvedStyle;
|
|
10
|
+
export { mergePropertyArrays, splitPropertiesByKind };
|