2 lines
4.4 KiB
JavaScript
2 lines
4.4 KiB
JavaScript
var K=Object.defineProperty,X=Object.defineProperties;var Y=Object.getOwnPropertyDescriptors;var E=Object.getOwnPropertySymbols;var x=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable;var O=(t,e,a)=>e in t?K(t,e,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[e]=a,_=(t,e)=>{for(var a in e||(e={}))x.call(e,a)&&O(t,a,e[a]);if(E)for(var a of E(e))B.call(e,a)&&O(t,a,e[a]);return t},w=(t,e)=>X(t,Y(e));import{D as f,S as Q,i as W,s as Z,e as U,c as j,a as G,d as S,b as p,$ as g,g as $,G as tt,R as T,K as et,v as at,ae as ot,af as F,U as N,L as v,M as b,N as st,ag as rt,P as D}from"./vendor-0937b0aa.js";import{c as H,e as I,f as R,i as it,h as nt,j as ct,a as lt,k as ut}from"./state-c0db3490.js";const dt=f(void 0);function ft(t){let e,a;return{c(){e=U("div"),a=U("div"),this.h()},l(s){e=j(s,"DIV",{id:!0,class:!0});var o=G(e);a=j(o,"DIV",{id:!0,class:!0}),G(a).forEach(S),o.forEach(S),this.h()},h(){p(a,"id","container"),p(a,"class","flex-1 overflow-auto"),p(e,"id","view"),p(e,"class","p-2 svelte-5ndy2s"),g(e,"error",t[2]),g(e,"outOfSync",t[3])},m(s,o){$(s,e,o),tt(e,a),t[4](a),t[5](e)},p(s,[o]){o&4&&g(e,"error",s[2]),o&8&&g(e,"outOfSync",s[3])},i:T,o:T,d(s){s&&S(e),t[4](null),t[5](null)}}}function pt(t,e,a){let s;et(t,H,i=>a(9,s=i));let o="",u="",r,c,n=!1,l=!1,d=!0;at(()=>{H.subscribe(i=>{try{if(r&&i&&(i.updateDiagram||i.autoSync)){if(i.autoSync||ot(H,s.updateDiagram=!1,s),a(3,l=!1),d=!0,o===i.code&&u===i.mermaid)return;o=i.code,u=i.mermaid;const y=c.parentElement.scrollTop;delete r.dataset.processed,F.initialize(Object.assign({},JSON.parse(i.mermaid))),F.render("graph-div",o,z=>{a(0,r.innerHTML=z,r)}),a(1,c.parentElement.scrollTop=y,c),a(2,n=!1)}else d?d=!1:a(3,l=!0)}catch(y){console.log("view fail",y),a(2,n=!0)}}),dt.subscribe(i=>{typeof i=="undefined"?a(2,n=!1):(a(2,n=!0),console.log("Error: ",i))})});function J(i){N[i?"unshift":"push"](()=>{r=i,a(0,r)})}function q(i){N[i?"unshift":"push"](()=>{c=i,a(1,c)})}return[r,c,n,l,J,q]}class It extends Q{constructor(e){super();W(this,e,pt,ft,Z,{})}}const gt=30,L=v(f("manual"),b(),"autoHistoryMode"),m=v(f([]),b(),"autoHistoryStore"),h=v(f([]),b(),"manualHistoryStore"),V=f([]),Lt=st([L,m,h,V],([t,e,a,s],o)=>{o(t==="auto"?e:t==="manual"?a:t==="loader"?s:e)}),mt=t=>{if(t.type==="loader"){V.update(e=>[t,...e]);return}if(t.name=rt(2),t.type!=="auto"){h.update(e=>[t,...e]);return}m.update(e=>(e.length===gt&&e.pop(),[t,...e]))},Et=t=>{(D(L)==="auto"?m:h).update(e=>(D(L)!=="loader"&&(e=e.filter(a=>t&&a.time!=t)),e))},Ot=t=>{const e=D(t?m:h);return e.length>0?JSON.stringify(e[0].state):""},k="code.mmd",M="config.json",ht=t=>k in t,P=async t=>t.truncated?await(await fetch(t.raw_url)).text():t.content,yt=async t=>{const[e,a,s,o]=t.split("github.com").pop().split("/"),{html_url:u,files:r,history:c}=await(await fetch(`https://api.github.com/gists/${s}${o?"/"+o:""}`)).json();if(ht(r)){const n=await P(r[k]);let l;M in r&&(l=await P(r[M]));const d=c[0];return{url:`${u}/${d.version}`,code:n,config:l,author:d.user.login,time:new Date(d.committed_at).getTime(),version:d.version.slice(-7)}}else throw"Invalid gist provided"},A=(t,e=t.url)=>{const a=w(_({},I),{code:t.code,loader:{type:"gist",config:{url:e}}});return t.config&&(a.mermaid=t.config),a},_t=async t=>{try{const[e,a,s,o]=t.split("github.com").pop().split("/"),{history:u}=await(await fetch(`https://api.github.com/gists/${s}${o?"/"+o:""}`)).json(),r=[];for(const n of u){const l=await yt(n.url).catch(()=>{});l&&r.push(l)}if(r.length===0)throw"Invalid gist provided";r.reverse();const c=A(r.slice(-1).pop(),t);for(const n of r)mt({state:A(n),time:n.time,type:"loader",url:n.url,name:`${n.author} v${n.version}`});return c}catch(e){console.error(e)}},C={gist:_t},wt=async()=>{const t=new URLSearchParams(window.location.search);let e=I,a,s,o=!1;const u=t.get("code"),r=t.get("config");if(u&&(a=await(await fetch(u)).text(),o=!0),r?s=await(await fetch(r)).text():s=I.mermaid,a)e={code:a,mermaid:s,loader:{type:"files",config:{codeURL:u,configURL:r}}};else for(const[c,n]of t.entries())if(c in C)try{e=await C[c](n),o=!0;break}catch(l){console.error(l)}o&&R(w(_({},e),{autoSync:!0,updateDiagram:!0,updateEditor:!0}))},St=()=>{ut(window.location.hash.slice(1))},vt=()=>{R({updateDiagram:!0})},Ut=async()=>{var t;St(),await it("Loading Gist...",wt().catch(console.error)),vt(),nt(),await ct(),(t=lt)==null||t.page()};export{It as V,Lt as a,mt as b,Et as c,dt as e,Ot as g,L as h,Ut as i,V as l,vt as s};
|