Add barcode-detector-api-polyfill dependency and update environment variable declarations in SvelteKit project
This commit is contained in:
+12
@@ -0,0 +1,12 @@
|
||||
import { Stream } from "./Stream";
|
||||
/** @interface */
|
||||
export interface Decoder {
|
||||
/**
|
||||
* @param {Stream} stream The stream of bytes being decoded.
|
||||
* @param {number} bite The next byte read from the stream.
|
||||
* @return {?(number|!Array.<number>)} The next code point(s)
|
||||
* decoded, or null if not enough data exists in the input
|
||||
* stream to decode a complete code point, or |finished|.
|
||||
*/
|
||||
handler(stream: Stream, bite: number): number | number[];
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
//# sourceMappingURL=Decoder.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Decoder.js","sourceRoot":"","sources":["../../../src/common/Decoder.ts"],"names":[],"mappings":""}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import { Stream } from "./Stream";
|
||||
/** @interface */
|
||||
export interface Encoder {
|
||||
/**
|
||||
* @param {Stream} stream The stream of code points being encoded.
|
||||
* @param {number} code_point Next code point read from the stream.
|
||||
* @return {(number|!Array.<number>)} Byte(s) to emit, or |finished|.
|
||||
*/
|
||||
handler(stream: Stream, code_point: number): number | number[];
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
//# sourceMappingURL=Encoder.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Encoder.js","sourceRoot":"","sources":["../../../src/common/Encoder.ts"],"names":[],"mappings":""}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* A stream represents an ordered sequence of tokens.
|
||||
*/
|
||||
export declare class Stream {
|
||||
tokens: number[];
|
||||
/**
|
||||
*
|
||||
* @constructor
|
||||
* @param {!(Array.<number>|Uint8Array)} tokens Array of tokens that provide
|
||||
* the stream.
|
||||
*/
|
||||
constructor(tokens: number[] | Uint8Array);
|
||||
/**
|
||||
* @return {boolean} True if end-of-stream has been hit.
|
||||
*/
|
||||
endOfStream(): boolean;
|
||||
/**
|
||||
* When a token is read from a stream, the first token in the
|
||||
* stream must be returned and subsequently removed, and
|
||||
* end-of-stream must be returned otherwise.
|
||||
*
|
||||
* @return {number} Get the next token from the stream, or
|
||||
* end_of_stream.
|
||||
*/
|
||||
read(): number;
|
||||
/**
|
||||
* When one or more tokens are prepended to a stream, those tokens
|
||||
* must be inserted, in given order, before the first token in the
|
||||
* stream.
|
||||
*
|
||||
* @param {(number|!Array.<number>)} token The token(s) to prepend to the
|
||||
* stream.
|
||||
*/
|
||||
prepend(token: (number | Array<number>)): void;
|
||||
/**
|
||||
* When one or more tokens are pushed to a stream, those tokens
|
||||
* must be inserted, in given order, after the last token in the
|
||||
* stream.
|
||||
*
|
||||
* @param {(number|!Array.<number>)} token The tokens(s) to push to the
|
||||
* stream.
|
||||
*/
|
||||
push(token: (number | Array<number>)): void;
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
import { end_of_stream } from "../encoding/terminology";
|
||||
/**
|
||||
* A stream represents an ordered sequence of tokens.
|
||||
*/
|
||||
var Stream = /** @class */ (function () {
|
||||
/**
|
||||
*
|
||||
* @constructor
|
||||
* @param {!(Array.<number>|Uint8Array)} tokens Array of tokens that provide
|
||||
* the stream.
|
||||
*/
|
||||
function Stream(tokens) {
|
||||
/** @type {!Array.<number>} */
|
||||
this.tokens = Array.from(tokens);
|
||||
// Reversed as push/pop is more efficient than shift/unshift.
|
||||
this.tokens.reverse();
|
||||
}
|
||||
/**
|
||||
* @return {boolean} True if end-of-stream has been hit.
|
||||
*/
|
||||
Stream.prototype.endOfStream = function () {
|
||||
return !this.tokens.length;
|
||||
};
|
||||
/**
|
||||
* When a token is read from a stream, the first token in the
|
||||
* stream must be returned and subsequently removed, and
|
||||
* end-of-stream must be returned otherwise.
|
||||
*
|
||||
* @return {number} Get the next token from the stream, or
|
||||
* end_of_stream.
|
||||
*/
|
||||
Stream.prototype.read = function () {
|
||||
if (!this.tokens.length)
|
||||
return end_of_stream;
|
||||
return this.tokens.pop();
|
||||
};
|
||||
/**
|
||||
* When one or more tokens are prepended to a stream, those tokens
|
||||
* must be inserted, in given order, before the first token in the
|
||||
* stream.
|
||||
*
|
||||
* @param {(number|!Array.<number>)} token The token(s) to prepend to the
|
||||
* stream.
|
||||
*/
|
||||
Stream.prototype.prepend = function (token) {
|
||||
if (Array.isArray(token)) {
|
||||
var tokens = (token);
|
||||
while (tokens.length)
|
||||
this.tokens.push(tokens.pop());
|
||||
}
|
||||
else {
|
||||
this.tokens.push(token);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* When one or more tokens are pushed to a stream, those tokens
|
||||
* must be inserted, in given order, after the last token in the
|
||||
* stream.
|
||||
*
|
||||
* @param {(number|!Array.<number>)} token The tokens(s) to push to the
|
||||
* stream.
|
||||
*/
|
||||
Stream.prototype.push = function (token) {
|
||||
if (Array.isArray(token)) {
|
||||
var tokens = (token);
|
||||
while (tokens.length)
|
||||
this.tokens.unshift(tokens.shift());
|
||||
}
|
||||
else {
|
||||
this.tokens.unshift(token);
|
||||
}
|
||||
};
|
||||
return Stream;
|
||||
}());
|
||||
export { Stream };
|
||||
//# sourceMappingURL=Stream.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Stream.js","sourceRoot":"","sources":["../../../src/common/Stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD;;GAEG;AACH;IAIE;;;;;OAKG;IACH,gBAAY,MAA6B;QACvC,8BAA8B;QAC9B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACjC,6DAA6D;QAC7D,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,4BAAW,GAAX;QACE,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAC7B,CAAC;IAED;;;;;;;OAOG;IACH,qBAAI,GAAJ;QACE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM;YACrB,OAAO,aAAa,CAAC;QACvB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;IAC3B,CAAC;IAED;;;;;;;OAOG;IACH,wBAAO,GAAP,UAAQ,KAA+B;QACrC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACxB,IAAM,MAAM,GAA+C,CAAC,KAAK,CAAC,CAAC;YACnE,OAAO,MAAM,CAAC,MAAM;gBAClB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;SAClC;aACI;YACH,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACzB;IACH,CAAC;IAED;;;;;;;OAOG;IACH,qBAAI,GAAJ,UAAK,KAA+B;QAClC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACxB,IAAM,MAAM,GAA+C,CAAC,KAAK,CAAC,CAAC;YACnE,OAAO,MAAM,CAAC,MAAM;gBAClB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;SACvC;aACI;YACH,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;SAC5B;IACH,CAAC;IACH,aAAC;AAAD,CAAC,AA3ED,IA2EC"}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
declare type TextDecoderOptions = {
|
||||
fatal?: boolean;
|
||||
ignoreBOM?: boolean;
|
||||
};
|
||||
declare type DecodeOptions = {
|
||||
stream?: boolean;
|
||||
};
|
||||
/**
|
||||
* @constructor
|
||||
* @param {string=} label The label of the encoding;
|
||||
* defaults to 'utf-8'.
|
||||
* @param {Object=} options
|
||||
*/
|
||||
export declare class TextDecoder {
|
||||
private _encoding;
|
||||
private _decoder;
|
||||
private _ignoreBOM;
|
||||
private _BOMseen;
|
||||
private _error_mode;
|
||||
private _do_not_flush;
|
||||
constructor(label?: string, options?: TextDecoderOptions);
|
||||
get encoding(): string;
|
||||
get fatal(): boolean;
|
||||
get ignoreBOM(): boolean;
|
||||
/**
|
||||
* @param {BufferSource=} input The buffer of bytes to decode.
|
||||
* @param {Object=} options
|
||||
* @return {string} The decoded string.
|
||||
*/
|
||||
decode(input?: ArrayBuffer | ArrayLike<number> | Uint8Array, options?: DecodeOptions): string;
|
||||
/**
|
||||
* @param {!Array.<number>} stream
|
||||
* @return {string}
|
||||
* @this {TextDecoder}
|
||||
*/
|
||||
private serializeStream;
|
||||
}
|
||||
export {};
|
||||
+233
@@ -0,0 +1,233 @@
|
||||
import { DEFAULT_ENCODING } from "../encoding/defaultEncoding";
|
||||
import { decoders } from "../encoding/encoding-factory";
|
||||
import { getEncoding } from "../encoding/encodings";
|
||||
import { finished } from "../encoding/finished";
|
||||
import { end_of_stream } from "../encoding/terminology";
|
||||
import { codePointsToString, includes, ToDictionary } from "../encoding/utilities";
|
||||
import { Stream } from "./Stream";
|
||||
/**
|
||||
* @constructor
|
||||
* @param {string=} label The label of the encoding;
|
||||
* defaults to 'utf-8'.
|
||||
* @param {Object=} options
|
||||
*/
|
||||
var TextDecoder = /** @class */ (function () {
|
||||
function TextDecoder(label, options) {
|
||||
label = label !== undefined ? String(label) : DEFAULT_ENCODING;
|
||||
var optionsMap = ToDictionary(options);
|
||||
// A TextDecoder object has an associated encoding, decoder,
|
||||
// stream, ignore BOM flag (initially unset), BOM seen flag
|
||||
// (initially unset), error mode (initially replacement), and do
|
||||
// not flush flag (initially unset).
|
||||
/** @private */
|
||||
this._encoding = null;
|
||||
/** @private @type {?Decoder} */
|
||||
this._decoder = null;
|
||||
/** @private @type {boolean} */
|
||||
this._ignoreBOM = false;
|
||||
/** @private @type {boolean} */
|
||||
this._BOMseen = false;
|
||||
/** @private @type {string} */
|
||||
this._error_mode = 'replacement';
|
||||
/** @private @type {boolean} */
|
||||
this._do_not_flush = false;
|
||||
// 1. Let encoding be the result of getting an encoding from
|
||||
// label.
|
||||
var encoding = getEncoding(label);
|
||||
// 2. If encoding is failure or replacement, throw a RangeError.
|
||||
if (encoding === null || encoding.name === 'replacement')
|
||||
throw RangeError('Unknown encoding: ' + label);
|
||||
if (!decoders[encoding.name]) {
|
||||
throw Error('Decoder not present.' +
|
||||
' Did you forget to include encoding-indexes.js first?');
|
||||
}
|
||||
// 3. Let dec be a new TextDecoder object.
|
||||
// const dec = this;
|
||||
// no need to do this as this is a proper class
|
||||
// now and TSC will handle transpilation to older platforms
|
||||
// 4. Set dec's encoding to encoding.
|
||||
this._encoding = encoding;
|
||||
// 5. If options's fatal member is true, set dec's error mode to
|
||||
// fatal.
|
||||
if (Boolean(optionsMap['fatal']))
|
||||
this._error_mode = 'fatal';
|
||||
// 6. If options's ignoreBOM member is true, set dec's ignore BOM
|
||||
// flag.
|
||||
if (Boolean(optionsMap['ignoreBOM']))
|
||||
this._ignoreBOM = true;
|
||||
// For pre-ES5 runtimes:
|
||||
// if (!Object.defineProperty) {
|
||||
// this.encoding = dec._encoding.name.toLowerCase();
|
||||
// this.fatal = dec._error_mode === 'fatal';
|
||||
// this.ignoreBOM = dec._ignoreBOM;
|
||||
// }
|
||||
// 7. Return dec.
|
||||
// return dec;
|
||||
}
|
||||
Object.defineProperty(TextDecoder.prototype, "encoding", {
|
||||
// if (Object.defineProperty) {
|
||||
// The encoding attribute's getter must return encoding's name.
|
||||
// Object.defineProperty(TextDecoder.prototype, 'encoding', {
|
||||
// /** @this {TextDecoder} */
|
||||
// get: function () { return this._encoding.name.toLowerCase(); }
|
||||
// });
|
||||
get: function () {
|
||||
return this._encoding.name.toLowerCase();
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(TextDecoder.prototype, "fatal", {
|
||||
// The fatal attribute's getter must return true if error mode
|
||||
// is fatal, and false otherwise.
|
||||
// Object.defineProperty(TextDecoder.prototype, 'fatal', {
|
||||
// /** @this {TextDecoder} */
|
||||
// get: function () { return this._error_mode === 'fatal'; }
|
||||
// });
|
||||
get: function () {
|
||||
return this._error_mode === 'fatal';
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(TextDecoder.prototype, "ignoreBOM", {
|
||||
// The ignoreBOM attribute's getter must return true if ignore
|
||||
// BOM flag is set, and false otherwise.
|
||||
// Object.defineProperty(TextDecoder.prototype, 'ignoreBOM', {
|
||||
// /** @this {TextDecoder} */
|
||||
// get: function () { return this._ignoreBOM; }
|
||||
// });
|
||||
get: function () {
|
||||
return this._ignoreBOM;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
// }
|
||||
/**
|
||||
* @param {BufferSource=} input The buffer of bytes to decode.
|
||||
* @param {Object=} options
|
||||
* @return {string} The decoded string.
|
||||
*/
|
||||
TextDecoder.prototype.decode = function (input, options) {
|
||||
var bytes = getBytesFromInput(input);
|
||||
var optionsMap = ToDictionary(options);
|
||||
// 1. If the do not flush flag is unset, set decoder to a new
|
||||
// encoding's decoder, set stream to a new stream, and unset the
|
||||
// BOM seen flag.
|
||||
if (!this._do_not_flush) {
|
||||
this._decoder = decoders[this._encoding.name]({
|
||||
fatal: this._error_mode === 'fatal'
|
||||
});
|
||||
this._BOMseen = false;
|
||||
}
|
||||
// 2. If options's stream is true, set the do not flush flag, and
|
||||
// unset the do not flush flag otherwise.
|
||||
this._do_not_flush = Boolean(optionsMap['stream']);
|
||||
// 3. If input is given, push a copy of input to stream.
|
||||
// TODO: Align with spec algorithm - maintain stream on instance.
|
||||
var input_stream = new Stream(bytes);
|
||||
// 4. Let output be a new stream.
|
||||
var output = [];
|
||||
/** @type {?(number|!Array.<number>)} */
|
||||
var result;
|
||||
// 5. While true:
|
||||
while (true) {
|
||||
// 1. Let token be the result of reading from stream.
|
||||
var token = input_stream.read();
|
||||
// 2. If token is end-of-stream and the do not flush flag is
|
||||
// set, return output, serialized.
|
||||
// TODO: Align with spec algorithm.
|
||||
if (token === end_of_stream)
|
||||
break;
|
||||
// 3. Otherwise, run these subsubsteps:
|
||||
// 1. Let result be the result of processing token for decoder,
|
||||
// stream, output, and error mode.
|
||||
result = this._decoder.handler(input_stream, token);
|
||||
// 2. If result is finished, return output, serialized.
|
||||
if (result === finished)
|
||||
break;
|
||||
if (result !== null) {
|
||||
if (Array.isArray(result))
|
||||
output.push.apply(output, /**@type {!Array.<number>}*/ (result));
|
||||
else
|
||||
output.push(result);
|
||||
}
|
||||
// 3. Otherwise, if result is error, throw a TypeError.
|
||||
// (Thrown in handler)
|
||||
// 4. Otherwise, do nothing.
|
||||
}
|
||||
// TODO: Align with spec algorithm.
|
||||
if (!this._do_not_flush) {
|
||||
do {
|
||||
result = this._decoder.handler(input_stream, input_stream.read());
|
||||
if (result === finished)
|
||||
break;
|
||||
if (!result)
|
||||
continue;
|
||||
if (Array.isArray(result))
|
||||
output.push.apply(output, /**@type {!Array.<number>}*/ (result));
|
||||
else
|
||||
output.push(result);
|
||||
} while (!input_stream.endOfStream());
|
||||
this._decoder = null;
|
||||
}
|
||||
return this.serializeStream(output);
|
||||
};
|
||||
// A TextDecoder object also has an associated serialize stream
|
||||
// algorithm...
|
||||
/**
|
||||
* @param {!Array.<number>} stream
|
||||
* @return {string}
|
||||
* @this {TextDecoder}
|
||||
*/
|
||||
TextDecoder.prototype.serializeStream = function (stream) {
|
||||
// 1. Let token be the result of reading from stream.
|
||||
// (Done in-place on array, rather than as a stream)
|
||||
// 2. If encoding is UTF-8, UTF-16BE, or UTF-16LE, and ignore
|
||||
// BOM flag and BOM seen flag are unset, run these subsubsteps:
|
||||
if (includes(['UTF-8', 'UTF-16LE', 'UTF-16BE'], this._encoding.name) &&
|
||||
!this._ignoreBOM && !this._BOMseen) {
|
||||
if (stream.length > 0 && stream[0] === 0xFEFF) {
|
||||
// 1. If token is U+FEFF, set BOM seen flag.
|
||||
this._BOMseen = true;
|
||||
stream.shift();
|
||||
}
|
||||
else if (stream.length > 0) {
|
||||
// 2. Otherwise, if token is not end-of-stream, set BOM seen
|
||||
// flag and append token to stream.
|
||||
this._BOMseen = true;
|
||||
}
|
||||
else {
|
||||
// 3. Otherwise, if token is not end-of-stream, append token
|
||||
// to output.
|
||||
// (no-op)
|
||||
}
|
||||
}
|
||||
// 4. Otherwise, return output.
|
||||
return codePointsToString(stream);
|
||||
};
|
||||
return TextDecoder;
|
||||
}());
|
||||
export { TextDecoder };
|
||||
function isBufferInstance(input) {
|
||||
try {
|
||||
return input instanceof ArrayBuffer;
|
||||
}
|
||||
catch (e) {
|
||||
console.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function getBytesFromInput(input) {
|
||||
if (typeof input !== 'object')
|
||||
return new Uint8Array(0);
|
||||
if (isBufferInstance(input)) {
|
||||
return new Uint8Array(input);
|
||||
}
|
||||
if ('buffer' in input && isBufferInstance(input.buffer)) {
|
||||
return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
|
||||
}
|
||||
return new Uint8Array(0);
|
||||
}
|
||||
//# sourceMappingURL=TextDecoder.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+27
@@ -0,0 +1,27 @@
|
||||
declare type TextEncoderOptions = {
|
||||
NONSTANDARD_allowLegacyEncoding?: boolean;
|
||||
fatal?: boolean;
|
||||
};
|
||||
declare type EncodeOptions = {
|
||||
stream?: boolean;
|
||||
};
|
||||
/**
|
||||
* @constructor
|
||||
* @param {string=} label The label of the encoding. NONSTANDARD.
|
||||
* @param {Object=} options NONSTANDARD.
|
||||
*/
|
||||
export declare class TextEncoder {
|
||||
private _encoding;
|
||||
private _encoder;
|
||||
private _do_not_flush;
|
||||
private _fatal;
|
||||
constructor(label?: string, options?: TextEncoderOptions);
|
||||
get encoding(): string;
|
||||
/**
|
||||
* @param {string=} opt_string The string to encode.
|
||||
* @param {Object=} options
|
||||
* @return {!Uint8Array} Encoded bytes, as a Uint8Array.
|
||||
*/
|
||||
encode(opt_string: string, options?: EncodeOptions): Uint8Array;
|
||||
}
|
||||
export {};
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
import { DEFAULT_ENCODING } from "../encoding/defaultEncoding";
|
||||
import { encoders } from "../encoding/encoding-factory";
|
||||
import { getEncoding } from "../encoding/encodings";
|
||||
import { finished } from "../encoding/finished";
|
||||
import { end_of_stream } from "../encoding/terminology";
|
||||
import { stringToCodePoints, ToDictionary } from "../encoding/utilities";
|
||||
import { getGlobalScope } from "../helper/getGlobalScope";
|
||||
import { Stream } from "./Stream";
|
||||
/**
|
||||
* @constructor
|
||||
* @param {string=} label The label of the encoding. NONSTANDARD.
|
||||
* @param {Object=} options NONSTANDARD.
|
||||
*/
|
||||
var TextEncoder = /** @class */ (function () {
|
||||
function TextEncoder(label, options) {
|
||||
var optionsMap = ToDictionary(options);
|
||||
// A TextEncoder object has an associated encoding and encoder.
|
||||
/** @private */
|
||||
this._encoding = null;
|
||||
/** @private @type {?Encoder} */
|
||||
this._encoder = null;
|
||||
// Non-standard
|
||||
/** @private @type {boolean} */
|
||||
this._do_not_flush = false;
|
||||
/** @private @type {string} */
|
||||
this._fatal = Boolean(optionsMap['fatal']) ? 'fatal' : 'replacement';
|
||||
// 1. Let enc be a new TextEncoder object.
|
||||
// const enc = this;
|
||||
// no need to do this as this is a proper class
|
||||
// now and TSC will handle transpilation to older platforms
|
||||
// 2. Set enc's encoding to UTF-8's encoder.
|
||||
if (Boolean(optionsMap['NONSTANDARD_allowLegacyEncoding'])) {
|
||||
// NONSTANDARD behavior.
|
||||
label = !!label ? String(label) : DEFAULT_ENCODING;
|
||||
var encoding = getEncoding(label);
|
||||
if (encoding === null || encoding.name === 'replacement')
|
||||
throw RangeError('Unknown encoding: ' + label);
|
||||
if (!encoders[encoding.name]) {
|
||||
throw Error('Encoder not present.' +
|
||||
' Did you forget to include encoding-indexes.js first?');
|
||||
}
|
||||
this._encoding = encoding;
|
||||
// EXPERIMENTAL_CODE
|
||||
// } else if (["iso-8859-1", "ISO-8859-1", "latin-1", "latin1", "LATIN-1", "LATIN1"].indexOf(label) !== -1) {
|
||||
// this._encoding = getEncoding('iso-8859-1');
|
||||
}
|
||||
else {
|
||||
// Standard behavior.
|
||||
this._encoding = getEncoding('utf-8');
|
||||
var glo = getGlobalScope() || {};
|
||||
if (label !== undefined && 'console' in glo) {
|
||||
console.warn('TextEncoder constructor called with encoding label, '
|
||||
+ 'which is ignored.');
|
||||
}
|
||||
}
|
||||
// For pre-ES5 runtimes:
|
||||
// if (!Object.defineProperty)
|
||||
// this.encoding = enc._encoding.name.toLowerCase();
|
||||
// 3. Return enc.
|
||||
// return enc;
|
||||
}
|
||||
Object.defineProperty(TextEncoder.prototype, "encoding", {
|
||||
// if(Object.defineProperty) {
|
||||
// // The encoding attribute's getter must return encoding's name.
|
||||
// Object.defineProperty(TextEncoder.prototype, 'encoding', {
|
||||
// /** @this {TextEncoder} */
|
||||
// get: function () { return this._encoding.name.toLowerCase(); }
|
||||
// });
|
||||
// }
|
||||
get: function () {
|
||||
return this._encoding.name.toLowerCase();
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
/**
|
||||
* @param {string=} opt_string The string to encode.
|
||||
* @param {Object=} options
|
||||
* @return {!Uint8Array} Encoded bytes, as a Uint8Array.
|
||||
*/
|
||||
TextEncoder.prototype.encode = function (opt_string, options) {
|
||||
opt_string = opt_string === undefined ? '' : String(opt_string);
|
||||
var optionsMap = ToDictionary(options);
|
||||
// NOTE: This option is nonstandard. None of the encodings
|
||||
// permitted for encoding (i.e. UTF-8, UTF-16) are stateful when
|
||||
// the input is a USVString so streaming is not necessary.
|
||||
if (!this._do_not_flush)
|
||||
this._encoder = encoders[this._encoding.name]({
|
||||
fatal: this._fatal === 'fatal'
|
||||
});
|
||||
this._do_not_flush = Boolean(optionsMap['stream']);
|
||||
// 1. Convert input to a stream.
|
||||
var input = new Stream(stringToCodePoints(opt_string));
|
||||
// 2. Let output be a new stream
|
||||
var output = [];
|
||||
/** @type {?(number|!Array.<number>)} */
|
||||
var result;
|
||||
// 3. While true, run these substeps:
|
||||
while (true) {
|
||||
// 1. Let token be the result of reading from input.
|
||||
var token = input.read();
|
||||
if (token === end_of_stream)
|
||||
break;
|
||||
// 2. Let result be the result of processing token for encoder,
|
||||
// input, output.
|
||||
result = this._encoder.handler(input, token);
|
||||
if (result === finished)
|
||||
break;
|
||||
if (Array.isArray(result))
|
||||
output.push.apply(output, /**@type {!Array.<number>}*/ (result));
|
||||
else
|
||||
output.push(result);
|
||||
}
|
||||
// TODO: Align with spec algorithm.
|
||||
if (!this._do_not_flush) {
|
||||
while (true) {
|
||||
result = this._encoder.handler(input, input.read());
|
||||
if (result === finished)
|
||||
break;
|
||||
if (Array.isArray(result))
|
||||
output.push.apply(output, /**@type {!Array.<number>}*/ (result));
|
||||
else
|
||||
output.push(result);
|
||||
}
|
||||
this._encoder = null;
|
||||
}
|
||||
// 3. If result is finished, convert output into a byte sequence,
|
||||
// and then return a Uint8Array object wrapping an ArrayBuffer
|
||||
// containing output.
|
||||
return new Uint8Array(output);
|
||||
};
|
||||
return TextEncoder;
|
||||
}());
|
||||
export { TextEncoder };
|
||||
//# sourceMappingURL=TextEncoder.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"TextEncoder.js","sourceRoot":"","sources":["../../../src/common/TextEncoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAYlC;;;;G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YACpD,IAAM,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;YAC3B,IAAI,KAAK,KAAK,aAAa;gBACzB,MAAM;YACR,+DAA+D;YAC/D,iBAAiB;YACjB,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAC7C,IAAI,MAAM,KAAK,QAAQ;gBACrB,MAAM;YACR,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;gBACvB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,4BAA4B,CAAA,CAAC,MAAM,CAAC,CAAC,CAAC;;gBAEhE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;SACvB;QACD,mCAAmC;QACnC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACvB,OAAO,IAAI,EAAE;gBACX,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;gBACpD,IAAI,MAAM,KAAK,QAAQ;oBACrB,MAAM;gBACR,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;oBACvB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,4BAA4B,CAAA,CAAC,MAAM,CAAC,CAAC,CAAC;;oBAEhE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;aACvB;YACD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;SACtB;QACD,iEAAiE;QACjE,8DAA8D;QAC9D,qBAAqB;QACrB,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IACH,kBAAC;AAAD,CAAC,AAvID,IAuIC"}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
export * from './Decoder';
|
||||
export * from './Encoder';
|
||||
export * from './Stream';
|
||||
export * from './TextEncoder';
|
||||
export * from './TextDecoder';
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
export * from './Stream';
|
||||
export * from './TextEncoder';
|
||||
export * from './TextDecoder';
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/index.ts"],"names":[],"mappings":"AAEA,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC"}
|
||||
Reference in New Issue
Block a user