heti/dist/heti-addon.min.js

2 lines
8.6 KiB
JavaScript
Raw Normal View History

2020-02-21 01:49:22 +08:00
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Heti=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var t=function(e,t){return e(t={exports:{}},t.exports),t.exports}((function(t){var n,r;n=e,r=function(){var e=document,t={}.hasOwnProperty;function n(){return r.apply(null,arguments)||i.apply(null,arguments)}function r(e,t,r,o,a){if(t&&!t.nodeType&&arguments.length<=2)return!1;var s,d="function"==typeof r;d&&(s=r,r=function(e,t){return s(e.text,t.startIndex)});var p=i(t,{find:e,wrap:d?null:r,replace:d?r:"$"+(o||"&"),prepMatch:function(e,t){if(!e[0])throw"findAndReplaceDOMText cannot handle zero-length matches";if(o>0){var n=e[o];e.index+=e[0].indexOf(n),e[0]=n}return e.endIndex=e.index+e[0].length,e.startIndex=e.index,e.index=t,e},filterElements:a});return n.revert=function(){return p.revert()},!0}function i(e,t){return new o(e,t)}function o(e,r){var i=r.preset&&n.PRESETS[r.preset];if(r.portionMode=r.portionMode||"retain",i)for(var o in i)t.call(i,o)&&!t.call(r,o)&&(r[o]=i[o]);this.node=e,this.options=r,this.prepMatch=r.prepMatch||this.prepMatch,this.reverts=[],this.matches=this.search(),this.matches.length&&this.processMatches()}return n.NON_PROSE_ELEMENTS={br:1,hr:1,script:1,style:1,img:1,video:1,audio:1,canvas:1,svg:1,map:1,object:1,input:1,textarea:1,select:1,option:1,optgroup:1,button:1},n.NON_CONTIGUOUS_PROSE_ELEMENTS={address:1,article:1,aside:1,blockquote:1,dd:1,div:1,dl:1,fieldset:1,figcaption:1,figure:1,footer:1,form:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,header:1,hgroup:1,hr:1,main:1,nav:1,noscript:1,ol:1,output:1,p:1,pre:1,section:1,ul:1,br:1,li:1,summary:1,dt:1,details:1,rp:1,rt:1,rtc:1,script:1,style:1,img:1,video:1,audio:1,canvas:1,svg:1,map:1,object:1,input:1,textarea:1,select:1,option:1,optgroup:1,button:1,table:1,tbody:1,thead:1,th:1,tr:1,td:1,caption:1,col:1,tfoot:1,colgroup:1},n.NON_INLINE_PROSE=function(e){return t.call(n.NON_CONTIGUOUS_PROSE_ELEMENTS,e.nodeName.toLowerCase())},n.PRESETS={prose:{forceContext:n.NON_INLINE_PROSE,filterElements:function(e){return!t.call(n.NON_PROSE_ELEMENTS,e.nodeName.toLowerCase())}}},n.Finder=o,o.prototype={search:function(){var e,t=0,n=0,r=this.options.find,i=this.getAggregateText(),o=[],a=this;return r="string"==typeof r?RegExp(String(r).replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1"),"g"):r,function i(s){for(var d=0,p=s.length;d<p;++d){var c=s[d];if("string"==typeof c){if(r.global)for(;e=r.exec(c);)o.push(a.prepMatch(e,t++,n));else(e=c.match(r))&&o.push(a.prepMatch(e,0,n));n+=c.length}else i(c)}}(i),o},prepMatch:function(e,t,n){if(!e[0])throw new Error("findAndReplaceDOMText cannot handle zero-length matches");return e.endIndex=n+e.index+e[0].length,e.startIndex=n+e.index,e.index=t,e},getAggregateText:function(){var e=this.options.filterElements,t=this.options.forceContext;return function n(r){if(r.nodeType===Node.TEXT_NODE)return[r.data];if(e&&!e(r))return[];var i=[""],o=0;if(r=r.firstChild)do{if(r.nodeType!==Node.TEXT_NODE){var a=n(r);t&&r.nodeType===Node.ELEMENT_NODE&&(!0===t||t(r))?(i[++o]=a,i[++o]=""):("string"==typeof a[0]&&(i[o]+=a.shift()),a.length&&(i[++o]=a,i[++o]=""))}else i[o]+=r.data}while(r=r.nextSibling);return i}(this.node)},processMatches:function(){var e,t,n,r=this.matches,i=this.node,o=this.options.filterElements,a=[],s=i,d=r.shift(),p=0,c=0,l=[i];e:for(;;){if(s.nodeType===Node.TEXT_NODE&&(!t&&s.length+p>=d.endIndex?t={node:s,index:c++,text:s.data.substring(d.startIndex-p,d.endIndex-p),indexInMatch:0===p?0:p-d.startIndex,indexInNode:d.startIndex-p,endIndexInNode:d.endIndex-p,isEnd:!0}:e&&a.push({node:s,index:c++,text:s.data,indexInMatch:p-d.startIndex,indexInNode:0}),!e&&s.length+p>d.startIndex&&(e={node:s,index:c++,indexInMatch:0,indexInNode:d.startIndex-p,endIndexInNode:d.endIndex-p,text:s.data.substring(d.startIndex-p,d.endIndex-p)}),p+=s.data.length),n=s.nodeType===Node.ELEMENT_NODE&&o&&!o(s),e&&t){if(s=this.replaceMatch(