UNPKG

fast-selector

Version:

Lib agnóstica, motor de seleção, sem dependência em tempo de execução, responsável por seleção de texto

3 lines 23.1 kB
/*! selector v0.9.9 */ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Highlighter=t():e.Highlighter=t()}(window,(function(){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=8)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=n(11);t.ID_DIVISION=";",t.LOCAL_STORE_KEY="selection",t.STYLESHEET_ID="selection-style",t.WRAP_TAG="comp",t.DATASET_IDENTIFIER="selection-id",t.DATASET_IDENTIFIER_EXTRA="selection-id-extra",t.DATASET_SPLIT_TYPE="selection-split-type",t.CAMEL_DATASET_IDENTIFIER=o.default(t.DATASET_IDENTIFIER),t.CAMEL_DATASET_IDENTIFIER_EXTRA=o.default(t.DATASET_IDENTIFIER_EXTRA),t.CAMEL_DATASET_SPLIT_TYPE=o.default(t.DATASET_SPLIT_TYPE),t.DEFAULT_OPTIONS={$root:window.document.documentElement,exceptSelectors:null,style:{className:"selection-purple"}},t.STYLESHEET_TEXT="\n ."+t.DEFAULT_OPTIONS.style.className+" {\n background: #a119e0;\n cursor: pointer;\n }\n ."+t.DEFAULT_OPTIONS.style.className+":hover {\n background: #f7aaaa;\n }\n"},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),function(e){e.none="none",e.head="head",e.tail="tail",e.both="both"}(t.SplitType||(t.SplitType={})),function(e){e.DOM_TYPE_ERROR="[DOM] Receive wrong node type.",e.DOM_SELECTION_EMPTY="[DOM] The selection contains no dom node, may be you except them.",e.RANGE_INVALID="[RANGE] Got invalid dom range, can't convert to a valid selection range.",e.RANGE_NODE_INVALID="[RANGE] Start or end node isn't a text node, it may occur an error.",e.DB_ID_DUPLICATE_ERROR="[STORE] Unique id conflict.",e.CACHE_SET_ERROR="[CACHE] Cache.data can't be set manually, please use .save().",e.SOURCE_TYPE_ERROR="[SOURCE] Object isn't a selection source instance.",e.SELECTION_RANGE_FROZEN="[SELECTION_RANGE] A selection range must be frozen before render.",e.SELECTION_SOURCE_NONE_RENDER="[SELECTION_SOURCE] This highliselectionght source isn't rendered. May be the exception skips it or the dom structure has changed."}(t.ERROR||(t.ERROR={})),function(e){e.CREATE="selection:create",e.REMOVE="selection:remove",e.MODIFY="selection:modify",e.HOVER="selection:hover",e.HOVER_OUT="selection:hover-out",e.CLICK="selection:click",e.SELECT="selection:select",e.UNSELECT="selection:unselect",e.RELEASE="selection:release"}(t.EventType||(t.EventType={})),function(e){e.text="text",e.span="span"}(t.SelectedNodeType||(t.SelectedNodeType={}))},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=n(0);t.isSelectionWrapNode=function(e){return!!e.dataset&&!!e.dataset[o.CAMEL_DATASET_IDENTIFIER]},t.getSelectionId=function(e){return t.isSelectionWrapNode(e)?e.dataset[o.CAMEL_DATASET_IDENTIFIER]:""},t.getSelectionsByRoot=function(e){Array.isArray(e)||(e=[e]);for(var t=[],n=0;n<e.length;n++){var r=e[n].querySelectorAll(o.WRAP_TAG+"[data-"+o.DATASET_IDENTIFIER+"]");t.concat(r)}return t},t.getSelectionById=function(e,t){for(var n=[],r=new RegExp("("+t+"\\"+o.ID_DIVISION+"|\\"+o.ID_DIVISION+"?"+t+"$)"),i=e.querySelectorAll(o.WRAP_TAG+"[data-"+o.DATASET_IDENTIFIER+"]"),a=0;a<i.length;a++){var s=i[a];if(s.dataset[o.CAMEL_DATASET_IDENTIFIER]!==t){var l=s.dataset[o.CAMEL_DATASET_IDENTIFIER_EXTRA];r.test(l)&&n.push(s)}else n.push(s)}return n},t.forEach=function(e,t){for(var n=0;n<e.length;n++)t(e[n],n,e)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=n(6),r=n(7),i=function(){function e(e,t,n,o,r){this.startMeta=e,this.endMeta=t,this.text=n,this.id=o,this.__isSelectionSource={},r&&(this.extra=r)}return e.prototype.deSerialize=function(e){var t=r.queryElementNode(this,e),n=t.start,i=t.end,a=r.getTextChildByOffset(n,this.startMeta.textOffset),s=r.getTextChildByOffset(i,this.endMeta.textOffset);return new o.default(a,s,this.text,this.id,!0)},e}();t.default=i},function(e,t,n){"use strict";var o=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var o,r,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(o=i.next()).done;)a.push(o.value)}catch(e){r={error:e}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return a},r=this&&this.__spread||function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(o(arguments[t]));return e};Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(){this.handlersMap=Object.create(null)}return e.prototype.on=function(e,t){return this.handlersMap[e]||(this.handlersMap[e]=[]),this.handlersMap[e].push(t),this},e.prototype.off=function(e,t){return this.handlersMap[e]&&this.handlersMap[e].splice(this.handlersMap[e].indexOf(t)>>>0,1),this},e.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return this.handlersMap[e]&&this.handlersMap[e].slice().forEach((function(e){return e.apply(void 0,r(t))})),this},e}();t.default=i},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=n(0);t.default=function(e){return o.LOCAL_STORE_KEY+(new Date).getTime()}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=n(3),r=n(1),i=n(17),a=n(7),s=n(5),l=function(){function e(e,t,n,o,i){void 0===i&&(i=!1),3===e.$node.nodeType&&3===t.$node.nodeType||console.warn(r.ERROR.RANGE_NODE_INVALID),this.start=e,this.end=t,this.text=n,this.frozen=i,this.id=o}return e.fromSelection=function(t){var n=i.getDomRange();if(!n)return null;var o={$node:n.startContainer,offset:n.startOffset},r={$node:n.endContainer,offset:n.endOffset},a=n.toString(),l=t.call(o,r,a);return new e(o,r,a,l=null!=l?l:s.default())},e.prototype.serialize=function(e,t){var n,r=a.getDomMeta(this.start.$node,this.start.offset,e),i=a.getDomMeta(this.end.$node,this.end.offset,e);return t.Serialize.RecordInfo.isEmpty()||(n=t.Serialize.RecordInfo.call(this.start,this.end,e)),this.frozen=!0,new o.default(r,i,this.text,this.id,n)},e.removeDomRange=i.removeSelection,e.getDomRange=i.getDomRange,e}();t.default=l},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=n(0);t.getTextChildByOffset=function(e,t){for(var n=[e],o=null,r=0,i=0;o=n.pop();){for(var a=o.childNodes,s=a.length-1;s>=0;s--)n.push(a[s]);if(3===o.nodeType&&(i=t-r,(r+=o.textContent.length)>=t))break}return o||(o=e),{$node:o,offset:i}},t.queryElementNode=function(e,t){return{start:t.getElementsByTagName(e.startMeta.parentTagName)[e.startMeta.parentIndex],end:t.getElementsByTagName(e.endMeta.parentTagName)[e.endMeta.parentIndex]}};t.getDomMeta=function(e,t,n){var r=function(e){if(e instanceof HTMLElement&&(!e.dataset||!e.dataset[o.CAMEL_DATASET_IDENTIFIER]))return e;for(var t=e.parentNode;t.dataset&&t.dataset[o.CAMEL_DATASET_IDENTIFIER];)t=t.parentNode;return t}(e),i=function(e,t){for(var n=e.tagName,o=t.getElementsByTagName(n),r=0;r<o.length;r++)if(e===o[r])return r;return-1}(r,n),a=function(e,t){for(var n=[e],o=null,r=0;o=n.pop();){for(var i=o.childNodes,a=i.length-1;a>=0;a--)n.push(i[a]);if(3===o.nodeType&&o!==t)r+=o.textContent.length;else if(3===o.nodeType)break}return r}(r,e);return{parentTagName:r.tagName,parentIndex:i,textOffset:a+t}}},function(e,t,n){e.exports=n(9)},function(e,t,n){"use strict";var o,r=this&&this.__extends||(o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__assign||function(){return(i=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)};Object.defineProperty(t,"__esModule",{value:!0}),n(10);var a=n(4),s=n(1),l=n(2),c=n(0),u=n(5),d=n(12),p=n(13),f=n(14),E=n(6),h=n(3),T=function(e){function t(t){var n=e.call(this)||this;return n._getHooks=function(){return{Render:{UUID:new d.default("Render.UUID"),SelectedNodes:new d.default("Render.SelectedNodes"),WrapNode:new d.default("Render.WrapNode")},Serialize:{RecordInfo:new d.default("Serialize.RecordInfo")},Remove:{UpdateNodes:new d.default("Remove.UpdateNodes")}}},n._selectionFromHRange=function(e){var t=e.serialize(n.options.$root,n.hooks);return 0===n.painter.selectionRange(e).length?(console.warn(s.ERROR.DOM_SELECTION_EMPTY),null):(n.cache.save(t),n.emit(s.EventType.CREATE,{sources:[t],type:"from-input"},n),n.lastCreated=t,t)},n._handleSelection=function(e){var t=E.default.fromSelection(n.hooks.Render.UUID);t?n.emit(s.EventType.SELECT,t):n.emit(s.EventType.UNSELECT)},n._handleReleased=function(e){var t=E.default.fromSelection(n.hooks.Render.UUID);t&&n.emit(s.EventType.RELEASE,t)},n._handleSelectionHover=function(e){var t=e.target;if(!l.isSelectionWrapNode(t))return n._hoverId&&n.emit(s.EventType.HOVER_OUT,{id:n._hoverId},n,e),void(n._hoverId=null);var o=l.getSelectionId(t);n._hoverId!==o&&(n._hoverId&&n.emit(s.EventType.HOVER_OUT,{id:n._hoverId},n,e),n._hoverId=o,n.emit(s.EventType.HOVER,{id:n._hoverId},n,e))},n._handleSelectionClick=function(e){var t=e.target;if(l.isSelectionWrapNode(t)){var o=l.getSelectionId(t);n.emit(s.EventType.CLICK,{id:o},n,e)}else;},n.run=function(){document.addEventListener("selectionchange",n._handleSelection),"ontouchstart"in document.documentElement?n.options.$root.addEventListener("touchend",n._handleReleased):n.options.$root.addEventListener("mouseup",n._handleReleased)},n.stop=function(){document.removeEventListener("selectionchange",n._handleSelection),"ontouchstart"in document.documentElement?n.options.$root.removeEventListener("touchend",n._handleReleased):n.options.$root.removeEventListener("mouseup",n._handleReleased)},n.addClass=function(e,t){return n.getDoms(t).forEach((function(t){return t.classList.add(e)}))},n.removeClass=function(e,t){return n.getDoms(t).forEach((function(t){return t.classList.remove(e)}))},n.getIdByDom=function(e){return l.getSelectionId(e)},n.getDoms=function(e){return e?l.getSelectionById(n.options.$root,e):l.getSelectionsByRoot(n.options.$root)},n.dispose=function(){n.options.$root.removeEventListener("mouseover",n._handleSelectionHover),document.removeEventListener("selectionchange",n._handleSelection),"ontouchstart"in document.documentElement?n.options.$root.removeEventListener("touchend",n._handleReleased):n.options.$root.removeEventListener("mouseup",n._handleReleased),n.options.$root.removeEventListener("click",n._handleSelectionClick),n.removeAll()},n.setOption=function(e,t){n.options=i(i({},n.options),e),n.painter=new f.default(n.hooks),n.painter.updateOptions(n.options,t)},n.updateOption=function(e,t){n.options=i(i({},n.options),e),n.painter.updateOptions(n.options,t)},n.fromRange=function(e){var t={$node:e.startContainer,offset:e.startOffset},o={$node:e.endContainer,offset:e.endOffset},r=e.toString(),i=n.hooks.Render.UUID.call(t,o,r);i=null!=i?i:u.default();var a=new E.default(t,o,r,i);return a?n._selectionFromHRange(a):(console.warn(s.ERROR.RANGE_INVALID),null)},n.fromStore=function(e,t,o,r){try{var i=new h.default(e,t,o,r);return n._highlighFromHSource(i),i}catch(n){return console.error(n,r,o,e,t),null}},n.options=c.DEFAULT_OPTIONS,n.hooks=n._getHooks(),n.setOption(t,c.STYLESHEET_TEXT),n.cache=new p.default,n.options.$root.addEventListener("mouseover",n._handleSelectionHover),n.options.$root.addEventListener("click",n._handleSelectionClick),n}return r(t,e),t.prototype._highlighFromHSource=function(e){void 0===e&&(e=[]);var t=this.painter.selectionSource(e);this.emit(s.EventType.CREATE,{sources:t,type:"from-store"},this),this.lastCreated=t[t.length-1],this.cache.save(e)},t.prototype.makeHighlight=function(e){this._selectionFromHRange(e),E.default.removeDomRange()},t.prototype.makeHighlightFromSelection=function(){var e=E.default.getDomRange();e&&(this.fromRange(e),window.getSelection().removeAllRanges())},t.prototype.remove=function(e){e&&(this.painter.removeSelection(e),this.cache.remove(e),this.emit(s.EventType.REMOVE,{ids:[e]},this))},t.prototype.removeAll=function(){this.painter.removeAllSelection();var e=this.cache.removeAll();this.emit(s.EventType.REMOVE,{ids:e},this)},t.event=s.EventType,t}(a.default);t.default=T},function(e,t){!function(){if(!(document.documentElement.dataset||Object.getOwnPropertyDescriptor(HTMLElement.prototype,"dataset")&&Object.getOwnPropertyDescriptor(HTMLElement.prototype,"dataset").get)){var e={enumerable:!0,get:function(){var t={},n=this.attributes;function o(e){return e.charAt(1).toUpperCase()}function r(){return this.value}function i(e,t){void 0!==t?this.setAttribute(e,t):this.removeAttribute(e)}for(var a=0;a<n.length;a++){var s=n[a];if(s&&s.name&&/^data-\w[\w-]*$/.test(s.name)){var l=s.name,c=s.value,u=l.substr(5).replace(/-./g,o);Object.defineProperty(t,u,{enumerable:e.enumerable,get:r.bind({value:c||""}),set:i.bind(this,l)})}}return t}};Object.defineProperty(HTMLElement.prototype,"dataset",e)}}()},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){return e.split("-").reduce((function(e,t,n){return e+(0===n?t:t[0].toUpperCase()+t.slice(1))}),"")}},function(e,t,n){"use strict";var o=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var o,r,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(o=i.next()).done;)a.push(o.value)}catch(e){r={error:e}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return a},r=this&&this.__spread||function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(o(arguments[t]));return e};Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e){this.name="",this.ops=[],this.name=e}return e.prototype.tap=function(e){return this.ops.push(e),this},e.prototype.isEmpty=function(){return 0===this.ops.length},e.prototype.call=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return this.ops.reduce((function(t,n){return n.apply(void 0,r(e))}),null)},e}();t.default=i},function(e,t,n){"use strict";var o,r=this&&this.__extends||(o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],o=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&o>=e.length&&(e=void 0),{value:e&&e[o++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(t,"__esModule",{value:!0});var a=n(4),s=n(1),l=function(e){function t(){var t=e.call(this)||this;return t._data=new Map,t}return r(t,e),Object.defineProperty(t.prototype,"data",{get:function(){return this.getAll()},set:function(e){throw s.ERROR.CACHE_SET_ERROR},enumerable:!0,configurable:!0}),t.prototype.save=function(e){var t=this;Array.isArray(e)?e.forEach((function(e){return t._data.set(e.id,e)})):this._data.set(e.id,e)},t.prototype.get=function(e){return this._data.get(e)},t.prototype.remove=function(e){this._data.delete(e)},t.prototype.getAll=function(){var e,t,n=[];this._data=new Map;try{for(var o=i(this._data),r=o.next();!r.done;r=o.next()){var a=r.value;n.push(a[1])}}catch(t){e={error:t}}finally{try{r&&!r.done&&(t=o.return)&&t.call(o)}finally{if(e)throw e.error}}return n},t.prototype.removeAll=function(){var e,t,n=[];try{for(var o=i(this._data),r=o.next();!r.done;r=o.next()){var a=r.value;n.push(a[0])}}catch(t){e={error:t}}finally{try{r&&!r.done&&(t=o.return)&&t.call(o)}finally{if(e)throw e.error}}return this._data=new Map,n},t}(a.default);t.default=l},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=n(15),r=n(2),i=n(16),a=n(0),s=n(3),l=n(1),c=function(){function e(e){this.hooks=e}return e.prototype.updateOptions=function(e,t){t&&i.initStylesheet(t),this.options={$root:e.$root,exceptSelectors:e.exceptSelectors,className:e.style.className}},e.prototype.selectionRange=function(e){if(!e.frozen)throw l.ERROR.SELECTION_RANGE_FROZEN;var t=this.options,n=t.$root,r=t.className,i=t.exceptSelectors,a=this.hooks,s=o.getSelectedNodes(n,e.start,e.end,i);return a.Render.SelectedNodes.isEmpty()||(s=a.Render.SelectedNodes.call(e.id,s)),s.map((function(t){var n=o.wrapSelection(t,e,r);return a.Render.WrapNode.isEmpty()||(n=a.Render.WrapNode.call(e.id,n)),n}))},e.prototype.selectionSource=function(e){var t=this,n=Array.isArray(e)?e:[e],o=[];return n.forEach((function(e){if(e instanceof s.default){var n=e.deSerialize(t.options.$root);t.selectionRange(n).length>0?o.push(e):console.warn(l.ERROR.SELECTION_SOURCE_NONE_RENDER,e)}else console.error(l.ERROR.SOURCE_TYPE_ERROR)})),o},e.prototype.removeSelection=function(e){for(var t=new RegExp("("+e+"\\"+a.ID_DIVISION+"|\\"+a.ID_DIVISION+"?"+e+"$)"),n=this.hooks,i=document.querySelectorAll(a.WRAP_TAG+"[data-"+a.DATASET_IDENTIFIER+"]"),s=[],l=[],c=[],u=0;u<i.length;u++){var d=i[u].dataset[a.CAMEL_DATASET_IDENTIFIER],p=i[u].dataset[a.CAMEL_DATASET_IDENTIFIER_EXTRA];d!==e||p?d===e?l.push(i[u]):d!==e&&t.test(p)&&c.push(i[u]):s.push(i[u])}s.forEach((function(t){var i=t.parentNode,a=document.createDocumentFragment();r.forEach(t.childNodes,(function(e){return a.appendChild(e.cloneNode(!1))}));var s=t.previousSibling,l=t.nextSibling;i.replaceChild(a,t),o.normalizeSiblingText(s,!0),o.normalizeSiblingText(l,!1),n.Remove.UpdateNodes.call(e,t,"remove")})),l.forEach((function(t){var o=t.dataset,r=o[a.CAMEL_DATASET_IDENTIFIER_EXTRA].split(a.ID_DIVISION);o[a.CAMEL_DATASET_IDENTIFIER]=r.shift(),o[a.CAMEL_DATASET_IDENTIFIER_EXTRA]=r.join(a.ID_DIVISION),n.Remove.UpdateNodes.call(e,t,"id-update")})),c.forEach((function(o){var r=o.dataset[a.CAMEL_DATASET_IDENTIFIER_EXTRA];o.dataset[a.CAMEL_DATASET_IDENTIFIER_EXTRA]=r.replace(t,""),n.Remove.UpdateNodes.call(e,o,"extra-update")}))},e.prototype.removeAllSelection=function(){r.getSelectionsByRoot(this.options.$root).forEach((function(e){var t=e.parentNode,n=document.createDocumentFragment();r.forEach(e.childNodes,(function(e){return n.appendChild(e.cloneNode(!1))})),t.replaceChild(n,e)}))},e}();t.default=c},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=n(2),r=n(0),i=n(1),a=function(e,t){if(!e)return!1;if(/^\./.test(t)){var n=t.replace(/^\./,"");return e&&e.classList.contains(n)}if(/^#/.test(t)){var o=t.replace(/^#/,"");return e&&e.id===o}var r=t.toUpperCase();return e&&e.tagName===r};function s(e,t){var n=Array.isArray(t)?t:[t];return(n=0===n.length?[r.DEFAULT_OPTIONS.style.className]:n).forEach((function(t){return e.classList.add(t)})),e}t.getSelectedNodes=function(e,t,n,o){var r=t.$node,s=n.$node,l=t.offset,c=n.offset;if(r===s&&r instanceof Text)return function(e,t,n,o){for(var r=e;r;){if(1===r.nodeType&&o&&o.some((function(e){return a(r,e)})))return[];r=r.parentNode}e.splitText(t);var s=e.nextSibling;return s.splitText(n-t),[{$node:s,type:i.SelectedNodeType.text,splitType:i.SplitType.both}]}(r,l,c,o);for(var u=[e],d=[],p=!1,f=null;f=u.pop();)if(1!==f.nodeType||!o||!o.some((function(e){return a(f,e)}))){for(var E=f.childNodes,h=E.length-1;h>=0;h--)u.push(E[h]);if(f===r){if(3===f.nodeType){f.splitText(l);var T=f.nextSibling;d.push({$node:T,type:i.SelectedNodeType.text,splitType:i.SplitType.head})}p=!0}else{if(f===s){if(3===f.nodeType)(T=f).splitText(c),d.push({$node:T,type:i.SelectedNodeType.text,splitType:i.SplitType.tail});break}p&&3===f.nodeType&&d.push({$node:f,type:i.SelectedNodeType.text,splitType:i.SplitType.none})}}return d},t.wrapSelection=function(e,t,n){var a=e.$node.parentNode,l=e.$node.previousSibling,c=e.$node.nextSibling;return o.isSelectionWrapNode(a)?o.isSelectionWrapNode(a)&&(l||c)?function(e,t,n){var o=document.createElement(r.WRAP_TAG),a=e.$node.parentNode,l=e.$node.previousSibling,c=e.$node.nextSibling,u=document.createDocumentFragment(),d=a.dataset[r.CAMEL_DATASET_IDENTIFIER],p=a.dataset[r.CAMEL_DATASET_IDENTIFIER_EXTRA],f=p?d+r.ID_DIVISION+p:d;o.setAttribute("data-"+r.DATASET_IDENTIFIER,t.id),o.setAttribute("data-"+r.DATASET_IDENTIFIER_EXTRA,f),o.setAttribute("id",t.id),o.appendChild(e.$node.cloneNode(!1));var E,h,T=!1,_=!1;return l&&((h=a.cloneNode(!1)).textContent=l.textContent,u.appendChild(h),T=!0),s(o,n),u.appendChild(o),c&&((h=a.cloneNode(!1)).textContent=c.textContent,u.appendChild(h),_=!0),E=T&&_?i.SplitType.both:T?i.SplitType.head:_?i.SplitType.tail:i.SplitType.none,o.setAttribute("data-"+r.DATASET_SPLIT_TYPE,E),a.parentNode.replaceChild(u,a),o}(e,t,n):function(e,t,n){var o=e.$node.parentNode,i=o;s(i,n);var a=o.dataset,l=a[r.CAMEL_DATASET_IDENTIFIER];return a[r.CAMEL_DATASET_IDENTIFIER]=t.id,a[r.CAMEL_DATASET_IDENTIFIER_EXTRA]=a[r.CAMEL_DATASET_IDENTIFIER_EXTRA]?l+r.ID_DIVISION+a[r.CAMEL_DATASET_IDENTIFIER_EXTRA]:l,i}(e,t,n):function(e,t,n){var o;return s(o=document.createElement(r.WRAP_TAG),n),o.appendChild(e.$node.cloneNode(!1)),e.$node.parentNode.replaceChild(o,e.$node),o.setAttribute("data-"+r.DATASET_IDENTIFIER,t.id),o.setAttribute("data-"+r.DATASET_SPLIT_TYPE,e.splitType),o.setAttribute("data-"+r.DATASET_IDENTIFIER_EXTRA,""),o.setAttribute("id",t.id),o}(e,t,n)},t.normalizeSiblingText=function(e,t){if(void 0===t&&(t=!0),e&&3===e.nodeType){var n=t?e.nextSibling:e.previousSibling;if(3===n.nodeType){var o=n.nodeValue;e.nodeValue=t?e.nodeValue+o:o+e.nodeValue,n.parentNode.removeChild(n)}}}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.initStylesheet=function(e){var t=e,n=document.getElementById(t);if(!n){var o=document.createTextNode(e);(n=document.createElement("style")).id=this.styleId,n.appendChild(o),document.head.appendChild(n)}return n}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getDomRange=function(){var e=window.getSelection();return e.isCollapsed?(console.debug("no text selected"),null):e.getRangeAt(0)},t.removeSelection=function(){window.getSelection().removeAllRanges()}}]).default})); //# sourceMappingURL=selector.min.js.map