wpd-codec 3.1.1 → 3.2.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.
@@ -1,4 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_bytes_view = require("../bytes/view.cjs");
2
3
  //#region src/stream/style.ts
3
4
  const STYLE_GROUP = 221;
4
5
  const DISPLAY_NUMBER_GROUP = 218;
@@ -68,13 +69,31 @@ function isParagraphNumberDisplayOff(subfunction) {
68
69
  function readDisplayNumberLevel(nonDeletable) {
69
70
  return nonDeletable[0];
70
71
  }
72
+ const PACKET_TYPE_NORMAL_STYLE = 48;
73
+ const PID_COUNT_OFFSET = 0;
74
+ const TEXT_BLOCK_HEADER_SIZE = 18;
75
+ function readStyleBeginBlock(packet) {
76
+ if (packet.length < 2) return;
77
+ const afterPids = 2 + require_bytes_view.uint16At(packet, PID_COUNT_OFFSET) * 2;
78
+ if (afterPids + TEXT_BLOCK_HEADER_SIZE > packet.length) return;
79
+ const relativeOffset = require_bytes_view.uint32At(packet, afterPids + 2);
80
+ const paragraphTextSize = require_bytes_view.uint32At(packet, afterPids + 6);
81
+ const beginningStyleTextSize = require_bytes_view.uint32At(packet, afterPids + 10);
82
+ if (beginningStyleTextSize === 0) return;
83
+ const start = relativeOffset + paragraphTextSize;
84
+ const end = start + beginningStyleTextSize;
85
+ if (start < 0 || end > packet.length) return;
86
+ return packet.subarray(start, end);
87
+ }
71
88
  //#endregion
72
89
  exports.DISPLAY_NUMBER_GROUP = DISPLAY_NUMBER_GROUP;
90
+ exports.PACKET_TYPE_NORMAL_STYLE = PACKET_TYPE_NORMAL_STYLE;
73
91
  exports.STYLE_GROUP = STYLE_GROUP;
74
92
  exports.isParagraphNumberDisplayOff = isParagraphNumberDisplayOff;
75
93
  exports.isParagraphNumberDisplayOn = isParagraphNumberDisplayOn;
76
94
  exports.isStyleScopeCloser = isStyleScopeCloser;
77
95
  exports.isStyleScopeOpener = isStyleScopeOpener;
78
96
  exports.readDisplayNumberLevel = readDisplayNumberLevel;
97
+ exports.readStyleBeginBlock = readStyleBeginBlock;
79
98
  exports.readSystemStyleNumber = readSystemStyleNumber;
80
99
  exports.styleSemanticsFor = styleSemanticsFor;
@@ -12,5 +12,7 @@ declare function styleSemanticsFor(systemStyleNumber: number): WpdStyleSemantics
12
12
  declare function isParagraphNumberDisplayOn(subfunction: number): boolean;
13
13
  declare function isParagraphNumberDisplayOff(subfunction: number): boolean;
14
14
  declare function readDisplayNumberLevel(nonDeletable: Uint8Array): number | undefined;
15
+ declare const PACKET_TYPE_NORMAL_STYLE = 48;
16
+ declare function readStyleBeginBlock(packet: Uint8Array): Uint8Array | undefined;
15
17
  //#endregion
16
- export { DISPLAY_NUMBER_GROUP, STYLE_GROUP, WpdStyleSemantics, isParagraphNumberDisplayOff, isParagraphNumberDisplayOn, isStyleScopeCloser, isStyleScopeOpener, readDisplayNumberLevel, readSystemStyleNumber, styleSemanticsFor };
18
+ export { DISPLAY_NUMBER_GROUP, PACKET_TYPE_NORMAL_STYLE, STYLE_GROUP, WpdStyleSemantics, isParagraphNumberDisplayOff, isParagraphNumberDisplayOn, isStyleScopeCloser, isStyleScopeOpener, readDisplayNumberLevel, readStyleBeginBlock, readSystemStyleNumber, styleSemanticsFor };
@@ -12,5 +12,7 @@ declare function styleSemanticsFor(systemStyleNumber: number): WpdStyleSemantics
12
12
  declare function isParagraphNumberDisplayOn(subfunction: number): boolean;
13
13
  declare function isParagraphNumberDisplayOff(subfunction: number): boolean;
14
14
  declare function readDisplayNumberLevel(nonDeletable: Uint8Array): number | undefined;
15
+ declare const PACKET_TYPE_NORMAL_STYLE = 48;
16
+ declare function readStyleBeginBlock(packet: Uint8Array): Uint8Array | undefined;
15
17
  //#endregion
16
- export { DISPLAY_NUMBER_GROUP, STYLE_GROUP, WpdStyleSemantics, isParagraphNumberDisplayOff, isParagraphNumberDisplayOn, isStyleScopeCloser, isStyleScopeOpener, readDisplayNumberLevel, readSystemStyleNumber, styleSemanticsFor };
18
+ export { DISPLAY_NUMBER_GROUP, PACKET_TYPE_NORMAL_STYLE, STYLE_GROUP, WpdStyleSemantics, isParagraphNumberDisplayOff, isParagraphNumberDisplayOn, isStyleScopeCloser, isStyleScopeOpener, readDisplayNumberLevel, readStyleBeginBlock, readSystemStyleNumber, styleSemanticsFor };
@@ -1,3 +1,4 @@
1
+ import { uint16At, uint32At } from "../bytes/view.js";
1
2
  //#region src/stream/style.ts
2
3
  const STYLE_GROUP = 221;
3
4
  const DISPLAY_NUMBER_GROUP = 218;
@@ -67,5 +68,21 @@ function isParagraphNumberDisplayOff(subfunction) {
67
68
  function readDisplayNumberLevel(nonDeletable) {
68
69
  return nonDeletable[0];
69
70
  }
71
+ const PACKET_TYPE_NORMAL_STYLE = 48;
72
+ const PID_COUNT_OFFSET = 0;
73
+ const TEXT_BLOCK_HEADER_SIZE = 18;
74
+ function readStyleBeginBlock(packet) {
75
+ if (packet.length < 2) return;
76
+ const afterPids = 2 + uint16At(packet, PID_COUNT_OFFSET) * 2;
77
+ if (afterPids + TEXT_BLOCK_HEADER_SIZE > packet.length) return;
78
+ const relativeOffset = uint32At(packet, afterPids + 2);
79
+ const paragraphTextSize = uint32At(packet, afterPids + 6);
80
+ const beginningStyleTextSize = uint32At(packet, afterPids + 10);
81
+ if (beginningStyleTextSize === 0) return;
82
+ const start = relativeOffset + paragraphTextSize;
83
+ const end = start + beginningStyleTextSize;
84
+ if (start < 0 || end > packet.length) return;
85
+ return packet.subarray(start, end);
86
+ }
70
87
  //#endregion
71
- export { DISPLAY_NUMBER_GROUP, STYLE_GROUP, isParagraphNumberDisplayOff, isParagraphNumberDisplayOn, isStyleScopeCloser, isStyleScopeOpener, readDisplayNumberLevel, readSystemStyleNumber, styleSemanticsFor };
88
+ export { DISPLAY_NUMBER_GROUP, PACKET_TYPE_NORMAL_STYLE, STYLE_GROUP, isParagraphNumberDisplayOff, isParagraphNumberDisplayOn, isStyleScopeCloser, isStyleScopeOpener, readDisplayNumberLevel, readStyleBeginBlock, readSystemStyleNumber, styleSemanticsFor };
@@ -56,7 +56,7 @@ function readEmbeddedSubfunctions(nonDeletable) {
56
56
  cursor += 1;
57
57
  continue;
58
58
  }
59
- 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
+ const size = code === 129 ? cursor + 3 <= nonDeletable.length ? require_bytes_view.uint16At(nonDeletable, cursor + 1) + CELL_FORMULA_FRAMING_SIZE : void 0 : EMBEDDED_SUBFUNCTION_SIZES.get(code);
60
60
  if (size === void 0 || cursor + size > nonDeletable.length) return {
61
61
  subfunctions,
62
62
  truncated: true
@@ -188,6 +188,7 @@ function readCellFill(data) {
188
188
  }
189
189
  //#endregion
190
190
  exports.CELL_FILL_COLORS_SUBFUNCTION = CELL_FILL_COLORS_SUBFUNCTION;
191
+ exports.CELL_FORMULA_SUBFUNCTION = CELL_FORMULA_SUBFUNCTION;
191
192
  exports.CELL_INFORMATION_SUBFUNCTION = CELL_INFORMATION_SUBFUNCTION;
192
193
  exports.CELL_SPANNING_SUBFUNCTION = CELL_SPANNING_SUBFUNCTION;
193
194
  exports.CHARACTER_DEFINE_TABLE_END = CHARACTER_DEFINE_TABLE_END;
@@ -4,6 +4,7 @@ declare const CHARACTER_TABLE_DEFINITION = 42;
4
4
  declare const CHARACTER_DEFINE_TABLE_END = 43;
5
5
  declare const CHARACTER_TABLE_COLUMN = 44;
6
6
  declare function readTableColumnWidthPt(nonDeletable: Uint8Array): number | undefined;
7
+ declare const CELL_FORMULA_SUBFUNCTION = 129;
7
8
  declare const ROW_INFORMATION_SUBFUNCTION = 128;
8
9
  declare const CELL_INFORMATION_SUBFUNCTION = 132;
9
10
  declare const CELL_SPANNING_SUBFUNCTION = 133;
@@ -40,4 +41,4 @@ interface WpdCellFill {
40
41
  }
41
42
  declare function readCellFill(data: Uint8Array): WpdCellFill | undefined;
42
43
  //#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 };
44
+ export { CELL_FILL_COLORS_SUBFUNCTION, CELL_FORMULA_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 };
@@ -4,6 +4,7 @@ declare const CHARACTER_TABLE_DEFINITION = 42;
4
4
  declare const CHARACTER_DEFINE_TABLE_END = 43;
5
5
  declare const CHARACTER_TABLE_COLUMN = 44;
6
6
  declare function readTableColumnWidthPt(nonDeletable: Uint8Array): number | undefined;
7
+ declare const CELL_FORMULA_SUBFUNCTION = 129;
7
8
  declare const ROW_INFORMATION_SUBFUNCTION = 128;
8
9
  declare const CELL_INFORMATION_SUBFUNCTION = 132;
9
10
  declare const CELL_SPANNING_SUBFUNCTION = 133;
@@ -40,4 +41,4 @@ interface WpdCellFill {
40
41
  }
41
42
  declare function readCellFill(data: Uint8Array): WpdCellFill | undefined;
42
43
  //#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 };
44
+ export { CELL_FILL_COLORS_SUBFUNCTION, CELL_FORMULA_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 };
@@ -55,7 +55,7 @@ function readEmbeddedSubfunctions(nonDeletable) {
55
55
  cursor += 1;
56
56
  continue;
57
57
  }
58
- 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
+ const size = code === 129 ? cursor + 3 <= nonDeletable.length ? uint16At(nonDeletable, cursor + 1) + CELL_FORMULA_FRAMING_SIZE : void 0 : EMBEDDED_SUBFUNCTION_SIZES.get(code);
59
59
  if (size === void 0 || cursor + size > nonDeletable.length) return {
60
60
  subfunctions,
61
61
  truncated: true
@@ -186,4 +186,4 @@ function readCellFill(data) {
186
186
  };
187
187
  }
188
188
  //#endregion
189
- 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 };
189
+ export { CELL_FILL_COLORS_SUBFUNCTION, CELL_FORMULA_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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wpd-codec",
3
- "version": "3.1.1",
3
+ "version": "3.2.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": {
@@ -80,8 +80,8 @@
80
80
  "license": "MIT",
81
81
  "packageManager": "pnpm@11.6.0",
82
82
  "dependencies": {
83
- "archive-codec": "1.9.1",
84
- "document-schema.js": "7.4.0",
83
+ "archive-codec": "1.9.2",
84
+ "document-schema.js": "7.5.0",
85
85
  "zod": "4.4.3"
86
86
  },
87
87
  "devDependencies": {