js.documents 12.1.0 → 14.0.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.
Files changed (58) hide show
  1. package/README.md +1 -1
  2. package/dist/codecs/read.cjs +1 -1
  3. package/dist/codecs/read.js +1 -1
  4. package/dist/codecs/registry.cjs +1 -1
  5. package/dist/codecs/registry.js +1 -1
  6. package/dist/convert/composition.cjs +1 -1
  7. package/dist/convert/composition.js +1 -1
  8. package/dist/edit/docx/content.cjs +1 -0
  9. package/dist/edit/docx/content.js +1 -0
  10. package/dist/edit/docx/table.cjs +14 -0
  11. package/dist/edit/docx/table.d.cts +2 -0
  12. package/dist/edit/docx/table.d.ts +2 -0
  13. package/dist/edit/docx/table.js +14 -0
  14. package/dist/edit/odf-repeated-runs.cjs +99 -0
  15. package/dist/edit/odf-repeated-runs.d.cts +22 -0
  16. package/dist/edit/odf-repeated-runs.d.ts +22 -0
  17. package/dist/edit/odf-repeated-runs.js +87 -0
  18. package/dist/edit/odp/slide.d.cts +1 -1
  19. package/dist/edit/odp/slide.d.ts +1 -1
  20. package/dist/edit/ods/address.cjs +9 -101
  21. package/dist/edit/ods/address.d.cts +2 -18
  22. package/dist/edit/ods/address.d.ts +2 -18
  23. package/dist/edit/ods/address.js +4 -86
  24. package/dist/edit/ods/column-row.cjs +7 -6
  25. package/dist/edit/ods/column-row.js +2 -1
  26. package/dist/edit/ods/floating.cjs +5 -4
  27. package/dist/edit/ods/floating.js +2 -1
  28. package/dist/edit/ods/print-settings.cjs +8 -7
  29. package/dist/edit/ods/print-settings.js +2 -1
  30. package/dist/edit/ods/sheet.cjs +2 -1
  31. package/dist/edit/ods/sheet.js +2 -1
  32. package/dist/edit/odt/content.cjs +2 -0
  33. package/dist/edit/odt/content.d.cts +1 -1
  34. package/dist/edit/odt/content.d.ts +1 -1
  35. package/dist/edit/odt/content.js +2 -0
  36. package/dist/edit/odt/editor.d.cts +1 -1
  37. package/dist/edit/odt/editor.d.ts +1 -1
  38. package/dist/edit/odt/table.cjs +114 -22
  39. package/dist/edit/odt/table.d.cts +1 -1
  40. package/dist/edit/odt/table.d.ts +1 -1
  41. package/dist/edit/odt/table.js +114 -22
  42. package/dist/index.cjs +3 -2
  43. package/dist/index.d.cts +3 -3
  44. package/dist/index.d.ts +3 -3
  45. package/dist/index.js +2 -2
  46. package/dist/model/bytes.cjs +5 -8
  47. package/dist/model/bytes.js +5 -8
  48. package/dist/svg/text.cjs +41 -8
  49. package/dist/svg/text.d.cts +25 -3
  50. package/dist/svg/text.d.ts +25 -3
  51. package/dist/svg/text.js +40 -8
  52. package/dist/svg/xml-encoding.cjs +91 -0
  53. package/dist/svg/xml-encoding.d.cts +32 -0
  54. package/dist/svg/xml-encoding.d.ts +32 -0
  55. package/dist/svg/xml-encoding.js +88 -0
  56. package/dist/{table-BT3wN3Hd.d.cts → table-Bt9ahRyh.d.cts} +2 -0
  57. package/dist/{table-DhTy5Re7.d.ts → table-Cou5rKOo.d.ts} +2 -0
  58. package/package.json +14 -14
@@ -1,8 +1,30 @@
1
+ import { TextEncodingLabel, UndecodableTextError } from "byte-codec";
1
2
  //#region src/svg/text.d.ts
2
- declare class SvgInvalidUtf8Error extends Error {
3
- constructor();
3
+ /** Thrown when an SVG document's own `<?xml ... encoding="..."?>` declaration names an encoding outside byte-codec's own bounded decodeText set: a legacy CJK or Cyrillic code page, or a name this package does not recognise as an alias of one of the six it does support (ExaDev/documents.js#1361). */
4
+ declare class SvgUnsupportedEncodingError extends Error {
5
+ /** The declaration's own raw label, exactly as written in the document. */
6
+ readonly label: string;
7
+ constructor(label: string);
4
8
  }
9
+ /** Thrown when svg bytes cannot be decoded as text under the encoding that settled it: a byte order mark or an `<?xml ...?>` declaration named one the bytes then contradict, or, with neither present, the bytes are not well-formed UTF-8, XML's own default. */
10
+ declare class SvgUndecodableTextError extends Error {
11
+ /** The encoding the bytes were decoded against and failed. */
12
+ readonly encoding: TextEncodingLabel;
13
+ constructor(encoding: TextEncodingLabel, cause: UndecodableTextError);
14
+ }
15
+ /**
16
+ * Decodes svg bytes to text, honouring the encoding a byte order mark or an `<?xml ...?>` declaration names and defaulting to strict UTF-8, XML's own default, when neither is present.
17
+ * @param bytes - The svg bytes.
18
+ * @throws SvgUnsupportedEncodingError When the declaration names an encoding outside byte-codec's own bounded set.
19
+ * @throws SvgUndecodableTextError When the bytes contradict the encoding that settled them.
20
+ * @returns The svg text.
21
+ */
5
22
  declare function decodeSvgText(bytes: Uint8Array): string;
23
+ /**
24
+ * Encodes svg text as UTF-8 bytes, with no `<?xml ...?>` declaration of its own.
25
+ * @param text - The svg text.
26
+ * @returns The UTF-8 bytes. A byte stream with no declaration and no byte order mark is UTF-8 under XML's own default, so {@link decodeSvgText} reads it back correctly without one.
27
+ */
6
28
  declare function encodeSvgText(text: string): Uint8Array<ArrayBuffer>;
7
29
  //#endregion
8
- export { SvgInvalidUtf8Error, decodeSvgText, encodeSvgText };
30
+ export { SvgUndecodableTextError, SvgUnsupportedEncodingError, decodeSvgText, encodeSvgText };
@@ -1,8 +1,30 @@
1
+ import { TextEncodingLabel, UndecodableTextError } from "byte-codec";
1
2
  //#region src/svg/text.d.ts
2
- declare class SvgInvalidUtf8Error extends Error {
3
- constructor();
3
+ /** Thrown when an SVG document's own `<?xml ... encoding="..."?>` declaration names an encoding outside byte-codec's own bounded decodeText set: a legacy CJK or Cyrillic code page, or a name this package does not recognise as an alias of one of the six it does support (ExaDev/documents.js#1361). */
4
+ declare class SvgUnsupportedEncodingError extends Error {
5
+ /** The declaration's own raw label, exactly as written in the document. */
6
+ readonly label: string;
7
+ constructor(label: string);
4
8
  }
9
+ /** Thrown when svg bytes cannot be decoded as text under the encoding that settled it: a byte order mark or an `<?xml ...?>` declaration named one the bytes then contradict, or, with neither present, the bytes are not well-formed UTF-8, XML's own default. */
10
+ declare class SvgUndecodableTextError extends Error {
11
+ /** The encoding the bytes were decoded against and failed. */
12
+ readonly encoding: TextEncodingLabel;
13
+ constructor(encoding: TextEncodingLabel, cause: UndecodableTextError);
14
+ }
15
+ /**
16
+ * Decodes svg bytes to text, honouring the encoding a byte order mark or an `<?xml ...?>` declaration names and defaulting to strict UTF-8, XML's own default, when neither is present.
17
+ * @param bytes - The svg bytes.
18
+ * @throws SvgUnsupportedEncodingError When the declaration names an encoding outside byte-codec's own bounded set.
19
+ * @throws SvgUndecodableTextError When the bytes contradict the encoding that settled them.
20
+ * @returns The svg text.
21
+ */
5
22
  declare function decodeSvgText(bytes: Uint8Array): string;
23
+ /**
24
+ * Encodes svg text as UTF-8 bytes, with no `<?xml ...?>` declaration of its own.
25
+ * @param text - The svg text.
26
+ * @returns The UTF-8 bytes. A byte stream with no declaration and no byte order mark is UTF-8 under XML's own default, so {@link decodeSvgText} reads it back correctly without one.
27
+ */
6
28
  declare function encodeSvgText(text: string): Uint8Array<ArrayBuffer>;
7
29
  //#endregion
8
- export { SvgInvalidUtf8Error, decodeSvgText, encodeSvgText };
30
+ export { SvgUndecodableTextError, SvgUnsupportedEncodingError, decodeSvgText, encodeSvgText };
package/dist/svg/text.js CHANGED
@@ -1,19 +1,51 @@
1
+ import { detectSvgEncoding } from "./xml-encoding.js";
2
+ import { UndecodableTextError, decodeText } from "byte-codec";
1
3
  //#region src/svg/text.ts
2
- var SvgInvalidUtf8Error = class extends Error {
3
- constructor() {
4
- super("svg text must be well-formed UTF-8");
5
- this.name = "SvgInvalidUtf8Error";
4
+ /** Thrown when an SVG document's own `<?xml ... encoding="..."?>` declaration names an encoding outside byte-codec's own bounded decodeText set: a legacy CJK or Cyrillic code page, or a name this package does not recognise as an alias of one of the six it does support (ExaDev/documents.js#1361). */
5
+ var SvgUnsupportedEncodingError = class extends Error {
6
+ /** The declaration's own raw label, exactly as written in the document. */
7
+ label;
8
+ constructor(label) {
9
+ super(`svg declares an encoding this package cannot decode: "${label}" (ExaDev/documents.js#1361)`);
10
+ this.name = "SvgUnsupportedEncodingError";
11
+ this.label = label;
6
12
  }
7
13
  };
14
+ /** Thrown when svg bytes cannot be decoded as text under the encoding that settled it: a byte order mark or an `<?xml ...?>` declaration named one the bytes then contradict, or, with neither present, the bytes are not well-formed UTF-8, XML's own default. */
15
+ var SvgUndecodableTextError = class extends Error {
16
+ /** The encoding the bytes were decoded against and failed. */
17
+ encoding;
18
+ constructor(encoding, cause) {
19
+ super(`svg bytes are not well-formed ${encoding}: ${cause.message}`, { cause });
20
+ this.name = "SvgUndecodableTextError";
21
+ this.encoding = encoding;
22
+ }
23
+ };
24
+ /**
25
+ * Decodes svg bytes to text, honouring the encoding a byte order mark or an `<?xml ...?>` declaration names and defaulting to strict UTF-8, XML's own default, when neither is present.
26
+ * @param bytes - The svg bytes.
27
+ * @throws SvgUnsupportedEncodingError When the declaration names an encoding outside byte-codec's own bounded set.
28
+ * @throws SvgUndecodableTextError When the bytes contradict the encoding that settled them.
29
+ * @returns The svg text.
30
+ */
8
31
  function decodeSvgText(bytes) {
32
+ const detected = detectSvgEncoding(bytes);
33
+ if (detected?.kind === "unsupported") throw new SvgUnsupportedEncodingError(detected.label);
34
+ const encoding = detected?.encoding ?? "utf-8";
9
35
  try {
10
- return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
11
- } catch {
12
- throw new SvgInvalidUtf8Error();
36
+ return decodeText(bytes, { encoding }).text;
37
+ } catch (error) {
38
+ if (error instanceof UndecodableTextError) throw new SvgUndecodableTextError(encoding, error);
39
+ throw error;
13
40
  }
14
41
  }
42
+ /**
43
+ * Encodes svg text as UTF-8 bytes, with no `<?xml ...?>` declaration of its own.
44
+ * @param text - The svg text.
45
+ * @returns The UTF-8 bytes. A byte stream with no declaration and no byte order mark is UTF-8 under XML's own default, so {@link decodeSvgText} reads it back correctly without one.
46
+ */
15
47
  function encodeSvgText(text) {
16
48
  return new TextEncoder().encode(text);
17
49
  }
18
50
  //#endregion
19
- export { SvgInvalidUtf8Error, decodeSvgText, encodeSvgText };
51
+ export { SvgUndecodableTextError, SvgUnsupportedEncodingError, decodeSvgText, encodeSvgText };
@@ -0,0 +1,91 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let byte_codec = require("byte-codec");
3
+ //#region src/svg/xml-encoding.ts
4
+ const XML_ENCODING_ALIASES = {
5
+ "utf-8": "utf-8",
6
+ utf8: "utf-8",
7
+ "unicode-1-1-utf-8": "utf-8",
8
+ unicode11utf8: "utf-8",
9
+ unicode20utf8: "utf-8",
10
+ "x-unicode20utf8": "utf-8",
11
+ "utf-16le": "utf-16le",
12
+ "utf-16": "utf-16le",
13
+ "ucs-2": "utf-16le",
14
+ unicode: "utf-16le",
15
+ unicodefeff: "utf-16le",
16
+ csunicode: "utf-16le",
17
+ "iso-10646-ucs-2": "utf-16le",
18
+ "utf-16be": "utf-16be",
19
+ unicodefffe: "utf-16be",
20
+ "utf-32le": "utf-32le",
21
+ "utf-32be": "utf-32be",
22
+ "windows-1252": "windows-1252",
23
+ cp1252: "windows-1252",
24
+ "x-cp1252": "windows-1252",
25
+ "iso-8859-1": "windows-1252",
26
+ "iso8859-1": "windows-1252",
27
+ "iso_8859-1": "windows-1252",
28
+ "iso_8859-1:1987": "windows-1252",
29
+ "iso-ir-100": "windows-1252",
30
+ csisolatin1: "windows-1252",
31
+ l1: "windows-1252",
32
+ latin1: "windows-1252",
33
+ cp819: "windows-1252",
34
+ ibm819: "windows-1252",
35
+ "us-ascii": "windows-1252",
36
+ ascii: "windows-1252",
37
+ "ansi_x3.4-1968": "windows-1252"
38
+ };
39
+ /**
40
+ * Maps a name from an XML encoding declaration onto the encoding byte-codec's decodeText would decode it under, matched case-insensitively against the WHATWG Encoding Standard's own label table (restricted to the six encodings decodeText supports).
41
+ * @param label - The declaration's raw `encoding` value, exactly as written.
42
+ * @returns The matching {@link TextEncodingLabel}, or `undefined` when the name is outside decodeText's own bounded set (ExaDev/documents.js#1361).
43
+ */
44
+ function mapXmlEncodingLabel(label) {
45
+ return XML_ENCODING_ALIASES[label.toLowerCase()];
46
+ }
47
+ const XML_DECLARATION_SEARCH_WINDOW = 512;
48
+ const XML_DECLARATION_START = "<?xml";
49
+ const XML_ENCODING_DECL_PATTERN = /\bencoding\s*=\s*(["'])([A-Za-z][A-Za-z0-9._-]*)\1/;
50
+ /**
51
+ * Reads the raw encoding label out of an `<?xml ...?>` declaration's own leading bytes, without decoding anything.
52
+ *
53
+ * Safe ahead of any real decode because the declaration's own grammar restricts every character in it to ASCII: XML mandates that a declaration, if present, start at the very first byte (a byte order mark aside), so bytes not beginning with the literal ASCII sequence `<?xml` carry no declaration to read, and bytes that do keep writing ASCII up to and including the encoding name itself, whatever that name turns out to be.
54
+ * @param bytes - The document's own leading bytes.
55
+ * @returns The declaration's raw `encoding` value, exactly as written, or `undefined` when the leading bytes carry no `<?xml ...?>` declaration, or that declaration names no encoding.
56
+ */
57
+ function readXmlEncodingDeclarationLabel(bytes) {
58
+ const windowLength = Math.min(bytes.length, XML_DECLARATION_SEARCH_WINDOW);
59
+ let window = "";
60
+ for (let index = 0; index < windowLength; index += 1) window += String.fromCharCode(bytes[index]);
61
+ if (!window.startsWith(XML_DECLARATION_START)) return;
62
+ const declarationEnd = window.indexOf("?>");
63
+ const declaration = declarationEnd === -1 ? window : window.slice(0, declarationEnd);
64
+ return XML_ENCODING_DECL_PATTERN.exec(declaration)?.[2];
65
+ }
66
+ /**
67
+ * Detects the encoding SVG's own XML prolog declares, per XML 1.0's own external-encoding-detection algorithm: a byte order mark first, since it needs no decoding to trust, then the `<?xml ... encoding="..."?>` declaration.
68
+ * @param bytes - The document's own leading bytes.
69
+ * @returns How the encoding was settled, or `undefined` when the leading bytes carry neither a byte order mark nor a declared encoding. XML's own default of UTF-8 applies in that case, left for the caller to decode strictly rather than through decodeText's own guessing.
70
+ */
71
+ function detectSvgEncoding(bytes) {
72
+ const bom = (0, byte_codec.detectByteOrderMark)(bytes);
73
+ if (bom !== void 0) return {
74
+ kind: "resolved",
75
+ encoding: bom.encoding
76
+ };
77
+ const label = readXmlEncodingDeclarationLabel(bytes);
78
+ if (label === void 0) return;
79
+ const encoding = mapXmlEncodingLabel(label);
80
+ return encoding === void 0 ? {
81
+ kind: "unsupported",
82
+ label
83
+ } : {
84
+ kind: "resolved",
85
+ encoding
86
+ };
87
+ }
88
+ //#endregion
89
+ exports.detectSvgEncoding = detectSvgEncoding;
90
+ exports.mapXmlEncodingLabel = mapXmlEncodingLabel;
91
+ exports.readXmlEncodingDeclarationLabel = readXmlEncodingDeclarationLabel;
@@ -0,0 +1,32 @@
1
+ import { TextEncodingLabel } from "byte-codec";
2
+ //#region src/svg/xml-encoding.d.ts
3
+ /**
4
+ * Maps a name from an XML encoding declaration onto the encoding byte-codec's decodeText would decode it under, matched case-insensitively against the WHATWG Encoding Standard's own label table (restricted to the six encodings decodeText supports).
5
+ * @param label - The declaration's raw `encoding` value, exactly as written.
6
+ * @returns The matching {@link TextEncodingLabel}, or `undefined` when the name is outside decodeText's own bounded set (ExaDev/documents.js#1361).
7
+ */
8
+ declare function mapXmlEncodingLabel(label: string): TextEncodingLabel | undefined;
9
+ /**
10
+ * Reads the raw encoding label out of an `<?xml ...?>` declaration's own leading bytes, without decoding anything.
11
+ *
12
+ * Safe ahead of any real decode because the declaration's own grammar restricts every character in it to ASCII: XML mandates that a declaration, if present, start at the very first byte (a byte order mark aside), so bytes not beginning with the literal ASCII sequence `<?xml` carry no declaration to read, and bytes that do keep writing ASCII up to and including the encoding name itself, whatever that name turns out to be.
13
+ * @param bytes - The document's own leading bytes.
14
+ * @returns The declaration's raw `encoding` value, exactly as written, or `undefined` when the leading bytes carry no `<?xml ...?>` declaration, or that declaration names no encoding.
15
+ */
16
+ declare function readXmlEncodingDeclarationLabel(bytes: Uint8Array): string | undefined;
17
+ /** How {@link detectSvgEncoding} settled the encoding: `resolved` when a byte order mark or a declaration named one decodeText can decode, `unsupported` when a declaration named something outside decodeText's own bounded set. */
18
+ type SvgEncodingDetection = {
19
+ readonly kind: "resolved";
20
+ readonly encoding: TextEncodingLabel;
21
+ } | {
22
+ readonly kind: "unsupported";
23
+ readonly label: string;
24
+ };
25
+ /**
26
+ * Detects the encoding SVG's own XML prolog declares, per XML 1.0's own external-encoding-detection algorithm: a byte order mark first, since it needs no decoding to trust, then the `<?xml ... encoding="..."?>` declaration.
27
+ * @param bytes - The document's own leading bytes.
28
+ * @returns How the encoding was settled, or `undefined` when the leading bytes carry neither a byte order mark nor a declared encoding. XML's own default of UTF-8 applies in that case, left for the caller to decode strictly rather than through decodeText's own guessing.
29
+ */
30
+ declare function detectSvgEncoding(bytes: Uint8Array): SvgEncodingDetection | undefined;
31
+ //#endregion
32
+ export { SvgEncodingDetection, detectSvgEncoding, mapXmlEncodingLabel, readXmlEncodingDeclarationLabel };
@@ -0,0 +1,32 @@
1
+ import { TextEncodingLabel } from "byte-codec";
2
+ //#region src/svg/xml-encoding.d.ts
3
+ /**
4
+ * Maps a name from an XML encoding declaration onto the encoding byte-codec's decodeText would decode it under, matched case-insensitively against the WHATWG Encoding Standard's own label table (restricted to the six encodings decodeText supports).
5
+ * @param label - The declaration's raw `encoding` value, exactly as written.
6
+ * @returns The matching {@link TextEncodingLabel}, or `undefined` when the name is outside decodeText's own bounded set (ExaDev/documents.js#1361).
7
+ */
8
+ declare function mapXmlEncodingLabel(label: string): TextEncodingLabel | undefined;
9
+ /**
10
+ * Reads the raw encoding label out of an `<?xml ...?>` declaration's own leading bytes, without decoding anything.
11
+ *
12
+ * Safe ahead of any real decode because the declaration's own grammar restricts every character in it to ASCII: XML mandates that a declaration, if present, start at the very first byte (a byte order mark aside), so bytes not beginning with the literal ASCII sequence `<?xml` carry no declaration to read, and bytes that do keep writing ASCII up to and including the encoding name itself, whatever that name turns out to be.
13
+ * @param bytes - The document's own leading bytes.
14
+ * @returns The declaration's raw `encoding` value, exactly as written, or `undefined` when the leading bytes carry no `<?xml ...?>` declaration, or that declaration names no encoding.
15
+ */
16
+ declare function readXmlEncodingDeclarationLabel(bytes: Uint8Array): string | undefined;
17
+ /** How {@link detectSvgEncoding} settled the encoding: `resolved` when a byte order mark or a declaration named one decodeText can decode, `unsupported` when a declaration named something outside decodeText's own bounded set. */
18
+ type SvgEncodingDetection = {
19
+ readonly kind: "resolved";
20
+ readonly encoding: TextEncodingLabel;
21
+ } | {
22
+ readonly kind: "unsupported";
23
+ readonly label: string;
24
+ };
25
+ /**
26
+ * Detects the encoding SVG's own XML prolog declares, per XML 1.0's own external-encoding-detection algorithm: a byte order mark first, since it needs no decoding to trust, then the `<?xml ... encoding="..."?>` declaration.
27
+ * @param bytes - The document's own leading bytes.
28
+ * @returns How the encoding was settled, or `undefined` when the leading bytes carry neither a byte order mark nor a declared encoding. XML's own default of UTF-8 applies in that case, left for the caller to decode strictly rather than through decodeText's own guessing.
29
+ */
30
+ declare function detectSvgEncoding(bytes: Uint8Array): SvgEncodingDetection | undefined;
31
+ //#endregion
32
+ export { SvgEncodingDetection, detectSvgEncoding, mapXmlEncodingLabel, readXmlEncodingDeclarationLabel };
@@ -0,0 +1,88 @@
1
+ import { detectByteOrderMark } from "byte-codec";
2
+ //#region src/svg/xml-encoding.ts
3
+ const XML_ENCODING_ALIASES = {
4
+ "utf-8": "utf-8",
5
+ utf8: "utf-8",
6
+ "unicode-1-1-utf-8": "utf-8",
7
+ unicode11utf8: "utf-8",
8
+ unicode20utf8: "utf-8",
9
+ "x-unicode20utf8": "utf-8",
10
+ "utf-16le": "utf-16le",
11
+ "utf-16": "utf-16le",
12
+ "ucs-2": "utf-16le",
13
+ unicode: "utf-16le",
14
+ unicodefeff: "utf-16le",
15
+ csunicode: "utf-16le",
16
+ "iso-10646-ucs-2": "utf-16le",
17
+ "utf-16be": "utf-16be",
18
+ unicodefffe: "utf-16be",
19
+ "utf-32le": "utf-32le",
20
+ "utf-32be": "utf-32be",
21
+ "windows-1252": "windows-1252",
22
+ cp1252: "windows-1252",
23
+ "x-cp1252": "windows-1252",
24
+ "iso-8859-1": "windows-1252",
25
+ "iso8859-1": "windows-1252",
26
+ "iso_8859-1": "windows-1252",
27
+ "iso_8859-1:1987": "windows-1252",
28
+ "iso-ir-100": "windows-1252",
29
+ csisolatin1: "windows-1252",
30
+ l1: "windows-1252",
31
+ latin1: "windows-1252",
32
+ cp819: "windows-1252",
33
+ ibm819: "windows-1252",
34
+ "us-ascii": "windows-1252",
35
+ ascii: "windows-1252",
36
+ "ansi_x3.4-1968": "windows-1252"
37
+ };
38
+ /**
39
+ * Maps a name from an XML encoding declaration onto the encoding byte-codec's decodeText would decode it under, matched case-insensitively against the WHATWG Encoding Standard's own label table (restricted to the six encodings decodeText supports).
40
+ * @param label - The declaration's raw `encoding` value, exactly as written.
41
+ * @returns The matching {@link TextEncodingLabel}, or `undefined` when the name is outside decodeText's own bounded set (ExaDev/documents.js#1361).
42
+ */
43
+ function mapXmlEncodingLabel(label) {
44
+ return XML_ENCODING_ALIASES[label.toLowerCase()];
45
+ }
46
+ const XML_DECLARATION_SEARCH_WINDOW = 512;
47
+ const XML_DECLARATION_START = "<?xml";
48
+ const XML_ENCODING_DECL_PATTERN = /\bencoding\s*=\s*(["'])([A-Za-z][A-Za-z0-9._-]*)\1/;
49
+ /**
50
+ * Reads the raw encoding label out of an `<?xml ...?>` declaration's own leading bytes, without decoding anything.
51
+ *
52
+ * Safe ahead of any real decode because the declaration's own grammar restricts every character in it to ASCII: XML mandates that a declaration, if present, start at the very first byte (a byte order mark aside), so bytes not beginning with the literal ASCII sequence `<?xml` carry no declaration to read, and bytes that do keep writing ASCII up to and including the encoding name itself, whatever that name turns out to be.
53
+ * @param bytes - The document's own leading bytes.
54
+ * @returns The declaration's raw `encoding` value, exactly as written, or `undefined` when the leading bytes carry no `<?xml ...?>` declaration, or that declaration names no encoding.
55
+ */
56
+ function readXmlEncodingDeclarationLabel(bytes) {
57
+ const windowLength = Math.min(bytes.length, XML_DECLARATION_SEARCH_WINDOW);
58
+ let window = "";
59
+ for (let index = 0; index < windowLength; index += 1) window += String.fromCharCode(bytes[index]);
60
+ if (!window.startsWith(XML_DECLARATION_START)) return;
61
+ const declarationEnd = window.indexOf("?>");
62
+ const declaration = declarationEnd === -1 ? window : window.slice(0, declarationEnd);
63
+ return XML_ENCODING_DECL_PATTERN.exec(declaration)?.[2];
64
+ }
65
+ /**
66
+ * Detects the encoding SVG's own XML prolog declares, per XML 1.0's own external-encoding-detection algorithm: a byte order mark first, since it needs no decoding to trust, then the `<?xml ... encoding="..."?>` declaration.
67
+ * @param bytes - The document's own leading bytes.
68
+ * @returns How the encoding was settled, or `undefined` when the leading bytes carry neither a byte order mark nor a declared encoding. XML's own default of UTF-8 applies in that case, left for the caller to decode strictly rather than through decodeText's own guessing.
69
+ */
70
+ function detectSvgEncoding(bytes) {
71
+ const bom = detectByteOrderMark(bytes);
72
+ if (bom !== void 0) return {
73
+ kind: "resolved",
74
+ encoding: bom.encoding
75
+ };
76
+ const label = readXmlEncodingDeclarationLabel(bytes);
77
+ if (label === void 0) return;
78
+ const encoding = mapXmlEncodingLabel(label);
79
+ return encoding === void 0 ? {
80
+ kind: "unsupported",
81
+ label
82
+ } : {
83
+ kind: "resolved",
84
+ encoding
85
+ };
86
+ }
87
+ //#endregion
88
+ export { detectSvgEncoding, mapXmlEncodingLabel, readXmlEncodingDeclarationLabel };
@@ -60,6 +60,8 @@ declare class OdtTable {
60
60
  constructor(container: XmlNode[], node: XmlElement, pkg: Package);
61
61
  private live;
62
62
  rows(): OdtTableRow[];
63
+ headerRows(): boolean[];
64
+ setHeaderRows(flags: readonly boolean[]): void;
63
65
  gridRows(): TableGridRows<OdtTableCell>;
64
66
  gridColumnCount(): number;
65
67
  private grid;
@@ -60,6 +60,8 @@ declare class OdtTable {
60
60
  constructor(container: XmlNode[], node: XmlElement, pkg: Package);
61
61
  private live;
62
62
  rows(): OdtTableRow[];
63
+ headerRows(): boolean[];
64
+ setHeaderRows(flags: readonly boolean[]): void;
63
65
  gridRows(): TableGridRows<OdtTableCell>;
64
66
  gridColumnCount(): number;
65
67
  private grid;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js.documents",
3
- "version": "12.1.0",
3
+ "version": "14.0.0",
4
4
  "description": "Bidirectional docx/pptx <-> PDF conversion and a read+write editable OOXML document model, built on ooxml.js and Zod 4 codecs.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -77,21 +77,21 @@
77
77
  ],
78
78
  "license": "MIT",
79
79
  "dependencies": {
80
- "archive-codec": "1.11.9",
81
- "byte-codec": "1.7.0",
82
- "doc-codec": "5.0.0",
83
- "document-schema.js": "7.13.0",
84
- "epub-codec": "4.0.0",
80
+ "archive-codec": "1.11.10",
81
+ "byte-codec": "1.8.0",
82
+ "doc-codec": "6.0.0",
83
+ "document-schema.js": "7.14.0",
84
+ "epub-codec": "5.0.0",
85
85
  "fflate": "0.8.3",
86
- "markdown-codec": "10.0.0",
87
- "odf.js": "10.0.0",
88
- "ooxml.js": "11.1.0",
89
- "pdf-codec": "5.2.3",
90
- "ppt-codec": "2.0.4",
91
- "rtf-codec": "7.0.0",
86
+ "markdown-codec": "11.0.0",
87
+ "odf.js": "11.0.0",
88
+ "ooxml.js": "12.0.0",
89
+ "pdf-codec": "5.2.4",
90
+ "ppt-codec": "2.1.0",
91
+ "rtf-codec": "8.0.0",
92
92
  "temml": "0.13.4",
93
- "wpd-codec": "5.0.2",
94
- "xls-codec": "4.15.15",
93
+ "wpd-codec": "5.1.0",
94
+ "xls-codec": "4.15.16",
95
95
  "zod": "4.4.3"
96
96
  },
97
97
  "devDependencies": {