trilium/libraries/jquery.mark.es6.min.js

8 lines
14 KiB
JavaScript
Raw Normal View History

2022-05-26 05:38:06 +08:00
/*!***************************************************
* mark.js v9.0.0
* https://markjs.io/
* Copyright (c) 20142018, Julian Kühnel
* Released under the MIT license https://git.io/vwTVl
*****************************************************/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],t):e.Mark=t(e.jQuery)}(this,function(e){"use strict";class t{constructor(e,t=!0,r=[],s=5e3){this.ctx=e,this.iframes=t,this.exclude=r,this.iframesTimeout=s}static matches(e,t){const r="string"==typeof t?[t]:t,s=e.matches||e.matchesSelector||e.msMatchesSelector||e.mozMatchesSelector||e.oMatchesSelector||e.webkitMatchesSelector;if(s){let t=!1;return r.every(r=>!s.call(e,r)||(t=!0,!1)),t}return!1}getContexts(){let e,t=[];return(e=void 0!==this.ctx&&this.ctx?NodeList.prototype.isPrototypeOf(this.ctx)?Array.prototype.slice.call(this.ctx):Array.isArray(this.ctx)?this.ctx:"string"==typeof this.ctx?Array.prototype.slice.call(document.querySelectorAll(this.ctx)):[this.ctx]:[]).forEach(e=>{const r=t.filter(t=>t.contains(e)).length>0;-1!==t.indexOf(e)||r||t.push(e)}),t}getIframeContents(e,t,r=(()=>{})){let s;try{const t=e.contentWindow;if(s=t.document,!t||!s)throw new Error("iframe inaccessible")}catch(e){r()}s&&t(s)}isIframeBlank(e){const t="about:blank",r=e.getAttribute("src").trim();return e.contentWindow.location.href===t&&r!==t&&r}observeIframeLoad(e,t,r){let s=!1,i=null;const n=()=>{if(!s){s=!0,clearTimeout(i);try{this.isIframeBlank(e)||(e.removeEventListener("load",n),this.getIframeContents(e,t,r))}catch(e){r()}}};e.addEventListener("load",n),i=setTimeout(n,this.iframesTimeout)}onIframeReady(e,t,r){try{"complete"===e.contentWindow.document.readyState?this.isIframeBlank(e)?this.observeIframeLoad(e,t,r):this.getIframeContents(e,t,r):this.observeIframeLoad(e,t,r)}catch(e){r()}}waitForIframes(e,t){let r=0;this.forEachIframe(e,()=>!0,e=>{r++,this.waitForIframes(e.querySelector("html"),()=>{--r||t()})},e=>{e||t()})}forEachIframe(e,r,s,i=(()=>{})){let n=e.querySelectorAll("iframe"),o=n.length,a=0;n=Array.prototype.slice.call(n);const h=()=>{--o<=0&&i(a)};o||h(),n.forEach(e=>{t.matches(e,this.exclude)?h():this.onIframeReady(e,t=>{r(e)&&(a++,s(t)),h()},h)})}createIterator(e,t,r){return document.createNodeIterator(e,t,r,!1)}createInstanceOnIframe(e){return new t(e.querySelector("html"),this.iframes)}compareNodeIframe(e,t,r){if(e.compareDocumentPosition(r)&Node.DOCUMENT_POSITION_PRECEDING){if(null===t)return!0;if(t.compareDocumentPosition(r)&Node.DOCUMENT_POSITION_FOLLOWING)return!0}return!1}getIteratorNode(e){const t=e.previousNode();let r;return{prevNode:t,node:r=null===t?e.nextNode():e.nextNode()&&e.nextNode()}}checkIframeFilter(e,t,r,s){let i=!1,n=!1;return s.forEach((e,t)=>{e.val===r&&(i=t,n=e.handled)}),this.compareNodeIframe(e,t,r)?(!1!==i||n?!1===i||n||(s[i].handled=!0):s.push({val:r,handled:!0}),!0):(!1===i&&s.push({val:r,handled:!1}),!1)}handleOpenIframes(e,t,r,s){e.forEach(e=>{e.handled||this.getIframeContents(e.val,e=>{this.createInstanceOnIframe(e).forEachNode(t,r,s)})})}iterateThroughNodes(e,t,r,s,i){const n=this.createIterator(t,e,s);let o,a,h=[],c=[],l=()=>(({prevNode:a,node:o}=this.getIteratorNode(n)),o);for(;l();)this.iframes&&this.forEachIframe(t,e=>this.checkIframeFilter(o,a,e,h),t=>{this.createInstanceOnIframe(t).forEachNode(e,e=>c.push(e),s)}),c.push(o);c.forEach(e=>{r(e)}),this.iframes&&this.handleOpenIframes(h,e,r,s),i()}forEachNode(e,t,r,s=(()=>{})){const i=this.getContexts();let n=i.length;n||s(),i.forEach(i=>{const o=()=>{this.iterateThroughNodes(e,i,t,r,()=>{--n<=0&&s()})};this.iframes?this.waitForIframes(i,o):o()})}}class r{constructor(e){this.opt=Object.assign({},{diacritics:!0,synonyms:{},accuracy:"partially",caseSensitive:!1,ignoreJoiners:!1,ignorePunctuation:[],wildcards:"disabled"},e)}create(e){return"disabled"!==this.opt.wildcards&&(e=this.setupWildcardsRegExp(e)),e=this.escapeStr(e),Object.keys(this.opt.synonyms).length&&(e=this.createSynonymsRegExp(e)),(this.opt.ignoreJoiners||this.opt.ignorePunctuation.length)&&(e=this.setupIgnoreJoinersRegExp(e)),this.opt.diacritics&&(e=this.createDiacriticsRegExp(e)),e=this.createMergedBlanksRegExp(e),(this.opt.ignoreJoiners||this.opt.ignorePunctuation.length)&&(e=this.createJoinersRegExp(e)),"disabled"!==