UNPKG

@veltdev/sdk

Version:

Velt is an SDK to add collaborative features to your product within minutes. Example: Comments like Figma, Frame.io, Google docs or sheets, Recording like Loom, Huddles like Slack and much more.

2 lines (1 loc) 1.11 kB
import{Ee as h,Wd as c}from"./chunk-GR3NESUB.js";var d=(t,r)=>{try{let e=l(t),i=[],n=[];return e.forEach(o=>{o?.parentElement?.closest(h.TAGS.SNIPPYLY_TEXT_HIGHLIGHT)?o?.parentElement?.normalize():n.push(o)}),n.forEach(o=>{let s=a(o,r);s&&i.push(s)}),i}catch(e){return c.catch("Error in highlighter highlightRange: ",e),[]}},l=t=>{try{if(t.collapsed)return[];let r=t.commonAncestorContainer;if(t.commonAncestorContainer.nodeType!==Node.ELEMENT_NODE&&(r=t.commonAncestorContainer.parentElement),!r)return[];let e=[],i=r.ownerDocument.createNodeIterator(r,NodeFilter.SHOW_TEXT),n,o=!1;for(;n=i.nextNode();)if(t.intersectsNode(n)){let s=n?.length;t.startContainer===n&&t.startOffset>0&&(n.splitText(t.startOffset),o=!0),t.endContainer===n&&t.endOffset<s&&n.splitText(t.endOffset),e.push(n)}return o&&e.shift(),e}catch(r){return c.catch("Error in highlighter getTextNodesInRange: ",r),[]}},a=(t,r)=>{try{let e=document.createElement(r||h.TAGS.SNIPPYLY_TEXT_HIGHLIGHT);return t.parentElement?.replaceChild(e,t),e.appendChild(t),e}catch(e){return c.catch("Error in highlighter highlightNode: ",e),null}};export{d as a};