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

2 lines
6.3 KiB
JavaScript

var e=Object.defineProperty,t=Object.defineProperties,a=Object.getOwnPropertyDescriptors,r=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,s=(t,a,r)=>a in t?e(t,a,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[a]=r,n=(e,t)=>{for(var a in t||(t={}))o.call(t,a)&&s(e,a,t[a]);if(r)for(var a of r(t))i.call(t,a)&&s(e,a,t[a]);return e},c=(e,r)=>t(e,a(r));import{J as l,K as d,C as u,ab as p,a4 as m,ac as f,ad as g,S as h,i as y,s as b,e as w,c as v,a as S,d as O,b as E,Y as j,f as L,E as D,L as T,I as _,A as x,a9 as J,aa as N,N as $,ae as k}from"./vendor-4cf3bda8.js";import{_ as C}from"./preload-helper-b2c28c98.js";import{i as I}from"./loading-1a95bbbb.js";let P;let A;const R={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},V=l(u(R),d(),"codeStore"),H=p([V],(([e],t)=>{t(m(JSON.stringify(e),!0))})),U=e=>{V.update((t=>n(n({},t),e)))};let G=!1;const B=(e,t,a=!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(V).autoSync){const e=confirm("Long diagram detected. Turn off Auto Sync? Click the sync logo to manually sync.");G=!0,e&&U({autoSync:!1})}V.update((r=>c(n({},r),{code:e,updateEditor:t,updateDiagram:a})))},M=(e,t)=>{V.update((a=>c(n({},a),{mermaid:e,updateEditor:t})))},z=e=>{V.update((t=>{const a=JSON.parse(t.mermaid);return a.theme&&!["dark","default"].includes(a.theme)||(a.theme=e?"dark":"default"),c(n({},t),{mermaid:JSON.stringify(a),updateEditor:!0})}))},F=()=>JSON.stringify(f(V)),K=u(void 0);function Y(e){let t,a;return{c(){t=w("div"),a=w("div"),this.h()},l(e){t=v(e,"DIV",{id:!0,class:!0});var r=S(t);a=v(r,"DIV",{id:!0,class:!0}),S(a).forEach(O),r.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(r,o){L(r,t,o),D(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 q(e,t,a){let r;_(e,V,(e=>a(7,r=e)));let o,i="",s="",n=!1,c=!1,l=!0;return x((()=>{V.subscribe((e=>{try{if(o&&e&&(e.updateDiagram||e.autoSync)){if(e.autoSync||J(V,r.updateDiagram=!1,r),a(2,c=!1),l=!0,i===e.code&&s===e.mermaid)return;i=e.code,s=e.mermaid;const t=o.parentElement.parentElement.parentElement.scrollTop;delete o.dataset.processed,N.exports.initialize(Object.assign({},JSON.parse(e.mermaid))),N.exports.render("graph-div",i,(e=>{a(0,o.innerHTML=e,o)})),a(0,o.parentElement.parentElement.parentElement.scrollTop=t,o),a(1,n=!1)}else l?l=!1:a(2,c=!0)}catch(t){console.log("view fail",t),a(1,n=!0)}})),K.subscribe((e=>{void 0===e?a(1,n=!1):(a(1,n=!0),console.log("Error: ",e))}))})),[o,n,c,function(e){$[e?"unshift":"push"]((()=>{o=e,a(0,o)}))}]}class Q extends h{constructor(e){super(),y(this,e,q,Y,b,{})}}const W=l(u("manual"),d(),"autoHistoryMode"),X=l(u([]),d(),"autoHistoryStore"),Z=l(u([]),d(),"manualHistoryStore"),ee=u([]),te=p([W,X,Z,ee],(([e,t,a,r],o)=>{o("auto"===e?t:"manual"===e?a:"loader"===e?r:t)})),ae=e=>{"loader"!==e.type?(e.name=k(2),"auto"===e.type?X.update((t=>(30===t.length&&t.pop(),[e,...t]))):Z.update((t=>[e,...t]))):ee.update((t=>[e,...t]))},re=e=>{("auto"===f(W)?X:Z).update((t=>("loader"!==f(W)&&(t=t.filter((t=>e&&t.time!=e))),t)))},oe=e=>{const t=f(e?X:Z);return t.length>0?JSON.stringify(t[0].state):""},ie=async e=>e.truncated?await(await fetch(e.raw_url)).text():e.content,se=async e=>{const[t,a,r,o]=e.split("github.com").pop().split("/"),{html_url:i,files:s,history:n}=await(await fetch(`https://api.github.com/gists/${r}${o?"/"+o:""}`)).json();if((e=>"code.mmd"in e)(s)){const e=await ie(s["code.mmd"]);let t;"config.json"in s&&(t=await ie(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"},ne=(e,t=e.url)=>{const a=c(n({},R),{code:e.code,loader:{type:"gist",config:{url:t}}});return e.config&&(a.mermaid=e.config),a},ce={gist:async e=>{try{const[t,a,r,o]=e.split("github.com").pop().split("/"),{history:i}=await(await fetch(`https://api.github.com/gists/${r}${o?"/"+o:""}`)).json(),s=[];for(const e of i){const t=await se(e.url).catch((()=>{}));t&&s.push(t)}if(0===s.length)throw"Invalid gist provided";s.reverse();const n=ne(s.slice(-1).pop(),e);for(const e of s)ae({state:ne(e),time:e.time,type:"loader",url:e.url,name:`${e.author} v${e.version}`});return n}catch(t){console.error(t)}}},le=()=>{(e=>{let t;try{const a=g(e);console.log(`Trying to load state: ${a}`),t=JSON.parse(a);const r="string"==typeof t.mermaid?JSON.parse(t.mermaid):t.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,t.mermaid=JSON.stringify(r,null,2)}catch(a){e&&console.error("Init error",a),t=f(V),console.log(t)}U(c(n({},t),{updateEditor:!0}))})(window.location.hash.slice(1))},de=()=>{U({updateDiagram:!0})},ue=async()=>{le(),await I("Loading Gist...",(async()=>{const e=new URLSearchParams(window.location.search);let t,a,r=R,o=!1;const i=e.get("code"),s=e.get("config");if(i&&(t=await(await fetch(i)).text(),o=!0),a=s?await(await fetch(s)).text():R.mermaid,t)r={code:t,mermaid:a,loader:{type:"files",config:{codeURL:i,configURL:s}}};else for(const[n,c]of e.entries())if(n in ce)try{r=await ce[n](c),o=!0;break}catch(l){console.error(l)}o&&U(c(n({},r),{autoSync:!0,updateDiagram:!0,updateEditor:!0}))})().catch(console.error)),de(),H.subscribe((e=>{history.replaceState(void 0,void 0,`#${e}`)})),await(async()=>{if(!P)try{const{Analytics:e}=await C((()=>import("./analytics.browser.es-d53875b8.js")),[]),t=await C((()=>import("./analytics-plugin-ga.browser.es-1cdb0512.js")),[]);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,te as b,V as c,oe as d,ae as e,re as f,F as g,W as h,H as i,K as j,ue as k,ee as l,M as m,de as s,z as t,B as u};