@pie-element/venn-classification 0.1.1-next.13 → 0.1.1-next.15

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.
@@ -5599,12 +5599,12 @@ var p$1 = /* @__PURE__ */ from_html("<label class=\"pie-settings-choice-row svel
5599
5599
  var m$1 = /* @__PURE__ */ from_html("<fieldset class=\"pie-settings-choice svelte-1ang3sw\"><legend class=\"svelte-1ang3sw\"> </legend> <!></fieldset>");
5600
5600
  var h$2 = /* @__PURE__ */ from_html("<fieldset class=\"pie-settings-group svelte-1ang3sw\"><legend class=\"pie-settings-group-name svelte-1ang3sw\"> </legend> <!></fieldset>");
5601
5601
  var g$1 = /* @__PURE__ */ from_html("<div class=\"pie-settings-panel svelte-1ang3sw\"></div>");
5602
- var _ = {
5602
+ var _$1 = {
5603
5603
  hash: "svelte-1ang3sw",
5604
5604
  code: ".pie-settings-panel.svelte-1ang3sw {display:flex;flex-direction:column;gap:16px;padding:16px;border:1px solid var(--pie-border-light, #ccc);border-radius:4px;color:var(--pie-text, #212121);}fieldset.svelte-1ang3sw {margin:0;padding:0;border:0;min-width:0;}.pie-settings-group.svelte-1ang3sw {display:flex;flex-direction:column;gap:8px;}.pie-settings-group-name.svelte-1ang3sw {margin-bottom:8px;font-weight:600;}.pie-settings-toggle.svelte-1ang3sw {display:flex;align-items:center;justify-content:space-between;gap:12px;}.pie-settings-choice.svelte-1ang3sw legend:where(.svelte-1ang3sw) {margin-bottom:4px;}.pie-settings-choice-row.svelte-1ang3sw {display:flex;align-items:center;gap:8px;}input.svelte-1ang3sw {accent-color:var(--pie-primary, #3f51b5);}input.svelte-1ang3sw:focus-visible {outline:2px solid var(--pie-focus-outline, #1a73e8);outline-offset:2px;}"
5605
5605
  };
5606
5606
  function v$1(t, n) {
5607
- push(n, !0), append_styles$1(t, _);
5607
+ push(n, !0), append_styles$1(t, _$1);
5608
5608
  let r = prop(n, "configuration", 19, () => ({})), i = Math.random().toString(36).slice(2, 10), a = /* @__PURE__ */ user_derived(() => Object.entries(n.groups).map(([e, t]) => [e, Object.entries(t).filter((e) => !!e[1])]).filter(([, e]) => e.length > 0)), o = (e, t) => u$1(t.isConfigProperty ? r() : n.model, e);
5609
5609
  function s(e, t, i) {
5610
5610
  t.isConfigProperty ? n.onChangeConfiguration?.(d$1(r(), e, i), e) : n.onChangeModel(d$1(n.model, e, i), e);
@@ -5737,7 +5737,7 @@ OrderedMap.from = function(value) {
5737
5737
  return new OrderedMap(content);
5738
5738
  };
5739
5739
  //#endregion
5740
- //#region ../../../node_modules/.bun/prosemirror-model@1.25.11/node_modules/prosemirror-model/dist/index.js
5740
+ //#region ../../../node_modules/.bun/prosemirror-model@1.25.12/node_modules/prosemirror-model/dist/index.js
5741
5741
  function findDiffStart(a, b, pos) {
5742
5742
  for (let i = 0;; i++) {
5743
5743
  if (i == a.childCount || i == b.childCount) return a.childCount == b.childCount ? null : pos;
@@ -6183,9 +6183,7 @@ var Mark$1 = class Mark$1 {
6183
6183
  if (!json) throw new RangeError("Invalid input for Mark.fromJSON");
6184
6184
  let type = schema.marks[json.type];
6185
6185
  if (!type) throw new RangeError(`There is no mark type ${json.type} in this schema`);
6186
- let mark = type.create(json.attrs);
6187
- type.checkAttrs(mark.attrs);
6188
- return mark;
6186
+ return type.create(json.attrs);
6189
6187
  }
6190
6188
  /**
6191
6189
  Test whether two sets of marks are identical.
@@ -7082,11 +7080,11 @@ var Node$2 = class Node$2 {
7082
7080
  */
7083
7081
  check() {
7084
7082
  this.type.checkContent(this.content);
7085
- this.type.checkAttrs(this.attrs);
7083
+ checkAttrs(this.type.attrs, this.attrs, "node", this.type.name);
7086
7084
  let copy = Mark$1.none;
7087
7085
  for (let i = 0; i < this.marks.length; i++) {
7088
7086
  let mark = this.marks[i];
7089
- mark.type.checkAttrs(mark.attrs);
7087
+ checkAttrs(mark.type.attrs, mark.attrs, "mark", mark.type.name);
7090
7088
  copy = mark.addToSet(copy);
7091
7089
  }
7092
7090
  if (!Mark$1.sameSet(copy, this.marks)) throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map((m) => m.type.name)}`);
@@ -7120,9 +7118,7 @@ var Node$2 = class Node$2 {
7120
7118
  return schema.text(json.text, marks);
7121
7119
  }
7122
7120
  let content = Fragment.fromJSON(schema, json.content);
7123
- let node = schema.nodeType(json.type).create(json.attrs, content, marks);
7124
- node.type.checkAttrs(node.attrs);
7125
- return node;
7121
+ return schema.nodeType(json.type).create(json.attrs, content, marks);
7126
7122
  }
7127
7123
  };
7128
7124
  Node$2.prototype.text = void 0;
@@ -7172,6 +7168,10 @@ function wrapMarks(marks, str) {
7172
7168
  for (let i = marks.length - 1; i >= 0; i--) str = marks[i].type.name + "(" + str + ")";
7173
7169
  return str;
7174
7170
  }
7171
+ function checkAttrs(attrs, values, type, name) {
7172
+ for (let attr in values) if (!(attr in attrs)) throw new RangeError(`Unsupported attribute ${attr} for ${type} of type ${name}`);
7173
+ for (let attr in attrs) if (attrs[attr].validate) attrs[attr].validate(values[attr]);
7174
+ }
7175
7175
  /**
7176
7176
  Instances of this class represent a match state of a node type's
7177
7177
  [content expression](https://prosemirror.net/docs/ref/#model.NodeSpec.content), and can be used to
@@ -7580,20 +7580,15 @@ function defaultAttrs(attrs) {
7580
7580
  function computeAttrs(attrs, value) {
7581
7581
  let built = Object.create(null);
7582
7582
  for (let name in attrs) {
7583
+ let attr = attrs[name];
7583
7584
  let given = value && value[name];
7584
- if (given === void 0) {
7585
- let attr = attrs[name];
7586
- if (attr.hasDefault) given = attr.default;
7587
- else throw new RangeError("No value supplied for attribute " + name);
7588
- }
7585
+ if (given === void 0) if (attr.hasDefault) given = attr.default;
7586
+ else throw new RangeError("No value supplied for attribute " + name);
7587
+ else if (attr.validate) attr.validate(given);
7589
7588
  built[name] = given;
7590
7589
  }
7591
7590
  return built;
7592
7591
  }
7593
- function checkAttrs(attrs, values, type, name) {
7594
- for (let attr in values) if (!(attr in attrs)) throw new RangeError(`Unsupported attribute ${attr} for ${type} of type ${name}`);
7595
- for (let attr in attrs) if (attrs[attr].validate) attrs[attr].validate(values[attr]);
7596
- }
7597
7592
  function initAttrs(typeName, attrs) {
7598
7593
  let result = Object.create(null);
7599
7594
  if (attrs) for (let name in attrs) result[name] = new Attribute(typeName, name, attrs[name]);
@@ -7748,11 +7743,9 @@ var NodeType$1 = class NodeType$1 {
7748
7743
  if (!this.validContent(content)) throw new RangeError(`Invalid content for node ${this.name}: ${content.toString().slice(0, 50)}`);
7749
7744
  }
7750
7745
  /**
7751
- @internal
7746
+ @internal no longer useful, but called by old prosemirror-view versions
7752
7747
  */
7753
- checkAttrs(attrs) {
7754
- checkAttrs(this.attrs, attrs, "node", this.name);
7755
- }
7748
+ checkAttrs(attrs) {}
7756
7749
  /**
7757
7750
  Check whether the given mark type is allowed in this node.
7758
7751
  */
@@ -7863,12 +7856,6 @@ var MarkType = class MarkType {
7863
7856
  for (let i = 0; i < set.length; i++) if (set[i].type == this) return set[i];
7864
7857
  }
7865
7858
  /**
7866
- @internal
7867
- */
7868
- checkAttrs(attrs) {
7869
- checkAttrs(this.attrs, attrs, "mark", this.name);
7870
- }
7871
- /**
7872
7859
  Queries whether a given mark type is
7873
7860
  [excluded](https://prosemirror.net/docs/ref/#model.MarkSpec.excludes) by this one.
7874
7861
  */
@@ -8727,7 +8714,7 @@ function renderSpec(doc, structure, xmlNS, blockArraysIn) {
8727
8714
  };
8728
8715
  }
8729
8716
  //#endregion
8730
- //#region ../../../node_modules/.bun/prosemirror-transform@1.12.0/node_modules/prosemirror-transform/dist/index.js
8717
+ //#region ../../../node_modules/.bun/prosemirror-transform@1.12.2/node_modules/prosemirror-transform/dist/index.js
8731
8718
  var lower16 = 65535;
8732
8719
  var factor16 = Math.pow(2, 16);
8733
8720
  function makeRecover(index, offset) {
@@ -8830,8 +8817,11 @@ var StepMap = class StepMap {
8830
8817
  let result = start + diff + (side < 0 ? 0 : newSize);
8831
8818
  if (simple) return result;
8832
8819
  let recover = pos == (assoc < 0 ? start : end) ? null : makeRecover(i / 3, pos - start);
8833
- let del = pos == start ? DEL_AFTER : pos == end ? DEL_BEFORE : DEL_ACROSS;
8834
- if (assoc < 0 ? pos != start : pos != end) del |= DEL_SIDE;
8820
+ let del = 0;
8821
+ if (oldSize) {
8822
+ del |= pos == start ? DEL_AFTER : pos == end ? DEL_BEFORE : DEL_ACROSS;
8823
+ if (assoc < 0 ? pos != start : pos != end) del |= DEL_SIDE;
8824
+ }
8835
8825
  return new MapResult(result, del, recover);
8836
8826
  }
8837
8827
  diff += newSize - oldSize;
@@ -9952,9 +9942,9 @@ var Fitter = class {
9952
9942
  }
9953
9943
  openMore() {
9954
9944
  let { content, openStart, openEnd } = this.unplaced;
9955
- let inner = contentAt(content, openStart);
9956
- if (!inner.childCount || inner.firstChild.isLeaf) return false;
9957
- this.unplaced = new Slice(content, openStart + 1, Math.max(openEnd, inner.size + openStart >= content.size - openEnd ? openStart + 1 : 0));
9945
+ if (maxOpen(content, -1) <= openStart) return false;
9946
+ if (this.unplaced.size > 1 && maxOpen(content, 1) > openEnd) openEnd++;
9947
+ this.unplaced = new Slice(content, openStart + 1, openEnd);
9958
9948
  return true;
9959
9949
  }
9960
9950
  dropNode() {
@@ -10088,6 +10078,13 @@ function invalidMarks(type, fragment, start) {
10088
10078
  function definesContent(type) {
10089
10079
  return type.spec.defining || type.spec.definingForContent;
10090
10080
  }
10081
+ function maxOpen(frag, side) {
10082
+ for (let count = 0;; count++) {
10083
+ let ch = side < 0 ? frag.firstChild : frag.lastChild;
10084
+ if (!ch || ch.isAtom) return count;
10085
+ frag = ch.content;
10086
+ }
10087
+ }
10091
10088
  function replaceRange(tr, from, to, slice) {
10092
10089
  if (!slice.size) return tr.deleteRange(from, to);
10093
10090
  let $from = tr.doc.resolve(from), $to = tr.doc.resolve(to);
@@ -11533,7 +11530,7 @@ var PluginKey = class {
11533
11530
  }
11534
11531
  };
11535
11532
  //#endregion
11536
- //#region ../../../node_modules/.bun/prosemirror-commands@1.7.1/node_modules/prosemirror-commands/dist/index.js
11533
+ //#region ../../../node_modules/.bun/prosemirror-commands@1.7.2/node_modules/prosemirror-commands/dist/index.js
11537
11534
  /**
11538
11535
  Delete the selection, if there is one.
11539
11536
  */
@@ -11855,20 +11852,23 @@ a custom function to determine the type of the newly split off block.
11855
11852
  */
11856
11853
  function splitBlockAs(splitNode) {
11857
11854
  return (state, dispatch) => {
11858
- let { $from, $to } = state.selection;
11859
11855
  if (state.selection instanceof NodeSelection && state.selection.node.isBlock) {
11856
+ let { $from } = state.selection;
11860
11857
  if (!$from.parentOffset || !canSplit(state.doc, $from.pos)) return false;
11861
11858
  if (dispatch) dispatch(state.tr.split($from.pos).scrollIntoView());
11862
11859
  return true;
11863
11860
  }
11864
- if (!$from.depth) return false;
11861
+ if (!state.selection.$from.depth) return false;
11862
+ let tr = state.tr;
11863
+ if (!state.selection.empty && (state.selection instanceof TextSelection || state.selection instanceof AllSelection)) tr.deleteSelection();
11864
+ let { $from } = tr.selection, mapFrom = tr.steps.length;
11865
11865
  let types = [];
11866
11866
  let splitDepth, deflt, atEnd = false, atStart = false;
11867
11867
  for (let d = $from.depth;; d--) if ($from.node(d).isBlock) {
11868
11868
  atEnd = $from.end(d) == $from.pos + ($from.depth - d);
11869
11869
  atStart = $from.start(d) == $from.pos - ($from.depth - d);
11870
11870
  deflt = defaultBlockAt$1($from.node(d - 1).contentMatchAt($from.indexAfter(d - 1)));
11871
- let splitType = splitNode && splitNode($to.parent, atEnd, $from);
11871
+ let splitType = splitNode && splitNode($from.parent, atEnd, $from);
11872
11872
  types.unshift(splitType || (atEnd && deflt ? { type: deflt } : null));
11873
11873
  splitDepth = d;
11874
11874
  break;
@@ -11876,9 +11876,7 @@ function splitBlockAs(splitNode) {
11876
11876
  if (d == 1) return false;
11877
11877
  types.unshift(null);
11878
11878
  }
11879
- let tr = state.tr;
11880
- if (state.selection instanceof TextSelection || state.selection instanceof AllSelection) tr.deleteSelection();
11881
- let splitPos = tr.mapping.map($from.pos);
11879
+ let splitPos = $from.pos;
11882
11880
  let can = canSplit(tr.doc, splitPos, types.length, types);
11883
11881
  if (!can) {
11884
11882
  types[0] = deflt ? { type: deflt } : null;
@@ -11887,8 +11885,9 @@ function splitBlockAs(splitNode) {
11887
11885
  if (!can) return false;
11888
11886
  tr.split(splitPos, types.length, types);
11889
11887
  if (!atEnd && atStart && $from.node(splitDepth).type != deflt) {
11890
- let first = tr.mapping.map($from.before(splitDepth)), $first = tr.doc.resolve(first);
11891
- if (deflt && $from.node(splitDepth - 1).canReplaceWith($first.index(), $first.index() + 1, deflt)) tr.setNodeMarkup(tr.mapping.map($from.before(splitDepth)), deflt);
11888
+ let mapping = tr.mapping.slice(mapFrom);
11889
+ let first = mapping.map($from.before(splitDepth)), $first = tr.doc.resolve(first);
11890
+ if (deflt && $from.node(splitDepth - 1).canReplaceWith($first.index(), $first.index() + 1, deflt)) tr.setNodeMarkup(mapping.map($from.before(splitDepth)), deflt);
11892
11891
  }
11893
11892
  if (dispatch) dispatch(tr.scrollIntoView());
11894
11893
  return true;
@@ -12214,7 +12213,7 @@ function sinkListItem(itemType) {
12214
12213
  };
12215
12214
  }
12216
12215
  //#endregion
12217
- //#region ../../../node_modules/.bun/prosemirror-view@1.42.3/node_modules/prosemirror-view/dist/index.js
12216
+ //#region ../../../node_modules/.bun/prosemirror-view@1.42.6/node_modules/prosemirror-view/dist/index.js
12218
12217
  var domIndex = function(node) {
12219
12218
  for (var index = 0;; index++) {
12220
12219
  node = node.previousSibling;
@@ -12245,12 +12244,12 @@ function scanFor(node, off, targetNode, targetOff, dir) {
12245
12244
  if (node == targetNode && off == targetOff) return true;
12246
12245
  if (off == (dir < 0 ? 0 : nodeSize(node))) {
12247
12246
  let parent = node.parentNode;
12248
- if (!parent || parent.nodeType != 1 || hasBlockDesc(node) || atomElements.test(node.nodeName) || node.contentEditable == "false") return false;
12247
+ if (!parent || !isElt(parent) || hasBlockDesc(node) || atomElements.test(node.nodeName) || node.contentEditable == "false") return false;
12249
12248
  off = domIndex(node) + (dir < 0 ? 0 : 1);
12250
12249
  node = parent;
12251
- } else if (node.nodeType == 1) {
12250
+ } else if (isElt(node)) {
12252
12251
  let child = node.childNodes[off + (dir < 0 ? -1 : 0)];
12253
- if (child.nodeType == 1 && child.contentEditable == "false") if ((_a = child.pmViewDesc) === null || _a === void 0 ? void 0 : _a.ignoreForSelection) off += dir;
12252
+ if (isElt(child) && child.contentEditable == "false") if ((_a = child.pmViewDesc) === null || _a === void 0 ? void 0 : _a.ignoreForSelection) off += dir;
12254
12253
  else return false;
12255
12254
  else {
12256
12255
  node = child;
@@ -12262,10 +12261,19 @@ function scanFor(node, off, targetNode, targetOff, dir) {
12262
12261
  function nodeSize(node) {
12263
12262
  return node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length;
12264
12263
  }
12264
+ function isElt(node) {
12265
+ return node.nodeType == 1;
12266
+ }
12267
+ function isText(node) {
12268
+ return node.nodeType == 3;
12269
+ }
12270
+ function contains(parent, child) {
12271
+ return child ? parent.contains(isElt(child) ? child : child.parentNode) : false;
12272
+ }
12265
12273
  function textNodeBefore$1(node, offset) {
12266
12274
  for (;;) {
12267
- if (node.nodeType == 3 && offset) return node;
12268
- if (node.nodeType == 1 && offset > 0) {
12275
+ if (isText(node) && offset) return node;
12276
+ if (isElt(node) && offset > 0) {
12269
12277
  if (node.contentEditable == "false") return null;
12270
12278
  node = node.childNodes[offset - 1];
12271
12279
  offset = nodeSize(node);
@@ -12277,8 +12285,8 @@ function textNodeBefore$1(node, offset) {
12277
12285
  }
12278
12286
  function textNodeAfter$1(node, offset) {
12279
12287
  for (;;) {
12280
- if (node.nodeType == 3 && offset < node.nodeValue.length) return node;
12281
- if (node.nodeType == 1 && offset < node.childNodes.length) {
12288
+ if (isText(node) && offset < node.nodeValue.length) return node;
12289
+ if (isElt(node) && offset < node.childNodes.length) {
12282
12290
  if (node.contentEditable == "false") return null;
12283
12291
  node = node.childNodes[offset];
12284
12292
  offset = 0;
@@ -12389,13 +12397,12 @@ function scrollRectIntoView(view, rect, startDOM) {
12389
12397
  let doc = view.dom.ownerDocument;
12390
12398
  for (let parent = startDOM || view.dom;;) {
12391
12399
  if (!parent) break;
12392
- if (parent.nodeType != 1) {
12400
+ if (!isElt(parent)) {
12393
12401
  parent = parentNode(parent);
12394
12402
  continue;
12395
12403
  }
12396
- let elt = parent;
12397
- let atTop = elt == doc.body;
12398
- let bounding = atTop ? windowRect(doc) : clientRect(elt);
12404
+ let atTop = parent == doc.body;
12405
+ let bounding = atTop ? windowRect(doc) : clientRect(parent);
12399
12406
  let moveX = 0, moveY = 0;
12400
12407
  if (rect.top < bounding.top + getSide(scrollThreshold, "top")) moveY = -(bounding.top - rect.top + getSide(scrollMargin, "top"));
12401
12408
  else if (rect.bottom > bounding.bottom - getSide(scrollThreshold, "bottom")) moveY = rect.bottom - rect.top > bounding.bottom - bounding.top ? rect.top + getSide(scrollMargin, "top") - bounding.top : rect.bottom - bounding.bottom + getSide(scrollMargin, "bottom");
@@ -12403,10 +12410,10 @@ function scrollRectIntoView(view, rect, startDOM) {
12403
12410
  else if (rect.right > bounding.right - getSide(scrollThreshold, "right")) moveX = rect.right - bounding.right + getSide(scrollMargin, "right");
12404
12411
  if (moveX || moveY) if (atTop) doc.defaultView.scrollBy(moveX, moveY);
12405
12412
  else {
12406
- let startX = elt.scrollLeft, startY = elt.scrollTop;
12407
- if (moveY) elt.scrollTop += moveY;
12408
- if (moveX) elt.scrollLeft += moveX;
12409
- let dX = elt.scrollLeft - startX, dY = elt.scrollTop - startY;
12413
+ let startX = parent.scrollLeft, startY = parent.scrollTop;
12414
+ if (moveY) parent.scrollTop += moveY;
12415
+ if (moveX) parent.scrollLeft += moveX;
12416
+ let dX = parent.scrollLeft - startX, dY = parent.scrollTop - startY;
12410
12417
  rect = {
12411
12418
  left: rect.left - dX,
12412
12419
  top: rect.top - dY,
@@ -12476,13 +12483,14 @@ function focusPreventScroll(dom) {
12476
12483
  }
12477
12484
  }
12478
12485
  function findOffsetInNode(node, coords) {
12479
- let closest, dxClosest = 2e8, coordsClosest, offset = 0;
12486
+ let closest;
12487
+ let dxClosest = 2e8, coordsClosest, offset = 0;
12480
12488
  let rowBot = coords.top, rowTop = coords.top;
12481
12489
  let firstBelow, coordsBelow;
12482
12490
  for (let child = node.firstChild, childIndex = 0; child; child = child.nextSibling, childIndex++) {
12483
12491
  let rects;
12484
- if (child.nodeType == 1) rects = child.getClientRects();
12485
- else if (child.nodeType == 3) rects = textRange(child).getClientRects();
12492
+ if (isElt(child)) rects = child.getClientRects();
12493
+ else if (isText(child)) rects = textRange(child).getClientRects();
12486
12494
  else continue;
12487
12495
  for (let i = 0; i < rects.length; i++) {
12488
12496
  let rect = rects[i];
@@ -12493,11 +12501,11 @@ function findOffsetInNode(node, coords) {
12493
12501
  if (dx < dxClosest) {
12494
12502
  closest = child;
12495
12503
  dxClosest = dx;
12496
- coordsClosest = dx && closest.nodeType == 3 ? {
12504
+ coordsClosest = dx && isText(closest) ? {
12497
12505
  left: rect.right < coords.left ? rect.right : rect.left,
12498
12506
  top: coords.top
12499
12507
  } : coords;
12500
- if (child.nodeType == 1 && dx) offset = childIndex + (coords.left >= (rect.left + rect.right) / 2 ? 1 : 0);
12508
+ if (isElt(child) && dx) offset = childIndex + (coords.left >= (rect.left + rect.right) / 2 ? 1 : 0);
12501
12509
  continue;
12502
12510
  }
12503
12511
  } else if (rect.top > coords.top && !firstBelow && rect.left <= coords.left && rect.right >= coords.left) {
@@ -12515,8 +12523,8 @@ function findOffsetInNode(node, coords) {
12515
12523
  coordsClosest = coordsBelow;
12516
12524
  dxClosest = 0;
12517
12525
  }
12518
- if (closest && closest.nodeType == 3) return findOffsetInText(closest, coordsClosest);
12519
- if (!closest || dxClosest && closest.nodeType == 1) return {
12526
+ if (closest && isText(closest)) return findOffsetInText(closest, coordsClosest);
12527
+ if (!closest || dxClosest) return {
12520
12528
  node,
12521
12529
  offset
12522
12530
  };
@@ -12554,7 +12562,7 @@ function targetKludge(dom, coords) {
12554
12562
  }
12555
12563
  function posFromElement(view, elt, coords) {
12556
12564
  let { node, offset } = findOffsetInNode(elt, coords), bias = -1;
12557
- if (node.nodeType == 1 && !node.firstChild) {
12565
+ if (isElt(node) && !node.firstChild) {
12558
12566
  let rect = node.getBoundingClientRect();
12559
12567
  bias = rect.left != rect.right && coords.left > (rect.left + rect.right) / 2 ? 1 : -1;
12560
12568
  }
@@ -12566,7 +12574,7 @@ function posFromCaret(view, node, offset, coords) {
12566
12574
  if (cur == view.dom) break;
12567
12575
  let desc = view.docView.nearestDesc(cur, true), rect;
12568
12576
  if (!desc) return null;
12569
- if (desc.dom.nodeType == 1 && (desc.node.isBlock && desc.parent || !desc.contentDOM) && ((rect = desc.dom.getBoundingClientRect()).width || rect.height)) {
12577
+ if (isElt(desc.dom) && (desc.node.isBlock && desc.parent || !desc.contentDOM) && ((rect = desc.dom.getBoundingClientRect()).width || rect.height)) {
12570
12578
  if (desc.node.isBlock && desc.parent && !/^T(R|BODY|HEAD|FOOT)$/.test(desc.dom.nodeName)) {
12571
12579
  if (!sawBlock && rect.left > coords.left || rect.top > coords.top) outsideBlock = desc.posBefore;
12572
12580
  else if (!sawBlock && rect.right < coords.left || rect.bottom < coords.top) outsideBlock = desc.posAfter;
@@ -12582,7 +12590,7 @@ function elementFromPoint(element, coords, box) {
12582
12590
  let len = element.childNodes.length;
12583
12591
  if (len && box.top < box.bottom) for (let startI = Math.max(0, Math.min(len - 1, Math.floor(len * (coords.top - box.top) / (box.bottom - box.top)) - 2)), i = startI;;) {
12584
12592
  let child = element.childNodes[i];
12585
- if (child.nodeType == 1) {
12593
+ if (isElt(child)) {
12586
12594
  let rects = child.getClientRects();
12587
12595
  for (let j = 0; j < rects.length; j++) {
12588
12596
  let rect = rects[j];
@@ -12599,7 +12607,7 @@ function posAtCoords(view, coords) {
12599
12607
  if (caret) ({node, offset} = caret);
12600
12608
  let elt = (view.root.elementFromPoint ? view.root : doc).elementFromPoint(coords.left, coords.top);
12601
12609
  let pos;
12602
- if (!elt || !view.dom.contains(elt.nodeType != 1 ? elt.parentNode : elt)) {
12610
+ if (!elt || !view.dom.contains(elt)) {
12603
12611
  let box = view.dom.getBoundingClientRect();
12604
12612
  if (!inRect(coords, box)) return null;
12605
12613
  elt = elementFromPoint(view.dom, coords, box);
@@ -12610,7 +12618,7 @@ function posAtCoords(view, coords) {
12610
12618
  }
12611
12619
  elt = targetKludge(elt, coords);
12612
12620
  if (node) {
12613
- if (gecko && node.nodeType == 1) {
12621
+ if (gecko && isElt(node)) {
12614
12622
  offset = Math.min(offset, node.childNodes.length);
12615
12623
  if (offset < node.childNodes.length) {
12616
12624
  let next = node.childNodes[offset], box;
@@ -12618,9 +12626,9 @@ function posAtCoords(view, coords) {
12618
12626
  }
12619
12627
  }
12620
12628
  let prev;
12621
- if (webkit && offset && node.nodeType == 1 && (prev = node.childNodes[offset - 1]).nodeType == 1 && prev.contentEditable == "false" && prev.getBoundingClientRect().top >= coords.top) offset--;
12622
- if (node == view.dom && offset == node.childNodes.length - 1 && node.lastChild.nodeType == 1 && coords.top > node.lastChild.getBoundingClientRect().bottom) pos = view.state.doc.content.size;
12623
- else if (offset == 0 || node.nodeType != 1 || node.childNodes[offset - 1].nodeName != "BR") pos = posFromCaret(view, node, offset, coords);
12629
+ if (webkit && offset && isElt(node) && isElt(prev = node.childNodes[offset - 1]) && prev.contentEditable == "false" && prev.getBoundingClientRect().top >= coords.top) offset--;
12630
+ if (node == view.dom && offset == node.childNodes.length - 1 && isElt(node.lastChild) && coords.top > node.lastChild.getBoundingClientRect().bottom) pos = view.state.doc.content.size;
12631
+ else if (offset == 0 || !isElt(node) || node.childNodes[offset - 1].nodeName != "BR") pos = posFromCaret(view, node, offset, coords);
12624
12632
  }
12625
12633
  if (pos == null) pos = posFromElement(view, elt, coords);
12626
12634
  let desc = view.docView.nearestDesc(elt, true);
@@ -12644,7 +12652,7 @@ var BIDI = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
12644
12652
  function coordsAtPos(view, pos, side) {
12645
12653
  let { node, offset, atom } = view.docView.domFromPos(pos, side < 0 ? -1 : 1);
12646
12654
  let supportEmptyRange = webkit || gecko;
12647
- if (node.nodeType == 3) if (supportEmptyRange && (BIDI.test(node.nodeValue) || (side < 0 ? !offset : offset == node.nodeValue.length))) {
12655
+ if (isText(node)) if (supportEmptyRange && (BIDI.test(node.nodeValue) || (side < 0 ? !offset : offset == node.nodeValue.length))) {
12648
12656
  let rect = singleRect(textRange(node, offset, offset), side);
12649
12657
  if (gecko && offset && /\s/.test(node.nodeValue[offset - 1]) && offset < node.nodeValue.length) {
12650
12658
  let rectBefore = singleRect(textRange(node, offset - 1, offset - 1), -1);
@@ -12669,26 +12677,26 @@ function coordsAtPos(view, pos, side) {
12669
12677
  if (!view.state.doc.resolve(pos - (atom || 0)).parent.inlineContent) {
12670
12678
  if (atom == null && offset && (side < 0 || offset == nodeSize(node))) {
12671
12679
  let before = node.childNodes[offset - 1];
12672
- if (before.nodeType == 1) return flattenH(before.getBoundingClientRect(), false);
12680
+ if (isElt(before)) return flattenH(before.getBoundingClientRect(), false);
12673
12681
  }
12674
12682
  if (atom == null && offset < nodeSize(node)) {
12675
12683
  let after = node.childNodes[offset];
12676
- if (after.nodeType == 1) return flattenH(after.getBoundingClientRect(), true);
12684
+ if (isElt(after)) return flattenH(after.getBoundingClientRect(), true);
12677
12685
  }
12678
12686
  return flattenH(node.getBoundingClientRect(), side >= 0);
12679
12687
  }
12680
12688
  if (atom == null && offset && (side < 0 || offset == nodeSize(node))) {
12681
12689
  let before = node.childNodes[offset - 1];
12682
- let target = before.nodeType == 3 ? textRange(before, nodeSize(before) - (supportEmptyRange ? 0 : 1)) : before.nodeType == 1 && (before.nodeName != "BR" || !before.nextSibling) ? before : null;
12690
+ let target = isText(before) ? textRange(before, nodeSize(before) - (supportEmptyRange ? 0 : 1)) : isElt(before) && (before.nodeName != "BR" || !before.nextSibling) ? before : null;
12683
12691
  if (target) return flattenV(singleRect(target, 1), false);
12684
12692
  }
12685
12693
  if (atom == null && offset < nodeSize(node)) {
12686
12694
  let after = node.childNodes[offset];
12687
12695
  while (after.pmViewDesc && after.pmViewDesc.ignoreForCoords) after = after.nextSibling;
12688
- let target = !after ? null : after.nodeType == 3 ? textRange(after, 0, supportEmptyRange ? 0 : 1) : after.nodeType == 1 ? after : null;
12696
+ let target = !after ? null : isText(after) ? textRange(after, 0, supportEmptyRange ? 0 : 1) : isElt(after) ? after : null;
12689
12697
  if (target) return flattenV(singleRect(target, -1), true);
12690
12698
  }
12691
- return flattenV(singleRect(node.nodeType == 3 ? textRange(node) : node, -side), side >= 0);
12699
+ return flattenV(singleRect(isText(node) ? textRange(node) : node, -side), side >= 0);
12692
12700
  }
12693
12701
  function flattenV(rect, left) {
12694
12702
  if (rect.width == 0) return rect;
@@ -12738,8 +12746,8 @@ function endOfTextblockVertical(view, state, dir) {
12738
12746
  let coords = coordsAtPos(view, $pos.pos, 1);
12739
12747
  for (let child = dom.firstChild; child; child = child.nextSibling) {
12740
12748
  let boxes;
12741
- if (child.nodeType == 1) boxes = child.getClientRects();
12742
- else if (child.nodeType == 3) boxes = textRange(child, 0, child.nodeValue.length).getClientRects();
12749
+ if (isElt(child)) boxes = child.getClientRects();
12750
+ else if (isText(child)) boxes = textRange(child, 0, child.nodeValue.length).getClientRects();
12743
12751
  else continue;
12744
12752
  for (let i = 0; i < boxes.length; i++) {
12745
12753
  let box = boxes[i];
@@ -12763,7 +12771,7 @@ function endOfTextblockHorizontal(view, state, dir) {
12763
12771
  sel.modify("move", dir, "character");
12764
12772
  let parentDOM = $head.depth ? view.docView.domAfterPos($head.before()) : view.dom;
12765
12773
  let { focusNode: newNode, focusOffset: newOff } = view.domSelectionRange();
12766
- let result = newNode && !parentDOM.contains(newNode.nodeType == 1 ? newNode : newNode.parentNode) || oldNode == newNode && oldOff == newOff;
12774
+ let result = newNode && !contains(parentDOM, newNode) || oldNode == newNode && oldOff == newOff;
12767
12775
  try {
12768
12776
  sel.collapse(anchorNode, anchorOffset);
12769
12777
  if (oldNode && (oldNode != anchorNode || oldOff != anchorOffset) && sel.extend) sel.extend(oldNode, oldOff);
@@ -12845,7 +12853,7 @@ var ViewDesc = class {
12845
12853
  return this.posAtStart + this.size - 2 * this.border;
12846
12854
  }
12847
12855
  localPosFromDOM(dom, offset, bias) {
12848
- if (this.contentDOM && this.contentDOM.contains(dom.nodeType == 1 ? dom : dom.parentNode)) if (bias < 0) {
12856
+ if (this.contentDOM && contains(this.contentDOM, dom)) if (bias < 0) {
12849
12857
  let domBefore, desc;
12850
12858
  if (dom == this.contentDOM) domBefore = dom.childNodes[offset - 1];
12851
12859
  else {
@@ -12866,7 +12874,7 @@ var ViewDesc = class {
12866
12874
  }
12867
12875
  let atEnd;
12868
12876
  if (dom == this.dom && this.contentDOM) atEnd = offset > domIndex(this.contentDOM);
12869
- else if (this.contentDOM && this.contentDOM != this.dom && this.dom.contains(this.contentDOM)) atEnd = dom.compareDocumentPosition(this.contentDOM) & 2;
12877
+ else if (this.contentDOM && this.contentDOM != this.dom && this.dom.contains(this.contentDOM)) atEnd = !!(dom.compareDocumentPosition(this.contentDOM) & 4);
12870
12878
  else if (this.dom.firstChild) {
12871
12879
  if (offset == 0) for (let search = dom;; search = search.parentNode) {
12872
12880
  if (search == this.dom) {
@@ -12888,7 +12896,7 @@ var ViewDesc = class {
12888
12896
  nearestDesc(dom, onlyNodes = false) {
12889
12897
  for (let first = true, cur = dom; cur; cur = cur.parentNode) {
12890
12898
  let desc = this.getDesc(cur), nodeDOM;
12891
- if (desc && (!onlyNodes || desc.node)) if (first && (nodeDOM = desc.nodeDOM) && !(nodeDOM.nodeType == 1 ? nodeDOM.contains(dom.nodeType == 1 ? dom : dom.parentNode) : nodeDOM == dom)) first = false;
12899
+ if (desc && (!onlyNodes || desc.node)) if (first && (nodeDOM = desc.nodeDOM) && !(isElt(nodeDOM) ? contains(nodeDOM, dom) : nodeDOM == dom)) first = false;
12892
12900
  else return desc;
12893
12901
  }
12894
12902
  }
@@ -12929,14 +12937,17 @@ var ViewDesc = class {
12929
12937
  let i = 0, offset = 0;
12930
12938
  for (let curPos = 0; i < this.children.length; i++) {
12931
12939
  let child = this.children[i], end = curPos + child.size;
12932
- if (end > pos || child instanceof TrailingHackViewDesc) {
12940
+ if (end > pos) {
12933
12941
  offset = pos - curPos;
12934
12942
  break;
12935
12943
  }
12936
12944
  curPos = end;
12937
12945
  }
12938
12946
  if (offset) return this.children[i].domFromPos(offset - this.children[i].border, side);
12939
- for (let prev; i && !(prev = this.children[i - 1]).size && prev instanceof WidgetViewDesc && prev.side >= 0; i--);
12947
+ for (; i > 0; i--) {
12948
+ let prev = this.children[i - 1];
12949
+ if (prev.size || !(prev instanceof BufferHackViewDesc || prev instanceof WidgetViewDesc && prev.side >= 0)) break;
12950
+ }
12940
12951
  if (side <= 0) {
12941
12952
  let prev, enter = true;
12942
12953
  for (;; i--, enter = false) {
@@ -13016,7 +13027,7 @@ var ViewDesc = class {
13016
13027
  }
13017
13028
  domAfterPos(pos) {
13018
13029
  let { node, offset } = this.domFromPos(pos, 0);
13019
- if (node.nodeType != 1 || offset == node.childNodes.length) throw new RangeError("No node after pos " + pos);
13030
+ if (!isElt(node) || offset == node.childNodes.length) throw new RangeError("No node after pos " + pos);
13020
13031
  return node.childNodes[offset];
13021
13032
  }
13022
13033
  setSelection(anchor, head, view, force = false) {
@@ -13033,7 +13044,7 @@ var ViewDesc = class {
13033
13044
  let brKludge = false;
13034
13045
  if ((gecko || safari) && anchor == head) {
13035
13046
  let { node, offset } = anchorDOM;
13036
- if (node.nodeType == 3) {
13047
+ if (isText(node)) {
13037
13048
  brKludge = !!(offset && node.nodeValue[offset - 1] == "\n");
13038
13049
  if (brKludge && offset == node.nodeValue.length) for (let scan = node, after; scan; scan = scan.parentNode) {
13039
13050
  if (after = scan.nextSibling) {
@@ -13051,7 +13062,7 @@ var ViewDesc = class {
13051
13062
  brKludge = prev && (prev.nodeName == "BR" || prev.contentEditable == "false");
13052
13063
  }
13053
13064
  }
13054
- if (gecko && selRange.focusNode && selRange.focusNode != headDOM.node && selRange.focusNode.nodeType == 1) {
13065
+ if (gecko && selRange.focusNode && selRange.focusNode != headDOM.node && isElt(selRange.focusNode)) {
13055
13066
  let after = selRange.focusNode.childNodes[selRange.focusOffset];
13056
13067
  if (after && after.contentEditable == "false") force = true;
13057
13068
  }
@@ -13127,13 +13138,10 @@ var WidgetViewDesc = class extends ViewDesc {
13127
13138
  if (self.parent) return self.parent.posBeforeChild(self);
13128
13139
  });
13129
13140
  if (!widget.type.spec.raw) {
13130
- if (dom.nodeType != 1) {
13131
- let wrap = document.createElement("span");
13132
- wrap.appendChild(dom);
13133
- dom = wrap;
13134
- }
13135
- if (!dom.hasAttribute("contenteditable")) dom.contentEditable = "false";
13136
- dom.classList.add("ProseMirror-widget");
13141
+ let elt = isElt(dom) ? dom : document.createElement("span");
13142
+ if (elt != dom) elt.appendChild(dom);
13143
+ if (!elt.hasAttribute("contenteditable")) elt.contentEditable = "false";
13144
+ elt.classList.add("ProseMirror-widget");
13137
13145
  }
13138
13146
  super(parent, [], dom, null);
13139
13147
  this.widget = widget;
@@ -13256,7 +13264,7 @@ var NodeViewDesc = class NodeViewDesc extends ViewDesc {
13256
13264
  let dom = spec && spec.dom, contentDOM = spec && spec.contentDOM;
13257
13265
  if (node.isText) {
13258
13266
  if (!dom) dom = document.createTextNode(node.text);
13259
- else if (dom.nodeType != 3) throw new RangeError("Text must be rendered as a DOM text node");
13267
+ else if (!isText(dom)) throw new RangeError("Text must be rendered as a DOM text node");
13260
13268
  } else if (!dom) {
13261
13269
  let spec = DOMSerializer.renderSpec(document, node.type.spec.toDOM(node), null, node.attrs);
13262
13270
  ({dom, contentDOM} = spec);
@@ -13289,7 +13297,7 @@ var NodeViewDesc = class NodeViewDesc extends ViewDesc {
13289
13297
  }
13290
13298
  }
13291
13299
  if (!rule.contentElement) {
13292
- let found = addedNodes && addedNodes.find((n) => n.nodeType == 1 && addedNodes.indexOf(n.parentNode) < 0 && this.dom.contains(n));
13300
+ let found = addedNodes && addedNodes.find((n) => isElt(n) && addedNodes.indexOf(n.parentNode) < 0 && this.dom.contains(n));
13293
13301
  if (found) rule.contentElement = found;
13294
13302
  else rule.getContent = () => Fragment.empty;
13295
13303
  }
@@ -13311,18 +13319,21 @@ var NodeViewDesc = class NodeViewDesc extends ViewDesc {
13311
13319
  let localComposition = composition && composition.pos > -1 ? composition : null;
13312
13320
  let compositionInChild = composition && composition.pos < 0;
13313
13321
  let updater = new ViewTreeUpdater(this, localComposition && localComposition.node, view);
13322
+ let addBuffers = this.node.inlineContent, atBufferPos = addBuffers && this.node.isBlock;
13314
13323
  iterDeco(this.node, this.innerDeco, (widget, i, insideNode) => {
13315
13324
  if (widget.spec.marks) updater.syncToMarks(widget.spec.marks, inline, view, i);
13316
13325
  else if (widget.type.side >= 0 && !insideNode) updater.syncToMarks(i == this.node.childCount ? Mark$1.none : this.node.child(i).marks, inline, view, i);
13317
13326
  updater.placeWidget(widget, view, off);
13318
13327
  }, (child, outerDeco, innerDeco, i) => {
13319
13328
  updater.syncToMarks(child.marks, inline, view, i);
13329
+ if (atBufferPos && child.isAtom && !child.isText) updater.addHackNode("IMG", updater.top);
13320
13330
  let compIndex;
13321
13331
  if (updater.findNodeMatch(child, outerDeco, innerDeco, i));
13322
13332
  else if (compositionInChild && view.state.selection.from > off && view.state.selection.to < off + child.nodeSize && (compIndex = updater.findIndexWithChild(composition.node)) > -1 && updater.updateNodeAt(child, outerDeco, innerDeco, compIndex, view));
13323
13333
  else if (updater.updateNextNode(child, outerDeco, innerDeco, view, i, off));
13324
13334
  else updater.addNode(child, outerDeco, innerDeco, view, off);
13325
13335
  off += child.nodeSize;
13336
+ if (addBuffers) atBufferPos = child.isAtom && !child.isText;
13326
13337
  });
13327
13338
  updater.syncToMarks([], inline, view, 0);
13328
13339
  if (this.node.isTextblock) updater.addTextblockHacks();
@@ -13379,7 +13390,7 @@ var NodeViewDesc = class NodeViewDesc extends ViewDesc {
13379
13390
  }
13380
13391
  updateOuterDeco(outerDeco) {
13381
13392
  if (sameOuterDeco(outerDeco, this.outerDeco)) return;
13382
- let needsWrap = this.nodeDOM.nodeType != 1;
13393
+ let needsWrap = !isElt(this.nodeDOM);
13383
13394
  let oldDOM = this.dom;
13384
13395
  this.dom = patchOuterDeco(this.dom, this.nodeDOM, computeOuterDeco(this.outerDeco, this.node, needsWrap), computeOuterDeco(outerDeco, this.node, needsWrap));
13385
13396
  if (this.dom != oldDOM) {
@@ -13389,13 +13400,13 @@ var NodeViewDesc = class NodeViewDesc extends ViewDesc {
13389
13400
  this.outerDeco = outerDeco;
13390
13401
  }
13391
13402
  selectNode() {
13392
- if (this.nodeDOM.nodeType == 1) {
13403
+ if (isElt(this.nodeDOM)) {
13393
13404
  this.nodeDOM.classList.add("ProseMirror-selectednode");
13394
13405
  if (this.contentDOM || !this.node.type.spec.draggable) this.nodeDOM.draggable = true;
13395
13406
  }
13396
13407
  }
13397
13408
  deselectNode() {
13398
- if (this.nodeDOM.nodeType == 1) {
13409
+ if (isElt(this.nodeDOM)) {
13399
13410
  this.nodeDOM.classList.remove("ProseMirror-selectednode");
13400
13411
  if (this.contentDOM || !this.node.type.spec.draggable) this.nodeDOM.removeAttribute("draggable");
13401
13412
  }
@@ -13463,7 +13474,7 @@ var TextViewDesc = class TextViewDesc extends NodeViewDesc {
13463
13474
  return this.node.text == text;
13464
13475
  }
13465
13476
  };
13466
- var TrailingHackViewDesc = class extends ViewDesc {
13477
+ var BufferHackViewDesc = class extends ViewDesc {
13467
13478
  parseRule() {
13468
13479
  return { ignore: true };
13469
13480
  }
@@ -13599,7 +13610,7 @@ function patchAttributes(dom, prev, cur) {
13599
13610
  }
13600
13611
  }
13601
13612
  function applyOuterDeco(dom, deco, node) {
13602
- return patchOuterDeco(dom, dom, noDeco, computeOuterDeco(deco, node, dom.nodeType != 1));
13613
+ return patchOuterDeco(dom, dom, noDeco, computeOuterDeco(deco, node, !isElt(dom)));
13603
13614
  }
13604
13615
  function sameOuterDeco(a, b) {
13605
13616
  if (a.length != b.length) return false;
@@ -13789,14 +13800,14 @@ var ViewTreeUpdater = class {
13789
13800
  dom.alt = "";
13790
13801
  }
13791
13802
  if (nodeName == "BR") dom.className = "ProseMirror-trailingBreak";
13792
- let hack = new TrailingHackViewDesc(this.top, [], dom, null);
13803
+ let hack = new BufferHackViewDesc(this.top, [], dom, null);
13793
13804
  if (parent != this.top) parent.children.push(hack);
13794
13805
  else parent.children.splice(this.index++, 0, hack);
13795
13806
  this.changed = true;
13796
13807
  }
13797
13808
  }
13798
13809
  isLocked(node) {
13799
- return this.lock && (node == this.lock || node.nodeType == 1 && node.contains(this.lock.parentNode));
13810
+ return this.lock && (node == this.lock || isElt(node) && node.contains(this.lock.parentNode));
13800
13811
  }
13801
13812
  };
13802
13813
  function preMatch(frag, parentDesc) {
@@ -13940,10 +13951,15 @@ function selectionFromDOM(view, origin = null) {
13940
13951
  if (selectionCollapsed(domSel)) {
13941
13952
  anchor = head;
13942
13953
  while (nearestDesc && !nearestDesc.node) nearestDesc = nearestDesc.parent;
13943
- let nearestDescNode = nearestDesc.node;
13944
- if (nearestDesc && nearestDescNode.isAtom && NodeSelection.isSelectable(nearestDescNode) && nearestDesc.parent && !(nearestDescNode.isInline && isOnEdge(domSel.focusNode, domSel.focusOffset, nearestDesc.dom))) {
13954
+ if (nearestDesc && nearestDesc.node.isAtom && NodeSelection.isSelectable(nearestDesc.node) && nearestDesc.parent && !(nearestDesc.node.isInline && isOnEdge(domSel.focusNode, domSel.focusOffset, nearestDesc.dom))) {
13945
13955
  let pos = nearestDesc.posBefore;
13946
13956
  selection = new NodeSelection(head == pos ? $head : doc.resolve(pos));
13957
+ } else if (gecko && origin == "key" && head > view.state.selection.to && isElt(domSel.focusNode) && domSel.focusOffset == domSel.focusNode.childNodes.length && nearestDesc && nearestDesc.posAtStart > view.state.selection.to) for (let scan = domSel.focusNode;; scan = scan.parentNode) {
13958
+ if (getComputedStyle(scan).overflow != "visible") {
13959
+ selection = Selection$1.findFrom(doc.resolve(nearestDesc.posAtStart), 1);
13960
+ break;
13961
+ }
13962
+ if (scan == nearestDesc.dom || scan.nextSibling || !scan.parentNode || !isElt(scan.parentNode)) break;
13947
13963
  }
13948
13964
  } else {
13949
13965
  if (domSel instanceof view.dom.ownerDocument.defaultView.Selection && domSel.rangeCount > 1) {
@@ -14081,7 +14097,7 @@ function hasSelection(view) {
14081
14097
  let sel = view.domSelectionRange();
14082
14098
  if (!sel.anchorNode) return false;
14083
14099
  try {
14084
- return view.dom.contains(sel.anchorNode.nodeType == 3 ? sel.anchorNode.parentNode : sel.anchorNode) && (view.editable || view.dom.contains(sel.focusNode.nodeType == 3 ? sel.focusNode.parentNode : sel.focusNode));
14100
+ return contains(view.dom, sel.anchorNode) && (view.editable || contains(view.dom, sel.focusNode));
14085
14101
  } catch (_) {
14086
14102
  return false;
14087
14103
  }
@@ -14120,8 +14136,7 @@ function selectHorizontally(view, dir, mods) {
14120
14136
  let nodePos = dir < 0 ? $head.pos - node.nodeSize : $head.pos;
14121
14137
  if (!(node.isAtom || (desc = view.docView.descAt(nodePos)) && !desc.contentDOM)) return false;
14122
14138
  if (NodeSelection.isSelectable(node)) return apply(view, new NodeSelection(dir < 0 ? view.state.doc.resolve($head.pos - node.nodeSize) : $head));
14123
- else if (webkit) return apply(view, new TextSelection(view.state.doc.resolve(dir < 0 ? nodePos : nodePos + node.nodeSize)));
14124
- else return false;
14139
+ else return apply(view, new TextSelection(view.state.doc.resolve(dir < 0 ? nodePos : nodePos + node.nodeSize)));
14125
14140
  }
14126
14141
  } else if (sel instanceof NodeSelection && sel.node.isInline) return apply(view, new TextSelection(dir > 0 ? sel.$to : sel.$from));
14127
14142
  else {
@@ -14130,12 +14145,9 @@ function selectHorizontally(view, dir, mods) {
14130
14145
  return false;
14131
14146
  }
14132
14147
  }
14133
- function nodeLen(node) {
14134
- return node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length;
14135
- }
14136
14148
  function isIgnorable(dom, dir) {
14137
14149
  let desc = dom.pmViewDesc;
14138
- return desc && desc.size == 0 && (dir < 0 || dom.nextSibling || dom.nodeName != "BR");
14150
+ return desc ? desc.size == 0 && (dir < 0 || dom.nextSibling || dom.nodeName != "BR") : isElt(dom) && dom.contentEditable == "false";
14139
14151
  }
14140
14152
  function skipIgnoredNodes(view, dir) {
14141
14153
  return dir < 0 ? skipIgnoredNodesBefore(view) : skipIgnoredNodesAfter(view);
@@ -14145,19 +14157,18 @@ function skipIgnoredNodesBefore(view) {
14145
14157
  let node = sel.focusNode, offset = sel.focusOffset;
14146
14158
  if (!node) return;
14147
14159
  let moveNode, moveOffset, force = false;
14148
- if (gecko && node.nodeType == 1 && offset < nodeLen(node) && isIgnorable(node.childNodes[offset], -1)) force = true;
14149
- for (;;) if (offset > 0) if (node.nodeType != 1) break;
14150
- else {
14160
+ if (gecko && isElt(node) && offset < nodeSize(node) && isIgnorable(node.childNodes[offset], -1)) force = true;
14161
+ for (;;) if (offset > 0) {
14162
+ if (!isElt(node)) break;
14151
14163
  let before = node.childNodes[offset - 1];
14152
14164
  if (isIgnorable(before, -1)) {
14153
14165
  moveNode = node;
14154
14166
  moveOffset = --offset;
14155
- } else if (before.nodeType == 3) {
14167
+ } else if (isText(before)) {
14156
14168
  node = before;
14157
14169
  offset = node.nodeValue.length;
14158
14170
  } else break;
14159
- }
14160
- else if (isBlockNode(node)) break;
14171
+ } else if (isBlockNode(node)) break;
14161
14172
  else {
14162
14173
  let prev = node.previousSibling;
14163
14174
  while (prev && isIgnorable(prev, -1)) {
@@ -14171,7 +14182,7 @@ function skipIgnoredNodesBefore(view) {
14171
14182
  offset = 0;
14172
14183
  } else {
14173
14184
  node = prev;
14174
- offset = nodeLen(node);
14185
+ offset = nodeSize(node);
14175
14186
  }
14176
14187
  }
14177
14188
  if (force) setSelFocus(view, node, offset);
@@ -14181,10 +14192,10 @@ function skipIgnoredNodesAfter(view) {
14181
14192
  let sel = view.domSelectionRange();
14182
14193
  let node = sel.focusNode, offset = sel.focusOffset;
14183
14194
  if (!node) return;
14184
- let len = nodeLen(node);
14195
+ let len = nodeSize(node);
14185
14196
  let moveNode, moveOffset;
14186
14197
  for (;;) if (offset < len) {
14187
- if (node.nodeType != 1) break;
14198
+ if (!isElt(node)) break;
14188
14199
  let after = node.childNodes[offset];
14189
14200
  if (isIgnorable(after, 1)) {
14190
14201
  moveNode = node;
@@ -14205,7 +14216,7 @@ function skipIgnoredNodesAfter(view) {
14205
14216
  } else {
14206
14217
  node = next;
14207
14218
  offset = 0;
14208
- len = nodeLen(node);
14219
+ len = nodeSize(node);
14209
14220
  }
14210
14221
  }
14211
14222
  if (moveNode) setSelFocus(view, moveNode, moveOffset);
@@ -14221,8 +14232,8 @@ function textNodeAfter(node, offset) {
14221
14232
  }
14222
14233
  while (node && offset < node.childNodes.length) {
14223
14234
  let next = node.childNodes[offset];
14224
- if (next.nodeType == 3) return next;
14225
- if (next.nodeType == 1 && next.contentEditable == "false") break;
14235
+ if (isText(next)) return next;
14236
+ if (isElt(next) && next.contentEditable == "false") break;
14226
14237
  node = next;
14227
14238
  offset = 0;
14228
14239
  }
@@ -14234,14 +14245,14 @@ function textNodeBefore(node, offset) {
14234
14245
  }
14235
14246
  while (node && offset) {
14236
14247
  let next = node.childNodes[offset - 1];
14237
- if (next.nodeType == 3) return next;
14238
- if (next.nodeType == 1 && next.contentEditable == "false") break;
14248
+ if (isText(next)) return next;
14249
+ if (isElt(next) && next.contentEditable == "false") break;
14239
14250
  node = next;
14240
14251
  offset = node.childNodes.length;
14241
14252
  }
14242
14253
  }
14243
14254
  function setSelFocus(view, node, offset) {
14244
- if (node.nodeType != 3) {
14255
+ if (!isText(node)) {
14245
14256
  let before, after;
14246
14257
  if (after = textNodeAfter(node, offset)) {
14247
14258
  node = after;
@@ -14323,7 +14334,7 @@ function switchEditable(view, node, state) {
14323
14334
  function safariDownArrowBug(view) {
14324
14335
  if (!safari || view.state.selection.$head.parentOffset > 0) return false;
14325
14336
  let { focusNode, focusOffset } = view.domSelectionRange();
14326
- if (focusNode && focusNode.nodeType == 1 && focusOffset == 0 && focusNode.firstChild && focusNode.firstChild.contentEditable == "false") {
14337
+ if (focusNode && isElt(focusNode) && focusOffset == 0 && focusNode.firstChild && isElt(focusNode.firstChild) && focusNode.firstChild.contentEditable == "false") {
14327
14338
  let child = focusNode.firstChild;
14328
14339
  switchEditable(view, child, "true");
14329
14340
  setTimeout(() => switchEditable(view, child, "false"), 20);
@@ -14370,7 +14381,7 @@ function serializeForClipboard(view, slice) {
14370
14381
  let doc = detachedDoc(), wrap = doc.createElement("div");
14371
14382
  wrap.appendChild(serializer.serializeFragment(content, { document: doc }));
14372
14383
  let firstChild = wrap.firstChild, needsWrap, wrappers = 0;
14373
- while (firstChild && firstChild.nodeType == 1 && (needsWrap = wrapMap[firstChild.nodeName.toLowerCase()])) {
14384
+ while (firstChild && isElt(firstChild) && (needsWrap = wrapMap[firstChild.nodeName.toLowerCase()])) {
14374
14385
  for (let i = needsWrap.length - 1; i >= 0; i--) {
14375
14386
  let wrapper = doc.createElement(needsWrap[i]);
14376
14387
  while (wrap.firstChild) wrapper.appendChild(wrap.firstChild);
@@ -14379,7 +14390,7 @@ function serializeForClipboard(view, slice) {
14379
14390
  }
14380
14391
  firstChild = wrap.firstChild;
14381
14392
  }
14382
- if (firstChild && firstChild.nodeType == 1) firstChild.setAttribute("data-pm-slice", `${openStart} ${openEnd}${wrappers ? ` -${wrappers}` : ""} ${JSON.stringify(context)}`);
14393
+ if (firstChild && isElt(firstChild)) firstChild.setAttribute("data-pm-slice", `${openStart} ${openEnd}${wrappers ? ` -${wrappers}` : ""} ${JSON.stringify(context)}`);
14383
14394
  return {
14384
14395
  dom: wrap,
14385
14396
  text: view.someProp("clipboardTextSerializer", (f) => f(slice, view)) || slice.content.textBetween(0, slice.content.size, "\n\n"),
@@ -14424,7 +14435,7 @@ function parseFromClipboard(view, text, html, plainText, $context) {
14424
14435
  let sliceData = contextNode && /^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(contextNode.getAttribute("data-pm-slice") || "");
14425
14436
  if (sliceData && sliceData[3]) for (let i = +sliceData[3]; i > 0; i--) {
14426
14437
  let child = dom.firstChild;
14427
- while (child && child.nodeType != 1) child = child.nextSibling;
14438
+ while (child && !isElt(child)) child = child.nextSibling;
14428
14439
  if (!child) break;
14429
14440
  dom = child;
14430
14441
  }
@@ -14577,11 +14588,10 @@ function addContext(slice, context) {
14577
14588
  let type = schema.nodes[array[i]];
14578
14589
  if (!type || type.hasRequiredAttrs()) break;
14579
14590
  try {
14580
- type.checkAttrs(array[i + 1]);
14591
+ content = Fragment.from(type.create(array[i + 1], content));
14581
14592
  } catch (e) {
14582
14593
  break;
14583
14594
  }
14584
- content = Fragment.from(type.create(array[i + 1], content));
14585
14595
  openStart++;
14586
14596
  openEnd++;
14587
14597
  }
@@ -14725,14 +14735,14 @@ function updateSelection(view, selection, origin) {
14725
14735
  if (!view.focused) view.focus();
14726
14736
  if (view.state.selection.eq(selection)) return;
14727
14737
  let tr = view.state.tr.setSelection(selection);
14728
- if (origin == "pointer") tr.setMeta("pointer", true);
14738
+ tr.setMeta("pointer", true);
14729
14739
  view.dispatch(tr);
14730
14740
  }
14731
14741
  function selectClickedLeaf(view, inside) {
14732
14742
  if (inside == -1) return false;
14733
14743
  let $pos = view.state.doc.resolve(inside), node = $pos.nodeAfter;
14734
14744
  if (node && node.isAtom && NodeSelection.isSelectable(node)) {
14735
- updateSelection(view, new NodeSelection($pos), "pointer");
14745
+ updateSelection(view, new NodeSelection($pos));
14736
14746
  return true;
14737
14747
  }
14738
14748
  return false;
@@ -14751,7 +14761,7 @@ function selectClickedNode(view, inside) {
14751
14761
  }
14752
14762
  }
14753
14763
  if (selectAt != null) {
14754
- updateSelection(view, NodeSelection.create(view.state.doc, selectAt), "pointer");
14764
+ updateSelection(view, NodeSelection.create(view.state.doc, selectAt));
14755
14765
  return true;
14756
14766
  } else return false;
14757
14767
  }
@@ -14768,7 +14778,7 @@ function defaultTripleClick(view, inside, event) {
14768
14778
  if (event.button != 0) return false;
14769
14779
  let selection = selectionForTripleClick(view, inside, true), doc = view.state.doc;
14770
14780
  if (!selection) return false;
14771
- updateSelection(view, selection, "pointer");
14781
+ updateSelection(view, selection);
14772
14782
  if (selection instanceof TextSelection && doc.eq(view.state.doc)) view.input.mouseDown = new TripleClickDrag(view, selection);
14773
14783
  return true;
14774
14784
  }
@@ -14854,7 +14864,7 @@ var LeftMouseDown = class extends MouseDown {
14854
14864
  }
14855
14865
  const target = flushed ? null : event.target;
14856
14866
  const targetDesc = target ? view.docView.nearestDesc(target, true) : null;
14857
- this.target = targetDesc && targetDesc.nodeDOM.nodeType == 1 ? targetDesc.nodeDOM : null;
14867
+ this.target = targetDesc && isElt(targetDesc.nodeDOM) ? targetDesc.nodeDOM : null;
14858
14868
  let { selection } = view.state;
14859
14869
  if (event.button == 0 && (targetNode.type.spec.draggable && targetNode.type.spec.selectable !== false || selection instanceof NodeSelection && selection.from <= targetPos && selection.to > targetPos)) this.mightDrag = {
14860
14870
  node: targetNode,
@@ -14893,7 +14903,7 @@ var LeftMouseDown = class extends MouseDown {
14893
14903
  if (this.allowDefault || !pos) setSelectionOrigin(this.view, "pointer");
14894
14904
  else if (handleSingleClick(this.view, pos.pos, pos.inside, event, this.selectNode)) event.preventDefault();
14895
14905
  else if (event.button == 0 && (this.flushed || safari && this.mightDrag && !this.mightDrag.node.isAtom || chrome && !this.view.state.selection.visible && Math.min(Math.abs(pos.pos - this.view.state.selection.from), Math.abs(pos.pos - this.view.state.selection.to)) <= 2)) {
14896
- updateSelection(this.view, Selection$1.near(this.view.state.doc.resolve(pos.pos)), "pointer");
14906
+ updateSelection(this.view, Selection$1.near(this.view.state.doc.resolve(pos.pos)));
14897
14907
  event.preventDefault();
14898
14908
  } else setSelectionOrigin(this.view, "pointer");
14899
14909
  }
@@ -14929,7 +14939,7 @@ var TripleClickDrag = class extends MouseDown {
14929
14939
  if (!target) return;
14930
14940
  let { doc } = this.view.state, start = this.startSelection;
14931
14941
  let [anchor, head] = target.from < start.from ? [start.to, target.from] : [start.from, target.to];
14932
- updateSelection(this.view, TextSelection.create(doc, anchor, head), "pointer");
14942
+ updateSelection(this.view, TextSelection.create(doc, anchor, head));
14933
14943
  }
14934
14944
  };
14935
14945
  handlers.touchstart = (view) => {
@@ -14955,7 +14965,7 @@ editHandlers.compositionstart = editHandlers.compositionupdate = (view) => {
14955
14965
  if (!view.composing) {
14956
14966
  view.domObserver.flush();
14957
14967
  let { state } = view, $pos = state.selection.$to;
14958
- if (state.selection instanceof TextSelection && (state.storedMarks || !$pos.textOffset && $pos.parentOffset && $pos.nodeBefore.marks.some((m) => m.type.spec.inclusive === false) || chrome && windows$1 && selectionBeforeUneditable(view))) {
14968
+ if (state.selection instanceof TextSelection && state.selection.empty && (state.storedMarks || !$pos.textOffset && $pos.parentOffset && $pos.nodeBefore.marks.some((m) => m.type.spec.inclusive === false) || chrome && windows$1 && selectionBeforeUneditable(view))) {
14959
14969
  view.markCursor = view.state.storedMarks || $pos.marks();
14960
14970
  endComposition(view, true);
14961
14971
  view.markCursor = null;
@@ -14963,10 +14973,10 @@ editHandlers.compositionstart = editHandlers.compositionupdate = (view) => {
14963
14973
  endComposition(view, !state.selection.empty);
14964
14974
  if (gecko && state.selection.empty && $pos.parentOffset && !$pos.textOffset && $pos.nodeBefore.marks.length) {
14965
14975
  let sel = view.domSelectionRange();
14966
- for (let node = sel.focusNode, offset = sel.focusOffset; node && node.nodeType == 1 && offset != 0;) {
14976
+ for (let node = sel.focusNode, offset = sel.focusOffset; node && isElt(node) && offset != 0;) {
14967
14977
  let before = offset < 0 ? node.lastChild : node.childNodes[offset - 1];
14968
14978
  if (!before) break;
14969
- if (before.nodeType == 3) {
14979
+ if (isText(before)) {
14970
14980
  let sel = view.domSelection();
14971
14981
  if (sel) sel.collapse(before, before.nodeValue.length);
14972
14982
  break;
@@ -14983,9 +14993,9 @@ editHandlers.compositionstart = editHandlers.compositionupdate = (view) => {
14983
14993
  };
14984
14994
  function selectionBeforeUneditable(view) {
14985
14995
  let { focusNode, focusOffset } = view.domSelectionRange();
14986
- if (!focusNode || focusNode.nodeType != 1 || focusOffset >= focusNode.childNodes.length) return false;
14996
+ if (!focusNode || !isElt(focusNode) || focusOffset >= focusNode.childNodes.length) return false;
14987
14997
  let next = focusNode.childNodes[focusOffset];
14988
- return next.nodeType == 1 && next.contentEditable == "false";
14998
+ return isElt(next) && next.contentEditable == "false";
14989
14999
  }
14990
15000
  editHandlers.compositionend = (view, event) => {
14991
15001
  if (view.composing) {
@@ -15138,7 +15148,7 @@ handlers.dragstart = (view, _event) => {
15138
15148
  let node;
15139
15149
  if (pos && pos.pos >= sel.from && pos.pos <= (sel instanceof NodeSelection ? sel.to - 1 : sel.to));
15140
15150
  else if (mouseDown && mouseDown.mightDrag) node = NodeSelection.create(view.state.doc, mouseDown.mightDrag.pos);
15141
- else if (event.target && event.target.nodeType == 1) {
15151
+ else if (event.target && isElt(event.target)) {
15142
15152
  let desc = view.docView.nearestDesc(event.target, true);
15143
15153
  if (desc && desc.node.type.spec.draggable && desc != view.docView) node = NodeSelection.create(view.state.doc, desc.posBefore);
15144
15154
  }
@@ -15911,7 +15921,7 @@ var DOMObserver = class {
15911
15921
  let desc = container && this.view.docView.nearestDesc(container);
15912
15922
  if (desc && desc.ignoreMutation({
15913
15923
  type: "selection",
15914
- target: container.nodeType == 3 ? container.parentNode : container
15924
+ target: isText(container) ? container.parentNode : container
15915
15925
  })) {
15916
15926
  this.setCurSelection();
15917
15927
  return true;
@@ -15940,7 +15950,7 @@ var DOMObserver = class {
15940
15950
  if (added.some((n) => n.nodeName == "BR") && (view.input.lastKeyCode == 8 || view.input.lastKeyCode == 46 || chrome && (view.composing || view.input.compositionEndedAt > Date.now() - 50) && mutations.some((m) => m.type == "childList" && m.removedNodes.length))) {
15941
15951
  for (let node of added) if (node.nodeName == "BR" && node.parentNode) {
15942
15952
  let after = node.nextSibling;
15943
- while (after && after.nodeType == 1) {
15953
+ while (after && isElt(after)) {
15944
15954
  if (after.contentEditable == "false") {
15945
15955
  node.parentNode.removeChild(node);
15946
15956
  break;
@@ -15992,7 +16002,7 @@ var DOMObserver = class {
15992
16002
  for (let i = 0; i < mut.addedNodes.length; i++) {
15993
16003
  let node = mut.addedNodes[i];
15994
16004
  added.push(node);
15995
- if (node.nodeType == 3) this.lastChangedTextNode = node;
16005
+ if (isText(node)) this.lastChangedTextNode = node;
15996
16006
  }
15997
16007
  if (desc.contentDOM && desc.contentDOM != desc.dom && !desc.contentDOM.contains(mut.target)) return {
15998
16008
  from: desc.posBefore,
@@ -16091,7 +16101,7 @@ function fixUpBadSafariComposition(view, addedNodes) {
16091
16101
  let parent = nextCell;
16092
16102
  for (;;) {
16093
16103
  let first = parent.firstChild;
16094
- if (!first || first.nodeType != 1 || first.contentEditable == "false" || /^(BR|IMG)$/.test(first.nodeName)) break;
16104
+ if (!first || !isElt(first) || first.contentEditable == "false" || /^(BR|IMG)$/.test(first.nodeName)) break;
16095
16105
  parent = first;
16096
16106
  }
16097
16107
  parent.insertBefore(node, parent.firstChild);
@@ -16104,7 +16114,7 @@ function parseBetween(view, from_, to_, addedNodes) {
16104
16114
  let domSel = view.domSelectionRange();
16105
16115
  let find;
16106
16116
  let anchor = domSel.anchorNode;
16107
- if (anchor && view.dom.contains(anchor.nodeType == 1 ? anchor : anchor.parentNode)) {
16117
+ if (anchor && contains(view.dom, anchor)) {
16108
16118
  find = [{
16109
16119
  node: anchor,
16110
16120
  offset: domSel.anchorOffset
@@ -16198,7 +16208,7 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
16198
16208
  view.input.lastKeyCode = null;
16199
16209
  let change = findDiff(compare.content, parse.doc.content, parse.from, preferredPos, preferredSide);
16200
16210
  if (change) view.input.domChangeCount++;
16201
- if ((ios && view.input.lastIOSEnter > Date.now() - 225 || android) && addedNodes.some((n) => n.nodeType == 1 && !isInline.test(n.nodeName)) && (!change || change.endA >= change.endB) && view.someProp("handleKeyDown", (f) => f(view, keyEvent(13, "Enter")))) {
16211
+ if ((ios && view.input.lastIOSEnter > Date.now() - 225 || android) && addedNodes.some((n) => isElt(n) && !isInline.test(n.nodeName)) && (!change || change.endA >= change.endB) && view.someProp("handleKeyDown", (f) => f(view, keyEvent(13, "Enter")))) {
16202
16212
  view.input.lastIOSEnter = 0;
16203
16213
  return;
16204
16214
  }
@@ -16234,7 +16244,7 @@ function readDOMChange(view, from, to, typeOver, addedNodes) {
16234
16244
  let $to = parse.doc.resolveNoCache(change.endB - parse.from);
16235
16245
  let $fromA = doc.resolve(change.start);
16236
16246
  let inlineChange = $from.sameParent($to) && $from.parent.inlineContent && $fromA.end() >= change.endA;
16237
- if ((ios && view.input.lastIOSEnter > Date.now() - 225 && (!inlineChange || addedNodes.some((n) => n.nodeName == "DIV" || n.nodeName == "P")) || !inlineChange && $from.pos < parse.doc.content.size && (!$from.sameParent($to) || !$from.parent.inlineContent) && $from.pos < $to.pos && !/\S/.test(parse.doc.textBetween($from.pos, $to.pos, "", ""))) && view.someProp("handleKeyDown", (f) => f(view, keyEvent(13, "Enter")))) {
16247
+ if ((ios && view.input.lastIOSEnter > Date.now() - 225 && (!inlineChange || addedNodes.some((n) => n.nodeName == "DIV" || n.nodeName == "P")) || !inlineChange && looksLikeEnter(parse.doc, $from.pos, $to.pos)) && view.someProp("handleKeyDown", (f) => f(view, keyEvent(13, "Enter")))) {
16238
16248
  view.input.lastIOSEnter = 0;
16239
16249
  return;
16240
16250
  }
@@ -16321,6 +16331,14 @@ function looksLikeBackspace(old, start, end, $newStart, $newEnd) {
16321
16331
  if (!$next.parent.isTextblock || $next.pos > end || skipClosingAndOpening($next, true, false) < end) return false;
16322
16332
  return $newStart.parent.content.cut($newStart.parentOffset).eq($next.parent.content);
16323
16333
  }
16334
+ function looksLikeEnter(content, from, to) {
16335
+ let newTextlines = 0, newLeaves = 0;
16336
+ content.nodesBetween(from, to, (node, pos) => {
16337
+ if (node.isTextblock && pos >= from && pos < to) newTextlines++;
16338
+ else if (node.isText ? /\S/.test(node.text.slice(Math.max(0, from - pos), Math.min(node.nodeSize, to - pos))) : node.isLeaf) newLeaves++;
16339
+ });
16340
+ return newLeaves == 0 && newTextlines == 1;
16341
+ }
16324
16342
  function skipClosingAndOpening($pos, fromEnd, mayOpen) {
16325
16343
  let depth = $pos.depth, end = fromEnd ? $pos.end() : $pos.pos;
16326
16344
  while (depth > 0 && (fromEnd || $pos.indexAfter(depth) == $pos.node(depth).childCount)) {
@@ -16545,11 +16563,11 @@ var EditorView = class {
16545
16563
  */
16546
16564
  scrollToSelection() {
16547
16565
  let startDOM = this.domSelectionRange().focusNode;
16548
- if (!startDOM || !this.dom.contains(startDOM.nodeType == 1 ? startDOM : startDOM.parentNode));
16566
+ if (!startDOM || !contains(this.dom, startDOM));
16549
16567
  else if (this.someProp("handleScrollToSelection", (f) => f(this)));
16550
16568
  else if (this.state.selection instanceof NodeSelection) {
16551
16569
  let target = this.docView.domAfterPos(this.state.selection.from);
16552
- if (target.nodeType == 1) scrollRectIntoView(this, target.getBoundingClientRect(), startDOM);
16570
+ if (isElt(target)) scrollRectIntoView(this, target.getBoundingClientRect(), startDOM);
16553
16571
  } else scrollRectIntoView(this, this.coordsAtPos(this.state.selection.head, 1), startDOM);
16554
16572
  }
16555
16573
  destroyPluginViews() {
@@ -16778,7 +16796,7 @@ var EditorView = class {
16778
16796
  @internal
16779
16797
  */
16780
16798
  domSelectionRange() {
16781
- let sel = this.domSelection();
16799
+ let sel = this.dom.isConnected !== false && this.domSelection();
16782
16800
  if (!sel) return {
16783
16801
  focusNode: null,
16784
16802
  focusOffset: 0,
@@ -27356,7 +27374,7 @@ var Underline = Mark.create({
27356
27374
  }
27357
27375
  });
27358
27376
  //#endregion
27359
- //#region ../../../node_modules/.bun/prosemirror-dropcursor@1.8.2/node_modules/prosemirror-dropcursor/dist/index.js
27377
+ //#region ../../../node_modules/.bun/prosemirror-dropcursor@1.8.4/node_modules/prosemirror-dropcursor/dist/index.js
27360
27378
  /**
27361
27379
  Create a plugin that, when added to a ProseMirror instance,
27362
27380
  causes a decoration to show up at the drop position when something
@@ -27379,6 +27397,7 @@ var DropCursorView = class {
27379
27397
  this.cursorPos = null;
27380
27398
  this.element = null;
27381
27399
  this.timeout = -1;
27400
+ this.lastDragEvent = null;
27382
27401
  this.width = (_a = options.width) !== null && _a !== void 0 ? _a : 1;
27383
27402
  this.color = options.color === false ? void 0 : options.color || "black";
27384
27403
  this.class = options.class;
@@ -27399,11 +27418,15 @@ var DropCursorView = class {
27399
27418
  });
27400
27419
  }
27401
27420
  destroy() {
27421
+ this.setCursor(null);
27402
27422
  this.handlers.forEach(({ name, handler }) => this.editorView.dom.removeEventListener(name, handler));
27403
27423
  }
27404
27424
  update(editorView, prevState) {
27405
- if (this.cursorPos != null && prevState.doc != editorView.state.doc) if (this.cursorPos > editorView.state.doc.content.size) this.setCursor(null);
27406
- else this.updateOverlay();
27425
+ if (this.cursorPos != null && prevState.doc != editorView.state.doc) if (this.lastDragEvent) {
27426
+ let target = this.computeTarget(this.lastDragEvent);
27427
+ if (target == this.cursorPos) this.updateOverlay();
27428
+ else this.setCursor(target);
27429
+ } else this.updateOverlay();
27407
27430
  }
27408
27431
  setCursor(pos) {
27409
27432
  if (pos == this.cursorPos) return;
@@ -27474,8 +27497,7 @@ var DropCursorView = class {
27474
27497
  clearTimeout(this.timeout);
27475
27498
  this.timeout = setTimeout(() => this.setCursor(null), timeout);
27476
27499
  }
27477
- dragover(event) {
27478
- if (!this.editorView.editable) return;
27500
+ computeTarget(event) {
27479
27501
  let pos = this.editorView.posAtCoords({
27480
27502
  left: event.clientX,
27481
27503
  top: event.clientY
@@ -27483,12 +27505,19 @@ var DropCursorView = class {
27483
27505
  let node = pos && pos.inside >= 0 && this.editorView.state.doc.nodeAt(pos.inside);
27484
27506
  let disableDropCursor = node && node.type.spec.disableDropCursor;
27485
27507
  let disabled = typeof disableDropCursor == "function" ? disableDropCursor(this.editorView, pos, event) : disableDropCursor;
27486
- if (pos && !disabled) {
27487
- let target = pos.pos;
27488
- if (this.editorView.dragging && this.editorView.dragging.slice) {
27489
- let point = dropPoint(this.editorView.state.doc, target, this.editorView.dragging.slice);
27490
- if (point != null) target = point;
27491
- }
27508
+ if (!pos || disabled) return null;
27509
+ let target = pos.pos;
27510
+ if (this.editorView.dragging && this.editorView.dragging.slice) {
27511
+ let point = dropPoint(this.editorView.state.doc, target, this.editorView.dragging.slice);
27512
+ if (point != null) target = point;
27513
+ }
27514
+ return target;
27515
+ }
27516
+ dragover(event) {
27517
+ if (!this.editorView.editable) return;
27518
+ this.lastDragEvent = event;
27519
+ let target = this.computeTarget(event);
27520
+ if (target != null) {
27492
27521
  this.setCursor(target);
27493
27522
  this.scheduleRemoval(5e3);
27494
27523
  }
@@ -35081,131 +35110,212 @@ create_custom_element(RegionPicker, {
35081
35110
  }, [], [], { mode: "open" });
35082
35111
  //#endregion
35083
35112
  //#region ../../shared/math-rendering-mathjax/dist/index.js
35084
- var e = {
35113
+ var e = "https://github.com/pie-framework/pie-players/blob/develop/docs/item-player/loading-strategies.md#one-mathjax-version-per-page";
35114
+ var t = "pie-mathjax-version-conflict";
35115
+ var n = Symbol.for("@pie-element/shared-math-rendering-mathjax/unsupported-page");
35116
+ function r(r, i) {
35117
+ if (typeof window > "u") return;
35118
+ let a = globalThis;
35119
+ a[n] ?? (a[n] = {
35120
+ logged: !1,
35121
+ conditions: []
35122
+ });
35123
+ let o = a[n];
35124
+ if (o.conditions.includes(r)) return;
35125
+ o.conditions.push(r);
35126
+ let s = `[math-rendering] Unsupported page (${r}): ${i}. PIE supports one MathJax major version per page; with MathJax 3 and 4 on one page, math rendering is best effort and may break. See ${e}`;
35127
+ o.logged || (o.logged = !0, console.error(s)), window.dispatchEvent(new CustomEvent(t, { detail: {
35128
+ condition: r,
35129
+ message: s,
35130
+ docsUrl: e
35131
+ } }));
35132
+ }
35133
+ function i() {
35134
+ let e = window.MathJax?.version;
35135
+ return typeof e == "string" && e.startsWith("3.") ? e : void 0;
35136
+ }
35137
+ var a = "https://cdn.jsdelivr.net/npm/mathjax@4.1.3/tex-mml-chtml.js";
35138
+ var o = {
35085
35139
  parallelogram: "\\lower.2em{\\Huge\\unicode{x25B1}}",
35086
35140
  overarc: "\\overparen",
35087
35141
  napprox: "\\not\\approx",
35088
35142
  longdiv: "\\enclose{longdiv}",
35089
35143
  abs: ["\\left|#1\\right|", 1]
35090
35144
  };
35091
- var t = "[math-rendering] using $ is not advisable, please use $$..$$ or \\(...\\)";
35092
- var n = /\\\(|\\\[|\$\$|\\\$|\\begin\{|\\(?:eq)?ref\{/;
35093
- var r = /\\\(|\\\[|\$|\\begin\{|\\(?:eq)?ref\{/;
35094
- var i = /\\embed\{newLine\}\[\]/g;
35095
- var a = [
35145
+ var s = "[math-rendering] using $ is not advisable, please use $$..$$ or \\(...\\)";
35146
+ var c = /\\\(|\\\[|\$\$|\\\$|\\begin\{|\\(?:eq)?ref\{/;
35147
+ var l = /\\\(|\\\[|\$|\\begin\{|\\(?:eq)?ref\{/;
35148
+ var u = /\\embed\{newLine\}\[\]/g;
35149
+ var d = [
35096
35150
  ["$$", "$$"],
35097
35151
  ["$", "$"],
35098
35152
  ["\\[", "\\]"],
35099
35153
  ["\\(", "\\)"]
35100
35154
  ];
35101
- var o = Symbol.for("@pie-element/shared-math-rendering-mathjax/loading");
35102
- function s() {
35155
+ var f = Symbol.for("@pie-element/shared-math-rendering-mathjax/loading");
35156
+ var p = "PIE-MJX-CHTML-styles";
35157
+ var m = "MJX-CHTML-styles";
35158
+ var h = [m, "MJX-SVG-styles"];
35159
+ var g = 201;
35160
+ function _(e) {
35161
+ let t = [...e.matches("mjx-container") ? [e] : [], ...e.querySelectorAll("mjx-container")];
35162
+ for (let e of t) for (let t of [e, ...e.querySelectorAll("[data-latex],[data-latex-item]")]) t.removeAttribute("data-latex"), t.removeAttribute("data-latex-item");
35163
+ }
35164
+ function v() {
35103
35165
  return window.MathJax;
35104
35166
  }
35105
- function c(e) {
35167
+ function y(e) {
35106
35168
  let t = e.includes("\\displaystyle") ? e.replace("\\displaystyle", "").trim() : e;
35107
- for (let [e, n] of a) if (t.startsWith(e) && t.endsWith(n)) return t.substring(e.length, t.length - n.length);
35169
+ for (let [e, n] of d) if (t.startsWith(e) && t.endsWith(n)) return t.substring(e.length, t.length - n.length);
35108
35170
  return t;
35109
35171
  }
35110
- function l(e) {
35172
+ function b(e) {
35111
35173
  for (let t of e.querySelectorAll("[data-latex]")) {
35112
35174
  if (t.dataset.mathHandled || t.closest("mjx-container")) continue;
35113
35175
  let e = t.textContent;
35114
- e && (t.textContent = `\\(${c(e)}\\)`.replace(i, "\\newline "), t.dataset.mathHandled = "true");
35176
+ e && (t.textContent = `\\(${y(e)}\\)`.replace(u, "\\newline "), t.dataset.mathHandled = "true");
35115
35177
  }
35116
35178
  }
35117
- function u(e, t) {
35179
+ function x(e, t) {
35118
35180
  for (let t of e.querySelectorAll("math")) if (!t.closest("mjx-assistive-mml")) return !0;
35119
- return (t ? r : n).test(e.textContent ?? "");
35181
+ return (t ? l : c).test(e.textContent ?? "");
35120
35182
  }
35121
- function d(n) {
35122
- return new Promise((r, i) => {
35123
- let { useSingleDollar: a = !1, accessibility: o = !0, loadFonts: c = !0, srcUrl: l } = n, u = {
35183
+ function S(e) {
35184
+ return new Promise((t, n) => {
35185
+ let { useSingleDollar: r = !1, accessibility: i = !0, loadFonts: c = !0, srcUrl: l } = e, u = {
35124
35186
  loader: {
35125
- load: o ? ["a11y/assistive-mml"] : [],
35126
- failed: (e) => i(e)
35187
+ load: i ? ["a11y/assistive-mml"] : [],
35188
+ failed: (e) => n(e)
35127
35189
  },
35128
35190
  startup: {
35129
35191
  typeset: !1,
35130
35192
  ready: () => {
35131
- let e = s()?.startup;
35132
- e?.defaultReady?.(), Promise.resolve(e?.promise).then(() => r(), i);
35193
+ let e = v(), r = e?.startup, i = !!e?.version?.startsWith("4.");
35194
+ i && C(e), r?.defaultReady?.(), i && w(r?.document), Promise.resolve(r?.promise).then(() => t(), n);
35133
35195
  }
35134
35196
  },
35135
- tex: { macros: { ...e } },
35197
+ tex: { macros: { ...o } },
35136
35198
  options: {
35137
- enableMenu: o,
35199
+ enableMenu: i,
35138
35200
  menuOptions: { settings: {
35139
- assistiveMml: o,
35201
+ assistiveMml: i,
35140
35202
  enrich: !1,
35141
35203
  inTabOrder: !1
35142
35204
  } }
35143
35205
  }
35144
35206
  };
35145
- a && u.tex && (console.warn(t), u.tex.inlineMath = [["$", "$"], ["\\(", "\\)"]], u.tex.processEscapes = !0), c || (u.chtml = { fontURL: "" }), window.MathJax = u;
35207
+ r && u.tex && (console.warn(s), u.tex.inlineMath = [["$", "$"], ["\\(", "\\)"]], u.tex.processEscapes = !0), c || (u.chtml = { fontURL: "" }), window.MathJax = u;
35146
35208
  let d = document.createElement("script");
35147
- d.src = l || "https://cdn.jsdelivr.net/npm/mathjax@4.1.3/tex-mml-chtml.js", d.async = !0, d.onerror = () => i(/* @__PURE__ */ Error("Failed to load MathJax")), document.head.appendChild(d);
35209
+ d.src = l || a, d.async = !0, d.onerror = () => n(/* @__PURE__ */ Error("Failed to load MathJax")), document.head.appendChild(d);
35148
35210
  });
35149
35211
  }
35150
- function f(e) {
35212
+ function C(e) {
35213
+ let t = e?._?.output?.chtml_ts?.CHTML;
35214
+ t && (t.STYLESHEETID = p);
35215
+ }
35216
+ function w(e) {
35217
+ if (!e) return;
35218
+ let t = /* @__PURE__ */ new WeakSet(), n = (e) => {
35219
+ let n = e.typesetRoot;
35220
+ !n || t.has(n) || (_(n), t.add(n));
35221
+ };
35222
+ e.addRenderAction?.("pie-strip-latex", g, (e) => {
35223
+ for (let t of e.math ?? []) n(t);
35224
+ return !1;
35225
+ }, (e) => {
35226
+ let t = e.typesetRoot;
35227
+ return t && _(t), !1;
35228
+ });
35229
+ let r = e.outputJax?.chtmlStyles;
35230
+ r?.id === m && (r.id = p), D();
35231
+ }
35232
+ function T(e) {
35233
+ return e instanceof HTMLStyleElement && h.includes(e.id);
35234
+ }
35235
+ function E(e) {
35236
+ r("foreign-output-stylesheet", `another MathJax added <style id="${e.id}"> to <head>`);
35237
+ }
35238
+ function D() {
35239
+ let e = document.head, t = [...e.children].find(T);
35240
+ if (t) {
35241
+ E(t);
35242
+ return;
35243
+ }
35244
+ let n = new MutationObserver((e) => {
35245
+ for (let t of e) {
35246
+ let e = [...t.addedNodes].find(T);
35247
+ if (e) {
35248
+ E(e), n.disconnect();
35249
+ return;
35250
+ }
35251
+ }
35252
+ });
35253
+ n.observe(e, { childList: !0 });
35254
+ }
35255
+ function O(e) {
35151
35256
  return new Promise((t, n) => {
35152
35257
  let r = e.startup ?? {};
35153
35258
  e.startup = r;
35154
35259
  let i = r.ready;
35155
35260
  r.ready = () => {
35156
- let e = s()?.startup;
35261
+ let e = v()?.startup;
35157
35262
  i ? i.call(r) : e?.defaultReady?.(), Promise.resolve(e?.promise).then(() => t(), n);
35158
35263
  };
35159
35264
  });
35160
35265
  }
35161
- function p(e) {
35162
- let t = s();
35163
- return t ? t.version ? t.startup?.promise ? Promise.resolve(t.startup.promise).then(() => void 0) : Promise.resolve() : f(t) : d(e);
35266
+ function k(e) {
35267
+ let t = v();
35268
+ return t ? t.version ? t.startup?.promise ? Promise.resolve(t.startup.promise).then(() => void 0) : Promise.resolve() : O(t) : S(e);
35164
35269
  }
35165
- function m(e) {
35166
- return p(e).then(() => {
35167
- typeof s()?.typesetPromise != "function" && console.warn("[mathjax-renderer] MathJax on this page has no typesetPromise; math stays untypeset.");
35270
+ function A(e) {
35271
+ return k(e).then(() => {
35272
+ typeof v()?.typesetPromise != "function" && console.warn("[mathjax-renderer] MathJax on this page has no typesetPromise; math stays untypeset.");
35168
35273
  });
35169
35274
  }
35170
- function h(e) {
35171
- let t = globalThis, n = t[o];
35172
- return n || (n = m(e), t[o] = n), n;
35275
+ function j(e) {
35276
+ let t = globalThis, n = t[f];
35277
+ return n || (n = A(e), t[f] = n), n;
35173
35278
  }
35174
- function g(e = {}) {
35279
+ function M(e = {}) {
35175
35280
  let t = e.useSingleDollar ?? !1;
35176
35281
  return async (n) => {
35177
35282
  if (typeof window > "u") return;
35178
- l(n);
35179
- let r = h(e);
35180
- if (!u(n, t)) {
35181
- r.catch(() => {});
35283
+ let a = i();
35284
+ a && r("mathjax-3-global", `window.MathJax is MathJax ${a}`), b(n);
35285
+ let o = j(e);
35286
+ if (!x(n, t)) {
35287
+ o.catch(() => {});
35182
35288
  return;
35183
35289
  }
35184
- await r;
35185
- let i = s();
35186
- await i?.startup?.promise, typeof i?.typesetPromise == "function" && await i.typesetPromise([n]);
35290
+ await o;
35291
+ let s = v();
35292
+ await s?.startup?.promise, typeof s?.typesetPromise == "function" && (await s.typesetPromise([n]), _(n));
35187
35293
  };
35188
35294
  }
35189
- var v = "@pie-lib/math-rendering";
35190
- var y = "@pie-lib/math-rendering@2";
35191
- var b = null;
35192
- function x() {
35193
- return !!window[y]?.opts?.useSingleDollar;
35295
+ var P = "@pie-lib/math-rendering";
35296
+ var F = "@pie-lib/math-rendering@2";
35297
+ var I = null;
35298
+ function L() {
35299
+ return !!window[F]?.opts?.useSingleDollar;
35194
35300
  }
35195
- function S() {
35196
- return b || (b = g({ useSingleDollar: x() })), b;
35301
+ function R() {
35302
+ return I || (I = M({ useSingleDollar: L() })), I;
35197
35303
  }
35198
- function C() {
35304
+ function z() {
35199
35305
  if (typeof window > "u") return null;
35200
- let e = window[v];
35306
+ let e = window[P];
35201
35307
  return typeof e?.renderMath == "function" ? e : null;
35202
35308
  }
35203
- var w = async (e) => {
35309
+ function B() {
35310
+ let e = i();
35311
+ e && r("legacy-renderer-delegation", `window['${P}'] renders this element's math with MathJax ${e}`);
35312
+ }
35313
+ var V = async (e) => {
35204
35314
  if (typeof window > "u") return;
35205
35315
  let t = typeof e == "string", n;
35206
35316
  t ? (n = document.createElement("div"), n.innerHTML = e) : n = e || document.body;
35207
- let r = C();
35208
- return r ? await r.renderMath?.(n) : await S()(n), t ? n.innerHTML : void 0;
35317
+ let r = z();
35318
+ return r ? (B(), await r.renderMath?.(n)) : await R()(n), t ? n.innerHTML : void 0;
35209
35319
  };
35210
35320
  //#endregion
35211
35321
  //#region src/delivery/tile-accessible-name.ts
@@ -36526,7 +36636,7 @@ function VennClassification($$anchor, $$props) {
36526
36636
  if (!containerEl) return;
36527
36637
  const warn = (err) => console.warn("venn-classification: MathJax render failed", err);
36528
36638
  try {
36529
- Promise.resolve(w(containerEl)).catch(warn);
36639
+ Promise.resolve(V(containerEl)).catch(warn);
36530
36640
  } catch (err) {
36531
36641
  warn(err);
36532
36642
  }