@loaders.gl/polyfills 4.0.0-alpha.5 → 4.0.0-alpha.6

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 (170) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/dist.min.js +268 -55
  3. package/dist/es5/bundle.js +6 -0
  4. package/dist/es5/bundle.js.map +1 -0
  5. package/dist/es5/index.js +103 -0
  6. package/dist/es5/index.js.map +1 -0
  7. package/dist/es5/lib/encoding-indexes.js +37 -0
  8. package/dist/es5/lib/encoding-indexes.js.map +1 -0
  9. package/dist/es5/lib/encoding.js +1214 -0
  10. package/dist/es5/lib/encoding.js.map +1 -0
  11. package/dist/es5/libs/encoding-indexes-asian.js +13 -0
  12. package/dist/es5/node/buffer/btoa.node.js +14 -0
  13. package/dist/es5/node/buffer/btoa.node.js.map +1 -0
  14. package/dist/es5/node/buffer/to-array-buffer.node.js +14 -0
  15. package/dist/es5/node/buffer/to-array-buffer.node.js.map +1 -0
  16. package/dist/es5/node/fetch/fetch-file.node.js +83 -0
  17. package/dist/es5/node/fetch/fetch-file.node.js.map +1 -0
  18. package/dist/es5/node/fetch/fetch.node.js +194 -0
  19. package/dist/es5/node/fetch/fetch.node.js.map +1 -0
  20. package/dist/es5/node/fetch/headers.node.js +151 -0
  21. package/dist/es5/node/fetch/headers.node.js.map +1 -0
  22. package/dist/es5/node/fetch/response.node.js +182 -0
  23. package/dist/es5/node/fetch/response.node.js.map +1 -0
  24. package/dist/es5/node/fetch/utils/decode-data-uri.node.js +58 -0
  25. package/dist/es5/node/fetch/utils/decode-data-uri.node.js.map +1 -0
  26. package/dist/es5/node/fetch/utils/stream-utils.node.js +92 -0
  27. package/dist/es5/node/fetch/utils/stream-utils.node.js.map +1 -0
  28. package/dist/es5/node/file/blob-stream-controller.js +90 -0
  29. package/dist/es5/node/file/blob-stream-controller.js.map +1 -0
  30. package/dist/es5/node/file/blob-stream.js +64 -0
  31. package/dist/es5/node/file/blob-stream.js.map +1 -0
  32. package/dist/es5/node/file/blob.js +212 -0
  33. package/dist/es5/node/file/blob.js.map +1 -0
  34. package/dist/es5/node/file/file-reader.js +153 -0
  35. package/dist/es5/node/file/file-reader.js.map +1 -0
  36. package/dist/es5/node/file/file.js +44 -0
  37. package/dist/es5/node/file/file.js.map +1 -0
  38. package/dist/es5/node/file/install-file-polyfills.js +25 -0
  39. package/dist/es5/node/file/install-file-polyfills.js.map +1 -0
  40. package/dist/es5/node/file/readable-stream.js +27 -0
  41. package/dist/es5/node/file/readable-stream.js.map +1 -0
  42. package/dist/es5/node/images/encode-image.node.js +30 -0
  43. package/dist/es5/node/images/encode-image.node.js.map +1 -0
  44. package/dist/es5/node/images/parse-image.node.js +64 -0
  45. package/dist/es5/node/images/parse-image.node.js.map +1 -0
  46. package/dist/es5/promise/all-settled.js +28 -0
  47. package/dist/es5/promise/all-settled.js.map +1 -0
  48. package/dist/es5/utils/assert.js +12 -0
  49. package/dist/es5/utils/assert.js.map +1 -0
  50. package/dist/es5/utils/globals.js +18 -0
  51. package/dist/es5/utils/globals.js.map +1 -0
  52. package/dist/esm/bundle.js +4 -0
  53. package/dist/esm/bundle.js.map +1 -0
  54. package/dist/esm/index.js +54 -0
  55. package/dist/esm/index.js.map +1 -0
  56. package/dist/esm/lib/encoding-indexes.js +30 -0
  57. package/dist/esm/lib/encoding-indexes.js.map +1 -0
  58. package/dist/esm/lib/encoding.js +1206 -0
  59. package/dist/esm/lib/encoding.js.map +1 -0
  60. package/dist/esm/libs/encoding-indexes-asian.js +13 -0
  61. package/dist/esm/node/buffer/btoa.node.js +7 -0
  62. package/dist/esm/node/buffer/btoa.node.js.map +1 -0
  63. package/dist/esm/node/buffer/to-array-buffer.node.js +8 -0
  64. package/dist/esm/node/buffer/to-array-buffer.node.js.map +1 -0
  65. package/dist/esm/node/fetch/fetch-file.node.js +50 -0
  66. package/dist/esm/node/fetch/fetch-file.node.js.map +1 -0
  67. package/dist/esm/node/fetch/fetch.node.js +126 -0
  68. package/dist/esm/node/fetch/fetch.node.js.map +1 -0
  69. package/dist/esm/node/fetch/headers.node.js +102 -0
  70. package/dist/esm/node/fetch/headers.node.js.map +1 -0
  71. package/dist/esm/node/fetch/response.node.js +67 -0
  72. package/dist/esm/node/fetch/response.node.js.map +1 -0
  73. package/dist/esm/node/fetch/utils/decode-data-uri.node.js +45 -0
  74. package/dist/esm/node/fetch/utils/decode-data-uri.node.js.map +1 -0
  75. package/dist/esm/node/fetch/utils/stream-utils.node.js +43 -0
  76. package/dist/esm/node/fetch/utils/stream-utils.node.js.map +1 -0
  77. package/dist/esm/node/file/blob-stream-controller.js +44 -0
  78. package/dist/esm/node/file/blob-stream-controller.js.map +1 -0
  79. package/dist/esm/node/file/blob-stream.js +20 -0
  80. package/dist/esm/node/file/blob-stream.js.map +1 -0
  81. package/dist/esm/node/file/blob.js +120 -0
  82. package/dist/esm/node/file/blob.js.map +1 -0
  83. package/dist/esm/node/file/file-reader.js +60 -0
  84. package/dist/esm/node/file/file-reader.js.map +1 -0
  85. package/dist/esm/node/file/file.js +19 -0
  86. package/dist/esm/node/file/file.js.map +1 -0
  87. package/dist/esm/node/file/install-file-polyfills.js +19 -0
  88. package/dist/esm/node/file/install-file-polyfills.js.map +1 -0
  89. package/dist/esm/node/file/readable-stream.js +4 -0
  90. package/dist/esm/node/file/readable-stream.js.map +1 -0
  91. package/dist/esm/node/images/encode-image.node.js +20 -0
  92. package/dist/esm/node/images/encode-image.node.js.map +1 -0
  93. package/dist/esm/node/images/parse-image.node.js +29 -0
  94. package/dist/esm/node/images/parse-image.node.js.map +1 -0
  95. package/dist/esm/promise/all-settled.js +19 -0
  96. package/dist/esm/promise/all-settled.js.map +1 -0
  97. package/dist/esm/utils/assert.js +6 -0
  98. package/dist/esm/utils/assert.js.map +1 -0
  99. package/dist/esm/utils/globals.js +9 -0
  100. package/dist/esm/utils/globals.js.map +1 -0
  101. package/dist/index.d.ts +2 -0
  102. package/dist/index.d.ts.map +1 -1
  103. package/dist/index.js +90 -49
  104. package/dist/lib/encoding-indexes.js +34 -29
  105. package/dist/lib/encoding.js +2610 -1281
  106. package/dist/libs/encoding-indexes-asian.d.ts +1 -1
  107. package/dist/libs/encoding-indexes-asian.js +9 -8
  108. package/dist/node/buffer/btoa.node.js +12 -5
  109. package/dist/node/buffer/to-array-buffer.node.js +11 -8
  110. package/dist/node/fetch/fetch-file.node.d.ts +4 -0
  111. package/dist/node/fetch/fetch-file.node.d.ts.map +1 -0
  112. package/dist/node/fetch/fetch-file.node.js +51 -0
  113. package/dist/node/fetch/fetch.node.d.ts +6 -1
  114. package/dist/node/fetch/fetch.node.d.ts.map +1 -1
  115. package/dist/node/fetch/fetch.node.js +128 -111
  116. package/dist/node/fetch/headers.node.d.ts +1 -1
  117. package/dist/node/fetch/headers.node.d.ts.map +1 -1
  118. package/dist/node/fetch/headers.node.js +95 -114
  119. package/dist/node/fetch/response.node.d.ts +2 -2
  120. package/dist/node/fetch/response.node.d.ts.map +1 -1
  121. package/dist/node/fetch/response.node.js +72 -84
  122. package/dist/node/fetch/utils/decode-data-uri.node.js +63 -53
  123. package/dist/node/fetch/utils/stream-utils.node.d.ts +8 -1
  124. package/dist/node/fetch/utils/stream-utils.node.d.ts.map +1 -1
  125. package/dist/node/fetch/utils/stream-utils.node.js +68 -93
  126. package/dist/node/file/blob-stream-controller.js +59 -52
  127. package/dist/node/file/blob-stream.js +36 -25
  128. package/dist/node/file/blob.js +151 -131
  129. package/dist/node/file/file-reader.js +28 -77
  130. package/dist/node/file/file.js +36 -25
  131. package/dist/node/file/install-file-polyfills.js +26 -21
  132. package/dist/node/file/readable-stream.js +10 -3
  133. package/dist/node/images/encode-image.node.js +38 -17
  134. package/dist/node/images/parse-image.node.d.ts +3 -1
  135. package/dist/node/images/parse-image.node.d.ts.map +1 -1
  136. package/dist/node/images/parse-image.node.js +40 -19
  137. package/dist/promise/all-settled.js +22 -17
  138. package/dist/utils/assert.js +8 -5
  139. package/dist/utils/globals.js +34 -7
  140. package/package.json +5 -4
  141. package/src/index.ts +7 -4
  142. package/src/node/fetch/fetch-file.node.ts +51 -0
  143. package/src/node/fetch/fetch.node.ts +64 -30
  144. package/src/node/fetch/headers.node.ts +1 -1
  145. package/src/node/fetch/response.node.ts +4 -2
  146. package/src/node/fetch/utils/stream-utils.node.ts +10 -58
  147. package/src/node/images/parse-image.node.ts +35 -20
  148. package/dist/bundle.js.map +0 -1
  149. package/dist/index.js.map +0 -1
  150. package/dist/lib/encoding-indexes.js.map +0 -1
  151. package/dist/lib/encoding.js.map +0 -1
  152. package/dist/node/buffer/btoa.node.js.map +0 -1
  153. package/dist/node/buffer/to-array-buffer.node.js.map +0 -1
  154. package/dist/node/fetch/fetch.node.js.map +0 -1
  155. package/dist/node/fetch/headers.node.js.map +0 -1
  156. package/dist/node/fetch/response.node.js.map +0 -1
  157. package/dist/node/fetch/utils/decode-data-uri.node.js.map +0 -1
  158. package/dist/node/fetch/utils/stream-utils.node.js.map +0 -1
  159. package/dist/node/file/blob-stream-controller.js.map +0 -1
  160. package/dist/node/file/blob-stream.js.map +0 -1
  161. package/dist/node/file/blob.js.map +0 -1
  162. package/dist/node/file/file-reader.js.map +0 -1
  163. package/dist/node/file/file.js.map +0 -1
  164. package/dist/node/file/install-file-polyfills.js.map +0 -1
  165. package/dist/node/file/readable-stream.js.map +0 -1
  166. package/dist/node/images/encode-image.node.js.map +0 -1
  167. package/dist/node/images/parse-image.node.js.map +0 -1
  168. package/dist/promise/all-settled.js.map +0 -1
  169. package/dist/utils/assert.js.map +0 -1
  170. package/dist/utils/globals.js.map +0 -1
@@ -0,0 +1,1214 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.TextDecoder = TextDecoder;
8
+ exports.TextEncoder = TextEncoder;
9
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
10
+ var _encodingIndexes = _interopRequireDefault(require("./encoding-indexes"));
11
+ global['encoding-indexes'] = _encodingIndexes.default || {};
12
+ function inRange(a, min, max) {
13
+ return min <= a && a <= max;
14
+ }
15
+ function includes(array, item) {
16
+ return array.indexOf(item) !== -1;
17
+ }
18
+ var floor = Math.floor;
19
+ function ToDictionary(o) {
20
+ if (o === undefined) return {};
21
+ if (o === Object(o)) return o;
22
+ throw TypeError('Could not convert argument to dictionary');
23
+ }
24
+ function stringToCodePoints(string) {
25
+ var s = String(string);
26
+ var n = s.length;
27
+ var i = 0;
28
+ var u = [];
29
+ while (i < n) {
30
+ var c = s.charCodeAt(i);
31
+ if (c < 0xd800 || c > 0xdfff) {
32
+ u.push(c);
33
+ } else if (0xdc00 <= c && c <= 0xdfff) {
34
+ u.push(0xfffd);
35
+ } else if (0xd800 <= c && c <= 0xdbff) {
36
+ if (i === n - 1) {
37
+ u.push(0xfffd);
38
+ } else {
39
+ var d = s.charCodeAt(i + 1);
40
+ if (0xdc00 <= d && d <= 0xdfff) {
41
+ var a = c & 0x3ff;
42
+ var b = d & 0x3ff;
43
+ u.push(0x10000 + (a << 10) + b);
44
+ i += 1;
45
+ } else {
46
+ u.push(0xfffd);
47
+ }
48
+ }
49
+ }
50
+ i += 1;
51
+ }
52
+ return u;
53
+ }
54
+ function codePointsToString(code_points) {
55
+ var s = '';
56
+ for (var i = 0; i < code_points.length; ++i) {
57
+ var cp = code_points[i];
58
+ if (cp <= 0xffff) {
59
+ s += String.fromCharCode(cp);
60
+ } else {
61
+ cp -= 0x10000;
62
+ s += String.fromCharCode((cp >> 10) + 0xd800, (cp & 0x3ff) + 0xdc00);
63
+ }
64
+ }
65
+ return s;
66
+ }
67
+ function isASCIIByte(a) {
68
+ return 0x00 <= a && a <= 0x7f;
69
+ }
70
+ var isASCIICodePoint = isASCIIByte;
71
+ var end_of_stream = -1;
72
+ function Stream(tokens) {
73
+ this.tokens = [].slice.call(tokens);
74
+ this.tokens.reverse();
75
+ }
76
+ Stream.prototype = {
77
+ endOfStream: function endOfStream() {
78
+ return !this.tokens.length;
79
+ },
80
+ read: function read() {
81
+ if (!this.tokens.length) return end_of_stream;
82
+ return this.tokens.pop();
83
+ },
84
+ prepend: function prepend(token) {
85
+ if (Array.isArray(token)) {
86
+ var tokens = token;
87
+ while (tokens.length) this.tokens.push(tokens.pop());
88
+ } else {
89
+ this.tokens.push(token);
90
+ }
91
+ },
92
+ push: function push(token) {
93
+ if (Array.isArray(token)) {
94
+ var tokens = token;
95
+ while (tokens.length) this.tokens.unshift(tokens.shift());
96
+ } else {
97
+ this.tokens.unshift(token);
98
+ }
99
+ }
100
+ };
101
+ var finished = -1;
102
+ function decoderError(fatal, opt_code_point) {
103
+ if (fatal) throw TypeError('Decoder error');
104
+ return opt_code_point || 0xfffd;
105
+ }
106
+ function encoderError(code_point) {
107
+ throw TypeError('The code point ' + code_point + ' could not be encoded.');
108
+ }
109
+ function Decoder() {}
110
+ Decoder.prototype = {
111
+ handler: function handler(stream, bite) {}
112
+ };
113
+ function Encoder() {}
114
+ Encoder.prototype = {
115
+ handler: function handler(stream, code_point) {}
116
+ };
117
+ function getEncoding(label) {
118
+ label = String(label).trim().toLowerCase();
119
+ if (Object.prototype.hasOwnProperty.call(label_to_encoding, label)) {
120
+ return label_to_encoding[label];
121
+ }
122
+ return null;
123
+ }
124
+ var encodings = [{
125
+ encodings: [{
126
+ labels: ['unicode-1-1-utf-8', 'utf-8', 'utf8'],
127
+ name: 'UTF-8'
128
+ }],
129
+ heading: 'The Encoding'
130
+ }, {
131
+ encodings: [{
132
+ labels: ['866', 'cp866', 'csibm866', 'ibm866'],
133
+ name: 'IBM866'
134
+ }, {
135
+ labels: ['csisolatin2', 'iso-8859-2', 'iso-ir-101', 'iso8859-2', 'iso88592', 'iso_8859-2', 'iso_8859-2:1987', 'l2', 'latin2'],
136
+ name: 'ISO-8859-2'
137
+ }, {
138
+ labels: ['csisolatin3', 'iso-8859-3', 'iso-ir-109', 'iso8859-3', 'iso88593', 'iso_8859-3', 'iso_8859-3:1988', 'l3', 'latin3'],
139
+ name: 'ISO-8859-3'
140
+ }, {
141
+ labels: ['csisolatin4', 'iso-8859-4', 'iso-ir-110', 'iso8859-4', 'iso88594', 'iso_8859-4', 'iso_8859-4:1988', 'l4', 'latin4'],
142
+ name: 'ISO-8859-4'
143
+ }, {
144
+ labels: ['csisolatincyrillic', 'cyrillic', 'iso-8859-5', 'iso-ir-144', 'iso8859-5', 'iso88595', 'iso_8859-5', 'iso_8859-5:1988'],
145
+ name: 'ISO-8859-5'
146
+ }, {
147
+ labels: ['arabic', 'asmo-708', 'csiso88596e', 'csiso88596i', 'csisolatinarabic', 'ecma-114', 'iso-8859-6', 'iso-8859-6-e', 'iso-8859-6-i', 'iso-ir-127', 'iso8859-6', 'iso88596', 'iso_8859-6', 'iso_8859-6:1987'],
148
+ name: 'ISO-8859-6'
149
+ }, {
150
+ labels: ['csisolatingreek', 'ecma-118', 'elot_928', 'greek', 'greek8', 'iso-8859-7', 'iso-ir-126', 'iso8859-7', 'iso88597', 'iso_8859-7', 'iso_8859-7:1987', 'sun_eu_greek'],
151
+ name: 'ISO-8859-7'
152
+ }, {
153
+ labels: ['csiso88598e', 'csisolatinhebrew', 'hebrew', 'iso-8859-8', 'iso-8859-8-e', 'iso-ir-138', 'iso8859-8', 'iso88598', 'iso_8859-8', 'iso_8859-8:1988', 'visual'],
154
+ name: 'ISO-8859-8'
155
+ }, {
156
+ labels: ['csiso88598i', 'iso-8859-8-i', 'logical'],
157
+ name: 'ISO-8859-8-I'
158
+ }, {
159
+ labels: ['csisolatin6', 'iso-8859-10', 'iso-ir-157', 'iso8859-10', 'iso885910', 'l6', 'latin6'],
160
+ name: 'ISO-8859-10'
161
+ }, {
162
+ labels: ['iso-8859-13', 'iso8859-13', 'iso885913'],
163
+ name: 'ISO-8859-13'
164
+ }, {
165
+ labels: ['iso-8859-14', 'iso8859-14', 'iso885914'],
166
+ name: 'ISO-8859-14'
167
+ }, {
168
+ labels: ['csisolatin9', 'iso-8859-15', 'iso8859-15', 'iso885915', 'iso_8859-15', 'l9'],
169
+ name: 'ISO-8859-15'
170
+ }, {
171
+ labels: ['iso-8859-16'],
172
+ name: 'ISO-8859-16'
173
+ }, {
174
+ labels: ['cskoi8r', 'koi', 'koi8', 'koi8-r', 'koi8_r'],
175
+ name: 'KOI8-R'
176
+ }, {
177
+ labels: ['koi8-ru', 'koi8-u'],
178
+ name: 'KOI8-U'
179
+ }, {
180
+ labels: ['csmacintosh', 'mac', 'macintosh', 'x-mac-roman'],
181
+ name: 'macintosh'
182
+ }, {
183
+ labels: ['dos-874', 'iso-8859-11', 'iso8859-11', 'iso885911', 'tis-620', 'windows-874'],
184
+ name: 'windows-874'
185
+ }, {
186
+ labels: ['cp1250', 'windows-1250', 'x-cp1250'],
187
+ name: 'windows-1250'
188
+ }, {
189
+ labels: ['cp1251', 'windows-1251', 'x-cp1251'],
190
+ name: 'windows-1251'
191
+ }, {
192
+ labels: ['ansi_x3.4-1968', 'ascii', 'cp1252', 'cp819', 'csisolatin1', 'ibm819', 'iso-8859-1', 'iso-ir-100', 'iso8859-1', 'iso88591', 'iso_8859-1', 'iso_8859-1:1987', 'l1', 'latin1', 'us-ascii', 'windows-1252', 'x-cp1252'],
193
+ name: 'windows-1252'
194
+ }, {
195
+ labels: ['cp1253', 'windows-1253', 'x-cp1253'],
196
+ name: 'windows-1253'
197
+ }, {
198
+ labels: ['cp1254', 'csisolatin5', 'iso-8859-9', 'iso-ir-148', 'iso8859-9', 'iso88599', 'iso_8859-9', 'iso_8859-9:1989', 'l5', 'latin5', 'windows-1254', 'x-cp1254'],
199
+ name: 'windows-1254'
200
+ }, {
201
+ labels: ['cp1255', 'windows-1255', 'x-cp1255'],
202
+ name: 'windows-1255'
203
+ }, {
204
+ labels: ['cp1256', 'windows-1256', 'x-cp1256'],
205
+ name: 'windows-1256'
206
+ }, {
207
+ labels: ['cp1257', 'windows-1257', 'x-cp1257'],
208
+ name: 'windows-1257'
209
+ }, {
210
+ labels: ['cp1258', 'windows-1258', 'x-cp1258'],
211
+ name: 'windows-1258'
212
+ }, {
213
+ labels: ['x-mac-cyrillic', 'x-mac-ukrainian'],
214
+ name: 'x-mac-cyrillic'
215
+ }],
216
+ heading: 'Legacy single-byte encodings'
217
+ }, {
218
+ encodings: [{
219
+ labels: ['chinese', 'csgb2312', 'csiso58gb231280', 'gb2312', 'gb_2312', 'gb_2312-80', 'gbk', 'iso-ir-58', 'x-gbk'],
220
+ name: 'GBK'
221
+ }, {
222
+ labels: ['gb18030'],
223
+ name: 'gb18030'
224
+ }],
225
+ heading: 'Legacy multi-byte Chinese (simplified) encodings'
226
+ }, {
227
+ encodings: [{
228
+ labels: ['big5', 'big5-hkscs', 'cn-big5', 'csbig5', 'x-x-big5'],
229
+ name: 'Big5'
230
+ }],
231
+ heading: 'Legacy multi-byte Chinese (traditional) encodings'
232
+ }, {
233
+ encodings: [{
234
+ labels: ['cseucpkdfmtjapanese', 'euc-jp', 'x-euc-jp'],
235
+ name: 'EUC-JP'
236
+ }, {
237
+ labels: ['csiso2022jp', 'iso-2022-jp'],
238
+ name: 'ISO-2022-JP'
239
+ }, {
240
+ labels: ['csshiftjis', 'ms932', 'ms_kanji', 'shift-jis', 'shift_jis', 'sjis', 'windows-31j', 'x-sjis'],
241
+ name: 'Shift_JIS'
242
+ }],
243
+ heading: 'Legacy multi-byte Japanese encodings'
244
+ }, {
245
+ encodings: [{
246
+ labels: ['cseuckr', 'csksc56011987', 'euc-kr', 'iso-ir-149', 'korean', 'ks_c_5601-1987', 'ks_c_5601-1989', 'ksc5601', 'ksc_5601', 'windows-949'],
247
+ name: 'EUC-KR'
248
+ }],
249
+ heading: 'Legacy multi-byte Korean encodings'
250
+ }, {
251
+ encodings: [{
252
+ labels: ['csiso2022kr', 'hz-gb-2312', 'iso-2022-cn', 'iso-2022-cn-ext', 'iso-2022-kr'],
253
+ name: 'replacement'
254
+ }, {
255
+ labels: ['utf-16be'],
256
+ name: 'UTF-16BE'
257
+ }, {
258
+ labels: ['utf-16', 'utf-16le'],
259
+ name: 'UTF-16LE'
260
+ }, {
261
+ labels: ['x-user-defined'],
262
+ name: 'x-user-defined'
263
+ }],
264
+ heading: 'Legacy miscellaneous encodings'
265
+ }];
266
+ var label_to_encoding = {};
267
+ encodings.forEach(function (category) {
268
+ category.encodings.forEach(function (encoding) {
269
+ encoding.labels.forEach(function (label) {
270
+ label_to_encoding[label] = encoding;
271
+ });
272
+ });
273
+ });
274
+ var encoders = {};
275
+ var decoders = {};
276
+ function indexCodePointFor(pointer, index) {
277
+ if (!index) return null;
278
+ return index[pointer] || null;
279
+ }
280
+ function indexPointerFor(code_point, index) {
281
+ var pointer = index.indexOf(code_point);
282
+ return pointer === -1 ? null : pointer;
283
+ }
284
+ function index(name) {
285
+ if (!('encoding-indexes' in global)) {
286
+ throw Error('Indexes missing.' + ' Did you forget to include encoding-indexes.js first?');
287
+ }
288
+ return global['encoding-indexes'][name];
289
+ }
290
+ function indexGB18030RangesCodePointFor(pointer) {
291
+ if (pointer > 39419 && pointer < 189000 || pointer > 1237575) return null;
292
+ if (pointer === 7457) return 0xe7c7;
293
+ var offset = 0;
294
+ var code_point_offset = 0;
295
+ var idx = index('gb18030-ranges');
296
+ var i;
297
+ for (i = 0; i < idx.length; ++i) {
298
+ var entry = idx[i];
299
+ if (entry[0] <= pointer) {
300
+ offset = entry[0];
301
+ code_point_offset = entry[1];
302
+ } else {
303
+ break;
304
+ }
305
+ }
306
+ return code_point_offset + pointer - offset;
307
+ }
308
+ function indexGB18030RangesPointerFor(code_point) {
309
+ if (code_point === 0xe7c7) return 7457;
310
+ var offset = 0;
311
+ var pointer_offset = 0;
312
+ var idx = index('gb18030-ranges');
313
+ var i;
314
+ for (i = 0; i < idx.length; ++i) {
315
+ var entry = idx[i];
316
+ if (entry[1] <= code_point) {
317
+ offset = entry[1];
318
+ pointer_offset = entry[0];
319
+ } else {
320
+ break;
321
+ }
322
+ }
323
+ return pointer_offset + code_point - offset;
324
+ }
325
+ function indexShiftJISPointerFor(code_point) {
326
+ shift_jis_index = shift_jis_index || index('jis0208').map(function (code_point, pointer) {
327
+ return inRange(pointer, 8272, 8835) ? null : code_point;
328
+ });
329
+ var index_ = shift_jis_index;
330
+ return index_.indexOf(code_point);
331
+ }
332
+ var shift_jis_index;
333
+ function indexBig5PointerFor(code_point) {
334
+ big5_index_no_hkscs = big5_index_no_hkscs || index('big5').map(function (code_point, pointer) {
335
+ return pointer < (0xa1 - 0x81) * 157 ? null : code_point;
336
+ });
337
+ var index_ = big5_index_no_hkscs;
338
+ if (code_point === 0x2550 || code_point === 0x255e || code_point === 0x2561 || code_point === 0x256a || code_point === 0x5341 || code_point === 0x5345) {
339
+ return index_.lastIndexOf(code_point);
340
+ }
341
+ return indexPointerFor(code_point, index_);
342
+ }
343
+ var big5_index_no_hkscs;
344
+ var DEFAULT_ENCODING = 'utf-8';
345
+ function TextDecoder(label, options) {
346
+ if (!(this instanceof TextDecoder)) throw TypeError("Called as a function. Did you forget 'new'?");
347
+ label = label !== undefined ? String(label) : DEFAULT_ENCODING;
348
+ options = ToDictionary(options);
349
+ this._encoding = null;
350
+ this._decoder = null;
351
+ this._ignoreBOM = false;
352
+ this._BOMseen = false;
353
+ this._error_mode = 'replacement';
354
+ this._do_not_flush = false;
355
+ var encoding = getEncoding(label);
356
+ if (encoding === null || encoding.name === 'replacement') throw RangeError('Unknown encoding: ' + label);
357
+ if (!decoders[encoding.name]) {
358
+ throw Error('Decoder not present.' + ' Did you forget to include encoding-indexes.js first?');
359
+ }
360
+ var dec = this;
361
+ dec._encoding = encoding;
362
+ if (Boolean(options['fatal'])) dec._error_mode = 'fatal';
363
+ if (Boolean(options['ignoreBOM'])) dec._ignoreBOM = true;
364
+ if (!Object.defineProperty) {
365
+ this.encoding = dec._encoding.name.toLowerCase();
366
+ this.fatal = dec._error_mode === 'fatal';
367
+ this.ignoreBOM = dec._ignoreBOM;
368
+ }
369
+ return dec;
370
+ }
371
+ if (Object.defineProperty) {
372
+ Object.defineProperty(TextDecoder.prototype, 'encoding', {
373
+ get: function get() {
374
+ return this._encoding.name.toLowerCase();
375
+ }
376
+ });
377
+ Object.defineProperty(TextDecoder.prototype, 'fatal', {
378
+ get: function get() {
379
+ return this._error_mode === 'fatal';
380
+ }
381
+ });
382
+ Object.defineProperty(TextDecoder.prototype, 'ignoreBOM', {
383
+ get: function get() {
384
+ return this._ignoreBOM;
385
+ }
386
+ });
387
+ }
388
+ TextDecoder.prototype.decode = function decode(input, options) {
389
+ var bytes;
390
+ if ((0, _typeof2.default)(input) === 'object' && input instanceof ArrayBuffer) {
391
+ bytes = new Uint8Array(input);
392
+ } else if ((0, _typeof2.default)(input) === 'object' && 'buffer' in input && input.buffer instanceof ArrayBuffer) {
393
+ bytes = new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
394
+ } else {
395
+ bytes = new Uint8Array(0);
396
+ }
397
+ options = ToDictionary(options);
398
+ if (!this._do_not_flush) {
399
+ this._decoder = decoders[this._encoding.name]({
400
+ fatal: this._error_mode === 'fatal'
401
+ });
402
+ this._BOMseen = false;
403
+ }
404
+ this._do_not_flush = Boolean(options['stream']);
405
+ var input_stream = new Stream(bytes);
406
+ var output = [];
407
+ var result;
408
+ while (true) {
409
+ var token = input_stream.read();
410
+ if (token === end_of_stream) break;
411
+ result = this._decoder.handler(input_stream, token);
412
+ if (result === finished) break;
413
+ if (result !== null) {
414
+ if (Array.isArray(result)) output.push.apply(output, result);else output.push(result);
415
+ }
416
+ }
417
+ if (!this._do_not_flush) {
418
+ do {
419
+ result = this._decoder.handler(input_stream, input_stream.read());
420
+ if (result === finished) break;
421
+ if (result === null) continue;
422
+ if (Array.isArray(result)) output.push.apply(output, result);else output.push(result);
423
+ } while (!input_stream.endOfStream());
424
+ this._decoder = null;
425
+ }
426
+ function serializeStream(stream) {
427
+ if (includes(['UTF-8', 'UTF-16LE', 'UTF-16BE'], this._encoding.name) && !this._ignoreBOM && !this._BOMseen) {
428
+ if (stream.length > 0 && stream[0] === 0xfeff) {
429
+ this._BOMseen = true;
430
+ stream.shift();
431
+ } else if (stream.length > 0) {
432
+ this._BOMseen = true;
433
+ } else {}
434
+ }
435
+ return codePointsToString(stream);
436
+ }
437
+ return serializeStream.call(this, output);
438
+ };
439
+ function TextEncoder(label, options) {
440
+ if (!(this instanceof TextEncoder)) throw TypeError("Called as a function. Did you forget 'new'?");
441
+ options = ToDictionary(options);
442
+ this._encoding = null;
443
+ this._encoder = null;
444
+ this._do_not_flush = false;
445
+ this._fatal = Boolean(options['fatal']) ? 'fatal' : 'replacement';
446
+ var enc = this;
447
+ if (Boolean(options['NONSTANDARD_allowLegacyEncoding'])) {
448
+ label = label !== undefined ? String(label) : DEFAULT_ENCODING;
449
+ var encoding = getEncoding(label);
450
+ if (encoding === null || encoding.name === 'replacement') throw RangeError('Unknown encoding: ' + label);
451
+ if (!encoders[encoding.name]) {
452
+ throw Error('Encoder not present.' + ' Did you forget to include encoding-indexes.js first?');
453
+ }
454
+ enc._encoding = encoding;
455
+ } else {
456
+ enc._encoding = getEncoding('utf-8');
457
+ if (label !== undefined && 'console' in global) {
458
+ console.warn('TextEncoder constructor called with encoding label, ' + 'which is ignored.');
459
+ }
460
+ }
461
+ if (!Object.defineProperty) this.encoding = enc._encoding.name.toLowerCase();
462
+ return enc;
463
+ }
464
+ if (Object.defineProperty) {
465
+ Object.defineProperty(TextEncoder.prototype, 'encoding', {
466
+ get: function get() {
467
+ return this._encoding.name.toLowerCase();
468
+ }
469
+ });
470
+ }
471
+ TextEncoder.prototype.encode = function encode(opt_string, options) {
472
+ opt_string = opt_string === undefined ? '' : String(opt_string);
473
+ options = ToDictionary(options);
474
+ if (!this._do_not_flush) this._encoder = encoders[this._encoding.name]({
475
+ fatal: this._fatal === 'fatal'
476
+ });
477
+ this._do_not_flush = Boolean(options['stream']);
478
+ var input = new Stream(stringToCodePoints(opt_string));
479
+ var output = [];
480
+ var result;
481
+ while (true) {
482
+ var token = input.read();
483
+ if (token === end_of_stream) break;
484
+ result = this._encoder.handler(input, token);
485
+ if (result === finished) break;
486
+ if (Array.isArray(result)) output.push.apply(output, result);else output.push(result);
487
+ }
488
+ if (!this._do_not_flush) {
489
+ while (true) {
490
+ result = this._encoder.handler(input, input.read());
491
+ if (result === finished) break;
492
+ if (Array.isArray(result)) output.push.apply(output, result);else output.push(result);
493
+ }
494
+ this._encoder = null;
495
+ }
496
+ return new Uint8Array(output);
497
+ };
498
+ function UTF8Decoder(options) {
499
+ var fatal = options.fatal;
500
+ var utf8_code_point = 0,
501
+ utf8_bytes_seen = 0,
502
+ utf8_bytes_needed = 0,
503
+ utf8_lower_boundary = 0x80,
504
+ utf8_upper_boundary = 0xbf;
505
+ this.handler = function (stream, bite) {
506
+ if (bite === end_of_stream && utf8_bytes_needed !== 0) {
507
+ utf8_bytes_needed = 0;
508
+ return decoderError(fatal);
509
+ }
510
+ if (bite === end_of_stream) return finished;
511
+ if (utf8_bytes_needed === 0) {
512
+ if (inRange(bite, 0x00, 0x7f)) {
513
+ return bite;
514
+ } else if (inRange(bite, 0xc2, 0xdf)) {
515
+ utf8_bytes_needed = 1;
516
+ utf8_code_point = bite & 0x1f;
517
+ } else if (inRange(bite, 0xe0, 0xef)) {
518
+ if (bite === 0xe0) utf8_lower_boundary = 0xa0;
519
+ if (bite === 0xed) utf8_upper_boundary = 0x9f;
520
+ utf8_bytes_needed = 2;
521
+ utf8_code_point = bite & 0xf;
522
+ } else if (inRange(bite, 0xf0, 0xf4)) {
523
+ if (bite === 0xf0) utf8_lower_boundary = 0x90;
524
+ if (bite === 0xf4) utf8_upper_boundary = 0x8f;
525
+ utf8_bytes_needed = 3;
526
+ utf8_code_point = bite & 0x7;
527
+ } else {
528
+ return decoderError(fatal);
529
+ }
530
+ return null;
531
+ }
532
+ if (!inRange(bite, utf8_lower_boundary, utf8_upper_boundary)) {
533
+ utf8_code_point = utf8_bytes_needed = utf8_bytes_seen = 0;
534
+ utf8_lower_boundary = 0x80;
535
+ utf8_upper_boundary = 0xbf;
536
+ stream.prepend(bite);
537
+ return decoderError(fatal);
538
+ }
539
+ utf8_lower_boundary = 0x80;
540
+ utf8_upper_boundary = 0xbf;
541
+ utf8_code_point = utf8_code_point << 6 | bite & 0x3f;
542
+ utf8_bytes_seen += 1;
543
+ if (utf8_bytes_seen !== utf8_bytes_needed) return null;
544
+ var code_point = utf8_code_point;
545
+ utf8_code_point = utf8_bytes_needed = utf8_bytes_seen = 0;
546
+ return code_point;
547
+ };
548
+ }
549
+ function UTF8Encoder(options) {
550
+ var fatal = options.fatal;
551
+ this.handler = function (stream, code_point) {
552
+ if (code_point === end_of_stream) return finished;
553
+ if (isASCIICodePoint(code_point)) return code_point;
554
+ var count, offset;
555
+ if (inRange(code_point, 0x0080, 0x07ff)) {
556
+ count = 1;
557
+ offset = 0xc0;
558
+ } else if (inRange(code_point, 0x0800, 0xffff)) {
559
+ count = 2;
560
+ offset = 0xe0;
561
+ } else if (inRange(code_point, 0x10000, 0x10ffff)) {
562
+ count = 3;
563
+ offset = 0xf0;
564
+ }
565
+ var bytes = [(code_point >> 6 * count) + offset];
566
+ while (count > 0) {
567
+ var temp = code_point >> 6 * (count - 1);
568
+ bytes.push(0x80 | temp & 0x3f);
569
+ count -= 1;
570
+ }
571
+ return bytes;
572
+ };
573
+ }
574
+ encoders['UTF-8'] = function (options) {
575
+ return new UTF8Encoder(options);
576
+ };
577
+ decoders['UTF-8'] = function (options) {
578
+ return new UTF8Decoder(options);
579
+ };
580
+ function SingleByteDecoder(index, options) {
581
+ var fatal = options.fatal;
582
+ this.handler = function (stream, bite) {
583
+ if (bite === end_of_stream) return finished;
584
+ if (isASCIIByte(bite)) return bite;
585
+ var code_point = index[bite - 0x80];
586
+ if (code_point === null) return decoderError(fatal);
587
+ return code_point;
588
+ };
589
+ }
590
+ function SingleByteEncoder(index, options) {
591
+ var fatal = options.fatal;
592
+ this.handler = function (stream, code_point) {
593
+ if (code_point === end_of_stream) return finished;
594
+ if (isASCIICodePoint(code_point)) return code_point;
595
+ var pointer = indexPointerFor(code_point, index);
596
+ if (pointer === null) encoderError(code_point);
597
+ return pointer + 0x80;
598
+ };
599
+ }
600
+ (function () {
601
+ if (!('encoding-indexes' in global)) return;
602
+ encodings.forEach(function (category) {
603
+ if (category.heading !== 'Legacy single-byte encodings') return;
604
+ category.encodings.forEach(function (encoding) {
605
+ var name = encoding.name;
606
+ var idx = index(name.toLowerCase());
607
+ decoders[name] = function (options) {
608
+ return new SingleByteDecoder(idx, options);
609
+ };
610
+ encoders[name] = function (options) {
611
+ return new SingleByteEncoder(idx, options);
612
+ };
613
+ });
614
+ });
615
+ })();
616
+ decoders['GBK'] = function (options) {
617
+ return new GB18030Decoder(options);
618
+ };
619
+ encoders['GBK'] = function (options) {
620
+ return new GB18030Encoder(options, true);
621
+ };
622
+ function GB18030Decoder(options) {
623
+ var fatal = options.fatal;
624
+ var gb18030_first = 0x00,
625
+ gb18030_second = 0x00,
626
+ gb18030_third = 0x00;
627
+ this.handler = function (stream, bite) {
628
+ if (bite === end_of_stream && gb18030_first === 0x00 && gb18030_second === 0x00 && gb18030_third === 0x00) {
629
+ return finished;
630
+ }
631
+ if (bite === end_of_stream && (gb18030_first !== 0x00 || gb18030_second !== 0x00 || gb18030_third !== 0x00)) {
632
+ gb18030_first = 0x00;
633
+ gb18030_second = 0x00;
634
+ gb18030_third = 0x00;
635
+ decoderError(fatal);
636
+ }
637
+ var code_point;
638
+ if (gb18030_third !== 0x00) {
639
+ code_point = null;
640
+ if (inRange(bite, 0x30, 0x39)) {
641
+ code_point = indexGB18030RangesCodePointFor((((gb18030_first - 0x81) * 10 + gb18030_second - 0x30) * 126 + gb18030_third - 0x81) * 10 + bite - 0x30);
642
+ }
643
+ var buffer = [gb18030_second, gb18030_third, bite];
644
+ gb18030_first = 0x00;
645
+ gb18030_second = 0x00;
646
+ gb18030_third = 0x00;
647
+ if (code_point === null) {
648
+ stream.prepend(buffer);
649
+ return decoderError(fatal);
650
+ }
651
+ return code_point;
652
+ }
653
+ if (gb18030_second !== 0x00) {
654
+ if (inRange(bite, 0x81, 0xfe)) {
655
+ gb18030_third = bite;
656
+ return null;
657
+ }
658
+ stream.prepend([gb18030_second, bite]);
659
+ gb18030_first = 0x00;
660
+ gb18030_second = 0x00;
661
+ return decoderError(fatal);
662
+ }
663
+ if (gb18030_first !== 0x00) {
664
+ if (inRange(bite, 0x30, 0x39)) {
665
+ gb18030_second = bite;
666
+ return null;
667
+ }
668
+ var lead = gb18030_first;
669
+ var pointer = null;
670
+ gb18030_first = 0x00;
671
+ var offset = bite < 0x7f ? 0x40 : 0x41;
672
+ if (inRange(bite, 0x40, 0x7e) || inRange(bite, 0x80, 0xfe)) pointer = (lead - 0x81) * 190 + (bite - offset);
673
+ code_point = pointer === null ? null : indexCodePointFor(pointer, index('gb18030'));
674
+ if (code_point === null && isASCIIByte(bite)) stream.prepend(bite);
675
+ if (code_point === null) return decoderError(fatal);
676
+ return code_point;
677
+ }
678
+ if (isASCIIByte(bite)) return bite;
679
+ if (bite === 0x80) return 0x20ac;
680
+ if (inRange(bite, 0x81, 0xfe)) {
681
+ gb18030_first = bite;
682
+ return null;
683
+ }
684
+ return decoderError(fatal);
685
+ };
686
+ }
687
+ function GB18030Encoder(options, gbk_flag) {
688
+ var fatal = options.fatal;
689
+ this.handler = function (stream, code_point) {
690
+ if (code_point === end_of_stream) return finished;
691
+ if (isASCIICodePoint(code_point)) return code_point;
692
+ if (code_point === 0xe5e5) return encoderError(code_point);
693
+ if (gbk_flag && code_point === 0x20ac) return 0x80;
694
+ var pointer = indexPointerFor(code_point, index('gb18030'));
695
+ if (pointer !== null) {
696
+ var lead = floor(pointer / 190) + 0x81;
697
+ var trail = pointer % 190;
698
+ var offset = trail < 0x3f ? 0x40 : 0x41;
699
+ return [lead, trail + offset];
700
+ }
701
+ if (gbk_flag) return encoderError(code_point);
702
+ pointer = indexGB18030RangesPointerFor(code_point);
703
+ var byte1 = floor(pointer / 10 / 126 / 10);
704
+ pointer = pointer - byte1 * 10 * 126 * 10;
705
+ var byte2 = floor(pointer / 10 / 126);
706
+ pointer = pointer - byte2 * 10 * 126;
707
+ var byte3 = floor(pointer / 10);
708
+ var byte4 = pointer - byte3 * 10;
709
+ return [byte1 + 0x81, byte2 + 0x30, byte3 + 0x81, byte4 + 0x30];
710
+ };
711
+ }
712
+ encoders['gb18030'] = function (options) {
713
+ return new GB18030Encoder(options);
714
+ };
715
+ decoders['gb18030'] = function (options) {
716
+ return new GB18030Decoder(options);
717
+ };
718
+ function Big5Decoder(options) {
719
+ var fatal = options.fatal;
720
+ var Big5_lead = 0x00;
721
+ this.handler = function (stream, bite) {
722
+ if (bite === end_of_stream && Big5_lead !== 0x00) {
723
+ Big5_lead = 0x00;
724
+ return decoderError(fatal);
725
+ }
726
+ if (bite === end_of_stream && Big5_lead === 0x00) return finished;
727
+ if (Big5_lead !== 0x00) {
728
+ var lead = Big5_lead;
729
+ var pointer = null;
730
+ Big5_lead = 0x00;
731
+ var offset = bite < 0x7f ? 0x40 : 0x62;
732
+ if (inRange(bite, 0x40, 0x7e) || inRange(bite, 0xa1, 0xfe)) pointer = (lead - 0x81) * 157 + (bite - offset);
733
+ switch (pointer) {
734
+ case 1133:
735
+ return [0x00ca, 0x0304];
736
+ case 1135:
737
+ return [0x00ca, 0x030c];
738
+ case 1164:
739
+ return [0x00ea, 0x0304];
740
+ case 1166:
741
+ return [0x00ea, 0x030c];
742
+ }
743
+ var code_point = pointer === null ? null : indexCodePointFor(pointer, index('big5'));
744
+ if (code_point === null && isASCIIByte(bite)) stream.prepend(bite);
745
+ if (code_point === null) return decoderError(fatal);
746
+ return code_point;
747
+ }
748
+ if (isASCIIByte(bite)) return bite;
749
+ if (inRange(bite, 0x81, 0xfe)) {
750
+ Big5_lead = bite;
751
+ return null;
752
+ }
753
+ return decoderError(fatal);
754
+ };
755
+ }
756
+ function Big5Encoder(options) {
757
+ var fatal = options.fatal;
758
+ this.handler = function (stream, code_point) {
759
+ if (code_point === end_of_stream) return finished;
760
+ if (isASCIICodePoint(code_point)) return code_point;
761
+ var pointer = indexBig5PointerFor(code_point);
762
+ if (pointer === null) return encoderError(code_point);
763
+ var lead = floor(pointer / 157) + 0x81;
764
+ if (lead < 0xa1) return encoderError(code_point);
765
+ var trail = pointer % 157;
766
+ var offset = trail < 0x3f ? 0x40 : 0x62;
767
+ return [lead, trail + offset];
768
+ };
769
+ }
770
+ encoders['Big5'] = function (options) {
771
+ return new Big5Encoder(options);
772
+ };
773
+ decoders['Big5'] = function (options) {
774
+ return new Big5Decoder(options);
775
+ };
776
+ function EUCJPDecoder(options) {
777
+ var fatal = options.fatal;
778
+ var eucjp_jis0212_flag = false,
779
+ eucjp_lead = 0x00;
780
+ this.handler = function (stream, bite) {
781
+ if (bite === end_of_stream && eucjp_lead !== 0x00) {
782
+ eucjp_lead = 0x00;
783
+ return decoderError(fatal);
784
+ }
785
+ if (bite === end_of_stream && eucjp_lead === 0x00) return finished;
786
+ if (eucjp_lead === 0x8e && inRange(bite, 0xa1, 0xdf)) {
787
+ eucjp_lead = 0x00;
788
+ return 0xff61 - 0xa1 + bite;
789
+ }
790
+ if (eucjp_lead === 0x8f && inRange(bite, 0xa1, 0xfe)) {
791
+ eucjp_jis0212_flag = true;
792
+ eucjp_lead = bite;
793
+ return null;
794
+ }
795
+ if (eucjp_lead !== 0x00) {
796
+ var lead = eucjp_lead;
797
+ eucjp_lead = 0x00;
798
+ var code_point = null;
799
+ if (inRange(lead, 0xa1, 0xfe) && inRange(bite, 0xa1, 0xfe)) {
800
+ code_point = indexCodePointFor((lead - 0xa1) * 94 + (bite - 0xa1), index(!eucjp_jis0212_flag ? 'jis0208' : 'jis0212'));
801
+ }
802
+ eucjp_jis0212_flag = false;
803
+ if (!inRange(bite, 0xa1, 0xfe)) stream.prepend(bite);
804
+ if (code_point === null) return decoderError(fatal);
805
+ return code_point;
806
+ }
807
+ if (isASCIIByte(bite)) return bite;
808
+ if (bite === 0x8e || bite === 0x8f || inRange(bite, 0xa1, 0xfe)) {
809
+ eucjp_lead = bite;
810
+ return null;
811
+ }
812
+ return decoderError(fatal);
813
+ };
814
+ }
815
+ function EUCJPEncoder(options) {
816
+ var fatal = options.fatal;
817
+ this.handler = function (stream, code_point) {
818
+ if (code_point === end_of_stream) return finished;
819
+ if (isASCIICodePoint(code_point)) return code_point;
820
+ if (code_point === 0x00a5) return 0x5c;
821
+ if (code_point === 0x203e) return 0x7e;
822
+ if (inRange(code_point, 0xff61, 0xff9f)) return [0x8e, code_point - 0xff61 + 0xa1];
823
+ if (code_point === 0x2212) code_point = 0xff0d;
824
+ var pointer = indexPointerFor(code_point, index('jis0208'));
825
+ if (pointer === null) return encoderError(code_point);
826
+ var lead = floor(pointer / 94) + 0xa1;
827
+ var trail = pointer % 94 + 0xa1;
828
+ return [lead, trail];
829
+ };
830
+ }
831
+ encoders['EUC-JP'] = function (options) {
832
+ return new EUCJPEncoder(options);
833
+ };
834
+ decoders['EUC-JP'] = function (options) {
835
+ return new EUCJPDecoder(options);
836
+ };
837
+ function ISO2022JPDecoder(options) {
838
+ var fatal = options.fatal;
839
+ var states = {
840
+ ASCII: 0,
841
+ Roman: 1,
842
+ Katakana: 2,
843
+ LeadByte: 3,
844
+ TrailByte: 4,
845
+ EscapeStart: 5,
846
+ Escape: 6
847
+ };
848
+ var iso2022jp_decoder_state = states.ASCII,
849
+ iso2022jp_decoder_output_state = states.ASCII,
850
+ iso2022jp_lead = 0x00,
851
+ iso2022jp_output_flag = false;
852
+ this.handler = function (stream, bite) {
853
+ switch (iso2022jp_decoder_state) {
854
+ default:
855
+ case states.ASCII:
856
+ if (bite === 0x1b) {
857
+ iso2022jp_decoder_state = states.EscapeStart;
858
+ return null;
859
+ }
860
+ if (inRange(bite, 0x00, 0x7f) && bite !== 0x0e && bite !== 0x0f && bite !== 0x1b) {
861
+ iso2022jp_output_flag = false;
862
+ return bite;
863
+ }
864
+ if (bite === end_of_stream) {
865
+ return finished;
866
+ }
867
+ iso2022jp_output_flag = false;
868
+ return decoderError(fatal);
869
+ case states.Roman:
870
+ if (bite === 0x1b) {
871
+ iso2022jp_decoder_state = states.EscapeStart;
872
+ return null;
873
+ }
874
+ if (bite === 0x5c) {
875
+ iso2022jp_output_flag = false;
876
+ return 0x00a5;
877
+ }
878
+ if (bite === 0x7e) {
879
+ iso2022jp_output_flag = false;
880
+ return 0x203e;
881
+ }
882
+ if (inRange(bite, 0x00, 0x7f) && bite !== 0x0e && bite !== 0x0f && bite !== 0x1b && bite !== 0x5c && bite !== 0x7e) {
883
+ iso2022jp_output_flag = false;
884
+ return bite;
885
+ }
886
+ if (bite === end_of_stream) {
887
+ return finished;
888
+ }
889
+ iso2022jp_output_flag = false;
890
+ return decoderError(fatal);
891
+ case states.Katakana:
892
+ if (bite === 0x1b) {
893
+ iso2022jp_decoder_state = states.EscapeStart;
894
+ return null;
895
+ }
896
+ if (inRange(bite, 0x21, 0x5f)) {
897
+ iso2022jp_output_flag = false;
898
+ return 0xff61 - 0x21 + bite;
899
+ }
900
+ if (bite === end_of_stream) {
901
+ return finished;
902
+ }
903
+ iso2022jp_output_flag = false;
904
+ return decoderError(fatal);
905
+ case states.LeadByte:
906
+ if (bite === 0x1b) {
907
+ iso2022jp_decoder_state = states.EscapeStart;
908
+ return null;
909
+ }
910
+ if (inRange(bite, 0x21, 0x7e)) {
911
+ iso2022jp_output_flag = false;
912
+ iso2022jp_lead = bite;
913
+ iso2022jp_decoder_state = states.TrailByte;
914
+ return null;
915
+ }
916
+ if (bite === end_of_stream) {
917
+ return finished;
918
+ }
919
+ iso2022jp_output_flag = false;
920
+ return decoderError(fatal);
921
+ case states.TrailByte:
922
+ if (bite === 0x1b) {
923
+ iso2022jp_decoder_state = states.EscapeStart;
924
+ return decoderError(fatal);
925
+ }
926
+ if (inRange(bite, 0x21, 0x7e)) {
927
+ iso2022jp_decoder_state = states.LeadByte;
928
+ var pointer = (iso2022jp_lead - 0x21) * 94 + bite - 0x21;
929
+ var code_point = indexCodePointFor(pointer, index('jis0208'));
930
+ if (code_point === null) return decoderError(fatal);
931
+ return code_point;
932
+ }
933
+ if (bite === end_of_stream) {
934
+ iso2022jp_decoder_state = states.LeadByte;
935
+ stream.prepend(bite);
936
+ return decoderError(fatal);
937
+ }
938
+ iso2022jp_decoder_state = states.LeadByte;
939
+ return decoderError(fatal);
940
+ case states.EscapeStart:
941
+ if (bite === 0x24 || bite === 0x28) {
942
+ iso2022jp_lead = bite;
943
+ iso2022jp_decoder_state = states.Escape;
944
+ return null;
945
+ }
946
+ stream.prepend(bite);
947
+ iso2022jp_output_flag = false;
948
+ iso2022jp_decoder_state = iso2022jp_decoder_output_state;
949
+ return decoderError(fatal);
950
+ case states.Escape:
951
+ var lead = iso2022jp_lead;
952
+ iso2022jp_lead = 0x00;
953
+ var state = null;
954
+ if (lead === 0x28 && bite === 0x42) state = states.ASCII;
955
+ if (lead === 0x28 && bite === 0x4a) state = states.Roman;
956
+ if (lead === 0x28 && bite === 0x49) state = states.Katakana;
957
+ if (lead === 0x24 && (bite === 0x40 || bite === 0x42)) state = states.LeadByte;
958
+ if (state !== null) {
959
+ iso2022jp_decoder_state = iso2022jp_decoder_state = state;
960
+ var output_flag = iso2022jp_output_flag;
961
+ iso2022jp_output_flag = true;
962
+ return !output_flag ? null : decoderError(fatal);
963
+ }
964
+ stream.prepend([lead, bite]);
965
+ iso2022jp_output_flag = false;
966
+ iso2022jp_decoder_state = iso2022jp_decoder_output_state;
967
+ return decoderError(fatal);
968
+ }
969
+ };
970
+ }
971
+ function ISO2022JPEncoder(options) {
972
+ var fatal = options.fatal;
973
+ var states = {
974
+ ASCII: 0,
975
+ Roman: 1,
976
+ jis0208: 2
977
+ };
978
+ var iso2022jp_state = states.ASCII;
979
+ this.handler = function (stream, code_point) {
980
+ if (code_point === end_of_stream && iso2022jp_state !== states.ASCII) {
981
+ stream.prepend(code_point);
982
+ iso2022jp_state = states.ASCII;
983
+ return [0x1b, 0x28, 0x42];
984
+ }
985
+ if (code_point === end_of_stream && iso2022jp_state === states.ASCII) return finished;
986
+ if ((iso2022jp_state === states.ASCII || iso2022jp_state === states.Roman) && (code_point === 0x000e || code_point === 0x000f || code_point === 0x001b)) {
987
+ return encoderError(0xfffd);
988
+ }
989
+ if (iso2022jp_state === states.ASCII && isASCIICodePoint(code_point)) return code_point;
990
+ if (iso2022jp_state === states.Roman && (isASCIICodePoint(code_point) && code_point !== 0x005c && code_point !== 0x007e || code_point == 0x00a5 || code_point == 0x203e)) {
991
+ if (isASCIICodePoint(code_point)) return code_point;
992
+ if (code_point === 0x00a5) return 0x5c;
993
+ if (code_point === 0x203e) return 0x7e;
994
+ }
995
+ if (isASCIICodePoint(code_point) && iso2022jp_state !== states.ASCII) {
996
+ stream.prepend(code_point);
997
+ iso2022jp_state = states.ASCII;
998
+ return [0x1b, 0x28, 0x42];
999
+ }
1000
+ if ((code_point === 0x00a5 || code_point === 0x203e) && iso2022jp_state !== states.Roman) {
1001
+ stream.prepend(code_point);
1002
+ iso2022jp_state = states.Roman;
1003
+ return [0x1b, 0x28, 0x4a];
1004
+ }
1005
+ if (code_point === 0x2212) code_point = 0xff0d;
1006
+ var pointer = indexPointerFor(code_point, index('jis0208'));
1007
+ if (pointer === null) return encoderError(code_point);
1008
+ if (iso2022jp_state !== states.jis0208) {
1009
+ stream.prepend(code_point);
1010
+ iso2022jp_state = states.jis0208;
1011
+ return [0x1b, 0x24, 0x42];
1012
+ }
1013
+ var lead = floor(pointer / 94) + 0x21;
1014
+ var trail = pointer % 94 + 0x21;
1015
+ return [lead, trail];
1016
+ };
1017
+ }
1018
+ encoders['ISO-2022-JP'] = function (options) {
1019
+ return new ISO2022JPEncoder(options);
1020
+ };
1021
+ decoders['ISO-2022-JP'] = function (options) {
1022
+ return new ISO2022JPDecoder(options);
1023
+ };
1024
+ function ShiftJISDecoder(options) {
1025
+ var fatal = options.fatal;
1026
+ var Shift_JIS_lead = 0x00;
1027
+ this.handler = function (stream, bite) {
1028
+ if (bite === end_of_stream && Shift_JIS_lead !== 0x00) {
1029
+ Shift_JIS_lead = 0x00;
1030
+ return decoderError(fatal);
1031
+ }
1032
+ if (bite === end_of_stream && Shift_JIS_lead === 0x00) return finished;
1033
+ if (Shift_JIS_lead !== 0x00) {
1034
+ var lead = Shift_JIS_lead;
1035
+ var pointer = null;
1036
+ Shift_JIS_lead = 0x00;
1037
+ var offset = bite < 0x7f ? 0x40 : 0x41;
1038
+ var lead_offset = lead < 0xa0 ? 0x81 : 0xc1;
1039
+ if (inRange(bite, 0x40, 0x7e) || inRange(bite, 0x80, 0xfc)) pointer = (lead - lead_offset) * 188 + bite - offset;
1040
+ if (inRange(pointer, 8836, 10715)) return 0xe000 - 8836 + pointer;
1041
+ var code_point = pointer === null ? null : indexCodePointFor(pointer, index('jis0208'));
1042
+ if (code_point === null && isASCIIByte(bite)) stream.prepend(bite);
1043
+ if (code_point === null) return decoderError(fatal);
1044
+ return code_point;
1045
+ }
1046
+ if (isASCIIByte(bite) || bite === 0x80) return bite;
1047
+ if (inRange(bite, 0xa1, 0xdf)) return 0xff61 - 0xa1 + bite;
1048
+ if (inRange(bite, 0x81, 0x9f) || inRange(bite, 0xe0, 0xfc)) {
1049
+ Shift_JIS_lead = bite;
1050
+ return null;
1051
+ }
1052
+ return decoderError(fatal);
1053
+ };
1054
+ }
1055
+ function ShiftJISEncoder(options) {
1056
+ var fatal = options.fatal;
1057
+ this.handler = function (stream, code_point) {
1058
+ if (code_point === end_of_stream) return finished;
1059
+ if (isASCIICodePoint(code_point) || code_point === 0x0080) return code_point;
1060
+ if (code_point === 0x00a5) return 0x5c;
1061
+ if (code_point === 0x203e) return 0x7e;
1062
+ if (inRange(code_point, 0xff61, 0xff9f)) return code_point - 0xff61 + 0xa1;
1063
+ if (code_point === 0x2212) code_point = 0xff0d;
1064
+ var pointer = indexShiftJISPointerFor(code_point);
1065
+ if (pointer === null) return encoderError(code_point);
1066
+ var lead = floor(pointer / 188);
1067
+ var lead_offset = lead < 0x1f ? 0x81 : 0xc1;
1068
+ var trail = pointer % 188;
1069
+ var offset = trail < 0x3f ? 0x40 : 0x41;
1070
+ return [lead + lead_offset, trail + offset];
1071
+ };
1072
+ }
1073
+ encoders['Shift_JIS'] = function (options) {
1074
+ return new ShiftJISEncoder(options);
1075
+ };
1076
+ decoders['Shift_JIS'] = function (options) {
1077
+ return new ShiftJISDecoder(options);
1078
+ };
1079
+ function EUCKRDecoder(options) {
1080
+ var fatal = options.fatal;
1081
+ var euckr_lead = 0x00;
1082
+ this.handler = function (stream, bite) {
1083
+ if (bite === end_of_stream && euckr_lead !== 0) {
1084
+ euckr_lead = 0x00;
1085
+ return decoderError(fatal);
1086
+ }
1087
+ if (bite === end_of_stream && euckr_lead === 0) return finished;
1088
+ if (euckr_lead !== 0x00) {
1089
+ var lead = euckr_lead;
1090
+ var pointer = null;
1091
+ euckr_lead = 0x00;
1092
+ if (inRange(bite, 0x41, 0xfe)) pointer = (lead - 0x81) * 190 + (bite - 0x41);
1093
+ var code_point = pointer === null ? null : indexCodePointFor(pointer, index('euc-kr'));
1094
+ if (pointer === null && isASCIIByte(bite)) stream.prepend(bite);
1095
+ if (code_point === null) return decoderError(fatal);
1096
+ return code_point;
1097
+ }
1098
+ if (isASCIIByte(bite)) return bite;
1099
+ if (inRange(bite, 0x81, 0xfe)) {
1100
+ euckr_lead = bite;
1101
+ return null;
1102
+ }
1103
+ return decoderError(fatal);
1104
+ };
1105
+ }
1106
+ function EUCKREncoder(options) {
1107
+ var fatal = options.fatal;
1108
+ this.handler = function (stream, code_point) {
1109
+ if (code_point === end_of_stream) return finished;
1110
+ if (isASCIICodePoint(code_point)) return code_point;
1111
+ var pointer = indexPointerFor(code_point, index('euc-kr'));
1112
+ if (pointer === null) return encoderError(code_point);
1113
+ var lead = floor(pointer / 190) + 0x81;
1114
+ var trail = pointer % 190 + 0x41;
1115
+ return [lead, trail];
1116
+ };
1117
+ }
1118
+ encoders['EUC-KR'] = function (options) {
1119
+ return new EUCKREncoder(options);
1120
+ };
1121
+ decoders['EUC-KR'] = function (options) {
1122
+ return new EUCKRDecoder(options);
1123
+ };
1124
+ function convertCodeUnitToBytes(code_unit, utf16be) {
1125
+ var byte1 = code_unit >> 8;
1126
+ var byte2 = code_unit & 0x00ff;
1127
+ if (utf16be) return [byte1, byte2];
1128
+ return [byte2, byte1];
1129
+ }
1130
+ function UTF16Decoder(utf16_be, options) {
1131
+ var fatal = options.fatal;
1132
+ var utf16_lead_byte = null,
1133
+ utf16_lead_surrogate = null;
1134
+ this.handler = function (stream, bite) {
1135
+ if (bite === end_of_stream && (utf16_lead_byte !== null || utf16_lead_surrogate !== null)) {
1136
+ return decoderError(fatal);
1137
+ }
1138
+ if (bite === end_of_stream && utf16_lead_byte === null && utf16_lead_surrogate === null) {
1139
+ return finished;
1140
+ }
1141
+ if (utf16_lead_byte === null) {
1142
+ utf16_lead_byte = bite;
1143
+ return null;
1144
+ }
1145
+ var code_unit;
1146
+ if (utf16_be) {
1147
+ code_unit = (utf16_lead_byte << 8) + bite;
1148
+ } else {
1149
+ code_unit = (bite << 8) + utf16_lead_byte;
1150
+ }
1151
+ utf16_lead_byte = null;
1152
+ if (utf16_lead_surrogate !== null) {
1153
+ var lead_surrogate = utf16_lead_surrogate;
1154
+ utf16_lead_surrogate = null;
1155
+ if (inRange(code_unit, 0xdc00, 0xdfff)) {
1156
+ return 0x10000 + (lead_surrogate - 0xd800) * 0x400 + (code_unit - 0xdc00);
1157
+ }
1158
+ stream.prepend(convertCodeUnitToBytes(code_unit, utf16_be));
1159
+ return decoderError(fatal);
1160
+ }
1161
+ if (inRange(code_unit, 0xd800, 0xdbff)) {
1162
+ utf16_lead_surrogate = code_unit;
1163
+ return null;
1164
+ }
1165
+ if (inRange(code_unit, 0xdc00, 0xdfff)) return decoderError(fatal);
1166
+ return code_unit;
1167
+ };
1168
+ }
1169
+ function UTF16Encoder(utf16_be, options) {
1170
+ var fatal = options.fatal;
1171
+ this.handler = function (stream, code_point) {
1172
+ if (code_point === end_of_stream) return finished;
1173
+ if (inRange(code_point, 0x0000, 0xffff)) return convertCodeUnitToBytes(code_point, utf16_be);
1174
+ var lead = convertCodeUnitToBytes((code_point - 0x10000 >> 10) + 0xd800, utf16_be);
1175
+ var trail = convertCodeUnitToBytes((code_point - 0x10000 & 0x3ff) + 0xdc00, utf16_be);
1176
+ return lead.concat(trail);
1177
+ };
1178
+ }
1179
+ encoders['UTF-16BE'] = function (options) {
1180
+ return new UTF16Encoder(true, options);
1181
+ };
1182
+ decoders['UTF-16BE'] = function (options) {
1183
+ return new UTF16Decoder(true, options);
1184
+ };
1185
+ encoders['UTF-16LE'] = function (options) {
1186
+ return new UTF16Encoder(false, options);
1187
+ };
1188
+ decoders['UTF-16LE'] = function (options) {
1189
+ return new UTF16Decoder(false, options);
1190
+ };
1191
+ function XUserDefinedDecoder(options) {
1192
+ var fatal = options.fatal;
1193
+ this.handler = function (stream, bite) {
1194
+ if (bite === end_of_stream) return finished;
1195
+ if (isASCIIByte(bite)) return bite;
1196
+ return 0xf780 + bite - 0x80;
1197
+ };
1198
+ }
1199
+ function XUserDefinedEncoder(options) {
1200
+ var fatal = options.fatal;
1201
+ this.handler = function (stream, code_point) {
1202
+ if (code_point === end_of_stream) return finished;
1203
+ if (isASCIICodePoint(code_point)) return code_point;
1204
+ if (inRange(code_point, 0xf780, 0xf7ff)) return code_point - 0xf780 + 0x80;
1205
+ return encoderError(code_point);
1206
+ };
1207
+ }
1208
+ encoders['x-user-defined'] = function (options) {
1209
+ return new XUserDefinedEncoder(options);
1210
+ };
1211
+ decoders['x-user-defined'] = function (options) {
1212
+ return new XUserDefinedDecoder(options);
1213
+ };
1214
+ //# sourceMappingURL=encoding.js.map