@knowvah/dot-engine 2.6.10 → 2.6.11

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/render.js CHANGED
@@ -5955,28 +5955,46 @@ var HTML_ENTITIES = {
5955
5955
  "zwj": 8205,
5956
5956
  "zwnj": 8204
5957
5957
  };
5958
- var BASIC_ENTITIES = {
5959
- amp: 38,
5960
- lt: 60,
5961
- gt: 62,
5962
- quot: 34,
5963
- apos: 39
5964
- };
5965
- function numericEntityValue(body) {
5966
- const hex = body[1] === "x" || body[1] === "X";
5967
- const v = hex ? parseInt(body.slice(2), 16) : parseInt(body.slice(1), 10);
5968
- return Number.isFinite(v) && v > 0 && v <= 1114111 ? v : null;
5958
+ var ENTITY_NAME_LENGTH_MAX = 8;
5959
+ function numericEntity(s, at) {
5960
+ const hex = s[at + 1] === "x" || s[at + 1] === "X";
5961
+ const digit = hex ? /^[0-9A-Fa-f]$/ : /^[0-9]$/;
5962
+ let n = 0;
5963
+ let i = hex ? 2 : 1;
5964
+ for (; i < 8; i++) {
5965
+ const c = s[at + i] ?? "";
5966
+ if (!digit.test(c)) break;
5967
+ n = n * (hex ? 16 : 10) + parseInt(c, 16);
5968
+ }
5969
+ if (i < 8 && s[at + i] === ";") return { value: n, next: at + i + 1 };
5970
+ return { value: 0, next: at };
5971
+ }
5972
+ function namedEntity(s, at) {
5973
+ for (let i = 0; i < ENTITY_NAME_LENGTH_MAX; i++) {
5974
+ const c = s[at + i];
5975
+ if (c === void 0 || c === "\0") break;
5976
+ if (c === ";") {
5977
+ const key = s.slice(at, at + i);
5978
+ if (Object.hasOwn(HTML_ENTITIES, key)) return { value: HTML_ENTITIES[key], next: at + i + 1 };
5979
+ break;
5980
+ }
5981
+ }
5982
+ return { value: 0, next: at };
5969
5983
  }
5970
- function entityValue(body) {
5971
- if (body[0] === "#") return numericEntityValue(body);
5972
- return BASIC_ENTITIES[body] ?? HTML_ENTITIES[body] ?? null;
5984
+ function htmlEntity(s, at) {
5985
+ return s[at] === "#" ? numericEntity(s, at) : namedEntity(s, at);
5973
5986
  }
5974
5987
  function htmlEntityUTF8(s) {
5975
- if (s.indexOf("&") < 0) return s;
5976
- return s.replace(/&(#x[0-9a-fA-F]+|#[0-9]+|[A-Za-z]+);/g, (m, body) => {
5977
- const v = entityValue(body);
5978
- return v === null ? m : String.fromCodePoint(v);
5979
- });
5988
+ let amp = s.indexOf("&");
5989
+ if (amp < 0) return s;
5990
+ let out = "";
5991
+ let from = 0;
5992
+ for (; amp >= 0; amp = s.indexOf("&", from)) {
5993
+ const e = htmlEntity(s, amp + 1);
5994
+ out += s.slice(from, amp) + (e.value ? String.fromCodePoint(e.value) : "&");
5995
+ from = e.next;
5996
+ }
5997
+ return out + s.slice(from);
5980
5998
  }
5981
5999
 
5982
6000
  // src/common/htmltable-lex-attvalue.ts
@@ -6370,8 +6388,26 @@ function releaseXb(st, first) {
6370
6388
  function cleanText(decoded) {
6371
6389
  return decoded.replace(/[\x00-\x1f]/g, "");
6372
6390
  }
6391
+ var XML_PREDEFINED = { lt: "<", gt: ">", amp: "&", quot: '"', apos: "'" };
6392
+ var SCAN_ENTITY_MIN = 2;
6393
+ var SCAN_ENTITY_MAX = 8;
6394
+ var TEXT_REF = /&(#x[0-9A-Fa-f]+|#[0-9]+|[^&;]+);/g;
6395
+ function textRefValue(ref, body) {
6396
+ if (body[0] === "#") {
6397
+ const v = charRefNumber(ref);
6398
+ return v < 0 ? ref : String.fromCodePoint(v);
6399
+ }
6400
+ const n = body.length;
6401
+ if (n >= SCAN_ENTITY_MIN && n <= SCAN_ENTITY_MAX && Object.hasOwn(HTML_ENTITIES, body)) {
6402
+ return String.fromCodePoint(HTML_ENTITIES[body]);
6403
+ }
6404
+ return Object.hasOwn(XML_PREDEFINED, body) ? XML_PREDEFINED[body] : ref;
6405
+ }
6406
+ function decodeTextRefs(raw) {
6407
+ return raw.indexOf("&") < 0 ? raw : raw.replace(TEXT_REF, textRefValue);
6408
+ }
6373
6409
  function textTokens(raw) {
6374
- return charDataTokens(htmlEntityUTF8(raw));
6410
+ return charDataTokens(decodeTextRefs(raw));
6375
6411
  }
6376
6412
  function charDataTokens(decoded) {
6377
6413
  const clean = cleanText(decoded);