Files
mermaid-live-editor/beta/_app/chunks/util-34e0aa3e.js
T

2 lines
6.1 KiB
JavaScript

var e=Object.defineProperty,t=Object.defineProperties,a=Object.getOwnPropertyDescriptors,o=Object.getOwnPropertySymbols,r=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,s=(t,a,o)=>a in t?e(t,a,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[a]=o,n=(e,t)=>{for(var a in t||(t={}))r.call(t,a)&&s(e,a,t[a]);if(o)for(var a of o(t))i.call(t,a)&&s(e,a,t[a]);return e},c=(e,o)=>t(e,a(o));import{a4 as l,a5 as d,C as u,a6 as p,Z as m,a7 as f,a8 as g,S as h,i as y,s as w,e as v,c as b,a as S,d as O,b as E,N as j,f as D,E as L,H as T,G as _,z as x,a3 as $,J as C,a9 as I}from"./vendor-5083b08a.js";import{_ as J}from"./preload-helper-9f12a5fd.js";import{i as N}from"./loading-bf553550.js";let P;let k;const A={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},R=l(u(A),d(),"codeStore"),H=p([R],(([e],t)=>{t(m(JSON.stringify(e),!0))})),V=e=>{R.update((t=>n(n({},t),e)))};let G=!1;const U=(e,t,a=!1)=>{var o;o=e,P&&(clearTimeout(k),k=setTimeout((function(){const e=o.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(R).autoSync){const e=confirm("Long diagram deteced. Turn off Auto Sync? Click the sync logo to manually sync.");G=!0,e&&V({autoSync:!1})}R.update((o=>c(n({},o),{code:e,updateEditor:t,updateDiagram:a})))},z=(e,t)=>{R.update((a=>c(n({},a),{mermaid:e,updateEditor:t})))},B=()=>JSON.stringify(f(R)),M=u(void 0);function F(e){let t,a;return{c(){t=v("div"),a=v("div"),this.h()},l(e){t=b(e,"DIV",{id:!0,class:!0});var o=S(t);a=b(o,"DIV",{id:!0,class:!0}),S(a).forEach(O),o.forEach(O),this.h()},h(){E(a,"id","container"),E(a,"class","flex-1 overflow-auto"),E(t,"id","view"),E(t,"class","p-2 svelte-5ndy2s"),j(t,"error",e[1]),j(t,"outOfSync",e[2])},m(o,r){D(o,t,r),L(t,a),e[3](a)},p(e,[a]){2&a&&j(t,"error",e[1]),4&a&&j(t,"outOfSync",e[2])},i:T,o:T,d(a){a&&O(t),e[3](null)}}}function Z(e,t,a){let o;_(e,R,(e=>a(7,o=e)));const r=window.mermaid;let i,s="",n="",c=!1,l=!1,d=!0;return x((()=>{R.subscribe((e=>{try{if(i&&e&&(e.updateDiagram||e.autoSync)){if(e.autoSync||$(R,o.updateDiagram=!1,o),a(2,l=!1),d=!0,s===e.code&&n===e.mermaid)return;s=e.code,n=e.mermaid;const t=i.parentElement.parentElement.parentElement.scrollTop;delete i.dataset.processed,r.initialize(Object.assign({},JSON.parse(e.mermaid))),r.render("graph-div",s,(e=>{a(0,i.innerHTML=e,i)})),a(0,i.parentElement.parentElement.parentElement.scrollTop=t,i),a(1,c=!1)}else d?d=!1:a(2,l=!0)}catch(t){console.log("view fail",t),a(1,c=!0)}})),M.subscribe((e=>{void 0===e?a(1,c=!1):(a(1,c=!0),console.log("Error: ",e))}))})),[i,c,l,function(e){C[e?"unshift":"push"]((()=>{i=e,a(0,i)}))}]}class q extends h{constructor(e){super(),y(this,e,Z,F,w,{})}}const K=l(u("manual"),d(),"autoHistoryMode"),Q=l(u([]),d(),"autoHistoryStore"),W=l(u([]),d(),"manualHistoryStore"),X=u([]),Y=p([K,Q,W,X],(([e,t,a,o],r)=>{r("auto"===e?t:"manual"===e?a:"loader"===e?o:t)})),ee=e=>{"loader"!==e.type?(e.name=I(2),"auto"===e.type?Q.update((t=>(30===t.length&&t.pop(),[e,...t]))):W.update((t=>[e,...t]))):X.update((t=>[e,...t]))},te=e=>{("auto"===f(K)?Q:W).update((t=>("loader"!==f(K)&&(t=t.filter((t=>e&&t.time!=e))),t)))},ae=e=>{const t=f(e?Q:W);return t.length>0?JSON.stringify(t[0].state):""},oe=async e=>e.truncated?await(await fetch(e.raw_url)).text():e.content,re=async e=>{const[t,a,o,r]=e.split("github.com").pop().split("/"),{html_url:i,files:s,history:n}=await(await fetch(`https://api.github.com/gists/${o}${r?"/"+r:""}`)).json();if((e=>"code.mmd"in e)(s)){const e=await oe(s["code.mmd"]);let t;"config.json"in s&&(t=await oe(s["config.json"]));const a=n[0];return{url:`${i}/${a.version}`,code:e,config:t,author:a.user.login,time:new Date(a.committed_at).getTime(),version:a.version.slice(-7)}}throw"Invalid gist provided"},ie=(e,t=e.url)=>{const a=c(n({},A),{code:e.code,loader:{type:"gist",config:{url:t}}});return e.config&&(a.mermaid=e.config),a},se={gist:async e=>{try{const[t,a,o,r]=e.split("github.com").pop().split("/"),{history:i}=await(await fetch(`https://api.github.com/gists/${o}${r?"/"+r:""}`)).json(),s=[];for(const e of i){const t=await re(e.url).catch((()=>{}));t&&s.push(t)}if(0===s.length)throw"Invalid gist provided";s.reverse();const n=ie(s.slice(-1).pop(),e);for(const e of s)ee({state:ie(e),time:e.time,type:"loader",url:e.url,name:`${e.author} v${e.version}`});return n}catch(t){console.error(t)}}},ne=()=>{(e=>{let t;try{const a=g(e);console.log(`Tring to load state: ${a}`),t=JSON.parse(a);const o="string"==typeof t.mermaid?JSON.parse(t.mermaid):t.mermaid;o.securityLevel&&"strict"!==o.securityLevel&&confirm(`Removing "securityLevel":"${o.securityLevel}" from the config for safety.\nClick Cancel if you trust the source of this Diagram.`)&&delete o.securityLevel,t.mermaid=JSON.stringify(o,null,2)}catch(a){e&&console.error("Init error",a),t=f(R),console.log(t)}V(c(n({},t),{updateEditor:!0}))})(window.location.hash.slice(1))},ce=()=>{V({updateDiagram:!0})},le=async()=>{ne(),await N("Loading Gist...",(async()=>{const e=new URLSearchParams(window.location.search);let t,a,o=A,r=!1;const i=e.get("code"),s=e.get("config");if(i&&(t=await(await fetch(i)).text(),r=!0),a=s?await(await fetch(s)).text():A.mermaid,t)o={code:t,mermaid:a,loader:{type:"files",config:{codeURL:i,configURL:s}}};else for(const[n,c]of e.entries())if(n in se)try{o=await se[n](c),r=!0;break}catch(l){console.error(l)}r&&V(c(n({},o),{autoSync:!0,updateDiagram:!0,updateEditor:!0}))})().catch(console.error)),ce(),H.subscribe((e=>{history.replaceState(void 0,void 0,`#${e}`)})),await(async()=>{if(!P)try{const{Analytics:e}=await J((()=>import("./analytics.browser.es-eaddcc60.js")),void 0),t=await J((()=>import("./analytics-plugin-ga.browser.es-1cdb0512.js")),void 0);P=e({app:"mermaid-live-editor",plugins:[t.init({trackingId:"UA-153180559-1"})]})}catch{console.info("Analytics blocked ;)")}})(),null==P||P.page()};export{q as V,P as a,Y as b,R as c,ae as d,ee as e,te as f,B as g,K as h,H as i,M as j,le as k,X as l,z as m,ce as s,U as u};