documents.js 1.61.0 → 1.63.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.
Files changed (236) hide show
  1. package/README.md +120 -47
  2. package/dist/{blr-types-CYYC3yYU.d.cts → blr-types-DVgO1DQ9.d.cts} +1 -1
  3. package/dist/{blr-types-CYYC3yYU.d.ts → blr-types-DVgO1DQ9.d.ts} +1 -1
  4. package/dist/convert/capability.cjs +1 -0
  5. package/dist/convert/capability.d.cts +1 -1
  6. package/dist/convert/capability.d.ts +1 -1
  7. package/dist/convert/capability.js +1 -0
  8. package/dist/convert/convert.cjs +92 -38
  9. package/dist/convert/convert.d.cts +11 -4
  10. package/dist/convert/convert.d.ts +11 -4
  11. package/dist/convert/convert.js +93 -39
  12. package/dist/convert/local.cjs +15 -2
  13. package/dist/convert/local.js +15 -2
  14. package/dist/convert/port.d.cts +8 -4
  15. package/dist/convert/port.d.ts +8 -4
  16. package/dist/edit/docx/content.cjs +75 -13
  17. package/dist/edit/docx/content.d.cts +8 -2
  18. package/dist/edit/docx/content.d.ts +8 -2
  19. package/dist/edit/docx/content.js +75 -13
  20. package/dist/edit/docx/paragraph.cjs +14 -0
  21. package/dist/edit/docx/paragraph.d.cts +5 -0
  22. package/dist/edit/docx/paragraph.d.ts +5 -0
  23. package/dist/edit/docx/paragraph.js +14 -0
  24. package/dist/edit/docx/run.cjs +1 -1
  25. package/dist/edit/docx/run.js +1 -1
  26. package/dist/edit/docx/table.cjs +41 -0
  27. package/dist/edit/docx/table.d.cts +7 -1
  28. package/dist/edit/docx/table.d.ts +7 -1
  29. package/dist/edit/docx/table.js +42 -1
  30. package/dist/edit/geometry.cjs +38 -0
  31. package/dist/edit/geometry.d.cts +7 -0
  32. package/dist/edit/geometry.d.ts +7 -0
  33. package/dist/edit/geometry.js +36 -0
  34. package/dist/edit/odg/content.cjs +15 -12
  35. package/dist/edit/odg/content.js +15 -12
  36. package/dist/edit/odg/editor.d.cts +1 -1
  37. package/dist/edit/odg/editor.d.ts +1 -1
  38. package/dist/edit/odg/page.d.cts +3 -3
  39. package/dist/edit/odg/page.d.ts +3 -3
  40. package/dist/edit/odg/vector.cjs +22 -13
  41. package/dist/edit/odg/vector.d.cts +1 -1
  42. package/dist/edit/odg/vector.d.ts +1 -1
  43. package/dist/edit/odg/vector.js +23 -14
  44. package/dist/edit/odp/content.cjs +15 -0
  45. package/dist/edit/odp/content.js +16 -1
  46. package/dist/edit/odp/editor.d.cts +1 -1
  47. package/dist/edit/odp/editor.d.ts +1 -1
  48. package/dist/edit/odp/image.d.cts +1 -1
  49. package/dist/edit/odp/image.d.ts +1 -1
  50. package/dist/edit/odp/shape.cjs +11 -30
  51. package/dist/edit/odp/shape.d.cts +2 -2
  52. package/dist/edit/odp/shape.d.ts +2 -2
  53. package/dist/edit/odp/shape.js +13 -33
  54. package/dist/edit/odp/slide.cjs +11 -0
  55. package/dist/edit/odp/slide.d.cts +14 -4
  56. package/dist/edit/odp/slide.d.ts +14 -4
  57. package/dist/edit/odp/slide.js +12 -1
  58. package/dist/edit/odt/content.cjs +56 -16
  59. package/dist/edit/odt/content.d.cts +4 -2
  60. package/dist/edit/odt/content.d.ts +4 -2
  61. package/dist/edit/odt/content.js +56 -17
  62. package/dist/edit/odt/editor.d.cts +1 -1
  63. package/dist/edit/odt/editor.d.ts +1 -1
  64. package/dist/edit/odt/table.cjs +36 -0
  65. package/dist/edit/odt/table.d.cts +1 -36
  66. package/dist/edit/odt/table.d.ts +1 -36
  67. package/dist/edit/odt/table.js +37 -1
  68. package/dist/edit/pptx/content.cjs +71 -3
  69. package/dist/edit/pptx/content.js +71 -3
  70. package/dist/edit/pptx/editor.d.cts +1 -1
  71. package/dist/edit/pptx/editor.d.ts +1 -1
  72. package/dist/edit/pptx/image.d.cts +1 -1
  73. package/dist/edit/pptx/image.d.ts +1 -1
  74. package/dist/edit/pptx/shape.cjs +23 -1
  75. package/dist/edit/pptx/shape.d.cts +2 -2
  76. package/dist/edit/pptx/shape.d.ts +2 -2
  77. package/dist/edit/pptx/shape.js +23 -3
  78. package/dist/edit/pptx/slide.cjs +10 -1
  79. package/dist/edit/pptx/slide.d.cts +11 -4
  80. package/dist/edit/pptx/slide.d.ts +11 -4
  81. package/dist/edit/pptx/slide.js +10 -1
  82. package/dist/edit/pptx/table.cjs +136 -0
  83. package/dist/edit/pptx/table.d.cts +2 -0
  84. package/dist/edit/pptx/table.d.ts +2 -0
  85. package/dist/edit/pptx/table.js +131 -0
  86. package/dist/firebird/backup.d.cts +1 -1
  87. package/dist/firebird/backup.d.ts +1 -1
  88. package/dist/firebird/blr-types.cjs +2 -2
  89. package/dist/firebird/blr-types.d.cts +1 -1
  90. package/dist/firebird/blr-types.d.ts +1 -1
  91. package/dist/firebird/blr-types.js +2 -2
  92. package/dist/firebird/data.cjs +68 -14
  93. package/dist/firebird/data.d.cts +1 -1
  94. package/dist/firebird/data.d.ts +1 -1
  95. package/dist/firebird/data.js +68 -14
  96. package/dist/firebird/schema.cjs +13 -1
  97. package/dist/firebird/schema.d.cts +1 -1
  98. package/dist/firebird/schema.d.ts +1 -1
  99. package/dist/firebird/schema.js +13 -1
  100. package/dist/fonts/obfuscation.cjs +50 -0
  101. package/dist/fonts/obfuscation.d.cts +9 -0
  102. package/dist/fonts/obfuscation.d.ts +9 -0
  103. package/dist/fonts/obfuscation.js +46 -0
  104. package/dist/fonts/odf.cjs +86 -0
  105. package/dist/fonts/odf.d.cts +9 -0
  106. package/dist/fonts/odf.d.ts +9 -0
  107. package/dist/fonts/odf.js +84 -0
  108. package/dist/fonts/ooxml.cjs +129 -0
  109. package/dist/fonts/ooxml.d.cts +9 -0
  110. package/dist/fonts/ooxml.d.ts +9 -0
  111. package/dist/fonts/ooxml.js +127 -0
  112. package/dist/fonts/registry.cjs +18 -0
  113. package/dist/fonts/registry.d.cts +2 -0
  114. package/dist/fonts/registry.d.ts +2 -0
  115. package/dist/fonts/registry.js +16 -0
  116. package/dist/{geometry-DvwdrIij.d.cts → geometry-DaJr8yQW.d.cts} +2 -2
  117. package/dist/{geometry-DvwdrIij.d.ts → geometry-DaJr8yQW.d.ts} +2 -2
  118. package/dist/hsqldb/binary-script.cjs +154 -0
  119. package/dist/hsqldb/binary-script.d.cts +15 -0
  120. package/dist/hsqldb/binary-script.d.ts +15 -0
  121. package/dist/hsqldb/binary-script.js +151 -0
  122. package/dist/hsqldb/cache.cjs +18 -11
  123. package/dist/hsqldb/cache.d.cts +9 -4
  124. package/dist/hsqldb/cache.d.ts +9 -4
  125. package/dist/hsqldb/cache.js +18 -11
  126. package/dist/hsqldb/rowformat.cjs +60 -16
  127. package/dist/hsqldb/rowformat.d.cts +2 -21
  128. package/dist/hsqldb/rowformat.d.ts +2 -21
  129. package/dist/hsqldb/rowformat.js +60 -17
  130. package/dist/{image-BZDy72Jb.d.cts → image-7snmKIxn.d.cts} +1 -1
  131. package/dist/{image-B-xQWYYS.d.ts → image-Cs8xF753.d.ts} +1 -1
  132. package/dist/{image-CeqwL-Qs.d.ts → image-DHcA9kaK.d.ts} +1 -1
  133. package/dist/{image-DWX6cNOD.d.cts → image-M5SezZVI.d.cts} +1 -1
  134. package/dist/index.cjs +86 -3
  135. package/dist/index.d.cts +33 -21
  136. package/dist/index.d.ts +33 -21
  137. package/dist/index.js +18 -5
  138. package/dist/layout/cell-typing.cjs +209 -0
  139. package/dist/layout/cell-typing.d.cts +22 -0
  140. package/dist/layout/cell-typing.d.ts +22 -0
  141. package/dist/layout/cell-typing.js +208 -0
  142. package/dist/layout/drawing.cjs +193 -17
  143. package/dist/layout/drawing.js +193 -17
  144. package/dist/layout/engine.cjs +46 -29
  145. package/dist/layout/engine.d.cts +0 -2
  146. package/dist/layout/engine.d.ts +0 -2
  147. package/dist/layout/engine.js +47 -30
  148. package/dist/layout/lattice.cjs +139 -0
  149. package/dist/layout/lattice.d.cts +20 -0
  150. package/dist/layout/lattice.d.ts +20 -0
  151. package/dist/layout/lattice.js +135 -0
  152. package/dist/layout/reconstruct.cjs +176 -113
  153. package/dist/layout/reconstruct.d.cts +2 -0
  154. package/dist/layout/reconstruct.d.ts +2 -0
  155. package/dist/layout/reconstruct.js +173 -110
  156. package/dist/layout/shared.cjs +52 -0
  157. package/dist/layout/shared.d.cts +4 -2
  158. package/dist/layout/shared.d.ts +4 -2
  159. package/dist/layout/shared.js +51 -1
  160. package/dist/layout/sheets.cjs +45 -11
  161. package/dist/layout/sheets.js +46 -12
  162. package/dist/layout/slides.cjs +7 -7
  163. package/dist/layout/slides.d.cts +0 -3
  164. package/dist/layout/slides.d.ts +0 -3
  165. package/dist/layout/slides.js +7 -7
  166. package/dist/markdown/write.cjs +19 -6
  167. package/dist/markdown/write.js +19 -6
  168. package/dist/mathml/layout.cjs +2 -2
  169. package/dist/mathml/layout.d.cts +1 -1
  170. package/dist/mathml/layout.d.ts +1 -1
  171. package/dist/mathml/layout.js +2 -2
  172. package/dist/model/embedded-drawing.cjs +32 -0
  173. package/dist/model/embedded-drawing.d.cts +8 -0
  174. package/dist/model/embedded-drawing.d.ts +8 -0
  175. package/dist/model/embedded-drawing.js +30 -0
  176. package/dist/model/formula.cjs +31 -0
  177. package/dist/model/formula.d.cts +6 -6
  178. package/dist/model/formula.d.ts +6 -6
  179. package/dist/model/formula.js +27 -0
  180. package/dist/model/geometry.d.cts +1 -1
  181. package/dist/model/geometry.d.ts +1 -1
  182. package/dist/model/paint-order.cjs +15 -0
  183. package/dist/model/paint-order.d.cts +14 -0
  184. package/dist/model/paint-order.d.ts +14 -0
  185. package/dist/model/paint-order.js +14 -0
  186. package/dist/odb/components.cjs +12 -0
  187. package/dist/odb/components.d.cts +6 -0
  188. package/dist/odb/components.d.ts +6 -0
  189. package/dist/odb/components.js +10 -0
  190. package/dist/odb/read.cjs +11 -7
  191. package/dist/odb/read.d.cts +3 -2
  192. package/dist/odb/read.d.ts +3 -2
  193. package/dist/odb/read.js +11 -7
  194. package/dist/odf/formula/detect.cjs +86 -18
  195. package/dist/odf/formula/detect.d.cts +10 -6
  196. package/dist/odf/formula/detect.d.ts +10 -6
  197. package/dist/odf/formula/detect.js +86 -19
  198. package/dist/odf/formula/read.cjs +4 -16
  199. package/dist/odf/formula/read.d.cts +4 -8
  200. package/dist/odf/formula/read.d.ts +4 -8
  201. package/dist/odf/formula/read.js +5 -17
  202. package/dist/odf/odp/read.cjs +9 -19
  203. package/dist/odf/odp/read.d.cts +2 -7
  204. package/dist/odf/odp/read.d.ts +2 -7
  205. package/dist/odf/odp/read.js +10 -20
  206. package/dist/odf/odt/read.cjs +63 -23
  207. package/dist/odf/odt/read.d.cts +2 -7
  208. package/dist/odf/odt/read.d.ts +2 -7
  209. package/dist/odf/odt/read.js +64 -24
  210. package/dist/omml/write.cjs +258 -0
  211. package/dist/omml/write.d.cts +2 -0
  212. package/dist/omml/write.d.ts +2 -0
  213. package/dist/omml/write.js +256 -0
  214. package/dist/registry-CrSqLIcn.d.ts +19 -0
  215. package/dist/registry-CtPhMD0f.d.cts +19 -0
  216. package/dist/rowformat-Cl2exlEh.d.cts +25 -0
  217. package/dist/rowformat-Cl2exlEh.d.ts +25 -0
  218. package/dist/{schema-Acco3Ezi.d.cts → schema-BeR_KJ0X.d.cts} +3 -1
  219. package/dist/{schema-VkAA6pF5.d.ts → schema-CSKwSb_v.d.ts} +3 -1
  220. package/dist/{shape-BUfjw5eZ.d.cts → shape-BhkP6HB8.d.cts} +6 -2
  221. package/dist/{shape-CTkl6kt8.d.ts → shape-BkVcwPcf.d.ts} +6 -2
  222. package/dist/{shape-BfN3m52m.d.ts → shape-CVXedeL7.d.ts} +3 -2
  223. package/dist/{shape-CN2ycxOo.d.cts → shape-CXZ6fejV.d.cts} +3 -2
  224. package/dist/table-C3CPZ--2.d.cts +35 -0
  225. package/dist/table-DjYcNOFm.d.cts +44 -0
  226. package/dist/table-DqfqMkVq.d.ts +44 -0
  227. package/dist/table-DvS_7UQS.d.ts +35 -0
  228. package/dist/{vector-ClohqsOe.d.cts → vector-Puuqu_IT.d.cts} +4 -0
  229. package/dist/{vector-ClohqsOe.d.ts → vector-Puuqu_IT.d.ts} +4 -0
  230. package/dist/write-DuyfnbL_.d.cts +16 -0
  231. package/dist/write-Zqwx6pka.d.ts +16 -0
  232. package/package.json +4 -4
  233. package/dist/odf/formula/placeholder.cjs +0 -36
  234. package/dist/odf/formula/placeholder.d.cts +0 -14
  235. package/dist/odf/formula/placeholder.d.ts +0 -14
  236. package/dist/odf/formula/placeholder.js +0 -36
@@ -25,23 +25,71 @@ var FirebirdCompositeRecordUnsupportedError = class extends Error {
25
25
  this.recordType = recordType;
26
26
  }
27
27
  };
28
- function skipBlobRecord(reader) {
29
- let segmentCount;
28
+ function readBlobRecord(reader) {
29
+ const ATT_BLOB_FIELD_NUMBER = 3;
30
+ const ATT_BLOB_NUMBER_SEGMENTS = 5;
31
+ const ATT_BLOB_DATA = 7;
32
+ let fieldNumber;
33
+ let segmentCount = 0;
30
34
  for (;;) {
31
35
  const attribute = reader.readTag();
32
- if (attribute === 0) break;
33
- if (attribute === 5) segmentCount = reader.readInt32Attribute();
34
- else if (attribute === 7) {
35
- const count = segmentCount ?? 0;
36
- for (let i = 0; i < count; i++) {
37
- const length = reader.readBlobSegmentLength();
38
- reader.readRawPayload(length);
39
- }
40
- } else reader.skipAttributeValue();
36
+ if (attribute === ATT_BLOB_DATA) break;
37
+ if (attribute === ATT_BLOB_FIELD_NUMBER) fieldNumber = reader.readInt32Attribute();
38
+ else if (attribute === ATT_BLOB_NUMBER_SEGMENTS) segmentCount = reader.readInt32Attribute();
39
+ else reader.skipAttributeValue();
40
+ }
41
+ if (fieldNumber === void 0) throw new FirebirdDataParseError("a rec_blob record had no att_blob_field_number attribute, so its content cannot be attributed to a column");
42
+ const segments = [];
43
+ let total = 0;
44
+ for (let i = 0; i < segmentCount; i++) {
45
+ const length = reader.readBlobSegmentLength();
46
+ const segment = reader.readRawPayload(length);
47
+ segments.push(segment);
48
+ total += segment.length;
49
+ }
50
+ const bytes = new Uint8Array(total);
51
+ let offset = 0;
52
+ for (const segment of segments) {
53
+ bytes.set(segment, offset);
54
+ offset += segment.length;
41
55
  }
56
+ return {
57
+ fieldNumber,
58
+ bytes
59
+ };
60
+ }
61
+ const BINARY_BLOB_DATA_URI_PREFIX = "data:application/octet-stream;base64,";
62
+ const BLOB_SUB_TYPE_TEXT = 1;
63
+ const BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
64
+ function bytesToBase64(bytes) {
65
+ let result = "";
66
+ for (let i = 0; i < bytes.length; i += 3) {
67
+ const b0 = bytes[i] ?? 0;
68
+ const b1 = bytes[i + 1];
69
+ const b2 = bytes[i + 2];
70
+ const triple = b0 << 16 | (b1 ?? 0) << 8 | (b2 ?? 0);
71
+ result += BASE64_ALPHABET[triple >> 18 & 63] ?? "";
72
+ result += BASE64_ALPHABET[triple >> 12 & 63] ?? "";
73
+ result += b1 === void 0 ? "=" : BASE64_ALPHABET[triple >> 6 & 63] ?? "";
74
+ result += b2 === void 0 ? "=" : BASE64_ALPHABET[triple & 63] ?? "";
75
+ }
76
+ return result;
77
+ }
78
+ function blobCellValue(field, bytes) {
79
+ if (field.subType === BLOB_SUB_TYPE_TEXT) return {
80
+ kind: "string",
81
+ value: new TextDecoder("utf-8").decode(bytes)
82
+ };
83
+ return {
84
+ kind: "string",
85
+ value: `${BINARY_BLOB_DATA_URI_PREFIX}${bytesToBase64(bytes)}`
86
+ };
87
+ }
88
+ function storedFieldsOf(fields) {
89
+ return fields.filter((field) => !field.computed);
42
90
  }
43
91
  function decodeRowValues(fields, payload) {
44
- const storedFields = fields.filter((field) => !field.computed);
92
+ const storedFields = storedFieldsOf(fields);
45
93
  const xdr = new XdrReader(payload);
46
94
  const rawValues = [];
47
95
  for (const field of storedFields) switch (field.physicalType) {
@@ -170,10 +218,16 @@ function readRowGroup(reader, relation, compressed) {
170
218
  if (dataTag !== ATT_DATA_DATA) throw new FirebirdDataParseError(`relation "${relation.name}": expected att_data_data (tag ${ATT_DATA_DATA}), found tag ${dataTag}`);
171
219
  }
172
220
  const payload = compressed ? reader.readCompressedPayload(xdrLength) : reader.readRawPayload(xdrLength);
173
- rows.push(decodeRowValues(relation.fields, payload));
221
+ const values = decodeRowValues(relation.fields, payload);
222
+ rows.push(values);
174
223
  let next = reader.readTag();
175
224
  while (next === REC_BLOB) {
176
- skipBlobRecord(reader);
225
+ const blob = readBlobRecord(reader);
226
+ const storedFields = storedFieldsOf(relation.fields);
227
+ const columnIndex = storedFields.findIndex((field) => field.fieldNumber === blob.fieldNumber);
228
+ const field = storedFields[columnIndex];
229
+ if (field === void 0) throw new FirebirdDataParseError(`relation "${relation.name}": a rec_blob record names att_blob_field_number ${blob.fieldNumber}, which matches no field's own att_field_number in this relation`);
230
+ values[columnIndex] = blobCellValue(field, blob.bytes);
177
231
  next = reader.readTag();
178
232
  }
179
233
  if (next !== REC_DATA) {
@@ -12,8 +12,10 @@ var FirebirdSchemaParseError = class extends Error {
12
12
  const ATT_RELATION_NAME = 1;
13
13
  const ATT_FIELD_NAME = 1;
14
14
  const ATT_FIELD_TYPE = 8;
15
+ const ATT_FIELD_SUB_TYPE = 9;
15
16
  const ATT_FIELD_LENGTH = 10;
16
17
  const ATT_FIELD_SCALE = 11;
18
+ const ATT_FIELD_NUMBER = 22;
17
19
  const ATT_FIELD_COMPUTED_FLAG = 23;
18
20
  const ATT_FIELD_CHARACTER_LENGTH = 41;
19
21
  function readField(reader) {
@@ -22,6 +24,8 @@ function readField(reader) {
22
24
  let lengthBytes = 0;
23
25
  let scale = 0;
24
26
  let characterLength;
27
+ let subType = 0;
28
+ let fieldNumber;
25
29
  let computed = false;
26
30
  for (;;) {
27
31
  const attribute = reader.readTag();
@@ -33,9 +37,15 @@ function readField(reader) {
33
37
  case ATT_FIELD_TYPE:
34
38
  blrType = reader.readInt32Attribute();
35
39
  break;
40
+ case ATT_FIELD_SUB_TYPE:
41
+ subType = reader.readInt32Attribute();
42
+ break;
36
43
  case ATT_FIELD_LENGTH:
37
44
  lengthBytes = reader.readInt32Attribute();
38
45
  break;
46
+ case ATT_FIELD_NUMBER:
47
+ fieldNumber = reader.readInt32Attribute();
48
+ break;
39
49
  case ATT_FIELD_SCALE:
40
50
  scale = reader.readInt32Attribute();
41
51
  break;
@@ -51,13 +61,15 @@ function readField(reader) {
51
61
  if (name === void 0) throw new FirebirdSchemaParseError("a rec_field record had no att_field_name attribute");
52
62
  if (blrType === void 0) throw new FirebirdSchemaParseError(`field "${name}" had no att_field_type attribute`);
53
63
  const physicalType = require_firebird_blr_types.decodeBlrType(blrType);
54
- const typeLabel = require_firebird_blr_types.describeFieldType(physicalType, lengthBytes, scale, characterLength);
64
+ const typeLabel = require_firebird_blr_types.describeFieldType(physicalType, lengthBytes, scale, characterLength, subType);
55
65
  return {
56
66
  name,
57
67
  physicalType,
58
68
  lengthBytes,
59
69
  scale,
60
70
  characterLength,
71
+ subType,
72
+ fieldNumber,
61
73
  typeLabel,
62
74
  computed
63
75
  };
@@ -1,2 +1,2 @@
1
- import { i as readRelationSchema, n as FirebirdRelation, r as FirebirdSchemaParseError, t as FirebirdField } from "../schema-Acco3Ezi.cjs";
1
+ import { i as readRelationSchema, n as FirebirdRelation, r as FirebirdSchemaParseError, t as FirebirdField } from "../schema-BeR_KJ0X.cjs";
2
2
  export { FirebirdField, FirebirdRelation, FirebirdSchemaParseError, readRelationSchema };
@@ -1,2 +1,2 @@
1
- import { i as readRelationSchema, n as FirebirdRelation, r as FirebirdSchemaParseError, t as FirebirdField } from "../schema-VkAA6pF5.js";
1
+ import { i as readRelationSchema, n as FirebirdRelation, r as FirebirdSchemaParseError, t as FirebirdField } from "../schema-CSKwSb_v.js";
2
2
  export { FirebirdField, FirebirdRelation, FirebirdSchemaParseError, readRelationSchema };
@@ -11,8 +11,10 @@ var FirebirdSchemaParseError = class extends Error {
11
11
  const ATT_RELATION_NAME = 1;
12
12
  const ATT_FIELD_NAME = 1;
13
13
  const ATT_FIELD_TYPE = 8;
14
+ const ATT_FIELD_SUB_TYPE = 9;
14
15
  const ATT_FIELD_LENGTH = 10;
15
16
  const ATT_FIELD_SCALE = 11;
17
+ const ATT_FIELD_NUMBER = 22;
16
18
  const ATT_FIELD_COMPUTED_FLAG = 23;
17
19
  const ATT_FIELD_CHARACTER_LENGTH = 41;
18
20
  function readField(reader) {
@@ -21,6 +23,8 @@ function readField(reader) {
21
23
  let lengthBytes = 0;
22
24
  let scale = 0;
23
25
  let characterLength;
26
+ let subType = 0;
27
+ let fieldNumber;
24
28
  let computed = false;
25
29
  for (;;) {
26
30
  const attribute = reader.readTag();
@@ -32,9 +36,15 @@ function readField(reader) {
32
36
  case ATT_FIELD_TYPE:
33
37
  blrType = reader.readInt32Attribute();
34
38
  break;
39
+ case ATT_FIELD_SUB_TYPE:
40
+ subType = reader.readInt32Attribute();
41
+ break;
35
42
  case ATT_FIELD_LENGTH:
36
43
  lengthBytes = reader.readInt32Attribute();
37
44
  break;
45
+ case ATT_FIELD_NUMBER:
46
+ fieldNumber = reader.readInt32Attribute();
47
+ break;
38
48
  case ATT_FIELD_SCALE:
39
49
  scale = reader.readInt32Attribute();
40
50
  break;
@@ -50,13 +60,15 @@ function readField(reader) {
50
60
  if (name === void 0) throw new FirebirdSchemaParseError("a rec_field record had no att_field_name attribute");
51
61
  if (blrType === void 0) throw new FirebirdSchemaParseError(`field "${name}" had no att_field_type attribute`);
52
62
  const physicalType = decodeBlrType(blrType);
53
- const typeLabel = describeFieldType(physicalType, lengthBytes, scale, characterLength);
63
+ const typeLabel = describeFieldType(physicalType, lengthBytes, scale, characterLength, subType);
54
64
  return {
55
65
  name,
56
66
  physicalType,
57
67
  lengthBytes,
58
68
  scale,
59
69
  characterLength,
70
+ subType,
71
+ fieldNumber,
60
72
  typeLabel,
61
73
  computed
62
74
  };
@@ -0,0 +1,50 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let pdf_codec_sfnt = require("pdf-codec/sfnt");
3
+ //#region src/fonts/obfuscation.ts
4
+ const FONT_KEY_HEX_LENGTH = 32;
5
+ const FONT_KEY_BYTE_LENGTH = 16;
6
+ const OBFUSCATED_PREFIX_LENGTH = 32;
7
+ const SFNT_HEADER_LENGTH = 12;
8
+ const HEX_PAIR_PATTERN = /^[0-9A-Fa-f]{2}$/;
9
+ var FontDeobfuscationError = class extends Error {
10
+ constructor(detail) {
11
+ super(`deobfuscateEmbeddedFont: ${detail}`);
12
+ this.name = "FontDeobfuscationError";
13
+ }
14
+ };
15
+ function deriveFontKey(fontKey) {
16
+ const hex = fontKey.replace(/[{}-]/g, "");
17
+ if (hex.length !== FONT_KEY_HEX_LENGTH) throw new FontDeobfuscationError(`w:fontKey ${JSON.stringify(fontKey)} has ${String(hex.length)} hex digit(s) after stripping braces and hyphens, expected ${String(FONT_KEY_HEX_LENGTH)}`);
18
+ const key = new Uint8Array(FONT_KEY_BYTE_LENGTH);
19
+ for (let i = 0; i < FONT_KEY_BYTE_LENGTH; i++) {
20
+ const start = 30 - i * 2;
21
+ const pair = hex.slice(start, start + 2);
22
+ if (!HEX_PAIR_PATTERN.test(pair)) throw new FontDeobfuscationError(`w:fontKey ${JSON.stringify(fontKey)} contains the non-hexadecimal pair ${JSON.stringify(pair)}`);
23
+ key[i] = Number.parseInt(pair, 16);
24
+ }
25
+ return key;
26
+ }
27
+ function looksLikeSfnt(bytes) {
28
+ return bytes.length >= SFNT_HEADER_LENGTH && (0, pdf_codec_sfnt.parseSfnt)(bytes) !== void 0;
29
+ }
30
+ function deobfuscateEmbeddedFont(bytes, fontKey) {
31
+ if (looksLikeSfnt(bytes)) return bytes;
32
+ if (fontKey === void 0) throw new FontDeobfuscationError("the part does not begin with an sfnt signature and carries no font key to deobfuscate it with");
33
+ if (bytes.length < OBFUSCATED_PREFIX_LENGTH) throw new FontDeobfuscationError(`an obfuscated part must be at least ${String(OBFUSCATED_PREFIX_LENGTH)} bytes long, got ${String(bytes.length)}`);
34
+ const key = deriveFontKey(fontKey);
35
+ const clear = new Uint8Array(bytes.length);
36
+ clear.set(bytes);
37
+ for (let i = 0; i < OBFUSCATED_PREFIX_LENGTH; i++) {
38
+ const keyByte = key[i % FONT_KEY_BYTE_LENGTH];
39
+ const cipherByte = clear[i];
40
+ if (keyByte === void 0 || cipherByte === void 0) throw new FontDeobfuscationError(`byte ${String(i)} of the obfuscated prefix is out of range`);
41
+ clear[i] = cipherByte ^ keyByte;
42
+ }
43
+ if (!looksLikeSfnt(clear)) throw new FontDeobfuscationError(`deobfuscating with font key ${JSON.stringify(fontKey)} did not produce a recognisable sfnt font`);
44
+ return clear;
45
+ }
46
+ //#endregion
47
+ exports.FontDeobfuscationError = FontDeobfuscationError;
48
+ exports.deobfuscateEmbeddedFont = deobfuscateEmbeddedFont;
49
+ exports.deriveFontKey = deriveFontKey;
50
+ exports.looksLikeSfnt = looksLikeSfnt;
@@ -0,0 +1,9 @@
1
+ //#region src/fonts/obfuscation.d.ts
2
+ declare class FontDeobfuscationError extends Error {
3
+ constructor(detail: string);
4
+ }
5
+ declare function deriveFontKey(fontKey: string): Uint8Array<ArrayBuffer>;
6
+ declare function looksLikeSfnt(bytes: Uint8Array<ArrayBuffer>): boolean;
7
+ declare function deobfuscateEmbeddedFont(bytes: Uint8Array<ArrayBuffer>, fontKey: string | undefined): Uint8Array<ArrayBuffer>;
8
+ //#endregion
9
+ export { FontDeobfuscationError, deobfuscateEmbeddedFont, deriveFontKey, looksLikeSfnt };
@@ -0,0 +1,9 @@
1
+ //#region src/fonts/obfuscation.d.ts
2
+ declare class FontDeobfuscationError extends Error {
3
+ constructor(detail: string);
4
+ }
5
+ declare function deriveFontKey(fontKey: string): Uint8Array<ArrayBuffer>;
6
+ declare function looksLikeSfnt(bytes: Uint8Array<ArrayBuffer>): boolean;
7
+ declare function deobfuscateEmbeddedFont(bytes: Uint8Array<ArrayBuffer>, fontKey: string | undefined): Uint8Array<ArrayBuffer>;
8
+ //#endregion
9
+ export { FontDeobfuscationError, deobfuscateEmbeddedFont, deriveFontKey, looksLikeSfnt };
@@ -0,0 +1,46 @@
1
+ import { parseSfnt } from "pdf-codec/sfnt";
2
+ //#region src/fonts/obfuscation.ts
3
+ const FONT_KEY_HEX_LENGTH = 32;
4
+ const FONT_KEY_BYTE_LENGTH = 16;
5
+ const OBFUSCATED_PREFIX_LENGTH = 32;
6
+ const SFNT_HEADER_LENGTH = 12;
7
+ const HEX_PAIR_PATTERN = /^[0-9A-Fa-f]{2}$/;
8
+ var FontDeobfuscationError = class extends Error {
9
+ constructor(detail) {
10
+ super(`deobfuscateEmbeddedFont: ${detail}`);
11
+ this.name = "FontDeobfuscationError";
12
+ }
13
+ };
14
+ function deriveFontKey(fontKey) {
15
+ const hex = fontKey.replace(/[{}-]/g, "");
16
+ if (hex.length !== FONT_KEY_HEX_LENGTH) throw new FontDeobfuscationError(`w:fontKey ${JSON.stringify(fontKey)} has ${String(hex.length)} hex digit(s) after stripping braces and hyphens, expected ${String(FONT_KEY_HEX_LENGTH)}`);
17
+ const key = new Uint8Array(FONT_KEY_BYTE_LENGTH);
18
+ for (let i = 0; i < FONT_KEY_BYTE_LENGTH; i++) {
19
+ const start = 30 - i * 2;
20
+ const pair = hex.slice(start, start + 2);
21
+ if (!HEX_PAIR_PATTERN.test(pair)) throw new FontDeobfuscationError(`w:fontKey ${JSON.stringify(fontKey)} contains the non-hexadecimal pair ${JSON.stringify(pair)}`);
22
+ key[i] = Number.parseInt(pair, 16);
23
+ }
24
+ return key;
25
+ }
26
+ function looksLikeSfnt(bytes) {
27
+ return bytes.length >= SFNT_HEADER_LENGTH && parseSfnt(bytes) !== void 0;
28
+ }
29
+ function deobfuscateEmbeddedFont(bytes, fontKey) {
30
+ if (looksLikeSfnt(bytes)) return bytes;
31
+ if (fontKey === void 0) throw new FontDeobfuscationError("the part does not begin with an sfnt signature and carries no font key to deobfuscate it with");
32
+ if (bytes.length < OBFUSCATED_PREFIX_LENGTH) throw new FontDeobfuscationError(`an obfuscated part must be at least ${String(OBFUSCATED_PREFIX_LENGTH)} bytes long, got ${String(bytes.length)}`);
33
+ const key = deriveFontKey(fontKey);
34
+ const clear = new Uint8Array(bytes.length);
35
+ clear.set(bytes);
36
+ for (let i = 0; i < OBFUSCATED_PREFIX_LENGTH; i++) {
37
+ const keyByte = key[i % FONT_KEY_BYTE_LENGTH];
38
+ const cipherByte = clear[i];
39
+ if (keyByte === void 0 || cipherByte === void 0) throw new FontDeobfuscationError(`byte ${String(i)} of the obfuscated prefix is out of range`);
40
+ clear[i] = cipherByte ^ keyByte;
41
+ }
42
+ if (!looksLikeSfnt(clear)) throw new FontDeobfuscationError(`deobfuscating with font key ${JSON.stringify(fontKey)} did not produce a recognisable sfnt font`);
43
+ return clear;
44
+ }
45
+ //#endregion
46
+ export { FontDeobfuscationError, deobfuscateEmbeddedFont, deriveFontKey, looksLikeSfnt };
@@ -0,0 +1,86 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_fonts_obfuscation = require("./obfuscation.cjs");
3
+ let odf_js = require("odf.js");
4
+ let pdf_codec_sfnt = require("pdf-codec/sfnt");
5
+ let pdf_codec_font_tables = require("pdf-codec/font-tables");
6
+ //#region src/fonts/odf.ts
7
+ const FONT_FACE_DECL_PARTS = ["content.xml", "styles.xml"];
8
+ const FS_SELECTION_ITALIC = 1;
9
+ const FS_SELECTION_BOLD = 32;
10
+ const BOLD_WEIGHT_THRESHOLD = 600;
11
+ var OdfEmbeddedFontError = class extends Error {
12
+ constructor(detail) {
13
+ super(`extractOdfEmbeddedFonts: ${detail}`);
14
+ this.name = "OdfEmbeddedFontError";
15
+ }
16
+ };
17
+ function normaliseFamily(value) {
18
+ const first = (0, odf_js.decodeXmlText)(value).split(",")[0]?.trim() ?? "";
19
+ const quoted = /^'(.*)'$|^"(.*)"$/.exec(first);
20
+ return (quoted?.[1] ?? quoted?.[2] ?? first).trim();
21
+ }
22
+ function boldFromWeightAttribute(weight) {
23
+ const keyword = weight.trim().toLowerCase();
24
+ if (keyword === "bold" || keyword === "bolder") return true;
25
+ if (keyword === "normal" || keyword === "lighter") return false;
26
+ const numeric = Number.parseInt(keyword, 10);
27
+ return Number.isNaN(numeric) ? void 0 : numeric >= BOLD_WEIGHT_THRESHOLD;
28
+ }
29
+ function italicFromStyleAttribute(style) {
30
+ const keyword = style.trim().toLowerCase();
31
+ if (keyword === "italic" || keyword === "oblique") return true;
32
+ return keyword === "normal" ? false : void 0;
33
+ }
34
+ function styleFromFontBytes(bytes) {
35
+ const font = (0, pdf_codec_sfnt.parseSfnt)(bytes);
36
+ if (font === void 0) return;
37
+ const os2 = (0, pdf_codec_font_tables.parseOs2)(font);
38
+ if (os2 === void 0) return;
39
+ return {
40
+ bold: (os2.fsSelection & FS_SELECTION_BOLD) !== 0,
41
+ italic: (os2.fsSelection & FS_SELECTION_ITALIC) !== 0
42
+ };
43
+ }
44
+ function fontPartBytes(pkg, href) {
45
+ const part = pkg.parts[href];
46
+ if (part === void 0) throw new OdfEmbeddedFontError(`svg:font-face-uri references ${JSON.stringify(href)}, which is not a part of this package`);
47
+ if (part.kind !== "binary") throw new OdfEmbeddedFontError(`embedded font part ${JSON.stringify(href)} is an XML part, not binary font data`);
48
+ return (0, odf_js.base64ToBytes)(part.base64);
49
+ }
50
+ function collectFontFace(pkg, fontFace, seenHrefs, out) {
51
+ const declaredFamily = (0, odf_js.attrValue)(fontFace, "svg:font-family") ?? (0, odf_js.attrValue)(fontFace, "style:name");
52
+ for (const src of (0, odf_js.childrenWithTag)(fontFace, "svg:font-face-src")) for (const uri of (0, odf_js.childrenWithTag)(src, "svg:font-face-uri")) {
53
+ const rawHref = (0, odf_js.attrValue)(uri, "xlink:href");
54
+ if (rawHref === void 0) throw new OdfEmbeddedFontError("a <svg:font-face-uri> carries no xlink:href");
55
+ const href = (0, odf_js.decodeXmlText)(rawHref);
56
+ if (seenHrefs.has(href)) continue;
57
+ seenHrefs.add(href);
58
+ if (declaredFamily === void 0) throw new OdfEmbeddedFontError(`the <style:font-face> embedding ${JSON.stringify(href)} declares neither svg:font-family nor style:name`);
59
+ const bytes = fontPartBytes(pkg, href);
60
+ if (!require_fonts_obfuscation.looksLikeSfnt(bytes)) throw new OdfEmbeddedFontError(`embedded font part ${JSON.stringify(href)} does not begin with a recognisable sfnt signature`);
61
+ const declaredWeight = (0, odf_js.attrValue)(uri, "loext:font-weight");
62
+ const declaredStyle = (0, odf_js.attrValue)(uri, "loext:font-style");
63
+ const intrinsic = styleFromFontBytes(bytes);
64
+ out.push({
65
+ family: normaliseFamily(declaredFamily),
66
+ bold: (declaredWeight === void 0 ? void 0 : boldFromWeightAttribute(declaredWeight)) ?? intrinsic?.bold ?? false,
67
+ italic: (declaredStyle === void 0 ? void 0 : italicFromStyleAttribute(declaredStyle)) ?? intrinsic?.italic ?? false,
68
+ bytes
69
+ });
70
+ }
71
+ }
72
+ function extractOdfEmbeddedFonts(pkg) {
73
+ const out = [];
74
+ const seenHrefs = /* @__PURE__ */ new Set();
75
+ for (const partPath of FONT_FACE_DECL_PARTS) {
76
+ const part = pkg.parts[partPath];
77
+ if (part?.kind !== "xml") continue;
78
+ const root = (0, odf_js.rootElement)(part.nodes);
79
+ if (root === void 0) continue;
80
+ for (const decls of (0, odf_js.childrenWithTag)(root, "office:font-face-decls")) for (const fontFace of (0, odf_js.childrenWithTag)(decls, "style:font-face")) collectFontFace(pkg, fontFace, seenHrefs, out);
81
+ }
82
+ return out;
83
+ }
84
+ //#endregion
85
+ exports.OdfEmbeddedFontError = OdfEmbeddedFontError;
86
+ exports.extractOdfEmbeddedFonts = extractOdfEmbeddedFonts;
@@ -0,0 +1,9 @@
1
+ import { Package } from "odf.js";
2
+ import { ProvidedFont } from "pdf-codec";
3
+ //#region src/fonts/odf.d.ts
4
+ declare class OdfEmbeddedFontError extends Error {
5
+ constructor(detail: string);
6
+ }
7
+ declare function extractOdfEmbeddedFonts(pkg: Package): ProvidedFont[];
8
+ //#endregion
9
+ export { OdfEmbeddedFontError, extractOdfEmbeddedFonts };
@@ -0,0 +1,9 @@
1
+ import { Package } from "odf.js";
2
+ import { ProvidedFont } from "pdf-codec";
3
+ //#region src/fonts/odf.d.ts
4
+ declare class OdfEmbeddedFontError extends Error {
5
+ constructor(detail: string);
6
+ }
7
+ declare function extractOdfEmbeddedFonts(pkg: Package): ProvidedFont[];
8
+ //#endregion
9
+ export { OdfEmbeddedFontError, extractOdfEmbeddedFonts };
@@ -0,0 +1,84 @@
1
+ import { looksLikeSfnt } from "./obfuscation.js";
2
+ import { attrValue, base64ToBytes, childrenWithTag, decodeXmlText, rootElement } from "odf.js";
3
+ import { parseSfnt } from "pdf-codec/sfnt";
4
+ import { parseOs2 } from "pdf-codec/font-tables";
5
+ //#region src/fonts/odf.ts
6
+ const FONT_FACE_DECL_PARTS = ["content.xml", "styles.xml"];
7
+ const FS_SELECTION_ITALIC = 1;
8
+ const FS_SELECTION_BOLD = 32;
9
+ const BOLD_WEIGHT_THRESHOLD = 600;
10
+ var OdfEmbeddedFontError = class extends Error {
11
+ constructor(detail) {
12
+ super(`extractOdfEmbeddedFonts: ${detail}`);
13
+ this.name = "OdfEmbeddedFontError";
14
+ }
15
+ };
16
+ function normaliseFamily(value) {
17
+ const first = decodeXmlText(value).split(",")[0]?.trim() ?? "";
18
+ const quoted = /^'(.*)'$|^"(.*)"$/.exec(first);
19
+ return (quoted?.[1] ?? quoted?.[2] ?? first).trim();
20
+ }
21
+ function boldFromWeightAttribute(weight) {
22
+ const keyword = weight.trim().toLowerCase();
23
+ if (keyword === "bold" || keyword === "bolder") return true;
24
+ if (keyword === "normal" || keyword === "lighter") return false;
25
+ const numeric = Number.parseInt(keyword, 10);
26
+ return Number.isNaN(numeric) ? void 0 : numeric >= BOLD_WEIGHT_THRESHOLD;
27
+ }
28
+ function italicFromStyleAttribute(style) {
29
+ const keyword = style.trim().toLowerCase();
30
+ if (keyword === "italic" || keyword === "oblique") return true;
31
+ return keyword === "normal" ? false : void 0;
32
+ }
33
+ function styleFromFontBytes(bytes) {
34
+ const font = parseSfnt(bytes);
35
+ if (font === void 0) return;
36
+ const os2 = parseOs2(font);
37
+ if (os2 === void 0) return;
38
+ return {
39
+ bold: (os2.fsSelection & FS_SELECTION_BOLD) !== 0,
40
+ italic: (os2.fsSelection & FS_SELECTION_ITALIC) !== 0
41
+ };
42
+ }
43
+ function fontPartBytes(pkg, href) {
44
+ const part = pkg.parts[href];
45
+ if (part === void 0) throw new OdfEmbeddedFontError(`svg:font-face-uri references ${JSON.stringify(href)}, which is not a part of this package`);
46
+ if (part.kind !== "binary") throw new OdfEmbeddedFontError(`embedded font part ${JSON.stringify(href)} is an XML part, not binary font data`);
47
+ return base64ToBytes(part.base64);
48
+ }
49
+ function collectFontFace(pkg, fontFace, seenHrefs, out) {
50
+ const declaredFamily = attrValue(fontFace, "svg:font-family") ?? attrValue(fontFace, "style:name");
51
+ for (const src of childrenWithTag(fontFace, "svg:font-face-src")) for (const uri of childrenWithTag(src, "svg:font-face-uri")) {
52
+ const rawHref = attrValue(uri, "xlink:href");
53
+ if (rawHref === void 0) throw new OdfEmbeddedFontError("a <svg:font-face-uri> carries no xlink:href");
54
+ const href = decodeXmlText(rawHref);
55
+ if (seenHrefs.has(href)) continue;
56
+ seenHrefs.add(href);
57
+ if (declaredFamily === void 0) throw new OdfEmbeddedFontError(`the <style:font-face> embedding ${JSON.stringify(href)} declares neither svg:font-family nor style:name`);
58
+ const bytes = fontPartBytes(pkg, href);
59
+ if (!looksLikeSfnt(bytes)) throw new OdfEmbeddedFontError(`embedded font part ${JSON.stringify(href)} does not begin with a recognisable sfnt signature`);
60
+ const declaredWeight = attrValue(uri, "loext:font-weight");
61
+ const declaredStyle = attrValue(uri, "loext:font-style");
62
+ const intrinsic = styleFromFontBytes(bytes);
63
+ out.push({
64
+ family: normaliseFamily(declaredFamily),
65
+ bold: (declaredWeight === void 0 ? void 0 : boldFromWeightAttribute(declaredWeight)) ?? intrinsic?.bold ?? false,
66
+ italic: (declaredStyle === void 0 ? void 0 : italicFromStyleAttribute(declaredStyle)) ?? intrinsic?.italic ?? false,
67
+ bytes
68
+ });
69
+ }
70
+ }
71
+ function extractOdfEmbeddedFonts(pkg) {
72
+ const out = [];
73
+ const seenHrefs = /* @__PURE__ */ new Set();
74
+ for (const partPath of FONT_FACE_DECL_PARTS) {
75
+ const part = pkg.parts[partPath];
76
+ if (part?.kind !== "xml") continue;
77
+ const root = rootElement(part.nodes);
78
+ if (root === void 0) continue;
79
+ for (const decls of childrenWithTag(root, "office:font-face-decls")) for (const fontFace of childrenWithTag(decls, "style:font-face")) collectFontFace(pkg, fontFace, seenHrefs, out);
80
+ }
81
+ return out;
82
+ }
83
+ //#endregion
84
+ export { OdfEmbeddedFontError, extractOdfEmbeddedFonts };
@@ -0,0 +1,129 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_fonts_obfuscation = require("./obfuscation.cjs");
3
+ let ooxml_js = require("ooxml.js");
4
+ //#region src/fonts/ooxml.ts
5
+ const OFFICE_DOCUMENT_RELATIONSHIP = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument";
6
+ const FONT_TABLE_RELATIONSHIP = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable";
7
+ const ROOT_RELS_PART = "_rels/.rels";
8
+ const DOCX_EMBED_ELEMENTS = [
9
+ [
10
+ "w:embedRegular",
11
+ false,
12
+ false
13
+ ],
14
+ [
15
+ "w:embedBold",
16
+ true,
17
+ false
18
+ ],
19
+ [
20
+ "w:embedItalic",
21
+ false,
22
+ true
23
+ ],
24
+ [
25
+ "w:embedBoldItalic",
26
+ true,
27
+ true
28
+ ]
29
+ ];
30
+ const PPTX_EMBED_ELEMENTS = [
31
+ [
32
+ "p:regular",
33
+ false,
34
+ false
35
+ ],
36
+ [
37
+ "p:bold",
38
+ true,
39
+ false
40
+ ],
41
+ [
42
+ "p:italic",
43
+ false,
44
+ true
45
+ ],
46
+ [
47
+ "p:boldItalic",
48
+ true,
49
+ true
50
+ ]
51
+ ];
52
+ var OoxmlEmbeddedFontError = class extends Error {
53
+ constructor(detail) {
54
+ super(`extractOoxmlEmbeddedFonts: ${detail}`);
55
+ this.name = "OoxmlEmbeddedFontError";
56
+ }
57
+ };
58
+ function relatedPartPath(pkg, fromPartPath, relationshipType) {
59
+ for (const relationship of (0, ooxml_js.resolveRelationships)(pkg, fromPartPath).values()) if (relationship.type === relationshipType && relationship.targetMode === void 0) return relationship.target;
60
+ }
61
+ function officeDocumentPartPath(pkg) {
62
+ const rels = (0, ooxml_js.rootElement)(pkg.parts[ROOT_RELS_PART]);
63
+ if (rels !== void 0) for (const relationship of (0, ooxml_js.childrenWithTag)(rels, "Relationship")) {
64
+ if ((0, ooxml_js.attr)(relationship, "Type") !== OFFICE_DOCUMENT_RELATIONSHIP || (0, ooxml_js.attr)(relationship, "TargetMode") !== void 0) continue;
65
+ const target = (0, ooxml_js.attr)(relationship, "Target");
66
+ if (target !== void 0) return target.startsWith("/") ? target.slice(1) : target;
67
+ }
68
+ throw new OoxmlEmbeddedFontError(`the package declares no officeDocument relationship in ${ROOT_RELS_PART}`);
69
+ }
70
+ function fontPartBytes(pkg, fromPartPath, relationships, relationshipId) {
71
+ const relationship = relationships.get(relationshipId);
72
+ if (relationship === void 0) throw new OoxmlEmbeddedFontError(`${fromPartPath} references relationship id ${JSON.stringify(relationshipId)}, which its .rels part does not declare`);
73
+ const part = pkg.parts[relationship.target];
74
+ if (part === void 0) throw new OoxmlEmbeddedFontError(`relationship id ${JSON.stringify(relationshipId)} targets ${JSON.stringify(relationship.target)}, which is not a part of this package`);
75
+ if (part.kind !== "binary") throw new OoxmlEmbeddedFontError(`embedded font part ${JSON.stringify(relationship.target)} is an XML part, not binary font data`);
76
+ return (0, ooxml_js.base64ToBytes)(part.base64);
77
+ }
78
+ function collectFaces(pkg, declaringPartPath, relationships, fontElementChildren, fontElement, family, fontKeyAttribute, out) {
79
+ for (const [tag, bold, italic] of fontElementChildren) for (const embed of (0, ooxml_js.childrenWithTag)(fontElement, tag)) {
80
+ const relationshipId = (0, ooxml_js.attr)(embed, "r:id");
81
+ if (relationshipId === void 0) throw new OoxmlEmbeddedFontError(`<${tag}> for font ${JSON.stringify(family)} carries no r:id`);
82
+ const fontKey = fontKeyAttribute === void 0 ? void 0 : (0, ooxml_js.attr)(embed, fontKeyAttribute);
83
+ out.push({
84
+ family,
85
+ bold,
86
+ italic,
87
+ bytes: require_fonts_obfuscation.deobfuscateEmbeddedFont(fontPartBytes(pkg, declaringPartPath, relationships, relationshipId), fontKey)
88
+ });
89
+ }
90
+ }
91
+ function extractDocxFonts(pkg) {
92
+ const fontTablePath = relatedPartPath(pkg, officeDocumentPartPath(pkg), FONT_TABLE_RELATIONSHIP);
93
+ if (fontTablePath === void 0) return [];
94
+ const fontTablePart = pkg.parts[fontTablePath];
95
+ if (fontTablePart?.kind !== "xml") throw new OoxmlEmbeddedFontError(`font table part ${JSON.stringify(fontTablePath)} is missing or is not an XML part`);
96
+ const fonts = (0, ooxml_js.rootElement)(fontTablePart);
97
+ if (fonts === void 0) return [];
98
+ const relationships = (0, ooxml_js.resolveRelationships)(pkg, fontTablePath);
99
+ const out = [];
100
+ for (const font of (0, ooxml_js.childrenWithTag)(fonts, "w:font")) {
101
+ const family = (0, ooxml_js.attr)(font, "w:name");
102
+ if (family === void 0) throw new OoxmlEmbeddedFontError(`a <w:font> in ${JSON.stringify(fontTablePath)} carries no w:name`);
103
+ collectFaces(pkg, fontTablePath, relationships, DOCX_EMBED_ELEMENTS, font, (0, ooxml_js.decodeEntities)(family), "w:fontKey", out);
104
+ }
105
+ return out;
106
+ }
107
+ function extractPptxFonts(pkg) {
108
+ const presentationPartPath = officeDocumentPartPath(pkg);
109
+ const presentationPart = pkg.parts[presentationPartPath];
110
+ if (presentationPart?.kind !== "xml") throw new OoxmlEmbeddedFontError(`presentation part ${JSON.stringify(presentationPartPath)} is missing or is not an XML part`);
111
+ const presentation = (0, ooxml_js.rootElement)(presentationPart);
112
+ if (presentation === void 0) return [];
113
+ const relationships = (0, ooxml_js.resolveRelationships)(pkg, presentationPartPath);
114
+ const out = [];
115
+ for (const list of (0, ooxml_js.childrenWithTag)(presentation, "p:embeddedFontLst")) for (const embeddedFont of (0, ooxml_js.childrenWithTag)(list, "p:embeddedFont")) {
116
+ const fontElement = (0, ooxml_js.childrenWithTag)(embeddedFont, "p:font")[0];
117
+ if (fontElement === void 0) throw new OoxmlEmbeddedFontError(`a <p:embeddedFont> in ${JSON.stringify(presentationPartPath)} carries no <p:font>`);
118
+ const family = (0, ooxml_js.attr)(fontElement, "typeface");
119
+ if (family === void 0) throw new OoxmlEmbeddedFontError(`a <p:font> in ${JSON.stringify(presentationPartPath)} carries no typeface`);
120
+ collectFaces(pkg, presentationPartPath, relationships, PPTX_EMBED_ELEMENTS, embeddedFont, (0, ooxml_js.decodeEntities)(family), void 0, out);
121
+ }
122
+ return out;
123
+ }
124
+ function extractOoxmlEmbeddedFonts(pkg, kind) {
125
+ return kind === "docx" ? extractDocxFonts(pkg) : extractPptxFonts(pkg);
126
+ }
127
+ //#endregion
128
+ exports.OoxmlEmbeddedFontError = OoxmlEmbeddedFontError;
129
+ exports.extractOoxmlEmbeddedFonts = extractOoxmlEmbeddedFonts;