Build 562131stable
Module 347024
5,845 characters · in bca0a10bf65022b8.jsDependencies
Source Raw
function(e,t,n){"use strict";let l;n.d(t,{W:()=>k,Ay:()=>_,Q9:()=>P}),n(321073);var i=n(635377),s=n.n(i),r=n(941426),a=n(534979);let o=new Map,c=new Map,u=new Set;function d(e){let t=o.get(e);if(null!=t)return t;if(!(e in a.pb)){let t=Promise.resolve(null);return o.set(e,t),t}return t=(null==l&&(l=(0,a.A)()),l).then(t=>t.loadGrammar(a.pb[e])).then(t=>{for(let n of(c.set(e,t),u))n(e);return t}),o.set(e,t),t}var h=n(157941),m=n(768947),p=n(927813),f=n(186306),g=n(323350),x=n(35277),A=n(820066),E=n(551483),C=n(618559);let I=new r.Vy("withCodeBlocks"),y=new Set(["line"]),S=/^[a-z0-9_+\-.#]+$/i,v=null,N=null;function _(e){let{onChange:t}=e,l=null,i=!1,s=!1,r=e=>{d(e).then(e=>{null!=e&&a()}).catch(()=>{})},a=()=>{s||(s=!0,queueMicrotask(()=>{s=!1;try{f.o.withoutSaving(e,()=>{A.VW.withoutNormalizing(e,()=>T(e,r))}),l=A.VW.richValue(e)}catch(e){I.warn("error applying arborium highlighting to editor",e)}}))};return e.onChange=()=>{A.VW.richValue(e)!==l&&(f.o.withoutSaving(e,()=>{A.VW.withoutNormalizing(e,()=>{T(e,r)&&null==v&&!i&&(i=!0,(null==N&&(N=Promise.all([n.e("57036"),n.e("75134")]).then(n.bind(n,981776)).then(e=>{v=e.default}).catch(e=>{throw N=null,e})),N).then(()=>{l=null,f.o.withoutSaving(e,()=>{A.VW.withoutNormalizing(e,()=>T(e))}),l=A.VW.richValue(e)}).catch(()=>{}).finally(()=>{i=!1}))})}),l=A.VW.richValue(e)),t()},e}function T(e,t){let n=function(e,t){let n=[],l=null;for(let t of A.VW.blocks(e))l=function(e,t,n,l,i){let s=function(e){let t,[n,l]=e;if(!y.has(n.type))return[];let i=[],s=/\\|```/g;for(let e=0;e<n.children.length;e++){let r=n.children[e];if(A.l5.isText(r))for(s.lastIndex=0;null!=(t=s.exec(r.text));){if("\\"===t[0]){s.lastIndex+=1;continue}i.push({path:A.PW.child(l,e),offset:t.index})}}return i}(t),r=s[0],a=s[s.length-1],o=null;if(null!=a){let[t]=A.VW.node(e,a.path);o=t.text.substring(a.offset+3)}let c=n&&null!=r,u=n&&0===s.length,d=l&&0===s.length,h=(c?s.slice(1):s).length%2==1,m=h&&(null==o||""===o||null!=o.match(S)),p=m&&null!=o&&""!==o?o.toLowerCase():null;return{blockEntry:t,wasInCodeBlock:n,isInCodeBlock:u,isStyledCodeBlockLine:d,lang:h||c?p:i,hljsTypes:null,closesCodeBlock:c,opensCodeBlock:h,opensCodeBlockOnOwnLine:m}}(e,t,null!=l&&(l.isInCodeBlock||l.opensCodeBlock),null!=l&&(l.isStyledCodeBlockLine||l.opensCodeBlockOnOwnLine),null!=l&&(l.opensCodeBlock||!l.closesCodeBlock)?l.lang:null),n.push(l);return function(e,t){let n=h.L.getConfig({location:"syntaxHighlightCodeBlocks"}).enabled,l=[],i=!1;for(let s of e){let r=s===e[e.length-1];if((s.closesCodeBlock||r)&&(i&&r&&!s.closesCodeBlock&&l.push(s),i=!1,l.length>0)){let e=l.map(e=>(0,g.IQ)(e.blockEntry[0])).join("\n"),i=l[0].lang;if(null!=i&&n)!function(e,t,n,l){let i=function(e,t,n,l){let i,s=(0,m.py)(t);if(null==s)return null;let r=`${e}-${s}`,a=w.get(r);if(null!=a&&a.length===n)return a;for(let t of e.split("\n"))if(t.length>1e3)return null;let o=c.has(s)?c.get(s)??null:(d(s),null);if(null==o)return l?.(s),null;let u=e.endsWith("\n")?e:`${e}
`,h=o.createSession();try{h.setText(u);let e=h.highlightToHtml();if(i=e.html,null!=l)for(let t of e.missingInjections)l(t)}finally{h.free()}let p=i.endsWith("\n")?i.slice(0,-1).split("\n"):i.split("\n");if(p.length!==n)return null;let f=[];for(let e=0;e<n;e++)f.push(function(e){let t,n=[],l=[],i=0,s=0;for(b.lastIndex=0;null!=(t=b.exec(e));){let r=t.index+t[0].length,a=L(e.substring(s,t.index)).length,o=l.filter(e=>null!=e);if(a>0&&o.length>0&&n.push({types:o,start:i,end:i+a}),a>0&&(i+=a),null!=t[1]){let e=R.get(t[1]);l.push(e??null)}else l.pop();s=r}let r=L(e.substring(s)).length,a=l.filter(e=>null!=e);return r>0&&a.length>0&&n.push({types:a,start:i,end:i+r}),n}(p[e]));return w.set(r,f),f}(e,t,n.length,l);if(null!=i)for(let e=0;e<n.length;e++)n[e].hljsTypes=i[e];else for(let e=0;e<n.length;e++)n[e].hljsTypes=[]}(e,i,l,t);else if(null==i||null==v||v.hasLanguage(i)){if(null!=i&&null!=v&&v.hasLanguage(i)){let t=function(e,t){if(null==v)return null;let n=`${e}-${t}`,l=M.get(n);if(null!=l)return l;let i=v.highlight(t,e,!1);if(null==i||i.illegal)return null;let s=i.value.split("\n");return M.set(n,s),s}(e,i);if(null!=t&&t.length===l.length){let e=[];for(let n=0;n<l.length;n++){let i,s=t[n].replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'"),r=[],a=0,o=0;for(;null!=(i=j.exec(s));){let t=i.index+i[0].length,n=i.index-o;i.index>o&&(e.length>0&&r.push({types:[...e],start:a,end:a+n}),a+=n),"</span>"===i[0]?e.pop():e.push(i[1]),o=t}if(e.length>0){let t=s.length-o;r.push({types:[...e],start:a,end:a+t})}l[n].hljsTypes=r}}else for(let e=0;e<l.length;e++)l[e].hljsTypes=null}}else for(let e=0;e<l.length;e++)l[e].hljsTypes=[];l=[]}i&&l.push(s),s.opensCodeBlock&&(i=!0)}}(n,t),n}(e,t);return function(e,t){for(let l of t){var n;let[t,i]=l.blockEntry,s=(n=l).isStyledCodeBlockLine||n.wasInCodeBlock?{lang:n.lang,wasInCodeBlock:n.wasInCodeBlock,isInCodeBlock:n.isInCodeBlock,isStyledCodeBlockLine:n.isStyledCodeBlockLine,hljsTypes:n.hljsTypes}:null;t?.codeBlockState!=s&&x.b.setNodes(e,{codeBlockState:s},{at:i})}}(e,n),n.some(e=>null!=e.lang)}let j=/(?:<span class="([^"]*)">)|(?:<\/span>)/g,b=/(?:<(a-[a-z]{1,2})>)|(?:<\/a-[a-z]{1,2}>)/g,R=new Map;for(let[e,t]of Object.entries(C))e.startsWith("a-")&&null!=t&&R.set(e,t);let O={max:1/0,maxAge:+p.A.Millis.MINUTE,updateAgeOnGet:!0},M=new(s())(O),w=new(s())(O);function L(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'")}function k(e,t){let n=0;for(let l of A.VW.nodes(e,{at:{anchor:{path:E.fP,offset:0},focus:t},mode:"lowest",match:e=>A.l5.isText(e)})){let e=l[0].text;A.PW.equals(l[1],t.path)&&(e=e.substring(0,t.offset));let i=e.match(/```/g);n+=i?.length??0}return n%2!=0}function P(e){if(null==e.selection)return!1;let t=A.ZF.start(e.selection);return k(e,t)}u.add(()=>{w.reset()})}