editable.ts 0.0.1

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.
Files changed (153) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +571 -0
  3. package/dist/editable.umd.cjs +2 -0
  4. package/dist/editable.umd.cjs.map +1 -0
  5. package/lib/block.d.ts +13 -0
  6. package/lib/block.d.ts.map +1 -0
  7. package/lib/block.js +58 -0
  8. package/lib/block.js.map +1 -0
  9. package/lib/clipboard.d.ts +22 -0
  10. package/lib/clipboard.d.ts.map +1 -0
  11. package/lib/clipboard.js +154 -0
  12. package/lib/clipboard.js.map +1 -0
  13. package/lib/config.d.ts +37 -0
  14. package/lib/config.d.ts.map +1 -0
  15. package/lib/config.js +64 -0
  16. package/lib/config.js.map +1 -0
  17. package/lib/content.d.ts +37 -0
  18. package/lib/content.d.ts.map +1 -0
  19. package/lib/content.js +526 -0
  20. package/lib/content.js.map +1 -0
  21. package/lib/core.d.ts +97 -0
  22. package/lib/core.d.ts.map +1 -0
  23. package/lib/core.js +261 -0
  24. package/lib/core.js.map +1 -0
  25. package/lib/create-default-behavior.d.ts +31 -0
  26. package/lib/create-default-behavior.d.ts.map +1 -0
  27. package/lib/create-default-behavior.js +178 -0
  28. package/lib/create-default-behavior.js.map +1 -0
  29. package/lib/create-default-events.d.ts +152 -0
  30. package/lib/create-default-events.d.ts.map +1 -0
  31. package/lib/create-default-events.js +183 -0
  32. package/lib/create-default-events.js.map +1 -0
  33. package/lib/cursor.d.ts +68 -0
  34. package/lib/cursor.d.ts.map +1 -0
  35. package/lib/cursor.js +354 -0
  36. package/lib/cursor.js.map +1 -0
  37. package/lib/dispatcher.d.ts +78 -0
  38. package/lib/dispatcher.d.ts.map +1 -0
  39. package/lib/dispatcher.js +416 -0
  40. package/lib/dispatcher.js.map +1 -0
  41. package/lib/eventable.d.ts +2 -0
  42. package/lib/eventable.d.ts.map +1 -0
  43. package/lib/eventable.js +104 -0
  44. package/lib/eventable.js.map +1 -0
  45. package/lib/feature-detection.d.ts +12 -0
  46. package/lib/feature-detection.d.ts.map +1 -0
  47. package/lib/feature-detection.js +42 -0
  48. package/lib/feature-detection.js.map +1 -0
  49. package/lib/highlight-support.d.ts +24 -0
  50. package/lib/highlight-support.d.ts.map +1 -0
  51. package/lib/highlight-support.js +172 -0
  52. package/lib/highlight-support.js.map +1 -0
  53. package/lib/highlight-text.d.ts +21 -0
  54. package/lib/highlight-text.d.ts.map +1 -0
  55. package/lib/highlight-text.js +147 -0
  56. package/lib/highlight-text.js.map +1 -0
  57. package/lib/keyboard.d.ts +33 -0
  58. package/lib/keyboard.d.ts.map +1 -0
  59. package/lib/keyboard.js +189 -0
  60. package/lib/keyboard.js.map +1 -0
  61. package/lib/monitored-highlighting.d.ts +28 -0
  62. package/lib/monitored-highlighting.d.ts.map +1 -0
  63. package/lib/monitored-highlighting.js +194 -0
  64. package/lib/monitored-highlighting.js.map +1 -0
  65. package/lib/node-iterator.d.ts +16 -0
  66. package/lib/node-iterator.d.ts.map +1 -0
  67. package/lib/node-iterator.js +97 -0
  68. package/lib/node-iterator.js.map +1 -0
  69. package/lib/node-type.d.ts +13 -0
  70. package/lib/node-type.d.ts.map +1 -0
  71. package/lib/node-type.js +15 -0
  72. package/lib/node-type.js.map +1 -0
  73. package/lib/parser.d.ts +89 -0
  74. package/lib/parser.d.ts.map +1 -0
  75. package/lib/parser.js +251 -0
  76. package/lib/parser.js.map +1 -0
  77. package/lib/plugins/highlighting/match-collection.d.ts +7 -0
  78. package/lib/plugins/highlighting/match-collection.d.ts.map +1 -0
  79. package/lib/plugins/highlighting/match-collection.js +62 -0
  80. package/lib/plugins/highlighting/match-collection.js.map +1 -0
  81. package/lib/plugins/highlighting/spellcheck-service.d.ts +12 -0
  82. package/lib/plugins/highlighting/spellcheck-service.d.ts.map +1 -0
  83. package/lib/plugins/highlighting/spellcheck-service.js +24 -0
  84. package/lib/plugins/highlighting/spellcheck-service.js.map +1 -0
  85. package/lib/plugins/highlighting/text-search.d.ts +10 -0
  86. package/lib/plugins/highlighting/text-search.d.ts.map +1 -0
  87. package/lib/plugins/highlighting/text-search.js +92 -0
  88. package/lib/plugins/highlighting/text-search.js.map +1 -0
  89. package/lib/plugins/highlighting/whitespace-highlighting.d.ts +14 -0
  90. package/lib/plugins/highlighting/whitespace-highlighting.d.ts.map +1 -0
  91. package/lib/plugins/highlighting/whitespace-highlighting.js +52 -0
  92. package/lib/plugins/highlighting/whitespace-highlighting.js.map +1 -0
  93. package/lib/quotes.d.ts +8 -0
  94. package/lib/quotes.d.ts.map +1 -0
  95. package/lib/quotes.js +170 -0
  96. package/lib/quotes.js.map +1 -0
  97. package/lib/range-container.d.ts +22 -0
  98. package/lib/range-container.d.ts.map +1 -0
  99. package/lib/range-container.js +52 -0
  100. package/lib/range-container.js.map +1 -0
  101. package/lib/range-save-restore.d.ts +13 -0
  102. package/lib/range-save-restore.d.ts.map +1 -0
  103. package/lib/range-save-restore.js +153 -0
  104. package/lib/range-save-restore.js.map +1 -0
  105. package/lib/selection-watcher.d.ts +55 -0
  106. package/lib/selection-watcher.d.ts.map +1 -0
  107. package/lib/selection-watcher.js +126 -0
  108. package/lib/selection-watcher.js.map +1 -0
  109. package/lib/selection.d.ts +74 -0
  110. package/lib/selection.d.ts.map +1 -0
  111. package/lib/selection.js +341 -0
  112. package/lib/selection.js.map +1 -0
  113. package/lib/smartQuotes.d.ts +16 -0
  114. package/lib/smartQuotes.d.ts.map +1 -0
  115. package/lib/smartQuotes.js +92 -0
  116. package/lib/smartQuotes.js.map +1 -0
  117. package/lib/util/binary_search.d.ts +23 -0
  118. package/lib/util/binary_search.d.ts.map +1 -0
  119. package/lib/util/binary_search.js +137 -0
  120. package/lib/util/binary_search.js.map +1 -0
  121. package/lib/util/clone-deep.d.ts +8 -0
  122. package/lib/util/clone-deep.d.ts.map +1 -0
  123. package/lib/util/clone-deep.js +10 -0
  124. package/lib/util/clone-deep.js.map +1 -0
  125. package/lib/util/dom.d.ts +43 -0
  126. package/lib/util/dom.d.ts.map +1 -0
  127. package/lib/util/dom.js +272 -0
  128. package/lib/util/dom.js.map +1 -0
  129. package/lib/util/element.d.ts +10 -0
  130. package/lib/util/element.d.ts.map +1 -0
  131. package/lib/util/element.js +29 -0
  132. package/lib/util/element.js.map +1 -0
  133. package/lib/util/error.d.ts +2 -0
  134. package/lib/util/error.d.ts.map +1 -0
  135. package/lib/util/error.js +16 -0
  136. package/lib/util/error.js.map +1 -0
  137. package/lib/util/log.d.ts +2 -0
  138. package/lib/util/log.d.ts.map +1 -0
  139. package/lib/util/log.js +18 -0
  140. package/lib/util/log.js.map +1 -0
  141. package/lib/util/merge.d.ts +6 -0
  142. package/lib/util/merge.d.ts.map +1 -0
  143. package/lib/util/merge.js +31 -0
  144. package/lib/util/merge.js.map +1 -0
  145. package/lib/util/string.d.ts +25 -0
  146. package/lib/util/string.d.ts.map +1 -0
  147. package/lib/util/string.js +68 -0
  148. package/lib/util/string.js.map +1 -0
  149. package/lib/util/viewport.d.ts +6 -0
  150. package/lib/util/viewport.d.ts.map +1 -0
  151. package/lib/util/viewport.js +8 -0
  152. package/lib/util/viewport.js.map +1 -0
  153. package/package.json +86 -0
@@ -0,0 +1,2 @@
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Editable={})}(this,function(e){"use strict";const t={log:!1,logErrors:!0,editableClass:"js-editable",editableDisabledClass:"js-editable-disabled",pastingAttribute:"data-editable-is-pasting",trimLeadingAndTrailingWhitespaces:!0,boldMarkup:{type:"tag",name:"strong",attribs:{},trim:!0},italicMarkup:{type:"tag",name:"em",attribs:{},trim:!0},underlineMarkup:{type:"tag",name:"u",attribs:{},trim:!1},linkMarkup:{type:"tag",name:"a",attribs:{},trim:!0},pastedHtmlRules:{allowedElements:{a:{href:!0,rel:!0,target:!0},strong:{},em:{},br:{}},allowedPlainTextElements:{br:{}},requiredAttributes:{a:["href"]},transformElements:{b:"strong",i:"em"},splitIntoBlocks:["h1","h2","h3","h4","h5","h6","p","blockquote"],blockLevelElements:["h1","h2","h3","h4","h5","h6","div","p","pre","hr","blockquote","article","figure","header","footer","ul","ol","li","section","table","video"],blacklistedElements:["style","script"],keepInternalRelativeLinks:!1,replaceQuotes:{}}};function n(...e){if(!1===t.logErrors)return;const n=1===e.length?e[0]:e;global.console&&("function"!=typeof console.error?console.log(n):console.error(n))}const i=Object.prototype.toString,r={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};function o(e){return e.replace(/\s+$/,"")}function s(e){return e.replace(/^\s+|\s+$/g,"")}function a(e){return"[object String]"===i.call(e)}class c{constructor(e,t){this.current=this.previous=this.nextNode=this.root=e,this.iteratorFunc=this[t||"getNext"]}[Symbol.iterator](){return this}getNextTextNode(){let e;for(;e=this.getNext();)if(3===e.nodeType&&""!==e.data)return e}getPreviousTextNode(){let e;for(;e=this.getPrevious();)if(3===e.nodeType&&""!==e.data)return e}next(){const e=this.iteratorFunc();return e?{value:e}:{done:!0,value:void 0}}getNext(){let e,t=this.current=this.nextNode;if(this.nextNode=void 0,this.current)if(e=t.firstChild,e&&"remove"!==t.getAttribute?.("data-editable"))this.nextNode=e;else for(;t!==this.root&&t;){const e=t.nextSibling;if(e){this.nextNode=e;break}t=t.parentNode}return this.current}getPrevious(){let e,t=this.current=this.previous;if(this.previous=void 0,this.current)if(e=t.lastChild,e&&"remove"!==t.getAttribute?.("data-editable"))this.previous=e;else for(;t!==this.root&&t;){const e=t.previousSibling;if(e){this.previous=e;break}t=t.parentNode}return this.current}replaceCurrent(e){this.current=e,this.nextNode=void 0,this.previous=void 0;let t=this.current;for(;t!==this.root&&t;){const e=t.nextSibling;if(e){this.nextNode=e;break}t=t.parentNode}}}const l=(e,t,n)=>{if("string"==typeof e){const i=t.querySelectorAll?t:t.ownerDocument,r=n||t;return Array.from(r.querySelectorAll?r.querySelectorAll(e):i.querySelectorAll(e))}return e.tagName?[e]:Array.isArray(e)?e:Array.from(e)},h=(e,t)=>"string"==typeof e?t.querySelector(e):e.tagName?e:e[0]?e[0]:e,u=(e,t=window)=>{const n=t.document.createElement("div");return n.innerHTML=e,n.firstElementChild},d=(e,t)=>{if(!e)return;let n=e;for(;n&&!n.closest;)n=n.parentNode;return n&&n.closest?n.closest(t):void 0},f=(e=window)=>e.document.createRange(),g=(e=window)=>{const t=e.document.getSelection?e.document.getSelection():null;return t||(e.getSelection?e.getSelection():null)},p=(e,t,n,i=window)=>{const r=[],o=i.document.createNodeIterator(e.commonAncestorContainer,NodeFilter.SHOW_ALL,{acceptNode:i=>e.intersectsNode(i)&&t.includes(i.nodeType)&&i!==e.commonAncestorContainer?"function"==typeof n?n(i)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP});let s;for(;s=o.nextNode();)r.push(s);return r},m=e=>{e.startContainer.compareDocumentPosition(e.endContainer)===Node.DOCUMENT_POSITION_FOLLOWING&&e.setStartBefore(e.endContainer),e.endContainer.compareDocumentPosition(e.startContainer)===Node.DOCUMENT_POSITION_PRECEDING&&e.setEndAfter(e.startContainer)},b=e=>e&&(e.nodeType===Node.TEXT_NODE||e.nodeType===Node.COMMENT_NODE),y=(e,t)=>e.splitText(t),C=(e,t)=>{const n=e.cloneRange();n.setStart(t,0),n.setEnd(e.startContainer,e.startOffset);const i=e.toString(),r=n.toString().length;return{start:r,end:r+i.length,text:i}},w=(e,t)=>e.startContainer===t.startContainer&&e.startOffset===t.startOffset&&e.endContainer===t.endContainer&&e.endOffset===t.endOffset;function v({root:e,startContainer:t,startOffset:n,whitespacesOnTheLeft:i}){if(!(3===t.nodeType))return v({root:e,startContainer:t.childNodes[n],startOffset:0,whitespacesOnTheLeft:i});const r=n+i;if(t.length>r)return[t,r];const o=new c(e);o.nextNode=t,o.getNextTextNode();const s=o.getNextTextNode();if(!s){const e=o.getPreviousTextNode();if(!e)throw new Error("No previous text node found");return[e,e.length]}return v({root:e,startContainer:s,startOffset:0,whitespacesOnTheLeft:r-t.length})}function S({root:e,endContainer:t,endOffset:n,whitespacesOnTheRight:i}){if(!(3===t.nodeType)){const r=!t.childNodes[n-1],o=r?t.childNodes[n]:t.childNodes[n-1];let s=0;return r||(s=3===o.nodeType?o.length:o.childNodes.length),S({root:e,endContainer:o,endOffset:s,whitespacesOnTheRight:i})}const r=n-i;if(r>0)return[t,r];const o=new c(e);o.previous=t,o.getPreviousTextNode();const s=o.getPreviousTextNode();if(!s){const e=o.getNextTextNode();if(!e)throw new Error("No next text node found");return[e,0]}return S({root:e,endContainer:s,endOffset:s.length,whitespacesOnTheRight:i-n})}function E(e){if((e=e.jquery?e[0]:e)&&e.classList&&e.classList.contains(t.editableClass))return e;const n=d(e,`.${t.editableClass}`);if(n)return n;return d(e,'[contenteditable="true"]')||null}function T(e){let t=0,n=e.previousSibling;for(;null!==n;)t++,n=n.previousSibling;return t}function x(e){const t=Array.from(e.childNodes);for(const n of t){if(3===n.nodeType&&!N(n))return!1;if(1===n.nodeType)return!1}return!0}function N(e){return 3===e.nodeType&&!e.nodeValue}function k(e){return 3===e.nodeType&&0===R(e)}function A(e){return 1===e.nodeType&&"BR"===e.tagName}function R(e){if(3===e.nodeType){const t=e.nodeValue;return t?o(t).length:0}let t=0;return Array.from(e.childNodes).reverse().every((e,n,i)=>!(!k(e)&&!A(e))||(t=i.length-n,!1)),t}function B(e,t,n){if(t===e)return L(t,n);if(L(t,n)){const n=T(t),i=t.parentNode;return!!i&&B(e,i,n)}return!1}function O(e,t,n){if(t===e)return M(t,n);if(M(t,n)){const n=T(t)+1,i=t.parentNode;return!!i&&O(e,i,n)}return!1}function L(e,t){if(3===e.nodeType)return 0===t;if(0===e.childNodes.length)return!0;const n=e.firstChild;return!(1!==e.childNodes.length||!n||1!==n.nodeType||"remove"!==n.getAttribute("data-editable"))||e.childNodes[t]===e.firstChild}function M(e,t){return 3===e.nodeType?t===e.length:0===e.childNodes.length||t>0&&e.childNodes[t-1]===e.lastChild}function I(e,t,n){if(t===e)return D(t,n);if(D(t,n)){const n=T(t)+1,i=t.parentNode;return!!i&&I(e,i,n)}return!1}function D(e,t){if(3===e.nodeType){const n=e.nodeValue;if(!n)return 0===t;return t>=o(n).length}return 0===e.childNodes.length||t>=R(e)}function H(e,t){let n,i,r;if(e.nodeType!==t.nodeType)return!1;if(e.nodeName!==t.nodeName)return!1;if(1!==e.nodeType||1!==t.nodeType)return!0;const o=e,s=t;for(n=0,i=o.attributes.length;n<i;n++)if(r=o.attributes[n],s.getAttribute(r.name)!==r.value)return!1;return!0}function F(e){return e.lastChild?F(e.lastChild):e}function $(e){return!(!e||11!==e.nodeType||0!==e.childNodes.length)}const V=Object.freeze(Object.defineProperty({__proto__:null,getHost:E,getNodeIndex:T,isBeginningOfHost:B,isDocumentFragmentWithoutChildren:$,isEndOfHost:O,isEndOffset:M,isInlineElement:function(e,t){switch((t.currentStyle||e.getComputedStyle(t,"")).display){case"inline":case"inline-block":return!0;default:return!1}},isLinebreak:A,isSameNode:H,isStartOffset:L,isTextEndOfHost:I,isTextEndOffset:D,isVoid:x,isVoidTextNode:N,isWhitespaceOnly:k,lastChild:F,lastOffsetWithContent:R,latestChild:function(e){return console.warn("Editable.js: Using obsolete function parser.latestCild(), use lastChild() instead"),F(e)}},Symbol.toStringTag,{value:"Module"}));let P=0;function q(e,t){const n=e.commonAncestorContainer;if(3===n.nodeType)return!1;const i=t.parentElement;return i?.parentElement===n}function W(e,t){const i=e.commonAncestorContainer;if(!i.ownerDocument)throw n("Cannot save range: range is empty"),new Error("Cannot save range: range is empty");const r=i.ownerDocument;if(!r.defaultView)throw n("Cannot save range: document has no defaultView"),new Error("Cannot save range: document has no defaultView");const o=r.defaultView.document,s=o.createElement("span");s.id="editable-range-boundary-"+ ++P,s.setAttribute("data-editable","remove"),s.style.lineHeight="0",s.style.display="none",s.appendChild(o.createTextNode("\ufeff"));const a=t&&q(e,e.startContainer),c=!t&&q(e,e.endContainer);if(a){const t=e.startContainer.parentElement;t&&t.parentElement&&t.parentElement.insertBefore(s,t)}else if(c){const t=e.endContainer.parentElement;t&&t.parentElement&&t.parentElement.insertBefore(s,t.nextSibling)}else{const n=e.cloneRange();n.collapse(t),n.insertNode(s)}return s}function _(e,t,n,i){const r=U(e,n);if(!r)return console.log("Marker element has been removed. Cannot restore selection.");t[i?"setStartBefore":"setEndBefore"](r),r.remove()}function j(e){let t,n,i;return e.collapsed?(i=W(e,!1),t={markerId:i.id,collapsed:!0}):(i=W(e,!1),n=W(e,!0),t={startMarkerId:n.id,endMarkerId:i.id,collapsed:!1}),e.collapsed?(e.setStartBefore(i),e.collapse(!0)):(e.setEndBefore(i),n&&e.setStartAfter(n)),t}function K(e,t){if(t.restored)return;const n=f();if(t.collapsed){if(!t.markerId)return void console.log("Marker ID is missing. Cannot restore selection.");const i=U(e,t.markerId);if(i){i.style.display="inline";const e=i.previousSibling;e&&3===e.nodeType?(i.remove(),n.setStart(e,e.length)):(n.setStartBefore(i),n.collapse(!0),i.remove())}else console.log("Marker element has been removed. Cannot restore selection.")}else{if(!t.startMarkerId||!t.endMarkerId)return void console.log("Marker IDs are missing. Cannot restore selection.");_(e,n,t.startMarkerId,!0),_(e,n,t.endMarkerId,!1)}return m(n),n}function U(e,t){return e.querySelector(`#${t}`)}function z(e,t,n){const i=j(t);return n(),K(e,i)}const Q=/\u200B/g,X=/\uFEFF/g,J=/[^\S ]/g,Y=/^\s+$/,G=/^\s+/,Z=/\s+$/;function ee(e){te(e)}function te(e){const t=document.createDocumentFragment();le(e,"firstChild"),le(e,"lastChild");const n=Array.from(e.childNodes),i=new Set;for(let r=0;r<n.length;r++){if(i.has(r))continue;const e=n[r];if("BR"===e.nodeName||e.textContent)if(1===e.nodeType&&"BR"!==e.nodeName){const o=e.cloneNode(!1);for(const t of Array.from(e.childNodes))o.appendChild(t.cloneNode(!0));let s=r+1;for(;s<n.length;){const t=n[s];if(!H(t,e))break;for(const e of Array.from(t.childNodes))o.appendChild(e.cloneNode(!0));i.add(s),t.remove(),s++}te(o),t.appendChild(o)}else t.appendChild(e.cloneNode(!0))}for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(t)}function ne(e){return e.replace(J," ")}function ie(e){e.innerHTML=re(e,!0)}function re(e,t){if(!e)return"";const n=(11===e.nodeType?oe(e):e.innerHTML).replace(X,"").replace(Q,"<br>"),i=document.createElement("div");return i.innerHTML=n,he(i,t),le(i,"firstChild"),le(i,"lastChild"),i.innerHTML}function oe(e){if(!e||!e.childNodes)return"";const t=document.createElement("div"),n=Array.from(e.childNodes);for(const i of n)t.appendChild(i.cloneNode(!0));return t.innerHTML}function se(e){const t=document.createElement("div");t.innerHTML=e;const n=document.createDocumentFragment();for(;t.firstChild;)n.appendChild(t.firstChild);return n}function ae(e,t){if("string"==typeof e){const n=t.querySelector(e);if(!n)throw new Error(`Element not found: ${e}`);return n}return e.ownerDocument!==t?t.adoptNode(e):e}function ce(e){const t=e.cloneContents().childNodes[0],n=document.createDocumentFragment();for(;t.childNodes.length;)n.appendChild(t.childNodes[0]);return n}function le(e,n,i=!0){let r;for(;r=e[n];)if(3===r.nodeType){if(!r.textContent||!Y.test(r.textContent))break;e.removeChild(r)}else{if("BR"!==r.nodeName){r[n]&&le(r,n,!1);break}r.remove()}i&&(r=e[n],3===r?.nodeType&&t.trimLeadingAndTrailingWhitespaces&&r.textContent&&(r.textContent=r.textContent.replace(n.startsWith("last")?Z:G,"")))}function he(e,t){for(;e;){const n=e.nextSibling;if(1!==e.nodeType){e=n;continue}const i=e,r=i.getAttribute("data-editable");i.firstChild&&he(i.firstChild,t),"remove"===r||"ui-remove"===r&&!t?i.remove():("unwrap"===r||"ui-unwrap"===r&&!t)&&xe(i),e=n}}function ue(e,t,n){const i=me(t,n),r=de(e,t,n);return i.concat(r)}function de(e,t,n){const i=[];let r=t.commonAncestorContainer;for(;r&&r!==e;)n&&!n(r)||i.push(r),r=r.parentNode;return i}function fe(e,t,n){return ue(e,t,e=>e.nodeName.toUpperCase()===n.toUpperCase())}function ge(e,t,n){return ue(e,t,e=>e.nodeName.toUpperCase()===n.nodeName.toUpperCase()&&1===e.nodeType&&pe(e.attributes,n.attributes))}function pe(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++){const i=e[n],r=t.getNamedItem(i.name);if(!r||r.value!==i.value)return!1}return!0}function me(e,t){return p(e,[1],t)}function be(e,t){return p(e,[1],t).filter(t=>((e,t)=>{const n=document.createRange();n.selectNodeContents(t);const i=e.compareBoundaryPoints(Range.START_TO_START,n),r=e.compareBoundaryPoints(Range.END_TO_END,n);return i<=0&&r>=0})(e,t))}function ye(e=[]){return e.map(e=>e.nodeName)}function Ce(e,t,n){const i=f();if(i.selectNodeContents(t),o=i,-1!==(r=e).compareBoundaryPoints(Range.END_TO_START,o)||-1!==o.compareBoundaryPoints(Range.END_TO_START,r))return!1;var r,o;let a=e.toString(),c=(t.jquery?t[0]:t).textContent;return n&&(a=s(a),c=s(c)),""!==a&&a===c}function we(e,t,n){return t.selectNodeContents(n),t}function ve(e,t,n){const i=ge(e,t,n);if(1===i.length&&1===i[0].nodeType&&Ce(t,i[0],!0)){const i=Ne(e,t,n);return i||t}return Ee(e,t,n)}function Se(e){return function(e){if(!e||!e.startContainer||!e.endContainer)return!1;if(e.startContainer===e.endContainer)return!0;const t=function(e){let t=e,n=null;function i(){if(!t)return null;if(t.firstChild&&n!==t.firstChild)n=t,t=t.firstChild;else if(t.nextSibling)n=t,t=t.nextSibling;else{let i=t.parentNode;for(;i&&i!==e;){if(i.nextSibling){n=t=i.nextSibling;break}i=i.parentNode}i&&i!==e||(n=t=null)}return t}return{next:i}}(e.commonAncestorContainer);let n,i=!1;for(;n=t.next();)if(n.nodeType===Node.ELEMENT_NODE&&!Ie(n,e)){i=!0;break}return!i}(e)}function Ee(e,t,n){let i=z(e,t,()=>{Re(e,t,n)});if(!i||!Se(i)){if(!i)return t;if(i=z(e,i,()=>{Ae(e,i,null)}),!i)return t}return Te(i,n),i}function Te(e,t){if(!Se(e))return void console.log("content.wrap(): can not surround range");let n;if("string"==typeof t){if(n=u(t),!n)return void console.log("content.wrap(): could not create element")}else n=t;e.surroundContents(n)}function xe(e){const t=(e=e.jquery?e[0]:e).parentNode;if(t){for(;e.firstChild;)t.insertBefore(e.firstChild,e);t.removeChild(e)}}function Ne(e,t,n){return z(e,t,()=>{Re(e,t,n)})}function ke(e,t,n){return z(e,t,()=>{Ae(e,t,n)})}function Ae(e,t,n){ue(e,t,null).forEach(e=>{"BR"===e.nodeName.toUpperCase()||n&&!e.matches(n)||xe(e)})}function Re(e,t,n){ue(e,t,null).forEach(e=>{"BR"!==e.nodeName.toUpperCase()&&(!n||e.nodeName.toUpperCase()===n.nodeName.toUpperCase()&&pe(e.attributes,n.attributes))&&xe(e)})}function Be(e,t,n){const i=document.createTextNode(t),r=e.cloneRange();r.collapse(n),r.insertNode(i),e[n?"setStartBefore":"setEndAfter"](i),m(e)}function Oe(e,t,n,i){return Be(t,i||n,!1),Be(t,n,!0),t}function Le(e,t,n){if(!Me(t,n))return t;const i=window.getSelection();i&&i.rangeCount>0&&(e=>{const t=e.startContainer,n=e.startOffset,i=e.endContainer,r=e.endOffset;if(b(i)&&r>0&&r<i.length&&y(i,r),b(t)&&n>0&&n<t.length){const i=y(t,n);e.setStart(i,0)}})(t);const r=z(e,t,()=>{p(t,[3],e=>null!==e.nodeValue&&e.nodeValue.indexOf(n)>=0).forEach(e=>{const t=e;t.nodeValue&&(t.nodeValue=t.nodeValue.replace(new RegExp(n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g"),""))})});return r?(m(r),r):t}function Me(e,t){return e.toString().indexOf(t)>=0}function Ie(e,t){const n=document.createRange();return n.selectNodeContents(e),t.compareBoundaryPoints(Range.START_TO_START,n)<=0&&t.compareBoundaryPoints(Range.END_TO_END,n)>=0}const De=Object.freeze(Object.defineProperty({__proto__:null,adoptElement:ae,areSameAttributes:pe,cleanInternals:ie,cloneRangeContents:ce,containsString:Me,createFragmentFromString:se,deleteCharacter:Le,expandTo:we,extractContent:re,forceWrap:Ee,getAncestorTags:de,getContainedTags:be,getInnerHtmlOfFragment:oe,getInnerTags:me,getTagNames:ye,getTags:ue,getTagsByName:fe,getTagsByNameAndAttributes:ge,insertCharacter:Be,isAffectedBy:function(e,t,n){return ue(e,t,null).some(e=>e.nodeName===n.toUpperCase())},isExactSelection:Ce,isWrappable:Se,normalizeTags:te,normalizeWhitespace:ne,nuke:Ae,nukeElem:Re,nukeTag:function(e,t,n){ue(e,t,null).forEach(e=>{e.nodeName.toUpperCase()===n.toUpperCase()&&xe(e)})},removeFormatting:ke,removeFormattingElem:Ne,selectNodeContents:function(e){const t=f();return t.selectNodeContents(e),t},surround:Oe,tidyHtml:ee,toggleTag:ve,unwrap:xe,unwrapInternalNodes:he,wrap:Te},Symbol.toStringTag,{value:"Module"}));let He=1;function Fe(e,{normalize:n,plainText:i,shouldSpellcheck:r}={}){!function(e){e.hasAttribute("data-editable")||(e.setAttribute("data-editable",`id-${He}`),He+=1)}(e),e.setAttribute("contenteditable","true"),e.setAttribute("spellcheck",String(Boolean(r))),e.setAttribute("data-plaintext",String(Boolean(i))),e.classList.remove(t.editableDisabledClass),e.classList.add(t.editableClass),n&&ee(e)}function $e(e){e.removeAttribute("contenteditable"),e.removeAttribute("spellcheck"),e.removeAttribute("data-plaintext"),function(e){e.hasAttribute("data-editable")&&e.getAttribute("data-editable")}(e),e.classList.remove(t.editableClass),e.classList.add(t.editableDisabledClass)}function Ve(e){return"true"===e.getAttribute("data-plaintext")}const Pe=[["«","»"],["»","«"],['"','"'],["“","”"],["”","”"],["“","“"],["„","“"]],qe=[["‘","’"],["‹","›"],["‚","‘"],["’","’"],["›","‹"],["'","'"],["‘","’"]],We=["’","'"],_e=/([‘’‹›‚'«»"“”„])(?![^<]*?>)/g,je=/\s|[>\-–—«»”"“„]/,Ke=/\s|[<\-–—«»”"“‘’‹›'.;?:,]/;let Ue,ze,Qe,Xe,Je,Ye,Ge,Ze,et;function tt(e,t){Ue=t||{},Ue.quotes=Ue.quotes||[void 0,void 0],Ue.singleQuotes=Ue.singleQuotes||[void 0,void 0];const n=function(e){return[...e.matchAll(_e)].map(t=>{const n=t.index;return{char:t[1],before:n>0?e[n-1]:"",after:n+1<e.length?e[n+1]:""}})}(e);return n.length>0?(nt(n,0),function(e,t){let n=0;return e.replace(_e,e=>{const i=t[n].replace||t[n].char;return n+=1,i})}(e,n)):e}function nt(e,t){for(;t<e.length;){const n=it(e,t);if(n){if(e[t].replace="double"===n.type?Ue.quotes?.[0]:Ue.singleQuotes?.[0],e[n.position].replace="double"===n.type?Ue.quotes?.[1]:Ue.singleQuotes?.[1],n.position!==t+1){const i=e.slice(t+1,n.position);i&&i.length>0&&nt(i,0)}t=n.position+1}else e[t].replace=ot(e[t].char),t+=1}}function it(e,t){if(t===e.length-1)return;const n=e[t],i=n.char;if(n.before&&!je.test(n.before))return;const r=rt(i,qe),o=rt(i,Pe);let s=o,a=r;const c=o.length>0&&!o.includes('"')||r.length>0&&!r.includes("'");o.length>0&&!o.includes('"')&&(s=[...o,'"']),r.length>0&&!r.includes("'")&&(a=[...r,"'"]);const l='"'===i||"'"===i;let h;for(let u=t+1;u<e.length;u++){const t=e[u].char,n=e[u].after;if(n&&Ke.test(n)||!n){if(a.includes(t)){if(r.includes(t)&&!l)return{position:u,type:"single"};if(!c&&!l)return{position:u,type:"single"};(!h||"single"===h.type&&u>h.position)&&(h={position:u,type:"single"})}if(s.includes(t)){if(o.includes(t)&&!l)return{position:u,type:"double"};if(!c&&!l)return{position:u,type:"double"};(!h||"double"===h.type&&u>h.position)&&(h={position:u,type:"double"})}}}return h||void 0}function rt(e,t){return t.filter(t=>t[0]===e).map(e=>e[1])}function ot(e){if(We.includes(e))return Ue.apostrophe}const st=/^\s*$/,at="\x3c!-- BLOCK --\x3e";let ct;function lt(e){const t=e.pastedHtmlRules;ze=t.allowedElements||{},Qe=t.allowedPlainTextElements||{},Xe=t.requiredAttributes||{},Je=t.transformElements||{},et=t.blacklistedElements||[],ct=t.keepInternalRelativeLinks||!1,Ge=t.replaceQuotes||{},Ye={},t.blockLevelElements.forEach(e=>{Ye[e]=!0}),Ze={},t.splitIntoBlocks.forEach(e=>{Ze[e]=!0})}function ht(e,n,i){const r=e.ownerDocument;if(e.setAttribute(t.pastingAttribute,"true"),n.isSelection){n=n.deleteExactSurroundingTags().deleteContainedTags().deleteContent()}const o=r.createElement("div");o.innerHTML=i;const a=function(e,{plainText:t=!1}={}){return ut(e,{allowedElements:t?Qe:ze,keepInternalRelativeLinks:!t&&ct}).split(at).map(e=>s(function(e){return Ge.quotes||Ge.singleQuotes||Ge.apostrophe?tt(e,Ge):e}(e).replace(/\n/g," ").replace(/ {2,}/g," ").replace(/(.)\u00A0/g,(e,t)=>t+(/[\u0020]/.test(t)?" ":" ")))).filter(e=>!st.test(e))}(o,{plainText:Ve(e)});return e.removeAttribute(t.pastingAttribute),{blocks:a,cursor:n}}function ut(e,t){return Array.from(e.childNodes).reduce((e,n)=>{if(-1!==et.indexOf(n.nodeName.toLowerCase()))return"";const i=n;if(t.keepInternalRelativeLinks&&"A"===i.nodeName&&i.href){const e=i.getAttribute("href");if(e){const t=e.replace(window.location.origin,"");i.setAttribute("href",t)}}if(1===n.nodeType){return e+function(e,t,n){let i=e.nodeName.toLowerCase();if(i=function(e){return Je[e]||e}(i),function(e,t,n){return!!n.allowedElements[e]&&function(e,t){const n=Xe[e];return!n||!n.some(e=>!t.getAttribute(e))}(e,t)}(i,e,n)){const n=function(e,t){return Array.from(t.attributes).reduce((t,n)=>{const i=n.name,r=n.value;return ze[e]?.[i]&&r?`${t} ${i}="${r}"`:t},"")}(i,e);return"br"===i?`<${i+n}>`:st.test(t)?t:`<${i+n}>${t}</${i}>`}if(Ze[i])return at+t+at;return Ye[i]?`${t} `:t}(i,ut(i,t),t)}return 3===n.nodeType?e+(n.nodeValue||"").replace(/[&<>]/g,function(e){return r[e]||e}):e},"")}lt(t),document.documentElement.contentEditable;const dt=/(apple)?webkit\/537\.36/i.test(window.navigator.userAgent),ft=/(apple)?webkit/i.test(window.navigator.userAgent),gt=!dt&&ft,pt=(e=>{const t=e,n=t.onselectionchange;if(void 0!==n)try{return t.onselectionchange=0,null===t.onselectionchange}catch(i){}finally{t.onselectionchange=n}return!1})(document),mt=!!gt;function bt(e,t){const n=function(e){const t={};function n(e,n){e.split(" ").forEach(e=>{t[e]=t[e]||[],t[e].unshift(n)})}function i(e,n){const i=t[e];if(!i)return;const r=i.indexOf(n);r<0||i.splice(r,1)}const r={on(e,t){if(2===arguments.length&&"string"==typeof e)n(e,t);else if(1===arguments.length&&"object"==typeof e)for(const i in e)n(i,e[i]);return r},off(e,n){2===arguments.length?i(e,n):1===arguments.length?t[e]=[]:Object.keys(t).forEach(e=>delete t[e])},notify(n,i,...o){const s=Array.from(arguments);let a,c,l;if(e?(c=n,a=e,l=s.slice(1)):(a=n,c=i,l=s.slice(2)),r.switchContext){c!==r.switchContext.events.shift()&&(r.switchContext=void 0)}const h=t[c];h&&h.every(e=>!1!==e.apply(a,l))}};return r}(t);e.on=n.on,e.off=n.off,e.notify=n.notify}function yt(e){return{x:void 0!==e.pageXOffset?e.pageXOffset:(e.document.documentElement||e.document.body.parentNode||e.document.body).scrollLeft,y:void 0!==e.pageYOffset?e.pageYOffset:(e.document.documentElement||e.document.body.parentNode||e.document.body).scrollTop}}class Ct{static findHost(e,t){return d(e,t)}constructor(e,t){this.setHost(e),this.range=t,this.isCursor=!0}getTags(e){return ue(this.host,this.range,e)}getTagNames(e){return ye(this.getTags(e))}getTagsByName(e){return fe(this.host,this.range,e)}getInnerTags(e){return me(this.range,e)}getContainedTags(e){return be(this.range,e)}getAncestorTags(e){return de(this.host,this.range,e)}isAtEnd(){return O(this.host,this.range.endContainer,this.range.endOffset)}isAtTextEnd(){return I(this.host,this.range.endContainer,this.range.endOffset)}isAtLastLine(){const e=this.win.document.createRange();e.selectNodeContents(this.host),e.collapse(!1);const t=wt(e,this.win),n=wt(this.range,this.win);return vt(t.bottom,n.bottom)}isAtFirstLine(){const e=this.win.document.createRange();e.selectNodeContents(this.host),e.collapse(!0);const t=wt(e,this.win),n=wt(this.range,this.win);return vt(t.top,n.top)}isAtBeginning(){return B(this.host,this.range.startContainer,this.range.startOffset)}insertBefore(e){if(a(e)&&(e=se(e)),$(e))return;let t=e=this.adoptElement(e);if(11===e.nodeType){const n=e.childNodes.length-1;t=e.childNodes[n]}this.range.insertNode(e),this.range.setStartAfter(t),this.range.setEndAfter(t),this.host.normalize()}insertAfter(e){if(a(e)&&(e=se(e)),$(e))return;e=this.adoptElement(e);const t=this.range.cloneRange();t.setStart(t.endContainer,t.endOffset),t.collapse(!0),t.insertNode(e),this.host.normalize()}setSelection(){this.setVisibleSelection()}setVisibleSelection(){if(this.win.document.activeElement!==this.host){const{x:e,y:t}=yt(this.win);this.win.scrollTo(e,t)}const e=g(this.win);e&&(e.removeAllRanges(),e.addRange(this.range))}before(){const e=this.range.cloneRange();return e.collapse(!0),e.setStartBefore(this.host),ce(e)}textBefore(){const e=this.range.cloneRange();return e.collapse(!0),e.setStartBefore(this.host),e.toString()}beforeHtml(){return oe(this.before())}after(){const e=this.range.cloneRange();return e.collapse(!1),e.setEndAfter(this.host),ce(e)}textAfter(){const e=this.range.cloneRange();return e.collapse(!1),e.setEndAfter(this.host),e.toString()}afterHtml(){return oe(this.after())}getBoundingClientRect(){return this.range.getBoundingClientRect()}getCoordinates(e="absolute"){const t=this.range.getBoundingClientRect();if("fixed"===e)return t;const{x:n,y:i}=yt(this.win);return{top:t.top+i,bottom:t.bottom+i,left:t.left+n,right:t.right+n,height:t.height,width:t.width}}moveBefore(e){if(this.updateHost(e),this.range.setStartBefore(e),this.range.setEndBefore(e),this.isSelection)return new Ct(this.host,this.range)}moveAfter(e){if(this.updateHost(e),this.range.setEndAfter(e),this.range.setStartAfter(e),this.isSelection)return new Ct(this.host,this.range)}moveAtBeginning(e=this.host){if(this.updateHost(e),this.range.selectNodeContents(e),this.range.collapse(!0),this.isSelection)return new Ct(this.host,this.range)}moveAtEnd(e=this.host){if(this.updateHost(e),this.range.selectNodeContents(e),this.range.collapse(!1),this.isSelection)return new Ct(this.host,this.range)}moveAtTextEnd(e){const t=F(e);if(t&&1===t.nodeType)return this.moveAtEnd(t)}setHost(e){e.jquery&&(e=e[0]),this.host=e;const t=e.ownerDocument;this.win=null!=e&&t&&t.defaultView||window}updateHost(e){const t=E(e);t||n("Can not set cursor outside of an editable block"),this.setHost(t)}retainVisibleSelection(e){this.save(),e(),this.restore(),this.setVisibleSelection()}save(){this.savedRangeInfo=j(this.range),this.savedRangeInfo.host=this.host}restore(){if(!this.savedRangeInfo)return void n("Could not restore selection");this.savedRangeInfo.host&&(this.host=this.savedRangeInfo.host);const e=K(this.host,this.savedRangeInfo);e?(this.range=e,this.savedRangeInfo=void 0):n("Could not restore selection range")}equals(e){return!!e&&(!!e.host&&(!!e.host.isEqualNode(this.host)&&(!!e.range&&!!w(e.range,this.range))))}createElement(e,t={}){const n=this.win.document.createElement(e);for(const i in t){const e=t[i];n.setAttribute(i,e)}return n}createTextNode(e){return this.win.document.createTextNode(e)}adoptElement(e){return ae(e,this.win.document)}triggerChange(){const e=new Event("formatEditable",{bubbles:!0,cancelable:!1});this.host.dispatchEvent(e)}}function wt(e,t){if(1!==e.startContainer.nodeType)return e.getBoundingClientRect();const n=t.document.createElement("span");n.setAttribute("doc-editable","unwrap"),e.insertNode(n);const i=n.getBoundingClientRect();return n.remove(),i}function vt(e,t){return e===t||Math.abs(e-t)<=2}const St={extractText(e,t=!0){let n="";return function(e,t,n){const i=new c(e);let r;for(;r=i.getNext();)3===r.nodeType&&""!==r.data?n(r.data):t&&1===r.nodeType&&"BR"===r.nodeName&&n("\n")}(e,t,e=>{n+=e}),n},highlightMatches(e,t,n=!0){if(!t||0===t.length)return;e.normalize();const i=new c(e);let r,o,s=0,a=0,l=t[s],h=[],u=l.id||l.startIndex;for(;r=i.getNext();){if(3!==r.nodeType||""===r.data){if(n&&1===r.nodeType&&"BR"===r.nodeName){a+=1;continue}continue}if(o=r,!o)continue;const e=o.data;let c=a+e.length;if(l.startIndex<c&&a<l.endIndex){const n=a<=l.startIndex,r=c>=l.endIndex;let d,f;n&&(u=l.id||l.startIndex),d=n?l.startIndex-a:0,f=r?l.endIndex-a-d:e.length-d;const g={element:o,text:e.substring(d,d+f),offset:d,length:f,isLastPortion:r,wordId:u};if(h.push(g),r){const e=this.wrapMatch(h,l.marker,l.title);e&&(i.replaceCurrent(e),c=a+g.length+g.offset,h=[],s+=1,s<t.length&&(l=t[s]))}}a=c}},wrapMatch(e,t,n){return e.map(e=>this.wrapPortion(e,t,n)).pop()},wrapPortion(e,t,n){const i=f();i.setStart(e.element,e.offset),i.setEnd(e.element,e.offset+e.length);const r=t.cloneNode(!0);if(r.setAttribute("data-word-id",String(e.wordId)),n&&r.setAttribute("title",n),i.surroundContents(r),r.nextSibling){const e=r.nextSibling;3===e.nodeType&&""===e.data&&e.remove()}return r}};function Et(e,t,n,i){if(!e||""===e)return[];if(i&&!function(e){try{return!!e&&e instanceof e.ownerDocument?.defaultView.HTMLElement}catch(t){return"object"==typeof e&&1===e.nodeType&&"object"==typeof e.style&&"object"==typeof e.ownerDocument}}(i))return[];if(!t?.length)return[];const r=("word"===n?Nt:Tt)(t);return[...e.matchAll(r)].map(e=>{let t,r;return"word"===n?(t=e.index+e[1].length,r=e[2]):(t=e.index,r=e[0]),{startIndex:t,endIndex:t+r.length,match:r,marker:i}})}function Tt(e=[]){const t=`(${e.map(e=>kt(e)).join("|")})`;return new RegExp(t,"g")}const xt="\\u0041-\\u005A\\u0061-\\u007A\\u0030-\\u0039\\u00AA\\u00B5\\u00BA\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u00FF\\u0100-\\u017F\\u0180-\\u024F";function Nt(e=[]){const t=e.map(e=>kt(e)),n=`([^${xt}]|^)(${t.join("|")})(?=[^${xt}]|$)`;return new RegExp(n,"g")}function kt(e){return String(e).replace(/([.*+?^=!:${}()|[\]/\\])/g,"\\$1")}const At={highlightText(e,t,n,i,r,o){if(this.hasHighlight(e,n))return;const s=St.extractText(e),a=`<span class="highlight-${i}"></span>`;let c=o;if(!c){const t=e.ownerDocument||("undefined"!=typeof document?document:null);c=t?.defaultView||void 0}if(c||(c="undefined"!=typeof window&&window.document?window:void 0),!c)throw new Error("Could not determine window object for highlightText");const l=At.createMarkerNode(a,i,c);if(!l)return;const h=function(e,t,n){return Et(e,[t],"text",n)}(s,t,l);if(h&&h.length){const t=h[0];return n&&(t.id=n),St.highlightMatches(e,h),r&&r.notify("change",e),t.startIndex}},highlightRange(e,t,n,i,r,o,s,a="comment"){this.hasHighlight(e,n)&&this.removeHighlight(e,n,o);if(""===St.extractText(e,!1))return-1;let c=s;if(!c){const t=e.ownerDocument||("undefined"!=typeof document?document:null);c=t?.defaultView||void 0}if(c||(c="undefined"!=typeof window&&window.document?window:void 0),!c)throw new Error("Could not determine window object for highlightRange");const l=this.createMarkerNode(`<span class="highlight-${a}"></span>`,a,c);if(!l)return-1;const h=i,u=r;return St.highlightMatches(e,[{startIndex:h,endIndex:u,match:t.substring(h,u),id:n,marker:l}],!1),o&&o.notify("change",e),h},updateHighlight(e,t,n,i){if(!document.documentElement.classList)return;const r=e.querySelectorAll(`[data-word-id="${t}"]`);for(const o of Array.from(r))i&&o.classList.remove(i),n&&o.classList.add(n)},removeHighlight(e,t,n){const i=e.querySelectorAll(`[data-word-id="${t}"]`);for(const r of Array.from(i))xe(r);e.normalize(),n&&n.notify("change",e)},hasHighlight:(e,t)=>!!e.querySelectorAll(`[data-word-id="${t}"]`).length,extractHighlightedRanges(e,t){let n="[data-word-id]";t&&(n+=`[data-highlight="${t}"]`);const i=e.querySelectorAll(n);if(!i.length)return;const r={};for(const s of Array.from(i)){const t=s.getAttribute("data-word-id");t&&!r[t]&&(r[t]=e.querySelectorAll(`[data-word-id="${t}"]`))}const o={};for(const s in r){const t=this.extractMarkerNodePosition(e,r[s]);t&&(o[s]=t)}return o},extractMarkerNodePosition(e,t){if(0===t.length)return;const n=f();t.length>1?(n.setStartBefore(t[0]),n.setEndAfter(t[t.length-1])):n.selectNode(t[0]);const i=C(n,e);return{start:i.start,end:i.end,text:i.text,nativeRange:n}},cleanupStaleMarkerNodes(e,t){const n=e.querySelectorAll(`span[data-highlight="${t}"]`);for(const i of Array.from(n))i.textContent&&i.textContent.length||i.remove()},createMarkerNode(e,t,n){let i=n||null;if(i||(i="undefined"!=typeof window&&window.document?window:null),!i||!i.document)throw new Error(`Window object with document is required. win: ${typeof n}, window: ${typeof window}`);const r=u(e,i);return r?(r.setAttribute("data-editable","ui-unwrap"),r.setAttribute("data-highlight",t),r):null}};class Rt extends Ct{constructor(e,t){super(e,t),delete this.isCursor,this.isSelection=!0}text(){return this.range.toString()}html(){return((e,t=window)=>{const n=t.document.createElement("div");return n.appendChild(e.cloneContents()),n.innerHTML})(this.range)}isAllSelected(){return B(this.host,this.range.startContainer,this.range.startOffset)&&I(this.host,this.range.endContainer,this.range.endOffset)}getTextRange(){return C(this.range,this.host)}toString(){return this.range.toString()}isWrappable(){return Se(this.range)}getRects(){return this.range.getClientRects()}link(e,n={}){e&&(n.href=e);const i=this.createElement(t.linkMarkup.name,t.linkMarkup.attribs);for(const t in n){const e=n[t];void 0!==e&&(null===e?i.removeAttribute(t):i.setAttribute(t,e))}t.linkMarkup.trim&&this.trimRange(),this.forceWrap(i)}trimRange(){const e=this.range.toString(),t=e.search(/\S|$/),n=e.search(/\S[\s]+$/),i=-1===n?0:e.length-(n+1),[r,o]=v({root:this.range.commonAncestorContainer,startContainer:this.range.startContainer,startOffset:this.range.startOffset,whitespacesOnTheLeft:t});this.range.setStart(r,o);const[s,a]=S({root:this.range.commonAncestorContainer,endContainer:this.range.endContainer,endOffset:this.range.endOffset,whitespacesOnTheRight:i});this.range.setEnd(s,a)}unlink(){this.removeFormatting(t.linkMarkup.name)}toggleLink(e,n={}){const i=this.getTagsByName(t.linkMarkup.name);if(i.length>=1){const e=i[0];this.isExactSelection(e,"visible")?this.unlink():this.expandTo(e)}else this.link(e,n)}highlightComment({highlightId:e,textRange:t}){At.highlightRange(this.host,t.text,e,t.start,t.end,void 0,this.win,"comment")}highlight({highlightId:e}){const t=this.textBefore(),n=this.text(),i=At.createMarkerNode('<span class="highlight-comment"></span>',"comment",this.win);if(!i)return;i.setAttribute("data-match",n);const r={startIndex:t.length,endIndex:t.length+n.length,match:n,marker:i};St.highlightMatches(this.host,[r])}toggle(e){if(Ve(this.host))return;if(this.range.collapsed)return;e=this.adoptElement(e);const t=ve(this.host,this.range,e);t&&(this.range=t,this.setVisibleSelection())}toggleCustom({tagName:e,attributes:t,trim:n=!1}){const i=this.createElement(e,t);n&&this.trimRange(),this.toggle(i)}makeCustom({tagName:e,attributes:t,trim:n=!1}){const i=this.createElement(e,t);n&&this.trimRange(),this.forceWrap(i)}makeBold(){const e=this.createElement(t.boldMarkup.name,t.boldMarkup.attribs);t.boldMarkup.trim&&this.trimRange(),this.forceWrap(e)}toggleBold(){const e=this.createElement(t.boldMarkup.name,t.boldMarkup.attribs);t.boldMarkup.trim&&this.trimRange(),this.toggle(e)}giveEmphasis(){const e=this.createElement(t.italicMarkup.name,t.italicMarkup.attribs);t.italicMarkup.trim&&this.trimRange(),this.forceWrap(e)}toggleEmphasis(){const e=this.createElement(t.italicMarkup.name,t.italicMarkup.attribs);t.italicMarkup.trim&&this.trimRange(),this.toggle(e)}makeUnderline(){const e=this.createElement(t.underlineMarkup.name,t.underlineMarkup.attribs);t.underlineMarkup.trim&&this.trimRange(),this.forceWrap(e)}toggleUnderline(){const e=this.createElement(t.underlineMarkup.name,t.underlineMarkup.attribs);t.underlineMarkup.trim&&this.trimRange(),this.toggle(e)}insertCharacter(e){const t=this.deleteContent(),n=t.createTextNode(e);return t.insertBefore(n),t.setVisibleSelection(),t}surround(e,t){this.range=Oe(this.host,this.range,e,t),this.setVisibleSelection()}removeSurround(e,t){this.range=Le(this.host,this.range,e),this.range=Le(this.host,this.range,t),this.setVisibleSelection()}removeChars(e=[]){for(let t=0;t<e.length;t++){const n=e[t];this.range=Le(this.host,this.range,n)}this.setVisibleSelection()}toggleSurround(e,t){this.containsString(e)&&this.containsString(t)?this.removeSurround(e,t):this.surround(e,t)}removeFormatting(e){const t=ke(this.host,this.range,e||null);t&&(this.range=t,this.setVisibleSelection())}deleteExactSurroundingTags(){const e=this.getAncestorTags().reverse();for(const t of e)if(this.isExactSelection(t,void 0)){t.remove();break}return new Rt(this.host,this.range)}deleteContainedTags(){return this.getContainedTags().forEach(e=>e.remove()),new Rt(this.host,this.range)}deleteContent(){return this.range.deleteContents(),new Ct(this.host,this.range)}expandTo(e){this.range=we(this.host,this.range,e),this.setVisibleSelection()}collapseAtBeginning(e){return this.range.collapse(!0),this.setVisibleSelection(),new Ct(this.host,this.range)}collapseAtEnd(e){return this.range.collapse(!1),this.setVisibleSelection(),new Ct(this.host,this.range)}forceWrap(e){if(Ve(this.host))return;if(this.range.collapsed)return;e=this.adoptElement(e);const t=Ee(this.host,this.range,e);t&&(this.range=t,this.setVisibleSelection())}isExactSelection(e,t){return Ce(this.range,e,"visible"===t)}containsString(e){return Me(this.range,e)}deleteCharacter(e){this.range=Le(this.host,this.range,e),this.setVisibleSelection()}}class Bt{constructor(e,t){this.host=e&&e.jquery?e[0]:e,this.range=t?.cloneRange(),this.isAnythingSelected=void 0!==t,this.isCursor=this.isAnythingSelected&&t.collapsed,this.isSelection=this.isAnythingSelected&&!this.isCursor}getCursor(){if(this.isCursor&&this.host&&this.range)return new Ct(this.host,this.range)}getSelection(){if(this.isSelection&&this.host&&this.range)return new Rt(this.host,this.range)}forceCursor(){if(!this.isSelection)return this.getCursor();const e=this.getSelection();return e?e.deleteContent():void 0}isDifferentFrom(e=new Bt){const t=this.range,n=e.range;return t&&n?!w(t,n):!(!t&&n)}}class Ot{constructor(e,t){this.dispatcher=e,this.win=t||window,this.selection=void 0,this.currentSelection=void 0,this.currentRange=void 0}syncSelection(){try{this.selection=g(this.win)}catch(e){return!1}return!0}getRangeContainer(){const e=this.syncSelection();if(this.selection?.rangeCount&&e)try{const e=this.selection.getRangeAt(0);if(e&&e.commonAncestorContainer){const t=E(e.commonAncestorContainer);if(t)return new Bt(t,e)}}catch(t){}return new Bt}getFreshRange(){return this.getRangeContainer()}getFreshSelection(){const e=this.getRangeContainer();return e.isCursor?e.getCursor():e.getSelection()}getSelection(){return this.currentSelection}forceCursor(){return this.getRangeContainer().forceCursor()}selectionChanged(){const e=this.getRangeContainer();if(e.isDifferentFrom(this.currentRange)){const t=this.currentSelection;this.currentRange=e,t&&(t.isCursor&&!this.currentRange.isCursor?this.dispatcher.notify("cursor",t.host):t.isSelection&&!this.currentRange.isSelection&&this.dispatcher.notify("selection",t.host)),this.currentRange.isCursor&&this.currentRange.host&&this.currentRange.range?(this.currentSelection=new Ct(this.currentRange.host,this.currentRange.range),this.dispatcher.notify("cursor",this.currentSelection.host,this.currentSelection)):this.currentRange.isSelection&&this.currentRange.host&&this.currentRange.range?(this.currentSelection=new Rt(this.currentRange.host,this.currentRange.range),this.dispatcher.notify("selection",this.currentSelection.host,this.currentSelection)):this.currentSelection=void 0}}}class Lt{constructor(e){bt(this),this.selectionWatcher=e,this.key=Lt.key}dispatchKeyEvent(e,t,n){switch(e.keyCode){case this.key.left:return this.notify(t,"left",e);case this.key.right:return this.notify(t,"right",e);case this.key.up:return this.notify(t,"up",e);case this.key.down:return this.notify(t,"down",e);case this.key.tab:return e.shiftKey?this.notify(t,"shiftTab",e):this.notify(t,"tab",e);case this.key.esc:return this.notify(t,"esc",e);case this.key.backspace:return this.preventContenteditableBug(t,e),this.notify(t,"backspace",e);case this.key.delete:return this.preventContenteditableBug(t,e),this.notify(t,"delete",e);case this.key.enter:return e.shiftKey?this.notify(t,"shiftEnter",e):this.notify(t,"enter",e);case this.key.ctrl:case this.key.shift:case this.key.alt:case 224:case 17:case 91:case 93:return;default:if(e.keyCode===this.key.b&&(e.ctrlKey||e.metaKey))return this.notify(t,"bold",e);if(e.keyCode===this.key.i&&(e.ctrlKey||e.metaKey))return this.notify(t,"italic",e);if(this.preventContenteditableBug(t,e),!n)return;if(!e.ctrlKey&&!e.metaKey)return this.notify(t,"character",e)}}preventContenteditableBug(e,t){if(!mt)return;if(t.ctrlKey||t.metaKey)return;const n=this.selectionWatcher.getFreshRange();if(!n.isSelection||!n.range)return;const i=Lt.getNodeToRemove(n.range,e);i&&i.remove()}static getNodeToRemove(e,t){if(0!==e.startOffset)return;let n=e.startContainer;if(3===n.nodeType){const e=n.parentNode;if(!e||1!==e.nodeType)return;n=e}if(n===t)return;const i=n.firstChild,r=n.lastChild;if(!i||!r)return;const o=f();if(o.setStartBefore(i),o.setEndAfter(r),a=e,(s=o).compareBoundaryPoints(Range.START_TO_START,a)<=0&&s.compareBoundaryPoints(Range.END_TO_END,a)>=0)return;var s,a;if(3===e.startContainer.nodeType){const t=[3,1];let i=n.firstChild;do{if(i&&-1!==t.indexOf(i.nodeType))break;i=i?i.nextSibling:null}while(i);if(i!==e.startContainer)return}const c=e.cloneRange();c.setStartBefore(n);return Lt.getNodeToRemove(c,t)||n}}Lt.key=Lt.prototype.key={left:37,up:38,right:39,down:40,tab:9,esc:27,backspace:8,delete:46,enter:13,shift:16,ctrl:17,alt:18,b:66,i:73};const Mt=e=>Array.isArray(e)&&2===e.length,It=e=>/^[\u00AB\u00BB\u201C\u201D\u201E\u0022]$/.test(e),Dt=e=>/^[\u2018\u2019\u2039\u203A\u201A\u0027]$/.test(e),Ht=e=>/^[\u2019\u0027]$/.test(e),Ft=e=>/\s|[>\-–—]/.test(e),$t=(e,t,n)=>{const i=e?.startContainer;if(!i||3!==i.nodeType)return null;const r=i,o=r.nodeValue;if(!o)return null;const s=`${o.substring(0,t)}${n}${o.substring(t+1)}`,a=document.createTextNode(s);return r.replaceWith(a),a},Vt=(e,t,n,i,r)=>{const o=Dt(n);if(!It(n)&&!o)return;const{quotes:s,singleQuotes:a}=t;if(n===s[0]||n===s[1]||n===a[0]||n===a[1])return;const c=e.startOffset,l=e.startContainer.textContent;if(!l)return;const h=[...l];let u=null;if(o&&((d=h)[f=c-2]&&It(d[f])))u=$t(e,c-1,a[0]);else if(((e,t)=>!!e[t]&&!Ft(e[t]))(h,c-2)){if(o){if(((e,t)=>{return!!e[t]&&(n=e[t],!/^\s$/.test(n));var n})(h,c))return;if(!((e,t,n)=>{if(t<=0)return!1;for(let i=t-1;i>=0;i--)if(Dt(e[i])&&!Ht(n)&&!Ht(e[i]))return e[i]===n;return!1})(h,c,a[0]))return}const t=o?a[1]:s[1];u=$t(e,c-1,t)}else if(((e,t)=>t<0||Ft(e[t]))(h,c-2)){const t=o?a[0]:s[0];u=$t(e,c-1,t)}var d,f;if(!u)return;const g=i.ownerDocument.defaultView;if(!g)return;const p=g.getSelection();p&&p.collapse(u,r??c)};class Pt{constructor(e){const t=e.win;bt(this,e),this.document=t.document,this.config=e.config,this.editable=e,this.editableSelector=e.editableSelector,this.selectionWatcher=new Ot(this,t),this.keyboard=new Lt(this.selectionWatcher),this.activeListeners=[],this.setup(),this.getEditableBlockByEvent=t=>{const n=t.target;return n?d(n,e.editableSelector):void 0}}setupDocumentListener(e,t,n=!1){const i={event:e,listener:t.bind(this),capture:n};return this.activeListeners.push(i),this.document.addEventListener(e,i.listener,n),this}setup(){this.setupKeyboardEvents(),this.setupEventListeners()}unload(){this.off();for(const e of this.activeListeners)this.document.removeEventListener(e.event,e.listener,e.capture);this.activeListeners.length=0}suspend(){if(!this.suspended){this.suspended=!0;for(const e of this.activeListeners)this.document.removeEventListener(e.event,e.listener,e.capture);this.activeListeners.length=0}}continue(){this.suspended&&(this.suspended=!1,this.setupEventListeners())}setupEventListeners(){this.setupElementListeners(),this.setupKeydownListener(),pt?this.setupSelectionChangeListeners():this.setupSelectionChangeFallbackListeners()}setupElementListeners(){const e={offset:void 0};this.setupDocumentListener("focus",function(e){const n=this.getEditableBlockByEvent(e);if(!n)return;const i=e.target;i&&i.getAttribute(t.pastingAttribute)||(this.selectionWatcher.syncSelection(),this.notify("focus",n))},!0).setupDocumentListener("blur",function(e){const n=this.getEditableBlockByEvent(e);n&&(n.getAttribute(t.pastingAttribute)||this.notify("blur",n))},!0).setupDocumentListener("copy",function(e){const t=this.getEditableBlockByEvent(e);if(!t)return;const n=this.selectionWatcher.getFreshSelection();n&&n.isSelection&&this.notify("clipboard",t,"copy",n)}).setupDocumentListener("cut",function(e){const t=this.getEditableBlockByEvent(e);if(!t)return;const n=this.selectionWatcher.getFreshSelection();n&&n.isSelection&&this.notify("clipboard",t,"cut",n)}).setupDocumentListener("paste",function(e){const t=this.getEditableBlockByEvent(e);if(!t)return;const n=e;n.preventDefault();const i=this.selectionWatcher.getFreshSelection();if(!i||!n.clipboardData)return;const r=n.clipboardData.getData("text/html")||n.clipboardData.getData("text/plain"),{blocks:o,cursor:s}=ht(t,i,r);if(o.length){const e=n.target;e&&(a=e.innerText,/\S+\s{1}$/.test(a))&&s.retainVisibleSelection(()=>{t.innerHTML=function(e,t,n){if(!e)return"";const i=(e=`${e}`).lastIndexOf(t);return-1===i?e:`${e.slice(0,i)}${n}${e.slice(i+t.length)}`}(t.innerHTML,"&nbsp;"," ")}),this.notify("paste",t,o,s),this.notify("change",t)}else s.setVisibleSelection();var a}).setupDocumentListener("input",function(t){const n=this.getEditableBlockByEvent(t);if(!n)return;const i=t.target;if(i&&((e,t)=>{const{smartQuotes:n,quotes:i,singleQuotes:r}=e;return!!n&&Mt(i)&&Mt(r)&&t.isContentEditable})(this.config,i)){const n=this.selectionWatcher.getFreshSelection();if(!n||!n.range)return;e.offset=n.range.startOffset;const r=t,o=this.config.quotes||{quotes:[],singleQuotes:[]};setTimeout(()=>{r.data&&Vt(n.range,o,r.data,i,e.offset)},300)}this.notify("change",n)}).setupDocumentListener("formatEditable",function(e){const t=this.getEditableBlockByEvent(e);t&&this.notify("change",t)})}dispatchSwitchEvent(e,t,n){if(e.altKey||e.ctrlKey||e.metaKey||e.shiftKey)return;const i=this.selectionWatcher.getFreshSelection();i&&!i.isSelection&&(this.switchContext?this.switchContext.events=["cursor"]:this.switchContext={positionX:i.getBoundingClientRect().left,events:["cursor"]},"up"===n&&i.isAtFirstLine()&&(e.preventDefault(),e.stopPropagation(),this.switchContext.events=["switch","blur","focus","cursor"],this.notify("switch",t,n,i)),"down"===n&&i.isAtLastLine()&&(e.preventDefault(),e.stopPropagation(),this.switchContext.events=["switch","blur","focus","cursor"],this.notify("switch",t,n,i)))}setupKeydownListener(){this.setupDocumentListener("keydown",function(e){const t=this.getEditableBlockByEvent(e);if(!t)return;const n=e;this.keyboard.dispatchKeyEvent(n,t,!1)},!0)}setupKeyboardEvents(){const e=this;this.keyboard.on("up",function(t){e.dispatchSwitchEvent(t,this,"up")}).on("down",function(t){e.dispatchSwitchEvent(t,this,"down")}).on("backspace",function(t){const n=e.selectionWatcher.getFreshRange();if(!n.isCursor)return;const i=n.getCursor();i&&i.isAtBeginning()&&(t.preventDefault(),t.stopPropagation(),e.notify("merge",this,"before",i))}).on("delete",function(t){const n=e.selectionWatcher.getFreshRange();if(!n.isCursor)return;const i=n.getCursor();i&&i.isAtTextEnd()&&(t.preventDefault(),t.stopPropagation(),e.notify("merge",this,"after",i))}).on("enter",function(t){const n=this;t.preventDefault(),t.stopPropagation();const i=e.selectionWatcher.getFreshRange().forceCursor();if(i)if(i.isAtTextEnd())e.notify("insert",n,"after",i);else if(i.isAtBeginning())e.notify("insert",n,"before",i);else{const t=i.before(),r=i.after();e.notify("split",n,oe(t),oe(r),i)}}).on("shiftEnter",function(t){const n=this;t.preventDefault(),t.stopPropagation();const i=e.selectionWatcher.forceCursor();i&&e.notify("newline",n,i)}).on("bold",function(t){t.preventDefault(),t.stopPropagation();const n=e.selectionWatcher.getFreshSelection();n&&n.isSelection&&e.notify("toggleBold",n)}).on("italic",function(t){t.preventDefault(),t.stopPropagation();const n=e.selectionWatcher.getFreshSelection();n&&n.isSelection&&e.notify("toggleEmphasis",n)}).on("character",function(t){e.notify("change",this)})}setupSelectionChangeListeners(){let e=!1,t=!1;const n=this.selectionWatcher;this.setupDocumentListener("selectionchange",i=>{let r=!1,o=this.selectionWatcher.getFreshSelection();o||(n.selectionChanged(),r=!0,o=this.selectionWatcher.getSelection()),o&&o.isSelection&&o.isAtBeginning()&&o.isAtEnd()?this.notify("selectToBoundary",o.host,i,"both"):o&&o.isSelection&&o.isAtBeginning()?this.notify("selectToBoundary",o.host,i,"start"):o&&o.isSelection&&o.isAtEnd()&&this.notify("selectToBoundary",o.host,i,"end"),t?e=!0:r||n.selectionChanged()}),this.setupDocumentListener("mousedown",function(i){this.getEditableBlockByEvent(i)&&(!1===this.config.mouseMoveSelectionChanges&&(t=!0,setTimeout(()=>n.selectionChanged(),0)),this.document.addEventListener("mouseup",()=>{t=!1,e&&(e=!1,n.selectionChanged())},{capture:!0,once:!0}))})}setupSelectionChangeFallbackListeners(){const e=e=>{const t=this.selectionWatcher.getFreshSelection();t&&t.isSelection&&t.isAtBeginning()&&t.isAtEnd()?this.notify("selectToBoundary",t.host,e,"both"):t&&t.isSelection&&t.isAtBeginning()?this.notify("selectToBoundary",t.host,e,"start"):t&&t.isSelection&&t.isAtEnd()&&this.notify("selectToBoundary",t.host,e,"end")};this.setupDocumentListener("mouseup",t=>{setTimeout(()=>{this.selectionWatcher.selectionChanged(),e(t)},0)}),this.setupDocumentListener("keyup",t=>{this.getEditableBlockByEvent(t)&&(this.selectionWatcher.selectionChanged(),e(t))})}}function qt(e,...t){const n={...e};for(const i of t)if(i&&"object"==typeof i)for(const e in i){if(!Object.prototype.hasOwnProperty.call(i,e))continue;const t=i[e],r=n[e];t&&"object"==typeof t&&!Array.isArray(t)&&r&&"object"==typeof r&&!Array.isArray(r)?n[e]=qt({},r,t):n[e]=t}return n}class Wt{constructor(e){this.spellcheckService=e}check(e,t){if(!e)return t(null);const n=ne(e);this.spellcheckService(n,e=>e&&e.length>0?t(null,e):t(null))}}const _t={A0:"no-break space",2e3:"en quad",2001:"em quad",2002:"en space",2003:"em space",2004:"three-per-em space",2005:"four-per-em space",2006:"six-per-em space",2007:"figure space",2008:"punctuation space",2009:"thin space","200A":"hair space","202F":"narrow no-break space","205F":"medium mathematical space",3e3:"ideographic space"},jt=new RegExp("[\\u2000-\\u200A\\u202F\\u205F\\u3000]","g");class Kt{constructor(e){this.marker=e}findMatches(e){if(!e)return;return[...e.matchAll(jt)].map(e=>this.prepareMatch(e))}prepareMatch(e){const t=e.index,n=`${e[0].charCodeAt(0).toString(16).toUpperCase()}`;const i=_t[n]||"unknown whitespace";return{startIndex:t,endIndex:t+e.length,match:e[0],title:`${i} (\\u${n})`,marker:this.marker}}}class Ut{constructor(){this.matches=[]}addMatches(e){e?.length&&(this.matches=function(e,t){let n;const i=e.length,r=t.length;let o=-1;const s=[],a={a1:e,i1:0,a2:t,i2:0};for(;a.i1<i||a.i2<r;)n=zt(a),n&&n.startIndex>=o?(s.push(n),o=n.endIndex):n&&(o=n.endIndex);return s}(this.matches,e))}}function zt(e){const t=e.i1,n=e.i2,i=e.a1[t],r=e.a2[n];return i&&r&&i.startIndex<r.startIndex?(e.i1=t+1,i):i&&r?(e.i2=n+1,r):i?(e.i1=t+1,i):r?(e.i2=n+1,r):void 0}class Qt{constructor(e,t,n){this.editable=e,this.win=e.win,this.focusedEditableHost=void 0,this.currentlyCheckedEditableHost=void 0,this.timeout={};this.config=qt({},{checkOnInit:!1,checkOnFocus:!1,checkOnChange:!0,throttle:1e3,removeOnCorrection:!0,spellcheck:{marker:'<span class="highlight-spellcheck"></span>',throttle:1e3,spellcheckService:function(){}},whitespace:{marker:'<span class="highlight-whitespace"></span>'}},t);const i=this.config.spellcheck.spellcheckService,r=this.config.spellcheck.marker,o=this.config.whitespace.marker,s=At.createMarkerNode(o,"whitespace",this.win),a=At.createMarkerNode(r,"spellcheck",this.win);if(!s||!a)throw new Error("Failed to create marker nodes");this.spellcheckMarkerNode=a,this.spellcheckService=new Wt(i),this.whitespace=new Kt(s),this.setupListeners()}setupListeners(){this.config.checkOnFocus&&(this.editable.on("focus",e=>this.onFocus(e)),this.editable.on("blur",e=>this.onBlur(e))),(this.config.checkOnChange||this.config.removeOnCorrection)&&this.editable.on("change",e=>this.onChange(e)),this.config.checkOnInit&&this.editable.on("init",e=>this.onInit(e))}onInit(e){this.highlight(e)}onFocus(e){this.focusedEditableHost!==e&&(this.focusedEditableHost=e,this.editableHasChanged(e,void 0))}onBlur(e){this.focusedEditableHost===e&&(this.focusedEditableHost=void 0)}onChange(e){this.config.checkOnChange&&this.editableHasChanged(e,this.config.throttle),this.config.removeOnCorrection&&this.removeHighlightsAtCursor(e)}editableHasChanged(e,t){this.timeout.id&&this.timeout.editableHost===e&&clearTimeout(this.timeout.id);const n=setTimeout(()=>{this.highlight(e),this.timeout={}},t||0);this.timeout={id:n,editableHost:e}}highlight(e){const t=St.extractText(e);this.spellcheckService.check(t,(t,n)=>{if(t||!e.isConnected)return;const i=St.extractText(e),r=new Ut;if(n&&n.length>0){const e=function(e,t,n){return Et(e,t,"word",n)}(i,n,this.spellcheckMarkerNode);r.addMatches(e)}const o=this.whitespace.findMatches(i);if(o){const e=o.map(e=>({startIndex:e.startIndex||0,endIndex:e.endIndex,match:e.match,marker:e.marker}));r.addMatches(e)}this.safeHighlightMatches(e,r.matches)})}safeHighlightMatches(e,t){const n=this.editable.getSelection(e);n?n.retainVisibleSelection(()=>{this.highlightMatches(e,t)}):this.highlightMatches(e,t),this.editable.dispatcher&&this.editable.dispatcher.notify("spellcheckUpdated",e)}highlightMatches(e,t){this.removeHighlights(e),t&&t.length>0&&St.highlightMatches(e,t)}removeHighlights(e){const t=h(e,this.win.document);if(t)for(const n of l('[data-highlight="spellcheck"], [data-highlight="whitespace"]',this.win.document,t))xe(n)}removeHighlightsAtCursor(e){const t=h(e,this.win.document);if(!t)return;e=t;const n=this.editable.getSelection(e);if(n&&n.isCursor){let i,r=n.range.startContainer;3===r.nodeType&&(r=r.parentNode);do{if(r===e)return;const t=r.getAttribute("data-highlight");if("spellcheck"===t||"whitespace"===t){i=r.getAttribute("data-word-id");break}}while(r=r.parentNode);i&&n.retainVisibleSelection(()=>{for(const e of l(`[data-word-id="${i}"]`,this.win.document,t))xe(e)})}}}function Xt(...e){if(!1===t.log)return;if(!global.console)return;const n=1===e.length?e[0]:e;1!==e.length&&"trace"===n[n.length-1]&&(n.pop(),console.trace&&console.trace()),console.log(n)}function Jt(e){const t=function(e){const t=e.win.document;return{focus(e){x(e)&&e.appendChild(t.createTextNode("\ufeff"))},blur(e){t.activeElement!==e&&ie(e)},selection(e,t){Xt(t?"Default selection behavior":"Default selection empty behavior")},cursor(e,t){Xt("Default cursor behavior")},newline(e,n){if(n.isAtTextEnd()){const e=t.createElement("br");n.insertBefore(e);const i=e.nextSibling;3===i?.nodeType&&"\ufeff"===i.textContent?.[0]||n.insertAfter(t.createTextNode("\ufeff"))}else n.insertBefore(t.createElement("br"));n.setVisibleSelection()},insert(t,n,i){const r=t.cloneNode(!1);r.id&&r.removeAttribute("id"),"before"===n?t.parentNode?.insertBefore(r,t):t.parentNode?.insertBefore(r,t.nextSibling),e.createCursorAtEnd(r)?.setVisibleSelection()},split(e,t,n,i){const r=se(t),o=e.cloneNode(!1);o.appendChild(r);const s=e.parentNode;s&&s.insertBefore(o,e),e.innerHTML=n,ee(o),ee(e),i.setVisibleSelection()},merge(n,i,r){const o="before"===i?n.previousElementSibling:n.nextElementSibling;if(!o)return;const s=re(o,!1),a=re(n,!1),c=t.createElement("div");c.innerHTML=s;const l=c.textContent?.length||0;c.innerHTML=a;const h=c.textContent?.length||0,u="before"===i?s+a:a+s;n.innerHTML=u,o.remove();const d="before"===i?l:h;e.createCursorAtCharacterOffset({element:n,offset:d})},empty(e){Xt("Default empty behavior")},switch(t,n,i){switch(n){case"before":const n=t.previousElementSibling;if(n){const t=e.createCursorAtEnd(n);t&&t.setVisibleSelection()}break;case"after":const i=t.nextElementSibling;if(i){const t=e.createCursorAtBeginning(i);t&&t.setVisibleSelection()}}},move(e,t,n){Xt("Default move behavior")},paste(t,n,i){if(i.insertBefore(n[0]),n.length<=1)return void i.setVisibleSelection();const r=t.parentNode;if(!r)return;let o=t;n.slice(1).forEach(e=>{const n=t.cloneNode(!1);n.id&&n.removeAttribute("id");const i=se(e);n.appendChild(i),r.insertBefore(n,o.nextSibling),o=n});const s=e.createCursorAtEnd(o);s&&s.setVisibleSelection()},clipboard(e,t,n){Xt("Default clipboard behavior")},toggleBold(e){e.toggleBold()},toggleEmphasis(e){e.toggleEmphasis()}}}(e);return{focus(e){t.focus(e)},blur(e){t.blur(e)},selection(e,n){t.selection(e,n)},cursor(e,n){t.cursor(e,n)},newline(e,n){t.newline(e,n)},split(e,n,i,r){t.split(e,n,i,r)},insert(e,n,i){t.insert(e,n,i)},merge(e,n,i){t.merge(e,n,i)},empty(e){t.empty(e)},switch(e,n,i){t.switch(e,n,i)},move(e,n,i){t.move(e,n,i)},clipboard(e,n,i){t.clipboard(e,n,i)},paste(e,n,i){t.paste(e,n,i)},toggleBold(e){t.toggleBold(e)},toggleEmphasis(e){t.toggleEmphasis(e)}}}function Yt(e){return[...new c(e,"getNextTextNode")]}function Gt({textNodes:e,absOffset:t}){let n,i=0,r=0;for(let o=0;o<e.length;o++){const s=e[o],a=s.textContent?.length||0;if(t<=i+a){n=s,r=t-i;break}i+=a}return{node:n,relativeOffset:r}}function Zt({host:e,requiredOnFirstLine:t,requiredOnLastLine:n,positionX:i}){const r=e.ownerDocument.createRange();let o;r.selectNodeContents(e);try{o=r.getBoundingClientRect()}catch(p){o=e.getBoundingClientRect()||{left:0,top:0,right:0,bottom:0,width:0,height:0,x:0,y:0,toJSON:()=>({})}}const s=Yt(e).reduce((e,t)=>e+(t.textContent?.length||0),0);const a=Yt(e);if(0===s)return{wasFound:!1};const c={currentOffset:Math.floor(s/2),leftLimit:0,rightLimit:s};let l=c.currentOffset,h=0,u=20;for(;c.leftLimit<c.rightLimit&&u>0;){u-=1,l=c.currentOffset;const e=nn({textNodes:a,offset:c.currentOffset});let r;try{r=e.getBoundingClientRect()}catch(p){r={left:0,top:0,right:0,bottom:0,width:0,height:0,x:0,y:0,toJSON:()=>({})}}h=Math.abs(r.left-i),t&&o.top!==r.top?en(c):n&&o.bottom!==r.bottom?tn(c):i<r.left?en(c):tn(c)}const d=nn({textNodes:a,offset:c.currentOffset});let f;try{f=d.getBoundingClientRect()}catch(p){f={left:0,top:0,right:0,bottom:0,width:0,height:0,x:0,y:0,toJSON:()=>({})}}const g=Math.abs(f.left-i);return g<h&&(h=g,l=c.currentOffset),{distance:h,offset:l,wasFound:!0}}function en(e){e.rightLimit=e.currentOffset,e.currentOffset=Math.floor((e.currentOffset+e.leftLimit)/2)}function tn(e){e.leftLimit=e.currentOffset,e.currentOffset=Math.ceil((e.currentOffset+e.rightLimit)/2)}function nn({textNodes:e,offset:t}){const{node:n,relativeOffset:i}=Gt({textNodes:e,absOffset:t});if(!n)throw new Error("Could not find text node for offset");const r=n.ownerDocument.createRange();return r.setStart(n,i),r.collapse(!0),r}class rn{constructor(e){const n={window:window,defaultBehavior:!0,mouseMoveSelectionChanges:!1,browserSpellcheck:!0};this.config=Object.assign(n,e),this.win=this.config.window,this.editableSelector=`.${t.editableClass}`,this.dispatcher=new Pt(this),!0===this.config.defaultBehavior&&this.dispatcher.on(Jt(this))}static getGlobalConfig(){return t}static globalConfig(e){Object.assign(t,e),lt(t)}add(e,t){return this.enable(e,t),this}remove(e){const n=l(e,this.win.document);this.disable(n);for(const i of n)i.classList.remove(t.editableDisabledClass);return this}disable(e){const n=l(e||`.${t.editableClass}`,this.win.document);for(const t of n)$e(t);return this}enable(e,n){const i="boolean"==typeof n?{normalize:n}:n??{},{normalize:r=!1,plainText:o=!1}=i,s=this.config.browserSpellcheck,a=l(e||`.${t.editableDisabledClass}`,this.win.document);for(const t of a)Fe(t,{normalize:r,plainText:o,shouldSpellcheck:s}),this.dispatcher.notify("init",t);return this}suspend(e){const n=l(e||`.${t.editableClass}`,this.win.document);for(const t of n)t.removeAttribute("contenteditable");return this.dispatcher.suspend(),this}continue(e){const n=l(e||`.${t.editableClass}`,this.win.document);for(const t of n)t.setAttribute("contenteditable","true");return this.dispatcher.continue(),this}createCursor(e,t="beginning"){const i=Ct.findHost(e,this.editableSelector);if(!i)return;const r=f(this.win);return"beginning"===t||"end"===t?(r.selectNodeContents(e),r.collapse("beginning"===t)):e!==i?"before"===t?(r.setStartBefore(e),r.setEndBefore(e)):"after"===t&&(r.setStartAfter(e),r.setEndAfter(e)):n("EditableJS: cannot create cursor outside of an editable block."),new Ct(i,r)}createCursorAtCharacterOffset({element:e,offset:t}){const n=Yt(e),{node:i,relativeOffset:r}=Gt({textNodes:n,absOffset:t});if(!i)throw new Error("Could not find text node for offset");const o=f(this.win);o.setStart(i,r),o.collapse(!0);const s=Ct.findHost(e,this.editableSelector);if(!s)throw new Error("No editable host found");const a=new Ct(s,o);return a.setVisibleSelection(),a}createCursorAtBeginning(e){return this.createCursor(e,"beginning")}createCursorAtEnd(e){return this.createCursor(e,"end")}createCursorBefore(e){return this.createCursor(e,"before")}createCursorAfter(e){return this.createCursor(e,"after")}getContent(e){return re(e)}appendTo(e,t){const n=ae(e,this.win.document),i=this.createCursor(n,"end");if(!i)throw new Error("Could not create cursor");return i.insertAfter("string"==typeof t?se(t):t),i}prependTo(e,t){const n=ae(e,this.win.document),i=this.createCursor(n,"beginning");if(!i)throw new Error("Could not create cursor");return i.insertBefore("string"==typeof t?se(t):t),i}getSelection(e){const t=this.dispatcher.selectionWatcher.getFreshSelection();if(!e||!t)return t;const n=t.range;return e?.isConnected&&((e,t)=>{const n=document.createRange();n.selectNodeContents(e);const i=t.compareBoundaryPoints(Range.START_TO_START,n),r=t.compareBoundaryPoints(Range.END_TO_END,n);return i>=0&&r<=0})(e,n)?t:void 0}setupHighlighting(e){return this.highlighting=new Qt(this,e,void 0),this}setupSpellcheck(e){let t;return e.markerNode&&(t=e.markerNode.outerHTML),this.setupHighlighting({throttle:e.throttle,spellcheck:{marker:t,spellcheckService:e.spellcheckService}}),this.spellcheck={checkSpelling:e=>{this.highlighting?.highlight(e)}},this}highlight({editableHost:e,text:t,highlightId:i,textRange:r,raiseEvents:o,type:s="comment"}){if(!r){return At.highlightText(e,t,i,s,o?this.dispatcher:void 0,this.win)||-1}return"number"!=typeof r.start||"number"!=typeof r.end?(n("Error in Editable.highlight: You passed a textRange object with invalid keys. Expected shape: { start: Number, end: Number }"),-1):r.start===r.end?(n("Error in Editable.highlight: You passed a textRange object with equal start and end offsets, which is considered a cursor and therefore unfit to create a highlight."),-1):At.highlightRange(e,t,i,r.start,r.end,o?this.dispatcher:void 0,this.win,s)}getHighlightPositions({editableHost:e,type:t}){const n=At.extractHighlightedRanges(e,t);if(!n)return{};const i={};for(const r in n){const{start:e,end:t,text:o}=n[r];i[r]={start:e,end:t,text:o}}return i}removeHighlight({editableHost:e,highlightId:t,raiseEvents:n}){At.removeHighlight(e,t,n?this.dispatcher:void 0)}decorateHighlight({editableHost:e,highlightId:t,addCssClass:n,removeCssClass:i}){At.updateHighlight(e,t,n,i)}on(e,t){return this.dispatcher.on(e,t),this}off(...e){return this.dispatcher.off.apply(this.dispatcher,e),this}unload(){return this.dispatcher.unload(),this}findClosestCursorOffset({element:e,origCoordinates:t,requiredOnFirstLine:n=!1,requiredOnLastLine:i=!1}){return Zt({host:e,requiredOnFirstLine:n,requiredOnLastLine:i,positionX:this.dispatcher.switchContext&&void 0!==this.dispatcher.switchContext.positionX?this.dispatcher.switchContext.positionX:t.left})}}rn.parser=V,rn.content=De;["focus","blur","flow","selection","cursor","newline","insert","split","merge","empty","change","switch","move","clipboard","paste","spellcheckUpdated","selectToBoundary"].forEach(e=>{rn.prototype[e]=function(t){return this.on(e,t)}}),e.Editable=rn,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
2
+ //# sourceMappingURL=editable.umd.cjs.map