javascript-excel 2.0.0-beta.1 → 2.1.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/README.md +11 -3
- package/dist/{auto-width-DRHsPKNk.d.cts → auto-width-DZvQSucm.d.cts} +1 -1
- package/dist/{csv-pXfaputs.js → csv-CrWF7JS1.js} +57 -13
- package/dist/{csv-DyVH9y7S.cjs → csv-DzGOFyHs.cjs} +57 -13
- package/dist/csv.cjs +3 -1
- package/dist/csv.d.cts +23 -5
- package/dist/csv.d.ts +23 -5
- package/dist/csv.js +3 -1
- package/dist/dom.cjs +2 -0
- package/dist/dom.d.cts +4 -4
- package/dist/dom.d.ts +3 -3
- package/dist/dom.js +2 -1
- package/dist/format.d.cts +1 -1
- package/dist/format.d.ts +1 -1
- package/dist/import.cjs +3 -1
- package/dist/import.d.cts +3 -3
- package/dist/import.d.ts +3 -3
- package/dist/import.js +3 -1
- package/dist/index.cjs +3 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +5 -5
- package/dist/index.js +3 -2
- package/dist/{infer-D9EC9vJ-.cjs → infer-BniOucP6.cjs} +65 -0
- package/dist/{infer-BR-J9BZa.js → infer-DcUyZ1T-.js} +54 -1
- package/dist/{model-0JikLfuM.d.cts → model-BUNp7B0Z.d.cts} +6 -0
- package/dist/{model-0JikLfuM.d.ts → model-BUNp7B0Z.d.ts} +6 -0
- package/dist/{pipeline-BuG_nn_S.d.ts → pipeline-6PmlmH1-.d.ts} +5 -2
- package/dist/{pipeline-DM7n0aRI.d.cts → pipeline-C63qD7Ym.d.cts} +5 -2
- package/dist/{pipeline-2dw9aehe.js → pipeline-CMealW1i.js} +6 -3
- package/dist/{pipeline-DMskqxiU.cjs → pipeline-Dc15gn1t.cjs} +6 -3
- package/dist/{read-ClszMDAE.js → read-CFQ09LlL.js} +253 -70
- package/dist/{read-ByceXfiL.cjs → read-DYDDLxUE.cjs} +253 -70
- package/dist/read.cjs +3 -1
- package/dist/read.d.cts +34 -6
- package/dist/read.d.ts +34 -6
- package/dist/read.js +3 -1
- package/dist/render.d.cts +1 -1
- package/dist/render.d.ts +1 -1
- package/dist/warnings-BPz1Ia3s.js +42 -0
- package/dist/warnings-CJPiDqei.cjs +47 -0
- package/dist/warnings-DhonqJ7A.d.cts +79 -0
- package/dist/warnings-DhonqJ7A.d.ts +79 -0
- package/dist/worker.cjs +3 -3
- package/dist/worker.d.cts +4 -4
- package/dist/worker.d.ts +4 -4
- package/dist/worker.js +3 -3
- package/dist/{write-DM6ieuQY.d.ts → write-BaMv1Z7W.d.ts} +2 -2
- package/dist/{write-DtjfdIFm.d.cts → write-Izl2NG0Y.d.cts} +2 -2
- package/package.json +1 -1
- package/dist/warnings-B1v58nCZ.d.cts +0 -41
- package/dist/warnings-B1v58nCZ.d.ts +0 -41
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_infer = require("./infer-
|
|
1
|
+
const require_infer = require("./infer-BniOucP6.cjs");
|
|
2
2
|
const require_errors = require("./errors-DOPrrGS4.cjs");
|
|
3
3
|
const require_dos_time = require("./dos-time-CxEs--rI.cjs");
|
|
4
4
|
const require_numfmt = require("./numfmt-DwsnhZKe.cjs");
|
|
@@ -12,6 +12,7 @@ const DEFAULT_LIMITS = Object.freeze({
|
|
|
12
12
|
maxTotalBytes: 1073741824,
|
|
13
13
|
maxRatio: 1e3,
|
|
14
14
|
maxXmlDepth: 64,
|
|
15
|
+
maxXmlTokenLength: 16777216,
|
|
15
16
|
maxCells: 1e7,
|
|
16
17
|
maxSharedStrings: 5e6,
|
|
17
18
|
maxWarnings: 1e3
|
|
@@ -325,6 +326,13 @@ function crcMismatch(info) {
|
|
|
325
326
|
*
|
|
326
327
|
* - Push-fed: `feed()` text chunks as they are inflated, then `end()`. Only
|
|
327
328
|
* the unfinished tail of a chunk is kept, so a part is never held whole.
|
|
329
|
+
* - Linear in the input, however the chunks fall (JSE-43). An unfinished
|
|
330
|
+
* token (tag, comment, CDATA section, PI) is collected as a list of chunks;
|
|
331
|
+
* each new chunk alone is searched for the token's end, with the scan state
|
|
332
|
+
* (the open quote of a start tag, or the last characters that may begin a
|
|
333
|
+
* `-->`) carried over. The chunks are joined once, when the end is found.
|
|
334
|
+
* One token is limited to `maxXmlTokenLength` characters while it is read.
|
|
335
|
+
* Text is never collected: it is passed on chunk by chunk.
|
|
328
336
|
* - Iterative, never recursive. Element depth is limited (`maxXmlDepth`).
|
|
329
337
|
* - Any `<!DOCTYPE` is rejected (XML_DTD_FORBIDDEN), so there is no entity
|
|
330
338
|
* expansion and nothing external is ever fetched. Only the five predefined
|
|
@@ -375,20 +383,58 @@ function malformed(message) {
|
|
|
375
383
|
return new require_errors.FormatError("XML_MALFORMED", message);
|
|
376
384
|
}
|
|
377
385
|
const EMPTY_ATTRS = new XmlAttrs([]);
|
|
386
|
+
const Wait = {
|
|
387
|
+
None: 0,
|
|
388
|
+
/** A plain terminator: `delim`. */
|
|
389
|
+
Delim: 1,
|
|
390
|
+
/** The '>' that ends a start tag (or a '<', which is an error), outside quoted values. */
|
|
391
|
+
Tag: 2
|
|
392
|
+
};
|
|
393
|
+
/** The longest reference pump() may keep unfinished: `&` plus 11 characters (a `;` after that makes it invalid anyway). */
|
|
394
|
+
const MAX_REF_TAIL = 12;
|
|
395
|
+
/**
|
|
396
|
+
* `details.value` is `max + 1`, meaning "more than max": the limit trips
|
|
397
|
+
* before the token's end is read, so its real length is not known, and how
|
|
398
|
+
* much of it was buffered depends on how the chunks fell.
|
|
399
|
+
*/
|
|
400
|
+
function tokenLimit(max) {
|
|
401
|
+
return new require_errors.LimitError("LIMIT_EXCEEDED", `An XML tag, comment, CDATA section or processing instruction is longer than maxXmlTokenLength (${max}).`, { details: {
|
|
402
|
+
limit: "maxXmlTokenLength",
|
|
403
|
+
value: max + 1,
|
|
404
|
+
max
|
|
405
|
+
} });
|
|
406
|
+
}
|
|
407
|
+
/** Unfinished-token chunks shorter than this are appended to the previous one, so 1-character chunks do not make a huge parts list. */
|
|
408
|
+
const MIN_PART = 4096;
|
|
378
409
|
var XmlTokenizer = class {
|
|
379
410
|
handler;
|
|
380
411
|
maxDepth;
|
|
412
|
+
maxToken;
|
|
381
413
|
buf = "";
|
|
382
414
|
stack = [];
|
|
383
415
|
/** While skipping: the end tag being searched for ("</qname"), and the depth to keep. */
|
|
384
416
|
skipTag;
|
|
385
417
|
skipDepth = 0;
|
|
418
|
+
/** While skipping: how many characters of `skipTag` the input seen so far ends with. */
|
|
419
|
+
skipMatched = 0;
|
|
386
420
|
rootSeen = false;
|
|
387
421
|
rootClosed = false;
|
|
388
422
|
pendingCR = false;
|
|
389
|
-
|
|
423
|
+
/** An unfinished token, from its '<': the chunks fed so far (`buf` is empty meanwhile). */
|
|
424
|
+
wait = Wait.None;
|
|
425
|
+
parts = [];
|
|
426
|
+
partsLength = 0;
|
|
427
|
+
/** Wait.Delim: the terminator, and the end of the searched text that may begin it. */
|
|
428
|
+
delim = "";
|
|
429
|
+
carry = "";
|
|
430
|
+
/** Wait.Tag: the open quote (34 or 39), or 0. */
|
|
431
|
+
quote = 0;
|
|
432
|
+
/** Characters examined or copied so far. A test hook for proving the scan is linear. */
|
|
433
|
+
work = 0;
|
|
434
|
+
constructor(handler, maxDepth, maxToken = DEFAULT_LIMITS.maxXmlTokenLength) {
|
|
390
435
|
this.handler = handler;
|
|
391
436
|
this.maxDepth = maxDepth;
|
|
437
|
+
this.maxToken = maxToken;
|
|
392
438
|
handler.attach?.(this);
|
|
393
439
|
}
|
|
394
440
|
depth() {
|
|
@@ -398,34 +444,108 @@ var XmlTokenizer = class {
|
|
|
398
444
|
if (depth < 1 || depth > this.stack.length) throw new RangeError(`skipToEndOf: no open element at depth ${depth}`);
|
|
399
445
|
this.skipTag = `</${this.stack[depth - 1]}`;
|
|
400
446
|
this.skipDepth = depth;
|
|
447
|
+
this.skipMatched = 0;
|
|
401
448
|
}
|
|
402
449
|
feed(chunk) {
|
|
403
|
-
|
|
450
|
+
if (this.wait !== Wait.None) {
|
|
451
|
+
if (!this.resume(chunk)) return;
|
|
452
|
+
} else if (this.buf.length === 0) this.buf = chunk;
|
|
453
|
+
else {
|
|
454
|
+
this.work += this.buf.length + chunk.length;
|
|
455
|
+
this.buf += chunk;
|
|
456
|
+
}
|
|
404
457
|
this.pump(false);
|
|
405
458
|
}
|
|
406
459
|
end() {
|
|
460
|
+
if (this.wait !== Wait.None) this.unsuspend();
|
|
407
461
|
this.pump(true);
|
|
462
|
+
if (this.skipTag !== void 0) throw malformed(`Element <${this.skipTag.slice(2)}> is not closed.`);
|
|
408
463
|
if (this.buf.trim() !== "") throw malformed("Unexpected end of XML data.");
|
|
409
464
|
if (this.stack.length > 0) throw malformed(`Element <${this.stack.at(-1)}> is not closed.`);
|
|
410
465
|
if (!this.rootSeen) throw malformed("XML part has no root element.");
|
|
411
466
|
}
|
|
467
|
+
/**
|
|
468
|
+
* Feeds one chunk to the unfinished token: only `chunk` is searched. Returns
|
|
469
|
+
* true when the token's end is in it; the chunks are then joined into `buf`
|
|
470
|
+
* and pump() reads the token from its start, exactly as if it had arrived
|
|
471
|
+
* whole. Throws when the token grows past maxXmlTokenLength.
|
|
472
|
+
*/
|
|
473
|
+
resume(chunk) {
|
|
474
|
+
this.work += chunk.length;
|
|
475
|
+
const last = this.parts.length - 1;
|
|
476
|
+
if (this.parts[last].length < MIN_PART) this.parts[last] += chunk;
|
|
477
|
+
else this.parts.push(chunk);
|
|
478
|
+
this.partsLength += chunk.length;
|
|
479
|
+
let found;
|
|
480
|
+
if (this.wait === Wait.Tag) {
|
|
481
|
+
const e = scanTag(chunk, 0, chunk.length, this.quote);
|
|
482
|
+
found = e >= 0;
|
|
483
|
+
if (!found) this.quote = -1 - e;
|
|
484
|
+
} else {
|
|
485
|
+
const s = this.carry + chunk;
|
|
486
|
+
found = s.indexOf(this.delim) !== -1;
|
|
487
|
+
if (!found) this.carry = s.slice(Math.max(0, s.length - (this.delim.length - 1)));
|
|
488
|
+
}
|
|
489
|
+
if (!found) {
|
|
490
|
+
if (this.partsLength > this.maxToken) throw tokenLimit(this.maxToken);
|
|
491
|
+
return false;
|
|
492
|
+
}
|
|
493
|
+
this.unsuspend();
|
|
494
|
+
return true;
|
|
495
|
+
}
|
|
496
|
+
/** Parks the unfinished token that starts at `buf[i]`. */
|
|
497
|
+
suspend(buf, i, wait, delim = "", searchFrom = 0) {
|
|
498
|
+
this.wait = wait;
|
|
499
|
+
this.parts = [buf.slice(i)];
|
|
500
|
+
this.partsLength = buf.length - i;
|
|
501
|
+
this.delim = delim;
|
|
502
|
+
this.carry = wait === Wait.Delim ? buf.slice(Math.max(searchFrom, buf.length - (delim.length - 1))) : "";
|
|
503
|
+
this.buf = "";
|
|
504
|
+
}
|
|
505
|
+
unsuspend() {
|
|
506
|
+
this.buf = this.parts.length === 1 ? this.parts[0] : this.parts.join("");
|
|
507
|
+
this.work += this.buf.length;
|
|
508
|
+
this.wait = Wait.None;
|
|
509
|
+
this.parts = [];
|
|
510
|
+
this.partsLength = 0;
|
|
511
|
+
this.carry = "";
|
|
512
|
+
}
|
|
513
|
+
/** A token of `length` characters (from '<' to the end of its terminator) is complete. */
|
|
514
|
+
checkToken(length) {
|
|
515
|
+
if (length > this.maxToken) throw tokenLimit(this.maxToken);
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* The token at `buf[i]` has no end in `buf`. Throws past the limit or at the
|
|
519
|
+
* end of the input; otherwise parks it until more input arrives.
|
|
520
|
+
*/
|
|
521
|
+
unfinished(buf, i, final, message, wait, delim = "", searchFrom = 0) {
|
|
522
|
+
if (buf.length - i > this.maxToken) throw tokenLimit(this.maxToken);
|
|
523
|
+
if (final) throw malformed(message);
|
|
524
|
+
this.suspend(buf, i, wait, delim, searchFrom);
|
|
525
|
+
}
|
|
412
526
|
pump(final) {
|
|
413
|
-
|
|
414
|
-
|
|
527
|
+
let buf = this.buf;
|
|
528
|
+
let len = buf.length;
|
|
529
|
+
this.work += len;
|
|
415
530
|
let i = 0;
|
|
416
531
|
while (i < len) {
|
|
417
532
|
if (this.skipTag !== void 0) {
|
|
418
533
|
const tag = this.skipTag;
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
if (at === -1 || at + tag.length >= len) {
|
|
534
|
+
const end = this.skipTo(buf, i);
|
|
535
|
+
if (end === -1) {
|
|
422
536
|
if (final) throw malformed(`Element <${tag.slice(2)}> is not closed.`);
|
|
423
|
-
i =
|
|
537
|
+
i = len;
|
|
424
538
|
break;
|
|
425
539
|
}
|
|
426
540
|
this.stack.length = this.skipDepth;
|
|
427
541
|
this.skipTag = void 0;
|
|
428
|
-
i =
|
|
542
|
+
if (end >= tag.length) i = end - tag.length;
|
|
543
|
+
else {
|
|
544
|
+
buf = tag + buf.slice(end);
|
|
545
|
+
len = buf.length;
|
|
546
|
+
this.work += len;
|
|
547
|
+
i = 0;
|
|
548
|
+
}
|
|
429
549
|
continue;
|
|
430
550
|
}
|
|
431
551
|
if (buf.charCodeAt(i) !== 60) {
|
|
@@ -435,6 +555,7 @@ var XmlTokenizer = class {
|
|
|
435
555
|
const amp = buf.lastIndexOf("&");
|
|
436
556
|
j = amp >= i && buf.indexOf(";", amp) === -1 ? amp : len;
|
|
437
557
|
if (j > i) this.chars(buf.slice(i, j));
|
|
558
|
+
if (j < len && len - j > MAX_REF_TAIL) this.chars(buf.slice(j));
|
|
438
559
|
i = j;
|
|
439
560
|
break;
|
|
440
561
|
}
|
|
@@ -448,29 +569,23 @@ var XmlTokenizer = class {
|
|
|
448
569
|
const c1 = buf.charCodeAt(i + 1);
|
|
449
570
|
if (c1 === 63) {
|
|
450
571
|
const e = buf.indexOf("?>", i + 2);
|
|
451
|
-
if (e === -1)
|
|
452
|
-
|
|
453
|
-
break;
|
|
454
|
-
}
|
|
572
|
+
if (e === -1) return this.unfinished(buf, i, final, "Unterminated processing instruction.", Wait.Delim, "?>", i + 2);
|
|
573
|
+
this.checkToken(e + 2 - i);
|
|
455
574
|
i = e + 2;
|
|
456
575
|
continue;
|
|
457
576
|
}
|
|
458
577
|
if (c1 === 33) {
|
|
459
578
|
if (buf.startsWith("<!--", i)) {
|
|
460
579
|
const e = buf.indexOf("-->", i + 4);
|
|
461
|
-
if (e === -1)
|
|
462
|
-
|
|
463
|
-
break;
|
|
464
|
-
}
|
|
580
|
+
if (e === -1) return this.unfinished(buf, i, final, "Unterminated comment.", Wait.Delim, "-->", i + 4);
|
|
581
|
+
this.checkToken(e + 3 - i);
|
|
465
582
|
i = e + 3;
|
|
466
583
|
continue;
|
|
467
584
|
}
|
|
468
585
|
if (buf.startsWith("<![CDATA[", i)) {
|
|
469
586
|
const e = buf.indexOf("]]>", i + 9);
|
|
470
|
-
if (e === -1)
|
|
471
|
-
|
|
472
|
-
break;
|
|
473
|
-
}
|
|
587
|
+
if (e === -1) return this.unfinished(buf, i, final, "Unterminated CDATA section.", Wait.Delim, "]]>", i + 9);
|
|
588
|
+
this.checkToken(e + 3 - i);
|
|
474
589
|
if (this.stack.length === 0) throw malformed("CDATA outside the root element.");
|
|
475
590
|
this.handler.text(normaliseNewlines(buf.slice(i + 9, e)));
|
|
476
591
|
i = e + 3;
|
|
@@ -481,10 +596,8 @@ var XmlTokenizer = class {
|
|
|
481
596
|
}
|
|
482
597
|
if (c1 === 47) {
|
|
483
598
|
const e = buf.indexOf(">", i + 2);
|
|
484
|
-
if (e === -1)
|
|
485
|
-
|
|
486
|
-
break;
|
|
487
|
-
}
|
|
599
|
+
if (e === -1) return this.unfinished(buf, i, final, "Unterminated end tag.", Wait.Delim, ">", i + 2);
|
|
600
|
+
this.checkToken(e + 1 - i);
|
|
488
601
|
const qname = buf.slice(i + 2, e).trim();
|
|
489
602
|
const open = this.stack.pop();
|
|
490
603
|
if (open === void 0 || open !== qname) throw malformed(open === void 0 ? `Unexpected end tag </${qname}>.` : `End tag </${qname}> does not match <${open}>.`);
|
|
@@ -493,16 +606,50 @@ var XmlTokenizer = class {
|
|
|
493
606
|
i = e + 1;
|
|
494
607
|
continue;
|
|
495
608
|
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
609
|
+
if (len - i === 1 && !final) break;
|
|
610
|
+
const e = scanTag(buf, i + 1, Math.min(len, i + this.maxToken), 0);
|
|
611
|
+
if (e < 0) {
|
|
612
|
+
this.quote = -1 - e;
|
|
613
|
+
return this.unfinished(buf, i, final, "Unterminated start tag.", Wait.Tag);
|
|
500
614
|
}
|
|
615
|
+
if (buf.charCodeAt(e) === 60) throw malformed("'<' inside a tag.");
|
|
501
616
|
this.startTag(buf, i + 1, e);
|
|
502
617
|
i = e + 1;
|
|
503
618
|
}
|
|
504
619
|
this.buf = i >= len ? "" : buf.slice(i);
|
|
505
620
|
}
|
|
621
|
+
/**
|
|
622
|
+
* Searches buf[from..] for the end tag being skipped (`skipTag` followed by
|
|
623
|
+
* '>' or a space), continuing a match the previous chunk ended in. Returns
|
|
624
|
+
* the index just after the matched `skipTag`, or -1 (then `skipMatched`
|
|
625
|
+
* holds the partial match). Linear: '<' occurs in `skipTag` only at its
|
|
626
|
+
* start, so after a mismatch the match can only restart at a later '<'.
|
|
627
|
+
*/
|
|
628
|
+
skipTo(buf, from) {
|
|
629
|
+
const tag = this.skipTag;
|
|
630
|
+
const len = buf.length;
|
|
631
|
+
let q = this.skipMatched;
|
|
632
|
+
let p = from;
|
|
633
|
+
while (p < len) {
|
|
634
|
+
if (q === 0) {
|
|
635
|
+
const lt = buf.indexOf("<", p);
|
|
636
|
+
if (lt === -1) break;
|
|
637
|
+
p = lt;
|
|
638
|
+
}
|
|
639
|
+
while (q < tag.length && p < len && buf.charCodeAt(p) === tag.charCodeAt(q)) {
|
|
640
|
+
p++;
|
|
641
|
+
q++;
|
|
642
|
+
}
|
|
643
|
+
if (p === len) break;
|
|
644
|
+
if (q === tag.length && isNameEnd(buf.charCodeAt(p))) {
|
|
645
|
+
this.skipMatched = 0;
|
|
646
|
+
return p;
|
|
647
|
+
}
|
|
648
|
+
q = 0;
|
|
649
|
+
}
|
|
650
|
+
this.skipMatched = q;
|
|
651
|
+
return -1;
|
|
652
|
+
}
|
|
506
653
|
chars(raw) {
|
|
507
654
|
if (this.stack.length === 0) {
|
|
508
655
|
if (raw.trim() !== "") throw malformed("Text outside the root element.");
|
|
@@ -572,18 +719,20 @@ function localName(qname) {
|
|
|
572
719
|
const colon = qname.indexOf(":");
|
|
573
720
|
return colon === -1 ? qname : qname.slice(colon + 1);
|
|
574
721
|
}
|
|
575
|
-
/**
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
722
|
+
/**
|
|
723
|
+
* Index of the first '>' or '<' outside quoted values in buf[from, to),
|
|
724
|
+
* starting inside the quote `quote` (34, 39 or 0). When there is none,
|
|
725
|
+
* returns `-1 - q`, where q is the quote open at `to`.
|
|
726
|
+
*/
|
|
727
|
+
function scanTag(buf, from, to, quote) {
|
|
728
|
+
for (let i = from; i < to; i++) {
|
|
579
729
|
const c = buf.charCodeAt(i);
|
|
580
730
|
if (quote !== 0) {
|
|
581
731
|
if (c === quote) quote = 0;
|
|
582
732
|
} else if (c === 34 || c === 39) quote = c;
|
|
583
|
-
else if (c === 62) return i;
|
|
584
|
-
else if (c === 60) throw malformed("'<' inside a tag.");
|
|
733
|
+
else if (c === 62 || c === 60) return i;
|
|
585
734
|
}
|
|
586
|
-
return -1;
|
|
735
|
+
return -1 - quote;
|
|
587
736
|
}
|
|
588
737
|
function normaliseNewlines(s) {
|
|
589
738
|
return s.indexOf("\r") === -1 ? s : s.replace(/\r\n?/g, "\n");
|
|
@@ -647,10 +796,10 @@ var ReadContext = class {
|
|
|
647
796
|
limits;
|
|
648
797
|
signal;
|
|
649
798
|
onWarning;
|
|
650
|
-
|
|
799
|
+
cap;
|
|
800
|
+
warnings;
|
|
651
801
|
/** Names of the parts read so far (for keeping the others, see InternalReadOptions). */
|
|
652
802
|
consumed = /* @__PURE__ */ new Set();
|
|
653
|
-
dropped = 0;
|
|
654
803
|
cells = 0;
|
|
655
804
|
constructor(zip, limits, signal, onWarning, onProgress) {
|
|
656
805
|
this.zip = zip;
|
|
@@ -658,22 +807,18 @@ var ReadContext = class {
|
|
|
658
807
|
this.signal = signal;
|
|
659
808
|
this.onWarning = onWarning;
|
|
660
809
|
this.onProgress = require_dos_time.throttleProgress(onProgress);
|
|
810
|
+
this.cap = new require_infer.WarningCap(limits.maxWarnings);
|
|
811
|
+
this.warnings = this.cap.warnings;
|
|
661
812
|
}
|
|
662
813
|
onProgress;
|
|
663
814
|
/** Returns to the event loop about every 16 ms between chunks, so a big read does not freeze the page (JSE-24). */
|
|
664
815
|
pause = require_dos_time.createYielder();
|
|
816
|
+
/**
|
|
817
|
+
* Records a warning, subject to the cap (internal/warning-cap.ts). The first
|
|
818
|
+
* dropped warning adds WARNINGS_TRUNCATED at that point, as in 2.0.0; its
|
|
819
|
+
* `dropped` counts grow until the read ends.
|
|
820
|
+
*/
|
|
665
821
|
warn(code, message, where) {
|
|
666
|
-
if (this.warnings.length >= this.limits.maxWarnings) {
|
|
667
|
-
if (this.dropped++ === 0) {
|
|
668
|
-
const w = {
|
|
669
|
-
code: "WARNINGS_TRUNCATED",
|
|
670
|
-
message: `More than maxWarnings (${this.limits.maxWarnings}) warnings; later ones were dropped.`
|
|
671
|
-
};
|
|
672
|
-
this.warnings.push(w);
|
|
673
|
-
this.onWarning?.(w);
|
|
674
|
-
}
|
|
675
|
-
return;
|
|
676
|
-
}
|
|
677
822
|
const w = {
|
|
678
823
|
code,
|
|
679
824
|
message
|
|
@@ -681,8 +826,16 @@ var ReadContext = class {
|
|
|
681
826
|
if (where?.part !== void 0) w.part = where.part;
|
|
682
827
|
if (where?.sheet !== void 0) w.sheet = where.sheet;
|
|
683
828
|
if (where?.ref !== void 0) w.ref = where.ref;
|
|
684
|
-
|
|
685
|
-
this.
|
|
829
|
+
if (where?.partKind !== void 0) w.partKind = where.partKind;
|
|
830
|
+
if (this.cap.add(w, (dropped) => {
|
|
831
|
+
const t = {
|
|
832
|
+
code: "WARNINGS_TRUNCATED",
|
|
833
|
+
message: `More than maxWarnings (${this.limits.maxWarnings}) warnings; later ones were dropped.`,
|
|
834
|
+
dropped
|
|
835
|
+
};
|
|
836
|
+
this.cap.warnings.push(t);
|
|
837
|
+
this.onWarning?.(t);
|
|
838
|
+
})) this.onWarning?.(w);
|
|
686
839
|
}
|
|
687
840
|
/** Counts one cell against maxCells. */
|
|
688
841
|
countCell() {
|
|
@@ -710,7 +863,7 @@ var ReadContext = class {
|
|
|
710
863
|
*/
|
|
711
864
|
async parse(entry, handler, onChunk) {
|
|
712
865
|
this.consumed.add(entry.name);
|
|
713
|
-
const tok = new XmlTokenizer(handler, this.limits.maxXmlDepth);
|
|
866
|
+
const tok = new XmlTokenizer(handler, this.limits.maxXmlDepth, this.limits.maxXmlTokenLength);
|
|
714
867
|
let decoder;
|
|
715
868
|
try {
|
|
716
869
|
for await (const chunk of this.zip.stream(entry, this.signal)) {
|
|
@@ -741,7 +894,8 @@ function withPart(err, part) {
|
|
|
741
894
|
},
|
|
742
895
|
cause: err
|
|
743
896
|
});
|
|
744
|
-
|
|
897
|
+
const limit = err instanceof require_errors.LimitError ? err.details?.["limit"] : void 0;
|
|
898
|
+
if (err instanceof require_errors.LimitError && (limit === "maxXmlDepth" || limit === "maxXmlTokenLength") && !err.details?.["part"]) return new require_errors.LimitError(err.code, `${part}: ${err.message}`, {
|
|
745
899
|
details: {
|
|
746
900
|
...err.details,
|
|
747
901
|
part
|
|
@@ -2189,6 +2343,8 @@ var SheetParser = class {
|
|
|
2189
2343
|
let value;
|
|
2190
2344
|
let type = "empty";
|
|
2191
2345
|
let deferredIndex = -1;
|
|
2346
|
+
/** Set when the value came from a number or ISO-date `<v>`: the text for `cell.rawText`. */
|
|
2347
|
+
let raw;
|
|
2192
2348
|
const v = p.v;
|
|
2193
2349
|
switch (p.t) {
|
|
2194
2350
|
case "s": {
|
|
@@ -2249,6 +2405,7 @@ var SheetParser = class {
|
|
|
2249
2405
|
break;
|
|
2250
2406
|
case "d":
|
|
2251
2407
|
if (v !== void 0) {
|
|
2408
|
+
if (v.trim() !== "") raw = v;
|
|
2252
2409
|
const d = require_infer.parseIsoDate(v.trim().replace(/(\.\d{3})\d+/, "$1"), this.opts.dateZone);
|
|
2253
2410
|
if (d) {
|
|
2254
2411
|
value = d;
|
|
@@ -2261,6 +2418,7 @@ var SheetParser = class {
|
|
|
2261
2418
|
break;
|
|
2262
2419
|
default: {
|
|
2263
2420
|
if (v === void 0 || v.trim() === "") break;
|
|
2421
|
+
raw = v;
|
|
2264
2422
|
const n = Number(v);
|
|
2265
2423
|
if (!Number.isFinite(n)) {
|
|
2266
2424
|
value = v;
|
|
@@ -2286,6 +2444,7 @@ var SheetParser = class {
|
|
|
2286
2444
|
if (value === void 0 && formula === void 0 && !style) return void 0;
|
|
2287
2445
|
const cell = { type };
|
|
2288
2446
|
if (value !== void 0) cell.value = value;
|
|
2447
|
+
if (raw !== void 0 && this.opts.rawText) cell.rawText = raw;
|
|
2289
2448
|
if (formula !== void 0) {
|
|
2290
2449
|
cell.formula = formula.text;
|
|
2291
2450
|
if (formula.arrayRef) cell.arrayRef = formula.arrayRef;
|
|
@@ -2815,6 +2974,7 @@ async function readImpl(input, options, internal) {
|
|
|
2815
2974
|
checkEnum("dates", o.dates, ["date", "serial"]);
|
|
2816
2975
|
checkEnum("dateZone", o.dateZone, ["local", "utc"]);
|
|
2817
2976
|
checkEnum("richText", o.richText, ["runs", "plain"]);
|
|
2977
|
+
if (o.rawText !== void 0 && typeof o.rawText !== "boolean") throw new TypeError(`rawText must be a boolean, got ${typeof o.rawText}`);
|
|
2818
2978
|
if (o.maxRows !== void 0 && (!Number.isInteger(o.maxRows) || o.maxRows < 0)) throw new TypeError(`maxRows must be a non-negative integer, got ${String(o.maxRows)}`);
|
|
2819
2979
|
throwIfAborted(o.signal);
|
|
2820
2980
|
const bytes = await require_infer.toBytes(input, "read");
|
|
@@ -2833,16 +2993,23 @@ async function readImpl(input, options, internal) {
|
|
|
2833
2993
|
const seen = /* @__PURE__ */ new Set();
|
|
2834
2994
|
const warnUnsupported = (rels, part) => {
|
|
2835
2995
|
for (const r of rels) {
|
|
2836
|
-
const
|
|
2996
|
+
const kind = r.kind;
|
|
2997
|
+
const what = UNSUPPORTED.get(kind);
|
|
2837
2998
|
if (what && !seen.has(r.kind)) {
|
|
2838
2999
|
seen.add(r.kind);
|
|
2839
|
-
ctx.warn("UNSUPPORTED_PART", `The workbook contains ${what}, which are not read.`, {
|
|
3000
|
+
ctx.warn("UNSUPPORTED_PART", `The workbook contains ${what}, which are not read.`, {
|
|
3001
|
+
part: r.external ? part : r.target,
|
|
3002
|
+
partKind: kind
|
|
3003
|
+
});
|
|
2840
3004
|
}
|
|
2841
3005
|
}
|
|
2842
3006
|
};
|
|
2843
3007
|
if (format.macros) {
|
|
2844
3008
|
seen.add("vbaProject");
|
|
2845
|
-
ctx.warn("UNSUPPORTED_PART", `The workbook is a ${format.label}; its VBA macros are not read or run.`, {
|
|
3009
|
+
ctx.warn("UNSUPPORTED_PART", `The workbook is a ${format.label}; its VBA macros are not read or run.`, {
|
|
3010
|
+
part: workbookPart,
|
|
3011
|
+
partKind: "vbaProject"
|
|
3012
|
+
});
|
|
2846
3013
|
}
|
|
2847
3014
|
warnUnsupported(wbRels, workbookPart);
|
|
2848
3015
|
const relOf = (kind) => wbRels.find((r) => r.kind === kind && !r.external);
|
|
@@ -2850,7 +3017,10 @@ async function readImpl(input, options, internal) {
|
|
|
2850
3017
|
const stylesRel = relOf("styles");
|
|
2851
3018
|
if (stylesRel) {
|
|
2852
3019
|
const entry = pkg.part(stylesRel.target);
|
|
2853
|
-
if (!entry) ctx.warn("MISSING_PART", `The styles part ${stylesRel.target} is missing; default styles were used.`, {
|
|
3020
|
+
if (!entry) ctx.warn("MISSING_PART", `The styles part ${stylesRel.target} is missing; default styles were used.`, {
|
|
3021
|
+
part: stylesRel.target,
|
|
3022
|
+
partKind: "styles"
|
|
3023
|
+
});
|
|
2854
3024
|
else {
|
|
2855
3025
|
const sp = new StylesParser(o.styles !== false);
|
|
2856
3026
|
await ctx.parse(entry, sp);
|
|
@@ -2865,10 +3035,13 @@ async function readImpl(input, options, internal) {
|
|
|
2865
3035
|
const themeRel = relOf("theme");
|
|
2866
3036
|
if (themeRel && o.styles !== false) {
|
|
2867
3037
|
const entry = pkg.part(themeRel.target);
|
|
2868
|
-
if (!entry) ctx.warn("MISSING_PART", `The theme part ${themeRel.target} is missing; the default theme applies.`, {
|
|
3038
|
+
if (!entry) ctx.warn("MISSING_PART", `The theme part ${themeRel.target} is missing; the default theme applies.`, {
|
|
3039
|
+
part: themeRel.target,
|
|
3040
|
+
partKind: "theme"
|
|
3041
|
+
});
|
|
2869
3042
|
else {
|
|
2870
3043
|
const tp = new ThemeParser();
|
|
2871
|
-
if (await optional(ctx, entry.name, () => ctx.parse(entry, tp))) theme = tp.result();
|
|
3044
|
+
if (await optional(ctx, entry.name, "theme", () => ctx.parse(entry, tp))) theme = tp.result();
|
|
2872
3045
|
}
|
|
2873
3046
|
}
|
|
2874
3047
|
let sst = [];
|
|
@@ -2877,7 +3050,10 @@ async function readImpl(input, options, internal) {
|
|
|
2877
3050
|
const sstRel = relOf("sharedStrings");
|
|
2878
3051
|
if (sstRel) {
|
|
2879
3052
|
const entry = pkg.part(sstRel.target);
|
|
2880
|
-
if (!entry) ctx.warn("MISSING_PART", `The shared strings part ${sstRel.target} is missing; cells that use it are empty.`, {
|
|
3053
|
+
if (!entry) ctx.warn("MISSING_PART", `The shared strings part ${sstRel.target} is missing; cells that use it are empty.`, {
|
|
3054
|
+
part: sstRel.target,
|
|
3055
|
+
partKind: "sharedStrings"
|
|
3056
|
+
});
|
|
2881
3057
|
else if (deferred) sstEntry = entry;
|
|
2882
3058
|
else {
|
|
2883
3059
|
const sp = new SharedStringsParser(o.richText ?? "runs", limits.maxSharedStrings);
|
|
@@ -2902,6 +3078,7 @@ async function readImpl(input, options, internal) {
|
|
|
2902
3078
|
dates: o.dates ?? "date",
|
|
2903
3079
|
dateZone: o.dateZone ?? "local",
|
|
2904
3080
|
richText: o.richText ?? "runs",
|
|
3081
|
+
rawText: o.rawText === true,
|
|
2905
3082
|
date1904: wbp.date1904,
|
|
2906
3083
|
maxRows: o.maxRows ?? 1048576
|
|
2907
3084
|
}, rel?.target ?? workbookPart);
|
|
@@ -2909,7 +3086,10 @@ async function readImpl(input, options, internal) {
|
|
|
2909
3086
|
parser.deferred = deferred;
|
|
2910
3087
|
const part = rel ? pkg.part(rel.target) : void 0;
|
|
2911
3088
|
if (!part) {
|
|
2912
|
-
ctx.warn("MISSING_PART", `The part for sheet "${entry.name}" is missing; the sheet is empty.`, {
|
|
3089
|
+
ctx.warn("MISSING_PART", `The part for sheet "${entry.name}" is missing; the sheet is empty.`, {
|
|
3090
|
+
sheet: entry.name,
|
|
3091
|
+
partKind: "worksheet"
|
|
3092
|
+
});
|
|
2913
3093
|
sheets.push(parser.finish([]));
|
|
2914
3094
|
continue;
|
|
2915
3095
|
}
|
|
@@ -3024,13 +3204,16 @@ function refsOnly(ref) {
|
|
|
3024
3204
|
}).join(",");
|
|
3025
3205
|
}
|
|
3026
3206
|
/** Parses an optional part; on a format problem, warns BROKEN_OPTIONAL_PART and returns false. */
|
|
3027
|
-
async function optional(ctx, part, fn) {
|
|
3207
|
+
async function optional(ctx, part, partKind, fn) {
|
|
3028
3208
|
try {
|
|
3029
3209
|
await fn();
|
|
3030
3210
|
return true;
|
|
3031
3211
|
} catch (err) {
|
|
3032
3212
|
if (err instanceof require_errors.FormatError && err.code === "XML_MALFORMED") {
|
|
3033
|
-
ctx.warn("BROKEN_OPTIONAL_PART", `${part} is not well-formed XML and was skipped.`, {
|
|
3213
|
+
ctx.warn("BROKEN_OPTIONAL_PART", `${part} is not well-formed XML and was skipped.`, {
|
|
3214
|
+
part,
|
|
3215
|
+
partKind
|
|
3216
|
+
});
|
|
3034
3217
|
return false;
|
|
3035
3218
|
}
|
|
3036
3219
|
throw err;
|
|
@@ -3039,22 +3222,22 @@ async function optional(ctx, part, fn) {
|
|
|
3039
3222
|
async function readProperties(pkg, ctx) {
|
|
3040
3223
|
const rels = await pkg.rels("");
|
|
3041
3224
|
const props = {};
|
|
3042
|
-
for (const kind of [
|
|
3043
|
-
"core-properties",
|
|
3044
|
-
"metadata/core-properties",
|
|
3045
|
-
"extended-properties"
|
|
3225
|
+
for (const [kind, partKind] of [
|
|
3226
|
+
["core-properties", "coreProperties"],
|
|
3227
|
+
["metadata/core-properties", "coreProperties"],
|
|
3228
|
+
["extended-properties", "extendedProperties"]
|
|
3046
3229
|
]) {
|
|
3047
3230
|
const rel = rels.find((r) => (r.kind === kind || r.type.endsWith(`/${kind}`)) && !r.external);
|
|
3048
3231
|
const entry = rel ? pkg.part(rel.target) : void 0;
|
|
3049
3232
|
if (!entry) continue;
|
|
3050
3233
|
const handler = new PropsParser(props);
|
|
3051
|
-
await optional(ctx, entry.name, () => ctx.parse(entry, handler));
|
|
3234
|
+
await optional(ctx, entry.name, partKind, () => ctx.parse(entry, handler));
|
|
3052
3235
|
}
|
|
3053
3236
|
const customRel = rels.find((r) => r.kind === "custom-properties" && !r.external);
|
|
3054
3237
|
const custom = customRel ? pkg.part(customRel.target) : void 0;
|
|
3055
3238
|
if (custom) {
|
|
3056
3239
|
const cp = new CustomPropsParser();
|
|
3057
|
-
if (await optional(ctx, custom.name, () => ctx.parse(custom, cp)) && cp.items.length) props.custom = cp.items;
|
|
3240
|
+
if (await optional(ctx, custom.name, "customProperties", () => ctx.parse(custom, cp)) && cp.items.length) props.custom = cp.items;
|
|
3058
3241
|
}
|
|
3059
3242
|
return Object.keys(props).length ? props : void 0;
|
|
3060
3243
|
}
|
package/dist/read.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
2
|
+
const require_warnings = require("./warnings-CJPiDqei.cjs");
|
|
3
|
+
const require_read = require("./read-DYDDLxUE.cjs");
|
|
3
4
|
exports.DEFAULT_READ_LIMITS = require_read.DEFAULT_READ_LIMITS;
|
|
4
5
|
exports.detectFormat = require_read.detectFormat;
|
|
6
|
+
exports.isDataLossWarning = require_warnings.isDataLossWarning;
|
|
5
7
|
exports.read = require_read.read;
|
|
6
8
|
exports.readSheetNames = require_read.readSheetNames;
|
package/dist/read.d.cts
CHANGED
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
*
|
|
11
11
|
* @module javascript-excel/read
|
|
12
12
|
*/
|
|
13
|
-
import { a as BlobType, i as
|
|
14
|
-
import { A as Theme, C as PrintSetup, D as Sheet, E as RowProps, O as SheetView, S as PatternType, T as RichTextRun, _ as Font, a as Cell, b as NumFmt, c as CellType, d as ColumnProps, f as ColumnWidth, g as Fill, h as ErrorCode, i as BorderStyle, j as Workbook, k as Style, l as CellValue, m as DocProperties, n as Border, o as CellErrorValue, p as DefinedName, r as BorderSide, s as CellInput, t as Alignment, u as Color, v as GradientFill, w as RichText, x as PatternFill, y as Hyperlink } from "./model-
|
|
13
|
+
import { a as isDataLossWarning, c as BlobType, i as ExcelWarningCode, n as ExcelPartKind, o as BinaryInput, r as ExcelWarning, s as BlobLike, t as DroppedWarnings } from "./warnings-DhonqJ7A.cjs";
|
|
14
|
+
import { A as Theme, C as PrintSetup, D as Sheet, E as RowProps, O as SheetView, S as PatternType, T as RichTextRun, _ as Font, a as Cell, b as NumFmt, c as CellType, d as ColumnProps, f as ColumnWidth, g as Fill, h as ErrorCode, i as BorderStyle, j as Workbook, k as Style, l as CellValue, m as DocProperties, n as Border, o as CellErrorValue, p as DefinedName, r as BorderSide, s as CellInput, t as Alignment, u as Color, v as GradientFill, w as RichText, x as PatternFill, y as Hyperlink } from "./model-BUNp7B0Z.cjs";
|
|
15
15
|
import { t as AbortSignalLike } from "./signal-Dz0ZYe6d.cjs";
|
|
16
|
-
import { t as Progress } from "./write-
|
|
16
|
+
import { t as Progress } from "./write-Izl2NG0Y.cjs";
|
|
17
17
|
/** Result of `read`. */
|
|
18
18
|
export interface ReadResult {
|
|
19
19
|
workbook: Workbook<Cell>;
|
|
@@ -33,6 +33,18 @@ export interface ReadOptions {
|
|
|
33
33
|
dateZone?: "local" | "utc" | undefined;
|
|
34
34
|
/** Rich text as runs (default) or flattened to a plain string. */
|
|
35
35
|
richText?: "runs" | "plain" | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Also return the text stored in the file for number and ISO-date cells, as
|
|
38
|
+
* `cell.rawText`, exactly as written in `<v>` (entities decoded and line ends
|
|
39
|
+
* normalised as for any XML text, nothing trimmed): `50.30`, `1E-7`, `1234567890123456789`,
|
|
40
|
+
* `2024-01-15`. `value` and `type` are unchanged, so a cell still says
|
|
41
|
+
* whether it was a number or a date. Set on `t="n"` (the default) and
|
|
42
|
+
* `t="d"` cells that have a value, including formula cells (the cached
|
|
43
|
+
* `<v>`) and date-formatted serials (the serial as stored, with `dates`
|
|
44
|
+
* `'date'` or `'serial'`). Strings, booleans, errors and cells with an
|
|
45
|
+
* empty or blank `<v>` never get it. Default false: no `rawText` key at all.
|
|
46
|
+
*/
|
|
47
|
+
rawText?: boolean | undefined;
|
|
36
48
|
/**
|
|
37
49
|
* Read only the first `maxRows` rows of each parsed sheet (zero-based rows
|
|
38
50
|
* 0..maxRows-1). Later rows are skipped without building cells, with one
|
|
@@ -58,14 +70,30 @@ export interface ReadLimits {
|
|
|
58
70
|
/** Decompressed / compressed, per entry, checked once an entry has produced more than 1 MiB. */
|
|
59
71
|
maxRatio: number;
|
|
60
72
|
maxXmlDepth: number;
|
|
73
|
+
/**
|
|
74
|
+
* Characters (UTF-16 code units, as `string.length` counts them) in one XML
|
|
75
|
+
* tag with its attributes, comment, CDATA section or processing instruction.
|
|
76
|
+
* Checked while the token is read, so it is never buffered past this. Text
|
|
77
|
+
* between tags is streamed and not limited by it. On a `LimitError`,
|
|
78
|
+
* `details.value` is `max + 1` ("more than max"): the token's full length is
|
|
79
|
+
* not read. Default 16 Mi (`DEFAULT_READ_LIMITS`).
|
|
80
|
+
*
|
|
81
|
+
* Optional only so that a complete `ReadLimits` object written for 2.0
|
|
82
|
+
* still compiles; when it is left out the default applies.
|
|
83
|
+
*/
|
|
84
|
+
maxXmlTokenLength?: number;
|
|
61
85
|
/** All sheets together. */
|
|
62
86
|
maxCells: number;
|
|
63
87
|
maxSharedStrings: number;
|
|
64
|
-
/**
|
|
88
|
+
/**
|
|
89
|
+
* Warnings kept before the cap applies. Past it, informational warnings are dropped and
|
|
90
|
+
* counted in one `WARNINGS_TRUNCATED` (added where the first one is dropped); data-loss
|
|
91
|
+
* warnings (`isDataLossWarning`) are still kept, up to the first 100 of each code.
|
|
92
|
+
*/
|
|
65
93
|
maxWarnings: number;
|
|
66
94
|
}
|
|
67
95
|
/** Default limits (docs/api.md §5.2; the measurements behind each value are listed there). */
|
|
68
|
-
export declare const DEFAULT_READ_LIMITS: Readonly<ReadLimits
|
|
96
|
+
export declare const DEFAULT_READ_LIMITS: Readonly<Required<ReadLimits>>;
|
|
69
97
|
/** A sheet as listed by `readSheetNames`. */
|
|
70
98
|
export interface SheetInfo {
|
|
71
99
|
name: string;
|
|
@@ -86,4 +114,4 @@ export declare function readSheetNames(input: BinaryInput, options?: {
|
|
|
86
114
|
}): Promise<SheetInfo[]>;
|
|
87
115
|
/** Reads an .xlsx, .xlsm, .xltx or .xltm file into the model. */
|
|
88
116
|
export declare function read(input: BinaryInput, options?: ReadOptions): Promise<ReadResult>;
|
|
89
|
-
export type
|
|
117
|
+
export { type AbortSignalLike, type Alignment, type BinaryInput, type BlobLike, type BlobType, type Border, type BorderSide, type BorderStyle, type Cell, type CellErrorValue, type CellInput, type CellType, type CellValue, type Color, type ColumnProps, type ColumnWidth, type DefinedName, type DocProperties, type DroppedWarnings, type ErrorCode, type ExcelPartKind, type ExcelWarning, type ExcelWarningCode, type Fill, type Font, type GradientFill, type Hyperlink, type NumFmt, type PatternFill, type PatternType, type PrintSetup, type Progress, type RichText, type RichTextRun, type RowProps, type Sheet, type SheetView, type Style, type Theme, type Workbook, isDataLossWarning };
|