@phin-tech/dottie 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- /*! dottie.js 0.9.0 | Apache-2.0 | https://github.com/phin-tech/dottie */
2
- "use strict";(()=>{var tn=Object.defineProperty;var en=(n,t,e)=>t in n?tn(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var V=(n,t,e)=>en(n,typeof t!="symbol"?t+"":t,e);var pe=.5522847498307936,tt=class n{constructor(){V(this,"segments",[])}get isEmpty(){return this.segments.length===0}moveTo(t){return this.segments.push({op:"M",p:t}),this}lineTo(t){return this.segments.push({op:"L",p:t}),this}quadTo(t,e){return this.segments.push({op:"Q",c:e,p:t}),this}curveTo(t,e,r){return this.segments.push({op:"C",c1:e,c2:r,p:t}),this}close(){return this.segments.push({op:"Z"}),this}addPath(t){return this.segments.push(...t.segments),this}addLines(t){return t.forEach((e,r)=>r===0?this.moveTo(e):this.lineTo(e)),this}static rect(t){return new n().addLines([{x:t.x,y:t.y},{x:t.x+t.width,y:t.y},{x:t.x+t.width,y:t.y+t.height},{x:t.x,y:t.y+t.height}]).close()}addEllipse(t){let e=t.x+t.width/2,r=t.y+t.height/2,o=t.width/2,s=t.height/2,i=o*pe,l=s*pe;return this.moveTo({x:e+o,y:r}),this.curveTo({x:e,y:r+s},{x:e+o,y:r+l},{x:e+i,y:r+s}),this.curveTo({x:e-o,y:r},{x:e-i,y:r+s},{x:e-o,y:r+l}),this.curveTo({x:e,y:r-s},{x:e-o,y:r-l},{x:e-i,y:r-s}),this.curveTo({x:e+o,y:r},{x:e+i,y:r-s},{x:e+o,y:r-l}),this.close()}static ellipse(t){return new n().addEllipse(t)}translated(t,e){let r=s=>({x:s.x+t,y:s.y+e}),o=new n;return o.segments=this.segments.map(s=>{switch(s.op){case"M":case"L":return{op:s.op,p:r(s.p)};case"Q":return{op:"Q",c:r(s.c),p:r(s.p)};case"C":return{op:"C",c1:r(s.c1),c2:r(s.c2),p:r(s.p)};case"Z":return s}}),o}contours(){let t=[],e=[],r={x:0,y:0};for(let o of this.segments){let s=e.length?e[e.length-1]:r;switch(o.op){case"M":e.length>1&&t.push(e),r=o.p,e=[o.p];break;case"L":e.push(o.p);break;case"Q":for(let i=1;i<=12;i++){let l=i/12,a=1-l;e.push({x:a*a*s.x+2*a*l*o.c.x+l*l*o.p.x,y:a*a*s.y+2*a*l*o.c.y+l*l*o.p.y})}break;case"C":for(let i=1;i<=16;i++){let l=i/16,a=1-l;e.push({x:a*a*a*s.x+3*a*a*l*o.c1.x+3*a*l*l*o.c2.x+l*l*l*o.p.x,y:a*a*a*s.y+3*a*a*l*o.c1.y+3*a*l*l*o.c2.y+l*l*l*o.p.y})}break;case"Z":e.push(r),e.length>1&&t.push(e),e=[r];break}}return e.length>1&&t.push(e),t}trimmed(t){let e=this.contours().map(s=>new pt(s)),r=Math.min(Math.max(t,0),1)*e.reduce((s,i)=>s+i.length,0),o=new n;for(let s of e){if(!(r>0))break;o.moveTo(s.points[0]);for(let i=1;i<s.points.length;i++){let l=s.lengths[i]-s.lengths[i-1];if(l<=r){o.lineTo(s.points[i]),r-=l;continue}let a=s.points[i-1],c=s.points[i],u=r/l;o.lineTo({x:a.x+(c.x-a.x)*u,y:a.y+(c.y-a.y)*u}),r=0;break}}return o}data(){let t=[];for(let e of this.segments)switch(e.op){case"M":t.push(`M${nt(e.p.x)} ${nt(e.p.y)}`);break;case"L":t.push(`L${nt(e.p.x)} ${nt(e.p.y)}`);break;case"Q":t.push(`Q${nt(e.c.x)} ${nt(e.c.y)} ${nt(e.p.x)} ${nt(e.p.y)}`);break;case"C":t.push(`C${nt(e.c1.x)} ${nt(e.c1.y)} ${nt(e.c2.x)} ${nt(e.c2.y)} ${nt(e.p.x)} ${nt(e.p.y)}`);break;case"Z":t.push("Z");break}return t.join(" ")}};function ye(n){return n<0?-Math.round(-n):Math.round(n)}function nt(n){let t=ye(n*100)/100;return Number.isInteger(t)?String(t===0?0:t):String(t)}var pt=class{constructor(t){V(this,"points");V(this,"lengths");this.points=t;let e=0;this.lengths=t.map((r,o)=>(o>0&&(e+=Math.hypot(r.x-t[o-1].x,r.y-t[o-1].y)),e))}get length(){return this.lengths.length?this.lengths[this.lengths.length-1]:0}point(t){if(this.points.length<=1||!(this.length>0))return this.points[0]??{x:0,y:0};let e=Math.min(Math.max(t,0),1)*this.length,r=1;for(;r<this.lengths.length-1&&this.lengths[r]<e;)r++;let o=this.lengths[r]-this.lengths[r-1],s=o>0?(e-this.lengths[r-1])/o:0,i=this.points[r-1],l=this.points[r];return{x:i.x+(l.x-i.x)*s,y:i.y+(l.y-i.y)*s}}},xt=n=>n.x+n.width/2,bt=n=>n.y+n.height/2,wt=n=>n.x+n.width,kt=n=>n.y+n.height;function Vt(n,t,e){if(e===0)return n;let r=n.x-t.x,o=n.y-t.y;return{x:t.x+r*Math.cos(e)-o*Math.sin(e),y:t.y+r*Math.sin(e)+o*Math.cos(e)}}function ge(n,t){let e=1-t;return{x:n[0].x*(e*e*e)+n[1].x*(3*t*e*e)+n[2].x*(3*t*t*e)+n[3].x*(t*t*t),y:n[0].y*(e*e*e)+n[1].y*(3*t*e*e)+n[2].y*(3*t*t*e)+n[3].y*(t*t*t)}}var xe=2,nn=["rectangle","ellipse","diamond","text","connector","freehand","path","note","image","symbol"],rn=["linear","easeIn","easeOut","easeInOut","hold","spring","bounce","elastic"],on={file:["version","pages","images"],page:["id","name","layers","elements","theme","guidesX","guidesY","guidesLocked","timeline","symbols","variables","flows"],flow:["id","from","to","every","speed","color","size","when","spread","volume","overrides"],flowOverride:["when","volume"],symbol:["id","name","width","height","layers","elements","timeline","button","params"],layer:["id","name","visible","locked"],rgba:["r","g","b","a"],style:["stroke","fill","fillStyle","strokeWidth","dash","roughness","bowing","fontSize","font","gridSize","opacity","dashOffset","textColor"],element:["id","kind","x","y","width","height","style","seed","layerID","text","connector","groupID","points","path","subpaths","evenOdd","rotation","link","url","anchor","click","hover","when","overrides","symbol","playback","offset","args","image","reveal","ports","labelRect","extension","capacity","delay","queue","gauge"],gauge:["metric","of","max","warn","alarm","style","label"],strokePoint:["x","y"],subpath:["closed","coords"],inlineImage:["data","format"],endpoint:["elementID","port","portIndex","x","y"],extensionRef:["id","shape","version","params"],normalizedPoint:["x","y"],normalizedRect:["x","y","width","height"],connector:["start","end","routing","startHead","endHead","waypoints","hops","cost"],waypoint:["x","y"],timeline:["fps","duration","boil","settle","poster","tracks","camera","markers"],track:["element","keys","boil","follow","repeats","march"],keyframe:["t","x","y","width","height","rotation","strokeWidth","stroke","fill","visible","reveal","opacity","ease"],follow:["path","start","end","ease","reverse","orient","laps"],repeat:["start","end","count"],cameraKey:["t","x","y","width","height","ease"],marker:["t","name","loop"],click:["scene","url","set","toggle","reset"],hover:["stroke","fill","opacity"],override:["when","stroke","fill","textColor","opacity","strokeWidth","dash","text","reroute","offline","cost","capacity","delay"]},Ot=3600,be=1e4,sn=n=>n===void 0||!Number.isFinite(n)||n===0?null:Math.min(Math.max(n,-be),be);var ln={r:.12,g:.12,b:.13,a:1},an={r:0,g:0,b:0,a:0};var yt=class extends Error{},b=n=>typeof n=="object"&&n!==null&&!Array.isArray(n),f=n=>typeof n=="number"&&Number.isFinite(n)?n:void 0,w=n=>typeof n=="string"?n:void 0,we=n=>b(n)&&Object.values(n).every(t=>typeof t=="string")?{...n}:null,ot=n=>typeof n=="boolean"?n:void 0,ke="00000000-0000-0000-0000-000000000000",It=/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/,it=n=>typeof n=="string"?n.toUpperCase():void 0;function Xt(n){return Number.isFinite(n)?Math.min(Math.max(n,0),Ot):n===1/0?Ot:0}function Me(n){return Number.isFinite(n)?Math.min(Math.max(n,1),60):12}function un(n){let t=n.trim();return!/^(https?:\/\/|mailto:)/i.test(t)||[...t].length<=7||/[\u0000-\u001f\u007f-\u009f]/.test(t)?null:t}function ct(n){if(!b(n))return;let t=f(n.r),e=f(n.g),r=f(n.b);if(!(t===void 0||e===void 0||r===void 0))return{r:t,g:e,b:r,a:f(n.a)??1}}var Zt=class{constructor(){V(this,"warnings",[]);V(this,"seen",new Set)}warn(t){this.seen.has(t)||(this.seen.add(t),this.warnings.push(t))}fields(t,e){let r=on[e];for(let o of Object.keys(t))r.includes(o)||this.warn(`Unknown field "${o}" on ${e}, ignored`)}style(t){let e=b(t)?t:{};this.fields(e,"style");let r=w(e.fillStyle)??"solid",o=w(e.dash)??"solid";return["solid","hachure","crossHatch","grid"].includes(r)||this.warn(`Unknown fill style "${r}", drawn solid`),["solid","dashed","dotted"].includes(o)||this.warn(`Unknown dash "${o}", drawn solid`),{stroke:ct(e.stroke)??{...ln},fill:ct(e.fill)??{...an},fillStyle:["solid","hachure","crossHatch","grid"].includes(r)?r:"solid",strokeWidth:f(e.strokeWidth)??2,dash:["solid","dashed","dotted"].includes(o)?o:"solid",roughness:f(e.roughness)??1,bowing:f(e.bowing)??1,fontSize:f(e.fontSize)??18,font:w(e.font)||null,gridSize:f(e.gridSize)??null,opacity:f(e.opacity)??null,dashOffset:f(e.dashOffset)??null,textColor:ct(e.textColor)??null}}endpoint(t){let e=b(t)?t:{},r=w(e.port),o=f(e.portIndex);return{elementID:it(e.elementID)??null,port:r&&["top","right","bottom","left"].includes(r)?r:null,portIndex:o!==void 0&&Number.isInteger(o)&&o>=0?o:null,x:f(e.x)??0,y:f(e.y)??0}}connector(t){if(!b(t))return null;this.fields(t,"connector");let e=(o,s)=>{let i=w(o);return i&&["none","arrow","triangle","dot","bar"].includes(i)?i:s},r=w(t.routing);return{start:this.endpoint(t.start),end:this.endpoint(t.end),routing:r&&["straight","curved","elbow"].includes(r)?r:"straight",startHead:e(t.startHead,"none"),endHead:e(t.endHead,"arrow"),waypoints:Array.isArray(t.waypoints)?t.waypoints.filter(b).map(o=>(this.fields(o,"waypoint"),{x:f(o.x)??0,y:f(o.y)??0})):null,hops:typeof t.hops=="boolean"?t.hops:null,cost:typeof t.cost=="number"&&Number.isFinite(t.cost)?t.cost:null}}image(t,e){if(!b(t))return null;let r=w(t.ref);if(r!==void 0)return e[r]??{data:"",format:"png"};let o=w(t.data);return o===void 0?null:this.picture(o,w(t.format))}picture(t,e){return cn.test(t)?{data:t.replace(/\s+/g,""),format:e==="jpeg"?"jpeg":"png"}:(this.warn("Skipped a picture whose data isn't base64"),{data:"",format:"png"})}element(t,e){if(!b(t))return null;this.fields(t,"element");let r=it(t.id),o=w(t.kind),s=it(t.layerID);if(!r||!o||!s)return this.warn("Skipped an element without an id, kind or layer"),null;nn.includes(o)||this.warn(`Unknown element kind "${o}", drawn as a placeholder`);let i=Array.isArray(t.subpaths)?t.subpaths.filter(b).map(l=>({closed:ot(l.closed)??!1,coords:Array.isArray(l.coords)?l.coords.filter(a=>typeof a=="number"):[]})):null;return{id:r,kind:o,layerID:s,x:f(t.x)??0,y:f(t.y)??0,width:f(t.width)??0,height:f(t.height)??0,style:this.style(t.style),seed:(f(t.seed)??1)>>>0,text:w(t.text)??null,connector:this.connector(t.connector),groupID:it(t.groupID)??null,points:Array.isArray(t.points)?t.points.filter(b).map(l=>({x:f(l.x)??0,y:f(l.y)??0})):null,path:Array.isArray(t.path)?t.path.filter(l=>typeof l=="number"):null,subpaths:i,evenOdd:ot(t.evenOdd)??null,rotation:f(t.rotation)??null,link:it(t.link)??null,url:w(t.url)??null,anchor:w(t.anchor)??null,click:this.click(t.click),hover:this.hover(t.hover),when:w(t.when)??null,overrides:this.overrides(t.overrides),symbol:it(t.symbol)??null,playback:this.playback(t.playback),offset:f(t.offset)??null,args:we(t.args),image:this.image(t.image,e),reveal:f(t.reveal)??null,ports:Array.isArray(t.ports)?t.ports.map(l=>{let a=b(l)?l:{};return{x:f(a.x)??0,y:f(a.y)??0}}):null,labelRect:this.labelRect(t.labelRect),extension:this.extension(t.extension),capacity:f(t.capacity)??null,delay:f(t.delay)??null,queue:t.queue===!0?!0:null,gauge:this.gauge(t.gauge)}}gauge(t){if(!b(t))return null;this.fields(t,"gauge");let e=o=>typeof o=="number"&&Number.isFinite(o)?o:null,r=w(t.style);return{metric:w(t.metric)??"",of:typeof t.of=="string"&&It.test(t.of)?t.of.toUpperCase():ke,max:e(t.max),warn:e(t.warn),alarm:e(t.alarm),style:r==="number"||r==="bar"||r==="dial"?r:null,label:w(t.label)??null}}labelRect(t){return b(t)?(this.fields(t,"normalizedRect"),{x:f(t.x)??0,y:f(t.y)??0,width:f(t.width)??0,height:f(t.height)??0}):null}extension(t){if(!b(t))return null;this.fields(t,"extensionRef");let e=w(t.id),r=w(t.shape),o=w(t.version);if(e===void 0||r===void 0||o===void 0)return this.warn("Skipped an extension without an id, shape or version"),null;let s={};if(b(t.params))for(let[i,l]of Object.entries(t.params))(typeof l=="number"||typeof l=="boolean"||typeof l=="string")&&(s[i]=l);return{id:e,shape:r,version:o,params:s}}variables(t){if(!b(t))return null;let e={};for(let[r,o]of Object.entries(t))typeof o=="boolean"&&(e[r]=o);return Object.keys(e).length>0?e:null}click(t){if(!b(t))return null;this.fields(t,"click");let e=w(t.url),r=e===void 0?null:un(e);e!==void 0&&r===null&&this.warn("Skipped a click link that isn't http, https or mailto");let o=null;if(b(t.set)){o={};for(let[l,a]of Object.entries(t.set))typeof a=="boolean"&&vt(l)&&(o[l]=a);Object.keys(o).length===0&&(o=null)}let s=typeof t.toggle=="string"?[t.toggle]:Array.isArray(t.toggle)&&t.toggle.every(l=>typeof l=="string")?t.toggle:null,i=s?s.filter(vt):null;return{scene:w(t.scene)??null,url:r,set:o,toggle:i&&i.length>0?i:null,reset:t.reset===!0?!0:null}}playback(t){let e=w(t);return e===void 0?null:["loop","once","still","click"].includes(e)?e:"loop"}symbol(t,e){if(!b(t))return null;this.fields(t,"symbol");let r=it(t.id);if(!r)return this.warn("Skipped a symbol without an id"),null;let o=i=>{let l=f(i);return Math.max(1,l??100)},s=(Array.isArray(t.layers)?t.layers:[]).filter(b).flatMap(i=>{let l=it(i.id);return l?[{id:l,name:w(i.name)??"",visible:ot(i.visible)??!0,locked:ot(i.locked)??!1}]:[]});return s.length===0&&s.push({id:`${r}-LAYER`,name:"Layer 1",visible:!0,locked:!1}),{id:r,name:w(t.name)??"Symbol",width:o(t.width),height:o(t.height),layers:s,elements:(Array.isArray(t.elements)?t.elements:[]).map(i=>this.element(i,e)).filter(i=>i!==null),timeline:this.timeline(t.timeline),button:ot(t.button)??null,params:we(t.params)}}overrides(t){return Array.isArray(t)?t.filter(b).map(e=>{this.fields(e,"override");let r=w(e.dash),o=null;if(b(e.reroute)&&Object.values(e.reroute).every(s=>typeof s=="string"&&It.test(s))){o={};for(let[s,i]of Object.entries(e.reroute))It.test(s)&&(o[s.toUpperCase()]=i.toUpperCase());Object.keys(o).length===0&&(o=null)}return{when:w(e.when)??"",stroke:ct(e.stroke)??null,fill:ct(e.fill)??null,textColor:ct(e.textColor)??null,opacity:f(e.opacity)??null,strokeWidth:f(e.strokeWidth)??null,dash:r!==void 0&&["solid","dashed","dotted"].includes(r)?r:null,text:w(e.text)??null,reroute:o,offline:e.offline===!0?!0:null,cost:typeof e.cost=="number"&&Number.isFinite(e.cost)?e.cost:null,capacity:typeof e.capacity=="number"&&Number.isFinite(e.capacity)?e.capacity:null,delay:typeof e.delay=="number"&&Number.isFinite(e.delay)?e.delay:null}}):null}hover(t){return b(t)?(this.fields(t,"hover"),{stroke:ct(t.stroke)??null,fill:ct(t.fill)??null,opacity:f(t.opacity)??null}):null}ease(t){let e=w(t);return e===void 0?null:rn.includes(e)?e:(this.warn(`Unknown ease "${e}", played linear`),null)}keyframe(t){if(!b(t))return null;this.fields(t,"keyframe");let e=f(t.t);if(e===void 0)return null;let r={t:e};for(let a of["x","y","width","height","rotation","strokeWidth","reveal","opacity"]){let c=f(t[a]);c!==void 0&&(r[a]=c)}let o=ct(t.stroke),s=ct(t.fill),i=ot(t.visible),l=this.ease(t.ease);return o&&(r.stroke=o),s&&(r.fill=s),i!==void 0&&(r.visible=i),l&&(r.ease=l),r}track(t){if(!b(t))return null;this.fields(t,"track");let e=it(t.element);if(!e)return null;let r=(Array.isArray(t.keys)?t.keys:[]).map(i=>this.keyframe(i)).filter(i=>i!==null&&i.t>=0&&i.t<=Ot);Yt(r,i=>i.t);let o=Array.isArray(t.follow)?t.follow.filter(b).flatMap(i=>{let l=it(i.path),a=f(i.start),c=f(i.end);return!l||a===void 0||c===void 0||a<0||c>Ot?[]:[{path:l,start:a,end:c,ease:this.ease(i.ease),reverse:ot(i.reverse)??null,orient:ot(i.orient)??null,laps:f(i.laps)??null}]}):null,s=Array.isArray(t.repeats)?t.repeats.filter(b).flatMap(i=>{let l=f(i.start),a=f(i.end);if(l===void 0||a===void 0)return[];let c=f(i.count),u={start:l,end:a,count:c===void 0?null:Math.trunc(c)};return Pe(u)?[u]:[]}):null;return{element:e,keys:r,boil:ot(t.boil)??null,follow:o,repeats:s,march:sn(f(t.march))}}timeline(t){if(!b(t))return null;this.fields(t,"timeline");let e=f(t.boil),r=Array.isArray(t.camera)?t.camera.filter(b).flatMap(i=>{let l=f(i.t),a=f(i.x),c=f(i.y),u=f(i.width),y=f(i.height);return l===void 0||a===void 0||c===void 0||u===void 0||y===void 0?[]:u>1&&y>1&&l>=0?[{t:l,x:a,y:c,width:u,height:y,ease:this.ease(i.ease)}]:[]}):null;r&&Yt(r,i=>i.t);let o=Array.isArray(t.markers)?t.markers.filter(b).flatMap(i=>{let l=f(i.t);return l!==void 0&&l>=0?[{t:l,name:w(i.name)??"",loop:ot(i.loop)??null}]:[]}):null;o&&Yt(o,i=>i.t);let s=f(t.poster);return{fps:Me(f(t.fps)??12),duration:Xt(f(t.duration)??0),boil:e!==void 0&&Number.isInteger(e)&&e>0?Math.min(e,1e4):null,settle:ot(t.settle)??null,poster:s===void 0?null:Xt(s),tracks:(Array.isArray(t.tracks)?t.tracks:[]).map(i=>this.track(i)).filter(i=>i!==null),camera:r,markers:o}}page(t,e,r){if(!b(t))throw new yt(`Page ${r} is not an object`);this.fields(t,"page");let o=(Array.isArray(t.layers)?t.layers:[]).filter(b).flatMap(s=>{let i=it(s.id);return i?[{id:i,name:w(s.name)??"",visible:ot(s.visible)??!0,locked:ot(s.locked)??!1}]:[]});return o.length===0&&(this.warn(`Page ${r} has no layers`),o.push({id:"LAYER",name:"Layer 1",visible:!0,locked:!1})),{id:it(t.id)??`PAGE-${r}`,name:w(t.name)??`Page ${r}`,layers:o,elements:(Array.isArray(t.elements)?t.elements:[]).map(s=>this.element(s,e)).filter(s=>s!==null),theme:w(t.theme)??null,timeline:this.timeline(t.timeline),symbols:Array.isArray(t.symbols)?t.symbols.map(s=>this.symbol(s,e)).filter(s=>s!==null):null,variables:this.variables(t.variables),flows:Array.isArray(t.flows)?t.flows.filter(b).map(s=>this.flow(s)):null}}flow(t){this.fields(t,"flow");let e=o=>typeof o=="string"&&It.test(o)?o.toUpperCase():ke,r=o=>{let s=f(o);return s!==void 0&&Number.isFinite(s)?s:null};return{id:e(t.id),from:e(t.from),to:Array.isArray(t.to)&&t.to.every(o=>typeof o=="string")?t.to.filter(o=>It.test(o)).map(o=>o.toUpperCase()):[],every:r(t.every),speed:r(t.speed),size:r(t.size),color:b(t.color)&&["r","g","b","a"].every(o=>typeof t.color[o]=="number")?ct(t.color)??null:null,when:w(t.when)??null,spread:t.spread===!0?!0:null,volume:r(t.volume),overrides:Array.isArray(t.overrides)&&t.overrides.length>0?t.overrides.filter(b).map(o=>(this.fields(o,"flowOverride"),{when:w(o.when)??"",volume:r(o.volume)})):null}}},cn=/^[A-Za-z0-9+/=\s]*$/;function Pe(n){return Number.isFinite(n.start)&&Number.isFinite(n.end)&&n.start>=0&&n.end-n.start>.001&&n.end<=Ot&&(n.count===null||n.count>=1&&n.count<=1e4)}function Yt(n,t){let e=n.map((r,o)=>[r,o]);e.sort((r,o)=>t(r[0])-t(o[0])||r[1]-o[1]);for(let r=0;r<n.length;r++)n[r]=e[r][0]}function Ee(n){let t=n;if(typeof n=="string")try{t=JSON.parse(n)}catch(i){throw new yt(`Not JSON: ${i.message}`)}if(!b(t))throw new yt("Not a Dottie drawing");let e=f(t.version);if(e===void 0)throw new yt("Not a Dottie drawing (no version)");if(!Array.isArray(t.pages)||t.pages.length===0)throw new yt("A drawing needs at least one page");let r=new Zt;r.fields(t,"file"),e>xe&&r.warn(`File version ${e} is newer than this player knows (${xe}); some things may not show`);let o={};if(b(t.images))for(let[i,l]of Object.entries(t.images))b(l)&&typeof l.data=="string"&&(o[i]=r.picture(l.data,w(l.format)));let s=t.pages.map((i,l)=>r.page(i,o,l+1));if(new Set(s.map(i=>i.id)).size!==s.length)throw new yt("Two pages share an id");return{version:e,pages:s,warnings:r.warnings}}function Lt(n){return{...n,style:{...n.style,stroke:{...n.style.stroke},fill:{...n.style.fill},textColor:n.style.textColor?{...n.style.textColor}:null},connector:n.connector?{...n.connector,start:{...n.connector.start},end:{...n.connector.end},waypoints:n.connector.waypoints?.map(t=>({...t}))??null}:null,gauge:n.gauge?{...n.gauge}:n.gauge}}var hn=64;function vt(n){return n.length<=hn&&/^[A-Za-z_][A-Za-z0-9_]*$/.test(n)}var Re=["throughput","load","delay","backlog","depth","inFlight","transit","backup"],mn=[">=","<=","==","!=",">","<"];function Bt(n){let t=mt(n);if(!t.includes("(")){let a=t.search(/[>=<!]/);if(a<0)return null;let c=mt(t.slice(0,a));if(!Re.includes(c))return null;let u=Bt(c+"() "+t.slice(a));return u?{...u,target:""}:null}let e=t.indexOf("("),r=t.indexOf(")");if(e<0||r<0||e>=r)return null;let o=mt(t.slice(0,e)),s=mt(t.slice(e+1,r)),i=mt(t.slice(r+1));if(!Re.includes(o)||s.includes("("))return null;let l=mn.find(a=>i.startsWith(a));return l===void 0||(i=mt(i.slice(l.length)),!/^-?[0-9]+(\.[0-9]+)?$/.test(i))?null:{metric:o,target:s,op:l,value:Number(i)}}function fn(n,t){switch(n.op){case">":return t>n.value;case">=":return t>=n.value;case"<":return t<n.value;case"<=":return t<=n.value;case"==":return t===n.value;default:return t!==n.value}}function Jt(n){return n.split("||").some(t=>t.split("&&").some(e=>Bt(e)!==null))}function dn(n){let t=[];for(let e of n.split("||"))for(let r of e.split("&&")){if(Bt(r)!==null)continue;let o=mt(r);if(o.startsWith("!")&&(o=mt(o.slice(1))),!vt(o))return null;t.push(o)}return t}function Ut(n,t,e=null){return dn(n)===null?!1:n.split("||").some(r=>r.split("&&").every(o=>{let s=Bt(o);if(s!==null){let a=e?e(s):null;return a!==null&&fn(s,a)}let i=mt(o),l=!1;return i.startsWith("!")&&(l=!0,i=mt(i.slice(1))),(t[i]??!1)!==l}))}function qt(n){return{...n,reroute:null,offline:null,cost:null,capacity:null,delay:null}}function Qt(n,t){let e=Lt(t);if(n.stroke&&(e.style.stroke={...n.stroke}),n.fill&&(e.style.fill={...n.fill}),n.textColor&&(e.style.textColor={...n.textColor}),n.strokeWidth!==null&&(e.style.strokeWidth=Math.max(0,n.strokeWidth)),n.dash!==null&&(e.style.dash=n.dash),n.text!==null&&(e.text=n.text),n.cost!==null&&e.connector&&(e.connector.cost=Math.min(Math.max(n.cost,0),1e6)),n.capacity!==null&&(e.capacity=Math.max(n.capacity,0)),n.delay!==null&&e.kind!=="connector"&&(e.delay=Math.max(n.delay,0)),n.opacity!==null){let r=Math.min(Math.max(n.opacity,0),1)*(e.style.opacity??1);e.style.opacity=r>=1?null:r}return e}function mt(n){return n.replace(/^[ \t ]+|[ \t ]+$/g,"")}var Mt=n=>({x:n.x,y:n.y,width:n.width,height:n.height}),Tt=n=>n.rotation??0,Ft=n=>({x:n.x+n.width/2,y:n.y+n.height/2}),Pt=(n,t)=>Vt(t,Ft(n),Tt(n)),Se=(n,t)=>Vt(t,Ft(n),-Tt(n));function Dt(n){if(n.kind!=="path"||!n.subpaths)return[];let t=[];for(let e of n.subpaths){if(e.coords.length<8||(e.coords.length-2)%6!==0)continue;let r=[];for(let o=0;o<e.coords.length;o+=2)r.push({x:n.x+e.coords[o]*n.width,y:n.y+e.coords[o+1]*n.height});t.push({closed:e.closed,points:r})}return t}function Ae(n){let t=new tt;for(let e of Dt(n)){t.moveTo(e.points[0]);for(let r=0;r<(e.points.length-1)/3;r++)t.curveTo(e.points[3*r+3],e.points[3*r+1],e.points[3*r+2]);e.closed&&t.close()}return t}function pn(n,t){let e=Mt(n),r=t==="top"?{x:xt(e),y:e.y}:t==="right"?{x:wt(e),y:bt(e)}:t==="bottom"?{x:xt(e),y:kt(e)}:{x:e.x,y:bt(e)};return Pt(n,r)}function yn(n){let t=[];for(let e=0;e+3<n.length;e+=3){let r=n.slice(e,e+4);for(let o=0;o<16;o++)t.push(ge(r,o/16))}return t.push(n[n.length-1]),t}function gn(n,t,e){let r=null,o=null;for(let i of Dt(n)){let l=yn(i.points),a=l.length,c=i.closed?a:a-1;for(let u=0;u<c;u++){let y=l[u],m=l[(u+1)%a],p={x:m.x-y.x,y:m.y-y.y},g={x:y.x-t.x,y:y.y-t.y},O=p.x*e.y-e.x*p.y;if(O===0)continue;let C=(p.x*g.y-p.y*g.x)/O,J=(e.x*g.y-e.y*g.x)/O;C>0&&J>=0&&J<=1&&((r===null||C<r)&&(r=C),C<=1&&(o===null||C>o)&&(o=C))}}let s=o??r;return s===null?null:{x:t.x+e.x*s,y:t.y+e.y*s}}function xn(n,t){let e=Mt(n),r=Ft(n),o=Se(n,t),s=o.x-r.x,i=o.y-r.y;if(!((s!==0||i!==0)&&e.width>0&&e.height>0))return r;if(n.kind==="path"){let u=gn(n,r,{x:s,y:i});if(u)return Pt(n,u)}let l=e.width/2,a=e.height/2,c;return n.kind==="ellipse"?c=1/Math.sqrt(s*s/(l*l)+i*i/(a*a)):n.kind==="diamond"?c=1/(Math.abs(s)/l+Math.abs(i)/a):c=Math.min(s!==0?l/Math.abs(s):1/0,i!==0?a/Math.abs(i):1/0),Pt(n,{x:r.x+s*c,y:r.y+i*c})}function Ie(n,t){let e=n.elementID?t.get(n.elementID):void 0;return e?Ft(e):{x:n.x,y:n.y}}function bn(n,t){let e=Mt(n);return Pt(n,{x:e.x+t.x*e.width,y:e.y+t.y*e.height})}function Oe(n,t,e){let r=n.elementID?e.get(n.elementID):void 0;if(!r)return{x:n.x,y:n.y};let o=n.portIndex,s=r.ports??[];return typeof o=="number"&&Number.isInteger(o)&&o>=0&&o<s.length?bn(r,s[o]):n.port?pn(r,n.port):xn(r,t)}function Fe(n,t){let e=n.connector;if(!e)return[{x:0,y:0},{x:0,y:0}];let r=e.waypoints??[];return[Oe(e.start,r.length>0?r[0]:Ie(e.end,t),t),Oe(e.end,r.length>0?r[r.length-1]:Ie(e.start,t),t)]}function De(n){if(n.kind==="polyline")return n.points;let t=[],e=n.points;for(let r=0;r<Math.floor((e.length-1)/3);r++){let o=e[3*r],s=e[3*r+1],i=e[3*r+2],l=e[3*r+3];for(let a=r===0?0:1;a<=24;a++){let c=a/24,u=1-c;t.push({x:u*u*u*o.x+3*u*u*c*s.x+3*u*c*c*i.x+c*c*c*l.x,y:u*u*u*o.y+3*u*u*c*s.y+3*u*c*c*i.y+c*c*c*l.y})}}return t}var _t=n=>n===null?null:n==="top"||n==="bottom";function wn(n){let t=[];for(let e of n){let r=t[t.length-1];if(!(r&&Math.abs(r.x-e.x)<.5&&Math.abs(r.y-e.y)<.5)){if(t.length>=2){let o=t[t.length-2],s=t[t.length-1];if(Math.abs(o.x-s.x)<.5&&Math.abs(s.x-e.x)<.5||Math.abs(o.y-s.y)<.5&&Math.abs(s.y-e.y)<.5){t[t.length-1]=e;continue}}t.push(e)}}return t.length>=2?t:n}function kn(n,t){switch(t.routing){case"straight":return{kind:"polyline",points:n};case"curved":{let e=[n[0]];for(let r=0;r<n.length-1;r++){let o=n[Math.max(r-1,0)],s=n[r],i=n[r+1],l=n[Math.min(r+2,n.length-1)];e.push({x:s.x+(i.x-o.x)/6,y:s.y+(i.y-o.y)/6}),e.push({x:i.x-(l.x-s.x)/6,y:i.y-(l.y-s.y)/6}),e.push(i)}return{kind:"curve",points:e}}case"elbow":{let e=n[0],r=n[1],o=_t(t.start.port)??Math.abs(r.y-e.y)>Math.abs(r.x-e.x),s=_t(t.end.port),i=[e];for(let l=1;l<n.length;l++){let a=n[l],c=i[i.length-1],u=Math.abs(c.x-a.x)<.5,y=Math.abs(c.y-a.y)<.5;if(u||y){i.push(a),u!==y&&(o=!u);continue}let m=l===n.length-1&&s!==null?!s:o;i.push(m?{x:c.x,y:a.y}:{x:a.x,y:c.y},a),o=m}return{kind:"polyline",points:wn(i)}}}}function Ce(n,t){let e=n.connector;if(!e)return{kind:"polyline",points:[]};let[r,o]=Fe(n,t);if(e.waypoints&&e.waypoints.length>0)return kn([r,...e.waypoints.map(a=>({x:a.x,y:a.y})),o],e);let s=o.x-r.x,i=o.y-r.y,l=Math.abs(s)>=Math.abs(i);switch(e.routing){case"straight":return{kind:"polyline",points:[r,o]};case"curved":return l?{kind:"curve",points:[r,{x:r.x+s/2,y:r.y},{x:o.x-s/2,y:o.y},o]}:{kind:"curve",points:[r,{x:r.x,y:r.y+i/2},{x:o.x,y:o.y-i/2},o]};case"elbow":{let a=_t(e.start.port)??!l,c=_t(e.end.port)??!l;if(a&&c){let u=r.y+i/2;return{kind:"polyline",points:[r,{x:r.x,y:u},{x:o.x,y:u},o]}}if(!a&&!c){let u=r.x+s/2;return{kind:"polyline",points:[r,{x:u,y:r.y},{x:u,y:o.y},o]}}return a?{kind:"polyline",points:[r,{x:r.x,y:o.y},o]}:{kind:"polyline",points:[r,{x:o.x,y:r.y},o]}}}}var Te=new WeakMap;function Ht(n){let t=n.elements,e=Te.get(t);if(e&&e.members.length===t.length&&e.members.every((o,s)=>o===t[s]))return e.index;let r=new Map;for(let o of t)r.has(o.id)||r.set(o.id,o);return Te.set(t,{members:[...t],index:r}),r}function Ge(n,t,e){let r=n[1]+e>>>0,o=r<n[1]?1:0;return[n[0]+t+o>>>0,r]}function Mn(n,t){let e=n&65535,r=n>>>16,o=t&65535,s=t>>>16,i=e*o,l=e*s,a=r*o,c=r*s,u=l+a,y=i+u%65536*65536;return[c+Math.floor(u/65536)+Math.floor(y/4294967296)>>>0,y>>>0]}function Ne(n,t,e){let r=Mn(n[1],e);return[r[0]+Math.imul(n[0],e)+Math.imul(n[1],t)>>>0,r[1]]}function te(n,t){let e=(n[1]>>>t|n[0]<<32-t)>>>0;return[(n[0]^n[0]>>>t)>>>0,(n[1]^e)>>>0]}function Pn(n){return n=Ne(te(n,30),3210233709,484763065),n=Ne(te(n,27),2496678331,321982955),te(n,31)}var Wt=class{constructor(t){V(this,"state");this.state=Ge([0,t>>>0],2654435769,2135587861)}next(){return this.state=Ge(this.state,2654435769,2135587861),Pn(this.state)}top53(){let[t,e]=this.next();return t*2097152+(e>>>11)}signed(){return Math.floor(this.top53())/2**52-1}unit(){return this.top53()/2**53}};var ve=(n,t,e)=>n.signed()*t*e;function ee(n,t,e,r,o,s,i){let l=Math.hypot(t.x-n.x,t.y-n.y);if(!(l>.5))return;let a=l<200?1:l>500?.4:-.0016668*l+1.233334,c=l<20?l/10:2;for(let u=0;u<2;u++){let y=(u===0?1:.5)*a,m=()=>ve(e,c,r)*y,p=e.unit()*.4+.3,g=ve(e,l/60,r)*o*a,O=t.x-n.x,C=t.y-n.y,J=-C/l,q=O/l,Q=s?n:{x:n.x+m(),y:n.y+m()},st=s?t:{x:t.x+m(),y:t.y+m()},x=n.x+O*p*.66+J*g+m()*.5,k=n.y+C*p*.66+q*g+m()*.5,v=n.x+O*(.5+p*.5)+J*g+m()*.5,j=n.y+C*(.5+p*.5)+q*g+m()*.5;i.moveTo(Q),i.curveTo(st,{x,y:k},{x:v,y:j})}}function ne(n,t,e,r){let o=new tt;for(let s=0;s<n.length;s++)ee(n[s],n[(s+1)%n.length],t,e,r,!1,o);return o}function Le(n,t,e){let r=new tt,o=n.x+n.width/2,s=n.y+n.height/2,i=n.width/2,l=n.height/2;if(!(i>.5&&l>.5))return r;let a=Math.max(8,Math.min(24,Math.trunc((i+l)/6))),c=Math.min(2.5,(i+l)/25)*e;for(let u=0;u<2;u++){let y=t.unit()*2*Math.PI,m=2*Math.PI*(u===0?1:1.04),p=Math.trunc(a*m/(2*Math.PI))+1,g=[];for(let O=0;O<p;O++){let C=y+m*O/a,J=t.signed()*c,q=t.signed()*c;g.push({x:o+i*Math.cos(C)+J,y:s+l*Math.sin(C)+q})}En(g,r)}return r}function En(n,t){if(!(n.length<=2)){t.moveTo(n[0]);for(let e=0;e<n.length-1;e++){let r=n[Math.max(e-1,0)],o=n[e],s=n[e+1],i=n[Math.min(e+2,n.length-1)];t.curveTo(s,{x:o.x+(s.x-r.x)/6,y:o.y+(s.y-r.y)/6},{x:s.x-(i.x-o.x)/6,y:s.y-(i.y-o.y)/6})}}}var Rn=-41*Math.PI/180;var jt=class{constructor(t=6e3){V(this,"map",new Map);V(this,"limit");this.limit=t}get(t,e){let r=this.map.get(t);if(r!==void 0)return r;let o=e();return this.map.size>=this.limit&&this.map.clear(),this.map.set(t,o),o}},An=new jt,fr=new jt;function In(n,t){let e=n.style;return[t,n.kind,n.x,n.y,n.width,n.height,n.seed,e.roughness,e.bowing,e.strokeWidth,e.fillStyle,e.fillStyle==="grid"?On(n):0,n.path?n.path.join(","):n.subpaths?JSON.stringify(n.subpaths):""].join("|")}var On=n=>Math.max(8,n.style.gridSize??50);function _e(n){return n.kind==="freehand"&&n.path===null?Ue(n):An.get(In(n,0),()=>Ue(n))}function Tn(n){return[{x:n.x,y:n.y},{x:wt(n),y:n.y},{x:wt(n),y:kt(n)},{x:n.x,y:kt(n)}]}function Be(n){return[{x:xt(n),y:n.y},{x:wt(n),y:bt(n)},{x:xt(n),y:kt(n)},{x:n.x,y:bt(n)}]}function Ue(n){let t=Mt(n),e=new Wt(n.seed),r=n.style.roughness;switch(n.kind){case"ellipse":return r<=0?tt.ellipse(t):Le(t,e,r);case"diamond":return r<=0?new tt().addLines(Be(t)).close():ne(Be(t),e,r,n.style.bowing);case"text":case"connector":return tt.rect(t);case"freehand":return Dn(n);case"path":return r<=0?Ae(n):Fn(n,e);default:return r<=0?tt.rect(t):ne(Tn(t),e,r,n.style.bowing)}}function Fn(n,t){let e=n.style.roughness,r=new tt;for(let o of Dt(n)){let s=o.points;for(let i=0;i<(s.length-1)/3;i++){let l=s[3*i],a=s[3*i+1],c=s[3*i+2],u=s[3*i+3];if(a.x===l.x&&a.y===l.y&&c.x===u.x&&c.y===u.y){ee(l,u,t,e,n.style.bowing,!0,r);continue}let y=Math.hypot(a.x-l.x,a.y-l.y)+Math.hypot(c.x-a.x,c.y-a.y)+Math.hypot(u.x-c.x,u.y-c.y),m=Math.min(2.5,y/30)*e;for(let p=0;p<2;p++){let g=p===0?1:.5,O=()=>t.signed()*m*g;r.moveTo(l);let C=a.x+O(),J=a.y+O(),q=c.x+O(),Q=c.y+O();r.curveTo(u,{x:C,y:J},{x:q,y:Q})}}}return r}function Dn(n){let t=Mt(n),e=n.path;if(e&&e.length>=8&&(e.length-2)%6===0){let s=l=>({x:t.x+e[2*l]*t.width,y:t.y+e[2*l+1]*t.height}),i=new tt().moveTo(s(0));for(let l=0;l<Math.floor((e.length/2-1)/3);l++)i.curveTo(s(3*l+3),s(3*l+1),s(3*l+2));return i}let r=(n.points??[]).map(s=>({x:t.x+s.x*t.width,y:t.y+s.y*t.height})),o=new tt;if(r.length===0)return o;if(o.moveTo(r[0]),r.length===1)return o.lineTo(r[0]);if(r.length===2)return o.lineTo(r[1]);for(let s=1;s<r.length-1;s++)o.quadTo({x:(r[s].x+r[s+1].x)/2,y:(r[s].y+r[s+1].y)/2},r[s]);return o.lineTo(r[r.length-1])}function He(n,t,e=Ht(t)){if(n.kind==="connector")return new pt(De(Ce(n,e)));let r=Lt(n);r.style.roughness=0;let o=_e(r).contours()[0]??[];return new pt(Tt(n)===0?o:o.map(s=>Pt(n,s)))}var ze=.5,se=160,ie=12,le={r:.95,g:.36,b:.33,a:1},Et=(n,t,e,r)=>n===null||!Number.isFinite(n)?t:Math.min(Math.max(n,e),r);function Ct(n,t){let e=(t+1099511627776)%281474976710656;return n.slice(0,24)+(e<0?e+2**48:e).toString(16).toUpperCase().padStart(12,"0")}var We=n=>n===null||!Number.isFinite(n)?1:Math.min(Math.max(n,0),1e6),je=new WeakMap,zt=new Map;function Cn(n){let t=n.elements,e=je.get(t);if(e&&e.members.length===t.length&&e.members.every((l,a)=>l===t[a]))return e.graph;let r=new Set(t.filter(l=>l.kind!=="connector").map(l=>l.id)),o=[];for(let l of t){let a=l.connector;a&&o.push([l.id,a.start.elementID,a.end.elementID,String(We(a.cost)),a.startHead!=="none"?"both":"one"])}let s=JSON.stringify([[...r],o]),i=zt.get(s);if(!i){let l=new Map,a=(c,u)=>{let y=l.get(c);y?y.push(u):l.set(c,[u])};for(let c of t){let u=c.connector,y=u?.start.elementID??null,m=u?.end.elementID??null;if(!u||y===null||m===null||y===m||!r.has(y)||!r.has(m))continue;let p=We(u.cost);a(y,{to:m,via:c.id,back:!1,cost:p}),u.startHead!=="none"&&a(m,{to:y,via:c.id,back:!0,cost:p})}i={shapes:r,next:l,trees:new Map},zt.size>=16&&zt.clear(),zt.set(s,i)}return je.set(t,{members:[...t],graph:i}),i}var re=class{constructor(){V(this,"heap",[])}get size(){return this.heap.length}less(t,e){let r=this.heap[t],o=this.heap[e];return r.dist<o.dist||r.dist===o.dist&&r.order<o.order}swap(t,e){[this.heap[t],this.heap[e]]=[this.heap[e],this.heap[t]]}push(t,e,r){this.heap.push({id:t,dist:e,order:r});for(let o=this.heap.length-1;o>0;){let s=o-1>>1;if(!this.less(o,s))break;this.swap(o,s),o=s}}pop(){let t=this.heap[0],e=this.heap.pop();if(this.heap.length>0){this.heap[0]=e;for(let r=0;;){let o=2*r+1,s=o+1,i=r;if(o<this.heap.length&&this.less(o,i)&&(i=o),s<this.heap.length&&this.less(s,i)&&(i=s),i===r)break;this.swap(r,i),r=i}}return t}};function $t(n,t,e=new Set,r){let o=Cn(t),s=JSON.stringify([n,r??null,[...e].sort()]);if(o.trees.has(s))return o.trees.get(s);let i=Gn(o,n,e,r);return o.trees.size>=4096&&o.trees.clear(),o.trees.set(s,i),i}function Gn({shapes:n,next:t},e,r,o){if(!n.has(e)||r.has(e))return null;let s=new Map([[e,0]]),i=new Map([[e,0]]),l=1,a=new oe(e),c=new re;for(c.push(e,0,0);c.size>0;){let{id:u,order:y}=c.pop();if(!(a.settled.has(u)||i.get(u)!==y)){if(a.settled.add(u),u===o&&u!==e)break;for(let m of t.get(u)??[]){if(r.has(m.via)||r.has(m.to)||a.settled.has(m.to))continue;let p=s.get(u)+m.cost,g=s.get(m.to);g!==void 0&&g<=p||(s.set(m.to,p),i.set(m.to,l),c.push(m.to,p,l++),a.came.set(m.to,{from:u,via:m.via,back:m.back}))}}}return a}var oe=class{constructor(t){V(this,"settled",new Set);V(this,"came",new Map);V(this,"from");this.from=t}goals(t,e){let r=t.filter(o=>o!==this.from&&this.settled.has(o));return r.length===0?[]:e&&r[0]!==t[0]?r:[r[0]]}hops(t){let e=[];for(let r=t,o=this.came.get(r);o;r=o.from,o=this.came.get(r))e.push([o.via,o.back]);return e.reverse()}};var Nn=()=>({elements:new Map,flows:new Map,carry:{}});function Ye(n,t,e){let r=n.flows.get(e);if(r)switch(t){case"throughput":return r.placed;case"backlog":return r.backlog;case"backup":return r.backup;case"transit":return r.transit;default:return null}let o=n.elements.get(e);if(!o)return null;switch(t){case"throughput":return o.throughput;case"load":return o.load;case"delay":return o.delay;case"backlog":return o.backlog;case"inFlight":return o.inFlight;case"depth":return o.depth;default:return null}}var B=1e-9,fe=n=>Et(n.volume,1,0,1e12);function ae(n,t){if(t===null||!n.overrides)return fe(n);let e=null;for(let r of n.overrides)r.volume!==null&&!Jt(r.when)&&Ut(r.when,t)&&(e=r.volume);return e===null?fe(n):Math.min(Math.max(Number.isFinite(e)?e:1,0),1e12)}function $e(n){let t=n.delay??null;return n.kind==="connector"||t===null||!Number.isFinite(t)?0:Math.min(Math.max(t,0),3600)}var ue=(n,t)=>n+"|"+t;function Xe(n,t,e,r,o=new Set,s=null,i={}){let l=Math.max(0,Math.min(s??e,1e6)),a=Ht(t),c=new Map,u=h=>{let d=c.get(h.id);return d||(d=He(h,t,a).points,c.set(h.id,d)),d},y=Nn();for(let h of t.elements)h.kind==="connector"&&!h.connector||y.elements.set(h.id,{throughput:0,load:null,delay:h.kind!=="connector"?$e(h):0,backlog:0,inFlight:0,depth:0});let m=n??[],p=new Map;for(let h of t.elements){let d=h.capacity??null;d!==null&&Number.isFinite(d)&&p.set(h.id,Math.max(d,0))}let g=()=>new Set([...p].filter(([,h])=>h<=B).map(([h])=>h)),O=(h,d)=>{let P=[],N=[],S=d;for(let E=h.came.get(S);E;E=h.came.get(S))P.push([E.via,E.back]),N.push(S),S=E.from;return N.push(S),{hops:P.reverse(),shapes:N.reverse()}},C=(h,d)=>{let P=[],N=[],S=[],E=0;return h.forEach(([z,rt],_)=>{let ut=a.get(z);if(!ut)return;let T=rt?[...u(ut)].reverse():u(ut);if(T.length===0)return;let et=P[P.length-1];if(et){let X=Math.hypot(T[0].x-et.x,T[0].y-et.y),ht=a.get(d[_]);N.push([E,E+X,ht?$e(ht):0]),E+=X}let ft=E;for(let X=1;X<T.length;X++)E+=Math.hypot(T[X].x-T[X-1].x,T[X].y-T[X-1].y);S.push([z,ft,E]),P.push(...T)}),E>0?{line:new pt(P),length:E,inside:N,stretches:S}:null},J=(h,d,P)=>{let N=d,S=0;for(let[E,z,rt]of h.inside){let _=(E-S)/P;if(N<=_)break;N-=_,S=E;let ut=(z-E)/P+rt;if(N<ut)return null;N-=ut,S=z}return S+=N*P,S>=0&&S<=h.length?S:null},q=(h,d)=>new Set([...h,...d]),Q=(h,d)=>{let P=y.elements.get(h);P&&d(P)},st=new Map,x=[];for(let h of m){let d=st.get(h.from)??0;x.push(d),st.set(h.from,d+1)}let k=m.length>0?Math.max(...m.map(fe)):1,v=[],j=new Map,Y=h=>Math.min(Math.max(Et(h.every,ze,.05,60)*k/Math.max(ae(h,r),B),.05),60),lt=new Map,at=h=>(lt.has(h)||lt.set(h,$t(h,t,o)),lt.get(h));for(let[h,d]of m.entries()){if(d.when!==null&&r!==null&&!Ut(d.when,r))continue;let P=a.get(d.from),N=P?at(d.from):null;if(!P||!N)continue;let S=ae(d,r),E={volume:S,placed:0,backlog:0,backup:0,transit:null},z=[],rt=[],_=N.goals(d.to,d.spread===!0),ut=_.length>1?_.map(F=>[[F],S/_.length]):[[d.to,S]];for(let[F,R]of ut){if(!(R>B))continue;let D=R;for(let A=0;A<32&&D>B;A++){let W=$t(d.from,t,q(o,g()),F[0]),$=W?.goals(F,!1)[0];if(!W||$===void 0)break;let I=O(W,$),L=[...I.shapes,...I.hops.map(([M])=>M)],U=L.filter(M=>p.has(M)).map(M=>p.get(M)),G=Math.min(D,U.length>0?Math.min(...U):1/0);if(!(G>B))break;for(let M of L)p.has(M)&&p.set(M,p.get(M)-G);z.push({hops:I.hops,shapes:I.shapes,goal:$,amount:G}),D-=G}if(!(D>B))continue;let H=d.from,dt=N.goals(F,!1)[0];if(dt!==void 0){let A=O(N,dt),W=g(),$=[[A.shapes[0],A.shapes[0]]];A.hops.forEach(([U],G)=>{$.push([U,A.shapes[G]],[A.shapes[G+1],A.shapes[G]])});let I=$.find(([U])=>W.has(U));if(I){H=I[1];let U=A.shapes.indexOf(H);for(let G=U;G>=0;G--){let M=a.get(A.shapes[G]);if(M&&M.queue===!0&&M.kind!=="connector"){H=A.shapes[G];break}}}let L=A.shapes.indexOf(H);if(H!==d.from&&L>=0){let U=A.shapes.slice(0,L+1),G=A.hops.slice(0,L);for(let M of[...U,...G.map(([Kt])=>Kt)])p.has(M)&&p.set(M,Math.max(0,p.get(M)-D));z.push({hops:G,shapes:U,goal:H,amount:D,waits:!0})}}let K=rt.find(([A])=>A===H);K?K[1]+=D:rt.push([H,D])}j.set(d.id,rt);for(let F of z){for(let R of[...F.shapes,...F.hops.map(([D])=>D)])Q(R,D=>{D.throughput+=F.amount});F.waits||(E.placed+=F.amount)}for(let[F,R]of rt)Q(F,D=>{D.backlog+=R}),E.backlog+=R;let T=z.filter(F=>!F.waits&&F.goal===d.to[0]).reduce((F,R)=>F+R.amount,0);E.backup=S>B?Math.max(0,(S-T)/S):0;let et=Y(d),ft=Et(d.speed,se,1,1e4),X=Et(d.size,ie,2,200),ht=x[h]/st.get(d.from)*et,gt=d.color??le,Z=[],At=0;for(let F of z)At+=F.amount/Math.max(S,B),Z.push(At);Z.length>0&&Math.abs(Z[Z.length-1]-1)<1e-9&&(Z[Z.length-1]=1);let Nt=0;z.forEach((F,R)=>{let D=C(F.hops,F.shapes);if(!D)return;let H=D.length/ft+D.inside.reduce((I,L)=>I+L[2],0);F.waits||(Nt+=H*F.amount);let dt=Math.ceil((e-ht-H)/et),K=Math.floor((e-ht)/et),A=R===0?0:Z[R-1],W=Z[R],$=(I,L)=>Math.floor((L+1)*I)-Math.floor(L*I);for(let I=Math.max(dt,K-3999);I<=K;I++){if($(W,I)-$(A,I)!==1)continue;let L=J(D,e-I*et-ht,ft);if(L===null)continue;let U=D.stretches.find(([,M,Kt])=>L>=M&&L<=Kt);U&&Q(U[0],M=>{M.inFlight+=1});let G=D.line.point(L/D.length);v.push(ce(Ct(d.id,I),G.x-X/2,G.y-X/2,X,gt,P.layerID))}}),E.transit=E.placed>B?Nt/E.placed:null,y.flows.set(d.id,E)}let Rt=new Map,Gt=Object.keys(i).filter(h=>i[h]>B);for(let h of m){let d=j.get(h.id)??[],P=d.map(([T])=>T),N="|"+h.id;if(Gt.some(T=>T.endsWith(N)))for(let T of t.elements){let et=i[ue(T.id,h.id)];et!==void 0&&et>B&&!P.includes(T.id)&&P.push(T.id)}if(P.length===0)continue;let S=ae(h,r),z=Y(h)*Math.max(S,B),rt=Et(h.speed,se,1,1e4),_=Et(h.size,ie,2,200),ut=h.color??le;P.forEach((T,et)=>{let ft=a.get(T);if(!ft)return;let X=a.get(h.from)?.layerID??ft.layerID,ht=d.find(([R])=>R===T)?.[1]??0,gt=Math.max(0,i[ue(T,h.id)]??0),Z=gt+ht*l;if(ht<=B&&gt>B){let R=new Map(p),D=[],H=0;for(let dt=0;dt<32;dt++){let K=new Set([...R].filter(([,M])=>M<=B).map(([M])=>M)),A=$t(T,t,q(o,K),h.to[0]),W=A?.goals(h.to,!1)[0];if(!A||W===void 0)break;let $=O(A,W),I=[...$.shapes.slice(1),...$.hops.map(([M])=>M)],L=I.filter(M=>R.has(M)).map(M=>R.get(M)),U=L.length>0?Math.min(...L):1/0,G=Number.isFinite(U)?U:Math.max(gt/.5-H,B*2);if(!(G>B))break;for(let M of I)R.has(M)&&R.set(M,R.get(M)-G);if(D.push({hops:$.hops,shapes:$.shapes,rate:G}),H+=G,!Number.isFinite(U))break}if(H>B){if(Z=Math.max(0,gt-H*l),Z>B){for(let[K,A]of R)p.set(K,A);for(let K of D)for(let A of[...K.shapes,...K.hops.map(([W])=>W)])Q(A,W=>{W.throughput+=K.rate})}let dt=gt/H;D.forEach((K,A)=>{let W=C(K.hops,K.shapes);if(!W)return;let $=Math.max(z/K.rate,.05);for(let I=0;I*$<dt&&I*$<=l&&I<2048;I++){let L=J(W,l-I*$,rt);if(L===null)continue;let U=W.line.point(L/W.length);v.push(ce(Ct(h.id,2**39+2**20+et*2**14+A*2**11+I),U.x-_/2,U.y-_/2,_,ut,X))}})}}if(!(Z>B||ht>B))return;Q(T,R=>{R.depth+=Z}),Z>B&&(y.carry[ue(T,h.id)]=Z);let At=Math.min(Math.max(Math.ceil(Z/z-1e-9),1),30),Nt=Math.trunc((At+9)/10),F=Rt.get(T)??0;Rt.set(T,F+Nt);for(let R=0;R<At;R++){let D=ft.x+2+_/2+R%10*(_+3),H=ft.y-4-_/2-(F+Math.trunc(R/10))*(_+3);v.push(ce(Ct(h.id,2**39+et*64+R),D-_/2,H-_/2,_,ut,X))}})}for(let h of t.elements){let d=h.capacity??null,P=y.elements.get(h.id);d===null||!Number.isFinite(d)||!P||(P.load=d>0?P.throughput/d:1)}return{packets:v,metrics:y}}var Ze={seed:1,text:null,connector:null,groupID:null,points:null,path:null,subpaths:null,evenOdd:null,rotation:null,link:null,url:null,anchor:null,click:null,hover:null,when:null,overrides:null,symbol:null,playback:null,offset:null,args:null,image:null,reveal:null};function Je(n,t,e,r="solid",o=null){return{stroke:{...n},fill:{...t},fillStyle:r,strokeWidth:e,dash:"solid",roughness:0,bowing:1,fontSize:18,font:null,gridSize:null,opacity:o,dashOffset:null,textColor:null}}function ce(n,t,e,r,o,s){return{...Ze,id:n,kind:"ellipse",layerID:s,x:t,y:e,width:r,height:r,style:Je(o,o,1.5)}}function vn(n,t){let e=new Map;for(let o of t.elements)o.anchor!==null&&!e.has(o.anchor)&&e.set(o.anchor,o.id);let r=/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/;return(o,s)=>{let i=o.target===""?s:e.get(o.target)??(r.test(o.target)?o.target.toUpperCase():null);return i===null?null:Ye(n,o.metric,i)}}function qe(n,t,e,r,o=1/0,s={}){let i=vn(t,r),l=[],a={};for(let c of n){let u=[];e!==null&&c.overrides&&c.overrides.forEach((g,O)=>{Jt(g.when)&&Ut(g.when,e,C=>i(C,c.id))&&u.push(O)});let y=e===null?null:c.gauge;if(!y){l.push({applied:u,gauge:null});continue}let m=Ye(t,y.metric,y.of),p=s[Ke(c.id)];if(m!==null&&p!==void 0&&y.metric!=="depth"&&y.metric!=="inFlight"&&o<Ve){let g=Math.max(0,o/Ve),O=g*g*(3-2*g);m=p+(m-p)*O}m!==null&&(a[Ke(c.id)]=m),l.push({applied:u,gauge:{value:m}})}return{plan:l,readings:a}}var Ke=n=>"gauge|"+n,Ve=1,St=n=>{let t=parseInt(n.slice(1),16);return{r:(t>>16&255)/255,g:(t>>8&255)/255,b:(t&255)/255,a:1}},Ln=St("#16a34a"),Bn=St("#d97706"),Un=St("#dc2626"),_n=St("#2f6fdf"),he=St("#e5e7eb"),Hn=St("#9ca3af");function Wn(n,t){if(t===null||!Number.isFinite(t))return"\u2013";switch(n){case"load":case"backup":return me(t*100,0)+"%";case"transit":case"delay":return me(t,Math.abs(t)>=10?1:2)+"s";default:return me(t,Math.abs(t)>=100?0:Math.abs(t)>=10?1:2)}}function me(n,t){let e=t===0?1:t===1?10:100,r=Math.floor(Math.abs(n)*e+.5);if(!(r<1e15))return n<0?"-\u221E":"\u221E";let o=Math.trunc(r/e),s=r-o*e,i=String(o);if(t>0&&s>0){let l=String(s);for(;l.length<t;)l="0"+l;for(;l.endsWith("0");)l=l.slice(0,-1);i+="."+l}return(n<0&&r>0?"-":"")+i}function Qe(n,t,e,r,o){let s=r.elements.find(x=>x.id===t.of),i=t.max??(t.metric==="load"?1:s?.capacity??e??1),l=e===null?0:i>0?Math.min(Math.max(e/i,0),1):0,a=t.warn??(t.metric==="load"?.7:null),c=t.alarm??(t.metric==="load"?.9:null),u=a===null&&c===null?_n:Ln;e!==null&&a!==null&&e>=a&&(u=Bn),e!==null&&c!==null&&e>=c&&(u=Un),e===null&&(u=Hn);let y=t.label;if(y===null){let x=s?s.text!==null?s.text.split(`
3
- `)[0]:s.anchor:null;y=`${t.metric} ${x??(o.some(k=>k.id===t.of)?"flow":"?")}`}let m=t.style??"number",p=Math.max(n.width,1),g=Math.max(n.height,1),O=(x,k)=>[x.x/p,x.y/g,(x.x+(k.x-x.x)/3)/p,(x.y+(k.y-x.y)/3)/g,(x.x+2*(k.x-x.x)/3)/p,(x.y+2*(k.y-x.y)/3)/g,k.x/p,k.y/g],C=(x,k,v,j)=>{let Y=[{x,y:k},{x:x+v,y:k},{x:x+v,y:k+j},{x,y:k+j}],lt=O(Y[0],Y[1]);for(let at=1;at<4;at++)lt=lt.concat(O(Y[at],Y[(at+1)%4]).slice(2));return{closed:!0,coords:lt}},J=(x,k,v,j)=>{let Y=Math.max(1,Math.ceil(Math.abs(j-v)/(Math.PI/2)-1e-9)),lt=(j-v)/Y,at=4/3*Math.tan(lt/4),Rt=d=>({x:x.x+k*Math.cos(d),y:x.y+k*Math.sin(d)}),Gt=Rt(v),h=[Gt.x/p,Gt.y/g];for(let d=0;d<Y;d++){let P=v+d*lt,N=P+lt,S=Rt(P),E=Rt(N),z={x:S.x-at*k*Math.sin(P),y:S.y+at*k*Math.cos(P)},rt={x:E.x+at*k*Math.sin(N),y:E.y-at*k*Math.cos(N)};h.push(z.x/p,z.y/g,rt.x/p,rt.y/g,E.x/p,E.y/g)}return{closed:!1,coords:h}},q=(x,k,v,j,Y)=>({...Ze,id:Ct(n.id,-(2**38)-x),kind:"path",layerID:n.layerID,x:n.x,y:n.y,width:n.width,height:n.height,style:Je(v,j??{r:0,g:0,b:0,a:0},Y,"solid",n.style.opacity),subpaths:k}),Q={...n,gauge:null,kind:"path",subpaths:[C(0,0,p,g)],text:y+`
4
- `+Wn(t.metric,e),style:{...n.style}},st=[];if(m==="number")Q.labelRect={x:0,y:0,width:1,height:1},Q.style.textColor={...u};else if(m==="bar"){Q.labelRect={x:0,y:0,width:1,height:.66};let x=Math.min(10,p*.08),k=Math.min(12,g*.18),v=g*.72,j=p-2*x;st.push(q(1,[C(x,v,j,k)],he,he,.5)),l>0&&st.push(q(2,[C(x,v,j*l,k)],u,u,.5))}else{Q.labelRect={x:0,y:.54,width:1,height:.46};let x=Math.min(p*.38,g*.4),k={x:p/2,y:g*.5},v=Math.max(2,x*.16);st.push(q(1,[J(k,x,Math.PI,2*Math.PI)],he,null,v)),l>0&&st.push(q(2,[J(k,x,Math.PI,Math.PI+Math.PI*l)],u,null,v));let j=Math.PI+Math.PI*l,Y={x:k.x+x*.85*Math.cos(j),y:k.y+x*.85*Math.sin(j)};st.push(q(3,[{closed:!1,coords:O(k,Y)}],{r:.2,g:.2,b:.2,a:1},null,2))}return[Q,...st]}var de=null;function jn(n){de=Ee({version:2,pages:[JSON.parse(n)]}).pages[0]}function zn(n){if(!de)throw new Error("no page");let t=JSON.parse(n);t.values??(t.values=null),t.since??(t.since=null),t.offline??(t.offline=[]),t.carried??(t.carried={});let e=de,r=Xe(e.flows,e,t.t,t.values,new Set(t.offline),t.since,t.carried),o=Math.max(0,Math.min(t.since??t.t,1e6)),{plan:s,readings:i}=qe(e.elements,r.metrics,t.values,e,o,t.carried),l=[];return e.elements.forEach((a,c)=>{let{applied:u,gauge:y}=s[c];if(u.length===0&&!y)return;let m=a;for(let p of u)m=Qt(qt(a.overrides[p]),m);l.push([a.id,u,y&&m.gauge?$n(Qe(m,m.gauge,y.value,e,e.flows??[])):null])}),JSON.stringify({packets:r.packets.map(a=>[a.id,a.x,a.y,a.width,a.layerID]),elements:Object.fromEntries(r.metrics.elements),flows:Object.fromEntries(r.metrics.flows),carry:{...r.metrics.carry,...i},finish:l})}function $n([n,...t]){let e=n.labelRect;return{text:n.text??"",label:[e.x,e.y,e.width,e.height],textColor:n.style.textColor,subpaths:n.subpaths??[],parts:t.map(r=>[r.id,r.subpaths??[],r.style.stroke,r.style.fill.a>0?r.style.fill:null,r.style.strokeWidth])}}globalThis.DottieSim={page:jn,frame:zn};})();
1
+ /*! dottie.js 0.10.0 | Apache-2.0 | https://github.com/phin-tech/dottie */
2
+ "use strict";(()=>{var xn=Object.defineProperty;var bn=(t,e,n)=>e in t?xn(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var K=(t,e,n)=>bn(t,typeof e!="symbol"?e+"":e,n);var St=.5522847498307936,se=class t{constructor(){K(this,"segments",[])}get isEmpty(){return this.segments.length===0}moveTo(e){return this.segments.push({op:"M",p:e}),this}lineTo(e){return this.segments.push({op:"L",p:e}),this}quadTo(e,n){return this.segments.push({op:"Q",c:n,p:e}),this}curveTo(e,n,o){return this.segments.push({op:"C",c1:n,c2:o,p:e}),this}close(){return this.segments.push({op:"Z"}),this}addPath(e){return this.segments.push(...e.segments),this}addLines(e){return e.forEach((n,o)=>o===0?this.moveTo(n):this.lineTo(n)),this}static rect(e){return new t().addLines([{x:e.x,y:e.y},{x:e.x+e.width,y:e.y},{x:e.x+e.width,y:e.y+e.height},{x:e.x,y:e.y+e.height}]).close()}addEllipse(e){let n=e.x+e.width/2,o=e.y+e.height/2,r=e.width/2,s=e.height/2,i=r*St,l=s*St;return this.moveTo({x:n+r,y:o}),this.curveTo({x:n,y:o+s},{x:n+r,y:o+l},{x:n+i,y:o+s}),this.curveTo({x:n-r,y:o},{x:n-i,y:o+s},{x:n-r,y:o+l}),this.curveTo({x:n,y:o-s},{x:n-r,y:o-l},{x:n-i,y:o-s}),this.curveTo({x:n+r,y:o},{x:n+i,y:o-s},{x:n+r,y:o-l}),this.close()}static ellipse(e){return new t().addEllipse(e)}translated(e,n){let o=s=>({x:s.x+e,y:s.y+n}),r=new t;return r.segments=this.segments.map(s=>{switch(s.op){case"M":case"L":return{op:s.op,p:o(s.p)};case"Q":return{op:"Q",c:o(s.c),p:o(s.p)};case"C":return{op:"C",c1:o(s.c1),c2:o(s.c2),p:o(s.p)};case"Z":return s}}),r}contours(){let e=[],n=[],o={x:0,y:0};for(let r of this.segments){let s=n.length?n[n.length-1]:o;switch(r.op){case"M":n.length>1&&e.push(n),o=r.p,n=[r.p];break;case"L":n.push(r.p);break;case"Q":for(let i=1;i<=12;i++){let l=i/12,a=1-l;n.push({x:a*a*s.x+2*a*l*r.c.x+l*l*r.p.x,y:a*a*s.y+2*a*l*r.c.y+l*l*r.p.y})}break;case"C":for(let i=1;i<=16;i++){let l=i/16,a=1-l;n.push({x:a*a*a*s.x+3*a*a*l*r.c1.x+3*a*l*l*r.c2.x+l*l*l*r.p.x,y:a*a*a*s.y+3*a*a*l*r.c1.y+3*a*l*l*r.c2.y+l*l*l*r.p.y})}break;case"Z":n.push(o),n.length>1&&e.push(n),n=[o];break}}return n.length>1&&e.push(n),e}trimmed(e){let n=this.contours().map(s=>new ke(s)),o=Math.min(Math.max(e,0),1)*n.reduce((s,i)=>s+i.length,0),r=new t;for(let s of n){if(!(o>0))break;r.moveTo(s.points[0]);for(let i=1;i<s.points.length;i++){let l=s.lengths[i]-s.lengths[i-1];if(l<=o){r.lineTo(s.points[i]),o-=l;continue}let a=s.points[i-1],c=s.points[i],u=o/l;r.lineTo({x:a.x+(c.x-a.x)*u,y:a.y+(c.y-a.y)*u}),o=0;break}}return r}data(){let e=[];for(let n of this.segments)switch(n.op){case"M":e.push(`M${ue(n.p.x)} ${ue(n.p.y)}`);break;case"L":e.push(`L${ue(n.p.x)} ${ue(n.p.y)}`);break;case"Q":e.push(`Q${ue(n.c.x)} ${ue(n.c.y)} ${ue(n.p.x)} ${ue(n.p.y)}`);break;case"C":e.push(`C${ue(n.c1.x)} ${ue(n.c1.y)} ${ue(n.c2.x)} ${ue(n.c2.y)} ${ue(n.p.x)} ${ue(n.p.y)}`);break;case"Z":e.push("Z");break}return e.join(" ")}};function It(t){return t<0?-Math.round(-t):Math.round(t)}function ue(t){let e=It(t*100)/100;return Number.isInteger(e)?String(e===0?0:e):String(e)}var ke=class{constructor(e){K(this,"points");K(this,"lengths");this.points=e;let n=0;this.lengths=e.map((o,r)=>(r>0&&(n+=Math.hypot(o.x-e[r-1].x,o.y-e[r-1].y)),n))}get length(){return this.lengths.length?this.lengths[this.lengths.length-1]:0}point(e){if(this.points.length<=1||!(this.length>0))return this.points[0]??{x:0,y:0};let n=Math.min(Math.max(e,0),1)*this.length,o=1;for(;o<this.lengths.length-1&&this.lengths[o]<n;)o++;let r=this.lengths[o]-this.lengths[o-1],s=r>0?(n-this.lengths[o-1])/r:0,i=this.points[o-1],l=this.points[o];return{x:i.x+(l.x-i.x)*s,y:i.y+(l.y-i.y)*s}}},Ae=t=>t.x+t.width/2,Se=t=>t.y+t.height/2,xe=t=>t.x+t.width,be=t=>t.y+t.height;function qe(t,e,n){if(n===0)return t;let o=t.x-e.x,r=t.y-e.y;return{x:e.x+o*Math.cos(n)-r*Math.sin(n),y:e.y+o*Math.sin(n)+r*Math.cos(n)}}function Tt(t,e){let n=1-e;return{x:t[0].x*(n*n*n)+t[1].x*(3*e*n*n)+t[2].x*(3*e*e*n)+t[3].x*(e*e*e),y:t[0].y*(n*n*n)+t[1].y*(3*e*n*n)+t[2].y*(3*e*e*n)+t[3].y*(e*e*e)}}var de=(t,e,n)=>({r:t,g:e,b:n,a:1});function wn(t){let e=parseInt(t.slice(1),16);return{r:(e>>16&255)/255,g:(e>>8&255)/255,b:(e&255)/255,a:1}}var kn=["accent","muted","danger","warning","success","info"],nt=t=>kn.map((e,n)=>({name:e,color:wn(t[n])})),tt=nt(["#2563eb","#6b7280","#dc2626","#d97706","#16a34a","#0891b2"]),Qe=nt(["#93c5fd","#cbd5e1","#fca5a5","#fcd34d","#86efac","#67e8f9"]),Mn=[{id:"paper",name:"Paper",background:de(.984,.98,.965),ink:de(.12,.12,.13),palette:tt},{id:"white",name:"White",background:de(1,1,1),ink:de(.12,.12,.13),palette:tt},{id:"sepia",name:"Sepia",background:de(.953,.914,.824),ink:de(.23,.18,.13),palette:nt(["#9a3412","#78716c","#b91c1c","#b45309","#4d7c0f","#0e7490"])},{id:"blueprint",name:"Blueprint",background:de(.106,.227,.361),ink:de(.91,.945,.984),palette:Qe},{id:"chalkboard",name:"Chalkboard",background:de(.169,.227,.2),ink:de(.945,.945,.918),palette:Qe},{id:"midnight",name:"Midnight",background:de(.082,.086,.102),ink:de(.925,.925,.94),palette:Qe}];function Pn(t){return Mn.find(e=>e.id===t)??null}function En(t){let e=t.customTheme;return e?{id:"custom",name:e.name,background:e.background,ink:e.ink,palette:e.palette}:Pn(t.theme)}function et(t,e){let n=e.trim().toLowerCase();return(En(t)?.palette??tt).find(o=>o.name.toLowerCase()===n)?.color??null}function Ot(t){let e=o=>!!o.style.named;if(!t.elements.some(e)&&!(t.symbols??[]).some(o=>o.elements.some(e)))return t;let n=o=>{let r=o.style.named;if(!r)return o;let s={...o.style},i=r.fill!==null?et(t,r.fill):null,l=r.stroke!==null?et(t,r.stroke):null,a=r.textColor!==null?et(t,r.textColor):null;return i&&(s.fill={...i}),l&&(s.stroke={...l}),a&&(s.textColor={...a}),{...o,style:s}};return{...t,elements:t.elements.map(n),symbols:t.symbols?t.symbols.map(o=>({...o,elements:o.elements.map(n)})):t.symbols}}var Ct=2,Rn=["rectangle","ellipse","diamond","text","connector","freehand","path","note","image","symbol"],An=["linear","easeIn","easeOut","easeInOut","hold","spring","bounce","elastic"],Sn={file:["version","pages","images"],page:["id","name","layers","elements","theme","customTheme","guidesX","guidesY","guidesLocked","timeline","symbols","variables","flows"],flow:["id","from","to","every","speed","color","size","when","spread","volume","overrides"],flowOverride:["when","volume"],symbol:["id","name","width","height","layers","elements","timeline","button","params"],layer:["id","name","visible","locked"],rgba:["r","g","b","a"],style:["stroke","fill","fillStyle","strokeWidth","dash","roughness","bowing","fontSize","font","gridSize","opacity","dashOffset","textColor","named"],colorNames:["fill","stroke","textColor"],customTheme:["name","background","ink","palette","base"],paletteColor:["name","color"],element:["id","kind","x","y","width","height","style","seed","layerID","text","connector","groupID","points","path","subpaths","evenOdd","rotation","link","url","anchor","click","hover","when","overrides","symbol","playback","offset","args","image","reveal","ports","labelRect","extension","capacity","delay","queue","gauge","containerID","container"],container:["fixed","lanes"],gauge:["metric","of","max","warn","alarm","style","label"],strokePoint:["x","y"],subpath:["closed","coords"],inlineImage:["data","format"],endpoint:["elementID","port","portIndex","x","y"],extensionRef:["id","shape","version","params"],normalizedPoint:["x","y"],normalizedRect:["x","y","width","height"],connector:["start","end","routing","startHead","endHead","waypoints","hops","avoid","cost"],waypoint:["x","y"],timeline:["fps","duration","boil","settle","poster","tracks","camera","markers"],track:["element","keys","boil","follow","repeats","march"],keyframe:["t","x","y","width","height","rotation","strokeWidth","stroke","fill","visible","reveal","opacity","ease"],follow:["path","start","end","ease","reverse","orient","laps"],repeat:["start","end","count"],cameraKey:["t","x","y","width","height","ease"],marker:["t","name","loop"],click:["scene","url","set","toggle","reset"],hover:["stroke","fill","opacity"],override:["when","stroke","fill","textColor","opacity","strokeWidth","dash","text","reroute","offline","cost","capacity","delay"]},De=3600,Ft=1e4,In=t=>t===void 0||!Number.isFinite(t)||t===0?null:Math.min(Math.max(t,-Ft),Ft);var Tn={r:.12,g:.12,b:.13,a:1},On={r:0,g:0,b:0,a:0};var Me=class extends Error{},M=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),g=t=>typeof t=="number"&&Number.isFinite(t)?t:void 0,k=t=>typeof t=="string"?t:void 0,Dt=t=>M(t)&&Object.values(t).every(e=>typeof e=="string")?{...t}:null,me=t=>typeof t=="boolean"?t:void 0,Gt="00000000-0000-0000-0000-000000000000",Fe=/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/,fe=t=>typeof t=="string"?t.toUpperCase():void 0;function rt(t){return Number.isFinite(t)?Math.min(Math.max(t,0),De):t===1/0?De:0}function Nt(t){return Number.isFinite(t)?Math.min(Math.max(t,1),60):12}function Cn(t){let e=t.trim();return!/^(https?:\/\/|mailto:)/i.test(e)||[...e].length<=7||/[\u0000-\u001f\u007f-\u009f]/.test(e)?null:e}function ce(t){if(!M(t))return;let e=g(t.r),n=g(t.g),o=g(t.b);if(!(e===void 0||n===void 0||o===void 0))return{r:e,g:n,b:o,a:g(t.a)??1}}var st=class{constructor(){K(this,"warnings",[]);K(this,"seen",new Set)}warn(e){this.seen.has(e)||(this.seen.add(e),this.warnings.push(e))}fields(e,n){let o=Sn[n];for(let r of Object.keys(e))o.includes(r)||this.warn(`Unknown field "${r}" on ${n}, ignored`)}style(e){let n=M(e)?e:{};this.fields(n,"style");let o=k(n.fillStyle)??"solid",r=k(n.dash)??"solid";return["solid","hachure","crossHatch","grid"].includes(o)||this.warn(`Unknown fill style "${o}", drawn solid`),["solid","dashed","dotted"].includes(r)||this.warn(`Unknown dash "${r}", drawn solid`),{stroke:ce(n.stroke)??{...Tn},fill:ce(n.fill)??{...On},fillStyle:["solid","hachure","crossHatch","grid"].includes(o)?o:"solid",strokeWidth:g(n.strokeWidth)??2,dash:["solid","dashed","dotted"].includes(r)?r:"solid",roughness:g(n.roughness)??1,bowing:g(n.bowing)??1,fontSize:g(n.fontSize)??18,font:k(n.font)||null,gridSize:g(n.gridSize)??null,opacity:g(n.opacity)??null,dashOffset:g(n.dashOffset)??null,textColor:ce(n.textColor)??null,named:this.colorNames(n.named)}}container(e){return M(e)?(this.fields(e,"container"),{fixed:e.fixed===!0?!0:null,lanes:e.lanes==="rows"||e.lanes==="columns"?e.lanes:null}):null}colorNames(e){if(!M(e))return null;this.fields(e,"colorNames");let n={fill:k(e.fill)??null,stroke:k(e.stroke)??null,textColor:k(e.textColor)??null};return n.fill===null&&n.stroke===null&&n.textColor===null?null:n}customTheme(e){if(!M(e))return null;this.fields(e,"customTheme");let n=ce(e.background),o=ce(e.ink);if(!n||!o)return this.warn("A custom theme needs a background and an ink; drawn without it"),null;let r=(Array.isArray(e.palette)?e.palette:[]).filter(M).flatMap(s=>{this.fields(s,"paletteColor");let i=k(s.name),l=ce(s.color);return i&&l?[{name:i,color:l}]:[]});return{name:k(e.name)??"Custom",background:n,ink:o,palette:r,base:k(e.base)??null}}endpoint(e){let n=M(e)?e:{},o=k(n.port),r=g(n.portIndex);return{elementID:fe(n.elementID)??null,port:o&&["top","right","bottom","left"].includes(o)?o:null,portIndex:r!==void 0&&Number.isInteger(r)&&r>=0?r:null,x:g(n.x)??0,y:g(n.y)??0}}connector(e){if(!M(e))return null;this.fields(e,"connector");let n=(r,s)=>{let i=k(r);return i&&["none","arrow","triangle","dot","bar"].includes(i)?i:s},o=k(e.routing);return{start:this.endpoint(e.start),end:this.endpoint(e.end),routing:o&&["straight","curved","elbow"].includes(o)?o:"straight",startHead:n(e.startHead,"none"),endHead:n(e.endHead,"arrow"),waypoints:Array.isArray(e.waypoints)?e.waypoints.filter(M).map(r=>(this.fields(r,"waypoint"),{x:g(r.x)??0,y:g(r.y)??0})):null,hops:typeof e.hops=="boolean"?e.hops:null,avoid:typeof e.avoid=="boolean"?e.avoid:null,cost:typeof e.cost=="number"&&Number.isFinite(e.cost)?e.cost:null}}image(e,n){if(!M(e))return null;let o=k(e.ref);if(o!==void 0)return n[o]??{data:"",format:"png"};let r=k(e.data);return r===void 0?null:this.picture(r,k(e.format))}picture(e,n){return Fn.test(e)?{data:e.replace(/\s+/g,""),format:n==="jpeg"?"jpeg":"png"}:(this.warn("Skipped a picture whose data isn't base64"),{data:"",format:"png"})}element(e,n){if(!M(e))return null;this.fields(e,"element");let o=fe(e.id),r=k(e.kind),s=fe(e.layerID);if(!o||!r||!s)return this.warn("Skipped an element without an id, kind or layer"),null;Rn.includes(r)||this.warn(`Unknown element kind "${r}", drawn as a placeholder`);let i=Array.isArray(e.subpaths)?e.subpaths.filter(M).map(l=>({closed:me(l.closed)??!1,coords:Array.isArray(l.coords)?l.coords.filter(a=>typeof a=="number"):[]})):null;return{id:o,kind:r,layerID:s,x:g(e.x)??0,y:g(e.y)??0,width:g(e.width)??0,height:g(e.height)??0,style:this.style(e.style),seed:(g(e.seed)??1)>>>0,text:k(e.text)??null,connector:this.connector(e.connector),groupID:fe(e.groupID)??null,points:Array.isArray(e.points)?e.points.filter(M).map(l=>({x:g(l.x)??0,y:g(l.y)??0})):null,path:Array.isArray(e.path)?e.path.filter(l=>typeof l=="number"):null,subpaths:i,evenOdd:me(e.evenOdd)??null,rotation:g(e.rotation)??null,link:fe(e.link)??null,url:k(e.url)??null,anchor:k(e.anchor)??null,click:this.click(e.click),hover:this.hover(e.hover),when:k(e.when)??null,overrides:this.overrides(e.overrides),symbol:fe(e.symbol)??null,playback:this.playback(e.playback),offset:g(e.offset)??null,args:Dt(e.args),image:this.image(e.image,n),reveal:g(e.reveal)??null,ports:Array.isArray(e.ports)?e.ports.map(l=>{let a=M(l)?l:{};return{x:g(a.x)??0,y:g(a.y)??0}}):null,labelRect:this.labelRect(e.labelRect),extension:this.extension(e.extension),capacity:g(e.capacity)??null,delay:g(e.delay)??null,queue:e.queue===!0?!0:null,gauge:this.gauge(e.gauge),containerID:fe(e.containerID)??null,container:this.container(e.container)}}gauge(e){if(!M(e))return null;this.fields(e,"gauge");let n=r=>typeof r=="number"&&Number.isFinite(r)?r:null,o=k(e.style);return{metric:k(e.metric)??"",of:typeof e.of=="string"&&Fe.test(e.of)?e.of.toUpperCase():Gt,max:n(e.max),warn:n(e.warn),alarm:n(e.alarm),style:o==="number"||o==="bar"||o==="dial"?o:null,label:k(e.label)??null}}labelRect(e){return M(e)?(this.fields(e,"normalizedRect"),{x:g(e.x)??0,y:g(e.y)??0,width:g(e.width)??0,height:g(e.height)??0}):null}extension(e){if(!M(e))return null;this.fields(e,"extensionRef");let n=k(e.id),o=k(e.shape),r=k(e.version);if(n===void 0||o===void 0||r===void 0)return this.warn("Skipped an extension without an id, shape or version"),null;let s={};if(M(e.params))for(let[i,l]of Object.entries(e.params))(typeof l=="number"||typeof l=="boolean"||typeof l=="string")&&(s[i]=l);return{id:n,shape:o,version:r,params:s}}variables(e){if(!M(e))return null;let n={};for(let[o,r]of Object.entries(e))typeof r=="boolean"&&(n[o]=r);return Object.keys(n).length>0?n:null}click(e){if(!M(e))return null;this.fields(e,"click");let n=k(e.url),o=n===void 0?null:Cn(n);n!==void 0&&o===null&&this.warn("Skipped a click link that isn't http, https or mailto");let r=null;if(M(e.set)){r={};for(let[l,a]of Object.entries(e.set))typeof a=="boolean"&&Be(l)&&(r[l]=a);Object.keys(r).length===0&&(r=null)}let s=typeof e.toggle=="string"?[e.toggle]:Array.isArray(e.toggle)&&e.toggle.every(l=>typeof l=="string")?e.toggle:null,i=s?s.filter(Be):null;return{scene:k(e.scene)??null,url:o,set:r,toggle:i&&i.length>0?i:null,reset:e.reset===!0?!0:null}}playback(e){let n=k(e);return n===void 0?null:["loop","once","still","click"].includes(n)?n:"loop"}symbol(e,n){if(!M(e))return null;this.fields(e,"symbol");let o=fe(e.id);if(!o)return this.warn("Skipped a symbol without an id"),null;let r=i=>{let l=g(i);return Math.max(1,l??100)},s=(Array.isArray(e.layers)?e.layers:[]).filter(M).flatMap(i=>{let l=fe(i.id);return l?[{id:l,name:k(i.name)??"",visible:me(i.visible)??!0,locked:me(i.locked)??!1}]:[]});return s.length===0&&s.push({id:`${o}-LAYER`,name:"Layer 1",visible:!0,locked:!1}),{id:o,name:k(e.name)??"Symbol",width:r(e.width),height:r(e.height),layers:s,elements:(Array.isArray(e.elements)?e.elements:[]).map(i=>this.element(i,n)).filter(i=>i!==null),timeline:this.timeline(e.timeline),button:me(e.button)??null,params:Dt(e.params)}}overrides(e){return Array.isArray(e)?e.filter(M).map(n=>{this.fields(n,"override");let o=k(n.dash),r=null;if(M(n.reroute)&&Object.values(n.reroute).every(s=>typeof s=="string"&&Fe.test(s))){r={};for(let[s,i]of Object.entries(n.reroute))Fe.test(s)&&(r[s.toUpperCase()]=i.toUpperCase());Object.keys(r).length===0&&(r=null)}return{when:k(n.when)??"",stroke:ce(n.stroke)??null,fill:ce(n.fill)??null,textColor:ce(n.textColor)??null,opacity:g(n.opacity)??null,strokeWidth:g(n.strokeWidth)??null,dash:o!==void 0&&["solid","dashed","dotted"].includes(o)?o:null,text:k(n.text)??null,reroute:r,offline:n.offline===!0?!0:null,cost:typeof n.cost=="number"&&Number.isFinite(n.cost)?n.cost:null,capacity:typeof n.capacity=="number"&&Number.isFinite(n.capacity)?n.capacity:null,delay:typeof n.delay=="number"&&Number.isFinite(n.delay)?n.delay:null}}):null}hover(e){return M(e)?(this.fields(e,"hover"),{stroke:ce(e.stroke)??null,fill:ce(e.fill)??null,opacity:g(e.opacity)??null}):null}ease(e){let n=k(e);return n===void 0?null:An.includes(n)?n:(this.warn(`Unknown ease "${n}", played linear`),null)}keyframe(e){if(!M(e))return null;this.fields(e,"keyframe");let n=g(e.t);if(n===void 0)return null;let o={t:n};for(let a of["x","y","width","height","rotation","strokeWidth","reveal","opacity"]){let c=g(e[a]);c!==void 0&&(o[a]=c)}let r=ce(e.stroke),s=ce(e.fill),i=me(e.visible),l=this.ease(e.ease);return r&&(o.stroke=r),s&&(o.fill=s),i!==void 0&&(o.visible=i),l&&(o.ease=l),o}track(e){if(!M(e))return null;this.fields(e,"track");let n=fe(e.element);if(!n)return null;let o=(Array.isArray(e.keys)?e.keys:[]).map(i=>this.keyframe(i)).filter(i=>i!==null&&i.t>=0&&i.t<=De);ot(o,i=>i.t);let r=Array.isArray(e.follow)?e.follow.filter(M).flatMap(i=>{let l=fe(i.path),a=g(i.start),c=g(i.end);return!l||a===void 0||c===void 0||a<0||c>De?[]:[{path:l,start:a,end:c,ease:this.ease(i.ease),reverse:me(i.reverse)??null,orient:me(i.orient)??null,laps:g(i.laps)??null}]}):null,s=Array.isArray(e.repeats)?e.repeats.filter(M).flatMap(i=>{let l=g(i.start),a=g(i.end);if(l===void 0||a===void 0)return[];let c=g(i.count),u={start:l,end:a,count:c===void 0?null:Math.trunc(c)};return Lt(u)?[u]:[]}):null;return{element:n,keys:o,boil:me(e.boil)??null,follow:r,repeats:s,march:In(g(e.march))}}timeline(e){if(!M(e))return null;this.fields(e,"timeline");let n=g(e.boil),o=Array.isArray(e.camera)?e.camera.filter(M).flatMap(i=>{let l=g(i.t),a=g(i.x),c=g(i.y),u=g(i.width),p=g(i.height);return l===void 0||a===void 0||c===void 0||u===void 0||p===void 0?[]:u>1&&p>1&&l>=0?[{t:l,x:a,y:c,width:u,height:p,ease:this.ease(i.ease)}]:[]}):null;o&&ot(o,i=>i.t);let r=Array.isArray(e.markers)?e.markers.filter(M).flatMap(i=>{let l=g(i.t);return l!==void 0&&l>=0?[{t:l,name:k(i.name)??"",loop:me(i.loop)??null}]:[]}):null;r&&ot(r,i=>i.t);let s=g(e.poster);return{fps:Nt(g(e.fps)??12),duration:rt(g(e.duration)??0),boil:n!==void 0&&Number.isInteger(n)&&n>0?Math.min(n,1e4):null,settle:me(e.settle)??null,poster:s===void 0?null:rt(s),tracks:(Array.isArray(e.tracks)?e.tracks:[]).map(i=>this.track(i)).filter(i=>i!==null),camera:o,markers:r}}page(e,n,o){if(!M(e))throw new Me(`Page ${o} is not an object`);this.fields(e,"page");let r=(Array.isArray(e.layers)?e.layers:[]).filter(M).flatMap(s=>{let i=fe(s.id);return i?[{id:i,name:k(s.name)??"",visible:me(s.visible)??!0,locked:me(s.locked)??!1}]:[]});return r.length===0&&(this.warn(`Page ${o} has no layers`),r.push({id:"LAYER",name:"Layer 1",visible:!0,locked:!1})),{id:fe(e.id)??`PAGE-${o}`,name:k(e.name)??`Page ${o}`,layers:r,elements:(Array.isArray(e.elements)?e.elements:[]).map(s=>this.element(s,n)).filter(s=>s!==null),theme:k(e.theme)??null,customTheme:this.customTheme(e.customTheme),timeline:this.timeline(e.timeline),symbols:Array.isArray(e.symbols)?e.symbols.map(s=>this.symbol(s,n)).filter(s=>s!==null):null,variables:this.variables(e.variables),flows:Array.isArray(e.flows)?e.flows.filter(M).map(s=>this.flow(s)):null}}flow(e){this.fields(e,"flow");let n=r=>typeof r=="string"&&Fe.test(r)?r.toUpperCase():Gt,o=r=>{let s=g(r);return s!==void 0&&Number.isFinite(s)?s:null};return{id:n(e.id),from:n(e.from),to:Array.isArray(e.to)&&e.to.every(r=>typeof r=="string")?e.to.filter(r=>Fe.test(r)).map(r=>r.toUpperCase()):[],every:o(e.every),speed:o(e.speed),size:o(e.size),color:M(e.color)&&["r","g","b","a"].every(r=>typeof e.color[r]=="number")?ce(e.color)??null:null,when:k(e.when)??null,spread:e.spread===!0?!0:null,volume:o(e.volume),overrides:Array.isArray(e.overrides)&&e.overrides.length>0?e.overrides.filter(M).map(r=>(this.fields(r,"flowOverride"),{when:k(r.when)??"",volume:o(r.volume)})):null}}},Fn=/^[A-Za-z0-9+/=\s]*$/;function Lt(t){return Number.isFinite(t.start)&&Number.isFinite(t.end)&&t.start>=0&&t.end-t.start>.001&&t.end<=De&&(t.count===null||t.count>=1&&t.count<=1e4)}function ot(t,e){let n=t.map((o,r)=>[o,r]);n.sort((o,r)=>e(o[0])-e(r[0])||o[1]-r[1]);for(let o=0;o<t.length;o++)t[o]=n[o][0]}function vt(t){let e=t;if(typeof t=="string")try{e=JSON.parse(t)}catch(i){throw new Me(`Not JSON: ${i.message}`)}if(!M(e))throw new Me("Not a Dottie drawing");let n=g(e.version);if(n===void 0)throw new Me("Not a Dottie drawing (no version)");if(!Array.isArray(e.pages)||e.pages.length===0)throw new Me("A drawing needs at least one page");let o=new st;o.fields(e,"file"),n>Ct&&o.warn(`File version ${n} is newer than this player knows (${Ct}); some things may not show`);let r={};if(M(e.images))for(let[i,l]of Object.entries(e.images))M(l)&&typeof l.data=="string"&&(r[i]=o.picture(l.data,k(l.format)));let s=e.pages.map((i,l)=>Ot(o.page(i,r,l+1)));if(new Set(s.map(i=>i.id)).size!==s.length)throw new Me("Two pages share an id");return{version:n,pages:s,warnings:o.warnings}}function Ue(t){return{...t,style:{...t.style,stroke:{...t.style.stroke},fill:{...t.style.fill},textColor:t.style.textColor?{...t.style.textColor}:null,named:t.style.named?{...t.style.named}:t.style.named},connector:t.connector?{...t.connector,start:{...t.connector.start},end:{...t.connector.end},waypoints:t.connector.waypoints?.map(e=>({...e}))??null}:null,gauge:t.gauge?{...t.gauge}:t.gauge}}var Dn=64;function Be(t){return t.length<=Dn&&/^[A-Za-z_][A-Za-z0-9_]*$/.test(t)}var Bt=["throughput","load","delay","backlog","depth","inFlight","transit","backup"],Gn=[">=","<=","==","!=",">","<"];function _e(t){let e=ye(t);if(!e.includes("(")){let a=e.search(/[>=<!]/);if(a<0)return null;let c=ye(e.slice(0,a));if(!Bt.includes(c))return null;let u=_e(c+"() "+e.slice(a));return u?{...u,target:""}:null}let n=e.indexOf("("),o=e.indexOf(")");if(n<0||o<0||n>=o)return null;let r=ye(e.slice(0,n)),s=ye(e.slice(n+1,o)),i=ye(e.slice(o+1));if(!Bt.includes(r)||s.includes("("))return null;let l=Gn.find(a=>i.startsWith(a));return l===void 0||(i=ye(i.slice(l.length)),!/^-?[0-9]+(\.[0-9]+)?$/.test(i))?null:{metric:r,target:s,op:l,value:Number(i)}}function Nn(t,e){switch(t.op){case">":return e>t.value;case">=":return e>=t.value;case"<":return e<t.value;case"<=":return e<=t.value;case"==":return e===t.value;default:return e!==t.value}}function it(t){return t.split("||").some(e=>e.split("&&").some(n=>_e(n)!==null))}function Ln(t){let e=[];for(let n of t.split("||"))for(let o of n.split("&&")){if(_e(o)!==null)continue;let r=ye(o);if(r.startsWith("!")&&(r=ye(r.slice(1))),!Be(r))return null;e.push(r)}return e}function je(t,e,n=null){return Ln(t)===null?!1:t.split("||").some(o=>o.split("&&").every(r=>{let s=_e(r);if(s!==null){let a=n?n(s):null;return a!==null&&Nn(s,a)}let i=ye(r),l=!1;return i.startsWith("!")&&(l=!0,i=ye(i.slice(1))),(e[i]??!1)!==l}))}function lt(t){return{...t,reroute:null,offline:null,cost:null,capacity:null,delay:null}}function at(t,e){let n=Ue(e);if(t.stroke&&(n.style.stroke={...t.stroke}),t.fill&&(n.style.fill={...t.fill}),t.textColor&&(n.style.textColor={...t.textColor}),t.strokeWidth!==null&&(n.style.strokeWidth=Math.max(0,t.strokeWidth)),t.dash!==null&&(n.style.dash=t.dash),t.text!==null&&(n.text=t.text),t.cost!==null&&n.connector&&(n.connector.cost=Math.min(Math.max(t.cost,0),1e6)),t.capacity!==null&&(n.capacity=Math.max(t.capacity,0)),t.delay!==null&&n.kind!=="connector"&&(n.delay=Math.max(t.delay,0)),t.opacity!==null){let o=Math.min(Math.max(t.opacity,0),1)*(n.style.opacity??1);n.style.opacity=o>=1?null:o}return n}function ye(t){return t.replace(/^[ \t ]+|[ \t ]+$/g,"")}var Pe=t=>({x:t.x,y:t.y,width:t.width,height:t.height}),Te=t=>t.rotation??0,Ge=t=>({x:t.x+t.width/2,y:t.y+t.height/2}),Ee=(t,e)=>qe(e,Ge(t),Te(t)),Ut=(t,e)=>qe(e,Ge(t),-Te(t));function _t(t){let e=Pe(t);if(Te(t)===0)return e;let n=[{x:e.x,y:e.y},{x:xe(e),y:e.y},{x:xe(e),y:be(e)},{x:e.x,y:be(e)}].map(l=>Ee(t,l)),o=n.map(l=>l.x),r=n.map(l=>l.y),s=Math.min(...o),i=Math.min(...r);return{x:s,y:i,width:Math.max(...o)-s,height:Math.max(...r)-i}}function Ne(t){if(t.kind!=="path"||!t.subpaths)return[];let e=[];for(let n of t.subpaths){if(n.coords.length<8||(n.coords.length-2)%6!==0)continue;let o=[];for(let r=0;r<n.coords.length;r+=2)o.push({x:t.x+n.coords[r]*t.width,y:t.y+n.coords[r+1]*t.height});e.push({closed:n.closed,points:o})}return e}function jt(t){let e=new se;for(let n of Ne(t)){e.moveTo(n.points[0]);for(let o=0;o<(n.points.length-1)/3;o++)e.curveTo(n.points[3*o+3],n.points[3*o+1],n.points[3*o+2]);n.closed&&e.close()}return e}var He=16,vn=24,Ht=24,Bn=48;function Un(t){if(t.kind==="connector"||t.kind==="text"||t.kind==="freehand"||t.kind==="path"&&!t.extension||t.style.opacity!==null&&t.style.opacity<=0)return null;let e=_t(t);return e.width<Ht||e.height<Ht?null:e}function ut(t,e){let n=e.x+e.width,o=e.y+e.height;for(let r=1;r<t.length;r++){let s=t[r-1],i=t[r];if(s.y===i.y){if(e.y<s.y&&s.y<o&&Math.min(s.x,i.x)<n&&Math.max(s.x,i.x)>e.x)return!0}else if(s.x===i.x&&e.x<s.x&&s.x<n&&Math.min(s.y,i.y)<o&&Math.max(s.y,i.y)>e.y)return!0}return!1}var ct=t=>({x:t.x-He,y:t.y-He,width:t.width+2*He,height:t.height+2*He}),Wt=(t,e)=>e.x<t.x&&t.x<e.x+e.width&&e.y<t.y&&t.y<e.y+e.height,We=new Map;function zt(t,e,n,o,r,s,i){let l=m=>!Wt(e,ct(m))&&!Wt(n,ct(m)),a=[],c=!1;for(let m of s){if(i.has(m.id))continue;let y=Un(m);!y||!l(y)||(a.push(y),!c&&ut(t,y)&&(c=!0))}if(!c)return t;let u=JSON.stringify([e.x,e.y,n.x,n.y,o,r,a.map(m=>[m.x,m.y,m.width,m.height])]),p=We.get(u);if(p)return p;let f=_n(t,e,n,o,r,a);return We.size>=512&&We.clear(),We.set(u,f),f}function _n(t,e,n,o,r,s){let i=s.map((l,a)=>a).filter(l=>ut(t,s[l]));if(i.length===0)return t;for(let l=0;l<4;l++){if(i.length>Bn)return t;let a=jn(e,n,o,r,i.map(u=>ct(s[u])));if(!a)return t;let c=s.map((u,p)=>p).filter(u=>!i.includes(u)&&ut(a,s[u]));if(c.length===0)return a;i=[...i,...c].sort((u,p)=>u-p)}return t}function jn(t,e,n,o,r){let s=[t.x,e.x,(t.x+e.x)/2],i=[t.y,e.y,(t.y+e.y)/2];for(let w of r)s.push(w.x,w.x+w.width),i.push(w.y,w.y+w.height);s=[...new Set(s)].sort((w,L)=>w-L),i=[...new Set(i)].sort((w,L)=>w-L);let l=s.length,a=i.length,c=s.indexOf(t.x),u=i.indexOf(t.y),p=s.indexOf(e.x),f=i.indexOf(e.y);if(c<0||u<0||p<0||f<0)return null;let m=new Map(s.map((w,L)=>[w,L])),y=new Map(i.map((w,L)=>[w,L])),O=new Uint8Array(l*a),N=new Uint8Array(l*a),X=new Uint8Array(l*a);for(let w of r){let L=m.get(w.x),h=m.get(w.x+w.width),d=y.get(w.y),E=y.get(w.y+w.height);if(!(L===void 0||h===void 0||d===void 0||E===void 0))for(let R=L;R<h;R++)for(let b=d;b<E;b++)b>d&&(N[R*a+b]=1),R>L&&(X[R*a+b]=1),R>L&&b>d&&(O[R*a+b]=1)}let q=(w,L)=>O[w*a+L]===1,ie=(w,L,h)=>N[Math.min(w,L)*a+h]===1,ne=(w,L,h)=>X[h*a+Math.min(w,L)]===1,x=l*a*2,P=new Array(x).fill(1/0),_=new Array(x).fill(-1),B=new Array(x).fill(!1),W=new ht,he=(c*a+u)*2+(n?1:0);P[he]=0,W.push(0,he);let Q=(p*a+f)*2+(o?1:0);for(let w=W.pop();w;w=W.pop()){let[L,h]=w;if(B[h])continue;if(B[h]=!0,h===Q)break;let d=Math.floor(h/2),E=h%2,R=Math.floor(d/a),b=d%a;for(let[S,z]of[[1,0],[-1,0],[0,1],[0,-1]]){let ee=R+S,v=b+z;if(ee<0||ee>=l||v<0||v>=a||q(ee,v))continue;let le=S!==0?0:1;if(S!==0?ie(R,ee,b):ne(b,v,R))continue;let C=Math.abs(s[ee]-s[R])+Math.abs(i[v]-i[b]),J=L+C+(le!==E?vn:0),ae=(ee*a+v)*2+le;J<P[ae]&&(P[ae]=J,_[ae]=h,W.push(J,ae))}}if(!B[Q])return null;let we=[];for(let w=Q;w>=0;w=_[w]){let L=Math.floor(w/2);we.push({x:s[Math.floor(L/a)],y:i[L%a]})}return we.reverse()}var ht=class{constructor(){K(this,"heap",[]);K(this,"next",0)}less(e,n){let o=this.heap[e],r=this.heap[n];return o[0]<r[0]||o[0]===r[0]&&o[1]<r[1]}push(e,n){this.heap.push([e,this.next++,n]);for(let o=this.heap.length-1;o>0;){let r=o-1>>1;if(!this.less(o,r))break;[this.heap[o],this.heap[r]]=[this.heap[r],this.heap[o]],o=r}}pop(){if(this.heap.length===0)return null;let e=this.heap[0],n=this.heap.pop();if(this.heap.length>0){this.heap[0]=n;for(let o=0;;){let r=2*o+1,s=r+1,i=o;if(r<this.heap.length&&this.less(r,i)&&(i=r),s<this.heap.length&&this.less(s,i)&&(i=s),i===o)break;[this.heap[o],this.heap[i]]=[this.heap[i],this.heap[o]],o=i}}return[e[0],e[2]]}};function Hn(t,e){let n=Pe(t),o=e==="top"?{x:Ae(n),y:n.y}:e==="right"?{x:xe(n),y:Se(n)}:e==="bottom"?{x:Ae(n),y:be(n)}:{x:n.x,y:Se(n)};return Ee(t,o)}function Wn(t){let e=[];for(let n=0;n+3<t.length;n+=3){let o=t.slice(n,n+4);for(let r=0;r<16;r++)e.push(Tt(o,r/16))}return e.push(t[t.length-1]),e}function zn(t,e,n){let o=null,r=null;for(let i of Ne(t)){let l=Wn(i.points),a=l.length,c=i.closed?a:a-1;for(let u=0;u<c;u++){let p=l[u],f=l[(u+1)%a],m={x:f.x-p.x,y:f.y-p.y},y={x:p.x-e.x,y:p.y-e.y},O=m.x*n.y-n.x*m.y;if(O===0)continue;let N=(m.x*y.y-m.y*y.x)/O,X=(n.x*y.y-n.y*y.x)/O;N>0&&X>=0&&X<=1&&((o===null||N<o)&&(o=N),N<=1&&(r===null||N>r)&&(r=N))}}let s=r??o;return s===null?null:{x:e.x+n.x*s,y:e.y+n.y*s}}function $n(t,e){let n=Pe(t),o=Ge(t),r=Ut(t,e),s=r.x-o.x,i=r.y-o.y;if(!((s!==0||i!==0)&&n.width>0&&n.height>0))return o;if(t.kind==="path"){let u=zn(t,o,{x:s,y:i});if(u)return Ee(t,u)}let l=n.width/2,a=n.height/2,c;return t.kind==="ellipse"?c=1/Math.sqrt(s*s/(l*l)+i*i/(a*a)):t.kind==="diamond"?c=1/(Math.abs(s)/l+Math.abs(i)/a):c=Math.min(s!==0?l/Math.abs(s):1/0,i!==0?a/Math.abs(i):1/0),Ee(t,{x:o.x+s*c,y:o.y+i*c})}function $t(t,e){let n=t.elementID?e.get(t.elementID):void 0;return n?Ge(n):{x:t.x,y:t.y}}function Kn(t,e){let n=Pe(t);return Ee(t,{x:n.x+e.x*n.width,y:n.y+e.y*n.height})}function Kt(t,e,n){let o=t.elementID?n.get(t.elementID):void 0;if(!o)return{x:t.x,y:t.y};let r=t.portIndex,s=o.ports??[];return typeof r=="number"&&Number.isInteger(r)&&r>=0&&r<s.length?Kn(o,s[r]):t.port?Hn(o,t.port):$n(o,e)}function Yt(t,e){let n=t.connector;if(!n)return[{x:0,y:0},{x:0,y:0}];let o=n.waypoints??[];return[Kt(n.start,o.length>0?o[0]:$t(n.end,e),e),Kt(n.end,o.length>0?o[o.length-1]:$t(n.start,e),e)]}function Xt(t){if(t.kind==="polyline")return t.points;let e=[],n=t.points;for(let o=0;o<Math.floor((n.length-1)/3);o++){let r=n[3*o],s=n[3*o+1],i=n[3*o+2],l=n[3*o+3];for(let a=o===0?0:1;a<=24;a++){let c=a/24,u=1-c;e.push({x:u*u*u*r.x+3*u*u*c*s.x+3*u*c*c*i.x+c*c*c*l.x,y:u*u*u*r.y+3*u*u*c*s.y+3*u*c*c*i.y+c*c*c*l.y})}}return e}var ze=t=>t===null?null:t==="top"||t==="bottom";function Jt(t){let e=[];for(let n of t){let o=e[e.length-1];if(!(o&&Math.abs(o.x-n.x)<.5&&Math.abs(o.y-n.y)<.5)){if(e.length>=2){let r=e[e.length-2],s=e[e.length-1];if(Math.abs(r.x-s.x)<.5&&Math.abs(s.x-n.x)<.5||Math.abs(r.y-s.y)<.5&&Math.abs(s.y-n.y)<.5){e[e.length-1]=n;continue}}e.push(n)}}return e.length>=2?e:t}function Vn(t,e){switch(e.routing){case"straight":return{kind:"polyline",points:t};case"curved":{let n=[t[0]];for(let o=0;o<t.length-1;o++){let r=t[Math.max(o-1,0)],s=t[o],i=t[o+1],l=t[Math.min(o+2,t.length-1)];n.push({x:s.x+(i.x-r.x)/6,y:s.y+(i.y-r.y)/6}),n.push({x:i.x-(l.x-s.x)/6,y:i.y-(l.y-s.y)/6}),n.push(i)}return{kind:"curve",points:n}}case"elbow":{let n=t[0],o=t[1],r=ze(e.start.port)??Math.abs(o.y-n.y)>Math.abs(o.x-n.x),s=ze(e.end.port),i=[n];for(let l=1;l<t.length;l++){let a=t[l],c=i[i.length-1],u=Math.abs(c.x-a.x)<.5,p=Math.abs(c.y-a.y)<.5;if(u||p){i.push(a),u!==p&&(r=!u);continue}let f=l===t.length-1&&s!==null?!s:r;i.push(f?{x:c.x,y:a.y}:{x:a.x,y:c.y},a),r=f}return{kind:"polyline",points:Jt(i)}}}}function Zt(t,e){let n=t.connector;if(!n)return{kind:"polyline",points:[]};let[o,r]=Yt(t,e);if(n.waypoints&&n.waypoints.length>0)return Vn([o,...n.waypoints.map(a=>({x:a.x,y:a.y})),r],n);let s=r.x-o.x,i=r.y-o.y,l=Math.abs(s)>=Math.abs(i);switch(n.routing){case"straight":return{kind:"polyline",points:[o,r]};case"curved":return l?{kind:"curve",points:[o,{x:o.x+s/2,y:o.y},{x:r.x-s/2,y:r.y},r]}:{kind:"curve",points:[o,{x:o.x,y:o.y+i/2},{x:r.x,y:r.y-i/2},r]};case"elbow":{let a=ze(n.start.port)??!l,c=ze(n.end.port)??!l,u;if(a&&c){let m=o.y+i/2;u=[o,{x:o.x,y:m},{x:r.x,y:m},r]}else if(!a&&!c){let m=o.x+s/2;u=[o,{x:m,y:o.y},{x:m,y:r.y},r]}else a?u=[o,{x:o.x,y:r.y},r]:u=[o,{x:r.x,y:o.y},r];if(n.avoid!==!0)return{kind:"polyline",points:u};let p=new Set([n.start.elementID,n.end.elementID].filter(m=>m!==null)),f=zt(u,o,r,a,c,e.values(),p);return{kind:"polyline",points:f===u?u:Jt(f)}}}}var Vt=new WeakMap;function $e(t){let e=t.elements,n=Vt.get(e);if(n&&n.members.length===e.length&&n.members.every((r,s)=>r===e[s]))return n.index;let o=new Map;for(let r of e)o.has(r.id)||o.set(r.id,r);return Vt.set(e,{members:[...e],index:o}),o}function qt(t,e,n){let o=t[1]+n>>>0,r=o<t[1]?1:0;return[t[0]+e+r>>>0,o]}function Yn(t,e){let n=t&65535,o=t>>>16,r=e&65535,s=e>>>16,i=n*r,l=n*s,a=o*r,c=o*s,u=l+a,p=i+u%65536*65536;return[c+Math.floor(u/65536)+Math.floor(p/4294967296)>>>0,p>>>0]}function Qt(t,e,n){let o=Yn(t[1],n);return[o[0]+Math.imul(t[0],n)+Math.imul(t[1],e)>>>0,o[1]]}function mt(t,e){let n=(t[1]>>>e|t[0]<<32-e)>>>0;return[(t[0]^t[0]>>>e)>>>0,(t[1]^n)>>>0]}function Xn(t){return t=Qt(mt(t,30),3210233709,484763065),t=Qt(mt(t,27),2496678331,321982955),mt(t,31)}var Ke=class{constructor(e){K(this,"state");this.state=qt([0,e>>>0],2654435769,2135587861)}next(){return this.state=qt(this.state,2654435769,2135587861),Xn(this.state)}top53(){let[e,n]=this.next();return e*2097152+(n>>>11)}signed(){return Math.floor(this.top53())/2**52-1}unit(){return this.top53()/2**53}};var en=(t,e,n)=>t.signed()*e*n;function ft(t,e,n,o,r,s,i){let l=Math.hypot(e.x-t.x,e.y-t.y);if(!(l>.5))return;let a=l<200?1:l>500?.4:-.0016668*l+1.233334,c=l<20?l/10:2;for(let u=0;u<2;u++){let p=(u===0?1:.5)*a,f=()=>en(n,c,o)*p,m=n.unit()*.4+.3,y=en(n,l/60,o)*r*a,O=e.x-t.x,N=e.y-t.y,X=-N/l,q=O/l,ie=s?t:{x:t.x+f(),y:t.y+f()},ne=s?e:{x:e.x+f(),y:e.y+f()},x=t.x+O*m*.66+X*y+f()*.5,P=t.y+N*m*.66+q*y+f()*.5,_=t.x+O*(.5+m*.5)+X*y+f()*.5,B=t.y+N*(.5+m*.5)+q*y+f()*.5;i.moveTo(ie),i.curveTo(ne,{x,y:P},{x:_,y:B})}}function dt(t,e,n,o){let r=new se;for(let s=0;s<t.length;s++)ft(t[s],t[(s+1)%t.length],e,n,o,!1,r);return r}function tn(t,e,n){let o=new se,r=t.x+t.width/2,s=t.y+t.height/2,i=t.width/2,l=t.height/2;if(!(i>.5&&l>.5))return o;let a=Math.max(8,Math.min(24,Math.trunc((i+l)/6))),c=Math.min(2.5,(i+l)/25)*n;for(let u=0;u<2;u++){let p=e.unit()*2*Math.PI,f=2*Math.PI*(u===0?1:1.04),m=Math.trunc(a*f/(2*Math.PI))+1,y=[];for(let O=0;O<m;O++){let N=p+f*O/a,X=e.signed()*c,q=e.signed()*c;y.push({x:r+i*Math.cos(N)+X,y:s+l*Math.sin(N)+q})}Jn(y,o)}return o}function Jn(t,e){if(!(t.length<=2)){e.moveTo(t[0]);for(let n=0;n<t.length-1;n++){let o=t[Math.max(n-1,0)],r=t[n],s=t[n+1],i=t[Math.min(n+2,t.length-1)];e.curveTo(s,{x:r.x+(s.x-o.x)/6,y:r.y+(s.y-o.y)/6},{x:s.x-(i.x-r.x)/6,y:s.y-(i.y-r.y)/6})}}}var Zn=-41*Math.PI/180;var Ve=class{constructor(e=6e3){K(this,"map",new Map);K(this,"limit");this.limit=e}get(e,n){let o=this.map.get(e);if(o!==void 0)return o;let r=n();return this.map.size>=this.limit&&this.map.clear(),this.map.set(e,r),r}},Qn=new Ve,Ko=new Ve;function eo(t,e){let n=t.style;return[e,t.kind,t.x,t.y,t.width,t.height,t.seed,n.roughness,n.bowing,n.strokeWidth,n.fillStyle,n.fillStyle==="grid"?to(t):0,t.path?t.path.join(","):t.subpaths?JSON.stringify(t.subpaths):""].join("|")}var to=t=>Math.max(8,t.style.gridSize??50);function rn(t){return t.kind==="freehand"&&t.path===null?on(t):Qn.get(eo(t,0),()=>on(t))}function no(t){return[{x:t.x,y:t.y},{x:xe(t),y:t.y},{x:xe(t),y:be(t)},{x:t.x,y:be(t)}]}function nn(t){return[{x:Ae(t),y:t.y},{x:xe(t),y:Se(t)},{x:Ae(t),y:be(t)},{x:t.x,y:Se(t)}]}function on(t){let e=Pe(t),n=new Ke(t.seed),o=t.style.roughness;switch(t.kind){case"ellipse":return o<=0?se.ellipse(e):tn(e,n,o);case"diamond":return o<=0?new se().addLines(nn(e)).close():dt(nn(e),n,o,t.style.bowing);case"text":case"connector":return se.rect(e);case"freehand":return ro(t);case"path":return o<=0?jt(t):oo(t,n);default:return o<=0?se.rect(e):dt(no(e),n,o,t.style.bowing)}}function oo(t,e){let n=t.style.roughness,o=new se;for(let r of Ne(t)){let s=r.points;for(let i=0;i<(s.length-1)/3;i++){let l=s[3*i],a=s[3*i+1],c=s[3*i+2],u=s[3*i+3];if(a.x===l.x&&a.y===l.y&&c.x===u.x&&c.y===u.y){ft(l,u,e,n,t.style.bowing,!0,o);continue}let p=Math.hypot(a.x-l.x,a.y-l.y)+Math.hypot(c.x-a.x,c.y-a.y)+Math.hypot(u.x-c.x,u.y-c.y),f=Math.min(2.5,p/30)*n;for(let m=0;m<2;m++){let y=m===0?1:.5,O=()=>e.signed()*f*y;o.moveTo(l);let N=a.x+O(),X=a.y+O(),q=c.x+O(),ie=c.y+O();o.curveTo(u,{x:N,y:X},{x:q,y:ie})}}}return o}function ro(t){let e=Pe(t),n=t.path;if(n&&n.length>=8&&(n.length-2)%6===0){let s=l=>({x:e.x+n[2*l]*e.width,y:e.y+n[2*l+1]*e.height}),i=new se().moveTo(s(0));for(let l=0;l<Math.floor((n.length/2-1)/3);l++)i.curveTo(s(3*l+3),s(3*l+1),s(3*l+2));return i}let o=(t.points??[]).map(s=>({x:e.x+s.x*e.width,y:e.y+s.y*e.height})),r=new se;if(o.length===0)return r;if(r.moveTo(o[0]),o.length===1)return r.lineTo(o[0]);if(o.length===2)return r.lineTo(o[1]);for(let s=1;s<o.length-1;s++)r.quadTo({x:(o[s].x+o[s+1].x)/2,y:(o[s].y+o[s+1].y)/2},o[s]);return r.lineTo(o[o.length-1])}function sn(t,e,n=$e(e)){if(t.kind==="connector")return new ke(Xt(Zt(t,n)));let o=Ue(t);o.style.roughness=0;let r=rn(o).contours()[0]??[];return new ke(Te(t)===0?r:r.map(s=>Ee(t,s)))}var an=.5,gt=160,xt=12,bt={r:.95,g:.36,b:.33,a:1},Ie=(t,e,n,o)=>t===null||!Number.isFinite(t)?e:Math.min(Math.max(t,n),o);function Le(t,e){let n=(e+1099511627776)%281474976710656;return t.slice(0,24)+(n<0?n+2**48:n).toString(16).toUpperCase().padStart(12,"0")}var Xe=t=>t===null||!Number.isFinite(t)?1:Math.min(Math.max(t,0),1e6),ln=new WeakMap,Ye=new Map;function so(t){let e=t.elements,n=ln.get(e);if(n&&n.members.length===e.length&&n.members.every((l,a)=>l===e[a]))return n.graph;let o=new Set(e.filter(l=>l.kind!=="connector").map(l=>l.id)),r=[];for(let l of e){let a=l.connector;a&&r.push([l.id,a.start.elementID,a.end.elementID,String(Xe(a.cost)),a.startHead!=="none"?"both":"one"])}let s=JSON.stringify([[...o],r]),i=Ye.get(s);if(!i){let l=new Map,a=(c,u)=>{let p=l.get(c);p?p.push(u):l.set(c,[u])};for(let c of e){let u=c.connector,p=u?.start.elementID??null,f=u?.end.elementID??null;if(!u||p===null||f===null||p===f||!o.has(p)||!o.has(f))continue;let m=Xe(u.cost);a(p,{to:f,via:c.id,back:!1,cost:m}),u.startHead!=="none"&&a(f,{to:p,via:c.id,back:!0,cost:m})}i={shapes:o,next:l,trees:new Map},Ye.size>=16&&Ye.clear(),Ye.set(s,i)}return ln.set(e,{members:[...e],graph:i}),i}var pt=class{constructor(){K(this,"heap",[])}get size(){return this.heap.length}less(e,n){let o=this.heap[e],r=this.heap[n];return o.dist<r.dist||o.dist===r.dist&&o.order<r.order}swap(e,n){[this.heap[e],this.heap[n]]=[this.heap[n],this.heap[e]]}push(e,n,o){this.heap.push({id:e,dist:n,order:o});for(let r=this.heap.length-1;r>0;){let s=r-1>>1;if(!this.less(r,s))break;this.swap(r,s),r=s}}pop(){let e=this.heap[0],n=this.heap.pop();if(this.heap.length>0){this.heap[0]=n;for(let o=0;;){let r=2*o+1,s=r+1,i=o;if(r<this.heap.length&&this.less(r,i)&&(i=r),s<this.heap.length&&this.less(s,i)&&(i=s),i===o)break;this.swap(o,i),o=i}}return e}};function Je(t,e,n=new Set,o){let r=so(e),s=JSON.stringify([t,o??null,[...n].sort()]);if(r.trees.has(s))return r.trees.get(s);let i=io(r,t,n,o);return r.trees.size>=4096&&r.trees.clear(),r.trees.set(s,i),i}function io({shapes:t,next:e},n,o,r){if(!t.has(n)||o.has(n))return null;let s=new Map([[n,0]]),i=new Map([[n,0]]),l=1,a=new yt(n),c=new pt;for(c.push(n,0,0);c.size>0;){let{id:u,order:p}=c.pop();if(!(a.settled.has(u)||i.get(u)!==p)){if(a.settled.add(u),u===r&&u!==n)break;for(let f of e.get(u)??[]){if(o.has(f.via)||o.has(f.to)||a.settled.has(f.to))continue;let m=s.get(u)+f.cost,y=s.get(f.to);y!==void 0&&y<=m||(s.set(f.to,m),i.set(f.to,l),c.push(f.to,m,l++),a.came.set(f.to,{from:u,via:f.via,back:f.back}))}}}return a}var yt=class{constructor(e){K(this,"settled",new Set);K(this,"came",new Map);K(this,"from");this.from=e}goals(e,n){let o=e.filter(r=>r!==this.from&&this.settled.has(r));return o.length===0?[]:n&&o[0]!==e[0]?o:[o[0]]}hops(e){let n=[];for(let o=e,r=this.came.get(o);r;o=r.from,r=this.came.get(o))n.push([r.via,r.back]);return n.reverse()}};var lo=()=>({elements:new Map,flows:new Map,carry:{}});function mn(t,e,n){let o=t.flows.get(n);if(o)switch(e){case"throughput":return o.placed;case"backlog":return o.backlog;case"backup":return o.backup;case"transit":return o.transit;default:return null}let r=t.elements.get(n);if(!r)return null;switch(e){case"throughput":return r.throughput;case"load":return r.load;case"delay":return r.delay;case"backlog":return r.backlog;case"inFlight":return r.inFlight;case"depth":return r.depth;default:return null}}var H=1e-9,Rt=t=>Ie(t.volume,1,0,1e12);function wt(t,e){if(e===null||!t.overrides)return Rt(t);let n=null;for(let o of t.overrides)o.volume!==null&&!it(o.when)&&je(o.when,e)&&(n=o.volume);return n===null?Rt(t):Math.min(Math.max(Number.isFinite(n)?n:1,0),1e12)}function un(t){let e=t.delay??null;return t.kind==="connector"||e===null||!Number.isFinite(e)?0:Math.min(Math.max(e,0),3600)}var kt=(t,e)=>t+"|"+e;function fn(t,e,n,o,r=new Set,s=null,i={}){let l=Math.max(0,Math.min(s??n,1e6)),a=$e(e),c=new Map,u=h=>{let d=c.get(h.id);return d||(d=sn(h,e,a).points,c.set(h.id,d)),d},p=lo(),f=new Map;for(let h of e.elements)h.kind==="connector"&&!h.connector||p.elements.set(h.id,{throughput:0,load:null,delay:h.kind!=="connector"?un(h):0,backlog:0,inFlight:0,depth:0});let m=t??[],y=new Map;for(let h of e.elements){let d=h.capacity??null;d!==null&&Number.isFinite(d)&&y.set(h.id,Math.max(d,0))}let O=()=>new Set([...y].filter(([,h])=>h<=H).map(([h])=>h)),N=(h,d)=>{let E=[],R=[],b=d;for(let S=h.came.get(b);S;S=h.came.get(b))E.push([S.via,S.back]),R.push(b),b=S.from;return R.push(b),{hops:E.reverse(),shapes:R.reverse()}},X=(h,d)=>{let E=[],R=[],b=[],S=0;return h.forEach(([z,ee],v)=>{let le=a.get(z);if(!le)return;let C=ee?[...u(le)].reverse():u(le);if(C.length===0)return;let J=E[E.length-1];if(J){let oe=Math.hypot(C[0].x-J.x,C[0].y-J.y),pe=a.get(d[v]);R.push([S,S+oe,pe?un(pe):0]),S+=oe}let ae=S;for(let oe=1;oe<C.length;oe++)S+=Math.hypot(C[oe].x-C[oe-1].x,C[oe].y-C[oe-1].y);b.push([z,ae,S]),E.push(...C)}),S>0?{line:new ke(E),length:S,inside:R,stretches:b}:null},q=(h,d,E)=>{let R=d,b=0;for(let[S,z,ee]of h.inside){let v=(S-b)/E;if(R<=v)break;R-=v,b=S;let le=(z-S)/E+ee;if(R<le)return null;R-=le,b=z}return b+=R*E,b>=0&&b<=h.length?b:null},ie=(h,d)=>new Set([...h,...d]),ne=(h,d)=>{let E=p.elements.get(h);E&&d(E)},x=new Map,P=[];for(let h of m){let d=x.get(h.from)??0;P.push(d),x.set(h.from,d+1)}let _=m.length>0?Math.max(...m.map(Rt)):1,B=[],W=new Map,he=h=>Math.min(Math.max(Ie(h.every,an,.05,60)*_/Math.max(wt(h,o),H),.05),60),Q=new Map,we=h=>(Q.has(h)||Q.set(h,Je(h,e,r)),Q.get(h));for(let[h,d]of m.entries()){if(d.when!==null&&o!==null&&!je(d.when,o))continue;let E=a.get(d.from),R=E?we(d.from):null;if(f.set(d.id,[]),!E||!R)continue;let b=wt(d,o),S={volume:b,placed:0,backlog:0,backup:0,transit:null},z=[],ee=[],v=R.goals(d.to,d.spread===!0),le=v.length>1?v.map(I=>[[I],b/v.length]):[[d.to,b]];for(let[I,T]of le){if(!(T>H))continue;let F=T;for(let D=0;D<32&&F>H;D++){let Y=Je(d.from,e,ie(r,O()),I[0]),Z=Y?.goals(I,!1)[0];if(!Y||Z===void 0)break;let G=N(Y,Z),j=[...G.shapes,...G.hops.map(([A])=>A)],$=j.filter(A=>y.has(A)).map(A=>y.get(A)),U=Math.min(F,$.length>0?Math.min(...$):1/0);if(!(U>H))break;for(let A of j)y.has(A)&&y.set(A,y.get(A)-U);z.push({hops:G.hops,shapes:G.shapes,goal:Z,amount:U}),F-=U}if(!(F>H))continue;let V=d.from,ge=R.goals(I,!1)[0];if(ge!==void 0){let D=N(R,ge),Y=O(),Z=[[D.shapes[0],D.shapes[0]]];D.hops.forEach(([$],U)=>{Z.push([$,D.shapes[U]],[D.shapes[U+1],D.shapes[U]])});let G=Z.find(([$])=>Y.has($));if(G){V=G[1];let $=D.shapes.indexOf(V);for(let U=$;U>=0;U--){let A=a.get(D.shapes[U]);if(A&&A.queue===!0&&A.kind!=="connector"){V=D.shapes[U];break}}}let j=D.shapes.indexOf(V);if(V!==d.from&&j>=0){let $=D.shapes.slice(0,j+1),U=D.hops.slice(0,j);for(let A of[...$,...U.map(([Ze])=>Ze)])y.has(A)&&y.set(A,Math.max(0,y.get(A)-F));z.push({hops:U,shapes:$,goal:V,amount:F,waits:!0})}}let te=ee.find(([D])=>D===V);te?te[1]+=F:ee.push([V,F])}W.set(d.id,ee),f.set(d.id,z.map(I=>({goal:I.goal,hops:I.hops,amount:I.amount,waits:I.waits===!0,cost:I.hops.reduce((T,[F])=>T+Xe(a.get(F)?.connector?.cost??null),0)})));for(let I of z){for(let T of[...I.shapes,...I.hops.map(([F])=>F)])ne(T,F=>{F.throughput+=I.amount});I.waits||(S.placed+=I.amount)}for(let[I,T]of ee)ne(I,F=>{F.backlog+=T}),S.backlog+=T;let C=z.filter(I=>!I.waits&&I.goal===d.to[0]).reduce((I,T)=>I+T.amount,0);S.backup=b>H?Math.max(0,(b-C)/b):0;let J=he(d),ae=Ie(d.speed,gt,1,1e4),oe=Ie(d.size,xt,2,200),pe=P[h]/x.get(d.from)*J,Re=d.color??bt,re=[],Ce=0;for(let I of z)Ce+=I.amount/Math.max(b,H),re.push(Ce);re.length>0&&Math.abs(re[re.length-1]-1)<1e-9&&(re[re.length-1]=1);let ve=0;z.forEach((I,T)=>{let F=X(I.hops,I.shapes);if(!F)return;let V=F.length/ae+F.inside.reduce((G,j)=>G+j[2],0);I.waits||(ve+=V*I.amount);let ge=Math.ceil((n-pe-V)/J),te=Math.floor((n-pe)/J),D=T===0?0:re[T-1],Y=re[T],Z=(G,j)=>Math.floor((j+1)*G)-Math.floor(j*G);for(let G=Math.max(ge,te-3999);G<=te;G++){if(Z(Y,G)-Z(D,G)!==1)continue;let j=q(F,n-G*J-pe,ae);if(j===null)continue;let $=F.stretches.find(([,A,Ze])=>j>=A&&j<=Ze);$&&ne($[0],A=>{A.inFlight+=1});let U=F.line.point(j/F.length);B.push(Mt(Le(d.id,G),U.x-oe/2,U.y-oe/2,oe,Re,E.layerID))}}),S.transit=S.placed>H?ve/S.placed:null,p.flows.set(d.id,S)}let w=new Map,L=Object.keys(i).filter(h=>i[h]>H);for(let h of m){let d=W.get(h.id)??[],E=d.map(([C])=>C),R="|"+h.id;if(L.some(C=>C.endsWith(R)))for(let C of e.elements){let J=i[kt(C.id,h.id)];J!==void 0&&J>H&&!E.includes(C.id)&&E.push(C.id)}if(E.length===0)continue;let b=wt(h,o),z=he(h)*Math.max(b,H),ee=Ie(h.speed,gt,1,1e4),v=Ie(h.size,xt,2,200),le=h.color??bt;E.forEach((C,J)=>{let ae=a.get(C);if(!ae)return;let oe=a.get(h.from)?.layerID??ae.layerID,pe=d.find(([T])=>T===C)?.[1]??0,Re=Math.max(0,i[kt(C,h.id)]??0),re=Re+pe*l;if(pe<=H&&Re>H){let T=new Map(y),F=[],V=0;for(let ge=0;ge<32;ge++){let te=new Set([...T].filter(([,A])=>A<=H).map(([A])=>A)),D=Je(C,e,ie(r,te),h.to[0]),Y=D?.goals(h.to,!1)[0];if(!D||Y===void 0)break;let Z=N(D,Y),G=[...Z.shapes.slice(1),...Z.hops.map(([A])=>A)],j=G.filter(A=>T.has(A)).map(A=>T.get(A)),$=j.length>0?Math.min(...j):1/0,U=Number.isFinite($)?$:Math.max(Re/.5-V,H*2);if(!(U>H))break;for(let A of G)T.has(A)&&T.set(A,T.get(A)-U);if(F.push({hops:Z.hops,shapes:Z.shapes,rate:U}),V+=U,!Number.isFinite($))break}if(V>H){if(re=Math.max(0,Re-V*l),re>H){for(let[te,D]of T)y.set(te,D);for(let te of F)for(let D of[...te.shapes,...te.hops.map(([Y])=>Y)])ne(D,Y=>{Y.throughput+=te.rate})}let ge=Re/V;F.forEach((te,D)=>{let Y=X(te.hops,te.shapes);if(!Y)return;let Z=Math.max(z/te.rate,.05);for(let G=0;G*Z<ge&&G*Z<=l&&G<2048;G++){let j=q(Y,l-G*Z,ee);if(j===null)continue;let $=Y.line.point(j/Y.length);B.push(Mt(Le(h.id,2**39+2**20+J*2**14+D*2**11+G),$.x-v/2,$.y-v/2,v,le,oe))}})}}if(!(re>H||pe>H))return;ne(C,T=>{T.depth+=re}),re>H&&(p.carry[kt(C,h.id)]=re);let Ce=Math.min(Math.max(Math.ceil(re/z-1e-9),1),30),ve=Math.trunc((Ce+9)/10),I=w.get(C)??0;w.set(C,I+ve);for(let T=0;T<Ce;T++){let F=ae.x+2+v/2+T%10*(v+3),V=ae.y-4-v/2-(I+Math.trunc(T/10))*(v+3);B.push(Mt(Le(h.id,2**39+J*64+T),F-v/2,V-v/2,v,le,oe))}})}for(let h of e.elements){let d=h.capacity??null,E=p.elements.get(h.id);d===null||!Number.isFinite(d)||!E||(E.load=d>0?E.throughput/d:1)}return{packets:B,metrics:p,routes:f}}var dn={seed:1,text:null,connector:null,groupID:null,points:null,path:null,subpaths:null,evenOdd:null,rotation:null,link:null,url:null,anchor:null,click:null,hover:null,when:null,overrides:null,symbol:null,playback:null,offset:null,args:null,image:null,reveal:null};function pn(t,e,n,o="solid",r=null){return{stroke:{...t},fill:{...e},fillStyle:o,strokeWidth:n,dash:"solid",roughness:0,bowing:1,fontSize:18,font:null,gridSize:null,opacity:r,dashOffset:null,textColor:null}}function Mt(t,e,n,o,r,s){return{...dn,id:t,kind:"ellipse",layerID:s,x:e,y:n,width:o,height:o,style:pn(r,r,1.5)}}function ao(t,e){let n=new Map;for(let r of e.elements)r.anchor!==null&&!n.has(r.anchor)&&n.set(r.anchor,r.id);let o=/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/;return(r,s)=>{let i=r.target===""?s:n.get(r.target)??(o.test(r.target)?r.target.toUpperCase():null);return i===null?null:mn(t,r.metric,i)}}function yn(t,e,n,o,r=1/0,s={}){let i=ao(e,o),l=[],a={};for(let c of t){let u=[];n!==null&&c.overrides&&c.overrides.forEach((y,O)=>{it(y.when)&&je(y.when,n,N=>i(N,c.id))&&u.push(O)});let p=n===null?null:c.gauge;if(!p){l.push({applied:u,gauge:null});continue}let f=mn(e,p.metric,p.of),m=s[cn(c.id)];if(f!==null&&m!==void 0&&p.metric!=="depth"&&p.metric!=="inFlight"&&r<hn){let y=Math.max(0,r/hn),O=y*y*(3-2*y);f=m+(f-m)*O}f!==null&&(a[cn(c.id)]=f),l.push({applied:u,gauge:{value:f}})}return{plan:l,readings:a}}var cn=t=>"gauge|"+t,hn=1,Oe=t=>{let e=parseInt(t.slice(1),16);return{r:(e>>16&255)/255,g:(e>>8&255)/255,b:(e&255)/255,a:1}},uo=Oe("#16a34a"),co=Oe("#d97706"),ho=Oe("#dc2626"),mo=Oe("#2f6fdf"),Pt=Oe("#e5e7eb"),fo=Oe("#9ca3af");function po(t,e){if(e===null||!Number.isFinite(e))return"\u2013";switch(t){case"load":case"backup":return Et(e*100,0)+"%";case"transit":case"delay":return Et(e,Math.abs(e)>=10?1:2)+"s";default:return Et(e,Math.abs(e)>=100?0:Math.abs(e)>=10?1:2)}}function Et(t,e){let n=e===0?1:e===1?10:100,o=Math.floor(Math.abs(t)*n+.5);if(!(o<1e15))return t<0?"-\u221E":"\u221E";let r=Math.trunc(o/n),s=o-r*n,i=String(r);if(e>0&&s>0){let l=String(s);for(;l.length<e;)l="0"+l;for(;l.endsWith("0");)l=l.slice(0,-1);i+="."+l}return(t<0&&o>0?"-":"")+i}function gn(t,e,n,o,r){let s=o.elements.find(x=>x.id===e.of),i=e.max??(e.metric==="load"?1:s?.capacity??n??1),l=n===null?0:i>0?Math.min(Math.max(n/i,0),1):0,a=e.warn??(e.metric==="load"?.7:null),c=e.alarm??(e.metric==="load"?.9:null),u=a===null&&c===null?mo:uo;n!==null&&a!==null&&n>=a&&(u=co),n!==null&&c!==null&&n>=c&&(u=ho),n===null&&(u=fo);let p=e.label;if(p===null){let x=s?s.text!==null?s.text.split(`
3
+ `)[0]:s.anchor:null;p=`${e.metric} ${x??(r.some(P=>P.id===e.of)?"flow":"?")}`}let f=e.style??"number",m=Math.max(t.width,1),y=Math.max(t.height,1),O=(x,P)=>[x.x/m,x.y/y,(x.x+(P.x-x.x)/3)/m,(x.y+(P.y-x.y)/3)/y,(x.x+2*(P.x-x.x)/3)/m,(x.y+2*(P.y-x.y)/3)/y,P.x/m,P.y/y],N=(x,P,_,B)=>{let W=[{x,y:P},{x:x+_,y:P},{x:x+_,y:P+B},{x,y:P+B}],he=O(W[0],W[1]);for(let Q=1;Q<4;Q++)he=he.concat(O(W[Q],W[(Q+1)%4]).slice(2));return{closed:!0,coords:he}},X=(x,P,_,B)=>{let W=Math.max(1,Math.ceil(Math.abs(B-_)/(Math.PI/2)-1e-9)),he=(B-_)/W,Q=4/3*Math.tan(he/4),we=h=>({x:x.x+P*Math.cos(h),y:x.y+P*Math.sin(h)}),w=we(_),L=[w.x/m,w.y/y];for(let h=0;h<W;h++){let d=_+h*he,E=d+he,R=we(d),b=we(E),S={x:R.x-Q*P*Math.sin(d),y:R.y+Q*P*Math.cos(d)},z={x:b.x+Q*P*Math.sin(E),y:b.y-Q*P*Math.cos(E)};L.push(S.x/m,S.y/y,z.x/m,z.y/y,b.x/m,b.y/y)}return{closed:!1,coords:L}},q=(x,P,_,B,W)=>({...dn,id:Le(t.id,-(2**38)-x),kind:"path",layerID:t.layerID,x:t.x,y:t.y,width:t.width,height:t.height,style:pn(_,B??{r:0,g:0,b:0,a:0},W,"solid",t.style.opacity),subpaths:P}),ie={...t,gauge:null,kind:"path",subpaths:[N(0,0,m,y)],text:p+`
4
+ `+po(e.metric,n),style:{...t.style}},ne=[];if(f==="number")ie.labelRect={x:0,y:0,width:1,height:1},ie.style.textColor={...u};else if(f==="bar"){ie.labelRect={x:0,y:0,width:1,height:.66};let x=Math.min(10,m*.08),P=Math.min(12,y*.18),_=y*.72,B=m-2*x;ne.push(q(1,[N(x,_,B,P)],Pt,Pt,.5)),l>0&&ne.push(q(2,[N(x,_,B*l,P)],u,u,.5))}else{ie.labelRect={x:0,y:.54,width:1,height:.46};let x=Math.min(m*.38,y*.4),P={x:m/2,y:y*.5},_=Math.max(2,x*.16);ne.push(q(1,[X(P,x,Math.PI,2*Math.PI)],Pt,null,_)),l>0&&ne.push(q(2,[X(P,x,Math.PI,Math.PI+Math.PI*l)],u,null,_));let B=Math.PI+Math.PI*l,W={x:P.x+x*.85*Math.cos(B),y:P.y+x*.85*Math.sin(B)};ne.push(q(3,[{closed:!1,coords:O(P,W)}],{r:.2,g:.2,b:.2,a:1},null,2))}return[ie,...ne]}var At=null;function yo(t){At=vt({version:2,pages:[JSON.parse(t)]}).pages[0]}function go(t){if(!At)throw new Error("no page");let e=JSON.parse(t);e.values??(e.values=null),e.since??(e.since=null),e.offline??(e.offline=[]),e.carried??(e.carried={});let n=At,o=fn(n.flows,n,e.t,e.values,new Set(e.offline),e.since,e.carried),r=Math.max(0,Math.min(e.since??e.t,1e6)),{plan:s,readings:i}=yn(n.elements,o.metrics,e.values,n,r,e.carried),l=[];return n.elements.forEach((a,c)=>{let{applied:u,gauge:p}=s[c];if(u.length===0&&!p)return;let f=a;for(let m of u)f=at(lt(a.overrides[m]),f);l.push([a.id,u,p&&f.gauge?xo(gn(f,f.gauge,p.value,n,n.flows??[])):null])}),JSON.stringify({packets:o.packets.map(a=>[a.id,a.x,a.y,a.width,a.layerID]),elements:Object.fromEntries(o.metrics.elements),flows:Object.fromEntries(o.metrics.flows),carry:{...o.metrics.carry,...i},finish:l,routes:e.routes?Object.fromEntries([...o.routes].map(([a,c])=>[a,c.map(u=>[u.goal,u.hops,u.amount,u.waits,u.cost])])):void 0})}function xo([t,...e]){let n=t.labelRect;return{text:t.text??"",label:[n.x,n.y,n.width,n.height],textColor:t.style.textColor,subpaths:t.subpaths??[],parts:e.map(o=>[o.id,o.subpaths??[],o.style.stroke,o.style.fill.a>0?o.style.fill:null,o.style.strokeWidth])}}globalThis.DottieSim={page:yo,frame:go};})();