import{a as j,b as J}from"./chunk-OMJ3HEST.js";import{a as x}from"./chunk-AX7GEE3B.js";import{a as U,c as G}from"./chunk-PERPLZAX.js";import{a as H,d as Y}from"./chunk-W3NBOZCE.js";import{D as A,E as z}from"./chunk-I7GW4F3B.js";import{a as B,b as q}from"./chunk-QGVT6DPT.js";import{Db as P,Dc as L,Ea as k,Fa as T,Ic as V,J as g,Jb as m,Nc as D,Oc as N,Pc as O,Qb as _,Sa as $,Ub as M,Wa as b,be as I,ia as C,xc as S,yc as E}from"./chunk-WL5U2YIT.js";import{e as v,h as y}from"./chunk-ADEKKGI2.js";function d(e,i={}){let r=i.highlighter||h.default;return{toHTMLRenderers:{codeBlock:t=>te(t,r)},wysiwygPlugins:[()=>ie(e,r)]}}function te(e,i){let r=e.info?e.info.split(/\s+/):[],t=[],n={},s=e.literal||"";if((e.fenceLength||0)>X&&(n["data-backticks"]=e.fenceLength),r.length&&r[0].length){let a=r[0];t.push(`lang-${a}`),n["data-language"]=a;let o=i.languages[a];o&&(s=i.highlight(s,o,a))}return[{type:"openTag",tagName:"pre",classNames:t},{type:"openTag",tagName:"code",attributes:n},{type:"html",content:s},{type:"closeTag",tagName:"code"},{type:"closeTag",tagName:"pre"}]}function ie(e,i){return new e.pmState.Plugin({state:{init:(r,{doc:t})=>K(t,e,i),apply:(r,t)=>r.docChanged?K(r.doc,e,i):t.map(r.mapping,r.doc)},props:{decorations(r){return this.getState(r)}}})}function K(e,i,r){let t=[];return ne(e).forEach(({node:n,pos:s})=>{let a=n.attrs.language,o=r.languages[a];if(!o)return;let c=u(r.tokenize(n.textContent,o)),l=s+1;c.forEach(({text:F,classes:R})=>{let f=l,p=f+F.length,w=R.join(" ");l=p,w.length&&t.push(i.pmView.Decoration.inline(f,p,{class:w}))})}),i.pmView.DecorationSet.create(e,t)}function ne(e){let i=[];return e.descendants((r,t)=>{r.isBlock&&r.type.name===Z&&i.push({node:r,pos:t})}),i}function u(e,i=[]){if(typeof e=="string")return[{text:e,classes:i}];if(Array.isArray(e))return e.flatMap(n=>u(n,i));let r=e.type?[ee,e.type]:[],t=typeof e.alias=="string"?[e.alias]:e.alias||[];return u(e.content,[...i,...r,...t])}var h,X,Z,ee,Q=v(()=>{h=y(x()),X=3,Z="codeBlock",ee="token";if(typeof window<"u"){let e=window;e.Prism=e.Prism||h.default,e.Prism.manual=!0}});var W,re,Ce,ae=v(()=>{I();q();J();$();Q();W=y(x());I();G();Y();z();re=["viewerContainer"],Ce=(()=>{let i=class i extends B{constructor(t,n,s){super(),this.handbookImagesService=t,this._markdown=n,this.currentUserService=s,this.isMarkdown=!0,this.disableLinks=!1,this.changePage=new P,this.currentTheme=""}ngOnChanges(t){t.data&&this.viewer&&this.initViewerContent()}ngOnDestroy(){super.ngOnDestroy()}ngAfterViewInit(){this.subscribeToTheme()}onPageLink(t){t.preventDefault();let n=t.target.getAttribute("href");if(!n)return;let s=/ref%20%22page:(.*?)%22/,a=n.match(s);a?this.changePage.emit(a[1]):window.open(n,"_blank")}initViewer(){this.viewer&&(this.viewerContainer.nativeElement.replaceChildren(),this.viewerContainer.nativeElement.className=""),this.viewer=j.factory({el:this.viewerContainer.nativeElement,plugins:[[d,{highlighter:W.default}]],viewer:!0,initialValue:this.data||"",theme:this.currentTheme,customHTMLRenderer:{image:(t=>(n,{getChildrenText:s,skipChildren:a})=>{let{destination:o}=n;if(a(),o.startsWith("image:")){let[c]=o.split(":").reverse();o=t.handbookImagesService.handbookImagesList.find(l=>l.id===c)?.thumbnailUrl??o}return{type:"openTag",tagName:"img",selfClose:!0,attributes:{src:o,alt:s(n)}}})(this)}})}initViewerContent(){this.viewer.setMarkdown(this.data)}subscribeToTheme(){this.currentUserService.webSettingsChanged.pipe(C(this.destroyed$),g(t=>!!t),g(t=>t.theme!==this.currentTheme)).subscribe(t=>{this.currentTheme=t.theme==="default"?this.getDefaultTheme():t.theme,this.initViewer()})}getDefaultTheme(){return window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}};i.\u0275fac=function(n){return new(n||i)(m(U),m(H),m(A))},i.\u0275cmp=_({type:i,selectors:[["dvls-doc-markdown-viewer"]],viewQuery:function(n,s){if(n&1&&D(re,5),n&2){let a;N(a=O())&&(s.viewerContainer=a.first)}},inputs:{isMarkdown:"isMarkdown",data:"data",disableLinks:"disableLinks"},outputs:{changePage:"changePage"},features:[M,b],decls:3,vars:0,consts:[["viewerContainer",""],[1,"viewer-container"],[3,"click"]],template:function(n,s){if(n&1){let a=L();S(0,"div",1)(1,"div",2,0),V("click",function(c){return k(a),T(s.onPageLink(c))}),E()()}},styles:["[_nghost-%COMP%]     .viewer-container{height:100%;overflow:auto}[_nghost-%COMP%]     .viewer-container .task-list-item{pointer-events:none}"]});let e=i;return e})()});export{d as a,Q as b,Ce as c,ae as d};
