Files
mermaid-live-editor/beta/_app/chunks/util-1bc8bcc1.js
T

2 lines
3.9 KiB
JavaScript

var e=Object.defineProperty,a=Object.defineProperties,t=Object.getOwnPropertyDescriptors,r=Object.getOwnPropertySymbols,s=Object.prototype.hasOwnProperty,o=Object.prototype.propertyIsEnumerable,i=(a,t,r)=>t in a?e(a,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):a[t]=r,n=(e,a)=>{for(var t in a||(a={}))s.call(a,t)&&i(e,t,a[t]);if(r)for(var t of r(a))o.call(a,t)&&i(e,t,a[t]);return e},c=(e,r)=>a(e,t(r));import{a2 as l,a3 as d,C as p,a4 as u,Z as m,a6 as f,a9 as y,S as g,i as h,s as b,e as v,c as O,a as S,d as E,b as w,N as D,f as T,F as j,G as L,H as _,z as C,a8 as x,J}from"./vendor-954b7cab.js";import{_ as N}from"./preload-helper-9f12a5fd.js";let P;let A;const I=l(p({code:"graph TD\n A[Christmas] --\x3e|Get money| B(Go shopping)\n B --\x3e C{Let me think}\n C --\x3e|One| D[Laptop]\n C --\x3e|Two| E[iPhone]\n C --\x3e|Three| F[fa:fa-car Car]\n ",mermaid:JSON.stringify({theme:"default"},null,2),updateEditor:!1,autoSync:!0,updateDiagram:!0}),d(),"codeStore"),k=u([I],(([e],a)=>{a(m(JSON.stringify(e),!0))})),V=e=>{I.update((a=>n(n({},a),e)))};let G=!1;const R=(e,a,t=!1)=>{var r;r=e,P&&(clearTimeout(A),A=setTimeout((function(){const e=r.replace(/^\s*%%.*\n/g,"\n").trimStart().split(" ")[0];console.debug("ga:","send","event","render",e),P.track("render",{graphType:e})}),5e3));if((e.match(/\n/g)||"").length+1>50&&!G&&f(I).autoSync){const e=confirm("Long diagram deteced. Turn off Auto Sync? Click the sync logo to manually sync.");G=!0,e&&V({autoSync:!1})}I.update((r=>c(n({},r),{code:e,updateEditor:a,updateDiagram:t})))},$=(e,a)=>{I.update((t=>c(n({},t),{mermaid:e,updateEditor:a})))},z=()=>JSON.stringify(f(I)),B=p(void 0);function F(e){let a,t;return{c(){a=v("div"),t=v("div"),this.h()},l(e){a=O(e,"DIV",{id:!0,class:!0});var r=S(a);t=O(r,"DIV",{id:!0,class:!0}),S(t).forEach(E),r.forEach(E),this.h()},h(){w(t,"id","container"),w(t,"class","flex-1 overflow-auto"),w(a,"id","view"),w(a,"class","p-2 svelte-5ndy2s"),D(a,"error",e[1]),D(a,"outOfSync",e[2])},m(r,s){T(r,a,s),j(a,t),e[3](t)},p(e,[t]){2&t&&D(a,"error",e[1]),4&t&&D(a,"outOfSync",e[2])},i:L,o:L,d(t){t&&E(a),e[3](null)}}}function H(e,a,t){let r;_(e,I,(e=>t(7,r=e)));const s=window.mermaid;let o,i="",n="",c=!1,l=!1,d=!0;return C((()=>{I.subscribe((e=>{try{if(o&&e&&(e.updateDiagram||e.autoSync)){if(e.autoSync||x(I,r.updateDiagram=!1,r),t(2,l=!1),d=!0,i===e.code&&n===e.mermaid)return;i=e.code,n=e.mermaid;const a=o.parentElement.parentElement.parentElement.scrollTop;delete o.dataset.processed,s.initialize(Object.assign({},JSON.parse(e.mermaid))),s.render("graph-div",i,(e=>{t(0,o.innerHTML=e,o)})),t(0,o.parentElement.parentElement.parentElement.scrollTop=a,o),t(1,c=!1)}else d?d=!1:t(2,l=!0)}catch(a){console.log("view fail",a),t(1,c=!0)}})),B.subscribe((e=>{void 0===e?t(1,c=!1):(t(1,c=!0),console.log("Error: ",e))}))})),[o,c,l,function(e){J[e?"unshift":"push"]((()=>{o=e,t(0,o)}))}]}class M extends g{constructor(e){super(),h(this,e,H,F,b,{})}}const U=()=>{(e=>{let a;try{const t=y(e);console.log(`Tring to load state: ${t}`),a=JSON.parse(t);const r="string"==typeof a.mermaid?JSON.parse(a.mermaid):a.mermaid;r.securityLevel&&"strict"!==r.securityLevel&&confirm(`Removing "securityLevel":"${r.securityLevel}" from the config for safety.\nClick Cancel if you trust the source of this Diagram.`)&&delete r.securityLevel,a.mermaid=JSON.stringify(r,null,2)}catch(t){e&&console.error("Init error",t),a=f(I),console.log(a)}V(c(n({},a),{updateEditor:!0}))})(window.location.hash.slice(1))},Z=()=>{V({updateDiagram:!0})},q=async()=>{U(),Z(),k.subscribe((e=>{history.replaceState(void 0,void 0,`#${e}`)})),await(async()=>{if(!P)try{const{Analytics:e}=await N((()=>import("./analytics.browser.es-eaddcc60.js")),void 0),a=await N((()=>import("./analytics-plugin-ga.browser.es-1cdb0512.js")),void 0);P=e({app:"mermaid-live-editor",plugins:[a.init({trackingId:"UA-153180559-1"})]})}catch{console.info("Analytics blocked ;)")}})(),null==P||P.page()};export{M as V,P as a,k as b,I as c,$ as d,B as e,z as g,q as i,Z as s,R as u};