copy-paste-bookmarks/plugin/highlight/highlight.js

6 lines
808 KiB
JavaScript
Raw Normal View History

2020-05-26 09:46:50 +02:00
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).RevealHighlight=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e,t,a){return e(a={path:t,exports:{},require:function(e,t){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==t&&a.path)}},a.exports),a.exports}var a=function(e){return e&&e.Math==Math&&e},n=a("object"==typeof globalThis&&globalThis)||a("object"==typeof window&&window)||a("object"==typeof self&&self)||a("object"==typeof e&&e)||Function("return this")(),r=function(e){try{return!!e()}catch(e){return!0}},i=!r((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),o={}.propertyIsEnumerable,s=Object.getOwnPropertyDescriptor,l={f:s&&!o.call({1:2},1)?function(e){var t=s(this,e);return!!t&&t.enumerable}:o},_=function(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}},c={}.toString,d=function(e){return c.call(e).slice(8,-1)},u="".split,m=r((function(){return!Object("z").propertyIsEnumerable(0)}))?function(e){return"String"==d(e)?u.call(e,""):Object(e)}:Object,p=function(e){if(null==e)throw TypeError("Can't call method on "+e);return e},E=function(e){return m(p(e))},g=function(e){return"object"==typeof e?null!==e:"function"==typeof e},S=function(e,t){if(!g(e))return e;var a,n;if(t&&"function"==typeof(a=e.toString)&&!g(n=a.call(e)))return n;if("function"==typeof(a=e.valueOf)&&!g(n=a.call(e)))return n;if(!t&&"function"==typeof(a=e.toString)&&!g(n=a.call(e)))return n;throw TypeError("Can't convert object to primitive value")},T={}.hasOwnProperty,b=function(e,t){return T.call(e,t)},f=n.document,C=g(f)&&g(f.createElement),R=function(e){return C?f.createElement(e):{}},N=!i&&!r((function(){return 7!=Object.defineProperty(R("div"),"a",{get:function(){return 7}}).a})),O=Object.getOwnPropertyDescriptor,v={f:i?O:function(e,t){if(e=E(e),t=S(t,!0),N)try{return O(e,t)}catch(e){}if(b(e,t))return _(!l.f.call(e,t),e[t])}},I=function(e){if(!g(e))throw TypeError(String(e)+" is not an object");return e},h=Object.defineProperty,A={f:i?h:function(e,t,a){if(I(e),t=S(t,!0),I(a),N)try{return h(e,t,a)}catch(e){}if("get"in a||"set"in a)throw TypeError("Accessors not supported");return"value"in a&&(e[t]=a.value),e}},y=i?function(e,t,a){return A.f(e,t,_(1,a))}:function(e,t,a){return e[t]=a,e},D=function(e,t){try{y(n,e,t)}catch(a){n[e]=t}return t},M=n["__core-js_shared__"]||D("__core-js_shared__",{}),L=Function.toString;"function"!=typeof M.inspectSource&&(M.inspectSource=function(e){return L.call(e)});var x,w,P,k=M.inspectSource,U=n.WeakMap,F="function"==typeof U&&/native code/.test(k(U)),B=t((function(e){(e.exports=function(e,t){return M[e]||(M[e]=void 0!==t?t:{})})("versions",[]).push({version:"3.6.5",mode:"global",copyright:"© 2020 Denis Pushkarev (zloirock.ru)"})})),G=0,Y=Math.random(),H=function(e){return"Symbol("+String(void 0===e?"":e)+")_"+(++G+Y).toString(36)},V=B("keys"),q=function(e){return V[e]||(V[e]=H(e))},z={},W=n.WeakMap;if(F){var Q=new W,$=Q.get,K=Q.has,j=Q.set;x=function(e,t){return j.call(Q,e,t),t},w=function(e){return $.call(Q,e)||{}},P=function(e){return K.call(Q,e)}}else{var X=q("state");z[X]=!0,x=function(e,t){return y(e,X,t),t},w=function(e){return b(e,X)?e[X]:{}},P=function(e){return b(e,X)}}var Z={set:x,get:w,has:P,enforce:function(e){return P(e)?w(e):x(e,{})},getterFor:function(e){return function(t){var a;if(!g(t)||(a=w(t)).type!==e)throw TypeError("Incompatible receiver, "+e+" required");return a}}},J=t((function(e){var t=Z.get,a=Z.enforce,r=String(String).split("String");(e.exports=function(e,t,i,o){var s=!!o&&!!o.unsafe,l=!!o&&!!o.enumerable,_=!!o&&!!o.noTargetGet;"function"==typeof i&&("string"!=typeof t||b(i,"name")||y(i,"name",t),a(i).source=r.join("string"==typeof t?t:"")),e!==n?(s?!_&&e[t]&&(l=!0):delete e[t],l?e[t]=i:y(e,t,i)):l?e[t]=i:D(t,i)})(Function.p
/*!
2020-05-26 09:46:50 +02:00
* reveal.js plugin that adds syntax highlight support.
*/
var Tl={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){Sl.highlightBlock(e.currentTarget)}),!1),t.highlightOnLoad&&Tl.highlightBlock(e)})),e.on("pdf-ready",(function(){[].slice.call(e.getRevealElement().querySelectorAll("pre code[data-line-numbers].current-fragment")).forEach((function(e){Tl.scrollHighlightedLineIntoView(e,{},!0)}))}))},highlightBlock:function(e){if(Sl.highlightBlock(e),0!==e.innerHTML.trim().length&&e.hasAttribute("data-line-numbers")){Sl.lineNumbersBlock(e,{singleLine:!0});var t={currentBlock:e},a=Tl.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 r=e.cloneNode(!0);r.setAttribute("data-line-numbers",Tl.serializeHighlightSteps([a])),r.classList.add("fragment"),e.parentNode.appendChild(r),Tl.highlightLines(r),"number"==typeof n?(r.setAttribute("data-fragment-index",n),n+=1):r.removeAttribute("data-fragment-index"),r.addEventListener("visible",Tl.scrollHighlightedLineIntoView.bind(Tl,r,t)),r.addEventListener("hidden",Tl.scrollHighlightedLineIntoView.bind(Tl,r.previousSibling,t))})),e.removeAttribute("data-fragment-index"),e.setAttribute("data-line-numbers",Tl.serializeHighlightSteps([a[0]]))}var r="function"==typeof e.closest?e.closest("section:not(.stack)"):null;if(r){r.addEventListener("visible",(function a(){Tl.scrollHighlightedLineIntoView(e,t,!0),r.removeEventListener("visible",a)}))}Tl.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),r=e.offsetHeight,i=getComputedStyle(e);r-=parseInt(i.paddingTop)+parseInt(i.paddingBottom);var o=e.scrollTop,s=n.top+(Math.min(n.bottom-n.top,r)-r)/2,l=e.querySelector(".hljs-ln");if(l&&(s+=l.offsetTop-parseInt(i.paddingTop)),s=Math.max(Math.min(s,e.scrollHeight-r),0),!0===a||o===s)e.scrollTop=s;else{if(e.scrollHeight<=r)return;var _=0;!function a(){_=Math.min(_+.02,1),e.scrollTop=o+(s-o)*Tl.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=Tl.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(Tl.HIGHLIGHT_STEP_DELIMITER)).map((