PageSourceSearch

https://www.pharmac.govt.nz/resources/js/lib/mark.js?m=1790717137

js pharmac.govt.nz collected 2026-10-02 04:16:37 UTC 12,273 bytes, 1 lines download raw bytes

1"use strict";var _extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n,r=arguments[t];for(n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},_createClass=function(){function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}}(),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}!function(e,t,n){"function"==typeof define&&define.amd?define([],function(){return e(t,n)}):"object"===("undefined"==typeof module?"undefined":_typeof(module))&&module.exports?module.exports=e(t,n):e(t,n)}(function(t,o){var i=(_createClass(n,[{key:"log",value:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"debug",n=this.opt.log;this.opt.debug&&"object"===(void 0===n?"undefined":_typeof(n))&&"function"==typeof n[t]&&n[t]("mark.js: "+e)}},{key:"escapeStr",value:function(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}},{key:"createRegExp",value:function(e){return e=this.escapeStr(e),Object.keys(this.opt.synonyms).length&&(e=this.createSynonymsRegExp(e)),this.opt.ignoreJoiners&&(e=this.setupIgnoreJoinersRegExp(e)),this.opt.diacritics&&(e=this.createDiacriticsRegExp(e)),e=this.createMergedBlanksRegExp(e),this.opt.ignoreJoiners&&(e=this.createIgnoreJoinersRegExp(e)),e=this.createAccuracyRegExp(e)}},{key:"createSynonymsRegExp",value:function(e){var t,n,r,o=this.opt.synonyms,i=this.opt.caseSensitive?"":"i";for(t in o)o.hasOwnProperty(t)&&(r=o[t],n=this.escapeStr(t),r=this.escapeStr(r),e=e.replace(new RegExp("("+n+"|"+r+")","gm"+i),"("+n+"|"+r+")"));return e}},{key:"setupIgnoreJoinersRegExp",value:function(e){return e.replace(/[^(|)\\]/g,function(e,t,n){t=n.charAt(t+1);return/[(|)\\]/.test(t)||""===t?e:e+"\0"})}},{key:"createIgnoreJoinersRegExp",value:function(e){return e.split("\0").join("[\\u00ad|\\u200b|\\u200c|\\u200d]?")}},{key:"createDiacriticsRegExp",value:function(n){var r=this.opt.caseSensitive?"":"i",e=this.opt.caseSensitive?["aàáâãäåāąă","AÀÁÂÃÄÅĀĄĂ","cçćč","CÇĆČ","dđď","DĐĎ","eèéêëěēę","EÈÉÊËĚĒĘ","iìíîïī","IÌÍÎÏĪ","lł","LŁ","nñňń","NÑŇŃ","oòóôõöøō","OÒÓÔÕÖØŌ","rř","RŘ","sšśș","SŠŚȘ","tťț","TŤȚ","uùúûüůū","UÙÚÛÜŮŪ","yÿý","YŸÝ","zžżź","ZŽŻŹ"]:["aÀÁÂÃÄÅàáâãäåĀāąĄăĂ","cÇçćĆčČ","dđĐďĎ","eÈÉÊËèéêëěĚĒēęĘ","iÌÍÎÏìíîïĪī","lłŁ","nÑñňŇńŃ","oÒÓÔÕÖØòóôõöøŌō","rřŘ","sŠšśŚșȘ","tťŤțȚ","uÙÚÛÜùúûüůŮŪū","yŸÿýÝ","zŽžżŻźŹ"],o=[];return n.split("").forEach(function(t){e.every(function(e){if(-1!==e.indexOf(t)){if(-1<o.indexOf(e))return!1;n=n.replace(new RegExp("["+e+"]","gm"+r),"["+e+"]"),o.push(e)}return!0})}),n}},{key:"createMergedBlanksRegExp",value:function(e){return e.replace(/[\s]+/gim,"[\\s]+")}},{key:"createAccuracyRegExp",value:function(e){var t=this,n=this.opt.accuracy,r="string"==typeof n?n:n.value,n="string"==typeof n?[]:n.limiters,o="";switch(n.forEach(function(e){o+="|"+t.escapeStr(e)}),r){case"partially":default:return"()("+e+")";case"complementary":return"()([^\\s"+o+"]*"+e+"[^\\s"+o+"]*)";case"exactly":return"(^|\\s"+o+")("+e+")(?=$|\\s"+o+")"}}},{key:"getSeparatedKeywords",value:function(e){var t=this,n=[];return e.forEach(function(e){t.opt.separateWordSearch?e.split(" ").forEach(function(e){e.trim()&&-1===n.indexOf(e)&&n.push(e)}):e.trim()&&-1===n.indexOf(e)&&n.push(e)}),{keywords:n.sort(function(e,t){return t.length-e.length}),length:n.length}}},{key:"getTextNodes",value:function(e){var t=this,n="",r=[];this.iterator.forEachNode(NodeFilter.SHOW_TEXT,function(e){r.push({start:n.length,end:(n+=e.textContent).length,node:e})},function(e){return t.matchesExclude(e.parentNode,!0)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT},function(){e({value:n,nodes:r})})}},{key:"matchesExclude",value:function(e,t){var n=this.opt.exclude.concat(["script","style","title","head","html"]);return t&&(n=n.concat(["*[data-markjs='true']"])),a.matches(e,n)}},{key:"wrapRangeInTextNode",value:function(e,t,n){var r=this.opt.element||"mark",e=e.splitText(t),t=e.splitText(n-t),r=o.createElement(r);return r.setAttribute("data-markjs","true"),this.opt.className&&r.setAttribute("class",this.opt.className),r.textContent=e.textContent,e.parentNode.replaceChild(r,e),t}},{key:"wrapRangeInMappedTextNode",value:function(i,a,s,c,u){var l=this;i.nodes.every(function(r,o){var e=i.nodes[o+1];if(void 0===e||e.start>a){e=function(){var e=a-r.start,n=(s>r.end?r.end:s)-r.start;if(c(r.node)){r.node=l.wrapRangeInTextNode(r.node,e,n);var t=i.value.substr(0,r.start),e=i.value.substr(n+r.start);
1if(i.value=t+e,i.nodes.forEach(function(e,t){o<=t&&(0<i.nodes[t].start&&t!==o&&(i.nodes[t].start-=n),i.nodes[t].end-=n)}),s-=n,u(r.node.previousSibling,r.start),!(s>r.end))return{v:!1};a=r.end}}();if("object"===(void 0===e?"undefined":_typeof(e)))return e.v}return!0})}},{key:"wrapMatches",value:function(o,e,i,a,t){var s=this,c=0===e?0:e+1;this.getTextNodes(function(e){e.nodes.forEach(function(e){e=e.node;for(var t;null!==(t=o.exec(e.textContent))&&""!==t[c];)if(i(t[c],e)){var n=t.index;if(0!==c)for(var r=1;r<c;r++)n+=t[r].length;e=s.wrapRangeInTextNode(e,n,n+t[c].length),a(e.previousSibling),o.lastIndex=0}}),t()})}},{key:"wrapMatchesAcrossElements",value:function(i,e,a,s,c){var u=this,l=0===e?0:e+1;this.getTextNodes(function(e){for(var t;null!==(t=i.exec(e.value))&&""!==t[l];){var n=t.index;if(0!==l)for(var r=1;r<l;r++)n+=t[r].length;var o=n+t[l].length;u.wrapRangeInMappedTextNode(e,n,o,function(e){return a(t[l],e)},function(e,t){i.lastIndex=t,s(e)})}c()})}},{key:"unwrapMatches",value:function(e){for(var t=e.parentNode,n=o.createDocumentFragment();e.firstChild;)n.appendChild(e.removeChild(e.firstChild));t.replaceChild(n,e),this.normalizeTextNode(t)}},{key:"normalizeTextNode",value:function(e){if(e){if(3===e.nodeType)for(;e.nextSibling&&3===e.nextSibling.nodeType;)e.nodeValue+=e.nextSibling.nodeValue,e.parentNode.removeChild(e.nextSibling);else this.normalizeTextNode(e.firstChild);this.normalizeTextNode(e.nextSibling)}}},{key:"markRegExp",value:function(e,t){var n=this;this.opt=t,this.log('Searching with expression "'+e+'"');var r=0,t="wrapMatches";this[t=this.opt.acrossElements?"wrapMatchesAcrossElements":t](e,this.opt.ignoreGroups,function(e,t){return n.opt.filter(t,e,r)},function(e){r++,n.opt.each(e)},function(){0===r&&n.opt.noMatch(e),n.opt.done(r)})}},{key:"mark",value:function(e,t){var o=this;this.opt=t;var i=0,a="wrapMatches",e=this.getSeparatedKeywords("string"==typeof e?[e]:e),s=e.keywords,c=e.length,u=this.opt.caseSensitive?"":"i",e=function e(n){var t=new RegExp(o.createRegExp(n),"gm"+u),r=0;o.log('Searching with expression "'+t+'"'),o[a](t,1,function(e,t){return o.opt.filter(t,n,i,r)},function(e){r++,i++,o.opt.each(e)},function(){0===r&&o.opt.noMatch(n),s[c-1]===n?o.opt.done(i):e(s[s.indexOf(n)+1])})};this.opt.acrossElements&&(a="wrapMatchesAcrossElements"),0===c?this.opt.done(i):e(s[0])}},{key:"unmark",value:function(e){var n=this;this.opt=e;var r=this.opt.element||"*";r+="[data-markjs]",this.opt.className&&(r+="."+this.opt.className),this.log('Removal selector "'+r+'"'),this.iterator.forEachNode(NodeFilter.SHOW_ELEMENT,function(e){n.unwrapMatches(e)},function(e){var t=a.matches(e,r),e=n.matchesExclude(e,!1);return!t||e?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT},this.opt.done)}},{key:"opt",set:function(e){this._opt=_extends({},{element:"",className:"",exclude:[],iframes:!1,separateWordSearch:!0,diacritics:!0,synonyms:{},accuracy:"partially",acrossElements:!1,caseSensitive:!1,ignoreJoiners:!1,ignoreGroups:0,each:function(){},noMatch:function(){},filter:function(){return!0},done:function(){},debug:!1,log:t.console},e)},get:function(){return this._opt}},{key:"iterator",get:function(){return this._iterator||(this._iterator=new a(this.ctx,this.opt.iframes,this.opt.exclude)),this._iterator}}]),n);function n(e){_classCallCheck(this,n),this.ctx=e}var a=(_createClass(c,[{key:"getContexts",value:function(){var n=[];return(void 0!==this.ctx&&this.ctx?NodeList.prototype.isPrototypeOf(this.ctx)?Array.prototype.slice.call(this.ctx):Array.isArray(this.ctx)?this.ctx:[this.ctx]:[]).forEach(function(t){var e=0<n.filter(function(e){return e.contains(t)}).length;-1!==n.indexOf(t)||e||n.push(t)}),n}},{key:"getIframeContents",value:function(e,t){var n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:function(){},r=void 0;try{var o=e.contentWindow,r=o.document;if(!o||!r)throw new Error("iframe inaccessible")}catch(e){n()}r&&t(r)}},{key:"onIframeReady",value:function(t,n,r){var o,i,a=this;try{o=t.contentWindow,i="about:blank","complete"!==o.document.readyState||s()?e():a.getIframeContents(t,n,r)}catch(e){r()}function s(){var e=t.getAttribute("src").trim();return o.location.href===i&&e!==i&&e}function e(){function e(){try{s()||(t.removeEventListener("load",e),a.getIframeContents(t,n,r))}catch(e){r()}}t.addEventListener("load",e)}}},{key:"waitForIframes",value:function(e,t){var n=this,r=0;this.forEachIframe(e,function(){return!0},function(e){r++,n.waitForIframes(e.querySelector("html"),function(){--r||t()})},function(e){e||t()})}}
1,{key:"forEachIframe",value:function(e,n,r){function o(){--a<=0&&t(s)}var i=this,t=3<arguments.length&&void 0!==arguments[3]?arguments[3]:function(){},a=(e=e.querySelectorAll("iframe")).length,s=0,e=Array.prototype.slice.call(e);a||o(),e.forEach(function(t){c.matches(t,i.exclude)?o():i.onIframeReady(t,function(e){n(t)&&(s++,r(e)),o()},o)})}},{key:"createIterator",value:function(e,t,n){return o.createNodeIterator(e,t,n,!1)}},{key:"createInstanceOnIframe",value:function(e){return new c(e.querySelector("html"),this.iframes)}},{key:"compareNodeIframe",value:function(e,t,n){if(e.compareDocumentPosition(n)&Node.DOCUMENT_POSITION_PRECEDING){if(null===t)return!0;if(t.compareDocumentPosition(n)&Node.DOCUMENT_POSITION_FOLLOWING)return!0}return!1}},{key:"getIteratorNode",value:function(e){var t=e.previousNode();return{prevNode:t,node:(null===t||e.nextNode())&&e.nextNode()}}},{key:"checkIframeFilter",value:function(e,t,n,r){var o=!1,i=!1;return r.forEach(function(e,t){e.val===n&&(o=t,i=e.handled)}),this.compareNodeIframe(e,t,n)?(!1!==o||i?!1===o||i||(r[o].handled=!0):r.push({val:n,handled:!0}),!0):(!1===o&&r.push({val:n,handled:!1}),!1)}},{key:"handleOpenIframes",value:function(e,t,n,r){var o=this;e.forEach(function(e){e.handled||o.getIframeContents(e.val,function(e){o.createInstanceOnIframe(e).forEachNode(t,n,r)})})}},{key:"iterateThroughNodes",value:function(t,e,n,r,o){for(var i,a=this,s=this.createIterator(e,t,r),c=[],u=void 0,l=void 0;i=void 0,i=a.getIteratorNode(s),l=i.prevNode,u=i.node;)this.iframes&&this.forEachIframe(e,function(e){return a.checkIframeFilter(u,l,e,c)},function(e){a.createInstanceOnIframe(e).forEachNode(t,n,r)}),n(u);this.iframes&&this.handleOpenIframes(c,t,n,r),o()}},{key:"forEachNode",value:function(n,r,o){var i=this,a=3<arguments.length&&void 0!==arguments[3]?arguments[3]:function(){},e=this.getContexts(),s=e.length;s||a(),e.forEach(function(e){function t(){i.iterateThroughNodes(n,e,r,o,function(){--s<=0&&a()})}i.iframes?i.waitForIframes(e,t):t()})}}],[{key:"matches",value:function(t,e){var e="string"==typeof e?[e]:e,n=t.matches||t.matchesSelector||t.msMatchesSelector||t.mozMatchesSelector||t.oMatchesSelector||t.webkitMatchesSelector;if(n){var r=!1;return e.every(function(e){return!n.call(t,e)||!(r=!0)}),r}return!1}}]),c);function c(e){var t=!(1<arguments.length&&void 0!==arguments[1])||arguments[1],n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:[];_classCallCheck(this,c),this.ctx=e,this.iframes=t,this.exclude=n}return t.Mark=function(e){var n=this,r=new i(e);return this.mark=function(e,t){return r.mark(e,t),n},this.markRegExp=function(e,t){return r.markRegExp(e,t),n},this.unmark=function(e){return r.unmark(e),n},this},t.Mark},window,document);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.