pdf-parser.js 5.2.27 → 5.2.28

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 (145) hide show
  1. package/dist/{afm-widths-BYiX2L9D.cjs → afm-widths-BHD2HZIL.cjs} +553 -642
  2. package/dist/{afm-widths-blUDDjlI.js → afm-widths-B_IGbGky.js} +553 -642
  3. package/dist/afm-widths.cjs +1 -1
  4. package/dist/afm-widths.js +1 -1
  5. package/dist/annotations.cjs +5 -3
  6. package/dist/annotations.js +5 -3
  7. package/dist/builtin-encoding.cjs +17 -6
  8. package/dist/builtin-encoding.js +17 -6
  9. package/dist/bytes/crc32.cjs +5 -3
  10. package/dist/bytes/crc32.js +5 -3
  11. package/dist/bytes/flate.cjs +0 -1
  12. package/dist/bytes/flate.js +0 -1
  13. package/dist/cff-bounds.cjs +42 -24
  14. package/dist/cff-bounds.js +42 -24
  15. package/dist/cff.cjs +13 -6
  16. package/dist/cff.js +13 -6
  17. package/dist/cmap-table.cjs +54 -26
  18. package/dist/cmap-table.js +54 -26
  19. package/dist/cmap.cjs +5 -3
  20. package/dist/cmap.js +5 -3
  21. package/dist/content-write.cjs +3 -2
  22. package/dist/content-write.js +3 -2
  23. package/dist/crypto/aes.cjs +76 -55
  24. package/dist/crypto/aes.js +76 -55
  25. package/dist/crypto/md5.cjs +345 -149
  26. package/dist/crypto/md5.js +345 -149
  27. package/dist/crypto/rc4.cjs +5 -4
  28. package/dist/crypto/rc4.js +5 -4
  29. package/dist/crypto/sha2.cjs +92 -43
  30. package/dist/crypto/sha2.js +92 -43
  31. package/dist/embedded-font.cjs +4 -2
  32. package/dist/embedded-font.js +4 -2
  33. package/dist/encoding.cjs +1 -1
  34. package/dist/encoding.js +1 -1
  35. package/dist/encrypt-write.cjs +25 -21
  36. package/dist/encrypt-write.js +25 -21
  37. package/dist/encrypt.cjs +43 -64
  38. package/dist/encrypt.js +43 -64
  39. package/dist/filters.cjs +40 -20
  40. package/dist/filters.js +40 -20
  41. package/dist/font-face.cjs +2 -1
  42. package/dist/font-face.js +2 -1
  43. package/dist/font-read.cjs +12 -6
  44. package/dist/font-read.js +12 -6
  45. package/dist/font-tables.cjs +55 -28
  46. package/dist/font-tables.js +55 -28
  47. package/dist/gdef-table.cjs +6 -3
  48. package/dist/gdef-table.js +6 -3
  49. package/dist/glyf-contours.cjs +3 -1
  50. package/dist/glyf-contours.js +3 -1
  51. package/dist/glyf.cjs +22 -11
  52. package/dist/glyf.js +22 -11
  53. package/dist/gpos-table.cjs +37 -19
  54. package/dist/gpos-table.js +37 -19
  55. package/dist/gsub-table.cjs +28 -17
  56. package/dist/gsub-table.js +28 -17
  57. package/dist/hmtx-table.cjs +5 -3
  58. package/dist/hmtx-table.js +5 -3
  59. package/dist/image/ccitt-encode.cjs +8 -5
  60. package/dist/image/ccitt-encode.js +8 -5
  61. package/dist/image/ccitt.cjs +801 -209
  62. package/dist/image/ccitt.js +801 -209
  63. package/dist/image/jbig2-arith.cjs +340 -306
  64. package/dist/image/jbig2-arith.js +340 -306
  65. package/dist/image/jbig2-bitmap.cjs +8 -5
  66. package/dist/image/jbig2-bitmap.js +8 -5
  67. package/dist/image/jbig2-generic.cjs +240 -69
  68. package/dist/image/jbig2-generic.js +240 -69
  69. package/dist/image/jbig2-text.cjs +4 -2
  70. package/dist/image/jbig2-text.js +4 -2
  71. package/dist/image/jbig2.cjs +69 -31
  72. package/dist/image/jbig2.js +69 -31
  73. package/dist/image/jp2-boxes.cjs +52 -27
  74. package/dist/image/jp2-boxes.js +52 -27
  75. package/dist/image/jpeg-info.cjs +29 -24
  76. package/dist/image/jpeg-info.js +29 -24
  77. package/dist/image/jpeg2000-codestream.cjs +44 -24
  78. package/dist/image/jpeg2000-codestream.js +44 -24
  79. package/dist/image/jpeg2000-dwt.cjs +2 -1
  80. package/dist/image/jpeg2000-dwt.js +2 -1
  81. package/dist/image/jpeg2000-t1.cjs +21 -11
  82. package/dist/image/jpeg2000-t1.js +21 -11
  83. package/dist/image/jpeg2000-t2.cjs +12 -5
  84. package/dist/image/jpeg2000-t2.js +12 -5
  85. package/dist/image/jpeg2000-tagtree.cjs +8 -4
  86. package/dist/image/jpeg2000-tagtree.js +8 -4
  87. package/dist/image/jpeg2000.cjs +11 -6
  88. package/dist/image/jpeg2000.js +11 -6
  89. package/dist/image/png-decode.cjs +62 -39
  90. package/dist/image/png-decode.d.cts +3 -2
  91. package/dist/image/png-decode.d.ts +3 -2
  92. package/dist/image/png-decode.js +62 -39
  93. package/dist/image/png-filter.cjs +23 -15
  94. package/dist/image/png-filter.js +23 -15
  95. package/dist/images-read.cjs +41 -36
  96. package/dist/images-read.js +41 -36
  97. package/dist/index.cjs +1 -1
  98. package/dist/index.js +1 -1
  99. package/dist/interpret.cjs +39 -24
  100. package/dist/interpret.js +39 -24
  101. package/dist/lexer.cjs +86 -51
  102. package/dist/lexer.js +86 -51
  103. package/dist/math-content-write.cjs +9 -5
  104. package/dist/math-content-write.js +9 -5
  105. package/dist/math-font-write.cjs +2 -1
  106. package/dist/math-font-write.js +2 -1
  107. package/dist/math-font.cjs +16 -7
  108. package/dist/math-font.js +16 -7
  109. package/dist/math-table.cjs +25 -13
  110. package/dist/math-table.js +25 -13
  111. package/dist/matrix.cjs +3 -2
  112. package/dist/matrix.js +3 -2
  113. package/dist/measure.cjs +1 -1
  114. package/dist/measure.js +1 -1
  115. package/dist/navigation.cjs +10 -5
  116. package/dist/navigation.js +10 -5
  117. package/dist/ot-layout-common.cjs +4 -2
  118. package/dist/ot-layout-common.js +4 -2
  119. package/dist/parse.cjs +7 -5
  120. package/dist/parse.js +7 -5
  121. package/dist/pdf-text.cjs +5 -2
  122. package/dist/pdf-text.js +5 -2
  123. package/dist/predictors.cjs +14 -9
  124. package/dist/predictors.js +14 -9
  125. package/dist/raster.cjs +30 -19
  126. package/dist/raster.js +30 -19
  127. package/dist/read.cjs +17 -8
  128. package/dist/read.js +17 -8
  129. package/dist/serialize.cjs +6 -2
  130. package/dist/serialize.js +6 -2
  131. package/dist/sfnt-subset.cjs +25 -13
  132. package/dist/sfnt-subset.js +25 -13
  133. package/dist/sfnt.cjs +20 -10
  134. package/dist/sfnt.js +20 -10
  135. package/dist/text-group.cjs +0 -1
  136. package/dist/text-group.js +0 -1
  137. package/dist/tounicode.cjs +4 -2
  138. package/dist/tounicode.js +4 -2
  139. package/dist/winansi.cjs +1 -1
  140. package/dist/winansi.js +1 -1
  141. package/dist/write.cjs +20 -12
  142. package/dist/write.js +20 -12
  143. package/dist/xref.cjs +5 -2
  144. package/dist/xref.js +5 -2
  145. package/package.json +1 -1
@@ -1,292 +1,292 @@
1
1
  //#region src/image/jbig2-arith.ts
2
2
  const QE_STATES = [
3
- [
4
- 22017,
5
- 1,
6
- 1,
7
- 1
8
- ],
9
- [
10
- 13313,
11
- 2,
12
- 6,
13
- 0
14
- ],
15
- [
16
- 6145,
17
- 3,
18
- 9,
19
- 0
20
- ],
21
- [
22
- 2753,
23
- 4,
24
- 12,
25
- 0
26
- ],
27
- [
28
- 1313,
29
- 5,
30
- 29,
31
- 0
32
- ],
33
- [
34
- 545,
35
- 38,
36
- 33,
37
- 0
38
- ],
39
- [
40
- 22017,
41
- 7,
42
- 6,
43
- 1
44
- ],
45
- [
46
- 21505,
47
- 8,
48
- 14,
49
- 0
50
- ],
51
- [
52
- 18433,
53
- 9,
54
- 14,
55
- 0
56
- ],
57
- [
58
- 14337,
59
- 10,
60
- 14,
61
- 0
62
- ],
63
- [
64
- 12289,
65
- 11,
66
- 17,
67
- 0
68
- ],
69
- [
70
- 9217,
71
- 12,
72
- 18,
73
- 0
74
- ],
75
- [
76
- 7169,
77
- 13,
78
- 20,
79
- 0
80
- ],
81
- [
82
- 5633,
83
- 29,
84
- 21,
85
- 0
86
- ],
87
- [
88
- 22017,
89
- 15,
90
- 14,
91
- 1
92
- ],
93
- [
94
- 21505,
95
- 16,
96
- 14,
97
- 0
98
- ],
99
- [
100
- 20737,
101
- 17,
102
- 15,
103
- 0
104
- ],
105
- [
106
- 18433,
107
- 18,
108
- 16,
109
- 0
110
- ],
111
- [
112
- 14337,
113
- 19,
114
- 17,
115
- 0
116
- ],
117
- [
118
- 13313,
119
- 20,
120
- 18,
121
- 0
122
- ],
123
- [
124
- 12289,
125
- 21,
126
- 19,
127
- 0
128
- ],
129
- [
130
- 10241,
131
- 22,
132
- 19,
133
- 0
134
- ],
135
- [
136
- 9217,
137
- 23,
138
- 20,
139
- 0
140
- ],
141
- [
142
- 8705,
143
- 24,
144
- 21,
145
- 0
146
- ],
147
- [
148
- 7169,
149
- 25,
150
- 22,
151
- 0
152
- ],
153
- [
154
- 6145,
155
- 26,
156
- 23,
157
- 0
158
- ],
159
- [
160
- 5633,
161
- 27,
162
- 24,
163
- 0
164
- ],
165
- [
166
- 5121,
167
- 28,
168
- 25,
169
- 0
170
- ],
171
- [
172
- 4609,
173
- 29,
174
- 26,
175
- 0
176
- ],
177
- [
178
- 4353,
179
- 30,
180
- 27,
181
- 0
182
- ],
183
- [
184
- 2753,
185
- 31,
186
- 28,
187
- 0
188
- ],
189
- [
190
- 2497,
191
- 32,
192
- 29,
193
- 0
194
- ],
195
- [
196
- 2209,
197
- 33,
198
- 30,
199
- 0
200
- ],
201
- [
202
- 1313,
203
- 34,
204
- 31,
205
- 0
206
- ],
207
- [
208
- 1089,
209
- 35,
210
- 32,
211
- 0
212
- ],
213
- [
214
- 673,
215
- 36,
216
- 33,
217
- 0
218
- ],
219
- [
220
- 545,
221
- 37,
222
- 34,
223
- 0
224
- ],
225
- [
226
- 321,
227
- 38,
228
- 35,
229
- 0
230
- ],
231
- [
232
- 273,
233
- 39,
234
- 36,
235
- 0
236
- ],
237
- [
238
- 133,
239
- 40,
240
- 37,
241
- 0
242
- ],
243
- [
244
- 73,
245
- 41,
246
- 38,
247
- 0
248
- ],
249
- [
250
- 37,
251
- 42,
252
- 39,
253
- 0
254
- ],
255
- [
256
- 21,
257
- 43,
258
- 40,
259
- 0
260
- ],
261
- [
262
- 9,
263
- 44,
264
- 41,
265
- 0
266
- ],
267
- [
268
- 5,
269
- 45,
270
- 42,
271
- 0
272
- ],
273
- [
274
- 1,
275
- 45,
276
- 43,
277
- 0
278
- ],
279
- [
280
- 22017,
281
- 46,
282
- 46,
283
- 0
284
- ]
3
+ {
4
+ qe: 22017,
5
+ nmps: 1,
6
+ nlps: 1,
7
+ switchMps: 1
8
+ },
9
+ {
10
+ qe: 13313,
11
+ nmps: 2,
12
+ nlps: 6,
13
+ switchMps: 0
14
+ },
15
+ {
16
+ qe: 6145,
17
+ nmps: 3,
18
+ nlps: 9,
19
+ switchMps: 0
20
+ },
21
+ {
22
+ qe: 2753,
23
+ nmps: 4,
24
+ nlps: 12,
25
+ switchMps: 0
26
+ },
27
+ {
28
+ qe: 1313,
29
+ nmps: 5,
30
+ nlps: 29,
31
+ switchMps: 0
32
+ },
33
+ {
34
+ qe: 545,
35
+ nmps: 38,
36
+ nlps: 33,
37
+ switchMps: 0
38
+ },
39
+ {
40
+ qe: 22017,
41
+ nmps: 7,
42
+ nlps: 6,
43
+ switchMps: 1
44
+ },
45
+ {
46
+ qe: 21505,
47
+ nmps: 8,
48
+ nlps: 14,
49
+ switchMps: 0
50
+ },
51
+ {
52
+ qe: 18433,
53
+ nmps: 9,
54
+ nlps: 14,
55
+ switchMps: 0
56
+ },
57
+ {
58
+ qe: 14337,
59
+ nmps: 10,
60
+ nlps: 14,
61
+ switchMps: 0
62
+ },
63
+ {
64
+ qe: 12289,
65
+ nmps: 11,
66
+ nlps: 17,
67
+ switchMps: 0
68
+ },
69
+ {
70
+ qe: 9217,
71
+ nmps: 12,
72
+ nlps: 18,
73
+ switchMps: 0
74
+ },
75
+ {
76
+ qe: 7169,
77
+ nmps: 13,
78
+ nlps: 20,
79
+ switchMps: 0
80
+ },
81
+ {
82
+ qe: 5633,
83
+ nmps: 29,
84
+ nlps: 21,
85
+ switchMps: 0
86
+ },
87
+ {
88
+ qe: 22017,
89
+ nmps: 15,
90
+ nlps: 14,
91
+ switchMps: 1
92
+ },
93
+ {
94
+ qe: 21505,
95
+ nmps: 16,
96
+ nlps: 14,
97
+ switchMps: 0
98
+ },
99
+ {
100
+ qe: 20737,
101
+ nmps: 17,
102
+ nlps: 15,
103
+ switchMps: 0
104
+ },
105
+ {
106
+ qe: 18433,
107
+ nmps: 18,
108
+ nlps: 16,
109
+ switchMps: 0
110
+ },
111
+ {
112
+ qe: 14337,
113
+ nmps: 19,
114
+ nlps: 17,
115
+ switchMps: 0
116
+ },
117
+ {
118
+ qe: 13313,
119
+ nmps: 20,
120
+ nlps: 18,
121
+ switchMps: 0
122
+ },
123
+ {
124
+ qe: 12289,
125
+ nmps: 21,
126
+ nlps: 19,
127
+ switchMps: 0
128
+ },
129
+ {
130
+ qe: 10241,
131
+ nmps: 22,
132
+ nlps: 19,
133
+ switchMps: 0
134
+ },
135
+ {
136
+ qe: 9217,
137
+ nmps: 23,
138
+ nlps: 20,
139
+ switchMps: 0
140
+ },
141
+ {
142
+ qe: 8705,
143
+ nmps: 24,
144
+ nlps: 21,
145
+ switchMps: 0
146
+ },
147
+ {
148
+ qe: 7169,
149
+ nmps: 25,
150
+ nlps: 22,
151
+ switchMps: 0
152
+ },
153
+ {
154
+ qe: 6145,
155
+ nmps: 26,
156
+ nlps: 23,
157
+ switchMps: 0
158
+ },
159
+ {
160
+ qe: 5633,
161
+ nmps: 27,
162
+ nlps: 24,
163
+ switchMps: 0
164
+ },
165
+ {
166
+ qe: 5121,
167
+ nmps: 28,
168
+ nlps: 25,
169
+ switchMps: 0
170
+ },
171
+ {
172
+ qe: 4609,
173
+ nmps: 29,
174
+ nlps: 26,
175
+ switchMps: 0
176
+ },
177
+ {
178
+ qe: 4353,
179
+ nmps: 30,
180
+ nlps: 27,
181
+ switchMps: 0
182
+ },
183
+ {
184
+ qe: 2753,
185
+ nmps: 31,
186
+ nlps: 28,
187
+ switchMps: 0
188
+ },
189
+ {
190
+ qe: 2497,
191
+ nmps: 32,
192
+ nlps: 29,
193
+ switchMps: 0
194
+ },
195
+ {
196
+ qe: 2209,
197
+ nmps: 33,
198
+ nlps: 30,
199
+ switchMps: 0
200
+ },
201
+ {
202
+ qe: 1313,
203
+ nmps: 34,
204
+ nlps: 31,
205
+ switchMps: 0
206
+ },
207
+ {
208
+ qe: 1089,
209
+ nmps: 35,
210
+ nlps: 32,
211
+ switchMps: 0
212
+ },
213
+ {
214
+ qe: 673,
215
+ nmps: 36,
216
+ nlps: 33,
217
+ switchMps: 0
218
+ },
219
+ {
220
+ qe: 545,
221
+ nmps: 37,
222
+ nlps: 34,
223
+ switchMps: 0
224
+ },
225
+ {
226
+ qe: 321,
227
+ nmps: 38,
228
+ nlps: 35,
229
+ switchMps: 0
230
+ },
231
+ {
232
+ qe: 273,
233
+ nmps: 39,
234
+ nlps: 36,
235
+ switchMps: 0
236
+ },
237
+ {
238
+ qe: 133,
239
+ nmps: 40,
240
+ nlps: 37,
241
+ switchMps: 0
242
+ },
243
+ {
244
+ qe: 73,
245
+ nmps: 41,
246
+ nlps: 38,
247
+ switchMps: 0
248
+ },
249
+ {
250
+ qe: 37,
251
+ nmps: 42,
252
+ nlps: 39,
253
+ switchMps: 0
254
+ },
255
+ {
256
+ qe: 21,
257
+ nmps: 43,
258
+ nlps: 40,
259
+ switchMps: 0
260
+ },
261
+ {
262
+ qe: 9,
263
+ nmps: 44,
264
+ nlps: 41,
265
+ switchMps: 0
266
+ },
267
+ {
268
+ qe: 5,
269
+ nmps: 45,
270
+ nlps: 42,
271
+ switchMps: 0
272
+ },
273
+ {
274
+ qe: 1,
275
+ nmps: 45,
276
+ nlps: 43,
277
+ switchMps: 0
278
+ },
279
+ {
280
+ qe: 22017,
281
+ nmps: 46,
282
+ nlps: 46,
283
+ switchMps: 0
284
+ }
285
285
  ];
286
- const QE_VALUE = Uint16Array.from(QE_STATES, (row) => row[0]);
287
- const QE_NMPS = Uint8Array.from(QE_STATES, (row) => row[1]);
288
- const QE_NLPS = Uint8Array.from(QE_STATES, (row) => row[2]);
289
- const QE_SWITCH = Uint8Array.from(QE_STATES, (row) => row[3]);
286
+ const QE_VALUE = Uint16Array.from(QE_STATES, (row) => row.qe);
287
+ const QE_NMPS = Uint8Array.from(QE_STATES, (row) => row.nmps);
288
+ const QE_NLPS = Uint8Array.from(QE_STATES, (row) => row.nlps);
289
+ const QE_SWITCH = Uint8Array.from(QE_STATES, (row) => row.switchMps);
290
290
  function createArithContexts(contextBits) {
291
291
  return new Uint8Array(1 << contextBits);
292
292
  }
@@ -294,6 +294,13 @@ const A_INITIAL = 32768;
294
294
  const C_INITIAL_SHIFT = 16;
295
295
  const INITDEC_C_SHIFT = 7;
296
296
  const PAST_END_BYTE = 255;
297
+ const MARKER_FOLLOWER_THRESHOLD = 143;
298
+ const MARKER_C_INCREMENT = 65280;
299
+ const STUFFED_BYTE_SHIFT = 9;
300
+ const NORMAL_BYTE_SHIFT = 8;
301
+ const STUFFED_BYTE_CT_RELOAD = 7;
302
+ const A_REGISTER_MASK = 65535;
303
+ const C_HIGH_HALF_SHIFT = 16;
297
304
  var MqDecoder = class {
298
305
  data;
299
306
  start;
@@ -317,25 +324,25 @@ var MqDecoder = class {
317
324
  return index >= this.start && index < this.end ? this.data[index] ?? PAST_END_BYTE : PAST_END_BYTE;
318
325
  }
319
326
  byteIn() {
320
- if (this.byteAt(this.bp) === 255) {
321
- if (this.byteAt(this.bp + 1) > 143) {
322
- this.c = this.c + 65280 >>> 0;
323
- this.ct = 8;
327
+ if (this.byteAt(this.bp) === PAST_END_BYTE) {
328
+ if (this.byteAt(this.bp + 1) > MARKER_FOLLOWER_THRESHOLD) {
329
+ this.c = this.c + MARKER_C_INCREMENT >>> 0;
330
+ this.ct = NORMAL_BYTE_SHIFT;
324
331
  return;
325
332
  }
326
333
  this.bp++;
327
- this.c = this.c + (this.byteAt(this.bp) << 9) >>> 0;
328
- this.ct = 7;
334
+ this.c = this.c + (this.byteAt(this.bp) << STUFFED_BYTE_SHIFT) >>> 0;
335
+ this.ct = STUFFED_BYTE_CT_RELOAD;
329
336
  return;
330
337
  }
331
338
  this.bp++;
332
- this.c = this.c + (this.byteAt(this.bp) << 8) >>> 0;
333
- this.ct = 8;
339
+ this.c = this.c + (this.byteAt(this.bp) << NORMAL_BYTE_SHIFT) >>> 0;
340
+ this.ct = NORMAL_BYTE_SHIFT;
334
341
  }
335
342
  renormalise() {
336
343
  do {
337
344
  if (this.ct === 0) this.byteIn();
338
- this.a = this.a << 1 & 65535;
345
+ this.a = this.a << 1 & A_REGISTER_MASK;
339
346
  this.c = this.c << 1 >>> 0;
340
347
  this.ct--;
341
348
  } while ((this.a & A_INITIAL) === 0);
@@ -347,7 +354,7 @@ var MqDecoder = class {
347
354
  const qe = QE_VALUE[index] ?? 0;
348
355
  this.a -= qe;
349
356
  let decision;
350
- if (this.c >>> 16 < qe) {
357
+ if (this.c >>> C_HIGH_HALF_SHIFT < qe) {
351
358
  if (this.a < qe) {
352
359
  decision = mps;
353
360
  index = QE_NMPS[index] ?? 0;
@@ -358,7 +365,7 @@ var MqDecoder = class {
358
365
  }
359
366
  this.a = qe;
360
367
  } else {
361
- this.c = this.c - (qe << 16) >>> 0;
368
+ this.c = this.c - (qe << C_HIGH_HALF_SHIFT) >>> 0;
362
369
  if ((this.a & A_INITIAL) !== 0) return mps;
363
370
  if (this.a < qe) {
364
371
  decision = 1 - mps;
@@ -379,18 +386,39 @@ function createIntegerContexts() {
379
386
  return createArithContexts(INTEGER_CONTEXT_BITS);
380
387
  }
381
388
  const INTEGER_RANGES = [
382
- [2, 0],
383
- [4, 4],
384
- [6, 20],
385
- [8, 84],
386
- [12, 340],
387
- [32, 4436]
389
+ {
390
+ bits: 2,
391
+ offset: 0
392
+ },
393
+ {
394
+ bits: 4,
395
+ offset: 4
396
+ },
397
+ {
398
+ bits: 6,
399
+ offset: 20
400
+ },
401
+ {
402
+ bits: 8,
403
+ offset: 84
404
+ },
405
+ {
406
+ bits: 12,
407
+ offset: 340
408
+ },
409
+ {
410
+ bits: 32,
411
+ offset: 4436
412
+ }
388
413
  ];
389
414
  function decodeInteger(mq, contexts) {
415
+ const PREV_SATURATION_THRESHOLD = 256;
416
+ const PREV_REGISTER_MASK = 511;
417
+ const PREV_SATURATION_HIGH_BIT = 256;
390
418
  let prev = 1;
391
419
  const nextBit = () => {
392
420
  const bit = mq.decode(contexts, prev);
393
- prev = prev < 256 ? prev << 1 | bit : (prev << 1 | bit) & 511 | 256;
421
+ prev = prev < PREV_SATURATION_THRESHOLD ? prev << 1 | bit : (prev << 1 | bit) & PREV_REGISTER_MASK | PREV_SATURATION_HIGH_BIT;
394
422
  return bit;
395
423
  };
396
424
  const readBits = (count) => {
@@ -402,13 +430,19 @@ function decodeInteger(mq, contexts) {
402
430
  let magnitude = 0;
403
431
  let matched = false;
404
432
  for (let i = 0; i < INTEGER_RANGES.length - 1; i++) if (nextBit() === 0) {
405
- const [bits, offset] = INTEGER_RANGES[i] ?? [0, 0];
433
+ const { bits, offset } = INTEGER_RANGES[i] ?? {
434
+ bits: 0,
435
+ offset: 0
436
+ };
406
437
  magnitude = readBits(bits) + offset;
407
438
  matched = true;
408
439
  break;
409
440
  }
410
441
  if (!matched) {
411
- const [bits, offset] = INTEGER_RANGES[INTEGER_RANGES.length - 1] ?? [0, 0];
442
+ const { bits, offset } = INTEGER_RANGES[INTEGER_RANGES.length - 1] ?? {
443
+ bits: 0,
444
+ offset: 0
445
+ };
412
446
  magnitude = readBits(bits) + offset;
413
447
  }
414
448
  if (sign === 1) return magnitude === 0 ? void 0 : -magnitude;