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