2 lines
5.9 KiB
JavaScript
2 lines
5.9 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 p,a6 as u,Z as m,a7 as f,a8 as g,S as h,i as y,s as w,e as b,c as v,a as S,d as O,b as E,N as j,f as T,E as D,H as _,G as x,z as L,a3 as $,J as I,a9 as P}from"./vendor-3751e217.js";import{_ as C}from"./preload-helper-9f12a5fd.js";import{i as J}from"./loading-5042d900.js";let N;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},H=l(p(A),d(),"codeStore"),R=u([H],(([e],t)=>{t(m(JSON.stringify(e),!0))})),V=e=>{H.update((t=>n(n({},t),e)))};let G=!1;const U=(e,t,a=!1)=>{var o;o=e,N&&(clearTimeout(k),k=setTimeout((function(){const e=o.replace(/^\s*%%.*\n/g,"\n").trimStart().split(" ")[0];console.debug("ga:","send","event","render",e),N.track("render",{graphType:e})}),5e3));if((e.match(/\n/g)||"").length+1>50&&!G&&f(H).autoSync){const e=confirm("Long diagram deteced. Turn off Auto Sync? Click the sync logo to manually sync.");G=!0,e&&V({autoSync:!1})}H.update((o=>c(n({},o),{code:e,updateEditor:t,updateDiagram:a})))},M=(e,t)=>{H.update((a=>c(n({},a),{mermaid:e,updateEditor:t})))},z=()=>JSON.stringify(f(H)),B=p(void 0);function F(e){let t,a;return{c(){t=b("div"),a=b("div"),this.h()},l(e){t=v(e,"DIV",{id:!0,class:!0});var o=S(t);a=v(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){T(o,t,r),D(t,a),e[3](a)},p(e,[a]){2&a&&j(t,"error",e[1]),4&a&&j(t,"outOfSync",e[2])},i:_,o:_,d(a){a&&O(t),e[3](null)}}}function Z(e,t,a){let o;x(e,H,(e=>a(6,o=e)));const r=window.mermaid;let i,s="",n=!1,c=!1,l=!0;return L((()=>{H.subscribe((e=>{try{if(i&&e&&(e.updateDiagram||e.autoSync)){e.autoSync||$(H,o.updateDiagram=!1,o),a(2,c=!1),l=!0,s=e.code;const t=i.parentElement.parentElement.parentElement.scrollTop;a(0,i.innerHTML=s,i),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,n=!1)}else l?l=!1:a(2,c=!0)}catch(t){console.log("view fail",t),a(1,n=!0)}})),B.subscribe((e=>{void 0===e?a(1,n=!1):(a(1,n=!0),console.log("Error: ",e))}))})),[i,n,c,function(e){I[e?"unshift":"push"]((()=>{i=e,a(0,i)}))}]}class q extends h{constructor(e){super(),y(this,e,Z,F,w,{})}}const K=l(p("manual"),d(),"autoHistoryMode"),Q=l(p([]),d(),"autoHistoryStore"),W=l(p([]),d(),"manualHistoryStore"),X=p([]),Y=u([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=P(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=>{const t=c(n({},A),{code:e.code,loader:{type:"gist",config:{url:e.url}}});return e.config&&(t.mermaid=e.config),t},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());n.loader.config.url=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),"string"!=typeof t.mermaid&&(t.mermaid=JSON.stringify(t.mermaid,null,2))}catch(a){e&&console.error("Init error",a),t=f(H),console.log(t)}V(c(n({},t),{updateEditor:!0}))})(window.location.hash.slice(1))},ce=()=>{V({updateDiagram:!0})},le=async()=>{ne(),await J("Loading Gist...",(async()=>{const e=new URLSearchParams(window.location.search);let t,a,o=A;const r=e.get("code"),i=e.get("config");if(r&&(t=await(await fetch(r)).text()),a=i?await(await fetch(i)).text():A.mermaid,t)o={code:t,mermaid:a,autoSync:!0,updateDiagram:!0,updateEditor:!0,loader:{type:"files",config:{codeURL:r,configURL:i}}};else for(const[n,c]of e.entries())if(n in se)try{o=await se[n](c);break}catch(s){console.error(s)}V(o)})().catch(console.error)),ce(),R.subscribe((e=>{history.replaceState(void 0,void 0,`#${e}`)})),await(async()=>{if(!N)try{const{Analytics:e}=await C((()=>import("./analytics.browser.es-eaddcc60.js")),void 0),t=await C((()=>import("./analytics-plugin-ga.browser.es-1cdb0512.js")),void 0);N=e({app:"mermaid-live-editor",plugins:[t.init({trackingId:"UA-153180559-1"})]})}catch{console.info("Analytics blocked ;)")}})(),null==N||N.page()};export{q as V,N as a,Y as b,H as c,ae as d,ee as e,te as f,z as g,K as h,R as i,B as j,le as k,X as l,M as m,ce as s,U as u};
|