@kerebron/legacy-compat 0.8.2 → 0.8.3

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/kerebron.js CHANGED
@@ -65,7 +65,7 @@ OrderedMap.prototype = {
65
65
  return new OrderedMap(t);
66
66
  };
67
67
  //#endregion
68
- //#region ../../node_modules/.deno/prosemirror-model@1.25.3/node_modules/prosemirror-model/dist/index.js
68
+ //#region ../../node_modules/.deno/prosemirror-model@1.25.9/node_modules/prosemirror-model/dist/index.js
69
69
  function findDiffStart(e, t, n) {
70
70
  for (let r = 0;; r++) {
71
71
  if (r == e.childCount || r == t.childCount) return e.childCount == t.childCount ? null : n;
@@ -76,8 +76,9 @@ function findDiffStart(e, t, n) {
76
76
  }
77
77
  if (!a.sameMarkup(o)) return n;
78
78
  if (a.isText && a.text != o.text) {
79
- for (let e = 0; a.text[e] == o.text[e]; e++) n++;
80
- return n;
79
+ let e = a.text, t = o.text, r = 0;
80
+ for (; e[r] == t[r]; r++) n++;
81
+ return r && r < e.length && r < t.length && surrogateHigh(e.charCodeAt(r - 1)) && surrogateLow(e.charCodeAt(r)) && n--, n;
81
82
  }
82
83
  if (a.content.size || o.content.size) {
83
84
  let e = findDiffStart(a.content, o.content, n + 1);
@@ -102,9 +103,9 @@ function findDiffEnd(e, t, n, r) {
102
103
  b: r
103
104
  };
104
105
  if (s.isText && s.text != c.text) {
105
- let e = 0, t = Math.min(s.text.length, c.text.length);
106
- for (; e < t && s.text[s.text.length - e - 1] == c.text[c.text.length - e - 1];) e++, n--, r--;
107
- return {
106
+ let e = s.text, t = c.text, a = e.length, o = t.length;
107
+ for (; a > 0 && o > 0 && e[a - 1] == t[o - 1];) a--, o--, n--, r--;
108
+ return a && o && a < e.length && surrogateHigh(e.charCodeAt(a - 1)) && surrogateLow(e.charCodeAt(a)) && (n++, r++), {
108
109
  a: n,
109
110
  b: r
110
111
  };
@@ -116,6 +117,12 @@ function findDiffEnd(e, t, n, r) {
116
117
  n -= l, r -= l;
117
118
  }
118
119
  }
120
+ function surrogateLow(e) {
121
+ return e >= 56320 && e < 57344;
122
+ }
123
+ function surrogateHigh(e) {
124
+ return e >= 55296 && e < 56320;
125
+ }
119
126
  var Fragment = class e {
120
127
  constructor(e, t) {
121
128
  if (this.content = e, this.size = t || 0, t == null) for (let t = 0; t < e.length; t++) this.size += e[t].nodeSize;
@@ -227,7 +234,7 @@ var Fragment = class e {
227
234
  static fromJSON(t, n) {
228
235
  if (!n) return e.empty;
229
236
  if (!Array.isArray(n)) throw RangeError("Invalid input for Fragment.fromJSON");
230
- return new e(n.map(t.nodeFromJSON));
237
+ return e.fromArray(n.map(t.nodeFromJSON));
231
238
  }
232
239
  static fromArray(t) {
233
240
  if (!t.length) return e.empty;
@@ -331,7 +338,7 @@ var ReplaceError = class extends Error {}, Slice = class e {
331
338
  return this.content.size - this.openStart - this.openEnd;
332
339
  }
333
340
  insertAt(t, n) {
334
- let r = insertInto(this.content, t + this.openStart, n);
341
+ let r = insertInto(this.content, t + this.openStart, n, this.openStart + 1, this.openEnd + 1);
335
342
  return r && new e(r, this.openStart, this.openEnd);
336
343
  }
337
344
  removeBetween(t, n) {
@@ -371,11 +378,11 @@ function removeRange(e, t, n) {
371
378
  if (r != s) throw RangeError("Removing non-flat range");
372
379
  return e.replaceChild(r, o.copy(removeRange(o.content, t - a - 1, n - a - 1)));
373
380
  }
374
- function insertInto(e, t, n, r) {
375
- let { index: a, offset: o } = e.findIndex(t), s = e.maybeChild(a);
376
- if (o == t || s.isText) return r && !r.canReplace(a, a, n) ? null : e.cut(0, t).append(n).append(e.cut(t));
377
- let c = insertInto(s.content, t - o - 1, n, s);
378
- return c && e.replaceChild(a, s.copy(c));
381
+ function insertInto(e, t, n, r, a, o) {
382
+ let { index: s, offset: c } = e.findIndex(t), l = e.maybeChild(s);
383
+ if (c == t || l.isText) return o && r <= 0 && a <= 0 && !o.canReplace(s, s, n) ? null : e.cut(0, t).append(n).append(e.cut(t));
384
+ let u = insertInto(l.content, t - c - 1, n, s == 0 ? r - 1 : 0, s == e.childCount - 1 ? a - 1 : 0, l);
385
+ return u && e.replaceChild(s, l.copy(u));
379
386
  }
380
387
  function replace(e, t, n) {
381
388
  if (n.openStart > e.depth) throw new ReplaceError("Inserted content deeper than insertion position");
@@ -414,7 +421,8 @@ function addRange(e, t, n, r) {
414
421
  t && t.depth == n && t.textOffset && addNode(t.nodeBefore, r);
415
422
  }
416
423
  function close(e, t) {
417
- return e.type.checkContent(t), e.copy(t);
424
+ if (!e.type.validContent(t)) throw new ReplaceError("Invalid content for node " + e.type.name);
425
+ return e.copy(t);
418
426
  }
419
427
  function replaceThreeWay(e, t, n, r, a) {
420
428
  let o = e.depth > a && joinable$1(e, t, a + 1), s = r.depth > a && joinable$1(n, r, a + 1), c = [];
@@ -1116,11 +1124,8 @@ function computeAttrs(e, t) {
1116
1124
  return n;
1117
1125
  }
1118
1126
  function checkAttrs(e, t, n, r) {
1119
- for (let r in t) if (!(r in e)) throw RangeError(`Unsupported attribute ${r} for ${n} of type ${r}`);
1120
- for (let n in e) {
1121
- let r = e[n];
1122
- r.validate && r.validate(t[n]);
1123
- }
1127
+ for (let a in t) if (!(a in e)) throw RangeError(`Unsupported attribute ${a} for ${n} of type ${r}`);
1128
+ for (let n in e) e[n].validate && e[n].validate(t[n]);
1124
1129
  }
1125
1130
  function initAttrs(e, t) {
1126
1131
  let n = Object.create(null);
@@ -1479,14 +1484,20 @@ var NodeContext = class {
1479
1484
  e.nodeType == 3 ? this.addTextNode(e, t) : e.nodeType == 1 && this.addElement(e, t);
1480
1485
  }
1481
1486
  addTextNode(e, t) {
1482
- let n = e.nodeValue, r = this.top, a = r.options & OPT_PRESERVE_WS_FULL ? "full" : this.localPreserveWS || (r.options & OPT_PRESERVE_WS) > 0;
1487
+ let n = e.nodeValue, r = this.top, a = r.options & OPT_PRESERVE_WS_FULL ? "full" : this.localPreserveWS || (r.options & OPT_PRESERVE_WS) > 0, { schema: o } = this.parser;
1483
1488
  if (a === "full" || r.inlineContext(e) || /[^ \t\r\n\u000c]/.test(n)) {
1484
- if (a) n = a === "full" ? n.replace(/\r\n?/g, "\n") : n.replace(/\r?\n|\r/g, " ");
1485
- else if (n = n.replace(/[ \t\r\n\u000c]+/g, " "), /^[ \t\r\n\u000c]/.test(n) && this.open == this.nodes.length - 1) {
1486
- let t = r.content[r.content.length - 1], a = e.previousSibling;
1487
- (!t || a && a.nodeName == "BR" || t.isText && /[ \t\r\n\u000c]$/.test(t.text)) && (n = n.slice(1));
1488
- }
1489
- n && this.insertNode(this.parser.schema.text(n), t, !/\S/.test(n)), this.findInText(e);
1489
+ if (!a) {
1490
+ if (n = n.replace(/[ \t\r\n\u000c]+/g, " "), /^[ \t\r\n\u000c]/.test(n) && this.open == this.nodes.length - 1) {
1491
+ let t = r.content[r.content.length - 1], a = e.previousSibling;
1492
+ (!t || a && a.nodeName == "BR" || t.isText && /[ \t\r\n\u000c]$/.test(t.text)) && (n = n.slice(1));
1493
+ }
1494
+ } else if (a === "full") n = n.replace(/\r\n?/g, "\n");
1495
+ else if (o.linebreakReplacement && /[\r\n]/.test(n) && this.top.findWrapping(o.linebreakReplacement.create())) {
1496
+ let e = n.split(/\r?\n|\r/);
1497
+ for (let n = 0; n < e.length; n++) n && this.insertNode(o.linebreakReplacement.create(), t, !0), e[n] && this.insertNode(o.text(e[n]), t, !/\S/.test(e[n]));
1498
+ n = "";
1499
+ } else n = n.replace(/\r?\n|\r/g, " ");
1500
+ n && this.insertNode(o.text(n), t, !/\S/.test(n)), this.findInText(e);
1490
1501
  } else this.findInside(e);
1491
1502
  }
1492
1503
  addElement(e, t, n) {
@@ -1728,6 +1739,7 @@ var DOMSerializer = class e {
1728
1739
  }), n;
1729
1740
  }
1730
1741
  serializeNodeInner(e, t) {
1742
+ if (e.isText) return doc$1(t).createTextNode(e.text);
1731
1743
  let { dom: n, contentDOM: r } = renderSpec(doc$1(t), this.nodes[e.type.name](e), null, e.attrs);
1732
1744
  if (r) {
1733
1745
  if (e.isLeaf) throw RangeError("Content hole not allowed in a leaf node spec");
@@ -1748,7 +1760,7 @@ var DOMSerializer = class e {
1748
1760
  return r && renderSpec(doc$1(n), r(e, t), null, e.attrs);
1749
1761
  }
1750
1762
  static renderSpec(e, t, n = null, r) {
1751
- return renderSpec(e, t, n, r);
1763
+ return typeof t == "string" ? { dom: e.createTextNode(t) } : renderSpec(e, t, n, r);
1752
1764
  }
1753
1765
  static fromSchema(t) {
1754
1766
  return t.cached.domSerializer || (t.cached.domSerializer = new e(this.nodesFromSchema(t), this.marksFromSchema(t)));
@@ -1787,9 +1799,8 @@ function suspiciousAttributesInner(e) {
1787
1799
  return n(e), t;
1788
1800
  }
1789
1801
  function renderSpec(e, t, n, r) {
1790
- if (typeof t == "string") return { dom: e.createTextNode(t) };
1791
- if (t.nodeType != null) return { dom: t };
1792
- if (t.dom && t.dom.nodeType != null) return t;
1802
+ if (t.nodeType == 1) return { dom: t };
1803
+ if (t.dom && t.dom.nodeType == 1) return t;
1793
1804
  let a = t[0], o;
1794
1805
  if (typeof a != "string") throw RangeError("Invalid array passed to renderSpec");
1795
1806
  if (r && (o = suspiciousAttributes(r)) && o.indexOf(t) > -1) throw RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");
@@ -1811,7 +1822,8 @@ function renderSpec(e, t, n, r) {
1811
1822
  dom: l,
1812
1823
  contentDOM: l
1813
1824
  };
1814
- } else {
1825
+ } else if (typeof o == "string") l.appendChild(e.createTextNode(o));
1826
+ else {
1815
1827
  let { dom: t, contentDOM: a } = renderSpec(e, o, n, r);
1816
1828
  if (l.appendChild(t), a) {
1817
1829
  if (c) throw RangeError("Multiple content holes");