@sava-info-systems/api-maker-with-extensions 2.2.1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ window.DIAGRAM_DATA=null;const ACCENT=[117,0,8];function ac(t=1,e=1){const[n,a,o]=ACCENT,s=Math.min(255,Math.round(n*t)),l=Math.min(255,Math.round(a*t)),c=Math.min(255,Math.round(o*t));return e<1?`rgba(${s},${l},${c},${e})`:"#"+[s,l,c].map((t=>t.toString(16).padStart(2,"0"))).join("")}const C={bg:"#0d1117",grid:"rgba(48,54,61,0.35)",instBg:"rgba(6,9,15,0.98)",instBorder:"#303539",instHeader1:"#131920",instHeader2:"#0e1318",dbBg:"rgba(22,27,34,0.97)",dbBorder:"#424a4e",dbHeader1:"#1c2128",dbHeader2:"#22272e",tableBg:"#0d1117",tableBgHov:"#141414",tableBgSel:"#0a0a0a",tableBorder:"#424a4e",tableBorderHov:ac(1.44,1),tableHeader1:"#1f2937",tableHeader2:"#111827",tableHdrLine:ac(1,.5),tableHeaderSel1:ac(1.18),tableHeaderSel2:ac(.52),tableAccent:ac(),tableAccentSel:ac(1.44),text:"#e6edf3",textMuted:"#8b949e",textDim:"#484f58",pk:"#fbbf24",fk:"#22d3ee",virtual:"#975d02",required:"#f87171",glow:"rgba(96,165,250,0.6)",types:{string:"#60a5fa",number:"#a78bfa",boolean:"#34d399",date:"#fb923c",objectId:"#fbbf24",file:"#c084fc",files:"#c084fc"},rels:[["#60a5fa","#22d3ee"],["#f472b6","#c084fc"],["#34d399","#60a5fa"],["#fbbf24","#fb923c"],["#a78bfa","#f472b6"],["#22d3ee","#34d399"]]},L={TABLE_MIN_W:230,TABLE_MAX_W:320,TABLE_HDR_H:40,TABLE_ROW_H:27,TABLE_PAD_X:12,TABLE_FOOT_PAD:6,TABLE_R:8,DB_HDR_H:44,DB_PAD_X:40,DB_PAD_Y:68,DB_GAP_X:56,DB_GAP_Y:48,DB_R:12,INST_HDR_H:52,INST_PAD_X:52,INST_PAD_Y:68,INST_GAP:120,INST_R:16,GRID_SIZE:40,TENSION_MIN:60,TENSION_MAX:220},canvas=document.getElementById("canvas"),ctx=canvas.getContext("2d"),S={rawData:[],tables:{},databases:{},instances:{},relations:[],panX:0,panY:0,zoom:1,vw:0,vh:0,selected:null,hovTable:null,hovRow:-1,dragging:null,mouseDown:!1,mouseStartX:0,mouseStartY:0,mouseMoved:!1,mouseTarget:null,hovConn:null,connDrag:null,raf:null,pulseT:0,ripples:[],animating:!1,_headerObsCache:null,_layoutVersion:0,_gradCache:new Map,_lastPulse:-1};function invalidateLayout(){S._layoutVersion++,S._headerObsCache=null,S._gradCache.clear()}function resize(){const t=window.devicePixelRatio||1;S.vw=window.innerWidth,S.vh=window.innerHeight-40,canvas.style.width=S.vw+"px",canvas.style.height=S.vh+"px",canvas.width=S.vw*t,canvas.height=S.vh*t,ctx.setTransform(t,0,0,t,0,0),scheduleRender()}function parseData(t){S.rawData=t,S.tables={},S.databases={},S.instances={},S.relations=[],t.forEach((t=>{const e=t.instanceName||"default",n=t.databaseName||"default",a=t.collectionName,o=`${e}\0${n}\0${a}`,s=t.calculated?.primaryKey||null,l=buildColumns(t.properties||{},s);S.tables[o]={key:o,inst:e,db:n,coll:a,columns:l,pk:s,x:0,y:0,w:0,h:0},S.instances[e]||(S.instances[e]={name:e,databases:[]});const c=`${e}\0${n}`;S.databases[c]||(S.databases[c]={key:c,inst:e,name:n,tables:[]},S.instances[e].databases.push(c)),S.databases[c].tables.includes(o)||S.databases[c].tables.push(o)}));let e=0;t.forEach((t=>{const n=t.instanceName||"default",a=t.databaseName||"default",o=t.collectionName,s=`${n}\0${a}\0${o}`;!function t(o,l){Object.entries(o).forEach((([o,c])=>{const r=l?l+"."+o:o;if(Array.isArray(c)&&(c=c[0]??{}),"object"!=typeof c||!c)return;if(!(c.__type||c.collection||c.table||c.instance||c.isVirtualField))return void t(c,r);const i=c.collection||c.table;if(!i)return;const x=`${c.instance||n}\0${c.database||a}\0${i}`;if(!S.tables[x])return;const d=S.tables[x];S.relations.push({fromTable:s,fromCol:r,toTable:x,toCol:d.pk||"_id",color:C.rels[e%C.rels.length],idx:e}),e++}))}(t.properties||{},"")})),computeTableSizes(),autoArrange()}function buildColumns(t,e,n,a){n=n||"",a=a||0;const o=[];return Object.entries(t).forEach((([t,s])=>{const l=n?n+"."+t:t;let c=!1;if(Array.isArray(s)&&(c=!0,s=s[0]??{}),"string"==typeof s)return void o.push({name:l,depth:a,type:s,isArray:c,isPK:l===e,isFK:!1,isVirtual:!1,isAutoIncDB:!1,isAutoIncAM:!1,validations:{},conversions:{},targetInst:null,targetDb:null,targetColl:null,targetCol:null});const r=s||{};if(!(r.__type||r.collection||r.table||r.instance||r.isVirtualField))return o.push({name:l,depth:a,type:"object",isArray:c,isPK:!1,isFK:!1,isVirtual:!1,isAutoIncDB:!1,isAutoIncAM:!1,isGroupHeader:!0,validations:{},conversions:{},targetInst:null,targetDb:null,targetColl:null,targetCol:null}),void o.push(...buildColumns(r,e,l,a+1));const i=r.collection||r.table||null;o.push({name:l,depth:a,type:r.__type||"object",isArray:c,isPK:l===e||!!r.isPrimaryKey,isFK:!!i&&!r.isVirtualField,isVirtual:!!r.isVirtualField,isAutoIncDB:!!r.isAutoIncrementByDB,isAutoIncAM:!!r.isAutoIncrementByAM,validations:r.validations||{},conversions:r.conversions||{},targetInst:r.instance||null,targetDb:r.database||null,targetColl:i,targetCol:r.column||null})})),o}function computeTableSizes(){ctx.save(),Object.values(S.tables).forEach((t=>{ctx.font='bold 13px "JetBrains Mono", monospace';let e=ctx.measureText(t.coll).width+64;ctx.font='11px "JetBrains Mono", monospace',t.columns.forEach((t=>{const n=10*(t.depth||0),a=t.name.includes(".")?t.name.split(".").pop():t.name,o=t.isGroupHeader?a+(t.isArray?" []":" {}"):a+(t.isArray?" []":""),s=t.isGroupHeader?"":t.type||"",l=ctx.measureText(o).width+n+(s?ctx.measureText(s).width+14:0)+(t.isGroupHeader?0:13*countIcons(t))+36;l>e&&(e=l)})),t.w=Math.max(L.TABLE_MIN_W,Math.min(L.TABLE_MAX_W,Math.ceil(e))),t.h=L.TABLE_HDR_H+t.columns.length*L.TABLE_ROW_H+L.TABLE_FOOT_PAD})),ctx.restore()}function countIcons(t){const e=t.validations,n=t.conversions;let a=1;return t.isVirtual&&a++,e.required&&a++,e.unique&&a++,e.email&&a++,e.enum&&a++,n.encryption&&a++,n.hashing&&a++,(n.defaults?.defaultFun||n.defaults?.defaultValue)&&a++,a}function autoArrange(){const t=L.DB_GAP_Y;let e=L.INST_PAD_X;Object.values(S.instances).forEach((n=>{let a=L.INST_HDR_H+L.INST_PAD_Y,o=0;n.databases.forEach((n=>{const s=S.databases[n],l=s.tables,c=computeTableLevels(l),r=l.length>0?Math.max(...l.map((t=>c[t]??0))):0,i=Array.from({length:r+1},(()=>[]));l.forEach((t=>i[c[t]??0].push(t)));const x=e+L.INST_PAD_X+L.DB_PAD_X,d=a+L.INST_PAD_Y+L.DB_HDR_H+L.DB_PAD_Y;let u=x,h=0;i.forEach((e=>{if(0!==e.length)for(let n=0;n<e.length;n+=3){const a=e.slice(n,n+3);let o=d,s=0;a.forEach((e=>{const n=S.tables[e];n.x=u,n.y=o,o+=n.h+t,s=Math.max(s,n.w)})),h=Math.max(h,o-d-t),u+=s+180}}));const f=u-x-180;s._layoutW=Math.max(f,L.TABLE_MIN_W)+2*L.DB_PAD_X,s._layoutH=h+L.DB_HDR_H+2*L.DB_PAD_Y,o=Math.max(o,s._layoutW),a+=s._layoutH+t})),e+=o+2*L.INST_PAD_X+L.INST_GAP})),centerView()}function computeTableLevels(t){if(!t||0===t.length)return{};const e=new Set(t),n={},a={};t.forEach((t=>{n[t]=[],a[t]=0})),S.relations.forEach((t=>{t.fromTable!==t.toTable&&e.has(t.fromTable)&&e.has(t.toTable)&&(n[t.fromTable].includes(t.toTable)||(n[t.fromTable].push(t.toTable),a[t.toTable]++))}));const o={};t.forEach((t=>{o[t]=0}));const s={...a},l=t.filter((t=>0===s[t]));let c=0;for(;c<l.length;){const t=l[c++];n[t].forEach((e=>{o[e]=Math.max(o[e],o[t]+1),s[e]--,0===s[e]&&l.push(e)}))}return o}function dbBounds(t){const e=S.databases[t];let n=1/0,a=1/0,o=-1/0,s=-1/0;return e.tables.forEach((t=>{const e=S.tables[t];n=Math.min(n,e.x),a=Math.min(a,e.y),o=Math.max(o,e.x+e.w),s=Math.max(s,e.y+e.h)})),{x:n-L.DB_PAD_X,y:a-L.DB_HDR_H-L.DB_PAD_Y,w:o-n+2*L.DB_PAD_X,h:s-a+L.DB_HDR_H+2*L.DB_PAD_Y}}function instBounds(t){const e=S.instances[t];let n=1/0,a=1/0,o=-1/0,s=-1/0;return e.databases.forEach((t=>{const e=dbBounds(t);n=Math.min(n,e.x),a=Math.min(a,e.y),o=Math.max(o,e.x+e.w),s=Math.max(s,e.y+e.h)})),{x:n-L.INST_PAD_X,y:a-L.INST_HDR_H-L.INST_PAD_Y,w:o-n+2*L.INST_PAD_X,h:s-a+L.INST_HDR_H+2*L.INST_PAD_Y}}function centerView(){if(!Object.keys(S.instances).length)return;let t=1/0,e=1/0,n=-1/0,a=-1/0;Object.keys(S.instances).forEach((o=>{const s=instBounds(o);t=Math.min(t,s.x),e=Math.min(e,s.y),n=Math.max(n,s.x+s.w),a=Math.max(a,s.y+s.h)}));const o=n-t,s=a-e;S.zoom=Math.max(.1,Math.min((S.vw-48)/o,(S.vh-48)/s)),S.panX=(S.vw-o*S.zoom)/2-t*S.zoom,S.panY=(S.vh-s*S.zoom)/2-e*S.zoom,updateZoomLabel()}function scheduleRender(){S.animating||requestAnimationFrame(renderFrame)}function startAnimation(){S.animating||(S.animating=!0,requestAnimationFrame(renderFrame))}function renderFrame(t){S.pulseT=(t||0)/1e3;const e=.5*Math.sin(2.5*S.pulseT)+.5,n=S.ripples.length>0||S.selected;n&&Math.abs(e-S._lastPulse)<.005&&!S.ripples.length?requestAnimationFrame(renderFrame):(S._lastPulse=e,render(),n?requestAnimationFrame(renderFrame):S.animating=!1)}function screenToWorldRect(){return{x:-S.panX/S.zoom,y:-S.panY/S.zoom,w:S.vw/S.zoom,h:S.vh/S.zoom}}function isRectVisible(t,e,n,a,o){return t<o.x+o.w&&t+n>o.x&&e<o.y+o.h&&e+a>o.y}function render(){ctx.clearRect(0,0,S.vw,S.vh),ctx.fillStyle=C.bg,ctx.fillRect(0,0,S.vw,S.vh),drawGrid(),ctx.save(),ctx.translate(S.panX,S.panY),ctx.scale(S.zoom,S.zoom);const t=screenToWorldRect();Object.keys(S.instances).forEach((e=>{const n=instBounds(e);isRectVisible(n.x,n.y,n.w,n.h,t)&&drawInstanceBox(e)})),Object.keys(S.databases).forEach((e=>{const n=dbBounds(e);isRectVisible(n.x,n.y,n.w,n.h,t)&&drawDatabaseBox(e)})),Object.values(S.tables).forEach((e=>{isRectVisible(e.x,e.y,e.w,e.h,t)&&drawTable(e)})),drawRelations(t),drawRipples(),ctx.restore()}function drawGrid(){const t=L.GRID_SIZE*S.zoom,e=(S.panX%t+t)%t,n=(S.panY%t+t)%t;ctx.save(),ctx.strokeStyle=C.grid,ctx.lineWidth=.5,ctx.beginPath();for(let n=e;n<S.vw;n+=t)ctx.moveTo(n,0),ctx.lineTo(n,S.vh);for(let e=n;e<S.vh;e+=t)ctx.moveTo(0,e),ctx.lineTo(S.vw,e);ctx.stroke(),ctx.fillStyle="rgba(48,54,61,0.6)",ctx.beginPath();for(let a=e;a<S.vw;a+=t)for(let e=n;e<S.vh;e+=t)ctx.moveTo(a+.7,e),ctx.arc(a,e,.7,0,2*Math.PI);ctx.fill(),ctx.restore()}function drawInstanceBox(t){const e=instBounds(t),n=L.INST_R;ctx.save(),ctx.shadowBlur=0,ctx.beginPath(),roundRect(ctx,e.x,e.y,e.w,e.h,n),ctx.clip(),ctx.fillStyle=C.instBg,ctx.fillRect(e.x,e.y,e.w,e.h);const a=ctx.createLinearGradient(e.x,e.y,e.x+e.w,e.y+e.h);a.addColorStop(0,"rgba(29,78,216,0.06)"),a.addColorStop(1,"rgba(6,182,212,0.04)"),ctx.fillStyle=a,ctx.fillRect(e.x,e.y,e.w,e.h),ctx.restore(),ctx.shadowBlur=0;const o=L.INST_HDR_H;ctx.save(),ctx.beginPath(),roundRect(ctx,e.x,e.y,e.w,o,[n,n,0,0]),ctx.clip();const s=ctx.createLinearGradient(e.x,e.y,e.x+e.w,e.y);s.addColorStop(0,C.instHeader1),s.addColorStop(1,C.instHeader2),ctx.fillStyle=s,ctx.fillRect(e.x,e.y,e.w,o),ctx.fillStyle="rgba(255,255,255,0.04)",ctx.fillRect(e.x,e.y,e.w,1),ctx.restore(),ctx.strokeStyle=C.instBorder,ctx.lineWidth=1,ctx.beginPath(),roundRect(ctx,e.x,e.y,e.w,e.h,n),ctx.stroke(),drawServerIcon(e.x+14,e.y+12,28,28),ctx.fillStyle="#fff",ctx.font='bold 14px "JetBrains Mono", monospace',ctx.textBaseline="middle",ctx.fillText(t.toUpperCase(),e.x+50,e.y+o/2),ctx.font='9px "JetBrains Mono", monospace';const l="INSTANCE",c=ctx.measureText(l).width+14;ctx.fillStyle="rgba(255,255,255,0.1)",roundRectFill(ctx,e.x+e.w-c-10,e.y+o/2-9,c,18,9),ctx.fillStyle="rgba(255,255,255,0.55)",ctx.fillText(l,e.x+e.w-c-3,e.y+o/2),ctx.textBaseline="alphabetic"}function drawDatabaseBox(t){const e=dbBounds(t),n=S.databases[t],a=L.DB_R;ctx.save(),ctx.beginPath(),roundRect(ctx,e.x,e.y,e.w,e.h,a),ctx.clip(),ctx.fillStyle=C.dbBg,ctx.fillRect(e.x,e.y,e.w,e.h),ctx.restore();const o=L.DB_HDR_H;ctx.save(),ctx.beginPath(),roundRect(ctx,e.x,e.y,e.w,o,[a,a,0,0]),ctx.clip();const s=ctx.createLinearGradient(e.x,e.y,e.x+e.w,e.y);s.addColorStop(0,C.dbHeader1),s.addColorStop(1,C.dbHeader2),ctx.fillStyle=s,ctx.fillRect(e.x,e.y,e.w,o),ctx.restore(),ctx.strokeStyle=C.dbBorder,ctx.lineWidth=1,ctx.beginPath(),roundRect(ctx,e.x,e.y,e.w,e.h,a),ctx.stroke(),drawDBIcon(e.x+12,e.y+8,26,26),ctx.fillStyle="#c9d1d9",ctx.font='bold 12px "JetBrains Mono", monospace',ctx.textBaseline="middle",ctx.fillText(n.name,e.x+44,e.y+o/2),ctx.font='9px "JetBrains Mono", monospace',ctx.fillStyle=C.textMuted;const l="DATABASE";ctx.fillText(l,e.x+e.w-ctx.measureText(l).width-10,e.y+o/2),ctx.textBaseline="alphabetic"}function drawTable(t){const{x:e,y:n,w:a,h:o,coll:s,columns:l,key:c}=t,r=S.selected===c,i=S.hovTable===c,x=.5*Math.sin(3*S.pulseT)+.5,d=L.TABLE_R;ctx.save(),ctx.shadowColor=r?ac(1,.4):"rgba(0,0,0,0.5)",ctx.shadowBlur=r?24+12*x:12,ctx.shadowOffsetY=4,ctx.beginPath(),roundRect(ctx,e,n,a,o,d),ctx.fillStyle="transparent",ctx.fill(),ctx.restore(),ctx.save(),ctx.beginPath(),roundRect(ctx,e,n,a,o,d),ctx.clip(),ctx.fillStyle=r?C.tableBgSel:i?C.tableBgHov:C.tableBg,ctx.fillRect(e,n,a,o);const u=c;let h=S._gradCache.get(u);const f=`${e},${n},${a},${o},${r?1:0},${S._layoutVersion}`;if(!h||h.state!==f){const t=ctx.createLinearGradient(e,n,e,n+o);t.addColorStop(0,"rgba(255,255,255,0.025)"),t.addColorStop(1,"rgba(0,0,0,0)");const s=ctx.createLinearGradient(e,n,e,n+L.TABLE_HDR_H);s.addColorStop(0,r?C.tableHeaderSel1:C.tableHeader1),s.addColorStop(1,r?C.tableHeaderSel2:C.tableHeader2);const l=ctx.createLinearGradient(e,n,e+a,n);l.addColorStop(0,r?C.tableAccentSel:C.tableAccent),l.addColorStop(1,ac(r?1.71:.63)),h={state:f,bgOverlay:t,hGrad:s,accentGrad:l},S._gradCache.set(u,h)}ctx.fillStyle=h.bgOverlay,ctx.fillRect(e,n,a,o),ctx.fillStyle=h.hGrad,ctx.fillRect(e,n,a,L.TABLE_HDR_H),ctx.fillStyle=h.accentGrad,ctx.fillRect(e,n,a,2),ctx.restore(),ctx.fillStyle="#f0f6fc",ctx.font='bold 13px "JetBrains Mono", monospace',ctx.textBaseline="middle",ctx.fillText(s,e+L.TABLE_PAD_X,n+L.TABLE_HDR_H/2+1);const y=String(l.length);ctx.font='10px "JetBrains Mono", monospace';const p=ctx.measureText(y).width+10,b=e+a-p-8,m=n+L.TABLE_HDR_H/2-9;ctx.fillStyle="rgba(255,255,255,0.12)",roundRectFill(ctx,b,m,p,18,9),ctx.fillStyle="rgba(255,255,255,0.55)",ctx.fillText(y,b+5,m+9),ctx.textBaseline="alphabetic",ctx.strokeStyle=C.tableHdrLine,ctx.lineWidth=1,ctx.beginPath(),ctx.moveTo(e+1,n+L.TABLE_HDR_H),ctx.lineTo(e+a-1,n+L.TABLE_HDR_H),ctx.stroke(),l.forEach(((e,n)=>drawColumn(t,e,n)));const g=r?.6+.4*x:i?.4:1;ctx.strokeStyle=r?ac(1.44,g):i?C.tableBorderHov:C.tableBorder,ctx.lineWidth=r?2:1,ctx.beginPath(),roundRect(ctx,e,n,a,o,d),ctx.stroke()}function drawColumn(t,e,n){const{x:a,y:o,w:s,key:l}=t,c=o+L.TABLE_HDR_H+L.TABLE_FOOT_PAD/2+n*L.TABLE_ROW_H,r=L.TABLE_ROW_H,i=S.hovTable===l&&S.hovRow===n;S.selected;e.isGroupHeader?(ctx.fillStyle="rgba(139,148,158,0.05)",ctx.fillRect(a+1,c,s-2,r)):e.isVirtual&&(ctx.fillStyle="rgba(245,158,11,0.07)",ctx.fillRect(a+1,c,s-2,r)),i&&(ctx.fillStyle="rgba(96,165,250,0.07)",ctx.fillRect(a+1,c,s-2,r)),e.isGroupHeader?(ctx.fillStyle="rgba(139,148,158,0.2)",ctx.fillRect(a+1,c+2,2,r-4)):e.isPK?(ctx.fillStyle=C.pk,ctx.fillRect(a+1,c+5,3,r-10)):e.isVirtual?(ctx.fillStyle=C.virtual,ctx.fillRect(a+1,c+5,3,r-10)):e.isFK&&(ctx.fillStyle=C.fk,ctx.fillRect(a+1,c+5,3,r-10));const x=10*(e.depth||0),d=e.name.includes(".")?e.name.split(".").pop():e.name,u=e.isGroupHeader?d+(e.isArray?" []":" {}"):d+(e.isArray?" []":"");ctx.font=e.isPK?'bold 11px "JetBrains Mono", monospace':e.isGroupHeader?'bold 10px "JetBrains Mono", monospace':'11px "JetBrains Mono", monospace',ctx.textBaseline="middle",e.isGroupHeader?ctx.fillStyle=C.textMuted:e.isVirtual?ctx.fillStyle=C.virtual:e.isFK?ctx.fillStyle=C.fk:e.isPK?ctx.fillStyle=C.pk:ctx.fillStyle=C.text,ctx.fillText(u,a+L.TABLE_PAD_X+2+x,c+r/2),ctx.textBaseline="alphabetic";let h=a+s-6;if(e.isGroupHeader)return;const f=C.types[e.type]||"#94a3b8",y=e.type||"?";ctx.font='9px "JetBrains Mono", monospace';const p=ctx.measureText(y).width+10;h-=p,roundRectFill(ctx,h,c+(r-16)/2,p,16,8,f+"22"),ctx.strokeStyle=f+"55",ctx.lineWidth=.8,ctx.beginPath(),roundRect(ctx,h,c+(r-16)/2,p,16,8),ctx.stroke(),ctx.fillStyle=f,ctx.textBaseline="middle",ctx.fillText(y,h+5,c+r/2),ctx.textBaseline="alphabetic",h-=4;const b=e.validations,m=e.conversions;e.isVirtual&&(h-=14,ctx.fillStyle="#f59e0b",ctx.font='bold 9px "JetBrains Mono", monospace',ctx.textBaseline="middle",ctx.fillText("V",h+2,c+r/2),ctx.textBaseline="alphabetic"),b.required&&(h-=12,ctx.fillStyle=C.required,ctx.beginPath(),ctx.arc(h+5,c+r/2,3.5,0,2*Math.PI),ctx.fill()),b.unique&&(h-=14,drawUniqueIcon(h,c+(r-12)/2,12,12)),b.email&&(h-=14,ctx.fillStyle="#60a5fa",ctx.font="bold 10px sans-serif",ctx.textBaseline="middle",ctx.fillText("@",h+1,c+r/2),ctx.textBaseline="alphabetic"),b.enum&&(h-=14,ctx.fillStyle="#a78bfa",ctx.font="10px sans-serif",ctx.textBaseline="middle",ctx.fillText("≡",h+1,c+r/2),ctx.textBaseline="alphabetic"),m.encryption&&(h-=14,drawLockIcon(h,c+(r-12)/2,10,12)),m.hashing&&(h-=14,ctx.fillStyle="#f59e0b",ctx.font='bold 10px "JetBrains Mono", monospace',ctx.textBaseline="middle",ctx.fillText("#",h+2,c+r/2),ctx.textBaseline="alphabetic"),(m.defaults?.defaultFun||m.defaults?.defaultValue)&&(h-=14,ctx.fillStyle="#6ee7b7",ctx.font='bold 9px "JetBrains Mono", monospace',ctx.textBaseline="middle",ctx.fillText("D",h+2,c+r/2),ctx.textBaseline="alphabetic"),(e.isAutoIncDB||e.isAutoIncAM)&&(h-=14,ctx.fillStyle="#fb923c",ctx.font='9px "JetBrains Mono", monospace',ctx.textBaseline="middle",ctx.fillText("AI",h,c+r/2),ctx.textBaseline="alphabetic")}function getHeaderObstacles(){if(S._headerObsCache)return S._headerObsCache;const t=[];return Object.keys(S.databases).forEach((e=>{const n=dbBounds(e);t.push({x:n.x,y:n.y,w:n.w,h:L.DB_HDR_H})})),Object.keys(S.instances).forEach((e=>{const n=instBounds(e);t.push({x:n.x,y:n.y,w:n.w,h:L.INST_HDR_H})})),S._headerObsCache=t,t}function findLabelPos(t,e=80,n=[]){const a=1.5*RT.STUB,o=getHeaderObstacles(),s=Object.values(S.tables);function l(t,n){return s.some((a=>t+e>a.x&&t-e<a.x+a.w&&n>a.y-12&&n<a.y+a.h+12))}function c(t,n){return o.some((a=>t+e>a.x&&t-e<a.x+a.w&&n>a.y-8&&n<a.y+a.h+8))}function r(e){let n=0,o=null;for(let s=0;s<t.length-1;s++){const l=t[s],c=t[s+1],r=Math.hypot(c.x-l.x,c.y-l.y);if(r<a)continue;const i=Math.max(2,Math.ceil(r/10));let x=-1,d=0;for(let t=0;t<=i;t++){const a=t/i;if(e(l.x+(c.x-l.x)*a,l.y+(c.y-l.y)*a))x<0&&(x=t),d++;else{if(d>n){n=d;const t=(x+d/2)/i;o={x:l.x+(c.x-l.x)*t,y:l.y+(c.y-l.y)*t}}x=-1,d=0}}if(d>n){n=d;const t=(x+d/2)/i;o={x:l.x+(c.x-l.x)*Math.min(1,t),y:l.y+(c.y-l.y)*Math.min(1,t)}}}return o}const i=r(((t,a)=>!l(t,a)&&!c(t,a)&&!function(t,a){return n.some((n=>t+e>n.x&&t-e<n.x+n.w&&a+13>n.y&&a-13<n.y+n.h))}(t,a)));if(i)return i;const x=r(((t,e)=>!l(t,e)&&!c(t,e)));if(x)return x;let d=t[Math.floor(t.length/2)],u=-1;for(let e=0;e<t.length-1;e++){const n=t[e],o=t[e+1],s=Math.hypot(o.x-n.x,o.y-n.y);s>=a&&s>u&&(u=s,d={x:(n.x+o.x)/2,y:(n.y+o.y)/2})}return d}function spreadOverlappingLines(){const t=RT.GAP+6,e=S.relations.filter((t=>t._wpts&&!t._pinWpts&&t._wpts.length>=6));if(e.length<2)return;const n=getHeaderObstacles(),a=Object.values(S.tables);function o(e,o,s){const l=Math.min(o,s)-8,c=Math.max(o,s)+8;let r=e;for(let o=0;o<10;o++){let o=!1;for(const s of[a,n])for(const n of s)if(!(n.x>=c||n.x+n.w<=l)&&r>n.y-t&&r<n.y+n.h+t){const a=n.y-t,s=n.y+n.h+t;r=Math.abs(e-a)<=Math.abs(e-s)?a:s,o=!0}if(!o)break}return r}function s(e,o,s){const l=Math.min(o,s)-8,c=Math.max(o,s)+8;let r=e;for(let o=0;o<10;o++){let o=!1;for(const s of[a,n])for(const n of s)if(!(n.y>=c||n.y+n.h<=l)&&r>n.x-t&&r<n.x+n.w+t){const a=n.x-t,s=n.x+n.w+t;r=Math.abs(e-a)<=Math.abs(e-s)?a:s,o=!0}if(!o)break}return r}const l=e.map((t=>{const e=t._wpts,n=Math.floor((e.length-1)/2),a=e[n],o=e[n+1];return{a:a,b:o,horiz:Math.abs(a.y-o.y)<1,vert:Math.abs(a.x-o.x)<1}}));function c(t,e,n){const a=t.map(((t,e)=>e));function o(t){return a[t]===t?t:a[t]=o(a[t])}for(let s=0;s<t.length;s++)for(let l=s+1;l<t.length;l++){const c=t[s],r=t[l];if(Math.abs(c.a[e]-r.a[e])>=4)continue;const i=Math.min(c.a[n],c.b[n]),x=Math.max(c.a[n],c.b[n]),d=Math.min(r.a[n],r.b[n]);i<Math.max(r.a[n],r.b[n])&&d<x&&(a[o(s)]=o(l))}const s=new Map;return t.forEach(((t,e)=>{const n=o(e);s.has(n)||s.set(n,[]),s.get(n).push(t)})),[...s.values()].filter((t=>t.length>1))}for(const t of c(l.filter((t=>t.horiz)),"y","x")){const e=t.reduce(((t,e)=>t+e.a.y),0)/t.length;t.forEach(((n,a)=>{const s=o(e+12*(a-(t.length-1)/2),n.a.x,n.b.x)-n.a.y;n.a.y+=s,n.b.y+=s}))}for(const t of c(l.filter((t=>t.vert)),"x","y")){const e=t.reduce(((t,e)=>t+e.a.x),0)/t.length;t.forEach(((n,a)=>{const o=s(e+12*(a-(t.length-1)/2),n.a.y,n.b.y)-n.a.x;n.a.x+=o,n.b.x+=o}))}}function distToSeg(t,e,n,a,o,s){const l=o-n,c=s-a,r=l*l+c*c;if(r<1e-4)return Math.hypot(t-n,e-a);const i=Math.max(0,Math.min(1,((t-n)*l+(e-a)*c)/r));return Math.hypot(t-(n+i*l),e-(a+i*c))}function hitConnHandle(t,e){const n=10/S.zoom;for(const a of S.relations){const o=a._wpts;if(o&&!(o.length<6))for(let s=2;s<=o.length-4;s++){const l=o[s],c=o[s+1];if(Math.hypot(c.x-l.x,c.y-l.y)<30)continue;const r=(l.x+c.x)/2,i=(l.y+c.y)/2;if(Math.hypot(t-r,e-i)<=n)return{rel:a,segIdx:s}}}return null}function hitConnSeg(t,e){const n=6/S.zoom;for(const a of S.relations){const o=a._wpts;if(o)for(let s=0;s<o.length-1;s++){const l=o[s],c=o[s+1];if(distToSeg(t,e,l.x,l.y,c.x,c.y)<=n)return a}}return null}function drawRelations(t){const e=getHeaderObstacles();S.relations.forEach((t=>{t._labelMid=null;const n=S.tables[t.fromTable],a=S.tables[t.toTable];if(!n||!a||t.fromTable===t.toTable)return void(t._wpts=null);if(t._pinWpts)return void(t._wpts=t._pinWpts);if(t._wpts&&t._wptVersion===S._layoutVersion)return;const{p1:o,s1:s,p2:l,s2:c}=connPoints(n,a,t.fromCol,t.toCol);t._wpts=computeWaypoints(o,s,l,c,n.key,a.key,e),t._wptVersion=S._layoutVersion})),spreadOverlappingLines(),ctx.font='9px "JetBrains Mono", monospace';const n=[];S.relations.forEach((t=>{if(S.selected!==t.fromTable&&S.selected!==t.toTable)return;if(!t._wpts)return;const e=ctx.measureText(`${t.fromCol} → ${t.toCol}`).width+12,a=findLabelPos(t._wpts,e/2,n);t._labelMid=a,n.push({x:a.x-e/2-6,y:a.y-10-6,w:e+12,h:30})}));const a=t?S.relations.filter((e=>{if(S.selected===e.fromTable||S.selected===e.toTable)return!0;const n=S.tables[e.fromTable],a=S.tables[e.toTable];return!(!n||!a)&&(isRectVisible(n.x,n.y,n.w,n.h,t)||isRectVisible(a.x,a.y,a.w,a.h,t))})):S.relations;a.forEach((t=>drawRelation(t,!1))),a.forEach((t=>drawRelation(t,!0)))}function drawRelation(t,e){const n=S.tables[t.fromTable],a=S.tables[t.toTable];if(!n||!a)return;const o=S.selected===t.fromTable||S.selected===t.toTable,s=.5*Math.sin(2.5*S.pulseT)+.5,l=o?1.8+.8*s:1.4;if(ctx.save(),ctx.globalAlpha=o?1:.22,t.fromTable===t.toTable){const s={x:n.x+n.w,y:colRowY(n,t.fromCol)},c={x:a.x+a.w,y:colRowY(a,t.toCol)};if(e||drawSelfLoop(s,c,t.color[0],t.color[1],l,o),e&&o){const e=`${t.fromCol} → ${t.toCol}`;ctx.font='9px "JetBrains Mono", monospace';const a=ctx.measureText(e).width+12,o=n.x+n.w+48,l=(s.y+c.y)/2;roundRectFill(ctx,o-a/2,l-10,a,18,9,"rgba(13,17,23,0.85)"),ctx.strokeStyle=t.color[0]+"66",ctx.lineWidth=.8,ctx.beginPath(),roundRect(ctx,o-a/2,l-10,a,18,9),ctx.stroke(),ctx.fillStyle=t.color[0],ctx.textBaseline="middle",ctx.fillText(e,o-a/2+6,l),ctx.textBaseline="alphabetic"}return void ctx.restore()}const c=t._wpts;if(c){if(!e&&(drawRoutedPath(c,t.color[0],t.color[1],l,o),drawArrowHead(c,t.color[1]),drawSourceDot(c[0],t.color[0]),(S.hovConn?.rel===t||o)&&c.length>=6))for(let e=2;e<=c.length-4;e++){const n=c[e],a=c[e+1];if(Math.hypot(a.x-n.x,a.y-n.y)<30)continue;const o=(n.x+a.x)/2,s=(n.y+a.y)/2,l=S.hovConn?.rel===t&&S.hovConn?.segIdx===e;ctx.save(),ctx.globalAlpha=1,ctx.beginPath(),ctx.arc(o,s,l?6:4,0,2*Math.PI),ctx.fillStyle=l?"#ffffff":"rgba(255,255,255,0.75)",ctx.fill(),ctx.strokeStyle=t.color[0],ctx.lineWidth=1.5/S.zoom,ctx.stroke(),ctx.restore()}if(e&&o){const e=`${t.fromCol} → ${t.toCol}`;ctx.font='9px "JetBrains Mono", monospace';const n=ctx.measureText(e).width+12,a=t._labelMid||findLabelPos(c,n/2);roundRectFill(ctx,a.x-n/2,a.y-10,n,18,9,"rgba(13,17,23,0.9)"),ctx.strokeStyle=t.color[0]+"66",ctx.lineWidth=.8,ctx.beginPath(),roundRect(ctx,a.x-n/2,a.y-10,n,18,9),ctx.stroke(),ctx.fillStyle=t.color[0],ctx.textBaseline="middle",ctx.fillText(e,a.x-n/2+6,a.y),ctx.textBaseline="alphabetic"}ctx.restore()}else ctx.restore()}function colRowY(t,e){if(!e)return t.y+t.h/2;const n=t.columns.findIndex((t=>t.name===e));return n<0?t.y+t.h/2:t.y+L.TABLE_HDR_H+L.TABLE_FOOT_PAD/2+n*L.TABLE_ROW_H+L.TABLE_ROW_H/2}function connPoints(t,e,n,a){const o=colRowY(t,n),s=colRowY(e,a),l=t.x+t.w/2,c=e.x+e.w/2;let r,i,x,d;const u=e.x-(t.x+t.w),h=t.x-(e.x+e.w);if(u>=-4)r={x:t.x+t.w,y:o},i="r",x={x:e.x,y:s},d="l";else if(h>=-4)r={x:t.x,y:o},i="l",x={x:e.x+e.w,y:s},d="r";else{e.y+e.h/2-(t.y+t.h/2)>=0?(r={x:l,y:t.y+t.h},i="d",x={x:c,y:e.y},d="u"):(r={x:l,y:t.y},i="u",x={x:c,y:e.y+e.h},d="d")}return{p1:r,s1:i,p2:x,s2:d}}window.addEventListener("resize",resize);const RT={STUB:36,GAP:22,CORNER_R:9,SELF_W:56};function addDir(t,e,n){return{x:t.x+("r"===e?n:"l"===e?-n:0),y:t.y+("d"===e?n:"u"===e?-n:0)}}function segHitsTable(t,e,n,a,o,s){const l=o.x-s,c=o.y-s,r=o.x+o.w+s,i=o.y+o.h+s;if(t===n){const n=Math.min(e,a),o=Math.max(e,a);return t>l&&t<r&&o>c&&n<i}const x=Math.min(t,n),d=Math.max(t,n);return e>c&&e<i&&d>l&&x<r}function pathHitsObs(t,e){for(let n=0;n<t.length-1;n++){const a=t[n],o=t[n+1];for(const t of e)if(segHitsTable(a.x,a.y,o.x,o.y,t,RT.GAP))return!0}return!1}function findClearHBand(t,e,n){const a=Math.min(t.x,e.x)-RT.GAP,o=Math.max(t.x,e.x)+RT.GAP,s=n.filter((t=>t.x<o&&t.x+t.w>a));if(!s.length)return(t.y+e.y)/2;const l=(t.y+e.y)/2,c=RT.GAP+8,r=[];for(const t of s)r.push(t.y-c),r.push(t.y+t.h+c);const i=r.filter((t=>!s.some((e=>t>e.y-c&&t<e.y+e.h+c))));return i.length>0?i.reduce(((t,e)=>Math.abs(e-l)<Math.abs(t-l)?e:t)):Math.max(...s.map((t=>t.y+t.h)))+c}function findClearVBand(t,e,n){const a=Math.min(t.y,e.y)-RT.GAP,o=Math.max(t.y,e.y)+RT.GAP,s=n.filter((t=>t.y<o&&t.y+t.h>a));if(!s.length)return(t.x+e.x)/2;const l=(t.x+e.x)/2,c=RT.GAP+8,r=[];for(const t of s)r.push(t.x-c),r.push(t.x+t.w+c);const i=r.filter((t=>!s.some((e=>t>e.x-c&&t<e.x+e.w+c))));return i.length>0?i.reduce(((t,e)=>Math.abs(e-l)<Math.abs(t-l)?e:t)):Math.max(...s.map((t=>t.x+t.w)))+c}function routeHH(t,e,n,a,o){const s=[(e.x+n.x)/2,e.x+RT.STUB,n.x-RT.STUB,e.x+.35*(n.x-e.x),e.x+.65*(n.x-e.x)];for(const l of s){const s=[t,e,{x:l,y:e.y},{x:l,y:n.y},n,a];if(!pathHitsObs(s,o))return s}const l=Math.min(e.x,n.x)-RT.GAP,c=Math.max(e.x,n.x)+RT.GAP,r=o.filter((t=>t.x<c&&t.x+t.w>l)),i=RT.GAP+8,x=[];for(const t of r)x.push(t.y-i),x.push(t.y+t.h+i);const d=(e.y+n.y)/2;x.sort(((t,e)=>Math.abs(t-d)-Math.abs(e-d)));for(const s of x){const l=[t,e,{x:e.x,y:s},{x:n.x,y:s},n,a];if(!pathHitsObs(l,o))return l}const u=x.length?x[0]:findClearHBand(e,n,o);return[t,e,{x:e.x,y:u},{x:n.x,y:u},n,a]}function routeVV(t,e,n,a,o){const s=[(e.y+n.y)/2,e.y+RT.STUB,n.y-RT.STUB];for(const l of s){const s=[t,e,{x:e.x,y:l},{x:n.x,y:l},n,a];if(!pathHitsObs(s,o))return s}const l=Math.min(e.y,n.y)-RT.GAP,c=Math.max(e.y,n.y)+RT.GAP,r=o.filter((t=>t.y<c&&t.y+t.h>l)),i=RT.GAP+8,x=[];for(const t of r)x.push(t.x-i),x.push(t.x+t.w+i);const d=(e.x+n.x)/2;x.sort(((t,e)=>Math.abs(t-d)-Math.abs(e-d)));for(const s of x){const l=[t,e,{x:s,y:e.y},{x:s,y:n.y},n,a];if(!pathHitsObs(l,o))return l}const u=x.length?x[0]:findClearVBand(e,n,o);return[t,e,{x:u,y:e.y},{x:u,y:n.y},n,a]}function routeL(t,e,n,a,o){const s={x:e.x,y:n.y},l={x:n.x,y:e.y},c=[t,e,s,n,a];if(!pathHitsObs(c,o))return c;const r=[t,e,l,n,a];if(!pathHitsObs(r,o))return r;const i=findClearVBand(e,n,o);return[t,e,{x:i,y:e.y},{x:i,y:n.y},n,a]}function computeWaypoints(t,e,n,a,o,s,l=[]){const c=Object.values(S.tables).filter((t=>t.key!==o&&t.key!==s)),r=l.length?[...c,...l]:c,i=addDir(t,e,RT.STUB),x=addDir(n,a,RT.STUB),d="r"===e||"l"===e,u="r"===a||"l"===a;return d&&u?routeHH(t,i,x,n,r):d||u?routeL(t,i,x,n,r):routeVV(t,i,x,n,r)}function drawRoutedPath(t,e,n,a,o){if(t.length<2)return;const s=t[0],l=t[t.length-1],c=ctx.createLinearGradient(s.x,s.y,l.x,l.y);c.addColorStop(0,e),c.addColorStop(1,n),o&&(ctx.shadowColor=e+"aa",ctx.shadowBlur=10),ctx.strokeStyle=c,ctx.lineWidth=a,ctx.lineCap="round",ctx.lineJoin="round",ctx.beginPath(),ctx.moveTo(s.x,s.y);for(let e=1;e<t.length-1;e++){const n=t[e-1],a=t[e],o=t[e+1],s=Math.hypot(a.x-n.x,a.y-n.y),l=Math.hypot(o.x-a.x,o.y-a.y);if(s<.5||l<.5){ctx.lineTo(a.x,a.y);continue}const c=Math.min(RT.CORNER_R,s/2,l/2),r=a.x-c*(a.x-n.x)/s,i=a.y-c*(a.y-n.y)/s,x=a.x+c*(o.x-a.x)/l,d=a.y+c*(o.y-a.y)/l;ctx.lineTo(r,i),ctx.quadraticCurveTo(a.x,a.y,x,d)}ctx.lineTo(l.x,l.y),ctx.stroke(),ctx.shadowBlur=0}function drawArrowHead(t,e){const n=t.length;if(n<2)return;const a=t[n-2],o=t[n-1],s=Math.atan2(o.y-a.y,o.x-a.x);ctx.fillStyle=e,ctx.beginPath(),ctx.moveTo(o.x,o.y),ctx.lineTo(o.x-10*Math.cos(s-.42),o.y-10*Math.sin(s-.42)),ctx.lineTo(o.x-10*Math.cos(s+.42),o.y-10*Math.sin(s+.42)),ctx.closePath(),ctx.fill()}function drawSourceDot(t,e){ctx.fillStyle=e,ctx.beginPath(),ctx.arc(t.x,t.y,3.5,0,2*Math.PI),ctx.fill()}function drawSelfLoop(t,e,n,a,o,s){const l=t.x+RT.SELF_W,c=[t,{x:l,y:t.y},{x:l,y:e.y},e];drawRoutedPath(c,n,a,o,s),drawArrowHead(c,a),drawSourceDot(t,n)}function drawRipples(){S.ripples=S.ripples.filter((t=>t.a>.015)),S.ripples.forEach((t=>{ctx.strokeStyle=`rgba(96,165,250,${t.a})`,ctx.lineWidth=1.5,ctx.beginPath(),ctx.arc(t.x,t.y,t.r,0,2*Math.PI),ctx.stroke(),t.r+=5,t.a*=.88}))}function drawServerIcon(t,e,n,a){ctx.save(),ctx.strokeStyle="rgba(255,255,255,0.75)",ctx.lineWidth=1.2;const o=(a-4)/3;for(let a=0;a<3;a++){const s=e+a*(o+2);ctx.fillStyle="rgba(255,255,255,0.08)",ctx.beginPath(),roundRect(ctx,t,s,n,o,2),ctx.fill(),ctx.stroke(),ctx.fillStyle=0===a?"#34d399":1===a?"#fbbf24":"rgba(255,255,255,0.2)",ctx.beginPath(),ctx.arc(t+n-5,s+o/2,2,0,2*Math.PI),ctx.fill()}ctx.restore()}function drawDBIcon(t,e,n,a){ctx.save(),ctx.strokeStyle="rgba(255,255,255,0.55)",ctx.lineWidth=1;const o=n,s=.28*a,l=t+o/2;ctx.fillStyle="rgba(255,255,255,0.08)",ctx.beginPath(),ctx.ellipse(l,e+s/2,o/2,s/2,0,0,2*Math.PI),ctx.fill(),ctx.stroke(),ctx.beginPath(),ctx.moveTo(t,e+s/2),ctx.lineTo(t,e+a-s/2),ctx.moveTo(t+o,e+s/2),ctx.lineTo(t+o,e+a-s/2),ctx.stroke(),ctx.fillStyle="rgba(255,255,255,0.05)",ctx.beginPath(),ctx.ellipse(l,e+a-s/2,o/2,s/2,0,0,2*Math.PI),ctx.fill(),ctx.stroke(),[.42,.65].forEach((t=>{ctx.beginPath(),ctx.ellipse(l,e+a*t,o/2,s/2,0,Math.PI,2*Math.PI),ctx.stroke()})),ctx.restore()}function drawUniqueIcon(t,e,n,a){ctx.save(),ctx.strokeStyle="#60a5fa",ctx.lineWidth=1.2,ctx.beginPath(),ctx.moveTo(t+2,e),ctx.lineTo(t+2,e+.6*a),ctx.quadraticCurveTo(t+2,e+a,t+n/2,e+a),ctx.quadraticCurveTo(t+n-2,e+a,t+n-2,e+.6*a),ctx.lineTo(t+n-2,e),ctx.stroke(),ctx.restore()}function drawLockIcon(t,e,n,a){ctx.save(),ctx.strokeStyle="#fbbf24",ctx.lineWidth=1,ctx.beginPath(),ctx.arc(t+n/2,e+.38*a,.32*n,Math.PI,0),ctx.stroke(),ctx.fillStyle="rgba(251,191,36,0.12)",roundRectFill(ctx,t+.12*n,e+.46*a,.76*n,.54*a,2),ctx.beginPath(),roundRect(ctx,t+.12*n,e+.46*a,.76*n,.54*a,2),ctx.stroke(),ctx.restore()}function toWorld(t,e){return{x:(t-S.panX)/S.zoom,y:(e-S.panY)/S.zoom}}function hitTable(t,e){const n=Object.keys(S.tables);for(let a=n.length-1;a>=0;a--){const o=S.tables[n[a]];if(t>=o.x&&t<=o.x+o.w&&e>=o.y&&e<=o.y+o.h)return n[a]}return null}function hitRow(t,e,n){const a=S.tables[n];if(!a)return-1;const o=e-a.y-L.TABLE_HDR_H-L.TABLE_FOOT_PAD/2;if(o<0)return-1;const s=Math.floor(o/L.TABLE_ROW_H);return s>=0&&s<a.columns.length?s:-1}function zoomBy(t){S.zoom=Math.max(.1,Math.min(10,S.zoom*t)),updateZoomLabel(),scheduleRender()}function updateTooltip(t,e,n,a){const o=document.getElementById("tooltip");if(!e)return void(o.style.display="none");const s=S.tables[e],l=hitRow(n,a,e);if(l<0)return void(o.style.display="none");const c=s.columns[l];if(!c)return void(o.style.display="none");const r=c.validations,i=c.conversions;let x=`<div class="tt-name">${c.name}</div>`;x+=`<div class="tt-type">${c.type}${c.isPK?" · 🔑 Primary Key":""}${c.isFK?" · 🔗 Foreign Key":""}${c.isVirtual?' · <span style="color:#f59e0b">V Virtual</span>':""}</div>`;const d=[];r.required&&d.push('<span class="tt-badge req">required</span>'),r.unique&&d.push('<span class="tt-badge uniq">unique</span>'),r.email&&d.push('<span class="tt-badge email">email</span>'),void 0!==r.min&&d.push(`<span class="tt-badge">min: ${r.min}</span>`),void 0!==r.max&&d.push(`<span class="tt-badge">max: ${r.max}</span>`),void 0!==r.minLength&&d.push(`<span class="tt-badge">minLen: ${r.minLength}</span>`),void 0!==r.maxLength&&d.push(`<span class="tt-badge">maxLen: ${r.maxLength}</span>`),r.enum&&d.push(`<span class="tt-badge enum">[${r.enum.join(", ")}]</span>`),d.length&&(x+=`<div class="tt-section"><strong>Validations</strong><br>${d.join("")}</div>`);const u=[];if(i.trim&&u.push('<span class="tt-badge">trim</span>'),i.trimStart&&u.push('<span class="tt-badge">trimStart</span>'),i.trimEnd&&u.push('<span class="tt-badge">trimEnd</span>'),i.toLowerCase&&u.push('<span class="tt-badge">toLowerCase</span>'),i.toUpperCase&&u.push('<span class="tt-badge">toUpperCase</span>'),i.encryption&&u.push('<span class="tt-badge enc">encrypted</span>'),i.hashing&&u.push('<span class="tt-badge hash">hashed</span>'),i.defaults?.defaultFun&&u.push('<span class="tt-badge def">defaultFun</span>'),i.defaults?.defaultValue&&u.push(`<span class="tt-badge def">default: ${JSON.stringify(i.defaults.defaultValue)}</span>`),u.length&&(x+=`<div class="tt-section"><strong>Conversions</strong><br>${u.join("")}</div>`),c.isFK&&c.targetColl){x+=`<div class="tt-section tt-fk">→ ${[c.targetInst,c.targetDb,c.targetColl].filter(Boolean).join(".")}${c.targetCol?"."+c.targetCol:""}</div>`}o.innerHTML=x,o.style.display="block";const h=t.clientX+18,f=t.clientY-10;o.style.left=h+"px",o.style.top=f+"px",requestAnimationFrame((()=>{const t=o.getBoundingClientRect();t.right>window.innerWidth-8&&(o.style.left=h-t.width-28+"px"),t.bottom>window.innerHeight-8&&(o.style.top=f-t.height+10+"px")}))}function exportPNG(){let t=1/0,e=1/0,n=-1/0,a=-1/0;Object.keys(S.instances).forEach((o=>{const s=instBounds(o);t=Math.min(t,s.x),e=Math.min(e,s.y),n=Math.max(n,s.x+s.w),a=Math.max(a,s.y+s.h)}));const o=n-t+120,s=a-e+120,l=document.createElement("canvas");l.width=2*o,l.height=2*s;l.getContext("2d").setTransform(2,0,0,2,0,0);const c=S.panX,r=S.panY,i=S.zoom;S.panX=60-t,S.panY=60-e,S.zoom=1,canvas.width=2*o,canvas.height=2*s,canvas.style.width=o+"px",canvas.style.height=s+"px",ctx.setTransform(2,0,0,2,0,0),S.vw=o,S.vh=s,render();const x=document.createElement("a");x.download="entity-diagram.png",x.href=canvas.toDataURL("image/png"),x.click(),S.panX=c,S.panY=r,S.zoom=i,resize(),scheduleRender()}function exportSVG(){let t=1/0,e=1/0,n=-1/0,a=-1/0;Object.keys(S.instances).forEach((o=>{const s=instBounds(o);t=Math.min(t,s.x),e=Math.min(e,s.y),n=Math.max(n,s.x+s.w),a=Math.max(a,s.y+s.h)}));const o=n-t+120,s=a-e+120,l=60-t,c=60-e,r=[];r.push(`<svg xmlns="http://www.w3.org/2000/svg" width="${o}" height="${s}" viewBox="0 0 ${o} ${s}">`),r.push("<style>text{font-family:'JetBrains Mono',monospace;}</style>"),r.push(`<rect width="${o}" height="${s}" fill="${C.bg}"/>`);const i=L.GRID_SIZE;for(let t=i;t<o;t+=i)for(let e=i;e<s;e+=i)r.push(`<circle cx="${t}" cy="${e}" r="0.7" fill="rgba(48,54,61,0.6)"/>`);Object.keys(S.instances).forEach((t=>{const e=instBounds(t),n=e.x+l,a=e.y+c;r.push(`<rect x="${n}" y="${a}" width="${e.w}" height="${e.h}" rx="${L.INST_R}" fill="#0d1423" stroke="#3b82f6" stroke-width="1.5" opacity="0.95"/>`),r.push(`<rect x="${n}" y="${a}" width="${e.w}" height="${L.INST_HDR_H}" rx="${L.INST_R}" fill="#1d4ed8"/>`),r.push(`<text x="${n+14}" y="${a+L.INST_HDR_H/2+5}" fill="white" font-weight="bold" font-size="13">${t.toUpperCase()}</text>`)})),Object.keys(S.databases).forEach((t=>{const e=dbBounds(t),n=S.databases[t],a=e.x+l,o=e.y+c;r.push(`<rect x="${a}" y="${o}" width="${e.w}" height="${e.h}" rx="${L.DB_R}" fill="#161b22" stroke="#2d333b"/>`),r.push(`<rect x="${a}" y="${o}" width="${e.w}" height="${L.DB_HDR_H}" rx="${L.DB_R}" fill="#1c2128"/>`),r.push(`<text x="${a+14}" y="${o+L.DB_HDR_H/2+5}" fill="#c9d1d9" font-weight="bold" font-size="11">${n.name}</text>`)})),S.relations.forEach((t=>{const e=S.tables[t.fromTable],n=S.tables[t.toTable];if(!e||!n)return;const{p1:a,p2:o}=connPoints(e,n,t.fromCol,t.toCol),s=`g_${t.idx}`;r.push(`<defs><linearGradient id="${s}" x1="0%" y1="0%" x2="100%" y2="0%"><stop offset="0%" stop-color="${t.color[0]}"/><stop offset="100%" stop-color="${t.color[1]}"/></linearGradient></defs>`),r.push(`<circle cx="${a.x+l}" cy="${a.y+c}" r="3.5" fill="${t.color[0]}" opacity="0.6"/>`),r.push(`<path d="M${a.x+l} ${a.y+c} L${o.x+l} ${o.y+c}" stroke="url(#${s})" stroke-width="1.5" fill="none" opacity="0.6"/>`)})),Object.values(S.tables).forEach((t=>{const e=t.x+l,n=t.y+c;r.push(`<rect x="${e}" y="${n}" width="${t.w}" height="${t.h}" rx="${L.TABLE_R}" fill="#161b22" stroke="#30363d"/>`),r.push(`<rect x="${e}" y="${n}" width="${t.w}" height="${L.TABLE_HDR_H}" rx="${L.TABLE_R}" fill="#1f2937"/>`),r.push(`<rect x="${e+L.TABLE_R}" y="${n}" width="${t.w-2*L.TABLE_R}" height="2" fill="#3b82f6"/>`),r.push(`<text x="${e+12}" y="${n+26}" fill="#f0f6fc" font-weight="bold" font-size="12">${esc(t.coll)}</text>`),r.push(`<line x1="${e}" y1="${n+L.TABLE_HDR_H}" x2="${e+t.w}" y2="${n+L.TABLE_HDR_H}" stroke="#21262d"/>`),t.columns.forEach(((a,o)=>{const s=n+L.TABLE_HDR_H+o*L.TABLE_ROW_H+L.TABLE_ROW_H/2+4,l=10*(a.depth||0),c=a.name.includes(".")?a.name.split(".").pop():a.name,i=a.isGroupHeader?c+(a.isArray?" []":" {}"):c+(a.isArray?" []":""),x=a.isGroupHeader?"#8b949e":a.isPK?C.pk:a.isFK?C.fk:a.isVirtual?C.virtual:"#e6edf3";if(r.push(`<text x="${e+14+l}" y="${s}" fill="${x}" font-size="${a.isGroupHeader?9:10}">${esc(i)}</text>`),!a.isGroupHeader){const n=C.types[a.type]||"#94a3b8";r.push(`<text x="${e+t.w-8}" y="${s}" fill="${n}" font-size="9" text-anchor="end">${esc(a.type||"?")}</text>`),a.isVirtual&&r.push(`<text x="${e+t.w-8-6*(a.type||"?").length-10}" y="${s}" fill="#f59e0b" font-size="9" text-anchor="end" font-weight="bold">V</text>`)}}))})),r.push("</svg>");const x=new Blob([r.join("\n")],{type:"image/svg+xml"}),d=document.createElement("a");d.download="entity-diagram.svg",d.href=URL.createObjectURL(x),d.click()}function exportJSON(){const t={};Object.entries(S.tables).forEach((([e,n])=>{t[e]={x:n.x,y:n.y,w:n.w,h:n.h}}));const e={entities:S.rawData,relations:S.relations.map((t=>({from:`${t.fromTable} . ${t.fromCol}`,to:`${t.toTable} . ${t.toCol}`}))),layout:t,camera:{panX:S.panX,panY:S.panY,zoom:S.zoom}},n=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),a=document.createElement("a");a.download="entity-diagram.json",a.href=URL.createObjectURL(n),a.click()}function esc(t){return String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function roundRect(t,e,n,a,o,s){const[l,c,r,i]=Array.isArray(s)?s:[s,s,s,s];t.beginPath(),t.moveTo(e+l,n),t.arcTo(e+a,n,e+a,n+o,c),t.arcTo(e+a,n+o,e,n+o,r),t.arcTo(e,n+o,e,n,i),t.arcTo(e,n,e+a,n,l),t.closePath()}function roundRectFill(t,e,n,a,o,s,l){void 0!==l&&(t.fillStyle=l),roundRect(t,e,n,a,o,s),t.fill()}function updateZoomLabel(){document.getElementById("zoom-display").textContent=Math.round(100*S.zoom)+"%"}function loadDiagramData(t){window.DIAGRAM_DATA=t,parseData(t),scheduleRender();const e=document.getElementById("loader");e&&(e.classList.add("hidden"),setTimeout((()=>e.remove()),500)),window.onDiagramLoaded?.()}async function init(){if(resize(),window.addEventListener("message",(function(t){t.data&&"LOAD_DIAGRAM_DATA"===t.data.type&&loadDiagramData(t.data.schemas)})),window.parent&&window.parent!==window){window.parent.postMessage({type:"DIAGRAM_READY"},"*");const t=document.getElementById("loader");t&&t.remove()}else try{const t=await fetch("./data.json");if(!t.ok)throw new Error(`HTTP ${t.status}`);loadDiagramData(await t.json())}catch(t){console.error("Failed to load data.json:",t),document.querySelector(".loader-text").textContent=`Error: ${t.message}`}}canvas.addEventListener("mousedown",(t=>{t.preventDefault();const{x:e,y:n}=toWorld(t.clientX,t.clientY-40),a=hitConnHandle(e,n);if(a){const{rel:o,segIdx:s}=a,l=o._wpts,c=Math.abs(l[s].y-l[s+1].y)<1;return S.connDrag={rel:o,segIdx:s,isHoriz:c,startWx:e,startWy:n,origPts:l.map((t=>({x:t.x,y:t.y})))},S.mouseDown=!0,S.mouseStartX=t.clientX,S.mouseStartY=t.clientY,S.mouseMoved=!1,S.mouseTarget=null,void(canvas.style.cursor=c?"ns-resize":"ew-resize")}const o=hitTable(e,n);if(S.mouseDown=!0,S.mouseStartX=t.clientX,S.mouseStartY=t.clientY,S.mouseMoved=!1,S.mouseTarget=o,o){const e=S.tables[o];S.dragging={type:"table",key:o,ox:e.x,oy:e.y,sx:t.clientX,sy:t.clientY},canvas.style.cursor="grabbing"}else S.dragging={type:"canvas",opx:S.panX,opy:S.panY,sx:t.clientX,sy:t.clientY},canvas.style.cursor="grabbing"})),canvas.addEventListener("mousemove",(t=>{const{x:e,y:n}=toWorld(t.clientX,t.clientY-40);if(!S.mouseDown){const a=hitTable(e,n),o=a?hitRow(e,n,a):-1,s=a!==S.hovTable||o!==S.hovRow;S.hovTable=a,S.hovRow=o;const l=a?null:hitConnHandle(e,n),c=S.hovConn;S.hovConn=l||null;const r=S.hovConn?.rel!==c?.rel||S.hovConn?.segIdx!==c?.segIdx;if((s||r)&&scheduleRender(),a)canvas.style.cursor="pointer";else if(l){const t=l.rel._wpts,e=Math.abs(t[l.segIdx].y-t[l.segIdx+1].y)<1;canvas.style.cursor=e?"ns-resize":"ew-resize"}else canvas.style.cursor="default";return void updateTooltip(t,a,e,n)}const a=t.clientX-S.mouseStartX,o=t.clientY-S.mouseStartY;if(!S.mouseMoved&&(Math.abs(a)>3||Math.abs(o)>3)&&(S.mouseMoved=!0),S.mouseMoved)if(S.connDrag){const{rel:t,segIdx:a,isHoriz:o,startWx:s,startWy:l,origPts:c}=S.connDrag,r=c.map((t=>({x:t.x,y:t.y})));if(o){const t=c[a].y+(n-l);r[a].y=t,r[a+1].y=t}else{const t=c[a].x+(e-s);r[a].x=t,r[a+1].x=t}t._pinWpts=r,t._wpts=r,scheduleRender()}else if("table"===S.dragging?.type){const e=S.dragging;S.tables[e.key].x=e.ox+(t.clientX-e.sx)/S.zoom,S.tables[e.key].y=e.oy+(t.clientY-e.sy)/S.zoom,S.relations.forEach((t=>{t.fromTable!==e.key&&t.toTable!==e.key||(t._pinWpts=null)})),invalidateLayout(),scheduleRender()}else if("canvas"===S.dragging?.type){const e=S.dragging;S.panX=e.opx+(t.clientX-e.sx),S.panY=e.opy+(t.clientY-e.sy),scheduleRender()}})),canvas.addEventListener("mouseup",(t=>{if(S.connDrag)return S.connDrag=null,S.mouseDown=!1,void(canvas.style.cursor=S.hovConn?S.hovConn.rel._wpts&&Math.abs(S.hovConn.rel._wpts[S.hovConn.segIdx]?.y-S.hovConn.rel._wpts[S.hovConn.segIdx+1]?.y)<1?"ns-resize":"ew-resize":S.hovTable?"pointer":"default");if(!S.mouseMoved&&S.mouseTarget){const t=S.mouseTarget,e=S.selected;if(S.selected=e===t?null:t,S._gradCache.clear(),S.selected){const e=S.tables[t],n=e.x+e.w/2,a=e.y+e.h/2;for(let t=0;t<4;t++)setTimeout((()=>{S.ripples.push({x:n,y:a,r:8+22*t,a:.9-.18*t})}),90*t)}startAnimation()}S.mouseDown=!1,S.dragging=null,canvas.style.cursor=S.hovTable?"pointer":"default"})),canvas.addEventListener("mouseleave",(()=>{S.hovTable=null,S.hovRow=-1,S.hovConn=null,S.connDrag=null,document.getElementById("tooltip").style.display="none",scheduleRender()})),canvas.addEventListener("dblclick",(t=>{const{x:e,y:n}=toWorld(t.clientX,t.clientY-40),a=hitConnSeg(e,n);a&&(a._pinWpts=null,scheduleRender())})),canvas.addEventListener("wheel",(t=>{if(t.preventDefault(),t.metaKey||t.ctrlKey){const e=t.deltaY<0?1.1:1/1.1,n=Math.max(.1,Math.min(10,S.zoom*e)),a=t.clientX,o=t.clientY-40;S.panX=a-(a-S.panX)*(n/S.zoom),S.panY=o-(o-S.panY)*(n/S.zoom),S.zoom=n,updateZoomLabel(),scheduleRender()}else S.panX-=t.deltaX,S.panY-=t.deltaY,scheduleRender()}),{passive:!1}),document.addEventListener("keydown",(t=>{"Escape"===t.key&&(S.selected=null,scheduleRender()),(t.metaKey||t.ctrlKey)&&"="===t.key&&(t.preventDefault(),zoomBy(1.2)),(t.metaKey||t.ctrlKey)&&"-"===t.key&&(t.preventDefault(),zoomBy(1/1.2)),(t.metaKey||t.ctrlKey)&&"0"===t.key&&(t.preventDefault(),centerView(),scheduleRender())})),document.getElementById("btn-fit").addEventListener("click",(()=>{centerView(),scheduleRender()})),document.getElementById("btn-zoom-in").addEventListener("click",(()=>{zoomBy(1.2)})),document.getElementById("btn-zoom-out").addEventListener("click",(()=>{zoomBy(1/1.2)})),document.getElementById("btn-deselect").addEventListener("click",(()=>{S.selected=null,scheduleRender()})),document.getElementById("btn-arrange").addEventListener("click",(()=>{autoArrange(),invalidateLayout(),scheduleRender()})),document.getElementById("btn-png").addEventListener("click",(()=>{exportPNG(),document.getElementById("export-menu").classList.remove("open")})),document.getElementById("btn-svg").addEventListener("click",(()=>{exportSVG(),document.getElementById("export-menu").classList.remove("open")})),window.loadFromGlobal=function(){window.DIAGRAM_DATA&&loadDiagramData(window.DIAGRAM_DATA)},init();
@@ -1 +1 @@
1
- !function(){const e="SET_VALUE",o="GET_VALUE",t="SET_OPTIONS",n="SET_LANGUAGE",r="FORMAT_DOCUMENT",a="INSERT_AT_CURSOR",i="SET_EXTRA_LIBS",c="SET_TS_COMPILER_OPTIONS",d="SET_TS_DIAGNOSTICS_OPTIONS",s="LOAD_TYPES",l="INIT_DIFF",u="RESET",g="FOCUS",f="SET_POSITION",y="SET_SELECTION",p="SET_SCROLL_TOP",k="SET_SCROLL_LEFT",m="TRIGGER",h="ADD_ACTION",C="DELTA_DECORATIONS",E="REMOVE_DECORATIONS",D="REVEAL_POSITION",b="EDITOR_READY",S="CONTENT_CHANGED",A="BLUR",O="VALUE_RESPONSE",I="CURSOR_POSITION_CHANGED",T="CURSOR_SELECTION_CHANGED",w="FONT_SIZE_CHANGED",v="ACTION_TRIGGERED",_="TYPES_LOADING",B="TYPES_LOADED";let M=null,L=null;const F={};let N={};function P(e){window.parent.postMessage(e,"*")}function R(e){F[e]&&P({type:v,payload:{actionId:e}})}const x=[];function U(e){if(M)try{e(M)}catch(e){console.error("[monaco-iframe] whenEditorReady callback failed",e)}else x.push(e)}const G="monaco_ct_v1_",H="monaco_ct_inflight",j=45e3;function V(e,o,t){return G+function(e){let o=5381;for(let t=0;t<e.length;t++)o=Math.imul(o,31)+e.charCodeAt(t)|0;return(o>>>0).toString(36)}(e+"|"+o+"|"+t)}async function K(e){try{const o=localStorage.getItem(e);return o?await async function(e){const o=atob(e),t=new Uint8Array(o.length);for(let e=0;e<o.length;e++)t[e]=o.charCodeAt(e);const n=new DecompressionStream("gzip"),r=n.writable.getWriter();r.write(t),r.close();const a=[],i=n.readable.getReader();for(;;){const e=await i.read();if(e.done)break;a.push(e.value)}const c=a.reduce((function(e,o){return e+o.length}),0),d=new Uint8Array(c);let s=0;return a.forEach((function(e){d.set(e,s),s+=e.length})),JSON.parse((new TextDecoder).decode(d))}(o):null}catch(o){try{localStorage.removeItem(e)}catch(e){}return null}}async function W(e,o){try{const t=await async function(e){const o=(new TextEncoder).encode(JSON.stringify(e)),t=new CompressionStream("gzip"),n=t.writable.getWriter();n.write(o),n.close();const r=[],a=t.readable.getReader();for(;;){const e=await a.read();if(e.done)break;r.push(e.value)}const i=r.reduce((function(e,o){return e+o.length}),0),c=new Uint8Array(i);let d=0;r.forEach((function(e){c.set(e,d),d+=e.length}));let s="";return c.forEach((function(e){s+=String.fromCharCode(e)})),btoa(s)}(o);localStorage.setItem(e,t)}catch(e){!e||"QuotaExceededError"!==e.name&&22!==e.code||console.warn("[monaco-iframe] Common types cache skipped — localStorage quota exceeded")}}function z(){try{const e=localStorage.getItem(H);return!!e&&Date.now()-Number(e)<j}catch(e){return!1}}function J(){try{localStorage.removeItem(H)}catch(e){}}function q(){M&&(M.dispose(),M=null),L&&(L.dispose(),L=null),N={},document.getElementById("editor").innerHTML=""}function Y(e){q();const o=Object.assign({},{automaticLayout:!0,minimap:{enabled:!1},theme:"vscode-dark-plus",fontSize:Number(localStorage.getItem("MONACO_FONT_SIZE")||0)||14,fontFamily:'JetBrains Mono, MonoLisa, Menlo, Monaco, "Courier New", "Lucida Console", monospace',wordWrap:"off",wrappingIndent:"indent",renderLineHighlight:"all",cursorBlinking:"smooth",cursorSmoothCaretAnimation:"on",smoothScrolling:!0,bracketPairColorization:{enabled:!0},guides:{bracketPairs:!0,indentation:!0},"semanticHighlighting.enabled":!0,stickyScroll:{enabled:!1}},e||{});var t;M=monaco.editor.create(document.getElementById("editor"),o),(t=M).addCommand(monaco.KeyMod.Shift|monaco.KeyCode.Delete,(function(){t.trigger("keyboard","editor.action.deleteLines")})),t.addCommand(monaco.KeyMod.Shift|monaco.KeyCode.Backspace,(function(){t.trigger("keyboard","editor.action.deleteLines")})),M.onDidChangeModelContent((function(){P({type:S,payload:{value:M.getValue()}})})),M.onDidBlurEditorText((function(){P({type:A,payload:{value:M.getValue()}})})),M.onDidChangeConfiguration((function(e){const o=monaco.editor.EditorOption;if(e.hasChanged(o.fontSize)){const e=M.getOptions().get(o.fontSize);localStorage.setItem("MONACO_FONT_SIZE",e),P({type:w,payload:{fontSize:e}})}})),M.onDidChangeCursorPosition((function(e){P({type:I,payload:{position:e.position}})})),M.onDidChangeCursorSelection((function(e){P({type:T,payload:{selection:e.selection}})})),function(){if(!M||0===x.length)return;x.splice(0).forEach((function(e){try{e(M)}catch(e){console.error("[monaco-iframe] Pending editor callback failed",e)}}))}()}monaco.editor.defineTheme("vscode-dark-plus",{base:"vs-dark",inherit:!0,rules:[{token:"comment",foreground:"6A9955",fontStyle:"italic"},{token:"comment.line",foreground:"6A9955",fontStyle:"italic"},{token:"comment.block",foreground:"6A9955",fontStyle:"italic"},{token:"keyword",foreground:"569CD6"},{token:"keyword.control",foreground:"C586C0"},{token:"keyword.operator",foreground:"569CD6"},{token:"storage.type",foreground:"569CD6"},{token:"storage.modifier",foreground:"569CD6"},{token:"type",foreground:"4EC9B0"},{token:"entity.name.type",foreground:"4EC9B0"},{token:"entity.name.class",foreground:"4EC9B0"},{token:"support.type",foreground:"4EC9B0"},{token:"entity.name.function",foreground:"DCDCAA"},{token:"support.function",foreground:"DCDCAA"},{token:"identifier",foreground:"9CDCFE"},{token:"string",foreground:"CE9178"},{token:"string.template",foreground:"CE9178"},{token:"number",foreground:"B5CEA8"},{token:"constant.language",foreground:"569CD6"},{token:"variable",foreground:"9CDCFE"},{token:"variable.parameter",foreground:"9CDCFE"},{token:"variable.language",foreground:"569CD6"},{token:"operator",foreground:"D4D4D4"},{token:"delimiter",foreground:"D4D4D4"},{token:"annotation",foreground:"DCDCAA"},{token:"regexp",foreground:"D16969"},{token:"key",foreground:"9CDCFE"},{token:"string.key.json",foreground:"9CDCFE"},{token:"string.value.json",foreground:"CE9178"},{token:"tag.css",foreground:"D7BA7D"},{token:"tag.scss",foreground:"D7BA7D"},{token:"tag.less",foreground:"D7BA7D"},{token:"entity.name.tag.css",foreground:"D7BA7D"},{token:"attribute.name.css",foreground:"9CDCFE"},{token:"attribute.name.scss",foreground:"9CDCFE"},{token:"attribute.name.less",foreground:"9CDCFE"},{token:"attribute.value.css",foreground:"CE9178"},{token:"attribute.value.scss",foreground:"CE9178"},{token:"attribute.value.less",foreground:"CE9178"},{token:"attribute.value.number.css",foreground:"B5CEA8"},{token:"attribute.value.unit.css",foreground:"9CDCFE"},{token:"attribute.value.hex.css",foreground:"CE9178"},{token:"string.css",foreground:"CE9178"},{token:"string.scss",foreground:"CE9178"},{token:"string.less",foreground:"CE9178"},{token:"keyword.css",foreground:"C586C0"},{token:"keyword.scss",foreground:"C586C0"},{token:"keyword.less",foreground:"C586C0"},{token:"number.css",foreground:"B5CEA8"},{token:"number.scss",foreground:"B5CEA8"},{token:"delimiter.css",foreground:"D4D4D4"},{token:"delimiter.scss",foreground:"D4D4D4"},{token:"delimiter.less",foreground:"D4D4D4"},{token:"pseudo.css",foreground:"D7BA7D"},{token:"unit.css",foreground:"9CDCFE"},{token:"variable.css",foreground:"9CDCFE"},{token:"variable.scss",foreground:"9CDCFE"},{token:"variable.less",foreground:"9CDCFE"},{token:"selector.css",foreground:"D7BA7D"},{token:"operator.css",foreground:"D4D4D4"}],colors:{"editor.background":"#1E1E1E","editor.foreground":"#D4D4D4","editor.lineHighlightBackground":"#2A2D2E","editor.selectionBackground":"#264F78","editor.inactiveSelectionBackground":"#3A3D41","editor.selectionHighlightBackground":"#ADD6FF26","editor.wordHighlightBackground":"#575757B8","editor.wordHighlightStrongBackground":"#004972B8","editorLineNumber.foreground":"#858585","editorLineNumber.activeForeground":"#C6C6C6","editorCursor.foreground":"#AEAFAD","editorWhitespace.foreground":"#3B4048","editorIndentGuide.background":"#404040","editorIndentGuide.activeBackground":"#707070","editorBracketMatch.background":"#0064001A","editorBracketMatch.border":"#888888","editor.findMatchBackground":"#515C6A","editor.findMatchHighlightBackground":"#EA5C0055","editorOverviewRuler.findMatchForeground":"#D186167E","editorSuggestWidget.background":"#252526","editorSuggestWidget.border":"#454545","editorSuggestWidget.foreground":"#D4D4D4","editorSuggestWidget.selectedBackground":"#062F4A","editorSuggestWidget.highlightForeground":"#18A3FF","editorHoverWidget.background":"#252526","editorHoverWidget.border":"#454545","peekView.border":"#007ACC","peekViewEditor.background":"#001F33","peekViewResult.background":"#252526","scrollbarSlider.background":"#79797966","scrollbarSlider.hoverBackground":"#646464B3","scrollbarSlider.activeBackground":"#BFBFBF66"}});let Z=0,Q=null;async function X(e,o){Q=e;const t=++Z;P({type:_});const n={"Content-Type":"application/json",authorization:e.token||""},r=e.hostAndPort,a=e.adminId,i=JSON.stringify(e.typesRequestBody||{});if(!o){if(!!!await K(V(r,a,i))&&(await new Promise((function(e){setTimeout(e,5e3)})),t!==Z))return}const c=[];try{const o=await Promise.all([fetch(e.typesUrl).then((function(e){return e.text()})),fetch(e.storeTypesUrl).then((function(e){return e.text()}))]);c.push({content:o[0],filePath:"file:///node_modules/@types/types/index.d.ts"}),c.push({content:o[1],filePath:"file:///node_modules/@types/store-types/index.d.ts"})}catch(e){console.error("[monaco-iframe] Failed to load asset types",e)}try{const e=V(r,a,i);let t=null;if(o||(t=await K(e)),t||z()&&(t=await(d=e,new Promise((function(e){let o=0;const t=setInterval((async function(){o++;try{const o=await K(d);if(o)return clearInterval(t),void e(o)}catch(e){}(!z()||o>=120)&&(clearInterval(t),e(null))}),500)})))),!t){!function(){try{localStorage.setItem(H,String(Date.now()))}catch(e){}}();try{t=await fetch(r+"/api/sites/types/"+a+"/get-common-types-from-be",{method:"POST",headers:n,body:i}).then((function(e){return e.json()})),t&&await W(e,t)}finally{J()}}t&&t.data&&Object.entries(t.data).forEach((function(e){c.push({content:e[1],filePath:e[0]})}))}catch(e){console.error("[monaco-iframe] Failed to load common types",e)}var d;try{const e=await fetch(r+"/api/sites/types/"+a+"/utility-class-types",{method:"POST",headers:n,body:i}).then((function(e){return e.json()}));e&&e.data&&Object.entries(e.data).forEach((function(e){c.push({content:e[1],filePath:e[0]})}))}catch(e){console.error("[monaco-iframe] Failed to load utility-class types",e)}try{const e=await fetch(r+"/api/sites/types/"+a+"/db-interfaces",{method:"POST",headers:n,body:JSON.stringify({})}).then((function(e){return e.json()}));e&&Object.entries(e).forEach((function(e){c.push({content:e[1],filePath:e[0]})}))}catch(e){console.error("[monaco-iframe] Failed to load DB interfaces",e)}t===Z&&(monaco.languages.typescript.typescriptDefaults.setExtraLibs(c),P({type:B}))}document.fonts.ready.then((function(){Y(),P({type:b})})),function(){const e=document.getElementById("reload-types-btn");e&&e.addEventListener("click",(async function(){if(Q){e.classList.add("loading"),e.textContent="↻ Loading…",function(){try{Object.keys(localStorage).forEach((function(e){e.startsWith(G)&&localStorage.removeItem(e)}))}catch(e){}J()}();try{await X(Q,!0)}finally{e.classList.remove("loading"),e.textContent="↺ Types"}}}))}(),window.addEventListener("keydown",(function(e){if(M)return!e.shiftKey||e.ctrlKey||e.metaKey||e.altKey||"Delete"!==e.key?void(function(e){return(e.ctrlKey||e.metaKey)&&e.altKey&&e.shiftKey&&("Backslash"===e.code||"\\"===e.key||"|"===e.key)}(e)&&(e.preventDefault(),e.stopPropagation(),R("idMonacoToggleZoom"))):(e.preventDefault(),e.stopPropagation(),M.trigger("keyboard","editor.action.deleteLines",void 0),void R("idMonacoDeleteLine"))}),!0),window.addEventListener("message",(function(S){const A=S.data;if(A&&A.type)switch(A.type){case e:U((function(e){e.setValue(A.payload.value||"")}));break;case o:{const e=A.requestId;U((function(o){P({type:O,payload:{value:o.getValue()},requestId:e})}));break}case t:A.payload&&U((function(e){const o=A.payload._modelUri,t=Object.assign({},A.payload);if(delete t._modelUri,e.updateOptions(t),o){const n=e.getModel()&&e.getModel().getLanguageId(),r=t.language||"plaintext"!==n&&n||"typescript",a=e.getValue(),i=monaco.editor.createModel(a,r,monaco.Uri.parse(o));e.setModel(i)}}));break;case n:U((function(e){const o=e.getModel();o&&monaco.editor.setModelLanguage(o,A.payload.language)}));break;case r:U((function(e){e.trigger(void 0,"editor.action.formatDocument",void 0)}));break;case a:A.payload&&null!=A.payload.text&&U((function(e){const o=e.getSelection();e.executeEdits("iframe-insert",[{identifier:{major:1,minor:1},range:o,text:A.payload.text,forceMoveMarkers:!0}])}));break;case s:if(A.payload){X(A.payload);const e=document.getElementById("reload-types-btn");e&&e.classList.add("visible")}break;case i:A.payload&&Array.isArray(A.payload.libs)&&monaco.languages.typescript.typescriptDefaults.setExtraLibs(A.payload.libs);break;case c:A.payload&&monaco.languages.typescript.typescriptDefaults.setCompilerOptions(A.payload);break;case d:A.payload&&monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions(A.payload);break;case f:A.payload&&A.payload.position&&U((function(e){e.setPosition(A.payload.position)}));break;case y:A.payload&&A.payload.selection&&U((function(e){e.setSelection(A.payload.selection)}));break;case p:A.payload&&null!=A.payload.top&&U((function(e){e.setScrollTop(A.payload.top)}));break;case k:A.payload&&null!=A.payload.left&&U((function(e){e.setScrollLeft(A.payload.left)}));break;case m:A.payload&&U((function(e){e.trigger(A.payload.source,A.payload.handlerId,A.payload.payload)}));break;case h:if(A.payload){const e=A.payload;F[e.id]=!0,U((function(o){o.addAction({id:e.id,label:e.label,keybindings:e.keybindings,precondition:e.precondition||null,keybindingContext:e.keybindingContext||null,contextMenuGroupId:e.contextMenuGroupId,contextMenuOrder:e.contextMenuOrder,run:function(){P({type:v,payload:{actionId:e.id}})}})}))}break;case C:A.payload&&U((function(e){const o=A.payload.oldDecorationIds||[],t=A.payload.newDecorations||[],n=A.payload.newParentIds||[],r=[];o.forEach((function(e){N[e]&&(N[e].forEach((function(e){r.push(e)})),delete N[e])}));const a=e.deltaDecorations(r,t);n.forEach((function(e,o){N[e]=a[o]?[a[o]]:[]}))}));break;case E:A.payload&&Array.isArray(A.payload.decorationIds)&&U((function(e){const o=[];A.payload.decorationIds.forEach((function(e){N[e]&&(N[e].forEach((function(e){o.push(e)})),delete N[e])})),o.length&&e.deltaDecorations(o,[])}));break;case l:{const e=A.payload||{};q();const o=Math.round(1e9*Math.random()),t=Math.round(1e9*Math.random()),n=e.language||"typescript",r=monaco.editor.createModel(e.text||"",n,monaco.Uri.parse("file:///"+o+"_Main.ts")),a=monaco.editor.createModel(e.editedText||"",n,monaco.Uri.parse("file:///"+t+"_Main.ts"));L=monaco.editor.createDiffEditor(document.getElementById("editor"),{originalEditable:!!e.isEditable,readOnly:!!e.isReadOnly,renderSideBySide:!0,automaticLayout:!0,theme:"vscode-dark-plus"}),L.setModel({original:r,modified:a});break}case u:Y(A.payload||{}),P({type:b});break;case g:U((function(e){e.focus()}));break;case D:A.payload&&A.payload.position&&U((function(e){e.revealPositionInCenter(A.payload.position)}))}}))}();
1
+ !function(){const e="SET_VALUE",o="GET_VALUE",t="SET_OPTIONS",n="SET_LANGUAGE",r="FORMAT_DOCUMENT",a="INSERT_AT_CURSOR",i="SET_EXTRA_LIBS",c="SET_TS_COMPILER_OPTIONS",d="SET_TS_DIAGNOSTICS_OPTIONS",s="LOAD_TYPES",l="INIT_DIFF",u="RESET",g="FOCUS",f="SET_POSITION",y="SET_SELECTION",p="SET_SCROLL_TOP",k="SET_SCROLL_LEFT",m="TRIGGER",h="ADD_ACTION",C="DELTA_DECORATIONS",E="REMOVE_DECORATIONS",D="REVEAL_POSITION",b="EDITOR_READY",S="CONTENT_CHANGED",A="BLUR",O="VALUE_RESPONSE",I="CURSOR_POSITION_CHANGED",T="CURSOR_SELECTION_CHANGED",w="FONT_SIZE_CHANGED",v="ACTION_TRIGGERED",_="TYPES_LOADING",B="TYPES_LOADED";let M=null,L=null;const F={};let N={};function P(e){window.parent.postMessage(e,"*")}function R(e){F[e]&&P({type:v,payload:{actionId:e}})}const x=[];function U(e){if(M)try{e(M)}catch(e){console.error("[monaco-iframe] whenEditorReady callback failed",e)}else x.push(e)}const G="monaco_ct_v1_",H="monaco_ct_inflight",j=45e3;function V(e,o,t){return G+function(e){let o=5381;for(let t=0;t<e.length;t++)o=Math.imul(o,31)+e.charCodeAt(t)|0;return(o>>>0).toString(36)}(e+"|"+o+"|"+t)}async function K(e){try{const o=localStorage.getItem(e);return o?await async function(e){const o=atob(e),t=new Uint8Array(o.length);for(let e=0;e<o.length;e++)t[e]=o.charCodeAt(e);const n=new DecompressionStream("gzip"),r=n.writable.getWriter();r.write(t),r.close();const a=[],i=n.readable.getReader();for(;;){const e=await i.read();if(e.done)break;a.push(e.value)}const c=a.reduce((function(e,o){return e+o.length}),0),d=new Uint8Array(c);let s=0;return a.forEach((function(e){d.set(e,s),s+=e.length})),JSON.parse((new TextDecoder).decode(d))}(o):null}catch(o){try{localStorage.removeItem(e)}catch(e){}return null}}async function W(e,o){try{const t=await async function(e){const o=(new TextEncoder).encode(JSON.stringify(e)),t=new CompressionStream("gzip"),n=t.writable.getWriter();n.write(o),n.close();const r=[],a=t.readable.getReader();for(;;){const e=await a.read();if(e.done)break;r.push(e.value)}const i=r.reduce((function(e,o){return e+o.length}),0),c=new Uint8Array(i);let d=0;r.forEach((function(e){c.set(e,d),d+=e.length}));let s="";return c.forEach((function(e){s+=String.fromCharCode(e)})),btoa(s)}(o);localStorage.setItem(e,t)}catch(e){!e||"QuotaExceededError"!==e.name&&22!==e.code||console.warn("[monaco-iframe] Common types cache skipped — localStorage quota exceeded")}}function z(){try{const e=localStorage.getItem(H);return!!e&&Date.now()-Number(e)<j}catch(e){return!1}}function J(){try{localStorage.removeItem(H)}catch(e){}}function q(){M&&(M.dispose(),M=null),L&&(L.dispose(),L=null),N={},document.getElementById("editor").innerHTML=""}function Y(e){q();const o=Object.assign({},{automaticLayout:!0,minimap:{enabled:!1},theme:"vscode-dark-plus",fontSize:Number(localStorage.getItem("MONACO_FONT_SIZE")||0)||14,fontFamily:'JetBrains Mono, MonoLisa, Menlo, Monaco, "Courier New", "Lucida Console", monospace',wordWrap:"off",wrappingIndent:"indent",renderLineHighlight:"all",cursorBlinking:"blink",cursorSmoothCaretAnimation:"off",smoothScrolling:!1,bracketPairColorization:{enabled:!0},guides:{bracketPairs:!0,indentation:!0},"semanticHighlighting.enabled":!0,stickyScroll:{enabled:!1}},e||{});var t;M=monaco.editor.create(document.getElementById("editor"),o),(t=M).addCommand(monaco.KeyMod.Shift|monaco.KeyCode.Delete,(function(){t.trigger("keyboard","editor.action.deleteLines")})),t.addCommand(monaco.KeyMod.Shift|monaco.KeyCode.Backspace,(function(){t.trigger("keyboard","editor.action.deleteLines")})),M.onDidChangeModelContent((function(){P({type:S,payload:{value:M.getValue()}})})),M.onDidBlurEditorText((function(){P({type:A,payload:{value:M.getValue()}})})),M.onDidChangeConfiguration((function(e){const o=monaco.editor.EditorOption;if(e.hasChanged(o.fontSize)){const e=M.getOptions().get(o.fontSize);localStorage.setItem("MONACO_FONT_SIZE",e),P({type:w,payload:{fontSize:e}})}})),M.onDidChangeCursorPosition((function(e){P({type:I,payload:{position:e.position}})})),M.onDidChangeCursorSelection((function(e){P({type:T,payload:{selection:e.selection}})})),function(){if(!M||0===x.length)return;x.splice(0).forEach((function(e){try{e(M)}catch(e){console.error("[monaco-iframe] Pending editor callback failed",e)}}))}()}monaco.editor.defineTheme("vscode-dark-plus",{base:"vs-dark",inherit:!0,rules:[{token:"comment",foreground:"6A9955",fontStyle:"italic"},{token:"comment.line",foreground:"6A9955",fontStyle:"italic"},{token:"comment.block",foreground:"6A9955",fontStyle:"italic"},{token:"keyword",foreground:"569CD6"},{token:"keyword.control",foreground:"C586C0"},{token:"keyword.operator",foreground:"569CD6"},{token:"storage.type",foreground:"569CD6"},{token:"storage.modifier",foreground:"569CD6"},{token:"type",foreground:"4EC9B0"},{token:"entity.name.type",foreground:"4EC9B0"},{token:"entity.name.class",foreground:"4EC9B0"},{token:"support.type",foreground:"4EC9B0"},{token:"entity.name.function",foreground:"DCDCAA"},{token:"support.function",foreground:"DCDCAA"},{token:"identifier",foreground:"9CDCFE"},{token:"string",foreground:"CE9178"},{token:"string.template",foreground:"CE9178"},{token:"number",foreground:"B5CEA8"},{token:"constant.language",foreground:"569CD6"},{token:"variable",foreground:"9CDCFE"},{token:"variable.parameter",foreground:"9CDCFE"},{token:"variable.language",foreground:"569CD6"},{token:"operator",foreground:"D4D4D4"},{token:"delimiter",foreground:"D4D4D4"},{token:"annotation",foreground:"DCDCAA"},{token:"regexp",foreground:"D16969"},{token:"key",foreground:"9CDCFE"},{token:"string.key.json",foreground:"9CDCFE"},{token:"string.value.json",foreground:"CE9178"},{token:"tag.css",foreground:"D7BA7D"},{token:"tag.scss",foreground:"D7BA7D"},{token:"tag.less",foreground:"D7BA7D"},{token:"entity.name.tag.css",foreground:"D7BA7D"},{token:"attribute.name.css",foreground:"9CDCFE"},{token:"attribute.name.scss",foreground:"9CDCFE"},{token:"attribute.name.less",foreground:"9CDCFE"},{token:"attribute.value.css",foreground:"CE9178"},{token:"attribute.value.scss",foreground:"CE9178"},{token:"attribute.value.less",foreground:"CE9178"},{token:"attribute.value.number.css",foreground:"B5CEA8"},{token:"attribute.value.unit.css",foreground:"9CDCFE"},{token:"attribute.value.hex.css",foreground:"CE9178"},{token:"string.css",foreground:"CE9178"},{token:"string.scss",foreground:"CE9178"},{token:"string.less",foreground:"CE9178"},{token:"keyword.css",foreground:"C586C0"},{token:"keyword.scss",foreground:"C586C0"},{token:"keyword.less",foreground:"C586C0"},{token:"number.css",foreground:"B5CEA8"},{token:"number.scss",foreground:"B5CEA8"},{token:"delimiter.css",foreground:"D4D4D4"},{token:"delimiter.scss",foreground:"D4D4D4"},{token:"delimiter.less",foreground:"D4D4D4"},{token:"pseudo.css",foreground:"D7BA7D"},{token:"unit.css",foreground:"9CDCFE"},{token:"variable.css",foreground:"9CDCFE"},{token:"variable.scss",foreground:"9CDCFE"},{token:"variable.less",foreground:"9CDCFE"},{token:"selector.css",foreground:"D7BA7D"},{token:"operator.css",foreground:"D4D4D4"}],colors:{"editor.background":"#1E1E1E","editor.foreground":"#D4D4D4","editor.lineHighlightBackground":"#2A2D2E","editor.selectionBackground":"#264F78","editor.inactiveSelectionBackground":"#3A3D41","editor.selectionHighlightBackground":"#ADD6FF26","editor.wordHighlightBackground":"#575757B8","editor.wordHighlightStrongBackground":"#004972B8","editorLineNumber.foreground":"#858585","editorLineNumber.activeForeground":"#C6C6C6","editorCursor.foreground":"#AEAFAD","editorWhitespace.foreground":"#3B4048","editorIndentGuide.background":"#404040","editorIndentGuide.activeBackground":"#707070","editorBracketMatch.background":"#0064001A","editorBracketMatch.border":"#888888","editor.findMatchBackground":"#515C6A","editor.findMatchHighlightBackground":"#EA5C0055","editorOverviewRuler.findMatchForeground":"#D186167E","editorSuggestWidget.background":"#252526","editorSuggestWidget.border":"#454545","editorSuggestWidget.foreground":"#D4D4D4","editorSuggestWidget.selectedBackground":"#062F4A","editorSuggestWidget.highlightForeground":"#18A3FF","editorHoverWidget.background":"#252526","editorHoverWidget.border":"#454545","peekView.border":"#007ACC","peekViewEditor.background":"#001F33","peekViewResult.background":"#252526","scrollbarSlider.background":"#79797966","scrollbarSlider.hoverBackground":"#646464B3","scrollbarSlider.activeBackground":"#BFBFBF66"}});let Z=0,Q=null;async function X(e,o){Q=e;const t=++Z;P({type:_});const n={"Content-Type":"application/json",authorization:e.token||""},r=e.hostAndPort,a=e.adminId,i=JSON.stringify(e.typesRequestBody||{});if(!o){if(!!!await K(V(r,a,i))&&(await new Promise((function(e){setTimeout(e,5e3)})),t!==Z))return}const c=[];try{const o=await Promise.all([fetch(e.typesUrl).then((function(e){return e.text()})),fetch(e.storeTypesUrl).then((function(e){return e.text()}))]);c.push({content:o[0],filePath:"file:///node_modules/@types/types/index.d.ts"}),c.push({content:o[1],filePath:"file:///node_modules/@types/store-types/index.d.ts"})}catch(e){console.error("[monaco-iframe] Failed to load asset types",e)}try{const e=V(r,a,i);let t=null;if(o||(t=await K(e)),t||z()&&(t=await(d=e,new Promise((function(e){let o=0;const t=setInterval((async function(){o++;try{const o=await K(d);if(o)return clearInterval(t),void e(o)}catch(e){}(!z()||o>=120)&&(clearInterval(t),e(null))}),500)})))),!t){!function(){try{localStorage.setItem(H,String(Date.now()))}catch(e){}}();try{t=await fetch(r+"/api/sites/types/"+a+"/get-common-types-from-be",{method:"POST",headers:n,body:i}).then((function(e){return e.json()})),t&&await W(e,t)}finally{J()}}t&&t.data&&Object.entries(t.data).forEach((function(e){c.push({content:e[1],filePath:e[0]})}))}catch(e){console.error("[monaco-iframe] Failed to load common types",e)}var d;try{const e=await fetch(r+"/api/sites/types/"+a+"/utility-class-types",{method:"POST",headers:n,body:i}).then((function(e){return e.json()}));e&&e.data&&Object.entries(e.data).forEach((function(e){c.push({content:e[1],filePath:e[0]})}))}catch(e){console.error("[monaco-iframe] Failed to load utility-class types",e)}try{const e=await fetch(r+"/api/sites/types/"+a+"/db-interfaces",{method:"POST",headers:n,body:JSON.stringify({})}).then((function(e){return e.json()}));e&&Object.entries(e).forEach((function(e){c.push({content:e[1],filePath:e[0]})}))}catch(e){console.error("[monaco-iframe] Failed to load DB interfaces",e)}t===Z&&(monaco.languages.typescript.typescriptDefaults.setExtraLibs(c),P({type:B}))}document.fonts.ready.then((function(){Y(),P({type:b})})),function(){const e=document.getElementById("reload-types-btn");e&&e.addEventListener("click",(async function(){if(Q){e.classList.add("loading"),e.textContent="↻ Loading…",function(){try{Object.keys(localStorage).forEach((function(e){e.startsWith(G)&&localStorage.removeItem(e)}))}catch(e){}J()}();try{await X(Q,!0)}finally{e.classList.remove("loading"),e.textContent="↺ Types"}}}))}(),window.addEventListener("keydown",(function(e){if(M)return!e.shiftKey||e.ctrlKey||e.metaKey||e.altKey||"Delete"!==e.key?void(function(e){return(e.ctrlKey||e.metaKey)&&e.altKey&&e.shiftKey&&("Backslash"===e.code||"\\"===e.key||"|"===e.key)}(e)&&(e.preventDefault(),e.stopPropagation(),R("idMonacoToggleZoom"))):(e.preventDefault(),e.stopPropagation(),M.trigger("keyboard","editor.action.deleteLines",void 0),void R("idMonacoDeleteLine"))}),!0),window.addEventListener("message",(function(S){const A=S.data;if(A&&A.type)switch(A.type){case e:U((function(e){e.setValue(A.payload.value||"")}));break;case o:{const e=A.requestId;U((function(o){P({type:O,payload:{value:o.getValue()},requestId:e})}));break}case t:A.payload&&U((function(e){const o=A.payload._modelUri,t=Object.assign({},A.payload);if(delete t._modelUri,e.updateOptions(t),o){const n=e.getModel()&&e.getModel().getLanguageId(),r=t.language||"plaintext"!==n&&n||"typescript",a=e.getValue(),i=monaco.editor.createModel(a,r,monaco.Uri.parse(o));e.setModel(i)}}));break;case n:U((function(e){const o=e.getModel();o&&monaco.editor.setModelLanguage(o,A.payload.language)}));break;case r:U((function(e){e.trigger(void 0,"editor.action.formatDocument",void 0)}));break;case a:A.payload&&null!=A.payload.text&&U((function(e){const o=e.getSelection();e.executeEdits("iframe-insert",[{identifier:{major:1,minor:1},range:o,text:A.payload.text,forceMoveMarkers:!0}])}));break;case s:if(A.payload){X(A.payload);const e=document.getElementById("reload-types-btn");e&&e.classList.add("visible")}break;case i:A.payload&&Array.isArray(A.payload.libs)&&monaco.languages.typescript.typescriptDefaults.setExtraLibs(A.payload.libs);break;case c:A.payload&&monaco.languages.typescript.typescriptDefaults.setCompilerOptions(A.payload);break;case d:A.payload&&monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions(A.payload);break;case f:A.payload&&A.payload.position&&U((function(e){e.setPosition(A.payload.position)}));break;case y:A.payload&&A.payload.selection&&U((function(e){e.setSelection(A.payload.selection)}));break;case p:A.payload&&null!=A.payload.top&&U((function(e){e.setScrollTop(A.payload.top)}));break;case k:A.payload&&null!=A.payload.left&&U((function(e){e.setScrollLeft(A.payload.left)}));break;case m:A.payload&&U((function(e){e.trigger(A.payload.source,A.payload.handlerId,A.payload.payload)}));break;case h:if(A.payload){const e=A.payload;F[e.id]=!0,U((function(o){o.addAction({id:e.id,label:e.label,keybindings:e.keybindings,precondition:e.precondition||null,keybindingContext:e.keybindingContext||null,contextMenuGroupId:e.contextMenuGroupId,contextMenuOrder:e.contextMenuOrder,run:function(){P({type:v,payload:{actionId:e.id}})}})}))}break;case C:A.payload&&U((function(e){const o=A.payload.oldDecorationIds||[],t=A.payload.newDecorations||[],n=A.payload.newParentIds||[],r=[];o.forEach((function(e){N[e]&&(N[e].forEach((function(e){r.push(e)})),delete N[e])}));const a=e.deltaDecorations(r,t);n.forEach((function(e,o){N[e]=a[o]?[a[o]]:[]}))}));break;case E:A.payload&&Array.isArray(A.payload.decorationIds)&&U((function(e){const o=[];A.payload.decorationIds.forEach((function(e){N[e]&&(N[e].forEach((function(e){o.push(e)})),delete N[e])})),o.length&&e.deltaDecorations(o,[])}));break;case l:{const e=A.payload||{};q();const o=Math.round(1e9*Math.random()),t=Math.round(1e9*Math.random()),n=e.language||"typescript",r=monaco.editor.createModel(e.text||"",n,monaco.Uri.parse("file:///"+o+"_Main.ts")),a=monaco.editor.createModel(e.editedText||"",n,monaco.Uri.parse("file:///"+t+"_Main.ts"));L=monaco.editor.createDiffEditor(document.getElementById("editor"),{originalEditable:!!e.isEditable,readOnly:!!e.isReadOnly,renderSideBySide:!0,automaticLayout:!0,theme:"vscode-dark-plus"}),L.setModel({original:r,modified:a});break}case u:Y(A.payload||{}),P({type:b});break;case g:U((function(e){e.focus()}));break;case D:A.payload&&A.payload.position&&U((function(e){e.revealPositionInCenter(A.payload.position)}))}}))}();