pdf-parser.js 5.2.25 → 5.2.27

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 (149) hide show
  1. package/dist/afm-widths.cjs +1 -1
  2. package/dist/afm-widths.js +1 -1
  3. package/dist/annotations.d.cts +2 -2
  4. package/dist/annotations.d.ts +2 -2
  5. package/dist/attachments.d.cts +2 -2
  6. package/dist/attachments.d.ts +2 -2
  7. package/dist/builtin-encoding.cjs +1 -1
  8. package/dist/builtin-encoding.d.cts +2 -2
  9. package/dist/builtin-encoding.d.ts +2 -2
  10. package/dist/builtin-encoding.js +1 -1
  11. package/dist/cff-bounds.cjs +31 -21
  12. package/dist/cff-bounds.d.cts +1 -1
  13. package/dist/cff-bounds.d.ts +1 -1
  14. package/dist/cff-bounds.js +31 -21
  15. package/dist/cff.d.cts +1 -1
  16. package/dist/cff.d.ts +1 -1
  17. package/dist/cmap-table.d.cts +1 -1
  18. package/dist/cmap-table.d.ts +1 -1
  19. package/dist/cmap.d.cts +1 -1
  20. package/dist/cmap.d.ts +1 -1
  21. package/dist/content-read.d.cts +1 -1
  22. package/dist/content-read.d.ts +1 -1
  23. package/dist/content-write.cjs +19 -13
  24. package/dist/content-write.d.cts +3 -3
  25. package/dist/content-write.d.ts +3 -3
  26. package/dist/content-write.js +19 -13
  27. package/dist/document.cjs +17 -11
  28. package/dist/document.d.cts +5 -5
  29. package/dist/document.d.ts +5 -5
  30. package/dist/document.js +17 -11
  31. package/dist/{embedded-font-BRhZfEN2.d.ts → embedded-font-ByD7ZiQS.d.ts} +4 -4
  32. package/dist/{embedded-font-DJUn9kMH.d.cts → embedded-font-DgVBedw6.d.cts} +4 -4
  33. package/dist/embedded-font-write.d.cts +2 -2
  34. package/dist/embedded-font-write.d.ts +2 -2
  35. package/dist/embedded-font.cjs +1 -1
  36. package/dist/embedded-font.d.cts +1 -1
  37. package/dist/embedded-font.d.ts +1 -1
  38. package/dist/embedded-font.js +1 -1
  39. package/dist/encoding.cjs +1 -1
  40. package/dist/encoding.js +1 -1
  41. package/dist/encrypt-write.d.cts +3 -3
  42. package/dist/encrypt-write.d.ts +3 -3
  43. package/dist/encrypt.d.cts +3 -3
  44. package/dist/encrypt.d.ts +3 -3
  45. package/dist/filters.cjs +6 -6
  46. package/dist/filters.d.cts +1 -1
  47. package/dist/filters.d.ts +1 -1
  48. package/dist/filters.js +6 -6
  49. package/dist/font-read.cjs +1 -1
  50. package/dist/font-read.d.cts +3 -3
  51. package/dist/font-read.d.ts +3 -3
  52. package/dist/font-read.js +1 -1
  53. package/dist/font-registry.d.cts +3 -3
  54. package/dist/font-registry.d.ts +3 -3
  55. package/dist/form.cjs +13 -8
  56. package/dist/form.d.cts +2 -2
  57. package/dist/form.d.ts +2 -2
  58. package/dist/form.js +13 -8
  59. package/dist/gdef-table.d.cts +3 -3
  60. package/dist/gdef-table.d.ts +3 -3
  61. package/dist/{glyf-vMGtP1pb.d.ts → glyf-Bv1katwK.d.ts} +4 -4
  62. package/dist/{glyf-nXC-IDRW.d.cts → glyf-DFyknMrW.d.cts} +4 -4
  63. package/dist/{glyf-contours-OSdG6Edr.d.ts → glyf-contours-B1PsI9oA.d.ts} +2 -2
  64. package/dist/{glyf-contours-zRQbj-Yp.d.cts → glyf-contours-NHBpgks-.d.cts} +2 -2
  65. package/dist/glyf-contours.d.cts +1 -1
  66. package/dist/glyf-contours.d.ts +1 -1
  67. package/dist/glyf.d.cts +1 -1
  68. package/dist/glyf.d.ts +1 -1
  69. package/dist/gsub-table.cjs +13 -9
  70. package/dist/gsub-table.js +13 -9
  71. package/dist/hmtx-table.d.cts +1 -1
  72. package/dist/hmtx-table.d.ts +1 -1
  73. package/dist/image/jbig2-generic.cjs +2 -2
  74. package/dist/image/jbig2-generic.js +2 -2
  75. package/dist/image/jpeg2000-codestream.cjs +17 -8
  76. package/dist/image/jpeg2000-codestream.js +17 -8
  77. package/dist/image/jpeg2000-tagtree.cjs +1 -1
  78. package/dist/image/jpeg2000-tagtree.js +1 -1
  79. package/dist/images-read.d.cts +2 -2
  80. package/dist/images-read.d.ts +2 -2
  81. package/dist/index.cjs +1 -1
  82. package/dist/index.d.cts +1 -1
  83. package/dist/index.d.ts +1 -1
  84. package/dist/index.js +1 -1
  85. package/dist/interpret.cjs +31 -18
  86. package/dist/interpret.d.cts +5 -5
  87. package/dist/interpret.d.ts +5 -5
  88. package/dist/interpret.js +31 -18
  89. package/dist/math-content-write.cjs +3 -3
  90. package/dist/math-content-write.js +3 -3
  91. package/dist/math-font-write.d.cts +1 -1
  92. package/dist/math-font-write.d.ts +1 -1
  93. package/dist/math-font.d.cts +4 -4
  94. package/dist/math-font.d.ts +4 -4
  95. package/dist/measure.cjs +1 -1
  96. package/dist/measure.js +1 -1
  97. package/dist/names.cjs +7 -7
  98. package/dist/names.d.cts +2 -2
  99. package/dist/names.d.ts +2 -2
  100. package/dist/names.js +7 -7
  101. package/dist/navigation.cjs +6 -7
  102. package/dist/navigation.d.cts +5 -5
  103. package/dist/navigation.d.ts +5 -5
  104. package/dist/navigation.js +6 -7
  105. package/dist/{objects-B7HdMeWS.d.ts → objects-e2RS3-yT.d.cts} +3 -3
  106. package/dist/{objects-B7HdMeWS.d.cts → objects-e2RS3-yT.d.ts} +3 -3
  107. package/dist/objects.d.cts +1 -1
  108. package/dist/objects.d.ts +1 -1
  109. package/dist/optional-content.d.cts +2 -2
  110. package/dist/optional-content.d.ts +2 -2
  111. package/dist/ot-layout-common.cjs +18 -13
  112. package/dist/ot-layout-common.d.cts +2 -2
  113. package/dist/ot-layout-common.d.ts +2 -2
  114. package/dist/ot-layout-common.js +18 -13
  115. package/dist/parse.cjs +5 -0
  116. package/dist/parse.d.cts +3 -2
  117. package/dist/parse.d.ts +3 -2
  118. package/dist/parse.js +5 -1
  119. package/dist/predictors.d.cts +1 -1
  120. package/dist/predictors.d.ts +1 -1
  121. package/dist/raster.cjs +10 -40
  122. package/dist/raster.d.cts +11 -11
  123. package/dist/raster.d.ts +11 -11
  124. package/dist/raster.js +10 -40
  125. package/dist/read.cjs +12 -8
  126. package/dist/read.js +12 -8
  127. package/dist/serialize.d.cts +1 -1
  128. package/dist/serialize.d.ts +1 -1
  129. package/dist/sfnt-subset.d.cts +1 -1
  130. package/dist/sfnt-subset.d.ts +1 -1
  131. package/dist/structure.cjs +4 -4
  132. package/dist/structure.d.cts +2 -2
  133. package/dist/structure.d.ts +2 -2
  134. package/dist/structure.js +4 -4
  135. package/dist/text-layout.d.cts +1 -1
  136. package/dist/text-layout.d.ts +1 -1
  137. package/dist/tounicode.d.cts +1 -1
  138. package/dist/tounicode.d.ts +1 -1
  139. package/dist/winansi.cjs +1 -1
  140. package/dist/winansi.js +1 -1
  141. package/dist/write.cjs +4 -4
  142. package/dist/write.d.cts +1 -1
  143. package/dist/write.d.ts +1 -1
  144. package/dist/write.js +4 -4
  145. package/dist/xref.d.cts +1 -1
  146. package/dist/xref.d.ts +1 -1
  147. package/package.json +2 -2
  148. package/dist/{afm-widths-BTu0IDp2.cjs → afm-widths-BYiX2L9D.cjs} +1 -1
  149. package/dist/{afm-widths-De_QMWgC.js → afm-widths-blUDDjlI.js} +1 -1
@@ -18,10 +18,10 @@ interface CompositeComponent {
18
18
  }
19
19
  interface GlyfTable {
20
20
  readonly numGlyphs: number;
21
- glyphBytes(glyphId: number): Uint8Array<ArrayBuffer> | undefined;
22
- glyphHeader(glyphId: number): GlyphHeader | undefined;
23
- compositeComponents(glyphId: number): readonly CompositeComponent[] | undefined;
24
- glyphInkBounds(glyphId: number): GlyphInkBounds | undefined;
21
+ glyphBytes: (glyphId: number) => Uint8Array<ArrayBuffer> | undefined;
22
+ glyphHeader: (glyphId: number) => GlyphHeader | undefined;
23
+ compositeComponents: (glyphId: number) => readonly CompositeComponent[] | undefined;
24
+ glyphInkBounds: (glyphId: number) => GlyphInkBounds | undefined;
25
25
  }
26
26
  interface GlyfOptions {
27
27
  readonly numGlyphs: number;
@@ -1,4 +1,4 @@
1
- import { r as GlyfTable } from "./glyf-vMGtP1pb.js";
1
+ import { r as GlyfTable } from "./glyf-Bv1katwK.js";
2
2
  //#region src/glyf-contours.d.ts
3
3
  interface GlyphContourPoint {
4
4
  readonly x: number;
@@ -8,6 +8,6 @@ interface GlyphContourPoint {
8
8
  interface GlyphOutline {
9
9
  readonly contours: readonly (readonly GlyphContourPoint[])[];
10
10
  }
11
- declare function decodeGlyphOutline(glyf: GlyfTable, glyphId: number): GlyphOutline | undefined;
11
+ declare function decodeGlyphOutline(glyf: Readonly<GlyfTable>, glyphId: number): GlyphOutline | undefined;
12
12
  //#endregion
13
13
  export { GlyphOutline as n, decodeGlyphOutline as r, GlyphContourPoint as t };
@@ -1,4 +1,4 @@
1
- import { r as GlyfTable } from "./glyf-nXC-IDRW.cjs";
1
+ import { r as GlyfTable } from "./glyf-DFyknMrW.cjs";
2
2
  //#region src/glyf-contours.d.ts
3
3
  interface GlyphContourPoint {
4
4
  readonly x: number;
@@ -8,6 +8,6 @@ interface GlyphContourPoint {
8
8
  interface GlyphOutline {
9
9
  readonly contours: readonly (readonly GlyphContourPoint[])[];
10
10
  }
11
- declare function decodeGlyphOutline(glyf: GlyfTable, glyphId: number): GlyphOutline | undefined;
11
+ declare function decodeGlyphOutline(glyf: Readonly<GlyfTable>, glyphId: number): GlyphOutline | undefined;
12
12
  //#endregion
13
13
  export { GlyphOutline as n, decodeGlyphOutline as r, GlyphContourPoint as t };
@@ -1,2 +1,2 @@
1
- import { n as GlyphOutline, r as decodeGlyphOutline, t as GlyphContourPoint } from "./glyf-contours-zRQbj-Yp.cjs";
1
+ import { n as GlyphOutline, r as decodeGlyphOutline, t as GlyphContourPoint } from "./glyf-contours-NHBpgks-.cjs";
2
2
  export { GlyphContourPoint, GlyphOutline, decodeGlyphOutline };
@@ -1,2 +1,2 @@
1
- import { n as GlyphOutline, r as decodeGlyphOutline, t as GlyphContourPoint } from "./glyf-contours-OSdG6Edr.js";
1
+ import { n as GlyphOutline, r as decodeGlyphOutline, t as GlyphContourPoint } from "./glyf-contours-B1PsI9oA.js";
2
2
  export { GlyphContourPoint, GlyphOutline, decodeGlyphOutline };
package/dist/glyf.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as parseGlyf, i as GlyphHeader, n as GlyfOptions, o as parseLoca, r as GlyfTable, t as CompositeComponent } from "./glyf-nXC-IDRW.cjs";
1
+ import { a as parseGlyf, i as GlyphHeader, n as GlyfOptions, o as parseLoca, r as GlyfTable, t as CompositeComponent } from "./glyf-DFyknMrW.cjs";
2
2
  export { CompositeComponent, GlyfOptions, GlyfTable, GlyphHeader, parseGlyf, parseLoca };
package/dist/glyf.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as parseGlyf, i as GlyphHeader, n as GlyfOptions, o as parseLoca, r as GlyfTable, t as CompositeComponent } from "./glyf-vMGtP1pb.js";
1
+ import { a as parseGlyf, i as GlyphHeader, n as GlyfOptions, o as parseLoca, r as GlyfTable, t as CompositeComponent } from "./glyf-Bv1katwK.js";
2
2
  export { CompositeComponent, GlyfOptions, GlyfTable, GlyphHeader, parseGlyf, parseLoca };
@@ -3,6 +3,7 @@ const require_sfnt = require("./sfnt.cjs");
3
3
  const require_ot_layout_common = require("./ot-layout-common.cjs");
4
4
  const require_gdef_table = require("./gdef-table.cjs");
5
5
  //#region src/gsub-table.ts
6
+ const constantZeroClassDef = () => 0;
6
7
  const DEFAULT_GSUB_FEATURE_TAGS = [
7
8
  "liga",
8
9
  "rlig",
@@ -192,7 +193,10 @@ function applyContextualRule(slots, inputSlots, records, lookupOf, skip, depth)
192
193
  const lookup = lookupOf(record.lookupIndex);
193
194
  if (lookup === void 0 || record.sequenceIndex >= inputSlots.length || depth >= MAX_LOOKUP_NESTING_DEPTH) return;
194
195
  const target = visibleInputSlot(window, record.sequenceIndex, skip);
195
- if (target !== void 0) applyLookupAtSlot(window, target, lookup, depth + 1);
196
+ if (target !== void 0) {
197
+ const application = applyLookupAtSlot(window, target, lookup, depth + 1);
198
+ if (application !== void 0) window.splice(target, application.consumed, ...application.replacement);
199
+ }
196
200
  }
197
201
  return {
198
202
  consumed: last - first + 1,
@@ -210,12 +214,8 @@ function visibleInputSlot(window, position, skip) {
210
214
  function applyLookupAtSlot(slots, index, lookup, depth) {
211
215
  for (const subtable of lookup.subtables) {
212
216
  const application = subtable(slots, index, depth);
213
- if (application !== void 0) {
214
- slots.splice(index, application.consumed, ...application.replacement);
215
- return application.replacement.length;
216
- }
217
+ if (application !== void 0) return application;
217
218
  }
218
- return 0;
219
219
  }
220
220
  const SUBST_LOOKUP_RECORD_SIZE = 4;
221
221
  function readSubstLookupRecords(bytes, offset, count) {
@@ -422,7 +422,6 @@ function parseContextualSubtable(bytes, chained, subtableOffset, skip, lookupOf)
422
422
  }, skip, lookupOf);
423
423
  }
424
424
  }
425
- const constantZeroClassDef = () => 0;
426
425
  function findScriptOffset(bytes, scriptListOffset) {
427
426
  if (!require_sfnt.hasBytes(bytes, scriptListOffset, 2)) return;
428
427
  const scriptCount = require_sfnt.u16(bytes, scriptListOffset);
@@ -526,8 +525,13 @@ function buildGsubShaper(font, options = {}) {
526
525
  for (const lookup of appliedLookups) {
527
526
  let slotIndex = 0;
528
527
  while (slotIndex < slots.length) {
529
- const advanced = applyLookupAtSlot(slots, slotIndex, lookup, 0);
530
- slotIndex += advanced !== 0 ? advanced : 1;
528
+ const application = applyLookupAtSlot(slots, slotIndex, lookup, 0);
529
+ if (application === void 0) {
530
+ slotIndex += 1;
531
+ continue;
532
+ }
533
+ slots.splice(slotIndex, application.consumed, ...application.replacement);
534
+ slotIndex += application.replacement.length !== 0 ? application.replacement.length : 1;
531
535
  }
532
536
  }
533
537
  return {
@@ -2,6 +2,7 @@ import { hasBytes, i16, sfntTableBytes, u16, u32 } from "./sfnt.js";
2
2
  import { parseClassDef, parseCoverage } from "./ot-layout-common.js";
3
3
  import { parseGdefTable } from "./gdef-table.js";
4
4
  //#region src/gsub-table.ts
5
+ const constantZeroClassDef = () => 0;
5
6
  const DEFAULT_GSUB_FEATURE_TAGS = [
6
7
  "liga",
7
8
  "rlig",
@@ -191,7 +192,10 @@ function applyContextualRule(slots, inputSlots, records, lookupOf, skip, depth)
191
192
  const lookup = lookupOf(record.lookupIndex);
192
193
  if (lookup === void 0 || record.sequenceIndex >= inputSlots.length || depth >= MAX_LOOKUP_NESTING_DEPTH) return;
193
194
  const target = visibleInputSlot(window, record.sequenceIndex, skip);
194
- if (target !== void 0) applyLookupAtSlot(window, target, lookup, depth + 1);
195
+ if (target !== void 0) {
196
+ const application = applyLookupAtSlot(window, target, lookup, depth + 1);
197
+ if (application !== void 0) window.splice(target, application.consumed, ...application.replacement);
198
+ }
195
199
  }
196
200
  return {
197
201
  consumed: last - first + 1,
@@ -209,12 +213,8 @@ function visibleInputSlot(window, position, skip) {
209
213
  function applyLookupAtSlot(slots, index, lookup, depth) {
210
214
  for (const subtable of lookup.subtables) {
211
215
  const application = subtable(slots, index, depth);
212
- if (application !== void 0) {
213
- slots.splice(index, application.consumed, ...application.replacement);
214
- return application.replacement.length;
215
- }
216
+ if (application !== void 0) return application;
216
217
  }
217
- return 0;
218
218
  }
219
219
  const SUBST_LOOKUP_RECORD_SIZE = 4;
220
220
  function readSubstLookupRecords(bytes, offset, count) {
@@ -421,7 +421,6 @@ function parseContextualSubtable(bytes, chained, subtableOffset, skip, lookupOf)
421
421
  }, skip, lookupOf);
422
422
  }
423
423
  }
424
- const constantZeroClassDef = () => 0;
425
424
  function findScriptOffset(bytes, scriptListOffset) {
426
425
  if (!hasBytes(bytes, scriptListOffset, 2)) return;
427
426
  const scriptCount = u16(bytes, scriptListOffset);
@@ -525,8 +524,13 @@ function buildGsubShaper(font, options = {}) {
525
524
  for (const lookup of appliedLookups) {
526
525
  let slotIndex = 0;
527
526
  while (slotIndex < slots.length) {
528
- const advanced = applyLookupAtSlot(slots, slotIndex, lookup, 0);
529
- slotIndex += advanced !== 0 ? advanced : 1;
527
+ const application = applyLookupAtSlot(slots, slotIndex, lookup, 0);
528
+ if (application === void 0) {
529
+ slotIndex += 1;
530
+ continue;
531
+ }
532
+ slots.splice(slotIndex, application.consumed, ...application.replacement);
533
+ slotIndex += application.replacement.length !== 0 ? application.replacement.length : 1;
530
534
  }
531
535
  }
532
536
  return {
@@ -1,7 +1,7 @@
1
1
  import { t as SfntFont } from "./sfnt-V08bb5ut.cjs";
2
2
  //#region src/hmtx-table.d.ts
3
3
  interface HmtxTable {
4
- advanceWidth(glyphId: number): number;
4
+ advanceWidth: (glyphId: number) => number;
5
5
  }
6
6
  declare function parseHmtx(font: SfntFont): HmtxTable;
7
7
  //#endregion
@@ -1,7 +1,7 @@
1
1
  import { t as SfntFont } from "./sfnt-V08bb5ut.js";
2
2
  //#region src/hmtx-table.d.ts
3
3
  interface HmtxTable {
4
- advanceWidth(glyphId: number): number;
4
+ advanceWidth: (glyphId: number) => number;
5
5
  }
6
6
  declare function parseHmtx(font: SfntFont): HmtxTable;
7
7
  //#endregion
@@ -91,14 +91,14 @@ function resolveTemplate(template) {
91
91
  if (positions === void 0) throw new require_image_jbig2_errors.Jbig2UnsupportedError(`generic region declares GBTEMPLATE ${String(template)}, which is outside the 0-3 range T.88 6.2.5.3 defines`);
92
92
  return positions;
93
93
  }
94
- function flattenTemplate(positions, at) {
94
+ function flattenTemplate(positions, atPixels) {
95
95
  const dx = new Int32Array(positions.length);
96
96
  const dy = new Int32Array(positions.length);
97
97
  positions.forEach((position, i) => {
98
98
  const offset = position.kind === "fixed" ? {
99
99
  x: position.dx,
100
100
  y: position.dy
101
- } : at[position.index] ?? {
101
+ } : atPixels[position.index] ?? {
102
102
  x: 0,
103
103
  y: 0
104
104
  };
@@ -90,14 +90,14 @@ function resolveTemplate(template) {
90
90
  if (positions === void 0) throw new Jbig2UnsupportedError(`generic region declares GBTEMPLATE ${String(template)}, which is outside the 0-3 range T.88 6.2.5.3 defines`);
91
91
  return positions;
92
92
  }
93
- function flattenTemplate(positions, at) {
93
+ function flattenTemplate(positions, atPixels) {
94
94
  const dx = new Int32Array(positions.length);
95
95
  const dy = new Int32Array(positions.length);
96
96
  positions.forEach((position, i) => {
97
97
  const offset = position.kind === "fixed" ? {
98
98
  x: position.dx,
99
99
  y: position.dy
100
- } : at[position.index] ?? {
100
+ } : atPixels[position.index] ?? {
101
101
  x: 0,
102
102
  y: 0
103
103
  };
@@ -201,6 +201,15 @@ function freezeHeader(header) {
201
201
  };
202
202
  return base;
203
203
  }
204
+ var CodestreamComments = class {
205
+ #texts = [];
206
+ add(text) {
207
+ this.#texts.push(text);
208
+ }
209
+ texts() {
210
+ return this.#texts;
211
+ }
212
+ };
204
213
  function readHeaderSegment(marker, cursor, header, componentCount, comments) {
205
214
  const length = cursor.uint16();
206
215
  if (length < 2) throw new require_image_jpeg2000_errors.Jpeg2000ParseError(`marker segment 0x${marker.toString(16)} declares a length of ${String(length)}, which is shorter than the length field itself`);
@@ -220,7 +229,7 @@ function readHeaderSegment(marker, cursor, header, componentCount, comments) {
220
229
  else if (marker === MARKER_COM) {
221
230
  const registration = cursor.uint16();
222
231
  const body = cursor.bytes(segmentEnd - cursor.position);
223
- if (registration === 1) comments.push(Array.from(body, (byte) => String.fromCharCode(byte)).join(""));
232
+ if (registration === 1) comments.add(Array.from(body, (byte) => String.fromCharCode(byte)).join(""));
224
233
  }
225
234
  cursor.position = segmentEnd;
226
235
  }
@@ -236,7 +245,7 @@ function parseJpeg2000Codestream(data) {
236
245
  const sizEnd = cursor.position + sizLength - 2;
237
246
  const siz = readImageSize(cursor, sizEnd);
238
247
  cursor.position = sizEnd;
239
- const comments = [];
248
+ const comments = new CodestreamComments();
240
249
  const main = emptyHeader();
241
250
  const tileParts = [];
242
251
  let sawEoc = false;
@@ -250,7 +259,7 @@ function parseJpeg2000Codestream(data) {
250
259
  if (marker === MARKER_PPM) throw new require_image_jpeg2000_errors.Jpeg2000UnsupportedError("the codestream carries a PPM marker (packed packet headers in the main header), an organisation this decoder does not reassemble");
251
260
  if (marker === MARKER_SOT) {
252
261
  cursor.position -= 2;
253
- readTilePart(cursor, siz.components.length, tileParts, comments);
262
+ tileParts.push(readTilePart(cursor, siz.components.length, comments));
254
263
  continue;
255
264
  }
256
265
  if (marker === MARKER_SOD || marker === MARKER_SOC) throw new require_image_jpeg2000_errors.Jpeg2000ParseError(`unexpected marker 0x${marker.toString(16)} in the main header`);
@@ -264,13 +273,13 @@ function parseJpeg2000Codestream(data) {
264
273
  siz,
265
274
  main: freezeHeader(main),
266
275
  tileParts,
267
- comments,
276
+ comments: comments.texts(),
268
277
  numTilesWide,
269
278
  numTilesHigh,
270
279
  truncated: !sawEoc
271
280
  };
272
281
  }
273
- function readTilePart(cursor, componentCount, tileParts, comments) {
282
+ function readTilePart(cursor, componentCount, comments) {
274
283
  const sotStart = cursor.position;
275
284
  cursor.uint16();
276
285
  const lsot = cursor.uint16();
@@ -292,14 +301,14 @@ function readTilePart(cursor, componentCount, tileParts, comments) {
292
301
  const dataEnd = Math.min(declaredEnd, cursor.data.length);
293
302
  if (dataEnd < dataStart) throw new require_image_jpeg2000_errors.Jpeg2000ParseError("a tile-part declares a Psot shorter than its own header");
294
303
  const trimmedEnd = trimTrailingEoc(cursor.data, dataEnd);
295
- tileParts.push({
304
+ cursor.position = dataEnd;
305
+ return {
296
306
  tileIndex,
297
307
  partIndex,
298
308
  header: freezeHeader(header),
299
309
  dataStart,
300
310
  dataEnd: trimmedEnd
301
- });
302
- cursor.position = dataEnd;
311
+ };
303
312
  }
304
313
  function trimTrailingEoc(data, end) {
305
314
  if (data[end - 2] === 255 && data[end - 1] === 217) return end - 2;
@@ -200,6 +200,15 @@ function freezeHeader(header) {
200
200
  };
201
201
  return base;
202
202
  }
203
+ var CodestreamComments = class {
204
+ #texts = [];
205
+ add(text) {
206
+ this.#texts.push(text);
207
+ }
208
+ texts() {
209
+ return this.#texts;
210
+ }
211
+ };
203
212
  function readHeaderSegment(marker, cursor, header, componentCount, comments) {
204
213
  const length = cursor.uint16();
205
214
  if (length < 2) throw new Jpeg2000ParseError(`marker segment 0x${marker.toString(16)} declares a length of ${String(length)}, which is shorter than the length field itself`);
@@ -219,7 +228,7 @@ function readHeaderSegment(marker, cursor, header, componentCount, comments) {
219
228
  else if (marker === MARKER_COM) {
220
229
  const registration = cursor.uint16();
221
230
  const body = cursor.bytes(segmentEnd - cursor.position);
222
- if (registration === 1) comments.push(Array.from(body, (byte) => String.fromCharCode(byte)).join(""));
231
+ if (registration === 1) comments.add(Array.from(body, (byte) => String.fromCharCode(byte)).join(""));
223
232
  }
224
233
  cursor.position = segmentEnd;
225
234
  }
@@ -235,7 +244,7 @@ function parseJpeg2000Codestream(data) {
235
244
  const sizEnd = cursor.position + sizLength - 2;
236
245
  const siz = readImageSize(cursor, sizEnd);
237
246
  cursor.position = sizEnd;
238
- const comments = [];
247
+ const comments = new CodestreamComments();
239
248
  const main = emptyHeader();
240
249
  const tileParts = [];
241
250
  let sawEoc = false;
@@ -249,7 +258,7 @@ function parseJpeg2000Codestream(data) {
249
258
  if (marker === MARKER_PPM) throw new Jpeg2000UnsupportedError("the codestream carries a PPM marker (packed packet headers in the main header), an organisation this decoder does not reassemble");
250
259
  if (marker === MARKER_SOT) {
251
260
  cursor.position -= 2;
252
- readTilePart(cursor, siz.components.length, tileParts, comments);
261
+ tileParts.push(readTilePart(cursor, siz.components.length, comments));
253
262
  continue;
254
263
  }
255
264
  if (marker === MARKER_SOD || marker === MARKER_SOC) throw new Jpeg2000ParseError(`unexpected marker 0x${marker.toString(16)} in the main header`);
@@ -263,13 +272,13 @@ function parseJpeg2000Codestream(data) {
263
272
  siz,
264
273
  main: freezeHeader(main),
265
274
  tileParts,
266
- comments,
275
+ comments: comments.texts(),
267
276
  numTilesWide,
268
277
  numTilesHigh,
269
278
  truncated: !sawEoc
270
279
  };
271
280
  }
272
- function readTilePart(cursor, componentCount, tileParts, comments) {
281
+ function readTilePart(cursor, componentCount, comments) {
273
282
  const sotStart = cursor.position;
274
283
  cursor.uint16();
275
284
  const lsot = cursor.uint16();
@@ -291,14 +300,14 @@ function readTilePart(cursor, componentCount, tileParts, comments) {
291
300
  const dataEnd = Math.min(declaredEnd, cursor.data.length);
292
301
  if (dataEnd < dataStart) throw new Jpeg2000ParseError("a tile-part declares a Psot shorter than its own header");
293
302
  const trimmedEnd = trimTrailingEoc(cursor.data, dataEnd);
294
- tileParts.push({
303
+ cursor.position = dataEnd;
304
+ return {
295
305
  tileIndex,
296
306
  partIndex,
297
307
  header: freezeHeader(header),
298
308
  dataStart,
299
309
  dataEnd: trimmedEnd
300
- });
301
- cursor.position = dataEnd;
310
+ };
302
311
  }
303
312
  function trimTrailingEoc(data, end) {
304
313
  if (data[end - 2] === 255 && data[end - 1] === 217) return end - 2;
@@ -1,6 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_image_jpeg2000_errors = require("./jpeg2000-errors.cjs");
3
3
  //#region src/image/jpeg2000-tagtree.ts
4
+ const SENTINEL_VALUE = 2147483647;
4
5
  var PacketBitReader = class {
5
6
  data;
6
7
  end;
@@ -99,7 +100,6 @@ var TagTree = class {
99
100
  return this.value[y * (this.levelWidths[0] ?? 1) + x] ?? SENTINEL_VALUE;
100
101
  }
101
102
  };
102
- const SENTINEL_VALUE = 2147483647;
103
103
  //#endregion
104
104
  exports.PacketBitReader = PacketBitReader;
105
105
  exports.TagTree = TagTree;
@@ -1,5 +1,6 @@
1
1
  import { Jpeg2000ParseError } from "./jpeg2000-errors.js";
2
2
  //#region src/image/jpeg2000-tagtree.ts
3
+ const SENTINEL_VALUE = 2147483647;
3
4
  var PacketBitReader = class {
4
5
  data;
5
6
  end;
@@ -98,6 +99,5 @@ var TagTree = class {
98
99
  return this.value[y * (this.levelWidths[0] ?? 1) + x] ?? SENTINEL_VALUE;
99
100
  }
100
101
  };
101
- const SENTINEL_VALUE = 2147483647;
102
102
  //#endregion
103
103
  export { PacketBitReader, TagTree };
@@ -1,5 +1,5 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.cjs";
2
- import { n as PdfDict } from "./objects-B7HdMeWS.cjs";
2
+ import { n as PdfDict } from "./objects-e2RS3-yT.cjs";
3
3
  import { PdfObjectResolver } from "./interpret.cjs";
4
4
  //#region src/images-read.d.ts
5
5
  interface ExtractedPdfImage {
@@ -13,6 +13,6 @@ interface ExtractedPdfImage {
13
13
  readonly globalsBytes?: Uint8Array<ArrayBuffer>;
14
14
  };
15
15
  }
16
- declare function readImageXObject(dict: PdfDict, raw: Uint8Array<ArrayBuffer>, resolver: PdfObjectResolver, sink: PdfDiagnosticSink): ExtractedPdfImage | undefined;
16
+ declare function readImageXObject(dict: PdfDict, raw: Uint8Array<ArrayBuffer>, resolver: Readonly<PdfObjectResolver>, sink: PdfDiagnosticSink): ExtractedPdfImage | undefined;
17
17
  //#endregion
18
18
  export { ExtractedPdfImage, readImageXObject };
@@ -1,5 +1,5 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.js";
2
- import { n as PdfDict } from "./objects-B7HdMeWS.js";
2
+ import { n as PdfDict } from "./objects-e2RS3-yT.js";
3
3
  import { PdfObjectResolver } from "./interpret.js";
4
4
  //#region src/images-read.d.ts
5
5
  interface ExtractedPdfImage {
@@ -13,6 +13,6 @@ interface ExtractedPdfImage {
13
13
  readonly globalsBytes?: Uint8Array<ArrayBuffer>;
14
14
  };
15
15
  }
16
- declare function readImageXObject(dict: PdfDict, raw: Uint8Array<ArrayBuffer>, resolver: PdfObjectResolver, sink: PdfDiagnosticSink): ExtractedPdfImage | undefined;
16
+ declare function readImageXObject(dict: PdfDict, raw: Uint8Array<ArrayBuffer>, resolver: Readonly<PdfObjectResolver>, sink: PdfDiagnosticSink): ExtractedPdfImage | undefined;
17
17
  //#endregion
18
18
  export { ExtractedPdfImage, readImageXObject };
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_afm_widths = require("./afm-widths-BTu0IDp2.cjs");
2
+ const require_afm_widths = require("./afm-widths-BYiX2L9D.cjs");
3
3
  const require_image_ccitt = require("./image/ccitt.cjs");
4
4
  const require_image_jbig2_errors = require("./image/jbig2-errors.cjs");
5
5
  const require_image_jbig2 = require("./image/jbig2.cjs");
package/dist/index.d.cts CHANGED
@@ -3,7 +3,7 @@ import { NOOP_DIAGNOSTIC_SINK, PdfDiagnostic, PdfDiagnosticSeverity, PdfDiagnost
3
3
  import { LAYOUT_FORMAT_VERSION, LayoutAnnotation, LayoutAnnotationQuad, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachment, LayoutAttachmentSchema, LayoutDestination, LayoutDestinationSchema, LayoutDestinationTarget, LayoutDestinationTargetSchema, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutFormField, LayoutFormFieldSchema, LayoutFormWidget, LayoutFormWidgetSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLink, LayoutInternalLinkSchema, LayoutItem, LayoutItemSchema, LayoutLayer, LayoutLayerSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutOutlineItem, LayoutOutlineItemSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutStructureElement, LayoutStructureElementSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema } from "./layout.cjs";
4
4
  import { t as GlyphInkBounds } from "./glyph-bounds-BV_Z40KS.cjs";
5
5
  import { PdfBytesSchema, pdfCodec } from "./codec.cjs";
6
- import { n as EmbeddedFaceMetrics, r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-DJUn9kMH.cjs";
6
+ import { n as EmbeddedFaceMetrics, r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-DgVBedw6.cjs";
7
7
  import { WinAnsiSubstitution } from "./winansi.cjs";
8
8
  import { PdfEncryptionError, PdfEncryptionOptions, PdfEncryptionPermissions, PdfEncryptionScheme } from "./encrypt-write.cjs";
9
9
  import { FontFace, FontFaceParseError, readFontFace } from "./font-face.cjs";
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import { NOOP_DIAGNOSTIC_SINK, PdfDiagnostic, PdfDiagnosticSeverity, PdfDiagnost
3
3
  import { LAYOUT_FORMAT_VERSION, LayoutAnnotation, LayoutAnnotationQuad, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachment, LayoutAttachmentSchema, LayoutDestination, LayoutDestinationSchema, LayoutDestinationTarget, LayoutDestinationTargetSchema, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutFormField, LayoutFormFieldSchema, LayoutFormWidget, LayoutFormWidgetSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLink, LayoutInternalLinkSchema, LayoutItem, LayoutItemSchema, LayoutLayer, LayoutLayerSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutOutlineItem, LayoutOutlineItemSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutStructureElement, LayoutStructureElementSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema } from "./layout.js";
4
4
  import { t as GlyphInkBounds } from "./glyph-bounds-BV_Z40KS.js";
5
5
  import { PdfBytesSchema, pdfCodec } from "./codec.js";
6
- import { n as EmbeddedFaceMetrics, r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-BRhZfEN2.js";
6
+ import { n as EmbeddedFaceMetrics, r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-ByD7ZiQS.js";
7
7
  import { WinAnsiSubstitution } from "./winansi.js";
8
8
  import { PdfEncryptionError, PdfEncryptionOptions, PdfEncryptionPermissions, PdfEncryptionScheme } from "./encrypt-write.js";
9
9
  import { FontFace, FontFaceParseError, readFontFace } from "./font-face.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as STANDARD_METRICS } from "./afm-widths-De_QMWgC.js";
1
+ import { t as STANDARD_METRICS } from "./afm-widths-blUDDjlI.js";
2
2
  import { decodeCcittFax } from "./image/ccitt.js";
3
3
  import { Jbig2ParseError, Jbig2UnsupportedError } from "./image/jbig2-errors.js";
4
4
  import { decodeJbig2Embedded } from "./image/jbig2.js";
@@ -274,17 +274,33 @@ function classifyShape(subpaths, paint, style) {
274
274
  if (subpaths.length !== 1 || subpath === void 0) return;
275
275
  return detectRect(subpath, paint) ?? detectEllipse(subpath, paint) ?? detectLine(subpath, paint, style);
276
276
  }
277
+ var MarkedContentStack = class {
278
+ #frames;
279
+ constructor(seed = []) {
280
+ this.#frames = [...seed];
281
+ }
282
+ open(frame) {
283
+ this.#frames.push(frame);
284
+ }
285
+ close() {
286
+ this.#frames.pop();
287
+ }
288
+ inScope(key) {
289
+ for (let i = this.#frames.length - 1; i >= 0; i--) {
290
+ const frame = this.#frames[i];
291
+ if (frame !== void 0 && key in frame) return frame[key];
292
+ }
293
+ }
294
+ };
277
295
  function interpretContentStream(bytes, resources, context) {
278
- const items = [];
279
- runContentStream(bytes, resources, {
296
+ return runContentStream(bytes, resources, {
280
297
  ctm: require_matrix.IDENTITY_MATRIX,
281
298
  fillColor: document_schema_js.COLOR_BLACK,
282
299
  strokeColor: document_schema_js.COLOR_BLACK,
283
300
  lineWidth: DEFAULT_LINE_WIDTH_PT,
284
301
  dashArray: [],
285
302
  ...initialTextParameters()
286
- }, context, items, 0, []);
287
- return items;
303
+ }, context, 0, new MarkedContentStack());
288
304
  }
289
305
  function lastPointOf(subpath) {
290
306
  const last = subpath.segments[subpath.segments.length - 1];
@@ -296,19 +312,15 @@ function lastPointOf(subpath) {
296
312
  y: last.yPt
297
313
  };
298
314
  }
299
- function runContentStream(bytes, resources, initialState, context, items, depth, markedContent) {
315
+ function runContentStream(bytes, resources, initialState, context, depth, markedContent) {
316
+ const items = [];
300
317
  const operations = require_content_read.readContentStream(bytes, context.sink);
301
318
  const gsStack = [];
302
319
  let gs = initialState;
303
320
  let text = defaultTextObjectState();
304
321
  let pathSubpaths = [];
305
322
  let currentSubpath;
306
- const inScope = (key) => {
307
- for (let i = markedContent.length - 1; i >= 0; i--) {
308
- const frame = markedContent[i];
309
- if (frame !== void 0 && key in frame) return frame[key];
310
- }
311
- };
323
+ const inScope = (key) => markedContent.inScope(key);
312
324
  const pushItem = (item) => {
313
325
  if (item.kind === "text") {
314
326
  const layer = item.layerName ?? inScope("layerName");
@@ -487,10 +499,10 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
487
499
  ...vertical ? { vertical: true } : {}
488
500
  });
489
501
  };
490
- const showText = (bytes) => {
502
+ const showText = (textBytes) => {
491
503
  showTextArray([{
492
504
  kind: "string",
493
- bytes,
505
+ bytes: textBytes,
494
506
  hex: false
495
507
  }]);
496
508
  };
@@ -541,10 +553,10 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
541
553
  };
542
554
  const formLayer = ownLayer ?? inScope("layerName");
543
555
  const formMcid = require_objects.dictGet(xobj.dict, "StructParents") !== void 0 ? void 0 : inScope("mcid");
544
- runContentStream(decoded.bytes, formResources, formState, context, items, depth + 1, [{
556
+ for (const formItem of runContentStream(decoded.bytes, formResources, formState, context, depth + 1, new MarkedContentStack([{
545
557
  ...formLayer !== void 0 ? { layerName: formLayer } : {},
546
558
  ...formMcid !== void 0 ? { mcid: formMcid } : {}
547
- }]);
559
+ }]))) items.push(formItem);
548
560
  }
549
561
  };
550
562
  for (const token of operations) {
@@ -843,18 +855,19 @@ function runContentStream(bytes, resources, initialState, context, items, depth,
843
855
  ...layerName !== void 0 ? { layerName } : {},
844
856
  ...markedContentScopeProps(props)
845
857
  };
846
- markedContent.push(depth === 0 ? scopeProps : {
858
+ markedContent.open(depth === 0 ? scopeProps : {
847
859
  ...scopeProps,
848
860
  mcid: void 0
849
861
  });
850
862
  break;
851
863
  }
852
864
  case "BMC":
853
- markedContent.push({});
865
+ markedContent.open({});
854
866
  break;
855
- case "EMC": markedContent.pop();
867
+ case "EMC": markedContent.close();
856
868
  }
857
869
  }
870
+ return items;
858
871
  }
859
872
  //#endregion
860
873
  exports.interpretContentStream = interpretContentStream;
@@ -1,6 +1,6 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.cjs";
2
2
  import { r as Matrix } from "./matrix-B7_SBKQ5.cjs";
3
- import { n as PdfDict, r as PdfObject } from "./objects-B7HdMeWS.cjs";
3
+ import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.cjs";
4
4
  import { Color, ContentStrokeStyle } from "document-schema.js";
5
5
  //#region src/interpret.d.ts
6
6
  interface ExtractedTextRun {
@@ -106,12 +106,12 @@ interface GlyphAdvance {
106
106
  readonly vertical?: VerticalGlyphAdvance;
107
107
  }
108
108
  interface FontMetricsPort {
109
- glyphAdvance(fontResourceName: string, resources: PdfDict, codes: Uint8Array<ArrayBuffer>, byteOffset: number): GlyphAdvance | undefined;
110
- isVertical(fontResourceName: string, resources: PdfDict): boolean;
109
+ glyphAdvance: (fontResourceName: string, resources: PdfDict, codes: Uint8Array<ArrayBuffer>, byteOffset: number) => GlyphAdvance | undefined;
110
+ isVertical: (fontResourceName: string, resources: PdfDict) => boolean;
111
111
  }
112
112
  interface PdfObjectResolver {
113
- resolve(obj: PdfObject | undefined): PdfObject | undefined;
114
- resolveDict(obj: PdfObject | undefined): PdfDict | undefined;
113
+ resolve: (obj: PdfObject | undefined) => PdfObject | undefined;
114
+ resolveDict: (obj: PdfObject | undefined) => PdfDict | undefined;
115
115
  }
116
116
  interface InterpretContext {
117
117
  readonly fontMetrics: FontMetricsPort;
@@ -1,6 +1,6 @@
1
1
  import { PdfDiagnosticSink } from "./diagnostics.js";
2
2
  import { r as Matrix } from "./matrix-B7_SBKQ5.js";
3
- import { n as PdfDict, r as PdfObject } from "./objects-B7HdMeWS.js";
3
+ import { n as PdfDict, r as PdfObject } from "./objects-e2RS3-yT.js";
4
4
  import { Color, ContentStrokeStyle } from "document-schema.js";
5
5
  //#region src/interpret.d.ts
6
6
  interface ExtractedTextRun {
@@ -106,12 +106,12 @@ interface GlyphAdvance {
106
106
  readonly vertical?: VerticalGlyphAdvance;
107
107
  }
108
108
  interface FontMetricsPort {
109
- glyphAdvance(fontResourceName: string, resources: PdfDict, codes: Uint8Array<ArrayBuffer>, byteOffset: number): GlyphAdvance | undefined;
110
- isVertical(fontResourceName: string, resources: PdfDict): boolean;
109
+ glyphAdvance: (fontResourceName: string, resources: PdfDict, codes: Uint8Array<ArrayBuffer>, byteOffset: number) => GlyphAdvance | undefined;
110
+ isVertical: (fontResourceName: string, resources: PdfDict) => boolean;
111
111
  }
112
112
  interface PdfObjectResolver {
113
- resolve(obj: PdfObject | undefined): PdfObject | undefined;
114
- resolveDict(obj: PdfObject | undefined): PdfDict | undefined;
113
+ resolve: (obj: PdfObject | undefined) => PdfObject | undefined;
114
+ resolveDict: (obj: PdfObject | undefined) => PdfDict | undefined;
115
115
  }
116
116
  interface InterpretContext {
117
117
  readonly fontMetrics: FontMetricsPort;