fossasia-22-renode/dist/plugin/highlight.esm.js

6 lines
777 KiB
JavaScript
Raw Normal View History

function e(t){Object.freeze(t);var a="function"==typeof t;return Object.getOwnPropertyNames(t).forEach((function(n){!t.hasOwnProperty(n)||null===t[n]||"object"!=typeof t[n]&&"function"!=typeof t[n]||a&&("caller"===n||"callee"===n||"arguments"===n)||Object.isFrozen(t[n])||e(t[n])})),t}function t(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function a(e){var t,a={},n=Array.prototype.slice.call(arguments,1);for(t in e)a[t]=e[t];return n.forEach((function(e){for(t in e)a[t]=e[t]})),a}function n(e){return e.nodeName.toLowerCase()}var i=Object.freeze({__proto__:null,escapeHTML:t,inherit:a,nodeStream:function(e){var t=[];return function e(a,i){for(var r=a.firstChild;r;r=r.nextSibling)3===r.nodeType?i+=r.nodeValue.length:1===r.nodeType&&(t.push({event:"start",offset:i,node:r}),i=e(r,i),n(r).match(/br|hr|img|input/)||t.push({event:"stop",offset:i,node:r}));return i}(e,0),t},mergeStreams:function(e,a,i){var r=0,s="",o=[];function l(){return e.length&&a.length?e[0].offset!==a[0].offset?e[0].offset<a[0].offset?e:a:"start"===a[0].event?e:a:e.length?e:a}function _(e){s+="<"+n(e)+[].map.call(e.attributes,(function(e){return" "+e.nodeName+'="'+t(e.value).replace(/"/g,"&quot;")+'"'})).join("")+">"}function c(e){s+="</"+n(e)+">"}function d(e){("start"===e.event?_:c)(e.node)}for(;e.length||a.length;){var m=l();if(s+=t(i.substring(r,m[0].offset)),r=m[0].offset,m===e){o.reverse().forEach(c);do{d(m.splice(0,1)[0]),m=l()}while(m===e&&m.length&&m[0].offset===r);o.reverse().forEach(_)}else"start"===m[0].event?o.push(m[0].node):o.pop(),d(m.splice(0,1)[0])}return s+t(i.substr(r))}});const r=e=>!!e.kind;class s{constructor(e,t){this.buffer="",this.classPrefix=t.classPrefix,e.walk(this)}addText(e){this.buffer+=t(e)}openNode(e){if(!r(e))return;let t=e.kind;e.sublanguage||(t=`${this.classPrefix}${t}`),this.span(t)}closeNode(e){r(e)&&(this.buffer+="</span>")}span(e){this.buffer+=`<span class="${e}">`}value(){return this.buffer}}class o{constructor(){this.rootNode={children:[]},this.stack=[this.rootNode]}get top(){return this.stack[this.stack.length-1]}get root(){return this.rootNode}add(e){this.top.children.push(e)}openNode(e){let t={kind:e,children:[]};this.add(t),this.stack.push(t)}closeNode(){if(this.stack.length>1)return this.stack.pop()}closeAllNodes(){for(;this.closeNode(););}toJSON(){return JSON.stringify(this.rootNode,null,4)}walk(e){return this.constructor._walk(e,this.rootNode)}static _walk(e,t){return"string"==typeof t?e.addText(t):t.children&&(e.openNode(t),t.children.forEach(t=>this._walk(e,t)),e.closeNode(t)),e}static _collapse(e){e.children&&(e.children.every(e=>"string"==typeof e)?(e.text=e.children.join(""),delete e.children):e.children.forEach(e=>{"string"!=typeof e&&o._collapse(e)}))}}class l extends o{constructor(e){super(),this.options=e}addKeyword(e,t){""!==e&&(this.openNode(t),this.addText(e),this.closeNode())}addText(e){""!==e&&this.add(e)}addSublanguage(e,t){let a=e.root;a.kind=t,a.sublanguage=!0,this.add(a)}toHTML(){return new s(this,this.options).value()}finalize(){}}function _(e){return e&&e.source||e}const c="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",d={begin:"\\\\[\\s\\S]",relevance:0},m={className:"string",begin:"'",end:"'",illegal:"\\n",contains:[d]},u={className:"string",begin:'"',end:'"',illegal:"\\n",contains:[d]},p={begin:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},E=function(e,t,n){var i=a({className:"comment",begin:e,end:t,contains:[]},n||{});return i.contains.push(p),i.contains.push({className:"doctag",begin:"(?:TODO|FIXME|NOTE|BUG|XXX):",relevance:0}),i},g=E("//","$"),S=E("/\\*","\\*/"),T=E("#","$"),b={className:"number",begin:"\\b\\d+(\\.\\d+)?",relevance:0},C={className:"number",begin:c,relevance:0},R={className:"number",begin:"\\b(0b[01]+)",relevance:0},N={className:"number",begin:"\\b\\d+(\\.\\d+)?(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",relevance:0},f={begin:/(?=\/[^\/\n]*\/)/,contains:[{classNam
/*!
* reveal.js plugin that adds syntax highlight support.
*/
var mn={id:"highlight",HIGHLIGHT_STEP_DELIMITER:"|",HIGHLIGHT_LINE_DELIMITER:",",HIGHLIGHT_LINE_RANGE_DELIMITER:"-",init:function(e){var t=e.getConfig().highlight||{};t.highlightOnLoad="boolean"!=typeof t.highlightOnLoad||t.highlightOnLoad,t.escapeHTML="boolean"!=typeof t.escapeHTML||t.escapeHTML,[].slice.call(e.getRevealElement().querySelectorAll("pre code")).forEach((function(e){e.hasAttribute("data-trim")&&"function"==typeof e.innerHTML.trim&&(e.innerHTML=function(e){function t(e){return e.replace(/^[\s\uFEFF\xA0]+/g,"")}return function(e){var a=function(e){for(var t=e.split("\n"),a=0;a<t.length&&""===t[a].trim();a++)t.splice(a--,1);for(a=t.length-1;a>=0&&""===t[a].trim();a--)t.splice(a,1);return t.join("\n")}(e.innerHTML).split("\n"),n=a.reduce((function(e,a){return a.length>0&&t(a).length>0&&e>a.length-t(a).length?a.length-t(a).length:e}),Number.POSITIVE_INFINITY);return a.map((function(e,t){return e.slice(n)})).join("\n")}(e)}(e)),t.escapeHTML&&!e.hasAttribute("data-noescape")&&(e.innerHTML=e.innerHTML.replace(/</g,"&lt;").replace(/>/g,"&gt;")),e.addEventListener("focusout",(function(e){cn.highlightBlock(e.currentTarget)}),!1),t.highlightOnLoad&&mn.highlightBlock(e)})),e.on("pdf-ready",(function(){[].slice.call(e.getRevealElement().querySelectorAll("pre code[data-line-numbers].current-fragment")).forEach((function(e){mn.scrollHighlightedLineIntoView(e,{},!0)}))}))},highlightBlock:function(e){if(cn.highlightBlock(e),0!==e.innerHTML.trim().length&&e.hasAttribute("data-line-numbers")){cn.lineNumbersBlock(e,{singleLine:!0});var t={currentBlock:e},a=mn.deserializeHighlightSteps(e.getAttribute("data-line-numbers"));if(a.length>1){var n=parseInt(e.getAttribute("data-fragment-index"),10);("number"!=typeof n||isNaN(n))&&(n=null),a.slice(1).forEach((function(a){var i=e.cloneNode(!0);i.setAttribute("data-line-numbers",mn.serializeHighlightSteps([a])),i.classList.add("fragment"),e.parentNode.appendChild(i),mn.highlightLines(i),"number"==typeof n?(i.setAttribute("data-fragment-index",n),n+=1):i.removeAttribute("data-fragment-index"),i.addEventListener("visible",mn.scrollHighlightedLineIntoView.bind(mn,i,t)),i.addEventListener("hidden",mn.scrollHighlightedLineIntoView.bind(mn,i.previousSibling,t))})),e.removeAttribute("data-fragment-index"),e.setAttribute("data-line-numbers",mn.serializeHighlightSteps([a[0]]))}var i="function"==typeof e.closest?e.closest("section:not(.stack)"):null;if(i){i.addEventListener("visible",(function a(){mn.scrollHighlightedLineIntoView(e,t,!0),i.removeEventListener("visible",a)}))}mn.highlightLines(e)}},scrollHighlightedLineIntoView:function(e,t,a){cancelAnimationFrame(t.animationFrameID),t.currentBlock&&(e.scrollTop=t.currentBlock.scrollTop),t.currentBlock=e;var n=this.getHighlightedLineBounds(e),i=e.offsetHeight,r=getComputedStyle(e);i-=parseInt(r.paddingTop)+parseInt(r.paddingBottom);var s=e.scrollTop,o=n.top+(Math.min(n.bottom-n.top,i)-i)/2,l=e.querySelector(".hljs-ln");if(l&&(o+=l.offsetTop-parseInt(r.paddingTop)),o=Math.max(Math.min(o,e.scrollHeight-i),0),!0===a||s===o)e.scrollTop=o;else{if(e.scrollHeight<=i)return;var _=0;!function a(){_=Math.min(_+.02,1),e.scrollTop=s+(o-s)*mn.easeInOutQuart(_),_<1&&(t.animationFrameID=requestAnimationFrame(a))}()}},easeInOutQuart:function(e){return e<.5?8*e*e*e*e:1-8*--e*e*e*e},getHighlightedLineBounds:function(e){var t=e.querySelectorAll(".highlight-line");if(0===t.length)return{top:0,bottom:0};var a=t[0],n=t[t.length-1];return{top:a.offsetTop,bottom:n.offsetTop+n.offsetHeight}},highlightLines:function(e,t){var a=mn.deserializeHighlightSteps(t||e.getAttribute("data-line-numbers"));a.length&&a[0].forEach((function(t){var a=[];"number"==typeof t.end?a=[].slice.call(e.querySelectorAll("table tr:nth-child(n+"+t.start+"):nth-child(-n+"+t.end+")")):"number"==typeof t.start&&(a=[].slice.call(e.querySelectorAll("table tr:nth-child("+t.start+")"))),a.length&&(a.forEach((function(e){e.classList.add("highlight-line")})),e.classList.add("has-highlights"))}))},deserializeHighlightSteps:function(e){return(e=(e=e.replace(/\s/g,"")).split(mn.HIGHLIGHT_STEP_DELIMITER)).map((