@johnoscott/isometric-engine 0.10.1 → 0.12.3
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.
- package/EDITOR-GUIDE.md +11 -1
- package/README.md +1 -1
- package/assets/app.css +31 -0
- package/assets/icons.svg +1 -1
- package/iso-editor.js +178 -178
- package/iso-render.js +97 -97
- package/iso-systems.js +104 -104
- package/js/iso-editor/doc.js +4 -0
- package/js/iso-editor/ui/canvas.js +185 -8
- package/js/iso-editor/ui/plain-icons.js +2 -0
- package/js/iso-editor/ui/setup.js +2 -1
- package/js/iso-objects/board.js +6 -1
- package/js/iso-objects/scene.js +3 -2
- package/js/iso-viewer/index.js +4 -1
- package/package.json +92 -92
- package/src/iso-core/compile-schema.ts +3 -1
- package/src/iso-editor/doc.ts +6 -0
- package/src/iso-editor/ui/app.css +31 -0
- package/src/iso-editor/ui/canvas.ts +130 -10
- package/src/iso-editor/ui/plain-icons.ts +2 -0
- package/src/iso-editor/ui/setup.ts +6 -2
- package/src/iso-objects/board.ts +6 -2
- package/src/iso-objects/scene.ts +4 -2
- package/src/iso-viewer/index.ts +2 -2
- package/src/iso-viewer/morph.ts +5 -2
- package/types/iso-core/compile-schema.d.ts +2 -2
- package/types/iso-editor/ui/canvas.d.ts +8 -0
- package/types/iso-editor/ui/monaco-entry.d.ts +2 -0
- package/types/iso-editor/ui/setup.d.ts +4 -0
- package/types/iso-systems/validate.d.ts +4 -0
- package/types/iso-viewer/bundle.d.ts +1 -0
- package/types/iso-viewer/index.d.ts +2 -2
- package/types/iso-viewer/morph.d.ts +6 -3
package/iso-editor.js
CHANGED
|
@@ -1,145 +1,145 @@
|
|
|
1
|
-
var Cf=Object.defineProperty;var Qo=(t,e)=>{for(var n in e)Cf(t,n,{get:e[n],enumerable:!0})};var ru={};Qo(ru,{Bounds:()=>ro,C:()=>It,DiagError:()=>zi,FONTS:()=>Bt,Kernel:()=>yr,S:()=>xt,VEl:()=>Ao,allowed:()=>Yl,apply:()=>no,bubble:()=>ti,buildSvg:()=>To,center:()=>Zo,colorRef:()=>Zn,createHash:()=>su,depthSort:()=>io,didYouMean:()=>Is,distance:()=>Gl,envelope:()=>ei,esc:()=>Dt,extendTheme:()=>Ki,faceFrame:()=>fl,fileLines:()=>ni,formatDiag:()=>Hl,formatDiags:()=>Jd,iso:()=>Xe,keyGlyph:()=>nd,loadTheme:()=>Bi,matStr:()=>so,n1:()=>Lt,parse:()=>Qd,parseSvg:()=>ql,placeholderFace:()=>rd,pt:()=>Xs,screenFaces:()=>xr,screenGlass:()=>od,serialize:()=>Vi,sha256Hex:()=>Ul,socketGlyph:()=>sd,tag:()=>Ve,termLines:()=>oo,textWidth:()=>$n,themeCss:()=>_i,themeParts:()=>Vl,vdoc:()=>tu});var td={sans700_13:{"0":.6787,"1":.5059,"2":.6372,"3":.6631,"4":.6812,"5":.6577,"6":.6777,"7":.6172,"8":.688,"9":.6777," ":.252,"!":.3506,'"':.563,"#":.6655,$:.6655,"%":1.0298,"&":.7388,"'":.3418,"(":.4229,")":.4229,"*":.4785,"+":.6655,",":.3418,"-":.4785,".":.3418,"/":.3286,":":.3418,";":.3418,"<":.6655,"=":.6655,">":.6655,"?":.5513,"@":.9214,A:.7266,B:.6875,C:.7354,D:.7417,E:.6162,F:.5918,G:.7544,H:.7773,I:.3125,J:.5952,K:.7036,L:.5889,M:.9009,N:.7622,O:.7808,P:.668,Q:.7808,R:.6885,S:.6694,T:.6543,U:.7544,V:.7153,W:1.0034,X:.7236,Y:.7021,Z:.6699,"[":.4229,"\\":.3286,"]":.4229,"^":.6655,_:.5845,"`":.4941,a:.584,b:.6455,c:.5815,d:.6455,e:.5952,f:.407,g:.6396,h:.6265,i:.2813,j:.2813,k:.5957,l:.2891,m:.9263,n:.6216,o:.6138,p:.6411,q:.6416,r:.4338,s:.5513,t:.4114,u:.6216,v:.5771,w:.8413,x:.5747,y:.5913,z:.5605,"{":.4229,"|":.2935,"}":.4229,"~":.6655,"\xB7":.3418,"\u2192":.9375,"\u2190":.9375,"\u2191":.8096,"\u2193":.8096,"\u2019":.3418,"\u2018":.3418,"\u201C":.5474,"\u201D":.5474,"\u2026":.9482,"\u2013":.6216,"\u2014":.9045,"\u2715":.7622,"\xD7":.6655,"\u2248":.6655,"\u2264":.6655,"\u2265":.6655,\u00E9:.5952},sans800_15:{"0":.687,"1":.5122,"2":.6406,"3":.6675,"4":.686,"5":.6626,"6":.6836,"7":.6191,"8":.6968,"9":.6836," ":.2344,"!":.3555,'"':.5835,"#":.6694,$:.6694,"%":1.0566,"&":.7397,"'":.3491,"(":.4287,")":.4287,"*":.4731,"+":.6694,",":.3491,"-":.4731,".":.3491,"/":.3286,":":.3491,";":.3491,"<":.6694,"=":.6694,">":.6694,"?":.5562,"@":.9146,A:.7363,B:.6899,C:.7339,D:.7388,E:.6147,F:.5903,G:.749,H:.7813,I:.3198,J:.6064,K:.7104,L:.5879,M:.9019,N:.7612,O:.7759,P:.6709,Q:.7759,R:.6924,S:.6719,T:.6533,U:.7524,V:.7212,W:1.0073,X:.731,Y:.71,Z:.6646,"[":.4287,"\\":.3286,"]":.4287,"^":.6694,_:.5889,"`":.4844,a:.5864,b:.6479,c:.5811,d:.6479,e:.5952,f:.4139,g:.6416,h:.6309,i:.2847,j:.2847,k:.605,l:.2935,m:.937,n:.626,o:.6138,p:.6436,q:.6445,r:.4406,s:.5557,t:.4198,u:.626,v:.5806,w:.856,x:.5835,y:.5996,z:.5601,"{":.4287,"|":.2974,"}":.4287,"~":.6694,"\xB7":.3491,"\u2192":.9404,"\u2190":.9404,"\u2191":.811,"\u2193":.811,"\u2019":.3491,"\u2018":.3491,"\u201C":.5688,"\u201D":.5688,"\u2026":.9883,"\u2013":.626,"\u2014":.9118,"\u2715":.7622,"\xD7":.6694,"\u2248":.6694,"\u2264":.6694,"\u2265":.6694,\u00E9:.5952},sans800_10_5:{"0":.7114,"1":.5366,"2":.665,"3":.6919,"4":.7104,"5":.687,"6":.708,"7":.6436,"8":.7212,"9":.708," ":.2588,"!":.3799,'"':.6079,"#":.6938,$:.6938,"%":1.0811,"&":.7642,"'":.3735,"(":.4531,")":.4531,"*":.4976,"+":.6938,",":.3735,"-":.4976,".":.3735,"/":.353,":":.3735,";":.3735,"<":.6938,"=":.6938,">":.6938,"?":.5806,"@":.939,A:.7607,B:.7144,C:.7583,D:.7632,E:.6392,F:.6147,G:.7734,H:.8057,I:.3442,J:.6309,K:.7349,L:.6123,M:.9263,N:.7856,O:.8003,P:.6953,Q:.8003,R:.7168,S:.6963,T:.6777,U:.7769,V:.7456,W:1.0317,X:.7554,Y:.7344,Z:.689,"[":.4531,"\\":.353,"]":.4531,"^":.6938,_:.6133,"`":.5088,a:.6108,b:.6724,c:.6055,d:.6724,e:.6196,f:.4383,g:.666,h:.6553,i:.3091,j:.3091,k:.6294,l:.3179,m:.9614,n:.6504,o:.6382,p:.668,q:.6689,r:.465,s:.5801,t:.4442,u:.6504,v:.605,w:.8804,x:.6079,y:.624,z:.5845,"{":.4531,"|":.3218,"}":.4531,"~":.6938,"\xB7":.3735,"\u2192":.9648,"\u2190":.9648,"\u2191":.8354,"\u2193":.8354,"\u2019":.3735,"\u2018":.3735,"\u201C":.5933,"\u201D":.5933,"\u2026":1.0127,"\u2013":.6504,"\u2014":.9204,"\u2715":.7622,"\xD7":.6938,"\u2248":.6938,"\u2264":.6938,"\u2265":.6938,\u00E9:.6196},sans600_12:{"0":.6665,"1":.4956,"2":.6299,"3":.6548,"4":.6724,"5":.6484,"6":.668,"7":.6113,"8":.6753,"9":.668," ":.2656,"!":.3413,'"':.5386,"#":.6577,$:.6577,"%":.999,"&":.7334,"'":.3306,"(":.4131,")":.4131,"*":.48,"+":.6577,",":.3306,"-":.48,".":.3306,"/":.3247,":":.3306,";":.3306,"<":.6577,"=":.6577,">":.6577,"?":.5425,"@":.9238,A:.7129,B:.6812,C:.7329,D:.7402,E:.6133,F:.5889,G:.7559,H:.7695,I:.3013,J:.5801,K:.6924,L:.5859,M:.8955,N:.7593,O:.7813,P:.6606,Q:.7813,R:.6807,S:.6626,T:.6514,U:.7524,V:.7056,W:.9956,X:.7124,Y:.6904,Z:.6709,"[":.4131,"\\":.3247,"]":.4131,"^":.6577,_:.5757,"`":.5,a:.5771,b:.6392,c:.5781,d:.6392,e:.5908,f:.3957,g:.6333,h:.6177,i:.2739,j:.2734,k:.582,l:.2808,m:.9116,n:.6128,o:.6099,p:.6348,q:.6348,r:.4232,s:.543,t:.3991,u:.6128,v:.5693,w:.8228,x:.562,y:.5791,z:.5571,"{":.4131,"|":.2856,"}":.4131,"~":.6577,"\xB7":.3306,"\u2192":.9307,"\u2190":.9307,"\u2191":.8037,"\u2193":.8037,"\u2019":.3306,"\u2018":.3306,"\u201C":.522,"\u201D":.522,"\u2026":.9043,"\u2013":.6128,"\u2014":.8957,"\u2715":.7622,"\xD7":.6577,"\u2248":.6577,"\u2264":.6577,"\u2265":.6577,\u00E9:.5908},sans800_12:{"0":.7026,"1":.5278,"2":.6563,"3":.6831,"4":.7017,"5":.6782,"6":.6992,"7":.6348,"8":.7124,"9":.6992," ":.25,"!":.3711,'"':.5991,"#":.6851,$:.6851,"%":1.0723,"&":.7554,"'":.3647,"(":.4443,")":.4443,"*":.4888,"+":.6851,",":.3647,"-":.4888,".":.3647,"/":.3442,":":.3647,";":.3647,"<":.6851,"=":.6851,">":.6851,"?":.5718,"@":.9302,A:.752,B:.7056,C:.7495,D:.7544,E:.6304,F:.606,G:.7646,H:.7969,I:.3354,J:.6221,K:.7261,L:.6035,M:.9175,N:.7769,O:.7915,P:.6865,Q:.7915,R:.708,S:.6875,T:.6689,U:.7681,V:.7368,W:1.0229,X:.7466,Y:.7256,Z:.6802,"[":.4443,"\\":.3442,"]":.4443,"^":.6851,_:.6045,"`":.5,a:.6021,b:.6636,c:.5967,d:.6636,e:.6108,f:.4295,g:.6572,h:.6465,i:.3003,j:.3003,k:.6206,l:.3091,m:.9526,n:.6416,o:.6294,p:.6592,q:.6602,r:.4562,s:.5713,t:.4354,u:.6416,v:.5962,w:.8716,x:.5991,y:.6152,z:.5757,"{":.4443,"|":.313,"}":.4443,"~":.6851,"\xB7":.3647,"\u2192":.9561,"\u2190":.9561,"\u2191":.8267,"\u2193":.8267,"\u2019":.3647,"\u2018":.3647,"\u201C":.5845,"\u201D":.5845,"\u2026":1.0039,"\u2013":.6416,"\u2014":.9173,"\u2715":.7622,"\xD7":.6851,"\u2248":.6851,"\u2264":.6851,"\u2265":.6851,\u00E9:.6108},sans800_11_5:{"0":.7056,"1":.5308,"2":.6592,"3":.686,"4":.7046,"5":.6812,"6":.7021,"7":.6377,"8":.7153,"9":.7021," ":.2529,"!":.374,'"':.6021,"#":.688,$:.688,"%":1.0752,"&":.7583,"'":.3677,"(":.4473,")":.4473,"*":.4917,"+":.688,",":.3677,"-":.4917,".":.3677,"/":.3472,":":.3677,";":.3677,"<":.688,"=":.688,">":.688,"?":.5747,"@":.9331,A:.7549,B:.7085,C:.7524,D:.7573,E:.6333,F:.6089,G:.7676,H:.7998,I:.3384,J:.625,K:.729,L:.6064,M:.9204,N:.7798,O:.7944,P:.6895,Q:.7944,R:.7109,S:.6904,T:.6719,U:.771,V:.7397,W:1.0259,X:.7495,Y:.7285,Z:.6831,"[":.4473,"\\":.3472,"]":.4473,"^":.688,_:.6074,"`":.5029,a:.605,b:.6665,c:.5996,d:.6665,e:.6138,f:.4325,g:.6602,h:.6494,i:.3032,j:.3032,k:.6235,l:.312,m:.9556,n:.6445,o:.6323,p:.6621,q:.6631,r:.4591,s:.5742,t:.4383,u:.6445,v:.5991,w:.8745,x:.6021,y:.6182,z:.5786,"{":.4473,"|":.3159,"}":.4473,"~":.688,"\xB7":.3677,"\u2192":.959,"\u2190":.959,"\u2191":.8296,"\u2193":.8296,"\u2019":.3677,"\u2018":.3677,"\u201C":.5874,"\u201D":.5874,"\u2026":1.0068,"\u2013":.6445,"\u2014":.9183,"\u2715":.7622,"\xD7":.688,"\u2248":.688,"\u2264":.688,"\u2265":.688,\u00E9:.6138},sans400_13:{"0":.624,"1":.458,"2":.5977,"3":.6211,"4":.6377,"5":.6123,"6":.6309,"7":.582,"8":.6328,"9":.6309," ":.2754,"!":.3052,'"':.4717,"#":.624,$:.624,"%":.9194,"&":.7056,"'":.291,"(":.376,")":.376,"*":.4658,"+":.624,",":.291,"-":.4658,".":.291,"/":.2988,":":.291,";":.291,"<":.624,"=":.624,">":.624,"?":.5068,"@":.9121,A:.668,B:.6514,C:.71,D:.7207,E:.5898,F:.5664,G:.7407,H:.7363,I:.2617,J:.5322,K:.6528,L:.562,M:.8682,N:.7363,O:.7656,P:.6294,Q:.7656,R:.6475,S:.6313,T:.6279,U:.7314,V:.668,W:.9619,X:.6729,Y:.6494,Z:.6558,"[":.376,"\\":.2988,"]":.376,"^":.624,_:.5405,"`":.4941,a:.5459,b:.6084,c:.5537,d:.6084,e:.5654,f:.356,g:.6035,h:.5825,i:.2412,j:.2407,k:.5371,l:.2471,m:.8643,n:.5776,o:.585,p:.6045,q:.6035,r:.3843,s:.5083,t:.3574,u:.5776,v:.5361,w:.7686,x:.5186,y:.5371,z:.5332,"{":.376,"|":.2529,"}":.376,"~":.624,"\xB7":.291,"\u2192":.8999,"\u2190":.8999,"\u2191":.7754,"\u2193":.7754,"\u2019":.291,"\u2018":.291,"\u201C":.4531,"\u201D":.4531,"\u2026":.7988,"\u2013":.5776,"\u2014":.872,"\u2715":.7622,"\xD7":.624,"\u2248":.624,"\u2264":.624,"\u2265":.624,\u00E9:.5654},mono400_11:{"0":.6021,"1":.6021,"2":.6021,"3":.6021,"4":.6021,"5":.6021,"6":.6021,"7":.6021,"8":.6021,"9":.6021," ":.6021,"!":.6021,'"':.6021,"#":.6021,$:.6021,"%":.6021,"&":.6021,"'":.6021,"(":.6021,")":.6021,"*":.6021,"+":.6021,",":.6021,"-":.6021,".":.6021,"/":.6021,":":.6021,";":.6021,"<":.6021,"=":.6021,">":.6021,"?":.6021,"@":.6021,A:.6021,B:.6021,C:.6021,D:.6021,E:.6021,F:.6021,G:.6021,H:.6021,I:.6021,J:.6021,K:.6021,L:.6021,M:.6021,N:.6021,O:.6021,P:.6021,Q:.6021,R:.6021,S:.6021,T:.6021,U:.6021,V:.6021,W:.6021,X:.6021,Y:.6021,Z:.6021,"[":.6021,"\\":.6021,"]":.6021,"^":.6021,_:.6021,"`":.6021,a:.6021,b:.6021,c:.6021,d:.6021,e:.6021,f:.6021,g:.6021,h:.6021,i:.6021,j:.6021,k:.6021,l:.6021,m:.6021,n:.6021,o:.6021,p:.6021,q:.6021,r:.6021,s:.6021,t:.6021,u:.6021,v:.6021,w:.6021,x:.6021,y:.6021,z:.6021,"{":.6021,"|":.6021,"}":.6021,"~":.6021,"\xB7":.6021,"\u2192":.6021,"\u2190":.6021,"\u2191":.6021,"\u2193":.6021,"\u2019":.6021,"\u2018":.6021,"\u201C":.6021,"\u201D":.6021,"\u2026":.6021,"\u2013":.6021,"\u2014":.6021,"\u2715":.6021,"\xD7":.6021,"\u2248":.6021,"\u2264":.6021,"\u2265":.6021,\u00E9:.6021},mono600_11:{"0":.6021,"1":.6021,"2":.6021,"3":.6021,"4":.6021,"5":.6021,"6":.6021,"7":.6021,"8":.6021,"9":.6021," ":.6021,"!":.6021,'"':.6021,"#":.6021,$:.6021,"%":.6021,"&":.6021,"'":.6021,"(":.6021,")":.6021,"*":.6021,"+":.6021,",":.6021,"-":.6021,".":.6021,"/":.6021,":":.6021,";":.6021,"<":.6021,"=":.6021,">":.6021,"?":.6021,"@":.6021,A:.6021,B:.6021,C:.6021,D:.6021,E:.6021,F:.6021,G:.6021,H:.6021,I:.6021,J:.6021,K:.6021,L:.6021,M:.6021,N:.6021,O:.6021,P:.6021,Q:.6021,R:.6021,S:.6021,T:.6021,U:.6021,V:.6021,W:.6021,X:.6021,Y:.6021,Z:.6021,"[":.6021,"\\":.6021,"]":.6021,"^":.6021,_:.6021,"`":.6021,a:.6021,b:.6021,c:.6021,d:.6021,e:.6021,f:.6021,g:.6021,h:.6021,i:.6021,j:.6021,k:.6021,l:.6021,m:.6021,n:.6021,o:.6021,p:.6021,q:.6021,r:.6021,s:.6021,t:.6021,u:.6021,v:.6021,w:.6021,x:.6021,y:.6021,z:.6021,"{":.6021,"|":.6021,"}":.6021,"~":.6021,"\xB7":.6021,"\u2192":.6021,"\u2190":.6021,"\u2191":.6021,"\u2193":.6021,"\u2019":.6021,"\u2018":.6021,"\u201C":.6021,"\u201D":.6021,"\u2026":.6021,"\u2013":.6021,"\u2014":.6021,"\u2715":.6021,"\xD7":.6021,"\u2248":.6021,"\u2264":.6021,"\u2265":.6021,\u00E9:.6021}};var xt=34,It=Math.cos(Math.PI/6),Xe=(t,e,n=0)=>[(t-e)*It*xt,(t+e)*.5*xt-n*xt],Lt=t=>{let e=Math.round(t*10)/10;return Object.is(e,-0)?"0":String(e)},Xs=t=>`${Lt(t[0])},${Lt(t[1])}`,Dt=t=>t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""");function Ve(t,e={},n){let s="";for(let r in e){let o=e[r];o==null||o===!1||o===""||(s+=` ${r}="${Dt(typeof o=="number"?Lt(o):o)}"`)}return n===void 0?`<${t}${s}/>`:`<${t}${s}>${n}</${t}>`}var Bt={lbl:{key:"sans700_13",size:13},sub:{key:"mono400_11",size:11},slabname:{key:"sans800_15",size:15,spacing:.12},sm:{key:"sans800_10_5",size:10.5,spacing:.1},floor:{key:"mono600_11",size:11,spacing:.01},say:{key:"sans600_12",size:12},tunname:{key:"sans800_12",size:12,spacing:.14},badge:{key:"sans800_11_5",size:11.5}};function $n(t,e){let n=td[e.key],s=e.key.startsWith("mono")?.6:.58,r=0;for(let o of t)r+=n[o]??s;return(r+(e.spacing??0)*[...t].length)*e.size}var no=(t,e,n)=>[t[0]*e+t[2]*n+t[4],t[1]*e+t[3]*n+t[5]],so=t=>`matrix(${t.map(e=>Math.round(e*1e4)/1e4).join(" ")})`;function fl(t,e){if(e==="left"){let[r,o]=Xe(t.x0,t.y1,t.z1);return{m:[It,.5,0,1,r,o],w:(t.x1-t.x0)*xt,h:(t.z1-t.z0)*xt}}if(e==="right"){let[r,o]=Xe(t.x1,t.y1,t.z1);return{m:[It,-.5,0,1,r,o],w:(t.y1-t.y0)*xt,h:(t.z1-t.z0)*xt}}let[n,s]=Xe(t.x0,t.y0,t.z1);return{m:[It,.5,-It,.5,n,s],w:(t.x1-t.x0)*xt,h:(t.y1-t.y0)*xt}}var ro=class{x0=1/0;y0=1/0;x1=-1/0;y1=-1/0;add(e){e[0]<this.x0&&(this.x0=e[0]),e[0]>this.x1&&(this.x1=e[0]),e[1]<this.y0&&(this.y0=e[1]),e[1]>this.y1&&(this.y1=e[1])}addRect(e,n,s,r){this.add([e,n]),this.add([e+s,n+r])}get empty(){return this.x0===1/0}},yr=class{bounds=new ro;texts=[];planes=[];planePolys=[];defs=new Map;poly(e,n,s={}){let r=e.map(o=>Xe(o[0],o[1],o[2]));return r.forEach(o=>this.bounds.add(o)),Ve("polygon",{points:r.map(Xs).join(" "),class:n,...s})}line3(e,n,s,r={}){let o=Xe(...e),i=Xe(...n);return this.bounds.add(o),this.bounds.add(i),Ve("line",{x1:o[0],y1:o[1],x2:i[0],y2:i[1],class:s,...r})}blockFaces(e){let{x0:n,y0:s,x1:r,y1:o,z0:i,z1:a}=e;return this.poly([[n,o,i],[r,o,i],[r,o,a],[n,o,a]],"lft")+this.poly([[r,s,i],[r,o,i],[r,o,a],[r,s,a]],"rgt")+this.poly([[n,s,a],[r,s,a],[r,o,a],[n,o,a]],"top")}onFace(e,n,s,r){let o=fl(e,n);for(let[i,a]of[[0,0],[o.w,0],[0,o.h],[o.w,o.h]])this.bounds.add(no(o.m,i,a));return Ve("g",{class:r,transform:so(o.m)},s(o.w,o.h))}onMatrix(e,n,s,r,o){for(let[i,a]of[[0,0],[n,0],[0,s],[n,s]])this.bounds.add(no(e,i,a));return Ve("g",{class:o,transform:so(e)},r(n,s))}text(e,n,s,r,o,i="middle",a={},l){let c=$n(s,o),u={x:i==="start"?e:i==="end"?e-c:e-c/2,y:n-o.size*.8,w:c,h:o.size*1.05,text:s,owner:l};return this.bounds.addRect(u.x-2,u.y-2,u.w+4,u.h+4),this.texts.push(u),Ve("text",{x:e,y:n,class:r,"text-anchor":i==="start"?void 0:i,...a},Dt(s))}planeText(e,n,s,r,o="start",i={}){let a=$n(n,r),l=o==="start"?0:o==="end"?-a:-a/2,c=[[l,-r.size*.8],[l+a,-r.size*.8],[l,r.size*.25],[l+a,r.size*.25]].map(([f,p])=>no(e,f,p));c.forEach(f=>this.bounds.add(f));let d=c.map(f=>f[0]),u=c.map(f=>f[1]);return this.planePolys.push([c[0],c[1],c[3],c[2]]),this.planes.push({x:Math.min(...d),y:Math.min(...u),w:Math.max(...d)-Math.min(...d),h:Math.max(...u)-Math.min(...u)}),Ve("text",{transform:so(e),class:s,"text-anchor":o==="start"?void 0:o,...i},Dt(n))}floorText(e,n,s,r,o,i="x",a="start",l={}){let[c,d]=Xe(e,n,s),u=i==="x"?[It,.5,-It,.5,c,d]:[It,-.5,It,.5,c,d];return this.planeText(u,r,o,Bt.floor,a,l)}faceText(e,n,s,r,o,i,a="left",l="start",c={}){let[d,u]=Xe(e,n,s),f=a==="left"?[It,.5,0,1,d,u]:[It,-.5,0,1,d,u];return this.planeText(f,r,o,i,l,c)}def(e,n){this.defs.set(e,n)}},Zo=t=>[(t.x0+t.x1)/2,(t.y0+t.y1)/2,t.z1];function oo(t,e,n){let s="";for(let r=0;r<n;r++){let o=e.z1-(e.z1-e.z0)*(.28+r*.2),i=(e.x1-e.x0)*(r===n-1?.35:.62-r*.1);s+=t.line3([e.x0+.35,e.y1,o],[e.x0+.35+i,e.y1,o],"det")}return s}function ei(t,e){let s=e.z1,r=[e.x0+.55,e.y0+.55,s],o=[e.x1-.55,e.y0+.55,s],i=[e.x1-.55,e.y1-.55,s],a=[e.x0+.55,e.y1-.55,s],l=[(e.x0+e.x1)/2,(e.y0+e.y1)/2,s];return t.poly([r,o,i,a],"det")+t.line3(r,l,"det")+t.line3(l,o,"det")}function ti(t,e){let s=e.z1,r=t.poly([[e.x0+.55,e.y0+.55,s],[e.x1-.55,e.y0+.55,s],[e.x1-.55,e.y1-.55,s],[e.x0+.55,e.y1-.55,s]],"det");for(let o=1;o<=2;o++){let i=e.y0+.55+(e.y1-e.y0-1.1)*o/3;r+=t.line3([e.x0+.55+.3,i,s],[e.x1-.55-.3-(o===2?.5:0),i,s],"det")}return r}function ni(t,e){let s=e.z1,r=(e.y0+e.y1)/2;return t.line3([e.x0+.3,r-.2,s],[e.x1-.3,r-.2,s],"det")+t.line3([e.x0+.3,r+.2,s],[e.x1-.3-.3,r+.2,s],"det")}function nd(t,e){let n=(e.x0+e.x1)/2,s=(e.y0+e.y1)/2,r=e.z1+.005,o=Math.min(e.x1-e.x0,e.y1-e.y0)*.16,i=[];for(let a=0;a<20;a++){let l=a/20*Math.PI*2;i.push([n-o*1.4+Math.cos(l)*o,s+Math.sin(l)*o,r])}return t.poly(i,"det")+t.line3([n-o*.4,s,r],[n+o*2.2,s,r],"det")+t.line3([n+o*1.7,s,r],[n+o*1.7,s+o*.8,r],"det")}function sd(t,e){let n=(e.x0+e.x1)/2,s=(e.y0+e.y1)/2,r=e.z1+.005,o=Math.min(e.x1-e.x0,e.y1-e.y0)*.28,i=[];for(let a=0;a<24;a++){let l=a/24*Math.PI*2;i.push([n+Math.cos(l)*o,s+Math.sin(l)*o,r])}return t.poly(i,"det sock-hole")}var Qs=(t,e,n,s,r,o=0)=>Ve("rect",{class:t,x:e,y:n,width:s,height:r,rx:o||void 0}),xr={terminal(t,e){let n="",s=Math.max(2,Math.floor((e-12)/9));for(let r=0;r<s;r++){let o=10+r*9,i=(t-18)*[.7,.45,.6,.3,.55][r%5];n+=Ve("line",{class:"ln",x1:8,y1:o,x2:8+i,y2:o})}return n},chat(t,e){return[[6,.62,"w"],[.3,.58,"m"],[6,.46,"w"],[.42,.5,"m"]].map((s,r)=>{let o=(t-14)*s[1],i=s[0]===6?7:t-7-o;return Qs(s[2],i,8+r*(e-18)/4,o,(e-18)/4-4,3)}).join("")},desktop(t,e){return Qs("wall",5,5,t-10,e-10,2)+Qs("bar",5,5,t-10,6)+Qs("win",t*.5,13,t*.38,e*.42,2)},tiles(t,e){let i=(t-12-5)/3,a=(e-12-2.5*1)/2,l="";for(let c=0;c<2;c++)for(let d=0;d<3;d++){let u=6+d*(i+2.5),f=6+c*(a+2.5);l+=Qs("t",u,f,i,a,1.5),[.3,.52,.74].forEach((p,g)=>{l+=Ve("line",{class:"ln",x1:u+2.5,y1:f+a*p,x2:u+2.5+(i-5)*[.8,.5,.65][(g+c+d)%3],y2:f+a*p})})}return l}};function rd(t,e){let n=t/2,s=e/2,r=Math.min(t,e)*.22;return Qs("unk",t*.2,e*.2,t*.6,e*.6,2)+Ve("path",{class:"unk-q",d:`M${Lt(n-r*.5)},${Lt(s-r*.45)}a${Lt(r*.5)},${Lt(r*.5)} 0 1 1 ${Lt(r*.5)},${Lt(r*.55)}v${Lt(r*.3)}`})+Ve("circle",{class:"unk-dot",cx:Lt(n),cy:Lt(s+r*.75),r:Lt(Math.max(.8,r*.1))})}function od(t,e){return Qs("glass",3,3,t-6,e-6,3)}function Rf(t){let e=[Xe(t.x0,t.y0,t.z1),Xe(t.x1,t.y0,t.z0),Xe(t.x0,t.y1,t.z0),Xe(t.x1,t.y1,t.z0),Xe(t.x1,t.y1,t.z1),Xe(t.x0,t.y0,t.z0)],n=e.map(r=>r[0]),s=e.map(r=>r[1]);return[Math.min(...n),Math.min(...s),Math.max(...n),Math.max(...s)]}function If(t,e){let s=t.x1<=e.x0+1e-6,r=e.x1<=t.x0+1e-6,o=t.y1<=e.y0+1e-6,i=e.y1<=t.y0+1e-6,a=t.z1<=e.z0+1e-6,l=e.z1<=t.z0+1e-6,c=s||o||a,d=r||i||l;return c&&!d?-1:d&&!c?1:0}function io(t){let e=t.length,n=t.map(c=>Rf(c.box)),s=c=>c.box.x0+c.box.y0+c.box.z0*.01,r=t.map(()=>[]),o=new Array(e).fill(0);for(let c=0;c<e;c++)for(let d=c+1;d<e;d++){let u=n[c],f=n[d];if(u[2]<=f[0]||f[2]<=u[0]||u[3]<=f[1]||f[3]<=u[1])continue;let p=If(t[c].box,t[d].box);p<0?(r[c].push(d),o[d]++):p>0&&(r[d].push(c),o[c]++)}let i=[],a=t.map((c,d)=>d).filter(c=>!o[c]),l=new Array(e).fill(!1);for(;i.length<e;){if(!a.length){let d=t.map((u,f)=>f).filter(u=>!l[u]).sort((u,f)=>s(t[u])-s(t[f]));a.push(d[0]),o[d[0]]=0}a.sort((d,u)=>s(t[d])-s(t[u])||d-u);let c=a.shift();if(!l[c]){l[c]=!0,i.push(t[c]);for(let d of r[c])!l[d]&&--o[d]===0&&a.push(d)}}return i}var si=Symbol.for("yaml.alias"),ri=Symbol.for("yaml.document"),Ln=Symbol.for("yaml.map"),pl=Symbol.for("yaml.pair"),xn=Symbol.for("yaml.scalar"),fs=Symbol.for("yaml.seq"),ln=Symbol.for("yaml.node.type"),Rn=t=>!!t&&typeof t=="object"&&t[ln]===si,In=t=>!!t&&typeof t=="object"&&t[ln]===ri,lt=t=>!!t&&typeof t=="object"&&t[ln]===Ln,tt=t=>!!t&&typeof t=="object"&&t[ln]===pl,He=t=>!!t&&typeof t=="object"&&t[ln]===xn,At=t=>!!t&&typeof t=="object"&&t[ln]===fs;function wt(t){if(t&&typeof t=="object")switch(t[ln]){case Ln:case fs:return!0}return!1}function mt(t){if(t&&typeof t=="object")switch(t[ln]){case si:case Ln:case xn:case fs:return!0}return!1}var oi=t=>(He(t)||wt(t))&&!!t.anchor;var pn=Symbol("break visit"),id=Symbol("skip children"),qn=Symbol("remove node");function Un(t,e){let n=ad(e);In(t)?wr(null,t.contents,n,Object.freeze([t]))===qn&&(t.contents=null):wr(null,t,n,Object.freeze([]))}Un.BREAK=pn;Un.SKIP=id;Un.REMOVE=qn;function wr(t,e,n,s){let r=ld(t,e,n,s);if(mt(r)||tt(r))return cd(t,s,r),wr(t,r,n,s);if(typeof r!="symbol"){if(wt(e)){s=Object.freeze(s.concat(e));for(let o=0;o<e.items.length;++o){let i=wr(o,e.items[o],n,s);if(typeof i=="number")o=i-1;else{if(i===pn)return pn;i===qn&&(e.items.splice(o,1),o-=1)}}}else if(tt(e)){s=Object.freeze(s.concat(e));let o=wr("key",e.key,n,s);if(o===pn)return pn;o===qn&&(e.key=null);let i=wr("value",e.value,n,s);if(i===pn)return pn;i===qn&&(e.value=null)}}return r}async function ii(t,e){let n=ad(e);In(t)?await vr(null,t.contents,n,Object.freeze([t]))===qn&&(t.contents=null):await vr(null,t,n,Object.freeze([]))}ii.BREAK=pn;ii.SKIP=id;ii.REMOVE=qn;async function vr(t,e,n,s){let r=await ld(t,e,n,s);if(mt(r)||tt(r))return cd(t,s,r),vr(t,r,n,s);if(typeof r!="symbol"){if(wt(e)){s=Object.freeze(s.concat(e));for(let o=0;o<e.items.length;++o){let i=await vr(o,e.items[o],n,s);if(typeof i=="number")o=i-1;else{if(i===pn)return pn;i===qn&&(e.items.splice(o,1),o-=1)}}}else if(tt(e)){s=Object.freeze(s.concat(e));let o=await vr("key",e.key,n,s);if(o===pn)return pn;o===qn&&(e.key=null);let i=await vr("value",e.value,n,s);if(i===pn)return pn;i===qn&&(e.value=null)}}return r}function ad(t){return typeof t=="object"&&(t.Collection||t.Node||t.Value)?Object.assign({Alias:t.Node,Map:t.Node,Scalar:t.Node,Seq:t.Node},t.Value&&{Map:t.Value,Scalar:t.Value,Seq:t.Value},t.Collection&&{Map:t.Collection,Seq:t.Collection},t):t}function ld(t,e,n,s){if(typeof n=="function")return n(t,e,s);if(lt(e))return n.Map?.(t,e,s);if(At(e))return n.Seq?.(t,e,s);if(tt(e))return n.Pair?.(t,e,s);if(He(e))return n.Scalar?.(t,e,s);if(Rn(e))return n.Alias?.(t,e,s)}function cd(t,e,n){let s=e[e.length-1];if(wt(s))s.items[t]=n;else if(tt(s))t==="key"?s.key=n:s.value=n;else if(In(s))s.contents=n;else{let r=Rn(s)?"alias":"scalar";throw new Error(`Cannot replace node with ${r} parent`)}}var Df={"!":"%21",",":"%2C","[":"%5B","]":"%5D","{":"%7B","}":"%7D"},Ff=t=>t.replace(/[!,[\]{}]/g,e=>Df[e]),Wn=class t{constructor(e,n){this.docStart=null,this.docEnd=!1,this.yaml=Object.assign({},t.defaultYaml,e),this.tags=Object.assign({},t.defaultTags,n)}clone(){let e=new t(this.yaml,this.tags);return e.docStart=this.docStart,e}atDocument(){let e=new t(this.yaml,this.tags);switch(this.yaml.version){case"1.1":this.atNextDocument=!0;break;case"1.2":this.atNextDocument=!1,this.yaml={explicit:t.defaultYaml.explicit,version:"1.2"},this.tags=Object.assign({},t.defaultTags);break}return e}add(e,n){this.atNextDocument&&(this.yaml={explicit:t.defaultYaml.explicit,version:"1.1"},this.tags=Object.assign({},t.defaultTags),this.atNextDocument=!1);let s=e.trim().split(/[ \t]+/),r=s.shift();switch(r){case"%TAG":{if(s.length!==2&&(n(0,"%TAG directive should contain exactly two parts"),s.length<2))return!1;let[o,i]=s;return this.tags[o]=i,!0}case"%YAML":{if(this.yaml.explicit=!0,s.length!==1)return n(0,"%YAML directive should contain exactly one part"),!1;let[o]=s;if(o==="1.1"||o==="1.2")return this.yaml.version=o,!0;{let i=/^\d+\.\d+$/.test(o);return n(6,`Unsupported YAML version ${o}`,i),!1}}default:return n(0,`Unknown directive ${r}`,!0),!1}}tagName(e,n){if(e==="!")return"!";if(e[0]!=="!")return n(`Not a valid tag: ${e}`),null;if(e[1]==="<"){let i=e.slice(2,-1);return i==="!"||i==="!!"?(n(`Verbatim tags aren't resolved, so ${e} is invalid.`),null):(e[e.length-1]!==">"&&n("Verbatim tags must end with a >"),i)}let[,s,r]=e.match(/^(.*!)([^!]*)$/s);r||n(`The ${e} tag has no suffix`);let o=this.tags[s];if(o)try{return o+decodeURIComponent(r)}catch(i){return n(String(i)),null}return s==="!"?e:(n(`Could not resolve tag: ${e}`),null)}tagString(e){for(let[n,s]of Object.entries(this.tags))if(e.startsWith(s))return n+Ff(e.substring(s.length));return e[0]==="!"?e:`!<${e}>`}toString(e){let n=this.yaml.explicit?[`%YAML ${this.yaml.version||"1.2"}`]:[],s=Object.entries(this.tags),r;if(e&&s.length>0&&mt(e.contents)){let o={};Un(e.contents,(i,a)=>{mt(a)&&a.tag&&(o[a.tag]=!0)}),r=Object.keys(o)}else r=[];for(let[o,i]of s)o==="!!"&&i==="tag:yaml.org,2002:"||(!e||r.some(a=>a.startsWith(i)))&&n.push(`%TAG ${o} ${i}`);return n.join(`
|
|
2
|
-
`)}};
|
|
3
|
-
`)?
|
|
1
|
+
var np=Object.defineProperty;var hi=(t,e)=>{for(var n in e)np(t,n,{get:e[n],enumerable:!0})};var Au={};hi(Au,{Bounds:()=>bo,C:()=>Bt,DiagError:()=>oa,FONTS:()=>It,Kernel:()=>Pr,S:()=>xt,VEl:()=>Ko,allowed:()=>fc,apply:()=>ho,bubble:()=>yi,buildSvg:()=>Bo,center:()=>gi,colorRef:()=>us,createHash:()=>Tu,depthSort:()=>xo,didYouMean:()=>Us,distance:()=>dc,envelope:()=>bi,esc:()=>Kt,extendTheme:()=>sa,faceFrame:()=>Ll,fileLines:()=>xi,formatDiag:()=>uc,formatDiags:()=>wu,iso:()=>Je,keyGlyph:()=>Ed,loadTheme:()=>na,matStr:()=>go,n1:()=>Rt,parse:()=>ku,parseSvg:()=>pc,placeholderFace:()=>Ad,pt:()=>cr,screenFaces:()=>Or,screenGlass:()=>Pd,serialize:()=>ia,sha256Hex:()=>mc,socketGlyph:()=>Td,tag:()=>_e,termLines:()=>yo,textWidth:()=>Rn,themeCss:()=>ra,themeParts:()=>cc,vdoc:()=>$u});var $d={sans700_13:{"0":.6787,"1":.5059,"2":.6372,"3":.6631,"4":.6812,"5":.6577,"6":.6777,"7":.6172,"8":.688,"9":.6777," ":.252,"!":.3506,'"':.563,"#":.6655,$:.6655,"%":1.0298,"&":.7388,"'":.3418,"(":.4229,")":.4229,"*":.4785,"+":.6655,",":.3418,"-":.4785,".":.3418,"/":.3286,":":.3418,";":.3418,"<":.6655,"=":.6655,">":.6655,"?":.5513,"@":.9214,A:.7266,B:.6875,C:.7354,D:.7417,E:.6162,F:.5918,G:.7544,H:.7773,I:.3125,J:.5952,K:.7036,L:.5889,M:.9009,N:.7622,O:.7808,P:.668,Q:.7808,R:.6885,S:.6694,T:.6543,U:.7544,V:.7153,W:1.0034,X:.7236,Y:.7021,Z:.6699,"[":.4229,"\\":.3286,"]":.4229,"^":.6655,_:.5845,"`":.4941,a:.584,b:.6455,c:.5815,d:.6455,e:.5952,f:.407,g:.6396,h:.6265,i:.2813,j:.2813,k:.5957,l:.2891,m:.9263,n:.6216,o:.6138,p:.6411,q:.6416,r:.4338,s:.5513,t:.4114,u:.6216,v:.5771,w:.8413,x:.5747,y:.5913,z:.5605,"{":.4229,"|":.2935,"}":.4229,"~":.6655,"\xB7":.3418,"\u2192":.9375,"\u2190":.9375,"\u2191":.8096,"\u2193":.8096,"\u2019":.3418,"\u2018":.3418,"\u201C":.5474,"\u201D":.5474,"\u2026":.9482,"\u2013":.6216,"\u2014":.9045,"\u2715":.7622,"\xD7":.6655,"\u2248":.6655,"\u2264":.6655,"\u2265":.6655,\u00E9:.5952},sans800_15:{"0":.687,"1":.5122,"2":.6406,"3":.6675,"4":.686,"5":.6626,"6":.6836,"7":.6191,"8":.6968,"9":.6836," ":.2344,"!":.3555,'"':.5835,"#":.6694,$:.6694,"%":1.0566,"&":.7397,"'":.3491,"(":.4287,")":.4287,"*":.4731,"+":.6694,",":.3491,"-":.4731,".":.3491,"/":.3286,":":.3491,";":.3491,"<":.6694,"=":.6694,">":.6694,"?":.5562,"@":.9146,A:.7363,B:.6899,C:.7339,D:.7388,E:.6147,F:.5903,G:.749,H:.7813,I:.3198,J:.6064,K:.7104,L:.5879,M:.9019,N:.7612,O:.7759,P:.6709,Q:.7759,R:.6924,S:.6719,T:.6533,U:.7524,V:.7212,W:1.0073,X:.731,Y:.71,Z:.6646,"[":.4287,"\\":.3286,"]":.4287,"^":.6694,_:.5889,"`":.4844,a:.5864,b:.6479,c:.5811,d:.6479,e:.5952,f:.4139,g:.6416,h:.6309,i:.2847,j:.2847,k:.605,l:.2935,m:.937,n:.626,o:.6138,p:.6436,q:.6445,r:.4406,s:.5557,t:.4198,u:.626,v:.5806,w:.856,x:.5835,y:.5996,z:.5601,"{":.4287,"|":.2974,"}":.4287,"~":.6694,"\xB7":.3491,"\u2192":.9404,"\u2190":.9404,"\u2191":.811,"\u2193":.811,"\u2019":.3491,"\u2018":.3491,"\u201C":.5688,"\u201D":.5688,"\u2026":.9883,"\u2013":.626,"\u2014":.9118,"\u2715":.7622,"\xD7":.6694,"\u2248":.6694,"\u2264":.6694,"\u2265":.6694,\u00E9:.5952},sans800_10_5:{"0":.7114,"1":.5366,"2":.665,"3":.6919,"4":.7104,"5":.687,"6":.708,"7":.6436,"8":.7212,"9":.708," ":.2588,"!":.3799,'"':.6079,"#":.6938,$:.6938,"%":1.0811,"&":.7642,"'":.3735,"(":.4531,")":.4531,"*":.4976,"+":.6938,",":.3735,"-":.4976,".":.3735,"/":.353,":":.3735,";":.3735,"<":.6938,"=":.6938,">":.6938,"?":.5806,"@":.939,A:.7607,B:.7144,C:.7583,D:.7632,E:.6392,F:.6147,G:.7734,H:.8057,I:.3442,J:.6309,K:.7349,L:.6123,M:.9263,N:.7856,O:.8003,P:.6953,Q:.8003,R:.7168,S:.6963,T:.6777,U:.7769,V:.7456,W:1.0317,X:.7554,Y:.7344,Z:.689,"[":.4531,"\\":.353,"]":.4531,"^":.6938,_:.6133,"`":.5088,a:.6108,b:.6724,c:.6055,d:.6724,e:.6196,f:.4383,g:.666,h:.6553,i:.3091,j:.3091,k:.6294,l:.3179,m:.9614,n:.6504,o:.6382,p:.668,q:.6689,r:.465,s:.5801,t:.4442,u:.6504,v:.605,w:.8804,x:.6079,y:.624,z:.5845,"{":.4531,"|":.3218,"}":.4531,"~":.6938,"\xB7":.3735,"\u2192":.9648,"\u2190":.9648,"\u2191":.8354,"\u2193":.8354,"\u2019":.3735,"\u2018":.3735,"\u201C":.5933,"\u201D":.5933,"\u2026":1.0127,"\u2013":.6504,"\u2014":.9204,"\u2715":.7622,"\xD7":.6938,"\u2248":.6938,"\u2264":.6938,"\u2265":.6938,\u00E9:.6196},sans600_12:{"0":.6665,"1":.4956,"2":.6299,"3":.6548,"4":.6724,"5":.6484,"6":.668,"7":.6113,"8":.6753,"9":.668," ":.2656,"!":.3413,'"':.5386,"#":.6577,$:.6577,"%":.999,"&":.7334,"'":.3306,"(":.4131,")":.4131,"*":.48,"+":.6577,",":.3306,"-":.48,".":.3306,"/":.3247,":":.3306,";":.3306,"<":.6577,"=":.6577,">":.6577,"?":.5425,"@":.9238,A:.7129,B:.6812,C:.7329,D:.7402,E:.6133,F:.5889,G:.7559,H:.7695,I:.3013,J:.5801,K:.6924,L:.5859,M:.8955,N:.7593,O:.7813,P:.6606,Q:.7813,R:.6807,S:.6626,T:.6514,U:.7524,V:.7056,W:.9956,X:.7124,Y:.6904,Z:.6709,"[":.4131,"\\":.3247,"]":.4131,"^":.6577,_:.5757,"`":.5,a:.5771,b:.6392,c:.5781,d:.6392,e:.5908,f:.3957,g:.6333,h:.6177,i:.2739,j:.2734,k:.582,l:.2808,m:.9116,n:.6128,o:.6099,p:.6348,q:.6348,r:.4232,s:.543,t:.3991,u:.6128,v:.5693,w:.8228,x:.562,y:.5791,z:.5571,"{":.4131,"|":.2856,"}":.4131,"~":.6577,"\xB7":.3306,"\u2192":.9307,"\u2190":.9307,"\u2191":.8037,"\u2193":.8037,"\u2019":.3306,"\u2018":.3306,"\u201C":.522,"\u201D":.522,"\u2026":.9043,"\u2013":.6128,"\u2014":.8957,"\u2715":.7622,"\xD7":.6577,"\u2248":.6577,"\u2264":.6577,"\u2265":.6577,\u00E9:.5908},sans800_12:{"0":.7026,"1":.5278,"2":.6563,"3":.6831,"4":.7017,"5":.6782,"6":.6992,"7":.6348,"8":.7124,"9":.6992," ":.25,"!":.3711,'"':.5991,"#":.6851,$:.6851,"%":1.0723,"&":.7554,"'":.3647,"(":.4443,")":.4443,"*":.4888,"+":.6851,",":.3647,"-":.4888,".":.3647,"/":.3442,":":.3647,";":.3647,"<":.6851,"=":.6851,">":.6851,"?":.5718,"@":.9302,A:.752,B:.7056,C:.7495,D:.7544,E:.6304,F:.606,G:.7646,H:.7969,I:.3354,J:.6221,K:.7261,L:.6035,M:.9175,N:.7769,O:.7915,P:.6865,Q:.7915,R:.708,S:.6875,T:.6689,U:.7681,V:.7368,W:1.0229,X:.7466,Y:.7256,Z:.6802,"[":.4443,"\\":.3442,"]":.4443,"^":.6851,_:.6045,"`":.5,a:.6021,b:.6636,c:.5967,d:.6636,e:.6108,f:.4295,g:.6572,h:.6465,i:.3003,j:.3003,k:.6206,l:.3091,m:.9526,n:.6416,o:.6294,p:.6592,q:.6602,r:.4562,s:.5713,t:.4354,u:.6416,v:.5962,w:.8716,x:.5991,y:.6152,z:.5757,"{":.4443,"|":.313,"}":.4443,"~":.6851,"\xB7":.3647,"\u2192":.9561,"\u2190":.9561,"\u2191":.8267,"\u2193":.8267,"\u2019":.3647,"\u2018":.3647,"\u201C":.5845,"\u201D":.5845,"\u2026":1.0039,"\u2013":.6416,"\u2014":.9173,"\u2715":.7622,"\xD7":.6851,"\u2248":.6851,"\u2264":.6851,"\u2265":.6851,\u00E9:.6108},sans800_11_5:{"0":.7056,"1":.5308,"2":.6592,"3":.686,"4":.7046,"5":.6812,"6":.7021,"7":.6377,"8":.7153,"9":.7021," ":.2529,"!":.374,'"':.6021,"#":.688,$:.688,"%":1.0752,"&":.7583,"'":.3677,"(":.4473,")":.4473,"*":.4917,"+":.688,",":.3677,"-":.4917,".":.3677,"/":.3472,":":.3677,";":.3677,"<":.688,"=":.688,">":.688,"?":.5747,"@":.9331,A:.7549,B:.7085,C:.7524,D:.7573,E:.6333,F:.6089,G:.7676,H:.7998,I:.3384,J:.625,K:.729,L:.6064,M:.9204,N:.7798,O:.7944,P:.6895,Q:.7944,R:.7109,S:.6904,T:.6719,U:.771,V:.7397,W:1.0259,X:.7495,Y:.7285,Z:.6831,"[":.4473,"\\":.3472,"]":.4473,"^":.688,_:.6074,"`":.5029,a:.605,b:.6665,c:.5996,d:.6665,e:.6138,f:.4325,g:.6602,h:.6494,i:.3032,j:.3032,k:.6235,l:.312,m:.9556,n:.6445,o:.6323,p:.6621,q:.6631,r:.4591,s:.5742,t:.4383,u:.6445,v:.5991,w:.8745,x:.6021,y:.6182,z:.5786,"{":.4473,"|":.3159,"}":.4473,"~":.688,"\xB7":.3677,"\u2192":.959,"\u2190":.959,"\u2191":.8296,"\u2193":.8296,"\u2019":.3677,"\u2018":.3677,"\u201C":.5874,"\u201D":.5874,"\u2026":1.0068,"\u2013":.6445,"\u2014":.9183,"\u2715":.7622,"\xD7":.688,"\u2248":.688,"\u2264":.688,"\u2265":.688,\u00E9:.6138},sans400_13:{"0":.624,"1":.458,"2":.5977,"3":.6211,"4":.6377,"5":.6123,"6":.6309,"7":.582,"8":.6328,"9":.6309," ":.2754,"!":.3052,'"':.4717,"#":.624,$:.624,"%":.9194,"&":.7056,"'":.291,"(":.376,")":.376,"*":.4658,"+":.624,",":.291,"-":.4658,".":.291,"/":.2988,":":.291,";":.291,"<":.624,"=":.624,">":.624,"?":.5068,"@":.9121,A:.668,B:.6514,C:.71,D:.7207,E:.5898,F:.5664,G:.7407,H:.7363,I:.2617,J:.5322,K:.6528,L:.562,M:.8682,N:.7363,O:.7656,P:.6294,Q:.7656,R:.6475,S:.6313,T:.6279,U:.7314,V:.668,W:.9619,X:.6729,Y:.6494,Z:.6558,"[":.376,"\\":.2988,"]":.376,"^":.624,_:.5405,"`":.4941,a:.5459,b:.6084,c:.5537,d:.6084,e:.5654,f:.356,g:.6035,h:.5825,i:.2412,j:.2407,k:.5371,l:.2471,m:.8643,n:.5776,o:.585,p:.6045,q:.6035,r:.3843,s:.5083,t:.3574,u:.5776,v:.5361,w:.7686,x:.5186,y:.5371,z:.5332,"{":.376,"|":.2529,"}":.376,"~":.624,"\xB7":.291,"\u2192":.8999,"\u2190":.8999,"\u2191":.7754,"\u2193":.7754,"\u2019":.291,"\u2018":.291,"\u201C":.4531,"\u201D":.4531,"\u2026":.7988,"\u2013":.5776,"\u2014":.872,"\u2715":.7622,"\xD7":.624,"\u2248":.624,"\u2264":.624,"\u2265":.624,\u00E9:.5654},mono400_11:{"0":.6021,"1":.6021,"2":.6021,"3":.6021,"4":.6021,"5":.6021,"6":.6021,"7":.6021,"8":.6021,"9":.6021," ":.6021,"!":.6021,'"':.6021,"#":.6021,$:.6021,"%":.6021,"&":.6021,"'":.6021,"(":.6021,")":.6021,"*":.6021,"+":.6021,",":.6021,"-":.6021,".":.6021,"/":.6021,":":.6021,";":.6021,"<":.6021,"=":.6021,">":.6021,"?":.6021,"@":.6021,A:.6021,B:.6021,C:.6021,D:.6021,E:.6021,F:.6021,G:.6021,H:.6021,I:.6021,J:.6021,K:.6021,L:.6021,M:.6021,N:.6021,O:.6021,P:.6021,Q:.6021,R:.6021,S:.6021,T:.6021,U:.6021,V:.6021,W:.6021,X:.6021,Y:.6021,Z:.6021,"[":.6021,"\\":.6021,"]":.6021,"^":.6021,_:.6021,"`":.6021,a:.6021,b:.6021,c:.6021,d:.6021,e:.6021,f:.6021,g:.6021,h:.6021,i:.6021,j:.6021,k:.6021,l:.6021,m:.6021,n:.6021,o:.6021,p:.6021,q:.6021,r:.6021,s:.6021,t:.6021,u:.6021,v:.6021,w:.6021,x:.6021,y:.6021,z:.6021,"{":.6021,"|":.6021,"}":.6021,"~":.6021,"\xB7":.6021,"\u2192":.6021,"\u2190":.6021,"\u2191":.6021,"\u2193":.6021,"\u2019":.6021,"\u2018":.6021,"\u201C":.6021,"\u201D":.6021,"\u2026":.6021,"\u2013":.6021,"\u2014":.6021,"\u2715":.6021,"\xD7":.6021,"\u2248":.6021,"\u2264":.6021,"\u2265":.6021,\u00E9:.6021},mono600_11:{"0":.6021,"1":.6021,"2":.6021,"3":.6021,"4":.6021,"5":.6021,"6":.6021,"7":.6021,"8":.6021,"9":.6021," ":.6021,"!":.6021,'"':.6021,"#":.6021,$:.6021,"%":.6021,"&":.6021,"'":.6021,"(":.6021,")":.6021,"*":.6021,"+":.6021,",":.6021,"-":.6021,".":.6021,"/":.6021,":":.6021,";":.6021,"<":.6021,"=":.6021,">":.6021,"?":.6021,"@":.6021,A:.6021,B:.6021,C:.6021,D:.6021,E:.6021,F:.6021,G:.6021,H:.6021,I:.6021,J:.6021,K:.6021,L:.6021,M:.6021,N:.6021,O:.6021,P:.6021,Q:.6021,R:.6021,S:.6021,T:.6021,U:.6021,V:.6021,W:.6021,X:.6021,Y:.6021,Z:.6021,"[":.6021,"\\":.6021,"]":.6021,"^":.6021,_:.6021,"`":.6021,a:.6021,b:.6021,c:.6021,d:.6021,e:.6021,f:.6021,g:.6021,h:.6021,i:.6021,j:.6021,k:.6021,l:.6021,m:.6021,n:.6021,o:.6021,p:.6021,q:.6021,r:.6021,s:.6021,t:.6021,u:.6021,v:.6021,w:.6021,x:.6021,y:.6021,z:.6021,"{":.6021,"|":.6021,"}":.6021,"~":.6021,"\xB7":.6021,"\u2192":.6021,"\u2190":.6021,"\u2191":.6021,"\u2193":.6021,"\u2019":.6021,"\u2018":.6021,"\u201C":.6021,"\u201D":.6021,"\u2026":.6021,"\u2013":.6021,"\u2014":.6021,"\u2715":.6021,"\xD7":.6021,"\u2248":.6021,"\u2264":.6021,"\u2265":.6021,\u00E9:.6021}};var xt=34,Bt=Math.cos(Math.PI/6),Je=(t,e,n=0)=>[(t-e)*Bt*xt,(t+e)*.5*xt-n*xt],Rt=t=>{let e=Math.round(t*10)/10;return Object.is(e,-0)?"0":String(e)},cr=t=>`${Rt(t[0])},${Rt(t[1])}`,Kt=t=>t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""");function _e(t,e={},n){let s="";for(let r in e){let o=e[r];o==null||o===!1||o===""||(s+=` ${r}="${Kt(typeof o=="number"?Rt(o):o)}"`)}return n===void 0?`<${t}${s}/>`:`<${t}${s}>${n}</${t}>`}var It={lbl:{key:"sans700_13",size:13},sub:{key:"mono400_11",size:11},slabname:{key:"sans800_15",size:15,spacing:.12},sm:{key:"sans800_10_5",size:10.5,spacing:.1},floor:{key:"mono600_11",size:11,spacing:.01},say:{key:"sans600_12",size:12},tunname:{key:"sans800_12",size:12,spacing:.14},badge:{key:"sans800_11_5",size:11.5}};function Rn(t,e){let n=$d[e.key],s=e.key.startsWith("mono")?.6:.58,r=0;for(let o of t)r+=n[o]??s;return(r+(e.spacing??0)*[...t].length)*e.size}var ho=(t,e,n)=>[t[0]*e+t[2]*n+t[4],t[1]*e+t[3]*n+t[5]],go=t=>`matrix(${t.map(e=>Math.round(e*1e4)/1e4).join(" ")})`;function Ll(t,e){if(e==="left"){let[r,o]=Je(t.x0,t.y1,t.z1);return{m:[Bt,.5,0,1,r,o],w:(t.x1-t.x0)*xt,h:(t.z1-t.z0)*xt}}if(e==="right"){let[r,o]=Je(t.x1,t.y1,t.z1);return{m:[Bt,-.5,0,1,r,o],w:(t.y1-t.y0)*xt,h:(t.z1-t.z0)*xt}}let[n,s]=Je(t.x0,t.y0,t.z1);return{m:[Bt,.5,-Bt,.5,n,s],w:(t.x1-t.x0)*xt,h:(t.y1-t.y0)*xt}}var bo=class{x0=1/0;y0=1/0;x1=-1/0;y1=-1/0;add(e){e[0]<this.x0&&(this.x0=e[0]),e[0]>this.x1&&(this.x1=e[0]),e[1]<this.y0&&(this.y0=e[1]),e[1]>this.y1&&(this.y1=e[1])}addRect(e,n,s,r){this.add([e,n]),this.add([e+s,n+r])}get empty(){return this.x0===1/0}},Pr=class{bounds=new bo;texts=[];planes=[];planePolys=[];defs=new Map;poly(e,n,s={}){let r=e.map(o=>Je(o[0],o[1],o[2]));return r.forEach(o=>this.bounds.add(o)),_e("polygon",{points:r.map(cr).join(" "),class:n,...s})}line3(e,n,s,r={}){let o=Je(...e),i=Je(...n);return this.bounds.add(o),this.bounds.add(i),_e("line",{x1:o[0],y1:o[1],x2:i[0],y2:i[1],class:s,...r})}blockFaces(e){let{x0:n,y0:s,x1:r,y1:o,z0:i,z1:a}=e;return this.poly([[n,o,i],[r,o,i],[r,o,a],[n,o,a]],"lft")+this.poly([[r,s,i],[r,o,i],[r,o,a],[r,s,a]],"rgt")+this.poly([[n,s,a],[r,s,a],[r,o,a],[n,o,a]],"top")}onFace(e,n,s,r){let o=Ll(e,n);for(let[i,a]of[[0,0],[o.w,0],[0,o.h],[o.w,o.h]])this.bounds.add(ho(o.m,i,a));return _e("g",{class:r,transform:go(o.m)},s(o.w,o.h))}onMatrix(e,n,s,r,o){for(let[i,a]of[[0,0],[n,0],[0,s],[n,s]])this.bounds.add(ho(e,i,a));return _e("g",{class:o,transform:go(e)},r(n,s))}text(e,n,s,r,o,i="middle",a={},l){let c=Rn(s,o),u={x:i==="start"?e:i==="end"?e-c:e-c/2,y:n-o.size*.8,w:c,h:o.size*1.05,text:s,owner:l};return this.bounds.addRect(u.x-2,u.y-2,u.w+4,u.h+4),this.texts.push(u),_e("text",{x:e,y:n,class:r,"text-anchor":i==="start"?void 0:i,...a},Kt(s))}planeText(e,n,s,r,o="start",i={}){let a=Rn(n,r),l=o==="start"?0:o==="end"?-a:-a/2,c=[[l,-r.size*.8],[l+a,-r.size*.8],[l,r.size*.25],[l+a,r.size*.25]].map(([f,p])=>ho(e,f,p));c.forEach(f=>this.bounds.add(f));let d=c.map(f=>f[0]),u=c.map(f=>f[1]);return this.planePolys.push([c[0],c[1],c[3],c[2]]),this.planes.push({x:Math.min(...d),y:Math.min(...u),w:Math.max(...d)-Math.min(...d),h:Math.max(...u)-Math.min(...u)}),_e("text",{transform:go(e),class:s,"text-anchor":o==="start"?void 0:o,...i},Kt(n))}floorText(e,n,s,r,o,i="x",a="start",l={}){let[c,d]=Je(e,n,s),u=i==="x"?[Bt,.5,-Bt,.5,c,d]:[Bt,-.5,Bt,.5,c,d];return this.planeText(u,r,o,It.floor,a,l)}faceText(e,n,s,r,o,i,a="left",l="start",c={}){let[d,u]=Je(e,n,s),f=a==="left"?[Bt,.5,0,1,d,u]:[Bt,-.5,0,1,d,u];return this.planeText(f,r,o,i,l,c)}def(e,n){this.defs.set(e,n)}},gi=t=>[(t.x0+t.x1)/2,(t.y0+t.y1)/2,t.z1];function yo(t,e,n){let s="";for(let r=0;r<n;r++){let o=e.z1-(e.z1-e.z0)*(.28+r*.2),i=(e.x1-e.x0)*(r===n-1?.35:.62-r*.1);s+=t.line3([e.x0+.35,e.y1,o],[e.x0+.35+i,e.y1,o],"det")}return s}function bi(t,e){let s=e.z1,r=[e.x0+.55,e.y0+.55,s],o=[e.x1-.55,e.y0+.55,s],i=[e.x1-.55,e.y1-.55,s],a=[e.x0+.55,e.y1-.55,s],l=[(e.x0+e.x1)/2,(e.y0+e.y1)/2,s];return t.poly([r,o,i,a],"det")+t.line3(r,l,"det")+t.line3(l,o,"det")}function yi(t,e){let s=e.z1,r=t.poly([[e.x0+.55,e.y0+.55,s],[e.x1-.55,e.y0+.55,s],[e.x1-.55,e.y1-.55,s],[e.x0+.55,e.y1-.55,s]],"det");for(let o=1;o<=2;o++){let i=e.y0+.55+(e.y1-e.y0-1.1)*o/3;r+=t.line3([e.x0+.55+.3,i,s],[e.x1-.55-.3-(o===2?.5:0),i,s],"det")}return r}function xi(t,e){let s=e.z1,r=(e.y0+e.y1)/2;return t.line3([e.x0+.3,r-.2,s],[e.x1-.3,r-.2,s],"det")+t.line3([e.x0+.3,r+.2,s],[e.x1-.3-.3,r+.2,s],"det")}function Ed(t,e){let n=(e.x0+e.x1)/2,s=(e.y0+e.y1)/2,r=e.z1+.005,o=Math.min(e.x1-e.x0,e.y1-e.y0)*.16,i=[];for(let a=0;a<20;a++){let l=a/20*Math.PI*2;i.push([n-o*1.4+Math.cos(l)*o,s+Math.sin(l)*o,r])}return t.poly(i,"det")+t.line3([n-o*.4,s,r],[n+o*2.2,s,r],"det")+t.line3([n+o*1.7,s,r],[n+o*1.7,s+o*.8,r],"det")}function Td(t,e){let n=(e.x0+e.x1)/2,s=(e.y0+e.y1)/2,r=e.z1+.005,o=Math.min(e.x1-e.x0,e.y1-e.y0)*.28,i=[];for(let a=0;a<24;a++){let l=a/24*Math.PI*2;i.push([n+Math.cos(l)*o,s+Math.sin(l)*o,r])}return t.poly(i,"det sock-hole")}var dr=(t,e,n,s,r,o=0)=>_e("rect",{class:t,x:e,y:n,width:s,height:r,rx:o||void 0}),Or={terminal(t,e){let n="",s=Math.max(2,Math.floor((e-12)/9));for(let r=0;r<s;r++){let o=10+r*9,i=(t-18)*[.7,.45,.6,.3,.55][r%5];n+=_e("line",{class:"ln",x1:8,y1:o,x2:8+i,y2:o})}return n},chat(t,e){return[[6,.62,"w"],[.3,.58,"m"],[6,.46,"w"],[.42,.5,"m"]].map((s,r)=>{let o=(t-14)*s[1],i=s[0]===6?7:t-7-o;return dr(s[2],i,8+r*(e-18)/4,o,(e-18)/4-4,3)}).join("")},desktop(t,e){return dr("wall",5,5,t-10,e-10,2)+dr("bar",5,5,t-10,6)+dr("win",t*.5,13,t*.38,e*.42,2)},tiles(t,e){let i=(t-12-5)/3,a=(e-12-2.5*1)/2,l="";for(let c=0;c<2;c++)for(let d=0;d<3;d++){let u=6+d*(i+2.5),f=6+c*(a+2.5);l+=dr("t",u,f,i,a,1.5),[.3,.52,.74].forEach((p,g)=>{l+=_e("line",{class:"ln",x1:u+2.5,y1:f+a*p,x2:u+2.5+(i-5)*[.8,.5,.65][(g+c+d)%3],y2:f+a*p})})}return l}};function Ad(t,e){let n=t/2,s=e/2,r=Math.min(t,e)*.22;return dr("unk",t*.2,e*.2,t*.6,e*.6,2)+_e("path",{class:"unk-q",d:`M${Rt(n-r*.5)},${Rt(s-r*.45)}a${Rt(r*.5)},${Rt(r*.5)} 0 1 1 ${Rt(r*.5)},${Rt(r*.55)}v${Rt(r*.3)}`})+_e("circle",{class:"unk-dot",cx:Rt(n),cy:Rt(s+r*.75),r:Rt(Math.max(.8,r*.1))})}function Pd(t,e){return dr("glass",3,3,t-6,e-6,3)}function op(t){let e=[Je(t.x0,t.y0,t.z1),Je(t.x1,t.y0,t.z0),Je(t.x0,t.y1,t.z0),Je(t.x1,t.y1,t.z0),Je(t.x1,t.y1,t.z1),Je(t.x0,t.y0,t.z0)],n=e.map(r=>r[0]),s=e.map(r=>r[1]);return[Math.min(...n),Math.min(...s),Math.max(...n),Math.max(...s)]}function ip(t,e){let s=t.x1<=e.x0+1e-6,r=e.x1<=t.x0+1e-6,o=t.y1<=e.y0+1e-6,i=e.y1<=t.y0+1e-6,a=t.z1<=e.z0+1e-6,l=e.z1<=t.z0+1e-6,c=s||o||a,d=r||i||l;return c&&!d?-1:d&&!c?1:0}function xo(t){let e=t.length,n=t.map(c=>op(c.box)),s=c=>c.box.x0+c.box.y0+c.box.z0*.01,r=t.map(()=>[]),o=new Array(e).fill(0);for(let c=0;c<e;c++)for(let d=c+1;d<e;d++){let u=n[c],f=n[d];if(u[2]<=f[0]||f[2]<=u[0]||u[3]<=f[1]||f[3]<=u[1])continue;let p=ip(t[c].box,t[d].box);p<0?(r[c].push(d),o[d]++):p>0&&(r[d].push(c),o[c]++)}let i=[],a=t.map((c,d)=>d).filter(c=>!o[c]),l=new Array(e).fill(!1);for(;i.length<e;){if(!a.length){let d=t.map((u,f)=>f).filter(u=>!l[u]).sort((u,f)=>s(t[u])-s(t[f]));a.push(d[0]),o[d[0]]=0}a.sort((d,u)=>s(t[d])-s(t[u])||d-u);let c=a.shift();if(!l[c]){l[c]=!0,i.push(t[c]);for(let d of r[c])!l[d]&&--o[d]===0&&a.push(d)}}return i}var wi=Symbol.for("yaml.alias"),vi=Symbol.for("yaml.document"),Gn=Symbol.for("yaml.map"),Nl=Symbol.for("yaml.pair"),Pn=Symbol.for("yaml.scalar"),Ss=Symbol.for("yaml.seq"),gn=Symbol.for("yaml.node.type"),Hn=t=>!!t&&typeof t=="object"&&t[gn]===wi,Yn=t=>!!t&&typeof t=="object"&&t[gn]===vi,ct=t=>!!t&&typeof t=="object"&&t[gn]===Gn,tt=t=>!!t&&typeof t=="object"&&t[gn]===Nl,Ge=t=>!!t&&typeof t=="object"&&t[gn]===Pn,Lt=t=>!!t&&typeof t=="object"&&t[gn]===Ss;function vt(t){if(t&&typeof t=="object")switch(t[gn]){case Gn:case Ss:return!0}return!1}function ht(t){if(t&&typeof t=="object")switch(t[gn]){case wi:case Gn:case Pn:case Ss:return!0}return!1}var ki=t=>(Ge(t)||vt(t))&&!!t.anchor;var Mn=Symbol("break visit"),Od=Symbol("skip children"),os=Symbol("remove node");function is(t,e){let n=Cd(e);Yn(t)?Cr(null,t.contents,n,Object.freeze([t]))===os&&(t.contents=null):Cr(null,t,n,Object.freeze([]))}is.BREAK=Mn;is.SKIP=Od;is.REMOVE=os;function Cr(t,e,n,s){let r=Ld(t,e,n,s);if(ht(r)||tt(r))return Nd(t,s,r),Cr(t,r,n,s);if(typeof r!="symbol"){if(vt(e)){s=Object.freeze(s.concat(e));for(let o=0;o<e.items.length;++o){let i=Cr(o,e.items[o],n,s);if(typeof i=="number")o=i-1;else{if(i===Mn)return Mn;i===os&&(e.items.splice(o,1),o-=1)}}}else if(tt(e)){s=Object.freeze(s.concat(e));let o=Cr("key",e.key,n,s);if(o===Mn)return Mn;o===os&&(e.key=null);let i=Cr("value",e.value,n,s);if(i===Mn)return Mn;i===os&&(e.value=null)}}return r}async function Si(t,e){let n=Cd(e);Yn(t)?await Lr(null,t.contents,n,Object.freeze([t]))===os&&(t.contents=null):await Lr(null,t,n,Object.freeze([]))}Si.BREAK=Mn;Si.SKIP=Od;Si.REMOVE=os;async function Lr(t,e,n,s){let r=await Ld(t,e,n,s);if(ht(r)||tt(r))return Nd(t,s,r),Lr(t,r,n,s);if(typeof r!="symbol"){if(vt(e)){s=Object.freeze(s.concat(e));for(let o=0;o<e.items.length;++o){let i=await Lr(o,e.items[o],n,s);if(typeof i=="number")o=i-1;else{if(i===Mn)return Mn;i===os&&(e.items.splice(o,1),o-=1)}}}else if(tt(e)){s=Object.freeze(s.concat(e));let o=await Lr("key",e.key,n,s);if(o===Mn)return Mn;o===os&&(e.key=null);let i=await Lr("value",e.value,n,s);if(i===Mn)return Mn;i===os&&(e.value=null)}}return r}function Cd(t){return typeof t=="object"&&(t.Collection||t.Node||t.Value)?Object.assign({Alias:t.Node,Map:t.Node,Scalar:t.Node,Seq:t.Node},t.Value&&{Map:t.Value,Scalar:t.Value,Seq:t.Value},t.Collection&&{Map:t.Collection,Seq:t.Collection},t):t}function Ld(t,e,n,s){if(typeof n=="function")return n(t,e,s);if(ct(e))return n.Map?.(t,e,s);if(Lt(e))return n.Seq?.(t,e,s);if(tt(e))return n.Pair?.(t,e,s);if(Ge(e))return n.Scalar?.(t,e,s);if(Hn(e))return n.Alias?.(t,e,s)}function Nd(t,e,n){let s=e[e.length-1];if(vt(s))s.items[t]=n;else if(tt(s))t==="key"?s.key=n:s.value=n;else if(Yn(s))s.contents=n;else{let r=Hn(s)?"alias":"scalar";throw new Error(`Cannot replace node with ${r} parent`)}}var ap={"!":"%21",",":"%2C","[":"%5B","]":"%5D","{":"%7B","}":"%7D"},lp=t=>t.replace(/[!,[\]{}]/g,e=>ap[e]),as=class t{constructor(e,n){this.docStart=null,this.docEnd=!1,this.yaml=Object.assign({},t.defaultYaml,e),this.tags=Object.assign({},t.defaultTags,n)}clone(){let e=new t(this.yaml,this.tags);return e.docStart=this.docStart,e}atDocument(){let e=new t(this.yaml,this.tags);switch(this.yaml.version){case"1.1":this.atNextDocument=!0;break;case"1.2":this.atNextDocument=!1,this.yaml={explicit:t.defaultYaml.explicit,version:"1.2"},this.tags=Object.assign({},t.defaultTags);break}return e}add(e,n){this.atNextDocument&&(this.yaml={explicit:t.defaultYaml.explicit,version:"1.1"},this.tags=Object.assign({},t.defaultTags),this.atNextDocument=!1);let s=e.trim().split(/[ \t]+/),r=s.shift();switch(r){case"%TAG":{if(s.length!==2&&(n(0,"%TAG directive should contain exactly two parts"),s.length<2))return!1;let[o,i]=s;return this.tags[o]=i,!0}case"%YAML":{if(this.yaml.explicit=!0,s.length!==1)return n(0,"%YAML directive should contain exactly one part"),!1;let[o]=s;if(o==="1.1"||o==="1.2")return this.yaml.version=o,!0;{let i=/^\d+\.\d+$/.test(o);return n(6,`Unsupported YAML version ${o}`,i),!1}}default:return n(0,`Unknown directive ${r}`,!0),!1}}tagName(e,n){if(e==="!")return"!";if(e[0]!=="!")return n(`Not a valid tag: ${e}`),null;if(e[1]==="<"){let i=e.slice(2,-1);return i==="!"||i==="!!"?(n(`Verbatim tags aren't resolved, so ${e} is invalid.`),null):(e[e.length-1]!==">"&&n("Verbatim tags must end with a >"),i)}let[,s,r]=e.match(/^(.*!)([^!]*)$/s);r||n(`The ${e} tag has no suffix`);let o=this.tags[s];if(o)try{return o+decodeURIComponent(r)}catch(i){return n(String(i)),null}return s==="!"?e:(n(`Could not resolve tag: ${e}`),null)}tagString(e){for(let[n,s]of Object.entries(this.tags))if(e.startsWith(s))return n+lp(e.substring(s.length));return e[0]==="!"?e:`!<${e}>`}toString(e){let n=this.yaml.explicit?[`%YAML ${this.yaml.version||"1.2"}`]:[],s=Object.entries(this.tags),r;if(e&&s.length>0&&ht(e.contents)){let o={};is(e.contents,(i,a)=>{ht(a)&&a.tag&&(o[a.tag]=!0)}),r=Object.keys(o)}else r=[];for(let[o,i]of s)o==="!!"&&i==="tag:yaml.org,2002:"||(!e||r.some(a=>a.startsWith(i)))&&n.push(`%TAG ${o} ${i}`);return n.join(`
|
|
2
|
+
`)}};as.defaultYaml={explicit:!1,version:"1.2"};as.defaultTags={"!!":"tag:yaml.org,2002:"};function Mi(t){if(/[\x00-\x19\s,[\]{}]/.test(t)){let n=`Anchor must not contain whitespace or control characters: ${JSON.stringify(t)}`;throw new Error(n)}return!0}function Rl(t){let e=new Set;return is(t,{Value(n,s){s.anchor&&e.add(s.anchor)}}),e}function Il(t,e){for(let n=1;;++n){let s=`${t}${n}`;if(!e.has(s))return s}}function Rd(t,e){let n=[],s=new Map,r=null;return{onAnchor:o=>{n.push(o),r??(r=Rl(t));let i=Il(e,r);return r.add(i),i},setAnchors:()=>{for(let o of n){let i=s.get(o);if(typeof i=="object"&&i.anchor&&(Ge(i.node)||vt(i.node)))i.node.anchor=i.anchor;else{let a=new Error("Failed to resolve repeated object (this should not happen)");throw a.source=o,a}}},sourceObjects:s}}function zs(t,e,n,s){if(s&&typeof s=="object")if(Array.isArray(s))for(let r=0,o=s.length;r<o;++r){let i=s[r],a=zs(t,s,String(r),i);a===void 0?delete s[r]:a!==i&&(s[r]=a)}else if(s instanceof Map)for(let r of Array.from(s.keys())){let o=s.get(r),i=zs(t,s,r,o);i===void 0?s.delete(r):i!==o&&s.set(r,i)}else if(s instanceof Set)for(let r of Array.from(s)){let o=zs(t,s,r,r);o===void 0?s.delete(r):o!==r&&(s.delete(r),s.add(o))}else for(let[r,o]of Object.entries(s)){let i=zs(t,s,r,o);i===void 0?delete s[r]:i!==o&&(s[r]=i)}return t.call(e,n,s)}function en(t,e,n){if(Array.isArray(t))return t.map((s,r)=>en(s,String(r),n));if(t&&typeof t.toJSON=="function"){if(!n||!ki(t))return t.toJSON(e,n);let s={aliasCount:0,count:1,res:void 0};n.anchors.set(t,s),n.onCreate=o=>{s.res=o,delete n.onCreate};let r=t.toJSON(e,n);return n.onCreate&&n.onCreate(r),r}return typeof t=="bigint"&&!n?.keep?Number(t):t}var Vs=class{constructor(e){Object.defineProperty(this,gn,{value:e})}clone(){let e=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return this.range&&(e.range=this.range.slice()),e}toJS(e,{mapAsMap:n,maxAliasCount:s,onAnchor:r,reviver:o}={}){if(!Yn(e))throw new TypeError("A document argument is required");let i={anchors:new Map,doc:e,keep:!0,mapAsMap:n===!0,mapKeyWarned:!1,maxAliasCount:typeof s=="number"?s:100},a=en(this,"",i);if(typeof r=="function")for(let{count:l,res:c}of i.anchors.values())r(c,l);return typeof o=="function"?zs(o,{"":a},"",a):a}};var Ms=class extends Vs{constructor(e){super(wi),this.source=e,Object.defineProperty(this,"tag",{set(){throw new Error("Alias nodes cannot have tags")}})}resolve(e,n){if(n?.maxAliasCount===0)throw new ReferenceError("Alias resolution is disabled");let s;n?.aliasResolveCache?s=n.aliasResolveCache:(s=[],is(e,{Node:(o,i)=>{(Hn(i)||ki(i))&&s.push(i)}}),n&&(n.aliasResolveCache=s));let r;for(let o of s){if(o===this)break;o.anchor===this.source&&(r=o)}if(r&&n){let{anchors:o,doc:i,maxAliasCount:a}=n,l=o.get(r);if(l||(en(r,null,n),l=o.get(r)),l?.res===void 0){let c="This should not happen: Alias anchor was not resolved?";throw new ReferenceError(c)}if(a>=0&&(l.count+=1,l.aliasCount===0&&(l.aliasCount=$i(i,r,o)),l.count*l.aliasCount>a)){let c="Excessive alias count indicates a resource exhaustion attack";throw new ReferenceError(c)}}return r}toJSON(e,n){if(!n)return{source:this.source};let s=this.resolve(n.doc,n);if(!s){let r=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw new ReferenceError(r)}return n.anchors.get(s).res}toString(e,n,s){let r=`*${this.source}`;if(e){if(Mi(this.source),e.options.verifyAliasOrder&&!e.anchors.has(this.source)){let o=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw new Error(o)}if(e.implicitKey)return`${r} `}return r}};function $i(t,e,n){if(Hn(e)){let s=e.resolve(t),r=n&&s&&n.get(s);return r?r.count*r.aliasCount:0}else if(vt(e)){let s=0;for(let r of e.items){let o=$i(t,r,n);o>s&&(s=o)}return s}else if(tt(e)){let s=$i(t,e.key,n),r=$i(t,e.value,n);return Math.max(s,r)}return 1}var Ei=t=>!t||typeof t!="function"&&typeof t!="object",Be=class extends Vs{constructor(e){super(Pn),this.value=e}toJSON(e,n){return n?.keep?this.value:en(this.value,e,n)}toString(){return String(this.value)}};Be.BLOCK_FOLDED="BLOCK_FOLDED";Be.BLOCK_LITERAL="BLOCK_LITERAL";Be.PLAIN="PLAIN";Be.QUOTE_DOUBLE="QUOTE_DOUBLE";Be.QUOTE_SINGLE="QUOTE_SINGLE";var cp="tag:yaml.org,2002:";function dp(t,e,n){if(e){let s=n.filter(o=>o.tag===e),r=s.find(o=>!o.format)??s[0];if(!r)throw new Error(`Tag ${e} not found`);return r}return n.find(s=>s.identify?.(t)&&!s.format)}function $s(t,e,n){if(Yn(t)&&(t=t.contents),ht(t))return t;if(tt(t)){let u=n.schema[Gn].createNode?.(n.schema,null,n);return u.items.push(t),u}(t instanceof String||t instanceof Number||t instanceof Boolean||typeof BigInt<"u"&&t instanceof BigInt)&&(t=t.valueOf());let{aliasDuplicateObjects:s,onAnchor:r,onTagObj:o,schema:i,sourceObjects:a}=n,l;if(s&&t&&typeof t=="object"){if(l=a.get(t),l)return l.anchor??(l.anchor=r(t)),new Ms(l.anchor);l={anchor:null,node:null},a.set(t,l)}e?.startsWith("!!")&&(e=cp+e.slice(2));let c=dp(t,e,i.tags);if(!c){if(t&&typeof t.toJSON=="function"&&(t=t.toJSON()),!t||typeof t!="object"){let u=new Be(t);return l&&(l.node=u),u}c=t instanceof Map?i[Gn]:Symbol.iterator in Object(t)?i[Ss]:i[Gn]}o&&(o(c),delete n.onTagObj);let d=c?.createNode?c.createNode(n.schema,t,n):typeof c?.nodeClass?.from=="function"?c.nodeClass.from(n.schema,t,n):new Be(t);return e?d.tag=e:c.default||(d.tag=c.tag),l&&(l.node=d),d}function wo(t,e,n){let s=n;for(let r=e.length-1;r>=0;--r){let o=e[r];if(typeof o=="number"&&Number.isInteger(o)&&o>=0){let i=[];i[o]=s,s=i}else s=new Map([[o,s]])}return $s(s,void 0,{aliasDuplicateObjects:!1,keepUndefined:!1,onAnchor:()=>{throw new Error("This should not happen, please report a bug.")},schema:t,sourceObjects:new Map})}var Rr=t=>t==null||typeof t=="object"&&!!t[Symbol.iterator]().next().done,Nr=class extends Vs{constructor(e,n){super(e),Object.defineProperty(this,"schema",{value:n,configurable:!0,enumerable:!1,writable:!0})}clone(e){let n=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return e&&(n.schema=e),n.items=n.items.map(s=>ht(s)||tt(s)?s.clone(e):s),this.range&&(n.range=this.range.slice()),n}addIn(e,n){if(Rr(e))this.add(n);else{let[s,...r]=e,o=this.get(s,!0);if(vt(o))o.addIn(r,n);else if(o===void 0&&this.schema)this.set(s,wo(this.schema,r,n));else throw new Error(`Expected YAML collection at ${s}. Remaining path: ${r}`)}}deleteIn(e){let[n,...s]=e;if(s.length===0)return this.delete(n);let r=this.get(n,!0);if(vt(r))return r.deleteIn(s);throw new Error(`Expected YAML collection at ${n}. Remaining path: ${s}`)}getIn(e,n){let[s,...r]=e,o=this.get(s,!0);return r.length===0?!n&&Ge(o)?o.value:o:vt(o)?o.getIn(r,n):void 0}hasAllNullValues(e){return this.items.every(n=>{if(!tt(n))return!1;let s=n.value;return s==null||e&&Ge(s)&&s.value==null&&!s.commentBefore&&!s.comment&&!s.tag})}hasIn(e){let[n,...s]=e;if(s.length===0)return this.has(n);let r=this.get(n,!0);return vt(r)?r.hasIn(s):!1}setIn(e,n){let[s,...r]=e;if(r.length===0)this.set(s,n);else{let o=this.get(s,!0);if(vt(o))o.setIn(r,n);else if(o===void 0&&this.schema)this.set(s,wo(this.schema,r,n));else throw new Error(`Expected YAML collection at ${s}. Remaining path: ${r}`)}}};var Id=t=>t.replace(/^(?!$)(?: $)?/gm,"#");function In(t,e){return/^\n+$/.test(t)?t.substring(1):e?t.replace(/^(?! *$)/gm,e):t}var ls=(t,e,n)=>t.endsWith(`
|
|
3
|
+
`)?In(n,e):n.includes(`
|
|
4
4
|
`)?`
|
|
5
|
-
`+
|
|
6
|
-
`)n===
|
|
7
|
-
`&&p!==" "){let
|
|
8
|
-
`&&
|
|
9
|
-
${e}${t.slice(0,T)}`:(n===
|
|
10
|
-
${e}${t.slice(
|
|
11
|
-
`);s=e,r=e+1,o=t[r]}return s}var
|
|
12
|
-
`){if(o-i>s)return!0;if(i=o+1,r-i<=s)return!1}return!0}function
|
|
5
|
+
`+In(n,e):(t.endsWith(" ")?"":" ")+n;var Dl="flow",Ti="block",vo="quoted";function ko(t,e,n="flow",{indentAtStart:s,lineWidth:r=80,minContentWidth:o=20,onFold:i,onOverflow:a}={}){if(!r||r<0)return t;r<o&&(o=0);let l=Math.max(1+o,1+r-e.length);if(t.length<=l)return t;let c=[],d={},u=r-e.length;typeof s=="number"&&(s>r-Math.max(2,o)?c.push(0):u=r-s);let f,p,g=!1,h=-1,b=-1,v=-1;n===Ti&&(h=Dd(t,h,e.length),h!==-1&&(u=h+l));for(let M;M=t[h+=1];){if(n===vo&&M==="\\"){switch(b=h,t[h+1]){case"x":h+=3;break;case"u":h+=5;break;case"U":h+=9;break;default:h+=1}v=h}if(M===`
|
|
6
|
+
`)n===Ti&&(h=Dd(t,h,e.length)),u=h+e.length+l,f=void 0;else{if(M===" "&&p&&p!==" "&&p!==`
|
|
7
|
+
`&&p!==" "){let y=t[h+1];y&&y!==" "&&y!==`
|
|
8
|
+
`&&y!==" "&&(f=h)}if(h>=u)if(f)c.push(f),u=f+l,f=void 0;else if(n===vo){for(;p===" "||p===" ";)p=M,M=t[h+=1],g=!0;let y=h>v+1?h-2:b-1;if(d[y])return t;c.push(y),d[y]=!0,u=y+l,f=void 0}else g=!0}p=M}if(g&&a&&a(),c.length===0)return t;i&&i();let w=t.slice(0,c[0]);for(let M=0;M<c.length;++M){let y=c[M],T=c[M+1]||t.length;y===0?w=`
|
|
9
|
+
${e}${t.slice(0,T)}`:(n===vo&&d[y]&&(w+=`${t[y]}\\`),w+=`
|
|
10
|
+
${e}${t.slice(y+1,T)}`)}return w}function Dd(t,e,n){let s=e,r=e+1,o=t[r];for(;o===" "||o===" ";)if(e<r+n)o=t[++e];else{do o=t[++e];while(o&&o!==`
|
|
11
|
+
`);s=e,r=e+1,o=t[r]}return s}var Pi=(t,e)=>({indentAtStart:e?t.indent.length:t.indentAtStart,lineWidth:t.options.lineWidth,minContentWidth:t.options.minContentWidth}),Oi=t=>/^(%|---|\.\.\.)/m.test(t);function up(t,e,n){if(!e||e<0)return!1;let s=e-n,r=t.length;if(r<=s)return!1;for(let o=0,i=0;o<r;++o)if(t[o]===`
|
|
12
|
+
`){if(o-i>s)return!0;if(i=o+1,r-i<=s)return!1}return!0}function So(t,e){let n=JSON.stringify(t);if(e.options.doubleQuotedAsJSON)return n;let{implicitKey:s}=e,r=e.options.doubleQuotedMinMultiLineLength,o=e.indent||(Oi(t)?" ":""),i="",a=0;for(let l=0,c=n[l];c;c=n[++l])if(c===" "&&n[l+1]==="\\"&&n[l+2]==="n"&&(i+=n.slice(a,l)+"\\ ",l+=1,a=l,c="\\"),c==="\\")switch(n[l+1]){case"u":{i+=n.slice(a,l);let d=n.substr(l+2,4);switch(d){case"0000":i+="\\0";break;case"0007":i+="\\a";break;case"000b":i+="\\v";break;case"001b":i+="\\e";break;case"0085":i+="\\N";break;case"00a0":i+="\\_";break;case"2028":i+="\\L";break;case"2029":i+="\\P";break;default:d.substr(0,2)==="00"?i+="\\x"+d.substr(2):i+=n.substr(l,6)}l+=5,a=l+1}break;case"n":if(s||n[l+2]==='"'||n.length<r)l+=1;else{for(i+=n.slice(a,l)+`
|
|
13
13
|
|
|
14
14
|
`;n[l+2]==="\\"&&n[l+3]==="n"&&n[l+4]!=='"';)i+=`
|
|
15
|
-
`,l+=2;i+=o,n[l+2]===" "&&(i+="\\"),l+=1,a=l+1}break;default:l+=1}return i=a?i+n.slice(a):n,s?i:
|
|
16
|
-
`)||/[ \t]\n|\n[ \t]/.test(t))return
|
|
17
|
-
${n}`)+"'";return e.implicitKey?s:
|
|
15
|
+
`,l+=2;i+=o,n[l+2]===" "&&(i+="\\"),l+=1,a=l+1}break;default:l+=1}return i=a?i+n.slice(a):n,s?i:ko(i,o,vo,Pi(e,!1))}function Fl(t,e){if(e.options.singleQuote===!1||e.implicitKey&&t.includes(`
|
|
16
|
+
`)||/[ \t]\n|\n[ \t]/.test(t))return So(t,e);let n=e.indent||(Oi(t)?" ":""),s="'"+t.replace(/'/g,"''").replace(/\n+/g,`$&
|
|
17
|
+
${n}`)+"'";return e.implicitKey?s:ko(s,n,Dl,Pi(e,!1))}function Ir(t,e){let{singleQuote:n}=e.options,s;if(n===!1)s=So;else{let r=t.includes('"'),o=t.includes("'");r&&!o?s=Fl:o&&!r?s=So:s=n?Fl:So}return s(t,e)}var jl;try{jl=new RegExp(`(^|(?<!
|
|
18
18
|
))
|
|
19
19
|
+(?!
|
|
20
|
-
|$)`,"g")}catch{
|
|
20
|
+
|$)`,"g")}catch{jl=/\n+(?!\n|$)/g}function Ai({comment:t,type:e,value:n},s,r,o){let{blockQuote:i,commentString:a,lineWidth:l}=s.options;if(!i||/\n[\t ]+$/.test(n))return Ir(n,s);let c=s.indent||(s.forceBlockIndent||Oi(n)?" ":""),d=i==="literal"?!0:i==="folded"||e===Be.BLOCK_FOLDED?!1:e===Be.BLOCK_LITERAL?!0:!up(n,l,c.length);if(!n)return d?`|
|
|
21
21
|
`:`>
|
|
22
22
|
`;let u,f;for(f=n.length;f>0;--f){let T=n[f-1];if(T!==`
|
|
23
23
|
`&&T!==" "&&T!==" ")break}let p=n.substring(f),g=p.indexOf(`
|
|
24
24
|
`);g===-1?u="-":n===p||g!==p.length-1?(u="+",o&&o()):u="",p&&(n=n.slice(0,-p.length),p[p.length-1]===`
|
|
25
|
-
`&&(p=p.slice(0,-1)),p=p.replace(
|
|
26
|
-
`)
|
|
27
|
-
$&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,"$1$2").replace(/\n+/g,`$&${c}`),
|
|
28
|
-
${c}${
|
|
29
|
-
${c}${
|
|
30
|
-
`)||d&&/[[\]{},]/.test(o))return
|
|
31
|
-
`)?
|
|
32
|
-
`))return
|
|
33
|
-
${l}`);if(i){let f=h=>h.default&&h.tag!=="tag:yaml.org,2002:str"&&h.test?.test(u),{compat:p,tags:g}=e.doc.schema;if(g.some(f)||p?.some(f))return
|
|
34
|
-
${e.indent}${a}`:a}function
|
|
35
|
-
${a}:`):(b=`${b}:`,f&&(b+=
|
|
36
|
-
`:"",
|
|
37
|
-
${
|
|
38
|
-
`&&M&&(
|
|
25
|
+
`&&(p=p.slice(0,-1)),p=p.replace(jl,`$&${c}`));let h=!1,b,v=-1;for(b=0;b<n.length;++b){let T=n[b];if(T===" ")h=!0;else if(T===`
|
|
26
|
+
`)v=b;else break}let w=n.substring(0,v<b?v+1:b);w&&(n=n.substring(w.length),w=w.replace(/\n+/g,`$&${c}`));let y=(h?c?"2":"1":"")+u;if(t&&(y+=" "+a(t.replace(/ ?[\r\n]+/g," ")),r&&r()),!d){let T=n.replace(/\n+/g,`
|
|
27
|
+
$&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,"$1$2").replace(/\n+/g,`$&${c}`),S=!1,P=Pi(s,!0);i!=="folded"&&e!==Be.BLOCK_FOLDED&&(P.onOverflow=()=>{S=!0});let I=ko(`${w}${T}${p}`,c,Ti,P);if(!S)return`>${y}
|
|
28
|
+
${c}${I}`}return n=n.replace(/\n+/g,`$&${c}`),`|${y}
|
|
29
|
+
${c}${w}${n}${p}`}function fp(t,e,n,s){let{type:r,value:o}=t,{actualString:i,implicitKey:a,indent:l,indentStep:c,inFlow:d}=e;if(a&&o.includes(`
|
|
30
|
+
`)||d&&/[[\]{},]/.test(o))return Ir(o,e);if(/^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(o))return a||d||!o.includes(`
|
|
31
|
+
`)?Ir(o,e):Ai(t,e,n,s);if(!a&&!d&&r!==Be.PLAIN&&o.includes(`
|
|
32
|
+
`))return Ai(t,e,n,s);if(Oi(o)){if(l==="")return e.forceBlockIndent=!0,Ai(t,e,n,s);if(a&&l===c)return Ir(o,e)}let u=o.replace(/\n+/g,`$&
|
|
33
|
+
${l}`);if(i){let f=h=>h.default&&h.tag!=="tag:yaml.org,2002:str"&&h.test?.test(u),{compat:p,tags:g}=e.doc.schema;if(g.some(f)||p?.some(f))return Ir(o,e)}return a?u:ko(u,l,Dl,Pi(e,!1))}function ur(t,e,n,s){let{implicitKey:r,inFlow:o}=e,i=typeof t.value=="string"?t:Object.assign({},t,{value:String(t.value)}),{type:a}=t;a!==Be.QUOTE_DOUBLE&&/[\x00-\x08\x0b-\x1f\x7f-\x9f\u{D800}-\u{DFFF}]/u.test(i.value)&&(a=Be.QUOTE_DOUBLE);let l=d=>{switch(d){case Be.BLOCK_FOLDED:case Be.BLOCK_LITERAL:return r||o?Ir(i.value,e):Ai(i,e,n,s);case Be.QUOTE_DOUBLE:return So(i.value,e);case Be.QUOTE_SINGLE:return Fl(i.value,e);case Be.PLAIN:return fp(i,e,n,s);default:return null}},c=l(a);if(c===null){let{defaultKeyType:d,defaultStringType:u}=e.options,f=r&&d||u;if(c=l(f),c===null)throw new Error(`Unsupported default string type ${f}`)}return c}function Ci(t,e){let n=Object.assign({blockQuote:!0,commentString:Id,defaultKeyType:null,defaultStringType:"PLAIN",directives:null,doubleQuotedAsJSON:!1,doubleQuotedMinMultiLineLength:40,falseStr:"false",flowCollectionPadding:!0,indentSeq:!0,lineWidth:80,minContentWidth:20,nullStr:"null",simpleKeys:!1,singleQuote:null,trailingComma:!1,trueStr:"true",verifyAliasOrder:!0},t.schema.toStringOptions,e),s;switch(n.collectionStyle){case"block":s=!1;break;case"flow":s=!0;break;default:s=null}return{anchors:new Set,doc:t,flowCollectionPadding:n.flowCollectionPadding?" ":"",indent:"",indentStep:typeof n.indent=="number"?" ".repeat(n.indent):" ",inFlow:s,options:n}}function pp(t,e){if(e.tag){let r=t.filter(o=>o.tag===e.tag);if(r.length>0)return r.find(o=>o.format===e.format)??r[0]}let n,s;if(Ge(e)){s=e.value;let r=t.filter(o=>o.identify?.(s));if(r.length>1){let o=r.filter(i=>i.test);o.length>0&&(r=o)}n=r.find(o=>o.format===e.format)??r.find(o=>!o.format)}else s=e,n=t.find(r=>r.nodeClass&&s instanceof r.nodeClass);if(!n){let r=s?.constructor?.name??(s===null?"null":typeof s);throw new Error(`Tag not resolved for ${r} value`)}return n}function mp(t,e,{anchors:n,doc:s}){if(!s.directives)return"";let r=[],o=(Ge(t)||vt(t))&&t.anchor;o&&Mi(o)&&(n.add(o),r.push(`&${o}`));let i=t.tag??(e.default?null:e.tag);return i&&r.push(s.directives.tagString(i)),r.join(" ")}function Es(t,e,n,s){if(tt(t))return t.toString(e,n,s);if(Hn(t)){if(e.doc.directives)return t.toString(e);if(e.resolvedAliases?.has(t))throw new TypeError("Cannot stringify circular structure without alias nodes");e.resolvedAliases?e.resolvedAliases.add(t):e.resolvedAliases=new Set([t]),t=t.resolve(e.doc)}let r,o=ht(t)?t:e.doc.createNode(t,{onTagObj:l=>r=l});r??(r=pp(e.doc.schema.tags,o));let i=mp(o,r,e);i.length>0&&(e.indentAtStart=(e.indentAtStart??0)+i.length+1);let a=typeof r.stringify=="function"?r.stringify(o,e,n,s):Ge(o)?ur(o,e,n,s):o.toString(e,n,s);return i?Ge(o)||a[0]==="{"||a[0]==="["?`${i} ${a}`:`${i}
|
|
34
|
+
${e.indent}${a}`:a}function Fd({key:t,value:e},n,s,r){let{allNullValues:o,doc:i,indent:a,indentStep:l,options:{commentString:c,indentSeq:d,simpleKeys:u}}=n,f=ht(t)&&t.comment||null;if(u){if(f)throw new Error("With simple keys, key nodes cannot have comments");if(vt(t)||!ht(t)&&typeof t=="object"){let P="With simple keys, collection cannot be used as a key value";throw new Error(P)}}let p=!u&&(!t||f&&e==null&&!n.inFlow||vt(t)||(Ge(t)?t.type===Be.BLOCK_FOLDED||t.type===Be.BLOCK_LITERAL:typeof t=="object"));n=Object.assign({},n,{allNullValues:!1,implicitKey:!p&&(u||!o),indent:a+l});let g=!1,h=!1,b=Es(t,n,()=>g=!0,()=>h=!0);if(!p&&!n.inFlow&&b.length>1024){if(u)throw new Error("With simple keys, single line scalar must not span more than 1024 characters");p=!0}if(n.inFlow){if(o||e==null)return g&&s&&s(),b===""?"?":p?`? ${b}`:b}else if(o&&!u||e==null&&p)return b=`? ${b}`,f&&!g?b+=ls(b,n.indent,c(f)):h&&r&&r(),b;g&&(f=null),p?(f&&(b+=ls(b,n.indent,c(f))),b=`? ${b}
|
|
35
|
+
${a}:`):(b=`${b}:`,f&&(b+=ls(b,n.indent,c(f))));let v,w,M;ht(e)?(v=!!e.spaceBefore,w=e.commentBefore,M=e.comment):(v=!1,w=null,M=null,e&&typeof e=="object"&&(e=i.createNode(e))),n.implicitKey=!1,!p&&!f&&Ge(e)&&(n.indentAtStart=b.length+1),h=!1,!d&&l.length>=2&&!n.inFlow&&!p&&Lt(e)&&!e.flow&&!e.tag&&!e.anchor&&(n.indent=n.indent.substring(2));let y=!1,T=Es(e,n,()=>y=!0,()=>h=!0),S=" ";if(f||v||w){if(S=v?`
|
|
36
|
+
`:"",w){let P=c(w);S+=`
|
|
37
|
+
${In(P,n.indent)}`}T===""&&!n.inFlow?S===`
|
|
38
|
+
`&&M&&(S=`
|
|
39
39
|
|
|
40
|
-
`):
|
|
41
|
-
${n.indent}`}else if(!p&&
|
|
42
|
-
`),
|
|
40
|
+
`):S+=`
|
|
41
|
+
${n.indent}`}else if(!p&&vt(e)){let P=T[0],I=T.indexOf(`
|
|
42
|
+
`),_=I!==-1,O=n.inFlow??e.flow??e.items.length===0;if(_||!O){let j=!1;if(_&&(P==="&"||P==="!")){let k=T.indexOf(" ");P==="&"&&k!==-1&&k<I&&T[k+1]==="!"&&(k=T.indexOf(" ",k+1)),(k===-1||I<k)&&(j=!0)}j||(S=`
|
|
43
43
|
${n.indent}`)}}else(T===""||T[0]===`
|
|
44
|
-
`)&&(
|
|
44
|
+
`)&&(S="");return b+=S+T,n.inFlow?y&&s&&s():M&&!y?b+=ls(b,n.indent,c(M)):h&&r&&r(),b}function Li(t,e){(t==="debug"||t==="warn")&&console.warn(e)}var Ni="<<",qn={identify:t=>t===Ni||typeof t=="symbol"&&t.description===Ni,default:"key",tag:"tag:yaml.org,2002:merge",test:/^<<$/,resolve:()=>Object.assign(new Be(Symbol(Ni)),{addToJSMap:Kl}),stringify:()=>Ni},jd=(t,e)=>(qn.identify(e)||Ge(e)&&(!e.type||e.type===Be.PLAIN)&&qn.identify(e.value))&&t?.doc.schema.tags.some(n=>n.tag===qn.tag&&n.default);function Kl(t,e,n){let s=Bd(t,n);if(Lt(s))for(let r of s.items)Bl(t,e,r);else if(Array.isArray(s))for(let r of s)Bl(t,e,r);else Bl(t,e,s)}function Bl(t,e,n){let s=Bd(t,n);if(!ct(s))throw new Error("Merge sources must be maps or map aliases");let r=s.toJSON(null,t,Map);for(let[o,i]of r)e instanceof Map?e.has(o)||e.set(o,i):e instanceof Set?e.add(o):Object.prototype.hasOwnProperty.call(e,o)||Object.defineProperty(e,o,{value:i,writable:!0,enumerable:!0,configurable:!0});return e}function Bd(t,e){return t&&Hn(e)?e.resolve(t.doc,t):e}function Ri(t,e,{key:n,value:s}){if(ht(n)&&n.addToJSMap)n.addToJSMap(t,e,s);else if(jd(t,n))Kl(t,e,s);else{let r=en(n,"",t);if(e instanceof Map)e.set(r,en(s,r,t));else if(e instanceof Set)e.add(r);else{let o=hp(n,r,t),i=en(s,o,t);o in e?Object.defineProperty(e,o,{value:i,writable:!0,enumerable:!0,configurable:!0}):e[o]=i}}return e}function hp(t,e,n){if(e===null)return"";if(typeof e!="object")return String(e);if(ht(t)&&n?.doc){let s=Ci(n.doc,{});s.anchors=new Set;for(let o of n.anchors.keys())s.anchors.add(o.anchor);s.inFlow=!0,s.inStringifyKey=!0;let r=t.toString(s);if(!n.mapKeyWarned){let o=JSON.stringify(r);o.length>40&&(o=o.substring(0,36)+'..."'),Li(n.doc.options.logLevel,`Keys with collection values will be stringified due to JS Object restrictions: ${o}. Set mapAsMap: true to use object keys.`),n.mapKeyWarned=!0}return r}return JSON.stringify(e)}function Dr(t,e,n){let s=$s(t,void 0,n),r=$s(e,void 0,n);return new Yt(s,r)}var Yt=class t{constructor(e,n=null){Object.defineProperty(this,gn,{value:Nl}),this.key=e,this.value=n}clone(e){let{key:n,value:s}=this;return ht(n)&&(n=n.clone(e)),ht(s)&&(s=s.clone(e)),new t(n,s)}toJSON(e,n){let s=n?.mapAsMap?new Map:{};return Ri(n,s,this)}toString(e,n,s){return e?.doc?Fd(this,e,n,s):JSON.stringify(this)}};function Di(t,e,n){return(e.inFlow??t.flow?bp:gp)(t,e,n)}function gp({comment:t,items:e},n,{blockItemPrefix:s,flowChars:r,itemIndent:o,onChompKeep:i,onComment:a}){let{indent:l,options:{commentString:c}}=n,d=Object.assign({},n,{indent:o,type:null}),u=!1,f=[];for(let g=0;g<e.length;++g){let h=e[g],b=null;if(ht(h))!u&&h.spaceBefore&&f.push(""),Ii(n,f,h.commentBefore,u),h.comment&&(b=h.comment);else if(tt(h)){let w=ht(h.key)?h.key:null;w&&(!u&&w.spaceBefore&&f.push(""),Ii(n,f,w.commentBefore,u))}u=!1;let v=Es(h,d,()=>b=null,()=>u=!0);b&&(v+=ls(v,o,c(b))),u&&b&&(u=!1),f.push(s+v)}let p;if(f.length===0)p=r.start+r.end;else{p=f[0];for(let g=1;g<f.length;++g){let h=f[g];p+=h?`
|
|
45
45
|
${l}${h}`:`
|
|
46
46
|
`}}return t?(p+=`
|
|
47
|
-
`+
|
|
48
|
-
`)),g<t.length-1?
|
|
47
|
+
`+In(c(t),l),a&&a()):u&&i&&i(),p}function bp({items:t},e,{flowChars:n,itemIndent:s}){let{indent:r,indentStep:o,flowCollectionPadding:i,options:{commentString:a}}=e;s+=o;let l=Object.assign({},e,{indent:s,inFlow:!0,type:null}),c=!1,d=0,u=[];for(let g=0;g<t.length;++g){let h=t[g],b=null;if(ht(h))h.spaceBefore&&u.push(""),Ii(e,u,h.commentBefore,!1),h.comment&&(b=h.comment);else if(tt(h)){let w=ht(h.key)?h.key:null;w&&(w.spaceBefore&&u.push(""),Ii(e,u,w.commentBefore,!1),w.comment&&(c=!0));let M=ht(h.value)?h.value:null;M?(M.comment&&(b=M.comment),M.commentBefore&&(c=!0)):h.value==null&&w?.comment&&(b=w.comment)}b&&(c=!0);let v=Es(h,l,()=>b=null);c||(c=u.length>d||v.includes(`
|
|
48
|
+
`)),g<t.length-1?v+=",":e.options.trailingComma&&(e.options.lineWidth>0&&(c||(c=u.reduce((w,M)=>w+M.length+2,2)+(v.length+2)>e.options.lineWidth)),c&&(v+=",")),b&&(v+=ls(v,s,a(b))),u.push(v),d=u.length}let{start:f,end:p}=n;if(u.length===0)return f+p;if(!c){let g=u.reduce((h,b)=>h+b.length+2,2);c=e.options.lineWidth>0&&g>e.options.lineWidth}if(c){let g=f;for(let h of u)g+=h?`
|
|
49
49
|
${o}${r}${h}`:`
|
|
50
50
|
`;return`${g}
|
|
51
|
-
${r}${p}`}else return`${f}${i}${u.join(" ")}${i}${p}`}function
|
|
52
|
-
`:" ")}return
|
|
51
|
+
${r}${p}`}else return`${f}${i}${u.join(" ")}${i}${p}`}function Ii({indent:t,options:{commentString:e}},n,s,r){if(s&&r&&(s=s.replace(/^\n+/,"")),s){let o=In(e(s),t);n.push(o.trimStart())}}function Gs(t,e){let n=Ge(e)?e.value:e;for(let s of t)if(tt(s)&&(s.key===e||s.key===n||Ge(s.key)&&s.key.value===n))return s}var Jt=class extends Nr{static get tagName(){return"tag:yaml.org,2002:map"}constructor(e){super(Gn,e),this.items=[]}static from(e,n,s){let{keepUndefined:r,replacer:o}=s,i=new this(e),a=(l,c)=>{if(typeof o=="function")c=o.call(n,l,c);else if(Array.isArray(o)&&!o.includes(l))return;(c!==void 0||r)&&i.items.push(Dr(l,c,s))};if(n instanceof Map)for(let[l,c]of n)a(l,c);else if(n&&typeof n=="object")for(let l of Object.keys(n))a(l,n[l]);return typeof e.sortMapEntries=="function"&&i.items.sort(e.sortMapEntries),i}add(e,n){let s;tt(e)?s=e:!e||typeof e!="object"||!("key"in e)?s=new Yt(e,e?.value):s=new Yt(e.key,e.value);let r=Gs(this.items,s.key),o=this.schema?.sortMapEntries;if(r){if(!n)throw new Error(`Key ${s.key} already set`);Ge(r.value)&&Ei(s.value)?r.value.value=s.value:r.value=s.value}else if(o){let i=this.items.findIndex(a=>o(s,a)<0);i===-1?this.items.push(s):this.items.splice(i,0,s)}else this.items.push(s)}delete(e){let n=Gs(this.items,e);return n?this.items.splice(this.items.indexOf(n),1).length>0:!1}get(e,n){let r=Gs(this.items,e)?.value;return(!n&&Ge(r)?r.value:r)??void 0}has(e){return!!Gs(this.items,e)}set(e,n){this.add(new Yt(e,n),!0)}toJSON(e,n,s){let r=s?new s:n?.mapAsMap?new Map:{};n?.onCreate&&n.onCreate(r);for(let o of this.items)Ri(n,r,o);return r}toString(e,n,s){if(!e)return JSON.stringify(this);for(let r of this.items)if(!tt(r))throw new Error(`Map items must all be pairs; found ${JSON.stringify(r)} instead`);return!e.allNullValues&&this.hasAllNullValues(!1)&&(e=Object.assign({},e,{allNullValues:!0})),Di(this,e,{blockItemPrefix:"",flowChars:{start:"{",end:"}"},itemIndent:e.indent||"",onChompKeep:s,onComment:n})}};var Un={collection:"map",default:!0,nodeClass:Jt,tag:"tag:yaml.org,2002:map",resolve(t,e){return ct(t)||e("Expected a mapping for this tag"),t},createNode:(t,e,n)=>Jt.from(t,e,n)};var on=class extends Nr{static get tagName(){return"tag:yaml.org,2002:seq"}constructor(e){super(Ss,e),this.items=[]}add(e){this.items.push(e)}delete(e){let n=Fi(e);return typeof n!="number"?!1:this.items.splice(n,1).length>0}get(e,n){let s=Fi(e);if(typeof s!="number")return;let r=this.items[s];return!n&&Ge(r)?r.value:r}has(e){let n=Fi(e);return typeof n=="number"&&n<this.items.length}set(e,n){let s=Fi(e);if(typeof s!="number")throw new Error(`Expected a valid index, not ${e}.`);let r=this.items[s];Ge(r)&&Ei(n)?r.value=n:this.items[s]=n}toJSON(e,n){let s=[];n?.onCreate&&n.onCreate(s);let r=0;for(let o of this.items)s.push(en(o,String(r++),n));return s}toString(e,n,s){return e?Di(this,e,{blockItemPrefix:"- ",flowChars:{start:"[",end:"]"},itemIndent:(e.indent||"")+" ",onChompKeep:s,onComment:n}):JSON.stringify(this)}static from(e,n,s){let{replacer:r}=s,o=new this(e);if(n&&Symbol.iterator in Object(n)){let i=0;for(let a of n){if(typeof r=="function"){let l=n instanceof Set?a:String(i++);a=r.call(n,l,a)}o.items.push($s(a,void 0,s))}}return o}};function Fi(t){let e=Ge(t)?t.value:t;return e&&typeof e=="string"&&(e=Number(e)),typeof e=="number"&&Number.isInteger(e)&&e>=0?e:null}var Wn={collection:"seq",default:!0,nodeClass:on,tag:"tag:yaml.org,2002:seq",resolve(t,e){return Lt(t)||e("Expected a sequence for this tag"),t},createNode:(t,e,n)=>on.from(t,e,n)};var Hs={identify:t=>typeof t=="string",default:!0,tag:"tag:yaml.org,2002:str",resolve:t=>t,stringify(t,e,n,s){return e=Object.assign({actualString:!0},e),ur(t,e,n,s)}};var fr={identify:t=>t==null,createNode:()=>new Be(null),default:!0,tag:"tag:yaml.org,2002:null",test:/^(?:~|[Nn]ull|NULL)?$/,resolve:()=>new Be(null),stringify:({source:t},e)=>typeof t=="string"&&fr.test.test(t)?t:e.options.nullStr};var Mo={identify:t=>typeof t=="boolean",default:!0,tag:"tag:yaml.org,2002:bool",test:/^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,resolve:t=>new Be(t[0]==="t"||t[0]==="T"),stringify({source:t,value:e},n){if(t&&Mo.test.test(t)){let s=t[0]==="t"||t[0]==="T";if(e===s)return t}return e?n.options.trueStr:n.options.falseStr}};function an({format:t,minFractionDigits:e,tag:n,value:s}){if(typeof s=="bigint")return String(s);let r=typeof s=="number"?s:Number(s);if(!isFinite(r))return isNaN(r)?".nan":r<0?"-.inf":".inf";let o=Object.is(s,-0)?"-0":JSON.stringify(s);if(!t&&e&&(!n||n==="tag:yaml.org,2002:float")&&/^-?\d/.test(o)&&!o.includes("e")){let i=o.indexOf(".");i<0&&(i=o.length,o+=".");let a=e-(o.length-i-1);for(;a-- >0;)o+="0"}return o}var ji={identify:t=>typeof t=="number",default:!0,tag:"tag:yaml.org,2002:float",test:/^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,resolve:t=>t.slice(-3).toLowerCase()==="nan"?NaN:t[0]==="-"?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,stringify:an},Bi={identify:t=>typeof t=="number",default:!0,tag:"tag:yaml.org,2002:float",format:"EXP",test:/^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,resolve:t=>parseFloat(t),stringify(t){let e=Number(t.value);return isFinite(e)?e.toExponential():an(t)}},Ki={identify:t=>typeof t=="number",default:!0,tag:"tag:yaml.org,2002:float",test:/^[-+]?(?:\.[0-9]+|[0-9]+\.[0-9]*)$/,resolve(t){let e=new Be(parseFloat(t)),n=t.indexOf(".");return n!==-1&&t[t.length-1]==="0"&&(e.minFractionDigits=t.length-n-1),e},stringify:an};var _i=t=>typeof t=="bigint"||Number.isInteger(t),_l=(t,e,n,{intAsBigInt:s})=>s?BigInt(t):parseInt(t.substring(e),n);function Kd(t,e,n){let{value:s}=t;return _i(s)&&s>=0?n+s.toString(e):an(t)}var zi={identify:t=>_i(t)&&t>=0,default:!0,tag:"tag:yaml.org,2002:int",format:"OCT",test:/^0o[0-7]+$/,resolve:(t,e,n)=>_l(t,2,8,n),stringify:t=>Kd(t,8,"0o")},Vi={identify:_i,default:!0,tag:"tag:yaml.org,2002:int",test:/^[-+]?[0-9]+$/,resolve:(t,e,n)=>_l(t,0,10,n),stringify:an},Gi={identify:t=>_i(t)&&t>=0,default:!0,tag:"tag:yaml.org,2002:int",format:"HEX",test:/^0x[0-9a-fA-F]+$/,resolve:(t,e,n)=>_l(t,2,16,n),stringify:t=>Kd(t,16,"0x")};var _d=[Un,Wn,Hs,fr,Mo,zi,Vi,Gi,ji,Bi,Ki];function zd(t){return typeof t=="bigint"||Number.isInteger(t)}var Hi=({value:t})=>JSON.stringify(t),yp=[{identify:t=>typeof t=="string",default:!0,tag:"tag:yaml.org,2002:str",resolve:t=>t,stringify:Hi},{identify:t=>t==null,createNode:()=>new Be(null),default:!0,tag:"tag:yaml.org,2002:null",test:/^null$/,resolve:()=>null,stringify:Hi},{identify:t=>typeof t=="boolean",default:!0,tag:"tag:yaml.org,2002:bool",test:/^true$|^false$/,resolve:t=>t==="true",stringify:Hi},{identify:zd,default:!0,tag:"tag:yaml.org,2002:int",test:/^-?(?:0|[1-9][0-9]*)$/,resolve:(t,e,{intAsBigInt:n})=>n?BigInt(t):parseInt(t,10),stringify:({value:t})=>zd(t)?t.toString():JSON.stringify(t)},{identify:t=>typeof t=="number",default:!0,tag:"tag:yaml.org,2002:float",test:/^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,resolve:t=>parseFloat(t),stringify:Hi}],xp={default:!0,tag:"",test:/^/,resolve(t,e){return e(`Unresolved plain scalar ${JSON.stringify(t)}`),t}},Vd=[Un,Wn].concat(yp,xp);var $o={identify:t=>t instanceof Uint8Array,default:!1,tag:"tag:yaml.org,2002:binary",resolve(t,e){if(typeof atob=="function"){let n=atob(t.replace(/[\n\r]/g,"")),s=new Uint8Array(n.length);for(let r=0;r<n.length;++r)s[r]=n.charCodeAt(r);return s}else return e("This environment does not support reading binary tags; either Buffer or atob is required"),t},stringify({comment:t,type:e,value:n},s,r,o){if(!n)return"";let i=n,a;if(typeof btoa=="function"){let l="";for(let c=0;c<i.length;++c)l+=String.fromCharCode(i[c]);a=btoa(l)}else throw new Error("This environment does not support writing binary tags; either Buffer or btoa is required");if(e??(e=Be.BLOCK_LITERAL),e!==Be.QUOTE_DOUBLE){let l=Math.max(s.options.lineWidth-s.indent.length,s.options.minContentWidth),c=Math.ceil(a.length/l),d=new Array(c);for(let u=0,f=0;u<c;++u,f+=l)d[u]=a.substr(f,l);a=d.join(e===Be.BLOCK_LITERAL?`
|
|
52
|
+
`:" ")}return ur({comment:t,type:e,value:a},s,r,o)}};function zl(t,e){if(Lt(t))for(let n=0;n<t.items.length;++n){let s=t.items[n];if(!tt(s)){if(ct(s)){s.items.length>1&&e("Each pair must have its own sequence indicator");let r=s.items[0]||new Yt(new Be(null));if(s.commentBefore&&(r.key.commentBefore=r.key.commentBefore?`${s.commentBefore}
|
|
53
53
|
${r.key.commentBefore}`:s.commentBefore),s.comment){let o=r.value??r.key;o.comment=o.comment?`${s.comment}
|
|
54
|
-
${o.comment}`:s.comment}s=r}t.items[n]=tt(s)?s:new
|
|
55
|
-
`)?(n.push("..."),n.push(
|
|
54
|
+
${o.comment}`:s.comment}s=r}t.items[n]=tt(s)?s:new Yt(s)}}else e("Expected a sequence for this tag");return t}function Vl(t,e,n){let{replacer:s}=n,r=new on(t);r.tag="tag:yaml.org,2002:pairs";let o=0;if(e&&Symbol.iterator in Object(e))for(let i of e){typeof s=="function"&&(i=s.call(e,String(o++),i));let a,l;if(Array.isArray(i))if(i.length===2)a=i[0],l=i[1];else throw new TypeError(`Expected [key, value] tuple: ${i}`);else if(i&&i instanceof Object){let c=Object.keys(i);if(c.length===1)a=c[0],l=i[a];else throw new TypeError(`Expected tuple with one key, not ${c.length} keys`)}else a=i;r.items.push(Dr(a,l,n))}return r}var Eo={collection:"seq",default:!1,tag:"tag:yaml.org,2002:pairs",resolve:zl,createNode:Vl};var Fr=class t extends on{constructor(){super(),this.add=Jt.prototype.add.bind(this),this.delete=Jt.prototype.delete.bind(this),this.get=Jt.prototype.get.bind(this),this.has=Jt.prototype.has.bind(this),this.set=Jt.prototype.set.bind(this),this.tag=t.tag}toJSON(e,n){if(!n)return super.toJSON(e);let s=new Map;n?.onCreate&&n.onCreate(s);for(let r of this.items){let o,i;if(tt(r)?(o=en(r.key,"",n),i=en(r.value,o,n)):o=en(r,"",n),s.has(o))throw new Error("Ordered maps must not include duplicate keys");s.set(o,i)}return s}static from(e,n,s){let r=Vl(e,n,s),o=new this;return o.items=r.items,o}};Fr.tag="tag:yaml.org,2002:omap";var To={collection:"seq",identify:t=>t instanceof Map,nodeClass:Fr,default:!1,tag:"tag:yaml.org,2002:omap",resolve(t,e){let n=zl(t,e),s=[];for(let{key:r}of n.items)Ge(r)&&(s.includes(r.value)?e(`Ordered maps must not include duplicate keys: ${r.value}`):s.push(r.value));return Object.assign(new Fr,n)},createNode:(t,e,n)=>Fr.from(t,e,n)};function Gd({value:t,source:e},n){return e&&(t?Gl:Hl).test.test(e)?e:t?n.options.trueStr:n.options.falseStr}var Gl={identify:t=>t===!0,default:!0,tag:"tag:yaml.org,2002:bool",test:/^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,resolve:()=>new Be(!0),stringify:Gd},Hl={identify:t=>t===!1,default:!0,tag:"tag:yaml.org,2002:bool",test:/^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/,resolve:()=>new Be(!1),stringify:Gd};var Hd={identify:t=>typeof t=="number",default:!0,tag:"tag:yaml.org,2002:float",test:/^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,resolve:t=>t.slice(-3).toLowerCase()==="nan"?NaN:t[0]==="-"?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,stringify:an},Yd={identify:t=>typeof t=="number",default:!0,tag:"tag:yaml.org,2002:float",format:"EXP",test:/^[-+]?(?:[0-9][0-9_]*)?(?:\.[0-9_]*)?[eE][-+]?[0-9]+$/,resolve:t=>parseFloat(t.replace(/_/g,"")),stringify(t){let e=Number(t.value);return isFinite(e)?e.toExponential():an(t)}},qd={identify:t=>typeof t=="number",default:!0,tag:"tag:yaml.org,2002:float",test:/^[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*$/,resolve(t){let e=new Be(parseFloat(t.replace(/_/g,""))),n=t.indexOf(".");if(n!==-1){let s=t.substring(n+1).replace(/_/g,"");s[s.length-1]==="0"&&(e.minFractionDigits=s.length)}return e},stringify:an};var Ao=t=>typeof t=="bigint"||Number.isInteger(t);function Yi(t,e,n,{intAsBigInt:s}){let r=t[0];if((r==="-"||r==="+")&&(e+=1),t=t.substring(e).replace(/_/g,""),s){switch(n){case 2:t=`0b${t}`;break;case 8:t=`0o${t}`;break;case 16:t=`0x${t}`;break}let i=BigInt(t);return r==="-"?BigInt(-1)*i:i}let o=parseInt(t,n);return r==="-"?-1*o:o}function Yl(t,e,n){let{value:s}=t;if(Ao(s)){let r=s.toString(e);return s<0?"-"+n+r.substr(1):n+r}return an(t)}var Ud={identify:Ao,default:!0,tag:"tag:yaml.org,2002:int",format:"BIN",test:/^[-+]?0b[0-1_]+$/,resolve:(t,e,n)=>Yi(t,2,2,n),stringify:t=>Yl(t,2,"0b")},Wd={identify:Ao,default:!0,tag:"tag:yaml.org,2002:int",format:"OCT",test:/^[-+]?0[0-7_]+$/,resolve:(t,e,n)=>Yi(t,1,8,n),stringify:t=>Yl(t,8,"0")},Jd={identify:Ao,default:!0,tag:"tag:yaml.org,2002:int",test:/^[-+]?[0-9][0-9_]*$/,resolve:(t,e,n)=>Yi(t,0,10,n),stringify:an},Xd={identify:Ao,default:!0,tag:"tag:yaml.org,2002:int",format:"HEX",test:/^[-+]?0x[0-9a-fA-F_]+$/,resolve:(t,e,n)=>Yi(t,2,16,n),stringify:t=>Yl(t,16,"0x")};var jr=class t extends Jt{constructor(e){super(e),this.tag=t.tag}add(e){let n;tt(e)?n=e:e&&typeof e=="object"&&"key"in e&&"value"in e&&e.value===null?n=new Yt(e.key,null):n=new Yt(e,null),Gs(this.items,n.key)||this.items.push(n)}get(e,n){let s=Gs(this.items,e);return!n&&tt(s)?Ge(s.key)?s.key.value:s.key:s}set(e,n){if(typeof n!="boolean")throw new Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof n}`);let s=Gs(this.items,e);s&&!n?this.items.splice(this.items.indexOf(s),1):!s&&n&&this.items.push(new Yt(e))}toJSON(e,n){return super.toJSON(e,n,Set)}toString(e,n,s){if(!e)return JSON.stringify(this);if(this.hasAllNullValues(!0))return super.toString(Object.assign({},e,{allNullValues:!0}),n,s);throw new Error("Set items must all have null values")}static from(e,n,s){let{replacer:r}=s,o=new this(e);if(n&&Symbol.iterator in Object(n))for(let i of n)typeof r=="function"&&(i=r.call(n,i,i)),o.items.push(Dr(i,null,s));return o}};jr.tag="tag:yaml.org,2002:set";var Po={collection:"map",identify:t=>t instanceof Set,nodeClass:jr,default:!1,tag:"tag:yaml.org,2002:set",createNode:(t,e,n)=>jr.from(t,e,n),resolve(t,e){if(ct(t)){if(t.hasAllNullValues(!0))return Object.assign(new jr,t);e("Set items must all have null values")}else e("Expected a mapping for this tag");return t}};function ql(t,e){let n=t[0],s=n==="-"||n==="+"?t.substring(1):t,r=i=>e?BigInt(i):Number(i),o=s.replace(/_/g,"").split(":").reduce((i,a)=>i*r(60)+r(a),r(0));return n==="-"?r(-1)*o:o}function Qd(t){let{value:e}=t,n=i=>i;if(typeof e=="bigint")n=i=>BigInt(i);else if(isNaN(e)||!isFinite(e))return an(t);let s="";e<0&&(s="-",e*=n(-1));let r=n(60),o=[e%r];return e<60?o.unshift(0):(e=(e-o[0])/r,o.unshift(e%r),e>=60&&(e=(e-o[0])/r,o.unshift(e))),s+o.map(i=>String(i).padStart(2,"0")).join(":").replace(/000000\d*$/,"")}var qi={identify:t=>typeof t=="bigint"||Number.isInteger(t),default:!0,tag:"tag:yaml.org,2002:int",format:"TIME",test:/^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+$/,resolve:(t,e,{intAsBigInt:n})=>ql(t,n),stringify:Qd},Ui={identify:t=>typeof t=="number",default:!0,tag:"tag:yaml.org,2002:float",format:"TIME",test:/^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*$/,resolve:t=>ql(t,!1),stringify:Qd},Br={identify:t=>t instanceof Date,default:!0,tag:"tag:yaml.org,2002:timestamp",test:RegExp("^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})(?:(?:t|T|[ \\t]+)([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?)?$"),resolve(t){let e=t.match(Br.test);if(!e)throw new Error("!!timestamp expects a date, starting with yyyy-mm-dd");let[,n,s,r,o,i,a]=e.map(Number),l=e[7]?Number((e[7]+"00").substr(1,3)):0,c=Date.UTC(n,s-1,r,o||0,i||0,a||0,l),d=e[8];if(d&&d!=="Z"){let u=ql(d,!1);Math.abs(u)<30&&(u*=60),c-=6e4*u}return new Date(c)},stringify:({value:t})=>t?.toISOString().replace(/(T00:00:00)?\.000Z$/,"")??""};var Ul=[Un,Wn,Hs,fr,Gl,Hl,Ud,Wd,Jd,Xd,Hd,Yd,qd,$o,qn,To,Eo,Po,qi,Ui,Br];var Zd=new Map([["core",_d],["failsafe",[Un,Wn,Hs]],["json",Vd],["yaml11",Ul],["yaml-1.1",Ul]]),eu={binary:$o,bool:Mo,float:Ki,floatExp:Bi,floatNaN:ji,floatTime:Ui,int:Vi,intHex:Gi,intOct:zi,intTime:qi,map:Un,merge:qn,null:fr,omap:To,pairs:Eo,seq:Wn,set:Po,timestamp:Br},tu={"tag:yaml.org,2002:binary":$o,"tag:yaml.org,2002:merge":qn,"tag:yaml.org,2002:omap":To,"tag:yaml.org,2002:pairs":Eo,"tag:yaml.org,2002:set":Po,"tag:yaml.org,2002:timestamp":Br};function Wi(t,e,n){let s=Zd.get(e);if(s&&!t)return n&&!s.includes(qn)?s.concat(qn):s.slice();let r=s;if(!r)if(Array.isArray(t))r=[];else{let o=Array.from(Zd.keys()).filter(i=>i!=="yaml11").map(i=>JSON.stringify(i)).join(", ");throw new Error(`Unknown schema "${e}"; use one of ${o} or define customTags array`)}if(Array.isArray(t))for(let o of t)r=r.concat(o);else typeof t=="function"&&(r=t(r.slice()));return n&&(r=r.concat(qn)),r.reduce((o,i)=>{let a=typeof i=="string"?eu[i]:i;if(!a){let l=JSON.stringify(i),c=Object.keys(eu).map(d=>JSON.stringify(d)).join(", ");throw new Error(`Unknown custom tag ${l}; use one of ${c}`)}return o.includes(a)||o.push(a),o},[])}var wp=(t,e)=>t.key<e.key?-1:t.key>e.key?1:0,Oo=class t{constructor({compat:e,customTags:n,merge:s,resolveKnownTags:r,schema:o,sortMapEntries:i,toStringDefaults:a}){this.compat=Array.isArray(e)?Wi(e,"compat"):e?Wi(null,e):null,this.name=typeof o=="string"&&o||"core",this.knownTags=r?tu:{},this.tags=Wi(n,this.name,s),this.toStringOptions=a??null,Object.defineProperty(this,Gn,{value:Un}),Object.defineProperty(this,Pn,{value:Hs}),Object.defineProperty(this,Ss,{value:Wn}),this.sortMapEntries=typeof i=="function"?i:i===!0?wp:null}clone(){let e=Object.create(t.prototype,Object.getOwnPropertyDescriptors(this));return e.tags=this.tags.slice(),e}};function nu(t,e){let n=[],s=e.directives===!0;if(e.directives!==!1&&t.directives){let l=t.directives.toString(t);l?(n.push(l),s=!0):t.directives.docStart&&(s=!0)}s&&n.push("---");let r=Ci(t,e),{commentString:o}=r.options;if(t.commentBefore){n.length!==1&&n.unshift("");let l=o(t.commentBefore);n.unshift(In(l,""))}let i=!1,a=null;if(t.contents){if(ht(t.contents)){if(t.contents.spaceBefore&&s&&n.push(""),t.contents.commentBefore){let d=o(t.contents.commentBefore);n.push(In(d,""))}r.forceBlockIndent=!!t.comment,a=t.contents.comment}let l=a?void 0:()=>i=!0,c=Es(t.contents,r,()=>a=null,l);a&&(c+=ls(c,"",o(a))),(c[0]==="|"||c[0]===">")&&n[n.length-1]==="---"?n[n.length-1]=`--- ${c}`:n.push(c)}else n.push(Es(t.contents,r));if(t.directives?.docEnd)if(t.comment){let l=o(t.comment);l.includes(`
|
|
55
|
+
`)?(n.push("..."),n.push(In(l,""))):n.push(`... ${l}`)}else n.push("...");else{let l=t.comment;l&&i&&(l=l.replace(/^\n+/,"")),l&&((!i||a)&&n[n.length-1]!==""&&n.push(""),n.push(In(o(l),"")))}return n.join(`
|
|
56
56
|
`)+`
|
|
57
|
-
`}var
|
|
57
|
+
`}var Jn=class t{constructor(e,n,s){this.commentBefore=null,this.comment=null,this.errors=[],this.warnings=[],Object.defineProperty(this,gn,{value:vi});let r=null;typeof n=="function"||Array.isArray(n)?r=n:s===void 0&&n&&(s=n,n=void 0);let o=Object.assign({intAsBigInt:!1,keepSourceTokens:!1,logLevel:"warn",prettyErrors:!0,strict:!0,stringKeys:!1,uniqueKeys:!0,version:"1.2"},s);this.options=o;let{version:i}=o;s?._directives?(this.directives=s._directives.atDocument(),this.directives.yaml.explicit&&(i=this.directives.yaml.version)):this.directives=new as({version:i}),this.setSchema(i,s),this.contents=e===void 0?null:this.createNode(e,r,s)}clone(){let e=Object.create(t.prototype,{[gn]:{value:vi}});return e.commentBefore=this.commentBefore,e.comment=this.comment,e.errors=this.errors.slice(),e.warnings=this.warnings.slice(),e.options=Object.assign({},this.options),this.directives&&(e.directives=this.directives.clone()),e.schema=this.schema.clone(),e.contents=ht(this.contents)?this.contents.clone(e.schema):this.contents,this.range&&(e.range=this.range.slice()),e}add(e){Kr(this.contents)&&this.contents.add(e)}addIn(e,n){Kr(this.contents)&&this.contents.addIn(e,n)}createAlias(e,n){if(!e.anchor){let s=Rl(this);e.anchor=!n||s.has(n)?Il(n||"a",s):n}return new Ms(e.anchor)}createNode(e,n,s){let r;if(typeof n=="function")e=n.call({"":e},"",e),r=n;else if(Array.isArray(n)){let b=w=>typeof w=="number"||w instanceof String||w instanceof Number,v=n.filter(b).map(String);v.length>0&&(n=n.concat(v)),r=n}else s===void 0&&n&&(s=n,n=void 0);let{aliasDuplicateObjects:o,anchorPrefix:i,flow:a,keepUndefined:l,onTagObj:c,tag:d}=s??{},{onAnchor:u,setAnchors:f,sourceObjects:p}=Rd(this,i||"a"),g={aliasDuplicateObjects:o??!0,keepUndefined:l??!1,onAnchor:u,onTagObj:c,replacer:r,schema:this.schema,sourceObjects:p},h=$s(e,d,g);return a&&vt(h)&&(h.flow=!0),f(),h}createPair(e,n,s={}){let r=this.createNode(e,null,s),o=this.createNode(n,null,s);return new Yt(r,o)}delete(e){return Kr(this.contents)?this.contents.delete(e):!1}deleteIn(e){return Rr(e)?this.contents==null?!1:(this.contents=null,!0):Kr(this.contents)?this.contents.deleteIn(e):!1}get(e,n){return vt(this.contents)?this.contents.get(e,n):void 0}getIn(e,n){return Rr(e)?!n&&Ge(this.contents)?this.contents.value:this.contents:vt(this.contents)?this.contents.getIn(e,n):void 0}has(e){return vt(this.contents)?this.contents.has(e):!1}hasIn(e){return Rr(e)?this.contents!==void 0:vt(this.contents)?this.contents.hasIn(e):!1}set(e,n){this.contents==null?this.contents=wo(this.schema,[e],n):Kr(this.contents)&&this.contents.set(e,n)}setIn(e,n){Rr(e)?this.contents=n:this.contents==null?this.contents=wo(this.schema,Array.from(e),n):Kr(this.contents)&&this.contents.setIn(e,n)}setSchema(e,n={}){typeof e=="number"&&(e=String(e));let s;switch(e){case"1.1":this.directives?this.directives.yaml.version="1.1":this.directives=new as({version:"1.1"}),s={resolveKnownTags:!1,schema:"yaml-1.1"};break;case"1.2":case"next":this.directives?this.directives.yaml.version=e:this.directives=new as({version:e}),s={resolveKnownTags:!0,schema:"core"};break;case null:this.directives&&delete this.directives,s=null;break;default:{let r=JSON.stringify(e);throw new Error(`Expected '1.1', '1.2' or null as first argument, but found: ${r}`)}}if(n.schema instanceof Object)this.schema=n.schema;else if(s)this.schema=new Oo(Object.assign(s,n));else throw new Error("With a null YAML version, the { schema: Schema } option is required")}toJS({json:e,jsonArg:n,mapAsMap:s,maxAliasCount:r,onAnchor:o,reviver:i}={}){let a={anchors:new Map,doc:this,keep:!e,mapAsMap:s===!0,mapKeyWarned:!1,maxAliasCount:typeof r=="number"?r:100},l=en(this.contents,n??"",a);if(typeof o=="function")for(let{count:c,res:d}of a.anchors.values())o(d,c);return typeof i=="function"?zs(i,{"":l},"",l):l}toJSON(e,n){return this.toJS({json:!0,jsonArg:e,mapAsMap:!1,onAnchor:n})}toString(e={}){if(this.errors.length>0)throw new Error("Document with errors cannot be stringified");if("indent"in e&&(!Number.isInteger(e.indent)||Number(e.indent)<=0)){let n=JSON.stringify(e.indent);throw new Error(`"indent" option must be a positive integer, not ${n}`)}return nu(this,e)}};function Kr(t){if(vt(t))return!0;throw new Error("Expected a YAML collection as document contents")}var Co=class extends Error{constructor(e,n,s,r){super(),this.name=e,this.code=s,this.message=r,this.pos=n}},Xn=class extends Co{constructor(e,n,s){super("YAMLParseError",e,n,s)}},Lo=class extends Co{constructor(e,n,s){super("YAMLWarning",e,n,s)}},Wl=(t,e)=>n=>{if(n.pos[0]===-1)return;n.linePos=n.pos.map(a=>e.linePos(a));let{line:s,col:r}=n.linePos[0];n.message+=` at line ${s}, column ${r}`;let o=r-1,i=t.substring(e.lineStarts[s-1],e.lineStarts[s]).replace(/[\n\r]+$/,"");if(o>=60&&i.length>80){let a=Math.min(o-39,i.length-79);i="\u2026"+i.substring(a),o-=a-1}if(i.length>80&&(i=i.substring(0,79)+"\u2026"),s>1&&/^ *$/.test(i.substring(0,o))){let a=t.substring(e.lineStarts[s-2],e.lineStarts[s-1]);a.length>80&&(a=a.substring(0,79)+`\u2026
|
|
58
58
|
`),i=a+i}if(/[^ ]/.test(i)){let a=1,l=n.linePos[1];l?.line===s&&l.col>r&&(a=Math.max(1,Math.min(l.col-r,80-o)));let c=" ".repeat(o)+"^".repeat(a);n.message+=`:
|
|
59
59
|
|
|
60
60
|
${i}
|
|
61
61
|
${c}
|
|
62
|
-
`}};function
|
|
63
|
-
`))return!0;if(t.end){for(let e of t.end)if(e.type==="newline")return!0}return!1;case"flow-collection":for(let e of t.items){for(let n of e.start)if(n.type==="newline")return!0;if(e.sep){for(let n of e.sep)if(n.type==="newline")return!0}if(
|
|
64
|
-
`+h.comment:a.comment=h.comment);continue}(h.newlineAfterProp||
|
|
65
|
-
`+M.comment:
|
|
66
|
-
`+
|
|
67
|
-
`+
|
|
68
|
-
`+
|
|
69
|
-
`+b.comment:c.comment=b.comment),c.range=[s.offset,h,b.offset]}else c.range=[s.offset,h,h];return c}function
|
|
70
|
-
`.repeat(Math.max(1,i.length-1)):"",b=s+r.length;return e.source&&(b+=e.source.length),{value:h,type:o,comment:r.comment,range:[s,b,b]}}let l=e.indent+r.indent,c=e.offset+r.length,d=0;for(let h=0;h<a;++h){let[b,
|
|
71
|
-
`;for(let h=d;h<a;++h){let[b,
|
|
72
|
-
`):b.length>l||
|
|
62
|
+
`}};function cs(t,{flow:e,indicator:n,next:s,offset:r,onError:o,parentIndent:i,startOnNewline:a}){let l=!1,c=a,d=a,u="",f="",p=!1,g=!1,h=null,b=null,v=null,w=null,M=null,y=null,T=null;for(let I of t)switch(g&&(I.type!=="space"&&I.type!=="newline"&&I.type!=="comma"&&o(I.offset,"MISSING_CHAR","Tags and anchors must be separated from the next token by white space"),g=!1),h&&(c&&I.type!=="comment"&&I.type!=="newline"&&o(h,"TAB_AS_INDENT","Tabs are not allowed as indentation"),h=null),I.type){case"space":!e&&(n!=="doc-start"||s?.type!=="flow-collection")&&I.source.includes(" ")&&(h=I),d=!0;break;case"comment":{d||o(I,"MISSING_CHAR","Comments must be separated from other tokens by white space characters");let _=I.source.substring(1)||" ";u?u+=f+_:u=_,f="",c=!1;break}case"newline":c?u?u+=I.source:(!y||n!=="seq-item-ind")&&(l=!0):f+=I.source,c=!0,p=!0,(b||v)&&(w=I),d=!0;break;case"anchor":b&&o(I,"MULTIPLE_ANCHORS","A node can have at most one anchor"),I.source.endsWith(":")&&o(I.offset+I.source.length-1,"BAD_ALIAS","Anchor ending in : is ambiguous",!0),b=I,T??(T=I.offset),c=!1,d=!1,g=!0;break;case"tag":{v&&o(I,"MULTIPLE_TAGS","A node can have at most one tag"),v=I,T??(T=I.offset),c=!1,d=!1,g=!0;break}case n:(b||v)&&o(I,"BAD_PROP_ORDER",`Anchors and tags must be after the ${I.source} indicator`),y&&o(I,"UNEXPECTED_TOKEN",`Unexpected ${I.source} in ${e??"collection"}`),y=I,c=n==="seq-item-ind"||n==="explicit-key-ind",d=!1;break;case"comma":if(e){M&&o(I,"UNEXPECTED_TOKEN",`Unexpected , in ${e}`),M=I,c=!1,d=!1;break}default:o(I,"UNEXPECTED_TOKEN",`Unexpected ${I.type} token`),c=!1,d=!1}let S=t[t.length-1],P=S?S.offset+S.source.length:r;return g&&s&&s.type!=="space"&&s.type!=="newline"&&s.type!=="comma"&&(s.type!=="scalar"||s.source!=="")&&o(s.offset,"MISSING_CHAR","Tags and anchors must be separated from the next token by white space"),h&&(c&&h.indent<=i||s?.type==="block-map"||s?.type==="block-seq")&&o(h,"TAB_AS_INDENT","Tabs are not allowed as indentation"),{comma:M,found:y,spaceBefore:l,comment:u,hasNewline:p,anchor:b,tag:v,newlineAfterProp:w,end:P,start:T??P}}function Ys(t){if(!t)return null;switch(t.type){case"alias":case"scalar":case"double-quoted-scalar":case"single-quoted-scalar":if(t.source.includes(`
|
|
63
|
+
`))return!0;if(t.end){for(let e of t.end)if(e.type==="newline")return!0}return!1;case"flow-collection":for(let e of t.items){for(let n of e.start)if(n.type==="newline")return!0;if(e.sep){for(let n of e.sep)if(n.type==="newline")return!0}if(Ys(e.key)||Ys(e.value))return!0}return!1;default:return!0}}function No(t,e,n){if(e?.type==="flow-collection"){let s=e.end[0];s.indent===t&&(s.source==="]"||s.source==="}")&&Ys(e)&&n(s,"BAD_INDENT","Flow end indicator should be more indented than parent",!0)}}function Ji(t,e,n){let{uniqueKeys:s}=t.options;if(s===!1)return!1;let r=typeof s=="function"?s:(o,i)=>o===i||Ge(o)&&Ge(i)&&o.value===i.value;return e.some(o=>r(o.key,n))}var su="All mapping items must start at the same column";function ru({composeNode:t,composeEmptyNode:e},n,s,r,o){let i=o?.nodeClass??Jt,a=new i(n.schema);n.atRoot&&(n.atRoot=!1);let l=s.offset,c=null;for(let d of s.items){let{start:u,key:f,sep:p,value:g}=d,h=cs(u,{indicator:"explicit-key-ind",next:f??p?.[0],offset:l,onError:r,parentIndent:s.indent,startOnNewline:!0}),b=!h.found;if(b){if(f&&(f.type==="block-seq"?r(l,"BLOCK_AS_IMPLICIT_KEY","A block sequence may not be used as an implicit map key"):"indent"in f&&f.indent!==s.indent&&r(l,"BAD_INDENT",su)),!h.anchor&&!h.tag&&!p){c=h.end,h.comment&&(a.comment?a.comment+=`
|
|
64
|
+
`+h.comment:a.comment=h.comment);continue}(h.newlineAfterProp||Ys(f))&&r(f??u[u.length-1],"MULTILINE_IMPLICIT_KEY","Implicit keys need to be on a single line")}else h.found?.indent!==s.indent&&r(l,"BAD_INDENT",su);n.atKey=!0;let v=h.end,w=f?t(n,f,h,r):e(n,v,u,null,h,r);n.schema.compat&&No(s.indent,f,r),n.atKey=!1,Ji(n,a.items,w)&&r(v,"DUPLICATE_KEY","Map keys must be unique");let M=cs(p??[],{indicator:"map-value-ind",next:g,offset:w.range[2],onError:r,parentIndent:s.indent,startOnNewline:!f||f.type==="block-scalar"});if(l=M.end,M.found){b&&(g?.type==="block-map"&&!M.hasNewline&&r(l,"BLOCK_AS_IMPLICIT_KEY","Nested mappings are not allowed in compact mappings"),n.options.strict&&h.start<M.found.offset-1024&&r(w.range,"KEY_OVER_1024_CHARS","The : indicator must be at most 1024 chars after the start of an implicit block mapping key"));let y=g?t(n,g,M,r):e(n,l,p,null,M,r);n.schema.compat&&No(s.indent,g,r),l=y.range[2];let T=new Yt(w,y);n.options.keepSourceTokens&&(T.srcToken=d),a.items.push(T)}else{b&&r(w.range,"MISSING_CHAR","Implicit map keys need to be followed by map values"),M.comment&&(w.comment?w.comment+=`
|
|
65
|
+
`+M.comment:w.comment=M.comment);let y=new Yt(w);n.options.keepSourceTokens&&(y.srcToken=d),a.items.push(y)}}return c&&c<l&&r(c,"IMPOSSIBLE","Map comment with trailing content"),a.range=[s.offset,l,c??l],a}function ou({composeNode:t,composeEmptyNode:e},n,s,r,o){let i=o?.nodeClass??on,a=new i(n.schema);n.atRoot&&(n.atRoot=!1),n.atKey&&(n.atKey=!1);let l=s.offset,c=null;for(let{start:d,value:u}of s.items){let f=cs(d,{indicator:"seq-item-ind",next:u,offset:l,onError:r,parentIndent:s.indent,startOnNewline:!0});if(!f.found)if(f.anchor||f.tag||u)u?.type==="block-seq"?r(f.end,"BAD_INDENT","All sequence items must start at the same column"):r(l,"MISSING_CHAR","Sequence item without - indicator");else{c=f.end,f.comment&&(a.comment=f.comment);continue}let p=u?t(n,u,f,r):e(n,f.end,d,null,f,r);n.schema.compat&&No(s.indent,u,r),l=p.range[2],a.items.push(p)}return a.range=[s.offset,l,c??l],a}function ds(t,e,n,s){let r="";if(t){let o=!1,i="";for(let a of t){let{source:l,type:c}=a;switch(c){case"space":o=!0;break;case"comment":{n&&!o&&s(a,"MISSING_CHAR","Comments must be separated from other tokens by white space characters");let d=l.substring(1)||" ";r?r+=i+d:r=d,i="";break}case"newline":r&&(i+=l),o=!0;break;default:s(a,"UNEXPECTED_TOKEN",`Unexpected ${c} at node end`)}e+=l.length}}return{comment:r,offset:e}}var Jl="Block collections are not allowed within flow collections",Xl=t=>t&&(t.type==="block-map"||t.type==="block-seq");function iu({composeNode:t,composeEmptyNode:e},n,s,r,o){let i=s.start.source==="{",a=i?"flow map":"flow sequence",l=o?.nodeClass??(i?Jt:on),c=new l(n.schema);c.flow=!0;let d=n.atRoot;d&&(n.atRoot=!1),n.atKey&&(n.atKey=!1);let u=s.offset+s.start.source.length;for(let b=0;b<s.items.length;++b){let v=s.items[b],{start:w,key:M,sep:y,value:T}=v,S=cs(w,{flow:a,indicator:"explicit-key-ind",next:M??y?.[0],offset:u,onError:r,parentIndent:s.indent,startOnNewline:!1});if(!S.found){if(!S.anchor&&!S.tag&&!y&&!T){b===0&&S.comma?r(S.comma,"UNEXPECTED_TOKEN",`Unexpected , in ${a}`):b<s.items.length-1&&r(S.start,"UNEXPECTED_TOKEN",`Unexpected empty item in ${a}`),S.comment&&(c.comment?c.comment+=`
|
|
66
|
+
`+S.comment:c.comment=S.comment),u=S.end;continue}!i&&n.options.strict&&Ys(M)&&r(M,"MULTILINE_IMPLICIT_KEY","Implicit keys of flow sequence pairs need to be on a single line")}if(b===0)S.comma&&r(S.comma,"UNEXPECTED_TOKEN",`Unexpected , in ${a}`);else if(S.comma||r(S.start,"MISSING_CHAR",`Missing , between ${a} items`),S.comment){let P="";e:for(let I of w)switch(I.type){case"comma":case"space":break;case"comment":P=I.source.substring(1);break e;default:break e}if(P){let I=c.items[c.items.length-1];tt(I)&&(I=I.value??I.key),I.comment?I.comment+=`
|
|
67
|
+
`+P:I.comment=P,S.comment=S.comment.substring(P.length+1)}}if(!i&&!y&&!S.found){let P=T?t(n,T,S,r):e(n,S.end,y,null,S,r);c.items.push(P),u=P.range[2],Xl(T)&&r(P.range,"BLOCK_IN_FLOW",Jl)}else{n.atKey=!0;let P=S.end,I=M?t(n,M,S,r):e(n,P,w,null,S,r);Xl(M)&&r(I.range,"BLOCK_IN_FLOW",Jl),n.atKey=!1;let _=cs(y??[],{flow:a,indicator:"map-value-ind",next:T,offset:I.range[2],onError:r,parentIndent:s.indent,startOnNewline:!1});if(_.found){if(!i&&!S.found&&n.options.strict){if(y)for(let k of y){if(k===_.found)break;if(k.type==="newline"){r(k,"MULTILINE_IMPLICIT_KEY","Implicit keys of flow sequence pairs need to be on a single line");break}}S.start<_.found.offset-1024&&r(_.found,"KEY_OVER_1024_CHARS","The : indicator must be at most 1024 chars after the start of an implicit flow sequence key")}}else T&&("source"in T&&T.source?.[0]===":"?r(T,"MISSING_CHAR",`Missing space after : in ${a}`):r(_.start,"MISSING_CHAR",`Missing , or : between ${a} items`));let O=T?t(n,T,_,r):_.found?e(n,_.end,y,null,_,r):null;O?Xl(T)&&r(O.range,"BLOCK_IN_FLOW",Jl):_.comment&&(I.comment?I.comment+=`
|
|
68
|
+
`+_.comment:I.comment=_.comment);let j=new Yt(I,O);if(n.options.keepSourceTokens&&(j.srcToken=v),i){let k=c;Ji(n,k.items,I)&&r(P,"DUPLICATE_KEY","Map keys must be unique"),k.items.push(j)}else{let k=new Jt(n.schema);k.flow=!0,k.items.push(j);let $=(O??I).range;k.range=[I.range[0],$[1],$[2]],c.items.push(k)}u=O?O.range[2]:_.end}}let f=i?"}":"]",[p,...g]=s.end,h=u;if(p?.source===f)h=p.offset+p.source.length;else{let b=a[0].toUpperCase()+a.substring(1),v=d?`${b} must end with a ${f}`:`${b} in block collection must be sufficiently indented and end with a ${f}`;r(u,d?"MISSING_CHAR":"BAD_INDENT",v),p&&p.source.length!==1&&g.unshift(p)}if(g.length>0){let b=ds(g,h,n.options.strict,r);b.comment&&(c.comment?c.comment+=`
|
|
69
|
+
`+b.comment:c.comment=b.comment),c.range=[s.offset,h,b.offset]}else c.range=[s.offset,h,h];return c}function Ql(t,e,n,s,r,o){let i=n.type==="block-map"?ru(t,e,n,s,o):n.type==="block-seq"?ou(t,e,n,s,o):iu(t,e,n,s,o),a=i.constructor;return r==="!"||r===a.tagName?(i.tag=a.tagName,i):(r&&(i.tag=r),i)}function au(t,e,n,s,r){let o=s.tag,i=o?e.directives.tagName(o.source,f=>r(o,"TAG_RESOLVE_FAILED",f)):null;if(n.type==="block-seq"){let{anchor:f,newlineAfterProp:p}=s,g=f&&o?f.offset>o.offset?f:o:f??o;g&&(!p||p.offset<g.offset)&&r(g,"MISSING_CHAR","Missing newline after block sequence props")}let a=n.type==="block-map"?"map":n.type==="block-seq"?"seq":n.start.source==="{"?"map":"seq";if(!o||!i||i==="!"||i===Jt.tagName&&a==="map"||i===on.tagName&&a==="seq")return Ql(t,e,n,r,i);let l=e.schema.tags.find(f=>f.tag===i&&f.collection===a);if(!l){let f=e.schema.knownTags[i];if(f?.collection===a)e.schema.tags.push(Object.assign({},f,{default:!1})),l=f;else return f?r(o,"BAD_COLLECTION_TYPE",`${f.tag} used for ${a} collection, but expects ${f.collection??"scalar"}`,!0):r(o,"TAG_RESOLVE_FAILED",`Unresolved tag: ${i}`,!0),Ql(t,e,n,r,i)}let c=Ql(t,e,n,r,i,l),d=l.resolve?.(c,f=>r(o,"TAG_RESOLVE_FAILED",f),e.options)??c,u=ht(d)?d:new Be(d);return u.range=c.range,u.tag=i,l?.format&&(u.format=l.format),u}function Zl(t,e,n){let s=e.offset,r=vp(e,t.options.strict,n);if(!r)return{value:"",type:null,comment:"",range:[s,s,s]};let o=r.mode===">"?Be.BLOCK_FOLDED:Be.BLOCK_LITERAL,i=e.source?kp(e.source):[],a=i.length;for(let h=i.length-1;h>=0;--h){let b=i[h][1];if(b===""||b==="\r")a=h;else break}if(a===0){let h=r.chomp==="+"&&i.length>0?`
|
|
70
|
+
`.repeat(Math.max(1,i.length-1)):"",b=s+r.length;return e.source&&(b+=e.source.length),{value:h,type:o,comment:r.comment,range:[s,b,b]}}let l=e.indent+r.indent,c=e.offset+r.length,d=0;for(let h=0;h<a;++h){let[b,v]=i[h];if(v===""||v==="\r")r.indent===0&&b.length>l&&(l=b.length);else{b.length<l&&n(c+b.length,"MISSING_CHAR","Block scalars with more-indented leading empty lines must use an explicit indentation indicator"),r.indent===0&&(l=b.length),d=h,l===0&&!t.atRoot&&n(c,"BAD_INDENT","Block scalar values in collections must be indented");break}c+=b.length+v.length+1}for(let h=i.length-1;h>=a;--h)i[h][0].length>l&&(a=h+1);let u="",f="",p=!1;for(let h=0;h<d;++h)u+=i[h][0].slice(l)+`
|
|
71
|
+
`;for(let h=d;h<a;++h){let[b,v]=i[h];c+=b.length+v.length+1;let w=v[v.length-1]==="\r";if(w&&(v=v.slice(0,-1)),v&&b.length<l){let y=`Block scalar lines must not be less indented than their ${r.indent?"explicit indentation indicator":"first line"}`;n(c-v.length-(w?2:1),"BAD_INDENT",y),b=""}o===Be.BLOCK_LITERAL?(u+=f+b.slice(l)+v,f=`
|
|
72
|
+
`):b.length>l||v[0]===" "?(f===" "?f=`
|
|
73
73
|
`:!p&&f===`
|
|
74
74
|
`&&(f=`
|
|
75
75
|
|
|
76
|
-
`),u+=f+b.slice(l)+
|
|
77
|
-
`,p=!0):
|
|
76
|
+
`),u+=f+b.slice(l)+v,f=`
|
|
77
|
+
`,p=!0):v===""?f===`
|
|
78
78
|
`?u+=`
|
|
79
79
|
`:f=`
|
|
80
|
-
`:(u+=f+
|
|
80
|
+
`:(u+=f+v,f=" ",p=!1)}switch(r.chomp){case"-":break;case"+":for(let h=a;h<i.length;++h)u+=`
|
|
81
81
|
`+i[h][0].slice(l);u[u.length-1]!==`
|
|
82
82
|
`&&(u+=`
|
|
83
83
|
`);break;default:u+=`
|
|
84
|
-
`}let g=s+r.length+e.source.length;return{value:u,type:o,comment:r.comment,range:[s,g,g]}}function
|
|
84
|
+
`}let g=s+r.length+e.source.length;return{value:u,type:o,comment:r.comment,range:[s,g,g]}}function vp({offset:t,props:e},n,s){if(e[0].type!=="block-scalar-header")return s(e[0],"IMPOSSIBLE","Block scalar header not found"),null;let{source:r}=e[0],o=r[0],i=0,a="",l=-1;for(let f=1;f<r.length;++f){let p=r[f];if(!a&&(p==="-"||p==="+"))a=p;else{let g=Number(p);!i&&g?i=g:l===-1&&(l=t+f)}}l!==-1&&s(l,"UNEXPECTED_TOKEN",`Block scalar header includes extra characters: ${r}`);let c=!1,d="",u=r.length;for(let f=1;f<e.length;++f){let p=e[f];switch(p.type){case"space":c=!0;case"newline":u+=p.source.length;break;case"comment":n&&!c&&s(p,"MISSING_CHAR","Comments must be separated from other tokens by white space characters"),u+=p.source.length,d=p.source.substring(1);break;case"error":s(p,"UNEXPECTED_TOKEN",p.message),u+=p.source.length;break;default:{let g=`Unexpected token in block scalar header: ${p.type}`;s(p,"UNEXPECTED_TOKEN",g);let h=p.source;h&&typeof h=="string"&&(u+=h.length)}}}return{mode:o,indent:i,chomp:a,comment:d,length:u}}function kp(t){let e=t.split(/\n( *)/),n=e[0],s=n.match(/^( *)/),o=[s?.[1]?[s[1],n.slice(s[1].length)]:["",n]];for(let i=1;i<e.length;i+=2)o.push([e[i],e[i+1]]);return o}function ec(t,e,n){let{offset:s,type:r,source:o,end:i}=t,a,l,c=(f,p,g)=>n(s+f,p,g);switch(r){case"scalar":a=Be.PLAIN,l=Sp(o,c);break;case"single-quoted-scalar":a=Be.QUOTE_SINGLE,l=Mp(o,c);break;case"double-quoted-scalar":a=Be.QUOTE_DOUBLE,l=$p(o,c);break;default:return n(t,"UNEXPECTED_TOKEN",`Expected a flow scalar value, but found: ${r}`),{value:"",type:null,comment:"",range:[s,s+o.length,s+o.length]}}let d=s+o.length,u=ds(i,d,e,n);return{value:l,type:a,comment:u.comment,range:[s,d,u.offset]}}function Sp(t,e){let n="";switch(t[0]){case" ":n="a tab character";break;case",":n="flow indicator character ,";break;case"%":n="directive indicator character %";break;case"|":case">":{n=`block scalar indicator ${t[0]}`;break}case"@":case"`":{n=`reserved character ${t[0]}`;break}}return n&&e(0,"BAD_SCALAR_START",`Plain value cannot start with ${n}`),lu(t)}function Mp(t,e){return(t[t.length-1]!=="'"||t.length===1)&&e(t.length,"MISSING_CHAR","Missing closing 'quote"),lu(t.slice(1,-1)).replace(/''/g,"'")}function lu(t){let e=/(.*?)\r?\n/sy,n=e.exec(t);if(!n)return t;let s,r;try{s=new RegExp("(?<![ ])[ ]+$"),r=new RegExp("^[ ]+|(?<![ ])[ ]+$","g")}catch{s=/[ \t]+$/,r=/^[ \t]+|[ \t]+$/g}let o=n[1].replace(s,""),i=" ",a=e.lastIndex;for(;n=e.exec(t);){let c=n[1].replace(r,"");c===""?i===`
|
|
85
85
|
`?o+=i:i=`
|
|
86
|
-
`:(o+=i+c,i=" "),a=e.lastIndex}let l=/[ \t]*(.*)/sy;return l.lastIndex=a,n=l.exec(t),o+i+(n?.[1]??"")}function
|
|
86
|
+
`:(o+=i+c,i=" "),a=e.lastIndex}let l=/[ \t]*(.*)/sy;return l.lastIndex=a,n=l.exec(t),o+i+(n?.[1]??"")}function $p(t,e){let n="";for(let s=1;s<t.length-1;++s){let r=t[s];if(!(r==="\r"&&t[s+1]===`
|
|
87
87
|
`))if(r===`
|
|
88
|
-
`){let{fold:o,offset:i}=
|
|
88
|
+
`){let{fold:o,offset:i}=Ep(t,s);n+=o,s=i}else if(r==="\\"){let o=t[++s],i=Tp[o];if(i)n+=i;else if(o===`
|
|
89
89
|
`)for(o=t[s+1];o===" "||o===" ";)o=t[++s+1];else if(o==="\r"&&t[s+1]===`
|
|
90
|
-
`)for(o=t[++s+1];o===" "||o===" ";)o=t[++s+1];else if(o==="x"||o==="u"||o==="U"){let a=o==="x"?2:o==="u"?4:8;n+=
|
|
90
|
+
`)for(o=t[++s+1];o===" "||o===" ";)o=t[++s+1];else if(o==="x"||o==="u"||o==="U"){let a=o==="x"?2:o==="u"?4:8;n+=Ap(t,s+1,a,e),s+=a}else{let a=t.substr(s-1,2);e(s-1,"BAD_DQ_ESCAPE",`Invalid escape sequence ${a}`),n+=a}}else if(r===" "||r===" "){let o=s,i=t[s+1];for(;i===" "||i===" ";)i=t[++s+1];i!==`
|
|
91
91
|
`&&!(i==="\r"&&t[s+2]===`
|
|
92
|
-
`)&&(n+=s>o?t.slice(o,s+1):r)}else n+=r}return(t[t.length-1]!=='"'||t.length===1)&&e(t.length,"MISSING_CHAR",'Missing closing "quote'),n}function
|
|
92
|
+
`)&&(n+=s>o?t.slice(o,s+1):r)}else n+=r}return(t[t.length-1]!=='"'||t.length===1)&&e(t.length,"MISSING_CHAR",'Missing closing "quote'),n}function Ep(t,e){let n="",s=t[e+1];for(;(s===" "||s===" "||s===`
|
|
93
93
|
`||s==="\r")&&!(s==="\r"&&t[e+2]!==`
|
|
94
94
|
`);)s===`
|
|
95
95
|
`&&(n+=`
|
|
96
|
-
`),e+=1,s=t[e+1];return n||(n=" "),{fold:n,offset:e}}var
|
|
97
|
-
`,r:"\r",t:" ",v:"\v",N:"\x85",_:"\xA0",L:"\u2028",P:"\u2029"," ":" ",'"':'"',"/":"/","\\":"\\"," ":" "};function
|
|
96
|
+
`),e+=1,s=t[e+1];return n||(n=" "),{fold:n,offset:e}}var Tp={0:"\0",a:"\x07",b:"\b",e:"\x1B",f:"\f",n:`
|
|
97
|
+
`,r:"\r",t:" ",v:"\v",N:"\x85",_:"\xA0",L:"\u2028",P:"\u2029"," ":" ",'"':'"',"/":"/","\\":"\\"," ":" "};function Ap(t,e,n,s){let r=t.substr(e,n),i=r.length===n&&/^[0-9a-fA-F]+$/.test(r)?parseInt(r,16):NaN;try{return String.fromCodePoint(i)}catch{let a=t.substr(e-2,n+2);return s(e-2,"BAD_DQ_ESCAPE",`Invalid escape sequence ${a}`),a}}function tc(t,e,n,s){let{value:r,type:o,comment:i,range:a}=e.type==="block-scalar"?Zl(t,e,s):ec(e,t.options.strict,s),l=n?t.directives.tagName(n.source,u=>s(n,"TAG_RESOLVE_FAILED",u)):null,c;t.options.stringKeys&&t.atKey?c=t.schema[Pn]:l?c=Pp(t.schema,r,l,n,s):e.type==="scalar"?c=Op(t,r,e,s):c=t.schema[Pn];let d;try{let u=c.resolve(r,f=>s(n??e,"TAG_RESOLVE_FAILED",f),t.options);d=Ge(u)?u:new Be(u)}catch(u){let f=u instanceof Error?u.message:String(u);s(n??e,"TAG_RESOLVE_FAILED",f),d=new Be(r)}return d.range=a,d.source=r,o&&(d.type=o),l&&(d.tag=l),c.format&&(d.format=c.format),i&&(d.comment=i),d}function Pp(t,e,n,s,r){if(n==="!")return t[Pn];let o=[];for(let a of t.tags)if(!a.collection&&a.tag===n)if(a.default&&a.test)o.push(a);else return a;for(let a of o)if(a.test?.test(e))return a;let i=t.knownTags[n];return i&&!i.collection?(t.tags.push(Object.assign({},i,{default:!1,test:void 0})),i):(r(s,"TAG_RESOLVE_FAILED",`Unresolved tag: ${n}`,n!=="tag:yaml.org,2002:str"),t[Pn])}function Op({atKey:t,directives:e,schema:n},s,r,o){let i=n.tags.find(a=>(a.default===!0||t&&a.default==="key")&&a.test?.test(s))||n[Pn];if(n.compat){let a=n.compat.find(l=>l.default&&l.test?.test(s))??n[Pn];if(i.tag!==a.tag){let l=e.tagString(i.tag),c=e.tagString(a.tag),d=`Value may be parsed as either ${l} or ${c}`;o(r,"TAG_RESOLVE_FAILED",d,!0)}}return i}function cu(t,e,n){if(e){n??(n=e.length);for(let s=n-1;s>=0;--s){let r=e[s];switch(r.type){case"space":case"comment":case"newline":t-=r.source.length;continue}for(r=e[++s];r?.type==="space";)t+=r.source.length,r=e[++s];break}}return t}var Cp={composeNode:nc,composeEmptyNode:Xi};function nc(t,e,n,s){let r=t.atKey,{spaceBefore:o,comment:i,anchor:a,tag:l}=n,c,d=!0;switch(e.type){case"alias":c=Lp(t,e,s),(a||l)&&s(e,"ALIAS_PROPS","An alias node must not specify any properties");break;case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":case"block-scalar":c=tc(t,e,l,s),a&&(c.anchor=a.source.substring(1));break;case"block-map":case"block-seq":case"flow-collection":try{c=au(Cp,t,e,n,s),a&&(c.anchor=a.source.substring(1))}catch(u){let f=u instanceof Error?u.message:String(u);s(e,"RESOURCE_EXHAUSTION",f)}break;default:{let u=e.type==="error"?e.message:`Unsupported token (type: ${e.type})`;s(e,"UNEXPECTED_TOKEN",u),d=!1}}return c??(c=Xi(t,e.offset,void 0,null,n,s)),a&&c.anchor===""&&s(a,"BAD_ALIAS","Anchor cannot be an empty string"),r&&t.options.stringKeys&&(!Ge(c)||typeof c.value!="string"||c.tag&&c.tag!=="tag:yaml.org,2002:str")&&s(l??e,"NON_STRING_KEY","With stringKeys, all keys must be strings"),o&&(c.spaceBefore=!0),i&&(e.type==="scalar"&&e.source===""?c.comment=i:c.commentBefore=i),t.options.keepSourceTokens&&d&&(c.srcToken=e),c}function Xi(t,e,n,s,{spaceBefore:r,comment:o,anchor:i,tag:a,end:l},c){let d={type:"scalar",offset:cu(e,n,s),indent:-1,source:""},u=tc(t,d,a,c);return i&&(u.anchor=i.source.substring(1),u.anchor===""&&c(i,"BAD_ALIAS","Anchor cannot be an empty string")),r&&(u.spaceBefore=!0),o&&(u.comment=o,u.range[2]=l),u}function Lp({options:t},{offset:e,source:n,end:s},r){let o=new Ms(n.substring(1));o.source===""&&r(e,"BAD_ALIAS","Alias cannot be an empty string"),o.source.endsWith(":")&&r(e+n.length-1,"BAD_ALIAS","Alias ending in : is ambiguous",!0);let i=e+n.length,a=ds(s,i,t.strict,r);return o.range=[e,i,a.offset],a.comment&&(o.comment=a.comment),o}function du(t,e,{offset:n,start:s,value:r,end:o},i){let a=Object.assign({_directives:e},t),l=new Jn(void 0,a),c={atKey:!1,atRoot:!0,directives:l.directives,options:l.options,schema:l.schema},d=cs(s,{indicator:"doc-start",next:r??o?.[0],offset:n,onError:i,parentIndent:0,startOnNewline:!0});d.found&&(l.directives.docStart=!0,r&&(r.type==="block-map"||r.type==="block-seq")&&!d.hasNewline&&i(d.end,"MISSING_CHAR","Block collection cannot start on same line with directives-end marker")),l.contents=r?nc(c,r,d,i):Xi(c,d.end,s,null,d,i);let u=l.contents.range[2],f=ds(o,u,!1,i);return f.comment&&(l.comment=f.comment),l.range=[n,u,f.offset],l}function Ro(t){if(typeof t=="number")return[t,t+1];if(Array.isArray(t))return t.length===2?t:[t[0],t[1]];let{offset:e,source:n}=t;return[e,e+(typeof n=="string"?n.length:1)]}function uu(t){let e="",n=!1,s=!1;for(let r=0;r<t.length;++r){let o=t[r];switch(o[0]){case"#":e+=(e===""?"":s?`
|
|
98
98
|
|
|
99
99
|
`:`
|
|
100
|
-
`)+(o.substring(1)||" "),n=!0,s=!1;break;case"%":t[r+1]?.[0]!=="#"&&(r+=1),n=!1;break;default:n||(s=!0),n=!1}}return{comment:e,afterEmptyLine:s}}var
|
|
101
|
-
${s}`:s;else if(r||e.directives.docStart||!o)e.commentBefore=s;else if(
|
|
100
|
+
`)+(o.substring(1)||" "),n=!0,s=!1;break;case"%":t[r+1]?.[0]!=="#"&&(r+=1),n=!1;break;default:n||(s=!0),n=!1}}return{comment:e,afterEmptyLine:s}}var Io=class{constructor(e={}){this.doc=null,this.atDirectives=!1,this.prelude=[],this.errors=[],this.warnings=[],this.onError=(n,s,r,o)=>{let i=Ro(n);o?this.warnings.push(new Lo(i,s,r)):this.errors.push(new Xn(i,s,r))},this.directives=new as({version:e.version||"1.2"}),this.options=e}decorate(e,n){let{comment:s,afterEmptyLine:r}=uu(this.prelude);if(s){let o=e.contents;if(n)e.comment=e.comment?`${e.comment}
|
|
101
|
+
${s}`:s;else if(r||e.directives.docStart||!o)e.commentBefore=s;else if(vt(o)&&!o.flow&&o.items.length>0){let i=o.items[0];tt(i)&&(i=i.key);let a=i.commentBefore;i.commentBefore=a?`${s}
|
|
102
102
|
${a}`:s}else{let i=o.commentBefore;o.commentBefore=i?`${s}
|
|
103
|
-
${i}`:s}}if(n){for(let o=0;o<this.errors.length;++o)e.errors.push(this.errors[o]);for(let o=0;o<this.warnings.length;++o)e.warnings.push(this.warnings[o])}else e.errors=this.errors,e.warnings=this.warnings;this.prelude=[],this.errors=[],this.warnings=[]}streamInfo(){return{comment:
|
|
104
|
-
${n.comment}`:n.comment}this.doc.range[2]=n.offset;break}default:this.errors.push(new
|
|
103
|
+
${i}`:s}}if(n){for(let o=0;o<this.errors.length;++o)e.errors.push(this.errors[o]);for(let o=0;o<this.warnings.length;++o)e.warnings.push(this.warnings[o])}else e.errors=this.errors,e.warnings=this.warnings;this.prelude=[],this.errors=[],this.warnings=[]}streamInfo(){return{comment:uu(this.prelude).comment,directives:this.directives,errors:this.errors,warnings:this.warnings}}*compose(e,n=!1,s=-1){for(let r of e)yield*this.next(r);yield*this.end(n,s)}*next(e){switch(e.type){case"directive":this.directives.add(e.source,(n,s,r)=>{let o=Ro(e);o[0]+=n,this.onError(o,"BAD_DIRECTIVE",s,r)}),this.prelude.push(e.source),this.atDirectives=!0;break;case"document":{let n=du(this.options,this.directives,e,this.onError);this.atDirectives&&!n.directives.docStart&&this.onError(e,"MISSING_CHAR","Missing directives-end/doc-start indicator line"),this.decorate(n,!1),this.doc&&(yield this.doc),this.doc=n,this.atDirectives=!1;break}case"byte-order-mark":case"space":break;case"comment":case"newline":this.prelude.push(e.source);break;case"error":{let n=e.source?`${e.message}: ${JSON.stringify(e.source)}`:e.message,s=new Xn(Ro(e),"UNEXPECTED_TOKEN",n);this.atDirectives||!this.doc?this.errors.push(s):this.doc.errors.push(s);break}case"doc-end":{if(!this.doc){let s="Unexpected doc-end without preceding document";this.errors.push(new Xn(Ro(e),"UNEXPECTED_TOKEN",s));break}this.doc.directives.docEnd=!0;let n=ds(e.end,e.offset+e.source.length,this.doc.options.strict,this.onError);if(this.decorate(this.doc,!0),n.comment){let s=this.doc.comment;this.doc.comment=s?`${s}
|
|
104
|
+
${n.comment}`:n.comment}this.doc.range[2]=n.offset;break}default:this.errors.push(new Xn(Ro(e),"UNEXPECTED_TOKEN",`Unsupported token ${e.type}`))}}*end(e=!1,n=-1){if(this.doc)this.decorate(this.doc,!0),yield this.doc,this.doc=null;else if(e){let s=Object.assign({_directives:this.directives},this.options),r=new Jn(void 0,s);this.atDirectives&&this.onError(n,"MISSING_CHAR","Missing directives-end indicator line"),r.range=[0,n,n],this.decorate(r,!1),yield r}}};var sc=Symbol("break visit"),Np=Symbol("skip children"),fu=Symbol("remove item");function pr(t,e){"type"in t&&t.type==="document"&&(t={start:t.start,value:t.value}),pu(Object.freeze([]),t,e)}pr.BREAK=sc;pr.SKIP=Np;pr.REMOVE=fu;pr.itemAtPath=(t,e)=>{let n=t;for(let[s,r]of e){let o=n?.[s];if(o&&"items"in o)n=o.items[r];else return}return n};pr.parentCollection=(t,e)=>{let n=pr.itemAtPath(t,e.slice(0,-1)),s=e[e.length-1][0],r=n?.[s];if(r&&"items"in r)return r;throw new Error("Parent collection not found")};function pu(t,e,n){let s=n(e,t);if(typeof s=="symbol")return s;for(let r of["key","value"]){let o=e[r];if(o&&"items"in o){for(let i=0;i<o.items.length;++i){let a=pu(Object.freeze(t.concat([[r,i]])),o.items[i],n);if(typeof a=="number")i=a-1;else{if(a===sc)return sc;a===fu&&(o.items.splice(i,1),i-=1)}}typeof s=="function"&&r==="key"&&(s=s(e,t))}}return typeof s=="function"?s(e,t):s}var rc="\uFEFF",oc="",ic="",Qi="";function mu(t){switch(t){case rc:return"byte-order-mark";case oc:return"doc-mode";case ic:return"flow-error-end";case Qi:return"scalar";case"---":return"doc-start";case"...":return"doc-end";case"":case`
|
|
105
105
|
`:case`\r
|
|
106
|
-
`:return"newline";case"-":return"seq-item-ind";case"?":return"explicit-key-ind";case":":return"map-value-ind";case"{":return"flow-map-start";case"}":return"flow-map-end";case"[":return"flow-seq-start";case"]":return"flow-seq-end";case",":return"comma"}switch(t[0]){case" ":case" ":return"space";case"#":return"comment";case"%":return"directive-line";case"*":return"alias";case"&":return"anchor";case"!":return"tag";case"'":return"single-quoted-scalar";case'"':return"double-quoted-scalar";case"|":case">":return"block-scalar-header"}return null}function
|
|
107
|
-
`:case"\r":case" ":return!0;default:return!1}}var
|
|
108
|
-
\r `),
|
|
106
|
+
`:return"newline";case"-":return"seq-item-ind";case"?":return"explicit-key-ind";case":":return"map-value-ind";case"{":return"flow-map-start";case"}":return"flow-map-end";case"[":return"flow-seq-start";case"]":return"flow-seq-end";case",":return"comma"}switch(t[0]){case" ":case" ":return"space";case"#":return"comment";case"%":return"directive-line";case"*":return"alias";case"&":return"anchor";case"!":return"tag";case"'":return"single-quoted-scalar";case'"':return"double-quoted-scalar";case"|":case">":return"block-scalar-header"}return null}function Qn(t){switch(t){case void 0:case" ":case`
|
|
107
|
+
`:case"\r":case" ":return!0;default:return!1}}var hu=new Set("0123456789ABCDEFabcdef"),Ip=new Set("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()"),Zi=new Set(",[]{}"),Dp=new Set(` ,[]{}
|
|
108
|
+
\r `),ac=t=>!t||Dp.has(t),Do=class{constructor(){this.atEnd=!1,this.blockScalarIndent=-1,this.blockScalarKeep=!1,this.buffer="",this.flowKey=!1,this.flowLevel=0,this.indentNext=0,this.indentValue=0,this.lineEndPos=null,this.next=null,this.pos=0}*lex(e,n=!1){if(e){if(typeof e!="string")throw TypeError("source is not a string");this.buffer=this.buffer?this.buffer+e:e,this.lineEndPos=null}this.atEnd=!n;let s=this.next??"stream";for(;s&&(n||this.hasChars(1));)s=yield*this.parseNext(s)}atLineEnd(){let e=this.pos,n=this.buffer[e];for(;n===" "||n===" ";)n=this.buffer[++e];return!n||n==="#"||n===`
|
|
109
109
|
`?!0:n==="\r"?this.buffer[e+1]===`
|
|
110
110
|
`:!1}charAt(e){return this.buffer[this.pos+e]}continueScalar(e){let n=this.buffer[e];if(this.indentNext>0){let s=0;for(;n===" ";)n=this.buffer[++s+e];if(n==="\r"){let r=this.buffer[s+e+1];if(r===`
|
|
111
111
|
`||!r&&!this.atEnd)return e+s+1}return n===`
|
|
112
|
-
`||s>=this.indentNext||!n&&!this.atEnd?e+s:-1}if(n==="-"||n==="."){let s=this.buffer.substr(e,3);if((s==="---"||s==="...")&&
|
|
113
|
-
`,this.pos),this.lineEndPos=e),e===-1?this.atEnd?this.buffer.substring(this.pos):null:(this.buffer[e-1]==="\r"&&(e-=1),this.buffer.substring(this.pos,e))}hasChars(e){return this.pos+e<=this.buffer.length}setNext(e){return this.buffer=this.buffer.substring(this.pos),this.pos=0,this.lineEndPos=null,this.next=e,null}peek(e){return this.buffer.substr(this.pos,e)}*parseNext(e){switch(e){case"stream":return yield*this.parseStream();case"line-start":return yield*this.parseLineStart();case"block-start":return yield*this.parseBlockStart();case"doc":return yield*this.parseDocument();case"flow":return yield*this.parseFlowCollection();case"quoted-scalar":return yield*this.parseQuotedScalar();case"block-scalar":return yield*this.parseBlockScalar();case"plain-scalar":return yield*this.parsePlainScalar()}}*parseStream(){let e=this.getLine();if(e===null)return this.setNext("stream");if(e[0]===
|
|
112
|
+
`||s>=this.indentNext||!n&&!this.atEnd?e+s:-1}if(n==="-"||n==="."){let s=this.buffer.substr(e,3);if((s==="---"||s==="...")&&Qn(this.buffer[e+3]))return-1}return e}getLine(){let e=this.lineEndPos;return(typeof e!="number"||e!==-1&&e<this.pos)&&(e=this.buffer.indexOf(`
|
|
113
|
+
`,this.pos),this.lineEndPos=e),e===-1?this.atEnd?this.buffer.substring(this.pos):null:(this.buffer[e-1]==="\r"&&(e-=1),this.buffer.substring(this.pos,e))}hasChars(e){return this.pos+e<=this.buffer.length}setNext(e){return this.buffer=this.buffer.substring(this.pos),this.pos=0,this.lineEndPos=null,this.next=e,null}peek(e){return this.buffer.substr(this.pos,e)}*parseNext(e){switch(e){case"stream":return yield*this.parseStream();case"line-start":return yield*this.parseLineStart();case"block-start":return yield*this.parseBlockStart();case"doc":return yield*this.parseDocument();case"flow":return yield*this.parseFlowCollection();case"quoted-scalar":return yield*this.parseQuotedScalar();case"block-scalar":return yield*this.parseBlockScalar();case"plain-scalar":return yield*this.parsePlainScalar()}}*parseStream(){let e=this.getLine();if(e===null)return this.setNext("stream");if(e[0]===rc&&(yield*this.pushCount(1),e=e.substring(1)),e[0]==="%"){let n=e.length,s=e.indexOf("#");for(;s!==-1;){let o=e[s-1];if(o===" "||o===" "){n=s-1;break}else s=e.indexOf("#",s+1)}for(;;){let o=e[n-1];if(o===" "||o===" ")n-=1;else break}let r=(yield*this.pushCount(n))+(yield*this.pushSpaces(!0));return yield*this.pushCount(e.length-r),this.pushNewline(),"stream"}if(this.atLineEnd()){let n=yield*this.pushSpaces(!0);return yield*this.pushCount(e.length-n),yield*this.pushNewline(),"stream"}return yield oc,yield*this.parseLineStart()}*parseLineStart(){let e=this.charAt(0);if(!e&&!this.atEnd)return this.setNext("line-start");if(e==="-"||e==="."){if(!this.atEnd&&!this.hasChars(4))return this.setNext("line-start");let n=this.peek(3);if((n==="---"||n==="...")&&Qn(this.charAt(3)))return yield*this.pushCount(3),this.indentValue=0,this.indentNext=0,n==="---"?"doc":"stream"}return this.indentValue=yield*this.pushSpaces(!1),this.indentNext>this.indentValue&&!Qn(this.charAt(1))&&(this.indentNext=this.indentValue),yield*this.parseBlockStart()}*parseBlockStart(){let[e,n]=this.peek(2);if(!n&&!this.atEnd)return this.setNext("block-start");if((e==="-"||e==="?"||e===":")&&Qn(n)){let s=(yield*this.pushCount(1))+(yield*this.pushSpaces(!0));return this.indentNext=this.indentValue+1,this.indentValue+=s,"block-start"}return"doc"}*parseDocument(){yield*this.pushSpaces(!0);let e=this.getLine();if(e===null)return this.setNext("doc");let n=yield*this.pushIndicators();switch(e[n]){case"#":yield*this.pushCount(e.length-n);case void 0:return yield*this.pushNewline(),yield*this.parseLineStart();case"{":case"[":return yield*this.pushCount(1),this.flowKey=!1,this.flowLevel=1,"flow";case"}":case"]":return yield*this.pushCount(1),"doc";case"*":return yield*this.pushUntil(ac),"doc";case'"':case"'":return yield*this.parseQuotedScalar();case"|":case">":return n+=yield*this.parseBlockScalarHeader(),n+=yield*this.pushSpaces(!0),yield*this.pushCount(e.length-n),yield*this.pushNewline(),yield*this.parseBlockScalar();default:return yield*this.parsePlainScalar()}}*parseFlowCollection(){let e,n,s=-1;do e=yield*this.pushNewline(),e>0?(n=yield*this.pushSpaces(!1),this.indentValue=s=n):n=0,n+=yield*this.pushSpaces(!0);while(e+n>0);let r=this.getLine();if(r===null)return this.setNext("flow");if((s!==-1&&s<this.indentNext&&r[0]!=="#"||s===0&&(r.startsWith("---")||r.startsWith("..."))&&Qn(r[3]))&&!(s===this.indentNext-1&&this.flowLevel===1&&(r[0]==="]"||r[0]==="}")))return this.flowLevel=0,yield ic,yield*this.parseLineStart();let o=0;for(;r[o]===",";)o+=yield*this.pushCount(1),o+=yield*this.pushSpaces(!0),this.flowKey=!1;switch(o+=yield*this.pushIndicators(),r[o]){case void 0:return"flow";case"#":return yield*this.pushCount(r.length-o),"flow";case"{":case"[":return yield*this.pushCount(1),this.flowKey=!1,this.flowLevel+=1,"flow";case"}":case"]":return yield*this.pushCount(1),this.flowKey=!0,this.flowLevel-=1,this.flowLevel?"flow":"doc";case"*":return yield*this.pushUntil(ac),"flow";case'"':case"'":return this.flowKey=!0,yield*this.parseQuotedScalar();case":":{let i=this.charAt(1);if(this.flowKey||Qn(i)||i===",")return this.flowKey=!1,yield*this.pushCount(1),yield*this.pushSpaces(!0),"flow"}default:return this.flowKey=!1,yield*this.parsePlainScalar()}}*parseQuotedScalar(){let e=this.charAt(0),n=this.buffer.indexOf(e,this.pos+1);if(e==="'")for(;n!==-1&&this.buffer[n+1]==="'";)n=this.buffer.indexOf("'",n+2);else for(;n!==-1;){let o=0;for(;this.buffer[n-1-o]==="\\";)o+=1;if(o%2===0)break;n=this.buffer.indexOf('"',n+1)}let s=this.buffer.substring(0,n),r=s.indexOf(`
|
|
114
114
|
`,this.pos);if(r!==-1){for(;r!==-1;){let o=this.continueScalar(r+1);if(o===-1)break;r=s.indexOf(`
|
|
115
|
-
`,o)}r!==-1&&(n=r-(s[r-1]==="\r"?2:1))}if(n===-1){if(!this.atEnd)return this.setNext("quoted-scalar");n=this.buffer.length}return yield*this.pushToIndex(n+1,!1),this.flowLevel?"flow":"doc"}*parseBlockScalarHeader(){this.blockScalarIndent=-1,this.blockScalarKeep=!1;let e=this.pos;for(;;){let n=this.buffer[++e];if(n==="+")this.blockScalarKeep=!0;else if(n>"0"&&n<="9")this.blockScalarIndent=Number(n)-1;else if(n!=="-")break}return yield*this.pushUntil(n=>
|
|
115
|
+
`,o)}r!==-1&&(n=r-(s[r-1]==="\r"?2:1))}if(n===-1){if(!this.atEnd)return this.setNext("quoted-scalar");n=this.buffer.length}return yield*this.pushToIndex(n+1,!1),this.flowLevel?"flow":"doc"}*parseBlockScalarHeader(){this.blockScalarIndent=-1,this.blockScalarKeep=!1;let e=this.pos;for(;;){let n=this.buffer[++e];if(n==="+")this.blockScalarKeep=!0;else if(n>"0"&&n<="9")this.blockScalarIndent=Number(n)-1;else if(n!=="-")break}return yield*this.pushUntil(n=>Qn(n)||n==="#")}*parseBlockScalar(){let e=this.pos-1,n=0,s;e:for(let o=this.pos;s=this.buffer[o];++o)switch(s){case" ":n+=1;break;case`
|
|
116
116
|
`:e=o,n=0;break;case"\r":{let i=this.buffer[o+1];if(!i&&!this.atEnd)return this.setNext("block-scalar");if(i===`
|
|
117
117
|
`)break}default:break e}if(!s&&!this.atEnd)return this.setNext("block-scalar");if(n>=this.indentNext){this.blockScalarIndent===-1?this.indentNext=n:this.indentNext=this.blockScalarIndent+(this.indentNext===0?1:this.indentNext);do{let o=this.continueScalar(e+1);if(o===-1)break;e=this.buffer.indexOf(`
|
|
118
118
|
`,o)}while(e!==-1);if(e===-1){if(!this.atEnd)return this.setNext("block-scalar");e=this.buffer.length}}let r=e+1;for(s=this.buffer[r];s===" ";)s=this.buffer[++r];if(s===" "){for(;s===" "||s===" "||s==="\r"||s===`
|
|
119
119
|
`;)s=this.buffer[++r];e=r-1}else if(!this.blockScalarKeep)do{let o=e-1,i=this.buffer[o];i==="\r"&&(i=this.buffer[--o]);let a=o;for(;i===" ";)i=this.buffer[--o];if(i===`
|
|
120
|
-
`&&o>=this.pos&&o+1+n>a)e=o;else break}while(!0);return yield
|
|
120
|
+
`&&o>=this.pos&&o+1+n>a)e=o;else break}while(!0);return yield Qi,yield*this.pushToIndex(e+1,!0),yield*this.parseLineStart()}*parsePlainScalar(){let e=this.flowLevel>0,n=this.pos-1,s=this.pos-1,r;for(;r=this.buffer[++s];)if(r===":"){let o=this.buffer[s+1];if(Qn(o)||e&&Zi.has(o))break;n=s}else if(Qn(r)){let o=this.buffer[s+1];if(r==="\r"&&(o===`
|
|
121
121
|
`?(s+=1,r=`
|
|
122
|
-
`,o=this.buffer[s+1]):n=s),o==="#"||e&&
|
|
123
|
-
`){let i=this.continueScalar(s+1);if(i===-1)break;s=Math.max(s,i-2)}}else{if(e&&
|
|
122
|
+
`,o=this.buffer[s+1]):n=s),o==="#"||e&&Zi.has(o))break;if(r===`
|
|
123
|
+
`){let i=this.continueScalar(s+1);if(i===-1)break;s=Math.max(s,i-2)}}else{if(e&&Zi.has(r))break;n=s}return!r&&!this.atEnd?this.setNext("plain-scalar"):(yield Qi,yield*this.pushToIndex(n+1,!0),e?"flow":"doc")}*pushCount(e){return e>0?(yield this.buffer.substr(this.pos,e),this.pos+=e,e):0}*pushToIndex(e,n){let s=this.buffer.slice(this.pos,e);return s?(yield s,this.pos+=s.length,s.length):(n&&(yield""),0)}*pushIndicators(){let e=0;e:for(;;){switch(this.charAt(0)){case"!":e+=yield*this.pushTag(),e+=yield*this.pushSpaces(!0);continue e;case"&":e+=yield*this.pushUntil(ac),e+=yield*this.pushSpaces(!0);continue e;case"-":case"?":case":":{let n=this.flowLevel>0,s=this.charAt(1);if(Qn(s)||n&&Zi.has(s)){n?this.flowKey&&(this.flowKey=!1):this.indentNext=this.indentValue+1,e+=yield*this.pushCount(1),e+=yield*this.pushSpaces(!0);continue e}}}break e}return e}*pushTag(){if(this.charAt(1)==="<"){let e=this.pos+2,n=this.buffer[e];for(;!Qn(n)&&n!==">";)n=this.buffer[++e];return yield*this.pushToIndex(n===">"?e+1:e,!1)}else{let e=this.pos+1,n=this.buffer[e];for(;n;)if(Ip.has(n))n=this.buffer[++e];else if(n==="%"&&hu.has(this.buffer[e+1])&&hu.has(this.buffer[e+2]))n=this.buffer[e+=3];else break;return yield*this.pushToIndex(e,!1)}}*pushNewline(){let e=this.buffer[this.pos];return e===`
|
|
124
124
|
`?yield*this.pushCount(1):e==="\r"&&this.charAt(1)===`
|
|
125
|
-
`?yield*this.pushCount(2):0}*pushSpaces(e){let n=this.pos-1,s;do s=this.buffer[++n];while(s===" "||e&&s===" ");let r=n-this.pos;return r>0&&(yield this.buffer.substr(this.pos,r),this.pos=n),r}*pushUntil(e){let n=this.pos,s=this.buffer[n];for(;!e(s);)s=this.buffer[++n];return yield*this.pushToIndex(n,!1)}};var
|
|
125
|
+
`?yield*this.pushCount(2):0}*pushSpaces(e){let n=this.pos-1,s;do s=this.buffer[++n];while(s===" "||e&&s===" ");let r=n-this.pos;return r>0&&(yield this.buffer.substr(this.pos,r),this.pos=n),r}*pushUntil(e){let n=this.pos,s=this.buffer[n];for(;!e(s);)s=this.buffer[++n];return yield*this.pushToIndex(n,!1)}};var Ts=class{constructor(){this.lineStarts=[],this.addNewLine=e=>this.lineStarts.push(e),this.linePos=e=>{let n=0,s=this.lineStarts.length;for(;n<s;){let o=n+s>>1;this.lineStarts[o]<e?n=o+1:s=o}if(this.lineStarts[n]===e)return{line:n+1,col:1};if(n===0)return{line:0,col:e};let r=this.lineStarts[n-1];return{line:n,col:e-r+1}}}};function qs(t,e){for(let n=0;n<t.length;++n)if(t[n].type===e)return!0;return!1}function gu(t){for(let e=0;e<t.length;++e)switch(t[e].type){case"space":case"comment":case"newline":break;default:return e}return-1}function yu(t){switch(t?.type){case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":case"flow-collection":return!0;default:return!1}}function ea(t){switch(t.type){case"document":return t.start;case"block-map":{let e=t.items[t.items.length-1];return e.sep??e.start}case"block-seq":return t.items[t.items.length-1].start;default:return[]}}function _r(t){if(t.length===0)return[];let e=t.length;e:for(;--e>=0;)switch(t[e].type){case"doc-start":case"explicit-key-ind":case"map-value-ind":case"seq-item-ind":case"newline":break e}for(;t[++e]?.type==="space";);return t.splice(e,t.length)}function ta(t,e){if(e.length<1e5)Array.prototype.push.apply(t,e);else for(let n=0;n<e.length;++n)t.push(e[n])}function bu(t){if(t.start.type==="flow-seq-start")for(let e of t.items)e.sep&&!e.value&&!qs(e.start,"explicit-key-ind")&&!qs(e.sep,"map-value-ind")&&(e.key&&(e.value=e.key),delete e.key,yu(e.value)?e.value.end?ta(e.value.end,e.sep):e.value.end=e.sep:ta(e.start,e.sep),delete e.sep)}var Fo=class{constructor(e){this.atNewLine=!0,this.atScalar=!1,this.indent=0,this.offset=0,this.onKeyLine=!1,this.stack=[],this.source="",this.type="",this.lexer=new Do,this.onNewLine=e}*parse(e,n=!1){this.onNewLine&&this.offset===0&&this.onNewLine(0);for(let s of this.lexer.lex(e,n))yield*this.next(s);n||(yield*this.end())}*next(e){if(this.source=e,this.atScalar){this.atScalar=!1,yield*this.step(),this.offset+=e.length;return}let n=mu(e);if(n)if(n==="scalar")this.atNewLine=!1,this.atScalar=!0,this.type="scalar";else{switch(this.type=n,yield*this.step(),n){case"newline":this.atNewLine=!0,this.indent=0,this.onNewLine&&this.onNewLine(this.offset+e.length);break;case"space":this.atNewLine&&e[0]===" "&&(this.indent+=e.length);break;case"explicit-key-ind":case"map-value-ind":case"seq-item-ind":this.atNewLine&&(this.indent+=e.length);break;case"doc-mode":case"flow-error-end":return;default:this.atNewLine=!1}this.offset+=e.length}else{let s=`Not a YAML token: ${e}`;yield*this.pop({type:"error",offset:this.offset,message:s,source:e}),this.offset+=e.length}}*end(){for(;this.stack.length>0;)yield*this.pop()}get sourceToken(){return{type:this.type,offset:this.offset,indent:this.indent,source:this.source}}*step(){let e=this.peek(1);if(this.type==="doc-end"&&e?.type!=="doc-end"){for(;this.stack.length>0;)yield*this.pop();this.stack.push({type:"doc-end",offset:this.offset,source:this.source});return}if(!e)return yield*this.stream();switch(e.type){case"document":return yield*this.document(e);case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":return yield*this.scalar(e);case"block-scalar":return yield*this.blockScalar(e);case"block-map":return yield*this.blockMap(e);case"block-seq":return yield*this.blockSequence(e);case"flow-collection":return yield*this.flowCollection(e);case"doc-end":return yield*this.documentEnd(e)}yield*this.pop()}peek(e){return this.stack[this.stack.length-e]}*pop(e){let n=e??this.stack.pop();if(!n)yield{type:"error",offset:this.offset,source:"",message:"Tried to pop an empty stack"};else if(this.stack.length===0)yield n;else{let s=this.peek(1);switch(n.type==="block-scalar"?n.indent="indent"in s?s.indent:0:n.type==="flow-collection"&&s.type==="document"&&(n.indent=0),n.type==="flow-collection"&&bu(n),s.type){case"document":s.value=n;break;case"block-scalar":s.props.push(n);break;case"block-map":{let r=s.items[s.items.length-1];if(r.value){s.items.push({start:[],key:n,sep:[]}),this.onKeyLine=!0;return}else if(r.sep)r.value=n;else{Object.assign(r,{key:n,sep:[]}),this.onKeyLine=!r.explicitKey;return}break}case"block-seq":{let r=s.items[s.items.length-1];r.value?s.items.push({start:[],value:n}):r.value=n;break}case"flow-collection":{let r=s.items[s.items.length-1];!r||r.value?s.items.push({start:[],key:n,sep:[]}):r.sep?r.value=n:Object.assign(r,{key:n,sep:[]});return}default:yield*this.pop(),yield*this.pop(n)}if((s.type==="document"||s.type==="block-map"||s.type==="block-seq")&&(n.type==="block-map"||n.type==="block-seq")){let r=n.items[n.items.length-1];r&&!r.sep&&!r.value&&r.start.length>0&&gu(r.start)===-1&&(n.indent===0||r.start.every(o=>o.type!=="comment"||o.indent<n.indent))&&(s.type==="document"?s.end=r.start:s.items.push({start:r.start}),n.items.splice(-1,1))}}}*stream(){switch(this.type){case"directive-line":yield{type:"directive",offset:this.offset,source:this.source};return;case"byte-order-mark":case"space":case"comment":case"newline":yield this.sourceToken;return;case"doc-mode":case"doc-start":{let e={type:"document",offset:this.offset,start:[]};this.type==="doc-start"&&e.start.push(this.sourceToken),this.stack.push(e);return}}yield{type:"error",offset:this.offset,message:`Unexpected ${this.type} token in YAML stream`,source:this.source}}*document(e){if(e.value)return yield*this.lineEnd(e);switch(this.type){case"doc-start":{gu(e.start)!==-1?(yield*this.pop(),yield*this.step()):e.start.push(this.sourceToken);return}case"anchor":case"tag":case"space":case"comment":case"newline":e.start.push(this.sourceToken);return}let n=this.startBlockValue(e);n?this.stack.push(n):yield{type:"error",offset:this.offset,message:`Unexpected ${this.type} token in YAML document`,source:this.source}}*scalar(e){if(this.type==="map-value-ind"){let n=ea(this.peek(2)),s=_r(n),r;e.end?(r=e.end,r.push(this.sourceToken),delete e.end):r=[this.sourceToken];let o={type:"block-map",offset:e.offset,indent:e.indent,items:[{start:s,key:e,sep:r}]};this.onKeyLine=!0,this.stack[this.stack.length-1]=o}else yield*this.lineEnd(e)}*blockScalar(e){switch(this.type){case"space":case"comment":case"newline":e.props.push(this.sourceToken);return;case"scalar":if(e.source=this.source,this.atNewLine=!0,this.indent=0,this.onNewLine){let n=this.source.indexOf(`
|
|
126
126
|
`)+1;for(;n!==0;)this.onNewLine(this.offset+n),n=this.source.indexOf(`
|
|
127
|
-
`,n)+1}yield*this.pop();break;default:yield*this.pop(),yield*this.step()}}*blockMap(e){let n=e.items[e.items.length-1];switch(this.type){case"newline":if(this.onKeyLine=!1,n.value){let s="end"in n.value?n.value.end:void 0;(Array.isArray(s)?s[s.length-1]:void 0)?.type==="comment"?s?.push(this.sourceToken):e.items.push({start:[this.sourceToken]})}else n.sep?n.sep.push(this.sourceToken):n.start.push(this.sourceToken);return;case"space":case"comment":if(n.value)e.items.push({start:[this.sourceToken]});else if(n.sep)n.sep.push(this.sourceToken);else{if(this.atIndentedComment(n.start,e.indent)){let r=e.items[e.items.length-2]?.value?.end;if(Array.isArray(r)){
|
|
127
|
+
`,n)+1}yield*this.pop();break;default:yield*this.pop(),yield*this.step()}}*blockMap(e){let n=e.items[e.items.length-1];switch(this.type){case"newline":if(this.onKeyLine=!1,n.value){let s="end"in n.value?n.value.end:void 0;(Array.isArray(s)?s[s.length-1]:void 0)?.type==="comment"?s?.push(this.sourceToken):e.items.push({start:[this.sourceToken]})}else n.sep?n.sep.push(this.sourceToken):n.start.push(this.sourceToken);return;case"space":case"comment":if(n.value)e.items.push({start:[this.sourceToken]});else if(n.sep)n.sep.push(this.sourceToken);else{if(this.atIndentedComment(n.start,e.indent)){let r=e.items[e.items.length-2]?.value?.end;if(Array.isArray(r)){ta(r,n.start),r.push(this.sourceToken),e.items.pop();return}}n.start.push(this.sourceToken)}return}if(this.indent>=e.indent){let s=!this.onKeyLine&&this.indent===e.indent,r=s&&(n.sep||n.explicitKey)&&this.type!=="seq-item-ind",o=[];if(r&&n.sep&&!n.value){let i=[];for(let a=0;a<n.sep.length;++a){let l=n.sep[a];switch(l.type){case"newline":i.push(a);break;case"space":break;case"comment":l.indent>e.indent&&(i.length=0);break;default:i.length=0}}i.length>=2&&(o=n.sep.splice(i[1]))}switch(this.type){case"anchor":case"tag":r||n.value?(o.push(this.sourceToken),e.items.push({start:o}),this.onKeyLine=!0):n.sep?n.sep.push(this.sourceToken):n.start.push(this.sourceToken);return;case"explicit-key-ind":!n.sep&&!n.explicitKey?(n.start.push(this.sourceToken),n.explicitKey=!0):r||n.value?(o.push(this.sourceToken),e.items.push({start:o,explicitKey:!0})):this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken],explicitKey:!0}]}),this.onKeyLine=!0;return;case"map-value-ind":if(n.explicitKey)if(n.sep)if(n.value)e.items.push({start:[],key:null,sep:[this.sourceToken]});else if(qs(n.sep,"map-value-ind"))this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:o,key:null,sep:[this.sourceToken]}]});else if(yu(n.key)&&!qs(n.sep,"newline")){let i=_r(n.start),a=n.key,l=n.sep;l.push(this.sourceToken),delete n.key,delete n.sep,this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:i,key:a,sep:l}]})}else o.length>0?n.sep=n.sep.concat(o,this.sourceToken):n.sep.push(this.sourceToken);else if(qs(n.start,"newline"))Object.assign(n,{key:null,sep:[this.sourceToken]});else{let i=_r(n.start);this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:i,key:null,sep:[this.sourceToken]}]})}else n.sep?n.value||r?e.items.push({start:o,key:null,sep:[this.sourceToken]}):qs(n.sep,"map-value-ind")?this.stack.push({type:"block-map",offset:this.offset,indent:this.indent,items:[{start:[],key:null,sep:[this.sourceToken]}]}):n.sep.push(this.sourceToken):Object.assign(n,{key:null,sep:[this.sourceToken]});this.onKeyLine=!0;return;case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":{let i=this.flowScalar(this.type);r||n.value?(e.items.push({start:o,key:i,sep:[]}),this.onKeyLine=!0):n.sep?this.stack.push(i):(Object.assign(n,{key:i,sep:[]}),this.onKeyLine=!0);return}default:{let i=this.startBlockValue(e);if(i){if(i.type==="block-seq"){if(!n.explicitKey&&n.sep&&!qs(n.sep,"newline")){yield*this.pop({type:"error",offset:this.offset,message:"Unexpected block-seq-ind on same line with key",source:this.source});return}}else s&&e.items.push({start:o});this.stack.push(i);return}}}}yield*this.pop(),yield*this.step()}*blockSequence(e){let n=e.items[e.items.length-1];switch(this.type){case"newline":if(n.value){let s="end"in n.value?n.value.end:void 0;(Array.isArray(s)?s[s.length-1]:void 0)?.type==="comment"?s?.push(this.sourceToken):e.items.push({start:[this.sourceToken]})}else n.start.push(this.sourceToken);return;case"space":case"comment":if(n.value)e.items.push({start:[this.sourceToken]});else{if(this.atIndentedComment(n.start,e.indent)){let r=e.items[e.items.length-2]?.value?.end;if(Array.isArray(r)){ta(r,n.start),r.push(this.sourceToken),e.items.pop();return}}n.start.push(this.sourceToken)}return;case"anchor":case"tag":if(n.value||this.indent<=e.indent)break;n.start.push(this.sourceToken);return;case"seq-item-ind":if(this.indent!==e.indent)break;n.value||qs(n.start,"seq-item-ind")?e.items.push({start:[this.sourceToken]}):n.start.push(this.sourceToken);return}if(this.indent>e.indent){let s=this.startBlockValue(e);if(s){this.stack.push(s);return}}yield*this.pop(),yield*this.step()}*flowCollection(e){let n=e.items[e.items.length-1];if(this.type==="flow-error-end"){let s;do yield*this.pop(),s=this.peek(1);while(s?.type==="flow-collection")}else if(e.end.length===0){switch(this.type){case"comma":case"explicit-key-ind":!n||n.sep?e.items.push({start:[this.sourceToken]}):n.start.push(this.sourceToken);return;case"map-value-ind":!n||n.value?e.items.push({start:[],key:null,sep:[this.sourceToken]}):n.sep?n.sep.push(this.sourceToken):Object.assign(n,{key:null,sep:[this.sourceToken]});return;case"space":case"comment":case"newline":case"anchor":case"tag":!n||n.value?e.items.push({start:[this.sourceToken]}):n.sep?n.sep.push(this.sourceToken):n.start.push(this.sourceToken);return;case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":{let r=this.flowScalar(this.type);!n||n.value?e.items.push({start:[],key:r,sep:[]}):n.sep?this.stack.push(r):Object.assign(n,{key:r,sep:[]});return}case"flow-map-end":case"flow-seq-end":e.end.push(this.sourceToken);return}let s=this.startBlockValue(e);s?this.stack.push(s):(yield*this.pop(),yield*this.step())}else{let s=this.peek(2);if(s.type==="block-map"&&(this.type==="map-value-ind"&&s.indent===e.indent||this.type==="newline"&&!s.items[s.items.length-1].sep))yield*this.pop(),yield*this.step();else if(this.type==="map-value-ind"&&s.type!=="flow-collection"){let r=ea(s),o=_r(r);bu(e);let i=e.end.splice(1,e.end.length);i.push(this.sourceToken);let a={type:"block-map",offset:e.offset,indent:e.indent,items:[{start:o,key:e,sep:i}]};this.onKeyLine=!0,this.stack[this.stack.length-1]=a}else yield*this.lineEnd(e)}}flowScalar(e){if(this.onNewLine){let n=this.source.indexOf(`
|
|
128
128
|
`)+1;for(;n!==0;)this.onNewLine(this.offset+n),n=this.source.indexOf(`
|
|
129
|
-
`,n)+1}return{type:e,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(e){switch(this.type){case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":return this.flowScalar(this.type);case"block-scalar-header":return{type:"block-scalar",offset:this.offset,indent:this.indent,props:[this.sourceToken],source:""};case"flow-map-start":case"flow-seq-start":return{type:"flow-collection",offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case"seq-item-ind":return{type:"block-seq",offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case"explicit-key-ind":{this.onKeyLine=!0;let n=
|
|
129
|
+
`,n)+1}return{type:e,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(e){switch(this.type){case"alias":case"scalar":case"single-quoted-scalar":case"double-quoted-scalar":return this.flowScalar(this.type);case"block-scalar-header":return{type:"block-scalar",offset:this.offset,indent:this.indent,props:[this.sourceToken],source:""};case"flow-map-start":case"flow-seq-start":return{type:"flow-collection",offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case"seq-item-ind":return{type:"block-seq",offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case"explicit-key-ind":{this.onKeyLine=!0;let n=ea(e),s=_r(n);return s.push(this.sourceToken),{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:s,explicitKey:!0}]}}case"map-value-ind":{this.onKeyLine=!0;let n=ea(e),s=_r(n);return{type:"block-map",offset:this.offset,indent:this.indent,items:[{start:s,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(e,n){return this.type!=="comment"||this.indent<=n?!1:e.every(s=>s.type==="newline"||s.type==="space")}*documentEnd(e){this.type!=="doc-mode"&&(e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type==="newline"&&(yield*this.pop()))}*lineEnd(e){switch(this.type){case"comma":case"doc-start":case"doc-end":case"flow-seq-end":case"flow-map-end":case"map-value-ind":yield*this.pop(),yield*this.step();break;case"newline":this.onKeyLine=!1;default:e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type==="newline"&&(yield*this.pop())}}};function Fp(t){let e=t.prettyErrors!==!1;return{lineCounter:t.lineCounter||e&&new Ts||null,prettyErrors:e}}function ln(t,e={}){let{lineCounter:n,prettyErrors:s}=Fp(e),r=new Fo(n?.addNewLine),o=new Io(e),i=null;for(let a of o.compose(r.parse(t),!0,t.length))if(!i)i=a;else if(i.options.logLevel!=="silent"){i.errors.push(new Xn(a.range.slice(0,2),"MULTIPLE_DOCS","Source contains multiple documents; please use YAML.parseAllDocuments()"));break}return s&&n&&(i.errors.forEach(Wl(t,n)),i.warnings.forEach(Wl(t,n))),i}function jo(t,e,n){let s;typeof e=="function"?s=e:n===void 0&&e&&typeof e=="object"&&(n=e);let r=ln(t,n);if(!r)return null;if(r.warnings.forEach(o=>Li(r.options.logLevel,o)),r.errors.length>0){if(r.options.logLevel!=="silent")throw r.errors[0];r.errors=[]}return r.toJS(Object.assign({reviver:s},n))}function lc(t,e,n){let s=null;if(typeof e=="function"||Array.isArray(e)?s=e:n===void 0&&e&&(n=e),typeof n=="string"&&(n=n.length),typeof n=="number"){let r=Math.round(n);n=r<1?void 0:r>8?{indent:8}:{indent:r}}if(t===void 0){let{keepUndefined:r}=n??e??{};if(!r)return}return Yn(t)&&!s?t.toString(n):new Jn(t,s,n).toString(n)}function na(t){let e=jo(t);for(let n of["light","dark","kinds","roles"])if(!e||typeof e[n]!="object")throw new Error(`theme: missing "${n}"`);return e}function sa(t,e={},n={}){let s={...t.kinds};for(let[r,o]of Object.entries(n)){let i=s[o.like??r]??s.control;s[r]={color:o.color??i.color,dash:o.dash??i.dash,legend:o.legend??i.legend}}return{...t,roles:{...t.roles,...e},kinds:s}}var xu=t=>Object.entries(t).map(([e,n])=>`--${e}:${n}`).join(";");function us(t,e){return e in t.light?`var(--${e})`:e}function ra(t){let{light:e,dark:n,rest:s}=cc(t);return`:root{${e}}
|
|
130
130
|
@media (prefers-color-scheme: dark){:root:not([data-theme="light"]){${n}}}
|
|
131
131
|
:root[data-theme="dark"]{${n}}
|
|
132
|
-
${s}`}function
|
|
133
|
-
`;for(let[n,s]of Object.entries(t.kinds)){let r=
|
|
134
|
-
`}return{light:
|
|
135
|
-
`)),this.diags=e}};function
|
|
132
|
+
${s}`}function cc(t){let e="";for(let[n,s]of Object.entries(t.roles))e+=`.k-${n}{--h:${s.h};--s:${s.s}%}`,s.top?e+=`.k-${n} .top{fill:${s.top}}`:s.tint&&(e+=`.k-${n} .top{fill:color-mix(in srgb,hsl(${s.h} ${Math.min(100,s.s+15)}% 50%) ${s.tint}%,var(--pad-top))}`),e+=`
|
|
133
|
+
`;for(let[n,s]of Object.entries(t.kinds)){let r=us(t,s.color),o=s.dash==="dashed"?";stroke-dasharray:7 6;stroke-width:2.4":s.dash==="dotted"?";stroke-dasharray:3 6;stroke-width:2.4":"";e+=`.f-${n}{stroke:${r}${o}} .t-${n}{fill:${r}} .c-${n}{--c:${r}}
|
|
134
|
+
`}return{light:xu(t.light),dark:xu(t.dark),rest:e}}var oa=class extends Error{diags;constructor(e){super(e.map(n=>`${n.line}:${n.col} ${n.message}`).join(`
|
|
135
|
+
`)),this.diags=e}};function dc(t,e){let n=t.length,s=e.length;if(!n)return s;if(!s)return n;let r=Array.from({length:n+1},(o,i)=>[i,...Array(s).fill(0)]);for(let o=0;o<=s;o++)r[0][o]=o;for(let o=1;o<=n;o++)for(let i=1;i<=s;i++){let a=t[o-1]===e[i-1]?0:1;r[o][i]=Math.min(r[o-1][i]+1,r[o][i-1]+1,r[o-1][i-1]+a),o>1&&i>1&&t[o-1]===e[i-2]&&t[o-2]===e[i-1]&&(r[o][i]=Math.min(r[o][i],r[o-2][i-2]+1))}return r[n][s]}function Us(t,e){let n,s=1/0,r=t.toLowerCase();for(let i of e){let a=dc(r,i.toLowerCase());a<s&&(s=a,n=i)}if(n===void 0)return;let o=Math.max(1,Math.min(3,Math.floor(Math.max(t.length,n.length)/3)));return s<=o?n:void 0}function uc(t,e,n){t.file&&(e=t.file,n=t.source);let r=`${t.line?`${e}:${t.line}:${t.col}`:e} ${t.severity}: ${t.message}`;if(t.hint&&(r+=`
|
|
136
136
|
${t.hint}`),n&&t.line){let i=n.split(/\r?\n/)[t.line-1]??"",a=String(t.line).padStart(4);r+=`
|
|
137
137
|
${a} | ${i}
|
|
138
|
-
${" ".repeat(a.length)} | ${" ".repeat(Math.max(0,t.col-1))}^`}return r}function
|
|
138
|
+
${" ".repeat(a.length)} | ${" ".repeat(Math.max(0,t.col-1))}^`}return r}function wu(t,e,n){return t.map(s=>uc(s,e,n)).join(`
|
|
139
139
|
|
|
140
|
-
`)}function
|
|
140
|
+
`)}function vu(t){return t.split("/").slice(1).map(e=>{let n=e.replace(/~1/g,"/").replace(/~0/g,"~");return/^\d+$/.test(n)?Number(n):n})}function ku(t){let e=new Ts,n=ln(t,{lineCounter:e,prettyErrors:!1,uniqueKeys:!0}),s=[],r=l=>{let c=e.linePos(l);return{line:c.line,col:c.col}};for(let l of n.errors){let c=r(l.pos[0]),d=l.message.split(`
|
|
141
141
|
`)[0],u=/Nested mappings|Implicit keys|mapping values/i.test(d)?`text that contains ": " (a colon followed by a blank) must be in quotes, e.g. command: 'send "a: b"'`:/Map keys must be unique/i.test(d)?"a key is written twice in the same map":void 0;s.push({severity:"error",message:`YAML: ${d}`,line:c.line,col:c.col,path:"",hint:u})}for(let l of n.warnings){let c=r(l.pos[0]);s.push({severity:"warning",message:`YAML: ${l.message.split(`
|
|
142
|
-
`)[0]}`,line:c.line,col:c.col,path:""})}function o(l,c={}){let d=Xd(l),u=n.contents,f={line:1,col:1},p=g=>{let h=g?.range;h&&(f=r(h[0]))};p(u);for(let g=0;g<d.length;g++){let h=d[g];if(lt(u)){let b=u.items.find(k=>tt(k)&&He(k.key)&&String(k.key.value)===String(h));if(!b)break;if(c.key&&g===d.length-1)return p(b.key),f;p(b.key),u=b.value,u&&p(u)}else if(At(u)&&typeof h=="number"){if(u=u.items[h],!u)break;p(u)}else break}return f}function i(l){let c=n.contents;for(let p of Xd(l)){if(lt(c)){let g=c.items.find(h=>tt(h)&&He(h.key)&&String(h.key.value)===String(p));if(!g)return;c=g.value}else if(At(c)&&typeof p=="number")c=c.items[p];else return;if(!c)return}let d=c.range;if(!d)return;let u=e.linePos(Math.max(d[0],d[1]-1)).line,f=t.split(/\r?\n/);for(;u>e.linePos(d[0]).line&&/^\s*(#.*)?$/.test(f[u-1]??"");)u--;return{start:e.linePos(d[0]).line,end:u}}let a=null;return n.errors.length||(a=n.toJS({maxAliasCount:100})),{data:a,locate:o,span:i,diags:s}}var mp=new Set(["svg","g","defs","marker","symbol","title","desc","path","polygon","polyline","line","rect","circle","ellipse","text","tspan","linearGradient","radialGradient","stop","clipPath"]),hp=new Set(["id","class","role","transform","viewBox","width","height","x","y","x1","y1","x2","y2","cx","cy","r","rx","ry","fx","fy","d","points","offset","gradientUnits","gradientTransform","markerWidth","markerHeight","refX","refY","orient","markerUnits","text-anchor","dominant-baseline","font-size","font-weight","letter-spacing","fill","stroke","stroke-width","stroke-dasharray","stroke-linecap","stroke-linejoin","opacity","fill-opacity","stroke-opacity","stop-color","stop-opacity","marker-start","marker-mid","marker-end","clip-path","preserveAspectRatio","vector-effect","paint-order","style"]),gp=new Set(["fill","stroke","marker-start","marker-mid","marker-end","clip-path","style"]),bp={amp:"&",lt:"<",gt:">",quot:'"',apos:"'","#39":"'"},Zd=t=>t.replace(/&(amp|lt|gt|quot|apos|#39);/g,(e,n)=>bp[n]);function Yl(t,e){return t.startsWith("data-")||t.startsWith("aria-")?/^[a-z][\w-]*$/.test(t):!(!hp.has(t)||gp.has(t)&&/url\(\s*(?!['"]?#)|javascript:|expression\(|@import/i.test(e))}function ql(t){let e={name:"#root",attrs:[],children:[]},n=[{node:e,dropped:!1}],s=/<(?:!--)[\s\S]*?-->|<\/([a-zA-Z][\w:-]*)\s*>|<([a-zA-Z][\w:-]*)((?:\s+[\w:-]+="[^"]*")*)\s*(\/?)>|([^<]+)/g,r,o=0;for(;r=s.exec(t);){if(r.index!==o)throw new Error(`not the renderer's SVG at ${o}: ${JSON.stringify(t.slice(o,o+40))}`);o=s.lastIndex;let i=n[n.length-1];if(r[0].charAt(1)!=="!"){if(r[1]){if(n.length<2||i.node.name!==r[1])throw new Error(`a stray </${r[1]}>`);n.pop();continue}if(r[2]){let a=r[2],l=[];for(let u of r[3].matchAll(/([\w:-]+)="([^"]*)"/g)){let f=u[1],p=Zd(u[2]);f==="xmlns"||f.startsWith("xmlns:")||Yl(f,p)&&l.push([f,p])}let c={name:a,attrs:l,children:[]},d=i.dropped||!mp.has(a);d||i.node.children.push(c),r[4]||n.push({node:c,dropped:d});continue}!i.dropped&&r[5].trim()&&i.node.children.push(Zd(r[5]))}}if(o!==t.length)throw new Error(`not the renderer's SVG at ${o}`);if(n.length!==1)throw new Error(`<${n[n.length-1].node.name}> is never closed`);return e}var yp="http://www.w3.org/2000/svg",eu=t=>t.replace(/var\(--([a-zA-Z][\w-]*)/g,"var(--iso-$1");function To(t,e=document){let n=r=>{let o=e.createElementNS(yp,r.name);for(let[i,a]of r.attrs)i==="style"?o.style.cssText=eu(a):o.setAttribute(i,/var\(--/.test(a)?eu(a):a);for(let i of r.children)o.append(typeof i=="string"?e.createTextNode(i):n(i));return o},s=ql(t).children.find(r=>typeof r!="string"&&r.name==="svg");if(!s)throw new Error("the drawing has no <svg>");return n(s)}var xp=t=>t.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`),Ao=class t{name;attrs=[];children=[];style={};constructor(e){this.name=e}setAttribute(e,n){let s=this.attrs.findIndex(r=>r[0]===e);s>=0?this.attrs[s][1]=String(n):this.attrs.push([e,String(n)])}getAttribute(e){return this.attrs.find(n=>n[0]===e)?.[1]??null}append(...e){for(let n of e)n!=null&&this.children.push(n)}set textContent(e){this.children=[String(e)]}get textContent(){return this.children.map(e=>typeof e=="string"?e:e.textContent).join("")}toNode(){let e=Object.entries(this.style).filter(([,n])=>n!==""&&n!==void 0).map(([n,s])=>`${xp(n)}:${s}`).join(";");return{name:this.name,attrs:e?[...this.attrs,["style",e]]:[...this.attrs],children:this.children.map(n=>n instanceof t?n.toNode():n)}}},tu={createElementNS:(t,e)=>new Ao(e)},nu=t=>t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"),wp=t=>nu(t).replace(/"/g,""");function Vi(t,e=new Set(["style"])){if(typeof t=="string")return nu(t);let n=t.attrs.map(([r,o])=>` ${r}="${wp(o)}"`).join("");if(!t.children.length)return`<${t.name}${n}/>`;let s=e.has(t.name)?t.children.map(r=>typeof r=="string"?r.replace(/<\//g,"<\\/"):Vi(r,e)).join(""):t.children.map(r=>Vi(r,e)).join("");return`<${t.name}${n}>${s}</${t.name}>`}var vp=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function Ul(t){let e=new TextEncoder().encode(t),n=e.length,s=Math.ceil((n+9)/64),r=new Uint8Array(s*64);r.set(e),r[n]=128;let o=new DataView(r.buffer);o.setUint32(r.length-4,n*8>>>0),o.setUint32(r.length-8,Math.floor(n/536870912));let i=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),a=new Uint32Array(64),l=(c,d)=>c>>>d|c<<32-d;for(let c=0;c<s;c++){for(let v=0;v<16;v++)a[v]=o.getUint32(c*64+v*4);for(let v=16;v<64;v++){let M=l(a[v-15],7)^l(a[v-15],18)^a[v-15]>>>3,x=l(a[v-2],17)^l(a[v-2],19)^a[v-2]>>>10;a[v]=a[v-16]+M+a[v-7]+x>>>0}let[d,u,f,p,g,h,b,k]=i;for(let v=0;v<64;v++){let M=k+(l(g,6)^l(g,11)^l(g,25))+(g&h^~g&b)+vp[v]+a[v]>>>0,x=(l(d,2)^l(d,13)^l(d,22))+(d&u^d&f^u&f)>>>0;k=b,b=h,h=g,g=p+M>>>0,p=f,f=u,u=d,d=M+x>>>0}i[0]+=d,i[1]+=u,i[2]+=f,i[3]+=p,i[4]+=g,i[5]+=h,i[6]+=b,i[7]+=k}return[...i].map(c=>c.toString(16).padStart(8,"0")).join("")}function su(t){if(t!=="sha256")throw new Error(`only sha256 here, not ${t}`);let e="",n={update(s){return e+=s,n},digest(s){return Ul(e)}};return n}var Mu={};Qo(Mu,{BOARD_3D:()=>js,BOARD_CSS:()=>vu,FLAT_DEFAULTS:()=>bc,FLAT_FONTS:()=>yc,GRID_CSS:()=>mc,LABEL_BUDGET:()=>ma,MARKS_CSS:()=>fc,Obstacles:()=>sr,PAGE_CSS:()=>dc,PLAYER_CSS:()=>ya,PLAYER_UI_CSS:()=>pc,ROUTE_BUDGET:()=>na,WALL_T:()=>es,assembly:()=>da,baseCss:()=>ba,boardCatalog:()=>ku,boardDiagram:()=>Su,boardErrors:()=>wa,boardOf:()=>or,boxAsset:()=>iu,boxSilhouette:()=>xa,calloutRect:()=>ic,cardAsset:()=>xc,cloudPath:()=>Zl,compileRaw:()=>yu,convexOverlap:()=>Lo,defaultLabel:()=>lu,drawCloud:()=>Ui,drawDecos:()=>Ql,drawingCss:()=>uc,durationFor:()=>lc,facePainter:()=>qi,flatHit:()=>wu,floorAt:()=>Cr,floorOf:()=>Ir,focusView:()=>bu,gateBox:()=>Co,iconPainter:()=>Po,inConvex:()=>ac,kindsCss:()=>Hi,labelRect:()=>Ro,layoutFlat:()=>Fs,lineRectArea:()=>mu,localAt:()=>Rr,markCss:()=>Yi,metricsMeasure:()=>xu,midpoint:()=>cc,noSource:()=>hc,nodeKind:()=>nr,nodeKindOr:()=>Tn,offscreen:()=>ca,openList:()=>nc,overlap2:()=>Ji,overlaps:()=>rr,paddingOf:()=>Do,parseEnd:()=>wn,place:()=>Xi,placeBoard:()=>jo,placeCallout:()=>aa,placeNodeLabel:()=>Io,placeholderIcon:()=>Xl,plate:()=>au,polyBounds:()=>xs,polyRectArea:()=>Lr,rectArea:()=>oc,regionKind:()=>Ft,regionRole:()=>ha,registerMarks:()=>ou,renderScene:()=>ga,resolveSteps:()=>ua,routeAll:()=>sa,screenToGrid:()=>ws,silhouette:()=>vn,simplify:()=>No,snapMove:()=>Fo,wallHeight:()=>Gi,wallsOf:()=>pa});var Ft=(t,e)=>e!==void 0&&Object.hasOwn(t.regions,e)?t.regions[e]:void 0,nr=(t,e)=>t.nodes[e??t.defaultNode],Tn=(t,e)=>nr(t,e)??t.nodes[t.defaultNode],Gi=t=>Object.values(t.regions).find(e=>e.shape==="walled")?.z[1]??.8,Hi=t=>Object.values(t.regions).map(e=>e.css??"").join("");var Wl=Object.create(null),Jl=[];function ou(t){Object.assign(Wl,t.icons??{}),Object.assign(xr,t.faces??{}),t.css&&!Jl.includes(t.css)&&Jl.push(t.css)}var Yi=()=>Jl.join(""),Po=t=>Object.hasOwn(Wl,t)?Wl[t]:void 0,qi=t=>Object.hasOwn(xr,t)?xr[t]:void 0;function Xl(t,e){let n=(e.x0+e.x1)/2,s=(e.y0+e.y1)/2,r=e.z1+.005,o=Math.min(.6,(e.x1-e.x0)*.24,(e.y1-e.y0)*.24),i=[[n-o,s-o,r],[n+o,s-o,r],[n+o,s+o,r],[n-o,s+o,r]];return t.poly(i,"ico-unknown")+t.line3([n-o*.3,s-o*.35,r],[n+o*.3,s-o*.35,r],"ico-unknown-q")+t.line3([n+o*.3,s-o*.35,r],[n,s+o*.1,r],"ico-unknown-q")+t.line3([n,s+o*.45,r],[n,s+o*.5,r],"ico-unknown-q")}function Ql(t,e,n){let s="";for(let r of n??[])r==="terminal"?s+=oo(t,e,3):r==="envelope"?s+=ei(t,e):r==="bubble"?s+=ti(t,e):r==="file-lines"?s+=ni(t,e):typeof r=="object"&&(r.terminal&&(s+=oo(t,e,r.terminal)),r.icon&&(s+=(Po(r.icon)??Xl)(t,e)));return s}var kp=(t,e)=>(t.deco??e.deco??[]).filter(n=>n!=="ghost");function iu(t,e,n,s,r,o){let i={name:t,description:e,size:n,role:s,deco:r,draw:(a,l,c)=>a.blockFaces(l)+Ql(a,l,kp(c,i))+(o?o(a,l):"")};return i}function au(t){let[e,n]=Zo(t);return{x0:e-.75,y0:n-.75,x1:e+.75,y1:n+.75,z0:t.z0,z1:t.z0+.18}}function Zl(t,e){let n=Math.max(8,Math.min(t,e)*.18),s=n*.55,r=s,o=s,i=t-s,a=e-s,l=(c,d,u,f)=>{let p=Math.hypot(u-c,f-d),g=Math.max(1,Math.round(p/(n*1.7))),h="";for(let b=1;b<=g;b++){let k=c+(u-c)*b/g,v=d+(f-d)*b/g,M=p/g/2*1.08;h+=` A${M.toFixed(1)},${M.toFixed(1)} 0 0 1 ${k.toFixed(1)},${v.toFixed(1)}`}return h};return`M${r.toFixed(1)},${o.toFixed(1)}`+l(r,o,i,o)+l(i,o,i,a)+l(i,a,r,a)+l(r,a,r,o)+"Z"}function Ui(t,e){let n={...e,z0:e.z1},s=a=>{let[l,c]=Xe(e.x0,e.y0,a);return[It,.5,-It,.5,l,c]},r=(e.x1-e.x0)*xt,o=(e.y1-e.y0)*xt,i=Zl(r,o);return t.onMatrix(s(e.z0),r,o,()=>Ve("path",{d:i,class:"lft cloud-side"}))+t.onMatrix(s(e.z1),r,o,()=>Ve("path",{d:i,class:"top cloud-top"}))}function lu(t,e){let[n,s]=Xe((t.x0+t.x1)/2,(t.y0+t.y1)/2,t.z1+.75);return{x:n,y:s-18+(e?0:6),anchor:"middle"}}var es=.16,ec=["right-of","left-of","below","behind"];function Xi(t,e,n,s,r,o={},i){let a=[],l=(S,$,w,N=!1,F="error")=>{let J=n.locate(S,{key:N});a.push({severity:F,message:$,line:J.line,col:J.col,path:S,hint:w})},c=[],d=new Map,u=[],f=new Map,p=new Set([...Object.keys(s.roles),...Object.keys(o)]);function g(S,$){let w=d.get(S.id);if(w){let N=n.locate(w.path+"/id");return l(S.path+"/id",`duplicate id "${S.id}" (first used on line ${N.line})`),!1}return d.set(S.id,S),c.push(S),S.parent=$,$?$.children.push(S):u.push(S),!0}let h=()=>({x0:0,y0:0,z0:0,x1:0,y1:0,z1:0});function b(S,$,w){let N={id:S.id,type:"node",path:$,children:[],box:h(),floor:0,node:S,appears:S.appears,disappears:S.disappears};g(N,w)&&(S.nodes??[]).forEach((F,J)=>b(F,`${$}/nodes/${J}`,N))}function k(S,$,w){let N={id:S.id,type:"region",path:$,children:[],box:h(),floor:0,region:S,appears:S.appears,disappears:S.disappears};g(N,w)&&((S.nodes??[]).forEach((F,J)=>b(F,`${$}/nodes/${J}`,N)),(S.regions??[]).forEach((F,J)=>k(F,`${$}/regions/${J}`,N)))}(t.regions??[]).forEach((S,$)=>k(S,`${e}/regions/${$}`,void 0)),(t.nodes??[]).forEach((S,$)=>b(S,`${e}/nodes/${$}`,void 0));let v=()=>d.keys(),M=()=>c.filter(S=>S.type==="region").map(S=>S.id);for(let S of[...c]){let $=S.node??S.region;if($.in!==void 0){let N=d.get($.in);if(!N){l(S.path+"/in",`unknown region "${$.in}"`+Oo($.in,M()));continue}if(N.type!=="region"){l(S.path+"/in",`"${$.in}" is a node, not a region; put nodes on a node with its own "nodes:" list`);continue}if(S.parent&&S.parent!==N){l(S.path+"/in",`"${S.id}" is written inside "${S.parent.id}" but says in: ${$.in}; use one or the other`);continue}for(let F=N;F;F=F.parent)if(F===S){l(S.path+"/in",`"${S.id}" cannot be inside itself`);continue}S.parent||(u.splice(u.indexOf(S),1),S.parent=N,N.children.push(S))}if(S.node){let N=S.node.asset;N!==void 0&&!nr(r,N)&&l(S.path+"/asset",`unknown asset "${N}"`+Oo(N,Object.keys(r.nodes)),`assets: ${Object.keys(r.nodes).join(", ")}`)}let w=(S.node??S.region).role;w!==void 0&&!p.has(w)&&l(S.path+"/role",`unknown colour role "${w}"`+Oo(w,p),`add it under "roles:" at the top of the file, or use one of: ${[...p].join(", ")}`)}for(let S of c){let $=S.region?.gate;if(!$?.node)continue;let w=d.get($.node);if(!w){l(S.path+"/gate/node",`unknown node "${$.node}"`+Oo($.node,v()));continue}if(w.type!=="node"){l(S.path+"/gate/node",`"${$.node}" is a region; a gate is a node`);continue}w.placedBy=S.id;let N=w.node;(N.at||ec.some(F=>N[F]))&&l(w.path,`"${w.id}" is the gate of "${S.id}", which places it; its own placement is ignored`,void 0,!1,"warning")}let x=S=>S.gap??t.gap??2;function T(S){let $=S.node,w=Tn(r,$.asset),N=$.size,F=w.size[0],J=w.size[1],ae=w.size[2];if(N&&(F=N[0],J=N[1],N.length>2&&(ae=N[2])),S.placedBy){let we=d.get(S.placedBy).region,j=we.gate,U=j.width??2,ee=N?Math.min(F,J):.3;ae=N&&N.length>2?ae:j.height??(we.height??Gi(r))+.3,j.side==="e"||j.side==="w"?(F=ee,J=U):(F=U,J=ee)}return[F,J,ae]}function y(S,$,w,N,F){for(let ye of $)D(ye);let J=$.filter(ye=>!ye.placedBy),ae=new Set(J),we=new Set,j=[],U=new Set,ee=ye=>{let xe=ye.node??ye.region,Re=[];for(let Ue of ec){let I=xe[Ue];if(I===void 0)continue;let re=d.get(I);if(!re){l(`${ye.path}/${Ue}`,`unknown id "${I}"`+Oo(I,v()));continue}if(re===ye){l(`${ye.path}/${Ue}`,`"${ye.id}" cannot be placed ${Ue} itself`);continue}if(!ae.has(re)){let $e=Pe=>Pe.parent?`"${Pe.parent.id}"`:"the scene";l(`${ye.path}/${Ue}`,`"${I}" is in ${$e(re)} but "${ye.id}" is in ${$e(ye)}; relative placement works between items in the same region`,re.placedBy?`"${I}" is a gate, placed by its ${d.get(re.placedBy)?.region?.kind??"region"}`:`place "${ye.id}" relative to something in ${$e(ye)}, or use "at:"`);continue}Re.push(re)}if(!Re.length&&!xe.at){let Ue=J.indexOf(ye);Ue>0&&Re.push(J[Ue-1])}return Re},fe=ye=>{if(!we.has(ye)){if(U.has(ye)){l(ye.path,`placement loop: "${ye.id}" is placed relative to something placed relative to it`);return}U.add(ye),ee(ye).forEach(fe),U.delete(ye),we.add(ye),j.push(ye)}};J.forEach(fe);for(let ye of j){let xe=ye.node??ye.region,Re=f.get(ye),Ue=ec.find(I=>xe[I]!==void 0&&d.get(xe[I])&&ae.has(d.get(xe[I])));if(xe.at&&Ue&&l(`${ye.path}/at`,`"${ye.id}" has both "at" and "${Ue}"; "at" wins`,void 0,!0,"warning"),xe.at)Re.x=xe.at[0],Re.y=xe.at[1];else if(Ue)A(Re,f.get(d.get(xe[Ue])),Ue,x(xe),xe.align??"center");else{let I=J.indexOf(ye);I>0?A(Re,f.get(J[I-1]),N==="row"?"right-of":"below",x(xe),"center"):(Re.x=w,Re.y=w)}xe.shift&&(Re.x+=xe.shift[0],Re.y+=xe.shift[1])}if(F||!J.length)return{w:0,d:0};let B=1/0,X=1/0,Q=-1/0,te=-1/0;for(let ye of J){let xe=f.get(ye);B=Math.min(B,xe.x),X=Math.min(X,xe.y),Q=Math.max(Q,xe.x+xe.w),te=Math.max(te,xe.y+xe.d)}let ne=Math.min(0,B-w),me=Math.min(0,X-w);if(ne||me)for(let ye of J){let xe=f.get(ye);xe.x-=ne,xe.y-=me}return{w:Q-ne+w,d:te-me+w}}function A(S,$,w,N,F){let J=()=>{S.y=F==="start"?$.y:F==="end"?$.y+$.d-S.d:$.y+($.d-S.d)/2},ae=()=>{S.x=F==="start"?$.x:F==="end"?$.x+$.w-S.w:$.x+($.w-S.w)/2};w==="right-of"?(S.x=$.x+$.w+N,J()):w==="left-of"?(S.x=$.x-N-S.w,J()):w==="below"?(S.y=$.y+$.d+N,ae()):(S.y=$.y-N-S.d,ae())}function D(S){if(S.type==="node"){let[j,U,ee]=T(S);f.set(S,{x:0,y:0,w:j,d:U,h:ee,z:S.node.z??0}),S.children.length&&y(S,S.children,0,"row",!0);return}let $=S.region,w=$.padding??Ft(r,$.kind)?.pad,N=!!$.size,F=y(S,S.children,w,$.flow??"row",N),J=$.size?$.size[0]:Math.max(F.w,w*2+.5),ae=$.size?$.size[1]:Math.max(F.d,w*2+.5);if(!$.size&&$.gate){let j=($.gate.width??2)+1;$.gate.side==="e"||$.gate.side==="w"?ae=Math.max(ae,j):J=Math.max(J,j)}let we=$.size&&$.size.length>2?$.size[2]:$.height??Ft(r,$.kind).z[1];f.set(S,{x:0,y:0,w:J,d:ae,h:we,z:0})}y(void 0,u,0,t.flow??"row",!0);function K(S,$,w,N){let F=f.get(S),J=$+F.x,ae=w+F.y;if(S.type==="region"){let we=Ft(r,S.region.kind),[j]=we.z,U=we.floor,ee=we.shape==="slab"&&Ft(r,S.parent?.region?.kind)?.shape==="slab"?0:j,fe=S.region.z??0,B=N+ee+fe,X=N+F.h+fe;S.box={x0:J,y0:ae,z0:B,x1:J+F.w,y1:ae+F.d,z1:X},S.floor=U?X:N}else{let we=N+F.z;S.box={x0:J,y0:ae,z0:we,x1:J+F.w,y1:ae+F.d,z1:we+F.h},S.floor=S.box.z1}for(let we of S.children)we.placedBy||K(we,J,ae,S.floor)}for(let S of u)S.placedBy||K(S,0,0,0);if(i){let S=w=>Math.round(w/i)*i,$=w=>Math.round(w*1e9)/1e9;for(let w of c){if(w.placedBy)continue;let N=w.box,F=S(N.x0),J=S(N.x1),ae=S(N.y0),we=S(N.y1);J-F<i&&(J=F+i),we-ae<i&&(we=ae+i),w.box={...N,x0:$(F),x1:$(J),y0:$(ae),y1:$(we)};let j=w.node??w.region;j.at&&j.at.forEach((U,ee)=>{let fe=U/i;Math.abs(fe-Math.round(fe))>1e-6&&l(`${w.path}/at/${ee}`,`${U} is not on the ${i} grid; it is drawn at ${$(S(U))}`,void 0,!1,"warning")})}}for(let S of c){let $=S.region?.gate;if(!$?.node)continue;let w=d.get($.node);!w||w.placedBy!==S.id||(w.box=Co(S,f.get(w).h,f.get(w).w,f.get(w).d),w.floor=w.box.z1)}for(let S of c){let $=S.children.filter(w=>!w.placedBy);for(let w=0;w<$.length;w++)for(let N=w+1;N<$.length;N++){let F=$[w],J=$[N];Wi(F,r)||Wi(J,r)||Ji(F.box,J.box)&&l(J.path,`"${J.id}" overlaps "${F.id}"`,'move one with "at", a relative placement, "gap" or "shift"',!1,"warning")}if(S.parent&&S.parent.type==="region"&&!S.placedBy){let w=S.parent.box,N=S.box,F=1e-6;(N.x0<w.x0-F||N.y0<w.y0-F||N.x1>w.x1+F||N.y1>w.y1+F)&&l(S.path,`"${S.id}" sticks out of region "${S.parent.id}"`,`make "${S.parent.id}" bigger, or leave out its "size" so it fits its contents`,!1,"warning")}}{let S=u.filter($=>!$.placedBy);for(let $=0;$<S.length;$++)for(let w=$+1;w<S.length;w++){let N=S[$],F=S[w];Ji(N.box,F.box)&&!Wi(N,r)&&!Wi(F,r)&&l(F.path,`"${F.id}" overlaps "${N.id}"`,'move one with "at", a relative placement, "gap" or "shift"',!1,"warning")}}let C=new Set,_=a.filter(S=>{let $=S.path+S.message;return C.has($)?!1:(C.add($),!0)});return{items:c,byId:d,roots:u,diags:_,catalog:r}}var Wi=(t,e)=>t.type==="region"&&["zone","tunnel"].includes(Ft(e,t.region.kind)?.shape??"");function Co(t,e,n,s){let r=t.region.gate,o=t.box,i=t.box.z0,a=r.at??.5,l=r.width??2;if(r.side==="w"||r.side==="e"){let u=r.side==="w"?o.x0+es/2:o.x1-es/2,f=o.y0+(o.y1-o.y0)*a;return{x0:u-n/2,x1:u+n/2,y0:f-l/2,y1:f+l/2,z0:i,z1:i+e}}let c=r.side==="n"?o.y0+es/2:o.y1-es/2,d=o.x0+(o.x1-o.x0)*a;return{x0:d-l/2,x1:d+l/2,y0:c-s/2,y1:c+s/2,z0:i,z1:i+e}}function Ji(t,e,n=1e-6){return t.x0<e.x1-n&&e.x0<t.x1-n&&t.y0<e.y1-n&&e.y0<t.y1-n}function Oo(t,e){let n=Is(t,e);return n?` (did you mean "${n}"?)`:""}var bs=.2,Qi=.05,Sp=.6,Zi=.25,ea={n:[0,-1],s:[0,1],e:[1,0],w:[-1,0]};function wn(t){let e=/^(.*?)(?:\.(n|e|s|w|top))?$/.exec(t);return{id:e[1],side:e[2]}}var cu=new WeakMap;function Cr(t,e,n){let s=cu.get(t);if(!s){s=[];for(let i of t.items){if(i.type!=="region"||!Ft(t.catalog,i.region.kind)?.floor)continue;let a=0;for(let l=i.parent;l;l=l.parent)a++;s.push({r:i,d:a})}cu.set(t,s)}let r=0,o=-1;for(let{r:i,d:a}of s){let l=i.box,c=1e-6;e>=l.x0-c&&e<=l.x1+c&&n>=l.y0-c&&n<=l.y1+c&&a>o&&(o=a,r=i.floor)}return r}function Mp(t,e){let n=[(t.x0+t.x1)/2,(t.y0+t.y1)/2],s=[(e.x0+e.x1)/2,(e.y0+e.y1)/2],r=s[0]-n[0],o=s[1]-n[1],i=Math.max(e.x0-t.x1,t.x0-e.x1),a=Math.max(e.y0-t.y1,t.y0-e.y1);return i>0&&(a<=0||i>=a)?r>0?"e":"w":a>0?o>0?"s":"n":Math.abs(r)>=Math.abs(o)?r>0?"e":"w":o>0?"s":"n"}var na=5e5;function sa(t,e,n,s,r,o){let i=[],a=(M,x,T,y="error")=>{let A=s.locate(M);i.push({severity:y,message:x,line:A.line,col:A.col,path:M,hint:T})},l=t.routes??[],c={left:na},d=0,u=()=>n.items.map(M=>M.id),f=new Map,p=[],g=[];l.forEach((M,x)=>{let T=`${e}/routes/${x}`;(f.has(M.id)||n.byId.has(M.id))&&a(T+"/id",`duplicate id "${M.id}"`),f.set(M.id,x);let y=M.kind??"send";r.has(y)||a(T+"/kind",`unknown flow kind "${y}"`+tc(y,r),`kinds: ${[...r].join(", ")}; add one under "kinds:"`);let A={id:M.id,raw:M,path:T,kind:y,points:[]},D=(K,C)=>{let{id:_}=wn(K),S=n.byId.get(_);if(!S){a(`${T}/${C}`,`unknown node "${_}"`+tc(_,u()));return}return S};A.from=D(M.from,"from"),A.to=D(M.to,"to"),p.push(A),g.push({r:A})});let h=new Map;for(let M of g){let{r:x}=M;if(!x.from||!x.to||x.raw.points)continue;let T=wn(x.raw.from).side,y=wn(x.raw.to).side,A=x.raw.via?.[0],D=x.raw.via?.[x.raw.via.length-1],K=($,w)=>{if(Array.isArray($))return{x0:$[0],x1:$[0],y0:$[1],y1:$[1],z0:0,z1:0};if(typeof $=="string"){let N=n.byId.get(wn($).id);if(N)return N.box}return w.box},C=($,w,N)=>{let F=w??Mp($.box,N);return{node:$,side:F,explicit:!!w,p:[0,0],z:0}};M.a=C(x.from,T,K(A,x.to)),M.b=C(x.to,y,K(D,x.from));let _=K(A,x.to),S=K(D,x.from);for(let[$,w]of[[M.a,_],[M.b,S]]){let N=`${$.node.id}.${$.side}`;h.has(N)||h.set(N,[]),h.get(N).push({e:$,other:[(w.x0+w.x1)/2,(w.y0+w.y1)/2]})}}for(let[,M]of h){let x=M[0].e,T=x.node.box,y=x.side,A=y==="e"||y==="w"?1:0;M.sort(($,w)=>$.other[A]-w.other[A]);let D=A?T.y0:T.x0,K=A?T.y1:T.x1,C=(D+K)/2,_=Math.max(0,K-D-.3),S=M.length>1?Math.min(Sp,_/(M.length-1)):0;M.forEach(($,w)=>{let N=(w-(M.length-1)/2)*S,F=C+N,J=$.e.node.box.z0;if(y==="top"){$.e.p=[(T.x0+T.x1)/2,(T.y0+T.y1)/2],$.e.z=T.z1;return}let[ae,we]=ea[y];$.e.p=A?[ae>0?T.x1+Qi:T.x0-Qi,F]:[F,we>0?T.y1+Qi:T.y0-Qi],$.e.z=J})}let b=[];for(let M of n.items)M.type==="node"&&b.push(M.box);let k=[];for(let M of n.items.filter(x=>Ft(n.catalog,x.region?.kind)?.shape==="walled")){let{x0:x,y0:T,x1:y,y1:A}=M.box,D=es,K=M.region.gate,C=[[{x0:x,y0:T,x1:y,y1:T+D,z0:0,z1:0},"n"],[{x0:x,y0:A-D,x1:y,y1:A,z0:0,z1:0},"s"],[{x0:x,y0:T,x1:x+D,y1:A,z0:0,z1:0},"w"],[{x0:y-D,y0:T,x1:y,y1:A,z0:0,z1:0},"e"]];for(let[_,S]of C)if(K&&K.side===S){if(K.node)continue;let $=K.at??.5,w=K.width??2;if(S==="e"||S==="w"){let N=T+(A-T)*$;k.push({..._,y1:N-w/2},{..._,y0:N+w/2})}else{let N=x+(y-x)*$;k.push({..._,x1:N-w/2},{..._,x0:N+w/2})}}else k.push(_)}let v=new Map;for(let M of g){let{r:x,a:T,b:y}=M;if(x.raw.points){x.points=x.raw.points.map(F=>[F[0],F[1],F.length>2?F[2]:Cr(n,F[0],F[1])+.01]);continue}if(!T||!y)continue;let A=[];(x.raw.via??[]).forEach((F,J)=>{if(Array.isArray(F))if(o){let ae=we=>Math.round(Math.round(we/o)*o*1e9)/1e9;F.forEach((we,j)=>{Math.abs(we/o-Math.round(we/o))>1e-6&&a(`${x.path}/via/${J}/${j}`,`${we} is not on the ${o} grid; it is drawn at ${ae(we)}`,void 0,"warning")}),A.push({p:[ae(F[0]),ae(F[1])]})}else A.push({p:[F[0],F[1]]});else{let{id:ae,side:we}=wn(F),j=n.byId.get(ae);if(!j){a(`${x.path}/via/${J}`,`unknown node "${ae}"`+tc(ae,u()));return}let U=we&&we!=="top"?we:"n",[ee,fe]=ea[U],B=j.box;A.push({p:[ee?ee>0?B.x1+.4:B.x0-.4:(B.x0+B.x1)/2,fe?fe>0?B.y1+.4:B.y0-.4:(B.y0+B.y1)/2]})}});let K=b.filter(F=>F!==T.node.box&&F!==y.node.box).concat(x.raw.cross?[]:k).filter(F=>!ta(T.node.box,F)&&!ta(y.node.box,F)&&!ta(F,T.node.box)&&!ta(F,y.node.box)),C=T.side==="top"?void 0:ea[T.side],_=y.side==="top"?void 0:ea[y.side],S=[T.p,...A.map(F=>F.p),y.p],$=[T.p],w=C,N=!0;for(let F=0;F+1<S.length;F++){let J=F+2===S.length,ae=Ep(S[F],S[F+1],K,v,w,J&&_?[-_[0],-_[1]]:void 0,c);if(!ae){N=!1;break}$.push(...ae.slice(1));let we=$.length;if(we>=2){let j=Math.sign($[we-1][0]-$[we-2][0]),U=Math.sign($[we-1][1]-$[we-2][1]);w=[j,U]}}!N&&c.left<=0?(d++,$=[T.p,[y.p[0],T.p[1]],y.p]):N||(a(x.path,`no path found for route "${x.id}" from "${T.node.id}" to "${y.node.id}"`,'add "via" points, or use "points" to draw it by hand',"warning"),$=[T.p,[y.p[0],T.p[1]],y.p]),$=No($);for(let F=0;F+1<$.length;F++)$p(v,$[F],$[F+1]);x.points=Pp(n,$,T,y)}return d&&a(e,`${d} of ${p.length} routes were drawn as plain elbows: the scene is too large to route them all around what stands in the way (${na.toLocaleString("en")} search steps)`,'split it into scenes, or give the busiest routes "via" points or "points"',"warning"),{routes:p,diags:i}}function ta(t,e){return e.x0>=t.x0-1e-6&&e.x1<=t.x1+1e-6&&e.y0>=t.y0-1e-6&&e.y1<=t.y1+1e-6&&e.z0>=t.z1-1e-6}var du=(t,e)=>`${Math.round(t/bs)},${Math.round(e/bs)}`;function $p(t,e,n){let s=Math.max(1,Math.round(Math.hypot(n[0]-e[0],n[1]-e[1])/bs));for(let r=0;r<=s;r++){let o=du(e[0]+(n[0]-e[0])*r/s,e[1]+(n[1]-e[1])*r/s);t.set(o,(t.get(o)??0)+1)}}function uu(t,e,n){for(let s of n)if(t>s.x0-Zi&&t<s.x1+Zi&&e>s.y0-Zi&&e<s.y1+Zi)return!0;return!1}function Ep(t,e,n,s,r,o,i={left:1/0}){if((Math.abs(t[0]-e[0])<1e-6||Math.abs(t[1]-e[1])<1e-6)&&Ap(t,e,n)){let j=[Math.sign(e[0]-t[0]),Math.sign(e[1]-t[1])],U=!r||r[0]===j[0]&&r[1]===j[1],ee=!o||o[0]===j[0]&&o[1]===j[1];if(U&&ee)return[t,e]}if(i.left<=0)return null;let a=j=>Math.round((j-t[0])/bs),l=j=>Math.round((j-t[1])/bs),c=j=>t[0]+j*bs,d=j=>t[1]+j*bs,u=a(e[0]),f=l(e[1]),p=30,g=Math.min(0,u)-p,h=Math.max(0,u)+p,b=Math.min(0,f)-p,k=Math.max(0,f)+p,v=1.2,M=bs,x=.06,T=[[1,0],[-1,0],[0,1],[0,-1]],y=h-g+1,A=k-b+1,D=(j,U)=>(j-g)*A+(U-b),K=new Int8Array(y*A).fill(-1),C=new Float64Array(y*A).fill(-1),_=new Float64Array(y*A*4).fill(1/0),S=(j,U)=>{let ee=D(j,U);return K[ee]<0&&(K[ee]=uu(c(j),d(U),n)?1:0),K[ee]===1},$=(j,U)=>{let ee=D(j,U);return C[ee]<0&&(C[ee]=s.get(du(c(j),d(U)))??0),C[ee]},w=nc(),N=(j,U)=>(Math.abs(j-u)+Math.abs(U-f))*M,F=r?T.findIndex(j=>j[0]===r[0]&&j[1]===r[1]):-1;w.push({i:0,j:0,d:F,g:0,f:N(0,0),idx:0,hp:0});let J=(j,U)=>Math.abs(j)+Math.abs(U)<=2,ae=(j,U)=>Math.abs(j-u)+Math.abs(U-f)<=2,we=0;for(;w.length()&&we++<2e5;){if(i.left--<=0)return null;let j=w.take();if(j.i===u&&j.j===f&&!(o&&j.d>=0&&(T[j.d][0]!==o[0]||T[j.d][1]!==o[1]))){let U=[];for(let ee=j;ee;ee=ee.prev)U.push([c(ee.i),d(ee.j)]);return U.reverse(),U[0]=t,Tp(No(U),e)}for(let U=0;U<4;U++){let ee=T[U];if(j.d>=0&&ee[0]===-T[j.d][0]&&ee[1]===-T[j.d][1])continue;let fe=j.i+ee[0],B=j.j+ee[1];if(fe<g||fe>h||B<b||B>k||!J(fe,B)&&!ae(fe,B)&&S(fe,B))continue;if((J(fe,B)||ae(fe,B))&&S(fe,B)&&!(fe===u&&B===f)){let ne=J(fe,B)?r:o&&[-o[0],-o[1]];if(!ne||(J(fe,B)?ee[0]!==ne[0]||ee[1]!==ne[1]:ee[0]!==o[0]||ee[1]!==o[1]))continue}let X=j.d>=0&&j.d!==U?v:0,Q=j.g+M+X+$(fe,B)*x,te=D(fe,B)*4+U;_[te]<=Q||(_[te]=Q,w.push({i:fe,j:B,d:U,g:Q,f:Q+N(fe,B),prev:j,idx:0,hp:0}))}}return null}function nc(){let t=[],e=[],n=(i,a)=>i.f<a.f||i.f===a.f&&i.idx<a.idx,s=(i,a)=>{let l=e[i];e[i]=e[a],e[a]=l,e[i].hp=i,e[a].hp=a},r=i=>{for(;i>0;){let a=i-1>>1;if(!n(e[i],e[a]))break;s(i,a),i=a}},o=i=>{for(;;){let a=2*i+1,l=a+1,c=i;if(a<e.length&&n(e[a],e[c])&&(c=a),l<e.length&&n(e[l],e[c])&&(c=l),c===i)return;s(i,c),i=c}};return{length:()=>t.length,push(i){i.idx=t.length,t.push(i),i.hp=e.length,e.push(i),r(i.hp)},take(){let i=e[0],a=e.pop();e.length&&(e[0]=a,a.hp=0,o(0));let l=t.pop();return l!==i&&(t[i.idx]=l,l.idx=i.idx,r(l.hp)),i}}}function Tp(t,e){let n=t.map(o=>[o[0],o[1]]),s=n.length,r=n[s-1];if(s>=2){let o=n[s-2];Math.abs(o[1]-r[1])<1e-9?(o[1]=e[1],s>=3&&Math.abs(n[s-3][1]-r[1])<1e-9&&(n[s-3][1]=e[1])):Math.abs(o[0]-r[0])<1e-9&&(o[0]=e[0],s>=3&&Math.abs(n[s-3][0]-r[0])<1e-9&&(n[s-3][0]=e[0]))}return n[s-1]=e,No(n)}function Ap(t,e,n){let s=Math.max(1,Math.round(Math.hypot(e[0]-t[0],e[1]-t[1])/(bs/2)));for(let r=2;r<s-1;r++)if(uu(t[0]+(e[0]-t[0])*r/s,t[1]+(e[1]-t[1])*r/s,n))return!1;return!0}function No(t){let e=[];for(let n of t){let s=e.length;if(!(s&&Math.abs(e[s-1][0]-n[0])<1e-6&&Math.abs(e[s-1][1]-n[1])<1e-6)){if(s>=2){let r=e[s-2],o=e[s-1];if(Math.abs(r[0]-o[0])<1e-6&&Math.abs(o[0]-n[0])<1e-6||Math.abs(r[1]-o[1])<1e-6&&Math.abs(o[1]-n[1])<1e-6){e[s-1]=n;continue}}e.push(n)}}return e}function Pp(t,e,n,s){let r=new Set,o=new Set;for(let c of t.items)c.type!=="region"||!Ft(t.catalog,c.region.kind)?.floor||(r.add(c.box.x0),r.add(c.box.x1),o.add(c.box.y0),o.add(c.box.y1));let i=[],a=(c,d)=>Cr(t,c,d)+.01;for(let c=0;c+1<e.length;c++){let[d,u]=e[c],[f,p]=e[c+1],g=[0,1];if(Math.abs(u-p)<1e-6)for(let h of r){let b=(h-d)/(f-d);b>1e-6&&b<1-1e-6&&g.push(b)}else for(let h of o){let b=(h-u)/(p-u);b>1e-6&&b<1-1e-6&&g.push(b)}g.sort((h,b)=>h-b);for(let h=0;h+1<g.length;h++){let b=g[h],k=g[h+1],v=(b+k)/2,M=a(d+(f-d)*v,u+(p-u)*v),x=[d+(f-d)*b,u+(p-u)*b,M],T=[d+(f-d)*k,u+(p-u)*k,M],y=i[i.length-1];y&&(Math.abs(y[0]-x[0])>1e-6||Math.abs(y[1]-x[1])>1e-6||Math.abs(y[2]-x[2])>1e-6)?i.push(x):y||i.push(x),i.push(T)}}i.length&&(i[0][2]=n.side==="top"?n.z:n.node.box.z0+.01,i[i.length-1][2]=s.side==="top"?s.z:s.node.box.z0+.01);let l=[];for(let c of i){let d=l.length;if(d>=2){let u=l[d-2],f=l[d-1],p=Math.abs(u[2]-f[2])<1e-9&&Math.abs(f[2]-c[2])<1e-9,g=Math.abs(u[0]-f[0])<1e-6&&Math.abs(f[0]-c[0])<1e-6||Math.abs(u[1]-f[1])<1e-6&&Math.abs(f[1]-c[1])<1e-6;if(p&&g){l[d-1]=c;continue}}l.push(c)}return l}function tc(t,e){let n=Is(t,e);return n?` (did you mean "${n}"?)`:""}function vn(t){return[Xe(t.x0,t.y0,t.z1),Xe(t.x1,t.y0,t.z1),Xe(t.x1,t.y0,t.z0),Xe(t.x1,t.y1,t.z0),Xe(t.x0,t.y1,t.z0),Xe(t.x0,t.y1,t.z1)]}function xs(t){let e=t.map(o=>o[0]),n=t.map(o=>o[1]),s=Math.min(...e),r=Math.min(...n);return{x:s,y:r,w:Math.max(...e)-s,h:Math.max(...n)-r}}function Lr(t,e){let n=t,s=(a,l)=>{let c=[];for(let d=0;d<n.length;d++){let u=n[d],f=n[(d+1)%n.length],p=a(u),g=a(f);p&&c.push(u),p!==g&&c.push(l(u,f))}n=c},r=a=>(l,c)=>[a,l[1]+(c[1]-l[1])*(a-l[0])/(c[0]-l[0])],o=a=>(l,c)=>[l[0]+(c[0]-l[0])*(a-l[1])/(c[1]-l[1]),a];if(s(a=>a[0]>=e.x,r(e.x)),!n.length||(s(a=>a[0]<=e.x+e.w,r(e.x+e.w)),!n.length)||(s(a=>a[1]>=e.y,o(e.y)),!n.length)||(s(a=>a[1]<=e.y+e.h,o(e.y+e.h)),!n.length))return 0;let i=0;for(let a=0;a<n.length;a++){let l=n[a],c=n[(a+1)%n.length];i+=l[0]*c[1]-c[0]*l[1]}return Math.abs(i)/2}function oc(t,e){let n=Math.min(t.x+t.w,e.x+e.w)-Math.max(t.x,e.x),s=Math.min(t.y+t.h,e.y+e.h)-Math.max(t.y,e.y);return n>0&&s>0?n*s:0}function mu(t,e){let n=0;for(let s=0;s+1<t.length;s++){let r=t[s],o=t[s+1],i=Math.hypot(o[0]-r[0],o[1]-r[1]),a=Math.max(1,Math.ceil(i/4));for(let l=0;l<a;l++){let c=r[0]+(o[0]-r[0])*(l+.5)/a,d=r[1]+(o[1]-r[1])*(l+.5)/a;c>=e.x&&c<=e.x+e.w&&d>=e.y&&d<=e.y+e.h&&(n+=i/a*4)}}return n}var ys=64,oa=class{cells=new Map;n=0;add(e,n,s,r,o){for(let i=Math.floor(n/ys);i<=Math.floor(r/ys);i++)for(let a=Math.floor(s/ys);a<=Math.floor(o/ys);a++){let l=i*1048576+a,c=this.cells.get(l);c||this.cells.set(l,c=[]),c[c.length-1]!==e&&c.push(e)}}query(e,n,s,r){let o=new Set;for(let i=Math.floor(e/ys);i<=Math.floor(s/ys);i++)for(let a=Math.floor(n/ys);a<=Math.floor(r/ys);a++){let l=this.cells.get(i*1048576+a);if(l)for(let c of l)o.add(c)}return[...o].sort((i,a)=>i-a)}},sc=t=>{let e=1/0,n=1/0,s=-1/0,r=-1/0;for(let[o,i]of t)o<e&&(e=o),o>s&&(s=o),i<n&&(n=i),i>r&&(r=i);return[e,n,s,r]},ia=new WeakMap;function Ds(t,e){let n=ia.get(t);for((!n||n.n>t.length)&&ia.set(t,n=new oa);n.n<t.length;n.n++){let[s,r,o,i]=e(t[n.n]);n.add(n.n,s,r,o,i)}return n}function fu(t){let e=ia.get(t);for((!e||e.n>t.length)&&ia.set(t,e=new oa);e.n<t.length;e.n++){let n=t[e.n].pts;for(let s=0;s+1<n.length;s++){let r=n[s],o=n[s+1],i=e.n*65536+s,a=Math.max(1,Math.ceil(Math.hypot(o[0]-r[0],o[1]-r[1])/(ys/2)));for(let l=0;l<a;l++){let c=l/a,d=(l+1)/a,u=r[0]+(o[0]-r[0])*c,f=r[1]+(o[1]-r[1])*c,p=r[0]+(o[0]-r[0])*d,g=r[1]+(o[1]-r[1])*d;e.add(i,Math.min(u,p)-1,Math.min(f,g)-1,Math.max(u,p)+1,Math.max(f,g)+1)}}}return e}var ts=(t,e,n,s,r)=>t.query(e,n,s,r),Nr=t=>sc(t),ra=t=>[t.x,t.y,t.x+t.w,t.y+t.h];function pu(t,e,n,[s,r,o,i]){let a=0,l=n-1;for(let c of[0,1]){let d=e[c]-t[c],u=c?r:s,f=c?i:o;if(Math.abs(d)<1e-12){if(t[c]<u||t[c]>f)return[1,0];continue}let p=(u-t[c])/d*n-.5,g=(f-t[c])/d*n-.5;p>g&&([p,g]=[g,p]),a=Math.max(a,Math.floor(p)-1),l=Math.min(l,Math.ceil(g)+1)}return[a,l]}var sr=class t{polys=[];rects=[];lines=[];solids=[];slants=[];budget={spots:1/0,over:!1,told:!1};hidden(e){let n=0;for(let s of ts(Ds(this.solids,Nr),...ra(e)))n+=Lr(this.solids[s],e);return n}hiddenPoly(e){let n=0;for(let s of ts(Ds(this.solids,Nr),...sc(e)))n+=Lo(e,this.solids[s]);return n}costPoly(e,n=1/0){let s=sc(e),r=0;for(let o of ts(Ds(this.polys,i=>Nr(i.poly)),...s))r+=Lo(e,this.polys[o].poly);for(let o of ts(Ds(this.rects,i=>ra(i.r)),...s))r+=Lr(e,this.rects[o].r)*2;for(let o of ts(Ds(this.slants,Nr),...s))r+=Lo(e,this.slants[o])*2;if(r>=n)return r;for(let o of ts(fu(this.lines),...s)){if(r>=n)return r;let i=this.lines[Math.floor(o/65536)].pts,a=o%65536,l=i[a],c=i[a+1],d=Math.hypot(c[0]-l[0],c[1]-l[1]),u=Math.max(1,Math.ceil(d/4)),[f,p]=pu(l,c,u,s);for(let g=f;g<=p;g++)ac(e,[l[0]+(c[0]-l[0])*(g+.5)/u,l[1]+(c[1]-l[1])*(g+.5)/u])&&(r+=d/u*4*.6)}return r}cost(e,n,s=.6){let r=ra(e),o=0;for(let i of ts(Ds(this.polys,a=>Nr(a.poly)),...r)){let a=this.polys[i];o+=Lr(a.poly,e)*(a.owner===n?1.5:1)}for(let i of ts(Ds(this.rects,a=>ra(a.r)),...r)){let a=this.rects[i];(a.owner!==n||!n)&&(o+=oc(a.r,e)*2)}for(let i of ts(Ds(this.slants,Nr),...r))o+=Lr(this.slants[i],e)*2;if(s){let i=-1,a=0;for(let l of ts(fu(this.lines),...r)){let c=Math.floor(l/65536);c!==i&&(i>=0&&(o+=a*s),i=c,a=0);let d=this.lines[c].pts,u=l%65536,f=d[u],p=d[u+1],g=Math.hypot(p[0]-f[0],p[1]-f[1]),h=Math.max(1,Math.ceil(g/4)),[b,k]=pu(f,p,h,r);for(let v=b;v<=k;v++){let M=f[0]+(p[0]-f[0])*(v+.5)/h,x=f[1]+(p[1]-f[1])*(v+.5)/h;M>=e.x&&M<=e.x+e.w&&x>=e.y&&x<=e.y+e.h&&(a+=g/h*4)}}i>=0&&(o+=a*s)}return o}fork(){let e=new t;return e.budget=this.budget,e.polys=this.polys,e.lines=this.lines,e.solids=this.solids,e.rects=[...this.rects],e.slants=this.slants,e}},hu=14;function Ro(t,e,n,s){let r=Math.max(t.name?$n(t.name,Bt.lbl):0,t.sub?$n(t.sub,Bt.sub):0)+4,o=(t.name?1:0)+(t.sub?1:0),i=n-(t.name?11:9)-1,a=(o-1)*hu+(t.name?11:9)+4;return{x:s==="start"?e-2:s==="end"?e-r+2:e-r/2,y:i,w:r,h:a}}function Io(t,e,n,s,r,o){let i=xs(n),a=Xe((e.x0+e.x1)/2,(e.y0+e.y1)/2,e.z1)[0],c=((t.name?1:0)+(t.sub?1:0)-1)*hu+4,d=i.y-6-c,u=i.y+Math.min(i.h,60)*.45,f=[];o&&f.push({...o,pen:0}),f.push({x:a,y:d,anchor:"middle",pen:o?20:0});for(let h of[12,24,40])f.push({x:a,y:d-h,anchor:"middle",pen:20+h});for(let h of[-30,30,-60,60])f.push({x:a+h,y:d-4,anchor:"middle",pen:30+Math.abs(h)});f.push({x:i.x+i.w+8,y:u,anchor:"start",pen:120}),f.push({x:i.x-8,y:u,anchor:"end",pen:120}),f.push({x:a,y:i.y+i.h+14,anchor:"middle",pen:300});let p,g=1/0;for(let h of f){let b=Ro(t,h.x,h.y,h.anchor),k=s.cost(b,r,.15)*2+h.pen;k<g&&(g=k,p={x:h.x,y:h.y,anchor:h.anchor,rect:b})}return p}function ic(t,e,n,s){return{x:(s==="start"?e:s==="end"?e-t:e-t/2)-2,y:n-14,w:t+4,h:28}}function aa(t,e,n,s,r){let o=[{...s,pen:0}];for(let d of[-46,-66,-86,-106,-126,-146])for(let u of[0,-70,70,-140,140])o.push({x:e+u,y:n+d,anchor:"middle",pen:10+(-d-46)*.5+Math.abs(u)*.4});for(let d of[34,60,86])o.push({x:e,y:n+d,anchor:"middle",pen:60+d*.3});let i=s.x-e,a=s.y-n;for(let d of[-1,1])for(let u of[16,32,48])o.push({...s,y:n+a+d*u,x:e+i,pen:5+u});for(let d of[-1,1])for(let u of[30,60,90])for(let f of[0,16,-16])o.push({...s,x:e+i+d*u,y:n+a+f,pen:8+u*.6+Math.abs(f)});let l,c=1/0;for(let d of o){let u=ic(t,d.x,d.y,d.anchor),f=r.cost(u,void 0,.05)*3+d.pen;f<c&&(c=f,l={x:d.x,y:d.y,anchor:d.anchor,rect:u})}return l}var gu=t=>{let e=0;for(let n=0;n<t.length;n++){let s=t[n],r=t[(n+1)%t.length];e+=s[0]*r[1]-r[0]*s[1]}return e/2},rc=t=>gu(t)<0?[...t].reverse():t;function ac(t,e){let n=rc(t);for(let s=0;s<n.length;s++){let r=n[s],o=n[(s+1)%n.length];if((o[0]-r[0])*(e[1]-r[1])-(o[1]-r[1])*(e[0]-r[0])<0)return!1}return!0}function Lo(t,e){let n=rc(t),s=rc(e);for(let r=0;r<s.length&&n.length;r++){let o=s[r],i=s[(r+1)%s.length],a=c=>(i[0]-o[0])*(c[1]-o[1])-(i[1]-o[1])*(c[0]-o[0]),l=n;n=[];for(let c=0;c<l.length;c++){let d=l[c],u=l[(c+1)%l.length],f=a(d),p=a(u);if(f>=0&&n.push(d),f>=0!=p>=0){let g=f/(f-p);n.push([d[0]+(u[0]-d[0])*g,d[1]+(u[1]-d[1])*g])}}}return n.length>=3?Math.abs(gu(n)):0}var la=24;function ca(t,e){let[n,s,r,o]=e,i=t.x+t.w/2,a=t.y+t.h/2,l=[["left",i-n],["right",n+r-i],["top",a-s],["bottom",s+o-a]];l.sort((d,u)=>d[1]-u[1]);let c=l[0][0];return c==="left"?{edge:c,dx:-(t.x+t.w-n)-la,dy:0}:c==="right"?{edge:c,dx:n+r-t.x+la,dy:0}:c==="top"?{edge:c,dx:0,dy:-(t.y+t.h-s)-la}:{edge:c,dx:0,dy:s+o-t.y+la}}function da(t,e,n){let s=x=>{let T=0;for(let y=x.parent;y;y=y.parent)T++;return T},r=x=>x.box.x0+x.box.y0+x.box.z0*.01,o=t.items.filter(x=>x.type==="region").sort((x,T)=>s(x)-s(T)||r(x)-r(T)),i=t.items.filter(x=>x.type==="node").sort((x,T)=>r(x)-r(T)||x.box.z0-T.box.z0),a=[],l=Math.min(90,400/Math.max(1,o.length)),c=650;o.forEach((x,T)=>{let y=xs(vn(x.box));a.push({id:x.id,kind:"region",...ca(y,n),delay:Math.round(T*l),dur:c,bbox:y})});let d=250+Math.round(l*o.length),u=Math.min(70,700/Math.max(1,i.length)),f=600;i.forEach((x,T)=>{let y=xs(vn(x.box));a.push({id:x.id,kind:"node",...ca(y,n),delay:Math.round(d+T*u),dur:f,bbox:y})});let p=i.length?d+(i.length-1)*u:d,g=Math.round(p+300),h=Math.min(30,300/Math.max(1,e.length)),b=400,k=e.filter(x=>x.points.length>=2).map((x,T)=>({id:x.id,delay:Math.round(g+T*h),dur:b})),v={delay:g+200,dur:400},M=Math.max(...a.map(x=>x.delay+x.dur),...k.map(x=>x.delay+x.dur),v.delay+v.dur);return{pieces:a,routes:k,labels:v,total:M}}function lc(t){return Math.max(5600,Math.min(12500,2600+t.length*40))}function ua(t,e,n,s,r,o){let i=[],a=(C,_,S,$="error")=>{let w=r.locate(C);i.push({severity:$,message:_,line:w.line,col:w.col,path:C,hint:S})},l=t.steps??[],c=new Set(Object.keys(o.kinds)),d=new Map(s.map(C=>[C.id,C])),u=()=>[...n.byId.keys(),...d.keys()],f=new Map;l.forEach((C,_)=>{C.id&&(f.has(C.id)&&a(`${e}/steps/${_}/id`,`duplicate step id "${C.id}"`),f.set(C.id,_+1))});let p=l.length,g=(C,_)=>{if(typeof C=="number"){if(C<1||C>p){a(_,`there is no step ${C}; this scene has ${p} step(s)`);return}return C}let S=f.get(C);return S===void 0&&a(_,`unknown step "${C}"`+An(C,f.keys())),S},h=C=>Zn(o,o.kinds[C]?.color??"control"),b=[],k=C=>{b.includes(C)||b.push(C)};for(let C of s)k(C.kind);let v={},M=(C,_,S,$)=>{if(_===void 0&&S===void 0)return;let w=_!==void 0?g(_,$+"/appears"):1,N=S!==void 0?g(S,$+"/disappears"):p+1;v[C]=Array.from({length:p},(F,J)=>J+1>=(w??1)&&J+1<(N??p+1))};for(let C of n.items)M(C.id,C.appears,C.disappears,C.path);for(let C of s)M(C.id,C.raw.appears,C.raw.disappears,C.path);let x=[],T=[],y=[],A=[],D=()=>{for(let C of s){if(C.raw.appears!==void 0||C.raw.disappears!==void 0)continue;let _=[C.from,C.to].map(S=>S&&(v[S.id]??K(S)));_.some(Boolean)&&(v[C.id]=Array.from({length:p},(S,$)=>_.every(w=>!w||w[$])))}},K=C=>{for(let _=C.parent;_;_=_.parent)if(v[_.id])return v[_.id]};return l.forEach((C,_)=>{let S=_+1,$=`${e}/steps/${_}`,w=C.kind??"control";c.has(w)||a($+"/kind",`unknown flow kind "${w}"`+An(w,c)),k(w);let N=new Set,F=[];(C.animate??[]).forEach((j,U)=>{let ee=Array.isArray(j)?j:[j],fe=[];ee.forEach((B,X)=>{let Q=Array.isArray(j)?`${$}/animate/${U}/${X}`:`${$}/animate/${U}`,te,ne;if(typeof B=="string"){let xe=/^([^:\s]+)\s*(?::\s*(\S+))?$/.exec(B.trim());te=xe?xe[1]:B,ne=xe?.[2]}else{let xe=Object.entries(B)[0];te=xe[0],ne=xe[1]}let me=d.get(te);if(!me){a(Q,`unknown route "${te}"`+An(te,d.keys()));return}if(ne&&!c.has(ne)){a(Q,`unknown flow kind "${ne}"`+An(ne,c));return}let ye=ne??me.kind;k(ye),fe.push({route:te,kind:ye,color:h(ye)}),N.add(te),me.from&&N.add(me.from.id),me.to&&N.add(me.to.id)}),fe.length&&F.push(fe)});let J=[];(C.pulse??[]).forEach((j,U)=>{let ee=n.byId.get(j);if(!ee){a(`${$}/pulse/${U}`,`unknown node "${j}"`+An(j,n.byId.keys()));return}let fe,B,X,Q,te=ee.node?nr(n.catalog,ee.node.asset):void 0;if(te?.pulse)[fe,B,X,Q]=te.pulse(ee.box);else{let ye=ee.box;fe=(ye.x0+ye.x1)/2,B=(ye.y0+ye.y1)/2,X=ye.z1,Q=Math.max(22,Math.min(60,(ye.x1-ye.x0+ye.y1-ye.y0)*8.5))}let[ne,me]=Xe(fe,B,X);J.push([ne,me,Q*1.7,Q*.98]),N.add(j)}),(C.highlight??[]).forEach((j,U)=>{!n.byId.has(j)&&!d.has(j)&&a(`${$}/highlight/${U}`,`unknown id "${j}"`+An(j,u())),N.add(j)});for(let[j,U]of[["show",!0],["hide",!1]])(C[j]??[]).forEach((ee,fe)=>{if(!n.byId.has(ee)&&!d.has(ee)){a(`${$}/${j}/${fe}`,`unknown id "${ee}"`+An(ee,u()));return}let B=v[ee]??(v[ee]=Array(p).fill(!U));for(let X=_;X<p;X++)B[X]=U});if((C.say??[]).forEach((j,U)=>{let ee,fe;if(Array.isArray(j.at))[ee,fe]=Xe(j.at[0],j.at[1],j.at[2]??.36);else{let X=n.byId.get(j.at);if(!X){a(`${$}/say/${U}/at`,`unknown node "${j.at}"`+An(j.at,n.byId.keys()));return}let Q=X.box;[ee,fe]=Xe((Q.x0+Q.x1)/2,(Q.y0+Q.y1)/2,Q.z1+.75)}let B=j.kind??w;c.has(B)||a(`${$}/say/${U}/kind`,`unknown flow kind "${B}"`+An(B,c)),T.push({step:S,x:ee+(j.dx??0),y:fe+(j.dy??(Array.isArray(j.at)?0:-46)),ax:ee,ay:fe,text:j.text,kind:B,anchor:j.anchor??"middle"})}),(C.mark??[]).forEach((j,U)=>{if(j.at){y.push({step:S,p:[j.at[0],j.at[1],j.at[2]??.36]});return}let ee=j.on?d.get(j.on):void 0;if(!ee){a(`${$}/mark/${U}`,j.on?`unknown route "${j.on}"`+An(j.on,d.keys()):'a mark needs "on: ROUTE" or "at: [x, y]"');return}let fe=ee.points[ee.points.length-1];y.push({step:S,p:[fe[0],fe[1],fe[2]+.6],on:ee.id}),N.add(ee.id)}),t.badges&&C.badge!==!1){let j=Array.isArray(C.badge)?[C.badge[0],C.badge[1],C.badge[2]??.36]:void 0,U=typeof C.badge=="string"?C.badge:F[0]?.[0]?.route,ee=U?d.get(U):void 0;if(!j)if(ee)j=cc(ee.points);else if(U&&n.byId.get(U)){let fe=n.byId.get(U).box;j=[(fe.x0+fe.x1)/2,(fe.y0+fe.y1)/2,fe.z1+.3]}else typeof C.badge=="string"&&a(`${$}/badge`,`unknown id "${C.badge}"`+An(C.badge,u()));j&&A.push({step:S,num:C.number??S,kind:w,p:j})}for(let j of[...N])for(let U=n.byId.get(j)?.parent;U;U=U.parent)N.add(U.id);for(let j of n.items)j.region?.kind==="tunnel"&&(j.region.around??[]).some(U=>N.has(U))&&N.add(j.id);let ae;if(C.focus?.length){let j=1/0,U=1/0,ee=-1/0,fe=-1/0;C.focus.forEach((B,X)=>{let Q=n.byId.get(B);if(!Q){a(`${$}/focus/${X}`,`unknown node or region "${B}"`+An(B,n.byId.keys()));return}let te=Q.box;for(let[ne,me,ye]of[[te.x0,te.y0,te.z1],[te.x1,te.y0,te.z0],[te.x0,te.y1,te.z0],[te.x1,te.y1,te.z0],[te.x1,te.y0,te.z1],[te.x0,te.y1,te.z1]]){let[xe,Re]=Xe(ne,me,ye);j=Math.min(j,xe),U=Math.min(U,Re),ee=Math.max(ee,xe),fe=Math.max(fe,Re)}N.add(B)}),j<1/0&&(ae=[Math.round(j-60),Math.round(U-70),Math.round(ee+60),Math.round(fe+40)])}let we=C.caption??"";x.push({n:S,num:C.number??S,kind:w,color:h(w),heading:C.heading,caption:we,command:C.command??"",phases:F,pulses:J,lit:[...N],duration:C.duration===void 0||C.duration==="auto"?lc(we):C.duration,...ae?{focus:ae}:{}})}),D(),{steps:x,says:T,marks:y,badges:A,vis:v,diags:i,kindsUsed:b}}function cc(t){let e=t.slice(1).map((s,r)=>Math.hypot(s[0]-t[r][0],s[1]-t[r][1],s[2]-t[r][2])),n=e.reduce((s,r)=>s+r,0)/2;for(let s=0;s<e.length;s++){if(n<=e[s]&&e[s]>0){let r=n/e[s],o=t[s],i=t[s+1];return[o[0]+(i[0]-o[0])*r,o[1]+(i[1]-o[1])*r,o[2]+(i[2]-o[2])*r]}n-=e[s]}return t[0]}function An(t,e){let n=Is(t,e);return n?` (did you mean "${n}"?)`:""}function bu(t,e){if(!e)return t;let[n,s,r,o]=e,i=t[2]/t[3],a=r-n,l=o-s;a/l<i?a=l*i:l=a/i,a=Math.min(a,t[2]),l=Math.min(l,t[3]);let c=(n+r)/2,d=(s+o)/2,u=Math.max(t[0],Math.min(t[0]+t[2]-a,c-a/2)),f=Math.max(t[1],Math.min(t[1]+t[3]-l,d-l/2));return[u,f,a,l]}var ha=(t,e)=>e.role??Ft(t,e.kind)?.role,fa=(t,e)=>Ft(t,e.region.kind)?.shape;function ga({scene:t,layout:e,routes:n,steps:s,theme:r,id:o,gridStep:i=1}){let a=new yr,l={base:"",floor:"",flows:"",blocks:[],air:"",labels:"",marks:"",badges:""},c=new sr;c.budget.spots=ma;let d=w=>s.vis[w]?{"data-vis":"1"}:{},u=e.items.filter(w=>w.type==="region"),f=w=>{let N=0;for(let F=w.parent;F;F=F.parent)N++;return N},p=e.catalog,g=u.filter(w=>fa(p,w)!=="walled"&&fa(p,w)!=="tunnel"),h=io(g.map(w=>({box:w.box,r:w}))).map(w=>w.r).sort((w,N)=>f(w)-f(N));for(let w of h)l.base+=Cp(a,p,w,d(w.id),i);for(let w of u.filter(N=>fa(p,N)==="walled")){for(let F of pa(w))c.solids.push(vn(F));for(let F of pa(w))l.blocks.push({box:F,svg:Ve("g",{class:`blk k-${ha(p,w.region)} wall${w.region.ghost?" ghost":""}`,"data-id":w.id,"data-dim":"1",...d(w.id)},a.blockFaces(F))});let N=w.region.gate;if(N&&!N.node){let F=Co(w,N.height??(w.region.height??.8)+.3,.3,.3);c.solids.push(vn(F)),l.blocks.push({box:F,svg:Ve("g",{class:"blk k-gate","data-id":w.id,...d(w.id)},a.blockFaces(F))})}w.region.label&&(w.region["label-style"]??"face")!=="none"&&(l.labels+=a.faceText(w.box.x0+.3,w.box.y1,w.box.z0+.13,w.region.label,"slabname sm fz",Bt.sm,"left","start",{"data-id":w.id,...d(w.id)}))}for(let w of u.filter(N=>fa(p,N)==="tunnel"))l.air+=Lp(a,w,d(w.id));let b=e.items.filter(w=>w.type==="node");for(let w of b){let N=w.node,F=Tn(p,N.asset),J=N.ghost||(N.deco??[]).includes("ghost"),ae=["blk",`k-${N.role??F.role}`,F.cls,J?"ghost":""].filter(Boolean).join(" ");l.blocks.push({box:w.box,svg:Ve("g",{class:ae,"data-id":w.id,"data-dim":"1",...d(w.id)},F.draw(a,w.box,N))}),c.polys.push({poly:vn(w.box),owner:w.id}),c.solids.push(vn(w.box))}let k=io(l.blocks).map(w=>w.svg).join(""),v=new Set,M={};for(let w of n){if(w.points.length<2)continue;let N=w.points.map(ae=>Xe(ae[0],ae[1],ae[2]));N.forEach(ae=>a.bounds.add(ae));let F="M"+N.map(Xs).join(" L");M[w.id]=F;let J=w.raw.arrow!==!1;J&&v.add(w.kind),l.flows+=Ve("g",{"data-hl":w.id,"data-id":w.id,...d(w.id)},Ve("path",{d:F,class:`flow f-${w.kind}`,"marker-end":J?`url(#ah-${o}-${w.kind})`:void 0})),c.lines.push({pts:N,owner:w.id})}for(let w of v)a.def(`ah-${o}-${w}`,Ve("marker",{id:`ah-${o}-${w}`,viewBox:"0 0 10 10",refX:"7",refY:"5",markerWidth:"4.2",markerHeight:"4.2",orient:"auto-start-reverse"},Ve("path",{d:"M0,0 L10,5 L0,10 z",style:`fill:${Zn(r,r.kinds[w]?.color??"control")}`})));for(let w of a.planePolys)c.slants.push(w);let x=b.filter(w=>w.node.label||w.node.sub).sort((w,N)=>(N.box.x1-N.box.x0)*(N.box.y1-N.box.y0)-(w.box.x1-w.box.x0)*(w.box.y1-w.box.y0));for(let w of x)l.labels+=Np(a,p,w,c,d(w.id));let T=[];for(let w of n)if(w.raw.label&&w.points.length>=2){let N=Rp(a,w,c,d(w.id),e);l.floor+=N.svg,N.warning&&T.push({path:`${w.path}/label`,message:N.warning}),c.budget.over&&!c.budget.told&&(c.budget.told=!0,T.push({path:w.path,message:`from route "${w.id}" on, route labels were placed without weighing what other labels and lines cover: the scene is too large to search every spot (${ma.toLocaleString("en")} spots); split it into scenes, or give the labels "along", "side" or "at"`}))}(t.notes??[]).forEach((w,N)=>{let F=Ip(a,w,e,n,`${o}-note-${N}`);w.floor?l.floor+=F:l.labels+=F});let y=[],A=new Map;for(let w of s.says){let N=A.get(w.step)??c.fork();A.set(w.step,N);let F=$n(w.text,Bt.say)+18,J=aa(F,w.ax,w.ay,{x:w.x,y:w.y,anchor:w.anchor},N);N.rects.push({r:J.rect,owner:""}),y.push({step:w.step,...J.rect,text:w.text});let ae=J.rect.x+2;a.bounds.addRect(J.rect.x,J.rect.y,J.rect.w,J.rect.h);let we=Zn(r,r.kinds[w.kind]?.color??"control");l.marks+=Ve("g",{class:"say","data-step":w.step},Ve("rect",{x:ae,y:J.y-12,width:F,height:24,rx:12,style:`stroke:${we}`})+Ve("text",{x:ae+F/2,y:J.y+4,"text-anchor":"middle",style:`fill:${we}`},Dt(w.text)))}for(let w of s.marks){let[N,F]=Xe(...w.p);a.bounds.addRect(N-12,F-12,24,24),l.marks+=Ve("g",{class:"xm","data-step":w.step,"data-hl":w.on},Ve("circle",{cx:N,cy:F,r:10})+Ve("path",{d:`M${Lt(N-4.5)},${Lt(F-4.5)} L${Lt(N+4.5)},${Lt(F+4.5)} M${Lt(N+4.5)},${Lt(F-4.5)} L${Lt(N-4.5)},${Lt(F+4.5)}`}))}for(let w of s.badges){let[N,F]=Xe(...w.p);a.bounds.addRect(N-13,F-13,26,26),l.badges+=Ve("g",{class:`badge c-${w.kind}`,"data-go":w.step,"data-badge":w.step,tabindex:"0",role:"button","aria-label":`Step ${w.num}`},Ve("circle",{cx:N,cy:F,r:11.5})+Ve("text",{x:N,y:F+.5},String(w.num)))}let D=a.bounds,K=22,C=D.empty?[0,0,100,100]:[Math.floor(D.x0-K),Math.floor(D.y0-K),Math.ceil(D.x1-D.x0+K*2),Math.ceil(D.y1-D.y0+K*2)],_=[...a.defs.values()].join(""),S=(w,N)=>Ve("g",{class:"g-"+w},N);return{svg:Ve("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:C.join(" "),role:"img","aria-label":t.aria??t.title,"data-scene":o},Ve("defs",{},_)+S("base",l.base)+S("floor",l.floor)+S("flows",l.flows)+S("blocks",k)+S("air",l.air)+S("labels",l.labels)+S("marks",l.marks)+S("badges",l.badges)+S("anim","")),viewBox:C,texts:a.texts,paths:M,warnings:T,callouts:y,assembly:da(e,n,C)}}function Op(t,e){let n=t.z1+.002,s=1e-6,r=[],o=(i,a)=>{let l=Xe(i[0],i[1],n),c=Xe(a[0],a[1],n);r.push(`M${Xs(l)}L${Xs(c)}`)};for(let i=Math.ceil((t.x0+s)/e)*e;i<t.x1-s;i+=e)o([i,t.y0],[i,t.y1]);for(let i=Math.ceil((t.y0+s)/e)*e;i<t.y1-s;i+=e)o([t.x0,i],[t.x1,i]);return r.length?Ve("path",{class:"grid",d:r.join("")}):""}function Cp(t,e,n,s,r=1){let o=n.region,i=n.box,a=ha(e,o),l=Ft(e,o.kind),c=l?.shape,d={"data-id":n.id,"data-dim":"1",...s},u="";c==="cloud"?u=Ve("g",{class:`blk k-${a} cloud`,...d},Ui(t,i)):c==="zone"?u=Ve("g",{class:`zone k-${a}`,...d},t.poly([[i.x0,i.y0,i.z1],[i.x1,i.y0,i.z1],[i.x1,i.y1,i.z1],[i.x0,i.y1,i.z1]])):u=Ve("g",{class:`blk k-${a}${o.ghost?" ghost":""}`,...d},t.blockFaces(i)+Op(i,r));let f=o["label-style"]??l?.labelStyle;if(o.label&&f!=="none")if(f==="face"){let p=c==="slab",g=p?i.z0+.28:i.z0+Math.min(.1,(i.z1-i.z0)*.25);u+=Ve("g",d,t.faceText(i.x0+(p?.6:.3),i.y1,g,o.label,p?"slabname":"slabname sm",p?Bt.slabname:Bt.sm,"left","start"))}else if(f==="face-right")u+=Ve("g",d,t.faceText(i.x1,i.y0+.6,i.z0+Math.max(.14,(i.z1-i.z0)*.2),o.label,"slabname",Bt.slabname,"right","end"));else{let p=c==="cloud"?"middle":"start",g=c==="cloud"?(i.x0+i.x1)/2:i.x0+.35,h=c==="cloud"?(i.y0+i.y1)/2:i.y1-.35;u+=Ve("g",d,t.floorText(g,h,i.z1+.01,o.label,"slabname sm","x",p))}return u}function pa(t){let{x0:e,y0:n,x1:s,y1:r,z0:o,z1:i}=t.box,a=es,l=t.region.gate,c=[],d=f=>{f.x1-f.x0>1e-6&&f.y1-f.y0>1e-6&&c.push({...f,z0:o,z1:i})},u=(f,p,g)=>{if(!l||l.side!==g)return[[f,p]];let h=l.at??.5,b=l.width??2,k=g==="e"||g==="w"?n+(r-n)*h:e+(s-e)*h;return[[f,k-b/2],[k+b/2,p]]};for(let[f,p]of u(e,s,"n"))d({x0:f,y0:n,x1:p,y1:n+a});for(let[f,p]of u(n+a,r-a,"w"))d({x0:e,y0:f,x1:e+a,y1:p});for(let[f,p]of u(n+a,r-a,"e"))d({x0:s-a,y0:f,x1:s,y1:p});for(let[f,p]of u(e,s,"s"))d({x0:f,y0:r-a,x1:p,y1:r});return c}function Np(t,e,n,s,r){let o=n.node,i=Tn(e,o.asset),a=n.box,l={name:o.label,sub:o.sub},c=o["label-at"],d;if(c){let f=xs(vn(a)),p=c.side??"above",g=f.y+Math.min(f.h,60)*.45;p==="right"?d={x:f.x+f.w+8,y:g,anchor:"start"}:p==="left"?d={x:f.x-8,y:g,anchor:"end"}:p==="below"?d={x:f.x+f.w/2,y:f.y+f.h+14,anchor:"middle"}:d=Io(l,a,vn(a),new sr,n.id),d={...d,x:d.x+(c.dx??0),y:d.y+(c.dy??0)}}else{let f=i.label?i.label(a,o,!!o.sub):void 0;d=Io(l,a,vn(a),s,n.id,f)}s.rects.push({r:Ro(l,d.x,d.y,d.anchor),owner:""});let u="";return o.label&&(u+=t.text(d.x,d.y,o.label,"lbl",Bt.lbl,d.anchor,{},n.id)),o.sub&&(u+=t.text(d.x,o.label?d.y+14:d.y,o.sub,"sub mono",Bt.sub,d.anchor,{},n.id)),Ve("g",{"data-id":n.id,"data-dim":"1",...r},u)}function Lp(t,e,n){let{x0:s,y0:r,x1:o,y1:i,z0:a,z1:l}=e.box,c=t.blockFaces(e.box),d=o-s>=i-r,u=Math.max(1,Math.round((d?o-s:i-r)/1.6));for(let p=1;p<u;p++){let g=d?s+(o-s)*p/u:r+(i-r)*p/u;c+=t.poly(d?[[g,r,l],[g,i,l],[g,i,a]]:[[s,g,l],[o,g,l],[o,g,a]],"rib")}let f=e.region.label;return f&&e.region["label-style"]!=="none"&&(c+=d?t.faceText(s+.35,i,a+.14,f,"tunname",Bt.tunname,"left","start"):t.faceText(o,i-.35,a+.18,f,"tunname",Bt.tunname,"right","start")),Ve("g",{class:"tunnel","data-id":e.id,"data-dim":"1",...n},c)}var ma=2e4;function Rp(t,e,n,s,r){let o=typeof e.raw.label=="string"?{text:e.raw.label}:e.raw.label,i=`floor mono t-${e.kind}`,a={"data-hl":e.id,...s},l=Bt.floor;if(o.at){let v=o.at.length>2?o.at[2]:e.points[0][2];return{svg:t.floorText(o.at[0],o.at[1],v,o.text,i,o.dir??"x",o.anchor??"start",a)}}let c=e.points,d=[];for(let v=0;v+1<c.length;v++){let M=c[v],x=c[v+1];Math.abs(M[2]-x[2])>1e-6||d.push({i:v,len:Math.hypot(x[0]-M[0],x[1]-M[1])})}if(!d.length)return{svg:"",warning:`label "${o.text}" of route "${e.id}" was dropped: the route has no level segment`};let u=o.along?d.filter(v=>v.i===Math.min(o.along-1,c.length-2)):[...d].sort((v,M)=>M.len-v.len),f=.22,p=11/xt,g=v=>{let M=$n(v,l)/xt,x,T=1/0,y=0;e:for(let A of u.length?u:d){let D=c[A.i],K=c[A.i+1],C=D[2],_=Math.abs(D[1]-K[1])<1e-6,S=_?Math.min(D[0],K[0]):Math.min(D[1],K[1]),$=_?Math.max(D[0],K[0]):Math.max(D[1],K[1]),w=_?D[1]:D[0],N=o.side==="left"?[-1]:o.side==="right"?[1]:[-1,1],F=[];for(let J=S+.3;J<=Math.max(S+.3,$-M-.2)+1e-9;J+=.4)F.push(J);for(let J=$-M-.2+.4;J<$+.5&&$-S<M+.5;J+=.6)F.push(J);for(let J of N)for(let ae of F){if(T<=y*.5)break e;let we=J<0?w-f:w+f+p,j,U,ee;if(_?(j=ae,U=we,ee=[Xe(j,U-p,C),Xe(j+M,U-p,C),Xe(j+M,U,C),Xe(j,U,C)]):(j=we,U=ae+M,ee=[Xe(j-p,U,C),Xe(j-p,U-M,C),Xe(j,U-M,C),Xe(j,U,C)]),(_?[[j,U-p],[j+M,U-p],[j+M,U],[j,U]]:[[j-p,U],[j-p,U-M],[j,U-M],[j,U]]).some(([ne,me])=>Math.abs(Cr(r,ne,me)+.01-C)>.001)){y++;continue}let B=n.hiddenPoly(ee),X=B*50+y*.5,Q=n.budget.spots-- >0;Q||(n.budget.over=!0);let te=X>=T?1/0:Q?X+n.costPoly(ee,T-X):X;y++,te<T&&(T=te,x={x:j,y:U,z:C,dir:_?"x":"y",rect:xs(ee),poly:ee,hidden:B})}}return x&&x.hidden<6?x:void 0},h=o.text,b=g(h),k;if(!b){let v=o.text.split(/(\s+)/);for(let M=v.length-1;M>0&&!b;M--){let x=v.slice(0,M).join("").trimEnd().replace(/[\s,;:·–-]+$/,"")+"\u2026";if(x.length<6)break;let T=g(x);T&&(b=T,h=x)}k=b?`label of route "${e.id}" shortened to "${h}": no clear floor for the whole text`:`label "${o.text}" of route "${e.id}" was dropped: blocks cover every spot beside it`,b?k+='; give it "along", "side" or "at", or move the nodes apart':k+='; give it "at: [x, y]", or move the nodes apart'}return b?(n.slants.push(b.poly),{svg:t.floorText(b.x,b.y,b.z+.01,h,i,b.dir,"start",a),warning:k}):{svg:"",warning:k}}function Ip(t,e,n,s,r){let o=e.on?s.find(d=>d.id===e.on):void 0,i=e.on&&!o?n.byId.get(e.on):void 0,a=e.at,l={"data-id":r,"data-hl":o?.id,"data-dim":o?void 0:"1"},c=e.kind??o?.kind??"control";if(e.floor){let d=a&&a.length>2?a[2]:o?o.points[0][2]:i?i.floor:.36,[u,f]=a?[a[0],a[1]]:o?[o.points[0][0]+.35,o.points[0][1]-.25]:i?[i.box.x0+.3,i.box.y1-.3]:[0,0];return t.floorText(u,f,d+.01,e.floor,`floor mono t-${c}`,e.dir??"x",e.anchor??"start",l)}if(e.face){let d=i?.box,[u,f,p]=a?[a[0],a[1],a[2]??.45]:d?[d.x0+.3,d.y1,d.z0+.13]:[0,0,0];return t.faceText(u,f,p,e.face,"slabname sm",Bt.sm,"left",e.anchor??"start",l)}if(e.label||e.sub){let d=i?.box,u=a?[a[0],a[1],a[2]??.36]:d?[(d.x0+d.x1)/2,(d.y0+d.y1)/2,d.z1+.75]:[0,0,0],[f,p]=Xe(u[0],u[1],u[2]),g=f+(e.dx??0),h=p-18+(e.dy??0),b=e.anchor??"middle",k="";return e.label&&(k+=t.text(g,h,e.label,"lbl",Bt.lbl,b)),e.sub&&(k+=t.text(g,e.label?h+14:h,e.sub,"sub mono",Bt.sub,b)),Ve("g",l,k)}return""}var dc=`
|
|
142
|
+
`)[0]}`,line:c.line,col:c.col,path:""})}function o(l,c={}){let d=vu(l),u=n.contents,f={line:1,col:1},p=g=>{let h=g?.range;h&&(f=r(h[0]))};p(u);for(let g=0;g<d.length;g++){let h=d[g];if(ct(u)){let b=u.items.find(v=>tt(v)&&Ge(v.key)&&String(v.key.value)===String(h));if(!b)break;if(c.key&&g===d.length-1)return p(b.key),f;p(b.key),u=b.value,u&&p(u)}else if(Lt(u)&&typeof h=="number"){if(u=u.items[h],!u)break;p(u)}else break}return f}function i(l){let c=n.contents;for(let p of vu(l)){if(ct(c)){let g=c.items.find(h=>tt(h)&&Ge(h.key)&&String(h.key.value)===String(p));if(!g)return;c=g.value}else if(Lt(c)&&typeof p=="number")c=c.items[p];else return;if(!c)return}let d=c.range;if(!d)return;let u=e.linePos(Math.max(d[0],d[1]-1)).line,f=t.split(/\r?\n/);for(;u>e.linePos(d[0]).line&&/^\s*(#.*)?$/.test(f[u-1]??"");)u--;return{start:e.linePos(d[0]).line,end:u}}let a=null;return n.errors.length||(a=n.toJS({maxAliasCount:100})),{data:a,locate:o,span:i,diags:s}}var Bp=new Set(["svg","g","defs","marker","symbol","title","desc","path","polygon","polyline","line","rect","circle","ellipse","text","tspan","linearGradient","radialGradient","stop","clipPath"]),Kp=new Set(["id","class","role","transform","viewBox","width","height","x","y","x1","y1","x2","y2","cx","cy","r","rx","ry","fx","fy","d","points","offset","gradientUnits","gradientTransform","markerWidth","markerHeight","refX","refY","orient","markerUnits","text-anchor","dominant-baseline","font-size","font-weight","letter-spacing","fill","stroke","stroke-width","stroke-dasharray","stroke-linecap","stroke-linejoin","opacity","fill-opacity","stroke-opacity","stop-color","stop-opacity","marker-start","marker-mid","marker-end","clip-path","preserveAspectRatio","vector-effect","paint-order","style"]),_p=new Set(["fill","stroke","marker-start","marker-mid","marker-end","clip-path","style"]),zp={amp:"&",lt:"<",gt:">",quot:'"',apos:"'","#39":"'"},Su=t=>t.replace(/&(amp|lt|gt|quot|apos|#39);/g,(e,n)=>zp[n]);function fc(t,e){return t.startsWith("data-")||t.startsWith("aria-")?/^[a-z][\w-]*$/.test(t):!(!Kp.has(t)||_p.has(t)&&/url\(\s*(?!['"]?#)|javascript:|expression\(|@import/i.test(e))}function pc(t){let e={name:"#root",attrs:[],children:[]},n=[{node:e,dropped:!1}],s=/<(?:!--)[\s\S]*?-->|<\/([a-zA-Z][\w:-]*)\s*>|<([a-zA-Z][\w:-]*)((?:\s+[\w:-]+="[^"]*")*)\s*(\/?)>|([^<]+)/g,r,o=0;for(;r=s.exec(t);){if(r.index!==o)throw new Error(`not the renderer's SVG at ${o}: ${JSON.stringify(t.slice(o,o+40))}`);o=s.lastIndex;let i=n[n.length-1];if(r[0].charAt(1)!=="!"){if(r[1]){if(n.length<2||i.node.name!==r[1])throw new Error(`a stray </${r[1]}>`);n.pop();continue}if(r[2]){let a=r[2],l=[];for(let u of r[3].matchAll(/([\w:-]+)="([^"]*)"/g)){let f=u[1],p=Su(u[2]);f==="xmlns"||f.startsWith("xmlns:")||fc(f,p)&&l.push([f,p])}let c={name:a,attrs:l,children:[]},d=i.dropped||!Bp.has(a);d||i.node.children.push(c),r[4]||n.push({node:c,dropped:d});continue}!i.dropped&&r[5].trim()&&i.node.children.push(Su(r[5]))}}if(o!==t.length)throw new Error(`not the renderer's SVG at ${o}`);if(n.length!==1)throw new Error(`<${n[n.length-1].node.name}> is never closed`);return e}var Vp="http://www.w3.org/2000/svg",Mu=t=>t.replace(/var\(--([a-zA-Z][\w-]*)/g,"var(--iso-$1");function Bo(t,e=document){let n=r=>{let o=e.createElementNS(Vp,r.name);for(let[i,a]of r.attrs)i==="style"?o.style.cssText=Mu(a):o.setAttribute(i,/var\(--/.test(a)?Mu(a):a);for(let i of r.children)o.append(typeof i=="string"?e.createTextNode(i):n(i));return o},s=pc(t).children.find(r=>typeof r!="string"&&r.name==="svg");if(!s)throw new Error("the drawing has no <svg>");return n(s)}var Gp=t=>t.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`),Ko=class t{name;attrs=[];children=[];style={};constructor(e){this.name=e}setAttribute(e,n){let s=this.attrs.findIndex(r=>r[0]===e);s>=0?this.attrs[s][1]=String(n):this.attrs.push([e,String(n)])}getAttribute(e){return this.attrs.find(n=>n[0]===e)?.[1]??null}append(...e){for(let n of e)n!=null&&this.children.push(n)}set textContent(e){this.children=[String(e)]}get textContent(){return this.children.map(e=>typeof e=="string"?e:e.textContent).join("")}toNode(){let e=Object.entries(this.style).filter(([,n])=>n!==""&&n!==void 0).map(([n,s])=>`${Gp(n)}:${s}`).join(";");return{name:this.name,attrs:e?[...this.attrs,["style",e]]:[...this.attrs],children:this.children.map(n=>n instanceof t?n.toNode():n)}}},$u={createElementNS:(t,e)=>new Ko(e)},Eu=t=>t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"),Hp=t=>Eu(t).replace(/"/g,""");function ia(t,e=new Set(["style"])){if(typeof t=="string")return Eu(t);let n=t.attrs.map(([r,o])=>` ${r}="${Hp(o)}"`).join("");if(!t.children.length)return`<${t.name}${n}/>`;let s=e.has(t.name)?t.children.map(r=>typeof r=="string"?r.replace(/<\//g,"<\\/"):ia(r,e)).join(""):t.children.map(r=>ia(r,e)).join("");return`<${t.name}${n}>${s}</${t.name}>`}var Yp=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function mc(t){let e=new TextEncoder().encode(t),n=e.length,s=Math.ceil((n+9)/64),r=new Uint8Array(s*64);r.set(e),r[n]=128;let o=new DataView(r.buffer);o.setUint32(r.length-4,n*8>>>0),o.setUint32(r.length-8,Math.floor(n/536870912));let i=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),a=new Uint32Array(64),l=(c,d)=>c>>>d|c<<32-d;for(let c=0;c<s;c++){for(let w=0;w<16;w++)a[w]=o.getUint32(c*64+w*4);for(let w=16;w<64;w++){let M=l(a[w-15],7)^l(a[w-15],18)^a[w-15]>>>3,y=l(a[w-2],17)^l(a[w-2],19)^a[w-2]>>>10;a[w]=a[w-16]+M+a[w-7]+y>>>0}let[d,u,f,p,g,h,b,v]=i;for(let w=0;w<64;w++){let M=v+(l(g,6)^l(g,11)^l(g,25))+(g&h^~g&b)+Yp[w]+a[w]>>>0,y=(l(d,2)^l(d,13)^l(d,22))+(d&u^d&f^u&f)>>>0;v=b,b=h,h=g,g=p+M>>>0,p=f,f=u,u=d,d=M+y>>>0}i[0]+=d,i[1]+=u,i[2]+=f,i[3]+=p,i[4]+=g,i[5]+=h,i[6]+=b,i[7]+=v}return[...i].map(c=>c.toString(16).padStart(8,"0")).join("")}function Tu(t){if(t!=="sha256")throw new Error(`only sha256 here, not ${t}`);let e="",n={update(s){return e+=s,n},digest(s){return mc(e)}};return n}var Uu={};hi(Uu,{BOARD_3D:()=>Xs,BOARD_CSS:()=>Hu,FLAT_DEFAULTS:()=>Fc,FLAT_FONTS:()=>jc,GRID_CSS:()=>Rc,LABEL_BUDGET:()=>Ca,MARKS_CSS:()=>Lc,Obstacles:()=>hr,PAGE_CSS:()=>Oc,PLAYER_CSS:()=>Ia,PLAYER_UI_CSS:()=>Nc,ROUTE_BUDGET:()=>xa,WALL_T:()=>fs,assembly:()=>Ta,baseCss:()=>Ra,boardCatalog:()=>Yu,boardDiagram:()=>qu,boardErrors:()=>Fa,boardOf:()=>br,boxAsset:()=>Ou,boxSilhouette:()=>Da,calloutRect:()=>Ec,cardAsset:()=>Bc,cloudPath:()=>xc,compileRaw:()=>zu,convexOverlap:()=>Ho,defaultLabel:()=>Lu,drawCloud:()=>ua,drawDecos:()=>yc,drawingCss:()=>Cc,durationFor:()=>Ac,facePainter:()=>da,flatHit:()=>Gu,floorAt:()=>zr,floorOf:()=>Yr,focusView:()=>_u,gateBox:()=>Vo,iconPainter:()=>_o,inConvex:()=>Tc,kindsCss:()=>la,labelRect:()=>Yo,layoutFlat:()=>Js,lineRectArea:()=>ju,localAt:()=>Hr,markCss:()=>ca,metricsMeasure:()=>Vu,midpoint:()=>Pc,noSource:()=>Ic,nodeKind:()=>mr,nodeKindOr:()=>Dn,offscreen:()=>Ea,openList:()=>kc,overlap2:()=>pa,overlaps:()=>gr,paddingOf:()=>Uo,parseEnd:()=>On,place:()=>ma,placeBoard:()=>Jo,placeCallout:()=>Ma,placeNodeLabel:()=>qo,placeholderIcon:()=>bc,plate:()=>Cu,polyBounds:()=>Os,polyRectArea:()=>Gr,rectArea:()=>$c,regionKind:()=>Dt,regionRole:()=>La,registerMarks:()=>Pu,renderScene:()=>Na,resolveSteps:()=>Aa,routeAll:()=>wa,screenToGrid:()=>Cs,silhouette:()=>Cn,simplify:()=>Go,snapMove:()=>Wo,wallHeight:()=>aa,wallsOf:()=>Oa});var Dt=(t,e)=>e!==void 0&&Object.hasOwn(t.regions,e)?t.regions[e]:void 0,mr=(t,e)=>t.nodes[e??t.defaultNode],Dn=(t,e)=>mr(t,e)??t.nodes[t.defaultNode],aa=t=>Object.values(t.regions).find(e=>e.shape==="walled")?.z[1]??.8,la=t=>Object.values(t.regions).map(e=>e.css??"").join("");var hc=Object.create(null),gc=[];function Pu(t){Object.assign(hc,t.icons??{}),Object.assign(Or,t.faces??{}),t.css&&!gc.includes(t.css)&&gc.push(t.css)}var ca=()=>gc.join(""),_o=t=>Object.hasOwn(hc,t)?hc[t]:void 0,da=t=>Object.hasOwn(Or,t)?Or[t]:void 0;function bc(t,e){let n=(e.x0+e.x1)/2,s=(e.y0+e.y1)/2,r=e.z1+.005,o=Math.min(.6,(e.x1-e.x0)*.24,(e.y1-e.y0)*.24),i=[[n-o,s-o,r],[n+o,s-o,r],[n+o,s+o,r],[n-o,s+o,r]];return t.poly(i,"ico-unknown")+t.line3([n-o*.3,s-o*.35,r],[n+o*.3,s-o*.35,r],"ico-unknown-q")+t.line3([n+o*.3,s-o*.35,r],[n,s+o*.1,r],"ico-unknown-q")+t.line3([n,s+o*.45,r],[n,s+o*.5,r],"ico-unknown-q")}function yc(t,e,n){let s="";for(let r of n??[])r==="terminal"?s+=yo(t,e,3):r==="envelope"?s+=bi(t,e):r==="bubble"?s+=yi(t,e):r==="file-lines"?s+=xi(t,e):typeof r=="object"&&(r.terminal&&(s+=yo(t,e,r.terminal)),r.icon&&(s+=(_o(r.icon)??bc)(t,e)));return s}var qp=(t,e)=>(t.deco??e.deco??[]).filter(n=>n!=="ghost");function Ou(t,e,n,s,r,o){let i={name:t,description:e,size:n,role:s,deco:r,draw:(a,l,c)=>a.blockFaces(l)+yc(a,l,qp(c,i))+(o?o(a,l):"")};return i}function Cu(t){let[e,n]=gi(t);return{x0:e-.75,y0:n-.75,x1:e+.75,y1:n+.75,z0:t.z0,z1:t.z0+.18}}function xc(t,e){let n=Math.max(8,Math.min(t,e)*.18),s=n*.55,r=s,o=s,i=t-s,a=e-s,l=(c,d,u,f)=>{let p=Math.hypot(u-c,f-d),g=Math.max(1,Math.round(p/(n*1.7))),h="";for(let b=1;b<=g;b++){let v=c+(u-c)*b/g,w=d+(f-d)*b/g,M=p/g/2*1.08;h+=` A${M.toFixed(1)},${M.toFixed(1)} 0 0 1 ${v.toFixed(1)},${w.toFixed(1)}`}return h};return`M${r.toFixed(1)},${o.toFixed(1)}`+l(r,o,i,o)+l(i,o,i,a)+l(i,a,r,a)+l(r,a,r,o)+"Z"}function ua(t,e){let n={...e,z0:e.z1},s=a=>{let[l,c]=Je(e.x0,e.y0,a);return[Bt,.5,-Bt,.5,l,c]},r=(e.x1-e.x0)*xt,o=(e.y1-e.y0)*xt,i=xc(r,o);return t.onMatrix(s(e.z0),r,o,()=>_e("path",{d:i,class:"lft cloud-side"}))+t.onMatrix(s(e.z1),r,o,()=>_e("path",{d:i,class:"top cloud-top"}))}function Lu(t,e){let[n,s]=Je((t.x0+t.x1)/2,(t.y0+t.y1)/2,t.z1+.75);return{x:n,y:s-18+(e?0:6),anchor:"middle"}}var fs=.16,wc=["right-of","left-of","below","behind"];function ma(t,e,n,s,r,o={},i){let a=[],l=(k,$,x,N=!1,F="error")=>{let J=n.locate(k,{key:N});a.push({severity:F,message:$,line:J.line,col:J.col,path:k,hint:x})},c=[],d=new Map,u=[],f=new Map,p=new Set([...Object.keys(s.roles),...Object.keys(o)]);function g(k,$){let x=d.get(k.id);if(x){let N=n.locate(x.path+"/id");return l(k.path+"/id",`duplicate id "${k.id}" (first used on line ${N.line})`),!1}return d.set(k.id,k),c.push(k),k.parent=$,$?$.children.push(k):u.push(k),!0}let h=()=>({x0:0,y0:0,z0:0,x1:0,y1:0,z1:0});function b(k,$,x){let N={id:k.id,type:"node",path:$,children:[],box:h(),floor:0,node:k,appears:k.appears,disappears:k.disappears};g(N,x)&&(k.nodes??[]).forEach((F,J)=>b(F,`${$}/nodes/${J}`,N))}function v(k,$,x){let N={id:k.id,type:"region",path:$,children:[],box:h(),floor:0,region:k,appears:k.appears,disappears:k.disappears};g(N,x)&&((k.nodes??[]).forEach((F,J)=>b(F,`${$}/nodes/${J}`,N)),(k.regions??[]).forEach((F,J)=>v(F,`${$}/regions/${J}`,N)))}(t.regions??[]).forEach((k,$)=>v(k,`${e}/regions/${$}`,void 0)),(t.nodes??[]).forEach((k,$)=>b(k,`${e}/nodes/${$}`,void 0));let w=()=>d.keys(),M=()=>c.filter(k=>k.type==="region").map(k=>k.id);for(let k of[...c]){let $=k.node??k.region;if($.in!==void 0){let N=d.get($.in);if(!N){l(k.path+"/in",`unknown region "${$.in}"`+zo($.in,M()));continue}if(N.type!=="region"){l(k.path+"/in",`"${$.in}" is a node, not a region; put nodes on a node with its own "nodes:" list`);continue}if(k.parent&&k.parent!==N){l(k.path+"/in",`"${k.id}" is written inside "${k.parent.id}" but says in: ${$.in}; use one or the other`);continue}for(let F=N;F;F=F.parent)if(F===k){l(k.path+"/in",`"${k.id}" cannot be inside itself`);continue}k.parent||(u.splice(u.indexOf(k),1),k.parent=N,N.children.push(k))}if(k.node){let N=k.node.asset;N!==void 0&&!mr(r,N)&&l(k.path+"/asset",`unknown asset "${N}"`+zo(N,Object.keys(r.nodes)),`assets: ${Object.keys(r.nodes).join(", ")}`)}let x=(k.node??k.region).role;x!==void 0&&!p.has(x)&&l(k.path+"/role",`unknown colour role "${x}"`+zo(x,p),`add it under "roles:" at the top of the file, or use one of: ${[...p].join(", ")}`)}for(let k of c){let $=k.region?.gate;if(!$?.node)continue;let x=d.get($.node);if(!x){l(k.path+"/gate/node",`unknown node "${$.node}"`+zo($.node,w()));continue}if(x.type!=="node"){l(k.path+"/gate/node",`"${$.node}" is a region; a gate is a node`);continue}x.placedBy=k.id;let N=x.node;(N.at||wc.some(F=>N[F]))&&l(x.path,`"${x.id}" is the gate of "${k.id}", which places it; its own placement is ignored`,void 0,!1,"warning")}let y=k=>k.gap??t.gap??2;function T(k){let $=k.node,x=Dn(r,$.asset),N=$.size,F=x.size[0],J=x.size[1],oe=x.size[2];if(N&&(F=N[0],J=N[1],N.length>2&&(oe=N[2])),k.placedBy){let ve=d.get(k.placedBy).region,B=ve.gate,W=B.width??2,ee=N?Math.min(F,J):.3;oe=N&&N.length>2?oe:B.height??(ve.height??aa(r))+.3,B.side==="e"||B.side==="w"?(F=ee,J=W):(F=W,J=ee)}return[F,J,oe]}function S(k,$,x,N,F){for(let be of $)I(be);let J=$.filter(be=>!be.placedBy),oe=new Set(J),ve=new Set,B=[],W=new Set,ee=be=>{let we=be.node??be.region,Ne=[];for(let qe of wc){let D=we[qe];if(D===void 0)continue;let se=d.get(D);if(!se){l(`${be.path}/${qe}`,`unknown id "${D}"`+zo(D,w()));continue}if(se===be){l(`${be.path}/${qe}`,`"${be.id}" cannot be placed ${qe} itself`);continue}if(!oe.has(se)){let Me=Oe=>Oe.parent?`"${Oe.parent.id}"`:"the scene";l(`${be.path}/${qe}`,`"${D}" is in ${Me(se)} but "${be.id}" is in ${Me(be)}; relative placement works between items in the same region`,se.placedBy?`"${D}" is a gate, placed by its ${d.get(se.placedBy)?.region?.kind??"region"}`:`place "${be.id}" relative to something in ${Me(be)}, or use "at:"`);continue}Ne.push(se)}if(!Ne.length&&!we.at){let qe=J.indexOf(be);qe>0&&Ne.push(J[qe-1])}return Ne},ue=be=>{if(!ve.has(be)){if(W.has(be)){l(be.path,`placement loop: "${be.id}" is placed relative to something placed relative to it`);return}W.add(be),ee(be).forEach(ue),W.delete(be),ve.add(be),B.push(be)}};J.forEach(ue);for(let be of B){let we=be.node??be.region,Ne=f.get(be),qe=wc.find(D=>we[D]!==void 0&&d.get(we[D])&&oe.has(d.get(we[D])));if(we.at&&qe&&l(`${be.path}/at`,`"${be.id}" has both "at" and "${qe}"; "at" wins`,void 0,!0,"warning"),we.at)Ne.x=we.at[0],Ne.y=we.at[1];else if(qe)P(Ne,f.get(d.get(we[qe])),qe,y(we),we.align??"center");else{let D=J.indexOf(be);D>0?P(Ne,f.get(J[D-1]),N==="row"?"right-of":"below",y(we),"center"):(Ne.x=x,Ne.y=x)}we.shift&&(Ne.x+=we.shift[0],Ne.y+=we.shift[1])}if(F||!J.length)return{w:0,d:0};let z=1/0,X=1/0,Q=-1/0,te=-1/0;for(let be of J){let we=f.get(be);z=Math.min(z,we.x),X=Math.min(X,we.y),Q=Math.max(Q,we.x+we.w),te=Math.max(te,we.y+we.d)}let ne=Math.min(0,z-x),fe=Math.min(0,X-x);if(ne||fe)for(let be of J){let we=f.get(be);we.x-=ne,we.y-=fe}return{w:Q-ne+x,d:te-fe+x}}function P(k,$,x,N,F){let J=()=>{k.y=F==="start"?$.y:F==="end"?$.y+$.d-k.d:$.y+($.d-k.d)/2},oe=()=>{k.x=F==="start"?$.x:F==="end"?$.x+$.w-k.w:$.x+($.w-k.w)/2};x==="right-of"?(k.x=$.x+$.w+N,J()):x==="left-of"?(k.x=$.x-N-k.w,J()):x==="below"?(k.y=$.y+$.d+N,oe()):(k.y=$.y-N-k.d,oe())}function I(k){if(k.type==="node"){let[B,W,ee]=T(k);f.set(k,{x:0,y:0,w:B,d:W,h:ee,z:k.node.z??0}),k.children.length&&S(k,k.children,0,"row",!0);return}let $=k.region,x=$.padding??Dt(r,$.kind)?.pad,N=!!$.size,F=S(k,k.children,x,$.flow??"row",N),J=$.size?$.size[0]:Math.max(F.w,x*2+.5),oe=$.size?$.size[1]:Math.max(F.d,x*2+.5);if(!$.size&&$.gate){let B=($.gate.width??2)+1;$.gate.side==="e"||$.gate.side==="w"?oe=Math.max(oe,B):J=Math.max(J,B)}let ve=$.size&&$.size.length>2?$.size[2]:$.height??Dt(r,$.kind).z[1];f.set(k,{x:0,y:0,w:J,d:oe,h:ve,z:0})}S(void 0,u,0,t.flow??"row",!0);function _(k,$,x,N){let F=f.get(k),J=$+F.x,oe=x+F.y;if(k.type==="region"){let ve=Dt(r,k.region.kind),[B]=ve.z,W=ve.floor,ee=ve.shape==="slab"&&Dt(r,k.parent?.region?.kind)?.shape==="slab"?0:B,ue=k.region.z??0,z=N+ee+ue,X=N+F.h+ue;k.box={x0:J,y0:oe,z0:z,x1:J+F.w,y1:oe+F.d,z1:X},k.floor=W?X:N}else{let ve=N+F.z;k.box={x0:J,y0:oe,z0:ve,x1:J+F.w,y1:oe+F.d,z1:ve+F.h},k.floor=k.box.z1}for(let ve of k.children)ve.placedBy||_(ve,J,oe,k.floor)}for(let k of u)k.placedBy||_(k,0,0,0);if(i){let k=x=>Math.round(x/i)*i,$=x=>Math.round(x*1e9)/1e9;for(let x of c){if(x.placedBy)continue;let N=x.box,F=k(N.x0),J=k(N.x1),oe=k(N.y0),ve=k(N.y1);J-F<i&&(J=F+i),ve-oe<i&&(ve=oe+i),x.box={...N,x0:$(F),x1:$(J),y0:$(oe),y1:$(ve)};let B=x.node??x.region;B.at&&B.at.forEach((W,ee)=>{let ue=W/i;Math.abs(ue-Math.round(ue))>1e-6&&l(`${x.path}/at/${ee}`,`${W} is not on the ${i} grid; it is drawn at ${$(k(W))}`,void 0,!1,"warning")})}}for(let k of c){let $=k.region?.gate;if(!$?.node)continue;let x=d.get($.node);!x||x.placedBy!==k.id||(x.box=Vo(k,f.get(x).h,f.get(x).w,f.get(x).d),x.floor=x.box.z1)}for(let k of c){let $=k.children.filter(x=>!x.placedBy);for(let x=0;x<$.length;x++)for(let N=x+1;N<$.length;N++){let F=$[x],J=$[N];fa(F,r)||fa(J,r)||pa(F.box,J.box)&&l(J.path,`"${J.id}" overlaps "${F.id}"`,'move one with "at", a relative placement, "gap" or "shift"',!1,"warning")}if(k.parent&&k.parent.type==="region"&&!k.placedBy){let x=k.parent.box,N=k.box,F=1e-6;(N.x0<x.x0-F||N.y0<x.y0-F||N.x1>x.x1+F||N.y1>x.y1+F)&&l(k.path,`"${k.id}" sticks out of region "${k.parent.id}"`,`make "${k.parent.id}" bigger, or leave out its "size" so it fits its contents`,!1,"warning")}}{let k=u.filter($=>!$.placedBy);for(let $=0;$<k.length;$++)for(let x=$+1;x<k.length;x++){let N=k[$],F=k[x];pa(N.box,F.box)&&!fa(N,r)&&!fa(F,r)&&l(F.path,`"${F.id}" overlaps "${N.id}"`,'move one with "at", a relative placement, "gap" or "shift"',!1,"warning")}}let O=new Set,j=a.filter(k=>{let $=k.path+k.message;return O.has($)?!1:(O.add($),!0)});return{items:c,byId:d,roots:u,diags:j,catalog:r}}var fa=(t,e)=>t.type==="region"&&["zone","tunnel"].includes(Dt(e,t.region.kind)?.shape??"");function Vo(t,e,n,s){let r=t.region.gate,o=t.box,i=t.box.z0,a=r.at??.5,l=r.width??2;if(r.side==="w"||r.side==="e"){let u=r.side==="w"?o.x0+fs/2:o.x1-fs/2,f=o.y0+(o.y1-o.y0)*a;return{x0:u-n/2,x1:u+n/2,y0:f-l/2,y1:f+l/2,z0:i,z1:i+e}}let c=r.side==="n"?o.y0+fs/2:o.y1-fs/2,d=o.x0+(o.x1-o.x0)*a;return{x0:d-l/2,x1:d+l/2,y0:c-s/2,y1:c+s/2,z0:i,z1:i+e}}function pa(t,e,n=1e-6){return t.x0<e.x1-n&&e.x0<t.x1-n&&t.y0<e.y1-n&&e.y0<t.y1-n}function zo(t,e){let n=Us(t,e);return n?` (did you mean "${n}"?)`:""}var As=.2,ha=.05,Up=.6,ga=.25,ba={n:[0,-1],s:[0,1],e:[1,0],w:[-1,0]};function On(t){let e=/^(.*?)(?:\.(n|e|s|w|top))?$/.exec(t);return{id:e[1],side:e[2]}}var Nu=new WeakMap;function zr(t,e,n){let s=Nu.get(t);if(!s){s=[];for(let i of t.items){if(i.type!=="region"||!Dt(t.catalog,i.region.kind)?.floor)continue;let a=0;for(let l=i.parent;l;l=l.parent)a++;s.push({r:i,d:a})}Nu.set(t,s)}let r=0,o=-1;for(let{r:i,d:a}of s){let l=i.box,c=1e-6;e>=l.x0-c&&e<=l.x1+c&&n>=l.y0-c&&n<=l.y1+c&&a>o&&(o=a,r=i.floor)}return r}function Wp(t,e){let n=[(t.x0+t.x1)/2,(t.y0+t.y1)/2],s=[(e.x0+e.x1)/2,(e.y0+e.y1)/2],r=s[0]-n[0],o=s[1]-n[1],i=Math.max(e.x0-t.x1,t.x0-e.x1),a=Math.max(e.y0-t.y1,t.y0-e.y1);return i>0&&(a<=0||i>=a)?r>0?"e":"w":a>0?o>0?"s":"n":Math.abs(r)>=Math.abs(o)?r>0?"e":"w":o>0?"s":"n"}var xa=5e5;function wa(t,e,n,s,r,o){let i=[],a=(M,y,T,S="error")=>{let P=s.locate(M);i.push({severity:S,message:y,line:P.line,col:P.col,path:M,hint:T})},l=t.routes??[],c={left:xa},d=0,u=()=>n.items.map(M=>M.id),f=new Map,p=[],g=[];l.forEach((M,y)=>{let T=`${e}/routes/${y}`;(f.has(M.id)||n.byId.has(M.id))&&a(T+"/id",`duplicate id "${M.id}"`),f.set(M.id,y);let S=M.kind??"send";r.has(S)||a(T+"/kind",`unknown flow kind "${S}"`+vc(S,r),`kinds: ${[...r].join(", ")}; add one under "kinds:"`);let P={id:M.id,raw:M,path:T,kind:S,points:[]},I=(_,O)=>{let{id:j}=On(_),k=n.byId.get(j);if(!k){a(`${T}/${O}`,`unknown node "${j}"`+vc(j,u()));return}return k};P.from=I(M.from,"from"),P.to=I(M.to,"to"),p.push(P),g.push({r:P})});let h=new Map;for(let M of g){let{r:y}=M;if(!y.from||!y.to||y.raw.points)continue;let T=On(y.raw.from).side,S=On(y.raw.to).side,P=y.raw.via?.[0],I=y.raw.via?.[y.raw.via.length-1],_=($,x)=>{if(Array.isArray($))return{x0:$[0],x1:$[0],y0:$[1],y1:$[1],z0:0,z1:0};if(typeof $=="string"){let N=n.byId.get(On($).id);if(N)return N.box}return x.box},O=($,x,N)=>{let F=x??Wp($.box,N);return{node:$,side:F,explicit:!!x,p:[0,0],z:0}};M.a=O(y.from,T,_(P,y.to)),M.b=O(y.to,S,_(I,y.from));let j=_(P,y.to),k=_(I,y.from);for(let[$,x]of[[M.a,j],[M.b,k]]){let N=`${$.node.id}.${$.side}`;h.has(N)||h.set(N,[]),h.get(N).push({e:$,other:[(x.x0+x.x1)/2,(x.y0+x.y1)/2]})}}for(let[,M]of h){let y=M[0].e,T=y.node.box,S=y.side,P=S==="e"||S==="w"?1:0;M.sort(($,x)=>$.other[P]-x.other[P]);let I=P?T.y0:T.x0,_=P?T.y1:T.x1,O=(I+_)/2,j=Math.max(0,_-I-.3),k=M.length>1?Math.min(Up,j/(M.length-1)):0;M.forEach(($,x)=>{let N=(x-(M.length-1)/2)*k,F=O+N,J=$.e.node.box.z0;if(S==="top"){$.e.p=[(T.x0+T.x1)/2,(T.y0+T.y1)/2],$.e.z=T.z1;return}let[oe,ve]=ba[S];$.e.p=P?[oe>0?T.x1+ha:T.x0-ha,F]:[F,ve>0?T.y1+ha:T.y0-ha],$.e.z=J})}let b=[];for(let M of n.items)M.type==="node"&&b.push(M.box);let v=[];for(let M of n.items.filter(y=>Dt(n.catalog,y.region?.kind)?.shape==="walled")){let{x0:y,y0:T,x1:S,y1:P}=M.box,I=fs,_=M.region.gate,O=[[{x0:y,y0:T,x1:S,y1:T+I,z0:0,z1:0},"n"],[{x0:y,y0:P-I,x1:S,y1:P,z0:0,z1:0},"s"],[{x0:y,y0:T,x1:y+I,y1:P,z0:0,z1:0},"w"],[{x0:S-I,y0:T,x1:S,y1:P,z0:0,z1:0},"e"]];for(let[j,k]of O)if(_&&_.side===k){if(_.node)continue;let $=_.at??.5,x=_.width??2;if(k==="e"||k==="w"){let N=T+(P-T)*$;v.push({...j,y1:N-x/2},{...j,y0:N+x/2})}else{let N=y+(S-y)*$;v.push({...j,x1:N-x/2},{...j,x0:N+x/2})}}else v.push(j)}let w=new Map;for(let M of g){let{r:y,a:T,b:S}=M;if(y.raw.points){y.points=y.raw.points.map(F=>[F[0],F[1],F.length>2?F[2]:zr(n,F[0],F[1])+.01]);continue}if(!T||!S)continue;let P=[];(y.raw.via??[]).forEach((F,J)=>{if(Array.isArray(F))if(o){let oe=ve=>Math.round(Math.round(ve/o)*o*1e9)/1e9;F.forEach((ve,B)=>{Math.abs(ve/o-Math.round(ve/o))>1e-6&&a(`${y.path}/via/${J}/${B}`,`${ve} is not on the ${o} grid; it is drawn at ${oe(ve)}`,void 0,"warning")}),P.push({p:[oe(F[0]),oe(F[1])]})}else P.push({p:[F[0],F[1]]});else{let{id:oe,side:ve}=On(F),B=n.byId.get(oe);if(!B){a(`${y.path}/via/${J}`,`unknown node "${oe}"`+vc(oe,u()));return}let W=ve&&ve!=="top"?ve:"n",[ee,ue]=ba[W],z=B.box;P.push({p:[ee?ee>0?z.x1+.4:z.x0-.4:(z.x0+z.x1)/2,ue?ue>0?z.y1+.4:z.y0-.4:(z.y0+z.y1)/2]})}});let _=b.filter(F=>F!==T.node.box&&F!==S.node.box).concat(y.raw.cross?[]:v).filter(F=>!ya(T.node.box,F)&&!ya(S.node.box,F)&&!ya(F,T.node.box)&&!ya(F,S.node.box)),O=T.side==="top"?void 0:ba[T.side],j=S.side==="top"?void 0:ba[S.side],k=[T.p,...P.map(F=>F.p),S.p],$=[T.p],x=O,N=!0;for(let F=0;F+1<k.length;F++){let J=F+2===k.length,oe=Xp(k[F],k[F+1],_,w,x,J&&j?[-j[0],-j[1]]:void 0,c);if(!oe){N=!1;break}$.push(...oe.slice(1));let ve=$.length;if(ve>=2){let B=Math.sign($[ve-1][0]-$[ve-2][0]),W=Math.sign($[ve-1][1]-$[ve-2][1]);x=[B,W]}}!N&&c.left<=0?(d++,$=[T.p,[S.p[0],T.p[1]],S.p]):N||(a(y.path,`no path found for route "${y.id}" from "${T.node.id}" to "${S.node.id}"`,'add "via" points, or use "points" to draw it by hand',"warning"),$=[T.p,[S.p[0],T.p[1]],S.p]),$=Go($);for(let F=0;F+1<$.length;F++)Jp(w,$[F],$[F+1]);y.points=em(n,$,T,S)}return d&&a(e,`${d} of ${p.length} routes were drawn as plain elbows: the scene is too large to route them all around what stands in the way (${xa.toLocaleString("en")} search steps)`,'split it into scenes, or give the busiest routes "via" points or "points"',"warning"),{routes:p,diags:i}}function ya(t,e){return e.x0>=t.x0-1e-6&&e.x1<=t.x1+1e-6&&e.y0>=t.y0-1e-6&&e.y1<=t.y1+1e-6&&e.z0>=t.z1-1e-6}var Ru=(t,e)=>`${Math.round(t/As)},${Math.round(e/As)}`;function Jp(t,e,n){let s=Math.max(1,Math.round(Math.hypot(n[0]-e[0],n[1]-e[1])/As));for(let r=0;r<=s;r++){let o=Ru(e[0]+(n[0]-e[0])*r/s,e[1]+(n[1]-e[1])*r/s);t.set(o,(t.get(o)??0)+1)}}function Iu(t,e,n){for(let s of n)if(t>s.x0-ga&&t<s.x1+ga&&e>s.y0-ga&&e<s.y1+ga)return!0;return!1}function Xp(t,e,n,s,r,o,i={left:1/0}){if((Math.abs(t[0]-e[0])<1e-6||Math.abs(t[1]-e[1])<1e-6)&&Zp(t,e,n)){let B=[Math.sign(e[0]-t[0]),Math.sign(e[1]-t[1])],W=!r||r[0]===B[0]&&r[1]===B[1],ee=!o||o[0]===B[0]&&o[1]===B[1];if(W&&ee)return[t,e]}if(i.left<=0)return null;let a=B=>Math.round((B-t[0])/As),l=B=>Math.round((B-t[1])/As),c=B=>t[0]+B*As,d=B=>t[1]+B*As,u=a(e[0]),f=l(e[1]),p=30,g=Math.min(0,u)-p,h=Math.max(0,u)+p,b=Math.min(0,f)-p,v=Math.max(0,f)+p,w=1.2,M=As,y=.06,T=[[1,0],[-1,0],[0,1],[0,-1]],S=h-g+1,P=v-b+1,I=(B,W)=>(B-g)*P+(W-b),_=new Int8Array(S*P).fill(-1),O=new Float64Array(S*P).fill(-1),j=new Float64Array(S*P*4).fill(1/0),k=(B,W)=>{let ee=I(B,W);return _[ee]<0&&(_[ee]=Iu(c(B),d(W),n)?1:0),_[ee]===1},$=(B,W)=>{let ee=I(B,W);return O[ee]<0&&(O[ee]=s.get(Ru(c(B),d(W)))??0),O[ee]},x=kc(),N=(B,W)=>(Math.abs(B-u)+Math.abs(W-f))*M,F=r?T.findIndex(B=>B[0]===r[0]&&B[1]===r[1]):-1;x.push({i:0,j:0,d:F,g:0,f:N(0,0),idx:0,hp:0});let J=(B,W)=>Math.abs(B)+Math.abs(W)<=2,oe=(B,W)=>Math.abs(B-u)+Math.abs(W-f)<=2,ve=0;for(;x.length()&&ve++<2e5;){if(i.left--<=0)return null;let B=x.take();if(B.i===u&&B.j===f&&!(o&&B.d>=0&&(T[B.d][0]!==o[0]||T[B.d][1]!==o[1]))){let W=[];for(let ee=B;ee;ee=ee.prev)W.push([c(ee.i),d(ee.j)]);return W.reverse(),W[0]=t,Qp(Go(W),e)}for(let W=0;W<4;W++){let ee=T[W];if(B.d>=0&&ee[0]===-T[B.d][0]&&ee[1]===-T[B.d][1])continue;let ue=B.i+ee[0],z=B.j+ee[1];if(ue<g||ue>h||z<b||z>v||!J(ue,z)&&!oe(ue,z)&&k(ue,z))continue;if((J(ue,z)||oe(ue,z))&&k(ue,z)&&!(ue===u&&z===f)){let ne=J(ue,z)?r:o&&[-o[0],-o[1]];if(!ne||(J(ue,z)?ee[0]!==ne[0]||ee[1]!==ne[1]:ee[0]!==o[0]||ee[1]!==o[1]))continue}let X=B.d>=0&&B.d!==W?w:0,Q=B.g+M+X+$(ue,z)*y,te=I(ue,z)*4+W;j[te]<=Q||(j[te]=Q,x.push({i:ue,j:z,d:W,g:Q,f:Q+N(ue,z),prev:B,idx:0,hp:0}))}}return null}function kc(){let t=[],e=[],n=(i,a)=>i.f<a.f||i.f===a.f&&i.idx<a.idx,s=(i,a)=>{let l=e[i];e[i]=e[a],e[a]=l,e[i].hp=i,e[a].hp=a},r=i=>{for(;i>0;){let a=i-1>>1;if(!n(e[i],e[a]))break;s(i,a),i=a}},o=i=>{for(;;){let a=2*i+1,l=a+1,c=i;if(a<e.length&&n(e[a],e[c])&&(c=a),l<e.length&&n(e[l],e[c])&&(c=l),c===i)return;s(i,c),i=c}};return{length:()=>t.length,push(i){i.idx=t.length,t.push(i),i.hp=e.length,e.push(i),r(i.hp)},take(){let i=e[0],a=e.pop();e.length&&(e[0]=a,a.hp=0,o(0));let l=t.pop();return l!==i&&(t[i.idx]=l,l.idx=i.idx,r(l.hp)),i}}}function Qp(t,e){let n=t.map(o=>[o[0],o[1]]),s=n.length,r=n[s-1];if(s>=2){let o=n[s-2];Math.abs(o[1]-r[1])<1e-9?(o[1]=e[1],s>=3&&Math.abs(n[s-3][1]-r[1])<1e-9&&(n[s-3][1]=e[1])):Math.abs(o[0]-r[0])<1e-9&&(o[0]=e[0],s>=3&&Math.abs(n[s-3][0]-r[0])<1e-9&&(n[s-3][0]=e[0]))}return n[s-1]=e,Go(n)}function Zp(t,e,n){let s=Math.max(1,Math.round(Math.hypot(e[0]-t[0],e[1]-t[1])/(As/2)));for(let r=2;r<s-1;r++)if(Iu(t[0]+(e[0]-t[0])*r/s,t[1]+(e[1]-t[1])*r/s,n))return!1;return!0}function Go(t){let e=[];for(let n of t){let s=e.length;if(!(s&&Math.abs(e[s-1][0]-n[0])<1e-6&&Math.abs(e[s-1][1]-n[1])<1e-6)){if(s>=2){let r=e[s-2],o=e[s-1];if(Math.abs(r[0]-o[0])<1e-6&&Math.abs(o[0]-n[0])<1e-6||Math.abs(r[1]-o[1])<1e-6&&Math.abs(o[1]-n[1])<1e-6){e[s-1]=n;continue}}e.push(n)}}return e}function em(t,e,n,s){let r=new Set,o=new Set;for(let c of t.items)c.type!=="region"||!Dt(t.catalog,c.region.kind)?.floor||(r.add(c.box.x0),r.add(c.box.x1),o.add(c.box.y0),o.add(c.box.y1));let i=[],a=(c,d)=>zr(t,c,d)+.01;for(let c=0;c+1<e.length;c++){let[d,u]=e[c],[f,p]=e[c+1],g=[0,1];if(Math.abs(u-p)<1e-6)for(let h of r){let b=(h-d)/(f-d);b>1e-6&&b<1-1e-6&&g.push(b)}else for(let h of o){let b=(h-u)/(p-u);b>1e-6&&b<1-1e-6&&g.push(b)}g.sort((h,b)=>h-b);for(let h=0;h+1<g.length;h++){let b=g[h],v=g[h+1],w=(b+v)/2,M=a(d+(f-d)*w,u+(p-u)*w),y=[d+(f-d)*b,u+(p-u)*b,M],T=[d+(f-d)*v,u+(p-u)*v,M],S=i[i.length-1];S&&(Math.abs(S[0]-y[0])>1e-6||Math.abs(S[1]-y[1])>1e-6||Math.abs(S[2]-y[2])>1e-6)?i.push(y):S||i.push(y),i.push(T)}}i.length&&(i[0][2]=n.side==="top"?n.z:n.node.box.z0+.01,i[i.length-1][2]=s.side==="top"?s.z:s.node.box.z0+.01);let l=[];for(let c of i){let d=l.length;if(d>=2){let u=l[d-2],f=l[d-1],p=Math.abs(u[2]-f[2])<1e-9&&Math.abs(f[2]-c[2])<1e-9,g=Math.abs(u[0]-f[0])<1e-6&&Math.abs(f[0]-c[0])<1e-6||Math.abs(u[1]-f[1])<1e-6&&Math.abs(f[1]-c[1])<1e-6;if(p&&g){l[d-1]=c;continue}}l.push(c)}return l}function vc(t,e){let n=Us(t,e);return n?` (did you mean "${n}"?)`:""}function Cn(t){return[Je(t.x0,t.y0,t.z1),Je(t.x1,t.y0,t.z1),Je(t.x1,t.y0,t.z0),Je(t.x1,t.y1,t.z0),Je(t.x0,t.y1,t.z0),Je(t.x0,t.y1,t.z1)]}function Os(t){let e=t.map(o=>o[0]),n=t.map(o=>o[1]),s=Math.min(...e),r=Math.min(...n);return{x:s,y:r,w:Math.max(...e)-s,h:Math.max(...n)-r}}function Gr(t,e){let n=t,s=(a,l)=>{let c=[];for(let d=0;d<n.length;d++){let u=n[d],f=n[(d+1)%n.length],p=a(u),g=a(f);p&&c.push(u),p!==g&&c.push(l(u,f))}n=c},r=a=>(l,c)=>[a,l[1]+(c[1]-l[1])*(a-l[0])/(c[0]-l[0])],o=a=>(l,c)=>[l[0]+(c[0]-l[0])*(a-l[1])/(c[1]-l[1]),a];if(s(a=>a[0]>=e.x,r(e.x)),!n.length||(s(a=>a[0]<=e.x+e.w,r(e.x+e.w)),!n.length)||(s(a=>a[1]>=e.y,o(e.y)),!n.length)||(s(a=>a[1]<=e.y+e.h,o(e.y+e.h)),!n.length))return 0;let i=0;for(let a=0;a<n.length;a++){let l=n[a],c=n[(a+1)%n.length];i+=l[0]*c[1]-c[0]*l[1]}return Math.abs(i)/2}function $c(t,e){let n=Math.min(t.x+t.w,e.x+e.w)-Math.max(t.x,e.x),s=Math.min(t.y+t.h,e.y+e.h)-Math.max(t.y,e.y);return n>0&&s>0?n*s:0}function ju(t,e){let n=0;for(let s=0;s+1<t.length;s++){let r=t[s],o=t[s+1],i=Math.hypot(o[0]-r[0],o[1]-r[1]),a=Math.max(1,Math.ceil(i/4));for(let l=0;l<a;l++){let c=r[0]+(o[0]-r[0])*(l+.5)/a,d=r[1]+(o[1]-r[1])*(l+.5)/a;c>=e.x&&c<=e.x+e.w&&d>=e.y&&d<=e.y+e.h&&(n+=i/a*4)}}return n}var Ps=64,ka=class{cells=new Map;n=0;add(e,n,s,r,o){for(let i=Math.floor(n/Ps);i<=Math.floor(r/Ps);i++)for(let a=Math.floor(s/Ps);a<=Math.floor(o/Ps);a++){let l=i*1048576+a,c=this.cells.get(l);c||this.cells.set(l,c=[]),c[c.length-1]!==e&&c.push(e)}}query(e,n,s,r){let o=new Set;for(let i=Math.floor(e/Ps);i<=Math.floor(s/Ps);i++)for(let a=Math.floor(n/Ps);a<=Math.floor(r/Ps);a++){let l=this.cells.get(i*1048576+a);if(l)for(let c of l)o.add(c)}return[...o].sort((i,a)=>i-a)}},Sc=t=>{let e=1/0,n=1/0,s=-1/0,r=-1/0;for(let[o,i]of t)o<e&&(e=o),o>s&&(s=o),i<n&&(n=i),i>r&&(r=i);return[e,n,s,r]},Sa=new WeakMap;function Ws(t,e){let n=Sa.get(t);for((!n||n.n>t.length)&&Sa.set(t,n=new ka);n.n<t.length;n.n++){let[s,r,o,i]=e(t[n.n]);n.add(n.n,s,r,o,i)}return n}function Du(t){let e=Sa.get(t);for((!e||e.n>t.length)&&Sa.set(t,e=new ka);e.n<t.length;e.n++){let n=t[e.n].pts;for(let s=0;s+1<n.length;s++){let r=n[s],o=n[s+1],i=e.n*65536+s,a=Math.max(1,Math.ceil(Math.hypot(o[0]-r[0],o[1]-r[1])/(Ps/2)));for(let l=0;l<a;l++){let c=l/a,d=(l+1)/a,u=r[0]+(o[0]-r[0])*c,f=r[1]+(o[1]-r[1])*c,p=r[0]+(o[0]-r[0])*d,g=r[1]+(o[1]-r[1])*d;e.add(i,Math.min(u,p)-1,Math.min(f,g)-1,Math.max(u,p)+1,Math.max(f,g)+1)}}}return e}var ps=(t,e,n,s,r)=>t.query(e,n,s,r),Vr=t=>Sc(t),va=t=>[t.x,t.y,t.x+t.w,t.y+t.h];function Fu(t,e,n,[s,r,o,i]){let a=0,l=n-1;for(let c of[0,1]){let d=e[c]-t[c],u=c?r:s,f=c?i:o;if(Math.abs(d)<1e-12){if(t[c]<u||t[c]>f)return[1,0];continue}let p=(u-t[c])/d*n-.5,g=(f-t[c])/d*n-.5;p>g&&([p,g]=[g,p]),a=Math.max(a,Math.floor(p)-1),l=Math.min(l,Math.ceil(g)+1)}return[a,l]}var hr=class t{polys=[];rects=[];lines=[];solids=[];slants=[];budget={spots:1/0,over:!1,told:!1};hidden(e){let n=0;for(let s of ps(Ws(this.solids,Vr),...va(e)))n+=Gr(this.solids[s],e);return n}hiddenPoly(e){let n=0;for(let s of ps(Ws(this.solids,Vr),...Sc(e)))n+=Ho(e,this.solids[s]);return n}costPoly(e,n=1/0){let s=Sc(e),r=0;for(let o of ps(Ws(this.polys,i=>Vr(i.poly)),...s))r+=Ho(e,this.polys[o].poly);for(let o of ps(Ws(this.rects,i=>va(i.r)),...s))r+=Gr(e,this.rects[o].r)*2;for(let o of ps(Ws(this.slants,Vr),...s))r+=Ho(e,this.slants[o])*2;if(r>=n)return r;for(let o of ps(Du(this.lines),...s)){if(r>=n)return r;let i=this.lines[Math.floor(o/65536)].pts,a=o%65536,l=i[a],c=i[a+1],d=Math.hypot(c[0]-l[0],c[1]-l[1]),u=Math.max(1,Math.ceil(d/4)),[f,p]=Fu(l,c,u,s);for(let g=f;g<=p;g++)Tc(e,[l[0]+(c[0]-l[0])*(g+.5)/u,l[1]+(c[1]-l[1])*(g+.5)/u])&&(r+=d/u*4*.6)}return r}cost(e,n,s=.6){let r=va(e),o=0;for(let i of ps(Ws(this.polys,a=>Vr(a.poly)),...r)){let a=this.polys[i];o+=Gr(a.poly,e)*(a.owner===n?1.5:1)}for(let i of ps(Ws(this.rects,a=>va(a.r)),...r)){let a=this.rects[i];(a.owner!==n||!n)&&(o+=$c(a.r,e)*2)}for(let i of ps(Ws(this.slants,Vr),...r))o+=Gr(this.slants[i],e)*2;if(s){let i=-1,a=0;for(let l of ps(Du(this.lines),...r)){let c=Math.floor(l/65536);c!==i&&(i>=0&&(o+=a*s),i=c,a=0);let d=this.lines[c].pts,u=l%65536,f=d[u],p=d[u+1],g=Math.hypot(p[0]-f[0],p[1]-f[1]),h=Math.max(1,Math.ceil(g/4)),[b,v]=Fu(f,p,h,r);for(let w=b;w<=v;w++){let M=f[0]+(p[0]-f[0])*(w+.5)/h,y=f[1]+(p[1]-f[1])*(w+.5)/h;M>=e.x&&M<=e.x+e.w&&y>=e.y&&y<=e.y+e.h&&(a+=g/h*4)}}i>=0&&(o+=a*s)}return o}fork(){let e=new t;return e.budget=this.budget,e.polys=this.polys,e.lines=this.lines,e.solids=this.solids,e.rects=[...this.rects],e.slants=this.slants,e}},Bu=14;function Yo(t,e,n,s){let r=Math.max(t.name?Rn(t.name,It.lbl):0,t.sub?Rn(t.sub,It.sub):0)+4,o=(t.name?1:0)+(t.sub?1:0),i=n-(t.name?11:9)-1,a=(o-1)*Bu+(t.name?11:9)+4;return{x:s==="start"?e-2:s==="end"?e-r+2:e-r/2,y:i,w:r,h:a}}function qo(t,e,n,s,r,o){let i=Os(n),a=Je((e.x0+e.x1)/2,(e.y0+e.y1)/2,e.z1)[0],c=((t.name?1:0)+(t.sub?1:0)-1)*Bu+4,d=i.y-6-c,u=i.y+Math.min(i.h,60)*.45,f=[];o&&f.push({...o,pen:0}),f.push({x:a,y:d,anchor:"middle",pen:o?20:0});for(let h of[12,24,40])f.push({x:a,y:d-h,anchor:"middle",pen:20+h});for(let h of[-30,30,-60,60])f.push({x:a+h,y:d-4,anchor:"middle",pen:30+Math.abs(h)});f.push({x:i.x+i.w+8,y:u,anchor:"start",pen:120}),f.push({x:i.x-8,y:u,anchor:"end",pen:120}),f.push({x:a,y:i.y+i.h+14,anchor:"middle",pen:300});let p,g=1/0;for(let h of f){let b=Yo(t,h.x,h.y,h.anchor),v=s.cost(b,r,.15)*2+h.pen;v<g&&(g=v,p={x:h.x,y:h.y,anchor:h.anchor,rect:b})}return p}function Ec(t,e,n,s){return{x:(s==="start"?e:s==="end"?e-t:e-t/2)-2,y:n-14,w:t+4,h:28}}function Ma(t,e,n,s,r){let o=[{...s,pen:0}];for(let d of[-46,-66,-86,-106,-126,-146])for(let u of[0,-70,70,-140,140])o.push({x:e+u,y:n+d,anchor:"middle",pen:10+(-d-46)*.5+Math.abs(u)*.4});for(let d of[34,60,86])o.push({x:e,y:n+d,anchor:"middle",pen:60+d*.3});let i=s.x-e,a=s.y-n;for(let d of[-1,1])for(let u of[16,32,48])o.push({...s,y:n+a+d*u,x:e+i,pen:5+u});for(let d of[-1,1])for(let u of[30,60,90])for(let f of[0,16,-16])o.push({...s,x:e+i+d*u,y:n+a+f,pen:8+u*.6+Math.abs(f)});let l,c=1/0;for(let d of o){let u=Ec(t,d.x,d.y,d.anchor),f=r.cost(u,void 0,.05)*3+d.pen;f<c&&(c=f,l={x:d.x,y:d.y,anchor:d.anchor,rect:u})}return l}var Ku=t=>{let e=0;for(let n=0;n<t.length;n++){let s=t[n],r=t[(n+1)%t.length];e+=s[0]*r[1]-r[0]*s[1]}return e/2},Mc=t=>Ku(t)<0?[...t].reverse():t;function Tc(t,e){let n=Mc(t);for(let s=0;s<n.length;s++){let r=n[s],o=n[(s+1)%n.length];if((o[0]-r[0])*(e[1]-r[1])-(o[1]-r[1])*(e[0]-r[0])<0)return!1}return!0}function Ho(t,e){let n=Mc(t),s=Mc(e);for(let r=0;r<s.length&&n.length;r++){let o=s[r],i=s[(r+1)%s.length],a=c=>(i[0]-o[0])*(c[1]-o[1])-(i[1]-o[1])*(c[0]-o[0]),l=n;n=[];for(let c=0;c<l.length;c++){let d=l[c],u=l[(c+1)%l.length],f=a(d),p=a(u);if(f>=0&&n.push(d),f>=0!=p>=0){let g=f/(f-p);n.push([d[0]+(u[0]-d[0])*g,d[1]+(u[1]-d[1])*g])}}}return n.length>=3?Math.abs(Ku(n)):0}var $a=24;function Ea(t,e){let[n,s,r,o]=e,i=t.x+t.w/2,a=t.y+t.h/2,l=[["left",i-n],["right",n+r-i],["top",a-s],["bottom",s+o-a]];l.sort((d,u)=>d[1]-u[1]);let c=l[0][0];return c==="left"?{edge:c,dx:-(t.x+t.w-n)-$a,dy:0}:c==="right"?{edge:c,dx:n+r-t.x+$a,dy:0}:c==="top"?{edge:c,dx:0,dy:-(t.y+t.h-s)-$a}:{edge:c,dx:0,dy:s+o-t.y+$a}}function Ta(t,e,n){let s=y=>{let T=0;for(let S=y.parent;S;S=S.parent)T++;return T},r=y=>y.box.x0+y.box.y0+y.box.z0*.01,o=t.items.filter(y=>y.type==="region").sort((y,T)=>s(y)-s(T)||r(y)-r(T)),i=t.items.filter(y=>y.type==="node").sort((y,T)=>r(y)-r(T)||y.box.z0-T.box.z0),a=[],l=Math.min(90,400/Math.max(1,o.length)),c=650;o.forEach((y,T)=>{let S=Os(Cn(y.box));a.push({id:y.id,kind:"region",...Ea(S,n),delay:Math.round(T*l),dur:c,bbox:S})});let d=250+Math.round(l*o.length),u=Math.min(70,700/Math.max(1,i.length)),f=600;i.forEach((y,T)=>{let S=Os(Cn(y.box));a.push({id:y.id,kind:"node",...Ea(S,n),delay:Math.round(d+T*u),dur:f,bbox:S})});let p=i.length?d+(i.length-1)*u:d,g=Math.round(p+300),h=Math.min(30,300/Math.max(1,e.length)),b=400,v=e.filter(y=>y.points.length>=2).map((y,T)=>({id:y.id,delay:Math.round(g+T*h),dur:b})),w={delay:g+200,dur:400},M=Math.max(...a.map(y=>y.delay+y.dur),...v.map(y=>y.delay+y.dur),w.delay+w.dur);return{pieces:a,routes:v,labels:w,total:M}}function Ac(t){return Math.max(5600,Math.min(12500,2600+t.length*40))}function Aa(t,e,n,s,r,o){let i=[],a=(O,j,k,$="error")=>{let x=r.locate(O);i.push({severity:$,message:j,line:x.line,col:x.col,path:O,hint:k})},l=t.steps??[],c=new Set(Object.keys(o.kinds)),d=new Map(s.map(O=>[O.id,O])),u=()=>[...n.byId.keys(),...d.keys()],f=new Map;l.forEach((O,j)=>{O.id&&(f.has(O.id)&&a(`${e}/steps/${j}/id`,`duplicate step id "${O.id}"`),f.set(O.id,j+1))});let p=l.length,g=(O,j)=>{if(typeof O=="number"){if(O<1||O>p){a(j,`there is no step ${O}; this scene has ${p} step(s)`);return}return O}let k=f.get(O);return k===void 0&&a(j,`unknown step "${O}"`+Fn(O,f.keys())),k},h=O=>us(o,o.kinds[O]?.color??"control"),b=[],v=O=>{b.includes(O)||b.push(O)};for(let O of s)v(O.kind);let w={},M=(O,j,k,$)=>{if(j===void 0&&k===void 0)return;let x=j!==void 0?g(j,$+"/appears"):1,N=k!==void 0?g(k,$+"/disappears"):p+1;w[O]=Array.from({length:p},(F,J)=>J+1>=(x??1)&&J+1<(N??p+1))};for(let O of n.items)M(O.id,O.appears,O.disappears,O.path);for(let O of s)M(O.id,O.raw.appears,O.raw.disappears,O.path);let y=[],T=[],S=[],P=[],I=()=>{for(let O of s){if(O.raw.appears!==void 0||O.raw.disappears!==void 0)continue;let j=[O.from,O.to].map(k=>k&&(w[k.id]??_(k)));j.some(Boolean)&&(w[O.id]=Array.from({length:p},(k,$)=>j.every(x=>!x||x[$])))}},_=O=>{for(let j=O.parent;j;j=j.parent)if(w[j.id])return w[j.id]};return l.forEach((O,j)=>{let k=j+1,$=`${e}/steps/${j}`,x=O.kind??"control";c.has(x)||a($+"/kind",`unknown flow kind "${x}"`+Fn(x,c)),v(x);let N=new Set,F=[];(O.animate??[]).forEach((B,W)=>{let ee=Array.isArray(B)?B:[B],ue=[];ee.forEach((z,X)=>{let Q=Array.isArray(B)?`${$}/animate/${W}/${X}`:`${$}/animate/${W}`,te,ne;if(typeof z=="string"){let we=/^([^:\s]+)\s*(?::\s*(\S+))?$/.exec(z.trim());te=we?we[1]:z,ne=we?.[2]}else{let we=Object.entries(z)[0];te=we[0],ne=we[1]}let fe=d.get(te);if(!fe){a(Q,`unknown route "${te}"`+Fn(te,d.keys()));return}if(ne&&!c.has(ne)){a(Q,`unknown flow kind "${ne}"`+Fn(ne,c));return}let be=ne??fe.kind;v(be),ue.push({route:te,kind:be,color:h(be)}),N.add(te),fe.from&&N.add(fe.from.id),fe.to&&N.add(fe.to.id)}),ue.length&&F.push(ue)});let J=[];(O.pulse??[]).forEach((B,W)=>{let ee=n.byId.get(B);if(!ee){a(`${$}/pulse/${W}`,`unknown node "${B}"`+Fn(B,n.byId.keys()));return}let ue,z,X,Q,te=ee.node?mr(n.catalog,ee.node.asset):void 0;if(te?.pulse)[ue,z,X,Q]=te.pulse(ee.box);else{let be=ee.box;ue=(be.x0+be.x1)/2,z=(be.y0+be.y1)/2,X=be.z1,Q=Math.max(22,Math.min(60,(be.x1-be.x0+be.y1-be.y0)*8.5))}let[ne,fe]=Je(ue,z,X);J.push([ne,fe,Q*1.7,Q*.98]),N.add(B)}),(O.highlight??[]).forEach((B,W)=>{!n.byId.has(B)&&!d.has(B)&&a(`${$}/highlight/${W}`,`unknown id "${B}"`+Fn(B,u())),N.add(B)});for(let[B,W]of[["show",!0],["hide",!1]])(O[B]??[]).forEach((ee,ue)=>{if(!n.byId.has(ee)&&!d.has(ee)){a(`${$}/${B}/${ue}`,`unknown id "${ee}"`+Fn(ee,u()));return}let z=w[ee]??(w[ee]=Array(p).fill(!W));for(let X=j;X<p;X++)z[X]=W});if((O.say??[]).forEach((B,W)=>{let ee,ue;if(Array.isArray(B.at))[ee,ue]=Je(B.at[0],B.at[1],B.at[2]??.36);else{let X=n.byId.get(B.at);if(!X){a(`${$}/say/${W}/at`,`unknown node "${B.at}"`+Fn(B.at,n.byId.keys()));return}let Q=X.box;[ee,ue]=Je((Q.x0+Q.x1)/2,(Q.y0+Q.y1)/2,Q.z1+.75)}let z=B.kind??x;c.has(z)||a(`${$}/say/${W}/kind`,`unknown flow kind "${z}"`+Fn(z,c)),T.push({step:k,x:ee+(B.dx??0),y:ue+(B.dy??(Array.isArray(B.at)?0:-46)),ax:ee,ay:ue,text:B.text,kind:z,anchor:B.anchor??"middle"})}),(O.mark??[]).forEach((B,W)=>{if(B.at){S.push({step:k,p:[B.at[0],B.at[1],B.at[2]??.36]});return}let ee=B.on?d.get(B.on):void 0;if(!ee){a(`${$}/mark/${W}`,B.on?`unknown route "${B.on}"`+Fn(B.on,d.keys()):'a mark needs "on: ROUTE" or "at: [x, y]"');return}let ue=ee.points[ee.points.length-1];S.push({step:k,p:[ue[0],ue[1],ue[2]+.6],on:ee.id}),N.add(ee.id)}),t.badges&&O.badge!==!1){let B=Array.isArray(O.badge)?[O.badge[0],O.badge[1],O.badge[2]??.36]:void 0,W=typeof O.badge=="string"?O.badge:F[0]?.[0]?.route,ee=W?d.get(W):void 0;if(!B)if(ee)B=Pc(ee.points);else if(W&&n.byId.get(W)){let ue=n.byId.get(W).box;B=[(ue.x0+ue.x1)/2,(ue.y0+ue.y1)/2,ue.z1+.3]}else typeof O.badge=="string"&&a(`${$}/badge`,`unknown id "${O.badge}"`+Fn(O.badge,u()));B&&P.push({step:k,num:O.number??k,kind:x,p:B})}for(let B of[...N])for(let W=n.byId.get(B)?.parent;W;W=W.parent)N.add(W.id);for(let B of n.items)B.region?.kind==="tunnel"&&(B.region.around??[]).some(W=>N.has(W))&&N.add(B.id);let oe;if(O.focus?.length){let B=1/0,W=1/0,ee=-1/0,ue=-1/0;O.focus.forEach((z,X)=>{let Q=n.byId.get(z);if(!Q){a(`${$}/focus/${X}`,`unknown node or region "${z}"`+Fn(z,n.byId.keys()));return}let te=Q.box;for(let[ne,fe,be]of[[te.x0,te.y0,te.z1],[te.x1,te.y0,te.z0],[te.x0,te.y1,te.z0],[te.x1,te.y1,te.z0],[te.x1,te.y0,te.z1],[te.x0,te.y1,te.z1]]){let[we,Ne]=Je(ne,fe,be);B=Math.min(B,we),W=Math.min(W,Ne),ee=Math.max(ee,we),ue=Math.max(ue,Ne)}N.add(z)}),B<1/0&&(oe=[Math.round(B-60),Math.round(W-70),Math.round(ee+60),Math.round(ue+40)])}let ve=O.caption??"";y.push({n:k,num:O.number??k,kind:x,color:h(x),heading:O.heading,caption:ve,command:O.command??"",phases:F,pulses:J,lit:[...N],duration:O.duration===void 0||O.duration==="auto"?Ac(ve):O.duration,...oe?{focus:oe}:{}})}),I(),{steps:y,says:T,marks:S,badges:P,vis:w,diags:i,kindsUsed:b}}function Pc(t){let e=t.slice(1).map((s,r)=>Math.hypot(s[0]-t[r][0],s[1]-t[r][1],s[2]-t[r][2])),n=e.reduce((s,r)=>s+r,0)/2;for(let s=0;s<e.length;s++){if(n<=e[s]&&e[s]>0){let r=n/e[s],o=t[s],i=t[s+1];return[o[0]+(i[0]-o[0])*r,o[1]+(i[1]-o[1])*r,o[2]+(i[2]-o[2])*r]}n-=e[s]}return t[0]}function Fn(t,e){let n=Us(t,e);return n?` (did you mean "${n}"?)`:""}function _u(t,e){if(!e)return t;let[n,s,r,o]=e,i=t[2]/t[3],a=r-n,l=o-s;a/l<i?a=l*i:l=a/i,a=Math.min(a,t[2]),l=Math.min(l,t[3]);let c=(n+r)/2,d=(s+o)/2,u=Math.max(t[0],Math.min(t[0]+t[2]-a,c-a/2)),f=Math.max(t[1],Math.min(t[1]+t[3]-l,d-l/2));return[u,f,a,l]}var La=(t,e)=>e.role??Dt(t,e.kind)?.role,Pa=(t,e)=>Dt(t,e.region.kind)?.shape;function Na({scene:t,layout:e,routes:n,steps:s,theme:r,id:o,gridStep:i=1}){let a=new Pr,l={base:"",floor:"",flows:"",blocks:[],air:"",labels:"",marks:"",badges:""},c=new hr;c.budget.spots=Ca;let d=x=>s.vis[x]?{"data-vis":"1"}:{},u=e.items.filter(x=>x.type==="region"),f=x=>{let N=0;for(let F=x.parent;F;F=F.parent)N++;return N},p=e.catalog,g=u.filter(x=>Pa(p,x)!=="walled"&&Pa(p,x)!=="tunnel"),h=xo(g.map(x=>({box:x.box,r:x}))).map(x=>x.r).sort((x,N)=>f(x)-f(N));for(let x of h)l.base+=nm(a,p,x,d(x.id),i);for(let x of u.filter(N=>Pa(p,N)==="walled")){for(let F of Oa(x))c.solids.push(Cn(F));for(let F of Oa(x))l.blocks.push({box:F,svg:_e("g",{class:`blk k-${La(p,x.region)} wall${x.region.ghost?" ghost":""}`,"data-id":x.id,"data-dim":"1",...d(x.id)},a.blockFaces(F))});let N=x.region.gate;if(N&&!N.node){let F=Vo(x,N.height??(x.region.height??.8)+.3,.3,.3);c.solids.push(Cn(F)),l.blocks.push({box:F,svg:_e("g",{class:"blk k-gate","data-id":x.id,...d(x.id)},a.blockFaces(F))})}x.region.label&&(x.region["label-style"]??"face")!=="none"&&(l.labels+=a.faceText(x.box.x0+.3,x.box.y1,x.box.z0+.13,x.region.label,"slabname sm fz",It.sm,"left","start",{"data-id":x.id,...d(x.id)}))}for(let x of u.filter(N=>Pa(p,N)==="tunnel"))l.air+=rm(a,x,d(x.id));let b=e.items.filter(x=>x.type==="node");for(let x of b){let N=x.node,F=Dn(p,N.asset),J=N.ghost||(N.deco??[]).includes("ghost"),oe=["blk",`k-${N.role??F.role}`,F.cls,J?"ghost":""].filter(Boolean).join(" ");l.blocks.push({box:x.box,svg:_e("g",{class:oe,"data-id":x.id,"data-dim":"1",...d(x.id)},F.draw(a,x.box,N))}),c.polys.push({poly:Cn(x.box),owner:x.id}),c.solids.push(Cn(x.box))}let v=xo(l.blocks).map(x=>x.svg).join(""),w=new Set,M={};for(let x of n){if(x.points.length<2)continue;let N=x.points.map(oe=>Je(oe[0],oe[1],oe[2]));N.forEach(oe=>a.bounds.add(oe));let F="M"+N.map(cr).join(" L");M[x.id]=F;let J=x.raw.arrow!==!1;J&&w.add(x.kind),l.flows+=_e("g",{"data-hl":x.id,"data-id":x.id,...d(x.id)},_e("path",{d:F,class:`flow f-${x.kind}`,"marker-end":J?`url(#ah-${o}-${x.kind})`:void 0})),c.lines.push({pts:N,owner:x.id})}for(let x of w)a.def(`ah-${o}-${x}`,_e("marker",{id:`ah-${o}-${x}`,viewBox:"0 0 10 10",refX:"7",refY:"5",markerWidth:"4.2",markerHeight:"4.2",orient:"auto-start-reverse"},_e("path",{d:"M0,0 L10,5 L0,10 z",style:`fill:${us(r,r.kinds[x]?.color??"control")}`})));for(let x of a.planePolys)c.slants.push(x);let y=b.filter(x=>x.node.label||x.node.sub).sort((x,N)=>(N.box.x1-N.box.x0)*(N.box.y1-N.box.y0)-(x.box.x1-x.box.x0)*(x.box.y1-x.box.y0));for(let x of y)l.labels+=sm(a,p,x,c,d(x.id));let T=[];for(let x of n)if(x.raw.label&&x.points.length>=2){let N=om(a,x,c,d(x.id),e);l.floor+=N.svg,N.warning&&T.push({path:`${x.path}/label`,message:N.warning}),c.budget.over&&!c.budget.told&&(c.budget.told=!0,T.push({path:x.path,message:`from route "${x.id}" on, route labels were placed without weighing what other labels and lines cover: the scene is too large to search every spot (${Ca.toLocaleString("en")} spots); split it into scenes, or give the labels "along", "side" or "at"`}))}(t.notes??[]).forEach((x,N)=>{let F=im(a,x,e,n,`${o}-note-${N}`);x.floor?l.floor+=F:l.labels+=F});let S=[],P=new Map;for(let x of s.says){let N=P.get(x.step)??c.fork();P.set(x.step,N);let F=Rn(x.text,It.say)+18,J=Ma(F,x.ax,x.ay,{x:x.x,y:x.y,anchor:x.anchor},N);N.rects.push({r:J.rect,owner:""}),S.push({step:x.step,...J.rect,text:x.text});let oe=J.rect.x+2;a.bounds.addRect(J.rect.x,J.rect.y,J.rect.w,J.rect.h);let ve=us(r,r.kinds[x.kind]?.color??"control");l.marks+=_e("g",{class:"say","data-step":x.step},_e("rect",{x:oe,y:J.y-12,width:F,height:24,rx:12,style:`stroke:${ve}`})+_e("text",{x:oe+F/2,y:J.y+4,"text-anchor":"middle",style:`fill:${ve}`},Kt(x.text)))}for(let x of s.marks){let[N,F]=Je(...x.p);a.bounds.addRect(N-12,F-12,24,24),l.marks+=_e("g",{class:"xm","data-step":x.step,"data-hl":x.on},_e("circle",{cx:N,cy:F,r:10})+_e("path",{d:`M${Rt(N-4.5)},${Rt(F-4.5)} L${Rt(N+4.5)},${Rt(F+4.5)} M${Rt(N+4.5)},${Rt(F-4.5)} L${Rt(N-4.5)},${Rt(F+4.5)}`}))}for(let x of s.badges){let[N,F]=Je(...x.p);a.bounds.addRect(N-13,F-13,26,26),l.badges+=_e("g",{class:`badge c-${x.kind}`,"data-go":x.step,"data-badge":x.step,tabindex:"0",role:"button","aria-label":`Step ${x.num}`},_e("circle",{cx:N,cy:F,r:11.5})+_e("text",{x:N,y:F+.5},String(x.num)))}let I=a.bounds,_=22,O=I.empty?[0,0,100,100]:[Math.floor(I.x0-_),Math.floor(I.y0-_),Math.ceil(I.x1-I.x0+_*2),Math.ceil(I.y1-I.y0+_*2)],j=[...a.defs.values()].join(""),k=(x,N)=>_e("g",{class:"g-"+x},N);return{svg:_e("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:O.join(" "),role:"img","aria-label":t.aria??t.title,"data-scene":o},_e("defs",{},j)+k("base",l.base)+k("floor",l.floor)+k("flows",l.flows)+k("blocks",v)+k("air",l.air)+k("labels",l.labels)+k("marks",l.marks)+k("badges",l.badges)+k("anim","")),viewBox:O,texts:a.texts,paths:M,warnings:T,callouts:S,assembly:Ta(e,n,O)}}function tm(t,e){let n=t.z1+.002,s=1e-6,r=[],o=(i,a)=>{let l=Je(i[0],i[1],n),c=Je(a[0],a[1],n);r.push(`M${cr(l)}L${cr(c)}`)};for(let i=Math.ceil((t.x0+s)/e)*e;i<t.x1-s;i+=e)o([i,t.y0],[i,t.y1]);for(let i=Math.ceil((t.y0+s)/e)*e;i<t.y1-s;i+=e)o([t.x0,i],[t.x1,i]);return r.length?_e("path",{class:"grid",d:r.join("")}):""}function nm(t,e,n,s,r=1){let o=n.region,i=n.box,a=La(e,o),l=Dt(e,o.kind),c=l?.shape,d={"data-id":n.id,"data-dim":"1",...s},u="";c==="cloud"?u=_e("g",{class:`blk k-${a} cloud`,...d},ua(t,i)):c==="zone"?u=_e("g",{class:`zone k-${a}`,...d},t.poly([[i.x0,i.y0,i.z1],[i.x1,i.y0,i.z1],[i.x1,i.y1,i.z1],[i.x0,i.y1,i.z1]])):u=_e("g",{class:`blk k-${a}${o.ghost?" ghost":""}`,...d},t.blockFaces(i)+tm(i,r));let f=o["label-style"]??l?.labelStyle;if(o.label&&f!=="none")if(f==="face"){let p=i.z1-i.z0,g=w=>w.size*.73/xt,h=c==="slab"&&.28+g(It.slabname)+.08>p,b=c==="slab"&&!h,v=b?i.z0+.28:h?i.z0+Math.max(.02,(p-g(It.sm))/2):i.z0+Math.min(.1,p*.25);u+=_e("g",d,t.faceText(i.x0+(b?.6:.3),i.y1,v,o.label,b?"slabname":"slabname sm",b?It.slabname:It.sm,"left","start"))}else if(f==="face-right")u+=_e("g",d,t.faceText(i.x1,i.y0+.6,i.z0+Math.max(.14,(i.z1-i.z0)*.2),o.label,"slabname",It.slabname,"right","end"));else{let p=c==="cloud"?"middle":"start",g=c==="cloud"?(i.x0+i.x1)/2:i.x0+.35,h=c==="cloud"?(i.y0+i.y1)/2:i.y1-.35;u+=_e("g",d,t.floorText(g,h,i.z1+.01,o.label,"slabname sm","x",p))}return u}function Oa(t){let{x0:e,y0:n,x1:s,y1:r,z0:o,z1:i}=t.box,a=fs,l=t.region.gate,c=[],d=f=>{f.x1-f.x0>1e-6&&f.y1-f.y0>1e-6&&c.push({...f,z0:o,z1:i})},u=(f,p,g)=>{if(!l||l.side!==g)return[[f,p]];let h=l.at??.5,b=l.width??2,v=g==="e"||g==="w"?n+(r-n)*h:e+(s-e)*h;return[[f,v-b/2],[v+b/2,p]]};for(let[f,p]of u(e,s,"n"))d({x0:f,y0:n,x1:p,y1:n+a});for(let[f,p]of u(n+a,r-a,"w"))d({x0:e,y0:f,x1:e+a,y1:p});for(let[f,p]of u(n+a,r-a,"e"))d({x0:s-a,y0:f,x1:s,y1:p});for(let[f,p]of u(e,s,"s"))d({x0:f,y0:r-a,x1:p,y1:r});return c}function sm(t,e,n,s,r){let o=n.node,i=Dn(e,o.asset),a=n.box,l={name:o.label,sub:o.sub},c=o["label-at"],d;if(c){let f=Os(Cn(a)),p=c.side??"above",g=f.y+Math.min(f.h,60)*.45;p==="right"?d={x:f.x+f.w+8,y:g,anchor:"start"}:p==="left"?d={x:f.x-8,y:g,anchor:"end"}:p==="below"?d={x:f.x+f.w/2,y:f.y+f.h+14,anchor:"middle"}:d=qo(l,a,Cn(a),new hr,n.id),d={...d,x:d.x+(c.dx??0),y:d.y+(c.dy??0)}}else{let f=i.label?i.label(a,o,!!o.sub):void 0;d=qo(l,a,Cn(a),s,n.id,f)}s.rects.push({r:Yo(l,d.x,d.y,d.anchor),owner:""});let u="";return o.label&&(u+=t.text(d.x,d.y,o.label,"lbl",It.lbl,d.anchor,{},n.id)),o.sub&&(u+=t.text(d.x,o.label?d.y+14:d.y,o.sub,"sub mono",It.sub,d.anchor,{},n.id)),_e("g",{"data-id":n.id,"data-dim":"1",...r},u)}function rm(t,e,n){let{x0:s,y0:r,x1:o,y1:i,z0:a,z1:l}=e.box,c=t.blockFaces(e.box),d=o-s>=i-r,u=Math.max(1,Math.round((d?o-s:i-r)/1.6));for(let p=1;p<u;p++){let g=d?s+(o-s)*p/u:r+(i-r)*p/u;c+=t.poly(d?[[g,r,l],[g,i,l],[g,i,a]]:[[s,g,l],[o,g,l],[o,g,a]],"rib")}let f=e.region.label;return f&&e.region["label-style"]!=="none"&&(c+=d?t.faceText(s+.35,i,a+.14,f,"tunname",It.tunname,"left","start"):t.faceText(o,i-.35,a+.18,f,"tunname",It.tunname,"right","start")),_e("g",{class:"tunnel","data-id":e.id,"data-dim":"1",...n},c)}var Ca=2e4;function om(t,e,n,s,r){let o=typeof e.raw.label=="string"?{text:e.raw.label}:e.raw.label,i=`floor mono t-${e.kind}`,a={"data-hl":e.id,...s},l=It.floor;if(o.at){let w=o.at.length>2?o.at[2]:e.points[0][2];return{svg:t.floorText(o.at[0],o.at[1],w,o.text,i,o.dir??"x",o.anchor??"start",a)}}let c=e.points,d=[];for(let w=0;w+1<c.length;w++){let M=c[w],y=c[w+1];Math.abs(M[2]-y[2])>1e-6||d.push({i:w,len:Math.hypot(y[0]-M[0],y[1]-M[1])})}if(!d.length)return{svg:"",warning:`label "${o.text}" of route "${e.id}" was dropped: the route has no level segment`};let u=o.along?d.filter(w=>w.i===Math.min(o.along-1,c.length-2)):[...d].sort((w,M)=>M.len-w.len),f=.22,p=11/xt,g=w=>{let M=Rn(w,l)/xt,y,T=1/0,S=0;e:for(let P of u.length?u:d){let I=c[P.i],_=c[P.i+1],O=I[2],j=Math.abs(I[1]-_[1])<1e-6,k=j?Math.min(I[0],_[0]):Math.min(I[1],_[1]),$=j?Math.max(I[0],_[0]):Math.max(I[1],_[1]),x=j?I[1]:I[0],N=o.side==="left"?[-1]:o.side==="right"?[1]:[-1,1],F=[];for(let J=k+.3;J<=Math.max(k+.3,$-M-.2)+1e-9;J+=.4)F.push(J);for(let J=$-M-.2+.4;J<$+.5&&$-k<M+.5;J+=.6)F.push(J);for(let J of N)for(let oe of F){if(T<=S*.5)break e;let ve=J<0?x-f:x+f+p,B,W,ee;if(j?(B=oe,W=ve,ee=[Je(B,W-p,O),Je(B+M,W-p,O),Je(B+M,W,O),Je(B,W,O)]):(B=ve,W=oe+M,ee=[Je(B-p,W,O),Je(B-p,W-M,O),Je(B,W-M,O),Je(B,W,O)]),(j?[[B,W-p],[B+M,W-p],[B+M,W],[B,W]]:[[B-p,W],[B-p,W-M],[B,W-M],[B,W]]).some(([ne,fe])=>Math.abs(zr(r,ne,fe)+.01-O)>.001)){S++;continue}let z=n.hiddenPoly(ee),X=z*50+S*.5,Q=n.budget.spots-- >0;Q||(n.budget.over=!0);let te=X>=T?1/0:Q?X+n.costPoly(ee,T-X):X;S++,te<T&&(T=te,y={x:B,y:W,z:O,dir:j?"x":"y",rect:Os(ee),poly:ee,hidden:z})}}return y&&y.hidden<6?y:void 0},h=o.text,b=g(h),v;if(!b){let w=o.text.split(/(\s+)/);for(let M=w.length-1;M>0&&!b;M--){let y=w.slice(0,M).join("").trimEnd().replace(/[\s,;:·–-]+$/,"")+"\u2026";if(y.length<6)break;let T=g(y);T&&(b=T,h=y)}v=b?`label of route "${e.id}" shortened to "${h}": no clear floor for the whole text`:`label "${o.text}" of route "${e.id}" was dropped: blocks cover every spot beside it`,b?v+='; give it "along", "side" or "at", or move the nodes apart':v+='; give it "at: [x, y]", or move the nodes apart'}return b?(n.slants.push(b.poly),{svg:t.floorText(b.x,b.y,b.z+.01,h,i,b.dir,"start",a),warning:v}):{svg:"",warning:v}}function im(t,e,n,s,r){let o=e.on?s.find(d=>d.id===e.on):void 0,i=e.on&&!o?n.byId.get(e.on):void 0,a=e.at,l={"data-id":r,"data-hl":o?.id,"data-dim":o?void 0:"1"},c=e.kind??o?.kind??"control";if(e.floor){let d=a&&a.length>2?a[2]:o?o.points[0][2]:i?i.floor:.36,[u,f]=a?[a[0],a[1]]:o?[o.points[0][0]+.35,o.points[0][1]-.25]:i?[i.box.x0+.3,i.box.y1-.3]:[0,0];return t.floorText(u,f,d+.01,e.floor,`floor mono t-${c}`,e.dir??"x",e.anchor??"start",l)}if(e.face){let d=i?.box,[u,f,p]=a?[a[0],a[1],a[2]??.45]:d?[d.x0+.3,d.y1,d.z0+.13]:[0,0,0];return t.faceText(u,f,p,e.face,"slabname sm",It.sm,"left",e.anchor??"start",l)}if(e.label||e.sub){let d=i?.box,u=a?[a[0],a[1],a[2]??.36]:d?[(d.x0+d.x1)/2,(d.y0+d.y1)/2,d.z1+.75]:[0,0,0],[f,p]=Je(u[0],u[1],u[2]),g=f+(e.dx??0),h=p-18+(e.dy??0),b=e.anchor??"middle",v="";return e.label&&(v+=t.text(g,h,e.label,"lbl",It.lbl,b)),e.sub&&(v+=t.text(g,e.label?h+14:h,e.sub,"sub mono",It.sub,b)),_e("g",l,v)}return""}var Oc=`
|
|
143
143
|
*{box-sizing:border-box}
|
|
144
144
|
html,body{margin:0}
|
|
145
145
|
body{background:var(--bg);color:var(--ink);font:15px/1.55 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;-webkit-font-smoothing:antialiased;overflow-x:hidden}
|
|
@@ -163,7 +163,7 @@ h2{font-size:20px;margin:44px 0 4px;letter-spacing:-.005em;text-wrap:balance}
|
|
|
163
163
|
.legend i{display:inline-block;width:26px;height:0;border-top:3px solid}
|
|
164
164
|
.legend i.box{height:10px;border-width:1.5px;border-style:solid;border-radius:2px}
|
|
165
165
|
footer{margin-top:40px;font-size:12.5px;color:var(--muted)}
|
|
166
|
-
`,
|
|
166
|
+
`,Cc=t=>am+la(t)+lm+ca(),am=`
|
|
167
167
|
/* blocks: hue per role, lightness per face and theme */
|
|
168
168
|
.blk .top{fill:hsl(var(--h) var(--s) var(--l-top))}
|
|
169
169
|
.blk .lft{fill:hsl(var(--h) var(--s) var(--l-left))}
|
|
@@ -204,14 +204,14 @@ footer{margin-top:40px;font-size:12.5px;color:var(--muted)}
|
|
|
204
204
|
.floor.t-control{fill:var(--muted)}
|
|
205
205
|
.slabname{font-size:15px;font-weight:800;fill:var(--muted);letter-spacing:.12em;opacity:.8}
|
|
206
206
|
.slabname.sm{font-size:10.5px;letter-spacing:.1em;opacity:1}
|
|
207
|
-
`,
|
|
207
|
+
`,lm=`.tunnel polygon{fill:hsl(205 85% 55% / .17);stroke:hsl(205 75% 45% / .8);stroke-width:1.3;stroke-linejoin:round}
|
|
208
208
|
.tunnel .top{fill:hsl(205 85% 65% / .22)}
|
|
209
209
|
.tunnel .rib{fill:none;stroke:hsl(205 75% 45% / .5);stroke-width:1}
|
|
210
210
|
.tunname{font-size:12px;font-weight:800;letter-spacing:.14em;fill:var(--tunnel-text);paint-order:stroke;stroke:var(--surface);stroke-width:3px;stroke-linejoin:round}
|
|
211
211
|
|
|
212
212
|
/* flows */
|
|
213
213
|
.flow{fill:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round}
|
|
214
|
-
`,
|
|
214
|
+
`,Ra=t=>Oc+Cc(t),Lc=`
|
|
215
215
|
/* step marks */
|
|
216
216
|
.xm circle{fill:var(--surface);stroke:var(--blocked);stroke-width:2.5}
|
|
217
217
|
.xm path{stroke:var(--blocked);stroke-width:3;stroke-linecap:round}
|
|
@@ -234,7 +234,7 @@ svg.all .badge{opacity:1}
|
|
|
234
234
|
svg.focus.all [data-hl]:not(.hl),svg.focus.all.dim-all [data-dim]:not(.hl){opacity:.9}
|
|
235
235
|
svg [data-step]:not(.on),svg.all [data-step]{opacity:0!important;pointer-events:none}
|
|
236
236
|
.pre{opacity:0!important;pointer-events:none}
|
|
237
|
-
`,
|
|
237
|
+
`,Nc=`
|
|
238
238
|
/* player */
|
|
239
239
|
.player{display:flex;align-items:flex-start;gap:10px 14px;padding:12px 16px;border-top:1px solid var(--line);flex-wrap:wrap}
|
|
240
240
|
.ctrls{display:flex;gap:6px;flex:none}
|
|
@@ -269,20 +269,20 @@ details.steps li code{font-size:11.5px}
|
|
|
269
269
|
.still .ctrls,.still .tools{display:none}
|
|
270
270
|
.tools{display:flex;gap:6px;flex:none;order:3;margin-left:auto}
|
|
271
271
|
.pbtn.small{font-size:12px;padding:4px 11px;font-weight:600;color:var(--muted)}
|
|
272
|
-
.pbtn.small[aria-pressed="true"]{color:var(--ink);border-color:var(--muted);background:var(--surface)}`,
|
|
272
|
+
.pbtn.small[aria-pressed="true"]{color:var(--ink);border-color:var(--muted);background:var(--surface)}`,Rc=`
|
|
273
273
|
.grid{display:none;fill:none;stroke:var(--ink);stroke-width:.6;opacity:.16;pointer-events:none}
|
|
274
274
|
svg.show-grid .grid{display:inline}
|
|
275
275
|
svg.pre-assemble > g:not(.g-anim){opacity:0}
|
|
276
|
-
`,ya=fc+pc+mc;var hc=t=>({data:t,locate:()=>({line:0,col:0}),span:()=>{},diags:[]});function yu(t,e,n,s=hc(t),r,o={},i=[]){let a=Ki(Bi(e),t.roles,t.kinds),l=[],c=new Map;return t.scenes.forEach((d,u)=>{let f=`/scenes/${u}`;if(c.has(d.id)){let v=s.locate(f+"/id");i.push({severity:"error",message:`duplicate scene id "${d.id}"`,line:v.line,col:v.col,path:f+"/id"})}c.set(d.id,u);let p={...t.grid,...d.grid,...o.snap?{snap:o.snap}:{}},g=Xi(d,f,s,a,n,t.roles,p.snap);i.push(...g.diags);let h=sa(d,f,g,s,new Set(Object.keys(a.kinds)),p.snap);i.push(...h.diags);let b=ua(d,f,g,h.routes,s,a);i.push(...b.diags),i.push(...jp(d,f,n,s));let k=ga({scene:d,layout:g,routes:h.routes,steps:b,theme:a,id:d.id,gridStep:p.step??p.snap??1});for(let v of k.warnings){let M=s.locate(v.path);i.push({severity:"warning",message:v.message,line:M.line,col:M.col,path:v.path})}l.push({id:d.id,raw:d,layout:g,routes:h.routes,steps:b,rendered:k,grid:p,assemble:d.assemble??t.assemble??!1})}),i.sort((d,u)=>d.line-u.line||d.col-u.col),{ok:!i.some(d=>d.severity==="error"),diags:i,doc:t,theme:a,catalog:n,scenes:l,parsed:s,source:r}}function jp(t,e,n,s){let r=[],o=(a,l)=>{let c=s.locate(a);r.push({severity:"warning",message:l,line:c.line,col:c.col,path:a})},i=(a,l)=>{a.nodes?.forEach((c,d)=>{let u=`${l}/nodes/${d}`;(c.deco??Tn(n,c.asset).deco??[]).forEach((f,p)=>{typeof f=="object"&&f.icon&&!Po(f.icon)&&o(c.deco?`${u}/deco/${p}/icon`:u,`node "${c.id}": no icon "${f.icon}" is registered here, so it is drawn as a placeholder`)}),c.face!==void 0&&!qi(c.face)&&o(`${u}/face`,`node "${c.id}": no screen face "${c.face}" is registered here, so it is drawn as a placeholder`)}),a.regions?.forEach((c,d)=>i(c,`${l}/regions/${d}`))};return i(t,e),r}function ws(t,e){let n=t/(It*xt),s=2*e/xt;return[(n+s)/2,(s-n)/2]}function Rr(t,e){let n=t.layout.byId.get(e);if(!n)return;let s=n.parent?[n.parent.box.x0,n.parent.box.y0]:[0,0];return[n.box.x0-s[0],n.box.y0-s[1]]}function xa(t){let e=[];for(let n of[t.x0,t.x1])for(let s of[t.y0,t.y1])for(let r of[t.z0,t.z1])e.push(Xe(n,s,r));return Bp(e)}function Ir(t){return[[t.x0,t.y0],[t.x1,t.y0],[t.x1,t.y1],[t.x0,t.y1]].map(([e,n])=>Xe(e,n,t.z0))}function Bp(t){let e=[...new Map(t.map(o=>[`${o[0].toFixed(3)},${o[1].toFixed(3)}`,o])).values()].sort((o,i)=>o[0]-i[0]||o[1]-i[1]);if(e.length<3)return e;let n=(o,i,a)=>(i[0]-o[0])*(a[1]-o[1])-(i[1]-o[1])*(a[0]-o[0]),s=[],r=[];for(let o of e){for(;s.length>=2&&n(s[s.length-2],s[s.length-1],o)<=1e-9;)s.pop();s.push(o)}for(let o of[...e].reverse()){for(;r.length>=2&&n(r[r.length-2],r[r.length-1],o)<=1e-9;)r.pop();r.push(o)}return[...s.slice(0,-1),...r.slice(0,-1)]}var Do=(t,e)=>e?.padding??Ft(t,e?.kind)?.pad??0;function Fo(t,e,n,s,r){let o=d=>Math.round(d/n)*n,i=o(t[0]+e[0]),a=o(t[1]+e[1]),l={left:!1,right:!1,top:!1,bottom:!1};if(r){let d=Math.ceil(r.pad/n-1e-9)*n,u=Math.floor((r.w-r.pad-s[0])/n+1e-9)*n,f=Math.floor((r.d-r.pad-s[1])/n+1e-9)*n;i<d&&(i=d,l.left=!0),u>=d&&i>u&&(i=u,l.right=!0),a<d&&(a=d,l.top=!0),f>=d&&a>f&&(a=f,l.bottom=!0)}let c=d=>Math.round(d*1e3)/1e3;return{at:[c(i),c(a)],delta:[c(i-t[0]),c(a-t[1])],clamped:l}}function rr(t,e){return e.some(s=>t.x0<s.x1-1e-6&&t.x1>s.x0+1e-6&&t.y0<s.y1-1e-6&&t.y1>s.y0+1e-6)}var bc=Object.freeze({W:178,H:58,GX:44,GY:44,PAD:22,TITLE:30,CH:96,cardRx:9,panelRx:14,bend:70,overlap:400,crossPanel:300,border:120,nearEdge:200,margin:16}),yc={name:{key:"sans600_12",size:13},sub:{key:"sans400_13",size:10},title:{key:"sans700_13",size:12,spacing:.02},titleSub:{key:"sans400_13",size:10.5},label:{key:"sans600_12",size:10.5}},xu=(t,e)=>$n(t,yc[e]);function wa(t){let e=[],n=new Map,s=(l,c)=>{if(typeof c!="string"||!c){e.push(`${l} has no id`);return}let d=n.get(c);d?e.push(`duplicate id "${c}": a ${d} and a ${l} (cards and panels share one set of ids)`):n.set(c,l)};for(let l of t.cards)s("card",l.id),(!Array.isArray(l.cell)||l.cell.length!==2||!l.cell.every(c=>Number.isInteger(c)&&c>=0))&&e.push(`card "${l.id}": cell must be [column, row], whole numbers from 0`);for(let l of t.panels??[]){s("panel",l.id);let c=l.cells;(!Array.isArray(c)||c.length!==4||!c.every(d=>Number.isInteger(d)&&d>=0)||c[2]<c[0]||c[3]<c[1])&&e.push(`panel "${l.id}": cells must be [c0, r0, c1, r1] with c0 \u2264 c1 and r0 \u2264 r1`)}let r=new Map;for(let l of t.cards){let c=String(l.cell);r.has(c)?e.push(`cards "${r.get(c)}" and "${l.id}" are both at cell [${c}]`):r.set(c,l.id)}let o=(t.panels??[]).filter(l=>Array.isArray(l.cells)&&l.cells.length===4);for(let l=0;l<o.length;l++)for(let c=l+1;c<o.length;c++){let d=o[l].cells,u=o[c].cells;d[0]<=u[2]&&u[0]<=d[2]&&d[1]<=u[3]&&u[1]<=d[3]&&!gc(d,u)&&!gc(u,d)&&e.push(`panels "${o[l].id}" and "${o[c].id}" overlap without one holding the other`)}let i=new Set([...t.cards.map(l=>l.id),...o.map(l=>l.id)]),a=new Set(o.map(l=>l.id));return(t.links??[]).forEach((l,c)=>{let d=`link ${l.id?`"${l.id}"`:c}`;for(let u of["a","b"])i.has(l[u])||e.push(`${d}: ${u} "${l[u]}" is no card or panel`);for(let u of["aOn","bOn"])l[u]!==void 0&&!a.has(l[u])&&e.push(`${d}: ${u} "${l[u]}" is no panel`);l.id!==void 0&&s("link",l.id)}),e}var gc=(t,e)=>t[0]>=e[0]&&t[2]<=e[2]&&t[1]>=e[1]&&t[3]<=e[3];function jo(t,e){let{W:n,H:s,GX:r,GY:o,PAD:i,TITLE:a,CH:l}=e,c=t.panels??[],d=B=>(B[2]-B[0]+1)*(B[3]-B[1]+1),u=(B,X)=>{let Q=c[B].cells,te=c[X].cells;return gc(te,Q)?d(Q)>d(te)||B<X:!1},f=c.map((B,X)=>{let Q=-1;return c.forEach((te,ne)=>{ne!==X&&u(ne,X)&&(Q<0||u(Q,ne))&&(Q=ne)}),Q}),p=B=>f[B]<0?0:1+p(f[B]),g=(B,X)=>{let Q=-1;c.forEach((ne,me)=>{let ye=ne.cells;B>=ye[0]&&B<=ye[2]&&X>=ye[1]&&X<=ye[3]&&(Q<0||u(Q,me))&&(Q=me)});let te=[];for(let ne=Q;ne>=0;ne=f[ne])te.unshift(ne);return te},h=Math.max(1,...t.cards.map(B=>B.cell[0]+1),...c.map(B=>B.cells[2]+1)),b=Math.max(1,...t.cards.map(B=>B.cell[1]+1),...c.map(B=>B.cells[3]+1)),k=[];for(let B=0;B<h;B++){k.push([]);for(let X=0;X<b;X++)k[B].push(g(B,X))}let v=(B,X,Q)=>{let te=B.filter(me=>!X.includes(me)),ne=X.filter(me=>!B.includes(me));return!te.length&&!ne.length?0:te.length*(i+(Q?a:0))+ne.length*i+l},M=new Array(h+1).fill(0),x=new Array(b+1).fill(0);for(let B=0;B<b;B++)for(let X=1;X<h;X++){let Q=v(k[X-1][B],k[X][B],!1);Q&&(M[X]=Math.max(M[X],Q-r))}for(let B=0;B<h;B++)for(let X=1;X<b;X++){let Q=v(k[B][X-1],k[B][X],!0);Q&&(x[X]=Math.max(x[X],Q-o))}let T=B=>{let X=B*(n+r);for(let Q=1;Q<=B;Q++)X+=M[Q];return X},y=B=>{let X=B*(s+o);for(let Q=1;Q<=B;Q++)X+=x[Q];return X},A=(B,X,Q,te)=>Q===X?B(X):B(X)+(te-X)*(B(Q)-B(X))/(Q-X),D=c.map(()=>new Set),K=(B,X)=>{for(let Q=B;Q>=0;Q=f[Q])D[Q].add(X)};c.forEach((B,X)=>{K(X,B.cells[1]),K(X,B.cells[3])});for(let B of t.cards){let X=k[B.cell[0]][B.cell[1]];X.length&&K(X[X.length-1],B.cell[1])}let C=c.map(()=>new Map),_=(B,X)=>B.slice(B.indexOf(X)+1);for(let B of c.map((X,Q)=>Q).sort((X,Q)=>p(X)-p(Q)||X-Q)){let X=c[B].cells,Q=[...D[B]].sort((ne,me)=>ne-me),te=f[B]>=0?C[f[B]].get(Q[0]):y(Q[0]);C[B].set(Q[0],te);for(let ne=1;ne<Q.length;ne++){let me=0;for(let ye=X[0];ye<=X[2];ye++)me=Math.max(me,v(_(k[ye][Q[ne-1]],B),_(k[ye][Q[ne]],B),!0));te+=s+Math.max(o,me),C[B].set(Q[ne],te)}}let S=c.map(()=>new Set),$=(B,X)=>{for(let Q=B;Q>=0;Q=f[Q])S[Q].add(X)};c.forEach((B,X)=>{$(X,B.cells[0]),$(X,B.cells[2])});for(let B of t.cards){let X=k[B.cell[0]][B.cell[1]];X.length&&$(X[X.length-1],B.cell[0])}let w=c.map(()=>new Map);for(let B of c.map((X,Q)=>Q).sort((X,Q)=>p(X)-p(Q)||X-Q)){let X=c[B].cells,Q=[...S[B]].sort((ne,me)=>ne-me);if(f[B]<0&&!f.includes(B)&&Q.length===X[2]-X[0]+1){for(let ne of Q)w[B].set(ne,A(T,X[0],X[2],ne));continue}let te=f[B]>=0?w[f[B]].get(Q[0]):T(Q[0]);w[B].set(Q[0],te);for(let ne=1;ne<Q.length;ne++){let me=0;for(let ye=X[1];ye<=X[3];ye++)me=Math.max(me,v(_(k[Q[ne-1]][ye],B),_(k[Q[ne]][ye],B),!1));te+=n+Math.max(r,me),w[B].set(Q[ne],te)}}let N=(B,X)=>{let Q=k[B][X],te=Q.length?Q[Q.length-1]:-1;return te>=0?[w[te].get(B),C[te].get(X)]:[T(B),y(X)]},F=c.map((B,X)=>X).sort((B,X)=>p(X)-p(B)||B-X),J=new Array(c.length);for(let B of F){let X=c[B].cells,Q=[],te=[];for(let ye of t.cards){let xe=k[ye.cell[0]][ye.cell[1]];xe[xe.length-1]===B&&(Q.push(w[B].get(ye.cell[0])),te.push(C[B].get(ye.cell[1])))}let ne=ye=>ye.cell[0]>=X[0]&&ye.cell[0]<=X[2]&&ye.cell[1]>=X[1]&&ye.cell[1]<=X[3];for(let ye of[X[1],X[3]])t.cards.some(xe=>xe.cell[1]===ye&&ne(xe))||te.push(C[B].get(ye));for(let ye of[X[0],X[2]])t.cards.some(xe=>xe.cell[0]===ye&&ne(xe))||Q.push(w[B].get(ye));let me={l:Q.length?Math.min(...Q):1/0,t:te.length?Math.min(...te):1/0,r:Q.length?Math.max(...Q)+n:-1/0,b:te.length?Math.max(...te)+s:-1/0};c.forEach((ye,xe)=>{if(f[xe]!==B)return;let Re=J[xe];me.l=Math.min(me.l,Re.l),me.t=Math.min(me.t,Re.t),me.r=Math.max(me.r,Re.r),me.b=Math.max(me.b,Re.b)}),J[B]={l:me.l-i,t:me.t-i,r:me.r+i,b:me.b+i+a}}let ae=t.cards.map(B=>N(B.cell[0],B.cell[1])),we=t.cards.map(B=>{let X=k[B.cell[0]][B.cell[1]];return X.length?X[X.length-1]:-1}),j=(B,X)=>{for(let Q=B;Q>=0;Q=f[Q])if(Q===X)return!0;return!1},U=(B,X)=>{t.cards.forEach((Q,te)=>{we[te]>=0&&j(we[te],B)&&(ae[te]=[ae[te][0]+X,ae[te][1]])}),c.forEach((Q,te)=>{j(te,B)&&(J[te]={...J[te],l:J[te].l+X,r:J[te].r+X})})},ee=B=>{let X=[],Q=[],te=[],ne=[];t.cards.forEach((I,re)=>{we[re]===B&&(X.push(ae[re][0]),te.push(ae[re][0]+n),Q.push(ae[re][1]),ne.push(ae[re][1]+s))}),c.forEach((I,re)=>{f[re]===B&&(X.push(J[re].l),te.push(J[re].r),Q.push(J[re].t),ne.push(J[re].b))});let me=J[B],ye=Math.min(...X,me.l+i),xe=Math.max(...te,me.r-i),Re=Math.min(...Q,me.t+i),Ue=Math.max(...ne,me.b-i-a);J[B]={l:ye-i,t:Re-i,r:xe+i,b:Ue+i+a}};for(let B of F)if(f[B]<0&&!f.includes(B))ee(B);else{let Q=[];t.cards.forEach((xe,Re)=>{we[Re]===B&&Q.push({l:ae[Re][0],r:ae[Re][0]+n,t:ae[Re][1],b:ae[Re][1]+s,card:Re})}),c.forEach((xe,Re)=>{f[Re]===B&&Q.push({...J[Re],panel:Re})}),Q.sort((xe,Re)=>xe.l-Re.l||xe.t-Re.t);let te=Math.min(...Q.map(xe=>xe.l)),ne=[];for(let xe of Q){let Re=te;for(let I of ne)I.t<xe.b&&xe.t<I.b&&I.r<=xe.l+1e-6&&(Re=Math.max(Re,I.r+(I.card!==void 0&&xe.card!==void 0?r:l)));let Ue=Re-xe.l;Ue<-1e-6&&(xe.card!==void 0?ae[xe.card]=[ae[xe.card][0]+Ue,ae[xe.card][1]]:U(xe.panel,Ue),xe.l+=Ue,xe.r+=Ue),ne.push(xe)}let me=Q.map(xe=>xe.l),ye=Q.map(xe=>xe.r);J[B]={...J[B],l:Math.min(...me)-i,r:Math.max(...ye)+i}}return{prect:J,parentIx:f,depthOf:p,pos:N,cardAt:B=>ae[B]}}function Fs(t,e,n={}){if(n.wrap){let{wrap:m,...O}=n;return Fs(Kp(t,e,m.aspect,O),e,O)}let s=wa(t);if(s.length)throw new Error(`the board has ${s.length} error${s.length>1?"s":""}:
|
|
276
|
+
`,Ia=Lc+Nc+Rc;var Ic=t=>({data:t,locate:()=>({line:0,col:0}),span:()=>{},diags:[]});function zu(t,e,n,s=Ic(t),r,o={},i=[]){let a=sa(na(e),t.roles,t.kinds),l=[],c=new Map;return t.scenes.forEach((d,u)=>{let f=`/scenes/${u}`;if(c.has(d.id)){let w=s.locate(f+"/id");i.push({severity:"error",message:`duplicate scene id "${d.id}"`,line:w.line,col:w.col,path:f+"/id"})}c.set(d.id,u);let p={...t.grid,...d.grid,...o.snap?{snap:o.snap}:{}},g=ma(d,f,s,a,n,t.roles,p.snap);i.push(...g.diags);let h=wa(d,f,g,s,new Set(Object.keys(a.kinds)),p.snap);i.push(...h.diags);let b=Aa(d,f,g,h.routes,s,a);i.push(...b.diags),i.push(...cm(d,f,n,s));let v=Na({scene:d,layout:g,routes:h.routes,steps:b,theme:a,id:d.id,gridStep:p.step??p.snap??1});for(let w of v.warnings){let M=s.locate(w.path);i.push({severity:"warning",message:w.message,line:M.line,col:M.col,path:w.path})}l.push({id:d.id,raw:d,layout:g,routes:h.routes,steps:b,rendered:v,grid:p,assemble:d.assemble??t.assemble??!1})}),i.sort((d,u)=>d.line-u.line||d.col-u.col),{ok:!i.some(d=>d.severity==="error"),diags:i,doc:t,theme:a,catalog:n,scenes:l,parsed:s,source:r}}function cm(t,e,n,s){let r=[],o=(a,l)=>{let c=s.locate(a);r.push({severity:"warning",message:l,line:c.line,col:c.col,path:a})},i=(a,l)=>{a.nodes?.forEach((c,d)=>{let u=`${l}/nodes/${d}`;(c.deco??Dn(n,c.asset).deco??[]).forEach((f,p)=>{typeof f=="object"&&f.icon&&!_o(f.icon)&&o(c.deco?`${u}/deco/${p}/icon`:u,`node "${c.id}": no icon "${f.icon}" is registered here, so it is drawn as a placeholder`)}),c.face!==void 0&&!da(c.face)&&o(`${u}/face`,`node "${c.id}": no screen face "${c.face}" is registered here, so it is drawn as a placeholder`)}),a.regions?.forEach((c,d)=>i(c,`${l}/regions/${d}`))};return i(t,e),r}function Cs(t,e){let n=t/(Bt*xt),s=2*e/xt;return[(n+s)/2,(s-n)/2]}function Hr(t,e){let n=t.layout.byId.get(e);if(!n)return;let s=n.parent?[n.parent.box.x0,n.parent.box.y0]:[0,0];return[n.box.x0-s[0],n.box.y0-s[1]]}function Da(t){let e=[];for(let n of[t.x0,t.x1])for(let s of[t.y0,t.y1])for(let r of[t.z0,t.z1])e.push(Je(n,s,r));return dm(e)}function Yr(t){return[[t.x0,t.y0],[t.x1,t.y0],[t.x1,t.y1],[t.x0,t.y1]].map(([e,n])=>Je(e,n,t.z0))}function dm(t){let e=[...new Map(t.map(o=>[`${o[0].toFixed(3)},${o[1].toFixed(3)}`,o])).values()].sort((o,i)=>o[0]-i[0]||o[1]-i[1]);if(e.length<3)return e;let n=(o,i,a)=>(i[0]-o[0])*(a[1]-o[1])-(i[1]-o[1])*(a[0]-o[0]),s=[],r=[];for(let o of e){for(;s.length>=2&&n(s[s.length-2],s[s.length-1],o)<=1e-9;)s.pop();s.push(o)}for(let o of[...e].reverse()){for(;r.length>=2&&n(r[r.length-2],r[r.length-1],o)<=1e-9;)r.pop();r.push(o)}return[...s.slice(0,-1),...r.slice(0,-1)]}var Uo=(t,e)=>e?.padding??Dt(t,e?.kind)?.pad??0;function Wo(t,e,n,s,r){let o=d=>Math.round(d/n)*n,i=o(t[0]+e[0]),a=o(t[1]+e[1]),l={left:!1,right:!1,top:!1,bottom:!1};if(r){let d=Math.ceil(r.pad/n-1e-9)*n,u=Math.floor((r.w-r.pad-s[0])/n+1e-9)*n,f=Math.floor((r.d-r.pad-s[1])/n+1e-9)*n;i<d&&(i=d,l.left=!0),u>=d&&i>u&&(i=u,l.right=!0),a<d&&(a=d,l.top=!0),f>=d&&a>f&&(a=f,l.bottom=!0)}let c=d=>Math.round(d*1e3)/1e3;return{at:[c(i),c(a)],delta:[c(i-t[0]),c(a-t[1])],clamped:l}}function gr(t,e){return e.some(s=>t.x0<s.x1-1e-6&&t.x1>s.x0+1e-6&&t.y0<s.y1-1e-6&&t.y1>s.y0+1e-6)}var Fc=Object.freeze({W:178,H:58,GX:44,GY:44,PAD:22,TITLE:30,CH:96,cardRx:9,panelRx:14,bend:70,overlap:400,crossPanel:300,border:120,nearEdge:200,margin:16}),jc={name:{key:"sans600_12",size:13},sub:{key:"sans400_13",size:10},title:{key:"sans700_13",size:12,spacing:.02},titleSub:{key:"sans400_13",size:10.5},label:{key:"sans600_12",size:10.5}},Vu=(t,e)=>Rn(t,jc[e]);function Fa(t){let e=[],n=new Map,s=(l,c)=>{if(typeof c!="string"||!c){e.push(`${l} has no id`);return}let d=n.get(c);d?e.push(`duplicate id "${c}": a ${d} and a ${l} (cards and panels share one set of ids)`):n.set(c,l)};for(let l of t.cards)s("card",l.id),(!Array.isArray(l.cell)||l.cell.length!==2||!l.cell.every(c=>Number.isInteger(c)&&c>=0))&&e.push(`card "${l.id}": cell must be [column, row], whole numbers from 0`);for(let l of t.panels??[]){s("panel",l.id);let c=l.cells;(!Array.isArray(c)||c.length!==4||!c.every(d=>Number.isInteger(d)&&d>=0)||c[2]<c[0]||c[3]<c[1])&&e.push(`panel "${l.id}": cells must be [c0, r0, c1, r1] with c0 \u2264 c1 and r0 \u2264 r1`)}let r=new Map;for(let l of t.cards){let c=String(l.cell);r.has(c)?e.push(`cards "${r.get(c)}" and "${l.id}" are both at cell [${c}]`):r.set(c,l.id)}let o=(t.panels??[]).filter(l=>Array.isArray(l.cells)&&l.cells.length===4);for(let l=0;l<o.length;l++)for(let c=l+1;c<o.length;c++){let d=o[l].cells,u=o[c].cells;d[0]<=u[2]&&u[0]<=d[2]&&d[1]<=u[3]&&u[1]<=d[3]&&!Dc(d,u)&&!Dc(u,d)&&e.push(`panels "${o[l].id}" and "${o[c].id}" overlap without one holding the other`)}let i=new Set([...t.cards.map(l=>l.id),...o.map(l=>l.id)]),a=new Set(o.map(l=>l.id));return(t.links??[]).forEach((l,c)=>{let d=`link ${l.id?`"${l.id}"`:c}`;for(let u of["a","b"])i.has(l[u])||e.push(`${d}: ${u} "${l[u]}" is no card or panel`);for(let u of["aOn","bOn"])l[u]!==void 0&&!a.has(l[u])&&e.push(`${d}: ${u} "${l[u]}" is no panel`);l.id!==void 0&&s("link",l.id)}),e}var Dc=(t,e)=>t[0]>=e[0]&&t[2]<=e[2]&&t[1]>=e[1]&&t[3]<=e[3];function Jo(t,e){let{W:n,H:s,GX:r,GY:o,PAD:i,TITLE:a,CH:l}=e,c=t.panels??[],d=z=>(z[2]-z[0]+1)*(z[3]-z[1]+1),u=(z,X)=>{let Q=c[z].cells,te=c[X].cells;return Dc(te,Q)?d(Q)>d(te)||z<X:!1},f=c.map((z,X)=>{let Q=-1;return c.forEach((te,ne)=>{ne!==X&&u(ne,X)&&(Q<0||u(Q,ne))&&(Q=ne)}),Q}),p=z=>f[z]<0?0:1+p(f[z]),g=(z,X)=>{let Q=-1;c.forEach((ne,fe)=>{let be=ne.cells;z>=be[0]&&z<=be[2]&&X>=be[1]&&X<=be[3]&&(Q<0||u(Q,fe))&&(Q=fe)});let te=[];for(let ne=Q;ne>=0;ne=f[ne])te.unshift(ne);return te},h=Math.max(1,...t.cards.map(z=>z.cell[0]+1),...c.map(z=>z.cells[2]+1)),b=Math.max(1,...t.cards.map(z=>z.cell[1]+1),...c.map(z=>z.cells[3]+1)),v=[];for(let z=0;z<h;z++){v.push([]);for(let X=0;X<b;X++)v[z].push(g(z,X))}let w=(z,X,Q)=>{let te=z.filter(fe=>!X.includes(fe)),ne=X.filter(fe=>!z.includes(fe));return!te.length&&!ne.length?0:te.length*(i+(Q?a:0))+ne.length*i+l},M=new Array(h+1).fill(0),y=new Array(b+1).fill(0);for(let z=0;z<b;z++)for(let X=1;X<h;X++){let Q=w(v[X-1][z],v[X][z],!1);Q&&(M[X]=Math.max(M[X],Q-r))}for(let z=0;z<h;z++)for(let X=1;X<b;X++){let Q=w(v[z][X-1],v[z][X],!0);Q&&(y[X]=Math.max(y[X],Q-o))}let T=z=>{let X=z*(n+r);for(let Q=1;Q<=z;Q++)X+=M[Q];return X},S=z=>{let X=z*(s+o);for(let Q=1;Q<=z;Q++)X+=y[Q];return X},P=(z,X,Q,te)=>Q===X?z(X):z(X)+(te-X)*(z(Q)-z(X))/(Q-X),I=c.map(()=>new Set),_=(z,X)=>{for(let Q=z;Q>=0;Q=f[Q])I[Q].add(X)};c.forEach((z,X)=>{_(X,z.cells[1]),_(X,z.cells[3])});for(let z of t.cards){let X=v[z.cell[0]][z.cell[1]];X.length&&_(X[X.length-1],z.cell[1])}let O=c.map(()=>new Map),j=(z,X)=>z.slice(z.indexOf(X)+1);for(let z of c.map((X,Q)=>Q).sort((X,Q)=>p(X)-p(Q)||X-Q)){let X=c[z].cells,Q=[...I[z]].sort((ne,fe)=>ne-fe),te=f[z]>=0?O[f[z]].get(Q[0]):S(Q[0]);O[z].set(Q[0],te);for(let ne=1;ne<Q.length;ne++){let fe=0;for(let be=X[0];be<=X[2];be++)fe=Math.max(fe,w(j(v[be][Q[ne-1]],z),j(v[be][Q[ne]],z),!0));te+=s+Math.max(o,fe),O[z].set(Q[ne],te)}}let k=c.map(()=>new Set),$=(z,X)=>{for(let Q=z;Q>=0;Q=f[Q])k[Q].add(X)};c.forEach((z,X)=>{$(X,z.cells[0]),$(X,z.cells[2])});for(let z of t.cards){let X=v[z.cell[0]][z.cell[1]];X.length&&$(X[X.length-1],z.cell[0])}let x=c.map(()=>new Map);for(let z of c.map((X,Q)=>Q).sort((X,Q)=>p(X)-p(Q)||X-Q)){let X=c[z].cells,Q=[...k[z]].sort((ne,fe)=>ne-fe);if(f[z]<0&&!f.includes(z)&&Q.length===X[2]-X[0]+1){for(let ne of Q)x[z].set(ne,P(T,X[0],X[2],ne));continue}let te=f[z]>=0?x[f[z]].get(Q[0]):T(Q[0]);x[z].set(Q[0],te);for(let ne=1;ne<Q.length;ne++){let fe=0;for(let be=X[1];be<=X[3];be++)fe=Math.max(fe,w(j(v[Q[ne-1]][be],z),j(v[Q[ne]][be],z),!1));te+=n+Math.max(r,fe),x[z].set(Q[ne],te)}}let N=(z,X)=>{let Q=v[z][X],te=Q.length?Q[Q.length-1]:-1;return te>=0?[x[te].get(z),O[te].get(X)]:[T(z),S(X)]},F=c.map((z,X)=>X).sort((z,X)=>p(X)-p(z)||z-X),J=new Array(c.length);for(let z of F){let X=c[z].cells,Q=[],te=[];for(let be of t.cards){let we=v[be.cell[0]][be.cell[1]];we[we.length-1]===z&&(Q.push(x[z].get(be.cell[0])),te.push(O[z].get(be.cell[1])))}let ne=be=>be.cell[0]>=X[0]&&be.cell[0]<=X[2]&&be.cell[1]>=X[1]&&be.cell[1]<=X[3];for(let be of[X[1],X[3]])t.cards.some(we=>we.cell[1]===be&&ne(we))||te.push(O[z].get(be));for(let be of[X[0],X[2]])t.cards.some(we=>we.cell[0]===be&&ne(we))||Q.push(x[z].get(be));let fe={l:Q.length?Math.min(...Q):1/0,t:te.length?Math.min(...te):1/0,r:Q.length?Math.max(...Q)+n:-1/0,b:te.length?Math.max(...te)+s:-1/0};c.forEach((be,we)=>{if(f[we]!==z)return;let Ne=J[we];fe.l=Math.min(fe.l,Ne.l),fe.t=Math.min(fe.t,Ne.t),fe.r=Math.max(fe.r,Ne.r),fe.b=Math.max(fe.b,Ne.b)}),J[z]={l:fe.l-i,t:fe.t-i,r:fe.r+i,b:fe.b+i+a}}let oe=t.cards.map(z=>N(z.cell[0],z.cell[1])),ve=t.cards.map(z=>{let X=v[z.cell[0]][z.cell[1]];return X.length?X[X.length-1]:-1}),B=(z,X)=>{for(let Q=z;Q>=0;Q=f[Q])if(Q===X)return!0;return!1},W=(z,X)=>{t.cards.forEach((Q,te)=>{ve[te]>=0&&B(ve[te],z)&&(oe[te]=[oe[te][0]+X,oe[te][1]])}),c.forEach((Q,te)=>{B(te,z)&&(J[te]={...J[te],l:J[te].l+X,r:J[te].r+X})})},ee=z=>{let X=[],Q=[],te=[],ne=[];t.cards.forEach((D,se)=>{ve[se]===z&&(X.push(oe[se][0]),te.push(oe[se][0]+n),Q.push(oe[se][1]),ne.push(oe[se][1]+s))}),c.forEach((D,se)=>{f[se]===z&&(X.push(J[se].l),te.push(J[se].r),Q.push(J[se].t),ne.push(J[se].b))});let fe=J[z],be=Math.min(...X,fe.l+i),we=Math.max(...te,fe.r-i),Ne=Math.min(...Q,fe.t+i),qe=Math.max(...ne,fe.b-i-a);J[z]={l:be-i,t:Ne-i,r:we+i,b:qe+i+a}};for(let z of F)if(f[z]<0&&!f.includes(z))ee(z);else{let Q=[];t.cards.forEach((we,Ne)=>{ve[Ne]===z&&Q.push({l:oe[Ne][0],r:oe[Ne][0]+n,t:oe[Ne][1],b:oe[Ne][1]+s,card:Ne})}),c.forEach((we,Ne)=>{f[Ne]===z&&Q.push({...J[Ne],panel:Ne})}),Q.sort((we,Ne)=>we.l-Ne.l||we.t-Ne.t);let te=Math.min(...Q.map(we=>we.l)),ne=[];for(let we of Q){let Ne=te;for(let D of ne)D.t<we.b&&we.t<D.b&&D.r<=we.l+1e-6&&(Ne=Math.max(Ne,D.r+(D.card!==void 0&&we.card!==void 0?r:l)));let qe=Ne-we.l;qe<-1e-6&&(we.card!==void 0?oe[we.card]=[oe[we.card][0]+qe,oe[we.card][1]]:W(we.panel,qe),we.l+=qe,we.r+=qe),ne.push(we)}let fe=Q.map(we=>we.l),be=Q.map(we=>we.r);J[z]={...J[z],l:Math.min(...fe)-i,r:Math.max(...be)+i}}return{prect:J,parentIx:f,depthOf:p,pos:N,cardAt:z=>oe[z]}}function Js(t,e,n={}){if(n.wrap){let{wrap:m,...C}=n;return Js(um(t,e,m.aspect,C),e,C)}let s=Fa(t);if(s.length)throw new Error(`the board has ${s.length} error${s.length>1?"s":""}:
|
|
277
277
|
${s.join(`
|
|
278
|
-
`)}`);let r={...bc,...n},{W:o,H:i}=r,a=m=>Math.round(m*10)/10,l=[],c=t.panels??[],{prect:d,parentIx:u,depthOf:f,cardAt:p}=jo(t,r),g=c.map((m,O)=>{let L=d[O],G=e(m.label??"","title")+(m.sub?e(m.sub,"titleSub"):0);return{...m,rect:L,titleAt:[a(L.l+16),a(L.b-15)],depth:f(O),parent:u[O]>=0?c[u[O]].id:void 0,title:{l:L.l+10,r:L.l+22+G,t:L.b-30,b:L.b-6}}}),h=t.cards.map(m=>{let[O,L]=p(t.cards.indexOf(m));return{...m,rect:{l:O,t:L,r:O+o,b:L+i}}}),b=new Map;g.forEach(m=>b.set(m.id,m.rect)),h.forEach(m=>b.set(m.id,m.rect));let k=h.map(m=>m.rect),v=g.map(m=>m.rect),M=g.filter(m=>m.label).map(m=>m.title),x=(m,O)=>m.l>=O.l&&m.r<=O.r&&m.t>=O.t&&m.b<=O.b,T=(m,O,L,G)=>Math.min(m[0],O[0])<L.r+G&&Math.max(m[0],O[0])>L.l-G&&Math.min(m[1],O[1])<L.b+G&&Math.max(m[1],O[1])>L.t-G,y=(m,O)=>v.reduce((L,G)=>{if(m[0]===O[0]){let Z=Math.min(m[1],O[1]),Se=Math.max(m[1],O[1]);m[0]>G.l&&m[0]<G.r&&(L+=[G.t,G.b].filter(ue=>ue>Z+1&&ue<Se-1).length)}else{let Z=Math.min(m[0],O[0]),Se=Math.max(m[0],O[0]);m[1]>G.t&&m[1]<G.b&&(L+=[G.l,G.r].filter(ue=>ue>Z+1&&ue<Se-1).length)}return L},0),A=(m,O)=>v.some(L=>m[1]===O[1]?[L.t,L.b].some(G=>Math.abs(m[1]-G)<16&&Math.max(m[0],O[0])>L.l&&Math.min(m[0],O[0])<L.r):[L.l,L.r].some(G=>Math.abs(m[0]-G)<16&&Math.max(m[1],O[1])>L.t&&Math.min(m[1],O[1])<L.b)),D=(m,O,L,G)=>v.filter(Z=>Z!==L&&Z!==G&&!x(L,Z)&&!x(G,Z)&&T(m,O,{l:Z.l+3,r:Z.r-3,t:Z.t+3,b:Z.b-3},0)).length,K=[],C=new Map,_=new Map,S=(m,O)=>{K.push([m,O]);let[L,G]=m[1]===O[1]?[C,m[1]]:m[0]===O[0]?[_,m[0]]:[void 0,0];if(!L)return;let Z=Math.floor(G/6);(L.get(Z)??L.set(Z,[]).get(Z)).push([m,O])},$=(m,O)=>{let L=m[1]===O[1];if(!L&&m[0]!==O[0])return 0;let G=L?1:0,Z=L?0:1,Se=L?C:_,ue=Math.floor(m[G]/6),Ke=Math.min(m[Z],O[Z]),Ye=Math.max(m[Z],O[Z]),Ie=0;for(let De=ue-1;De<=ue+1;De++)for(let[Ce,vt]of Se.get(De)??[])Math.abs(m[G]-Ce[G])<6&&Math.min(Ye,Math.max(Ce[Z],vt[Z]))-Math.max(Ke,Math.min(Ce[Z],vt[Z]))>0&&Ie++;return Ie},w=[...b.values()],N=Math.min(...w.map(m=>m.l)),F=Math.max(...w.map(m=>m.r)),J=Math.min(...w.map(m=>m.t)),ae=Math.max(...w.map(m=>m.b)),we=(m,O)=>{let L=(m+O)/2;return[L,L-12,L+12,L-24,L+24]},j=(()=>{let m=[];return k.forEach(O=>k.forEach(L=>{L.t>O.b&&L.l<O.r+400&&L.r>O.l-400&&m.push(...we(O.b,L.t))})),m.push(J-22,J-34,ae+22,ae+34),[...new Set(m.map(Math.round))]})(),U=(()=>{let m=[];return k.forEach(O=>k.forEach(L=>{L.l>O.r&&m.push(...we(O.r,L.l))})),m.push(N-22,N-34,F+22,F+34),[...new Set(m.map(Math.round))]})(),ee=new Map,fe=new Map,B=m=>{let O=ee.get(m);return O||ee.set(m,O=k.filter(L=>m<L.b+6&&m>L.t-6)),O},X=m=>{let O=fe.get(m);return O||fe.set(m,O=k.filter(L=>m<L.r+6&&m>L.l-6)),O},Q=r.crossPanel/r.overlap,te=r.border/r.overlap,ne=r.nearEdge/r.overlap;function me(m,O,L,G,Z=!0){let Se=0;for(let Ie=1;Ie<m.length;Ie++)Se+=Math.abs(m[Ie-1][0]-m[Ie][0])+Math.abs(m[Ie-1][1]-m[Ie][1]);let ue=Se+r.bend*(m.length-2);if(ue>=G)return ue;let Ke=0,Ye=0;for(let Ie=1;Ie<m.length;Ie++){let De=m[Ie-1],Ce=m[Ie];if(Z){if(Pe(De,Ce,O,L)||A(De,Ce))return 1/0;continue}for(let vt of De[1]===Ce[1]?B(De[1]):X(De[0]))vt!==O&&vt!==L&&T(De,Ce,vt,6)&&Ke++;for(let vt of M)T(De,Ce,vt,2)&&Ke++}for(let Ie=1;Ie<m.length;Ie++){let De=m[Ie-1],Ce=m[Ie];if(Ye+=$(De,Ce)+Q*D(De,Ce,O,L)+te*y(De,Ce),A(De,Ce)&&(Ye+=ne),ue+r.overlap*Ye>=G)return ue+r.overlap*Ye}return ue+r.overlap*Ye+Ke*1e5}let ye=m=>(m.l+m.r)/2,xe=m=>(m.t+m.b)/2,Re=[0,-22,22,-44,44],Ue={bc:1/0},I=(m,O,L,G)=>Math.abs(m-L)+Math.abs(O-G),re=(m,O,L,G,Z,Se,ue,Ke)=>{let Ye=0;return Ye+=I(m,O,L,G),Ye+=I(L,G,Z,Se),Ye+=I(Z,Se,ue,Ke),Ye+r.bend*2},$e=(m,O,L,G,Z,Se,ue,Ke,Ye,Ie)=>{let De=0;return De+=I(m,O,L,G),De+=I(L,G,Z,Se),De+=I(Z,Se,ue,Ke),De+=I(ue,Ke,Ye,Ie),De+r.bend*3},Pe=(m,O,L,G)=>{for(let Z of m[1]===O[1]?B(m[1]):X(m[0]))if(Z!==L&&Z!==G&&T(m,O,Z,6))return!0;for(let Z of M)if(T(m,O,Z,2))return!0;return A(m,O)};function be(m,O,L,G){let Z=Math.max(m.l,O.l),Se=Math.min(m.r,O.r);if(Se-Z>24)for(let St of Re){let Et=(Z+Se)/2+St;Et>Z+8&&Et<Se-8&&L(O.t>=m.b?[[Et,m.b],[Et,O.t]]:[[Et,m.t],[Et,O.b]])}let ue=Math.max(m.t,O.t),Ke=Math.min(m.b,O.b);if(Ke-ue>16)for(let St of[0,-10,10]){let Et=(ue+Ke)/2+St;L(O.l>=m.r?[[m.r,Et],[O.l,Et]]:[[m.l,Et],[O.r,Et]])}let Ye=U.length,Ie=j.length,De=new Uint8Array(Re.length*Ie),Ce=new Uint8Array(Re.length*Ie),vt=new Uint8Array(Re.length*Ye),Mn=new Uint8Array(Re.length*Ye),kt=(St,Et,bn,Yt)=>G?(St[Et]||(St[Et]=Pe(bn,Yt,m,O)?2:1),St[Et]===1):!0;Re.forEach((St,Et)=>Re.forEach((bn,Yt)=>{let Pt=ye(m)+St,Ot=ye(O)+bn,_t=xe(m)+St/3,pt=xe(O)+bn/3;j.forEach((rt,fn)=>{let Mt=rt>m.b?m.b:rt<m.t?m.t:null,Jt=rt>O.b?O.b:rt<O.t?O.t:null;Mt!==null&&Jt!==null&&re(Pt,Mt,Pt,rt,Ot,rt,Ot,Jt)<Ue.bc&&kt(De,Et*Ie+fn,[Pt,Mt],[Pt,rt])&&kt(Ce,Yt*Ie+fn,[Ot,rt],[Ot,Jt])&&L([[Pt,Mt],[Pt,rt],[Ot,rt],[Ot,Jt]])}),U.forEach((rt,fn)=>{let Mt=rt>m.r?m.r:rt<m.l?m.l:null,Jt=rt>O.r?O.r:rt<O.l?O.l:null;Mt!==null&&Jt!==null&&re(Mt,_t,rt,_t,rt,pt,Jt,pt)<Ue.bc&&kt(vt,Et*Ye+fn,[Mt,_t],[rt,_t])&&kt(Mn,Yt*Ye+fn,[rt,pt],[Jt,pt])&&L([[Mt,_t],[rt,_t],[rt,pt],[Jt,pt]])}),St===0&&bn===0&&U.forEach((rt,fn)=>j.forEach((Mt,Jt)=>{let H=rt>m.r?m.r:rt<m.l?m.l:null,he=Mt>O.b?O.b:Mt<O.t?O.t:null;H!==null&&he!==null&&$e(H,_t,rt,_t,rt,Mt,Ot,Mt,Ot,he)<Ue.bc&&kt(vt,Et*Ye+fn,[H,_t],[rt,_t])&&kt(Ce,Yt*Ie+Jt,[Ot,Mt],[Ot,he])&&L([[H,_t],[rt,_t],[rt,Mt],[Ot,Mt],[Ot,he]]);let ke=Mt>m.b?m.b:Mt<m.t?m.t:null,Ae=rt>O.r?O.r:rt<O.l?O.l:null;ke!==null&&Ae!==null&&$e(Pt,ke,Pt,Mt,rt,Mt,rt,pt,Ae,pt)<Ue.bc&&kt(De,Et*Ie+Jt,[Pt,ke],[Pt,Mt])&&kt(Mn,Yt*Ye+fn,[rt,pt],[Ae,pt])&&L([[Pt,ke],[Pt,Mt],[rt,Mt],[rt,pt],[Ae,pt]])}));let as=ye(m)<O.l?O.l:ye(m)>O.r?O.r:null,Ht=pt<m.t?m.t:pt>m.b?m.b:null;as!==null&&Ht!==null&&L([[Pt,Ht],[Pt,pt],[as,pt]]);let Yn=xe(m)<O.t?O.t:xe(m)>O.b?O.b:null,ls=Ot<m.l?m.l:Ot>m.r?m.r:null;Yn!==null&&ls!==null&&L([[ls,_t],[Ot,_t],[Ot,Yn]])}))}function ce(m,O,L,G){for(let Z of Re){let Se=ye(m)+Z,ue=xe(m)+Z/3,Ke=[[[Se,m.t],[Se,O.t]],[[m.r,ue],[O.r,ue]],[[Se,m.b],[Se,O.b]],[[m.l,ue],[O.l,ue]]];for(let Ye of Ke)G(L?[Ye[1],Ye[0]]:Ye)}}let ze=(m,O,L,G)=>{let Z=null;return Ue.bc=1/0,m(Se=>{let ue=me(Se,O,L,Ue.bc,G);ue<Ue.bc&&(Ue.bc=ue,Z=Se)},G),Z},Oe=[],Ee=m=>v.some(O=>[O.l,O.r].some(L=>m.l<L+3&&m.r>L-3&&m.b>O.t&&m.t<O.b)||[O.t,O.b].some(L=>m.t<L+3&&m.b>L-3&&m.r>O.l&&m.l<O.r)),Be=m=>K.filter(([O,L])=>T(O,L,m,1)).length,it=m=>M.some(O=>m.l<O.r&&m.r>O.l&&m.t<O.b&&m.b>O.t),We=m=>k.filter(O=>m.l<O.r+3&&m.r>O.l-3&&m.t<O.b+3&&m.b>O.t-3).length,Ne=m=>Oe.filter(O=>m.l<O.r+4&&m.r>O.l-4&&m.t<O.b+2&&m.b>O.t-2).length,gt=m=>50*at(m)+3*Be(m)+(Ee(m)?1:0)+(it(m)?5:0)+5*We(m)+5*Ne(m),Ze=m=>Be(m)>0||Ee(m)||it(m)||We(m)>0||Ne(m)>0,ft=[];(t.links??[]).forEach((m,O)=>{let L=m.id??`link-${O}`,G=b.get(m.aOn??m.a),Z=b.get(m.bOn??m.b);if(G===Z){l.push(`link "${L}" joins "${m.aOn??m.a}" to itself: not drawn`),ft.push({...m,id:L,points:[],routed:!1});return}let Se=x(G,Z)?Ye=>ce(G,Z,!1,Ye):x(Z,G)?Ye=>ce(Z,G,!0,Ye):(Ye,Ie)=>be(G,Z,Ye,Ie),ue=ze(Se,G,Z,!0),Ke=!0;if(ue||(ue=ze(Se,G,Z,!1),Ke=!1,l.push(`link "${L}": no clear route; drawn the least bad way`)),!ue){ft.push({...m,id:L,points:[],routed:!1});return}for(let Ye=1;Ye<ue.length;Ye++)S(ue[Ye-1],ue[Ye]);ft.push({...m,id:L,points:ue,routed:Ke})});let ot=[];for(let m=0;m<K.length;m++)for(let O=m+1;O<K.length;O++){let[L,G]=K[m],[Z,Se]=K[O],ue=L[1]===G[1],Ke=Z[1]===Se[1];if(ue===Ke)continue;let[Ye,Ie]=ue?[[L,G],[Z,Se]]:[[Z,Se],[L,G]],De=Ie[0][0],Ce=Ye[0][1];De>Math.min(Ye[0][0],Ye[1][0])&&De<Math.max(Ye[0][0],Ye[1][0])&&Ce>Math.min(Ie[0][1],Ie[1][1])&&Ce<Math.max(Ie[0][1],Ie[1][1])&&ot.push([De,Ce])}let at=m=>ot.filter(([O,L])=>O>m.l-2&&O<m.r+2&&L>m.t-2&&L<m.b+2).length;for(let m of ft){let O=m,L=m.points;if(!O.label||!L.length)continue;let G=[];for(let Ie=1;Ie<L.length;Ie++)G.push([L[Ie-1],L[Ie]]);let Z=Ie=>Math.abs(Ie[0][0]-Ie[1][0])+Math.abs(Ie[0][1]-Ie[1][1]);G.sort((Ie,De)=>Z(De)-Z(Ie));let Se=e(O.label,"label")+6,ue=null,Ke=null,Ye=1/0;for(let[Ie,De]of G){let Ce=(Ie[0]+De[0])/2,vt=(Ie[1]+De[1])/2,Mn=Ie[1]===De[1]?[0,-.3,.3,-.15,.15].flatMap(kt=>{let St=Ce+kt*Math.abs(Ie[0]-De[0]);return[[St,vt-6,"middle"],[St,vt+15,"middle"]]}):[0,-.3,.3].flatMap(kt=>{let St=vt+4+kt*Math.abs(Ie[1]-De[1]);return[[Ce+7,St,"start"],[Ce-7,St,"end"],[Ce+24,St,"start"],[Ce-24,St,"end"]]});for(let[kt,St,Et]of Mn){let bn=Et==="middle"?kt-Se/2:Et==="end"?kt-Se:kt,Yt={l:bn,r:bn+Se,t:St-11,b:St+3};if(!Ze(Yt)){ue=[kt,St,Et,Yt];break}let Pt=gt(Yt);Pt<Ye&&(Ye=Pt,Ke=[kt,St,Et,Yt])}if(ue)break}if(!ue&&Ke&&(ue=Ke),!ue){let[Ie,De]=G[0],Ce=(Ie[0]+De[0])/2,vt=(Ie[1]+De[1])/2-6;ue=[Ce,vt,"middle",{l:Ce-Se/2,r:Ce+Se/2,t:vt-11,b:vt+3}]}Oe.push(ue[3]),m.at={x:a(ue[0]),y:a(ue[1]),anchor:ue[2],box:ue[3],text:O.label}}let E=[],Y=[];for(let m of[...w,...Oe,...g.map(O=>O.title)])E.push(m.l,m.r),Y.push(m.t,m.b);for(let m of ft)for(let O of m.points)E.push(O[0]),Y.push(O[1]);let q=r.margin,de={l:Math.min(...E)-q,t:Math.min(...Y)-q,r:Math.max(...E)+q,b:Math.max(...Y)+q};return{cards:h,panels:g,links:ft,bounds:de,options:r,warnings:l}}function wu(t,e,n){let s=o=>e>=o.l&&e<=o.r&&n>=o.t&&n<=o.b,r=t.cards.find(o=>s(o.rect));return r?r.id:[...t.panels].sort((o,i)=>i.depth-o.depth).find(o=>s(o.rect))?.id}function Kp(t,e,n,s={}){let r=a=>{let l=Fs(a,e,s);return Math.max(l.bounds.r-l.bounds.l,(l.bounds.b-l.bounds.t)*n)},o=t,i=r(t);for(let a=0;a<12;a++){let l,c=i;for(let d of _p(o)){if(wa(d).length)continue;let u=r(d);u<c-.5&&(c=u,l=d)}if(!l)break;o=l,i=c}return o}function*_p(t){let e=t.panels??[],n=(i,a)=>i[0]>=a[0]&&i[2]<=a[2]&&i[1]>=a[1]&&i[3]<=a[3],s=(i,a)=>i.every((l,c)=>l===a[c]),r=(i,a=-1)=>{let l=-1;return e.forEach((c,d)=>{d===a||!n(i,c.cells)||a>=0&&d>a&&s(c.cells,e[a].cells)||(l<0||n(c.cells,e[l].cells)&&(!s(c.cells,e[l].cells)||d>l))&&(l=d)}),l},o=i=>{let a=[];return e.forEach((l,c)=>{r(l.cells,c)===i&&a.push({range:[...l.cells],panel:c})}),t.cards.forEach((l,c)=>{let d=[l.cell[0],l.cell[1],l.cell[0],l.cell[1]];r(d)===i&&a.push({range:d,card:c})}),a};for(let i of[-1,...e.map((a,l)=>l)]){let a=o(i);if(i>=0&&!a.some(u=>u.panel!==void 0))continue;let l=u=>[u.range[1],u.range[3]],c=[];for(let u of[...a].sort((f,p)=>f.range[1]-p.range[1]||f.range[0]-p.range[0])){let f=c.find(p=>p.some(g=>l(g)[0]<=l(u)[1]&&l(u)[0]<=l(g)[1]));f?f.push(u):c.push([u])}let d=Math.max(...a.map(u=>u.range[3]));for(let u of c){u.sort((f,p)=>f.range[0]-p.range[0]);for(let f=1;f<u.length;f++){let p=u.slice(f),g=u[0].range[0],h=d+1,b=Math.min(...p.map(y=>y.range[1])),k=Math.max(...p.map(y=>y.range[3]))-b+1,v=t.cards.map(y=>({...y,cell:[...y.cell]})),M=e.map(y=>({...y,cells:[...y.cells]}));for(let y of v)y.cell[1]>d&&(y.cell[1]+=k);let x=new Set;for(let y=i;y>=0&&!x.has(y);y=r(e[y].cells,y))x.add(y);M.forEach((y,A)=>{y.cells[1]>d?(y.cells[1]+=k,y.cells[3]+=k):(x.has(A)||y.cells[1]<=d&&y.cells[3]>d)&&(y.cells[3]+=k)});let T=g;for(let y of p){let A=T-y.range[0],D=h+(y.range[1]-b)-y.range[1],K=C=>C[0]>=y.range[0]&&C[0]<=y.range[2]&&C[1]>=y.range[1]&&C[1]<=y.range[3];t.cards.forEach((C,_)=>{K([C.cell[0],C.cell[1]])&&(v[_].cell=[C.cell[0]+A,C.cell[1]+D])}),e.forEach((C,_)=>{n(C.cells,y.range)&&(M[_].cells=[C.cells[0]+A,C.cells[1]+D,C.cells[2]+A,C.cells[3]+D])}),T+=y.range[2]-y.range[0]+1}e.forEach((y,A)=>{let D=t.cards.map((K,C)=>n([K.cell[0],K.cell[1],K.cell[0],K.cell[1]],y.cells)?v[C].cell:void 0).filter(K=>!!K);D.length&&(M[A].cells=[Math.min(...D.map(K=>K[0])),Math.min(...D.map(K=>K[1])),Math.max(...D.map(K=>K[0])),Math.max(...D.map(K=>K[1]))])}),yield{cards:v,panels:M,links:t.links}}}}}function or(t,e=()=>!0){let n=t.layout.items.filter(y=>e(y.id)),s=t.layout.catalog,r=y=>y.type==="node"&&!y.children.some(A=>A.type==="node"&&e(A.id)),o=n.filter(r),i=y=>{let A=[];for(let D=y;D;D=D.parent)A.unshift(D);return A},a=new Map(o.map(y=>[y.id,i(y)])),l=(y,A)=>{let D=a.get(y.id),K=a.get(A.id),C=0;for(;C<D.length&&C<K.length&&D[C]===K[C];)C++;return[D[C].box,K[C].box]},c=1e-6,d=(y,A)=>{let[D,K]=l(y,A);return D.y1<=K.y0+c&&D.x0<K.x1-c&&K.x0<D.x1-c},u=(y,A)=>{let[D,K]=l(y,A);return D.x1<=K.x0+c&&D.y0<K.y1-c&&K.y0<D.y1-c},f=(y,A)=>{let D=new Map,K=[];for(let C of[...o].sort((_,S)=>A(_)-A(S))){let _=0;for(let S of K)D.get(S.id)+1>_&&y(S,C)&&(_=D.get(S.id)+1);D.set(C.id,_),K.push(C)}return D},p=f(d,y=>y.box.y0),g=f(u,y=>y.box.x0),h=Math.min(...o.map(y=>y.box.x1-y.box.x0))/2;for(let y of o)if(!y.parent)for(let A of o)A.parent&&A.box.x0<=y.box.x0+h&&g.set(y.id,Math.max(g.get(y.id),g.get(A.id)));let b=new Map;for(let y of o)b.set(y.id,[g.get(y.id),p.get(y.id)]);let k=new Map;for(let y of o){let A=b.get(y.id),D=k.get(String(A));if(D!==void 0&&D!==y.id){for(let[,K]of b)K[0]>A[0]&&K!==A&&K[0]++;A[0]++,k.clear();for(let K of o)k.set(String(b.get(K.id)),K.id)}else k.set(String(A),y.id)}let v=o.map(y=>{let A=y.node,D=Tn(s,A.asset);return{id:y.id,label:A.label??y.id,sub:A.sub,role:A.role??D.role,ghost:A.ghost||void 0,cell:b.get(y.id)}}),M=[];for(let y of n){if(r(y))continue;let A=[],D=$=>{for(let w of $.children){let N=b.get(w.id);N&&A.push(N),D(w)}};if(D(y),!A.length)continue;let K=A.map($=>$[0]),C=A.map($=>$[1]),_=y.type==="region"?y.region.label:y.node.label??y.id,S=y.type==="region"?y.region.role??Ft(s,y.region.kind)?.role:y.node.role??Tn(s,y.node.asset).role;M.push({id:y.id,label:_,sub:y.type==="node"?y.node.sub:void 0,role:S,cells:[Math.min(...K),Math.min(...C),Math.max(...K),Math.max(...C)]})}let x=new Set([...v.map(y=>y.id),...M.map(y=>y.id)]),T=[];for(let y of t.routes){if(!e(y.id))continue;let A=wn(y.raw.from).id,D=wn(y.raw.to).id;if(!x.has(A)||!x.has(D))continue;let K=typeof y.raw.label=="string"?y.raw.label:y.raw.label?.text;T.push({id:y.id,a:A,b:D,kind:y.kind,label:K})}return{cards:v,panels:M,links:T}}var js={W:4,D:2,H:.9,GX:2,GY:2.4,PAD:.6,CH:2.2,PANEL_H:.3},vu=`
|
|
278
|
+
`)}`);let r={...Fc,...n},{W:o,H:i}=r,a=m=>Math.round(m*10)/10,l=[],c=t.panels??[],{prect:d,parentIx:u,depthOf:f,cardAt:p}=Jo(t,r),g=c.map((m,C)=>{let R=d[C],G=e(m.label??"","title")+(m.sub?e(m.sub,"titleSub"):0);return{...m,rect:R,titleAt:[a(R.l+16),a(R.b-15)],depth:f(C),parent:u[C]>=0?c[u[C]].id:void 0,title:{l:R.l+10,r:R.l+22+G,t:R.b-30,b:R.b-6}}}),h=t.cards.map(m=>{let[C,R]=p(t.cards.indexOf(m));return{...m,rect:{l:C,t:R,r:C+o,b:R+i}}}),b=new Map;g.forEach(m=>b.set(m.id,m.rect)),h.forEach(m=>b.set(m.id,m.rect));let v=h.map(m=>m.rect),w=g.map(m=>m.rect),M=g.filter(m=>m.label).map(m=>m.title),y=(m,C)=>m.l>=C.l&&m.r<=C.r&&m.t>=C.t&&m.b<=C.b,T=(m,C,R,G)=>Math.min(m[0],C[0])<R.r+G&&Math.max(m[0],C[0])>R.l-G&&Math.min(m[1],C[1])<R.b+G&&Math.max(m[1],C[1])>R.t-G,S=(m,C)=>w.reduce((R,G)=>{if(m[0]===C[0]){let Z=Math.min(m[1],C[1]),$e=Math.max(m[1],C[1]);m[0]>G.l&&m[0]<G.r&&(R+=[G.t,G.b].filter(de=>de>Z+1&&de<$e-1).length)}else{let Z=Math.min(m[0],C[0]),$e=Math.max(m[0],C[0]);m[1]>G.t&&m[1]<G.b&&(R+=[G.l,G.r].filter(de=>de>Z+1&&de<$e-1).length)}return R},0),P=(m,C)=>w.some(R=>m[1]===C[1]?[R.t,R.b].some(G=>Math.abs(m[1]-G)<16&&Math.max(m[0],C[0])>R.l&&Math.min(m[0],C[0])<R.r):[R.l,R.r].some(G=>Math.abs(m[0]-G)<16&&Math.max(m[1],C[1])>R.t&&Math.min(m[1],C[1])<R.b)),I=(m,C,R,G)=>w.filter(Z=>Z!==R&&Z!==G&&!y(R,Z)&&!y(G,Z)&&T(m,C,{l:Z.l+3,r:Z.r-3,t:Z.t+3,b:Z.b-3},0)).length,_=[],O=new Map,j=new Map,k=(m,C)=>{_.push([m,C]);let[R,G]=m[1]===C[1]?[O,m[1]]:m[0]===C[0]?[j,m[0]]:[void 0,0];if(!R)return;let Z=Math.floor(G/6);(R.get(Z)??R.set(Z,[]).get(Z)).push([m,C])},$=(m,C)=>{let R=m[1]===C[1];if(!R&&m[0]!==C[0])return 0;let G=R?1:0,Z=R?0:1,$e=R?O:j,de=Math.floor(m[G]/6),De=Math.min(m[Z],C[Z]),He=Math.max(m[Z],C[Z]),Re=0;for(let ze=de-1;ze<=de+1;ze++)for(let[nt,st]of $e.get(ze)??[])Math.abs(m[G]-nt[G])<6&&Math.min(He,Math.max(nt[Z],st[Z]))-Math.max(De,Math.min(nt[Z],st[Z]))>0&&Re++;return Re},x=[...b.values()],N=Math.min(...x.map(m=>m.l)),F=Math.max(...x.map(m=>m.r)),J=Math.min(...x.map(m=>m.t)),oe=Math.max(...x.map(m=>m.b)),ve=(m,C)=>{let R=(m+C)/2;return[R,R-12,R+12,R-24,R+24]},B=(()=>{let m=[];return v.forEach(C=>v.forEach(R=>{R.t>C.b&&R.l<C.r+400&&R.r>C.l-400&&m.push(...ve(C.b,R.t))})),m.push(J-22,J-34,oe+22,oe+34),[...new Set(m.map(Math.round))]})(),W=(()=>{let m=[];return v.forEach(C=>v.forEach(R=>{R.l>C.r&&m.push(...ve(C.r,R.l))})),m.push(N-22,N-34,F+22,F+34),[...new Set(m.map(Math.round))]})(),ee=new Map,ue=new Map,z=m=>{let C=ee.get(m);return C||ee.set(m,C=v.filter(R=>m<R.b+6&&m>R.t-6)),C},X=m=>{let C=ue.get(m);return C||ue.set(m,C=v.filter(R=>m<R.r+6&&m>R.l-6)),C},Q=r.crossPanel/r.overlap,te=r.border/r.overlap,ne=r.nearEdge/r.overlap;function fe(m,C,R,G,Z=!0){let $e=0;for(let Re=1;Re<m.length;Re++)$e+=Math.abs(m[Re-1][0]-m[Re][0])+Math.abs(m[Re-1][1]-m[Re][1]);let de=$e+r.bend*(m.length-2);if(de>=G)return de;let De=0,He=0;for(let Re=1;Re<m.length;Re++){let ze=m[Re-1],nt=m[Re];if(Z){if(Oe(ze,nt,C,R)||P(ze,nt))return 1/0;continue}for(let st of ze[1]===nt[1]?z(ze[1]):X(ze[0]))st!==C&&st!==R&&T(ze,nt,st,6)&&De++;for(let st of M)T(ze,nt,st,2)&&De++}for(let Re=1;Re<m.length;Re++){let ze=m[Re-1],nt=m[Re];if(He+=$(ze,nt)+Q*I(ze,nt,C,R)+te*S(ze,nt),P(ze,nt)&&(He+=ne),de+r.overlap*He>=G)return de+r.overlap*He}return de+r.overlap*He+De*1e5}let be=m=>(m.l+m.r)/2,we=m=>(m.t+m.b)/2,Ne=[0,-22,22,-44,44],qe={bc:1/0},D=(m,C,R,G)=>Math.abs(m-R)+Math.abs(C-G),se=(m,C,R,G,Z,$e,de,De)=>{let He=0;return He+=D(m,C,R,G),He+=D(R,G,Z,$e),He+=D(Z,$e,de,De),He+r.bend*2},Me=(m,C,R,G,Z,$e,de,De,He,Re)=>{let ze=0;return ze+=D(m,C,R,G),ze+=D(R,G,Z,$e),ze+=D(Z,$e,de,De),ze+=D(de,De,He,Re),ze+r.bend*3},Oe=(m,C,R,G)=>{for(let Z of m[1]===C[1]?z(m[1]):X(m[0]))if(Z!==R&&Z!==G&&T(m,C,Z,6))return!0;for(let Z of M)if(T(m,C,Z,2))return!0;return P(m,C)};function ge(m,C,R,G){let Z=Math.max(m.l,C.l),$e=Math.min(m.r,C.r);if($e-Z>24)for(let Et of Ne){let yt=(Z+$e)/2+Et;yt>Z+8&&yt<$e-8&&R(C.t>=m.b?[[yt,m.b],[yt,C.t]]:[[yt,m.t],[yt,C.b]])}let de=Math.max(m.t,C.t),De=Math.min(m.b,C.b);if(De-de>16)for(let Et of[0,-10,10]){let yt=(de+De)/2+Et;R(C.l>=m.r?[[m.r,yt],[C.l,yt]]:[[m.l,yt],[C.r,yt]])}let He=W.length,Re=B.length,ze=new Uint8Array(Ne.length*Re),nt=new Uint8Array(Ne.length*Re),st=new Uint8Array(Ne.length*He),Ye=new Uint8Array(Ne.length*He),Pt=(Et,yt,wn,Xt)=>G?(Et[yt]||(Et[yt]=Oe(wn,Xt,m,C)?2:1),Et[yt]===1):!0;Ne.forEach((Et,yt)=>Ne.forEach((wn,Xt)=>{let Ht=be(m)+Et,Wt=be(C)+wn,zt=we(m)+Et/3,St=we(C)+wn/3;B.forEach((it,vn)=>{let Tt=it>m.b?m.b:it<m.t?m.t:null,tn=it>C.b?C.b:it<C.t?C.t:null;Tt!==null&&tn!==null&&se(Ht,Tt,Ht,it,Wt,it,Wt,tn)<qe.bc&&Pt(ze,yt*Re+vn,[Ht,Tt],[Ht,it])&&Pt(nt,Xt*Re+vn,[Wt,it],[Wt,tn])&&R([[Ht,Tt],[Ht,it],[Wt,it],[Wt,tn]])}),W.forEach((it,vn)=>{let Tt=it>m.r?m.r:it<m.l?m.l:null,tn=it>C.r?C.r:it<C.l?C.l:null;Tt!==null&&tn!==null&&se(Tt,zt,it,zt,it,St,tn,St)<qe.bc&&Pt(st,yt*He+vn,[Tt,zt],[it,zt])&&Pt(Ye,Xt*He+vn,[it,St],[tn,St])&&R([[Tt,zt],[it,zt],[it,St],[tn,St]])}),Et===0&&wn===0&&W.forEach((it,vn)=>B.forEach((Tt,tn)=>{let H=it>m.r?m.r:it<m.l?m.l:null,pe=Tt>C.b?C.b:Tt<C.t?C.t:null;H!==null&&pe!==null&&Me(H,zt,it,zt,it,Tt,Wt,Tt,Wt,pe)<qe.bc&&Pt(st,yt*He+vn,[H,zt],[it,zt])&&Pt(nt,Xt*Re+tn,[Wt,Tt],[Wt,pe])&&R([[H,zt],[it,zt],[it,Tt],[Wt,Tt],[Wt,pe]]);let ke=Tt>m.b?m.b:Tt<m.t?m.t:null,Te=it>C.r?C.r:it<C.l?C.l:null;ke!==null&&Te!==null&&Me(Ht,ke,Ht,Tt,it,Tt,it,St,Te,St)<qe.bc&&Pt(ze,yt*Re+tn,[Ht,ke],[Ht,Tt])&&Pt(Ye,Xt*He+vn,[it,St],[Te,St])&&R([[Ht,ke],[Ht,Tt],[it,Tt],[it,St],[Te,St]])}));let zn=be(m)<C.l?C.l:be(m)>C.r?C.r:null,Ct=St<m.t?m.t:St>m.b?m.b:null;zn!==null&&Ct!==null&&R([[Ht,Ct],[Ht,St],[zn,St]]);let ss=we(m)<C.t?C.t:we(m)>C.b?C.b:null,xs=Wt<m.l?m.l:Wt>m.r?m.r:null;ss!==null&&xs!==null&&R([[xs,zt],[Wt,zt],[Wt,ss]])}))}function ie(m,C,R,G){for(let Z of Ne){let $e=be(m)+Z,de=we(m)+Z/3,De=[[[$e,m.t],[$e,C.t]],[[m.r,de],[C.r,de]],[[$e,m.b],[$e,C.b]],[[m.l,de],[C.l,de]]];for(let He of De)G(R?[He[1],He[0]]:He)}}let Ke=(m,C,R,G)=>{let Z=null;return qe.bc=1/0,m($e=>{let de=fe($e,C,R,qe.bc,G);de<qe.bc&&(qe.bc=de,Z=$e)},G),Z},Ce=[],Ee=m=>w.some(C=>[C.l,C.r].some(R=>m.l<R+3&&m.r>R-3&&m.b>C.t&&m.t<C.b)||[C.t,C.b].some(R=>m.t<R+3&&m.b>R-3&&m.r>C.l&&m.l<C.r)),je=m=>_.filter(([C,R])=>T(C,R,m,1)).length,lt=m=>M.some(C=>m.l<C.r&&m.r>C.l&&m.t<C.b&&m.b>C.t),Ue=m=>v.filter(C=>m.l<C.r+3&&m.r>C.l-3&&m.t<C.b+3&&m.b>C.t-3).length,dt=m=>Ce.filter(C=>m.l<C.r+4&&m.r>C.l-4&&m.t<C.b+2&&m.b>C.t-2).length,ut=m=>50*bt(m)+3*je(m)+(Ee(m)?1:0)+(lt(m)?5:0)+5*Ue(m)+5*dt(m),Ae=m=>je(m)>0||Ee(m)||lt(m)||Ue(m)>0||dt(m)>0,pt=[];(t.links??[]).forEach((m,C)=>{let R=m.id??`link-${C}`,G=b.get(m.aOn??m.a),Z=b.get(m.bOn??m.b);if(G===Z){l.push(`link "${R}" joins "${m.aOn??m.a}" to itself: not drawn`),pt.push({...m,id:R,points:[],routed:!1});return}let $e=y(G,Z)?He=>ie(G,Z,!1,He):y(Z,G)?He=>ie(Z,G,!0,He):(He,Re)=>ge(G,Z,He,Re),de=Ke($e,G,Z,!0),De=!0;if(de||(de=Ke($e,G,Z,!1),De=!1,l.push(`link "${R}": no clear route; drawn the least bad way`)),!de){pt.push({...m,id:R,points:[],routed:!1});return}for(let He=1;He<de.length;He++)k(de[He-1],de[He]);pt.push({...m,id:R,points:de,routed:De})});let et=[];for(let m=0;m<_.length;m++)for(let C=m+1;C<_.length;C++){let[R,G]=_[m],[Z,$e]=_[C],de=R[1]===G[1],De=Z[1]===$e[1];if(de===De)continue;let[He,Re]=de?[[R,G],[Z,$e]]:[[Z,$e],[R,G]],ze=Re[0][0],nt=He[0][1];ze>Math.min(He[0][0],He[1][0])&&ze<Math.max(He[0][0],He[1][0])&&nt>Math.min(Re[0][1],Re[1][1])&&nt<Math.max(Re[0][1],Re[1][1])&&et.push([ze,nt])}let bt=m=>et.filter(([C,R])=>C>m.l-2&&C<m.r+2&&R>m.t-2&&R<m.b+2).length;for(let m of pt){let C=m,R=m.points;if(!C.label||!R.length)continue;let G=[];for(let Re=1;Re<R.length;Re++)G.push([R[Re-1],R[Re]]);let Z=Re=>Math.abs(Re[0][0]-Re[1][0])+Math.abs(Re[0][1]-Re[1][1]);G.sort((Re,ze)=>Z(ze)-Z(Re));let $e=e(C.label,"label")+6,de=null,De=null,He=1/0;for(let[Re,ze]of G){let nt=(Re[0]+ze[0])/2,st=(Re[1]+ze[1])/2,Ye=Re[1]===ze[1]?[0,-.3,.3,-.15,.15].flatMap(Pt=>{let Et=nt+Pt*Math.abs(Re[0]-ze[0]);return[[Et,st-6,"middle"],[Et,st+15,"middle"]]}):[0,-.3,.3].flatMap(Pt=>{let Et=st+4+Pt*Math.abs(Re[1]-ze[1]);return[[nt+7,Et,"start"],[nt-7,Et,"end"],[nt+24,Et,"start"],[nt-24,Et,"end"]]});for(let[Pt,Et,yt]of Ye){let wn=yt==="middle"?Pt-$e/2:yt==="end"?Pt-$e:Pt,Xt={l:wn,r:wn+$e,t:Et-11,b:Et+3};if(!Ae(Xt)){de=[Pt,Et,yt,Xt];break}let Ht=ut(Xt);Ht<He&&(He=Ht,De=[Pt,Et,yt,Xt])}if(de)break}if(!de&&De&&(de=De),!de){let[Re,ze]=G[0],nt=(Re[0]+ze[0])/2,st=(Re[1]+ze[1])/2-6;de=[nt,st,"middle",{l:nt-$e/2,r:nt+$e/2,t:st-11,b:st+3}]}Ce.push(de[3]),m.at={x:a(de[0]),y:a(de[1]),anchor:de[2],box:de[3],text:C.label}}let A=[],Y=[];for(let m of[...x,...Ce,...g.map(C=>C.title)])A.push(m.l,m.r),Y.push(m.t,m.b);for(let m of pt)for(let C of m.points)A.push(C[0]),Y.push(C[1]);let q=r.margin,ae={l:Math.min(...A)-q,t:Math.min(...Y)-q,r:Math.max(...A)+q,b:Math.max(...Y)+q};return{cards:h,panels:g,links:pt,bounds:ae,options:r,warnings:l}}function Gu(t,e,n){let s=o=>e>=o.l&&e<=o.r&&n>=o.t&&n<=o.b,r=t.cards.find(o=>s(o.rect));return r?r.id:[...t.panels].sort((o,i)=>i.depth-o.depth).find(o=>s(o.rect))?.id}function um(t,e,n,s={}){let r=a=>{let l=Js(a,e,s);return Math.max(l.bounds.r-l.bounds.l,(l.bounds.b-l.bounds.t)*n)},o=t,i=r(t);for(let a=0;a<12;a++){let l,c=i;for(let d of fm(o)){if(Fa(d).length)continue;let u=r(d);u<c-.5&&(c=u,l=d)}if(!l)break;o=l,i=c}return o}function*fm(t){let e=t.panels??[],n=(i,a)=>i[0]>=a[0]&&i[2]<=a[2]&&i[1]>=a[1]&&i[3]<=a[3],s=(i,a)=>i.every((l,c)=>l===a[c]),r=(i,a=-1)=>{let l=-1;return e.forEach((c,d)=>{d===a||!n(i,c.cells)||a>=0&&d>a&&s(c.cells,e[a].cells)||(l<0||n(c.cells,e[l].cells)&&(!s(c.cells,e[l].cells)||d>l))&&(l=d)}),l},o=i=>{let a=[];return e.forEach((l,c)=>{r(l.cells,c)===i&&a.push({range:[...l.cells],panel:c})}),t.cards.forEach((l,c)=>{let d=[l.cell[0],l.cell[1],l.cell[0],l.cell[1]];r(d)===i&&a.push({range:d,card:c})}),a};for(let i of[-1,...e.map((a,l)=>l)]){let a=o(i);if(i>=0&&!a.some(u=>u.panel!==void 0))continue;let l=u=>[u.range[1],u.range[3]],c=[];for(let u of[...a].sort((f,p)=>f.range[1]-p.range[1]||f.range[0]-p.range[0])){let f=c.find(p=>p.some(g=>l(g)[0]<=l(u)[1]&&l(u)[0]<=l(g)[1]));f?f.push(u):c.push([u])}let d=Math.max(...a.map(u=>u.range[3]));for(let u of c){u.sort((f,p)=>f.range[0]-p.range[0]);for(let f=1;f<u.length;f++){let p=u.slice(f),g=u[0].range[0],h=d+1,b=Math.min(...p.map(S=>S.range[1])),v=Math.max(...p.map(S=>S.range[3]))-b+1,w=t.cards.map(S=>({...S,cell:[...S.cell]})),M=e.map(S=>({...S,cells:[...S.cells]}));for(let S of w)S.cell[1]>d&&(S.cell[1]+=v);let y=new Set;for(let S=i;S>=0&&!y.has(S);S=r(e[S].cells,S))y.add(S);M.forEach((S,P)=>{S.cells[1]>d?(S.cells[1]+=v,S.cells[3]+=v):(y.has(P)||S.cells[1]<=d&&S.cells[3]>d)&&(S.cells[3]+=v)});let T=g;for(let S of p){let P=T-S.range[0],I=h+(S.range[1]-b)-S.range[1],_=O=>O[0]>=S.range[0]&&O[0]<=S.range[2]&&O[1]>=S.range[1]&&O[1]<=S.range[3];t.cards.forEach((O,j)=>{_([O.cell[0],O.cell[1]])&&(w[j].cell=[O.cell[0]+P,O.cell[1]+I])}),e.forEach((O,j)=>{n(O.cells,S.range)&&(M[j].cells=[O.cells[0]+P,O.cells[1]+I,O.cells[2]+P,O.cells[3]+I])}),T+=S.range[2]-S.range[0]+1}e.forEach((S,P)=>{let I=t.cards.map((_,O)=>n([_.cell[0],_.cell[1],_.cell[0],_.cell[1]],S.cells)?w[O].cell:void 0).filter(_=>!!_);I.length&&(M[P].cells=[Math.min(...I.map(_=>_[0])),Math.min(...I.map(_=>_[1])),Math.max(...I.map(_=>_[0])),Math.max(...I.map(_=>_[1]))])}),yield{cards:w,panels:M,links:t.links}}}}}function br(t,e=()=>!0){let n=t.layout.items.filter(P=>e(P.id)),s=t.layout.catalog,r=!t.layout.items.some(P=>P.type==="node"),o=P=>r?!P.children.some(I=>e(I.id)):P.type==="node"&&!P.children.some(I=>I.type==="node"&&e(I.id)),i=n.filter(o),a=P=>{let I=[];for(let _=P;_;_=_.parent)I.unshift(_);return I},l=new Map(i.map(P=>[P.id,a(P)])),c=(P,I)=>{let _=l.get(P.id),O=l.get(I.id),j=0;for(;j<_.length&&j<O.length&&_[j]===O[j];)j++;return[_[j].box,O[j].box]},d=1e-6,u=(P,I)=>{let[_,O]=c(P,I);return _.y1<=O.y0+d&&_.x0<O.x1-d&&O.x0<_.x1-d},f=(P,I)=>{let[_,O]=c(P,I);return _.x1<=O.x0+d&&_.y0<O.y1-d&&O.y0<_.y1-d},p=(P,I)=>{let _=new Map,O=[];for(let j of[...i].sort((k,$)=>I(k)-I($))){let k=0;for(let $ of O)_.get($.id)+1>k&&P($,j)&&(k=_.get($.id)+1);_.set(j.id,k),O.push(j)}return _},g=p(u,P=>P.box.y0),h=p(f,P=>P.box.x0),b=Math.min(...i.map(P=>P.box.x1-P.box.x0))/2;for(let P of i)if(!P.parent)for(let I of i)I.parent&&I.box.x0<=P.box.x0+b&&h.set(P.id,Math.max(h.get(P.id),h.get(I.id)));let v=new Map;for(let P of i)v.set(P.id,[h.get(P.id),g.get(P.id)]);let w=new Map;for(let P of i){let I=v.get(P.id),_=w.get(String(I));if(_!==void 0&&_!==P.id){for(let[,O]of v)O[0]>I[0]&&O!==I&&O[0]++;I[0]++,w.clear();for(let O of i)w.set(String(v.get(O.id)),O.id)}else w.set(String(I),P.id)}let M=i.map(P=>{if(P.region){let O=P.region;return{id:P.id,label:O.label??P.id,sub:void 0,role:O.role??Dt(s,O.kind)?.role??"grey",ghost:O.ghost||void 0,cell:v.get(P.id)}}let I=P.node,_=Dn(s,I.asset);return{id:P.id,label:I.label??P.id,sub:I.sub,role:I.role??_.role,ghost:I.ghost||void 0,cell:v.get(P.id)}}),y=[];for(let P of n){if(o(P))continue;let I=[],_=x=>{for(let N of x.children){let F=v.get(N.id);F&&I.push(F),_(N)}};if(_(P),!I.length)continue;let O=I.map(x=>x[0]),j=I.map(x=>x[1]),k=P.type==="region"?P.region.label:P.node.label??P.id,$=P.type==="region"?P.region.role??Dt(s,P.region.kind)?.role:P.node.role??Dn(s,P.node.asset).role;y.push({id:P.id,label:k,sub:P.type==="node"?P.node.sub:void 0,role:$,cells:[Math.min(...O),Math.min(...j),Math.max(...O),Math.max(...j)]})}let T=new Set([...M.map(P=>P.id),...y.map(P=>P.id)]),S=[];for(let P of t.routes){if(!e(P.id))continue;let I=On(P.raw.from).id,_=On(P.raw.to).id;if(!T.has(I)||!T.has(_))continue;let O=typeof P.raw.label=="string"?P.raw.label:P.raw.label?.text;S.push({id:P.id,a:I,b:_,kind:P.kind,label:O})}return{cards:M,panels:y,links:S}}var Xs={W:4,D:2,H:.9,GX:2,GY:2.4,PAD:.6,CH:2.2,PANEL_H:.3},Hu=`
|
|
279
279
|
.blk .card-name{font-size:13px;font-weight:600;fill:var(--ink)}
|
|
280
280
|
.blk .card-sub{font-size:10px;fill:var(--ink);opacity:.75}
|
|
281
281
|
.blk.ghost .card-name,.blk.ghost .card-sub{fill:var(--muted)}
|
|
282
|
-
`;function xc(t){return{name:"card",description:"A card: a slab with its name on its front face",size:[js.W,js.D,js.H],role:"grey",draw(e,n,s){let r=t(s.id),o=e.blockFaces(n);if(!r)return o;let i=n.z1-n.z0;return o+=e.faceText(n.x0+.2,n.y1,n.z0+(r.sub?i*.52:i*.34),r.label,"card-name",Bt.lbl,"left","start"),r.sub&&(o+=e.faceText(n.x0+.2,n.y1,n.z0+i*.14,r.sub,"card-sub",Bt.sub,"left","start")),o}}}function ku(t){let e=new Map(t.cards.map(n=>[n.id,{label:n.label,sub:n.sub}]));return{regions:{panel:{shape:"slab",pad:js.PAD,z:[js.PANEL_H,0],floor:!0,role:"grey",labelStyle:"floor"}},nodes:{card:xc(n=>e.get(n))},defaultNode:"card"}}function Su(t,e={}){let n=js,{prect:s,parentIx:r,cardAt:o}=jo(t,{W:n.W,H:n.D,GX:n.GX,GY:n.GY,PAD:n.PAD,TITLE:0,CH:n.CH}),i=t.panels??[],a=g=>Math.round(g*1e3)/1e3,l=g=>(g.cells[2]-g.cells[0]+1)*(g.cells[3]-g.cells[1]+1),c=g=>{let h=-1;return i.forEach((b,k)=>{let v=b.cells;g.cell[0]>=v[0]&&g.cell[0]<=v[2]&&g.cell[1]>=v[1]&&g.cell[1]<=v[3]&&(h<0||l(b)<=l(i[h]))&&(h=k)}),h},d=i.map((g,h)=>{let b=s[h],k=r[h]>=0?s[r[h]]:{l:0,t:0};return{id:g.id,kind:"panel",label:g.label,role:g.role,at:[a(b.l-k.l),a(b.t-k.t)],size:[a(b.r-b.l),a(b.b-b.t)],regions:[],nodes:[]}}),u=[],f=[];d.forEach((g,h)=>r[h]>=0?d[r[h]].regions.push(g):u.push(g));for(let g of t.cards){let[h,b]=o(t.cards.indexOf(g)),k=c(g),v=k>=0?s[k]:{l:0,t:0},M={id:g.id,asset:"card",role:g.role,ghost:g.ghost||void 0,at:[a(h-v.l),a(b-v.t)],size:[n.W,n.D,n.H]};(k>=0?d[k].nodes:f).push(M)}for(let g of d)g.regions.length||delete g.regions,g.nodes.length||delete g.nodes;let p=(t.links??[]).map((g,h)=>({id:g.id??`link-${h}`,from:g.aOn??g.a,to:g.bOn??g.b,kind:g.kind,label:g.label}));return{isodiag:1,title:e.title,kinds:e.kinds,roles:e.roles,scenes:[{id:"board",title:e.title??"board",regions:u,nodes:f,routes:p}]}}var uf={};Qo(uf,{APPEARS:()=>Pu,BASE_FIELDS:()=>Nc,BINS:()=>ju,BIN_MS:()=>On,CARD:()=>jt,DUAL_VIEW_CSS:()=>df,IDLES:()=>Ou,MAX_ZOOM:()=>Eu,MIN_ZOOM:()=>$u,P3:()=>ht,SEGMENT_NAME:()=>Ma,SEVERITIES:()=>mn,TIMELINE_VERSION:()=>Fu,activityOf:()=>jc,attr:()=>zn,binNext:()=>Oa,binStart:()=>ir,cardMotion:()=>Cu,cls:()=>Lu,crumbs:()=>jr,dualView:()=>af,escapeName:()=>Ta,extent:()=>ka,findGaps:()=>Ca,fitWithOverlay:()=>Ru,flatCss:()=>nf,flatSvg:()=>_r,formatScope:()=>Bu,gapKey:()=>lr,gapLabel:()=>ar,h:()=>z,hasSegment:()=>zu,highlights:()=>_o,isZone:()=>Hu,isoVars:()=>Iu,join:()=>Ku,kindOf:()=>Dr,legend:()=>Cc,levelOf:()=>Xt,markConnectors:()=>Vr,md:()=>ns,measureIn:()=>zr,memorySource:()=>Ju,modeFor:()=>Fc,morphSvgs:()=>ja,mountTimeline:()=>ef,n:()=>Sc,nameOf:()=>Fr,node:()=>Nu,offsetAt:()=>tn,overlayPaint:()=>Tu,parentOf:()=>_u,prefixAt:()=>vs,prune:()=>$c,pts:()=>Bo,rangeOf:()=>Ko,readTime:()=>Lc,rectOf:()=>sf,renderPage:()=>Du,rewrite:()=>Mc,scope:()=>Tc,scopePattern:()=>$a,scopeRules:()=>Ea,scopeSelector:()=>Ec,searchFor:()=>Br,severities:()=>Vu,stepData:()=>Oc,storedMode:()=>lf,ticks:()=>Na,timeScale:()=>Kr,toCSV:()=>Ra,toJSON:()=>La,unite:()=>Sa,viewToggle:()=>cf,viewport:()=>va,within:()=>hn});var $u=.1,Eu=8;function va(t,e){let n,s,r=!1,o=0,i=0,a=0,l=0,c=0,d=!1,u=()=>{let A=t.getBoundingClientRect();return{w:Math.max(1,A.width),h:Math.max(1,A.height)}},f=(A=n)=>{let D=u();return Math.min(D.w/A.w,D.h/A.h)},p=A=>{o++;try{A()}finally{o--}};function g(){let A=e.svg();if(!A||!n)return;o||(r=!0);let D=u(),K=f(),C=D.w/K,_=D.h/K;n={x:n.x+(n.w-C)/2,y:n.y+(n.h-_)/2,w:C,h:_},A.setAttribute("viewBox",`${n.x.toFixed(2)} ${n.y.toFixed(2)} ${n.w.toFixed(2)} ${n.h.toFixed(2)}`),i=K,e.onApply(K),a&&Math.abs(K/a-1)>.02&&(cancelAnimationFrame(l),l=requestAnimationFrame(()=>{l=0,e.onRezoom()}))}let h=(A,D)=>{let K=t.getBoundingClientRect(),C=f();return{x:n.x+(A-K.left)/C,y:n.y+(D-K.top)/C}};function b(A,D,K){if(!n)return;let C=f(),_=Math.min(8,Math.max(.1,C*A)),S=t.getBoundingClientRect(),$=D??S.left+S.width/2,w=K??S.top+S.height/2,N=h($,w),F=u();n={x:N.x-($-S.left)/_,y:N.y-(w-S.top)/_,w:F.w/_,h:F.h/_},g()}function k(A=s){if(!A)return;let D=u(),K=24,C=Math.min(8,Math.max(.1,Math.min((D.w-K*2)/A.w,(D.h-K*2)/A.h))),_=A.x+A.w/2,S=A.y+A.h/2,$={x:_-D.w/C/2,y:S-D.h/C/2,w:D.w/C,h:D.h/C};if(n&&Math.abs($.w/n.w-1)<.001&&Math.abs($.h/n.h-1)<.001&&Math.abs($.x-n.x)<$.w*.001&&Math.abs($.y-n.y)<$.h*.001){g();return}n=$,g()}function v(){for(let A=0,D="";A<4;A++){let K=e.itemsBox()??s;if(!K)return;let C=[K.x,K.y,K.w,K.h].map(S=>Math.round(S)).join();if(C===D)break;D=C;let _=Math.max(24,Math.min(K.w,K.h)*.06);if(p(()=>k({x:K.x-_,y:K.y-_,w:K.w+_*2,h:K.h+_*2})),!e.marksShowing()||!a||Math.abs(f()/a-1)<=.02)break;cancelAnimationFrame(l),l=0,e.onRezoom()}r=!1}function M(){if(r||!e.svg()||!n)return;let A=t.getBoundingClientRect();A.width<2||A.height<2||v()}function x(){if(!n)return;let A=f();b(1/A)}function T(){return new Promise(A=>{let D=0,K=i,C=()=>{if(d){A();return}let _=!!(l||c)||i!==K;K=i,D=_?0:D+1,D>=2?A():requestAnimationFrame(C)};requestAnimationFrame(C)})}let y=new ResizeObserver(()=>{if(!(!n||d)){if(r&&i){let A=u(),D=n.x+n.w/2,K=n.y+n.h/2;n={x:D-A.w/i/2,y:K-A.h/i/2,w:A.w/i,h:A.h/i}}r||(cancelAnimationFrame(c),c=requestAnimationFrame(()=>{c=0,d||M()})),p(g)}});return y.observe(t),{get view(){return n},set view(A){n=A},get full(){return s},set full(A){s=A},get moved(){return r},get zoom(){return i},painted(A){a=A},size:u,scale:f,quietly:p,applyView:g,toSvg:h,zoomAt:b,fit:k,fitItems:v,autoFit:M,actual:x,settled:T,dispose(){cancelAnimationFrame(c),cancelAnimationFrame(l),y.disconnect(),d=!0}}}var Kt="http://www.w3.org/2000/svg",jt={half:2.4,h:3.2,t:.25,above:1.4,lift:3.8,fan:.32,gap:.3},ht=(t,e,n)=>[(t-e)*It*xt,(t+e)*.5*xt-n*xt],Bo=t=>t.map(([e,n])=>`${e.toFixed(1)},${n.toFixed(1)}`).join(" ");function Tu(t,e){function n(o,i,a){let l=t.k(),c=(u,f,p,g,h="")=>{let b=o.createElementNS(Kt,"g");b.setAttribute("class",`live-badge ${p.cls} ${h}`.trim());let k=8/l,v=o.createElementNS(Kt,"circle");if(v.setAttribute("cx",String(u)),v.setAttribute("cy",String(f)),v.setAttribute("r",String(k)),b.append(v),"g"in p){let x=o.createElementNS(Kt,"text");x.setAttribute("x",String(u)),x.setAttribute("y",String(f)),x.style.fontSize=`${(10/l).toFixed(2)}px`,x.textContent=p.g,b.append(x)}else{let x=o.createElementNS(Kt,"use");x.setAttribute("href",t.iconHref(p.icon));let T=11/l;x.setAttribute("x",String(u-T/2)),x.setAttribute("y",String(f-T/2)),x.setAttribute("width",String(T)),x.setAttribute("height",String(T)),b.append(x)}let M=o.createElementNS(Kt,"title");M.textContent=g,b.append(M),i(b)},d=(u,f)=>{for(let p of t.outlinesFor(u)){if(p.kind!=="poly")continue;let g=o.createElementNS(Kt,"polygon");g.setAttribute("class",f),g.setAttribute("points",p.points.map(([h,b])=>`${h.toFixed(1)},${b.toFixed(1)}`).join(" ")),i(g)}};for(let u of a){let f=t.boxOf(u.at);if(f){if(u.outline&&d(u.at,u.outline),u.badge)c(f.x,f.y,u.badge,u.title);else if(u.hit){let p=o.createElementNS(Kt,"title");p.textContent=u.title;let g=o.createElementNS(Kt,"rect");g.setAttribute("class","live-hit"),g.setAttribute("x",String(f.x)),g.setAttribute("y",String(f.y)),g.setAttribute("width",String(f.w)),g.setAttribute("height",String(f.h)),g.append(p),i(g)}if((u.beside??[]).forEach((p,g)=>c(f.x+18*(g+1)/l,f.y,p.glyph,p.title)),u.dot&&c(f.x,f.y+f.h,u.dot.glyph,u.dot.title),u.tag){let p=o.createElementNS(Kt,"text");p.setAttribute("class",`live-life ${u.tag.cls}`),p.setAttribute("x",String(f.x+f.w)),p.setAttribute("y",String(f.y+f.h)),p.style.fontSize=`${(9/l).toFixed(2)}px`,p.textContent=u.tag.text,i(p)}}}}function s(o,i,a){for(let l of a){let c=o.createElementNS(Kt,"g");c.setAttribute("class",`live-extra${l.cls}`);for(let[M,x]of l.data)c.setAttribute(M,x);let{x:d,y:u,w:f,hgt:p,k:g}=l.rect,h=o.createElementNS(Kt,"rect");h.setAttribute("x",String(d)),h.setAttribute("y",String(u)),h.setAttribute("width",String(f)),h.setAttribute("height",String(p)),h.setAttribute("rx",String(6/g));let b=o.createElementNS(Kt,"text");b.setAttribute("x",String(d+8/g)),b.setAttribute("y",String(u+13/g)),b.style.fontSize=`${(11/g).toFixed(2)}px`,b.textContent=l.line1;let k=o.createElementNS(Kt,"text");k.setAttribute("class","sub"),k.setAttribute("x",String(d+8/g)),k.setAttribute("y",String(u+27/g)),k.style.fontSize=`${(9/g).toFixed(2)}px`,k.textContent=l.line2;let v=o.createElementNS(Kt,"title");v.textContent=l.title,c.append(h,b,k,v),i(c)}}function r(o,i,a){let l=[];for(let c of a){let d=c.over,u=(d.x0+d.x1)/2,f=(d.y0+d.y1)/2,p=0,g={x0:0,y0:0,x1:0,y1:0};for(let j=0;j<6;j++){let U=d.z1+jt.above+p,ee=U+jt.h,fe=[ht(u-jt.half,f+jt.t,U),ht(u+jt.half,f+jt.t,U),ht(u+jt.half,f-jt.t,ee),ht(u-jt.half,f+jt.t,ee)];if(g={x0:Math.min(...fe.map(B=>B[0])),y0:Math.min(...fe.map(B=>B[1])),x1:Math.max(...fe.map(B=>B[0])),y1:Math.max(...fe.map(B=>B[1]))},!rr(g,l))break;p+=jt.lift}l.push(g);let h=d.z1+jt.above+p,b=h+jt.h,k=u-jt.half,v=u+jt.half,M=f+jt.t,x=f-jt.t,T=o.createElementNS(Kt,"g");T.setAttribute("class",`${e}-card${c.cls}`);for(let[j,U]of c.data)T.setAttribute(j,U);let[y,A]=ht(u,f,d.z1+.15),D=`${y.toFixed(1)}px ${A.toFixed(1)}px`;T.style.transformOrigin=D;let K=o.createElementNS(Kt,"g");K.setAttribute("class",`${e}-float`),K.style.transformOrigin=D;let C=[];for(let j=Math.min(c.count-1,3);j>=1;j--){let U=j*jt.fan,ee=x-(j-1)*(2*jt.t+jt.gap)-jt.gap,fe=ee-2*jt.t,B=k+U,X=v+U,Q=h+U,te=b+U,ne=(me,ye)=>{let xe=o.createElementNS(Kt,"polygon");xe.setAttribute("class",`${e}-face stacked ${me}`),xe.setAttribute("points",Bo(ye)),K.append(xe)};ne("s-top",[ht(B,fe,te),ht(X,fe,te),ht(X,ee,te),ht(B,ee,te)]),ne("s-side",[ht(X,fe,Q),ht(X,ee,Q),ht(X,ee,te),ht(X,fe,te)]),ne("s-front",[ht(B,ee,Q),ht(X,ee,Q),ht(X,ee,te),ht(B,ee,te)]),C.push({x0:B,x1:X,y0:fe,y1:ee,z0:Q,z1:te})}let _=o.createElementNS(Kt,"polygon");_.setAttribute("class",`${e}-tail`),_.setAttribute("points",Bo([ht(u-.5,M,h+.05),ht(u+.5,M,h+.05),ht(u,f,d.z1+.15)]));let S=(j,U)=>{let ee=o.createElementNS(Kt,"polygon");return ee.setAttribute("class",j),ee.setAttribute("points",Bo(U)),ee},$=S(`${e}-face front`,[ht(k,M,h),ht(v,M,h),ht(v,M,b),ht(k,M,b)]);K.append(_,S(`${e}-face top`,[ht(k,x,b),ht(v,x,b),ht(v,M,b),ht(k,M,b)]),S(`${e}-face side`,[ht(v,x,h),ht(v,M,h),ht(v,M,b),ht(v,x,b)]),$);let[w,N]=ht(k,M,b),F=40,J=o.createElementNS(Kt,"g");J.setAttribute("transform",`matrix(${(It*xt/F).toFixed(4)} ${(.5*xt/F).toFixed(4)} 0 ${(xt/F).toFixed(4)} ${w.toFixed(1)} ${N.toFixed(1)})`);let ae=(j,U,ee,fe)=>{let B=o.createElementNS(Kt,"text");return B.setAttribute("class",j),B.setAttribute("x",String(U)),B.setAttribute("y",String(ee)),B.textContent=fe,B};if(J.append(ae(`${e}-mark`,34,98,c.mark),ae(`${e}-who`,70,52,c.who),ae(`${e}-age`,70,82,c.age)),c.line!==void 0&&J.append(ae(`${e}-q`,12,118,c.line)),c.count>1){let j=o.createElementNS(Kt,"circle");j.setAttribute("class",`${e}-count-bg`),j.setAttribute("cx","178"),j.setAttribute("cy","14"),j.setAttribute("r","15"),J.append(j,ae(`${e}-count`,178,14,String(c.count)))}K.append(J);let we=o.createElementNS(Kt,"title");we.textContent=c.title,T.append(K,we),t.onCard?.(T,{cx:u,cy:f,tipZ:d.z1+.15,card:{x0:k,x1:v,y0:x,y1:M,z0:h,z1:b},panes:C.reverse()}),i(T)}}return{paintMarks:n,paintGhosts:s,paintCards:r}}var Pu=[["scale","Scale"],["spin","Spin"],["dissolve","Dissolve"],["inflate","Inflate"]],Ou=[["none","None"],["jiggle","Jiggle"],["pirouette","Pirouette"],["glow","Glow"],["breathe","Breathe"]];function zp(t){let e=2166136261;for(let n=0;n<t.length;n++)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return(e>>>0)%1e3/1e3}var wc=t=>t<0?0:t>1?1:1-Math.pow(1-t,3),Au=t=>t<0?0:t>1?1:t*t*t,vc=Math.PI*2,kc={appear:{scale:420,spin:760,dissolve:520,inflate:640},disappear:{scale:320,spin:600,dissolve:420,inflate:420},period:{jiggle:4200,pirouette:6400,glow:3200,breathe:4400}},Pn={windup:220,turn:980,land:260};function Cu(t,e,{prefix:n,key:s,alt:r}){let o={...e},i=1,a=new Map,l=new WeakSet,c=0,d=0,u=new WeakMap,f=new WeakMap;function p(_){c=0;for(let[S,$]of a){if(!S.isConnected){a.delete(S);continue}let w;if($.repeat){if(w=(_+($.offset??0))%$.repeat/$.dur,w>1){l.has(S)&&(t.restore(S),l.delete(S),S.style.removeProperty("transform"));continue}}else if(w=(_-$.start)/$.dur,w>=1){g(S,$);continue}let N=$.frame(Math.max(0,w));t.spin(S,N.theta,N.lift),l.add(S),f.set(S,N),N.scale!==1?S.style.transform=`scale(${N.scale.toFixed(4)})`:S.style.removeProperty("transform"),d++}a.size&&(c=requestAnimationFrame(p))}function g(_,S){a.delete(_),l.has(_)&&(t.restore(_),l.delete(_)),_.style.removeProperty("transform"),S.done?.()}function h(_){let S=a.get(_.card);S&&g(_.card,S),a.set(_.card,_),c||(c=requestAnimationFrame(p))}let b=8,k=0,v=_=>(k++,_.finally(()=>{k--}));function M(_){return!o.enabled||k>=b?Promise.resolve():v(T(_))}function x(_){return!o.enabled||k>=b?Promise.resolve():v(y(_))}function T(_){let S=kc.appear[o.appear]/i;if(o.appear==="spin")return new Promise(N=>h({card:_,start:performance.now(),dur:S,frame:F=>({theta:(1-wc(F))*vc,lift:0,scale:Math.max(.001,wc(F))}),done:N}));let $=o.appear==="scale"?[{transform:"scale(0)"},{transform:"scale(1)"}]:o.appear==="dissolve"?[{opacity:0,filter:"blur(4px)"},{opacity:1,filter:"blur(0px)"}]:[{transform:"scale(0)",easing:"cubic-bezier(.3,0,.4,1)"},{transform:"scale(1.16)",offset:.55,easing:"ease-in-out"},{transform:"scale(.95)",offset:.78,easing:"ease-in-out"},{transform:"scale(1)"}];return _.animate($,{duration:S,easing:o.appear==="inflate"?"linear":"ease-out"}).finished.then(()=>{},()=>{})}function y(_){let S=kc.disappear[o.appear]/i;if(o.appear==="spin")return new Promise(N=>h({card:_,start:performance.now(),dur:S,frame:F=>({theta:Au(F)*vc,lift:0,scale:Math.max(.001,1-Au(F))}),done:()=>{_.style.transform="scale(0)",N()}}));let $=o.appear==="scale"?[{transform:"scale(1)"},{transform:"scale(0)"}]:o.appear==="dissolve"?[{opacity:1,filter:"blur(0px)"},{opacity:0,filter:"blur(4px)"}]:[{transform:"scale(1)"},{transform:"scale(1.08)",offset:.3},{transform:"scale(0)"}];return _.animate($,{duration:S,easing:"ease-in",fill:"forwards"}).finished.then(()=>{},()=>{})}function A(_){u.get(_)?.cancel(),u.delete(_);let S=a.get(_);S?.repeat&&g(_,S)}function D(_,S){if(A(_),!o.enabled||o.idle==="none"||_.classList.contains("still"))return;let $=_.getAttribute(s)??_.getAttribute(r)??"",w=(S??kc.period[o.idle])/i,N=zp($)*w;if(o.idle==="pirouette"){let j=(Pn.windup+Pn.turn+Pn.land)/i,U=Pn.windup/(Pn.windup+Pn.turn+Pn.land),ee=(Pn.windup+Pn.turn)/(Pn.windup+Pn.turn+Pn.land);h({card:_,start:0,dur:j,repeat:w,offset:N,frame:fe=>{if(fe<U)return{theta:-.35*Math.sin(fe/U*Math.PI/2),lift:0,scale:1};if(fe<ee){let X=(fe-U)/(ee-U);return{theta:-.35*(1-X)+wc(X)*vc,lift:.9*Math.sin(X*Math.PI),scale:1}}let B=(fe-ee)/(1-ee);return{theta:0,lift:0,scale:1-.04*Math.sin(B*Math.PI)}}});return}let F=_.querySelector(`.${n}-float`)??_,J=t.amber(),ae=o.idle==="jiggle"?[{transform:"scale(1)",offset:0},{transform:"scale(1.07)",offset:.04},{transform:"scale(.97)",offset:.08},{transform:"scale(1.02)",offset:.11},{transform:"scale(1)",offset:.14},{transform:"scale(1)",offset:1}]:o.idle==="glow"?[{filter:`drop-shadow(0 0 0px ${J})`},{filter:`drop-shadow(0 0 7px ${J})`},{filter:`drop-shadow(0 0 0px ${J})`}]:[{transform:"scale(1)"},{transform:"scale(1.035)"},{transform:"scale(1)"}],we=F.animate(ae,{duration:w,iterations:1/0,easing:o.idle==="jiggle"?"linear":"ease-in-out"});we.startTime=(document.timeline.currentTime??0)-((document.timeline.currentTime??0)+N)%w,u.set(_,we)}function K(_,S,$,w,N=!1){N&&(w=!1);for(let[J,ae]of S)!_.has(J)&&!N&&M(ae),!u.has(ae)&&!a.get(ae)?.repeat&&D(ae);if(!o.enabled||!w)return;let F=t.leavingLayer();if(F)for(let[J,ae]of $){let we=_.get(J);!we||S.has(J)||(A(we),we.setAttribute("class",`${n}-leaving${ae?" expired":""}`),we.removeAttribute(r),F.append(we),x(we).then(()=>we.remove()))}}function C(_){for(let[S,$]of[...a])g(S,$);c&&cancelAnimationFrame(c),c=0;for(let S of document.getAnimations())S.effect?.target?.closest?.(`.live-layer, .${n}-leaving-layer`)&&S.cancel();t.leavingLayer()?.replaceChildren()}return{get settings(){return{...o}},set(_,S){let $=o;if(o={...o,..._},(!o.enabled||$.idle!==o.idle||$.enabled!==o.enabled)&&(C(void 0),o.enabled))for(let w of S)D(w)},update:K,appear:M,disappear:x,startIdle:D,stopIdle:A,stopAll:C,async preview(_){o.enabled&&await Promise.all(_.map(async S=>{if(A(S),await M(S),o.idle!=="none"&&!S.classList.contains("still")){let $=o.idle==="pirouette"?1800:1400;D(S,$),await new Promise(w=>setTimeout(w,$*2.2/i)),A(S)}else await new Promise($=>setTimeout($,700/i));await x(S);for(let $ of S.getAnimations())$.cancel();S.style.removeProperty("transform"),D(S)}))},get stats(){return{jobs:a.size,raf:!!c,frames:d,effects:k}},setSpeed(_){i=_},lastFrame:_=>f.get(_)}}var Sc=t=>String(Math.round(t*100)/100),Nu=(t,e={},...n)=>({name:t,attrs:Object.entries(e).map(([s,r])=>[s,typeof r=="number"?Sc(r):r]),children:n});function Mc(t,e){if(typeof t=="string")return t;let n=t.attrs.map(([s,r])=>{if(s==="id")return[s,e+r];let o=r.replace(/var\(--([a-zA-Z][\w-]*)/g,"var(--iso-$1").replace(/url\(\s*(['"]?)#/g,(i,a)=>`url(${a}#${e}`);return(s==="href"||s==="xlink:href")&&o.startsWith("#")&&!o.startsWith(`#${e}`)&&(o=`#${e}${o.slice(1)}`),[s,o]});return{name:t.name,attrs:n,children:t.children.map(s=>Mc(s,e))}}function $c(t,e){if(typeof t=="string")return t;if(!e(t))return{...t,children:t.children.map(n=>$c(n,e)).filter(n=>n!==void 0)}}var Lu=t=>(t.attrs.find(e=>e[0]==="class")?.[1]??"").split(/\s+/),zn=(t,e)=>t.attrs.find(n=>n[0]===e)?.[1];function ka(t){let e=[],n=[],s=i=>{if(typeof i=="string")return;let a=zn(i,"transform");if(a&&/matrix/.test(a))return;let l=zn(i,"points");if(l)for(let c of l.trim().split(/\s+/)){let[d,u]=c.split(",").map(Number);Number.isFinite(d)&&Number.isFinite(u)&&(e.push(d),n.push(u))}if(i.name==="rect"){let c=Number(zn(i,"x")),d=Number(zn(i,"y")),u=Number(zn(i,"width")),f=Number(zn(i,"height"));[c,d,u,f].every(Number.isFinite)&&(e.push(c,c+u),n.push(d,d+f))}if(i.name==="circle"){let c=Number(zn(i,"cx")),d=Number(zn(i,"cy")),u=Number(zn(i,"r"));[c,d,u].every(Number.isFinite)&&(e.push(c-u,c+u),n.push(d-u,d+u))}i.children.forEach(s)};if(t.forEach(s),!e.length)return;let r=Math.min(...e),o=Math.min(...n);return{x:r,y:o,w:Math.max(...e)-r,h:Math.max(...n)-o}}var Sa=(t,e)=>{if(!e)return t;let n=Math.min(t.x,e.x),s=Math.min(t.y,e.y);return{x:n,y:s,w:Math.max(t.x+t.w,e.x+e.w)-n,h:Math.max(t.y+t.h,e.y+e.h)-s}};function Ru(t,e,n){let s=a=>Math.min((e.width-e.pad*2)/a.w,(e.height-e.pad*2)/a.h),r=s(t),o=n(r),i=Sa(t,ka(o));return r=s(i),o=n(r),i=Sa(t,ka(o)),r=s(i),{k:r,box:i,live:o}}var Iu=t=>t.replace(/--([a-zA-Z][\w-]*)/g,"--iso-$1");function Vp(t){let e=[],n=0,s=t.replace(/\/\*[\s\S]*?\*\//g,"");for(;n<s.length;){let r=s.indexOf("{",n);if(r<0)break;let o=1,i=r+1;for(;i<s.length&&o;)s[i]==="{"?o++:s[i]==="}"&&o--,i++;e.push([s.slice(n,r).trim(),s.slice(r+1,i-1)]),n=i}return e}function Gp(t){let e=[],n=0,s=0;for(let r=0;r<t.length;r++){let o=t[r];o==="("||o==="["?n++:o===")"||o==="]"?n--:o===","&&!n&&(e.push(t.slice(s,r).trim()),s=r+1)}return e.push(t.slice(s).trim()),e.filter(Boolean)}function Ec(t,e,n){let s=/^:root((?:\[[^\]]*\]|:not\([^)]*\))*)(.*)$/.exec(t),r=n.replace(/^\./,"");if(s){let o=s[1],i=s[2].trim();return`${o?`.${r}${o} `:""}${e}${i?" "+i:""}`}if(/^(html|body|\*)\b/.test(t)||/^[a-z]+$/.test(t)&&!/^(svg|g|text|path|polygon|rect|circle|line)$/.test(t))throw new Error(`the canvas's CSS can't style the page: "${t}"`);return`${e} ${t}`}function Tc(t,e,n){let s="";for(let[r,o]of Vp(t)){if(r.startsWith("@keyframes")){s+=`@keyframes iso-${r.slice(10).trim()}{${o}}
|
|
283
|
-
`;continue}if(r.startsWith("@media")||r.startsWith("@supports")){s+=`${r}{${
|
|
284
|
-
`;continue}if(r.startsWith("@"))throw new Error(`the canvas's CSS has an at-rule it can't scope: ${r}`);s+=`${
|
|
285
|
-
`}return s}var
|
|
282
|
+
`;function Bc(t){return{name:"card",description:"A card: a slab with its name on its front face",size:[Xs.W,Xs.D,Xs.H],role:"grey",draw(e,n,s){let r=t(s.id),o=e.blockFaces(n);if(!r)return o;let i=n.z1-n.z0;return o+=e.faceText(n.x0+.2,n.y1,n.z0+(r.sub?i*.52:i*.34),r.label,"card-name",It.lbl,"left","start"),r.sub&&(o+=e.faceText(n.x0+.2,n.y1,n.z0+i*.14,r.sub,"card-sub",It.sub,"left","start")),o}}}function Yu(t){let e=new Map(t.cards.map(n=>[n.id,{label:n.label,sub:n.sub}]));return{regions:{panel:{shape:"slab",pad:Xs.PAD,z:[Xs.PANEL_H,0],floor:!0,role:"grey",labelStyle:"floor"}},nodes:{card:Bc(n=>e.get(n))},defaultNode:"card"}}function qu(t,e={}){let n=Xs,{prect:s,parentIx:r,cardAt:o}=Jo(t,{W:n.W,H:n.D,GX:n.GX,GY:n.GY,PAD:n.PAD,TITLE:0,CH:n.CH}),i=t.panels??[],a=g=>Math.round(g*1e3)/1e3,l=g=>(g.cells[2]-g.cells[0]+1)*(g.cells[3]-g.cells[1]+1),c=g=>{let h=-1;return i.forEach((b,v)=>{let w=b.cells;g.cell[0]>=w[0]&&g.cell[0]<=w[2]&&g.cell[1]>=w[1]&&g.cell[1]<=w[3]&&(h<0||l(b)<=l(i[h]))&&(h=v)}),h},d=i.map((g,h)=>{let b=s[h],v=r[h]>=0?s[r[h]]:{l:0,t:0};return{id:g.id,kind:"panel",label:g.label,role:g.role,at:[a(b.l-v.l),a(b.t-v.t)],size:[a(b.r-b.l),a(b.b-b.t)],regions:[],nodes:[]}}),u=[],f=[];d.forEach((g,h)=>r[h]>=0?d[r[h]].regions.push(g):u.push(g));for(let g of t.cards){let[h,b]=o(t.cards.indexOf(g)),v=c(g),w=v>=0?s[v]:{l:0,t:0},M={id:g.id,asset:"card",role:g.role,ghost:g.ghost||void 0,at:[a(h-w.l),a(b-w.t)],size:[n.W,n.D,n.H]};(v>=0?d[v].nodes:f).push(M)}for(let g of d)g.regions.length||delete g.regions,g.nodes.length||delete g.nodes;let p=(t.links??[]).map((g,h)=>({id:g.id??`link-${h}`,from:g.aOn??g.a,to:g.bOn??g.b,kind:g.kind,label:g.label}));return{isodiag:1,title:e.title,kinds:e.kinds,roles:e.roles,scenes:[{id:"board",title:e.title??"board",regions:u,nodes:f,routes:p}]}}var If={};hi(If,{APPEARS:()=>Zu,BASE_FIELDS:()=>Qc,BINS:()=>cf,BIN_MS:()=>Bn,CARD:()=>_t,DUAL_VIEW_CSS:()=>Rf,IDLES:()=>ef,MAX_ZOOM:()=>Ju,MIN_ZOOM:()=>Wu,P3:()=>gt,SEGMENT_NAME:()=>_a,SEVERITIES:()=>$n,TIMELINE_VERSION:()=>lf,activityOf:()=>rd,attr:()=>Zn,binNext:()=>qa,binStart:()=>yr,buildLayer:()=>ni,cardMotion:()=>tf,clamp:()=>Ns,cls:()=>sf,crumbs:()=>Wr,dualView:()=>Cf,ease:()=>ti,escapeName:()=>Ga,extent:()=>Ba,findGaps:()=>Ua,fitWithOverlay:()=>rf,flatCss:()=>Tf,flatSvg:()=>Qr,formatScope:()=>df,gapKey:()=>wr,gapLabel:()=>xr,h:()=>K,hasSegment:()=>pf,highlights:()=>Zo,isZone:()=>gf,isoVars:()=>of,join:()=>uf,kindOf:()=>qr,legend:()=>Xc,levelOf:()=>rn,markConnectors:()=>eo,md:()=>ms,measureIn:()=>Zr,memorySource:()=>vf,modeFor:()=>sd,morphSvgs:()=>tl,mountTimeline:()=>$f,n:()=>Vc,nameOf:()=>Ur,node:()=>nf,offsetAt:()=>cn,overlayPaint:()=>Xu,parentOf:()=>ff,prefixAt:()=>Ls,prune:()=>Hc,pts:()=>Xo,rangeOf:()=>Qo,readTime:()=>Zc,rectOf:()=>Af,renderPage:()=>af,rewrite:()=>Gc,scope:()=>qc,scopePattern:()=>za,scopeRules:()=>Va,scopeSelector:()=>Yc,searchFor:()=>Jr,severities:()=>mf,stepData:()=>Jc,storedMode:()=>Lf,ticks:()=>Wa,timeScale:()=>Xr,toCSV:()=>Xa,toJSON:()=>Ja,unite:()=>Ka,viewToggle:()=>Nf,viewport:()=>ja,within:()=>En});var Wu=.1,Ju=8;function ja(t,e){let n,s,r=!1,o=0,i=0,a=0,l=0,c=0,d=!1,u=()=>{let P=t.getBoundingClientRect();return{w:Math.max(1,P.width),h:Math.max(1,P.height)}},f=(P=n)=>{let I=u();return Math.min(I.w/P.w,I.h/P.h)},p=P=>{o++;try{P()}finally{o--}};function g(){let P=e.svg();if(!P||!n)return;o||(r=!0);let I=u(),_=f(),O=I.w/_,j=I.h/_;n={x:n.x+(n.w-O)/2,y:n.y+(n.h-j)/2,w:O,h:j},P.setAttribute("viewBox",`${n.x.toFixed(2)} ${n.y.toFixed(2)} ${n.w.toFixed(2)} ${n.h.toFixed(2)}`),i=_,e.onApply(_),a&&Math.abs(_/a-1)>.02&&(cancelAnimationFrame(l),l=requestAnimationFrame(()=>{l=0,e.onRezoom()}))}let h=(P,I)=>{let _=t.getBoundingClientRect(),O=f();return{x:n.x+(P-_.left)/O,y:n.y+(I-_.top)/O}};function b(P,I,_){if(!n)return;let O=f(),j=Math.min(8,Math.max(.1,O*P)),k=t.getBoundingClientRect(),$=I??k.left+k.width/2,x=_??k.top+k.height/2,N=h($,x),F=u();n={x:N.x-($-k.left)/j,y:N.y-(x-k.top)/j,w:F.w/j,h:F.h/j},g()}function v(P=s){if(!P)return;let I=u(),_=24,O=Math.min(8,Math.max(.1,Math.min((I.w-_*2)/P.w,(I.h-_*2)/P.h))),j=P.x+P.w/2,k=P.y+P.h/2,$={x:j-I.w/O/2,y:k-I.h/O/2,w:I.w/O,h:I.h/O};if(n&&Math.abs($.w/n.w-1)<.001&&Math.abs($.h/n.h-1)<.001&&Math.abs($.x-n.x)<$.w*.001&&Math.abs($.y-n.y)<$.h*.001){g();return}n=$,g()}function w(){for(let P=0,I="";P<4;P++){let _=e.itemsBox()??s;if(!_)return;let O=[_.x,_.y,_.w,_.h].map(k=>Math.round(k)).join();if(O===I)break;I=O;let j=Math.max(24,Math.min(_.w,_.h)*.06);if(p(()=>v({x:_.x-j,y:_.y-j,w:_.w+j*2,h:_.h+j*2})),!e.marksShowing()||!a||Math.abs(f()/a-1)<=.02)break;cancelAnimationFrame(l),l=0,e.onRezoom()}r=!1}function M(){if(r||!e.svg()||!n)return;let P=t.getBoundingClientRect();P.width<2||P.height<2||w()}function y(){if(!n)return;let P=f();b(1/P)}function T(){return new Promise(P=>{let I=0,_=i,O=()=>{if(d){P();return}let j=!!(l||c)||i!==_;_=i,I=j?0:I+1,I>=2?P():requestAnimationFrame(O)};requestAnimationFrame(O)})}let S=new ResizeObserver(()=>{if(!(!n||d)){if(r&&i){let P=u(),I=n.x+n.w/2,_=n.y+n.h/2;n={x:I-P.w/i/2,y:_-P.h/i/2,w:P.w/i,h:P.h/i}}r||(cancelAnimationFrame(c),c=requestAnimationFrame(()=>{c=0,d||M()})),p(g)}});return S.observe(t),{get view(){return n},set view(P){n=P},get full(){return s},set full(P){s=P},get moved(){return r},get zoom(){return i},painted(P){a=P},size:u,scale:f,quietly:p,applyView:g,toSvg:h,zoomAt:b,fit:v,fitItems:w,autoFit:M,actual:y,settled:T,dispose(){cancelAnimationFrame(c),cancelAnimationFrame(l),S.disconnect(),d=!0}}}var Gt="http://www.w3.org/2000/svg",_t={half:2.4,h:3.2,t:.25,above:1.4,lift:3.8,fan:.32,gap:.3},gt=(t,e,n)=>[(t-e)*Bt*xt,(t+e)*.5*xt-n*xt],Xo=t=>t.map(([e,n])=>`${e.toFixed(1)},${n.toFixed(1)}`).join(" ");function Xu(t,e){function n(o,i,a){let l=t.k(),c=(u,f,p,g,h="")=>{let b=o.createElementNS(Gt,"g");b.setAttribute("class",`live-badge ${p.cls} ${h}`.trim());let v=8/l,w=o.createElementNS(Gt,"circle");if(w.setAttribute("cx",String(u)),w.setAttribute("cy",String(f)),w.setAttribute("r",String(v)),b.append(w),"g"in p){let y=o.createElementNS(Gt,"text");y.setAttribute("x",String(u)),y.setAttribute("y",String(f)),y.style.fontSize=`${(10/l).toFixed(2)}px`,y.textContent=p.g,b.append(y)}else{let y=o.createElementNS(Gt,"use");y.setAttribute("href",t.iconHref(p.icon));let T=11/l;y.setAttribute("x",String(u-T/2)),y.setAttribute("y",String(f-T/2)),y.setAttribute("width",String(T)),y.setAttribute("height",String(T)),b.append(y)}let M=o.createElementNS(Gt,"title");M.textContent=g,b.append(M),i(b)},d=(u,f)=>{for(let p of t.outlinesFor(u)){if(p.kind!=="poly")continue;let g=o.createElementNS(Gt,"polygon");g.setAttribute("class",f),g.setAttribute("points",p.points.map(([h,b])=>`${h.toFixed(1)},${b.toFixed(1)}`).join(" ")),i(g)}};for(let u of a){let f=t.boxOf(u.at);if(f){if(u.outline&&d(u.at,u.outline),u.badge)c(f.x,f.y,u.badge,u.title);else if(u.hit){let p=o.createElementNS(Gt,"title");p.textContent=u.title;let g=o.createElementNS(Gt,"rect");g.setAttribute("class","live-hit"),g.setAttribute("x",String(f.x)),g.setAttribute("y",String(f.y)),g.setAttribute("width",String(f.w)),g.setAttribute("height",String(f.h)),g.append(p),i(g)}if((u.beside??[]).forEach((p,g)=>c(f.x+18*(g+1)/l,f.y,p.glyph,p.title)),u.dot&&c(f.x,f.y+f.h,u.dot.glyph,u.dot.title),u.tag){let p=o.createElementNS(Gt,"text");p.setAttribute("class",`live-life ${u.tag.cls}`),p.setAttribute("x",String(f.x+f.w)),p.setAttribute("y",String(f.y+f.h)),p.style.fontSize=`${(9/l).toFixed(2)}px`,p.textContent=u.tag.text,i(p)}}}}function s(o,i,a){for(let l of a){let c=o.createElementNS(Gt,"g");c.setAttribute("class",`live-extra${l.cls}`);for(let[M,y]of l.data)c.setAttribute(M,y);let{x:d,y:u,w:f,hgt:p,k:g}=l.rect,h=o.createElementNS(Gt,"rect");h.setAttribute("x",String(d)),h.setAttribute("y",String(u)),h.setAttribute("width",String(f)),h.setAttribute("height",String(p)),h.setAttribute("rx",String(6/g));let b=o.createElementNS(Gt,"text");b.setAttribute("x",String(d+8/g)),b.setAttribute("y",String(u+13/g)),b.style.fontSize=`${(11/g).toFixed(2)}px`,b.textContent=l.line1;let v=o.createElementNS(Gt,"text");v.setAttribute("class","sub"),v.setAttribute("x",String(d+8/g)),v.setAttribute("y",String(u+27/g)),v.style.fontSize=`${(9/g).toFixed(2)}px`,v.textContent=l.line2;let w=o.createElementNS(Gt,"title");w.textContent=l.title,c.append(h,b,v,w),i(c)}}function r(o,i,a){let l=[];for(let c of a){let d=c.over,u=(d.x0+d.x1)/2,f=(d.y0+d.y1)/2,p=0,g={x0:0,y0:0,x1:0,y1:0};for(let B=0;B<6;B++){let W=d.z1+_t.above+p,ee=W+_t.h,ue=[gt(u-_t.half,f+_t.t,W),gt(u+_t.half,f+_t.t,W),gt(u+_t.half,f-_t.t,ee),gt(u-_t.half,f+_t.t,ee)];if(g={x0:Math.min(...ue.map(z=>z[0])),y0:Math.min(...ue.map(z=>z[1])),x1:Math.max(...ue.map(z=>z[0])),y1:Math.max(...ue.map(z=>z[1]))},!gr(g,l))break;p+=_t.lift}l.push(g);let h=d.z1+_t.above+p,b=h+_t.h,v=u-_t.half,w=u+_t.half,M=f+_t.t,y=f-_t.t,T=o.createElementNS(Gt,"g");T.setAttribute("class",`${e}-card${c.cls}`);for(let[B,W]of c.data)T.setAttribute(B,W);let[S,P]=gt(u,f,d.z1+.15),I=`${S.toFixed(1)}px ${P.toFixed(1)}px`;T.style.transformOrigin=I;let _=o.createElementNS(Gt,"g");_.setAttribute("class",`${e}-float`),_.style.transformOrigin=I;let O=[];for(let B=Math.min(c.count-1,3);B>=1;B--){let W=B*_t.fan,ee=y-(B-1)*(2*_t.t+_t.gap)-_t.gap,ue=ee-2*_t.t,z=v+W,X=w+W,Q=h+W,te=b+W,ne=(fe,be)=>{let we=o.createElementNS(Gt,"polygon");we.setAttribute("class",`${e}-face stacked ${fe}`),we.setAttribute("points",Xo(be)),_.append(we)};ne("s-top",[gt(z,ue,te),gt(X,ue,te),gt(X,ee,te),gt(z,ee,te)]),ne("s-side",[gt(X,ue,Q),gt(X,ee,Q),gt(X,ee,te),gt(X,ue,te)]),ne("s-front",[gt(z,ee,Q),gt(X,ee,Q),gt(X,ee,te),gt(z,ee,te)]),O.push({x0:z,x1:X,y0:ue,y1:ee,z0:Q,z1:te})}let j=o.createElementNS(Gt,"polygon");j.setAttribute("class",`${e}-tail`),j.setAttribute("points",Xo([gt(u-.5,M,h+.05),gt(u+.5,M,h+.05),gt(u,f,d.z1+.15)]));let k=(B,W)=>{let ee=o.createElementNS(Gt,"polygon");return ee.setAttribute("class",B),ee.setAttribute("points",Xo(W)),ee},$=k(`${e}-face front`,[gt(v,M,h),gt(w,M,h),gt(w,M,b),gt(v,M,b)]);_.append(j,k(`${e}-face top`,[gt(v,y,b),gt(w,y,b),gt(w,M,b),gt(v,M,b)]),k(`${e}-face side`,[gt(w,y,h),gt(w,M,h),gt(w,M,b),gt(w,y,b)]),$);let[x,N]=gt(v,M,b),F=40,J=o.createElementNS(Gt,"g");J.setAttribute("transform",`matrix(${(Bt*xt/F).toFixed(4)} ${(.5*xt/F).toFixed(4)} 0 ${(xt/F).toFixed(4)} ${x.toFixed(1)} ${N.toFixed(1)})`);let oe=(B,W,ee,ue)=>{let z=o.createElementNS(Gt,"text");return z.setAttribute("class",B),z.setAttribute("x",String(W)),z.setAttribute("y",String(ee)),z.textContent=ue,z};if(J.append(oe(`${e}-mark`,34,98,c.mark),oe(`${e}-who`,70,52,c.who),oe(`${e}-age`,70,82,c.age)),c.line!==void 0&&J.append(oe(`${e}-q`,12,118,c.line)),c.count>1){let B=o.createElementNS(Gt,"circle");B.setAttribute("class",`${e}-count-bg`),B.setAttribute("cx","178"),B.setAttribute("cy","14"),B.setAttribute("r","15"),J.append(B,oe(`${e}-count`,178,14,String(c.count)))}_.append(J);let ve=o.createElementNS(Gt,"title");ve.textContent=c.title,T.append(_,ve),t.onCard?.(T,{cx:u,cy:f,tipZ:d.z1+.15,card:{x0:v,x1:w,y0:y,y1:M,z0:h,z1:b},panes:O.reverse()}),i(T)}}return{paintMarks:n,paintGhosts:s,paintCards:r}}var Zu=[["scale","Scale"],["spin","Spin"],["dissolve","Dissolve"],["inflate","Inflate"]],ef=[["none","None"],["jiggle","Jiggle"],["pirouette","Pirouette"],["glow","Glow"],["breathe","Breathe"]];function pm(t){let e=2166136261;for(let n=0;n<t.length;n++)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return(e>>>0)%1e3/1e3}var Kc=t=>t<0?0:t>1?1:1-Math.pow(1-t,3),Qu=t=>t<0?0:t>1?1:t*t*t,_c=Math.PI*2,zc={appear:{scale:420,spin:760,dissolve:520,inflate:640},disappear:{scale:320,spin:600,dissolve:420,inflate:420},period:{jiggle:4200,pirouette:6400,glow:3200,breathe:4400}},jn={windup:220,turn:980,land:260};function tf(t,e,{prefix:n,key:s,alt:r}){let o={...e},i=1,a=new Map,l=new WeakSet,c=0,d=0,u=new WeakMap,f=new WeakMap;function p(j){c=0;for(let[k,$]of a){if(!k.isConnected){a.delete(k);continue}let x;if($.repeat){if(x=(j+($.offset??0))%$.repeat/$.dur,x>1){l.has(k)&&(t.restore(k),l.delete(k),k.style.removeProperty("transform"));continue}}else if(x=(j-$.start)/$.dur,x>=1){g(k,$);continue}let N=$.frame(Math.max(0,x));t.spin(k,N.theta,N.lift),l.add(k),f.set(k,N),N.scale!==1?k.style.transform=`scale(${N.scale.toFixed(4)})`:k.style.removeProperty("transform"),d++}a.size&&(c=requestAnimationFrame(p))}function g(j,k){a.delete(j),l.has(j)&&(t.restore(j),l.delete(j)),j.style.removeProperty("transform"),k.done?.()}function h(j){let k=a.get(j.card);k&&g(j.card,k),a.set(j.card,j),c||(c=requestAnimationFrame(p))}let b=8,v=0,w=j=>(v++,j.finally(()=>{v--}));function M(j){return!o.enabled||v>=b?Promise.resolve():w(T(j))}function y(j){return!o.enabled||v>=b?Promise.resolve():w(S(j))}function T(j){let k=zc.appear[o.appear]/i;if(o.appear==="spin")return new Promise(N=>h({card:j,start:performance.now(),dur:k,frame:F=>({theta:(1-Kc(F))*_c,lift:0,scale:Math.max(.001,Kc(F))}),done:N}));let $=o.appear==="scale"?[{transform:"scale(0)"},{transform:"scale(1)"}]:o.appear==="dissolve"?[{opacity:0,filter:"blur(4px)"},{opacity:1,filter:"blur(0px)"}]:[{transform:"scale(0)",easing:"cubic-bezier(.3,0,.4,1)"},{transform:"scale(1.16)",offset:.55,easing:"ease-in-out"},{transform:"scale(.95)",offset:.78,easing:"ease-in-out"},{transform:"scale(1)"}];return j.animate($,{duration:k,easing:o.appear==="inflate"?"linear":"ease-out"}).finished.then(()=>{},()=>{})}function S(j){let k=zc.disappear[o.appear]/i;if(o.appear==="spin")return new Promise(N=>h({card:j,start:performance.now(),dur:k,frame:F=>({theta:Qu(F)*_c,lift:0,scale:Math.max(.001,1-Qu(F))}),done:()=>{j.style.transform="scale(0)",N()}}));let $=o.appear==="scale"?[{transform:"scale(1)"},{transform:"scale(0)"}]:o.appear==="dissolve"?[{opacity:1,filter:"blur(0px)"},{opacity:0,filter:"blur(4px)"}]:[{transform:"scale(1)"},{transform:"scale(1.08)",offset:.3},{transform:"scale(0)"}];return j.animate($,{duration:k,easing:"ease-in",fill:"forwards"}).finished.then(()=>{},()=>{})}function P(j){u.get(j)?.cancel(),u.delete(j);let k=a.get(j);k?.repeat&&g(j,k)}function I(j,k){if(P(j),!o.enabled||o.idle==="none"||j.classList.contains("still"))return;let $=j.getAttribute(s)??j.getAttribute(r)??"",x=(k??zc.period[o.idle])/i,N=pm($)*x;if(o.idle==="pirouette"){let B=(jn.windup+jn.turn+jn.land)/i,W=jn.windup/(jn.windup+jn.turn+jn.land),ee=(jn.windup+jn.turn)/(jn.windup+jn.turn+jn.land);h({card:j,start:0,dur:B,repeat:x,offset:N,frame:ue=>{if(ue<W)return{theta:-.35*Math.sin(ue/W*Math.PI/2),lift:0,scale:1};if(ue<ee){let X=(ue-W)/(ee-W);return{theta:-.35*(1-X)+Kc(X)*_c,lift:.9*Math.sin(X*Math.PI),scale:1}}let z=(ue-ee)/(1-ee);return{theta:0,lift:0,scale:1-.04*Math.sin(z*Math.PI)}}});return}let F=j.querySelector(`.${n}-float`)??j,J=t.amber(),oe=o.idle==="jiggle"?[{transform:"scale(1)",offset:0},{transform:"scale(1.07)",offset:.04},{transform:"scale(.97)",offset:.08},{transform:"scale(1.02)",offset:.11},{transform:"scale(1)",offset:.14},{transform:"scale(1)",offset:1}]:o.idle==="glow"?[{filter:`drop-shadow(0 0 0px ${J})`},{filter:`drop-shadow(0 0 7px ${J})`},{filter:`drop-shadow(0 0 0px ${J})`}]:[{transform:"scale(1)"},{transform:"scale(1.035)"},{transform:"scale(1)"}],ve=F.animate(oe,{duration:x,iterations:1/0,easing:o.idle==="jiggle"?"linear":"ease-in-out"});ve.startTime=(document.timeline.currentTime??0)-((document.timeline.currentTime??0)+N)%x,u.set(j,ve)}function _(j,k,$,x,N=!1){N&&(x=!1);for(let[J,oe]of k)!j.has(J)&&!N&&M(oe),!u.has(oe)&&!a.get(oe)?.repeat&&I(oe);if(!o.enabled||!x)return;let F=t.leavingLayer();if(F)for(let[J,oe]of $){let ve=j.get(J);!ve||k.has(J)||(P(ve),ve.setAttribute("class",`${n}-leaving${oe?" expired":""}`),ve.removeAttribute(r),F.append(ve),y(ve).then(()=>ve.remove()))}}function O(j){for(let[k,$]of[...a])g(k,$);c&&cancelAnimationFrame(c),c=0;for(let k of document.getAnimations())k.effect?.target?.closest?.(`.live-layer, .${n}-leaving-layer`)&&k.cancel();t.leavingLayer()?.replaceChildren()}return{get settings(){return{...o}},set(j,k){let $=o;if(o={...o,...j},(!o.enabled||$.idle!==o.idle||$.enabled!==o.enabled)&&(O(void 0),o.enabled))for(let x of k)I(x)},update:_,appear:M,disappear:y,startIdle:I,stopIdle:P,stopAll:O,async preview(j){o.enabled&&await Promise.all(j.map(async k=>{if(P(k),await M(k),o.idle!=="none"&&!k.classList.contains("still")){let $=o.idle==="pirouette"?1800:1400;I(k,$),await new Promise(x=>setTimeout(x,$*2.2/i)),P(k)}else await new Promise($=>setTimeout($,700/i));await y(k);for(let $ of k.getAnimations())$.cancel();k.style.removeProperty("transform"),I(k)}))},get stats(){return{jobs:a.size,raf:!!c,frames:d,effects:v}},setSpeed(j){i=j},lastFrame:j=>f.get(j)}}var Vc=t=>String(Math.round(t*100)/100),nf=(t,e={},...n)=>({name:t,attrs:Object.entries(e).map(([s,r])=>[s,typeof r=="number"?Vc(r):r]),children:n});function Gc(t,e){if(typeof t=="string")return t;let n=t.attrs.map(([s,r])=>{if(s==="id")return[s,e+r];let o=r.replace(/var\(--([a-zA-Z][\w-]*)/g,"var(--iso-$1").replace(/url\(\s*(['"]?)#/g,(i,a)=>`url(${a}#${e}`);return(s==="href"||s==="xlink:href")&&o.startsWith("#")&&!o.startsWith(`#${e}`)&&(o=`#${e}${o.slice(1)}`),[s,o]});return{name:t.name,attrs:n,children:t.children.map(s=>Gc(s,e))}}function Hc(t,e){if(typeof t=="string")return t;if(!e(t))return{...t,children:t.children.map(n=>Hc(n,e)).filter(n=>n!==void 0)}}var sf=t=>(t.attrs.find(e=>e[0]==="class")?.[1]??"").split(/\s+/),Zn=(t,e)=>t.attrs.find(n=>n[0]===e)?.[1];function Ba(t){let e=[],n=[],s=i=>{if(typeof i=="string")return;let a=Zn(i,"transform");if(a&&/matrix/.test(a))return;let l=Zn(i,"points");if(l)for(let c of l.trim().split(/\s+/)){let[d,u]=c.split(",").map(Number);Number.isFinite(d)&&Number.isFinite(u)&&(e.push(d),n.push(u))}if(i.name==="rect"){let c=Number(Zn(i,"x")),d=Number(Zn(i,"y")),u=Number(Zn(i,"width")),f=Number(Zn(i,"height"));[c,d,u,f].every(Number.isFinite)&&(e.push(c,c+u),n.push(d,d+f))}if(i.name==="circle"){let c=Number(Zn(i,"cx")),d=Number(Zn(i,"cy")),u=Number(Zn(i,"r"));[c,d,u].every(Number.isFinite)&&(e.push(c-u,c+u),n.push(d-u,d+u))}i.children.forEach(s)};if(t.forEach(s),!e.length)return;let r=Math.min(...e),o=Math.min(...n);return{x:r,y:o,w:Math.max(...e)-r,h:Math.max(...n)-o}}var Ka=(t,e)=>{if(!e)return t;let n=Math.min(t.x,e.x),s=Math.min(t.y,e.y);return{x:n,y:s,w:Math.max(t.x+t.w,e.x+e.w)-n,h:Math.max(t.y+t.h,e.y+e.h)-s}};function rf(t,e,n){let s=a=>Math.min((e.width-e.pad*2)/a.w,(e.height-e.pad*2)/a.h),r=s(t),o=n(r),i=Ka(t,Ba(o));return r=s(i),o=n(r),i=Ka(t,Ba(o)),r=s(i),{k:r,box:i,live:o}}var of=t=>t.replace(/--([a-zA-Z][\w-]*)/g,"--iso-$1");function mm(t){let e=[],n=0,s=t.replace(/\/\*[\s\S]*?\*\//g,"");for(;n<s.length;){let r=s.indexOf("{",n);if(r<0)break;let o=1,i=r+1;for(;i<s.length&&o;)s[i]==="{"?o++:s[i]==="}"&&o--,i++;e.push([s.slice(n,r).trim(),s.slice(r+1,i-1)]),n=i}return e}function hm(t){let e=[],n=0,s=0;for(let r=0;r<t.length;r++){let o=t[r];o==="("||o==="["?n++:o===")"||o==="]"?n--:o===","&&!n&&(e.push(t.slice(s,r).trim()),s=r+1)}return e.push(t.slice(s).trim()),e.filter(Boolean)}function Yc(t,e,n){let s=/^:root((?:\[[^\]]*\]|:not\([^)]*\))*)(.*)$/.exec(t),r=n.replace(/^\./,"");if(s){let o=s[1],i=s[2].trim();return`${o?`.${r}${o} `:""}${e}${i?" "+i:""}`}if(/^(html|body|\*)\b/.test(t)||/^[a-z]+$/.test(t)&&!/^(svg|g|text|path|polygon|rect|circle|line)$/.test(t))throw new Error(`the canvas's CSS can't style the page: "${t}"`);return`${e} ${t}`}function qc(t,e,n){let s="";for(let[r,o]of mm(t)){if(r.startsWith("@keyframes")){s+=`@keyframes iso-${r.slice(10).trim()}{${o}}
|
|
283
|
+
`;continue}if(r.startsWith("@media")||r.startsWith("@supports")){s+=`${r}{${qc(o,e,n)}}
|
|
284
|
+
`;continue}if(r.startsWith("@"))throw new Error(`the canvas's CSS has an at-rule it can't scope: ${r}`);s+=`${hm(r).map(i=>Yc(i,e,n)).join(",")}{${o.replace(/\banimation:\s*([a-z][\w-]*)/g,"animation:iso-$1")}}
|
|
285
|
+
`}return s}var Uc=["<","script"].join("");function ms(t){return t?Kt(t).replace(/`([^`]+)`/g,"<code>$1</code>").replace(/\*\*([^*]+)\*\*/g,"<b>$1</b>").replace(/(^|[^*])\*([^*\s][^*]*)\*/g,"$1<em>$2</em>").replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(e,n,s)=>/^(https?:|#|\.{0,2}\/)/.test(s.replace(/&/g,"&"))?`<a href="${s}">${n}</a>`:n):""}var Wc=t=>(t??"").split(/\n\s*\n/).filter(Boolean).map(e=>`<p class="sec-sub">${ms(e.trim())}</p>`).join("");function Jc(t){return JSON.stringify({scenes:t.scenes.map(e=>({id:e.id,loop:e.raw.loop??!0,dim:e.raw.dim??"flows",vis:e.steps.vis,steps:e.steps.steps.map(n=>({...n,caption:ms(n.caption)})),assemble:e.assemble,grid:!!e.grid.show,assembly:e.rendered.assembly}))})}function Xc(t,e){let n=t.theme,s=e.raw.legend;if(s===!1)return"";let r=Array.isArray(s)?s:e.steps.kindsUsed.filter(a=>e.routes.some(l=>l.kind===a)||e.steps.steps.some(l=>l.phases.some(c=>c.some(d=>d.kind===a)))),o=a=>`<span><i${a.box?' class="box"':""} style="${a.swatch}"></i>${a.label}</span>`,i=r.map(a=>{let l=Dt(t.catalog,a)?.legend;if(l)return o(l);let c=n.kinds[a];return c?`<span><i style="${`border-color:${us(n,c.color)}${c.dash==="dashed"?";border-top-style:dashed":c.dash==="dotted"?";border-top-style:dotted":""}`}"></i>${ms(c.legend)}</span>`:""});if(!Array.isArray(s)){let a=new Set(e.layout.items.map(l=>l.region?.kind));for(let[l,c]of Object.entries(t.catalog.regions))c.legend?.auto&&a.has(l)&&i.push(o(c.legend))}return i.join("")}function gm(t){let e=t.steps.steps,n=`<div class="tools">
|
|
286
286
|
<button class="pbtn small" type="button" data-a="grid" aria-pressed="${t.grid.show?"true":"false"}" title="Show the floor grid">Grid</button>
|
|
287
287
|
<button class="pbtn small" type="button" data-a="assemble" title="Draw the diagram again, piece by piece">Assemble</button>
|
|
288
288
|
</div>`;if(!e.length)return`<div class="player">${n}</div>`;let s=e[0];return`<div class="player">
|
|
@@ -293,33 +293,33 @@ svg.pre-assemble > g:not(.g-anim){opacity:0}
|
|
|
293
293
|
</div>
|
|
294
294
|
${n}
|
|
295
295
|
<div class="cap" aria-live="polite">
|
|
296
|
-
<div class="cap-h"><span class="num" style="background:${s.color}">${s.num}</span><span class="h">${
|
|
297
|
-
<p class="cap-t">${
|
|
298
|
-
<pre class="cap-c">${
|
|
296
|
+
<div class="cap-h"><span class="num" style="background:${s.color}">${s.num}</span><span class="h">${Kt(s.heading)}</span><span class="cnt">1 / ${e.length}</span></div>
|
|
297
|
+
<p class="cap-t">${ms(s.caption)}</p>
|
|
298
|
+
<pre class="cap-c">${Kt(s.command)}</pre>
|
|
299
299
|
<div class="prog"><i></i></div>
|
|
300
300
|
</div>
|
|
301
301
|
<div class="dots"></div>
|
|
302
|
-
</div>`}function
|
|
303
|
-
<section class="scene" id="scene-${
|
|
304
|
-
<h2>${
|
|
305
|
-
${
|
|
302
|
+
</div>`}function bm(t){let e=t.steps.steps;return e.length?`<details class="steps"><summary>All ${e.length} steps as text</summary><ol>${e.map(n=>`<li value="${n.num}"><b>${Kt(n.heading)}.</b> ${ms(n.caption)}${n.command?`<br><code>${Kt(n.command)}</code>`:""}</li>`).join("")}</ol></details>`:""}function af(t,e={}){let n=t.doc,s=n.title??n.scenes[0]?.title??"Diagram",r=(n.pills??[]).map(i=>`<span class="pill">${ms(i)}</span>`).join(""),o=t.scenes.map(i=>`
|
|
303
|
+
<section class="scene" id="scene-${Kt(i.id)}">
|
|
304
|
+
<h2>${Kt(i.raw.title)}</h2>
|
|
305
|
+
${Wc(i.raw.caption)}
|
|
306
306
|
<div class="figure" tabindex="-1">
|
|
307
307
|
<div class="scroller">${i.grid.show?i.rendered.svg.replace("<svg ",'<svg class="show-grid" '):i.rendered.svg}</div>
|
|
308
|
-
${
|
|
309
|
-
<div class="legend">${
|
|
308
|
+
${gm(i)}
|
|
309
|
+
<div class="legend">${Xc(t,i)}</div>
|
|
310
310
|
</div>
|
|
311
|
-
${
|
|
312
|
-
${i.raw.after?`<div class="after">${
|
|
311
|
+
${bm(i)}
|
|
312
|
+
${i.raw.after?`<div class="after">${Wc(i.raw.after)}</div>`:""}
|
|
313
313
|
</section>`).join(`
|
|
314
314
|
`);return`<!doctype html>
|
|
315
315
|
<html lang="en">
|
|
316
316
|
<head>
|
|
317
317
|
<meta charset="utf-8">
|
|
318
318
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
319
|
-
<title>${
|
|
320
|
-
${n.lede?`<meta name="description" content="${
|
|
319
|
+
<title>${Kt(s)}</title>
|
|
320
|
+
${n.lede?`<meta name="description" content="${Kt(n.lede)}">`:""}
|
|
321
321
|
<style>
|
|
322
|
-
${
|
|
322
|
+
${ra(t.theme)}${Ra(t.catalog)}${Ia}
|
|
323
323
|
</style>
|
|
324
324
|
${e.extraHead??""}
|
|
325
325
|
</head>
|
|
@@ -327,17 +327,17 @@ ${e.extraHead??""}
|
|
|
327
327
|
<div class="wrap">
|
|
328
328
|
<header class="page">
|
|
329
329
|
<div>
|
|
330
|
-
<h1>${
|
|
331
|
-
${n.lede?`<p class="lede">${
|
|
330
|
+
<h1>${Kt(s)}</h1>
|
|
331
|
+
${n.lede?`<p class="lede">${ms(n.lede)}</p>`:""}
|
|
332
332
|
</div>
|
|
333
333
|
<div class="pills">${r}<button class="theme" id="themeBtn" type="button">Theme</button></div>
|
|
334
334
|
</header>
|
|
335
335
|
${o}
|
|
336
|
-
${n.after?
|
|
337
|
-
${n.footer?`<footer>${
|
|
336
|
+
${n.after?Wc(n.after):""}
|
|
337
|
+
${n.footer?`<footer>${ms(n.footer)}</footer>`:""}
|
|
338
338
|
</div>
|
|
339
|
-
${
|
|
340
|
-
${
|
|
339
|
+
${Uc} type="application/json" id="diagram-steps">${Jc(t).replace(/</g,"\\u003c")}<\/script>
|
|
340
|
+
${Uc}>
|
|
341
341
|
(function(){
|
|
342
342
|
var root=document.documentElement, m=/theme=(light|dark)/.exec(location.hash);
|
|
343
343
|
try{var t=localStorage.getItem('diagram-theme'); if(t) root.dataset.theme=t;}catch(e){}
|
|
@@ -349,14 +349,14 @@ ${Ac}>
|
|
|
349
349
|
});
|
|
350
350
|
})();
|
|
351
351
|
<\/script>
|
|
352
|
-
${e.runtime?`${
|
|
352
|
+
${e.runtime?`${Uc}>${e.runtime}<\/script>`:""}
|
|
353
353
|
${e.extraBody??""}
|
|
354
354
|
</body>
|
|
355
355
|
</html>
|
|
356
|
-
`}function z(t,e=null,...n){let s=document.createElement(t);for(let[r,o]of Object.entries(e??{}))if(!(o==null||o===!1))if(r==="class")s.className=String(o);else if(r==="on")for(let[i,a]of Object.entries(o))s.addEventListener(i,a);else s.setAttribute(r,o===!0?"":String(o));for(let r of n)r!=null&&r!==!1&&s.append(r instanceof Node?r:document.createTextNode(String(r)));return s}var Fu=1,Ma="(?:[^/:%\\s]|%[0-9A-F]{2})+",mn=["debug","info","notice","warning","error"],ju=["1m","1h","1d"],On={"1m":6e4,"1h":36e5,"1d":864e5},$a=t=>`^(?:(?:${t.kinds.join("|")}):(?:${Ma})(?:/(?:${t.kinds.join("|")}):(?:${Ma}))*)?$`;function Ea(t){let e=new RegExp($a(t)),n=o=>e.test(o);function s(o){if(!e.test(o))throw new Error(`not a scope path: ${JSON.stringify(o)}`);return o===""?[]:o.split("/").map(i=>{let a=i.indexOf(":");return{kind:i.slice(0,a),name:decodeURIComponent(i.slice(a+1))}})}function r(o){let i="";for(let a of s(o)){if(!t.parents[a.kind].includes(i))return!1;i=a.kind}return!0}return{isScope:n,parseScope:s,wellNested:r}}var Ta=t=>t.replace(/[%/:\s]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase().padStart(2,"0")}`),Bu=t=>t.map(e=>`${e.kind}:${Ta(e.name)}`).join("/"),Ku=(t,e,n)=>(t?`${t}/`:"")+`${e}:${Ta(n)}`,Xt=t=>t===""?0:t.split("/").length;function vs(t,e){return e<=0?"":(t===""?[]:t.split("/")).slice(0,e).join("/")}var _u=t=>vs(t,Xt(t)-1),hn=(t,e)=>e===""||t===e||t.startsWith(`${e}/`),zu=(t,e)=>t!==""&&t.split("/").includes(e),Dr=t=>t===""?"fleet":t.slice(t.lastIndexOf("/")+1).split(":")[0],Fr=t=>t===""?"all hosts":decodeURIComponent(t.slice(t.lastIndexOf("/")+1).split(":").slice(1).join(":"));function jr(t){let e=[{scope:"",label:"all hosts",kind:"fleet"}];for(let n=1;n<=Xt(t);n++){let s=vs(t,n);e.push({scope:s,label:Fr(s),kind:Dr(s)})}return e}var Nc=["kind","source","severity","scope","since","before"];function qp(t){let e=[],n=0;for(;n<t.length;){for(;n<t.length&&/\s/.test(t[n]);)n++;if(n>=t.length)break;let s=!1;t[n]==="-"&&n+1<t.length&&!/\s/.test(t[n+1])&&(s=!0,n++);let r=/^(attr\.[a-z][a-z0-9_]*|[a-z]+):/.exec(t.slice(n)),o;r&&(o=r[1],n+=r[0].length);let i="",a=!1;if(t[n]==='"'){let l=t.indexOf('"',n+1);i=t.slice(n+1,l<0?t.length:l),a=!0,n=l<0?t.length:l+1}else{let l=n;for(;n<t.length&&!/\s/.test(t[n]);)n++;i=t.slice(l,n)}e.push({neg:s,raw:i,quoted:a,field:o})}return e}var Up=/^(\d+)(s|m|h|d|w)$/,Wp={s:1e3,m:6e4,h:36e5,d:864e5,w:7*864e5};function Lc(t,e){let n=Up.exec(t);if(n)return e-Number(n[1])*Wp[n[2]];let s=/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?)?(Z|[+-]\d{2}:?\d{2})?$/.exec(t);if(!s)return;let[,r,o,i,a="0",l="0",c="0",d="0",u]=s;if(u){let p=Date.parse(t.replace(" ","T"));return Number.isNaN(p)?void 0:p}let f=new Date(+r,+o-1,+i,+a,+l,+c,+d.padEnd(3,"0")).getTime();return Number.isNaN(f)?void 0:f}function Jp(t,e,n=Date.now()){let s=[],r=[];for(let o of qp(e??"")){let i=c=>{let d=o.field?`${o.field}:${o.raw}`:o.raw;c&&r.push(`${JSON.stringify(d)}: ${c}; searched as text`),d&&s.push({neg:o.neg,value:d})};if(!o.field){i();continue}if(!(t.includes(o.field)||o.field.startsWith("attr."))){i(`no field ${o.field}`);continue}if(!o.raw){i(`${o.field}: needs a value`);continue}let l=o.field;if(l==="severity"){let c=/^(>=|<=|>|<|=)?(.*)$/.exec(o.raw);if(!mn.includes(c[2])){i(`no severity ${c[2]} (${mn.join(", ")})`);continue}s.push({neg:o.neg,field:l,op:c[1]??"=",value:c[2]})}else if(l==="since"||l==="before"){let c=Lc(o.raw,n);if(c===void 0){i(`can't read the time ${o.raw} (15m, 2h, 3d, 1w, or a date like 2026-11-20 or 2026-11-20T09:30)`);continue}if(o.neg){i(`-${l} isn't allowed (use ${l==="since"?"before":"since"})`);continue}s.push({neg:!1,field:l,value:o.raw,time:c})}else s.push({neg:o.neg,field:l,value:o.raw})}return{terms:s,warnings:r}}var Aa=t=>mn.indexOf(t),Xp={"=":"eq",">=":"ge",">":"gt","<=":"le","<":"lt"};function Qp(t,e){switch(t.field){case void 0:return{field:"text",value:t.value};case"kind":case"source":return t.value.endsWith("*")?{field:t.field,value:t.value.slice(0,-1),prefix:!0}:{field:t.field,value:t.value};case"severity":return{field:"severity",op:Xp[t.op??"="],value:t.value};case"scope":return{field:"scope",value:t.value,from:e.topKinds.some(n=>t.value.startsWith(`${n}:`))?"top":"segments"};case"since":case"before":return;default:return e.links.includes(t.field)?{field:"link",link:t.field,value:t.value}:{field:"attr",key:t.field.slice(5),value:t.value}}}function Zp(t,e){let n=[],s=new Map;for(let r of e.terms){let o=Qp(r,t);if(!o)continue;if(r.neg){n.push({not:!0,any:[o]});continue}if(o.field==="text"||o.field==="severity"){n.push({any:[o]});continue}let i=o.field==="link"?`link.${o.link}`:o.field==="attr"?`attr.${o.key}`:o.field,a=s.get(i);if(a)a.any.push(o);else{let l={any:[o]};s.set(i,l),n.push(l)}}return{all:n}}function em(t,e,n,s){switch(e.field){case"text":{let r=e.value.toLowerCase();if(n.summary.toLowerCase().includes(r)||n.kind.toLowerCase().includes(r)||n.source.toLowerCase().includes(r)||n.scope.toLowerCase().includes(r))return!0;for(let[o,i]of Object.entries(n.attrs))if(typeof i=="string"&&!s.has(`${n.source}.${o}`)&&i.toLowerCase().includes(r))return!0;return!1}case"kind":case"source":{let r=n[e.field];return e.prefix?r.startsWith(e.value):r===e.value}case"severity":{let r=Aa(n.severity),o=Aa(e.value);return e.op==="ge"?r>=o:e.op==="gt"?r>o:e.op==="le"?r<=o:e.op==="lt"?r<o:r===o}case"scope":return e.from==="top"?hn(n.scope,e.value):`/${n.scope}/`.includes(`/${e.value}/`);case"link":return t.linkMatch?.(String(e.link),e.value,n)??n.links[e.link]===e.value;case"attr":{let r=n.attrs[e.key];return r!=null&&String(r).toLowerCase()===e.value.toLowerCase()}}}function Br(t){let e=[...Nc,...t.links],n=(a,l=Date.now())=>Jp(e,a,l),s=a=>Zp(t,a);function r(a,l,c,d){let u=n(a,l);return{where:s(u),...Ko(u,c,d),warnings:u.warnings}}function o(a,l=[]){let c=new Set(l),d=a?.all??[];return d.length?u=>d.every(f=>f.any.some(p=>em(t,p,u,c))!==!!f.not):()=>!0}return{FIELDS:e,parseSearch:n,toAst:s,compileSearch:r,matchAst:o,matcher:(a,l=[])=>o(s(a),l)}}function Ko(t,e,n){for(let s of t.terms)s.field==="since"&&(e=Math.max(e,s.time)),s.field==="before"&&(n=Math.min(n,s.time));return{from:e,to:Math.max(e,n)}}function _o(t,e){let n=e.toLowerCase(),s=[];for(let o of t.terms){if(o.neg||o.field||!o.value)continue;let i=o.value.toLowerCase();for(let a=n.indexOf(i);a>=0;a=n.indexOf(i,a+i.length))s.push([a,a+i.length])}s.sort((o,i)=>o[0]-i[0]);let r=[];for(let o of s){let i=r[r.length-1];i&&o[0]<=i[1]?i[1]=Math.max(i[1],o[1]):r.push([...o])}return r}var Vu=t=>mn.filter(e=>Aa(e)>=Aa(t));var Gu=new Map,Pa=new Map;function tn(t,e){if(!t||t==="UTC")return 0;let n=`${t}|${Math.floor(e/(15*6e4))}`,s=Pa.get(n);if(s!==void 0)return s;let r=Gu.get(t);if(!r){try{r=new Intl.DateTimeFormat("en-US",{timeZone:t,hourCycle:"h23",year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric"})}catch{return 0}Gu.set(t,r)}let o={};for(let l of r.formatToParts(new Date(e)))l.type!=="literal"&&(o[l.type]=Number(l.value));let i=Date.UTC(o.year,o.month-1,o.day,o.hour%24,o.minute,o.second),a=Math.round((i-Math.floor(e/1e3)*1e3)/6e4)*6e4;return Pa.size>5e4&&Pa.clear(),Pa.set(n,a),a}var Hu=t=>{try{return new Intl.DateTimeFormat("en-US",{timeZone:t}),!0}catch{return!1}};function ir(t,e,n){if(e==="1m")return Math.floor(t/6e4)*6e4;let s=tn(n,t);if(e==="1h")return s%36e5===0?Math.floor(t/36e5)*36e5:Math.floor((t+s)/36e5)*36e5-s;let r=Math.floor((t+s)/864e5)*864e5,o=r-tn(n,r-s);return o>t?o=r-864e5-tn(n,r-864e5-s):Oa(o,n)<=t&&(o=Oa(o,n)),o}function Oa(t,e,n="1d"){if(n==="1m")return t+6e4;if(n==="1h")return t+36e5;let s=tn(e,t),r=Math.floor((t+s)/864e5)*864e5+864e5;return r-tn(e,r-s)}var Bs=6e4,Ks=36e5,Cn=864e5;function Ca(t,e,n,s={}){let r=Math.max((s.minFrac??.15)*(n-e),s.minMs??10*Bs),o=t.filter(([l,c])=>c>=e&&l<n).map(([l,c])=>[Math.max(e,l),Math.min(n,Math.max(l,c))]).sort((l,c)=>l[0]-c[0]),i=[];if(!o.length)return i;let a=e;for(let[l,c]of o)l-a>r&&i.push({from:a,to:l}),a=Math.max(a,c);return n-a>r&&i.push({from:a,to:n}),i}function ar(t){if(t>=Cn){let e=Math.floor(t/Cn),n=Math.round((t-e*Cn)/Ks);return n?`${e} d ${n} h`:`${e} d`}if(t>=Ks){let e=Math.floor(t/Ks),n=Math.round((t-e*Ks)/Bs);return n&&e<10?`${e} h ${n} min`:`${e} h`}return`${Math.max(1,Math.round(t/Bs))} min`}var lr=t=>`${t.from}-${t.to}`;function Kr(t,e,n,s=[],r={}){let o=r.cut??24,i=Math.max(1,n),a=Math.max(1,e-t),l=s.filter(M=>M.to>t&&M.from<e).map(M=>({from:Math.max(t,M.from),to:Math.min(e,M.to),w:r.weights?.get(lr(M))??0})).sort((M,x)=>M.from-x.from),c=l.reduce((M,x)=>M+(x.to-x.from)*(1-x.w),0),d=l.reduce((M,x)=>M+(1-x.w)*o,0),u=(i-d)/Math.max(1,a-c);if(!(u>0)||d>i*.6)return Kr(t,e,n,[],r);let f=[[t,0]],p=0,g=t,h=[];for(let M of l){p+=(M.from-g)*u,f.push([M.from,p]);let x=(1-M.w)*o+M.w*u*(M.to-M.from);h.push({from:M.from,to:M.to,x0:p,x1:p+x,weight:M.w}),p+=x,f.push([M.to,p]),g=M.to}f.push([e,p+(e-g)*u]);let b=M=>{if(M<=t)return(M-t)*u;if(M>=e)return f[f.length-1][1]+(M-e)*u;let x=0,T=f.length-1;for(;T-x>1;){let C=x+T>>1;f[C][0]<=M?x=C:T=C}let[y,A]=f[x],[D,K]=f[T];return D===y?A:A+(M-y)/(D-y)*(K-A)},k=M=>h.find(x=>x.weight<1&&M>x.x0&&M<x.x1);return{t0:t,t1:e,width:i,cuts:h,x:b,t:M=>{let x=k(M);if(x)return M-x.x0<x.x1-M?x.from:x.to;if(M<=0)return t+M/u;let T=0,y=f.length-1;if(M>=f[y][1])return e+(M-f[y][1])/u;for(;y-T>1;){let _=T+y>>1;f[_][1]<=M?T=_:y=_}let[A,D]=f[T],[K,C]=f[y];return C===D?A:A+(M-D)/(C-D)*(K-A)},cutAt:k,msPerPx:1/u}}var Rc=[1e3,5e3,15e3,3e4,Bs,5*Bs,15*Bs,30*Bs,Ks,3*Ks,6*Ks,12*Ks,Cn,2*Cn,7*Cn,14*Cn,28*Cn];function Na(t,e,n=80){let s=Rc.find(l=>l/t.msPerPx>=n)??Rc[Rc.length-1],r=[],o=l=>{let c=new Date(l+tn(e,l)),d=String(c.getUTCHours()).padStart(2,"0"),u=String(c.getUTCMinutes()).padStart(2,"0"),f=String(c.getUTCSeconds()).padStart(2,"0"),p=`${c.getUTCDate()} ${["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][c.getUTCMonth()]}`,g=d==="00"&&u==="00"&&f==="00";return s>=Cn||g?{label:p,major:!0}:{label:s<Bs?`${d}:${u}:${f}`:`${d}:${u}`,major:!1}},i=[],a=t.t0;for(let l of t.cuts)l.weight<1&&(i.push([a,l.from]),a=l.to);i.push([a,t.t1]);for(let[l,c]of i){let d=f=>f-tn(e,f-tn(e,f)),u=Math.ceil((l+tn(e,l))/s)*s;s>=7*Cn&&(u=Math.ceil((l+tn(e,l))/Cn)*Cn);for(let f=0,p=d(u);p<c&&f<2e3;f++,u+=s,p=d(u)){if(p<l)continue;let g=t.x(p),h=r[r.length-1];(!h||g-h.x>=n*.6)&&r.push({t:p,x:g,...o(p)})}}return r}var tm=["id","time","t","dur","scope","source","kind","severity","summary"],nm=t=>{if(t==null)return"";let e=typeof t=="string"&&/^[=+\-@\t\r]/.test(t)?`'${t}`:String(t);return/[",\n\r]/.test(e)?`"${e.replace(/"/g,'""')}"`:e},Yu=(t,e)=>e.size?{...t,attrs:Object.fromEntries(Object.entries(t.attrs).filter(([n])=>!e.has(`${t.source}.${n}`)))}:t;function La(t,e=[]){let n=new Set(e);return JSON.stringify(t.map(s=>Yu(s,n)),null,2)+`
|
|
357
|
-
`}function
|
|
356
|
+
`}function K(t,e=null,...n){let s=document.createElement(t);for(let[r,o]of Object.entries(e??{}))if(!(o==null||o===!1))if(r==="class")s.className=String(o);else if(r==="on")for(let[i,a]of Object.entries(o))s.addEventListener(i,a);else s.setAttribute(r,o===!0?"":String(o));for(let r of n)r!=null&&r!==!1&&s.append(r instanceof Node?r:document.createTextNode(String(r)));return s}var lf=1,_a="(?:[^/:%\\s]|%[0-9A-F]{2})+",$n=["debug","info","notice","warning","error"],cf=["1m","1h","1d"],Bn={"1m":6e4,"1h":36e5,"1d":864e5},za=t=>`^(?:(?:${t.kinds.join("|")}):(?:${_a})(?:/(?:${t.kinds.join("|")}):(?:${_a}))*)?$`;function Va(t){let e=new RegExp(za(t)),n=o=>e.test(o);function s(o){if(!e.test(o))throw new Error(`not a scope path: ${JSON.stringify(o)}`);return o===""?[]:o.split("/").map(i=>{let a=i.indexOf(":");return{kind:i.slice(0,a),name:decodeURIComponent(i.slice(a+1))}})}function r(o){let i="";for(let a of s(o)){if(!t.parents[a.kind].includes(i))return!1;i=a.kind}return!0}return{isScope:n,parseScope:s,wellNested:r}}var Ga=t=>t.replace(/[%/:\s]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase().padStart(2,"0")}`),df=t=>t.map(e=>`${e.kind}:${Ga(e.name)}`).join("/"),uf=(t,e,n)=>(t?`${t}/`:"")+`${e}:${Ga(n)}`,rn=t=>t===""?0:t.split("/").length;function Ls(t,e){return e<=0?"":(t===""?[]:t.split("/")).slice(0,e).join("/")}var ff=t=>Ls(t,rn(t)-1),En=(t,e)=>e===""||t===e||t.startsWith(`${e}/`),pf=(t,e)=>t!==""&&t.split("/").includes(e),qr=t=>t===""?"fleet":t.slice(t.lastIndexOf("/")+1).split(":")[0],Ur=t=>t===""?"all hosts":decodeURIComponent(t.slice(t.lastIndexOf("/")+1).split(":").slice(1).join(":"));function Wr(t){let e=[{scope:"",label:"all hosts",kind:"fleet"}];for(let n=1;n<=rn(t);n++){let s=Ls(t,n);e.push({scope:s,label:Ur(s),kind:qr(s)})}return e}var Qc=["kind","source","severity","scope","since","before"];function ym(t){let e=[],n=0;for(;n<t.length;){for(;n<t.length&&/\s/.test(t[n]);)n++;if(n>=t.length)break;let s=!1;t[n]==="-"&&n+1<t.length&&!/\s/.test(t[n+1])&&(s=!0,n++);let r=/^(attr\.[a-z][a-z0-9_]*|[a-z]+):/.exec(t.slice(n)),o;r&&(o=r[1],n+=r[0].length);let i="",a=!1;if(t[n]==='"'){let l=t.indexOf('"',n+1);i=t.slice(n+1,l<0?t.length:l),a=!0,n=l<0?t.length:l+1}else{let l=n;for(;n<t.length&&!/\s/.test(t[n]);)n++;i=t.slice(l,n)}e.push({neg:s,raw:i,quoted:a,field:o})}return e}var xm=/^(\d+)(s|m|h|d|w)$/,wm={s:1e3,m:6e4,h:36e5,d:864e5,w:7*864e5};function Zc(t,e){let n=xm.exec(t);if(n)return e-Number(n[1])*wm[n[2]];let s=/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?)?(Z|[+-]\d{2}:?\d{2})?$/.exec(t);if(!s)return;let[,r,o,i,a="0",l="0",c="0",d="0",u]=s;if(u){let p=Date.parse(t.replace(" ","T"));return Number.isNaN(p)?void 0:p}let f=new Date(+r,+o-1,+i,+a,+l,+c,+d.padEnd(3,"0")).getTime();return Number.isNaN(f)?void 0:f}function vm(t,e,n=Date.now()){let s=[],r=[];for(let o of ym(e??"")){let i=c=>{let d=o.field?`${o.field}:${o.raw}`:o.raw;c&&r.push(`${JSON.stringify(d)}: ${c}; searched as text`),d&&s.push({neg:o.neg,value:d})};if(!o.field){i();continue}if(!(t.includes(o.field)||o.field.startsWith("attr."))){i(`no field ${o.field}`);continue}if(!o.raw){i(`${o.field}: needs a value`);continue}let l=o.field;if(l==="severity"){let c=/^(>=|<=|>|<|=)?(.*)$/.exec(o.raw);if(!$n.includes(c[2])){i(`no severity ${c[2]} (${$n.join(", ")})`);continue}s.push({neg:o.neg,field:l,op:c[1]??"=",value:c[2]})}else if(l==="since"||l==="before"){let c=Zc(o.raw,n);if(c===void 0){i(`can't read the time ${o.raw} (15m, 2h, 3d, 1w, or a date like 2026-11-20 or 2026-11-20T09:30)`);continue}if(o.neg){i(`-${l} isn't allowed (use ${l==="since"?"before":"since"})`);continue}s.push({neg:!1,field:l,value:o.raw,time:c})}else s.push({neg:o.neg,field:l,value:o.raw})}return{terms:s,warnings:r}}var Ha=t=>$n.indexOf(t),km={"=":"eq",">=":"ge",">":"gt","<=":"le","<":"lt"};function Sm(t,e){switch(t.field){case void 0:return{field:"text",value:t.value};case"kind":case"source":return t.value.endsWith("*")?{field:t.field,value:t.value.slice(0,-1),prefix:!0}:{field:t.field,value:t.value};case"severity":return{field:"severity",op:km[t.op??"="],value:t.value};case"scope":return{field:"scope",value:t.value,from:e.topKinds.some(n=>t.value.startsWith(`${n}:`))?"top":"segments"};case"since":case"before":return;default:return e.links.includes(t.field)?{field:"link",link:t.field,value:t.value}:{field:"attr",key:t.field.slice(5),value:t.value}}}function Mm(t,e){let n=[],s=new Map;for(let r of e.terms){let o=Sm(r,t);if(!o)continue;if(r.neg){n.push({not:!0,any:[o]});continue}if(o.field==="text"||o.field==="severity"){n.push({any:[o]});continue}let i=o.field==="link"?`link.${o.link}`:o.field==="attr"?`attr.${o.key}`:o.field,a=s.get(i);if(a)a.any.push(o);else{let l={any:[o]};s.set(i,l),n.push(l)}}return{all:n}}function $m(t,e,n,s){switch(e.field){case"text":{let r=e.value.toLowerCase();if(n.summary.toLowerCase().includes(r)||n.kind.toLowerCase().includes(r)||n.source.toLowerCase().includes(r)||n.scope.toLowerCase().includes(r))return!0;for(let[o,i]of Object.entries(n.attrs))if(typeof i=="string"&&!s.has(`${n.source}.${o}`)&&i.toLowerCase().includes(r))return!0;return!1}case"kind":case"source":{let r=n[e.field];return e.prefix?r.startsWith(e.value):r===e.value}case"severity":{let r=Ha(n.severity),o=Ha(e.value);return e.op==="ge"?r>=o:e.op==="gt"?r>o:e.op==="le"?r<=o:e.op==="lt"?r<o:r===o}case"scope":return e.from==="top"?En(n.scope,e.value):`/${n.scope}/`.includes(`/${e.value}/`);case"link":return t.linkMatch?.(String(e.link),e.value,n)??n.links[e.link]===e.value;case"attr":{let r=n.attrs[e.key];return r!=null&&String(r).toLowerCase()===e.value.toLowerCase()}}}function Jr(t){let e=[...Qc,...t.links],n=(a,l=Date.now())=>vm(e,a,l),s=a=>Mm(t,a);function r(a,l,c,d){let u=n(a,l);return{where:s(u),...Qo(u,c,d),warnings:u.warnings}}function o(a,l=[]){let c=new Set(l),d=a?.all??[];return d.length?u=>d.every(f=>f.any.some(p=>$m(t,p,u,c))!==!!f.not):()=>!0}return{FIELDS:e,parseSearch:n,toAst:s,compileSearch:r,matchAst:o,matcher:(a,l=[])=>o(s(a),l)}}function Qo(t,e,n){for(let s of t.terms)s.field==="since"&&(e=Math.max(e,s.time)),s.field==="before"&&(n=Math.min(n,s.time));return{from:e,to:Math.max(e,n)}}function Zo(t,e){let n=e.toLowerCase(),s=[];for(let o of t.terms){if(o.neg||o.field||!o.value)continue;let i=o.value.toLowerCase();for(let a=n.indexOf(i);a>=0;a=n.indexOf(i,a+i.length))s.push([a,a+i.length])}s.sort((o,i)=>o[0]-i[0]);let r=[];for(let o of s){let i=r[r.length-1];i&&o[0]<=i[1]?i[1]=Math.max(i[1],o[1]):r.push([...o])}return r}var mf=t=>$n.filter(e=>Ha(e)>=Ha(t));var hf=new Map,Ya=new Map;function cn(t,e){if(!t||t==="UTC")return 0;let n=`${t}|${Math.floor(e/(15*6e4))}`,s=Ya.get(n);if(s!==void 0)return s;let r=hf.get(t);if(!r){try{r=new Intl.DateTimeFormat("en-US",{timeZone:t,hourCycle:"h23",year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric"})}catch{return 0}hf.set(t,r)}let o={};for(let l of r.formatToParts(new Date(e)))l.type!=="literal"&&(o[l.type]=Number(l.value));let i=Date.UTC(o.year,o.month-1,o.day,o.hour%24,o.minute,o.second),a=Math.round((i-Math.floor(e/1e3)*1e3)/6e4)*6e4;return Ya.size>5e4&&Ya.clear(),Ya.set(n,a),a}var gf=t=>{try{return new Intl.DateTimeFormat("en-US",{timeZone:t}),!0}catch{return!1}};function yr(t,e,n){if(e==="1m")return Math.floor(t/6e4)*6e4;let s=cn(n,t);if(e==="1h")return s%36e5===0?Math.floor(t/36e5)*36e5:Math.floor((t+s)/36e5)*36e5-s;let r=Math.floor((t+s)/864e5)*864e5,o=r-cn(n,r-s);return o>t?o=r-864e5-cn(n,r-864e5-s):qa(o,n)<=t&&(o=qa(o,n)),o}function qa(t,e,n="1d"){if(n==="1m")return t+6e4;if(n==="1h")return t+36e5;let s=cn(e,t),r=Math.floor((t+s)/864e5)*864e5+864e5;return r-cn(e,r-s)}var Qs=6e4,Zs=36e5,Kn=864e5;function Ua(t,e,n,s={}){let r=Math.max((s.minFrac??.15)*(n-e),s.minMs??10*Qs),o=t.filter(([l,c])=>c>=e&&l<n).map(([l,c])=>[Math.max(e,l),Math.min(n,Math.max(l,c))]).sort((l,c)=>l[0]-c[0]),i=[];if(!o.length)return i;let a=e;for(let[l,c]of o)l-a>r&&i.push({from:a,to:l}),a=Math.max(a,c);return n-a>r&&i.push({from:a,to:n}),i}function xr(t){if(t>=Kn){let e=Math.floor(t/Kn),n=Math.round((t-e*Kn)/Zs);return n?`${e} d ${n} h`:`${e} d`}if(t>=Zs){let e=Math.floor(t/Zs),n=Math.round((t-e*Zs)/Qs);return n&&e<10?`${e} h ${n} min`:`${e} h`}return`${Math.max(1,Math.round(t/Qs))} min`}var wr=t=>`${t.from}-${t.to}`;function Xr(t,e,n,s=[],r={}){let o=r.cut??24,i=Math.max(1,n),a=Math.max(1,e-t),l=s.filter(M=>M.to>t&&M.from<e).map(M=>({from:Math.max(t,M.from),to:Math.min(e,M.to),w:r.weights?.get(wr(M))??0})).sort((M,y)=>M.from-y.from),c=l.reduce((M,y)=>M+(y.to-y.from)*(1-y.w),0),d=l.reduce((M,y)=>M+(1-y.w)*o,0),u=(i-d)/Math.max(1,a-c);if(!(u>0)||d>i*.6)return Xr(t,e,n,[],r);let f=[[t,0]],p=0,g=t,h=[];for(let M of l){p+=(M.from-g)*u,f.push([M.from,p]);let y=(1-M.w)*o+M.w*u*(M.to-M.from);h.push({from:M.from,to:M.to,x0:p,x1:p+y,weight:M.w}),p+=y,f.push([M.to,p]),g=M.to}f.push([e,p+(e-g)*u]);let b=M=>{if(M<=t)return(M-t)*u;if(M>=e)return f[f.length-1][1]+(M-e)*u;let y=0,T=f.length-1;for(;T-y>1;){let O=y+T>>1;f[O][0]<=M?y=O:T=O}let[S,P]=f[y],[I,_]=f[T];return I===S?P:P+(M-S)/(I-S)*(_-P)},v=M=>h.find(y=>y.weight<1&&M>y.x0&&M<y.x1);return{t0:t,t1:e,width:i,cuts:h,x:b,t:M=>{let y=v(M);if(y)return M-y.x0<y.x1-M?y.from:y.to;if(M<=0)return t+M/u;let T=0,S=f.length-1;if(M>=f[S][1])return e+(M-f[S][1])/u;for(;S-T>1;){let j=T+S>>1;f[j][1]<=M?T=j:S=j}let[P,I]=f[T],[_,O]=f[S];return O===I?P:P+(M-I)/(O-I)*(_-P)},cutAt:v,msPerPx:1/u}}var ed=[1e3,5e3,15e3,3e4,Qs,5*Qs,15*Qs,30*Qs,Zs,3*Zs,6*Zs,12*Zs,Kn,2*Kn,7*Kn,14*Kn,28*Kn];function Wa(t,e,n=80){let s=ed.find(l=>l/t.msPerPx>=n)??ed[ed.length-1],r=[],o=l=>{let c=new Date(l+cn(e,l)),d=String(c.getUTCHours()).padStart(2,"0"),u=String(c.getUTCMinutes()).padStart(2,"0"),f=String(c.getUTCSeconds()).padStart(2,"0"),p=`${c.getUTCDate()} ${["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][c.getUTCMonth()]}`,g=d==="00"&&u==="00"&&f==="00";return s>=Kn||g?{label:p,major:!0}:{label:s<Qs?`${d}:${u}:${f}`:`${d}:${u}`,major:!1}},i=[],a=t.t0;for(let l of t.cuts)l.weight<1&&(i.push([a,l.from]),a=l.to);i.push([a,t.t1]);for(let[l,c]of i){let d=f=>f-cn(e,f-cn(e,f)),u=Math.ceil((l+cn(e,l))/s)*s;s>=7*Kn&&(u=Math.ceil((l+cn(e,l))/Kn)*Kn);for(let f=0,p=d(u);p<c&&f<2e3;f++,u+=s,p=d(u)){if(p<l)continue;let g=t.x(p),h=r[r.length-1];(!h||g-h.x>=n*.6)&&r.push({t:p,x:g,...o(p)})}}return r}var Em=["id","time","t","dur","scope","source","kind","severity","summary"],Tm=t=>{if(t==null)return"";let e=typeof t=="string"&&/^[=+\-@\t\r]/.test(t)?`'${t}`:String(t);return/[",\n\r]/.test(e)?`"${e.replace(/"/g,'""')}"`:e},bf=(t,e)=>e.size?{...t,attrs:Object.fromEntries(Object.entries(t.attrs).filter(([n])=>!e.has(`${t.source}.${n}`)))}:t;function Ja(t,e=[]){let n=new Set(e);return JSON.stringify(t.map(s=>bf(s,n)),null,2)+`
|
|
357
|
+
`}function Xa(t,e=[]){let n=new Set(e),s=t.map(l=>bf(l,n)),r=[...new Set(s.flatMap(l=>Object.keys(l.attrs)))].sort(),o=[...new Set(s.flatMap(l=>Object.keys(l.links)))].sort(),i=[...Em,...r.map(l=>`attr.${l}`),...o.map(l=>`link.${l}`)],a=s.map(l=>[l.id,new Date(l.t).toISOString(),l.t,l.dur,l.scope,l.source,l.kind,l.severity,l.summary,...r.map(c=>l.attrs[c]),...o.map(c=>l.links[c])].map(Tm).join(","));return[i.join(","),...a].join(`\r
|
|
358
358
|
`)+`\r
|
|
359
|
-
`}var sm=864e5,Vn=36e5,Ia=(t,e)=>t.t-e.t||(t.id<e.id?-1:t.id>e.id?1:0);function ss(t,e){let n=0,s=t.length;for(;n<s;){let r=n+s>>1;t[r].t<e?n=r+1:s=r}return n}var Wu=(t,e)=>{t.min=Math.min(t.min,e.min),t.max=Math.max(t.max,e.max),t.sum+=e.sum,t.count+=e.count};function qu(t,e,n){let s=[];for(let r of t){let o=ir(r.t,e,n),i=s[s.length-1];i&&i.t===o?Wu(i,r):s.push({t:o,min:r.min,max:r.max,sum:r.sum,count:r.count})}return s}function Ic(t,e,n,s){for(let i=ss(t,e.t);i<t.length&&t[i].t===e.t;i++)if(n(t[i])){t[i]=e;return}let r=t[t.length-1];if(!r||s(r,e)<=0){t.push(e);return}let o=ss(t,e.t);for(;o<t.length&&s(t[o],e)<0;)o++;t.splice(o,0,e)}function Uu(t,e,n){for(let s=ss(t,e);s<t.length&&t[s].t===e;s++)if(n(t[s])){t.splice(s,1);return}}function Ju(t,e,n={}){let s=t.catalog,{isScope:r}=Ea(e),{parseSearch:o,matchAst:i,toAst:a}=Br(e),l=I=>Object.fromEntries(e.flags.filter(re=>I?.[re]).map(re=>[re,!0])),c=n.now??s.now,d=(s.names??[]).flatMap(I=>(I.aliases??[]).map(re=>[re,I.scope])).sort((I,re)=>re[0].length-I[0].length),u=new Map,f=I=>{if(!d.length)return I;let re=u.get(I);if(re===void 0){let $e=d.find(([Pe])=>hn(I,Pe));re=$e?$e[1]+I.slice($e[0].length):I,u.set(I,re)}return re},p=new Map((s.names??[]).map(I=>[I.scope,I])),g=I=>d.length?{...I,scope:f(I.scope)}:I,h=I=>`${I.source}\0${I.id}`,b=t.events.map(g).sort(Ia),k=new Map;for(let I of b)k.set(h(I),I);let v=b.filter(I=>I.dur!==void 0&&!I.open),M=v.reduce((I,re)=>Math.max(I,re.dur),0),x=new Map;for(let I of b)I.open&&x.set(h(I),I);let T=new Map,y=new Set,A=I=>{for(let re=Xt(I);re>=1;re--){let $e=vs(I,re);if(y.has($e))break;y.add($e)}},D=new Map;for(let I of s.sources)for(let re of I.series)D.set(re.name,re.type);let K=s.sources.flatMap(I=>(I.sensitive??[]).map(re=>`${I.name}.${re}`)),C=new Map;for(let I of s.sources)C.set(I.name,{events:I.defaultRetention.events,rollups:{...I.defaultRetention.rollups},setBy:"default"});for(let I of s.retention)C.set(I.source,{events:I.events,rollups:{...I.rollups},setBy:I.setBy});let _=new Map;for(let I of s.sources)for(let re of I.series)_.set(re.name,I.name);function S(I){let re=f(I.scope),$e=`${I.series}\0${re}`,Pe=T.get($e);Pe||(Pe={series:I.series,scope:re,fine:[],cache:new Map},T.set($e,Pe),A(re));let be="value"in I?{t:I.t,min:I.value,max:I.value,sum:I.value,count:1}:{t:I.t,min:I.min,max:I.max,sum:I.sum,count:I.count};Ic(Pe.fine,be,ce=>ce.t===be.t,(ce,ze)=>ce.t-ze.t),Pe.cache.clear()}for(let I of b)A(I.scope);for(let I of t.metrics)S(I);let $=new Map,w=new Set,N=(I,re)=>{w.add(I.source);let $e=$.get(I.scope);$e||$.set(I.scope,$e=new Map);let Pe=$e.get(I.source);Pe||$e.set(I.source,Pe=new Map);let be=Math.floor(I.t/Vn)*Vn,ce=Pe.get(be);if(ce||Pe.set(be,ce={t:be,count:0,severity:{},kinds:{},first:1/0,last:-1/0}),ce.count+=re,re>0)ce.first=Math.min(ce.first,I.t),ce.last=Math.max(ce.last,I.t);else if(I.t===ce.first||I.t===ce.last){ce.first=1/0,ce.last=-1/0;for(let ze=ss(b,be);ze<b.length&&b[ze].t<be+Vn;ze++){let Oe=b[ze];Oe.scope===I.scope&&Oe.source===I.source&&(ce.first=Math.min(ce.first,Oe.t),ce.last=Math.max(ce.last,Oe.t))}}ce.severity[I.severity]=(ce.severity[I.severity]??0)+re,ce.kinds[I.kind]=(ce.kinds[I.kind]??0)+re,ce.severity[I.severity]===0&&delete ce.severity[I.severity],ce.kinds[I.kind]===0&&delete ce.kinds[I.kind],ce.count||Pe.delete(be)};for(let I of b)N(I,1);let F=(I,re,$e)=>{let Pe=`${re}|${$e??""}`,be=I.cache.get(Pe);return be||(be=re==="1d"?qu(F(I,"1h",$e),"1d",$e):qu(I.fine,re,$e),I.cache.set(Pe,be)),be},J=I=>I===null?-1/0:c-I*sm,ae=I=>J(C.get(I)?.events??null),we=(I,re)=>{let $e=C.get(I);return J($e?re?$e.rollups[re]:$e.events:null)};function j(I){let re=[];for(let $e of new Set(I)){let Pe=C.get($e);if(!Pe)continue;let be=b.find(Ee=>Ee.source===$e&&Ee.t>=ae($e))?.t,ce=Ee=>{let Be=1/0;for(let it of T.values())if(_.get(it.series)===$e){let We=(Ee?F(it,Ee):it.fine).find(Ne=>Ne.t>=we($e,Ee));We&&We.t<Be&&(Be=We.t)}return Be===1/0?void 0:Be},ze=[be,ce()].filter(Ee=>Ee!==void 0),Oe={};for(let Ee of["1m","1h","1d"]){let Be=ce(Ee)??(be!==void 0&&be>=we($e,Ee)?be:void 0);Be!==void 0&&(Oe[Ee]=Math.max(Be,we($e,Ee)))}re.push({source:$e,events:Pe.events,rollups:{...Pe.rollups},setBy:Pe.setBy,keptFrom:{...ze.length?{events:Math.min(...ze)}:{},rollups:Oe}})}return re}function U(I){let re=I.where,$e={from:I.from,to:I.to},Pe=[];if(!re&&I.q){let We=o(I.q,c);re=a(We),$e=Ko(We,I.from,I.to),Pe=We.warnings}let be=i(re,K),ce=I.filters??{},ze=ce.source?.length?new Set(ce.source):void 0,Oe=ce.kind?.length?new Set(ce.kind):void 0,Ee=ce.severity?.length?new Set(ce.severity):void 0,Be=ce.scope?.length?ce.scope:void 0;return{test:We=>hn(We.scope,I.scope)&&(!ze||ze.has(We.source))&&(!Oe||Oe.has(We.kind))&&(!Ee||Ee.has(We.severity))&&(!Be||Be.some(Ne=>hn(We.scope,Ne)))&&We.t>=ae(We.source)&&be(We),range:$e,warnings:Pe}}function ee(I){let re=Xt(I.scope),$e=re+I.depth,Pe=new Map,be=Ee=>{let Be=Pe.get(Ee);return Be===void 0&&!Pe.has(Ee)&&(Be=hn(Ee,I.scope)?Xt(Ee)>=$e?vs(Ee,$e):Ee:void 0,Pe.set(Ee,Be)),Be},ce=Ee=>{let Be=0,it=Xt(Ee)+1;for(let We of y)Xt(We)===it&&hn(We,Ee)&&Be++;return Be},ze=new Map,Oe=Ee=>{let Be=ze.get(Ee);if(!Be){let it=Xt(Ee)-re,We=p.get(Ee);Be={scope:Ee,label:We?.label??Fr(Ee),kind:Dr(Ee),...l(We),depth:it,...it<I.depth?{own:!0}:{},children:ce(Ee),count:0},ze.set(Ee,Be)}return Be};for(let Ee of y)Xt(Ee)===$e&&hn(Ee,I.scope)&&Oe(Ee);return $e===0&&Oe(""),{at:be,add:Oe,rows:ze}}let fe=I=>[...I.values()].sort((re,$e)=>re.scope===$e.scope?0:re.scope<$e.scope?-1:1);function B(I,re){let $e=[];for(let Pe=ss(v,I-M);Pe<v.length&&v[Pe].t<I;Pe++)v[Pe].t+v[Pe].dur>I&&$e.push(v[Pe]);for(let Pe of x.values())Pe.t<I&&c>I&&$e.push(Pe);for(let Pe=ss(b,I);Pe<b.length&&b[Pe].t<re;Pe++)$e.push(b[Pe]);return $e}function X(I,re,$e,Pe){let be=I.series?new Set(I.series):void 0,ce=new Map;for(let Oe of T.values()){if(be&&!be.has(Oe.series))continue;let Ee=re(Oe.scope);if(Ee===void 0)continue;let Be=_.get(Oe.series)??"",it=we(Be,I.bin),We=I.bin?F(Oe,I.bin,I.tz):Oe.fine;for(let Ne=ss(We,I.bin?ir($e,I.bin,I.tz):$e);Ne<We.length&&We[Ne].t<Pe;Ne++){let gt=We[Ne];if(gt.t<it)continue;let Ze=`${Oe.series}\0${Ee}\0${gt.t}`,ft=ce.get(Ze);ft?Wu(ft,gt):ce.set(Ze,{series:Oe.series,scope:Ee,t:gt.t,bin:I.bin??"1m",min:gt.min,max:gt.max,sum:gt.sum,count:gt.count})}}let ze=[...ce.values()].sort((Oe,Ee)=>Oe.t-Ee.t||(Oe.series<Ee.series?-1:1)||(Oe.scope<Ee.scope?-1:1));return I.bin?ze:ze.map(Oe=>({series:Oe.series,scope:Oe.scope,t:Oe.t,value:Oe.count===1||D.get(Oe.series)!=="gauge"?Oe.sum:Oe.sum/Oe.count}))}let Q=I=>`${I.t}:${I.id}`,te=(I,re)=>{let $e=re.indexOf(":"),Pe=Number(re.slice(0,$e)),be=re.slice($e+1);return I.t>Pe||I.t===Pe&&I.id>be};function ne(I){if(I.bin!=="1h"&&I.bin!=="1d"||(I.where?.all.length??0)||I.q||I.filters?.kind?.length||I.filters?.severity?.length||I.filters?.scope?.length||tn(I.tz,I.from)%Vn||tn(I.tz,I.to)%Vn)return;let re=I.filters?.source?.length?new Set(I.filters.source):void 0,$e=E=>Math.max(I.from,ae(E)),{at:Pe,add:be,rows:ce}=ee(I),ze=new Set,Oe=new Map,Ee=0,Be=(E,Y)=>{let q=ir(Y,I.bin,I.tz),de=`${E}\0${q}`,m=Oe.get(de);return m||(m={scope:E,t:q,bin:I.bin,count:0,severity:{},kinds:{}},Oe.set(de,m)),m},it=(E,Y,q)=>{let de=be(E);de.count+=q,Ee+=q,(de.first===void 0||Y<de.first)&&(de.first=Y),(de.last===void 0||Y>de.last)&&(de.last=Y)},We=Math.floor(I.to/Vn)*Vn;for(let[E,Y]of $){let q=Pe(E);if(q!==void 0)for(let[de,m]of Y){if(re&&!re.has(de))continue;let O=Math.ceil($e(de)/Vn)*Vn;for(let[L,G]of m){if(L<O||L>=We)continue;it(q,G.first,G.count),G.last>(ce.get(q).last??-1/0)&&(ce.get(q).last=G.last),ze.add(de);let Z=Be(q,L);Z.count+=G.count;for(let[Se,ue]of Object.entries(G.severity))Z.severity[Se]=(Z.severity[Se]??0)+ue;for(let[Se,ue]of Object.entries(G.kinds))Z.kinds[Se]=(Z.kinds[Se]??0)+ue}}}let Ne=E=>hn(E.scope,I.scope)&&(!re||re.has(E.source))&&E.t>=ae(E.source)&&Pe(E.scope)!==void 0,gt=E=>{let Y=Pe(E.scope);it(Y,E.t,1),ze.add(E.source);let q=Be(Y,E.t);q.count++,q.severity[E.severity]=(q.severity[E.severity]??0)+1,q.kinds[E.kind]=(q.kinds[E.kind]??0)+1};for(let E of w){if(re&&!re.has(E))continue;let Y=$e(E),q=Math.ceil(Y/Vn)*Vn,de=q>=We?[[Y,I.to]]:[[Y,q],[We,I.to]];for(let[m,O]of de)for(let L=ss(b,m);L<b.length&&b[L].t<O;L++){let G=b[L];G.source===E&&Ne(G)&>(G)}}let Ze=On[I.bin],ft=[];for(let E=ss(v,I.from-M);E<v.length&&v[E].t<I.from;E++){let Y=v[E];Y.t+Y.dur>I.from&&Ne(Y)&&(it(Pe(Y.scope),Y.t,1),ze.add(Y.source),Y.dur>=Ze&&ft.length<5e3&&ft.push(Y))}for(let E of x.values())E.t<I.from&&c>I.from&&Ne(E)&&(it(Pe(E.scope),E.t,1),ze.add(E.source),ft.length<5e3&&ft.push(E));for(let E=ss(v,I.from);E<v.length&&v[E].t<I.to&&ft.length<5e3;E++)v[E].dur>=Ze&&Ne(v[E])&&ft.push(v[E]);for(let E of x.values())E.t>=I.from&&E.t<I.to&&ft.length<5e3&&Ne(E)&&ft.push(E);let ot=X(I,Pe,I.from,I.to);for(let E of ot){let Y=_.get(E.series);Y&&ze.add(Y)}let at=[...Oe.values()].sort((E,Y)=>E.t-Y.t||(E.scope<Y.scope?-1:1));return{timeline:1,type:"result",rows:fe(ce),bins:at,spans:ft,metrics:ot,total:Ee,retention:j(ze)}}async function me(I){if(!r(I.scope))throw new Error(`not a scope path: ${JSON.stringify(I.scope)}`);let re=ne(I);if(re)return re;let{test:$e,range:Pe,warnings:be}=U(I),{at:ce,add:ze,rows:Oe}=ee(I),Ee=new Set,Be=[];for(let ot of B(Pe.from,Pe.to)){if(!$e(ot))continue;let at=ce(ot.scope);if(at===void 0)continue;let E=ze(at);E.count++,(E.first===void 0||ot.t<E.first)&&(E.first=ot.t),(E.last===void 0||ot.t>E.last)&&(E.last=ot.t),Ee.add(ot.source),Be.push(ot)}Be.sort(Ia);let it=X(I,ce,Pe.from,Pe.to);for(let ot of it){let at=_.get(ot.series);at&&Ee.add(at)}let We={timeline:1,type:"result",total:Be.length,...be.length?{warnings:be}:{}};if(I.bin){let ot=On[I.bin],at=new Map,E=[];for(let q of Be){if((q.open||q.dur!==void 0&&q.dur>=ot)&&E.length<5e3&&E.push(q),q.t<Pe.from)continue;let de=ce(q.scope),m=ir(q.t,I.bin,I.tz),O=`${de}\0${m}`,L=at.get(O);L||(L={scope:de,t:m,bin:I.bin,count:0,severity:{},kinds:{}},at.set(O,L)),L.count++,L.severity[q.severity]=(L.severity[q.severity]??0)+1,L.kinds[q.kind]=(L.kinds[q.kind]??0)+1}let Y=[...at.values()].sort((q,de)=>q.t-de.t||(q.scope<de.scope?-1:1));return{...We,rows:fe(Oe),bins:Y,spans:E,metrics:it,retention:j(Ee)}}let Ne=Math.min(1e4,Math.max(1,I.limit??2e3)),gt=I.cursor?Be.findIndex(ot=>te(ot,I.cursor)):0,Ze=gt<0?[]:Be.slice(gt,gt+Ne),ft=gt>=0&>+Ne<Be.length;return{...We,rows:fe(Oe),events:Ze,metrics:it,retention:j(Ee),...ft?{next:Q(Ze[Ze.length-1])}:{}}}let ye=new Set,xe=I=>mn.includes(I),Re=0;function Ue(I){let re=h(I),$e=k.get(re);$e&&(Uu(b,$e.t,Pe=>Pe===$e),N($e,-1),$e.dur!==void 0&&!$e.open&&Uu(v,$e.t,Pe=>Pe===$e),x.delete(re)),k.set(re,I),N(I,1),Ic(b,I,()=>!1,Ia),I.open?x.set(re,I):I.dur!==void 0&&(Ic(v,I,()=>!1,Ia),M=Math.max(M,I.dur)),A(I.scope)}return{async catalog(){return{...s,now:c,retention:j(s.sources.map(I=>I.name))}},query:me,subscribe(I,re){let $e={q:I,on:re};return ye.add($e),()=>{ye.delete($e)}},...n.stateAt?{stateAt:(I,re)=>n.stateAt(I,re)}:{},append(I,re=[],$e){$e!==void 0&&(c=Math.max(c,$e));let Pe=new Set(y),be=I.map(g);for(let ce of be){if(!xe(ce.severity))throw new Error(`not a severity: ${ce.severity}`);Ue(ce)}for(let ce of re)S(ce);Re++;for(let ce of ye){let{test:ze}=U(ce.q),{at:Oe}=ee(ce.q),Ee=be.filter(Ze=>ze(Ze)&&Oe(Ze.scope)!==void 0),Be=ce.q.series?new Set(ce.q.series):void 0,it=re.filter(Ze=>hn(f(Ze.scope),ce.q.scope)&&(!Be||Be.has(Ze.series))).map(Ze=>({...Ze,scope:Oe(f(Ze.scope))})),We=[...y].filter(Ze=>!Pe.has(Ze)),Ne=Xt(ce.q.scope)+ce.q.depth,gt=We.filter(Ze=>Xt(Ze)===Ne&&hn(Ze,ce.q.scope)).map(Ze=>({scope:Ze,label:p.get(Ze)?.label??Fr(Ze),kind:Dr(Ze),depth:ce.q.depth,children:0,count:0}));ce.on({timeline:1,type:"batch",events:Ee,metrics:it,...gt.length?{rows:gt}:{},now:c,resume:String(Re)})}},setRetention(I,re){C.set(I,{events:re.events,rollups:{...re.rollups},setBy:"user"})},get now(){return c},get size(){let I=0;for(let re of T.values())I+=re.fine.length;return{events:b.length,samples:I}}}}var Xu="http://www.w3.org/2000/svg",cr=22,Da=38,rs=26,rm=210,om=24,zo=6e4,dr=36e5,kn=864e5,Qu={"15m":15*zo,"1h":dr,"1d":kn,"1w":7*kn},Zu=t=>mn.indexOf(t),im={debug:"dot",info:"circle",notice:"square",warning:"triangle",error:"diamond"},Ct=(t,e,n)=>{let s=document.createElementNS(Xu,t);for(let[r,o]of Object.entries(e))o!==void 0&&s.setAttribute(r,String(o));if(n){let r=document.createElementNS(Xu,"title");r.textContent=n,s.append(r)}return s},nn=(t,e)=>{try{return new Intl.DateTimeFormat(void 0,{timeZone:e,dateStyle:"medium",timeStyle:"medium"}).format(t)}catch{return new Date(t).toISOString()}},Dc=t=>t<1e3?`${Math.round(t)} ms`:t<zo?`${(t/1e3).toFixed(1)} s`:ar(t),am=(t,e)=>e==="bytes"?t>=1e9?`${(t/1e9).toFixed(1)} GB`:t>=1e6?`${(t/1e6).toFixed(1)} MB`:t>=1e3?`${(t/1e3).toFixed(1)} kB`:`${Math.round(t)} B`:`${Math.round(t*10)/10}${e==="count"?"":` ${e}`}`;function Fc(t,e){if(t<=3*dr)return{kind:"single"};for(let n of["1m","1h","1d"])if(t/On[n]<=e/2)return{kind:"binned",bin:n};return{kind:"binned",bin:"1d"}}function jc(t,e,n){let s=[];for(let i of t.events??[])s.push([i.t,i.t]),i.dur!==void 0&&!i.open&&s.push([i.t+i.dur,i.t+i.dur]);for(let i of t.spans??[])s.push([i.t,i.t]),i.dur!==void 0&&!i.open&&s.push([i.t+i.dur,i.t+i.dur]);let r=e.kind==="binned"?On[e.bin]:zo;for(let i of t.bins??[])i.count&&s.push([i.t,i.t+On[i.bin]]);let o=new Map;for(let i of t.metrics){let a="value"in i?i.value:i.sum,l=`${i.series}|${i.scope}`,c=(n?.get(i.series)??"counter")==="counter"?a!==0:o.get(l)!==a;o.set(l,a),c&&s.push([i.t,i.t+r])}return s}function ef(t,e){let n=e.tz??Intl.DateTimeFormat().resolvedOptions().timeZone,s=typeof matchMedia=="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches,r=e.motion??!s;t.classList.add(...e.rootClass??[],"tlx");let{parseSearch:o,compileSearch:i}=Br(e.catalog),a=(H="system")=>{t.style.colorScheme=H==="system"?"light dark":H,H==="system"?delete t.dataset.theme:t.dataset.theme=H};a(e.theme),t.setAttribute("role","region"),t.setAttribute("aria-label","Timeline");let l,c="",d=1,u="",f={},p=!1,g=e.collapseGaps??!0,h={t0:0,t1:kn},b,k="",v={from:0,to:0,mode:{kind:"single"},key:""},M,x,T,y,A=!0,D=0,K=0,C=!1,_,S=[],$=[],w=-1,N=new Set,F=new Map,J=[],ae=Kr(0,kn,800),we=new Map,j=[],U=z("nav",{class:"tlx-crumbs","aria-label":"Scope"}),ee=z("div",{class:"segmented tlx-quick",role:"group","aria-label":"Range"});for(let H of["15m","1h","1d","1w","run"]){let he=z("button",{type:"button",class:"seg","data-v":H,title:H==="run"?"The latest run":`The last ${H}`},H==="run"?"this run":H);he.addEventListener("click",()=>Mn(H)),ee.append(he)}let fe=z("button",{type:"button",class:"btn sm tlx-live","aria-pressed":"false",title:"Follow what happens now"},"Live"),B=z("button",{type:"button",class:"btn sm quiet tlx-now",hidden:!0,title:"Back to the live edge"},"Back to now"),X=z("button",{type:"button",class:"btn sm quiet tlx-fit",title:"Everything in this scope"},"Fit"),Q=z("input",{type:"checkbox",class:"tlx-gaps"});Q.checked=g;let te=!0,ne=z("input",{type:"checkbox",class:"tlx-quiet"});ne.checked=te;let me=z("input",{type:"search",class:"input tlx-q",placeholder:"Search: words, kind:\u2026, source:\u2026, severity:>=warning, -kind:\u2026","aria-label":"Search the timeline",spellcheck:"false"}),ye=z("span",{class:"tlx-hits",role:"status","aria-live":"polite"}),xe=z("button",{type:"button",class:"btn sm quiet tlx-prev",title:"Previous hit (\u21E7N)","aria-label":"Previous hit"},"\u2039"),Re=z("button",{type:"button",class:"btn sm quiet tlx-next",title:"Next hit (N)","aria-label":"Next hit"},"\u203A"),Ue=z("div",{class:"tlx-facets",role:"group","aria-label":"Sources"}),I=z("select",{class:"input tlx-sev","aria-label":"Severity"},z("option",{value:""},"every severity"),...mn.slice(1).map(H=>z("option",{value:H},`${H} and above`))),re=z("select",{class:"input tlx-views","aria-label":"Saved views",hidden:!e.views},z("option",{value:""},"Saved views\u2026")),$e=z("button",{type:"button",class:"btn sm quiet tlx-save",hidden:!e.saveView,title:"Save this view"},"Save view"),Pe=z("div",{class:"tlx-warn",role:"status",hidden:!0}),be=z("div",{class:"tlx-status",role:"status"}),ce=z("span",{class:"tlx-canvas-note"}),ze=z("div",{class:"tlx-labels"}),Oe=z("div",{class:"tlx-lanes",tabindex:"0",role:"application","aria-label":"Timeline lanes: drag to pan, wheel to zoom, drag the axis to choose a range, click it to move the playhead. Keys: \u2190 \u2192 pan, + \u2212 zoom, N next hit"}),Ee=Ct("svg",{class:"tlx-svg"});Oe.append(Ee);let Be=z("div",{class:"tlx-scroll"},z("div",{class:"tlx-grid"},ze,Oe)),it=z("section",{class:"tlx-table",hidden:!0,"aria-label":"The events in the chosen range"}),We=z("aside",{class:"tlx-detail",hidden:!0,"aria-label":"The event"});t.replaceChildren(z("div",{class:"tlx-bar"},U,z("span",{class:"spacer"}),ee,fe,B,X,z("label",{class:"tlx-gaps-label",title:"Draw long empty stretches as narrow breaks"},Q,"Collapse gaps"),z("label",{class:"tlx-gaps-label",title:"Hide the rows with nothing in this range"},ne,"Hide quiet rows")),z("div",{class:"tlx-bar"},me,ye,xe,Re,I,re,$e),Ue,Pe,z("div",{class:"tlx-body"},Be,We),z("div",{class:"tlx-foot"},be,z("span",{class:"spacer"}),ce),it);let Ne=()=>Math.max(200,Oe.clientWidth||800),gt=()=>{let H=(Fe,st)=>(Fe.own?-1:0)-(st.own?-1:0)||Fe.scope.localeCompare(st.scope,void 0,{numeric:!0}),ke=(b?.rows??[]).filter(Fe=>!te||Fe.count>0||Fe.own||(b?.rows.length??0)<=1).sort(H).map(Fe=>({kind:"row",row:Fe})),Ae=new Set(b?.metrics.map(Fe=>Fe.series)??[]);for(let Fe of[...Ae].sort()){let st=we.get(Fe);ke.push({kind:"metric",series:Fe,unit:st?.unit??"count",type:st?.type??"counter",title:st?.title??Fe})}return ke},Ze=(H,he)=>l?.names?.find(ke=>ke.scope===H)?.label??he,ft=H=>H.kind==="metric"?Da:cr,ot=()=>Fc(h.t1-h.t0,Ne()),at=()=>l?.now??Date.now();function E(){return{timeline:1,type:"view",name:"",scope:c,depth:d,range:{from:Math.round(h.t0),to:Math.round(h.t1)},...u?{q:u}:{},...Object.keys(f).length?{filters:f}:{},...p?{live:p}:{},...g?{}:{collapseGaps:!1},...te?{}:{quietRows:!0}}}function Y(H){H.scope!==void 0&&(c=H.scope),H.depth!==void 0&&(d=H.depth),u=H.q??"",me.value=u,f=H.filters??{},I.value=f.severity?.length?f.severity[0]:"",g=H.collapseGaps??e.collapseGaps??!0,Q.checked=g,te=!H.quietRows,ne.checked=te,N.clear(),F.clear();let he=H.range;he&&"last"in he?Mn(he.last,!1):he&&(h={t0:he.from,t1:he.to}),kt(!!H.live,!1)}let q=()=>{let H=E();if(e.onViewChange?.(H),!!e.urlState)try{history.replaceState(null,"",`#timeline=${encodeURIComponent(JSON.stringify(H))}`)}catch{}},de=()=>{if(!e.urlState)return;let H=/#timeline=(.+)$/.exec(location.hash);if(H)try{return JSON.parse(decodeURIComponent(H[1]))}catch{return}};function m(H,he,ke,Ae={}){let Fe=i(u,at(),H,he);S=Fe.warnings;let st=u?[]:f.source?[...we].filter(([,bt])=>f.source.includes(bt.source)).map(([bt])=>bt):void 0;return{timeline:1,type:"query",scope:c,depth:d,from:Fe.from,to:Fe.to,tz:n,...ke.kind==="binned"?{bin:ke.bin}:{},...u?{q:u,where:Fe.where}:{},...Object.keys(f).length?{filters:f}:{},...st?{series:st}:{},...Ae}}let O=()=>JSON.stringify([c,d,u,f,ot()]);async function L(H=!1){let he=ot(),ke=O(),Ae=h.t1-h.t0;if(!H&&b&&ke===v.key&&h.t0>=v.from&&h.t1<=v.to){Z();return}if(K){C=!0;return}K++;let Fe=h.t0-Ae/2,st=Math.min(h.t1+Ae/2,Math.max(h.t1,at()+Ae*.1));try{let bt=await e.source.query(m(Fe,st,he,he.kind==="single"?{limit:1e4}:{}));he.kind==="single"&&bt.next&&(bt=await e.source.query(m(Fe,st,{kind:"binned",bin:"1m"}))),b=bt,k=ke,v={from:Fe,to:st,mode:he,key:ke}}catch(bt){be.textContent=`The history couldn't be read: ${String(bt?.message??bt)}`}finally{K--}Z(),q(),C&&(C=!1,L())}function G(){let H=Ne(),he=ot();if(J=[],g&&b){let ke=new Map([...we].map(([Ae,Fe])=>[Ae,Fe.type]));J=Ca(jc(b,he,ke),h.t0,Math.min(h.t1,Math.max(h.t0,at())),{minFrac:.15,minMs:10*zo}),he.kind==="binned"&&(J=J.filter(Ae=>Ae.to-Ae.from>=2*On[he.bin])),J=J.filter(Ae=>!(N.has(lr(Ae))&&(F.get(lr(Ae))??1)>=1))}ae=Kr(h.t0,h.t1,H,J,{cut:om,weights:F})}let Z=()=>{D||(D=requestAnimationFrame(Se))};function Se(){D=0,G();let H=Ne(),he=gt(),ke=v.mode,Ae=[],Fe=rs;for(let ve of he)Ae.push(Fe),Fe+=ft(ve);let st=Math.max(Fe,rs+cr);Ee.setAttribute("width",String(H)),Ee.setAttribute("height",String(st)),Ee.setAttribute("viewBox",`0 0 ${H} ${st}`);let bt=Be.scrollTop-200,yn=Be.scrollTop+(Be.clientHeight||600)+200,et=[],Qe=ae.x;et.push(Ct("rect",{class:"tlx-axis",x:0,y:0,width:H,height:rs}));let Ut=(b?.retention??[]).map(ve=>({r:ve,from:ke.kind==="binned"?ve.keptFrom.rollups[ke.bin]??ve.keptFrom.events:ve.keptFrom.events,days:ke.kind==="binned"?ve.rollups[ke.bin]:ve.events})).filter(ve=>ve.from!==void 0);if(Ut.length){let ve=Math.min(...Ut.map(je=>je.from));ve>h.t0&&et.push(Ct("rect",{class:"tlx-notkept",x:Math.max(0,Qe(h.t0)),y:rs,width:Math.max(0,Qe(ve)-Math.max(0,Qe(h.t0))),height:st-rs},`Nothing kept before ${nn(ve,n)}: ${Ut.map(je=>`${je.r.source} ${je.days===null?"kept until deleted":`kept ${je.days} days`}`).join(", ")}`))}let an=at();an<h.t1&&et.push(Ct("rect",{class:"tlx-future",x:Qe(an),y:rs,width:H-Qe(an),height:st-rs}));for(let ve of Na(ae,n,90)){et.push(Ct("line",{class:`tlx-tick${ve.major?" major":""}`,x1:ve.x,x2:ve.x,y1:rs-6,y2:st}));let je=Ct("text",{class:"tlx-ticklabel",x:ve.x+3,y:16});je.textContent=ve.label,et.push(je)}y&&et.push(Ct("rect",{class:"tlx-brush",x:Qe(y.from),y:0,width:Math.max(1,Qe(y.to)-Qe(y.from)),height:st}));let br=ke.kind==="single"?(b?.events??[]).filter(ve=>ve.dur!==void 0||ve.open):b?.spans??[],Xo=ke.kind==="single"?(b?.events??[]).filter(ve=>ve.dur===void 0&&!ve.open):[],Ws=new Map;he.forEach((ve,je)=>{ve.kind==="row"&&Ws.set(ve.row.scope,je)});let cs=ve=>{let je=Xt(c)+d,dt=Xt(ve)>=je?vs(ve,je):ve;return Ws.get(dt)},Js=ve=>Ae[ve]+ft(he[ve])>=bt&&Ae[ve]<=yn;if(he.forEach((ve,je)=>{Js(je)&&et.push(Ct("rect",{class:`tlx-lane${je%2?" odd":""}${ve.kind==="metric"?" metric":""}`,x:0,y:Ae[je],width:H,height:ft(ve)}))}),ke.kind==="binned"){let ve=new Map;for(let je of b?.bins??[]){let dt=cs(je.scope);dt!==void 0&&ve.set(dt,Math.max(ve.get(dt)??0,je.count))}for(let je of b?.bins??[]){let dt=cs(je.scope);if(dt===void 0||!Js(dt))continue;let yt=Qe(je.t),ut=Qe(je.t+On[je.bin]);if(ut<0||yt>H)continue;let Tt=[...mn].reverse().find(R=>(je.severity[R]??0)>0)??"info",P=Math.max(2,(cr-8)*Math.sqrt(je.count)/Math.sqrt(ve.get(dt)||1));et.push(Ct("rect",{class:"tlx-countbar",x:yt,y:Ae[dt]+cr-3-P,width:Math.max(1,ut-yt-.5),height:P,"data-t":je.t},`${nn(je.t,n)}: ${je.count} event${je.count===1?"":"s"}${Tt!=="info"&&Tt!=="debug"?`, the worst ${Tt}`:""}`)),(Tt==="warning"||Tt==="error")&&et.push(Ct("rect",{class:`tlx-heat sev-${Tt}`,x:yt,y:Ae[dt]+cr-(Tt==="error"?4:3),width:Math.max(1,ut-yt-.5),height:Tt==="error"?3:2}))}}for(let ve of br){let je=cs(ve.scope);if(je===void 0||!Js(je))continue;let dt=ve.open?an:ve.t+(ve.dur??0),yt=Qe(ve.t),ut=Qe(dt);if(ut<-2||yt>H+2)continue;let Tt=`tlx-span sev-${ve.severity}${ve.open?" open":""}${T?.id===ve.id?" selected":""}`,P=`${ve.summary} \xB7 ${nn(ve.t,n)}${ve.open?", still going":`, ${Dc(dt-ve.t)}`}`,R=Ae[je]+5,V=ke.kind==="binned"?4:8,W=yt;for(let oe of ae.cuts)oe.weight>=1||oe.x1<=yt||oe.x0>=ut||(oe.x0>W&&et.push(Ct("rect",{class:Tt,x:W,y:R,width:Math.max(1,oe.x0-W),height:V,rx:2,"data-id":ve.id},P)),et.push(Ct("path",{class:`${Tt} through`,d:`M${oe.x0} ${R+V/2} H${oe.x1}`,"data-id":ve.id},`${P} (lasted through the break)`)),W=oe.x1);ut>W&&et.push(Ct("rect",{class:Tt,x:Math.max(-2,W),y:R,width:Math.max(2,Math.min(H+2,ut)-Math.max(-2,W)),height:V,rx:2,"data-id":ve.id},P))}let eo=new Map;for(let ve of Xo){let je=cs(ve.scope);if(je===void 0||!Js(je))continue;let dt=Qe(ve.t);if(dt<-6||dt>H+6||dt-(eo.get(je)??-1/0)<3)continue;eo.set(je,dt);let yt=Ae[je]+cr/2+2,ut=4,Tt=im[ve.severity],P=Tt==="diamond"?`M${dt} ${yt-ut-1} l${ut+1} ${ut+1} l${-ut-1} ${ut+1} l${-ut-1} ${-ut-1} z`:Tt==="triangle"?`M${dt} ${yt-ut-1} l${ut+1} ${2*ut+1} h${-2*ut-2} z`:Tt==="square"?`M${dt-ut+.5} ${yt-ut+.5} h${2*ut-1} v${2*ut-1} h${-2*ut+1} z`:"",R=`${nn(ve.t,n)} \xB7 ${ve.summary}`,V=`tlx-mark sev-${ve.severity}${T?.id===ve.id?" selected":""}${w>=0&&$[w]?.id===ve.id?" hit":""}`;et.push(P?Ct("path",{class:V,d:P,"data-id":ve.id},R):Ct("circle",{class:V,cx:dt,cy:yt,r:Tt==="dot"?2.5:ut,"data-id":ve.id},R))}he.forEach((ve,je)=>{if(ve.kind!=="metric"||!Js(je))return;let dt=new Map;for(let se of b?.metrics??[]){if(se.series!==ve.series)continue;let ie="value"in se?{min:se.value,max:se.value,sum:se.value,count:1}:{min:se.min,max:se.max,sum:se.sum,count:se.count},le=dt.get(se.t);le?(le.min=Math.min(le.min,ie.min),le.max=Math.max(le.max,ie.max),le.sum+=ie.sum,le.count+=ie.count):dt.set(se.t,{...ie})}let yt=[...dt].sort((se,ie)=>se[0]-ie[0]);if(!yt.length)return;let ut=ke.kind==="binned"?On[ke.bin]:zo,Tt=se=>ve.type==="gauge"?se.sum/Math.max(1,se.count):se.sum,P=Math.max(1e-9,...yt.map(([,se])=>ve.type==="gauge"?se.max:Tt(se))),R=Ae[je]+Da-4,V=Da-10,W=se=>R-se/P*V;if(ve.type==="gauge"){let se=yt.map(([ie,le])=>`${Qe(ie)},${W(le.max)}`).join(" ")+" "+[...yt].reverse().map(([ie,le])=>`${Qe(ie)},${W(le.min)}`).join(" ");et.push(Ct("polygon",{class:"tlx-band",points:se})),et.push(Ct("polyline",{class:"tlx-line",points:yt.map(([ie,le])=>`${Qe(ie+ut/2)},${W(Tt(le))}`).join(" ")}))}else{let se="",ie=-1/0;for(let[le,pe]of yt){let ge=Qe(le),Te=Qe(le+ut),qe=W(Tt(pe));se+=le>ie?`M${ge} ${R} V${qe} H${Te}`:` V${qe} H${Te}`,ie=le+ut;let Le=yt.find(([ct])=>ct>le);(!Le||Le[0]>ie)&&(se+=` V${R} Z`)}et.push(Ct("path",{class:"tlx-area",d:se}))}let oe=Ct("text",{class:"tlx-peak",x:4,y:Ae[je]+11});oe.textContent=`peak ${am(P,ve.unit)}${ve.type==="counter"?` per ${ke.kind==="binned"?ke.bin:"1m"}`:""}`,et.push(oe)});for(let ve of ae.cuts){if(ve.weight>=1)continue;let je=ut=>{let Tt=`M${ut} 0`;for(let P=0;P<st;P+=8)Tt+=` L${ut+(P/8%2?-3:3)} ${P+8}`;return Tt},dt=Ct("g",{class:"tlx-cut",tabindex:0,role:"button","data-from":ve.from,"data-to":ve.to,"aria-label":`A break of ${ar(ve.to-ve.from)} with nothing shown, from ${nn(ve.from,n)} to ${nn(ve.to,n)}: press to open it`},`${ar(ve.to-ve.from)} with nothing here: ${nn(ve.from,n)} to ${nn(ve.to,n)} (click to open)`);dt.append(Ct("rect",{class:"tlx-cut-bg",x:ve.x0,y:0,width:ve.x1-ve.x0,height:st})),dt.append(Ct("path",{class:"tlx-cut-edge",d:je(ve.x0+3)}),Ct("path",{class:"tlx-cut-edge",d:je(ve.x1-3)}));let yt=Ct("text",{class:"tlx-cut-label",x:(ve.x0+ve.x1)/2,y:15,"text-anchor":"middle"});yt.textContent=ar(ve.to-ve.from),dt.append(yt),et.push(dt)}if(M!==void 0){let ve=Qe(M);et.push(Ct("line",{class:"tlx-playhead",x1:ve,x2:ve,y1:0,y2:st})),et.push(Ct("path",{class:"tlx-handle",d:`M${ve-6} 0 h12 v8 l-6 7 l-6 -7 z`},`the playhead: ${nn(M,n)}`))}Ee.replaceChildren(...et),ze.replaceChildren(z("div",{class:"tlx-labelhead",style:`height:${rs}px`},ot().kind==="single"?"single events":`per ${ot().kind==="binned"?ot().bin:""}`),...he.map(ve=>{if(ve.kind==="metric")return z("div",{class:"tlx-rowlabel metric",style:`height:${Da}px`,title:`${ve.title} (${ve.type==="counter"?"sums":"min, max and mean"})`},ve.title);let je=ve.row,dt=z("div",{class:`tlx-rowlabel${je.own?" own":""}`,style:`height:${cr}px`,"data-scope":je.scope,title:`${je.scope||"all hosts"} \xB7 ${je.count} event${je.count===1?"":"s"}`},z("span",{class:"tlx-kind"},e.catalog.flags.find(yt=>je[yt])??je.kind),z("span",{class:"tlx-name"},je.own?`${je.label} (itself)`:je.label),z("span",{class:"tlx-count"},String(je.count)));if(!je.own&&je.scope!==c){let yt=z("button",{type:"button",class:"tlx-drill",title:je.children?`Into ${je.label}: its ${je.children} part${je.children===1?"":"s"}`:`Into ${je.label}`,"aria-label":`Into ${je.label}`},"\u203A");yt.addEventListener("click",()=>St(je.scope)),dt.append(yt)}return dt})),ze.style.width=`${rm}px`,ue()}function ue(){U.replaceChildren(...jr(c).flatMap((Ae,Fe,st)=>{let bt=z("button",{type:"button",class:`tlx-crumb${Fe===st.length-1?" current":""}`,"aria-current":Fe===st.length-1?"location":void 0},Ze(Ae.scope,Ae.label));return bt.addEventListener("click",()=>{Ae.scope!==c&&(c=Ae.scope,d=1,L(!0))}),Fe?[z("span",{class:"tlx-sep","aria-hidden":"true"},"/"),bt]:[bt]})),fe.setAttribute("aria-pressed",String(p)),fe.classList.toggle("on",p),B.hidden=!p||A;let H=ot(),he=b?.total??0,ke=(b?.retention??[]).filter(Ae=>Ae.events!==null).map(Ae=>`${Ae.source} kept ${Ae.events} d`);be.textContent=`${nn(h.t0,n)} \u2013 ${nn(h.t1,n)} \xB7 ${H.kind==="single"?"single events":`bins of ${H.bin}`} \xB7 ${he} event${he===1?"":"s"}${J.length?` \xB7 ${J.length} break${J.length===1?"":"s"}`:""}${ke.length?` \xB7 ${ke.slice(0,3).join(", ")}`:""}`,Pe.hidden=!S.length,Pe.textContent=S.join(" \xB7 "),ye.textContent=u?$.length?`${w+1>0?`${w+1} of `:""}${$.length}${$.length>=2e3?"+":""} hit${$.length===1?"":"s"}`:`${he?`${he} hit${he===1?"":"s"}`:"no hits"}`:"";for(let Ae of ee.querySelectorAll(".seg"))Ae.classList.remove("on");ce.textContent=M===void 0?"":x?(()=>{let Ae=e.stamp?.(x)??{};return`Canvas: the state recorded at ${nn(Date.parse(Ae.at??"")||M,n)}${Ae.tag?` (${Ae.tag})`:""}`})():"No state recorded here",ce.classList.toggle("none",M!==void 0&&!x)}function Ke(){Ue.replaceChildren();for(let H of l?.sources??[]){let he=!f.source?.length||f.source.includes(H.name),ke=z("button",{type:"button",class:`tlx-chip${he?" on":""}${H.status==="not-yet"?" notyet":""}`,"aria-pressed":String(he&&H.status!=="not-yet"),disabled:H.status==="not-yet",title:H.status==="not-yet"?`${H.title}: not kept yet`:`${H.title}${Ye(H)}`},H.name);H.status!=="not-yet"&&ke.addEventListener("click",()=>Ie(H.name)),Ue.append(ke)}}let Ye=H=>{let he=l?.retention.find(ke=>ke.source===H.name);return he?` (kept ${he.events===null?"until deleted":`${he.events} days`})`:""};function Ie(H){let he=(l?.sources??[]).filter(Ae=>Ae.status==="kept").map(Ae=>Ae.name),ke=f.source?.length?[...f.source]:[...he];ke=ke.includes(H)?ke.filter(Ae=>Ae!==H):[...ke,H],f={...f,...ke.length===he.length?{source:void 0}:{source:ke}},f.source||delete f.source,Ke(),L(!0),Ce()}let De=0;me.addEventListener("input",()=>{clearTimeout(De),De=setTimeout(()=>{u=me.value.trim(),w=-1,L(!0),Ce()},250)}),me.addEventListener("keydown",H=>{H.key==="Enter"&&(H.preventDefault(),clearTimeout(De),u=me.value.trim(),L(!0).then(()=>Ce()).then(()=>vt(H.shiftKey?-1:1)))});async function Ce(){if(!u){$=[],w=-1,ue();return}let H=h.t1-h.t0;$=(await e.source.query(m(h.t0-H*4,Math.max(h.t1+H*4,at()),{kind:"single"},{limit:2e3}))).events??[],w=Math.min(w,$.length-1),ue()}function vt(H){if(!$.length)return;let he=(h.t0+h.t1)/2;w<0?w=H>0?Math.max(0,$.findIndex(Fe=>Fe.t>=he)):Math.max(0,$.length-1-[...$].reverse().findIndex(Fe=>Fe.t<=he)):w=(w+H+$.length)%$.length;let ke=$[w],Ae=Math.min(h.t1-h.t0,2*dr);h={t0:ke.t-Ae/2,t1:ke.t+Ae/2},A=!1,pt(ke),L()}xe.addEventListener("click",()=>vt(-1)),Re.addEventListener("click",()=>vt(1)),I.addEventListener("change",()=>{let H=I.value;f={...f,...H?{severity:mn.filter(he=>Zu(he)>=Zu(H))}:{}},H||delete f.severity,L(!0),Ce()});async function Mn(H,he=!0){let ke=at();if(H==="run"){let Ae=await e.source.query({timeline:1,type:"query",scope:c,depth:0,from:ke-30*kn,to:ke+1,filters:{kind:["run"]},limit:1e4}).catch(()=>{}),Fe=Ae?.events?.[Ae.events.length-1];h=Fe?{t0:Fe.t-(Fe.dur??dr)*.02,t1:(Fe.open?ke:Fe.t+(Fe.dur??dr))+(Fe.dur??dr)*.04}:{t0:ke-kn,t1:ke+kn*.02}}else h={t0:ke-Qu[H],t1:ke+Qu[H]*.02};A=!0,N.clear(),F.clear(),he&&L()}function kt(H,he=!0){if(p=H,_?.(),_=void 0,H&&e.source.subscribe){let ke=0,Ae=0;_=e.source.subscribe(m(at()-dr,at()+365*kn,{kind:"single"}),Fe=>{if(l&&(l.now=Math.max(l.now,Fe.now)),A){let bt=h.t1-h.t0;h={t0:Fe.now-bt*.98,t1:Fe.now+bt*.02}}let st=Date.now();st-ke>500?(ke=st,L(!0)):Ae||(Ae=setTimeout(()=>{Ae=0,ke=Date.now(),L(!0)},500))}),A=!0}he&&(ue(),q())}fe.addEventListener("click",()=>kt(!p)),B.addEventListener("click",()=>{A=!0;let H=h.t1-h.t0,he=at();h={t0:he-H*.98,t1:he+H*.02},L()}),X.addEventListener("click",()=>{Et()}),Q.addEventListener("change",()=>{g=Q.checked,N.clear(),F.clear(),Z(),q()}),ne.addEventListener("change",()=>{te=ne.checked,Z(),q()});function St(H){let he=b?.rows.find(ke=>ke.scope===H);c=H,d=he&&he.children===0?0:1,y=void 0,it.hidden=!0,L(!0)}async function Et(){let H=at(),ke=((await e.source.query({timeline:1,type:"query",scope:c,depth:0,from:H-400*kn,to:H+1,bin:"1d",tz:n}).catch(()=>{}))?.bins??[]).map(Fe=>Fe.t),Ae=ke.length?Math.min(...ke):H-7*kn;h={t0:Ae,t1:H+(H-Ae)*.02},A=!0,L()}let bn=0;async function Yt(H){if(M=H,Z(),H===void 0){x=void 0;return}let he=++bn,ke=e.source.stateAt?await e.source.stateAt(c,H).catch(()=>{}):void 0;he===bn&&(x=ke,e.onPlayhead?.(H,ke),ue())}async function Pt(H,he){y={from:Math.min(H,he),to:Math.max(H,he)},Z();let ke=await e.source.query(m(y.from,y.to,{kind:"single"},{limit:500})),Ae=o(u),Fe=et=>{let Qe=[],Nt=0;for(let[Ut,an]of _o(Ae,et))Qe.push(et.slice(Nt,Ut),z("mark",null,et.slice(Ut,an))),Nt=an;return Qe.push(et.slice(Nt)),Qe},st=(ke.events??[]).map(et=>{let Qe=z("tr",{"data-id":et.id,tabindex:"0"},z("td",null,nn(et.t,n)),z("td",null,et.dur!==void 0?Dc(et.dur):et.open?"still going":""),z("td",null,et.source),z("td",null,et.kind),z("td",{class:`sev-${et.severity}`},et.severity),z("td",{class:"tlx-sum"},...Fe(et.summary)),z("td",{class:"tlx-scope"},et.scope));return Qe.addEventListener("click",()=>pt(et)),Qe.addEventListener("keydown",Nt=>{Nt.key==="Enter"&&pt(et)}),Qe}),bt=z("button",{type:"button",class:"btn sm quiet","aria-label":"Close the table"},"Close");bt.addEventListener("click",()=>{y=void 0,it.hidden=!0,Z()});let yn=et=>{let Qe=z("button",{type:"button",class:"btn sm","data-export":et},et.toUpperCase());return Qe.addEventListener("click",()=>{_t(et)}),Qe};it.replaceChildren(z("div",{class:"tlx-table-head"},z("strong",null,`${ke.total} event${ke.total===1?"":"s"}`),z("span",null,` ${nn(y.from,n)} \u2013 ${nn(y.to,n)}${ke.total>500?" (the first 500 shown; the export has them all)":""}`),z("span",{class:"spacer"}),z("span",null,"Export: "),yn("json"),yn("csv"),bt),z("div",{class:"tlx-table-wrap"},z("table",null,z("thead",null,z("tr",null,...["When","Long","Source","Kind","Severity","What","Scope"].map(et=>z("th",{scope:"col"},et)))),z("tbody",null,...st)))),it.hidden=!1}async function Ot(){if(!y)return[];let H=[],he;do{let ke=await e.source.query(m(y.from,y.to,{kind:"single"},{limit:1e4,...he?{cursor:he}:{}}));H.push(...ke.events??[]),he=ke.next}while(he&&H.length<2e5);return H}async function _t(H){let he=await Ot(),ke=H==="json"?La(he,j):Ra(he,j),Ae=`timeline-${new Date(y.from).toISOString().slice(0,16).replace(/:/g,"")}.${H}`,Fe=H==="json"?"application/json":"text/csv";if(e.onExport){e.onExport(Ae,ke,Fe);return}let st=z("a",{href:`data:${Fe};charset=utf-8,${encodeURIComponent(ke)}`,download:Ae});document.body.append(st),st.click(),st.remove()}function pt(H){if(T=H,Z(),!H){We.hidden=!0;return}let he=l?.sources.find(Qe=>Qe.name===H.source),ke=new Set(he?.sensitive??[]),Ae=o(u),Fe=Qe=>{let Nt=[],Ut=0;for(let[an,br]of _o(Ae,Qe))Nt.push(Qe.slice(Ut,an),z("mark",null,Qe.slice(an,br))),Ut=br;return Nt.push(Qe.slice(Ut)),Nt},st=(Qe,Nt)=>{if(!Nt)return null;let Ut=z("button",{type:"button",class:"btn sm"},Qe);return Ut.addEventListener("click",Nt),Ut},bt=Object.entries(H.attrs).map(([Qe,Nt])=>{if(!ke.has(Qe))return z("tr",null,z("th",{scope:"row"},Qe),z("td",null,...Fe(String(Nt))));let Ut=z("button",{type:"button",class:"btn sm quiet",title:"This can name a remote host, a folder or free text"},"Show"),an=z("td",{class:"tlx-sensitive"},"hidden ",Ut);return Ut.addEventListener("click",()=>an.replaceChildren(String(Nt))),z("tr",null,z("th",{scope:"row"},Qe),an)}),yn=z("button",{type:"button",class:"btn sm quiet tlx-close","aria-label":"Close"},"\xD7");yn.addEventListener("click",()=>pt(void 0));let et=jr(H.scope).slice(1).map(Qe=>{let Nt=z("button",{type:"button",class:"tlx-crumb"},Ze(Qe.scope,Qe.label));return Nt.addEventListener("click",()=>St(Qe.scope)),Nt});We.replaceChildren(z("div",{class:"tlx-detail-head"},z("strong",null,H.kind),yn),z("p",{class:`tlx-sev sev-${H.severity}`},`${H.severity} \xB7 ${he?.title??H.source}`),z("p",{class:"tlx-sum"},...Fe(H.summary)),z("p",null,nn(H.t,n),H.dur!==void 0?` \xB7 ${Dc(H.dur)}${H.open?" so far":""}`:H.open?" \xB7 still going":""),z("p",{class:"tlx-crumbs small"},...et),...bt.length?[z("table",{class:"tlx-attrs"},z("tbody",null,...bt))]:[],z("div",{class:"tlx-links"},...(e.actions?.(H)??[]).map(([Qe,Nt])=>st(Qe,Nt)))),We.hidden=!1}function as(H,he){let ke=lr({from:H,to:he});if(!J.find(bt=>bt.from===H&&bt.to===he))return;if(N.add(ke),!r){F.set(ke,1),Z();return}let Fe=performance.now(),st=bt=>{let yn=Math.min(1,(bt-Fe)/260);F.set(ke,1-(1-yn)**3),Se(),yn<1&&requestAnimationFrame(st)};requestAnimationFrame(st)}let Ht,Yn=H=>H.clientX-Ee.getBoundingClientRect().left;Ee.addEventListener("pointerdown",H=>{let he=Yn(H),ke=H.clientY-Ee.getBoundingClientRect().top,Ae=H.target.closest?.(".tlx-cut");if(Ae){H.preventDefault(),as(Number(Ae.getAttribute("data-from")),Number(Ae.getAttribute("data-to")));return}Ee.setPointerCapture(H.pointerId),Ht={kind:ke<rs||H.shiftKey?"brush":H.target.classList.contains("tlx-handle")?"scrub":"pan",x0:he,t0:ae.t(he),v0:h,moved:!1},H.preventDefault(),Oe.focus({preventScroll:!0})}),Ee.addEventListener("pointermove",H=>{if(!Ht)return;let he=Yn(H);if(Math.abs(he-Ht.x0)>3&&(Ht.moved=!0),!!Ht.moved)if(Ht.kind==="pan"){let ke=(Ht.x0-he)*ae.msPerPx;h={t0:Ht.v0.t0+ke,t1:Ht.v0.t1+ke},A=!1,L()}else Ht.kind==="scrub"?Yt(ae.t(he)):(y={from:Math.min(Ht.t0,ae.t(he)),to:Math.max(Ht.t0,ae.t(he))},Z())}),Ee.addEventListener("pointerup",H=>{let he=Ht;if(Ht=void 0,!he)return;let ke=Yn(H);if(he.kind==="brush"&&he.moved){Pt(he.t0,ae.t(ke));return}if(he.kind==="brush"&&!he.moved){Yt(ae.t(ke));return}if(he.kind==="pan"&&!he.moved){let Ae=H.target.closest?.("[data-id]")?.getAttribute("data-id"),Fe=Ae?[...b?.events??[],...b?.spans??[]].find(st=>st.id===Ae):void 0;Fe?(pt(Fe),Yt(Fe.t)):Yt(ae.t(ke))}}),Ee.addEventListener("keydown",H=>{let he=H.target.closest?.(".tlx-cut");he&&(H.key==="Enter"||H.key===" ")&&(H.preventDefault(),as(Number(he.getAttribute("data-from")),Number(he.getAttribute("data-to"))))}),Ee.addEventListener("wheel",H=>{H.preventDefault();let he=Yn(H);if(H.shiftKey||Math.abs(H.deltaX)>Math.abs(H.deltaY)){let ke=(H.shiftKey?H.deltaY:H.deltaX)*ae.msPerPx;h={t0:h.t0+ke,t1:h.t1+ke},A=!1}else ls(ae.t(he),Math.exp(H.deltaY*.0015),he/Ne());L()},{passive:!1});function ls(H,he,ke=.5){let Ae=Math.min(400*kn,Math.max(1e4,(h.t1-h.t0)*he));h={t0:H-ke*Ae,t1:H+(1-ke)*Ae},N.clear(),F.clear(),he<1&&(A=p&&h.t1>=at())}Oe.addEventListener("keydown",H=>{let he=h.t1-h.t0;if(H.key==="ArrowLeft"||H.key==="ArrowRight"){let ke=he*.15*(H.key==="ArrowLeft"?-1:1);h={t0:h.t0+ke,t1:h.t1+ke},A=!1}else if(H.key==="+"||H.key==="=")ls((h.t0+h.t1)/2,.6);else if(H.key==="-"||H.key==="_")ls((h.t0+h.t1)/2,1/.6);else if(H.key==="n"||H.key==="N"){vt(H.shiftKey?-1:1),H.preventDefault();return}else if(H.key==="Escape")pt(void 0),y=void 0,it.hidden=!0;else return;H.preventDefault(),L()}),t.addEventListener("keydown",H=>{H.key==="/"&&document.activeElement!==me&&!H.target.closest("input, select, textarea")&&(H.preventDefault(),me.focus())}),Be.addEventListener("scroll",()=>Z(),{passive:!0}),$e.addEventListener("click",async()=>{let H=`${jr(c).slice(-1)[0].label}${u?`: ${u}`:""}`.slice(0,80);await e.saveView?.({...E(),name:H}),await fn()});let rt=[];async function fn(){e.views&&(rt=await e.views(),re.replaceChildren(z("option",{value:""},"Saved views\u2026"),...rt.map((H,he)=>z("option",{value:String(he)},H.name))))}re.addEventListener("change",()=>{let H=rt[Number(re.value)];H&&(Y(H),Ke(),L(!0)),re.value=""});let Mt=typeof ResizeObserver=="function"?new ResizeObserver(()=>Z()):void 0;Mt?.observe(Oe);let Jt=(async()=>{l=await e.source.catalog(),j=l.sources.flatMap(Ae=>(Ae.sensitive??[]).map(Fe=>`${Ae.name}.${Fe}`));for(let Ae of l.sources)for(let Fe of Ae.series)we.set(Fe.name,{unit:Fe.unit,type:Fe.type,title:Fe.title,source:Ae.name});c=l.hosts.length===1?`host:${l.hosts[0].replace(/[%/:\s]/g,Ae=>`%${Ae.charCodeAt(0).toString(16).toUpperCase().padStart(2,"0")}`)}`:"";let he=l.now;h={t0:he-kn,t1:he+kn*.02};let ke=de()??e.view;ke&&Y(ke),Ke(),await fn(),await L(!0),u&&await Ce()})();return{el:t,ready:Jt,get view(){return E()},setView(H){return Y(H),Ke(),L(!0)},setRange(H,he){return h={t0:H,t1:he},A=!1,L()},setPlayhead:Yt,setLive:kt,setTheme:a,refresh:()=>L(!0),internal:{get result(){return b},get mode(){return ot()},get scale(){return ae},get gaps(){return J},get playState(){return x},get hits(){return $},get selected(){return T},get follow(){return A},openCut:as,showTable:Pt,rangeEvents:Ot,exportRange:_t,select:pt,stepHit:vt,drill:St,findHits:Ce,paint:Se,lines:gt},dispose(){_?.(),Mt?.disconnect(),D&&cancelAnimationFrame(D),t.replaceChildren()}}}var lm={arrow:{d:"M0,0 L10,5 L0,10 z",refX:9},open:{d:"M0,0 L10,5 L0,10 L3,5 z",refX:9},diamond:{d:"M0,5 L5,1.5 L10,5 L5,8.5 z",refX:1}},sn=t=>(Math.round(t*10)/10).toString(),tf=t=>(t??"link").replace(/[^\w-]/g,"_");function _r(t,e){let{id:n}=e,s=e.styles??{},r=t.options,o=t.bounds,i=new Map,a=(p,g)=>{let h=s[p]??{},b=g==="start"?h.start??"none":h.end??"arrow";if(b!=="none")return(i.get(p)??i.set(p,new Set).get(p)).add(b),`url(#${n}-mk-${p}-${b})`},l="",c="",d="",u="";for(let p of[...t.panels].sort((g,h)=>g.depth-h.depth)){let g=p.rect,h=p.label?Ve("text",{class:"pl",x:p.titleAt[0],y:p.titleAt[1]},Dt(p.label)+(p.sub?Ve("tspan",{class:"pls",dx:10},Dt(p.sub)):"")):"";l+=Ve("g",{class:`panel k-${p.role??"grey"}`,"data-id":p.id},Ve("rect",{class:"face",x:sn(g.l),y:sn(g.t),width:sn(g.r-g.l),height:sn(g.b-g.t),rx:r.panelRx})+h)}for(let p of t.links){if(!p.points.length)continue;let g=tf(p.kind);c+=Ve("path",{class:`conn k-${g}`,d:"M"+p.points.map(h=>`${sn(h[0])},${sn(h[1])}`).join(" L"),"data-id":p.id,"data-a":p.a,"data-b":p.b,"marker-start":a(g,"start"),"marker-end":a(g,"end")}),p.at&&(u+=Ve("text",{class:`cl k-${g}`,x:p.at.x,y:p.at.y,"text-anchor":p.at.anchor==="start"?void 0:p.at.anchor,"data-for":p.id},Dt(p.at.text)))}for(let p of t.cards){let g=p.rect;d+=Ve("g",{class:`card k-${p.role??"grey"}${p.ghost?" ghost":""}`,"data-id":p.id,tabindex:0,role:"button","aria-label":p.sub?`${p.label}: ${p.sub}`:p.label},Ve("rect",{class:"face",x:sn(g.l),y:sn(g.t),width:r.W,height:r.H,rx:r.cardRx})+Ve("text",{class:"lt",x:sn(g.l+14),y:sn(g.t+24)},Dt(p.label))+(p.sub?Ve("text",{class:"st",x:sn(g.l+14),y:sn(g.t+42)},Dt(p.sub)):""))}let f="";for(let[p,g]of i)for(let h of g){let b=lm[h];f+=Ve("marker",{id:`${n}-mk-${p}-${h}`,viewBox:"0 0 10 10",refX:b.refX,refY:5,markerWidth:5.4,markerHeight:5.4,orient:"auto-start-reverse"},Ve("path",{d:b.d,class:`mk k-${p}`}))}return Ve("svg",{xmlns:"http://www.w3.org/2000/svg",class:"flat",viewBox:`${sn(o.l)} ${sn(o.t)} ${sn(o.r-o.l)} ${sn(o.b-o.t)}`,role:"img","aria-label":e.title??"drawing, flat view","data-view":"2d"},(f?Ve("defs",{},f):"")+Ve("g",{class:"panels"},l)+Ve("g",{class:"conns"},c)+Ve("g",{class:"cards"},d)+Ve("g",{class:"labels"},u))}function nf(t={}){let e=s=>s?s.startsWith("#")||s.includes("(")?s:`var(--${s})`:"var(--ink)",n=`
|
|
359
|
+
`}var Am=864e5,es=36e5,Qa=(t,e)=>t.t-e.t||(t.id<e.id?-1:t.id>e.id?1:0);function hs(t,e){let n=0,s=t.length;for(;n<s;){let r=n+s>>1;t[r].t<e?n=r+1:s=r}return n}var wf=(t,e)=>{t.min=Math.min(t.min,e.min),t.max=Math.max(t.max,e.max),t.sum+=e.sum,t.count+=e.count};function yf(t,e,n){let s=[];for(let r of t){let o=yr(r.t,e,n),i=s[s.length-1];i&&i.t===o?wf(i,r):s.push({t:o,min:r.min,max:r.max,sum:r.sum,count:r.count})}return s}function td(t,e,n,s){for(let i=hs(t,e.t);i<t.length&&t[i].t===e.t;i++)if(n(t[i])){t[i]=e;return}let r=t[t.length-1];if(!r||s(r,e)<=0){t.push(e);return}let o=hs(t,e.t);for(;o<t.length&&s(t[o],e)<0;)o++;t.splice(o,0,e)}function xf(t,e,n){for(let s=hs(t,e);s<t.length&&t[s].t===e;s++)if(n(t[s])){t.splice(s,1);return}}function vf(t,e,n={}){let s=t.catalog,{isScope:r}=Va(e),{parseSearch:o,matchAst:i,toAst:a}=Jr(e),l=D=>Object.fromEntries(e.flags.filter(se=>D?.[se]).map(se=>[se,!0])),c=n.now??s.now,d=(s.names??[]).flatMap(D=>(D.aliases??[]).map(se=>[se,D.scope])).sort((D,se)=>se[0].length-D[0].length),u=new Map,f=D=>{if(!d.length)return D;let se=u.get(D);if(se===void 0){let Me=d.find(([Oe])=>En(D,Oe));se=Me?Me[1]+D.slice(Me[0].length):D,u.set(D,se)}return se},p=new Map((s.names??[]).map(D=>[D.scope,D])),g=D=>d.length?{...D,scope:f(D.scope)}:D,h=D=>`${D.source}\0${D.id}`,b=t.events.map(g).sort(Qa),v=new Map;for(let D of b)v.set(h(D),D);let w=b.filter(D=>D.dur!==void 0&&!D.open),M=w.reduce((D,se)=>Math.max(D,se.dur),0),y=new Map;for(let D of b)D.open&&y.set(h(D),D);let T=new Map,S=new Set,P=D=>{for(let se=rn(D);se>=1;se--){let Me=Ls(D,se);if(S.has(Me))break;S.add(Me)}},I=new Map;for(let D of s.sources)for(let se of D.series)I.set(se.name,se.type);let _=s.sources.flatMap(D=>(D.sensitive??[]).map(se=>`${D.name}.${se}`)),O=new Map;for(let D of s.sources)O.set(D.name,{events:D.defaultRetention.events,rollups:{...D.defaultRetention.rollups},setBy:"default"});for(let D of s.retention)O.set(D.source,{events:D.events,rollups:{...D.rollups},setBy:D.setBy});let j=new Map;for(let D of s.sources)for(let se of D.series)j.set(se.name,D.name);function k(D){let se=f(D.scope),Me=`${D.series}\0${se}`,Oe=T.get(Me);Oe||(Oe={series:D.series,scope:se,fine:[],cache:new Map},T.set(Me,Oe),P(se));let ge="value"in D?{t:D.t,min:D.value,max:D.value,sum:D.value,count:1}:{t:D.t,min:D.min,max:D.max,sum:D.sum,count:D.count};td(Oe.fine,ge,ie=>ie.t===ge.t,(ie,Ke)=>ie.t-Ke.t),Oe.cache.clear()}for(let D of b)P(D.scope);for(let D of t.metrics)k(D);let $=new Map,x=new Set,N=(D,se)=>{x.add(D.source);let Me=$.get(D.scope);Me||$.set(D.scope,Me=new Map);let Oe=Me.get(D.source);Oe||Me.set(D.source,Oe=new Map);let ge=Math.floor(D.t/es)*es,ie=Oe.get(ge);if(ie||Oe.set(ge,ie={t:ge,count:0,severity:{},kinds:{},first:1/0,last:-1/0}),ie.count+=se,se>0)ie.first=Math.min(ie.first,D.t),ie.last=Math.max(ie.last,D.t);else if(D.t===ie.first||D.t===ie.last){ie.first=1/0,ie.last=-1/0;for(let Ke=hs(b,ge);Ke<b.length&&b[Ke].t<ge+es;Ke++){let Ce=b[Ke];Ce.scope===D.scope&&Ce.source===D.source&&(ie.first=Math.min(ie.first,Ce.t),ie.last=Math.max(ie.last,Ce.t))}}ie.severity[D.severity]=(ie.severity[D.severity]??0)+se,ie.kinds[D.kind]=(ie.kinds[D.kind]??0)+se,ie.severity[D.severity]===0&&delete ie.severity[D.severity],ie.kinds[D.kind]===0&&delete ie.kinds[D.kind],ie.count||Oe.delete(ge)};for(let D of b)N(D,1);let F=(D,se,Me)=>{let Oe=`${se}|${Me??""}`,ge=D.cache.get(Oe);return ge||(ge=se==="1d"?yf(F(D,"1h",Me),"1d",Me):yf(D.fine,se,Me),D.cache.set(Oe,ge)),ge},J=D=>D===null?-1/0:c-D*Am,oe=D=>J(O.get(D)?.events??null),ve=(D,se)=>{let Me=O.get(D);return J(Me?se?Me.rollups[se]:Me.events:null)};function B(D){let se=[];for(let Me of new Set(D)){let Oe=O.get(Me);if(!Oe)continue;let ge=b.find(Ee=>Ee.source===Me&&Ee.t>=oe(Me))?.t,ie=Ee=>{let je=1/0;for(let lt of T.values())if(j.get(lt.series)===Me){let Ue=(Ee?F(lt,Ee):lt.fine).find(dt=>dt.t>=ve(Me,Ee));Ue&&Ue.t<je&&(je=Ue.t)}return je===1/0?void 0:je},Ke=[ge,ie()].filter(Ee=>Ee!==void 0),Ce={};for(let Ee of["1m","1h","1d"]){let je=ie(Ee)??(ge!==void 0&&ge>=ve(Me,Ee)?ge:void 0);je!==void 0&&(Ce[Ee]=Math.max(je,ve(Me,Ee)))}se.push({source:Me,events:Oe.events,rollups:{...Oe.rollups},setBy:Oe.setBy,keptFrom:{...Ke.length?{events:Math.min(...Ke)}:{},rollups:Ce}})}return se}function W(D){let se=D.where,Me={from:D.from,to:D.to},Oe=[];if(!se&&D.q){let Ue=o(D.q,c);se=a(Ue),Me=Qo(Ue,D.from,D.to),Oe=Ue.warnings}let ge=i(se,_),ie=D.filters??{},Ke=ie.source?.length?new Set(ie.source):void 0,Ce=ie.kind?.length?new Set(ie.kind):void 0,Ee=ie.severity?.length?new Set(ie.severity):void 0,je=ie.scope?.length?ie.scope:void 0;return{test:Ue=>En(Ue.scope,D.scope)&&(!Ke||Ke.has(Ue.source))&&(!Ce||Ce.has(Ue.kind))&&(!Ee||Ee.has(Ue.severity))&&(!je||je.some(dt=>En(Ue.scope,dt)))&&Ue.t>=oe(Ue.source)&&ge(Ue),range:Me,warnings:Oe}}function ee(D){let se=rn(D.scope),Me=se+D.depth,Oe=new Map,ge=Ee=>{let je=Oe.get(Ee);return je===void 0&&!Oe.has(Ee)&&(je=En(Ee,D.scope)?rn(Ee)>=Me?Ls(Ee,Me):Ee:void 0,Oe.set(Ee,je)),je},ie=Ee=>{let je=0,lt=rn(Ee)+1;for(let Ue of S)rn(Ue)===lt&&En(Ue,Ee)&&je++;return je},Ke=new Map,Ce=Ee=>{let je=Ke.get(Ee);if(!je){let lt=rn(Ee)-se,Ue=p.get(Ee);je={scope:Ee,label:Ue?.label??Ur(Ee),kind:qr(Ee),...l(Ue),depth:lt,...lt<D.depth?{own:!0}:{},children:ie(Ee),count:0},Ke.set(Ee,je)}return je};for(let Ee of S)rn(Ee)===Me&&En(Ee,D.scope)&&Ce(Ee);return Me===0&&Ce(""),{at:ge,add:Ce,rows:Ke}}let ue=D=>[...D.values()].sort((se,Me)=>se.scope===Me.scope?0:se.scope<Me.scope?-1:1);function z(D,se){let Me=[];for(let Oe=hs(w,D-M);Oe<w.length&&w[Oe].t<D;Oe++)w[Oe].t+w[Oe].dur>D&&Me.push(w[Oe]);for(let Oe of y.values())Oe.t<D&&c>D&&Me.push(Oe);for(let Oe=hs(b,D);Oe<b.length&&b[Oe].t<se;Oe++)Me.push(b[Oe]);return Me}function X(D,se,Me,Oe){let ge=D.series?new Set(D.series):void 0,ie=new Map;for(let Ce of T.values()){if(ge&&!ge.has(Ce.series))continue;let Ee=se(Ce.scope);if(Ee===void 0)continue;let je=j.get(Ce.series)??"",lt=ve(je,D.bin),Ue=D.bin?F(Ce,D.bin,D.tz):Ce.fine;for(let dt=hs(Ue,D.bin?yr(Me,D.bin,D.tz):Me);dt<Ue.length&&Ue[dt].t<Oe;dt++){let ut=Ue[dt];if(ut.t<lt)continue;let Ae=`${Ce.series}\0${Ee}\0${ut.t}`,pt=ie.get(Ae);pt?wf(pt,ut):ie.set(Ae,{series:Ce.series,scope:Ee,t:ut.t,bin:D.bin??"1m",min:ut.min,max:ut.max,sum:ut.sum,count:ut.count})}}let Ke=[...ie.values()].sort((Ce,Ee)=>Ce.t-Ee.t||(Ce.series<Ee.series?-1:1)||(Ce.scope<Ee.scope?-1:1));return D.bin?Ke:Ke.map(Ce=>({series:Ce.series,scope:Ce.scope,t:Ce.t,value:Ce.count===1||I.get(Ce.series)!=="gauge"?Ce.sum:Ce.sum/Ce.count}))}let Q=D=>`${D.t}:${D.id}`,te=(D,se)=>{let Me=se.indexOf(":"),Oe=Number(se.slice(0,Me)),ge=se.slice(Me+1);return D.t>Oe||D.t===Oe&&D.id>ge};function ne(D){if(D.bin!=="1h"&&D.bin!=="1d"||(D.where?.all.length??0)||D.q||D.filters?.kind?.length||D.filters?.severity?.length||D.filters?.scope?.length||cn(D.tz,D.from)%es||cn(D.tz,D.to)%es)return;let se=D.filters?.source?.length?new Set(D.filters.source):void 0,Me=A=>Math.max(D.from,oe(A)),{at:Oe,add:ge,rows:ie}=ee(D),Ke=new Set,Ce=new Map,Ee=0,je=(A,Y)=>{let q=yr(Y,D.bin,D.tz),ae=`${A}\0${q}`,m=Ce.get(ae);return m||(m={scope:A,t:q,bin:D.bin,count:0,severity:{},kinds:{}},Ce.set(ae,m)),m},lt=(A,Y,q)=>{let ae=ge(A);ae.count+=q,Ee+=q,(ae.first===void 0||Y<ae.first)&&(ae.first=Y),(ae.last===void 0||Y>ae.last)&&(ae.last=Y)},Ue=Math.floor(D.to/es)*es;for(let[A,Y]of $){let q=Oe(A);if(q!==void 0)for(let[ae,m]of Y){if(se&&!se.has(ae))continue;let C=Math.ceil(Me(ae)/es)*es;for(let[R,G]of m){if(R<C||R>=Ue)continue;lt(q,G.first,G.count),G.last>(ie.get(q).last??-1/0)&&(ie.get(q).last=G.last),Ke.add(ae);let Z=je(q,R);Z.count+=G.count;for(let[$e,de]of Object.entries(G.severity))Z.severity[$e]=(Z.severity[$e]??0)+de;for(let[$e,de]of Object.entries(G.kinds))Z.kinds[$e]=(Z.kinds[$e]??0)+de}}}let dt=A=>En(A.scope,D.scope)&&(!se||se.has(A.source))&&A.t>=oe(A.source)&&Oe(A.scope)!==void 0,ut=A=>{let Y=Oe(A.scope);lt(Y,A.t,1),Ke.add(A.source);let q=je(Y,A.t);q.count++,q.severity[A.severity]=(q.severity[A.severity]??0)+1,q.kinds[A.kind]=(q.kinds[A.kind]??0)+1};for(let A of x){if(se&&!se.has(A))continue;let Y=Me(A),q=Math.ceil(Y/es)*es,ae=q>=Ue?[[Y,D.to]]:[[Y,q],[Ue,D.to]];for(let[m,C]of ae)for(let R=hs(b,m);R<b.length&&b[R].t<C;R++){let G=b[R];G.source===A&&dt(G)&&ut(G)}}let Ae=Bn[D.bin],pt=[];for(let A=hs(w,D.from-M);A<w.length&&w[A].t<D.from;A++){let Y=w[A];Y.t+Y.dur>D.from&&dt(Y)&&(lt(Oe(Y.scope),Y.t,1),Ke.add(Y.source),Y.dur>=Ae&&pt.length<5e3&&pt.push(Y))}for(let A of y.values())A.t<D.from&&c>D.from&&dt(A)&&(lt(Oe(A.scope),A.t,1),Ke.add(A.source),pt.length<5e3&&pt.push(A));for(let A=hs(w,D.from);A<w.length&&w[A].t<D.to&&pt.length<5e3;A++)w[A].dur>=Ae&&dt(w[A])&&pt.push(w[A]);for(let A of y.values())A.t>=D.from&&A.t<D.to&&pt.length<5e3&&dt(A)&&pt.push(A);let et=X(D,Oe,D.from,D.to);for(let A of et){let Y=j.get(A.series);Y&&Ke.add(Y)}let bt=[...Ce.values()].sort((A,Y)=>A.t-Y.t||(A.scope<Y.scope?-1:1));return{timeline:1,type:"result",rows:ue(ie),bins:bt,spans:pt,metrics:et,total:Ee,retention:B(Ke)}}async function fe(D){if(!r(D.scope))throw new Error(`not a scope path: ${JSON.stringify(D.scope)}`);let se=ne(D);if(se)return se;let{test:Me,range:Oe,warnings:ge}=W(D),{at:ie,add:Ke,rows:Ce}=ee(D),Ee=new Set,je=[];for(let et of z(Oe.from,Oe.to)){if(!Me(et))continue;let bt=ie(et.scope);if(bt===void 0)continue;let A=Ke(bt);A.count++,(A.first===void 0||et.t<A.first)&&(A.first=et.t),(A.last===void 0||et.t>A.last)&&(A.last=et.t),Ee.add(et.source),je.push(et)}je.sort(Qa);let lt=X(D,ie,Oe.from,Oe.to);for(let et of lt){let bt=j.get(et.series);bt&&Ee.add(bt)}let Ue={timeline:1,type:"result",total:je.length,...ge.length?{warnings:ge}:{}};if(D.bin){let et=Bn[D.bin],bt=new Map,A=[];for(let q of je){if((q.open||q.dur!==void 0&&q.dur>=et)&&A.length<5e3&&A.push(q),q.t<Oe.from)continue;let ae=ie(q.scope),m=yr(q.t,D.bin,D.tz),C=`${ae}\0${m}`,R=bt.get(C);R||(R={scope:ae,t:m,bin:D.bin,count:0,severity:{},kinds:{}},bt.set(C,R)),R.count++,R.severity[q.severity]=(R.severity[q.severity]??0)+1,R.kinds[q.kind]=(R.kinds[q.kind]??0)+1}let Y=[...bt.values()].sort((q,ae)=>q.t-ae.t||(q.scope<ae.scope?-1:1));return{...Ue,rows:ue(Ce),bins:Y,spans:A,metrics:lt,retention:B(Ee)}}let dt=Math.min(1e4,Math.max(1,D.limit??2e3)),ut=D.cursor?je.findIndex(et=>te(et,D.cursor)):0,Ae=ut<0?[]:je.slice(ut,ut+dt),pt=ut>=0&&ut+dt<je.length;return{...Ue,rows:ue(Ce),events:Ae,metrics:lt,retention:B(Ee),...pt?{next:Q(Ae[Ae.length-1])}:{}}}let be=new Set,we=D=>$n.includes(D),Ne=0;function qe(D){let se=h(D),Me=v.get(se);Me&&(xf(b,Me.t,Oe=>Oe===Me),N(Me,-1),Me.dur!==void 0&&!Me.open&&xf(w,Me.t,Oe=>Oe===Me),y.delete(se)),v.set(se,D),N(D,1),td(b,D,()=>!1,Qa),D.open?y.set(se,D):D.dur!==void 0&&(td(w,D,()=>!1,Qa),M=Math.max(M,D.dur)),P(D.scope)}return{async catalog(){return{...s,now:c,retention:B(s.sources.map(D=>D.name))}},query:fe,subscribe(D,se){let Me={q:D,on:se};return be.add(Me),()=>{be.delete(Me)}},...n.stateAt?{stateAt:(D,se)=>n.stateAt(D,se)}:{},append(D,se=[],Me){Me!==void 0&&(c=Math.max(c,Me));let Oe=new Set(S),ge=D.map(g);for(let ie of ge){if(!we(ie.severity))throw new Error(`not a severity: ${ie.severity}`);qe(ie)}for(let ie of se)k(ie);Ne++;for(let ie of be){let{test:Ke}=W(ie.q),{at:Ce}=ee(ie.q),Ee=ge.filter(Ae=>Ke(Ae)&&Ce(Ae.scope)!==void 0),je=ie.q.series?new Set(ie.q.series):void 0,lt=se.filter(Ae=>En(f(Ae.scope),ie.q.scope)&&(!je||je.has(Ae.series))).map(Ae=>({...Ae,scope:Ce(f(Ae.scope))})),Ue=[...S].filter(Ae=>!Oe.has(Ae)),dt=rn(ie.q.scope)+ie.q.depth,ut=Ue.filter(Ae=>rn(Ae)===dt&&En(Ae,ie.q.scope)).map(Ae=>({scope:Ae,label:p.get(Ae)?.label??Ur(Ae),kind:qr(Ae),depth:ie.q.depth,children:0,count:0}));ie.on({timeline:1,type:"batch",events:Ee,metrics:lt,...ut.length?{rows:ut}:{},now:c,resume:String(Ne)})}},setRetention(D,se){O.set(D,{events:se.events,rollups:{...se.rollups},setBy:"user"})},get now(){return c},get size(){let D=0;for(let se of T.values())D+=se.fine.length;return{events:b.length,samples:D}}}}var kf="http://www.w3.org/2000/svg",vr=22,Za=38,gs=26,Pm=210,Om=24,ei=6e4,kr=36e5,Ln=864e5,Sf={"15m":15*ei,"1h":kr,"1d":Ln,"1w":7*Ln},Mf=t=>$n.indexOf(t),Cm={debug:"dot",info:"circle",notice:"square",warning:"triangle",error:"diamond"},Nt=(t,e,n)=>{let s=document.createElementNS(kf,t);for(let[r,o]of Object.entries(e))o!==void 0&&s.setAttribute(r,String(o));if(n){let r=document.createElementNS(kf,"title");r.textContent=n,s.append(r)}return s},dn=(t,e)=>{try{return new Intl.DateTimeFormat(void 0,{timeZone:e,dateStyle:"medium",timeStyle:"medium"}).format(t)}catch{return new Date(t).toISOString()}},nd=t=>t<1e3?`${Math.round(t)} ms`:t<ei?`${(t/1e3).toFixed(1)} s`:xr(t),Lm=(t,e)=>e==="bytes"?t>=1e9?`${(t/1e9).toFixed(1)} GB`:t>=1e6?`${(t/1e6).toFixed(1)} MB`:t>=1e3?`${(t/1e3).toFixed(1)} kB`:`${Math.round(t)} B`:`${Math.round(t*10)/10}${e==="count"?"":` ${e}`}`;function sd(t,e){if(t<=3*kr)return{kind:"single"};for(let n of["1m","1h","1d"])if(t/Bn[n]<=e/2)return{kind:"binned",bin:n};return{kind:"binned",bin:"1d"}}function rd(t,e,n){let s=[];for(let i of t.events??[])s.push([i.t,i.t]),i.dur!==void 0&&!i.open&&s.push([i.t+i.dur,i.t+i.dur]);for(let i of t.spans??[])s.push([i.t,i.t]),i.dur!==void 0&&!i.open&&s.push([i.t+i.dur,i.t+i.dur]);let r=e.kind==="binned"?Bn[e.bin]:ei;for(let i of t.bins??[])i.count&&s.push([i.t,i.t+Bn[i.bin]]);let o=new Map;for(let i of t.metrics){let a="value"in i?i.value:i.sum,l=`${i.series}|${i.scope}`,c=(n?.get(i.series)??"counter")==="counter"?a!==0:o.get(l)!==a;o.set(l,a),c&&s.push([i.t,i.t+r])}return s}function $f(t,e){let n=e.tz??Intl.DateTimeFormat().resolvedOptions().timeZone,s=typeof matchMedia=="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches,r=e.motion??!s;t.classList.add(...e.rootClass??[],"tlx");let{parseSearch:o,compileSearch:i}=Jr(e.catalog),a=(H="system")=>{t.style.colorScheme=H==="system"?"light dark":H,H==="system"?delete t.dataset.theme:t.dataset.theme=H};a(e.theme),t.setAttribute("role","region"),t.setAttribute("aria-label","Timeline");let l,c="",d=1,u="",f={},p=!1,g=e.collapseGaps??!0,h={t0:0,t1:Ln},b,v="",w={from:0,to:0,mode:{kind:"single"},key:""},M,y,T,S,P=!0,I=0,_=0,O=!1,j,k=[],$=[],x=-1,N=new Set,F=new Map,J=[],oe=Xr(0,Ln,800),ve=new Map,B=[],W=K("nav",{class:"tlx-crumbs","aria-label":"Scope"}),ee=K("div",{class:"segmented tlx-quick",role:"group","aria-label":"Range"});for(let H of["15m","1h","1d","1w","run"]){let pe=K("button",{type:"button",class:"seg","data-v":H,title:H==="run"?"The latest run":`The last ${H}`},H==="run"?"this run":H);pe.addEventListener("click",()=>Ye(H)),ee.append(pe)}let ue=K("button",{type:"button",class:"btn sm tlx-live","aria-pressed":"false",title:"Follow what happens now"},"Live"),z=K("button",{type:"button",class:"btn sm quiet tlx-now",hidden:!0,title:"Back to the live edge"},"Back to now"),X=K("button",{type:"button",class:"btn sm quiet tlx-fit",title:"Everything in this scope"},"Fit"),Q=K("input",{type:"checkbox",class:"tlx-gaps"});Q.checked=g;let te=!0,ne=K("input",{type:"checkbox",class:"tlx-quiet"});ne.checked=te;let fe=K("input",{type:"search",class:"input tlx-q",placeholder:"Search: words, kind:\u2026, source:\u2026, severity:>=warning, -kind:\u2026","aria-label":"Search the timeline",spellcheck:"false"}),be=K("span",{class:"tlx-hits",role:"status","aria-live":"polite"}),we=K("button",{type:"button",class:"btn sm quiet tlx-prev",title:"Previous hit (\u21E7N)","aria-label":"Previous hit"},"\u2039"),Ne=K("button",{type:"button",class:"btn sm quiet tlx-next",title:"Next hit (N)","aria-label":"Next hit"},"\u203A"),qe=K("div",{class:"tlx-facets",role:"group","aria-label":"Sources"}),D=K("select",{class:"input tlx-sev","aria-label":"Severity"},K("option",{value:""},"every severity"),...$n.slice(1).map(H=>K("option",{value:H},`${H} and above`))),se=K("select",{class:"input tlx-views","aria-label":"Saved views",hidden:!e.views},K("option",{value:""},"Saved views\u2026")),Me=K("button",{type:"button",class:"btn sm quiet tlx-save",hidden:!e.saveView,title:"Save this view"},"Save view"),Oe=K("div",{class:"tlx-warn",role:"status",hidden:!0}),ge=K("div",{class:"tlx-status",role:"status"}),ie=K("span",{class:"tlx-canvas-note"}),Ke=K("div",{class:"tlx-labels"}),Ce=K("div",{class:"tlx-lanes",tabindex:"0",role:"application","aria-label":"Timeline lanes: drag to pan, wheel to zoom, drag the axis to choose a range, click it to move the playhead. Keys: \u2190 \u2192 pan, + \u2212 zoom, N next hit"}),Ee=Nt("svg",{class:"tlx-svg"});Ce.append(Ee);let je=K("div",{class:"tlx-scroll"},K("div",{class:"tlx-grid"},Ke,Ce)),lt=K("section",{class:"tlx-table",hidden:!0,"aria-label":"The events in the chosen range"}),Ue=K("aside",{class:"tlx-detail",hidden:!0,"aria-label":"The event"});t.replaceChildren(K("div",{class:"tlx-bar"},W,K("span",{class:"spacer"}),ee,ue,z,X,K("label",{class:"tlx-gaps-label",title:"Draw long empty stretches as narrow breaks"},Q,"Collapse gaps"),K("label",{class:"tlx-gaps-label",title:"Hide the rows with nothing in this range"},ne,"Hide quiet rows")),K("div",{class:"tlx-bar"},fe,be,we,Ne,D,se,Me),qe,Oe,K("div",{class:"tlx-body"},je,Ue),K("div",{class:"tlx-foot"},ge,K("span",{class:"spacer"}),ie),lt);let dt=()=>Math.max(200,Ce.clientWidth||800),ut=()=>{let H=(Ie,ot)=>(Ie.own?-1:0)-(ot.own?-1:0)||Ie.scope.localeCompare(ot.scope,void 0,{numeric:!0}),ke=(b?.rows??[]).filter(Ie=>!te||Ie.count>0||Ie.own||(b?.rows.length??0)<=1).sort(H).map(Ie=>({kind:"row",row:Ie})),Te=new Set(b?.metrics.map(Ie=>Ie.series)??[]);for(let Ie of[...Te].sort()){let ot=ve.get(Ie);ke.push({kind:"metric",series:Ie,unit:ot?.unit??"count",type:ot?.type??"counter",title:ot?.title??Ie})}return ke},Ae=(H,pe)=>l?.names?.find(ke=>ke.scope===H)?.label??pe,pt=H=>H.kind==="metric"?Za:vr,et=()=>sd(h.t1-h.t0,dt()),bt=()=>l?.now??Date.now();function A(){return{timeline:1,type:"view",name:"",scope:c,depth:d,range:{from:Math.round(h.t0),to:Math.round(h.t1)},...u?{q:u}:{},...Object.keys(f).length?{filters:f}:{},...p?{live:p}:{},...g?{}:{collapseGaps:!1},...te?{}:{quietRows:!0}}}function Y(H){H.scope!==void 0&&(c=H.scope),H.depth!==void 0&&(d=H.depth),u=H.q??"",fe.value=u,f=H.filters??{},D.value=f.severity?.length?f.severity[0]:"",g=H.collapseGaps??e.collapseGaps??!0,Q.checked=g,te=!H.quietRows,ne.checked=te,N.clear(),F.clear();let pe=H.range;pe&&"last"in pe?Ye(pe.last,!1):pe&&(h={t0:pe.from,t1:pe.to}),Pt(!!H.live,!1)}let q=()=>{let H=A();if(e.onViewChange?.(H),!!e.urlState)try{history.replaceState(null,"",`#timeline=${encodeURIComponent(JSON.stringify(H))}`)}catch{}},ae=()=>{if(!e.urlState)return;let H=/#timeline=(.+)$/.exec(location.hash);if(H)try{return JSON.parse(decodeURIComponent(H[1]))}catch{return}};function m(H,pe,ke,Te={}){let Ie=i(u,bt(),H,pe);k=Ie.warnings;let ot=u?[]:f.source?[...ve].filter(([,kt])=>f.source.includes(kt.source)).map(([kt])=>kt):void 0;return{timeline:1,type:"query",scope:c,depth:d,from:Ie.from,to:Ie.to,tz:n,...ke.kind==="binned"?{bin:ke.bin}:{},...u?{q:u,where:Ie.where}:{},...Object.keys(f).length?{filters:f}:{},...ot?{series:ot}:{},...Te}}let C=()=>JSON.stringify([c,d,u,f,et()]);async function R(H=!1){let pe=et(),ke=C(),Te=h.t1-h.t0;if(!H&&b&&ke===w.key&&h.t0>=w.from&&h.t1<=w.to){Z();return}if(_){O=!0;return}_++;let Ie=h.t0-Te/2,ot=Math.min(h.t1+Te/2,Math.max(h.t1,bt()+Te*.1));try{let kt=await e.source.query(m(Ie,ot,pe,pe.kind==="single"?{limit:1e4}:{}));pe.kind==="single"&&kt.next&&(kt=await e.source.query(m(Ie,ot,{kind:"binned",bin:"1m"}))),b=kt,v=ke,w={from:Ie,to:ot,mode:pe,key:ke}}catch(kt){ge.textContent=`The history couldn't be read: ${String(kt?.message??kt)}`}finally{_--}Z(),q(),O&&(O=!1,R())}function G(){let H=dt(),pe=et();if(J=[],g&&b){let ke=new Map([...ve].map(([Te,Ie])=>[Te,Ie.type]));J=Ua(rd(b,pe,ke),h.t0,Math.min(h.t1,Math.max(h.t0,bt())),{minFrac:.15,minMs:10*ei}),pe.kind==="binned"&&(J=J.filter(Te=>Te.to-Te.from>=2*Bn[pe.bin])),J=J.filter(Te=>!(N.has(wr(Te))&&(F.get(wr(Te))??1)>=1))}oe=Xr(h.t0,h.t1,H,J,{cut:Om,weights:F})}let Z=()=>{I||(I=requestAnimationFrame($e))};function $e(){I=0,G();let H=dt(),pe=ut(),ke=w.mode,Te=[],Ie=gs;for(let xe of pe)Te.push(Ie),Ie+=pt(xe);let ot=Math.max(Ie,gs+vr);Ee.setAttribute("width",String(H)),Ee.setAttribute("height",String(ot)),Ee.setAttribute("viewBox",`0 0 ${H} ${ot}`);let kt=je.scrollTop-200,An=je.scrollTop+(je.clientHeight||600)+200,Xe=[],Qe=oe.x;Xe.push(Nt("rect",{class:"tlx-axis",x:0,y:0,width:H,height:gs}));let Qt=(b?.retention??[]).map(xe=>({r:xe,from:ke.kind==="binned"?xe.keptFrom.rollups[ke.bin]??xe.keptFrom.events:xe.keptFrom.events,days:ke.kind==="binned"?xe.rollups[ke.bin]:xe.events})).filter(xe=>xe.from!==void 0);if(Qt.length){let xe=Math.min(...Qt.map(Fe=>Fe.from));xe>h.t0&&Xe.push(Nt("rect",{class:"tlx-notkept",x:Math.max(0,Qe(h.t0)),y:gs,width:Math.max(0,Qe(xe)-Math.max(0,Qe(h.t0))),height:ot-gs},`Nothing kept before ${dn(xe,n)}: ${Qt.map(Fe=>`${Fe.r.source} ${Fe.days===null?"kept until deleted":`kept ${Fe.days} days`}`).join(", ")}`))}let nn=bt();nn<h.t1&&Xe.push(Nt("rect",{class:"tlx-future",x:Qe(nn),y:gs,width:H-Qe(nn),height:ot-gs}));for(let xe of Wa(oe,n,90)){Xe.push(Nt("line",{class:`tlx-tick${xe.major?" major":""}`,x1:xe.x,x2:xe.x,y1:gs-6,y2:ot}));let Fe=Nt("text",{class:"tlx-ticklabel",x:xe.x+3,y:16});Fe.textContent=xe.label,Xe.push(Fe)}S&&Xe.push(Nt("rect",{class:"tlx-brush",x:Qe(S.from),y:0,width:Math.max(1,Qe(S.to)-Qe(S.from)),height:ot}));let Ar=ke.kind==="single"?(b?.events??[]).filter(xe=>xe.dur!==void 0||xe.open):b?.spans??[],Pl=ke.kind==="single"?(b?.events??[]).filter(xe=>xe.dur===void 0&&!xe.open):[],ui=new Map;pe.forEach((xe,Fe)=>{xe.kind==="row"&&ui.set(xe.row.scope,Fe)});let lr=xe=>{let Fe=rn(c)+d,at=rn(xe)>=Fe?Ls(xe,Fe):xe;return ui.get(at)},rs=xe=>Te[xe]+pt(pe[xe])>=kt&&Te[xe]<=An;if(pe.forEach((xe,Fe)=>{rs(Fe)&&Xe.push(Nt("rect",{class:`tlx-lane${Fe%2?" odd":""}${xe.kind==="metric"?" metric":""}`,x:0,y:Te[Fe],width:H,height:pt(xe)}))}),ke.kind==="binned"){let xe=new Map;for(let Fe of b?.bins??[]){let at=lr(Fe.scope);at!==void 0&&xe.set(at,Math.max(xe.get(at)??0,Fe.count))}for(let Fe of b?.bins??[]){let at=lr(Fe.scope);if(at===void 0||!rs(at))continue;let wt=Qe(Fe.t),mt=Qe(Fe.t+Bn[Fe.bin]);if(mt<0||wt>H)continue;let Ot=[...$n].reverse().find(mn=>(Fe.severity[mn]??0)>0)??"info",Zt=Math.max(2,(vr-8)*Math.sqrt(Fe.count)/Math.sqrt(xe.get(at)||1));Xe.push(Nt("rect",{class:"tlx-countbar",x:wt,y:Te[at]+vr-3-Zt,width:Math.max(1,mt-wt-.5),height:Zt,"data-t":Fe.t},`${dn(Fe.t,n)}: ${Fe.count} event${Fe.count===1?"":"s"}${Ot!=="info"&&Ot!=="debug"?`, the worst ${Ot}`:""}`)),(Ot==="warning"||Ot==="error")&&Xe.push(Nt("rect",{class:`tlx-heat sev-${Ot}`,x:wt,y:Te[at]+vr-(Ot==="error"?4:3),width:Math.max(1,mt-wt-.5),height:Ot==="error"?3:2}))}}for(let xe of Ar){let Fe=lr(xe.scope);if(Fe===void 0||!rs(Fe))continue;let at=xe.open?nn:xe.t+(xe.dur??0),wt=Qe(xe.t),mt=Qe(at);if(mt<-2||wt>H+2)continue;let Ot=`tlx-span sev-${xe.severity}${xe.open?" open":""}${T?.id===xe.id?" selected":""}`,Zt=`${xe.summary} \xB7 ${dn(xe.t,n)}${xe.open?", still going":`, ${nd(at-xe.t)}`}`,mn=Te[Fe]+5,sn=ke.kind==="binned"?4:8,hn=wt;for(let Sn of oe.cuts)Sn.weight>=1||Sn.x1<=wt||Sn.x0>=mt||(Sn.x0>hn&&Xe.push(Nt("rect",{class:Ot,x:hn,y:mn,width:Math.max(1,Sn.x0-hn),height:sn,rx:2,"data-id":xe.id},Zt)),Xe.push(Nt("path",{class:`${Ot} through`,d:`M${Sn.x0} ${mn+sn/2} H${Sn.x1}`,"data-id":xe.id},`${Zt} (lasted through the break)`)),hn=Sn.x1);mt>hn&&Xe.push(Nt("rect",{class:Ot,x:Math.max(-2,hn),y:mn,width:Math.max(2,Math.min(H+2,mt)-Math.max(-2,hn)),height:sn,rx:2,"data-id":xe.id},Zt))}let kn=new Map;for(let xe of Pl){let Fe=lr(xe.scope);if(Fe===void 0||!rs(Fe))continue;let at=Qe(xe.t);if(at<-6||at>H+6||at-(kn.get(Fe)??-1/0)<3)continue;kn.set(Fe,at);let wt=Te[Fe]+vr/2+2,mt=4,Ot=Cm[xe.severity],Zt=Ot==="diamond"?`M${at} ${wt-mt-1} l${mt+1} ${mt+1} l${-mt-1} ${mt+1} l${-mt-1} ${-mt-1} z`:Ot==="triangle"?`M${at} ${wt-mt-1} l${mt+1} ${2*mt+1} h${-2*mt-2} z`:Ot==="square"?`M${at-mt+.5} ${wt-mt+.5} h${2*mt-1} v${2*mt-1} h${-2*mt+1} z`:"",mn=`${dn(xe.t,n)} \xB7 ${xe.summary}`,sn=`tlx-mark sev-${xe.severity}${T?.id===xe.id?" selected":""}${x>=0&&$[x]?.id===xe.id?" hit":""}`;Xe.push(Zt?Nt("path",{class:sn,d:Zt,"data-id":xe.id},mn):Nt("circle",{class:sn,cx:at,cy:wt,r:Ot==="dot"?2.5:mt,"data-id":xe.id},mn))}pe.forEach((xe,Fe)=>{if(xe.kind!=="metric"||!rs(Fe))return;let at=new Map;for(let Mt of b?.metrics??[]){if(Mt.series!==xe.series)continue;let Vt="value"in Mt?{min:Mt.value,max:Mt.value,sum:Mt.value,count:1}:{min:Mt.min,max:Mt.max,sum:Mt.sum,count:Mt.count},$t=at.get(Mt.t);$t?($t.min=Math.min($t.min,Vt.min),$t.max=Math.max($t.max,Vt.max),$t.sum+=Vt.sum,$t.count+=Vt.count):at.set(Mt.t,{...Vt})}let wt=[...at].sort((Mt,Vt)=>Mt[0]-Vt[0]);if(!wt.length)return;let mt=ke.kind==="binned"?Bn[ke.bin]:ei,Ot=Mt=>xe.type==="gauge"?Mt.sum/Math.max(1,Mt.count):Mt.sum,Zt=Math.max(1e-9,...wt.map(([,Mt])=>xe.type==="gauge"?Mt.max:Ot(Mt))),mn=Te[Fe]+Za-4,sn=Za-10,hn=Mt=>mn-Mt/Zt*sn;if(xe.type==="gauge"){let Mt=wt.map(([Vt,$t])=>`${Qe(Vt)},${hn($t.max)}`).join(" ")+" "+[...wt].reverse().map(([Vt,$t])=>`${Qe(Vt)},${hn($t.min)}`).join(" ");Xe.push(Nt("polygon",{class:"tlx-band",points:Mt})),Xe.push(Nt("polyline",{class:"tlx-line",points:wt.map(([Vt,$t])=>`${Qe(Vt+mt/2)},${hn(Ot($t))}`).join(" ")}))}else{let Mt="",Vt=-1/0;for(let[$t,Vn]of wt){let fo=Qe($t),ws=Qe($t+mt),po=hn(Ot(Vn));Mt+=$t>Vt?`M${fo} ${mn} V${po} H${ws}`:` V${po} H${ws}`,Vt=$t+mt;let _s=wt.find(([fi])=>fi>$t);(!_s||_s[0]>Vt)&&(Mt+=` V${mn} Z`)}Xe.push(Nt("path",{class:"tlx-area",d:Mt}))}let Sn=Nt("text",{class:"tlx-peak",x:4,y:Te[Fe]+11});Sn.textContent=`peak ${Lm(Zt,xe.unit)}${xe.type==="counter"?` per ${ke.kind==="binned"?ke.bin:"1m"}`:""}`,Xe.push(Sn)});for(let xe of oe.cuts){if(xe.weight>=1)continue;let Fe=mt=>{let Ot=`M${mt} 0`;for(let Zt=0;Zt<ot;Zt+=8)Ot+=` L${mt+(Zt/8%2?-3:3)} ${Zt+8}`;return Ot},at=Nt("g",{class:"tlx-cut",tabindex:0,role:"button","data-from":xe.from,"data-to":xe.to,"aria-label":`A break of ${xr(xe.to-xe.from)} with nothing shown, from ${dn(xe.from,n)} to ${dn(xe.to,n)}: press to open it`},`${xr(xe.to-xe.from)} with nothing here: ${dn(xe.from,n)} to ${dn(xe.to,n)} (click to open)`);at.append(Nt("rect",{class:"tlx-cut-bg",x:xe.x0,y:0,width:xe.x1-xe.x0,height:ot})),at.append(Nt("path",{class:"tlx-cut-edge",d:Fe(xe.x0+3)}),Nt("path",{class:"tlx-cut-edge",d:Fe(xe.x1-3)}));let wt=Nt("text",{class:"tlx-cut-label",x:(xe.x0+xe.x1)/2,y:15,"text-anchor":"middle"});wt.textContent=xr(xe.to-xe.from),at.append(wt),Xe.push(at)}if(M!==void 0){let xe=Qe(M);Xe.push(Nt("line",{class:"tlx-playhead",x1:xe,x2:xe,y1:0,y2:ot})),Xe.push(Nt("path",{class:"tlx-handle",d:`M${xe-6} 0 h12 v8 l-6 7 l-6 -7 z`},`the playhead: ${dn(M,n)}`))}Ee.replaceChildren(...Xe),Ke.replaceChildren(K("div",{class:"tlx-labelhead",style:`height:${gs}px`},et().kind==="single"?"single events":`per ${et().kind==="binned"?et().bin:""}`),...pe.map(xe=>{if(xe.kind==="metric")return K("div",{class:"tlx-rowlabel metric",style:`height:${Za}px`,title:`${xe.title} (${xe.type==="counter"?"sums":"min, max and mean"})`},xe.title);let Fe=xe.row,at=K("div",{class:`tlx-rowlabel${Fe.own?" own":""}`,style:`height:${vr}px`,"data-scope":Fe.scope,title:`${Fe.scope||"all hosts"} \xB7 ${Fe.count} event${Fe.count===1?"":"s"}`},K("span",{class:"tlx-kind"},e.catalog.flags.find(wt=>Fe[wt])??Fe.kind),K("span",{class:"tlx-name"},Fe.own?`${Fe.label} (itself)`:Fe.label),K("span",{class:"tlx-count"},String(Fe.count)));if(!Fe.own&&Fe.scope!==c){let wt=K("button",{type:"button",class:"tlx-drill",title:Fe.children?`Into ${Fe.label}: its ${Fe.children} part${Fe.children===1?"":"s"}`:`Into ${Fe.label}`,"aria-label":`Into ${Fe.label}`},"\u203A");wt.addEventListener("click",()=>Et(Fe.scope)),at.append(wt)}return at})),Ke.style.width=`${Pm}px`,de()}function de(){W.replaceChildren(...Wr(c).flatMap((Te,Ie,ot)=>{let kt=K("button",{type:"button",class:`tlx-crumb${Ie===ot.length-1?" current":""}`,"aria-current":Ie===ot.length-1?"location":void 0},Ae(Te.scope,Te.label));return kt.addEventListener("click",()=>{Te.scope!==c&&(c=Te.scope,d=1,R(!0))}),Ie?[K("span",{class:"tlx-sep","aria-hidden":"true"},"/"),kt]:[kt]})),ue.setAttribute("aria-pressed",String(p)),ue.classList.toggle("on",p),z.hidden=!p||P;let H=et(),pe=b?.total??0,ke=(b?.retention??[]).filter(Te=>Te.events!==null).map(Te=>`${Te.source} kept ${Te.events} d`);ge.textContent=`${dn(h.t0,n)} \u2013 ${dn(h.t1,n)} \xB7 ${H.kind==="single"?"single events":`bins of ${H.bin}`} \xB7 ${pe} event${pe===1?"":"s"}${J.length?` \xB7 ${J.length} break${J.length===1?"":"s"}`:""}${ke.length?` \xB7 ${ke.slice(0,3).join(", ")}`:""}`,Oe.hidden=!k.length,Oe.textContent=k.join(" \xB7 "),be.textContent=u?$.length?`${x+1>0?`${x+1} of `:""}${$.length}${$.length>=2e3?"+":""} hit${$.length===1?"":"s"}`:`${pe?`${pe} hit${pe===1?"":"s"}`:"no hits"}`:"";for(let Te of ee.querySelectorAll(".seg"))Te.classList.remove("on");ie.textContent=M===void 0?"":y?(()=>{let Te=e.stamp?.(y)??{};return`Canvas: the state recorded at ${dn(Date.parse(Te.at??"")||M,n)}${Te.tag?` (${Te.tag})`:""}`})():"No state recorded here",ie.classList.toggle("none",M!==void 0&&!y)}function De(){qe.replaceChildren();for(let H of l?.sources??[]){let pe=!f.source?.length||f.source.includes(H.name),ke=K("button",{type:"button",class:`tlx-chip${pe?" on":""}${H.status==="not-yet"?" notyet":""}`,"aria-pressed":String(pe&&H.status!=="not-yet"),disabled:H.status==="not-yet",title:H.status==="not-yet"?`${H.title}: not kept yet`:`${H.title}${He(H)}`},H.name);H.status!=="not-yet"&&ke.addEventListener("click",()=>Re(H.name)),qe.append(ke)}}let He=H=>{let pe=l?.retention.find(ke=>ke.source===H.name);return pe?` (kept ${pe.events===null?"until deleted":`${pe.events} days`})`:""};function Re(H){let pe=(l?.sources??[]).filter(Te=>Te.status==="kept").map(Te=>Te.name),ke=f.source?.length?[...f.source]:[...pe];ke=ke.includes(H)?ke.filter(Te=>Te!==H):[...ke,H],f={...f,...ke.length===pe.length?{source:void 0}:{source:ke}},f.source||delete f.source,De(),R(!0),nt()}let ze=0;fe.addEventListener("input",()=>{clearTimeout(ze),ze=setTimeout(()=>{u=fe.value.trim(),x=-1,R(!0),nt()},250)}),fe.addEventListener("keydown",H=>{H.key==="Enter"&&(H.preventDefault(),clearTimeout(ze),u=fe.value.trim(),R(!0).then(()=>nt()).then(()=>st(H.shiftKey?-1:1)))});async function nt(){if(!u){$=[],x=-1,de();return}let H=h.t1-h.t0;$=(await e.source.query(m(h.t0-H*4,Math.max(h.t1+H*4,bt()),{kind:"single"},{limit:2e3}))).events??[],x=Math.min(x,$.length-1),de()}function st(H){if(!$.length)return;let pe=(h.t0+h.t1)/2;x<0?x=H>0?Math.max(0,$.findIndex(Ie=>Ie.t>=pe)):Math.max(0,$.length-1-[...$].reverse().findIndex(Ie=>Ie.t<=pe)):x=(x+H+$.length)%$.length;let ke=$[x],Te=Math.min(h.t1-h.t0,2*kr);h={t0:ke.t-Te/2,t1:ke.t+Te/2},P=!1,St(ke),R()}we.addEventListener("click",()=>st(-1)),Ne.addEventListener("click",()=>st(1)),D.addEventListener("change",()=>{let H=D.value;f={...f,...H?{severity:$n.filter(pe=>Mf(pe)>=Mf(H))}:{}},H||delete f.severity,R(!0),nt()});async function Ye(H,pe=!0){let ke=bt();if(H==="run"){let Te=await e.source.query({timeline:1,type:"query",scope:c,depth:0,from:ke-30*Ln,to:ke+1,filters:{kind:["run"]},limit:1e4}).catch(()=>{}),Ie=Te?.events?.[Te.events.length-1];h=Ie?{t0:Ie.t-(Ie.dur??kr)*.02,t1:(Ie.open?ke:Ie.t+(Ie.dur??kr))+(Ie.dur??kr)*.04}:{t0:ke-Ln,t1:ke+Ln*.02}}else h={t0:ke-Sf[H],t1:ke+Sf[H]*.02};P=!0,N.clear(),F.clear(),pe&&R()}function Pt(H,pe=!0){if(p=H,j?.(),j=void 0,H&&e.source.subscribe){let ke=0,Te=0;j=e.source.subscribe(m(bt()-kr,bt()+365*Ln,{kind:"single"}),Ie=>{if(l&&(l.now=Math.max(l.now,Ie.now)),P){let kt=h.t1-h.t0;h={t0:Ie.now-kt*.98,t1:Ie.now+kt*.02}}let ot=Date.now();ot-ke>500?(ke=ot,R(!0)):Te||(Te=setTimeout(()=>{Te=0,ke=Date.now(),R(!0)},500))}),P=!0}pe&&(de(),q())}ue.addEventListener("click",()=>Pt(!p)),z.addEventListener("click",()=>{P=!0;let H=h.t1-h.t0,pe=bt();h={t0:pe-H*.98,t1:pe+H*.02},R()}),X.addEventListener("click",()=>{yt()}),Q.addEventListener("change",()=>{g=Q.checked,N.clear(),F.clear(),Z(),q()}),ne.addEventListener("change",()=>{te=ne.checked,Z(),q()});function Et(H){let pe=b?.rows.find(ke=>ke.scope===H);c=H,d=pe&&pe.children===0?0:1,S=void 0,lt.hidden=!0,R(!0)}async function yt(){let H=bt(),ke=((await e.source.query({timeline:1,type:"query",scope:c,depth:0,from:H-400*Ln,to:H+1,bin:"1d",tz:n}).catch(()=>{}))?.bins??[]).map(Ie=>Ie.t),Te=ke.length?Math.min(...ke):H-7*Ln;h={t0:Te,t1:H+(H-Te)*.02},P=!0,R()}let wn=0;async function Xt(H){if(M=H,Z(),H===void 0){y=void 0;return}let pe=++wn,ke=e.source.stateAt?await e.source.stateAt(c,H).catch(()=>{}):void 0;pe===wn&&(y=ke,e.onPlayhead?.(H,ke),de())}async function Ht(H,pe){S={from:Math.min(H,pe),to:Math.max(H,pe)},Z();let ke=await e.source.query(m(S.from,S.to,{kind:"single"},{limit:500})),Te=o(u),Ie=Xe=>{let Qe=[],Ft=0;for(let[Qt,nn]of Zo(Te,Xe))Qe.push(Xe.slice(Ft,Qt),K("mark",null,Xe.slice(Qt,nn))),Ft=nn;return Qe.push(Xe.slice(Ft)),Qe},ot=(ke.events??[]).map(Xe=>{let Qe=K("tr",{"data-id":Xe.id,tabindex:"0"},K("td",null,dn(Xe.t,n)),K("td",null,Xe.dur!==void 0?nd(Xe.dur):Xe.open?"still going":""),K("td",null,Xe.source),K("td",null,Xe.kind),K("td",{class:`sev-${Xe.severity}`},Xe.severity),K("td",{class:"tlx-sum"},...Ie(Xe.summary)),K("td",{class:"tlx-scope"},Xe.scope));return Qe.addEventListener("click",()=>St(Xe)),Qe.addEventListener("keydown",Ft=>{Ft.key==="Enter"&&St(Xe)}),Qe}),kt=K("button",{type:"button",class:"btn sm quiet","aria-label":"Close the table"},"Close");kt.addEventListener("click",()=>{S=void 0,lt.hidden=!0,Z()});let An=Xe=>{let Qe=K("button",{type:"button",class:"btn sm","data-export":Xe},Xe.toUpperCase());return Qe.addEventListener("click",()=>{zt(Xe)}),Qe};lt.replaceChildren(K("div",{class:"tlx-table-head"},K("strong",null,`${ke.total} event${ke.total===1?"":"s"}`),K("span",null,` ${dn(S.from,n)} \u2013 ${dn(S.to,n)}${ke.total>500?" (the first 500 shown; the export has them all)":""}`),K("span",{class:"spacer"}),K("span",null,"Export: "),An("json"),An("csv"),kt),K("div",{class:"tlx-table-wrap"},K("table",null,K("thead",null,K("tr",null,...["When","Long","Source","Kind","Severity","What","Scope"].map(Xe=>K("th",{scope:"col"},Xe)))),K("tbody",null,...ot)))),lt.hidden=!1}async function Wt(){if(!S)return[];let H=[],pe;do{let ke=await e.source.query(m(S.from,S.to,{kind:"single"},{limit:1e4,...pe?{cursor:pe}:{}}));H.push(...ke.events??[]),pe=ke.next}while(pe&&H.length<2e5);return H}async function zt(H){let pe=await Wt(),ke=H==="json"?Ja(pe,B):Xa(pe,B),Te=`timeline-${new Date(S.from).toISOString().slice(0,16).replace(/:/g,"")}.${H}`,Ie=H==="json"?"application/json":"text/csv";if(e.onExport){e.onExport(Te,ke,Ie);return}let ot=K("a",{href:`data:${Ie};charset=utf-8,${encodeURIComponent(ke)}`,download:Te});document.body.append(ot),ot.click(),ot.remove()}function St(H){if(T=H,Z(),!H){Ue.hidden=!0;return}let pe=l?.sources.find(Qe=>Qe.name===H.source),ke=new Set(pe?.sensitive??[]),Te=o(u),Ie=Qe=>{let Ft=[],Qt=0;for(let[nn,Ar]of Zo(Te,Qe))Ft.push(Qe.slice(Qt,nn),K("mark",null,Qe.slice(nn,Ar))),Qt=Ar;return Ft.push(Qe.slice(Qt)),Ft},ot=(Qe,Ft)=>{if(!Ft)return null;let Qt=K("button",{type:"button",class:"btn sm"},Qe);return Qt.addEventListener("click",Ft),Qt},kt=Object.entries(H.attrs).map(([Qe,Ft])=>{if(!ke.has(Qe))return K("tr",null,K("th",{scope:"row"},Qe),K("td",null,...Ie(String(Ft))));let Qt=K("button",{type:"button",class:"btn sm quiet",title:"This can name a remote host, a folder or free text"},"Show"),nn=K("td",{class:"tlx-sensitive"},"hidden ",Qt);return Qt.addEventListener("click",()=>nn.replaceChildren(String(Ft))),K("tr",null,K("th",{scope:"row"},Qe),nn)}),An=K("button",{type:"button",class:"btn sm quiet tlx-close","aria-label":"Close"},"\xD7");An.addEventListener("click",()=>St(void 0));let Xe=Wr(H.scope).slice(1).map(Qe=>{let Ft=K("button",{type:"button",class:"tlx-crumb"},Ae(Qe.scope,Qe.label));return Ft.addEventListener("click",()=>Et(Qe.scope)),Ft});Ue.replaceChildren(K("div",{class:"tlx-detail-head"},K("strong",null,H.kind),An),K("p",{class:`tlx-sev sev-${H.severity}`},`${H.severity} \xB7 ${pe?.title??H.source}`),K("p",{class:"tlx-sum"},...Ie(H.summary)),K("p",null,dn(H.t,n),H.dur!==void 0?` \xB7 ${nd(H.dur)}${H.open?" so far":""}`:H.open?" \xB7 still going":""),K("p",{class:"tlx-crumbs small"},...Xe),...kt.length?[K("table",{class:"tlx-attrs"},K("tbody",null,...kt))]:[],K("div",{class:"tlx-links"},...(e.actions?.(H)??[]).map(([Qe,Ft])=>ot(Qe,Ft)))),Ue.hidden=!1}function zn(H,pe){let ke=wr({from:H,to:pe});if(!J.find(kt=>kt.from===H&&kt.to===pe))return;if(N.add(ke),!r){F.set(ke,1),Z();return}let Ie=performance.now(),ot=kt=>{let An=Math.min(1,(kt-Ie)/260);F.set(ke,1-(1-An)**3),$e(),An<1&&requestAnimationFrame(ot)};requestAnimationFrame(ot)}let Ct,ss=H=>H.clientX-Ee.getBoundingClientRect().left;Ee.addEventListener("pointerdown",H=>{let pe=ss(H),ke=H.clientY-Ee.getBoundingClientRect().top,Te=H.target.closest?.(".tlx-cut");if(Te){H.preventDefault(),zn(Number(Te.getAttribute("data-from")),Number(Te.getAttribute("data-to")));return}Ee.setPointerCapture(H.pointerId),Ct={kind:ke<gs||H.shiftKey?"brush":H.target.classList.contains("tlx-handle")?"scrub":"pan",x0:pe,t0:oe.t(pe),v0:h,moved:!1},H.preventDefault(),Ce.focus({preventScroll:!0})}),Ee.addEventListener("pointermove",H=>{if(!Ct)return;let pe=ss(H);if(Math.abs(pe-Ct.x0)>3&&(Ct.moved=!0),!!Ct.moved)if(Ct.kind==="pan"){let ke=(Ct.x0-pe)*oe.msPerPx;h={t0:Ct.v0.t0+ke,t1:Ct.v0.t1+ke},P=!1,R()}else Ct.kind==="scrub"?Xt(oe.t(pe)):(S={from:Math.min(Ct.t0,oe.t(pe)),to:Math.max(Ct.t0,oe.t(pe))},Z())}),Ee.addEventListener("pointerup",H=>{let pe=Ct;if(Ct=void 0,!pe)return;let ke=ss(H);if(pe.kind==="brush"&&pe.moved){Ht(pe.t0,oe.t(ke));return}if(pe.kind==="brush"&&!pe.moved){Xt(oe.t(ke));return}if(pe.kind==="pan"&&!pe.moved){let Te=H.target.closest?.("[data-id]")?.getAttribute("data-id"),Ie=Te?[...b?.events??[],...b?.spans??[]].find(ot=>ot.id===Te):void 0;Ie?(St(Ie),Xt(Ie.t)):Xt(oe.t(ke))}}),Ee.addEventListener("keydown",H=>{let pe=H.target.closest?.(".tlx-cut");pe&&(H.key==="Enter"||H.key===" ")&&(H.preventDefault(),zn(Number(pe.getAttribute("data-from")),Number(pe.getAttribute("data-to"))))}),Ee.addEventListener("wheel",H=>{H.preventDefault();let pe=ss(H);if(H.shiftKey||Math.abs(H.deltaX)>Math.abs(H.deltaY)){let ke=(H.shiftKey?H.deltaY:H.deltaX)*oe.msPerPx;h={t0:h.t0+ke,t1:h.t1+ke},P=!1}else xs(oe.t(pe),Math.exp(H.deltaY*.0015),pe/dt());R()},{passive:!1});function xs(H,pe,ke=.5){let Te=Math.min(400*Ln,Math.max(1e4,(h.t1-h.t0)*pe));h={t0:H-ke*Te,t1:H+(1-ke)*Te},N.clear(),F.clear(),pe<1&&(P=p&&h.t1>=bt())}Ce.addEventListener("keydown",H=>{let pe=h.t1-h.t0;if(H.key==="ArrowLeft"||H.key==="ArrowRight"){let ke=pe*.15*(H.key==="ArrowLeft"?-1:1);h={t0:h.t0+ke,t1:h.t1+ke},P=!1}else if(H.key==="+"||H.key==="=")xs((h.t0+h.t1)/2,.6);else if(H.key==="-"||H.key==="_")xs((h.t0+h.t1)/2,1/.6);else if(H.key==="n"||H.key==="N"){st(H.shiftKey?-1:1),H.preventDefault();return}else if(H.key==="Escape")St(void 0),S=void 0,lt.hidden=!0;else return;H.preventDefault(),R()}),t.addEventListener("keydown",H=>{H.key==="/"&&document.activeElement!==fe&&!H.target.closest("input, select, textarea")&&(H.preventDefault(),fe.focus())}),je.addEventListener("scroll",()=>Z(),{passive:!0}),Me.addEventListener("click",async()=>{let H=`${Wr(c).slice(-1)[0].label}${u?`: ${u}`:""}`.slice(0,80);await e.saveView?.({...A(),name:H}),await vn()});let it=[];async function vn(){e.views&&(it=await e.views(),se.replaceChildren(K("option",{value:""},"Saved views\u2026"),...it.map((H,pe)=>K("option",{value:String(pe)},H.name))))}se.addEventListener("change",()=>{let H=it[Number(se.value)];H&&(Y(H),De(),R(!0)),se.value=""});let Tt=typeof ResizeObserver=="function"?new ResizeObserver(()=>Z()):void 0;Tt?.observe(Ce);let tn=(async()=>{l=await e.source.catalog(),B=l.sources.flatMap(Te=>(Te.sensitive??[]).map(Ie=>`${Te.name}.${Ie}`));for(let Te of l.sources)for(let Ie of Te.series)ve.set(Ie.name,{unit:Ie.unit,type:Ie.type,title:Ie.title,source:Te.name});c=l.hosts.length===1?`host:${l.hosts[0].replace(/[%/:\s]/g,Te=>`%${Te.charCodeAt(0).toString(16).toUpperCase().padStart(2,"0")}`)}`:"";let pe=l.now;h={t0:pe-Ln,t1:pe+Ln*.02};let ke=ae()??e.view;ke&&Y(ke),De(),await vn(),await R(!0),u&&await nt()})();return{el:t,ready:tn,get view(){return A()},setView(H){return Y(H),De(),R(!0)},setRange(H,pe){return h={t0:H,t1:pe},P=!1,R()},setPlayhead:Xt,setLive:Pt,setTheme:a,refresh:()=>R(!0),internal:{get result(){return b},get mode(){return et()},get scale(){return oe},get gaps(){return J},get playState(){return y},get hits(){return $},get selected(){return T},get follow(){return P},openCut:zn,showTable:Ht,rangeEvents:Wt,exportRange:zt,select:St,stepHit:st,drill:Et,findHits:nt,paint:$e,lines:ut},dispose(){j?.(),Tt?.disconnect(),I&&cancelAnimationFrame(I),t.replaceChildren()}}}var Nm={arrow:{d:"M0,0 L10,5 L0,10 z",refX:9},open:{d:"M0,0 L10,5 L0,10 L3,5 z",refX:9},diamond:{d:"M0,5 L5,1.5 L10,5 L5,8.5 z",refX:1}},un=t=>(Math.round(t*10)/10).toString(),Ef=t=>(t??"link").replace(/[^\w-]/g,"_");function Qr(t,e){let{id:n}=e,s=e.styles??{},r=t.options,o=t.bounds,i=new Map,a=(p,g)=>{let h=s[p]??{},b=g==="start"?h.start??"none":h.end??"arrow";if(b!=="none")return(i.get(p)??i.set(p,new Set).get(p)).add(b),`url(#${n}-mk-${p}-${b})`},l="",c="",d="",u="";for(let p of[...t.panels].sort((g,h)=>g.depth-h.depth)){let g=p.rect,h=p.label?_e("text",{class:"pl",x:p.titleAt[0],y:p.titleAt[1]},Kt(p.label)+(p.sub?_e("tspan",{class:"pls",dx:10},Kt(p.sub)):"")):"";l+=_e("g",{class:`panel k-${p.role??"grey"}`,"data-id":p.id},_e("rect",{class:"face",x:un(g.l),y:un(g.t),width:un(g.r-g.l),height:un(g.b-g.t),rx:r.panelRx})+h)}for(let p of t.links){if(!p.points.length)continue;let g=Ef(p.kind);c+=_e("path",{class:`conn k-${g}`,d:"M"+p.points.map(h=>`${un(h[0])},${un(h[1])}`).join(" L"),"data-id":p.id,"data-a":p.a,"data-b":p.b,"marker-start":a(g,"start"),"marker-end":a(g,"end")}),p.at&&(u+=_e("text",{class:`cl k-${g}`,x:p.at.x,y:p.at.y,"text-anchor":p.at.anchor==="start"?void 0:p.at.anchor,"data-for":p.id},Kt(p.at.text)))}for(let p of t.cards){let g=p.rect;d+=_e("g",{class:`card k-${p.role??"grey"}${p.ghost?" ghost":""}`,"data-id":p.id,tabindex:0,role:"button","aria-label":p.sub?`${p.label}: ${p.sub}`:p.label},_e("rect",{class:"face",x:un(g.l),y:un(g.t),width:r.W,height:r.H,rx:r.cardRx})+_e("text",{class:"lt",x:un(g.l+14),y:un(g.t+24)},Kt(p.label))+(p.sub?_e("text",{class:"st",x:un(g.l+14),y:un(g.t+42)},Kt(p.sub)):""))}let f="";for(let[p,g]of i)for(let h of g){let b=Nm[h];f+=_e("marker",{id:`${n}-mk-${p}-${h}`,viewBox:"0 0 10 10",refX:b.refX,refY:5,markerWidth:5.4,markerHeight:5.4,orient:"auto-start-reverse"},_e("path",{d:b.d,class:`mk k-${p}`}))}return _e("svg",{xmlns:"http://www.w3.org/2000/svg",class:"flat",viewBox:`${un(o.l)} ${un(o.t)} ${un(o.r-o.l)} ${un(o.b-o.t)}`,role:"img","aria-label":e.title??"drawing, flat view","data-view":"2d"},(f?_e("defs",{},f):"")+_e("g",{class:"panels"},l)+_e("g",{class:"conns"},c)+_e("g",{class:"cards"},d)+_e("g",{class:"labels"},u))}function Tf(t={}){let e=s=>s?s.startsWith("#")||s.includes("(")?s:`var(--${s})`:"var(--ink)",n=`
|
|
360
360
|
.flat{font-family:inherit}
|
|
361
361
|
.flat .card{cursor:pointer;outline:none}
|
|
362
362
|
.flat .card .face{fill:hsl(var(--h) var(--s) var(--l-top));stroke:hsl(var(--h) var(--s) var(--l-edge) / .55);stroke-width:1}
|
|
@@ -374,8 +374,8 @@ ${e.extraBody??""}
|
|
|
374
374
|
.flat .panel.sel .face{stroke:var(--accent,#2f6fd6);stroke-width:2}
|
|
375
375
|
.flat .conn.hot{stroke-width:3}
|
|
376
376
|
.flat .conn.dim,.flat .cl.dim{opacity:.3}
|
|
377
|
-
`;for(let[s,r]of Object.entries(t)){let o=
|
|
378
|
-
`}return n}var cm={name:["card","lt"],sub:["card","st"],title:["panel","pl"],titleSub:["panel","pls"],label:["","cl"]};function zr(t){let e="http://www.w3.org/2000/svg",n=document.createElementNS(e,"svg");n.setAttribute("class","flat"),n.setAttribute("aria-hidden","true"),n.style.cssText="position:absolute;left:-10000px;top:0;width:10px;height:10px;visibility:hidden",t.appendChild(n);let s={};for(let[i,[a,l]]of Object.entries(cm)){let c=document.createElementNS(e,"g");a&&c.setAttribute("class",a);let d=document.createElementNS(e,"text");d.setAttribute("class",l),c.appendChild(d),n.appendChild(c),s[i]=d}let r=new Map,o=((i,a)=>{let l=a+"\0"+i,c=r.get(l);return c===void 0&&(s[a].textContent=i,c=s[a].getComputedTextLength(),r.set(l,c)),c});return o.dispose=()=>n.remove(),o}var sf=(t,e)=>t.cards.find(n=>n.id===e)?.rect??t.panels.find(n=>n.id===e)?.rect;var _s="http://www.w3.org/2000/svg";function Vr(t,e,n){let s=new Map((n?.links??[]).map((r,o)=>[r.id??`link-${o}`,r]));for(let r of e.routes){let o=s.get(r.id),i=o?.a??wn(r.raw.from).id,a=o?.b??wn(r.raw.to).id;for(let l of t.querySelectorAll(`[data-id="${CSS.escape(r.id)}"]`))l.setAttribute("data-a",i),l.setAttribute("data-b",a)}}var dm=(t="auto")=>t==="always"||t==="auto"&&!(typeof matchMedia=="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches);function ja(t,e,n,s,r={}){let o=r.duration??600;if(!o||!dm(r.motion))return;let i=_c(t,e,n,s);t.appendChild(i.svg),i.at(0);let a=0,l=!1,c,d=new Promise(g=>c=g),u=()=>{l||(l=!0,cancelAnimationFrame(a),i.svg.remove(),c())},f=performance.now(),p=g=>{if(l)return;let h=Math.min(1,(g-f)/o);i.at(h),h<1?a=requestAnimationFrame(p):u()};return a=requestAnimationFrame(p),{done:d,finish:u}}var ur=t=>Math.max(0,Math.min(1,t)),Kc=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2;function Fa(t){let e=t.cloneNode(!0),n=[t,...t.querySelectorAll("*")],s=[e,...e.querySelectorAll("*")];return n.forEach((r,o)=>{let i=getComputedStyle(r),a=s[o];a.removeAttribute("class"),a.removeAttribute("tabindex");for(let l of["fill","fill-opacity","stroke","stroke-width","stroke-dasharray","stroke-opacity","opacity","font-size","font-weight","font-family","letter-spacing","paint-order","stroke-linejoin","text-anchor"])a.style.setProperty(l,i.getPropertyValue(l))}),e}var Bc=(t,e)=>{let n=t.getBoundingClientRect();return{x:n.left-e.left,y:n.top-e.top,w:n.width,h:n.height}},rf=t=>{let e=Math.min(...t.map(o=>o.x)),n=Math.min(...t.map(o=>o.y)),s=Math.max(...t.map(o=>o.x+o.w)),r=Math.max(...t.map(o=>o.y+o.h));return{x:e,y:n,w:s-e,h:r-n}},um=(t,e)=>{let n=t.getScreenCTM();return`matrix(${n.a} ${n.b} ${n.c} ${n.d} ${n.e-e.left} ${n.f-e.top})`},of=(t,e,n)=>{let s=1+(e.w/Math.max(t.w,1e-6)-1)*n,r=1+(e.h/Math.max(t.h,1e-6)-1)*n,o=(e.x-t.x*(e.w/Math.max(t.w,1e-6)))*n,i=(e.y-t.y*(e.h/Math.max(t.h,1e-6)))*n;return`matrix(${s} 0 0 ${r} ${o} ${i})`};function fm(t,e){let n=t.querySelector("polygon.top");if(!n)return;let s=n.getScreenCTM(),r=[];for(let o=0;o<n.points.numberOfItems;o++){let i=n.points.getItem(o);r.push([s.a*i.x+s.c*i.y+s.e-e.left,s.b*i.x+s.d*i.y+s.f-e.top])}return r.length===4?{pts:r,fill:getComputedStyle(n).fill}:void 0}function _c(t,e,n,s){let r=t.getBoundingClientRect(),o=document.createElementNS(_s,"svg");o.setAttribute("class","dual-morph"),o.setAttribute("aria-hidden","true"),o.style.cssText=`position:absolute;left:0;top:0;width:${r.width}px;height:${Math.max(r.height,e.getBoundingClientRect().height,n.getBoundingClientRect().height)}px;overflow:visible;pointer-events:none`;let i=T=>{let y=document.createElementNS(_s,"g");return y.setAttribute("transform",um(T,r)),y},a=T=>T.hasAttribute("data-a")||T.hasAttribute("data-for"),l=T=>{let y=new Map;for(let A of T.querySelectorAll("[data-id]")){if(a(A)||A.parentElement?.closest("[data-id]")||A.closest(".overlay"))continue;let D=A.getAttribute("data-id");(y.get(D)??y.set(D,[]).get(D)).push(A)}return y},c=l(e),d=l(n),u=document.createElementNS(_s,"g"),f=document.createElementNS(_s,"g"),p=i(e),g=i(n);for(let T of e.querySelectorAll("[data-a],[data-for]"))T.closest(".overlay")||p.appendChild(Fa(T));for(let T of n.querySelectorAll("[data-a],[data-for]"))T.closest(".overlay")||g.appendChild(Fa(T));u.appendChild(p),f.appendChild(g);let h=[...g.querySelectorAll("path")].map(T=>{let y=T.getTotalLength?.()??0;return{p:T,len:y}}),b=[...g.children].filter(T=>T.tagName.toLowerCase()==="text"),k=[...(s==="2d"?c:d).keys()],v=[],M=document.createElementNS(_s,"g");for(let T of new Set([...k,...c.keys(),...d.keys()])){let y=c.get(T),A=d.get(T),D={};if(y){D.a=rf(y.map(N=>Bc(N,r)));let $=document.createElementNS(_s,"g"),w=i(e);for(let N of y)w.appendChild(Fa(N));$.appendChild(w),D.src=$}if(A){D.b=rf(A.map(N=>Bc(N,r)));let $=document.createElementNS(_s,"g"),w=i(n);for(let N of A)w.appendChild(Fa(N));$.appendChild(w),D.dst=$}let K=s==="3d"?y?.[0]:A?.[0],C=s==="3d"?A?.[0]:y?.[0],_=K?fm(K,r):void 0,S=C?.querySelector("rect.face");if(_&&S){let $=Bc(S,r),w=[[$.x,$.y],[$.x+$.w,$.y],[$.x+$.w,$.y+$.h],[$.x,$.y+$.h]],N=_.pts.reduce((j,U,ee)=>U[0]<_.pts[j][0]?ee:j,0),F=[..._.pts.slice(N),..._.pts.slice(0,N)],J=[F[0],F[1],F[2],F[3]],ae=getComputedStyle(S).fill,we=document.createElementNS(_s,"polygon");D.face=we,D.faceFrom=s==="3d"?J:w,D.faceTo=s==="3d"?w:J,D.faceFill=s==="3d"?[_.fill,ae]:[ae,_.fill]}D.src&&M.appendChild(D.src),D.face&&M.appendChild(D.face),D.dst&&M.appendChild(D.dst),v.push(D)}o.append(u,M,f);let x=(T,y,A)=>`color-mix(in srgb, ${T} ${Math.round((1-A)*100)}%, ${y})`;return{svg:o,at(T){let y=ur(T/.2),A=Kc(ur((T-.2)/.6)),D=ur((T-.8)/.2);u.setAttribute("opacity",String(1-y));for(let{p:K,len:C}of h)K.style.strokeDasharray=`${C} ${C}`,K.style.strokeDashoffset=String(C*(1-D));f.setAttribute("opacity",String(D>0?1:0));for(let K of b)K.style.opacity=String(D);for(let K of v)if(K.src&&(K.src.setAttribute("transform",K.a&&K.b?of(K.a,K.b,A):""),K.src.setAttribute("opacity",String(K.b?1-ur(A/(K.face?.35:.6)):1-A))),K.dst&&(K.dst.setAttribute("transform",K.a&&K.b?of(K.b,K.a,1-A):""),K.dst.setAttribute("opacity",String(K.a?ur((A-(K.face?.65:.4))/(K.face?.35:.6)):A))),K.face){let C=K.faceFrom.map((_,S)=>[_[0]+(K.faceTo[S][0]-_[0])*A,_[1]+(K.faceTo[S][1]-_[1])*A]);K.face.setAttribute("points",C.map(_=>_.join(",")).join(" ")),K.face.style.fill=x(K.faceFill[0],K.faceFill[1],A),K.face.setAttribute("opacity",String(A<.08?A/.08:A>.92?(1-A)/.08:1))}}}}var pm=0;function af(t,e,n={}){let s=`dv${++pm}`,r=document.createElement("div");r.className="dual-view",r.style.position="relative",t.appendChild(r);let o=document.createElement("div"),i=document.createElement("div");o.className="dual-3d",i.className="dual-2d",r.append(o,i),o.innerHTML=e.rendered.svg;let a=o.querySelector("svg");a.setAttribute("data-view","3d");let l=n.board??or(e);Vr(a,e,l);let c=new Set(e.routes.map(C=>C.id));for(let C of a.querySelectorAll("g[data-id]")){let _=C.getAttribute("data-id");c.has(_)||C.hasAttribute("tabindex")||!C.querySelector("polygon")||(C.setAttribute("tabindex","0"),C.setAttribute("role","button"),C.setAttribute("aria-label",_))}let d=zr(i),u=Fs(l,d,n.flat);d.dispose(),i.innerHTML=_r(u,{id:s,title:n.title,styles:n.styles});let f=i.querySelector("svg");for(let C of[a,f])C.style.display="block",C.style.width="100%",C.style.height="auto";n.title&&a.setAttribute("aria-label",n.title);let p=n.mode??"3d",g,h=C=>C==="3d"?o:i,b=C=>C==="3d"?a:f,k=C=>{o.hidden=C!=="3d",i.hidden=C!=="2d";for(let _ of[o,i])_.style.cssText="";r.style.height="",r.dataset.mode=C};k(p);let v=()=>{for(let C of[a,f]){for(let _ of C.querySelectorAll("[data-id]"))_.classList.toggle("sel",!!g&&_.getAttribute("data-id")===g);for(let _ of C.querySelectorAll("[data-a]")){let S=!!g&&(_.getAttribute("data-a")===g||_.getAttribute("data-b")===g);_.classList.toggle("hot",S),_.classList.toggle("dim",!!g&&!S),C.querySelector(`[data-for="${CSS.escape(_.getAttribute("data-id")??"")}"]`)?.classList.toggle("dim",!!g&&!S)}}},M=C=>{g=C,v()},x=C=>{let _=C.target.closest?.("[data-id]");if(!_||!r.contains(_)||_.hasAttribute("data-a"))return;let S=_.getAttribute("data-id");M(S),n.onSelect?.(S)},T=C=>{(C.key==="Enter"||C.key===" ")&&C.target.matches?.("[data-id][tabindex]")&&(C.preventDefault(),x(C))};r.addEventListener("click",x),r.addEventListener("keydown",T);let y,A=()=>{if(!y)return;cancelAnimationFrame(y.frame),y.layer.remove();let C=y;y=void 0,p=C.to,k(p),v(),C.done()},D=C=>{!C||!g||b(p).querySelector(`[data-id="${CSS.escape(g)}"][tabindex]`)?.focus({preventScroll:!0})};return{get mode(){return y?y.to:p},layout:u,root:r,morph:C=>{let _=r.contains(document.activeElement);if(y&&A(),C===p)return D(_),Promise.resolve();let S=n.motion??"auto";return S==="never"||S==="auto"&&typeof matchMedia=="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches||!(n.duration??600)?(p=C,k(p),v(),D(_),Promise.resolve()):new Promise(w=>{let N=p,F=r.getBoundingClientRect().height;o.hidden=!1,i.hidden=!1;for(let fe of[o,i])fe.style.cssText="position:absolute;left:0;top:0;right:0;visibility:hidden";let J=h(C).getBoundingClientRect().height;r.style.height=`${F}px`;let ae=_c(r,b(N),b(C),N);r.appendChild(ae.svg);let we=n.duration??600,j=performance.now(),U={frame:0,layer:ae.svg,to:C,done:()=>{D(_),w()}},ee=fe=>{if(y!==U)return;let B=Math.min(1,(fe-j)/we);ae.at(B),r.style.height=`${F+(J-F)*Kc(ur((B-.2)/.6))}px`,B<1?U.frame=requestAnimationFrame(ee):A()};y=U,U.frame=requestAnimationFrame(ee)})},select:M,get selected(){return g},svgOf:b,destroy(){y&&A(),r.removeEventListener("click",x),r.removeEventListener("keydown",T),r.remove()}}}function lf(t="iso-view"){try{let e=localStorage.getItem(t);return e==="2d"||e==="3d"?e:void 0}catch{return}}function cf(t,e,n={}){let s=n.storageKey??"iso-view",r=Array.isArray(e)?e:[e],o=document.createElement("div");o.className="view-switch",o.setAttribute("role","group"),o.setAttribute("aria-label","Drawing view");let i=["3d","2d"].map((l,c)=>{let d=document.createElement("button");return d.type="button",d.dataset.mode=l,d.textContent=(n.labels??["3D","2D"])[c],d.addEventListener("click",()=>{try{localStorage.setItem(s,l)}catch{}a(l);for(let u of r)u.morph(l)}),o.appendChild(d),d}),a=l=>i.forEach(c=>c.setAttribute("aria-pressed",String(c.dataset.mode===l)));return a(r[0]?.mode??"3d"),t.appendChild(o),o}var df=`
|
|
377
|
+
`;for(let[s,r]of Object.entries(t)){let o=Ef(s),i=e(r.color);n+=`.flat .conn.k-${o}{stroke:${i}${r.dash?`;stroke-dasharray:${r.dash}`:""}${r.width?`;stroke-width:${r.width}`:""}} .flat .mk.k-${o}{fill:${i}} .flat .cl.k-${o}{fill:${i}}
|
|
378
|
+
`}return n}var Rm={name:["card","lt"],sub:["card","st"],title:["panel","pl"],titleSub:["panel","pls"],label:["","cl"]};function Zr(t){let e="http://www.w3.org/2000/svg",n=document.createElementNS(e,"svg");n.setAttribute("class","flat"),n.setAttribute("aria-hidden","true"),n.style.cssText="position:absolute;left:-10000px;top:0;width:10px;height:10px;visibility:hidden",t.appendChild(n);let s={};for(let[i,[a,l]]of Object.entries(Rm)){let c=document.createElementNS(e,"g");a&&c.setAttribute("class",a);let d=document.createElementNS(e,"text");d.setAttribute("class",l),c.appendChild(d),n.appendChild(c),s[i]=d}let r=new Map,o=((i,a)=>{let l=a+"\0"+i,c=r.get(l);return c===void 0&&(s[a].textContent=i,c=s[a].getComputedTextLength(),r.set(l,c)),c});return o.dispose=()=>n.remove(),o}var Af=(t,e)=>t.cards.find(n=>n.id===e)?.rect??t.panels.find(n=>n.id===e)?.rect;var er="http://www.w3.org/2000/svg";function eo(t,e,n){let s=new Map((n?.links??[]).map((r,o)=>[r.id??`link-${o}`,r]));for(let r of e.routes){let o=s.get(r.id),i=o?.a??On(r.raw.from).id,a=o?.b??On(r.raw.to).id;for(let l of t.querySelectorAll(`[data-id="${CSS.escape(r.id)}"]`))l.setAttribute("data-a",i),l.setAttribute("data-b",a)}}var Im=(t="auto")=>t==="always"||t==="auto"&&!(typeof matchMedia=="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches);function tl(t,e,n,s,r={}){let o=r.duration??600;if(!o||!Im(r.motion))return;let i=ni(t,e,n,s);t.appendChild(i.svg),i.at(0);let a=0,l=!1,c,d=new Promise(g=>c=g),u=()=>{l||(l=!0,cancelAnimationFrame(a),i.svg.remove(),c())},f=performance.now(),p=g=>{if(l)return;let h=Math.min(1,(g-f)/o);i.at(h),h<1?a=requestAnimationFrame(p):u()};return a=requestAnimationFrame(p),{done:d,finish:u}}var Ns=t=>Math.max(0,Math.min(1,t)),ti=t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2;function el(t){let e=t.cloneNode(!0),n=[t,...t.querySelectorAll("*")],s=[e,...e.querySelectorAll("*")];return n.forEach((r,o)=>{let i=getComputedStyle(r),a=s[o];a.removeAttribute("class"),a.removeAttribute("tabindex");for(let l of["fill","fill-opacity","stroke","stroke-width","stroke-dasharray","stroke-opacity","opacity","font-size","font-weight","font-family","letter-spacing","paint-order","stroke-linejoin","text-anchor"])a.style.setProperty(l,i.getPropertyValue(l))}),e}var od=(t,e)=>{let n=t.getBoundingClientRect();return{x:n.left-e.left,y:n.top-e.top,w:n.width,h:n.height}},Pf=t=>{let e=Math.min(...t.map(o=>o.x)),n=Math.min(...t.map(o=>o.y)),s=Math.max(...t.map(o=>o.x+o.w)),r=Math.max(...t.map(o=>o.y+o.h));return{x:e,y:n,w:s-e,h:r-n}},Dm=(t,e)=>{let n=t.getScreenCTM();return`matrix(${n.a} ${n.b} ${n.c} ${n.d} ${n.e-e.left} ${n.f-e.top})`},Of=(t,e,n)=>{let s=1+(e.w/Math.max(t.w,1e-6)-1)*n,r=1+(e.h/Math.max(t.h,1e-6)-1)*n,o=(e.x-t.x*(e.w/Math.max(t.w,1e-6)))*n,i=(e.y-t.y*(e.h/Math.max(t.h,1e-6)))*n;return`matrix(${s} 0 0 ${r} ${o} ${i})`};function Fm(t,e){let n=t.querySelector("polygon.top");if(!n)return;let s=n.getScreenCTM(),r=[];for(let o=0;o<n.points.numberOfItems;o++){let i=n.points.getItem(o);r.push([s.a*i.x+s.c*i.y+s.e-e.left,s.b*i.x+s.d*i.y+s.f-e.top])}return r.length===4?{pts:r,fill:getComputedStyle(n).fill}:void 0}function ni(t,e,n,s){let r=t.getBoundingClientRect(),o=document.createElementNS(er,"svg");o.setAttribute("class","dual-morph"),o.setAttribute("aria-hidden","true"),o.style.cssText=`position:absolute;left:0;top:0;width:${r.width}px;height:${Math.max(r.height,e.getBoundingClientRect().height,n.getBoundingClientRect().height)}px;overflow:visible;pointer-events:none`;let i=T=>{let S=document.createElementNS(er,"g");return S.setAttribute("transform",Dm(T,r)),S},a=T=>T.hasAttribute("data-a")||T.hasAttribute("data-for"),l=T=>{let S=new Map;for(let P of T.querySelectorAll("[data-id]")){if(a(P)||P.parentElement?.closest("[data-id]")||P.closest(".overlay"))continue;let I=P.getAttribute("data-id");(S.get(I)??S.set(I,[]).get(I)).push(P)}return S},c=l(e),d=l(n),u=document.createElementNS(er,"g"),f=document.createElementNS(er,"g"),p=i(e),g=i(n);for(let T of e.querySelectorAll("[data-a],[data-for]"))T.closest(".overlay")||p.appendChild(el(T));for(let T of n.querySelectorAll("[data-a],[data-for]"))T.closest(".overlay")||g.appendChild(el(T));u.appendChild(p),f.appendChild(g);let h=[...g.querySelectorAll("path")].map(T=>{let S=T.getTotalLength?.()??0;return{p:T,len:S}}),b=[...g.children].filter(T=>T.tagName.toLowerCase()==="text"),v=[...(s==="2d"?c:d).keys()],w=[],M=document.createElementNS(er,"g");for(let T of new Set([...v,...c.keys(),...d.keys()])){let S=c.get(T),P=d.get(T),I={};if(S){I.a=Pf(S.map(N=>od(N,r)));let $=document.createElementNS(er,"g"),x=i(e);for(let N of S)x.appendChild(el(N));$.appendChild(x),I.src=$}if(P){I.b=Pf(P.map(N=>od(N,r)));let $=document.createElementNS(er,"g"),x=i(n);for(let N of P)x.appendChild(el(N));$.appendChild(x),I.dst=$}let _=s==="3d"?S?.[0]:P?.[0],O=s==="3d"?P?.[0]:S?.[0],j=_?Fm(_,r):void 0,k=O?.querySelector("rect.face");if(j&&k){let $=od(k,r),x=[[$.x,$.y],[$.x+$.w,$.y],[$.x+$.w,$.y+$.h],[$.x,$.y+$.h]],N=j.pts.reduce((B,W,ee)=>W[0]<j.pts[B][0]?ee:B,0),F=[...j.pts.slice(N),...j.pts.slice(0,N)],J=[F[0],F[1],F[2],F[3]],oe=getComputedStyle(k).fill,ve=document.createElementNS(er,"polygon");I.face=ve,I.faceFrom=s==="3d"?J:x,I.faceTo=s==="3d"?x:J,I.faceFill=s==="3d"?[j.fill,oe]:[oe,j.fill]}I.src&&M.appendChild(I.src),I.face&&M.appendChild(I.face),I.dst&&M.appendChild(I.dst),w.push(I)}o.append(u,M,f);let y=(T,S,P)=>`color-mix(in srgb, ${T} ${Math.round((1-P)*100)}%, ${S})`;return{svg:o,at(T){let S=Ns(T/.2),P=ti(Ns((T-.2)/.6)),I=Ns((T-.8)/.2);u.setAttribute("opacity",String(1-S));for(let{p:_,len:O}of h)_.style.strokeDasharray=`${O} ${O}`,_.style.strokeDashoffset=String(O*(1-I));f.setAttribute("opacity",String(I>0?1:0));for(let _ of b)_.style.opacity=String(I);for(let _ of w)if(_.src&&(_.src.setAttribute("transform",_.a&&_.b?Of(_.a,_.b,P):""),_.src.setAttribute("opacity",String(_.b?1-Ns(P/(_.face?.35:.6)):1-P))),_.dst&&(_.dst.setAttribute("transform",_.a&&_.b?Of(_.b,_.a,1-P):""),_.dst.setAttribute("opacity",String(_.a?Ns((P-(_.face?.65:.4))/(_.face?.35:.6)):P))),_.face){let O=_.faceFrom.map((j,k)=>[j[0]+(_.faceTo[k][0]-j[0])*P,j[1]+(_.faceTo[k][1]-j[1])*P]);_.face.setAttribute("points",O.map(j=>j.join(",")).join(" ")),_.face.style.fill=y(_.faceFill[0],_.faceFill[1],P),_.face.setAttribute("opacity",String(P<.08?P/.08:P>.92?(1-P)/.08:1))}}}}var jm=0;function Cf(t,e,n={}){let s=`dv${++jm}`,r=document.createElement("div");r.className="dual-view",r.style.position="relative",t.appendChild(r);let o=document.createElement("div"),i=document.createElement("div");o.className="dual-3d",i.className="dual-2d",r.append(o,i),o.innerHTML=e.rendered.svg;let a=o.querySelector("svg");a.setAttribute("data-view","3d");let l=n.board??br(e);eo(a,e,l);let c=new Set(e.routes.map(O=>O.id));for(let O of a.querySelectorAll("g[data-id]")){let j=O.getAttribute("data-id");c.has(j)||O.hasAttribute("tabindex")||!O.querySelector("polygon")||(O.setAttribute("tabindex","0"),O.setAttribute("role","button"),O.setAttribute("aria-label",j))}let d=Zr(i),u=Js(l,d,n.flat);d.dispose(),i.innerHTML=Qr(u,{id:s,title:n.title,styles:n.styles});let f=i.querySelector("svg");for(let O of[a,f])O.style.display="block",O.style.width="100%",O.style.height="auto";n.title&&a.setAttribute("aria-label",n.title);let p=n.mode??"3d",g,h=O=>O==="3d"?o:i,b=O=>O==="3d"?a:f,v=O=>{o.hidden=O!=="3d",i.hidden=O!=="2d";for(let j of[o,i])j.style.cssText="";r.style.height="",r.dataset.mode=O};v(p);let w=()=>{for(let O of[a,f]){for(let j of O.querySelectorAll("[data-id]"))j.classList.toggle("sel",!!g&&j.getAttribute("data-id")===g);for(let j of O.querySelectorAll("[data-a]")){let k=!!g&&(j.getAttribute("data-a")===g||j.getAttribute("data-b")===g);j.classList.toggle("hot",k),j.classList.toggle("dim",!!g&&!k),O.querySelector(`[data-for="${CSS.escape(j.getAttribute("data-id")??"")}"]`)?.classList.toggle("dim",!!g&&!k)}}},M=O=>{g=O,w()},y=O=>{let j=O.target.closest?.("[data-id]");if(!j||!r.contains(j)||j.hasAttribute("data-a"))return;let k=j.getAttribute("data-id");M(k),n.onSelect?.(k)},T=O=>{(O.key==="Enter"||O.key===" ")&&O.target.matches?.("[data-id][tabindex]")&&(O.preventDefault(),y(O))};r.addEventListener("click",y),r.addEventListener("keydown",T);let S,P=()=>{if(!S)return;cancelAnimationFrame(S.frame),S.layer.remove();let O=S;S=void 0,p=O.to,v(p),w(),O.done()},I=O=>{!O||!g||b(p).querySelector(`[data-id="${CSS.escape(g)}"][tabindex]`)?.focus({preventScroll:!0})};return{get mode(){return S?S.to:p},layout:u,root:r,morph:O=>{let j=r.contains(document.activeElement);if(S&&P(),O===p)return I(j),Promise.resolve();let k=n.motion??"auto";return k==="never"||k==="auto"&&typeof matchMedia=="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches||!(n.duration??600)?(p=O,v(p),w(),I(j),Promise.resolve()):new Promise(x=>{let N=p,F=r.getBoundingClientRect().height;o.hidden=!1,i.hidden=!1;for(let ue of[o,i])ue.style.cssText="position:absolute;left:0;top:0;right:0;visibility:hidden";let J=h(O).getBoundingClientRect().height;r.style.height=`${F}px`;let oe=ni(r,b(N),b(O),N);r.appendChild(oe.svg);let ve=n.duration??600,B=performance.now(),W={frame:0,layer:oe.svg,to:O,done:()=>{I(j),x()}},ee=ue=>{if(S!==W)return;let z=Math.min(1,(ue-B)/ve);oe.at(z),r.style.height=`${F+(J-F)*ti(Ns((z-.2)/.6))}px`,z<1?W.frame=requestAnimationFrame(ee):P()};S=W,W.frame=requestAnimationFrame(ee)})},select:M,get selected(){return g},svgOf:b,destroy(){S&&P(),r.removeEventListener("click",y),r.removeEventListener("keydown",T),r.remove()}}}function Lf(t="iso-view"){try{let e=localStorage.getItem(t);return e==="2d"||e==="3d"?e:void 0}catch{return}}function Nf(t,e,n={}){let s=n.storageKey??"iso-view",r=Array.isArray(e)?e:[e],o=document.createElement("div");o.className="view-switch",o.setAttribute("role","group"),o.setAttribute("aria-label","Drawing view");let i=["3d","2d"].map((l,c)=>{let d=document.createElement("button");return d.type="button",d.dataset.mode=l,d.textContent=(n.labels??["3D","2D"])[c],d.addEventListener("click",()=>{try{localStorage.setItem(s,l)}catch{}a(l);for(let u of r)u.morph(l)}),o.appendChild(d),d}),a=l=>i.forEach(c=>c.setAttribute("aria-pressed",String(c.dataset.mode===l)));return a(r[0]?.mode??"3d"),t.appendChild(o),o}var Rf=`
|
|
379
379
|
.view-switch{display:inline-flex;border:1px solid var(--line);border-radius:8px;overflow:hidden;background:var(--surface);font:600 12px/1 system-ui,sans-serif;box-shadow:0 1px 4px rgba(0,0,0,.12)}
|
|
380
380
|
.view-switch button{font:inherit;border:0;background:none;color:var(--ink);padding:6px 10px;cursor:pointer}
|
|
381
381
|
.view-switch button+button{border-left:1px solid var(--line)}
|
|
@@ -385,14 +385,14 @@ ${e.extraBody??""}
|
|
|
385
385
|
.dual-view .blk.sel polygon{stroke:var(--accent,#2f6fd6);stroke-width:2.4}
|
|
386
386
|
.dual-view [data-a].dim{opacity:.3}
|
|
387
387
|
.dual-view [data-a].hot path{stroke-width:3.4}
|
|
388
|
-
`;var
|
|
389
|
-
`))return{path:[...r,
|
|
390
|
-
`,e-1)+1,r=n.slice(s,e),o=/[A-Za-z0-9_.:\/{}*~$-]*$/.exec(r)[0].replace(/^[{[,]/,""),i=e-o.length,a=
|
|
391
|
-
`,o-1)+1,a=r.slice(i,o);if(o=i-1,!a.trim()||/^\s*#/.test(a))continue;let l=/^\s*/.exec(a)[0].length;if(l===n&&!s){let c=i+l+(a.slice(l).startsWith("- ")?2:0),d=t.at(c);if(d.where==="key"||a.slice(l).startsWith("- "))return d.path.slice(0,-1)}if(l<n||s&&l<=n&&/:\s*$/.test(a)){let c=/^(\s*)(- )?([^\s:#][^:#]*?)\s*:/.exec(a);if(c){let d=t.at(i+c[1].length+(c[2]?2:0));if(d.where==="key")return d.path}if(/^\s*- /.test(a)){let d=t.at(i+l+2),u=d.path.length-1;for(;u>=0&&typeof d.path[u]!="number";)u--;return u>=0?d.path.slice(0,u+1):d.path}if(l<n)return[]}if(l===0&&n===0)return[]}return[]}function
|
|
392
|
-
`,e-1)+1,
|
|
393
|
-
`,e);return n<0?t.length:n},
|
|
394
|
-
`,e);return n<0?t.length:n+1},
|
|
395
|
-
`?r-1:r;return
|
|
388
|
+
`;var ep={};hi(ep,{EditorDoc:()=>Nn,EditorModel:()=>oo,HISTORY_DEPTH:()=>dd,PLAIN_ICONS:()=>Xf,PLAIN_ICON_SVG:()=>uo,PLAIN_KEYMAP:()=>Al,PLAIN_SPRITE:()=>Qf,PLAIN_WORDS:()=>gd,PREF:()=>ii,PROTOCOL:()=>Wf,SchemaNav:()=>io,SpliceError:()=>bn,TYPING_PAUSE_MS:()=>Yf,VIEWS:()=>jf,actionsFor:()=>Ml,analyse:()=>pl,applyStep:()=>yn,ask:()=>$r,canvasView:()=>Tl,chain:()=>ns,clipboard:()=>kl,clipboardFor:()=>dl,closeMenu:()=>xl,cmSnippet:()=>zf,commandsFor:()=>lo,complete:()=>ul,completionContext:()=>nl,composite:()=>Er,deleteAt:()=>js,docFor:()=>ml,flatCanvas:()=>qf,flatten:()=>fd,flowText:()=>fn,fromPointer:()=>rt,icon:()=>Ut,iconSymbols:()=>ci,insertItem:()=>oi,insertKey:()=>Tn,insertRawPair:()=>cl,invertStep:()=>ol,isMessage:()=>Jf,isPrefix:()=>qt,isTyping:()=>or,keySheet:()=>vl,keymapWith:()=>wl,later:()=>ir,layer:()=>rr,mdRuns:()=>Vf,menuOpen:()=>Hf,mountEditor:()=>Uf,moveKey:()=>ll,namesIn:()=>ud,openMenu:()=>ys,outline:()=>fl,pairText:()=>ro,parentOf:()=>Df,place:()=>pd,problemRange:()=>bl,propsPanel:()=>El,providersFor:()=>hl,rangeOfPath:()=>gl,renameKey:()=>sr,run:()=>xn,samePath:()=>Ff,scalarText:()=>ts,scopeCss:()=>yd,scopeOne:()=>bd,seqCmd:()=>ai,setLayer:()=>Mr,setValue:()=>Fs,setupFor:()=>Zf,spriteOf:()=>di,toPointer:()=>Se,treeView:()=>Sl});var Bm=t=>String(t).replace(/~/g,"~0").replace(/\//g,"~1"),Se=t=>t.map(e=>"/"+Bm(e)).join("");function rt(t){return t?t.split("/").slice(1).map(e=>{let n=e.replace(/~1/g,"/").replace(/~0/g,"~");return/^\d+$/.test(n)?Number(n):n}):[]}var Df=t=>t.length?t.slice(0,-1):void 0,qt=(t,e)=>t.length<=e.length&&t.every((n,s)=>String(n)===String(e[s])),Ff=(t,e)=>t.length===e.length&&qt(t,e);var Nn=class{text;doc;lines;constructor(e){this.text=e,this.lines=new Ts,this.doc=ln(e,{keepSourceTokens:!0,lineCounter:this.lines,prettyErrors:!1,uniqueKeys:!1})}get ok(){return this.doc.errors.length===0}get data(){try{return this.doc.toJS()}catch{return}}pos(e){return this.lines.linePos(e)}offset(e,n){return(this.lines.lineStarts[e-1]??this.text.length)+n-1}rangeOf(e,n="value"){let s=this.doc.contents,r;for(let i of e)if(r=void 0,ct(s)){let a=s.items.find(l=>tt(l)&&Ge(l.key)&&String(l.key.value)===String(i));if(!a)return;r=a,s=a.value}else if(Lt(s)&&typeof i=="number")s=s.items[i];else return;if(n==="key"&&r&&Ge(r.key)&&r.key.range)return[r.key.range[0],r.key.range[1]];let o=s?.range;if(n==="pair"&&r&&Ge(r.key)&&r.key.range)return[r.key.range[0],o?o[1]:r.key.range[1]];if(o)return[o[0],o[1]];if(r&&Ge(r.key)&&r.key.range)return[r.key.range[0],r.key.range[1]]}at(e){let n=(s,r)=>{if(ct(s)){for(let o of s.items){let i=o.key;if(i?.range&&e>=i.range[0]&&e<=i.range[1])return{path:[...r,to(o)],where:"key",node:i};let a=o.value;if(a?.range&&e>=a.range[0]&&(Ge(a)?e<=a.range[1]:e<a.range[1]))return n(a,[...r,to(o)])??{path:[...r,to(o)],where:"value",node:a};if(i?.range&&(!a||!a.range||Ge(a)&&a.value===null)&&e>i.range[1]&&!this.text.slice(i.range[1],e).includes(`
|
|
389
|
+
`))return{path:[...r,to(o)],where:"value",node:a??void 0}}return s.range&&e>=s.range[0]&&e<=s.range[1]?{path:r,where:"inside",node:s}:void 0}if(Lt(s)){for(let[o,i]of s.items.entries()){let a=i?.range;if(a&&e>=a[0]&&(Ge(i)?e<=a[1]:e<a[1]))return n(i,[...r,o])??{path:[...r,o],where:"value",node:i}}return s.range&&e>=s.range[0]&&e<=s.range[1]?{path:r,where:"inside",node:s}:void 0}if(Ge(s)&&s.range&&e>=s.range[0]&&e<=s.range[1])return{path:r,where:"value",node:s}};return n(this.doc.contents,[])??{path:[],where:"inside"}}nodeAt(e){let n=this.doc.contents;for(let s of e)if(ct(n))n=n.items.find(r=>Ge(r.key)&&String(r.key.value)===String(s))?.value;else if(Lt(n)&&typeof s=="number")n=n.items[s];else return;return n??void 0}paths(){let e=[],n=(s,r)=>{let o=s?.range;if(o&&r.length&&e.push({path:r,range:[o[0],o[1]]}),ct(s))for(let i of s.items)n(i.value,[...r,to(i)]);else Lt(s)&&s.items.forEach((i,a)=>n(i,[...r,a]))};return n(this.doc.contents,[]),e}};function to(t){return Ge(t.key)?String(t.key.value):String(t.key)}function nl(t,e){let n=t.text,s=n.lastIndexOf(`
|
|
390
|
+
`,e-1)+1,r=n.slice(s,e),o=/[A-Za-z0-9_.:\/{}*~$-]*$/.exec(r)[0].replace(/^[{[,]/,""),i=e-o.length,a=Km(t,i);if(a){let u=n.slice(a.range[0],i),f=/([A-Za-z0-9_-]+)\s*:\s*$/.exec(u.slice(Math.max(u.lastIndexOf(","),u.lastIndexOf("{"))+1));return a.kind==="map"&&f?{path:[...a.path,f[1]],kind:"value",prefix:o,start:i,flow:!0}:{path:a.path,kind:a.kind==="map"?"key":"item",prefix:o,start:i,flow:!0}}let l=/^(\s*)(?:- )?([^\s:#][^:#]*?)\s*:\s+$/.exec(r.slice(0,r.length-o.length));if(l){let u=s+r.indexOf(l[2],l[1].length),f=t.at(u);return f.where==="key"?{path:f.path,kind:"value",prefix:o,start:i,flow:!1}:{path:[...id(t,s,l[1].length),l[2]],kind:"value",prefix:o,start:i,flow:!1}}let c=/^(\s*)- $/.exec(r.slice(0,r.length-o.length));if(c)return{path:id(t,s,c[1].length,!0),kind:"item",prefix:o,start:i,flow:!1};let d=/^\s*/.exec(r)[0].length;return{path:id(t,s,d),kind:"key",prefix:o,start:i,flow:!1}}function id(t,e,n,s=!1){let r=t.text,o=e-1;for(;o>0;){let i=r.lastIndexOf(`
|
|
391
|
+
`,o-1)+1,a=r.slice(i,o);if(o=i-1,!a.trim()||/^\s*#/.test(a))continue;let l=/^\s*/.exec(a)[0].length;if(l===n&&!s){let c=i+l+(a.slice(l).startsWith("- ")?2:0),d=t.at(c);if(d.where==="key"||a.slice(l).startsWith("- "))return d.path.slice(0,-1)}if(!s&&/^- /.test(a.slice(l))&&l+2===n){let c=t.at(i+l+2);if(c.where==="key")return c.path.slice(0,-1)}if(l<n||s&&l<=n&&/:\s*$/.test(a)){let c=/^(\s*)(- )?([^\s:#][^:#]*?)\s*:/.exec(a);if(c){let d=t.at(i+c[1].length+(c[2]?2:0));if(d.where==="key")return d.path}if(/^\s*- /.test(a)){let d=t.at(i+l+2),u=d.path.length-1;for(;u>=0&&typeof d.path[u]!="number";)u--;return u>=0?d.path.slice(0,u+1):d.path}if(l<n)return[]}if(l===0&&n===0)return[]}return[]}function Km(t,e){let n,s=(r,o)=>{if(!vt(r))return;let i=r.range;if(r.flow&&i&&e>i[0]&&e<i[1]&&(n={path:o,kind:ct(r)?"map":"list",range:[i[0],i[1]]}),ct(r))for(let l of r.items)s(l.value,[...o,to(l)]);else Lt(r)&&r.items.forEach((l,c)=>s(l,[...o,c]))};return s(t.doc.contents,[]),n}var bn=class extends Error{};function yn(t,e){let n=t;for(let s of[...e].sort((r,o)=>o.start-r.start))n=n.slice(0,s.start)+s.text+n.slice(s.end);return n}function ol(t,e){let n=[...e].sort((r,o)=>r.start-o.start),s=0;return n.map(r=>{let o=r.start+s;return s+=r.text.length-(r.end-r.start),{start:o,end:o+r.text.length,text:t.slice(r.start,r.end)}})}var Is=t=>({text:t,doc:ln(t,{keepSourceTokens:!0,uniqueKeys:!1})});function bs(t){return Ge(t.key)?String(t.key.value):String(t.key)}function Ds(t,e){let n=t.doc.contents,s,r,o=[n];for(let i of e){if(s=void 0,ct(n)){r=n;let a=n.items.find(l=>tt(l)&&bs(l)===String(i));if(!a)return{node:void 0,parent:r,chain:o};s=a,n=a.value}else if(Lt(n)&&typeof i=="number"){if(r=n,n=n.items[i],n===void 0)return{node:void 0,parent:r,chain:o}}else return{node:void 0,chain:o};o.push(n)}return{node:n,pair:s,parent:r,chain:o}}var ri=t=>t.some(e=>(ct(e)||Lt(e))&&e.flow),Rs=(t,e)=>t.lastIndexOf(`
|
|
392
|
+
`,e-1)+1,ad=(t,e)=>{let n=t.indexOf(`
|
|
393
|
+
`,e);return n<0?t.length:n},ld=(t,e)=>{let n=t.indexOf(`
|
|
394
|
+
`,e);return n<0?t.length:n+1},si=(t,e)=>e-Rs(t,e);function tr(t,e){let n=e.key,s=e.value,r=s?.range?Math.max(s.range[1],n.range[1]):n.range[1],o=r>0&&t.text[r-1]===`
|
|
395
|
+
`?r-1:r;return ld(t.text,o)}function no(t,e){let n=e.key.range[0],s=Rs(t.text,n),r=n-s;if(Sr(t.text,n))return n;for(;s!==0;){let o=Rs(t.text,s-1),i=t.text.slice(o,s-1);if(/^\s*#/.test(i)&&i.length-i.trimStart().length===r)s=o;else break}return s}var il=(t,e)=>/^\s*(-\s+)*$/.test(t.slice(Rs(t,e),e)),Sr=(t,e)=>/-\s+$/.test(t.slice(Rs(t,e),e)),_m=/[,[\]{}]/;function ts(t,e){if(t==null)return"null";if(typeof t!="string")return String(t);if(e.style===Be.QUOTE_DOUBLE)return JSON.stringify(t);if(e.style===Be.QUOTE_SINGLE&&!t.includes(`
|
|
396
396
|
`))return`'${t.replace(/'/g,"''")}'`;if(t.includes(`
|
|
397
397
|
`)){if(e.flow)return JSON.stringify(t);let s=t.endsWith(`
|
|
398
398
|
`)?t.slice(0,-1):t;return/(^|\n)\s/.test(s.split(`
|
|
@@ -400,74 +400,74 @@ ${e.extraBody??""}
|
|
|
400
400
|
`)?"|":"|-")+`
|
|
401
401
|
`+s.split(`
|
|
402
402
|
`).map(r=>r?" ".repeat(e.indent)+r:"").join(`
|
|
403
|
-
`)}let n=
|
|
404
|
-
`)))&&
|
|
405
|
-
`))||Array.isArray(n)&&
|
|
403
|
+
`)}let n=lc(t,{lineWidth:0}).replace(/\n$/,"");return e.flow&&_m.test(n)&&!/^["']/.test(n)?JSON.stringify(t):n}function fn(t){if(Array.isArray(t))return t.length?`[${t.map(fn).join(", ")}]`:"[]";if(t&&typeof t=="object"){let e=Object.entries(t);return e.length?`{ ${e.map(([n,s])=>`${nr(n)}: ${fn(s)}`).join(", ")} }`:"{}"}return ts(t,{flow:!0,indent:0})}var nr=t=>ts(t,{flow:!0,indent:0}),_n=t=>!!t&&typeof t=="object",cd=t=>{if(Array.isArray(t))return t.every(e=>!_n(e)&&!(typeof e=="string"&&e.includes(`
|
|
404
|
+
`)))&&fn(t).length<=60;if(_n(t)){let e=Object.entries(t);return e.length>0&&e.length<=2&&e.every(([,n])=>!_n(n)&&!(typeof n=="string"&&n.includes(`
|
|
405
|
+
`))||Array.isArray(n)&&cd(n))&&fn(t).length<=40}return!1};function sl(t,e=0){let n=" ".repeat(e),s=r=>_n(r)?(Array.isArray(r)?!r.length:!Object.keys(r).length)?Array.isArray(r)?"[]":"{}":cd(r)?fn(r):void 0:ts(r,{flow:!1,indent:e+2});return Array.isArray(t)?t.map(r=>{let o=s(r);if(o!==void 0)return`${n}- ${o}`;let i=sl(r,e+2);return Array.isArray(r)?`${n}-
|
|
406
406
|
${i}`:`${n}- ${i.slice(e+2)}`}).join(`
|
|
407
|
-
`):Object.entries(t).map(([r,o])=>{let i=s(o);return i!==void 0?`${n}${
|
|
408
|
-
${
|
|
409
|
-
`)}function
|
|
410
|
-
`+
|
|
407
|
+
`):Object.entries(t).map(([r,o])=>{let i=s(o);return i!==void 0?`${n}${nr(r)}: ${i}`:`${n}${nr(r)}:
|
|
408
|
+
${sl(o,e+2)}`}).join(`
|
|
409
|
+
`)}function rl(t,e){return _n(t)?(Array.isArray(t)?!t.length:!Object.keys(t).length)?Array.isArray(t)?" []":" {}":cd(t)?" "+fn(t):`
|
|
410
|
+
`+al(sl(t),e+2):" "+ts(t,{flow:!1,indent:e+2})}var al=(t,e)=>t.split(`
|
|
411
411
|
`).map(n=>n&&" ".repeat(e)+n).join(`
|
|
412
|
-
`);function
|
|
413
|
-
`&&!
|
|
412
|
+
`);function Fs(t,e,n){let s=Is(t),r=Ds(s,e);if(r.node===void 0)throw new bn(`no value at ${e.join(".")}`);let o=ri(r.chain.slice(0,-1)),i=r.node,a=r.pair?.key,l=a?.range?si(t,a.range[0]):i?.range?si(t,i.range[0]):0;if(Ge(i)&&i.range&&!_n(n)&&i.range[1]>i.range[0]){let v=i.type===Be.BLOCK_LITERAL||i.type===Be.BLOCK_FOLDED?void 0:i.type,w=ts(n,{flow:o,indent:l+2,style:v}),M=i.range[1];if(t[M-1]===`
|
|
413
|
+
`&&!w.endsWith(`
|
|
414
414
|
`))for(M-=1;M>i.range[0]&&t[M-1]===`
|
|
415
|
-
`;)M-=1;if(
|
|
416
|
-
`)){let
|
|
417
|
-
`;)
|
|
418
|
-
`?d-1:d,f=
|
|
415
|
+
`;)M-=1;if(w.startsWith("|")&&!t.slice(i.range[0],M).includes(`
|
|
416
|
+
`)){let y=ad(t,M),T=t.slice(M,y);/^\s*#/.test(T)&&(w=w.replace(/^(\|-?)/,`$1${T}`),M=y)}return{steps:[[{start:i.range[0],end:M,text:w}]]}}if((o||_n(i)&&i.flow||!r.pair)&&i?.range&&i.range[1]>i.range[0]){let v=o||!_n(n)||!r.pair?_n(n)?fn(n):ts(n,{flow:o,indent:l+2}):null;if(v!==null){let w=i.range[1];for(;w>i.range[0]&&t[w-1]===`
|
|
417
|
+
`;)w-=1;return{steps:[[{start:i.range[0],end:w,text:v}]]}}}if(!r.pair||!a?.range)return so(t,e.slice(0,-1),v=>v.setIn(e,n));let c=t.indexOf(":",a.range[1]),d=i?.range?i.range[1]:c+1,u=t[d-1]===`
|
|
418
|
+
`?d-1:d,f=ad(t,c),p=i?.range&&i.range[0]>f?t.slice(c+1,f):"",g=/^\s*#/.test(p)?p:"",h=rl(n,l),b=u;if(g&&h.startsWith(`
|
|
419
419
|
`))h=g+h;else if(g)h=h+g;else if(h.startsWith(`
|
|
420
|
-
`)&&u<=f){let
|
|
420
|
+
`)&&u<=f){let v=t.slice(u,f);/^\s*#/.test(v)&&(h=v+h,b=f)}return{steps:[[{start:c+1,end:b,text:h}]]}}function Tn(t,e,n,s,r={}){let o=r.order??[],i=Is(t),a=Ds(i,e);if(a.node===void 0||a.node===null||Ge(a.node)&&a.node.value===null){if(!e.length){let w=`${nr(n)}:${rl(s,0)}
|
|
421
421
|
`;return{steps:[[{start:t.length,end:t.length,text:(t&&!t.endsWith(`
|
|
422
422
|
`)?`
|
|
423
|
-
`:"")+
|
|
424
|
-
`,h=!e.length&&
|
|
425
|
-
`:"";if(u===0&&d.length&&
|
|
426
|
-
`:g}]]}}let b=
|
|
423
|
+
`:"")+w}]]}}return a.node===void 0?Tn(t,e.slice(0,-1),String(e[e.length-1]),{[n]:s},{order:r.order}):Fs(t,e,{[n]:s})}let l=a.node;if(!ct(l))throw new bn(`${e.join(".")||"the file"} is not a map`);if(l.items.some(w=>bs(w)===n))throw new bn(`"${n}" is already in ${e.join(".")||"the file"}`);let c=l.flow||ri(a.chain.slice(0,-1)),d=l.items,u=d.length;if(r.after!==void 0)u=d.findIndex(w=>bs(w)===r.after)+1||d.length;else if(r.before!==void 0){let w=d.findIndex(M=>bs(M)===r.before);w>=0&&(u=w)}else if(!e.length&&o.includes(n)){let w=o.indexOf(n),M=d.findIndex(y=>o.indexOf(bs(y))>w||bs(y).startsWith("x-"));M>=0&&(u=M)}if(c&&l.range&&t[l.range[0]]!=="{"){let w=i.doc.getIn(e,!0).toJSON();return{steps:[[{start:l.range[0],end:l.range[1],text:fn({...w,[n]:s})}]]}}if(c){let w=`${nr(n)}: ${fn(s)}`;if(!d.length){let T=l.range;return{steps:[[{start:T[0],end:t.lastIndexOf("}",T[1])+1,text:`{ ${w} }`}]]}}if(u<d.length){let T=d[u].key.range[0];return{steps:[[{start:T,end:T,text:`${w}, `}]]}}let M=d[d.length-1],y=M.value?.range?.[1]??M.key.range[1];return{steps:[[{start:y,end:y,text:`, ${w}`}]]}}let f=d[0]?.key;if(!f?.range)return so(t,e,w=>w.setIn([...e,n],s),!0);let p=si(t,f.range[0]);if(d.some(w=>!il(t,w.key.range[0])))return so(t,e,w=>w.setIn([...e,n],s),!0);let g=`${" ".repeat(p)}${nr(n)}:${rl(s,p)}
|
|
424
|
+
`,h=!e.length&&_n(s)?`
|
|
425
|
+
`:"";if(u===0&&d.length&&Sr(t,f.range[0])){let w=f.range[0];return{steps:[[{start:w,end:w,text:g.slice(p)+" ".repeat(p)}]]}}if(u<d.length){let w=no(i,d[u]);return{steps:[[{start:w,end:w,text:h&&u>0?g+`
|
|
426
|
+
`:g}]]}}let b=tr(i,d[d.length-1]),v=b===t.length&&t.length&&!t.endsWith(`
|
|
427
427
|
`)?`
|
|
428
|
-
`:"";return{steps:[[{start:b,end:b,text:
|
|
429
|
-
`?g-1:g);return{steps:[[{start:p,end:h,text:""}]]}}function
|
|
430
|
-
`;if(c<l.length){let
|
|
431
|
-
`?
|
|
428
|
+
`:"";return{steps:[[{start:b,end:b,text:v+h+g}]]}}function js(t,e){if(!e.length)throw new bn("can't delete the whole file");let n=Is(t),s=e.slice(0,-1),o=Ds(n,s).node,i=e[e.length-1];if(!ct(o)&&!Lt(o))throw new bn(`no entry at ${e.join(".")}`);let a=o.items,l=ct(o)?a.findIndex(b=>bs(b)===String(i)):Number(i);if(l<0||l>=a.length)throw new bn(`no entry at ${e.join(".")}`);let c=o.flow,d=b=>tt(b)?b.key.range[0]:b.range[0],u=b=>tt(b)?b.value?.range?.[1]??b.key.range[1]:b.range[1];if(a.length===1)return!s.length&&ct(o)&&!o.flow?{steps:[[{start:no(n,a[0]),end:tr(n,a[0]),text:""}]]}:s.length?Fs(t,s,ct(o)?{}:[]):{steps:[[{start:0,end:t.length,text:""}]]};if(c)return l<a.length-1?{steps:[[{start:d(a[l]),end:d(a[l+1]),text:""}]]}:{steps:[[{start:u(a[l-1]),end:u(a[l]),text:""}]]};if(ct(o)){let b=a[l],v=b.key.range[0];return il(t,v)?Sr(t,v)?{steps:[[{start:v,end:a[l+1]?a[l+1].key.range[0]:tr(n,b),text:""}]]}:{steps:[[{start:no(n,b),end:tr(n,b),text:""}]]}:so(t,s,w=>w.deleteIn(e),!0)}let f=a[l],p=Rs(t,f.range[0]);if(!/^\s*-/.test(t.slice(p,f.range[0])))return so(t,s,b=>b.deleteIn(e),!0);let g=f.range[1],h=ld(t,t[g-1]===`
|
|
429
|
+
`?g-1:g);return{steps:[[{start:p,end:h,text:""}]]}}function oi(t,e,n,s,r){let o=Is(t),i=Ds(o,e);if(i.node===void 0||i.node===null||Ge(i.node)&&i.node.value===null)return i.node===void 0?Tn(t,e.slice(0,-1),String(e[e.length-1]),[n],{order:r}):Fs(t,e,[n]);let a=i.node;if(!Lt(a))throw new bn(`${e.join(".")} is not a list`);let l=a.items,c=s===void 0?l.length:Math.max(0,Math.min(s,l.length));if(a.flow||ri(i.chain.slice(0,-1))){let y=fn(n);if(!l.length){let S=a.range,P=t.lastIndexOf("]",S[1]);return{steps:[[{start:S[0],end:P+1,text:`[${y}]`}]]}}if(c<l.length){let S=l[c].range[0];return{steps:[[{start:S,end:S,text:`${y}, `}]]}}let T=l[l.length-1].range[1];return{steps:[[{start:T,end:T,text:`, ${y}`}]]}}let d=l[0],u=Rs(t,d.range[0]),f=t.slice(u,d.range[0]);if(!/^\s*- $/.test(f))return so(t,e,y=>{y.getIn(e).items.splice(c,0,y.createNode(n))},!0);let p=f.indexOf("-"),g=l[Math.min(c,l.length-1)],h=_n(n)&&ct(g)&&g.flow,b=" ".repeat(p)+"- "+(h?fn(n):_n(n)&&Object.keys(n).length?al(sl(n),p+2).slice(p+2):ts(n,{flow:!1,indent:p+2}))+`
|
|
430
|
+
`;if(c<l.length){let y=Rs(t,l[c].range[0]);return{steps:[[{start:y,end:y,text:b}]]}}let v=l[l.length-1].range[1],w=ld(t,t[v-1]===`
|
|
431
|
+
`?v-1:v),M=w===t.length&&!t.endsWith(`
|
|
432
432
|
`)?`
|
|
433
|
-
`:"";return{steps:[[{start:
|
|
433
|
+
`:"";return{steps:[[{start:w,end:w,text:M+b}]]}}function sr(t,e,n){let s=Is(t),r=Ds(s,e);if(!r.pair)throw new bn(`no key at ${e.join(".")}`);if(r.parent.items.some(i=>bs(i)===n))throw new bn(`"${n}" is already there`);let o=r.pair.key;return{steps:[[{start:o.range[0],end:o.range[1],text:nr(n)}]]}}function ll(t,e,n,s){let r=Is(t),o=Ds(r,e);if(!o.pair||!ct(o.parent))throw new bn(`no key at ${e.join(".")}`);let i=o.parent,a=Sr(t,o.pair.key.range[0])||i.items.some(g=>Sr(t,g.key.range[0]));if(i.flow||a){let h=o.pair.value?r.doc.getIn(e)?.toJSON?.()??r.doc.getIn(e):null,b=js(t,e),v=yn(t,b.steps[0]),w=Tn(v,e.slice(0,-1),String(e[e.length-1]),h,n?{before:n,order:s}:{order:s});return{steps:[...b.steps,...w.steps]}}let l=no(r,o.pair),c=tr(r,o.pair),d=t.slice(l,c),u=n?i.items.find(g=>bs(g)===n):void 0;if(u===o.pair)return{steps:[]};let f=u?no(r,u):tr(r,i.items[i.items.length-1]),p=d.endsWith(`
|
|
434
434
|
`)?d:d+`
|
|
435
435
|
`;return{steps:[[{start:l,end:c,text:""},{start:f,end:f,text:f===t.length&&!t.endsWith(`
|
|
436
436
|
`)?`
|
|
437
|
-
`+p:p}]]}}function
|
|
438
|
-
`?u[1]-1:
|
|
439
|
-
`,p=
|
|
437
|
+
`+p:p}]]}}function so(t,e,n,s=!1){let r=Is(t),i=Ds(r,e).node;if(n(r.doc),!e.length||!i?.range)return{steps:[[{start:0,end:t.length,text:r.doc.toString({lineWidth:0})}]],fallback:!0};let a=r.doc.getIn(e,!0),l=i.flow,c=new Jn;c.contents=a;let d=c.toString({lineWidth:0,indent:2}).replace(/\n$/,""),u=i.range;if(l)return{steps:[[{start:u[0],end:u[1],text:d.replace(/\n\s*/g," ")}]],fallback:!0};let f=Rs(t,u[0]),p=u[0]-f,g=u[1]>0&&t[u[1]-1]===`
|
|
438
|
+
`?u[1]-1:ad(t,u[1]);return d=al(d,p).slice(t.slice(f,u[0]).trim()?p:0),{steps:[[{start:t.slice(f,u[0]).trim()?u[0]:f,end:g,text:d}]],fallback:!0}}function cl(t,e,n,s,r){let o=Is(t),i=Ds(o,e),a=i.node,l=ln(s).toJS()?.[n];if(!ct(a)||a.flow||ri(i.chain.slice(0,-1))||!a.items.length)return Tn(t,e,n,l,{order:r});let c=a.items,d=c[0].key;if(!d.range||c.some(h=>!il(t,h.key.range[0])||Sr(t,h.key.range[0])))return Tn(t,e,n,l,{order:r});if(c.some(h=>bs(h)===n))throw new bn(`"${n}" is already in ${e.join(".")||"the file"}`);let u=si(t,d.range[0]),f=al(s.replace(/\n+$/,""),u)+`
|
|
439
|
+
`,p=tr(o,c[c.length-1]),g=p===t.length&&t.length&&!t.endsWith(`
|
|
440
440
|
`)?`
|
|
441
|
-
`:"";return{steps:[[{start:p,end:p,text:g+f}]]}}function
|
|
442
|
-
`}let o=
|
|
441
|
+
`:"";return{steps:[[{start:p,end:p,text:g+f}]]}}function ro(t,e){let n=Is(t),s=Ds(n,e);if(!s.pair||!ct(s.parent))return;let r=s.pair.key.range[0];if(s.parent.flow||ri(s.chain.slice(0,-1))||!il(t,r)||Sr(t,r)){let l=n.doc.getIn(e,!0),c=l&&typeof l=="object"&&l.toJSON?l.toJSON():n.doc.getIn(e);return`${nr(String(e[e.length-1]))}:${rl(c,0)}
|
|
442
|
+
`}let o=no(n,s.pair),i=tr(n,s.pair),a=si(t,r);return t.slice(o,i).split(`
|
|
443
443
|
`).map(l=>l.slice(0,a).trim()===""?l.slice(a):l.trimStart()).join(`
|
|
444
444
|
`).replace(/\n*$/,`
|
|
445
|
-
`)}var
|
|
446
|
-
`)&&!(/[\w-]/.test(d)&&/^[^\w-]/.test(i.text))}l&&a==="delete"&&(l=i.end===o.caret);let{inverse:c}=this.run([e]);l?(o.steps.push(e),o.inverse.unshift(...c),o.time=r,o.after={paths:this.selection,text:n.after},o.caret=a==="insert"?i.start+i.text.length:i.start):(this.seal(),this.push({id:this.nextId++,label:"Typing",origin:"text",steps:[e],inverse:c,before:{paths:this.selection,text:n.before??this.textSel},after:{paths:this.selection,text:n.after},time:r,fallback:!1,open:!!a,caret:i?a==="insert"?i.start+i.text.length:i.start:void 0,typing:a,source:s})),n.after!==void 0&&(this.textSel=n.after),this.emit({kind:"do",origin:"text",label:"Typing",steps:[e],version:this._version,source:s})}seal(){let e=this.undoStack[this.undoStack.length-1];e&&(e.open=!1)}run(e){let n=[],s=this._text;for(let r of e){let o=
|
|
445
|
+
`)}var dd=500,zm=1e3,oo=class{_text="";_doc;_version=0;undoStack=[];redoStack=[];nextId=1;cleanId=0;listeners=new Set;selListeners=new Set;_good;selection=[];textSel;fallbacks=0;depth=dd;now=()=>Date.now();constructor(e=""){this._text=e}get text(){return this._text}get version(){return this._version}get doc(){return this._doc??=new Nn(this._text)}get goodDoc(){return this.doc.ok&&(this._good=this.doc),this._good??this.doc}select(e,n){this.selection=e;for(let s of this.selListeners)s({paths:e,origin:n})}onSelect(e){return this.selListeners.add(e),()=>this.selListeners.delete(e)}on(e){return this.listeners.add(e),()=>this.listeners.delete(e)}emit(e){for(let n of this.listeners)n(e)}load(e,n="file"){let s=this._text;this.undoStack=[],this.redoStack=[],this.selection=[],this._good=void 0,this.set(e),this.cleanId=0,this.emit({kind:"load",origin:n,label:"Open",steps:[[{start:0,end:s.length,text:e}]],version:this._version})}set(e){this._text=e,this._doc=void 0,this._version++}apply(e,n="api"){this.seal();let s=e.build(this._text);if(!s.steps.some(a=>a.length))return!1;let r={paths:this.selection,text:this.textSel},{inverse:o}=this.run(s.steps),i=e.remap??(a=>a);this.selection=e.select??this.selection.map(i).filter(a=>a!==null),s.fallback&&this.fallbacks++,this.push({id:this.nextId++,label:e.label,origin:n,steps:s.steps,inverse:o,before:r,after:{paths:this.selection,text:this.textSel},time:this.now(),fallback:!!s.fallback,open:!1}),this.emit({kind:"do",origin:n,label:e.label,steps:s.steps,version:this._version,remap:e.remap});for(let a of this.selListeners)a({paths:this.selection,origin:n});return!0}typed(e,n={},s){if(!e.length)return;let r=this.now(),o=this.undoStack[this.undoStack.length-1],i=e.length===1?e[0]:void 0,a=i?i.text&&i.start===i.end?"insert":!i.text&&i.end>i.start?"delete":void 0:void 0,l=!!(o&&o.open&&o.origin==="text"&&o.source===s&&this.redoStack.length===0&&r-o.time<zm&&i&&a&&a===o.typing);if(l&&a==="insert"){let d=this._text[i.start-1]??"";l=i.start===o.caret&&!i.text.includes(`
|
|
446
|
+
`)&&!(/[\w-]/.test(d)&&/^[^\w-]/.test(i.text))}l&&a==="delete"&&(l=i.end===o.caret);let{inverse:c}=this.run([e]);l?(o.steps.push(e),o.inverse.unshift(...c),o.time=r,o.after={paths:this.selection,text:n.after},o.caret=a==="insert"?i.start+i.text.length:i.start):(this.seal(),this.push({id:this.nextId++,label:"Typing",origin:"text",steps:[e],inverse:c,before:{paths:this.selection,text:n.before??this.textSel},after:{paths:this.selection,text:n.after},time:r,fallback:!1,open:!!a,caret:i?a==="insert"?i.start+i.text.length:i.start:void 0,typing:a,source:s})),n.after!==void 0&&(this.textSel=n.after),this.emit({kind:"do",origin:"text",label:"Typing",steps:[e],version:this._version,source:s})}seal(){let e=this.undoStack[this.undoStack.length-1];e&&(e.open=!1)}run(e){let n=[],s=this._text;for(let r of e){let o=yn(s,r);n.unshift(ol(s,r)),s=o}return this.set(s),{inverse:n}}push(e){this.undoStack.push(e),this.redoStack=[],this.undoStack.length>this.depth&&this.undoStack.shift().id===this.cleanId&&(this.cleanId=-1)}get canUndo(){return this.undoStack.length>0}get canRedo(){return this.redoStack.length>0}get undoLabel(){return this.undoStack[this.undoStack.length-1]?.label}get redoLabel(){return this.redoStack[this.redoStack.length-1]?.label}undo(){this.seal();let e=this.undoStack.pop();if(!e)return!1;this.run(e.inverse),this.redoStack.push(e),this.selection=e.before.paths,this.textSel=e.before.text,this.emit({kind:"undo",origin:"history",label:e.label,steps:e.inverse,version:this._version,textSel:e.before.text});for(let n of this.selListeners)n({paths:this.selection,origin:"history"});return!0}redo(){let e=this.redoStack.pop();if(!e)return!1;this.run(e.steps),this.undoStack.push(e),this.selection=e.after.paths,this.textSel=e.after.text,this.emit({kind:"redo",origin:"history",label:e.label,steps:e.steps,version:this._version,textSel:e.after.text});for(let n of this.selListeners)n({paths:this.selection,origin:"history"});return!0}markClean(){this.seal(),this.cleanId=this.undoStack[this.undoStack.length-1]?.id??0}get dirty(){return(this.undoStack[this.undoStack.length-1]?.id??0)!==this.cleanId}get history(){return this.undoStack.map(e=>e.label)}};var io=class{root;defs;constructor(e){this.root=e,this.defs=e.$defs??{}}spread(e,n=new Set){if(!e||typeof e!="object"||n.has(e))return[];n.add(e);let s=e,r=[s];typeof s.$ref=="string"&&s.$ref.startsWith("#/$defs/")&&r.push(...this.spread(this.defs[s.$ref.slice(8)],n));for(let o of["anyOf","oneOf","allOf"])for(let i of s[o]??[])r.push(...this.spread(i,n));return r}at(e){let n=this.spread(this.root);for(let s of e){let r=[];for(let o of n){if(typeof s=="number"){o.items&&r.push(...this.spread(o.items));continue}let i=o.properties??{};if(i[s]!==void 0){r.push(...this.spread(i[s]));continue}let a=Object.entries(o.patternProperties??{}).find(([l])=>new RegExp(l).test(s));if(a){r.push(...this.spread(a[1]));continue}o.additionalProperties&&typeof o.additionalProperties=="object"&&r.push(...this.spread(o.additionalProperties))}if(n=r,!n.length)break}return n}keys(e,n={}){let s=this.at(e),r=new Set;for(let i of s)for(let[a,l]of Object.entries(i.dependentSchemas??{})){let c=Object.entries(l.properties??{}).filter(([,d])=>d===!1).map(([d])=>d);n[a]!==void 0?c.forEach(d=>r.add(d)):c.some(d=>n[d]!==void 0)&&r.add(a)}let o=new Map;for(let i of s)for(let[a,l]of Object.entries(i.properties??{})){if(r.has(a)||l===!1)continue;let c=o.get(a),d=this.info(a,e,l);(!c||!c.doc&&d.doc)&&o.set(a,d)}return[...o.values()]}info(e,n,s){let r=this.at([...n,e]).length?this.at([...n,e]):this.spread(s),o=r.map(c=>c.markdownDescription??c.description).find(Boolean),i=new Set(r.flatMap(c=>Array.isArray(c.type)?c.type:c.type?[c.type]:[])),a=r.some(c=>c.properties||c.additionalProperties||c.patternProperties),l=i.has("array")&&!i.has("string")?"list":(i.has("object")||a)&&!i.has("string")&&!r.some(c=>c.const!==void 0||c.enum)?"map":"scalar";return{name:e,doc:o,shape:l,enumValues:this.values([...n,e],r),examples:r.flatMap(c=>c.examples??[])}}values(e,n=this.at(e)){let s=new Set;for(let r of n){for(let o of r.enum??[])s.add(String(o));r.const!==void 0&&typeof r.const!="object"&&s.add(String(r.const)),r.type==="boolean"&&(s.add("true"),s.add("false"))}return[...s]}hover(e){let n=this.at(e),s=n.map(o=>o.markdownDescription??o.description).find(Boolean);if(!s)return;let r=this.values(e,n);return s+(r.length&&r.length<=12?`
|
|
447
447
|
|
|
448
|
-
One of: ${r.map(o=>"`"+o+"`").join(", ")}`:"")}defaultFor(e){let n=this.at(e),s=this.values(e,n);if(s.length)return s[0]==="true"||s[0]==="false"?!1:s[0];let r=n.flatMap(i=>i.examples??[]).find(i=>typeof i=="string"),o=new Set(n.flatMap(i=>Array.isArray(i.type)?i.type:i.type?[i.type]:[]));return o.has("array")?[]:o.has("object")||n.some(i=>i.properties||i.additionalProperties)?{}:o.has("integer")||o.has("number")?1:r??""}types(e){return new Set(this.at(e).flatMap(n=>Array.isArray(n.type)?n.type:n.type?[n.type]:[]))}isNameMap(e){return this.at(e).some(n=>n.additionalProperties&&typeof n.additionalProperties=="object"&&!n.properties)}};var
|
|
448
|
+
One of: ${r.map(o=>"`"+o+"`").join(", ")}`:"")}defaultFor(e){let n=this.at(e),s=this.values(e,n);if(s.length)return s[0]==="true"||s[0]==="false"?!1:s[0];let r=n.flatMap(i=>i.examples??[]).find(i=>typeof i=="string"),o=new Set(n.flatMap(i=>Array.isArray(i.type)?i.type:i.type?[i.type]:[]));return o.has("array")?[]:o.has("object")||n.some(i=>i.properties||i.additionalProperties)?{}:o.has("integer")||o.has("number")?1:r??""}types(e){return new Set(this.at(e).flatMap(n=>Array.isArray(n.type)?n.type:n.type?[n.type]:[]))}isNameMap(e){return this.at(e).some(n=>n.additionalProperties&&typeof n.additionalProperties=="object"&&!n.properties)}};var ii={view:"view",live:"live"},jf=["text","both","canvas"];var ao=t=>ln(t,{uniqueKeys:!1}).toJS();function ns(t,e){let n=[],s=t,r=!1;for(let o of e){let i=o(s);for(let a of i.steps)n.push(a),s=yn(s,a);r||=!!i.fallback}return{steps:n,fallback:r}}function ai(t,e){return{label:t,touched:e.flatMap(n=>n.touched??[]),select:e.find(n=>n.select)?.select,build:n=>ns(n,e.map(s=>r=>s.build(r)))}}var Vm=(t,e)=>{let n=ao(t),s=e.slice(0,-1).reduce((r,o)=>r?.[o],n);return!!s&&typeof s=="object"&&String(e[e.length-1])in s},Bf=t=>t.split("/").slice(1).map(e=>{let n=e.replace(/~1/g,"/").replace(/~0/g,"~");return/^\d+$/.test(n)?Number(n):n});function lo(t){let e=v=>t.describe(v),n=t.topOrder,s=v=>{let w=new Set;for(let M of t.kinds){let y=M.section.reduce((T,S)=>T?.[S],v);if(y&&typeof y=="object")for(let T of Object.keys(y))w.add(T)}return w};function r(v,w,M=`Set ${e(v)}`){return{label:M,touched:[v],build:y=>{let T=new Nn(y);return T.rangeOf(v)||T.nodeAt(v)!==void 0||Vm(y,v)?Fs(y,v,w):Tn(y,v.slice(0,-1),String(v[v.length-1]),w,{order:n})}}}function o(v,w){let M=v.map(([y])=>[t.pins.key,"layout",y]);return i({label:w,touched:M,build:y=>ns(y,v.map(([,T],S)=>P=>r(M[S],{at:T}).build(P)))})}function i(v){return{...v,build:w=>t.pins.legacyOnly(ao(w))?ns(w,[M=>sr(M,[t.pins.legacyKey],t.pins.key),M=>v.build(M)]):v.build(w)}}function a(v,w,M,y={}){return{label:y.label??`Add ${e([...v,w])}`,touched:[[...v,w]],select:[[...v,w]],build:T=>Tn(T,v,w,M,{...y,order:n})}}function l(v,w,M,y=`Add to ${e(v)}`){return{label:y,touched:[v],build:T=>oi(T,v,w,M,n)}}function c(v,w){return{label:`Move ${e(v)}`,touched:[v],build:M=>ll(M,v,w,n)}}function d(v,w,M){return t.refs(ao(v)).filter(y=>(y.slot.key?y.value===M:y.name===M)&&y.slot.targets.includes(w))}function u(v,w={}){let M=t.objectOf(Se(v)),y=M&&M.path===Se(v);return{label:`Delete ${e(v)}`,touched:[v],remap:T=>qt(v,T)?null:T,build:T=>{if(!y||!w.withRefs)return js(T,v);let P=d(T,M.kind,M.name).map($=>{let x=Bf($.path);return typeof x.at(-1)=="number"?x:t.refDeletePath(x)}),I=[...new Map(P.map($=>[Se($),$])).values()],_=I.filter($=>typeof $.at(-1)=="number").sort(($,x)=>x.at(-1)-$.at(-1)),O=I.filter($=>typeof $.at(-1)!="number"),j=[..._,...O,v],k=j.filter(($,x)=>!j.some((N,F)=>F!==x&&N.length<$.length&&qt(N,$)));return ns(T,k.map($=>x=>js(x,$)))}}}function f(v,w){let M=t.objectOf(Se(v)),y=String(v[v.length-1]),T=v.slice(0,-1);return{label:`Rename ${e(v)} to ${w}`,touched:[[...T,w]],remap:S=>qt(v,S)?[...T,w,...S.slice(v.length)]:S,build:S=>{let P=sr(S,v,w);if(!M||M.path!==Se(v))return P;let I=new Nn(S),_=[...P.steps[0]];for(let O of d(S,M.kind,y)){let j=Bf(O.path),k=t.renameRef(O,w);if(k===void 0)continue;let $=I.rangeOf(j,O.slot.key?"key":"value");if(!$)continue;let x=S.slice($[0],$[1]),N=x[0]==='"'||x[0]==="'"?x[0]:void 0;_.push({start:$[0],end:$[1],text:N==='"'?JSON.stringify(k):N==="'"?`'${k}'`:ts(k,{flow:!0,indent:0})})}return{steps:[_]}}}}function p(v){let w=String(v[v.length-1]),M=v.slice(0,-1),y="";return{label:`Duplicate ${e(v)}`,get select(){return y?[[...M,y]]:void 0},build:T=>{let S=ao(T),P=s(S),I=w.replace(/-\d+$/,""),_=2;for(;P.has(`${I}-${_}`);)_++;y=`${I}-${_}`;let O=t.objectOf(Se(v))?.kind??"",j=t.copyValue(O,v.reduce((k,$)=>k?.[$],S));return Tn(T,M,y,j,{after:w,order:n})}}}function g(v,w){let M=v.slice(0,-1);return{label:`Rename ${e(v)} to ${w}`,touched:[[...M,w]],remap:y=>qt(v,y)?[...M,w,...y.slice(v.length)]:y,build:y=>sr(y,v,w)}}function h(v,w,M){return{label:`Move ${e([...v,w])}`,touched:[v],remap:y=>qt(v,y)&&y.length>v.length&&y[v.length]===w?[...v,M,...y.slice(v.length+1)]:y,build:y=>{if(w===M)return{steps:[]};let T=[...v,w].reduce((S,P)=>S?.[P],ao(y));return ns(y,[S=>js(S,[...v,w]),S=>oi(S,v,T,M,n)])}}}function b(v,w){let M=s(ao(v)),y=1;for(;M.has(`${w}-${y}`);)y++;return`${w}-${y}`}return{describe:e,setCmd:r,pinsCmd:o,withPinsMoved:i,insertCmd:a,insertItemCmd:l,moveCmd:c,referencesTo:d,deleteCmd:u,renameCmd:f,duplicateCmd:p,renameKeyCmd:g,moveItemCmd:h,freshName:b}}var co=t=>!!t&&typeof t=="object"&&!Array.isArray(t);function dl(t){let{deleteCmd:e,describe:n,setCmd:s}=lo(t),r=t.topOrder,o=t.kinds.map(p=>Se(p.section)),i=new Map(t.kinds.map(p=>[Se(p.section),p])),a=t.entryGroups.map(p=>Se(p));function l(p){let g=t.objectOf(Se(p));if(g&&g.path===Se(p))return t.kinds.find(b=>b.kind===g.kind).section;let h=t.entryGroups.find(b=>p.length===b.length+1&&qt(b,p));if(h)return h}function c(p,g){let h=g.filter(w=>w.length&&!g.some(M=>M!==w&&M.length<w.length&&qt(M,w)));if(!h.length)return;let b=h.filter(w=>l(w));if(b.length===h.length){let w=new Map;for(let S of b){let P=Se(l(S));w.set(P,[...w.get(P)??[],S])}let M=[],y=[...o,...a];for(let S of[...w.keys()].sort((P,I)=>y.indexOf(P)-y.indexOf(I))){let P=rt(S),I=w.get(S).map(O=>ro(p,O)).filter(O=>!!O),_=" ".repeat(P.length);M.push(P.map((O,j)=>`${" ".repeat(j)}${O}:`).join(`
|
|
449
449
|
`)+`
|
|
450
|
-
`+
|
|
451
|
-
`).map(
|
|
450
|
+
`+I.map(O=>O.replace(/\n$/,"").split(`
|
|
451
|
+
`).map(j=>j&&_+j).join(`
|
|
452
452
|
`)).join(`
|
|
453
453
|
`)+`
|
|
454
|
-
`)}let T=b.length;return{text:M.join(""),what:T===1?n(b[0]):`${T} items`}}let
|
|
455
|
-
`)[0]}`};let
|
|
454
|
+
`)}let T=b.length;return{text:M.join(""),what:T===1?n(b[0]):`${T} items`}}let v=h.map(w=>typeof w[w.length-1]=="string"?ro(p,w):void 0).filter(w=>!!w);if(v.length)return{text:v.join(""),what:h.length===1?n(h[0]):`${h.length} keys`}}function d(p,g,h=[]){let b=ln(g);if(b.errors.length)return{what:"nothing",error:`the clipboard isn't YAML: ${b.errors[0].message.split(`
|
|
455
|
+
`)[0]}`};let v=b.toJS();if(!co(v)||!Object.keys(v).length)return{what:"nothing",error:"the clipboard holds no YAML map"};let w=new Set([...t.kinds.map(P=>String(P.section[0])),...t.entryGroups.map(P=>String(P[0]))]);if(Object.keys(v).every(P=>w.has(P)))return u(p,g,v);let y=[...new Map(h.map(P=>t.objectOf(Se(P))).filter(P=>!!P).map(P=>[P.path,rt(P.path)])).values()];if(!y.length)return{what:"nothing",error:`select a ${t.noun} to paste these keys onto`};let T=Object.entries(v),S=`Paste ${T.map(([P])=>P).join(", ")} onto ${y.length===1?n(y[0]):`${y.length} items`}`;return{what:S,cmd:{label:S,touched:y,build:P=>ns(P,y.flatMap(I=>T.map(([_,O])=>j=>s([...I,_],O).build(j))))}}}function u(p,g,h){let b=ln(p).toJS(),v=new Set;for(let $ of t.kinds){let x=Bs(b,$.section);if(co(x))for(let N of Object.keys(x))v.add(N)}let w=new Map(t.entryGroups.map($=>{let x=Bs(b,$);return[Se($),new Set(Object.keys(co(x)?x:{}))]})),M=[];for(let $ of[...o,...a]){let x=Bs(h,rt($));if(co(x))for(let N of Object.keys(x)){let F=w.get($)??v,J=N;if(F.has(J)){let oe=N.replace(/-\d+$/,""),ve=2;for(;F.has(`${oe}-${ve}`);)ve++;J=`${oe}-${ve}`}F.add(J),M.push({holder:rt($),name:N,to:J})}}if(!M.length)return{what:"nothing",error:"nothing to paste"};let y=new Map(M.filter($=>!w.has(Se($.holder))&&$.name!==$.to).map($=>[$.name,$.to])),T=g,S=$=>{for(let x of $.steps)T=yn(T,x)},P=$=>t.kinds.find(x=>x.kind===$)?.section??[];for(let $ of t.refs(h)){if($.slot.key)continue;let x=$.name!==void 0?y.get($.name):void 0;!x||!$.slot.targets.some(N=>co(Bs(h,P(N)))&&$.name in Bs(h,P(N)))||S(Fs(T,rt($.path),$.slot.rename?$.slot.rename($.value,x):x))}let I=[],_="";for(let $ of M){let x=i.get(Se($.holder)),N=x&&t.pasteDrops?.(b,{kind:x.kind,path:[...$.holder,$.name],value:Bs(h,[...$.holder,$.name])});N&&(S(js(T,N.path)),I.push($.to),_=N.why)}for(let $ of M)$.name!==$.to&&S(sr(T,[...$.holder,$.name],$.to));let O=ln(T).toJS(),j=M.length,k=j===1?`Paste ${i.get(Se(M[0].holder))?.singular??t.kinds[0]?.singular??"entry"} ${M[0].to}`:`Paste ${j} items`;return{what:k+(I.length?` (${I.join(", ")}: ${_})`:""),names:new Map(M.map($=>[$.name,$.to])),cmd:{label:w.has(Se(M[0].holder))&&j===1?`Paste ${M[0].holder.join(".")} entry ${M[0].to}`:k,select:M.map($=>[...$.holder,$.to]),build:$=>ns($,M.map(x=>N=>{let F=x.holder;if(!co(Bs(ln(N).toJS(),F)))return Tn(N,F.slice(0,-1),String(F[F.length-1]),{[x.to]:Bs(O,[...F,x.to])},{order:r});let oe=ro(T,[...F,x.to]);return oe?cl(N,F,x.to,oe,r):Tn(N,F,x.to,Bs(O,[...F,x.to]),{order:r})}))}}}function f(p,g){let h=c(p,g);if(!h)return;let b=g.filter(w=>w.length&&!g.some(M=>M!==w&&M.length<w.length&&qt(M,w))),v=[...b].sort((w,M)=>typeof w.at(-1)=="number"&&typeof M.at(-1)=="number"?M.at(-1)-w.at(-1):0);return{text:h.text,cmd:{label:`Cut ${h.what}`,remap:w=>b.some(M=>qt(M,w))?null:w,build:w=>ns(w,v.map(M=>y=>e(M).build(y)))}}}return{copyText:c,pasteCmd:d,cutCmd:f}}var Bs=(t,e)=>e.reduce((n,s)=>n&&typeof n=="object"?n[s]:void 0,t);var Kf=t=>{let e=t.data;return e&&typeof e=="object"&&!Array.isArray(e)?e:{}},_f=(t,e)=>e.reduce((n,s)=>n&&typeof n=="object"?n[s]:void 0,t);function ud(t,e){let n=_f(Kf(t),e.section);return n&&typeof n=="object"&&!Array.isArray(n)?Object.keys(n).filter(s=>!s.startsWith("x-")):[]}function ul(t,e,n,s){let r=nl(t,e),o=[],i=Kf(t);if(r.kind==="key"){let a=_f(i,r.path),l=a&&typeof a=="object"&&!Array.isArray(a)?a:{};if(n.isNameMap(r.path)){let c=Se(r.path);for(let[d,u]of Object.entries(s.snippets))d.split("#")[0]===c&&o.push({label:u.label,insert:u.body,kind:"snippet",snippet:!0,doc:u.doc,preferred:!0})}else{let c=" ".repeat(Math.max(0,r.start-(t.text.lastIndexOf(`
|
|
456
456
|
`,r.start-1)+1)));for(let d of n.keys(r.path,l)){if(d.name in l)continue;let u=r.flow||d.shape==="scalar"?": ":d.shape==="list"?`:
|
|
457
457
|
`+c+" - ":`:
|
|
458
|
-
`+c+" ",f=d.enumValues.length>1&&d.shape==="scalar"?`${d.name}: \${1|${d.enumValues.join(",")}|}`:d.name+u;o.push({label:d.name,insert:f,snippet:f.includes("${"),kind:"key",doc:d.doc,detail:d.enumValues.length?d.enumValues.join(" | "):d.shape==="map"?"map":d.shape==="list"?"list":void 0})}}}else{let a=r.kind==="item"?[...r.path,0]:r.path,l=
|
|
459
|
-
`)[0]??"")+" \u2026":b}return
|
|
460
|
-
`,a[0]),p=f>=0&&f<a[1]?f:a[1],g=e.pos(a[0]),h=e.pos(Math.max(p,a[0]+1));return{...r,startLine:g.line,startCol:g.col,endLine:h.line,endCol:h.col}}let l=Math.max(1,n.line),c=Math.max(1,n.col),d=e.offset(l,c),u=/^[^\s,:{}[\]]+/.exec(e.text.slice(d));return{...r,startLine:l,startCol:c,endLine:l,endCol:c+Math.max(1,u?u[0].length:1)}}var
|
|
458
|
+
`+c+" ",f=d.enumValues.length>1&&d.shape==="scalar"?`${d.name}: \${1|${d.enumValues.join(",")}|}`:d.name+u;o.push({label:d.name,insert:f,snippet:f.includes("${"),kind:"key",doc:d.doc,detail:d.enumValues.length?d.enumValues.join(" | "):d.shape==="map"?"map":d.shape==="list"?"list":void 0})}}}else{let a=r.kind==="item"?[...r.path,0]:r.path,l=Se(a),c=s.slotAt(l);if(c){for(let d of c.targets){let u=s.kinds.find(f=>f.kind===d);if(u)for(let f of ud(t,u))o.push({label:c.write?c.write(f):f,insert:c.write?c.write(f):f,kind:"ref",detail:`${u.singular} \xB7 declared`,preferred:!0})}for(let d of c.extra??[])o.push({label:d,insert:/[{*]/.test(d)?JSON.stringify(d):d,kind:"value",detail:s.extraDetail?.(d,i)})}for(let d of n.values(a))o.some(u=>u.label===d)||o.push({label:d,insert:d,kind:"value"});if(!o.length){let d=n.keys(r.path.slice(0,-1)).find(u=>u.name===String(r.path[r.path.length-1]));for(let u of d?.examples??[])typeof u=="string"&&o.push({label:u,insert:u,kind:"value",detail:"example"})}}return{items:o,start:r.start,path:r.path,context:r.kind}}var Ks=t=>Ge(t.key)?String(t.key.value):String(t.key);function fl(t,e,n="main",s){let r=t.text,o=t.data??{},i=g=>{if(!g)return"";let h=g.range;if(h&&h[1]>h[0]){let b=r.slice(h[0],h[1]).replace(/\s+$/,"");return/^[|>]/.test(b)?(String(g.value??"").split(`
|
|
459
|
+
`)[0]??"")+" \u2026":b}return Ge(g)?String(g.value??""):""},a=(g,h,b,v,w)=>{let M=Se(h),y=typeof h[h.length-1]=="string"&&String(h[h.length-1]).startsWith("x-");if(ct(g))return{id:M,path:h,kind:v,label:b,shape:"map",section:w,ext:y,children:g.items.map(S=>a(S.value,[...h,Ks(S)],Ks(S),"key"))};if(Lt(g))return{id:M,path:h,kind:v,label:b,shape:"list",section:w,ext:y,value:g.items.length?void 0:"[]",children:g.items.map((S,P)=>a(S,[...h,P],Ge(S)?i(S):`${P+1}`,"item"))};let T={id:M,path:h,kind:v,label:b,shape:"scalar",value:i(g),section:w,ext:y,children:[]};return v==="item"&&(T.label=T.value??"",delete T.value),T},l=t.doc.contents,c=ct(l)?l.items:[],d=g=>c.find(h=>Ks(h)===g),u=[],f=new Set;for(let g of e.outline.first){let h=d(g);h&&(u.push(a(h.value,[g],g,"key")),f.add(g))}let p=new Set;if(n==="main"){for(let g of e.outline.kinds){let h=e.kinds.find(y=>y.kind===g),b=h.section.map(String),v=d(b[0]);b.length===1?f.add(b[0]):p.add(b[0]);let w=v?.value;b.length>1&&(w=ct(w)?w.items.find(y=>Ks(y)===b[1])?.value:void 0);let M={id:Se(b),path:b,kind:"group",label:h.group,section:h.kind,shape:ct(w)?"map":"missing",children:[]};if(ct(w))for(let y of w.items){let T=Ks(y);if(T.startsWith("x-")){M.children.push(a(y.value,[...b,T],T,"key"));continue}let S=a(y.value,[...b,T],T,"resource",h.kind),P=s?.get(T)??e.outline.tag?.(h.kind,T,Gm(o,[...b,T]),o);P!==void 0&&(S.lifetime=P),M.children.push(S)}u.push(M)}for(let g of p){let h=d(g),b=new Set(e.kinds.filter(v=>String(v.section[0])===g).map(v=>String(v.section[1])));if(h&&ct(h.value)){f.add(g);for(let v of h.value.items)b.has(Ks(v))||u.push(a(v.value,[g,Ks(v)],`${g}.${Ks(v)}`,"key"))}else h&&f.add(g)}}for(let{key:g,label:h,when:b}of e.outline.groups){let v=d(g);f.add(g),v?u.push({...a(v.value,[g],h,"group"),kind:"group"}):n!=="other"&&(!b||b(o))&&u.push({id:"/"+g,path:[g],kind:"group",label:h,shape:"missing",children:[]})}for(let g of c){let h=Ks(g);!f.has(h)&&tt(g)&&u.push(a(g.value,[h],h,"key"))}return{id:"",path:[],kind:"root",label:e.outline.rootLabel(o,n),shape:"map",children:u}}var Gm=(t,e)=>e.reduce((n,s)=>n&&typeof n=="object"?n[s]:void 0,t);function fd(t,e=[]){e.push(t);for(let n of t.children)fd(n,e);return e}function pl(t,e,n){let s=new Nn(e),r=t.read(e,{fileName:n.fileName,defaults:n.defaults,profiles:n.profiles,role:t.role(e)});return{problems:[...n.extendsDiags??[],...r.diags].map(i=>pd(t,s,i,n.fileName)),tags:r.tags??new Map,read:r.read}}function pd(t,e,n,s){let r={severity:n.severity,message:n.message,hint:n.hint,path:n.path};if(n.file&&n.file!==s){let f=e.rangeOf(["extends"])??[0,0],p=e.pos(f[0]),g=e.pos(f[1]);return{...r,message:`${n.file}:${n.line}: ${n.message}`,file:n.file,startLine:p.line,startCol:p.col,endLine:g.line,endCol:g.col}}let o=rt(n.path),i=t.objectOf(n.path)?.path===n.path,a=o.length?e.rangeOf(o,i||t.keyMessage.test(n.message)?"key":"value"):void 0;if(a&&a[1]>a[0]){let f=e.text.indexOf(`
|
|
460
|
+
`,a[0]),p=f>=0&&f<a[1]?f:a[1],g=e.pos(a[0]),h=e.pos(Math.max(p,a[0]+1));return{...r,startLine:g.line,startCol:g.col,endLine:h.line,endCol:h.col}}let l=Math.max(1,n.line),c=Math.max(1,n.col),d=e.offset(l,c),u=/^[^\s,:{}[\]]+/.exec(e.text.slice(d));return{...r,startLine:l,startCol:c,endLine:l,endCol:c+Math.max(1,u?u[0].length:1)}}var md;function ml(t){return md?.text!==t&&(md=new Nn(t)),md}function hl(t){let e=new Map,n=c=>{let d=e.get(c);return d||e.set(c,d=new io(c)),d},s=c=>{let d=t.role(c)==="base"?"base":"main";return n(t.schema(d,c))},r=c=>t.kinds.find(d=>d.kind===c)?.section??[];function o(c,d){let u=ul(c,d,s(c.text),t),f=u.items.map((p,g)=>({it:p,i:g})).sort((p,g)=>+!!g.it.preferred-+!!p.it.preferred||p.i-g.i).map(p=>p.it);return{from:u.start,items:f}}function i(c,d){let u=c.at(d);if(!u.path.length||u.where==="inside")return null;let f=[],p=s(c.text).hover(u.path);p&&f.push(`**${u.path.join(".")}**
|
|
461
461
|
|
|
462
|
-
${p}`);let g=l.refs(c.data).find(b=>b.path===
|
|
462
|
+
${p}`);let g=l.refs(c.data).find(b=>b.path===Se(u.path));if(g?.name){let b=g.slot.targets.map(v=>[...r(v),g.name]).find(v=>c.rangeOf(v));f.push(b?`\u2192 \`${b.join(".")}\` (line ${c.pos(c.rangeOf(b,"key")[0]).line}; \u2318-click to go there)`:`\u2192 no ${g.slot.targets.join("/")} named \`${g.name}\``)}if(!f.length)return null;let h=c.rangeOf(u.path,u.where==="key"?"key":"value")??[d,d];return{from:h[0],to:h[1],parts:f}}function a(c,d){let u=c.at(d);if(u.path[0]==="extends"&&u.where!=="key"){let p=c.nodeAt(u.path);if(typeof p?.value=="string")return{open:p.value}}let f=l.refs(c.data).find(p=>p.path===Se(u.path));if(!f?.name)return null;for(let p of f.slot.targets){let g=c.rangeOf([...r(p),f.name],"key");if(g)return{from:g[0],to:g[1]}}return null}let l=t;return{navFor:s,completionAt:o,hoverAt:i,definitionAt:a}}function gl(t,e){return t.rangeOf(e,"pair")??t.rangeOf(e)}function bl(t,e){let n=[0];for(let o=t.indexOf(`
|
|
463
463
|
`);o>=0;o=t.indexOf(`
|
|
464
|
-
`,o+1))n.push(o+1);let s=(o,i)=>{let a=Math.min(Math.max(o,1),n.length),l=a<n.length?n[a]-1:t.length;return Math.min(n[a-1]+Math.max(i,1)-1,l)},r=s(e.startLine,e.startCol);return[r,Math.max(r,s(e.endLine,e.endCol))]}function yf(t){return t.replace(/\$\{(\d+)\|([^|}]*)\|\}/g,(e,n,s)=>`\${${n}:${s.split(",")[0]}}`).replace(/\$\{0\}/g,"${}")}function xf(t){return t.split(/\n{2,}/).map(e=>{let n=[];for(let s of e.matchAll(/\*\*([^*]+)\*\*|`([^`]+)`|([^*`]+|[*`])/g))s[1]!==void 0?n.push({kind:"bold",text:s[1]}):s[2]!==void 0?n.push({kind:"code",text:s[2]}):n.push({kind:"text",text:s[3]});return n})}var tl=null;function pr(t){tl=t}function Hs(){return tl&&tl.isConnected?tl:document.body}var wf="http://www.w3.org/2000/svg";function Wt(t,e=""){let n=document.createElementNS(wf,"svg");n.setAttribute("class",`icon${e?" "+e:""}`),n.setAttribute("aria-hidden","true");let s=document.createElementNS(wf,"use");return s.setAttribute("href",`#se-i-${t}`),n.append(s),n}function mr(t,e,n){return new Promise(s=>{let r=z("dialog",{class:"dlg","aria-label":t}),o=z("form",{method:"dialog"}),i=z("div",{class:"dlg-foot"});for(let a of n){let l=z("button",{type:"submit",value:a.value,class:`btn${a.primary?" primary":""}${a.danger?" danger":""}`},a.label);i.append(l)}o.append(z("div",{class:"dlg-head"},z("h2",{class:"h-title"},t)),z("div",{class:"dlg-body"},...e),i),r.append(o),Hs().append(r),r.addEventListener("close",()=>{let a=r.returnValue;r.remove(),s(a&&a!=="cancel"?a:null)}),r.showModal(),i.querySelector(".primary")?.focus()})}var Uo,vf=()=>!!Uo;function is(t,e,n="Actions"){Uo?.close(!1);let s=document.activeElement,r=z("div",{class:"menu",role:"menu","aria-label":n,tabindex:"-1"}),o=[];for(let g of t){if("sep"in g){r.append(z("div",{class:"menu-sep",role:"separator"}));continue}if("heading"in g){r.append(z("div",{class:"menu-label"},g.heading));continue}let h=(g.disabled?g.why:void 0)??g.desc,b=z("button",{type:"button",role:"menuitem",tabindex:"-1",class:"menu-item"+(g.danger?" danger":""),"data-desc":h,"aria-description":h},g.icon?Wt(g.icon):z("span"),z("span",{class:"mi-label"},g.label),g.keys?z("span",{class:"menu-trail"},g.keys):null);g.disabled&&(b.disabled=!0),b.addEventListener("click",k=>{k.stopPropagation(),!b.disabled&&(p(!0),g.onSelect())}),o.push(b),r.append(b)}Hs().append(r);let i=r.getBoundingClientRect(),a,l;if(e instanceof HTMLElement){let g=e.getBoundingClientRect();a=g.left,l=g.bottom+4,l+i.height>innerHeight-8&&(l=g.top-i.height-4)}else a=e.x,l=e.y,l+i.height>innerHeight-8&&(l=Math.max(8,e.y-i.height));r.style.left=`${Math.max(8,Math.min(a,innerWidth-i.width-8))}px`,r.style.top=`${Math.max(8,l)}px`;let c=()=>o.filter(g=>!g.disabled),d=g=>{let h=c();h.length&&h[(g+h.length)%h.length].focus()};d(0),r.addEventListener("keydown",g=>{let b=c().indexOf(document.activeElement);g.key==="ArrowDown"?(d(b+1),g.preventDefault()):g.key==="ArrowUp"?(d(b-1),g.preventDefault()):g.key==="Home"?(d(0),g.preventDefault()):g.key==="End"?(d(-1),g.preventDefault()):(g.key==="Escape"||g.key==="Tab")&&(p(!0),g.preventDefault()),g.stopPropagation()});let u=g=>{r.contains(g.target)||p(!1)};setTimeout(()=>{addEventListener("pointerdown",u,!0),addEventListener("blur",f)},0);let f=()=>p(!1);function p(g){r.isConnected&&(r.remove(),removeEventListener("pointerdown",u,!0),removeEventListener("blur",f),Uo=void 0,g&&s?.focus())}return Uo={el:r,close:p},r}function nl(){Uo?.close(!1)}var kf=150,Ys=t=>t.kind==="do"&&t.origin==="text";function qs(t,e=150){let n=0,s=()=>{n=0,t()},r=()=>{clearTimeout(n),n=window.setTimeout(s,e)};return r.now=()=>{clearTimeout(n),s()},r.pending=()=>n!==0,r.cancel=()=>{clearTimeout(n),n=0},r}function sl(t,e){return t.map((n,s)=>s===0?{...n,keys:[...n.keys.slice(0,1),...e,...n.keys.slice(1)]}:n)}function rl(t){let e=z("dialog",{class:"dlg keys-dlg","aria-label":"Keyboard"}),n=z("form",{method:"dialog"}),s=z("div",{class:"dlg-body keys"});for(let r of t){s.append(z("h3",{class:"keys-h"},r.where));let o=z("dl",{class:"keys-list"});for(let[i,a]of r.keys)o.append(z("dt",null,...i.split(/(\s+or\s+|,\s*)/).map(l=>/^\s+or\s+$|^,\s*$/.test(l)?l:z("kbd",null,l))),z("dd",null,a));s.append(o)}return n.append(z("div",{class:"dlg-head"},z("h2",{class:"h-title"},"Keyboard")),s,z("div",{class:"dlg-foot"},z("button",{type:"submit",class:"btn primary",value:"close"},"Close"))),e.append(n),e.addEventListener("close",()=>e.remove()),Hs().append(e),e.showModal(),e}function ol(t,e,n){let{copyText:s,cutCmd:r,pasteCmd:o}=n,i="",a=()=>!t.doc.ok,l=f=>!!f?.closest?.("input, textarea, select, .monaco-editor, [contenteditable]"),c=()=>{let f=s(t.text,t.selection);if(!f){e("Select something to copy");return}return i=f.text,e(`Copied ${f.what}`),f.text},d=()=>{if(a()){e("Fix the YAML first","warn");return}let f=r(t.text,t.selection);if(!f){e("Select something to cut");return}return i=f.text,t.apply(f.cmd,"menu"),t.select([],"menu"),f.text},u=f=>{if(a())return e("Fix the YAML first","warn"),!1;let p=o(t.text,f,t.selection);if(!p.cmd)return e(`Can't paste: ${p.error}`,"warn"),!1;try{if(!t.apply(p.cmd,"menu"))return!1}catch(h){return e(`Can't paste: ${h.message}`,"bad"),!1}p.cmd.select&&t.select(p.cmd.select,"menu");let g=p.names?[...p.names].filter(([h,b])=>h!==b):[];return e(g.length?`${p.what}: ${g.map(([h,b])=>`${h} \u2192 ${b}`).join(", ")}`:p.what),!0};return{items(){let f=t.selection.length>0;return[{label:"Cut",icon:"clipboard",keys:"\u2318X",disabled:!f||a(),why:f?"Fix the YAML first":"Nothing selected",onSelect:()=>{this.cut()}},{label:"Copy",icon:"copy",keys:"\u2318C",disabled:!f,why:"Nothing selected",onSelect:()=>{this.copy()}},{label:"Paste",icon:"clipboard-paste",keys:"\u2318V",disabled:a(),why:"Fix the YAML first",onSelect:()=>{this.paste()}}]},attach(f,p){let g=k=>{let v=k;if(l(v.target)||!p(v.target))return;let M=c();M!==void 0&&(v.clipboardData?.setData("text/plain",M),v.preventDefault())},h=k=>{let v=k;if(l(v.target)||!p(v.target))return;let M=d();M!==void 0&&(v.clipboardData?.setData("text/plain",M),v.preventDefault())},b=k=>{let v=k;if(l(v.target)||!p(v.target))return;let M=v.clipboardData?.getData("text/plain")??"";v.preventDefault(),u(M||i)};return f.addEventListener("copy",g),f.addEventListener("cut",h),f.addEventListener("paste",b),()=>{f.removeEventListener("copy",g),f.removeEventListener("cut",h),f.removeEventListener("paste",b)}},async copy(){let f=c();if(f===void 0)return!1;try{await navigator.clipboard.writeText(f)}catch{}return!0},async cut(){let f=d();if(f===void 0)return!1;try{await navigator.clipboard.writeText(f)}catch{}return!0},async paste(f){let p=f;if(p===void 0)try{p=await navigator.clipboard.readText()}catch{p=i}return p?u(p):(e("The clipboard is empty"),!1)}}}function il(t,e,n){let s=n.kit,r=s.ui,{setCmd:o,insertCmd:i,insertItemCmd:a,deleteCmd:l,renameCmd:c,renameKeyCmd:d,duplicateCmd:u,moveCmd:f,moveItemCmd:p,referencesTo:g,describe:h,freshName:b}=s.commands,k=E=>s.kinds.find(Y=>Y.kind===E),v=E=>E.id==="",M=E=>s.entryGroups.some(Y=>E.length===Y.length+1&&Vt(Y,E)),x=E=>s.entryGroups.some(Y=>Y.length===E.length&&Vt(Y,E)),T=new Set(["",...s.kinds.map(E=>Me(E.section)),...s.entryGroups.map(E=>Me(E))]),y="",A="",D,K=[],C=new Map,_="",S=0,$=()=>new Set(e.selection.map(Me)),w=()=>!e.doc.ok;t.setAttribute("role","tree"),t.setAttribute("aria-label",r.label),t.setAttribute("aria-multiselectable","true"),t.classList.add("tree");function N(){let E=s.outline(e.goodDoc,n.role(),n.lifetimes());K=[];let Y=(Z,Se,ue)=>{if(K.push({n:Z,depth:Se,parent:ue}),T.has(Z.id))for(let Ke of Z.children)Y(Ke,Se+1,Z);D?.mode==="new"&&Me(D.mapPath)===Z.id&&T.has(Z.id)&&K.push({n:{id:D.id,path:[...D.mapPath,""],kind:"resource",label:"",shape:"scalar",children:[]},depth:Se+1,parent:Z})};Y(E,0),C=new Map(K.map(Z=>[Z.n.id,Z])),C.has(y)||(y=K[0]?.n.id??"");let q=$(),de=F(),m=document.createDocumentFragment();w()&&m.append(z("div",{class:"callout compact warn tree-note",role:"status"},z("span",{class:"c-body"},`Fix the YAML at line ${e.doc.doc.errors[0]?e.doc.pos(e.doc.doc.errors[0].pos[0]).line:"?"} to edit here; the tree shows the last version that read cleanly.`)));for(let{n:Z,depth:Se}of K)m.append(ae(Z,Se,q.has(Z.id),de.get(Z.id)));let O=t.contains(document.activeElement);t.replaceChildren(m);let L=t.querySelector(`[data-id="${CSS.escape(y)}"]`);L&&(L.tabIndex=0);let G=t.querySelector(".tedit");G?(G.focus(),G instanceof HTMLInputElement&&G.select()):O&&L&&!t.contains(document.activeElement)&&L.focus({preventScroll:!0})}function F(){let E=new Map;for(let Y of n.problems()){if(Y.file)continue;let q=nt(Y.path);for(let de=1;de<=q.length;de++){let m=Me(q.slice(0,de)),O=E.get(m)??{e:0,w:0};Y.severity==="error"?O.e++:O.w++,E.set(m,O)}}return E}function J(E){if(v(E))return r.rootIcon;if(E.section)return r.kindIcon(E.section);let Y=String(E.path[E.path.length-1]??"");return E.path.length===1&&r.keyIcon(Y)?r.keyIcon(Y):M(E.path)?r.entryIcon(String(E.path[0])):E.shape==="list"?"list":E.shape==="map"?"list-tree":"circle-dot"}function ae(E,Y,q,de){let m=T.has(E.id),O=E.children.length>0||E.shape==="missing"&&!1,L=z("div",{class:`trow k-${E.kind}${q?" selected":""}${E.shape==="missing"?" missing":""}${E.ext?" ext":""}`,role:"treeitem","aria-level":Y+1,"aria-selected":String(q),"aria-expanded":E.children.length?String(m):void 0,tabindex:"-1","data-id":E.id,draggable:X(E)?"true":void 0,"aria-label":we(E)});L.style.setProperty("--depth",String(Y));let G=z("span",{class:"twisty","aria-hidden":"true"},O?Wt(m?"chevron-down":"chevron-right"):"");G.addEventListener("click",ue=>{ue.stopPropagation(),j(E.id)}),L.append(G,Wt(J(E),"ticon"));let Z=D&&D.id===E.id?D:void 0;Z&&(Z.mode==="rename"||Z.mode==="new")?L.append(ze(E,Z)):L.append(z("span",{class:"tlabel"},E.label||(E.kind==="item"?'""':""))),Z?.mode==="value"?L.append(Ee(E)):E.value!==void 0&&E.kind!=="item"?L.append(z("span",{class:"tval"},E.value)):E.shape==="missing"?L.append(z("span",{class:"tval none"},"none")):E.kind==="group"&&E.children.length&&L.append(z("span",{class:"tcount"},String(E.children.length)));let Se=E.lifetime?r.tagPill(E.lifetime):void 0;if(Se&&L.append(z("span",{class:`tpill l-${E.lifetime}`,title:Se.title},E.lifetime)),de?.e?L.append(z("span",{class:"count bad",title:`${de.e} error${de.e>1?"s":""}`},String(de.e))):de?.w&&L.append(z("span",{class:"count warn",title:`${de.w} warning${de.w>1?"s":""}`},String(de.w))),!w()&&ne(E).length){let ue=z("button",{type:"button",class:"tadd btn sm quiet icon-only",tabindex:"-1","aria-label":`Add to ${E.label||r.text.rootAdd}`,title:"Add\u2026"},Wt("plus"));ue.addEventListener("click",Ke=>{Ke.stopPropagation(),U(E.id),is(ne(E),ue,`Add to ${E.label}`)}),L.append(ue)}return L}let we=E=>[E.kind==="group"?`${E.label}, ${E.shape==="missing"?"none":E.children.length}`:E.label,E.value!==void 0&&E.kind!=="item"?`: ${E.value}`:"",E.lifetime&&E.lifetime!=="run"?`, ${E.lifetime}`:""].join("");function j(E,Y){Y??!T.has(E)?T.add(E):T.delete(E),N()}function U(E){y=E;for(let q of t.querySelectorAll(".trow"))q.tabIndex=q.dataset.id===E?0:-1;let Y=t.querySelector(`[data-id="${CSS.escape(E)}"]`);Y?.focus({preventScroll:!0}),Y?.scrollIntoView({block:"nearest"})}function ee(E,Y=E[E.length-1]){Y!==void 0&&(y=Y,U(y)),e.select(E.map(nt),"tree"),N(),U(y)}function fe(E,Y){if(Y.shiftKey&&A){let q=K.map(O=>O.n.id),de=q.indexOf(A),m=q.indexOf(E);if(de>=0&&m>=0){ee(q.slice(Math.min(de,m),Math.max(de,m)+1),E);return}}if(Y.metaKey||Y.ctrlKey){let q=$();q.has(E)?q.delete(E):q.add(E),A=E,ee([...q],E);return}A=E,ee([E])}function B(E){for(let Y of E)for(let q=0;q<Y.length;q++)T.add(Me(Y.slice(0,q)));if(E[0]){let Y=Me(E[0]);for(N();!C.has(Y)&&Y;)Y=Y.replace(/\/[^/]*$/,"");y=Y}N(),t.querySelector(`[data-id="${CSS.escape(y)}"]`)?.scrollIntoView({block:"nearest"})}let X=E=>!w()&&!v(E)&&E.kind!=="group"&&E.path.length>1||E.kind==="item",Q=E=>E.kind==="resource"&&!!E.section,te=E=>E.kind==="group"&&(!!E.section||x(E.path));function ne(E){if(w())return[];let Y=n.nav(),q=[],de=e.goodDoc.data;if(v(E)){for(let G of s.kinds){if(n.role()!=="main")break;q.push({label:`New ${G.singular}`,icon:r.kindIcon(G.kind),onSelect:()=>Pe(G.kind)})}let m=new Set(E.children.filter(G=>G.shape!=="missing").map(G=>String(G.path[0]))),O=new Set(s.kinds.map(G=>String(G.section[0]))),L=Y.keys([],de??{}).filter(G=>!m.has(G.name)&&!O.has(G.name)&&!(de&&G.name in de));return L.length&&q.push({sep:!0},{heading:"Settings"},...L.map(G=>({label:G.name,desc:ye(G.doc),onSelect:()=>$e([],G.name)}))),q}if(E.kind==="group"&&E.section){let m=E.section;for(let O of r.newItems(m))q.push({label:O.label,icon:O.icon,desc:O.desc,onSelect:()=>Pe(m,O.template,O.stem)});return q}if(x(E.path)&&r.entryItems)return me(E.path);if(E.shape==="missing")return[{label:`Add ${E.label}`,icon:"plus",onSelect:()=>$e([],String(E.path[0]),!0)}];if(E.shape==="list"){let m=s.slotAt(Me([...E.path,0])),O=new Set(E.children.map(L=>L.label));if(m){for(let L of m.targets)for(let G of Re(L))O.has(m.write?m.write(G):G)||q.push({label:m.write?m.write(G):G,icon:r.kindIcon(L),desc:`${k(L).singular}`,onSelect:()=>re(a(E.path,m.write?m.write(G):G,void 0,`Add ${G} to ${h(E.path)}`))});for(let L of m.extra??[])O.has(L)||q.push({label:L,onSelect:()=>re(a(E.path,L,void 0,`Add ${L} to ${h(E.path)}`))})}for(let L of Y.values([...E.path,0]))O.has(L)||q.push({label:L,onSelect:()=>re(a(E.path,L))});return q.push({label:"New item",icon:"plus",onSelect:()=>{re(a(E.path,""));let L=[...E.path,E.children.length];be(Me(L),"value")}}),q}if(E.shape==="map"||E.kind==="resource"){let m=xe(de,E.path),O=m&&typeof m=="object"&&!Array.isArray(m)?m:{};for(let L of Y.keys(E.path,O))L.name in O||q.push({label:L.name,desc:ye(L.doc),onSelect:()=>$e(E.path,L.name)});return q}return q}function me(E){let Y=e.goodDoc.data??{},q=xe(Y,E)??{};return r.entryItems(E,Y,Ue).filter(de=>!de.when||de.when(Y)).map(de=>({label:de.label,icon:de.icon,onSelect:()=>{re(i(E,I(Object.keys(q),de.entry),de.value,de.cmdLabel?{label:de.cmdLabel}:{}))}}))}let ye=E=>E?.split(/(?<=\.)\s/)[0]?.replace(/`/g,""),xe=(E,Y)=>Y.reduce((q,de)=>q&&typeof q=="object"?q[de]:void 0,E),Re=E=>{let Y=xe(e.goodDoc.data,k(E).section);return Y&&typeof Y=="object"?Object.keys(Y).filter(q=>!q.startsWith("x-")):[]},Ue=E=>{let Y=xe(e.goodDoc.data,k(E).section);return Y?Object.keys(Y).filter(q=>!q.startsWith("x-")&&!(Y[q]&&typeof Y[q]=="object"&&"external"in Y[q])):[]},I=(E,Y)=>{if(!E.includes(Y))return Y;let q=2;for(;E.includes(`${Y}-${q}`);)q++;return`${Y}-${q}`};function re(E){try{return e.apply(E,"tree")}catch(Y){return n.note(String(Y.message),"bad"),!1}}function $e(E,Y,q=!1){let de=n.nav(),m=q?{}:de.defaultFor([...E,Y]);if(re(i(E,Y,m))){T.add(Me(E));let O=Me([...E,Y]);y=O,m===""||typeof m=="number"?be(O,"value"):(N(),U(O))}}function Pe(E,Y=k(E).template,q=k(E).singular){let de=k(E).section;T.add(Me(de)),D={id:"#new",mode:"new",section:E,mapPath:de,template:Y,value:b(e.text,q)},N()}function be(E,Y){if(w())return;let q=C.get(E);if(!q){N();return}Y==="rename"&&(q.n.kind==="group"||v(q.n)||q.n.kind==="item")||Y==="value"&&q.n.shape!=="scalar"||(D={id:E,mode:Y},y=E,N())}function ce(E=!0){D=void 0,N(),E&&U(y)}function ze(E,Y){let q=Y.mode==="new"?String(Y.value??""):String(E.path[E.path.length-1]),de=z("input",{class:"tedit tname",value:q,"aria-label":Y.mode==="new"?`Name of the new ${Y.section?k(Y.section).singular:"entry"}`:`Rename ${E.label}`,spellcheck:"false",autocomplete:"off"});de.value=q;let m=()=>{let G=de.value.trim(),Z=Y.mode==="new"||Q(E)||M(E.path),Se=G?Z&&!s.nameRule.test(G)?r.nameHint:G!==q&&Oe(Y.mode==="new"?Y.mapPath:E.path.slice(0,-1),G,Z)?`"${G}" is already used`:"":"a name is needed";return de.setAttribute("aria-invalid",String(!!Se)),de.title=Se,Se?void 0:G};de.addEventListener("input",m),de.addEventListener("keydown",G=>{G.stopPropagation(),G.key==="Escape"&&(G.preventDefault(),ce()),G.key==="Enter"&&(G.preventDefault(),L())});let O=!1,L=()=>{if(O)return;let G=m();if(G===void 0){de.value.trim()||(O=!0,ce());return}if(O=!0,D=void 0,Y.mode==="new"){let Z=[...Y.mapPath,G];re(i(Y.mapPath,G,Y.template(),{label:`Add ${Y.section?k(Y.section).singular:"entry"} ${G}`}))&&(y=Me(Z),e.select([Z],"tree"),T.add(y))}else if(G!==q){let Z=E.path;if(re(Q(E)?c(Z,G):d(Z,G))){let Se=[...Z.slice(0,-1),G];T.has(E.id)&&(T.delete(E.id),T.add(Me(Se))),y=Me(Se)}}N(),U(y)};return de.addEventListener("blur",()=>{O||(de.value.trim()&&m()!==void 0?L():(O=!0,D=void 0,N()))}),de}function Oe(E,Y,q){if(q&&!x(E))return s.kinds.some(m=>Re(m.kind).includes(Y));let de=xe(e.goodDoc.data,E);return!!de&&typeof de=="object"&&Y in de}function Ee(E){let Y=n.nav(),q=xe(e.goodDoc.data,E.path),de=Y.values(E.path),m=s.slotAt(Me(E.path)),O=m?m.targets.flatMap(Z=>Re(Z).map(Se=>m.write?m.write(Se):Se)).concat(m.extra??[]):[],L=[...new Set([...de,...O])],G;return L.length&&(de.length||m)?(G=z("select",{class:"tedit tvalue","aria-label":`Value of ${E.label}`},...L.map(Z=>z("option",{value:Z},Z))),L.includes(String(q))||G.prepend(z("option",{value:String(q??"")},String(q??""))),G.value=String(q??""),G.addEventListener("change",()=>Be(E,G.value))):(G=z("input",{class:"tedit tvalue","aria-label":`Value of ${E.label}`,spellcheck:"false",autocomplete:"off"}),G.value=q==null?"":String(q)),G.addEventListener("keydown",Z=>{Z.stopPropagation(),Z.key==="Escape"&&(Z.preventDefault(),ce()),Z.key==="Enter"&&(Z.preventDefault(),Be(E,G.value))}),G.addEventListener("blur",()=>{D?.id===E.id&&Be(E,G.value,!1)}),G}function Be(E,Y,q=!0){if(D?.id!==E.id)return;D=void 0;let de=n.nav().types(E.path),m=xe(e.goodDoc.data,E.path),O=Y;(de.has("integer")||de.has("number")||typeof m=="number")&&/^-?\d+(\.\d+)?$/.test(Y.trim())?O=Number(Y):(de.has("boolean")||typeof m=="boolean")&&/^(true|false)$/.test(Y.trim())&&(O=Y.trim()==="true"),O!==m&&re(o(E.path,O)),N(),q&&U(y)}async function it(E){if(w()||!E.length)return;let Y=E.map(ue=>C.get(ue)?.n).filter(ue=>!!ue&&!v(ue)&&ue.shape!=="missing"),q=Y.filter(ue=>!Y.some(Ke=>Ke!==ue&&Ke.path.length<ue.path.length&&Vt(Ke.path,ue.path)));if(!q.length)return;let de=!1,m=q.filter(Q).flatMap(ue=>g(e.text,ue.section,String(ue.path[ue.path.length-1])).filter(Ke=>!q.some(Ye=>Vt(Ye.path,nt(Ke.path)))).map(Ke=>({n:ue,r:Ke})));if(m.length){let ue=z("ul",{class:"ref-list"},...m.map(({n:Ie,r:De})=>z("li",null,z("code",null,De.path.slice(1).replace(/\//g,".")),` \u2014 ${De.slot.what} (${Ie.label})`))),Ke=q.length===1?h(q[0].path):`${q.length} items`,Ye=await mr(`Delete ${Ke}?`,[z("p",{class:"sub"},`${m.length===1?"One place refers":`${m.length} places refer`} to ${q.length===1?"it":"them"}:`),ue,z("p",{class:"sub"},"Delete the references too, or leave them (the problems list will show them). Either way, Undo brings everything back.")],[{label:"Cancel",value:"cancel"},{label:"Delete only",value:"only",danger:!0},{label:"Delete with references",value:"with",danger:!0,primary:!0}]);if(!Ye){U(y);return}de=Ye==="with"}let L=[...q].sort((ue,Ke)=>typeof ue.path.at(-1)=="number"&&typeof Ke.path.at(-1)=="number"?Ke.path.at(-1)-ue.path.at(-1):0).map(ue=>l(ue.path,{withRefs:de&&Q(ue)})),G=K.findIndex(ue=>ue.n.id===q[0].id),Z=K[G+1]?.n.id&&!q.some(ue=>K[G+1].n.id.startsWith(ue.id))?K[G+1].n.id:K[G-1]?.n.id??"";re(L.length===1?L[0]:We(`Delete ${q.length} items`,L))&&(y=Z,e.select(Z?[nt(Z)]:[],"tree"),N(),U(y))}function We(E,Y){return{label:E,remap:q=>Y.reduce((de,m)=>de&&m.remap?m.remap(de):de,q),build:q=>{let de=[],m=!1;for(let O of Y){let L=O.build(q);for(let G of L.steps)de.push(G),q=dn(q,G);m||=!!L.fallback}return{steps:de,fallback:m}}}}function Ne(E){let Y=C.get(E)?.n;if(!Y||w())return;if(!Q(Y)){n.note(r.text.duplicateNote,"info");return}let q=u(Y.path);if(re(q)){let de=q.select?.[0];de&&(y=Me(de),e.select([de],"tree")),N(),U(y)}}function gt(E,Y){let q=$().has(E.id)?[...$()]:[E.id],de=q.length>1,m=ne(E),O=w(),L=[];m.length&&!de&&L.push({heading:"Add"},...m.slice(0,12),...m.length>12?[{label:"More\u2026",icon:"plus",onSelect:()=>is(m,Y,"Add")}]:[],{sep:!0}),de||(L.push({label:"Rename",icon:"pencil",keys:"F2",disabled:O||E.kind==="group"||v(E)||E.kind==="item",why:r.text.renameWhy,onSelect:()=>be(E.id,"rename")}),E.shape==="scalar"&&L.push({label:"Edit value",icon:"pencil",keys:"Enter",disabled:O,onSelect:()=>be(E.id,"value")}),L.push({label:"Duplicate",icon:"copy",keys:"\u2318D",disabled:O||!Q(E),why:r.text.duplicateWhy,onSelect:()=>Ne(E.id)})),E.path.length&&L.push({label:"Select parent",icon:"arrow-up-right",keys:"\u2318\u2191",onSelect:()=>Ze()}),L.push({label:"Show in text",icon:"code-xml",onSelect:()=>n.showInText(E.path)}),n.clipItems&&L.push({sep:!0},...n.clipItems()),L.push({sep:!0},{label:de?`Delete ${q.length} items`:"Delete",icon:"trash-2",keys:"\u232B",danger:!0,disabled:O||v(E)||E.shape==="missing",why:v(E)?r.text.deleteWhy:"Nothing to delete",onSelect:()=>it(q)}),is(L,Y,`${E.label||r.text.root} actions`)}function Ze(){let E=e.selection.length?e.selection:[nt(y)],Y=[...new Set(E.map(q=>{let de=q.slice(0,-1);for(;de.length&&!C.has(Me(de));)de=de.slice(0,-1);return Me(de)}))];ee(Y)}t.addEventListener("click",E=>{let Y=E.target.closest(".trow");!Y||E.target.closest(".tedit")||fe(Y.dataset.id,E)}),t.addEventListener("dblclick",E=>{let Y=E.target.closest(".trow");if(!Y||E.target.closest(".tedit, .twisty, .tadd"))return;let q=C.get(Y.dataset.id)?.n;q&&(q.shape==="scalar"&&E.target.closest(".tval")?be(q.id,"value"):q.kind==="resource"||q.kind==="key"?be(q.id,"rename"):j(q.id))}),t.addEventListener("contextmenu",E=>{let Y=E.target.closest(".trow");if(!Y)return;E.preventDefault();let q=Y.dataset.id;$().has(q)||fe(q,{shiftKey:!1,metaKey:!1,ctrlKey:!1});let de=C.get(q)?.n;de&>(de,{x:E.clientX,y:E.clientY})}),t.addEventListener("focusin",E=>{let Y=E.target.closest(".trow");Y&&!E.target.closest(".tedit")&&(y=Y.dataset.id)}),t.addEventListener("keydown",E=>{if(E.target.closest(".tedit"))return;let Y=K.map(G=>G.n.id),q=Math.max(0,Y.indexOf(y)),de=C.get(y),m=de?.n,O=E.metaKey||E.ctrlKey,L=G=>{let Z=Y[Math.max(0,Math.min(Y.length-1,G))];E.shiftKey?(A||(A=y),fe(Z,{shiftKey:!0,metaKey:!1,ctrlKey:!1})):(A=Z,ee([Z]))};switch(E.key){case"ArrowDown":if(O)return;L(q+1);break;case"ArrowUp":if(O){Ze();break}L(q-1);break;case"Home":L(0);break;case"End":L(Y.length-1);break;case"ArrowRight":m&&m.children.length&&!T.has(m.id)?j(m.id,!0):m&&m.children.length&&L(q+1);break;case"ArrowLeft":m&&T.has(m.id)&&m.children.length?j(m.id,!1):de?.parent&&(A=de.parent.id,ee([de.parent.id]));break;case"Enter":if(!m)return;if(m.shape==="scalar"&&m.kind!=="group"){let G=xe(e.goodDoc.data,m.path);typeof G=="boolean"&&!w()?re(o(m.path,!G)):be(m.id,"value")}else m.children.length&&j(m.id);break;case"F2":m&&be(m.id,"rename");break;case"Delete":case"Backspace":it(e.selection.length?e.selection.map(Me):[y]);break;case"ContextMenu":m&>(m,t.querySelector(`[data-id="${CSS.escape(y)}"]`));break;case"F10":if(E.shiftKey&&m)gt(m,t.querySelector(`[data-id="${CSS.escape(y)}"]`));else return;break;case"+":case"Insert":m&&ne(m).length&&is(ne(m),t.querySelector(`[data-id="${CSS.escape(y)}"]`),"Add");break;default:if(O&&E.key.toLowerCase()==="d"){Ne(y);break}if(O&&E.key.toLowerCase()==="a"){ee(Y.filter(G=>G),y);break}if(E.key.length===1&&!O&&/\S/.test(E.key)){let G=Date.now();_=G-S>700?E.key.toLowerCase():_+E.key.toLowerCase(),S=G;let Se=[...Y.slice(q+(_.length===1?1:0)),...Y.slice(0,q+1)].find(ue=>(C.get(ue)?.n.label??"").toLowerCase().startsWith(_));Se!==void 0&&(A=Se,ee([Se]));break}return}E.preventDefault()});let ft;t.addEventListener("dragstart",E=>{let Y=E.target.closest(".trow");Y&&(ft=Y.dataset.id,E.dataTransfer?.setData("text/plain",nt(ft).join(".")),E.dataTransfer&&(E.dataTransfer.effectAllowed="move"))});let ot=E=>{let Y=E.target.closest(".trow");if(!Y||!ft||Y.dataset.id===ft)return;let q=C.get(ft)?.n,de=C.get(Y.dataset.id)?.n;if(!q||!de||Me(q.path.slice(0,-1))!==Me(de.path.slice(0,-1)))return;let m=Y.getBoundingClientRect();return{r:Y,a:q,b:de,after:E.clientY>m.top+m.height/2}};t.addEventListener("dragover",E=>{for(let q of t.querySelectorAll(".drop-before, .drop-after"))q.classList.remove("drop-before","drop-after");let Y=ot(E);Y&&(E.preventDefault(),Y.r.classList.add(Y.after?"drop-after":"drop-before"))}),t.addEventListener("dragleave",E=>{if(E.target===t)for(let Y of t.querySelectorAll(".drop-before, .drop-after"))Y.classList.remove("drop-before","drop-after")}),t.addEventListener("drop",E=>{let Y=ot(E);for(let G of t.querySelectorAll(".drop-before, .drop-after"))G.classList.remove("drop-before","drop-after");if(ft=void 0,!Y)return;E.preventDefault();let{a:q,b:de,after:m}=Y,O=q.path.slice(0,-1),L=G=>G[G.length-1];if(typeof L(q.path)=="number"){let G=L(q.path),Z=L(de.path)+(m?1:0);Z>G&&(Z-=1),re(p(O,G,Z))&&(y=Me([...O,Z]),e.select([[...O,Z]],"tree"))}else{let G=(C.get(Me(O))?.n.children??[]).map(ue=>String(L(ue.path))),Z=G.indexOf(String(L(de.path))),Se=m?G[Z+1]:G[Z];Se!==String(L(q.path))&&re(f(q.path,Se===void 0?void 0:Se)),y=q.id}N(),U(y)}),e.on(E=>{if(E.remap){for(let q of[...T]){let de=E.remap(nt(q));de&&Me(de)!==q&&(T.delete(q),T.add(Me(de)))}let Y=E.remap(nt(y));Y&&(y=Me(Y))}E.kind==="load"&&(D=void 0,y=""),Ys(E)?at():at.now()});let at=qs(()=>N());return e.onSelect(E=>{E.origin!=="tree"?B(E.paths):N()}),N(),{paint:N,dispose:()=>at.cancel(),focus:()=>U(y),rows:()=>K.map(E=>({id:E.n.id,label:E.n.label,depth:E.depth,kind:E.n.kind,value:E.n.value,lifetime:E.n.lifetime})),startEdit:be,remove:it,duplicate:Ne,expand:E=>j(E,!0)}}var Xc=(t,e)=>e.reduce((n,s)=>n&&typeof n=="object"?n[s]:void 0,t);function un(t,e,n,s){try{return t.apply(e,n)}catch(r){return s?.(String(r.message),"bad"),!1}}function hr(t,e){return{label:t,remap:n=>e.reduce((s,r)=>s&&r.remap?r.remap(s):s,n),build:n=>{let s=[],r=!1;for(let o of e){let i=o.build(n);for(let a of i.steps)s.push(a),n=dn(n,a);r||=!!i.fallback}return{steps:s,fallback:r}}}}function al(t){let{deleteCmd:e,renameCmd:n,renameKeyCmd:s,referencesTo:r,describe:o,duplicateCmd:i}=t.commands,a=f=>{let p=t.objectOf(Me(f));return!!p&&p.path===Me(f)};async function l(f,p,g,h){let b=p.filter(y=>y.length&&!p.some(A=>A!==y&&A.length<y.length&&Vt(A,y)));if(!b.length)return!1;let k=b.filter(a).flatMap(y=>{let A=t.objectOf(Me(y));return r(f.text,A.kind,A.name).filter(D=>!b.some(K=>Vt(K,nt(D.path)))).map(D=>({p:y,x:D}))}),v=!1;if(k.length){let y=await mr(`Delete ${b.length===1?o(b[0]):`${b.length} items`}?`,[z("p",{class:"sub"},`${k.length===1?"One place refers":`${k.length} places refer`} to ${b.length===1?"it":"them"}:`),z("ul",{class:"ref-list"},...k.map(({x:A})=>z("li",null,z("code",null,A.path.slice(1).replace(/\//g,".")),` \u2014 ${A.slot.what}`))),z("p",{class:"sub"},"Delete the references too, or leave them (the problems list will show them). Either way, Undo brings everything back.")],[{label:"Cancel",value:"cancel"},{label:"Delete only",value:"only",danger:!0},{label:"Delete with references",value:"with",danger:!0,primary:!0}]);if(!y)return!1;v=y==="with"}let x=[...b].sort((y,A)=>typeof y.at(-1)=="number"&&typeof A.at(-1)=="number"?A.at(-1)-y.at(-1):0).map(y=>e(y,{withRefs:v&&a(y)})),T=un(f,x.length===1?x[0]:hr(`Delete ${b.length} items`,x),g,h);return T&&f.select([],g),T}async function c(f,p,g,h){let b=String(p[p.length-1]),k=z("input",{type:"text",value:b,"aria-label":"New name",spellcheck:"false",autocomplete:"off",class:"mono-input"});k.value=b;let v=z("p",{class:"dlg-error",role:"alert"}),M=()=>t.kinds.flatMap(A=>Object.keys(Xc(f.goodDoc.data,A.section)??{})),x=()=>{let A=k.value.trim(),D=!t.nameRule.test(A)&&a(p)?t.nameHint:A!==b&&M().includes(A)?`"${A}" is already used`:"";return v.textContent=D,D?void 0:A};k.addEventListener("input",x);let T=mr(`Rename ${o(p)}`,[z("label",{class:"field"},z("span",null,"Name"),k),v,a(p)?z("p",{class:"sub"},"Every reference to it is renamed too."):""],[{label:"Cancel",value:"cancel"},{label:"Rename",value:"ok",primary:!0}]);if(setTimeout(()=>{k.focus(),k.select()},0),await T!=="ok")return!1;let y=x();return!y||y===b?!1:un(f,a(p)?n(p,y):s(p,y),g,h)}let d=(f,p,g,h)=>{let b=i(p);un(f,b,g,h)&&b.select&&f.select(b.select,g)};function u(f,p){let g=new Map;for(let h of p){let b=t.objectOf(Me(h));if(!b)continue;g.set(b.path,nt(b.path));for(let M of r(f.text,b.kind,b.name)){let x=t.objectOf(M.path);g.set(x?x.path:M.path,nt(x?x.path:M.path))}let k=Xc(f.goodDoc.data,nt(b.path)),v=JSON.stringify(k??{}).match(/[a-z][a-z0-9-]*/g)??[];for(let M of t.kinds)for(let x of Object.keys(Xc(f.goodDoc.data,M.section)??{}))if(v.includes(x)&&x!==b.name){let T=Me([...M.section,x]);g.set(T,nt(T))}}return[...g.values()]}return{deletePaths:l,renameDialog:c,duplicate:d,connected:u}}var ll=(t,e)=>e.reduce((n,s)=>n&&typeof n=="object"?n[s]:void 0,t),gr=t=>!!t&&typeof t=="object"&&!Array.isArray(t),Us=Symbol("mixed");function cl(t,e,n){let s,r=!1,o=n.kit,i=o.ui,{setCmd:a,deleteCmd:l,insertItemCmd:c,referencesTo:d,describe:u}=o.commands,{deletePaths:f,renameDialog:p}=o.actions,g=S=>o.kinds.find($=>$.kind===S),h=S=>g(S)?.singular??"item",b=S=>Object.keys(ll(e.goodDoc.data,g(S)?.section??[])??{}).filter($=>!$.startsWith("x-")),k=S=>un(e,S,"props",n.note);function v(){if(t.contains(document.activeElement)&&document.activeElement.matches("input, textarea"))return;t.replaceChildren();let S=e.selection;if(!S.length){t.append(z("p",{class:"hint"},"Select something in the canvas, the tree or the text."));return}let $=S.map(we=>o.objectOf(Me(we)));if(S.length>1){if(new Set($.map(j=>j?.kind)).size===1&&$.every(j=>j&&j.path===Me(nt(j.path)))){let j=[...new Set($.map(U=>U.path))].map(nt);t.append(z("div",{class:"sel-title"},`${j.length} ${h($[0].kind)}s`),z("div",{class:"sel-path"},j.map(U=>U[U.length-1]).join(", "))),M(j,$[0].kind)}else t.append(z("div",{class:"sel-title"},`${S.length} items`),z("ul",{class:"plain"},...S.map(j=>z("li",null,z("code",null,j.join(".")||i.rootItem)))));K();return}let w=S[0],N=$[0],F=N?nt(N.path):w.length?w:[];if(!N){C(w);return}let J=z("div",{class:"sel-headrow"},z("div",{class:"sel-title"},u(F))),ae=z("button",{type:"button",class:"btn sm quiet icon-only","aria-label":`Rename ${u(F)}`,title:"Rename (F2)"},Wt("pencil"));ae.addEventListener("click",()=>p(e,F,"props",n.note)),J.append(ae),t.append(J),Me(w)!==N.path&&(s=Me(w)),M([F],N.kind),A(N.kind,N.name),D(N.path),K()}function M(S,$){let w=n.nav(),N=e.goodDoc.data,F=S.map(ne=>ll(N,ne)??{}),J=F[0]&&gr(F[0])?F[0]:{},ae=F.some(ne=>i.isExternal(ne)),we=w.keys(S[0],ae?{external:!0}:J),j=Object.keys(J),U=we.filter(ne=>F.some(me=>gr(me)&&ne.name in me)).sort((ne,me)=>(j.indexOf(ne.name)+1||999)-(j.indexOf(me.name)+1||999)),ee=n.read(),fe=new Set([...U.map(ne=>ne.name),...i.important($,F[0]??{},ae),...S.length===1&&ee!==void 0&&i.inheritedKeys?i.inheritedKeys(S[0],ee):[]]),B=we.filter(ne=>!U.includes(ne)&&fe.has(ne.name)),X=we.filter(ne=>!fe.has(ne.name)),Q=z("div",{class:"props"});for(let ne of[...U,...B])Q.append(x(S,$,ne,F,ee));if(X.length&&e.doc.ok){let ne=z("select",{class:"padd","aria-label":"Add a property"},z("option",{value:""},"+ Add property"),...X.map(me=>z("option",{value:me.name,title:(me.doc??"").replace(/`/g,"")},me.name)));ne.addEventListener("change",()=>{let me=ne.value;if(!me)return;let ye=w.defaultFor([...S[0],me]);s=Me([...S[0],me]),r=!0,k(S.length===1?a([...S[0],me],ye,`Add ${u([...S[0],me])}`):hr(`Add ${me} to ${S.length} ${h($)}s`,S.map(xe=>a([...xe,me],ye))))}),Q.append(ne)}let te=new Set(we.map(ne=>ne.name));for(let ne of new Set(F.flatMap(me=>gr(me)?Object.keys(me):[])))te.has(ne)||Q.append(x(S,$,{name:ne,shape:"scalar",enumValues:[],examples:[],doc:ne.startsWith("x-")?i.extensionDoc:"Not a key the schema knows."},F,ee));if(t.append(Q),s){let ne=Q.querySelector(`[data-path="${CSS.escape(s)}"]`);ne?.classList.add("focus-row"),ne?.scrollIntoView({block:"nearest"}),r&&ne?.querySelector("input, select, textarea")?.focus({preventScroll:!0}),s=void 0,r=!1}}function x(S,$,w,N,F){let J=n.nav(),ae=N.map(be=>gr(be)?be[w.name]:void 0),j=ae.every(be=>JSON.stringify(be)===JSON.stringify(ae[0]))?ae[0]:Us,U=ae.some(be=>be!==void 0),ee=$&&S.length===1&&F!==void 0?i.inherited?.(S[0],w.name,F):void 0,fe=S.map(be=>Me([...be,w.name])),B=z("div",{class:`prow${U?"":" unset"}`,"data-path":fe[0]}),X=z("label",{class:"plabel",title:w.doc?.replace(/`/g,"")??""},w.name),Q=`pf-${Math.random().toString(36).slice(2,8)}`;X.setAttribute("for",Q),B.append(X);let te=(be,ce)=>k(S.length===1?a([...S[0],w.name],be,ce):hr(ce??`Set ${w.name} on ${S.length} ${h($)}s`,S.map(ze=>a([...ze,w.name],be)))),ne=()=>{let be=S.filter((ce,ze)=>ae[ze]!==void 0);k(be.length===1?{...l([...be[0],w.name]),label:`Remove ${u([...be[0],w.name])}`}:hr(`Remove ${w.name} from ${be.length} ${h($)}s`,be.map(ce=>l([...ce,w.name]))))},me=o.slotAt(Me([...S[0],w.name])),ye=o.slotAt(Me([...S[0],w.name,0])),xe=J.values([...S[0],w.name]),Re=J.types([...S[0],w.name]),Ue,I=j===Us?"(mixed)":"";if(me||xe.length){let be=[...new Set([...xe,...me?me.targets.flatMap(ze=>b(ze).map(Oe=>me.write?me.write(Oe):Oe)).concat(me.extra??[]):[]])],ce=z("select",{id:Q,class:"pinput"});ce.append(z("option",{value:"\0"},I||"\u2014"));for(let ze of be)ce.append(z("option",{value:ze},ze));j!==Us&&j!==void 0&&!be.includes(String(j))&&ce.append(z("option",{value:String(j)},String(j))),ce.value=j===Us||j===void 0?"\0":String(j),ce.addEventListener("change",()=>{if(ce.value==="\0"){U&&ne();return}te(xe.includes("true")&&(ce.value==="true"||ce.value==="false")?ce.value==="true":ce.value)}),Ue=ce}else if(ye&&S.length===1){let be=Array.isArray(j)?j:[],ce=z("div",{class:"chips"});be.forEach((Oe,Ee)=>{let Be=z("button",{type:"button",class:"chip-x","aria-label":`Remove ${Oe}`},"\xD7");Be.addEventListener("click",()=>k({...l([...S[0],w.name,Ee]),label:`Remove ${Oe} from ${u([...S[0],w.name])}`})),ce.append(z("span",{class:"chip"},String(Oe),Be))});let ze=[...new Set(ye.targets.flatMap(Oe=>b(Oe)).concat(ye.extra??[]))].filter(Oe=>!be.includes(Oe));if(ze.length){let Oe=z("select",{id:Q,class:"pinput chip-add","aria-label":`Add to ${w.name}`},z("option",{value:""},"+ add"),...ze.map(Ee=>z("option",{value:Ee},Ee)));Oe.addEventListener("change",()=>{Oe.value&&k(c([...S[0],w.name],Oe.value,void 0,`Add ${Oe.value} to ${u([...S[0],w.name])}`))}),ce.append(Oe)}Ue=ce}else if(w.name==="prompt"||typeof j=="string"&&j.includes(`
|
|
465
|
-
`)){let
|
|
466
|
-
`)||!
|
|
467
|
-
`)?
|
|
468
|
-
`)}),
|
|
464
|
+
`,o+1))n.push(o+1);let s=(o,i)=>{let a=Math.min(Math.max(o,1),n.length),l=a<n.length?n[a]-1:t.length;return Math.min(n[a-1]+Math.max(i,1)-1,l)},r=s(e.startLine,e.startCol);return[r,Math.max(r,s(e.endLine,e.endCol))]}function zf(t){return t.replace(/\$\{(\d+)\|([^|}]*)\|\}/g,(e,n,s)=>`\${${n}:${s.split(",")[0]}}`).replace(/\$\{0\}/g,"${}")}function Vf(t){return t.split(/\n{2,}/).map(e=>{let n=[];for(let s of e.matchAll(/\*\*([^*]+)\*\*|`([^`]+)`|([^*`]+|[*`])/g))s[1]!==void 0?n.push({kind:"bold",text:s[1]}):s[2]!==void 0?n.push({kind:"code",text:s[2]}):n.push({kind:"text",text:s[3]});return n})}var yl=null;function Mr(t){yl=t}function rr(){return yl&&yl.isConnected?yl:document.body}var Gf="http://www.w3.org/2000/svg";function Ut(t,e=""){let n=document.createElementNS(Gf,"svg");n.setAttribute("class",`icon${e?" "+e:""}`),n.setAttribute("aria-hidden","true");let s=document.createElementNS(Gf,"use");return s.setAttribute("href",`#se-i-${t}`),n.append(s),n}function $r(t,e,n){return new Promise(s=>{let r=K("dialog",{class:"dlg","aria-label":t}),o=K("form",{method:"dialog"}),i=K("div",{class:"dlg-foot"});for(let a of n){let l=K("button",{type:"submit",value:a.value,class:`btn${a.primary?" primary":""}${a.danger?" danger":""}`},a.label);i.append(l)}o.append(K("div",{class:"dlg-head"},K("h2",{class:"h-title"},t)),K("div",{class:"dlg-body"},...e),i),r.append(o),rr().append(r),r.addEventListener("close",()=>{let a=r.returnValue;r.remove(),s(a&&a!=="cancel"?a:null)}),r.showModal(),i.querySelector(".primary")?.focus()})}var li,Hf=()=>!!li;function ys(t,e,n="Actions"){li?.close(!1);let s=document.activeElement,r=K("div",{class:"menu",role:"menu","aria-label":n,tabindex:"-1"}),o=[];for(let g of t){if("sep"in g){r.append(K("div",{class:"menu-sep",role:"separator"}));continue}if("heading"in g){r.append(K("div",{class:"menu-label"},g.heading));continue}let h=(g.disabled?g.why:void 0)??g.desc,b=K("button",{type:"button",role:"menuitem",tabindex:"-1",class:"menu-item"+(g.danger?" danger":""),"data-desc":h,"aria-description":h},g.icon?Ut(g.icon):K("span"),K("span",{class:"mi-label"},g.label),g.keys?K("span",{class:"menu-trail"},g.keys):null);g.disabled&&(b.disabled=!0),b.addEventListener("click",v=>{v.stopPropagation(),!b.disabled&&(p(!0),g.onSelect())}),o.push(b),r.append(b)}rr().append(r);let i=r.getBoundingClientRect(),a,l;if(e instanceof HTMLElement){let g=e.getBoundingClientRect();a=g.left,l=g.bottom+4,l+i.height>innerHeight-8&&(l=g.top-i.height-4)}else a=e.x,l=e.y,l+i.height>innerHeight-8&&(l=Math.max(8,e.y-i.height));r.style.left=`${Math.max(8,Math.min(a,innerWidth-i.width-8))}px`,r.style.top=`${Math.max(8,l)}px`;let c=()=>o.filter(g=>!g.disabled),d=g=>{let h=c();h.length&&h[(g+h.length)%h.length].focus()};d(0),r.addEventListener("keydown",g=>{let b=c().indexOf(document.activeElement);g.key==="ArrowDown"?(d(b+1),g.preventDefault()):g.key==="ArrowUp"?(d(b-1),g.preventDefault()):g.key==="Home"?(d(0),g.preventDefault()):g.key==="End"?(d(-1),g.preventDefault()):(g.key==="Escape"||g.key==="Tab")&&(p(!0),g.preventDefault()),g.stopPropagation()});let u=g=>{r.contains(g.target)||p(!1)};setTimeout(()=>{addEventListener("pointerdown",u,!0),addEventListener("blur",f)},0);let f=()=>p(!1);function p(g){r.isConnected&&(r.remove(),removeEventListener("pointerdown",u,!0),removeEventListener("blur",f),li=void 0,g&&s?.focus())}return li={el:r,close:p},r}function xl(){li?.close(!1)}var Yf=150,or=t=>t.kind==="do"&&t.origin==="text";function ir(t,e=150){let n=0,s=()=>{n=0,t()},r=()=>{clearTimeout(n),n=window.setTimeout(s,e)};return r.now=()=>{clearTimeout(n),s()},r.pending=()=>n!==0,r.cancel=()=>{clearTimeout(n),n=0},r}function wl(t,e){return t.map((n,s)=>s===0?{...n,keys:[...n.keys.slice(0,1),...e,...n.keys.slice(1)]}:n)}function vl(t){let e=K("dialog",{class:"dlg keys-dlg","aria-label":"Keyboard"}),n=K("form",{method:"dialog"}),s=K("div",{class:"dlg-body keys"});for(let r of t){s.append(K("h3",{class:"keys-h"},r.where));let o=K("dl",{class:"keys-list"});for(let[i,a]of r.keys)o.append(K("dt",null,...i.split(/(\s+or\s+|,\s*)/).map(l=>/^\s+or\s+$|^,\s*$/.test(l)?l:K("kbd",null,l))),K("dd",null,a));s.append(o)}return n.append(K("div",{class:"dlg-head"},K("h2",{class:"h-title"},"Keyboard")),s,K("div",{class:"dlg-foot"},K("button",{type:"submit",class:"btn primary",value:"close"},"Close"))),e.append(n),e.addEventListener("close",()=>e.remove()),rr().append(e),e.showModal(),e}function kl(t,e,n){let{copyText:s,cutCmd:r,pasteCmd:o}=n,i="",a=()=>!t.doc.ok,l=f=>!!f?.closest?.("input, textarea, select, .monaco-editor, [contenteditable]"),c=()=>{let f=s(t.text,t.selection);if(!f){e("Select something to copy");return}return i=f.text,e(`Copied ${f.what}`),f.text},d=()=>{if(a()){e("Fix the YAML first","warn");return}let f=r(t.text,t.selection);if(!f){e("Select something to cut");return}return i=f.text,t.apply(f.cmd,"menu"),t.select([],"menu"),f.text},u=f=>{if(a())return e("Fix the YAML first","warn"),!1;let p=o(t.text,f,t.selection);if(!p.cmd)return e(`Can't paste: ${p.error}`,"warn"),!1;try{if(!t.apply(p.cmd,"menu"))return!1}catch(h){return e(`Can't paste: ${h.message}`,"bad"),!1}p.cmd.select&&t.select(p.cmd.select,"menu");let g=p.names?[...p.names].filter(([h,b])=>h!==b):[];return e(g.length?`${p.what}: ${g.map(([h,b])=>`${h} \u2192 ${b}`).join(", ")}`:p.what),!0};return{items(){let f=t.selection.length>0;return[{label:"Cut",icon:"clipboard",keys:"\u2318X",disabled:!f||a(),why:f?"Fix the YAML first":"Nothing selected",onSelect:()=>{this.cut()}},{label:"Copy",icon:"copy",keys:"\u2318C",disabled:!f,why:"Nothing selected",onSelect:()=>{this.copy()}},{label:"Paste",icon:"clipboard-paste",keys:"\u2318V",disabled:a(),why:"Fix the YAML first",onSelect:()=>{this.paste()}}]},attach(f,p){let g=v=>{let w=v;if(l(w.target)||!p(w.target))return;let M=c();M!==void 0&&(w.clipboardData?.setData("text/plain",M),w.preventDefault())},h=v=>{let w=v;if(l(w.target)||!p(w.target))return;let M=d();M!==void 0&&(w.clipboardData?.setData("text/plain",M),w.preventDefault())},b=v=>{let w=v;if(l(w.target)||!p(w.target))return;let M=w.clipboardData?.getData("text/plain")??"";w.preventDefault(),u(M||i)};return f.addEventListener("copy",g),f.addEventListener("cut",h),f.addEventListener("paste",b),()=>{f.removeEventListener("copy",g),f.removeEventListener("cut",h),f.removeEventListener("paste",b)}},async copy(){let f=c();if(f===void 0)return!1;try{await navigator.clipboard.writeText(f)}catch{}return!0},async cut(){let f=d();if(f===void 0)return!1;try{await navigator.clipboard.writeText(f)}catch{}return!0},async paste(f){let p=f;if(p===void 0)try{p=await navigator.clipboard.readText()}catch{p=i}return p?u(p):(e("The clipboard is empty"),!1)}}}function Sl(t,e,n){let s=n.kit,r=s.ui,{setCmd:o,insertCmd:i,insertItemCmd:a,deleteCmd:l,renameCmd:c,renameKeyCmd:d,duplicateCmd:u,moveCmd:f,moveItemCmd:p,referencesTo:g,describe:h,freshName:b}=s.commands,v=A=>s.kinds.find(Y=>Y.kind===A),w=A=>A.id==="",M=A=>s.entryGroups.some(Y=>A.length===Y.length+1&&qt(Y,A)),y=A=>s.entryGroups.some(Y=>Y.length===A.length&&qt(Y,A)),T=new Set(["",...s.kinds.map(A=>Se(A.section)),...s.entryGroups.map(A=>Se(A))]),S="",P="",I,_=[],O=new Map,j="",k=0,$=()=>new Set(e.selection.map(Se)),x=()=>!e.doc.ok;t.setAttribute("role","tree"),t.setAttribute("aria-label",r.label),t.setAttribute("aria-multiselectable","true"),t.classList.add("tree");function N(){let A=s.outline(e.goodDoc,n.role(),n.lifetimes());_=[];let Y=(Z,$e,de)=>{if(_.push({n:Z,depth:$e,parent:de}),T.has(Z.id))for(let De of Z.children)Y(De,$e+1,Z);I?.mode==="new"&&Se(I.mapPath)===Z.id&&T.has(Z.id)&&_.push({n:{id:I.id,path:[...I.mapPath,""],kind:"resource",label:"",shape:"scalar",children:[]},depth:$e+1,parent:Z})};Y(A,0),O=new Map(_.map(Z=>[Z.n.id,Z])),O.has(S)||(S=_[0]?.n.id??"");let q=$(),ae=F(),m=document.createDocumentFragment();x()&&m.append(K("div",{class:"callout compact warn tree-note",role:"status"},K("span",{class:"c-body"},`Fix the YAML at line ${e.doc.doc.errors[0]?e.doc.pos(e.doc.doc.errors[0].pos[0]).line:"?"} to edit here; the tree shows the last version that read cleanly.`)));for(let{n:Z,depth:$e}of _)m.append(oe(Z,$e,q.has(Z.id),ae.get(Z.id)));let C=t.contains(document.activeElement);t.replaceChildren(m);let R=t.querySelector(`[data-id="${CSS.escape(S)}"]`);R&&(R.tabIndex=0);let G=t.querySelector(".tedit");G?(G.focus(),G instanceof HTMLInputElement&&G.select()):C&&R&&!t.contains(document.activeElement)&&R.focus({preventScroll:!0})}function F(){let A=new Map;for(let Y of n.problems()){if(Y.file)continue;let q=rt(Y.path);for(let ae=1;ae<=q.length;ae++){let m=Se(q.slice(0,ae)),C=A.get(m)??{e:0,w:0};Y.severity==="error"?C.e++:C.w++,A.set(m,C)}}return A}function J(A){if(w(A))return r.rootIcon;if(A.section)return r.kindIcon(A.section);let Y=String(A.path[A.path.length-1]??"");return A.path.length===1&&r.keyIcon(Y)?r.keyIcon(Y):M(A.path)?r.entryIcon(String(A.path[0])):A.shape==="list"?"list":A.shape==="map"?"list-tree":"circle-dot"}function oe(A,Y,q,ae){let m=T.has(A.id),C=A.children.length>0||A.shape==="missing"&&!1,R=K("div",{class:`trow k-${A.kind}${q?" selected":""}${A.shape==="missing"?" missing":""}${A.ext?" ext":""}`,role:"treeitem","aria-level":Y+1,"aria-selected":String(q),"aria-expanded":A.children.length?String(m):void 0,tabindex:"-1","data-id":A.id,draggable:X(A)?"true":void 0,"aria-label":ve(A)});R.style.setProperty("--depth",String(Y));let G=K("span",{class:"twisty","aria-hidden":"true"},C?Ut(m?"chevron-down":"chevron-right"):"");G.addEventListener("click",de=>{de.stopPropagation(),B(A.id)}),R.append(G,Ut(J(A),"ticon"));let Z=I&&I.id===A.id?I:void 0;Z&&(Z.mode==="rename"||Z.mode==="new")?R.append(Ke(A,Z)):R.append(K("span",{class:"tlabel"},A.label||(A.kind==="item"?'""':""))),Z?.mode==="value"?R.append(Ee(A)):A.value!==void 0&&A.kind!=="item"?R.append(K("span",{class:"tval"},A.value)):A.shape==="missing"?R.append(K("span",{class:"tval none"},"none")):A.kind==="group"&&A.children.length&&R.append(K("span",{class:"tcount"},String(A.children.length)));let $e=A.lifetime?r.tagPill(A.lifetime):void 0;if($e&&R.append(K("span",{class:`tpill l-${A.lifetime}`,title:$e.title},A.lifetime)),ae?.e?R.append(K("span",{class:"count bad",title:`${ae.e} error${ae.e>1?"s":""}`},String(ae.e))):ae?.w&&R.append(K("span",{class:"count warn",title:`${ae.w} warning${ae.w>1?"s":""}`},String(ae.w))),!x()&&ne(A).length){let de=K("button",{type:"button",class:"tadd btn sm quiet icon-only",tabindex:"-1","aria-label":`Add to ${A.label||r.text.rootAdd}`,title:"Add\u2026"},Ut("plus"));de.addEventListener("click",De=>{De.stopPropagation(),W(A.id),ys(ne(A),de,`Add to ${A.label}`)}),R.append(de)}return R}let ve=A=>[A.kind==="group"?`${A.label}, ${A.shape==="missing"?"none":A.children.length}`:A.label,A.value!==void 0&&A.kind!=="item"?`: ${A.value}`:"",A.lifetime&&A.lifetime!=="run"?`, ${A.lifetime}`:""].join("");function B(A,Y){Y??!T.has(A)?T.add(A):T.delete(A),N()}function W(A){S=A;for(let q of t.querySelectorAll(".trow"))q.tabIndex=q.dataset.id===A?0:-1;let Y=t.querySelector(`[data-id="${CSS.escape(A)}"]`);Y?.focus({preventScroll:!0}),Y?.scrollIntoView({block:"nearest"})}function ee(A,Y=A[A.length-1]){Y!==void 0&&(S=Y,W(S)),e.select(A.map(rt),"tree"),N(),W(S)}function ue(A,Y){if(Y.shiftKey&&P){let q=_.map(C=>C.n.id),ae=q.indexOf(P),m=q.indexOf(A);if(ae>=0&&m>=0){ee(q.slice(Math.min(ae,m),Math.max(ae,m)+1),A);return}}if(Y.metaKey||Y.ctrlKey){let q=$();q.has(A)?q.delete(A):q.add(A),P=A,ee([...q],A);return}P=A,ee([A])}function z(A){for(let Y of A)for(let q=0;q<Y.length;q++)T.add(Se(Y.slice(0,q)));if(A[0]){let Y=Se(A[0]);for(N();!O.has(Y)&&Y;)Y=Y.replace(/\/[^/]*$/,"");S=Y}N(),t.querySelector(`[data-id="${CSS.escape(S)}"]`)?.scrollIntoView({block:"nearest"})}let X=A=>!x()&&!w(A)&&A.kind!=="group"&&A.path.length>1||A.kind==="item",Q=A=>A.kind==="resource"&&!!A.section,te=A=>A.kind==="group"&&(!!A.section||y(A.path));function ne(A){if(x())return[];let Y=n.nav(),q=[],ae=e.goodDoc.data;if(w(A)){for(let G of s.kinds){if(n.role()!=="main")break;q.push({label:`New ${G.singular}`,icon:r.kindIcon(G.kind),onSelect:()=>Oe(G.kind)})}let m=new Set(A.children.filter(G=>G.shape!=="missing").map(G=>String(G.path[0]))),C=new Set(s.kinds.map(G=>String(G.section[0]))),R=Y.keys([],ae??{}).filter(G=>!m.has(G.name)&&!C.has(G.name)&&!(ae&&G.name in ae));return R.length&&q.push({sep:!0},{heading:"Settings"},...R.map(G=>({label:G.name,desc:be(G.doc),onSelect:()=>Me([],G.name)}))),q}if(A.kind==="group"&&A.section){let m=A.section;for(let C of r.newItems(m))q.push({label:C.label,icon:C.icon,desc:C.desc,onSelect:()=>Oe(m,C.template,C.stem)});return q}if(y(A.path)&&r.entryItems)return fe(A.path);if(A.shape==="missing")return[{label:`Add ${A.label}`,icon:"plus",onSelect:()=>Me([],String(A.path[0]),!0)}];if(A.shape==="list"){let m=s.slotAt(Se([...A.path,0])),C=new Set(A.children.map(R=>R.label));if(m){for(let R of m.targets)for(let G of Ne(R))C.has(m.write?m.write(G):G)||q.push({label:m.write?m.write(G):G,icon:r.kindIcon(R),desc:`${v(R).singular}`,onSelect:()=>se(a(A.path,m.write?m.write(G):G,void 0,`Add ${G} to ${h(A.path)}`))});for(let R of m.extra??[])C.has(R)||q.push({label:R,onSelect:()=>se(a(A.path,R,void 0,`Add ${R} to ${h(A.path)}`))})}for(let R of Y.values([...A.path,0]))C.has(R)||q.push({label:R,onSelect:()=>se(a(A.path,R))});return q.push({label:"New item",icon:"plus",onSelect:()=>{se(a(A.path,""));let R=[...A.path,A.children.length];ge(Se(R),"value")}}),q}if(A.shape==="map"||A.kind==="resource"){let m=we(ae,A.path),C=m&&typeof m=="object"&&!Array.isArray(m)?m:{};for(let R of Y.keys(A.path,C))R.name in C||q.push({label:R.name,desc:be(R.doc),onSelect:()=>Me(A.path,R.name)});return q}return q}function fe(A){let Y=e.goodDoc.data??{},q=we(Y,A)??{};return r.entryItems(A,Y,qe).filter(ae=>!ae.when||ae.when(Y)).map(ae=>({label:ae.label,icon:ae.icon,onSelect:()=>{se(i(A,D(Object.keys(q),ae.entry),ae.value,ae.cmdLabel?{label:ae.cmdLabel}:{}))}}))}let be=A=>A?.split(/(?<=\.)\s/)[0]?.replace(/`/g,""),we=(A,Y)=>Y.reduce((q,ae)=>q&&typeof q=="object"?q[ae]:void 0,A),Ne=A=>{let Y=we(e.goodDoc.data,v(A).section);return Y&&typeof Y=="object"?Object.keys(Y).filter(q=>!q.startsWith("x-")):[]},qe=A=>{let Y=we(e.goodDoc.data,v(A).section);return Y?Object.keys(Y).filter(q=>!q.startsWith("x-")&&!(Y[q]&&typeof Y[q]=="object"&&"external"in Y[q])):[]},D=(A,Y)=>{if(!A.includes(Y))return Y;let q=2;for(;A.includes(`${Y}-${q}`);)q++;return`${Y}-${q}`};function se(A){try{return e.apply(A,"tree")}catch(Y){return n.note(String(Y.message),"bad"),!1}}function Me(A,Y,q=!1){let ae=n.nav(),m=q?{}:ae.defaultFor([...A,Y]);if(se(i(A,Y,m))){T.add(Se(A));let C=Se([...A,Y]);S=C,m===""||typeof m=="number"?ge(C,"value"):(N(),W(C))}}function Oe(A,Y=v(A).template,q=v(A).singular){let ae=v(A).section;T.add(Se(ae)),I={id:"#new",mode:"new",section:A,mapPath:ae,template:Y,value:b(e.text,q)},N()}function ge(A,Y){if(x())return;let q=O.get(A);if(!q){N();return}Y==="rename"&&(q.n.kind==="group"||w(q.n)||q.n.kind==="item")||Y==="value"&&q.n.shape!=="scalar"||(I={id:A,mode:Y},S=A,N())}function ie(A=!0){I=void 0,N(),A&&W(S)}function Ke(A,Y){let q=Y.mode==="new"?String(Y.value??""):String(A.path[A.path.length-1]),ae=K("input",{class:"tedit tname",value:q,"aria-label":Y.mode==="new"?`Name of the new ${Y.section?v(Y.section).singular:"entry"}`:`Rename ${A.label}`,spellcheck:"false",autocomplete:"off"});ae.value=q;let m=()=>{let G=ae.value.trim(),Z=Y.mode==="new"||Q(A)||M(A.path),$e=G?Z&&!s.nameRule.test(G)?r.nameHint:G!==q&&Ce(Y.mode==="new"?Y.mapPath:A.path.slice(0,-1),G,Z)?`"${G}" is already used`:"":"a name is needed";return ae.setAttribute("aria-invalid",String(!!$e)),ae.title=$e,$e?void 0:G};ae.addEventListener("input",m),ae.addEventListener("keydown",G=>{G.stopPropagation(),G.key==="Escape"&&(G.preventDefault(),ie()),G.key==="Enter"&&(G.preventDefault(),R())});let C=!1,R=()=>{if(C)return;let G=m();if(G===void 0){ae.value.trim()||(C=!0,ie());return}if(C=!0,I=void 0,Y.mode==="new"){let Z=[...Y.mapPath,G];se(i(Y.mapPath,G,Y.template(),{label:`Add ${Y.section?v(Y.section).singular:"entry"} ${G}`}))&&(S=Se(Z),e.select([Z],"tree"),T.add(S))}else if(G!==q){let Z=A.path;if(se(Q(A)?c(Z,G):d(Z,G))){let $e=[...Z.slice(0,-1),G];T.has(A.id)&&(T.delete(A.id),T.add(Se($e))),S=Se($e)}}N(),W(S)};return ae.addEventListener("blur",()=>{C||(ae.value.trim()&&m()!==void 0?R():(C=!0,I=void 0,N()))}),ae}function Ce(A,Y,q){if(q&&!y(A))return s.kinds.some(m=>Ne(m.kind).includes(Y));let ae=we(e.goodDoc.data,A);return!!ae&&typeof ae=="object"&&Y in ae}function Ee(A){let Y=n.nav(),q=we(e.goodDoc.data,A.path),ae=Y.values(A.path),m=s.slotAt(Se(A.path)),C=m?m.targets.flatMap(Z=>Ne(Z).map($e=>m.write?m.write($e):$e)).concat(m.extra??[]):[],R=[...new Set([...ae,...C])],G;return R.length&&(ae.length||m)?(G=K("select",{class:"tedit tvalue","aria-label":`Value of ${A.label}`},...R.map(Z=>K("option",{value:Z},Z))),R.includes(String(q))||G.prepend(K("option",{value:String(q??"")},String(q??""))),G.value=String(q??""),G.addEventListener("change",()=>je(A,G.value))):(G=K("input",{class:"tedit tvalue","aria-label":`Value of ${A.label}`,spellcheck:"false",autocomplete:"off"}),G.value=q==null?"":String(q)),G.addEventListener("keydown",Z=>{Z.stopPropagation(),Z.key==="Escape"&&(Z.preventDefault(),ie()),Z.key==="Enter"&&(Z.preventDefault(),je(A,G.value))}),G.addEventListener("blur",()=>{I?.id===A.id&&je(A,G.value,!1)}),G}function je(A,Y,q=!0){if(I?.id!==A.id)return;I=void 0;let ae=n.nav().types(A.path),m=we(e.goodDoc.data,A.path),C=Y;(ae.has("integer")||ae.has("number")||typeof m=="number")&&/^-?\d+(\.\d+)?$/.test(Y.trim())?C=Number(Y):(ae.has("boolean")||typeof m=="boolean")&&/^(true|false)$/.test(Y.trim())&&(C=Y.trim()==="true"),C!==m&&se(o(A.path,C)),N(),q&&W(S)}async function lt(A){if(x()||!A.length)return;let Y=A.map(de=>O.get(de)?.n).filter(de=>!!de&&!w(de)&&de.shape!=="missing"),q=Y.filter(de=>!Y.some(De=>De!==de&&De.path.length<de.path.length&&qt(De.path,de.path)));if(!q.length)return;let ae=!1,m=q.filter(Q).flatMap(de=>g(e.text,de.section,String(de.path[de.path.length-1])).filter(De=>!q.some(He=>qt(He.path,rt(De.path)))).map(De=>({n:de,r:De})));if(m.length){let de=K("ul",{class:"ref-list"},...m.map(({n:Re,r:ze})=>K("li",null,K("code",null,ze.path.slice(1).replace(/\//g,".")),` \u2014 ${ze.slot.what} (${Re.label})`))),De=q.length===1?h(q[0].path):`${q.length} items`,He=await $r(`Delete ${De}?`,[K("p",{class:"sub"},`${m.length===1?"One place refers":`${m.length} places refer`} to ${q.length===1?"it":"them"}:`),de,K("p",{class:"sub"},"Delete the references too, or leave them (the problems list will show them). Either way, Undo brings everything back.")],[{label:"Cancel",value:"cancel"},{label:"Delete only",value:"only",danger:!0},{label:"Delete with references",value:"with",danger:!0,primary:!0}]);if(!He){W(S);return}ae=He==="with"}let R=[...q].sort((de,De)=>typeof de.path.at(-1)=="number"&&typeof De.path.at(-1)=="number"?De.path.at(-1)-de.path.at(-1):0).map(de=>l(de.path,{withRefs:ae&&Q(de)})),G=_.findIndex(de=>de.n.id===q[0].id),Z=_[G+1]?.n.id&&!q.some(de=>_[G+1].n.id.startsWith(de.id))?_[G+1].n.id:_[G-1]?.n.id??"";se(R.length===1?R[0]:Ue(`Delete ${q.length} items`,R))&&(S=Z,e.select(Z?[rt(Z)]:[],"tree"),N(),W(S))}function Ue(A,Y){return{label:A,remap:q=>Y.reduce((ae,m)=>ae&&m.remap?m.remap(ae):ae,q),build:q=>{let ae=[],m=!1;for(let C of Y){let R=C.build(q);for(let G of R.steps)ae.push(G),q=yn(q,G);m||=!!R.fallback}return{steps:ae,fallback:m}}}}function dt(A){let Y=O.get(A)?.n;if(!Y||x())return;if(!Q(Y)){n.note(r.text.duplicateNote,"info");return}let q=u(Y.path);if(se(q)){let ae=q.select?.[0];ae&&(S=Se(ae),e.select([ae],"tree")),N(),W(S)}}function ut(A,Y){let q=$().has(A.id)?[...$()]:[A.id],ae=q.length>1,m=ne(A),C=x(),R=[];m.length&&!ae&&R.push({heading:"Add"},...m.slice(0,12),...m.length>12?[{label:"More\u2026",icon:"plus",onSelect:()=>ys(m,Y,"Add")}]:[],{sep:!0}),ae||(R.push({label:"Rename",icon:"pencil",keys:"F2",disabled:C||A.kind==="group"||w(A)||A.kind==="item",why:r.text.renameWhy,onSelect:()=>ge(A.id,"rename")}),A.shape==="scalar"&&R.push({label:"Edit value",icon:"pencil",keys:"Enter",disabled:C,onSelect:()=>ge(A.id,"value")}),R.push({label:"Duplicate",icon:"copy",keys:"\u2318D",disabled:C||!Q(A),why:r.text.duplicateWhy,onSelect:()=>dt(A.id)})),A.path.length&&R.push({label:"Select parent",icon:"arrow-up-right",keys:"\u2318\u2191",onSelect:()=>Ae()}),R.push({label:"Show in text",icon:"code-xml",onSelect:()=>n.showInText(A.path)}),n.clipItems&&R.push({sep:!0},...n.clipItems()),R.push({sep:!0},{label:ae?`Delete ${q.length} items`:"Delete",icon:"trash-2",keys:"\u232B",danger:!0,disabled:C||w(A)||A.shape==="missing",why:w(A)?r.text.deleteWhy:"Nothing to delete",onSelect:()=>lt(q)}),ys(R,Y,`${A.label||r.text.root} actions`)}function Ae(){let A=e.selection.length?e.selection:[rt(S)],Y=[...new Set(A.map(q=>{let ae=q.slice(0,-1);for(;ae.length&&!O.has(Se(ae));)ae=ae.slice(0,-1);return Se(ae)}))];ee(Y)}t.addEventListener("click",A=>{let Y=A.target.closest(".trow");!Y||A.target.closest(".tedit")||ue(Y.dataset.id,A)}),t.addEventListener("dblclick",A=>{let Y=A.target.closest(".trow");if(!Y||A.target.closest(".tedit, .twisty, .tadd"))return;let q=O.get(Y.dataset.id)?.n;q&&(q.shape==="scalar"&&A.target.closest(".tval")?ge(q.id,"value"):q.kind==="resource"||q.kind==="key"?ge(q.id,"rename"):B(q.id))}),t.addEventListener("contextmenu",A=>{let Y=A.target.closest(".trow");if(!Y)return;A.preventDefault();let q=Y.dataset.id;$().has(q)||ue(q,{shiftKey:!1,metaKey:!1,ctrlKey:!1});let ae=O.get(q)?.n;ae&&ut(ae,{x:A.clientX,y:A.clientY})}),t.addEventListener("focusin",A=>{let Y=A.target.closest(".trow");Y&&!A.target.closest(".tedit")&&(S=Y.dataset.id)}),t.addEventListener("keydown",A=>{if(A.target.closest(".tedit"))return;let Y=_.map(G=>G.n.id),q=Math.max(0,Y.indexOf(S)),ae=O.get(S),m=ae?.n,C=A.metaKey||A.ctrlKey,R=G=>{let Z=Y[Math.max(0,Math.min(Y.length-1,G))];A.shiftKey?(P||(P=S),ue(Z,{shiftKey:!0,metaKey:!1,ctrlKey:!1})):(P=Z,ee([Z]))};switch(A.key){case"ArrowDown":if(C)return;R(q+1);break;case"ArrowUp":if(C){Ae();break}R(q-1);break;case"Home":R(0);break;case"End":R(Y.length-1);break;case"ArrowRight":m&&m.children.length&&!T.has(m.id)?B(m.id,!0):m&&m.children.length&&R(q+1);break;case"ArrowLeft":m&&T.has(m.id)&&m.children.length?B(m.id,!1):ae?.parent&&(P=ae.parent.id,ee([ae.parent.id]));break;case"Enter":if(!m)return;if(m.shape==="scalar"&&m.kind!=="group"){let G=we(e.goodDoc.data,m.path);typeof G=="boolean"&&!x()?se(o(m.path,!G)):ge(m.id,"value")}else m.children.length&&B(m.id);break;case"F2":m&&ge(m.id,"rename");break;case"Delete":case"Backspace":lt(e.selection.length?e.selection.map(Se):[S]);break;case"ContextMenu":m&&ut(m,t.querySelector(`[data-id="${CSS.escape(S)}"]`));break;case"F10":if(A.shiftKey&&m)ut(m,t.querySelector(`[data-id="${CSS.escape(S)}"]`));else return;break;case"+":case"Insert":m&&ne(m).length&&ys(ne(m),t.querySelector(`[data-id="${CSS.escape(S)}"]`),"Add");break;default:if(C&&A.key.toLowerCase()==="d"){dt(S);break}if(C&&A.key.toLowerCase()==="a"){ee(Y.filter(G=>G),S);break}if(A.key.length===1&&!C&&/\S/.test(A.key)){let G=Date.now();j=G-k>700?A.key.toLowerCase():j+A.key.toLowerCase(),k=G;let $e=[...Y.slice(q+(j.length===1?1:0)),...Y.slice(0,q+1)].find(de=>(O.get(de)?.n.label??"").toLowerCase().startsWith(j));$e!==void 0&&(P=$e,ee([$e]));break}return}A.preventDefault()});let pt;t.addEventListener("dragstart",A=>{let Y=A.target.closest(".trow");Y&&(pt=Y.dataset.id,A.dataTransfer?.setData("text/plain",rt(pt).join(".")),A.dataTransfer&&(A.dataTransfer.effectAllowed="move"))});let et=A=>{let Y=A.target.closest(".trow");if(!Y||!pt||Y.dataset.id===pt)return;let q=O.get(pt)?.n,ae=O.get(Y.dataset.id)?.n;if(!q||!ae||Se(q.path.slice(0,-1))!==Se(ae.path.slice(0,-1)))return;let m=Y.getBoundingClientRect();return{r:Y,a:q,b:ae,after:A.clientY>m.top+m.height/2}};t.addEventListener("dragover",A=>{for(let q of t.querySelectorAll(".drop-before, .drop-after"))q.classList.remove("drop-before","drop-after");let Y=et(A);Y&&(A.preventDefault(),Y.r.classList.add(Y.after?"drop-after":"drop-before"))}),t.addEventListener("dragleave",A=>{if(A.target===t)for(let Y of t.querySelectorAll(".drop-before, .drop-after"))Y.classList.remove("drop-before","drop-after")}),t.addEventListener("drop",A=>{let Y=et(A);for(let G of t.querySelectorAll(".drop-before, .drop-after"))G.classList.remove("drop-before","drop-after");if(pt=void 0,!Y)return;A.preventDefault();let{a:q,b:ae,after:m}=Y,C=q.path.slice(0,-1),R=G=>G[G.length-1];if(typeof R(q.path)=="number"){let G=R(q.path),Z=R(ae.path)+(m?1:0);Z>G&&(Z-=1),se(p(C,G,Z))&&(S=Se([...C,Z]),e.select([[...C,Z]],"tree"))}else{let G=(O.get(Se(C))?.n.children??[]).map(de=>String(R(de.path))),Z=G.indexOf(String(R(ae.path))),$e=m?G[Z+1]:G[Z];$e!==String(R(q.path))&&se(f(q.path,$e===void 0?void 0:$e)),S=q.id}N(),W(S)}),e.on(A=>{if(A.remap){for(let q of[...T]){let ae=A.remap(rt(q));ae&&Se(ae)!==q&&(T.delete(q),T.add(Se(ae)))}let Y=A.remap(rt(S));Y&&(S=Se(Y))}A.kind==="load"&&(I=void 0,S=""),or(A)?bt():bt.now()});let bt=ir(()=>N());return e.onSelect(A=>{A.origin!=="tree"?z(A.paths):N()}),N(),{paint:N,dispose:()=>bt.cancel(),focus:()=>W(S),rows:()=>_.map(A=>({id:A.n.id,label:A.n.label,depth:A.depth,kind:A.n.kind,value:A.n.value,lifetime:A.n.lifetime})),startEdit:ge,remove:lt,duplicate:dt,expand:A=>B(A,!0)}}var hd=(t,e)=>e.reduce((n,s)=>n&&typeof n=="object"?n[s]:void 0,t);function xn(t,e,n,s){try{return t.apply(e,n)}catch(r){return s?.(String(r.message),"bad"),!1}}function Er(t,e){return{label:t,remap:n=>e.reduce((s,r)=>s&&r.remap?r.remap(s):s,n),build:n=>{let s=[],r=!1;for(let o of e){let i=o.build(n);for(let a of i.steps)s.push(a),n=yn(n,a);r||=!!i.fallback}return{steps:s,fallback:r}}}}function Ml(t){let{deleteCmd:e,renameCmd:n,renameKeyCmd:s,referencesTo:r,describe:o,duplicateCmd:i}=t.commands,a=f=>{let p=t.objectOf(Se(f));return!!p&&p.path===Se(f)};async function l(f,p,g,h){let b=p.filter(S=>S.length&&!p.some(P=>P!==S&&P.length<S.length&&qt(P,S)));if(!b.length)return!1;let v=b.filter(a).flatMap(S=>{let P=t.objectOf(Se(S));return r(f.text,P.kind,P.name).filter(I=>!b.some(_=>qt(_,rt(I.path)))).map(I=>({p:S,x:I}))}),w=!1;if(v.length){let S=await $r(`Delete ${b.length===1?o(b[0]):`${b.length} items`}?`,[K("p",{class:"sub"},`${v.length===1?"One place refers":`${v.length} places refer`} to ${b.length===1?"it":"them"}:`),K("ul",{class:"ref-list"},...v.map(({x:P})=>K("li",null,K("code",null,P.path.slice(1).replace(/\//g,".")),` \u2014 ${P.slot.what}`))),K("p",{class:"sub"},"Delete the references too, or leave them (the problems list will show them). Either way, Undo brings everything back.")],[{label:"Cancel",value:"cancel"},{label:"Delete only",value:"only",danger:!0},{label:"Delete with references",value:"with",danger:!0,primary:!0}]);if(!S)return!1;w=S==="with"}let y=[...b].sort((S,P)=>typeof S.at(-1)=="number"&&typeof P.at(-1)=="number"?P.at(-1)-S.at(-1):0).map(S=>e(S,{withRefs:w&&a(S)})),T=xn(f,y.length===1?y[0]:Er(`Delete ${b.length} items`,y),g,h);return T&&f.select([],g),T}async function c(f,p,g,h){let b=String(p[p.length-1]),v=K("input",{type:"text",value:b,"aria-label":"New name",spellcheck:"false",autocomplete:"off",class:"mono-input"});v.value=b;let w=K("p",{class:"dlg-error",role:"alert"}),M=()=>t.kinds.flatMap(P=>Object.keys(hd(f.goodDoc.data,P.section)??{})),y=()=>{let P=v.value.trim(),I=!t.nameRule.test(P)&&a(p)?t.nameHint:P!==b&&M().includes(P)?`"${P}" is already used`:"";return w.textContent=I,I?void 0:P};v.addEventListener("input",y);let T=$r(`Rename ${o(p)}`,[K("label",{class:"field"},K("span",null,"Name"),v),w,a(p)?K("p",{class:"sub"},"Every reference to it is renamed too."):""],[{label:"Cancel",value:"cancel"},{label:"Rename",value:"ok",primary:!0}]);if(setTimeout(()=>{v.focus(),v.select()},0),await T!=="ok")return!1;let S=y();return!S||S===b?!1:xn(f,a(p)?n(p,S):s(p,S),g,h)}let d=(f,p,g,h)=>{let b=i(p);xn(f,b,g,h)&&b.select&&f.select(b.select,g)};function u(f,p){let g=new Map;for(let h of p){let b=t.objectOf(Se(h));if(!b)continue;g.set(b.path,rt(b.path));for(let M of r(f.text,b.kind,b.name)){let y=t.objectOf(M.path);g.set(y?y.path:M.path,rt(y?y.path:M.path))}let v=hd(f.goodDoc.data,rt(b.path)),w=JSON.stringify(v??{}).match(/[a-z][a-z0-9-]*/g)??[];for(let M of t.kinds)for(let y of Object.keys(hd(f.goodDoc.data,M.section)??{}))if(w.includes(y)&&y!==b.name){let T=Se([...M.section,y]);g.set(T,rt(T))}}return[...g.values()]}return{deletePaths:l,renameDialog:c,duplicate:d,connected:u}}var $l=(t,e)=>e.reduce((n,s)=>n&&typeof n=="object"?n[s]:void 0,t),Tr=t=>!!t&&typeof t=="object"&&!Array.isArray(t),ar=Symbol("mixed");function El(t,e,n){let s,r=!1,o=n.kit,i=o.ui,{setCmd:a,deleteCmd:l,insertItemCmd:c,referencesTo:d,describe:u}=o.commands,{deletePaths:f,renameDialog:p}=o.actions,g=k=>o.kinds.find($=>$.kind===k),h=k=>g(k)?.singular??"item",b=k=>Object.keys($l(e.goodDoc.data,g(k)?.section??[])??{}).filter($=>!$.startsWith("x-")),v=k=>xn(e,k,"props",n.note);function w(){if(t.contains(document.activeElement)&&document.activeElement.matches("input, textarea"))return;t.replaceChildren();let k=e.selection;if(!k.length){t.append(K("p",{class:"hint"},"Select something in the canvas, the tree or the text."));return}let $=k.map(ve=>o.objectOf(Se(ve)));if(k.length>1){if(new Set($.map(B=>B?.kind)).size===1&&$.every(B=>B&&B.path===Se(rt(B.path)))){let B=[...new Set($.map(W=>W.path))].map(rt);t.append(K("div",{class:"sel-title"},`${B.length} ${h($[0].kind)}s`),K("div",{class:"sel-path"},B.map(W=>W[W.length-1]).join(", "))),M(B,$[0].kind)}else t.append(K("div",{class:"sel-title"},`${k.length} items`),K("ul",{class:"plain"},...k.map(B=>K("li",null,K("code",null,B.join(".")||i.rootItem)))));_();return}let x=k[0],N=$[0],F=N?rt(N.path):x.length?x:[];if(!N){O(x);return}let J=K("div",{class:"sel-headrow"},K("div",{class:"sel-title"},u(F))),oe=K("button",{type:"button",class:"btn sm quiet icon-only","aria-label":`Rename ${u(F)}`,title:"Rename (F2)"},Ut("pencil"));oe.addEventListener("click",()=>p(e,F,"props",n.note)),J.append(oe),t.append(J),Se(x)!==N.path&&(s=Se(x)),M([F],N.kind),P(N.kind,N.name),I(N.path),_()}function M(k,$){let x=n.nav(),N=e.goodDoc.data,F=k.map(ne=>$l(N,ne)??{}),J=F[0]&&Tr(F[0])?F[0]:{},oe=F.some(ne=>i.isExternal(ne)),ve=x.keys(k[0],oe?{external:!0}:J),B=Object.keys(J),W=ve.filter(ne=>F.some(fe=>Tr(fe)&&ne.name in fe)).sort((ne,fe)=>(B.indexOf(ne.name)+1||999)-(B.indexOf(fe.name)+1||999)),ee=n.read(),ue=new Set([...W.map(ne=>ne.name),...i.important($,F[0]??{},oe),...k.length===1&&ee!==void 0&&i.inheritedKeys?i.inheritedKeys(k[0],ee):[]]),z=ve.filter(ne=>!W.includes(ne)&&ue.has(ne.name)),X=ve.filter(ne=>!ue.has(ne.name)),Q=K("div",{class:"props"});for(let ne of[...W,...z])Q.append(y(k,$,ne,F,ee));if(X.length&&e.doc.ok){let ne=K("select",{class:"padd","aria-label":"Add a property"},K("option",{value:""},"+ Add property"),...X.map(fe=>K("option",{value:fe.name,title:(fe.doc??"").replace(/`/g,"")},fe.name)));ne.addEventListener("change",()=>{let fe=ne.value;if(!fe)return;let be=x.defaultFor([...k[0],fe]);s=Se([...k[0],fe]),r=!0,v(k.length===1?a([...k[0],fe],be,`Add ${u([...k[0],fe])}`):Er(`Add ${fe} to ${k.length} ${h($)}s`,k.map(we=>a([...we,fe],be))))}),Q.append(ne)}let te=new Set(ve.map(ne=>ne.name));for(let ne of new Set(F.flatMap(fe=>Tr(fe)?Object.keys(fe):[])))te.has(ne)||Q.append(y(k,$,{name:ne,shape:"scalar",enumValues:[],examples:[],doc:ne.startsWith("x-")?i.extensionDoc:"Not a key the schema knows."},F,ee));if(t.append(Q),s){let ne=Q.querySelector(`[data-path="${CSS.escape(s)}"]`);ne?.classList.add("focus-row"),ne?.scrollIntoView({block:"nearest"}),r&&ne?.querySelector("input, select, textarea")?.focus({preventScroll:!0}),s=void 0,r=!1}}function y(k,$,x,N,F){let J=n.nav(),oe=N.map(ge=>Tr(ge)?ge[x.name]:void 0),B=oe.every(ge=>JSON.stringify(ge)===JSON.stringify(oe[0]))?oe[0]:ar,W=oe.some(ge=>ge!==void 0),ee=$&&k.length===1&&F!==void 0?i.inherited?.(k[0],x.name,F):void 0,ue=k.map(ge=>Se([...ge,x.name])),z=K("div",{class:`prow${W?"":" unset"}`,"data-path":ue[0]}),X=K("label",{class:"plabel",title:x.doc?.replace(/`/g,"")??""},x.name),Q=`pf-${Math.random().toString(36).slice(2,8)}`;X.setAttribute("for",Q),z.append(X);let te=(ge,ie)=>v(k.length===1?a([...k[0],x.name],ge,ie):Er(ie??`Set ${x.name} on ${k.length} ${h($)}s`,k.map(Ke=>a([...Ke,x.name],ge)))),ne=()=>{let ge=k.filter((ie,Ke)=>oe[Ke]!==void 0);v(ge.length===1?{...l([...ge[0],x.name]),label:`Remove ${u([...ge[0],x.name])}`}:Er(`Remove ${x.name} from ${ge.length} ${h($)}s`,ge.map(ie=>l([...ie,x.name]))))},fe=o.slotAt(Se([...k[0],x.name])),be=o.slotAt(Se([...k[0],x.name,0])),we=J.values([...k[0],x.name]),Ne=J.types([...k[0],x.name]),qe,D=B===ar?"(mixed)":"";if(fe||we.length){let ge=[...new Set([...we,...fe?fe.targets.flatMap(Ke=>b(Ke).map(Ce=>fe.write?fe.write(Ce):Ce)).concat(fe.extra??[]):[]])],ie=K("select",{id:Q,class:"pinput"});ie.append(K("option",{value:"\0"},D||"\u2014"));for(let Ke of ge)ie.append(K("option",{value:Ke},Ke));B!==ar&&B!==void 0&&!ge.includes(String(B))&&ie.append(K("option",{value:String(B)},String(B))),ie.value=B===ar||B===void 0?"\0":String(B),ie.addEventListener("change",()=>{if(ie.value==="\0"){W&&ne();return}te(we.includes("true")&&(ie.value==="true"||ie.value==="false")?ie.value==="true":ie.value)}),qe=ie}else if(be&&k.length===1){let ge=Array.isArray(B)?B:[],ie=K("div",{class:"chips"});ge.forEach((Ce,Ee)=>{let je=K("button",{type:"button",class:"chip-x","aria-label":`Remove ${Ce}`},"\xD7");je.addEventListener("click",()=>v({...l([...k[0],x.name,Ee]),label:`Remove ${Ce} from ${u([...k[0],x.name])}`})),ie.append(K("span",{class:"chip"},String(Ce),je))});let Ke=[...new Set(be.targets.flatMap(Ce=>b(Ce)).concat(be.extra??[]))].filter(Ce=>!ge.includes(Ce));if(Ke.length){let Ce=K("select",{id:Q,class:"pinput chip-add","aria-label":`Add to ${x.name}`},K("option",{value:""},"+ add"),...Ke.map(Ee=>K("option",{value:Ee},Ee)));Ce.addEventListener("change",()=>{Ce.value&&v(c([...k[0],x.name],Ce.value,void 0,`Add ${Ce.value} to ${u([...k[0],x.name])}`))}),ie.append(Ce)}qe=ie}else if(x.name==="prompt"||typeof B=="string"&&B.includes(`
|
|
465
|
+
`)){let ge=K("textarea",{id:Q,class:"pinput",rows:"5",spellcheck:"false",placeholder:D});ge.value=typeof B=="string"?B:"",ge.addEventListener("change",()=>{let ie=ge.value;ie===""&&W?ne():ie!==B&&te(ie.endsWith(`
|
|
466
|
+
`)||!ie.includes(`
|
|
467
|
+
`)?ie:ie+`
|
|
468
|
+
`)}),qe=ge}else if(x.shape==="scalar"&&(B===void 0||B===ar||typeof B!="object")){let ge=K("input",{id:Q,class:"pinput",type:Ne.has("integer")||Ne.has("number")?"number":"text",spellcheck:"false",autocomplete:"off",placeholder:D});ge.value=B===void 0||B===ar?"":String(B),ge.addEventListener("change",()=>{let ie=ge.value;if(ie===""){W&&ne();return}let Ke=(Ne.has("integer")||Ne.has("number"))&&/^-?\d+(\.\d+)?$/.test(ie)?Number(ie):ie;Ke!==B&&te(Ke)}),ge.addEventListener("keydown",ie=>{ie.key==="Enter"&&ge.blur()}),qe=ge}else{let ge=K("input",{id:Q,class:"pinput mono",spellcheck:"false",autocomplete:"off",placeholder:D||(x.shape==="list"?"[a, b]":"{ key: value }")});ge.value=B===void 0||B===ar?"":fn(B),ge.addEventListener("change",()=>{if(ge.value.trim()===""){W&&ne();return}let ie;try{ie=jo(ge.value)}catch(Ke){ge.setAttribute("aria-invalid","true"),ge.title=`Not YAML: ${Ke.message}`;return}ge.removeAttribute("aria-invalid"),JSON.stringify(ie)!==JSON.stringify(B)&&te(ie)}),ge.addEventListener("keydown",ie=>{ie.key==="Enter"&&ge.blur()}),qe=ge}let se=B===void 0||B===ar?"":T(B);if(se&&(qe.title=se),ee&&!W){z.classList.add("inherited"),z.append(K("div",{class:"pinherit",title:T(ee.value)},T(ee.value)));let ge=K("div",{class:"pfrom"},`inherited from ${ee.from??i.inheritedFrom}`),ie=K("button",{type:"button",class:"btn sm quiet poverride",title:`Write ${x.name}: ${T(ee.value)} in this file, to change it here`},"Override");ie.addEventListener("click",()=>{s=ue[0],r=!0,te(ee.value,`Override ${u([...k[0],x.name])}`)}),z.append(ge,ie);let Ke=n.problems().filter(Ce=>ue.some(Ee=>Ce.path===Ee||Ce.path.startsWith(Ee+"/")));for(let Ce of Ke)z.append(K("div",{class:`pprob ${Ce.severity}`},Ut(Ce.severity==="error"?"circle-x":"triangle-alert"),Ce.message));return z}z.append(qe);let Me=K("span",{class:"pacts"});if(ee&&W){let ge=K("button",{type:"button",class:"btn sm quiet",title:`Remove this file's value: ${T(ee.value)} applies again`},"Reset");ge.addEventListener("click",ne),Me.append(ge)}else if(W&&qe.tagName!=="SELECT"){let ge=K("button",{type:"button",class:"btn sm quiet icon-only","aria-label":`Remove ${x.name}`,title:`Remove ${x.name}`},Ut("x"));ge.addEventListener("click",ne),Me.append(ge)}z.append(Me),ee&&z.append(K("div",{class:"pfrom"},`overrides ${T(ee.value)} from ${ee.from??i.inheritedFrom}`));let Oe=n.problems().filter(ge=>ue.some(ie=>ge.path===ie||ge.path.startsWith(ie+"/")));for(let ge of Oe)z.append(K("div",{class:`pprob ${ge.severity}`},Ut(ge.severity==="error"?"circle-x":"triangle-alert"),ge.message));return z}let T=k=>k===null||typeof k!="object"?String(k):fn(k);function S(k){let $=n.now&&i.facts?i.facts(n.now(k)):void 0;if(!$)return;if(t.append(K("div",{class:"sel-head"},"Now")),!$.length){t.append(K("p",{class:"hint now-unknown"},"Not known: the host has said nothing about it."));return}let x=K("dl",{class:"now"});for(let N of $)x.append(K("dt",null,N.term),K("dd",N.cls?{class:N.cls}:null,N.def));t.append(x)}function P(k,$){S(Se([...g(k)?.section??[],$]));let x=d(e.text,k,$);if(t.append(K("div",{class:"sel-head"},x.length?`Used in ${x.length} place${x.length>1?"s":""}`:"Not referenced")),!x.length)return;let N=K("ul",{class:"plain sel-refs"});for(let F of x){let J=K("button",{type:"button",class:"linkish"},F.path.slice(1).replace(/\//g,"."));J.addEventListener("click",()=>e.select([rt(F.path)],"props")),N.append(K("li",null,J,K("span",{class:"hint"},` ${F.slot.what}`)))}t.append(N)}function I(k){let $=n.problems().filter(x=>x.path===k&&!x.file);$.length&&t.append(K("div",{class:"sel-head"},"Problems"),...$.map(x=>K("div",{class:`sel-prob ${x.severity}`},Ut(x.severity==="error"?"circle-x":"triangle-alert"),K("span",null,x.message))))}function _(){if(!e.doc.ok||!e.selection.some($=>$.length))return;let k=K("button",{type:"button",class:"btn sm danger props-delete"},Ut("trash-2"),e.selection.length>1?`Delete ${e.selection.length} items`:"Delete");k.addEventListener("click",()=>f(e,e.selection,"props",n.note)),t.append(k)}function O(k){let $=n.nav();t.append(K("div",{class:"sel-title"},k.length?u(k):i.rootTitle),K("code",{class:"sel-path"},k.join(".")||"(the whole file)"));let x=$.hover(k);x&&k.length&&t.append(K("p",{class:"sel-doc"},x.split(`
|
|
469
469
|
|
|
470
|
-
`)[0].replace(/`/g,"")));let N=ll(e.goodDoc.data,S);if(o.kinds.some(ee=>Me(ee.section)===Me(S))){let ee=gr(N)?Object.keys(N).length:0;t.append(z("p",null,`${ee} ${ee===1?"entry":"entries"}. Add one from the tree's +, or the canvas's menu.`));return}let J=S.length?gr(N)?S:S.slice(0,-1):[],ae=ll(e.goodDoc.data,J);if(!gr(ae)&&J.length)return;let we=new Set(o.kinds.map(ee=>String(ee.section[0]))),j=$.keys(J,ae??{}).filter(ee=>!we.has(ee.name)||J.length),U=z("div",{class:"props"});for(let ee of j)U.append(x([J],"",ee,[ae??{}],void 0));if(t.append(U),S.length&&Me(S)!==Me(J)){let ee=U.querySelector(`[data-path="${CSS.escape(Me(S))}"]`);ee?.classList.add("focus-row"),ee?.scrollIntoView({block:"nearest"})}}t.addEventListener("focusout",()=>setTimeout(()=>{t.contains(document.activeElement)||v()},0)),e.onSelect(()=>v());let _=qs(()=>v());return e.on(S=>{Ys(S)?_():_.now()}),{paint:v,dispose:()=>_.cancel()}}var on="http://www.w3.org/2000/svg";function dl(t,e,n){let s=n.kit,r=s.ui,o=r.text,{setCmd:i,deleteCmd:a,insertCmd:l,insertItemCmd:c,pinsCmd:d,withPinsMoved:u,freshName:f,describe:p}=s.commands,{deletePaths:g,renameDialog:h,duplicate:b,connected:k}=s.actions,v=P=>s.objectOf(P),M=P=>s.kinds.find(R=>R.kind===P),x=s.pins.key,T;t.classList.add("canvas");let y=z("div",{class:`${r.rootClass} canvas-stage`,tabindex:"0",role:"application","aria-label":o.stage}),A=z("div",{class:"canvas-tools",role:"toolbar","aria-label":"Canvas"}),D=z("button",{type:"button",class:"btn sm quiet icon-only","aria-label":"Zoom out (\u2212)",title:"Zoom out (\u2212)"},"\u2212"),K=z("button",{type:"button",class:"btn sm quiet zoom-label",title:"Fit (0) \xB7 100% (1)"},"100%"),C=z("button",{type:"button",class:"btn sm quiet icon-only","aria-label":"Zoom in (+)",title:"Zoom in (+)"},"+"),_=z("button",{type:"button",class:"btn sm quiet",title:"Fit (0)"},"Fit"),S=(P,R,V)=>{let W=z("div",{class:"segmented",role:"group","aria-label":P,title:P});for(let[oe,se,ie]of V){let le=z("button",{type:"button",class:"seg","data-v":oe,title:ie},se);le.addEventListener("click",()=>{fe[R]=oe,X(),Q()}),W.append(le)}return W},$=S("The wheel","wheel",[["zoom","Zoom","The wheel zooms around the pointer; \u21E7-wheel pans sideways"],["scroll","Scroll","The wheel pans; \u21E7-wheel pans sideways; a pinch zooms"]]),w=S(o.dragGroup,"drag",[["pan","Pan","Drag pans; \u21E7- or \u2318-drag draws a selection"],["select","Select",o.dragSelectTip]]),N="3d",F,J,ae=async()=>J??=await s.flat.load(),we=z("div",{class:"segmented view-seg",role:"group","aria-label":"The view"});for(let[P,R,V]of[["3d","3D","3D: the drawing; drag a selected thing to move it"],["2d","2D","2D: select, rename, delete, add from the palette and edit here; moving is in 3D"]]){let W=z("button",{type:"button",class:"seg","data-v":P,title:V},R);W.addEventListener("click",()=>B(P)),we.append(W)}let j={host:t,doc:e,cd:()=>te,svg:()=>ne,elementsFor:P=>G(P),boxOf:P=>Z(P),union:P=>Se(P),outlinesFor:P=>Ie(P),scale:()=>Ze(),full:()=>Ne.full,toSvg:(P,R)=>at(P,R),autoFit:()=>de(),paint:()=>De(),reveal:P=>dt(P),note:(P,R)=>n.note(P,R)},U=n.layer?.(j);A.append(...U?.tools??[],...s.flat?[we]:[],$,w,D,K,C,_);let ee=z("div",{class:"canvas-empty",hidden:!0});t.append(y,A,ee,...U?.marks??[]);let fe={wheel:"zoom",drag:"pan"};try{Object.assign(fe,JSON.parse(n.store?.get("canvas-nav")??"{}"))}catch{}s.flat&&n.store?.get("canvas-view")==="2d"&&(N="2d");function B(P){if(!s.flat||P===N)return;ze();let R=N;N=P,n.store?.set("canvas-view",P),Q(),ne&&te&&ne.parentNode===y&&(be={svg:ne,mode:R}),re!==void 0&&(Ne.view=void 0,ye="",I(re,$e))}let X=()=>n.store?.set("canvas-nav",JSON.stringify(fe));function Q(){for(let[P,R]of[[$,fe.wheel],[w,fe.drag],[we,N]])for(let V of P.querySelectorAll(".seg"))V.setAttribute("aria-pressed",String(V.dataset.v===R));if(ne?.classList.toggle("mode-pan",fe.drag==="pan"),ne?.classList.toggle("mode-select",fe.drag==="select"),Ce?.kind==="pin"&&Ce.moved){ne?.classList.add("dragging"),ne?.classList.toggle("drag-bad",!!Ce.invalid);return}n.onHint?.(`${fe.drag==="pan"?"Drag: pan \xB7 \u21E7-drag: select":"Drag: select \xB7 space-drag: pan"} \xB7 Wheel: ${fe.wheel==="zoom"?"zoom":"scroll"}`)}let te,ne,me,ye="",xe,Re=()=>document,Ue=!1;async function I(P,R){if(Ue)return;if(!P){Be(o.unreadable);return}let V=JSON.stringify(R);if(V===ye&&ne){pt()||De();return}if(N==="2d"&&!J)try{await ae()}catch(oe){N="3d",Q(),n.note(`The 2D view couldn't load: ${oe.message}`,"warn")}let W;try{W=s.draw(P,R,n.theme)}catch(oe){Be(`The canvas couldn't draw this: ${oe.message}`);return}if(W.diags.length){Be(`The canvas couldn't draw this: ${W.diags[0]}`);return}if(ye=V,re=P,$e=R,pt()){Pe=!0;return}await Ee(W),te.pinNotes.length&&n.note(`Pins: ${te.pinNotes.join("; ")}`,"warn")}let re,$e,Pe=!1,be,ce;function ze(){if(!ce)return;let P=ce;ce=void 0,P.m.finish(),P.from.remove(),P.to.style.visibility=""}function Oe(P,R){let V=J?.morph?.(y,te.scene,P,R,{motion:s.flat?.motion,duration:s.flat?.duration});if(!V){P.svg.remove();return}P.svg.style.visibility="hidden",R.style.visibility="hidden";let W={m:V,from:P.svg,to:R};ce=W,y.classList.add("morphing"),V.done.then(()=>{ce===W&&ze(),y.classList.remove("morphing")})}async function Ee(P){ze();let R,V=P.scene.rendered.viewBox;try{if(N==="2d"&&J){F=J.draw(P.scene,y,{styles:s.flat?.styles,title:s.flat?.title,options:s.flat?.options}),V=F.full,R=To(F.svg);for(let pe of R.querySelectorAll("[tabindex]"))pe.removeAttribute("tabindex"),pe.removeAttribute("role")}else F=void 0,R=To(P.svg)}catch(pe){Be(`The canvas couldn't draw this: ${pe.message}`);return}te=P,R.classList.add("scene"),R.removeAttribute("width"),R.removeAttribute("height"),R.setAttribute("preserveAspectRatio","xMidYMid meet"),R.setAttribute("aria-hidden","true"),me=document.createElementNS(on,"g"),me.setAttribute("class","overlay"),me.setAttribute("fill","none"),me.setAttribute("stroke","currentColor"),me.setAttribute("pointer-events","none"),R.append(me,...U?.groups?.()??[]);let W=be;be=void 0,W&&ne===W.svg&&ne.parentNode===y?(W.svg.querySelector(".overlay")?.replaceChildren(),W.svg.style.position="absolute",W.svg.style.inset="0",y.append(R)):ne?.parentNode===y?ne.replaceWith(R):y.append(R),ne=R;let[oe,se,ie,le]=V;Ne.full={x:oe,y:se,w:ie,h:le},Ne.view?ft(ot):(Ne.view={...Ne.full},de()),ee.hidden=!0,U?.drawn?.(),ut&&yt(ut)&&(ut=void 0),Q(),De(),W&&W.svg!==R&&(getComputedStyle(y).position==="static"&&(y.style.position="relative"),Oe(W,R))}function Be(P){be=void 0,ee.textContent=P,ee.hidden=!1}function it(P){De()}function We(){if(!te||!ne)return;let P=[...new Set([...te.pathOf.values()].filter(V=>{let W=v(V);return W&&W.path===V}))],R=U?.extent?.()??[];return Se([...P.flatMap(V=>G(V)).filter(V=>V.getBBox().width||V.getBBox().height).map(Z),...R])}let Ne=va(t,{svg:()=>ne,onApply:P=>{ne.classList.toggle("zoom-near",P>=1);let R=Math.round(P*100);K.textContent=`${R}%`,n.onZoom(R)},onRezoom:()=>De(),itemsBox:()=>We(),marksShowing:()=>!!U?.showing?.()}),{size:gt,scale:Ze,quietly:ft,applyView:ot,toSvg:at,zoomAt:E,fit:Y,fitItems:q,autoFit:de,actual:m,settled:O}=Ne;function L(){let P=Ke(e.selection);P&&Y({x:P.x-20,y:P.y-20,w:P.w+40,h:P.h+40})}C.addEventListener("click",()=>E(1.25)),D.addEventListener("click",()=>E(.8)),K.addEventListener("click",()=>q()),_.addEventListener("click",()=>q());let G=P=>!ne||!te?[]:[...te.pathOf.entries()].filter(([,V])=>V===P||P&&V.startsWith(P+"/")&&!1).map(([V])=>V).flatMap(V=>[...ne.querySelectorAll(`[data-id="${CSS.escape(V)}"]`)]).filter(V=>!V.closest(".pre")&&!V.classList.contains("pre")),Z=P=>{let R=P.getBBox(),V=P.getCTM(),W=ne.getCTM();if(!V||!W)return{x:R.x,y:R.y,w:R.width,h:R.height};let oe=W.inverse().multiply(V),se=[[R.x,R.y],[R.x+R.width,R.y],[R.x,R.y+R.height],[R.x+R.width,R.y+R.height]].map(([pe,ge])=>({x:oe.a*pe+oe.c*ge+oe.e,y:oe.b*pe+oe.d*ge+oe.f})),ie=se.map(pe=>pe.x),le=se.map(pe=>pe.y);return{x:Math.min(...ie),y:Math.min(...le),w:Math.max(...ie)-Math.min(...ie),h:Math.max(...le)-Math.min(...le)}},Se=P=>{if(!P.length)return;let R=Math.min(...P.map(se=>se.x)),V=Math.min(...P.map(se=>se.y)),W=Math.max(...P.map(se=>se.x+se.w)),oe=Math.max(...P.map(se=>se.y+se.h));return{x:R,y:V,w:W-R,h:oe-V}},ue=P=>{let R=Me(P),V=G(R),W=v(R);return!V.length&&W&&W.path!==R&&(V=G(W.path)),V.length?Se(V.filter(oe=>oe.getBBox().width||oe.getBBox().height).map(Z)):void 0},Ke=P=>Se(P.map(ue).filter(R=>!!R)),Ye=P=>{let R=P?.closest?.("[data-id]");if(!R||!te)return;let V=R;for(;V;){let W=V.getAttribute("data-id");if(W&&te.pathOf.has(W))return te.pathOf.get(W);V=V.parentElement?.closest("[data-id]")??null}};function Ie(P){if(!te)return[];let R=[],V=new Set([...te.pathOf].filter(([,W])=>W===P).map(([W])=>W));if(F&&ne)return F.outlines(V,ne);for(let[W,oe]of te.pathOf){if(oe!==P)continue;let se=te.scene.layout.byId.get(W),ie=se?.parent;for(;ie&&!V.has(ie.id);)ie=ie.parent;if(!ie)if(se){if(ne?.querySelector(`[data-id="${CSS.escape(W)}"].pre`))continue;let le=Ft(s.catalog,se.region?.kind)?.shape,pe=se.type==="node"||le==="slab"||le==="block";R.push({kind:"poly",id:W,points:pe?xa(se.box):Ir(se.box)})}else te.scene.rendered.paths[W]&&!ne?.querySelector(`[data-id="${CSS.escape(W)}"].pre`)&&R.push({kind:"route",d:te.scene.rendered.paths[W]})}return R}function De(){if(Ne.painted(Ne.view?Ze():0),!me||!ne)return;let P=Re();me.replaceChildren();let R=(le,pe,ge=4)=>{let Te=P.createElementNS(on,"rect");Te.setAttribute("class",pe),Te.setAttribute("x",String(le.x-ge)),Te.setAttribute("y",String(le.y-ge)),Te.setAttribute("width",String(le.w+ge*2)),Te.setAttribute("height",String(le.h+ge*2)),Te.setAttribute("rx","6"),me.append(Te)},V=(le,pe)=>{let ge=v(le),Te=Ie(le);if(!Te.length&&ge&&ge.path!==le&&(Te=Ie(ge.path)),!Te.length){let qe=ue(nt(le));qe&&R(qe,pe,pe==="hover"?3:4);return}for(let qe of Te)if(qe.kind==="route"){let Le=P.createElementNS(on,"path");Le.setAttribute("class",pe==="ring"?"route-ring":"route-hover"),Le.setAttribute("d",qe.d),me.append(Le)}else{let Le=P.createElementNS(on,"polygon");Le.setAttribute("class",pe),Le.setAttribute("points",qe.points.map(([ct,Je])=>`${ct.toFixed(1)},${Je.toFixed(1)}`).join(" ")),Le.setAttribute("data-for",qe.id),me.append(Le)}};xe!==void 0&&!e.selection.some(le=>Me(le)===xe)&&V(xe,"hover");for(let le of e.selection)V(Me(le),"ring");let W=bt(),oe=T?.from??W,se=oe?ue(nt(oe.path)):void 0;if(se&&s.connect){let le=Ze(),pe=se.x+se.w+10/le,ge=se.y+se.h/2;if(T&&T.x!==void 0&&T.y!==void 0){T.over&&V(T.over,"hover");let Te=P.createElementNS(on,"line");Te.setAttribute("class",`connect-line${T.over?" ok":""}`),Te.setAttribute("x1",String(pe)),Te.setAttribute("y1",String(ge)),Te.setAttribute("x2",String(T.x)),Te.setAttribute("y2",String(T.y)),me.append(Te)}if(!T){let Te=P.createElementNS(on,"circle");Te.setAttribute("class","connect-handle"),Te.setAttribute("cx",String(pe)),Te.setAttribute("cy",String(ge)),Te.setAttribute("r",String(7/le)),Te.style.pointerEvents="all",Te.style.cursor="crosshair";let qe=P.createElementNS(on,"title");qe.textContent=`Drag to what ${oe.name} connects to`,Te.append(qe),me.append(Te)}}let ie=new Map;for(let le of n.problems()){if(le.file)continue;let pe=v(le.path);if(!pe)continue;let ge=ie.get(pe.path)??{e:0,w:0};le.severity==="error"?ge.e++:ge.w++,ie.set(pe.path,ge)}for(let[le,pe]of ie){let ge=G(le).filter(ds=>te.scene.layout.byId.has(ds.getAttribute("data-id")??"")),Te=Se(ge.map(Z));if(!Te)continue;let qe=P.createElementNS(on,"g");qe.setAttribute("class",`badge${pe.e?"":" warn"}`);let Le=Ze(),ct=Te.x+Te.w,Je=Te.y,Rt=9/Le,Ge=P.createElementNS(on,"circle");Ge.setAttribute("cx",String(ct)),Ge.setAttribute("cy",String(Je)),Ge.setAttribute("r",String(Rt));let $t=P.createElementNS(on,"text");$t.setAttribute("x",String(ct)),$t.setAttribute("y",String(Je)),$t.style.fontSize=`${(11/Le).toFixed(2)}px`,$t.textContent=String(pe.e||pe.w),qe.append(Ge,$t),me.append(qe)}U?.paint?.(P)}let Ce,vt=!1,Mn=()=>{y.addEventListener("pointerdown",Et),y.addEventListener("pointermove",bn),y.addEventListener("pointerup",fn),y.addEventListener("pointercancel",fn),y.addEventListener("wheel",Ae,{passive:!1}),y.addEventListener("contextmenu",Fe),y.addEventListener("dblclick",P=>{let R=Ye(P.target);R!==void 0&&n.showInText(nt(R))})},kt=P=>({x:P.clientX,y:P.clientY}),St=P=>{try{y.setPointerCapture(P.pointerId)}catch{}};function Et(P){if(y.focus({preventScroll:!0}),U?.down?.(P))return;let{x:R,y:V}=kt(P);if(P.button===0&&T?.pick){P.preventDefault(),et(Ye(P.target));return}if(P.button===0&&P.target?.closest?.(".connect-handle")){let qe=bt();if(qe){St(P),P.preventDefault();let Le=at(R,V);T={from:qe,x:Le.x,y:Le.y},De();return}}(P.button===0||P.button===1)&&St(P);let W=()=>{Ce={kind:"pan",x0:R,y0:V,v0:{...Ne.view}},ne?.classList.add("panning"),P.preventDefault()};if(P.button===1||vt){W();return}if(P.button!==0)return;let oe=Ye(P.target);if(oe===void 0){let qe=P.shiftKey||P.metaKey||P.ctrlKey;if(fe.drag==="pan"&&!qe){Ce={kind:"pan",x0:R,y0:V,v0:{...Ne.view},emptyClick:!0},ne?.classList.add("panning");return}let Le=fe.drag==="select"&&qe;Ce={kind:"marquee",x0:R,y0:V,sel0:Le?e.selection:[],add:Le,touch:P.altKey};return}let se=nt(oe),ie=e.selection.map(Me);if(P.shiftKey||P.metaKey||P.ctrlKey){e.select(ie.includes(oe)?e.selection.filter(qe=>Me(qe)!==oe):[...e.selection,se],"canvas");return}ie.includes(oe)||e.select([se],"canvas");let le=ie.includes(oe)&&ie.length>1?oe:void 0;Ce={kind:"click",x0:R,y0:V,ptr:le};let pe=v(oe),ge=pe&&pe.path===oe?pe.name:void 0,Te=ge&&N==="3d"?te?.pinId.get(ge):void 0;if(Te&&te){let qe=te.scene.layout.byId.get(Te),Le=Rr(te.scene,Te);if(qe&&Le){let ct=qe.box,Je=qe.parent,Rt=(Je?Je.children:te.scene.layout.items.filter(Ge=>!Ge.parent)).filter(Ge=>Ge!==qe).map(Ge=>({x0:Ge.box.x0,y0:Ge.box.y0,x1:Ge.box.x1,y1:Ge.box.y1}));Ce={kind:"pin",x0:R,y0:V,name:ge,id:Te,ptr:oe,narrow:le,start:Le,shown:Le,z0:ct.z0,size:[ct.x1-ct.x0,ct.y1-ct.y0],siblings:Rt,parent:Je?{w:Je.box.x1-Je.box.x0,d:Je.box.y1-Je.box.y0,pad:Do(s.catalog,Je.region),box:Je.box,label:Je.region?.label??Je.id}:void 0,origCd:te}}}}function bn(P){let{x:R,y:V}=kt(P);if(T){let oe=at(R,V),se=Ye(document.elementFromPoint(R,V)),ie=se===void 0?void 0:v(se);T={...T,x:oe.x,y:oe.y,over:ie&&ie.path!==T.from.path?ie.path:void 0},De();return}if(!Ce){let oe=Ye(P.target);oe!==xe&&(xe=oe,De());return}let W=Ze();if(Ce.kind==="click"&&N==="2d"&&!Ce.moved&&Math.hypot(R-Ce.x0,V-Ce.y0)>4){Ce.moved=!0,n.onHint?.("Moving is in 3D: switch to 3D to drag it where it goes");return}if(Ce.kind==="pan")Math.hypot(R-Ce.x0,V-Ce.y0)>3&&(Ce.emptyClick=!1),Ne.view={...Ce.v0,x:Ce.v0.x-(R-Ce.x0)/W,y:Ce.v0.y-(V-Ce.y0)/W},ot();else if(Ce.kind==="marquee"){if(Math.hypot(R-Ce.x0,V-Ce.y0)<3)return;Ce.moved=!0;let oe=at(Ce.x0,Ce.y0),se=at(R,V);if(F){Yt(oe,se);return}let[ie,le]=ws(oe.x,oe.y),[pe,ge]=ws(se.x,se.y),Te={x0:Math.min(ie,pe),y0:Math.min(le,ge),x1:Math.max(ie,pe),y1:Math.max(le,ge)},qe=new Map;for(let[Je,Rt]of Jt()){let Ge=Rt,$t=Ge.x0>=Te.x0&&Ge.y0>=Te.y0&&Ge.x1<=Te.x1&&Ge.y1<=Te.y1,ds=Ge.x0<Te.x1&&Ge.x1>Te.x0&&Ge.y0<Te.y1&&Ge.y1>Te.y0;(Ce.touch?ds:$t)&&qe.set(Je,nt(Je))}let Le=new Map((Ce.sel0??[]).map(Je=>[Me(Je),Je]));for(let[Je,Rt]of qe)Le.set(Je,Rt);e.select([...Le.values()],"canvas"),De();let ct=Re().createElementNS(on,"polygon");ct.setAttribute("class","marquee"),ct.setAttribute("points",[[Te.x0,Te.y0],[Te.x1,Te.y0],[Te.x1,Te.y1],[Te.x0,Te.y1]].map(([Je,Rt])=>Xe(Je,Rt,0).map(Ge=>Ge.toFixed(1)).join(",")).join(" ")),me.append(ct),Mt=Te}else if(Ce.kind==="pin"){if(!Ce.moved&&Math.hypot(R-Ce.x0,V-Ce.y0)<4)return;if(Ce.moved=!0,Ot={x:R,y:V,alt:P.altKey},!Pt){Pt=!0;let oe=()=>{Pt&&(Pt=!1,as())};requestAnimationFrame(oe),setTimeout(oe,32)}}}function Yt(P,R){if(!Ce||!F||!te)return;let V={l:Math.min(P.x,R.x),t:Math.min(P.y,R.y),r:Math.max(P.x,R.x),b:Math.max(P.y,R.y)},W=new Map;for(let ie of F.hits(V,!!Ce.touch)){let le=te.pathOf.get(ie);le!==void 0&&v(le)?.path===le&&W.set(le,nt(le))}let oe=new Map((Ce.sel0??[]).map(ie=>[Me(ie),ie]));for(let[ie,le]of W)oe.set(ie,le);e.select([...oe.values()],"canvas"),De();let se=Re().createElementNS(on,"rect");se.setAttribute("class","marquee"),se.setAttribute("x",String(V.l)),se.setAttribute("y",String(V.t)),se.setAttribute("width",String(V.r-V.l)),se.setAttribute("height",String(V.b-V.t)),me.append(se)}let Pt=!1,Ot,_t=0,pt=()=>Ce?.kind==="pin"&&Ce.moved?Ce:void 0;function as(){let P=pt();if(!P||!Ot||!te)return;let R=Ze(),V=Ot.alt?.5:1;P.step=V;let W=Fo(P.start,ws((Ot.x-P.x0)/R,(Ot.y-P.y0)/R),V,P.size,P.parent),oe=P.parent?P.parent.box.x0:0,se=P.parent?P.parent.box.y0:0,ie={x0:oe+W.at[0],y0:se+W.at[1],x1:oe+W.at[0]+P.size[0],y1:se+W.at[1]+P.size[1]},le=!P.move||P.move.at[0]!==W.at[0]||P.move.at[1]!==W.at[1];P.move=W,P.invalid=rr(ie,P.siblings),ne?.classList.add("dragging"),ne?.classList.toggle("drag-bad",P.invalid),Yn(P.id,[W.at[0]-P.shown[0],W.at[1]-P.shown[1]]),ls(ie);let pe=P.parent?`within ${P.parent.label}`:"on the canvas";n.onHint?.(`Moving ${P.name} ${pe} \xB7 ${V===1?"whole cells (\u2325: half cells)":"half cells"} \xB7 ${P.invalid?"overlaps: it won't drop here":"Esc cancels"}${o.pinHint}`),le&&!P.invalid&&re&&(clearTimeout(_t),_t=window.setTimeout(async()=>{let ge=pt();if(!ge||ge.invalid||!ge.move)return;let Te;try{({next:Te,keep:ge.keep}=Ht(ge))}catch{return}pt()===ge&&(await Ee(Te),pt()===ge&&(ge.shown=ge.move.at,Yn(ge.id,[0,0]),ls(ge.parent?{x0:ge.parent.box.x0+ge.move.at[0],y0:ge.parent.box.y0+ge.move.at[1],x1:ge.parent.box.x0+ge.move.at[0]+ge.size[0],y1:ge.parent.box.y0+ge.move.at[1]+ge.size[1]}:ie)))},0))}function Ht(P){let R=JSON.parse(JSON.stringify($e??{}));s.pins.legacyOnly(R)&&(R[x]=R[s.pins.legacyKey],delete R[s.pins.legacyKey]),R[x]??={},R[x].layout??={};let V=R[x].layout;V[P.name]={at:P.move.at};let W=s.draw(re,R,n.theme),oe=P.origCd,se=new Map([...oe.pinId].map(([ge,Te])=>[Te,ge])),ie=oe.scene.layout.byId.get(P.id),le=ie.parent?ie.parent.children:oe.scene.layout.items.filter(ge=>!ge.parent),pe=[];for(let ge of le){if(ge===ie)continue;let Te=se.get(ge.id),qe=Rr(oe.scene,ge.id),Le=W.scene.layout.byId.get(ge.id)?.box;!Te||!qe||!Le||Te in V||(Math.abs(Le.x0-ge.box.x0)>1e-6||Math.abs(Le.y0-ge.box.y0)>1e-6)&&pe.push([Te,qe])}if(pe.length){for(let[ge,Te]of pe)V[ge]={at:Te};W=s.draw(re,R,n.theme)}return{next:W,keep:pe}}function Yn(P,[R,V]){if(!ne||!te)return;let[W,oe]=[(R-V)*It*xt,(R+V)*.5*xt],se=new Set([P]);for(let ie of te.scene.layout.items){let le=ie.parent;for(;le;){if(le.id===P){se.add(ie.id);break}le=le.parent}}for(let ie of ne.querySelectorAll("[data-id]"))se.has(ie.getAttribute("data-id")??"")&&(ie.parentElement?.closest(`[data-id="${CSS.escape(ie.getAttribute("data-id"))}"]`)||ie.setAttribute("transform",R||V?`translate(${W.toFixed(1)} ${oe.toFixed(1)})`:""))}function ls(P){let R=pt();if(!R||!me)return;De();let V=Re(),W=V.createElementNS(on,"g");W.setAttribute("class",R.gridShown?"gridwrap":"gridwrap fresh"),R.gridShown=!0;let oe=R.z0,se=(Le,ct)=>Xe(Le,ct,oe).map(Je=>Je.toFixed(1)).join(","),ie=R.parent?R.parent.box:{x0:Math.floor(P.x0)-8,y0:Math.floor(P.y0)-8,x1:Math.ceil(P.x1)+8,y1:Math.ceil(P.y1)+8},le=(Le,ct,Je,Rt,Ge)=>{let $t=V.createElementNS(on,"polyline");$t.setAttribute("class",Ge),$t.setAttribute("points",`${se(Le,ct)} ${se(Je,Rt)}`),W.append($t)},pe=R.parent?R.parent.box.x0:0,ge=R.parent?R.parent.box.y0:0,Te=R.step??1;for(let Le=Math.ceil((ie.x0-pe)/Te)*Te;pe+Le<=ie.x1+1e-9;Le+=Te)le(pe+Le,ie.y0,pe+Le,ie.y1,Number.isInteger(Le)?"dgrid":"dgrid sub");for(let Le=Math.ceil((ie.y0-ge)/Te)*Te;ge+Le<=ie.y1+1e-9;Le+=Te)le(ie.x0,ge+Le,ie.x1,ge+Le,Number.isInteger(Le)?"dgrid":"dgrid sub");me.append(W);let qe=V.createElementNS(on,"polygon");if(qe.setAttribute("class",`drop${R.invalid?" bad":""}`),qe.setAttribute("points",[[P.x0,P.y0],[P.x1,P.y0],[P.x1,P.y1],[P.x0,P.y1]].map(([Le,ct])=>se(Le,ct)).join(" ")),me.append(qe),R.parent&&R.move){let Le=R.parent.box,ct=R.move.clamped,Je=R.parent.pad,Rt=(Ge,$t,ds,us)=>{let to=V.createElementNS(on,"polyline");to.setAttribute("class","edge"),to.setAttribute("points",`${se(Ge,$t)} ${se(ds,us)}`),me.append(to)};ct.left&&Rt(Le.x0+Je,Le.y0,Le.x0+Je,Le.y1),ct.right&&Rt(Le.x1-Je,Le.y0,Le.x1-Je,Le.y1),ct.top&&Rt(Le.x0,Le.y0+Je,Le.x1,Le.y0+Je),ct.bottom&&Rt(Le.x0,Le.y1-Je,Le.x1,Le.y1-Je)}}async function rt(P){let R=pt();if(!R)return;Ce=void 0,clearTimeout(_t);let V=me?[...me.querySelectorAll(".gridwrap, .drop, .edge")]:[];if(V.length){for(let se of V)se.classList.add("out");matchMedia("(prefers-reduced-motion: reduce)").matches||await new Promise(se=>setTimeout(se,160))}ye="",ne?.classList.remove("dragging","drag-bad"),Q();let W=R.move,oe=W&&(W.at[0]!==R.start[0]||W.at[1]!==R.start[1]);if(P&&W&&oe&&!R.invalid){let se=`Pin ${p(nt(R.ptr))} at [${W.at.join(", ")}]`,ie=R.keep??[];if(!R.shown||R.shown[0]!==W.at[0]||R.shown[1]!==W.at[1])try{ie=Ht(R).keep}catch{}un(e,ie.length?d([[R.name,W.at],...ie],`${se} (${ie.map(([le])=>le).join(", ")} kept in place)`):u(i([x,"layout",R.name],{at:W.at},se)),"canvas",n.note),Pe&&re&&(Pe=!1,ye="",I(re,$e));return}P&&R.invalid&&n.note(`${R.name} can't go there: it would overlap`,"warn"),await Ee(R.origCd),Pe&&re&&(Pe=!1,ye="",I(re,$e))}function fn(P){if(T&&!T.pick){let{x:se,y:ie}=kt(P);et(Ye(document.elementFromPoint(se,ie)));return}let R=Ce;if(Ce=void 0,ne?.classList.remove("panning"),!R)return;let{x:V,y:W}=kt(P);(R.kind==="marquee"&&!R.moved&&!R.add||R.kind==="pan"&&R.emptyClick)&&e.select([],"canvas");let oe=R.kind==="click"?R.ptr:R.kind==="pin"&&!R.moved?R.narrow:void 0;if(oe&&e.select([nt(oe)],"canvas"),R.kind==="pin"&&R.moved){Ce=R,Ot={x:V,y:W,alt:P.altKey},Pt=!1,as(),rt(!0);return}De()}let Mt;function Jt(){let P=new Map;if(!te)return P;for(let[R,V]of te.pathOf){let W=v(V);if(!W||W.path!==V)continue;let oe=te.scene.layout.byId.get(R);if(!oe||ne?.querySelector(`[data-id="${CSS.escape(R)}"].pre`))continue;let se=oe.box,ie=se.z0,le={x0:se.x0-ie,y0:se.y0-ie,x1:se.x1-ie,y1:se.y1-ie},pe=P.get(V);P.set(V,pe?{x0:Math.min(pe.x0,le.x0),y0:Math.min(pe.y0,le.y0),x1:Math.max(pe.x1,le.x1),y1:Math.max(pe.y1,le.y1)}:le)}return P}let H=P=>Math.round(P*2)/2,he=([P,R])=>[H(P),H(R)],ke=(P,R)=>{let[V,W]=ws(1,0),[oe,se]=ws(0,1),ie=V*se-W*oe;return[(P*se-R*oe)/ie,(R*V-P*W)/ie]};function Ae(P){P.preventDefault();let{x:R,y:V}=kt(P),W=Ze();if(P.ctrlKey||P.metaKey){E(Math.exp(-P.deltaY*.01),R,V);return}if(P.shiftKey){Ne.view={...Ne.view,x:Ne.view.x+(P.deltaX||P.deltaY)/W},ot();return}fe.wheel==="zoom"?E(Math.exp(-P.deltaY*.0025),R,V):(Ne.view={...Ne.view,x:Ne.view.x+P.deltaX/W,y:Ne.view.y+P.deltaY/W},ot())}function Fe(P){P.preventDefault();let{x:R,y:V}=kt(P);if(U?.context?.(P,{x:R,y:V}))return;let W=Ye(P.target);W!==void 0&&!e.selection.some(oe=>Me(oe)===W)&&e.select([nt(W)],"canvas"),is(st(W),{x:R,y:V},"Canvas")}function st(P){let R=e.selection,V=[],W=!e.doc.ok;if(P===void 0||!R.length){for(let le of r.newOrder)V.push({label:`New ${M(le).singular}`,icon:"plus",disabled:W,onSelect:()=>Ut(le)});n.clipItems&&V.push({sep:!0},...n.clipItems().filter(le=>"label"in le&&le.label==="Paste")),V.push({sep:!0},{label:"Fit",keys:"0",onSelect:()=>q()},{label:"Fit the whole drawing",onSelect:()=>Y()},{label:"Zoom 100%",keys:"1",onSelect:()=>m()});let ie=!!s.pins.of(e.goodDoc.data);return V.push({label:"Reset layout",icon:"rotate-ccw",desc:"Remove every pin (x-editor.layout)",disabled:W||!ie,why:"Nothing is pinned",onSelect:Js}),V}let oe=R.length===1?R[0]:void 0,se=oe&&v(Me(oe))?.path===Me(oe);if(oe){V.push(...s.objectItems(e,oe,"canvas",n.note)),V.length&&V.push({sep:!0}),V.push({label:"Rename\u2026",icon:"pencil",keys:"F2",disabled:W||!se,why:o.renameWhy,onSelect:()=>h(e,oe,"canvas",n.note)}),V.push({label:"Duplicate",icon:"copy",keys:"\u2318D",disabled:W||!se,why:o.duplicateWhy,onSelect:()=>b(e,oe,"canvas",n.note)});let ie=se?v(Me(oe)).name:"";s.pins.of(e.goodDoc.data)?.[ie]&&V.push({label:"Unpin",icon:"rotate-ccw",desc:"Let the layout place it again",onSelect:()=>un(e,u({...a([x,"layout",ie]),label:`Unpin ${p(oe)}`}),"canvas",n.note)}),V.push({sep:!0}),V.push({label:"Show in text",icon:"code-xml",onSelect:()=>n.showInText(oe)}),V.push({label:"Show in tree",icon:"list-tree",onSelect:()=>n.showInTree(oe)})}return s.connect&&oe&&se&&V.push({label:"Connect to\u2026",icon:"link",desc:"Then click what it connects to (Esc cancels)",disabled:W,onSelect:()=>yn()}),s.group&&V.push({label:R.length>1?`Group ${R.length} items`:"Group",icon:"box",keys:"\u2318G",desc:"Into a new container, as one step",disabled:W||!Qe().length,why:"Only objects are grouped",onSelect:Nt}),V.push({label:"Select parent",icon:"arrow-up-right",keys:"\u2318\u2191",onSelect:eo}),V.push({label:"Select connected",icon:"link",desc:"What refers to it, and what it refers to",onSelect:()=>e.select(k(e,R),"canvas")}),V.push({label:"Zoom to selection",keys:"\u21E72",onSelect:L}),n.clipItems&&V.push({sep:!0},...n.clipItems()),V.push({sep:!0},{label:R.length>1?`Delete ${R.length} items`:"Delete",icon:"trash-2",keys:"\u232B",danger:!0,disabled:W,onSelect:()=>g(e,R,"canvas",n.note)}),V}function bt(){if(!s.connect||!e.doc.ok||e.selection.length!==1)return;let P=Me(e.selection[0]),R=v(P);return R&&R.path===P?R:void 0}function yn(){let P=bt();P&&(T={from:P,pick:!0},n.note(`Click what ${P.name} connects to (Esc cancels)`),De())}function et(P){let R=T?.from;if(T=void 0,De(),!R||P===void 0)return;let V=v(P);if(!V||V.path===R.path){n.note("Not connected: drop it on another object","warn");return}let W=e.goodDoc.data,oe=s.connect?.(R,V,W);if(!oe){n.note(`${R.name} and ${V.name} can't be connected`,"warn");return}let se=oe.label??`Connect ${R.name} to ${V.name}`,ie,le;if(oe.name!==void 0){let pe=f(e.text,oe.name);ie=l(oe.at,pe,oe.value,{label:se}),le=[...oe.at,pe]}else{let pe=oe.at.reduce((ge,Te)=>ge&&typeof ge=="object"?ge[Te]:void 0,W);le=[...oe.at,Array.isArray(pe)?pe.length:0],ie=c(oe.at,oe.value,void 0,se)}un(e,{...ie,select:[le]},"canvas",n.note)&&e.select([le],"canvas")}function Qe(){let P=new Map;for(let R of e.selection){let V=v(Me(R));V&&P.set(V.path,V)}return[...P.values()]}function Nt(){if(!s.group||!e.doc.ok)return;let P=Qe();if(!P.length){n.note("Only objects are grouped","warn");return}let R=s.group(P,e.goodDoc.data);if(!R){n.note(P.length>1?`These ${P.length} can't be grouped`:`${P[0].name} can't be grouped`,"warn");return}let V=f(e.text,R.name),W=s.pins.of(e.goodDoc.data)??{},oe=P.filter(pe=>W[pe.name]!==void 0).map(pe=>u(a([x,"layout",pe.name]))),se=R.label??`Group ${P.length>1?`${P.length} items`:P[0].name} into ${V}`,ie=[...R.at,V],le=qo(se,[l(R.at,V,R.value,{label:se}),...R.members(V).map(pe=>i(pe.path,pe.value)),...oe]);un(e,{...le,select:[ie]},"canvas",n.note)&&e.select([ie],"canvas")}function Ut(P){let R=M(P),V=f(e.text,R.singular),W=[...R.section,V];un(e,l(W.slice(0,-1),V,R.template(),{label:`Add ${R.singular} ${V}`}),"canvas",n.note)&&(e.select([W],"canvas"),h(e,W,"canvas",n.note))}function an(P,R,V){if(!te||!ne)return;let W=R.build(e.text).steps.reduce((us,to)=>dn(us,to),e.text),oe;try{oe=s.trial(W,n.theme)}catch{return}if(!oe)return;let se=oe.pinId.get(P),ie=se?oe.scene.layout.byId.get(se):void 0,le=se?Rr(oe.scene,se):void 0;if(!ie||!le)return;let pe=ie.box,ge=ie.parent,Te=(pe.x0+pe.x1)/2,qe=(pe.y0+pe.y1)/2,Le=[(Te-qe)*It*xt,(Te+qe)*.5*xt-pe.z0*xt],ct=at(V.x,V.y),Je=Fo(le,ws(ct.x-Le[0],ct.y-Le[1]),1,[pe.x1-pe.x0,pe.y1-pe.y0],ge?{w:ge.box.x1-ge.box.x0,d:ge.box.y1-ge.box.y0,pad:Do(s.catalog,ge.region)}:void 0),Rt=Je.at[0]-le[0],Ge=Je.at[1]-le[1],$t={x0:pe.x0+Rt,y0:pe.y0+Ge,x1:pe.x1+Rt,y1:pe.y1+Ge},ds=(ge?ge.children:oe.scene.layout.items.filter(us=>!us.parent)).filter(us=>us!==ie).map(us=>us.box);return rr($t,ds)?void 0:Je.at}function br(P,R){if(!te)return;let V=at(R.x,R.y);if(F){for(let oe of F.panelsAt(V.x,V.y)){let se=[...te.pinId].find(([,ie])=>ie===oe)?.[0];if(se&&v(te.pathOf.get(oe)??"")?.kind===P)return se}return}let W=oe=>{let se=!1;for(let ie=0,le=oe.length-1;ie<oe.length;le=ie++){let[pe,ge]=oe[ie],[Te,qe]=oe[le];ge>V.y!=qe>V.y&&V.x<(Te-pe)*(V.y-ge)/(qe-ge)+pe&&(se=!se)}return se};for(let[oe,se]of te.pinId){if(v(te.pathOf.get(se)??"")?.kind!==P)continue;let ie=te.scene.layout.byId.get(se);if(ie&&W(Ir(ie.box)))return oe}}function Xo(P){if(!te)return[];let R=at(P.x,P.y),V=le=>{let pe=te.pathOf.get(le),ge=pe===void 0?void 0:v(pe);return ge&&ge.path===pe?ge:void 0};if(F)return F.panelsAt(R.x,R.y).map(V).filter(le=>!!le);let W=le=>{let pe=!1;for(let ge=0,Te=le.length-1;ge<le.length;Te=ge++){let[qe,Le]=le[ge],[ct,Je]=le[Te];Le>R.y!=Je>R.y&&R.x<(ct-qe)*(R.y-Le)/(Je-Le)+qe&&(pe=!pe)}return pe},oe=le=>{let pe=0;for(let ge=le.parent;ge;ge=ge.parent)pe++;return pe},se=new Map;for(let le of Re().elementsFromPoint(P.x,P.y))if(ne?.contains(le))for(let pe=le.closest("[data-id]");pe;pe=pe.parentElement?.closest("[data-id]")??null){let ge=V(pe.getAttribute("data-id")??"");ge&&!se.has(ge.path)&&se.set(ge.path,ge)}let ie=[];for(let[,le]of te.pinId){let pe=te.scene.layout.byId.get(le),ge=V(le);pe&&ge&&!se.has(ge.path)&&W(Ir(pe.box))&&ie.push({r:ge,d:oe(pe),a:(pe.box.x1-pe.box.x0)*(pe.box.y1-pe.box.y0)})}return[...se.values(),...ie.sort((le,pe)=>pe.d-le.d||le.a-pe.a).map(le=>le.r)]}function Ws(P,R,V){if(!e.doc.ok){n.note("Fix the YAML first","warn");return}let W=M(P),oe=V?.value?.(),se=V&&oe!==void 0?V.label.toLowerCase():W.singular,ie=f(e.text,V?.name??W.singular),le=[...W.section,ie],pe=oe??W.template(),ge,Te=R?s.dropInto?.(P):void 0;if(R&&Te){let Ge=br(Te.container,R);Ge&&(ge=Ge,pe={...Te.value(Ge),...oe??{}})}let qe=ge?Te.label(ge):"";if(R&&!ge&&s.dropOnto)for(let Ge of Xo(R)){let $t=s.dropOnto(Ge,pe,P,e.goodDoc.data);if($t){ge=Ge.name,pe=$t.value,qe=$t.label?` ${$t.label}`:` in ${Ge.name}`;break}}let Le=`Add ${se} ${ie}${qe}`,ct=l(le.slice(0,-1),ie,pe,{label:Le}),Je=R&&!ge&&N==="3d"?an(ie,ct,R):void 0,Rt=Je?qo(`${Le} at [${Je.join(", ")}]`,[ct,u(i([x,"layout",ie],{at:Je}))]):ct;if(un(e,{...Rt,select:[le]},"canvas",n.note))return R&&!ge&&!Je&&n.note(N==="2d"?`${W.singular} ${ie} added; the layout placed it (in 3D a drop pins it where it lands)`:`${W.singular} ${ie} added; that spot is taken, so the layout placed it`),e.select([le],"canvas"),y.focus({preventScroll:!0}),h(e,le,"canvas",n.note),le}let cs=z("div",{class:"palette",role:"toolbar","aria-label":o.palette,"aria-orientation":"vertical"});r.palette.forEach((P,R)=>{let{kind:V,icon:W,label:oe}=P,se=z("button",{type:"button",class:"pal-item","data-section":V,"data-entry":String(R),title:`Add ${oe.toLowerCase()} (click), or drag it where it goes`},Wt(W),z("span",{class:"pal-label"},oe));se.addEventListener("pointerdown",ie=>{if(ie.button!==0)return;ie.preventDefault();try{se.setPointerCapture(ie.pointerId)}catch{}let le=ie.clientX,pe=ie.clientY,ge,Te=Ge=>{let $t=y.getBoundingClientRect();return Ge.clientX>=$t.left&&Ge.clientX<=$t.right&&Ge.clientY>=$t.top&&Ge.clientY<=$t.bottom&&!cs.contains(document.elementFromPoint(Ge.clientX,Ge.clientY))},qe=Ge=>{if(!ge&&Math.hypot(Ge.clientX-le,Ge.clientY-pe)<4)return;ge||(ge=z("div",{class:"pal-ghost","aria-hidden":"true"},Wt(W),oe),t.append(ge));let $t=t.getBoundingClientRect();ge.style.left=`${Ge.clientX-$t.left+8}px`,ge.style.top=`${Ge.clientY-$t.top+8}px`,ge.classList.toggle("bad",!Te(Ge))},Le=(Ge,$t)=>{se.removeEventListener("pointermove",qe),se.removeEventListener("pointerup",ct),se.removeEventListener("pointercancel",Je),removeEventListener("keydown",Rt,!0);let ds=!!ge;ge?.remove(),$t&&(ds?Te(Ge)&&Ws(V,{x:Ge.clientX,y:Ge.clientY},P):Ws(V,void 0,P))},ct=Ge=>Le(Ge,!0),Je=Ge=>Le(Ge,!1),Rt=Ge=>{Ge.key==="Escape"&&(Ge.stopPropagation(),Ge.preventDefault(),Le(ie,!1))};se.addEventListener("pointermove",qe),se.addEventListener("pointerup",ct),se.addEventListener("pointercancel",Je),addEventListener("keydown",Rt,!0)}),se.addEventListener("keydown",ie=>{(ie.key==="Enter"||ie.key===" ")&&(ie.preventDefault(),Ws(V,void 0,P))}),cs.append(se)}),t.append(cs);function Js(){let P=s.pins.keyOf(e.goodDoc.data),R=e.goodDoc.data?.[P],V=R&&Object.keys(R).length===1;un(e,{...a(V?[P]:[P,"layout"]),label:"Reset the layout"},"canvas",n.note)}function eo(){let P=new Map;for(let R of e.selection){let V=v(Me(R)),W=V&&V.path!==Me(R)?nt(V.path):V?M(V.kind).section:[];P.set(Me(W),W)}e.select([...P.values()],"canvas")}function ve(P){if(P.type==="keyup"&&P.key!==" ")return;if(P.key===" "){vt=P.type==="keydown",ne?.classList.toggle(r.panKeyClass,vt),P.preventDefault();return}let R=U?.key?.(P);if(R==="ignore")return;if(R==="handled"){P.preventDefault(),P.stopPropagation();return}let V=P.metaKey||P.ctrlKey,W=e.selection,oe=[...new Set([...te?.pathOf.values()??[]].filter(ie=>v(ie)?.path===ie))],se=!e.doc.ok;switch(P.key){case"+":case"=":E(1.25);break;case"-":case"_":E(.8);break;case"0":q();break;case"1":m();break;case"@":case"2":if(P.shiftKey||P.key==="@")L();else return;break;case"Escape":if(T){T=void 0,De(),n.note("Not connected");break}if(pt()){rt(!1);break}e.select([],"canvas");break;case"Delete":case"Backspace":W.length&&!se&&g(e,W,"canvas",n.note);break;case"F2":W.length===1&&!se&&h(e,W[0],"canvas",n.note);break;case"ArrowUp":if(V){eo();break}return;case"Tab":case"ArrowRight":case"ArrowLeft":case"ArrowDown":{if(!oe.length)return;let ie=W.length?oe.indexOf(Me(W[0])):-1,le=P.key==="ArrowLeft"||P.key==="Tab"&&P.shiftKey,pe=ie<0?0:(ie+(le?-1:1)+oe.length)%oe.length;e.select([nt(oe[pe])],"canvas"),dt(nt(oe[pe]));break}case"ContextMenu":case"F10":if(P.key==="F10"&&!P.shiftKey)return;{let ie=Ke(W),le=t.getBoundingClientRect(),pe=Ze();is(st(W.length?Me(W[0]):void 0),ie?{x:le.left+(ie.x+ie.w-Ne.view.x)*pe,y:le.top+(ie.y-Ne.view.y)*pe}:{x:le.left+40,y:le.top+40},"Canvas")}break;default:if(V&&P.key.toLowerCase()==="d"&&W.length===1&&!se){b(e,W[0],"canvas",n.note);break}if(V&&P.key.toLowerCase()==="a"){e.select(oe.map(nt),"canvas");break}if(V&&P.key.toLowerCase()==="g"&&s.group&&W.length&&!se){Nt();break}return}P.preventDefault(),P.stopPropagation()}y.addEventListener("keydown",ve),y.addEventListener("keyup",ve);let je=P=>t.classList.toggle("has-focus",P);y.addEventListener("focus",()=>je(!0)),y.addEventListener("blur",()=>je(!1)),Q();function dt(P){let R=ue(P);!R||!Ne.view||(R.x<Ne.view.x||R.y<Ne.view.y||R.x+R.w>Ne.view.x+Ne.view.w||R.y+R.h>Ne.view.y+Ne.view.h)&&(Ne.view={...Ne.view,x:R.x+R.w/2-Ne.view.w/2,y:R.y+R.h/2-Ne.view.h/2},ot())}function yt(P){if(!Ne.view||!P.length)return!0;let R=P.map(ue);if(R.some(oe=>!oe))return!1;let V=Se(R),W=24/Ze();return V.x-W>=Ne.view.x&&V.y-W>=Ne.view.y&&V.x+V.w+W<=Ne.view.x+Ne.view.w&&V.y+V.h+W<=Ne.view.y+Ne.view.h?!0:V.w+2*W>Ne.view.w||V.h+2*W>Ne.view.h?(Y({x:V.x-W,y:V.y-W,w:V.w+2*W,h:V.h+2*W}),!0):(Ne.view={...Ne.view,x:V.x+V.w/2-Ne.view.w/2,y:V.y+V.h/2-Ne.view.h/2},ot(),!0)}let ut;Mn(),e.onSelect(P=>{De(),!(P.origin==="canvas"||!P.paths.length)&&(ut=yt(P.paths)?void 0:P.paths)});let Tt={addFromPalette:Ws,palette:cs,groupSelection:Nt,startPick:yn,objectsUnder:Xo,get linking(){return T},render:I,setTheme:it,paintOverlay:De,fit:q,fitAll:Y,actual:m,zoomAt:E,itemsBox:We,get moved(){return Ne.moved},settled:O,get zoom(){return Ne.zoom},dispose(){ze(),clearTimeout(_t),Ne.dispose(),Ue=!0},focus:()=>y.focus(),get view(){return Ne.view},get doc(){return te},get mode(){return N},setMode:B,get flat(){return F?.layout},stage:y,key:ve,scale:()=>Ze(),nav:fe,paintNav:Q,outlinesFor:Ie,footprints:Jt,get drag(){return pt()},get lastMarquee(){return Mt},boxFor:ue,pageXYOf:P=>{let R=ue(P),V=t.getBoundingClientRect(),W=Ze();return R&&Ne.view?{x:V.left+(R.x+R.w/2-Ne.view.x)*W,y:V.top+(R.y+R.h/2-Ne.view.y)*W}:void 0}};return U&&Object.defineProperties(Tt,Object.getOwnPropertyDescriptors(U.api)),Tt}var Sf={draw(t,e,n){let s=zr(e),r;try{r=Fs(or(t),s,n.options)}finally{s.dispose()}let o=r.bounds,i=l=>r.cards.find(c=>c.id===l)?.rect??r.panels.find(c=>c.id===l)?.rect;return{svg:_r(r,{id:"canvas-2d",title:n.title,styles:n.styles}),full:[o.l,o.t,o.r-o.l,o.b-o.t],layout:r,outlines(l,c){let d=[];for(let u of l){let f=i(u);if(f){d.push({kind:"poly",id:u,points:[[f.l,f.t],[f.r,f.t],[f.r,f.b],[f.l,f.b]]});continue}let p=c.querySelector(`path.conn[data-id="${CSS.escape(u)}"]`)?.getAttribute("d");p&&d.push({kind:"route",d:p})}return d},hits(l,c){return[...r.cards,...r.panels].filter(d=>{let u=d.rect;return c?u.l<l.r&&u.r>l.l&&u.t<l.b&&u.b>l.t:u.l>=l.l&&u.t>=l.t&&u.r<=l.r&&u.b<=l.b}).map(d=>d.id)},panelsAt(l,c){return[...r.panels].sort((d,u)=>u.depth-d.depth).filter(d=>l>=d.rect.l&&l<=d.rect.r&&c>=d.rect.t&&c<=d.rect.b).map(d=>d.id)}}},morph(t,e,n,s,r){let o=n.mode==="3d"?n.svg:s;return Vr(o,e,or(e)),ja(t,n.svg,s,n.mode,r)}};var wm=t=>`
|
|
470
|
+
`)[0].replace(/`/g,"")));let N=$l(e.goodDoc.data,k);if(o.kinds.some(ee=>Se(ee.section)===Se(k))){let ee=Tr(N)?Object.keys(N).length:0;t.append(K("p",null,`${ee} ${ee===1?"entry":"entries"}. Add one from the tree's +, or the canvas's menu.`));return}let J=k.length?Tr(N)?k:k.slice(0,-1):[],oe=$l(e.goodDoc.data,J);if(!Tr(oe)&&J.length)return;let ve=new Set(o.kinds.map(ee=>String(ee.section[0]))),B=$.keys(J,oe??{}).filter(ee=>!ve.has(ee.name)||J.length),W=K("div",{class:"props"});for(let ee of B)W.append(y([J],"",ee,[oe??{}],void 0));if(t.append(W),k.length&&Se(k)!==Se(J)){let ee=W.querySelector(`[data-path="${CSS.escape(Se(k))}"]`);ee?.classList.add("focus-row"),ee?.scrollIntoView({block:"nearest"})}}t.addEventListener("focusout",()=>setTimeout(()=>{t.contains(document.activeElement)||w()},0)),e.onSelect(()=>w());let j=ir(()=>w());return e.on(k=>{or(k)?j():j.now()}),{paint:w,dispose:()=>j.cancel()}}var pn="http://www.w3.org/2000/svg";function Tl(t,e,n){let s=n.kit,r=s.ui,o=r.text,{setCmd:i,deleteCmd:a,insertCmd:l,insertItemCmd:c,pinsCmd:d,withPinsMoved:u,freshName:f,describe:p}=s.commands,{deletePaths:g,renameDialog:h,duplicate:b,connected:v}=s.actions,w=E=>s.objectOf(E),M=E=>s.kinds.find(L=>L.kind===E),y=s.pins.key,T;t.classList.add("canvas");let S=K("div",{class:`${r.rootClass} canvas-stage`,tabindex:"0",role:"application","aria-label":o.stage}),P=K("div",{class:"canvas-tools",role:"toolbar","aria-label":"Canvas"}),I=K("button",{type:"button",class:"btn sm quiet icon-only","aria-label":"Zoom out (\u2212)",title:"Zoom out (\u2212)"},"\u2212"),_=K("button",{type:"button",class:"btn sm quiet zoom-label",title:"Fit (0) \xB7 100% (1)"},"100%"),O=K("button",{type:"button",class:"btn sm quiet icon-only","aria-label":"Zoom in (+)",title:"Zoom in (+)"},"+"),j=K("button",{type:"button",class:"btn sm quiet",title:"Fit (0)"},"Fit"),k=(E,L,V)=>{let U=K("div",{class:"segmented",role:"group","aria-label":E,title:E});for(let[re,le,ce]of V){let me=K("button",{type:"button",class:"seg","data-v":re,title:ce},le);me.addEventListener("click",()=>{ue[L]=re,X(),Q()}),U.append(me)}return U},$=k("The wheel","wheel",[["zoom","Zoom","The wheel zooms around the pointer; \u21E7-wheel pans sideways"],["scroll","Scroll","The wheel pans; \u21E7-wheel pans sideways; a pinch zooms"]]),x=k(o.dragGroup,"drag",[["pan","Pan","Drag pans; \u21E7- or \u2318-drag draws a selection"],["select","Select",o.dragSelectTip]]),N="3d",F,J,oe=async()=>J??=await s.flat.load(),ve=K("div",{class:"segmented view-seg",role:"group","aria-label":"The view"});for(let[E,L,V]of[["3d","3D","3D: the drawing; drag a selected thing to move it"],["2d","2D","2D: select, rename, delete, add from the palette and edit here; moving is in 3D"]]){let U=K("button",{type:"button",class:"seg","data-v":E,title:V},L);U.addEventListener("click",()=>z(E)),ve.append(U)}let B={host:t,doc:e,cd:()=>te,svg:()=>ne,elementsFor:E=>$e(E),boxOf:E=>de(E),union:E=>De(E),outlinesFor:E=>nt(E),scale:()=>et(),full:()=>Ae.full,toSvg:(E,L)=>Y(E,L),autoFit:()=>C(),paint:()=>st(),reveal:E=>kd(E),note:(E,L)=>n.note(E,L)},W=n.layer?.(B);P.append(...W?.tools??[],...s.flat?[ve]:[],$,x,I,_,O,j);let ee=K("div",{class:"canvas-empty",hidden:!0});t.append(S,P,ee,...W?.marks??[]);let ue={wheel:"zoom",drag:"pan"};try{Object.assign(ue,JSON.parse(n.store?.get("canvas-nav")??"{}"))}catch{}s.flat&&n.store?.get("canvas-view")==="2d"&&(N="2d");function z(E){if(!s.flat||E===N)return;Ke();let L=N;N=E,n.store?.set("canvas-view",E),Q(),ne&&te&&ne.parentNode===S&&(ge={svg:ne,mode:L}),se!==void 0&&(Ae.view=void 0,be="",D(se,Me))}let X=()=>n.store?.set("canvas-nav",JSON.stringify(ue));function Q(){for(let[E,L]of[[$,ue.wheel],[x,ue.drag],[ve,N]])for(let V of E.querySelectorAll(".seg"))V.setAttribute("aria-pressed",String(V.dataset.v===L));if(ne?.classList.toggle("mode-pan",ue.drag==="pan"),ne?.classList.toggle("mode-select",ue.drag==="select"),Ye?.kind==="pin"&&Ye.moved){ne?.classList.add("dragging"),ne?.classList.toggle("drag-bad",!!Ye.invalid);return}n.onHint?.(`${ue.drag==="pan"?"Drag: pan \xB7 \u21E7-drag: select":"Drag: select \xB7 space-drag: pan"} \xB7 Wheel: ${ue.wheel==="zoom"?"zoom":"scroll"}`)}let te,ne,fe,be="",we,Ne=()=>document,qe=!1;async function D(E,L){if(qe)return;if(!E){je(o.unreadable);return}let V=JSON.stringify(L);if(V===be&&ne){Ct()||st();return}if(N==="2d"&&!J)try{await oe()}catch(re){N="3d",Q(),n.note(`The 2D view couldn't load: ${re.message}`,"warn")}let U;try{U=s.draw(E,L,n.theme)}catch(re){je(`The canvas couldn't draw this: ${re.message}`);return}if(U.diags.length){je(`The canvas couldn't draw this: ${U.diags[0]}`);return}if(be=V,se=E,Me=L,Ct()){Oe=!0;return}await Ee(U),te.pinNotes.length&&n.note(`Pins: ${te.pinNotes.join("; ")}`,"warn")}let se,Me,Oe=!1,ge,ie;function Ke(){if(!ie)return;let E=ie;ie=void 0,E.m.finish(),E.from.remove(),E.to.style.visibility=""}function Ce(E,L){let V=J?.morph?.(S,te.scene,E,L,{motion:s.flat?.motion,duration:s.flat?.duration});if(!V){E.svg.remove();return}E.svg.style.visibility="hidden",L.style.visibility="hidden";let U={m:V,from:E.svg,to:L};ie=U,S.classList.add("morphing"),V.done.then(()=>{ie===U&&Ke(),S.classList.remove("morphing")})}async function Ee(E){Ke();let L,V=E.scene.rendered.viewBox;try{if(N==="2d"&&J){F=J.draw(E.scene,S,{styles:s.flat?.styles,title:s.flat?.title,options:s.flat?.options}),V=F.full,L=Bo(F.svg);for(let he of L.querySelectorAll("[tabindex]"))he.removeAttribute("tabindex"),he.removeAttribute("role")}else F=void 0,L=Bo(E.svg)}catch(he){je(`The canvas couldn't draw this: ${he.message}`);return}te=E,L.classList.add("scene"),L.removeAttribute("width"),L.removeAttribute("height"),L.setAttribute("preserveAspectRatio","xMidYMid meet"),L.setAttribute("aria-hidden","true"),fe=document.createElementNS(pn,"g"),fe.setAttribute("class","overlay"),fe.setAttribute("fill","none"),fe.setAttribute("stroke","currentColor"),fe.setAttribute("pointer-events","none"),L.append(fe,...W?.groups?.()??[]);let U=ge;ge=void 0,U&&ne===U.svg&&ne.parentNode===S?(U.svg.querySelector(".overlay")?.replaceChildren(),U.svg.style.position="absolute",U.svg.style.inset="0",S.append(L)):ne?.parentNode===S?ne.replaceWith(L):S.append(L),ne=L;let[re,le,ce,me]=V;Ae.full={x:re,y:le,w:ce,h:me},Ae.view?bt(A):(Ae.view={...Ae.full},C()),ee.hidden=!0,W?.drawn?.(),mi&&Sd(mi)&&(mi=void 0),Q(),st(),U&&U.svg!==L&&(getComputedStyle(S).position==="static"&&(S.style.position="relative"),Ce(U,L))}function je(E){ge=void 0,ee.textContent=E,ee.hidden=!1}function lt(E){st()}function Ue(){if(!te||!ne)return;let E=[...new Set([...te.pathOf.values()].filter(V=>{let U=w(V);return U&&U.path===V}))],L=W?.extent?.()??[];return De([...E.flatMap(V=>$e(V)).filter(V=>V.getBBox().width||V.getBBox().height).map(de),...L])}let dt=r.paletteLayout==="docked",ut=dt?S:t,Ae=ja(ut,{svg:()=>ne,onApply:E=>{ne.classList.toggle("zoom-near",E>=1);let L=Math.round(E*100);_.textContent=`${L}%`,n.onZoom(L)},onRezoom:()=>st(),itemsBox:()=>Ue(),marksShowing:()=>!!W?.showing?.()}),{size:pt,scale:et,quietly:bt,applyView:A,toSvg:Y,zoomAt:q,fit:ae,fitItems:m,autoFit:C,actual:R,settled:G}=Ae;function Z(){let E=Re(e.selection);E&&ae({x:E.x-20,y:E.y-20,w:E.w+40,h:E.h+40})}O.addEventListener("click",()=>q(1.25)),I.addEventListener("click",()=>q(.8)),_.addEventListener("click",()=>m()),j.addEventListener("click",()=>m());let $e=E=>!ne||!te?[]:[...te.pathOf.entries()].filter(([,V])=>V===E||E&&V.startsWith(E+"/")&&!1).map(([V])=>V).flatMap(V=>[...ne.querySelectorAll(`[data-id="${CSS.escape(V)}"]`)]).filter(V=>!V.closest(".pre")&&!V.classList.contains("pre")),de=E=>{let L=E.getBBox(),V=E.getCTM(),U=ne.getCTM();if(!V||!U)return{x:L.x,y:L.y,w:L.width,h:L.height};let re=U.inverse().multiply(V),le=[[L.x,L.y],[L.x+L.width,L.y],[L.x,L.y+L.height],[L.x+L.width,L.y+L.height]].map(([he,ye])=>({x:re.a*he+re.c*ye+re.e,y:re.b*he+re.d*ye+re.f})),ce=le.map(he=>he.x),me=le.map(he=>he.y);return{x:Math.min(...ce),y:Math.min(...me),w:Math.max(...ce)-Math.min(...ce),h:Math.max(...me)-Math.min(...me)}},De=E=>{if(!E.length)return;let L=Math.min(...E.map(le=>le.x)),V=Math.min(...E.map(le=>le.y)),U=Math.max(...E.map(le=>le.x+le.w)),re=Math.max(...E.map(le=>le.y+le.h));return{x:L,y:V,w:U-L,h:re-V}},He=E=>{let L=Se(E),V=$e(L),U=w(L);return!V.length&&U&&U.path!==L&&(V=$e(U.path)),V.length?De(V.filter(re=>re.getBBox().width||re.getBBox().height).map(de)):void 0},Re=E=>De(E.map(He).filter(L=>!!L)),ze=E=>{let L=E?.closest?.("[data-id]");if(!L||!te)return;let V=L;for(;V;){let U=V.getAttribute("data-id");if(U&&te.pathOf.has(U))return te.pathOf.get(U);V=V.parentElement?.closest("[data-id]")??null}};function nt(E){if(!te)return[];let L=[],V=new Set([...te.pathOf].filter(([,U])=>U===E).map(([U])=>U));if(F&&ne)return F.outlines(V,ne);for(let[U,re]of te.pathOf){if(re!==E)continue;let le=te.scene.layout.byId.get(U),ce=le?.parent;for(;ce&&!V.has(ce.id);)ce=ce.parent;if(!ce)if(le){if(ne?.querySelector(`[data-id="${CSS.escape(U)}"].pre`))continue;let me=Dt(s.catalog,le.region?.kind)?.shape,he=le.type==="node"||me==="slab"||me==="block";L.push({kind:"poly",id:U,points:he?Da(le.box):Yr(le.box)})}else te.scene.rendered.paths[U]&&!ne?.querySelector(`[data-id="${CSS.escape(U)}"].pre`)&&L.push({kind:"route",d:te.scene.rendered.paths[U]})}return L}function st(){if(Ae.painted(Ae.view?et():0),!fe||!ne)return;let E=Ne();fe.replaceChildren();let L=(me,he,ye=4)=>{let Pe=E.createElementNS(pn,"rect");Pe.setAttribute("class",he),Pe.setAttribute("x",String(me.x-ye)),Pe.setAttribute("y",String(me.y-ye)),Pe.setAttribute("width",String(me.w+ye*2)),Pe.setAttribute("height",String(me.h+ye*2)),Pe.setAttribute("rx","6"),fe.append(Pe)},V=(me,he)=>{let ye=w(me),Pe=nt(me);if(!Pe.length&&ye&&ye.path!==me&&(Pe=nt(ye.path)),!Pe.length){let Ze=He(rt(me));Ze&&L(Ze,he,he==="hover"?3:4);return}for(let Ze of Pe)if(Ze.kind==="route"){let Le=E.createElementNS(pn,"path");Le.setAttribute("class",he==="ring"?"route-ring":"route-hover"),Le.setAttribute("d",Ze.d),fe.append(Le)}else{let Le=E.createElementNS(pn,"polygon");Le.setAttribute("class",he),Le.setAttribute("points",Ze.points.map(([ft,We])=>`${ft.toFixed(1)},${We.toFixed(1)}`).join(" ")),Le.setAttribute("data-for",Ze.id),fe.append(Le)}};we!==void 0&&!e.selection.some(me=>Se(me)===we)&&V(we,"hover");for(let me of e.selection)V(Se(me),"ring");let U=Xe(),re=T?.from??U,le=re?He(rt(re.path)):void 0;if(le&&s.connect){let me=et(),he=le.x+le.w+10/me,ye=le.y+le.h/2;if(T&&T.x!==void 0&&T.y!==void 0){T.over&&V(T.over,"hover");let Pe=E.createElementNS(pn,"line");Pe.setAttribute("class",`connect-line${T.over?" ok":""}`),Pe.setAttribute("x1",String(he)),Pe.setAttribute("y1",String(ye)),Pe.setAttribute("x2",String(T.x)),Pe.setAttribute("y2",String(T.y)),fe.append(Pe)}if(!T){let Pe=E.createElementNS(pn,"circle");Pe.setAttribute("class","connect-handle"),Pe.setAttribute("cx",String(he)),Pe.setAttribute("cy",String(ye)),Pe.setAttribute("r",String(7/me)),Pe.style.pointerEvents="all",Pe.style.cursor="crosshair";let Ze=E.createElementNS(pn,"title");Ze.textContent=`Drag to what ${re.name} connects to`,Pe.append(Ze),fe.append(Pe)}}let ce=new Map;for(let me of n.problems()){if(me.file)continue;let he=w(me.path);if(!he)continue;let ye=ce.get(he.path)??{e:0,w:0};me.severity==="error"?ye.e++:ye.w++,ce.set(he.path,ye)}for(let[me,he]of ce){let ye=$e(me).filter(vs=>te.scene.layout.byId.has(vs.getAttribute("data-id")??"")),Pe=De(ye.map(de));if(!Pe)continue;let Ze=E.createElementNS(pn,"g");Ze.setAttribute("class",`badge${he.e?"":" warn"}`);let Le=et(),ft=Pe.x+Pe.w,We=Pe.y,jt=9/Le,Ve=E.createElementNS(pn,"circle");Ve.setAttribute("cx",String(ft)),Ve.setAttribute("cy",String(We)),Ve.setAttribute("r",String(jt));let At=E.createElementNS(pn,"text");At.setAttribute("x",String(ft)),At.setAttribute("y",String(We)),At.style.fontSize=`${(11/Le).toFixed(2)}px`,At.textContent=String(he.e||he.w),Ze.append(Ve,At),fe.append(Ze)}W?.paint?.(E)}let Ye,Pt=!1,Et=()=>{S.addEventListener("pointerdown",Xt),S.addEventListener("pointermove",Ht),S.addEventListener("pointerup",tn),S.addEventListener("pointercancel",tn),S.addEventListener("wheel",ot,{passive:!1}),S.addEventListener("contextmenu",kt),S.addEventListener("dblclick",E=>{let L=ze(E.target);L!==void 0&&n.showInText(rt(L))})},yt=E=>({x:E.clientX,y:E.clientY}),wn=E=>{try{S.setPointerCapture(E.pointerId)}catch{}};function Xt(E){if(S.focus({preventScroll:!0}),W?.down?.(E))return;let{x:L,y:V}=yt(E);if(E.button===0&&T?.pick){E.preventDefault(),Ft(ze(E.target));return}if(E.button===0&&E.target?.closest?.(".connect-handle")){let Ze=Xe();if(Ze){wn(E),E.preventDefault();let Le=Y(L,V);T={from:Ze,x:Le.x,y:Le.y},st();return}}(E.button===0||E.button===1)&&wn(E);let U=()=>{Ye={kind:"pan",x0:L,y0:V,v0:{...Ae.view}},ne?.classList.add("panning"),E.preventDefault()};if(E.button===1||Pt){U();return}if(E.button!==0)return;let re=ze(E.target);if(re===void 0){let Ze=E.shiftKey||E.metaKey||E.ctrlKey;if(ue.drag==="pan"&&!Ze){Ye={kind:"pan",x0:L,y0:V,v0:{...Ae.view},emptyClick:!0},ne?.classList.add("panning");return}let Le=ue.drag==="select"&&Ze;Ye={kind:"marquee",x0:L,y0:V,sel0:Le?e.selection:[],add:Le,touch:E.altKey};return}let le=rt(re),ce=e.selection.map(Se);if(E.shiftKey||E.metaKey||E.ctrlKey){e.select(ce.includes(re)?e.selection.filter(Ze=>Se(Ze)!==re):[...e.selection,le],"canvas");return}ce.includes(re)||e.select([le],"canvas");let me=ce.includes(re)&&ce.length>1?re:void 0;Ye={kind:"click",x0:L,y0:V,ptr:me};let he=w(re),ye=he&&he.path===re?he.name:void 0,Pe=ye&&N==="3d"?te?.pinId.get(ye):void 0;if(Pe&&te){let Ze=te.scene.layout.byId.get(Pe),Le=Hr(te.scene,Pe);if(Ze&&Le){let ft=Ze.box,We=Ze.parent,jt=(We?We.children:te.scene.layout.items.filter(Ve=>!Ve.parent)).filter(Ve=>Ve!==Ze).map(Ve=>({x0:Ve.box.x0,y0:Ve.box.y0,x1:Ve.box.x1,y1:Ve.box.y1}));Ye={kind:"pin",x0:L,y0:V,name:ye,id:Pe,ptr:re,narrow:me,start:Le,shown:Le,z0:ft.z0,size:[ft.x1-ft.x0,ft.y1-ft.y0],siblings:jt,parent:We?{w:We.box.x1-We.box.x0,d:We.box.y1-We.box.y0,pad:Uo(s.catalog,We.region),box:We.box,label:We.region?.label??We.id}:void 0,origCd:te}}}}function Ht(E){let{x:L,y:V}=yt(E);if(T){let re=Y(L,V),le=ze(document.elementFromPoint(L,V)),ce=le===void 0?void 0:w(le);T={...T,x:re.x,y:re.y,over:ce&&ce.path!==T.from.path?ce.path:void 0},st();return}if(!Ye){let re=ze(E.target);re!==we&&(we=re,st());return}let U=et();if(Ye.kind==="click"&&N==="2d"&&!Ye.moved&&Math.hypot(L-Ye.x0,V-Ye.y0)>4){Ye.moved=!0,n.onHint?.("Moving is in 3D: switch to 3D to drag it where it goes");return}if(Ye.kind==="pan")Math.hypot(L-Ye.x0,V-Ye.y0)>3&&(Ye.emptyClick=!1),Ae.view={...Ye.v0,x:Ye.v0.x-(L-Ye.x0)/U,y:Ye.v0.y-(V-Ye.y0)/U},A();else if(Ye.kind==="marquee"){if(Math.hypot(L-Ye.x0,V-Ye.y0)<3)return;Ye.moved=!0;let re=Y(Ye.x0,Ye.y0),le=Y(L,V);if(F){Wt(re,le);return}let[ce,me]=Cs(re.x,re.y),[he,ye]=Cs(le.x,le.y),Pe={x0:Math.min(ce,he),y0:Math.min(me,ye),x1:Math.max(ce,he),y1:Math.max(me,ye)},Ze=new Map;for(let[We,jt]of pe()){let Ve=jt,At=Ve.x0>=Pe.x0&&Ve.y0>=Pe.y0&&Ve.x1<=Pe.x1&&Ve.y1<=Pe.y1,vs=Ve.x0<Pe.x1&&Ve.x1>Pe.x0&&Ve.y0<Pe.y1&&Ve.y1>Pe.y0;(Ye.touch?vs:At)&&Ze.set(We,rt(We))}let Le=new Map((Ye.sel0??[]).map(We=>[Se(We),We]));for(let[We,jt]of Ze)Le.set(We,jt);e.select([...Le.values()],"canvas"),st();let ft=Ne().createElementNS(pn,"polygon");ft.setAttribute("class","marquee"),ft.setAttribute("points",[[Pe.x0,Pe.y0],[Pe.x1,Pe.y0],[Pe.x1,Pe.y1],[Pe.x0,Pe.y1]].map(([We,jt])=>Je(We,jt,0).map(Ve=>Ve.toFixed(1)).join(",")).join(" ")),fe.append(ft),H=Pe}else if(Ye.kind==="pin"){if(!Ye.moved&&Math.hypot(L-Ye.x0,V-Ye.y0)<4)return;if(Ye.moved=!0,St={x:L,y:V,alt:E.altKey},!zt){zt=!0;let re=()=>{zt&&(zt=!1,ss())};requestAnimationFrame(re),setTimeout(re,32)}}}function Wt(E,L){if(!Ye||!F||!te)return;let V={l:Math.min(E.x,L.x),t:Math.min(E.y,L.y),r:Math.max(E.x,L.x),b:Math.max(E.y,L.y)},U=new Map;for(let ce of F.hits(V,!!Ye.touch)){let me=te.pathOf.get(ce);me!==void 0&&w(me)?.path===me&&U.set(me,rt(me))}let re=new Map((Ye.sel0??[]).map(ce=>[Se(ce),ce]));for(let[ce,me]of U)re.set(ce,me);e.select([...re.values()],"canvas"),st();let le=Ne().createElementNS(pn,"rect");le.setAttribute("class","marquee"),le.setAttribute("x",String(V.l)),le.setAttribute("y",String(V.t)),le.setAttribute("width",String(V.r-V.l)),le.setAttribute("height",String(V.b-V.t)),fe.append(le)}let zt=!1,St,zn=0,Ct=()=>Ye?.kind==="pin"&&Ye.moved?Ye:void 0;function ss(){let E=Ct();if(!E||!St||!te)return;let L=et(),V=St.alt?.5:1;E.step=V;let U=Wo(E.start,Cs((St.x-E.x0)/L,(St.y-E.y0)/L),V,E.size,E.parent),re=E.parent?E.parent.box.x0:0,le=E.parent?E.parent.box.y0:0,ce={x0:re+U.at[0],y0:le+U.at[1],x1:re+U.at[0]+E.size[0],y1:le+U.at[1]+E.size[1]},me=!E.move||E.move.at[0]!==U.at[0]||E.move.at[1]!==U.at[1];E.move=U,E.invalid=gr(ce,E.siblings),ne?.classList.add("dragging"),ne?.classList.toggle("drag-bad",E.invalid),it(E.id,[U.at[0]-E.shown[0],U.at[1]-E.shown[1]]),vn(ce);let he=E.parent?`within ${E.parent.label}`:"on the canvas";n.onHint?.(`Moving ${E.name} ${he} \xB7 ${V===1?"whole cells (\u2325: half cells)":"half cells"} \xB7 ${E.invalid?"overlaps: it won't drop here":"Esc cancels"}${o.pinHint}`),me&&!E.invalid&&se&&(clearTimeout(zn),zn=window.setTimeout(async()=>{let ye=Ct();if(!ye||ye.invalid||!ye.move)return;let Pe;try{({next:Pe,keep:ye.keep}=xs(ye))}catch{return}Ct()===ye&&(await Ee(Pe),Ct()===ye&&(ye.shown=ye.move.at,it(ye.id,[0,0]),vn(ye.parent?{x0:ye.parent.box.x0+ye.move.at[0],y0:ye.parent.box.y0+ye.move.at[1],x1:ye.parent.box.x0+ye.move.at[0]+ye.size[0],y1:ye.parent.box.y0+ye.move.at[1]+ye.size[1]}:ce)))},0))}function xs(E){let L=JSON.parse(JSON.stringify(Me??{}));s.pins.legacyOnly(L)&&(L[y]=L[s.pins.legacyKey],delete L[s.pins.legacyKey]),L[y]??={},L[y].layout??={};let V=L[y].layout;V[E.name]={at:E.move.at};let U=s.draw(se,L,n.theme),re=E.origCd,le=new Map([...re.pinId].map(([ye,Pe])=>[Pe,ye])),ce=re.scene.layout.byId.get(E.id),me=ce.parent?ce.parent.children:re.scene.layout.items.filter(ye=>!ye.parent),he=[];for(let ye of me){if(ye===ce)continue;let Pe=le.get(ye.id),Ze=Hr(re.scene,ye.id),Le=U.scene.layout.byId.get(ye.id)?.box;!Pe||!Ze||!Le||Pe in V||(Math.abs(Le.x0-ye.box.x0)>1e-6||Math.abs(Le.y0-ye.box.y0)>1e-6)&&he.push([Pe,Ze])}if(he.length){for(let[ye,Pe]of he)V[ye]={at:Pe};U=s.draw(se,L,n.theme)}return{next:U,keep:he}}function it(E,[L,V]){if(!ne||!te)return;let[U,re]=[(L-V)*Bt*xt,(L+V)*.5*xt],le=new Set([E]);for(let ce of te.scene.layout.items){let me=ce.parent;for(;me;){if(me.id===E){le.add(ce.id);break}me=me.parent}}for(let ce of ne.querySelectorAll("[data-id]"))le.has(ce.getAttribute("data-id")??"")&&(ce.parentElement?.closest(`[data-id="${CSS.escape(ce.getAttribute("data-id"))}"]`)||ce.setAttribute("transform",L||V?`translate(${U.toFixed(1)} ${re.toFixed(1)})`:""))}function vn(E){let L=Ct();if(!L||!fe)return;st();let V=Ne(),U=V.createElementNS(pn,"g");U.setAttribute("class",L.gridShown?"gridwrap":"gridwrap fresh"),L.gridShown=!0;let re=L.z0,le=(Le,ft)=>Je(Le,ft,re).map(We=>We.toFixed(1)).join(","),ce=L.parent?L.parent.box:{x0:Math.floor(E.x0)-8,y0:Math.floor(E.y0)-8,x1:Math.ceil(E.x1)+8,y1:Math.ceil(E.y1)+8},me=(Le,ft,We,jt,Ve)=>{let At=V.createElementNS(pn,"polyline");At.setAttribute("class",Ve),At.setAttribute("points",`${le(Le,ft)} ${le(We,jt)}`),U.append(At)},he=L.parent?L.parent.box.x0:0,ye=L.parent?L.parent.box.y0:0,Pe=L.step??1;for(let Le=Math.ceil((ce.x0-he)/Pe)*Pe;he+Le<=ce.x1+1e-9;Le+=Pe)me(he+Le,ce.y0,he+Le,ce.y1,Number.isInteger(Le)?"dgrid":"dgrid sub");for(let Le=Math.ceil((ce.y0-ye)/Pe)*Pe;ye+Le<=ce.y1+1e-9;Le+=Pe)me(ce.x0,ye+Le,ce.x1,ye+Le,Number.isInteger(Le)?"dgrid":"dgrid sub");fe.append(U);let Ze=V.createElementNS(pn,"polygon");if(Ze.setAttribute("class",`drop${L.invalid?" bad":""}`),Ze.setAttribute("points",[[E.x0,E.y0],[E.x1,E.y0],[E.x1,E.y1],[E.x0,E.y1]].map(([Le,ft])=>le(Le,ft)).join(" ")),fe.append(Ze),L.parent&&L.move){let Le=L.parent.box,ft=L.move.clamped,We=L.parent.pad,jt=(Ve,At,vs,ks)=>{let mo=V.createElementNS(pn,"polyline");mo.setAttribute("class","edge"),mo.setAttribute("points",`${le(Ve,At)} ${le(vs,ks)}`),fe.append(mo)};ft.left&&jt(Le.x0+We,Le.y0,Le.x0+We,Le.y1),ft.right&&jt(Le.x1-We,Le.y0,Le.x1-We,Le.y1),ft.top&&jt(Le.x0,Le.y0+We,Le.x1,Le.y0+We),ft.bottom&&jt(Le.x0,Le.y1-We,Le.x1,Le.y1-We)}}async function Tt(E){let L=Ct();if(!L)return;Ye=void 0,clearTimeout(zn);let V=fe?[...fe.querySelectorAll(".gridwrap, .drop, .edge")]:[];if(V.length){for(let le of V)le.classList.add("out");matchMedia("(prefers-reduced-motion: reduce)").matches||await new Promise(le=>setTimeout(le,160))}be="",ne?.classList.remove("dragging","drag-bad"),Q();let U=L.move,re=U&&(U.at[0]!==L.start[0]||U.at[1]!==L.start[1]);if(E&&U&&re&&!L.invalid){let le=`Pin ${p(rt(L.ptr))} at [${U.at.join(", ")}]`,ce=L.keep??[];if(!L.shown||L.shown[0]!==U.at[0]||L.shown[1]!==U.at[1])try{ce=xs(L).keep}catch{}xn(e,ce.length?d([[L.name,U.at],...ce],`${le} (${ce.map(([me])=>me).join(", ")} kept in place)`):u(i([y,"layout",L.name],{at:U.at},le)),"canvas",n.note),Oe&&se&&(Oe=!1,be="",D(se,Me));return}E&&L.invalid&&n.note(`${L.name} can't go there: it would overlap`,"warn"),await Ee(L.origCd),Oe&&se&&(Oe=!1,be="",D(se,Me))}function tn(E){if(T&&!T.pick){let{x:le,y:ce}=yt(E);Ft(ze(document.elementFromPoint(le,ce)));return}let L=Ye;if(Ye=void 0,ne?.classList.remove("panning"),!L)return;let{x:V,y:U}=yt(E);(L.kind==="marquee"&&!L.moved&&!L.add||L.kind==="pan"&&L.emptyClick)&&e.select([],"canvas");let re=L.kind==="click"?L.ptr:L.kind==="pin"&&!L.moved?L.narrow:void 0;if(re&&e.select([rt(re)],"canvas"),L.kind==="pin"&&L.moved){Ye=L,St={x:V,y:U,alt:E.altKey},zt=!1,ss(),Tt(!0);return}st()}let H;function pe(){let E=new Map;if(!te)return E;for(let[L,V]of te.pathOf){let U=w(V);if(!U||U.path!==V)continue;let re=te.scene.layout.byId.get(L);if(!re||ne?.querySelector(`[data-id="${CSS.escape(L)}"].pre`))continue;let le=re.box,ce=le.z0,me={x0:le.x0-ce,y0:le.y0-ce,x1:le.x1-ce,y1:le.y1-ce},he=E.get(V);E.set(V,he?{x0:Math.min(he.x0,me.x0),y0:Math.min(he.y0,me.y0),x1:Math.max(he.x1,me.x1),y1:Math.max(he.y1,me.y1)}:me)}return E}let ke=E=>Math.round(E*2)/2,Te=([E,L])=>[ke(E),ke(L)],Ie=(E,L)=>{let[V,U]=Cs(1,0),[re,le]=Cs(0,1),ce=V*le-U*re;return[(E*le-L*re)/ce,(L*V-E*U)/ce]};function ot(E){E.preventDefault();let{x:L,y:V}=yt(E),U=et();if(E.ctrlKey||E.metaKey){q(Math.exp(-E.deltaY*.01),L,V);return}if(E.shiftKey){Ae.view={...Ae.view,x:Ae.view.x+(E.deltaX||E.deltaY)/U},A();return}ue.wheel==="zoom"?q(Math.exp(-E.deltaY*.0025),L,V):(Ae.view={...Ae.view,x:Ae.view.x+E.deltaX/U,y:Ae.view.y+E.deltaY/U},A())}function kt(E){E.preventDefault();let{x:L,y:V}=yt(E);if(W?.context?.(E,{x:L,y:V}))return;let U=ze(E.target);U!==void 0&&!e.selection.some(re=>Se(re)===U)&&e.select([rt(U)],"canvas"),ys(An(U),{x:L,y:V},"Canvas")}function An(E){let L=e.selection,V=[],U=!e.doc.ok;if(E===void 0||!L.length){for(let me of r.newOrder)V.push({label:`New ${M(me).singular}`,icon:"plus",disabled:U,onSelect:()=>Ar(me)});n.clipItems&&V.push({sep:!0},...n.clipItems().filter(me=>"label"in me&&me.label==="Paste")),V.push({sep:!0},{label:"Fit",keys:"0",onSelect:()=>m()},{label:"Fit the whole drawing",onSelect:()=>ae()},{label:"Zoom 100%",keys:"1",onSelect:()=>R()});let ce=!!s.pins.of(e.goodDoc.data);return V.push({label:"Reset layout",icon:"rotate-ccw",desc:"Remove every pin (x-editor.layout)",disabled:U||!ce,why:"Nothing is pinned",onSelect:tp}),V}let re=L.length===1?L[0]:void 0,le=re&&w(Se(re))?.path===Se(re);if(re){V.push(...s.objectItems(e,re,"canvas",n.note)),V.length&&V.push({sep:!0}),V.push({label:"Rename\u2026",icon:"pencil",keys:"F2",disabled:U||!le,why:o.renameWhy,onSelect:()=>h(e,re,"canvas",n.note)}),V.push({label:"Duplicate",icon:"copy",keys:"\u2318D",disabled:U||!le,why:o.duplicateWhy,onSelect:()=>b(e,re,"canvas",n.note)});let ce=le?w(Se(re)).name:"";s.pins.of(e.goodDoc.data)?.[ce]&&V.push({label:"Unpin",icon:"rotate-ccw",desc:"Let the layout place it again",onSelect:()=>xn(e,u({...a([y,"layout",ce]),label:`Unpin ${p(re)}`}),"canvas",n.note)}),V.push({sep:!0}),V.push({label:"Show in text",icon:"code-xml",onSelect:()=>n.showInText(re)}),V.push({label:"Show in tree",icon:"list-tree",onSelect:()=>n.showInTree(re)})}return s.connect&&re&&le&&V.push({label:"Connect to\u2026",icon:"link",desc:"Then click what it connects to (Esc cancels)",disabled:U,onSelect:()=>Qe()}),s.group&&V.push({label:L.length>1?`Group ${L.length} items`:"Group",icon:"box",keys:"\u2318G",desc:"Into a new container, as one step",disabled:U||!Qt().length,why:"Only objects are grouped",onSelect:nn}),V.push({label:"Select parent",icon:"arrow-up-right",keys:"\u2318\u2191",onSelect:wd}),V.push({label:"Select connected",icon:"link",desc:"What refers to it, and what it refers to",onSelect:()=>e.select(v(e,L),"canvas")}),V.push({label:"Zoom to selection",keys:"\u21E72",onSelect:Z}),n.clipItems&&V.push({sep:!0},...n.clipItems()),V.push({sep:!0},{label:L.length>1?`Delete ${L.length} items`:"Delete",icon:"trash-2",keys:"\u232B",danger:!0,disabled:U,onSelect:()=>g(e,L,"canvas",n.note)}),V}function Xe(){if(!s.connect||!e.doc.ok||e.selection.length!==1)return;let E=Se(e.selection[0]),L=w(E);return L&&L.path===E?L:void 0}function Qe(){let E=Xe();E&&(T={from:E,pick:!0},n.note(`Click what ${E.name} connects to (Esc cancels)`),st())}function Ft(E){let L=T?.from;if(T=void 0,st(),!L||E===void 0)return;let V=w(E);if(!V||V.path===L.path){n.note("Not connected: drop it on another object","warn");return}let U=e.goodDoc.data,re=s.connect?.(L,V,U);if(!re){n.note(`${L.name} and ${V.name} can't be connected`,"warn");return}let le=re.label??`Connect ${L.name} to ${V.name}`,ce,me;if(re.name!==void 0){let he=f(e.text,re.name);ce=l(re.at,he,re.value,{label:le}),me=[...re.at,he]}else{let he=re.at.reduce((ye,Pe)=>ye&&typeof ye=="object"?ye[Pe]:void 0,U);me=[...re.at,Array.isArray(he)?he.length:0],ce=c(re.at,re.value,void 0,le)}xn(e,{...ce,select:[me]},"canvas",n.note)&&e.select([me],"canvas")}function Qt(){let E=new Map;for(let L of e.selection){let V=w(Se(L));V&&E.set(V.path,V)}return[...E.values()]}function nn(){if(!s.group||!e.doc.ok)return;let E=Qt();if(!E.length){n.note("Only objects are grouped","warn");return}let L=s.group(E,e.goodDoc.data);if(!L){n.note(E.length>1?`These ${E.length} can't be grouped`:`${E[0].name} can't be grouped`,"warn");return}let V=f(e.text,L.name),U=s.pins.of(e.goodDoc.data)??{},re=E.filter(he=>U[he.name]!==void 0).map(he=>u(a([y,"layout",he.name]))),le=L.label??`Group ${E.length>1?`${E.length} items`:E[0].name} into ${V}`,ce=[...L.at,V],me=ai(le,[l(L.at,V,L.value,{label:le}),...L.members(V).map(he=>i(he.path,he.value)),...re]);xn(e,{...me,select:[ce]},"canvas",n.note)&&e.select([ce],"canvas")}function Ar(E){let L=M(E),V=f(e.text,L.singular),U=[...L.section,V];xn(e,l(U.slice(0,-1),V,L.template(),{label:`Add ${L.singular} ${V}`}),"canvas",n.note)&&(e.select([U],"canvas"),h(e,U,"canvas",n.note))}function Pl(E,L,V){if(!te||!ne)return;let U=L.build(e.text).steps.reduce((ks,mo)=>yn(ks,mo),e.text),re;try{re=s.trial(U,n.theme)}catch{return}if(!re)return;let le=re.pinId.get(E),ce=le?re.scene.layout.byId.get(le):void 0,me=le?Hr(re.scene,le):void 0;if(!ce||!me)return;let he=ce.box,ye=ce.parent,Pe=(he.x0+he.x1)/2,Ze=(he.y0+he.y1)/2,Le=[(Pe-Ze)*Bt*xt,(Pe+Ze)*.5*xt-he.z0*xt],ft=Y(V.x,V.y),We=Wo(me,Cs(ft.x-Le[0],ft.y-Le[1]),1,[he.x1-he.x0,he.y1-he.y0],ye?{w:ye.box.x1-ye.box.x0,d:ye.box.y1-ye.box.y0,pad:Uo(s.catalog,ye.region)}:void 0),jt=We.at[0]-me[0],Ve=We.at[1]-me[1],At={x0:he.x0+jt,y0:he.y0+Ve,x1:he.x1+jt,y1:he.y1+Ve},vs=(ye?ye.children:re.scene.layout.items.filter(ks=>!ks.parent)).filter(ks=>ks!==ce).map(ks=>ks.box);return gr(At,vs)?void 0:We.at}function ui(E,L){if(!te)return;let V=Y(L.x,L.y);if(F){for(let re of F.panelsAt(V.x,V.y)){let le=[...te.pinId].find(([,ce])=>ce===re)?.[0];if(le&&w(te.pathOf.get(re)??"")?.kind===E)return le}return}let U=re=>{let le=!1;for(let ce=0,me=re.length-1;ce<re.length;me=ce++){let[he,ye]=re[ce],[Pe,Ze]=re[me];ye>V.y!=Ze>V.y&&V.x<(Pe-he)*(V.y-ye)/(Ze-ye)+he&&(le=!le)}return le};for(let[re,le]of te.pinId){if(w(te.pathOf.get(le)??"")?.kind!==E)continue;let ce=te.scene.layout.byId.get(le);if(ce&&U(Yr(ce.box)))return re}}function lr(E){if(!te)return[];let L=Y(E.x,E.y),V=me=>{let he=te.pathOf.get(me),ye=he===void 0?void 0:w(he);return ye&&ye.path===he?ye:void 0};if(F)return F.panelsAt(L.x,L.y).map(V).filter(me=>!!me);let U=me=>{let he=!1;for(let ye=0,Pe=me.length-1;ye<me.length;Pe=ye++){let[Ze,Le]=me[ye],[ft,We]=me[Pe];Le>L.y!=We>L.y&&L.x<(ft-Ze)*(L.y-Le)/(We-Le)+Ze&&(he=!he)}return he},re=me=>{let he=0;for(let ye=me.parent;ye;ye=ye.parent)he++;return he},le=new Map;for(let me of Ne().elementsFromPoint(E.x,E.y))if(ne?.contains(me))for(let he=me.closest("[data-id]");he;he=he.parentElement?.closest("[data-id]")??null){let ye=V(he.getAttribute("data-id")??"");ye&&!le.has(ye.path)&&le.set(ye.path,ye)}let ce=[];for(let[,me]of te.pinId){let he=te.scene.layout.byId.get(me),ye=V(me);he&&ye&&!le.has(ye.path)&&U(Yr(he.box))&&ce.push({r:ye,d:re(he),a:(he.box.x1-he.box.x0)*(he.box.y1-he.box.y0)})}return[...le.values(),...ce.sort((me,he)=>he.d-me.d||me.a-he.a).map(me=>me.r)]}function rs(E,L,V){if(!e.doc.ok){n.note("Fix the YAML first","warn");return}let U=M(E),re=V?.value?.(),le=V&&re!==void 0?V.label.toLowerCase():U.singular,ce=f(e.text,V?.name??U.singular),me=[...U.section,ce],he=re??U.template(),ye,Pe=L?s.dropInto?.(E):void 0;if(L&&Pe){let Ve=ui(Pe.container,L);Ve&&(ye=Ve,he={...Pe.value(Ve),...re??{}})}let Ze=ye?Pe.label(ye):"";if(L&&!ye&&s.dropOnto)for(let Ve of lr(L)){let At=s.dropOnto(Ve,he,E,e.goodDoc.data);if(At){ye=Ve.name,he=At.value,Ze=At.label?` ${At.label}`:` in ${Ve.name}`;break}}let Le=`Add ${le} ${ce}${Ze}`,ft=l(me.slice(0,-1),ce,he,{label:Le}),We=L&&!ye&&N==="3d"?Pl(ce,ft,L):void 0,jt=We?ai(`${Le} at [${We.join(", ")}]`,[ft,u(i([y,"layout",ce],{at:We}))]):ft;if(xn(e,{...jt,select:[me]},"canvas",n.note))return L&&!ye&&!We&&n.note(N==="2d"?`${U.singular} ${ce} added; the layout placed it (in 3D a drop pins it where it lands)`:`${U.singular} ${ce} added; that spot is taken, so the layout placed it`),e.select([me],"canvas"),S.focus({preventScroll:!0}),h(e,me,"canvas",n.note),me}let kn=K("div",{class:"palette",role:"toolbar","aria-label":o.palette,"aria-orientation":"vertical"}),xe=new Map,Fe="canvas-palette",at;try{let E=JSON.parse(n.store?.get(Fe)??"{}");typeof E.last=="string"&&(at=E.last)}catch{}let wt=[...new Set(r.palette.map(E=>E.section).filter(E=>E!==void 0))],mt=at!==void 0&&wt.includes(at)?at:wt[0],Ot=(E,L)=>{let V=xe.get(E);V&&(V.head.setAttribute("aria-expanded",String(L)),V.body.hidden=!L)};function Zt(E){let L=xe.get(E);if(L)return L.body;let V=`pal-sec-${xe.size}-${Math.random().toString(36).slice(2,8)}`,U=K("button",{type:"button",class:"pal-head","aria-expanded":"false","aria-controls":V,"data-section-head":E},Ut("chevron-right","pal-chev"),K("span",{class:"pal-head-label"},E)),re=K("div",{class:"pal-body",id:V,role:"group","aria-label":E,"data-section-body":E});return U.addEventListener("click",()=>Ot(E,U.getAttribute("aria-expanded")!=="true")),kn.append(K("div",{class:"pal-section","data-pal-section":E},U,re)),xe.set(E,{head:U,body:re}),Ot(E,E===mt),re}let mn="canvas-palette-dock",sn={};try{let E=JSON.parse(n.store?.get(mn)??"{}");typeof E.w=="number"&&Number.isFinite(E.w)&&(sn.w=E.w),E.collapsed===!0&&(sn.collapsed=!0)}catch{}let hn=()=>{try{n.store?.set(mn,JSON.stringify(sn))}catch{}},Sn=160,Mt=440,Vt=dt?K("aside",{class:"pal-dock","aria-label":"Palette"}):kn,$t=K("div",{class:"pal-grip",role:"separator","aria-orientation":"vertical","aria-label":"Resize the palette",tabindex:"0"}),Vn=K("input",{type:"search",class:"pal-search",placeholder:"Search","aria-label":"Search the palette",autocomplete:"off",spellcheck:"false"}),fo=K("p",{class:"pal-none",role:"status",hidden:""}),ws=K("button",{type:"button",class:"btn sm quiet icon-only pal-collapse","aria-expanded":"true","aria-label":"Collapse the palette",title:"Collapse the palette"},Ut("chevron-left")),po=()=>[...kn.querySelectorAll(".pal-item")].filter(E=>!E.hidden&&!E.closest("[hidden]")),_s;function fi(){let E=Vn.value.toLowerCase().split(/\s+/).filter(Boolean);E.length&&!_s&&(_s=new Map([...xe].map(([V,U])=>[V,U.head.getAttribute("aria-expanded")==="true"])));let L=0;for(let V of kn.querySelectorAll(".pal-item")){let U=r.palette[Number(V.dataset.entry)],re=`${U.label} ${U.section??""}`.toLowerCase();V.hidden=!E.every(le=>re.includes(le)),V.hidden||L++}for(let[V,U]of xe){let re=[...U.body.querySelectorAll(".pal-item")].some(le=>!le.hidden);U.head.parentElement.hidden=E.length>0&&!re,E.length&&Ot(V,re)}if(!E.length&&_s){for(let[V,U]of _s)Ot(V,U);_s=void 0}fo.hidden=L>0,fo.textContent=L?"":`Nothing matches "${Vn.value.trim()}"`}let pi=(E,L=!0)=>{let V=Math.round(Math.min(Mt,Math.max(Sn,E)));t.style.setProperty("--pal-w",`${V}px`),$t.setAttribute("aria-valuenow",String(V)),L&&(sn.w=V,hn())},xd=(E,L=!0)=>{t.classList.toggle("pal-collapsed",E),ws.setAttribute("aria-expanded",String(!E));let V=E?"Show the palette":"Collapse the palette";ws.setAttribute("aria-label",V),ws.title=V,ws.replaceChildren(Ut(E?"chevron-right":"chevron-left")),L&&(E?sn.collapsed=!0:delete sn.collapsed,hn())};dt&&(t.classList.add("pal-docked"),kn.classList.add("pal-list"),Vt.append(K("div",{class:"pal-dock-head"},ws,K("label",{class:"pal-search-wrap"},Ut("search"),Vn)),kn,fo),$t.setAttribute("aria-valuemin",String(Sn)),$t.setAttribute("aria-valuemax",String(Mt)),pi(sn.w??220,!1),xd(!!sn.collapsed,!1),ws.addEventListener("click",()=>{xd(!t.classList.contains("pal-collapsed")),t.classList.contains("pal-collapsed")||Vn.focus()}),Vn.addEventListener("input",fi),Vn.addEventListener("keydown",E=>{if(E.key==="Escape"&&Vn.value)E.preventDefault(),E.stopPropagation(),Vn.value="",fi();else if(E.key==="ArrowDown"){let L=po()[0];L&&(E.preventDefault(),L.focus())}else if(E.key==="Enter"){let L=po()[0];L&&(E.preventDefault(),L.dispatchEvent(new KeyboardEvent("keydown",{key:"Enter",bubbles:!0})))}}),kn.addEventListener("keydown",E=>{if(E.key!=="ArrowDown"&&E.key!=="ArrowUp")return;let L=[...kn.querySelectorAll(".pal-head, .pal-item")].filter(U=>!U.hidden&&!U.parentElement?.closest("[hidden]")&&(U.classList.contains("pal-head")||!U.closest(".pal-body[hidden]"))),V=L.indexOf(document.activeElement);V<0||(E.preventDefault(),E.key==="ArrowUp"&&V===0?Vn.focus():L[Math.min(L.length-1,Math.max(0,V+(E.key==="ArrowDown"?1:-1)))].focus())}),$t.addEventListener("pointerdown",E=>{if(E.button!==0)return;try{$t.setPointerCapture(E.pointerId)}catch{}let L=E.clientX,V=Vt.getBoundingClientRect().width,U=le=>pi(V+le.clientX-L,!1),re=le=>{$t.removeEventListener("pointermove",U),$t.removeEventListener("pointerup",re),pi(V+le.clientX-L)};$t.addEventListener("pointermove",U),$t.addEventListener("pointerup",re)}),$t.addEventListener("keydown",E=>{let L=E.key==="ArrowLeft"?-16:E.key==="ArrowRight"?16:0;L&&(E.preventDefault(),pi(Vt.getBoundingClientRect().width+L))}));let Ol=E=>{if(!(E.section===void 0||E.section===at)){at=E.section;try{n.store?.set(Fe,JSON.stringify({last:at}))}catch{}}};r.palette.forEach((E,L)=>{let{kind:V,icon:U,label:re}=E,le=K("button",{type:"button",class:"pal-item","data-section":V,"data-entry":String(L),title:`Add ${re.toLowerCase()} (click), or drag it where it goes`},Ut(U),K("span",{class:"pal-label"},re));le.addEventListener("pointerdown",ce=>{if(ce.button!==0)return;ce.preventDefault();try{le.setPointerCapture(ce.pointerId)}catch{}let me=ce.clientX,he=ce.clientY,ye,Pe=Ve=>{let At=S.getBoundingClientRect();return Ve.clientX>=At.left&&Ve.clientX<=At.right&&Ve.clientY>=At.top&&Ve.clientY<=At.bottom&&!Vt.contains(document.elementFromPoint(Ve.clientX,Ve.clientY))},Ze=Ve=>{if(!ye&&Math.hypot(Ve.clientX-me,Ve.clientY-he)<4)return;ye||(ye=K("div",{class:"pal-ghost","aria-hidden":"true"},Ut(U),re),t.append(ye));let At=t.getBoundingClientRect();ye.style.left=`${Ve.clientX-At.left+8}px`,ye.style.top=`${Ve.clientY-At.top+8}px`,ye.classList.toggle("bad",!Pe(Ve))},Le=(Ve,At)=>{le.removeEventListener("pointermove",Ze),le.removeEventListener("pointerup",ft),le.removeEventListener("pointercancel",We),removeEventListener("keydown",jt,!0);let vs=!!ye;ye?.remove(),At&&(vs?Pe(Ve)&&(Ol(E),rs(V,{x:Ve.clientX,y:Ve.clientY},E)):(Ol(E),rs(V,void 0,E)))},ft=Ve=>Le(Ve,!0),We=Ve=>Le(Ve,!1),jt=Ve=>{Ve.key==="Escape"&&(Ve.stopPropagation(),Ve.preventDefault(),Le(ce,!1))};le.addEventListener("pointermove",Ze),le.addEventListener("pointerup",ft),le.addEventListener("pointercancel",We),addEventListener("keydown",jt,!0)}),le.addEventListener("keydown",ce=>{(ce.key==="Enter"||ce.key===" ")&&(ce.preventDefault(),Ol(E),rs(V,void 0,E))}),(E.section===void 0?kn:Zt(E.section)).append(le)}),dt?t.prepend(Vt,$t):t.append(kn);function tp(){let E=s.pins.keyOf(e.goodDoc.data),L=e.goodDoc.data?.[E],V=L&&Object.keys(L).length===1;xn(e,{...a(V?[E]:[E,"layout"]),label:"Reset the layout"},"canvas",n.note)}function wd(){let E=new Map;for(let L of e.selection){let V=w(Se(L)),U=V&&V.path!==Se(L)?rt(V.path):V?M(V.kind).section:[];E.set(Se(U),U)}e.select([...E.values()],"canvas")}function Cl(E){if(E.type==="keyup"&&E.key!==" ")return;if(E.key===" "){Pt=E.type==="keydown",ne?.classList.toggle(r.panKeyClass,Pt),E.preventDefault();return}let L=W?.key?.(E);if(L==="ignore")return;if(L==="handled"){E.preventDefault(),E.stopPropagation();return}let V=E.metaKey||E.ctrlKey,U=e.selection,re=[...new Set([...te?.pathOf.values()??[]].filter(ce=>w(ce)?.path===ce))],le=!e.doc.ok;switch(E.key){case"+":case"=":q(1.25);break;case"-":case"_":q(.8);break;case"0":m();break;case"1":R();break;case"@":case"2":if(E.shiftKey||E.key==="@")Z();else return;break;case"Escape":if(T){T=void 0,st(),n.note("Not connected");break}if(Ct()){Tt(!1);break}e.select([],"canvas");break;case"Delete":case"Backspace":U.length&&!le&&g(e,U,"canvas",n.note);break;case"F2":U.length===1&&!le&&h(e,U[0],"canvas",n.note);break;case"ArrowUp":if(V){wd();break}return;case"Tab":case"ArrowRight":case"ArrowLeft":case"ArrowDown":{if(!re.length)return;let ce=U.length?re.indexOf(Se(U[0])):-1,me=E.key==="ArrowLeft"||E.key==="Tab"&&E.shiftKey,he=ce<0?0:(ce+(me?-1:1)+re.length)%re.length;e.select([rt(re[he])],"canvas"),kd(rt(re[he]));break}case"ContextMenu":case"F10":if(E.key==="F10"&&!E.shiftKey)return;{let ce=Re(U),me=ut.getBoundingClientRect(),he=et();ys(An(U.length?Se(U[0]):void 0),ce?{x:me.left+(ce.x+ce.w-Ae.view.x)*he,y:me.top+(ce.y-Ae.view.y)*he}:{x:me.left+40,y:me.top+40},"Canvas")}break;default:if(V&&E.key.toLowerCase()==="d"&&U.length===1&&!le){b(e,U[0],"canvas",n.note);break}if(V&&E.key.toLowerCase()==="a"){e.select(re.map(rt),"canvas");break}if(V&&E.key.toLowerCase()==="g"&&s.group&&U.length&&!le){nn();break}return}E.preventDefault(),E.stopPropagation()}S.addEventListener("keydown",Cl),S.addEventListener("keyup",Cl);let vd=E=>t.classList.toggle("has-focus",E);S.addEventListener("focus",()=>vd(!0)),S.addEventListener("blur",()=>vd(!1)),Q();function kd(E){let L=He(E);!L||!Ae.view||(L.x<Ae.view.x||L.y<Ae.view.y||L.x+L.w>Ae.view.x+Ae.view.w||L.y+L.h>Ae.view.y+Ae.view.h)&&(Ae.view={...Ae.view,x:L.x+L.w/2-Ae.view.w/2,y:L.y+L.h/2-Ae.view.h/2},A())}function Sd(E){if(!Ae.view||!E.length)return!0;let L=E.map(He);if(L.some(re=>!re))return!1;let V=De(L),U=24/et();return V.x-U>=Ae.view.x&&V.y-U>=Ae.view.y&&V.x+V.w+U<=Ae.view.x+Ae.view.w&&V.y+V.h+U<=Ae.view.y+Ae.view.h?!0:V.w+2*U>Ae.view.w||V.h+2*U>Ae.view.h?(ae({x:V.x-U,y:V.y-U,w:V.w+2*U,h:V.h+2*U}),!0):(Ae.view={...Ae.view,x:V.x+V.w/2-Ae.view.w/2,y:V.y+V.h/2-Ae.view.h/2},A(),!0)}let mi;Et(),e.onSelect(E=>{st(),!(E.origin==="canvas"||!E.paths.length)&&(mi=Sd(E.paths)?void 0:E.paths)});let Md={addFromPalette:rs,palette:kn,groupSelection:nn,startPick:Qe,objectsUnder:lr,get linking(){return T},render:D,setTheme:lt,paintOverlay:st,fit:m,fitAll:ae,actual:R,zoomAt:q,itemsBox:Ue,get moved(){return Ae.moved},settled:G,get zoom(){return Ae.zoom},dispose(){Ke(),clearTimeout(zn),Ae.dispose(),qe=!0},focus:()=>S.focus(),get view(){return Ae.view},get doc(){return te},get mode(){return N},setMode:z,get flat(){return F?.layout},stage:S,key:Cl,scale:()=>et(),nav:ue,paintNav:Q,outlinesFor:nt,footprints:pe,get drag(){return Ct()},get lastMarquee(){return H},boxFor:He,pageXYOf:E=>{let L=He(E),V=ut.getBoundingClientRect(),U=et();return L&&Ae.view?{x:V.left+(L.x+L.w/2-Ae.view.x)*U,y:V.top+(L.y+L.h/2-Ae.view.y)*U}:void 0}};return W&&Object.defineProperties(Md,Object.getOwnPropertyDescriptors(W.api)),Md}var qf={draw(t,e,n){let s=Zr(e),r;try{r=Js(br(t),s,n.options)}finally{s.dispose()}let o=r.bounds,i=l=>r.cards.find(c=>c.id===l)?.rect??r.panels.find(c=>c.id===l)?.rect;return{svg:Qr(r,{id:"canvas-2d",title:n.title,styles:n.styles}),full:[o.l,o.t,o.r-o.l,o.b-o.t],layout:r,outlines(l,c){let d=[];for(let u of l){let f=i(u);if(f){d.push({kind:"poly",id:u,points:[[f.l,f.t],[f.r,f.t],[f.r,f.b],[f.l,f.b]]});continue}let p=c.querySelector(`path.conn[data-id="${CSS.escape(u)}"]`)?.getAttribute("d");p&&d.push({kind:"route",d:p})}return d},hits(l,c){return[...r.cards,...r.panels].filter(d=>{let u=d.rect;return c?u.l<l.r&&u.r>l.l&&u.t<l.b&&u.b>l.t:u.l>=l.l&&u.t>=l.t&&u.r<=l.r&&u.b<=l.b}).map(d=>d.id)},panelsAt(l,c){return[...r.panels].sort((d,u)=>u.depth-d.depth).filter(d=>l>=d.rect.l&&l<=d.rect.r&&c>=d.rect.t&&c<=d.rect.b).map(d=>d.id)}}},morph(t,e,n,s,r){let o=n.mode==="3d"?n.svg:s;return eo(o,e,br(e)),tl(t,n.svg,s,n.mode,r)}};var Hm=t=>`
|
|
471
471
|
<header class="titlebar">
|
|
472
472
|
<button id="se-tree" class="btn sm quiet icon-only" type="button" aria-expanded="false" aria-controls="se-side" aria-label="Show the outline" title="The outline"><svg class="icon" aria-hidden="true"><use href="#se-i-list-tree"></use></svg></button>
|
|
473
473
|
<span class="brand" data-se="brand" hidden>${t.brand}</span>
|
|
@@ -541,10 +541,10 @@ ${t.slots} <div id="se-grip" role="separator" aria-orientation="horizontal" a
|
|
|
541
541
|
<span id="se-st-pos"></span>
|
|
542
542
|
<span id="se-st-kind"></span>
|
|
543
543
|
<span id="se-announce" class="sr-only" aria-live="polite"></span>
|
|
544
|
-
</footer>`;function Mf(t,e,n){let s=n.features,r=n.kit,o=n.words,i=n.load,a=!!e.watch,l=e.host??{},c={get:m=>{try{return e.storage?.get(m)??null}catch{return null}},set:(m,O)=>{try{e.storage?.set(m,O)}catch{}}},d=z("div",{class:o.rootClass,"data-view":"both"}),u=document.createElement("template");u.innerHTML=n.sprite??"";let f=document.createElement("template");f.innerHTML=wm(o),d.append(u.content,f.content),t.append(d),pr(d);let p=m=>d.querySelector(`#se-${m}`),g=[],h=(m,O,L,G)=>{m.addEventListener(O,L,G),g.push(()=>m.removeEventListener(O,L,G))};h(d,"focusin",()=>pr(d)),h(d,"pointerdown",()=>pr(d));let b={problems:[],lifetimes:new Map,read:void 0,plan:void 0,view:a?"canvas":c.get(Yo.view)??"both",theme:e.theme??(l.themeControls?c.get("theme")??"system":"system"),density:l.themeControls?c.get("density")??"comfortable":"comfortable",readOnly:!!e.readOnly||!s.edit,problemsOpen:!1,problemsSeen:0,checks:0};l.brand&&(d.querySelector('[data-se="brand"]').hidden=!1);for(let m of l.titleStart??[])d.querySelector('[data-se="title-start"]').append(m);p("save").hidden=!e.onSave,p("theme").hidden=p("density").hidden=!l.themeControls;let k=new Ur;for(let m of["apply","undo","redo"]){let O=k[m].bind(k);k[m]=(...L)=>b.readOnly?(fe("This file is read-only here","warn"),!1):O(...L)}let v=()=>s.text?s.text.textPane(p("code"),k,{onOpen:m=>l.onOpen?.(m),onSave:()=>{me()},onSaveAs:()=>l.onSaveAs?.()}):vm(),M=v(),x=m=>!!m?.closest?.(".monaco-editor, #se-code"),T=s.edit?s.edit.clipboard(k,(m,O)=>fe(m,O)):{items:()=>[],attach:()=>()=>{}},y=il(p("outline"),k,{kit:n.tree,clipItems:()=>T.items(),nav:()=>r.nav(k.text),problems:()=>b.problems,role:()=>r.role(k.text),lifetimes:()=>b.lifetimes,showInText:m=>C(m),note:(m,O)=>fe(m,O)}),A=s.edit?s.edit.propsPanel(p("sel-body"),k,{nav:()=>r.nav(k.text),problems:()=>b.problems,read:()=>b.read,note:(m,O)=>fe(m,O),showInText:m=>C(m),now:m=>Be?.now?.(m)}):{paint:()=>{},dispose:()=>{}},D=()=>{p("st-sel").textContent=k.selection.length>1?`${k.selection.length} selected`:"",A.paint()};k.onSelect(D);let K=s.canvas?s.canvas.canvasView(p("canvas"),k,{problems:()=>b.problems,note:(m,O)=>fe(m,O),showInText:m=>C(m),showInTree:m=>{p("tab-outline").click(),k.select([m],"menu"),y.focus()},onZoom:m=>{p("st-zoom").textContent=`${m}%`},onHint:m=>{p("st-hint").textContent=m},clipItems:()=>T.items(),store:c,...n.canvasOpts?.(()=>Be.api)}):km(n.noCanvas);g.push(T.attach(d,m=>!!m?.closest?.("#se-outline, .canvas, #se-sel-body")));function C(m){b.view==="canvas"&&$("both",!0),M.goTo(m)}let _=d.querySelector(".side-tabs");for(let m of l.sideTabs??[]){let O=z("button",{class:"seg",type:"button",role:"tab",id:`se-tab-${m.id}`,"aria-controls":m.panel.id,"aria-selected":"false"}),L=document.createElementNS("http://www.w3.org/2000/svg","svg");L.setAttribute("class","icon"),L.setAttribute("aria-hidden","true");let G=document.createElementNS("http://www.w3.org/2000/svg","use");G.setAttribute("href",`#se-i-${m.icon}`),L.append(G),O.append(L,m.label),_.append(O),m.panel.setAttribute("role","tabpanel"),m.panel.setAttribute("aria-labelledby",O.id),m.panel.hidden=!0,d.querySelector("nav.side").append(m.panel)}_.hidden=!(l.sideTabs??[]).length;for(let m of _.querySelectorAll('[role="tab"]'))h(m,"click",()=>{for(let O of _.querySelectorAll('[role="tab"]')){let L=O===m;O.setAttribute("aria-selected",String(L)),O.classList.toggle("active",L),d.querySelector(`#${O.getAttribute("aria-controls")}`).hidden=!L}c.set("tab",m.id)});c.get("tab")&&c.get("tab")!=="se-tab-outline"&&d.querySelector(`#${c.get("tab")}`)?d.querySelector(`#${c.get("tab")}`).click():p("tab-outline").classList.add("active");let S=b.view;function $(m,O=!1){O&&(S=m,a||c.set(Yo.view,m)),s.text?s.canvas||(m="text"):m="canvas",b.view=m,d.dataset.view=m;for(let L of d.querySelectorAll("#se-views .seg"))L.setAttribute("aria-pressed",String(L.dataset.v===m));M.editor.layout()}for(let m of d.querySelectorAll("#se-views .seg"))h(m,"click",()=>$(m.dataset.v,!0));let w=m=>{d.classList.toggle("side-open",m),p("tree").setAttribute("aria-expanded",String(m)),p("tree").setAttribute("aria-label",m?"Hide the outline":"Show the outline"),p("scrim").hidden=!m};h(p("tree"),"click",()=>w(!d.classList.contains("side-open"))),h(p("scrim"),"click",()=>w(!1)),h(d,"keydown",m=>{m.key==="Escape"&&d.classList.contains("side-open")&&!m.target.closest?.("dialog, .menu")&&(w(!1),p("tree").focus())});{let m=new ResizeObserver(()=>{d.classList.contains("side-open")&&d.clientWidth>760&&w(!1)});m.observe(d),g.push(()=>m.disconnect())}function N(m,O,L,G,Z){let Se=p(m),ue=c.get(O);ue&&d.style.setProperty(O,`${ue}px`);let Ke=()=>parseFloat(getComputedStyle(d).getPropertyValue(O))||(L==="left"?260:280),Ye=Ie=>{let De=Math.round(Math.min(Z,Math.max(G,Ie)));d.style.setProperty(O,`${De}px`),c.set(O,String(De))};h(Se,"pointerdown",Ie=>{Se.setPointerCapture(Ie.pointerId);let De=Ie.clientX,Ce=Ke(),vt=kt=>Ye(L==="left"?Ce+kt.clientX-De:Ce-(kt.clientX-De)),Mn=()=>{Se.removeEventListener("pointermove",vt),Se.removeEventListener("pointerup",Mn)};Se.addEventListener("pointermove",vt),Se.addEventListener("pointerup",Mn)}),h(Se,"keydown",Ie=>{let De=Ie.key==="ArrowLeft"?-16:Ie.key==="ArrowRight"?16:0;De&&(Ye(Ke()+(L==="left"?De:-De)),Ie.preventDefault())})}N("side-grip","--side-w","left",180,520),N("right-grip","--right-w","right",200,520),N("work-grip","--canvas-w","left",240,1600);let F=m=>{d.classList.toggle("no-right",!m),p("panel").setAttribute("aria-pressed",String(m)),c.set("panel",m?"1":"0")};F(c.get("panel")!=="0"),h(p("panel"),"click",()=>F(d.classList.contains("no-right")));let J=matchMedia("(prefers-color-scheme: dark)"),ae=()=>b.theme==="dark"||b.theme==="system"&&J.matches;function we(){d.style.colorScheme=b.theme==="system"?"light dark":b.theme,b.theme==="system"?delete d.dataset.theme:d.dataset.theme=b.theme,b.density==="compact"?d.dataset.density="compact":delete d.dataset.density,M.setTheme(ae()),K.setTheme(ae()?"dark":"light");for(let m of d.querySelectorAll("#se-theme .seg"))m.setAttribute("aria-pressed",String(m.dataset.v===b.theme));p("density").setAttribute("aria-pressed",String(b.density==="compact"))}h(J,"change",()=>{b.theme==="system"&&we()});let j=m=>{b.theme=m,l.themeControls&&c.set("theme",m),we()},U=m=>{b.density=m,c.set("density",m),we()};for(let m of d.querySelectorAll("#se-theme .seg"))h(m,"click",()=>j(m.dataset.v));h(p("density"),"click",()=>U(b.density==="compact"?"comfortable":"compact"));let ee=0;function fe(m,O="info"){let L=p("note");L.className=`callout compact ${O==="info"?"":O}`,L.querySelector(".c-body").textContent=m,L.hidden=!1,clearTimeout(ee),ee=window.setTimeout(()=>{L.hidden=!0},6e3)}function B(m,O){let L=p("filebar");L.querySelector(".c-body").replaceChildren(...m),L.querySelector(".c-acts").replaceChildren(...O.map(Z=>{let Se=z("button",{type:"button",class:`btn sm${Z.primary?" primary":""}`},Z.label);return Se.addEventListener("click",Z.run),Se})),L.hidden=!1}let X=()=>{p("filebar").hidden=!0},Q=()=>k.dirty,te=!1;function ne(){p("save").disabled=!Q()||b.readOnly,Q()!==te&&(te=Q(),e.onDirtyChange?.(te))}async function me(){if(!e.onSave||b.readOnly)return!1;if(!Q())return!0;let m=k.text;k.seal();let O;try{O=await e.onSave(m)}catch(L){return fe(`Not saved: ${L.message??L}`,"bad"),!1}return"conflict"in O?l.onConflict?(l.onConflict(),!1):(B([z("span",{class:"c-title"},"Changed elsewhere."),z("span",null," This file changed outside the editor since it was loaded, so it wasn't saved.")],[{label:"Dismiss",run:X}]),!1):(k.text===m&&k.markClean(),X(),ne(),!0)}h(p("save"),"click",()=>{me()});let ye=l.keymap?sl(r.keymap,l.keymap):r.keymap,xe=()=>rl(ye);h(p("keys"),"click",()=>xe()),h(d,"keydown",m=>{let O=m.target;if(m.key==="?"&&!m.metaKey&&!m.ctrlKey&&!m.altKey){if(O.closest?.("input, textarea, select, .monaco-editor, #se-code, [contenteditable], dialog"))return;m.preventDefault(),xe();return}if(l.keys?.(m)||!(m.metaKey||m.ctrlKey)||m.altKey||x(m.target))return;let L=m.key.toLowerCase();L==="s"&&!m.shiftKey?(m.preventDefault(),me()):L==="z"&&!m.shiftKey?(k.undo(),m.preventDefault()):(L==="z"&&m.shiftKey||L==="y")&&(k.redo(),m.preventDefault())});let Re=m=>r.objectPath(m,b.read),Ue=()=>s.plan?s.plan.planPanel(p("plan"),{has:m=>!!Re(m),select:m=>{let O=Re(m);return O?(k.select([nt(O)],"menu"),!0):!1}}):{paint:()=>{}},I=Ue(),re=c.get("bottom-tab")??"problems";function $e(m){re=m,c.set("bottom-tab",m);for(let O of d.querySelectorAll('.bottom-tabs [role="tab"]')){let L=O.id===`se-tab-${m}`;O.setAttribute("aria-selected",String(L)),O.classList.toggle("active",L)}p("problems-list").hidden=m!=="problems",p("plan").hidden=m!=="plan",p("problems-toggle").setAttribute("aria-controls",m==="plan"?"se-plan":"se-problems-list")}for(let m of d.querySelectorAll('.bottom-tabs [role="tab"]'))h(m,"click",()=>{$e(m.id==="se-tab-plan"?"plan":"problems"),Ee(!0,!1)});function Pe(){I.paint(b.plan,n.hasExtra);let m=r.extraLabel(b.plan);p("plan-label").textContent=m.text,p("plan-label").className=`plan-label ${m.cls}`}let be=0,ce=!1;async function ze(){clearTimeout(be);let m=k.text,O=k.version,L=await r.check(m,b.plan,fe);ce||k.version!==O||(b.plan=L.extra,b.problems=L.problems,b.read=L.read,b.lifetimes=L.tags,b.checks++,M.setProblems(b.problems.filter(G=>!G.file)),it(),Pe(),y.paint(),D(),K.render(L.model,L.data))}g.push(k.on(()=>{ne(),Oe(),clearTimeout(be),be=window.setTimeout(()=>{ze()},150)}));function Oe(){let m=p("undo"),O=p("redo");m.disabled=!k.canUndo||b.readOnly,O.disabled=!k.canRedo||b.readOnly,m.title=k.canUndo?`Undo ${k.undoLabel} (\u2318Z)`:"Nothing to undo",O.title=k.canRedo?`Redo ${k.redoLabel} (\u21E7\u2318Z)`:"Nothing to redo",m.setAttribute("aria-label",m.title),O.setAttribute("aria-label",O.title)}h(p("undo"),"click",()=>{k.undo(),M.focus()}),h(p("redo"),"click",()=>{k.redo(),M.focus()});function Ee(m,O){O&&!b.problems.length&&!Be?.attention?.()?.count&&re==="problems"&&(m=!1),b.problemsOpen=m,p("problems").classList.toggle("collapsed",!m),p("problems-toggle").setAttribute("aria-expanded",String(m)),M.editor.layout()}h(p("problems-toggle"),"click",()=>Ee(!b.problemsOpen,!0));let Be;function it(){let m=p("problems-list");m.replaceChildren();let O=b.problems.filter(ue=>ue.severity==="error").length,L=b.problems.length-O;p("problems-label").textContent=b.problems.length?`Problems \xB7 ${O} error${O===1?"":"s"}, ${L} warning${L===1?"":"s"}`:"No problems";let G=b.problemsSeen,Z=Be?.attention?.();b.problemsSeen=b.problems.length+(Z?.count??0);let Se=Z?.opens??0;Z?.still&&!b.problems.length?Ee(b.problemsOpen,!1):!b.problems.length&&!Se&&re==="problems"?Ee(!1,!1):(b.problems.length||Se)&&!G?Ee(!0,!1):Ee(b.problemsOpen,!1),p("st-problems").textContent=`${O} \u2715 ${L} \u26A0`,p("st-problems").className=O?"bad":L?"warn":"ok",Z?.rows.length&&(m.append(...Z.rows),b.problems.length&&m.append(z("div",{class:"prob-head"},"In the file"))),p("problems-label").textContent=(b.problems.length?p("problems-label").textContent:Z?.count?"":"No problems")+(Z?.count?`${b.problems.length?" \xB7 ":""}${Z.label}`:"");for(let ue of b.problems){let Ke=z("button",{type:"button",class:`prob ${ue.severity}${ue.file?" other-file":""}`},z("span",{class:"where"},ue.file?`${ue.file} \xB7 line ${ue.startLine}`:`${ue.startLine}:${ue.startCol}`),z("span",{class:"msg"},ue.message),ue.hint?z("span",{class:"hint"},ue.hint):null);ue.file?Ke.title=`In ${ue.file}, line ${ue.startLine}: not in this file`:Ke.addEventListener("click",()=>M.goToOffset(el(k.text,ue)[0])),m.append(Ke)}}let We=0,Ne=()=>{We||(We=requestAnimationFrame(()=>{We=0;let m=M.caret();p("st-pos").textContent=m?`Ln ${m.line}, Col ${m.col}`:""}))},gt=qs(()=>Ze());function Ze(){let m=M.pathAtCaret();p("st-path").textContent=m.length?m.join(" \u203A "):"",p("st-path").title=Me(m),p("st-kind").textContent=r.kindLabel(k.text)}let ft=()=>M.onCaret(()=>{Ne(),gt()});ft(),g.push(k.on(m=>{Ne(),Ys(m)?gt():gt.now()}));{let m=p("grip"),O=G=>{let Z=Math.min(Math.max(p("problems").getBoundingClientRect().height-G,48),innerHeight*.6);d.style.setProperty("--problems-h",`${Z}px`),c.set("problems-h",String(Math.round(Z)))},L=c.get("problems-h");L&&d.style.setProperty("--problems-h",`${L}px`),h(m,"pointerdown",G=>{m.setPointerCapture(G.pointerId);let Z=G.clientY,Se=Ke=>{O(Ke.clientY-Z),Z=Ke.clientY},ue=()=>{m.removeEventListener("pointermove",Se),m.removeEventListener("pointerup",ue)};m.addEventListener("pointermove",Se),m.addEventListener("pointerup",ue)}),h(m,"keydown",G=>{G.key==="ArrowUp"&&(O(-16),G.preventDefault()),G.key==="ArrowDown"&&(O(16),G.preventDefault())})}Be=n.part?.({root:d,byId:p,doc:k,store:c,note:fe,watch:a,on:(m,O,L)=>h(m,O,L),disposed:()=>ce,paintProblems:()=>it(),paintProps:()=>A.paint()},{canvas:()=>K,objectPath:Re});function ot(m){m=m||!s.edit,b.readOnly=m,d.classList.toggle("read-only",m),p("ro").hidden=!m,M.setReadOnly(m),ne(),Oe()}function at(){p("views").hidden=!(s.text&&s.canvas),p("right").hidden=p("right-grip").hidden=!s.edit,p("tab-plan").hidden=!s.plan,d.dataset.features=Object.keys(s).sort().join(" ")}!s.plan&&re==="plan"&&(re="problems"),$e(re),at(),$(b.view),we(),ot(b.readOnly),k.load(e.text??""),Be?.start?.(),ne(),Oe();let E=n.late,Y=Promise.resolve();async function q(m){let O=m.filter(G=>!n.names.includes(G));if(O.length)throw new Error(`unknown feature ${O.join(", ")}: the features are ${n.names.join(", ")}`);let L=Y.then(async()=>{if(ce)throw new Error("the editor was disposed");let G=[...new Set(m)].filter(Ke=>!s[Ke]);if(!G.length)return;let Z=G.filter(Ke=>!E.includes(Ke));if(Z.length)throw new Error(`${Z.join(", ")} can't be added to a mounted editor (only ${E.join(" and ")} can): mount with ${Z.length>1?"them":"it"}`);if(!i)throw new Error(`this build has no loader for ${G.join(", ")}: mount with ${G.length>1?"them":"it"}`);let Se=await i(G);if(ce)throw new Error("the editor was disposed");let ue=k.selection.slice();for(let Ke of Se)s[Ke.name]=Ke;G.includes("text")&&(M.dispose(),M=v(),ft(),M.setReadOnly(b.readOnly),M.setProblems(b.problems.filter(Ke=>!Ke.file)),we(),ue.length&&k.select(ue,"menu")),G.includes("plan")&&(I=Ue(),Pe()),at(),$(S),Ze()});return Y=L.catch(()=>{}),L}let de={root:d,doc:k,get pane(){return M},tree:y,canvas:K,props:A,clip:T,state:b,check:ze,save:me,note:fe,setView:$,showBanner:B,hideBanner:X,keySheet:xe,setTheme:j,setDensity:U,setBottomTab:$e,markers:()=>M.monaco.editor.getModelMarkers({resource:M.model.uri}).map(O=>({severity:O.severity,message:O.message,line:O.startLineNumber,col:O.startColumn,endCol:O.endColumn}))};return n.internal&&Object.defineProperties(de,Object.getOwnPropertyDescriptors(n.internal)),Be&&Object.defineProperties(de,Object.getOwnPropertyDescriptors(Be.api)),{internal:de,getText:()=>k.text,setText(m){X(),k.load(m),k.markClean(),ne(),Oe()},setReadOnly:ot,setTheme:j,addFeatures:q,fit(){ce||K.fit()},dispose(){if(!ce){ce=!0,clearTimeout(be),clearTimeout(ee),Be?.dispose?.(),cancelAnimationFrame(We),gt.cancel(),nl();for(let m of g.splice(0))m();y.dispose(),A.dispose(),K.dispose(),M.dispose(),d.remove(),pr(null)}}}}function vm(){let t=()=>{};return{setTheme:t,setReadOnly:t,setProblems:t,goTo:t,goToOffset:t,focus:t,dispose:t,onCaret:t,caret:()=>{},pathAtCaret:()=>[],editor:{layout:t,focus:t},model:void 0,monaco:void 0,resyncs:()=>0}}function km(t={}){let e={palette:void 0,doc:void 0,stage:void 0,...t};return new Proxy({},{get:(n,s)=>s in e?e[s]:()=>{}})}var $f=1;function Ef(t,e){return!!t&&typeof t=="object"&&t.v===1&&e.includes(t.type)}var Zr={"arrow-up-right":'<path d="M7 7h10v10" /> <path d="M7 17 17 7" />',box:'<path d="M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z" /> <path d="m3.3 7 8.7 5 8.7-5" /> <path d="M12 22V12" />',"chevron-down":'<path d="m6 9 6 6 6-6" />',"chevron-right":'<path d="m9 18 6-6-6-6" />',"circle-dot":'<circle cx="12" cy="12" r="1" /> <circle cx="12" cy="12" r="10" />',"circle-x":'<circle cx="12" cy="12" r="10" /> <path d="m15 9-6 6" /> <path d="m9 9 6 6" />',clipboard:'<rect width="8" height="4" x="8" y="2" rx="1" ry="1" /> <path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2" />',"clipboard-paste":'<path d="M11 14h10" /> <path d="M16 4h2a2 2 0 0 1 2 2v1.344" /> <path d="m17 18 4-4-4-4" /> <path d="M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 1.793-1.113" /> <rect x="8" y="2" width="8" height="4" rx="1" />',"code-xml":'<path d="m18 16 4-4-4-4" /> <path d="m6 8-4 4 4 4" /> <path d="m14.5 4-5 16" />',copy:'<rect width="14" height="14" x="8" y="8" rx="2" ry="2" /> <path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" />',layers:'<path d="M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z" /> <path d="M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12" /> <path d="M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17" />',link:'<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" /> <path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" />',list:'<path d="M3 5h.01" /> <path d="M3 12h.01" /> <path d="M3 19h.01" /> <path d="M8 5h13" /> <path d="M8 12h13" /> <path d="M8 19h13" />',"list-tree":'<path d="M8 5h13" /> <path d="M13 12h8" /> <path d="M13 19h8" /> <path d="M3 10a2 2 0 0 0 2 2h3" /> <path d="M3 5v12a2 2 0 0 0 2 2h3" />',"panel-right":'<rect width="18" height="18" x="3" y="3" rx="2" /> <path d="M15 3v18" />',pencil:'<path d="M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z" /> <path d="m15 5 4 4" />',plus:'<path d="M5 12h14" /> <path d="M12 5v14" />',"rotate-ccw":'<path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" /> <path d="M3 3v5h5" />',"trash-2":'<path d="M10 11v6" /> <path d="M14 11v6" /> <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" /> <path d="M3 6h18" /> <path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />',"triangle-alert":'<path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3" /> <path d="M12 9v4" /> <path d="M12 17h.01" />',x:'<path d="M18 6 6 18" /> <path d="m6 6 12 12" />'},Tf=Object.keys(Zr),Wo=t=>Object.entries(t).map(([e,n])=>`<symbol id="se-i-${e}" viewBox="0 0 24 24">${n}</symbol>`).join(""),Jo=t=>`<svg xmlns="http://www.w3.org/2000/svg" class="sprite" aria-hidden="true" focusable="false">${t}</svg>`,Af=Jo(Wo(Zr));var Sm=/^[a-z][a-z0-9-]*$/,Qc={rootClass:"iso-editor",brand:"iso <b>editor</b>",sideLabel:"The file",canvasLabel:"The file, drawn",problemsLabel:"Problems",bottomTabsLabel:"Problems",extraTab:"Check",slots:""},ul=[{where:"Anywhere in the editor",keys:[["\u2318S","Save"],["\u2318Z","Undo"],["\u21E7\u2318Z or \u2318Y","Redo"],["?","This sheet"],["Esc","Close a menu or dialog"]]},{where:"The tree and the canvas",keys:[["F2","Rename"],["\u232B","Delete"],["\u2318D","Duplicate"],["\u2318\u2191","Select the parent"]]},{where:"The canvas",keys:[["+ \u2212","Zoom"],["0","Fit"],["1","100%"],["\u21E72","Zoom to the selection"]]}];function Pf(t,e,n){let s=Xr(t),r=e.nameRule??Sm,o=e.nameHint??"a lower-case letter, then lower-case letters, digits and -",i=e.icon??(()=>"box"),a=al({commands:s,objectOf:t.objectOf,kinds:t.kinds,nameRule:r,nameHint:o}),l=Qa(t),c={docFor:Xa,completionAt:l.completionAt,hoverAt:l.hoverAt,definitionAt:l.definitionAt,rangeOfPath:Za},d=(x,T)=>T.reduce((y,A)=>y&&typeof y=="object"?y[A]:void 0,x),u=(x,T)=>d(x,[T,"layout"]),f={key:t.pins.key,legacyKey:t.pins.legacyKey,legacyOnly:t.pins.legacyOnly,of:x=>u(x,t.pins.key)??(t.pins.legacyKey?u(x,t.pins.legacyKey):void 0),keyOf:x=>t.pins.legacyOnly(x)&&t.pins.legacyKey?t.pins.legacyKey:t.pins.key},p=(x,T=e.fileName)=>t.read(x,{fileName:T,role:t.role(x)}),g={outline:(x,T,y)=>Wa(x,t,T,y),commands:s,slotAt:t.slotAt,kinds:t.kinds,entryGroups:t.entryGroups,nameRule:r,ui:{label:"The file, as a tree",rootIcon:"layers",kindIcon:i,keyIcon:()=>{},entryIcon:()=>"list-tree",newItems:x=>[{label:`New ${t.kinds.find(y=>y.kind===x).singular}`,icon:i(x)}],tagPill:x=>({title:x}),nameHint:o,text:{root:"File",rootAdd:"the file",renameWhy:"Groups and the file itself have fixed names",deleteWhy:"The file itself stays",duplicateNote:"Duplicate works on objects",duplicateWhy:"Only objects can be duplicated"}}},h={commands:s,actions:a,slotAt:t.slotAt,objectOf:t.objectOf,kinds:t.kinds,ui:{important:()=>[],isExternal:()=>!1,inheritedFrom:"the base file",extensionDoc:"An extension: ignored by the reader.",rootTitle:"The file",rootItem:"(the file)"}},b={rootClass:"iso-canvas",panKeyClass:"pan-key",newOrder:t.kinds.map(x=>x.kind),palette:e.palette?e.palette.map(x=>({kind:x.kind,label:x.label,icon:x.icon??i(x.kind),name:x.name,...x.value===void 0?{}:{value:()=>structuredClone(x.value)}})):t.kinds.map(x=>({kind:x.kind,icon:i(x.kind),label:x.singular[0].toUpperCase()+x.singular.slice(1)})),text:{stage:"The file, drawn: arrow keys and Tab move through what is drawn; + and \u2212 zoom, 0 fits",dragGroup:"A drag on nothing",dragSelectTip:"Drag draws a selection; hold the space key to pan",unreadable:"The canvas draws a file that reads cleanly; fix the problems listed to see it.",palette:"Add to the file: click, or drag onto the canvas",pinHint:"",renameWhy:"Only objects are renamed here",duplicateWhy:"Only objects are duplicated"}},k={draw:e.draw,catalog:e.catalog,objectOf:t.objectOf,kinds:t.kinds,commands:s,actions:a,objectItems:()=>[],pins:f,ui:b,flat:e.flat,...t.connect?{connect:(x,T,y)=>t.connect(x,T,y)}:{},...t.group?{group:(x,T)=>t.group(x,T)}:{},...t.dropInto?{dropOnto:(x,T,y,A)=>t.dropInto(x,T,y,A)}:{},trial:(x,T)=>{let y=p(x);return y.read===void 0||y.diags.some(A=>A.severity==="error")?void 0:e.draw(y.read,y.read.data,T)}},v={async check(x){let T=Ja(t,x,{fileName:e.fileName}),y=!T.problems.some(A=>A.severity==="error")&&T.read!==void 0;return{problems:T.problems,read:T.read,tags:T.tags,model:y?T.read:void 0,data:T.read?.data,extra:void 0}},role:x=>t.role(x),kindLabel:()=>t.id,nav:l.navFor,objectPath(x,T){let y=T?.data;for(let A of t.kinds)if(d(y,[...A.section,x])!==void 0)return Me([...A.section,x])},extraLabel:()=>({text:"",cls:""}),keymap:e.keymap??(t.group?ul.map(x=>x.where==="The tree and the canvas"?{...x,keys:[...x.keys,["\u2318G","Group the selection"]]}:x):ul)},M={canvas:{canvasView:(x,T,y)=>dl(x,T,{...y,theme:e.theme,kit:k,layer:e.layer})},edit:{propsPanel:(x,T,y)=>cl(x,T,{...y,kit:h}),clipboard:(x,T)=>ol(x,T,qa(t))},...n?{text:{textPane:(x,T,y)=>n(x,T,{...y,services:c})}}:{}};return{kit:v,tree:g,words:{...Qc,...e.words},features:M,names:["text","canvas","edit"],late:["text"],hasExtra:!1,part:e.part?x=>e.part(x):void 0,sprite:Jo(Wo({...Zr,...e.icons}))}}function Mm(t){let e=[],n=t.replace(/\/\*[\s\S]*?\*\//g,""),s=0;for(;s<n.length;){let r=n.indexOf("{",s),o=n.indexOf(";",s);if(r<0&&o<0)break;if(o>=0&&(r<0||o<r)){let l=n.slice(s,o).trim();l&&e.push([l,null]),s=o+1;continue}let i=1,a=r+1;for(;a<n.length&&i;)n[a]==="{"?i++:n[a]==="}"&&i--,a++;e.push([n.slice(s,r).trim(),n.slice(r+1,a-1)]),s=a}return e}function $m(t){let e=[],n=0,s=0;for(let r=0;r<t.length;r++){let o=t[r];o==="("||o==="["?n++:o===")"||o==="]"?n--:o===","&&!n&&(e.push(t.slice(s,r).trim()),s=r+1)}return e.push(t.slice(s).trim()),e.filter(Boolean)}function Zc(t,e){let n=`.${e}`,s=/^(?:html|body|:root)((?:\[[^\]]*\]|\.[\w-]+|:not\([^)]*\))*)(.*)$/.exec(t);return s&&/^(html|body|:root)(?![\w-])/.test(t)?`${n}${s[1]}${s[2].trim()?" "+s[2].trim():""}`:t==="*"?`${n}, ${n} *`:`${n} ${t}`}function ed(t,e){let n="";for(let[s,r]of Mm(t)){if(r===null){(s.startsWith("@layer")||s.startsWith("@import"))&&(n+=`${s};
|
|
544
|
+
</footer>`;function Uf(t,e,n){let s=n.features,r=n.kit,o=n.words,i=n.load,a=!!e.watch,l=e.host??{},c={get:m=>{try{return e.storage?.get(m)??null}catch{return null}},set:(m,C)=>{try{e.storage?.set(m,C)}catch{}}},d=K("div",{class:o.rootClass,"data-view":"both"}),u=document.createElement("template");u.innerHTML=n.sprite??"";let f=document.createElement("template");f.innerHTML=Hm(o),d.append(u.content,f.content),t.append(d),Mr(d);let p=m=>d.querySelector(`#se-${m}`),g=[],h=(m,C,R,G)=>{m.addEventListener(C,R,G),g.push(()=>m.removeEventListener(C,R,G))};h(d,"focusin",()=>Mr(d)),h(d,"pointerdown",()=>Mr(d));let b={problems:[],lifetimes:new Map,read:void 0,plan:void 0,view:a?"canvas":c.get(ii.view)??"both",theme:e.theme??(l.themeControls?c.get("theme")??"system":"system"),density:l.themeControls?c.get("density")??"comfortable":"comfortable",readOnly:!!e.readOnly||!s.edit,problemsOpen:!1,problemsSeen:0,checks:0};l.brand&&(d.querySelector('[data-se="brand"]').hidden=!1);for(let m of l.titleStart??[])d.querySelector('[data-se="title-start"]').append(m);p("save").hidden=!e.onSave,p("theme").hidden=p("density").hidden=!l.themeControls;let v=new oo;for(let m of["apply","undo","redo"]){let C=v[m].bind(v);v[m]=(...R)=>b.readOnly?(ue("This file is read-only here","warn"),!1):C(...R)}let w=()=>s.text?s.text.textPane(p("code"),v,{onOpen:m=>l.onOpen?.(m),onSave:()=>{fe()},onSaveAs:()=>l.onSaveAs?.()}):Ym(),M=w(),y=m=>!!m?.closest?.(".monaco-editor, #se-code"),T=s.edit?s.edit.clipboard(v,(m,C)=>ue(m,C)):{items:()=>[],attach:()=>()=>{}},S=Sl(p("outline"),v,{kit:n.tree,clipItems:()=>T.items(),nav:()=>r.nav(v.text),problems:()=>b.problems,role:()=>r.role(v.text),lifetimes:()=>b.lifetimes,showInText:m=>O(m),note:(m,C)=>ue(m,C)}),P=s.edit?s.edit.propsPanel(p("sel-body"),v,{nav:()=>r.nav(v.text),problems:()=>b.problems,read:()=>b.read,note:(m,C)=>ue(m,C),showInText:m=>O(m),now:m=>je?.now?.(m)}):{paint:()=>{},dispose:()=>{}},I=()=>{p("st-sel").textContent=v.selection.length>1?`${v.selection.length} selected`:"",P.paint()};v.onSelect(I);let _=s.canvas?s.canvas.canvasView(p("canvas"),v,{problems:()=>b.problems,note:(m,C)=>ue(m,C),showInText:m=>O(m),showInTree:m=>{p("tab-outline").click(),v.select([m],"menu"),S.focus()},onZoom:m=>{p("st-zoom").textContent=`${m}%`},onHint:m=>{p("st-hint").textContent=m},clipItems:()=>T.items(),store:c,...n.canvasOpts?.(()=>je.api)}):qm(n.noCanvas);g.push(T.attach(d,m=>!!m?.closest?.("#se-outline, .canvas, #se-sel-body")));function O(m){b.view==="canvas"&&$("both",!0),M.goTo(m)}let j=d.querySelector(".side-tabs");for(let m of l.sideTabs??[]){let C=K("button",{class:"seg",type:"button",role:"tab",id:`se-tab-${m.id}`,"aria-controls":m.panel.id,"aria-selected":"false"}),R=document.createElementNS("http://www.w3.org/2000/svg","svg");R.setAttribute("class","icon"),R.setAttribute("aria-hidden","true");let G=document.createElementNS("http://www.w3.org/2000/svg","use");G.setAttribute("href",`#se-i-${m.icon}`),R.append(G),C.append(R,m.label),j.append(C),m.panel.setAttribute("role","tabpanel"),m.panel.setAttribute("aria-labelledby",C.id),m.panel.hidden=!0,d.querySelector("nav.side").append(m.panel)}j.hidden=!(l.sideTabs??[]).length;for(let m of j.querySelectorAll('[role="tab"]'))h(m,"click",()=>{for(let C of j.querySelectorAll('[role="tab"]')){let R=C===m;C.setAttribute("aria-selected",String(R)),C.classList.toggle("active",R),d.querySelector(`#${C.getAttribute("aria-controls")}`).hidden=!R}c.set("tab",m.id)});c.get("tab")&&c.get("tab")!=="se-tab-outline"&&d.querySelector(`#${c.get("tab")}`)?d.querySelector(`#${c.get("tab")}`).click():p("tab-outline").classList.add("active");let k=b.view;function $(m,C=!1){C&&(k=m,a||c.set(ii.view,m)),s.text?s.canvas||(m="text"):m="canvas",b.view=m,d.dataset.view=m;for(let R of d.querySelectorAll("#se-views .seg"))R.setAttribute("aria-pressed",String(R.dataset.v===m));M.editor.layout()}for(let m of d.querySelectorAll("#se-views .seg"))h(m,"click",()=>$(m.dataset.v,!0));let x=m=>{d.classList.toggle("side-open",m),p("tree").setAttribute("aria-expanded",String(m)),p("tree").setAttribute("aria-label",m?"Hide the outline":"Show the outline"),p("scrim").hidden=!m};h(p("tree"),"click",()=>x(!d.classList.contains("side-open"))),h(p("scrim"),"click",()=>x(!1)),h(d,"keydown",m=>{m.key==="Escape"&&d.classList.contains("side-open")&&!m.target.closest?.("dialog, .menu")&&(x(!1),p("tree").focus())});{let m=new ResizeObserver(()=>{d.classList.contains("side-open")&&d.clientWidth>760&&x(!1)});m.observe(d),g.push(()=>m.disconnect())}function N(m,C,R,G,Z){let $e=p(m),de=c.get(C);de&&d.style.setProperty(C,`${de}px`);let De=()=>parseFloat(getComputedStyle(d).getPropertyValue(C))||(R==="left"?260:280),He=Re=>{let ze=Math.round(Math.min(Z,Math.max(G,Re)));d.style.setProperty(C,`${ze}px`),c.set(C,String(ze))};h($e,"pointerdown",Re=>{$e.setPointerCapture(Re.pointerId);let ze=Re.clientX,nt=De(),st=Pt=>He(R==="left"?nt+Pt.clientX-ze:nt-(Pt.clientX-ze)),Ye=()=>{$e.removeEventListener("pointermove",st),$e.removeEventListener("pointerup",Ye)};$e.addEventListener("pointermove",st),$e.addEventListener("pointerup",Ye)}),h($e,"keydown",Re=>{let ze=Re.key==="ArrowLeft"?-16:Re.key==="ArrowRight"?16:0;ze&&(He(De()+(R==="left"?ze:-ze)),Re.preventDefault())})}N("side-grip","--side-w","left",180,520),N("right-grip","--right-w","right",200,520),N("work-grip","--canvas-w","left",240,1600);let F=m=>{d.classList.toggle("no-right",!m),p("panel").setAttribute("aria-pressed",String(m)),c.set("panel",m?"1":"0")};F(c.get("panel")!=="0"),h(p("panel"),"click",()=>F(d.classList.contains("no-right")));let J=matchMedia("(prefers-color-scheme: dark)"),oe=()=>b.theme==="dark"||b.theme==="system"&&J.matches;function ve(){d.style.colorScheme=b.theme==="system"?"light dark":b.theme,b.theme==="system"?delete d.dataset.theme:d.dataset.theme=b.theme,b.density==="compact"?d.dataset.density="compact":delete d.dataset.density,M.setTheme(oe()),_.setTheme(oe()?"dark":"light");for(let m of d.querySelectorAll("#se-theme .seg"))m.setAttribute("aria-pressed",String(m.dataset.v===b.theme));p("density").setAttribute("aria-pressed",String(b.density==="compact"))}h(J,"change",()=>{b.theme==="system"&&ve()});let B=m=>{b.theme=m,l.themeControls&&c.set("theme",m),ve()},W=m=>{b.density=m,c.set("density",m),ve()};for(let m of d.querySelectorAll("#se-theme .seg"))h(m,"click",()=>B(m.dataset.v));h(p("density"),"click",()=>W(b.density==="compact"?"comfortable":"compact"));let ee=0;function ue(m,C="info"){let R=p("note");R.className=`callout compact ${C==="info"?"":C}`,R.querySelector(".c-body").textContent=m,R.hidden=!1,clearTimeout(ee),ee=window.setTimeout(()=>{R.hidden=!0},6e3)}function z(m,C){let R=p("filebar");R.querySelector(".c-body").replaceChildren(...m),R.querySelector(".c-acts").replaceChildren(...C.map(Z=>{let $e=K("button",{type:"button",class:`btn sm${Z.primary?" primary":""}`},Z.label);return $e.addEventListener("click",Z.run),$e})),R.hidden=!1}let X=()=>{p("filebar").hidden=!0},Q=()=>v.dirty,te=!1;function ne(){p("save").disabled=!Q()||b.readOnly,Q()!==te&&(te=Q(),e.onDirtyChange?.(te))}async function fe(){if(!e.onSave||b.readOnly)return!1;if(!Q())return!0;let m=v.text;v.seal();let C;try{C=await e.onSave(m)}catch(R){return ue(`Not saved: ${R.message??R}`,"bad"),!1}return"conflict"in C?l.onConflict?(l.onConflict(),!1):(z([K("span",{class:"c-title"},"Changed elsewhere."),K("span",null," This file changed outside the editor since it was loaded, so it wasn't saved.")],[{label:"Dismiss",run:X}]),!1):(v.text===m&&v.markClean(),X(),ne(),!0)}h(p("save"),"click",()=>{fe()});let be=l.keymap?wl(r.keymap,l.keymap):r.keymap,we=()=>vl(be);h(p("keys"),"click",()=>we()),h(d,"keydown",m=>{let C=m.target;if(m.key==="?"&&!m.metaKey&&!m.ctrlKey&&!m.altKey){if(C.closest?.("input, textarea, select, .monaco-editor, #se-code, [contenteditable], dialog"))return;m.preventDefault(),we();return}if(l.keys?.(m)||!(m.metaKey||m.ctrlKey)||m.altKey||y(m.target))return;let R=m.key.toLowerCase();R==="s"&&!m.shiftKey?(m.preventDefault(),fe()):R==="z"&&!m.shiftKey?(v.undo(),m.preventDefault()):(R==="z"&&m.shiftKey||R==="y")&&(v.redo(),m.preventDefault())});let Ne=m=>r.objectPath(m,b.read),qe=()=>s.plan?s.plan.planPanel(p("plan"),{has:m=>!!Ne(m),select:m=>{let C=Ne(m);return C?(v.select([rt(C)],"menu"),!0):!1}}):{paint:()=>{}},D=qe(),se=c.get("bottom-tab")??"problems";function Me(m){se=m,c.set("bottom-tab",m);for(let C of d.querySelectorAll('.bottom-tabs [role="tab"]')){let R=C.id===`se-tab-${m}`;C.setAttribute("aria-selected",String(R)),C.classList.toggle("active",R)}p("problems-list").hidden=m!=="problems",p("plan").hidden=m!=="plan",p("problems-toggle").setAttribute("aria-controls",m==="plan"?"se-plan":"se-problems-list")}for(let m of d.querySelectorAll('.bottom-tabs [role="tab"]'))h(m,"click",()=>{Me(m.id==="se-tab-plan"?"plan":"problems"),Ee(!0,!1)});function Oe(){D.paint(b.plan,n.hasExtra);let m=r.extraLabel(b.plan);p("plan-label").textContent=m.text,p("plan-label").className=`plan-label ${m.cls}`}let ge=0,ie=!1;async function Ke(){clearTimeout(ge);let m=v.text,C=v.version,R=await r.check(m,b.plan,ue);ie||v.version!==C||(b.plan=R.extra,b.problems=R.problems,b.read=R.read,b.lifetimes=R.tags,b.checks++,M.setProblems(b.problems.filter(G=>!G.file)),lt(),Oe(),S.paint(),I(),_.render(R.model,R.data))}g.push(v.on(()=>{ne(),Ce(),clearTimeout(ge),ge=window.setTimeout(()=>{Ke()},150)}));function Ce(){let m=p("undo"),C=p("redo");m.disabled=!v.canUndo||b.readOnly,C.disabled=!v.canRedo||b.readOnly,m.title=v.canUndo?`Undo ${v.undoLabel} (\u2318Z)`:"Nothing to undo",C.title=v.canRedo?`Redo ${v.redoLabel} (\u21E7\u2318Z)`:"Nothing to redo",m.setAttribute("aria-label",m.title),C.setAttribute("aria-label",C.title)}h(p("undo"),"click",()=>{v.undo(),M.focus()}),h(p("redo"),"click",()=>{v.redo(),M.focus()});function Ee(m,C){C&&!b.problems.length&&!je?.attention?.()?.count&&se==="problems"&&(m=!1),b.problemsOpen=m,p("problems").classList.toggle("collapsed",!m),p("problems-toggle").setAttribute("aria-expanded",String(m)),M.editor.layout()}h(p("problems-toggle"),"click",()=>Ee(!b.problemsOpen,!0));let je;function lt(){let m=p("problems-list");m.replaceChildren();let C=b.problems.filter(de=>de.severity==="error").length,R=b.problems.length-C;p("problems-label").textContent=b.problems.length?`Problems \xB7 ${C} error${C===1?"":"s"}, ${R} warning${R===1?"":"s"}`:"No problems";let G=b.problemsSeen,Z=je?.attention?.();b.problemsSeen=b.problems.length+(Z?.count??0);let $e=Z?.opens??0;Z?.still&&!b.problems.length?Ee(b.problemsOpen,!1):!b.problems.length&&!$e&&se==="problems"?Ee(!1,!1):(b.problems.length||$e)&&!G?Ee(!0,!1):Ee(b.problemsOpen,!1),p("st-problems").textContent=`${C} \u2715 ${R} \u26A0`,p("st-problems").className=C?"bad":R?"warn":"ok",Z?.rows.length&&(m.append(...Z.rows),b.problems.length&&m.append(K("div",{class:"prob-head"},"In the file"))),p("problems-label").textContent=(b.problems.length?p("problems-label").textContent:Z?.count?"":"No problems")+(Z?.count?`${b.problems.length?" \xB7 ":""}${Z.label}`:"");for(let de of b.problems){let De=K("button",{type:"button",class:`prob ${de.severity}${de.file?" other-file":""}`},K("span",{class:"where"},de.file?`${de.file} \xB7 line ${de.startLine}`:`${de.startLine}:${de.startCol}`),K("span",{class:"msg"},de.message),de.hint?K("span",{class:"hint"},de.hint):null);de.file?De.title=`In ${de.file}, line ${de.startLine}: not in this file`:De.addEventListener("click",()=>M.goToOffset(bl(v.text,de)[0])),m.append(De)}}let Ue=0,dt=()=>{Ue||(Ue=requestAnimationFrame(()=>{Ue=0;let m=M.caret();p("st-pos").textContent=m?`Ln ${m.line}, Col ${m.col}`:""}))},ut=ir(()=>Ae());function Ae(){let m=M.pathAtCaret();p("st-path").textContent=m.length?m.join(" \u203A "):"",p("st-path").title=Se(m),p("st-kind").textContent=r.kindLabel(v.text)}let pt=()=>M.onCaret(()=>{dt(),ut()});pt(),g.push(v.on(m=>{dt(),or(m)?ut():ut.now()}));{let m=p("grip"),C=G=>{let Z=Math.min(Math.max(p("problems").getBoundingClientRect().height-G,48),innerHeight*.6);d.style.setProperty("--problems-h",`${Z}px`),c.set("problems-h",String(Math.round(Z)))},R=c.get("problems-h");R&&d.style.setProperty("--problems-h",`${R}px`),h(m,"pointerdown",G=>{m.setPointerCapture(G.pointerId);let Z=G.clientY,$e=De=>{C(De.clientY-Z),Z=De.clientY},de=()=>{m.removeEventListener("pointermove",$e),m.removeEventListener("pointerup",de)};m.addEventListener("pointermove",$e),m.addEventListener("pointerup",de)}),h(m,"keydown",G=>{G.key==="ArrowUp"&&(C(-16),G.preventDefault()),G.key==="ArrowDown"&&(C(16),G.preventDefault())})}je=n.part?.({root:d,byId:p,doc:v,store:c,note:ue,watch:a,on:(m,C,R)=>h(m,C,R),disposed:()=>ie,paintProblems:()=>lt(),paintProps:()=>P.paint()},{canvas:()=>_,objectPath:Ne});function et(m){m=m||!s.edit,b.readOnly=m,d.classList.toggle("read-only",m),p("ro").hidden=!m,M.setReadOnly(m),ne(),Ce()}function bt(){p("views").hidden=!(s.text&&s.canvas),p("right").hidden=p("right-grip").hidden=!s.edit,p("tab-plan").hidden=!s.plan,d.dataset.features=Object.keys(s).sort().join(" ")}!s.plan&&se==="plan"&&(se="problems"),Me(se),bt(),$(b.view),ve(),et(b.readOnly),v.load(e.text??""),je?.start?.(),ne(),Ce();let A=n.late,Y=Promise.resolve();async function q(m){let C=m.filter(G=>!n.names.includes(G));if(C.length)throw new Error(`unknown feature ${C.join(", ")}: the features are ${n.names.join(", ")}`);let R=Y.then(async()=>{if(ie)throw new Error("the editor was disposed");let G=[...new Set(m)].filter(De=>!s[De]);if(!G.length)return;let Z=G.filter(De=>!A.includes(De));if(Z.length)throw new Error(`${Z.join(", ")} can't be added to a mounted editor (only ${A.join(" and ")} can): mount with ${Z.length>1?"them":"it"}`);if(!i)throw new Error(`this build has no loader for ${G.join(", ")}: mount with ${G.length>1?"them":"it"}`);let $e=await i(G);if(ie)throw new Error("the editor was disposed");let de=v.selection.slice();for(let De of $e)s[De.name]=De;G.includes("text")&&(M.dispose(),M=w(),pt(),M.setReadOnly(b.readOnly),M.setProblems(b.problems.filter(De=>!De.file)),ve(),de.length&&v.select(de,"menu")),G.includes("plan")&&(D=qe(),Oe()),bt(),$(k),Ae()});return Y=R.catch(()=>{}),R}let ae={root:d,doc:v,get pane(){return M},tree:S,canvas:_,props:P,clip:T,state:b,check:Ke,save:fe,note:ue,setView:$,showBanner:z,hideBanner:X,keySheet:we,setTheme:B,setDensity:W,setBottomTab:Me,markers:()=>M.monaco.editor.getModelMarkers({resource:M.model.uri}).map(C=>({severity:C.severity,message:C.message,line:C.startLineNumber,col:C.startColumn,endCol:C.endColumn}))};return n.internal&&Object.defineProperties(ae,Object.getOwnPropertyDescriptors(n.internal)),je&&Object.defineProperties(ae,Object.getOwnPropertyDescriptors(je.api)),{internal:ae,getText:()=>v.text,setText(m){X(),v.load(m),v.markClean(),ne(),Ce()},setReadOnly:et,setTheme:B,addFeatures:q,fit(){ie||_.fit()},dispose(){if(!ie){ie=!0,clearTimeout(ge),clearTimeout(ee),je?.dispose?.(),cancelAnimationFrame(Ue),ut.cancel(),xl();for(let m of g.splice(0))m();S.dispose(),P.dispose(),_.dispose(),M.dispose(),d.remove(),Mr(null)}}}}function Ym(){let t=()=>{};return{setTheme:t,setReadOnly:t,setProblems:t,goTo:t,goToOffset:t,focus:t,dispose:t,onCaret:t,caret:()=>{},pathAtCaret:()=>[],editor:{layout:t,focus:t},model:void 0,monaco:void 0,resyncs:()=>0}}function qm(t={}){let e={palette:void 0,doc:void 0,stage:void 0,...t};return new Proxy({},{get:(n,s)=>s in e?e[s]:()=>{}})}var Wf=1;function Jf(t,e){return!!t&&typeof t=="object"&&t.v===1&&e.includes(t.type)}var uo={"arrow-up-right":'<path d="M7 7h10v10" /> <path d="M7 17 17 7" />',box:'<path d="M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z" /> <path d="m3.3 7 8.7 5 8.7-5" /> <path d="M12 22V12" />',"chevron-down":'<path d="m6 9 6 6 6-6" />',"chevron-left":'<path d="m15 18-6-6 6-6" />',"chevron-right":'<path d="m9 18 6-6-6-6" />',"circle-dot":'<circle cx="12" cy="12" r="1" /> <circle cx="12" cy="12" r="10" />',"circle-x":'<circle cx="12" cy="12" r="10" /> <path d="m15 9-6 6" /> <path d="m9 9 6 6" />',clipboard:'<rect width="8" height="4" x="8" y="2" rx="1" ry="1" /> <path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2" />',"clipboard-paste":'<path d="M11 14h10" /> <path d="M16 4h2a2 2 0 0 1 2 2v1.344" /> <path d="m17 18 4-4-4-4" /> <path d="M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 1.793-1.113" /> <rect x="8" y="2" width="8" height="4" rx="1" />',"code-xml":'<path d="m18 16 4-4-4-4" /> <path d="m6 8-4 4 4 4" /> <path d="m14.5 4-5 16" />',copy:'<rect width="14" height="14" x="8" y="8" rx="2" ry="2" /> <path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" />',layers:'<path d="M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z" /> <path d="M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12" /> <path d="M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17" />',link:'<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" /> <path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" />',list:'<path d="M3 5h.01" /> <path d="M3 12h.01" /> <path d="M3 19h.01" /> <path d="M8 5h13" /> <path d="M8 12h13" /> <path d="M8 19h13" />',"list-tree":'<path d="M8 5h13" /> <path d="M13 12h8" /> <path d="M13 19h8" /> <path d="M3 10a2 2 0 0 0 2 2h3" /> <path d="M3 5v12a2 2 0 0 0 2 2h3" />',"panel-right":'<rect width="18" height="18" x="3" y="3" rx="2" /> <path d="M15 3v18" />',pencil:'<path d="M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z" /> <path d="m15 5 4 4" />',plus:'<path d="M5 12h14" /> <path d="M12 5v14" />',"rotate-ccw":'<path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" /> <path d="M3 3v5h5" />',search:'<path d="m21 21-4.34-4.34" /> <circle cx="11" cy="11" r="8" />',"trash-2":'<path d="M10 11v6" /> <path d="M14 11v6" /> <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" /> <path d="M3 6h18" /> <path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />',"triangle-alert":'<path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3" /> <path d="M12 9v4" /> <path d="M12 17h.01" />',x:'<path d="M18 6 6 18" /> <path d="m6 6 12 12" />'},Xf=Object.keys(uo),ci=t=>Object.entries(t).map(([e,n])=>`<symbol id="se-i-${e}" viewBox="0 0 24 24">${n}</symbol>`).join(""),di=t=>`<svg xmlns="http://www.w3.org/2000/svg" class="sprite" aria-hidden="true" focusable="false">${t}</svg>`,Qf=di(ci(uo));var Um=/^[a-z][a-z0-9-]*$/,gd={rootClass:"iso-editor",brand:"iso <b>editor</b>",sideLabel:"The file",canvasLabel:"The file, drawn",problemsLabel:"Problems",bottomTabsLabel:"Problems",extraTab:"Check",slots:""},Al=[{where:"Anywhere in the editor",keys:[["\u2318S","Save"],["\u2318Z","Undo"],["\u21E7\u2318Z or \u2318Y","Redo"],["?","This sheet"],["Esc","Close a menu or dialog"]]},{where:"The tree and the canvas",keys:[["F2","Rename"],["\u232B","Delete"],["\u2318D","Duplicate"],["\u2318\u2191","Select the parent"]]},{where:"The canvas",keys:[["+ \u2212","Zoom"],["0","Fit"],["1","100%"],["\u21E72","Zoom to the selection"]]}];function Zf(t,e,n){let s=lo(t),r=e.nameRule??Um,o=e.nameHint??"a lower-case letter, then lower-case letters, digits and -",i=e.icon??(()=>"box"),a=Ml({commands:s,objectOf:t.objectOf,kinds:t.kinds,nameRule:r,nameHint:o}),l=hl(t),c={docFor:ml,completionAt:l.completionAt,hoverAt:l.hoverAt,definitionAt:l.definitionAt,rangeOfPath:gl},d=(y,T)=>T.reduce((S,P)=>S&&typeof S=="object"?S[P]:void 0,y),u=(y,T)=>d(y,[T,"layout"]),f={key:t.pins.key,legacyKey:t.pins.legacyKey,legacyOnly:t.pins.legacyOnly,of:y=>u(y,t.pins.key)??(t.pins.legacyKey?u(y,t.pins.legacyKey):void 0),keyOf:y=>t.pins.legacyOnly(y)&&t.pins.legacyKey?t.pins.legacyKey:t.pins.key},p=(y,T=e.fileName)=>t.read(y,{fileName:T,role:t.role(y)}),g={outline:(y,T,S)=>fl(y,t,T,S),commands:s,slotAt:t.slotAt,kinds:t.kinds,entryGroups:t.entryGroups,nameRule:r,ui:{label:"The file, as a tree",rootIcon:"layers",kindIcon:i,keyIcon:()=>{},entryIcon:()=>"list-tree",newItems:y=>[{label:`New ${t.kinds.find(S=>S.kind===y).singular}`,icon:i(y)}],tagPill:y=>({title:y}),nameHint:o,text:{root:"File",rootAdd:"the file",renameWhy:"Groups and the file itself have fixed names",deleteWhy:"The file itself stays",duplicateNote:"Duplicate works on objects",duplicateWhy:"Only objects can be duplicated"}}},h={commands:s,actions:a,slotAt:t.slotAt,objectOf:t.objectOf,kinds:t.kinds,ui:{important:()=>[],isExternal:()=>!1,inheritedFrom:"the base file",extensionDoc:"An extension: ignored by the reader.",rootTitle:"The file",rootItem:"(the file)"}},b={rootClass:"iso-canvas",panKeyClass:"pan-key",newOrder:t.kinds.map(y=>y.kind),palette:e.palette?e.palette.map(y=>({kind:y.kind,label:y.label,icon:y.icon??i(y.kind),name:y.name,...y.section===void 0?{}:{section:y.section},...y.value===void 0?{}:{value:()=>structuredClone(y.value)}})):t.kinds.map(y=>({kind:y.kind,icon:i(y.kind),label:y.singular[0].toUpperCase()+y.singular.slice(1)})),...e.paletteLayout===void 0?{}:{paletteLayout:e.paletteLayout},text:{stage:"The file, drawn: arrow keys and Tab move through what is drawn; + and \u2212 zoom, 0 fits",dragGroup:"A drag on nothing",dragSelectTip:"Drag draws a selection; hold the space key to pan",unreadable:"The canvas draws a file that reads cleanly; fix the problems listed to see it.",palette:"Add to the file: click, or drag onto the canvas",pinHint:"",renameWhy:"Only objects are renamed here",duplicateWhy:"Only objects are duplicated"}},v={draw:e.draw,catalog:e.catalog,objectOf:t.objectOf,kinds:t.kinds,commands:s,actions:a,objectItems:()=>[],pins:f,ui:b,flat:e.flat,...t.connect?{connect:(y,T,S)=>t.connect(y,T,S)}:{},...t.group?{group:(y,T)=>t.group(y,T)}:{},...t.dropInto?{dropOnto:(y,T,S,P)=>t.dropInto(y,T,S,P)}:{},trial:(y,T)=>{let S=p(y);return S.read===void 0||S.diags.some(P=>P.severity==="error")?void 0:e.draw(S.read,S.read.data,T)}},w={async check(y){let T=pl(t,y,{fileName:e.fileName}),S=!T.problems.some(P=>P.severity==="error")&&T.read!==void 0;return{problems:T.problems,read:T.read,tags:T.tags,model:S?T.read:void 0,data:T.read?.data,extra:void 0}},role:y=>t.role(y),kindLabel:()=>t.id,nav:l.navFor,objectPath(y,T){let S=T?.data;for(let P of t.kinds)if(d(S,[...P.section,y])!==void 0)return Se([...P.section,y])},extraLabel:()=>({text:"",cls:""}),keymap:e.keymap??(t.group?Al.map(y=>y.where==="The tree and the canvas"?{...y,keys:[...y.keys,["\u2318G","Group the selection"]]}:y):Al)},M={canvas:{canvasView:(y,T,S)=>Tl(y,T,{...S,theme:e.theme,kit:v,layer:e.layer})},edit:{propsPanel:(y,T,S)=>El(y,T,{...S,kit:h}),clipboard:(y,T)=>kl(y,T,dl(t))},...n?{text:{textPane:(y,T,S)=>n(y,T,{...S,services:c})}}:{}};return{kit:w,tree:g,words:{...gd,...e.words},features:M,names:["text","canvas","edit"],late:["text"],hasExtra:!1,part:e.part?y=>e.part(y):void 0,sprite:di(ci({...uo,...e.icons}))}}function Wm(t){let e=[],n=t.replace(/\/\*[\s\S]*?\*\//g,""),s=0;for(;s<n.length;){let r=n.indexOf("{",s),o=n.indexOf(";",s);if(r<0&&o<0)break;if(o>=0&&(r<0||o<r)){let l=n.slice(s,o).trim();l&&e.push([l,null]),s=o+1;continue}let i=1,a=r+1;for(;a<n.length&&i;)n[a]==="{"?i++:n[a]==="}"&&i--,a++;e.push([n.slice(s,r).trim(),n.slice(r+1,a-1)]),s=a}return e}function Jm(t){let e=[],n=0,s=0;for(let r=0;r<t.length;r++){let o=t[r];o==="("||o==="["?n++:o===")"||o==="]"?n--:o===","&&!n&&(e.push(t.slice(s,r).trim()),s=r+1)}return e.push(t.slice(s).trim()),e.filter(Boolean)}function bd(t,e){let n=`.${e}`,s=/^(?:html|body|:root)((?:\[[^\]]*\]|\.[\w-]+|:not\([^)]*\))*)(.*)$/.exec(t);return s&&/^(html|body|:root)(?![\w-])/.test(t)?`${n}${s[1]}${s[2].trim()?" "+s[2].trim():""}`:t==="*"?`${n}, ${n} *`:`${n} ${t}`}function yd(t,e){let n="";for(let[s,r]of Wm(t)){if(r===null){(s.startsWith("@layer")||s.startsWith("@import"))&&(n+=`${s};
|
|
545
545
|
`);continue}if(s.startsWith("@keyframes")){n+=`@keyframes se-${s.slice(10).trim()}{${r}}
|
|
546
546
|
`;continue}if(/^@(layer|media|container|supports)\b/.test(s)){n+=`${s}{
|
|
547
|
-
${
|
|
547
|
+
${yd(r,e)}}
|
|
548
548
|
`;continue}if(s.startsWith("@font-face")){n+=`${s}{${r}}
|
|
549
|
-
`;continue}if(s.startsWith("@"))throw new Error(`the editor's CSS has an at-rule it can't scope: ${s}`);let o=[...new Set(
|
|
550
|
-
`}return n}export{
|
|
549
|
+
`;continue}if(s.startsWith("@"))throw new Error(`the editor's CSS has an at-rule it can't scope: ${s}`);let o=[...new Set(Jm(s).flatMap(i=>bd(i,e).split(", ")))].join(",");n+=`${o}{${r.replace(/\banimation(-name)?:\s*([a-z][\w-]*)/g,(i,a,l)=>l==="none"?i:`animation${a??""}:se-${l}`)}}
|
|
550
|
+
`}return n}export{Au as core,ep as editor,Uu as objects,If as viewer};
|