document-bytes 1.8.1 → 1.9.0

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.
package/dist/index.d.cts CHANGED
@@ -64,6 +64,12 @@ interface InflateResult {
64
64
  }
65
65
  declare function inflateTolerant(data: Uint8Array<ArrayBuffer>): InflateResult;
66
66
  //#endregion
67
+ //#region src/text/decode-dbcs.d.ts
68
+ /**
69
+ * A legacy multi-byte or double-byte CJK encoding {@link decodeText} can decode when the caller declares it explicitly, decoded by this file's own decoders. Never produced by detection, for the same reason a {@link LegacySingleByteEncodingLabel} never is: nothing distinguishes one of these code pages from another, or from any single-byte encoding, without the statistical model this module does not carry (see {@link TextEncodingLabel}). `gbk` and `gb18030` share one decoder ({@link decodeGb18030}) because the Encoding Standard defines GBK's decoder as gb18030's own (https://encoding.spec.whatwg.org/#gbk-decoder).
70
+ */
71
+ type DbcsEncodingLabel = "shift_jis" | "euc-jp" | "euc-kr" | "gbk" | "gb18030" | "big5";
72
+ //#endregion
67
73
  //#region src/text/legacy-single-byte-tables.d.ts
68
74
  /** A legacy single-byte encoding {@link decodeText} can decode when the caller declares it explicitly. Never produced by detection: nothing distinguishes one of these code pages from another, or from windows-1252, without the statistical model this module does not carry (see {@link TextEncodingLabel}). */
69
75
  type LegacySingleByteEncodingLabel = "ibm866" | "iso-8859-2" | "iso-8859-3" | "iso-8859-4" | "iso-8859-5" | "iso-8859-6" | "iso-8859-7" | "iso-8859-8" | "iso-8859-8-i" | "iso-8859-10" | "iso-8859-13" | "iso-8859-14" | "iso-8859-15" | "iso-8859-16" | "koi8-r" | "koi8-u" | "macintosh" | "windows-874" | "windows-1250" | "windows-1251" | "windows-1253" | "windows-1254" | "windows-1255" | "windows-1256" | "windows-1257" | "windows-1258" | "x-mac-cyrillic";
@@ -74,9 +80,9 @@ type LegacySingleByteEncodingLabel = "ibm866" | "iso-8859-2" | "iso-8859-3" | "i
74
80
  *
75
81
  * Detection stays deliberately bounded to `"utf-8"`, `"utf-16le"`, `"utf-16be"`, `"utf-32le"`, `"utf-32be"` and `"windows-1252"`: each of those is either self-identifying through a byte order mark, structurally checkable through its own validity rules, or guessable behind a stated plausibility test, and nothing distinguishes one legacy code page from another, or from windows-1252, without the statistical model this module does not carry. Bytes that look like an undetected legacy encoding are refused rather than guessed at.
76
82
  *
77
- * {@link DecodeTextOptions.encoding} can name more than detection can reach, though: every {@link LegacySingleByteEncodingLabel} the WHATWG Encoding Standard defines is also accepted, for a caller who already knows their file's code page rather than asking this module to guess it (ExaDev/documents.js#1361). Legacy multi-byte and double-byte CJK encodings (Shift_JIS, EUC-JP, ISO-2022-JP, GBK, gb18030, Big5, EUC-KR) remain outside what either detection or a declared `encoding` can reach; see legacy-single-byte-tables.ts for why that is a different kind of change, tracked separately as ExaDev/documents.js#1388.
83
+ * {@link DecodeTextOptions.encoding} can name more than detection can reach, though: every {@link LegacySingleByteEncodingLabel} the WHATWG Encoding Standard defines is also accepted, for a caller who already knows their file's code page rather than asking this module to guess it (ExaDev/documents.js#1361), and so is every {@link DbcsEncodingLabel} — the standard's legacy multi-byte and double-byte CJK encodings, Shift_JIS, EUC-JP, EUC-KR, GBK, gb18030 and Big5, decoded against decode-dbcs.ts's own generated index tables for the same reason (ExaDev/documents.js#1388). ISO-2022-JP, the one legacy CJK encoding that is a genuine escape-sequence state machine rather than a byte-width decoder, is tracked as its own follow-on to #1388 rather than bundled in here.
78
84
  */
79
- type TextEncodingLabel = "utf-8" | "utf-16le" | "utf-16be" | "utf-32le" | "utf-32be" | "windows-1252" | LegacySingleByteEncodingLabel;
85
+ type TextEncodingLabel = "utf-8" | "utf-16le" | "utf-16be" | "utf-32le" | "utf-32be" | "windows-1252" | LegacySingleByteEncodingLabel | DbcsEncodingLabel;
80
86
  /**
81
87
  * How {@link decodeText} arrived at the encoding it used.
82
88
  *
@@ -121,6 +127,18 @@ declare class UndecodableTextError extends Error {
121
127
  * Exported so tests can place inputs on and around a chunk boundary without repeating the figure.
122
128
  */
123
129
  declare const TEXT_DECODE_CHUNK_CODE_UNITS: number;
130
+ /**
131
+ * Splits `codePoint` into one or two UTF-16 code units and pushes them onto `units`: the code point itself below the supplementary plane, a surrogate pair biased by {@link SURROGATE_BITS} and {@link LOW_SURROGATE_MASK} above it. Shared by every decoder here that can produce a code point outside the Basic Multilingual Plane — {@link decodeUtf32} for UTF-32's own scalar values, and decode-dbcs.ts's decoders for the WHATWG index tables' own supplementary-plane entries (Big5's CJK Compatibility Ideographs Supplement pointers, gb18030's final algorithmic range) — so the split happens in exactly one place rather than once per caller.
132
+ * @param units - The code unit array to push onto, in place.
133
+ * @param codePoint - A Unicode scalar value in the range 0 to {@link MAX_CODE_POINT}.
134
+ */
135
+ declare function appendCodePoint(units: number[], codePoint: number): void;
136
+ /**
137
+ * Converts a sequence of UTF-16 code units to a string in fixed-size chunks (see {@link TEXT_DECODE_CHUNK_CODE_UNITS}), shared by every decoder in this module and in decode-dbcs.ts so each collects code units into a plain array and calls this once at the end rather than concatenating a string one character at a time.
138
+ * @param units - The code units to convert, in order.
139
+ * @returns The resulting string.
140
+ */
141
+ declare function fromCodeUnits(units: readonly number[]): string;
124
142
  /** A byte order mark's own encoding, and how many leading bytes it occupies. */
125
143
  interface ByteOrderMark {
126
144
  /** The encoding the mark identifies. */
@@ -216,4 +234,4 @@ interface JpegInfo {
216
234
  }
217
235
  declare function readJpegInfo(bytes: Uint8Array<ArrayBuffer>): JpegInfo;
218
236
  //#endregion
219
- export { BASE64_ENCODE_CHUNK_CHARS, ByteOrderMark, ByteReader, ByteWriter, DecodeTextOptions, DecodedText, DecodedTextConfidence, DecodedTextSource, DeflateLevel, InflateResult, JpegInfo, MAX_INFLATE_OUTPUT_BYTES, PNG_MAX_DIMENSION, PNG_MAX_PIXELS, PngDecodeOptions, PngEncodeOptions, PngFilterType, RawImage, TEXT_DECODE_CHUNK_CODE_UNITS, TextEncodingLabel, UndecodableTextError, UndecodableTextReason, base64ToBytes, bytesToBase64, concatBytes, crc32, decodePng, decodeText, deflate, detectByteOrderMark, encodePng, exceedsMaxPixelCount, filterScanlines, inflate, inflateTolerant, isAsciiWhitespace, isProbablyText, readJpegInfo, resolveEncodingLabel, tryDecodeText, unfilterScanlines };
237
+ export { BASE64_ENCODE_CHUNK_CHARS, ByteOrderMark, ByteReader, ByteWriter, DecodeTextOptions, DecodedText, DecodedTextConfidence, DecodedTextSource, DeflateLevel, InflateResult, JpegInfo, MAX_INFLATE_OUTPUT_BYTES, PNG_MAX_DIMENSION, PNG_MAX_PIXELS, PngDecodeOptions, PngEncodeOptions, PngFilterType, RawImage, TEXT_DECODE_CHUNK_CODE_UNITS, TextEncodingLabel, UndecodableTextError, UndecodableTextReason, appendCodePoint, base64ToBytes, bytesToBase64, concatBytes, crc32, decodePng, decodeText, deflate, detectByteOrderMark, encodePng, exceedsMaxPixelCount, filterScanlines, fromCodeUnits, inflate, inflateTolerant, isAsciiWhitespace, isProbablyText, readJpegInfo, resolveEncodingLabel, tryDecodeText, unfilterScanlines };
package/dist/index.d.ts CHANGED
@@ -64,6 +64,12 @@ interface InflateResult {
64
64
  }
65
65
  declare function inflateTolerant(data: Uint8Array<ArrayBuffer>): InflateResult;
66
66
  //#endregion
67
+ //#region src/text/decode-dbcs.d.ts
68
+ /**
69
+ * A legacy multi-byte or double-byte CJK encoding {@link decodeText} can decode when the caller declares it explicitly, decoded by this file's own decoders. Never produced by detection, for the same reason a {@link LegacySingleByteEncodingLabel} never is: nothing distinguishes one of these code pages from another, or from any single-byte encoding, without the statistical model this module does not carry (see {@link TextEncodingLabel}). `gbk` and `gb18030` share one decoder ({@link decodeGb18030}) because the Encoding Standard defines GBK's decoder as gb18030's own (https://encoding.spec.whatwg.org/#gbk-decoder).
70
+ */
71
+ type DbcsEncodingLabel = "shift_jis" | "euc-jp" | "euc-kr" | "gbk" | "gb18030" | "big5";
72
+ //#endregion
67
73
  //#region src/text/legacy-single-byte-tables.d.ts
68
74
  /** A legacy single-byte encoding {@link decodeText} can decode when the caller declares it explicitly. Never produced by detection: nothing distinguishes one of these code pages from another, or from windows-1252, without the statistical model this module does not carry (see {@link TextEncodingLabel}). */
69
75
  type LegacySingleByteEncodingLabel = "ibm866" | "iso-8859-2" | "iso-8859-3" | "iso-8859-4" | "iso-8859-5" | "iso-8859-6" | "iso-8859-7" | "iso-8859-8" | "iso-8859-8-i" | "iso-8859-10" | "iso-8859-13" | "iso-8859-14" | "iso-8859-15" | "iso-8859-16" | "koi8-r" | "koi8-u" | "macintosh" | "windows-874" | "windows-1250" | "windows-1251" | "windows-1253" | "windows-1254" | "windows-1255" | "windows-1256" | "windows-1257" | "windows-1258" | "x-mac-cyrillic";
@@ -74,9 +80,9 @@ type LegacySingleByteEncodingLabel = "ibm866" | "iso-8859-2" | "iso-8859-3" | "i
74
80
  *
75
81
  * Detection stays deliberately bounded to `"utf-8"`, `"utf-16le"`, `"utf-16be"`, `"utf-32le"`, `"utf-32be"` and `"windows-1252"`: each of those is either self-identifying through a byte order mark, structurally checkable through its own validity rules, or guessable behind a stated plausibility test, and nothing distinguishes one legacy code page from another, or from windows-1252, without the statistical model this module does not carry. Bytes that look like an undetected legacy encoding are refused rather than guessed at.
76
82
  *
77
- * {@link DecodeTextOptions.encoding} can name more than detection can reach, though: every {@link LegacySingleByteEncodingLabel} the WHATWG Encoding Standard defines is also accepted, for a caller who already knows their file's code page rather than asking this module to guess it (ExaDev/documents.js#1361). Legacy multi-byte and double-byte CJK encodings (Shift_JIS, EUC-JP, ISO-2022-JP, GBK, gb18030, Big5, EUC-KR) remain outside what either detection or a declared `encoding` can reach; see legacy-single-byte-tables.ts for why that is a different kind of change, tracked separately as ExaDev/documents.js#1388.
83
+ * {@link DecodeTextOptions.encoding} can name more than detection can reach, though: every {@link LegacySingleByteEncodingLabel} the WHATWG Encoding Standard defines is also accepted, for a caller who already knows their file's code page rather than asking this module to guess it (ExaDev/documents.js#1361), and so is every {@link DbcsEncodingLabel} — the standard's legacy multi-byte and double-byte CJK encodings, Shift_JIS, EUC-JP, EUC-KR, GBK, gb18030 and Big5, decoded against decode-dbcs.ts's own generated index tables for the same reason (ExaDev/documents.js#1388). ISO-2022-JP, the one legacy CJK encoding that is a genuine escape-sequence state machine rather than a byte-width decoder, is tracked as its own follow-on to #1388 rather than bundled in here.
78
84
  */
79
- type TextEncodingLabel = "utf-8" | "utf-16le" | "utf-16be" | "utf-32le" | "utf-32be" | "windows-1252" | LegacySingleByteEncodingLabel;
85
+ type TextEncodingLabel = "utf-8" | "utf-16le" | "utf-16be" | "utf-32le" | "utf-32be" | "windows-1252" | LegacySingleByteEncodingLabel | DbcsEncodingLabel;
80
86
  /**
81
87
  * How {@link decodeText} arrived at the encoding it used.
82
88
  *
@@ -121,6 +127,18 @@ declare class UndecodableTextError extends Error {
121
127
  * Exported so tests can place inputs on and around a chunk boundary without repeating the figure.
122
128
  */
123
129
  declare const TEXT_DECODE_CHUNK_CODE_UNITS: number;
130
+ /**
131
+ * Splits `codePoint` into one or two UTF-16 code units and pushes them onto `units`: the code point itself below the supplementary plane, a surrogate pair biased by {@link SURROGATE_BITS} and {@link LOW_SURROGATE_MASK} above it. Shared by every decoder here that can produce a code point outside the Basic Multilingual Plane — {@link decodeUtf32} for UTF-32's own scalar values, and decode-dbcs.ts's decoders for the WHATWG index tables' own supplementary-plane entries (Big5's CJK Compatibility Ideographs Supplement pointers, gb18030's final algorithmic range) — so the split happens in exactly one place rather than once per caller.
132
+ * @param units - The code unit array to push onto, in place.
133
+ * @param codePoint - A Unicode scalar value in the range 0 to {@link MAX_CODE_POINT}.
134
+ */
135
+ declare function appendCodePoint(units: number[], codePoint: number): void;
136
+ /**
137
+ * Converts a sequence of UTF-16 code units to a string in fixed-size chunks (see {@link TEXT_DECODE_CHUNK_CODE_UNITS}), shared by every decoder in this module and in decode-dbcs.ts so each collects code units into a plain array and calls this once at the end rather than concatenating a string one character at a time.
138
+ * @param units - The code units to convert, in order.
139
+ * @returns The resulting string.
140
+ */
141
+ declare function fromCodeUnits(units: readonly number[]): string;
124
142
  /** A byte order mark's own encoding, and how many leading bytes it occupies. */
125
143
  interface ByteOrderMark {
126
144
  /** The encoding the mark identifies. */
@@ -216,4 +234,4 @@ interface JpegInfo {
216
234
  }
217
235
  declare function readJpegInfo(bytes: Uint8Array<ArrayBuffer>): JpegInfo;
218
236
  //#endregion
219
- export { BASE64_ENCODE_CHUNK_CHARS, ByteOrderMark, ByteReader, ByteWriter, DecodeTextOptions, DecodedText, DecodedTextConfidence, DecodedTextSource, DeflateLevel, InflateResult, JpegInfo, MAX_INFLATE_OUTPUT_BYTES, PNG_MAX_DIMENSION, PNG_MAX_PIXELS, PngDecodeOptions, PngEncodeOptions, PngFilterType, RawImage, TEXT_DECODE_CHUNK_CODE_UNITS, TextEncodingLabel, UndecodableTextError, UndecodableTextReason, base64ToBytes, bytesToBase64, concatBytes, crc32, decodePng, decodeText, deflate, detectByteOrderMark, encodePng, exceedsMaxPixelCount, filterScanlines, inflate, inflateTolerant, isAsciiWhitespace, isProbablyText, readJpegInfo, resolveEncodingLabel, tryDecodeText, unfilterScanlines };
237
+ export { BASE64_ENCODE_CHUNK_CHARS, ByteOrderMark, ByteReader, ByteWriter, DecodeTextOptions, DecodedText, DecodedTextConfidence, DecodedTextSource, DeflateLevel, InflateResult, JpegInfo, MAX_INFLATE_OUTPUT_BYTES, PNG_MAX_DIMENSION, PNG_MAX_PIXELS, PngDecodeOptions, PngEncodeOptions, PngFilterType, RawImage, TEXT_DECODE_CHUNK_CODE_UNITS, TextEncodingLabel, UndecodableTextError, UndecodableTextReason, appendCodePoint, base64ToBytes, bytesToBase64, concatBytes, crc32, decodePng, decodeText, deflate, detectByteOrderMark, encodePng, exceedsMaxPixelCount, filterScanlines, fromCodeUnits, inflate, inflateTolerant, isAsciiWhitespace, isProbablyText, readJpegInfo, resolveEncodingLabel, tryDecodeText, unfilterScanlines };