@cj-tech-master/excelts 7.5.0 → 7.6.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/browser/modules/excel/stream/hyperlink-reader.js +1 -1
- package/dist/browser/modules/excel/stream/workbook-reader.browser.js +2 -2
- package/dist/browser/modules/excel/stream/worksheet-reader.js +1 -1
- package/dist/browser/modules/excel/xlsx/xform/base-xform.js +1 -1
- package/dist/browser/modules/xml/dom.js +2 -1
- package/dist/browser/modules/xml/index.d.ts +1 -1
- package/dist/browser/modules/xml/sax.d.ts +41 -0
- package/dist/browser/modules/xml/sax.js +265 -76
- package/dist/browser/modules/xml/to-object.js +2 -1
- package/dist/browser/modules/xml/types.d.ts +24 -0
- package/dist/cjs/modules/excel/stream/hyperlink-reader.js +1 -1
- package/dist/cjs/modules/excel/stream/workbook-reader.browser.js +2 -2
- package/dist/cjs/modules/excel/stream/worksheet-reader.js +1 -1
- package/dist/cjs/modules/excel/xlsx/xform/base-xform.js +1 -1
- package/dist/cjs/modules/xml/dom.js +2 -1
- package/dist/cjs/modules/xml/sax.js +265 -76
- package/dist/cjs/modules/xml/to-object.js +2 -1
- package/dist/esm/modules/excel/stream/hyperlink-reader.js +1 -1
- package/dist/esm/modules/excel/stream/workbook-reader.browser.js +2 -2
- package/dist/esm/modules/excel/stream/worksheet-reader.js +1 -1
- package/dist/esm/modules/excel/xlsx/xform/base-xform.js +1 -1
- package/dist/esm/modules/xml/dom.js +2 -1
- package/dist/esm/modules/xml/sax.js +265 -76
- package/dist/esm/modules/xml/to-object.js +2 -1
- package/dist/iife/excelts.iife.js +196 -54
- package/dist/iife/excelts.iife.js.map +1 -1
- package/dist/iife/excelts.iife.min.js +44 -44
- package/dist/types/modules/xml/index.d.ts +1 -1
- package/dist/types/modules/xml/sax.d.ts +41 -0
- package/dist/types/modules/xml/types.d.ts +24 -0
- package/package.json +1 -1
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* - Dual-mode: streaming (SAX parser + stream writer) and buffered (DOM parser + writer)
|
|
11
11
|
* - Shared XmlSink interface lets rendering code target both modes transparently
|
|
12
12
|
*/
|
|
13
|
-
export type { XmlAttributes, XmlNodeType, XmlElement, XmlText, XmlCData, XmlComment, XmlProcessingInstruction, XmlNode, XmlDocument, XmlSink, SaxTag, SaxEvent, SaxEventAny, SaxHandlers, SaxOptions, WritableTarget, XmlParseOptions, ToPlainObjectOptions, ParseXmlToObjectOptions } from "./types.js";
|
|
13
|
+
export type { XmlAttributes, XmlNodeType, XmlElement, XmlText, XmlCData, XmlComment, XmlProcessingInstruction, XmlNode, XmlDocument, XmlSink, SaxTag, SaxEvent, SaxEventAny, SaxHandlers, SaxOptions, InvalidCharHandling, WritableTarget, XmlParseOptions, ToPlainObjectOptions, ParseXmlToObjectOptions } from "./types.js";
|
|
14
14
|
export { xmlEncode, xmlDecode, xmlEncodeAttr, validateXmlName, encodeCData, validateCommentText } from "./encode.js";
|
|
15
15
|
export { XmlWriter, StdDocAttributes } from "./writer.js";
|
|
16
16
|
export { XmlStreamWriter } from "./stream-writer.js";
|
|
@@ -37,6 +37,7 @@ declare class SaxParser {
|
|
|
37
37
|
private xmlns;
|
|
38
38
|
private maxDepth;
|
|
39
39
|
private maxEntityExpansions;
|
|
40
|
+
private invalidCharHandling;
|
|
40
41
|
private _entityExpansionCount;
|
|
41
42
|
private _nsStack;
|
|
42
43
|
private state;
|
|
@@ -81,6 +82,46 @@ declare class SaxParser {
|
|
|
81
82
|
fail(message: string): this;
|
|
82
83
|
write(chunk: string | null): this;
|
|
83
84
|
close(): this;
|
|
85
|
+
/**
|
|
86
|
+
* Handle an invalid XML character according to the configured strategy.
|
|
87
|
+
*
|
|
88
|
+
* Used by `handleTextInRoot()` fast path which manages its own text accumulation
|
|
89
|
+
* and cannot use the `getCode()` loop approach.
|
|
90
|
+
*
|
|
91
|
+
* - `"error"`: call `fail()` and return the original code.
|
|
92
|
+
* - `"skip"`: return `REPLACEMENT_CHAR` as a sentinel (caller handles skip).
|
|
93
|
+
* - `"replace"`: return `REPLACEMENT_CHAR`.
|
|
94
|
+
*
|
|
95
|
+
* Note: For `getCode()`, invalid char handling is inlined to avoid recursion.
|
|
96
|
+
*
|
|
97
|
+
* @param code - The invalid character code point.
|
|
98
|
+
* @param kind - Optional description (e.g. "lone surrogate") for error messages.
|
|
99
|
+
* @returns The code point to use.
|
|
100
|
+
*/
|
|
101
|
+
private handleInvalidChar;
|
|
102
|
+
/**
|
|
103
|
+
* Handle an invalid character inside the `handleTextInRoot()` fast loop.
|
|
104
|
+
*
|
|
105
|
+
* Unlike `handleInvalidChar()` (which returns a code point for `getCode()`),
|
|
106
|
+
* this method manages the text accumulation state (`this.text`, `start`) that
|
|
107
|
+
* the fast text loop relies on.
|
|
108
|
+
*
|
|
109
|
+
* - `"error"`: call `fail()`, leave text accumulation unchanged (char stays in output).
|
|
110
|
+
* - `"skip"`: flush text up to the invalid char, skip it, return new `start`.
|
|
111
|
+
* - `"replace"`: flush text up to the invalid char, append U+FFFD, return new `start`.
|
|
112
|
+
*
|
|
113
|
+
* @returns The updated `start` index for the text accumulation loop.
|
|
114
|
+
*/
|
|
115
|
+
private handleInvalidCharInText;
|
|
116
|
+
/**
|
|
117
|
+
* Handle an invalid character inside `sAttribValueQuoted()`.
|
|
118
|
+
*
|
|
119
|
+
* Same pattern as `handleInvalidCharInText()` but for attribute value
|
|
120
|
+
* accumulation (always uses `this.text`, no conditional handler check).
|
|
121
|
+
*
|
|
122
|
+
* @returns The updated `start` index.
|
|
123
|
+
*/
|
|
124
|
+
private handleInvalidCharInAttr;
|
|
84
125
|
private getCode;
|
|
85
126
|
private unget;
|
|
86
127
|
private processState;
|
|
@@ -169,6 +169,15 @@ export interface SaxHandlers {
|
|
|
169
169
|
pi?: (target: string, body: string) => void;
|
|
170
170
|
error?: (err: Error) => void;
|
|
171
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Strategy for handling invalid XML characters (control chars, lone surrogates,
|
|
174
|
+
* non-characters like U+FFFE/U+FFFF).
|
|
175
|
+
*
|
|
176
|
+
* - `"error"` — Report via error handler or throw (XML 1.0 strict). **Default.**
|
|
177
|
+
* - `"skip"` — Silently remove the invalid character from the output.
|
|
178
|
+
* - `"replace"` — Replace the invalid character with U+FFFD (REPLACEMENT CHARACTER).
|
|
179
|
+
*/
|
|
180
|
+
export type InvalidCharHandling = "error" | "skip" | "replace";
|
|
172
181
|
/** SAX parser options. */
|
|
173
182
|
export interface SaxOptions {
|
|
174
183
|
/** Track position (line/column) for error messages. Default: true */
|
|
@@ -187,6 +196,17 @@ export interface SaxOptions {
|
|
|
187
196
|
* Default: 10000. Set 0 to disable.
|
|
188
197
|
*/
|
|
189
198
|
maxEntityExpansions?: number;
|
|
199
|
+
/**
|
|
200
|
+
* How to handle invalid XML characters (ASCII control chars, lone surrogates,
|
|
201
|
+
* non-characters U+FFFE/U+FFFF, DEL U+007F, etc.).
|
|
202
|
+
*
|
|
203
|
+
* - `"error"` — Report via error handler or throw. **(Default)**
|
|
204
|
+
* - `"skip"` — Silently discard the character.
|
|
205
|
+
* - `"replace"` — Replace with U+FFFD (REPLACEMENT CHARACTER).
|
|
206
|
+
*
|
|
207
|
+
* @default "error"
|
|
208
|
+
*/
|
|
209
|
+
invalidCharHandling?: InvalidCharHandling;
|
|
190
210
|
}
|
|
191
211
|
/**
|
|
192
212
|
* Minimal writable interface for XmlStreamWriter.
|
|
@@ -265,6 +285,8 @@ export interface ParseXmlToObjectOptions extends ToPlainObjectOptions {
|
|
|
265
285
|
maxDepth?: number;
|
|
266
286
|
/** Maximum total entity expansions. Default: 10000. */
|
|
267
287
|
maxEntityExpansions?: number;
|
|
288
|
+
/** How to handle invalid XML characters. Default: "error". */
|
|
289
|
+
invalidCharHandling?: InvalidCharHandling;
|
|
268
290
|
}
|
|
269
291
|
/** Options for `parseXml()`. */
|
|
270
292
|
export interface XmlParseOptions {
|
|
@@ -282,5 +304,7 @@ export interface XmlParseOptions {
|
|
|
282
304
|
maxDepth?: number;
|
|
283
305
|
/** Maximum total entity expansions. Default: 10000. */
|
|
284
306
|
maxEntityExpansions?: number;
|
|
307
|
+
/** How to handle invalid XML characters. Default: "error". */
|
|
308
|
+
invalidCharHandling?: InvalidCharHandling;
|
|
285
309
|
}
|
|
286
310
|
export {};
|