wpd-codec 1.0.1 → 1.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 +71 -28
- package/dist/container/summary.cjs +78 -0
- package/dist/container/summary.d.cts +6 -0
- package/dist/container/summary.d.ts +6 -0
- package/dist/container/summary.js +76 -0
- package/dist/diagnostics-CR0pXOyb.d.cts +25 -0
- package/dist/diagnostics-CR0pXOyb.d.ts +25 -0
- package/dist/diagnostics.cjs +11 -1
- package/dist/diagnostics.d.cts +1 -1
- package/dist/diagnostics.d.ts +1 -1
- package/dist/diagnostics.js +11 -1
- package/dist/index.cjs +48 -0
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +7 -1
- package/dist/read.cjs +286 -36
- package/dist/read.d.cts +1 -1
- package/dist/read.d.ts +1 -1
- package/dist/read.js +287 -37
- package/dist/stream/page.cjs +47 -0
- package/dist/stream/page.d.cts +20 -0
- package/dist/stream/page.d.ts +20 -0
- package/dist/stream/page.js +35 -0
- package/dist/stream/style.cjs +80 -0
- package/dist/stream/style.d.cts +16 -0
- package/dist/stream/style.d.ts +16 -0
- package/dist/stream/style.js +71 -0
- package/dist/stream/tab.cjs +33 -0
- package/dist/stream/tab.d.cts +12 -0
- package/dist/stream/tab.d.ts +12 -0
- package/dist/stream/tab.js +31 -0
- package/dist/stream/table.cjs +160 -0
- package/dist/stream/table.d.cts +43 -0
- package/dist/stream/table.d.ts +43 -0
- package/dist/stream/table.js +146 -0
- package/dist/stream/units.cjs +11 -0
- package/dist/stream/units.d.cts +6 -0
- package/dist/stream/units.d.ts +6 -0
- package/dist/stream/units.js +8 -0
- package/package.json +2 -2
- package/dist/diagnostics-Cp0HKphg.d.cts +0 -15
- package/dist/diagnostics-Cp0HKphg.d.ts +0 -15
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
//#region src/stream/style.ts
|
|
2
|
+
const STYLE_GROUP = 221;
|
|
3
|
+
const DISPLAY_NUMBER_GROUP = 218;
|
|
4
|
+
const STYLE_BEGIN_ON = 0;
|
|
5
|
+
const STYLE_END_OFF = 3;
|
|
6
|
+
const PARAGRAPH_STYLE_BEGIN_ON = 4;
|
|
7
|
+
const PARAGRAPH_STYLE_END_OFF = 9;
|
|
8
|
+
const GLOBAL_ON = 10;
|
|
9
|
+
const GLOBAL_OFF = 11;
|
|
10
|
+
const STYLE_SCOPE_OPENERS = /* @__PURE__ */ new Set([
|
|
11
|
+
STYLE_BEGIN_ON,
|
|
12
|
+
PARAGRAPH_STYLE_BEGIN_ON,
|
|
13
|
+
GLOBAL_ON
|
|
14
|
+
]);
|
|
15
|
+
const STYLE_SCOPE_CLOSERS = /* @__PURE__ */ new Set([
|
|
16
|
+
STYLE_END_OFF,
|
|
17
|
+
PARAGRAPH_STYLE_END_OFF,
|
|
18
|
+
GLOBAL_OFF
|
|
19
|
+
]);
|
|
20
|
+
function isStyleScopeOpener(subfunction) {
|
|
21
|
+
return STYLE_SCOPE_OPENERS.has(subfunction);
|
|
22
|
+
}
|
|
23
|
+
function isStyleScopeCloser(subfunction) {
|
|
24
|
+
return STYLE_SCOPE_CLOSERS.has(subfunction);
|
|
25
|
+
}
|
|
26
|
+
const SYSTEM_STYLE_NUMBER_OFFSET = 2;
|
|
27
|
+
const SYSTEM_STYLE_NONE = 255;
|
|
28
|
+
function readSystemStyleNumber(nonDeletable) {
|
|
29
|
+
const value = nonDeletable[SYSTEM_STYLE_NUMBER_OFFSET];
|
|
30
|
+
if (value === void 0 || value === SYSTEM_STYLE_NONE) return;
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
const FIRST_HEADING_LEVEL_STYLE = 68;
|
|
34
|
+
const LAST_HEADING_LEVEL_STYLE = 75;
|
|
35
|
+
const FIRST_INDENTED_LEVEL_STYLE = 52;
|
|
36
|
+
const LAST_INDENTED_LEVEL_STYLE = 59;
|
|
37
|
+
const FIRST_PLAIN_LEVEL_STYLE = 60;
|
|
38
|
+
const LAST_PLAIN_LEVEL_STYLE = 67;
|
|
39
|
+
const LIST_STYLE = 31;
|
|
40
|
+
const BULLETS_STYLE = 48;
|
|
41
|
+
function styleSemanticsFor(systemStyleNumber) {
|
|
42
|
+
if (systemStyleNumber >= FIRST_HEADING_LEVEL_STYLE && systemStyleNumber <= LAST_HEADING_LEVEL_STYLE) return {
|
|
43
|
+
headingLevel: systemStyleNumber - FIRST_HEADING_LEVEL_STYLE + 1,
|
|
44
|
+
listLevel: void 0
|
|
45
|
+
};
|
|
46
|
+
if (systemStyleNumber >= FIRST_INDENTED_LEVEL_STYLE && systemStyleNumber <= LAST_INDENTED_LEVEL_STYLE) return {
|
|
47
|
+
headingLevel: void 0,
|
|
48
|
+
listLevel: systemStyleNumber - FIRST_INDENTED_LEVEL_STYLE
|
|
49
|
+
};
|
|
50
|
+
if (systemStyleNumber >= FIRST_PLAIN_LEVEL_STYLE && systemStyleNumber <= LAST_PLAIN_LEVEL_STYLE) return {
|
|
51
|
+
headingLevel: void 0,
|
|
52
|
+
listLevel: systemStyleNumber - FIRST_PLAIN_LEVEL_STYLE
|
|
53
|
+
};
|
|
54
|
+
if (systemStyleNumber === LIST_STYLE || systemStyleNumber === BULLETS_STYLE) return {
|
|
55
|
+
headingLevel: void 0,
|
|
56
|
+
listLevel: 0
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const PARAGRAPH_NUMBER_DISPLAY_ON = 12;
|
|
60
|
+
const PARAGRAPH_NUMBER_DISPLAY_OFF = 13;
|
|
61
|
+
function isParagraphNumberDisplayOn(subfunction) {
|
|
62
|
+
return subfunction === PARAGRAPH_NUMBER_DISPLAY_ON;
|
|
63
|
+
}
|
|
64
|
+
function isParagraphNumberDisplayOff(subfunction) {
|
|
65
|
+
return subfunction === PARAGRAPH_NUMBER_DISPLAY_OFF;
|
|
66
|
+
}
|
|
67
|
+
function readDisplayNumberLevel(nonDeletable) {
|
|
68
|
+
return nonDeletable[0];
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { DISPLAY_NUMBER_GROUP, STYLE_GROUP, isParagraphNumberDisplayOff, isParagraphNumberDisplayOn, isStyleScopeCloser, isStyleScopeOpener, readDisplayNumberLevel, readSystemStyleNumber, styleSemanticsFor };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/stream/tab.ts
|
|
3
|
+
const TAB_GROUP = 224;
|
|
4
|
+
const TAB_TYPE_SHIFT = 3;
|
|
5
|
+
const TAB_EFFECTS = /* @__PURE__ */ new Map([
|
|
6
|
+
[0, { kind: "tab" }],
|
|
7
|
+
[1, { kind: "tab" }],
|
|
8
|
+
[2, { kind: "tab" }],
|
|
9
|
+
[4, { kind: "tab" }],
|
|
10
|
+
[6, { kind: "tab" }],
|
|
11
|
+
[7, { kind: "tab" }],
|
|
12
|
+
[10, { kind: "tab" }],
|
|
13
|
+
[18, { kind: "tab" }],
|
|
14
|
+
[26, { kind: "tab" }],
|
|
15
|
+
[8, {
|
|
16
|
+
kind: "align",
|
|
17
|
+
alignment: "center"
|
|
18
|
+
}],
|
|
19
|
+
[9, {
|
|
20
|
+
kind: "align",
|
|
21
|
+
alignment: "center"
|
|
22
|
+
}],
|
|
23
|
+
[16, {
|
|
24
|
+
kind: "align",
|
|
25
|
+
alignment: "right"
|
|
26
|
+
}]
|
|
27
|
+
]);
|
|
28
|
+
function tabEffectFor(tabDefinition) {
|
|
29
|
+
return TAB_EFFECTS.get(tabDefinition >> TAB_TYPE_SHIFT);
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
exports.TAB_GROUP = TAB_GROUP;
|
|
33
|
+
exports.tabEffectFor = tabEffectFor;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Alignment } from "document-schema.js";
|
|
2
|
+
//#region src/stream/tab.d.ts
|
|
3
|
+
declare const TAB_GROUP = 224;
|
|
4
|
+
type WpdTabEffect = {
|
|
5
|
+
readonly kind: "tab";
|
|
6
|
+
} | {
|
|
7
|
+
readonly kind: "align";
|
|
8
|
+
readonly alignment: Alignment;
|
|
9
|
+
};
|
|
10
|
+
declare function tabEffectFor(tabDefinition: number): WpdTabEffect | undefined;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { TAB_GROUP, WpdTabEffect, tabEffectFor };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Alignment } from "document-schema.js";
|
|
2
|
+
//#region src/stream/tab.d.ts
|
|
3
|
+
declare const TAB_GROUP = 224;
|
|
4
|
+
type WpdTabEffect = {
|
|
5
|
+
readonly kind: "tab";
|
|
6
|
+
} | {
|
|
7
|
+
readonly kind: "align";
|
|
8
|
+
readonly alignment: Alignment;
|
|
9
|
+
};
|
|
10
|
+
declare function tabEffectFor(tabDefinition: number): WpdTabEffect | undefined;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { TAB_GROUP, WpdTabEffect, tabEffectFor };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/stream/tab.ts
|
|
2
|
+
const TAB_GROUP = 224;
|
|
3
|
+
const TAB_TYPE_SHIFT = 3;
|
|
4
|
+
const TAB_EFFECTS = /* @__PURE__ */ new Map([
|
|
5
|
+
[0, { kind: "tab" }],
|
|
6
|
+
[1, { kind: "tab" }],
|
|
7
|
+
[2, { kind: "tab" }],
|
|
8
|
+
[4, { kind: "tab" }],
|
|
9
|
+
[6, { kind: "tab" }],
|
|
10
|
+
[7, { kind: "tab" }],
|
|
11
|
+
[10, { kind: "tab" }],
|
|
12
|
+
[18, { kind: "tab" }],
|
|
13
|
+
[26, { kind: "tab" }],
|
|
14
|
+
[8, {
|
|
15
|
+
kind: "align",
|
|
16
|
+
alignment: "center"
|
|
17
|
+
}],
|
|
18
|
+
[9, {
|
|
19
|
+
kind: "align",
|
|
20
|
+
alignment: "center"
|
|
21
|
+
}],
|
|
22
|
+
[16, {
|
|
23
|
+
kind: "align",
|
|
24
|
+
alignment: "right"
|
|
25
|
+
}]
|
|
26
|
+
]);
|
|
27
|
+
function tabEffectFor(tabDefinition) {
|
|
28
|
+
return TAB_EFFECTS.get(tabDefinition >> TAB_TYPE_SHIFT);
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { TAB_GROUP, tabEffectFor };
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_bytes_view = require("../bytes/view.cjs");
|
|
3
|
+
const require_stream_units = require("./units.cjs");
|
|
4
|
+
//#region src/stream/table.ts
|
|
5
|
+
const CHARACTER_TABLE_DEFINITION = 42;
|
|
6
|
+
const CHARACTER_DEFINE_TABLE_END = 43;
|
|
7
|
+
const CHARACTER_TABLE_COLUMN = 44;
|
|
8
|
+
const COLUMN_WIDTH_OFFSET = 1;
|
|
9
|
+
const COLUMN_NON_DELETABLE_SIZE = 17;
|
|
10
|
+
function readTableColumnWidthPt(nonDeletable) {
|
|
11
|
+
if (nonDeletable.length < COLUMN_NON_DELETABLE_SIZE) return;
|
|
12
|
+
const widthWpu = require_bytes_view.uint16At(nonDeletable, COLUMN_WIDTH_OFFSET);
|
|
13
|
+
if (widthWpu <= 0) return;
|
|
14
|
+
return require_stream_units.pointsFromWpu(widthWpu);
|
|
15
|
+
}
|
|
16
|
+
const EMBEDDED_SUBFUNCTION_SIZES = /* @__PURE__ */ new Map([
|
|
17
|
+
[128, 5],
|
|
18
|
+
[130, 4],
|
|
19
|
+
[131, 4],
|
|
20
|
+
[132, 9],
|
|
21
|
+
[133, 4],
|
|
22
|
+
[134, 10],
|
|
23
|
+
[135, 6],
|
|
24
|
+
[136, 5],
|
|
25
|
+
[137, 11],
|
|
26
|
+
[139, 3],
|
|
27
|
+
[140, 3]
|
|
28
|
+
]);
|
|
29
|
+
const CELL_FORMULA_SUBFUNCTION = 129;
|
|
30
|
+
const CELL_FORMULA_FRAMING_SIZE = 6;
|
|
31
|
+
const DONT_END_PARAGRAPH_STYLE_SUBFUNCTION = 141;
|
|
32
|
+
const ROW_INFORMATION_SUBFUNCTION = 128;
|
|
33
|
+
const CELL_INFORMATION_SUBFUNCTION = 132;
|
|
34
|
+
const CELL_SPANNING_SUBFUNCTION = 133;
|
|
35
|
+
const CELL_FILL_COLORS_SUBFUNCTION = 134;
|
|
36
|
+
function readEmbeddedSubfunctions(nonDeletable) {
|
|
37
|
+
if (nonDeletable.length < 2) return {
|
|
38
|
+
subfunctions: [],
|
|
39
|
+
truncated: false
|
|
40
|
+
};
|
|
41
|
+
let cursor = 2 + require_bytes_view.uint16At(nonDeletable, 0);
|
|
42
|
+
if (cursor > nonDeletable.length) return {
|
|
43
|
+
subfunctions: [],
|
|
44
|
+
truncated: true
|
|
45
|
+
};
|
|
46
|
+
const subfunctions = [];
|
|
47
|
+
while (cursor < nonDeletable.length) {
|
|
48
|
+
const code = nonDeletable[cursor];
|
|
49
|
+
if (code === void 0) break;
|
|
50
|
+
if (code === DONT_END_PARAGRAPH_STYLE_SUBFUNCTION) {
|
|
51
|
+
subfunctions.push({
|
|
52
|
+
code,
|
|
53
|
+
data: /* @__PURE__ */ new Uint8Array(0)
|
|
54
|
+
});
|
|
55
|
+
cursor += 1;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const size = code === CELL_FORMULA_SUBFUNCTION ? cursor + 3 <= nonDeletable.length ? require_bytes_view.uint16At(nonDeletable, cursor + 1) + CELL_FORMULA_FRAMING_SIZE : void 0 : EMBEDDED_SUBFUNCTION_SIZES.get(code);
|
|
59
|
+
if (size === void 0 || cursor + size > nonDeletable.length) return {
|
|
60
|
+
subfunctions,
|
|
61
|
+
truncated: true
|
|
62
|
+
};
|
|
63
|
+
if (nonDeletable[cursor + size - 1] !== code) return {
|
|
64
|
+
subfunctions,
|
|
65
|
+
truncated: true
|
|
66
|
+
};
|
|
67
|
+
subfunctions.push({
|
|
68
|
+
code,
|
|
69
|
+
data: nonDeletable.subarray(cursor + 1, cursor + size - 1)
|
|
70
|
+
});
|
|
71
|
+
cursor += size;
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
subfunctions,
|
|
75
|
+
truncated: false
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function findEmbeddedSubfunction(subfunctions, code) {
|
|
79
|
+
return subfunctions.find((subfunction) => subfunction.code === code)?.data;
|
|
80
|
+
}
|
|
81
|
+
const ROW_FLAG_FIXED_HEIGHT = 2;
|
|
82
|
+
const ROW_FLAG_HEADER_ROW = 4;
|
|
83
|
+
function readRowInformation(data) {
|
|
84
|
+
const flags = data[0];
|
|
85
|
+
if (flags === void 0 || data.length < 3) return;
|
|
86
|
+
const heightWpu = require_bytes_view.uint16At(data, 1);
|
|
87
|
+
const fixedHeight = (flags & ROW_FLAG_FIXED_HEIGHT) !== 0;
|
|
88
|
+
return {
|
|
89
|
+
headerRow: (flags & ROW_FLAG_HEADER_ROW) !== 0,
|
|
90
|
+
heightPt: fixedHeight && heightWpu > 0 ? require_stream_units.pointsFromWpu(heightWpu) : void 0
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const CELL_JUSTIFICATION = [
|
|
94
|
+
"left",
|
|
95
|
+
"justify",
|
|
96
|
+
"center",
|
|
97
|
+
"right",
|
|
98
|
+
"justify",
|
|
99
|
+
"left"
|
|
100
|
+
];
|
|
101
|
+
const CELL_FLAG_USE_JUSTIFICATION = 2;
|
|
102
|
+
const CELL_JUSTIFICATION_MASK = 7;
|
|
103
|
+
function readCellInformation(data) {
|
|
104
|
+
const flag = data[0];
|
|
105
|
+
const justification = data[1];
|
|
106
|
+
if (flag === void 0 || justification === void 0) return;
|
|
107
|
+
if ((flag & CELL_FLAG_USE_JUSTIFICATION) === 0) return { alignment: void 0 };
|
|
108
|
+
return { alignment: CELL_JUSTIFICATION[justification & CELL_JUSTIFICATION_MASK] };
|
|
109
|
+
}
|
|
110
|
+
const SPAN_COVERED_FLAG = 128;
|
|
111
|
+
const SPAN_COUNT_MASK = 127;
|
|
112
|
+
function readCellSpanning(data) {
|
|
113
|
+
const horizontal = data[0];
|
|
114
|
+
const vertical = data[1];
|
|
115
|
+
if (horizontal === void 0 || vertical === void 0) return;
|
|
116
|
+
return {
|
|
117
|
+
columnSpan: horizontal & SPAN_COUNT_MASK,
|
|
118
|
+
rowSpan: vertical & SPAN_COUNT_MASK,
|
|
119
|
+
coveredFromLeft: (horizontal & SPAN_COVERED_FLAG) !== 0,
|
|
120
|
+
coveredFromAbove: (vertical & SPAN_COVERED_FLAG) !== 0
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const COLOR_COMPONENT_MAX = 255;
|
|
124
|
+
const RGBS_SIZE = 4;
|
|
125
|
+
const FULL_SHADE = 255;
|
|
126
|
+
function colorAt(data, offset) {
|
|
127
|
+
const r = data[offset];
|
|
128
|
+
const g = data[offset + 1];
|
|
129
|
+
const b = data[offset + 2];
|
|
130
|
+
if (r === void 0 || g === void 0 || b === void 0) return;
|
|
131
|
+
return {
|
|
132
|
+
r: r / COLOR_COMPONENT_MAX,
|
|
133
|
+
g: g / COLOR_COMPONENT_MAX,
|
|
134
|
+
b: b / COLOR_COMPONENT_MAX
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function readCellFill(data) {
|
|
138
|
+
const background = colorAt(data, RGBS_SIZE);
|
|
139
|
+
if (background === void 0) return;
|
|
140
|
+
const backgroundShade = data[7];
|
|
141
|
+
return {
|
|
142
|
+
background,
|
|
143
|
+
blended: backgroundShade !== void 0 && backgroundShade !== FULL_SHADE
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
//#endregion
|
|
147
|
+
exports.CELL_FILL_COLORS_SUBFUNCTION = CELL_FILL_COLORS_SUBFUNCTION;
|
|
148
|
+
exports.CELL_INFORMATION_SUBFUNCTION = CELL_INFORMATION_SUBFUNCTION;
|
|
149
|
+
exports.CELL_SPANNING_SUBFUNCTION = CELL_SPANNING_SUBFUNCTION;
|
|
150
|
+
exports.CHARACTER_DEFINE_TABLE_END = CHARACTER_DEFINE_TABLE_END;
|
|
151
|
+
exports.CHARACTER_TABLE_COLUMN = CHARACTER_TABLE_COLUMN;
|
|
152
|
+
exports.CHARACTER_TABLE_DEFINITION = CHARACTER_TABLE_DEFINITION;
|
|
153
|
+
exports.ROW_INFORMATION_SUBFUNCTION = ROW_INFORMATION_SUBFUNCTION;
|
|
154
|
+
exports.findEmbeddedSubfunction = findEmbeddedSubfunction;
|
|
155
|
+
exports.readCellFill = readCellFill;
|
|
156
|
+
exports.readCellInformation = readCellInformation;
|
|
157
|
+
exports.readCellSpanning = readCellSpanning;
|
|
158
|
+
exports.readEmbeddedSubfunctions = readEmbeddedSubfunctions;
|
|
159
|
+
exports.readRowInformation = readRowInformation;
|
|
160
|
+
exports.readTableColumnWidthPt = readTableColumnWidthPt;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Alignment, Color } from "document-schema.js";
|
|
2
|
+
//#region src/stream/table.d.ts
|
|
3
|
+
declare const CHARACTER_TABLE_DEFINITION = 42;
|
|
4
|
+
declare const CHARACTER_DEFINE_TABLE_END = 43;
|
|
5
|
+
declare const CHARACTER_TABLE_COLUMN = 44;
|
|
6
|
+
declare function readTableColumnWidthPt(nonDeletable: Uint8Array): number | undefined;
|
|
7
|
+
declare const ROW_INFORMATION_SUBFUNCTION = 128;
|
|
8
|
+
declare const CELL_INFORMATION_SUBFUNCTION = 132;
|
|
9
|
+
declare const CELL_SPANNING_SUBFUNCTION = 133;
|
|
10
|
+
declare const CELL_FILL_COLORS_SUBFUNCTION = 134;
|
|
11
|
+
interface WpdEmbeddedSubfunction {
|
|
12
|
+
readonly code: number;
|
|
13
|
+
readonly data: Uint8Array;
|
|
14
|
+
}
|
|
15
|
+
interface WpdEmbeddedSubfunctions {
|
|
16
|
+
readonly subfunctions: readonly WpdEmbeddedSubfunction[];
|
|
17
|
+
readonly truncated: boolean;
|
|
18
|
+
}
|
|
19
|
+
declare function readEmbeddedSubfunctions(nonDeletable: Uint8Array): WpdEmbeddedSubfunctions;
|
|
20
|
+
declare function findEmbeddedSubfunction(subfunctions: readonly WpdEmbeddedSubfunction[], code: number): Uint8Array | undefined;
|
|
21
|
+
interface WpdRowInformation {
|
|
22
|
+
readonly headerRow: boolean;
|
|
23
|
+
readonly heightPt: number | undefined;
|
|
24
|
+
}
|
|
25
|
+
declare function readRowInformation(data: Uint8Array): WpdRowInformation | undefined;
|
|
26
|
+
interface WpdCellInformation {
|
|
27
|
+
readonly alignment: Alignment | undefined;
|
|
28
|
+
}
|
|
29
|
+
declare function readCellInformation(data: Uint8Array): WpdCellInformation | undefined;
|
|
30
|
+
interface WpdCellSpanning {
|
|
31
|
+
readonly columnSpan: number;
|
|
32
|
+
readonly rowSpan: number;
|
|
33
|
+
readonly coveredFromLeft: boolean;
|
|
34
|
+
readonly coveredFromAbove: boolean;
|
|
35
|
+
}
|
|
36
|
+
declare function readCellSpanning(data: Uint8Array): WpdCellSpanning | undefined;
|
|
37
|
+
interface WpdCellFill {
|
|
38
|
+
readonly background: Color;
|
|
39
|
+
readonly blended: boolean;
|
|
40
|
+
}
|
|
41
|
+
declare function readCellFill(data: Uint8Array): WpdCellFill | undefined;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { CELL_FILL_COLORS_SUBFUNCTION, CELL_INFORMATION_SUBFUNCTION, CELL_SPANNING_SUBFUNCTION, CHARACTER_DEFINE_TABLE_END, CHARACTER_TABLE_COLUMN, CHARACTER_TABLE_DEFINITION, ROW_INFORMATION_SUBFUNCTION, WpdCellFill, WpdCellInformation, WpdCellSpanning, WpdEmbeddedSubfunction, WpdEmbeddedSubfunctions, WpdRowInformation, findEmbeddedSubfunction, readCellFill, readCellInformation, readCellSpanning, readEmbeddedSubfunctions, readRowInformation, readTableColumnWidthPt };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Alignment, Color } from "document-schema.js";
|
|
2
|
+
//#region src/stream/table.d.ts
|
|
3
|
+
declare const CHARACTER_TABLE_DEFINITION = 42;
|
|
4
|
+
declare const CHARACTER_DEFINE_TABLE_END = 43;
|
|
5
|
+
declare const CHARACTER_TABLE_COLUMN = 44;
|
|
6
|
+
declare function readTableColumnWidthPt(nonDeletable: Uint8Array): number | undefined;
|
|
7
|
+
declare const ROW_INFORMATION_SUBFUNCTION = 128;
|
|
8
|
+
declare const CELL_INFORMATION_SUBFUNCTION = 132;
|
|
9
|
+
declare const CELL_SPANNING_SUBFUNCTION = 133;
|
|
10
|
+
declare const CELL_FILL_COLORS_SUBFUNCTION = 134;
|
|
11
|
+
interface WpdEmbeddedSubfunction {
|
|
12
|
+
readonly code: number;
|
|
13
|
+
readonly data: Uint8Array;
|
|
14
|
+
}
|
|
15
|
+
interface WpdEmbeddedSubfunctions {
|
|
16
|
+
readonly subfunctions: readonly WpdEmbeddedSubfunction[];
|
|
17
|
+
readonly truncated: boolean;
|
|
18
|
+
}
|
|
19
|
+
declare function readEmbeddedSubfunctions(nonDeletable: Uint8Array): WpdEmbeddedSubfunctions;
|
|
20
|
+
declare function findEmbeddedSubfunction(subfunctions: readonly WpdEmbeddedSubfunction[], code: number): Uint8Array | undefined;
|
|
21
|
+
interface WpdRowInformation {
|
|
22
|
+
readonly headerRow: boolean;
|
|
23
|
+
readonly heightPt: number | undefined;
|
|
24
|
+
}
|
|
25
|
+
declare function readRowInformation(data: Uint8Array): WpdRowInformation | undefined;
|
|
26
|
+
interface WpdCellInformation {
|
|
27
|
+
readonly alignment: Alignment | undefined;
|
|
28
|
+
}
|
|
29
|
+
declare function readCellInformation(data: Uint8Array): WpdCellInformation | undefined;
|
|
30
|
+
interface WpdCellSpanning {
|
|
31
|
+
readonly columnSpan: number;
|
|
32
|
+
readonly rowSpan: number;
|
|
33
|
+
readonly coveredFromLeft: boolean;
|
|
34
|
+
readonly coveredFromAbove: boolean;
|
|
35
|
+
}
|
|
36
|
+
declare function readCellSpanning(data: Uint8Array): WpdCellSpanning | undefined;
|
|
37
|
+
interface WpdCellFill {
|
|
38
|
+
readonly background: Color;
|
|
39
|
+
readonly blended: boolean;
|
|
40
|
+
}
|
|
41
|
+
declare function readCellFill(data: Uint8Array): WpdCellFill | undefined;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { CELL_FILL_COLORS_SUBFUNCTION, CELL_INFORMATION_SUBFUNCTION, CELL_SPANNING_SUBFUNCTION, CHARACTER_DEFINE_TABLE_END, CHARACTER_TABLE_COLUMN, CHARACTER_TABLE_DEFINITION, ROW_INFORMATION_SUBFUNCTION, WpdCellFill, WpdCellInformation, WpdCellSpanning, WpdEmbeddedSubfunction, WpdEmbeddedSubfunctions, WpdRowInformation, findEmbeddedSubfunction, readCellFill, readCellInformation, readCellSpanning, readEmbeddedSubfunctions, readRowInformation, readTableColumnWidthPt };
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { uint16At } from "../bytes/view.js";
|
|
2
|
+
import { pointsFromWpu } from "./units.js";
|
|
3
|
+
//#region src/stream/table.ts
|
|
4
|
+
const CHARACTER_TABLE_DEFINITION = 42;
|
|
5
|
+
const CHARACTER_DEFINE_TABLE_END = 43;
|
|
6
|
+
const CHARACTER_TABLE_COLUMN = 44;
|
|
7
|
+
const COLUMN_WIDTH_OFFSET = 1;
|
|
8
|
+
const COLUMN_NON_DELETABLE_SIZE = 17;
|
|
9
|
+
function readTableColumnWidthPt(nonDeletable) {
|
|
10
|
+
if (nonDeletable.length < COLUMN_NON_DELETABLE_SIZE) return;
|
|
11
|
+
const widthWpu = uint16At(nonDeletable, COLUMN_WIDTH_OFFSET);
|
|
12
|
+
if (widthWpu <= 0) return;
|
|
13
|
+
return pointsFromWpu(widthWpu);
|
|
14
|
+
}
|
|
15
|
+
const EMBEDDED_SUBFUNCTION_SIZES = /* @__PURE__ */ new Map([
|
|
16
|
+
[128, 5],
|
|
17
|
+
[130, 4],
|
|
18
|
+
[131, 4],
|
|
19
|
+
[132, 9],
|
|
20
|
+
[133, 4],
|
|
21
|
+
[134, 10],
|
|
22
|
+
[135, 6],
|
|
23
|
+
[136, 5],
|
|
24
|
+
[137, 11],
|
|
25
|
+
[139, 3],
|
|
26
|
+
[140, 3]
|
|
27
|
+
]);
|
|
28
|
+
const CELL_FORMULA_SUBFUNCTION = 129;
|
|
29
|
+
const CELL_FORMULA_FRAMING_SIZE = 6;
|
|
30
|
+
const DONT_END_PARAGRAPH_STYLE_SUBFUNCTION = 141;
|
|
31
|
+
const ROW_INFORMATION_SUBFUNCTION = 128;
|
|
32
|
+
const CELL_INFORMATION_SUBFUNCTION = 132;
|
|
33
|
+
const CELL_SPANNING_SUBFUNCTION = 133;
|
|
34
|
+
const CELL_FILL_COLORS_SUBFUNCTION = 134;
|
|
35
|
+
function readEmbeddedSubfunctions(nonDeletable) {
|
|
36
|
+
if (nonDeletable.length < 2) return {
|
|
37
|
+
subfunctions: [],
|
|
38
|
+
truncated: false
|
|
39
|
+
};
|
|
40
|
+
let cursor = 2 + uint16At(nonDeletable, 0);
|
|
41
|
+
if (cursor > nonDeletable.length) return {
|
|
42
|
+
subfunctions: [],
|
|
43
|
+
truncated: true
|
|
44
|
+
};
|
|
45
|
+
const subfunctions = [];
|
|
46
|
+
while (cursor < nonDeletable.length) {
|
|
47
|
+
const code = nonDeletable[cursor];
|
|
48
|
+
if (code === void 0) break;
|
|
49
|
+
if (code === DONT_END_PARAGRAPH_STYLE_SUBFUNCTION) {
|
|
50
|
+
subfunctions.push({
|
|
51
|
+
code,
|
|
52
|
+
data: /* @__PURE__ */ new Uint8Array(0)
|
|
53
|
+
});
|
|
54
|
+
cursor += 1;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const size = code === CELL_FORMULA_SUBFUNCTION ? cursor + 3 <= nonDeletable.length ? uint16At(nonDeletable, cursor + 1) + CELL_FORMULA_FRAMING_SIZE : void 0 : EMBEDDED_SUBFUNCTION_SIZES.get(code);
|
|
58
|
+
if (size === void 0 || cursor + size > nonDeletable.length) return {
|
|
59
|
+
subfunctions,
|
|
60
|
+
truncated: true
|
|
61
|
+
};
|
|
62
|
+
if (nonDeletable[cursor + size - 1] !== code) return {
|
|
63
|
+
subfunctions,
|
|
64
|
+
truncated: true
|
|
65
|
+
};
|
|
66
|
+
subfunctions.push({
|
|
67
|
+
code,
|
|
68
|
+
data: nonDeletable.subarray(cursor + 1, cursor + size - 1)
|
|
69
|
+
});
|
|
70
|
+
cursor += size;
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
subfunctions,
|
|
74
|
+
truncated: false
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function findEmbeddedSubfunction(subfunctions, code) {
|
|
78
|
+
return subfunctions.find((subfunction) => subfunction.code === code)?.data;
|
|
79
|
+
}
|
|
80
|
+
const ROW_FLAG_FIXED_HEIGHT = 2;
|
|
81
|
+
const ROW_FLAG_HEADER_ROW = 4;
|
|
82
|
+
function readRowInformation(data) {
|
|
83
|
+
const flags = data[0];
|
|
84
|
+
if (flags === void 0 || data.length < 3) return;
|
|
85
|
+
const heightWpu = uint16At(data, 1);
|
|
86
|
+
const fixedHeight = (flags & ROW_FLAG_FIXED_HEIGHT) !== 0;
|
|
87
|
+
return {
|
|
88
|
+
headerRow: (flags & ROW_FLAG_HEADER_ROW) !== 0,
|
|
89
|
+
heightPt: fixedHeight && heightWpu > 0 ? pointsFromWpu(heightWpu) : void 0
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const CELL_JUSTIFICATION = [
|
|
93
|
+
"left",
|
|
94
|
+
"justify",
|
|
95
|
+
"center",
|
|
96
|
+
"right",
|
|
97
|
+
"justify",
|
|
98
|
+
"left"
|
|
99
|
+
];
|
|
100
|
+
const CELL_FLAG_USE_JUSTIFICATION = 2;
|
|
101
|
+
const CELL_JUSTIFICATION_MASK = 7;
|
|
102
|
+
function readCellInformation(data) {
|
|
103
|
+
const flag = data[0];
|
|
104
|
+
const justification = data[1];
|
|
105
|
+
if (flag === void 0 || justification === void 0) return;
|
|
106
|
+
if ((flag & CELL_FLAG_USE_JUSTIFICATION) === 0) return { alignment: void 0 };
|
|
107
|
+
return { alignment: CELL_JUSTIFICATION[justification & CELL_JUSTIFICATION_MASK] };
|
|
108
|
+
}
|
|
109
|
+
const SPAN_COVERED_FLAG = 128;
|
|
110
|
+
const SPAN_COUNT_MASK = 127;
|
|
111
|
+
function readCellSpanning(data) {
|
|
112
|
+
const horizontal = data[0];
|
|
113
|
+
const vertical = data[1];
|
|
114
|
+
if (horizontal === void 0 || vertical === void 0) return;
|
|
115
|
+
return {
|
|
116
|
+
columnSpan: horizontal & SPAN_COUNT_MASK,
|
|
117
|
+
rowSpan: vertical & SPAN_COUNT_MASK,
|
|
118
|
+
coveredFromLeft: (horizontal & SPAN_COVERED_FLAG) !== 0,
|
|
119
|
+
coveredFromAbove: (vertical & SPAN_COVERED_FLAG) !== 0
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
const COLOR_COMPONENT_MAX = 255;
|
|
123
|
+
const RGBS_SIZE = 4;
|
|
124
|
+
const FULL_SHADE = 255;
|
|
125
|
+
function colorAt(data, offset) {
|
|
126
|
+
const r = data[offset];
|
|
127
|
+
const g = data[offset + 1];
|
|
128
|
+
const b = data[offset + 2];
|
|
129
|
+
if (r === void 0 || g === void 0 || b === void 0) return;
|
|
130
|
+
return {
|
|
131
|
+
r: r / COLOR_COMPONENT_MAX,
|
|
132
|
+
g: g / COLOR_COMPONENT_MAX,
|
|
133
|
+
b: b / COLOR_COMPONENT_MAX
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function readCellFill(data) {
|
|
137
|
+
const background = colorAt(data, RGBS_SIZE);
|
|
138
|
+
if (background === void 0) return;
|
|
139
|
+
const backgroundShade = data[7];
|
|
140
|
+
return {
|
|
141
|
+
background,
|
|
142
|
+
blended: backgroundShade !== void 0 && backgroundShade !== FULL_SHADE
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
//#endregion
|
|
146
|
+
export { CELL_FILL_COLORS_SUBFUNCTION, CELL_INFORMATION_SUBFUNCTION, CELL_SPANNING_SUBFUNCTION, CHARACTER_DEFINE_TABLE_END, CHARACTER_TABLE_COLUMN, CHARACTER_TABLE_DEFINITION, ROW_INFORMATION_SUBFUNCTION, findEmbeddedSubfunction, readCellFill, readCellInformation, readCellSpanning, readEmbeddedSubfunctions, readRowInformation, readTableColumnWidthPt };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/stream/units.ts
|
|
3
|
+
const WPU_PER_INCH = 1200;
|
|
4
|
+
const POINTS_PER_INCH = 72;
|
|
5
|
+
function pointsFromWpu(wpu) {
|
|
6
|
+
return wpu * 72 / WPU_PER_INCH;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
exports.POINTS_PER_INCH = POINTS_PER_INCH;
|
|
10
|
+
exports.WPU_PER_INCH = WPU_PER_INCH;
|
|
11
|
+
exports.pointsFromWpu = pointsFromWpu;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wpd-codec",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Hand-written read-only WordPerfect 6.x-X6 (.wpd) reader over document-schema.js's ContentDocument",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"packageManager": "pnpm@11.6.0",
|
|
80
80
|
"dependencies": {
|
|
81
81
|
"archive-codec": "^1.3.0",
|
|
82
|
-
"document-schema.js": "^5.
|
|
82
|
+
"document-schema.js": "^5.5.0",
|
|
83
83
|
"zod": "^4.4.3"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
//#region src/diagnostics.d.ts
|
|
2
|
-
interface WpdDiagnostic {
|
|
3
|
-
readonly code: string;
|
|
4
|
-
readonly message: string;
|
|
5
|
-
}
|
|
6
|
-
type WpdDiagnosticSink = (diagnostic: WpdDiagnostic) => void;
|
|
7
|
-
declare const WpdDiagnosticCodes: {
|
|
8
|
-
readonly UnmappedCharacter: "wpd/unmapped-character";
|
|
9
|
-
readonly MissingPrefixPacket: "wpd/missing-prefix-packet";
|
|
10
|
-
readonly TableFlattened: "wpd/table-flattened";
|
|
11
|
-
readonly ColumnBreakFlattened: "wpd/column-break-flattened";
|
|
12
|
-
};
|
|
13
|
-
declare const NOOP_WPD_DIAGNOSTIC_SINK: WpdDiagnosticSink;
|
|
14
|
-
//#endregion
|
|
15
|
-
export { WpdDiagnosticSink as i, WpdDiagnostic as n, WpdDiagnosticCodes as r, NOOP_WPD_DIAGNOSTIC_SINK as t };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
//#region src/diagnostics.d.ts
|
|
2
|
-
interface WpdDiagnostic {
|
|
3
|
-
readonly code: string;
|
|
4
|
-
readonly message: string;
|
|
5
|
-
}
|
|
6
|
-
type WpdDiagnosticSink = (diagnostic: WpdDiagnostic) => void;
|
|
7
|
-
declare const WpdDiagnosticCodes: {
|
|
8
|
-
readonly UnmappedCharacter: "wpd/unmapped-character";
|
|
9
|
-
readonly MissingPrefixPacket: "wpd/missing-prefix-packet";
|
|
10
|
-
readonly TableFlattened: "wpd/table-flattened";
|
|
11
|
-
readonly ColumnBreakFlattened: "wpd/column-break-flattened";
|
|
12
|
-
};
|
|
13
|
-
declare const NOOP_WPD_DIAGNOSTIC_SINK: WpdDiagnosticSink;
|
|
14
|
-
//#endregion
|
|
15
|
-
export { WpdDiagnosticSink as i, WpdDiagnostic as n, WpdDiagnosticCodes as r, NOOP_WPD_DIAGNOSTIC_SINK as t };
|