chiltepin-studio 0.16.5 → 0.16.6

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.
@@ -2827,21 +2827,21 @@ a.link-chip:hover,a.st-link:hover{text-decoration:underline;}
2827
2827
  .docskin .code-cap-group{border:0;background:none;padding:0 2px;margin:-10px 0 18px;}`,s8="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAYmUlEQVR42t2beZRddZXvP/v3O3esuSpVSSpzCCGEIKOMsQtoNDSTiASRVhtxwKftw7HbVjEL27FtBxRQ24FunoIabFFsVBBIAFGZIpCEBELmVKqSGm/d4Zx7zu+33x/nVohvPQEDKHrXOqvuulP99vTde3/3PvDSfQgQqCIiIKbxytPvvWD/5KX4sAhOEFQN4HqBWUAE/G6/syt/ZQ8BrIgAfc3AZR0zuPvEZZnyBZc162kXZHXaTLmns1CY0fis+WsTXlLhuWj2oTx5+ccP1rsee6+uHjlef7x9oX/HDUFy2rtEu6fxk8Z3nrcCzEtIeJYvX24yOf3qOW9qvvGWW/9tweevuCHpmdftdo0N6JObxmTzusQ0TRfXOT9zBuTmIvjnK0PwUrF8X1+f+cUvVt70lg9Pe/UnrvhUMjBeNteuOTfYsnM3E+PG10PjsgWrrR3tJhtEAZTlrwUErYi4fF7/65IPTX/TZR85LH78iVrm/qd+Rf8WtDRR8NUxbDjiKGQCkrEsj98xfuPwXr24YX3/l+wBVkScqL7llRe1v+nvP9Ab/3rtusya9bvpfyqjE5W8jDzq7MjG+hPVEb2HJB6oTVSfDOF7L1QW+HN6gEFRhKkLDrfrP/vfc9siG3PP/f1m6+OqtVqTbrs9csPro/eXIv6jkQJfhEP8uR7LETFoLse/nP2Opo4pvcY/smHI7NyUUHdF7b8vMXseid5YivgKUG946+Qlf+kKMCsWo6pMXXCMueSVr+3QDZtKduf2GmGYSaq7AzO0rvqdiuf7QLbxnWS/S/9SFWAAyxyyV34cHwRcdtqFTa0trdZt2lGS8T2Kp2CHNkQajvKFxufdi1nxBX+KFAcYVZwx4kHRbbjmbPbQzvn195x8ZovftrNmR8bqhDXxXjOmOlx9rGZkjaiiin2xLfKCNzB9fQQrVmBERI0xXsQkIqiqzlXl9VOmyOeybfGq487Od/T0ZmVHf1WisuKdwcfgI5+o1+NVsSI4ePGU8GJngSZgIXDK3HmtZy9Y2HHi7JeXCrY9YtUPqrzv2g6dO6NT7nhwJ9s3JezpF+phO6WHSrzs8DYeXFVe88TG2odF5OfqVZB9IfGSCwEB6OqiuV4N3prN5I7omNI0p2da08HzD+qdccxJM+hdUqbctJUto8PuZ1dFetJrxZ521N/Jw+sfJ0rqxJHBRY4gD4lBDzvX6fEXzDzq5q8M/2zVT0Y+ifAxMeL0CjVciTQKoJdMHRAArqNNrlp2afO7z7pgIV3tbUzvnsPc7qWM+XXJQ7tukrWbd5vHHlIZeSrhE59cxqGF8/iPBz9K/2CJzY87hnZ6Ch3NDKwRXDTBojPx82ZOZfD+rFl14+C9AwP1jwF3iRFUFVJ8eF6KeEFiazEEe8EVO3MuseF5Y8UBCVt3EmY2saV8m/yu/16zc6hiymUj3dMNPQs9AzuF32xbxUhlhLAGo3uV2oRSryWYghJYjxiRUqkqi5YW3Ymnz57bmm/6h8pI/RWl8dgDu4Hy8ycennc9g10NyVXvPiO39Y6NZ9mtemr9fi08da+X+34VmcceT9ixAaK9TRx/9HymtAtHzT6K0eRJnto9RKVkKY17ahPgEsjmhLZuT+dMQSzk8xmsqpFi6OccneOIV0ydP3N2y/mBuEtcmCzo6so/XCol5QP1Zvt8hV8p4k5oDvoeufeJH/3NkZ1v+uDp83OXukhOHohl0RZl3u9g1YOe45b1cdQJbZw+7SvUkhJPjv8aKzkwSr4o9M62TJ9nae0xFFqEICdYMcSho651alEoe0ZGpKx7XfuCRHuWaHMS14/Z/WhiwphfNMLQ/6lAUJaDWWnEvTzQ97WRfO7tbz3anH/CzITHNgY6xdHVnuPobJa7toyz8IjFnLR8jN7sa9gw8UMeGvomJEUqYZW2DkNghErFMb0rTxh5xsuO0rgnX3Rs+AmUxhTbrkjW4OrYsFzyvoz3A2ZTNZO9ejmRXXmAXWFwoMLfZMQdJ/r5Q7py7/uX957qD23x3t3260Cb25DjjsEmIW7Hk3x1uIXTL5uKl608tPfrbB7ejroiTiK6ugxrVjkWzs4z44iA8rjS2hyAASOGcpgKfvTNCfMKwl48FugUkX6nrI99fnbWzVgJm/sgWP2n8IA+sCuNJMerfvHI2U3v+dcV5ybd47tsvG5Q7GnLkCw4r2TGd3PD6gnyJy+hd+EutgyMUVdHc1Mz5WrC5kc9j/y4zqzVnjumxZx7dRttvZ6RkTrZrCF2DmOF5nnQ3gJvMDAKqBfwKt29U3R9Pj/76i077zq52V64uuz+u6GE5EXDgD4IVoskx1n94OJp+Sv+7dPL4ym1oUys0yS47Muw9E1QLWG2PEy07Qk+v1c5+6PdTARbmKgpe/cqD66K+e23I4IbYv7+KeWdbZYZo56vPVDn4BPztE6BsXGHV/AeYq+U7vWcl7dMm5Iha5VsAGgiJ8zq9Yd2dZl7BvZeML1g778n0ieWg13/R6RF+8cA3q3gTirmXtWd9dd/5qNnJ73NLoibF0lwyVegpRsxOfTJVdj1d1Gq1Pn62AQ7zBD3/yLi0R/UGf4/EYvuSHjrMFzWmeWE+UXaZ+U4vMkwbVvM1fdGTH9Znu5eYe9IgqjgFCbudZzjDR3tGbKBQQCXJAwM7pGXTevRue3t5s7+oXPmFXM33Rq54RVgVj9HJTxXBch64OLDZ7dPDIzc9oFLjms+9qgeieN2Yy/6d3AxYrLojgeQO6/BxQlNgTJz4wi1/wk5Yb3ndaOGt3fkeM1BTSxY0EJhah6Tt6gTKFiWtFkW7Yz59p0hlS7LgkWWauip1pToPs95WArNAWKEjBW0Id7gniE5evZsb60p3LNn7MQblvZdd+u2bax/IT1gOdj1Ij43OP65M1/e87eXXnycS3b0W3vuFVDsgiADpd3wy3+H6igSx2gUsqAt4NTeHMcc3MLcQ9po6m3Ct+bw1oCmQoiAeMVnDQvaA04pOe66s84Dw8qcJRlKkad+u+fCjCUoWlTBWoOgxInivTI+Nm5OWXhwsn58bNY3Nz1V+mXCr55rKDyrAlaAuRZ0aXN2cVfOf/Ojly2VtrFdRuccL+aE16cSjO+Eu6+Coe1QjyCqQhLjshbfmsXnLYqgHkgUvIIqMtnpK4iCt4butgxnBcCamLt+G/Pkk3DmgHJKWwbNGaRR+AaBIak7PIY4TsiKlYOnTtPb+gePX9jVdN0tlbjS6Hb1ebXD60EQ0Vq5/uGzTpiVmdWT9cnwmJhCEa2OwIbb4NYV0P8khDUIy+BjsGCMYlQxxiBGEAOSEcQ2aIJ0FAJGwKRPYyPkuvO845Ai34oCrnlcuaQ1gzQHiIKINHQmFAsBgqeQz7Fr1w5Z3DXbv2rG9PbBocrlINr3HOST58AX+FPb83NySbTha/90Sm4OoyR1J2bqTMg1QWkAjIEkQaMqrh5BEoN6RMFqw+KJQuwh1vRKFCIHsaLOT0I+KKjzKBAoSORxAqqgTlFV1KWub0QYm4gZr3iCIMeso5f5jYV2eddN/7m3OLvz4J9vGik9G3tsniXtGUQYHgtff/yirvyc3qJze/eIedX/gjlHw9bHIAqhMoErjWLrNbIFIdtZINucIZMF7316+sYZ1Gujk0sBQEURUUBQa1JPMIIRwYmQ5AxqBZVJL5GnzaZKIWvAe9q7p+CiEbN4+lx/1Mzenl2bRs4Goe9ZwvwZFbAanAgUhPNPPnIGjAyKb+5BjjoTtqyDWgUqZVxpgozEVEyW6x8e5/0/2s4n7hjivm01gkBSy03GPYo4n1q9YRedPIlJQ0KtIZH0HSupQryQKkFATBovzoM1QjYQxoaHGO/fgtm7Q5fOP1xtyjvTc6AYsKIBIEtbsvN6Ws0RS+Z3wNC4kaiMXnMpuuE3oAGuXCUTKD/fAUuv28Et/kT02DfzncfhrO/s5opVIxgL6n3qvpqeKBUijfs0GAURwRvB4skVMwRtBXw+hw2EXN6QMYLX1PLSKJS8QiZjiGohe3buYGLbWntEa7u0FjjppM6OlpUpgyR/dCm8qhH/o+PRy49a1JKd3mqd31a2YhSeegTJ5HBhSKZg+cnGhLfeNs5137mBs159LgB/d/LL+NDbLuWqhyY4rM1y0eIm6rEnsAZsigsquu9ooh6nQkaUqK2ZLz8xxq3bK4yUYWqL5dSOgHf1BLQaCN1+dKuHwAjGpnzZ2OBWmdExRWc253oeLg8fBvxmOZiVf4BKe2aUFMHCkXOmNoOP1VVCRIEgi08cgYGd48pbftTPP//zBznr1ecyURoHYPP2XZQjmNoccP36Mhp7rKSe8HTeSy0J4Dxk1LMj18Rpvy7xyJILeNuXb+SMt72dJ2qez/XHnL2+ykDsCQSc7sug+3BBgUp5jGI44OYX85BwOMCeA/GAnjTTIMpB0zvzUKtB4veBj4ogGcM1v5mgpnDGGcsAaGltY+O6x/jGFz9PrmDAeHZVlJGKoytvSVAadHfauzlFfaqPar7A8rsHeN1HvsB7L383ABdffBE7f3cPmx7fwKOh8KHtEdfNzTWwXfGTxVRjl6Ye16EyxvRsgMKCZxshmmegubRRKXV1FC3U41SLDtRDYGCi4rh9e8icJuH7136WB+5ZxfVfvYo3n30aYaVENmcxpIcMvYBN45xGHEOqCK8QFDN84dEh7IJjee/l76ZWqxLHdcbHxtjcP8REoswtGG4ve9aWHQVSDEizCqim+JB4Ja5W6AqErDDtgNvhK0EFMEJLXjwkScNiHjWCZIQtJcdIGDO3K8cvf3ozP/jezdTrUChAGIGrewotlpyB1nxjy0kb6O/TS4HACmEM39lU54yl8wAoFIoAXPWJ97Nr6146p2TI4IkRHqh4Ds8bXCMGVJX9HIp6nEjBGDJWuhHo0T/sAs/KB1iDMWEIVZtaP1E0SBEoTFL/qyceb7MUmz3FdDbC+z/5ccYHtnHVF69h6fwCLS0BSegx1qT+3tjwUQ/GwmN7IyoFw+CaO7jth9+ltbuX733r6/z4hu/T1ZVFVREjWCsMN8pp1fR3fEMJ8HSVaI3BqPrUjAfgAStArlTUCbWwHELVoIkiiU/d2CnTC4a8lUa+VqwRxkZiTj+nj0v/9wdYe/+v+Ninr+aiY7pQ08jjljR+VPHO40XBGrZHDglgz8gY7/mHN1BPwDlobTWMDNWxFnqmZFLvyJiniyqfun2iDWD0YGygcaw4T/WAQ2B9AzkTZXC0VIc4q/hUcGM8SQizWgOO7c7y0HDCQV0ZnBemNVnK29dy1Uf+kW9f/yPOO6GTsxYWkPGQIBA8mvYCHjIFg29YMUhnZ1QTyDdlyHiPiCGsJbzxnW+FJOLnK2/AAIe0BI1yWVD1JEmKM17TXGetZawakigjz5YF/iAI7gFBFbFs7h+LIfbpr7gGEMYOrYZccUyOfODZORLTmjUUspbNWwZY8alrOHRezDWv6UVqIV94sMQ/3r4XmzV4UWwGfjtUZ6xxioOaDTlJnSNrwRpDeTzmpL5X8Imrv8G/XvMt6kGOuUXhhJaAcqKTiYC4Yf3Ep5lArGUwrINl+/MejibWrNs+WodajAU08RA7rBp8y2wOnnsIKy9ZzIlHtjMshiEs0w+dzjUfOZYbL5xF08AYYFm3J+Tu7TWGywlBR5Y7d0ecduswP91RAwOLWgOOaA4oxdDZlKE1b5nVnSEZ3clvbvsxV77nnWwdrfJPiztoqdSJAO8U55W609QuCllrSayVnWEdFR5/NkrgD4bAKeBXAy0F+9DWcuwH90R2amsWlyj4BOa8DOldSGIM8wO4ZuYOSqNbiJsKdGWBkXH8hgouE2AT5Q2LW7l9S8jrfjrIQR0Z7twacmSnoW9qFl/3WIQrD2vi4ocnGBzzHNRTIJfJM7J7J28+5zwGYvjMGVN5dbnKWD2tghQlclB34FRw3tPUlGNUsVtr9SSX4VFq8ExssXmGNOgBufz08zYMOtmwdnckeO/VNVrZBtdg4pAkTkh0Hq2D0PXoZvyaXcT9ZVQsQaK4SsKpM3N89bROpuaETUN1zpyd4/q+DuY0B/hEcbFnSdHw3dO7OXhuM9snEp4YqjFQ9Rx2aCs/umgm74wjJoYj1Ai+UUDVEiVW8D7NAp0tTX5rrc5Q3W+cv2z51qcL5gNIg31gL1y5MjmySW757Zhb/LdjdU9T1igG2bIWsnlkSi8myIDGOBSVDGJtGi5xWrQLiqsrZ80pcNb0HPVEyVqB0KepsdEex5FyeBzxvSNb2OibGUqEKd3dHKIG1u6i3F/GZwJclDZWUaKEkwCIEFihrbnJP7hn1NSUn61ceZN7Nqr8GRUwGQZNmeDG+6vJBzeP1O28jMFnArQawiP3QPsUaGqFqIREJcgE4B1q01YvXQRT8BCHDqNKRpW4pkisGJcimCaKUYgjj6wd4pBikUOOejkU23GVGL9kJpn2rdTXrsNr2gqX6p6k0REaoDWfY8KI+dXohIrhB6AH3g5PhsEKMPeNxY8MOFavGvfIeOx87BEv4Aw6PIRufwpGRyERJHRIlF7s++uR2GMTD5HHhx4bKzLJEtV9GlaJxzjAJyTTZ5O0TSWp1sCHBOoIunpwavDeU64rdZd+zZjUy2Z2tLjfliqyNXQPrKnqgzxDF/hHcYIKGGM++/MJke0VRzJRT7NBoqAWJIs6g0Y+veqKhg5Ch0YNAev+95/XUwpM49T6k4rQyOHV4nbugP7tGO8Q53ATE0w89hiuHhPGUI39vlI4Y4SmXAZbzHPzwIjEcJXIC8MJ7iNHPg7+uKLceXE7p17WaVyYt7a1JYsXeZrYnFxgF1KecL+2GtjHBjeC9un9L6do4lKCwynOg48TPIIWingPrlzBxQmRM4yHjsgLdacUAyF2nkVTu90dsbef3jb86JnH9x3D6tX+yucwK3xOc4EeMOtAD23OPPxE6N+2KIdME6SaeMkFDY4/8eBBJrOEZx8Zmrp64/XG+xqnHqSJ4hNPEivOgXNKkqTI4RzElRpJLURVCJ0wVnPEmqa+QiAEKB1NRXxLi//Mtr2mjHnjd5/csqkHzAsyF2iEgS4H+9PQD0wJTLI98a98RcEkJGrD2JNt9DfepfU5rtGsuLRw0kmga4Cd92md7xKPS1LBk4blnVOcS8vbxCkeg0eYCD2l0ONIyeSCFYoZQAxzpvYkX+ofDh4qx998oMaXloNd+RyXqZ7zbHB9Y0J0R6x356wcP5zoIX9TCJJarKYW+cbmc+rSzpPm9uRpCttPWrdh4VTQSaFTBSSN15JEJ3VIGHsmQk+1ke5iD3krtGaFxCsHdU9xPxirBt/fW954bEv3ax+oVpIXZTi6HyDKsp7WW+8v1c+pqE5dWgiSSuxNNXTEcSrsJPGpflJQfk/oOGkI6cE1nieTivJpURMlSjnyTNSVWAWnQtxw+9asoe6UuZ2d7s7Q22t3j401F7LLbhye2LUCZPWLpQBAV4B8sRRVj2nO3/JwLT6npkx5RXM2Dp3aibqnXveEkSdOfOrmvuH6jXw9CXTs99xr6h1R4qkmnlJdKUdK5J8mObxCMWPIZ9KJ8dyuTreqrvZL/SOhz9hz7hhLHlgO9to/cklCDng3CNz50/JzBkrRLa9sMYe/szOX+Ci2g2Ei6aQrjYc0SUg6/TKyr4NDUgU4Td0/9rovOfiGCJ5Gfy+p8KDkraW3rTX5n2ocfGOwNJ6IPf+eirvzQJYjntee4KQS3jKztXP9SOk/l+TNOW/vyrFQcLsqkZ1IFCP73d+mTws+OShSGiSJgm8wPig41bQRAbJGGu2x0JUv+CSX1xtGy/bWsXBDMZe56Lax+JEDFf55bYmtT8PBfLEUVfsTbiyKVO+uJCeHRnKLmrJ+WmB9lKhUnZfYp6Mtj+D2o61c466nNHEIDsUhiELGQC4QilZoz+Z8S7HJrfFiv7KnZO6rxN+d1912wc2D1a2Tixt/zk3RfSOKU5syh9U0/tSsjJz7quYMJ2YtU1STcuxMKXZS9SoxKX+X3hRJCquNWt4aIWeEYiAUrfVZY33FBGajx/yyErKmGq9zxq64r+x/CMoKMFc+z3uGXrBl6f3dsK/Nnh4l7vKpVs44Km+DI7OW+YGhVdXhVVUVpyqTWx7WGDLGYI1oojAhxg4osr6e8FAYszl2j9YwX1vcNeu6/9q2LWwIri+5e4Ya88RJLoG+jsySauxek8efO8XK4TMCyfUaQ7cV2owhIykoxkBVYdQrA4ljR+wZdH7rhHKnt3blB5edf/uFK1e6/bHnJb0uvxzsYtBJRQjCKa3Zg6o+OcKhSwL8wRmRGUBz6g+SONU9ibLdGLPeO/PwvK5pa1fu3Fn7f0DX/0XdL7wCTN8f5Bx+bzT8/7XFcrDLU6B+0e5rkD+lMlbt156eAr4Rx6xIt9Bkkr7uAf1TWfv/AgxYkH5Da9T7AAAAAElFTkSuQmCC",o8=`<link rel="icon" type="image/png" href="${s8}">`,r8={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"};function S(e){return e==null?"":String(e).replace(/[&<>"]/g,t=>r8[t]??t)}var i8=/^(#[0-9a-fA-F]{3,8}|rgba?\([\d.,\s%]+\)|hsla?\([\d.,\s%]+\)|[a-zA-Z]{1,24})$/;function Fi(e,t){if(e===void 0)return t;const n=e.trim();return i8.test(n)?n:t}var a8=/^\s*(javascript|data|vbscript):/i;function yf(e){return a8.test(e)?"#":e}var qy=new h4({gfm:!0,breaks:!1});qy.use({tokenizer:{html(){},tag(){}},renderer:{heading(e){const t=this.parser.parseInline(e.tokens);if(e.depth>2)return`<h${e.depth}>${t}</h${e.depth}>
2828
2828
  `;const n=by(t),s=FM(t),o=s!==void 0?`<p class="src-note">Source: ${S(s)}</p>
2829
2829
  `:"";return`<h${e.depth}>${n}</h${e.depth}>
2830
- ${o}`},link(e){const t=yf(e.href),n=e.title!==null&&e.title!==void 0?` title="${e.title}"`:"",s=this.parser.parseInline(e.tokens);return`<a href="${t}"${n}>${s}</a>`},image(e){const t=yf(e.href),n=e.title!==null&&e.title!==void 0?` title="${e.title}"`:"";return`<img src="${t}" alt="${e.text}"${n}>`}}});function g0(e){return`<div class="prose">${qy.parse(e,{async:!1})}</div>`}function vo(e){const t=e.split(/\n{2,}/).map(s=>s.trim()).filter(s=>s!==""),n=s=>qy.parseInline(s,{async:!1});return t.length<=1?n(t[0]??""):t.map(s=>`<p>${n(s)}</p>`).join("")}function g4(e){const t=e?.title??"Untitled",n=e?.tag??"",s=e?.subtitle,o=s!==void 0?`<p class="cover-sub">${S(s)}</p>`:"";return'<div class="cover-pad">'+(e?.logo!==void 0&&e.logo!==""?`<img class="cover-logo" src="${S(yf(e.logo))}" alt="${S(t)}">`:"")+`<div class="cover-meta"><span>DOCUMENT</span><span class="accent">${S(n)}</span></div><h1 class="cover-title">${S(t)}</h1>`+o+"</div>"}function l8(){return""}function _(e){return` data-bp="${S(e)}"`}function he(e){return` data-bl="${S(e)}"`}var c8=1600,d8=/<svg\b[^>]*\bviewBox="-?[\d.]+ -?[\d.]+ ([\d.]+) [\d.]+"[^>]*>/;function u8(e){const t=d8.exec(e);if(t===null||t[1]===void 0)return e;const n=t[0];if(n.includes(" style="))return e;const s=Math.ceil(Number(t[1]));if(!Number.isFinite(s)||s<=0)return e;const o=e.indexOf("</svg>",t.index+n.length);if(o<0)return e;const r=s>c8,i=r?`${n.slice(0,-1)} style="width:calc(${s}px * var(--scale,1));max-width:none">`:`${n.slice(0,-1)} style="max-width:min(100%,calc(${s}px * var(--scale,1)))">`,l=o+6;return e.slice(0,t.index)+`<div class="diagram-stage${r?" diagram-stage--wide":""}">`+i+e.slice(t.index+n.length,l)+"</div>"+e.slice(l)}function ct(e,t){const n=e.tagClass!==void 0?` ${e.tagClass}`:"",s=e.method!==void 0&&e.method.length>0?`<span class="diagram-tag-sep">·</span><span class="diagram-tag-method${n}">${S(e.method)}</span>`:"",o=e.path!==void 0&&e.path.length>0?`<span class="diagram-tag-path">${S(e.path)}</span>`:"",r=`<span class="diagram-eyebrow t-eyebrow"><span class="diagram-tag${n}">${S(e.tag)}</span>`+s+o+"</span>",i=e.titleHtml!==void 0?`<span class="diagram-title">${e.titleHtml}</span>`:e.title!==void 0&&e.title.length>0?`<span class="diagram-title">${S(e.title)}</span>`:"",l=e.fignum!==void 0&&e.fignum.length>0?`<span class="diagram-fignum">${S(e.fignum)}</span>`:"",d=e.desc!==void 0&&e.desc.length>0?`<p class="diagram-desc"${_("description")}>${S(e.desc)}</p>`:"",u=e.legendHtml??"",p=e.footerHtml??"";return'<div class="diagram"><div class="diagram-head">'+r+i+l+"</div>"+d+u8(t)+u+p+"</div>"}var p8={meta:"",callout:"Note",table:"Comparison",sequence:"Sequence",erd:"Entity model",userstory:"User story",timeline:"Roadmap",kanban:"Board",prose:"Overview",glossary:"Glossary",proscons:"Trade-offs",cvt:"Before / after",stats:"Metrics",code:"Code",agenda:"Agenda",tree:"Hierarchy",pyramid:"Pyramid",flow:"Flowchart",state:"State machine",dfd:"Data flow",journey:"Journey",gantt:"Schedule",graph:"Graph",quadrant:"Matrix",swimlane:"Process",c4:"C4 model",uml:"Class model",frontend:"Component tree",cluster:"Cluster",block:"Architecture",felogic:"Frontend logic",wireframe:"Mockup",endpoint:"API endpoint",pullquote:"Quote",layers:"Layers",matrix:"Capability matrix",anatomy:"Anatomy",composition:"Composition",drivers:"Drivers",options:"Options",spec:"Spec",list:"List",stories:"User stories",pattern:"Pattern",gallery:"Gallery",chart:"Chart",figure:"Figure",steps:"Steps",faq:"FAQ",envelope:"Capacity math",slo:"Service objectives",swot:"SWOT",okr:"Objectives",persona:"Personas",changelog:"Changelog",team:"Team",heatmap:"Heatmap",scorecard:"Decision matrix",risk:"Risk register",palette:"Palette",typescale:"Type scale",dodont:"Guidelines",inventory:"Inventory",array:"Array",linkedlist:"Linked list",bintree:"Binary tree",hashmap:"Hash map",agentloop:"Agent loop",trace:"Trace",prompt:"Prompt",context:"Context window",archmap:"Architecture map",divider:"Divider",bignumber:"Big number",takeaways:"Takeaways",statustable:"Status",cycle:"Cycle",benchmark:"Benchmark",sankey:"Flow volumes",gitgraph:"Branch model",treemap:"Composition",packet:"Wire format",venn:"Overlap",wardley:"Strategy map",harvey:"Comparison",scqa:"Summary",scenarios:"Scenarios",fishbone:"Cause & effect",storymap:"Story map",eventcontract:"Event contract",saga:"Saga",slopegraph:"Before / after",spans:"Trace",rollout:"Rollout",perfbudget:"Performance budget",percentiles:"Latency percentiles",timing:"Timing diagram",threatmodel:"Threat model",neuralnet:"Neural net",mindmap:"Mind map",usecase:"Use cases",pkg:"Packages",audit:"Audit findings",checklist:"Checklist",modelcard:"Model card",chevrons:"Process",roadmap:"Roadmap"};function Aw(e){if(e.sourceType!==void 0){const t=io[e.sourceType];if(t!==void 0)return t.sectionLabel}return p8[e.kind]}var Cw={note:"Note",tip:"Tip",warn:"Warning",danger:"Danger",success:"Success"};function f8(e){const t=e.tone??"note",n=e.title??Cw[t]??Cw.note,s=e.body??"";return`<div class="callout ${t}"><div class="callout-title"${_("title")}>${S(n)}</div><div class="callout-body"${_("body")}>${vo(s)}</div></div>`}var yn=30,Cn=14;function h8(e,t,n,s){return s?`<path d="M${e-6},${t-3} L${e},${t} L${e-6},${t+3} z" fill="${n}"/>`:`<path d="M${e-6},${t-3} L${e},${t} L${e-6},${t+3}" fill="none" stroke="${n}" stroke-width="1.2"/>`}function $r(e,t,n,s){const o=Cn/2,r=n.length>0?` stroke-dasharray="${n}"`:"";return`<line x1="1" y1="${o}" x2="${yn-7}" y2="${o}" stroke="${e}" stroke-width="${t}"${r}/>`+h8(yn-1,o,e,s)}function pi(e,t,n,s){const o=s.length>0?` stroke-dasharray="${s}"`:"";return`<rect x="1" y="1" width="${yn-2}" height="${Cn-2}" rx="2" fill="${n}" stroke="${e}" stroke-width="${t}"${o}/>`}function m8(e,t,n,s){let o;switch(e){case"node-dot":{const r=s!==void 0&&s.length>0?` stroke-dasharray="${s}"`:"";o=`<circle cx="${yn/2}" cy="${Cn/2}" r="5.5" fill="${t??"var(--paper)"}" stroke="${n??"var(--ink)"}" stroke-width="1.5"${r}/>`;break}case"line":o=`<line x1="1" y1="${Cn/2}" x2="${yn-1}" y2="${Cn/2}" stroke="${n??"var(--muted)"}" stroke-width="1.25"/>`;break;case"line-dashed":o=`<line x1="1" y1="${Cn/2}" x2="${yn-1}" y2="${Cn/2}" stroke="${n??"var(--muted)"}" stroke-width="1.25" stroke-dasharray="5 4"/>`;break;case"node-accent-outline":o=pi("var(--accent)",1.5,"var(--paper)","");break;case"fill":o=pi("var(--rule-solid)",1,t??"var(--ink)","");break;case"node":o=pi("var(--ink)",1.5,"var(--paper)","");break;case"node-accent":o=pi("var(--accent)",1.5,"var(--accent-tint)","");break;case"node-dashed":o=pi("var(--ink)",1.25,"var(--paper)","4 3");break;case"node-fill2":o=pi("var(--rule-solid)",1,"var(--paper-2)","");break;case"edge":o=$r("var(--muted)",1.5,"",!0);break;case"edge-dashed":o=$r("var(--muted)",1.5,"5 4",!1);break;case"edge-async":o=$r("var(--muted)",1.25,"2 3",!1);break;case"edge-error":o=$r("var(--negative)",1.5,"",!0);break;case"edge-accent":o=$r("var(--accent)",1.75,"",!0);break;case"edge-link":o=$r("var(--link)",1.5,"",!0);break;case"edge-accent-dashed":o=$r("var(--accent)",1.75,"5 4",!1);break;case"edge-negative-dashed":o=$r("var(--negative)",1.5,"5 4",!0);break;case"edge-implements":{const r=Cn/2;o=`<line x1="1" y1="${r}" x2="${yn-8}" y2="${r}" stroke="var(--muted)" stroke-width="1.5" stroke-dasharray="5 4"/><path d="M${yn-8},${r-4} L${yn-1},${r} L${yn-8},${r+4} z" fill="var(--paper)" stroke="var(--ink)" stroke-width="1.2"/>`;break}case"line-dot":case"line-dot-accent":{const r=Cn/2,i=e==="line-dot"?"var(--muted)":"var(--accent)";o=`<line x1="1" y1="${r}" x2="${yn-1}" y2="${r}" stroke="${i}" stroke-width="${e==="line-dot"?1.5:1.75}"/><circle cx="${yn/2}" cy="${r}" r="3.5" fill="${i}"/>`;break}case"node-store":o=`<rect x="1" y="1" width="${yn-2}" height="${Cn-2}" fill="var(--paper-2)"/><path d="M${yn-1},1 H1 V${Cn-1} H${yn-1}" fill="none" stroke="var(--rule-solid)" stroke-width="1"/>`;break;case"node-stadium":o=`<rect x="1" y="1" width="${yn-2}" height="${Cn-2}" rx="${(Cn-2)/2}" fill="var(--paper)" stroke="var(--ink)" stroke-width="1.5"/>`;break;case"node-stadium-fill2":o=`<rect x="1" y="1" width="${yn-2}" height="${Cn-2}" rx="${(Cn-2)/2}" fill="var(--paper-2)" stroke="var(--rule-solid)" stroke-width="1"/>`;break;case"node-negative":o=pi("var(--negative)",1.5,"var(--negative-tint)","");break;case"chip":return""}return`<svg class="lg-sw" viewBox="0 0 ${yn} ${Cn}" width="${yn}" height="${Cn}" aria-hidden="true">${o}</svg>`}function ot(e,t){if(e.length<2)return"";const n=e.map(o=>{const r=o.swatch==="chip"?`<span class="lg-chip t-eyebrow">${S(o.chip??"")}</span>`:m8(o.swatch,o.fill,o.stroke,o.dash);return`<span class="lg-item"${o.path!==void 0?_(o.path):""}>${r}<span class="lg-label">${S(o.label)}</span></span>`}).join("");return`<div class="diagram-legend"${t!==void 0?he(t):""}><span class="lg-title t-eyebrow">Legend</span>${n}</div>`}function wt(e,t,n=`${t}s`){return`${e} ${e===1?t:n}`}function Hy(e,t,n=[]){const s=(t??"").trim(),o=[...s!==""?[s]:[],...n.filter(r=>r.trim()!=="")];return o.length===0?e:`${e}: ${o.join(", ")}`}function g8(e){return` role="img" aria-label="${S(e)}"`}function v8(e){return`<title>${S(e)}</title>`}function Sn(e,t,n=[]){const s=Hy(e,t,n);return{name:s,attrs:g8(s),title:v8(s)}}var ut=' data-decorative="1"',zr=20,Bc=40,v4=6,Bn=12,Wa=6.2,y4=7.4,y8=150,lc=28,Hu=64,Sa=14,Ea=14,Nw=18,Ma=18,Wy=7;function x8(e){const t=e.entities??[],n=e.relations??[],s=e.groups??[],o=e.enums??[],r=e.dir!=="TB",i=t.map((fe,ge)=>k8(fe,ge)),l=new Map;for(const fe of i)l.set(fe.name,fe),fe.entity.schema!==void 0&&l.set(`${fe.entity.schema}.${fe.name}`,fe);const d=[];n.forEach((fe,ge)=>{const Ce=l.get(fe.from),Fe=l.get(fe.to);if(Ce===void 0||Fe===void 0)return;const qe=E8(fe.card);d.push({r:fe,idx:ge,from:Ce,to:Fe,...qe,dashed:fe.identifying===!1})});const u=new Map,p=new Map;for(const fe of d)fe.toMany||u.set(fe.to.name,(u.get(fe.to.name)??0)+1),fe.fromMany||u.set(fe.from.name,(u.get(fe.from.name)??0)+1),p.set(fe.from.name,(p.get(fe.from.name)??0)+1),fe.to!==fe.from&&p.set(fe.to.name,(p.get(fe.to.name)??0)+1);let h,m=0,g=!1;for(const[fe,ge]of u)ge>m?(m=ge,h=fe,g=!1):ge===m&&(g=!0);g&&(h=void 0);const v=[],y=new Map,b=[];for(const fe of s){const ge=(fe.entities??[]).filter(Fe=>l.has(Fe)&&!y.has(l.get(Fe)?.name??Fe));if(ge.length===0)continue;const Ce=v.length;v.push(fe.name),b.push(!0);for(const Fe of ge)y.set(l.get(Fe)?.name??Fe,Ce)}for(const fe of i){if(y.has(fe.name)||fe.entity.schema===void 0)continue;let ge=v.indexOf(fe.entity.schema);(ge===-1||!b[ge])&&(ge=v.length,v.push(fe.entity.schema),b.push(!0)),y.set(fe.name,ge)}const E=i.filter(fe=>!y.has(fe.name));if(E.length>0){const fe=v.length;v.push(""),b.push(!1);for(const ge of E)y.set(ge.name,fe)}const $=i.map((fe,ge)=>({box:fe,band:y.get(fe.name)??0,layer:0,order:ge,u:0,v:0,du:r?fe.w:fe.h,dv:r?fe.h:fe.w})),A=new Map($.map(fe=>[fe.box.name,fe])),T=new Map;for(const fe of $)T.set(fe.box.name,new Set);for(const fe of d)fe.from!==fe.to&&(T.get(fe.from.name)?.add(fe.to.name),T.get(fe.to.name)?.add(fe.from.name));S8($,T,p,h,A);const N=[...new Set($.map(fe=>fe.layer))].sort((fe,ge)=>fe-ge),j=N[0]??0,P=N[N.length-1]??0,I=[],O=new Map,C=(fe,ge)=>{const Ce=O.get(fe)??[];Ce.push(ge),O.set(fe,Ce)};let D=0;for(const fe of d){const ge=A.get(fe.from.name),Ce=A.get(fe.to.name);if(ge===void 0||Ce===void 0)continue;const Fe=ge===Ce,qe=ge.layer,ze=Ce.layer;let Xe,pt,kt=!1;Fe?Xe=pt=qe:qe<ze?(Xe=qe,pt=ze-1,kt=ze-qe>1):qe>ze?(Xe=qe-1,pt=ze,kt=qe-ze>1):Xe=pt=qe;const St={rel:fe,src:ge,dst:Ce,g1:Xe,g2:pt,long:kt,self:Fe,slot1:0,slot2:0,channel:kt?D++:-1};I.push(St),Fe||(C(Xe,St),kt&&C(pt,St))}const F=new Map;for(let fe=j;fe<=P;fe++){const ge=O.get(fe)?.length??0;F.set(fe,Math.max(fe===P?ge>0?(ge+1)*Sa:0:Hu,(ge+1)*Sa))}const U=D>0?D*Sa+8:0,X=new Map,B=new Map,te=[],ee=()=>{let fe=Ma;for(let Fe=j;Fe<=P;Fe++){const qe=Math.max(0,...$.filter(ze=>ze.layer===Fe).map(ze=>ze.du));X.set(Fe,fe),B.set(Fe,qe),fe+=qe+(F.get(Fe)??Hu)}let ge=Ma+U;te.length=0;let Ce=!1;v.forEach((Fe,qe)=>{const ze=$.filter(dt=>dt.band===qe),Xe=b[qe]===!0;if(ze.length===0){te.push({top:ge,bottom:ge,minL:0,maxL:0});return}const pt=ge+(qe>0?(Ce?Ea:0)+lc:0)+(Xe?Ea+Nw:0);let kt=0;const St=new Map;for(const dt of ze){const _t=St.get(dt.layer)??[];_t.push(dt),St.set(dt.layer,_t)}for(const dt of St.values())dt.sort((_t,En)=>_t.order-En.order),kt=Math.max(kt,dt.reduce((_t,En)=>_t+En.dv,0)+lc*(dt.length-1));let Nt=1/0,Bt=-1/0;for(const[dt,_t]of St){const En=_t.reduce((Et,an)=>Et+an.dv,0)+lc*(_t.length-1);let zt=pt+(kt-En)/2;for(const Et of _t)Et.u=(X.get(dt)??0)+((B.get(dt)??Et.du)-Et.du)/2,Et.v=zt,zt+=Et.dv+lc;Nt=Math.min(Nt,dt),Bt=Math.max(Bt,dt)}te.push({top:pt,bottom:pt+kt,minL:Nt,maxL:Bt}),ge=pt+kt,Ce=Xe})};ee();const H=[...N].sort((fe,ge)=>Math.abs(fe)-Math.abs(ge)||fe-ge),W=(fe,ge)=>{for(const Ce of fe){const Fe=ge(Ce);for(const qe of $){if(qe.layer!==Ce)continue;const ze=[...T.get(qe.box.name)??[]].map(Xe=>A.get(Xe)).filter(Xe=>Xe!==void 0&&Xe.layer===Fe);ze.length!==0&&(qe.order=ze.reduce((Xe,pt)=>Xe+pt.v+pt.dv/2,0)/ze.length)}}ee()};W(H,fe=>fe>0?fe-1:fe<0?fe+1:fe),W([...H].reverse(),fe=>fe>=0?fe+1:fe-1),W(H,fe=>fe>0?fe-1:fe<0?fe+1:fe);for(const[fe,ge]of O){const Ce=(X.get(fe)??0)+(B.get(fe)??0),Fe=F.get(fe)??Hu;ge.sort((qe,ze)=>Pw(qe.src,qe.dst)-Pw(ze.src,ze.dst)),ge.forEach((qe,ze)=>{const Xe=Ce+(ze+1)*Fe/(ge.length+1);qe.g1===fe&&qe.slot1===0&&(qe.slot1=Xe),qe.long&&qe.g2===fe&&(qe.slot2=Xe),qe.long||(qe.slot2=qe.slot1)})}const K=(fe,ge)=>r?fe:ge,R=(fe,ge)=>r?ge:fe,z=fe=>fe.map(([ge,Ce],Fe)=>`${Fe===0?"M":"L"}${nt(K(ge,Ce))},${nt(R(ge,Ce))}`).join(" ");let Y=0,V=0;const re=(fe,ge)=>{Y=Math.max(Y,fe),V=Math.max(V,ge)};for(const fe of $)re(K(fe.u+fe.du,fe.v+fe.dv),R(fe.u+fe.du,fe.v+fe.dv));let Q="",ne=!1;Q+=`<g${he("groups")}>`,v.forEach((fe,ge)=>{if(b[ge]!==!0)return;const Ce=te[ge];if(Ce===void 0||Ce.top===Ce.bottom)return;ne=!0;const Fe=(X.get(Ce.minL)??0)-Ea,qe=(X.get(Ce.maxL)??0)+(B.get(Ce.maxL)??0)+Ea,ze=Ce.top-Ea-Nw,Xe=Ce.bottom+Ea,pt=K(Fe,ze),kt=R(Fe,ze),St=K(qe,Xe)-pt,Nt=R(qe,Xe)-kt;re(pt+St,kt+Nt);const Bt=s.findIndex(dt=>dt.name===fe);Q+=`<g${Bt>=0?_(`groups.${Bt}`):""}><rect x="${nt(pt)}" y="${nt(kt)}" width="${nt(St)}" height="${nt(Nt)}" rx="8" class="er-panel"/><text x="${nt(pt+12)}" y="${nt(kt+13)}" class="t-eyebrow er-panel-tab">${S(fe.toUpperCase())}</text></g>`}),Q+="</g>";const Z=[];let q=!1,de=!1;Q+=`<g${he("relations")}>`;for(const fe of I){const{rel:ge,src:Ce,dst:Fe}=fe;q=!0,ge.dashed&&(de=!0);const qe=ge.fromMany&&!ge.toMany?!0:!ge.fromMany&&ge.toMany?!1:Lw(ge.from,ge.to,ge.r.fromCol)||!Lw(ge.to,ge.from,ge.r.toCol),ze=ge.fromMany&&ge.toMany,Xe=ze?Ce.v+Ce.dv/2:jw(Ce,r,qe?y0(ge.from,ge.to,ge.r.fromCol):Iw(ge.from,ge.r.fromCol)),pt=ze?Fe.v+Fe.dv/2:jw(Fe,r,qe?Iw(ge.to,ge.r.toCol):y0(ge.to,ge.from,ge.r.toCol)),kt=Ce.layer,St=Fe.layer;let Nt,Bt,dt,_t;if(fe.self){const zt=Ce.u+Ce.du,Et=Math.abs(pt-Xe)<1?Xe+zr:pt,an=zt+Sa;Nt=z([[zt,Xe],[an,Xe],[an,Et],[zt,Et]]),Bt=1,dt=-1,_t=[an+8,Math.max(Xe,Et)+12]}else if(kt===St){const zt=Math.max(Ce.u+Ce.du,Fe.u+Fe.du),Et=fe.slot1>0?fe.slot1:zt+Sa;Nt=z([[Ce.u+Ce.du,Xe],[Et,Xe],[Et,pt],[Fe.u+Fe.du,pt]]),Bt=1,dt=-1,_t=[Et,(Xe+pt)/2]}else{const zt=kt<St,Et=zt?Ce.u+Ce.du:Ce.u,an=zt?Fe.u:Fe.u+Fe.du;if(Bt=zt?1:-1,dt=zt?1:-1,!fe.long)Nt=z([[Et,Xe],[fe.slot1,Xe],[fe.slot1,pt],[an,pt]]),_t=[fe.slot1,Math.abs(Xe-pt)<zr*2?Math.max(Xe,pt)+12:(Xe+pt)/2];else{const _n=Ma+fe.channel*Sa+4;Nt=z([[Et,Xe],[fe.slot1,Xe],[fe.slot1,_n],[fe.slot2,_n],[fe.slot2,pt],[an,pt]]),_t=[(fe.slot1+fe.slot2)/2,_n]}}const En=ge.dashed?' stroke-dasharray="5 4"':"";if(Q+=`<g${_(`relations.${ge.idx}`)}><path d="${Nt}" fill="none" stroke="var(--muted)" stroke-width="1.25"${En}/>`+Rw(fe.self||Bt>0?Ce.u+Ce.du:Ce.u,Xe,Bt,Ow(ge.fromMany,!1),r,K,R)+Rw(fe.self||kt===St?Fe.u+Fe.du:dt>0?Fe.u:Fe.u+Fe.du,pt,fe.self||kt===St?1:-dt,Ow(ge.toMany,ge.toOptional),r,K,R)+"</g>",ge.r.label!==void 0&&ge.r.label!==""){const zt=ge.r.label.toUpperCase(),Et=Math.round(zt.length*Wa+8),an=K(_t[0],_t[1]),_n=R(_t[0],_t[1]);Z.push(`<rect x="${nt(an-Et/2)}" y="${nt(_n-7)}" width="${Et}" height="14" fill="var(--paper)"/><text x="${nt(an)}" y="${nt(_n+3.5)}" class="t-arrow er-rel" text-anchor="middle">${S(zt)}</text>`),re(an+Et/2,_n+7)}}Q+="</g>";const le=new Set;let J=!1;const ue=new Set;Q+=`<g${he("entities")}>`;for(const fe of $){const ge=fe.box,Ce=K(fe.u,fe.v),Fe=R(fe.u,fe.v),qe=ge.name===h,ze=qe?"AGGREGATE ROOT":ge.kind==="view"?"VIEW":ge.kind==="enum"?"ENUM":ge.kind==="external"?"EXT":ge.join?"JOIN":"ENTITY";ge.join&&!qe&&ge.kind==="table"&&(J=!0),ge.kind!=="table"&&ue.add(ge.kind);const Xe=ge.kind==="view"||ge.kind==="enum",pt=qe?"var(--accent)":Xe?"var(--rule-solid)":"var(--ink)",kt=qe?"var(--accent-tint)":ge.kind==="view"?"var(--paper-2)":"var(--paper)",St=Xe?1:1.5,Nt=ge.kind==="external"?' stroke-dasharray="4 3"':"";Q+=`<g${_(`entities.${ge.idx}`)}><rect x="${nt(Ce)}" y="${nt(Fe)}" width="${ge.w}" height="${ge.h}" rx="6" fill="${kt}" stroke="${pt}" stroke-width="${St}"${Nt}/><text x="${nt(Ce+Bn)}" y="${nt(Fe+15)}" class="er-eyebrow t-eyebrow${qe?" c-accent":""}">${ze}</text><text x="${nt(Ce+Bn)}" y="${nt(Fe+31)}" class="er-head-text t-name">${S(ge.name)}</text>`,ge.headLines.forEach((dt,_t)=>{Q+=`<text x="${nt(Ce+Bn)}" y="${nt(Fe+44+_t*13)}" class="er-col dim t-sub c-soft">${S(dt)}</text>`}),(ge.rows.length>0||ge.headLines.length>0)&&(Q+=`<line x1="${nt(Ce)}" y1="${nt(Fe+ge.headH)}" x2="${nt(Ce+ge.w)}" y2="${nt(Fe+ge.headH)}" class="er-headline"/>`),Q+=`<g${he(`entities.${ge.idx}.columns`)}>`;let Bt=-1;ge.rows.forEach((dt,_t)=>{const En=Fe+ge.headH+_t*zr,zt=En+14;dt.kind==="col"?(Bt>=0&&(Q+="</g>"),Bt=dt.colIdx,Q+=`<g${_(`entities.${ge.idx}.columns.${dt.colIdx}`)}>`,dt.note!==void 0&&(Q+=`<title>${S(dt.note)}</title>`),_t>0&&(Q+=`<line x1="${nt(Ce+1)}" y1="${nt(En)}" x2="${nt(Ce+ge.w-1)}" y2="${nt(En)}" class="er-rowline"${ut}/>`),dt.markers.forEach((Et,an)=>{le.add(Et),Q+=`<text x="${nt(Ce+Bn+an*Wy)}" y="${nt(zt)}" class="er-key ${w8(Et)} t-sub c-muted">${S(Et)}</text>`}),Q+=`<text x="${nt(Ce+Bn+Tw(ge))}" y="${nt(zt)}" class="er-col t-sub c-ink">${S(dt.left)}</text>`+(dt.right.length>0?`<text x="${nt(Ce+ge.w-Bn)}" y="${nt(zt)}" class="er-col dim t-sub c-soft" text-anchor="end">${S(dt.right)}</text>`:"")):Q+=`<text x="${nt(Ce+Bn+Tw(ge))}" y="${nt(zt)}" class="er-col dim t-sub c-soft">${S(dt.left)}</text>`}),Bt>=0&&(Q+="</g>"),Q+="</g></g>"}Q+="</g>";const ve=o.map((fe,ge)=>b8(fe.name,fe.values,ge));if(ve.length>0){const fe=Y+Hu;let ge=Ma+U;Q+=`<g${he("enums")}>`;for(const Ce of ve)Q+=`<g${_(`enums.${Ce.idx}`)}><rect x="${nt(fe)}" y="${nt(ge)}" width="${Ce.w}" height="${Ce.h}" rx="6" fill="var(--paper)" stroke="var(--rule-solid)" stroke-width="1"/><text x="${nt(fe+Bn)}" y="${nt(ge+15)}" class="er-eyebrow t-eyebrow">ENUM</text><text x="${nt(fe+Bn)}" y="${nt(ge+31)}" class="er-head-text t-name">${S(Ce.name)}</text><line x1="${nt(fe)}" y1="${nt(ge+Bc)}" x2="${nt(fe+Ce.w)}" y2="${nt(ge+Bc)}" class="er-headline"/>`,Ce.values.forEach((Fe,qe)=>{const ze=ge+Bc+qe*zr;qe>0&&(Q+=`<line x1="${nt(fe+1)}" y1="${nt(ze)}" x2="${nt(fe+Ce.w-1)}" y2="${nt(ze)}" class="er-rowline"${ut}/>`),Q+=`<text x="${nt(fe+Bn)}" y="${nt(ze+14)}" class="er-col t-sub c-ink">${S(Fe)}</text>`}),Q+="</g>",re(fe+Ce.w,ge+Ce.h),ge+=Ce.h+lc;Q+="</g>"}Q+=Z.join("");const we=Math.ceil(Y+Ma),$e=Math.ceil(V+Ma),je=Sn("Entity relationship diagram",e.title,[wt(t.length,"entity","entities")]),De=`<svg viewBox="0 0 ${we} ${$e}"${je.attrs}>`+je.title+Q+"</svg>",Me=[];le.has("#")&&Me.push({swatch:"chip",chip:"#",label:"primary key"}),le.has("→")&&Me.push({swatch:"chip",chip:"→",label:"foreign key"}),le.has("U")&&Me.push({swatch:"chip",chip:"U",label:"unique"}),le.has("?")&&Me.push({swatch:"chip",chip:"?",label:"nullable"}),le.has("⌘")&&Me.push({swatch:"chip",chip:"⌘",label:"indexed"}),q&&Me.push({swatch:"chip",chip:"1 / N",label:"cardinality"}),de&&(Me.push({swatch:"line",label:"identifying"}),Me.push({swatch:"line-dashed",label:"non-identifying"})),J&&Me.push({swatch:"chip",chip:"JOIN",label:"join table"}),ue.has("view")&&Me.push({swatch:"node-fill2",label:"view"}),(ue.has("enum")||ve.length>0)&&Me.push({swatch:"chip",chip:"ENUM",label:"enum"}),ue.has("external")&&Me.push({swatch:"node-dashed",label:"external"}),ne&&Me.push({swatch:"node-fill2",label:"schema group"}),h!==void 0&&Me.push({swatch:"node-accent",label:"aggregate root"});const Be=ot(Me),Ge={tag:"ER",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...Be.length>0?{legendHtml:Be}:{}};return ct(Ge,De)}function k8(e,t){const n=e.columns??[],s=e.kind??"table",o=Math.max(0,...n.map(m=>v0(m).length)),r=o>0?o*Wy+6:0;let i=Math.max(y8,e.name.length*y4+Bn*2+24);const l=n.map(m=>$8(m));n.forEach((m,g)=>{i=Math.max(i,Bn*2+r+m.name.length*Wa+16+(l[g]?.length??0)*Wa)});const d=i-Bn*2-r,u=[];n.forEach((m,g)=>{if(u.push({kind:"col",col:m,colIdx:g,markers:v0(m),left:m.name,right:l[g]??"",...m.note!==void 0&&m.note.length>0?{note:m.note}:{}}),m.enum!==void 0&&m.enum.length>0)for(const v of _w(m.enum.join(" · "),Math.max(24,Math.floor(d/Wa))))u.push({kind:"sub",colIdx:g,markers:[],left:v,right:""})});const p=e.note!==void 0&&e.note.length>0?_w(e.note,Math.max(24,Math.floor((i-Bn*2)/Wa))):[],h=Bc+(p.length>0?p.length*13+2:0);return{name:e.name,idx:t,entity:e,cols:n,rows:u,headLines:p,headH:h,pkIdx:n.findIndex(m=>m.pk===!0),join:n.length>0&&n.every(m=>m.fk===!0),kind:s,w:Math.round(i),h:h+u.length*zr+(u.length>0?v4:0)}}function b8(e,t,n){const s=Math.round(Math.max(120,e.length*y4+Bn*2+12,...t.map(o=>o.length*Wa+Bn*2)));return{idx:n,name:e,values:t,w:s,h:Bc+t.length*zr+(t.length>0?v4:0)}}function v0(e){const t=[];return e.pk===!0&&t.push("#"),e.fk===!0&&t.push("→"),e.unique===!0&&t.push("U"),e.nullable===!0&&t.push("?"),e.index===!0&&t.push("⌘"),t}function w8(e){return e==="#"?"pk":e==="→"?"fk":e==="U"?"uk":e==="?"?"nul":"ix"}function Tw(e){const t=Math.max(0,...e.cols.map(n=>v0(n).length));return t>0?t*Wy+6:0}function $8(e){const t=[];return e.type!==void 0&&e.type.length>0&&t.push(e.type),e.ref!==void 0&&e.ref.length>0&&t.push(`→ ${e.ref}`),e.default!==void 0&&e.default.length>0&&t.push(`= ${e.default}`),t.join(" ")}function _w(e,t){const n=[];let s="";for(const o of e.split(/\s+/).filter(r=>r.length>0))for(s.length===0?s=o:s.length+1+o.length<=t?s+=" "+o:(n.push(s),s=o);s.length>t;)n.push(s.slice(0,t)),s=s.slice(t);return s.length>0&&n.push(s),n}function S8(e,t,n,s,o){const r=new Set,i=[];for(const u of e){if(r.has(u.box.name)||(t.get(u.box.name)?.size??0)===0)continue;const p=[],h=[u];for(r.add(u.box.name);h.length>0;){const m=h.shift();p.push(m);for(const g of t.get(m.box.name)??[]){if(r.has(g))continue;r.add(g);const v=o.get(g);v!==void 0&&h.push(v)}}i.push(p)}i.sort((u,p)=>{const h=s!==void 0&&u.some(g=>g.box.name===s)?1:0;return(s!==void 0&&p.some(g=>g.box.name===s)?1:0)-h||p.length-u.length}),i.forEach((u,p)=>{const h=u.find(E=>E.box.name===s)??u.reduce((E,$)=>(n.get($.box.name)??0)>(n.get(E.box.name)??0)?$:E,u[0]),m=new Map([[h.box.name,0]]),g=[h];for(;g.length>0;){const E=g.shift(),$=m.get(E.box.name)??0;for(const A of t.get(E.box.name)??[]){if(m.has(A))continue;m.set(A,$+1);const T=o.get(A);T!==void 0&&g.push(T)}}const v=new Map,y=[];for(const E of u){if(E===h||v.has(E.box.name))continue;const $=[],A=[E.box.name];for(v.set(E.box.name,y.length);A.length>0;){const T=A.shift();$.push(T);for(const N of t.get(T)??[])N===h.box.name||v.has(N)||(v.set(N,y.length),A.push(N))}y.push($)}const b=y.map(()=>1);if(p===0&&y.length>1){const E=y.map((T,N)=>({i:N,size:T.length})).sort((T,N)=>N.size-T.size||T.i-N.i);let $=0,A=0;for(const{i:T,size:N}of E)A<=$?(b[T]=1,A+=N):(b[T]=-1,$+=N)}for(const E of u){const $=m.get(E.box.name)??0,A=v.get(E.box.name);E.layer=A===void 0?0:(b[A]??1)*$}});const l=e.filter(u=>!r.has(u.box.name));if(l.length===0)return;const d=[...new Set(e.filter(u=>r.has(u.box.name)).map(u=>u.layer))].sort((u,p)=>u-p);if(d.length===0){l.forEach((u,p)=>{u.layer=p%4});return}l.forEach((u,p)=>{u.layer=d[p%d.length]??0})}function Lw(e,t,n){return y0(e,t,n)>=0}function y0(e,t,n){if(n!==void 0){const d=e.cols.findIndex(u=>u.name===n);if(d>=0)return zc(e,d)}const s=t.name.toLowerCase(),o=s.replace(/s$/,""),r=e.cols.map((d,u)=>({c:d,i:u})).filter(d=>d.c.fk===!0),i=r.find(d=>{const u=d.c.ref?.toLowerCase()??"";return u.startsWith(s+".")||u===s||u.startsWith(t.name.toLowerCase())});if(i!==void 0)return zc(e,i.i);const l=r.find(d=>{const u=d.c.name.toLowerCase();return u.includes(s)||u.includes(o)});return l!==void 0?zc(e,l.i):-1}function Iw(e,t){if(t!==void 0){const n=e.cols.findIndex(s=>s.name===t);if(n>=0)return zc(e,n)}return e.pkIdx>=0?zc(e,e.pkIdx):-1}function zc(e,t){return e.rows.findIndex(n=>n.kind==="col"&&n.colIdx===t)}function jw(e,t,n){return!t||n<0?e.v+e.dv/2:e.v+e.box.headH+n*zr+zr/2}function Pw(e,t){return(e.v+e.dv/2+t.v+t.dv/2)/2}function E8(e){if(e===void 0)return{fromMany:!0,toMany:!1,toOptional:!1};if(e==="0..1")return{fromMany:!1,toMany:!1,toOptional:!0};if(e==="0..N")return{fromMany:!1,toMany:!0,toOptional:!0};const t=e.split(":"),n=s=>s!==void 0&&s.trim().toUpperCase()!=="1";return{fromMany:n(t[0]),toMany:n(t[1]),toOptional:!1}}function Ow(e,t){return t?e?"0..N":"0..1":e?"N":"1"}function Rw(e,t,n,s,o,r,i){const l=e+n*10,d=r(l,t),u=i(l,t);if(o){const p=n>0?"start":"end";return`<text x="${nt(d)}" y="${nt(u-4)}" class="t-arrow er-card" text-anchor="${p}">${S(s)}</text>`}return`<text x="${nt(d+4)}" y="${nt(u+3)}" class="t-arrow er-card" text-anchor="start">${S(s)}</text>`}var nt=e=>Math.round(e*10)/10;function M8(e){const t=e.columns??[];let n=`<div class="kanban"${he("columns")}>`;return t.forEach((s,o)=>{const r=(s.cards??[]).map((i,l)=>{const d=i.tag!==void 0?`<div class="kan-card-tag">${S(i.tag)}</div>`:"";return`<div class="kan-card"${_(`columns.${o}.cards.${l}`)}><div class="kan-card-title">${S(i.title)}</div>`+d+"</div>"}).join("");n+=`<div class="kan-col"${_(`columns.${o}`)}${he(`columns.${o}.cards`)}><div class="kan-head"${_(`columns.${o}.label`)}>${S(s.label)}</div>`+r+"</div>"}),n+"</div>"}function lt(e,t,n){if(e==null||e==="")return[];const s=String(e).split(/\s+/),o=[];let r="";for(const i of s){if(!r){r=i;continue}if((r+" "+i).length<=t)r+=" "+i;else if(o.push(r),r=i,o.length===n)break}return r&&o.length<n&&o.push(r),o.slice(0,n)}function hn(e){return` data-reveal="${e}"`}var x4={sync:{cls:"msg-line",marker:"sqArrow",txt:"msg-text t-arrow em"},response:{cls:"msg-line dashed",marker:"sqOpen",txt:"msg-text t-arrow"},async:{cls:"msg-line async",marker:"sqOpen",txt:"msg-text t-arrow"},error:{cls:"msg-line err",marker:"sqErr",txt:"msg-text t-arrow err"},note:{cls:"",marker:null,txt:"msg-text t-arrow note"}},qp=36,A8=28,C8=24,N8=14,k4=13,T8=34,_8=3,Dw=18,Bw=12,zw=6,Fc=6,b4=150,L8=46,I8=6.2,j8=40;function P8(e,t){const n=o=>e.findIndex(r=>r.id===o),s=e.slice(0,-1).map(()=>L8);for(const o of t){if(!("from"in o)||o.kind==="note")continue;const r=n(o.from),i=n(o.to);if(r<0||i<0||Math.abs(r-i)!==1)continue;const l=Math.min(r,i),d=Math.ceil((o.label??"").length*I8+j8)-b4;d>(s[l]??0)&&(s[l]=d)}return s}function w4(e){return e.kind==="msg"}function O8(e){const t=new Map;let n=0;for(const s of e)s.kind!=="end"&&(t.set(s.idx,n),n+=1);return t}function R8(e,t,n,s){const o=u=>{const p=s.get(u);return p===void 0?"":hn(p)},r=e.filter(w4);if(!r.some(u=>u.summary!==void 0&&u.summary.length>0))return"";const i=new Set,l=u=>{const p=u.open.idx,h=u.end?.idx??Number.POSITIVE_INFINITY;if(r.some(g=>g.idx>p&&g.idx<h&&g.summary!==void 0&&g.summary.length>0)){i.add(u.open.idx);for(const g of u.elses)i.add(g.idx)}u.children.forEach(l)};t.forEach(l);const d=[];for(const u of e){if(u.kind==="open"&&i.has(u.idx)){const E=u.label.length>0?`<span class="step-frame-label">${S(u.label)}</span>`:"";d.push(`<li class="step-frame"${_(`messages.${u.idx}`)}${o(u.idx)}><span class="step-frame-tag">${S(u.frame.toUpperCase())}</span>${E}</li>`);continue}if(u.kind==="else"&&i.has(u.idx)){d.push(`<li class="step-frame else"${_(`messages.${u.idx}`)}${o(u.idx)}><span class="step-frame-tag">else</span><span class="step-frame-label">${S(u.label)}</span></li>`);continue}if(u.kind!=="msg"||u.summary===void 0||u.summary.length===0)continue;const p=u.msgKind==="error"?' class="err"':"",h=u.msgKind==="error"?" err":"",m=n.get(u.from)?.name??u.from,g=u.msgKind==="note"||u.from===u.to?"":` &rarr; ${S(n.get(u.to)?.name??u.to)}`,v=`${S(m)}${g}`,y=u.code!==void 0&&u.code.length>0?`<pre class="sql">${S(u.code)}</pre>`:"",b=u.note!==void 0&&u.note.length>0?`<span class="step-note">${S(u.note)}</span>`:"";d.push(`<li${p}${_(`messages.${u.idx}`)}${o(u.idx)}><span class="step-n">${u.n}</span><span class="step-actor${h}">${v}</span><span class="step-summary">${S(u.summary)}</span>`+y+b+"</li>")}return`<div class="seq-steps"><div class="seq-steps-title">Step-by-step</div><ol>${d.join("")}</ol></div>`}function D8(e){if(e.length===0)return"";const t=e.map((n,s)=>`<span${_(`foot.${s}`)}><strong>${S(n.label)}:</strong> ${S(n.value)}</span>`).join("");return`<div class="diagram-foot"${he("foot")}>${t}</div>`}function B8(e,t,n){const s=[];let o=n-qp,r=0;return e.forEach((i,l)=>{const d=i;if("frame"in d){const y=typeof d.label=="string"?d.label:"";s.push({kind:"open",idx:l,top:o,y:o+14,frame:String(d.frame),label:y}),o+=A8;return}if("else"in d){s.push({kind:"else",idx:l,top:o,y:o+8,frame:"",label:String(d.else??"")}),o+=C8;return}if("end"in d){s.push({kind:"end",idx:l,top:o,y:o+10,frame:"",label:""}),o+=N8;return}const u=i;r+=1;const p=u.kind!==void 0&&u.kind in x4?u.kind:"sync",h=u.label??"",m=p==="note"?lt(h,T8,_8):[],g=p==="note"?qp+k4*Math.max(0,m.length-1):qp,v={kind:"msg",idx:l,n:r,top:o,y:o+g,fromI:t(u.from),toI:t(u.to),msgKind:p,label:h,from:u.from,to:u.to,activate:u.activate===!0,deactivate:u.deactivate===!0,lines:m,...u.summary!==void 0?{summary:u.summary}:{},...u.code!==void 0?{code:u.code}:{},...u.note!==void 0?{note:u.note}:{}};s.push(v),o+=g}),{rows:s,cursor:o}}function z8(e){const t=[],n=[];for(const s of e)if(s.kind==="open"){const o={open:s,elses:[],children:[],x1:0,x2:0},r=n[n.length-1];r!==void 0?r.children.push(o):t.push(o),n.push(o)}else if(s.kind==="else")n[n.length-1]?.elses.push(s);else if(s.kind==="end"){const o=n.pop();o!==void 0&&(o.end=s)}return t}function F8(e,t,n){if(e.msgKind==="note"){const s=n(e);return s===null?null:[s.x,s.x+s.w]}if(e.fromI<0&&e.toI<0)return null;if(e.fromI<0)return[t(e.toI),t(e.toI)];if(e.toI<0)return[t(e.fromI),t(e.fromI)+36+e.label.length*Fc];if(e.fromI===e.toI){const s=t(e.fromI);return[s,s+36+e.label.length*Fc]}return[Math.min(t(e.fromI),t(e.toI)),Math.max(t(e.fromI),t(e.toI))]}function q8(e){const t=e.actors??[],n=e.messages??[],s=Math.max(t.length,1),o=24,r=b4,i=P8(t,n),l=16,d=t.map(J=>lt(J.name,J.external===!0?16:19,2)),u=d.some(J=>J.length>1),p=u?54:40,h=[];for(let J=0;J<s;J++)h.push(o+r/2+J*r+i.slice(0,J).reduce((ue,ve)=>ue+ve,0));const m=J=>h[J]??o+r/2,g=o*2+s*r+i.reduce((J,ue)=>J+ue,0),v=J=>t.findIndex(ue=>ue.id===J),y=l+p+28,{rows:b,cursor:E}=B8(n,v,y),$=b.filter(w4),A=O8(b),T=J=>hn(A.get(J)??0),N=E+qp+12,j=N+6;let P=-1;for(const J of $)J.msgKind==="response"&&J.toI===0&&J.fromI>0&&(P=J.idx);const I=J=>{if(J.fromI<0&&J.toI<0)return null;const ue=Math.max(0,...J.lines.map(Be=>Be.length)),ve=J.top+14,we=J.y-J.top-18;if(J.fromI<0||J.toI<0||J.fromI===J.toI){const Be=m(J.fromI<0?J.toI:J.fromI),Ge=Math.max(72,Math.round(ue*Fc)+16);return{x:Be+12+Ge<=g-2?Be+12:Be-12-Ge,w:Ge,top:ve,h:we}}const $e=Math.min(m(J.fromI),m(J.toI)),je=Math.max(m(J.fromI),m(J.toI)),De=Math.max(je-$e+60,Math.round(ue*Fc)+16),Me=($e+je)/2;return{x:Math.round(Me-De/2),w:De,top:ve,h:we}},O=z8(b),C=J=>{J.children.forEach(C);const ue=J.open.idx,ve=J.end?.idx??Number.POSITIVE_INFINITY;let we=Number.POSITIVE_INFINITY,$e=Number.NEGATIVE_INFINITY;for(const je of $){if(je.idx<=ue||je.idx>=ve)continue;const De=F8(je,m,I);De!==null&&(we=Math.min(we,De[0]),$e=Math.max($e,De[1]))}we===Number.POSITIVE_INFINITY?(we=o,$e=g-o):(we-=Dw,$e+=Dw);for(const je of J.children)we=Math.min(we,je.x1-Bw),$e=Math.max($e,je.x2+Bw);J.x1=Math.max(2,Math.round(we)),J.x2=Math.min(g-2,Math.round($e))};O.forEach(C);const D=J=>J.end?.y??E+6,F=$.some(J=>J.activate||J.deactivate),U=[],X=new Map,B=J=>{let ue=X.get(J);return ue===void 0&&(ue=[],X.set(J,ue)),ue},te=(J,ue,ve,we)=>{const $e=B(J),je={i:J,y1:ue,y2:Number.NaN,depth:$e.length,caller:ve,last:ue,step:we};$e.push(je),U.push(je)};for(const J of $){if(F){if(J.activate&&J.toI>=0&&te(J.toI,J.y,J.fromI,A.get(J.idx)??0),J.deactivate&&J.fromI>=0){const ue=B(J.fromI).pop();ue!==void 0&&(ue.y2=J.y)}continue}if(!(J.msgKind==="note"||J.fromI<0)){for(const ue of B(J.fromI))ue.last=J.y;if(!(J.toI<0||J.toI===J.fromI))if(J.msgKind==="sync"||J.msgKind==="async")te(J.toI,J.y,J.fromI,A.get(J.idx)??0);else{const ue=B(J.fromI);for(let ve=ue.length-1;ve>=0;ve--){const we=ue[ve];if(we.caller===J.toI){we.y2=J.y,ue.splice(ve,1);break}}}}}for(const J of X.values())for(const ue of J)ue.y2=F?E:ue.last;const ee=Sn("Sequence diagram",e.title??e.endpoint?.path,[`${wt($.length,"message")} between ${wt(t.length,"actor")}`]);let H=`<svg viewBox="0 0 ${g} ${j}"${ee.attrs}>`+ee.title+'<defs><marker id="sqArrow" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="var(--muted)"/></marker><marker id="sqOpen" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path d="M1,1 L9,5 L1,9" fill="none" stroke="var(--muted)" stroke-width="1.6"/></marker><marker id="sqErr" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="var(--negative)"/></marker><marker id="sqAccent" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path d="M1,1 L9,5 L1,9" fill="none" stroke="var(--accent)" stroke-width="1.6"/></marker></defs>',W="",K="";const R=t.map((J,ue)=>m(ue)),z=(J,ue)=>{const ve=(ue.length+2)*Fc,we=R.find($e=>$e>=J-6&&$e<=J+ve);return we===void 0?J:we+12},Y=J=>{const ue=J.open.y,ve=D(J),we=_(`messages.${J.open.idx}`)+T(J.open.idx);W+=`<g${we}><rect x="${J.x1}" y="${ue}" width="${J.x2-J.x1}" height="${Math.max(0,ve-ue)}" rx="4" class="seq-frame"/></g>`;const $e=J.open.frame.toUpperCase(),je=10+$e.length*7,De=J.open.label.length>0?`<text x="${z(J.x1+je+8,J.open.label)}" y="${ue+12}" class="seq-frame-guard t-arrow c-soft">[${S(J.open.label)}]</text>`:"";K+=`<g${we}><rect x="${J.x1}" y="${ue}" width="${je}" height="16" rx="2" class="seq-frame-tab"/><text x="${J.x1+5}" y="${ue+11.5}" class="seq-frame-tab-text t-eyebrow">${S($e)}</text>`+De+"</g>";for(const Me of J.elses){const Be=_(`messages.${Me.idx}`)+T(Me.idx);W+=`<g${Be}><line x1="${J.x1}" y1="${Me.y}" x2="${J.x2}" y2="${Me.y}" class="seq-frame-else"/></g>`,K+=`<g${Be}><text x="${z(J.x1+8,Me.label)}" y="${Me.y+14}" class="seq-frame-guard t-arrow c-soft">[${S(Me.label)}]</text></g>`}J.children.forEach(Y)};O.forEach(Y),H+=W;for(let J=0;J<t.length;J++){const ue=m(J);H+=`<line x1="${ue}" y1="${l+p}" x2="${ue}" y2="${N}" class="lifeline"/>`}for(const J of U){const ue=J.y1-zw,ve=J.y2+zw;H+=`<rect x="${m(J.i)-3+J.depth*4}" y="${ue}" width="6" height="${Math.max(0,ve-ue)}" class="activation"${hn(J.step)}/>`}H+=`<g${he("actors")}>`,t.forEach((J,ue)=>{const ve=J.external===!0,we=ve?" ext":"",$e=d[ue]??[],je=J.sub!==void 0,De=$e.length>1?l+(ve?21:17):je?l+(ve?22:17):l+(ve?25:24),Me=l+(u?47:33),Be=$e.length<=1?`<text x="${m(ue)}" y="${De}" class="lane-head-text t-name">${S(J.name)}</text>`:$e.map((ge,Ce)=>`<text x="${m(ue)}" y="${De+Ce*14}" class="lane-head-text t-name">${S(ge)}</text>`).join(""),Ge=je?`<text x="${m(ue)}" y="${Me}" class="lane-head-sub t-sub">${S(J.sub??"")}</text>`:"",fe=ve?`<text x="${m(ue)-r/2+8}" y="${l+11}" class="lane-head-chip t-eyebrow">EXT</text>`:"";H+=`<g${_(`actors.${ue}`)}><rect x="${m(ue)-r/2}" y="${l}" width="${r}" height="${p}" rx="4" class="lane-head${we}"/>`+fe+Be+Ge+"</g>"}),H+="</g>",H+=K,H+=`<g${he("messages")}>`;const V={sync:!1,response:!1,async:!1,error:!1,note:!1};for(const J of $){const ue=x4[J.msgKind],we=J.idx===P?{cls:`${ue.cls} accent`,marker:"sqAccent",txt:`${ue.txt} accent`}:ue;V[J.msgKind]=!0;const $e=_(`messages.${J.idx}`)+T(J.idx),je=J.msgKind==="error"?" err":"",De=(ze,Xe)=>`<circle cx="${ze}" cy="${Xe}" r="8" class="step-badge${je}"/><text x="${ze}" y="${Xe+3}" class="step-badge-text t-badge${je===""?"":" c-negative"}">${J.n}</text>`;if(J.msgKind==="note"){const ze=I(J);if(ze===null)continue;const Xe=J.summary!==void 0&&J.summary.length>0,pt=ze.x+ze.w/2,kt=J.lines.map((St,Nt)=>`<text x="${pt}" y="${ze.top+16+Nt*k4}" class="seq-note-text t-sub" text-anchor="middle">${S(St)}</text>`).join("");H+=`<g${$e}><rect x="${ze.x}" y="${ze.top}" width="${ze.w}" height="${ze.h}" rx="3" class="seq-note"/><path d="M${ze.x+ze.w-7},${ze.top} v7 h7" class="seq-note-fold"/>`+kt+(Xe?De(ze.x+2,ze.top):"")+"</g>";continue}if(J.fromI<0||J.toI<0){if(J.fromI<0&&J.toI<0)continue;const ze=m(J.fromI<0?J.toI:J.fromI);H+=`<g${$e}>`+De(ze+18,J.y-10)+`<text x="${ze+34}" y="${J.y-6}" class="msg-text note">${S(J.label)}</text></g>`;continue}if(J.fromI===J.toI){const ze=m(J.fromI),Xe=we.marker!==null?` marker-end="url(#${we.marker})"`:"";H+=`<g${$e}><path d="M${ze},${J.y-14} H${ze+28} V${J.y} H${ze+3}" class="${we.cls} self"${Xe}/>`+De(ze+16,J.y-26)+`<text x="${ze+36}" y="${J.y-4}" class="${we.txt}" text-anchor="start">${S(J.label)}</text></g>`;continue}const Me=m(J.fromI),Be=m(J.toI),Ge=Be>Me,fe=Be+(Ge?-3:3),ge=Ge?Me+18:Me-18,Ce=Ge?ge+16:ge-16,Fe=Ge?"start":"end",qe=we.marker!==null?` marker-end="url(#${we.marker})"`:"";H+=`<g${$e}><line x1="${Me}" y1="${J.y}" x2="${fe}" y2="${J.y}" class="${we.cls}"${qe}/>`+De(ge,J.y-10)+`<text x="${Ce}" y="${J.y-6}" class="${we.txt}" text-anchor="${Fe}">${S(J.label)}</text></g>`}H+="</g>",H+="</svg>";const re=new Map;for(const J of t)re.set(J.id,{name:J.name});const Q=R8(b,O,re,A),ne=e.foot!==void 0?D8(e.foot):"",Z=[];V.sync&&Z.push({swatch:"edge",label:"call"}),V.response&&Z.push({swatch:"edge-dashed",label:"response"}),V.async&&Z.push({swatch:"edge-async",label:"async"}),V.error&&Z.push({swatch:"edge-error",label:"error"}),P>=0&&Z.push({swatch:"edge-accent-dashed",label:"the answer the caller gets"}),t.some(J=>J.external===!0)&&Z.push({swatch:"chip",chip:"EXT",label:"external actor"}),O.length>0&&Z.push({swatch:"node-fill2",label:"fragment (alt / opt / loop)"}),U.length>0&&Z.push({swatch:"node",label:"active"});const q=ot(Z),de=e.endpoint?.method,le={tag:"SEQUENCE",...de!==void 0?{tagClass:de.toLowerCase(),method:de}:{},...e.endpoint?.path!==void 0?{path:e.endpoint.path}:{},...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...q.length>0?{legendHtml:q}:{},...ne.length>0?{footerHtml:ne}:{}};return ct(le,H+Q)}function Fw(e){if(typeof e=="string")return"";const t=[];return e.align==="r"&&t.push("r"),e.align==="c"&&t.push("c"),e.highlight===!0&&t.push("hi"),t.join(" ")}function H8(e){return typeof e=="string"?e:e.label}function W8(e){if(typeof e=="string"||typeof e=="number")return"";const t=[];return e.tone&&t.push(`cell-${e.tone}`),e.lead===!0&&t.push("lead"),e.highlight===!0&&t.push("hi"),t.join(" ")}function U8(e){return S(typeof e=="string"||typeof e=="number"?e:e.v)}function K8(e){const t=e.columns??[],n=e.rows??[],s=t.map((i,l)=>{const d=Fw(i);return`<th${d?` class="${d}"`:""}${_(`columns.${l}`)}>${S(H8(i))}</th>`}).join(""),o=n.map((i,l)=>{const d=(i??[]).map((u,p)=>{const h=t[p],m=[h!==void 0?Fw(h):"",W8(u)].filter(Boolean).join(" ");return`<td${m?` class="${m}"`:""}${_(`rows.${l}.${p}`)}>${U8(u)}</td>`}).join("");return`<tr${_(`rows.${l}`)}>${d}</tr>`}).join(""),r=e.note!==void 0?`<p class="tbl-note"${_("note")}>${S(e.note)}</p>`:"";return`<table class="pres-table"><thead><tr>${s}</tr></thead><tbody${he("rows")}>${o}</tbody></table>${r}`}var V8={done:"node-fill2",current:"node-accent",next:"node-dashed",future:"node-dashed"};function G8(e){const t=e.items??[],n=[];let s=`<div class="tl"${he("items")}>`;t.forEach((r,i)=>{const l=r.status??"future";n.includes(l)||n.push(l);const d=r.date!==void 0?`<div class="tl-date"${_(`items.${i}.date`)}>${S(r.date)}</div>`:"",u=r.desc!==void 0?`<div class="tl-desc"${_(`items.${i}.desc`)}>${S(r.desc)}</div>`:"",p=`<span class="tl-status tl-s-${l}"${r.status!==void 0?_(`items.${i}.status`):""}>${S(l)}</span>`;s+=`<div class="tl-item"${_(`items.${i}`)}${hn(i)}><span class="tl-dot ${l}"></span><div class="tl-head">${d}${p}</div><div class="tl-label"${_(`items.${i}.label`)}>${S(r.label)}</div>`+u+"</div>"});const o=n.map(r=>({swatch:V8[r]??"node-dashed",label:r}));return s+"</div>"+ot(o)}function $4(e){return e.slice(e.indexOf("#")+1)}function Y8(e){const t=e.role??"user",n=e.want??"…",s=e.soThat??"…",o=[];e.title!==void 0&&o.push(`<span class="story-title"${_("title")}>${S(e.title)}</span>`),(e.tags??[]).forEach((d,u)=>o.push(`<span class="story-chip"${_(`tags.${u}`)}>${S(d)}</span>`)),e.points!==void 0&&e.points!==null&&o.push(`<span class="story-chip pts"${_("points")}>${S(e.points)} pts</span>`),e.priority!==void 0&&o.push(`<span class="story-chip"${_("priority")}>Priority · ${S(e.priority)}</span>`);let r='<div class="story">';o.length>0&&(r+=`<div class="story-head">${o.join("")}</div>`),r+=`<div class="story-stmt">As a <b${_("role")}>${S(t)}</b>, I want to <b${_("want")}>${S(n)}</b>, so that <b${_("soThat")}>${S(s)}</b>.</div>`,r+="</div>";const i=e.criteria??[];i.length>0&&(r+='<div class="ac-title">Acceptance criteria</div>',i.forEach((d,u)=>{r+=`<div class="ac-item"${_(`criteria.${u}`)}><div class="gwt"><span class="k g">Given</span><span class="v"${_(`criteria.${u}.given`)}>${S(d.given??"")}</span><span class="k w">When</span><span class="v"${_(`criteria.${u}.when`)}>${S(d.when??"")}</span><span class="k t">Then</span><span class="v"${_(`criteria.${u}.then`)}>${S(d.then??"")}</span></div></div>`}));const l=e.links??[];return l.length>0&&(r+=`<div class="ac-title">Related</div><div class="links-row"${he("links")}>`,l.forEach((d,u)=>{const p=`<span class="lt">${S(d.mode??"")}</span>${S(d.label??"")}`;r+=d.ref!==void 0&&d.ref!==""?`<a class="link-chip" data-ref="${S(d.ref)}" href="#${S($4(d.ref))}"${_(`links.${u}`)}>${p}</a>`:`<span class="link-chip"${_(`links.${u}`)}>${p}</span>`}),r+="</div>"),r}function X8(e){const n=(e.blocks??[]).map((s,o)=>{const r=(s.type??"p").toLowerCase(),i=s.text??"";if(r==="h")return`<h3${_(`blocks.${o}`)}>${vo(i)}</h3>`;if(r==="quote")return`<blockquote${_(`blocks.${o}`)}>${vo(i)}</blockquote>`;if(r==="ul"){const l=(s.items??[]).map((d,u)=>`<li${_(`blocks.${o}.items.${u}`)}>${vo(d)}</li>`).join("");return`<ul${_(`blocks.${o}`)}${he(`blocks.${o}.items`)}>${l}</ul>`}if(r==="ol"){const l=(s.items??[]).map((d,u)=>`<li${_(`blocks.${o}.items.${u}`)}>${vo(d)}</li>`).join("");return`<ol${_(`blocks.${o}`)}${he(`blocks.${o}.items`)}>${l}</ol>`}return`<p${_(`blocks.${o}`)}>${vo(i)}</p>`}).join("");return`<div class="prose"${he("blocks")}>${n}</div>`}function Q8(e,t){if(e===void 0||e.length===0)return"";const n=e.map((s,o)=>`<span${_(`terms.${t}.avoid.${o}`)}>${S(s)}</span>`).join(", ");return` <span class="avoid"${he(`terms.${t}.avoid`)}>not: ${n}</span>`}function Z8(e){const n=(e.terms??[]).map((s,o)=>`<div class="row"${_(`terms.${o}`)}><dt${_(`terms.${o}.term`)}>${S(s.term)}</dt><dd${_(`terms.${o}.def`)}>${S(s.def)}${Q8(s.avoid,o)}</dd></div>`).join("");return`<div class="glossary"${he("terms")}>${n}</div>`}function J8(e){const t=e.prosLabel??"Pros",n=e.consLabel??"Cons",s=(e.pros??[]).map((r,i)=>`<div class="pc-item"${_(`pros.${i}`)}>${S(r)}</div>`).join(""),o=(e.cons??[]).map((r,i)=>`<div class="pc-item"${_(`cons.${i}`)}>${S(r)}</div>`).join("");return`<div class="pc"><div class="pc-col pro"${he("pros")}><div class="pc-head"${_("prosLabel")}>${S(t)}</div>`+s+`</div><div class="pc-col con"${he("cons")}><div class="pc-head"${_("consLabel")}>${S(n)}</div>`+o+"</div></div>"}function ez(e){const t=e.current??{},n=e.target??{},s=(t.items??[]).map((d,u)=>`<div class="ct-item"${_(`current.items.${u}`)}>${S(d)}</div>`).join(""),o=(n.items??[]).map((d,u)=>`<div class="ct-item"${_(`target.items.${u}`)}>${S(d)}</div>`).join(""),r=t.label??"Current",i=n.label??"Target",l=e.note!==void 0?`<div class="tbl-note"${_("note")}>${S(e.note)}</div>`:"";return`<div><div class="ct"><div class="ct-panel cur"${_("current")}${he("current.items")}><div class="ct-label"${_("current.label")}>${S(r)}</div>`+s+`</div><div class="ct-arrow">&rarr;</div><div class="ct-panel tgt"${_("target")}${he("target.items")}><div class="ct-label"${_("target.label")}>${S(i)}</div>`+o+"</div></div>"+l+"</div>"}var tz={up:"▲",down:"▼",flat:"—"};function nz(e){const n=(e.stats??[]).map((s,o)=>{const r=s.accent!==void 0?` style="border-top-color:${Fi(s.accent,"var(--accent)")}"`:"",i=s.delta!==void 0?`<div class="stat-delta ${s.trend??"flat"}">${tz[s.trend??"flat"]} ${S(s.delta)}</div>`:"";return`<div class="stat-card"${r}${_(`stats.${o}`)}><div class="stat-value"${_(`stats.${o}.value`)}>${S(s.value)}</div><div class="stat-label"${_(`stats.${o}.label`)}>${S(s.label)}</div>`+i+"</div>"}).join("");return`<div class="stat-row"${he("stats")}>${n}</div>`}var sz=new Set("const let var function return if else for while do switch case break continue class extends new await async import from export default try catch finally throw typeof instanceof void delete yield static public private protected readonly abstract implements interface type enum namespace def elif lambda pass with raise except none true false and or not is in self nil func struct map range defer chan select fallthrough echo fi done local require module package this super create table alter add drop select insert update delete into values where join group order by limit primary key foreign references not null default unique index on check constraint cascade returning begin commit rollback".split(/\s+/)),oz=new Set("string number boolean int integer float double bool char byte long short void object any unknown never bigint promise array list set optional uuid text varchar timestamptz timestamp date numeric decimal jsonb json serial bigserial smallint".split(/\s+/)),Wu=/(\/\*[\s\S]*?\*\/|\/\/[^\n]*|#[^\n]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)|(\b\d[\w.]*)|([A-Za-z_$][\w$]*)/g,rz=new Set(["md","markdown","mdx"]);function fh(e,t){if(e.length===0)return"";if(t!==void 0&&rz.has(t.trim().toLowerCase()))return iz(String(e));const n=String(e);let s="",o=0;Wu.lastIndex=0;let r;for(;(r=Wu.exec(n))!==null;){r.index>o&&(s+=S(n.slice(o,r.index)));const i=r[0];if(r[1]!==void 0)s+=`<span class="com">${S(i)}</span>`;else if(r[2]!==void 0)s+=`<span class="str">${S(i)}</span>`;else if(r[3]!==void 0)s+=`<span class="num">${S(i)}</span>`;else{const l=i.toLowerCase();sz.has(l)?s+=`<span class="kw">${S(i)}</span>`:oz.has(l)?s+=`<span class="ty">${S(i)}</span>`:n[Wu.lastIndex]==="("?s+=`<span class="fn">${S(i)}</span>`:s+=S(i)}o=Wu.lastIndex}return o<n.length&&(s+=S(n.slice(o))),s}var Og=/(`[^`\n]+`)|(\*\*[^*\n]+\*\*|__[^_\n]+__)|(\*[^*\n]+\*|_[^_\n]+_)|(\[[^\]\n]+\]\([^)\n]+\))/g;function qw(e){let t="",n=0;Og.lastIndex=0;let s;for(;(s=Og.exec(e))!==null;){s.index>n&&(t+=S(e.slice(n,s.index)));const o=s[0];if(s[1]!==void 0)t+=`<span class="str">${S(o)}</span>`;else if(s[2]!==void 0)t+=`<span class="fn">${S(o)}</span>`;else if(s[3]!==void 0)t+=`<span class="ty">${S(o)}</span>`;else{const r=/^(\[[^\]]+\])(\([^)]+\))$/.exec(o);r!==null?t+=`<span class="fn">${S(r[1]??"")}</span><span class="com">${S(r[2]??"")}</span>`:t+=S(o)}n=Og.lastIndex}return n<e.length&&(t+=S(e.slice(n))),t}function iz(e){const t=[];let n=!1;for(const s of e.split(`
2830
+ ${o}`},link(e){const t=yf(e.href),n=e.title!==null&&e.title!==void 0?` title="${e.title}"`:"",s=this.parser.parseInline(e.tokens);return`<a href="${t}"${n}>${s}</a>`},image(e){const t=yf(e.href),n=e.title!==null&&e.title!==void 0?` title="${e.title}"`:"";return`<img src="${t}" alt="${e.text}"${n}>`}}});function g0(e){return`<div class="prose">${qy.parse(e,{async:!1})}</div>`}function vo(e){const t=e.split(/\n{2,}/).map(s=>s.trim()).filter(s=>s!==""),n=s=>qy.parseInline(s,{async:!1});return t.length<=1?n(t[0]??""):t.map(s=>`<p>${n(s)}</p>`).join("")}function g4(e){const t=e?.title??"Untitled",n=e?.tag??"",s=e?.subtitle,o=s!==void 0?`<p class="cover-sub">${S(s)}</p>`:"";return'<div class="cover-pad">'+(e?.logo!==void 0&&e.logo!==""?`<img class="cover-logo" src="${S(yf(e.logo))}" alt="${S(t)}">`:"")+`<div class="cover-meta"><span>DOCUMENT</span><span class="accent">${S(n)}</span></div><h1 class="cover-title">${S(t)}</h1>`+o+"</div>"}function l8(){return""}function _(e){return` data-bp="${S(e)}"`}function he(e){return` data-bl="${S(e)}"`}var c8=1600,d8=/<svg\b[^>]*\bviewBox="-?[\d.]+ -?[\d.]+ ([\d.]+) [\d.]+"[^>]*>/;function u8(e){const t=d8.exec(e);if(t===null||t[1]===void 0)return e;const n=t[0];if(n.includes(" style="))return e;const s=Math.ceil(Number(t[1]));if(!Number.isFinite(s)||s<=0)return e;const o=e.indexOf("</svg>",t.index+n.length);if(o<0)return e;const r=s>c8,i=r?`${n.slice(0,-1)} style="width:calc(${s}px * var(--scale,1));max-width:none">`:`${n.slice(0,-1)} style="max-width:min(100%,calc(${s}px * var(--scale,1)))">`,l=o+6;return e.slice(0,t.index)+`<div class="diagram-stage${r?" diagram-stage--wide":""}">`+i+e.slice(t.index+n.length,l)+"</div>"+e.slice(l)}function ct(e,t){const n=e.tagClass!==void 0?` ${e.tagClass}`:"",s=e.method!==void 0&&e.method.length>0?`<span class="diagram-tag-sep">·</span><span class="diagram-tag-method${n}">${S(e.method)}</span>`:"",o=e.path!==void 0&&e.path.length>0?`<span class="diagram-tag-path">${S(e.path)}</span>`:"",r=`<span class="diagram-eyebrow t-eyebrow"><span class="diagram-tag${n}">${S(e.tag)}</span>`+s+o+"</span>",i=e.titleHtml!==void 0?`<span class="diagram-title">${e.titleHtml}</span>`:e.title!==void 0&&e.title.length>0?`<span class="diagram-title">${S(e.title)}</span>`:"",l=e.fignum!==void 0&&e.fignum.length>0?`<span class="diagram-fignum">${S(e.fignum)}</span>`:"",d=e.desc!==void 0&&e.desc.length>0?`<p class="diagram-desc"${_("description")}>${S(e.desc)}</p>`:"",u=e.legendHtml??"",p=e.footerHtml??"";return'<div class="diagram"><div class="diagram-head">'+r+i+l+"</div>"+d+u8(t)+u+p+"</div>"}var p8={meta:"",callout:"Note",table:"Comparison",sequence:"Sequence",erd:"Entity model",userstory:"User story",timeline:"Roadmap",kanban:"Board",prose:"Overview",glossary:"Glossary",proscons:"Trade-offs",cvt:"Before / after",stats:"Metrics",code:"Code",agenda:"Agenda",tree:"Hierarchy",pyramid:"Pyramid",flow:"Flowchart",state:"State machine",dfd:"Data flow",journey:"Journey",gantt:"Schedule",graph:"Graph",quadrant:"Matrix",swimlane:"Process",c4:"C4 model",uml:"Class model",frontend:"Component tree",cluster:"Cluster",block:"Architecture",felogic:"Frontend logic",wireframe:"Mockup",endpoint:"API endpoint",pullquote:"Quote",layers:"Layers",matrix:"Capability matrix",anatomy:"Anatomy",composition:"Composition",drivers:"Drivers",options:"Options",spec:"Spec",list:"List",stories:"User stories",pattern:"Pattern",gallery:"Gallery",chart:"Chart",figure:"Figure",steps:"Steps",faq:"FAQ",envelope:"Capacity math",slo:"Service objectives",swot:"SWOT",okr:"Objectives",persona:"Personas",changelog:"Changelog",team:"Team",heatmap:"Heatmap",scorecard:"Decision matrix",risk:"Risk register",palette:"Palette",typescale:"Type scale",dodont:"Guidelines",inventory:"Inventory",array:"Array",linkedlist:"Linked list",bintree:"Binary tree",hashmap:"Hash map",agentloop:"Agent loop",trace:"Trace",prompt:"Prompt",context:"Context window",archmap:"Architecture map",divider:"Divider",bignumber:"Big number",takeaways:"Takeaways",statustable:"Status",cycle:"Cycle",benchmark:"Benchmark",sankey:"Flow volumes",gitgraph:"Branch model",treemap:"Composition",packet:"Wire format",venn:"Overlap",wardley:"Strategy map",harvey:"Comparison",scqa:"Summary",scenarios:"Scenarios",fishbone:"Cause & effect",storymap:"Story map",eventcontract:"Event contract",saga:"Saga",slopegraph:"Before / after",spans:"Trace",rollout:"Rollout",perfbudget:"Performance budget",percentiles:"Latency percentiles",timing:"Timing diagram",threatmodel:"Threat model",neuralnet:"Neural net",mindmap:"Mind map",usecase:"Use cases",pkg:"Packages",audit:"Audit findings",checklist:"Checklist",modelcard:"Model card",chevrons:"Process",roadmap:"Roadmap"};function Aw(e){if(e.sourceType!==void 0){const t=io[e.sourceType];if(t!==void 0)return t.sectionLabel}return p8[e.kind]}var Cw={note:"Note",tip:"Tip",warn:"Warning",danger:"Danger",success:"Success"};function f8(e){const t=e.tone??"note",n=e.title??Cw[t]??Cw.note,s=e.body??"";return`<div class="callout ${t}"><div class="callout-title"${_("title")}>${S(n)}</div><div class="callout-body"${_("body")}>${vo(s)}</div></div>`}var yn=30,Cn=14;function h8(e,t,n,s){return s?`<path d="M${e-6},${t-3} L${e},${t} L${e-6},${t+3} z" fill="${n}"/>`:`<path d="M${e-6},${t-3} L${e},${t} L${e-6},${t+3}" fill="none" stroke="${n}" stroke-width="1.2"/>`}function $r(e,t,n,s){const o=Cn/2,r=n.length>0?` stroke-dasharray="${n}"`:"";return`<line x1="1" y1="${o}" x2="${yn-7}" y2="${o}" stroke="${e}" stroke-width="${t}"${r}/>`+h8(yn-1,o,e,s)}function pi(e,t,n,s){const o=s.length>0?` stroke-dasharray="${s}"`:"";return`<rect x="1" y="1" width="${yn-2}" height="${Cn-2}" rx="2" fill="${n}" stroke="${e}" stroke-width="${t}"${o}/>`}function m8(e,t,n,s){let o;switch(e){case"node-dot":{const r=s!==void 0&&s.length>0?` stroke-dasharray="${s}"`:"";o=`<circle cx="${yn/2}" cy="${Cn/2}" r="5.5" fill="${t??"var(--paper)"}" stroke="${n??"var(--ink)"}" stroke-width="1.5"${r}/>`;break}case"line":o=`<line x1="1" y1="${Cn/2}" x2="${yn-1}" y2="${Cn/2}" stroke="${n??"var(--muted)"}" stroke-width="1.25"/>`;break;case"line-dashed":o=`<line x1="1" y1="${Cn/2}" x2="${yn-1}" y2="${Cn/2}" stroke="${n??"var(--muted)"}" stroke-width="1.25" stroke-dasharray="5 4"/>`;break;case"node-accent-outline":o=pi("var(--accent)",1.5,"var(--paper)","");break;case"fill":o=pi("var(--rule-solid)",1,t??"var(--ink)","");break;case"node":o=pi("var(--ink)",1.5,"var(--paper)","");break;case"node-accent":o=pi("var(--accent)",1.5,"var(--accent-tint)","");break;case"node-dashed":o=pi("var(--ink)",1.25,"var(--paper)","4 3");break;case"node-fill2":o=pi("var(--rule-solid)",1,"var(--paper-2)","");break;case"edge":o=$r("var(--muted)",1.5,"",!0);break;case"edge-dashed":o=$r("var(--muted)",1.5,"5 4",!1);break;case"edge-async":o=$r("var(--muted)",1.25,"2 3",!1);break;case"edge-error":o=$r("var(--negative)",1.5,"",!0);break;case"edge-accent":o=$r("var(--accent)",1.75,"",!0);break;case"edge-link":o=$r("var(--link)",1.5,"",!0);break;case"edge-accent-dashed":o=$r("var(--accent)",1.75,"5 4",!1);break;case"edge-negative-dashed":o=$r("var(--negative)",1.5,"5 4",!0);break;case"edge-implements":{const r=Cn/2;o=`<line x1="1" y1="${r}" x2="${yn-8}" y2="${r}" stroke="var(--muted)" stroke-width="1.5" stroke-dasharray="5 4"/><path d="M${yn-8},${r-4} L${yn-1},${r} L${yn-8},${r+4} z" fill="var(--paper)" stroke="var(--ink)" stroke-width="1.2"/>`;break}case"line-dot":case"line-dot-accent":{const r=Cn/2,i=e==="line-dot"?"var(--muted)":"var(--accent)";o=`<line x1="1" y1="${r}" x2="${yn-1}" y2="${r}" stroke="${i}" stroke-width="${e==="line-dot"?1.5:1.75}"/><circle cx="${yn/2}" cy="${r}" r="3.5" fill="${i}"/>`;break}case"node-store":o=`<rect x="1" y="1" width="${yn-2}" height="${Cn-2}" fill="var(--paper-2)"/><path d="M${yn-1},1 H1 V${Cn-1} H${yn-1}" fill="none" stroke="var(--rule-solid)" stroke-width="1"/>`;break;case"node-stadium":o=`<rect x="1" y="1" width="${yn-2}" height="${Cn-2}" rx="${(Cn-2)/2}" fill="var(--paper)" stroke="var(--ink)" stroke-width="1.5"/>`;break;case"node-stadium-fill2":o=`<rect x="1" y="1" width="${yn-2}" height="${Cn-2}" rx="${(Cn-2)/2}" fill="var(--paper-2)" stroke="var(--rule-solid)" stroke-width="1"/>`;break;case"node-negative":o=pi("var(--negative)",1.5,"var(--negative-tint)","");break;case"chip":return""}return`<svg class="lg-sw" viewBox="0 0 ${yn} ${Cn}" width="${yn}" height="${Cn}" aria-hidden="true">${o}</svg>`}function ot(e,t){if(e.length<2)return"";const n=e.map(o=>{const r=o.swatch==="chip"?`<span class="lg-chip t-eyebrow">${S(o.chip??"")}</span>`:m8(o.swatch,o.fill,o.stroke,o.dash);return`<span class="lg-item"${o.path!==void 0?_(o.path):""}>${r}<span class="lg-label">${S(o.label)}</span></span>`}).join("");return`<div class="diagram-legend"${t!==void 0?he(t):""}><span class="lg-title t-eyebrow">Legend</span>${n}</div>`}function wt(e,t,n=`${t}s`){return`${e} ${e===1?t:n}`}function Hy(e,t,n=[]){const s=(t??"").trim(),o=[...s!==""?[s]:[],...n.filter(r=>r.trim()!=="")];return o.length===0?e:`${e}: ${o.join(", ")}`}function g8(e){return` role="img" aria-label="${S(e)}"`}function v8(e){return`<title>${S(e)}</title>`}function Sn(e,t,n=[]){const s=Hy(e,t,n);return{name:s,attrs:g8(s),title:v8(s)}}var ut=' data-decorative="1"',zr=20,Bc=40,v4=6,Bn=12,Wa=6.2,y4=7.4,y8=150,lc=28,Hu=64,Sa=14,Ea=14,Nw=18,Ma=18,Wy=7;function x8(e){const t=e.entities??[],n=e.relations??[],s=e.groups??[],o=e.enums??[],r=e.dir!=="TB",i=t.map((fe,ge)=>k8(fe,ge)),l=new Map;for(const fe of i)l.set(fe.name,fe),fe.entity.schema!==void 0&&l.set(`${fe.entity.schema}.${fe.name}`,fe);const d=[];n.forEach((fe,ge)=>{const Ce=l.get(fe.from),Fe=l.get(fe.to);if(Ce===void 0||Fe===void 0)return;const qe=E8(fe.card);d.push({r:fe,idx:ge,from:Ce,to:Fe,...qe,dashed:fe.identifying===!1})});const u=new Map,p=new Map;for(const fe of d)fe.toMany||u.set(fe.to.name,(u.get(fe.to.name)??0)+1),fe.fromMany||u.set(fe.from.name,(u.get(fe.from.name)??0)+1),p.set(fe.from.name,(p.get(fe.from.name)??0)+1),fe.to!==fe.from&&p.set(fe.to.name,(p.get(fe.to.name)??0)+1);let h,m=0,g=!1;for(const[fe,ge]of u)ge>m?(m=ge,h=fe,g=!1):ge===m&&(g=!0);g&&(h=void 0);const v=[],y=new Map,b=[];for(const fe of s){const ge=(fe.entities??[]).filter(Fe=>l.has(Fe)&&!y.has(l.get(Fe)?.name??Fe));if(ge.length===0)continue;const Ce=v.length;v.push(fe.name),b.push(!0);for(const Fe of ge)y.set(l.get(Fe)?.name??Fe,Ce)}for(const fe of i){if(y.has(fe.name)||fe.entity.schema===void 0)continue;let ge=v.indexOf(fe.entity.schema);(ge===-1||!b[ge])&&(ge=v.length,v.push(fe.entity.schema),b.push(!0)),y.set(fe.name,ge)}const E=i.filter(fe=>!y.has(fe.name));if(E.length>0){const fe=v.length;v.push(""),b.push(!1);for(const ge of E)y.set(ge.name,fe)}const $=i.map((fe,ge)=>({box:fe,band:y.get(fe.name)??0,layer:0,order:ge,u:0,v:0,du:r?fe.w:fe.h,dv:r?fe.h:fe.w})),A=new Map($.map(fe=>[fe.box.name,fe])),T=new Map;for(const fe of $)T.set(fe.box.name,new Set);for(const fe of d)fe.from!==fe.to&&(T.get(fe.from.name)?.add(fe.to.name),T.get(fe.to.name)?.add(fe.from.name));S8($,T,p,h,A);const N=[...new Set($.map(fe=>fe.layer))].sort((fe,ge)=>fe-ge),j=N[0]??0,P=N[N.length-1]??0,I=[],O=new Map,C=(fe,ge)=>{const Ce=O.get(fe)??[];Ce.push(ge),O.set(fe,Ce)};let D=0;for(const fe of d){const ge=A.get(fe.from.name),Ce=A.get(fe.to.name);if(ge===void 0||Ce===void 0)continue;const Fe=ge===Ce,qe=ge.layer,ze=Ce.layer;let Xe,pt,kt=!1;Fe?Xe=pt=qe:qe<ze?(Xe=qe,pt=ze-1,kt=ze-qe>1):qe>ze?(Xe=qe-1,pt=ze,kt=qe-ze>1):Xe=pt=qe;const St={rel:fe,src:ge,dst:Ce,g1:Xe,g2:pt,long:kt,self:Fe,slot1:0,slot2:0,channel:kt?D++:-1};I.push(St),Fe||(C(Xe,St),kt&&C(pt,St))}const F=new Map;for(let fe=j;fe<=P;fe++){const ge=O.get(fe)?.length??0;F.set(fe,Math.max(fe===P?ge>0?(ge+1)*Sa:0:Hu,(ge+1)*Sa))}const U=D>0?D*Sa+8:0,X=new Map,B=new Map,te=[],ee=()=>{let fe=Ma;for(let Fe=j;Fe<=P;Fe++){const qe=Math.max(0,...$.filter(ze=>ze.layer===Fe).map(ze=>ze.du));X.set(Fe,fe),B.set(Fe,qe),fe+=qe+(F.get(Fe)??Hu)}let ge=Ma+U;te.length=0;let Ce=!1;v.forEach((Fe,qe)=>{const ze=$.filter(dt=>dt.band===qe),Xe=b[qe]===!0;if(ze.length===0){te.push({top:ge,bottom:ge,minL:0,maxL:0});return}const pt=ge+(qe>0?(Ce?Ea:0)+lc:0)+(Xe?Ea+Nw:0);let kt=0;const St=new Map;for(const dt of ze){const _t=St.get(dt.layer)??[];_t.push(dt),St.set(dt.layer,_t)}for(const dt of St.values())dt.sort((_t,En)=>_t.order-En.order),kt=Math.max(kt,dt.reduce((_t,En)=>_t+En.dv,0)+lc*(dt.length-1));let Nt=1/0,Bt=-1/0;for(const[dt,_t]of St){const En=_t.reduce((Et,an)=>Et+an.dv,0)+lc*(_t.length-1);let zt=pt+(kt-En)/2;for(const Et of _t)Et.u=(X.get(dt)??0)+((B.get(dt)??Et.du)-Et.du)/2,Et.v=zt,zt+=Et.dv+lc;Nt=Math.min(Nt,dt),Bt=Math.max(Bt,dt)}te.push({top:pt,bottom:pt+kt,minL:Nt,maxL:Bt}),ge=pt+kt,Ce=Xe})};ee();const H=[...N].sort((fe,ge)=>Math.abs(fe)-Math.abs(ge)||fe-ge),W=(fe,ge)=>{for(const Ce of fe){const Fe=ge(Ce);for(const qe of $){if(qe.layer!==Ce)continue;const ze=[...T.get(qe.box.name)??[]].map(Xe=>A.get(Xe)).filter(Xe=>Xe!==void 0&&Xe.layer===Fe);ze.length!==0&&(qe.order=ze.reduce((Xe,pt)=>Xe+pt.v+pt.dv/2,0)/ze.length)}}ee()};W(H,fe=>fe>0?fe-1:fe<0?fe+1:fe),W([...H].reverse(),fe=>fe>=0?fe+1:fe-1),W(H,fe=>fe>0?fe-1:fe<0?fe+1:fe);for(const[fe,ge]of O){const Ce=(X.get(fe)??0)+(B.get(fe)??0),Fe=F.get(fe)??Hu;ge.sort((qe,ze)=>Pw(qe.src,qe.dst)-Pw(ze.src,ze.dst)),ge.forEach((qe,ze)=>{const Xe=Ce+(ze+1)*Fe/(ge.length+1);qe.g1===fe&&qe.slot1===0&&(qe.slot1=Xe),qe.long&&qe.g2===fe&&(qe.slot2=Xe),qe.long||(qe.slot2=qe.slot1)})}const K=(fe,ge)=>r?fe:ge,R=(fe,ge)=>r?ge:fe,z=fe=>fe.map(([ge,Ce],Fe)=>`${Fe===0?"M":"L"}${nt(K(ge,Ce))},${nt(R(ge,Ce))}`).join(" ");let Y=0,V=0;const re=(fe,ge)=>{Y=Math.max(Y,fe),V=Math.max(V,ge)};for(const fe of $)re(K(fe.u+fe.du,fe.v+fe.dv),R(fe.u+fe.du,fe.v+fe.dv));let Q="",ne=!1;Q+=`<g${he("groups")}>`,v.forEach((fe,ge)=>{if(b[ge]!==!0)return;const Ce=te[ge];if(Ce===void 0||Ce.top===Ce.bottom)return;ne=!0;const Fe=(X.get(Ce.minL)??0)-Ea,qe=(X.get(Ce.maxL)??0)+(B.get(Ce.maxL)??0)+Ea,ze=Ce.top-Ea-Nw,Xe=Ce.bottom+Ea,pt=K(Fe,ze),kt=R(Fe,ze),St=K(qe,Xe)-pt,Nt=R(qe,Xe)-kt;re(pt+St,kt+Nt);const Bt=s.findIndex(dt=>dt.name===fe);Q+=`<g${Bt>=0?_(`groups.${Bt}`):""}><rect x="${nt(pt)}" y="${nt(kt)}" width="${nt(St)}" height="${nt(Nt)}" rx="8" class="er-panel"/><text x="${nt(pt+12)}" y="${nt(kt+13)}" class="t-eyebrow er-panel-tab">${S(fe.toUpperCase())}</text></g>`}),Q+="</g>";const Z=[];let q=!1,de=!1;Q+=`<g${he("relations")}>`;for(const fe of I){const{rel:ge,src:Ce,dst:Fe}=fe;q=!0,ge.dashed&&(de=!0);const qe=ge.fromMany&&!ge.toMany?!0:!ge.fromMany&&ge.toMany?!1:Lw(ge.from,ge.to,ge.r.fromCol)||!Lw(ge.to,ge.from,ge.r.toCol),ze=ge.fromMany&&ge.toMany,Xe=ze?Ce.v+Ce.dv/2:jw(Ce,r,qe?y0(ge.from,ge.to,ge.r.fromCol):Iw(ge.from,ge.r.fromCol)),pt=ze?Fe.v+Fe.dv/2:jw(Fe,r,qe?Iw(ge.to,ge.r.toCol):y0(ge.to,ge.from,ge.r.toCol)),kt=Ce.layer,St=Fe.layer;let Nt,Bt,dt,_t;if(fe.self){const zt=Ce.u+Ce.du,Et=Math.abs(pt-Xe)<1?Xe+zr:pt,an=zt+Sa;Nt=z([[zt,Xe],[an,Xe],[an,Et],[zt,Et]]),Bt=1,dt=-1,_t=[an+8,Math.max(Xe,Et)+12]}else if(kt===St){const zt=Math.max(Ce.u+Ce.du,Fe.u+Fe.du),Et=fe.slot1>0?fe.slot1:zt+Sa;Nt=z([[Ce.u+Ce.du,Xe],[Et,Xe],[Et,pt],[Fe.u+Fe.du,pt]]),Bt=1,dt=-1,_t=[Et,(Xe+pt)/2]}else{const zt=kt<St,Et=zt?Ce.u+Ce.du:Ce.u,an=zt?Fe.u:Fe.u+Fe.du;if(Bt=zt?1:-1,dt=zt?1:-1,!fe.long)Nt=z([[Et,Xe],[fe.slot1,Xe],[fe.slot1,pt],[an,pt]]),_t=[fe.slot1,Math.abs(Xe-pt)<zr*2?Math.max(Xe,pt)+12:(Xe+pt)/2];else{const _n=Ma+fe.channel*Sa+4;Nt=z([[Et,Xe],[fe.slot1,Xe],[fe.slot1,_n],[fe.slot2,_n],[fe.slot2,pt],[an,pt]]),_t=[(fe.slot1+fe.slot2)/2,_n]}}const En=ge.dashed?' stroke-dasharray="5 4"':"";if(Q+=`<g${_(`relations.${ge.idx}`)}><path d="${Nt}" fill="none" stroke="var(--muted)" stroke-width="1.25"${En}/>`+Rw(fe.self||Bt>0?Ce.u+Ce.du:Ce.u,Xe,Bt,Ow(ge.fromMany,!1),r,K,R)+Rw(fe.self||kt===St?Fe.u+Fe.du:dt>0?Fe.u:Fe.u+Fe.du,pt,fe.self||kt===St?1:-dt,Ow(ge.toMany,ge.toOptional),r,K,R)+"</g>",ge.r.label!==void 0&&ge.r.label!==""){const zt=ge.r.label.toUpperCase(),Et=Math.round(zt.length*Wa+8),an=K(_t[0],_t[1]),_n=R(_t[0],_t[1]);Z.push(`<rect x="${nt(an-Et/2)}" y="${nt(_n-7)}" width="${Et}" height="14" fill="var(--paper)"/><text x="${nt(an)}" y="${nt(_n+3.5)}" class="t-arrow er-rel" text-anchor="middle">${S(zt)}</text>`),re(an+Et/2,_n+7)}}Q+="</g>";const le=new Set;let J=!1;const ue=new Set;Q+=`<g${he("entities")}>`;for(const fe of $){const ge=fe.box,Ce=K(fe.u,fe.v),Fe=R(fe.u,fe.v),qe=ge.name===h,ze=qe?"AGGREGATE ROOT":ge.kind==="view"?"VIEW":ge.kind==="enum"?"ENUM":ge.kind==="external"?"EXT":ge.join?"JOIN":"ENTITY";ge.join&&!qe&&ge.kind==="table"&&(J=!0),ge.kind!=="table"&&ue.add(ge.kind);const Xe=ge.kind==="view"||ge.kind==="enum",pt=qe?"var(--accent)":Xe?"var(--rule-solid)":"var(--ink)",kt=qe?"var(--accent-tint)":ge.kind==="view"?"var(--paper-2)":"var(--paper)",St=Xe?1:1.5,Nt=ge.kind==="external"?' stroke-dasharray="4 3"':"";Q+=`<g${_(`entities.${ge.idx}`)}><rect x="${nt(Ce)}" y="${nt(Fe)}" width="${ge.w}" height="${ge.h}" rx="6" fill="${kt}" stroke="${pt}" stroke-width="${St}"${Nt}/><text x="${nt(Ce+Bn)}" y="${nt(Fe+15)}" class="er-eyebrow t-eyebrow${qe?" c-accent":""}">${ze}</text><text x="${nt(Ce+Bn)}" y="${nt(Fe+31)}" class="er-head-text t-name">${S(ge.name)}</text>`,ge.headLines.forEach((dt,_t)=>{Q+=`<text x="${nt(Ce+Bn)}" y="${nt(Fe+44+_t*13)}" class="er-col dim t-sub c-soft">${S(dt)}</text>`}),(ge.rows.length>0||ge.headLines.length>0)&&(Q+=`<line x1="${nt(Ce)}" y1="${nt(Fe+ge.headH)}" x2="${nt(Ce+ge.w)}" y2="${nt(Fe+ge.headH)}" class="er-headline"/>`),Q+=`<g${he(`entities.${ge.idx}.columns`)}>`;let Bt=-1;ge.rows.forEach((dt,_t)=>{const En=Fe+ge.headH+_t*zr,zt=En+14;dt.kind==="col"?(Bt>=0&&(Q+="</g>"),Bt=dt.colIdx,Q+=`<g${_(`entities.${ge.idx}.columns.${dt.colIdx}`)}>`,dt.note!==void 0&&(Q+=`<title>${S(dt.note)}</title>`),_t>0&&(Q+=`<line x1="${nt(Ce+1)}" y1="${nt(En)}" x2="${nt(Ce+ge.w-1)}" y2="${nt(En)}" class="er-rowline"${ut}/>`),dt.markers.forEach((Et,an)=>{le.add(Et),Q+=`<text x="${nt(Ce+Bn+an*Wy)}" y="${nt(zt)}" class="er-key ${w8(Et)} t-sub c-muted">${S(Et)}</text>`}),Q+=`<text x="${nt(Ce+Bn+Tw(ge))}" y="${nt(zt)}" class="er-col t-sub c-ink">${S(dt.left)}</text>`+(dt.right.length>0?`<text x="${nt(Ce+ge.w-Bn)}" y="${nt(zt)}" class="er-col dim t-sub c-soft" text-anchor="end">${S(dt.right)}</text>`:"")):Q+=`<text x="${nt(Ce+Bn+Tw(ge))}" y="${nt(zt)}" class="er-col dim t-sub c-soft">${S(dt.left)}</text>`}),Bt>=0&&(Q+="</g>"),Q+="</g></g>"}Q+="</g>";const ve=o.map((fe,ge)=>b8(fe.name,fe.values,ge));if(ve.length>0){const fe=Y+Hu;let ge=Ma+U;Q+=`<g${he("enums")}>`;for(const Ce of ve)Q+=`<g${_(`enums.${Ce.idx}`)}><rect x="${nt(fe)}" y="${nt(ge)}" width="${Ce.w}" height="${Ce.h}" rx="6" fill="var(--paper)" stroke="var(--rule-solid)" stroke-width="1"/><text x="${nt(fe+Bn)}" y="${nt(ge+15)}" class="er-eyebrow t-eyebrow">ENUM</text><text x="${nt(fe+Bn)}" y="${nt(ge+31)}" class="er-head-text t-name">${S(Ce.name)}</text><line x1="${nt(fe)}" y1="${nt(ge+Bc)}" x2="${nt(fe+Ce.w)}" y2="${nt(ge+Bc)}" class="er-headline"/>`,Ce.values.forEach((Fe,qe)=>{const ze=ge+Bc+qe*zr;qe>0&&(Q+=`<line x1="${nt(fe+1)}" y1="${nt(ze)}" x2="${nt(fe+Ce.w-1)}" y2="${nt(ze)}" class="er-rowline"${ut}/>`),Q+=`<text x="${nt(fe+Bn)}" y="${nt(ze+14)}" class="er-col t-sub c-ink">${S(Fe)}</text>`}),Q+="</g>",re(fe+Ce.w,ge+Ce.h),ge+=Ce.h+lc;Q+="</g>"}Q+=Z.join("");const we=Math.ceil(Y+Ma),$e=Math.ceil(V+Ma),je=Sn("Entity relationship diagram",e.title,[wt(t.length,"entity","entities")]),De=`<svg viewBox="0 0 ${we} ${$e}"${je.attrs}>`+je.title+Q+"</svg>",Me=[];le.has("#")&&Me.push({swatch:"chip",chip:"#",label:"primary key"}),le.has("→")&&Me.push({swatch:"chip",chip:"→",label:"foreign key"}),le.has("U")&&Me.push({swatch:"chip",chip:"U",label:"unique"}),le.has("?")&&Me.push({swatch:"chip",chip:"?",label:"nullable"}),le.has("⌘")&&Me.push({swatch:"chip",chip:"⌘",label:"indexed"}),q&&Me.push({swatch:"chip",chip:"1 / N",label:"cardinality"}),de&&(Me.push({swatch:"line",label:"identifying"}),Me.push({swatch:"line-dashed",label:"non-identifying"})),J&&Me.push({swatch:"chip",chip:"JOIN",label:"join table"}),ue.has("view")&&Me.push({swatch:"node-fill2",label:"view"}),(ue.has("enum")||ve.length>0)&&Me.push({swatch:"chip",chip:"ENUM",label:"enum"}),ue.has("external")&&Me.push({swatch:"node-dashed",label:"external"}),ne&&Me.push({swatch:"node-fill2",label:"schema group"}),h!==void 0&&Me.push({swatch:"node-accent",label:"aggregate root"});const Be=ot(Me),Ge={tag:"ER",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...Be.length>0?{legendHtml:Be}:{}};return ct(Ge,De)}function k8(e,t){const n=e.columns??[],s=e.kind??"table",o=Math.max(0,...n.map(m=>v0(m).length)),r=o>0?o*Wy+6:0;let i=Math.max(y8,e.name.length*y4+Bn*2+24);const l=n.map(m=>$8(m));n.forEach((m,g)=>{i=Math.max(i,Bn*2+r+m.name.length*Wa+16+(l[g]?.length??0)*Wa)});const d=i-Bn*2-r,u=[];n.forEach((m,g)=>{if(u.push({kind:"col",col:m,colIdx:g,markers:v0(m),left:m.name,right:l[g]??"",...m.note!==void 0&&m.note.length>0?{note:m.note}:{}}),m.enum!==void 0&&m.enum.length>0)for(const v of _w(m.enum.join(" · "),Math.max(24,Math.floor(d/Wa))))u.push({kind:"sub",colIdx:g,markers:[],left:v,right:""})});const p=e.note!==void 0&&e.note.length>0?_w(e.note,Math.max(24,Math.floor((i-Bn*2)/Wa))):[],h=Bc+(p.length>0?p.length*13+2:0);return{name:e.name,idx:t,entity:e,cols:n,rows:u,headLines:p,headH:h,pkIdx:n.findIndex(m=>m.pk===!0),join:n.length>0&&n.every(m=>m.fk===!0),kind:s,w:Math.round(i),h:h+u.length*zr+(u.length>0?v4:0)}}function b8(e,t,n){const s=Math.round(Math.max(120,e.length*y4+Bn*2+12,...t.map(o=>o.length*Wa+Bn*2)));return{idx:n,name:e,values:t,w:s,h:Bc+t.length*zr+(t.length>0?v4:0)}}function v0(e){const t=[];return e.pk===!0&&t.push("#"),e.fk===!0&&t.push("→"),e.unique===!0&&t.push("U"),e.nullable===!0&&t.push("?"),e.index===!0&&t.push("⌘"),t}function w8(e){return e==="#"?"pk":e==="→"?"fk":e==="U"?"uk":e==="?"?"nul":"ix"}function Tw(e){const t=Math.max(0,...e.cols.map(n=>v0(n).length));return t>0?t*Wy+6:0}function $8(e){const t=[];return e.type!==void 0&&e.type.length>0&&t.push(e.type),e.ref!==void 0&&e.ref.length>0&&t.push(`→ ${e.ref}`),e.default!==void 0&&e.default.length>0&&t.push(`= ${e.default}`),t.join(" ")}function _w(e,t){const n=[];let s="";for(const o of e.split(/\s+/).filter(r=>r.length>0))for(s.length===0?s=o:s.length+1+o.length<=t?s+=" "+o:(n.push(s),s=o);s.length>t;)n.push(s.slice(0,t)),s=s.slice(t);return s.length>0&&n.push(s),n}function S8(e,t,n,s,o){const r=new Set,i=[];for(const u of e){if(r.has(u.box.name)||(t.get(u.box.name)?.size??0)===0)continue;const p=[],h=[u];for(r.add(u.box.name);h.length>0;){const m=h.shift();p.push(m);for(const g of t.get(m.box.name)??[]){if(r.has(g))continue;r.add(g);const v=o.get(g);v!==void 0&&h.push(v)}}i.push(p)}i.sort((u,p)=>{const h=s!==void 0&&u.some(g=>g.box.name===s)?1:0;return(s!==void 0&&p.some(g=>g.box.name===s)?1:0)-h||p.length-u.length}),i.forEach((u,p)=>{const h=u.find(E=>E.box.name===s)??u.reduce((E,$)=>(n.get($.box.name)??0)>(n.get(E.box.name)??0)?$:E,u[0]),m=new Map([[h.box.name,0]]),g=[h];for(;g.length>0;){const E=g.shift(),$=m.get(E.box.name)??0;for(const A of t.get(E.box.name)??[]){if(m.has(A))continue;m.set(A,$+1);const T=o.get(A);T!==void 0&&g.push(T)}}const v=new Map,y=[];for(const E of u){if(E===h||v.has(E.box.name))continue;const $=[],A=[E.box.name];for(v.set(E.box.name,y.length);A.length>0;){const T=A.shift();$.push(T);for(const N of t.get(T)??[])N===h.box.name||v.has(N)||(v.set(N,y.length),A.push(N))}y.push($)}const b=y.map(()=>1);if(p===0&&y.length>1){const E=y.map((T,N)=>({i:N,size:T.length})).sort((T,N)=>N.size-T.size||T.i-N.i);let $=0,A=0;for(const{i:T,size:N}of E)A<=$?(b[T]=1,A+=N):(b[T]=-1,$+=N)}for(const E of u){const $=m.get(E.box.name)??0,A=v.get(E.box.name);E.layer=A===void 0?0:(b[A]??1)*$}});const l=e.filter(u=>!r.has(u.box.name));if(l.length===0)return;const d=[...new Set(e.filter(u=>r.has(u.box.name)).map(u=>u.layer))].sort((u,p)=>u-p);if(d.length===0){l.forEach((u,p)=>{u.layer=p%4});return}l.forEach((u,p)=>{u.layer=d[p%d.length]??0})}function Lw(e,t,n){return y0(e,t,n)>=0}function y0(e,t,n){if(n!==void 0){const d=e.cols.findIndex(u=>u.name===n);if(d>=0)return zc(e,d)}const s=t.name.toLowerCase(),o=s.replace(/s$/,""),r=e.cols.map((d,u)=>({c:d,i:u})).filter(d=>d.c.fk===!0),i=r.find(d=>{const u=d.c.ref?.toLowerCase()??"";return u.startsWith(s+".")||u===s||u.startsWith(t.name.toLowerCase())});if(i!==void 0)return zc(e,i.i);const l=r.find(d=>{const u=d.c.name.toLowerCase();return u.includes(s)||u.includes(o)});return l!==void 0?zc(e,l.i):-1}function Iw(e,t){if(t!==void 0){const n=e.cols.findIndex(s=>s.name===t);if(n>=0)return zc(e,n)}return e.pkIdx>=0?zc(e,e.pkIdx):-1}function zc(e,t){return e.rows.findIndex(n=>n.kind==="col"&&n.colIdx===t)}function jw(e,t,n){return!t||n<0?e.v+e.dv/2:e.v+e.box.headH+n*zr+zr/2}function Pw(e,t){return(e.v+e.dv/2+t.v+t.dv/2)/2}function E8(e){if(e===void 0)return{fromMany:!0,toMany:!1,toOptional:!1};if(e==="0..1")return{fromMany:!1,toMany:!1,toOptional:!0};if(e==="0..N")return{fromMany:!1,toMany:!0,toOptional:!0};const t=e.split(":"),n=s=>s!==void 0&&s.trim().toUpperCase()!=="1";return{fromMany:n(t[0]),toMany:n(t[1]),toOptional:!1}}function Ow(e,t){return t?e?"0..N":"0..1":e?"N":"1"}function Rw(e,t,n,s,o,r,i){const l=e+n*10,d=r(l,t),u=i(l,t);if(o){const p=n>0?"start":"end";return`<text x="${nt(d)}" y="${nt(u-4)}" class="t-arrow er-card" text-anchor="${p}">${S(s)}</text>`}return`<text x="${nt(d+4)}" y="${nt(u+3)}" class="t-arrow er-card" text-anchor="start">${S(s)}</text>`}var nt=e=>Math.round(e*10)/10;function M8(e){const t=e.columns??[];let n=`<div class="kanban"${he("columns")}>`;return t.forEach((s,o)=>{const r=(s.cards??[]).map((i,l)=>{const d=i.tag!==void 0?`<div class="kan-card-tag">${S(i.tag)}</div>`:"";return`<div class="kan-card"${_(`columns.${o}.cards.${l}`)}><div class="kan-card-title">${S(i.title)}</div>`+d+"</div>"}).join("");n+=`<div class="kan-col"${_(`columns.${o}`)}${he(`columns.${o}.cards`)}><div class="kan-head"${_(`columns.${o}.label`)}>${S(s.label)}</div>`+r+"</div>"}),n+"</div>"}function lt(e,t,n){if(e==null||e==="")return[];const s=String(e).split(/\s+/),o=[];let r="";for(const i of s){if(!r){r=i;continue}if((r+" "+i).length<=t)r+=" "+i;else if(o.push(r),r=i,o.length===n)break}return r&&o.length<n&&o.push(r),o.slice(0,n)}function hn(e){return` data-reveal="${e}"`}var x4={sync:{cls:"msg-line",marker:"sqArrow",txt:"msg-text t-arrow em"},response:{cls:"msg-line dashed",marker:"sqOpen",txt:"msg-text t-arrow"},async:{cls:"msg-line async",marker:"sqOpen",txt:"msg-text t-arrow"},error:{cls:"msg-line err",marker:"sqErr",txt:"msg-text t-arrow err"},note:{cls:"",marker:null,txt:"msg-text t-arrow note"}},qp=36,A8=28,C8=24,N8=14,k4=13,T8=34,_8=3,Dw=18,Bw=12,zw=6,Fc=6,b4=150,L8=46,I8=6.2,j8=40;function P8(e,t){const n=o=>e.findIndex(r=>r.id===o),s=e.slice(0,-1).map(()=>L8);for(const o of t){if(!("from"in o)||o.kind==="note")continue;const r=n(o.from),i=n(o.to);if(r<0||i<0||Math.abs(r-i)!==1)continue;const l=Math.min(r,i),d=Math.ceil((o.label??"").length*I8+j8)-b4;d>(s[l]??0)&&(s[l]=d)}return s}function w4(e){return e.kind==="msg"}function O8(e){const t=new Map;let n=0;for(const s of e)s.kind!=="end"&&(t.set(s.idx,n),n+=1);return t}function R8(e,t,n,s){const o=u=>{const p=s.get(u);return p===void 0?"":hn(p)},r=e.filter(w4);if(!r.some(u=>u.summary!==void 0&&u.summary.length>0))return"";const i=new Set,l=u=>{const p=u.open.idx,h=u.end?.idx??Number.POSITIVE_INFINITY;if(r.some(g=>g.idx>p&&g.idx<h&&g.summary!==void 0&&g.summary.length>0)){i.add(u.open.idx);for(const g of u.elses)i.add(g.idx)}u.children.forEach(l)};t.forEach(l);const d=[];for(const u of e){if(u.kind==="open"&&i.has(u.idx)){const E=u.label.length>0?`<span class="step-frame-label">${S(u.label)}</span>`:"";d.push(`<li class="step-frame"${_(`messages.${u.idx}`)}${o(u.idx)}><span class="step-frame-tag">${S(u.frame.toUpperCase())}</span>${E}</li>`);continue}if(u.kind==="else"&&i.has(u.idx)){d.push(`<li class="step-frame else"${_(`messages.${u.idx}`)}${o(u.idx)}><span class="step-frame-tag">else</span><span class="step-frame-label">${S(u.label)}</span></li>`);continue}if(u.kind!=="msg"||u.summary===void 0||u.summary.length===0)continue;const p=u.msgKind==="error"?' class="err"':"",h=u.msgKind==="error"?" err":"",m=n.get(u.from)?.name??u.from,g=u.msgKind==="note"||u.from===u.to?"":` &rarr; ${S(n.get(u.to)?.name??u.to)}`,v=`${S(m)}${g}`,y=u.code!==void 0&&u.code.length>0?`<pre class="sql">${S(u.code)}</pre>`:"",b=u.note!==void 0&&u.note.length>0?`<span class="step-note">${S(u.note)}</span>`:"";d.push(`<li${p}${_(`messages.${u.idx}`)}${o(u.idx)}><span class="step-n">${u.n}</span><span class="step-actor${h}">${v}</span><span class="step-summary">${S(u.summary)}</span>`+y+b+"</li>")}return`<div class="seq-steps"><div class="seq-steps-title">Step-by-step</div><ol>${d.join("")}</ol></div>`}function D8(e){if(e.length===0)return"";const t=e.map((n,s)=>`<span${_(`foot.${s}`)}><strong>${S(n.label)}:</strong> ${S(n.value)}</span>`).join("");return`<div class="diagram-foot"${he("foot")}>${t}</div>`}function B8(e,t,n){const s=[];let o=n-qp,r=0;return e.forEach((i,l)=>{const d=i;if("frame"in d){const y=typeof d.label=="string"?d.label:"";s.push({kind:"open",idx:l,top:o,y:o+14,frame:String(d.frame),label:y}),o+=A8;return}if("else"in d){s.push({kind:"else",idx:l,top:o,y:o+8,frame:"",label:String(d.else??"")}),o+=C8;return}if("end"in d){s.push({kind:"end",idx:l,top:o,y:o+10,frame:"",label:""}),o+=N8;return}const u=i;r+=1;const p=u.kind!==void 0&&u.kind in x4?u.kind:"sync",h=u.label??"",m=p==="note"?lt(h,T8,_8):[],g=p==="note"?qp+k4*Math.max(0,m.length-1):qp,v={kind:"msg",idx:l,n:r,top:o,y:o+g,fromI:t(u.from),toI:t(u.to),msgKind:p,label:h,from:u.from,to:u.to,activate:u.activate===!0,deactivate:u.deactivate===!0,lines:m,...u.summary!==void 0?{summary:u.summary}:{},...u.code!==void 0?{code:u.code}:{},...u.note!==void 0?{note:u.note}:{}};s.push(v),o+=g}),{rows:s,cursor:o}}function z8(e){const t=[],n=[];for(const s of e)if(s.kind==="open"){const o={open:s,elses:[],children:[],x1:0,x2:0},r=n[n.length-1];r!==void 0?r.children.push(o):t.push(o),n.push(o)}else if(s.kind==="else")n[n.length-1]?.elses.push(s);else if(s.kind==="end"){const o=n.pop();o!==void 0&&(o.end=s)}return t}function F8(e,t,n){if(e.msgKind==="note"){const s=n(e);return s===null?null:[s.x,s.x+s.w]}if(e.fromI<0&&e.toI<0)return null;if(e.fromI<0)return[t(e.toI),t(e.toI)];if(e.toI<0)return[t(e.fromI),t(e.fromI)+36+e.label.length*Fc];if(e.fromI===e.toI){const s=t(e.fromI);return[s,s+36+e.label.length*Fc]}return[Math.min(t(e.fromI),t(e.toI)),Math.max(t(e.fromI),t(e.toI))]}function q8(e){const t=e.actors??[],n=e.messages??[],s=Math.max(t.length,1),o=24,r=b4,i=P8(t,n),l=16,d=t.map(J=>lt(J.name,J.external===!0?16:19,2)),u=d.some(J=>J.length>1),p=u?54:40,h=[];for(let J=0;J<s;J++)h.push(o+r/2+J*r+i.slice(0,J).reduce((ue,ve)=>ue+ve,0));const m=J=>h[J]??o+r/2,g=o*2+s*r+i.reduce((J,ue)=>J+ue,0),v=J=>t.findIndex(ue=>ue.id===J),y=l+p+28,{rows:b,cursor:E}=B8(n,v,y),$=b.filter(w4),A=O8(b),T=J=>hn(A.get(J)??0),N=E+qp+12,j=N+6;let P=-1;for(const J of $)J.msgKind==="response"&&J.toI===0&&J.fromI>0&&(P=J.idx);const I=J=>{if(J.fromI<0&&J.toI<0)return null;const ue=Math.max(0,...J.lines.map(Be=>Be.length)),ve=J.top+14,we=J.y-J.top-18;if(J.fromI<0||J.toI<0||J.fromI===J.toI){const Be=m(J.fromI<0?J.toI:J.fromI),Ge=Math.max(72,Math.round(ue*Fc)+16);return{x:Be+12+Ge<=g-2?Be+12:Be-12-Ge,w:Ge,top:ve,h:we}}const $e=Math.min(m(J.fromI),m(J.toI)),je=Math.max(m(J.fromI),m(J.toI)),De=Math.max(je-$e+60,Math.round(ue*Fc)+16),Me=($e+je)/2;return{x:Math.round(Me-De/2),w:De,top:ve,h:we}},O=z8(b),C=J=>{J.children.forEach(C);const ue=J.open.idx,ve=J.end?.idx??Number.POSITIVE_INFINITY;let we=Number.POSITIVE_INFINITY,$e=Number.NEGATIVE_INFINITY;for(const je of $){if(je.idx<=ue||je.idx>=ve)continue;const De=F8(je,m,I);De!==null&&(we=Math.min(we,De[0]),$e=Math.max($e,De[1]))}we===Number.POSITIVE_INFINITY?(we=o,$e=g-o):(we-=Dw,$e+=Dw);for(const je of J.children)we=Math.min(we,je.x1-Bw),$e=Math.max($e,je.x2+Bw);J.x1=Math.max(2,Math.round(we)),J.x2=Math.min(g-2,Math.round($e))};O.forEach(C);const D=J=>J.end?.y??E+6,F=$.some(J=>J.activate||J.deactivate),U=[],X=new Map,B=J=>{let ue=X.get(J);return ue===void 0&&(ue=[],X.set(J,ue)),ue},te=(J,ue,ve,we)=>{const $e=B(J),je={i:J,y1:ue,y2:Number.NaN,depth:$e.length,caller:ve,last:ue,step:we};$e.push(je),U.push(je)};for(const J of $){if(F){if(J.activate&&J.toI>=0&&te(J.toI,J.y,J.fromI,A.get(J.idx)??0),J.deactivate&&J.fromI>=0){const ue=B(J.fromI).pop();ue!==void 0&&(ue.y2=J.y)}continue}if(!(J.msgKind==="note"||J.fromI<0)){for(const ue of B(J.fromI))ue.last=J.y;if(!(J.toI<0||J.toI===J.fromI))if(J.msgKind==="sync"||J.msgKind==="async")te(J.toI,J.y,J.fromI,A.get(J.idx)??0);else{const ue=B(J.fromI);for(let ve=ue.length-1;ve>=0;ve--){const we=ue[ve];if(we.caller===J.toI){we.y2=J.y,ue.splice(ve,1);break}}}}}for(const J of X.values())for(const ue of J)ue.y2=F?E:ue.last;const ee=Sn("Sequence diagram",e.title??e.endpoint?.path,[`${wt($.length,"message")} between ${wt(t.length,"actor")}`]);let H=`<svg viewBox="0 0 ${g} ${j}"${ee.attrs}>`+ee.title+'<defs><marker id="sqArrow" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="var(--muted)"/></marker><marker id="sqOpen" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path d="M1,1 L9,5 L1,9" fill="none" stroke="var(--muted)" stroke-width="1.6"/></marker><marker id="sqErr" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="var(--negative)"/></marker><marker id="sqAccent" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path d="M1,1 L9,5 L1,9" fill="none" stroke="var(--accent)" stroke-width="1.6"/></marker></defs>',W="",K="";const R=t.map((J,ue)=>m(ue)),z=(J,ue)=>{const ve=(ue.length+2)*Fc,we=R.find($e=>$e>=J-6&&$e<=J+ve);return we===void 0?J:we+12},Y=J=>{const ue=J.open.y,ve=D(J),we=_(`messages.${J.open.idx}`)+T(J.open.idx);W+=`<g${we}><rect x="${J.x1}" y="${ue}" width="${J.x2-J.x1}" height="${Math.max(0,ve-ue)}" rx="4" class="seq-frame"/></g>`;const $e=J.open.frame.toUpperCase(),je=10+$e.length*7,De=J.open.label.length>0?`<text x="${z(J.x1+je+8,J.open.label)}" y="${ue+12}" class="seq-frame-guard t-arrow c-soft">[${S(J.open.label)}]</text>`:"";K+=`<g${we}><rect x="${J.x1}" y="${ue}" width="${je}" height="16" rx="2" class="seq-frame-tab"/><text x="${J.x1+5}" y="${ue+11.5}" class="seq-frame-tab-text t-eyebrow">${S($e)}</text>`+De+"</g>";for(const Me of J.elses){const Be=_(`messages.${Me.idx}`)+T(Me.idx);W+=`<g${Be}><line x1="${J.x1}" y1="${Me.y}" x2="${J.x2}" y2="${Me.y}" class="seq-frame-else"/></g>`,K+=`<g${Be}><text x="${z(J.x1+8,Me.label)}" y="${Me.y+14}" class="seq-frame-guard t-arrow c-soft">[${S(Me.label)}]</text></g>`}J.children.forEach(Y)};O.forEach(Y),H+=W;for(let J=0;J<t.length;J++){const ue=m(J);H+=`<line x1="${ue}" y1="${l+p}" x2="${ue}" y2="${N}" class="lifeline"/>`}for(const J of U){const ue=J.y1-zw,ve=J.y2+zw;H+=`<rect x="${m(J.i)-3+J.depth*4}" y="${ue}" width="6" height="${Math.max(0,ve-ue)}" class="activation"${hn(J.step)}/>`}H+=`<g${he("actors")}>`,t.forEach((J,ue)=>{const ve=J.external===!0,we=ve?" ext":"",$e=d[ue]??[],je=J.sub!==void 0,De=$e.length>1?l+(ve?21:17):je?l+(ve?22:17):l+(ve?25:24),Me=l+(u?47:33),Be=$e.length<=1?`<text x="${m(ue)}" y="${De}" class="lane-head-text t-name">${S(J.name)}</text>`:$e.map((ge,Ce)=>`<text x="${m(ue)}" y="${De+Ce*14}" class="lane-head-text t-name">${S(ge)}</text>`).join(""),Ge=je?`<text x="${m(ue)}" y="${Me}" class="lane-head-sub t-sub">${S(J.sub??"")}</text>`:"",fe=ve?`<text x="${m(ue)-r/2+8}" y="${l+11}" class="lane-head-chip t-eyebrow">EXT</text>`:"";H+=`<g${_(`actors.${ue}`)}><rect x="${m(ue)-r/2}" y="${l}" width="${r}" height="${p}" rx="4" class="lane-head${we}"/>`+fe+Be+Ge+"</g>"}),H+="</g>",H+=K,H+=`<g${he("messages")}>`;const V={sync:!1,response:!1,async:!1,error:!1,note:!1};for(const J of $){const ue=x4[J.msgKind],we=J.idx===P?{cls:`${ue.cls} accent`,marker:"sqAccent",txt:`${ue.txt} accent`}:ue;V[J.msgKind]=!0;const $e=_(`messages.${J.idx}`)+T(J.idx),je=J.msgKind==="error"?" err":"",De=(ze,Xe)=>`<circle cx="${ze}" cy="${Xe}" r="8" class="step-badge${je}"/><text x="${ze}" y="${Xe+3}" class="step-badge-text t-badge${je===""?"":" c-negative"}">${J.n}</text>`;if(J.msgKind==="note"){const ze=I(J);if(ze===null)continue;const Xe=J.summary!==void 0&&J.summary.length>0,pt=ze.x+ze.w/2,kt=J.lines.map((St,Nt)=>`<text x="${pt}" y="${ze.top+16+Nt*k4}" class="seq-note-text t-sub" text-anchor="middle">${S(St)}</text>`).join("");H+=`<g${$e}><rect x="${ze.x}" y="${ze.top}" width="${ze.w}" height="${ze.h}" rx="3" class="seq-note"/><path d="M${ze.x+ze.w-7},${ze.top} v7 h7" class="seq-note-fold"/>`+kt+(Xe?De(ze.x+2,ze.top):"")+"</g>";continue}if(J.fromI<0||J.toI<0){if(J.fromI<0&&J.toI<0)continue;const ze=m(J.fromI<0?J.toI:J.fromI);H+=`<g${$e}>`+De(ze+18,J.y-10)+`<text x="${ze+34}" y="${J.y-6}" class="msg-text note">${S(J.label)}</text></g>`;continue}if(J.fromI===J.toI){const ze=m(J.fromI),Xe=we.marker!==null?` marker-end="url(#${we.marker})"`:"";H+=`<g${$e}><path d="M${ze},${J.y-14} H${ze+28} V${J.y} H${ze+3}" class="${we.cls} self"${Xe}/>`+De(ze+16,J.y-26)+`<text x="${ze+36}" y="${J.y-4}" class="${we.txt}" text-anchor="start">${S(J.label)}</text></g>`;continue}const Me=m(J.fromI),Be=m(J.toI),Ge=Be>Me,fe=Be+(Ge?-3:3),ge=Ge?Me+18:Me-18,Ce=Ge?ge+16:ge-16,Fe=Ge?"start":"end",qe=we.marker!==null?` marker-end="url(#${we.marker})"`:"";H+=`<g${$e}><line x1="${Me}" y1="${J.y}" x2="${fe}" y2="${J.y}" class="${we.cls}"${qe}/>`+De(ge,J.y-10)+`<text x="${Ce}" y="${J.y-6}" class="${we.txt}" text-anchor="${Fe}">${S(J.label)}</text></g>`}H+="</g>",H+="</svg>";const re=new Map;for(const J of t)re.set(J.id,{name:J.name});const Q=R8(b,O,re,A),ne=e.foot!==void 0?D8(e.foot):"",Z=[];V.sync&&Z.push({swatch:"edge",label:"call"}),V.response&&Z.push({swatch:"edge-dashed",label:"response"}),V.async&&Z.push({swatch:"edge-async",label:"async"}),V.error&&Z.push({swatch:"edge-error",label:"error"}),P>=0&&Z.push({swatch:"edge-accent-dashed",label:"the answer the caller gets"}),t.some(J=>J.external===!0)&&Z.push({swatch:"chip",chip:"EXT",label:"external actor"}),O.length>0&&Z.push({swatch:"node-fill2",label:"fragment (alt / opt / loop)"}),U.length>0&&Z.push({swatch:"node",label:"active"});const q=ot(Z),de=e.endpoint?.method,le={tag:"SEQUENCE",...de!==void 0?{tagClass:de.toLowerCase(),method:de}:{},...e.endpoint?.path!==void 0?{path:e.endpoint.path}:{},...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...q.length>0?{legendHtml:q}:{},...ne.length>0?{footerHtml:ne}:{}};return ct(le,H+Q)}function Fw(e){if(typeof e=="string")return"";const t=[];return e.align==="r"&&t.push("r"),e.align==="c"&&t.push("c"),e.highlight===!0&&t.push("hi"),t.join(" ")}function H8(e){return typeof e=="string"?e:e.label}function W8(e){if(typeof e=="string"||typeof e=="number")return"";const t=[];return e.tone&&t.push(`cell-${e.tone}`),e.lead===!0&&t.push("lead"),e.highlight===!0&&t.push("hi"),t.join(" ")}function U8(e){return S(typeof e=="string"||typeof e=="number"?e:e.v)}function K8(e){const t=e.columns??[],n=e.rows??[],s=t.map((i,l)=>{const d=Fw(i);return`<th${d?` class="${d}"`:""}${_(`columns.${l}`)}>${S(H8(i))}</th>`}).join(""),o=n.map((i,l)=>{const d=(i??[]).map((u,p)=>{const h=t[p],m=[h!==void 0?Fw(h):"",W8(u)].filter(Boolean).join(" ");return`<td${m?` class="${m}"`:""}${_(`rows.${l}.${p}`)}>${U8(u)}</td>`}).join("");return`<tr${_(`rows.${l}`)}>${d}</tr>`}).join(""),r=e.note!==void 0?`<p class="tbl-note"${_("note")}>${S(e.note)}</p>`:"";return`<table class="pres-table"><thead><tr>${s}</tr></thead><tbody${he("rows")}>${o}</tbody></table>${r}`}var V8={done:"node-fill2",current:"node-accent",next:"node-dashed",future:"node-dashed"};function G8(e){const t=e.items??[],n=[];let s=`<div class="tl"${he("items")}>`;t.forEach((r,i)=>{const l=r.status??"future";n.includes(l)||n.push(l);const d=r.date!==void 0?`<div class="tl-date"${_(`items.${i}.date`)}>${S(r.date)}</div>`:"",u=r.desc!==void 0?`<div class="tl-desc"${_(`items.${i}.desc`)}>${S(r.desc)}</div>`:"",p=`<span class="tl-status tl-s-${l}"${r.status!==void 0?_(`items.${i}.status`):""}>${S(l)}</span>`;s+=`<div class="tl-item"${_(`items.${i}`)}${hn(i)}><span class="tl-dot ${l}"></span><div class="tl-head">${d}${p}</div><div class="tl-label"${_(`items.${i}.label`)}>${S(r.label)}</div>`+u+"</div>"});const o=n.map(r=>({swatch:V8[r]??"node-dashed",label:r}));return s+"</div>"+ot(o)}function $4(e){return e.slice(e.indexOf("#")+1)}function Y8(e){const t=e.role??"user",n=e.want??"…",s=e.soThat??"…",o=[];e.title!==void 0&&o.push(`<span class="story-title"${_("title")}>${S(e.title)}</span>`),(e.tags??[]).forEach((d,u)=>o.push(`<span class="story-chip"${_(`tags.${u}`)}>${S(d)}</span>`)),e.points!==void 0&&e.points!==null&&o.push(`<span class="story-chip pts"${_("points")}>${S(e.points)} pts</span>`),e.priority!==void 0&&o.push(`<span class="story-chip"${_("priority")}>Priority · ${S(e.priority)}</span>`);let r='<div class="story">';o.length>0&&(r+=`<div class="story-head">${o.join("")}</div>`),r+=`<div class="story-stmt">As a <b${_("role")}>${S(t)}</b>, I want to <b${_("want")}>${S(n)}</b>, so that <b${_("soThat")}>${S(s)}</b>.</div>`,r+="</div>";const i=e.criteria??[];i.length>0&&(r+='<div class="ac-title">Acceptance criteria</div>',i.forEach((d,u)=>{r+=`<div class="ac-item"${_(`criteria.${u}`)}><div class="gwt"><span class="k g">Given</span><span class="v"${_(`criteria.${u}.given`)}>${S(d.given??"")}</span><span class="k w">When</span><span class="v"${_(`criteria.${u}.when`)}>${S(d.when??"")}</span><span class="k t">Then</span><span class="v"${_(`criteria.${u}.then`)}>${S(d.then??"")}</span></div></div>`}));const l=e.links??[];return l.length>0&&(r+=`<div class="ac-title">Related</div><div class="links-row"${he("links")}>`,l.forEach((d,u)=>{const p=`<span class="lt">${S(d.mode??"")}</span>${S(d.label??"")}`;r+=d.ref!==void 0&&d.ref!==""?`<a class="link-chip" data-ref="${S(d.ref)}" href="#${S($4(d.ref))}"${_(`links.${u}`)}>${p}</a>`:`<span class="link-chip"${_(`links.${u}`)}>${p}</span>`}),r+="</div>"),r}function X8(e){const n=(e.blocks??[]).map((s,o)=>{const r=(s.type??"p").toLowerCase(),i=s.text??"";if(r==="h")return`<h3${_(`blocks.${o}`)}>${vo(i)}</h3>`;if(r==="quote")return`<blockquote${_(`blocks.${o}`)}>${vo(i)}</blockquote>`;if(r==="ul"){const l=(s.items??[]).map((d,u)=>`<li${_(`blocks.${o}.items.${u}`)}>${vo(d)}</li>`).join("");return`<ul${_(`blocks.${o}`)}${he(`blocks.${o}.items`)}>${l}</ul>`}if(r==="ol"){const l=(s.items??[]).map((d,u)=>`<li${_(`blocks.${o}.items.${u}`)}>${vo(d)}</li>`).join("");return`<ol${_(`blocks.${o}`)}${he(`blocks.${o}.items`)}>${l}</ol>`}return`<p${_(`blocks.${o}`)}>${vo(i)}</p>`}).join("");return`<div class="prose"${he("blocks")}>${n}</div>`}function Q8(e,t){if(e===void 0||e.length===0)return"";const n=e.map((s,o)=>`<span${_(`terms.${t}.avoid.${o}`)}>${S(s)}</span>`).join(", ");return` <span class="avoid"${he(`terms.${t}.avoid`)}>not: ${n}</span>`}function Z8(e){const n=(e.terms??[]).map((s,o)=>`<div class="row"${_(`terms.${o}`)}><dt${_(`terms.${o}.term`)}>${S(s.term)}</dt><dd${_(`terms.${o}.def`)}>${S(s.def)}${Q8(s.avoid,o)}</dd></div>`).join("");return`<div class="glossary"${he("terms")}>${n}</div>`}function J8(e){const t=e.prosLabel??"Pros",n=e.consLabel??"Cons",s=(e.pros??[]).map((r,i)=>`<div class="pc-item"${_(`pros.${i}`)}>${S(r)}</div>`).join(""),o=(e.cons??[]).map((r,i)=>`<div class="pc-item"${_(`cons.${i}`)}>${S(r)}</div>`).join("");return`<div class="pc"><div class="pc-col pro"${he("pros")}><div class="pc-head"${_("prosLabel")}>${S(t)}</div>`+s+`</div><div class="pc-col con"${he("cons")}><div class="pc-head"${_("consLabel")}>${S(n)}</div>`+o+"</div></div>"}function ez(e){const t=e.current??{},n=e.target??{},s=(t.items??[]).map((d,u)=>`<div class="ct-item"${_(`current.items.${u}`)}>${S(d)}</div>`).join(""),o=(n.items??[]).map((d,u)=>`<div class="ct-item"${_(`target.items.${u}`)}>${S(d)}</div>`).join(""),r=t.label??"Current",i=n.label??"Target",l=e.note!==void 0?`<div class="tbl-note"${_("note")}>${S(e.note)}</div>`:"";return`<div><div class="ct"><div class="ct-panel cur"${_("current")}${he("current.items")}><div class="ct-label"${_("current.label")}>${S(r)}</div>`+s+`</div><div class="ct-arrow">&rarr;</div><div class="ct-panel tgt"${_("target")}${he("target.items")}><div class="ct-label"${_("target.label")}>${S(i)}</div>`+o+"</div></div>"+l+"</div>"}var tz={up:"▲",down:"▼",flat:"—"};function nz(e){const n=(e.stats??[]).map((s,o)=>{const r=s.accent!==void 0?` style="border-top-color:${Fi(s.accent,"var(--accent)")}"`:"",i=s.delta!==void 0?`<div class="stat-delta ${s.trend??"flat"}">${tz[s.trend??"flat"]} ${S(s.delta)}</div>`:"";return`<div class="stat-card"${r}${_(`stats.${o}`)}><div class="stat-value"${_(`stats.${o}.value`)}>${S(s.value)}</div><div class="stat-label"${_(`stats.${o}.label`)}>${S(s.label)}</div>`+i+"</div>"}).join("");return`<div class="stat-row"${he("stats")}>${n}</div>`}var sz=new Set("const let var function return if else for while do switch case break continue class extends new await async import from export default try catch finally throw typeof instanceof void delete yield static public private protected readonly abstract implements interface type enum namespace def elif lambda pass with raise except none true false and or not is in self nil func struct map range defer chan select fallthrough echo fi done local require module package this super create table alter add drop select insert update delete into values where join group order by limit primary key foreign references not null default unique index on check constraint cascade returning begin commit rollback".split(/\s+/)),oz=new Set("string number boolean int integer float double bool char byte long short void object any unknown never bigint promise array list set optional uuid text varchar timestamptz timestamp date numeric decimal jsonb json serial bigserial smallint".split(/\s+/)),Wu=/(\/\*[\s\S]*?\*\/|\/\/[^\n]*|#[^\n]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)|(\b\d[\w.]*)|([A-Za-z_$][\w$]*)/g,rz=new Set(["md","markdown","mdx"]),iz=new Set(["text","txt","plain","plaintext","prompt","none"]);function fh(e,t){if(e.length===0)return"";const n=t?.trim().toLowerCase();if(n!==void 0&&rz.has(n))return az(String(e));if(n!==void 0&&iz.has(n))return S(String(e));const s=String(e);let o="",r=0;Wu.lastIndex=0;let i;for(;(i=Wu.exec(s))!==null;){i.index>r&&(o+=S(s.slice(r,i.index)));const l=i[0];if(i[1]!==void 0)o+=`<span class="com">${S(l)}</span>`;else if(i[2]!==void 0)o+=`<span class="str">${S(l)}</span>`;else if(i[3]!==void 0)o+=`<span class="num">${S(l)}</span>`;else{const d=l.toLowerCase();sz.has(d)?o+=`<span class="kw">${S(l)}</span>`:oz.has(d)?o+=`<span class="ty">${S(l)}</span>`:s[Wu.lastIndex]==="("?o+=`<span class="fn">${S(l)}</span>`:o+=S(l)}r=Wu.lastIndex}return r<s.length&&(o+=S(s.slice(r))),o}var Og=/(`[^`\n]+`)|(\*\*[^*\n]+\*\*|__[^_\n]+__)|(\*[^*\n]+\*|_[^_\n]+_)|(\[[^\]\n]+\]\([^)\n]+\))/g;function qw(e){let t="",n=0;Og.lastIndex=0;let s;for(;(s=Og.exec(e))!==null;){s.index>n&&(t+=S(e.slice(n,s.index)));const o=s[0];if(s[1]!==void 0)t+=`<span class="str">${S(o)}</span>`;else if(s[2]!==void 0)t+=`<span class="fn">${S(o)}</span>`;else if(s[3]!==void 0)t+=`<span class="ty">${S(o)}</span>`;else{const r=/^(\[[^\]]+\])(\([^)]+\))$/.exec(o);r!==null?t+=`<span class="fn">${S(r[1]??"")}</span><span class="com">${S(r[2]??"")}</span>`:t+=S(o)}n=Og.lastIndex}return n<e.length&&(t+=S(e.slice(n))),t}function az(e){const t=[];let n=!1;for(const s of e.split(`
2831
2831
  `))if(/^\s*(```|~~~)/.test(s))n=!n,t.push(`<span class="com">${S(s)}</span>`);else if(n)t.push(fh(s));else if(/^#{1,6}\s/.test(s))t.push(`<span class="kw">${S(s)}</span>`);else if(/^\s*>/.test(s))t.push(`<span class="com">${S(s)}</span>`);else if(/^\s*(-{3,}|={3,}|\*{3,})\s*$/.test(s))t.push(`<span class="com">${S(s)}</span>`);else{const o=/^(\s*)([-*+]|\d+\.)(\s+)(.*)$/.exec(s);o!==null?t.push(`${S(o[1]??"")}<span class="num">${S(o[2]??"")}</span>${o[3]??""}${qw(o[4]??"")}`):t.push(qw(s))}return t.join(`
2832
- `)}function az(e){return e.startsWith("+")?"df-add":e.startsWith("-")?"df-del":e.startsWith("@@")?"df-hunk":"df-ctx"}function lz(e){const t=(e.code??"").split(`
2833
- `).map(n=>`<span class="df-line ${az(n)}">${S(n===""?" ":n)}</span>`).join("");return`<div class="code-block diff-block"><div class="code-header"><span>${S(e.title??"")}</span><span${_("lang")}>${S(e.lang??"diff")}</span></div><pre class="diff-pre"${_("code")}>${t}</pre></div>`}function cz(e){return e.startsWith("$ ")?`<span class="tm-line tm-cmd"><span class="tm-prompt">$</span> <span class="tm-cmd-text">${S(e.slice(2))}</span></span>`:e.startsWith("# ")?`<span class="tm-line tm-comment">${S(e)}</span>`:`<span class="tm-line tm-out">${S(e===""?" ":e)}</span>`}function Hw(e){const t=(e.session??"").replace(/\n$/,"").split(`
2834
- `).map(cz).join("");return`<div class="code-block terminal-block"><div class="code-header"><span>${S(e.title??"terminal")}</span><span>shell</span></div><pre class="tm-pre"${_("session")}>${t}</pre></div>`}function dz(e){const t=new Set;if(e===void 0)return t;for(const n of e.split(",")){const s=n.trim(),o=/^(\d+)(?:\s*-\s*(\d+))?$/.exec(s);if(o===null)continue;const r=Number(o[1]),i=o[2]===void 0?r:Number(o[2]);if(!(r<1||i<r))for(let l=r;l<=i;l++)t.add(l)}return t}function uz(e){const t=e.split(`
2835
- `),n=[];let s;for(const o of t){let r=s===void 0?o:`<span class="${s}">${o}`;const i=/<span class="([a-z]+)">|<\/span>/g;let l;for(;(l=i.exec(o))!==null;)s=l[1]===void 0?void 0:l[1];s!==void 0&&(r+="</span>"),n.push(r)}return n}function Ww(e,t,n,s,o){const r=dz(o.highlight),i=uz(fh(n.replace(/\n$/,""),t)),l=i.map((g,v)=>`<span class="cl${r.has(v+1)?" cl-hl":""}">${g}
2836
- </span>`).join(""),d=["code-block","cb"];o.lines&&d.push("cb-lines"),o.wrap&&d.push("cb-wrap");const u=o.start+i.length-1,p=o.lines?` style="--code-start:${o.start-1};--code-gutter:${String(u).length}ch"`:"",h=o.eyebrow!==void 0&&e===""?`<span class="code-eyebrow"${_(s.title)}>${S(o.eyebrow)}</span>`:`<span${_(s.title)}>${S(e)}</span>`,m=o.caption!==void 0?`<div class="code-cap"${s.caption!==void 0?_(s.caption):""}>${S(o.caption)}</div>`:"";return`<div class="${d.join(" ")}"${s.self!==void 0?_(s.self):""}${p}><div class="code-header">`+h+`<span${_(s.lang)}>${S(t)}</span></div><pre${_(s.code)}>${l}</pre>`+m+"</div>"}var pz=["BEFORE","AFTER"];function fz(e){if(e.kind==="diff")return lz(e);if(e.kind==="terminal")return Hw(e);const t={lines:e.lines??!1,start:e.start??1,wrap:e.wrap??!1};if(e.blocks===void 0){if(e.code!==void 0)return Ww(e.title??"",e.lang??"",e.code,{title:"title",lang:"lang",code:"code",caption:"caption"},{...t,highlight:e.highlight,caption:e.caption});if(e.session!==void 0)return Hw(e)}const n=e.blocks??[],s=e.kind==="compare",o=s?2:e.cols??1,r=n.map((d,u)=>Ww(d.title??"",d.lang??"",d.code,{self:`blocks.${u}`,title:`blocks.${u}.title`,lang:`blocks.${u}.lang`,code:`blocks.${u}.code`,caption:`blocks.${u}.caption`},{...t,highlight:d.highlight,caption:d.caption,eyebrow:s?pz[u]??`#${u+1}`:void 0})).join(""),i=e.caption!==void 0?`<div class="code-cap code-cap-group"${_("caption")}>${S(e.caption)}</div>`:"",l=o>1?` class="code-grid" style="--code-cols:${o}"`:"";return`<div${he("blocks")}${l}>${r}</div>${i}`}function hz(e){const n=(e.items??[]).map((s,o)=>{const r=s.duration!==void 0?`<div class="agenda-dur"${_(`items.${o}.duration`)}>${S(s.duration)}</div>`:"",i=s.owner!==void 0?`<span class="agenda-owner"${_(`items.${o}.owner`)}>${S(s.owner)}</span>`:"",l=s.desc!==void 0?`<div class="agenda-desc"${_(`items.${o}.desc`)}>${S(s.desc)}</div>`:"",d=s.time!==void 0?`<div class="agenda-time"${_(`items.${o}.time`)}>${S(s.time)}</div>`:"";return`<div class="agenda-row"${_(`items.${o}`)}><div>${d}${r}</div><div><div class="agenda-title"><span${_(`items.${o}.title`)}>${S(s.title)}</span>${i}</div>`+l+"</div></div>"}).join("");return`<div class="agenda"${he("items")}>${n}</div>`}var S4={root:'fill="var(--accent-tint)" stroke="var(--accent)" stroke-width="1.5"',branch:'fill="var(--paper)" stroke="var(--ink)" stroke-width="1.5"',leaf:'fill="var(--paper-2)" stroke="var(--rule-solid)" stroke-width="1"'},Hp='fill="none" stroke="var(--muted)" stroke-width="1.25"';function mz(e){const t=e.nodes??[],n=new Map,s=new Map;for(const C of t)n.set(C.id,C),s.set(C.id,[]);const o=[];for(const C of t)C.parent!==void 0&&n.has(C.parent)?s.get(C.parent)?.push(C.id):o.push(C.id);const r=new Map,i=new Map,l=new Set;let d=0,u=0;const p=(C,D)=>{if(l.has(C))return;l.add(C),i.set(C,D),D>u&&(u=D);const F=s.get(C)??[];if(F.length===0)r.set(C,d),d+=1;else{for(const B of F)p(B,D+1);const U=r.get(F[0]??"")??0,X=r.get(F[F.length-1]??"")??0;r.set(C,(U+X)/2)}};for(const C of o)p(C,0);const h=168,m=50,g=16,v=56,y=24,b=18,E=18,$=C=>y+(i.get(C)??0)*(h+v),A=C=>b+(r.get(C)??0)*(m+g),T=y*2+(u+1)*h+u*v,N=b+Math.max(d,1)*(m+g)-g+E;let j=`<svg viewBox="0 0 ${T} ${N}" role="img"><title>Issue tree</title>`;for(const C of t){if(C.parent===void 0||!n.has(C.parent)||!r.has(C.id))continue;const D=$(C.parent)+h,F=A(C.parent)+m/2,U=$(C.id),X=A(C.id)+m/2,B=(D+U)/2;j+=`<path ${Hp} d="M ${D} ${F} H ${B} V ${X} H ${U}"/>`}const P=new Set;j+=`<g${he("nodes")}>`,t.forEach((C,D)=>{if(!r.has(C.id))return;const F=$(C.id),U=A(C.id),B=(i.get(C.id)??0)===0?"root":(s.get(C.id)??[]).length>0?"branch":"leaf";P.add(B);const te=`<rect x="${F}" y="${U}" width="${h}" height="${m}" rx="4" ${S4[B]}/>`,ee=B==="root"?F+h/2:F+14,H=B==="root"?"middle":"start",W=lt(C.label,B==="root"?22:20,C.note!==void 0?1:2),K=W.length===2?U+22:U+(C.note!==void 0?22:30),R=B==="root"?"t-name c-accent":"t-name",z=W.map((V,re)=>`<text x="${ee}" y="${K+re*14}" class="${R}" text-anchor="${H}">${S(V)}</text>`).join(""),Y=C.note!==void 0?`<text x="${ee}" y="${U+38}" class="t-sub c-muted" text-anchor="${H}">${S(C.note)}</text>`:"";j+=`<g${_(`nodes.${D}`)}>`+te+z+Y+"</g>"}),j+="</g>",j+="</svg>";const I=[];P.has("root")&&I.push({swatch:"node-accent",label:"question"}),P.has("branch")&&I.push({swatch:"node",label:"branch"}),P.has("leaf")&&I.push({swatch:"node-fill2",label:"testable claim"});const O=ot(I);return ct({tag:"MECE",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...O.length>0?{legendHtml:O}:{}},j)}var mo=148,fo=58,Wp=18,Rg=34,cc=mo+Wp,Dg=20,Uw=24,gz=6,Bg=26,vz=10;function zg(e,t){if(e.length<=t)return e;const n=e.slice(0,t-1),s=n.lastIndexOf(" ");return`${s>t/2?n.slice(0,s):n}…`}function yz(e){const t=e.nodes??[],n=new Map,s=new Map;for(const B of t)n.set(B.id,B),s.set(B.id,[]);const o=[];for(const B of t)B.parent!==void 0&&n.has(B.parent)?s.get(B.parent)?.push(B.id):o.push(B.id);const r=B=>(s.get(B)??[]).length===0,i=B=>{const te=s.get(B)??[],ee=te.filter(H=>r(H));if(!(ee.length<=gz))return{leaves:ee,branches:te.filter(H=>!r(H))}},l=mo*2+Bg+Wp,d=new Map,u=new Set,p=B=>{const te=d.get(B);if(te!==void 0)return te;if(u.has(B))return cc;u.add(B);const ee=i(B),H=s.get(B)??[],W=ee!==void 0?Math.max(cc,ee.branches.reduce((K,R)=>K+p(R),0)+l):H.length===0?cc:Math.max(cc,H.reduce((K,R)=>K+p(R),0));return u.delete(B),d.set(B,W),W},h=new Map,m=new Map,g=new Map,v=new Set,y=new Set,b=[];let E=0;const $=(B,te,ee,H)=>{if(v.has(B))return;v.add(B),g.set(B,H),m.set(B,ee),ee+fo>E&&(E=ee+fo);const W=s.get(B)??[];if(W.length===0){h.set(B,te+cc/2);return}const K=ee+fo+Rg,R=i(B);if(R!==void 0){const Q=R.branches.reduce((de,le)=>de+p(le),0)+l;let ne=te+(p(B)-Q)/2;for(const de of R.branches)$(de,ne,K,H+1),ne+=p(de);const Z=ne+(l-Wp)/2;R.leaves.forEach((de,le)=>{if(v.has(de))return;v.add(de),g.set(de,H+1),y.add(de);const J=le%2,ue=Math.floor(le/2),ve=K+ue*(fo+vz);m.set(de,ve),ve+fo>E&&(E=ve+fo),h.set(de,J===0?Z-Bg/2-mo/2:Z+Bg/2+mo/2)}),b.push({parent:B,trunkX:Z});const q=R.branches.length>0?h.get(R.branches[0]??"")??Z:Z;h.set(B,(q+Z)/2);return}const z=W.reduce((Q,ne)=>Q+p(ne),0);let Y=te+(p(B)-z)/2;for(const Q of W)$(Q,Y,K,H+1),Y+=p(Q);const V=h.get(W[0]??"")??0,re=h.get(W[W.length-1]??"")??0;h.set(B,(V+re)/2)},A=16,T=16;let N=A;for(const B of o)$(B,N,T,0),N+=p(B);const j=Math.max(N-Wp+A,A*2+mo),P=E+T,I=B=>Math.round(((h.get(B)??0)-mo/2)*10)/10,O=B=>m.get(B)??T;let C=`<svg viewBox="0 0 ${j} ${P}" role="img"><title>Org chart</title>`;for(const B of t){if(B.parent===void 0||!n.has(B.parent)||!h.has(B.id)||y.has(B.id))continue;const te=Math.round((h.get(B.parent)??0)*10)/10,ee=O(B.parent)+fo,H=Math.round((h.get(B.id)??0)*10)/10,W=O(B.id),K=ee+Rg/2;C+=`<path ${Hp} d="M ${te} ${ee} V ${K} H ${H} V ${W}"/>`}for(const B of b){const te=(s.get(B.parent)??[]).filter(z=>y.has(z)),ee=O(B.parent)+fo,H=Math.round(B.trunkX*10)/10;let W=ee,K="";for(const z of te){const Y=O(z)+fo/2;Y>W&&(W=Y);const V=h.get(z)??0,re=Math.round((V<B.trunkX?V+mo/2:V-mo/2)*10)/10;K+=`<path ${Hp} d="M ${H} ${Y} H ${re}"/>`}const R=Math.round((h.get(B.parent)??0)*10)/10;C+=`<path ${Hp} d="M ${R} ${ee} V ${ee+Rg/2} H ${H} V ${W}"/>`+K}let D=!1,F=!1;C+=`<g${he("nodes")}>`,t.forEach((B,te)=>{if(!h.has(B.id))return;const ee=I(B.id),H=O(B.id),W=(g.get(B.id)??0)===0;W?D=!0:F=!0;const K=B.role!==void 0&&B.role!=="",z=lt(B.label,Dg,2).map(ue=>zg(ue,Dg+2)),Y=z.join(" ").length<String(B.label).trim().replace(/\s+/g," ").length;if(Y&&z.length>0){const ue=z[z.length-1]??"";z[z.length-1]=ue.endsWith("…")?ue:zg(`${ue}…`,Dg+2)}const V=z.length===2,re=K?V?H+19:H+25:V?H+25:H+33,Q=V?H+49:H+43,ne=ee+mo/2,Z=W?"t-name c-accent":"t-name",q=z.map((ue,ve)=>`<text x="${ne}" y="${re+ve*14}" class="${Z}" text-anchor="middle"${ve===0?_(`nodes.${te}.label`):""}>${S(ue)}</text>`).join(""),de=K?`<text x="${ne}" y="${Q}" class="t-sub c-muted" text-anchor="middle"${_(`nodes.${te}.role`)}>${S(zg(String(B.role),Uw))}</text>`:"",le=K&&String(B.role).length>Uw,J=Y||le?`<title>${S(K?`${B.label} — ${String(B.role)}`:B.label)}</title>`:"";C+=`<g${_(`nodes.${te}`)}><rect x="${ee}" y="${H}" width="${mo}" height="${fo}" rx="4" ${S4[W?"root":"branch"]}/>`+J+q+de+"</g>"}),C+="</g>",C+="</svg>";const U=[];D&&U.push({swatch:"node-accent",label:"head"}),F&&U.push({swatch:"node",label:"reports to the card above"});const X=ot(U);return ct({tag:"ORG",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...X.length>0?{legendHtml:X}:{}},C)}function xz(e,t){const n=Math.round(e*100)/100,s=(Number.isInteger(n),String(n));return t!==void 0?`${s}${t}`:s}function kz(e){if(e.variant==="issue")return mz(e);if(e.variant==="org")return yz(e);const t=e.nodes??[],n=new Map,s=new Map,o=new Map;t.forEach((p,h)=>o.set(p,h));for(const p of t)n.set(p.id,p),s.set(p.id,[]);const r=[];for(const p of t)p.parent!==void 0&&n.has(p.parent)?s.get(p.parent)?.push(p.id):r.push(p.id);const i=[],l=new Set,d=(p,h,m)=>{if(l.has(p))return;l.add(p);const g=n.get(p);if(g===void 0)return;const v=s.get(p)??[];i.push({node:g,depth:h,branch:v.length>0,...m!==void 0?{parent:m}:{}});for(const y of v)d(y,h+1,g)};for(const p of r)d(p,0);const u=i.map(p=>{const h=o.get(p.node)??0,m=p.branch?" branch":"",g=p.branch?"▸":"—",v=p.node.note!==void 0?`<span class="tnote"${_(`nodes.${h}.note`)}>${S(p.node.note)}</span>`:"";let y="";if(typeof p.node.value=="number"){const b=xz(p.node.value,e.unit),E=p.parent?.value,$=typeof E=="number"&&E>0?`<span class="tshare">${Math.round(p.node.value/E*100)}%</span>`:"";y=`<span class="tvalue"${_(`nodes.${h}.value`)}>${S(b)}</span>${$}`}return`<div class="tree-row${m}" style="padding-left:${p.depth*22}px"${_(`nodes.${h}`)}><span class="tw">${g}</span><span class="tlabel"${_(`nodes.${h}.label`)}>${S(p.node.label)}</span>`+v+y+"</div>"}).join("");return`<div class="tree-list"${he("nodes")}>${u}</div>`}var Kw=["var(--navy)","var(--blue)","var(--teal)","var(--positive)","var(--purple)","var(--highlight)"];function bz(e){const t=e.levels??[],n=Math.max(t.length,1),s=560,o=16,r=Math.min(78,Math.floor(300/n)),i=4,l=s/2,d=16,u=480,p=250,h=o+n*(r+i)+d,m=v=>p+(u-p)*(v/n),g=t.map((v,y)=>{const b=o+y*(r+i),E=m(y),$=m(y+1),A=Kw[y%Kw.length]??"var(--navy)",T=v.desc!==void 0,N=Math.max(8,Math.floor((Math.min(E,$)-20)/7.3)),j=lt(v.label,N,T?1:2),P=b+r/2-(j.length-1)*7+(T?-4:0),I=j.map((C,D)=>`<text x="${l}" y="${P+D*14}" class="pyr-label">${S(C)}</text>`).join(""),O=T?`<text x="${l}" y="${b+r/2+14}" class="pyr-desc"${_(`levels.${y}.desc`)}>${S(v.desc??"")}</text>`:"";return`<g${_(`levels.${y}`)}><polygon points="${l-E/2},${b} ${l+E/2},${b} ${l+$/2},${b+r} ${l-$/2},${b+r}" fill="${A}"/>`+I+O+"</g>"}).join("");return`<svg viewBox="0 0 ${s} ${h}" role="img"><title>Pyramid</title><g${he("levels")}>${g}</g></svg>`}function Fs(e,t,n=0,s=0){const o=n*10,r={x:e.x+e.w/2,y:e.y+e.h/2},i={x:t.x+t.w/2,y:t.y+t.h/2},l=i.x-r.x,d=i.y-r.y;if(Math.abs(l)>=Math.abs(d)){const v=l>=0?e.x+e.w:e.x,y=l>=0?t.x:t.x+t.w,b=r.y+o,E=i.y+o+s,$=(v+y)/2;return{d:`M ${v} ${b} H ${$} V ${E} H ${y}`,lx:$,ly:(b+E)/2}}const u=d>=0?e.y+e.h:e.y,p=d>=0?t.y:t.y+t.h,h=r.x+o,m=i.x+o+s,g=(u+p)/2;return{d:`M ${h} ${u} V ${g} H ${m} V ${p}`,lx:(h+m)/2,ly:g}}function qs(e){const t=new Set(e.map(n=>`${n.from}\0${n.to}`));return e.map(n=>n.from===n.to||!t.has(`${n.to}\0${n.from}`)?0:n.from<n.to?-1:1)}var wz=8,$z=6;function Hs(e,t){const n=new Map;e.forEach((o,r)=>{if(o.from===o.to)return;const i=t(o.from),l=t(o.to);if(i===void 0||l===void 0)return;const d=l.x+l.w/2-(i.x+i.w/2),u=l.y+l.h/2-(i.y+i.h/2),p=Math.abs(d)>=Math.abs(u),h=p?d>=0?"L":"R":u>=0?"T":"B",m=`${o.to}\0${h}`,g=n.get(m)??{members:[],span:p?l.h:l.w};g.members.push({i:r,from:o.from}),n.set(m,g)});const s=e.map(()=>0);for(const o of n.values()){const r=o.members.length;if(r<2)continue;const i=[...o.members].sort((u,p)=>u.from<p.from?-1:u.from>p.from?1:u.i-p.i),l=Math.max(0,o.span/2-$z),d=Math.min(wz,l/((r-1)/2));i.forEach((u,p)=>{s[u.i]=Math.round((p-(r-1)/2)*d*100)/100})}return s}function Sz(e,t,n=!1){if(t===void 0||t==="")return"";const s=Math.max(26,t.length*5.4),o=n?" err":"";return`<g><rect x="${e.lx-s/2}" y="${e.ly-9}" width="${s}" height="18" rx="9" fill="var(--white)" stroke="var(--rule)"${ut}/><text x="${e.lx}" y="${e.ly+3}" class="edge-label${o}">${S(t)}</text></g>`}function x0(e,t,n="muted"){if(t===void 0||t==="")return"";const s=Math.round(t.length*6+8),o=n==="error"?" c-negative":n==="accent"?" c-accent":"";return`<g><rect x="${e.lx-s/2}" y="${e.ly-7}" width="${s}" height="14" fill="var(--paper)"/><text x="${e.lx}" y="${e.ly+3.5}" class="t-arrow${o}" text-anchor="middle">${S(t)}</text></g>`}function xf(e,t,n=!1,s=!1){if(s){const i=n?" c-negative":"";return`<g><circle cx="${e.lx}" cy="${e.ly}" r="8" fill="var(--paper)" stroke="${n?"var(--negative)":"var(--muted)"}" stroke-width="1"/><text x="${e.lx}" y="${e.ly+3}" text-anchor="middle" class="t-badge${i}">${t}</text></g>`}const o=n?"var(--negative)":"var(--charcoal)",r=n?"var(--negative)":"var(--charcoal)";return`<g><circle cx="${e.lx}" cy="${e.ly}" r="9.5" fill="var(--white)" stroke="${o}" stroke-width="1.2"/><text x="${e.lx}" y="${e.ly+3.5}" text-anchor="middle" style="font-family:var(--font-mono);font-size:10px;font-weight:700" fill="${r}">${t}</text></g>`}function E4(e){return e.length===0?"":`<div class="edge-steps">${e.map((n,s)=>`<span class="edge-step${n.err===!0?" err":""}"${n.path!==void 0?_(n.path):""}${n.reveal!==void 0?hn(n.reveal):""}><b>${s+1}</b>${S(n.label)}</span>`).join("")}</div>`}var Uu=13;function Uy(e,t,n){let s=e,o=t,r=!1;for(let i=0;i<2;i++){let l=!1;for(const d of n){const u=d.x-Uu,p=d.y-Uu,h=d.x+d.w+Uu,m=d.y+d.h+Uu;if(s<=u||s>=h||o<=p||o>=m)continue;const g=s-u,v=h-s,y=o-p,b=m-o,E=Math.min(g,v,y,b);E===g?s=u:E===v?s=h:E===y?o=p:o=m,l=!0,r=!0}if(!l)break}return r?{lx:Math.round(s),ly:Math.round(o)}:{lx:e,ly:t}}function Ws(e,t=[],n={}){const o=e.filter(d=>d.label!==void 0&&d.label!=="").length>=4,r=[],i=[],l=[...t];for(const d of e){if(d.label===void 0||d.label==="")continue;const u=d.err===!0,p=Uy(d.lx,d.ly,o?l:t),h=_(d.path)+(d.reveal!==void 0?hn(d.reveal):"");if(o)l.push({x:p.lx-6,y:p.ly-6,w:12,h:12}),i.push({label:d.label,path:d.path,...u?{err:!0}:{},...d.reveal!==void 0?{reveal:d.reveal}:{}}),r.push(`<g${h}>${xf(p,i.length,u,n.skin===!0)}</g>`);else if(n.skin===!0){const m=u?"error":d.accent===!0?"accent":"muted";r.push(`<g${h}>${x0(p,d.label,m)}</g>`)}else r.push(`<g${h}>${Sz(p,d.label,u)}</g>`)}return{overlay:r.join(""),legend:E4(i)}}var Gn={padX:38,padTop:52,padBot:36};function wd(e){return{cols:Math.max(1,...e.map(t=>t.col+(t.cols??1)-1)),rows:Math.max(1,...e.map(t=>t.row+(t.rows??1)-1))}}function Ez(e,t){if(e===t)return!1;const n=e.col+(e.cols??1),s=e.row+(e.rows??1),o=t.col+(t.cols??1),r=t.row+(t.rows??1),i=e.col>=t.col&&e.row>=t.row&&n<=o&&s<=r,l=(t.cols??1)*(t.rows??1)>(e.cols??1)*(e.rows??1);return i&&l}var Ku={x:4,y:8,w:8,h:12},Fr={x:4,y:10,w:8,h:14};function Ky(e){const t=new Map;for(const p of e)p.id!==void 0&&!t.has(p.id)&&t.set(p.id,p);const n=p=>{const h=p.parent!==void 0?t.get(p.parent):void 0;return h===p?void 0:h},s=new Map,o=p=>{const h=e.filter(m=>Ez(p,m)).length;return{depth:h,inset:{x:h*12,y:h*11,w:h*24,h:h*17},declared:!1}},r=(p,h)=>{const m=s.get(p);if(m!==void 0)return m;const g=n(p);let v;if(g===void 0||h.has(g))v=o(p);else{const y=r(g,new Set([...h,p]));v={depth:y.depth+1,inset:{x:y.inset.x+Ku.x,y:y.inset.y+Ku.y,w:y.inset.w+Ku.w,h:y.inset.h+Ku.h},declared:!0}}return s.set(p,v),v};for(const p of e)r(p,new Set);const i=new Map;for(const p of e){const h=n(p);h!==void 0&&s.get(p)?.declared===!0&&i.set(h,[...i.get(h)??[],p])}const l=new Map,d=(p,h)=>{const m=l.get(p);if(m!==void 0)return m;const g=(i.get(p)??[]).filter(y=>!h.has(y)),v=g.length===0?0:1+Math.max(...g.map(y=>d(y,new Set([...h,p]))));return l.set(p,v),v},u=new Map;for(const p of e){const h=s.get(p)??o(p),m=d(p,new Set);u.set(p,{...h,height:m,inset:{x:h.inset.x-Fr.x*m,y:h.inset.y-Fr.y*m,w:h.inset.w-Fr.w*m,h:h.inset.h-Fr.h*m}})}return u}function Mz(e){return e.some(t=>t.parent!==void 0)?Ky(e):new Map}function Yi(e){if(!e.some(n=>n.parent!==void 0))return{padX:0,padTop:0,padBot:0};const t=Math.max(0,...[...Ky(e).values()].map(n=>n.height));return{padX:Fr.x*t,padTop:Fr.y*t,padBot:(Fr.h-Fr.y)*t}}function xl(e,t){const n=d=>({x:t.xOf(d.col)-28,y:t.yOf(d.row)-38,w:(d.cols??1)*t.cellW+((d.cols??1)-1)*t.gapX+56,h:(d.rows??1)*t.cellH+((d.rows??1)-1)*t.gapY+66}),s=Ky(e),o=e.some(d=>d.parent!==void 0),r=d=>(d.cols??1)*(d.rows??1),i=e.map((d,u)=>({g:d,gi:u})).sort((d,u)=>o?(s.get(d.g)?.depth??0)-(s.get(u.g)?.depth??0)||r(u.g)-r(d.g)||d.gi-u.gi:r(u.g)-r(d.g));let l=`<g${he("groups")}>`;for(const{g:d,gi:u}of i){const p=n(d),h=Fi(d.color,"var(--slate)"),m=s.get(d)??{depth:0,inset:{x:0,y:0,w:0,h:0},declared:!1},g=m.depth,v={x:p.x+m.inset.x,y:p.y+m.inset.y,w:p.w-m.inset.w,h:p.h-m.inset.h},y=m.declared?g%2===1:g>0;if(t.skin===!0){const E=Fi(d.color,""),$=E.length>0?`color-mix(in srgb, ${E} 62%, var(--ink))`:"",A=E.length>0?$:"var(--rule-solid)",T=E.length>0?$:"var(--soft)",N=y?`<text x="${v.x+v.w-12}" y="${v.y+16}" class="t-eyebrow" fill="${T}" text-anchor="end">${S(d.label)}</text>`:`<text x="${v.x+12}" y="${v.y+16}" class="t-eyebrow" fill="${T}">${S(d.label)}</text>`;l+=`<g${_(`groups.${u}`)}><rect x="${v.x}" y="${v.y}" width="${v.w}" height="${v.h}" rx="6" fill="var(--paper-2)" fill-opacity="0.6" stroke="${A}" stroke-width="1"/>`+N+"</g>";continue}const b=y?`<text x="${v.x+v.w-16}" y="${v.y+19}" class="grp-label" fill="${h}" text-anchor="end">${S(d.label)}</text>`:`<text x="${v.x+16}" y="${v.y+19}" class="grp-label" fill="${h}">${S(d.label)}</text>`;l+=`<g${_(`groups.${u}`)}><rect x="${v.x}" y="${v.y}" width="${v.w}" height="${v.h}" rx="12" fill="none" stroke="${h}" stroke-opacity="0.6" stroke-width="1.3" stroke-dasharray="7 5"/>`+b+"</g>"}return l+="</g>",l}function tr(e){return` data-grid="1"${e.quick?' data-grid-auto="1"':""} data-cols="${e.cols}" data-rows="${e.rows}" data-cell-w="${e.cellW}" data-cell-h="${e.cellH}" data-gap-x="${e.gapX}" data-gap-y="${e.gapY}" data-pad-x="${e.padX}" data-pad-top="${e.padTop}"`}function Mo(e,t,n){return` data-col="${e}" data-row="${t}"${n!==void 0?` data-w="${n}"`:""}`}var Az="box",Cz={function:"M3 2 H5 L10.5 12 M7.6 7 L3.5 12",bucket:"M2 3.5 a5 1.6 0 0 0 10 0 a5 1.6 0 0 0 -10 0 M2 3.5 L3.5 12.5 H10.5 L12 3.5",queue:"M3 1.5 V12.5 M7 1.5 V12.5 M11 1.5 V12.5",topic:"M1.5 7 H5.5 M5.5 7 L11.5 2.5 M5.5 7 H12 M5.5 7 L11.5 11.5",cache:"M1.5 4.5 L7 2 L12.5 4.5 L7 7 Z M1.5 8 L7 10.5 L12.5 8 M1.5 11 L7 13.5 L12.5 11",db:"M1.5 3 a5.5 2.2 0 0 0 11 0 a5.5 2.2 0 0 0 -11 0 V11 a5.5 2.2 0 0 0 11 0 V3",cdn:"M3.5 12 a3 3 0 0 1 0.3 -6 a4 4 0 0 1 7.6 1 a2.5 2.5 0 0 1 0.6 5 Z",lb:"M1.5 7 H5 M5 7 L9 3 H12.5 M5 7 H12.5 M5 7 L9 11 H12.5",gateway:"M2 1.5 L7 7 L2 12.5 M7.5 1.5 L12.5 7 L7.5 12.5",pod:"M7 1.2 L12.2 4.1 V9.9 L7 12.8 L1.8 9.9 V4.1 Z M5.2 7 a1.8 1.8 0 1 0 3.6 0 a1.8 1.8 0 1 0 -3.6 0",cluster:"M1.5 7 a5.5 5.5 0 1 0 11 0 a5.5 5.5 0 1 0 -11 0 M7 1.5 V4.5 M7 9.5 V12.5 M1.5 7 H4.5 M9.5 7 H12.5",user:"M4.5 4.5 a2.5 2.5 0 1 0 5 0 a2.5 2.5 0 1 0 -5 0 M2.5 13 a4.5 4.5 0 0 1 9 0",browser:"M1.5 2.5 H12.5 V11.5 H1.5 Z M1.5 5.5 H12.5",mobile:"M4 1.5 H10 a1 1 0 0 1 1 1 V11.5 a1 1 0 0 1 -1 1 H4 a1 1 0 0 1 -1 -1 V2.5 a1 1 0 0 1 1 -1 Z M6 11 H8",cron:"M1.5 7 a5.5 5.5 0 1 0 11 0 a5.5 5.5 0 1 0 -11 0 M7 3.5 V7 L9.5 8.5",ml:"M7 1.5 L8.4 5.6 L12.5 7 L8.4 8.4 L7 12.5 L5.6 8.4 L1.5 7 L5.6 5.6 Z",secret:"M3 6.5 H11 V13 H3 Z M4.5 6.5 V4.5 a2.5 2.5 0 0 1 5 0 V6.5",config:"M1.5 3.5 H12.5 M1.5 7 H12.5 M1.5 10.5 H12.5 M4.5 2 V5 M9.5 5.5 V8.5 M6 9 V12",deployment:"M1.5 5 H9 V12.5 H1.5 Z M4 5 V2.5 H11.5 V10 H9",ingress:"M1.5 7 H8 M5.5 4.5 L8 7 L5.5 9.5 M10 1.5 H12.5 V12.5 H10",node:"M2 2 H12 V6 H2 Z M2 8 H12 V12 H2 Z M4.5 4 H6.5 M4.5 10 H6.5",namespace:"M1.5 3.5 H5.5 L7 5 H12.5 V12 H1.5 Z",box:"M2 2 H12 V12 H2 Z"},M4={function:"function",lambda:"function",bucket:"bucket",s3:"bucket",blob:"bucket",object:"bucket",queue:"queue",sqs:"queue",mq:"queue",broker:"queue",rabbitmq:"queue",topic:"topic",sns:"topic",kafka:"topic",kinesis:"topic",stream:"topic",cache:"cache",redis:"cache",memcached:"cache",db:"db",database:"db",store:"db",postgres:"db",mysql:"db",mongo:"db",mongodb:"db",dynamo:"db",cdn:"cdn",lb:"lb",gateway:"gateway",proxy:"gateway",pod:"pod",cluster:"cluster",user:"user",person:"user",actor:"user",browser:"browser",web:"browser",mobile:"mobile",cron:"cron",scheduler:"cron",job:"cron",cronjob:"cron",ml:"ml",model:"ml",llm:"ml",agent:"ml",ai:"ml",secret:"secret",secrets:"secret",vault:"secret",kms:"secret",config:"config",configmap:"config",settings:"config",deployment:"deployment",ingress:"ingress",node:"node",vm:"node",server:"node",host:"node",namespace:"namespace"};function Nz(e){return M4[(e??"").trim().toLowerCase()]??Az}function Tz(e){return(e??"").trim().toLowerCase()in M4}function _z(e,t,n,s="var(--muted)"){return`<path d="${Cz[Nz(e)]}" transform="translate(${t} ${n})" fill="none" stroke="${s}" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round"/>`}var Lz=["client","service","microservice","compute","container","data","store","db","database","postgres","mysql","mongo","mongodb","dynamo","bucket","blob","object","s3","queue","mq","broker","sqs","rabbitmq","cache","redis","memcached","gateway","lb","proxy","function","lambda","cdn","external","producer","topic","consumer","context","firewall","waf","shield","dns","auth","identity","idp","iam","oauth","sso","monitor","observability","metrics","logs","tracing","apm","scheduler","cron","job","stream","kafka","kinesis","warehouse","lake","analytics","bi","search","index","elasticsearch","opensearch","registry","ci","cicd","pipeline","git","repo","scm","device","iot","email","sms","config","settings","ml","model","llm","agent","ai","user","person","actor","browser","web","mobile","vm","server","host","secrets","vault","kms","notification","webhook","worker","etl","shard","shards","sharded","replica","replicas","replicaset","users","crowd","region","geo","globe","deployment","pod","ingress","configmap","secret","cronjob","node","namespace","cluster","sns"],A4={},mt=(e,t)=>{for(const n of e)A4[n]=t},Zt=e=>({chip:e,primary:!0,fill:"paper",dashed:!1}),Tn=e=>({chip:e,primary:!1,fill:"paper-2",dashed:!1}),kl=e=>({chip:e,primary:!0,fill:"paper",dashed:!0});mt(["client","user","person","actor","users","crowd","browser","web","mobile","device","iot"],Zt("CLIENT"));mt(["service","microservice","compute","container","worker","etl"],Zt("SVC"));mt(["data"],Zt("DATA"));mt(["store","db","database","postgres","mysql","mongo","mongodb","dynamo"],Tn("DB"));mt(["shard","shards","sharded","replica","replicas","replicaset"],Tn("DB"));mt(["bucket","blob","object","s3"],Tn("BUCKET"));mt(["warehouse","lake"],Tn("WAREHOUSE"));mt(["queue","mq","broker","sqs","rabbitmq"],Tn("QUEUE"));mt(["topic"],Tn("TOPIC"));mt(["stream","kafka","kinesis"],Tn("BUS"));mt(["cache","redis","memcached"],Tn("CACHE"));mt(["search","index","elasticsearch","opensearch"],Tn("SEARCH"));mt(["registry"],Tn("REGISTRY"));mt(["gateway","proxy"],Zt("GATEWAY"));mt(["lb"],Zt("LB"));mt(["function","lambda"],Zt("FN"));mt(["cdn"],kl("EDGE"));mt(["external"],kl("EXT"));mt(["producer"],Zt("PRODUCER"));mt(["consumer"],Zt("CONSUMER"));mt(["context"],Zt("CONTEXT"));mt(["firewall","waf","shield"],Zt("WAF"));mt(["dns"],kl("DNS"));mt(["auth","identity","idp","iam","oauth","sso"],Zt("AUTH"));mt(["monitor","observability","metrics","logs","tracing","apm"],Zt("OBS"));mt(["scheduler","cron","job"],Zt("CRON"));mt(["analytics","bi"],Zt("ANALYTICS"));mt(["ci","cicd","pipeline"],Zt("CI"));mt(["git","repo","scm"],Tn("GIT"));mt(["email","sms"],kl("EMAIL"));mt(["config","settings"],Tn("CONFIG"));mt(["ml","model","llm","agent","ai"],Zt("AI"));mt(["vm","server","host"],Zt("HOST"));mt(["secrets","vault","kms"],Tn("SECRETS"));mt(["notification","webhook"],kl("WEBHOOK"));mt(["region","geo","globe"],kl("REGION"));mt(["deployment"],Zt("DEPLOY"));mt(["pod"],Zt("POD"));mt(["ingress"],Zt("INGRESS"));mt(["configmap"],Tn("CONFIG"));mt(["secret"],Tn("SECRETS"));mt(["cronjob"],Zt("CRON"));mt(["node"],Zt("NODE"));mt(["namespace"],Tn("NS"));mt(["cluster"],Zt("CLUSTER"));mt(["sns"],Tn("TOPIC"));function Vo(e){const t=(e??"").trim().toLowerCase();return t===""?{chip:"",primary:!0,fill:"paper",dashed:!1}:A4[t]??Zt(t.toUpperCase())}function Iz(e,t=!1){return t?"var(--accent-tint)":e.fill==="paper-2"?"var(--paper-2)":"var(--paper)"}function al(e,t,n,s){const o=(e??"").toLowerCase();if(o==="store"||o==="db"||o==="database"||o==="postgres"||o==="mysql"||o==="mongo"||o==="mongodb"||o==="dynamo")return`<g stroke="${s}" stroke-width="1.3" fill="none"><ellipse cx="${t+8}" cy="${n+3}" rx="7" ry="3"/><path d="M${t+1} ${n+3} V ${n+13}"/><path d="M${t+15} ${n+3} V ${n+13}"/><path d="M${t+1} ${n+13} a 7 3 0 0 0 14 0"/></g>`;if(o==="bucket"||o==="blob"||o==="object"||o==="s3")return`<g stroke="${s}" stroke-width="1.3" fill="none"><ellipse cx="${t+8}" cy="${n+3}" rx="7" ry="2.5"/><path d="M${t+1.5} ${n+3} L ${t+3.5} ${n+14} L ${t+12.5} ${n+14} L ${t+14.5} ${n+3}"/></g>`;if(o==="queue"||o==="topic"||o==="mq"||o==="broker"||o==="sqs"||o==="rabbitmq")return`<g stroke="${s}" stroke-width="1.6"><path d="M${t+2} ${n+1} V ${n+14}"/><path d="M${t+8} ${n+1} V ${n+14}"/><path d="M${t+14} ${n+1} V ${n+14}"/></g>`;if(o==="firewall"||o==="waf"||o==="shield")return`<path d="M${t+8} ${n} L ${t+15} ${n+3} V ${n+9} Q ${t+15} ${n+14} ${t+8} ${n+16} Q ${t+1} ${n+14} ${t+1} ${n+9} V ${n+3} Z" fill="none" stroke="${s}" stroke-width="1.3"/>`;if(o==="dns")return`<g stroke="${s}" stroke-width="1.2" fill="none"><circle cx="${t+8}" cy="${n+8}" r="7"/><ellipse cx="${t+8}" cy="${n+8}" rx="3" ry="7"/><path d="M${t+1.5} ${n+8} H ${t+14.5}"/></g>`;if(o==="auth"||o==="identity"||o==="idp"||o==="iam"||o==="oauth"||o==="sso")return`<g stroke="${s}" stroke-width="1.4" fill="none"><circle cx="${t+5}" cy="${n+8}" r="3.5"/><path d="M${t+8.5} ${n+8} H ${t+15} M${t+12.5} ${n+8} V ${n+11.5} M${t+15} ${n+8} V ${n+10.5}"/></g>`;if(o==="monitor"||o==="observability"||o==="metrics"||o==="logs"||o==="tracing"||o==="apm")return`<path d="M${t} ${n+9} H ${t+4} L ${t+6.5} ${n+3} L ${t+9.5} ${n+13} L ${t+12} ${n+9} H ${t+16}" fill="none" stroke="${s}" stroke-width="1.5" stroke-linejoin="round"/>`;if(o==="scheduler"||o==="cron"||o==="job")return`<g stroke="${s}" stroke-width="1.3" fill="none"><circle cx="${t+8}" cy="${n+8}" r="7"/><path d="M${t+8} ${n+4} V ${n+8} L ${t+11.5} ${n+10}"/></g>`;if(o==="stream"||o==="kafka"||o==="kinesis"){const r=i=>`<path d="M${t+1} ${n+4+i} q 3.5 -3 7 0 t 7 0" fill="none" stroke="${s}" stroke-width="1.4"/>`;return`<g>${r(0)}${r(4.5)}${r(9)}</g>`}if(o==="warehouse"||o==="lake")return`<g stroke="${s}" stroke-width="1.3" fill="none"><ellipse cx="${t+8}" cy="${n+3}" rx="7" ry="3"/><path d="M${t+1} ${n+3} V ${n+13}"/><path d="M${t+15} ${n+3} V ${n+13}"/><path d="M${t+1} ${n+8} a 7 3 0 0 0 14 0"/><path d="M${t+1} ${n+13} a 7 3 0 0 0 14 0"/></g>`;if(o==="search"||o==="index")return`<g stroke="${s}" stroke-width="1.4" fill="none"><circle cx="${t+6.5}" cy="${n+6.5}" r="5"/><path d="M${t+10.5} ${n+10.5} L ${t+15} ${n+15}"/></g>`;if(o==="ml"||o==="model"||o==="llm"||o==="agent"||o==="ai")return`<path d="M${t+8} ${n+1} L ${t+9.8} ${n+6.2} L ${t+15} ${n+8} L ${t+9.8} ${n+9.8} L ${t+8} ${n+15} L ${t+6.2} ${n+9.8} L ${t+1} ${n+8} L ${t+6.2} ${n+6.2} Z" fill="${s}"/>`;if(o==="user"||o==="person"||o==="actor")return`<g fill="${s}"><circle cx="${t+8}" cy="${n+4.5}" r="3.5"/><path d="M ${t+2} ${n+15} a 6 6.5 0 0 1 12 0 z"/></g>`;if(o==="browser"||o==="web")return`<g stroke="${s}" stroke-width="1.3" fill="none"><rect x="${t+1}" y="${n+2}" width="14" height="12" rx="2"/><path d="M${t+1} ${n+6} H ${t+15}"/></g>`;if(o==="mobile")return`<g stroke="${s}" stroke-width="1.3" fill="none"><rect x="${t+4}" y="${n+1}" width="8" height="14" rx="2"/><path d="M${t+7} ${n+12.5} H ${t+9}"/></g>`;if(o==="vm"||o==="server"||o==="host")return`<g stroke="${s}" stroke-width="1.3" fill="none"><rect x="${t+2}" y="${n+2}" width="12" height="5" rx="1.2"/><rect x="${t+2}" y="${n+9}" width="12" height="5" rx="1.2"/><path d="M${t+4.5} ${n+4.5} H ${t+7} M${t+4.5} ${n+11.5} H ${t+7}"/></g>`;if(o==="secrets"||o==="vault"||o==="kms")return`<g stroke="${s}" stroke-width="1.3" fill="none"><rect x="${t+3}" y="${n+7}" width="10" height="8" rx="1.5"/><path d="M${t+5} ${n+7} V ${n+5} a 3 3 0 0 1 6 0 V ${n+7}"/></g>`;if(o==="notification"||o==="webhook")return`<g stroke="${s}" stroke-width="1.3" fill="none"><path d="M${t+3} ${n+11} a 5 5 0 0 1 1.6 -3.6 V ${n+5} a 3.4 3.4 0 0 1 6.8 0 v 2.4 a 5 5 0 0 1 1.6 3.6 z"/><path d="M${t+6.5} ${n+13.5} a 1.5 1.5 0 0 0 3 0"/></g>`;if(o==="email"||o==="sms")return`<g stroke="${s}" stroke-width="1.3" fill="none"><rect x="${t+1}" y="${n+3}" width="14" height="10" rx="1.5"/><path d="M${t+1.5} ${n+4} L ${t+8} ${n+9} L ${t+14.5} ${n+4}"/></g>`;if(o==="registry")return`<g stroke="${s}" stroke-width="1.2" fill="none"><rect x="${t+1}" y="${n+8}" width="6" height="6" rx="1"/><rect x="${t+9}" y="${n+8}" width="6" height="6" rx="1"/><rect x="${t+5}" y="${n+1}" width="6" height="6" rx="1"/></g>`;if(o==="ci"||o==="cicd"||o==="pipeline")return`<g stroke="${s}" stroke-width="1.3" fill="none"><circle cx="${t+8}" cy="${n+8}" r="7"/><path d="M${t+6} ${n+5} L ${t+11.5} ${n+8} L ${t+6} ${n+11} Z" fill="${s}" stroke="none"/></g>`;if(o==="git"||o==="repo"||o==="scm")return`<g stroke="${s}" stroke-width="1.3" fill="none"><circle cx="${t+4}" cy="${n+3.5}" r="2.5"/><circle cx="${t+4}" cy="${n+12.5}" r="2.5"/><circle cx="${t+12}" cy="${n+6}" r="2.5"/><path d="M${t+4} ${n+6} V ${n+10} M${t+4} ${n+8} q 0 -2 3 -2 h 2.5"/></g>`;if(o==="device"||o==="iot")return`<g stroke="${s}" stroke-width="1.2" fill="none"><rect x="${t+4}" y="${n+4}" width="8" height="8" rx="1.5"/><path d="M${t+6} ${n+4} V ${n+1} M${t+10} ${n+4} V ${n+1} M${t+6} ${n+15} V ${n+12} M${t+10} ${n+15} V ${n+12} M${t+4} ${n+6} H ${t+1} M${t+4} ${n+10} H ${t+1} M${t+15} ${n+6} H ${t+12} M${t+15} ${n+10} H ${t+12}"/></g>`;if(o==="analytics"||o==="bi")return`<g fill="${s}"><rect x="${t+1}" y="${n+9}" width="3.4" height="6" rx="0.8"/><rect x="${t+6.3}" y="${n+5}" width="3.4" height="10" rx="0.8"/><rect x="${t+11.6}" y="${n+1}" width="3.4" height="14" rx="0.8"/></g>`;if(o==="config"||o==="settings")return`<g stroke="${s}" stroke-width="1.3" fill="none"><circle cx="${t+8}" cy="${n+8}" r="4"/><path d="M${t+8} ${n+1} V ${n+3.5} M${t+8} ${n+12.5} V ${n+15} M${t+1} ${n+8} H ${t+3.5} M${t+12.5} ${n+8} H ${t+15} M${t+3} ${n+3} L ${t+5} ${n+5} M${t+11} ${n+11} L ${t+13} ${n+13} M${t+13} ${n+3} L ${t+11} ${n+5} M${t+5} ${n+11} L ${t+3} ${n+13}"/></g>`;if(o==="cache"||o==="redis"||o==="memcached"){const r=i=>`<path d="M${t+1} ${n+5+i} L${t+8} ${n+2+i} L${t+15} ${n+5+i} L${t+8} ${n+8+i} Z" fill="none" stroke="${s}" stroke-width="1.2"/>`;return`<g>${r(0)}${r(3.5)}${r(7)}</g>`}return o==="function"||o==="lambda"?`<text x="${t+7}" y="${n+14}" font-family="Georgia, serif" font-size="17" font-style="italic" font-weight="700" fill="${s}" text-anchor="middle">ƒ</text>`:o==="cdn"||o==="external"?`<path d="M${t+3} ${n+13} a 4 4 0 0 1 0.5 -8 a 5 5 0 0 1 9.5 1.2 a 3 3 0 0 1 1 6.8 z" fill="none" stroke="${s}" stroke-width="1.3"/>`:o==="gateway"||o==="lb"||o==="proxy"?`<g stroke="${s}" stroke-width="1.5" fill="none"><path d="M${t+2} ${n+1} L ${t+8} ${n+7} L ${t+2} ${n+13}"/><path d="M${t+8} ${n+1} L ${t+14} ${n+7} L ${t+8} ${n+13}"/></g>`:o==="service"||o==="microservice"||o==="compute"||o==="container"||o==="worker"||o==="etl"?`<g stroke="${s}" stroke-width="1.3"><rect x="${t+4}" y="${n+1}" width="11" height="11" rx="1.5" fill="none"/><rect x="${t+1}" y="${n+4}" width="11" height="11" rx="1.5" fill="var(--paper)"/></g>`:Tz(o)?_z(o,t,n,s):""}var Qo={solid:{stroke:"var(--muted)",sw:1.5,dash:"",marker:"skArrow",err:!1},dashed:{stroke:"var(--muted)",sw:1.5,dash:"5 4",marker:"skOpen",err:!1},forbidden:{stroke:"var(--negative)",sw:1.5,dash:"4 3",marker:"skErr",err:!0},error:{stroke:"var(--negative)",sw:1.5,dash:"",marker:"skErr",err:!0}},C4=Object.defineProperty,jz=(e,t,n)=>t in e?C4(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Pz=(e,t)=>{for(var n in t)C4(e,n,{get:t[n],enumerable:!0})},Oz=(e,t,n)=>jz(e,t+"",n),N4={};Pz(N4,{Graph:()=>Us,alg:()=>Vy,json:()=>_4,version:()=>Bz});var Rz=Object.defineProperty,T4=(e,t)=>{for(var n in t)Rz(e,n,{get:t[n],enumerable:!0})},Us=class{constructor(e){this._isDirected=!0,this._isMultigraph=!1,this._isCompound=!1,this._nodes={},this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={},this._nodeCount=0,this._edgeCount=0,this._defaultNodeLabelFn=()=>{},this._defaultEdgeLabelFn=()=>{},e&&(this._isDirected="directed"in e?e.directed:!0,this._isMultigraph="multigraph"in e?e.multigraph:!1,this._isCompound="compound"in e?e.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children["\0"]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(e){return this._label=e,this}graph(){return this._label}setDefaultNodeLabel(e){return typeof e!="function"?this._defaultNodeLabelFn=()=>e:this._defaultNodeLabelFn=e,this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){return this.nodes().filter(e=>Object.keys(this._in[e]).length===0)}sinks(){return this.nodes().filter(e=>Object.keys(this._out[e]).length===0)}setNodes(e,t){return e.forEach(n=>{t!==void 0?this.setNode(n,t):this.setNode(n)}),this}setNode(e,t){return e in this._nodes?(arguments.length>1&&(this._nodes[e]=t),this):(this._nodes[e]=arguments.length>1?t:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]="\0",this._children[e]={},this._children["\0"][e]=!0),this._in[e]={},this._preds[e]={},this._out[e]={},this._sucs[e]={},++this._nodeCount,this)}node(e){return this._nodes[e]}hasNode(e){return e in this._nodes}removeNode(e){if(e in this._nodes){let t=n=>this.removeEdge(this._edgeObjs[n]);delete this._nodes[e],this._isCompound&&(this._removeFromParentsChildList(e),delete this._parent[e],this.children(e).forEach(n=>{this.setParent(n)}),delete this._children[e]),Object.keys(this._in[e]).forEach(t),delete this._in[e],delete this._preds[e],Object.keys(this._out[e]).forEach(t),delete this._out[e],delete this._sucs[e],--this._nodeCount}return this}setParent(e,t){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(t===void 0)t="\0";else{t+="";for(let n=t;n!==void 0;n=this.parent(n))if(n===e)throw new Error("Setting "+t+" as parent of "+e+" would create a cycle");this.setNode(t)}return this.setNode(e),this._removeFromParentsChildList(e),this._parent[e]=t,this._children[t][e]=!0,this}parent(e){if(this._isCompound){let t=this._parent[e];if(t!=="\0")return t}}children(e="\0"){if(this._isCompound){let t=this._children[e];if(t)return Object.keys(t)}else{if(e==="\0")return this.nodes();if(this.hasNode(e))return[]}return[]}predecessors(e){let t=this._preds[e];if(t)return Object.keys(t)}successors(e){let t=this._sucs[e];if(t)return Object.keys(t)}neighbors(e){let t=this.predecessors(e);if(t){let n=new Set(t);for(let s of this.successors(e))n.add(s);return Array.from(n.values())}}isLeaf(e){let t;return this.isDirected()?t=this.successors(e):t=this.neighbors(e),t.length===0}filterNodes(e){let t=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});t.setGraph(this.graph()),Object.entries(this._nodes).forEach(([o,r])=>{e(o)&&t.setNode(o,r)}),Object.values(this._edgeObjs).forEach(o=>{t.hasNode(o.v)&&t.hasNode(o.w)&&t.setEdge(o,this.edge(o))});let n={},s=o=>{let r=this.parent(o);return!r||t.hasNode(r)?(n[o]=r??void 0,r??void 0):r in n?n[r]:s(r)};return this._isCompound&&t.nodes().forEach(o=>t.setParent(o,s(o))),t}setDefaultEdgeLabel(e){return typeof e!="function"?this._defaultEdgeLabelFn=()=>e:this._defaultEdgeLabelFn=e,this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(e,t){return e.reduce((n,s)=>(t!==void 0?this.setEdge(n,s,t):this.setEdge(n,s),s)),this}setEdge(e,t,n,s){let o,r,i,l,d=!1;typeof e=="object"&&e!==null&&"v"in e?(o=e.v,r=e.w,i=e.name,arguments.length===2&&(l=t,d=!0)):(o=e,r=t,i=s,arguments.length>2&&(l=n,d=!0)),o=""+o,r=""+r,i!==void 0&&(i=""+i);let u=_c(this._isDirected,o,r,i);if(u in this._edgeLabels)return d&&(this._edgeLabels[u]=l),this;if(i!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(o),this.setNode(r),this._edgeLabels[u]=d?l:this._defaultEdgeLabelFn(o,r,i);let p=Dz(this._isDirected,o,r,i);return o=p.v,r=p.w,Object.freeze(p),this._edgeObjs[u]=p,Vw(this._preds[r],o),Vw(this._sucs[o],r),this._in[r][u]=p,this._out[o][u]=p,this._edgeCount++,this}edge(e,t,n){let s=arguments.length===1?Fg(this._isDirected,e):_c(this._isDirected,e,t,n);return this._edgeLabels[s]}edgeAsObj(e,t,n){let s=arguments.length===1?this.edge(e):this.edge(e,t,n);return typeof s!="object"?{label:s}:s}hasEdge(e,t,n){return(arguments.length===1?Fg(this._isDirected,e):_c(this._isDirected,e,t,n))in this._edgeLabels}removeEdge(e,t,n){let s=arguments.length===1?Fg(this._isDirected,e):_c(this._isDirected,e,t,n),o=this._edgeObjs[s];if(o){let r=o.v,i=o.w;delete this._edgeLabels[s],delete this._edgeObjs[s],Gw(this._preds[i],r),Gw(this._sucs[r],i),delete this._in[i][s],delete this._out[r][s],this._edgeCount--}return this}inEdges(e,t){return this.isDirected()?this.filterEdges(this._in[e],e,t):this.nodeEdges(e,t)}outEdges(e,t){return this.isDirected()?this.filterEdges(this._out[e],e,t):this.nodeEdges(e,t)}nodeEdges(e,t){if(e in this._nodes)return this.filterEdges({...this._in[e],...this._out[e]},e,t)}_removeFromParentsChildList(e){delete this._children[this._parent[e]][e]}filterEdges(e,t,n){if(!e)return;let s=Object.values(e);return n?s.filter(o=>o.v===t&&o.w===n||o.v===n&&o.w===t):s}};function Vw(e,t){e[t]?e[t]++:e[t]=1}function Gw(e,t){e[t]!==void 0&&!--e[t]&&delete e[t]}function _c(e,t,n,s){let o=""+t,r=""+n;if(!e&&o>r){let i=o;o=r,r=i}return o+""+r+""+(s===void 0?"\0":s)}function Dz(e,t,n,s){let o=""+t,r=""+n;if(!e&&o>r){let l=o;o=r,r=l}let i={v:o,w:r};return s&&(i.name=s),i}function Fg(e,t){return _c(e,t.v,t.w,t.name)}var Bz="4.0.1",_4={};T4(_4,{read:()=>Hz,write:()=>zz});function zz(e){let t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:Fz(e),edges:qz(e)},n=e.graph();return n!==void 0&&(t.value=structuredClone(n)),t}function Fz(e){return e.nodes().map(t=>{let n=e.node(t),s=e.parent(t),o={v:t};return n!==void 0&&(o.value=n),s!==void 0&&(o.parent=s),o})}function qz(e){return e.edges().map(t=>{let n=e.edge(t),s={v:t.v,w:t.w};return t.name!==void 0&&(s.name=t.name),n!==void 0&&(s.value=n),s})}function Hz(e){let t=new Us(e.options);return e.value!==void 0&&t.setGraph(e.value),e.nodes.forEach(n=>{t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(n=>{t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var Vy={};T4(Vy,{CycleException:()=>bf,bellmanFord:()=>L4,components:()=>Kz,dijkstra:()=>kf,dijkstraAll:()=>Yz,findCycles:()=>Xz,floydWarshall:()=>Zz,isAcyclic:()=>eF,postorder:()=>nF,preorder:()=>sF,prim:()=>oF,shortestPaths:()=>rF,tarjan:()=>j4,topsort:()=>P4});var Wz=()=>1;function L4(e,t,n,s){return Uz(e,String(t),n||Wz,s||function(o){return e.outEdges(o)})}function Uz(e,t,n,s){let o={},r,i=0,l=e.nodes(),d=function(h){let m=n(h);o[h.v].distance+m<o[h.w].distance&&(o[h.w]={distance:o[h.v].distance+m,predecessor:h.v},r=!0)},u=function(){l.forEach(function(h){s(h).forEach(function(m){let g=m.v===h?m.v:m.w,v=g===m.v?m.w:m.v;d({v:g,w:v})})})};l.forEach(function(h){let m=h===t?0:Number.POSITIVE_INFINITY;o[h]={distance:m,predecessor:""}});let p=l.length;for(let h=1;h<p&&(r=!1,i++,u(),!!r);h++);if(i===p-1&&(r=!1,u(),r))throw new Error("The graph contains a negative weight cycle");return o}function Kz(e){let t={},n=[],s;function o(r){r in t||(t[r]=!0,s.push(r),e.successors(r).forEach(o),e.predecessors(r).forEach(o))}return e.nodes().forEach(function(r){s=[],o(r),s.length&&n.push(s)}),n}var I4=class{constructor(){this._arr=[],this._keyIndices={}}size(){return this._arr.length}keys(){return this._arr.map(e=>e.key)}has(e){return e in this._keyIndices}priority(e){let t=this._keyIndices[e];if(t!==void 0)return this._arr[t].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(e,t){let n=this._keyIndices,s=String(e);if(!(s in n)){let o=this._arr,r=o.length;return n[s]=r,o.push({key:s,priority:t}),this._decrease(r),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);let e=this._arr.pop();return delete this._keyIndices[e.key],this._heapify(0),e.key}decrease(e,t){let n=this._keyIndices[e];if(n===void 0)throw new Error(`Key not found: ${e}`);let s=this._arr[n].priority;if(t>s)throw new Error(`New priority is greater than current priority. Key: ${e} Old: ${s} New: ${t}`);this._arr[n].priority=t,this._decrease(n)}_heapify(e){let t=this._arr,n=2*e,s=n+1,o=e;n<t.length&&(o=t[n].priority<t[o].priority?n:o,s<t.length&&(o=t[s].priority<t[o].priority?s:o),o!==e&&(this._swap(e,o),this._heapify(o)))}_decrease(e){let t=this._arr,n=t[e].priority,s;for(;e!==0&&(s=e>>1,!(t[s].priority<n));)this._swap(e,s),e=s}_swap(e,t){let n=this._arr,s=this._keyIndices,o=n[e],r=n[t];n[e]=r,n[t]=o,s[r.key]=e,s[o.key]=t}},Vz=()=>1;function kf(e,t,n,s){let o=function(r){return e.outEdges(r)};return Gz(e,String(t),n||Vz,s||o)}function Gz(e,t,n,s){let o={},r=new I4,i,l,d=function(u){let p=u.v!==i?u.v:u.w,h=o[p],m=n(u),g=l.distance+m;if(m<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+u+" Weight: "+m);g<h.distance&&(h.distance=g,h.predecessor=i,r.decrease(p,g))};for(e.nodes().forEach(function(u){let p=u===t?0:Number.POSITIVE_INFINITY;o[u]={distance:p,predecessor:""},r.add(u,p)});r.size()>0&&(i=r.removeMin(),l=o[i],l.distance!==Number.POSITIVE_INFINITY);)s(i).forEach(d);return o}function Yz(e,t,n){return e.nodes().reduce(function(s,o){return s[o]=kf(e,o,t,n),s},{})}function j4(e){let t=0,n=[],s={},o=[];function r(i){let l=s[i]={onStack:!0,lowlink:t,index:t++};if(n.push(i),e.successors(i).forEach(function(d){d in s?s[d].onStack&&(l.lowlink=Math.min(l.lowlink,s[d].index)):(r(d),l.lowlink=Math.min(l.lowlink,s[d].lowlink))}),l.lowlink===l.index){let d=[],u;do u=n.pop(),s[u].onStack=!1,d.push(u);while(i!==u);o.push(d)}}return e.nodes().forEach(function(i){i in s||r(i)}),o}function Xz(e){return j4(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var Qz=()=>1;function Zz(e,t,n){return Jz(e,t||Qz,n||function(s){return e.outEdges(s)})}function Jz(e,t,n){let s={},o=e.nodes();return o.forEach(function(r){s[r]={},s[r][r]={distance:0,predecessor:""},o.forEach(function(i){r!==i&&(s[r][i]={distance:Number.POSITIVE_INFINITY,predecessor:""})}),n(r).forEach(function(i){let l=i.v===r?i.w:i.v,d=t(i);s[r][l]={distance:d,predecessor:r}})}),o.forEach(function(r){let i=s[r];o.forEach(function(l){let d=s[l];o.forEach(function(u){let p=d[r],h=i[u],m=d[u],g=p.distance+h.distance;g<m.distance&&(m.distance=g,m.predecessor=h.predecessor)})})}),s}var bf=class extends Error{constructor(...e){super(...e)}};function P4(e){let t={},n={},s=[];function o(r){if(r in n)throw new bf;r in t||(n[r]=!0,t[r]=!0,e.predecessors(r).forEach(o),delete n[r],s.push(r))}if(e.sinks().forEach(o),Object.keys(t).length!==e.nodeCount())throw new bf;return s}function eF(e){try{P4(e)}catch(t){if(t instanceof bf)return!1;throw t}return!0}function tF(e,t,n,s,o){Array.isArray(t)||(t=[t]);let r=(l=>{var d;return(d=e.isDirected()?e.successors(l):e.neighbors(l))!=null?d:[]}),i={};return t.forEach(function(l){if(!e.hasNode(l))throw new Error("Graph does not have node: "+l);o=O4(e,l,n==="post",i,r,s,o)}),o}function O4(e,t,n,s,o,r,i){return t in s||(s[t]=!0,n||(i=r(i,t)),o(t).forEach(function(l){i=O4(e,l,n,s,o,r,i)}),n&&(i=r(i,t))),i}function R4(e,t,n){return tF(e,t,n,function(s,o){return s.push(o),s},[])}function nF(e,t){return R4(e,t,"post")}function sF(e,t){return R4(e,t,"pre")}function oF(e,t){let n=new Us,s={},o=new I4,r;function i(d){let u=d.v===r?d.w:d.v,p=o.priority(u);if(p!==void 0){let h=t(d);h<p&&(s[u]=r,o.decrease(u,h))}}if(e.nodeCount()===0)return n;e.nodes().forEach(function(d){o.add(d,Number.POSITIVE_INFINITY),n.setNode(d)}),o.decrease(e.nodes()[0],0);let l=!1;for(;o.size()>0;){if(r=o.removeMin(),r in s)n.setEdge(r,s[r]);else{if(l)throw new Error("Input graph is not connected: "+e);l=!0}e.nodeEdges(r).forEach(i)}return n}function rF(e,t,n,s){return iF(e,t,n,s??(o=>{let r=e.outEdges(o);return r??[]}))}function iF(e,t,n,s){if(n===void 0)return kf(e,t,n,s);let o=!1,r=e.nodes();for(let i=0;i<r.length;i++){let l=s(r[i]);for(let d=0;d<l.length;d++){let u=l[d],p=u.v===r[i]?u.v:u.w,h=p===u.v?u.w:u.v;n({v:p,w:h})<0&&(o=!0)}if(o)return L4(e,t,n,s)}return kf(e,t,n,s)}function bl(e,t,n,s){let o=s;for(;e.hasNode(o);)o=Gy(s);return n.dummy=t,e.setNode(o,n),o}function aF(e){let t=new Us().setGraph(e.graph());return e.nodes().forEach(n=>t.setNode(n,e.node(n))),e.edges().forEach(n=>{let s=t.edge(n.v,n.w)||{weight:0,minlen:1},o=e.edge(n);t.setEdge(n.v,n.w,{weight:s.weight+o.weight,minlen:Math.max(s.minlen,o.minlen)})}),t}function D4(e){let t=new Us({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function Yw(e,t){let n=e.x,s=e.y,o=t.x-n,r=t.y-s,i=e.width/2,l=e.height/2;if(!o&&!r)throw new Error("Not possible to find intersection inside of the rectangle");let d,u;return Math.abs(r)*i>Math.abs(o)*l?(r<0&&(l=-l),d=l*o/r,u=l):(o<0&&(i=-i),d=i,u=i*r/o),{x:n+d,y:s+u}}function $d(e){let t=rd(z4(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let s=e.node(n),o=s.rank;o!==void 0&&(t[o]||(t[o]=[]),t[o][s.order]=n)}),t}function lF(e){let t=e.nodes().map(s=>{let o=e.node(s).rank;return o===void 0?Number.MAX_VALUE:o}),n=ko(Math.min,t);e.nodes().forEach(s=>{let o=e.node(s);Object.hasOwn(o,"rank")&&(o.rank-=n)})}function cF(e){let t=e.nodes().map(i=>e.node(i).rank).filter(i=>i!==void 0),n=ko(Math.min,t),s=[];e.nodes().forEach(i=>{let l=e.node(i).rank-n;s[l]||(s[l]=[]),s[l].push(i)});let o=0,r=e.graph().nodeRankFactor;Array.from(s).forEach((i,l)=>{i===void 0&&l%r!==0?--o:i!==void 0&&o&&i.forEach(d=>e.node(d).rank+=o)})}function Xw(e,t,n,s){let o={width:0,height:0};return arguments.length>=4&&(o.rank=n,o.order=s),bl(e,"border",o,t)}function dF(e,t=B4){let n=[];for(let s=0;s<e.length;s+=t){let o=e.slice(s,s+t);n.push(o)}return n}var B4=65535;function ko(e,t){if(t.length>B4){let n=dF(t);return e(...n.map(s=>e(...s)))}else return e(...t)}function z4(e){let t=e.nodes().map(n=>{let s=e.node(n).rank;return s===void 0?Number.MIN_VALUE:s});return ko(Math.max,t)}function uF(e,t){let n={lhs:[],rhs:[]};return e.forEach(s=>{t(s)?n.lhs.push(s):n.rhs.push(s)}),n}function F4(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function q4(e,t){return t()}var pF=0;function Gy(e){let t=++pF;return e+(""+t)}function rd(e,t,n=1){t==null&&(t=e,e=0);let s=r=>r<t;n<0&&(s=r=>t<r);let o=[];for(let r=e;s(r);r+=n)o.push(r);return o}function wf(e,t){let n={};for(let s of t)e[s]!==void 0&&(n[s]=e[s]);return n}function hh(e,t){let n;return typeof t=="string"?n=s=>s[t]:n=t,Object.entries(e).reduce((s,[o,r])=>(s[o]=n(r,o),s),{})}function fF(e,t){return e.reduce((n,s,o)=>(n[s]=t[o],n),{})}var mh="\0",hF="3.0.0",mF=class{constructor(){Oz(this,"_sentinel");let e={};e._next=e._prev=e,this._sentinel=e}dequeue(){let e=this._sentinel,t=e._prev;if(t!==e)return Qw(t),t}enqueue(e){let t=this._sentinel;e._prev&&e._next&&Qw(e),e._next=t._next,t._next._prev=e,t._next=e,e._prev=t}toString(){let e=[],t=this._sentinel,n=t._prev;for(;n!==t;)e.push(JSON.stringify(n,gF)),n=n._prev;return"["+e.join(", ")+"]"}};function Qw(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function gF(e,t){if(e!=="_next"&&e!=="_prev")return t}var vF=mF,yF=()=>1;function xF(e,t){if(e.nodeCount()<=1)return[];let n=bF(e,t||yF);return kF(n.graph,n.buckets,n.zeroIdx).flatMap(s=>e.outEdges(s.v,s.w)||[])}function kF(e,t,n){var s;let o=[],r=t[t.length-1],i=t[0],l;for(;e.nodeCount();){for(;l=i.dequeue();)qg(e,t,n,l);for(;l=r.dequeue();)qg(e,t,n,l);if(e.nodeCount()){for(let d=t.length-2;d>0;--d)if(l=(s=t[d])==null?void 0:s.dequeue(),l){o=o.concat(qg(e,t,n,l,!0)||[]);break}}}return o}function qg(e,t,n,s,o){let r=[],i=o?r:void 0;return(e.inEdges(s.v)||[]).forEach(l=>{let d=e.edge(l),u=e.node(l.v);o&&r.push({v:l.v,w:l.w}),u.out-=d,k0(t,n,u)}),(e.outEdges(s.v)||[]).forEach(l=>{let d=e.edge(l),u=l.w,p=e.node(u);p.in-=d,k0(t,n,p)}),e.removeNode(s.v),i}function bF(e,t){let n=new Us,s=0,o=0;e.nodes().forEach(l=>{n.setNode(l,{v:l,in:0,out:0})}),e.edges().forEach(l=>{let d=n.edge(l.v,l.w)||0,u=t(l),p=d+u;n.setEdge(l.v,l.w,p);let h=n.node(l.v),m=n.node(l.w);o=Math.max(o,h.out+=u),s=Math.max(s,m.in+=u)});let r=wF(o+s+3).map(()=>new vF),i=s+1;return n.nodes().forEach(l=>{k0(r,i,n.node(l))}),{graph:n,buckets:r,zeroIdx:i}}function k0(e,t,n){var s,o,r;n.out?n.in?(r=e[n.out-n.in+t])==null||r.enqueue(n):(o=e[e.length-1])==null||o.enqueue(n):(s=e[0])==null||s.enqueue(n)}function wF(e){let t=[];for(let n=0;n<e;n++)t.push(n);return t}function $F(e){(e.graph().acyclicer==="greedy"?xF(e,t(e)):SF(e)).forEach(n=>{let s=e.edge(n);e.removeEdge(n),s.forwardName=n.name,s.reversed=!0,e.setEdge(n.w,n.v,s,Gy("rev"))});function t(n){return s=>n.edge(s).weight}}function SF(e){let t=[],n={},s={};function o(r){Object.hasOwn(s,r)||(s[r]=!0,n[r]=!0,e.outEdges(r).forEach(i=>{Object.hasOwn(n,i.w)?t.push(i):o(i.w)}),delete n[r])}return e.nodes().forEach(o),t}function EF(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let s=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,s)}})}function MF(e){e.graph().dummyChains=[],e.edges().forEach(t=>AF(e,t))}function AF(e,t){let n=t.v,s=e.node(n).rank,o=t.w,r=e.node(o).rank,i=t.name,l=e.edge(t),d=l.labelRank;if(r===s+1)return;e.removeEdge(t);let u,p,h;for(h=0,++s;s<r;++h,++s)l.points=[],p={width:0,height:0,edgeLabel:l,edgeObj:t,rank:s},u=bl(e,"edge",p,"_d"),s===d&&(p.width=l.width,p.height=l.height,p.dummy="edge-label",p.labelpos=l.labelpos),e.setEdge(n,u,{weight:l.weight},i),h===0&&e.graph().dummyChains.push(u),n=u;e.setEdge(n,o,{weight:l.weight},i)}function CF(e){e.graph().dummyChains.forEach(t=>{let n=e.node(t),s=n.edgeLabel,o;for(e.setEdge(n.edgeObj,s);n.dummy;)o=e.successors(t)[0],e.removeNode(t),s.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(s.x=n.x,s.y=n.y,s.width=n.width,s.height=n.height),t=o,n=e.node(t)})}function Yy(e){let t={};function n(s){let o=e.node(s);if(Object.hasOwn(t,s))return o.rank;t[s]=!0;let r=e.outEdges(s),i=r?r.map(d=>d==null?Number.POSITIVE_INFINITY:n(d.w)-e.edge(d).minlen):[],l=ko(Math.min,i);return l===Number.POSITIVE_INFINITY&&(l=0),o.rank=l}e.sources().forEach(n)}function ll(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var H4=NF;function NF(e){let t=new Us({directed:!1}),n=e.nodes();if(n.length===0)throw new Error("Graph must have at least one node");let s=n[0],o=e.nodeCount();t.setNode(s,{});let r,i;for(;TF(t,e)<o&&(r=_F(t,e),!!r);)i=t.hasNode(r.v)?ll(e,r):-ll(e,r),LF(t,e,i);return t}function TF(e,t){function n(s){let o=t.nodeEdges(s);o&&o.forEach(r=>{let i=r.v,l=s===i?r.w:i;!e.hasNode(l)&&!ll(t,r)&&(e.setNode(l,{}),e.setEdge(s,l,{}),n(l))})}return e.nodes().forEach(n),e.nodeCount()}function _F(e,t){return t.edges().reduce((n,s)=>{let o=Number.POSITIVE_INFINITY;return e.hasNode(s.v)!==e.hasNode(s.w)&&(o=ll(t,s)),o<n[0]?[o,s]:n},[Number.POSITIVE_INFINITY,null])[1]}function LF(e,t,n){e.nodes().forEach(s=>t.node(s).rank+=n)}var{preorder:IF,postorder:jF}=Vy,PF=Xi;Xi.initLowLimValues=Qy;Xi.initCutValues=Xy;Xi.calcCutValue=W4;Xi.leaveEdge=K4;Xi.enterEdge=V4;Xi.exchangeEdges=G4;function Xi(e){e=aF(e),Yy(e);let t=H4(e);Qy(t),Xy(t,e);let n,s;for(;n=K4(t);)s=V4(t,e,n),G4(t,e,n,s)}function Xy(e,t){let n=jF(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(s=>OF(e,t,s))}function OF(e,t,n){let s=e.node(n).parent,o=e.edge(n,s);o.cutvalue=W4(e,t,n)}function W4(e,t,n){let s=e.node(n).parent,o=!0,r=t.edge(n,s),i=0;r||(o=!1,r=t.edge(s,n)),i=r.weight;let l=t.nodeEdges(n);return l&&l.forEach(d=>{let u=d.v===n,p=u?d.w:d.v;if(p!==s){let h=u===o,m=t.edge(d).weight;if(i+=h?m:-m,DF(e,n,p)){let g=e.edge(n,p).cutvalue;i+=h?-g:g}}}),i}function Qy(e,t){arguments.length<2&&(t=e.nodes()[0]),U4(e,{},1,t)}function U4(e,t,n,s,o){let r=n,i=e.node(s);t[s]=!0;let l=e.neighbors(s);return l&&l.forEach(d=>{Object.hasOwn(t,d)||(n=U4(e,t,n,d,s))}),i.low=r,i.lim=n++,o?i.parent=o:delete i.parent,n}function K4(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function V4(e,t,n){let s=n.v,o=n.w;t.hasEdge(s,o)||(s=n.w,o=n.v);let r=e.node(s),i=e.node(o),l=r,d=!1;return r.lim>i.lim&&(l=i,d=!0),t.edges().filter(u=>d===Zw(e,e.node(u.v),l)&&d!==Zw(e,e.node(u.w),l)).reduce((u,p)=>ll(t,p)<ll(t,u)?p:u)}function G4(e,t,n,s){let o=n.v,r=n.w;e.removeEdge(o,r),e.setEdge(s.v,s.w,{}),Qy(e),Xy(e,t),RF(e,t)}function RF(e,t){let n=e.nodes().find(o=>!e.node(o).parent);if(!n)return;let s=IF(e,[n]);s=s.slice(1),s.forEach(o=>{let r=e.node(o).parent,i=t.edge(o,r),l=!1;i||(i=t.edge(r,o),l=!0),t.node(o).rank=t.node(r).rank+(l?i.minlen:-i.minlen)})}function DF(e,t,n){return e.hasEdge(t,n)}function Zw(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var BF=zF;function zF(e){let t=e.graph().ranker;if(typeof t=="function")return t(e);switch(t){case"network-simplex":Jw(e);break;case"tight-tree":qF(e);break;case"longest-path":FF(e);break;case"none":break;default:Jw(e)}}var FF=Yy;function qF(e){Yy(e),H4(e)}function Jw(e){PF(e)}var HF=WF;function WF(e){let t=KF(e);e.graph().dummyChains.forEach(n=>{let s=e.node(n),o=s.edgeObj,r=UF(e,t,o.v,o.w),i=r.path,l=r.lca,d=0,u=i[d],p=!0;for(;n!==o.w;){if(s=e.node(n),p){for(;(u=i[d])!==l&&e.node(u).maxRank<s.rank;)d++;u===l&&(p=!1)}if(!p){for(;d<i.length-1&&e.node(i[d+1]).minRank<=s.rank;)d++;u=i[d]}u!==void 0&&e.setParent(n,u),n=e.successors(n)[0]}})}function UF(e,t,n,s){let o=[],r=[],i=Math.min(t[n].low,t[s].low),l=Math.max(t[n].lim,t[s].lim),d;d=n;do d=e.parent(d),o.push(d);while(d&&(t[d].low>i||l>t[d].lim));let u=d,p=s;for(;(p=e.parent(p))!==u;)r.push(p);return{path:o.concat(r.reverse()),lca:u}}function KF(e){let t={},n=0;function s(o){let r=n;e.children(o).forEach(s),t[o]={low:r,lim:n++}}return e.children(mh).forEach(s),t}function VF(e){let t=bl(e,"root",{},"_root"),n=GF(e),s=Object.values(n),o=ko(Math.max,s)-1,r=2*o+1;e.graph().nestingRoot=t,e.edges().forEach(l=>e.edge(l).minlen*=r);let i=YF(e)+1;e.children(mh).forEach(l=>Y4(e,t,r,i,o,n,l)),e.graph().nodeRankFactor=r}function Y4(e,t,n,s,o,r,i){var l;let d=e.children(i);if(!d.length){i!==t&&e.setEdge(t,i,{weight:0,minlen:n});return}let u=Xw(e,"_bt"),p=Xw(e,"_bb"),h=e.node(i);e.setParent(u,i),h.borderTop=u,e.setParent(p,i),h.borderBottom=p,d.forEach(m=>{var g;Y4(e,t,n,s,o,r,m);let v=e.node(m),y=v.borderTop?v.borderTop:m,b=v.borderBottom?v.borderBottom:m,E=v.borderTop?s:2*s,$=y!==b?1:o-((g=r[i])!=null?g:0)+1;e.setEdge(u,y,{weight:E,minlen:$,nestingEdge:!0}),e.setEdge(b,p,{weight:E,minlen:$,nestingEdge:!0})}),e.parent(i)||e.setEdge(t,u,{weight:0,minlen:o+((l=r[i])!=null?l:0)})}function GF(e){let t={};function n(s,o){let r=e.children(s);r&&r.length&&r.forEach(i=>n(i,o+1)),t[s]=o}return e.children(mh).forEach(s=>n(s,1)),t}function YF(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function XF(e){let t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{e.edge(n).nestingEdge&&e.removeEdge(n)})}var QF=ZF;function ZF(e){function t(n){let s=e.children(n),o=e.node(n);if(s.length&&s.forEach(t),Object.hasOwn(o,"minRank")){o.borderLeft=[],o.borderRight=[];for(let r=o.minRank,i=o.maxRank+1;r<i;++r)e$(e,"borderLeft","_bl",n,o,r),e$(e,"borderRight","_br",n,o,r)}}e.children(mh).forEach(t)}function e$(e,t,n,s,o,r){let i={width:0,height:0,rank:r,borderType:t},l=o[t][r-1],d=bl(e,"border",i,n);o[t][r]=d,e.setParent(d,s),l&&e.setEdge(l,d,{weight:1})}function JF(e){var t;let n=(t=e.graph().rankdir)==null?void 0:t.toLowerCase();(n==="lr"||n==="rl")&&X4(e)}function e7(e){var t;let n=(t=e.graph().rankdir)==null?void 0:t.toLowerCase();(n==="bt"||n==="rl")&&t7(e),(n==="lr"||n==="rl")&&(n7(e),X4(e))}function X4(e){e.nodes().forEach(t=>t$(e.node(t))),e.edges().forEach(t=>t$(e.edge(t)))}function t$(e){let t=e.width;e.width=e.height,e.height=t}function t7(e){e.nodes().forEach(t=>Hg(e.node(t))),e.edges().forEach(t=>{var n;let s=e.edge(t);(n=s.points)==null||n.forEach(Hg),Object.hasOwn(s,"y")&&Hg(s)})}function Hg(e){e.y=-e.y}function n7(e){e.nodes().forEach(t=>Wg(e.node(t))),e.edges().forEach(t=>{var n;let s=e.edge(t);(n=s.points)==null||n.forEach(Wg),Object.hasOwn(s,"x")&&Wg(s)})}function Wg(e){let t=e.x;e.x=e.y,e.y=t}function s7(e){let t={},n=e.nodes().filter(l=>!e.children(l).length),s=n.map(l=>e.node(l).rank),o=ko(Math.max,s),r=rd(o+1).map(()=>[]);function i(l){if(t[l])return;t[l]=!0;let d=e.node(l);r[d.rank].push(l);let u=e.successors(l);u&&u.forEach(i)}return n.sort((l,d)=>e.node(l).rank-e.node(d).rank).forEach(i),r}function o7(e,t){let n=0;for(let s=1;s<t.length;++s)n+=r7(e,t[s-1],t[s]);return n}function r7(e,t,n){let s=fF(n,n.map((u,p)=>p)),o=t.flatMap(u=>{let p=e.outEdges(u);return p?p.map(h=>({pos:s[h.w],weight:e.edge(h).weight})).sort((h,m)=>h.pos-m.pos):[]}),r=1;for(;r<n.length;)r<<=1;let i=2*r-1;r-=1;let l=new Array(i).fill(0),d=0;return o.forEach(u=>{let p=u.pos+r;l[p]+=u.weight;let h=0;for(;p>0;)p%2&&(h+=l[p+1]),p=p-1>>1,l[p]+=u.weight;d+=u.weight*h}),d}function i7(e,t=[]){return t.map(n=>{let s=e.inEdges(n);if(!s||!s.length)return{v:n};{let o=s.reduce((r,i)=>{let l=e.edge(i),d=e.node(i.v);return{sum:r.sum+l.weight*d.order,weight:r.weight+l.weight}},{sum:0,weight:0});return{v:n,barycenter:o.sum/o.weight,weight:o.weight}}})}function a7(e,t){let n={};e.forEach((o,r)=>{let i={indegree:0,in:[],out:[],vs:[o.v],i:r};o.barycenter!==void 0&&(i.barycenter=o.barycenter,i.weight=o.weight),n[o.v]=i}),t.edges().forEach(o=>{let r=n[o.v],i=n[o.w];r!==void 0&&i!==void 0&&(i.indegree++,r.out.push(i))});let s=Object.values(n).filter(o=>!o.indegree);return l7(s)}function l7(e){let t=[];function n(o){return r=>{r.merged||(r.barycenter===void 0||o.barycenter===void 0||r.barycenter>=o.barycenter)&&c7(o,r)}}function s(o){return r=>{r.in.push(o),--r.indegree===0&&e.push(r)}}for(;e.length;){let o=e.pop();t.push(o),o.in.reverse().forEach(n(o)),o.out.forEach(s(o))}return t.filter(o=>!o.merged).map(o=>wf(o,["vs","i","barycenter","weight"]))}function c7(e,t){let n=0,s=0;e.weight&&(n+=e.barycenter*e.weight,s+=e.weight),t.weight&&(n+=t.barycenter*t.weight,s+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/s,e.weight=s,e.i=Math.min(t.i,e.i),t.merged=!0}function d7(e,t){let n=uF(e,p=>Object.hasOwn(p,"barycenter")),s=n.lhs,o=n.rhs.sort((p,h)=>h.i-p.i),r=[],i=0,l=0,d=0;s.sort(u7(!!t)),d=n$(r,o,d),s.forEach(p=>{d+=p.vs.length,r.push(p.vs),i+=p.barycenter*p.weight,l+=p.weight,d=n$(r,o,d)});let u={vs:r.flat(1)};return l&&(u.barycenter=i/l,u.weight=l),u}function n$(e,t,n){let s;for(;t.length&&(s=t[t.length-1]).i<=n;)t.pop(),e.push(s.vs),n++;return n}function u7(e){return(t,n)=>t.barycenter<n.barycenter?-1:t.barycenter>n.barycenter?1:e?n.i-t.i:t.i-n.i}function Q4(e,t,n,s){let o=e.children(t),r=e.node(t),i=r?r.borderLeft:void 0,l=r?r.borderRight:void 0,d={};i&&(o=o.filter(m=>m!==i&&m!==l));let u=i7(e,o);u.forEach(m=>{if(e.children(m.v).length){let g=Q4(e,m.v,n,s);d[m.v]=g,Object.hasOwn(g,"barycenter")&&f7(m,g)}});let p=a7(u,n);p7(p,d);let h=d7(p,s);if(i&&l){h.vs=[i,h.vs,l].flat(1);let m=e.predecessors(i);if(m&&m.length){let g=e.node(m[0]),v=e.predecessors(l),y=e.node(v[0]);Object.hasOwn(h,"barycenter")||(h.barycenter=0,h.weight=0),h.barycenter=(h.barycenter*h.weight+g.order+y.order)/(h.weight+2),h.weight+=2}}return h}function p7(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(s=>t[s]?t[s].vs:s)})}function f7(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}function h7(e,t,n,s){s||(s=e.nodes());let o=m7(e),r=new Us({compound:!0}).setGraph({root:o}).setDefaultNodeLabel(i=>e.node(i));return s.forEach(i=>{let l=e.node(i),d=e.parent(i);if(l.rank===t||l.minRank<=t&&t<=l.maxRank){r.setNode(i),r.setParent(i,d||o);let u=e[n](i);u&&u.forEach(p=>{let h=p.v===i?p.w:p.v,m=r.edge(h,i),g=m!==void 0?m.weight:0;r.setEdge(h,i,{weight:e.edge(p).weight+g})}),Object.hasOwn(l,"minRank")&&r.setNode(i,{borderLeft:l.borderLeft[t],borderRight:l.borderRight[t]})}}),r}function m7(e){let t;for(;e.hasNode(t=Gy("_root")););return t}function g7(e,t,n){let s={},o;n.forEach(r=>{let i=e.parent(r),l,d;for(;i;){if(l=e.parent(i),l?(d=s[l],s[l]=i):(d=o,o=i),d&&d!==i){t.setEdge(d,i);return}i=l}})}function Z4(e,t={}){if(typeof t.customOrder=="function"){t.customOrder(e,Z4);return}let n=z4(e),s=s$(e,rd(1,n+1),"inEdges"),o=s$(e,rd(n-1,-1,-1),"outEdges"),r=s7(e);if(o$(e,r),t.disableOptimalOrderHeuristic)return;let i=Number.POSITIVE_INFINITY,l,d=t.constraints||[];for(let u=0,p=0;p<4;++u,++p){v7(u%2?s:o,u%4>=2,d),r=$d(e);let h=o7(e,r);h<i?(p=0,l=Object.assign({},r),i=h):h===i&&(l=structuredClone(r))}o$(e,l)}function s$(e,t,n){let s=new Map,o=(r,i)=>{s.has(r)||s.set(r,[]),s.get(r).push(i)};for(let r of e.nodes()){let i=e.node(r);if(typeof i.rank=="number"&&o(i.rank,r),typeof i.minRank=="number"&&typeof i.maxRank=="number")for(let l=i.minRank;l<=i.maxRank;l++)l!==i.rank&&o(l,r)}return t.map(function(r){return h7(e,r,n,s.get(r)||[])})}function v7(e,t,n){let s=new Us;e.forEach(function(o){n.forEach(l=>s.setEdge(l.left,l.right));let r=o.graph().root,i=Q4(o,r,s,t);i.vs.forEach((l,d)=>o.node(l).order=d),g7(o,s,i.vs)})}function o$(e,t){Object.values(t).forEach(n=>n.forEach((s,o)=>e.node(s).order=o))}function y7(e,t){let n={};function s(o,r){let i=0,l=0,d=o.length,u=r[r.length-1];return r.forEach((p,h)=>{let m=k7(e,p),g=m?e.node(m).order:d;(m||p===u)&&(r.slice(l,h+1).forEach(v=>{let y=e.predecessors(v);y&&y.forEach(b=>{let E=e.node(b),$=E.order;($<i||g<$)&&!(E.dummy&&e.node(v).dummy)&&J4(n,b,v)})}),l=h+1,i=g)}),r}return t.length&&t.reduce(s),n}function x7(e,t){let n={};function s(r,i,l,d,u){rd(i,l).forEach(p=>{let h=r[p];if(h!==void 0&&e.node(h).dummy){let m=e.predecessors(h);m&&m.forEach(g=>{if(g===void 0)return;let v=e.node(g);v.dummy&&(v.order<d||v.order>u)&&J4(n,g,h)})}})}function o(r,i){let l=-1,d=-1,u=0;return i.forEach((p,h)=>{if(e.node(p).dummy==="border"){let m=e.predecessors(p);if(m&&m.length){let g=m[0];if(g===void 0)return;d=e.node(g).order,s(i,u,h,l,d),u=h,l=d}}s(i,u,i.length,d,r.length)}),i}return t.length&&t.reduce(o),n}function k7(e,t){if(e.node(t).dummy){let n=e.predecessors(t);if(n)return n.find(s=>e.node(s).dummy)}}function J4(e,t,n){if(t>n){let o=t;t=n,n=o}let s=e[t];s||(e[t]=s={}),s[n]=!0}function b7(e,t,n){if(t>n){let o=t;t=n,n=o}let s=e[t];return s!==void 0&&Object.hasOwn(s,n)}function w7(e,t,n,s){let o={},r={},i={};return t.forEach(l=>{l.forEach((d,u)=>{o[d]=d,r[d]=d,i[d]=u})}),t.forEach(l=>{let d=-1;l.forEach(u=>{let p=s(u);if(p&&p.length){let h=p.sort((g,v)=>{let y=i[g],b=i[v];return(y!==void 0?y:0)-(b!==void 0?b:0)}),m=(h.length-1)/2;for(let g=Math.floor(m),v=Math.ceil(m);g<=v;++g){let y=h[g];if(y===void 0)continue;let b=i[y];if(b!==void 0&&r[u]===u&&d<b&&!b7(n,u,y)){let E=o[y];E!==void 0&&(r[y]=u,r[u]=o[u]=E,d=b)}}}})}),{root:o,align:r}}function $7(e,t,n,s,o=!1){let r={},i=S7(e,t,n,o),l=o?"borderLeft":"borderRight";function d(g,v){let y=i.nodes().slice(),b={},E=y.pop();for(;E;){if(b[E])g(E);else{b[E]=!0,y.push(E);for(let $ of v(E))y.push($)}E=y.pop()}}function u(g){let v=i.inEdges(g);v?r[g]=v.reduce((y,b)=>{var E;let $=(E=r[b.v])!=null?E:0,A=i.edge(b);return Math.max(y,$+(A!==void 0?A:0))},0):r[g]=0}function p(g){let v=i.outEdges(g),y=Number.POSITIVE_INFINITY;v&&(y=v.reduce((E,$)=>{let A=r[$.w],T=i.edge($);return Math.min(E,(A!==void 0?A:0)-(T!==void 0?T:0))},Number.POSITIVE_INFINITY));let b=e.node(g);y!==Number.POSITIVE_INFINITY&&b.borderType!==l&&(r[g]=Math.max(r[g]!==void 0?r[g]:0,y))}function h(g){return i.predecessors(g)||[]}function m(g){return i.successors(g)||[]}return d(u,h),d(p,m),Object.keys(s).forEach(g=>{var v;let y=n[g];y!==void 0&&(r[g]=(v=r[y])!=null?v:0)}),r}function S7(e,t,n,s){let o=new Us,r=e.graph(),i=N7(r.nodesep,r.edgesep,s);return t.forEach(l=>{let d;l.forEach(u=>{let p=n[u];if(p!==void 0){if(o.setNode(p),d!==void 0){let h=n[d];if(h!==void 0){let m=o.edge(h,p);o.setEdge(h,p,Math.max(i(e,u,d),m||0))}}d=u}})}),o}function E7(e,t){return Object.values(t).reduce((n,s)=>{let o=Number.NEGATIVE_INFINITY,r=Number.POSITIVE_INFINITY;Object.entries(s).forEach(([l,d])=>{let u=T7(e,l)/2;o=Math.max(d+u,o),r=Math.min(d-u,r)});let i=o-r;return i<n[0]&&(n=[i,s]),n},[Number.POSITIVE_INFINITY,null])[1]}function M7(e,t){let n=Object.values(t),s=ko(Math.min,n),o=ko(Math.max,n);["u","d"].forEach(r=>{["l","r"].forEach(i=>{let l=r+i,d=e[l];if(!d||d===t)return;let u=Object.values(d),p=s-ko(Math.min,u);i!=="l"&&(p=o-ko(Math.max,u)),p&&(e[l]=hh(d,h=>h+p))})})}function A7(e,t=void 0){let n=e.ul;return n?hh(n,(s,o)=>{var r,i;if(t){let d=t.toLowerCase(),u=e[d];if(u&&u[o]!==void 0)return u[o]}let l=Object.values(e).map(d=>{let u=d[o];return u!==void 0?u:0}).sort((d,u)=>d-u);return(((r=l[1])!=null?r:0)+((i=l[2])!=null?i:0))/2}):{}}function C7(e){let t=$d(e),n=Object.assign(y7(e,t),x7(e,t)),s={},o;["u","d"].forEach(i=>{o=i==="u"?t:Object.values(t).reverse(),["l","r"].forEach(l=>{l==="r"&&(o=o.map(p=>Object.values(p).reverse()));let d=w7(e,o,n,p=>(i==="u"?e.predecessors(p):e.successors(p))||[]),u=$7(e,o,d.root,d.align,l==="r");l==="r"&&(u=hh(u,p=>-p)),s[i+l]=u})});let r=E7(e,s);return M7(s,r),A7(s,e.graph().align)}function N7(e,t,n){return(s,o,r)=>{let i=s.node(o),l=s.node(r),d=0,u;if(d+=i.width/2,Object.hasOwn(i,"labelpos"))switch(i.labelpos.toLowerCase()){case"l":u=-i.width/2;break;case"r":u=i.width/2;break}if(u&&(d+=n?u:-u),u=void 0,d+=(i.dummy?t:e)/2,d+=(l.dummy?t:e)/2,d+=l.width/2,Object.hasOwn(l,"labelpos"))switch(l.labelpos.toLowerCase()){case"l":u=l.width/2;break;case"r":u=-l.width/2;break}return u&&(d+=n?u:-u),d}}function T7(e,t){return e.node(t).width}function _7(e){e=D4(e),L7(e),Object.entries(C7(e)).forEach(([t,n])=>e.node(t).x=n)}function L7(e){let t=$d(e),n=e.graph(),s=n.ranksep,o=n.rankalign,r=0;t.forEach(i=>{let l=i.reduce((d,u)=>{var p;let h=(p=e.node(u).height)!=null?p:0;return d>h?d:h},0);i.forEach(d=>{let u=e.node(d);o==="top"?u.y=r+u.height/2:o==="bottom"?u.y=r+l-u.height/2:u.y=r+l/2}),r+=l+s})}function I7(e,t={}){let n=t.debugTiming?F4:q4;return n("layout",()=>{let s=n(" buildLayoutGraph",()=>H7(e));return n(" runLayout",()=>j7(s,n,t)),n(" updateInputGraph",()=>P7(e,s)),s})}function j7(e,t,n){t(" makeSpaceForEdgeLabels",()=>W7(e)),t(" removeSelfEdges",()=>J7(e)),t(" acyclic",()=>$F(e)),t(" nestingGraph.run",()=>VF(e)),t(" rank",()=>BF(D4(e))),t(" injectEdgeLabelProxies",()=>U7(e)),t(" removeEmptyRanks",()=>cF(e)),t(" nestingGraph.cleanup",()=>XF(e)),t(" normalizeRanks",()=>lF(e)),t(" assignRankMinMax",()=>K7(e)),t(" removeEdgeLabelProxies",()=>V7(e)),t(" normalize.run",()=>MF(e)),t(" parentDummyChains",()=>HF(e)),t(" addBorderSegments",()=>QF(e)),t(" order",()=>Z4(e,n)),t(" insertSelfEdges",()=>e9(e)),t(" adjustCoordinateSystem",()=>JF(e)),t(" position",()=>_7(e)),t(" positionSelfEdges",()=>t9(e)),t(" removeBorderNodes",()=>Z7(e)),t(" normalize.undo",()=>CF(e)),t(" fixupEdgeLabelCoords",()=>X7(e)),t(" undoCoordinateSystem",()=>e7(e)),t(" translateGraph",()=>G7(e)),t(" assignNodeIntersects",()=>Y7(e)),t(" reversePoints",()=>Q7(e)),t(" acyclic.undo",()=>EF(e))}function P7(e,t){e.nodes().forEach(n=>{let s=e.node(n),o=t.node(n);s&&(s.x=o.x,s.y=o.y,s.order=o.order,s.rank=o.rank,t.children(n).length&&(s.width=o.width,s.height=o.height))}),e.edges().forEach(n=>{let s=e.edge(n),o=t.edge(n);s.points=o.points,Object.hasOwn(o,"x")&&(s.x=o.x,s.y=o.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}var O7=["nodesep","edgesep","ranksep","marginx","marginy"],R7={ranksep:50,edgesep:20,nodesep:50,rankdir:"TB",rankalign:"center"},D7=["acyclicer","ranker","rankdir","align","rankalign"],B7=["width","height","rank"],r$={width:0,height:0},z7=["minlen","weight","width","height","labeloffset"],F7={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},q7=["labelpos"];function H7(e){let t=new Us({multigraph:!0,compound:!0}),n=Kg(e.graph());return t.setGraph(Object.assign({},R7,Ug(n,O7),wf(n,D7))),e.nodes().forEach(s=>{let o=Kg(e.node(s)),r=Ug(o,B7);Object.keys(r$).forEach(l=>{r[l]===void 0&&(r[l]=r$[l])}),t.setNode(s,r);let i=e.parent(s);i!==void 0&&t.setParent(s,i)}),e.edges().forEach(s=>{let o=Kg(e.edge(s));t.setEdge(s,Object.assign({},F7,Ug(o,z7),wf(o,q7)))}),t}function W7(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let s=e.edge(n);s.minlen*=2,s.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?s.width+=s.labeloffset:s.height+=s.labeloffset)})}function U7(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let s=e.node(t.v),o={rank:(e.node(t.w).rank-s.rank)/2+s.rank,e:t};bl(e,"edge-proxy",o,"_ep")}})}function K7(e){let t=0;e.nodes().forEach(n=>{let s=e.node(n);s.borderTop&&(s.minRank=e.node(s.borderTop).rank,s.maxRank=e.node(s.borderBottom).rank,t=Math.max(t,s.maxRank))}),e.graph().maxRank=t}function V7(e){e.nodes().forEach(t=>{let n=e.node(t);if(n.dummy==="edge-proxy"){let s=n;e.edge(s.e).labelRank=n.rank,e.removeNode(t)}})}function G7(e){let t=Number.POSITIVE_INFINITY,n=0,s=Number.POSITIVE_INFINITY,o=0,r=e.graph(),i=r.marginx||0,l=r.marginy||0;function d(u){let p=u.x,h=u.y,m=u.width,g=u.height;t=Math.min(t,p-m/2),n=Math.max(n,p+m/2),s=Math.min(s,h-g/2),o=Math.max(o,h+g/2)}e.nodes().forEach(u=>d(e.node(u))),e.edges().forEach(u=>{let p=e.edge(u);Object.hasOwn(p,"x")&&d(p)}),t-=i,s-=l,e.nodes().forEach(u=>{let p=e.node(u);p.x-=t,p.y-=s}),e.edges().forEach(u=>{let p=e.edge(u);p.points.forEach(h=>{h.x-=t,h.y-=s}),Object.hasOwn(p,"x")&&(p.x-=t),Object.hasOwn(p,"y")&&(p.y-=s)}),r.width=n-t+i,r.height=o-s+l}function Y7(e){e.edges().forEach(t=>{let n=e.edge(t),s=e.node(t.v),o=e.node(t.w),r,i;n.points?(r=n.points[0],i=n.points[n.points.length-1]):(n.points=[],r=o,i=s),n.points.unshift(Yw(s,r)),n.points.push(Yw(o,i))})}function X7(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset;break}})}function Q7(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function Z7(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),s=e.node(n.borderTop),o=e.node(n.borderBottom),r=e.node(n.borderLeft[n.borderLeft.length-1]),i=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(i.x-r.x),n.height=Math.abs(o.y-s.y),n.x=r.x+n.width/2,n.y=s.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function J7(e){e.edges().forEach(t=>{if(t.v===t.w){let n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function e9(e){$d(e).forEach(t=>{let n=0;t.forEach((s,o)=>{let r=e.node(s);r.order=o+n,(r.selfEdges||[]).forEach(i=>{bl(e,"selfedge",{width:i.label.width,height:i.label.height,rank:r.rank,order:o+ ++n,e:i.e,label:i.label},"_se")}),delete r.selfEdges})})}function t9(e){e.nodes().forEach(t=>{let n=e.node(t);if(n.dummy==="selfedge"){let s=n,o=e.node(s.e.v),r=o.x+o.width/2,i=o.y,l=n.x-r,d=o.height/2;e.setEdge(s.e,s.label),e.removeNode(t),s.label.points=[{x:r+2*l/3,y:i-d},{x:r+5*l/6,y:i-d},{x:r+l,y:i},{x:r+5*l/6,y:i+d},{x:r+2*l/3,y:i+d}],s.label.x=n.x,s.label.y=n.y}})}function Ug(e,t){return hh(wf(e,t),Number)}function Kg(e){let t={};return e&&Object.entries(e).forEach(([n,s])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=s}),t}function n9(e){let t=$d(e),n=new Us({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(s=>{n.setNode(s,{label:s}),n.setParent(s,"layer"+e.node(s).rank)}),e.edges().forEach(s=>n.setEdge(s.v,s.w,{},s.name)),t.forEach((s,o)=>{let r="layer"+o;n.setNode(r,{rank:"same"}),s.reduce((i,l)=>(n.setEdge(i,l,{style:"invis"}),l))}),n}var s9={graphlib:N4,version:hF,layout:I7,debug:n9,util:{time:F4,notime:q4}},$f=s9;function nr(e,t,n){if(e.length>0&&e.every(r=>r.col!==void 0&&r.row!==void 0))return e.map(r=>({...r,col:r.col,row:r.row}));const o=o9(e.map(r=>r.id),t,n);return e.map(r=>{const i=o.get(r.id)??{col:1,row:1};return{...r,col:i.col,row:i.row}})}function o9(e,t,n){const s=new Set(e),o=new $f.graphlib.Graph;o.setGraph({rankdir:n,nodesep:16,ranksep:16,marginx:0,marginy:0}),o.setDefaultEdgeLabel(()=>({}));for(const l of e)o.setNode(l,{width:10,height:10});for(const l of t)l.from!==l.to&&s.has(l.from)&&s.has(l.to)&&o.setEdge(l.from,l.to);$f.layout(o);const r=e.map(l=>{const d=o.node(l);return{id:l,x:Math.round(d?.x??0),y:Math.round(d?.y??0)}}),i=new Map;return n==="TB"?[...new Set(r.map(d=>d.y))].sort((d,u)=>d-u).forEach((d,u)=>{r.filter(p=>p.y===d).sort((p,h)=>p.x-h.x).forEach((p,h)=>i.set(p.id,{col:h+1,row:u+1}))}):[...new Set(r.map(d=>d.x))].sort((d,u)=>d-u).forEach((d,u)=>{r.filter(p=>p.x===d).sort((p,h)=>p.y-h.y).forEach((p,h)=>i.set(p.id,{col:u+1,row:h+1}))}),i}var r9={agent:"AGENT",llm:"LLM",tool:"TOOL",human:"HUMAN",memory:"MEMORY"};function i9(e,t){const n=new Set(e.map(d=>d.id)),s=new Map,o=new Map;for(const d of e)s.set(d.id,0),o.set(d.id,[]);for(const d of t)!n.has(d.from)||!n.has(d.to)||d.from===d.to||(s.set(d.to,(s.get(d.to)??0)+1),o.get(d.from)?.push(d.to));let r=e.filter(d=>d.kind==="start").map(d=>d.id);r.length===0&&(r=e.filter(d=>(s.get(d.id)??0)===0).map(d=>d.id)),r.length===0&&e[0]!==void 0&&(r=[e[0].id]);const i=new Map,l=[...r];for(;l.length>0;){const d=l.shift();if(!i.has(d)){i.set(d,i.size);for(const u of o.get(d)??[]){const p=(s.get(u)??0)-1;s.set(u,p),p<=0&&!i.has(u)&&l.push(u)}}}for(const d of e)i.has(d.id)||i.set(d.id,i.size);return i}var i$=/^(no|fail|failed|error|reject|rejected)\b/i,a9=160,l9=64,c9=150,a$=52;function d9(e){const t=e.edges??[],n=e.groups??[],s=e.nodes??[],o=!(s.length>0&&s.every(V=>V.col!==void 0&&V.row!==void 0)),r=nr(s,t,e.dir??"LR"),i=a9,l=l9,d=56,u=48,p=Yi(n),h=(n.length>0?Gn.padX:22)+p.padX,m=(n.length>0?Gn.padTop:22)+p.padTop,g=(n.length>0?Gn.padBot:18)+p.padBot,v=wd(n),y=Math.max(1,...r.map(V=>V.col+((V.w??1)-1)),v.cols),b=Math.max(1,...r.map(V=>V.row),v.rows),E=V=>h+(V-1)*(i+d),$=V=>m+(V-1)*(l+u),A=V=>({x:E(V.col),y:$(V.row),w:(V.w??1)*i+((V.w??1)-1)*d,h:l}),T=V=>{const re=A(V);if((V.kind??"process")==="decision")return re;const Q=(i-c9)/2,ne=(l-a$)/2;return{x:re.x+Q,y:re.y+ne,w:re.w-Q*2,h:a$}},N=new Map(r.map(V=>[V.id,V])),j=h*2+y*i+(y-1)*d,P=m+b*l+(b-1)*u+g,I=V=>V.kind==="error"||i$.test(V.label??""),O=new Set(t.filter(I).map(V=>V.to)),C=new Set(r.filter(V=>V.kind==="end"&&!O.has(V.id)&&!i$.test(V.label)).map(V=>V.id)),D=tr({quick:o,cols:y,rows:b,cellW:i,cellH:l,gapX:d,gapY:u,padX:h,padTop:m}),F=Sn("Flowchart",e.title,[wt(r.length,"step")]);let U=`<svg viewBox="0 0 ${j} ${P}"${F.attrs}${D}>${F.title}`;n.length>0&&(U+=xl(n,{xOf:E,yOf:$,cellW:i,cellH:l,gapX:d,gapY:u,skin:!0}));const X={plain:!1,dashed:!1,error:!1,accent:!1},B=[],te=qs(t),ee=i9(r,t),H=V=>ee.get(V)??0,W=Hs(t,V=>{const re=N.get(V);return re!==void 0?T(re):void 0});U+=`<g${he("edges")}>`,t.forEach((V,re)=>{const Q=N.get(V.from),ne=N.get(V.to);if(!Q||!ne)return;const Z=Fs(T(Q),T(ne),te[re]??0,W[re]??0),q=I(V),de=!q&&C.has(V.to),le=!q&&V.kind==="dashed",J=q?"var(--negative)":de?"var(--accent)":"var(--muted)",ue=q?"skErr":de?"skAccent":le?"skOpen":"skArrow",ve=de?1.75:1.5,we=le?' stroke-dasharray="5 4"':"";q?X.error=!0:de?X.accent=!0:le?X.dashed=!0:X.plain=!0;const $e=Math.max(H(V.from),H(V.to));U+=`<path d="${Z.d}" fill="none" stroke="${J}" stroke-width="${ve}"${we} marker-end="url(#${ue})"${_(`edges.${re}`)}${hn($e)}/>`,B.push({lx:Z.lx,ly:Z.ly,...V.label!==void 0?{label:V.label}:{},err:q,accent:de,path:`edges.${re}`,reveal:$e})}),U+="</g>";const K=new Set;U+=`<g${he("nodes")}>`,r.forEach((V,re)=>{const Q=V.kind??"process";K.add(Q);const ne=T(V),Z=ne.x+ne.w/2,q=ne.y+ne.h/2,de=C.has(V.id),le=r9[Q],J=Q==="start"||Q==="memory",ue=de?"var(--accent)":J?"var(--rule-solid)":"var(--ink)",ve=de?1.5:J?1:1.5,we=de?"var(--accent-tint)":J?"var(--paper-2)":"var(--paper)",$e=Q==="human"?' stroke-dasharray="4 3"':"";let je;Q==="decision"?je=`<polygon points="${Z},${ne.y} ${ne.x+ne.w},${q} ${Z},${ne.y+ne.h} ${ne.x},${q}" fill="${we}" stroke="${ue}" stroke-width="${ve}" stroke-linejoin="round"/>`:Q==="start"||Q==="end"?je=`<rect x="${ne.x}" y="${ne.y}" width="${ne.w}" height="${ne.h}" rx="${ne.h/2}" fill="${we}" stroke="${ue}" stroke-width="${ve}"/>`:je=`<rect x="${ne.x}" y="${ne.y}" width="${ne.w}" height="${ne.h}" rx="4" fill="${we}" stroke="${ue}" stroke-width="${ve}"${$e}/>`,le!==void 0&&(je+=`<text x="${ne.x+8}" y="${ne.y+11}" class="blk-chip t-sub">${le}</text>`);const De=V.label.indexOf(`
2837
- `),Me=De>=0?V.label.slice(0,De):V.label,Be=De>=0?V.label.slice(De+1).replace(/\s+/g," ").trim():"",Ge=Q==="decision"?18:20,fe=Be.length>0?lt(Me,Ge,1):lt(Me,Ge,2),ge=de?" c-accent":"",Ce=le!==void 0?4:0;let Fe="";if(Q==="agent"||Q==="llm"){const qe=lt(Me,17,1)[0]??Me;if(Fe=al("agent",ne.x+10,ne.y+19,de?"var(--accent)":"var(--ink)"),Fe+=`<text x="${ne.x+30}" y="${ne.y+30}" class="al-name${ge}">${S(qe)}</text>`,Be.length>0){const ze=Math.min(ne.w-20,12+Be.length*5.6);Fe+=`<rect x="${ne.x+10}" y="${ne.y+36}" width="${ze.toFixed(1)}" height="13" rx="3" fill="var(--paper)" stroke="var(--rule-solid)" stroke-width="1"/><text x="${(ne.x+10+ze/2).toFixed(1)}" y="${ne.y+45.5}" text-anchor="middle" class="al-chip">${S(Be)}</text>`}}else Be.length>0?Fe=`<text x="${Z}" y="${q-1+Ce}" class="fc-label t-name${ge}">${S(fe[0]??Me)}</text><text x="${Z}" y="${q+12+Ce}" class="fc-sub t-sub" text-anchor="middle">${S(Be)}</text>`:Fe=fe.map((qe,ze)=>`<text x="${Z}" y="${q+4.5+Ce-(fe.length-1)*7.5+ze*15}" class="fc-label t-name${ge}">${S(qe)}</text>`).join("");U+=`<g${_(`nodes.${re}`)}${Mo(V.col,V.row,V.w??1)}${hn(H(V.id))}>${je}${Fe}</g>`}),U+="</g>";const{overlay:R,legend:z}=Ws(B,r.map(V=>T(V)),{skin:!0});U+=R,U+="</svg>";const Y=[];return K.has("start")&&Y.push({swatch:"node-fill2",label:"start"}),K.has("process")&&Y.push({swatch:"node",label:"step"}),K.has("decision")&&Y.push({swatch:"node",label:"decision (diamond)"}),K.has("agent")&&Y.push({swatch:"node",label:"AGENT · autonomous step"}),K.has("llm")&&Y.push({swatch:"node",label:"LLM · model call"}),K.has("tool")&&Y.push({swatch:"node",label:"TOOL · retrieval / API / code"}),K.has("human")&&Y.push({swatch:"node-dashed",label:"HUMAN · review gate"}),K.has("memory")&&Y.push({swatch:"node-fill2",label:"MEMORY · store"}),K.has("end")&&[...C].length<r.filter(V=>V.kind==="end").length&&Y.push({swatch:"node",label:"exit"}),X.plain&&Y.push({swatch:"edge",label:"next"}),X.dashed&&Y.push({swatch:"edge-dashed",label:"optional"}),X.error&&Y.push({swatch:"edge-error",label:"error path"}),C.size>0&&Y.push({swatch:"node-accent",label:"happy path"}),{svg:U+z,legend:ot(Y)}}function u9(e,t){const{svg:n,legend:s}=d9(e);return ct({tag:t,...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...s.length>0?{legendHtml:s}:{}},n)}function p9(e){return u9(e,e.variant==="dag"?"DAG":"FLOW")}var l$=/\b(error|fail|failed|failure|reject|rejected|cancel|cancelled|canceled|abort|aborted|timeout|timed out|expired|dead)\b/i;function eA(e){return lt(e.name??"",23,3)}function Aa(e,t,n,s,o,r,i){const l=r+(e.col-1)*(t+s)+t/2,d=i+(e.row-1)*(n+o)+n/2;if(e.kind==="start"||e.kind==="terminal")return{x:l-13,y:d-13,w:26,h:26,cx:l,cy:d};const u=eA(e),p=Math.max(0,...u.map(g=>g.length)),h=Math.max(96,Math.min(p*8+26,t+s-26)),m=46+(Math.max(1,u.length)-1)*15;return{x:l-h/2,y:d-m/2,w:h,h:m,cx:l,cy:d}}function c$(e){return e==="terminal"?"pill pill-end":e==="wait"?"pill pill-wait":e==="start"?"pill pill-init":"pill pill-active"}function f9(e){const t=e.transitions??[],n=e.states??[],s=!(n.length>0&&n.every(Y=>Y.col!==void 0&&Y.row!==void 0)),o=nr(n,t,e.dir??"LR"),r=168,i=64,l=74,d=60,u=e.groups??[],p=Yi(u),h=(u.length>0?Gn.padX:30)+p.padX,m=(u.length>0?Gn.padTop:30)+p.padTop,g=(u.length>0?Gn.padBot:20)+p.padBot,v=wd(u),y=Math.max(1,...o.map(Y=>Y.col),v.cols),b=Math.max(1,...o.map(Y=>Y.row),v.rows),E=h*2+y*r+(y-1)*l,$=m*2+b*i+(b-1)*d+g,A=new Map(o.map(Y=>[Y.id,Y])),T=Y=>Y!==void 0&&Y.kind==="terminal"&&(l$.test(Y.name??"")||l$.test(Y.id)),N=o.filter(Y=>Y.kind==="terminal"&&!T(Y)),j=N.length===1?N[0]?.id:void 0,P=tr({quick:s,cols:y,rows:b,cellW:r,cellH:i,gapX:l,gapY:d,padX:h,padTop:m}),I=Sn("State machine",e.title,[wt(o.length,"state"),wt(t.length,"transition")]);let O=`<svg viewBox="0 0 ${E} ${$}"${I.attrs}${P}>${I.title}`;u.length>0&&(O+=xl(u,{xOf:re=>h+(re-1)*(r+l),yOf:re=>m+(re-1)*(i+d),cellW:r,cellH:i,gapX:l,gapY:d,skin:!0}));const C=t.length>=4,D=[],F={plain:!1,error:!1,accent:!1},U=qs(t),X=o.map(Y=>{const V=Aa(Y,r,i,l,d,h,m);return{x:V.x,y:V.y,w:V.w,h:V.h}}),B=Hs(t,Y=>{const V=A.get(Y);return V!==void 0?Aa(V,r,i,l,d,h,m):void 0});t.forEach((Y,V)=>{const re=A.get(Y.from),Q=A.get(Y.to);if(!re||!Q)return;const ne=Y.event+(Y.guard!==void 0?` ${Y.guard}`:""),Z=T(Q),q=!Z&&j!==void 0&&Y.to===j,de=Z?"var(--negative)":q?"var(--accent)":"var(--muted)",le=Z?"skErr":q?"skAccent":"skArrow",J=q?1.75:1.5,ue=Z?"error":q?"accent":"muted";Z?F.error=!0:q?F.accent=!0:F.plain=!0;const ve=_(`transitions.${V}`)+hn(V);if(Y.from===Y.to){const je=Aa(re,r,i,l,d,h,m);O+=`<path d="M ${je.cx-12} ${je.y} C ${je.cx-30} ${je.y-32}, ${je.cx+30} ${je.y-32}, ${je.cx+12} ${je.y}" fill="none" stroke="${de}" stroke-width="${J}" marker-end="url(#${le})"${ve}/>`;const De={lx:je.cx,ly:je.y-28},Me=C?xf(De,V+1,Z,!0):x0(De,ne,ue);D.push(`<g${ve}>${Me}</g>`);return}const we=Fs(Aa(re,r,i,l,d,h,m),Aa(Q,r,i,l,d,h,m),U[V]??0,B[V]??0);O+=`<path d="${we.d}" fill="none" stroke="${de}" stroke-width="${J}" marker-end="url(#${le})"${ve}/>`;const $e=C?xf(Uy(we.lx,we.ly,X),V+1,Z,!0):x0(we,ne,ue);D.push(`<g${ve}>${$e}</g>`)});const te={active:!1,wait:!1,start:!1,end:!1,errEnd:!1};O+=`<g${he("states")}>`,o.forEach((Y,V)=>{const re=Aa(Y,r,i,l,d,h,m),Q=Mo(Y.col,Y.row);if(Y.kind==="start")te.start=!0,O+=`<circle cx="${re.cx}" cy="${re.cy}" r="10" fill="var(--ink)"${_(`states.${V}`)}${Q}/>`;else if(Y.kind==="terminal"){const ne=Y.id===j,Z=T(Y);Z?te.errEnd=!0:ne||(te.end=!0);const q=ne?"var(--accent)":Z?"var(--negative)":"var(--ink)",de=ne?"var(--accent-tint)":Z?"var(--negative-tint)":"var(--paper)";O+=`<g${_(`states.${V}`)}${Q}><circle cx="${re.cx}" cy="${re.cy}" r="12" fill="${de}" stroke="${q}" stroke-width="1.5"/><circle cx="${re.cx}" cy="${re.cy}" r="6" fill="${q}"/></g>`}else{const ne=Y.kind==="wait";ne?te.wait=!0:te.active=!0;const Z=ne?"var(--paper-2)":"var(--paper)",q=ne?"var(--rule-solid)":"var(--ink)",de=ne?1:1.5,le=eA(Y),J=le.length<=1?`<text x="${re.cx}" y="${re.cy+4.5}" class="t-name" text-anchor="middle"${_(`states.${V}.name`)}>${S(Y.name??"")}</text>`:`<g${_(`states.${V}.name`)}>`+le.map((ue,ve)=>`<text x="${re.cx}" y="${re.cy+4.5-(le.length-1)*7.5+ve*15}" class="t-name" text-anchor="middle">${S(ue)}</text>`).join("")+"</g>";O+=`<g${_(`states.${V}`)}${Q}><rect x="${re.x}" y="${re.y}" width="${re.w}" height="${re.h}" rx="23" fill="${Z}" stroke="${q}" stroke-width="${de}"/>`+J+"</g>"}}),O+="</g>",O+=D.join(""),O+="</svg>";const ee=Y=>A.get(Y)?.name??Y,H=Y=>C?`<td class="t-num"><span class="edge-step"><b>${Y+1}</b></span></td>`:"",W=t.map((Y,V)=>`<tr${_(`transitions.${V}`)}${hn(V)}>`+H(V)+`<td><span class="${c$(A.get(Y.from)?.kind)}">${S(ee(Y.from))}</span></td><td style="font-family:var(--font-mono);font-size:11px"${_(`transitions.${V}.event`)}>${S(Y.event)}</td><td class="c-soft" style="font-size:11px"${_(`transitions.${V}.guard`)}>${S(Y.guard??"—")}</td><td><span class="${c$(A.get(Y.to)?.kind)}">${S(ee(Y.to))}</span></td></tr>`).join(""),K=t.length>0?`<table class="transition-table"><thead><tr>${C?"<th>№</th>":""}<th>From</th><th>Event</th><th>Guard</th><th>To</th></tr></thead><tbody${he("transitions")}>${W}</tbody></table>`:"",R=[];te.start&&R.push({swatch:"chip",chip:"●",label:"start"}),te.active&&R.push({swatch:"node",label:"state"}),te.wait&&R.push({swatch:"node-fill2",label:"waiting"}),te.end&&R.push({swatch:"chip",chip:"◉",label:"end"}),F.plain&&R.push({swatch:"edge",label:"transition"}),te.errEnd&&R.push({swatch:"node-negative",label:"error exit"}),F.error&&R.push({swatch:"edge-error",label:"error transition"}),j!==void 0&&R.push({swatch:"node-accent",label:"success exit"});const z=ot(R);return ct({tag:"STATE",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...z.length>0?{legendHtml:z}:{},...K.length>0?{footerHtml:K}:{}},O)}function tA(e){const t=(e??"process").toLowerCase();return t==="external"?"external":t==="store"||t==="datastore"?"store":"process"}function nA(e,t){const n=Vo(e==="process"?void 0:e),s=t?"var(--accent)":n.primary?"var(--ink)":"var(--rule-solid)",o=t||n.primary?1.5:1,r=t?"var(--accent-tint)":n.fill==="paper-2"?"var(--paper-2)":"var(--paper)",i=n.dashed?' stroke-dasharray="4 3"':"",l=t?" c-accent":n.fill==="paper-2"?" c-muted":"";return{skin:n,stroke:s,sw:o,fill:r,dash:i,chipTone:l}}function sA(e,t,n){return e==="process"?`<rect x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" rx="16" fill="${n.fill}" stroke="${n.stroke}" stroke-width="${n.sw}"/>`:e==="store"?`<rect x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" fill="${n.fill}" stroke="none"/><path d="M${t.x+t.w} ${t.y} H ${t.x} V ${t.y+t.h} H ${t.x+t.w}" fill="none" stroke="${n.stroke}" stroke-width="${n.sw}"/>`:`<rect x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" fill="${n.fill}" stroke="${n.stroke}" stroke-width="${n.sw}"${n.dash}/>`}function oA(e,t){return t.skin.chip!==""?`<text x="${e.x+e.w-10}" y="${e.y+14}" class="t-eyebrow${t.chipTone}" text-anchor="end">${S(t.skin.chip)}</text>`:""}function rA(e,t,n,s,o){const r=n.x+n.w/2,i=n.y+n.h/2,l=s?" c-accent":"";return e.length<=1?`<text x="${r}" y="${i+4}" class="t-name${l}" text-anchor="middle"${_(o)}>${S(t)}</text>`:`<g${_(o)}>`+e.map((d,u)=>`<text x="${r}" y="${i+4-(e.length-1)*7+u*14}" class="t-name${l}" text-anchor="middle">${S(d)}</text>`).join("")+"</g>"}var d$=tA;function h9(e){const t=e.edges??[],n=e.nodes??[],s=!(n.length>0&&n.every(z=>z.col!==void 0&&z.row!==void 0)),o=nr(n,t,e.dir??"LR"),r=148,i=o.map(z=>lt(z.name,20,3)),d=66+(Math.max(1,...i.map(z=>z.length))-1)*14,u=104,p=54,h=e.groups??[],m=Yi(h),g=(h.length>0?Gn.padX:26)+m.padX,v=(h.length>0?Gn.padTop:26)+m.padTop,y=(h.length>0?Gn.padBot:20)+m.padBot,b=wd(h),E=Math.max(1,...o.map(z=>z.col),b.cols),$=Math.max(1,...o.map(z=>z.row),b.rows),A=z=>g+(z-1)*(r+u),T=z=>v+(z-1)*(d+p),N=z=>({x:A(z.col),y:T(z.row),w:r,h:d}),j=new Map(o.map(z=>[z.id,z])),P=g*2+E*r+(E-1)*u,I=v+$*d+($-1)*p+y,O=o.filter(z=>d$(z.kind)==="external"),C=O.length===1?O[0]?.id:void 0,D=tr({quick:s,cols:E,rows:$,cellW:r,cellH:d,gapX:u,gapY:p,padX:g,padTop:v}),F=Sn("Data-flow diagram",e.title,[wt(o.length,"node"),wt(t.length,"flow")]);let U=`<svg viewBox="0 0 ${P} ${I}"${F.attrs}${D}>${F.title}`;h.length>0&&(U+=xl(h,{xOf:A,yOf:T,cellW:r,cellH:d,gapX:u,gapY:p,skin:!0}));const X=[],B=qs(t),te=Hs(t,z=>{const Y=j.get(z);return Y!==void 0?N(Y):void 0});U+=`<g${he("edges")}>`,t.forEach((z,Y)=>{const V=j.get(z.from),re=j.get(z.to);if(!V||!re)return;const Q=Fs(N(V),N(re),B[Y]??0,te[Y]??0);U+=`<path d="${Q.d}" fill="none" stroke="var(--muted)" stroke-width="1.5" marker-end="url(#skArrow)"${_(`edges.${Y}`)}/>`,X.push({lx:Q.lx,ly:Q.ly,...z.label!==void 0?{label:z.label}:{},path:`edges.${Y}`})}),U+="</g>";const ee=new Set;U+=`<g${he("nodes")}>`,o.forEach((z,Y)=>{const V=N(z),re=d$(z.kind);ee.add(re);const Q=z.id===C,ne=nA(re,Q),Z=sA(re,V,ne),q=oA(V,ne),de=z.num!==void 0&&re==="process"?`<text x="${V.x+12}" y="${V.y+16}" class="t-badge"${_(`nodes.${Y}.num`)}>${S(z.num)}</text>`:"",le=rA(i[Y]??[],z.name,V,Q,`nodes.${Y}.name`);U+=`<g${_(`nodes.${Y}`)}${Mo(z.col,z.row)}>${Z}${q}${de}${le}</g>`}),U+="</g>";const{overlay:H,legend:W}=Ws(X,o.map(z=>N(z)),{skin:!0});U+=H,U+="</svg>";const K=[];ee.has("process")&&K.push({swatch:"node",label:"process"}),ee.has("external")&&C===void 0&&K.push({swatch:"node-dashed",label:"external entity"}),ee.has("store")&&K.push({swatch:"node-store",label:"data store"}),t.length>0&&K.push({swatch:"edge",label:"data flow"}),C!==void 0&&K.push({swatch:"node-accent",label:"external entity"});const R=ot(K);return ct({tag:"DFD",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...R.length>0?{legendHtml:R}:{}},U+W)}function m9(e){return e<0?0:e>1?1:e}function g9(e){return e>=.6?"high":e<=.35?"low":"mid"}var v9={high:`fill="var(--ink)" stroke="var(--paper)" stroke-width="1.5"${ut}`,mid:'fill="var(--paper)" stroke="var(--ink)" stroke-width="1.5"',low:`fill="var(--negative)" stroke="var(--paper)" stroke-width="1.5"${ut}`},y9={high:{swatch:"fill",fill:"var(--ink)",label:"positive"},mid:{swatch:"node",label:"neutral"},low:{swatch:"fill",fill:"var(--negative)",label:"negative"}};function x9(e){const t=e.stages??[],n=e.rows??[],s=e.emotion??[],o=Math.max(t.length,1),r=Math.max(380,o*150),i=92,l=20,d=(r-l*2)/o,u=v=>l+d*(v+.5),p=v=>i-14-(i-30)*m9(v),h=`<tr${he("stages")}><th></th>`+t.map((v,y)=>`<th class="c"${_(`stages.${y}`)}>${S(v.label)}</th>`).join("")+"</tr>",m=n.map((v,y)=>`<tr${_(`rows.${y}`)}><td class="lead"${_(`rows.${y}.label`)}>${S(v.label)}</td>`+(v.cells??[]).map((b,E)=>`<td class="c"${_(`rows.${y}.cells.${E}`)}>${S(b)}</td>`).join("")+"</tr>").join("");let g="";if(s.length>0){const v=new Set,y=s.map(($,A)=>`${u(A)},${p($)}`).join(" "),b=s.map(($,A)=>{const T=g9($);return v.add(T),`<circle cx="${u(A)}" cy="${p($)}" r="5" ${v9[T]}${_(`emotion.${A}`)}/>`}).join(""),E=ot(["high","mid","low"].filter($=>v.has($)).map($=>y9[$]));g=`<div class="jr-emotion"><div class="jr-emotion-label t-eyebrow">Emotion</div><svg viewBox="0 0 ${r} ${i}" style="width:100%" role="img"><title>Emotion curve</title><polyline points="${y}" fill="none" stroke="var(--ink)" stroke-width="1.5" stroke-linejoin="round"/><g${he("emotion")}>${b}</g></svg>${E}</div>`}return`<div><table class="pres-table"><thead>${h}</thead><tbody${he("rows")}>${m}</tbody></table>`+g+"</div>"}function k9(e){switch((e??"").toLowerCase()){case"done":return"done";case"active":case"current":return"active";case"milestone":return"milestone";default:return"planned"}}var b9={planned:'fill="var(--paper-2)" stroke="var(--ink)" stroke-width="1"',done:'fill="var(--ink)" stroke="var(--ink)" stroke-width="1"',active:'fill="var(--accent-tint)" stroke="var(--accent)" stroke-width="1.5"',milestone:'fill="var(--paper)" stroke="var(--ink)" stroke-width="1.25" stroke-dasharray="4 3"'},w9={planned:{swatch:"node-fill2",label:"planned"},done:{swatch:"fill",fill:"var(--ink)",label:"done"},active:{swatch:"node-accent",label:"in progress"},milestone:{swatch:"node-dashed",label:"milestone"}};function $9(e,t,n,s){const o=e.length>s?`${e.slice(0,Math.max(1,s-1))}…`:e,r=o===e?"":`<title>${S(e)}</title>`;return`<text x="${t}" y="${n}" class="t-eyebrow" text-anchor="middle">${r}${S(o)}</text>`}function S9(e){const t=e.periods??[],n=e.tasks??[],s=Math.max(t.length,1),o=156,r=20,i=18,l=64,d=6.6,u=I=>I.length*d,p=t.some(I=>u(I)>l-6),h=Math.max(1,Math.floor(((p?l*2:l)-6)/d)),m=p?48:34,g=14,v=n.map(I=>lt(I.label,Math.floor((o-r)/7),3)),b=30+(Math.max(1,...v.map(I=>I.length))-1)*14,E=o+r*2+s*l,$=m+n.length*b+g,A=I=>o+r+I*l;let T=`<svg viewBox="0 0 ${E} ${$}" role="img"><title>Schedule</title>`;T+=`<g${he("periods")}>`;for(let I=0;I<t.length;I++)T+=`<g${_(`periods.${I}`)}><line x1="${A(I)}" y1="${m-6}" x2="${A(I)}" y2="${$-g}" stroke="var(--rule)" stroke-width="1"${ut}/>`+$9(t[I]??"",A(I)+l/2,m-12-(p&&I%2===0?14:0),h)+"</g>";T+="</g>",T+=`<line x1="${A(s)}" y1="${m-6}" x2="${A(s)}" y2="${$-g}" stroke="var(--rule)" stroke-width="1"${ut}/>`;const N=new Set;T+=`<g${he("tasks")}>`;for(let I=0;I<n.length;I++){const O=n[I];if(O===void 0)continue;const C=k9(O.kind);N.add(C);const D=m+I*b,F=A(O.start??0),X=Math.max(1,O.span??1)*l-8,B=v[I]??[],te=C==="active"?"t-name c-accent":"t-name",ee=B.length<=1?`<text x="${r}" y="${D+b/2+4.5}" class="${te}"${_(`tasks.${I}.label`)}>${S(O.label)}</text>`:`<g${_(`tasks.${I}.label`)}>`+B.map((H,W)=>`<text x="${r}" y="${D+b/2+4.5-(B.length-1)*7+W*14}" class="${te}">${S(H)}</text>`).join("")+"</g>";T+=`<g${_(`tasks.${I}`)}>`+ee+`<rect x="${F+4}" y="${D+(b-i)/2}" width="${X}" height="${i}" rx="2" ${b9[C]}/></g>`}T+="</g>",T+="</svg>";const j=["planned","done","active","milestone"].filter(I=>N.has(I)).map(I=>w9[I]),P=ot(j);return ct({tag:"GANTT",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...P.length>0?{legendHtml:P}:{}},T)}function E9(e){const t=e.edges??[],n=e.nodes??[],s=!(n.length>0&&n.every(R=>R.col!==void 0&&R.row!==void 0)),o=nr(n,t,"LR"),r=150,i=84,l=44,d=40,u=26,p=24,h=20,m=Math.max(1,...o.map(R=>R.col)),g=Math.max(1,...o.map(R=>R.row)),v=R=>u+(R-1)*(r+l)+r/2,y=R=>p+(R-1)*(i+d)+i/2,b=R=>{const z=v(R.col),Y=y(R.row),V=Math.max(98,Math.min(R.label.length*8+26,r+l-10));return{x:z-V/2,y:Y-20,w:V,h:40,cx:z,cy:Y}},E=new Map(o.map(R=>[R.id,R])),$=u*2+m*r+(m-1)*l,A=p+g*i+(g-1)*d+h,T=o.filter(R=>R.state==="target"),N=o.filter(R=>R.state==="current"),j=T.length===1?T[0]?.id:T.length===0&&N.length===1?N[0]?.id:void 0,P=o.some(R=>R.state!==void 0||R.group!==void 0),I=tr({quick:s,cols:m,rows:g,cellW:r,cellH:i,gapX:l,gapY:d,padX:u,padTop:p});let O=`<svg viewBox="0 0 ${$} ${A}" role="img"${I}><title>Graph</title>`;const C=[],D=qs(t),F=Hs(t,R=>{const z=E.get(R);return z!==void 0?b(z):void 0});let U=!1,X=!1;O+=`<g${he("edges")}>`,t.forEach((R,z)=>{const Y=E.get(R.from),V=E.get(R.to);if(!Y||!V)return;const re=Fs(b(Y),b(V),D[z]??0,F[z]??0),Q=(R.dir??"directed")!=="undirected";Q?U=!0:X=!0;const ne=Q?' marker-end="url(#skArrow)"':"";O+=`<path d="${re.d}" fill="none" stroke="var(--muted)" stroke-width="1.5"${ne}${_(`edges.${z}`)}/>`;const Z=R.weight!==void 0?R.label!==void 0&&R.label.length>0?`${R.label} · ${R.weight}`:String(R.weight):R.label;C.push({lx:re.lx,ly:re.ly,...Z!==void 0?{label:Z}:{},path:`edges.${z}`})}),O+="</g>";const B=new Set;let te=!1;O+=`<g${he("nodes")}>`,o.forEach((R,z)=>{const Y=b(R),V=R.id===j,re=R.state;re!==void 0&&B.add(re);const Q=re==="visited",ne=V?"var(--accent)":Q?"var(--rule-solid)":"var(--ink)",Z=V?"var(--accent-tint)":Q?"var(--paper-2)":"var(--paper)",q=V?1.5:Q?1:1.5,de=re==="frontier"?' stroke-dasharray="4 3"':"",le=V?" c-accent":Q?" c-muted":"",J=re!==void 0?`<text x="${Y.x+14}" y="${Y.y+11}" class="t-eyebrow${le}">${re.toUpperCase()}</text>`:"";let ue="";R.group!==void 0&&(te=!0,ue=`<text x="${Y.x+Y.w-14}" y="${Y.y+11}" class="t-eyebrow${le}" text-anchor="end">G${R.group}</text>`);const ve=Y.cy+4+(P?3:0);O+=`<g${_(`nodes.${z}`)}${Mo(R.col,R.row)}><rect x="${Y.x}" y="${Y.y}" width="${Y.w}" height="${Y.h}" rx="20" fill="${Z}" stroke="${ne}" stroke-width="${q}"${de}/>`+J+ue+`<text x="${Y.cx}" y="${ve}" class="t-name${V?" c-accent":""}" text-anchor="middle">${S(R.label.length>21?`${R.label.slice(0,20)}…`:R.label)}</text></g>`}),O+="</g>";const{overlay:ee,legend:H}=Ws(C,o.map(R=>b(R)),{skin:!0});O+=ee,O+="</svg>";const W=[];o.some(R=>R.state===void 0)&&W.push({swatch:"node",label:"node"}),B.has("visited")&&W.push({swatch:"node-fill2",label:"visited"}),B.has("frontier")&&W.push({swatch:"node-dashed",label:"frontier"}),B.has("current")&&W.push({swatch:"chip",chip:"CURRENT",label:"current"}),B.has("target")&&W.push({swatch:"chip",chip:"TARGET",label:"target"}),te&&W.push({swatch:"chip",chip:"G1",label:"group"}),U&&W.push({swatch:"edge",label:"edge"}),X&&W.push({swatch:"edge",label:"undirected (no head)"}),j!==void 0&&W.push({swatch:"node-accent",label:T.length===1?"target":"current"});const K=ot(W);return ct({tag:"GRAPH",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...K.length>0?{legendHtml:K}:{}},O+H)}function u$(e){return e===void 0||Number.isNaN(e)?.5:e<0?0:e>1?1:e}function M9(e){const s=e.yAxis??{},o=Math.max(56,18+Math.ceil(Math.max(0,...[s.high,s.low].map($=>($??"").length*6.2)))),r=580+(o-56),i=o,l=r-56,d=40,u=384,p=(i+l)/2,h=(d+u)/2,m=$=>i+(l-i)*u$($),g=$=>u-(u-d)*u$($),v=e.items??[],y=e.xAxis??{},b=e.yAxis??{};let E=`<svg viewBox="0 0 ${r} 440" role="img"><title>Quadrant</title>`;return E+=`<rect x="${i}" y="${d}" width="${l-i}" height="${u-d}" fill="var(--paper)" stroke="var(--rule-solid)" stroke-width="1"/>`,E+=`<rect x="${p}" y="${d}" width="${l-p}" height="${h-d}" fill="var(--paper-2)"/>`,E+=`<line x1="${i}" y1="${h}" x2="${l}" y2="${h}" stroke="var(--muted)" stroke-width="1.25" marker-end="url(#skArrow)"/>`,E+=`<line x1="${p}" y1="${u}" x2="${p}" y2="${d}" stroke="var(--muted)" stroke-width="1.25" marker-end="url(#skArrow)"/>`,y.label!==void 0&&(E+=`<text x="${l}" y="${u+30}" class="t-eyebrow" text-anchor="end"${_("xAxis.label")}>${S(y.label)} →</text>`),b.label!==void 0&&(E+=`<text x="${p-8}" y="${d-4}" class="t-eyebrow" text-anchor="end"${_("yAxis.label")}>↑ ${S(b.label)}</text>`),y.low!==void 0&&(E+=`<text x="${i}" y="${u+16}" class="t-sub c-soft" text-anchor="start"${_("xAxis.low")}>${S(y.low)}</text>`),y.high!==void 0&&(E+=`<text x="${l}" y="${u+16}" class="t-sub c-soft" text-anchor="end"${_("xAxis.high")}>${S(y.high)}</text>`),b.high!==void 0&&(E+=`<text x="${i-10}" y="${d+6}" class="t-sub c-soft" text-anchor="end"${_("yAxis.high")}>${S(b.high)}</text>`),b.low!==void 0&&(E+=`<text x="${i-10}" y="${u}" class="t-sub c-soft" text-anchor="end"${_("yAxis.low")}>${S(b.low)}</text>`),E+=`<g${he("items")}>`,v.forEach(($,A)=>{const T=m($.x),N=g($.y),j=T>p,P=T+(j?-12:12),I=j?"end":"start";E+=`<g${_(`items.${A}`)}><circle cx="${T}" cy="${N}" r="5.5" fill="var(--ink)" stroke="var(--paper)" stroke-width="1.5"${ut}/><text x="${P}" y="${N+4.5}" class="t-name" text-anchor="${I}"${_(`items.${A}.label`)}>${S($.label)}</text></g>`}),E+="</g>",E+="</svg>",ct({tag:"2×2",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{}},E)}var A9={action:"",decision:"DECISION",start:"",end:"",wait:"WAIT"};function C9(e){const t=e.lanes??[],n=e.steps??[],s=e.links??[],o=e.phases??[],{placements:r,derived:i}=oR(e),l=132,d=18,u=20,p=168,h=34,m=150,g=o.length>0?26:0,v=24+g,y=n.map(re=>lt(re.label,18,3)),b=Math.max(1,...y.map(re=>re.length)),$=n.some(re=>re.note!==void 0&&re.note!=="")?12:0,A=52+Math.max(0,b-2)*14+$,T=92+Math.max(0,b-2)*14+$,N=Math.max(1,...r.map(re=>re.col),...o.map(re=>re.to??re.from)),j=re=>l+d+(re-1)*(p+h),P=re=>v+re*T,I=re=>({x:j(re.col)+(p-m)/2,y:P(re.lane)+(T-A)/2,w:m,h:A}),O=new Map;n.forEach((re,Q)=>{const ne=r[Q];ne!==void 0&&!O.has(re.id)&&O.set(re.id,ne)});const C=l+d*2+N*p+(N-1)*h,D=Math.max(1,t.length)*T,F=v+D+u,U=tr({quick:i,cols:N,rows:Math.max(1,t.length),cellW:p,cellH:T,gapX:h,gapY:0,padX:l+d,padTop:v});let X=`<svg viewBox="0 0 ${C} ${F}" role="img"${U}><title>Swimlane</title>`;X+=`<g${he("lanes")}>`;for(let re=0;re<t.length;re++){const Q=t[re];if(Q===void 0)continue;const ne=lt(Q.label,Math.max(8,Math.floor((l-28)/7)),3),Z=ne.map((q,de)=>`<text x="${d+14}" y="${(P(re)+T/2+4-(ne.length-1)*8+de*16).toFixed(1)}" class="t-name">${S(q)}</text>`).join("");X+=`<g${_(`lanes.${re}`)}><rect x="${d}" y="${P(re)}" width="${C-d*2}" height="${T}" fill="var(--paper)" stroke="var(--rule-solid)" stroke-width="1"/><rect x="${d}" y="${P(re)}" width="${l}" height="${T}" fill="var(--paper-2)" stroke="var(--rule-solid)" stroke-width="1"/>`+Z+"</g>"}if(X+="</g>",o.length>0){const re=v-g,Q=v+D;X+=`<g${he("phases")}>`,o.forEach((ne,Z)=>{const q=Math.min(ne.from,N),de=Math.min(Math.max(ne.to??N,q),N),le=q===1?d+l:j(q)-h/2,J=de===N?C-d:j(de)+p+h/2,ue=(q>1?`<line x1="${le}" y1="${re}" x2="${le}" y2="${Q}" stroke="var(--rule-solid)" stroke-width="1" stroke-dasharray="4 3"/>`:"")+(de<N?`<line x1="${J}" y1="${re}" x2="${J}" y2="${Q}" stroke="var(--rule-solid)" stroke-width="1" stroke-dasharray="4 3"/>`:""),ve=lt(ne.label,Math.max(6,Math.floor((J-le-16)/7)),1)[0]??"";X+=`<g${_(`phases.${Z}`)}><rect x="${le}" y="${re}" width="${J-le}" height="${g}" fill="var(--paper-2)" stroke="var(--rule-solid)" stroke-width="1"/><text x="${(le+J)/2}" y="${re+g/2+3}" class="t-eyebrow" text-anchor="middle">${S(ve.toUpperCase())}</text>`+ue+"</g>"}),X+="</g>"}const B=[],te=qs(s),ee=Hs(s,re=>{const Q=O.get(re);return Q!==void 0?I(Q):void 0}),H={plain:!1,dashed:!1,error:!1};X+=`<g${he("links")}>`,s.forEach((re,Q)=>{const ne=O.get(re.from),Z=O.get(re.to);if(!ne||!Z)return;const q=Fs(I(ne),I(Z),te[Q]??0,ee[Q]??0),de=re.kind==="error",le=re.kind==="dashed",J=de?"var(--negative)":"var(--muted)",ue=de?"skErr":le?"skOpen":"skArrow",ve=le?' stroke-dasharray="5 4"':"";de?H.error=!0:le?H.dashed=!0:H.plain=!0,X+=`<path d="${q.d}" fill="none" stroke="${J}" stroke-width="1.5"${ve} marker-end="url(#${ue})"${_(`links.${Q}`)}/>`,B.push({lx:q.lx,ly:q.ly,...re.label!==void 0?{label:re.label}:{},path:`links.${Q}`,...de?{err:!0}:{}})}),X+="</g>";const W=new Set;let K=!1;X+=`<g${he("steps")}>`,n.forEach((re,Q)=>{const ne=r[Q]??{col:1,lane:0},Z=I(ne),q=re.kind??"action";W.add(q);const de=re.accent===!0;de&&(K=!0);const le=!de&&(q==="start"||q==="wait"),J=de?"var(--accent-tint)":le?"var(--paper-2)":"var(--paper)",ue=de?"var(--accent)":le?"var(--rule-solid)":"var(--ink)",ve=le?1:1.5,we=q==="start"||q==="end"?Z.h/2:4,$e=A9[q],je=$e!==""?`<text x="${Z.x+10}" y="${Z.y+12}" class="t-eyebrow${de?" c-accent":le?" c-muted":""}">${$e}</text>`:"",De=re.note!==void 0&&re.note!==""?re.note:void 0,Me=($e!==""?5:0)-(De!==void 0?6:0),Be=y[Q]??[],Ge=Be.map((ge,Ce)=>`<text x="${Z.x+Z.w/2}" y="${Z.y+Z.h/2+4+Me-(Be.length-1)*7+Ce*14}" class="t-name" text-anchor="middle">${S(ge)}</text>`).join(""),fe=De!==void 0?`<text x="${Z.x+Z.w/2}" y="${Z.y+Z.h-9}" class="t-sub" text-anchor="middle">${S(lt(De,24,1)[0]??"")}</text>`:"";X+=`<g${_(`steps.${Q}`)}${Mo(ne.col,ne.lane+1)}><rect x="${Z.x}" y="${Z.y}" width="${Z.w}" height="${Z.h}" rx="${we}" fill="${J}" stroke="${ue}" stroke-width="${ve}"/>`+je+Ge+fe+"</g>"}),X+="</g>";const{overlay:R,legend:z}=Ws(B,r.map(re=>I(re)),{skin:!0});X+=R,X+="</svg>";const Y=[];W.has("start")&&Y.push({swatch:"node-stadium-fill2",label:"start"}),W.has("action")&&Y.push({swatch:"node",label:"step"}),W.has("decision")&&Y.push({swatch:"chip",chip:"DECISION",label:"decision"}),W.has("wait")&&Y.push({swatch:"chip",chip:"WAIT",label:"waiting"}),W.has("end")&&Y.push({swatch:"node-stadium",label:"end"}),K&&Y.push({swatch:"node-accent",label:"focal step"}),H.plain&&Y.push({swatch:"edge",label:"next"}),H.dashed&&Y.push({swatch:"edge-dashed",label:"message"}),H.error&&Y.push({swatch:"edge-error",label:"error path"});const V=ot(Y);return ct({tag:"LANES",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...V.length>0?{legendHtml:V}:{}},X+z)}var N9={PERSON:"person",SYSTEM:"software system",EXT:"external system",DB:"database",CONTAINER:"container",COMPONENT:"component"};function T9(e){const t=(e.family??"").toLowerCase();switch(e.kind){case"person":return{chip:"PERSON",primary:!0,fill:"paper",dashed:!1};case"system":return{chip:"SYSTEM",primary:!0,fill:"paper",dashed:!1};case"external":return Vo("external");case"store":return Vo("store");case"container":case"component":{const n=e.kind==="container"?"CONTAINER":"COMPONENT";return t==="external"?{chip:n,primary:!0,fill:"paper",dashed:!0}:t==="store"||t==="data"?{chip:n,primary:!1,fill:"paper-2",dashed:!1}:{chip:n,primary:!0,fill:"paper",dashed:!1}}default:return Vo(e.kind)}}function p$(e,t){return t.join(" ").split(/\s+/).filter(Boolean).length<e.trim().split(/\s+/).filter(Boolean).length}function _9(e){if(e===void 0||e.trim()==="")return;let t=lt(e,32,3);if(!p$(e,t))return{lines:t,small:!1,clipped:!1};if(t=lt(e,36,3),!p$(e,t))return{lines:t,small:!0,clipped:!1};const n=t[t.length-1];return n!==void 0&&(t[t.length-1]=`${n.replace(/[.,;:]?$/,"")}…`),{lines:t,small:!0,clipped:!0}}function L9(e){return e==="component"?"CONTAINER":e==="container"?"SYSTEM":"BOUNDARY"}function I9(e){const t=e.edges??[],n=e.nodes??[],s=!(n.length>0&&n.every(q=>q.col!==void 0&&q.row!==void 0)),o=nr(n,t,e.dir??"LR"),r=new Map(o.map(q=>[q.id,q])),i=212,l=o.map(q=>_9(q.desc)),d=o.map((q,de)=>{const J=l[de]?.lines.length??0,ue=q.kind==="store"?86:76,ve=q.kind==="store"?16:8;return J>0?ue+(J-1)*13+ve:0}),u=Math.max(112,...d),p=56,h=64,m=e.groups??[],g=Yi(m),v=(m.length>0?Gn.padX:26)+g.padX,y=(m.length>0?Gn.padTop:46)+g.padTop,b=(m.length>0?Gn.padBot:24)+g.padBot,E=wd(m),$=Math.max(1,...o.map(q=>q.col+((q.w??1)-1)),E.cols),A=Math.max(1,...o.map(q=>q.row),E.rows),T=q=>({x:v+(q.col-1)*(i+p),y:y+(q.row-1)*(u+h),w:(q.w??1)*i+((q.w??1)-1)*p,h:u}),N=v*2+$*i+($-1)*p,j=y+A*u+(A-1)*h+b,P=e.level===void 0||e.level==="context",I=o.filter(q=>q.kind==="system"),O=P&&I.length===1?I[0]?.id:void 0,C=L9(e.level),D=(q,de,le)=>{if(q.length===0)return"";const J=Math.min(...q.map(Me=>Me.x))-16,ue=Math.min(...q.map(Me=>Me.y))-26,ve=Math.max(...q.map(Me=>Me.x+Me.w))+16,we=Math.max(...q.map(Me=>Me.y+Me.h))+16,$e=Fi(le,""),je=$e.length>0?$e:"var(--rule-solid)",De=$e.length>0?$e:"var(--soft)";return`<g><rect x="${J}" y="${ue}" width="${ve-J}" height="${we-ue}" rx="6" fill="var(--paper-2)" fill-opacity="0.6" stroke="${je}" stroke-width="1"/><text x="${J+12}" y="${ue+16}" class="t-eyebrow" fill="${De}">${S(de)}</text><text x="${ve-12}" y="${ue+16}" class="t-eyebrow" fill="${De}" text-anchor="end">${C}</text></g>`};let F="";if(e.boundary!==void 0){const q=o.filter(de=>de.kind==="container"||de.kind==="component"||de.kind==="store").map(T);F=D(q,e.boundary.label)}let U="";for(const q of e.boundaries??[]){const de=q.nodes.map(le=>r.get(le)).filter(le=>le!==void 0).map(T);U+=D(de,q.label,q.color)}const X=tr({quick:s,cols:$,rows:A,cellW:i,cellH:u,gapX:p,gapY:h,padX:v,padTop:y}),B=m.length>0?xl(m,{xOf:q=>v+(q-1)*(i+p),yOf:q=>y+(q-1)*(u+h),cellW:i,cellH:u,gapX:p,gapY:h,skin:!0}):"",te=Sn("C4 diagram",e.title,[wt(o.length,"element"),wt(t.length,"relationship")]);let ee=`<svg viewBox="0 0 ${N} ${j}"${te.attrs}${X}>${te.title}${B}${F}${U}`;const H=[],W=new Set,K=qs(t),R=Hs(t,q=>{const de=r.get(q);return de!==void 0?T(de):void 0});ee+=`<g${he("edges")}>`,t.forEach((q,de)=>{const le=r.get(q.from),J=r.get(q.to);if(!le||!J)return;const ue=Fs(T(le),T(J),K[de]??0,R[de]??0),ve=q.kind??"solid";W.add(ve);const we=Qo[ve]??Qo.solid??{stroke:"var(--muted)",sw:1.5,dash:"",marker:"skArrow",err:!1},$e=we.dash.length>0?` stroke-dasharray="${we.dash}"`:"";ee+=`<path d="${ue.d}" fill="none" stroke="${we.stroke}" stroke-width="${we.sw}"${$e} marker-end="url(#${we.marker})"${_(`edges.${de}`)}/>`;const je=q.tech!==void 0?`${q.label!==void 0?`${q.label} `:""}[${q.tech}]`:q.label;H.push({lx:ue.lx,ly:ue.ly,...je!==void 0?{label:je}:{},err:we.err,path:`edges.${de}`})}),ee+="</g>";const z=new Set;let Y=!1,V=!1;ee+=`<g${he("nodes")}>`,o.forEach((q,de)=>{const le=T(q),J=T9(q),ue=q.id===O;J.chip!==""&&z.add(J.chip),J.dashed&&(Y=!0),J.fill==="paper-2"&&(V=!0);const ve=le.x+le.w/2,we=ue?"var(--accent)":J.primary?"var(--ink)":"var(--rule-solid)",$e=ue||J.primary?1.5:1,je=ue?"var(--accent-tint)":J.fill==="paper-2"?"var(--paper-2)":"var(--paper)",De=J.dashed?' stroke-dasharray="4 3"':"",Me=q.kind==="store",Be=Me?10:0,Ge=l[de]??{lines:[],small:!1,clipped:!1},fe=Me?`<path d="M${le.x} ${le.y+12} A ${le.w/2} 12 0 0 1 ${le.x+le.w} ${le.y+12} V ${le.y+le.h-12} A ${le.w/2} 12 0 0 1 ${le.x} ${le.y+le.h-12} Z" fill="${je}" stroke="${we}" stroke-width="${$e}"${De}/><path d="M${le.x} ${le.y+12} A ${le.w/2} 12 0 0 0 ${le.x+le.w} ${le.y+12}" fill="none" stroke="${we}" stroke-width="${$e}"${De}/>`:`<rect x="${le.x}" y="${le.y}" width="${le.w}" height="${le.h}" rx="6" fill="${je}" stroke="${we}" stroke-width="${$e}"${De}/>`,ge=q.kind==="person"?al("person",le.x+le.w-28,le.y+10,"var(--muted)"):"",Ce=J.fill==="paper-2",Fe=ue?" c-accent":Ce?" c-muted":"",qe=Ce?" c-muted":" c-soft",ze=J.chip!==""?`<text x="${ve}" y="${le.y+18+Be}" class="t-eyebrow${Fe}" text-anchor="middle">${S(J.chip)}</text>`:"",Xe=q.tech!==void 0?`<text x="${ve}" y="${le.y+56+Be}" class="t-sub${Ce?" c-muted":""}" text-anchor="middle">${S(q.tech)}</text>`:"",pt=Ge.small?' style="font-size:9px"':"",kt=Ge.lines.map((Nt,Bt)=>`<text x="${ve}" y="${le.y+76+Be+Bt*13}" class="t-sub${qe}"${pt} text-anchor="middle">${S(Nt)}</text>`).join(""),St=Ge.clipped?`<title>${S(q.desc??"")}</title>`:"";ee+=`<g${_(`nodes.${de}`)}${Mo(q.col,q.row,q.w??1)}>`+St+fe+ge+ze+`<text x="${ve}" y="${le.y+40+Be}" class="t-name${ue?" c-accent":""}" text-anchor="middle">${S(q.name)}</text>`+Xe+kt+"</g>"}),ee+="</g>";const{overlay:re,legend:Q}=Ws(H,o.map(q=>T(q)),{skin:!0});ee+=re,ee+="</svg>";const ne=[];for(const q of z)ne.push({swatch:"chip",chip:q,label:N9[q]??q.toLowerCase()});Y&&ne.push({swatch:"node-dashed",label:"outside the boundary"}),V&&ne.push({swatch:"node-fill2",label:"data store"}),W.has("solid")&&ne.push({swatch:"edge",label:"uses"}),W.has("dashed")&&ne.push({swatch:"edge-dashed",label:"async / optional"}),W.has("forbidden")&&ne.push({swatch:"edge-error",label:"forbidden"}),W.has("error")&&ne.push({swatch:"edge-error",label:"error"}),O!==void 0&&ne.push({swatch:"node-accent",label:"the system in scope"});const Z=ot(ne);return ct({tag:e.level!==void 0?`C4 · ${e.level.toUpperCase()}`:"C4",tagClass:"c4",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...Z.length>0?{legendHtml:Z}:{}},ee+Q)}function j9(e,t=7){const n=i=>Math.round(i*10)/10,s=e[0];if(s===void 0)return"";let o=`M${n(s.x)},${n(s.y)}`;for(let i=1;i<e.length-1;i++){const l=e[i],d=e[i-1],u=e[i+1];if(l===void 0||d===void 0||u===void 0)continue;const p=Math.hypot(l.x-d.x,l.y-d.y)||1,h=Math.hypot(u.x-l.x,u.y-l.y)||1,m=Math.min(t,p/2),g=Math.min(t,h/2),v={x:l.x+(d.x-l.x)/p*m,y:l.y+(d.y-l.y)/p*m},y={x:l.x+(u.x-l.x)/h*g,y:l.y+(u.y-l.y)/h*g};o+=` L${n(v.x)},${n(v.y)} Q${n(l.x)},${n(l.y)} ${n(y.x)},${n(y.y)}`}const r=e[e.length-1];return r!==void 0&&(o+=` L${n(r.x)},${n(r.y)}`),o}function P9(e){switch((e??"association").toLowerCase()){case"inheritance":case"extends":return{kind:"inheritance",dash:"",end:"umlTri"};case"implementation":case"implements":return{kind:"implementation",dash:"5 4",end:"umlTri"};case"composition":return{kind:"composition",dash:"",start:"umlDiaF"};case"aggregation":return{kind:"aggregation",dash:"",start:"umlDiaH"};case"dependency":return{kind:"dependency",dash:"5 4",end:"umlOpen"};default:return{kind:"association",dash:"",end:"umlOpen"}}}var O9=e=>(e.stereotype??"").replace(/[«»]/g,"").trim().toLowerCase()==="interface";function R9(e){const t=e.classes??[],n=e.rels??[],s=15,o=O=>{const C=[O.name,...O.stereotype!==void 0?[`«${O.stereotype}»`]:[],...O.attrs??[],...O.methods??[]],D=Math.max(8,...C.map(F=>F.length));return Math.min(280,Math.max(150,D*6.4+30))},r=O=>O.stereotype!==void 0?38:26,i=O=>(O!==void 0&&O.length>0?O.length*s:6)+10,l=O=>r(O)+i(O.attrs)+i(O.methods),d=new Map(t.map(O=>[O.id,O])),u=n.map((O,C)=>({rl:O,ri:C})).filter(({rl:O})=>d.has(O.from)&&d.has(O.to)),p=t.filter(O9),h=p.length===1?p[0]?.id:void 0,m=new $f.graphlib.Graph({multigraph:!0});m.setGraph({rankdir:"TB",nodesep:46,ranksep:58,marginx:20,marginy:20}),m.setDefaultEdgeLabel(()=>({}));for(const O of t)m.setNode(O.id,{width:o(O),height:l(O)});u.forEach(({rl:O},C)=>m.setEdge(O.from,O.to,{},`e${C}`)),$f.layout(m);const g=m.graph(),v=Math.ceil(g.width??0),y=Math.ceil(g.height??0),b=new Map;for(const O of t){const C=m.node(O.id);C!==void 0&&b.set(O.id,{x:C.x-o(O)/2,y:C.y-l(O)/2})}let E=`<svg viewBox="0 0 ${v} ${y}" role="img"><title>UML class diagram</title><defs><marker id="umlTri" viewBox="0 0 14 14" refX="13" refY="7" markerWidth="13" markerHeight="13" markerUnits="userSpaceOnUse" orient="auto-start-reverse"><path d="M1,1 L13,7 L1,13 z" fill="var(--paper)" stroke="var(--ink)" stroke-width="1.2"/></marker><marker id="umlDiaF" viewBox="0 0 20 12" refX="30" refY="6" markerWidth="11" markerHeight="7" markerUnits="userSpaceOnUse" orient="auto-start-reverse"><path d="M1,6 L10,1 L19,6 L10,11 z" fill="var(--muted)"/></marker><marker id="umlDiaH" viewBox="0 0 20 12" refX="30" refY="6" markerWidth="11" markerHeight="7" markerUnits="userSpaceOnUse" orient="auto-start-reverse"><path d="M1,6 L10,1 L19,6 L10,11 z" fill="var(--paper)" stroke="var(--muted)" stroke-width="1.2"/></marker><marker id="umlOpen" viewBox="0 0 12 12" refX="10" refY="6" markerWidth="12" markerHeight="12" markerUnits="userSpaceOnUse" orient="auto-start-reverse"><path d="M1,1 L11,6 L1,11" fill="none" stroke="var(--muted)" stroke-width="1.3"/></marker></defs>`;const $=[],A=new Set;E+=`<g${he("rels")}>`,u.forEach(({rl:O,ri:C},D)=>{const U=m.edge(O.from,O.to,`e${D}`)?.points;if(U===void 0||U.length<2)return;const X=P9(O.kind);A.add(X.kind);const B=X.start!==void 0?` marker-start="url(#${X.start})"`:"",te=X.end!==void 0?` marker-end="url(#${X.end})"`:"",ee=X.dash.length>0?` stroke-dasharray="${X.dash}"`:"";if(E+=`<path d="${j9(U,9)}" fill="none" stroke="var(--muted)" stroke-width="1.5"${ee}${B}${te}${_(`rels.${C}`)}/>`,O.label!==void 0&&O.label!==""){const H=U[Math.floor(U.length/2)];H!==void 0&&$.push({lx:H.x,ly:H.y,label:O.label,path:`rels.${C}`})}}),E+="</g>",E+=`<g${he("classes")}>`;const T=[];t.forEach((O,C)=>{const D=b.get(O.id);if(D===void 0)return;const F={x:D.x,y:D.y,w:o(O),h:l(O)};T.push(F);const U=r(O),X=i(O.attrs),B=O.id===h,te=F.y+(O.stereotype!==void 0?30:18),ee=O.stereotype!==void 0?`<text x="${F.x+F.w/2}" y="${F.y+14}" class="t-eyebrow${B?" c-accent":""}" text-anchor="middle">«${S(O.stereotype)}»</text>`:"",H=`<g${he(`classes.${C}.attrs`)}>`+(O.attrs??[]).map((z,Y)=>`<text x="${F.x+12}" y="${F.y+U+15+Y*s}" class="t-sub c-ink"${_(`classes.${C}.attrs.${Y}`)}>${S(z)}</text>`).join("")+"</g>",W=`<g${he(`classes.${C}.methods`)}>`+(O.methods??[]).map((z,Y)=>`<text x="${F.x+12}" y="${F.y+U+X+15+Y*s}" class="t-sub c-ink"${_(`classes.${C}.methods.${Y}`)}>${S(z)}</text>`).join("")+"</g>",K=B?"var(--accent)":"var(--ink)",R=B?"var(--accent-tint)":"var(--paper)";E+=`<g${_(`classes.${C}`)}><rect x="${F.x}" y="${F.y}" width="${F.w}" height="${F.h}" rx="4" fill="${R}" stroke="${K}" stroke-width="1.5"/>`+ee+`<text x="${F.x+F.w/2}" y="${te}" class="t-name${B?" c-accent":""}" text-anchor="middle"${_(`classes.${C}.name`)}>${S(O.name)}</text><line x1="${F.x}" y1="${F.y+U}" x2="${F.x+F.w}" y2="${F.y+U}" class="uml-sep"${ut}/>`+H+`<line x1="${F.x}" y1="${F.y+U+X}" x2="${F.x+F.w}" y2="${F.y+U+X}" class="uml-sep"${ut}/>`+W+"</g>"}),E+="</g>";const{overlay:N,legend:j}=Ws($,T,{skin:!0});E+=N,E+="</svg>";const P=[];A.has("association")&&P.push({swatch:"edge",label:"association"}),A.has("inheritance")&&P.push({swatch:"chip",chip:"△",label:"inherits"}),A.has("implementation")&&P.push({swatch:"edge-dashed",label:"implements"}),A.has("composition")&&P.push({swatch:"chip",chip:"◆",label:"composed of"}),A.has("aggregation")&&P.push({swatch:"chip",chip:"◇",label:"aggregates"}),A.has("dependency")&&P.push({swatch:"edge-dashed",label:"depends on"}),h!==void 0&&P.push({swatch:"node-accent",label:"interface"});const I=ot(P);return ct({tag:"UML",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...I.length>0?{legendHtml:I}:{}},E+j)}function f$(e){switch((e??"component").toLowerCase()){case"root":return{chip:"ROOT",primary:!0,fill:"paper",dashed:!1};case"layout":return{chip:"LAYOUT",primary:!0,fill:"paper",dashed:!1};case"page":return{chip:"PAGE",primary:!0,fill:"paper",dashed:!1};case"leaf":return{chip:"LEAF",primary:!1,fill:"paper-2",dashed:!1};case"provider":case"context":return{chip:"PROVIDER",primary:!0,fill:"paper",dashed:!0};case"hook":return{chip:"HOOK",primary:!0,fill:"paper",dashed:!1};case"store":case"state":return{chip:"STORE",primary:!1,fill:"paper-2",dashed:!1};default:return{chip:"",primary:!0,fill:"paper",dashed:!1}}}var D9={ROOT:"root",LAYOUT:"layout",PAGE:"page",LEAF:"leaf",PROVIDER:"provider / context",HOOK:"hook",STORE:"store / state"};function B9(e){const t=e.nodes??[],n=new Map,s=new Map;for(const X of t)n.set(X.id,X),s.set(X.id,[]);const o=[];for(const X of t)X.parent!==void 0&&n.has(X.parent)?s.get(X.parent)?.push(X.id):o.push(X.id);const r=o.length===1?o[0]:void 0,i=new Map,l=new Map,d=new Set;let u=0,p=0;const h=(X,B)=>{if(d.has(X))return;d.add(X),l.set(X,B),B>p&&(p=B);const te=s.get(X)??[];if(te.length===0)i.set(X,u),u+=1;else{for(const W of te)h(W,B+1);const ee=i.get(te[0]??"")??0,H=i.get(te[te.length-1]??"")??0;i.set(X,(ee+H)/2)}};for(const X of o)h(X,0);const m=158,g=56,v=24,y=96,b=24,E=18,$=18,A=Math.max(u,1),T=X=>b+(i.get(X)??0)*(m+v),N=X=>E+(l.get(X)??0)*y,j=b*2+A*(m+v)-v,P=E+p*y+g+$;let I=`<svg viewBox="0 0 ${j} ${P}" role="img"><title>Component tree</title>`;for(const X of t){if(X.parent===void 0||!n.has(X.parent)||!i.has(X.id))continue;const B=T(X.parent)+m/2,te=N(X.parent)+g,ee=T(X.id)+m/2,H=N(X.id),W=(te+H)/2;I+=`<path d="M ${B} ${te} V ${W} H ${ee} V ${H}" fill="none" stroke="var(--muted)" stroke-width="1.25"/>`}const O=new Set;let C=!1,D=!1;I+=`<g${he("nodes")}>`,t.forEach((X,B)=>{if(!i.has(X.id))return;const te=T(X.id),ee=N(X.id),H=f$(X.kind),W=X.id===r;H.chip!==""&&O.add(H.chip),H.dashed&&(C=!0),H.fill==="paper-2"&&(D=!0);const K=W?"var(--accent)":H.primary?"var(--ink)":"var(--rule-solid)",R=W||H.primary?1.5:1,z=W?"var(--accent-tint)":H.fill==="paper-2"?"var(--paper-2)":"var(--paper)",Y=H.dashed?' stroke-dasharray="4 3"':"",V=`<rect x="${te}" y="${ee}" width="${m}" height="${g}" rx="4" fill="${z}" stroke="${K}" stroke-width="${R}"${Y}/>`,re=W?" c-accent":H.fill==="paper-2"?" c-muted":"",Q=H.chip!==""?`<text x="${te+12}" y="${ee+13}" class="t-eyebrow${re}">${H.chip}</text>`:"",ne=te+12,Z=lt(X.name,19,X.note!==void 0?1:2),q=H.chip!==""?18:8,de=Z.length*14+(X.note!==void 0?14:0),le=ee+q+(g-q-de)/2+11,J=Z.map((ve,we)=>`<text x="${ne}" y="${(le+we*14).toFixed(1)}" class="t-name${W?" c-accent":""}">${S(ve)}</text>`).join(""),ue=X.note!==void 0?`<text x="${ne}" y="${(le+Z.length*14).toFixed(1)}" class="t-sub">${S(X.note)}</text>`:"";I+=`<g${_(`nodes.${B}`)}>`+V+Q+J+ue+"</g>"}),I+="</g>",I+="</svg>";const F=[];t.some(X=>f$(X.kind).chip==="")&&F.push({swatch:"node",label:"component"});for(const X of O)F.push({swatch:"chip",chip:X,label:D9[X]??X.toLowerCase()});C&&F.push({swatch:"node-dashed",label:"wraps its subtree"}),D&&F.push({swatch:"node-fill2",label:"leaf / store"}),r!==void 0&&F.push({swatch:"node-accent",label:"tree root"});const U=ot(F);return ct({tag:"FE",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...U.length>0?{legendHtml:U}:{}},I)}var iA=Qo.solid??{stroke:"var(--muted)",sw:1.5,dash:"",marker:"skArrow",err:!1},z9={CLIENT:"client",SVC:"service",DATA:"data",DB:"database",BUCKET:"object store",WAREHOUSE:"warehouse",QUEUE:"queue",TOPIC:"topic",BUS:"stream",CACHE:"cache",SEARCH:"search index",REGISTRY:"registry",GATEWAY:"gateway",LB:"load balancer",FN:"function",EDGE:"edge / CDN",EXT:"external",PRODUCER:"producer",CONSUMER:"consumer",CONTEXT:"bounded context",WAF:"firewall",DNS:"DNS",AUTH:"identity",OBS:"observability",CRON:"scheduler",ANALYTICS:"analytics",CI:"pipeline",GIT:"repository",EMAIL:"messaging",CONFIG:"config",AI:"model / agent",HOST:"host",SECRETS:"secrets",WEBHOOK:"webhook",REGION:"region",DEPLOY:"deployment",POD:"pod",INGRESS:"ingress",NS:"namespace",NODE:"node",CLUSTER:"cluster"};function aA(e,t){const n=e.filter(s=>t.includes((s.kind??"").toLowerCase()));return n.length===1?n[0]?.id:void 0}function Zy(e,t,n,s=!1){const o=[],r=new Set;for(const i of e){const l=Vo(i.kind);l.chip===""||r.has(l.chip)||(r.add(l.chip),o.push({swatch:"chip",chip:l.chip,label:z9[l.chip]??l.chip.toLowerCase()}))}return s&&o.push({swatch:"chip",chip:"×N",label:"replicas"}),t.has("solid")&&o.push({swatch:"edge",label:"calls"}),t.has("dashed")&&o.push({swatch:"edge-dashed",label:"async / optional"}),t.has("forbidden")&&o.push({swatch:"edge-error",label:"forbidden"}),t.has("error")&&o.push({swatch:"edge-error",label:"error"}),n&&o.push({swatch:"node-accent",label:"entry point"}),ot(o)}function Rn(e){const o=e.anchor==="middle"?' text-anchor="middle"':"",r=lt(e.name,Math.max(6,Math.floor(e.textW/(e.skin===!0?7:6.6))),2),i=e.tech!==void 0?lt(e.tech,Math.max(6,Math.floor(e.textW/(e.skin===!0?6.2:5.8))),2):[],l=e.skin===!0?` class="blk-name t-name${e.accent===!0?" c-accent":""}"`:` class="blk-name" fill="${e.nameFill}"`,d=e.skin===!0?' class="blk-tech t-sub"':` class="blk-tech" fill="${e.techFill}"`,u=r.length*15+(i.length>0?4+i.length*12:0);let p=e.boxY+(e.boxH-u)/2+15-4,h="";for(const m of r)h+=`<text x="${e.x}" y="${p.toFixed(1)}"${l}${o}>${S(m)}</text>`,p+=15;if(i.length>0){p+=1;for(const m of i)h+=`<text x="${e.x}" y="${p.toFixed(1)}"${d}${o}>${S(m)}</text>`,p+=12}return h}function lA(e){const t=Math.min(e.w,Math.max(84,Math.round(e.w*.5)));return{x:Math.round(e.x+(e.w-t)/2),y:e.y,w:t,h:e.h}}function F9(e){return Jy(e)==="bar"}function qc(e,t,n){const s=Jy(e);return(()=>{switch(s){case"bar":return lA(t);case"cloud":return{x:t.x+t.w*.07,y:t.y+t.h*.3,w:t.w*.86,h:t.h*.7-4};case"stack":return{x:t.x,y:t.y-12,w:t.w+12,h:t.h+12};case"figure":case"crowd":return{x:t.x+t.w*.28,y:t.y,w:t.w*.44,h:t.h};case"globe":return{x:t.x+t.w*.3,y:t.y,w:t.w*.4,h:t.h};default:return t}})()}var b0=6;function cA(e,t,n){return dA(e,t)?{x:n.x,y:n.y,w:n.w-b0*2,h:n.h-b0*2}:n}var q9=new Set(["stack","replica","shards","crowd"]),H9=new Set(["cloud","shield","figure","crowd","globe","shards","replica"]);function dA(e,t){return e!==void 0&&e>=2&&!q9.has(t)}function W9(e,t){switch(e){case"pipe":return{x:t.x+t.w-Math.min(15,t.w*.11)*2-4,y:t.y+13,end:!0};case"cylinder":case"tiered":case"pail":return{x:t.x+t.w-14,y:t.y+Math.min(13,t.h*.16)*2+8,end:!0};default:return H9.has(e)?{x:t.x+8,y:t.y+13,end:!1}:{x:t.x+t.w-8,y:t.y+13,end:!0}}}function uA(e,t,n,s){if(e===void 0||e<2)return{back:"",chip:""};const o=b0,r=(u,p)=>`<rect x="${n.x+o*u}" y="${n.y+o*u}" width="${n.w}" height="${n.h}" rx="6" fill="${s.fill}" stroke="${s.accent}" stroke-width="1" opacity="${p}"/>`,i=dA(e,t)?r(2,.45)+r(1,.7):"",l=W9(t,n),d=`<text x="${l.x.toFixed(1)}" y="${l.y.toFixed(1)}" class="blk-rep t-sub"${l.end?' text-anchor="end"':""}>×${e}</text>`;return{back:i,chip:d}}function pA(e,t,n){const s=t.length>0?e.replace(/^<g[^>]*>/,o=>o+t):e;return n.length>0?s.replace(/<\/g>$/,`${n}</g>`):s}function Jy(e){switch((e??"").toLowerCase()){case"db":case"database":case"store":case"postgres":case"mysql":case"mongo":case"mongodb":case"dynamo":return"cylinder";case"warehouse":case"lake":return"tiered";case"bucket":case"blob":case"object":case"s3":return"pail";case"queue":case"topic":case"stream":case"mq":case"broker":case"sqs":case"rabbitmq":case"kafka":case"kinesis":return"pipe";case"sns":return"pipe";case"cdn":case"external":return"cloud";case"gateway":case"proxy":case"ingress":case"lb":return"bar";case"cache":case"redis":case"memcached":case"worker":case"etl":return"stack";case"vm":case"server":case"host":case"node":return"rack";case"waf":case"firewall":case"shield":return"shield";case"user":case"person":case"actor":return"figure";case"users":case"crowd":return"crowd";case"browser":case"web":return"window";case"mobile":return"phone";case"function":case"lambda":return"fn";case"scheduler":case"cron":case"job":case"cronjob":return"clock";case"secrets":case"vault":case"kms":case"secret":return"vault";case"shard":case"shards":case"sharded":return"shards";case"replica":case"replicas":case"replicaset":return"replica";case"region":case"geo":case"globe":return"globe";default:return"card"}}function fA(e,t){return{accent:t?"var(--accent)":e.primary?"var(--ink)":"var(--rule-solid)",fill:Iz(e,t),text:"var(--ink)",legacy:!1,sw:t||e.primary?1.5:1,dashed:e.dashed,focal:t}}function hA(e,t,n){if(t.chip==="")return"";const s=n.x+n.w/2;let o,r,i="";switch(e){case"cylinder":case"tiered":case"pail":{const l=e==="pail"?Math.min(11,n.h*.13):Math.min(13,n.h*.16);o=s,r=n.y+l*2+8,i=' text-anchor="middle"';break}case"pipe":o=n.x+Math.min(15,n.w*.11)+6,r=n.y+12;break;case"bar":o=s,r=n.y+12,i=' text-anchor="middle"';break;case"fn":{const l=Math.min(n.h/2,n.w*.32);o=s,r=n.y+n.h/2-l*.62,i=' text-anchor="middle"';break}case"vault":o=s,r=n.y+n.h*.3+11,i=' text-anchor="middle"';break;case"card":case"stack":case"rack":case"window":case"phone":case"clock":o=n.x+10,r=n.y+(e==="clock"?Math.min(18,n.h*.22)+14:12);break;default:o=n.x+n.w-4,r=n.y+12,i=' text-anchor="end"'}return`<text x="${o.toFixed(1)}" y="${r.toFixed(1)}" class="blk-chip t-eyebrow"${i}>${S(t.chip)}</text>`}function ex(e,t,n,s=!1){const o=Vo(e.kind),r=fA(o,s),i=Jy(e.kind),l=r.legacy?t:i==="bar"?lA(t):cA(e.replicas,i,t),d=U9(e,l,r,i);if(r.legacy)return d;const u=uA(e.replicas,i,l,r);return pA(d,u.back,hA(i,o,l)+u.chip)}function U9(e,t,n,s){const o=t.x+t.w/2,r=e.tech!==void 0?{tech:e.tech}:{},i=n.legacy?' filter="url(#gshadow)"':"",l=n.sw,d=n.dashed?' stroke-dasharray="4 3"':"",u=n.legacy?n.accent:"var(--muted)",p=n.legacy?n.accent:"var(--muted)",h=n.legacy?{}:{skin:!0,accent:n.focal};if(s==="cylinder"){const m=Math.min(13,t.h*.16),g=t.w/2;return`<g${i}><path d="M${t.x} ${t.y+m} A ${g} ${m} 0 0 1 ${t.x+t.w} ${t.y+m} V ${t.y+t.h-m} A ${g} ${m} 0 0 1 ${t.x} ${t.y+t.h-m} Z" fill="${n.fill}" stroke="${n.accent}" stroke-width="${l}"${d}/><path d="M${t.x} ${t.y+m} A ${g} ${m} 0 0 0 ${t.x+t.w} ${t.y+m}" fill="none" stroke="${n.accent}" stroke-width="${l}"${d}/>`+Rn({name:e.name,...r,x:o,boxY:t.y+m*2,boxH:t.h-m*2.6,textW:t.w-30,nameFill:n.text,techFill:p,...h,anchor:"middle"})+"</g>"}if(s==="pipe"){const m=Math.min(15,t.w*.11),g=t.h/2,v=t.y+g;return`<g${i}><path d="M${t.x+m} ${t.y} H ${t.x+t.w-m} A ${m} ${g} 0 0 1 ${t.x+t.w-m} ${t.y+t.h} H ${t.x+m} A ${m} ${g} 0 0 1 ${t.x+m} ${t.y} Z" fill="${n.fill}" stroke="${n.accent}" stroke-width="${l}"${d}/><ellipse cx="${t.x+t.w-m}" cy="${v}" rx="${m}" ry="${g}" fill="none" stroke="${n.accent}" stroke-width="1.1" stroke-opacity="0.7"${ut}/>`+Rn({name:e.name,...r,x:t.x+(t.w-m)/2,boxY:t.y,boxH:t.h,textW:t.w-m*3.2,nameFill:n.text,techFill:p,...h,anchor:"middle"})+"</g>"}if(s==="stack"){const g=(b,E)=>`<rect x="${t.x+6*b}" y="${t.y-6*b}" width="${t.w}" height="${t.h}" rx="10" fill="${n.fill}" stroke="${n.accent}" stroke-width="1" opacity="${E}"/>`,v=al(e.kind,t.x+14,t.y+t.h/2-8,u),y=v.length>0?t.x+40:t.x+16;return`<g${i}>`+g(2,.45)+g(1,.7)+`<rect x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" rx="10" fill="${n.fill}" stroke="${n.accent}" stroke-width="${l}"${d}/>`+v+Rn({name:e.name,...r,x:y,boxY:t.y,boxH:t.h,textW:t.x+t.w-y-14,nameFill:n.text,techFill:p,...h})+"</g>"}if(s==="cloud"){const m=t.y+t.h-3,g=`M ${t.x+t.w*.2} ${m} A ${t.w*.13} ${t.h*.2} 0 0 1 ${t.x+t.w*.14} ${m-t.h*.32} A ${t.w*.17} ${t.h*.28} 0 0 1 ${t.x+t.w*.43} ${m-t.h*.58} A ${t.w*.18} ${t.h*.26} 0 0 1 ${t.x+t.w*.72} ${m-t.h*.5} A ${t.w*.13} ${t.h*.21} 0 0 1 ${t.x+t.w*.82} ${m} Z`;return`<g${i}><path d="${g}" fill="${n.fill}" stroke="${n.accent}" stroke-width="${l}"${d} stroke-linejoin="round"/>`+Rn({name:e.name,...r,x:t.x+t.w*.48,boxY:t.y+t.h*.34,boxH:t.h*.58,textW:t.w*.52,nameFill:n.text,techFill:p,...h,anchor:"middle"})+"</g>"}if(s==="bar")return`<g${i}><rect x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" rx="2" fill="${n.fill}" stroke="${n.accent}" stroke-width="${l}"${d}/>`+Rn({name:e.name,...r,x:o,boxY:t.y+18,boxH:t.h-24,textW:t.w-14,nameFill:n.text,techFill:p,...h,anchor:"middle"})+"</g>";if(s==="figure"){const m=Math.min(11,t.h*.13),g=t.y+m+2,v=g+m+20;return`<g><circle cx="${o}" cy="${g.toFixed(1)}" r="${m}" fill="${u}"/><path d="M ${o-m*1.8} ${v.toFixed(1)} a ${m*1.8} ${m*2} 0 0 1 ${m*3.6} 0 z" fill="${u}"/>`+Rn({name:e.name,...r,x:o,boxY:v+2,boxH:t.y+t.h-v-2,textW:t.w-12,nameFill:n.text,techFill:p,...h,anchor:"middle"})+"</g>"}if(s==="fn"){const m=Math.min(t.h/2,t.w*.32),g=t.y+t.h/2;return`<g${i}><circle cx="${o}" cy="${g}" r="${m}" fill="${n.fill}" stroke="${n.accent}" stroke-width="${l}"${d}/><text x="${o}" y="${(g-m*.25).toFixed(1)}" font-family="Georgia, serif" font-size="${Math.max(15,m*.42).toFixed(0)}" font-style="italic" font-weight="700" fill="${u}" text-anchor="middle">ƒ</text>`+Rn({name:e.name,...r,x:o,boxY:g-m*.1,boxH:m,textW:m*1.7,nameFill:n.text,techFill:p,...h,anchor:"middle"})+"</g>"}if(s==="clock"){const m=Math.min(18,t.h*.22),g=t.y+3,v=$=>`<path d="M${$.toFixed(1)} ${(g-6).toFixed(1)} V ${(g+4).toFixed(1)}" stroke="${n.accent}" stroke-width="3" stroke-linecap="round"/>`,y=t.x+t.w-18,b=t.y+t.h-16,E=Math.min(11,t.h*.14);return`<g${i}><rect x="${t.x}" y="${t.y+3}" width="${t.w}" height="${t.h-3}" rx="9" fill="${n.fill}" stroke="${n.accent}" stroke-width="${l}"${d}/><path d="M${t.x} ${t.y+12} a 9 9 0 0 1 9 -9 H ${t.x+t.w-9} a 9 9 0 0 1 9 9 V ${t.y+3+m} H ${t.x} Z" fill="${u}" fill-opacity="0.16"/><path d="M${t.x} ${t.y+3+m} H ${t.x+t.w}" stroke="${n.accent}" stroke-width="1" stroke-opacity="0.5"${ut}/>`+v(t.x+t.w*.3)+v(t.x+t.w*.7)+`<circle cx="${y}" cy="${b}" r="${E}" fill="var(--paper)" stroke="${n.accent}" stroke-width="1.4"/><path d="M${y} ${(b-E*.55).toFixed(1)} V ${b} L ${(y+E*.45).toFixed(1)} ${(b+E*.3).toFixed(1)}" stroke="${n.accent}" stroke-width="1.4" fill="none" stroke-linecap="round"/>`+Rn({name:e.name,...r,x:o,boxY:t.y+3+m,boxH:t.h-3-m,textW:t.w-40,nameFill:n.text,techFill:p,...h,anchor:"middle"})+"</g>"}if(s==="vault"){const m=t.y+t.h*.3,g=t.h*.7,v=Math.min(t.w*.72,t.h*1.6),y=o-v/2,b=v*.22;return`<g${i}><path d="M${(o-b).toFixed(1)} ${(m+4).toFixed(1)} V ${(t.y+b*.9+4).toFixed(1)} A ${b.toFixed(1)} ${(b*.95).toFixed(1)} 0 0 1 ${(o+b).toFixed(1)} ${(t.y+b*.9+4).toFixed(1)} V ${(m+4).toFixed(1)}" fill="none" stroke="${n.accent}" stroke-width="4" stroke-linecap="round"/><rect x="${y.toFixed(1)}" y="${m.toFixed(1)}" width="${v.toFixed(1)}" height="${g.toFixed(1)}" rx="10" fill="${n.fill}" stroke="${n.accent}" stroke-width="${l}"${d}/>`+Rn({name:e.name,...r,x:o,boxY:m,boxH:g,textW:v-18,nameFill:n.text,techFill:p,...h,anchor:"middle"})+"</g>"}if(s==="shards"){const v=(t.w-24-16)/3,y=t.h*.58,b=Math.min(7,y*.18);let E="";for(let $=0;$<3;$++){const A=t.x+12+$*(v+8);E+=`<path d="M${A.toFixed(1)} ${t.y+b} A ${v/2} ${b} 0 0 1 ${(A+v).toFixed(1)} ${t.y+b} V ${(t.y+y-b).toFixed(1)} A ${v/2} ${b} 0 0 1 ${A.toFixed(1)} ${(t.y+y-b).toFixed(1)} Z" fill="${n.fill}" stroke="${n.accent}" stroke-width="1.1"/><path d="M${A.toFixed(1)} ${t.y+b} A ${v/2} ${b} 0 0 0 ${(A+v).toFixed(1)} ${t.y+b}" fill="none" stroke="${n.accent}" stroke-width="1.1"/>`}return`<g${i}>`+E+Rn({name:e.name,...r,x:o,boxY:t.y+y+2,boxH:t.h-y-2,textW:t.w-16,nameFill:n.text,techFill:p,...h,anchor:"middle"})+"</g>"}if(s==="replica"){const g=Math.min(11,t.h*.14),v=t.w-14,y=(b,E,$,A)=>`<g opacity="${$}"><path d="M${(t.x+b).toFixed(1)} ${(t.y+E+g).toFixed(1)} A ${v/2} ${g} 0 0 1 ${(t.x+b+v).toFixed(1)} ${(t.y+E+g).toFixed(1)} V ${(t.y+E+t.h-14-g).toFixed(1)} A ${v/2} ${g} 0 0 1 ${(t.x+b).toFixed(1)} ${(t.y+E+t.h-14-g).toFixed(1)} Z" fill="${n.fill}" stroke="${n.accent}" stroke-width="${A}"/><path d="M${(t.x+b).toFixed(1)} ${(t.y+E+g).toFixed(1)} A ${v/2} ${g} 0 0 0 ${(t.x+b+v).toFixed(1)} ${(t.y+E+g).toFixed(1)}" fill="none" stroke="${n.accent}" stroke-width="${A}"/></g>`;return`<g${i}>`+y(14,0,.5,1)+y(7,7,.75,1)+y(0,14,1,1.2)+Rn({name:e.name,...r,x:t.x+v/2,boxY:t.y+14+g*2,boxH:t.h-14-g*2.6,textW:v-24,nameFill:n.text,techFill:p,...h,anchor:"middle"})+"</g>"}if(s==="crowd"){const m=Math.min(9,t.h*.11),g=(y,b,E,$)=>{const A=m*E;return`<g opacity="${$}"><circle cx="${y}" cy="${(b+A).toFixed(1)}" r="${A.toFixed(1)}" fill="${u}"/><path d="M ${(y-A*1.7).toFixed(1)} ${(b+A*2+A*1.9).toFixed(1)} a ${(A*1.7).toFixed(1)} ${(A*1.9).toFixed(1)} 0 0 1 ${(A*3.4).toFixed(1)} 0 z" fill="${u}"/></g>`},v=t.y+4;return"<g>"+g(o-m*2.4,v+3,.85,.45)+g(o+m*2.4,v+3,.85,.45)+g(o,v,1,1)+Rn({name:e.name,...r,x:o,boxY:v+m*4.6,boxH:t.y+t.h-(v+m*4.6),textW:t.w-12,nameFill:n.text,techFill:p,...h,anchor:"middle"})+"</g>"}if(s==="globe"){const m=Math.min(t.h*.33,30),g=t.y+m+2;return`<g><circle cx="${o}" cy="${g.toFixed(1)}" r="${m}" fill="${n.fill}" stroke="${n.accent}" stroke-width="${l}"${d}/><ellipse cx="${o}" cy="${g.toFixed(1)}" rx="${(m*.42).toFixed(1)}" ry="${m}" fill="none" stroke="${n.accent}" stroke-width="1" stroke-opacity="0.65"${ut}/><path d="M${(o-m).toFixed(1)} ${g.toFixed(1)} H ${(o+m).toFixed(1)}" stroke="${n.accent}" stroke-width="1" stroke-opacity="0.65"${ut}/><path d="M${(o-m*.87).toFixed(1)} ${(g-m*.45).toFixed(1)} a ${m*1.15} ${m*1.15} 0 0 1 ${(m*1.74).toFixed(1)} 0" fill="none" stroke="${n.accent}" stroke-width="1" stroke-opacity="0.45"${ut}/>`+Rn({name:e.name,...r,x:o,boxY:g+m+2,boxH:t.y+t.h-(g+m+2),textW:t.w-12,nameFill:n.text,techFill:p,...h,anchor:"middle"})+"</g>"}if(s==="phone"){const g=t.x+12,v=t.y+5,y=t.h-10,b=g+34+14;return`<g${i}><rect x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" rx="10" fill="${n.fill}" stroke="${n.accent}" stroke-width="${l}"${d}/><rect x="${g}" y="${v}" width="34" height="${y}" rx="7" fill="var(--paper)" stroke="${n.accent}" stroke-width="${l}"${d}/><path d="M${g+34/2-5} ${v+6} H ${g+34/2+5}" stroke="${n.accent}" stroke-width="1.4" stroke-linecap="round"/><circle cx="${g+34/2}" cy="${v+y-7}" r="2" fill="${u}"/>`+Rn({name:e.name,...r,x:b,boxY:t.y,boxH:t.h,textW:t.x+t.w-b-12,nameFill:n.text,techFill:p,...h})+"</g>"}if(s==="window"){const g=v=>`<circle cx="${t.x+12+v*10}" cy="${t.y+9}" r="2.6" fill="${u}" opacity="${.85-v*.2}"/>`;return`<g${i}><rect x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" rx="9" fill="${n.fill}" stroke="${n.accent}" stroke-width="${l}"${d}/><path d="M${t.x} ${t.y+9} a 9 9 0 0 1 9 -9 H ${t.x+t.w-9} a 9 9 0 0 1 9 9 V ${t.y+18} H ${t.x} Z" fill="${u}" fill-opacity="0.14"/><path d="M${t.x} ${t.y+18} H ${t.x+t.w}" stroke="${n.accent}" stroke-width="1" stroke-opacity="0.5"${ut}/>`+g(0)+g(1)+g(2)+Rn({name:e.name,...r,x:o,boxY:t.y+18,boxH:t.h-18,textW:t.w-24,nameFill:n.text,techFill:p,...h,anchor:"middle"})+"</g>"}return mA(e,t,n)}function K9(e,t,n=!1){const s=Vo(e.kind),o=fA(s,n),r=cA(e.replicas,"card",t),i=mA(e,r,o),l=uA(e.replicas,"card",r,o);return pA(i,l.back,hA("card",s,r)+l.chip)}function mA(e,t,n){const s=n.legacy?n.accent:"var(--muted)",o=al(e.kind,t.x+14,t.y+t.h/2-8,s),r=o.length>0?t.x+40:t.x+16,i=n.legacy?' filter="url(#gshadow)"':"",l=n.dashed?' stroke-dasharray="4 3"':"",d=!n.legacy&&Vo(e.kind).chip!=="",u=d?t.y+10:t.y,p=d?t.h-10:t.h;return`<g${i}><rect x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" rx="${n.legacy?10:6}" fill="${n.fill}" stroke="${n.accent}" stroke-width="${n.sw}"${l}/>`+o+Rn({name:e.name,...e.tech!==void 0?{tech:e.tech}:{},x:r,boxY:u,boxH:p,textW:t.x+t.w-r-14,nameFill:n.text,techFill:n.legacy?n.accent:"var(--muted)",...n.legacy?{}:{skin:!0,accent:n.focal}})+"</g>"}function V9(e,t){const n=new Map(e.map(s=>[s.id,s]));return e.map(s=>{if(!F9(s.kind)||s.h!==void 0)return s;const o=t.filter(h=>h.from===s.id||h.to===s.id).map(h=>n.get(h.from===s.id?h.to:h.from)).filter(h=>h!==void 0&&h.id!==s.id),r=new Map;for(const h of o)r.set(h.col,[...r.get(h.col)??[],h]);const i=[...r.values()].sort((h,m)=>m.length-h.length)[0];if(i===void 0||i.length<2)return s;const l=[...new Set(i.map(h=>h.row))].sort((h,m)=>h-m),d=l[0]??s.row,u=l[l.length-1]??s.row;return u<=d||e.some(h=>h.id!==s.id&&h.col<=s.col+((s.w??1)-1)&&h.col+((h.w??1)-1)>=s.col&&h.row+((h.h??1)-1)>=d&&h.row<=u)?s:{...s,row:d,h:u-d+1}})}function G9(e,t){const n=e.groups??[],s=e.edges??[],o=e.nodes??[],r=n.length===0&&!(o.length>0&&o.every(H=>H.col!==void 0&&H.row!==void 0)),i=n.length===0?nr(o,s,e.dir??"LR"):o.map(H=>({...H,col:H.col??1,row:H.row??1})),l=V9(i,s),d=178,u=88,p=64,h=64,m=Yi(n),g=38+m.padX,v=52+m.padTop,y=36+m.padBot,b=Math.max(1,...l.map(H=>(H.col??1)+((H.w??1)-1)),...n.map(H=>H.col+(H.cols??1)-1)),E=Math.max(1,...l.map(H=>(H.row??1)+((H.h??1)-1)),...n.map(H=>H.row+(H.rows??1)-1)),$=H=>g+(H-1)*(d+p),A=H=>v+(H-1)*(u+h),T=H=>({x:$(H.col??1),y:A(H.row??1),w:(H.w??1)*d+((H.w??1)-1)*p,h:(H.h??1)*u+((H.h??1)-1)*h}),N=new Map(l.map(H=>[H.id,H])),j=g*2+b*d+(b-1)*p,P=v+E*u+(E-1)*h+y,I=tr({quick:r,cols:b,rows:E,cellW:d,cellH:u,gapX:p,gapY:h,padX:g,padTop:v}),O=Sn("Block diagram",e.title,[wt(l.length,"node"),wt(s.length,"connection")]);let C=`<svg viewBox="0 0 ${j} ${P}"${O.attrs}${I}>${O.title}`;C+=xl(n,{xOf:$,yOf:A,cellW:d,cellH:u,gapX:p,gapY:h,skin:!0});const D=aA(l,t),F=new Set,U=[];C+=`<g${he("edges")}>`;const X=qs(s),B=Hs(s,H=>{const W=N.get(H);return W!==void 0?qc(W.kind,T(W),W.replicas):void 0});s.forEach((H,W)=>{const K=N.get(H.from),R=N.get(H.to);if(!K||!R)return;const z=Fs(qc(K.kind,T(K),K.replicas),qc(R.kind,T(R),R.replicas),X[W]??0,B[W]??0),Y=H.kind??"solid";F.add(Y in Qo?Y:"solid");const V=Qo[Y]??iA;C+=`<path d="${z.d}" fill="none" stroke="${V.stroke}" stroke-width="${V.sw}" stroke-dasharray="${V.dash}" marker-end="url(#${V.marker})"${_(`edges.${W}`)}/>`,U.push({lx:z.lx,ly:z.ly,...H.label!==void 0?{label:H.label}:{},err:V.err,path:`edges.${W}`})}),C+="</g>",C+=`<g${he("nodes")}>`,l.forEach((H,W)=>{const K=Mo(H.col??1,H.row??1,H.w??1);C+=`<g${_(`nodes.${W}`)}${K}>${ex(H,T(H),void 0,H.id===D)}</g>`}),C+="</g>";const{overlay:te,legend:ee}=Ws(U,l.map(H=>T(H)),{skin:!0});return C+=te,C+="</svg>",{svg:C+ee,legend:Zy(l,F,D!==void 0,gA(l))}}function gA(e){return e.some(t=>t.replicas!==void 0&&t.replicas>=2)}function Y9(e,t){const n=e.layers??[],s=e.nodes??[],o=e.edges??[],r=n.map((K,R)=>s.filter(z=>(z.layer??0)===R)),i=28,l=e.systemLabel!==void 0?46:16,d=132,u=16,p=14,h=12,m=158,g=64,v=22,y=K=>K*m+(K-1)*v,E=Math.max(220,...r.map(K=>y(Math.max(K.length,1))))+u*2,$=g+p*2,A=i+14,T=A+d,N=T+E+14+i,j=i+l,P=K=>j+K*($+h),O=P(n.length)-h+16+i,C=new Map;r.forEach((K,R)=>{const z=T+(E-y(K.length))/2;K.forEach((Y,V)=>{C.set(Y.id,{x:z+V*(m+v),y:P(R)+p,w:m,h:g})})});const D=Sn("Layered architecture",e.title,[wt(n.length,"layer"),wt(s.length,"node")]);let F=`<svg viewBox="0 0 ${N} ${O}"${D.attrs}>${D.title}<rect x="${i}" y="${i}" width="${N-i*2}" height="${O-i*2}" rx="8" fill="none" stroke="var(--rule-solid)" stroke-width="1" stroke-dasharray="4 3"/>`;e.systemLabel!==void 0&&(F+=`<text x="${i+14}" y="${i+18}" class="grp-label t-eyebrow c-muted"${_("systemLabel")}>${S(e.systemLabel)}</text>`);const U=aA(s,t),X=new Set;F+=`<g${he("layers")}>`;for(let K=0;K<n.length;K++){const R=n[K];if(R===void 0)continue;const z=Fi(R.color,""),Y=z.length>0?z:"var(--rule-solid)",V=z.length>0?z:"var(--soft)",Q=lt(R.label,Math.max(8,Math.floor((d-24)/6.8)),3).map((ne,Z)=>`<text x="${A+12}" y="${(P(K)+16+Z*12).toFixed(1)}" class="layer-label t-eyebrow" fill="${V}">${S(ne)}</text>`).join("");F+=`<g${_(`layers.${K}`)}><rect x="${A}" y="${P(K)}" width="${d+E}" height="${$}" rx="6" fill="var(--paper-2)" fill-opacity="0.6" stroke="${Y}" stroke-width="1"/>`+Q+"</g>"}F+="</g>";const B=[];F+=`<g${he("edges")}>`;const te=qs(o),ee=Hs(o,K=>C.get(K));o.forEach((K,R)=>{const z=C.get(K.from),Y=C.get(K.to);if(!z||!Y)return;const V=Fs(z,Y,te[R]??0,ee[R]??0),re=K.kind??"solid";X.add(re in Qo?re:"solid");const Q=Qo[re]??iA;F+=`<path d="${V.d}" fill="none" stroke="${Q.stroke}" stroke-width="${Q.sw}" stroke-dasharray="${Q.dash}" marker-end="url(#${Q.marker})"${_(`edges.${R}`)}/>`,B.push({lx:V.lx,ly:V.ly,...K.label!==void 0?{label:K.label}:{},err:Q.err,path:`edges.${R}`})}),F+="</g>",F+=`<g${he("nodes")}>`,s.forEach((K,R)=>{const z=C.get(K.id);z!==void 0&&(F+=`<g${_(`nodes.${R}`)}>${K9(K,z,K.id===U)}</g>`)}),F+="</g>";const{overlay:H,legend:W}=Ws(B,[...C.values()],{skin:!0});return F+=H,F+="</svg>",{svg:F+W,legend:Zy(s,X,U!==void 0,gA(s))}}function X9(e,t){const{svg:n,legend:s}=e.layers!==void 0&&e.layers.length>0?Y9(e,t.entry):G9(e,t.entry),o={tag:t.tag,...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...s.length>0?{legendHtml:s}:{}};return ct(o,n)}var Q9={arch:{tag:"ARCH",entry:["gateway"]},infra:{tag:"INFRA",entry:["gateway"]},event:{tag:"EVENT",entry:["producer"]},ddd:{tag:"DDD",entry:[]},network:{tag:"ZONES",entry:["gateway","firewall","waf","shield"]},k8s:{tag:"K8S",entry:["ingress","gateway"]}};function Z9(e){return X9(e,Q9[e.preset??"arch"])}var J9=new Set(["db","database","store","warehouse","lake","postgres","mysql","mongo","mongodb","dynamo"]);function eq(e){const t=e.clusters??[],n=e.services??[],s=e.edges??[],o=new Map;for(const B of t)o.set(B.id,[]);for(const B of n){const te=o.get(B.cluster);te!==void 0&&te.push(B)}const r=158,i=78,l=22,d=24,u=34,p=22,h=34,m=26,g=new Map,v=[];let y=m,b=0;for(const B of t){const te=o.get(B.id)??[],ee=Math.min(2,Math.max(1,te.length)),H=Math.max(1,Math.ceil(te.length/ee)),W=ee*r+(ee-1)*l+d*2,K=u+H*i+(H-1)*l+p;v.push({c:B,x:y,y:m,w:W,h:K}),te.forEach((R,z)=>{const Y=Math.floor(z/ee),V=z%ee;g.set(R.id,{x:y+d+V*(r+l),y:m+u+Y*(i+l),w:r,h:i})}),K>b&&(b=K),y+=W+h}const E=y-h+m,$=m*2+b;let A=`<svg viewBox="0 0 ${E} ${$}" role="img"><title>Cluster diagram</title>`;A+=`<g${he("clusters")}>`,v.forEach((B,te)=>{const ee=B.c.kind!==void 0?`<text x="${B.x+B.w-12}" y="${B.y+16}" class="t-eyebrow" text-anchor="end">${S(B.c.kind)}</text>`:"";A+=`<g${_(`clusters.${te}`)}><rect x="${B.x}" y="${B.y}" width="${B.w}" height="${B.h}" rx="6" fill="var(--paper-2)" fill-opacity="0.6" stroke="var(--rule-solid)" stroke-width="1"/><text x="${B.x+12}" y="${B.y+16}" class="t-eyebrow">${S(B.c.label)}</text>`+ee+"</g>"}),A+="</g>";const T=[],N=new Set;A+=`<g${he("edges")}>`;const j=qs(s),P=new Map(n.map(B=>[B.id,B.kind])),I=B=>{const te=g.get(B);return te===void 0?void 0:qc(P.get(B),te)},O=Hs(s,I);s.forEach((B,te)=>{const ee=I(B.from),H=I(B.to);if(!ee||!H)return;const W=Fs(ee,H,j[te]??0,O[te]??0),K=B.kind??"solid";N.add(K);const R=Qo[K]??Qo.solid??{stroke:"var(--muted)",sw:1.5,dash:"",marker:"skArrow",err:!1},z=R.dash.length>0?` stroke-dasharray="${R.dash}"`:"";A+=`<path d="${W.d}" fill="none" stroke="${R.stroke}" stroke-width="${R.sw}"${z} marker-end="url(#${R.marker})"${_(`edges.${te}`)}/>`,T.push({lx:W.lx,ly:W.ly,...B.label!==void 0?{label:B.label}:{},err:R.err,path:`edges.${te}`})}),A+="</g>";const C=n.filter(B=>(B.kind??"").toLowerCase()==="gateway"),D=C.length===1?C[0]?.id:void 0;A+=`<g${he("services")}>`,n.forEach((B,te)=>{const ee=g.get(B.id);if(ee===void 0)return;const H=B.replicas??0;let W="";if(H>0){const R=Math.min(H,5),z=J9.has((B.kind??"").toLowerCase())?ee.y+ee.h-24:ee.y+ee.h-14;let Y="";for(let V=0;V<R;V++)Y+=`<rect x="${ee.x+12+V*7}" y="${z}" width="4" height="8" rx="1" fill="var(--muted)"/>`;W="<g>"+Y+`<text x="${ee.x+12+R*7+4}" y="${z+7}" class="t-sub">×${H}</text></g>`}const K=ex({kind:B.kind,name:B.label,...B.tech!==void 0?{tech:B.tech}:{}},ee,void 0,B.id===D);A+=`<g${_(`services.${te}`)}>${K}${W}</g>`}),A+="</g>";const{overlay:F,legend:U}=Ws(T,[...g.values()],{skin:!0});A+=F,A+="</svg>";const X=Zy(n,N,D!==void 0);return ct({tag:"CLUSTER",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...X.length>0?{legendHtml:X}:{}},A+U)}var tq=["component","engine","core","interface","strategy","impl","adapter","controller","handler","route","gateway","service","usecase","apiclient","client","repository","repo","dao","worker","consumer","middleware","model","entity","db","store","database","cache","queue","bus","broker","state","hook","external","backend","egress","api","thirdparty"],hs=e=>({chip:e,primary:!0,fill:"paper",dashed:!1}),h$=e=>({chip:e,primary:!1,fill:"paper-2",dashed:!1});function nq(e){const t=(e??"component").toLowerCase();switch(t){case"component":return hs("");case"engine":case"core":return hs("ENGINE");case"interface":return{chip:"INTERFACE",primary:!0,fill:"paper",dashed:!0};case"strategy":case"impl":return hs("STRATEGY");case"adapter":return hs("ADAPTER");case"controller":case"handler":case"route":return hs("CONTROLLER");case"gateway":return hs("GATEWAY");case"service":case"usecase":return hs("SERVICE");case"apiclient":case"client":return hs("CLIENT");case"repository":case"repo":case"dao":return hs("REPOSITORY");case"worker":case"consumer":return hs("WORKER");case"middleware":return h$("MIDDLEWARE");case"model":case"entity":return hs("MODEL");case"state":case"store_state":return h$("STATE");case"hook":return hs("HOOK");default:return hs(t.toUpperCase())}}function sq(e){switch((e??"uses").toLowerCase()){case"implements":return{stroke:"var(--muted)",sw:1.5,dash:"5 4",marker:"feTri",legend:"implements"};case"egress":case"https":case"api":return{stroke:"var(--link)",sw:1.5,dash:"",marker:"feLink",legend:"network"};case"reads":case"dashed":return{stroke:"var(--muted)",sw:1.5,dash:"5 4",marker:"skOpen",legend:"reads"};case"async":return{stroke:"var(--muted)",sw:1.25,dash:"2 3",marker:"skOpen",legend:"async"};default:return{stroke:"var(--muted)",sw:1.5,dash:"",marker:"skArrow",legend:"uses"}}}var m$={bus:"queue",backend:"external",api:"external",thirdparty:"external",egress:"external"},oq=new Set(["db","store","database","queue","broker","cache","redis","external"]);function rq(e,t){const n=e.groups??[],s=e.edges??[],o=e.nodes??[],r=!(o.length>0&&o.every(q=>q.col!==void 0&&q.row!==void 0)),i=n.length===0?nr(o,s,e.dir??"LR"):o.map(q=>({...q,col:q.col??1,row:q.row??1})),l=178,d=80,u=54,p=60,h=Mz(n),m=Yi(n),g=h.size>0?{x:28,top:38,bot:28}:{x:16,top:22,bot:16},v=26+(g.x-16)+m.padX,y=30+(g.top-22)+m.padTop,b=20+(g.bot-16)+m.padBot,E=Math.max(1,...i.map(q=>q.col+((q.w??1)-1)),...n.map(q=>q.col+(q.cols??1)-1)),$=Math.max(1,...i.map(q=>q.row),...n.map(q=>q.row+(q.rows??1)-1)),A=q=>v+(q-1)*(l+u),T=q=>y+(q-1)*(d+p),N=q=>({x:A(q.col),y:T(q.row),w:(q.w??1)*l+((q.w??1)-1)*u,h:d}),j=q=>({x:A(q.col)-g.x,y:T(q.row)-g.top,w:(q.cols??1)*l+((q.cols??1)-1)*u+g.x*2,h:(q.rows??1)*d+((q.rows??1)-1)*p+g.top+g.bot}),P=new Map(i.map(q=>[q.id,q])),I=v*2+E*l+(E-1)*u,O=y+$*d+($-1)*p+b,C=q=>(q.cols??1)*(q.rows??1),D=n.map((q,de)=>({g:q,gi:de})).sort((q,de)=>h.size>0?(h.get(q.g)?.depth??0)-(h.get(de.g)?.depth??0)||C(de.g)-C(q.g)||q.gi-de.gi:C(de.g)-C(q.g)),F=e.variant==="be"?["controller","handler","route"]:["engine","core"],U=i.filter(q=>F.includes((q.kind??"").toLowerCase())),X=U.length===1?U[0]?.id:void 0,B=tr({quick:r,cols:E,rows:$,cellW:l,cellH:d,gapX:u,gapY:p,padX:v,padTop:y});let te=`<svg viewBox="0 0 ${I} ${O}" role="img"${B}><title>Module graph</title><defs><marker id="feLink" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="var(--link)"/></marker><marker id="feTri" viewBox="0 0 14 14" refX="13" refY="7" markerWidth="11" markerHeight="11" markerUnits="userSpaceOnUse" orient="auto-start-reverse"><path d="M1,1 L13,7 L1,13 z" fill="var(--paper)" stroke="var(--ink)" stroke-width="1.2"/></marker></defs>`;te+=`<g${he("groups")}>`;for(const{g:q,gi:de}of D){const le=j(q),J=h.get(q),ue=J===void 0?le:{x:le.x+J.inset.x,y:le.y+J.inset.y,w:le.w-J.inset.w,h:le.h-J.inset.h},we=J!==void 0&&J.depth%2===1?`<text x="${ue.x+ue.w-12}" y="${ue.y+15}" class="t-eyebrow" text-anchor="end">${S(q.label)}</text>`:`<text x="${ue.x+12}" y="${ue.y+15}" class="t-eyebrow">${S(q.label)}</text>`;te+=`<g${_(`groups.${de}`)}><rect x="${ue.x}" y="${ue.y}" width="${ue.w}" height="${ue.h}" rx="6" fill="var(--paper-2)" fill-opacity="0.6" stroke="var(--rule-solid)" stroke-width="1"/>`+we+"</g>"}te+="</g>";const ee=q=>{const de=(q.kind??"").toLowerCase();return qc(m$[de]??de,N(q))},H=[],W=new Set;te+=`<g${he("edges")}>`;const K=qs(s),R=Hs(s,q=>{const de=P.get(q);return de!==void 0?ee(de):void 0});s.forEach((q,de)=>{const le=P.get(q.from),J=P.get(q.to);if(!le||!J)return;const ue=Fs(ee(le),ee(J),K[de]??0,R[de]??0),ve=sq(q.kind);W.add(ve.legend);const we=ve.dash.length>0?` stroke-dasharray="${ve.dash}"`:"";te+=`<path d="${ue.d}" fill="none" stroke="${ve.stroke}" stroke-width="${ve.sw}"${we} marker-end="url(#${ve.marker})"${_(`edges.${de}`)}/>`,H.push({lx:ue.lx,ly:ue.ly,...q.label!==void 0?{label:q.label}:{},path:`edges.${de}`})}),te+="</g>";const z=new Map;let Y=!1,V=!1;te+=`<g${he("nodes")}>`,i.forEach((q,de)=>{const le=N(q),J=(q.kind??"").toLowerCase(),ue=q.id===X,ve=m$[J]??J;if(oq.has(ve)){const dt=Vo(ve);dt.chip!==""&&!z.has(dt.chip)&&z.set(dt.chip,"shape"),dt.dashed&&(Y=!0),dt.fill==="paper-2"&&(V=!0),te+=`<g${_(`nodes.${de}`)}${Mo(q.col,q.row,q.w??1)}>${ex({kind:ve,name:q.name,...q.note!==void 0?{tech:q.note}:{}},le,void 0,ue)}</g>`;return}const we=nq(q.kind);we.chip!==""&&!z.has(we.chip)&&z.set(we.chip,"card"),we.dashed&&(Y=!0),we.fill==="paper-2"&&(V=!0);const $e=ue?"var(--accent)":we.primary?"var(--ink)":"var(--rule-solid)",je=ue||we.primary?1.5:1,De=ue?"var(--accent-tint)":we.fill==="paper-2"?"var(--paper-2)":"var(--paper)",Me=we.dashed?' stroke-dasharray="4 3"':"",Be=`<rect x="${le.x}" y="${le.y}" width="${le.w}" height="${le.h}" rx="6" fill="${De}" stroke="${$e}" stroke-width="${je}"${Me}/>`,Ge=ue?" c-accent":we.fill==="paper-2"?" c-muted":"",fe=we.chip!==""?`<text x="${le.x+12}" y="${le.y+14}" class="t-eyebrow${Ge}">${S(we.chip)}</text>`:"",ge=le.x+12,Ce=le.w-24,Fe=lt(q.name,Math.max(6,Math.floor(Ce/7)),2),qe=q.note!==void 0?lt(q.note,Math.max(6,Math.floor(Ce/6.2)),2):[],ze=15,Xe=12,pt=3,kt=le.y+(we.chip!==""?20:8),St=Fe.length*ze+(qe.length>0?pt+qe.length*Xe:0);let Nt=kt+(le.y+le.h-kt-St)/2+ze-4,Bt="";for(const dt of Fe)Bt+=`<text x="${ge}" y="${Nt.toFixed(1)}" class="t-name${ue?" c-accent":""}">${S(dt)}</text>`,Nt+=ze;if(qe.length>0){Nt+=pt-ze+Xe;for(const dt of qe)Bt+=`<text x="${ge}" y="${Nt.toFixed(1)}" class="t-sub">${S(dt)}</text>`,Nt+=Xe}te+=`<g${_(`nodes.${de}`)}${Mo(q.col,q.row,q.w??1)}>`+Be+fe+Bt+"</g>"}),te+="</g>";const{overlay:re,legend:Q}=Ws(H,i.map(q=>N(q)),{skin:!0});te+=re,te+="</svg>";const ne=[];for(const q of z.keys())ne.push({swatch:"chip",chip:q,label:iq[q]??q.toLowerCase()});Y&&ne.push({swatch:"node-dashed",label:"contract / external"}),V&&ne.push({swatch:"node-fill2",label:"passive (state, middleware, store)"}),W.has("uses")&&ne.push({swatch:"edge",label:"uses"}),W.has("implements")&&ne.push({swatch:"edge-implements",label:"implements"}),W.has("reads")&&ne.push({swatch:"edge-dashed",label:"reads / optional"}),W.has("async")&&ne.push({swatch:"edge-async",label:"async"}),W.has("network")&&ne.push({swatch:"edge-link",label:"network call"}),X!==void 0&&ne.push({swatch:"node-accent",label:"entry point"});const Z=ot(ne);return ct({tag:t,...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...Z.length>0?{legendHtml:Z}:{}},te+Q)}var iq={ENGINE:"engine / core",INTERFACE:"interface",STRATEGY:"strategy",ADAPTER:"adapter",CONTROLLER:"controller / route",GATEWAY:"gateway",SERVICE:"service / use case",CLIENT:"API client",REPOSITORY:"repository",WORKER:"worker / consumer",MIDDLEWARE:"middleware",MODEL:"model / entity",STATE:"state store",HOOK:"hook",DB:"database",QUEUE:"queue / bus",CACHE:"cache",EXT:"external"};function aq(e){return rq(e,"LOGIC")}function lq(e){return e==="phone"?200:380}function g$(e){const t=Math.max(1,e.rows??1);switch(e.type){case"header":return 34;case"subheader":return 26;case"text":return 16+(t-1)*12;case"button":return 42;case"input":case"search":return 42;case"image":return 96;case"avatar":return 52;case"card":return t*64+(t-1)*10;case"list":return t*40;case"nav":return 34;case"tabs":return 52;case"divider":return 14;case"badge":return 26;case"toggle":return 30;case"spacer":return 18*t;default:return 24}}var Vu='fill="var(--paper-2)" stroke="var(--rule-solid)" stroke-width="1"';function cq(e,t,n,s){const o=Math.max(1,e.rows??1),r=e.label??"",i=e.tone==="danger"?"var(--negative)":e.tone==="muted"?"var(--paper-2)":"var(--ink)",l=e.tone==="muted"?"wf-btn on-light":"wf-btn",d=e.tone==="muted"?' stroke="var(--rule-solid)" stroke-width="1"':"",u=e.align==="c"?t+s/2:e.align==="r"?t+s:t,p=e.align==="c"?"middle":e.align==="r"?"end":"start";switch(e.type){case"header":return`<text x="${u}" y="${n+22}" class="wf-h" fill="var(--charcoal)" text-anchor="${p}">${S(r||"Heading")}</text>`;case"subheader":return`<text x="${u}" y="${n+17}" class="wf-sub" fill="var(--gray)" text-anchor="${p}">${S(r||"Subheading")}</text>`;case"text":{let h="";for(let m=0;m<o;m++){const g=m===o-1?s*.66:s;h+=`<rect x="${t}" y="${n+m*12}" width="${g}" height="6" rx="3" fill="var(--rule)"/>`}return h}case"button":return`<rect x="${t}" y="${n}" width="${s}" height="34" rx="6" fill="${i}"${d}/><text x="${t+s/2}" y="${n+22}" class="${l}" text-anchor="middle">${S(r||"Button")}</text>`;case"input":case"search":{const h=e.type==="search"?`<circle cx="${t+16}" cy="${n+17}" r="5" fill="none" stroke="var(--gray)" stroke-width="1.4"/><path d="M${t+20} ${n+21} l4 4" stroke="var(--gray)" stroke-width="1.4"/>`:"",m=e.type==="search"?t+30:t+12;return`<rect x="${t}" y="${n}" width="${s}" height="34" rx="8" fill="var(--white)" stroke="var(--rule-solid)" stroke-width="1.2"/>`+h+`<text x="${m}" y="${n+21}" class="wf-ph-text">${S(r||"Type here…")}</text>`}case"image":return`<rect x="${t}" y="${n}" width="${s}" height="88" rx="8" ${Vu}/><path d="M${t} ${n+88} L${t+s*.4} ${n+40} L${t+s*.62} ${n+66} L${t+s*.78} ${n+50} L${t+s} ${n+88}" fill="none" stroke="var(--gray)" stroke-width="1.3"/><circle cx="${t+s*.74} " cy="${n+26}" r="7" fill="none" stroke="var(--gray)" stroke-width="1.3"/>`;case"avatar":return`<circle cx="${t+22}" cy="${n+22}" r="20" ${Vu}/><circle cx="${t+22}" cy="${n+17}" r="7" fill="var(--gray)"/><path d="M${t+9} ${n+40} a13 11 0 0 1 26 0" fill="var(--gray)"/>`+(r?`<text x="${t+52}" y="${n+27}" class="wf-sub" fill="var(--charcoal)">${S(r)}</text>`:"");case"card":{let h="";for(let g=0;g<o;g++){const v=n+g*74;h+=`<rect x="${t}" y="${v}" width="${s}" height="64" rx="10" fill="var(--white)" stroke="var(--rule-solid)" stroke-width="1.2"/><rect x="${t+12}" y="${v+12}" width="40" height="40" rx="8" ${Vu}/><rect x="${t+64}" y="${v+16}" width="${s-92}" height="7" rx="3.5" fill="var(--rule)"/><rect x="${t+64}" y="${v+34}" width="${(s-92)*.6}" height="6" rx="3" fill="var(--rule)"/>`}const m=r?`<text x="${t+64}" y="${n+30}" class="wf-ph-text"></text>`:"";return h+m}case"list":{let h="";for(let m=0;m<o;m++){const g=n+m*40;h+=`<circle cx="${t+16}" cy="${g+20}" r="12" ${Vu}/><rect x="${t+38}" y="${g+12}" width="${s-76}" height="6" rx="3" fill="var(--rule)"/><rect x="${t+38}" y="${g+24}" width="${(s-76)*.55}" height="5" rx="2.5" fill="var(--rule)"/><path d="M${t+s-14} ${g+15} l5 5 l-5 5" fill="none" stroke="var(--gray)" stroke-width="1.4"/>`+(m<o-1?`<line x1="${t+38}" y1="${g+40}" x2="${t+s}" y2="${g+40}" stroke="var(--light-gray)" stroke-width="1"/>`:"")}return h}case"nav":{const h=(r||"Home, Docs, Pricing, About").split(",").map(v=>v.trim());let m="",g=t;for(const v of h){const y=16+v.length*6.2;m+=`<rect x="${g}" y="${n+4}" width="${y}" height="22" rx="11" fill="var(--light-gray)"/><text x="${g+y/2}" y="${n+19}" class="wf-ph-text" text-anchor="middle">${S(v)}</text>`,g+=y+8}return m}case"tabs":{const h=(r||"Home, Search, Bell, Profile").split(",").map(v=>v.trim()),m=s/h.length;let g=`<line x1="${t}" y1="${n}" x2="${t+s}" y2="${n}" stroke="var(--rule)" stroke-width="1"${ut}/>`;return h.forEach((v,y)=>{const b=t+m*y+m/2;g+=`<circle cx="${b}" cy="${n+18}" r="8" fill="none" stroke="${y===0?i:"var(--gray)"}" stroke-width="1.6"/><text x="${b}" y="${n+42}" class="wf-tab" text-anchor="middle" fill="${y===0?i:"var(--gray)"}">${S(v)}</text>`}),g}case"divider":return`<line x1="${t}" y1="${n+7}" x2="${t+s}" y2="${n+7}" stroke="var(--rule)" stroke-width="1"${ut}/>`;case"badge":{const h=22+r.length*6.4;return`<rect x="${u-(p==="middle"?h/2:p==="end"?h:0)}" y="${n}" width="${h}" height="22" rx="11" fill="${i}"${d}/><text x="${u-(p==="middle"?0:p==="end"?h/2:-h/2)}" y="${n+15}" class="${l}" text-anchor="middle">${S(r||"New")}</text>`}case"toggle":return(r?`<text x="${t}" y="${n+19}" class="wf-sub" fill="var(--charcoal)">${S(r)}</text>`:"")+`<rect x="${t+s-44}" y="${n+6}" width="44" height="22" rx="11" fill="${i}"${d}/><circle cx="${t+s-16}" cy="${n+17}" r="8" fill="var(--paper)" stroke="var(--rule-solid)" stroke-width="1"/>`;case"spacer":return"";default:return""}}function dq(e,t){const n=e.device??"browser",s=lq(n),o=16,r=e.elements??[];let i=0;for(const j of r)i+=g$(j)+10;i=Math.max(i,80);const l=n==="phone",d=n==="browser",u=30,h=u+(d?26:0),m=l?24:0,g=s+o*2,v=i+o,y=h+v+m,b=l?30:14,E=l?2.4:1.8,$=`wfclip${t}`;let A="";if(l)A+=`<rect x="0" y="0" width="${g}" height="${u}" fill="var(--light-gray)"/>`,A+=`<rect x="${g/2-26}" y="6" width="52" height="9" rx="4.5" fill="var(--charcoal)"/>`,e.title&&(A+=`<text x="16" y="20" class="wf-status"${_(`screens.${t}.title`)}>${S(e.title)}</text>`),A+=`<text x="${g-16}" y="20" class="wf-status" text-anchor="end">100%</text>`;else if(A+=`<rect x="0" y="0" width="${g}" height="${u}" fill="var(--light-gray)"/>`,A+=`<line x1="0" y1="${u}" x2="${g}" y2="${u}" stroke="var(--rule)" stroke-width="1"${ut}/>`,A+='<circle cx="18" cy="15" r="5" fill="var(--rule-solid)"/><circle cx="34" cy="15" r="5" fill="var(--rule-solid)"/><circle cx="50" cy="15" r="5" fill="var(--rule-solid)"/>',e.title&&!d&&(A+=`<text x="${g/2}" y="20" class="wf-status" text-anchor="middle"${_(`screens.${t}.title`)}>${S(e.title)}</text>`),d){const j=e.url??e.title??"example.com";A+=`<rect x="68" y="${u+5}" width="${g-84}" height="16" rx="8" fill="var(--white)" stroke="var(--rule-solid)" stroke-width="1"/>`,A+=`<text x="78" y="${u+16}" class="wf-url"${_(`screens.${t}.url`)}>${S(j)}</text>`}let T=h+o;return A+=`<g${he(`screens.${t}.elements`)}>`,r.forEach((j,P)=>{A+=`<g${_(`screens.${t}.elements.${P}`)}>${cq(j,o,T,s)}</g>`,T+=g$(j)+10}),A+="</g>",l&&(A+=`<rect x="${g/2-30}" y="${y-15}" width="60" height="5" rx="2.5" fill="var(--charcoal)" opacity="0.55"/>`),{svg:`<g><defs><clipPath id="${$}"><rect x="0" y="0" width="${g}" height="${y}" rx="${b}"/></clipPath></defs><rect x="0" y="0" width="${g}" height="${y}" rx="${b}" fill="var(--paper)"/><g clip-path="url(#${$})">${A}</g><rect x="0" y="0" width="${g}" height="${y}" rx="${b}" fill="none" stroke="var(--ink)" stroke-width="${E}"/></g>`,width:g,height:y}}function uq(e){const t=e.screens??[],n=36,s=22,o=8,r=8,i=t.map((g,v)=>dq(g,v)),l=i.reduce((g,v)=>g+v.width,0)+n*Math.max(0,i.length-1),d=i.reduce((g,v)=>Math.max(g,v.height),0),u=l+o*2,p=d+s+r*2;let h=`<svg viewBox="0 0 ${u} ${p}" role="img"><title>${S(e.title??"UI mockup")}</title>`;h+=`<g${he("screens")}>`;let m=o;return i.forEach((g,v)=>{const y=t[v];h+=`<g transform="translate(${m}, ${r})"${_(`screens.${v}`)}>${g.svg}</g>`;const b=y?.label;if(b!==void 0&&b.length>0){const E=lt(b,Math.floor(g.width/6),2);h+=`<g${_(`screens.${v}.label`)}>`,E.forEach(($,A)=>{h+=`<text x="${m+g.width/2}" y="${r+d+16+A*12}" class="wf-caption" text-anchor="middle">${S($)}</text>`}),h+="</g>"}m+=g.width+n}),h+="</g>",h+="</svg>",ct({tag:"UI",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{}},h)}function Sf(e){const t=r=>r.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),n=/("(?:\\.|[^"\\])*")(\s*:)?|\b(true|false|null)\b|(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)/g;let s="",o=0;for(let r=n.exec(e);r!==null;r=n.exec(e)){s+=t(e.slice(o,r.index));const i=r[1],l=r[2],d=r[3],u=r[4];i!==void 0?s+=l!==void 0?`<span class="j-key">${t(i)}</span>${l}`:`<span class="j-str">${t(i)}</span>`:d!==void 0?s+=`<span class="j-kw">${t(d)}</span>`:u!==void 0?s+=`<span class="j-num">${t(u)}</span>`:s+=t(r[0]),o=n.lastIndex}return s+=t(e.slice(o)),s}function pq(e){const t=String(e).trim();return t.startsWith("3")?"ep-3xx":t.startsWith("4")?"ep-4xx":t.startsWith("5")?"ep-5xx":"ep-2xx"}var vA=e=>e===!0?' <span class="ep-req">required</span>':"";function fq(e){const t=e.map((n,s)=>`<tr${_(`params.${s}`)}><td class="ep-name"><span${_(`params.${s}.name`)}>${S(n.name)}</span>${vA(n.required)}</td><td class="ep-type">${S(n.in??"")}</td><td class="ep-type"${_(`params.${s}.type`)}>${S(n.type??"")}</td><td${_(`params.${s}.desc`)}>${S(n.desc??"")}</td></tr>`).join("");return`<table class="ep-table"><thead><tr><th>Name</th><th>In</th><th>Type</th><th>Description</th></tr></thead><tbody${he("params")}>${t}</tbody></table>`}function hq(e){const t=e.map((n,s)=>`<tr${_(`body.${s}`)}><td class="ep-name"><span${_(`body.${s}.name`)}>${S(n.name)}</span>${vA(n.required)}</td><td class="ep-type"${_(`body.${s}.type`)}>${S(n.type??"")}</td><td${_(`body.${s}.desc`)}>${S(n.desc??"")}</td></tr>`).join("");return`<table class="ep-table"><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody${he("body")}>${t}</tbody></table>`}function mq(e){const t=e.map((n,s)=>{const o=n.example!==void 0?`<tr><td></td><td colspan="2"><pre class="ep-ex"${_(`responses.${s}.example`)}>${Sf(n.example)}</pre></td></tr>`:"";return`<tr${_(`responses.${s}`)}><td><span class="ep-status ${pq(n.status)}"${_(`responses.${s}.status`)}>${S(String(n.status))}</span></td><td colspan="2"${_(`responses.${s}.desc`)}>${S(n.desc??"")}</td></tr>${o}`}).join("");return`<table class="ep-table"><thead><tr><th>Status</th><th colspan="2">Description</th></tr></thead><tbody${he("responses")}>${t}</tbody></table>`}function gq(e){const t=`<div class="ep-head"><span class="ep-method ${e.method.toLowerCase()}"${_("method")}>${S(e.method)}</span><span class="ep-path"${_("path")}>${S(e.path)}</span>`+(e.auth!==void 0?`<span class="ep-auth"${_("auth")}>${S(e.auth)}</span>`:"")+"</div>",n=[];e.title!==void 0&&n.push(`<div class="ep-title">${S(e.title)}</div>`),e.description!==void 0&&n.push(`<p class="ep-desc">${S(e.description)}</p>`);const s=e.params??[];s.length>0&&n.push(`<div class="ep-section">Parameters</div>${fq(s)}`);const o=e.body??[];o.length>0&&n.push(`<div class="ep-section">Request body</div>${hq(o)}`);const r=e.responses??[];return r.length>0&&n.push(`<div class="ep-section">Responses</div>${mq(r)}`),e.request!==void 0&&n.push(`<div class="ep-section">Example request</div><pre class="ep-ex"${_("request")}>${Sf(e.request)}</pre>`),e.response!==void 0&&n.push(`<div class="ep-section">Example response</div><pre class="ep-ex"${_("response")}>${Sf(e.response)}</pre>`),`<div class="endpoint">${t}<div class="ep-body">${n.join("")}</div></div>`}function vq(e){const t=e.attribution!==void 0?`<div class="pull-attr"${_("attribution")}>${S(e.attribution)}</div>`:"";return`<div class="pull"><p class="pull-text"${_("text")}>${vo(e.text)}</p>${t}</div>`}function yq(e,t){const n='<div class="layer-meta">'+(e.kicker!==void 0?`<div class="layer-kicker"${_(`items.${t}.kicker`)}>${S(e.kicker)}</div>`:"")+`<div class="layer-title"${_(`items.${t}.title`)}>${S(e.title)}</div>`+(e.source!==void 0?`<div class="layer-src">${S(e.source)}</div>`:"")+(e.question!==void 0?`<div class="layer-q">${S(e.question)}</div>`:"")+"</div>",s=e.body!==void 0?`<div class="layer-body"${_(`items.${t}.body`)}>${S(e.body)}</div>`:'<div class="layer-body"></div>';return`<div class="layer"${_(`items.${t}`)}><div class="layer-num">${t+1}</div>${n}${s}</div>`}function xq(e){const t=e.items??[];return`<div class="layer-stack"${he("items")}>${t.map((n,s)=>yq(n,s)).join("")}</div>`}var kq=["m-full","m-some","m-none"],bq={"m-full":{swatch:"node",label:"full"},"m-some":{swatch:"node-dashed",label:"partial"},"m-none":{swatch:"chip",chip:"—",label:"none"}};function wq(e){const t=e.trim().toLowerCase();return t===""||t==="—"||t==="-"||t==="none"||t==="no"||t==="✗"||t==="x"?"m-none":t==="full"||t==="all"||t==="admin"||t==="owner"||t==="yes"||t==="✓"||t==="write"||t==="manage"?"m-full":"m-some"}function $q(e){const t=e.corner??"",n=`<tr><th class="mx-corner"${_("corner")}>${S(t)}</th>`+e.cols.map((d,u)=>`<th scope="col"${_(`cols.${u}`)}>${S(d)}</th>`).join("")+"</tr>",s=new Set,o=e.rows.map((d,u)=>{const p=e.cols.map((h,m)=>{const g=d.cells[m]??"",v=g.trim()===""?"—":g,y=wq(g);return s.add(y),`<td class="mx-cell ${y}"${_(`rows.${u}.cells.${m}`)}>${S(v)}</td>`}).join("");return`<tr${_(`rows.${u}`)}><th scope="row" class="mx-row"${_(`rows.${u}.label`)}>${S(d.label)}</th>${p}</tr>`}).join(""),r=e.title!==void 0?`<div class="mx-title">${S(e.title)}</div>`:"",i=e.description!==void 0?`<p class="mx-desc">${S(e.description)}</p>`:"",l=ot(kq.filter(d=>s.has(d)).map(d=>bq[d]));return`<div class="matrix">${r}${i}<div class="mx-scroll"><table class="mx-grid"><thead>${n}</thead><tbody${he("rows")}>${o}</tbody></table></div>${l}</div>`}function Sq(e){const t=e.separator??":",n=e.parts.map((i,l)=>{const d=`a-seg-${l%4+1}`;return`${l>0?`<span class="a-sep"${_("separator")}>${S(t)}</span>`:""}<span class="a-seg ${d}"${_(`parts.${l}.value`)}>${S(i.value)}</span>`}).join(""),s=e.parts.map((i,l)=>{const d=`a-seg-${l%4+1}`,u=i.note!==void 0?`<div class="a-note"${_(`parts.${l}.note`)}>${S(i.note)}</div>`:"";return`<div class="a-card"${_(`parts.${l}`)}><div class="a-label ${d}"${_(`parts.${l}.label`)}>${S(i.label)}</div><div class="a-value"${_(`parts.${l}.value`)}>${S(i.value)}</div>${u}</div>`}).join(`<span class="a-card-sep"${_("separator")}>`+S(t)+"</span>"),o=e.title!==void 0?`<div class="a-title">${S(e.title)}</div>`:"",r=e.description!==void 0?`<p class="a-desc">${S(e.description)}</p>`:"";return`<div class="anatomy">${o}${r}<div class="a-string">${n}</div><div class="a-cards"${he("parts")}>${s}</div></div>`}function Eq(e){const t=e.gates.map((r,i)=>{const l=i>0?'<span class="cp-op">∩</span>':"",d=r.kicker!==void 0?`<div class="cp-gate-kicker"${_(`gates.${i}.kicker`)}>${S(r.kicker)}</div>`:"",u=r.desc!==void 0?`<div class="cp-desc"${_(`gates.${i}.desc`)}>${S(r.desc)}</div>`:"",p=r.source!==void 0?`<div class="cp-gate-src">${S(r.source)}</div>`:"";return`${l}<div class="cp-gate cp-g${i%4+1}"${_(`gates.${i}`)}><div class="cp-gate-head">${d}<div class="cp-gate-label"${_(`gates.${i}.label`)}>${S(r.label)}</div></div>${u}${p}</div>`}).join(""),n=e.result!==void 0?`<span class="cp-eq">=</span><div class="cp-result"><div class="cp-result-kicker">Effective</div><div class="cp-result-label"${_("result")}>${S(e.result)}</div></div>`:"",s=e.title!==void 0?`<div class="cp-title">${S(e.title)}</div>`:"",o=e.description!==void 0?`<p class="cp-desc-top">${S(e.description)}</p>`:"";return`<div class="composition">${s}${o}<div class="cp-row"${he("gates")}>${t}${n}</div></div>`}var yA={location:'<path d="M12 21s-7-6.3-7-11a7 7 0 0 1 14 0c0 4.7-7 11-7 11z"/><circle cx="12" cy="10" r="2.5"/>',shield:'<path d="M12 3l7 3v5c0 4.5-3 8-7 10-4-2-7-5.5-7-10V6l7-3z"/><path d="M9 12l2 2 4-4"/>',grid:'<rect x="3" y="3" width="18" height="18" rx="2"/><path d="M3 9h18M3 15h18M9 3v18"/>',lock:'<rect x="3" y="11" width="18" height="10" rx="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/><circle cx="12" cy="16" r="1.5"/>',key:'<circle cx="8" cy="15" r="4"/><path d="M11 12l8-8M17 5l2 2M14 8l2 2"/>',user:'<circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 4-6 8-6s8 2 8 6"/>',clock:'<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>',check:'<path d="M20 6L9 17l-5-5"/>',database:'<ellipse cx="12" cy="5" rx="8" ry="3"/><path d="M4 5v14c0 1.7 3.6 3 8 3s8-1.3 8-3V5"/><path d="M4 12c0 1.7 3.6 3 8 3s8-1.3 8-3"/>',bolt:'<path d="M13 2L4 14h7l-1 8 9-12h-7z"/>',flag:'<path d="M5 21V4M5 4h11l-2 4 2 4H5"/>',doc:'<path d="M14 3H6v18h12V7z"/><path d="M14 3v4h4"/>',link:'<path d="M10 13a5 5 0 0 0 7 0l2-2a5 5 0 0 0-7-7l-1 1"/><path d="M14 11a5 5 0 0 0-7 0l-2 2a5 5 0 0 0 7 7l1-1"/>',eye:'<path d="M2 12s4-7 10-7 10 7 10 7-4 7-10 7S2 12 2 12z"/><circle cx="12" cy="12" r="3"/>',server:'<rect x="3" y="4" width="18" height="7" rx="2"/><rect x="3" y="13" width="18" height="7" rx="2"/><path d="M7 7.5h.01M7 16.5h.01"/>',layers:'<path d="M12 2l9 5-9 5-9-5 9-5z"/><path d="M3 12l9 5 9-5"/><path d="M3 17l9 5 9-5"/>'};function Mq(e,t){const n=e.accent!==void 0?` dv-${e.accent}`:"",s=e.icon!==void 0?yA[e.icon]??'<circle cx="12" cy="12" r="8"/>':"",o=s!==""?`<svg class="dv-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${s}</svg>`:"",r=e.body!==void 0?`<div class="dv-sub"${_(`items.${t}.body`)}>${S(e.body)}</div>`:"",i=e.tag!==void 0?`<div class="dv-tag"${_(`items.${t}.tag`)}>${S(e.tag)}</div>`:"";return`<div class="dv-card${n}"${_(`items.${t}`)}>${o}<div class="dv-title"${_(`items.${t}.title`)}>${S(e.title)}</div>${r}${i}</div>`}function Aq(e){const t=e.items??[],n=e.title!==void 0?`<div class="dv-head">${S(e.title)}</div>`:"",s=e.description!==void 0?`<p class="dv-desc">${S(e.description)}</p>`:"";return`<div class="drivers">${n}${s}<div class="dv-grid"${he("items")}>${t.map((o,r)=>Mq(o,r)).join("")}</div></div>`}function Cq(e,t){const n=e.tone??"neutral",s=n==="chosen"?" is-chosen":"",o=e.kicker!==void 0?`<span class="op-kicker">${S(e.kicker)}</span>`:"",r=e.how!==void 0?`<div class="op-how"${_(`items.${t}.how`)}>${S(e.how)}</div>`:"",i=e.pros!==void 0&&e.pros.length>0?`<ul class="op-list op-pros"${he(`items.${t}.pros`)}>${e.pros.map((u,p)=>`<li${_(`items.${t}.pros.${p}`)}>${S(u)}</li>`).join("")}</ul>`:"",l=e.cons!==void 0&&e.cons.length>0?`<ul class="op-list op-cons"${he(`items.${t}.cons`)}>${e.cons.map((u,p)=>`<li${_(`items.${t}.cons.${p}`)}>${S(u)}</li>`).join("")}</ul>`:"",d=e.verdict!==void 0?`<div class="op-verdict op-v-${n}"${_(`items.${t}.verdict`)}>${S(e.verdict)}</div>`:"";return`<div class="op-card${s}"${_(`items.${t}`)}><div class="op-head op-h-${n}">${o}<span class="op-title"${_(`items.${t}.title`)}>${S(e.title)}</span></div>${r}<div class="op-body">${i}${l}</div>${d}</div>`}function Nq(e){const t=e.items??[],n=e.title!==void 0?`<div class="op-headline">${S(e.title)}</div>`:"",s=e.description!==void 0?`<p class="op-desc">${S(e.description)}</p>`:"";return`<div class="options">${n}${s}<div class="op-grid"${he("items")}>${t.map((o,r)=>Cq(o,r)).join("")}</div></div>`}function Tq(e,t){let n,s=_(`rows.${t}.value`);if(e.steps!==void 0&&e.steps.length>0){const o=e.steps.map((r,i)=>`<span class="sp-step"${_(`rows.${t}.steps.${i}`)}>${S(r)}</span>`).join('<span class="sp-arrow">&rarr;</span>');n=`<div class="sp-flow"${he(`rows.${t}.steps`)}>${o}</div>`,s=""}else n=S(e.value??"");return`<div class="sp-label"${_(`rows.${t}.label`)}>${S(e.label)}</div><div class="sp-val"${s}>${n}</div>`}function _q(e){const t=e.rows??[],n=e.accent!==void 0?` sp-${e.accent}`:"",s=e.title!==void 0?`<div class="sp-head">${S(e.title)}</div>`:"",o=e.description!==void 0?`<p class="sp-desc">${S(e.description)}</p>`:"";return`<div class="spec">${s}${o}<div class="sp-grid${n}"${he("rows")}>${t.map((r,i)=>Tq(r,i)).join("")}</div></div>`}function Lq(e){return`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${yA[e]??'<circle cx="12" cy="12" r="8"/>'}</svg>`}function Iq(e,t,n){if(t==="check"){const s=e.done===!1;return`<span class="ls-mark ls-check${s?" ls-off":""}" aria-hidden="true">${s?"○":"✓"}</span>`}return t==="number"?`<span class="ls-mark ls-num" aria-hidden="true">${n+1}</span>`:t==="icon"?`<span class="ls-mark ls-icon" aria-hidden="true">${Lq(e.icon??"check")}</span>`:'<span class="ls-mark ls-bar" aria-hidden="true"></span>'}function jq(e,t,n,s){const o=e.accent??s,r=o!==void 0?` ls-${o}`:"",i=e.text!==void 0?`<span class="ls-text"${_(`items.${n}.text`)}>${S(e.text)}</span>`:"";return`<li class="ls-item${r}"${_(`items.${n}`)}>`+Iq(e,t,n)+`<span class="ls-body"><span class="ls-lead"${_(`items.${n}.lead`)}>${S(e.lead)}</span>${i}</span></li>`}function Pq(e){const t=e.style??"accent",n=e.title!==void 0?`<div class="ls-head">${S(e.title)}</div>`:"",s=e.description!==void 0?`<p class="ls-desc">${S(e.description)}</p>`:"",o=e.items.map((r,i)=>jq(r,t,i,e.accent)).join("");return`<div class="list-block ls-style-${t}">${n}${s}<ul class="ls-list"${he("items")}>${o}</ul></div>`}function Vg(e,t){return`<span class="st-chip ${e}">${S(t)}</span>`}function Oq(e,t){const n=e.title??e.want??e.role??"Story",s=e.title!==void 0?"title":e.want!==void 0?"want":e.role!==void 0?"role":void 0,o=s!==void 0?_(`items.${t}.${s}`):"",r=e.id!==void 0?`<span class="st-id"${_(`items.${t}.id`)}>${S(e.id)}</span>`:"",i=[];e.points!==void 0&&i.push(Vg("st-points",`${e.points} pts`)),e.priority!==void 0&&i.push(Vg("st-prio",e.priority));for(const d of e.tags??[])i.push(Vg("st-tag",d));const l=i.length>0?`<span class="st-chips">${i.join("")}</span>`:"";return`<summary class="st-summary"><span class="st-caret" aria-hidden="true"></span><span class="st-sum-main">${r}<span class="st-sum-title"${o}>${S(n)}</span></span>`+l+"</summary>"}function Rq(e,t){if(e.role===void 0&&e.want===void 0&&e.soThat===void 0)return"";const n=[];return e.role!==void 0&&n.push(`<b>As</b> <span${_(`items.${t}.role`)}>${S(e.role)}</span>`),e.want!==void 0&&n.push(`<b>I want</b> <span${_(`items.${t}.want`)}>${S(e.want)}</span>`),e.soThat!==void 0&&n.push(`<b>so that</b> <span${_(`items.${t}.soThat`)}>${S(e.soThat)}</span>`),`<p class="st-narr">${n.join(", ")}.</p>`}function Dq(e,t){const n=e.criteria??[];if(n.length===0)return"";const s=n.map((o,r)=>{const i=[];return o.given!==void 0&&i.push(`<b>Given</b> ${S(o.given)}`),o.when!==void 0&&i.push(`<b>when</b> ${S(o.when)}`),o.then!==void 0&&i.push(`<b>then</b> ${S(o.then)}`),`<li${_(`items.${t}.criteria.${r}`)}>${i.join(", ")}.</li>`}).join("");return`<div class="st-ac-label">Acceptance criteria</div><ul class="st-ac"${he(`items.${t}.criteria`)}>${s}</ul>`}function Bq(e,t){const n=e.links??[];if(n.length===0)return"";const s=n.map((o,r)=>{const i=o.label??o.ref??o.mode??"link";return o.ref!==void 0&&o.ref!==""?`<a class="st-link" data-ref="${S(o.ref)}" href="#${S($4(o.ref))}"${_(`items.${t}.links.${r}`)}>${S(i)}</a>`:`<span class="st-link"${_(`items.${t}.links.${r}`)}>${S(i)}</span>`}).join("");return`<div class="st-links"${he(`items.${t}.links`)}>${s}</div>`}function zq(e,t){return`<details class="st-item"${e.open===!0?" open":""}${_(`items.${t}`)}>`+Oq(e,t)+`<div class="st-body">${Rq(e,t)}${Dq(e,t)}${Bq(e,t)}</div></details>`}function Fq(e){const t=e.title!==void 0?`<div class="st-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="st-desc">${S(e.description)}</p>`:"",s=e.items.map((o,r)=>zq(o,r)).join("");return`<div class="stories">${t}${n}<div class="st-list"${he("items")}>${s}</div></div>`}function Gu(e,t,n){return t===void 0||t===""?"":`<div class="pt-row"><div class="pt-label">${e}</div><div class="pt-value"${_(n)}>${S(t)}</div></div>`}function qq(e,t,n){if(t===void 0||t.length===0)return"";const s=t.map((o,r)=>`<span class="pt-chip"${_(`${n}.${r}`)}>${S(o)}</span>`).join("");return`<div class="pt-row"><div class="pt-label">${e}</div><div class="pt-value"><div class="pt-chips"${he(n)}>${s}</div></div></div>`}function Hq(e){const t=e.participants??[];if(t.length===0)return"";const n=t.map((s,o)=>{const r=s.role!==void 0?`<span class="pt-prole"${_(`participants.${o}.role`)}>${S(s.role)}</span>`:"";return`<li${_(`participants.${o}`)}><span class="pt-pname"${_(`participants.${o}.name`)}>${S(s.name)}</span>${r}</li>`}).join("");return`<div class="pt-row"><div class="pt-label">Participants</div><div class="pt-value"><ul class="pt-parts"${he("participants")}>${n}</ul></div></div>`}function Wq(e){const t=e.consequences;if(t===void 0)return"";const n=t.pros??[],s=t.cons??[];if(n.length===0&&s.length===0)return"";const o=(r,i,l,d)=>l.length===0?"":`<ul class="pt-cons-list ${r}"${he(d)}>${l.map((u,p)=>`<li${_(`${d}.${p}`)}><span class="pt-sign">${i}</span>${S(u)}</li>`).join("")}</ul>`;return`<div class="pt-row"><div class="pt-label">Consequences</div><div class="pt-value"><div class="pt-cons">${o("pt-pro","+",n,"consequences.pros")}${o("pt-con","−",s,"consequences.cons")}</div></div></div>`}function Uq(e){const t=e.category!==void 0?`<span class="pt-cat"${_("category")}>${S(e.category)}</span>`:"",n=`<div class="pt-header"><span class="pt-kicker">PATTERN</span><span class="pt-name"${_("name")}>${S(e.name)}</span>${t}</div>`,s=Gu("Intent",e.intent,"intent")+qq("Forces",e.forces,"forces")+Gu("Solution",e.solution,"solution")+Gu("Structure",e.structure,"structure")+Hq(e)+Wq(e)+Gu("Notes",e.note,"note");return`<div class="pattern">${n}<div class="pt-rows">${s}</div></div>`}function Kq(e){const t={...e};delete t.type;const n=DA[e.type];return n!==void 0?n(t):""}function Vq(e,t){const n=e.accent!==void 0?` gl-${e.accent}`:"",s=e.title!==void 0?`<div class="gl-card-title"${_(`items.${t}.title`)}>${S(e.title)}</div>`:"",o=e.caption!==void 0?`<div class="gl-cap"${_(`items.${t}.caption`)}>${S(e.caption)}</div>`:"";if(e.block!==void 0)return`<div class="gl-cell${n}"${_(`items.${t}`)}>${s}${Kq(e.block)}${o}</div>`;if(e.code!==void 0){const r=e.title!==void 0||e.lang!==void 0?`<div class="code-header"><span>${S(e.title??"")}</span><span>${S(e.lang??"")}</span></div>`:"";return`<div class="gl-card gl-code${n}"${_(`items.${t}`)}>${r}<pre${_(`items.${t}.code`)}>${fh(e.code,e.lang)}</pre>${o}</div>`}return`<div class="gl-card${n}"${_(`items.${t}`)}>${s}${o}</div>`}function Gq(e){const t=e.title!==void 0?`<div class="gl-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="gl-desc">${S(e.description)}</p>`:"",o=` style="--gl-cols:${e.cols!==void 0&&e.cols>0?Math.floor(e.cols):2}"`,r=e.items.map((i,l)=>Vq(i,l)).join("");return`<div class="gallery">${t}${n}<div class="gl-grid"${o}${he("items")}>${r}</div></div>`}var xA=["#3d4656","#8a5a3c","#5f7f6e","#6b6f9c","#8a7a48"],Gg=xA.length,tx={dark:"#1f2937",light:"#ffffff",fallback:"#d1d5db"};function Qi(e,t,n){if(n==="red")return"var(--negative)";if(t<=1)return"var(--ink)";const s=(e%Gg+Gg)%Gg;return`var(--series-${s+1}, ${xA[s]??""})`}var gh={fill:"var(--ink)",stroke:"var(--ink)",dark:!0},Yq={fill:"var(--ink-2)",stroke:"var(--ink-2)",dark:!0},kA={fill:"var(--ink-3)",stroke:"var(--ink-3)",dark:!1},Xq={fill:"var(--muted)",stroke:"var(--muted)",dark:!0},bA={fill:"var(--paper-2)",stroke:"var(--ink)",dark:!1},wA=[gh,Yq,kA,bA],v$=[gh,kA,Xq,bA],Yg=wA.length;function Xn(e){const t=e.filter(n=>n!==void 0&&n!=="red").length;return e.map(n=>n==="red"?"negative":n!==void 0&&t===1?"focal":void 0)}function nx(e,t){if(t==="negative")return{fill:"var(--negative)",stroke:"var(--negative)",dark:!0};if(t==="focal")return{fill:"var(--accent)",stroke:"var(--accent)",dark:!0};const n=(e%Yg+Yg)%Yg;return wA[n]??gh}function sx(e,t){if(t!==void 0)return nx(e,t);const n=v$.length;return v$[(e%n+n)%n]??gh}var Qq={active:{fill:"var(--paper)",stroke:"var(--accent)",text:"var(--accent)",sw:1.75,dash:""},target:{fill:"var(--accent-tint)",stroke:"var(--accent)",text:"var(--ink)",sw:1.75,dash:""},visited:{fill:"var(--paper-2)",stroke:"var(--rule-solid)",text:"var(--muted)",sw:1,dash:""},muted:{fill:"var(--paper)",stroke:"var(--rule-solid)",text:"var(--soft)",sw:1,dash:"4 3"}},y$={fill:"var(--paper)",stroke:"var(--ink)",text:"var(--ink)",sw:1.5,dash:""};function vh(e){return e===void 0?y$:Qq[e]??y$}function yh(e){const t=e.dash.length>0?` stroke-dasharray="${e.dash}"`:"";return` fill="${e.fill}" stroke="${e.stroke}" stroke-width="${e.sw}"${t}`}var xh={active:{swatch:"node-accent-outline",label:"current"},target:{swatch:"node-accent",label:"target"},visited:{swatch:"node-fill2",label:"visited"},muted:{swatch:"node-dashed",label:"out of play"}},Tt=e=>Number.isFinite(e)&&e>0?e:0;function rt(e,t){return`${Math.round(e*100)/100}${t??""}`}function ox(e){if(!(e>0))return 1;const t=Math.pow(10,Math.floor(Math.log10(e/5))),n=[1,2,2.5,5,10].map(r=>r*t);let s=n[0]??1,o=1/0;for(const r of n){const i=Math.ceil(e/r-1e-9),l=i>=4&&i<=6?Math.abs(i-5):10+Math.abs(i-5);l<o&&(s=r,o=l)}return s}function x$(e){if(!(e>0)||!Number.isFinite(e))return 1;const t=Math.pow(10,Math.floor(Math.log10(e))),n=[1,2,2.5,5,10].map(r=>r*t);let s=n[0]??1,o=1/0;for(const r of n){const i=Math.abs(Math.log10(r)-Math.log10(e));i<o&&(s=r,o=i)}return s}function kh(e){const t=ox(e),n=Math.max(1,Math.ceil(e/t-1e-9));return Array.from({length:n+1},(s,o)=>Math.round(o*t*1e6)/1e6)}function w0(e){let t=Math.min(...e),n=Math.max(...e);if(t===n){const l=t===0?1:Math.abs(t)*.2;t-=l,n+=l}else{const l=(n-t)*.06;t-=l,n+=l}const s=ox(n-t),o=Math.floor(t/s)*s,r=Math.ceil(n/s)*s,i=[];for(let l=o;l<=r+s/2;l+=s)i.push(Math.round(l*1e6)/1e6);return{min:o,max:r,ticks:i}}var rn=e=>Math.round(e*10)/10;function oo(e,t){return`<svg viewBox="0 0 ${e} ${t}" role="img"><title>Chart</title>`}var Hc=6;function bh(e,t){const n=Math.max(3,Math.floor(t));return e.length>n?`${e.slice(0,n-1)}…`:e}function rx(e){return(e??[]).filter(t=>Number.isFinite(t))}var Up=e=>Math.round(e*1e9)/1e9;function $A(e,t){const n=rx(e),s=n.length;if(s===0)return{bins:[],width:1,n:0};const o=t!==void 0&&t>0?Math.max(1,Math.round(t)):Math.ceil(Math.log2(s))+1,r=Math.min(...n),i=Math.max(...n),l=i-r,d=l>0?x$(l/o):x$(Math.abs(r)/10||1),u=Up(Math.floor(r/d+1e-9)*d),p=Math.max(1,Math.ceil((i-u)/d-1e-9)),h=new Array(p).fill(0);for(const g of n){const v=Math.min(p-1,Math.max(0,Math.floor((g-u)/d+1e-9)));h[v]=(h[v]??0)+1}return{bins:h.map((g,v)=>({lo:Up(u+v*d),hi:Up(u+(v+1)*d),count:g})),width:d,n:s}}function $0(e){return e.length>0?e.reduce((t,n)=>t+n,0)/e.length:0}function Zq(e,t){if(e.length<2)return 0;const n=e.reduce((s,o)=>s+(o-t)*(o-t),0);return Math.sqrt(n/(e.length-1))}function SA(e,t,n,s=18,o=18){const r=Math.max(420,Math.min(760,110+e*n)),i=250,l=kh(t>0?t:1);return{width:r,height:i,x0:52,x1:r-o,y0:s,y1:i-32,yMax:l[l.length-1]??1,ticks:l}}function EA(e,t){let n="";return e.ticks.forEach((s,o)=>{const r=Math.round(e.y1-(e.y1-e.y0)*s/e.yMax);n+=`<line x1="${e.x0}" y1="${r}" x2="${e.x1}" y2="${r}" stroke="${o===0?"var(--rule-solid)":"var(--rule)"}" stroke-width="1"${ut}/>`,n+=`<text x="${e.x0-8}" y="${r+3}" class="t-sub c-soft" text-anchor="end">${S(rt(s,t))}</text>`}),n}function S0(e,t){return e==="negative"?"var(--negative)":e==="focal"?"var(--accent)":t}function Jq(e){const t=rx(e.values),n=t.length===0&&(e.labels?.length??0)>0&&(e.series?.length??0)>0,s=e.series?.[0],o=n?e.labels??[]:[],r=n?void 0:$A(t,e.bins),i=n?o.map((E,$)=>Tt(s?.values[$]??0)):(r?.bins??[]).map(E=>E.count),l=i.length,d=Math.max(0,...i),u=e.max!==void 0&&e.max>0?e.max:d,p=SA(l,u,50),h=p.x1-p.x0,m=l>0?h/l:h,g=E=>Math.round(p.y1-(p.y1-p.y0)*Math.min(E,p.yMax)/p.yMax);let v=oo(p.width,p.height)+EA(p,void 0);const y=m>=22;if(v+=`<g${n?he("series"):_("values")}>`,i.forEach((E,$)=>{const A=rn(p.x0+m*$),T=g(E),N=Math.max(p.y1-T,E>0?1:0),j=r?.bins[$],P=j!==void 0?`${rt(j.lo,e.unit)} – ${rt(j.hi,e.unit)}: ${E}`:`${o[$]??""}: ${E}`,I=n?_(`series.0.values.${$}`):"";v+=`<g${I}>`,v+=`<rect x="${A}" y="${T}" width="${rn(m)}" height="${N}" fill="var(--ink)" stroke="var(--paper-2)" stroke-width="1"${E===0?' opacity="0.35"':""}><title>${S(P)}</title></rect>`,y&&E>0&&(v+=`<text x="${rn(A+m/2)}" y="${T-4}" class="t-arrow" text-anchor="middle">${S(String(E))}</text>`),v+="</g>"}),v+="</g>",n)v+=`<g${he("labels")}>`,o.forEach((E,$)=>{const A=bh(E,m/Hc),T=A!==E?`<title>${S(E)}</title>`:"";v+=`<text x="${rn(p.x0+m*($+.5))}" y="${p.y1+18}" class="t-sub" text-anchor="middle"${_(`labels.${$}`)}>${S(A)}${T}</text>`}),v+="</g>";else if(r!==void 0&&r.bins.length>0){const E=[...r.bins.map(T=>T.lo),r.bins[r.bins.length-1]?.hi??0],$=Math.max(...E.map(T=>rt(T,void 0).length))*Hc+8,A=Math.max(1,Math.ceil($/m));E.forEach((T,N)=>{const j=rn(p.x0+m*N);v+=`<line x1="${j}" y1="${p.y1}" x2="${j}" y2="${p.y1+4}" stroke="var(--rule-solid)" stroke-width="1"${ut}/>`;const P=N===E.length-1;N%A!==0&&!P||(v+=`<text x="${j}" y="${p.y1+18}" class="t-sub" text-anchor="${P?"end":N===0?"start":"middle"}">${S(rt(T,P?e.unit:void 0))}</text>`)})}const b=[{swatch:"fill",fill:"var(--ink)",label:"count per bin"}];if(r!==void 0&&r.bins.length>0&&t.length>0){const E=$0(t),$=r.bins[0]?.lo??0,A=r.bins[r.bins.length-1]?.hi??1,T=rn(p.x0+h*(E-$)/(A-$)),N=`mean ${rt(E,e.unit)}`,j=T+N.length*Hc+8>p.x1;v+=`<g><title>${S(`mean ${rt(E,e.unit)} · n = ${t.length}`)}</title>`,v+=`<line x1="${T}" y1="${p.y0-4}" x2="${T}" y2="${p.y1}" stroke="var(--accent)" stroke-width="1.25" stroke-dasharray="5 4"/>`,v+=`<text x="${j?T-5:T+5}" y="${p.y0+4}" class="t-arrow c-accent"${j?' text-anchor="end"':""}>${S(N)}</text>`,v+="</g>",b.push({swatch:"line-dashed",stroke:"var(--accent)",label:"mean"})}return v+="</svg>",{svg:v,legend:ot(b)}}function eH(e,t){if(e.mean!==void 0&&e.sd!==void 0&&e.sd>0)return{mean:e.mean,sd:e.sd,fitted:!1};const n=e.mean??$0(t),s=e.sd!==void 0&&e.sd>0?e.sd:Zq(t,$0(t));return{mean:n,sd:s>0&&Number.isFinite(s)?s:1,fitted:!0}}var tH=(e,t,n)=>Math.round((e-t)/n*10)/10;function nH(e){const t=rx(e.values),{mean:n,sd:s,fitted:o}=eH(e,t),r=(e.markers??[]).filter(Z=>Number.isFinite(Z.at)),i=Z=>Math.exp(-.5*((Z-n)/s)**2)/(s*Math.sqrt(2*Math.PI));let l=n-3.5*s,d=n+3.5*s;for(const Z of r)l=Math.min(l,Z.at-.25*s),d=Math.max(d,Z.at+.25*s);const u=ox(d-l),p=[];for(let Z=Math.ceil(l/u)*u;Z<=d+1e-9;Z+=u)p.push(Up(Z));const m=t.length>0&&(e.bins!==void 0||t.length>=20)?$A(t,e.bins):void 0,g=Z=>m!==void 0&&m.n>0?Z.count/(m.n*m.width):0,v=m!==void 0?Math.max(0,...m.bins.map(g)):0;m!==void 0&&(l=Math.min(l,m.bins[0]?.lo??l),d=Math.max(d,m.bins[m.bins.length-1]?.hi??d));const y=560,b=r.length>0?1:0,E=24,$=y-24,A=Z=>rn(E+($-E)*(Z-l)/(d-l)),T=r.map((Z,q)=>({m:Z,i:q,x:A(Z.at)})).sort((Z,q)=>Z.x-q.x),N=new Map;let j=-1/0,P=0;for(const Z of T){const q=Z.x-j<72?(P+1)%2:0;N.set(Z.i,q),j=Z.x,P=q}const I=[...N.values()].some(Z=>Z===1),O=b===0?34:I?82:56,C=O+170+32,D=O,F=C-32,U=Math.max(i(n),v)*1.05,X=Z=>rn(F-(F-D)*Z/U);let B=oo(y,C);B+=`<line x1="${E}" y1="${F}" x2="${$}" y2="${F}" stroke="var(--rule-solid)" stroke-width="1"${ut}/>`;for(const Z of p){const q=A(Z);B+=`<line x1="${q}" y1="${D}" x2="${q}" y2="${F}" stroke="var(--rule)" stroke-width="1"${ut}/>`,B+=`<text x="${q}" y="${F+18}" class="t-sub c-soft" text-anchor="middle">${S(rt(Z,e.unit))}</text>`}if(m!==void 0){B+=`<g${_("values")}>`;for(const Z of m.bins){const q=g(Z),de=A(Z.lo),le=rn(A(Z.hi)-de),J=X(q);B+=`<rect x="${de}" y="${J}" width="${le}" height="${rn(Math.max(F-J,0))}" fill="var(--ink)" fill-opacity="0.08" stroke="var(--rule-solid)" stroke-width="1"><title>${S(`${rt(Z.lo,e.unit)} – ${rt(Z.hi,e.unit)}: ${Z.count} of ${m.n}`)}</title></rect>`}B+="</g>"}const ee=(d-l)/140,H=Math.ceil(Math.max(n-l,d-n)/ee),W=[l];for(let Z=-H;Z<=H;Z++){const q=n+Z*ee;q>l&&q<d&&W.push(q)}W.push(d);const K=Z=>`${A(Z)},${X(i(Z))}`,R=(Z,q)=>{const de=W.filter(J=>J>Z&&J<q),le=[Z,...de,q].map(K);return`M ${A(Z)},${F} L ${le.join(" L ")} L ${A(q)},${F} Z`};B+=`<path d="${R(n-2*s,n+2*s)}" fill="var(--accent)" fill-opacity="0.1" stroke="none"><title>${S(`μ ± 2σ: ${rt(n-2*s,e.unit)} – ${rt(n+2*s,e.unit)} (95.4%)`)}</title></path>`,B+=`<path d="${R(n-s,n+s)}" fill="var(--accent)" fill-opacity="0.22" stroke="none"><title>${S(`μ ± 1σ: ${rt(n-s,e.unit)} – ${rt(n+s,e.unit)} (68.3%)`)}</title></path>`,B+=`<path class="chart-bell" d="M ${W.map(K).join(" L ")}" fill="none" stroke="var(--ink)" stroke-width="1.75" stroke-linejoin="round"><title>${S(`normal curve, μ = ${rt(n,e.unit)}, σ = ${rt(s,e.unit)}`)}</title></path>`,B+=`<line class="chart-bell-mean" x1="${A(n)}" y1="${X(i(n))}" x2="${A(n)}" y2="${F}" stroke="var(--rule-solid)" stroke-width="1" stroke-dasharray="2 3"><title>${S(`μ = ${rt(n,e.unit)}`)}</title></line>`;const z=Xn(r.map(Z=>Z.accent));r.length>0&&(B+=`<g${he("markers")}>`),r.forEach((Z,q)=>{const de=A(Z.at),le=N.get(q)??0,J=S0(z[q],"var(--ink)"),ue=tH(Z.at,n,s),ve=12+le*26,we=de<E+40?"start":de>$-40?"end":"middle";B+=`<g${_(`markers.${q}`)}><title>${S(`${Z.label} at ${rt(Z.at,e.unit)} · z = ${ue.toFixed(1)}`)}</title>`,B+=`<line x1="${de}" y1="${ve+16}" x2="${de}" y2="${F}" stroke="${J}" stroke-width="1.25" stroke-dasharray="5 4"/>`,B+=`<text x="${de}" y="${ve}" class="t-sub c-ink" text-anchor="${we}"${_(`markers.${q}.label`)}>${S(Z.label)}</text>`,B+=`<text x="${de}" y="${ve+12}" class="t-arrow" text-anchor="${we}">${S(`z = ${ue.toFixed(1)}`)}</text>`,B+="</g>"}),r.length>0&&(B+="</g>");const Y=T.some(Z=>Z.x<E+110&&(N.get(Z.i)??0)===0),V=Y?$-2:E+2,re=Y?"end":"start",Q=12;B+=`<text x="${V}" y="${Q}" class="t-sub c-ink" text-anchor="${re}">${S(`μ = ${rt(n,e.unit)}`)}</text>`,B+=`<text x="${V}" y="${Q+13}" class="t-sub c-ink" text-anchor="${re}">${S(`σ = ${rt(s,e.unit)}${o?` · n = ${t.length}`:""}`)}</text>`,B+="</svg>";const ne=[{swatch:"fill",fill:"var(--accent)",label:"±1 σ · 68%"},{swatch:"fill",fill:"var(--accent-tint)",label:"±2 σ · 95%"}];return r.length>0&&ne.push({swatch:"line-dashed",stroke:"var(--ink)",label:"marker (z-score)"}),m!==void 0&&ne.push({swatch:"node-fill2",label:"sample histogram (density)"}),{svg:B,legend:ot(ne)}}function sH(e){const t=e.boxes??[],n=t.length,s=t.flatMap($=>[$.min,$.q1,$.median,$.q3,$.max,...$.outliers??[]]).filter(Number.isFinite),o=w0(s.length>0?s:[0,1]),r=Math.max(420,Math.min(760,110+n*96)),i=260,l=52,d=r-18,u=18,p=i-32,h=$=>rn(p-(p-u)*($-o.min)/(o.max-o.min)),m=n>0?(d-l)/n:d-l,g=Math.min(56,Math.round(m*.5));let v=oo(r,i);for(const $ of o.ticks){const A=h($);v+=`<line x1="${l}" y1="${A}" x2="${d}" y2="${A}" stroke="${$===o.min?"var(--rule-solid)":"var(--rule)"}" stroke-width="1"${ut}/>`,v+=`<text x="${l-8}" y="${A+3}" class="t-sub c-soft" text-anchor="end">${S(rt($,e.unit))}</text>`}const y=Xn(t.map($=>$.accent));let b=0;v+=`<g${he("boxes")}>`,t.forEach(($,A)=>{const T=rn(l+m*(A+.5)),N=y[A],j=S0(N,"var(--ink)"),P=N==="focal"?"var(--accent-tint)":N==="negative"?"var(--negative-tint)":"var(--paper-2)",I=S0(N,"var(--accent)"),O=Math.min($.min,$.q1),C=Math.max($.max,$.q3),D=Math.min($.q1,$.q3),F=Math.max($.q1,$.q3),U=`${$.label} — min ${rt($.min,e.unit)} · q1 ${rt($.q1,e.unit)} · median ${rt($.median,e.unit)} · q3 ${rt($.q3,e.unit)} · max ${rt($.max,e.unit)}`,X=Math.round(g/2);v+=`<g${_(`boxes.${A}`)}><title>${S(U)}</title>`,v+=`<line x1="${T}" y1="${h(O)}" x2="${T}" y2="${h(D)}" stroke="${j}" stroke-width="1.25"/>`,v+=`<line x1="${T}" y1="${h(F)}" x2="${T}" y2="${h(C)}" stroke="${j}" stroke-width="1.25"/>`,v+=`<line x1="${T-X/2}" y1="${h(O)}" x2="${T+X/2}" y2="${h(O)}" stroke="${j}" stroke-width="1.25"/>`,v+=`<line x1="${T-X/2}" y1="${h(C)}" x2="${T+X/2}" y2="${h(C)}" stroke="${j}" stroke-width="1.25"/>`;const B=h(F),te=Math.max(rn(h(D)-B),1);v+=`<rect x="${T-g/2}" y="${B}" width="${g}" height="${te}" fill="${P}" stroke="${j}" stroke-width="1.25"/>`,v+=`<line class="chart-median" x1="${T-g/2}" y1="${h($.median)}" x2="${T+g/2}" y2="${h($.median)}" stroke="${I}" stroke-width="2.5"${_(`boxes.${A}.median`)}><title>${S(`${$.label} median ${rt($.median,e.unit)}`)}</title></line>`,($.outliers??[]).filter(Number.isFinite).forEach((W,K)=>{b++,v+=`<circle class="chart-outlier" cx="${T}" cy="${h(W)}" r="3" fill="var(--paper)" stroke="${j}" stroke-width="1.25"${_(`boxes.${A}.outliers.${K}`)}><title>${S(`${$.label} outlier ${rt(W,e.unit)}`)}</title></circle>`});const ee=bh($.label,m/Hc),H=ee!==$.label?`<title>${S($.label)}</title>`:"";v+=`<text x="${T}" y="${p+18}" class="t-sub" text-anchor="middle"${_(`boxes.${A}.label`)}>${S(ee)}${H}</text>`,v+="</g>"}),v+="</g></svg>";const E=[{swatch:"node-fill2",label:"box = q1 – q3"},{swatch:"line",stroke:"var(--accent)",label:"median"},{swatch:"line",stroke:"var(--ink)",label:"whiskers = min – max"}];return b>0&&E.push({swatch:"node-dot",label:"outlier"}),y.includes("focal")&&E.push({swatch:"node-accent",label:"focal"}),y.includes("negative")&&E.push({swatch:"node-negative",label:"negative"}),{svg:v,legend:ot(E)}}function oH(e){const n=(e.items??[]).map(($,A)=>({it:$,i:A,v:Tt($.value)})).sort(($,A)=>A.v-$.v||$.i-A.i),s=n.length,o=n.reduce(($,A)=>$+A.v,0),r=Math.max(0,...n.map($=>$.v)),i=e.max!==void 0&&e.max>0?e.max:r,l=SA(s,i,64,18,52),d=s>0?(l.x1-l.x0)/s:l.x1-l.x0,u=rn(Math.min(56,d*.6)),p=$=>Math.round(l.y1-(l.y1-l.y0)*Math.min($,l.yMax)/l.yMax),h=$=>rn(l.y1-(l.y1-l.y0)*$/100);let m=oo(l.width,l.height)+EA(l,e.unit);for(let $=0;$<=100;$+=20)m+=`<text x="${l.x1+8}" y="${h($)+3}" class="t-sub c-soft">${$}%</text>`;m+=`<line x1="${l.x0}" y1="${h(80)}" x2="${l.x1}" y2="${h(80)}" stroke="var(--muted)" stroke-width="1" stroke-dasharray="5 4"><title>80% of the total</title></line>`;let g=0,v=!0;const y=[],b=[];return m+=`<g${he("items")}>`,n.forEach(($,A)=>{g+=$.v;const T=o>0?g/o*100:0,N=o>0?$.v/o*100:0,j=rn(l.x0+d*A+(d-u)/2),P=p($.v),I=Math.max(l.y1-P,$.v>0?1:0),O=rn(j+u/2),C=v?"var(--accent)":"var(--muted)",D=`${$.it.label} — ${rt($.v,e.unit)} (${Math.round(N*10)/10}%) · cumulative ${Math.round(T*10)/10}%`;m+=`<g class="${v?"chart-vital":"chart-rest"}"${_(`items.${$.i}`)}>`,m+=`<rect x="${j}" y="${P}" width="${u}" height="${I}" fill="${C}"${I<=1?' opacity="0.35"':""}><title>${S(D)}</title></rect>`,m+=`<text x="${O}" y="${P-4}" class="t-arrow" text-anchor="middle">${S(rt($.v,e.unit))}</text>`;const F=bh($.it.label,d/Hc),U=F!==$.it.label?`<title>${S($.it.label)}</title>`:"";m+=`<text x="${O}" y="${l.y1+18}" class="t-sub" text-anchor="middle"${_(`items.${$.i}.label`)}>${S(F)}${U}</text>`,m+="</g>";const X=h(T);y.push(`${O},${X}`),b.push(`<circle class="chart-cum" cx="${O}" cy="${X}" r="3" fill="var(--paper)" stroke="var(--ink)" stroke-width="1.5"><title>${S(`cumulative ${Math.round(T*10)/10}% after ${$.it.label}`)}</title></circle>`),T>=80-1e-9&&(v=!1)}),m+="</g>",y.length>1&&(m+=`<polyline class="chart-cum-line" points="${y.join(" ")}" fill="none" stroke="var(--ink)" stroke-width="1.75" stroke-linejoin="round"/>`),m+=b.join(""),m+="</svg>",{svg:m,legend:ot([{swatch:"fill",fill:"var(--accent)",label:"bars = value · the vital few, to 80%"},{swatch:"fill",fill:"var(--muted)",label:"bars = value · the rest"},{swatch:"line-dot",label:"line = cumulative %"},{swatch:"line-dashed",label:"80% rule"}],"items")}}var Xg=28,k$=600,rH={1:[.16],2:[.28,.12],3:[.32,.2,.09]};function iH(e){const t=e.bullets??[],n=t.length,s=t.flatMap(N=>[Tt(N.value),...N.target!==void 0?[Tt(N.target)]:[],...(N.ranges??[]).map(Tt)]),o=e.max!==void 0&&e.max>0?e.max:Math.max(0,...s),r=kh(o>0?o:1),i=r[r.length-1]??1,l=Math.max(0,...t.map(N=>N.label.length)),d=Math.min(180,Math.max(64,l*7+14)),u=Math.floor((d-14)/7),p=d,h=k$-66,m=6,g=m+n*Xg+24,v=N=>rn(p+(h-p)*Math.min(N,i)/i);let y=oo(k$,g);const b=m+n*Xg+2;for(const N of r){const j=v(N);y+=`<line x1="${j}" y1="${m}" x2="${j}" y2="${b}" stroke="var(--rule)" stroke-width="1"${ut}/>`,y+=`<text x="${j}" y="${b+14}" class="t-sub c-soft" text-anchor="middle">${S(rt(N,e.unit))}</text>`}y+=`<line x1="${p}" y1="${b}" x2="${h}" y2="${b}" stroke="var(--rule-solid)" stroke-width="1"${ut}/>`;const E=Xn(t.map(N=>N.accent));let $=0,A=0;y+=`<g${he("bullets")}>`,t.forEach((N,j)=>{const P=m+j*Xg,I=P+14,O=Tt(N.value),C=`${N.label} — ${rt(O,e.unit)}${N.target!==void 0?` of target ${rt(N.target,e.unit)}`:""}`;y+=`<g${_(`bullets.${j}`)}><title>${S(C)}</title>`;const D=bh(N.label,u),F=D!==N.label?`<title>${S(N.label)}</title>`:"";y+=`<text x="0" y="${I+4}" class="t-name"${_(`bullets.${j}.label`)}>${S(D)}${F}</text>`;const U=[...(N.ranges??[]).map(Tt)].sort((H,W)=>H-W),X=rH[Math.min(U.length,3)]??[];U.length>0&&(y+=`<g${he(`bullets.${j}.ranges`)}>`);for(let H=U.length-1;H>=0;H--){const W=U[H]??0,K=X[Math.min(H,X.length-1)]??.1;$++,y+=`<rect class="chart-band" x="${p}" y="${P+4}" width="${rn(v(W)-p)}" height="20" fill="var(--muted)" fill-opacity="${K}"${_(`bullets.${j}.ranges.${H}`)}><title>${S(`${N.label} range ${H+1}: up to ${rt(W,e.unit)}`)}</title></rect>`}U.length>0&&(y+="</g>");const B=v(O),te=E[j]==="negative"?"var(--negative)":"var(--accent)";y+=`<rect class="chart-measure" x="${p}" y="${I-4}" width="${rn(Math.max(B-p,O>0?1:0))}" height="8" fill="${te}"${_(`bullets.${j}.value`)}><title>${S(`${N.label} ${rt(O,e.unit)}`)}</title></rect>`;let ee=B+6;if(N.target!==void 0&&Number.isFinite(N.target)){A++;const H=v(Tt(N.target));y+=`<rect class="chart-target" x="${rn(H-1)}" y="${P+5}" width="2" height="18" fill="var(--ink)"${_(`bullets.${j}.target`)}><title>${S(`${N.label} target ${rt(N.target,e.unit)}`)}</title></rect>`,H>=B-2&&H<ee+4&&(ee=H+6)}y+=`<text x="${rn(ee)}" y="${I+3.5}" class="t-arrow c-ink">${S(rt(O,e.unit))}</text>`,y+="</g>"}),y+="</g></svg>";const T=[{swatch:"fill",fill:"var(--accent)",label:"measure"}];return A>0&&T.push({swatch:"line",stroke:"var(--ink)",label:"target"}),$>0&&T.push({swatch:"node-fill2",label:"qualitative ranges (darkest = poorest)"}),E.includes("negative")&&T.push({swatch:"fill",fill:"var(--negative)",label:"negative"}),{svg:y,legend:ot(T,"bullets")}}var E0=' style="fill:var(--paper);stroke:none"';function wh(e,t,n=!1){const s=Math.max(420,Math.min(680,120+t*84)),o=240,r=e.series??[],i=r.flatMap(m=>m.values.map(Tt)),l=n?Array.from({length:t},(m,g)=>r.reduce((v,y)=>v+Tt(y.values[g]??0),0)):[],d=Math.max(0,...i,...l),u=e.max!==void 0&&e.max>0?e.max:d>0?d:1,p=kh(u),h=p[p.length-1]??u;return{width:s,height:o,x0:52,x1:s-18,y0:18,y1:o-32,yMax:h,ticks:p}}function $h(e,t,n,s){let o="";e.ticks.forEach((l,d)=>{const u=Math.round(e.y1-(e.y1-e.y0)*l/e.yMax);o+=`<line x1="${e.x0}" y1="${u}" x2="${e.x1}" y2="${u}" stroke="${d===0?"var(--rule-solid)":"var(--rule)"}" stroke-width="1"${ut}/>`,o+=`<text x="${e.x0-8}" y="${u+3}" class="t-sub c-soft" text-anchor="end">${S(rt(l,n))}</text>`});const r=Math.max(t.length,1),i=(e.x1-e.x0)/r;return s&&(o+=`<g${he("labels")}>`),t.forEach((l,d)=>{const u=Math.round(e.x0+i*d+i/2);o+=`<text x="${u}" y="${e.y1+18}" class="t-sub" text-anchor="middle"${s?_(`labels.${d}`):""}>${S(l)}</text>`}),s&&(o+="</g>"),o}function b$(e){const t=e.map((n,s)=>({swatch:"fill",fill:Qi(s,e.length,n.accent),label:n.label,path:`series.${s}`}));return ot(t,"series")}function MA(e,t){const n=Xn(e.map(o=>o.accent)),s=e.map((o,r)=>({swatch:"fill",fill:sx(r,n[r]).fill,label:`${o.label} — ${rt(Tt(o.value),t)}`,path:`items.${r}`}));return ot(s,"items")}function aH(e,t,n,s){const o=wh(e,t.length),r=Math.max(t.length,1),i=(o.x1-o.x0)/r,l=Math.min(18,i*.18),d=4,u=Math.max(n.length,1),p=Math.max(6,Math.round((i-l*2-d*(u-1))/u));let h=`<g${he("series")}>`;return n.forEach((m,g)=>{const v=Qi(g,n.length,m.accent);h+=`<g${_(`series.${g}`)}>`;for(let y=0;y<t.length;y++){const b=Tt(m.values[y]??0),E=Math.min(b,o.yMax),$=Math.round((o.y1-o.y0)*E/o.yMax),A=Math.round(o.x0+i*y+l+g*(p+d)),T=o.y1-$;h+=`<g${_(`series.${g}.values.${y}`)}>`,h+=`<rect x="${A}" y="${T}" width="${p}" height="${Math.max($,1)}" fill="${v}"${$===0?' opacity="0.35"':""}/>`,h+=`<text x="${A+Math.round(p/2)}" y="${T-4}" class="t-arrow" text-anchor="middle">${S(rt(b,e.unit))}</text>`,h+="</g>"}h+="</g>"}),h+="</g>",Sh(o)+$h(o,t,e.unit,s)+h+"</svg>"}function lH(e,t,n,s,o){const r=wh(e,t.length),i=Math.max(t.length,1),l=(r.x1-r.x0)/i,d=h=>Math.round(r.x0+l*h+l/2),u=h=>Math.round(r.y1-(r.y1-r.y0)*Math.min(Tt(h),r.yMax)/r.yMax);let p=`<g${he("series")}>`;return n.forEach((h,m)=>{const g=Qi(m,n.length,h.accent),v=h.values.slice(0,t.length).map((y,b)=>`${d(b)},${u(y)}`);if(v.length!==0){if(p+=`<g${_(`series.${m}`)}>`,s&&v.length>1){const y=d(0),b=d(v.length-1);p+=`<polygon points="${y},${r.y1} ${v.join(" ")} ${b},${r.y1}" fill="${g}" fill-opacity="0.12" stroke="none"/>`}v.length>1&&(p+=`<polyline points="${v.join(" ")}" fill="none" stroke="${g}" stroke-width="1.75" stroke-linejoin="round"/>`),h.values.slice(0,t.length).forEach((y,b)=>{p+=`<circle cx="${d(b)}" cy="${u(y)}" r="3" fill="var(--paper)" stroke="${g}" stroke-width="1.75"/>`}),p+="</g>"}}),p+="</g>",Sh(r)+$h(r,t,e.unit,o)+p+"</svg>"}function cH(e,t,n=!1){const r=Math.round(240),i=Math.round(236/2),l=74,d=26,u=l+d/2,p=n?0:l-d/2,h=t.reduce((v,y)=>v+Tt(y.value),0);let m=oo(480,236);const g=`<circle cx="${r}" cy="${i}" r="${u}" fill="none" stroke="var(--rule-solid)" stroke-width="1"/>`+(n?"":`<circle cx="${r}" cy="${i}" r="${p}" fill="none" stroke="var(--rule-solid)" stroke-width="1"/>`);if(h<=0)m+=n?`<circle cx="${r}" cy="${i}" r="${u}" fill="var(--paper)"${ut}/>`+g:`<circle cx="${r}" cy="${i}" r="${l}" fill="none" stroke="var(--paper)" stroke-width="${d}"${ut}/>`+g;else{let v=-90;const y=Xn(t.map(A=>A.accent)),b=[],E=A=>{const T=A*Math.PI/180,N=Math.round((r+(n?0:p-1)*Math.cos(T))*10)/10,j=Math.round((i+(n?0:p-1)*Math.sin(T))*10)/10,P=Math.round((r+(u+1)*Math.cos(T))*10)/10,I=Math.round((i+(u+1)*Math.sin(T))*10)/10;b.push(`<line x1="${N}" y1="${j}" x2="${P}" y2="${I}" stroke="var(--paper-2)" stroke-width="2"${ut}/>`)},$=[];m+=`<g${he("items")}>`,t.forEach((A,T)=>{const N=Tt(A.value);if(N===0)return;const j=N/h*360,P=sx(T,y[T]).fill,I=`<title>${S(`${A.label} — ${rt(N,e.unit)} (${Math.round(N/h*1e3)/10}%)`)}</title>`;if(j>=359.999)m+=n?`<circle cx="${r}" cy="${i}" r="${u}" fill="${P}"${_(`items.${T}`)}>${I}</circle>`:`<circle cx="${r}" cy="${i}" r="${l}" fill="none" stroke="${P}" stroke-width="${d}"${_(`items.${T}`)}/>`;else if(n){const O=v*Math.PI/180,C=(v+j)*Math.PI/180,D=Math.round((r+u*Math.cos(O))*10)/10,F=Math.round((i+u*Math.sin(O))*10)/10,U=Math.round((r+u*Math.cos(C))*10)/10,X=Math.round((i+u*Math.sin(C))*10)/10,B=j>180?1:0;m+=`<path d="M ${r} ${i} L ${D} ${F} A ${u} ${u} 0 ${B} 1 ${U} ${X} Z" fill="${P}" stroke="none"${_(`items.${T}`)}>${I}</path>`,E(v)}else{const O=v*Math.PI/180,C=(v+j)*Math.PI/180,D=Math.round(r+l*Math.cos(O)),F=Math.round(i+l*Math.sin(O)),U=Math.round(r+l*Math.cos(C)),X=Math.round(i+l*Math.sin(C)),B=j>180?1:0;m+=`<path d="M ${D} ${F} A ${l} ${l} 0 ${B} 1 ${U} ${X}" fill="none" stroke="${P}" stroke-width="${d}" stroke-linecap="butt"${_(`items.${T}`)}/>`,E(v)}N/h>=.08&&$.push({mid:v+j/2,text:`${A.label} ${rt(N,e.unit)}`}),v+=j}),m+="</g>",m+=g,b.length>1&&(m+=b.join("")),m+=dH($,r,i,u)}return n||(m+=`<text x="${r}" y="${i+2}" class="chart-total">${S(rt(h,e.unit))}</text>`,m+=`<text x="${r}" y="${i+20}" class="t-eyebrow" text-anchor="middle">TOTAL</text>`),m+="</svg>",{svg:m,legend:MA(t,e.unit)}}function dH(e,t,n,s){const o=e.map(i=>{const l=i.mid*Math.PI/180,d=Math.cos(l)>=0;return{text:i.text,right:d,x0:t+(s+2)*Math.cos(l),y0:n+(s+2)*Math.sin(l),x1:t+(s+12)*Math.cos(l),y:n+(s+12)*Math.sin(l)}});for(const i of[!0,!1]){const l=o.filter(u=>u.right===i).sort((u,p)=>u.y-p.y);let d=-1/0;for(const u of l){const p=Math.max(u.y,d+12);u.y=p,d=p}}const r=i=>Math.round(i*10)/10;return o.map(i=>{const l=i.right?Math.max(i.x1,t+s+8):Math.min(i.x1,t-s-8);return`<line x1="${r(i.x0)}" y1="${r(i.y0)}" x2="${r(l)}" y2="${r(i.y)}" stroke="var(--muted)" stroke-width="0.75"/><text x="${r(l+(i.right?4:-4))}" y="${r(i.y+3.5)}" class="t-sub c-ink" text-anchor="${i.right?"start":"end"}">${S(i.text)}</text>`}).join("")}function uH(e,t,n,s){const o=wh(e,t.length,!0),r=Math.max(t.length,1),i=(o.x1-o.x0)/r,l=Math.max(10,Math.min(56,i*.55));let d=`<g${he("series")}>`;for(let u=0;u<t.length;u++){const p=Math.round(o.x0+i*u+(i-l)/2);let h=o.y1;n.forEach((g,v)=>{const y=Tt(g.values[u]??0);if(y===0)return;const b=Math.round((o.y1-o.y0)*y/o.yMax);h-=b,d+=`<rect x="${p}" y="${h}" width="${Math.round(l)}" height="${b}" fill="${Qi(v,n.length,g.accent)}" stroke="var(--paper-2)" stroke-width="1"${ut}${_(`series.${v}.values.${u}`)}><title>${S(`${g.label} — ${rt(y,e.unit)}`)}</title></rect>`});const m=n.reduce((g,v)=>g+Tt(v.values[u]??0),0);m>0&&(d+=`<text x="${p+Math.round(l/2)}" y="${h-5}" class="t-arrow" text-anchor="middle">${S(rt(m,e.unit))}</text>`)}return d+="</g>",Sh(o)+$h(o,t,e.unit,s)+d+"</svg>"}function pH(e,t,n,s){const o=wh(e,t.length),r=Math.max(t.length,1),i=(o.x1-o.x0)/r,l=p=>Math.round(o.x0+i*p+i/2),d=p=>Math.round(o.y1-(o.y1-o.y0)*Math.min(Tt(p),o.yMax)/o.yMax);let u=`<g${he("series")}>`;return n.forEach((p,h)=>{const m=Qi(h,n.length,p.accent);u+=`<g${_(`series.${h}`)}>`,p.values.slice(0,t.length).forEach((g,v)=>{u+=`<circle cx="${l(v)}" cy="${d(g)}" r="5" fill="${m}" fill-opacity="0.2" stroke="${m}" stroke-width="1.5"><title>${S(`${p.label} — ${rt(Tt(g),e.unit)}`)}</title></circle>`}),u+="</g>"}),u+="</g>",Sh(o)+$h(o,t,e.unit,s)+u+"</svg>"}var M0=40;function fH(e){return e.length>M0?`${e.slice(0,M0-1)}…`:e}function hH(e,t,n){if(e===void 0)return 5;const s=Math.max(e,0);if(n<=t)return 8;const o=(Math.sqrt(s)-Math.sqrt(t))/(Math.sqrt(n)-Math.sqrt(t));return Math.round((4+o*14)*10)/10}var mH=(e,t)=>e.x0<t.x1&&t.x0<e.x1&&e.y0<t.y1&&t.y0<e.y1;function gH(e,t){const n=Math.max(t.x0,Math.min(e.px,t.x1)),s=Math.max(t.y0,Math.min(e.py,t.y1)),o=e.px-n,r=e.py-s;return o*o+r*r<e.r*e.r}function vH(e){return e==="negative"?"var(--negative)":e==="focal"?"var(--accent)":"var(--ink)"}function yH(e,t){const n=e.guides,s=560,o=320,r=e.yLabel!==void 0?70:56,i=s-20,l=18,d=o-(e.xLabel!==void 0?48:34),u=t.map(C=>C.x),p=t.map(C=>C.y);n?.x!==void 0&&u.push(n.x),n?.y!==void 0&&p.push(n.y);const h=w0(u),m=w0(p),g=C=>Math.round((r+(i-r)*(C-h.min)/(h.max-h.min))*10)/10,v=C=>Math.round((d-(d-l)*(C-m.min)/(m.max-m.min))*10)/10,y=t.filter(C=>C.size!==void 0).map(C=>Math.max(C.size??0,0)),b=y.length>0?Math.min(...y):0,E=y.length>0?Math.max(...y):0;let $=oo(s,o);for(const C of m.ticks){const D=v(C);$+=`<line x1="${r}" y1="${D}" x2="${i}" y2="${D}" stroke="${C===m.min?"var(--rule-solid)":"var(--rule)"}" stroke-width="1"${ut}/>`,$+=`<text x="${r-8}" y="${D+3}" class="t-sub c-soft" text-anchor="end">${S(rt(C,e.unit))}</text>`}for(const C of h.ticks){const D=g(C);$+=`<line x1="${D}" y1="${l}" x2="${D}" y2="${d}" stroke="${C===h.min?"var(--rule-solid)":"var(--rule)"}" stroke-width="1"${ut}/>`,$+=`<text x="${D}" y="${d+16}" class="t-sub c-soft" text-anchor="middle">${S(rt(C,void 0))}</text>`}if(e.xLabel!==void 0&&($+=`<text x="${Math.round((r+i)/2)}" y="${o-8}" class="t-eyebrow" text-anchor="middle"${_("xLabel")}>${S(e.xLabel)}</text>`),e.yLabel!==void 0){const C=Math.round((l+d)/2);$+=`<text x="14" y="${C}" class="t-eyebrow" text-anchor="middle" transform="rotate(-90 14 ${C})"${_("yLabel")}>${S(e.yLabel)}</text>`}if(n!==void 0){if(n.x!==void 0){const C=g(n.x);$+=`<line x1="${C}" y1="${l}" x2="${C}" y2="${d}" stroke="var(--muted)" stroke-width="1" stroke-dasharray="5 4"${_("guides.x")}/>`}if(n.y!==void 0){const C=v(n.y);$+=`<line x1="${r}" y1="${C}" x2="${i}" y2="${C}" stroke="var(--muted)" stroke-width="1" stroke-dasharray="5 4"${_("guides.y")}/>`}if(n.quadrants!==void 0&&n.quadrants.length===4){const[C,D,F,U]=n.quadrants,X=(B,te,ee,H,W)=>B===void 0||B===""?"":`<text x="${te}" y="${ee}" class="t-eyebrow" text-anchor="${H}"${_(`guides.quadrants.${W}`)}>${S(B)}</text>`;$+=X(C,r+8,l+12,"start",0),$+=X(D,i-8,l+12,"end",1),$+=X(F,r+8,d-8,"start",2),$+=X(U,i-8,d-8,"end",3)}}const A=t.map(C=>({px:g(C.x),py:v(C.y),r:hH(C.size,b,E)})),T=Xn(t.map(C=>C.accent));let N=`<g${he("points")}>`;t.forEach((C,D)=>{const F=A[D];if(F===void 0)return;const U=vH(T[D]),X=`${C.label!==void 0?`${C.label} — `:""}${rt(C.x,void 0)}, ${rt(C.y,e.unit)}${C.size!==void 0?` (${rt(C.size,void 0)})`:""}`;N+=`<circle cx="${F.px}" cy="${F.py}" r="${F.r}" fill="${U}" fill-opacity="0.18" stroke="${U}" stroke-width="1.5"${_(`points.${D}`)}><title>${S(X)}</title></circle>`}),N+="</g>";const j=[];let P="",I="";t.forEach((C,D)=>{const F=A[D];if(F===void 0||C.label===void 0||C.label==="")return;const U=fH(C.label),X=U.length*6,{px:B,py:te,r:ee}=F;let H=ee;for(const ne of A){const Z=Math.sqrt((ne.px-B)*(ne.px-B)+(ne.py-te)*(ne.py-te));Z<ne.r&&ne.r+Z>H&&(H=ne.r+Z)}const W=[{anchor:"start",lx:B+H+5,ly:te+3},{anchor:"end",lx:B-H-5,ly:te+3},{anchor:"middle",lx:B,ly:te-H-7},{anchor:"middle",lx:B,ly:te+H+12}],K=ne=>({x0:ne.anchor==="start"?ne.lx:ne.anchor==="end"?ne.lx-X:ne.lx-X/2,x1:ne.anchor==="start"?ne.lx+X:ne.anchor==="end"?ne.lx:ne.lx+X/2,y0:ne.ly-9,y1:ne.ly+2}),R=ne=>ne.x0>=2&&ne.x1<=s-2&&ne.y0>=2&&ne.y1<=o-2&&!A.some(Z=>gH(Z,ne))&&!j.some(Z=>mH(Z,ne)),z=W.find(ne=>R(K(ne)));if(z===void 0)return;const Y=K(z);j.push(Y);const V=z.lx-(B+ee+5),re=z.ly-(te+3);if(Math.sqrt(V*V+re*re)>14){const ne=Math.max(Y.x0,Math.min(B,Y.x1)),Z=Math.max(Y.y0,Math.min(te,Y.y1)),q=Math.sqrt((B-ne)*(B-ne)+(te-Z)*(te-Z));if(q>ee+2){const de=B-(B-ne)/q*(ee+1.5),le=te-(te-Z)/q*(ee+1.5);P+=`<line x1="${Math.round(ne*10)/10}" y1="${Math.round(Z*10)/10}" x2="${Math.round(de*10)/10}" y2="${Math.round(le*10)/10}" stroke="var(--muted)" stroke-width="0.75"/>`}}const Q=C.label.length>M0?`<title>${S(C.label)}</title>`:"";I+=`<text x="${Math.round(z.lx*10)/10}" y="${Math.round(z.ly*10)/10}" class="t-sub c-ink" style="text-anchor:${z.anchor}"${_(`points.${D}.label`)}>${S(U)}${Q}</text>`}),$+=P+N+I+"</svg>";const O=[];return T.some(C=>C===void 0)&&O.push({swatch:"fill",fill:"var(--ink)",label:"point"}),T.some(C=>C==="focal")&&O.push({swatch:"fill",fill:"var(--accent)",label:"focal"}),T.some(C=>C==="negative")&&O.push({swatch:"fill",fill:"var(--negative)",label:"negative"}),(n?.x!==void 0||n?.y!==void 0)&&O.push({swatch:"edge-dashed",label:"guide"}),{svg:$,legend:ot(O)}}function xH(e,t){const s=t.length<=1,o=s?246:264,r=Math.round(420/2),i=s?150:158,l=e.max!==void 0&&e.max>0?e.max:100,d=135,u=270,p=s?92:96,h=s?26:16,m=7,g=(j,P)=>{const I=P*Math.PI/180;return`${Math.round((r+j*Math.cos(I))*10)/10} ${Math.round((i+j*Math.sin(I))*10)/10}`},v=(j,P)=>{const I=u*Math.min(Math.max(P,0),1);if(I<=0)return"";const O=I>180?1:0;return`M ${g(j,d)} A ${j} ${j} 0 ${O} 1 ${g(j,d+I)}`};let y=oo(420,o);const b=Xn(t.map(j=>j.accent));y+=`<g${he("items")}>`,t.forEach((j,P)=>{const I=p-P*(h+m);if(I<=h)return;const O=sx(P,b[P]).fill,C=Tt(j.value)/l;y+=`<g${_(`items.${P}`)}>`,y+=`<path d="${v(I,1)}" fill="none" stroke="var(--paper)" stroke-width="${h}" stroke-linecap="round"${ut}/>`;const D=v(I,C);D!==""&&(y+=`<path d="${D}" fill="none" stroke="${O}" stroke-width="${h}" stroke-linecap="round"/>`),y+="</g>"}),y+="</g>";const E=t[0];if(E!==void 0){y+=`<text x="${r}" y="${i+(s?6:2)}" class="chart-total">${S(rt(Tt(E.value),e.unit))}</text>`;const j=s?E.desc??E.label:"OF "+rt(l,e.unit);y+=`<text x="${r}" y="${i+(s?26:20)}" class="t-eyebrow" text-anchor="middle">${S(j.toUpperCase())}</text>`}const $=p+h/2+13,A=Math.round($*Math.cos(135*Math.PI/180)),T=Math.round(i+$*Math.sin(135*Math.PI/180));y+=`<text x="${r+A}" y="${T}" class="t-sub c-soft" text-anchor="middle">0</text>`,y+=`<text x="${r-A}" y="${T}" class="t-sub c-soft" text-anchor="middle">${S(rt(l,e.unit))}</text>`,y+="</svg>";const N=t.length>1||t[0]?.desc!==void 0&&!s?MA(t,e.unit):"";return{svg:y,legend:N}}function kH(e,t,n){const r=Math.round(210),i=Math.round(280/2),l=100,d=t.length;if(d<3)return oo(420,60)+"</svg>";const u=n.flatMap(E=>E.values.slice(0,d).map(Tt)),p=u.length>0?Math.max(...u):0,h=e.max!==void 0&&e.max>0?e.max:p>0?p:1,m=kh(h),g=m[m.length-1]??h,v=E=>-Math.PI/2+2*Math.PI*E/d,y=(E,$)=>{const A=v(E);return[Math.round(r+$*Math.cos(A)),Math.round(i+$*Math.sin(A))]};let b=oo(420,280);m.forEach((E,$)=>{if($===0)return;const A=Array.from({length:d},(T,N)=>y(N,l*E/g).join(","));b+=`<polygon points="${A.join(" ")}" fill="none" stroke="${$===m.length-1?"var(--rule-solid)":"var(--rule)"}" stroke-width="1"${ut}/>`});for(let E=0;E<d;E++){const[$,A]=y(E,l);b+=`<line x1="${r}" y1="${i}" x2="${$}" y2="${A}" stroke="var(--rule)" stroke-width="1"${ut}/>`}return b+=`<g${he("labels")}>`,t.forEach((E,$)=>{const A=v($),[T,N]=y($,l+14),j=Math.cos(A),P=j>.3?"start":j<-.3?"end":"middle";b+=`<text x="${T}" y="${N+3}" class="t-sub" text-anchor="${P}"${_(`labels.${$}`)}>${S(E)}</text>`}),b+="</g>",b+=`<g${he("series")}>`,n.forEach((E,$)=>{const A=Qi($,n.length,E.accent),T=Array.from({length:d},(N,j)=>{const P=Math.min(Tt(E.values[j]??0),g);return y(j,l*P/g)});b+=`<g${_(`series.${$}`)}>`,b+=`<polygon points="${T.map(N=>N.join(",")).join(" ")}" fill="${A}" fill-opacity="0.1" stroke="${A}" stroke-width="1.75" stroke-linejoin="round"/>`,T.forEach(([N,j])=>{b+=`<circle cx="${N}" cy="${j}" r="2.5" fill="var(--paper)" stroke="${A}" stroke-width="1.5"/>`}),b+="</g>"}),b+="</g>",b+"</svg>"}function Sh(e){return oo(e.width,e.height)}var Yu=720,bH=150,fi=34,Xu=14;function hi(e,t){return`${(Math.round(e*100)/100).toLocaleString("en-US")} ${t??"ms"}`}var Qg=23;function wH(e){const t=e.desc!==void 0&&e.desc.length>0?`${e.label} — ${e.desc}`:e.label;return t.length<=Qg?t:e.label.length<=Qg?e.label:`${e.label.slice(0,Qg-1)}…`}function $H(e){const t=e.items??[],n=e.unit,s=t.reduce((j,P)=>j+Tt(P.value),0),o=e.budget!==void 0&&e.budget>0?e.budget:void 0,r=o!==void 0,i=r?22:6,l=t.length+(t.length>0?1:0),d=i+l*(fi+Xu)-(l>0?Xu:0)+6,u=bH+10,p=r?176:74,h=Yu-u-p,m=r&&s>0&&o<=s*1.4,g=m?Math.max(s,o):s>0?s:o??0,v=j=>g>0?Math.round(h*j/g):0;let y=`<svg viewBox="0 0 ${Yu} ${Math.max(d,40)}" role="img"><title>Budget waterfall</title>`,b=0,E=!1;const $=Xn(t.map(j=>j.accent)),A=$.includes("focal");if(y+=`<g${he("items")}>`,t.forEach((j,P)=>{const I=Tt(j.value),O=i+P*(fi+Xu),C=u+v(b),D=Math.max(v(I),I>0?2:0),F=nx(P,$[P]);if(y+=`<g${_(`items.${P}`)}>`,y+=`<text x="0" y="${O+22}" class="t-name"${_(`items.${P}.label`)}>${S(wH(j))}</text>`,y+=`<rect x="${C}" y="${O}" width="${D}" height="${fi}" fill="${F.fill}" stroke="${F.stroke}" stroke-width="1"/>`,r&&b+I>o){E=!0;const U=Math.max(b,o),X=u+v(U),B=Math.max(v(b+I)-v(U),2);y+=`<rect x="${X}" y="${O}" width="${B}" height="${fi}" fill="var(--negative)"/>`}y+=`<text x="${C+D+6}" y="${O+22}" class="t-sub c-muted"${_(`items.${P}.value`)}>${S(hi(I,n))}</text>`,y+="</g>",b+=I}),y+="</g>",t.length>0){const j=i+t.length*(fi+Xu),P=Math.max(v(s),s>0?2:0);if(y+=`<rect x="${u}" y="${j}" width="${P}" height="${fi}" fill="var(--ink)"/>`,y+=`<text x="${u+10}" y="${j+21}" class="t-eyebrow"${E0}>TOTAL</text>`,y+=`<text x="${u+P+6}" y="${j+22}" class="t-sub c-ink">${S(hi(s,n))}</text>`,r){const I=Math.round((s-o)*100)/100,O=I>0,C=I===0?"on budget":O?`${hi(I,n)} over`:`${hi(-I,n)} under`,D=20+C.length*6,F=u+P+6+Math.round(hi(s,n).length*6.2)+8,U=O?"var(--negative)":"var(--rule-solid)",X=O?" c-negative":" c-muted";y+=`<rect x="${F}" y="${j+4}" width="${D}" height="${fi-8}" rx="2" fill="var(--paper)" stroke="${U}" stroke-width="1"/>`,y+=`<text x="${F+Math.round(D/2)}" y="${j+21}" class="t-arrow${X}" text-anchor="middle">${S(C)}</text>`}}if(r&&m){const j=u+v(o);y+=`<line x1="${j}" y1="${i-6}" x2="${j}" y2="${Math.max(d,40)-4}" stroke="var(--negative)" stroke-width="1.25" stroke-dasharray="5 4"/>`;const P=j>Yu-130;y+=`<text x="${P?j-6:j+6}" y="${i-8}" class="t-arrow c-negative"${P?' text-anchor="end"':""}${_("budget")}>budget: ${S(hi(o,n))}</text>`}else r&&(y+=`<text x="${Yu-4}" y="${i-8}" class="t-arrow c-negative" text-anchor="end"${_("budget")}>budget: ${S(hi(o,n))} — beyond scale →</text>`);y+="</svg>";const T=[];t.length>0&&T.push({swatch:"fill",fill:"var(--ink)",label:"step (darker first) · total"}),A&&T.push({swatch:"fill",fill:"var(--accent)",label:"focal step"}),r&&T.push({swatch:"edge-dashed",label:"budget cap"}),E&&T.push({swatch:"fill",fill:"var(--negative)",label:"over budget"});const N=ot(T);return ct({tag:"BUDGET",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...N.length>0?{legendHtml:N}:{}},y)}var Eh=560,Wc=54,dc=10,A0=18,SH=.28;function EH(e,t){return`${(Math.round(e*100)/100).toLocaleString("en-US")}${t!==void 0?` ${t}`:""}`}function w$(e,t){const n=t>0?Tt(e)/t:0;return Math.round(Eh*Math.max(n,SH))}function MH(e,t,n,s,o,r,i,l){const d=Eh/2,u=w$(e.value,o),p=t!==void 0?w$(t.value,o):u,h=nx(n,s),m=[`${d-u/2},${r}`,`${d+u/2},${r}`,`${d+p/2},${r+Wc}`,`${d-p/2},${r+Wc}`].join(" "),g=e.desc!==void 0&&e.desc.length>0,v=g?r+20:r+24,y=g?r+35:r+40,b=h.dark?` class="t-name"${E0}`:' class="t-name"',E=h.dark?` class="t-sub"${E0}`:' class="t-sub c-muted"',$=g?`<text x="${d}" y="${r+47}"${E} text-anchor="middle"${_(`${l}.${n}.desc`)}>${S(e.desc??"")}</text>`:"";return`<g${_(`${l}.${n}`)}><polygon points="${m}" fill="${h.fill}" stroke="${h.stroke}" stroke-width="1"/><text x="${d}" y="${v}"${b} text-anchor="middle"${_(`${l}.${n}.label`)}>${S(e.label)}</text><text x="${d}" y="${y}"${E} text-anchor="middle"${_(`${l}.${n}.value`)}>${S(EH(Tt(e.value),i))}</text>`+$+"</g>"}function AH(e,t,n){const s=Eh/2,o=Tt(e.value),r=Tt(t.value),i=o>0?Math.round(r/o*100):0,l=`↓ ${i}%`,d=34+String(i).length*7;return`<rect x="${s-d/2}" y="${n}" width="${d}" height="${A0}" rx="2" fill="var(--paper)" stroke="var(--rule-solid)" stroke-width="1"/><text x="${s}" y="${n+13}" class="t-arrow" text-anchor="middle">${S(l)}</text>`}function CH(e){const t=e.items!==void 0?"items":"stages",n=e.items??e.stages??[],s=Math.max(...n.map(p=>Tt(p.value)),0),o=Wc+dc+A0+dc,r=Math.max(n.length*Wc+(n.length-1)*(dc+A0+dc),0);let i=`<svg viewBox="0 0 ${Eh} ${r}" role="img"><title>Funnel</title>`;const l=Xn(n.map(p=>p.accent));i+=`<g${he(t)}>`,n.forEach((p,h)=>{const m=h*o;i+=MH(p,n[h+1],h,l[h],s,m,e.unit,t);const g=n[h+1];g!==void 0&&(i+=AH(p,g,m+Wc+dc))}),i+="</g>",i+="</svg>";const d=[];n.length>1&&d.push({swatch:"fill",fill:"var(--ink)",label:"stage (darker first)"}),l.includes("focal")&&d.push({swatch:"fill",fill:"var(--accent)",label:"focal stage"}),l.includes("negative")&&d.push({swatch:"fill",fill:"var(--negative)",label:"negative"}),n.length>1&&d.push({swatch:"chip",chip:"↓ %",label:"conversion from the stage above"});const u=ot(d);return ct({tag:"FUNNEL",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...u.length>0?{legendHtml:u}:{}},i)}function NH(e){const t=e.kind??"bar";if(t==="waterfall")return $H(e);if(t==="funnel")return CH(e);const n=e.labels??[],s=e.series??[];let o;if(t==="donut"||t==="pie")o=cH(e,e.items??[],t==="pie");else if(t==="histogram")o=Jq(e);else if(t==="bell")o=nH(e);else if(t==="boxplot")o=sH(e);else if(t==="pareto")o=oH(e);else if(t==="bullet")o=iH(e);else if(t==="gauge")o=xH(e,e.items??[]);else if(t==="scatter"&&e.points!==void 0&&e.points.length>0)o=yH(e,e.points);else if(t==="radar")o={svg:kH(e,n,s),legend:b$(s)};else{const r=Math.max(n.length,...s.map(u=>u.values.length),0),i=n.length>0?n:Array.from({length:r},(u,p)=>String(p+1)),l=n.length>0;o={svg:t==="bar"?aH(e,i,s,l):t==="stacked"?uH(e,i,s,l):t==="scatter"?pH(e,i,s,l):lH(e,i,s,t==="area",l),legend:b$(s)}}return ct({tag:"CHART",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...o.legend.length>0?{legendHtml:o.legend}:{}},o.svg)}function TH(e){const t=e.width!==void 0&&Number.isFinite(e.width)&&e.width>0?` style="max-width:${Math.round(e.width)}px"`:"",n=e.alt??e.caption??"",s=e.caption!==void 0?`<figcaption class="fig-cap"${_("caption")}>${S(e.caption)}</figcaption>`:"";return`<figure class="fig"><img class="fig-img" src="${S(yf(e.src))}" alt="${S(n)}"${t}>`+s+"</figure>"}function _H(e,t){const n=e.body!==void 0?`<p class="stp-text"${_(`items.${t}.body`)}>${S(e.body)}</p>`:"",s=e.lang!==void 0?`<div class="stp-code-head">${S(e.lang)}</div>`:"",o=e.code!==void 0?`<div class="stp-code">${s}<pre><code>${fh(e.code,e.lang)}</code></pre></div>`:"",r=e.note!==void 0?`<p class="stp-note"${_(`items.${t}.note`)}>${S(e.note)}</p>`:"";return`<li class="stp-item"${_(`items.${t}`)}${hn(t)}><span class="stp-num" aria-hidden="true">${t+1}</span><div class="stp-body"><div class="stp-title"${_(`items.${t}.title`)}>${S(e.title)}</div>`+n+o+r+"</div></li>"}function LH(e){const t=e.title!==void 0?`<div class="stp-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="stp-desc">${S(e.description)}</p>`:"",s=e.items.map((o,r)=>_H(o,r)).join("");return`<div class="steps">${t}${n}<ol class="stp-list"${he("items")}>${s}</ol></div>`}function IH(e){const t=e.split(/\n{2,}/).map(n=>n.trim()).filter(n=>n.length>0);return t.length===0?"":t.map(n=>`<p>${S(n)}</p>`).join("")}function jH(e,t){return`<details class="fq-item"${e.open===!0?" open":""}${_(`items.${t}`)}><summary class="fq-summary"><span class="fq-caret" aria-hidden="true"></span><span class="fq-q"${_(`items.${t}.q`)}>${S(e.q)}</span></summary><div class="fq-a"${_(`items.${t}.a`)}>${IH(e.a)}</div></details>`}function PH(e){const t=e.title!==void 0?`<div class="fq-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="fq-desc">${S(e.description)}</p>`:"",s=e.items.map((o,r)=>jH(o,r)).join("");return`<div class="faq">${t}${n}<div class="fq-list"${he("items")}>${s}</div></div>`}function OH(e,t){return`<div class="env-given"${_(`assumptions.${t}`)}><div class="env-g-label"${_(`assumptions.${t}.label`)}>${S(e.label)}</div><div class="env-g-value"${_(`assumptions.${t}.value`)}>${S(e.value)}</div></div>`}function RH(e,t){return`<div class="env-step"${_(`steps.${t}`)}><span class="env-s-label"${_(`steps.${t}.label`)}>${S(e.label)}</span><span class="env-s-calc"${_(`steps.${t}.calc`)}>${S(e.calc)}</span><span class="env-s-arrow" aria-hidden="true">→</span><span class="env-s-result"${_(`steps.${t}.result`)}>${S(e.result)}</span></div>`}function DH(e){const t=e.title!==void 0?`<div class="env-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="env-desc">${S(e.description)}</p>`:"",s=e.assumptions.map((i,l)=>OH(i,l)).join(""),o=e.steps.map((i,l)=>RH(i,l)).join(""),r=e.result!==void 0?`<div class="env-result"${_("result")}><div class="env-r-label"${_("result.label")}>${S(e.result.label)}</div><div class="env-r-value"${_("result.value")}>${S(e.result.value)}</div></div>`:"";return'<div class="envelope">'+t+n+`<div class="env-card"><div class="env-givens"${he("assumptions")}>${s}</div><div class="env-steps"${he("steps")}>${o}</div>`+r+"</div></div>"}function BH(e){return e>.8?"slo-b-hot":e>=.5?"slo-b-warn":"slo-b-ok"}function zH(e){const t=Math.min(e,1),n=Math.round(t*1e3)/10,s=e>=1?"error budget exhausted":`${Math.round(t*100)}% of error budget used`;return`<div class="slo-budget"><div class="slo-track"><div class="slo-fill ${BH(e)}" style="width:${n}%"></div></div><div class="slo-caption">${S(s)}</div></div>`}function FH(e,t){const n=e.window!==void 0?`<span class="slo-window">${S(e.window)}</span>`:"",s=e.budget!==void 0&&e.budget>=1,o=e.current!==void 0?`<div class="slo-val"><span class="slo-v-label">Current</span><span class="slo-v-num ${s?"slo-bad":"slo-ok"}">${S(e.current)}</span></div>`:"",r=e.budget!==void 0?zH(e.budget):"";return`<div class="slo-item"${_(`items.${t}`)}><div class="slo-top"><span class="slo-name"${_(`items.${t}.name`)}>${S(e.name)}</span>`+n+`</div><p class="slo-sli"${_(`items.${t}.sli`)}>${S(e.sli)}</p><div class="slo-vals"><div class="slo-val"><span class="slo-v-label">Target</span><span class="slo-v-num"${_(`items.${t}.target`)}>${S(e.target)}</span></div>`+o+"</div>"+r+"</div>"}function qH(e){const t=e.title!==void 0?`<div class="slo-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="slo-desc">${S(e.description)}</p>`:"",s=e.items.map((o,r)=>FH(o,r)).join("");return`<div class="slo">${t}${n}<div class="slo-list"${he("items")}>${s}</div></div>`}function HH(e){const t=e.items.map((s,o)=>`<li class="swot-item"${_(`${e.path}.${o}`)}>${S(s)}</li>`).join(""),n=t!==""?`<ul class="swot-list">${t}</ul>`:"";return`<div class="swot-quad swot-${e.key}"${he(e.path)}><div class="swot-label">${S(e.label)}</div>`+n+"</div>"}function WH(e){const t=e.title!==void 0?`<div class="swot-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="swot-desc">${S(e.description)}</p>`:"",o=[{key:"s",path:"strengths",label:"Strengths",items:e.strengths??[]},{key:"w",path:"weaknesses",label:"Weaknesses",items:e.weaknesses??[]},{key:"o",path:"opportunities",label:"Opportunities",items:e.opportunities??[]},{key:"t",path:"threats",label:"Threats",items:e.threats??[]}].map(HH).join("");return`<div class="swot">${t}${n}<div class="swot-grid">${o}</div></div>`}function UH(e){return e==="done"||e==="on-track"?"okr-b-ok":e==="at-risk"?"okr-b-warn":e==="off-track"?"okr-b-bad":"okr-b-plain"}function KH(e,t){const n=Math.min(Math.max(e.progress,0),1),s=Math.round(n*1e3)/10,o=`${Math.round(n*100)}%`;return`<div class="okr-kr"${_(t)}><div class="okr-kr-text"${_(`${t}.kr`)}>${S(e.kr)}</div><div class="okr-kr-bar"><div class="okr-track"><div class="okr-fill ${UH(e.status)}" style="width:${s}%"></div></div><span class="okr-pct"${_(`${t}.progress`)}>${S(o)}</span>`+(e.status!==void 0?`<span class="okr-status okr-s-${e.status}"${_(`${t}.status`)}>${S(e.status)}</span>`:"")+"</div></div>"}function VH(e,t){const n=e.owner!==void 0?`<span class="okr-owner"${_(`items.${t}.owner`)}>${S(e.owner)}</span>`:"",s=e.krs.map((o,r)=>KH(o,`items.${t}.krs.${r}`)).join("");return`<div class="okr-item"${_(`items.${t}`)}><div class="okr-top"><span class="okr-objective"${_(`items.${t}.objective`)}>${S(e.objective)}</span>`+n+`</div><div class="okr-krs"${he(`items.${t}.krs`)}>${s}</div></div>`}function GH(e){const t=e.title!==void 0?`<div class="okr-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="okr-desc">${S(e.description)}</p>`:"",s=e.items.map((o,r)=>VH(o,r)).join("");return`<div class="okr">${t}${n}<div class="okr-list"${he("items")}>${s}</div></div>`}function AA(e){const t=e.trim().split(/\s+/).filter(o=>o.length>0),n=t[0]?.charAt(0)??"",s=t.length>1?t[t.length-1]?.charAt(0)??"":t[0]?.charAt(1)??"";return`${n}${s}`.toUpperCase()}function $$(e,t,n,s){if(s===void 0||s.length===0)return"";const o=s.map((r,i)=>`<li class="pa-li"${_(`${n}.${i}`)}>${S(r)}</li>`).join("");return`<div class="pa-section ${t}"><div class="pa-sec-label">${S(e)}</div><ul class="pa-list"${he(n)}>${o}</ul></div>`}function YH(e,t){if(t===void 0||t.length===0)return"";const n=t.map((s,o)=>`<span class="pa-tool"${_(`${e}.${o}`)}>${S(s)}</span>`).join("");return`<div class="pa-section"><div class="pa-sec-label">Tools</div><div class="pa-tools"${he(e)}>${n}</div></div>`}function XH(e,t){const n=e.accent!==void 0?` pa-${e.accent}`:"",s=e.role!==void 0?`<div class="pa-role"${_(`personas.${t}.role`)}>${S(e.role)}</div>`:"",o=e.quote!==void 0?`<blockquote class="pa-quote"${_(`personas.${t}.quote`)}>${S(e.quote)}</blockquote>`:"";return`<div class="pa-card${n}"${_(`personas.${t}`)}><div class="pa-id"><span class="pa-avatar">${S(AA(e.name))}</span><div class="pa-who"><div class="pa-name"${_(`personas.${t}.name`)}>${S(e.name)}</div>`+s+"</div></div>"+o+$$("Goals","pa-goals",`personas.${t}.goals`,e.goals)+$$("Frustrations","pa-frustrations",`personas.${t}.frustrations`,e.frustrations)+YH(`personas.${t}.tools`,e.tools)+"</div>"}function QH(e){const t=e.title!==void 0?`<div class="pa-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="pa-desc">${S(e.description)}</p>`:"",s=e.personas.map((o,r)=>XH(o,r)).join("");return`<div class="persona">${t}${n}<div class="pa-grid"${he("personas")}>${s}</div></div>`}function ZH(e,t){const n=e.type!==void 0?`<span class="cg-type cg-t-${e.type}"${_(`${t}.type`)}>${S(e.type)}</span>`:"";return`<div class="cg-item"${_(t)}>`+n+`<span class="cg-text"${_(`${t}.text`)}>${S(e.text)}</span></div>`}function JH(e,t){const n=e.tag==="breaking",s=e.date!==void 0?`<span class="cg-date"${_(`releases.${t}.date`)}>${S(e.date)}</span>`:"",o=e.tag!==void 0?`<span class="cg-tag cg-tag-${e.tag}"${_(`releases.${t}.tag`)}>${S(e.tag)}</span>`:"",r=e.items.map((i,l)=>ZH(i,`releases.${t}.items.${l}`)).join("");return`<div class="cg-release"${_(`releases.${t}`)}><span class="cg-dot${n?" cg-dot-breaking":""}"></span><div class="cg-rel-head"><span class="cg-version${n?" cg-v-breaking":""}"${_(`releases.${t}.version`)}>${S(e.version)}</span>`+s+o+`</div><div class="cg-items"${he(`releases.${t}.items`)}>${r}</div></div>`}function eW(e){const t=e.title!==void 0?`<div class="cg-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="cg-desc">${S(e.description)}</p>`:"",s=e.releases.map((o,r)=>JH(o,r)).join("");return`<div class="changelog">${t}${n}<div class="cg-rail"${he("releases")}>${s}</div></div>`}function tW(e,t){const n=e.accent!==void 0?` tem-${e.accent}`:"",s=e.initials!==void 0&&e.initials.length>0?e.initials:AA(e.name),o=e.role!==void 0?`<div class="tem-role"${_(`members.${t}.role`)}>${S(e.role)}</div>`:"",r=e.focus!==void 0?`<div class="tem-focus"${_(`members.${t}.focus`)}>${S(e.focus)}</div>`:"";return`<div class="tem-card${n}"${_(`members.${t}`)}><span class="tem-avatar">${S(s)}</span><div class="tem-name"${_(`members.${t}.name`)}>${S(e.name)}</div>`+o+r+"</div>"}function nW(e){const t=e.title!==void 0?`<div class="tem-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="tem-desc">${S(e.description)}</p>`:"",s=e.members.map((o,r)=>tW(o,r)).join("");return`<div class="team">${t}${n}<div class="tem-grid"${he("members")}>${s}</div></div>`}var jr=["var(--paper-2)","var(--ink-3)","var(--ink-2)","var(--ink)"],sW=2,Zg="box-shadow:inset 0 0 0 1px var(--rule-solid)";function oW(e){return Math.min(jr.length-1,Math.max(0,Math.floor(e*jr.length)))}function Qu(e){return String(Math.round(e*100)/100)}function rW(e){const t=e.xLabels,n=e.rows,s=n.flatMap(E=>E.values.slice(0,t.length)).filter(E=>Number.isFinite(E)),o=s.length>0?Math.min(...s):0,r=s.length>0?Math.max(...s):1,i=e.min??o,l=e.max??r,d=l-i,u=E=>d<=0?.5:Math.min(1,Math.max(0,(E-i)/d)),p=new Set;let h=!1,m='<div class="hm-corner"></div>';m+=t.map((E,$)=>`<div class="hm-col t-eyebrow"${_(`xLabels.${$}`)}>${S(E)}</div>`).join(""),n.forEach((E,$)=>{m+=`<div class="hm-rowlabel t-name"${_(`rows.${$}.label`)}>${S(E.label)}</div>`;for(let A=0;A<t.length;A++){const T=E.values[A];if(T===void 0||!Number.isFinite(T)){m+=`<div class="hm-cell hm-blank" style="background:var(--paper);${Zg}"></div>`;continue}const N=e.unit!==void 0?` title="${S(`${Qu(T)} ${e.unit}`)}"`:"";if(T===0){h=!0,m+=`<div class="hm-cell" style="background:var(--paper);color:var(--ink);${Zg}"${N}${_(`rows.${$}.values.${A}`)}>0</div>`;continue}const j=oW(u(T));p.add(j);const P=j>=sW?"var(--paper)":"var(--ink)";m+=`<div class="hm-cell" style="background:${jr[j]};color:${P};${Zg}"${N}${_(`rows.${$}.values.${A}`)}>${S(Qu(T))}</div>`}});const g=e.unit!==void 0?` ${e.unit}`:"",v=[...p].sort((E,$)=>E-$).map(E=>{const $=i+d*E/jr.length,A=E===jr.length-1?l:i+d*(E+1)/jr.length,T=j=>d>=20?String(Math.round(j)):Qu(j),N=d<=0?`${Qu(i)}${g}`:`${T($)}–${T(A)}${g}`;return{swatch:"fill",fill:jr[E]??jr[0],label:N}});h&&v.unshift({swatch:"fill",fill:"var(--paper)",label:`0${g}`});const y=ot(v),b=`<div class="heatmap" style="overflow-x:auto"><div class="hm-grid" style="grid-template-columns:auto repeat(${t.length},minmax(44px,1fr))"${he("rows")}>${m}</div></div>`;return ct({tag:"HEATMAP",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...y.length>0?{legendHtml:y}:{}},b)}function iW(e){const t=Math.round(e*10)/10;return Number.isInteger(t)?String(t):t.toFixed(1)}function aW(e){const t=e.criteria,n=e.options,s=n.map(g=>t.reduce((v,y,b)=>v+(g.scores[b]??0)*(y.weight??1),0)),o=s.length>0?Math.max(...s):0,r=g=>s[g]===o,i=n.map((g,v)=>{const y=r(v),b=y?'<span class="sc-winner">WINNER</span>':"",E=g.note!==void 0?`<span class="sc-note"${_(`options.${v}.note`)}>${S(g.note)}</span>`:"";return`<th class="c${y?" sc-win":""}"${_(`options.${v}`)}>${S(g.label)}${b}${E}</th>`}).join(""),l=`<tr${he("options")}><th>Criteria</th>${i}</tr>`,d=t.map((g,v)=>{const y=g.weight??1,b=y!==1?`<span class="sc-weight"${_(`criteria.${v}.weight`)}>×${S(String(y))}</span>`:"",E=n.map(($,A)=>{const T=$.scores[v];return`<td class="c sc-score"${_(`options.${A}.scores.${v}`)}>${T!==void 0?S(String(T)):"—"}</td>`}).join("");return`<tr${_(`criteria.${v}`)}><td class="sc-crit"${_(`criteria.${v}.label`)}>${S(g.label)}${b}</td>${E}</tr>`}).join(""),p=`<tr class="sc-foot"><td>TOTAL</td>${s.map((g,v)=>`<td class="c sc-total${r(v)?" sc-win":""}">${S(iW(g))}</td>`).join("")}</tr>`,h=e.title!==void 0?`<div class="sc-head">${S(e.title)}</div>`:"",m=e.description!==void 0?`<p class="sc-desc">${S(e.description)}</p>`:"";return`<div class="scorecard">${h}${m}<div class="sc-scroll"><table class="sc-table"><thead>${l}</thead><tbody${he("criteria")}>${d}${p}</tbody></table></div></div>`}function lW(e){const{likelihood:t,impact:n}=e;return t==="high"&&n==="high"?"critical":t==="high"||n==="high"?"high":t==="low"&&n==="low"?"low":"medium"}function cW(e,t){const n=lW(e),s=e.mitigation!==void 0?`<p class="rk-mitigation"${_(`items.${t}.mitigation`)}><span class="rk-mit-label">Mitigation:</span> ${S(e.mitigation)}</p>`:"",o=e.owner!==void 0?`<span class="rk-owner"${_(`items.${t}.owner`)}>${S(e.owner)}</span>`:"",r=e.status!==void 0?`<span class="rk-status rk-st-${e.status}"${_(`items.${t}.status`)}>${S(e.status)}</span>`:"",i=o!==""||r!==""?`<span class="rk-chips">${o}${r}</span>`:"";return`<div class="rk-item"${_(`items.${t}`)}><div class="rk-top"><span class="rk-sev rk-sev-${n}">${n}</span><span class="rk-risk"${_(`items.${t}.risk`)}>${S(e.risk)}</span>`+i+`</div><div class="rk-meta">L: ${S(e.likelihood)} · I: ${S(e.impact)}</div>`+s+"</div>"}function dW(e){const t=e.title!==void 0?`<div class="rk-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="rk-desc">${S(e.description)}</p>`:"",s=e.items.map((o,r)=>cW(o,r)).join("");return`<div class="risk">${t}${n}<div class="rk-list"${he("items")}>${s}</div></div>`}var uW=tx.fallback,C0=tx.dark,pW=tx.light;function fW(e){const t=e.trim().replace(/^#/,"");if(/^[0-9a-fA-F]{3}$/.test(t)){const n=t.split("");return[parseInt(`${n[0]}${n[0]}`,16),parseInt(`${n[1]}${n[1]}`,16),parseInt(`${n[2]}${n[2]}`,16)]}return/^[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$/.test(t)?[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]:null}function hW(e){const t=n=>{const s=n/255;return s<=.03928?s/12.92:((s+.055)/1.055)**2.4};return .2126*t(e[0])+.7152*t(e[1])+.0722*t(e[2])}function mW(e){const t=fW(e);return t===null||hW(t)>.6?C0:pW}var gW="rgba(255,255,255,.86)",vW="rgba(0,0,0,.58)";function yW(e,t){const n=Fi(e.value,uW),s=mW(n),o=Fi(e.on,s),r=e.on===void 0?`;background:${o===C0?gW:vW}`:"",i=e.usage!==void 0?`<div class="pl-usage"${_(`colors.${t}.usage`)}>${S(e.usage)}</div>`:"";return`<div class="pl-card"${_(`colors.${t}`)}><div class="pl-swatch" style="background:${n}"><span class="pl-hex" style="color:${o}${r}"${_(`colors.${t}.value`)}>${S(e.value)}</span></div><div class="pl-meta"><div class="pl-name t-name"${_(`colors.${t}.name`)}>${S(e.name)}</div>`+i+"</div></div>"}function xW(e){const t=e.title!==void 0?`<div class="pl-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="pl-desc">${S(e.description)}</p>`:"",s=Math.min(6,Math.max(2,Math.floor(e.cols??4))),o=e.colors.map((r,i)=>yW(r,i)).join("");return`<div class="palette">${t}${n}<div class="pl-grid" style="--pl-cols:${s}"${he("colors")}>${o}</div></div>`}var kW="The quick brown fox jumps over the lazy dog",S$={display:"ts-f-display",body:"ts-f-body",mono:"ts-f-mono"};function uc(e){return String(Math.round(e*100)/100)}function bW(e,t,n){const s=e.weight??400,o=e.lineHeight??1.3,r=Math.min(64,Math.max(10,e.size)),i=S$[e.font??"body"]??S$.body,l=e.note!==void 0?`<div class="ts-note"${_(`items.${n}.note`)}>${S(e.note)}</div>`:"",d=`font-size:${uc(r)}px;font-weight:${uc(s)};line-height:${uc(o)}`;return`<div class="ts-row"${_(`items.${n}`)}><div class="ts-meta"><div class="ts-name"${_(`items.${n}.name`)}>${S(e.name)}</div><div class="ts-spec">${S(`${uc(e.size)}px / weight ${uc(s)}`)}</div>`+l+`</div><div class="ts-sample ${i}" style="${d}"${_("sample")}>${S(t)}</div></div>`}function wW(e){const t=e.title!==void 0?`<div class="ts-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="ts-desc">${S(e.description)}</p>`:"",s=e.sample??kW,o=e.items.map((r,i)=>bW(r,s,i)).join("");return`<div class="typescale">${t}${n}<div class="ts-rows"${he("items")}>${o}</div></div>`}function $W(e,t,n){const s=e.example!==void 0?`<div class="dd-ex"${_(`${t}.${n}.example`)}>${S(e.example)}</div>`:"";return`<div class="dd-item"${_(`${t}.${n}`)}><div class="dd-text"${_(`${t}.${n}.text`)}>${S(e.text)}</div>${s}</div>`}function E$(e,t,n,s,o){return`<div class="dd-card ${e}"><div class="dd-band"><span class="dd-sign">${t}</span><span class="dd-label">${S(n)}</span></div><div class="dd-list"${he(o)}>${s.map((r,i)=>$W(r,o,i)).join("")}</div></div>`}function SW(e){const t=e.title!==void 0?`<div class="dd-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="dd-desc">${S(e.description)}</p>`:"";return`<div class="dodont">${t}${n}<div class="dd-grid">`+E$("dd-do","✓","Do",e.dos,"dos")+E$("dd-dont","✕","Don't",e.donts,"donts")+"</div></div>"}var EW={stable:"inv-st-stable",beta:"inv-st-beta",experimental:"inv-st-experimental",deprecated:"inv-st-deprecated",planned:"inv-st-planned"};function MW(e,t){const n=e.tag!==void 0?`<span class="inv-tag"${_(`items.${t}.tag`)}>${S(e.tag)}</span>`:"",s=e.note!==void 0?`<div class="inv-note"${_(`items.${t}.note`)}>${S(e.note)}</div>`:"";return`<div class="inv-row"${_(`items.${t}`)}><div class="inv-main"><div class="inv-top"><span class="inv-name"${_(`items.${t}.name`)}>${S(e.name)}</span>${n}</div>`+s+`</div><span class="inv-status ${EW[e.status]??""}"${_(`items.${t}.status`)}>${S(e.status)}</span></div>`}function AW(e){const t=e.title!==void 0?`<div class="inv-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="inv-desc">${S(e.description)}</p>`:"",s=e.items.map((o,r)=>MW(o,r)).join("");return`<div class="inventory">${t}${n}<div class="inv-list"${he("items")}>${s}</div></div>`}var Ms=44,Jg=8;function CW(e){return e.length>5?`${e.slice(0,4)}…`:e}function NW(e){const t=e.items??[],n=e.showIndex??!0,s=t.length,o=t.some(b=>b.label!==void 0&&b.label.length>0),r=s>0&&e.window!==void 0?e.window:void 0,i=r!==void 0?20:0,l=n?16:0,d=6+i+l,u=o?26:0,p=d+Ms+u+8,h=Jg*2+Math.max(s,1)*Ms;let m=`<svg viewBox="0 0 ${h} ${p}" width="${h}" height="${p}" role="img"><title>Array</title>`;if(s===0)return m+=`<text x="${Jg}" y="${d+26}" class="t-sub c-soft">(empty)</text></svg>`,M$(e,m,"");const g=b=>Jg+b*Ms,v=new Set;let y=!1;if(m+=`<g${he("items")}>`,t.forEach((b,E)=>{const $=vh(b.tone);b.tone!==void 0?v.add(b.tone):y=!0;const A=g(E);m+=`<g${_(`items.${E}`)}>`,n&&(m+=`<text x="${A+Ms/2}" y="${d-5}" class="t-sub c-soft" text-anchor="middle">${E}</text>`),m+=`<rect x="${A}" y="${d}" width="${Ms}" height="${Ms}"${yh($)}/>`,m+=`<text x="${A+Ms/2}" y="${d+Ms/2+5}" class="ds-val" fill="${$.text}"${_(`items.${E}.value`)}>${S(CW(b.value))}</text>`,m+="</g>"}),m+="</g>",t.forEach((b,E)=>{if(b.label===void 0||b.label.length===0)return;const $=g(E)+Ms/2,A=d+Ms;m+=`<g${_(`items.${E}.label`)}>`,m+=`<path d="M${$-4},${A+9} L${$},${A+3} L${$+4},${A+9} z" fill="var(--ink)"/>`,m+=`<text x="${$}" y="${A+20}" class="t-badge c-ink" text-anchor="middle">${S(b.label)}</text>`,m+="</g>"}),r!==void 0){const b=Math.max(0,Math.min(s-1,Math.min(r.from,r.to))),E=Math.max(0,Math.min(s-1,Math.max(r.from,r.to))),$=g(b)-3,A=(E-b+1)*Ms+6;m+=`<rect x="${$}" y="${d-3}" width="${A}" height="${Ms+6}" rx="4" fill="none" stroke="var(--ink)" stroke-width="1.25" stroke-dasharray="4 3"${_("window")}/>`,r.label!==void 0&&r.label.length>0&&(m+=`<text x="${$+A}" y="${d-l-6}" text-anchor="end" class="t-eyebrow"${_("window.label")}>${S(r.label)}</text>`)}return m+="</svg>",M$(e,m,TW(y,v,r!==void 0))}function TW(e,t,n){const s=[];e&&s.push({swatch:"node",label:"cell"});for(const o of["active","target","visited","muted"])t.has(o)&&s.push(xh[o]);return n&&s.push({swatch:"chip",chip:"[ ]",label:"window"}),ot(s)}function M$(e,t,n){return ct({tag:"ARRAY",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...n.length>0?{legendHtml:n}:{}},t)}var Bo=56,Zu=40,zo=38,Ju=34,ev=8;function _W(e){return e.length>4?`${e.slice(0,3)}…`:e}var ep='fill="none" stroke="var(--muted)" stroke-width="1.5" marker-end="url(#skArrow)"';function LW(e){const t=e.nodes??[],n=(e.kind??"singly")==="doubly",s=e.nullEnd??!0,o=t.length,i=t.some(b=>b.label!==void 0&&b.label.length>0)?30:8,l=i+Zu/2,d=i+Zu+10,u=s?Ju+18:0,p=ev*2+Math.max(o,1)*Bo+Math.max(o-1,0)*Ju+u;let h=`<svg viewBox="0 0 ${p} ${d}" width="${p}" height="${d}" role="img"><title>Linked list</title>`;if(o===0)return h+=`<text x="${ev}" y="${l+4}" class="t-sub c-soft">(empty)</text></svg>`,A$(e,h,"");const m=b=>ev+b*(Bo+Ju);for(let b=0;b<o-1;b+=1){const E=m(b)+zo+(Bo-zo)/2,$=m(b+1);n?(h+=`<path d="M${E},${l-7} L${$-2},${l-7}" ${ep}/>`,h+=`<path d="M${$},${l+7} L${m(b)+Bo+2},${l+7}" ${ep}/>`):h+=`<path d="M${E},${l} L${$-2},${l}" ${ep}/>`}if(s){const b=m(o-1)+zo+(Bo-zo)/2,E=m(o-1)+Bo+Ju,$=n?l-7:l;h+=`<path d="M${b},${$} L${E-2},${$}" ${ep}/>`,h+=`<text x="${E+8}" y="${$+5}" class="t-name c-muted">∅</text>`}const g=new Set;let v=!1;h+=`<g${he("nodes")}>`,t.forEach((b,E)=>{const $=vh(b.tone);b.tone!==void 0?g.add(b.tone):v=!0;const A=m(E);h+=`<g${_(`nodes.${E}`)}><rect x="${A}" y="${i}" width="${Bo}" height="${Zu}" rx="4"${yh($)}/><line x1="${A+zo}" y1="${i+5}" x2="${A+zo}" y2="${i+Zu-5}" stroke="${$.stroke}" stroke-width="1"/><circle cx="${A+zo+(Bo-zo)/2}" cy="${l}" r="3" fill="${$.text}"/><text x="${A+zo/2}" y="${l+5}" class="ds-val" fill="${$.text}"${_(`nodes.${E}.value`)}>${S(_W(b.value))}</text></g>`}),h+="</g>",t.forEach((b,E)=>{if(b.label===void 0||b.label.length===0)return;const $=m(E)+Bo/2;h+=`<g${_(`nodes.${E}.label`)}>`,h+=`<text x="${$}" y="${i-14}" class="t-badge c-ink" text-anchor="middle">${S(b.label)}</text>`,h+=`<path d="M${$-4},${i-10} L${$+4},${i-10} L${$},${i-4} z" fill="var(--ink)"/>`,h+="</g>"}),h+="</svg>";const y=[];v&&y.push({swatch:"node",label:"node"});for(const b of["active","target","visited","muted"])g.has(b)&&y.push(xh[b]);return y.push({swatch:"edge",label:n?"next / prev":"next"}),A$(e,h,ot(y))}function A$(e,t,n){return ct({tag:"LIST",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...n.length>0?{legendHtml:n}:{}},t)}var pc=18,C$=52,N$=64,tv=10,T$=8;function IW(e){return e.length>4?`${e.slice(0,3)}…`:e}function jW(e){const t=e.nodes??[];if(t.length===0){const T=`<svg viewBox="0 0 220 44" width="220" height="44" role="img"><title>Binary tree</title><text x="${tv}" y="26" class="t-sub c-soft">(empty)</text></svg>`;return _$(e,T,"")}const n=new Map(t.map(T=>[T.id,T])),s=new Map,o=[];for(const T of t){if(T.parent===void 0||!n.has(T.parent)){o.push(T);continue}const N=s.get(T.parent)??{};T.side==="right"?N.right=T:N.left=T,s.set(T.parent,N)}const r=new Map;let i=0;const l=(T,N)=>{if(r.has(T.id))return r.get(T.id)?.x??0;const j=s.get(T.id)??{};let P;if(j.left!==void 0&&j.right!==void 0){const I=l(j.left,N+1),O=l(j.right,N+1);P=(I+O)/2}else j.left!==void 0?P=l(j.left,N+1)+.5:j.right!==void 0?P=l(j.right,N+1)-.5:(P=i,i+=1);return r.set(T.id,{node:T,x:P,depth:N}),P};o.forEach((T,N)=>{N>0&&(i+=.8),l(T,0)});const d=[...r.values()],u=Math.min(...d.map(T=>T.x)),p=Math.max(...d.map(T=>T.x)),h=Math.max(...d.map(T=>T.depth)),m=T=>tv+pc+Math.round((T.x-u)*C$),g=T=>T$+pc+T.depth*N$,v=tv*2+2*pc+Math.round((p-u)*C$),y=T$+2*pc+h*N$+8;let b=`<svg viewBox="0 0 ${v} ${y}" width="${v}" height="${y}" role="img"><title>Binary tree</title>`;for(const T of d){const N=T.node.parent;if(N===void 0)continue;const j=r.get(N);j!==void 0&&(b+=`<line x1="${m(j)}" y1="${g(j)}" x2="${m(T)}" y2="${g(T)}" stroke="var(--muted)" stroke-width="1.5"/>`)}const E=new Set;let $=!1;b+=`<g${he("nodes")}>`,t.forEach((T,N)=>{const j=r.get(T.id);if(j===void 0)return;const P=vh(T.tone);T.tone!==void 0?E.add(T.tone):$=!0,b+=`<g${_(`nodes.${N}`)}><circle cx="${m(j)}" cy="${g(j)}" r="${pc}"${yh(P)}/><text x="${m(j)}" y="${g(j)+4}" class="bt-val" fill="${P.text}"${_(`nodes.${N}.value`)}>${S(IW(T.value))}</text></g>`}),b+="</g>",b+="</svg>";const A=[];$&&A.push({swatch:"node",label:"node"});for(const T of["active","target","visited","muted"])E.has(T)&&A.push(xh[T]);return _$(e,b,ot(A))}function _$(e,t,n){return ct({tag:"TREE",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...n.length>0?{legendHtml:n}:{}},t)}var fc=34,Ca=30,tp=10,L$=24,np=16,Sr=6,PW=12,OW=320;function I$(e){return e.length>24?`${e.slice(0,23)}…`:e}function j$(e){return e.value!==void 0&&e.value.length>0?`${e.key}: ${e.value}`:e.key}function RW(e){const t=Math.max(0,Math.floor(e.buckets)),n=Math.min(t,PW),s=t-n,o=e.entries??[],r=new Map;o.forEach((y,b)=>{const E=Math.floor(y.bucket);if(E<0||E>=t)return;const $=r.get(E)??[];$.push({e:y,idx:b}),r.set(E,$)});const i=s>0?20:0,l=Math.max(n,1)*(Ca+tp)-(n>0?tp:0)+12+i,d=y=>Math.max(34,Math.round(I$(j$(y)).length*6.6)+18);let u=OW;for(let y=0;y<n;y+=1){let b=Sr+fc+np;for(const{e:E}of r.get(y)??[])b+=d(E)+np;u=Math.max(u,b+Sr)}let p=`<svg viewBox="0 0 ${u} ${l}" width="${u}" height="${l}" role="img"><title>Hash map</title>`;if(n===0)return p+=`<text x="${Sr}" y="${Ca/2+9}" class="t-sub c-soft">(empty)</text></svg>`,P$(e,p,"");const h=new Set;let m=!1,g=!1;p+=`<g${he("entries")}>`;for(let y=0;y<n;y+=1){const b=4+y*(Ca+tp),E=b+Ca/2;p+=`<rect x="${Sr}" y="${b}" width="${fc}" height="${Ca}" rx="2" fill="var(--paper-2)" stroke="var(--rule-solid)" stroke-width="1"/>`,p+=`<text x="${Sr+fc/2}" y="${E+4}" class="t-sub c-muted" text-anchor="middle">${y}</text>`;const $=r.get(y)??[];if($.length===0){p+=`<text x="${Sr+fc+12}" y="${E+4}" class="t-sub c-soft">—</text>`;continue}$.length>1&&(g=!0);let A=Sr+fc;$.forEach(({e:T,idx:N})=>{const j=d(T);p+=`<path d="M${A+1},${E} L${A+np-2},${E}" fill="none" stroke="var(--muted)" stroke-width="1.25" marker-end="url(#skArrow)"/>`,A+=np;const P=vh(T.tone);T.tone!==void 0?h.add(T.tone):m=!0,p+=`<g${_(`entries.${N}`)}>`,p+=`<rect x="${A}" y="${E-L$/2}" width="${j}" height="${L$}" rx="4"${yh(P)}/>`,p+=`<text x="${A+j/2}" y="${E+4}" class="hsh-key" fill="${P.text}">${S(I$(j$(T)))}</text>`,p+="</g>",A+=j})}if(p+="</g>",s>0){const y=4+n*(Ca+tp)+10;p+=`<text x="${Sr}" y="${y}" class="t-sub c-soft">+${s} more bucket${s===1?"":"s"}</text>`}p+="</svg>";const v=[{swatch:"node-fill2",label:"bucket"}];m&&v.push({swatch:"node",label:"entry"});for(const y of["active","target","visited","muted"])h.has(y)&&v.push(xh[y]);return g&&v.push({swatch:"edge",label:"collision chain"}),P$(e,p,ot(v))}function P$(e,t,n){return ct({tag:"HASH",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...n.length>0?{legendHtml:n}:{}},t)}var O$=660,mi=16,gi=118,hc=56,ss=232,Er=176,Na=512,DW=134,R$=10,BW=5,D$={fill:"var(--paper)",stroke:"var(--ink)"},B$={fill:"var(--accent-tint)",stroke:"var(--accent)"},z$={fill:"var(--paper-2)",stroke:"var(--rule-solid)"},sp={fill:"var(--paper-2)",stroke:"var(--ink)"};function op(e,t,n,s){return`<circle cx="${t}" cy="${n}" r="8" class="step-badge"/><text x="${t}" y="${n+3}" text-anchor="middle" class="t-badge">${e}</text><text x="${t+13}" y="${n+3.5}" class="al-lbl">${S(s)}</text>`}function CA(e){return lt(e.desc,22,2)}function F$(e){const t=CA(e).length;return t===0?26:28+t*13}function zW(e){const t=e.tools??[],n=t.slice(0,BW),s=t.length-n.length,o=n.length>0,r=e.memory,i=e.env??"User",l=lt(e.agent.note,28,3),d=e.agent.model!==void 0&&e.agent.model.length>0,u=Math.max(56,36+(d?22:0)+(l.length>0?l.length*13+8:0)),p=o?n.reduce((te,ee)=>te+F$(ee),0)+R$*(n.length-1)+(s>0?18:0):0,m=Math.round(10+Math.max(u,p,hc,64)/2),g=Math.round(m-u/2),v=Math.round(m-hc/2),y=Math.round(m-p/2),b=Math.max(g+u,v+hc,o?y+p:0),E=r??[],$=r!==void 0,A=176,T=$?Math.max(44,32+E.length*15):0,N=Math.round(ss+(Er-A)/2),j=b+46,P=$?j+T+8:b+12;let I=`<svg viewBox="0 0 ${O$} ${P}" width="${O$}" height="${P}" role="img"><title>Agent loop</title>`;I+=`<rect x="${mi}" y="${v}" width="${gi}" height="${hc}" rx="4" fill="${D$.fill}" stroke="${D$.stroke}" stroke-width="1.5"/>`+al("user",mi+Math.round(gi/2)-8,v+10,"var(--muted)")+`<text x="${mi+Math.round(gi/2)}" y="${v+hc-12}" text-anchor="middle" class="al-env"${_("env")}>${S(i)}</text>`,I+=`<rect x="${ss}" y="${g}" width="${Er}" height="${u}" rx="4" fill="${B$.fill}" stroke="${B$.stroke}" stroke-width="1.5"/>`,I+=al("agent",ss+12,g+12,"var(--accent)"),I+=`<text x="${ss+36}" y="${g+24}" class="al-name"${_("agent.name")}>${S(e.agent.name)}</text>`;let O=g+34;if(d){const te=e.agent.model??"",ee=Math.min(Er-24,16+te.length*6);I+=`<rect x="${ss+12}" y="${O}" width="${ee}" height="16" rx="3" fill="var(--paper)" stroke="var(--rule-solid)" stroke-width="1"/><text x="${ss+12+Math.round(ee/2)}" y="${O+11.5}" text-anchor="middle" class="al-chip"${_("agent.model")}>${S(te)}</text>`,O+=22}if(l.forEach((te,ee)=>{I+=`<text x="${ss+12}" y="${O+10+ee*13}" class="al-note">${S(te)}</text>`}),o){let te=y;I+=`<g${he("tools")}>`,n.forEach((ee,H)=>{const W=F$(ee);I+=`<g${_(`tools.${H}`)}>`,I+=`<rect x="${Na}" y="${te}" width="${DW}" height="${W}" rx="4" fill="${z$.fill}" stroke="${z$.stroke}" stroke-width="1"/>`,I+=`<text x="${Na+11}" y="${te+17}" class="al-tool-name"${_(`tools.${H}.name`)}>${S(ee.name)}</text>`,CA(ee).forEach((K,R)=>{I+=`<text x="${Na+11}" y="${te+31+R*13}" class="al-tool-desc">${S(K)}</text>`}),I+="</g>",te+=W+R$}),I+="</g>",s>0&&(I+=`<text x="${Na+11}" y="${te+2}" class="al-more">+${s} more</text>`)}const C=m-13,D=m+13;if(I+=`<line x1="${mi+gi}" y1="${C}" x2="${ss-4}" y2="${C}" class="al-edge" marker-end="url(#gArrow)"/>`,I+=op(1,mi+gi+18,C-13,"prompt"),I+=`<line x1="${ss}" y1="${D}" x2="${mi+gi+4}" y2="${D}" class="al-edge dashed" marker-end="url(#gSoft)"/>`,I+=op(4,mi+gi+18,D+17,"response"),o&&(I+=`<line x1="${ss+Er}" y1="${C}" x2="${Na-4}" y2="${C}" class="al-edge" marker-end="url(#gArrow)"/>`,I+=op(2,ss+Er+18,C-13,"tool call"),I+=`<line x1="${Na}" y1="${D}" x2="${ss+Er+4}" y2="${D}" class="al-edge dashed" marker-end="url(#gSoft)"/>`,I+=op(3,ss+Er+18,D+17,"result")),$){const te=ss+Math.round(Er/2);I+=`<line x1="${te}" y1="${g+u+3}" x2="${te}" y2="${j-8}" class="al-edge dashed" marker-start="url(#gSoft)" marker-end="url(#gSoft)"/>`,I+=`<text x="${te+8}" y="${Math.round((g+u+j)/2)+3}" class="al-lbl">read/write</text>`;const ee=7;I+=`<path d="M${N} ${j+ee} a ${Math.round(A/2)} ${ee} 0 0 1 ${A} 0 V ${j+T-ee} a ${Math.round(A/2)} ${ee} 0 0 1 -${A} 0 Z" fill="${sp.fill}" stroke="${sp.stroke}" stroke-width="1"/><ellipse cx="${N+Math.round(A/2)}" cy="${j+ee}" rx="${Math.round(A/2)}" ry="${ee}" fill="${sp.fill}" stroke="${sp.stroke}" stroke-width="1"/>`,I+=`<text x="${N+Math.round(A/2)}" y="${j+27}" text-anchor="middle" class="al-mem">memory</text>`,I+=`<g${he("memory")}>`,E.forEach((H,W)=>{const K=lt(H,28,1)[0]??"";I+=`<text x="${N+Math.round(A/2)}" y="${j+41+W*15}" text-anchor="middle" class="al-mem-item"${_(`memory.${W}`)}>${S(K)}</text>`}),I+="</g>"}I+="</svg>";const F=e.stop!==void 0&&e.stop.length>0?`<div class="al-foot"><span class="al-foot-label">stops when:</span> <span${_("stop")}>${S(e.stop)}</span></div>`:"",U=[o?"tool":"",$?"memory":""].filter(te=>te.length>0),X=[{swatch:"node",label:"environment"},{swatch:"node-accent",label:"agent"},...U.length>0?[{swatch:"node-fill2",label:U.join(" · ")}]:[],{swatch:"edge",label:o?"prompt · tool call":"prompt"},{swatch:"edge-dashed",label:o?"response · result":"response"}],B=ot(X);return ct({tag:"AGENT",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...B.length>0?{legendHtml:B}:{},...F.length>0?{footerHtml:F}:{}},I)}var FW={user:"USER",assistant:"ASSISTANT",tool:"TOOL",system:"SYSTEM"};function qW(e,t){const n=[];return e.thinking!==void 0&&e.thinking.length>0&&n.push(`<div class="tr-think"${_(`turns.${t}.thinking`)}>${S(e.thinking)}</div>`),e.tool!==void 0&&e.tool.length>0&&n.push(`<div class="tr-tool-name"${_(`turns.${t}.tool`)}>${S(e.tool)}</div>`),e.args!==void 0&&e.args.length>0&&n.push(`<div class="tr-io"><span class="tr-io-label">args:</span><code class="tr-mono">${S(e.args)}</code></div>`),e.result!==void 0&&e.result.length>0&&n.push(`<div class="tr-io"><span class="tr-io-label">→</span><code class="tr-mono">${S(e.result)}</code></div>`),e.text!==void 0&&e.text.length>0&&n.push(`<div class="tr-text"${_(`turns.${t}.text`)}>${S(e.text)}</div>`),`<div class="tr-turn tr-${e.role}"${_(`turns.${t}`)}><span class="tr-chip">${FW[e.role]??S(e.role).toUpperCase()}</span><div class="tr-card">${n.join("")}</div></div>`}function HW(e){const t=e.title!==void 0?`<div class="tr-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="tr-desc">${S(e.description)}</p>`:"",s=e.turns.map((o,r)=>qW(o,r)).join("");return`<div class="trace">${t}${n}<div class="tr-list"${he("turns")}>${s}</div></div>`}var WW=/\{\{[a-zA-Z0-9_.]+\}\}/g;function UW(e){return S(e).replace(WW,t=>`<span class="pr-var">${t}</span>`)}function KW(e,t){const n=e.label!==void 0&&e.label.length>0?`<span class="pr-label"${_(`segments.${t}.label`)}>— ${S(e.label)}</span>`:"";return`<div class="pr-seg pr-${e.kind}"${_(`segments.${t}`)}><div class="pr-kicker">${e.kind.toUpperCase()}${n}</div><div class="pr-text"${_(`segments.${t}.text`)}>${UW(e.text)}</div></div>`}function VW(e){const t=e.title!==void 0?`<div class="pr-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="pr-desc">${S(e.description)}</p>`:"",s=e.segments.map((i,l)=>KW(i,l)).join(""),o=e.vars??[],r=o.length>0?`<div class="pr-vars"${he("vars")}>${o.map((i,l)=>`<div class="pr-var-row"${_(`vars.${l}`)}><span class="pr-var"${_(`vars.${l}.name`)}>{{${S(i.name)}}}</span>`+(i.desc!==void 0&&i.desc.length>0?`<span class="pr-var-desc"${_(`vars.${l}.desc`)}>${S(i.desc)}</span>`:"")+"</div>").join("")}</div>`:"";return`<div class="prompt">${t}${n}<div class="pr-list"${he("segments")}>${s}</div>${r}</div>`}var q$={navy:"var(--series-2)",blue:"var(--series-2)",teal:"var(--series-1)",green:"var(--series-1)",amber:"var(--series-3)",purple:"var(--series-5)",red:"var(--negative)",gray:"var(--ink-3)"},H$=["var(--series-1)","var(--series-2)","var(--series-3)","var(--series-4)","var(--series-5)"];function W$(e,t){return e!==void 0&&q$[e]!==void 0?q$[e]:H$[t%H$.length]??"var(--series-1)"}function nv(e,t,n){const s=10+n.length*6.2;return`<rect x="${Math.round(e-s/2)}" y="${t-8}" width="${Math.round(s)}" height="16" rx="3" class="ctx-seg-mask"/><text x="${e}" y="${t+3.5}" text-anchor="middle" class="ctx-seg-label">${S(n)}</text>`}var vi=820,yi=34,mc=8,As=22,gc=e=>Number.isFinite(e)&&e>0?e:0,rp=e=>Math.round(e).toLocaleString("en-US");function sv(e,t,n,s,o,r){return`M${e+o} ${n} H ${e+t-r}`+(r>0?` a ${r} ${r} 0 0 1 ${r} ${r}`:"")+` V ${n+s-r}`+(r>0?` a ${r} ${r} 0 0 1 -${r} ${r}`:"")+` H ${e+o}`+(o>0?` a ${o} ${o} 0 0 1 -${o} -${o}`:"")+` V ${n+o}`+(o>0?` a ${o} ${o} 0 0 1 ${o} -${o}`:"")+" Z"}function GW(e){const t=e.unit??"tokens",n=gc(e.window),s=e.segments.map((v,y)=>({seg:v,si:y})).filter(({seg:v})=>gc(v.tokens)>0),o=s.reduce((v,{seg:y})=>v+gc(y.tokens),0),r=n>0&&o>n,i=n>0&&o<n?n-o:0,l=Math.max(n,o,1),d=v=>Math.round(vi*v/l),u=As+yi+8;let p=`<svg viewBox="0 0 ${vi} ${u}" width="${vi}" height="${u}" role="img"><title>Context window</title>`;p+=`<text x="${vi}" y="${As-8}" text-anchor="end" class="ctx-window-label"${_("window")}>window: ${S(rp(n))} ${S(t)}</text>`;let h=0;if(p+=`<g${he("segments")}>`,s.forEach(({seg:v,si:y},b)=>{const E=gc(v.tokens),$=d(h),A=Math.max(d(h+E)-$,2),T=b===0,N=b===s.length-1&&i===0;p+=`<path d="${sv($,A,As,yi,T?mc:0,N?mc:0)}" fill="${W$(v.accent,b)}"${_(`segments.${y}`)}/>`;const j=$+Math.round(A/2),P=As+Math.round(yi/2);A>90?p+=nv(j,P,v.label):A>=22&&(p+=nv(j,P,String(b+1))),h+=E}),p+="</g>",i>0){const v=d(o),y=Math.max(vi-v,2);p+=`<path d="${sv(v,y,As,yi,s.length===0?mc:0,mc)}" fill="var(--paper-2)" stroke="var(--rule-solid)" stroke-width="1"/>`,y>=90&&(p+=`<text x="${v+Math.round(y/2)}" y="${As+21}" text-anchor="middle" class="ctx-free-label">free (${S(rp(i))})</text>`)}if(r){const v=d(n),y=Math.max(vi-v,2);p+=`<path d="${sv(v,y,As,yi,0,mc)}" fill="var(--negative)"/>`,y>=70&&(p+=nv(v+Math.round(y/2),As+Math.round(yi/2),`+${rp(o-n)}`)),p+=`<line x1="${v}" y1="${As-6}" x2="${v}" y2="${As+yi+5}" class="ctx-boundary"/>`;const b="over budget",E=20+b.length*6,$=Math.min(v-Math.round(E/2),vi-E-160);p+=`<rect x="${$}" y="${As-20}" width="${E}" height="16" rx="8" class="ctx-chip-bg"/>`,p+=`<text x="${$+Math.round(E/2)}" y="${As-8.5}" text-anchor="middle" class="ctx-chip">${b}</text>`}p+="</svg>";const m=s.map(({seg:v,si:y},b)=>{const E=gc(v.tokens),$=n>0?Math.round(E/n*100):0,A=v.desc!==void 0&&v.desc.length>0?`<span class="ctx-note"${_(`segments.${y}.desc`)}>${S(v.desc)}</span>`:"";return`<div class="ctx-row"${_(`segments.${y}`)}><span class="ctx-dot" style="background:${W$(v.accent,b)}"></span><span class="ctx-idx">${b+1}</span><span class="ctx-label"${_(`segments.${y}.label`)}>${S(v.label)}</span><span class="ctx-num"${_(`segments.${y}.tokens`)}>${S(rp(E))} ${S(t)} · ${$}%</span>`+A+"</div>"}).join(""),g=m.length>0?`<div class="ctx-legend"${he("segments")}><span class="lg-title t-eyebrow">Legend</span>${m}</div>`:"";return ct({tag:"CONTEXT",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{}},p+g)}var YW=["current","target","new","gap","deprecated"],NA={current:"Current",target:"Target",new:"New",gap:"Gap",deprecated:"Deprecated"};function TA(e){if(typeof e=="string")return"current";const t=e.status;return t!==void 0&&t in NA?t:"current"}function XW(e){return typeof e=="string"?e:e.name}function QW(e,t){const n=TA(e),s=n==="current"?"":` am-t-${n}`,o=n==="gap"?'<span class="t-eyebrow am-chip">Gap</span>':"";return`<div class="am-tile${s}"${_(t)}>${S(XW(e))}${o}</div>`}function ZW(e,t){const n=e.accent!==void 0?` am-${e.accent}`:"",s=e.desc!==void 0?`<div class="am-area-desc"${_(`areas.${t}.desc`)}>${S(e.desc)}</div>`:"",o=e.items??[],r=o.length>0?`<div class="am-tiles"${he(`areas.${t}.items`)}>${o.map((i,l)=>QW(i,`areas.${t}.items.${l}`)).join("")}</div>`:"";return`<div class="am-area${n}"${_(`areas.${t}`)}><div class="am-area-label"${_(`areas.${t}.label`)}>${S(e.label)}</div>`+s+r+"</div>"}function JW(e){const t=new Set;for(const o of e)for(const r of o.items??[])t.add(TA(r));const n=YW.filter(o=>t.has(o));return n.length<2?"":`<div class="diagram-legend"><span class="lg-title t-eyebrow">Legend</span>${n.map(o=>`<span class="lg-item">${o==="gap"?'<span class="lg-chip t-eyebrow">Gap</span>':`<span class="lg-sw am-sw am-sw-${o}"></span>`}<span class="lg-label">${NA[o]}</span></span>`).join("")}</div>`}function eU(e){const t=e.title!==void 0?`<div class="am-head"${_("title")}>${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="am-desc"${_("description")}>${S(e.description)}</p>`:"",s=e.cols!==void 0?Math.min(4,Math.max(2,Math.floor(e.cols))):3,o=e.areas.map((r,i)=>ZW(r,i)).join("");return`<div class="archmap">${t}${n}<div class="am-grid" style="--am-cols:${s}"${he("areas")}>${o}</div>`+JW(e.areas)+"</div>"}function tU(e){const t=e.accent!==void 0?` dvd-${e.accent}`:"",n=e.kicker!==void 0?`<div class="dvd-kicker"><span class="dvd-rule" aria-hidden="true"></span><span class="dvd-kicker-text"${_("kicker")}>${S(e.kicker)}</span><span class="dvd-rule" aria-hidden="true"></span></div>`:"",s=e.subtitle!==void 0?`<p class="dvd-subtitle"${_("subtitle")}>${S(e.subtitle)}</p>`:"";return`<div class="dvd${t}">`+n+`<div class="dvd-title"${_("title")}>${S(e.title)}</div>`+s+"</div>"}var nU={up:"▲",down:"▼",flat:"—"};function sU(e){const t=e.accent!==void 0?` bn-${e.accent}`:"",n=e.trend!==void 0?`<span class="bn-arrow" aria-hidden="true">${nU[e.trend]??""}</span>`:"",s=e.delta!==void 0?`<span class="bn-delta"${_("delta")}>${n}${S(e.delta)}</span>`:"",o=e.context!==void 0?`<p class="bn-context"${_("context")}>${S(e.context)}</p>`:"";return`<div class="bn${t}"><div class="bn-value-row"><span class="bn-value"${_("value")}>${S(e.value)}</span>${s}</div><div class="bn-label"${_("label")}>${S(e.label)}</div>`+o+"</div>"}function oU(e){const t=e.accent!==void 0?` tk-${e.accent}`:"",n=S(e.title??"Takeaways"),s=e.items.map((o,r)=>{const i=o.detail!==void 0?`<p class="tk-detail"${_(`items.${r}.detail`)}>${S(o.detail)}</p>`:"";return`<li class="tk-item"${_(`items.${r}`)}><span class="tk-num" aria-hidden="true">${r+1}</span><div class="tk-body"><div class="tk-text"${_(`items.${r}.text`)}>${S(o.text)}</div>${i}</div></li>`}).join("");return`<div class="tk${t}"><div class="tk-title">${n}</div><ol class="tk-list"${he("items")}>${s}</ol></div>`}var rU=["Task","Update"],iU=2;function _A(e,t){const n=e.toLowerCase();for(const s of t)if(s.label.toLowerCase()===n)return N3(s.color);for(const s of pM)if(s.label.toLowerCase()===n)return s.color;return"gray"}function aU(e,t){return`<span class="stt-pill stt-${_A(e,t)}">${S(e)}</span>`}function U$(e,t,n,s,o){const r=Array.from({length:n},(d,u)=>{const p=e.cells[u],h=u===0&&o===null?' class="stt-lead"':"",m=u===0&&o!==null?`<span class="stt-tree" aria-hidden="true">${o.last?"└":"├"}</span>`:"";return p===void 0?`<td${h}>${m}</td>`:`<td${h}${_(`${t}.cells.${u}`)}>${m}${S(p)}</td>`}).join(""),i=o===null&&"subtasks"in e&&e.subtasks!==void 0&&e.subtasks.length>0;return`<tr${o!==null?' class="stt-sub"':i?' class="stt-haskids"':""}${_(t)}>${r}<td class="stt-status"${_(`${t}.status`)}>${aU(e.status,s)}</td></tr>`}function lU(e){const t=e.items??[],n=t.some(i=>i.owner!==void 0),s=t.some(i=>i.due!==void 0),o=["<th>Task</th>","<th>Status</th>","<th>Priority</th>"];n&&o.push("<th>Owner</th>"),s&&o.push("<th>Due</th>");let r=`<table class="trk"><thead><tr>${o.join("")}</tr></thead><tbody${he("items")}>`;for(const[i,l]of t.entries()){const d=l.status??"todo",u=l.priority,p=u!==void 0?`<span class="pri ${u}">${S(u)}</span>`:"",h=d==="done"?' class="done"':"",m=[`<td class="trk-task"${_(`items.${i}.task`)}>${S(l.task)}</td>`,`<td${_(`items.${i}.status`)}><span class="st ${d}">${S(d)}</span></td>`,`<td${_(`items.${i}.priority`)}>${p}</td>`];n&&m.push(`<td${_(`items.${i}.owner`)}>${S(l.owner??"")}</td>`),s&&m.push(`<td${_(`items.${i}.due`)}>${S(l.due??"")}</td>`),r+=`<tr${h}${_(`items.${i}`)}>${m.join("")}</tr>`}return r+"</tbody></table>"}function cU(e){if(e.rows===void 0)return lU(e);const t=e.rows,n=e.statuses??[],s=e.columns??rU,o=Math.max(s.length,...t.flatMap(m=>[m.cells.length,...(m.subtasks??[]).map(g=>g.cells.length)])),r=Array.from({length:o},(m,g)=>{const v=s[g]!==void 0?S(s[g]??""):"";return`<th${e.columns!==void 0&&g<e.columns.length?_(`columns.${g}`):""}>${v}</th>`}).join("")+'<th class="stt-status-h">Status</th>',i=t.map((m,g)=>{const v=m.subtasks??[],y=U$(m,`rows.${g}`,o,n,null)+v.map((b,E)=>U$(b,`rows.${g}.subtasks.${E}`,o,n,{last:E===v.length-1})).join("");return`<tbody class="stt-group"${he(`rows.${g}.subtasks`)}>${y}</tbody>`}).join(""),l=e.description!==void 0?`<p class="stt-desc"${_("description")}>${S(e.description)}</p>`:"",d=n.map((m,g)=>({label:m.label,index:g})),u=new Set(n.map(m=>m.label.toLowerCase())),p=m=>{const g=m.toLowerCase();u.has(g)||(u.add(g),d.push({label:m,index:-1}))};for(const m of t){p(m.status);for(const g of m.subtasks??[])p(g.status)}const h=d.length>=iU?`<div class="diagram-legend stt-legend"${he("statuses")}><span class="lg-title t-eyebrow">Legend</span>`+d.map(({label:m,index:g})=>{const v=g>=0;return`<span class="lg-item stt-key"${v?_(`statuses.${g}`):""}><i class="lg-sw stt-dot stt-${_A(m,n)}"${v?_(`statuses.${g}.color`):""}></i><span class="lg-label"${v?_(`statuses.${g}.label`):""}>${S(m)}</span></span>`}).join("")+"</div>":"";return`<div class="stt">${l}<div class="stt-wrap"><table class="stt-table"${he("rows")}><thead><tr>${r}</tr></thead>${i}</table>${h}</div></div>`}function dU(e){const t=e.steps.map((N,j)=>typeof N=="string"?{label:N,labelPath:`steps.${j}`}:{label:N.label,desc:N.desc,labelPath:`steps.${j}.label`}),n=t.length,s=t.map(N=>lt(N.label,14,2)),o=Math.max(1,...s.flat().map(N=>N.length)),r=Math.max(1,...s.map(N=>N.length)),i=Math.min(150,Math.max(96,o*7+30)),l=34+(r-1)*14,d=e.center!==void 0&&e.center.length>0?lt(e.center,18,3):[],u=Math.max(0,...d.map(N=>N.length))*7.2,p=Math.max(96,Math.ceil((i+40)/(2*Math.sin(Math.PI/n))),d.length>0?Math.ceil(i/2+u/2+18):0),m=p+i/2+30,g=m*2,v=N=>-Math.PI/2+N*2*Math.PI/n,y=N=>({x:m+p*Math.cos(v(N)),y:m+p*Math.sin(v(N))});let b=`<svg viewBox="0 0 ${g} ${g}" role="img"><title>Cycle</title>`;const E=(N,j)=>{const P=y(N),I=i/2+10,O=l/2+10,C=Math.PI/180;for(let D=C;D<Math.PI/n;D+=C){const F=v(N)+j*D,U=m+p*Math.cos(F),X=m+p*Math.sin(F);if(Math.abs(U-P.x)>I||Math.abs(X-P.y)>O)return D}return Math.PI/n};for(let N=0;N<n;N++){const j=(N+1)%n,P=v(N)+E(N,1),I=v(N+1)-E(j,-1);if(I-P<.08)continue;const O=m+p*Math.cos(P),C=m+p*Math.sin(P),D=m+p*Math.cos(I),F=m+p*Math.sin(I);b+=`<path d="M ${O.toFixed(1)} ${C.toFixed(1)} A ${p} ${p} 0 0 1 ${D.toFixed(1)} ${F.toFixed(1)}" fill="none" stroke="var(--muted)" stroke-width="1.5" marker-end="url(#skArrow)"/>`}d.length>0&&(b+=`<g class="cycle-center"${_("center")}>`+d.map((N,j)=>`<text x="${m}" y="${m+4-(d.length-1)*8+j*16}" class="t-sub" text-anchor="middle">${S(N)}</text>`).join("")+"</g>"),b+=`<g${he("steps")}>`,t.forEach((N,j)=>{const P=y(j),I=s[j]??[],O=P.x-i/2,C=P.y-l/2,D=N.labelPath===`steps.${j}`?"":_(N.labelPath),F=I.length<=1?`<text x="${P.x.toFixed(1)}" y="${(P.y+4).toFixed(1)}" class="t-name" text-anchor="middle"${_(N.labelPath)}>${S(N.label)}</text>`:`<g${D}>`+I.map((H,W)=>`<text x="${P.x.toFixed(1)}" y="${(P.y+4-(I.length-1)*7+W*14).toFixed(1)}" class="t-name" text-anchor="middle">${S(H)}</text>`).join("")+"</g>",U=Math.cos(v(j)),X=Math.sin(v(j)),te=Math.min(Math.abs(U)>1e-6?i/2/Math.abs(U):1/0,Math.abs(X)>1e-6?l/2/Math.abs(X):1/0)+14,ee={lx:P.x+U*te,ly:P.y+X*te};b+=`<g${_(`steps.${j}`)}><rect x="${O.toFixed(1)}" y="${C.toFixed(1)}" width="${i}" height="${l}" rx="${Math.min(17,l/2)}" fill="var(--paper)" stroke="var(--ink)" stroke-width="1.5"/>`+F+`</g><g${_(`steps.${j}`)}>${xf(ee,j+1,!1,!0)}</g>`}),b+="</g></svg>";const $=t.some(N=>N.desc!==void 0&&N.desc.length>0)?E4(t.map((N,j)=>({label:N.desc!==void 0&&N.desc.length>0?`${N.label} — ${N.desc}`:N.label,path:`steps.${j}`}))):"",T=ot([{swatch:"node",label:"stage"},{swatch:"edge",label:"next stage"}]);return ct({tag:"CYCLE",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...T.length>0?{legendHtml:T}:{}},b+$)}var uU="Benchmark",Ef="—";function ov(e,t){if(e===void 0)return{text:Ef,forced:!1,num:void 0,path:t};if(typeof e=="string"||typeof e=="number"){const s=String(e);return{text:s,forced:!1,num:K$(s),path:t}}const n=e.value!==void 0?String(e.value):Ef;return{text:n,...e.note!==void 0?{note:e.note}:{},forced:e.best===!0,num:K$(n),path:e.value!==void 0?`${t}.value`:t}}function K$(e){const t=/-?\d+(?:[.,]\d+)?/.exec(e.replace(/,(?=\d{3}\b)/g,""));if(t===null)return;const n=Number(t[0].replace(",","."));return Number.isFinite(n)?n:void 0}function pU(e,t,n){const s=Math.max(1,e.variants?.length??1);return t.map((o,r)=>{const i=e.cells?.[r],l=`rows.${n}.cells.${r}`;return Array.isArray(i)?Array.from({length:s},(d,u)=>ov(i[u],`${l}.${u}`)):Array.from({length:s},(d,u)=>ov(u===0?i:void 0,l))})}function fU(e,t,n){const s=new Set;for(const[l,d]of e.entries())d[t]?.forced===!0&&s.add(l);if(n==="none")return s;const o=e.map(l=>l[t]?.num),r=o.filter(l=>l!==void 0);if(r.length<2)return s;const i=n==="low"?Math.min(...r):Math.max(...r);return o.forEach((l,d)=>{l===i&&s.add(d)}),s}function hU(e){const t=e.subjects,n=e.rows,s=t.map((u,p)=>{const h=["bm-subj",u.featured===!0?"bm-feat":""].filter(Boolean).join(" "),m=u.sub!==void 0?`<span class="bm-subj-sub"${_(`subjects.${p}.sub`)}>${S(u.sub)}</span>`:"";return`<th class="${h}"${_(`subjects.${p}`)}>${S(u.label)}${m}</th>`}).join(""),o=`<tr${he("subjects")}><th class="bm-metric">${S(e.metricLabel??uU)}</th>${s}</tr>`,r=n.map((u,p)=>{const h=pU(u,t,p),m=h[0]?.length??1,g=Array.from({length:m},(E,$)=>fU(h,$,u.better)),v=u.sub!==void 0?`<span class="bm-row-sub"${_(`rows.${p}.sub`)}>${S(u.sub)}</span>`:"",y=`<td class="bm-metric"${_(`rows.${p}`)}><span class="bm-row-label"${_(`rows.${p}.label`)}>${S(u.label)}</span>${v}</td>`,b=h.map((E,$)=>{const A=t[$],T=A?.tone==="muted"?"bm-muted":"bm-accent",N=E.map((P,I)=>{const C=["bm-slot",g[I]?.has($)===!0&&P.text!==Ef?`bm-best ${T}`:""].filter(Boolean).join(" "),D=P.note!==void 0?`<span class="bm-note">${S(P.note)}</span>`:"",F=u.variants?.[I],U=F!==void 0&&P.text!==Ef?`<span class="bm-cap"${_(`rows.${p}.variants.${I}`)}>${S(F)}</span>`:"";return`<div class="${C}"${_(P.path)}>${D}<span class="bm-val">${S(P.text)}</span>${U}</div>`}).join("");return`<td class="${["bm-cell",A?.featured===!0?"bm-feat":""].filter(Boolean).join(" ")}">${N}</td>`}).join("");return`<tr>${y}${b}</tr>`}).join(""),i=e.title!==void 0?`<div class="bm-head">${S(e.title)}</div>`:"",l=e.description!==void 0?`<p class="bm-desc"${_("description")}>${S(e.description)}</p>`:"",d=e.note!==void 0?`<p class="bm-foot"${_("note")}>${S(e.note)}</p>`:"";return`<div class="benchmark">${i}${l}<div class="bm-scroll"><table class="bm-table"><thead>${o}</thead><tbody${he("rows")}>${r}</tbody></table></div>${d}</div>`}function mU(e){return e==="negative"?"negative":e==="focal"?"accent":"plain"}var gU={plain:"var(--ink)",accent:"var(--accent)",negative:"var(--negative)"},vU={plain:'fill="var(--paper)" stroke="var(--rule-solid)" stroke-width="1"',accent:'fill="var(--accent-tint)" stroke="var(--accent)" stroke-width="1"',negative:'fill="var(--negative-tint)" stroke="var(--negative)" stroke-width="1"'},V$=900,ip=13,rv=8,G$=16,yU=14,iv=16,xU=3;function av(e,t){const n=Math.round(e*10)/10,s=Number.isInteger(n)?String(n):n.toFixed(1);return t!==void 0?`${s}${t}`:s}function kU(e,t){const n=new Map(e.map(s=>[s,0]));for(let s=0;s<e.length;s++){let o=!1;for(const r of t){const i=n.get(r.from),l=n.get(r.to);i===void 0||l===void 0||l<i+1&&(n.set(r.to,i+1),o=!0)}if(!o)break}return n}function bU(e){const t=e.links.filter(A=>A.from!==A.to&&A.value>0),n=e.nodes??[],s=new Map(n.map((A,T)=>[A.id,T])),o=[];for(const A of n)o.includes(A.id)||o.push(A.id);for(const A of t)o.includes(A.from)||o.push(A.from),o.includes(A.to)||o.push(A.to);if(o.length===0||t.length===0)return Y$(e,'<svg viewBox="0 0 900 60" role="img"><title>Sankey</title></svg>',"");const r=kU(o,t),i=new Map,l=Xn(n.map(A=>A.accent));o.forEach(A=>{const T=s.get(A),N=n[T??-1],j=t.filter(I=>I.to===A).reduce((I,O)=>I+O.value,0),P=t.filter(I=>I.from===A).reduce((I,O)=>I+O.value,0);i.set(A,{id:A,label:N?.label??A,tone:mU(T!==void 0?l[T]:void 0),col:N?.col!==void 0?Math.max(0,N.col-1):r.get(A)??0,value:Math.max(j,P),x:0,y:0,h:0,outAt:0,inAt:0,path:s.has(A)?`nodes.${s.get(A)??0}`:void 0})});const d=Math.max(...[...i.values()].map(A=>A.col))+1,u=Array.from({length:d},()=>[]);for(const A of o){const T=i.get(A);T!==void 0&&u[T.col]?.push(T)}const p=Math.max(220,Math.min(420,60+o.length*34)),h=p-G$-yU,m=Math.min(...u.filter(A=>A.length>0).map(A=>{const T=A.reduce((j,P)=>j+P.value,0),N=h-iv*(A.length-1);return T>0?Math.max(N,40)/T:1/0})),g=A=>d===1?rv:rv+(V$-rv*2-ip)*A/(d-1);u.forEach((A,T)=>{const N=A.reduce((P,I)=>P+I.value*m,0)+iv*(A.length-1);let j=G$+Math.max(0,(h-N)/2);for(const P of A)P.h=Math.max(xU,P.value*m),P.x=g(T),P.y=j,P.outAt=j,P.inAt=j,j+=P.h+iv});const v=[...i.values()].some(A=>A.tone!=="plain");let y=-1;if(!v){let A=0;e.links.forEach((T,N)=>{T.from===T.to||!i.has(T.from)||!i.has(T.to)||T.value>A&&(A=T.value,y=N)})}let b=`<svg viewBox="0 0 ${V$} ${p}" role="img"><title>${S(e.title??"Flow volumes")}</title>`;const E=new Set;b+=`<g${he("links")}>`,e.links.forEach((A,T)=>{const N=i.get(A.from),j=i.get(A.to);if(N===void 0||j===void 0||A.value<=0||A.from===A.to)return;const P=Math.max(1,A.value*m),I=N.x+ip,O=j.x,C=N.outAt,D=j.inAt;N.outAt+=P,j.inAt+=P;const F=(I+O)/2,U=`M ${Pt(I)} ${Pt(C)} C ${Pt(F)} ${Pt(C)}, ${Pt(F)} ${Pt(D)}, ${Pt(O)} ${Pt(D)} L ${Pt(O)} ${Pt(D+P)} C ${Pt(F)} ${Pt(D+P)}, ${Pt(F)} ${Pt(C+P)}, ${Pt(I)} ${Pt(C+P)} Z`,X=N.tone!=="plain"?N.tone:T===y?"accent":"plain";if(E.add(X),b+=`<path d="${U}" ${vU[X]}${_(`links.${T}`)}><title>${S(`${N.label} → ${j.label}: ${av(A.value,e.unit)}`)}</title></path>`,P>=13){const B=A.label??av(A.value,e.unit),te=X==="accent"?"t-arrow c-accent":X==="negative"?"t-arrow c-negative":"t-arrow";b+=`<text x="${Pt(F)}" y="${Pt((C+D)/2+P/2+3)}" class="${te}" text-anchor="middle">${S(B)}</text>`}}),b+="</g>",b+=`<g${he("nodes")}>`;for(const A of i.values()){const T=A.path!==void 0?_(A.path):"";b+=`<g${T}>`,b+=`<rect x="${Pt(A.x)}" y="${Pt(A.y)}" width="${ip}" height="${Pt(A.h)}" fill="${gU[A.tone]}"/>`;const N=A.col===d-1,j=N?A.x-8:A.x+ip+8,P=A.y+A.h/2,I=N?"end":"start",O=A.tone==="accent"?"t-name c-accent":A.tone==="negative"?"t-name c-negative":"t-name",C=av(A.value,e.unit),D=Math.max(A.label.length*7.2,C.length*6.2)+8;b+=`<rect x="${Pt(N?j-D+4:j-4)}" y="${Pt(P-9)}" width="${Pt(D)}" height="28" rx="2" fill="var(--paper)"/>`,b+=`<text x="${Pt(j)}" y="${Pt(P+3)}" class="${O}" text-anchor="${I}">${S(A.label)}</text>`,b+=`<text x="${Pt(j)}" y="${Pt(P+15)}" class="t-sub c-muted" text-anchor="${I}">${S(C)}</text>`,b+="</g>"}b+="</g></svg>";const $=[{swatch:"fill",fill:"var(--ink)",label:"stage (height = volume)"}];return E.has("plain")&&$.push({swatch:"fill",fill:"var(--paper)",label:"flow (width = volume)"}),E.has("accent")&&$.push({swatch:"node-accent",label:v?"focal flow":"heaviest flow"}),E.has("negative")&&$.push({swatch:"fill",fill:"var(--negative-tint)",label:"negative flow"}),Y$(e,b,ot($))}function Pt(e){return Math.round(e*10)/10}function Y$(e,t,n){return ct({tag:"SANKEY",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...n.length>0?{legendHtml:n}:{}},t)}var ap=104,X$=96,lv=62,cv=46,Q$=6;function wU(e){const t=[];for(const $ of e.branches??[])t.includes($.name)||t.push($.name);for(const $ of e.commits){const A=$.branch??t[0]??"main";t.includes(A)||t.push(A),$.merge!==void 0&&!t.includes($.merge)&&t.push($.merge)}t.length===0&&t.push("main");const n=t[0]??"main",s=$=>$===n,o=$=>s($)?"var(--accent)":"var(--muted)",r=$=>s($)?1.75:1.5,i=$=>cv+Math.max(0,t.indexOf($))*lv,l=new Map,d=[],u=[];let p=0,h=0;e.commits.forEach(($,A)=>{const T=$.branch??t[0]??"main",N=ap+p*X$,j=i(T),P={x:N,y:j,lane:t.indexOf(T)},I=o(T),O=r(T),C=l.get(T);if(C===void 0){const D=$.from??t[Math.max(0,t.indexOf(T)-1)],F=D!==void 0?l.get(D):void 0;F!==void 0&&u.push(Z$(F,P,I,O))}else u.push(`<line x1="${C.x}" y1="${C.y}" x2="${N}" y2="${j}" stroke="${I}" stroke-width="${O}"/>`);if($.merge!==void 0){const D=l.get($.merge);D!==void 0&&(u.push(Z$(D,P,o($.merge),r($.merge),!0)),h+=1),l.delete($.merge)}l.set(T,P),d.push({p:P,branch:T,index:A}),p+=1});const m=ap+Math.max(1,p)*X$,g=cv+t.length*lv+26;let v=`<svg viewBox="0 0 ${m} ${g}" role="img"><title>${S(e.title??"Branch graph")}</title>`;v+=`<g${he("branches")}>`,t.forEach(($,A)=>{const T=cv+A*lv;v+=`<line x1="${ap-18}" y1="${T}" x2="${m-12}" y2="${T}" stroke="var(--rule)" stroke-width="1" stroke-dasharray="2 5"${ut}/>`;const N=(e.branches??[]).some(j=>j.name===$)?_(`branches.${(e.branches??[]).findIndex(j=>j.name===$)}`):"";v+=`<text x="${ap-26}" y="${T+4}" class="gg-branch t-sub c-ink"${N}>${S($)}</text>`}),v+="</g>",v+=`<g>${u.join("")}</g>`;const y={release:!1,hotfix:!1,revert:!1};v+=`<g${he("commits")}>`,d.forEach(({p:$,branch:A,index:T})=>{const N=e.commits[T];if(N===void 0)return;const j=o(A),P=N.kind==="release"||N.tag!==void 0;if(P&&(y.release=!0),N.kind==="hotfix"&&(y.hotfix=!0),N.kind==="revert"&&(y.revert=!0),v+=`<g${_(`commits.${T}`)}>`,v+=`<circle cx="${$.x}" cy="${$.y}" r="${P?Q$+2:Q$}" fill="${N.kind==="revert"?"var(--paper)":j}" stroke="${j}" stroke-width="1.5"/>`,N.kind==="hotfix"&&(v+=`<circle cx="${$.x}" cy="${$.y}" r="2.5" fill="var(--paper)"/>`),N.label!==void 0&&(v+=`<text x="${$.x}" y="${$.y+22}" class="gg-msg t-sub" text-anchor="middle">${S(N.label)}</text>`),N.tag!==void 0){const I=Math.max(34,N.tag.length*6.5+14);v+="<g>",v+=`<rect x="${$.x-I/2}" y="${$.y-40}" width="${I}" height="18" rx="2" fill="var(--paper)" stroke="var(--ink)" stroke-width="1"/>`,v+=`<text x="${$.x}" y="${$.y-27.5}" class="t-badge c-ink" text-anchor="middle">${S(N.tag)}</text>`,v+=`<line x1="${$.x}" y1="${$.y-22}" x2="${$.x}" y2="${$.y-10}" stroke="var(--rule-solid)" stroke-width="1" stroke-dasharray="2 2"/>`,v+="</g>"}v+="</g>"}),v+="</g></svg>";const b=[{swatch:"line-dot-accent",label:`${n} (trunk)`}];t.length>1&&b.push({swatch:"line-dot",label:"branch"}),h>0&&b.push({swatch:"edge-dashed",label:"merge"}),y.release&&b.push({swatch:"chip",chip:"v1",label:"release tag"}),y.hotfix&&b.push({swatch:"chip",chip:"◉",label:"hotfix"}),y.revert&&b.push({swatch:"chip",chip:"○",label:"revert"});const E=ot(b);return ct({tag:"BRANCHES",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...E.length>0?{legendHtml:E}:{}},v)}function Z$(e,t,n,s,o=!1){const r=(e.x+t.x)/2;return`<path d="${`M ${e.x} ${e.y} C ${r} ${e.y}, ${r} ${t.y}, ${t.x} ${t.y}`}" fill="none" stroke="${n}" stroke-width="${s}"${o?' stroke-dasharray="5 4"':""}/>`}var lp=880,cp=400,dp=3;function J$(e,t){if(e.length===0||t<=0)return 1/0;const n=e.reduce((r,i)=>r+i,0);if(n<=0)return 1/0;const s=Math.max(...e),o=Math.min(...e);return Math.max(t*t*s/(n*n),n*n/(t*t*o))}function e2(e,t){const n=e.reduce((i,l)=>i+l.area,0),s=t.w>=t.h,o=n/(s?t.h:t.w);let r=s?t.y:t.x;for(const{area:i,tile:l}of e){const d=i/o;s?(l.x=t.x,l.y=r,l.w=o,l.h=d):(l.x=r,l.y=t.y,l.w=d,l.h=o),r+=d}return s?{x:t.x+o,y:t.y,w:t.w-o,h:t.h}:{x:t.x,y:t.y+o,w:t.w,h:t.h-o}}function $U(e,t,n){let s=n,o=[];for(let r=0;r<e.length;r++){const i=e[r],l=t[r];if(i===void 0||l===void 0)continue;const d=Math.min(s.w,s.h),u=o.map(p=>p.area);o.length===0||J$([...u,l],d)<=J$(u,d)?o.push({area:l,tile:i}):(s=e2(o,s),o=[{area:l,tile:i}])}o.length>0&&e2(o,s)}function t2(e,t){const n=Math.round(e*10)/10,s=Number.isInteger(n)?String(n):n.toFixed(1);return t!==void 0?`${s}${t}`:s}var SU={plain:'fill="var(--paper)" stroke="var(--ink)" stroke-width="1"',accent:'fill="var(--accent-tint)" stroke="var(--accent)" stroke-width="1.5"',negative:'fill="var(--negative-tint)" stroke="var(--negative)" stroke-width="1.5"'};function EU(e){const t=e.items.map((h,m)=>({item:h,index:m})).filter(h=>h.item.value>0).sort((h,m)=>m.item.value-h.item.value),n=t.reduce((h,m)=>h+m.item.value,0);let s=`<svg viewBox="0 0 ${lp} ${cp}" role="img"><title>${S(e.title??"Treemap")}</title>`;if(t.length===0||n<=0)return s+=`<rect x="0" y="0" width="${lp}" height="${cp}" rx="8" fill="var(--paper)" stroke="var(--rule-solid)"/></svg>`,n2(e,s,"");const o=t.map(h=>({item:h.item,index:h.index,x:0,y:0,w:0,h:0})),r=lp*cp/n;$U(o,t.map(h=>h.item.value*r),{x:0,y:0,w:lp,h:cp});const i=Xn(t.map(h=>h.item.accent)),l=i.includes("focal"),d=(h,m)=>{const g=i[m];return g==="negative"?"negative":g==="focal"||!l&&m===0?"accent":"plain"},u=new Set;s+=`<g${he("items")}>`,o.forEach((h,m)=>{const g=h.x+dp/2,v=h.y+dp/2,y=Math.max(0,h.w-dp),b=Math.max(0,h.h-dp);if(y<2||b<2)return;const E=d(h,m);u.add(E);const $=Math.round(h.item.value/n*100),A=E==="accent"?"t-name c-accent":E==="negative"?"t-name c-negative":"t-name";if(s+=`<g${_(`items.${h.index}`)}>`,E!=="plain"&&(s+=`<rect x="${os(g)}" y="${os(v)}" width="${os(y)}" height="${os(b)}" rx="3" fill="var(--paper)"/>`),s+=`<rect x="${os(g)}" y="${os(v)}" width="${os(y)}" height="${os(b)}" rx="3" ${SU[E]}/>`,y>=58&&b>=30){const T=Math.max(6,Math.floor(y/7.4)),N=lt(h.item.label,T,b>=58?2:1);N.forEach((P,I)=>{s+=`<text x="${os(g+9)}" y="${os(v+20+I*15)}" class="${A}">${S(P)}</text>`});const j=v+20+N.length*15;b>=48&&(s+=`<text x="${os(g+9)}" y="${os(j+1)}" class="t-sub c-muted">${S(t2(h.item.value,e.unit))} · ${$}%</text>`),h.item.desc!==void 0&&b>=74&&(s+=`<text x="${os(g+9)}" y="${os(j+16)}" class="t-sub c-soft">${S(h.item.desc)}</text>`)}s+=`<title>${S(`${h.item.label}: ${t2(h.item.value,e.unit)} (${$}%)`)}</title>`,s+="</g>"}),s+="</g></svg>";const p=[];return u.has("plain")&&p.push({swatch:"node",label:"item (area = value)"}),u.has("accent")&&p.push({swatch:"node-accent",label:l?"focal item":"largest item"}),u.has("negative")&&p.push({swatch:"fill",fill:"var(--negative-tint)",label:"negative"}),n2(e,s,ot(p))}function os(e){return Math.round(e*10)/10}function n2(e,t,n){return ct({tag:"TREEMAP",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...n.length>0?{legendHtml:n}:{}},t)}var s2=["var(--paper)","var(--paper-2)"];function MU(e,t){return e==="red"?{fill:"var(--negative-tint)",stroke:"var(--negative)"}:e==="gray"?{fill:"var(--paper-2)",stroke:"var(--rule-solid)"}:e!==void 0?{fill:"var(--accent-tint)",stroke:"var(--accent)"}:{fill:s2[t%s2.length]??"var(--paper)",stroke:"var(--ink)"}}var dv=34,AU=8,uv=26,Ta=46,o2=880;function CU(e){const t=e.width!==void 0&&e.width>0?Math.floor(e.width):32,n=[];let s=0;e.fields.forEach((h,m)=>{let g=Math.max(0,Math.floor(h.bits)),v=!0;for(;g>0;){const y=Math.floor(s/t),b=s%t,E=Math.min(g,t-b);n.push({label:h.label,value:h.value,paint:MU(h.accent,m),index:m,row:y,from:b,bits:E,cut:E<g,cont:!v}),s+=E,g-=E,v=!1}});const o=Math.max(1,Math.ceil(s/t)||1),r=uv+o*Ta+10,i=(o2-dv-AU)/t,l=h=>dv+h*i;let d=`<svg viewBox="0 0 ${o2} ${r}" role="img"><title>${S(e.title??"Packet layout")}</title>`;d+="<g>";for(let h=0;h<=t;h+=1){const m=l(h),g=h%8===0;d+=`<line x1="${ms(m)}" y1="${g?10:15}" x2="${ms(m)}" y2="20" stroke="var(--rule)" stroke-width="1"${ut}/>`,g&&h<t&&(d+=`<text x="${ms(m+2)}" y="8" class="pk-tick">${h}</text>`)}d+="</g>",d+=`<g${he("fields")}>`,n.forEach(h=>{const m=l(h.from),g=h.bits*i,v=uv+h.row*Ta;d+=`<g${_(`fields.${h.index}`)}>`,d+=`<rect x="${ms(m+1)}" y="${ms(v+2)}" width="${ms(g-2)}" height="${Ta-6}" rx="3" fill="${h.paint.fill}" stroke="${h.paint.stroke}" stroke-width="1"/>`;const y=m+g/2;if(g>=46){const b=h.cont?" (cont.)":h.cut?" →":"";d+=`<text x="${ms(y)}" y="${ms(v+(h.value!==void 0&&g>=80?17:24))}" class="pk-name">${S(h.label+b)}</text>`,h.value!==void 0&&g>=80&&(d+=`<text x="${ms(y)}" y="${ms(v+28)}" class="pk-value">${S(h.value)}</text>`)}d+=`<text x="${ms(y)}" y="${ms(v+Ta-8)}" class="pk-bits">${h.bits}</text>`,d+=`<title>${S(`${h.label} — ${h.bits} bit${h.bits===1?"":"s"} at offset ${h.row*t+h.from}`)}</title>`,d+="</g>"}),d+="</g>";for(let h=0;h<o;h++)d+=`<text x="${dv-8}" y="${ms(uv+h*Ta+Ta/2)}" class="pk-off">${h*t}</text>`;d+="</svg>";const u=s,p=`<p class="pk-total">${u} bits · ${Math.round(u/8*10)/10} bytes`+(u%t!==0?` · last row is ${u%t} of ${t} bits`:"")+"</p>";return ct({tag:"PACKET",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},footerHtml:p},d)}function ms(e){return Math.round(e*10)/10}function NU(e){return e==="negative"?"negative":e==="focal"?"accent":"plain"}var TU={plain:'fill="var(--ink)" fill-opacity="0.06" stroke="var(--ink)" stroke-width="1.5"',accent:'fill="var(--accent-tint)" stroke="var(--accent)" stroke-width="1.5"',negative:'fill="var(--negative-tint)" stroke="var(--negative)" stroke-width="1.5"'},_U={plain:"t-name",accent:"t-name c-accent",negative:"t-name c-negative"},LU=620;function IU(e){return e<=2?{height:340,radius:132,circles:[{cx:240,cy:176},{cx:380,cy:176}],own:[{x:178,y:176},{x:442,y:176}],pairs:[{of:[0,1],x:310,y:176}],centre:{x:310,y:176}}:{height:396,radius:118,circles:[{cx:250,cy:158},{cx:370,cy:158},{cx:310,cy:258}],own:[{x:196,y:126},{x:424,y:126},{x:310,y:316}],pairs:[{of:[0,1],x:310,y:132},{of:[0,2],x:264,y:226},{of:[1,2],x:356,y:226}],centre:{x:310,y:202}}}function jU(e){const t=e.sets.slice(0,3),n=IU(t.length),s=Xn(t.map(p=>p.accent)),o=p=>NU(s[p]);let r=`<svg viewBox="0 0 ${LU} ${n.height}" role="img"><title>${S(e.title??"Venn")}</title>`;r+=`<g${he("sets")}>`,t.forEach((p,h)=>{const m=n.circles[h];m!==void 0&&(r+=`<g${_(`sets.${h}`)}>`,r+=`<circle cx="${m.cx}" cy="${m.cy}" r="${n.radius}" ${TU[o(h)]}/>`,r+="</g>")}),r+="</g>",t.forEach((p,h)=>{const m=n.own[h];if(m===void 0)return;const g=lt(p.label,14,2);if(g.forEach((v,y)=>{r+=`<text x="${m.x}" y="${m.y-(g.length-1)*8+y*16}" class="${_U[o(h)]}" text-anchor="middle">${S(v)}</text>`}),p.desc!==void 0){const v=m.y-(g.length-1)*8+g.length*16+2;lt(p.desc,18,2).forEach((y,b)=>{r+=`<text x="${m.x}" y="${v+b*13}" class="t-sub c-muted" text-anchor="middle">${S(y)}</text>`})}});const i=new Map(t.map((p,h)=>[p.label.toLowerCase(),h]));let l=!1;r+=`<g${he("shared")}>`,(e.shared??[]).forEach((p,h)=>{const m=p.sets.map(y=>i.get(y.toLowerCase())).filter(y=>y!==void 0).sort((y,b)=>y-b);if(m.length<2)return;const g=m.length>=3?n.centre:n.pairs.find(y=>y.of.length===m.length&&y.of.every((b,E)=>b===m[E]));if(g===void 0)return;l=!0;const v=lt(p.label,t.length>2?12:16,2);v.forEach((y,b)=>{r+=`<text x="${g.x}" y="${g.y-(v.length-1)*7+b*14}" class="t-name" text-anchor="middle"${b===0?_(`shared.${h}`):""}>${S(y)}</text>`})}),r+="</g></svg>";const d=[];t.some((p,h)=>o(h)==="plain")&&d.push({swatch:"node",label:"set"}),t.some((p,h)=>o(h)==="accent")&&d.push({swatch:"node-accent",label:"focal set"}),t.some((p,h)=>o(h)==="negative")&&d.push({swatch:"fill",fill:"var(--negative-tint)",label:"negative set"}),l&&d.push({swatch:"node-fill2",label:"overlap (darker = shared)"});const u=ot(d);return ct({tag:"VENN",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...u.length>0?{legendHtml:u}:{}},r)}var r2=880,i2=420,PU=96,OU=20,RU=18,DU=52,a2=[{at:0,label:"Genesis"},{at:.25,label:"Custom-built"},{at:.5,label:"Product"},{at:.75,label:"Commodity"}],BU={user:'fill="var(--ink)" stroke="var(--ink)" stroke-width="1.5"',component:'fill="var(--paper)" stroke="var(--ink)" stroke-width="1.5"',commodity:'fill="var(--paper-2)" stroke="var(--rule-solid)" stroke-width="1.5"',build:'fill="var(--accent-tint)" stroke="var(--accent)" stroke-width="1.75"',buy:'fill="var(--paper)" stroke="var(--ink)" stroke-width="1.25" stroke-dasharray="3 2"'},zU={user:{swatch:"node-dot",fill:"var(--ink)",label:"user"},component:{swatch:"node-dot",label:"component"},commodity:{swatch:"node-dot",fill:"var(--paper-2)",stroke:"var(--rule-solid)",label:"commodity"},build:{swatch:"node-dot",fill:"var(--accent-tint)",stroke:"var(--accent)",label:"build"},buy:{swatch:"node-dot",dash:"3 2",label:"buy"}};function FU(e){const t=PU,n=r2-OU,s=RU,o=i2-DU,r=v=>t+(n-t)*pv(v),i=v=>o-(o-s)*pv(v);let l=`<svg viewBox="0 0 ${r2} ${i2}" role="img"><title>${S(e.title??"Wardley map")}</title>`;l+=`<rect x="${t}" y="${s}" width="${n-t}" height="${o-s}" fill="var(--paper)" stroke="var(--rule-solid)" stroke-width="1"/>`,a2.forEach((v,y)=>{const b=r(v.at);y>0&&(l+=`<line x1="${pn(b)}" y1="${s}" x2="${pn(b)}" y2="${o}" stroke="var(--rule-solid)" stroke-width="1" stroke-dasharray="3 4"/>`);const E=a2[y+1]?.at??1;l+=`<text x="${pn((b+r(E))/2)}" y="${o+20}" class="t-eyebrow" text-anchor="middle">${S(v.label.toUpperCase())}</text>`}),l+=`<text x="${pn((t+n)/2)}" y="${o+38}" class="t-eyebrow c-muted" text-anchor="middle">EVOLUTION →</text>`,l+=`<text x="18" y="${pn((s+o)/2)}" class="t-eyebrow c-muted" text-anchor="middle" transform="rotate(-90 18 ${pn((s+o)/2)})">VISIBLE TO THE USER →</text>`;const d=new Map(e.components.map(v=>[v.id??v.label,{x:r(v.x),y:i(v.y)}]));let u=!1;l+=`<g${he("links")}>`,(e.links??[]).forEach((v,y)=>{const b=d.get(v.from),E=d.get(v.to);b===void 0||E===void 0||(u=!0,l+=`<line x1="${pn(b.x)}" y1="${pn(b.y)}" x2="${pn(E.x)}" y2="${pn(E.y)}" stroke="var(--muted)" stroke-width="1.25"${_(`links.${y}`)}/>`,v.label!==void 0&&(l+=`<text x="${pn((b.x+E.x)/2)}" y="${pn((b.y+E.y)/2-5)}" class="t-arrow" text-anchor="middle">${S(v.label)}</text>`))}),l+="</g>";const p=new Set;let h=!1;l+=`<g${he("components")}>`,e.components.forEach((v,y)=>{const b=d.get(v.id??v.label);if(b===void 0)return;const E=v.kind??"component";if(p.add(E),l+=`<g${_(`components.${y}`)}>`,v.movement!==void 0&&v.movement!==0){h=!0;const N=r(pv(v.x)+v.movement);l+=`<line x1="${pn(b.x)}" y1="${pn(b.y)}" x2="${pn(N)}" y2="${pn(b.y)}" stroke="var(--muted)" stroke-width="1.5" stroke-dasharray="4 3" marker-end="url(#skOpen)"/>`}l+=`<circle cx="${pn(b.x)}" cy="${pn(b.y)}" r="7" ${BU[E]}/>`;const $=b.y-14>s+12,A=lt(v.label,18,2),T=E==="build"?"t-name c-accent":"t-name";A.forEach((N,j)=>{const P=$?b.y-14-(A.length-1-j)*14:b.y+22+j*14;l+=`<text x="${pn(b.x)}" y="${pn(P)}" class="${T}" text-anchor="middle">${S(N)}</text>`}),l+="</g>"}),l+="</g></svg>";const m=["user","component","commodity","build","buy"].filter(v=>p.has(v)).map(v=>zU[v]);u&&m.push({swatch:"line",label:"depends on"}),h&&m.push({swatch:"edge-dashed",label:"movement"});const g=ot(m);return ct({tag:"WARDLEY",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...g.length>0?{legendHtml:g}:{}},l)}function pv(e){return Math.min(1,Math.max(0,e))}function pn(e){return Math.round(e*10)/10}var Ci=4,vn=9;function fv(e){const t=Math.max(0,Math.min(Ci,Math.round(e))),n=`<svg width="${vn*2+2}" height="${vn*2+2}" viewBox="0 0 ${vn*2+2} ${vn*2+2}" role="img" aria-label="${t} of ${Ci}">`,s=`<circle cx="${vn+1}" cy="${vn+1}" r="${vn}" fill="var(--white)" stroke="var(--navy)" stroke-width="1.4"/>`;if(t===0)return`${n}${s}</svg>`;if(t===Ci)return`${n}${s}<circle cx="${vn+1}" cy="${vn+1}" r="${vn}" fill="var(--navy)"/></svg>`;const o=t/Ci*360,r=(o-90)*Math.PI/180,i=vn+1+vn*Math.cos(r),l=vn+1+vn*Math.sin(r),d=o>180?1:0,u=`<path d="M ${vn+1} ${vn+1} L ${vn+1} 1 A ${vn} ${vn} 0 ${d} 1 ${N0(i)} ${N0(l)} Z" fill="var(--navy)"/>`;return`${n}${s}${u}</svg>`}function N0(e){return Math.round(e*10)/10}function qU(e){const t=e.columns,n=t.map((g,v)=>e.rows.reduce((y,b)=>y+(b.ratings[v]??0)*(b.weight??1),0)),s=Math.max(...n,0),o=e.recommend?.toLowerCase(),r=t.map((g,v)=>{const y=o!==void 0&&g.toLowerCase()===o,b=y?'<span class="hv-rec">RECOMMENDED</span>':"";return`<th class="hv-col${y?" hv-is-rec":""}"${_(`columns.${v}`)}>${S(g)}${b}</th>`}).join(""),i=e.rows.map((g,v)=>{const y=g.weight!==void 0&&g.weight!==1?`<span class="hv-weight"${_(`rows.${v}.weight`)}>×${S(String(g.weight))}</span>`:"",b=g.note!==void 0?`<span class="hv-note"${_(`rows.${v}.note`)}>${S(g.note)}</span>`:"",E=t.map(($,A)=>{const T=o!==void 0&&$.toLowerCase()===o,N=g.ratings[A],j=N===void 0?'<span class="hv-na">—</span>':`${fv(N)}<span class="hv-sr">${Math.max(0,Math.min(Ci,Math.round(N)))} of ${Ci}</span>`;return`<td class="hv-cell${T?" hv-is-rec":""}"${_(`rows.${v}.ratings.${A}`)}>${j}</td>`}).join("");return`<tr${_(`rows.${v}`)}><td class="hv-crit"><span class="hv-label"${_(`rows.${v}.label`)}>${S(g.label)}</span>${y}${b}</td>${E}</tr>`}).join(""),l=`<tr class="hv-foot"><td>Weighted</td>${n.map((g,v)=>{const y=o!==void 0&&t[v]?.toLowerCase()===o,b=g===s&&s>0;return`<td class="hv-total${y?" hv-is-rec":""}${b?" hv-lead":""}">${N0(g)}</td>`}).join("")}</tr>`,[d,u]=e.scale??[],p=d!==void 0&&u!==void 0?`<div class="diagram-legend hv-scale"><span class="lg-title t-eyebrow">Legend</span><span class="lg-item">${fv(0)}<span class="lg-label">${S(d)}</span></span><span class="lg-item">${fv(Ci)}<span class="lg-label">${S(u)}</span></span></div>`:"",h=e.title!==void 0?`<div class="hv-head">${S(e.title)}</div>`:"",m=e.description!==void 0?`<p class="hv-desc"${_("description")}>${S(e.description)}</p>`:"";return`<div class="harvey">${h}${m}<div class="hv-scroll"><table class="hv-table"><thead><tr${he("columns")}><th class="hv-crit">Criteria</th>${r}</tr></thead><tbody${he("rows")}>${i}${l}</tbody></table>${p}</div></div>`}var HU=[{key:"situation",label:"Situation",hint:"what everyone already agrees on"},{key:"complication",label:"Complication",hint:"what changed"},{key:"question",label:"Question",hint:"what has to be settled"}];function WU(e){const t=HU.filter(i=>typeof e[i.key]=="string"&&e[i.key]!=="").map((i,l)=>{const d=e[i.key];return`<div class="sq-row"${_(i.key)}><span class="sq-num">${l+1}</span><div class="sq-body"><span class="sq-label">${S(i.label)}</span><p class="sq-text">${vo(d)}</p></div></div>`}).join(""),n=e.because!==void 0&&e.because.length>0?`<ul class="sq-because"${he("because")}>`+e.because.map((i,l)=>`<li${_(`because.${l}`)}>${vo(i)}</li>`).join("")+"</ul>":"",s=typeof e.answer=="string"&&e.answer!==""?`<div class="sq-answer"${_("answer")}><span class="sq-label sq-label-answer">Answer</span><p class="sq-text sq-text-answer">${vo(e.answer)}</p>${n}</div>`:"",o=e.title!==void 0?`<div class="sq-head">${S(e.title)}</div>`:"",r=e.description!==void 0?`<p class="sq-desc"${_("description")}>${S(e.description)}</p>`:"";return`<div class="scqa">${o}${r}${t}${s}</div>`}var hv={pos:"sc-pos",neg:"sc-neg",base:"sc-base"};function UU(e){const t=e.cases,n=t.map((d,u)=>{const p=d.tone!==void 0?` ${hv[d.tone]??""}`:"",h=d.tone==="base"?'<span class="sn-badge">BASE CASE</span>':"",m=d.note!==void 0?`<span class="sn-note">${S(d.note)}</span>`:"";return`<th class="sn-case${p}"${_(`cases.${u}`)}>${S(d.label)}${h}${m}</th>`}).join(""),s=e.drivers.map((d,u)=>{const p=t.map((h,m)=>{const g=h.tone!==void 0?` ${hv[h.tone]??""}`:"",v=h.values[u];return v===void 0?`<td class="sn-cell sn-blank${g}">·</td>`:`<td class="sn-cell${g}"${_(`cases.${m}.values.${u}`)}>${S(v)}</td>`}).join("");return`<tr><td class="sn-driver"${_(`drivers.${u}`)}>${S(d)}</td>${p}</tr>`}).join(""),r=t.some(d=>d.outcome!==void 0)?`<tr class="sn-outcome"><td>${S(e.outcomeLabel??"Outcome")}</td>`+t.map((d,u)=>{const p=d.tone!==void 0?` ${hv[d.tone]??""}`:"";return d.outcome===void 0?`<td class="${p.trim()}">—</td>`:`<td class="${p.trim()}"${_(`cases.${u}.outcome`)}>${S(d.outcome)}</td>`}).join("")+"</tr>":"",i=e.title!==void 0?`<div class="sn-head">${S(e.title)}</div>`:"",l=e.description!==void 0?`<p class="sn-desc"${_("description")}>${S(e.description)}</p>`:"";return`<div class="scenarios">${i}${l}<div class="sn-scroll"><table class="sn-table"><thead><tr${he("cases")}><th class="sn-driver">Driver</th>${n}</tr></thead><tbody${he("drivers")}>${s}${r}</tbody></table></div></div>`}var up=Math.tan(62*Math.PI/180),l2=64,KU=28,Mr=26;function mv(e,t,n){const s=lt(e,t,n),o=s.join(" "),r=String(e).trim().split(/\s+/).join(" "),i=o!==r&&s.length>0;if(i){const l=s[s.length-1]??"";s[s.length-1]=`${l}…`}return{lines:s,truncated:i}}var gv=(e,t)=>e.truncated?`<title>${S(t)}</title>`:"",vv=e=>Math.max(0,...e.map(t=>t.length));function VU(e){const t=e.causes.map((X,B)=>{const te=mv(X.label,16,4),ee=(X.items??[]).map(R=>{const z=mv(R,24,2);return{full:R,clamped:z,w:vv(z.lines)*6.2}}),W=14+Math.max(1,...ee.map(R=>R.clamped.lines.length))*13,K=ee.length>0?52+(ee.length-1)*W:l2;return{idx:B,label:X.label,labelClamped:te,labelW:vv(te.lines)*7.4,items:ee,gap:W,needH:K}}),n=t.filter(X=>X.idx%2===0),s=t.filter(X=>X.idx%2===1),o=X=>X.length===0?0:Math.max(l2,...X.map(B=>B.needH)),r=o(n),i=o(s),l=X=>X.length===0?0:Math.max(...X.map(B=>B.labelClamped.lines.length))*15+12,d=l(n),u=l(s),p=(X,B)=>{let te=B/up+X.labelW/2+4;return X.items.forEach((ee,H)=>{const W=B-(26+H*X.gap);te=Math.max(te,W/up+10+ee.w)}),Math.max(te,40)},h=(X,B,te)=>{const ee=[];let H=te;return X.forEach((W,K)=>{const R=H+(K===0?0:KU)+p(W,B);ee.push(R),H=R}),ee},m=h(n,r,Mr),g=h(s,i,Mr+44),v=mv(e.effect,16,3),y=v.lines,b=Math.max(96,vv(y)*7.4+28),E=y.length*16+18,$=Math.max(Mr+d+r,Mr+E/2+4),A=Math.max($+i+u,$+E/2+4)+Mr,N=Math.max(Mr+40,...m,...g)+30+6,j=N+b+Mr,P=X=>X.toFixed(1);let I=`<svg viewBox="0 0 ${P(j)} ${P(A)}" width="${P(j)}" height="${P(A)}" role="img"><title>Fishbone</title>`;I+=`<path d="M ${Mr} ${P($)} L ${P(N)} ${P($)}" fill="none" stroke="var(--ink)" stroke-width="1.5"/>`;let O=!1;const C=(X,B,te,ee)=>{const H=B-te/up,W=$+ee*te;let K=`<g${_(`causes.${X.idx}`)}>`;K+=`<path d="M ${P(B)} ${P($)} L ${P(H)} ${P(W)}" fill="none" stroke="var(--ink)" stroke-width="1.25"/>`;const R=15,z=X.labelClamped.lines.length,Y=ee===-1?W-10-(z-1)*R:W+20;return K+=`<g${_(`causes.${X.idx}.label`)}>${gv(X.labelClamped,X.label)}`,X.labelClamped.lines.forEach((V,re)=>{K+=`<text x="${P(H)}" y="${P(Y+re*R)}" class="t-name" text-anchor="middle">${S(V)}</text>`}),K+="</g>",X.items.length>0&&(O=!0,K+=`<g${he(`causes.${X.idx}.items`)}>`,X.items.forEach((V,re)=>{const Q=te-(26+re*X.gap),ne=$+ee*Q,Z=B-Q/up;let q=`<g${_(`causes.${X.idx}.items.${re}`)}>${gv(V.clamped,V.full)}`;q+=`<path d="M ${P(Z-6)} ${P(ne)} L ${P(Z)} ${P(ne)}" stroke="var(--muted)" stroke-width="1.25"/>`;const de=V.clamped.lines.length;V.clamped.lines.forEach((le,J)=>{q+=`<text x="${P(Z-10)}" y="${P(ne+3.5-(de-1)*13/2+J*13)}" class="t-sub c-ink" text-anchor="end">${S(le)}</text>`}),K+=q+"</g>"}),K+="</g>"),K+"</g>"};I+=`<g${he("causes")}>`,n.forEach((X,B)=>{const te=m[B];te!==void 0&&(I+=C(X,te,r,-1))}),s.forEach((X,B)=>{const te=g[B];te!==void 0&&(I+=C(X,te,i,1))}),I+="</g>";const D=$-E/2;I+=`<g${_("effect")}>${gv(v,e.effect)}`,I+=`<rect x="${P(N)}" y="${P(D)}" width="${P(b)}" height="${P(E)}" rx="4" fill="var(--accent-tint)" stroke="var(--accent)" stroke-width="1.5"/>`,y.forEach((X,B)=>{I+=`<text x="${P(N+b/2)}" y="${P($+4.5-(y.length-1)*16/2+B*16)}" class="t-name c-accent" text-anchor="middle">${S(X)}</text>`}),I+="</g></svg>";const F=[{swatch:"node-accent",label:"effect"}];F.push({swatch:"chip",chip:"BONE",label:"cause category"}),O&&F.push({swatch:"chip",chip:"—",label:"specific cause"});const U=ot(F);return ct({tag:"FISHBONE",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...U.length>0?{legendHtml:U}:{}},I)}var GU=170,YU=128,c2=40;function XU(e){return typeof e=="string"?{title:e}:e}function QU(e){const t=e.backbone.length,n=YU+t*GU;let s=`<div class="sm-row sm-head"${he("backbone")} style="min-width:${n}px">`;s+='<div class="sm-gutter"></div>',e.backbone.forEach((i,l)=>{const d=i.label.length>c2;s+=`<div class="sm-colcell"><div class="sm-step"${_(`backbone.${l}`)}${d?` title="${S(i.label)}"`:""}>`,s+=`<span class="t-eyebrow sm-step-eyebrow">Step ${l+1}</span>`,s+=`<div class="sm-step-label t-name"${_(`backbone.${l}.label`)}>${S(i.label)}</div>`,i.note!==void 0&&(s+=`<div class="sm-step-note">${S(i.note)}</div>`),s+="</div></div>"}),s+="</div>";let o=`<div${he("slices")}>`;e.slices.forEach((i,l)=>{o+=`<div class="sm-row sm-band${l===0?" sm-band-first":""}"${_(`slices.${l}`)} style="min-width:${n}px">`,o+=`<div class="sm-gutter sm-slice"${_(`slices.${l}.label`)}>${S(i.label)}</div>`,i.cells.forEach((d,u)=>{o+=`<div class="sm-colcell sm-cell"${he(`slices.${l}.cells.${u}`)}>`,d.forEach((p,h)=>{const m=XU(p),g=m.title.length>c2;o+=`<div class="sm-card"${_(`slices.${l}.cells.${u}.${h}`)}${g?` title="${S(m.title)}"`:""}>`,o+=`<div class="sm-card-title">${S(m.title)}</div>`,m.tag!==void 0&&(o+=`<span class="sm-card-tag">${S(m.tag)}</span>`),o+="</div>"}),o+="</div>"}),o+="</div>"}),o+="</div>";const r=`<div class="storymap"><div class="sm-scroll">${s}${o}</div></div>`;return ct({tag:"STORY MAP",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{}},r)}function ZU(e,t){return`<span class="evc-chip"${_(t)}>${S(e)}</span>`}function d2(e,t,n){const s=n.length>0?n.map((o,r)=>ZU(o,`${t}.${r}`)).join(""):'<span class="evc-none t-sub">—</span>';return`<div class="evc-party"><span class="evc-party-label t-eyebrow">${S(e)}${n.length>0?` (${n.length})`:""}</span><div class="evc-chips"${he(t)}>${s}</div></div>`}function pp(e,t,n){return`<span class="evc-fact"${_(n)}><span class="evc-fact-k t-eyebrow">${S(e)}</span><span class="evc-fact-v">${S(t)}</span></span>`}function u2(e,t,n){const s=e.map((o,r)=>{const i=n!==void 0&&o.name===n,l=i?"#":o.required===!0?"":"?",d=i?' class="evc-key"':"",u=o.example!==void 0?` <span class="evc-eg">e.g. ${S(o.example)}</span>`:"";return`<tr${d}${_(`${t}.${r}`)}><td class="evc-mark">${l}</td><td class="evc-fname"${_(`${t}.${r}.name`)}>${S(o.name)}</td><td class="evc-type"${_(`${t}.${r}.type`)}>${S(o.type)}</td><td class="evc-desc"><span${_(`${t}.${r}.desc`)}>${S(o.desc??"")}</span>${u}</td></tr>`}).join("");return`<table class="evc-table"><thead><tr><th></th><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody${he(t)}>${s}</tbody></table>`}function JU(e){const n='<div class="evc-head">'+('<span class="evc-eyebrow t-eyebrow">EVENT'+(e.version!==void 0?`<span class="evc-sep">·</span><span${_("version")}>${S(e.version)}</span>`:"")+"</span>")+`<span class="evc-name"${_("name")}>${S(e.name)}</span>`+(e.channel!==void 0?`<span class="evc-channel"${_("channel")}><span class="t-eyebrow">channel</span>${S(e.channel)}</span>`:"")+"</div>",s=[];e.title!==void 0&&s.push(`<div class="evc-title">${S(e.title)}</div>`),e.summary!==void 0&&s.push(`<p class="evc-summary"${_("summary")}>${S(e.summary)}</p>`),e.description!==void 0&&s.push(`<p class="evc-desc-p">${S(e.description)}</p>`);const o=e.producers??[],r=e.consumers??[];(o.length>0||r.length>0)&&s.push('<div class="evc-strip">'+d2("Producers","producers",o)+'<span class="evc-arrow t-arrow" aria-hidden="true">→</span>'+d2("Consumers","consumers",r)+"</div>");const i=[];e.delivery!==void 0&&i.push(pp("delivery",e.delivery,"delivery")),e.ordering!==void 0&&i.push(pp("ordering",e.ordering,"ordering")),e.key!==void 0&&i.push(pp("key",e.key,"key")),e.retention!==void 0&&i.push(pp("retention",e.retention,"retention")),i.length>0&&s.push(`<div class="evc-facts">${i.join("")}</div>`);const l=e.schema??[];if(l.length>0){const p=e.key!==void 0&&l.some(g=>g.name===e.key),h=l.some(g=>g.required!==!0&&!(p&&g.name===e.key)),m=[];p&&m.push('<span class="evc-mark-k">#</span> partition key'),h&&m.push('<span class="evc-mark-k">?</span> optional'),s.push('<div class="evc-section">Payload</div>'+u2(l,"schema",e.key)+(m.length>0?`<div class="evc-keyline t-sub">${m.join(" · ")}</div>`:""))}const d=e.headers??[];d.length>0&&s.push(`<div class="evc-section">Headers</div>${u2(d,"headers",void 0)}`),e.example!==void 0&&s.push(`<div class="evc-section">Example</div><pre class="ep-ex"${_("example")}>${Sf(e.example)}</pre>`);const u=e.errors??[];if(u.length>0){const p=u.map((h,m)=>`<tr${_(`errors.${m}`)}><td class="evc-fname"${_(`errors.${m}.name`)}>${S(h.name)}</td><td class="evc-desc"${_(`errors.${m}.when`)}>${S(h.when??"")}</td></tr>`).join("");s.push(`<div class="evc-section">Errors</div><table class="evc-table"><thead><tr><th>Error</th><th>When</th></tr></thead><tbody${he("errors")}>${p}</tbody></table>`)}return e.note!==void 0&&s.push(`<p class="evc-note"${_("note")}>${S(e.note)}</p>`),`<div class="eventcontract">${n}<div class="evc-body">${s.join("")}</div></div>`}var vc=22,yv=22,eK=18,tK=176,yc=44,xc=34,nK=36,sK=34,p2=22,oK=28,fp=7.4,rK=6,Kp=6.3,xv={ok:"",failed:"FAILED",skipped:"SKIPPED",compensated:"COMPENSATED"},kv="ORCHESTRATOR",iK="COMPENSATE",LA=e=>e==="accent"?" c-accent":e==="negative"?" c-negative":"";function f2(e,t,n,s,o){const r=Math.round(n.length*Kp+10),i=o?e-r:e,l=s==="accent"?"var(--accent)":s==="negative"?"var(--negative)":"var(--rule-solid)";return`<rect x="${i}" y="${t-8}" width="${r}" height="15" rx="2" fill="var(--paper)" stroke="${l}" stroke-width="1"/><text x="${i+r/2}" y="${t+3.5}" class="t-eyebrow${LA(s)}" text-anchor="middle">${S(n)}</text>`}var bv=e=>Math.max(0,...e.map(t=>t.length));function aK(e,t){return e.map((n,s)=>n.status!==void 0?n.status:t<0?"ok":s<t?"compensated":s===t?"failed":"skipped")}function lK(e){const t=e.steps,n=t.length,s=e.mode==="orchestration",o=e.coordinator??"Orchestrator",r=e.failAt!==void 0?t.findIndex(z=>z.id===e.failAt):t.findIndex(z=>z.status==="failed"),i=aK(t,r),l=t.map(z=>lt(z.name,p2,3)),d=t.map(z=>z.action!==void 0?lt(z.action,oK,2):[]),u=t.map(z=>z.compensate!==void 0?lt(z.compensate,p2,3):[]),p=Math.max(1,...l.map(z=>z.length)),h=Math.max(0,...d.map(z=>z.length)),m=Math.max(0,...u.map(z=>z.length)),g=m>0,v=30+p*15+(h>0?h*13+4:0)+8,y=22+m*15+8,b=[tK];t.forEach((z,Y)=>{const V=xv[i[Y]??"ok"],re=V.length>0?V.length*Kp+10+8:0;b.push(34+z.service.length*Kp+8+re+10),b.push(bv(l[Y]??[])*fp+24),b.push(bv(d[Y]??[])*rK+24),b.push(bv(u[Y]??[])*fp+24)});let E=Math.ceil(Math.max(...b));if(s){const z=14+o.length*fp+12+kv.length*Kp+10+14,Y=n*E+(n-1)*yc;z>Y&&(E=Math.ceil((z-(n-1)*yc)/n))}const $=z=>vc+z*(E+yc),A=z=>$(z)+E/2,T=yv,N=s?yv+xc+nK:yv,j=N+v/2,P=N+v+sK,I=P+y/2,O=vc*2+n*E+(n-1)*yc,C=(g?P+y:N+v)+eK,D=[];if(r>0&&g)for(let z=r-1;z>=0;z--)(u[z]??[]).length>0&&D.push(z);const F=z=>z,U=z=>{const Y=D.indexOf(z);return Y<0?z:n+Y},X=Sn("Saga",e.title,[wt(n,"step"),...u.filter(z=>z.length>0).length>0?[wt(u.filter(z=>z.length>0).length,"compensation")]:[]]);let B=`<svg viewBox="0 0 ${O} ${C}"${X.attrs}>${X.title}`;if(s){const z=vc+14,Y=z+o.length*fp+12;B+=`<g${_("coordinator")}><rect x="${vc}" y="${T}" width="${O-vc*2}" height="${xc}" rx="4" fill="var(--paper-2)" stroke="var(--rule-solid)" stroke-width="1"/><text x="${z}" y="${T+xc/2+4.5}" class="t-name">${S(o)}</text>`+f2(Y,T+xc/2,kv,"muted",!1)+"</g>",B+='<g class="sg-fanout">';for(let V=0;V<n;V++)B+=`<line x1="${A(V)}" y1="${T+xc}" x2="${A(V)}" y2="${N}" stroke="var(--muted)" stroke-width="1.25" marker-end="url(#skArrow)"${hn(F(V))}/>`;B+="</g>"}let te=!1,ee=!1;B+='<g class="sg-forward">';for(let z=0;z<n-1;z++){const Y=r>=0&&z>=r;Y?ee=!0:te=!0;const V=Y?' stroke-dasharray="5 4"':"",re=Y?"skOpen":"skArrow";B+=`<line x1="${$(z)+E}" y1="${j}" x2="${$(z+1)}" y2="${j}" stroke="var(--muted)" stroke-width="1.5"${V} marker-end="url(#${re})"${hn(F(z+1))}/>`}B+="</g>";const H=new Set;B+=`<g${he("steps")}>`,t.forEach((z,Y)=>{const V=i[Y]??"ok";H.add(V);const re=$(Y),Q=Y===r,ne=V==="failed",Z=V==="skipped",q=Q?"var(--accent)":ne?"var(--negative)":Z?"var(--rule-solid)":"var(--ink)",de=Q?"var(--accent-tint)":ne?"var(--negative-tint)":Z?"var(--paper-2)":"var(--paper)",le=Z?1:1.5,J=Q?"accent":ne?"negative":"muted",ue=LA(J),ve=N+16;let we=`<rect x="${re}" y="${N}" width="${E}" height="${v}" rx="4" fill="${de}" stroke="${q}" stroke-width="${le}"/><circle cx="${re+19}" cy="${ve}" r="7" fill="var(--paper)" stroke="${Q?"var(--accent)":"var(--muted)"}" stroke-width="1"/><text x="${re+19}" y="${ve+3}" class="t-badge${ue}" text-anchor="middle">${Y+1}</text><text x="${re+34}" y="${ve+3}" class="t-eyebrow${ue}"${_(`steps.${Y}.service`)}>${S(z.service)}</text>`;const $e=xv[V];$e.length>0&&(we+=f2(re+E-10,ve,$e,J,!0)),(l[Y]??[]).forEach((Be,Ge)=>{we+=`<text x="${re+12}" y="${N+30+11+Ge*15}" class="t-name${Q?" c-accent":""}">${S(Be)}</text>`}),(d[Y]??[]).forEach((Be,Ge)=>{we+=`<text x="${re+12}" y="${N+30+p*15+12+Ge*13}" class="t-sub"${Ge===0?_(`steps.${Y}.action`):""}>${S(Be)}</text>`});const Me=u[Y]??[];if(Me.length>0){const Be=hn(U(Y));we+=`<line x1="${A(Y)}" y1="${N+v}" x2="${A(Y)}" y2="${P}" stroke="var(--rule-solid)" stroke-width="1" stroke-dasharray="2 3"${Be}/><g${_(`steps.${Y}.compensate`)}${Be}><rect x="${re}" y="${P}" width="${E}" height="${y}" rx="4" fill="var(--paper)" stroke="var(--ink)" stroke-width="1.25" stroke-dasharray="4 3"/><text x="${re+12}" y="${P+14}" class="t-eyebrow">${iK}</text>`,Me.forEach((Ge,fe)=>{we+=`<text x="${re+12}" y="${P+22+12+fe*15}" class="t-name">${S(Ge)}</text>`}),we+="</g>"}B+=`<g${_(`steps.${Y}`)}${hn(F(Y))}>${we}</g>`}),B+="</g>";let W=!1;if(D.length>0){W=!0;const z='fill="none" stroke="var(--negative)" stroke-width="1.5" stroke-dasharray="5 4" marker-end="url(#skErr)"';B+='<g class="sg-compflow">';const Y=D[0]??0,V=$(r)-yc/2,re=N+v-12;B+=`<path d="M${$(r)},${re} H${V} V${I} H${$(Y)+E}" ${z}${hn(U(Y))}/>`;for(let Q=1;Q<D.length;Q++){const ne=D[Q-1]??0,Z=D[Q]??0;B+=`<path d="M${$(ne)},${I} H${$(Z)+E}" ${z}${hn(U(Z))}/>`}B+="</g>"}B+="</svg>";const K=[];s&&K.push({swatch:"chip",chip:kv,label:"coordinates every step"}),K.push({swatch:"node",label:"step"}),g&&K.push({swatch:"node-dashed",label:"compensation"}),r>=0&&K.push({swatch:"node-accent",label:"failure point"}),H.has("compensated")&&K.push({swatch:"chip",chip:xv.compensated,label:"undone"}),H.has("skipped")&&K.push({swatch:"node-fill2",label:"skipped"}),te&&K.push({swatch:"edge",label:"next"}),ee&&K.push({swatch:"edge-dashed",label:"not reached"}),W&&K.push({swatch:"edge-negative-dashed",label:"compensating flow"});const R=ot(K);return ct({tag:"SAGA",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...R.length>0?{legendHtml:R}:{}},B)}var _a=26,cK=260,dK=16,h2=7,m2=28,uK=6.2;function g2(e){return e.length>m2?`${e.slice(0,m2-1)}…`:e}function v2(e,t){const n=e.map((r,i)=>({y:r,tie:t[i]??0,i})).sort((r,i)=>r.y-i.y||r.tie-i.tie||r.i-i.i),s=e.slice();let o=-1/0;for(const{y:r,i}of n){const l=Math.max(r,o+dK);s[i]=l,o=l}return s}function pK(e){return e==="negative"?"negative":e==="focal"?"accent":"plain"}var fK={plain:"var(--muted)",accent:"var(--accent)",negative:"var(--negative)"},y2={plain:"t-sub c-ink",accent:"t-sub c-accent",negative:"t-sub c-negative"};function hK(e){const t=e.items,n=e.unit??"",s=F=>n===""?String(F):n==="%"?`${F}${n}`:`${F} ${n}`;let o=Math.min(...t.map(F=>Math.min(F.from,F.to))),r=Math.max(...t.map(F=>Math.max(F.from,F.to)));o===r&&(o-=1,r+=1);const i=_a+34,l=Math.max(160,t.length*22),d=F=>i+(r-F)/(r-o)*l,u=t.map(F=>d(F.from)),p=t.map(F=>d(F.to)),h=v2(u,u),m=v2(p,u),g=t.map(F=>`${g2(F.label)} ${s(F.from)}`),v=t.map(F=>`${s(F.to)} ${g2(F.label)}`),y=F=>Math.max(30,...F.map(U=>U.length*uK)),b=_a+y(g)+12,E=b+cK,$=E+12+y(v)+_a,A=Math.max(i+l,...h,...m)+8,T=A+_a,N=F=>F.toFixed(1);let j=`<svg viewBox="0 0 ${N($)} ${N(T)}" role="img"><title>Slopegraph</title>`;const P=F=>`<line x1="${N(F)}" y1="${N(i-8)}" x2="${N(F)}" y2="${N(A)}" stroke="var(--rule-solid)" stroke-width="1"/>`;j+=P(b)+P(E),j+=`<text x="${N(b)}" y="${N(_a+8)}" class="t-eyebrow" text-anchor="middle"${_("left")}>${S(e.left)}</text>`,j+=`<text x="${N(E)}" y="${N(_a+8)}" class="t-eyebrow" text-anchor="middle"${_("right")}>${S(e.right)}</text>`;const I=new Set,O=Xn(t.map(F=>F.accent));j+=`<g${he("items")}>`,t.forEach((F,U)=>{const X=pK(O[U]);I.add(X);const B=fK[X],te=X!=="plain"?' font-weight="600"':"",ee=u[U]??i,H=p[U]??i,W=h[U]??i,K=m[U]??i;let R=`<g${_(`items.${U}`)}>`;R+=`<title>${S(`${F.label}: ${s(F.from)} → ${s(F.to)}`)}</title>`,R+=`<line x1="${N(b)}" y1="${N(ee)}" x2="${N(E)}" y2="${N(H)}" stroke="${B}" stroke-width="${X!=="plain"?1.75:1.25}"/>`,R+=`<circle cx="${N(b)}" cy="${N(ee)}" r="3" fill="${X==="plain"?"var(--ink)":B}"/>`,R+=`<circle cx="${N(E)}" cy="${N(H)}" r="3" fill="${X==="plain"?"var(--ink)":B}"/>`,Math.abs(W-ee)>h2&&(R+=`<line x1="${N(b-8)}" y1="${N(W)}" x2="${N(b-2)}" y2="${N(ee)}" stroke="var(--rule-solid)" stroke-width="1"/>`),Math.abs(K-H)>h2&&(R+=`<line x1="${N(E+2)}" y1="${N(H)}" x2="${N(E+8)}" y2="${N(K)}" stroke="var(--rule-solid)" stroke-width="1"/>`),R+=`<text x="${N(b-10)}" y="${N(W+3.5)}" class="${y2[X]}" text-anchor="end"${te}${_(`items.${U}.from`)}>${S(g[U]??"")}</text>`,R+=`<text x="${N(E+10)}" y="${N(K+3.5)}" class="${y2[X]}" text-anchor="start"${te}${_(`items.${U}.to`)}>${S(v[U]??"")}</text>`,j+=R+"</g>"}),j+="</g></svg>";const C=[];I.has("plain")&&C.push({swatch:"fill",fill:"var(--muted)",label:"item"}),I.has("accent")&&C.push({swatch:"fill",fill:"var(--accent)",label:"focal item"}),I.has("negative")&&C.push({swatch:"fill",fill:"var(--negative)",label:"negative"});const D=ot(C);return ct({tag:"SLOPEGRAPH",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...D.length>0?{legendHtml:D}:{}},j)}var Mf={server:"SVC",client:"CLIENT",db:"DB",queue:"QUEUE",cache:"CACHE",internal:"INT"},hp=14,mK=136,wv=520,gK=24,Lc=30,vK=Lc+8,$v=24,xi=14,x2=7,yK=50,xK=64,k2=6,b2=5.7,Sv=6.4,Ev=13,kK=2,bK=32;function Mv(e){return Number.isInteger(e)?String(e):String(Math.round(e*100)/100)}function wK(e,t){const n=e/t,s=10**Math.floor(Math.log10(n));for(const o of[1,2,2.5,5,10])if(o*s>=n)return o*s;return 10*s}function $K(e){const t=new Map;for(const n of e)t.has(n.id)||t.set(n.id,n);return e.map(n=>{let s=0,o=n;for(;o!==void 0&&o.parent!==void 0&&s<bK;){const r=t.get(o.parent);if(r===void 0||r===o)break;s+=1,o=r}return s})}function SK(e){const t=new Set(e.map(r=>r.id)),n=e.findIndex(r=>r.parent===void 0||!t.has(r.parent)),s=new Set;if(n<0)return s;let o=n;s.add(o);for(let r=0;r<e.length;r++){const i=e[o]?.id;let l=-1;if(e.forEach((d,u)=>{d.parent!==i||s.has(u)||(l<0||d.duration>(e[l]?.duration??0))&&(l=u)}),l<0)break;s.add(l),o=l}return s}function EK(e){const t=new Map;for(const s of e)s.kind===void 0||!(s.kind in Mf)||t.set(s.kind,(t.get(s.kind)??0)+1);let n;for(const[s,o]of t)(n===void 0||o>(t.get(n)??0))&&(n=s);return n===void 0?void 0:Mf[n]}function MK(e,t){const n=e.map((o,r)=>({s:o,i:r})).filter(({s:o})=>o.attrs!==void 0&&Object.keys(o.attrs).length>0||o.note!==void 0);return n.length===0?"":`<div class="sp-details"><div class="sp-details-title t-eyebrow">Attributes</div><ul>${n.map(({s:o,i:r})=>{const i=o.attrs!==void 0&&Object.keys(o.attrs).length>0?`<span class="sp-d-attrs"${_(`spans.${r}.attrs`)}>`+Object.entries(o.attrs).map(([d,u])=>`<span class="sp-d-attr">${S(d)}=${S(String(u))}</span>`).join("")+"</span>":"",l=o.note!==void 0?`<span class="sp-d-note"${_(`spans.${r}.note`)}>${S(o.note)}</span>`:"";return`<li${_(`spans.${r}`)}${hn(t.get(r)??0)}><span class="sp-d-span"><span class="sp-d-service">${S(o.service)}</span> ${S(o.name)}</span>`+i+l+"</li>"}).join("")}</ul></div>`}function AK(e){const t=e.spans??[],n=e.unit??"ms",s=hp+mK,o=Math.max(1e-9,...t.map(C=>C.start+C.duration)),r=C=>s+C/o*wv,i=[];for(const C of t)i.includes(C.service)||i.push(C.service);const l=$K(t),d=SK(t),u=[],p=[];let h=vK,m=s+wv;i.forEach((C,D)=>{const F=t.map((H,W)=>({s:H,idx:W})).filter(({s:H})=>H.service===C).sort((H,W)=>H.s.start-W.s.start||H.idx-W.idx),U=lt(C,18,2),X=EK(F.map(H=>H.s)),B=U.length>1?xK:yK,te=Math.max(B,F.length*$v+x2*2),ee=h;u.push({service:C,lines:U,chip:X,y:ee,h:te}),F.forEach(({s:H,idx:W},K)=>{const R=r(H.start),z=Math.max(kK,r(H.start+H.duration)-R),Y=ee+x2+K*$v+($v-xi)/2,V=H.name.length*k2+10<=z,re=H.error===!0;let Q=R+z+5+`${Mv(H.duration)} ${n}`.length*b2;re&&(Q+=8+3*Sv+8),V||(Q+=8+H.name.length*k2),m=Math.max(m,Q),p.push({idx:W,span:H,depth:l[W]??0,laneI:D,x:R,y:Y,w:z,crit:d.has(W),err:re,nameInside:V,right:Q})}),h+=te});const g=h,v=Math.ceil(m+gK),y=g+8,b=new Map;[...p].sort((C,D)=>C.span.start-D.span.start||C.idx-D.idx).forEach((C,D)=>b.set(C.idx,D));const E=C=>hn(b.get(C)??0),$=Sn("Trace waterfall",e.title,[wt(t.length,"span")]);let A=`<svg viewBox="0 0 ${v} ${y}"${$.attrs}>${$.title}`;const T=wK(o,6);A+='<g class="sp-axis-g">';for(let C=0;C<=o+1e-9;C+=T){const D=r(C);A+=`<line x1="${D}" y1="${Lc}" x2="${D}" y2="${g}" class="sp-grid"${ut}/><text x="${D}" y="${Lc-7}" class="t-arrow c-soft" text-anchor="middle">${Mv(C)} ${S(n)}</text>`}A+=`<line x1="${s}" y1="${Lc}" x2="${s+wv}" y2="${Lc}" class="sp-axis"/>`,A+="</g>",u.forEach((C,D)=>{D>0&&(A+=`<line x1="0" y1="${C.y}" x2="${v}" y2="${C.y}" class="sp-lane-rule"${ut}/>`);const F=C.y+21;if(A+='<g class="sp-lane">',C.lines.forEach((U,X)=>{A+=`<text x="${hp}" y="${F+X*15}" class="t-name">${S(U)}</text>`}),C.chip!==void 0){const U=F+(C.lines.length-1)*15+8,X=Math.round(C.chip.length*Sv+10);A+=`<rect x="${hp}" y="${U}" width="${X}" height="${Ev}" rx="2" class="sp-chip"/><text x="${hp+5}" y="${U+9.5}" class="t-eyebrow sp-chip-text">${S(C.chip)}</text>`}A+="</g>"});const N=new Map;for(const C of p)N.has(C.span.id)||N.set(C.span.id,C);A+='<g class="sp-links">';for(const C of p){if(C.span.parent===void 0)continue;const D=N.get(C.span.parent);if(D===void 0||D===C)continue;const F=C.x,U=C.y>D.y,X=U?D.y+xi:D.y,B=U?C.y:C.y+xi;A+=`<line x1="${F}" y1="${X}" x2="${F}" y2="${B}" class="sp-link"${hn(Math.max(b.get(C.idx)??0,b.get(D.idx)??0))}/>`}A+="</g>",A+=`<g${he("spans")}>`;for(const C of p){const F=`sp-bar ${C.depth===0?"d0":C.depth===1?"d1":"d2"}${C.crit?" crit":""}${C.err?" err":""}`,X=!C.crit&&!C.err&&C.depth<2?"t-sub sp-on-dark":"t-sub c-ink",B=C.y+xi/2+3.5;let te=`<g${_(`spans.${C.idx}`)}${E(C.idx)}>`;te+=`<rect x="${C.x}" y="${C.y}" width="${C.w}" height="${xi}" rx="2" class="${F}"/>`,C.nameInside&&(te+=`<text x="${C.x+5}" y="${B}" class="${X}"${_(`spans.${C.idx}.name`)}>${S(C.span.name)}</text>`);let ee=C.x+C.w+5;const H=`${Mv(C.span.duration)} ${n}`;if(te+=`<text x="${ee}" y="${B}" class="t-arrow sp-dur"${_(`spans.${C.idx}.duration`)}>${S(H)}</text>`,ee+=H.length*b2+8,C.err){const W=Math.round(3*Sv+8);te+=`<rect x="${ee}" y="${C.y+(xi-Ev)/2}" width="${W}" height="${Ev}" rx="2" class="sp-chip err"/><text x="${ee+4}" y="${C.y+xi/2+3}" class="t-eyebrow sp-chip-text err">ERR</text>`,ee+=W+8}C.nameInside||(te+=`<text x="${ee}" y="${B}" class="t-sub c-ink"${_(`spans.${C.idx}.name`)}>${S(C.span.name)}</text>`),te+="</g>",A+=te}A+="</g>",A+="</svg>";const j=p.filter(C=>!C.crit&&!C.err),P=[];j.some(C=>C.depth===0)&&P.push({swatch:"fill",fill:"var(--ink)",label:"span"}),j.some(C=>C.depth===1)&&P.push({swatch:"fill",fill:"var(--muted)",label:"nested span"}),j.some(C=>C.depth>=2)&&P.push({swatch:"node-fill2",label:"nested twice or more"}),d.size>0&&P.push({swatch:"node-accent",label:"critical path"}),p.some(C=>C.err)&&P.push({swatch:"node-negative",label:"error"});const I=[];for(const C of t)C.kind===void 0||!(C.kind in Mf)||I.includes(C.kind)||(I.push(C.kind),P.push({swatch:"chip",chip:Mf[C.kind],label:C.kind}));const O=ot(P);return ct({tag:"SPANS",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...O.length>0?{legendHtml:O}:{}},A+MK(t,b))}var w2={done:"node-fill2",current:"node-accent-outline",next:"node-dashed",blocked:"node-negative"},CK=["done","current","next","blocked"];function NK(e){return Number.isInteger(e)?String(e):String(Math.round(e*10)/10)}function TK(e){const t=e.stages??[],n=new Set;let s=!1,o=`<div class="ro-strip"${he("stages")}>`;t.forEach((d,u)=>{const p=d.status!==void 0&&d.status in w2?d.status:void 0;p!==void 0&&n.add(p);const h=p!==void 0?` ro-s-${p}`:"",m=p!==void 0?`<span class="ro-status ro-st-${p}"${_(`stages.${u}.status`)}>${S(p)}</span>`:"",g=d.traffic!==void 0?`<div class="ro-traffic"${_(`stages.${u}.traffic`)}><div class="ro-track"><div class="ro-fill" style="width:${Math.min(100,Math.max(0,d.traffic))}%"></div></div><span class="ro-pct t-sub">${NK(d.traffic)}%</span></div>`:"",v=d.duration!==void 0?`<div class="ro-dur t-sub"${_(`stages.${u}.duration`)}>${S(d.duration)}</div>`:"",y=d.note!==void 0?`<div class="ro-note"${_(`stages.${u}.note`)}>${S(d.note)}</div>`:"";o+=`<div class="ro-stage${h}"${_(`stages.${u}`)}><span class="ro-n t-eyebrow">Stage ${u+1}</span><div class="ro-head"><span class="ro-name t-name"${_(`stages.${u}.name`)}>${S(d.name)}</span>${m}</div>`+g+v+y+"</div>";const b=u===t.length-1;if(!b||d.gate!==void 0){const E=d.gate!==void 0?`<span class="ro-gate t-arrow"${_(`stages.${u}.gate`)}>${S(d.gate)}</span>`:"";d.gate!==void 0&&(s=!0),o+=`<div class="ro-link${b?" ro-link-end":""}">${E}</div>`}}),o+="</div>";const r=CK.filter(d=>n.has(d)).map(d=>({swatch:w2[d],label:d}));s&&r.push({swatch:"chip",chip:"GATE",label:"gate — must pass to advance"});const i=ot(r),l=e.rollback!==void 0?`<div class="ro-rollback"${_("rollback")}><span class="t-eyebrow">Rollback</span><span class="ro-rollback-text">${S(e.rollback)}</span></div>`:"";return ct({tag:"ROLLOUT",...e.strategy!==void 0?{path:e.strategy}:{},...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...i.length>0?{legendHtml:i}:{},...l.length>0?{footerHtml:l}:{}},o)}var $2=.7,_K=.1,La=300,mp=36,Ar=12,LK=6.8,S2=6.2;function IK(e){return(e.lowerIsBetter!==!1?e.measured>e.budget:e.measured<e.budget)?"over":e.budget!==0&&Math.abs(e.measured-e.budget)/Math.abs(e.budget)<=_K?"near":"ok"}function E2(e){return!Number.isFinite(e)||Number.isInteger(e)?String(e):String(Math.round(e*100)/100)}function Av(e,t){return t!==void 0&&t!==""?`${E2(e)}${t.length<=3?"":" "}${t}`:E2(e)}var jK={over:"var(--negative)",near:"var(--accent)",ok:"var(--muted)"},PK={over:" c-negative",near:" c-accent",ok:" c-muted"},OK={over:"var(--negative)",near:"var(--rule-solid)",ok:"var(--rule-solid)"};function RK(e){const t=e.metrics,n=t.map(IK),s=X=>{const B=X.lowerIsBetter===!1?"≥":"≤",te=X.note!==void 0&&X.note!==""?` · ${X.note}`:"";return`budget ${B} ${Av(X.budget,X.unit)}${te}`},o=t.map(s),r=Math.max(120,...t.map(X=>X.metric.length*LK+8),...o.map(X=>X.length*S2+8)),i=16,l=16,d=Math.max(56,...t.map(X=>Av(X.measured,X.unit).length*S2+14)),u=44,p=i+r,h=p+La+8,m=h+d+6,g=m+u+l,v=e.context!==void 0&&e.context!==""?18:0,b=12+v+22,E=b+t.length*mp+10,$=p+La*$2,A=Sn("Performance budget",e.title,[wt(t.length,"metric")]);let T=`<svg viewBox="0 0 ${g} ${E}"${A.attrs}>${A.title}`;v>0&&(T+=`<text x="${i}" y="22" class="t-sub c-muted"${_("context")}>${S(e.context??"")}</text>`);const N=b-6,j=b+t.length*mp;T+=`<text x="${$}" y="${b-10}" class="t-eyebrow" text-anchor="middle">budget</text>`,T+=`<line x1="${$}" y1="${N}" x2="${$}" y2="${j}" stroke="var(--ink)" stroke-width="1" stroke-dasharray="4 3"/>`,T+=`<g${he("metrics")}>`,t.forEach((X,B)=>{const te=n[B]??"ok",ee=b+B*mp,H=ee+mp/2,K=(X.budget!==0?Math.max(0,X.measured/X.budget):X.measured>0?1/0:0)*La*$2,R=K>La,z=Math.max(0,Math.min(La,K)),Y=p+z,V=jK[te],re=Av(X.measured,X.unit);T+=`<g${_(`metrics.${B}`)} data-status="${te}">`+(B>0?`<line x1="${i}" y1="${ee}" x2="${g-l}" y2="${ee}" stroke="var(--rule)" stroke-width="1"${ut}/>`:"")+`<text x="${i}" y="${H-2}" class="pb-label"${_(`metrics.${B}.metric`)}>${S(X.metric)}</text><text x="${i}" y="${H+11}" class="t-sub c-soft"${_(`metrics.${B}.budget`)}>${S(o[B]??"")}</text><rect x="${p}" y="${H-Ar/2}" width="${La}" height="${Ar}" rx="2" fill="var(--paper-2)" stroke="var(--rule)" stroke-width="1"${ut}/><rect x="${p}" y="${H-Ar/2}" width="${z}" height="${Ar}" rx="2" fill="${V}"${_(`metrics.${B}.measured`)}/>`+(R?`<path d="M${Y-6} ${H-Ar/2-2} l -4 ${Ar+4} M${Y-2} ${H-Ar/2-2} l -4 ${Ar+4}" stroke="var(--paper)" stroke-width="2" fill="none"/>`:"")+`<text x="${h}" y="${H+3.5}" class="t-sub c-ink pb-val">${S(re)}</text><rect x="${m}" y="${H-7}" width="${u}" height="14" rx="2" fill="var(--paper)" stroke="${OK[te]}" stroke-width="1"/><text x="${m+u/2}" y="${H+3}" class="t-eyebrow${PK[te]}" text-anchor="middle">${te}</text></g>`}),T+="</g></svg>";const P=X=>n.filter(B=>B===X).length,I=P("over"),O=P("near"),C=P("ok"),D=[];I>0&&D.push({swatch:"fill",fill:"var(--negative)",label:"over budget"}),O>0&&D.push({swatch:"fill",fill:"var(--accent)",label:"near — within 10%"}),C>0&&D.push({swatch:"fill",fill:"var(--muted)",label:"within budget"}),D.push({swatch:"line-dashed",stroke:"var(--ink)",label:"budget"});const F=ot(D),U=`<div class="diagram-foot pb-foot"><span><strong>${I}</strong> over</span><span><strong>${O}</strong> near</span><span><strong>${C}</strong> ok</span></div>`;return ct({tag:"PERF BUDGET",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...F.length>0?{legendHtml:F}:{},footerHtml:U},T)}var M2=440,gp=34,A2=24,vp=6.2,DK=6.8,Cv=7;function BK(e){if(!(e>0))return 1;const t=Math.pow(10,Math.floor(Math.log10(e/5))),n=[1,2,2.5,5,10].map(r=>r*t);let s=n[0]??1,o=1/0;for(const r of n){const i=Math.ceil(e/r-1e-9),l=i>=4&&i<=6?Math.abs(i-5):10+Math.abs(i-5);l<o&&(s=r,o=l)}return s}var Ia=e=>Math.round(e*1e6)/1e6;function ja(e){return Number.isInteger(e)?String(e):String(Math.round(e*100)/100)}function zK(e,t,n,s,o){if(n&&e>0&&t>0){const h=Math.floor(Math.log10(e)),m=Math.ceil(Math.log10(t)-1e-9),g=Math.pow(10,h),v=Math.pow(10,Math.max(m,h+1)),y=Math.max(1,Math.log10(v)-Math.log10(g)),b=[];for(let A=h;A<=Math.log10(v)+1e-9;A++){const T=Math.pow(10,A);b.push(Ia(T)),y<=3&&T*10<=v+1e-9&&b.push(Ia(T*2),Ia(T*5))}const E=Math.log10(g),$=Math.log10(v)-E;return{lo:g,hi:v,ticks:b,log:!0,x:A=>s+(Math.log10(Math.max(A,g))-E)/$*o}}const r=Math.max(t-e,1e-9),i=BK(r),l=Ia(Math.floor(e/i)*i),d=Ia(Math.max(Math.ceil(t/i)*i,l+i)),u=[];for(let h=l;h<=d+1e-9;h+=i)u.push(Ia(h));const p=d-l;return{lo:l,hi:d,ticks:u,log:!1,x:h=>s+(h-l)/p*o}}function C2(e){return e.max??e.p999??e.p99}function FK(e){const t=e.rows,n=e.unit??"",s=Xn(t.map(C=>C.accent)),o=C=>C.slo??e.slo,r=Math.max(96,...t.map(C=>C.label.length*DK+12)),i=12,l=i+r,d=Math.min(...t.map(C=>C.p50)),u=Math.max(...t.map(C2),...t.map(C=>o(C)??-1/0)),p=zK(d,u,e.scale==="log",l,M2),h=l+M2,g=12+(e.slo!==void 0?16:0),v=g+t.length*gp+8,y=v+26,b=Math.max(0,...t.map(C=>(ja(C.p99).length+1)*vp)),E=h+A2+Math.max(0,b-A2+8),$=Sn("Latency percentiles",e.title,[wt(t.length,"row")]);let A=`<svg viewBox="0 0 ${E} ${y}"${$.attrs}>${$.title}`;A+=`<g${ut}>`;for(const C of p.ticks){const D=p.x(C);A+=`<line x1="${D}" y1="${g}" x2="${D}" y2="${v}" stroke="var(--rule)" stroke-width="1"/>`}A+="</g>",A+=`<line x1="${l}" y1="${v}" x2="${h}" y2="${v}" stroke="var(--rule-solid)" stroke-width="1"/>`;let T=-1/0;for(const C of p.ticks){const D=`${ja(C)}${n}`,F=D.length*vp,U=p.x(C);U-F/2<T+6||(A+=`<text x="${U}" y="${v+14}" class="t-sub c-soft" text-anchor="middle">${S(D)}</text>`,T=U+F/2)}if(e.slo!==void 0){const C=p.x(e.slo);A+=`<g${_("slo")}><line x1="${C}" y1="${g-4}" x2="${C}" y2="${v}" stroke="var(--ink)" stroke-width="1" stroke-dasharray="4 3"/><text x="${C}" y="${g-8}" class="t-eyebrow" text-anchor="middle">SLO ${S(ja(e.slo))}${S(n)}</text></g>`}let N=!1,j=!1,P=!1;A+=`<g${he("rows")}>`,t.forEach((C,D)=>{const F=g+D*gp,U=F+gp/2,X=o(C),B=X!==void 0&&C.p99>X;B&&(N=!0);const te=s[D]==="negative",ee={p50:p.x(C.p50),p90:C.p90!==void 0?p.x(C.p90):void 0,p95:C.p95!==void 0?p.x(C.p95):void 0,p99:p.x(C.p99),p999:C.p999!==void 0?p.x(C.p999):void 0,max:C.max!==void 0?p.x(C.max):void 0},H=p.x(C2(C));let W=`<g${_(`rows.${D}`)}${B?' data-over="1"':""}>`;if(D>0&&(W+=`<line x1="${i}" y1="${F}" x2="${E-8}" y2="${F}" stroke="var(--rule)" stroke-width="1"${ut}/>`),W+=`<text x="${i}" y="${U+4}" class="pc-label${te?" c-negative":""}"${_(`rows.${D}.label`)}>${S(C.label)}</text>`,C.slo!==void 0){const q=p.x(C.slo);W+=`<line x1="${q}" y1="${F+3}" x2="${q}" y2="${F+gp-3}" stroke="var(--ink)" stroke-width="1" stroke-dasharray="4 3"${_(`rows.${D}.slo`)}/><text x="${q+4}" y="${F+10}" class="t-eyebrow">SLO ${S(ja(C.slo))}${S(n)}</text>`}W+=`<line x1="${ee.p50}" y1="${U}" x2="${H}" y2="${U}" stroke="var(--muted)" stroke-width="1.25"/>`,ee.max!==void 0&&(P=!0,W+=`<g${_(`rows.${D}.max`)}><circle cx="${ee.max}" cy="${U}" r="3.5" fill="var(--paper)" stroke="var(--soft)" stroke-width="1.25"/><path d="M${ee.max-2} ${U-2} l 4 4 M${ee.max+2} ${U-2} l -4 4" stroke="var(--soft)" stroke-width="1" fill="none"/></g>`),ee.p999!==void 0&&(W+=`<circle cx="${ee.p999}" cy="${U}" r="2.5" fill="var(--paper)" stroke="var(--muted)" stroke-width="1.25"${_(`rows.${D}.p999`)}/>`);for(const q of["p90","p95"]){const de=ee[q];de!==void 0&&(j=!0,W+=`<circle cx="${de}" cy="${U}" r="2.5" fill="var(--paper)" stroke="var(--muted)" stroke-width="1.25"${_(`rows.${D}.${q}`)}/>`)}const K=B?"var(--negative)":"var(--accent)";W+=`<circle cx="${ee.p99}" cy="${U}" r="4" fill="${K}"${_(`rows.${D}.p99`)}/>`,W+=`<circle cx="${ee.p50}" cy="${U}" r="4" fill="var(--ink)"${_(`rows.${D}.p50`)}/>`;const R=ja(C.p50),z=R.length*vp;ee.p50-Cv-z>=l-2&&(W+=`<text x="${ee.p50-Cv}" y="${U+3.5}" class="t-sub c-muted" text-anchor="end">${S(R)}</text>`);const Y=ja(C.p99),V=Y.length*vp,re=ee.p99+Cv,Q=re+V;[ee.p999,ee.max].filter(q=>q!==void 0).every(q=>q-4>Q+2||q+4<re-2)&&(W+=`<text x="${re}" y="${U+3.5}" class="t-sub${B?" c-negative":" c-muted"}">${S(Y)}</text>`),W+="</g>",A+=W}),A+="</g></svg>";const I=[{swatch:"node-dot",fill:"var(--ink)",stroke:"var(--ink)",label:"p50"}];j&&I.push({swatch:"node-dot",fill:"var(--paper)",stroke:"var(--muted)",label:"p90 · p95"}),I.push({swatch:"node-dot",fill:"var(--accent)",stroke:"var(--accent)",label:"p99"}),N&&I.push({swatch:"node-dot",fill:"var(--negative)",stroke:"var(--negative)",label:"p99 over the SLO"}),P&&I.push({swatch:"node-dot",fill:"var(--paper)",stroke:"var(--soft)",label:"max"}),t.some(C=>o(C)!==void 0)&&I.push({swatch:"line-dashed",stroke:"var(--ink)",label:"SLO"});const O=ot(I);return ct({tag:"PERCENTILES",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...O.length>0?{legendHtml:O}:{}},A)}var N2=520,T2=22,_2=18,qK=8,yp=14,HK=24,L2=14,Nv=6,I2=6.2,WK=7.4;function UK(e){if(!(e>0))return 1;const t=Math.pow(10,Math.floor(Math.log10(e/5))),n=[1,2,2.5,5,10].map(r=>r*t);let s=n[0]??1,o=1/0;for(const r of n){const i=Math.ceil(e/r-1e-9),l=i>=4&&i<=6?Math.abs(i-5):10+Math.abs(i-5);l<o&&(s=r,o=l)}return s}var Tv=e=>Math.round(e*1e6)/1e6,KK=e=>Number.isInteger(e)?String(e):String(Math.round(e*100)/100);function VK(e,t){return e.length<=t?e:t<2?"":`${e.slice(0,t-1)}…`}function j2(e){const t=e.map((o,r)=>({...o,i:r})).sort((o,r)=>o.x-r.x||o.i-r.i),n=[],s=new Array(e.length).fill(0);for(const o of t){const r=o.x-o.w/2;let i=n.findIndex(l=>l+6<=r);i<0&&(i=n.length,n.push(-1/0)),n[i]=o.x+o.w/2,s[o.i]=i}return s}function GK(e){const t=e.lanes,n=e.events??[],s=e.constraints??[],o=e.unit??"",r=o.length>2?` ${o}`:o,i=t.map(le=>{const J=[];for(const ue of le.states)J.includes(ue.state)||J.push(ue.state);return J}),l=t.flatMap(le=>le.states),d=Xn(l.map(le=>le.accent)),u=[...l.flatMap(le=>[le.from,le.to]),...n.map(le=>le.at),...s.flatMap(le=>[le.from,le.to])],p=Math.min(...u),h=Math.max(...u),m=UK(Math.max(h-p,1e-9)),g=Tv(Math.floor(p/m)*m),v=Tv(Math.max(Math.ceil(h/m)*m,g+m)),y=[];for(let le=g;le<=v+1e-9;le+=m)y.push(Tv(le));const b=Math.max(88,...t.map(le=>le.label.length*WK+8),...i.flatMap(le=>le.map(J=>J.length*I2+12))),E=yp+b,$=E+N2,A=le=>E+(le-g)/(v-g)*N2,T=n.map(le=>({x:A(le.at),w:le.label.length*Nv+10})),N=j2(T),j=n.length>0?Math.max(...N)+1:0,P=j>0?j*L2+8:0,I=s.map(le=>({x:(A(le.from)+A(le.to))/2,w:(le.label.length+4)*Nv+10})),O=j2(I),C=s.length>0?Math.max(...O)+1:0,D=C>0?C*24+4:0,U=10,X=U+P,B=X+D,te=le=>_2+(i[le]?.length??1)*T2+qK,ee=[];let H=B;for(let le=0;le<t.length;le++)ee.push(H),H+=te(le);const W=H,K=W+6,R=K+26,z=$+HK,Y=Sn("Timing diagram",e.title,[wt(t.length,"lane"),wt(n.length,"event")]);let V=`<svg viewBox="0 0 ${z} ${R}"${Y.attrs}>${Y.title}`;V+=`<g${ut}>`;for(const le of y){const J=A(le);V+=`<line x1="${J}" y1="${B}" x2="${J}" y2="${W}" stroke="var(--rule)" stroke-width="1"/>`}for(let le=1;le<t.length;le++){const J=ee[le]??0;V+=`<line x1="${yp}" y1="${J}" x2="${z-8}" y2="${J}" stroke="var(--rule)" stroke-width="1"/>`}V+="</g>",V+=`<line x1="${E}" y1="${K}" x2="${$}" y2="${K}" stroke="var(--rule-solid)" stroke-width="1"/>`;let re=-1/0;for(const le of y){const J=`${KK(le)}${r}`,ue=J.length*I2,ve=A(le);ve-ue/2<re+6||(V+=`<text x="${ve}" y="${K+14}" class="t-sub c-soft" text-anchor="middle">${S(J)}</text>`,re=ve+ue/2)}let Q=!1,ne=!1,Z=0;if(V+=`<g${he("lanes")}>`,t.forEach((le,J)=>{const ue=i[J]??[],ve=ee[J]??0,we=Me=>ve+_2+(Math.max(0,ue.indexOf(Me))+.5)*T2;let $e=`<g${_(`lanes.${J}`)} data-levels="${ue.length}">`;$e+=`<text x="${yp}" y="${ve+13}" class="t-name"${_(`lanes.${J}.label`)}>${S(le.label)}</text>`;for(const Me of ue)$e+=`<text x="${E-8}" y="${we(Me)+3.5}" class="t-sub c-soft tg-level" text-anchor="end">${S(Me)}</text>`;const je=le.states.map((Me,Be)=>({st:Me,si:Be,mark:d[Z+Be]})).sort((Me,Be)=>Me.st.from-Be.st.from||Me.si-Be.si);Z+=le.states.length;let De="";je.forEach((Me,Be)=>{const Ge=A(Me.st.from),fe=A(Me.st.to),ge=we(Me.st.state);if(De+=Be===0?`M ${Ge} ${ge} `:`V ${ge} `,Be>0){const Ce=je[Be-1],Fe=Ce!==void 0?A(Ce.st.to):Ge;Ge>Fe+.5&&(De+=`H ${Ge} `)}De+=`H ${fe} `}),$e+=`<path d="${De.trim()}" fill="none" stroke="var(--muted)" stroke-width="1.5" stroke-linejoin="round"/>`,$e+=`<g${he(`lanes.${J}.states`)}>`;for(const Me of je){const Be=A(Me.st.from),Ge=A(Me.st.to),fe=we(Me.st.state),ge=Me.mark==="negative"?"var(--negative)":Me.mark==="focal"?"var(--accent)":void 0;Me.mark==="negative"&&(Q=!0),Me.mark==="focal"&&(ne=!0);const Ce=Me.mark==="negative"?" c-negative":Me.mark==="focal"?" c-accent":"",Fe=Math.floor((Ge-Be-6)/Nv),qe=VK(Me.st.state,Fe),ze=qe!==Me.st.state?`<title>${S(Me.st.state)}</title>`:"";$e+=`<g${_(`lanes.${J}.states.${Me.si}`)}>`+(ge!==void 0?`<line x1="${Be}" y1="${fe}" x2="${Ge}" y2="${fe}" stroke="${ge}" stroke-width="2.25"/>`:"")+(qe!==""?`<text x="${(Be+Ge)/2}" y="${fe-5}" class="t-arrow${Ce}" text-anchor="middle">${ze}${S(qe)}</text>`:"")+"</g>"}$e+="</g></g>",V+=$e}),V+="</g>",s.length>0&&(V+=`<g${he("constraints")}>`,s.forEach((le,J)=>{const ue=A(le.from),ve=A(le.to),we=O[J]??0,$e=X+4+(C-1-we)*24+16;V+=`<g${_(`constraints.${J}`)}><path d="M ${ue} ${$e+5} V ${$e} H ${ve} V ${$e+5}" fill="none" stroke="var(--ink)" stroke-width="1"/><text x="${(ue+ve)/2}" y="${$e-4}" class="t-arrow c-ink" text-anchor="middle">{ ${S(le.label)} }</text></g>`}),V+="</g>"),n.length>0){const le=new Map(t.map((J,ue)=>[J.label,ue]));V+=`<g${he("events")}>`,n.forEach((J,ue)=>{const ve=A(J.at),we=N[ue]??0,$e=U+(j-1-we)*L2+10,je=J.lane!==void 0?le.get(J.lane):void 0,De=je!==void 0?ee[je]??B:B,Me=je!==void 0?(ee[je]??B)+te(je):W,Be=T[ue]?.w??0,Ge=Math.min(Math.max(ve,yp+Be/2),z-4-Be/2);V+=`<g${_(`events.${ue}`)}><line x1="${ve}" y1="${$e+4}" x2="${ve}" y2="${Me}" stroke="var(--muted)" stroke-width="1" stroke-dasharray="3 3"/><circle cx="${ve}" cy="${De}" r="2.5" fill="var(--muted)"/><text x="${Ge}" y="${$e}" class="t-arrow c-ink" text-anchor="middle"${_(`events.${ue}.label`)}>${S(J.label)}</text></g>`}),V+="</g>"}V+="</svg>";const q=[{swatch:"line",stroke:"var(--muted)",label:"state"}];Q&&q.push({swatch:"line",stroke:"var(--negative)",label:"failure state"}),ne&&q.push({swatch:"line",stroke:"var(--accent)",label:"highlighted state"}),n.length>0&&q.push({swatch:"line-dashed",stroke:"var(--muted)",label:"event"}),s.length>0&&q.push({swatch:"chip",chip:"{ }",label:"duration constraint"});const de=ot(q);return ct({tag:"TIMING",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...de.length>0?{legendHtml:de}:{}},V)}var YK={S:"Spoofing",T:"Tampering",R:"Repudiation",I:"Information disclosure",D:"Denial of service",E:"Elevation of privilege"},IA=6,jA=11,PA=34;function XK(e,t){return`<g class="tm-lock" fill="none" stroke="var(--muted)" stroke-width="1.2"><path d="M${e+1.5} ${t+4.5} V ${t+2.5} a 2.5 2.5 0 0 1 5 0 V ${t+4.5}"/><path d="M${e} ${t+4.5} h 8 v 5.5 h -8 z"/></g>`}function OA(e){return e==="plain"?32:16}function QK(e,t,n,s,o){const r=OA(s),i=e-o/2,l=t-r/2,d=s==="plain"?" c-negative":"";let u=`<rect x="${i}" y="${l}" width="${o}" height="${r}" fill="var(--paper)"/>`;const p=s==="tls"?jA:0,h=n!==""?n.length*IA:0,m=e-(p+h)/2,g=l+11.5;if(s==="tls"&&(u+=XK(m,g-8.5)),n!==""&&(u+=`<text x="${m+p}" y="${g}" class="t-arrow${d}">${S(n)}</text>`),s==="plain"){const v=PA-4,y=l+16+1.5;u+=`<rect x="${e-v/2}" y="${y}" width="${v}" height="13" rx="2" fill="var(--negative-tint)" stroke="var(--negative)" stroke-width="1"/><text x="${e}" y="${y+9.5}" class="t-eyebrow c-negative" text-anchor="middle">plain</text>`}return u}function ZK(e,t){const n=(t==="tls"?jA:0)+(e!==""?e.length*IA:0);return 6+Math.max(n,t==="plain"?PA:0)}function JK(e){return e==="tls"||e==="plain"||e==="internal"?e:"none"}var eV=/^\s*(.+?)\s*(?:->|→)\s*(.+?)\s*$/;function tV(e,t){if(e.length===0)return"";const n=o=>{const r=eV.exec(o);return r!==null&&r[1]!==void 0&&r[2]!==void 0?`${S(t(r[1])??r[1])} → ${S(t(r[2])??r[2])}`:S(t(o.trim())??o)},s=e.map((o,r)=>{const i=o.id!==void 0?`<td class="tm-id"${_(`threats.${r}.id`)}>${S(o.id)}</td>`:'<td class="tm-id"></td>',l=`<td><abbr class="tm-cat" title="${S(YK[o.category])}"${_(`threats.${r}.category`)}>${o.category}</abbr></td>`,d=`<td class="tm-target"${_(`threats.${r}.target`)}>${n(o.target)}</td>`,u=`<td class="tm-threat"${_(`threats.${r}.threat`)}>${S(o.threat)}</td>`,p=`<td class="tm-mit"${o.mitigation!==void 0?_(`threats.${r}.mitigation`):""}>${o.mitigation!==void 0?S(o.mitigation):'<span class="tm-none">—</span>'}</td>`,h=o.severity!==void 0?`<td><span class="rk-sev rk-sev-${o.severity}"${_(`threats.${r}.severity`)}>${S(o.severity)}</span></td>`:"<td></td>",m=o.status!==void 0?`<td><span class="rk-status tm-st-${o.status}"${_(`threats.${r}.status`)}>${S(o.status)}</span></td>`:"<td></td>";return`<tr class="tm-row"${_(`threats.${r}`)}>${i}${l}${d}${u}${p}${h}${m}</tr>`}).join("");return`<div class="tm-scroll"><table class="trk tm-table"><thead><tr><th>ID</th><th>STRIDE</th><th>Target</th><th>Threat</th><th>Mitigation</th><th>Severity</th><th>Status</th></tr></thead><tbody${he("threats")}>${s}</tbody></table></div>`}function nV(e){const t=e.edges??[],n=e.nodes,s=!(n.length>0&&n.every(R=>R.col!==void 0&&R.row!==void 0)),o=nr(n,t,e.dir??"LR"),r=148,i=o.map(R=>lt(R.name,20,3)),d=66+(Math.max(1,...i.map(R=>R.length))-1)*14,u=104,p=54,h=e.boundaries??[],m=Yi(h),g=(h.length>0?Gn.padX:26)+m.padX,v=(h.length>0?Gn.padTop:26)+m.padTop,y=(h.length>0?Gn.padBot:20)+m.padBot,b=wd(h),E=Math.max(1,...o.map(R=>R.col),b.cols),$=Math.max(1,...o.map(R=>R.row),b.rows),A=R=>g+(R-1)*(r+u),T=R=>v+(R-1)*(d+p),N=R=>({x:A(R.col),y:T(R.row),w:r,h:d}),j=new Map(o.map(R=>[R.id,R])),P=g*2+E*r+(E-1)*u,I=v+$*d+($-1)*p+y,O=tr({quick:s,cols:E,rows:$,cellW:r,cellH:d,gapX:u,gapY:p,padX:g,padTop:v}),C=Sn("Threat model",e.title,[wt(o.length,"node"),wt(t.length,"flow"),wt((e.threats??[]).length,"threat")]);let D=`<svg viewBox="0 0 ${P} ${I}"${C.attrs}${O}>${C.title}`;if(h.length>0){const R=xl(h,{xOf:A,yOf:T,cellW:r,cellH:d,gapX:u,gapY:p,skin:!0}).replace(/data-bl="groups"/g,'data-bl="boundaries"').replace(/data-bp="groups\./g,'data-bp="boundaries.');D+=`<g class="tm-bounds">${R}</g>`}const F=new Set,U=qs(t),X=Hs(t,R=>{const z=j.get(R);return z!==void 0?N(z):void 0}),B=[],te=o.map(R=>N(R));D+=`<g${he("edges")}>`,t.forEach((R,z)=>{const Y=j.get(R.from),V=j.get(R.to);if(!Y||!V)return;const re=JK(R.channel);F.add(re);const Q=Fs(N(Y),N(V),U[z]??0,X[z]??0),ne=re==="plain",Z=ne?"var(--negative)":"var(--muted)",q=ne?' stroke-dasharray="4 3"':"",de=ne?"skErr":"skArrow";D+=`<path d="${Q.d}" fill="none" stroke="${Z}" stroke-width="1.5"${q} marker-end="url(#${de})"${_(`edges.${z}`)}${ne?' data-channel="plain"':""}/>`;const le=R.label??"";if(le===""&&re!=="tls"&&re!=="plain")return;const J=ZK(le,re),ue=Uy(Q.lx,Q.ly,te),ve=OA(re);te.push({x:ue.lx-J/2,y:ue.ly-ve/2,w:J,h:ve}),B.push(`<g${_(`edges.${z}`)}>${QK(ue.lx,ue.ly,le,re,J)}</g>`)}),D+="</g>";const ee=new Set;D+=`<g${he("nodes")}>`,o.forEach((R,z)=>{const Y=N(R),V=tA(R.kind);ee.add(V);const re=nA(V,!1),Q=rA(i[z]??[],R.name,Y,!1,`nodes.${z}.name`);D+=`<g${_(`nodes.${z}`)}${Mo(R.col,R.row)}>${sA(V,Y,re)}${oA(Y,re)}${Q}</g>`}),D+="</g>",D+=B.join(""),D+="</svg>";const H=[];ee.has("process")&&H.push({swatch:"node",label:"process"}),ee.has("external")&&H.push({swatch:"node-dashed",label:"external entity"}),ee.has("store")&&H.push({swatch:"node-store",label:"data store"}),h.length>0&&H.push({swatch:"line-dashed",stroke:"var(--negative)",label:"trust boundary"}),F.has("none")&&H.push({swatch:"edge",label:"data flow"}),F.has("tls")&&H.push({swatch:"edge",label:"tls (lock)"}),F.has("internal")&&H.push({swatch:"edge",label:"internal"}),F.has("plain")&&H.push({swatch:"edge-negative-dashed",label:"plain — unencrypted"});const W=ot(H),K=tV(e.threats??[],R=>j.get(R)?.name);return ct({tag:"THREAT MODEL",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...W.length>0?{legendHtml:W}:{},...K.length>0?{footerHtml:K}:{}},D)}var sV=6,oV=4,tn=8,P2=24,O2=18,_v=124,R2=30,D2=22,rV=26,Lv=14,Iv=13;function iV(e,t,n){const s='fill="var(--paper)" stroke="var(--ink)" stroke-width="1.5"',o='fill="var(--muted)" stroke="var(--muted)" stroke-width="1"',r='fill="var(--paper-2)" stroke="var(--rule-solid)" stroke-width="1"';switch(e){case"input":case"output":return`<circle cx="${t}" cy="${n}" r="${tn}" ${s}/>`;case"conv":return`<rect x="${t-tn+1}" y="${n-tn+1}" width="${2*tn-2}" height="${2*tn-2}" ${o}/>`;case"pool":return`<rect x="${t-tn+1}" y="${n-tn+1}" width="${2*tn-2}" height="${2*tn-2}" rx="4" ${r}/>`;case"attention":return`<path d="M${t} ${n-tn-1} L${t+tn+1} ${n} L${t} ${n+tn+1} L${t-tn-1} ${n} z" ${o}/>`;case"norm":return`<circle cx="${t}" cy="${n}" r="${tn}" ${r}/>`;case"dropout":return`<circle cx="${t}" cy="${n}" r="${tn}" fill="var(--paper)" stroke="var(--rule-solid)" stroke-width="1" stroke-dasharray="3 2"/>`;case"recurrent":return`<circle cx="${t}" cy="${n}" r="${tn}" ${o}/><circle cx="${t}" cy="${n}" r="3" fill="var(--paper)"/>`;case"embedding":case"dense":return`<circle cx="${t}" cy="${n}" r="${tn}" ${o}/>`}}var aV={input:{swatch:"node-dot",label:"input"},output:{swatch:"node-dot",label:"output"},dense:{swatch:"node-dot",label:"dense",fill:"var(--muted)",stroke:"var(--muted)"},embedding:{swatch:"node-dot",label:"embedding",fill:"var(--muted)",stroke:"var(--muted)"},recurrent:{swatch:"node-dot",label:"recurrent",fill:"var(--muted)",stroke:"var(--muted)"},conv:{swatch:"fill",label:"conv",fill:"var(--muted)"},pool:{swatch:"node-fill2",label:"pool"},attention:{swatch:"node-dot",label:"attention",fill:"var(--muted)",stroke:"var(--muted)"},norm:{swatch:"node-dot",label:"norm",fill:"var(--paper-2)",stroke:"var(--rule-solid)"},dropout:{swatch:"node-dot",label:"dropout",stroke:"var(--rule-solid)",dash:"3 2"}};function lV(e,t,n){return e.kind!==void 0?e.kind:t===0?"input":t===n-1?"output":"dense"}function cV(e){const t=e.layers,n=t.length,s=Math.max(1,Math.min(12,Math.round(e.maxUnits??sV))),o=[],r=[];t.forEach((C,D)=>{const F=o[D-1]??oV,U=C.units!==void 0?Math.max(1,Math.round(C.units)):void 0,X=Math.min(U!==void 0?U:F,s);o.push(X),r.push(U!==void 0&&U>X)});const i=C=>((o[C]??1)-1)*P2+(r[C]===!0?O2:0)+2*tn,l=Math.max(...t.map((C,D)=>i(D))),d=D2+l/2,u=t.map((C,D)=>lV(C,D,n)),p=t.map(C=>lt(C.label,16,2)),h=Math.max(1,...p.map(C=>C.length)),m=(C,D)=>{const F=o[C]??1,U=d-i(C)/2+tn,X=r[C]===!0&&D===F-1?O2:0;return U+D*P2+X},g=C=>R2+_v/2+C*_v,v=D2+l+rV,y=C=>(C.units!==void 0?1:0)+(C.activation!==void 0?1:0)+(C.note!==void 0?1:0),b=Math.max(0,...t.map(y)),E=R2*2+n*_v,$=v+h*Lv+b*Iv+14,A=Sn("Neural network",e.title,[wt(n,"layer")]);let T=`<svg viewBox="0 0 ${E} ${$}"${A.attrs}>${A.title}`;T+='<g fill="none" stroke="var(--rule-solid)" stroke-width=".6" data-decorative="1">';for(let C=1;C<n;C++){if(t[C]?.connect==="none")continue;const D=g(C-1)+tn,F=g(C)-tn;for(let U=0;U<(o[C-1]??0);U++){const X=m(C-1,U);for(let B=0;B<(o[C]??0);B++)T+=`<line x1="${D}" y1="${X}" x2="${F}" y2="${m(C,B)}"/>`}}T+="</g>";const N=new Set;T+=`<g${he("layers")}>`,t.forEach((C,D)=>{const F=u[D]??"dense";N.add(F);const U=g(D),X=o[D]??1;let B=`<g${_(`layers.${D}`)}>`;for(let H=0;H<X;H++)B+=iV(F,U,m(D,H));if(r[D]===!0&&X>=2){const H=m(D,X-2)+tn,W=m(D,X-1)-tn,K=(H+W)/2;B+=`<g fill="var(--muted)" data-decorative="1"><circle cx="${U}" cy="${K-5}" r="1.2"/><circle cx="${U}" cy="${K}" r="1.2"/><circle cx="${U}" cy="${K+5}" r="1.2"/></g>`}const te=p[D]??[];let ee=v;if(B+=`<g${_(`layers.${D}.label`)}>`,te.forEach((H,W)=>{B+=`<text x="${U}" y="${ee+W*Lv}" class="t-name" text-anchor="middle">${S(H)}</text>`}),B+="</g>",ee+=h*Lv,C.units!==void 0&&(B+=`<text x="${U}" y="${ee}" class="t-sub c-ink" text-anchor="middle"${_(`layers.${D}.units`)}>${S(String(C.units))}</text>`,ee+=Iv),C.activation!==void 0&&(B+=`<text x="${U}" y="${ee}" class="t-sub" text-anchor="middle"${_(`layers.${D}.activation`)}>${S(C.activation)}</text>`,ee+=Iv),C.note!==void 0){const H=lt(C.note,18,1)[0]??"",W=H!==C.note?`<title>${S(C.note)}</title>`:"";B+=`<text x="${U}" y="${ee}" class="t-sub c-soft" text-anchor="middle"${_(`layers.${D}.note`)}>${W}${S(H)}</text>`}B+="</g>",T+=B}),T+="</g></svg>";const j=[...N].map(C=>aV[C]),P=ot(j),I=e.description!==void 0&&e.lede!==void 0?`${e.description} ${e.lede}`:e.description??e.lede,O=e.params!==void 0?`<div class="diagram-foot"><span${_("params")}><strong>Params</strong> ${S(e.params)}</span></div>`:"";return ct({tag:"NEURAL NET",...e.title!==void 0?{title:e.title}:{},...I!==void 0?{desc:I}:{},...P.length>0?{legendHtml:P}:{},...O.length>0?{footerHtml:O}:{}},T)}var xp=24,dV=7,Fo=15,uV=14,pV=10,jv=12,Pv=40,B2=36,kp=24;function fV(e,t,n){return e==="red"?"var(--negative)":e===void 0?"var(--muted)":n===1?"var(--accent)":Qi(t,n)}function hV(e){const t=e.nodes,n=new Map;t.forEach((W,K)=>n.set(W.id,K));const s=new Map,o=[];t.forEach((W,K)=>{const R=W.parent!==void 0?n.get(W.parent):void 0;R===void 0||R===K?o.push(K):s.set(R,[...s.get(R)??[],K])});const r=o.filter(W=>t[W]?.accent!==void 0&&t[W]?.accent!=="red"),i=new Map;o.forEach(W=>{const K=t[W]?.accent;i.set(W,fV(K,r.indexOf(W),r.length))});const l=[],d=new Set,u=W=>W.lines.length*Fo+(W.node.note!==void 0?uV:0)+pV,p=(W,K,R,z,Y)=>{if(d.has(W))return 0;d.add(W);const V=t[W];if(V===void 0)return 0;const re=lt(V.label,xp,2),Q=Math.max(24,...re.map(ve=>ve.length*dV),V.note!==void 0?Math.min(V.note.length,xp+4)*5.6:0),ne={node:V,index:W,depth:K,side:R,branch:z,lines:re,w:Q,y:Y};l.push(ne);const Z=s.get(W)??[];if(Z.length===0)return u(ne);let q=0;const de=[];for(const ve of Z){const we=l.length;q+=p(ve,K+1,R,z,Y+q);const $e=l[we];$e!==void 0&&$e.index===ve&&de.push($e)}const le=u(ne);q<le&&(q=le);const J=de[0],ue=de[de.length-1];return ne.y=J!==void 0&&ue!==void 0?(J.y+ue.y)/2:Y,q};let h=0,m=0;o.forEach((W,K)=>{const R=K%2===0?1:-1,z=R===1?h:m,Y=p(W,1,R,K,z+(z>0?jv:0));R===1?h+=Y+(z>0?jv:0):m+=Y+(z>0?jv:0)});const g=(W,K)=>Math.max(0,...l.filter(R=>R.side===W&&R.depth===K).map(R=>R.w)),v=Math.max(1,...l.map(W=>W.depth)),y=W=>{let K=0;for(let R=1;R<=v;R++){const z=g(W,R);z>0&&(K+=Pv+z)}return K},b=lt(e.center,xp,2),E=Math.max(60,...b.map(W=>W.length*7.5))+28,$=b.length>1?B2+Fo:B2,A=y(-1),T=y(1),N=Math.max(h,m,$),j=kp*2+A+E+T,P=kp*2+N,I=kp+A+E/2,O=kp+N/2,C=W=>O-(W===1?h:m)/2,D=W=>{let K=E/2;for(let R=1;R<W.depth;R++){const z=g(W.side,R);z>0&&(K+=Pv+z)}return K+=Pv,I+W.side*K},F=W=>C(W.side)+W.y+W.lines.length*Fo/2,U=W=>Math.round(W*10)/10,X=Sn("Mind map",e.center,[wt(o.length,"branch"),wt(t.length,"node")]);let B=`<svg viewBox="0 0 ${U(j)} ${U(P)}"${X.attrs}>${X.title}`;B+='<g fill="none" stroke-width="1.5" data-decorative="1">';for(const W of l){const K=i.get(W.branch)??"var(--muted)",R=D(W)-W.side*6,z=F(W)+W.lines.length*Fo/2+2;let Y,V;if(W.depth===1)Y=I+W.side*(E/2),V=O;else{const Q=l.find(ne=>ne.index===n.get(W.node.parent??""));if(Q===void 0)continue;Y=D(Q)+W.side*(Q.w+6),V=F(Q)+Q.lines.length*Fo/2+2}const re=Y+(R-Y)*.5;B+=`<path d="M${U(Y)} ${U(V)} Q${U(re)} ${U(z)} ${U(R)} ${U(z)}" stroke="${K}"/>`,B+=`<line x1="${U(R)}" y1="${U(z)}" x2="${U(R+W.side*(W.w+12))}" y2="${U(z)}" stroke="${K}" stroke-width="${W.depth===1?1.5:1}"/>`}B+="</g>",B+=`<g${_("center")}><rect x="${U(I-E/2)}" y="${U(O-$/2)}" width="${U(E)}" height="${$}" rx="${$/2}" fill="var(--paper)" stroke="var(--ink)" stroke-width="1.5"/>`,b.forEach((W,K)=>{B+=`<text x="${U(I)}" y="${U(O+4.5-(b.length-1)*Fo/2+K*Fo)}" class="t-name" text-anchor="middle">${S(W)}</text>`}),B+="</g>",B+=`<g${he("nodes")}>`;for(const W of l){const K=i.get(W.branch)??"var(--muted)",R=D(W),z=C(W.side)+W.y,Y=W.side===1?"start":"end",V=K!=="var(--muted)"?` style="fill:${K}"`:"";let re=`<g${_(`nodes.${W.index}`)}>`;if(W.lines.forEach((Q,ne)=>{re+=`<text x="${U(R)}" y="${U(z+11+ne*Fo)}" class="t-name" text-anchor="${Y}"${V}>${S(Q)}</text>`}),W.node.note!==void 0){const Q=lt(W.node.note,xp+4,1)[0]??"",ne=Q!==W.node.note?`<title>${S(W.node.note)}</title>`:"";re+=`<text x="${U(R)}" y="${U(z+W.lines.length*Fo+13)}" class="t-sub c-soft" text-anchor="${Y}"${_(`nodes.${W.index}.note`)}>${ne}${S(Q)}</text>`}re+="</g>",B+=re}B+="</g></svg>";const te=[],ee=new Set;for(const W of o){const K=i.get(W)??"var(--muted)";K==="var(--muted)"||ee.has(K)||(ee.add(K),te.push({swatch:"line",stroke:K,label:t[W]?.label??"",path:`nodes.${W}`}))}const H=ot(te);return ct({tag:"MIND MAP",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...H.length>0?{legendHtml:H}:{}},B)}var Cs=76,Dr=27,mV=2*Dr+22,Ov=2*Cs+44,kc=26,z2=30,Pa=118,bc=84,Rv=44,F2=22;function wc(e,t,n,s){const o=n-e,r=s-t;if(o===0&&r===0)return{x:e+Cs,y:t};const i=1/Math.sqrt(o*o/(Cs*Cs)+r*r/(Dr*Dr));return{x:e+o*i,y:t+r*i}}function gV(e,t,n){const s='fill="none" stroke="var(--ink)" stroke-width="1.5" stroke-linecap="round"';return e==="system"?`<rect x="${t-22}" y="${n-20}" width="44" height="40" rx="3" fill="var(--paper)" stroke="var(--ink)" stroke-width="1.25" stroke-dasharray="4 3"/><text x="${t}" y="${n+3.5}" class="t-eyebrow" text-anchor="middle">SYS</text>`:e==="time"?`<circle cx="${t}" cy="${n}" r="15" fill="var(--paper)" stroke="var(--ink)" stroke-width="1.5"/><path d="M${t} ${n-9} V${n} H${t+7}" ${s}/>`:`<circle cx="${t}" cy="${n-15}" r="6" fill="var(--paper)" stroke="var(--ink)" stroke-width="1.5"/><path d="M${t} ${n-9} V${n+6} M${t-11} ${n-3} H${t+11} M${t} ${n+6} L${t-9} ${n+20} M${t} ${n+6} L${t+9} ${n+20}" ${s}/>`}function vV(e){const t=e.actors,n=e.cases,s=e.links??[],o=e.relations??[],r=new Map(n.map((z,Y)=>[z.id,Y])),i=new Map(t.map((z,Y)=>[z.id,Y])),l=n.length>6?2:1,d=Math.ceil(n.length/l),u=n.some(z=>z.note!==void 0),p=mV+(u?12:0),h=kc*2+l*Ov-(Ov-2*Cs),m=z2+kc+d*p-(p-2*Dr)+kc,g=t.filter(z=>z.side!=="right"),v=t.filter(z=>z.side==="right"),y=g.length>0?Pa+Rv:0,b=v.length>0?Pa+Rv:0,E=20+y,$=F2,A=z=>{const Y=Math.floor(z/d),V=z%d;return{x:E+kc+Cs+Y*Ov,y:$+z2+kc+Dr+V*p}},T=z=>{const Y=z.map(Z=>{const q=s.filter(de=>de.from===Z.id&&r.has(de.to)).map(de=>A(r.get(de.to)??0).y);return{id:Z.id,y:q.length>0?q.reduce((de,le)=>de+le,0)/q.length:$+m/2}}),V=Y.map((Z,q)=>q).sort((Z,q)=>(Y[Z]?.y??0)-(Y[q]?.y??0)||Z-q),re=[],Q=$+bc/2;V.forEach((Z,q)=>{const de=re[q-1],le=Math.max(Y[Z]?.y??0,Q,de!==void 0?de+bc:-1/0);re.push(le)});const ne=new Map;return V.forEach((Z,q)=>ne.set(Y[Z]?.id??"",re[q]??0)),ne},N=T(g),j=T(v),P=z=>z.side==="right"?{x:E+h+Rv+Pa/2,y:j.get(z.id)??0}:{x:20+Pa/2,y:N.get(z.id)??0},I=Math.max($+m,...t.map(z=>P(z).y+bc/2)),O=20+y+h+b+20,C=I+F2,D=z=>Math.round(z*10)/10,F=Sn("Use-case diagram",e.system??e.title,[wt(t.length,"actor"),wt(n.length,"use case")]);let U=`<svg viewBox="0 0 ${D(O)} ${D(C)}"${F.attrs}>${F.title}`;U+='<defs><marker id="ucTri" viewBox="0 0 14 14" refX="13" refY="7" markerWidth="13" markerHeight="13" markerUnits="userSpaceOnUse" orient="auto-start-reverse"><path d="M1,1 L13,7 L1,13 z" fill="var(--paper)" stroke="var(--ink)" stroke-width="1.2"/></marker></defs>',U+=`<g${_("system")}><rect x="${E}" y="${$}" width="${D(h)}" height="${D(m)}" rx="8" fill="var(--paper-2)" stroke="var(--rule-solid)" stroke-width="1"/>`,e.system!==void 0&&(U+=`<text x="${E+14}" y="${$+19}" class="t-eyebrow">${S(e.system)}</text>`),U+="</g>";const X=[];U+=`<g${he("links")}>`,s.forEach((z,Y)=>{const V=t[i.get(z.from)??-1],re=r.get(z.to);if(V===void 0||re===void 0)return;const Q=P(V),ne=A(re),Z=wc(ne.x,ne.y,Q.x,Q.y),q=Q.x+(V.side==="right"?-24:24);U+=`<line x1="${D(q)}" y1="${D(Q.y)}" x2="${D(Z.x)}" y2="${D(Z.y)}" stroke="var(--muted)" stroke-width="1.25"${_(`links.${Y}`)}/>`,z.label!==void 0&&X.push({lx:(q+Z.x)/2,ly:(Q.y+Z.y)/2,label:z.label,path:`links.${Y}`})}),U+="</g>";const B=new Set;U+=`<g${he("relations")}>`,o.forEach((z,Y)=>{const V=r.get(z.from),re=r.get(z.to);if(V===void 0||re===void 0||V===re)return;B.add(z.kind);const Q=A(V),ne=A(re),Z=Math.floor(V/d)===Math.floor(re/d),q=Z&&Math.abs(V-re)===1,de='stroke="var(--muted)" stroke-width="1.25"',le=z.kind==="generalize"?"url(#ucTri)":"url(#skOpen)",J=z.kind==="generalize"?"":' stroke-dasharray="5 4"',ve=[z.kind==="generalize"?void 0:`«${z.kind}»`,z.label].filter(De=>De!==void 0).join(" ");let we,$e,je;if(Z&&!q){const De=Math.floor(V/d),Me=l===2?De===0?-1:1:v.length>0&&g.length===0?-1:1,Be=wc(Q.x,Q.y,Q.x+Me*Cs*2,Q.y+(ne.y-Q.y)*.3),Ge=wc(ne.x,ne.y,ne.x+Me*Cs*2,ne.y-(ne.y-Q.y)*.3),fe=Q.x+Me*(Cs+34),ge=(Q.y+ne.y)/2;we=`M${D(Be.x)} ${D(Be.y)} Q${D(fe)} ${D(ge)} ${D(Ge.x)} ${D(Ge.y)}`,$e=(Be.x+2*fe+Ge.x)/4,je=ge}else{const De=wc(Q.x,Q.y,ne.x,ne.y),Me=wc(ne.x,ne.y,Q.x,Q.y);we=`M${D(De.x)} ${D(De.y)} L${D(Me.x)} ${D(Me.y)}`,$e=(De.x+Me.x)/2,je=(De.y+Me.y)/2}U+=`<path d="${we}" fill="none" ${de}${J} marker-end="${le}"${_(`relations.${Y}`)}/>`,ve.length>0&&X.push({lx:$e,ly:je,label:ve,path:`relations.${Y}`})}),U+="</g>";const te=[];U+=`<g${he("cases")}>`,n.forEach((z,Y)=>{const V=A(Y);te.push({x:V.x-Cs,y:V.y-Dr,w:2*Cs,h:2*Dr});const re=lt(z.name,18,2),Q=z.note!==void 0?lt(z.note,22,1)[0]??"":void 0,ne=re.length*14+(Q!==void 0?12:0),Z=V.y+4.5-ne/2+7;let q=`<g${_(`cases.${Y}`)}><ellipse cx="${D(V.x)}" cy="${D(V.y)}" rx="${Cs}" ry="${Dr}" fill="var(--paper)" stroke="var(--ink)" stroke-width="1.5"/>`;if(q+=`<g${_(`cases.${Y}.name`)}>`,re.forEach((de,le)=>{q+=`<text x="${D(V.x)}" y="${D(Z+le*14)}" class="t-name" text-anchor="middle">${S(de)}</text>`}),q+="</g>",Q!==void 0){const de=Q!==z.note?`<title>${S(z.note)}</title>`:"";q+=`<text x="${D(V.x)}" y="${D(Z+re.length*14-1)}" class="t-sub" text-anchor="middle"${_(`cases.${Y}.note`)}>${de}${S(Q)}</text>`}q+="</g>",U+=q}),U+="</g>";const ee=new Set;U+=`<g${he("actors")}>`,t.forEach((z,Y)=>{const V=z.kind??"person";ee.add(V);const re=P(z);te.push({x:re.x-Pa/2,y:re.y-bc/2,w:Pa,h:bc});const Q=lt(z.name,16,2);let ne=`<g${_(`actors.${Y}`)}>${gV(V,re.x,re.y)}`;ne+=`<g${_(`actors.${Y}.name`)}>`,Q.forEach((Z,q)=>{ne+=`<text x="${D(re.x)}" y="${D(re.y+34+q*14)}" class="t-name" text-anchor="middle">${S(Z)}</text>`}),ne+="</g></g>",U+=ne}),U+="</g>";const{overlay:H,legend:W}=Ws(X,te,{skin:!0});U+=H,U+="</svg>";const K=[{swatch:"node-stadium",label:"use case"}];ee.has("system")&&K.push({swatch:"node-dashed",label:"external system"}),s.length>0&&K.push({swatch:"line",label:"association"}),B.has("include")&&K.push({swatch:"edge-dashed",label:"«include»"}),B.has("extend")&&K.push({swatch:"edge-dashed",label:"«extend»"}),B.has("generalize")&&K.push({swatch:"edge-implements",label:"generalizes"});const R=ot(K);return ct({tag:"USE CASE",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...R.length>0?{legendHtml:R}:{}},U+W)}var Dv=168,q2=128,H2=56,yV=54,ho=12,W2=26,U2=13,Vp=5,Cr={padX:18,padTop:42,padBot:14};function K2(e){const t=e??[];return t.length<=Vp?[...t]:[...t.slice(0,Vp),`+${t.length-Vp} more`]}function xV(e){const t=e.packages,n=e.deps??[],s=new Set(t.map(Q=>Q.id)),o=new Set(t.map(Q=>Q.parent).filter(Q=>Q!==void 0&&s.has(Q))),r=t.filter(Q=>!o.has(Q.id)),i=new Set(r.map(Q=>Q.id)),l=nr(r,n.filter(Q=>i.has(Q.from)&&i.has(Q.to)),e.dir??"LR"),d=new Map(l.map(Q=>[Q.id,Q])),u=new Map(t.map(Q=>[Q.id,Q])),p=(Q,ne=0)=>{const Z=Q.parent!==void 0?u.get(Q.parent):void 0;return Z===void 0||ne>t.length?0:1+p(Z,ne+1)},h=Math.max(0,...t.map(Q=>p(Q))),m=r.map(Q=>K2(Q.contains)),g=Math.max(0,...m.map(Q=>Q.length)),v=ho+W2+(g>0?6+g*U2+8:8),y=26+h*Cr.padX,b=26+h*Cr.padTop,E=20+h*Cr.padBot,$=Math.max(1,...l.map(Q=>Q.col)),A=Math.max(1,...l.map(Q=>Q.row)),T=Q=>y+(Q-1)*(Dv+q2),N=Q=>b+(Q-1)*(v+H2),j=y*2+$*Dv+($-1)*q2,P=b+A*v+(A-1)*H2+E,I=new Map,O=(Q,ne=0)=>{const Z=I.get(Q);if(Z!==void 0)return Z;const q=d.get(Q);if(q!==void 0){const $e={x:T(q.col),y:N(q.row),w:Dv,h:v};return I.set(Q,$e),$e}if(ne>t.length)return;const de=t.filter($e=>$e.parent===Q).map($e=>O($e.id,ne+1));let le=1/0,J=1/0,ue=-1/0,ve=-1/0;for(const $e of de)$e!==void 0&&(le=Math.min(le,$e.x),J=Math.min(J,$e.y),ue=Math.max(ue,$e.x+$e.w),ve=Math.max(ve,$e.y+$e.h));if(!Number.isFinite(le))return;const we={x:le-Cr.padX,y:J-Cr.padTop,w:ue-le+2*Cr.padX,h:ve-J+Cr.padTop+Cr.padBot};return I.set(Q,we),we},C=Sn("Package diagram",e.title,[wt(t.length,"package"),wt(n.length,"dependency","dependencies")]);let D=`<svg viewBox="0 0 ${j} ${P}"${C.attrs}>${C.title}`;const F=(Q,ne)=>{const Z=ne?"var(--ink)":"var(--rule-solid)",q=ne?1.5:1,de=ne?"var(--paper)":"var(--paper-2)",le=Math.min(yV,Q.w/2);return`<path d="M${Q.x} ${Q.y+ho} V${Q.y+2} Q${Q.x} ${Q.y} ${Q.x+2} ${Q.y} H${Q.x+le-2} Q${Q.x+le} ${Q.y} ${Q.x+le} ${Q.y+2} V${Q.y+ho}" fill="${de}" stroke="${Z}" stroke-width="${q}"/><rect x="${Q.x}" y="${Q.y+ho}" width="${Q.w}" height="${Q.h-ho}" fill="${de}" stroke="${Z}" stroke-width="${q}"/>`},U=t.map((Q,ne)=>({p:Q,pi:ne,depth:p(Q)})).filter(({p:Q})=>o.has(Q.id)).sort((Q,ne)=>Q.depth-ne.depth||Q.pi-ne.pi);let X=!1;D+=`<g${he("packages")}>`;for(const{p:Q,pi:ne}of U){const Z=O(Q.id);if(Z===void 0)continue;X=!0;const q=Q.stereotype!==void 0?`<text x="${Z.x+Z.w-10}" y="${Z.y+ho+16}" class="t-eyebrow" text-anchor="end"${_(`packages.${ne}.stereotype`)}>«${S(Q.stereotype)}»</text>`:"";D+=`<g${_(`packages.${ne}`)}>`+F(Z,!1)+`<text x="${Z.x+10}" y="${Z.y+ho+17}" class="t-name c-muted"${_(`packages.${ne}.name`)}>${S(Q.name)}</text>`+q+"</g>"}const B=[],te=new Set,ee=qs(n),H=Hs(n,Q=>O(Q));let W=`<g${he("deps")}>`;n.forEach((Q,ne)=>{const Z=O(Q.from),q=O(Q.to);if(Z===void 0||q===void 0||Q.from===Q.to)return;Q.kind!==void 0&&te.add(Q.kind);const de=Fs(Z,q,ee[ne]??0,H[ne]??0);W+=`<path d="${de.d}" fill="none" stroke="var(--muted)" stroke-width="1.5" stroke-dasharray="5 4" marker-end="url(#skArrow)"${_(`deps.${ne}`)}/>`;const le=[Q.kind!==void 0?`«${Q.kind}»`:void 0,Q.label].filter(J=>J!==void 0).join(" ");B.push({lx:de.lx,ly:de.ly,...le.length>0?{label:le}:{},path:`deps.${ne}`})}),W+="</g>";let K="";const R=[];t.forEach((Q,ne)=>{if(d.get(Q.id)===void 0)return;const q=O(Q.id);if(q===void 0)return;R.push(q);const de=K2(Q.contains),le=Q.stereotype!==void 0?12:20,J=lt(Q.name,le,1)[0]??"",ue=J!==Q.name?`<title>${S(Q.name)}</title>`:"";let ve=`<g${_(`packages.${ne}`)}>${F(q,!0)}`;if(ve+=`<text x="${q.x+10}" y="${q.y+ho+17}" class="t-name"${_(`packages.${ne}.name`)}>${ue}${S(J)}</text>`,Q.stereotype!==void 0&&(ve+=`<text x="${q.x+q.w-10}" y="${q.y+ho+16}" class="t-eyebrow" text-anchor="end"${_(`packages.${ne}.stereotype`)}>«${S(Q.stereotype)}»</text>`),de.length>0){const we=q.y+ho+W2;ve+=`<line x1="${q.x}" y1="${we}" x2="${q.x+q.w}" y2="${we}" stroke="var(--rule-solid)" stroke-width="1"/>`,ve+=`<g${he(`packages.${ne}.contains`)}>`,de.forEach(($e,je)=>{const De=je>=Vp,Me=De?"":_(`packages.${ne}.contains.${je}`);ve+=`<text x="${q.x+10}" y="${we+6+(je+1)*U2-2}" class="t-sub${De?" c-soft":" c-ink"}"${Me}>${S($e)}</text>`}),ve+="</g>"}ve+="</g>",K+=ve}),D+=K+"</g>"+W;const{overlay:z,legend:Y}=Ws(B,R,{skin:!0});D+=z+"</svg>";const V=[{swatch:"node",label:"package"}];X&&V.push({swatch:"node-fill2",label:"parent package"}),n.length>0&&V.push({swatch:"edge-dashed",label:"dependency"});for(const Q of["import","use","access","merge"])te.has(Q)&&V.push({swatch:"chip",chip:`«${Q}»`,label:Q});const re=ot(V);return ct({tag:"PACKAGES",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...re.length>0?{legendHtml:re}:{}},D+Y)}var kV=["critical","high","medium","low","info"],V2={critical:0,high:1,medium:2,low:3,info:4};function bV(e){return e.map((t,n)=>({f:t,i:n})).sort((t,n)=>V2[t.f.severity]-V2[n.f.severity]||t.i-n.i)}function wV(e){const t=new Map;for(const n of e)t.set(n.severity,(t.get(n.severity)??0)+1);return kV.filter(n=>(t.get(n)??0)>0).map(n=>({severity:n,n:t.get(n)??0}))}function G2(e,t=""){return`<span class="rk-sev rk-sev-${e} au-sev${t}">`}function $V(e){const t=e.findings,n=g=>t.some(v=>v[g]!==void 0&&String(v[g]).length>0),s={id:n("id"),evidence:n("evidence"),fix:n("fix"),owner:n("owner"),status:n("status")},o=[];e.scope!==void 0&&o.push(`<span class="au-m"${_("scope")}><span class="au-k">scope</span>${S(e.scope)}</span>`),e.date!==void 0&&o.push(`<span class="au-m"${_("date")}><span class="au-k">date</span>${S(e.date)}</span>`),e.auditor!==void 0&&o.push(`<span class="au-m"${_("auditor")}><span class="au-k">auditor</span>${S(e.auditor)}</span>`);const r=e.title!==void 0||o.length>0?'<div class="au-head">'+(e.title!==void 0?`<span class="au-title"${_("title")}>${S(e.title)}</span>`:"")+(o.length>0?`<span class="au-meta">${o.join("")}</span>`:"")+"</div>":"",i=e.description!==void 0?`<p class="au-desc"${_("description")}>${S(e.description)}</p>`:"",l=wV(t).map(({severity:g,n:v})=>`${G2(g," au-count")}<b class="au-n">${v}</b> ${g}</span>`).join(""),d=`<div class="au-counts"><span class="au-total t-sub">${t.length} finding${t.length===1?"":"s"}</span>${l}</div>`,u=(g,v="")=>`<th${v!==""?` class="${v}"`:""}>${g}</th>`,p="<thead><tr>"+(s.id?u("ID","au-c-id"):"")+u("Severity","au-c-sev")+u("Finding")+(s.evidence?u("Evidence"):"")+(s.fix?u("Fix"):"")+(s.owner?u("Owner","au-c-owner"):"")+(s.status?u("Status","au-c-status"):"")+"</tr></thead>",h=bV(t).map(({f:g,i:v})=>{const y=`findings.${v}`,b=g.area!==void 0?`<span class="au-area"${_(`${y}.area`)}>${S(g.area)}</span>`:"",E=g.ref!==void 0?`<span class="au-ref"${_(`${y}.ref`)}>${S(g.ref)}</span>`:"",$=g.status!==void 0?`<span class="rk-status au-st au-st-${g.status}"${_(`${y}.status`)}>${S(g.status)}</span>`:"";return`<tr class="au-row au-sev-row-${g.severity}"${_(y)}>`+(s.id?`<td class="au-id"${_(`${y}.id`)}>${S(g.id??"")}</td>`:"")+`<td class="au-c-sev">${G2(g.severity)}${S(g.severity)}</span></td><td class="au-finding"><span class="au-ftitle"${_(`${y}.title`)}>${S(g.title)}</span>${b}${E}</td>`+(s.evidence?`<td class="au-evidence"${_(`${y}.evidence`)}>${S(g.evidence??"")}</td>`:"")+(s.fix?`<td class="au-fix"${_(`${y}.fix`)}>${S(g.fix??"")}</td>`:"")+(s.owner?`<td class="au-owner"${_(`${y}.owner`)}>${S(g.owner??"")}</td>`:"")+(s.status?`<td class="au-c-status">${$}</td>`:"")+"</tr>"}).join(""),m=`<div class="au-scroll"><table class="au-table">${p}<tbody${he("findings")}>${h}</tbody></table></div>`;return`<div class="audit">${r}${i}${d}${m}</div>`}var SV={pass:"✓",fail:"✗",partial:"◐",na:"—",pending:"○"},EV={pass:"pass",fail:"fail",partial:"partial",na:"n/a",pending:"pending"};function MV(e){const t={pass:0,fail:0,partial:0,pending:0,na:0};for(const o of e)t[o.status]+=1;const n=t.pass+t.fail+t.partial+t.pending,s=n===0?null:(t.pass+t.partial/2)/n*100;return{...t,rate:s}}function Y2(e,t){const n=e.evidence!==void 0?`<span class="cl-evidence"${_(`${t}.evidence`)}>${S(e.evidence)}</span>`:"",s=e.note!==void 0?`<span class="cl-note"${_(`${t}.note`)}>${S(e.note)}</span>`:"",o=e.ref!==void 0?`<span class="cl-ref"${_(`${t}.ref`)}>${S(e.ref)}</span>`:"";return`<div class="cl-item cl-s-${e.status}"${_(t)}><span class="cl-verdict cl-v-${e.status}"${_(`${t}.status`)}><span class="cl-glyph" aria-hidden="true">${SV[e.status]}</span>${EV[e.status]}</span><div class="cl-body"><span class="cl-text"${_(`${t}.item`)}>${S(e.item)}</span>${n}${s}${o}</div></div>`}function AV(e){const t=e.items??[],n=e.groups??[],s=[...t,...n.flatMap(h=>h.items)],o=e.title!==void 0||e.standard!==void 0?'<div class="cl-head">'+(e.title!==void 0?`<span class="cl-title"${_("title")}>${S(e.title)}</span>`:"")+(e.standard!==void 0?`<span class="cl-standard"${_("standard")}>${S(e.standard)}</span>`:"")+"</div>":"",r=e.description!==void 0?`<p class="cl-desc"${_("description")}>${S(e.description)}</p>`:"";let i="";t.length>0&&(i+=`<div class="cl-items"${he("items")}>${t.map((h,m)=>Y2(h,`items.${m}`)).join("")}</div>`),n.length>0&&(i+=`<div class="cl-groups"${he("groups")}>`,n.forEach((h,m)=>{i+=`<div class="cl-group"${_(`groups.${m}`)}><div class="cl-group-label t-eyebrow"${_(`groups.${m}.label`)}>${S(h.label)}</div><div class="cl-items"${he(`groups.${m}.items`)}>${h.items.map((g,v)=>Y2(g,`groups.${m}.items.${v}`)).join("")}</div></div>`}),i+="</div>");const l=MV(s),d=[`${l.pass} pass`,`${l.fail} fail`];l.partial>0&&d.push(`${l.partial} partial`),l.pending>0&&d.push(`${l.pending} pending`),l.na>0&&d.push(`${l.na} n/a`);const u=l.rate===null?"—":`${Math.round(l.rate)}%`,p=s.length>0?`<div class="cl-foot"><span class="cl-counts">${d.join(" · ")}</span><span class="cl-rate">pass rate <b>${u}</b></span></div>`:"";return`<div class="checklist">${o}${r}${i}${p}</div>`}function Bv(e){return`<div class="evc-section">${S(e)}</div>`}function X2(e,t){const n=e.map((s,o)=>`<li${_(`${t}.${o}`)}>${S(s)}</li>`).join("");return`<ul class="mc-list"${he(t)}>${n}</ul>`}function CV(e){const t=e.some(o=>o.split!==void 0),n=e.some(o=>o.note!==void 0),s=e.map((o,r)=>{const i=`metrics.${r}`;return`<tr${_(i)}><td class="evc-fname"${_(`${i}.name`)}>${S(o.name)}</td><td class="mc-value"${_(`${i}.value`)}>${S(String(o.value))}</td>`+(t?`<td class="evc-type"${_(`${i}.split`)}>${S(o.split??"")}</td>`:"")+(n?`<td class="evc-desc"${_(`${i}.note`)}>${S(o.note??"")}</td>`:"")+"</tr>"}).join("");return'<table class="evc-table mc-metrics"><thead><tr><th>Metric</th><th class="mc-value">Value</th>'+(t?"<th>Split</th>":"")+(n?"<th>Note</th>":"")+`</tr></thead><tbody${he("metrics")}>${s}</tbody></table>`}function NV(e){const n='<div class="evc-head">'+('<span class="evc-eyebrow t-eyebrow">MODEL'+(e.version!==void 0?`<span class="evc-sep">·</span><span${_("version")}>${S(e.version)}</span>`:"")+"</span>")+`<span class="evc-name"${_("name")}>${S(e.name)}</span>`+(e.task!==void 0?`<span class="mc-task"${_("task")}><span class="t-eyebrow">task</span>${S(e.task)}</span>`:"")+"</div>",s=[];e.description!==void 0&&s.push(`<p class="evc-desc-p"${_("description")}>${S(e.description)}</p>`);const o=[],r=(u,p,h)=>{p!==void 0&&o.push(`<div class="mc-cell"${_(h)}><span class="mc-k t-eyebrow">${u}</span><span class="mc-v">${S(p)}</span></div>`)};r("architecture",e.architecture,"architecture"),r("params",e.params,"params"),r("owner",e.owner,"owner"),r("license",e.license,"license"),o.length>0&&s.push(`<div class="mc-spec">${o.join("")}</div>`);const i=[["Intended use","intendedUse",e.intendedUse],["Out of scope","outOfScope",e.outOfScope],["Training data","trainingData",e.trainingData]];for(const[u,p,h]of i)h!==void 0&&h.length>0&&s.push(Bv(u)+X2(h,p));const l=e.metrics??[];l.length>0&&s.push(Bv("Metrics")+CV(l));const d=[["Limitations","limitations",e.limitations],["Ethics","ethics",e.ethics]];for(const[u,p,h]of d)h!==void 0&&h.length>0&&s.push(Bv(u)+X2(h,p));return`<div class="modelcard">${n}<div class="evc-body">${s.join("")}</div></div>`}var Oa=8,bp=22,Xa=150,qr=50,Uc=14,TV=5,Q2=18,_V=16,LV=23,Z2=15,J2=13,IV={done:"var(--paper-2)",current:"var(--accent)",todo:"var(--paper)",negative:"var(--negative-tint)"},jV={done:"var(--rule-solid)",current:"var(--accent)",todo:"var(--ink)",negative:"var(--negative)"},PV={done:"t-name c-muted",current:"t-name ch-on-accent",todo:"t-name c-ink",negative:"t-name c-negative"};function eS(e,t,n){const s=lt(e,t,n),o=e.trim().split(/\s+/).join(" ");let r=s.join(" ")!==o;return{lines:s.map((l,d)=>l.length<=t&&!(r&&d===s.length-1)?l:(r=!0,`${l.slice(0,Math.max(1,t-1)).trimEnd()}…`)),cut:r}}function OV(e,t){const n=s=>s.toFixed(1);return[`${n(e)},${n(t)}`,`${n(e+Xa-Uc)},${n(t)}`,`${n(e+Xa)},${n(t+qr/2)}`,`${n(e+Xa-Uc)},${n(t+qr)}`,`${n(e)},${n(t+qr)}`,`${n(e+Uc)},${n(t+qr/2)}`].join(" ")}function RV(e){const t=e.steps,n=t.length,s=e.current!==void 0&&Number.isFinite(e.current)?Math.round(e.current):void 0,o=s!==void 0&&s>=1&&s<=n,r=(N,j)=>j==="red"?"negative":o?N+1===s?"current":N+1<s?"done":"todo":"todo",i=t.map(N=>eS(N.label,_V,2)),l=t.map(N=>N.desc!==void 0?eS(N.desc,LV,2):{lines:[],cut:!1}),d=Math.min(Oa,n),u=Math.ceil(n/Oa),p=Xa-Uc+TV,h=bp*2+(d-1)*p+Xa,m=[];for(let N=0;N<u;N+=1){const j=l.slice(N*Oa,(N+1)*Oa),P=Math.max(0,...j.map(I=>I.lines.length));m.push(qr+(P>0?8+P*J2:0))}const g=bp*2+m.reduce((N,j)=>N+j,0)+(u-1)*Q2,v=N=>N.toFixed(1),y=Hy("Process chevrons",e.title,[wt(n,"step")]);let b=`<svg viewBox="0 0 ${v(h)} ${v(g)}" role="img" aria-label="${S(y)}"><title>${S(y)}</title>`;const E=new Set;b+=`<g${he("steps")}>`;let $=bp;t.forEach((N,j)=>{const P=Math.floor(j/Oa),I=j%Oa;I===0&&P>0&&($+=(m[P-1]??qr)+Q2);const O=bp+I*p,C=$,D=r(j,N.accent);E.add(D);const F=i[j]??{lines:[N.label],cut:!1},U=l[j]??{lines:[],cut:!1},X=O+Xa/2+Uc/4;let B=`<g class="ch-step ch-${D}"${_(`steps.${j}`)}>`;(F.cut||U.cut)&&(B+=`<title>${S(N.desc!==void 0?`${N.label} — ${N.desc}`:N.label)}</title>`),B+=`<polygon points="${OV(O,C)}" fill="${IV[D]}" stroke="${jV[D]}" stroke-width="${D==="current"?1.5:1.25}" stroke-linejoin="round"/>`;const te=F.lines.length,ee=C+qr/2-(te-1)*Z2/2+4.5;if(F.lines.forEach((H,W)=>{B+=`<text x="${v(X)}" y="${v(ee+W*Z2)}" class="${PV[D]}" text-anchor="middle"${W===0?_(`steps.${j}.label`):""}>${S(H)}</text>`}),U.lines.length>0){const H=C+qr+8+10;U.lines.forEach((W,K)=>{B+=`<text x="${v(X)}" y="${v(H+K*J2)}" class="t-sub c-muted" text-anchor="middle"${K===0?_(`steps.${j}.desc`):""}>${S(W)}</text>`})}b+=B+"</g>"}),b+="</g></svg>";const A=[];E.has("done")&&A.push({swatch:"node-fill2",label:"done"}),E.has("current")&&A.push({swatch:"node-accent",label:"current step"}),E.has("todo")&&A.push({swatch:"node",label:o?"upcoming":"step"}),E.has("negative")&&A.push({swatch:"node-negative",label:"failure / exit"});const T=ot(A);return ct({tag:"CHEVRONS",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...T.length>0?{legendHtml:T}:{}},b)}var Nr=22,DV=150,BV=260,zV=26,$c=24,tS=6,zv=10,Fv=6,RA=6.4,FV=22,qv=15,qV={done:'fill="var(--paper-2)" stroke="var(--rule-solid)" stroke-width="1"',current:'fill="var(--paper)" stroke="var(--accent)" stroke-width="1.5"',next:'fill="var(--paper)" stroke="var(--ink)" stroke-width="1.25"',later:'fill="var(--paper)" stroke="var(--muted)" stroke-width="1.25" stroke-dasharray="4 3"',risk:'fill="var(--negative-tint)" stroke="var(--negative)" stroke-width="1.25"'},HV={done:"rm-label t-sub c-muted",current:"rm-label t-sub c-ink rm-current",next:"rm-label t-sub c-ink",later:"rm-label t-sub c-soft",risk:"rm-label t-sub c-negative"},WV={done:"node-fill2",current:"node-accent-outline",next:"node",later:"node-dashed",risk:"node-negative"},UV=["done","current","next","later","risk"];function KV(e){const t=[];return e.map(n=>{let s=t.findIndex(o=>o.every(r=>n.to<r.from||n.from>r.to));return s===-1&&(s=t.length,t.push([])),t[s]?.push({from:n.from,to:n.to}),{...n,lane:s}})}function VV(e,t){const n=Math.max(3,Math.floor(t/RA));return e.length<=n?{text:e,cut:!1}:{text:`${e.slice(0,n-1).trimEnd()}…`,cut:!0}}function GV(e){const t=e.periods,n=new Map;t.forEach((D,F)=>{n.has(D)||n.set(D,F)});const s=e.themes!==void 0?[...e.themes]:[];if(e.themes===void 0)for(const D of e.items)s.includes(D.theme)||s.push(D.theme);const o=new Map;for(const D of s)o.set(D,[]);e.items.forEach((D,F)=>{const U=o.get(D.theme),X=n.get(D.from),B=D.to!==void 0?n.get(D.to):X;U===void 0||X===void 0||B===void 0||U.push({i:F,item:D,from:Math.min(X,B),to:Math.max(X,B)})});const r=s.map(D=>KV(o.get(D)??[])),i=r.flat().filter(D=>D.from===D.to),l=Math.max(0,...i.map(D=>D.item.label.length*RA+16+Fv*2+4)),d=Math.min(BV,Math.max(DV,Math.ceil(l))),u=s.map(D=>lt(D,FV,3)),h=Nr+Math.max(60,...u.map(D=>Math.max(...D.map(F=>F.length))*7.2))+14,m=t.length*d,g=h+m+Nr,v=r.map((D,F)=>{const U=Math.max(1,...D.map(te=>te.lane+1)),X=U*$c+(U-1)*tS,B=(u[F]?.length??1)*qv;return Math.max(X,B)+zv*2}),y=Nr+zV,b=v.reduce((D,F)=>D+F,0),E=y+b+Nr,$=D=>D.toFixed(1),A=r.reduce((D,F)=>D+F.length,0),T=Hy("Roadmap",e.title,[wt(s.length,"theme"),wt(t.length,"period"),wt(A,"item")]);let N=`<svg viewBox="0 0 ${$(g)} ${$(E)}" role="img" aria-label="${S(T)}"><title>${S(T)}</title>`;N+=`<g${he("periods")}>`,t.forEach((D,F)=>{const U=h+F*d;N+=`<text x="${$(U+d/2)}" y="${$(Nr+12)}" class="t-eyebrow" text-anchor="middle"${_(`periods.${F}`)}>${S(D)}</text>`,N+=`<line x1="${$(U)}" y1="${$(y)}" x2="${$(U)}" y2="${$(y+b)}" stroke="var(--rule)" stroke-width="1"${ut}/>`}),N+="</g>",N+=`<line x1="${$(h+m)}" y1="${$(y)}" x2="${$(h+m)}" y2="${$(y+b)}" stroke="var(--rule)" stroke-width="1"${ut}/>`,N+=`<line x1="${$(Nr)}" y1="${$(y)}" x2="${$(h+m)}" y2="${$(y)}" stroke="var(--rule-solid)" stroke-width="1"/>`;const j=new Set;let P=y;N+=`<g${he("items")}>`,s.forEach((D,F)=>{const U=v[F]??$c+zv*2,X=u[F]??[D],B=P+U/2-(X.length-1)*qv/2+4.5,te=e.themes!==void 0?_(`themes.${F}`):"";X.forEach((ee,H)=>{N+=`<text x="${$(Nr)}" y="${$(B+H*qv)}" class="t-name c-ink rm-theme"${H===0?te:""}>${S(ee)}</text>`});for(const ee of r[F]??[]){const H=ee.item.status??"next";j.add(H);const W=h+ee.from*d+Fv,K=(ee.to-ee.from+1)*d-Fv*2,R=P+zv+ee.lane*($c+tS),z=VV(ee.item.label,K-16),Y=ee.item.note!==void 0?`${ee.item.label} — ${ee.item.note}`:ee.item.label;N+=`<g class="rm-item rm-${H}"${_(`items.${ee.i}`)}><title>${S(Y)}</title><rect x="${$(W)}" y="${$(R)}" width="${$(K)}" height="${$c}" rx="3" ${qV[H]}/><text x="${$(W+8)}" y="${$(R+$c/2+3.5)}" class="${HV[H]}"${_(`items.${ee.i}.label`)}>${S(z.text)}</text></g>`}P+=U,N+=`<line x1="${$(Nr)}" y1="${$(P)}" x2="${$(h+m)}" y2="${$(P)}" stroke="var(--rule)" stroke-width="1"${ut}/>`}),N+="</g>";const I=e.now!==void 0?n.get(e.now):void 0;if(I!==void 0){const D=h+I*d;N+=`<g class="rm-now"${_("now")}><line x1="${$(D)}" y1="${$(y-6)}" x2="${$(D)}" y2="${$(y+b)}" stroke="var(--ink)" stroke-width="1.25" stroke-dasharray="4 3"/><text x="${$(D+5)}" y="${$(y-9)}" class="t-eyebrow c-ink">now</text></g>`}N+="</svg>";const O=UV.filter(D=>j.has(D)).map(D=>({swatch:WV[D],label:D==="current"?"current — in progress":D==="next"?"next / planned":D}));I!==void 0&&O.push({swatch:"line-dashed",stroke:"var(--ink)",label:"now"});const C=ot(O);return ct({tag:"ROADMAP",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...C.length>0?{legendHtml:C}:{}},N)}var DA={meta:l8,callout:f8,table:K8,sequence:q8,erd:x8,userstory:Y8,timeline:G8,kanban:M8,prose:X8,glossary:Z8,proscons:J8,cvt:ez,stats:nz,code:fz,agenda:hz,tree:kz,pyramid:bz,flow:p9,state:f9,dfd:h9,journey:x9,gantt:S9,graph:E9,quadrant:M9,swimlane:C9,c4:I9,uml:R9,frontend:B9,cluster:eq,block:Z9,felogic:aq,wireframe:uq,endpoint:gq,pullquote:vq,layers:xq,matrix:$q,anatomy:Sq,composition:Eq,drivers:Aq,options:Nq,spec:_q,list:Pq,stories:Fq,pattern:Uq,gallery:Gq,chart:NH,figure:TH,steps:LH,faq:PH,envelope:DH,slo:qH,swot:WH,okr:GH,persona:QH,changelog:eW,team:nW,heatmap:rW,scorecard:aW,risk:dW,palette:xW,typescale:wW,dodont:SW,inventory:AW,array:NW,linkedlist:LW,bintree:jW,hashmap:RW,agentloop:zW,trace:HW,prompt:VW,context:GW,archmap:eU,divider:tU,bignumber:sU,takeaways:oU,statustable:cU,cycle:dU,benchmark:hU,sankey:bU,gitgraph:wU,treemap:EU,packet:CU,venn:jU,wardley:FU,harvey:qU,scqa:WU,scenarios:UU,fishbone:VU,storymap:QU,eventcontract:JU,saga:lK,slopegraph:hK,spans:AK,rollout:TK,perfbudget:RK,percentiles:FK,timing:GK,threatmodel:nV,neuralnet:cV,mindmap:hV,usecase:vV,pkg:xV,audit:$V,checklist:AV,modelcard:NV,chevrons:RV,roadmap:GV};function BA(){return'<svg width="0" height="0" style="position:absolute" aria-hidden="true"><defs><marker id="gArrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="var(--charcoal)"/></marker><marker id="gSoft" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="var(--gray)"/></marker><marker id="gErr" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="var(--negative)"/></marker><marker id="gTri" viewBox="0 0 14 14" refX="13" refY="7" markerWidth="14" markerHeight="14" orient="auto-start-reverse"><path d="M1,1 L13,7 L1,13 z" fill="var(--paper)" stroke="var(--purple)" stroke-width="1.2"/></marker><marker id="skArrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="var(--muted)"/></marker><marker id="skOpen" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path d="M1,1 L9,5 L1,9" fill="none" stroke="var(--muted)" stroke-width="1.6"/></marker><marker id="skErr" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="var(--negative)"/></marker><marker id="skAccent" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="var(--accent)"/></marker><filter id="gshadow" x="-20%" y="-20%" width="140%" height="170%"><feDropShadow dx="0" dy="2" stdDeviation="3" flood-color="var(--ink)" flood-opacity="0.13"/></filter></defs></svg>'}var zA="textbook",YV={textbook:{label:"Editorial",vars:{}}};function XV(e){const t=YV[e].vars,n=[];for(const s of Object.keys(t))n.push(`${s}:${t[s]};`);return n.join("")}function FA(e){const t=new WeakMap;for(let n=0;n<e.length-1;n++){const s=e[n],o=e[n+1];if(s===void 0||o===void 0||s.kind!=="markdown"||o.kind==="markdown")continue;const r=Z6(s.text);r!==void 0&&t.set(o,r.text)}return t}function qA(e){return e<10?`0${e}`:String(e)}var QV=new Set(["divider","takeaways"]);function ZV(e){if(e===null||typeof e!="object")return{};const t=e,n={};return typeof t.title=="string"&&t.title.length>0&&(n.title=t.title),typeof t.lede=="string"&&t.lede.length>0&&(n.lede=t.lede),n}function JV(e,t,n,s){const o=`<div class="section-num">SECTION ${qA(e)} · ${S(t)}</div>`;if(n===void 0&&s===void 0)return`<div class="section-head bare">${o}</div>`;const r=n!==void 0?`<h2 class="section-title"${_("title")}>${S(n)}</h2>`:"",i=s!==void 0?`<p class="section-lede"${_("lede")}>${S(s)}</p>`:"";return'<div class="section-head">'+o+r+i+"</div>"}function eG(e,t){const n=DA[e];return n(t)}function tG(e,t){if(e.kind==="meta")return"";if(e.parseError!==void 0)return`<div class="err">${S(e.kind)} block — parse error:
2838
- ${S(e.parseError)}</div>`;if(e.data===null||e.data===void 0)return"";const{title:n,lede:s}=ZV(e.data),o=QV.has(e.kind),r=!o&&n!==void 0&&typeof e.data=="object"?{...e.data,title:void 0}:e.data,i=eG(e.kind,r),l=t.headingFor.get(e),d=!o&&n!==void 0&&l!==void 0&&qM(l,n),u=n??(o?void 0:l);t.sectionNum+=1;const p=t.sectionNum,h=`section-${qA(p)}`;t.sections.push({id:h,num:p,label:Aw(e),...u!==void 0?{title:u}:{},...e.id!==void 0?{blockId:e.id}:{}});const m=JV(p,Aw(e),o||d?void 0:n,s),g=e.id!==void 0?`<span class="block-anchor" id="${S(e.id)}" aria-hidden="true"></span>`:"",v=e.id!==void 0?` data-block-id="${S(e.id)}"`:"";return`<section id="${h}" class="section-block"${v}>${g}${m}${i}</section>`}function T0(e,t){return e.kind==="markdown"?g0(e.text):tG(e,t)}function HA(e,t){let n=XV(e);if(t!==void 0)for(const s of Object.keys(t))n+=`${s}:${t[s]};`;return n}function Zi(e,t={}){const n=e.meta?.title??"Untitled",s=t.theme??zA,o=HA(s,t.themeVars),r={sectionNum:0,sections:[],headingFor:FA(e.segments)},i=e.segments.map(l=>{const d=r.sections.length,u=T0(l,r),p=r.sections.length>d?r.sections[r.sections.length-1]:void 0;return{html:u,...p!==void 0?{sectionId:p.id,sectionNum:p.num}:{}}});return{css:m4,themeVars:o,title:n,defs:BA(),cover:g4(e.meta),segments:i,sections:r.sections}}function nG(e,t={}){const{css:n,themeVars:s,title:o,defs:r,cover:i,segments:l,sections:d}=Zi(e,t),u=r+i+l.map(p=>p.html).join("");return{css:n,themeVars:s,body:u,title:o,sections:d}}var fn=e=>Array.isArray(e)?e.length:0;function sG(e){const t=[e.items,e.rows,e.stats,e.blocks,e.levels,e.terms,e.parts,e.gates,e.nodes,e.screens,e.classes,e.states,e.entities,e.tasks,e.columns,e.lanes,e.steps,e.clusters,e.personas,e.areas,e.series,e.causes];let n=0;for(const s of t)n=Math.max(n,fn(s));return n}var oG={drivers:2,persona:2,chart:2,erd:2,composition:2,wireframe:2,spec:1.5,timeline:1.5,table:1.4,benchmark:1.4,sankey:1.2,gitgraph:1.2,treemap:1.2,packet:1.4,wardley:1.2,harvey:1.4,scenarios:1.4,scqa:1.6,matrix:1.2,flow:1.2,state:1.2,dfd:1.2,graph:1.2,swimlane:1.2,c4:1.2,uml:1.2,frontend:1.2,cluster:1.2,block:1.2,felogic:1.2,archmap:1.2,cycle:1.2,fishbone:1.4,slopegraph:.9,eventcontract:1.4,saga:1.6,spans:.7,rollout:1.6,perfbudget:.8,percentiles:.8,timing:1.2,threatmodel:1.6,neuralnet:.7,mindmap:.7,usecase:1,pkg:1.2,audit:1,checklist:.8,modelcard:1.4,chevrons:.7,roadmap:.9};function rG(e){if(e.kind==="meta")return 0;if(e.parseError!==void 0||e.data===null||e.data===void 0)return 2;const t=e.data;if(e.kind==="callout"||e.kind==="pullquote")return 3;if(e.kind==="proscons")return 2+(fn(t.pros)+fn(t.cons))*1.1;if(e.kind==="cvt")return 2+(fn(t.current?.items)+fn(t.target?.items))*1.1;if(e.kind==="code"){let n=0,s=fn(t.blocks);for(const o of t.blocks??[])n+=String(o.code??"").split(`
2832
+ `)}function lz(e){return e.startsWith("+")?"df-add":e.startsWith("-")?"df-del":e.startsWith("@@")?"df-hunk":"df-ctx"}function cz(e){const t=(e.code??"").split(`
2833
+ `).map(n=>`<span class="df-line ${lz(n)}">${S(n===""?" ":n)}</span>`).join("");return`<div class="code-block diff-block"><div class="code-header"><span>${S(e.title??"")}</span><span${_("lang")}>${S(e.lang??"diff")}</span></div><pre class="diff-pre"${_("code")}>${t}</pre></div>`}function dz(e){return e.startsWith("$ ")?`<span class="tm-line tm-cmd"><span class="tm-prompt">$</span> <span class="tm-cmd-text">${S(e.slice(2))}</span></span>`:e.startsWith("# ")?`<span class="tm-line tm-comment">${S(e)}</span>`:`<span class="tm-line tm-out">${S(e===""?" ":e)}</span>`}function Hw(e){const t=(e.session??"").replace(/\n$/,"").split(`
2834
+ `).map(dz).join("");return`<div class="code-block terminal-block"><div class="code-header"><span>${S(e.title??"terminal")}</span><span>shell</span></div><pre class="tm-pre"${_("session")}>${t}</pre></div>`}function uz(e){const t=new Set;if(e===void 0)return t;for(const n of e.split(",")){const s=n.trim(),o=/^(\d+)(?:\s*-\s*(\d+))?$/.exec(s);if(o===null)continue;const r=Number(o[1]),i=o[2]===void 0?r:Number(o[2]);if(!(r<1||i<r))for(let l=r;l<=i;l++)t.add(l)}return t}function pz(e){const t=e.split(`
2835
+ `),n=[];let s;for(const o of t){let r=s===void 0?o:`<span class="${s}">${o}`;const i=/<span class="([a-z]+)">|<\/span>/g;let l;for(;(l=i.exec(o))!==null;)s=l[1]===void 0?void 0:l[1];s!==void 0&&(r+="</span>"),n.push(r)}return n}function Ww(e,t,n,s,o){const r=uz(o.highlight),i=pz(fh(n.replace(/\n$/,""),t)),l=i.map((g,v)=>`<span class="cl${r.has(v+1)?" cl-hl":""}">${g}
2836
+ </span>`).join(""),d=["code-block","cb"];o.lines&&d.push("cb-lines"),o.wrap&&d.push("cb-wrap");const u=o.start+i.length-1,p=o.lines?` style="--code-start:${o.start-1};--code-gutter:${String(u).length}ch"`:"",h=o.eyebrow!==void 0&&e===""?`<span class="code-eyebrow"${_(s.title)}>${S(o.eyebrow)}</span>`:`<span${_(s.title)}>${S(e)}</span>`,m=o.caption!==void 0?`<div class="code-cap"${s.caption!==void 0?_(s.caption):""}>${S(o.caption)}</div>`:"";return`<div class="${d.join(" ")}"${s.self!==void 0?_(s.self):""}${p}><div class="code-header">`+h+`<span${_(s.lang)}>${S(t)}</span></div><pre${_(s.code)}>${l}</pre>`+m+"</div>"}var fz=["BEFORE","AFTER"];function hz(e){if(e.kind==="diff")return cz(e);if(e.kind==="terminal")return Hw(e);const t={lines:e.lines??!1,start:e.start??1,wrap:e.wrap??!1};if(e.blocks===void 0){if(e.code!==void 0)return Ww(e.title??"",e.lang??"",e.code,{title:"title",lang:"lang",code:"code",caption:"caption"},{...t,highlight:e.highlight,caption:e.caption});if(e.session!==void 0)return Hw(e)}const n=e.blocks??[],s=e.kind==="compare",o=s?2:e.cols??1,r=n.map((d,u)=>Ww(d.title??"",d.lang??"",d.code,{self:`blocks.${u}`,title:`blocks.${u}.title`,lang:`blocks.${u}.lang`,code:`blocks.${u}.code`,caption:`blocks.${u}.caption`},{...t,highlight:d.highlight,caption:d.caption,eyebrow:s?fz[u]??`#${u+1}`:void 0})).join(""),i=e.caption!==void 0?`<div class="code-cap code-cap-group"${_("caption")}>${S(e.caption)}</div>`:"",l=o>1?` class="code-grid" style="--code-cols:${o}"`:"";return`<div${he("blocks")}${l}>${r}</div>${i}`}function mz(e){const n=(e.items??[]).map((s,o)=>{const r=s.duration!==void 0?`<div class="agenda-dur"${_(`items.${o}.duration`)}>${S(s.duration)}</div>`:"",i=s.owner!==void 0?`<span class="agenda-owner"${_(`items.${o}.owner`)}>${S(s.owner)}</span>`:"",l=s.desc!==void 0?`<div class="agenda-desc"${_(`items.${o}.desc`)}>${S(s.desc)}</div>`:"",d=s.time!==void 0?`<div class="agenda-time"${_(`items.${o}.time`)}>${S(s.time)}</div>`:"";return`<div class="agenda-row"${_(`items.${o}`)}><div>${d}${r}</div><div><div class="agenda-title"><span${_(`items.${o}.title`)}>${S(s.title)}</span>${i}</div>`+l+"</div></div>"}).join("");return`<div class="agenda"${he("items")}>${n}</div>`}var S4={root:'fill="var(--accent-tint)" stroke="var(--accent)" stroke-width="1.5"',branch:'fill="var(--paper)" stroke="var(--ink)" stroke-width="1.5"',leaf:'fill="var(--paper-2)" stroke="var(--rule-solid)" stroke-width="1"'},Hp='fill="none" stroke="var(--muted)" stroke-width="1.25"';function gz(e){const t=e.nodes??[],n=new Map,s=new Map;for(const C of t)n.set(C.id,C),s.set(C.id,[]);const o=[];for(const C of t)C.parent!==void 0&&n.has(C.parent)?s.get(C.parent)?.push(C.id):o.push(C.id);const r=new Map,i=new Map,l=new Set;let d=0,u=0;const p=(C,D)=>{if(l.has(C))return;l.add(C),i.set(C,D),D>u&&(u=D);const F=s.get(C)??[];if(F.length===0)r.set(C,d),d+=1;else{for(const B of F)p(B,D+1);const U=r.get(F[0]??"")??0,X=r.get(F[F.length-1]??"")??0;r.set(C,(U+X)/2)}};for(const C of o)p(C,0);const h=168,m=50,g=16,v=56,y=24,b=18,E=18,$=C=>y+(i.get(C)??0)*(h+v),A=C=>b+(r.get(C)??0)*(m+g),T=y*2+(u+1)*h+u*v,N=b+Math.max(d,1)*(m+g)-g+E;let j=`<svg viewBox="0 0 ${T} ${N}" role="img"><title>Issue tree</title>`;for(const C of t){if(C.parent===void 0||!n.has(C.parent)||!r.has(C.id))continue;const D=$(C.parent)+h,F=A(C.parent)+m/2,U=$(C.id),X=A(C.id)+m/2,B=(D+U)/2;j+=`<path ${Hp} d="M ${D} ${F} H ${B} V ${X} H ${U}"/>`}const P=new Set;j+=`<g${he("nodes")}>`,t.forEach((C,D)=>{if(!r.has(C.id))return;const F=$(C.id),U=A(C.id),B=(i.get(C.id)??0)===0?"root":(s.get(C.id)??[]).length>0?"branch":"leaf";P.add(B);const te=`<rect x="${F}" y="${U}" width="${h}" height="${m}" rx="4" ${S4[B]}/>`,ee=B==="root"?F+h/2:F+14,H=B==="root"?"middle":"start",W=lt(C.label,B==="root"?22:20,C.note!==void 0?1:2),K=W.length===2?U+22:U+(C.note!==void 0?22:30),R=B==="root"?"t-name c-accent":"t-name",z=W.map((V,re)=>`<text x="${ee}" y="${K+re*14}" class="${R}" text-anchor="${H}">${S(V)}</text>`).join(""),Y=C.note!==void 0?`<text x="${ee}" y="${U+38}" class="t-sub c-muted" text-anchor="${H}">${S(C.note)}</text>`:"";j+=`<g${_(`nodes.${D}`)}>`+te+z+Y+"</g>"}),j+="</g>",j+="</svg>";const I=[];P.has("root")&&I.push({swatch:"node-accent",label:"question"}),P.has("branch")&&I.push({swatch:"node",label:"branch"}),P.has("leaf")&&I.push({swatch:"node-fill2",label:"testable claim"});const O=ot(I);return ct({tag:"MECE",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...O.length>0?{legendHtml:O}:{}},j)}var mo=148,fo=58,Wp=18,Rg=34,cc=mo+Wp,Dg=20,Uw=24,vz=6,Bg=26,yz=10;function zg(e,t){if(e.length<=t)return e;const n=e.slice(0,t-1),s=n.lastIndexOf(" ");return`${s>t/2?n.slice(0,s):n}…`}function xz(e){const t=e.nodes??[],n=new Map,s=new Map;for(const B of t)n.set(B.id,B),s.set(B.id,[]);const o=[];for(const B of t)B.parent!==void 0&&n.has(B.parent)?s.get(B.parent)?.push(B.id):o.push(B.id);const r=B=>(s.get(B)??[]).length===0,i=B=>{const te=s.get(B)??[],ee=te.filter(H=>r(H));if(!(ee.length<=vz))return{leaves:ee,branches:te.filter(H=>!r(H))}},l=mo*2+Bg+Wp,d=new Map,u=new Set,p=B=>{const te=d.get(B);if(te!==void 0)return te;if(u.has(B))return cc;u.add(B);const ee=i(B),H=s.get(B)??[],W=ee!==void 0?Math.max(cc,ee.branches.reduce((K,R)=>K+p(R),0)+l):H.length===0?cc:Math.max(cc,H.reduce((K,R)=>K+p(R),0));return u.delete(B),d.set(B,W),W},h=new Map,m=new Map,g=new Map,v=new Set,y=new Set,b=[];let E=0;const $=(B,te,ee,H)=>{if(v.has(B))return;v.add(B),g.set(B,H),m.set(B,ee),ee+fo>E&&(E=ee+fo);const W=s.get(B)??[];if(W.length===0){h.set(B,te+cc/2);return}const K=ee+fo+Rg,R=i(B);if(R!==void 0){const Q=R.branches.reduce((de,le)=>de+p(le),0)+l;let ne=te+(p(B)-Q)/2;for(const de of R.branches)$(de,ne,K,H+1),ne+=p(de);const Z=ne+(l-Wp)/2;R.leaves.forEach((de,le)=>{if(v.has(de))return;v.add(de),g.set(de,H+1),y.add(de);const J=le%2,ue=Math.floor(le/2),ve=K+ue*(fo+yz);m.set(de,ve),ve+fo>E&&(E=ve+fo),h.set(de,J===0?Z-Bg/2-mo/2:Z+Bg/2+mo/2)}),b.push({parent:B,trunkX:Z});const q=R.branches.length>0?h.get(R.branches[0]??"")??Z:Z;h.set(B,(q+Z)/2);return}const z=W.reduce((Q,ne)=>Q+p(ne),0);let Y=te+(p(B)-z)/2;for(const Q of W)$(Q,Y,K,H+1),Y+=p(Q);const V=h.get(W[0]??"")??0,re=h.get(W[W.length-1]??"")??0;h.set(B,(V+re)/2)},A=16,T=16;let N=A;for(const B of o)$(B,N,T,0),N+=p(B);const j=Math.max(N-Wp+A,A*2+mo),P=E+T,I=B=>Math.round(((h.get(B)??0)-mo/2)*10)/10,O=B=>m.get(B)??T;let C=`<svg viewBox="0 0 ${j} ${P}" role="img"><title>Org chart</title>`;for(const B of t){if(B.parent===void 0||!n.has(B.parent)||!h.has(B.id)||y.has(B.id))continue;const te=Math.round((h.get(B.parent)??0)*10)/10,ee=O(B.parent)+fo,H=Math.round((h.get(B.id)??0)*10)/10,W=O(B.id),K=ee+Rg/2;C+=`<path ${Hp} d="M ${te} ${ee} V ${K} H ${H} V ${W}"/>`}for(const B of b){const te=(s.get(B.parent)??[]).filter(z=>y.has(z)),ee=O(B.parent)+fo,H=Math.round(B.trunkX*10)/10;let W=ee,K="";for(const z of te){const Y=O(z)+fo/2;Y>W&&(W=Y);const V=h.get(z)??0,re=Math.round((V<B.trunkX?V+mo/2:V-mo/2)*10)/10;K+=`<path ${Hp} d="M ${H} ${Y} H ${re}"/>`}const R=Math.round((h.get(B.parent)??0)*10)/10;C+=`<path ${Hp} d="M ${R} ${ee} V ${ee+Rg/2} H ${H} V ${W}"/>`+K}let D=!1,F=!1;C+=`<g${he("nodes")}>`,t.forEach((B,te)=>{if(!h.has(B.id))return;const ee=I(B.id),H=O(B.id),W=(g.get(B.id)??0)===0;W?D=!0:F=!0;const K=B.role!==void 0&&B.role!=="",z=lt(B.label,Dg,2).map(ue=>zg(ue,Dg+2)),Y=z.join(" ").length<String(B.label).trim().replace(/\s+/g," ").length;if(Y&&z.length>0){const ue=z[z.length-1]??"";z[z.length-1]=ue.endsWith("…")?ue:zg(`${ue}…`,Dg+2)}const V=z.length===2,re=K?V?H+19:H+25:V?H+25:H+33,Q=V?H+49:H+43,ne=ee+mo/2,Z=W?"t-name c-accent":"t-name",q=z.map((ue,ve)=>`<text x="${ne}" y="${re+ve*14}" class="${Z}" text-anchor="middle"${ve===0?_(`nodes.${te}.label`):""}>${S(ue)}</text>`).join(""),de=K?`<text x="${ne}" y="${Q}" class="t-sub c-muted" text-anchor="middle"${_(`nodes.${te}.role`)}>${S(zg(String(B.role),Uw))}</text>`:"",le=K&&String(B.role).length>Uw,J=Y||le?`<title>${S(K?`${B.label} — ${String(B.role)}`:B.label)}</title>`:"";C+=`<g${_(`nodes.${te}`)}><rect x="${ee}" y="${H}" width="${mo}" height="${fo}" rx="4" ${S4[W?"root":"branch"]}/>`+J+q+de+"</g>"}),C+="</g>",C+="</svg>";const U=[];D&&U.push({swatch:"node-accent",label:"head"}),F&&U.push({swatch:"node",label:"reports to the card above"});const X=ot(U);return ct({tag:"ORG",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...X.length>0?{legendHtml:X}:{}},C)}function kz(e,t){const n=Math.round(e*100)/100,s=(Number.isInteger(n),String(n));return t!==void 0?`${s}${t}`:s}function bz(e){if(e.variant==="issue")return gz(e);if(e.variant==="org")return xz(e);const t=e.nodes??[],n=new Map,s=new Map,o=new Map;t.forEach((p,h)=>o.set(p,h));for(const p of t)n.set(p.id,p),s.set(p.id,[]);const r=[];for(const p of t)p.parent!==void 0&&n.has(p.parent)?s.get(p.parent)?.push(p.id):r.push(p.id);const i=[],l=new Set,d=(p,h,m)=>{if(l.has(p))return;l.add(p);const g=n.get(p);if(g===void 0)return;const v=s.get(p)??[];i.push({node:g,depth:h,branch:v.length>0,...m!==void 0?{parent:m}:{}});for(const y of v)d(y,h+1,g)};for(const p of r)d(p,0);const u=i.map(p=>{const h=o.get(p.node)??0,m=p.branch?" branch":"",g=p.branch?"▸":"—",v=p.node.note!==void 0?`<span class="tnote"${_(`nodes.${h}.note`)}>${S(p.node.note)}</span>`:"";let y="";if(typeof p.node.value=="number"){const b=kz(p.node.value,e.unit),E=p.parent?.value,$=typeof E=="number"&&E>0?`<span class="tshare">${Math.round(p.node.value/E*100)}%</span>`:"";y=`<span class="tvalue"${_(`nodes.${h}.value`)}>${S(b)}</span>${$}`}return`<div class="tree-row${m}" style="padding-left:${p.depth*22}px"${_(`nodes.${h}`)}><span class="tw">${g}</span><span class="tlabel"${_(`nodes.${h}.label`)}>${S(p.node.label)}</span>`+v+y+"</div>"}).join("");return`<div class="tree-list"${he("nodes")}>${u}</div>`}var Kw=["var(--navy)","var(--blue)","var(--teal)","var(--positive)","var(--purple)","var(--highlight)"];function wz(e){const t=e.levels??[],n=Math.max(t.length,1),s=560,o=16,r=Math.min(78,Math.floor(300/n)),i=4,l=s/2,d=16,u=480,p=250,h=o+n*(r+i)+d,m=v=>p+(u-p)*(v/n),g=t.map((v,y)=>{const b=o+y*(r+i),E=m(y),$=m(y+1),A=Kw[y%Kw.length]??"var(--navy)",T=v.desc!==void 0,N=Math.max(8,Math.floor((Math.min(E,$)-20)/7.3)),j=lt(v.label,N,T?1:2),P=b+r/2-(j.length-1)*7+(T?-4:0),I=j.map((C,D)=>`<text x="${l}" y="${P+D*14}" class="pyr-label">${S(C)}</text>`).join(""),O=T?`<text x="${l}" y="${b+r/2+14}" class="pyr-desc"${_(`levels.${y}.desc`)}>${S(v.desc??"")}</text>`:"";return`<g${_(`levels.${y}`)}><polygon points="${l-E/2},${b} ${l+E/2},${b} ${l+$/2},${b+r} ${l-$/2},${b+r}" fill="${A}"/>`+I+O+"</g>"}).join("");return`<svg viewBox="0 0 ${s} ${h}" role="img"><title>Pyramid</title><g${he("levels")}>${g}</g></svg>`}function Fs(e,t,n=0,s=0){const o=n*10,r={x:e.x+e.w/2,y:e.y+e.h/2},i={x:t.x+t.w/2,y:t.y+t.h/2},l=i.x-r.x,d=i.y-r.y;if(Math.abs(l)>=Math.abs(d)){const v=l>=0?e.x+e.w:e.x,y=l>=0?t.x:t.x+t.w,b=r.y+o,E=i.y+o+s,$=(v+y)/2;return{d:`M ${v} ${b} H ${$} V ${E} H ${y}`,lx:$,ly:(b+E)/2}}const u=d>=0?e.y+e.h:e.y,p=d>=0?t.y:t.y+t.h,h=r.x+o,m=i.x+o+s,g=(u+p)/2;return{d:`M ${h} ${u} V ${g} H ${m} V ${p}`,lx:(h+m)/2,ly:g}}function qs(e){const t=new Set(e.map(n=>`${n.from}\0${n.to}`));return e.map(n=>n.from===n.to||!t.has(`${n.to}\0${n.from}`)?0:n.from<n.to?-1:1)}var $z=8,Sz=6;function Hs(e,t){const n=new Map;e.forEach((o,r)=>{if(o.from===o.to)return;const i=t(o.from),l=t(o.to);if(i===void 0||l===void 0)return;const d=l.x+l.w/2-(i.x+i.w/2),u=l.y+l.h/2-(i.y+i.h/2),p=Math.abs(d)>=Math.abs(u),h=p?d>=0?"L":"R":u>=0?"T":"B",m=`${o.to}\0${h}`,g=n.get(m)??{members:[],span:p?l.h:l.w};g.members.push({i:r,from:o.from}),n.set(m,g)});const s=e.map(()=>0);for(const o of n.values()){const r=o.members.length;if(r<2)continue;const i=[...o.members].sort((u,p)=>u.from<p.from?-1:u.from>p.from?1:u.i-p.i),l=Math.max(0,o.span/2-Sz),d=Math.min($z,l/((r-1)/2));i.forEach((u,p)=>{s[u.i]=Math.round((p-(r-1)/2)*d*100)/100})}return s}function Ez(e,t,n=!1){if(t===void 0||t==="")return"";const s=Math.max(26,t.length*5.4),o=n?" err":"";return`<g><rect x="${e.lx-s/2}" y="${e.ly-9}" width="${s}" height="18" rx="9" fill="var(--white)" stroke="var(--rule)"${ut}/><text x="${e.lx}" y="${e.ly+3}" class="edge-label${o}">${S(t)}</text></g>`}function x0(e,t,n="muted"){if(t===void 0||t==="")return"";const s=Math.round(t.length*6+8),o=n==="error"?" c-negative":n==="accent"?" c-accent":"";return`<g><rect x="${e.lx-s/2}" y="${e.ly-7}" width="${s}" height="14" fill="var(--paper)"/><text x="${e.lx}" y="${e.ly+3.5}" class="t-arrow${o}" text-anchor="middle">${S(t)}</text></g>`}function xf(e,t,n=!1,s=!1){if(s){const i=n?" c-negative":"";return`<g><circle cx="${e.lx}" cy="${e.ly}" r="8" fill="var(--paper)" stroke="${n?"var(--negative)":"var(--muted)"}" stroke-width="1"/><text x="${e.lx}" y="${e.ly+3}" text-anchor="middle" class="t-badge${i}">${t}</text></g>`}const o=n?"var(--negative)":"var(--charcoal)",r=n?"var(--negative)":"var(--charcoal)";return`<g><circle cx="${e.lx}" cy="${e.ly}" r="9.5" fill="var(--white)" stroke="${o}" stroke-width="1.2"/><text x="${e.lx}" y="${e.ly+3.5}" text-anchor="middle" style="font-family:var(--font-mono);font-size:10px;font-weight:700" fill="${r}">${t}</text></g>`}function E4(e){return e.length===0?"":`<div class="edge-steps">${e.map((n,s)=>`<span class="edge-step${n.err===!0?" err":""}"${n.path!==void 0?_(n.path):""}${n.reveal!==void 0?hn(n.reveal):""}><b>${s+1}</b>${S(n.label)}</span>`).join("")}</div>`}var Uu=13;function Uy(e,t,n){let s=e,o=t,r=!1;for(let i=0;i<2;i++){let l=!1;for(const d of n){const u=d.x-Uu,p=d.y-Uu,h=d.x+d.w+Uu,m=d.y+d.h+Uu;if(s<=u||s>=h||o<=p||o>=m)continue;const g=s-u,v=h-s,y=o-p,b=m-o,E=Math.min(g,v,y,b);E===g?s=u:E===v?s=h:E===y?o=p:o=m,l=!0,r=!0}if(!l)break}return r?{lx:Math.round(s),ly:Math.round(o)}:{lx:e,ly:t}}function Ws(e,t=[],n={}){const o=e.filter(d=>d.label!==void 0&&d.label!=="").length>=4,r=[],i=[],l=[...t];for(const d of e){if(d.label===void 0||d.label==="")continue;const u=d.err===!0,p=Uy(d.lx,d.ly,o?l:t),h=_(d.path)+(d.reveal!==void 0?hn(d.reveal):"");if(o)l.push({x:p.lx-6,y:p.ly-6,w:12,h:12}),i.push({label:d.label,path:d.path,...u?{err:!0}:{},...d.reveal!==void 0?{reveal:d.reveal}:{}}),r.push(`<g${h}>${xf(p,i.length,u,n.skin===!0)}</g>`);else if(n.skin===!0){const m=u?"error":d.accent===!0?"accent":"muted";r.push(`<g${h}>${x0(p,d.label,m)}</g>`)}else r.push(`<g${h}>${Ez(p,d.label,u)}</g>`)}return{overlay:r.join(""),legend:E4(i)}}var Gn={padX:38,padTop:52,padBot:36};function wd(e){return{cols:Math.max(1,...e.map(t=>t.col+(t.cols??1)-1)),rows:Math.max(1,...e.map(t=>t.row+(t.rows??1)-1))}}function Mz(e,t){if(e===t)return!1;const n=e.col+(e.cols??1),s=e.row+(e.rows??1),o=t.col+(t.cols??1),r=t.row+(t.rows??1),i=e.col>=t.col&&e.row>=t.row&&n<=o&&s<=r,l=(t.cols??1)*(t.rows??1)>(e.cols??1)*(e.rows??1);return i&&l}var Ku={x:4,y:8,w:8,h:12},Fr={x:4,y:10,w:8,h:14};function Ky(e){const t=new Map;for(const p of e)p.id!==void 0&&!t.has(p.id)&&t.set(p.id,p);const n=p=>{const h=p.parent!==void 0?t.get(p.parent):void 0;return h===p?void 0:h},s=new Map,o=p=>{const h=e.filter(m=>Mz(p,m)).length;return{depth:h,inset:{x:h*12,y:h*11,w:h*24,h:h*17},declared:!1}},r=(p,h)=>{const m=s.get(p);if(m!==void 0)return m;const g=n(p);let v;if(g===void 0||h.has(g))v=o(p);else{const y=r(g,new Set([...h,p]));v={depth:y.depth+1,inset:{x:y.inset.x+Ku.x,y:y.inset.y+Ku.y,w:y.inset.w+Ku.w,h:y.inset.h+Ku.h},declared:!0}}return s.set(p,v),v};for(const p of e)r(p,new Set);const i=new Map;for(const p of e){const h=n(p);h!==void 0&&s.get(p)?.declared===!0&&i.set(h,[...i.get(h)??[],p])}const l=new Map,d=(p,h)=>{const m=l.get(p);if(m!==void 0)return m;const g=(i.get(p)??[]).filter(y=>!h.has(y)),v=g.length===0?0:1+Math.max(...g.map(y=>d(y,new Set([...h,p]))));return l.set(p,v),v},u=new Map;for(const p of e){const h=s.get(p)??o(p),m=d(p,new Set);u.set(p,{...h,height:m,inset:{x:h.inset.x-Fr.x*m,y:h.inset.y-Fr.y*m,w:h.inset.w-Fr.w*m,h:h.inset.h-Fr.h*m}})}return u}function Az(e){return e.some(t=>t.parent!==void 0)?Ky(e):new Map}function Yi(e){if(!e.some(n=>n.parent!==void 0))return{padX:0,padTop:0,padBot:0};const t=Math.max(0,...[...Ky(e).values()].map(n=>n.height));return{padX:Fr.x*t,padTop:Fr.y*t,padBot:(Fr.h-Fr.y)*t}}function xl(e,t){const n=d=>({x:t.xOf(d.col)-28,y:t.yOf(d.row)-38,w:(d.cols??1)*t.cellW+((d.cols??1)-1)*t.gapX+56,h:(d.rows??1)*t.cellH+((d.rows??1)-1)*t.gapY+66}),s=Ky(e),o=e.some(d=>d.parent!==void 0),r=d=>(d.cols??1)*(d.rows??1),i=e.map((d,u)=>({g:d,gi:u})).sort((d,u)=>o?(s.get(d.g)?.depth??0)-(s.get(u.g)?.depth??0)||r(u.g)-r(d.g)||d.gi-u.gi:r(u.g)-r(d.g));let l=`<g${he("groups")}>`;for(const{g:d,gi:u}of i){const p=n(d),h=Fi(d.color,"var(--slate)"),m=s.get(d)??{depth:0,inset:{x:0,y:0,w:0,h:0},declared:!1},g=m.depth,v={x:p.x+m.inset.x,y:p.y+m.inset.y,w:p.w-m.inset.w,h:p.h-m.inset.h},y=m.declared?g%2===1:g>0;if(t.skin===!0){const E=Fi(d.color,""),$=E.length>0?`color-mix(in srgb, ${E} 62%, var(--ink))`:"",A=E.length>0?$:"var(--rule-solid)",T=E.length>0?$:"var(--soft)",N=y?`<text x="${v.x+v.w-12}" y="${v.y+16}" class="t-eyebrow" fill="${T}" text-anchor="end">${S(d.label)}</text>`:`<text x="${v.x+12}" y="${v.y+16}" class="t-eyebrow" fill="${T}">${S(d.label)}</text>`;l+=`<g${_(`groups.${u}`)}><rect x="${v.x}" y="${v.y}" width="${v.w}" height="${v.h}" rx="6" fill="var(--paper-2)" fill-opacity="0.6" stroke="${A}" stroke-width="1"/>`+N+"</g>";continue}const b=y?`<text x="${v.x+v.w-16}" y="${v.y+19}" class="grp-label" fill="${h}" text-anchor="end">${S(d.label)}</text>`:`<text x="${v.x+16}" y="${v.y+19}" class="grp-label" fill="${h}">${S(d.label)}</text>`;l+=`<g${_(`groups.${u}`)}><rect x="${v.x}" y="${v.y}" width="${v.w}" height="${v.h}" rx="12" fill="none" stroke="${h}" stroke-opacity="0.6" stroke-width="1.3" stroke-dasharray="7 5"/>`+b+"</g>"}return l+="</g>",l}function tr(e){return` data-grid="1"${e.quick?' data-grid-auto="1"':""} data-cols="${e.cols}" data-rows="${e.rows}" data-cell-w="${e.cellW}" data-cell-h="${e.cellH}" data-gap-x="${e.gapX}" data-gap-y="${e.gapY}" data-pad-x="${e.padX}" data-pad-top="${e.padTop}"`}function Mo(e,t,n){return` data-col="${e}" data-row="${t}"${n!==void 0?` data-w="${n}"`:""}`}var Cz="box",Nz={function:"M3 2 H5 L10.5 12 M7.6 7 L3.5 12",bucket:"M2 3.5 a5 1.6 0 0 0 10 0 a5 1.6 0 0 0 -10 0 M2 3.5 L3.5 12.5 H10.5 L12 3.5",queue:"M3 1.5 V12.5 M7 1.5 V12.5 M11 1.5 V12.5",topic:"M1.5 7 H5.5 M5.5 7 L11.5 2.5 M5.5 7 H12 M5.5 7 L11.5 11.5",cache:"M1.5 4.5 L7 2 L12.5 4.5 L7 7 Z M1.5 8 L7 10.5 L12.5 8 M1.5 11 L7 13.5 L12.5 11",db:"M1.5 3 a5.5 2.2 0 0 0 11 0 a5.5 2.2 0 0 0 -11 0 V11 a5.5 2.2 0 0 0 11 0 V3",cdn:"M3.5 12 a3 3 0 0 1 0.3 -6 a4 4 0 0 1 7.6 1 a2.5 2.5 0 0 1 0.6 5 Z",lb:"M1.5 7 H5 M5 7 L9 3 H12.5 M5 7 H12.5 M5 7 L9 11 H12.5",gateway:"M2 1.5 L7 7 L2 12.5 M7.5 1.5 L12.5 7 L7.5 12.5",pod:"M7 1.2 L12.2 4.1 V9.9 L7 12.8 L1.8 9.9 V4.1 Z M5.2 7 a1.8 1.8 0 1 0 3.6 0 a1.8 1.8 0 1 0 -3.6 0",cluster:"M1.5 7 a5.5 5.5 0 1 0 11 0 a5.5 5.5 0 1 0 -11 0 M7 1.5 V4.5 M7 9.5 V12.5 M1.5 7 H4.5 M9.5 7 H12.5",user:"M4.5 4.5 a2.5 2.5 0 1 0 5 0 a2.5 2.5 0 1 0 -5 0 M2.5 13 a4.5 4.5 0 0 1 9 0",browser:"M1.5 2.5 H12.5 V11.5 H1.5 Z M1.5 5.5 H12.5",mobile:"M4 1.5 H10 a1 1 0 0 1 1 1 V11.5 a1 1 0 0 1 -1 1 H4 a1 1 0 0 1 -1 -1 V2.5 a1 1 0 0 1 1 -1 Z M6 11 H8",cron:"M1.5 7 a5.5 5.5 0 1 0 11 0 a5.5 5.5 0 1 0 -11 0 M7 3.5 V7 L9.5 8.5",ml:"M7 1.5 L8.4 5.6 L12.5 7 L8.4 8.4 L7 12.5 L5.6 8.4 L1.5 7 L5.6 5.6 Z",secret:"M3 6.5 H11 V13 H3 Z M4.5 6.5 V4.5 a2.5 2.5 0 0 1 5 0 V6.5",config:"M1.5 3.5 H12.5 M1.5 7 H12.5 M1.5 10.5 H12.5 M4.5 2 V5 M9.5 5.5 V8.5 M6 9 V12",deployment:"M1.5 5 H9 V12.5 H1.5 Z M4 5 V2.5 H11.5 V10 H9",ingress:"M1.5 7 H8 M5.5 4.5 L8 7 L5.5 9.5 M10 1.5 H12.5 V12.5 H10",node:"M2 2 H12 V6 H2 Z M2 8 H12 V12 H2 Z M4.5 4 H6.5 M4.5 10 H6.5",namespace:"M1.5 3.5 H5.5 L7 5 H12.5 V12 H1.5 Z",box:"M2 2 H12 V12 H2 Z"},M4={function:"function",lambda:"function",bucket:"bucket",s3:"bucket",blob:"bucket",object:"bucket",queue:"queue",sqs:"queue",mq:"queue",broker:"queue",rabbitmq:"queue",topic:"topic",sns:"topic",kafka:"topic",kinesis:"topic",stream:"topic",cache:"cache",redis:"cache",memcached:"cache",db:"db",database:"db",store:"db",postgres:"db",mysql:"db",mongo:"db",mongodb:"db",dynamo:"db",cdn:"cdn",lb:"lb",gateway:"gateway",proxy:"gateway",pod:"pod",cluster:"cluster",user:"user",person:"user",actor:"user",browser:"browser",web:"browser",mobile:"mobile",cron:"cron",scheduler:"cron",job:"cron",cronjob:"cron",ml:"ml",model:"ml",llm:"ml",agent:"ml",ai:"ml",secret:"secret",secrets:"secret",vault:"secret",kms:"secret",config:"config",configmap:"config",settings:"config",deployment:"deployment",ingress:"ingress",node:"node",vm:"node",server:"node",host:"node",namespace:"namespace"};function Tz(e){return M4[(e??"").trim().toLowerCase()]??Cz}function _z(e){return(e??"").trim().toLowerCase()in M4}function Lz(e,t,n,s="var(--muted)"){return`<path d="${Nz[Tz(e)]}" transform="translate(${t} ${n})" fill="none" stroke="${s}" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round"/>`}var Iz=["client","service","microservice","compute","container","data","store","db","database","postgres","mysql","mongo","mongodb","dynamo","bucket","blob","object","s3","queue","mq","broker","sqs","rabbitmq","cache","redis","memcached","gateway","lb","proxy","function","lambda","cdn","external","producer","topic","consumer","context","firewall","waf","shield","dns","auth","identity","idp","iam","oauth","sso","monitor","observability","metrics","logs","tracing","apm","scheduler","cron","job","stream","kafka","kinesis","warehouse","lake","analytics","bi","search","index","elasticsearch","opensearch","registry","ci","cicd","pipeline","git","repo","scm","device","iot","email","sms","config","settings","ml","model","llm","agent","ai","user","person","actor","browser","web","mobile","vm","server","host","secrets","vault","kms","notification","webhook","worker","etl","shard","shards","sharded","replica","replicas","replicaset","users","crowd","region","geo","globe","deployment","pod","ingress","configmap","secret","cronjob","node","namespace","cluster","sns"],A4={},mt=(e,t)=>{for(const n of e)A4[n]=t},Zt=e=>({chip:e,primary:!0,fill:"paper",dashed:!1}),Tn=e=>({chip:e,primary:!1,fill:"paper-2",dashed:!1}),kl=e=>({chip:e,primary:!0,fill:"paper",dashed:!0});mt(["client","user","person","actor","users","crowd","browser","web","mobile","device","iot"],Zt("CLIENT"));mt(["service","microservice","compute","container","worker","etl"],Zt("SVC"));mt(["data"],Zt("DATA"));mt(["store","db","database","postgres","mysql","mongo","mongodb","dynamo"],Tn("DB"));mt(["shard","shards","sharded","replica","replicas","replicaset"],Tn("DB"));mt(["bucket","blob","object","s3"],Tn("BUCKET"));mt(["warehouse","lake"],Tn("WAREHOUSE"));mt(["queue","mq","broker","sqs","rabbitmq"],Tn("QUEUE"));mt(["topic"],Tn("TOPIC"));mt(["stream","kafka","kinesis"],Tn("BUS"));mt(["cache","redis","memcached"],Tn("CACHE"));mt(["search","index","elasticsearch","opensearch"],Tn("SEARCH"));mt(["registry"],Tn("REGISTRY"));mt(["gateway","proxy"],Zt("GATEWAY"));mt(["lb"],Zt("LB"));mt(["function","lambda"],Zt("FN"));mt(["cdn"],kl("EDGE"));mt(["external"],kl("EXT"));mt(["producer"],Zt("PRODUCER"));mt(["consumer"],Zt("CONSUMER"));mt(["context"],Zt("CONTEXT"));mt(["firewall","waf","shield"],Zt("WAF"));mt(["dns"],kl("DNS"));mt(["auth","identity","idp","iam","oauth","sso"],Zt("AUTH"));mt(["monitor","observability","metrics","logs","tracing","apm"],Zt("OBS"));mt(["scheduler","cron","job"],Zt("CRON"));mt(["analytics","bi"],Zt("ANALYTICS"));mt(["ci","cicd","pipeline"],Zt("CI"));mt(["git","repo","scm"],Tn("GIT"));mt(["email","sms"],kl("EMAIL"));mt(["config","settings"],Tn("CONFIG"));mt(["ml","model","llm","agent","ai"],Zt("AI"));mt(["vm","server","host"],Zt("HOST"));mt(["secrets","vault","kms"],Tn("SECRETS"));mt(["notification","webhook"],kl("WEBHOOK"));mt(["region","geo","globe"],kl("REGION"));mt(["deployment"],Zt("DEPLOY"));mt(["pod"],Zt("POD"));mt(["ingress"],Zt("INGRESS"));mt(["configmap"],Tn("CONFIG"));mt(["secret"],Tn("SECRETS"));mt(["cronjob"],Zt("CRON"));mt(["node"],Zt("NODE"));mt(["namespace"],Tn("NS"));mt(["cluster"],Zt("CLUSTER"));mt(["sns"],Tn("TOPIC"));function Vo(e){const t=(e??"").trim().toLowerCase();return t===""?{chip:"",primary:!0,fill:"paper",dashed:!1}:A4[t]??Zt(t.toUpperCase())}function jz(e,t=!1){return t?"var(--accent-tint)":e.fill==="paper-2"?"var(--paper-2)":"var(--paper)"}function al(e,t,n,s){const o=(e??"").toLowerCase();if(o==="store"||o==="db"||o==="database"||o==="postgres"||o==="mysql"||o==="mongo"||o==="mongodb"||o==="dynamo")return`<g stroke="${s}" stroke-width="1.3" fill="none"><ellipse cx="${t+8}" cy="${n+3}" rx="7" ry="3"/><path d="M${t+1} ${n+3} V ${n+13}"/><path d="M${t+15} ${n+3} V ${n+13}"/><path d="M${t+1} ${n+13} a 7 3 0 0 0 14 0"/></g>`;if(o==="bucket"||o==="blob"||o==="object"||o==="s3")return`<g stroke="${s}" stroke-width="1.3" fill="none"><ellipse cx="${t+8}" cy="${n+3}" rx="7" ry="2.5"/><path d="M${t+1.5} ${n+3} L ${t+3.5} ${n+14} L ${t+12.5} ${n+14} L ${t+14.5} ${n+3}"/></g>`;if(o==="queue"||o==="topic"||o==="mq"||o==="broker"||o==="sqs"||o==="rabbitmq")return`<g stroke="${s}" stroke-width="1.6"><path d="M${t+2} ${n+1} V ${n+14}"/><path d="M${t+8} ${n+1} V ${n+14}"/><path d="M${t+14} ${n+1} V ${n+14}"/></g>`;if(o==="firewall"||o==="waf"||o==="shield")return`<path d="M${t+8} ${n} L ${t+15} ${n+3} V ${n+9} Q ${t+15} ${n+14} ${t+8} ${n+16} Q ${t+1} ${n+14} ${t+1} ${n+9} V ${n+3} Z" fill="none" stroke="${s}" stroke-width="1.3"/>`;if(o==="dns")return`<g stroke="${s}" stroke-width="1.2" fill="none"><circle cx="${t+8}" cy="${n+8}" r="7"/><ellipse cx="${t+8}" cy="${n+8}" rx="3" ry="7"/><path d="M${t+1.5} ${n+8} H ${t+14.5}"/></g>`;if(o==="auth"||o==="identity"||o==="idp"||o==="iam"||o==="oauth"||o==="sso")return`<g stroke="${s}" stroke-width="1.4" fill="none"><circle cx="${t+5}" cy="${n+8}" r="3.5"/><path d="M${t+8.5} ${n+8} H ${t+15} M${t+12.5} ${n+8} V ${n+11.5} M${t+15} ${n+8} V ${n+10.5}"/></g>`;if(o==="monitor"||o==="observability"||o==="metrics"||o==="logs"||o==="tracing"||o==="apm")return`<path d="M${t} ${n+9} H ${t+4} L ${t+6.5} ${n+3} L ${t+9.5} ${n+13} L ${t+12} ${n+9} H ${t+16}" fill="none" stroke="${s}" stroke-width="1.5" stroke-linejoin="round"/>`;if(o==="scheduler"||o==="cron"||o==="job")return`<g stroke="${s}" stroke-width="1.3" fill="none"><circle cx="${t+8}" cy="${n+8}" r="7"/><path d="M${t+8} ${n+4} V ${n+8} L ${t+11.5} ${n+10}"/></g>`;if(o==="stream"||o==="kafka"||o==="kinesis"){const r=i=>`<path d="M${t+1} ${n+4+i} q 3.5 -3 7 0 t 7 0" fill="none" stroke="${s}" stroke-width="1.4"/>`;return`<g>${r(0)}${r(4.5)}${r(9)}</g>`}if(o==="warehouse"||o==="lake")return`<g stroke="${s}" stroke-width="1.3" fill="none"><ellipse cx="${t+8}" cy="${n+3}" rx="7" ry="3"/><path d="M${t+1} ${n+3} V ${n+13}"/><path d="M${t+15} ${n+3} V ${n+13}"/><path d="M${t+1} ${n+8} a 7 3 0 0 0 14 0"/><path d="M${t+1} ${n+13} a 7 3 0 0 0 14 0"/></g>`;if(o==="search"||o==="index")return`<g stroke="${s}" stroke-width="1.4" fill="none"><circle cx="${t+6.5}" cy="${n+6.5}" r="5"/><path d="M${t+10.5} ${n+10.5} L ${t+15} ${n+15}"/></g>`;if(o==="ml"||o==="model"||o==="llm"||o==="agent"||o==="ai")return`<path d="M${t+8} ${n+1} L ${t+9.8} ${n+6.2} L ${t+15} ${n+8} L ${t+9.8} ${n+9.8} L ${t+8} ${n+15} L ${t+6.2} ${n+9.8} L ${t+1} ${n+8} L ${t+6.2} ${n+6.2} Z" fill="${s}"/>`;if(o==="user"||o==="person"||o==="actor")return`<g fill="${s}"><circle cx="${t+8}" cy="${n+4.5}" r="3.5"/><path d="M ${t+2} ${n+15} a 6 6.5 0 0 1 12 0 z"/></g>`;if(o==="browser"||o==="web")return`<g stroke="${s}" stroke-width="1.3" fill="none"><rect x="${t+1}" y="${n+2}" width="14" height="12" rx="2"/><path d="M${t+1} ${n+6} H ${t+15}"/></g>`;if(o==="mobile")return`<g stroke="${s}" stroke-width="1.3" fill="none"><rect x="${t+4}" y="${n+1}" width="8" height="14" rx="2"/><path d="M${t+7} ${n+12.5} H ${t+9}"/></g>`;if(o==="vm"||o==="server"||o==="host")return`<g stroke="${s}" stroke-width="1.3" fill="none"><rect x="${t+2}" y="${n+2}" width="12" height="5" rx="1.2"/><rect x="${t+2}" y="${n+9}" width="12" height="5" rx="1.2"/><path d="M${t+4.5} ${n+4.5} H ${t+7} M${t+4.5} ${n+11.5} H ${t+7}"/></g>`;if(o==="secrets"||o==="vault"||o==="kms")return`<g stroke="${s}" stroke-width="1.3" fill="none"><rect x="${t+3}" y="${n+7}" width="10" height="8" rx="1.5"/><path d="M${t+5} ${n+7} V ${n+5} a 3 3 0 0 1 6 0 V ${n+7}"/></g>`;if(o==="notification"||o==="webhook")return`<g stroke="${s}" stroke-width="1.3" fill="none"><path d="M${t+3} ${n+11} a 5 5 0 0 1 1.6 -3.6 V ${n+5} a 3.4 3.4 0 0 1 6.8 0 v 2.4 a 5 5 0 0 1 1.6 3.6 z"/><path d="M${t+6.5} ${n+13.5} a 1.5 1.5 0 0 0 3 0"/></g>`;if(o==="email"||o==="sms")return`<g stroke="${s}" stroke-width="1.3" fill="none"><rect x="${t+1}" y="${n+3}" width="14" height="10" rx="1.5"/><path d="M${t+1.5} ${n+4} L ${t+8} ${n+9} L ${t+14.5} ${n+4}"/></g>`;if(o==="registry")return`<g stroke="${s}" stroke-width="1.2" fill="none"><rect x="${t+1}" y="${n+8}" width="6" height="6" rx="1"/><rect x="${t+9}" y="${n+8}" width="6" height="6" rx="1"/><rect x="${t+5}" y="${n+1}" width="6" height="6" rx="1"/></g>`;if(o==="ci"||o==="cicd"||o==="pipeline")return`<g stroke="${s}" stroke-width="1.3" fill="none"><circle cx="${t+8}" cy="${n+8}" r="7"/><path d="M${t+6} ${n+5} L ${t+11.5} ${n+8} L ${t+6} ${n+11} Z" fill="${s}" stroke="none"/></g>`;if(o==="git"||o==="repo"||o==="scm")return`<g stroke="${s}" stroke-width="1.3" fill="none"><circle cx="${t+4}" cy="${n+3.5}" r="2.5"/><circle cx="${t+4}" cy="${n+12.5}" r="2.5"/><circle cx="${t+12}" cy="${n+6}" r="2.5"/><path d="M${t+4} ${n+6} V ${n+10} M${t+4} ${n+8} q 0 -2 3 -2 h 2.5"/></g>`;if(o==="device"||o==="iot")return`<g stroke="${s}" stroke-width="1.2" fill="none"><rect x="${t+4}" y="${n+4}" width="8" height="8" rx="1.5"/><path d="M${t+6} ${n+4} V ${n+1} M${t+10} ${n+4} V ${n+1} M${t+6} ${n+15} V ${n+12} M${t+10} ${n+15} V ${n+12} M${t+4} ${n+6} H ${t+1} M${t+4} ${n+10} H ${t+1} M${t+15} ${n+6} H ${t+12} M${t+15} ${n+10} H ${t+12}"/></g>`;if(o==="analytics"||o==="bi")return`<g fill="${s}"><rect x="${t+1}" y="${n+9}" width="3.4" height="6" rx="0.8"/><rect x="${t+6.3}" y="${n+5}" width="3.4" height="10" rx="0.8"/><rect x="${t+11.6}" y="${n+1}" width="3.4" height="14" rx="0.8"/></g>`;if(o==="config"||o==="settings")return`<g stroke="${s}" stroke-width="1.3" fill="none"><circle cx="${t+8}" cy="${n+8}" r="4"/><path d="M${t+8} ${n+1} V ${n+3.5} M${t+8} ${n+12.5} V ${n+15} M${t+1} ${n+8} H ${t+3.5} M${t+12.5} ${n+8} H ${t+15} M${t+3} ${n+3} L ${t+5} ${n+5} M${t+11} ${n+11} L ${t+13} ${n+13} M${t+13} ${n+3} L ${t+11} ${n+5} M${t+5} ${n+11} L ${t+3} ${n+13}"/></g>`;if(o==="cache"||o==="redis"||o==="memcached"){const r=i=>`<path d="M${t+1} ${n+5+i} L${t+8} ${n+2+i} L${t+15} ${n+5+i} L${t+8} ${n+8+i} Z" fill="none" stroke="${s}" stroke-width="1.2"/>`;return`<g>${r(0)}${r(3.5)}${r(7)}</g>`}return o==="function"||o==="lambda"?`<text x="${t+7}" y="${n+14}" font-family="Georgia, serif" font-size="17" font-style="italic" font-weight="700" fill="${s}" text-anchor="middle">ƒ</text>`:o==="cdn"||o==="external"?`<path d="M${t+3} ${n+13} a 4 4 0 0 1 0.5 -8 a 5 5 0 0 1 9.5 1.2 a 3 3 0 0 1 1 6.8 z" fill="none" stroke="${s}" stroke-width="1.3"/>`:o==="gateway"||o==="lb"||o==="proxy"?`<g stroke="${s}" stroke-width="1.5" fill="none"><path d="M${t+2} ${n+1} L ${t+8} ${n+7} L ${t+2} ${n+13}"/><path d="M${t+8} ${n+1} L ${t+14} ${n+7} L ${t+8} ${n+13}"/></g>`:o==="service"||o==="microservice"||o==="compute"||o==="container"||o==="worker"||o==="etl"?`<g stroke="${s}" stroke-width="1.3"><rect x="${t+4}" y="${n+1}" width="11" height="11" rx="1.5" fill="none"/><rect x="${t+1}" y="${n+4}" width="11" height="11" rx="1.5" fill="var(--paper)"/></g>`:_z(o)?Lz(o,t,n,s):""}var Qo={solid:{stroke:"var(--muted)",sw:1.5,dash:"",marker:"skArrow",err:!1},dashed:{stroke:"var(--muted)",sw:1.5,dash:"5 4",marker:"skOpen",err:!1},forbidden:{stroke:"var(--negative)",sw:1.5,dash:"4 3",marker:"skErr",err:!0},error:{stroke:"var(--negative)",sw:1.5,dash:"",marker:"skErr",err:!0}},C4=Object.defineProperty,Pz=(e,t,n)=>t in e?C4(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Oz=(e,t)=>{for(var n in t)C4(e,n,{get:t[n],enumerable:!0})},Rz=(e,t,n)=>Pz(e,t+"",n),N4={};Oz(N4,{Graph:()=>Us,alg:()=>Vy,json:()=>_4,version:()=>zz});var Dz=Object.defineProperty,T4=(e,t)=>{for(var n in t)Dz(e,n,{get:t[n],enumerable:!0})},Us=class{constructor(e){this._isDirected=!0,this._isMultigraph=!1,this._isCompound=!1,this._nodes={},this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={},this._nodeCount=0,this._edgeCount=0,this._defaultNodeLabelFn=()=>{},this._defaultEdgeLabelFn=()=>{},e&&(this._isDirected="directed"in e?e.directed:!0,this._isMultigraph="multigraph"in e?e.multigraph:!1,this._isCompound="compound"in e?e.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children["\0"]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(e){return this._label=e,this}graph(){return this._label}setDefaultNodeLabel(e){return typeof e!="function"?this._defaultNodeLabelFn=()=>e:this._defaultNodeLabelFn=e,this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){return this.nodes().filter(e=>Object.keys(this._in[e]).length===0)}sinks(){return this.nodes().filter(e=>Object.keys(this._out[e]).length===0)}setNodes(e,t){return e.forEach(n=>{t!==void 0?this.setNode(n,t):this.setNode(n)}),this}setNode(e,t){return e in this._nodes?(arguments.length>1&&(this._nodes[e]=t),this):(this._nodes[e]=arguments.length>1?t:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]="\0",this._children[e]={},this._children["\0"][e]=!0),this._in[e]={},this._preds[e]={},this._out[e]={},this._sucs[e]={},++this._nodeCount,this)}node(e){return this._nodes[e]}hasNode(e){return e in this._nodes}removeNode(e){if(e in this._nodes){let t=n=>this.removeEdge(this._edgeObjs[n]);delete this._nodes[e],this._isCompound&&(this._removeFromParentsChildList(e),delete this._parent[e],this.children(e).forEach(n=>{this.setParent(n)}),delete this._children[e]),Object.keys(this._in[e]).forEach(t),delete this._in[e],delete this._preds[e],Object.keys(this._out[e]).forEach(t),delete this._out[e],delete this._sucs[e],--this._nodeCount}return this}setParent(e,t){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(t===void 0)t="\0";else{t+="";for(let n=t;n!==void 0;n=this.parent(n))if(n===e)throw new Error("Setting "+t+" as parent of "+e+" would create a cycle");this.setNode(t)}return this.setNode(e),this._removeFromParentsChildList(e),this._parent[e]=t,this._children[t][e]=!0,this}parent(e){if(this._isCompound){let t=this._parent[e];if(t!=="\0")return t}}children(e="\0"){if(this._isCompound){let t=this._children[e];if(t)return Object.keys(t)}else{if(e==="\0")return this.nodes();if(this.hasNode(e))return[]}return[]}predecessors(e){let t=this._preds[e];if(t)return Object.keys(t)}successors(e){let t=this._sucs[e];if(t)return Object.keys(t)}neighbors(e){let t=this.predecessors(e);if(t){let n=new Set(t);for(let s of this.successors(e))n.add(s);return Array.from(n.values())}}isLeaf(e){let t;return this.isDirected()?t=this.successors(e):t=this.neighbors(e),t.length===0}filterNodes(e){let t=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});t.setGraph(this.graph()),Object.entries(this._nodes).forEach(([o,r])=>{e(o)&&t.setNode(o,r)}),Object.values(this._edgeObjs).forEach(o=>{t.hasNode(o.v)&&t.hasNode(o.w)&&t.setEdge(o,this.edge(o))});let n={},s=o=>{let r=this.parent(o);return!r||t.hasNode(r)?(n[o]=r??void 0,r??void 0):r in n?n[r]:s(r)};return this._isCompound&&t.nodes().forEach(o=>t.setParent(o,s(o))),t}setDefaultEdgeLabel(e){return typeof e!="function"?this._defaultEdgeLabelFn=()=>e:this._defaultEdgeLabelFn=e,this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(e,t){return e.reduce((n,s)=>(t!==void 0?this.setEdge(n,s,t):this.setEdge(n,s),s)),this}setEdge(e,t,n,s){let o,r,i,l,d=!1;typeof e=="object"&&e!==null&&"v"in e?(o=e.v,r=e.w,i=e.name,arguments.length===2&&(l=t,d=!0)):(o=e,r=t,i=s,arguments.length>2&&(l=n,d=!0)),o=""+o,r=""+r,i!==void 0&&(i=""+i);let u=_c(this._isDirected,o,r,i);if(u in this._edgeLabels)return d&&(this._edgeLabels[u]=l),this;if(i!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(o),this.setNode(r),this._edgeLabels[u]=d?l:this._defaultEdgeLabelFn(o,r,i);let p=Bz(this._isDirected,o,r,i);return o=p.v,r=p.w,Object.freeze(p),this._edgeObjs[u]=p,Vw(this._preds[r],o),Vw(this._sucs[o],r),this._in[r][u]=p,this._out[o][u]=p,this._edgeCount++,this}edge(e,t,n){let s=arguments.length===1?Fg(this._isDirected,e):_c(this._isDirected,e,t,n);return this._edgeLabels[s]}edgeAsObj(e,t,n){let s=arguments.length===1?this.edge(e):this.edge(e,t,n);return typeof s!="object"?{label:s}:s}hasEdge(e,t,n){return(arguments.length===1?Fg(this._isDirected,e):_c(this._isDirected,e,t,n))in this._edgeLabels}removeEdge(e,t,n){let s=arguments.length===1?Fg(this._isDirected,e):_c(this._isDirected,e,t,n),o=this._edgeObjs[s];if(o){let r=o.v,i=o.w;delete this._edgeLabels[s],delete this._edgeObjs[s],Gw(this._preds[i],r),Gw(this._sucs[r],i),delete this._in[i][s],delete this._out[r][s],this._edgeCount--}return this}inEdges(e,t){return this.isDirected()?this.filterEdges(this._in[e],e,t):this.nodeEdges(e,t)}outEdges(e,t){return this.isDirected()?this.filterEdges(this._out[e],e,t):this.nodeEdges(e,t)}nodeEdges(e,t){if(e in this._nodes)return this.filterEdges({...this._in[e],...this._out[e]},e,t)}_removeFromParentsChildList(e){delete this._children[this._parent[e]][e]}filterEdges(e,t,n){if(!e)return;let s=Object.values(e);return n?s.filter(o=>o.v===t&&o.w===n||o.v===n&&o.w===t):s}};function Vw(e,t){e[t]?e[t]++:e[t]=1}function Gw(e,t){e[t]!==void 0&&!--e[t]&&delete e[t]}function _c(e,t,n,s){let o=""+t,r=""+n;if(!e&&o>r){let i=o;o=r,r=i}return o+""+r+""+(s===void 0?"\0":s)}function Bz(e,t,n,s){let o=""+t,r=""+n;if(!e&&o>r){let l=o;o=r,r=l}let i={v:o,w:r};return s&&(i.name=s),i}function Fg(e,t){return _c(e,t.v,t.w,t.name)}var zz="4.0.1",_4={};T4(_4,{read:()=>Wz,write:()=>Fz});function Fz(e){let t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:qz(e),edges:Hz(e)},n=e.graph();return n!==void 0&&(t.value=structuredClone(n)),t}function qz(e){return e.nodes().map(t=>{let n=e.node(t),s=e.parent(t),o={v:t};return n!==void 0&&(o.value=n),s!==void 0&&(o.parent=s),o})}function Hz(e){return e.edges().map(t=>{let n=e.edge(t),s={v:t.v,w:t.w};return t.name!==void 0&&(s.name=t.name),n!==void 0&&(s.value=n),s})}function Wz(e){let t=new Us(e.options);return e.value!==void 0&&t.setGraph(e.value),e.nodes.forEach(n=>{t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),e.edges.forEach(n=>{t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}var Vy={};T4(Vy,{CycleException:()=>bf,bellmanFord:()=>L4,components:()=>Vz,dijkstra:()=>kf,dijkstraAll:()=>Xz,findCycles:()=>Qz,floydWarshall:()=>Jz,isAcyclic:()=>tF,postorder:()=>sF,preorder:()=>oF,prim:()=>rF,shortestPaths:()=>iF,tarjan:()=>j4,topsort:()=>P4});var Uz=()=>1;function L4(e,t,n,s){return Kz(e,String(t),n||Uz,s||function(o){return e.outEdges(o)})}function Kz(e,t,n,s){let o={},r,i=0,l=e.nodes(),d=function(h){let m=n(h);o[h.v].distance+m<o[h.w].distance&&(o[h.w]={distance:o[h.v].distance+m,predecessor:h.v},r=!0)},u=function(){l.forEach(function(h){s(h).forEach(function(m){let g=m.v===h?m.v:m.w,v=g===m.v?m.w:m.v;d({v:g,w:v})})})};l.forEach(function(h){let m=h===t?0:Number.POSITIVE_INFINITY;o[h]={distance:m,predecessor:""}});let p=l.length;for(let h=1;h<p&&(r=!1,i++,u(),!!r);h++);if(i===p-1&&(r=!1,u(),r))throw new Error("The graph contains a negative weight cycle");return o}function Vz(e){let t={},n=[],s;function o(r){r in t||(t[r]=!0,s.push(r),e.successors(r).forEach(o),e.predecessors(r).forEach(o))}return e.nodes().forEach(function(r){s=[],o(r),s.length&&n.push(s)}),n}var I4=class{constructor(){this._arr=[],this._keyIndices={}}size(){return this._arr.length}keys(){return this._arr.map(e=>e.key)}has(e){return e in this._keyIndices}priority(e){let t=this._keyIndices[e];if(t!==void 0)return this._arr[t].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(e,t){let n=this._keyIndices,s=String(e);if(!(s in n)){let o=this._arr,r=o.length;return n[s]=r,o.push({key:s,priority:t}),this._decrease(r),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);let e=this._arr.pop();return delete this._keyIndices[e.key],this._heapify(0),e.key}decrease(e,t){let n=this._keyIndices[e];if(n===void 0)throw new Error(`Key not found: ${e}`);let s=this._arr[n].priority;if(t>s)throw new Error(`New priority is greater than current priority. Key: ${e} Old: ${s} New: ${t}`);this._arr[n].priority=t,this._decrease(n)}_heapify(e){let t=this._arr,n=2*e,s=n+1,o=e;n<t.length&&(o=t[n].priority<t[o].priority?n:o,s<t.length&&(o=t[s].priority<t[o].priority?s:o),o!==e&&(this._swap(e,o),this._heapify(o)))}_decrease(e){let t=this._arr,n=t[e].priority,s;for(;e!==0&&(s=e>>1,!(t[s].priority<n));)this._swap(e,s),e=s}_swap(e,t){let n=this._arr,s=this._keyIndices,o=n[e],r=n[t];n[e]=r,n[t]=o,s[r.key]=e,s[o.key]=t}},Gz=()=>1;function kf(e,t,n,s){let o=function(r){return e.outEdges(r)};return Yz(e,String(t),n||Gz,s||o)}function Yz(e,t,n,s){let o={},r=new I4,i,l,d=function(u){let p=u.v!==i?u.v:u.w,h=o[p],m=n(u),g=l.distance+m;if(m<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+u+" Weight: "+m);g<h.distance&&(h.distance=g,h.predecessor=i,r.decrease(p,g))};for(e.nodes().forEach(function(u){let p=u===t?0:Number.POSITIVE_INFINITY;o[u]={distance:p,predecessor:""},r.add(u,p)});r.size()>0&&(i=r.removeMin(),l=o[i],l.distance!==Number.POSITIVE_INFINITY);)s(i).forEach(d);return o}function Xz(e,t,n){return e.nodes().reduce(function(s,o){return s[o]=kf(e,o,t,n),s},{})}function j4(e){let t=0,n=[],s={},o=[];function r(i){let l=s[i]={onStack:!0,lowlink:t,index:t++};if(n.push(i),e.successors(i).forEach(function(d){d in s?s[d].onStack&&(l.lowlink=Math.min(l.lowlink,s[d].index)):(r(d),l.lowlink=Math.min(l.lowlink,s[d].lowlink))}),l.lowlink===l.index){let d=[],u;do u=n.pop(),s[u].onStack=!1,d.push(u);while(i!==u);o.push(d)}}return e.nodes().forEach(function(i){i in s||r(i)}),o}function Qz(e){return j4(e).filter(function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}var Zz=()=>1;function Jz(e,t,n){return eF(e,t||Zz,n||function(s){return e.outEdges(s)})}function eF(e,t,n){let s={},o=e.nodes();return o.forEach(function(r){s[r]={},s[r][r]={distance:0,predecessor:""},o.forEach(function(i){r!==i&&(s[r][i]={distance:Number.POSITIVE_INFINITY,predecessor:""})}),n(r).forEach(function(i){let l=i.v===r?i.w:i.v,d=t(i);s[r][l]={distance:d,predecessor:r}})}),o.forEach(function(r){let i=s[r];o.forEach(function(l){let d=s[l];o.forEach(function(u){let p=d[r],h=i[u],m=d[u],g=p.distance+h.distance;g<m.distance&&(m.distance=g,m.predecessor=h.predecessor)})})}),s}var bf=class extends Error{constructor(...e){super(...e)}};function P4(e){let t={},n={},s=[];function o(r){if(r in n)throw new bf;r in t||(n[r]=!0,t[r]=!0,e.predecessors(r).forEach(o),delete n[r],s.push(r))}if(e.sinks().forEach(o),Object.keys(t).length!==e.nodeCount())throw new bf;return s}function tF(e){try{P4(e)}catch(t){if(t instanceof bf)return!1;throw t}return!0}function nF(e,t,n,s,o){Array.isArray(t)||(t=[t]);let r=(l=>{var d;return(d=e.isDirected()?e.successors(l):e.neighbors(l))!=null?d:[]}),i={};return t.forEach(function(l){if(!e.hasNode(l))throw new Error("Graph does not have node: "+l);o=O4(e,l,n==="post",i,r,s,o)}),o}function O4(e,t,n,s,o,r,i){return t in s||(s[t]=!0,n||(i=r(i,t)),o(t).forEach(function(l){i=O4(e,l,n,s,o,r,i)}),n&&(i=r(i,t))),i}function R4(e,t,n){return nF(e,t,n,function(s,o){return s.push(o),s},[])}function sF(e,t){return R4(e,t,"post")}function oF(e,t){return R4(e,t,"pre")}function rF(e,t){let n=new Us,s={},o=new I4,r;function i(d){let u=d.v===r?d.w:d.v,p=o.priority(u);if(p!==void 0){let h=t(d);h<p&&(s[u]=r,o.decrease(u,h))}}if(e.nodeCount()===0)return n;e.nodes().forEach(function(d){o.add(d,Number.POSITIVE_INFINITY),n.setNode(d)}),o.decrease(e.nodes()[0],0);let l=!1;for(;o.size()>0;){if(r=o.removeMin(),r in s)n.setEdge(r,s[r]);else{if(l)throw new Error("Input graph is not connected: "+e);l=!0}e.nodeEdges(r).forEach(i)}return n}function iF(e,t,n,s){return aF(e,t,n,s??(o=>{let r=e.outEdges(o);return r??[]}))}function aF(e,t,n,s){if(n===void 0)return kf(e,t,n,s);let o=!1,r=e.nodes();for(let i=0;i<r.length;i++){let l=s(r[i]);for(let d=0;d<l.length;d++){let u=l[d],p=u.v===r[i]?u.v:u.w,h=p===u.v?u.w:u.v;n({v:p,w:h})<0&&(o=!0)}if(o)return L4(e,t,n,s)}return kf(e,t,n,s)}function bl(e,t,n,s){let o=s;for(;e.hasNode(o);)o=Gy(s);return n.dummy=t,e.setNode(o,n),o}function lF(e){let t=new Us().setGraph(e.graph());return e.nodes().forEach(n=>t.setNode(n,e.node(n))),e.edges().forEach(n=>{let s=t.edge(n.v,n.w)||{weight:0,minlen:1},o=e.edge(n);t.setEdge(n.v,n.w,{weight:s.weight+o.weight,minlen:Math.max(s.minlen,o.minlen)})}),t}function D4(e){let t=new Us({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function Yw(e,t){let n=e.x,s=e.y,o=t.x-n,r=t.y-s,i=e.width/2,l=e.height/2;if(!o&&!r)throw new Error("Not possible to find intersection inside of the rectangle");let d,u;return Math.abs(r)*i>Math.abs(o)*l?(r<0&&(l=-l),d=l*o/r,u=l):(o<0&&(i=-i),d=i,u=i*r/o),{x:n+d,y:s+u}}function $d(e){let t=rd(z4(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let s=e.node(n),o=s.rank;o!==void 0&&(t[o]||(t[o]=[]),t[o][s.order]=n)}),t}function cF(e){let t=e.nodes().map(s=>{let o=e.node(s).rank;return o===void 0?Number.MAX_VALUE:o}),n=ko(Math.min,t);e.nodes().forEach(s=>{let o=e.node(s);Object.hasOwn(o,"rank")&&(o.rank-=n)})}function dF(e){let t=e.nodes().map(i=>e.node(i).rank).filter(i=>i!==void 0),n=ko(Math.min,t),s=[];e.nodes().forEach(i=>{let l=e.node(i).rank-n;s[l]||(s[l]=[]),s[l].push(i)});let o=0,r=e.graph().nodeRankFactor;Array.from(s).forEach((i,l)=>{i===void 0&&l%r!==0?--o:i!==void 0&&o&&i.forEach(d=>e.node(d).rank+=o)})}function Xw(e,t,n,s){let o={width:0,height:0};return arguments.length>=4&&(o.rank=n,o.order=s),bl(e,"border",o,t)}function uF(e,t=B4){let n=[];for(let s=0;s<e.length;s+=t){let o=e.slice(s,s+t);n.push(o)}return n}var B4=65535;function ko(e,t){if(t.length>B4){let n=uF(t);return e(...n.map(s=>e(...s)))}else return e(...t)}function z4(e){let t=e.nodes().map(n=>{let s=e.node(n).rank;return s===void 0?Number.MIN_VALUE:s});return ko(Math.max,t)}function pF(e,t){let n={lhs:[],rhs:[]};return e.forEach(s=>{t(s)?n.lhs.push(s):n.rhs.push(s)}),n}function F4(e,t){let n=Date.now();try{return t()}finally{console.log(e+" time: "+(Date.now()-n)+"ms")}}function q4(e,t){return t()}var fF=0;function Gy(e){let t=++fF;return e+(""+t)}function rd(e,t,n=1){t==null&&(t=e,e=0);let s=r=>r<t;n<0&&(s=r=>t<r);let o=[];for(let r=e;s(r);r+=n)o.push(r);return o}function wf(e,t){let n={};for(let s of t)e[s]!==void 0&&(n[s]=e[s]);return n}function hh(e,t){let n;return typeof t=="string"?n=s=>s[t]:n=t,Object.entries(e).reduce((s,[o,r])=>(s[o]=n(r,o),s),{})}function hF(e,t){return e.reduce((n,s,o)=>(n[s]=t[o],n),{})}var mh="\0",mF="3.0.0",gF=class{constructor(){Rz(this,"_sentinel");let e={};e._next=e._prev=e,this._sentinel=e}dequeue(){let e=this._sentinel,t=e._prev;if(t!==e)return Qw(t),t}enqueue(e){let t=this._sentinel;e._prev&&e._next&&Qw(e),e._next=t._next,t._next._prev=e,t._next=e,e._prev=t}toString(){let e=[],t=this._sentinel,n=t._prev;for(;n!==t;)e.push(JSON.stringify(n,vF)),n=n._prev;return"["+e.join(", ")+"]"}};function Qw(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function vF(e,t){if(e!=="_next"&&e!=="_prev")return t}var yF=gF,xF=()=>1;function kF(e,t){if(e.nodeCount()<=1)return[];let n=wF(e,t||xF);return bF(n.graph,n.buckets,n.zeroIdx).flatMap(s=>e.outEdges(s.v,s.w)||[])}function bF(e,t,n){var s;let o=[],r=t[t.length-1],i=t[0],l;for(;e.nodeCount();){for(;l=i.dequeue();)qg(e,t,n,l);for(;l=r.dequeue();)qg(e,t,n,l);if(e.nodeCount()){for(let d=t.length-2;d>0;--d)if(l=(s=t[d])==null?void 0:s.dequeue(),l){o=o.concat(qg(e,t,n,l,!0)||[]);break}}}return o}function qg(e,t,n,s,o){let r=[],i=o?r:void 0;return(e.inEdges(s.v)||[]).forEach(l=>{let d=e.edge(l),u=e.node(l.v);o&&r.push({v:l.v,w:l.w}),u.out-=d,k0(t,n,u)}),(e.outEdges(s.v)||[]).forEach(l=>{let d=e.edge(l),u=l.w,p=e.node(u);p.in-=d,k0(t,n,p)}),e.removeNode(s.v),i}function wF(e,t){let n=new Us,s=0,o=0;e.nodes().forEach(l=>{n.setNode(l,{v:l,in:0,out:0})}),e.edges().forEach(l=>{let d=n.edge(l.v,l.w)||0,u=t(l),p=d+u;n.setEdge(l.v,l.w,p);let h=n.node(l.v),m=n.node(l.w);o=Math.max(o,h.out+=u),s=Math.max(s,m.in+=u)});let r=$F(o+s+3).map(()=>new yF),i=s+1;return n.nodes().forEach(l=>{k0(r,i,n.node(l))}),{graph:n,buckets:r,zeroIdx:i}}function k0(e,t,n){var s,o,r;n.out?n.in?(r=e[n.out-n.in+t])==null||r.enqueue(n):(o=e[e.length-1])==null||o.enqueue(n):(s=e[0])==null||s.enqueue(n)}function $F(e){let t=[];for(let n=0;n<e;n++)t.push(n);return t}function SF(e){(e.graph().acyclicer==="greedy"?kF(e,t(e)):EF(e)).forEach(n=>{let s=e.edge(n);e.removeEdge(n),s.forwardName=n.name,s.reversed=!0,e.setEdge(n.w,n.v,s,Gy("rev"))});function t(n){return s=>n.edge(s).weight}}function EF(e){let t=[],n={},s={};function o(r){Object.hasOwn(s,r)||(s[r]=!0,n[r]=!0,e.outEdges(r).forEach(i=>{Object.hasOwn(n,i.w)?t.push(i):o(i.w)}),delete n[r])}return e.nodes().forEach(o),t}function MF(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let s=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,s)}})}function AF(e){e.graph().dummyChains=[],e.edges().forEach(t=>CF(e,t))}function CF(e,t){let n=t.v,s=e.node(n).rank,o=t.w,r=e.node(o).rank,i=t.name,l=e.edge(t),d=l.labelRank;if(r===s+1)return;e.removeEdge(t);let u,p,h;for(h=0,++s;s<r;++h,++s)l.points=[],p={width:0,height:0,edgeLabel:l,edgeObj:t,rank:s},u=bl(e,"edge",p,"_d"),s===d&&(p.width=l.width,p.height=l.height,p.dummy="edge-label",p.labelpos=l.labelpos),e.setEdge(n,u,{weight:l.weight},i),h===0&&e.graph().dummyChains.push(u),n=u;e.setEdge(n,o,{weight:l.weight},i)}function NF(e){e.graph().dummyChains.forEach(t=>{let n=e.node(t),s=n.edgeLabel,o;for(e.setEdge(n.edgeObj,s);n.dummy;)o=e.successors(t)[0],e.removeNode(t),s.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(s.x=n.x,s.y=n.y,s.width=n.width,s.height=n.height),t=o,n=e.node(t)})}function Yy(e){let t={};function n(s){let o=e.node(s);if(Object.hasOwn(t,s))return o.rank;t[s]=!0;let r=e.outEdges(s),i=r?r.map(d=>d==null?Number.POSITIVE_INFINITY:n(d.w)-e.edge(d).minlen):[],l=ko(Math.min,i);return l===Number.POSITIVE_INFINITY&&(l=0),o.rank=l}e.sources().forEach(n)}function ll(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var H4=TF;function TF(e){let t=new Us({directed:!1}),n=e.nodes();if(n.length===0)throw new Error("Graph must have at least one node");let s=n[0],o=e.nodeCount();t.setNode(s,{});let r,i;for(;_F(t,e)<o&&(r=LF(t,e),!!r);)i=t.hasNode(r.v)?ll(e,r):-ll(e,r),IF(t,e,i);return t}function _F(e,t){function n(s){let o=t.nodeEdges(s);o&&o.forEach(r=>{let i=r.v,l=s===i?r.w:i;!e.hasNode(l)&&!ll(t,r)&&(e.setNode(l,{}),e.setEdge(s,l,{}),n(l))})}return e.nodes().forEach(n),e.nodeCount()}function LF(e,t){return t.edges().reduce((n,s)=>{let o=Number.POSITIVE_INFINITY;return e.hasNode(s.v)!==e.hasNode(s.w)&&(o=ll(t,s)),o<n[0]?[o,s]:n},[Number.POSITIVE_INFINITY,null])[1]}function IF(e,t,n){e.nodes().forEach(s=>t.node(s).rank+=n)}var{preorder:jF,postorder:PF}=Vy,OF=Xi;Xi.initLowLimValues=Qy;Xi.initCutValues=Xy;Xi.calcCutValue=W4;Xi.leaveEdge=K4;Xi.enterEdge=V4;Xi.exchangeEdges=G4;function Xi(e){e=lF(e),Yy(e);let t=H4(e);Qy(t),Xy(t,e);let n,s;for(;n=K4(t);)s=V4(t,e,n),G4(t,e,n,s)}function Xy(e,t){let n=PF(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(s=>RF(e,t,s))}function RF(e,t,n){let s=e.node(n).parent,o=e.edge(n,s);o.cutvalue=W4(e,t,n)}function W4(e,t,n){let s=e.node(n).parent,o=!0,r=t.edge(n,s),i=0;r||(o=!1,r=t.edge(s,n)),i=r.weight;let l=t.nodeEdges(n);return l&&l.forEach(d=>{let u=d.v===n,p=u?d.w:d.v;if(p!==s){let h=u===o,m=t.edge(d).weight;if(i+=h?m:-m,BF(e,n,p)){let g=e.edge(n,p).cutvalue;i+=h?-g:g}}}),i}function Qy(e,t){arguments.length<2&&(t=e.nodes()[0]),U4(e,{},1,t)}function U4(e,t,n,s,o){let r=n,i=e.node(s);t[s]=!0;let l=e.neighbors(s);return l&&l.forEach(d=>{Object.hasOwn(t,d)||(n=U4(e,t,n,d,s))}),i.low=r,i.lim=n++,o?i.parent=o:delete i.parent,n}function K4(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function V4(e,t,n){let s=n.v,o=n.w;t.hasEdge(s,o)||(s=n.w,o=n.v);let r=e.node(s),i=e.node(o),l=r,d=!1;return r.lim>i.lim&&(l=i,d=!0),t.edges().filter(u=>d===Zw(e,e.node(u.v),l)&&d!==Zw(e,e.node(u.w),l)).reduce((u,p)=>ll(t,p)<ll(t,u)?p:u)}function G4(e,t,n,s){let o=n.v,r=n.w;e.removeEdge(o,r),e.setEdge(s.v,s.w,{}),Qy(e),Xy(e,t),DF(e,t)}function DF(e,t){let n=e.nodes().find(o=>!e.node(o).parent);if(!n)return;let s=jF(e,[n]);s=s.slice(1),s.forEach(o=>{let r=e.node(o).parent,i=t.edge(o,r),l=!1;i||(i=t.edge(r,o),l=!0),t.node(o).rank=t.node(r).rank+(l?i.minlen:-i.minlen)})}function BF(e,t,n){return e.hasEdge(t,n)}function Zw(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var zF=FF;function FF(e){let t=e.graph().ranker;if(typeof t=="function")return t(e);switch(t){case"network-simplex":Jw(e);break;case"tight-tree":HF(e);break;case"longest-path":qF(e);break;case"none":break;default:Jw(e)}}var qF=Yy;function HF(e){Yy(e),H4(e)}function Jw(e){OF(e)}var WF=UF;function UF(e){let t=VF(e);e.graph().dummyChains.forEach(n=>{let s=e.node(n),o=s.edgeObj,r=KF(e,t,o.v,o.w),i=r.path,l=r.lca,d=0,u=i[d],p=!0;for(;n!==o.w;){if(s=e.node(n),p){for(;(u=i[d])!==l&&e.node(u).maxRank<s.rank;)d++;u===l&&(p=!1)}if(!p){for(;d<i.length-1&&e.node(i[d+1]).minRank<=s.rank;)d++;u=i[d]}u!==void 0&&e.setParent(n,u),n=e.successors(n)[0]}})}function KF(e,t,n,s){let o=[],r=[],i=Math.min(t[n].low,t[s].low),l=Math.max(t[n].lim,t[s].lim),d;d=n;do d=e.parent(d),o.push(d);while(d&&(t[d].low>i||l>t[d].lim));let u=d,p=s;for(;(p=e.parent(p))!==u;)r.push(p);return{path:o.concat(r.reverse()),lca:u}}function VF(e){let t={},n=0;function s(o){let r=n;e.children(o).forEach(s),t[o]={low:r,lim:n++}}return e.children(mh).forEach(s),t}function GF(e){let t=bl(e,"root",{},"_root"),n=YF(e),s=Object.values(n),o=ko(Math.max,s)-1,r=2*o+1;e.graph().nestingRoot=t,e.edges().forEach(l=>e.edge(l).minlen*=r);let i=XF(e)+1;e.children(mh).forEach(l=>Y4(e,t,r,i,o,n,l)),e.graph().nodeRankFactor=r}function Y4(e,t,n,s,o,r,i){var l;let d=e.children(i);if(!d.length){i!==t&&e.setEdge(t,i,{weight:0,minlen:n});return}let u=Xw(e,"_bt"),p=Xw(e,"_bb"),h=e.node(i);e.setParent(u,i),h.borderTop=u,e.setParent(p,i),h.borderBottom=p,d.forEach(m=>{var g;Y4(e,t,n,s,o,r,m);let v=e.node(m),y=v.borderTop?v.borderTop:m,b=v.borderBottom?v.borderBottom:m,E=v.borderTop?s:2*s,$=y!==b?1:o-((g=r[i])!=null?g:0)+1;e.setEdge(u,y,{weight:E,minlen:$,nestingEdge:!0}),e.setEdge(b,p,{weight:E,minlen:$,nestingEdge:!0})}),e.parent(i)||e.setEdge(t,u,{weight:0,minlen:o+((l=r[i])!=null?l:0)})}function YF(e){let t={};function n(s,o){let r=e.children(s);r&&r.length&&r.forEach(i=>n(i,o+1)),t[s]=o}return e.children(mh).forEach(s=>n(s,1)),t}function XF(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function QF(e){let t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(n=>{e.edge(n).nestingEdge&&e.removeEdge(n)})}var ZF=JF;function JF(e){function t(n){let s=e.children(n),o=e.node(n);if(s.length&&s.forEach(t),Object.hasOwn(o,"minRank")){o.borderLeft=[],o.borderRight=[];for(let r=o.minRank,i=o.maxRank+1;r<i;++r)e$(e,"borderLeft","_bl",n,o,r),e$(e,"borderRight","_br",n,o,r)}}e.children(mh).forEach(t)}function e$(e,t,n,s,o,r){let i={width:0,height:0,rank:r,borderType:t},l=o[t][r-1],d=bl(e,"border",i,n);o[t][r]=d,e.setParent(d,s),l&&e.setEdge(l,d,{weight:1})}function e7(e){var t;let n=(t=e.graph().rankdir)==null?void 0:t.toLowerCase();(n==="lr"||n==="rl")&&X4(e)}function t7(e){var t;let n=(t=e.graph().rankdir)==null?void 0:t.toLowerCase();(n==="bt"||n==="rl")&&n7(e),(n==="lr"||n==="rl")&&(s7(e),X4(e))}function X4(e){e.nodes().forEach(t=>t$(e.node(t))),e.edges().forEach(t=>t$(e.edge(t)))}function t$(e){let t=e.width;e.width=e.height,e.height=t}function n7(e){e.nodes().forEach(t=>Hg(e.node(t))),e.edges().forEach(t=>{var n;let s=e.edge(t);(n=s.points)==null||n.forEach(Hg),Object.hasOwn(s,"y")&&Hg(s)})}function Hg(e){e.y=-e.y}function s7(e){e.nodes().forEach(t=>Wg(e.node(t))),e.edges().forEach(t=>{var n;let s=e.edge(t);(n=s.points)==null||n.forEach(Wg),Object.hasOwn(s,"x")&&Wg(s)})}function Wg(e){let t=e.x;e.x=e.y,e.y=t}function o7(e){let t={},n=e.nodes().filter(l=>!e.children(l).length),s=n.map(l=>e.node(l).rank),o=ko(Math.max,s),r=rd(o+1).map(()=>[]);function i(l){if(t[l])return;t[l]=!0;let d=e.node(l);r[d.rank].push(l);let u=e.successors(l);u&&u.forEach(i)}return n.sort((l,d)=>e.node(l).rank-e.node(d).rank).forEach(i),r}function r7(e,t){let n=0;for(let s=1;s<t.length;++s)n+=i7(e,t[s-1],t[s]);return n}function i7(e,t,n){let s=hF(n,n.map((u,p)=>p)),o=t.flatMap(u=>{let p=e.outEdges(u);return p?p.map(h=>({pos:s[h.w],weight:e.edge(h).weight})).sort((h,m)=>h.pos-m.pos):[]}),r=1;for(;r<n.length;)r<<=1;let i=2*r-1;r-=1;let l=new Array(i).fill(0),d=0;return o.forEach(u=>{let p=u.pos+r;l[p]+=u.weight;let h=0;for(;p>0;)p%2&&(h+=l[p+1]),p=p-1>>1,l[p]+=u.weight;d+=u.weight*h}),d}function a7(e,t=[]){return t.map(n=>{let s=e.inEdges(n);if(!s||!s.length)return{v:n};{let o=s.reduce((r,i)=>{let l=e.edge(i),d=e.node(i.v);return{sum:r.sum+l.weight*d.order,weight:r.weight+l.weight}},{sum:0,weight:0});return{v:n,barycenter:o.sum/o.weight,weight:o.weight}}})}function l7(e,t){let n={};e.forEach((o,r)=>{let i={indegree:0,in:[],out:[],vs:[o.v],i:r};o.barycenter!==void 0&&(i.barycenter=o.barycenter,i.weight=o.weight),n[o.v]=i}),t.edges().forEach(o=>{let r=n[o.v],i=n[o.w];r!==void 0&&i!==void 0&&(i.indegree++,r.out.push(i))});let s=Object.values(n).filter(o=>!o.indegree);return c7(s)}function c7(e){let t=[];function n(o){return r=>{r.merged||(r.barycenter===void 0||o.barycenter===void 0||r.barycenter>=o.barycenter)&&d7(o,r)}}function s(o){return r=>{r.in.push(o),--r.indegree===0&&e.push(r)}}for(;e.length;){let o=e.pop();t.push(o),o.in.reverse().forEach(n(o)),o.out.forEach(s(o))}return t.filter(o=>!o.merged).map(o=>wf(o,["vs","i","barycenter","weight"]))}function d7(e,t){let n=0,s=0;e.weight&&(n+=e.barycenter*e.weight,s+=e.weight),t.weight&&(n+=t.barycenter*t.weight,s+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/s,e.weight=s,e.i=Math.min(t.i,e.i),t.merged=!0}function u7(e,t){let n=pF(e,p=>Object.hasOwn(p,"barycenter")),s=n.lhs,o=n.rhs.sort((p,h)=>h.i-p.i),r=[],i=0,l=0,d=0;s.sort(p7(!!t)),d=n$(r,o,d),s.forEach(p=>{d+=p.vs.length,r.push(p.vs),i+=p.barycenter*p.weight,l+=p.weight,d=n$(r,o,d)});let u={vs:r.flat(1)};return l&&(u.barycenter=i/l,u.weight=l),u}function n$(e,t,n){let s;for(;t.length&&(s=t[t.length-1]).i<=n;)t.pop(),e.push(s.vs),n++;return n}function p7(e){return(t,n)=>t.barycenter<n.barycenter?-1:t.barycenter>n.barycenter?1:e?n.i-t.i:t.i-n.i}function Q4(e,t,n,s){let o=e.children(t),r=e.node(t),i=r?r.borderLeft:void 0,l=r?r.borderRight:void 0,d={};i&&(o=o.filter(m=>m!==i&&m!==l));let u=a7(e,o);u.forEach(m=>{if(e.children(m.v).length){let g=Q4(e,m.v,n,s);d[m.v]=g,Object.hasOwn(g,"barycenter")&&h7(m,g)}});let p=l7(u,n);f7(p,d);let h=u7(p,s);if(i&&l){h.vs=[i,h.vs,l].flat(1);let m=e.predecessors(i);if(m&&m.length){let g=e.node(m[0]),v=e.predecessors(l),y=e.node(v[0]);Object.hasOwn(h,"barycenter")||(h.barycenter=0,h.weight=0),h.barycenter=(h.barycenter*h.weight+g.order+y.order)/(h.weight+2),h.weight+=2}}return h}function f7(e,t){e.forEach(n=>{n.vs=n.vs.flatMap(s=>t[s]?t[s].vs:s)})}function h7(e,t){e.barycenter!==void 0?(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight):(e.barycenter=t.barycenter,e.weight=t.weight)}function m7(e,t,n,s){s||(s=e.nodes());let o=g7(e),r=new Us({compound:!0}).setGraph({root:o}).setDefaultNodeLabel(i=>e.node(i));return s.forEach(i=>{let l=e.node(i),d=e.parent(i);if(l.rank===t||l.minRank<=t&&t<=l.maxRank){r.setNode(i),r.setParent(i,d||o);let u=e[n](i);u&&u.forEach(p=>{let h=p.v===i?p.w:p.v,m=r.edge(h,i),g=m!==void 0?m.weight:0;r.setEdge(h,i,{weight:e.edge(p).weight+g})}),Object.hasOwn(l,"minRank")&&r.setNode(i,{borderLeft:l.borderLeft[t],borderRight:l.borderRight[t]})}}),r}function g7(e){let t;for(;e.hasNode(t=Gy("_root")););return t}function v7(e,t,n){let s={},o;n.forEach(r=>{let i=e.parent(r),l,d;for(;i;){if(l=e.parent(i),l?(d=s[l],s[l]=i):(d=o,o=i),d&&d!==i){t.setEdge(d,i);return}i=l}})}function Z4(e,t={}){if(typeof t.customOrder=="function"){t.customOrder(e,Z4);return}let n=z4(e),s=s$(e,rd(1,n+1),"inEdges"),o=s$(e,rd(n-1,-1,-1),"outEdges"),r=o7(e);if(o$(e,r),t.disableOptimalOrderHeuristic)return;let i=Number.POSITIVE_INFINITY,l,d=t.constraints||[];for(let u=0,p=0;p<4;++u,++p){y7(u%2?s:o,u%4>=2,d),r=$d(e);let h=r7(e,r);h<i?(p=0,l=Object.assign({},r),i=h):h===i&&(l=structuredClone(r))}o$(e,l)}function s$(e,t,n){let s=new Map,o=(r,i)=>{s.has(r)||s.set(r,[]),s.get(r).push(i)};for(let r of e.nodes()){let i=e.node(r);if(typeof i.rank=="number"&&o(i.rank,r),typeof i.minRank=="number"&&typeof i.maxRank=="number")for(let l=i.minRank;l<=i.maxRank;l++)l!==i.rank&&o(l,r)}return t.map(function(r){return m7(e,r,n,s.get(r)||[])})}function y7(e,t,n){let s=new Us;e.forEach(function(o){n.forEach(l=>s.setEdge(l.left,l.right));let r=o.graph().root,i=Q4(o,r,s,t);i.vs.forEach((l,d)=>o.node(l).order=d),v7(o,s,i.vs)})}function o$(e,t){Object.values(t).forEach(n=>n.forEach((s,o)=>e.node(s).order=o))}function x7(e,t){let n={};function s(o,r){let i=0,l=0,d=o.length,u=r[r.length-1];return r.forEach((p,h)=>{let m=b7(e,p),g=m?e.node(m).order:d;(m||p===u)&&(r.slice(l,h+1).forEach(v=>{let y=e.predecessors(v);y&&y.forEach(b=>{let E=e.node(b),$=E.order;($<i||g<$)&&!(E.dummy&&e.node(v).dummy)&&J4(n,b,v)})}),l=h+1,i=g)}),r}return t.length&&t.reduce(s),n}function k7(e,t){let n={};function s(r,i,l,d,u){rd(i,l).forEach(p=>{let h=r[p];if(h!==void 0&&e.node(h).dummy){let m=e.predecessors(h);m&&m.forEach(g=>{if(g===void 0)return;let v=e.node(g);v.dummy&&(v.order<d||v.order>u)&&J4(n,g,h)})}})}function o(r,i){let l=-1,d=-1,u=0;return i.forEach((p,h)=>{if(e.node(p).dummy==="border"){let m=e.predecessors(p);if(m&&m.length){let g=m[0];if(g===void 0)return;d=e.node(g).order,s(i,u,h,l,d),u=h,l=d}}s(i,u,i.length,d,r.length)}),i}return t.length&&t.reduce(o),n}function b7(e,t){if(e.node(t).dummy){let n=e.predecessors(t);if(n)return n.find(s=>e.node(s).dummy)}}function J4(e,t,n){if(t>n){let o=t;t=n,n=o}let s=e[t];s||(e[t]=s={}),s[n]=!0}function w7(e,t,n){if(t>n){let o=t;t=n,n=o}let s=e[t];return s!==void 0&&Object.hasOwn(s,n)}function $7(e,t,n,s){let o={},r={},i={};return t.forEach(l=>{l.forEach((d,u)=>{o[d]=d,r[d]=d,i[d]=u})}),t.forEach(l=>{let d=-1;l.forEach(u=>{let p=s(u);if(p&&p.length){let h=p.sort((g,v)=>{let y=i[g],b=i[v];return(y!==void 0?y:0)-(b!==void 0?b:0)}),m=(h.length-1)/2;for(let g=Math.floor(m),v=Math.ceil(m);g<=v;++g){let y=h[g];if(y===void 0)continue;let b=i[y];if(b!==void 0&&r[u]===u&&d<b&&!w7(n,u,y)){let E=o[y];E!==void 0&&(r[y]=u,r[u]=o[u]=E,d=b)}}}})}),{root:o,align:r}}function S7(e,t,n,s,o=!1){let r={},i=E7(e,t,n,o),l=o?"borderLeft":"borderRight";function d(g,v){let y=i.nodes().slice(),b={},E=y.pop();for(;E;){if(b[E])g(E);else{b[E]=!0,y.push(E);for(let $ of v(E))y.push($)}E=y.pop()}}function u(g){let v=i.inEdges(g);v?r[g]=v.reduce((y,b)=>{var E;let $=(E=r[b.v])!=null?E:0,A=i.edge(b);return Math.max(y,$+(A!==void 0?A:0))},0):r[g]=0}function p(g){let v=i.outEdges(g),y=Number.POSITIVE_INFINITY;v&&(y=v.reduce((E,$)=>{let A=r[$.w],T=i.edge($);return Math.min(E,(A!==void 0?A:0)-(T!==void 0?T:0))},Number.POSITIVE_INFINITY));let b=e.node(g);y!==Number.POSITIVE_INFINITY&&b.borderType!==l&&(r[g]=Math.max(r[g]!==void 0?r[g]:0,y))}function h(g){return i.predecessors(g)||[]}function m(g){return i.successors(g)||[]}return d(u,h),d(p,m),Object.keys(s).forEach(g=>{var v;let y=n[g];y!==void 0&&(r[g]=(v=r[y])!=null?v:0)}),r}function E7(e,t,n,s){let o=new Us,r=e.graph(),i=T7(r.nodesep,r.edgesep,s);return t.forEach(l=>{let d;l.forEach(u=>{let p=n[u];if(p!==void 0){if(o.setNode(p),d!==void 0){let h=n[d];if(h!==void 0){let m=o.edge(h,p);o.setEdge(h,p,Math.max(i(e,u,d),m||0))}}d=u}})}),o}function M7(e,t){return Object.values(t).reduce((n,s)=>{let o=Number.NEGATIVE_INFINITY,r=Number.POSITIVE_INFINITY;Object.entries(s).forEach(([l,d])=>{let u=_7(e,l)/2;o=Math.max(d+u,o),r=Math.min(d-u,r)});let i=o-r;return i<n[0]&&(n=[i,s]),n},[Number.POSITIVE_INFINITY,null])[1]}function A7(e,t){let n=Object.values(t),s=ko(Math.min,n),o=ko(Math.max,n);["u","d"].forEach(r=>{["l","r"].forEach(i=>{let l=r+i,d=e[l];if(!d||d===t)return;let u=Object.values(d),p=s-ko(Math.min,u);i!=="l"&&(p=o-ko(Math.max,u)),p&&(e[l]=hh(d,h=>h+p))})})}function C7(e,t=void 0){let n=e.ul;return n?hh(n,(s,o)=>{var r,i;if(t){let d=t.toLowerCase(),u=e[d];if(u&&u[o]!==void 0)return u[o]}let l=Object.values(e).map(d=>{let u=d[o];return u!==void 0?u:0}).sort((d,u)=>d-u);return(((r=l[1])!=null?r:0)+((i=l[2])!=null?i:0))/2}):{}}function N7(e){let t=$d(e),n=Object.assign(x7(e,t),k7(e,t)),s={},o;["u","d"].forEach(i=>{o=i==="u"?t:Object.values(t).reverse(),["l","r"].forEach(l=>{l==="r"&&(o=o.map(p=>Object.values(p).reverse()));let d=$7(e,o,n,p=>(i==="u"?e.predecessors(p):e.successors(p))||[]),u=S7(e,o,d.root,d.align,l==="r");l==="r"&&(u=hh(u,p=>-p)),s[i+l]=u})});let r=M7(e,s);return A7(s,r),C7(s,e.graph().align)}function T7(e,t,n){return(s,o,r)=>{let i=s.node(o),l=s.node(r),d=0,u;if(d+=i.width/2,Object.hasOwn(i,"labelpos"))switch(i.labelpos.toLowerCase()){case"l":u=-i.width/2;break;case"r":u=i.width/2;break}if(u&&(d+=n?u:-u),u=void 0,d+=(i.dummy?t:e)/2,d+=(l.dummy?t:e)/2,d+=l.width/2,Object.hasOwn(l,"labelpos"))switch(l.labelpos.toLowerCase()){case"l":u=l.width/2;break;case"r":u=-l.width/2;break}return u&&(d+=n?u:-u),d}}function _7(e,t){return e.node(t).width}function L7(e){e=D4(e),I7(e),Object.entries(N7(e)).forEach(([t,n])=>e.node(t).x=n)}function I7(e){let t=$d(e),n=e.graph(),s=n.ranksep,o=n.rankalign,r=0;t.forEach(i=>{let l=i.reduce((d,u)=>{var p;let h=(p=e.node(u).height)!=null?p:0;return d>h?d:h},0);i.forEach(d=>{let u=e.node(d);o==="top"?u.y=r+u.height/2:o==="bottom"?u.y=r+l-u.height/2:u.y=r+l/2}),r+=l+s})}function j7(e,t={}){let n=t.debugTiming?F4:q4;return n("layout",()=>{let s=n(" buildLayoutGraph",()=>W7(e));return n(" runLayout",()=>P7(s,n,t)),n(" updateInputGraph",()=>O7(e,s)),s})}function P7(e,t,n){t(" makeSpaceForEdgeLabels",()=>U7(e)),t(" removeSelfEdges",()=>e9(e)),t(" acyclic",()=>SF(e)),t(" nestingGraph.run",()=>GF(e)),t(" rank",()=>zF(D4(e))),t(" injectEdgeLabelProxies",()=>K7(e)),t(" removeEmptyRanks",()=>dF(e)),t(" nestingGraph.cleanup",()=>QF(e)),t(" normalizeRanks",()=>cF(e)),t(" assignRankMinMax",()=>V7(e)),t(" removeEdgeLabelProxies",()=>G7(e)),t(" normalize.run",()=>AF(e)),t(" parentDummyChains",()=>WF(e)),t(" addBorderSegments",()=>ZF(e)),t(" order",()=>Z4(e,n)),t(" insertSelfEdges",()=>t9(e)),t(" adjustCoordinateSystem",()=>e7(e)),t(" position",()=>L7(e)),t(" positionSelfEdges",()=>n9(e)),t(" removeBorderNodes",()=>J7(e)),t(" normalize.undo",()=>NF(e)),t(" fixupEdgeLabelCoords",()=>Q7(e)),t(" undoCoordinateSystem",()=>t7(e)),t(" translateGraph",()=>Y7(e)),t(" assignNodeIntersects",()=>X7(e)),t(" reversePoints",()=>Z7(e)),t(" acyclic.undo",()=>MF(e))}function O7(e,t){e.nodes().forEach(n=>{let s=e.node(n),o=t.node(n);s&&(s.x=o.x,s.y=o.y,s.order=o.order,s.rank=o.rank,t.children(n).length&&(s.width=o.width,s.height=o.height))}),e.edges().forEach(n=>{let s=e.edge(n),o=t.edge(n);s.points=o.points,Object.hasOwn(o,"x")&&(s.x=o.x,s.y=o.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}var R7=["nodesep","edgesep","ranksep","marginx","marginy"],D7={ranksep:50,edgesep:20,nodesep:50,rankdir:"TB",rankalign:"center"},B7=["acyclicer","ranker","rankdir","align","rankalign"],z7=["width","height","rank"],r$={width:0,height:0},F7=["minlen","weight","width","height","labeloffset"],q7={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},H7=["labelpos"];function W7(e){let t=new Us({multigraph:!0,compound:!0}),n=Kg(e.graph());return t.setGraph(Object.assign({},D7,Ug(n,R7),wf(n,B7))),e.nodes().forEach(s=>{let o=Kg(e.node(s)),r=Ug(o,z7);Object.keys(r$).forEach(l=>{r[l]===void 0&&(r[l]=r$[l])}),t.setNode(s,r);let i=e.parent(s);i!==void 0&&t.setParent(s,i)}),e.edges().forEach(s=>{let o=Kg(e.edge(s));t.setEdge(s,Object.assign({},q7,Ug(o,F7),wf(o,H7)))}),t}function U7(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let s=e.edge(n);s.minlen*=2,s.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?s.width+=s.labeloffset:s.height+=s.labeloffset)})}function K7(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let s=e.node(t.v),o={rank:(e.node(t.w).rank-s.rank)/2+s.rank,e:t};bl(e,"edge-proxy",o,"_ep")}})}function V7(e){let t=0;e.nodes().forEach(n=>{let s=e.node(n);s.borderTop&&(s.minRank=e.node(s.borderTop).rank,s.maxRank=e.node(s.borderBottom).rank,t=Math.max(t,s.maxRank))}),e.graph().maxRank=t}function G7(e){e.nodes().forEach(t=>{let n=e.node(t);if(n.dummy==="edge-proxy"){let s=n;e.edge(s.e).labelRank=n.rank,e.removeNode(t)}})}function Y7(e){let t=Number.POSITIVE_INFINITY,n=0,s=Number.POSITIVE_INFINITY,o=0,r=e.graph(),i=r.marginx||0,l=r.marginy||0;function d(u){let p=u.x,h=u.y,m=u.width,g=u.height;t=Math.min(t,p-m/2),n=Math.max(n,p+m/2),s=Math.min(s,h-g/2),o=Math.max(o,h+g/2)}e.nodes().forEach(u=>d(e.node(u))),e.edges().forEach(u=>{let p=e.edge(u);Object.hasOwn(p,"x")&&d(p)}),t-=i,s-=l,e.nodes().forEach(u=>{let p=e.node(u);p.x-=t,p.y-=s}),e.edges().forEach(u=>{let p=e.edge(u);p.points.forEach(h=>{h.x-=t,h.y-=s}),Object.hasOwn(p,"x")&&(p.x-=t),Object.hasOwn(p,"y")&&(p.y-=s)}),r.width=n-t+i,r.height=o-s+l}function X7(e){e.edges().forEach(t=>{let n=e.edge(t),s=e.node(t.v),o=e.node(t.w),r,i;n.points?(r=n.points[0],i=n.points[n.points.length-1]):(n.points=[],r=o,i=s),n.points.unshift(Yw(s,r)),n.points.push(Yw(o,i))})}function Q7(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset;break}})}function Z7(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function J7(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),s=e.node(n.borderTop),o=e.node(n.borderBottom),r=e.node(n.borderLeft[n.borderLeft.length-1]),i=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(i.x-r.x),n.height=Math.abs(o.y-s.y),n.x=r.x+n.width/2,n.y=s.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy==="border"&&e.removeNode(t)})}function e9(e){e.edges().forEach(t=>{if(t.v===t.w){let n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function t9(e){$d(e).forEach(t=>{let n=0;t.forEach((s,o)=>{let r=e.node(s);r.order=o+n,(r.selfEdges||[]).forEach(i=>{bl(e,"selfedge",{width:i.label.width,height:i.label.height,rank:r.rank,order:o+ ++n,e:i.e,label:i.label},"_se")}),delete r.selfEdges})})}function n9(e){e.nodes().forEach(t=>{let n=e.node(t);if(n.dummy==="selfedge"){let s=n,o=e.node(s.e.v),r=o.x+o.width/2,i=o.y,l=n.x-r,d=o.height/2;e.setEdge(s.e,s.label),e.removeNode(t),s.label.points=[{x:r+2*l/3,y:i-d},{x:r+5*l/6,y:i-d},{x:r+l,y:i},{x:r+5*l/6,y:i+d},{x:r+2*l/3,y:i+d}],s.label.x=n.x,s.label.y=n.y}})}function Ug(e,t){return hh(wf(e,t),Number)}function Kg(e){let t={};return e&&Object.entries(e).forEach(([n,s])=>{typeof n=="string"&&(n=n.toLowerCase()),t[n]=s}),t}function s9(e){let t=$d(e),n=new Us({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(s=>{n.setNode(s,{label:s}),n.setParent(s,"layer"+e.node(s).rank)}),e.edges().forEach(s=>n.setEdge(s.v,s.w,{},s.name)),t.forEach((s,o)=>{let r="layer"+o;n.setNode(r,{rank:"same"}),s.reduce((i,l)=>(n.setEdge(i,l,{style:"invis"}),l))}),n}var o9={graphlib:N4,version:mF,layout:j7,debug:s9,util:{time:F4,notime:q4}},$f=o9;function nr(e,t,n){if(e.length>0&&e.every(r=>r.col!==void 0&&r.row!==void 0))return e.map(r=>({...r,col:r.col,row:r.row}));const o=r9(e.map(r=>r.id),t,n);return e.map(r=>{const i=o.get(r.id)??{col:1,row:1};return{...r,col:i.col,row:i.row}})}function r9(e,t,n){const s=new Set(e),o=new $f.graphlib.Graph;o.setGraph({rankdir:n,nodesep:16,ranksep:16,marginx:0,marginy:0}),o.setDefaultEdgeLabel(()=>({}));for(const l of e)o.setNode(l,{width:10,height:10});for(const l of t)l.from!==l.to&&s.has(l.from)&&s.has(l.to)&&o.setEdge(l.from,l.to);$f.layout(o);const r=e.map(l=>{const d=o.node(l);return{id:l,x:Math.round(d?.x??0),y:Math.round(d?.y??0)}}),i=new Map;return n==="TB"?[...new Set(r.map(d=>d.y))].sort((d,u)=>d-u).forEach((d,u)=>{r.filter(p=>p.y===d).sort((p,h)=>p.x-h.x).forEach((p,h)=>i.set(p.id,{col:h+1,row:u+1}))}):[...new Set(r.map(d=>d.x))].sort((d,u)=>d-u).forEach((d,u)=>{r.filter(p=>p.x===d).sort((p,h)=>p.y-h.y).forEach((p,h)=>i.set(p.id,{col:u+1,row:h+1}))}),i}var i9={agent:"AGENT",llm:"LLM",tool:"TOOL",human:"HUMAN",memory:"MEMORY"};function a9(e,t){const n=new Set(e.map(d=>d.id)),s=new Map,o=new Map;for(const d of e)s.set(d.id,0),o.set(d.id,[]);for(const d of t)!n.has(d.from)||!n.has(d.to)||d.from===d.to||(s.set(d.to,(s.get(d.to)??0)+1),o.get(d.from)?.push(d.to));let r=e.filter(d=>d.kind==="start").map(d=>d.id);r.length===0&&(r=e.filter(d=>(s.get(d.id)??0)===0).map(d=>d.id)),r.length===0&&e[0]!==void 0&&(r=[e[0].id]);const i=new Map,l=[...r];for(;l.length>0;){const d=l.shift();if(!i.has(d)){i.set(d,i.size);for(const u of o.get(d)??[]){const p=(s.get(u)??0)-1;s.set(u,p),p<=0&&!i.has(u)&&l.push(u)}}}for(const d of e)i.has(d.id)||i.set(d.id,i.size);return i}var i$=/^(no|fail|failed|error|reject|rejected)\b/i,l9=160,c9=64,d9=150,a$=52;function u9(e){const t=e.edges??[],n=e.groups??[],s=e.nodes??[],o=!(s.length>0&&s.every(V=>V.col!==void 0&&V.row!==void 0)),r=nr(s,t,e.dir??"LR"),i=l9,l=c9,d=56,u=48,p=Yi(n),h=(n.length>0?Gn.padX:22)+p.padX,m=(n.length>0?Gn.padTop:22)+p.padTop,g=(n.length>0?Gn.padBot:18)+p.padBot,v=wd(n),y=Math.max(1,...r.map(V=>V.col+((V.w??1)-1)),v.cols),b=Math.max(1,...r.map(V=>V.row),v.rows),E=V=>h+(V-1)*(i+d),$=V=>m+(V-1)*(l+u),A=V=>({x:E(V.col),y:$(V.row),w:(V.w??1)*i+((V.w??1)-1)*d,h:l}),T=V=>{const re=A(V);if((V.kind??"process")==="decision")return re;const Q=(i-d9)/2,ne=(l-a$)/2;return{x:re.x+Q,y:re.y+ne,w:re.w-Q*2,h:a$}},N=new Map(r.map(V=>[V.id,V])),j=h*2+y*i+(y-1)*d,P=m+b*l+(b-1)*u+g,I=V=>V.kind==="error"||i$.test(V.label??""),O=new Set(t.filter(I).map(V=>V.to)),C=new Set(r.filter(V=>V.kind==="end"&&!O.has(V.id)&&!i$.test(V.label)).map(V=>V.id)),D=tr({quick:o,cols:y,rows:b,cellW:i,cellH:l,gapX:d,gapY:u,padX:h,padTop:m}),F=Sn("Flowchart",e.title,[wt(r.length,"step")]);let U=`<svg viewBox="0 0 ${j} ${P}"${F.attrs}${D}>${F.title}`;n.length>0&&(U+=xl(n,{xOf:E,yOf:$,cellW:i,cellH:l,gapX:d,gapY:u,skin:!0}));const X={plain:!1,dashed:!1,error:!1,accent:!1},B=[],te=qs(t),ee=a9(r,t),H=V=>ee.get(V)??0,W=Hs(t,V=>{const re=N.get(V);return re!==void 0?T(re):void 0});U+=`<g${he("edges")}>`,t.forEach((V,re)=>{const Q=N.get(V.from),ne=N.get(V.to);if(!Q||!ne)return;const Z=Fs(T(Q),T(ne),te[re]??0,W[re]??0),q=I(V),de=!q&&C.has(V.to),le=!q&&V.kind==="dashed",J=q?"var(--negative)":de?"var(--accent)":"var(--muted)",ue=q?"skErr":de?"skAccent":le?"skOpen":"skArrow",ve=de?1.75:1.5,we=le?' stroke-dasharray="5 4"':"";q?X.error=!0:de?X.accent=!0:le?X.dashed=!0:X.plain=!0;const $e=Math.max(H(V.from),H(V.to));U+=`<path d="${Z.d}" fill="none" stroke="${J}" stroke-width="${ve}"${we} marker-end="url(#${ue})"${_(`edges.${re}`)}${hn($e)}/>`,B.push({lx:Z.lx,ly:Z.ly,...V.label!==void 0?{label:V.label}:{},err:q,accent:de,path:`edges.${re}`,reveal:$e})}),U+="</g>";const K=new Set;U+=`<g${he("nodes")}>`,r.forEach((V,re)=>{const Q=V.kind??"process";K.add(Q);const ne=T(V),Z=ne.x+ne.w/2,q=ne.y+ne.h/2,de=C.has(V.id),le=i9[Q],J=Q==="start"||Q==="memory",ue=de?"var(--accent)":J?"var(--rule-solid)":"var(--ink)",ve=de?1.5:J?1:1.5,we=de?"var(--accent-tint)":J?"var(--paper-2)":"var(--paper)",$e=Q==="human"?' stroke-dasharray="4 3"':"";let je;Q==="decision"?je=`<polygon points="${Z},${ne.y} ${ne.x+ne.w},${q} ${Z},${ne.y+ne.h} ${ne.x},${q}" fill="${we}" stroke="${ue}" stroke-width="${ve}" stroke-linejoin="round"/>`:Q==="start"||Q==="end"?je=`<rect x="${ne.x}" y="${ne.y}" width="${ne.w}" height="${ne.h}" rx="${ne.h/2}" fill="${we}" stroke="${ue}" stroke-width="${ve}"/>`:je=`<rect x="${ne.x}" y="${ne.y}" width="${ne.w}" height="${ne.h}" rx="4" fill="${we}" stroke="${ue}" stroke-width="${ve}"${$e}/>`,le!==void 0&&(je+=`<text x="${ne.x+8}" y="${ne.y+11}" class="blk-chip t-sub">${le}</text>`);const De=V.label.indexOf(`
2837
+ `),Me=De>=0?V.label.slice(0,De):V.label,Be=De>=0?V.label.slice(De+1).replace(/\s+/g," ").trim():"",Ge=Q==="decision"?18:20,fe=Be.length>0?lt(Me,Ge,1):lt(Me,Ge,2),ge=de?" c-accent":"",Ce=le!==void 0?4:0;let Fe="";if(Q==="agent"||Q==="llm"){const qe=lt(Me,17,1)[0]??Me;if(Fe=al("agent",ne.x+10,ne.y+19,de?"var(--accent)":"var(--ink)"),Fe+=`<text x="${ne.x+30}" y="${ne.y+30}" class="al-name${ge}">${S(qe)}</text>`,Be.length>0){const ze=Math.min(ne.w-20,12+Be.length*5.6);Fe+=`<rect x="${ne.x+10}" y="${ne.y+36}" width="${ze.toFixed(1)}" height="13" rx="3" fill="var(--paper)" stroke="var(--rule-solid)" stroke-width="1"/><text x="${(ne.x+10+ze/2).toFixed(1)}" y="${ne.y+45.5}" text-anchor="middle" class="al-chip">${S(Be)}</text>`}}else Be.length>0?Fe=`<text x="${Z}" y="${q-1+Ce}" class="fc-label t-name${ge}">${S(fe[0]??Me)}</text><text x="${Z}" y="${q+12+Ce}" class="fc-sub t-sub" text-anchor="middle">${S(Be)}</text>`:Fe=fe.map((qe,ze)=>`<text x="${Z}" y="${q+4.5+Ce-(fe.length-1)*7.5+ze*15}" class="fc-label t-name${ge}">${S(qe)}</text>`).join("");U+=`<g${_(`nodes.${re}`)}${Mo(V.col,V.row,V.w??1)}${hn(H(V.id))}>${je}${Fe}</g>`}),U+="</g>";const{overlay:R,legend:z}=Ws(B,r.map(V=>T(V)),{skin:!0});U+=R,U+="</svg>";const Y=[];return K.has("start")&&Y.push({swatch:"node-fill2",label:"start"}),K.has("process")&&Y.push({swatch:"node",label:"step"}),K.has("decision")&&Y.push({swatch:"node",label:"decision (diamond)"}),K.has("agent")&&Y.push({swatch:"node",label:"AGENT · autonomous step"}),K.has("llm")&&Y.push({swatch:"node",label:"LLM · model call"}),K.has("tool")&&Y.push({swatch:"node",label:"TOOL · retrieval / API / code"}),K.has("human")&&Y.push({swatch:"node-dashed",label:"HUMAN · review gate"}),K.has("memory")&&Y.push({swatch:"node-fill2",label:"MEMORY · store"}),K.has("end")&&[...C].length<r.filter(V=>V.kind==="end").length&&Y.push({swatch:"node",label:"exit"}),X.plain&&Y.push({swatch:"edge",label:"next"}),X.dashed&&Y.push({swatch:"edge-dashed",label:"optional"}),X.error&&Y.push({swatch:"edge-error",label:"error path"}),C.size>0&&Y.push({swatch:"node-accent",label:"happy path"}),{svg:U+z,legend:ot(Y)}}function p9(e,t){const{svg:n,legend:s}=u9(e);return ct({tag:t,...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...s.length>0?{legendHtml:s}:{}},n)}function f9(e){return p9(e,e.variant==="dag"?"DAG":"FLOW")}var l$=/\b(error|fail|failed|failure|reject|rejected|cancel|cancelled|canceled|abort|aborted|timeout|timed out|expired|dead)\b/i;function eA(e){return lt(e.name??"",23,3)}function Aa(e,t,n,s,o,r,i){const l=r+(e.col-1)*(t+s)+t/2,d=i+(e.row-1)*(n+o)+n/2;if(e.kind==="start"||e.kind==="terminal")return{x:l-13,y:d-13,w:26,h:26,cx:l,cy:d};const u=eA(e),p=Math.max(0,...u.map(g=>g.length)),h=Math.max(96,Math.min(p*8+26,t+s-26)),m=46+(Math.max(1,u.length)-1)*15;return{x:l-h/2,y:d-m/2,w:h,h:m,cx:l,cy:d}}function c$(e){return e==="terminal"?"pill pill-end":e==="wait"?"pill pill-wait":e==="start"?"pill pill-init":"pill pill-active"}function h9(e){const t=e.transitions??[],n=e.states??[],s=!(n.length>0&&n.every(Y=>Y.col!==void 0&&Y.row!==void 0)),o=nr(n,t,e.dir??"LR"),r=168,i=64,l=74,d=60,u=e.groups??[],p=Yi(u),h=(u.length>0?Gn.padX:30)+p.padX,m=(u.length>0?Gn.padTop:30)+p.padTop,g=(u.length>0?Gn.padBot:20)+p.padBot,v=wd(u),y=Math.max(1,...o.map(Y=>Y.col),v.cols),b=Math.max(1,...o.map(Y=>Y.row),v.rows),E=h*2+y*r+(y-1)*l,$=m*2+b*i+(b-1)*d+g,A=new Map(o.map(Y=>[Y.id,Y])),T=Y=>Y!==void 0&&Y.kind==="terminal"&&(l$.test(Y.name??"")||l$.test(Y.id)),N=o.filter(Y=>Y.kind==="terminal"&&!T(Y)),j=N.length===1?N[0]?.id:void 0,P=tr({quick:s,cols:y,rows:b,cellW:r,cellH:i,gapX:l,gapY:d,padX:h,padTop:m}),I=Sn("State machine",e.title,[wt(o.length,"state"),wt(t.length,"transition")]);let O=`<svg viewBox="0 0 ${E} ${$}"${I.attrs}${P}>${I.title}`;u.length>0&&(O+=xl(u,{xOf:re=>h+(re-1)*(r+l),yOf:re=>m+(re-1)*(i+d),cellW:r,cellH:i,gapX:l,gapY:d,skin:!0}));const C=t.length>=4,D=[],F={plain:!1,error:!1,accent:!1},U=qs(t),X=o.map(Y=>{const V=Aa(Y,r,i,l,d,h,m);return{x:V.x,y:V.y,w:V.w,h:V.h}}),B=Hs(t,Y=>{const V=A.get(Y);return V!==void 0?Aa(V,r,i,l,d,h,m):void 0});t.forEach((Y,V)=>{const re=A.get(Y.from),Q=A.get(Y.to);if(!re||!Q)return;const ne=Y.event+(Y.guard!==void 0?` ${Y.guard}`:""),Z=T(Q),q=!Z&&j!==void 0&&Y.to===j,de=Z?"var(--negative)":q?"var(--accent)":"var(--muted)",le=Z?"skErr":q?"skAccent":"skArrow",J=q?1.75:1.5,ue=Z?"error":q?"accent":"muted";Z?F.error=!0:q?F.accent=!0:F.plain=!0;const ve=_(`transitions.${V}`)+hn(V);if(Y.from===Y.to){const je=Aa(re,r,i,l,d,h,m);O+=`<path d="M ${je.cx-12} ${je.y} C ${je.cx-30} ${je.y-32}, ${je.cx+30} ${je.y-32}, ${je.cx+12} ${je.y}" fill="none" stroke="${de}" stroke-width="${J}" marker-end="url(#${le})"${ve}/>`;const De={lx:je.cx,ly:je.y-28},Me=C?xf(De,V+1,Z,!0):x0(De,ne,ue);D.push(`<g${ve}>${Me}</g>`);return}const we=Fs(Aa(re,r,i,l,d,h,m),Aa(Q,r,i,l,d,h,m),U[V]??0,B[V]??0);O+=`<path d="${we.d}" fill="none" stroke="${de}" stroke-width="${J}" marker-end="url(#${le})"${ve}/>`;const $e=C?xf(Uy(we.lx,we.ly,X),V+1,Z,!0):x0(we,ne,ue);D.push(`<g${ve}>${$e}</g>`)});const te={active:!1,wait:!1,start:!1,end:!1,errEnd:!1};O+=`<g${he("states")}>`,o.forEach((Y,V)=>{const re=Aa(Y,r,i,l,d,h,m),Q=Mo(Y.col,Y.row);if(Y.kind==="start")te.start=!0,O+=`<circle cx="${re.cx}" cy="${re.cy}" r="10" fill="var(--ink)"${_(`states.${V}`)}${Q}/>`;else if(Y.kind==="terminal"){const ne=Y.id===j,Z=T(Y);Z?te.errEnd=!0:ne||(te.end=!0);const q=ne?"var(--accent)":Z?"var(--negative)":"var(--ink)",de=ne?"var(--accent-tint)":Z?"var(--negative-tint)":"var(--paper)";O+=`<g${_(`states.${V}`)}${Q}><circle cx="${re.cx}" cy="${re.cy}" r="12" fill="${de}" stroke="${q}" stroke-width="1.5"/><circle cx="${re.cx}" cy="${re.cy}" r="6" fill="${q}"/></g>`}else{const ne=Y.kind==="wait";ne?te.wait=!0:te.active=!0;const Z=ne?"var(--paper-2)":"var(--paper)",q=ne?"var(--rule-solid)":"var(--ink)",de=ne?1:1.5,le=eA(Y),J=le.length<=1?`<text x="${re.cx}" y="${re.cy+4.5}" class="t-name" text-anchor="middle"${_(`states.${V}.name`)}>${S(Y.name??"")}</text>`:`<g${_(`states.${V}.name`)}>`+le.map((ue,ve)=>`<text x="${re.cx}" y="${re.cy+4.5-(le.length-1)*7.5+ve*15}" class="t-name" text-anchor="middle">${S(ue)}</text>`).join("")+"</g>";O+=`<g${_(`states.${V}`)}${Q}><rect x="${re.x}" y="${re.y}" width="${re.w}" height="${re.h}" rx="23" fill="${Z}" stroke="${q}" stroke-width="${de}"/>`+J+"</g>"}}),O+="</g>",O+=D.join(""),O+="</svg>";const ee=Y=>A.get(Y)?.name??Y,H=Y=>C?`<td class="t-num"><span class="edge-step"><b>${Y+1}</b></span></td>`:"",W=t.map((Y,V)=>`<tr${_(`transitions.${V}`)}${hn(V)}>`+H(V)+`<td><span class="${c$(A.get(Y.from)?.kind)}">${S(ee(Y.from))}</span></td><td style="font-family:var(--font-mono);font-size:11px"${_(`transitions.${V}.event`)}>${S(Y.event)}</td><td class="c-soft" style="font-size:11px"${_(`transitions.${V}.guard`)}>${S(Y.guard??"—")}</td><td><span class="${c$(A.get(Y.to)?.kind)}">${S(ee(Y.to))}</span></td></tr>`).join(""),K=t.length>0?`<table class="transition-table"><thead><tr>${C?"<th>№</th>":""}<th>From</th><th>Event</th><th>Guard</th><th>To</th></tr></thead><tbody${he("transitions")}>${W}</tbody></table>`:"",R=[];te.start&&R.push({swatch:"chip",chip:"●",label:"start"}),te.active&&R.push({swatch:"node",label:"state"}),te.wait&&R.push({swatch:"node-fill2",label:"waiting"}),te.end&&R.push({swatch:"chip",chip:"◉",label:"end"}),F.plain&&R.push({swatch:"edge",label:"transition"}),te.errEnd&&R.push({swatch:"node-negative",label:"error exit"}),F.error&&R.push({swatch:"edge-error",label:"error transition"}),j!==void 0&&R.push({swatch:"node-accent",label:"success exit"});const z=ot(R);return ct({tag:"STATE",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...z.length>0?{legendHtml:z}:{},...K.length>0?{footerHtml:K}:{}},O)}function tA(e){const t=(e??"process").toLowerCase();return t==="external"?"external":t==="store"||t==="datastore"?"store":"process"}function nA(e,t){const n=Vo(e==="process"?void 0:e),s=t?"var(--accent)":n.primary?"var(--ink)":"var(--rule-solid)",o=t||n.primary?1.5:1,r=t?"var(--accent-tint)":n.fill==="paper-2"?"var(--paper-2)":"var(--paper)",i=n.dashed?' stroke-dasharray="4 3"':"",l=t?" c-accent":n.fill==="paper-2"?" c-muted":"";return{skin:n,stroke:s,sw:o,fill:r,dash:i,chipTone:l}}function sA(e,t,n){return e==="process"?`<rect x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" rx="16" fill="${n.fill}" stroke="${n.stroke}" stroke-width="${n.sw}"/>`:e==="store"?`<rect x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" fill="${n.fill}" stroke="none"/><path d="M${t.x+t.w} ${t.y} H ${t.x} V ${t.y+t.h} H ${t.x+t.w}" fill="none" stroke="${n.stroke}" stroke-width="${n.sw}"/>`:`<rect x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" fill="${n.fill}" stroke="${n.stroke}" stroke-width="${n.sw}"${n.dash}/>`}function oA(e,t){return t.skin.chip!==""?`<text x="${e.x+e.w-10}" y="${e.y+14}" class="t-eyebrow${t.chipTone}" text-anchor="end">${S(t.skin.chip)}</text>`:""}function rA(e,t,n,s,o){const r=n.x+n.w/2,i=n.y+n.h/2,l=s?" c-accent":"";return e.length<=1?`<text x="${r}" y="${i+4}" class="t-name${l}" text-anchor="middle"${_(o)}>${S(t)}</text>`:`<g${_(o)}>`+e.map((d,u)=>`<text x="${r}" y="${i+4-(e.length-1)*7+u*14}" class="t-name${l}" text-anchor="middle">${S(d)}</text>`).join("")+"</g>"}var d$=tA;function m9(e){const t=e.edges??[],n=e.nodes??[],s=!(n.length>0&&n.every(z=>z.col!==void 0&&z.row!==void 0)),o=nr(n,t,e.dir??"LR"),r=148,i=o.map(z=>lt(z.name,20,3)),d=66+(Math.max(1,...i.map(z=>z.length))-1)*14,u=104,p=54,h=e.groups??[],m=Yi(h),g=(h.length>0?Gn.padX:26)+m.padX,v=(h.length>0?Gn.padTop:26)+m.padTop,y=(h.length>0?Gn.padBot:20)+m.padBot,b=wd(h),E=Math.max(1,...o.map(z=>z.col),b.cols),$=Math.max(1,...o.map(z=>z.row),b.rows),A=z=>g+(z-1)*(r+u),T=z=>v+(z-1)*(d+p),N=z=>({x:A(z.col),y:T(z.row),w:r,h:d}),j=new Map(o.map(z=>[z.id,z])),P=g*2+E*r+(E-1)*u,I=v+$*d+($-1)*p+y,O=o.filter(z=>d$(z.kind)==="external"),C=O.length===1?O[0]?.id:void 0,D=tr({quick:s,cols:E,rows:$,cellW:r,cellH:d,gapX:u,gapY:p,padX:g,padTop:v}),F=Sn("Data-flow diagram",e.title,[wt(o.length,"node"),wt(t.length,"flow")]);let U=`<svg viewBox="0 0 ${P} ${I}"${F.attrs}${D}>${F.title}`;h.length>0&&(U+=xl(h,{xOf:A,yOf:T,cellW:r,cellH:d,gapX:u,gapY:p,skin:!0}));const X=[],B=qs(t),te=Hs(t,z=>{const Y=j.get(z);return Y!==void 0?N(Y):void 0});U+=`<g${he("edges")}>`,t.forEach((z,Y)=>{const V=j.get(z.from),re=j.get(z.to);if(!V||!re)return;const Q=Fs(N(V),N(re),B[Y]??0,te[Y]??0);U+=`<path d="${Q.d}" fill="none" stroke="var(--muted)" stroke-width="1.5" marker-end="url(#skArrow)"${_(`edges.${Y}`)}/>`,X.push({lx:Q.lx,ly:Q.ly,...z.label!==void 0?{label:z.label}:{},path:`edges.${Y}`})}),U+="</g>";const ee=new Set;U+=`<g${he("nodes")}>`,o.forEach((z,Y)=>{const V=N(z),re=d$(z.kind);ee.add(re);const Q=z.id===C,ne=nA(re,Q),Z=sA(re,V,ne),q=oA(V,ne),de=z.num!==void 0&&re==="process"?`<text x="${V.x+12}" y="${V.y+16}" class="t-badge"${_(`nodes.${Y}.num`)}>${S(z.num)}</text>`:"",le=rA(i[Y]??[],z.name,V,Q,`nodes.${Y}.name`);U+=`<g${_(`nodes.${Y}`)}${Mo(z.col,z.row)}>${Z}${q}${de}${le}</g>`}),U+="</g>";const{overlay:H,legend:W}=Ws(X,o.map(z=>N(z)),{skin:!0});U+=H,U+="</svg>";const K=[];ee.has("process")&&K.push({swatch:"node",label:"process"}),ee.has("external")&&C===void 0&&K.push({swatch:"node-dashed",label:"external entity"}),ee.has("store")&&K.push({swatch:"node-store",label:"data store"}),t.length>0&&K.push({swatch:"edge",label:"data flow"}),C!==void 0&&K.push({swatch:"node-accent",label:"external entity"});const R=ot(K);return ct({tag:"DFD",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...R.length>0?{legendHtml:R}:{}},U+W)}function g9(e){return e<0?0:e>1?1:e}function v9(e){return e>=.6?"high":e<=.35?"low":"mid"}var y9={high:`fill="var(--ink)" stroke="var(--paper)" stroke-width="1.5"${ut}`,mid:'fill="var(--paper)" stroke="var(--ink)" stroke-width="1.5"',low:`fill="var(--negative)" stroke="var(--paper)" stroke-width="1.5"${ut}`},x9={high:{swatch:"fill",fill:"var(--ink)",label:"positive"},mid:{swatch:"node",label:"neutral"},low:{swatch:"fill",fill:"var(--negative)",label:"negative"}};function k9(e){const t=e.stages??[],n=e.rows??[],s=e.emotion??[],o=Math.max(t.length,1),r=Math.max(380,o*150),i=92,l=20,d=(r-l*2)/o,u=v=>l+d*(v+.5),p=v=>i-14-(i-30)*g9(v),h=`<tr${he("stages")}><th></th>`+t.map((v,y)=>`<th class="c"${_(`stages.${y}`)}>${S(v.label)}</th>`).join("")+"</tr>",m=n.map((v,y)=>`<tr${_(`rows.${y}`)}><td class="lead"${_(`rows.${y}.label`)}>${S(v.label)}</td>`+(v.cells??[]).map((b,E)=>`<td class="c"${_(`rows.${y}.cells.${E}`)}>${S(b)}</td>`).join("")+"</tr>").join("");let g="";if(s.length>0){const v=new Set,y=s.map(($,A)=>`${u(A)},${p($)}`).join(" "),b=s.map(($,A)=>{const T=v9($);return v.add(T),`<circle cx="${u(A)}" cy="${p($)}" r="5" ${y9[T]}${_(`emotion.${A}`)}/>`}).join(""),E=ot(["high","mid","low"].filter($=>v.has($)).map($=>x9[$]));g=`<div class="jr-emotion"><div class="jr-emotion-label t-eyebrow">Emotion</div><svg viewBox="0 0 ${r} ${i}" style="width:100%" role="img"><title>Emotion curve</title><polyline points="${y}" fill="none" stroke="var(--ink)" stroke-width="1.5" stroke-linejoin="round"/><g${he("emotion")}>${b}</g></svg>${E}</div>`}return`<div><table class="pres-table"><thead>${h}</thead><tbody${he("rows")}>${m}</tbody></table>`+g+"</div>"}function b9(e){switch((e??"").toLowerCase()){case"done":return"done";case"active":case"current":return"active";case"milestone":return"milestone";default:return"planned"}}var w9={planned:'fill="var(--paper-2)" stroke="var(--ink)" stroke-width="1"',done:'fill="var(--ink)" stroke="var(--ink)" stroke-width="1"',active:'fill="var(--accent-tint)" stroke="var(--accent)" stroke-width="1.5"',milestone:'fill="var(--paper)" stroke="var(--ink)" stroke-width="1.25" stroke-dasharray="4 3"'},$9={planned:{swatch:"node-fill2",label:"planned"},done:{swatch:"fill",fill:"var(--ink)",label:"done"},active:{swatch:"node-accent",label:"in progress"},milestone:{swatch:"node-dashed",label:"milestone"}};function S9(e,t,n,s){const o=e.length>s?`${e.slice(0,Math.max(1,s-1))}…`:e,r=o===e?"":`<title>${S(e)}</title>`;return`<text x="${t}" y="${n}" class="t-eyebrow" text-anchor="middle">${r}${S(o)}</text>`}function E9(e){const t=e.periods??[],n=e.tasks??[],s=Math.max(t.length,1),o=156,r=20,i=18,l=64,d=6.6,u=I=>I.length*d,p=t.some(I=>u(I)>l-6),h=Math.max(1,Math.floor(((p?l*2:l)-6)/d)),m=p?48:34,g=14,v=n.map(I=>lt(I.label,Math.floor((o-r)/7),3)),b=30+(Math.max(1,...v.map(I=>I.length))-1)*14,E=o+r*2+s*l,$=m+n.length*b+g,A=I=>o+r+I*l;let T=`<svg viewBox="0 0 ${E} ${$}" role="img"><title>Schedule</title>`;T+=`<g${he("periods")}>`;for(let I=0;I<t.length;I++)T+=`<g${_(`periods.${I}`)}><line x1="${A(I)}" y1="${m-6}" x2="${A(I)}" y2="${$-g}" stroke="var(--rule)" stroke-width="1"${ut}/>`+S9(t[I]??"",A(I)+l/2,m-12-(p&&I%2===0?14:0),h)+"</g>";T+="</g>",T+=`<line x1="${A(s)}" y1="${m-6}" x2="${A(s)}" y2="${$-g}" stroke="var(--rule)" stroke-width="1"${ut}/>`;const N=new Set;T+=`<g${he("tasks")}>`;for(let I=0;I<n.length;I++){const O=n[I];if(O===void 0)continue;const C=b9(O.kind);N.add(C);const D=m+I*b,F=A(O.start??0),X=Math.max(1,O.span??1)*l-8,B=v[I]??[],te=C==="active"?"t-name c-accent":"t-name",ee=B.length<=1?`<text x="${r}" y="${D+b/2+4.5}" class="${te}"${_(`tasks.${I}.label`)}>${S(O.label)}</text>`:`<g${_(`tasks.${I}.label`)}>`+B.map((H,W)=>`<text x="${r}" y="${D+b/2+4.5-(B.length-1)*7+W*14}" class="${te}">${S(H)}</text>`).join("")+"</g>";T+=`<g${_(`tasks.${I}`)}>`+ee+`<rect x="${F+4}" y="${D+(b-i)/2}" width="${X}" height="${i}" rx="2" ${w9[C]}/></g>`}T+="</g>",T+="</svg>";const j=["planned","done","active","milestone"].filter(I=>N.has(I)).map(I=>$9[I]),P=ot(j);return ct({tag:"GANTT",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...P.length>0?{legendHtml:P}:{}},T)}function M9(e){const t=e.edges??[],n=e.nodes??[],s=!(n.length>0&&n.every(R=>R.col!==void 0&&R.row!==void 0)),o=nr(n,t,"LR"),r=150,i=84,l=44,d=40,u=26,p=24,h=20,m=Math.max(1,...o.map(R=>R.col)),g=Math.max(1,...o.map(R=>R.row)),v=R=>u+(R-1)*(r+l)+r/2,y=R=>p+(R-1)*(i+d)+i/2,b=R=>{const z=v(R.col),Y=y(R.row),V=Math.max(98,Math.min(R.label.length*8+26,r+l-10));return{x:z-V/2,y:Y-20,w:V,h:40,cx:z,cy:Y}},E=new Map(o.map(R=>[R.id,R])),$=u*2+m*r+(m-1)*l,A=p+g*i+(g-1)*d+h,T=o.filter(R=>R.state==="target"),N=o.filter(R=>R.state==="current"),j=T.length===1?T[0]?.id:T.length===0&&N.length===1?N[0]?.id:void 0,P=o.some(R=>R.state!==void 0||R.group!==void 0),I=tr({quick:s,cols:m,rows:g,cellW:r,cellH:i,gapX:l,gapY:d,padX:u,padTop:p});let O=`<svg viewBox="0 0 ${$} ${A}" role="img"${I}><title>Graph</title>`;const C=[],D=qs(t),F=Hs(t,R=>{const z=E.get(R);return z!==void 0?b(z):void 0});let U=!1,X=!1;O+=`<g${he("edges")}>`,t.forEach((R,z)=>{const Y=E.get(R.from),V=E.get(R.to);if(!Y||!V)return;const re=Fs(b(Y),b(V),D[z]??0,F[z]??0),Q=(R.dir??"directed")!=="undirected";Q?U=!0:X=!0;const ne=Q?' marker-end="url(#skArrow)"':"";O+=`<path d="${re.d}" fill="none" stroke="var(--muted)" stroke-width="1.5"${ne}${_(`edges.${z}`)}/>`;const Z=R.weight!==void 0?R.label!==void 0&&R.label.length>0?`${R.label} · ${R.weight}`:String(R.weight):R.label;C.push({lx:re.lx,ly:re.ly,...Z!==void 0?{label:Z}:{},path:`edges.${z}`})}),O+="</g>";const B=new Set;let te=!1;O+=`<g${he("nodes")}>`,o.forEach((R,z)=>{const Y=b(R),V=R.id===j,re=R.state;re!==void 0&&B.add(re);const Q=re==="visited",ne=V?"var(--accent)":Q?"var(--rule-solid)":"var(--ink)",Z=V?"var(--accent-tint)":Q?"var(--paper-2)":"var(--paper)",q=V?1.5:Q?1:1.5,de=re==="frontier"?' stroke-dasharray="4 3"':"",le=V?" c-accent":Q?" c-muted":"",J=re!==void 0?`<text x="${Y.x+14}" y="${Y.y+11}" class="t-eyebrow${le}">${re.toUpperCase()}</text>`:"";let ue="";R.group!==void 0&&(te=!0,ue=`<text x="${Y.x+Y.w-14}" y="${Y.y+11}" class="t-eyebrow${le}" text-anchor="end">G${R.group}</text>`);const ve=Y.cy+4+(P?3:0);O+=`<g${_(`nodes.${z}`)}${Mo(R.col,R.row)}><rect x="${Y.x}" y="${Y.y}" width="${Y.w}" height="${Y.h}" rx="20" fill="${Z}" stroke="${ne}" stroke-width="${q}"${de}/>`+J+ue+`<text x="${Y.cx}" y="${ve}" class="t-name${V?" c-accent":""}" text-anchor="middle">${S(R.label.length>21?`${R.label.slice(0,20)}…`:R.label)}</text></g>`}),O+="</g>";const{overlay:ee,legend:H}=Ws(C,o.map(R=>b(R)),{skin:!0});O+=ee,O+="</svg>";const W=[];o.some(R=>R.state===void 0)&&W.push({swatch:"node",label:"node"}),B.has("visited")&&W.push({swatch:"node-fill2",label:"visited"}),B.has("frontier")&&W.push({swatch:"node-dashed",label:"frontier"}),B.has("current")&&W.push({swatch:"chip",chip:"CURRENT",label:"current"}),B.has("target")&&W.push({swatch:"chip",chip:"TARGET",label:"target"}),te&&W.push({swatch:"chip",chip:"G1",label:"group"}),U&&W.push({swatch:"edge",label:"edge"}),X&&W.push({swatch:"edge",label:"undirected (no head)"}),j!==void 0&&W.push({swatch:"node-accent",label:T.length===1?"target":"current"});const K=ot(W);return ct({tag:"GRAPH",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...K.length>0?{legendHtml:K}:{}},O+H)}function u$(e){return e===void 0||Number.isNaN(e)?.5:e<0?0:e>1?1:e}function A9(e){const s=e.yAxis??{},o=Math.max(56,18+Math.ceil(Math.max(0,...[s.high,s.low].map($=>($??"").length*6.2)))),r=580+(o-56),i=o,l=r-56,d=40,u=384,p=(i+l)/2,h=(d+u)/2,m=$=>i+(l-i)*u$($),g=$=>u-(u-d)*u$($),v=e.items??[],y=e.xAxis??{},b=e.yAxis??{};let E=`<svg viewBox="0 0 ${r} 440" role="img"><title>Quadrant</title>`;return E+=`<rect x="${i}" y="${d}" width="${l-i}" height="${u-d}" fill="var(--paper)" stroke="var(--rule-solid)" stroke-width="1"/>`,E+=`<rect x="${p}" y="${d}" width="${l-p}" height="${h-d}" fill="var(--paper-2)"/>`,E+=`<line x1="${i}" y1="${h}" x2="${l}" y2="${h}" stroke="var(--muted)" stroke-width="1.25" marker-end="url(#skArrow)"/>`,E+=`<line x1="${p}" y1="${u}" x2="${p}" y2="${d}" stroke="var(--muted)" stroke-width="1.25" marker-end="url(#skArrow)"/>`,y.label!==void 0&&(E+=`<text x="${l}" y="${u+30}" class="t-eyebrow" text-anchor="end"${_("xAxis.label")}>${S(y.label)} →</text>`),b.label!==void 0&&(E+=`<text x="${p-8}" y="${d-4}" class="t-eyebrow" text-anchor="end"${_("yAxis.label")}>↑ ${S(b.label)}</text>`),y.low!==void 0&&(E+=`<text x="${i}" y="${u+16}" class="t-sub c-soft" text-anchor="start"${_("xAxis.low")}>${S(y.low)}</text>`),y.high!==void 0&&(E+=`<text x="${l}" y="${u+16}" class="t-sub c-soft" text-anchor="end"${_("xAxis.high")}>${S(y.high)}</text>`),b.high!==void 0&&(E+=`<text x="${i-10}" y="${d+6}" class="t-sub c-soft" text-anchor="end"${_("yAxis.high")}>${S(b.high)}</text>`),b.low!==void 0&&(E+=`<text x="${i-10}" y="${u}" class="t-sub c-soft" text-anchor="end"${_("yAxis.low")}>${S(b.low)}</text>`),E+=`<g${he("items")}>`,v.forEach(($,A)=>{const T=m($.x),N=g($.y),j=T>p,P=T+(j?-12:12),I=j?"end":"start";E+=`<g${_(`items.${A}`)}><circle cx="${T}" cy="${N}" r="5.5" fill="var(--ink)" stroke="var(--paper)" stroke-width="1.5"${ut}/><text x="${P}" y="${N+4.5}" class="t-name" text-anchor="${I}"${_(`items.${A}.label`)}>${S($.label)}</text></g>`}),E+="</g>",E+="</svg>",ct({tag:"2×2",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{}},E)}var C9={action:"",decision:"DECISION",start:"",end:"",wait:"WAIT"};function N9(e){const t=e.lanes??[],n=e.steps??[],s=e.links??[],o=e.phases??[],{placements:r,derived:i}=oR(e),l=132,d=18,u=20,p=168,h=34,m=150,g=o.length>0?26:0,v=24+g,y=n.map(re=>lt(re.label,18,3)),b=Math.max(1,...y.map(re=>re.length)),$=n.some(re=>re.note!==void 0&&re.note!=="")?12:0,A=52+Math.max(0,b-2)*14+$,T=92+Math.max(0,b-2)*14+$,N=Math.max(1,...r.map(re=>re.col),...o.map(re=>re.to??re.from)),j=re=>l+d+(re-1)*(p+h),P=re=>v+re*T,I=re=>({x:j(re.col)+(p-m)/2,y:P(re.lane)+(T-A)/2,w:m,h:A}),O=new Map;n.forEach((re,Q)=>{const ne=r[Q];ne!==void 0&&!O.has(re.id)&&O.set(re.id,ne)});const C=l+d*2+N*p+(N-1)*h,D=Math.max(1,t.length)*T,F=v+D+u,U=tr({quick:i,cols:N,rows:Math.max(1,t.length),cellW:p,cellH:T,gapX:h,gapY:0,padX:l+d,padTop:v});let X=`<svg viewBox="0 0 ${C} ${F}" role="img"${U}><title>Swimlane</title>`;X+=`<g${he("lanes")}>`;for(let re=0;re<t.length;re++){const Q=t[re];if(Q===void 0)continue;const ne=lt(Q.label,Math.max(8,Math.floor((l-28)/7)),3),Z=ne.map((q,de)=>`<text x="${d+14}" y="${(P(re)+T/2+4-(ne.length-1)*8+de*16).toFixed(1)}" class="t-name">${S(q)}</text>`).join("");X+=`<g${_(`lanes.${re}`)}><rect x="${d}" y="${P(re)}" width="${C-d*2}" height="${T}" fill="var(--paper)" stroke="var(--rule-solid)" stroke-width="1"/><rect x="${d}" y="${P(re)}" width="${l}" height="${T}" fill="var(--paper-2)" stroke="var(--rule-solid)" stroke-width="1"/>`+Z+"</g>"}if(X+="</g>",o.length>0){const re=v-g,Q=v+D;X+=`<g${he("phases")}>`,o.forEach((ne,Z)=>{const q=Math.min(ne.from,N),de=Math.min(Math.max(ne.to??N,q),N),le=q===1?d+l:j(q)-h/2,J=de===N?C-d:j(de)+p+h/2,ue=(q>1?`<line x1="${le}" y1="${re}" x2="${le}" y2="${Q}" stroke="var(--rule-solid)" stroke-width="1" stroke-dasharray="4 3"/>`:"")+(de<N?`<line x1="${J}" y1="${re}" x2="${J}" y2="${Q}" stroke="var(--rule-solid)" stroke-width="1" stroke-dasharray="4 3"/>`:""),ve=lt(ne.label,Math.max(6,Math.floor((J-le-16)/7)),1)[0]??"";X+=`<g${_(`phases.${Z}`)}><rect x="${le}" y="${re}" width="${J-le}" height="${g}" fill="var(--paper-2)" stroke="var(--rule-solid)" stroke-width="1"/><text x="${(le+J)/2}" y="${re+g/2+3}" class="t-eyebrow" text-anchor="middle">${S(ve.toUpperCase())}</text>`+ue+"</g>"}),X+="</g>"}const B=[],te=qs(s),ee=Hs(s,re=>{const Q=O.get(re);return Q!==void 0?I(Q):void 0}),H={plain:!1,dashed:!1,error:!1};X+=`<g${he("links")}>`,s.forEach((re,Q)=>{const ne=O.get(re.from),Z=O.get(re.to);if(!ne||!Z)return;const q=Fs(I(ne),I(Z),te[Q]??0,ee[Q]??0),de=re.kind==="error",le=re.kind==="dashed",J=de?"var(--negative)":"var(--muted)",ue=de?"skErr":le?"skOpen":"skArrow",ve=le?' stroke-dasharray="5 4"':"";de?H.error=!0:le?H.dashed=!0:H.plain=!0,X+=`<path d="${q.d}" fill="none" stroke="${J}" stroke-width="1.5"${ve} marker-end="url(#${ue})"${_(`links.${Q}`)}/>`,B.push({lx:q.lx,ly:q.ly,...re.label!==void 0?{label:re.label}:{},path:`links.${Q}`,...de?{err:!0}:{}})}),X+="</g>";const W=new Set;let K=!1;X+=`<g${he("steps")}>`,n.forEach((re,Q)=>{const ne=r[Q]??{col:1,lane:0},Z=I(ne),q=re.kind??"action";W.add(q);const de=re.accent===!0;de&&(K=!0);const le=!de&&(q==="start"||q==="wait"),J=de?"var(--accent-tint)":le?"var(--paper-2)":"var(--paper)",ue=de?"var(--accent)":le?"var(--rule-solid)":"var(--ink)",ve=le?1:1.5,we=q==="start"||q==="end"?Z.h/2:4,$e=C9[q],je=$e!==""?`<text x="${Z.x+10}" y="${Z.y+12}" class="t-eyebrow${de?" c-accent":le?" c-muted":""}">${$e}</text>`:"",De=re.note!==void 0&&re.note!==""?re.note:void 0,Me=($e!==""?5:0)-(De!==void 0?6:0),Be=y[Q]??[],Ge=Be.map((ge,Ce)=>`<text x="${Z.x+Z.w/2}" y="${Z.y+Z.h/2+4+Me-(Be.length-1)*7+Ce*14}" class="t-name" text-anchor="middle">${S(ge)}</text>`).join(""),fe=De!==void 0?`<text x="${Z.x+Z.w/2}" y="${Z.y+Z.h-9}" class="t-sub" text-anchor="middle">${S(lt(De,24,1)[0]??"")}</text>`:"";X+=`<g${_(`steps.${Q}`)}${Mo(ne.col,ne.lane+1)}><rect x="${Z.x}" y="${Z.y}" width="${Z.w}" height="${Z.h}" rx="${we}" fill="${J}" stroke="${ue}" stroke-width="${ve}"/>`+je+Ge+fe+"</g>"}),X+="</g>";const{overlay:R,legend:z}=Ws(B,r.map(re=>I(re)),{skin:!0});X+=R,X+="</svg>";const Y=[];W.has("start")&&Y.push({swatch:"node-stadium-fill2",label:"start"}),W.has("action")&&Y.push({swatch:"node",label:"step"}),W.has("decision")&&Y.push({swatch:"chip",chip:"DECISION",label:"decision"}),W.has("wait")&&Y.push({swatch:"chip",chip:"WAIT",label:"waiting"}),W.has("end")&&Y.push({swatch:"node-stadium",label:"end"}),K&&Y.push({swatch:"node-accent",label:"focal step"}),H.plain&&Y.push({swatch:"edge",label:"next"}),H.dashed&&Y.push({swatch:"edge-dashed",label:"message"}),H.error&&Y.push({swatch:"edge-error",label:"error path"});const V=ot(Y);return ct({tag:"LANES",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...V.length>0?{legendHtml:V}:{}},X+z)}var T9={PERSON:"person",SYSTEM:"software system",EXT:"external system",DB:"database",CONTAINER:"container",COMPONENT:"component"};function _9(e){const t=(e.family??"").toLowerCase();switch(e.kind){case"person":return{chip:"PERSON",primary:!0,fill:"paper",dashed:!1};case"system":return{chip:"SYSTEM",primary:!0,fill:"paper",dashed:!1};case"external":return Vo("external");case"store":return Vo("store");case"container":case"component":{const n=e.kind==="container"?"CONTAINER":"COMPONENT";return t==="external"?{chip:n,primary:!0,fill:"paper",dashed:!0}:t==="store"||t==="data"?{chip:n,primary:!1,fill:"paper-2",dashed:!1}:{chip:n,primary:!0,fill:"paper",dashed:!1}}default:return Vo(e.kind)}}function p$(e,t){return t.join(" ").split(/\s+/).filter(Boolean).length<e.trim().split(/\s+/).filter(Boolean).length}function L9(e){if(e===void 0||e.trim()==="")return;let t=lt(e,32,3);if(!p$(e,t))return{lines:t,small:!1,clipped:!1};if(t=lt(e,36,3),!p$(e,t))return{lines:t,small:!0,clipped:!1};const n=t[t.length-1];return n!==void 0&&(t[t.length-1]=`${n.replace(/[.,;:]?$/,"")}…`),{lines:t,small:!0,clipped:!0}}function I9(e){return e==="component"?"CONTAINER":e==="container"?"SYSTEM":"BOUNDARY"}function j9(e){const t=e.edges??[],n=e.nodes??[],s=!(n.length>0&&n.every(q=>q.col!==void 0&&q.row!==void 0)),o=nr(n,t,e.dir??"LR"),r=new Map(o.map(q=>[q.id,q])),i=212,l=o.map(q=>L9(q.desc)),d=o.map((q,de)=>{const J=l[de]?.lines.length??0,ue=q.kind==="store"?86:76,ve=q.kind==="store"?16:8;return J>0?ue+(J-1)*13+ve:0}),u=Math.max(112,...d),p=56,h=64,m=e.groups??[],g=Yi(m),v=(m.length>0?Gn.padX:26)+g.padX,y=(m.length>0?Gn.padTop:46)+g.padTop,b=(m.length>0?Gn.padBot:24)+g.padBot,E=wd(m),$=Math.max(1,...o.map(q=>q.col+((q.w??1)-1)),E.cols),A=Math.max(1,...o.map(q=>q.row),E.rows),T=q=>({x:v+(q.col-1)*(i+p),y:y+(q.row-1)*(u+h),w:(q.w??1)*i+((q.w??1)-1)*p,h:u}),N=v*2+$*i+($-1)*p,j=y+A*u+(A-1)*h+b,P=e.level===void 0||e.level==="context",I=o.filter(q=>q.kind==="system"),O=P&&I.length===1?I[0]?.id:void 0,C=I9(e.level),D=(q,de,le)=>{if(q.length===0)return"";const J=Math.min(...q.map(Me=>Me.x))-16,ue=Math.min(...q.map(Me=>Me.y))-26,ve=Math.max(...q.map(Me=>Me.x+Me.w))+16,we=Math.max(...q.map(Me=>Me.y+Me.h))+16,$e=Fi(le,""),je=$e.length>0?$e:"var(--rule-solid)",De=$e.length>0?$e:"var(--soft)";return`<g><rect x="${J}" y="${ue}" width="${ve-J}" height="${we-ue}" rx="6" fill="var(--paper-2)" fill-opacity="0.6" stroke="${je}" stroke-width="1"/><text x="${J+12}" y="${ue+16}" class="t-eyebrow" fill="${De}">${S(de)}</text><text x="${ve-12}" y="${ue+16}" class="t-eyebrow" fill="${De}" text-anchor="end">${C}</text></g>`};let F="";if(e.boundary!==void 0){const q=o.filter(de=>de.kind==="container"||de.kind==="component"||de.kind==="store").map(T);F=D(q,e.boundary.label)}let U="";for(const q of e.boundaries??[]){const de=q.nodes.map(le=>r.get(le)).filter(le=>le!==void 0).map(T);U+=D(de,q.label,q.color)}const X=tr({quick:s,cols:$,rows:A,cellW:i,cellH:u,gapX:p,gapY:h,padX:v,padTop:y}),B=m.length>0?xl(m,{xOf:q=>v+(q-1)*(i+p),yOf:q=>y+(q-1)*(u+h),cellW:i,cellH:u,gapX:p,gapY:h,skin:!0}):"",te=Sn("C4 diagram",e.title,[wt(o.length,"element"),wt(t.length,"relationship")]);let ee=`<svg viewBox="0 0 ${N} ${j}"${te.attrs}${X}>${te.title}${B}${F}${U}`;const H=[],W=new Set,K=qs(t),R=Hs(t,q=>{const de=r.get(q);return de!==void 0?T(de):void 0});ee+=`<g${he("edges")}>`,t.forEach((q,de)=>{const le=r.get(q.from),J=r.get(q.to);if(!le||!J)return;const ue=Fs(T(le),T(J),K[de]??0,R[de]??0),ve=q.kind??"solid";W.add(ve);const we=Qo[ve]??Qo.solid??{stroke:"var(--muted)",sw:1.5,dash:"",marker:"skArrow",err:!1},$e=we.dash.length>0?` stroke-dasharray="${we.dash}"`:"";ee+=`<path d="${ue.d}" fill="none" stroke="${we.stroke}" stroke-width="${we.sw}"${$e} marker-end="url(#${we.marker})"${_(`edges.${de}`)}/>`;const je=q.tech!==void 0?`${q.label!==void 0?`${q.label} `:""}[${q.tech}]`:q.label;H.push({lx:ue.lx,ly:ue.ly,...je!==void 0?{label:je}:{},err:we.err,path:`edges.${de}`})}),ee+="</g>";const z=new Set;let Y=!1,V=!1;ee+=`<g${he("nodes")}>`,o.forEach((q,de)=>{const le=T(q),J=_9(q),ue=q.id===O;J.chip!==""&&z.add(J.chip),J.dashed&&(Y=!0),J.fill==="paper-2"&&(V=!0);const ve=le.x+le.w/2,we=ue?"var(--accent)":J.primary?"var(--ink)":"var(--rule-solid)",$e=ue||J.primary?1.5:1,je=ue?"var(--accent-tint)":J.fill==="paper-2"?"var(--paper-2)":"var(--paper)",De=J.dashed?' stroke-dasharray="4 3"':"",Me=q.kind==="store",Be=Me?10:0,Ge=l[de]??{lines:[],small:!1,clipped:!1},fe=Me?`<path d="M${le.x} ${le.y+12} A ${le.w/2} 12 0 0 1 ${le.x+le.w} ${le.y+12} V ${le.y+le.h-12} A ${le.w/2} 12 0 0 1 ${le.x} ${le.y+le.h-12} Z" fill="${je}" stroke="${we}" stroke-width="${$e}"${De}/><path d="M${le.x} ${le.y+12} A ${le.w/2} 12 0 0 0 ${le.x+le.w} ${le.y+12}" fill="none" stroke="${we}" stroke-width="${$e}"${De}/>`:`<rect x="${le.x}" y="${le.y}" width="${le.w}" height="${le.h}" rx="6" fill="${je}" stroke="${we}" stroke-width="${$e}"${De}/>`,ge=q.kind==="person"?al("person",le.x+le.w-28,le.y+10,"var(--muted)"):"",Ce=J.fill==="paper-2",Fe=ue?" c-accent":Ce?" c-muted":"",qe=Ce?" c-muted":" c-soft",ze=J.chip!==""?`<text x="${ve}" y="${le.y+18+Be}" class="t-eyebrow${Fe}" text-anchor="middle">${S(J.chip)}</text>`:"",Xe=q.tech!==void 0?`<text x="${ve}" y="${le.y+56+Be}" class="t-sub${Ce?" c-muted":""}" text-anchor="middle">${S(q.tech)}</text>`:"",pt=Ge.small?' style="font-size:9px"':"",kt=Ge.lines.map((Nt,Bt)=>`<text x="${ve}" y="${le.y+76+Be+Bt*13}" class="t-sub${qe}"${pt} text-anchor="middle">${S(Nt)}</text>`).join(""),St=Ge.clipped?`<title>${S(q.desc??"")}</title>`:"";ee+=`<g${_(`nodes.${de}`)}${Mo(q.col,q.row,q.w??1)}>`+St+fe+ge+ze+`<text x="${ve}" y="${le.y+40+Be}" class="t-name${ue?" c-accent":""}" text-anchor="middle">${S(q.name)}</text>`+Xe+kt+"</g>"}),ee+="</g>";const{overlay:re,legend:Q}=Ws(H,o.map(q=>T(q)),{skin:!0});ee+=re,ee+="</svg>";const ne=[];for(const q of z)ne.push({swatch:"chip",chip:q,label:T9[q]??q.toLowerCase()});Y&&ne.push({swatch:"node-dashed",label:"outside the boundary"}),V&&ne.push({swatch:"node-fill2",label:"data store"}),W.has("solid")&&ne.push({swatch:"edge",label:"uses"}),W.has("dashed")&&ne.push({swatch:"edge-dashed",label:"async / optional"}),W.has("forbidden")&&ne.push({swatch:"edge-error",label:"forbidden"}),W.has("error")&&ne.push({swatch:"edge-error",label:"error"}),O!==void 0&&ne.push({swatch:"node-accent",label:"the system in scope"});const Z=ot(ne);return ct({tag:e.level!==void 0?`C4 · ${e.level.toUpperCase()}`:"C4",tagClass:"c4",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...Z.length>0?{legendHtml:Z}:{}},ee+Q)}function P9(e,t=7){const n=i=>Math.round(i*10)/10,s=e[0];if(s===void 0)return"";let o=`M${n(s.x)},${n(s.y)}`;for(let i=1;i<e.length-1;i++){const l=e[i],d=e[i-1],u=e[i+1];if(l===void 0||d===void 0||u===void 0)continue;const p=Math.hypot(l.x-d.x,l.y-d.y)||1,h=Math.hypot(u.x-l.x,u.y-l.y)||1,m=Math.min(t,p/2),g=Math.min(t,h/2),v={x:l.x+(d.x-l.x)/p*m,y:l.y+(d.y-l.y)/p*m},y={x:l.x+(u.x-l.x)/h*g,y:l.y+(u.y-l.y)/h*g};o+=` L${n(v.x)},${n(v.y)} Q${n(l.x)},${n(l.y)} ${n(y.x)},${n(y.y)}`}const r=e[e.length-1];return r!==void 0&&(o+=` L${n(r.x)},${n(r.y)}`),o}function O9(e){switch((e??"association").toLowerCase()){case"inheritance":case"extends":return{kind:"inheritance",dash:"",end:"umlTri"};case"implementation":case"implements":return{kind:"implementation",dash:"5 4",end:"umlTri"};case"composition":return{kind:"composition",dash:"",start:"umlDiaF"};case"aggregation":return{kind:"aggregation",dash:"",start:"umlDiaH"};case"dependency":return{kind:"dependency",dash:"5 4",end:"umlOpen"};default:return{kind:"association",dash:"",end:"umlOpen"}}}var R9=e=>(e.stereotype??"").replace(/[«»]/g,"").trim().toLowerCase()==="interface";function D9(e){const t=e.classes??[],n=e.rels??[],s=15,o=O=>{const C=[O.name,...O.stereotype!==void 0?[`«${O.stereotype}»`]:[],...O.attrs??[],...O.methods??[]],D=Math.max(8,...C.map(F=>F.length));return Math.min(280,Math.max(150,D*6.4+30))},r=O=>O.stereotype!==void 0?38:26,i=O=>(O!==void 0&&O.length>0?O.length*s:6)+10,l=O=>r(O)+i(O.attrs)+i(O.methods),d=new Map(t.map(O=>[O.id,O])),u=n.map((O,C)=>({rl:O,ri:C})).filter(({rl:O})=>d.has(O.from)&&d.has(O.to)),p=t.filter(R9),h=p.length===1?p[0]?.id:void 0,m=new $f.graphlib.Graph({multigraph:!0});m.setGraph({rankdir:"TB",nodesep:46,ranksep:58,marginx:20,marginy:20}),m.setDefaultEdgeLabel(()=>({}));for(const O of t)m.setNode(O.id,{width:o(O),height:l(O)});u.forEach(({rl:O},C)=>m.setEdge(O.from,O.to,{},`e${C}`)),$f.layout(m);const g=m.graph(),v=Math.ceil(g.width??0),y=Math.ceil(g.height??0),b=new Map;for(const O of t){const C=m.node(O.id);C!==void 0&&b.set(O.id,{x:C.x-o(O)/2,y:C.y-l(O)/2})}let E=`<svg viewBox="0 0 ${v} ${y}" role="img"><title>UML class diagram</title><defs><marker id="umlTri" viewBox="0 0 14 14" refX="13" refY="7" markerWidth="13" markerHeight="13" markerUnits="userSpaceOnUse" orient="auto-start-reverse"><path d="M1,1 L13,7 L1,13 z" fill="var(--paper)" stroke="var(--ink)" stroke-width="1.2"/></marker><marker id="umlDiaF" viewBox="0 0 20 12" refX="30" refY="6" markerWidth="11" markerHeight="7" markerUnits="userSpaceOnUse" orient="auto-start-reverse"><path d="M1,6 L10,1 L19,6 L10,11 z" fill="var(--muted)"/></marker><marker id="umlDiaH" viewBox="0 0 20 12" refX="30" refY="6" markerWidth="11" markerHeight="7" markerUnits="userSpaceOnUse" orient="auto-start-reverse"><path d="M1,6 L10,1 L19,6 L10,11 z" fill="var(--paper)" stroke="var(--muted)" stroke-width="1.2"/></marker><marker id="umlOpen" viewBox="0 0 12 12" refX="10" refY="6" markerWidth="12" markerHeight="12" markerUnits="userSpaceOnUse" orient="auto-start-reverse"><path d="M1,1 L11,6 L1,11" fill="none" stroke="var(--muted)" stroke-width="1.3"/></marker></defs>`;const $=[],A=new Set;E+=`<g${he("rels")}>`,u.forEach(({rl:O,ri:C},D)=>{const U=m.edge(O.from,O.to,`e${D}`)?.points;if(U===void 0||U.length<2)return;const X=O9(O.kind);A.add(X.kind);const B=X.start!==void 0?` marker-start="url(#${X.start})"`:"",te=X.end!==void 0?` marker-end="url(#${X.end})"`:"",ee=X.dash.length>0?` stroke-dasharray="${X.dash}"`:"";if(E+=`<path d="${P9(U,9)}" fill="none" stroke="var(--muted)" stroke-width="1.5"${ee}${B}${te}${_(`rels.${C}`)}/>`,O.label!==void 0&&O.label!==""){const H=U[Math.floor(U.length/2)];H!==void 0&&$.push({lx:H.x,ly:H.y,label:O.label,path:`rels.${C}`})}}),E+="</g>",E+=`<g${he("classes")}>`;const T=[];t.forEach((O,C)=>{const D=b.get(O.id);if(D===void 0)return;const F={x:D.x,y:D.y,w:o(O),h:l(O)};T.push(F);const U=r(O),X=i(O.attrs),B=O.id===h,te=F.y+(O.stereotype!==void 0?30:18),ee=O.stereotype!==void 0?`<text x="${F.x+F.w/2}" y="${F.y+14}" class="t-eyebrow${B?" c-accent":""}" text-anchor="middle">«${S(O.stereotype)}»</text>`:"",H=`<g${he(`classes.${C}.attrs`)}>`+(O.attrs??[]).map((z,Y)=>`<text x="${F.x+12}" y="${F.y+U+15+Y*s}" class="t-sub c-ink"${_(`classes.${C}.attrs.${Y}`)}>${S(z)}</text>`).join("")+"</g>",W=`<g${he(`classes.${C}.methods`)}>`+(O.methods??[]).map((z,Y)=>`<text x="${F.x+12}" y="${F.y+U+X+15+Y*s}" class="t-sub c-ink"${_(`classes.${C}.methods.${Y}`)}>${S(z)}</text>`).join("")+"</g>",K=B?"var(--accent)":"var(--ink)",R=B?"var(--accent-tint)":"var(--paper)";E+=`<g${_(`classes.${C}`)}><rect x="${F.x}" y="${F.y}" width="${F.w}" height="${F.h}" rx="4" fill="${R}" stroke="${K}" stroke-width="1.5"/>`+ee+`<text x="${F.x+F.w/2}" y="${te}" class="t-name${B?" c-accent":""}" text-anchor="middle"${_(`classes.${C}.name`)}>${S(O.name)}</text><line x1="${F.x}" y1="${F.y+U}" x2="${F.x+F.w}" y2="${F.y+U}" class="uml-sep"${ut}/>`+H+`<line x1="${F.x}" y1="${F.y+U+X}" x2="${F.x+F.w}" y2="${F.y+U+X}" class="uml-sep"${ut}/>`+W+"</g>"}),E+="</g>";const{overlay:N,legend:j}=Ws($,T,{skin:!0});E+=N,E+="</svg>";const P=[];A.has("association")&&P.push({swatch:"edge",label:"association"}),A.has("inheritance")&&P.push({swatch:"chip",chip:"△",label:"inherits"}),A.has("implementation")&&P.push({swatch:"edge-dashed",label:"implements"}),A.has("composition")&&P.push({swatch:"chip",chip:"◆",label:"composed of"}),A.has("aggregation")&&P.push({swatch:"chip",chip:"◇",label:"aggregates"}),A.has("dependency")&&P.push({swatch:"edge-dashed",label:"depends on"}),h!==void 0&&P.push({swatch:"node-accent",label:"interface"});const I=ot(P);return ct({tag:"UML",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...I.length>0?{legendHtml:I}:{}},E+j)}function f$(e){switch((e??"component").toLowerCase()){case"root":return{chip:"ROOT",primary:!0,fill:"paper",dashed:!1};case"layout":return{chip:"LAYOUT",primary:!0,fill:"paper",dashed:!1};case"page":return{chip:"PAGE",primary:!0,fill:"paper",dashed:!1};case"leaf":return{chip:"LEAF",primary:!1,fill:"paper-2",dashed:!1};case"provider":case"context":return{chip:"PROVIDER",primary:!0,fill:"paper",dashed:!0};case"hook":return{chip:"HOOK",primary:!0,fill:"paper",dashed:!1};case"store":case"state":return{chip:"STORE",primary:!1,fill:"paper-2",dashed:!1};default:return{chip:"",primary:!0,fill:"paper",dashed:!1}}}var B9={ROOT:"root",LAYOUT:"layout",PAGE:"page",LEAF:"leaf",PROVIDER:"provider / context",HOOK:"hook",STORE:"store / state"};function z9(e){const t=e.nodes??[],n=new Map,s=new Map;for(const X of t)n.set(X.id,X),s.set(X.id,[]);const o=[];for(const X of t)X.parent!==void 0&&n.has(X.parent)?s.get(X.parent)?.push(X.id):o.push(X.id);const r=o.length===1?o[0]:void 0,i=new Map,l=new Map,d=new Set;let u=0,p=0;const h=(X,B)=>{if(d.has(X))return;d.add(X),l.set(X,B),B>p&&(p=B);const te=s.get(X)??[];if(te.length===0)i.set(X,u),u+=1;else{for(const W of te)h(W,B+1);const ee=i.get(te[0]??"")??0,H=i.get(te[te.length-1]??"")??0;i.set(X,(ee+H)/2)}};for(const X of o)h(X,0);const m=158,g=56,v=24,y=96,b=24,E=18,$=18,A=Math.max(u,1),T=X=>b+(i.get(X)??0)*(m+v),N=X=>E+(l.get(X)??0)*y,j=b*2+A*(m+v)-v,P=E+p*y+g+$;let I=`<svg viewBox="0 0 ${j} ${P}" role="img"><title>Component tree</title>`;for(const X of t){if(X.parent===void 0||!n.has(X.parent)||!i.has(X.id))continue;const B=T(X.parent)+m/2,te=N(X.parent)+g,ee=T(X.id)+m/2,H=N(X.id),W=(te+H)/2;I+=`<path d="M ${B} ${te} V ${W} H ${ee} V ${H}" fill="none" stroke="var(--muted)" stroke-width="1.25"/>`}const O=new Set;let C=!1,D=!1;I+=`<g${he("nodes")}>`,t.forEach((X,B)=>{if(!i.has(X.id))return;const te=T(X.id),ee=N(X.id),H=f$(X.kind),W=X.id===r;H.chip!==""&&O.add(H.chip),H.dashed&&(C=!0),H.fill==="paper-2"&&(D=!0);const K=W?"var(--accent)":H.primary?"var(--ink)":"var(--rule-solid)",R=W||H.primary?1.5:1,z=W?"var(--accent-tint)":H.fill==="paper-2"?"var(--paper-2)":"var(--paper)",Y=H.dashed?' stroke-dasharray="4 3"':"",V=`<rect x="${te}" y="${ee}" width="${m}" height="${g}" rx="4" fill="${z}" stroke="${K}" stroke-width="${R}"${Y}/>`,re=W?" c-accent":H.fill==="paper-2"?" c-muted":"",Q=H.chip!==""?`<text x="${te+12}" y="${ee+13}" class="t-eyebrow${re}">${H.chip}</text>`:"",ne=te+12,Z=lt(X.name,19,X.note!==void 0?1:2),q=H.chip!==""?18:8,de=Z.length*14+(X.note!==void 0?14:0),le=ee+q+(g-q-de)/2+11,J=Z.map((ve,we)=>`<text x="${ne}" y="${(le+we*14).toFixed(1)}" class="t-name${W?" c-accent":""}">${S(ve)}</text>`).join(""),ue=X.note!==void 0?`<text x="${ne}" y="${(le+Z.length*14).toFixed(1)}" class="t-sub">${S(X.note)}</text>`:"";I+=`<g${_(`nodes.${B}`)}>`+V+Q+J+ue+"</g>"}),I+="</g>",I+="</svg>";const F=[];t.some(X=>f$(X.kind).chip==="")&&F.push({swatch:"node",label:"component"});for(const X of O)F.push({swatch:"chip",chip:X,label:B9[X]??X.toLowerCase()});C&&F.push({swatch:"node-dashed",label:"wraps its subtree"}),D&&F.push({swatch:"node-fill2",label:"leaf / store"}),r!==void 0&&F.push({swatch:"node-accent",label:"tree root"});const U=ot(F);return ct({tag:"FE",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...U.length>0?{legendHtml:U}:{}},I)}var iA=Qo.solid??{stroke:"var(--muted)",sw:1.5,dash:"",marker:"skArrow",err:!1},F9={CLIENT:"client",SVC:"service",DATA:"data",DB:"database",BUCKET:"object store",WAREHOUSE:"warehouse",QUEUE:"queue",TOPIC:"topic",BUS:"stream",CACHE:"cache",SEARCH:"search index",REGISTRY:"registry",GATEWAY:"gateway",LB:"load balancer",FN:"function",EDGE:"edge / CDN",EXT:"external",PRODUCER:"producer",CONSUMER:"consumer",CONTEXT:"bounded context",WAF:"firewall",DNS:"DNS",AUTH:"identity",OBS:"observability",CRON:"scheduler",ANALYTICS:"analytics",CI:"pipeline",GIT:"repository",EMAIL:"messaging",CONFIG:"config",AI:"model / agent",HOST:"host",SECRETS:"secrets",WEBHOOK:"webhook",REGION:"region",DEPLOY:"deployment",POD:"pod",INGRESS:"ingress",NS:"namespace",NODE:"node",CLUSTER:"cluster"};function aA(e,t){const n=e.filter(s=>t.includes((s.kind??"").toLowerCase()));return n.length===1?n[0]?.id:void 0}function Zy(e,t,n,s=!1){const o=[],r=new Set;for(const i of e){const l=Vo(i.kind);l.chip===""||r.has(l.chip)||(r.add(l.chip),o.push({swatch:"chip",chip:l.chip,label:F9[l.chip]??l.chip.toLowerCase()}))}return s&&o.push({swatch:"chip",chip:"×N",label:"replicas"}),t.has("solid")&&o.push({swatch:"edge",label:"calls"}),t.has("dashed")&&o.push({swatch:"edge-dashed",label:"async / optional"}),t.has("forbidden")&&o.push({swatch:"edge-error",label:"forbidden"}),t.has("error")&&o.push({swatch:"edge-error",label:"error"}),n&&o.push({swatch:"node-accent",label:"entry point"}),ot(o)}function Rn(e){const o=e.anchor==="middle"?' text-anchor="middle"':"",r=lt(e.name,Math.max(6,Math.floor(e.textW/(e.skin===!0?7:6.6))),2),i=e.tech!==void 0?lt(e.tech,Math.max(6,Math.floor(e.textW/(e.skin===!0?6.2:5.8))),2):[],l=e.skin===!0?` class="blk-name t-name${e.accent===!0?" c-accent":""}"`:` class="blk-name" fill="${e.nameFill}"`,d=e.skin===!0?' class="blk-tech t-sub"':` class="blk-tech" fill="${e.techFill}"`,u=r.length*15+(i.length>0?4+i.length*12:0);let p=e.boxY+(e.boxH-u)/2+15-4,h="";for(const m of r)h+=`<text x="${e.x}" y="${p.toFixed(1)}"${l}${o}>${S(m)}</text>`,p+=15;if(i.length>0){p+=1;for(const m of i)h+=`<text x="${e.x}" y="${p.toFixed(1)}"${d}${o}>${S(m)}</text>`,p+=12}return h}function lA(e){const t=Math.min(e.w,Math.max(84,Math.round(e.w*.5)));return{x:Math.round(e.x+(e.w-t)/2),y:e.y,w:t,h:e.h}}function q9(e){return Jy(e)==="bar"}function qc(e,t,n){const s=Jy(e);return(()=>{switch(s){case"bar":return lA(t);case"cloud":return{x:t.x+t.w*.07,y:t.y+t.h*.3,w:t.w*.86,h:t.h*.7-4};case"stack":return{x:t.x,y:t.y-12,w:t.w+12,h:t.h+12};case"figure":case"crowd":return{x:t.x+t.w*.28,y:t.y,w:t.w*.44,h:t.h};case"globe":return{x:t.x+t.w*.3,y:t.y,w:t.w*.4,h:t.h};default:return t}})()}var b0=6;function cA(e,t,n){return dA(e,t)?{x:n.x,y:n.y,w:n.w-b0*2,h:n.h-b0*2}:n}var H9=new Set(["stack","replica","shards","crowd"]),W9=new Set(["cloud","shield","figure","crowd","globe","shards","replica"]);function dA(e,t){return e!==void 0&&e>=2&&!H9.has(t)}function U9(e,t){switch(e){case"pipe":return{x:t.x+t.w-Math.min(15,t.w*.11)*2-4,y:t.y+13,end:!0};case"cylinder":case"tiered":case"pail":return{x:t.x+t.w-14,y:t.y+Math.min(13,t.h*.16)*2+8,end:!0};default:return W9.has(e)?{x:t.x+8,y:t.y+13,end:!1}:{x:t.x+t.w-8,y:t.y+13,end:!0}}}function uA(e,t,n,s){if(e===void 0||e<2)return{back:"",chip:""};const o=b0,r=(u,p)=>`<rect x="${n.x+o*u}" y="${n.y+o*u}" width="${n.w}" height="${n.h}" rx="6" fill="${s.fill}" stroke="${s.accent}" stroke-width="1" opacity="${p}"/>`,i=dA(e,t)?r(2,.45)+r(1,.7):"",l=U9(t,n),d=`<text x="${l.x.toFixed(1)}" y="${l.y.toFixed(1)}" class="blk-rep t-sub"${l.end?' text-anchor="end"':""}>×${e}</text>`;return{back:i,chip:d}}function pA(e,t,n){const s=t.length>0?e.replace(/^<g[^>]*>/,o=>o+t):e;return n.length>0?s.replace(/<\/g>$/,`${n}</g>`):s}function Jy(e){switch((e??"").toLowerCase()){case"db":case"database":case"store":case"postgres":case"mysql":case"mongo":case"mongodb":case"dynamo":return"cylinder";case"warehouse":case"lake":return"tiered";case"bucket":case"blob":case"object":case"s3":return"pail";case"queue":case"topic":case"stream":case"mq":case"broker":case"sqs":case"rabbitmq":case"kafka":case"kinesis":return"pipe";case"sns":return"pipe";case"cdn":case"external":return"cloud";case"gateway":case"proxy":case"ingress":case"lb":return"bar";case"cache":case"redis":case"memcached":case"worker":case"etl":return"stack";case"vm":case"server":case"host":case"node":return"rack";case"waf":case"firewall":case"shield":return"shield";case"user":case"person":case"actor":return"figure";case"users":case"crowd":return"crowd";case"browser":case"web":return"window";case"mobile":return"phone";case"function":case"lambda":return"fn";case"scheduler":case"cron":case"job":case"cronjob":return"clock";case"secrets":case"vault":case"kms":case"secret":return"vault";case"shard":case"shards":case"sharded":return"shards";case"replica":case"replicas":case"replicaset":return"replica";case"region":case"geo":case"globe":return"globe";default:return"card"}}function fA(e,t){return{accent:t?"var(--accent)":e.primary?"var(--ink)":"var(--rule-solid)",fill:jz(e,t),text:"var(--ink)",legacy:!1,sw:t||e.primary?1.5:1,dashed:e.dashed,focal:t}}function hA(e,t,n){if(t.chip==="")return"";const s=n.x+n.w/2;let o,r,i="";switch(e){case"cylinder":case"tiered":case"pail":{const l=e==="pail"?Math.min(11,n.h*.13):Math.min(13,n.h*.16);o=s,r=n.y+l*2+8,i=' text-anchor="middle"';break}case"pipe":o=n.x+Math.min(15,n.w*.11)+6,r=n.y+12;break;case"bar":o=s,r=n.y+12,i=' text-anchor="middle"';break;case"fn":{const l=Math.min(n.h/2,n.w*.32);o=s,r=n.y+n.h/2-l*.62,i=' text-anchor="middle"';break}case"vault":o=s,r=n.y+n.h*.3+11,i=' text-anchor="middle"';break;case"card":case"stack":case"rack":case"window":case"phone":case"clock":o=n.x+10,r=n.y+(e==="clock"?Math.min(18,n.h*.22)+14:12);break;default:o=n.x+n.w-4,r=n.y+12,i=' text-anchor="end"'}return`<text x="${o.toFixed(1)}" y="${r.toFixed(1)}" class="blk-chip t-eyebrow"${i}>${S(t.chip)}</text>`}function ex(e,t,n,s=!1){const o=Vo(e.kind),r=fA(o,s),i=Jy(e.kind),l=r.legacy?t:i==="bar"?lA(t):cA(e.replicas,i,t),d=K9(e,l,r,i);if(r.legacy)return d;const u=uA(e.replicas,i,l,r);return pA(d,u.back,hA(i,o,l)+u.chip)}function K9(e,t,n,s){const o=t.x+t.w/2,r=e.tech!==void 0?{tech:e.tech}:{},i=n.legacy?' filter="url(#gshadow)"':"",l=n.sw,d=n.dashed?' stroke-dasharray="4 3"':"",u=n.legacy?n.accent:"var(--muted)",p=n.legacy?n.accent:"var(--muted)",h=n.legacy?{}:{skin:!0,accent:n.focal};if(s==="cylinder"){const m=Math.min(13,t.h*.16),g=t.w/2;return`<g${i}><path d="M${t.x} ${t.y+m} A ${g} ${m} 0 0 1 ${t.x+t.w} ${t.y+m} V ${t.y+t.h-m} A ${g} ${m} 0 0 1 ${t.x} ${t.y+t.h-m} Z" fill="${n.fill}" stroke="${n.accent}" stroke-width="${l}"${d}/><path d="M${t.x} ${t.y+m} A ${g} ${m} 0 0 0 ${t.x+t.w} ${t.y+m}" fill="none" stroke="${n.accent}" stroke-width="${l}"${d}/>`+Rn({name:e.name,...r,x:o,boxY:t.y+m*2,boxH:t.h-m*2.6,textW:t.w-30,nameFill:n.text,techFill:p,...h,anchor:"middle"})+"</g>"}if(s==="pipe"){const m=Math.min(15,t.w*.11),g=t.h/2,v=t.y+g;return`<g${i}><path d="M${t.x+m} ${t.y} H ${t.x+t.w-m} A ${m} ${g} 0 0 1 ${t.x+t.w-m} ${t.y+t.h} H ${t.x+m} A ${m} ${g} 0 0 1 ${t.x+m} ${t.y} Z" fill="${n.fill}" stroke="${n.accent}" stroke-width="${l}"${d}/><ellipse cx="${t.x+t.w-m}" cy="${v}" rx="${m}" ry="${g}" fill="none" stroke="${n.accent}" stroke-width="1.1" stroke-opacity="0.7"${ut}/>`+Rn({name:e.name,...r,x:t.x+(t.w-m)/2,boxY:t.y,boxH:t.h,textW:t.w-m*3.2,nameFill:n.text,techFill:p,...h,anchor:"middle"})+"</g>"}if(s==="stack"){const g=(b,E)=>`<rect x="${t.x+6*b}" y="${t.y-6*b}" width="${t.w}" height="${t.h}" rx="10" fill="${n.fill}" stroke="${n.accent}" stroke-width="1" opacity="${E}"/>`,v=al(e.kind,t.x+14,t.y+t.h/2-8,u),y=v.length>0?t.x+40:t.x+16;return`<g${i}>`+g(2,.45)+g(1,.7)+`<rect x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" rx="10" fill="${n.fill}" stroke="${n.accent}" stroke-width="${l}"${d}/>`+v+Rn({name:e.name,...r,x:y,boxY:t.y,boxH:t.h,textW:t.x+t.w-y-14,nameFill:n.text,techFill:p,...h})+"</g>"}if(s==="cloud"){const m=t.y+t.h-3,g=`M ${t.x+t.w*.2} ${m} A ${t.w*.13} ${t.h*.2} 0 0 1 ${t.x+t.w*.14} ${m-t.h*.32} A ${t.w*.17} ${t.h*.28} 0 0 1 ${t.x+t.w*.43} ${m-t.h*.58} A ${t.w*.18} ${t.h*.26} 0 0 1 ${t.x+t.w*.72} ${m-t.h*.5} A ${t.w*.13} ${t.h*.21} 0 0 1 ${t.x+t.w*.82} ${m} Z`;return`<g${i}><path d="${g}" fill="${n.fill}" stroke="${n.accent}" stroke-width="${l}"${d} stroke-linejoin="round"/>`+Rn({name:e.name,...r,x:t.x+t.w*.48,boxY:t.y+t.h*.34,boxH:t.h*.58,textW:t.w*.52,nameFill:n.text,techFill:p,...h,anchor:"middle"})+"</g>"}if(s==="bar")return`<g${i}><rect x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" rx="2" fill="${n.fill}" stroke="${n.accent}" stroke-width="${l}"${d}/>`+Rn({name:e.name,...r,x:o,boxY:t.y+18,boxH:t.h-24,textW:t.w-14,nameFill:n.text,techFill:p,...h,anchor:"middle"})+"</g>";if(s==="figure"){const m=Math.min(11,t.h*.13),g=t.y+m+2,v=g+m+20;return`<g><circle cx="${o}" cy="${g.toFixed(1)}" r="${m}" fill="${u}"/><path d="M ${o-m*1.8} ${v.toFixed(1)} a ${m*1.8} ${m*2} 0 0 1 ${m*3.6} 0 z" fill="${u}"/>`+Rn({name:e.name,...r,x:o,boxY:v+2,boxH:t.y+t.h-v-2,textW:t.w-12,nameFill:n.text,techFill:p,...h,anchor:"middle"})+"</g>"}if(s==="fn"){const m=Math.min(t.h/2,t.w*.32),g=t.y+t.h/2;return`<g${i}><circle cx="${o}" cy="${g}" r="${m}" fill="${n.fill}" stroke="${n.accent}" stroke-width="${l}"${d}/><text x="${o}" y="${(g-m*.25).toFixed(1)}" font-family="Georgia, serif" font-size="${Math.max(15,m*.42).toFixed(0)}" font-style="italic" font-weight="700" fill="${u}" text-anchor="middle">ƒ</text>`+Rn({name:e.name,...r,x:o,boxY:g-m*.1,boxH:m,textW:m*1.7,nameFill:n.text,techFill:p,...h,anchor:"middle"})+"</g>"}if(s==="clock"){const m=Math.min(18,t.h*.22),g=t.y+3,v=$=>`<path d="M${$.toFixed(1)} ${(g-6).toFixed(1)} V ${(g+4).toFixed(1)}" stroke="${n.accent}" stroke-width="3" stroke-linecap="round"/>`,y=t.x+t.w-18,b=t.y+t.h-16,E=Math.min(11,t.h*.14);return`<g${i}><rect x="${t.x}" y="${t.y+3}" width="${t.w}" height="${t.h-3}" rx="9" fill="${n.fill}" stroke="${n.accent}" stroke-width="${l}"${d}/><path d="M${t.x} ${t.y+12} a 9 9 0 0 1 9 -9 H ${t.x+t.w-9} a 9 9 0 0 1 9 9 V ${t.y+3+m} H ${t.x} Z" fill="${u}" fill-opacity="0.16"/><path d="M${t.x} ${t.y+3+m} H ${t.x+t.w}" stroke="${n.accent}" stroke-width="1" stroke-opacity="0.5"${ut}/>`+v(t.x+t.w*.3)+v(t.x+t.w*.7)+`<circle cx="${y}" cy="${b}" r="${E}" fill="var(--paper)" stroke="${n.accent}" stroke-width="1.4"/><path d="M${y} ${(b-E*.55).toFixed(1)} V ${b} L ${(y+E*.45).toFixed(1)} ${(b+E*.3).toFixed(1)}" stroke="${n.accent}" stroke-width="1.4" fill="none" stroke-linecap="round"/>`+Rn({name:e.name,...r,x:o,boxY:t.y+3+m,boxH:t.h-3-m,textW:t.w-40,nameFill:n.text,techFill:p,...h,anchor:"middle"})+"</g>"}if(s==="vault"){const m=t.y+t.h*.3,g=t.h*.7,v=Math.min(t.w*.72,t.h*1.6),y=o-v/2,b=v*.22;return`<g${i}><path d="M${(o-b).toFixed(1)} ${(m+4).toFixed(1)} V ${(t.y+b*.9+4).toFixed(1)} A ${b.toFixed(1)} ${(b*.95).toFixed(1)} 0 0 1 ${(o+b).toFixed(1)} ${(t.y+b*.9+4).toFixed(1)} V ${(m+4).toFixed(1)}" fill="none" stroke="${n.accent}" stroke-width="4" stroke-linecap="round"/><rect x="${y.toFixed(1)}" y="${m.toFixed(1)}" width="${v.toFixed(1)}" height="${g.toFixed(1)}" rx="10" fill="${n.fill}" stroke="${n.accent}" stroke-width="${l}"${d}/>`+Rn({name:e.name,...r,x:o,boxY:m,boxH:g,textW:v-18,nameFill:n.text,techFill:p,...h,anchor:"middle"})+"</g>"}if(s==="shards"){const v=(t.w-24-16)/3,y=t.h*.58,b=Math.min(7,y*.18);let E="";for(let $=0;$<3;$++){const A=t.x+12+$*(v+8);E+=`<path d="M${A.toFixed(1)} ${t.y+b} A ${v/2} ${b} 0 0 1 ${(A+v).toFixed(1)} ${t.y+b} V ${(t.y+y-b).toFixed(1)} A ${v/2} ${b} 0 0 1 ${A.toFixed(1)} ${(t.y+y-b).toFixed(1)} Z" fill="${n.fill}" stroke="${n.accent}" stroke-width="1.1"/><path d="M${A.toFixed(1)} ${t.y+b} A ${v/2} ${b} 0 0 0 ${(A+v).toFixed(1)} ${t.y+b}" fill="none" stroke="${n.accent}" stroke-width="1.1"/>`}return`<g${i}>`+E+Rn({name:e.name,...r,x:o,boxY:t.y+y+2,boxH:t.h-y-2,textW:t.w-16,nameFill:n.text,techFill:p,...h,anchor:"middle"})+"</g>"}if(s==="replica"){const g=Math.min(11,t.h*.14),v=t.w-14,y=(b,E,$,A)=>`<g opacity="${$}"><path d="M${(t.x+b).toFixed(1)} ${(t.y+E+g).toFixed(1)} A ${v/2} ${g} 0 0 1 ${(t.x+b+v).toFixed(1)} ${(t.y+E+g).toFixed(1)} V ${(t.y+E+t.h-14-g).toFixed(1)} A ${v/2} ${g} 0 0 1 ${(t.x+b).toFixed(1)} ${(t.y+E+t.h-14-g).toFixed(1)} Z" fill="${n.fill}" stroke="${n.accent}" stroke-width="${A}"/><path d="M${(t.x+b).toFixed(1)} ${(t.y+E+g).toFixed(1)} A ${v/2} ${g} 0 0 0 ${(t.x+b+v).toFixed(1)} ${(t.y+E+g).toFixed(1)}" fill="none" stroke="${n.accent}" stroke-width="${A}"/></g>`;return`<g${i}>`+y(14,0,.5,1)+y(7,7,.75,1)+y(0,14,1,1.2)+Rn({name:e.name,...r,x:t.x+v/2,boxY:t.y+14+g*2,boxH:t.h-14-g*2.6,textW:v-24,nameFill:n.text,techFill:p,...h,anchor:"middle"})+"</g>"}if(s==="crowd"){const m=Math.min(9,t.h*.11),g=(y,b,E,$)=>{const A=m*E;return`<g opacity="${$}"><circle cx="${y}" cy="${(b+A).toFixed(1)}" r="${A.toFixed(1)}" fill="${u}"/><path d="M ${(y-A*1.7).toFixed(1)} ${(b+A*2+A*1.9).toFixed(1)} a ${(A*1.7).toFixed(1)} ${(A*1.9).toFixed(1)} 0 0 1 ${(A*3.4).toFixed(1)} 0 z" fill="${u}"/></g>`},v=t.y+4;return"<g>"+g(o-m*2.4,v+3,.85,.45)+g(o+m*2.4,v+3,.85,.45)+g(o,v,1,1)+Rn({name:e.name,...r,x:o,boxY:v+m*4.6,boxH:t.y+t.h-(v+m*4.6),textW:t.w-12,nameFill:n.text,techFill:p,...h,anchor:"middle"})+"</g>"}if(s==="globe"){const m=Math.min(t.h*.33,30),g=t.y+m+2;return`<g><circle cx="${o}" cy="${g.toFixed(1)}" r="${m}" fill="${n.fill}" stroke="${n.accent}" stroke-width="${l}"${d}/><ellipse cx="${o}" cy="${g.toFixed(1)}" rx="${(m*.42).toFixed(1)}" ry="${m}" fill="none" stroke="${n.accent}" stroke-width="1" stroke-opacity="0.65"${ut}/><path d="M${(o-m).toFixed(1)} ${g.toFixed(1)} H ${(o+m).toFixed(1)}" stroke="${n.accent}" stroke-width="1" stroke-opacity="0.65"${ut}/><path d="M${(o-m*.87).toFixed(1)} ${(g-m*.45).toFixed(1)} a ${m*1.15} ${m*1.15} 0 0 1 ${(m*1.74).toFixed(1)} 0" fill="none" stroke="${n.accent}" stroke-width="1" stroke-opacity="0.45"${ut}/>`+Rn({name:e.name,...r,x:o,boxY:g+m+2,boxH:t.y+t.h-(g+m+2),textW:t.w-12,nameFill:n.text,techFill:p,...h,anchor:"middle"})+"</g>"}if(s==="phone"){const g=t.x+12,v=t.y+5,y=t.h-10,b=g+34+14;return`<g${i}><rect x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" rx="10" fill="${n.fill}" stroke="${n.accent}" stroke-width="${l}"${d}/><rect x="${g}" y="${v}" width="34" height="${y}" rx="7" fill="var(--paper)" stroke="${n.accent}" stroke-width="${l}"${d}/><path d="M${g+34/2-5} ${v+6} H ${g+34/2+5}" stroke="${n.accent}" stroke-width="1.4" stroke-linecap="round"/><circle cx="${g+34/2}" cy="${v+y-7}" r="2" fill="${u}"/>`+Rn({name:e.name,...r,x:b,boxY:t.y,boxH:t.h,textW:t.x+t.w-b-12,nameFill:n.text,techFill:p,...h})+"</g>"}if(s==="window"){const g=v=>`<circle cx="${t.x+12+v*10}" cy="${t.y+9}" r="2.6" fill="${u}" opacity="${.85-v*.2}"/>`;return`<g${i}><rect x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" rx="9" fill="${n.fill}" stroke="${n.accent}" stroke-width="${l}"${d}/><path d="M${t.x} ${t.y+9} a 9 9 0 0 1 9 -9 H ${t.x+t.w-9} a 9 9 0 0 1 9 9 V ${t.y+18} H ${t.x} Z" fill="${u}" fill-opacity="0.14"/><path d="M${t.x} ${t.y+18} H ${t.x+t.w}" stroke="${n.accent}" stroke-width="1" stroke-opacity="0.5"${ut}/>`+g(0)+g(1)+g(2)+Rn({name:e.name,...r,x:o,boxY:t.y+18,boxH:t.h-18,textW:t.w-24,nameFill:n.text,techFill:p,...h,anchor:"middle"})+"</g>"}return mA(e,t,n)}function V9(e,t,n=!1){const s=Vo(e.kind),o=fA(s,n),r=cA(e.replicas,"card",t),i=mA(e,r,o),l=uA(e.replicas,"card",r,o);return pA(i,l.back,hA("card",s,r)+l.chip)}function mA(e,t,n){const s=n.legacy?n.accent:"var(--muted)",o=al(e.kind,t.x+14,t.y+t.h/2-8,s),r=o.length>0?t.x+40:t.x+16,i=n.legacy?' filter="url(#gshadow)"':"",l=n.dashed?' stroke-dasharray="4 3"':"",d=!n.legacy&&Vo(e.kind).chip!=="",u=d?t.y+10:t.y,p=d?t.h-10:t.h;return`<g${i}><rect x="${t.x}" y="${t.y}" width="${t.w}" height="${t.h}" rx="${n.legacy?10:6}" fill="${n.fill}" stroke="${n.accent}" stroke-width="${n.sw}"${l}/>`+o+Rn({name:e.name,...e.tech!==void 0?{tech:e.tech}:{},x:r,boxY:u,boxH:p,textW:t.x+t.w-r-14,nameFill:n.text,techFill:n.legacy?n.accent:"var(--muted)",...n.legacy?{}:{skin:!0,accent:n.focal}})+"</g>"}function G9(e,t){const n=new Map(e.map(s=>[s.id,s]));return e.map(s=>{if(!q9(s.kind)||s.h!==void 0)return s;const o=t.filter(h=>h.from===s.id||h.to===s.id).map(h=>n.get(h.from===s.id?h.to:h.from)).filter(h=>h!==void 0&&h.id!==s.id),r=new Map;for(const h of o)r.set(h.col,[...r.get(h.col)??[],h]);const i=[...r.values()].sort((h,m)=>m.length-h.length)[0];if(i===void 0||i.length<2)return s;const l=[...new Set(i.map(h=>h.row))].sort((h,m)=>h-m),d=l[0]??s.row,u=l[l.length-1]??s.row;return u<=d||e.some(h=>h.id!==s.id&&h.col<=s.col+((s.w??1)-1)&&h.col+((h.w??1)-1)>=s.col&&h.row+((h.h??1)-1)>=d&&h.row<=u)?s:{...s,row:d,h:u-d+1}})}function Y9(e,t){const n=e.groups??[],s=e.edges??[],o=e.nodes??[],r=n.length===0&&!(o.length>0&&o.every(H=>H.col!==void 0&&H.row!==void 0)),i=n.length===0?nr(o,s,e.dir??"LR"):o.map(H=>({...H,col:H.col??1,row:H.row??1})),l=G9(i,s),d=178,u=88,p=64,h=64,m=Yi(n),g=38+m.padX,v=52+m.padTop,y=36+m.padBot,b=Math.max(1,...l.map(H=>(H.col??1)+((H.w??1)-1)),...n.map(H=>H.col+(H.cols??1)-1)),E=Math.max(1,...l.map(H=>(H.row??1)+((H.h??1)-1)),...n.map(H=>H.row+(H.rows??1)-1)),$=H=>g+(H-1)*(d+p),A=H=>v+(H-1)*(u+h),T=H=>({x:$(H.col??1),y:A(H.row??1),w:(H.w??1)*d+((H.w??1)-1)*p,h:(H.h??1)*u+((H.h??1)-1)*h}),N=new Map(l.map(H=>[H.id,H])),j=g*2+b*d+(b-1)*p,P=v+E*u+(E-1)*h+y,I=tr({quick:r,cols:b,rows:E,cellW:d,cellH:u,gapX:p,gapY:h,padX:g,padTop:v}),O=Sn("Block diagram",e.title,[wt(l.length,"node"),wt(s.length,"connection")]);let C=`<svg viewBox="0 0 ${j} ${P}"${O.attrs}${I}>${O.title}`;C+=xl(n,{xOf:$,yOf:A,cellW:d,cellH:u,gapX:p,gapY:h,skin:!0});const D=aA(l,t),F=new Set,U=[];C+=`<g${he("edges")}>`;const X=qs(s),B=Hs(s,H=>{const W=N.get(H);return W!==void 0?qc(W.kind,T(W),W.replicas):void 0});s.forEach((H,W)=>{const K=N.get(H.from),R=N.get(H.to);if(!K||!R)return;const z=Fs(qc(K.kind,T(K),K.replicas),qc(R.kind,T(R),R.replicas),X[W]??0,B[W]??0),Y=H.kind??"solid";F.add(Y in Qo?Y:"solid");const V=Qo[Y]??iA;C+=`<path d="${z.d}" fill="none" stroke="${V.stroke}" stroke-width="${V.sw}" stroke-dasharray="${V.dash}" marker-end="url(#${V.marker})"${_(`edges.${W}`)}/>`,U.push({lx:z.lx,ly:z.ly,...H.label!==void 0?{label:H.label}:{},err:V.err,path:`edges.${W}`})}),C+="</g>",C+=`<g${he("nodes")}>`,l.forEach((H,W)=>{const K=Mo(H.col??1,H.row??1,H.w??1);C+=`<g${_(`nodes.${W}`)}${K}>${ex(H,T(H),void 0,H.id===D)}</g>`}),C+="</g>";const{overlay:te,legend:ee}=Ws(U,l.map(H=>T(H)),{skin:!0});return C+=te,C+="</svg>",{svg:C+ee,legend:Zy(l,F,D!==void 0,gA(l))}}function gA(e){return e.some(t=>t.replicas!==void 0&&t.replicas>=2)}function X9(e,t){const n=e.layers??[],s=e.nodes??[],o=e.edges??[],r=n.map((K,R)=>s.filter(z=>(z.layer??0)===R)),i=28,l=e.systemLabel!==void 0?46:16,d=132,u=16,p=14,h=12,m=158,g=64,v=22,y=K=>K*m+(K-1)*v,E=Math.max(220,...r.map(K=>y(Math.max(K.length,1))))+u*2,$=g+p*2,A=i+14,T=A+d,N=T+E+14+i,j=i+l,P=K=>j+K*($+h),O=P(n.length)-h+16+i,C=new Map;r.forEach((K,R)=>{const z=T+(E-y(K.length))/2;K.forEach((Y,V)=>{C.set(Y.id,{x:z+V*(m+v),y:P(R)+p,w:m,h:g})})});const D=Sn("Layered architecture",e.title,[wt(n.length,"layer"),wt(s.length,"node")]);let F=`<svg viewBox="0 0 ${N} ${O}"${D.attrs}>${D.title}<rect x="${i}" y="${i}" width="${N-i*2}" height="${O-i*2}" rx="8" fill="none" stroke="var(--rule-solid)" stroke-width="1" stroke-dasharray="4 3"/>`;e.systemLabel!==void 0&&(F+=`<text x="${i+14}" y="${i+18}" class="grp-label t-eyebrow c-muted"${_("systemLabel")}>${S(e.systemLabel)}</text>`);const U=aA(s,t),X=new Set;F+=`<g${he("layers")}>`;for(let K=0;K<n.length;K++){const R=n[K];if(R===void 0)continue;const z=Fi(R.color,""),Y=z.length>0?z:"var(--rule-solid)",V=z.length>0?z:"var(--soft)",Q=lt(R.label,Math.max(8,Math.floor((d-24)/6.8)),3).map((ne,Z)=>`<text x="${A+12}" y="${(P(K)+16+Z*12).toFixed(1)}" class="layer-label t-eyebrow" fill="${V}">${S(ne)}</text>`).join("");F+=`<g${_(`layers.${K}`)}><rect x="${A}" y="${P(K)}" width="${d+E}" height="${$}" rx="6" fill="var(--paper-2)" fill-opacity="0.6" stroke="${Y}" stroke-width="1"/>`+Q+"</g>"}F+="</g>";const B=[];F+=`<g${he("edges")}>`;const te=qs(o),ee=Hs(o,K=>C.get(K));o.forEach((K,R)=>{const z=C.get(K.from),Y=C.get(K.to);if(!z||!Y)return;const V=Fs(z,Y,te[R]??0,ee[R]??0),re=K.kind??"solid";X.add(re in Qo?re:"solid");const Q=Qo[re]??iA;F+=`<path d="${V.d}" fill="none" stroke="${Q.stroke}" stroke-width="${Q.sw}" stroke-dasharray="${Q.dash}" marker-end="url(#${Q.marker})"${_(`edges.${R}`)}/>`,B.push({lx:V.lx,ly:V.ly,...K.label!==void 0?{label:K.label}:{},err:Q.err,path:`edges.${R}`})}),F+="</g>",F+=`<g${he("nodes")}>`,s.forEach((K,R)=>{const z=C.get(K.id);z!==void 0&&(F+=`<g${_(`nodes.${R}`)}>${V9(K,z,K.id===U)}</g>`)}),F+="</g>";const{overlay:H,legend:W}=Ws(B,[...C.values()],{skin:!0});return F+=H,F+="</svg>",{svg:F+W,legend:Zy(s,X,U!==void 0,gA(s))}}function Q9(e,t){const{svg:n,legend:s}=e.layers!==void 0&&e.layers.length>0?X9(e,t.entry):Y9(e,t.entry),o={tag:t.tag,...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...s.length>0?{legendHtml:s}:{}};return ct(o,n)}var Z9={arch:{tag:"ARCH",entry:["gateway"]},infra:{tag:"INFRA",entry:["gateway"]},event:{tag:"EVENT",entry:["producer"]},ddd:{tag:"DDD",entry:[]},network:{tag:"ZONES",entry:["gateway","firewall","waf","shield"]},k8s:{tag:"K8S",entry:["ingress","gateway"]}};function J9(e){return Q9(e,Z9[e.preset??"arch"])}var eq=new Set(["db","database","store","warehouse","lake","postgres","mysql","mongo","mongodb","dynamo"]);function tq(e){const t=e.clusters??[],n=e.services??[],s=e.edges??[],o=new Map;for(const B of t)o.set(B.id,[]);for(const B of n){const te=o.get(B.cluster);te!==void 0&&te.push(B)}const r=158,i=78,l=22,d=24,u=34,p=22,h=34,m=26,g=new Map,v=[];let y=m,b=0;for(const B of t){const te=o.get(B.id)??[],ee=Math.min(2,Math.max(1,te.length)),H=Math.max(1,Math.ceil(te.length/ee)),W=ee*r+(ee-1)*l+d*2,K=u+H*i+(H-1)*l+p;v.push({c:B,x:y,y:m,w:W,h:K}),te.forEach((R,z)=>{const Y=Math.floor(z/ee),V=z%ee;g.set(R.id,{x:y+d+V*(r+l),y:m+u+Y*(i+l),w:r,h:i})}),K>b&&(b=K),y+=W+h}const E=y-h+m,$=m*2+b;let A=`<svg viewBox="0 0 ${E} ${$}" role="img"><title>Cluster diagram</title>`;A+=`<g${he("clusters")}>`,v.forEach((B,te)=>{const ee=B.c.kind!==void 0?`<text x="${B.x+B.w-12}" y="${B.y+16}" class="t-eyebrow" text-anchor="end">${S(B.c.kind)}</text>`:"";A+=`<g${_(`clusters.${te}`)}><rect x="${B.x}" y="${B.y}" width="${B.w}" height="${B.h}" rx="6" fill="var(--paper-2)" fill-opacity="0.6" stroke="var(--rule-solid)" stroke-width="1"/><text x="${B.x+12}" y="${B.y+16}" class="t-eyebrow">${S(B.c.label)}</text>`+ee+"</g>"}),A+="</g>";const T=[],N=new Set;A+=`<g${he("edges")}>`;const j=qs(s),P=new Map(n.map(B=>[B.id,B.kind])),I=B=>{const te=g.get(B);return te===void 0?void 0:qc(P.get(B),te)},O=Hs(s,I);s.forEach((B,te)=>{const ee=I(B.from),H=I(B.to);if(!ee||!H)return;const W=Fs(ee,H,j[te]??0,O[te]??0),K=B.kind??"solid";N.add(K);const R=Qo[K]??Qo.solid??{stroke:"var(--muted)",sw:1.5,dash:"",marker:"skArrow",err:!1},z=R.dash.length>0?` stroke-dasharray="${R.dash}"`:"";A+=`<path d="${W.d}" fill="none" stroke="${R.stroke}" stroke-width="${R.sw}"${z} marker-end="url(#${R.marker})"${_(`edges.${te}`)}/>`,T.push({lx:W.lx,ly:W.ly,...B.label!==void 0?{label:B.label}:{},err:R.err,path:`edges.${te}`})}),A+="</g>";const C=n.filter(B=>(B.kind??"").toLowerCase()==="gateway"),D=C.length===1?C[0]?.id:void 0;A+=`<g${he("services")}>`,n.forEach((B,te)=>{const ee=g.get(B.id);if(ee===void 0)return;const H=B.replicas??0;let W="";if(H>0){const R=Math.min(H,5),z=eq.has((B.kind??"").toLowerCase())?ee.y+ee.h-24:ee.y+ee.h-14;let Y="";for(let V=0;V<R;V++)Y+=`<rect x="${ee.x+12+V*7}" y="${z}" width="4" height="8" rx="1" fill="var(--muted)"/>`;W="<g>"+Y+`<text x="${ee.x+12+R*7+4}" y="${z+7}" class="t-sub">×${H}</text></g>`}const K=ex({kind:B.kind,name:B.label,...B.tech!==void 0?{tech:B.tech}:{}},ee,void 0,B.id===D);A+=`<g${_(`services.${te}`)}>${K}${W}</g>`}),A+="</g>";const{overlay:F,legend:U}=Ws(T,[...g.values()],{skin:!0});A+=F,A+="</svg>";const X=Zy(n,N,D!==void 0);return ct({tag:"CLUSTER",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...X.length>0?{legendHtml:X}:{}},A+U)}var nq=["component","engine","core","interface","strategy","impl","adapter","controller","handler","route","gateway","service","usecase","apiclient","client","repository","repo","dao","worker","consumer","middleware","model","entity","db","store","database","cache","queue","bus","broker","state","hook","external","backend","egress","api","thirdparty"],hs=e=>({chip:e,primary:!0,fill:"paper",dashed:!1}),h$=e=>({chip:e,primary:!1,fill:"paper-2",dashed:!1});function sq(e){const t=(e??"component").toLowerCase();switch(t){case"component":return hs("");case"engine":case"core":return hs("ENGINE");case"interface":return{chip:"INTERFACE",primary:!0,fill:"paper",dashed:!0};case"strategy":case"impl":return hs("STRATEGY");case"adapter":return hs("ADAPTER");case"controller":case"handler":case"route":return hs("CONTROLLER");case"gateway":return hs("GATEWAY");case"service":case"usecase":return hs("SERVICE");case"apiclient":case"client":return hs("CLIENT");case"repository":case"repo":case"dao":return hs("REPOSITORY");case"worker":case"consumer":return hs("WORKER");case"middleware":return h$("MIDDLEWARE");case"model":case"entity":return hs("MODEL");case"state":case"store_state":return h$("STATE");case"hook":return hs("HOOK");default:return hs(t.toUpperCase())}}function oq(e){switch((e??"uses").toLowerCase()){case"implements":return{stroke:"var(--muted)",sw:1.5,dash:"5 4",marker:"feTri",legend:"implements"};case"egress":case"https":case"api":return{stroke:"var(--link)",sw:1.5,dash:"",marker:"feLink",legend:"network"};case"reads":case"dashed":return{stroke:"var(--muted)",sw:1.5,dash:"5 4",marker:"skOpen",legend:"reads"};case"async":return{stroke:"var(--muted)",sw:1.25,dash:"2 3",marker:"skOpen",legend:"async"};default:return{stroke:"var(--muted)",sw:1.5,dash:"",marker:"skArrow",legend:"uses"}}}var m$={bus:"queue",backend:"external",api:"external",thirdparty:"external",egress:"external"},rq=new Set(["db","store","database","queue","broker","cache","redis","external"]);function iq(e,t){const n=e.groups??[],s=e.edges??[],o=e.nodes??[],r=!(o.length>0&&o.every(q=>q.col!==void 0&&q.row!==void 0)),i=n.length===0?nr(o,s,e.dir??"LR"):o.map(q=>({...q,col:q.col??1,row:q.row??1})),l=178,d=80,u=54,p=60,h=Az(n),m=Yi(n),g=h.size>0?{x:28,top:38,bot:28}:{x:16,top:22,bot:16},v=26+(g.x-16)+m.padX,y=30+(g.top-22)+m.padTop,b=20+(g.bot-16)+m.padBot,E=Math.max(1,...i.map(q=>q.col+((q.w??1)-1)),...n.map(q=>q.col+(q.cols??1)-1)),$=Math.max(1,...i.map(q=>q.row),...n.map(q=>q.row+(q.rows??1)-1)),A=q=>v+(q-1)*(l+u),T=q=>y+(q-1)*(d+p),N=q=>({x:A(q.col),y:T(q.row),w:(q.w??1)*l+((q.w??1)-1)*u,h:d}),j=q=>({x:A(q.col)-g.x,y:T(q.row)-g.top,w:(q.cols??1)*l+((q.cols??1)-1)*u+g.x*2,h:(q.rows??1)*d+((q.rows??1)-1)*p+g.top+g.bot}),P=new Map(i.map(q=>[q.id,q])),I=v*2+E*l+(E-1)*u,O=y+$*d+($-1)*p+b,C=q=>(q.cols??1)*(q.rows??1),D=n.map((q,de)=>({g:q,gi:de})).sort((q,de)=>h.size>0?(h.get(q.g)?.depth??0)-(h.get(de.g)?.depth??0)||C(de.g)-C(q.g)||q.gi-de.gi:C(de.g)-C(q.g)),F=e.variant==="be"?["controller","handler","route"]:["engine","core"],U=i.filter(q=>F.includes((q.kind??"").toLowerCase())),X=U.length===1?U[0]?.id:void 0,B=tr({quick:r,cols:E,rows:$,cellW:l,cellH:d,gapX:u,gapY:p,padX:v,padTop:y});let te=`<svg viewBox="0 0 ${I} ${O}" role="img"${B}><title>Module graph</title><defs><marker id="feLink" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="var(--link)"/></marker><marker id="feTri" viewBox="0 0 14 14" refX="13" refY="7" markerWidth="11" markerHeight="11" markerUnits="userSpaceOnUse" orient="auto-start-reverse"><path d="M1,1 L13,7 L1,13 z" fill="var(--paper)" stroke="var(--ink)" stroke-width="1.2"/></marker></defs>`;te+=`<g${he("groups")}>`;for(const{g:q,gi:de}of D){const le=j(q),J=h.get(q),ue=J===void 0?le:{x:le.x+J.inset.x,y:le.y+J.inset.y,w:le.w-J.inset.w,h:le.h-J.inset.h},we=J!==void 0&&J.depth%2===1?`<text x="${ue.x+ue.w-12}" y="${ue.y+15}" class="t-eyebrow" text-anchor="end">${S(q.label)}</text>`:`<text x="${ue.x+12}" y="${ue.y+15}" class="t-eyebrow">${S(q.label)}</text>`;te+=`<g${_(`groups.${de}`)}><rect x="${ue.x}" y="${ue.y}" width="${ue.w}" height="${ue.h}" rx="6" fill="var(--paper-2)" fill-opacity="0.6" stroke="var(--rule-solid)" stroke-width="1"/>`+we+"</g>"}te+="</g>";const ee=q=>{const de=(q.kind??"").toLowerCase();return qc(m$[de]??de,N(q))},H=[],W=new Set;te+=`<g${he("edges")}>`;const K=qs(s),R=Hs(s,q=>{const de=P.get(q);return de!==void 0?ee(de):void 0});s.forEach((q,de)=>{const le=P.get(q.from),J=P.get(q.to);if(!le||!J)return;const ue=Fs(ee(le),ee(J),K[de]??0,R[de]??0),ve=oq(q.kind);W.add(ve.legend);const we=ve.dash.length>0?` stroke-dasharray="${ve.dash}"`:"";te+=`<path d="${ue.d}" fill="none" stroke="${ve.stroke}" stroke-width="${ve.sw}"${we} marker-end="url(#${ve.marker})"${_(`edges.${de}`)}/>`,H.push({lx:ue.lx,ly:ue.ly,...q.label!==void 0?{label:q.label}:{},path:`edges.${de}`})}),te+="</g>";const z=new Map;let Y=!1,V=!1;te+=`<g${he("nodes")}>`,i.forEach((q,de)=>{const le=N(q),J=(q.kind??"").toLowerCase(),ue=q.id===X,ve=m$[J]??J;if(rq.has(ve)){const dt=Vo(ve);dt.chip!==""&&!z.has(dt.chip)&&z.set(dt.chip,"shape"),dt.dashed&&(Y=!0),dt.fill==="paper-2"&&(V=!0),te+=`<g${_(`nodes.${de}`)}${Mo(q.col,q.row,q.w??1)}>${ex({kind:ve,name:q.name,...q.note!==void 0?{tech:q.note}:{}},le,void 0,ue)}</g>`;return}const we=sq(q.kind);we.chip!==""&&!z.has(we.chip)&&z.set(we.chip,"card"),we.dashed&&(Y=!0),we.fill==="paper-2"&&(V=!0);const $e=ue?"var(--accent)":we.primary?"var(--ink)":"var(--rule-solid)",je=ue||we.primary?1.5:1,De=ue?"var(--accent-tint)":we.fill==="paper-2"?"var(--paper-2)":"var(--paper)",Me=we.dashed?' stroke-dasharray="4 3"':"",Be=`<rect x="${le.x}" y="${le.y}" width="${le.w}" height="${le.h}" rx="6" fill="${De}" stroke="${$e}" stroke-width="${je}"${Me}/>`,Ge=ue?" c-accent":we.fill==="paper-2"?" c-muted":"",fe=we.chip!==""?`<text x="${le.x+12}" y="${le.y+14}" class="t-eyebrow${Ge}">${S(we.chip)}</text>`:"",ge=le.x+12,Ce=le.w-24,Fe=lt(q.name,Math.max(6,Math.floor(Ce/7)),2),qe=q.note!==void 0?lt(q.note,Math.max(6,Math.floor(Ce/6.2)),2):[],ze=15,Xe=12,pt=3,kt=le.y+(we.chip!==""?20:8),St=Fe.length*ze+(qe.length>0?pt+qe.length*Xe:0);let Nt=kt+(le.y+le.h-kt-St)/2+ze-4,Bt="";for(const dt of Fe)Bt+=`<text x="${ge}" y="${Nt.toFixed(1)}" class="t-name${ue?" c-accent":""}">${S(dt)}</text>`,Nt+=ze;if(qe.length>0){Nt+=pt-ze+Xe;for(const dt of qe)Bt+=`<text x="${ge}" y="${Nt.toFixed(1)}" class="t-sub">${S(dt)}</text>`,Nt+=Xe}te+=`<g${_(`nodes.${de}`)}${Mo(q.col,q.row,q.w??1)}>`+Be+fe+Bt+"</g>"}),te+="</g>";const{overlay:re,legend:Q}=Ws(H,i.map(q=>N(q)),{skin:!0});te+=re,te+="</svg>";const ne=[];for(const q of z.keys())ne.push({swatch:"chip",chip:q,label:aq[q]??q.toLowerCase()});Y&&ne.push({swatch:"node-dashed",label:"contract / external"}),V&&ne.push({swatch:"node-fill2",label:"passive (state, middleware, store)"}),W.has("uses")&&ne.push({swatch:"edge",label:"uses"}),W.has("implements")&&ne.push({swatch:"edge-implements",label:"implements"}),W.has("reads")&&ne.push({swatch:"edge-dashed",label:"reads / optional"}),W.has("async")&&ne.push({swatch:"edge-async",label:"async"}),W.has("network")&&ne.push({swatch:"edge-link",label:"network call"}),X!==void 0&&ne.push({swatch:"node-accent",label:"entry point"});const Z=ot(ne);return ct({tag:t,...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...Z.length>0?{legendHtml:Z}:{}},te+Q)}var aq={ENGINE:"engine / core",INTERFACE:"interface",STRATEGY:"strategy",ADAPTER:"adapter",CONTROLLER:"controller / route",GATEWAY:"gateway",SERVICE:"service / use case",CLIENT:"API client",REPOSITORY:"repository",WORKER:"worker / consumer",MIDDLEWARE:"middleware",MODEL:"model / entity",STATE:"state store",HOOK:"hook",DB:"database",QUEUE:"queue / bus",CACHE:"cache",EXT:"external"};function lq(e){return iq(e,"LOGIC")}function cq(e){return e==="phone"?200:380}function g$(e){const t=Math.max(1,e.rows??1);switch(e.type){case"header":return 34;case"subheader":return 26;case"text":return 16+(t-1)*12;case"button":return 42;case"input":case"search":return 42;case"image":return 96;case"avatar":return 52;case"card":return t*64+(t-1)*10;case"list":return t*40;case"nav":return 34;case"tabs":return 52;case"divider":return 14;case"badge":return 26;case"toggle":return 30;case"spacer":return 18*t;default:return 24}}var Vu='fill="var(--paper-2)" stroke="var(--rule-solid)" stroke-width="1"';function dq(e,t,n,s){const o=Math.max(1,e.rows??1),r=e.label??"",i=e.tone==="danger"?"var(--negative)":e.tone==="muted"?"var(--paper-2)":"var(--ink)",l=e.tone==="muted"?"wf-btn on-light":"wf-btn",d=e.tone==="muted"?' stroke="var(--rule-solid)" stroke-width="1"':"",u=e.align==="c"?t+s/2:e.align==="r"?t+s:t,p=e.align==="c"?"middle":e.align==="r"?"end":"start";switch(e.type){case"header":return`<text x="${u}" y="${n+22}" class="wf-h" fill="var(--charcoal)" text-anchor="${p}">${S(r||"Heading")}</text>`;case"subheader":return`<text x="${u}" y="${n+17}" class="wf-sub" fill="var(--gray)" text-anchor="${p}">${S(r||"Subheading")}</text>`;case"text":{let h="";for(let m=0;m<o;m++){const g=m===o-1?s*.66:s;h+=`<rect x="${t}" y="${n+m*12}" width="${g}" height="6" rx="3" fill="var(--rule)"/>`}return h}case"button":return`<rect x="${t}" y="${n}" width="${s}" height="34" rx="6" fill="${i}"${d}/><text x="${t+s/2}" y="${n+22}" class="${l}" text-anchor="middle">${S(r||"Button")}</text>`;case"input":case"search":{const h=e.type==="search"?`<circle cx="${t+16}" cy="${n+17}" r="5" fill="none" stroke="var(--gray)" stroke-width="1.4"/><path d="M${t+20} ${n+21} l4 4" stroke="var(--gray)" stroke-width="1.4"/>`:"",m=e.type==="search"?t+30:t+12;return`<rect x="${t}" y="${n}" width="${s}" height="34" rx="8" fill="var(--white)" stroke="var(--rule-solid)" stroke-width="1.2"/>`+h+`<text x="${m}" y="${n+21}" class="wf-ph-text">${S(r||"Type here…")}</text>`}case"image":return`<rect x="${t}" y="${n}" width="${s}" height="88" rx="8" ${Vu}/><path d="M${t} ${n+88} L${t+s*.4} ${n+40} L${t+s*.62} ${n+66} L${t+s*.78} ${n+50} L${t+s} ${n+88}" fill="none" stroke="var(--gray)" stroke-width="1.3"/><circle cx="${t+s*.74} " cy="${n+26}" r="7" fill="none" stroke="var(--gray)" stroke-width="1.3"/>`;case"avatar":return`<circle cx="${t+22}" cy="${n+22}" r="20" ${Vu}/><circle cx="${t+22}" cy="${n+17}" r="7" fill="var(--gray)"/><path d="M${t+9} ${n+40} a13 11 0 0 1 26 0" fill="var(--gray)"/>`+(r?`<text x="${t+52}" y="${n+27}" class="wf-sub" fill="var(--charcoal)">${S(r)}</text>`:"");case"card":{let h="";for(let g=0;g<o;g++){const v=n+g*74;h+=`<rect x="${t}" y="${v}" width="${s}" height="64" rx="10" fill="var(--white)" stroke="var(--rule-solid)" stroke-width="1.2"/><rect x="${t+12}" y="${v+12}" width="40" height="40" rx="8" ${Vu}/><rect x="${t+64}" y="${v+16}" width="${s-92}" height="7" rx="3.5" fill="var(--rule)"/><rect x="${t+64}" y="${v+34}" width="${(s-92)*.6}" height="6" rx="3" fill="var(--rule)"/>`}const m=r?`<text x="${t+64}" y="${n+30}" class="wf-ph-text"></text>`:"";return h+m}case"list":{let h="";for(let m=0;m<o;m++){const g=n+m*40;h+=`<circle cx="${t+16}" cy="${g+20}" r="12" ${Vu}/><rect x="${t+38}" y="${g+12}" width="${s-76}" height="6" rx="3" fill="var(--rule)"/><rect x="${t+38}" y="${g+24}" width="${(s-76)*.55}" height="5" rx="2.5" fill="var(--rule)"/><path d="M${t+s-14} ${g+15} l5 5 l-5 5" fill="none" stroke="var(--gray)" stroke-width="1.4"/>`+(m<o-1?`<line x1="${t+38}" y1="${g+40}" x2="${t+s}" y2="${g+40}" stroke="var(--light-gray)" stroke-width="1"/>`:"")}return h}case"nav":{const h=(r||"Home, Docs, Pricing, About").split(",").map(v=>v.trim());let m="",g=t;for(const v of h){const y=16+v.length*6.2;m+=`<rect x="${g}" y="${n+4}" width="${y}" height="22" rx="11" fill="var(--light-gray)"/><text x="${g+y/2}" y="${n+19}" class="wf-ph-text" text-anchor="middle">${S(v)}</text>`,g+=y+8}return m}case"tabs":{const h=(r||"Home, Search, Bell, Profile").split(",").map(v=>v.trim()),m=s/h.length;let g=`<line x1="${t}" y1="${n}" x2="${t+s}" y2="${n}" stroke="var(--rule)" stroke-width="1"${ut}/>`;return h.forEach((v,y)=>{const b=t+m*y+m/2;g+=`<circle cx="${b}" cy="${n+18}" r="8" fill="none" stroke="${y===0?i:"var(--gray)"}" stroke-width="1.6"/><text x="${b}" y="${n+42}" class="wf-tab" text-anchor="middle" fill="${y===0?i:"var(--gray)"}">${S(v)}</text>`}),g}case"divider":return`<line x1="${t}" y1="${n+7}" x2="${t+s}" y2="${n+7}" stroke="var(--rule)" stroke-width="1"${ut}/>`;case"badge":{const h=22+r.length*6.4;return`<rect x="${u-(p==="middle"?h/2:p==="end"?h:0)}" y="${n}" width="${h}" height="22" rx="11" fill="${i}"${d}/><text x="${u-(p==="middle"?0:p==="end"?h/2:-h/2)}" y="${n+15}" class="${l}" text-anchor="middle">${S(r||"New")}</text>`}case"toggle":return(r?`<text x="${t}" y="${n+19}" class="wf-sub" fill="var(--charcoal)">${S(r)}</text>`:"")+`<rect x="${t+s-44}" y="${n+6}" width="44" height="22" rx="11" fill="${i}"${d}/><circle cx="${t+s-16}" cy="${n+17}" r="8" fill="var(--paper)" stroke="var(--rule-solid)" stroke-width="1"/>`;case"spacer":return"";default:return""}}function uq(e,t){const n=e.device??"browser",s=cq(n),o=16,r=e.elements??[];let i=0;for(const j of r)i+=g$(j)+10;i=Math.max(i,80);const l=n==="phone",d=n==="browser",u=30,h=u+(d?26:0),m=l?24:0,g=s+o*2,v=i+o,y=h+v+m,b=l?30:14,E=l?2.4:1.8,$=`wfclip${t}`;let A="";if(l)A+=`<rect x="0" y="0" width="${g}" height="${u}" fill="var(--light-gray)"/>`,A+=`<rect x="${g/2-26}" y="6" width="52" height="9" rx="4.5" fill="var(--charcoal)"/>`,e.title&&(A+=`<text x="16" y="20" class="wf-status"${_(`screens.${t}.title`)}>${S(e.title)}</text>`),A+=`<text x="${g-16}" y="20" class="wf-status" text-anchor="end">100%</text>`;else if(A+=`<rect x="0" y="0" width="${g}" height="${u}" fill="var(--light-gray)"/>`,A+=`<line x1="0" y1="${u}" x2="${g}" y2="${u}" stroke="var(--rule)" stroke-width="1"${ut}/>`,A+='<circle cx="18" cy="15" r="5" fill="var(--rule-solid)"/><circle cx="34" cy="15" r="5" fill="var(--rule-solid)"/><circle cx="50" cy="15" r="5" fill="var(--rule-solid)"/>',e.title&&!d&&(A+=`<text x="${g/2}" y="20" class="wf-status" text-anchor="middle"${_(`screens.${t}.title`)}>${S(e.title)}</text>`),d){const j=e.url??e.title??"example.com";A+=`<rect x="68" y="${u+5}" width="${g-84}" height="16" rx="8" fill="var(--white)" stroke="var(--rule-solid)" stroke-width="1"/>`,A+=`<text x="78" y="${u+16}" class="wf-url"${_(`screens.${t}.url`)}>${S(j)}</text>`}let T=h+o;return A+=`<g${he(`screens.${t}.elements`)}>`,r.forEach((j,P)=>{A+=`<g${_(`screens.${t}.elements.${P}`)}>${dq(j,o,T,s)}</g>`,T+=g$(j)+10}),A+="</g>",l&&(A+=`<rect x="${g/2-30}" y="${y-15}" width="60" height="5" rx="2.5" fill="var(--charcoal)" opacity="0.55"/>`),{svg:`<g><defs><clipPath id="${$}"><rect x="0" y="0" width="${g}" height="${y}" rx="${b}"/></clipPath></defs><rect x="0" y="0" width="${g}" height="${y}" rx="${b}" fill="var(--paper)"/><g clip-path="url(#${$})">${A}</g><rect x="0" y="0" width="${g}" height="${y}" rx="${b}" fill="none" stroke="var(--ink)" stroke-width="${E}"/></g>`,width:g,height:y}}function pq(e){const t=e.screens??[],n=36,s=22,o=8,r=8,i=t.map((g,v)=>uq(g,v)),l=i.reduce((g,v)=>g+v.width,0)+n*Math.max(0,i.length-1),d=i.reduce((g,v)=>Math.max(g,v.height),0),u=l+o*2,p=d+s+r*2;let h=`<svg viewBox="0 0 ${u} ${p}" role="img"><title>${S(e.title??"UI mockup")}</title>`;h+=`<g${he("screens")}>`;let m=o;return i.forEach((g,v)=>{const y=t[v];h+=`<g transform="translate(${m}, ${r})"${_(`screens.${v}`)}>${g.svg}</g>`;const b=y?.label;if(b!==void 0&&b.length>0){const E=lt(b,Math.floor(g.width/6),2);h+=`<g${_(`screens.${v}.label`)}>`,E.forEach(($,A)=>{h+=`<text x="${m+g.width/2}" y="${r+d+16+A*12}" class="wf-caption" text-anchor="middle">${S($)}</text>`}),h+="</g>"}m+=g.width+n}),h+="</g>",h+="</svg>",ct({tag:"UI",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{}},h)}function Sf(e){const t=r=>r.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),n=/("(?:\\.|[^"\\])*")(\s*:)?|\b(true|false|null)\b|(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)/g;let s="",o=0;for(let r=n.exec(e);r!==null;r=n.exec(e)){s+=t(e.slice(o,r.index));const i=r[1],l=r[2],d=r[3],u=r[4];i!==void 0?s+=l!==void 0?`<span class="j-key">${t(i)}</span>${l}`:`<span class="j-str">${t(i)}</span>`:d!==void 0?s+=`<span class="j-kw">${t(d)}</span>`:u!==void 0?s+=`<span class="j-num">${t(u)}</span>`:s+=t(r[0]),o=n.lastIndex}return s+=t(e.slice(o)),s}function fq(e){const t=String(e).trim();return t.startsWith("3")?"ep-3xx":t.startsWith("4")?"ep-4xx":t.startsWith("5")?"ep-5xx":"ep-2xx"}var vA=e=>e===!0?' <span class="ep-req">required</span>':"";function hq(e){const t=e.map((n,s)=>`<tr${_(`params.${s}`)}><td class="ep-name"><span${_(`params.${s}.name`)}>${S(n.name)}</span>${vA(n.required)}</td><td class="ep-type">${S(n.in??"")}</td><td class="ep-type"${_(`params.${s}.type`)}>${S(n.type??"")}</td><td${_(`params.${s}.desc`)}>${S(n.desc??"")}</td></tr>`).join("");return`<table class="ep-table"><thead><tr><th>Name</th><th>In</th><th>Type</th><th>Description</th></tr></thead><tbody${he("params")}>${t}</tbody></table>`}function mq(e){const t=e.map((n,s)=>`<tr${_(`body.${s}`)}><td class="ep-name"><span${_(`body.${s}.name`)}>${S(n.name)}</span>${vA(n.required)}</td><td class="ep-type"${_(`body.${s}.type`)}>${S(n.type??"")}</td><td${_(`body.${s}.desc`)}>${S(n.desc??"")}</td></tr>`).join("");return`<table class="ep-table"><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody${he("body")}>${t}</tbody></table>`}function gq(e){const t=e.map((n,s)=>{const o=n.example!==void 0?`<tr><td></td><td colspan="2"><pre class="ep-ex"${_(`responses.${s}.example`)}>${Sf(n.example)}</pre></td></tr>`:"";return`<tr${_(`responses.${s}`)}><td><span class="ep-status ${fq(n.status)}"${_(`responses.${s}.status`)}>${S(String(n.status))}</span></td><td colspan="2"${_(`responses.${s}.desc`)}>${S(n.desc??"")}</td></tr>${o}`}).join("");return`<table class="ep-table"><thead><tr><th>Status</th><th colspan="2">Description</th></tr></thead><tbody${he("responses")}>${t}</tbody></table>`}function vq(e){const t=`<div class="ep-head"><span class="ep-method ${e.method.toLowerCase()}"${_("method")}>${S(e.method)}</span><span class="ep-path"${_("path")}>${S(e.path)}</span>`+(e.auth!==void 0?`<span class="ep-auth"${_("auth")}>${S(e.auth)}</span>`:"")+"</div>",n=[];e.title!==void 0&&n.push(`<div class="ep-title">${S(e.title)}</div>`),e.description!==void 0&&n.push(`<p class="ep-desc">${S(e.description)}</p>`);const s=e.params??[];s.length>0&&n.push(`<div class="ep-section">Parameters</div>${hq(s)}`);const o=e.body??[];o.length>0&&n.push(`<div class="ep-section">Request body</div>${mq(o)}`);const r=e.responses??[];return r.length>0&&n.push(`<div class="ep-section">Responses</div>${gq(r)}`),e.request!==void 0&&n.push(`<div class="ep-section">Example request</div><pre class="ep-ex"${_("request")}>${Sf(e.request)}</pre>`),e.response!==void 0&&n.push(`<div class="ep-section">Example response</div><pre class="ep-ex"${_("response")}>${Sf(e.response)}</pre>`),`<div class="endpoint">${t}<div class="ep-body">${n.join("")}</div></div>`}function yq(e){const t=e.attribution!==void 0?`<div class="pull-attr"${_("attribution")}>${S(e.attribution)}</div>`:"";return`<div class="pull"><p class="pull-text"${_("text")}>${vo(e.text)}</p>${t}</div>`}function xq(e,t){const n='<div class="layer-meta">'+(e.kicker!==void 0?`<div class="layer-kicker"${_(`items.${t}.kicker`)}>${S(e.kicker)}</div>`:"")+`<div class="layer-title"${_(`items.${t}.title`)}>${S(e.title)}</div>`+(e.source!==void 0?`<div class="layer-src">${S(e.source)}</div>`:"")+(e.question!==void 0?`<div class="layer-q">${S(e.question)}</div>`:"")+"</div>",s=e.body!==void 0?`<div class="layer-body"${_(`items.${t}.body`)}>${S(e.body)}</div>`:'<div class="layer-body"></div>';return`<div class="layer"${_(`items.${t}`)}><div class="layer-num">${t+1}</div>${n}${s}</div>`}function kq(e){const t=e.items??[];return`<div class="layer-stack"${he("items")}>${t.map((n,s)=>xq(n,s)).join("")}</div>`}var bq=["m-full","m-some","m-none"],wq={"m-full":{swatch:"node",label:"full"},"m-some":{swatch:"node-dashed",label:"partial"},"m-none":{swatch:"chip",chip:"—",label:"none"}};function $q(e){const t=e.trim().toLowerCase();return t===""||t==="—"||t==="-"||t==="none"||t==="no"||t==="✗"||t==="x"?"m-none":t==="full"||t==="all"||t==="admin"||t==="owner"||t==="yes"||t==="✓"||t==="write"||t==="manage"?"m-full":"m-some"}function Sq(e){const t=e.corner??"",n=`<tr><th class="mx-corner"${_("corner")}>${S(t)}</th>`+e.cols.map((d,u)=>`<th scope="col"${_(`cols.${u}`)}>${S(d)}</th>`).join("")+"</tr>",s=new Set,o=e.rows.map((d,u)=>{const p=e.cols.map((h,m)=>{const g=d.cells[m]??"",v=g.trim()===""?"—":g,y=$q(g);return s.add(y),`<td class="mx-cell ${y}"${_(`rows.${u}.cells.${m}`)}>${S(v)}</td>`}).join("");return`<tr${_(`rows.${u}`)}><th scope="row" class="mx-row"${_(`rows.${u}.label`)}>${S(d.label)}</th>${p}</tr>`}).join(""),r=e.title!==void 0?`<div class="mx-title">${S(e.title)}</div>`:"",i=e.description!==void 0?`<p class="mx-desc">${S(e.description)}</p>`:"",l=ot(bq.filter(d=>s.has(d)).map(d=>wq[d]));return`<div class="matrix">${r}${i}<div class="mx-scroll"><table class="mx-grid"><thead>${n}</thead><tbody${he("rows")}>${o}</tbody></table></div>${l}</div>`}function Eq(e){const t=e.separator??":",n=e.parts.map((i,l)=>{const d=`a-seg-${l%4+1}`;return`${l>0?`<span class="a-sep"${_("separator")}>${S(t)}</span>`:""}<span class="a-seg ${d}"${_(`parts.${l}.value`)}>${S(i.value)}</span>`}).join(""),s=e.parts.map((i,l)=>{const d=`a-seg-${l%4+1}`,u=i.note!==void 0?`<div class="a-note"${_(`parts.${l}.note`)}>${S(i.note)}</div>`:"";return`<div class="a-card"${_(`parts.${l}`)}><div class="a-label ${d}"${_(`parts.${l}.label`)}>${S(i.label)}</div><div class="a-value"${_(`parts.${l}.value`)}>${S(i.value)}</div>${u}</div>`}).join(`<span class="a-card-sep"${_("separator")}>`+S(t)+"</span>"),o=e.title!==void 0?`<div class="a-title">${S(e.title)}</div>`:"",r=e.description!==void 0?`<p class="a-desc">${S(e.description)}</p>`:"";return`<div class="anatomy">${o}${r}<div class="a-string">${n}</div><div class="a-cards"${he("parts")}>${s}</div></div>`}function Mq(e){const t=e.gates.map((r,i)=>{const l=i>0?'<span class="cp-op">∩</span>':"",d=r.kicker!==void 0?`<div class="cp-gate-kicker"${_(`gates.${i}.kicker`)}>${S(r.kicker)}</div>`:"",u=r.desc!==void 0?`<div class="cp-desc"${_(`gates.${i}.desc`)}>${S(r.desc)}</div>`:"",p=r.source!==void 0?`<div class="cp-gate-src">${S(r.source)}</div>`:"";return`${l}<div class="cp-gate cp-g${i%4+1}"${_(`gates.${i}`)}><div class="cp-gate-head">${d}<div class="cp-gate-label"${_(`gates.${i}.label`)}>${S(r.label)}</div></div>${u}${p}</div>`}).join(""),n=e.result!==void 0?`<span class="cp-eq">=</span><div class="cp-result"><div class="cp-result-kicker">Effective</div><div class="cp-result-label"${_("result")}>${S(e.result)}</div></div>`:"",s=e.title!==void 0?`<div class="cp-title">${S(e.title)}</div>`:"",o=e.description!==void 0?`<p class="cp-desc-top">${S(e.description)}</p>`:"";return`<div class="composition">${s}${o}<div class="cp-row"${he("gates")}>${t}${n}</div></div>`}var yA={location:'<path d="M12 21s-7-6.3-7-11a7 7 0 0 1 14 0c0 4.7-7 11-7 11z"/><circle cx="12" cy="10" r="2.5"/>',shield:'<path d="M12 3l7 3v5c0 4.5-3 8-7 10-4-2-7-5.5-7-10V6l7-3z"/><path d="M9 12l2 2 4-4"/>',grid:'<rect x="3" y="3" width="18" height="18" rx="2"/><path d="M3 9h18M3 15h18M9 3v18"/>',lock:'<rect x="3" y="11" width="18" height="10" rx="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/><circle cx="12" cy="16" r="1.5"/>',key:'<circle cx="8" cy="15" r="4"/><path d="M11 12l8-8M17 5l2 2M14 8l2 2"/>',user:'<circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 4-6 8-6s8 2 8 6"/>',clock:'<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>',check:'<path d="M20 6L9 17l-5-5"/>',database:'<ellipse cx="12" cy="5" rx="8" ry="3"/><path d="M4 5v14c0 1.7 3.6 3 8 3s8-1.3 8-3V5"/><path d="M4 12c0 1.7 3.6 3 8 3s8-1.3 8-3"/>',bolt:'<path d="M13 2L4 14h7l-1 8 9-12h-7z"/>',flag:'<path d="M5 21V4M5 4h11l-2 4 2 4H5"/>',doc:'<path d="M14 3H6v18h12V7z"/><path d="M14 3v4h4"/>',link:'<path d="M10 13a5 5 0 0 0 7 0l2-2a5 5 0 0 0-7-7l-1 1"/><path d="M14 11a5 5 0 0 0-7 0l-2 2a5 5 0 0 0 7 7l1-1"/>',eye:'<path d="M2 12s4-7 10-7 10 7 10 7-4 7-10 7S2 12 2 12z"/><circle cx="12" cy="12" r="3"/>',server:'<rect x="3" y="4" width="18" height="7" rx="2"/><rect x="3" y="13" width="18" height="7" rx="2"/><path d="M7 7.5h.01M7 16.5h.01"/>',layers:'<path d="M12 2l9 5-9 5-9-5 9-5z"/><path d="M3 12l9 5 9-5"/><path d="M3 17l9 5 9-5"/>'};function Aq(e,t){const n=e.accent!==void 0?` dv-${e.accent}`:"",s=e.icon!==void 0?yA[e.icon]??'<circle cx="12" cy="12" r="8"/>':"",o=s!==""?`<svg class="dv-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${s}</svg>`:"",r=e.body!==void 0?`<div class="dv-sub"${_(`items.${t}.body`)}>${S(e.body)}</div>`:"",i=e.tag!==void 0?`<div class="dv-tag"${_(`items.${t}.tag`)}>${S(e.tag)}</div>`:"";return`<div class="dv-card${n}"${_(`items.${t}`)}>${o}<div class="dv-title"${_(`items.${t}.title`)}>${S(e.title)}</div>${r}${i}</div>`}function Cq(e){const t=e.items??[],n=e.title!==void 0?`<div class="dv-head">${S(e.title)}</div>`:"",s=e.description!==void 0?`<p class="dv-desc">${S(e.description)}</p>`:"";return`<div class="drivers">${n}${s}<div class="dv-grid"${he("items")}>${t.map((o,r)=>Aq(o,r)).join("")}</div></div>`}function Nq(e,t){const n=e.tone??"neutral",s=n==="chosen"?" is-chosen":"",o=e.kicker!==void 0?`<span class="op-kicker">${S(e.kicker)}</span>`:"",r=e.how!==void 0?`<div class="op-how"${_(`items.${t}.how`)}>${S(e.how)}</div>`:"",i=e.pros!==void 0&&e.pros.length>0?`<ul class="op-list op-pros"${he(`items.${t}.pros`)}>${e.pros.map((u,p)=>`<li${_(`items.${t}.pros.${p}`)}>${S(u)}</li>`).join("")}</ul>`:"",l=e.cons!==void 0&&e.cons.length>0?`<ul class="op-list op-cons"${he(`items.${t}.cons`)}>${e.cons.map((u,p)=>`<li${_(`items.${t}.cons.${p}`)}>${S(u)}</li>`).join("")}</ul>`:"",d=e.verdict!==void 0?`<div class="op-verdict op-v-${n}"${_(`items.${t}.verdict`)}>${S(e.verdict)}</div>`:"";return`<div class="op-card${s}"${_(`items.${t}`)}><div class="op-head op-h-${n}">${o}<span class="op-title"${_(`items.${t}.title`)}>${S(e.title)}</span></div>${r}<div class="op-body">${i}${l}</div>${d}</div>`}function Tq(e){const t=e.items??[],n=e.title!==void 0?`<div class="op-headline">${S(e.title)}</div>`:"",s=e.description!==void 0?`<p class="op-desc">${S(e.description)}</p>`:"";return`<div class="options">${n}${s}<div class="op-grid"${he("items")}>${t.map((o,r)=>Nq(o,r)).join("")}</div></div>`}function _q(e,t){let n,s=_(`rows.${t}.value`);if(e.steps!==void 0&&e.steps.length>0){const o=e.steps.map((r,i)=>`<span class="sp-step"${_(`rows.${t}.steps.${i}`)}>${S(r)}</span>`).join('<span class="sp-arrow">&rarr;</span>');n=`<div class="sp-flow"${he(`rows.${t}.steps`)}>${o}</div>`,s=""}else n=S(e.value??"");return`<div class="sp-label"${_(`rows.${t}.label`)}>${S(e.label)}</div><div class="sp-val"${s}>${n}</div>`}function Lq(e){const t=e.rows??[],n=e.accent!==void 0?` sp-${e.accent}`:"",s=e.title!==void 0?`<div class="sp-head">${S(e.title)}</div>`:"",o=e.description!==void 0?`<p class="sp-desc">${S(e.description)}</p>`:"";return`<div class="spec">${s}${o}<div class="sp-grid${n}"${he("rows")}>${t.map((r,i)=>_q(r,i)).join("")}</div></div>`}function Iq(e){return`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${yA[e]??'<circle cx="12" cy="12" r="8"/>'}</svg>`}function jq(e,t,n){if(t==="check"){const s=e.done===!1;return`<span class="ls-mark ls-check${s?" ls-off":""}" aria-hidden="true">${s?"○":"✓"}</span>`}return t==="number"?`<span class="ls-mark ls-num" aria-hidden="true">${n+1}</span>`:t==="icon"?`<span class="ls-mark ls-icon" aria-hidden="true">${Iq(e.icon??"check")}</span>`:'<span class="ls-mark ls-bar" aria-hidden="true"></span>'}function Pq(e,t,n,s){const o=e.accent??s,r=o!==void 0?` ls-${o}`:"",i=e.text!==void 0?`<span class="ls-text"${_(`items.${n}.text`)}>${S(e.text)}</span>`:"";return`<li class="ls-item${r}"${_(`items.${n}`)}>`+jq(e,t,n)+`<span class="ls-body"><span class="ls-lead"${_(`items.${n}.lead`)}>${S(e.lead)}</span>${i}</span></li>`}function Oq(e){const t=e.style??"accent",n=e.title!==void 0?`<div class="ls-head">${S(e.title)}</div>`:"",s=e.description!==void 0?`<p class="ls-desc">${S(e.description)}</p>`:"",o=e.items.map((r,i)=>Pq(r,t,i,e.accent)).join("");return`<div class="list-block ls-style-${t}">${n}${s}<ul class="ls-list"${he("items")}>${o}</ul></div>`}function Vg(e,t){return`<span class="st-chip ${e}">${S(t)}</span>`}function Rq(e,t){const n=e.title??e.want??e.role??"Story",s=e.title!==void 0?"title":e.want!==void 0?"want":e.role!==void 0?"role":void 0,o=s!==void 0?_(`items.${t}.${s}`):"",r=e.id!==void 0?`<span class="st-id"${_(`items.${t}.id`)}>${S(e.id)}</span>`:"",i=[];e.points!==void 0&&i.push(Vg("st-points",`${e.points} pts`)),e.priority!==void 0&&i.push(Vg("st-prio",e.priority));for(const d of e.tags??[])i.push(Vg("st-tag",d));const l=i.length>0?`<span class="st-chips">${i.join("")}</span>`:"";return`<summary class="st-summary"><span class="st-caret" aria-hidden="true"></span><span class="st-sum-main">${r}<span class="st-sum-title"${o}>${S(n)}</span></span>`+l+"</summary>"}function Dq(e,t){if(e.role===void 0&&e.want===void 0&&e.soThat===void 0)return"";const n=[];return e.role!==void 0&&n.push(`<b>As</b> <span${_(`items.${t}.role`)}>${S(e.role)}</span>`),e.want!==void 0&&n.push(`<b>I want</b> <span${_(`items.${t}.want`)}>${S(e.want)}</span>`),e.soThat!==void 0&&n.push(`<b>so that</b> <span${_(`items.${t}.soThat`)}>${S(e.soThat)}</span>`),`<p class="st-narr">${n.join(", ")}.</p>`}function Bq(e,t){const n=e.criteria??[];if(n.length===0)return"";const s=n.map((o,r)=>{const i=[];return o.given!==void 0&&i.push(`<b>Given</b> ${S(o.given)}`),o.when!==void 0&&i.push(`<b>when</b> ${S(o.when)}`),o.then!==void 0&&i.push(`<b>then</b> ${S(o.then)}`),`<li${_(`items.${t}.criteria.${r}`)}>${i.join(", ")}.</li>`}).join("");return`<div class="st-ac-label">Acceptance criteria</div><ul class="st-ac"${he(`items.${t}.criteria`)}>${s}</ul>`}function zq(e,t){const n=e.links??[];if(n.length===0)return"";const s=n.map((o,r)=>{const i=o.label??o.ref??o.mode??"link";return o.ref!==void 0&&o.ref!==""?`<a class="st-link" data-ref="${S(o.ref)}" href="#${S($4(o.ref))}"${_(`items.${t}.links.${r}`)}>${S(i)}</a>`:`<span class="st-link"${_(`items.${t}.links.${r}`)}>${S(i)}</span>`}).join("");return`<div class="st-links"${he(`items.${t}.links`)}>${s}</div>`}function Fq(e,t){return`<details class="st-item"${e.open===!0?" open":""}${_(`items.${t}`)}>`+Rq(e,t)+`<div class="st-body">${Dq(e,t)}${Bq(e,t)}${zq(e,t)}</div></details>`}function qq(e){const t=e.title!==void 0?`<div class="st-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="st-desc">${S(e.description)}</p>`:"",s=e.items.map((o,r)=>Fq(o,r)).join("");return`<div class="stories">${t}${n}<div class="st-list"${he("items")}>${s}</div></div>`}function Gu(e,t,n){return t===void 0||t===""?"":`<div class="pt-row"><div class="pt-label">${e}</div><div class="pt-value"${_(n)}>${S(t)}</div></div>`}function Hq(e,t,n){if(t===void 0||t.length===0)return"";const s=t.map((o,r)=>`<span class="pt-chip"${_(`${n}.${r}`)}>${S(o)}</span>`).join("");return`<div class="pt-row"><div class="pt-label">${e}</div><div class="pt-value"><div class="pt-chips"${he(n)}>${s}</div></div></div>`}function Wq(e){const t=e.participants??[];if(t.length===0)return"";const n=t.map((s,o)=>{const r=s.role!==void 0?`<span class="pt-prole"${_(`participants.${o}.role`)}>${S(s.role)}</span>`:"";return`<li${_(`participants.${o}`)}><span class="pt-pname"${_(`participants.${o}.name`)}>${S(s.name)}</span>${r}</li>`}).join("");return`<div class="pt-row"><div class="pt-label">Participants</div><div class="pt-value"><ul class="pt-parts"${he("participants")}>${n}</ul></div></div>`}function Uq(e){const t=e.consequences;if(t===void 0)return"";const n=t.pros??[],s=t.cons??[];if(n.length===0&&s.length===0)return"";const o=(r,i,l,d)=>l.length===0?"":`<ul class="pt-cons-list ${r}"${he(d)}>${l.map((u,p)=>`<li${_(`${d}.${p}`)}><span class="pt-sign">${i}</span>${S(u)}</li>`).join("")}</ul>`;return`<div class="pt-row"><div class="pt-label">Consequences</div><div class="pt-value"><div class="pt-cons">${o("pt-pro","+",n,"consequences.pros")}${o("pt-con","−",s,"consequences.cons")}</div></div></div>`}function Kq(e){const t=e.category!==void 0?`<span class="pt-cat"${_("category")}>${S(e.category)}</span>`:"",n=`<div class="pt-header"><span class="pt-kicker">PATTERN</span><span class="pt-name"${_("name")}>${S(e.name)}</span>${t}</div>`,s=Gu("Intent",e.intent,"intent")+Hq("Forces",e.forces,"forces")+Gu("Solution",e.solution,"solution")+Gu("Structure",e.structure,"structure")+Wq(e)+Uq(e)+Gu("Notes",e.note,"note");return`<div class="pattern">${n}<div class="pt-rows">${s}</div></div>`}function Vq(e){const t={...e};delete t.type;const n=DA[e.type];return n!==void 0?n(t):""}function Gq(e,t){const n=e.accent!==void 0?` gl-${e.accent}`:"",s=e.title!==void 0?`<div class="gl-card-title"${_(`items.${t}.title`)}>${S(e.title)}</div>`:"",o=e.caption!==void 0?`<div class="gl-cap"${_(`items.${t}.caption`)}>${S(e.caption)}</div>`:"";if(e.block!==void 0)return`<div class="gl-cell${n}"${_(`items.${t}`)}>${s}${Vq(e.block)}${o}</div>`;if(e.code!==void 0){const r=e.title!==void 0||e.lang!==void 0?`<div class="code-header"><span>${S(e.title??"")}</span><span>${S(e.lang??"")}</span></div>`:"";return`<div class="gl-card gl-code${n}"${_(`items.${t}`)}>${r}<pre${_(`items.${t}.code`)}>${fh(e.code,e.lang)}</pre>${o}</div>`}return`<div class="gl-card${n}"${_(`items.${t}`)}>${s}${o}</div>`}function Yq(e){const t=e.title!==void 0?`<div class="gl-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="gl-desc">${S(e.description)}</p>`:"",o=` style="--gl-cols:${e.cols!==void 0&&e.cols>0?Math.floor(e.cols):2}"`,r=e.items.map((i,l)=>Gq(i,l)).join("");return`<div class="gallery">${t}${n}<div class="gl-grid"${o}${he("items")}>${r}</div></div>`}var xA=["#3d4656","#8a5a3c","#5f7f6e","#6b6f9c","#8a7a48"],Gg=xA.length,tx={dark:"#1f2937",light:"#ffffff",fallback:"#d1d5db"};function Qi(e,t,n){if(n==="red")return"var(--negative)";if(t<=1)return"var(--ink)";const s=(e%Gg+Gg)%Gg;return`var(--series-${s+1}, ${xA[s]??""})`}var gh={fill:"var(--ink)",stroke:"var(--ink)",dark:!0},Xq={fill:"var(--ink-2)",stroke:"var(--ink-2)",dark:!0},kA={fill:"var(--ink-3)",stroke:"var(--ink-3)",dark:!1},Qq={fill:"var(--muted)",stroke:"var(--muted)",dark:!0},bA={fill:"var(--paper-2)",stroke:"var(--ink)",dark:!1},wA=[gh,Xq,kA,bA],v$=[gh,kA,Qq,bA],Yg=wA.length;function Xn(e){const t=e.filter(n=>n!==void 0&&n!=="red").length;return e.map(n=>n==="red"?"negative":n!==void 0&&t===1?"focal":void 0)}function nx(e,t){if(t==="negative")return{fill:"var(--negative)",stroke:"var(--negative)",dark:!0};if(t==="focal")return{fill:"var(--accent)",stroke:"var(--accent)",dark:!0};const n=(e%Yg+Yg)%Yg;return wA[n]??gh}function sx(e,t){if(t!==void 0)return nx(e,t);const n=v$.length;return v$[(e%n+n)%n]??gh}var Zq={active:{fill:"var(--paper)",stroke:"var(--accent)",text:"var(--accent)",sw:1.75,dash:""},target:{fill:"var(--accent-tint)",stroke:"var(--accent)",text:"var(--ink)",sw:1.75,dash:""},visited:{fill:"var(--paper-2)",stroke:"var(--rule-solid)",text:"var(--muted)",sw:1,dash:""},muted:{fill:"var(--paper)",stroke:"var(--rule-solid)",text:"var(--soft)",sw:1,dash:"4 3"}},y$={fill:"var(--paper)",stroke:"var(--ink)",text:"var(--ink)",sw:1.5,dash:""};function vh(e){return e===void 0?y$:Zq[e]??y$}function yh(e){const t=e.dash.length>0?` stroke-dasharray="${e.dash}"`:"";return` fill="${e.fill}" stroke="${e.stroke}" stroke-width="${e.sw}"${t}`}var xh={active:{swatch:"node-accent-outline",label:"current"},target:{swatch:"node-accent",label:"target"},visited:{swatch:"node-fill2",label:"visited"},muted:{swatch:"node-dashed",label:"out of play"}},Tt=e=>Number.isFinite(e)&&e>0?e:0;function rt(e,t){return`${Math.round(e*100)/100}${t??""}`}function ox(e){if(!(e>0))return 1;const t=Math.pow(10,Math.floor(Math.log10(e/5))),n=[1,2,2.5,5,10].map(r=>r*t);let s=n[0]??1,o=1/0;for(const r of n){const i=Math.ceil(e/r-1e-9),l=i>=4&&i<=6?Math.abs(i-5):10+Math.abs(i-5);l<o&&(s=r,o=l)}return s}function x$(e){if(!(e>0)||!Number.isFinite(e))return 1;const t=Math.pow(10,Math.floor(Math.log10(e))),n=[1,2,2.5,5,10].map(r=>r*t);let s=n[0]??1,o=1/0;for(const r of n){const i=Math.abs(Math.log10(r)-Math.log10(e));i<o&&(s=r,o=i)}return s}function kh(e){const t=ox(e),n=Math.max(1,Math.ceil(e/t-1e-9));return Array.from({length:n+1},(s,o)=>Math.round(o*t*1e6)/1e6)}function w0(e){let t=Math.min(...e),n=Math.max(...e);if(t===n){const l=t===0?1:Math.abs(t)*.2;t-=l,n+=l}else{const l=(n-t)*.06;t-=l,n+=l}const s=ox(n-t),o=Math.floor(t/s)*s,r=Math.ceil(n/s)*s,i=[];for(let l=o;l<=r+s/2;l+=s)i.push(Math.round(l*1e6)/1e6);return{min:o,max:r,ticks:i}}var rn=e=>Math.round(e*10)/10;function oo(e,t){return`<svg viewBox="0 0 ${e} ${t}" role="img"><title>Chart</title>`}var Hc=6;function bh(e,t){const n=Math.max(3,Math.floor(t));return e.length>n?`${e.slice(0,n-1)}…`:e}function rx(e){return(e??[]).filter(t=>Number.isFinite(t))}var Up=e=>Math.round(e*1e9)/1e9;function $A(e,t){const n=rx(e),s=n.length;if(s===0)return{bins:[],width:1,n:0};const o=t!==void 0&&t>0?Math.max(1,Math.round(t)):Math.ceil(Math.log2(s))+1,r=Math.min(...n),i=Math.max(...n),l=i-r,d=l>0?x$(l/o):x$(Math.abs(r)/10||1),u=Up(Math.floor(r/d+1e-9)*d),p=Math.max(1,Math.ceil((i-u)/d-1e-9)),h=new Array(p).fill(0);for(const g of n){const v=Math.min(p-1,Math.max(0,Math.floor((g-u)/d+1e-9)));h[v]=(h[v]??0)+1}return{bins:h.map((g,v)=>({lo:Up(u+v*d),hi:Up(u+(v+1)*d),count:g})),width:d,n:s}}function $0(e){return e.length>0?e.reduce((t,n)=>t+n,0)/e.length:0}function Jq(e,t){if(e.length<2)return 0;const n=e.reduce((s,o)=>s+(o-t)*(o-t),0);return Math.sqrt(n/(e.length-1))}function SA(e,t,n,s=18,o=18){const r=Math.max(420,Math.min(760,110+e*n)),i=250,l=kh(t>0?t:1);return{width:r,height:i,x0:52,x1:r-o,y0:s,y1:i-32,yMax:l[l.length-1]??1,ticks:l}}function EA(e,t){let n="";return e.ticks.forEach((s,o)=>{const r=Math.round(e.y1-(e.y1-e.y0)*s/e.yMax);n+=`<line x1="${e.x0}" y1="${r}" x2="${e.x1}" y2="${r}" stroke="${o===0?"var(--rule-solid)":"var(--rule)"}" stroke-width="1"${ut}/>`,n+=`<text x="${e.x0-8}" y="${r+3}" class="t-sub c-soft" text-anchor="end">${S(rt(s,t))}</text>`}),n}function S0(e,t){return e==="negative"?"var(--negative)":e==="focal"?"var(--accent)":t}function eH(e){const t=rx(e.values),n=t.length===0&&(e.labels?.length??0)>0&&(e.series?.length??0)>0,s=e.series?.[0],o=n?e.labels??[]:[],r=n?void 0:$A(t,e.bins),i=n?o.map((E,$)=>Tt(s?.values[$]??0)):(r?.bins??[]).map(E=>E.count),l=i.length,d=Math.max(0,...i),u=e.max!==void 0&&e.max>0?e.max:d,p=SA(l,u,50),h=p.x1-p.x0,m=l>0?h/l:h,g=E=>Math.round(p.y1-(p.y1-p.y0)*Math.min(E,p.yMax)/p.yMax);let v=oo(p.width,p.height)+EA(p,void 0);const y=m>=22;if(v+=`<g${n?he("series"):_("values")}>`,i.forEach((E,$)=>{const A=rn(p.x0+m*$),T=g(E),N=Math.max(p.y1-T,E>0?1:0),j=r?.bins[$],P=j!==void 0?`${rt(j.lo,e.unit)} – ${rt(j.hi,e.unit)}: ${E}`:`${o[$]??""}: ${E}`,I=n?_(`series.0.values.${$}`):"";v+=`<g${I}>`,v+=`<rect x="${A}" y="${T}" width="${rn(m)}" height="${N}" fill="var(--ink)" stroke="var(--paper-2)" stroke-width="1"${E===0?' opacity="0.35"':""}><title>${S(P)}</title></rect>`,y&&E>0&&(v+=`<text x="${rn(A+m/2)}" y="${T-4}" class="t-arrow" text-anchor="middle">${S(String(E))}</text>`),v+="</g>"}),v+="</g>",n)v+=`<g${he("labels")}>`,o.forEach((E,$)=>{const A=bh(E,m/Hc),T=A!==E?`<title>${S(E)}</title>`:"";v+=`<text x="${rn(p.x0+m*($+.5))}" y="${p.y1+18}" class="t-sub" text-anchor="middle"${_(`labels.${$}`)}>${S(A)}${T}</text>`}),v+="</g>";else if(r!==void 0&&r.bins.length>0){const E=[...r.bins.map(T=>T.lo),r.bins[r.bins.length-1]?.hi??0],$=Math.max(...E.map(T=>rt(T,void 0).length))*Hc+8,A=Math.max(1,Math.ceil($/m));E.forEach((T,N)=>{const j=rn(p.x0+m*N);v+=`<line x1="${j}" y1="${p.y1}" x2="${j}" y2="${p.y1+4}" stroke="var(--rule-solid)" stroke-width="1"${ut}/>`;const P=N===E.length-1;N%A!==0&&!P||(v+=`<text x="${j}" y="${p.y1+18}" class="t-sub" text-anchor="${P?"end":N===0?"start":"middle"}">${S(rt(T,P?e.unit:void 0))}</text>`)})}const b=[{swatch:"fill",fill:"var(--ink)",label:"count per bin"}];if(r!==void 0&&r.bins.length>0&&t.length>0){const E=$0(t),$=r.bins[0]?.lo??0,A=r.bins[r.bins.length-1]?.hi??1,T=rn(p.x0+h*(E-$)/(A-$)),N=`mean ${rt(E,e.unit)}`,j=T+N.length*Hc+8>p.x1;v+=`<g><title>${S(`mean ${rt(E,e.unit)} · n = ${t.length}`)}</title>`,v+=`<line x1="${T}" y1="${p.y0-4}" x2="${T}" y2="${p.y1}" stroke="var(--accent)" stroke-width="1.25" stroke-dasharray="5 4"/>`,v+=`<text x="${j?T-5:T+5}" y="${p.y0+4}" class="t-arrow c-accent"${j?' text-anchor="end"':""}>${S(N)}</text>`,v+="</g>",b.push({swatch:"line-dashed",stroke:"var(--accent)",label:"mean"})}return v+="</svg>",{svg:v,legend:ot(b)}}function tH(e,t){if(e.mean!==void 0&&e.sd!==void 0&&e.sd>0)return{mean:e.mean,sd:e.sd,fitted:!1};const n=e.mean??$0(t),s=e.sd!==void 0&&e.sd>0?e.sd:Jq(t,$0(t));return{mean:n,sd:s>0&&Number.isFinite(s)?s:1,fitted:!0}}var nH=(e,t,n)=>Math.round((e-t)/n*10)/10;function sH(e){const t=rx(e.values),{mean:n,sd:s,fitted:o}=tH(e,t),r=(e.markers??[]).filter(Z=>Number.isFinite(Z.at)),i=Z=>Math.exp(-.5*((Z-n)/s)**2)/(s*Math.sqrt(2*Math.PI));let l=n-3.5*s,d=n+3.5*s;for(const Z of r)l=Math.min(l,Z.at-.25*s),d=Math.max(d,Z.at+.25*s);const u=ox(d-l),p=[];for(let Z=Math.ceil(l/u)*u;Z<=d+1e-9;Z+=u)p.push(Up(Z));const m=t.length>0&&(e.bins!==void 0||t.length>=20)?$A(t,e.bins):void 0,g=Z=>m!==void 0&&m.n>0?Z.count/(m.n*m.width):0,v=m!==void 0?Math.max(0,...m.bins.map(g)):0;m!==void 0&&(l=Math.min(l,m.bins[0]?.lo??l),d=Math.max(d,m.bins[m.bins.length-1]?.hi??d));const y=560,b=r.length>0?1:0,E=24,$=y-24,A=Z=>rn(E+($-E)*(Z-l)/(d-l)),T=r.map((Z,q)=>({m:Z,i:q,x:A(Z.at)})).sort((Z,q)=>Z.x-q.x),N=new Map;let j=-1/0,P=0;for(const Z of T){const q=Z.x-j<72?(P+1)%2:0;N.set(Z.i,q),j=Z.x,P=q}const I=[...N.values()].some(Z=>Z===1),O=b===0?34:I?82:56,C=O+170+32,D=O,F=C-32,U=Math.max(i(n),v)*1.05,X=Z=>rn(F-(F-D)*Z/U);let B=oo(y,C);B+=`<line x1="${E}" y1="${F}" x2="${$}" y2="${F}" stroke="var(--rule-solid)" stroke-width="1"${ut}/>`;for(const Z of p){const q=A(Z);B+=`<line x1="${q}" y1="${D}" x2="${q}" y2="${F}" stroke="var(--rule)" stroke-width="1"${ut}/>`,B+=`<text x="${q}" y="${F+18}" class="t-sub c-soft" text-anchor="middle">${S(rt(Z,e.unit))}</text>`}if(m!==void 0){B+=`<g${_("values")}>`;for(const Z of m.bins){const q=g(Z),de=A(Z.lo),le=rn(A(Z.hi)-de),J=X(q);B+=`<rect x="${de}" y="${J}" width="${le}" height="${rn(Math.max(F-J,0))}" fill="var(--ink)" fill-opacity="0.08" stroke="var(--rule-solid)" stroke-width="1"><title>${S(`${rt(Z.lo,e.unit)} – ${rt(Z.hi,e.unit)}: ${Z.count} of ${m.n}`)}</title></rect>`}B+="</g>"}const ee=(d-l)/140,H=Math.ceil(Math.max(n-l,d-n)/ee),W=[l];for(let Z=-H;Z<=H;Z++){const q=n+Z*ee;q>l&&q<d&&W.push(q)}W.push(d);const K=Z=>`${A(Z)},${X(i(Z))}`,R=(Z,q)=>{const de=W.filter(J=>J>Z&&J<q),le=[Z,...de,q].map(K);return`M ${A(Z)},${F} L ${le.join(" L ")} L ${A(q)},${F} Z`};B+=`<path d="${R(n-2*s,n+2*s)}" fill="var(--accent)" fill-opacity="0.1" stroke="none"><title>${S(`μ ± 2σ: ${rt(n-2*s,e.unit)} – ${rt(n+2*s,e.unit)} (95.4%)`)}</title></path>`,B+=`<path d="${R(n-s,n+s)}" fill="var(--accent)" fill-opacity="0.22" stroke="none"><title>${S(`μ ± 1σ: ${rt(n-s,e.unit)} – ${rt(n+s,e.unit)} (68.3%)`)}</title></path>`,B+=`<path class="chart-bell" d="M ${W.map(K).join(" L ")}" fill="none" stroke="var(--ink)" stroke-width="1.75" stroke-linejoin="round"><title>${S(`normal curve, μ = ${rt(n,e.unit)}, σ = ${rt(s,e.unit)}`)}</title></path>`,B+=`<line class="chart-bell-mean" x1="${A(n)}" y1="${X(i(n))}" x2="${A(n)}" y2="${F}" stroke="var(--rule-solid)" stroke-width="1" stroke-dasharray="2 3"><title>${S(`μ = ${rt(n,e.unit)}`)}</title></line>`;const z=Xn(r.map(Z=>Z.accent));r.length>0&&(B+=`<g${he("markers")}>`),r.forEach((Z,q)=>{const de=A(Z.at),le=N.get(q)??0,J=S0(z[q],"var(--ink)"),ue=nH(Z.at,n,s),ve=12+le*26,we=de<E+40?"start":de>$-40?"end":"middle";B+=`<g${_(`markers.${q}`)}><title>${S(`${Z.label} at ${rt(Z.at,e.unit)} · z = ${ue.toFixed(1)}`)}</title>`,B+=`<line x1="${de}" y1="${ve+16}" x2="${de}" y2="${F}" stroke="${J}" stroke-width="1.25" stroke-dasharray="5 4"/>`,B+=`<text x="${de}" y="${ve}" class="t-sub c-ink" text-anchor="${we}"${_(`markers.${q}.label`)}>${S(Z.label)}</text>`,B+=`<text x="${de}" y="${ve+12}" class="t-arrow" text-anchor="${we}">${S(`z = ${ue.toFixed(1)}`)}</text>`,B+="</g>"}),r.length>0&&(B+="</g>");const Y=T.some(Z=>Z.x<E+110&&(N.get(Z.i)??0)===0),V=Y?$-2:E+2,re=Y?"end":"start",Q=12;B+=`<text x="${V}" y="${Q}" class="t-sub c-ink" text-anchor="${re}">${S(`μ = ${rt(n,e.unit)}`)}</text>`,B+=`<text x="${V}" y="${Q+13}" class="t-sub c-ink" text-anchor="${re}">${S(`σ = ${rt(s,e.unit)}${o?` · n = ${t.length}`:""}`)}</text>`,B+="</svg>";const ne=[{swatch:"fill",fill:"var(--accent)",label:"±1 σ · 68%"},{swatch:"fill",fill:"var(--accent-tint)",label:"±2 σ · 95%"}];return r.length>0&&ne.push({swatch:"line-dashed",stroke:"var(--ink)",label:"marker (z-score)"}),m!==void 0&&ne.push({swatch:"node-fill2",label:"sample histogram (density)"}),{svg:B,legend:ot(ne)}}function oH(e){const t=e.boxes??[],n=t.length,s=t.flatMap($=>[$.min,$.q1,$.median,$.q3,$.max,...$.outliers??[]]).filter(Number.isFinite),o=w0(s.length>0?s:[0,1]),r=Math.max(420,Math.min(760,110+n*96)),i=260,l=52,d=r-18,u=18,p=i-32,h=$=>rn(p-(p-u)*($-o.min)/(o.max-o.min)),m=n>0?(d-l)/n:d-l,g=Math.min(56,Math.round(m*.5));let v=oo(r,i);for(const $ of o.ticks){const A=h($);v+=`<line x1="${l}" y1="${A}" x2="${d}" y2="${A}" stroke="${$===o.min?"var(--rule-solid)":"var(--rule)"}" stroke-width="1"${ut}/>`,v+=`<text x="${l-8}" y="${A+3}" class="t-sub c-soft" text-anchor="end">${S(rt($,e.unit))}</text>`}const y=Xn(t.map($=>$.accent));let b=0;v+=`<g${he("boxes")}>`,t.forEach(($,A)=>{const T=rn(l+m*(A+.5)),N=y[A],j=S0(N,"var(--ink)"),P=N==="focal"?"var(--accent-tint)":N==="negative"?"var(--negative-tint)":"var(--paper-2)",I=S0(N,"var(--accent)"),O=Math.min($.min,$.q1),C=Math.max($.max,$.q3),D=Math.min($.q1,$.q3),F=Math.max($.q1,$.q3),U=`${$.label} — min ${rt($.min,e.unit)} · q1 ${rt($.q1,e.unit)} · median ${rt($.median,e.unit)} · q3 ${rt($.q3,e.unit)} · max ${rt($.max,e.unit)}`,X=Math.round(g/2);v+=`<g${_(`boxes.${A}`)}><title>${S(U)}</title>`,v+=`<line x1="${T}" y1="${h(O)}" x2="${T}" y2="${h(D)}" stroke="${j}" stroke-width="1.25"/>`,v+=`<line x1="${T}" y1="${h(F)}" x2="${T}" y2="${h(C)}" stroke="${j}" stroke-width="1.25"/>`,v+=`<line x1="${T-X/2}" y1="${h(O)}" x2="${T+X/2}" y2="${h(O)}" stroke="${j}" stroke-width="1.25"/>`,v+=`<line x1="${T-X/2}" y1="${h(C)}" x2="${T+X/2}" y2="${h(C)}" stroke="${j}" stroke-width="1.25"/>`;const B=h(F),te=Math.max(rn(h(D)-B),1);v+=`<rect x="${T-g/2}" y="${B}" width="${g}" height="${te}" fill="${P}" stroke="${j}" stroke-width="1.25"/>`,v+=`<line class="chart-median" x1="${T-g/2}" y1="${h($.median)}" x2="${T+g/2}" y2="${h($.median)}" stroke="${I}" stroke-width="2.5"${_(`boxes.${A}.median`)}><title>${S(`${$.label} median ${rt($.median,e.unit)}`)}</title></line>`,($.outliers??[]).filter(Number.isFinite).forEach((W,K)=>{b++,v+=`<circle class="chart-outlier" cx="${T}" cy="${h(W)}" r="3" fill="var(--paper)" stroke="${j}" stroke-width="1.25"${_(`boxes.${A}.outliers.${K}`)}><title>${S(`${$.label} outlier ${rt(W,e.unit)}`)}</title></circle>`});const ee=bh($.label,m/Hc),H=ee!==$.label?`<title>${S($.label)}</title>`:"";v+=`<text x="${T}" y="${p+18}" class="t-sub" text-anchor="middle"${_(`boxes.${A}.label`)}>${S(ee)}${H}</text>`,v+="</g>"}),v+="</g></svg>";const E=[{swatch:"node-fill2",label:"box = q1 – q3"},{swatch:"line",stroke:"var(--accent)",label:"median"},{swatch:"line",stroke:"var(--ink)",label:"whiskers = min – max"}];return b>0&&E.push({swatch:"node-dot",label:"outlier"}),y.includes("focal")&&E.push({swatch:"node-accent",label:"focal"}),y.includes("negative")&&E.push({swatch:"node-negative",label:"negative"}),{svg:v,legend:ot(E)}}function rH(e){const n=(e.items??[]).map(($,A)=>({it:$,i:A,v:Tt($.value)})).sort(($,A)=>A.v-$.v||$.i-A.i),s=n.length,o=n.reduce(($,A)=>$+A.v,0),r=Math.max(0,...n.map($=>$.v)),i=e.max!==void 0&&e.max>0?e.max:r,l=SA(s,i,64,18,52),d=s>0?(l.x1-l.x0)/s:l.x1-l.x0,u=rn(Math.min(56,d*.6)),p=$=>Math.round(l.y1-(l.y1-l.y0)*Math.min($,l.yMax)/l.yMax),h=$=>rn(l.y1-(l.y1-l.y0)*$/100);let m=oo(l.width,l.height)+EA(l,e.unit);for(let $=0;$<=100;$+=20)m+=`<text x="${l.x1+8}" y="${h($)+3}" class="t-sub c-soft">${$}%</text>`;m+=`<line x1="${l.x0}" y1="${h(80)}" x2="${l.x1}" y2="${h(80)}" stroke="var(--muted)" stroke-width="1" stroke-dasharray="5 4"><title>80% of the total</title></line>`;let g=0,v=!0;const y=[],b=[];return m+=`<g${he("items")}>`,n.forEach(($,A)=>{g+=$.v;const T=o>0?g/o*100:0,N=o>0?$.v/o*100:0,j=rn(l.x0+d*A+(d-u)/2),P=p($.v),I=Math.max(l.y1-P,$.v>0?1:0),O=rn(j+u/2),C=v?"var(--accent)":"var(--muted)",D=`${$.it.label} — ${rt($.v,e.unit)} (${Math.round(N*10)/10}%) · cumulative ${Math.round(T*10)/10}%`;m+=`<g class="${v?"chart-vital":"chart-rest"}"${_(`items.${$.i}`)}>`,m+=`<rect x="${j}" y="${P}" width="${u}" height="${I}" fill="${C}"${I<=1?' opacity="0.35"':""}><title>${S(D)}</title></rect>`,m+=`<text x="${O}" y="${P-4}" class="t-arrow" text-anchor="middle">${S(rt($.v,e.unit))}</text>`;const F=bh($.it.label,d/Hc),U=F!==$.it.label?`<title>${S($.it.label)}</title>`:"";m+=`<text x="${O}" y="${l.y1+18}" class="t-sub" text-anchor="middle"${_(`items.${$.i}.label`)}>${S(F)}${U}</text>`,m+="</g>";const X=h(T);y.push(`${O},${X}`),b.push(`<circle class="chart-cum" cx="${O}" cy="${X}" r="3" fill="var(--paper)" stroke="var(--ink)" stroke-width="1.5"><title>${S(`cumulative ${Math.round(T*10)/10}% after ${$.it.label}`)}</title></circle>`),T>=80-1e-9&&(v=!1)}),m+="</g>",y.length>1&&(m+=`<polyline class="chart-cum-line" points="${y.join(" ")}" fill="none" stroke="var(--ink)" stroke-width="1.75" stroke-linejoin="round"/>`),m+=b.join(""),m+="</svg>",{svg:m,legend:ot([{swatch:"fill",fill:"var(--accent)",label:"bars = value · the vital few, to 80%"},{swatch:"fill",fill:"var(--muted)",label:"bars = value · the rest"},{swatch:"line-dot",label:"line = cumulative %"},{swatch:"line-dashed",label:"80% rule"}],"items")}}var Xg=28,k$=600,iH={1:[.16],2:[.28,.12],3:[.32,.2,.09]};function aH(e){const t=e.bullets??[],n=t.length,s=t.flatMap(N=>[Tt(N.value),...N.target!==void 0?[Tt(N.target)]:[],...(N.ranges??[]).map(Tt)]),o=e.max!==void 0&&e.max>0?e.max:Math.max(0,...s),r=kh(o>0?o:1),i=r[r.length-1]??1,l=Math.max(0,...t.map(N=>N.label.length)),d=Math.min(180,Math.max(64,l*7+14)),u=Math.floor((d-14)/7),p=d,h=k$-66,m=6,g=m+n*Xg+24,v=N=>rn(p+(h-p)*Math.min(N,i)/i);let y=oo(k$,g);const b=m+n*Xg+2;for(const N of r){const j=v(N);y+=`<line x1="${j}" y1="${m}" x2="${j}" y2="${b}" stroke="var(--rule)" stroke-width="1"${ut}/>`,y+=`<text x="${j}" y="${b+14}" class="t-sub c-soft" text-anchor="middle">${S(rt(N,e.unit))}</text>`}y+=`<line x1="${p}" y1="${b}" x2="${h}" y2="${b}" stroke="var(--rule-solid)" stroke-width="1"${ut}/>`;const E=Xn(t.map(N=>N.accent));let $=0,A=0;y+=`<g${he("bullets")}>`,t.forEach((N,j)=>{const P=m+j*Xg,I=P+14,O=Tt(N.value),C=`${N.label} — ${rt(O,e.unit)}${N.target!==void 0?` of target ${rt(N.target,e.unit)}`:""}`;y+=`<g${_(`bullets.${j}`)}><title>${S(C)}</title>`;const D=bh(N.label,u),F=D!==N.label?`<title>${S(N.label)}</title>`:"";y+=`<text x="0" y="${I+4}" class="t-name"${_(`bullets.${j}.label`)}>${S(D)}${F}</text>`;const U=[...(N.ranges??[]).map(Tt)].sort((H,W)=>H-W),X=iH[Math.min(U.length,3)]??[];U.length>0&&(y+=`<g${he(`bullets.${j}.ranges`)}>`);for(let H=U.length-1;H>=0;H--){const W=U[H]??0,K=X[Math.min(H,X.length-1)]??.1;$++,y+=`<rect class="chart-band" x="${p}" y="${P+4}" width="${rn(v(W)-p)}" height="20" fill="var(--muted)" fill-opacity="${K}"${_(`bullets.${j}.ranges.${H}`)}><title>${S(`${N.label} range ${H+1}: up to ${rt(W,e.unit)}`)}</title></rect>`}U.length>0&&(y+="</g>");const B=v(O),te=E[j]==="negative"?"var(--negative)":"var(--accent)";y+=`<rect class="chart-measure" x="${p}" y="${I-4}" width="${rn(Math.max(B-p,O>0?1:0))}" height="8" fill="${te}"${_(`bullets.${j}.value`)}><title>${S(`${N.label} ${rt(O,e.unit)}`)}</title></rect>`;let ee=B+6;if(N.target!==void 0&&Number.isFinite(N.target)){A++;const H=v(Tt(N.target));y+=`<rect class="chart-target" x="${rn(H-1)}" y="${P+5}" width="2" height="18" fill="var(--ink)"${_(`bullets.${j}.target`)}><title>${S(`${N.label} target ${rt(N.target,e.unit)}`)}</title></rect>`,H>=B-2&&H<ee+4&&(ee=H+6)}y+=`<text x="${rn(ee)}" y="${I+3.5}" class="t-arrow c-ink">${S(rt(O,e.unit))}</text>`,y+="</g>"}),y+="</g></svg>";const T=[{swatch:"fill",fill:"var(--accent)",label:"measure"}];return A>0&&T.push({swatch:"line",stroke:"var(--ink)",label:"target"}),$>0&&T.push({swatch:"node-fill2",label:"qualitative ranges (darkest = poorest)"}),E.includes("negative")&&T.push({swatch:"fill",fill:"var(--negative)",label:"negative"}),{svg:y,legend:ot(T,"bullets")}}var E0=' style="fill:var(--paper);stroke:none"';function wh(e,t,n=!1){const s=Math.max(420,Math.min(680,120+t*84)),o=240,r=e.series??[],i=r.flatMap(m=>m.values.map(Tt)),l=n?Array.from({length:t},(m,g)=>r.reduce((v,y)=>v+Tt(y.values[g]??0),0)):[],d=Math.max(0,...i,...l),u=e.max!==void 0&&e.max>0?e.max:d>0?d:1,p=kh(u),h=p[p.length-1]??u;return{width:s,height:o,x0:52,x1:s-18,y0:18,y1:o-32,yMax:h,ticks:p}}function $h(e,t,n,s){let o="";e.ticks.forEach((l,d)=>{const u=Math.round(e.y1-(e.y1-e.y0)*l/e.yMax);o+=`<line x1="${e.x0}" y1="${u}" x2="${e.x1}" y2="${u}" stroke="${d===0?"var(--rule-solid)":"var(--rule)"}" stroke-width="1"${ut}/>`,o+=`<text x="${e.x0-8}" y="${u+3}" class="t-sub c-soft" text-anchor="end">${S(rt(l,n))}</text>`});const r=Math.max(t.length,1),i=(e.x1-e.x0)/r;return s&&(o+=`<g${he("labels")}>`),t.forEach((l,d)=>{const u=Math.round(e.x0+i*d+i/2);o+=`<text x="${u}" y="${e.y1+18}" class="t-sub" text-anchor="middle"${s?_(`labels.${d}`):""}>${S(l)}</text>`}),s&&(o+="</g>"),o}function b$(e){const t=e.map((n,s)=>({swatch:"fill",fill:Qi(s,e.length,n.accent),label:n.label,path:`series.${s}`}));return ot(t,"series")}function MA(e,t){const n=Xn(e.map(o=>o.accent)),s=e.map((o,r)=>({swatch:"fill",fill:sx(r,n[r]).fill,label:`${o.label} — ${rt(Tt(o.value),t)}`,path:`items.${r}`}));return ot(s,"items")}function lH(e,t,n,s){const o=wh(e,t.length),r=Math.max(t.length,1),i=(o.x1-o.x0)/r,l=Math.min(18,i*.18),d=4,u=Math.max(n.length,1),p=Math.max(6,Math.round((i-l*2-d*(u-1))/u));let h=`<g${he("series")}>`;return n.forEach((m,g)=>{const v=Qi(g,n.length,m.accent);h+=`<g${_(`series.${g}`)}>`;for(let y=0;y<t.length;y++){const b=Tt(m.values[y]??0),E=Math.min(b,o.yMax),$=Math.round((o.y1-o.y0)*E/o.yMax),A=Math.round(o.x0+i*y+l+g*(p+d)),T=o.y1-$;h+=`<g${_(`series.${g}.values.${y}`)}>`,h+=`<rect x="${A}" y="${T}" width="${p}" height="${Math.max($,1)}" fill="${v}"${$===0?' opacity="0.35"':""}/>`,h+=`<text x="${A+Math.round(p/2)}" y="${T-4}" class="t-arrow" text-anchor="middle">${S(rt(b,e.unit))}</text>`,h+="</g>"}h+="</g>"}),h+="</g>",Sh(o)+$h(o,t,e.unit,s)+h+"</svg>"}function cH(e,t,n,s,o){const r=wh(e,t.length),i=Math.max(t.length,1),l=(r.x1-r.x0)/i,d=h=>Math.round(r.x0+l*h+l/2),u=h=>Math.round(r.y1-(r.y1-r.y0)*Math.min(Tt(h),r.yMax)/r.yMax);let p=`<g${he("series")}>`;return n.forEach((h,m)=>{const g=Qi(m,n.length,h.accent),v=h.values.slice(0,t.length).map((y,b)=>`${d(b)},${u(y)}`);if(v.length!==0){if(p+=`<g${_(`series.${m}`)}>`,s&&v.length>1){const y=d(0),b=d(v.length-1);p+=`<polygon points="${y},${r.y1} ${v.join(" ")} ${b},${r.y1}" fill="${g}" fill-opacity="0.12" stroke="none"/>`}v.length>1&&(p+=`<polyline points="${v.join(" ")}" fill="none" stroke="${g}" stroke-width="1.75" stroke-linejoin="round"/>`),h.values.slice(0,t.length).forEach((y,b)=>{p+=`<circle cx="${d(b)}" cy="${u(y)}" r="3" fill="var(--paper)" stroke="${g}" stroke-width="1.75"/>`}),p+="</g>"}}),p+="</g>",Sh(r)+$h(r,t,e.unit,o)+p+"</svg>"}function dH(e,t,n=!1){const r=Math.round(240),i=Math.round(236/2),l=74,d=26,u=l+d/2,p=n?0:l-d/2,h=t.reduce((v,y)=>v+Tt(y.value),0);let m=oo(480,236);const g=`<circle cx="${r}" cy="${i}" r="${u}" fill="none" stroke="var(--rule-solid)" stroke-width="1"/>`+(n?"":`<circle cx="${r}" cy="${i}" r="${p}" fill="none" stroke="var(--rule-solid)" stroke-width="1"/>`);if(h<=0)m+=n?`<circle cx="${r}" cy="${i}" r="${u}" fill="var(--paper)"${ut}/>`+g:`<circle cx="${r}" cy="${i}" r="${l}" fill="none" stroke="var(--paper)" stroke-width="${d}"${ut}/>`+g;else{let v=-90;const y=Xn(t.map(A=>A.accent)),b=[],E=A=>{const T=A*Math.PI/180,N=Math.round((r+(n?0:p-1)*Math.cos(T))*10)/10,j=Math.round((i+(n?0:p-1)*Math.sin(T))*10)/10,P=Math.round((r+(u+1)*Math.cos(T))*10)/10,I=Math.round((i+(u+1)*Math.sin(T))*10)/10;b.push(`<line x1="${N}" y1="${j}" x2="${P}" y2="${I}" stroke="var(--paper-2)" stroke-width="2"${ut}/>`)},$=[];m+=`<g${he("items")}>`,t.forEach((A,T)=>{const N=Tt(A.value);if(N===0)return;const j=N/h*360,P=sx(T,y[T]).fill,I=`<title>${S(`${A.label} — ${rt(N,e.unit)} (${Math.round(N/h*1e3)/10}%)`)}</title>`;if(j>=359.999)m+=n?`<circle cx="${r}" cy="${i}" r="${u}" fill="${P}"${_(`items.${T}`)}>${I}</circle>`:`<circle cx="${r}" cy="${i}" r="${l}" fill="none" stroke="${P}" stroke-width="${d}"${_(`items.${T}`)}/>`;else if(n){const O=v*Math.PI/180,C=(v+j)*Math.PI/180,D=Math.round((r+u*Math.cos(O))*10)/10,F=Math.round((i+u*Math.sin(O))*10)/10,U=Math.round((r+u*Math.cos(C))*10)/10,X=Math.round((i+u*Math.sin(C))*10)/10,B=j>180?1:0;m+=`<path d="M ${r} ${i} L ${D} ${F} A ${u} ${u} 0 ${B} 1 ${U} ${X} Z" fill="${P}" stroke="none"${_(`items.${T}`)}>${I}</path>`,E(v)}else{const O=v*Math.PI/180,C=(v+j)*Math.PI/180,D=Math.round(r+l*Math.cos(O)),F=Math.round(i+l*Math.sin(O)),U=Math.round(r+l*Math.cos(C)),X=Math.round(i+l*Math.sin(C)),B=j>180?1:0;m+=`<path d="M ${D} ${F} A ${l} ${l} 0 ${B} 1 ${U} ${X}" fill="none" stroke="${P}" stroke-width="${d}" stroke-linecap="butt"${_(`items.${T}`)}/>`,E(v)}N/h>=.08&&$.push({mid:v+j/2,text:`${A.label} ${rt(N,e.unit)}`}),v+=j}),m+="</g>",m+=g,b.length>1&&(m+=b.join("")),m+=uH($,r,i,u)}return n||(m+=`<text x="${r}" y="${i+2}" class="chart-total">${S(rt(h,e.unit))}</text>`,m+=`<text x="${r}" y="${i+20}" class="t-eyebrow" text-anchor="middle">TOTAL</text>`),m+="</svg>",{svg:m,legend:MA(t,e.unit)}}function uH(e,t,n,s){const o=e.map(i=>{const l=i.mid*Math.PI/180,d=Math.cos(l)>=0;return{text:i.text,right:d,x0:t+(s+2)*Math.cos(l),y0:n+(s+2)*Math.sin(l),x1:t+(s+12)*Math.cos(l),y:n+(s+12)*Math.sin(l)}});for(const i of[!0,!1]){const l=o.filter(u=>u.right===i).sort((u,p)=>u.y-p.y);let d=-1/0;for(const u of l){const p=Math.max(u.y,d+12);u.y=p,d=p}}const r=i=>Math.round(i*10)/10;return o.map(i=>{const l=i.right?Math.max(i.x1,t+s+8):Math.min(i.x1,t-s-8);return`<line x1="${r(i.x0)}" y1="${r(i.y0)}" x2="${r(l)}" y2="${r(i.y)}" stroke="var(--muted)" stroke-width="0.75"/><text x="${r(l+(i.right?4:-4))}" y="${r(i.y+3.5)}" class="t-sub c-ink" text-anchor="${i.right?"start":"end"}">${S(i.text)}</text>`}).join("")}function pH(e,t,n,s){const o=wh(e,t.length,!0),r=Math.max(t.length,1),i=(o.x1-o.x0)/r,l=Math.max(10,Math.min(56,i*.55));let d=`<g${he("series")}>`;for(let u=0;u<t.length;u++){const p=Math.round(o.x0+i*u+(i-l)/2);let h=o.y1;n.forEach((g,v)=>{const y=Tt(g.values[u]??0);if(y===0)return;const b=Math.round((o.y1-o.y0)*y/o.yMax);h-=b,d+=`<rect x="${p}" y="${h}" width="${Math.round(l)}" height="${b}" fill="${Qi(v,n.length,g.accent)}" stroke="var(--paper-2)" stroke-width="1"${ut}${_(`series.${v}.values.${u}`)}><title>${S(`${g.label} — ${rt(y,e.unit)}`)}</title></rect>`});const m=n.reduce((g,v)=>g+Tt(v.values[u]??0),0);m>0&&(d+=`<text x="${p+Math.round(l/2)}" y="${h-5}" class="t-arrow" text-anchor="middle">${S(rt(m,e.unit))}</text>`)}return d+="</g>",Sh(o)+$h(o,t,e.unit,s)+d+"</svg>"}function fH(e,t,n,s){const o=wh(e,t.length),r=Math.max(t.length,1),i=(o.x1-o.x0)/r,l=p=>Math.round(o.x0+i*p+i/2),d=p=>Math.round(o.y1-(o.y1-o.y0)*Math.min(Tt(p),o.yMax)/o.yMax);let u=`<g${he("series")}>`;return n.forEach((p,h)=>{const m=Qi(h,n.length,p.accent);u+=`<g${_(`series.${h}`)}>`,p.values.slice(0,t.length).forEach((g,v)=>{u+=`<circle cx="${l(v)}" cy="${d(g)}" r="5" fill="${m}" fill-opacity="0.2" stroke="${m}" stroke-width="1.5"><title>${S(`${p.label} — ${rt(Tt(g),e.unit)}`)}</title></circle>`}),u+="</g>"}),u+="</g>",Sh(o)+$h(o,t,e.unit,s)+u+"</svg>"}var M0=40;function hH(e){return e.length>M0?`${e.slice(0,M0-1)}…`:e}function mH(e,t,n){if(e===void 0)return 5;const s=Math.max(e,0);if(n<=t)return 8;const o=(Math.sqrt(s)-Math.sqrt(t))/(Math.sqrt(n)-Math.sqrt(t));return Math.round((4+o*14)*10)/10}var gH=(e,t)=>e.x0<t.x1&&t.x0<e.x1&&e.y0<t.y1&&t.y0<e.y1;function vH(e,t){const n=Math.max(t.x0,Math.min(e.px,t.x1)),s=Math.max(t.y0,Math.min(e.py,t.y1)),o=e.px-n,r=e.py-s;return o*o+r*r<e.r*e.r}function yH(e){return e==="negative"?"var(--negative)":e==="focal"?"var(--accent)":"var(--ink)"}function xH(e,t){const n=e.guides,s=560,o=320,r=e.yLabel!==void 0?70:56,i=s-20,l=18,d=o-(e.xLabel!==void 0?48:34),u=t.map(C=>C.x),p=t.map(C=>C.y);n?.x!==void 0&&u.push(n.x),n?.y!==void 0&&p.push(n.y);const h=w0(u),m=w0(p),g=C=>Math.round((r+(i-r)*(C-h.min)/(h.max-h.min))*10)/10,v=C=>Math.round((d-(d-l)*(C-m.min)/(m.max-m.min))*10)/10,y=t.filter(C=>C.size!==void 0).map(C=>Math.max(C.size??0,0)),b=y.length>0?Math.min(...y):0,E=y.length>0?Math.max(...y):0;let $=oo(s,o);for(const C of m.ticks){const D=v(C);$+=`<line x1="${r}" y1="${D}" x2="${i}" y2="${D}" stroke="${C===m.min?"var(--rule-solid)":"var(--rule)"}" stroke-width="1"${ut}/>`,$+=`<text x="${r-8}" y="${D+3}" class="t-sub c-soft" text-anchor="end">${S(rt(C,e.unit))}</text>`}for(const C of h.ticks){const D=g(C);$+=`<line x1="${D}" y1="${l}" x2="${D}" y2="${d}" stroke="${C===h.min?"var(--rule-solid)":"var(--rule)"}" stroke-width="1"${ut}/>`,$+=`<text x="${D}" y="${d+16}" class="t-sub c-soft" text-anchor="middle">${S(rt(C,void 0))}</text>`}if(e.xLabel!==void 0&&($+=`<text x="${Math.round((r+i)/2)}" y="${o-8}" class="t-eyebrow" text-anchor="middle"${_("xLabel")}>${S(e.xLabel)}</text>`),e.yLabel!==void 0){const C=Math.round((l+d)/2);$+=`<text x="14" y="${C}" class="t-eyebrow" text-anchor="middle" transform="rotate(-90 14 ${C})"${_("yLabel")}>${S(e.yLabel)}</text>`}if(n!==void 0){if(n.x!==void 0){const C=g(n.x);$+=`<line x1="${C}" y1="${l}" x2="${C}" y2="${d}" stroke="var(--muted)" stroke-width="1" stroke-dasharray="5 4"${_("guides.x")}/>`}if(n.y!==void 0){const C=v(n.y);$+=`<line x1="${r}" y1="${C}" x2="${i}" y2="${C}" stroke="var(--muted)" stroke-width="1" stroke-dasharray="5 4"${_("guides.y")}/>`}if(n.quadrants!==void 0&&n.quadrants.length===4){const[C,D,F,U]=n.quadrants,X=(B,te,ee,H,W)=>B===void 0||B===""?"":`<text x="${te}" y="${ee}" class="t-eyebrow" text-anchor="${H}"${_(`guides.quadrants.${W}`)}>${S(B)}</text>`;$+=X(C,r+8,l+12,"start",0),$+=X(D,i-8,l+12,"end",1),$+=X(F,r+8,d-8,"start",2),$+=X(U,i-8,d-8,"end",3)}}const A=t.map(C=>({px:g(C.x),py:v(C.y),r:mH(C.size,b,E)})),T=Xn(t.map(C=>C.accent));let N=`<g${he("points")}>`;t.forEach((C,D)=>{const F=A[D];if(F===void 0)return;const U=yH(T[D]),X=`${C.label!==void 0?`${C.label} — `:""}${rt(C.x,void 0)}, ${rt(C.y,e.unit)}${C.size!==void 0?` (${rt(C.size,void 0)})`:""}`;N+=`<circle cx="${F.px}" cy="${F.py}" r="${F.r}" fill="${U}" fill-opacity="0.18" stroke="${U}" stroke-width="1.5"${_(`points.${D}`)}><title>${S(X)}</title></circle>`}),N+="</g>";const j=[];let P="",I="";t.forEach((C,D)=>{const F=A[D];if(F===void 0||C.label===void 0||C.label==="")return;const U=hH(C.label),X=U.length*6,{px:B,py:te,r:ee}=F;let H=ee;for(const ne of A){const Z=Math.sqrt((ne.px-B)*(ne.px-B)+(ne.py-te)*(ne.py-te));Z<ne.r&&ne.r+Z>H&&(H=ne.r+Z)}const W=[{anchor:"start",lx:B+H+5,ly:te+3},{anchor:"end",lx:B-H-5,ly:te+3},{anchor:"middle",lx:B,ly:te-H-7},{anchor:"middle",lx:B,ly:te+H+12}],K=ne=>({x0:ne.anchor==="start"?ne.lx:ne.anchor==="end"?ne.lx-X:ne.lx-X/2,x1:ne.anchor==="start"?ne.lx+X:ne.anchor==="end"?ne.lx:ne.lx+X/2,y0:ne.ly-9,y1:ne.ly+2}),R=ne=>ne.x0>=2&&ne.x1<=s-2&&ne.y0>=2&&ne.y1<=o-2&&!A.some(Z=>vH(Z,ne))&&!j.some(Z=>gH(Z,ne)),z=W.find(ne=>R(K(ne)));if(z===void 0)return;const Y=K(z);j.push(Y);const V=z.lx-(B+ee+5),re=z.ly-(te+3);if(Math.sqrt(V*V+re*re)>14){const ne=Math.max(Y.x0,Math.min(B,Y.x1)),Z=Math.max(Y.y0,Math.min(te,Y.y1)),q=Math.sqrt((B-ne)*(B-ne)+(te-Z)*(te-Z));if(q>ee+2){const de=B-(B-ne)/q*(ee+1.5),le=te-(te-Z)/q*(ee+1.5);P+=`<line x1="${Math.round(ne*10)/10}" y1="${Math.round(Z*10)/10}" x2="${Math.round(de*10)/10}" y2="${Math.round(le*10)/10}" stroke="var(--muted)" stroke-width="0.75"/>`}}const Q=C.label.length>M0?`<title>${S(C.label)}</title>`:"";I+=`<text x="${Math.round(z.lx*10)/10}" y="${Math.round(z.ly*10)/10}" class="t-sub c-ink" style="text-anchor:${z.anchor}"${_(`points.${D}.label`)}>${S(U)}${Q}</text>`}),$+=P+N+I+"</svg>";const O=[];return T.some(C=>C===void 0)&&O.push({swatch:"fill",fill:"var(--ink)",label:"point"}),T.some(C=>C==="focal")&&O.push({swatch:"fill",fill:"var(--accent)",label:"focal"}),T.some(C=>C==="negative")&&O.push({swatch:"fill",fill:"var(--negative)",label:"negative"}),(n?.x!==void 0||n?.y!==void 0)&&O.push({swatch:"edge-dashed",label:"guide"}),{svg:$,legend:ot(O)}}function kH(e,t){const s=t.length<=1,o=s?246:264,r=Math.round(420/2),i=s?150:158,l=e.max!==void 0&&e.max>0?e.max:100,d=135,u=270,p=s?92:96,h=s?26:16,m=7,g=(j,P)=>{const I=P*Math.PI/180;return`${Math.round((r+j*Math.cos(I))*10)/10} ${Math.round((i+j*Math.sin(I))*10)/10}`},v=(j,P)=>{const I=u*Math.min(Math.max(P,0),1);if(I<=0)return"";const O=I>180?1:0;return`M ${g(j,d)} A ${j} ${j} 0 ${O} 1 ${g(j,d+I)}`};let y=oo(420,o);const b=Xn(t.map(j=>j.accent));y+=`<g${he("items")}>`,t.forEach((j,P)=>{const I=p-P*(h+m);if(I<=h)return;const O=sx(P,b[P]).fill,C=Tt(j.value)/l;y+=`<g${_(`items.${P}`)}>`,y+=`<path d="${v(I,1)}" fill="none" stroke="var(--paper)" stroke-width="${h}" stroke-linecap="round"${ut}/>`;const D=v(I,C);D!==""&&(y+=`<path d="${D}" fill="none" stroke="${O}" stroke-width="${h}" stroke-linecap="round"/>`),y+="</g>"}),y+="</g>";const E=t[0];if(E!==void 0){y+=`<text x="${r}" y="${i+(s?6:2)}" class="chart-total">${S(rt(Tt(E.value),e.unit))}</text>`;const j=s?E.desc??E.label:"OF "+rt(l,e.unit);y+=`<text x="${r}" y="${i+(s?26:20)}" class="t-eyebrow" text-anchor="middle">${S(j.toUpperCase())}</text>`}const $=p+h/2+13,A=Math.round($*Math.cos(135*Math.PI/180)),T=Math.round(i+$*Math.sin(135*Math.PI/180));y+=`<text x="${r+A}" y="${T}" class="t-sub c-soft" text-anchor="middle">0</text>`,y+=`<text x="${r-A}" y="${T}" class="t-sub c-soft" text-anchor="middle">${S(rt(l,e.unit))}</text>`,y+="</svg>";const N=t.length>1||t[0]?.desc!==void 0&&!s?MA(t,e.unit):"";return{svg:y,legend:N}}function bH(e,t,n){const r=Math.round(210),i=Math.round(280/2),l=100,d=t.length;if(d<3)return oo(420,60)+"</svg>";const u=n.flatMap(E=>E.values.slice(0,d).map(Tt)),p=u.length>0?Math.max(...u):0,h=e.max!==void 0&&e.max>0?e.max:p>0?p:1,m=kh(h),g=m[m.length-1]??h,v=E=>-Math.PI/2+2*Math.PI*E/d,y=(E,$)=>{const A=v(E);return[Math.round(r+$*Math.cos(A)),Math.round(i+$*Math.sin(A))]};let b=oo(420,280);m.forEach((E,$)=>{if($===0)return;const A=Array.from({length:d},(T,N)=>y(N,l*E/g).join(","));b+=`<polygon points="${A.join(" ")}" fill="none" stroke="${$===m.length-1?"var(--rule-solid)":"var(--rule)"}" stroke-width="1"${ut}/>`});for(let E=0;E<d;E++){const[$,A]=y(E,l);b+=`<line x1="${r}" y1="${i}" x2="${$}" y2="${A}" stroke="var(--rule)" stroke-width="1"${ut}/>`}return b+=`<g${he("labels")}>`,t.forEach((E,$)=>{const A=v($),[T,N]=y($,l+14),j=Math.cos(A),P=j>.3?"start":j<-.3?"end":"middle";b+=`<text x="${T}" y="${N+3}" class="t-sub" text-anchor="${P}"${_(`labels.${$}`)}>${S(E)}</text>`}),b+="</g>",b+=`<g${he("series")}>`,n.forEach((E,$)=>{const A=Qi($,n.length,E.accent),T=Array.from({length:d},(N,j)=>{const P=Math.min(Tt(E.values[j]??0),g);return y(j,l*P/g)});b+=`<g${_(`series.${$}`)}>`,b+=`<polygon points="${T.map(N=>N.join(",")).join(" ")}" fill="${A}" fill-opacity="0.1" stroke="${A}" stroke-width="1.75" stroke-linejoin="round"/>`,T.forEach(([N,j])=>{b+=`<circle cx="${N}" cy="${j}" r="2.5" fill="var(--paper)" stroke="${A}" stroke-width="1.5"/>`}),b+="</g>"}),b+="</g>",b+"</svg>"}function Sh(e){return oo(e.width,e.height)}var Yu=720,wH=150,fi=34,Xu=14;function hi(e,t){return`${(Math.round(e*100)/100).toLocaleString("en-US")} ${t??"ms"}`}var Qg=23;function $H(e){const t=e.desc!==void 0&&e.desc.length>0?`${e.label} — ${e.desc}`:e.label;return t.length<=Qg?t:e.label.length<=Qg?e.label:`${e.label.slice(0,Qg-1)}…`}function SH(e){const t=e.items??[],n=e.unit,s=t.reduce((j,P)=>j+Tt(P.value),0),o=e.budget!==void 0&&e.budget>0?e.budget:void 0,r=o!==void 0,i=r?22:6,l=t.length+(t.length>0?1:0),d=i+l*(fi+Xu)-(l>0?Xu:0)+6,u=wH+10,p=r?176:74,h=Yu-u-p,m=r&&s>0&&o<=s*1.4,g=m?Math.max(s,o):s>0?s:o??0,v=j=>g>0?Math.round(h*j/g):0;let y=`<svg viewBox="0 0 ${Yu} ${Math.max(d,40)}" role="img"><title>Budget waterfall</title>`,b=0,E=!1;const $=Xn(t.map(j=>j.accent)),A=$.includes("focal");if(y+=`<g${he("items")}>`,t.forEach((j,P)=>{const I=Tt(j.value),O=i+P*(fi+Xu),C=u+v(b),D=Math.max(v(I),I>0?2:0),F=nx(P,$[P]);if(y+=`<g${_(`items.${P}`)}>`,y+=`<text x="0" y="${O+22}" class="t-name"${_(`items.${P}.label`)}>${S($H(j))}</text>`,y+=`<rect x="${C}" y="${O}" width="${D}" height="${fi}" fill="${F.fill}" stroke="${F.stroke}" stroke-width="1"/>`,r&&b+I>o){E=!0;const U=Math.max(b,o),X=u+v(U),B=Math.max(v(b+I)-v(U),2);y+=`<rect x="${X}" y="${O}" width="${B}" height="${fi}" fill="var(--negative)"/>`}y+=`<text x="${C+D+6}" y="${O+22}" class="t-sub c-muted"${_(`items.${P}.value`)}>${S(hi(I,n))}</text>`,y+="</g>",b+=I}),y+="</g>",t.length>0){const j=i+t.length*(fi+Xu),P=Math.max(v(s),s>0?2:0);if(y+=`<rect x="${u}" y="${j}" width="${P}" height="${fi}" fill="var(--ink)"/>`,y+=`<text x="${u+10}" y="${j+21}" class="t-eyebrow"${E0}>TOTAL</text>`,y+=`<text x="${u+P+6}" y="${j+22}" class="t-sub c-ink">${S(hi(s,n))}</text>`,r){const I=Math.round((s-o)*100)/100,O=I>0,C=I===0?"on budget":O?`${hi(I,n)} over`:`${hi(-I,n)} under`,D=20+C.length*6,F=u+P+6+Math.round(hi(s,n).length*6.2)+8,U=O?"var(--negative)":"var(--rule-solid)",X=O?" c-negative":" c-muted";y+=`<rect x="${F}" y="${j+4}" width="${D}" height="${fi-8}" rx="2" fill="var(--paper)" stroke="${U}" stroke-width="1"/>`,y+=`<text x="${F+Math.round(D/2)}" y="${j+21}" class="t-arrow${X}" text-anchor="middle">${S(C)}</text>`}}if(r&&m){const j=u+v(o);y+=`<line x1="${j}" y1="${i-6}" x2="${j}" y2="${Math.max(d,40)-4}" stroke="var(--negative)" stroke-width="1.25" stroke-dasharray="5 4"/>`;const P=j>Yu-130;y+=`<text x="${P?j-6:j+6}" y="${i-8}" class="t-arrow c-negative"${P?' text-anchor="end"':""}${_("budget")}>budget: ${S(hi(o,n))}</text>`}else r&&(y+=`<text x="${Yu-4}" y="${i-8}" class="t-arrow c-negative" text-anchor="end"${_("budget")}>budget: ${S(hi(o,n))} — beyond scale →</text>`);y+="</svg>";const T=[];t.length>0&&T.push({swatch:"fill",fill:"var(--ink)",label:"step (darker first) · total"}),A&&T.push({swatch:"fill",fill:"var(--accent)",label:"focal step"}),r&&T.push({swatch:"edge-dashed",label:"budget cap"}),E&&T.push({swatch:"fill",fill:"var(--negative)",label:"over budget"});const N=ot(T);return ct({tag:"BUDGET",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...N.length>0?{legendHtml:N}:{}},y)}var Eh=560,Wc=54,dc=10,A0=18,EH=.28;function MH(e,t){return`${(Math.round(e*100)/100).toLocaleString("en-US")}${t!==void 0?` ${t}`:""}`}function w$(e,t){const n=t>0?Tt(e)/t:0;return Math.round(Eh*Math.max(n,EH))}function AH(e,t,n,s,o,r,i,l){const d=Eh/2,u=w$(e.value,o),p=t!==void 0?w$(t.value,o):u,h=nx(n,s),m=[`${d-u/2},${r}`,`${d+u/2},${r}`,`${d+p/2},${r+Wc}`,`${d-p/2},${r+Wc}`].join(" "),g=e.desc!==void 0&&e.desc.length>0,v=g?r+20:r+24,y=g?r+35:r+40,b=h.dark?` class="t-name"${E0}`:' class="t-name"',E=h.dark?` class="t-sub"${E0}`:' class="t-sub c-muted"',$=g?`<text x="${d}" y="${r+47}"${E} text-anchor="middle"${_(`${l}.${n}.desc`)}>${S(e.desc??"")}</text>`:"";return`<g${_(`${l}.${n}`)}><polygon points="${m}" fill="${h.fill}" stroke="${h.stroke}" stroke-width="1"/><text x="${d}" y="${v}"${b} text-anchor="middle"${_(`${l}.${n}.label`)}>${S(e.label)}</text><text x="${d}" y="${y}"${E} text-anchor="middle"${_(`${l}.${n}.value`)}>${S(MH(Tt(e.value),i))}</text>`+$+"</g>"}function CH(e,t,n){const s=Eh/2,o=Tt(e.value),r=Tt(t.value),i=o>0?Math.round(r/o*100):0,l=`↓ ${i}%`,d=34+String(i).length*7;return`<rect x="${s-d/2}" y="${n}" width="${d}" height="${A0}" rx="2" fill="var(--paper)" stroke="var(--rule-solid)" stroke-width="1"/><text x="${s}" y="${n+13}" class="t-arrow" text-anchor="middle">${S(l)}</text>`}function NH(e){const t=e.items!==void 0?"items":"stages",n=e.items??e.stages??[],s=Math.max(...n.map(p=>Tt(p.value)),0),o=Wc+dc+A0+dc,r=Math.max(n.length*Wc+(n.length-1)*(dc+A0+dc),0);let i=`<svg viewBox="0 0 ${Eh} ${r}" role="img"><title>Funnel</title>`;const l=Xn(n.map(p=>p.accent));i+=`<g${he(t)}>`,n.forEach((p,h)=>{const m=h*o;i+=AH(p,n[h+1],h,l[h],s,m,e.unit,t);const g=n[h+1];g!==void 0&&(i+=CH(p,g,m+Wc+dc))}),i+="</g>",i+="</svg>";const d=[];n.length>1&&d.push({swatch:"fill",fill:"var(--ink)",label:"stage (darker first)"}),l.includes("focal")&&d.push({swatch:"fill",fill:"var(--accent)",label:"focal stage"}),l.includes("negative")&&d.push({swatch:"fill",fill:"var(--negative)",label:"negative"}),n.length>1&&d.push({swatch:"chip",chip:"↓ %",label:"conversion from the stage above"});const u=ot(d);return ct({tag:"FUNNEL",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...u.length>0?{legendHtml:u}:{}},i)}function TH(e){const t=e.kind??"bar";if(t==="waterfall")return SH(e);if(t==="funnel")return NH(e);const n=e.labels??[],s=e.series??[];let o;if(t==="donut"||t==="pie")o=dH(e,e.items??[],t==="pie");else if(t==="histogram")o=eH(e);else if(t==="bell")o=sH(e);else if(t==="boxplot")o=oH(e);else if(t==="pareto")o=rH(e);else if(t==="bullet")o=aH(e);else if(t==="gauge")o=kH(e,e.items??[]);else if(t==="scatter"&&e.points!==void 0&&e.points.length>0)o=xH(e,e.points);else if(t==="radar")o={svg:bH(e,n,s),legend:b$(s)};else{const r=Math.max(n.length,...s.map(u=>u.values.length),0),i=n.length>0?n:Array.from({length:r},(u,p)=>String(p+1)),l=n.length>0;o={svg:t==="bar"?lH(e,i,s,l):t==="stacked"?pH(e,i,s,l):t==="scatter"?fH(e,i,s,l):cH(e,i,s,t==="area",l),legend:b$(s)}}return ct({tag:"CHART",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...o.legend.length>0?{legendHtml:o.legend}:{}},o.svg)}function _H(e){const t=e.width!==void 0&&Number.isFinite(e.width)&&e.width>0?` style="max-width:${Math.round(e.width)}px"`:"",n=e.alt??e.caption??"",s=e.caption!==void 0?`<figcaption class="fig-cap"${_("caption")}>${S(e.caption)}</figcaption>`:"";return`<figure class="fig"><img class="fig-img" src="${S(yf(e.src))}" alt="${S(n)}"${t}>`+s+"</figure>"}function LH(e,t){const n=e.body!==void 0?`<p class="stp-text"${_(`items.${t}.body`)}>${S(e.body)}</p>`:"",s=e.lang!==void 0?`<div class="stp-code-head">${S(e.lang)}</div>`:"",o=e.code!==void 0?`<div class="stp-code">${s}<pre><code>${fh(e.code,e.lang)}</code></pre></div>`:"",r=e.note!==void 0?`<p class="stp-note"${_(`items.${t}.note`)}>${S(e.note)}</p>`:"";return`<li class="stp-item"${_(`items.${t}`)}${hn(t)}><span class="stp-num" aria-hidden="true">${t+1}</span><div class="stp-body"><div class="stp-title"${_(`items.${t}.title`)}>${S(e.title)}</div>`+n+o+r+"</div></li>"}function IH(e){const t=e.title!==void 0?`<div class="stp-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="stp-desc">${S(e.description)}</p>`:"",s=e.items.map((o,r)=>LH(o,r)).join("");return`<div class="steps">${t}${n}<ol class="stp-list"${he("items")}>${s}</ol></div>`}function jH(e){const t=e.split(/\n{2,}/).map(n=>n.trim()).filter(n=>n.length>0);return t.length===0?"":t.map(n=>`<p>${S(n)}</p>`).join("")}function PH(e,t){return`<details class="fq-item"${e.open===!0?" open":""}${_(`items.${t}`)}><summary class="fq-summary"><span class="fq-caret" aria-hidden="true"></span><span class="fq-q"${_(`items.${t}.q`)}>${S(e.q)}</span></summary><div class="fq-a"${_(`items.${t}.a`)}>${jH(e.a)}</div></details>`}function OH(e){const t=e.title!==void 0?`<div class="fq-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="fq-desc">${S(e.description)}</p>`:"",s=e.items.map((o,r)=>PH(o,r)).join("");return`<div class="faq">${t}${n}<div class="fq-list"${he("items")}>${s}</div></div>`}function RH(e,t){return`<div class="env-given"${_(`assumptions.${t}`)}><div class="env-g-label"${_(`assumptions.${t}.label`)}>${S(e.label)}</div><div class="env-g-value"${_(`assumptions.${t}.value`)}>${S(e.value)}</div></div>`}function DH(e,t){return`<div class="env-step"${_(`steps.${t}`)}><span class="env-s-label"${_(`steps.${t}.label`)}>${S(e.label)}</span><span class="env-s-calc"${_(`steps.${t}.calc`)}>${S(e.calc)}</span><span class="env-s-arrow" aria-hidden="true">→</span><span class="env-s-result"${_(`steps.${t}.result`)}>${S(e.result)}</span></div>`}function BH(e){const t=e.title!==void 0?`<div class="env-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="env-desc">${S(e.description)}</p>`:"",s=e.assumptions.map((i,l)=>RH(i,l)).join(""),o=e.steps.map((i,l)=>DH(i,l)).join(""),r=e.result!==void 0?`<div class="env-result"${_("result")}><div class="env-r-label"${_("result.label")}>${S(e.result.label)}</div><div class="env-r-value"${_("result.value")}>${S(e.result.value)}</div></div>`:"";return'<div class="envelope">'+t+n+`<div class="env-card"><div class="env-givens"${he("assumptions")}>${s}</div><div class="env-steps"${he("steps")}>${o}</div>`+r+"</div></div>"}function zH(e){return e>.8?"slo-b-hot":e>=.5?"slo-b-warn":"slo-b-ok"}function FH(e){const t=Math.min(e,1),n=Math.round(t*1e3)/10,s=e>=1?"error budget exhausted":`${Math.round(t*100)}% of error budget used`;return`<div class="slo-budget"><div class="slo-track"><div class="slo-fill ${zH(e)}" style="width:${n}%"></div></div><div class="slo-caption">${S(s)}</div></div>`}function qH(e,t){const n=e.window!==void 0?`<span class="slo-window">${S(e.window)}</span>`:"",s=e.budget!==void 0&&e.budget>=1,o=e.current!==void 0?`<div class="slo-val"><span class="slo-v-label">Current</span><span class="slo-v-num ${s?"slo-bad":"slo-ok"}">${S(e.current)}</span></div>`:"",r=e.budget!==void 0?FH(e.budget):"";return`<div class="slo-item"${_(`items.${t}`)}><div class="slo-top"><span class="slo-name"${_(`items.${t}.name`)}>${S(e.name)}</span>`+n+`</div><p class="slo-sli"${_(`items.${t}.sli`)}>${S(e.sli)}</p><div class="slo-vals"><div class="slo-val"><span class="slo-v-label">Target</span><span class="slo-v-num"${_(`items.${t}.target`)}>${S(e.target)}</span></div>`+o+"</div>"+r+"</div>"}function HH(e){const t=e.title!==void 0?`<div class="slo-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="slo-desc">${S(e.description)}</p>`:"",s=e.items.map((o,r)=>qH(o,r)).join("");return`<div class="slo">${t}${n}<div class="slo-list"${he("items")}>${s}</div></div>`}function WH(e){const t=e.items.map((s,o)=>`<li class="swot-item"${_(`${e.path}.${o}`)}>${S(s)}</li>`).join(""),n=t!==""?`<ul class="swot-list">${t}</ul>`:"";return`<div class="swot-quad swot-${e.key}"${he(e.path)}><div class="swot-label">${S(e.label)}</div>`+n+"</div>"}function UH(e){const t=e.title!==void 0?`<div class="swot-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="swot-desc">${S(e.description)}</p>`:"",o=[{key:"s",path:"strengths",label:"Strengths",items:e.strengths??[]},{key:"w",path:"weaknesses",label:"Weaknesses",items:e.weaknesses??[]},{key:"o",path:"opportunities",label:"Opportunities",items:e.opportunities??[]},{key:"t",path:"threats",label:"Threats",items:e.threats??[]}].map(WH).join("");return`<div class="swot">${t}${n}<div class="swot-grid">${o}</div></div>`}function KH(e){return e==="done"||e==="on-track"?"okr-b-ok":e==="at-risk"?"okr-b-warn":e==="off-track"?"okr-b-bad":"okr-b-plain"}function VH(e,t){const n=Math.min(Math.max(e.progress,0),1),s=Math.round(n*1e3)/10,o=`${Math.round(n*100)}%`;return`<div class="okr-kr"${_(t)}><div class="okr-kr-text"${_(`${t}.kr`)}>${S(e.kr)}</div><div class="okr-kr-bar"><div class="okr-track"><div class="okr-fill ${KH(e.status)}" style="width:${s}%"></div></div><span class="okr-pct"${_(`${t}.progress`)}>${S(o)}</span>`+(e.status!==void 0?`<span class="okr-status okr-s-${e.status}"${_(`${t}.status`)}>${S(e.status)}</span>`:"")+"</div></div>"}function GH(e,t){const n=e.owner!==void 0?`<span class="okr-owner"${_(`items.${t}.owner`)}>${S(e.owner)}</span>`:"",s=e.krs.map((o,r)=>VH(o,`items.${t}.krs.${r}`)).join("");return`<div class="okr-item"${_(`items.${t}`)}><div class="okr-top"><span class="okr-objective"${_(`items.${t}.objective`)}>${S(e.objective)}</span>`+n+`</div><div class="okr-krs"${he(`items.${t}.krs`)}>${s}</div></div>`}function YH(e){const t=e.title!==void 0?`<div class="okr-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="okr-desc">${S(e.description)}</p>`:"",s=e.items.map((o,r)=>GH(o,r)).join("");return`<div class="okr">${t}${n}<div class="okr-list"${he("items")}>${s}</div></div>`}function AA(e){const t=e.trim().split(/\s+/).filter(o=>o.length>0),n=t[0]?.charAt(0)??"",s=t.length>1?t[t.length-1]?.charAt(0)??"":t[0]?.charAt(1)??"";return`${n}${s}`.toUpperCase()}function $$(e,t,n,s){if(s===void 0||s.length===0)return"";const o=s.map((r,i)=>`<li class="pa-li"${_(`${n}.${i}`)}>${S(r)}</li>`).join("");return`<div class="pa-section ${t}"><div class="pa-sec-label">${S(e)}</div><ul class="pa-list"${he(n)}>${o}</ul></div>`}function XH(e,t){if(t===void 0||t.length===0)return"";const n=t.map((s,o)=>`<span class="pa-tool"${_(`${e}.${o}`)}>${S(s)}</span>`).join("");return`<div class="pa-section"><div class="pa-sec-label">Tools</div><div class="pa-tools"${he(e)}>${n}</div></div>`}function QH(e,t){const n=e.accent!==void 0?` pa-${e.accent}`:"",s=e.role!==void 0?`<div class="pa-role"${_(`personas.${t}.role`)}>${S(e.role)}</div>`:"",o=e.quote!==void 0?`<blockquote class="pa-quote"${_(`personas.${t}.quote`)}>${S(e.quote)}</blockquote>`:"";return`<div class="pa-card${n}"${_(`personas.${t}`)}><div class="pa-id"><span class="pa-avatar">${S(AA(e.name))}</span><div class="pa-who"><div class="pa-name"${_(`personas.${t}.name`)}>${S(e.name)}</div>`+s+"</div></div>"+o+$$("Goals","pa-goals",`personas.${t}.goals`,e.goals)+$$("Frustrations","pa-frustrations",`personas.${t}.frustrations`,e.frustrations)+XH(`personas.${t}.tools`,e.tools)+"</div>"}function ZH(e){const t=e.title!==void 0?`<div class="pa-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="pa-desc">${S(e.description)}</p>`:"",s=e.personas.map((o,r)=>QH(o,r)).join("");return`<div class="persona">${t}${n}<div class="pa-grid"${he("personas")}>${s}</div></div>`}function JH(e,t){const n=e.type!==void 0?`<span class="cg-type cg-t-${e.type}"${_(`${t}.type`)}>${S(e.type)}</span>`:"";return`<div class="cg-item"${_(t)}>`+n+`<span class="cg-text"${_(`${t}.text`)}>${S(e.text)}</span></div>`}function eW(e,t){const n=e.tag==="breaking",s=e.date!==void 0?`<span class="cg-date"${_(`releases.${t}.date`)}>${S(e.date)}</span>`:"",o=e.tag!==void 0?`<span class="cg-tag cg-tag-${e.tag}"${_(`releases.${t}.tag`)}>${S(e.tag)}</span>`:"",r=e.items.map((i,l)=>JH(i,`releases.${t}.items.${l}`)).join("");return`<div class="cg-release"${_(`releases.${t}`)}><span class="cg-dot${n?" cg-dot-breaking":""}"></span><div class="cg-rel-head"><span class="cg-version${n?" cg-v-breaking":""}"${_(`releases.${t}.version`)}>${S(e.version)}</span>`+s+o+`</div><div class="cg-items"${he(`releases.${t}.items`)}>${r}</div></div>`}function tW(e){const t=e.title!==void 0?`<div class="cg-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="cg-desc">${S(e.description)}</p>`:"",s=e.releases.map((o,r)=>eW(o,r)).join("");return`<div class="changelog">${t}${n}<div class="cg-rail"${he("releases")}>${s}</div></div>`}function nW(e,t){const n=e.accent!==void 0?` tem-${e.accent}`:"",s=e.initials!==void 0&&e.initials.length>0?e.initials:AA(e.name),o=e.role!==void 0?`<div class="tem-role"${_(`members.${t}.role`)}>${S(e.role)}</div>`:"",r=e.focus!==void 0?`<div class="tem-focus"${_(`members.${t}.focus`)}>${S(e.focus)}</div>`:"";return`<div class="tem-card${n}"${_(`members.${t}`)}><span class="tem-avatar">${S(s)}</span><div class="tem-name"${_(`members.${t}.name`)}>${S(e.name)}</div>`+o+r+"</div>"}function sW(e){const t=e.title!==void 0?`<div class="tem-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="tem-desc">${S(e.description)}</p>`:"",s=e.members.map((o,r)=>nW(o,r)).join("");return`<div class="team">${t}${n}<div class="tem-grid"${he("members")}>${s}</div></div>`}var jr=["var(--paper-2)","var(--ink-3)","var(--ink-2)","var(--ink)"],oW=2,Zg="box-shadow:inset 0 0 0 1px var(--rule-solid)";function rW(e){return Math.min(jr.length-1,Math.max(0,Math.floor(e*jr.length)))}function Qu(e){return String(Math.round(e*100)/100)}function iW(e){const t=e.xLabels,n=e.rows,s=n.flatMap(E=>E.values.slice(0,t.length)).filter(E=>Number.isFinite(E)),o=s.length>0?Math.min(...s):0,r=s.length>0?Math.max(...s):1,i=e.min??o,l=e.max??r,d=l-i,u=E=>d<=0?.5:Math.min(1,Math.max(0,(E-i)/d)),p=new Set;let h=!1,m='<div class="hm-corner"></div>';m+=t.map((E,$)=>`<div class="hm-col t-eyebrow"${_(`xLabels.${$}`)}>${S(E)}</div>`).join(""),n.forEach((E,$)=>{m+=`<div class="hm-rowlabel t-name"${_(`rows.${$}.label`)}>${S(E.label)}</div>`;for(let A=0;A<t.length;A++){const T=E.values[A];if(T===void 0||!Number.isFinite(T)){m+=`<div class="hm-cell hm-blank" style="background:var(--paper);${Zg}"></div>`;continue}const N=e.unit!==void 0?` title="${S(`${Qu(T)} ${e.unit}`)}"`:"";if(T===0){h=!0,m+=`<div class="hm-cell" style="background:var(--paper);color:var(--ink);${Zg}"${N}${_(`rows.${$}.values.${A}`)}>0</div>`;continue}const j=rW(u(T));p.add(j);const P=j>=oW?"var(--paper)":"var(--ink)";m+=`<div class="hm-cell" style="background:${jr[j]};color:${P};${Zg}"${N}${_(`rows.${$}.values.${A}`)}>${S(Qu(T))}</div>`}});const g=e.unit!==void 0?` ${e.unit}`:"",v=[...p].sort((E,$)=>E-$).map(E=>{const $=i+d*E/jr.length,A=E===jr.length-1?l:i+d*(E+1)/jr.length,T=j=>d>=20?String(Math.round(j)):Qu(j),N=d<=0?`${Qu(i)}${g}`:`${T($)}–${T(A)}${g}`;return{swatch:"fill",fill:jr[E]??jr[0],label:N}});h&&v.unshift({swatch:"fill",fill:"var(--paper)",label:`0${g}`});const y=ot(v),b=`<div class="heatmap" style="overflow-x:auto"><div class="hm-grid" style="grid-template-columns:auto repeat(${t.length},minmax(44px,1fr))"${he("rows")}>${m}</div></div>`;return ct({tag:"HEATMAP",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...y.length>0?{legendHtml:y}:{}},b)}function aW(e){const t=Math.round(e*10)/10;return Number.isInteger(t)?String(t):t.toFixed(1)}function lW(e){const t=e.criteria,n=e.options,s=n.map(g=>t.reduce((v,y,b)=>v+(g.scores[b]??0)*(y.weight??1),0)),o=s.length>0?Math.max(...s):0,r=g=>s[g]===o,i=n.map((g,v)=>{const y=r(v),b=y?'<span class="sc-winner">WINNER</span>':"",E=g.note!==void 0?`<span class="sc-note"${_(`options.${v}.note`)}>${S(g.note)}</span>`:"";return`<th class="c${y?" sc-win":""}"${_(`options.${v}`)}>${S(g.label)}${b}${E}</th>`}).join(""),l=`<tr${he("options")}><th>Criteria</th>${i}</tr>`,d=t.map((g,v)=>{const y=g.weight??1,b=y!==1?`<span class="sc-weight"${_(`criteria.${v}.weight`)}>×${S(String(y))}</span>`:"",E=n.map(($,A)=>{const T=$.scores[v];return`<td class="c sc-score"${_(`options.${A}.scores.${v}`)}>${T!==void 0?S(String(T)):"—"}</td>`}).join("");return`<tr${_(`criteria.${v}`)}><td class="sc-crit"${_(`criteria.${v}.label`)}>${S(g.label)}${b}</td>${E}</tr>`}).join(""),p=`<tr class="sc-foot"><td>TOTAL</td>${s.map((g,v)=>`<td class="c sc-total${r(v)?" sc-win":""}">${S(aW(g))}</td>`).join("")}</tr>`,h=e.title!==void 0?`<div class="sc-head">${S(e.title)}</div>`:"",m=e.description!==void 0?`<p class="sc-desc">${S(e.description)}</p>`:"";return`<div class="scorecard">${h}${m}<div class="sc-scroll"><table class="sc-table"><thead>${l}</thead><tbody${he("criteria")}>${d}${p}</tbody></table></div></div>`}function cW(e){const{likelihood:t,impact:n}=e;return t==="high"&&n==="high"?"critical":t==="high"||n==="high"?"high":t==="low"&&n==="low"?"low":"medium"}function dW(e,t){const n=cW(e),s=e.mitigation!==void 0?`<p class="rk-mitigation"${_(`items.${t}.mitigation`)}><span class="rk-mit-label">Mitigation:</span> ${S(e.mitigation)}</p>`:"",o=e.owner!==void 0?`<span class="rk-owner"${_(`items.${t}.owner`)}>${S(e.owner)}</span>`:"",r=e.status!==void 0?`<span class="rk-status rk-st-${e.status}"${_(`items.${t}.status`)}>${S(e.status)}</span>`:"",i=o!==""||r!==""?`<span class="rk-chips">${o}${r}</span>`:"";return`<div class="rk-item"${_(`items.${t}`)}><div class="rk-top"><span class="rk-sev rk-sev-${n}">${n}</span><span class="rk-risk"${_(`items.${t}.risk`)}>${S(e.risk)}</span>`+i+`</div><div class="rk-meta">L: ${S(e.likelihood)} · I: ${S(e.impact)}</div>`+s+"</div>"}function uW(e){const t=e.title!==void 0?`<div class="rk-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="rk-desc">${S(e.description)}</p>`:"",s=e.items.map((o,r)=>dW(o,r)).join("");return`<div class="risk">${t}${n}<div class="rk-list"${he("items")}>${s}</div></div>`}var pW=tx.fallback,C0=tx.dark,fW=tx.light;function hW(e){const t=e.trim().replace(/^#/,"");if(/^[0-9a-fA-F]{3}$/.test(t)){const n=t.split("");return[parseInt(`${n[0]}${n[0]}`,16),parseInt(`${n[1]}${n[1]}`,16),parseInt(`${n[2]}${n[2]}`,16)]}return/^[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$/.test(t)?[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]:null}function mW(e){const t=n=>{const s=n/255;return s<=.03928?s/12.92:((s+.055)/1.055)**2.4};return .2126*t(e[0])+.7152*t(e[1])+.0722*t(e[2])}function gW(e){const t=hW(e);return t===null||mW(t)>.6?C0:fW}var vW="rgba(255,255,255,.86)",yW="rgba(0,0,0,.58)";function xW(e,t){const n=Fi(e.value,pW),s=gW(n),o=Fi(e.on,s),r=e.on===void 0?`;background:${o===C0?vW:yW}`:"",i=e.usage!==void 0?`<div class="pl-usage"${_(`colors.${t}.usage`)}>${S(e.usage)}</div>`:"";return`<div class="pl-card"${_(`colors.${t}`)}><div class="pl-swatch" style="background:${n}"><span class="pl-hex" style="color:${o}${r}"${_(`colors.${t}.value`)}>${S(e.value)}</span></div><div class="pl-meta"><div class="pl-name t-name"${_(`colors.${t}.name`)}>${S(e.name)}</div>`+i+"</div></div>"}function kW(e){const t=e.title!==void 0?`<div class="pl-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="pl-desc">${S(e.description)}</p>`:"",s=Math.min(6,Math.max(2,Math.floor(e.cols??4))),o=e.colors.map((r,i)=>xW(r,i)).join("");return`<div class="palette">${t}${n}<div class="pl-grid" style="--pl-cols:${s}"${he("colors")}>${o}</div></div>`}var bW="The quick brown fox jumps over the lazy dog",S$={display:"ts-f-display",body:"ts-f-body",mono:"ts-f-mono"};function uc(e){return String(Math.round(e*100)/100)}function wW(e,t,n){const s=e.weight??400,o=e.lineHeight??1.3,r=Math.min(64,Math.max(10,e.size)),i=S$[e.font??"body"]??S$.body,l=e.note!==void 0?`<div class="ts-note"${_(`items.${n}.note`)}>${S(e.note)}</div>`:"",d=`font-size:${uc(r)}px;font-weight:${uc(s)};line-height:${uc(o)}`;return`<div class="ts-row"${_(`items.${n}`)}><div class="ts-meta"><div class="ts-name"${_(`items.${n}.name`)}>${S(e.name)}</div><div class="ts-spec">${S(`${uc(e.size)}px / weight ${uc(s)}`)}</div>`+l+`</div><div class="ts-sample ${i}" style="${d}"${_("sample")}>${S(t)}</div></div>`}function $W(e){const t=e.title!==void 0?`<div class="ts-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="ts-desc">${S(e.description)}</p>`:"",s=e.sample??bW,o=e.items.map((r,i)=>wW(r,s,i)).join("");return`<div class="typescale">${t}${n}<div class="ts-rows"${he("items")}>${o}</div></div>`}function SW(e,t,n){const s=e.example!==void 0?`<div class="dd-ex"${_(`${t}.${n}.example`)}>${S(e.example)}</div>`:"";return`<div class="dd-item"${_(`${t}.${n}`)}><div class="dd-text"${_(`${t}.${n}.text`)}>${S(e.text)}</div>${s}</div>`}function E$(e,t,n,s,o){return`<div class="dd-card ${e}"><div class="dd-band"><span class="dd-sign">${t}</span><span class="dd-label">${S(n)}</span></div><div class="dd-list"${he(o)}>${s.map((r,i)=>SW(r,o,i)).join("")}</div></div>`}function EW(e){const t=e.title!==void 0?`<div class="dd-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="dd-desc">${S(e.description)}</p>`:"";return`<div class="dodont">${t}${n}<div class="dd-grid">`+E$("dd-do","✓","Do",e.dos,"dos")+E$("dd-dont","✕","Don't",e.donts,"donts")+"</div></div>"}var MW={stable:"inv-st-stable",beta:"inv-st-beta",experimental:"inv-st-experimental",deprecated:"inv-st-deprecated",planned:"inv-st-planned"};function AW(e,t){const n=e.tag!==void 0?`<span class="inv-tag"${_(`items.${t}.tag`)}>${S(e.tag)}</span>`:"",s=e.note!==void 0?`<div class="inv-note"${_(`items.${t}.note`)}>${S(e.note)}</div>`:"";return`<div class="inv-row"${_(`items.${t}`)}><div class="inv-main"><div class="inv-top"><span class="inv-name"${_(`items.${t}.name`)}>${S(e.name)}</span>${n}</div>`+s+`</div><span class="inv-status ${MW[e.status]??""}"${_(`items.${t}.status`)}>${S(e.status)}</span></div>`}function CW(e){const t=e.title!==void 0?`<div class="inv-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="inv-desc">${S(e.description)}</p>`:"",s=e.items.map((o,r)=>AW(o,r)).join("");return`<div class="inventory">${t}${n}<div class="inv-list"${he("items")}>${s}</div></div>`}var Ms=44,Jg=8;function NW(e){return e.length>5?`${e.slice(0,4)}…`:e}function TW(e){const t=e.items??[],n=e.showIndex??!0,s=t.length,o=t.some(b=>b.label!==void 0&&b.label.length>0),r=s>0&&e.window!==void 0?e.window:void 0,i=r!==void 0?20:0,l=n?16:0,d=6+i+l,u=o?26:0,p=d+Ms+u+8,h=Jg*2+Math.max(s,1)*Ms;let m=`<svg viewBox="0 0 ${h} ${p}" width="${h}" height="${p}" role="img"><title>Array</title>`;if(s===0)return m+=`<text x="${Jg}" y="${d+26}" class="t-sub c-soft">(empty)</text></svg>`,M$(e,m,"");const g=b=>Jg+b*Ms,v=new Set;let y=!1;if(m+=`<g${he("items")}>`,t.forEach((b,E)=>{const $=vh(b.tone);b.tone!==void 0?v.add(b.tone):y=!0;const A=g(E);m+=`<g${_(`items.${E}`)}>`,n&&(m+=`<text x="${A+Ms/2}" y="${d-5}" class="t-sub c-soft" text-anchor="middle">${E}</text>`),m+=`<rect x="${A}" y="${d}" width="${Ms}" height="${Ms}"${yh($)}/>`,m+=`<text x="${A+Ms/2}" y="${d+Ms/2+5}" class="ds-val" fill="${$.text}"${_(`items.${E}.value`)}>${S(NW(b.value))}</text>`,m+="</g>"}),m+="</g>",t.forEach((b,E)=>{if(b.label===void 0||b.label.length===0)return;const $=g(E)+Ms/2,A=d+Ms;m+=`<g${_(`items.${E}.label`)}>`,m+=`<path d="M${$-4},${A+9} L${$},${A+3} L${$+4},${A+9} z" fill="var(--ink)"/>`,m+=`<text x="${$}" y="${A+20}" class="t-badge c-ink" text-anchor="middle">${S(b.label)}</text>`,m+="</g>"}),r!==void 0){const b=Math.max(0,Math.min(s-1,Math.min(r.from,r.to))),E=Math.max(0,Math.min(s-1,Math.max(r.from,r.to))),$=g(b)-3,A=(E-b+1)*Ms+6;m+=`<rect x="${$}" y="${d-3}" width="${A}" height="${Ms+6}" rx="4" fill="none" stroke="var(--ink)" stroke-width="1.25" stroke-dasharray="4 3"${_("window")}/>`,r.label!==void 0&&r.label.length>0&&(m+=`<text x="${$+A}" y="${d-l-6}" text-anchor="end" class="t-eyebrow"${_("window.label")}>${S(r.label)}</text>`)}return m+="</svg>",M$(e,m,_W(y,v,r!==void 0))}function _W(e,t,n){const s=[];e&&s.push({swatch:"node",label:"cell"});for(const o of["active","target","visited","muted"])t.has(o)&&s.push(xh[o]);return n&&s.push({swatch:"chip",chip:"[ ]",label:"window"}),ot(s)}function M$(e,t,n){return ct({tag:"ARRAY",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...n.length>0?{legendHtml:n}:{}},t)}var Bo=56,Zu=40,zo=38,Ju=34,ev=8;function LW(e){return e.length>4?`${e.slice(0,3)}…`:e}var ep='fill="none" stroke="var(--muted)" stroke-width="1.5" marker-end="url(#skArrow)"';function IW(e){const t=e.nodes??[],n=(e.kind??"singly")==="doubly",s=e.nullEnd??!0,o=t.length,i=t.some(b=>b.label!==void 0&&b.label.length>0)?30:8,l=i+Zu/2,d=i+Zu+10,u=s?Ju+18:0,p=ev*2+Math.max(o,1)*Bo+Math.max(o-1,0)*Ju+u;let h=`<svg viewBox="0 0 ${p} ${d}" width="${p}" height="${d}" role="img"><title>Linked list</title>`;if(o===0)return h+=`<text x="${ev}" y="${l+4}" class="t-sub c-soft">(empty)</text></svg>`,A$(e,h,"");const m=b=>ev+b*(Bo+Ju);for(let b=0;b<o-1;b+=1){const E=m(b)+zo+(Bo-zo)/2,$=m(b+1);n?(h+=`<path d="M${E},${l-7} L${$-2},${l-7}" ${ep}/>`,h+=`<path d="M${$},${l+7} L${m(b)+Bo+2},${l+7}" ${ep}/>`):h+=`<path d="M${E},${l} L${$-2},${l}" ${ep}/>`}if(s){const b=m(o-1)+zo+(Bo-zo)/2,E=m(o-1)+Bo+Ju,$=n?l-7:l;h+=`<path d="M${b},${$} L${E-2},${$}" ${ep}/>`,h+=`<text x="${E+8}" y="${$+5}" class="t-name c-muted">∅</text>`}const g=new Set;let v=!1;h+=`<g${he("nodes")}>`,t.forEach((b,E)=>{const $=vh(b.tone);b.tone!==void 0?g.add(b.tone):v=!0;const A=m(E);h+=`<g${_(`nodes.${E}`)}><rect x="${A}" y="${i}" width="${Bo}" height="${Zu}" rx="4"${yh($)}/><line x1="${A+zo}" y1="${i+5}" x2="${A+zo}" y2="${i+Zu-5}" stroke="${$.stroke}" stroke-width="1"/><circle cx="${A+zo+(Bo-zo)/2}" cy="${l}" r="3" fill="${$.text}"/><text x="${A+zo/2}" y="${l+5}" class="ds-val" fill="${$.text}"${_(`nodes.${E}.value`)}>${S(LW(b.value))}</text></g>`}),h+="</g>",t.forEach((b,E)=>{if(b.label===void 0||b.label.length===0)return;const $=m(E)+Bo/2;h+=`<g${_(`nodes.${E}.label`)}>`,h+=`<text x="${$}" y="${i-14}" class="t-badge c-ink" text-anchor="middle">${S(b.label)}</text>`,h+=`<path d="M${$-4},${i-10} L${$+4},${i-10} L${$},${i-4} z" fill="var(--ink)"/>`,h+="</g>"}),h+="</svg>";const y=[];v&&y.push({swatch:"node",label:"node"});for(const b of["active","target","visited","muted"])g.has(b)&&y.push(xh[b]);return y.push({swatch:"edge",label:n?"next / prev":"next"}),A$(e,h,ot(y))}function A$(e,t,n){return ct({tag:"LIST",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...n.length>0?{legendHtml:n}:{}},t)}var pc=18,C$=52,N$=64,tv=10,T$=8;function jW(e){return e.length>4?`${e.slice(0,3)}…`:e}function PW(e){const t=e.nodes??[];if(t.length===0){const T=`<svg viewBox="0 0 220 44" width="220" height="44" role="img"><title>Binary tree</title><text x="${tv}" y="26" class="t-sub c-soft">(empty)</text></svg>`;return _$(e,T,"")}const n=new Map(t.map(T=>[T.id,T])),s=new Map,o=[];for(const T of t){if(T.parent===void 0||!n.has(T.parent)){o.push(T);continue}const N=s.get(T.parent)??{};T.side==="right"?N.right=T:N.left=T,s.set(T.parent,N)}const r=new Map;let i=0;const l=(T,N)=>{if(r.has(T.id))return r.get(T.id)?.x??0;const j=s.get(T.id)??{};let P;if(j.left!==void 0&&j.right!==void 0){const I=l(j.left,N+1),O=l(j.right,N+1);P=(I+O)/2}else j.left!==void 0?P=l(j.left,N+1)+.5:j.right!==void 0?P=l(j.right,N+1)-.5:(P=i,i+=1);return r.set(T.id,{node:T,x:P,depth:N}),P};o.forEach((T,N)=>{N>0&&(i+=.8),l(T,0)});const d=[...r.values()],u=Math.min(...d.map(T=>T.x)),p=Math.max(...d.map(T=>T.x)),h=Math.max(...d.map(T=>T.depth)),m=T=>tv+pc+Math.round((T.x-u)*C$),g=T=>T$+pc+T.depth*N$,v=tv*2+2*pc+Math.round((p-u)*C$),y=T$+2*pc+h*N$+8;let b=`<svg viewBox="0 0 ${v} ${y}" width="${v}" height="${y}" role="img"><title>Binary tree</title>`;for(const T of d){const N=T.node.parent;if(N===void 0)continue;const j=r.get(N);j!==void 0&&(b+=`<line x1="${m(j)}" y1="${g(j)}" x2="${m(T)}" y2="${g(T)}" stroke="var(--muted)" stroke-width="1.5"/>`)}const E=new Set;let $=!1;b+=`<g${he("nodes")}>`,t.forEach((T,N)=>{const j=r.get(T.id);if(j===void 0)return;const P=vh(T.tone);T.tone!==void 0?E.add(T.tone):$=!0,b+=`<g${_(`nodes.${N}`)}><circle cx="${m(j)}" cy="${g(j)}" r="${pc}"${yh(P)}/><text x="${m(j)}" y="${g(j)+4}" class="bt-val" fill="${P.text}"${_(`nodes.${N}.value`)}>${S(jW(T.value))}</text></g>`}),b+="</g>",b+="</svg>";const A=[];$&&A.push({swatch:"node",label:"node"});for(const T of["active","target","visited","muted"])E.has(T)&&A.push(xh[T]);return _$(e,b,ot(A))}function _$(e,t,n){return ct({tag:"TREE",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...n.length>0?{legendHtml:n}:{}},t)}var fc=34,Ca=30,tp=10,L$=24,np=16,Sr=6,OW=12,RW=320;function I$(e){return e.length>24?`${e.slice(0,23)}…`:e}function j$(e){return e.value!==void 0&&e.value.length>0?`${e.key}: ${e.value}`:e.key}function DW(e){const t=Math.max(0,Math.floor(e.buckets)),n=Math.min(t,OW),s=t-n,o=e.entries??[],r=new Map;o.forEach((y,b)=>{const E=Math.floor(y.bucket);if(E<0||E>=t)return;const $=r.get(E)??[];$.push({e:y,idx:b}),r.set(E,$)});const i=s>0?20:0,l=Math.max(n,1)*(Ca+tp)-(n>0?tp:0)+12+i,d=y=>Math.max(34,Math.round(I$(j$(y)).length*6.6)+18);let u=RW;for(let y=0;y<n;y+=1){let b=Sr+fc+np;for(const{e:E}of r.get(y)??[])b+=d(E)+np;u=Math.max(u,b+Sr)}let p=`<svg viewBox="0 0 ${u} ${l}" width="${u}" height="${l}" role="img"><title>Hash map</title>`;if(n===0)return p+=`<text x="${Sr}" y="${Ca/2+9}" class="t-sub c-soft">(empty)</text></svg>`,P$(e,p,"");const h=new Set;let m=!1,g=!1;p+=`<g${he("entries")}>`;for(let y=0;y<n;y+=1){const b=4+y*(Ca+tp),E=b+Ca/2;p+=`<rect x="${Sr}" y="${b}" width="${fc}" height="${Ca}" rx="2" fill="var(--paper-2)" stroke="var(--rule-solid)" stroke-width="1"/>`,p+=`<text x="${Sr+fc/2}" y="${E+4}" class="t-sub c-muted" text-anchor="middle">${y}</text>`;const $=r.get(y)??[];if($.length===0){p+=`<text x="${Sr+fc+12}" y="${E+4}" class="t-sub c-soft">—</text>`;continue}$.length>1&&(g=!0);let A=Sr+fc;$.forEach(({e:T,idx:N})=>{const j=d(T);p+=`<path d="M${A+1},${E} L${A+np-2},${E}" fill="none" stroke="var(--muted)" stroke-width="1.25" marker-end="url(#skArrow)"/>`,A+=np;const P=vh(T.tone);T.tone!==void 0?h.add(T.tone):m=!0,p+=`<g${_(`entries.${N}`)}>`,p+=`<rect x="${A}" y="${E-L$/2}" width="${j}" height="${L$}" rx="4"${yh(P)}/>`,p+=`<text x="${A+j/2}" y="${E+4}" class="hsh-key" fill="${P.text}">${S(I$(j$(T)))}</text>`,p+="</g>",A+=j})}if(p+="</g>",s>0){const y=4+n*(Ca+tp)+10;p+=`<text x="${Sr}" y="${y}" class="t-sub c-soft">+${s} more bucket${s===1?"":"s"}</text>`}p+="</svg>";const v=[{swatch:"node-fill2",label:"bucket"}];m&&v.push({swatch:"node",label:"entry"});for(const y of["active","target","visited","muted"])h.has(y)&&v.push(xh[y]);return g&&v.push({swatch:"edge",label:"collision chain"}),P$(e,p,ot(v))}function P$(e,t,n){return ct({tag:"HASH",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...n.length>0?{legendHtml:n}:{}},t)}var O$=660,mi=16,gi=118,hc=56,ss=232,Er=176,Na=512,BW=134,R$=10,zW=5,D$={fill:"var(--paper)",stroke:"var(--ink)"},B$={fill:"var(--accent-tint)",stroke:"var(--accent)"},z$={fill:"var(--paper-2)",stroke:"var(--rule-solid)"},sp={fill:"var(--paper-2)",stroke:"var(--ink)"};function op(e,t,n,s){return`<circle cx="${t}" cy="${n}" r="8" class="step-badge"/><text x="${t}" y="${n+3}" text-anchor="middle" class="t-badge">${e}</text><text x="${t+13}" y="${n+3.5}" class="al-lbl">${S(s)}</text>`}function CA(e){return lt(e.desc,22,2)}function F$(e){const t=CA(e).length;return t===0?26:28+t*13}function FW(e){const t=e.tools??[],n=t.slice(0,zW),s=t.length-n.length,o=n.length>0,r=e.memory,i=e.env??"User",l=lt(e.agent.note,28,3),d=e.agent.model!==void 0&&e.agent.model.length>0,u=Math.max(56,36+(d?22:0)+(l.length>0?l.length*13+8:0)),p=o?n.reduce((te,ee)=>te+F$(ee),0)+R$*(n.length-1)+(s>0?18:0):0,m=Math.round(10+Math.max(u,p,hc,64)/2),g=Math.round(m-u/2),v=Math.round(m-hc/2),y=Math.round(m-p/2),b=Math.max(g+u,v+hc,o?y+p:0),E=r??[],$=r!==void 0,A=176,T=$?Math.max(44,32+E.length*15):0,N=Math.round(ss+(Er-A)/2),j=b+46,P=$?j+T+8:b+12;let I=`<svg viewBox="0 0 ${O$} ${P}" width="${O$}" height="${P}" role="img"><title>Agent loop</title>`;I+=`<rect x="${mi}" y="${v}" width="${gi}" height="${hc}" rx="4" fill="${D$.fill}" stroke="${D$.stroke}" stroke-width="1.5"/>`+al("user",mi+Math.round(gi/2)-8,v+10,"var(--muted)")+`<text x="${mi+Math.round(gi/2)}" y="${v+hc-12}" text-anchor="middle" class="al-env"${_("env")}>${S(i)}</text>`,I+=`<rect x="${ss}" y="${g}" width="${Er}" height="${u}" rx="4" fill="${B$.fill}" stroke="${B$.stroke}" stroke-width="1.5"/>`,I+=al("agent",ss+12,g+12,"var(--accent)"),I+=`<text x="${ss+36}" y="${g+24}" class="al-name"${_("agent.name")}>${S(e.agent.name)}</text>`;let O=g+34;if(d){const te=e.agent.model??"",ee=Math.min(Er-24,16+te.length*6);I+=`<rect x="${ss+12}" y="${O}" width="${ee}" height="16" rx="3" fill="var(--paper)" stroke="var(--rule-solid)" stroke-width="1"/><text x="${ss+12+Math.round(ee/2)}" y="${O+11.5}" text-anchor="middle" class="al-chip"${_("agent.model")}>${S(te)}</text>`,O+=22}if(l.forEach((te,ee)=>{I+=`<text x="${ss+12}" y="${O+10+ee*13}" class="al-note">${S(te)}</text>`}),o){let te=y;I+=`<g${he("tools")}>`,n.forEach((ee,H)=>{const W=F$(ee);I+=`<g${_(`tools.${H}`)}>`,I+=`<rect x="${Na}" y="${te}" width="${BW}" height="${W}" rx="4" fill="${z$.fill}" stroke="${z$.stroke}" stroke-width="1"/>`,I+=`<text x="${Na+11}" y="${te+17}" class="al-tool-name"${_(`tools.${H}.name`)}>${S(ee.name)}</text>`,CA(ee).forEach((K,R)=>{I+=`<text x="${Na+11}" y="${te+31+R*13}" class="al-tool-desc">${S(K)}</text>`}),I+="</g>",te+=W+R$}),I+="</g>",s>0&&(I+=`<text x="${Na+11}" y="${te+2}" class="al-more">+${s} more</text>`)}const C=m-13,D=m+13;if(I+=`<line x1="${mi+gi}" y1="${C}" x2="${ss-4}" y2="${C}" class="al-edge" marker-end="url(#gArrow)"/>`,I+=op(1,mi+gi+18,C-13,"prompt"),I+=`<line x1="${ss}" y1="${D}" x2="${mi+gi+4}" y2="${D}" class="al-edge dashed" marker-end="url(#gSoft)"/>`,I+=op(4,mi+gi+18,D+17,"response"),o&&(I+=`<line x1="${ss+Er}" y1="${C}" x2="${Na-4}" y2="${C}" class="al-edge" marker-end="url(#gArrow)"/>`,I+=op(2,ss+Er+18,C-13,"tool call"),I+=`<line x1="${Na}" y1="${D}" x2="${ss+Er+4}" y2="${D}" class="al-edge dashed" marker-end="url(#gSoft)"/>`,I+=op(3,ss+Er+18,D+17,"result")),$){const te=ss+Math.round(Er/2);I+=`<line x1="${te}" y1="${g+u+3}" x2="${te}" y2="${j-8}" class="al-edge dashed" marker-start="url(#gSoft)" marker-end="url(#gSoft)"/>`,I+=`<text x="${te+8}" y="${Math.round((g+u+j)/2)+3}" class="al-lbl">read/write</text>`;const ee=7;I+=`<path d="M${N} ${j+ee} a ${Math.round(A/2)} ${ee} 0 0 1 ${A} 0 V ${j+T-ee} a ${Math.round(A/2)} ${ee} 0 0 1 -${A} 0 Z" fill="${sp.fill}" stroke="${sp.stroke}" stroke-width="1"/><ellipse cx="${N+Math.round(A/2)}" cy="${j+ee}" rx="${Math.round(A/2)}" ry="${ee}" fill="${sp.fill}" stroke="${sp.stroke}" stroke-width="1"/>`,I+=`<text x="${N+Math.round(A/2)}" y="${j+27}" text-anchor="middle" class="al-mem">memory</text>`,I+=`<g${he("memory")}>`,E.forEach((H,W)=>{const K=lt(H,28,1)[0]??"";I+=`<text x="${N+Math.round(A/2)}" y="${j+41+W*15}" text-anchor="middle" class="al-mem-item"${_(`memory.${W}`)}>${S(K)}</text>`}),I+="</g>"}I+="</svg>";const F=e.stop!==void 0&&e.stop.length>0?`<div class="al-foot"><span class="al-foot-label">stops when:</span> <span${_("stop")}>${S(e.stop)}</span></div>`:"",U=[o?"tool":"",$?"memory":""].filter(te=>te.length>0),X=[{swatch:"node",label:"environment"},{swatch:"node-accent",label:"agent"},...U.length>0?[{swatch:"node-fill2",label:U.join(" · ")}]:[],{swatch:"edge",label:o?"prompt · tool call":"prompt"},{swatch:"edge-dashed",label:o?"response · result":"response"}],B=ot(X);return ct({tag:"AGENT",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...B.length>0?{legendHtml:B}:{},...F.length>0?{footerHtml:F}:{}},I)}var qW={user:"USER",assistant:"ASSISTANT",tool:"TOOL",system:"SYSTEM"};function HW(e,t){const n=[];return e.thinking!==void 0&&e.thinking.length>0&&n.push(`<div class="tr-think"${_(`turns.${t}.thinking`)}>${S(e.thinking)}</div>`),e.tool!==void 0&&e.tool.length>0&&n.push(`<div class="tr-tool-name"${_(`turns.${t}.tool`)}>${S(e.tool)}</div>`),e.args!==void 0&&e.args.length>0&&n.push(`<div class="tr-io"><span class="tr-io-label">args:</span><code class="tr-mono">${S(e.args)}</code></div>`),e.result!==void 0&&e.result.length>0&&n.push(`<div class="tr-io"><span class="tr-io-label">→</span><code class="tr-mono">${S(e.result)}</code></div>`),e.text!==void 0&&e.text.length>0&&n.push(`<div class="tr-text"${_(`turns.${t}.text`)}>${S(e.text)}</div>`),`<div class="tr-turn tr-${e.role}"${_(`turns.${t}`)}><span class="tr-chip">${qW[e.role]??S(e.role).toUpperCase()}</span><div class="tr-card">${n.join("")}</div></div>`}function WW(e){const t=e.title!==void 0?`<div class="tr-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="tr-desc">${S(e.description)}</p>`:"",s=e.turns.map((o,r)=>HW(o,r)).join("");return`<div class="trace">${t}${n}<div class="tr-list"${he("turns")}>${s}</div></div>`}var UW=/\{\{[a-zA-Z0-9_.]+\}\}/g;function KW(e){return S(e).replace(UW,t=>`<span class="pr-var">${t}</span>`)}function VW(e,t){const n=e.label!==void 0&&e.label.length>0?`<span class="pr-label"${_(`segments.${t}.label`)}>— ${S(e.label)}</span>`:"";return`<div class="pr-seg pr-${e.kind}"${_(`segments.${t}`)}><div class="pr-kicker">${e.kind.toUpperCase()}${n}</div><div class="pr-text"${_(`segments.${t}.text`)}>${KW(e.text)}</div></div>`}function GW(e){const t=e.title!==void 0?`<div class="pr-head">${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="pr-desc">${S(e.description)}</p>`:"",s=e.segments.map((i,l)=>VW(i,l)).join(""),o=e.vars??[],r=o.length>0?`<div class="pr-vars"${he("vars")}>${o.map((i,l)=>`<div class="pr-var-row"${_(`vars.${l}`)}><span class="pr-var"${_(`vars.${l}.name`)}>{{${S(i.name)}}}</span>`+(i.desc!==void 0&&i.desc.length>0?`<span class="pr-var-desc"${_(`vars.${l}.desc`)}>${S(i.desc)}</span>`:"")+"</div>").join("")}</div>`:"";return`<div class="prompt">${t}${n}<div class="pr-list"${he("segments")}>${s}</div>${r}</div>`}var q$={navy:"var(--series-2)",blue:"var(--series-2)",teal:"var(--series-1)",green:"var(--series-1)",amber:"var(--series-3)",purple:"var(--series-5)",red:"var(--negative)",gray:"var(--ink-3)"},H$=["var(--series-1)","var(--series-2)","var(--series-3)","var(--series-4)","var(--series-5)"];function W$(e,t){return e!==void 0&&q$[e]!==void 0?q$[e]:H$[t%H$.length]??"var(--series-1)"}function nv(e,t,n){const s=10+n.length*6.2;return`<rect x="${Math.round(e-s/2)}" y="${t-8}" width="${Math.round(s)}" height="16" rx="3" class="ctx-seg-mask"/><text x="${e}" y="${t+3.5}" text-anchor="middle" class="ctx-seg-label">${S(n)}</text>`}var vi=820,yi=34,mc=8,As=22,gc=e=>Number.isFinite(e)&&e>0?e:0,rp=e=>Math.round(e).toLocaleString("en-US");function sv(e,t,n,s,o,r){return`M${e+o} ${n} H ${e+t-r}`+(r>0?` a ${r} ${r} 0 0 1 ${r} ${r}`:"")+` V ${n+s-r}`+(r>0?` a ${r} ${r} 0 0 1 -${r} ${r}`:"")+` H ${e+o}`+(o>0?` a ${o} ${o} 0 0 1 -${o} -${o}`:"")+` V ${n+o}`+(o>0?` a ${o} ${o} 0 0 1 ${o} -${o}`:"")+" Z"}function YW(e){const t=e.unit??"tokens",n=gc(e.window),s=e.segments.map((v,y)=>({seg:v,si:y})).filter(({seg:v})=>gc(v.tokens)>0),o=s.reduce((v,{seg:y})=>v+gc(y.tokens),0),r=n>0&&o>n,i=n>0&&o<n?n-o:0,l=Math.max(n,o,1),d=v=>Math.round(vi*v/l),u=As+yi+8;let p=`<svg viewBox="0 0 ${vi} ${u}" width="${vi}" height="${u}" role="img"><title>Context window</title>`;p+=`<text x="${vi}" y="${As-8}" text-anchor="end" class="ctx-window-label"${_("window")}>window: ${S(rp(n))} ${S(t)}</text>`;let h=0;if(p+=`<g${he("segments")}>`,s.forEach(({seg:v,si:y},b)=>{const E=gc(v.tokens),$=d(h),A=Math.max(d(h+E)-$,2),T=b===0,N=b===s.length-1&&i===0;p+=`<path d="${sv($,A,As,yi,T?mc:0,N?mc:0)}" fill="${W$(v.accent,b)}"${_(`segments.${y}`)}/>`;const j=$+Math.round(A/2),P=As+Math.round(yi/2);A>90?p+=nv(j,P,v.label):A>=22&&(p+=nv(j,P,String(b+1))),h+=E}),p+="</g>",i>0){const v=d(o),y=Math.max(vi-v,2);p+=`<path d="${sv(v,y,As,yi,s.length===0?mc:0,mc)}" fill="var(--paper-2)" stroke="var(--rule-solid)" stroke-width="1"/>`,y>=90&&(p+=`<text x="${v+Math.round(y/2)}" y="${As+21}" text-anchor="middle" class="ctx-free-label">free (${S(rp(i))})</text>`)}if(r){const v=d(n),y=Math.max(vi-v,2);p+=`<path d="${sv(v,y,As,yi,0,mc)}" fill="var(--negative)"/>`,y>=70&&(p+=nv(v+Math.round(y/2),As+Math.round(yi/2),`+${rp(o-n)}`)),p+=`<line x1="${v}" y1="${As-6}" x2="${v}" y2="${As+yi+5}" class="ctx-boundary"/>`;const b="over budget",E=20+b.length*6,$=Math.min(v-Math.round(E/2),vi-E-160);p+=`<rect x="${$}" y="${As-20}" width="${E}" height="16" rx="8" class="ctx-chip-bg"/>`,p+=`<text x="${$+Math.round(E/2)}" y="${As-8.5}" text-anchor="middle" class="ctx-chip">${b}</text>`}p+="</svg>";const m=s.map(({seg:v,si:y},b)=>{const E=gc(v.tokens),$=n>0?Math.round(E/n*100):0,A=v.desc!==void 0&&v.desc.length>0?`<span class="ctx-note"${_(`segments.${y}.desc`)}>${S(v.desc)}</span>`:"";return`<div class="ctx-row"${_(`segments.${y}`)}><span class="ctx-dot" style="background:${W$(v.accent,b)}"></span><span class="ctx-idx">${b+1}</span><span class="ctx-label"${_(`segments.${y}.label`)}>${S(v.label)}</span><span class="ctx-num"${_(`segments.${y}.tokens`)}>${S(rp(E))} ${S(t)} · ${$}%</span>`+A+"</div>"}).join(""),g=m.length>0?`<div class="ctx-legend"${he("segments")}><span class="lg-title t-eyebrow">Legend</span>${m}</div>`:"";return ct({tag:"CONTEXT",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{}},p+g)}var XW=["current","target","new","gap","deprecated"],NA={current:"Current",target:"Target",new:"New",gap:"Gap",deprecated:"Deprecated"};function TA(e){if(typeof e=="string")return"current";const t=e.status;return t!==void 0&&t in NA?t:"current"}function QW(e){return typeof e=="string"?e:e.name}function ZW(e,t){const n=TA(e),s=n==="current"?"":` am-t-${n}`,o=n==="gap"?'<span class="t-eyebrow am-chip">Gap</span>':"";return`<div class="am-tile${s}"${_(t)}>${S(QW(e))}${o}</div>`}function JW(e,t){const n=e.accent!==void 0?` am-${e.accent}`:"",s=e.desc!==void 0?`<div class="am-area-desc"${_(`areas.${t}.desc`)}>${S(e.desc)}</div>`:"",o=e.items??[],r=o.length>0?`<div class="am-tiles"${he(`areas.${t}.items`)}>${o.map((i,l)=>ZW(i,`areas.${t}.items.${l}`)).join("")}</div>`:"";return`<div class="am-area${n}"${_(`areas.${t}`)}><div class="am-area-label"${_(`areas.${t}.label`)}>${S(e.label)}</div>`+s+r+"</div>"}function eU(e){const t=new Set;for(const o of e)for(const r of o.items??[])t.add(TA(r));const n=XW.filter(o=>t.has(o));return n.length<2?"":`<div class="diagram-legend"><span class="lg-title t-eyebrow">Legend</span>${n.map(o=>`<span class="lg-item">${o==="gap"?'<span class="lg-chip t-eyebrow">Gap</span>':`<span class="lg-sw am-sw am-sw-${o}"></span>`}<span class="lg-label">${NA[o]}</span></span>`).join("")}</div>`}function tU(e){const t=e.title!==void 0?`<div class="am-head"${_("title")}>${S(e.title)}</div>`:"",n=e.description!==void 0?`<p class="am-desc"${_("description")}>${S(e.description)}</p>`:"",s=e.cols!==void 0?Math.min(4,Math.max(2,Math.floor(e.cols))):3,o=e.areas.map((r,i)=>JW(r,i)).join("");return`<div class="archmap">${t}${n}<div class="am-grid" style="--am-cols:${s}"${he("areas")}>${o}</div>`+eU(e.areas)+"</div>"}function nU(e){const t=e.accent!==void 0?` dvd-${e.accent}`:"",n=e.kicker!==void 0?`<div class="dvd-kicker"><span class="dvd-rule" aria-hidden="true"></span><span class="dvd-kicker-text"${_("kicker")}>${S(e.kicker)}</span><span class="dvd-rule" aria-hidden="true"></span></div>`:"",s=e.subtitle!==void 0?`<p class="dvd-subtitle"${_("subtitle")}>${S(e.subtitle)}</p>`:"";return`<div class="dvd${t}">`+n+`<div class="dvd-title"${_("title")}>${S(e.title)}</div>`+s+"</div>"}var sU={up:"▲",down:"▼",flat:"—"};function oU(e){const t=e.accent!==void 0?` bn-${e.accent}`:"",n=e.trend!==void 0?`<span class="bn-arrow" aria-hidden="true">${sU[e.trend]??""}</span>`:"",s=e.delta!==void 0?`<span class="bn-delta"${_("delta")}>${n}${S(e.delta)}</span>`:"",o=e.context!==void 0?`<p class="bn-context"${_("context")}>${S(e.context)}</p>`:"";return`<div class="bn${t}"><div class="bn-value-row"><span class="bn-value"${_("value")}>${S(e.value)}</span>${s}</div><div class="bn-label"${_("label")}>${S(e.label)}</div>`+o+"</div>"}function rU(e){const t=e.accent!==void 0?` tk-${e.accent}`:"",n=S(e.title??"Takeaways"),s=e.items.map((o,r)=>{const i=o.detail!==void 0?`<p class="tk-detail"${_(`items.${r}.detail`)}>${S(o.detail)}</p>`:"";return`<li class="tk-item"${_(`items.${r}`)}><span class="tk-num" aria-hidden="true">${r+1}</span><div class="tk-body"><div class="tk-text"${_(`items.${r}.text`)}>${S(o.text)}</div>${i}</div></li>`}).join("");return`<div class="tk${t}"><div class="tk-title">${n}</div><ol class="tk-list"${he("items")}>${s}</ol></div>`}var iU=["Task","Update"],aU=2;function _A(e,t){const n=e.toLowerCase();for(const s of t)if(s.label.toLowerCase()===n)return N3(s.color);for(const s of pM)if(s.label.toLowerCase()===n)return s.color;return"gray"}function lU(e,t){return`<span class="stt-pill stt-${_A(e,t)}">${S(e)}</span>`}function U$(e,t,n,s,o){const r=Array.from({length:n},(d,u)=>{const p=e.cells[u],h=u===0&&o===null?' class="stt-lead"':"",m=u===0&&o!==null?`<span class="stt-tree" aria-hidden="true">${o.last?"└":"├"}</span>`:"";return p===void 0?`<td${h}>${m}</td>`:`<td${h}${_(`${t}.cells.${u}`)}>${m}${S(p)}</td>`}).join(""),i=o===null&&"subtasks"in e&&e.subtasks!==void 0&&e.subtasks.length>0;return`<tr${o!==null?' class="stt-sub"':i?' class="stt-haskids"':""}${_(t)}>${r}<td class="stt-status"${_(`${t}.status`)}>${lU(e.status,s)}</td></tr>`}function cU(e){const t=e.items??[],n=t.some(i=>i.owner!==void 0),s=t.some(i=>i.due!==void 0),o=["<th>Task</th>","<th>Status</th>","<th>Priority</th>"];n&&o.push("<th>Owner</th>"),s&&o.push("<th>Due</th>");let r=`<table class="trk"><thead><tr>${o.join("")}</tr></thead><tbody${he("items")}>`;for(const[i,l]of t.entries()){const d=l.status??"todo",u=l.priority,p=u!==void 0?`<span class="pri ${u}">${S(u)}</span>`:"",h=d==="done"?' class="done"':"",m=[`<td class="trk-task"${_(`items.${i}.task`)}>${S(l.task)}</td>`,`<td${_(`items.${i}.status`)}><span class="st ${d}">${S(d)}</span></td>`,`<td${_(`items.${i}.priority`)}>${p}</td>`];n&&m.push(`<td${_(`items.${i}.owner`)}>${S(l.owner??"")}</td>`),s&&m.push(`<td${_(`items.${i}.due`)}>${S(l.due??"")}</td>`),r+=`<tr${h}${_(`items.${i}`)}>${m.join("")}</tr>`}return r+"</tbody></table>"}function dU(e){if(e.rows===void 0)return cU(e);const t=e.rows,n=e.statuses??[],s=e.columns??iU,o=Math.max(s.length,...t.flatMap(m=>[m.cells.length,...(m.subtasks??[]).map(g=>g.cells.length)])),r=Array.from({length:o},(m,g)=>{const v=s[g]!==void 0?S(s[g]??""):"";return`<th${e.columns!==void 0&&g<e.columns.length?_(`columns.${g}`):""}>${v}</th>`}).join("")+'<th class="stt-status-h">Status</th>',i=t.map((m,g)=>{const v=m.subtasks??[],y=U$(m,`rows.${g}`,o,n,null)+v.map((b,E)=>U$(b,`rows.${g}.subtasks.${E}`,o,n,{last:E===v.length-1})).join("");return`<tbody class="stt-group"${he(`rows.${g}.subtasks`)}>${y}</tbody>`}).join(""),l=e.description!==void 0?`<p class="stt-desc"${_("description")}>${S(e.description)}</p>`:"",d=n.map((m,g)=>({label:m.label,index:g})),u=new Set(n.map(m=>m.label.toLowerCase())),p=m=>{const g=m.toLowerCase();u.has(g)||(u.add(g),d.push({label:m,index:-1}))};for(const m of t){p(m.status);for(const g of m.subtasks??[])p(g.status)}const h=d.length>=aU?`<div class="diagram-legend stt-legend"${he("statuses")}><span class="lg-title t-eyebrow">Legend</span>`+d.map(({label:m,index:g})=>{const v=g>=0;return`<span class="lg-item stt-key"${v?_(`statuses.${g}`):""}><i class="lg-sw stt-dot stt-${_A(m,n)}"${v?_(`statuses.${g}.color`):""}></i><span class="lg-label"${v?_(`statuses.${g}.label`):""}>${S(m)}</span></span>`}).join("")+"</div>":"";return`<div class="stt">${l}<div class="stt-wrap"><table class="stt-table"${he("rows")}><thead><tr>${r}</tr></thead>${i}</table>${h}</div></div>`}function uU(e){const t=e.steps.map((N,j)=>typeof N=="string"?{label:N,labelPath:`steps.${j}`}:{label:N.label,desc:N.desc,labelPath:`steps.${j}.label`}),n=t.length,s=t.map(N=>lt(N.label,14,2)),o=Math.max(1,...s.flat().map(N=>N.length)),r=Math.max(1,...s.map(N=>N.length)),i=Math.min(150,Math.max(96,o*7+30)),l=34+(r-1)*14,d=e.center!==void 0&&e.center.length>0?lt(e.center,18,3):[],u=Math.max(0,...d.map(N=>N.length))*7.2,p=Math.max(96,Math.ceil((i+40)/(2*Math.sin(Math.PI/n))),d.length>0?Math.ceil(i/2+u/2+18):0),m=p+i/2+30,g=m*2,v=N=>-Math.PI/2+N*2*Math.PI/n,y=N=>({x:m+p*Math.cos(v(N)),y:m+p*Math.sin(v(N))});let b=`<svg viewBox="0 0 ${g} ${g}" role="img"><title>Cycle</title>`;const E=(N,j)=>{const P=y(N),I=i/2+10,O=l/2+10,C=Math.PI/180;for(let D=C;D<Math.PI/n;D+=C){const F=v(N)+j*D,U=m+p*Math.cos(F),X=m+p*Math.sin(F);if(Math.abs(U-P.x)>I||Math.abs(X-P.y)>O)return D}return Math.PI/n};for(let N=0;N<n;N++){const j=(N+1)%n,P=v(N)+E(N,1),I=v(N+1)-E(j,-1);if(I-P<.08)continue;const O=m+p*Math.cos(P),C=m+p*Math.sin(P),D=m+p*Math.cos(I),F=m+p*Math.sin(I);b+=`<path d="M ${O.toFixed(1)} ${C.toFixed(1)} A ${p} ${p} 0 0 1 ${D.toFixed(1)} ${F.toFixed(1)}" fill="none" stroke="var(--muted)" stroke-width="1.5" marker-end="url(#skArrow)"/>`}d.length>0&&(b+=`<g class="cycle-center"${_("center")}>`+d.map((N,j)=>`<text x="${m}" y="${m+4-(d.length-1)*8+j*16}" class="t-sub" text-anchor="middle">${S(N)}</text>`).join("")+"</g>"),b+=`<g${he("steps")}>`,t.forEach((N,j)=>{const P=y(j),I=s[j]??[],O=P.x-i/2,C=P.y-l/2,D=N.labelPath===`steps.${j}`?"":_(N.labelPath),F=I.length<=1?`<text x="${P.x.toFixed(1)}" y="${(P.y+4).toFixed(1)}" class="t-name" text-anchor="middle"${_(N.labelPath)}>${S(N.label)}</text>`:`<g${D}>`+I.map((H,W)=>`<text x="${P.x.toFixed(1)}" y="${(P.y+4-(I.length-1)*7+W*14).toFixed(1)}" class="t-name" text-anchor="middle">${S(H)}</text>`).join("")+"</g>",U=Math.cos(v(j)),X=Math.sin(v(j)),te=Math.min(Math.abs(U)>1e-6?i/2/Math.abs(U):1/0,Math.abs(X)>1e-6?l/2/Math.abs(X):1/0)+14,ee={lx:P.x+U*te,ly:P.y+X*te};b+=`<g${_(`steps.${j}`)}><rect x="${O.toFixed(1)}" y="${C.toFixed(1)}" width="${i}" height="${l}" rx="${Math.min(17,l/2)}" fill="var(--paper)" stroke="var(--ink)" stroke-width="1.5"/>`+F+`</g><g${_(`steps.${j}`)}>${xf(ee,j+1,!1,!0)}</g>`}),b+="</g></svg>";const $=t.some(N=>N.desc!==void 0&&N.desc.length>0)?E4(t.map((N,j)=>({label:N.desc!==void 0&&N.desc.length>0?`${N.label} — ${N.desc}`:N.label,path:`steps.${j}`}))):"",T=ot([{swatch:"node",label:"stage"},{swatch:"edge",label:"next stage"}]);return ct({tag:"CYCLE",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...T.length>0?{legendHtml:T}:{}},b+$)}var pU="Benchmark",Ef="—";function ov(e,t){if(e===void 0)return{text:Ef,forced:!1,num:void 0,path:t};if(typeof e=="string"||typeof e=="number"){const s=String(e);return{text:s,forced:!1,num:K$(s),path:t}}const n=e.value!==void 0?String(e.value):Ef;return{text:n,...e.note!==void 0?{note:e.note}:{},forced:e.best===!0,num:K$(n),path:e.value!==void 0?`${t}.value`:t}}function K$(e){const t=/-?\d+(?:[.,]\d+)?/.exec(e.replace(/,(?=\d{3}\b)/g,""));if(t===null)return;const n=Number(t[0].replace(",","."));return Number.isFinite(n)?n:void 0}function fU(e,t,n){const s=Math.max(1,e.variants?.length??1);return t.map((o,r)=>{const i=e.cells?.[r],l=`rows.${n}.cells.${r}`;return Array.isArray(i)?Array.from({length:s},(d,u)=>ov(i[u],`${l}.${u}`)):Array.from({length:s},(d,u)=>ov(u===0?i:void 0,l))})}function hU(e,t,n){const s=new Set;for(const[l,d]of e.entries())d[t]?.forced===!0&&s.add(l);if(n==="none")return s;const o=e.map(l=>l[t]?.num),r=o.filter(l=>l!==void 0);if(r.length<2)return s;const i=n==="low"?Math.min(...r):Math.max(...r);return o.forEach((l,d)=>{l===i&&s.add(d)}),s}function mU(e){const t=e.subjects,n=e.rows,s=t.map((u,p)=>{const h=["bm-subj",u.featured===!0?"bm-feat":""].filter(Boolean).join(" "),m=u.sub!==void 0?`<span class="bm-subj-sub"${_(`subjects.${p}.sub`)}>${S(u.sub)}</span>`:"";return`<th class="${h}"${_(`subjects.${p}`)}>${S(u.label)}${m}</th>`}).join(""),o=`<tr${he("subjects")}><th class="bm-metric">${S(e.metricLabel??pU)}</th>${s}</tr>`,r=n.map((u,p)=>{const h=fU(u,t,p),m=h[0]?.length??1,g=Array.from({length:m},(E,$)=>hU(h,$,u.better)),v=u.sub!==void 0?`<span class="bm-row-sub"${_(`rows.${p}.sub`)}>${S(u.sub)}</span>`:"",y=`<td class="bm-metric"${_(`rows.${p}`)}><span class="bm-row-label"${_(`rows.${p}.label`)}>${S(u.label)}</span>${v}</td>`,b=h.map((E,$)=>{const A=t[$],T=A?.tone==="muted"?"bm-muted":"bm-accent",N=E.map((P,I)=>{const C=["bm-slot",g[I]?.has($)===!0&&P.text!==Ef?`bm-best ${T}`:""].filter(Boolean).join(" "),D=P.note!==void 0?`<span class="bm-note">${S(P.note)}</span>`:"",F=u.variants?.[I],U=F!==void 0&&P.text!==Ef?`<span class="bm-cap"${_(`rows.${p}.variants.${I}`)}>${S(F)}</span>`:"";return`<div class="${C}"${_(P.path)}>${D}<span class="bm-val">${S(P.text)}</span>${U}</div>`}).join("");return`<td class="${["bm-cell",A?.featured===!0?"bm-feat":""].filter(Boolean).join(" ")}">${N}</td>`}).join("");return`<tr>${y}${b}</tr>`}).join(""),i=e.title!==void 0?`<div class="bm-head">${S(e.title)}</div>`:"",l=e.description!==void 0?`<p class="bm-desc"${_("description")}>${S(e.description)}</p>`:"",d=e.note!==void 0?`<p class="bm-foot"${_("note")}>${S(e.note)}</p>`:"";return`<div class="benchmark">${i}${l}<div class="bm-scroll"><table class="bm-table"><thead>${o}</thead><tbody${he("rows")}>${r}</tbody></table></div>${d}</div>`}function gU(e){return e==="negative"?"negative":e==="focal"?"accent":"plain"}var vU={plain:"var(--ink)",accent:"var(--accent)",negative:"var(--negative)"},yU={plain:'fill="var(--paper)" stroke="var(--rule-solid)" stroke-width="1"',accent:'fill="var(--accent-tint)" stroke="var(--accent)" stroke-width="1"',negative:'fill="var(--negative-tint)" stroke="var(--negative)" stroke-width="1"'},V$=900,ip=13,rv=8,G$=16,xU=14,iv=16,kU=3;function av(e,t){const n=Math.round(e*10)/10,s=Number.isInteger(n)?String(n):n.toFixed(1);return t!==void 0?`${s}${t}`:s}function bU(e,t){const n=new Map(e.map(s=>[s,0]));for(let s=0;s<e.length;s++){let o=!1;for(const r of t){const i=n.get(r.from),l=n.get(r.to);i===void 0||l===void 0||l<i+1&&(n.set(r.to,i+1),o=!0)}if(!o)break}return n}function wU(e){const t=e.links.filter(A=>A.from!==A.to&&A.value>0),n=e.nodes??[],s=new Map(n.map((A,T)=>[A.id,T])),o=[];for(const A of n)o.includes(A.id)||o.push(A.id);for(const A of t)o.includes(A.from)||o.push(A.from),o.includes(A.to)||o.push(A.to);if(o.length===0||t.length===0)return Y$(e,'<svg viewBox="0 0 900 60" role="img"><title>Sankey</title></svg>',"");const r=bU(o,t),i=new Map,l=Xn(n.map(A=>A.accent));o.forEach(A=>{const T=s.get(A),N=n[T??-1],j=t.filter(I=>I.to===A).reduce((I,O)=>I+O.value,0),P=t.filter(I=>I.from===A).reduce((I,O)=>I+O.value,0);i.set(A,{id:A,label:N?.label??A,tone:gU(T!==void 0?l[T]:void 0),col:N?.col!==void 0?Math.max(0,N.col-1):r.get(A)??0,value:Math.max(j,P),x:0,y:0,h:0,outAt:0,inAt:0,path:s.has(A)?`nodes.${s.get(A)??0}`:void 0})});const d=Math.max(...[...i.values()].map(A=>A.col))+1,u=Array.from({length:d},()=>[]);for(const A of o){const T=i.get(A);T!==void 0&&u[T.col]?.push(T)}const p=Math.max(220,Math.min(420,60+o.length*34)),h=p-G$-xU,m=Math.min(...u.filter(A=>A.length>0).map(A=>{const T=A.reduce((j,P)=>j+P.value,0),N=h-iv*(A.length-1);return T>0?Math.max(N,40)/T:1/0})),g=A=>d===1?rv:rv+(V$-rv*2-ip)*A/(d-1);u.forEach((A,T)=>{const N=A.reduce((P,I)=>P+I.value*m,0)+iv*(A.length-1);let j=G$+Math.max(0,(h-N)/2);for(const P of A)P.h=Math.max(kU,P.value*m),P.x=g(T),P.y=j,P.outAt=j,P.inAt=j,j+=P.h+iv});const v=[...i.values()].some(A=>A.tone!=="plain");let y=-1;if(!v){let A=0;e.links.forEach((T,N)=>{T.from===T.to||!i.has(T.from)||!i.has(T.to)||T.value>A&&(A=T.value,y=N)})}let b=`<svg viewBox="0 0 ${V$} ${p}" role="img"><title>${S(e.title??"Flow volumes")}</title>`;const E=new Set;b+=`<g${he("links")}>`,e.links.forEach((A,T)=>{const N=i.get(A.from),j=i.get(A.to);if(N===void 0||j===void 0||A.value<=0||A.from===A.to)return;const P=Math.max(1,A.value*m),I=N.x+ip,O=j.x,C=N.outAt,D=j.inAt;N.outAt+=P,j.inAt+=P;const F=(I+O)/2,U=`M ${Pt(I)} ${Pt(C)} C ${Pt(F)} ${Pt(C)}, ${Pt(F)} ${Pt(D)}, ${Pt(O)} ${Pt(D)} L ${Pt(O)} ${Pt(D+P)} C ${Pt(F)} ${Pt(D+P)}, ${Pt(F)} ${Pt(C+P)}, ${Pt(I)} ${Pt(C+P)} Z`,X=N.tone!=="plain"?N.tone:T===y?"accent":"plain";if(E.add(X),b+=`<path d="${U}" ${yU[X]}${_(`links.${T}`)}><title>${S(`${N.label} → ${j.label}: ${av(A.value,e.unit)}`)}</title></path>`,P>=13){const B=A.label??av(A.value,e.unit),te=X==="accent"?"t-arrow c-accent":X==="negative"?"t-arrow c-negative":"t-arrow";b+=`<text x="${Pt(F)}" y="${Pt((C+D)/2+P/2+3)}" class="${te}" text-anchor="middle">${S(B)}</text>`}}),b+="</g>",b+=`<g${he("nodes")}>`;for(const A of i.values()){const T=A.path!==void 0?_(A.path):"";b+=`<g${T}>`,b+=`<rect x="${Pt(A.x)}" y="${Pt(A.y)}" width="${ip}" height="${Pt(A.h)}" fill="${vU[A.tone]}"/>`;const N=A.col===d-1,j=N?A.x-8:A.x+ip+8,P=A.y+A.h/2,I=N?"end":"start",O=A.tone==="accent"?"t-name c-accent":A.tone==="negative"?"t-name c-negative":"t-name",C=av(A.value,e.unit),D=Math.max(A.label.length*7.2,C.length*6.2)+8;b+=`<rect x="${Pt(N?j-D+4:j-4)}" y="${Pt(P-9)}" width="${Pt(D)}" height="28" rx="2" fill="var(--paper)"/>`,b+=`<text x="${Pt(j)}" y="${Pt(P+3)}" class="${O}" text-anchor="${I}">${S(A.label)}</text>`,b+=`<text x="${Pt(j)}" y="${Pt(P+15)}" class="t-sub c-muted" text-anchor="${I}">${S(C)}</text>`,b+="</g>"}b+="</g></svg>";const $=[{swatch:"fill",fill:"var(--ink)",label:"stage (height = volume)"}];return E.has("plain")&&$.push({swatch:"fill",fill:"var(--paper)",label:"flow (width = volume)"}),E.has("accent")&&$.push({swatch:"node-accent",label:v?"focal flow":"heaviest flow"}),E.has("negative")&&$.push({swatch:"fill",fill:"var(--negative-tint)",label:"negative flow"}),Y$(e,b,ot($))}function Pt(e){return Math.round(e*10)/10}function Y$(e,t,n){return ct({tag:"SANKEY",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...n.length>0?{legendHtml:n}:{}},t)}var ap=104,X$=96,lv=62,cv=46,Q$=6;function $U(e){const t=[];for(const $ of e.branches??[])t.includes($.name)||t.push($.name);for(const $ of e.commits){const A=$.branch??t[0]??"main";t.includes(A)||t.push(A),$.merge!==void 0&&!t.includes($.merge)&&t.push($.merge)}t.length===0&&t.push("main");const n=t[0]??"main",s=$=>$===n,o=$=>s($)?"var(--accent)":"var(--muted)",r=$=>s($)?1.75:1.5,i=$=>cv+Math.max(0,t.indexOf($))*lv,l=new Map,d=[],u=[];let p=0,h=0;e.commits.forEach(($,A)=>{const T=$.branch??t[0]??"main",N=ap+p*X$,j=i(T),P={x:N,y:j,lane:t.indexOf(T)},I=o(T),O=r(T),C=l.get(T);if(C===void 0){const D=$.from??t[Math.max(0,t.indexOf(T)-1)],F=D!==void 0?l.get(D):void 0;F!==void 0&&u.push(Z$(F,P,I,O))}else u.push(`<line x1="${C.x}" y1="${C.y}" x2="${N}" y2="${j}" stroke="${I}" stroke-width="${O}"/>`);if($.merge!==void 0){const D=l.get($.merge);D!==void 0&&(u.push(Z$(D,P,o($.merge),r($.merge),!0)),h+=1),l.delete($.merge)}l.set(T,P),d.push({p:P,branch:T,index:A}),p+=1});const m=ap+Math.max(1,p)*X$,g=cv+t.length*lv+26;let v=`<svg viewBox="0 0 ${m} ${g}" role="img"><title>${S(e.title??"Branch graph")}</title>`;v+=`<g${he("branches")}>`,t.forEach(($,A)=>{const T=cv+A*lv;v+=`<line x1="${ap-18}" y1="${T}" x2="${m-12}" y2="${T}" stroke="var(--rule)" stroke-width="1" stroke-dasharray="2 5"${ut}/>`;const N=(e.branches??[]).some(j=>j.name===$)?_(`branches.${(e.branches??[]).findIndex(j=>j.name===$)}`):"";v+=`<text x="${ap-26}" y="${T+4}" class="gg-branch t-sub c-ink"${N}>${S($)}</text>`}),v+="</g>",v+=`<g>${u.join("")}</g>`;const y={release:!1,hotfix:!1,revert:!1};v+=`<g${he("commits")}>`,d.forEach(({p:$,branch:A,index:T})=>{const N=e.commits[T];if(N===void 0)return;const j=o(A),P=N.kind==="release"||N.tag!==void 0;if(P&&(y.release=!0),N.kind==="hotfix"&&(y.hotfix=!0),N.kind==="revert"&&(y.revert=!0),v+=`<g${_(`commits.${T}`)}>`,v+=`<circle cx="${$.x}" cy="${$.y}" r="${P?Q$+2:Q$}" fill="${N.kind==="revert"?"var(--paper)":j}" stroke="${j}" stroke-width="1.5"/>`,N.kind==="hotfix"&&(v+=`<circle cx="${$.x}" cy="${$.y}" r="2.5" fill="var(--paper)"/>`),N.label!==void 0&&(v+=`<text x="${$.x}" y="${$.y+22}" class="gg-msg t-sub" text-anchor="middle">${S(N.label)}</text>`),N.tag!==void 0){const I=Math.max(34,N.tag.length*6.5+14);v+="<g>",v+=`<rect x="${$.x-I/2}" y="${$.y-40}" width="${I}" height="18" rx="2" fill="var(--paper)" stroke="var(--ink)" stroke-width="1"/>`,v+=`<text x="${$.x}" y="${$.y-27.5}" class="t-badge c-ink" text-anchor="middle">${S(N.tag)}</text>`,v+=`<line x1="${$.x}" y1="${$.y-22}" x2="${$.x}" y2="${$.y-10}" stroke="var(--rule-solid)" stroke-width="1" stroke-dasharray="2 2"/>`,v+="</g>"}v+="</g>"}),v+="</g></svg>";const b=[{swatch:"line-dot-accent",label:`${n} (trunk)`}];t.length>1&&b.push({swatch:"line-dot",label:"branch"}),h>0&&b.push({swatch:"edge-dashed",label:"merge"}),y.release&&b.push({swatch:"chip",chip:"v1",label:"release tag"}),y.hotfix&&b.push({swatch:"chip",chip:"◉",label:"hotfix"}),y.revert&&b.push({swatch:"chip",chip:"○",label:"revert"});const E=ot(b);return ct({tag:"BRANCHES",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...E.length>0?{legendHtml:E}:{}},v)}function Z$(e,t,n,s,o=!1){const r=(e.x+t.x)/2;return`<path d="${`M ${e.x} ${e.y} C ${r} ${e.y}, ${r} ${t.y}, ${t.x} ${t.y}`}" fill="none" stroke="${n}" stroke-width="${s}"${o?' stroke-dasharray="5 4"':""}/>`}var lp=880,cp=400,dp=3;function J$(e,t){if(e.length===0||t<=0)return 1/0;const n=e.reduce((r,i)=>r+i,0);if(n<=0)return 1/0;const s=Math.max(...e),o=Math.min(...e);return Math.max(t*t*s/(n*n),n*n/(t*t*o))}function e2(e,t){const n=e.reduce((i,l)=>i+l.area,0),s=t.w>=t.h,o=n/(s?t.h:t.w);let r=s?t.y:t.x;for(const{area:i,tile:l}of e){const d=i/o;s?(l.x=t.x,l.y=r,l.w=o,l.h=d):(l.x=r,l.y=t.y,l.w=d,l.h=o),r+=d}return s?{x:t.x+o,y:t.y,w:t.w-o,h:t.h}:{x:t.x,y:t.y+o,w:t.w,h:t.h-o}}function SU(e,t,n){let s=n,o=[];for(let r=0;r<e.length;r++){const i=e[r],l=t[r];if(i===void 0||l===void 0)continue;const d=Math.min(s.w,s.h),u=o.map(p=>p.area);o.length===0||J$([...u,l],d)<=J$(u,d)?o.push({area:l,tile:i}):(s=e2(o,s),o=[{area:l,tile:i}])}o.length>0&&e2(o,s)}function t2(e,t){const n=Math.round(e*10)/10,s=Number.isInteger(n)?String(n):n.toFixed(1);return t!==void 0?`${s}${t}`:s}var EU={plain:'fill="var(--paper)" stroke="var(--ink)" stroke-width="1"',accent:'fill="var(--accent-tint)" stroke="var(--accent)" stroke-width="1.5"',negative:'fill="var(--negative-tint)" stroke="var(--negative)" stroke-width="1.5"'};function MU(e){const t=e.items.map((h,m)=>({item:h,index:m})).filter(h=>h.item.value>0).sort((h,m)=>m.item.value-h.item.value),n=t.reduce((h,m)=>h+m.item.value,0);let s=`<svg viewBox="0 0 ${lp} ${cp}" role="img"><title>${S(e.title??"Treemap")}</title>`;if(t.length===0||n<=0)return s+=`<rect x="0" y="0" width="${lp}" height="${cp}" rx="8" fill="var(--paper)" stroke="var(--rule-solid)"/></svg>`,n2(e,s,"");const o=t.map(h=>({item:h.item,index:h.index,x:0,y:0,w:0,h:0})),r=lp*cp/n;SU(o,t.map(h=>h.item.value*r),{x:0,y:0,w:lp,h:cp});const i=Xn(t.map(h=>h.item.accent)),l=i.includes("focal"),d=(h,m)=>{const g=i[m];return g==="negative"?"negative":g==="focal"||!l&&m===0?"accent":"plain"},u=new Set;s+=`<g${he("items")}>`,o.forEach((h,m)=>{const g=h.x+dp/2,v=h.y+dp/2,y=Math.max(0,h.w-dp),b=Math.max(0,h.h-dp);if(y<2||b<2)return;const E=d(h,m);u.add(E);const $=Math.round(h.item.value/n*100),A=E==="accent"?"t-name c-accent":E==="negative"?"t-name c-negative":"t-name";if(s+=`<g${_(`items.${h.index}`)}>`,E!=="plain"&&(s+=`<rect x="${os(g)}" y="${os(v)}" width="${os(y)}" height="${os(b)}" rx="3" fill="var(--paper)"/>`),s+=`<rect x="${os(g)}" y="${os(v)}" width="${os(y)}" height="${os(b)}" rx="3" ${EU[E]}/>`,y>=58&&b>=30){const T=Math.max(6,Math.floor(y/7.4)),N=lt(h.item.label,T,b>=58?2:1);N.forEach((P,I)=>{s+=`<text x="${os(g+9)}" y="${os(v+20+I*15)}" class="${A}">${S(P)}</text>`});const j=v+20+N.length*15;b>=48&&(s+=`<text x="${os(g+9)}" y="${os(j+1)}" class="t-sub c-muted">${S(t2(h.item.value,e.unit))} · ${$}%</text>`),h.item.desc!==void 0&&b>=74&&(s+=`<text x="${os(g+9)}" y="${os(j+16)}" class="t-sub c-soft">${S(h.item.desc)}</text>`)}s+=`<title>${S(`${h.item.label}: ${t2(h.item.value,e.unit)} (${$}%)`)}</title>`,s+="</g>"}),s+="</g></svg>";const p=[];return u.has("plain")&&p.push({swatch:"node",label:"item (area = value)"}),u.has("accent")&&p.push({swatch:"node-accent",label:l?"focal item":"largest item"}),u.has("negative")&&p.push({swatch:"fill",fill:"var(--negative-tint)",label:"negative"}),n2(e,s,ot(p))}function os(e){return Math.round(e*10)/10}function n2(e,t,n){return ct({tag:"TREEMAP",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...n.length>0?{legendHtml:n}:{}},t)}var s2=["var(--paper)","var(--paper-2)"];function AU(e,t){return e==="red"?{fill:"var(--negative-tint)",stroke:"var(--negative)"}:e==="gray"?{fill:"var(--paper-2)",stroke:"var(--rule-solid)"}:e!==void 0?{fill:"var(--accent-tint)",stroke:"var(--accent)"}:{fill:s2[t%s2.length]??"var(--paper)",stroke:"var(--ink)"}}var dv=34,CU=8,uv=26,Ta=46,o2=880;function NU(e){const t=e.width!==void 0&&e.width>0?Math.floor(e.width):32,n=[];let s=0;e.fields.forEach((h,m)=>{let g=Math.max(0,Math.floor(h.bits)),v=!0;for(;g>0;){const y=Math.floor(s/t),b=s%t,E=Math.min(g,t-b);n.push({label:h.label,value:h.value,paint:AU(h.accent,m),index:m,row:y,from:b,bits:E,cut:E<g,cont:!v}),s+=E,g-=E,v=!1}});const o=Math.max(1,Math.ceil(s/t)||1),r=uv+o*Ta+10,i=(o2-dv-CU)/t,l=h=>dv+h*i;let d=`<svg viewBox="0 0 ${o2} ${r}" role="img"><title>${S(e.title??"Packet layout")}</title>`;d+="<g>";for(let h=0;h<=t;h+=1){const m=l(h),g=h%8===0;d+=`<line x1="${ms(m)}" y1="${g?10:15}" x2="${ms(m)}" y2="20" stroke="var(--rule)" stroke-width="1"${ut}/>`,g&&h<t&&(d+=`<text x="${ms(m+2)}" y="8" class="pk-tick">${h}</text>`)}d+="</g>",d+=`<g${he("fields")}>`,n.forEach(h=>{const m=l(h.from),g=h.bits*i,v=uv+h.row*Ta;d+=`<g${_(`fields.${h.index}`)}>`,d+=`<rect x="${ms(m+1)}" y="${ms(v+2)}" width="${ms(g-2)}" height="${Ta-6}" rx="3" fill="${h.paint.fill}" stroke="${h.paint.stroke}" stroke-width="1"/>`;const y=m+g/2;if(g>=46){const b=h.cont?" (cont.)":h.cut?" →":"";d+=`<text x="${ms(y)}" y="${ms(v+(h.value!==void 0&&g>=80?17:24))}" class="pk-name">${S(h.label+b)}</text>`,h.value!==void 0&&g>=80&&(d+=`<text x="${ms(y)}" y="${ms(v+28)}" class="pk-value">${S(h.value)}</text>`)}d+=`<text x="${ms(y)}" y="${ms(v+Ta-8)}" class="pk-bits">${h.bits}</text>`,d+=`<title>${S(`${h.label} — ${h.bits} bit${h.bits===1?"":"s"} at offset ${h.row*t+h.from}`)}</title>`,d+="</g>"}),d+="</g>";for(let h=0;h<o;h++)d+=`<text x="${dv-8}" y="${ms(uv+h*Ta+Ta/2)}" class="pk-off">${h*t}</text>`;d+="</svg>";const u=s,p=`<p class="pk-total">${u} bits · ${Math.round(u/8*10)/10} bytes`+(u%t!==0?` · last row is ${u%t} of ${t} bits`:"")+"</p>";return ct({tag:"PACKET",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},footerHtml:p},d)}function ms(e){return Math.round(e*10)/10}function TU(e){return e==="negative"?"negative":e==="focal"?"accent":"plain"}var _U={plain:'fill="var(--ink)" fill-opacity="0.06" stroke="var(--ink)" stroke-width="1.5"',accent:'fill="var(--accent-tint)" stroke="var(--accent)" stroke-width="1.5"',negative:'fill="var(--negative-tint)" stroke="var(--negative)" stroke-width="1.5"'},LU={plain:"t-name",accent:"t-name c-accent",negative:"t-name c-negative"},IU=620;function jU(e){return e<=2?{height:340,radius:132,circles:[{cx:240,cy:176},{cx:380,cy:176}],own:[{x:178,y:176},{x:442,y:176}],pairs:[{of:[0,1],x:310,y:176}],centre:{x:310,y:176}}:{height:396,radius:118,circles:[{cx:250,cy:158},{cx:370,cy:158},{cx:310,cy:258}],own:[{x:196,y:126},{x:424,y:126},{x:310,y:316}],pairs:[{of:[0,1],x:310,y:132},{of:[0,2],x:264,y:226},{of:[1,2],x:356,y:226}],centre:{x:310,y:202}}}function PU(e){const t=e.sets.slice(0,3),n=jU(t.length),s=Xn(t.map(p=>p.accent)),o=p=>TU(s[p]);let r=`<svg viewBox="0 0 ${IU} ${n.height}" role="img"><title>${S(e.title??"Venn")}</title>`;r+=`<g${he("sets")}>`,t.forEach((p,h)=>{const m=n.circles[h];m!==void 0&&(r+=`<g${_(`sets.${h}`)}>`,r+=`<circle cx="${m.cx}" cy="${m.cy}" r="${n.radius}" ${_U[o(h)]}/>`,r+="</g>")}),r+="</g>",t.forEach((p,h)=>{const m=n.own[h];if(m===void 0)return;const g=lt(p.label,14,2);if(g.forEach((v,y)=>{r+=`<text x="${m.x}" y="${m.y-(g.length-1)*8+y*16}" class="${LU[o(h)]}" text-anchor="middle">${S(v)}</text>`}),p.desc!==void 0){const v=m.y-(g.length-1)*8+g.length*16+2;lt(p.desc,18,2).forEach((y,b)=>{r+=`<text x="${m.x}" y="${v+b*13}" class="t-sub c-muted" text-anchor="middle">${S(y)}</text>`})}});const i=new Map(t.map((p,h)=>[p.label.toLowerCase(),h]));let l=!1;r+=`<g${he("shared")}>`,(e.shared??[]).forEach((p,h)=>{const m=p.sets.map(y=>i.get(y.toLowerCase())).filter(y=>y!==void 0).sort((y,b)=>y-b);if(m.length<2)return;const g=m.length>=3?n.centre:n.pairs.find(y=>y.of.length===m.length&&y.of.every((b,E)=>b===m[E]));if(g===void 0)return;l=!0;const v=lt(p.label,t.length>2?12:16,2);v.forEach((y,b)=>{r+=`<text x="${g.x}" y="${g.y-(v.length-1)*7+b*14}" class="t-name" text-anchor="middle"${b===0?_(`shared.${h}`):""}>${S(y)}</text>`})}),r+="</g></svg>";const d=[];t.some((p,h)=>o(h)==="plain")&&d.push({swatch:"node",label:"set"}),t.some((p,h)=>o(h)==="accent")&&d.push({swatch:"node-accent",label:"focal set"}),t.some((p,h)=>o(h)==="negative")&&d.push({swatch:"fill",fill:"var(--negative-tint)",label:"negative set"}),l&&d.push({swatch:"node-fill2",label:"overlap (darker = shared)"});const u=ot(d);return ct({tag:"VENN",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...u.length>0?{legendHtml:u}:{}},r)}var r2=880,i2=420,OU=96,RU=20,DU=18,BU=52,a2=[{at:0,label:"Genesis"},{at:.25,label:"Custom-built"},{at:.5,label:"Product"},{at:.75,label:"Commodity"}],zU={user:'fill="var(--ink)" stroke="var(--ink)" stroke-width="1.5"',component:'fill="var(--paper)" stroke="var(--ink)" stroke-width="1.5"',commodity:'fill="var(--paper-2)" stroke="var(--rule-solid)" stroke-width="1.5"',build:'fill="var(--accent-tint)" stroke="var(--accent)" stroke-width="1.75"',buy:'fill="var(--paper)" stroke="var(--ink)" stroke-width="1.25" stroke-dasharray="3 2"'},FU={user:{swatch:"node-dot",fill:"var(--ink)",label:"user"},component:{swatch:"node-dot",label:"component"},commodity:{swatch:"node-dot",fill:"var(--paper-2)",stroke:"var(--rule-solid)",label:"commodity"},build:{swatch:"node-dot",fill:"var(--accent-tint)",stroke:"var(--accent)",label:"build"},buy:{swatch:"node-dot",dash:"3 2",label:"buy"}};function qU(e){const t=OU,n=r2-RU,s=DU,o=i2-BU,r=v=>t+(n-t)*pv(v),i=v=>o-(o-s)*pv(v);let l=`<svg viewBox="0 0 ${r2} ${i2}" role="img"><title>${S(e.title??"Wardley map")}</title>`;l+=`<rect x="${t}" y="${s}" width="${n-t}" height="${o-s}" fill="var(--paper)" stroke="var(--rule-solid)" stroke-width="1"/>`,a2.forEach((v,y)=>{const b=r(v.at);y>0&&(l+=`<line x1="${pn(b)}" y1="${s}" x2="${pn(b)}" y2="${o}" stroke="var(--rule-solid)" stroke-width="1" stroke-dasharray="3 4"/>`);const E=a2[y+1]?.at??1;l+=`<text x="${pn((b+r(E))/2)}" y="${o+20}" class="t-eyebrow" text-anchor="middle">${S(v.label.toUpperCase())}</text>`}),l+=`<text x="${pn((t+n)/2)}" y="${o+38}" class="t-eyebrow c-muted" text-anchor="middle">EVOLUTION →</text>`,l+=`<text x="18" y="${pn((s+o)/2)}" class="t-eyebrow c-muted" text-anchor="middle" transform="rotate(-90 18 ${pn((s+o)/2)})">VISIBLE TO THE USER →</text>`;const d=new Map(e.components.map(v=>[v.id??v.label,{x:r(v.x),y:i(v.y)}]));let u=!1;l+=`<g${he("links")}>`,(e.links??[]).forEach((v,y)=>{const b=d.get(v.from),E=d.get(v.to);b===void 0||E===void 0||(u=!0,l+=`<line x1="${pn(b.x)}" y1="${pn(b.y)}" x2="${pn(E.x)}" y2="${pn(E.y)}" stroke="var(--muted)" stroke-width="1.25"${_(`links.${y}`)}/>`,v.label!==void 0&&(l+=`<text x="${pn((b.x+E.x)/2)}" y="${pn((b.y+E.y)/2-5)}" class="t-arrow" text-anchor="middle">${S(v.label)}</text>`))}),l+="</g>";const p=new Set;let h=!1;l+=`<g${he("components")}>`,e.components.forEach((v,y)=>{const b=d.get(v.id??v.label);if(b===void 0)return;const E=v.kind??"component";if(p.add(E),l+=`<g${_(`components.${y}`)}>`,v.movement!==void 0&&v.movement!==0){h=!0;const N=r(pv(v.x)+v.movement);l+=`<line x1="${pn(b.x)}" y1="${pn(b.y)}" x2="${pn(N)}" y2="${pn(b.y)}" stroke="var(--muted)" stroke-width="1.5" stroke-dasharray="4 3" marker-end="url(#skOpen)"/>`}l+=`<circle cx="${pn(b.x)}" cy="${pn(b.y)}" r="7" ${zU[E]}/>`;const $=b.y-14>s+12,A=lt(v.label,18,2),T=E==="build"?"t-name c-accent":"t-name";A.forEach((N,j)=>{const P=$?b.y-14-(A.length-1-j)*14:b.y+22+j*14;l+=`<text x="${pn(b.x)}" y="${pn(P)}" class="${T}" text-anchor="middle">${S(N)}</text>`}),l+="</g>"}),l+="</g></svg>";const m=["user","component","commodity","build","buy"].filter(v=>p.has(v)).map(v=>FU[v]);u&&m.push({swatch:"line",label:"depends on"}),h&&m.push({swatch:"edge-dashed",label:"movement"});const g=ot(m);return ct({tag:"WARDLEY",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...g.length>0?{legendHtml:g}:{}},l)}function pv(e){return Math.min(1,Math.max(0,e))}function pn(e){return Math.round(e*10)/10}var Ci=4,vn=9;function fv(e){const t=Math.max(0,Math.min(Ci,Math.round(e))),n=`<svg width="${vn*2+2}" height="${vn*2+2}" viewBox="0 0 ${vn*2+2} ${vn*2+2}" role="img" aria-label="${t} of ${Ci}">`,s=`<circle cx="${vn+1}" cy="${vn+1}" r="${vn}" fill="var(--white)" stroke="var(--navy)" stroke-width="1.4"/>`;if(t===0)return`${n}${s}</svg>`;if(t===Ci)return`${n}${s}<circle cx="${vn+1}" cy="${vn+1}" r="${vn}" fill="var(--navy)"/></svg>`;const o=t/Ci*360,r=(o-90)*Math.PI/180,i=vn+1+vn*Math.cos(r),l=vn+1+vn*Math.sin(r),d=o>180?1:0,u=`<path d="M ${vn+1} ${vn+1} L ${vn+1} 1 A ${vn} ${vn} 0 ${d} 1 ${N0(i)} ${N0(l)} Z" fill="var(--navy)"/>`;return`${n}${s}${u}</svg>`}function N0(e){return Math.round(e*10)/10}function HU(e){const t=e.columns,n=t.map((g,v)=>e.rows.reduce((y,b)=>y+(b.ratings[v]??0)*(b.weight??1),0)),s=Math.max(...n,0),o=e.recommend?.toLowerCase(),r=t.map((g,v)=>{const y=o!==void 0&&g.toLowerCase()===o,b=y?'<span class="hv-rec">RECOMMENDED</span>':"";return`<th class="hv-col${y?" hv-is-rec":""}"${_(`columns.${v}`)}>${S(g)}${b}</th>`}).join(""),i=e.rows.map((g,v)=>{const y=g.weight!==void 0&&g.weight!==1?`<span class="hv-weight"${_(`rows.${v}.weight`)}>×${S(String(g.weight))}</span>`:"",b=g.note!==void 0?`<span class="hv-note"${_(`rows.${v}.note`)}>${S(g.note)}</span>`:"",E=t.map(($,A)=>{const T=o!==void 0&&$.toLowerCase()===o,N=g.ratings[A],j=N===void 0?'<span class="hv-na">—</span>':`${fv(N)}<span class="hv-sr">${Math.max(0,Math.min(Ci,Math.round(N)))} of ${Ci}</span>`;return`<td class="hv-cell${T?" hv-is-rec":""}"${_(`rows.${v}.ratings.${A}`)}>${j}</td>`}).join("");return`<tr${_(`rows.${v}`)}><td class="hv-crit"><span class="hv-label"${_(`rows.${v}.label`)}>${S(g.label)}</span>${y}${b}</td>${E}</tr>`}).join(""),l=`<tr class="hv-foot"><td>Weighted</td>${n.map((g,v)=>{const y=o!==void 0&&t[v]?.toLowerCase()===o,b=g===s&&s>0;return`<td class="hv-total${y?" hv-is-rec":""}${b?" hv-lead":""}">${N0(g)}</td>`}).join("")}</tr>`,[d,u]=e.scale??[],p=d!==void 0&&u!==void 0?`<div class="diagram-legend hv-scale"><span class="lg-title t-eyebrow">Legend</span><span class="lg-item">${fv(0)}<span class="lg-label">${S(d)}</span></span><span class="lg-item">${fv(Ci)}<span class="lg-label">${S(u)}</span></span></div>`:"",h=e.title!==void 0?`<div class="hv-head">${S(e.title)}</div>`:"",m=e.description!==void 0?`<p class="hv-desc"${_("description")}>${S(e.description)}</p>`:"";return`<div class="harvey">${h}${m}<div class="hv-scroll"><table class="hv-table"><thead><tr${he("columns")}><th class="hv-crit">Criteria</th>${r}</tr></thead><tbody${he("rows")}>${i}${l}</tbody></table>${p}</div></div>`}var WU=[{key:"situation",label:"Situation",hint:"what everyone already agrees on"},{key:"complication",label:"Complication",hint:"what changed"},{key:"question",label:"Question",hint:"what has to be settled"}];function UU(e){const t=WU.filter(i=>typeof e[i.key]=="string"&&e[i.key]!=="").map((i,l)=>{const d=e[i.key];return`<div class="sq-row"${_(i.key)}><span class="sq-num">${l+1}</span><div class="sq-body"><span class="sq-label">${S(i.label)}</span><p class="sq-text">${vo(d)}</p></div></div>`}).join(""),n=e.because!==void 0&&e.because.length>0?`<ul class="sq-because"${he("because")}>`+e.because.map((i,l)=>`<li${_(`because.${l}`)}>${vo(i)}</li>`).join("")+"</ul>":"",s=typeof e.answer=="string"&&e.answer!==""?`<div class="sq-answer"${_("answer")}><span class="sq-label sq-label-answer">Answer</span><p class="sq-text sq-text-answer">${vo(e.answer)}</p>${n}</div>`:"",o=e.title!==void 0?`<div class="sq-head">${S(e.title)}</div>`:"",r=e.description!==void 0?`<p class="sq-desc"${_("description")}>${S(e.description)}</p>`:"";return`<div class="scqa">${o}${r}${t}${s}</div>`}var hv={pos:"sc-pos",neg:"sc-neg",base:"sc-base"};function KU(e){const t=e.cases,n=t.map((d,u)=>{const p=d.tone!==void 0?` ${hv[d.tone]??""}`:"",h=d.tone==="base"?'<span class="sn-badge">BASE CASE</span>':"",m=d.note!==void 0?`<span class="sn-note">${S(d.note)}</span>`:"";return`<th class="sn-case${p}"${_(`cases.${u}`)}>${S(d.label)}${h}${m}</th>`}).join(""),s=e.drivers.map((d,u)=>{const p=t.map((h,m)=>{const g=h.tone!==void 0?` ${hv[h.tone]??""}`:"",v=h.values[u];return v===void 0?`<td class="sn-cell sn-blank${g}">·</td>`:`<td class="sn-cell${g}"${_(`cases.${m}.values.${u}`)}>${S(v)}</td>`}).join("");return`<tr><td class="sn-driver"${_(`drivers.${u}`)}>${S(d)}</td>${p}</tr>`}).join(""),r=t.some(d=>d.outcome!==void 0)?`<tr class="sn-outcome"><td>${S(e.outcomeLabel??"Outcome")}</td>`+t.map((d,u)=>{const p=d.tone!==void 0?` ${hv[d.tone]??""}`:"";return d.outcome===void 0?`<td class="${p.trim()}">—</td>`:`<td class="${p.trim()}"${_(`cases.${u}.outcome`)}>${S(d.outcome)}</td>`}).join("")+"</tr>":"",i=e.title!==void 0?`<div class="sn-head">${S(e.title)}</div>`:"",l=e.description!==void 0?`<p class="sn-desc"${_("description")}>${S(e.description)}</p>`:"";return`<div class="scenarios">${i}${l}<div class="sn-scroll"><table class="sn-table"><thead><tr${he("cases")}><th class="sn-driver">Driver</th>${n}</tr></thead><tbody${he("drivers")}>${s}${r}</tbody></table></div></div>`}var up=Math.tan(62*Math.PI/180),l2=64,VU=28,Mr=26;function mv(e,t,n){const s=lt(e,t,n),o=s.join(" "),r=String(e).trim().split(/\s+/).join(" "),i=o!==r&&s.length>0;if(i){const l=s[s.length-1]??"";s[s.length-1]=`${l}…`}return{lines:s,truncated:i}}var gv=(e,t)=>e.truncated?`<title>${S(t)}</title>`:"",vv=e=>Math.max(0,...e.map(t=>t.length));function GU(e){const t=e.causes.map((X,B)=>{const te=mv(X.label,16,4),ee=(X.items??[]).map(R=>{const z=mv(R,24,2);return{full:R,clamped:z,w:vv(z.lines)*6.2}}),W=14+Math.max(1,...ee.map(R=>R.clamped.lines.length))*13,K=ee.length>0?52+(ee.length-1)*W:l2;return{idx:B,label:X.label,labelClamped:te,labelW:vv(te.lines)*7.4,items:ee,gap:W,needH:K}}),n=t.filter(X=>X.idx%2===0),s=t.filter(X=>X.idx%2===1),o=X=>X.length===0?0:Math.max(l2,...X.map(B=>B.needH)),r=o(n),i=o(s),l=X=>X.length===0?0:Math.max(...X.map(B=>B.labelClamped.lines.length))*15+12,d=l(n),u=l(s),p=(X,B)=>{let te=B/up+X.labelW/2+4;return X.items.forEach((ee,H)=>{const W=B-(26+H*X.gap);te=Math.max(te,W/up+10+ee.w)}),Math.max(te,40)},h=(X,B,te)=>{const ee=[];let H=te;return X.forEach((W,K)=>{const R=H+(K===0?0:VU)+p(W,B);ee.push(R),H=R}),ee},m=h(n,r,Mr),g=h(s,i,Mr+44),v=mv(e.effect,16,3),y=v.lines,b=Math.max(96,vv(y)*7.4+28),E=y.length*16+18,$=Math.max(Mr+d+r,Mr+E/2+4),A=Math.max($+i+u,$+E/2+4)+Mr,N=Math.max(Mr+40,...m,...g)+30+6,j=N+b+Mr,P=X=>X.toFixed(1);let I=`<svg viewBox="0 0 ${P(j)} ${P(A)}" width="${P(j)}" height="${P(A)}" role="img"><title>Fishbone</title>`;I+=`<path d="M ${Mr} ${P($)} L ${P(N)} ${P($)}" fill="none" stroke="var(--ink)" stroke-width="1.5"/>`;let O=!1;const C=(X,B,te,ee)=>{const H=B-te/up,W=$+ee*te;let K=`<g${_(`causes.${X.idx}`)}>`;K+=`<path d="M ${P(B)} ${P($)} L ${P(H)} ${P(W)}" fill="none" stroke="var(--ink)" stroke-width="1.25"/>`;const R=15,z=X.labelClamped.lines.length,Y=ee===-1?W-10-(z-1)*R:W+20;return K+=`<g${_(`causes.${X.idx}.label`)}>${gv(X.labelClamped,X.label)}`,X.labelClamped.lines.forEach((V,re)=>{K+=`<text x="${P(H)}" y="${P(Y+re*R)}" class="t-name" text-anchor="middle">${S(V)}</text>`}),K+="</g>",X.items.length>0&&(O=!0,K+=`<g${he(`causes.${X.idx}.items`)}>`,X.items.forEach((V,re)=>{const Q=te-(26+re*X.gap),ne=$+ee*Q,Z=B-Q/up;let q=`<g${_(`causes.${X.idx}.items.${re}`)}>${gv(V.clamped,V.full)}`;q+=`<path d="M ${P(Z-6)} ${P(ne)} L ${P(Z)} ${P(ne)}" stroke="var(--muted)" stroke-width="1.25"/>`;const de=V.clamped.lines.length;V.clamped.lines.forEach((le,J)=>{q+=`<text x="${P(Z-10)}" y="${P(ne+3.5-(de-1)*13/2+J*13)}" class="t-sub c-ink" text-anchor="end">${S(le)}</text>`}),K+=q+"</g>"}),K+="</g>"),K+"</g>"};I+=`<g${he("causes")}>`,n.forEach((X,B)=>{const te=m[B];te!==void 0&&(I+=C(X,te,r,-1))}),s.forEach((X,B)=>{const te=g[B];te!==void 0&&(I+=C(X,te,i,1))}),I+="</g>";const D=$-E/2;I+=`<g${_("effect")}>${gv(v,e.effect)}`,I+=`<rect x="${P(N)}" y="${P(D)}" width="${P(b)}" height="${P(E)}" rx="4" fill="var(--accent-tint)" stroke="var(--accent)" stroke-width="1.5"/>`,y.forEach((X,B)=>{I+=`<text x="${P(N+b/2)}" y="${P($+4.5-(y.length-1)*16/2+B*16)}" class="t-name c-accent" text-anchor="middle">${S(X)}</text>`}),I+="</g></svg>";const F=[{swatch:"node-accent",label:"effect"}];F.push({swatch:"chip",chip:"BONE",label:"cause category"}),O&&F.push({swatch:"chip",chip:"—",label:"specific cause"});const U=ot(F);return ct({tag:"FISHBONE",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...U.length>0?{legendHtml:U}:{}},I)}var YU=170,XU=128,c2=40;function QU(e){return typeof e=="string"?{title:e}:e}function ZU(e){const t=e.backbone.length,n=XU+t*YU;let s=`<div class="sm-row sm-head"${he("backbone")} style="min-width:${n}px">`;s+='<div class="sm-gutter"></div>',e.backbone.forEach((i,l)=>{const d=i.label.length>c2;s+=`<div class="sm-colcell"><div class="sm-step"${_(`backbone.${l}`)}${d?` title="${S(i.label)}"`:""}>`,s+=`<span class="t-eyebrow sm-step-eyebrow">Step ${l+1}</span>`,s+=`<div class="sm-step-label t-name"${_(`backbone.${l}.label`)}>${S(i.label)}</div>`,i.note!==void 0&&(s+=`<div class="sm-step-note">${S(i.note)}</div>`),s+="</div></div>"}),s+="</div>";let o=`<div${he("slices")}>`;e.slices.forEach((i,l)=>{o+=`<div class="sm-row sm-band${l===0?" sm-band-first":""}"${_(`slices.${l}`)} style="min-width:${n}px">`,o+=`<div class="sm-gutter sm-slice"${_(`slices.${l}.label`)}>${S(i.label)}</div>`,i.cells.forEach((d,u)=>{o+=`<div class="sm-colcell sm-cell"${he(`slices.${l}.cells.${u}`)}>`,d.forEach((p,h)=>{const m=QU(p),g=m.title.length>c2;o+=`<div class="sm-card"${_(`slices.${l}.cells.${u}.${h}`)}${g?` title="${S(m.title)}"`:""}>`,o+=`<div class="sm-card-title">${S(m.title)}</div>`,m.tag!==void 0&&(o+=`<span class="sm-card-tag">${S(m.tag)}</span>`),o+="</div>"}),o+="</div>"}),o+="</div>"}),o+="</div>";const r=`<div class="storymap"><div class="sm-scroll">${s}${o}</div></div>`;return ct({tag:"STORY MAP",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{}},r)}function JU(e,t){return`<span class="evc-chip"${_(t)}>${S(e)}</span>`}function d2(e,t,n){const s=n.length>0?n.map((o,r)=>JU(o,`${t}.${r}`)).join(""):'<span class="evc-none t-sub">—</span>';return`<div class="evc-party"><span class="evc-party-label t-eyebrow">${S(e)}${n.length>0?` (${n.length})`:""}</span><div class="evc-chips"${he(t)}>${s}</div></div>`}function pp(e,t,n){return`<span class="evc-fact"${_(n)}><span class="evc-fact-k t-eyebrow">${S(e)}</span><span class="evc-fact-v">${S(t)}</span></span>`}function u2(e,t,n){const s=e.map((o,r)=>{const i=n!==void 0&&o.name===n,l=i?"#":o.required===!0?"":"?",d=i?' class="evc-key"':"",u=o.example!==void 0?` <span class="evc-eg">e.g. ${S(o.example)}</span>`:"";return`<tr${d}${_(`${t}.${r}`)}><td class="evc-mark">${l}</td><td class="evc-fname"${_(`${t}.${r}.name`)}>${S(o.name)}</td><td class="evc-type"${_(`${t}.${r}.type`)}>${S(o.type)}</td><td class="evc-desc"><span${_(`${t}.${r}.desc`)}>${S(o.desc??"")}</span>${u}</td></tr>`}).join("");return`<table class="evc-table"><thead><tr><th></th><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody${he(t)}>${s}</tbody></table>`}function eK(e){const n='<div class="evc-head">'+('<span class="evc-eyebrow t-eyebrow">EVENT'+(e.version!==void 0?`<span class="evc-sep">·</span><span${_("version")}>${S(e.version)}</span>`:"")+"</span>")+`<span class="evc-name"${_("name")}>${S(e.name)}</span>`+(e.channel!==void 0?`<span class="evc-channel"${_("channel")}><span class="t-eyebrow">channel</span>${S(e.channel)}</span>`:"")+"</div>",s=[];e.title!==void 0&&s.push(`<div class="evc-title">${S(e.title)}</div>`),e.summary!==void 0&&s.push(`<p class="evc-summary"${_("summary")}>${S(e.summary)}</p>`),e.description!==void 0&&s.push(`<p class="evc-desc-p">${S(e.description)}</p>`);const o=e.producers??[],r=e.consumers??[];(o.length>0||r.length>0)&&s.push('<div class="evc-strip">'+d2("Producers","producers",o)+'<span class="evc-arrow t-arrow" aria-hidden="true">→</span>'+d2("Consumers","consumers",r)+"</div>");const i=[];e.delivery!==void 0&&i.push(pp("delivery",e.delivery,"delivery")),e.ordering!==void 0&&i.push(pp("ordering",e.ordering,"ordering")),e.key!==void 0&&i.push(pp("key",e.key,"key")),e.retention!==void 0&&i.push(pp("retention",e.retention,"retention")),i.length>0&&s.push(`<div class="evc-facts">${i.join("")}</div>`);const l=e.schema??[];if(l.length>0){const p=e.key!==void 0&&l.some(g=>g.name===e.key),h=l.some(g=>g.required!==!0&&!(p&&g.name===e.key)),m=[];p&&m.push('<span class="evc-mark-k">#</span> partition key'),h&&m.push('<span class="evc-mark-k">?</span> optional'),s.push('<div class="evc-section">Payload</div>'+u2(l,"schema",e.key)+(m.length>0?`<div class="evc-keyline t-sub">${m.join(" · ")}</div>`:""))}const d=e.headers??[];d.length>0&&s.push(`<div class="evc-section">Headers</div>${u2(d,"headers",void 0)}`),e.example!==void 0&&s.push(`<div class="evc-section">Example</div><pre class="ep-ex"${_("example")}>${Sf(e.example)}</pre>`);const u=e.errors??[];if(u.length>0){const p=u.map((h,m)=>`<tr${_(`errors.${m}`)}><td class="evc-fname"${_(`errors.${m}.name`)}>${S(h.name)}</td><td class="evc-desc"${_(`errors.${m}.when`)}>${S(h.when??"")}</td></tr>`).join("");s.push(`<div class="evc-section">Errors</div><table class="evc-table"><thead><tr><th>Error</th><th>When</th></tr></thead><tbody${he("errors")}>${p}</tbody></table>`)}return e.note!==void 0&&s.push(`<p class="evc-note"${_("note")}>${S(e.note)}</p>`),`<div class="eventcontract">${n}<div class="evc-body">${s.join("")}</div></div>`}var vc=22,yv=22,tK=18,nK=176,yc=44,xc=34,sK=36,oK=34,p2=22,rK=28,fp=7.4,iK=6,Kp=6.3,xv={ok:"",failed:"FAILED",skipped:"SKIPPED",compensated:"COMPENSATED"},kv="ORCHESTRATOR",aK="COMPENSATE",LA=e=>e==="accent"?" c-accent":e==="negative"?" c-negative":"";function f2(e,t,n,s,o){const r=Math.round(n.length*Kp+10),i=o?e-r:e,l=s==="accent"?"var(--accent)":s==="negative"?"var(--negative)":"var(--rule-solid)";return`<rect x="${i}" y="${t-8}" width="${r}" height="15" rx="2" fill="var(--paper)" stroke="${l}" stroke-width="1"/><text x="${i+r/2}" y="${t+3.5}" class="t-eyebrow${LA(s)}" text-anchor="middle">${S(n)}</text>`}var bv=e=>Math.max(0,...e.map(t=>t.length));function lK(e,t){return e.map((n,s)=>n.status!==void 0?n.status:t<0?"ok":s<t?"compensated":s===t?"failed":"skipped")}function cK(e){const t=e.steps,n=t.length,s=e.mode==="orchestration",o=e.coordinator??"Orchestrator",r=e.failAt!==void 0?t.findIndex(z=>z.id===e.failAt):t.findIndex(z=>z.status==="failed"),i=lK(t,r),l=t.map(z=>lt(z.name,p2,3)),d=t.map(z=>z.action!==void 0?lt(z.action,rK,2):[]),u=t.map(z=>z.compensate!==void 0?lt(z.compensate,p2,3):[]),p=Math.max(1,...l.map(z=>z.length)),h=Math.max(0,...d.map(z=>z.length)),m=Math.max(0,...u.map(z=>z.length)),g=m>0,v=30+p*15+(h>0?h*13+4:0)+8,y=22+m*15+8,b=[nK];t.forEach((z,Y)=>{const V=xv[i[Y]??"ok"],re=V.length>0?V.length*Kp+10+8:0;b.push(34+z.service.length*Kp+8+re+10),b.push(bv(l[Y]??[])*fp+24),b.push(bv(d[Y]??[])*iK+24),b.push(bv(u[Y]??[])*fp+24)});let E=Math.ceil(Math.max(...b));if(s){const z=14+o.length*fp+12+kv.length*Kp+10+14,Y=n*E+(n-1)*yc;z>Y&&(E=Math.ceil((z-(n-1)*yc)/n))}const $=z=>vc+z*(E+yc),A=z=>$(z)+E/2,T=yv,N=s?yv+xc+sK:yv,j=N+v/2,P=N+v+oK,I=P+y/2,O=vc*2+n*E+(n-1)*yc,C=(g?P+y:N+v)+tK,D=[];if(r>0&&g)for(let z=r-1;z>=0;z--)(u[z]??[]).length>0&&D.push(z);const F=z=>z,U=z=>{const Y=D.indexOf(z);return Y<0?z:n+Y},X=Sn("Saga",e.title,[wt(n,"step"),...u.filter(z=>z.length>0).length>0?[wt(u.filter(z=>z.length>0).length,"compensation")]:[]]);let B=`<svg viewBox="0 0 ${O} ${C}"${X.attrs}>${X.title}`;if(s){const z=vc+14,Y=z+o.length*fp+12;B+=`<g${_("coordinator")}><rect x="${vc}" y="${T}" width="${O-vc*2}" height="${xc}" rx="4" fill="var(--paper-2)" stroke="var(--rule-solid)" stroke-width="1"/><text x="${z}" y="${T+xc/2+4.5}" class="t-name">${S(o)}</text>`+f2(Y,T+xc/2,kv,"muted",!1)+"</g>",B+='<g class="sg-fanout">';for(let V=0;V<n;V++)B+=`<line x1="${A(V)}" y1="${T+xc}" x2="${A(V)}" y2="${N}" stroke="var(--muted)" stroke-width="1.25" marker-end="url(#skArrow)"${hn(F(V))}/>`;B+="</g>"}let te=!1,ee=!1;B+='<g class="sg-forward">';for(let z=0;z<n-1;z++){const Y=r>=0&&z>=r;Y?ee=!0:te=!0;const V=Y?' stroke-dasharray="5 4"':"",re=Y?"skOpen":"skArrow";B+=`<line x1="${$(z)+E}" y1="${j}" x2="${$(z+1)}" y2="${j}" stroke="var(--muted)" stroke-width="1.5"${V} marker-end="url(#${re})"${hn(F(z+1))}/>`}B+="</g>";const H=new Set;B+=`<g${he("steps")}>`,t.forEach((z,Y)=>{const V=i[Y]??"ok";H.add(V);const re=$(Y),Q=Y===r,ne=V==="failed",Z=V==="skipped",q=Q?"var(--accent)":ne?"var(--negative)":Z?"var(--rule-solid)":"var(--ink)",de=Q?"var(--accent-tint)":ne?"var(--negative-tint)":Z?"var(--paper-2)":"var(--paper)",le=Z?1:1.5,J=Q?"accent":ne?"negative":"muted",ue=LA(J),ve=N+16;let we=`<rect x="${re}" y="${N}" width="${E}" height="${v}" rx="4" fill="${de}" stroke="${q}" stroke-width="${le}"/><circle cx="${re+19}" cy="${ve}" r="7" fill="var(--paper)" stroke="${Q?"var(--accent)":"var(--muted)"}" stroke-width="1"/><text x="${re+19}" y="${ve+3}" class="t-badge${ue}" text-anchor="middle">${Y+1}</text><text x="${re+34}" y="${ve+3}" class="t-eyebrow${ue}"${_(`steps.${Y}.service`)}>${S(z.service)}</text>`;const $e=xv[V];$e.length>0&&(we+=f2(re+E-10,ve,$e,J,!0)),(l[Y]??[]).forEach((Be,Ge)=>{we+=`<text x="${re+12}" y="${N+30+11+Ge*15}" class="t-name${Q?" c-accent":""}">${S(Be)}</text>`}),(d[Y]??[]).forEach((Be,Ge)=>{we+=`<text x="${re+12}" y="${N+30+p*15+12+Ge*13}" class="t-sub"${Ge===0?_(`steps.${Y}.action`):""}>${S(Be)}</text>`});const Me=u[Y]??[];if(Me.length>0){const Be=hn(U(Y));we+=`<line x1="${A(Y)}" y1="${N+v}" x2="${A(Y)}" y2="${P}" stroke="var(--rule-solid)" stroke-width="1" stroke-dasharray="2 3"${Be}/><g${_(`steps.${Y}.compensate`)}${Be}><rect x="${re}" y="${P}" width="${E}" height="${y}" rx="4" fill="var(--paper)" stroke="var(--ink)" stroke-width="1.25" stroke-dasharray="4 3"/><text x="${re+12}" y="${P+14}" class="t-eyebrow">${aK}</text>`,Me.forEach((Ge,fe)=>{we+=`<text x="${re+12}" y="${P+22+12+fe*15}" class="t-name">${S(Ge)}</text>`}),we+="</g>"}B+=`<g${_(`steps.${Y}`)}${hn(F(Y))}>${we}</g>`}),B+="</g>";let W=!1;if(D.length>0){W=!0;const z='fill="none" stroke="var(--negative)" stroke-width="1.5" stroke-dasharray="5 4" marker-end="url(#skErr)"';B+='<g class="sg-compflow">';const Y=D[0]??0,V=$(r)-yc/2,re=N+v-12;B+=`<path d="M${$(r)},${re} H${V} V${I} H${$(Y)+E}" ${z}${hn(U(Y))}/>`;for(let Q=1;Q<D.length;Q++){const ne=D[Q-1]??0,Z=D[Q]??0;B+=`<path d="M${$(ne)},${I} H${$(Z)+E}" ${z}${hn(U(Z))}/>`}B+="</g>"}B+="</svg>";const K=[];s&&K.push({swatch:"chip",chip:kv,label:"coordinates every step"}),K.push({swatch:"node",label:"step"}),g&&K.push({swatch:"node-dashed",label:"compensation"}),r>=0&&K.push({swatch:"node-accent",label:"failure point"}),H.has("compensated")&&K.push({swatch:"chip",chip:xv.compensated,label:"undone"}),H.has("skipped")&&K.push({swatch:"node-fill2",label:"skipped"}),te&&K.push({swatch:"edge",label:"next"}),ee&&K.push({swatch:"edge-dashed",label:"not reached"}),W&&K.push({swatch:"edge-negative-dashed",label:"compensating flow"});const R=ot(K);return ct({tag:"SAGA",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...R.length>0?{legendHtml:R}:{}},B)}var _a=26,dK=260,uK=16,h2=7,m2=28,pK=6.2;function g2(e){return e.length>m2?`${e.slice(0,m2-1)}…`:e}function v2(e,t){const n=e.map((r,i)=>({y:r,tie:t[i]??0,i})).sort((r,i)=>r.y-i.y||r.tie-i.tie||r.i-i.i),s=e.slice();let o=-1/0;for(const{y:r,i}of n){const l=Math.max(r,o+uK);s[i]=l,o=l}return s}function fK(e){return e==="negative"?"negative":e==="focal"?"accent":"plain"}var hK={plain:"var(--muted)",accent:"var(--accent)",negative:"var(--negative)"},y2={plain:"t-sub c-ink",accent:"t-sub c-accent",negative:"t-sub c-negative"};function mK(e){const t=e.items,n=e.unit??"",s=F=>n===""?String(F):n==="%"?`${F}${n}`:`${F} ${n}`;let o=Math.min(...t.map(F=>Math.min(F.from,F.to))),r=Math.max(...t.map(F=>Math.max(F.from,F.to)));o===r&&(o-=1,r+=1);const i=_a+34,l=Math.max(160,t.length*22),d=F=>i+(r-F)/(r-o)*l,u=t.map(F=>d(F.from)),p=t.map(F=>d(F.to)),h=v2(u,u),m=v2(p,u),g=t.map(F=>`${g2(F.label)} ${s(F.from)}`),v=t.map(F=>`${s(F.to)} ${g2(F.label)}`),y=F=>Math.max(30,...F.map(U=>U.length*pK)),b=_a+y(g)+12,E=b+dK,$=E+12+y(v)+_a,A=Math.max(i+l,...h,...m)+8,T=A+_a,N=F=>F.toFixed(1);let j=`<svg viewBox="0 0 ${N($)} ${N(T)}" role="img"><title>Slopegraph</title>`;const P=F=>`<line x1="${N(F)}" y1="${N(i-8)}" x2="${N(F)}" y2="${N(A)}" stroke="var(--rule-solid)" stroke-width="1"/>`;j+=P(b)+P(E),j+=`<text x="${N(b)}" y="${N(_a+8)}" class="t-eyebrow" text-anchor="middle"${_("left")}>${S(e.left)}</text>`,j+=`<text x="${N(E)}" y="${N(_a+8)}" class="t-eyebrow" text-anchor="middle"${_("right")}>${S(e.right)}</text>`;const I=new Set,O=Xn(t.map(F=>F.accent));j+=`<g${he("items")}>`,t.forEach((F,U)=>{const X=fK(O[U]);I.add(X);const B=hK[X],te=X!=="plain"?' font-weight="600"':"",ee=u[U]??i,H=p[U]??i,W=h[U]??i,K=m[U]??i;let R=`<g${_(`items.${U}`)}>`;R+=`<title>${S(`${F.label}: ${s(F.from)} → ${s(F.to)}`)}</title>`,R+=`<line x1="${N(b)}" y1="${N(ee)}" x2="${N(E)}" y2="${N(H)}" stroke="${B}" stroke-width="${X!=="plain"?1.75:1.25}"/>`,R+=`<circle cx="${N(b)}" cy="${N(ee)}" r="3" fill="${X==="plain"?"var(--ink)":B}"/>`,R+=`<circle cx="${N(E)}" cy="${N(H)}" r="3" fill="${X==="plain"?"var(--ink)":B}"/>`,Math.abs(W-ee)>h2&&(R+=`<line x1="${N(b-8)}" y1="${N(W)}" x2="${N(b-2)}" y2="${N(ee)}" stroke="var(--rule-solid)" stroke-width="1"/>`),Math.abs(K-H)>h2&&(R+=`<line x1="${N(E+2)}" y1="${N(H)}" x2="${N(E+8)}" y2="${N(K)}" stroke="var(--rule-solid)" stroke-width="1"/>`),R+=`<text x="${N(b-10)}" y="${N(W+3.5)}" class="${y2[X]}" text-anchor="end"${te}${_(`items.${U}.from`)}>${S(g[U]??"")}</text>`,R+=`<text x="${N(E+10)}" y="${N(K+3.5)}" class="${y2[X]}" text-anchor="start"${te}${_(`items.${U}.to`)}>${S(v[U]??"")}</text>`,j+=R+"</g>"}),j+="</g></svg>";const C=[];I.has("plain")&&C.push({swatch:"fill",fill:"var(--muted)",label:"item"}),I.has("accent")&&C.push({swatch:"fill",fill:"var(--accent)",label:"focal item"}),I.has("negative")&&C.push({swatch:"fill",fill:"var(--negative)",label:"negative"});const D=ot(C);return ct({tag:"SLOPEGRAPH",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...D.length>0?{legendHtml:D}:{}},j)}var Mf={server:"SVC",client:"CLIENT",db:"DB",queue:"QUEUE",cache:"CACHE",internal:"INT"},hp=14,gK=136,wv=520,vK=24,Lc=30,yK=Lc+8,$v=24,xi=14,x2=7,xK=50,kK=64,k2=6,b2=5.7,Sv=6.4,Ev=13,bK=2,wK=32;function Mv(e){return Number.isInteger(e)?String(e):String(Math.round(e*100)/100)}function $K(e,t){const n=e/t,s=10**Math.floor(Math.log10(n));for(const o of[1,2,2.5,5,10])if(o*s>=n)return o*s;return 10*s}function SK(e){const t=new Map;for(const n of e)t.has(n.id)||t.set(n.id,n);return e.map(n=>{let s=0,o=n;for(;o!==void 0&&o.parent!==void 0&&s<wK;){const r=t.get(o.parent);if(r===void 0||r===o)break;s+=1,o=r}return s})}function EK(e){const t=new Set(e.map(r=>r.id)),n=e.findIndex(r=>r.parent===void 0||!t.has(r.parent)),s=new Set;if(n<0)return s;let o=n;s.add(o);for(let r=0;r<e.length;r++){const i=e[o]?.id;let l=-1;if(e.forEach((d,u)=>{d.parent!==i||s.has(u)||(l<0||d.duration>(e[l]?.duration??0))&&(l=u)}),l<0)break;s.add(l),o=l}return s}function MK(e){const t=new Map;for(const s of e)s.kind===void 0||!(s.kind in Mf)||t.set(s.kind,(t.get(s.kind)??0)+1);let n;for(const[s,o]of t)(n===void 0||o>(t.get(n)??0))&&(n=s);return n===void 0?void 0:Mf[n]}function AK(e,t){const n=e.map((o,r)=>({s:o,i:r})).filter(({s:o})=>o.attrs!==void 0&&Object.keys(o.attrs).length>0||o.note!==void 0);return n.length===0?"":`<div class="sp-details"><div class="sp-details-title t-eyebrow">Attributes</div><ul>${n.map(({s:o,i:r})=>{const i=o.attrs!==void 0&&Object.keys(o.attrs).length>0?`<span class="sp-d-attrs"${_(`spans.${r}.attrs`)}>`+Object.entries(o.attrs).map(([d,u])=>`<span class="sp-d-attr">${S(d)}=${S(String(u))}</span>`).join("")+"</span>":"",l=o.note!==void 0?`<span class="sp-d-note"${_(`spans.${r}.note`)}>${S(o.note)}</span>`:"";return`<li${_(`spans.${r}`)}${hn(t.get(r)??0)}><span class="sp-d-span"><span class="sp-d-service">${S(o.service)}</span> ${S(o.name)}</span>`+i+l+"</li>"}).join("")}</ul></div>`}function CK(e){const t=e.spans??[],n=e.unit??"ms",s=hp+gK,o=Math.max(1e-9,...t.map(C=>C.start+C.duration)),r=C=>s+C/o*wv,i=[];for(const C of t)i.includes(C.service)||i.push(C.service);const l=SK(t),d=EK(t),u=[],p=[];let h=yK,m=s+wv;i.forEach((C,D)=>{const F=t.map((H,W)=>({s:H,idx:W})).filter(({s:H})=>H.service===C).sort((H,W)=>H.s.start-W.s.start||H.idx-W.idx),U=lt(C,18,2),X=MK(F.map(H=>H.s)),B=U.length>1?kK:xK,te=Math.max(B,F.length*$v+x2*2),ee=h;u.push({service:C,lines:U,chip:X,y:ee,h:te}),F.forEach(({s:H,idx:W},K)=>{const R=r(H.start),z=Math.max(bK,r(H.start+H.duration)-R),Y=ee+x2+K*$v+($v-xi)/2,V=H.name.length*k2+10<=z,re=H.error===!0;let Q=R+z+5+`${Mv(H.duration)} ${n}`.length*b2;re&&(Q+=8+3*Sv+8),V||(Q+=8+H.name.length*k2),m=Math.max(m,Q),p.push({idx:W,span:H,depth:l[W]??0,laneI:D,x:R,y:Y,w:z,crit:d.has(W),err:re,nameInside:V,right:Q})}),h+=te});const g=h,v=Math.ceil(m+vK),y=g+8,b=new Map;[...p].sort((C,D)=>C.span.start-D.span.start||C.idx-D.idx).forEach((C,D)=>b.set(C.idx,D));const E=C=>hn(b.get(C)??0),$=Sn("Trace waterfall",e.title,[wt(t.length,"span")]);let A=`<svg viewBox="0 0 ${v} ${y}"${$.attrs}>${$.title}`;const T=$K(o,6);A+='<g class="sp-axis-g">';for(let C=0;C<=o+1e-9;C+=T){const D=r(C);A+=`<line x1="${D}" y1="${Lc}" x2="${D}" y2="${g}" class="sp-grid"${ut}/><text x="${D}" y="${Lc-7}" class="t-arrow c-soft" text-anchor="middle">${Mv(C)} ${S(n)}</text>`}A+=`<line x1="${s}" y1="${Lc}" x2="${s+wv}" y2="${Lc}" class="sp-axis"/>`,A+="</g>",u.forEach((C,D)=>{D>0&&(A+=`<line x1="0" y1="${C.y}" x2="${v}" y2="${C.y}" class="sp-lane-rule"${ut}/>`);const F=C.y+21;if(A+='<g class="sp-lane">',C.lines.forEach((U,X)=>{A+=`<text x="${hp}" y="${F+X*15}" class="t-name">${S(U)}</text>`}),C.chip!==void 0){const U=F+(C.lines.length-1)*15+8,X=Math.round(C.chip.length*Sv+10);A+=`<rect x="${hp}" y="${U}" width="${X}" height="${Ev}" rx="2" class="sp-chip"/><text x="${hp+5}" y="${U+9.5}" class="t-eyebrow sp-chip-text">${S(C.chip)}</text>`}A+="</g>"});const N=new Map;for(const C of p)N.has(C.span.id)||N.set(C.span.id,C);A+='<g class="sp-links">';for(const C of p){if(C.span.parent===void 0)continue;const D=N.get(C.span.parent);if(D===void 0||D===C)continue;const F=C.x,U=C.y>D.y,X=U?D.y+xi:D.y,B=U?C.y:C.y+xi;A+=`<line x1="${F}" y1="${X}" x2="${F}" y2="${B}" class="sp-link"${hn(Math.max(b.get(C.idx)??0,b.get(D.idx)??0))}/>`}A+="</g>",A+=`<g${he("spans")}>`;for(const C of p){const F=`sp-bar ${C.depth===0?"d0":C.depth===1?"d1":"d2"}${C.crit?" crit":""}${C.err?" err":""}`,X=!C.crit&&!C.err&&C.depth<2?"t-sub sp-on-dark":"t-sub c-ink",B=C.y+xi/2+3.5;let te=`<g${_(`spans.${C.idx}`)}${E(C.idx)}>`;te+=`<rect x="${C.x}" y="${C.y}" width="${C.w}" height="${xi}" rx="2" class="${F}"/>`,C.nameInside&&(te+=`<text x="${C.x+5}" y="${B}" class="${X}"${_(`spans.${C.idx}.name`)}>${S(C.span.name)}</text>`);let ee=C.x+C.w+5;const H=`${Mv(C.span.duration)} ${n}`;if(te+=`<text x="${ee}" y="${B}" class="t-arrow sp-dur"${_(`spans.${C.idx}.duration`)}>${S(H)}</text>`,ee+=H.length*b2+8,C.err){const W=Math.round(3*Sv+8);te+=`<rect x="${ee}" y="${C.y+(xi-Ev)/2}" width="${W}" height="${Ev}" rx="2" class="sp-chip err"/><text x="${ee+4}" y="${C.y+xi/2+3}" class="t-eyebrow sp-chip-text err">ERR</text>`,ee+=W+8}C.nameInside||(te+=`<text x="${ee}" y="${B}" class="t-sub c-ink"${_(`spans.${C.idx}.name`)}>${S(C.span.name)}</text>`),te+="</g>",A+=te}A+="</g>",A+="</svg>";const j=p.filter(C=>!C.crit&&!C.err),P=[];j.some(C=>C.depth===0)&&P.push({swatch:"fill",fill:"var(--ink)",label:"span"}),j.some(C=>C.depth===1)&&P.push({swatch:"fill",fill:"var(--muted)",label:"nested span"}),j.some(C=>C.depth>=2)&&P.push({swatch:"node-fill2",label:"nested twice or more"}),d.size>0&&P.push({swatch:"node-accent",label:"critical path"}),p.some(C=>C.err)&&P.push({swatch:"node-negative",label:"error"});const I=[];for(const C of t)C.kind===void 0||!(C.kind in Mf)||I.includes(C.kind)||(I.push(C.kind),P.push({swatch:"chip",chip:Mf[C.kind],label:C.kind}));const O=ot(P);return ct({tag:"SPANS",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...O.length>0?{legendHtml:O}:{}},A+AK(t,b))}var w2={done:"node-fill2",current:"node-accent-outline",next:"node-dashed",blocked:"node-negative"},NK=["done","current","next","blocked"];function TK(e){return Number.isInteger(e)?String(e):String(Math.round(e*10)/10)}function _K(e){const t=e.stages??[],n=new Set;let s=!1,o=`<div class="ro-strip"${he("stages")}>`;t.forEach((d,u)=>{const p=d.status!==void 0&&d.status in w2?d.status:void 0;p!==void 0&&n.add(p);const h=p!==void 0?` ro-s-${p}`:"",m=p!==void 0?`<span class="ro-status ro-st-${p}"${_(`stages.${u}.status`)}>${S(p)}</span>`:"",g=d.traffic!==void 0?`<div class="ro-traffic"${_(`stages.${u}.traffic`)}><div class="ro-track"><div class="ro-fill" style="width:${Math.min(100,Math.max(0,d.traffic))}%"></div></div><span class="ro-pct t-sub">${TK(d.traffic)}%</span></div>`:"",v=d.duration!==void 0?`<div class="ro-dur t-sub"${_(`stages.${u}.duration`)}>${S(d.duration)}</div>`:"",y=d.note!==void 0?`<div class="ro-note"${_(`stages.${u}.note`)}>${S(d.note)}</div>`:"";o+=`<div class="ro-stage${h}"${_(`stages.${u}`)}><span class="ro-n t-eyebrow">Stage ${u+1}</span><div class="ro-head"><span class="ro-name t-name"${_(`stages.${u}.name`)}>${S(d.name)}</span>${m}</div>`+g+v+y+"</div>";const b=u===t.length-1;if(!b||d.gate!==void 0){const E=d.gate!==void 0?`<span class="ro-gate t-arrow"${_(`stages.${u}.gate`)}>${S(d.gate)}</span>`:"";d.gate!==void 0&&(s=!0),o+=`<div class="ro-link${b?" ro-link-end":""}">${E}</div>`}}),o+="</div>";const r=NK.filter(d=>n.has(d)).map(d=>({swatch:w2[d],label:d}));s&&r.push({swatch:"chip",chip:"GATE",label:"gate — must pass to advance"});const i=ot(r),l=e.rollback!==void 0?`<div class="ro-rollback"${_("rollback")}><span class="t-eyebrow">Rollback</span><span class="ro-rollback-text">${S(e.rollback)}</span></div>`:"";return ct({tag:"ROLLOUT",...e.strategy!==void 0?{path:e.strategy}:{},...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...i.length>0?{legendHtml:i}:{},...l.length>0?{footerHtml:l}:{}},o)}var $2=.7,LK=.1,La=300,mp=36,Ar=12,IK=6.8,S2=6.2;function jK(e){return(e.lowerIsBetter!==!1?e.measured>e.budget:e.measured<e.budget)?"over":e.budget!==0&&Math.abs(e.measured-e.budget)/Math.abs(e.budget)<=LK?"near":"ok"}function E2(e){return!Number.isFinite(e)||Number.isInteger(e)?String(e):String(Math.round(e*100)/100)}function Av(e,t){return t!==void 0&&t!==""?`${E2(e)}${t.length<=3?"":" "}${t}`:E2(e)}var PK={over:"var(--negative)",near:"var(--accent)",ok:"var(--muted)"},OK={over:" c-negative",near:" c-accent",ok:" c-muted"},RK={over:"var(--negative)",near:"var(--rule-solid)",ok:"var(--rule-solid)"};function DK(e){const t=e.metrics,n=t.map(jK),s=X=>{const B=X.lowerIsBetter===!1?"≥":"≤",te=X.note!==void 0&&X.note!==""?` · ${X.note}`:"";return`budget ${B} ${Av(X.budget,X.unit)}${te}`},o=t.map(s),r=Math.max(120,...t.map(X=>X.metric.length*IK+8),...o.map(X=>X.length*S2+8)),i=16,l=16,d=Math.max(56,...t.map(X=>Av(X.measured,X.unit).length*S2+14)),u=44,p=i+r,h=p+La+8,m=h+d+6,g=m+u+l,v=e.context!==void 0&&e.context!==""?18:0,b=12+v+22,E=b+t.length*mp+10,$=p+La*$2,A=Sn("Performance budget",e.title,[wt(t.length,"metric")]);let T=`<svg viewBox="0 0 ${g} ${E}"${A.attrs}>${A.title}`;v>0&&(T+=`<text x="${i}" y="22" class="t-sub c-muted"${_("context")}>${S(e.context??"")}</text>`);const N=b-6,j=b+t.length*mp;T+=`<text x="${$}" y="${b-10}" class="t-eyebrow" text-anchor="middle">budget</text>`,T+=`<line x1="${$}" y1="${N}" x2="${$}" y2="${j}" stroke="var(--ink)" stroke-width="1" stroke-dasharray="4 3"/>`,T+=`<g${he("metrics")}>`,t.forEach((X,B)=>{const te=n[B]??"ok",ee=b+B*mp,H=ee+mp/2,K=(X.budget!==0?Math.max(0,X.measured/X.budget):X.measured>0?1/0:0)*La*$2,R=K>La,z=Math.max(0,Math.min(La,K)),Y=p+z,V=PK[te],re=Av(X.measured,X.unit);T+=`<g${_(`metrics.${B}`)} data-status="${te}">`+(B>0?`<line x1="${i}" y1="${ee}" x2="${g-l}" y2="${ee}" stroke="var(--rule)" stroke-width="1"${ut}/>`:"")+`<text x="${i}" y="${H-2}" class="pb-label"${_(`metrics.${B}.metric`)}>${S(X.metric)}</text><text x="${i}" y="${H+11}" class="t-sub c-soft"${_(`metrics.${B}.budget`)}>${S(o[B]??"")}</text><rect x="${p}" y="${H-Ar/2}" width="${La}" height="${Ar}" rx="2" fill="var(--paper-2)" stroke="var(--rule)" stroke-width="1"${ut}/><rect x="${p}" y="${H-Ar/2}" width="${z}" height="${Ar}" rx="2" fill="${V}"${_(`metrics.${B}.measured`)}/>`+(R?`<path d="M${Y-6} ${H-Ar/2-2} l -4 ${Ar+4} M${Y-2} ${H-Ar/2-2} l -4 ${Ar+4}" stroke="var(--paper)" stroke-width="2" fill="none"/>`:"")+`<text x="${h}" y="${H+3.5}" class="t-sub c-ink pb-val">${S(re)}</text><rect x="${m}" y="${H-7}" width="${u}" height="14" rx="2" fill="var(--paper)" stroke="${RK[te]}" stroke-width="1"/><text x="${m+u/2}" y="${H+3}" class="t-eyebrow${OK[te]}" text-anchor="middle">${te}</text></g>`}),T+="</g></svg>";const P=X=>n.filter(B=>B===X).length,I=P("over"),O=P("near"),C=P("ok"),D=[];I>0&&D.push({swatch:"fill",fill:"var(--negative)",label:"over budget"}),O>0&&D.push({swatch:"fill",fill:"var(--accent)",label:"near — within 10%"}),C>0&&D.push({swatch:"fill",fill:"var(--muted)",label:"within budget"}),D.push({swatch:"line-dashed",stroke:"var(--ink)",label:"budget"});const F=ot(D),U=`<div class="diagram-foot pb-foot"><span><strong>${I}</strong> over</span><span><strong>${O}</strong> near</span><span><strong>${C}</strong> ok</span></div>`;return ct({tag:"PERF BUDGET",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...F.length>0?{legendHtml:F}:{},footerHtml:U},T)}var M2=440,gp=34,A2=24,vp=6.2,BK=6.8,Cv=7;function zK(e){if(!(e>0))return 1;const t=Math.pow(10,Math.floor(Math.log10(e/5))),n=[1,2,2.5,5,10].map(r=>r*t);let s=n[0]??1,o=1/0;for(const r of n){const i=Math.ceil(e/r-1e-9),l=i>=4&&i<=6?Math.abs(i-5):10+Math.abs(i-5);l<o&&(s=r,o=l)}return s}var Ia=e=>Math.round(e*1e6)/1e6;function ja(e){return Number.isInteger(e)?String(e):String(Math.round(e*100)/100)}function FK(e,t,n,s,o){if(n&&e>0&&t>0){const h=Math.floor(Math.log10(e)),m=Math.ceil(Math.log10(t)-1e-9),g=Math.pow(10,h),v=Math.pow(10,Math.max(m,h+1)),y=Math.max(1,Math.log10(v)-Math.log10(g)),b=[];for(let A=h;A<=Math.log10(v)+1e-9;A++){const T=Math.pow(10,A);b.push(Ia(T)),y<=3&&T*10<=v+1e-9&&b.push(Ia(T*2),Ia(T*5))}const E=Math.log10(g),$=Math.log10(v)-E;return{lo:g,hi:v,ticks:b,log:!0,x:A=>s+(Math.log10(Math.max(A,g))-E)/$*o}}const r=Math.max(t-e,1e-9),i=zK(r),l=Ia(Math.floor(e/i)*i),d=Ia(Math.max(Math.ceil(t/i)*i,l+i)),u=[];for(let h=l;h<=d+1e-9;h+=i)u.push(Ia(h));const p=d-l;return{lo:l,hi:d,ticks:u,log:!1,x:h=>s+(h-l)/p*o}}function C2(e){return e.max??e.p999??e.p99}function qK(e){const t=e.rows,n=e.unit??"",s=Xn(t.map(C=>C.accent)),o=C=>C.slo??e.slo,r=Math.max(96,...t.map(C=>C.label.length*BK+12)),i=12,l=i+r,d=Math.min(...t.map(C=>C.p50)),u=Math.max(...t.map(C2),...t.map(C=>o(C)??-1/0)),p=FK(d,u,e.scale==="log",l,M2),h=l+M2,g=12+(e.slo!==void 0?16:0),v=g+t.length*gp+8,y=v+26,b=Math.max(0,...t.map(C=>(ja(C.p99).length+1)*vp)),E=h+A2+Math.max(0,b-A2+8),$=Sn("Latency percentiles",e.title,[wt(t.length,"row")]);let A=`<svg viewBox="0 0 ${E} ${y}"${$.attrs}>${$.title}`;A+=`<g${ut}>`;for(const C of p.ticks){const D=p.x(C);A+=`<line x1="${D}" y1="${g}" x2="${D}" y2="${v}" stroke="var(--rule)" stroke-width="1"/>`}A+="</g>",A+=`<line x1="${l}" y1="${v}" x2="${h}" y2="${v}" stroke="var(--rule-solid)" stroke-width="1"/>`;let T=-1/0;for(const C of p.ticks){const D=`${ja(C)}${n}`,F=D.length*vp,U=p.x(C);U-F/2<T+6||(A+=`<text x="${U}" y="${v+14}" class="t-sub c-soft" text-anchor="middle">${S(D)}</text>`,T=U+F/2)}if(e.slo!==void 0){const C=p.x(e.slo);A+=`<g${_("slo")}><line x1="${C}" y1="${g-4}" x2="${C}" y2="${v}" stroke="var(--ink)" stroke-width="1" stroke-dasharray="4 3"/><text x="${C}" y="${g-8}" class="t-eyebrow" text-anchor="middle">SLO ${S(ja(e.slo))}${S(n)}</text></g>`}let N=!1,j=!1,P=!1;A+=`<g${he("rows")}>`,t.forEach((C,D)=>{const F=g+D*gp,U=F+gp/2,X=o(C),B=X!==void 0&&C.p99>X;B&&(N=!0);const te=s[D]==="negative",ee={p50:p.x(C.p50),p90:C.p90!==void 0?p.x(C.p90):void 0,p95:C.p95!==void 0?p.x(C.p95):void 0,p99:p.x(C.p99),p999:C.p999!==void 0?p.x(C.p999):void 0,max:C.max!==void 0?p.x(C.max):void 0},H=p.x(C2(C));let W=`<g${_(`rows.${D}`)}${B?' data-over="1"':""}>`;if(D>0&&(W+=`<line x1="${i}" y1="${F}" x2="${E-8}" y2="${F}" stroke="var(--rule)" stroke-width="1"${ut}/>`),W+=`<text x="${i}" y="${U+4}" class="pc-label${te?" c-negative":""}"${_(`rows.${D}.label`)}>${S(C.label)}</text>`,C.slo!==void 0){const q=p.x(C.slo);W+=`<line x1="${q}" y1="${F+3}" x2="${q}" y2="${F+gp-3}" stroke="var(--ink)" stroke-width="1" stroke-dasharray="4 3"${_(`rows.${D}.slo`)}/><text x="${q+4}" y="${F+10}" class="t-eyebrow">SLO ${S(ja(C.slo))}${S(n)}</text>`}W+=`<line x1="${ee.p50}" y1="${U}" x2="${H}" y2="${U}" stroke="var(--muted)" stroke-width="1.25"/>`,ee.max!==void 0&&(P=!0,W+=`<g${_(`rows.${D}.max`)}><circle cx="${ee.max}" cy="${U}" r="3.5" fill="var(--paper)" stroke="var(--soft)" stroke-width="1.25"/><path d="M${ee.max-2} ${U-2} l 4 4 M${ee.max+2} ${U-2} l -4 4" stroke="var(--soft)" stroke-width="1" fill="none"/></g>`),ee.p999!==void 0&&(W+=`<circle cx="${ee.p999}" cy="${U}" r="2.5" fill="var(--paper)" stroke="var(--muted)" stroke-width="1.25"${_(`rows.${D}.p999`)}/>`);for(const q of["p90","p95"]){const de=ee[q];de!==void 0&&(j=!0,W+=`<circle cx="${de}" cy="${U}" r="2.5" fill="var(--paper)" stroke="var(--muted)" stroke-width="1.25"${_(`rows.${D}.${q}`)}/>`)}const K=B?"var(--negative)":"var(--accent)";W+=`<circle cx="${ee.p99}" cy="${U}" r="4" fill="${K}"${_(`rows.${D}.p99`)}/>`,W+=`<circle cx="${ee.p50}" cy="${U}" r="4" fill="var(--ink)"${_(`rows.${D}.p50`)}/>`;const R=ja(C.p50),z=R.length*vp;ee.p50-Cv-z>=l-2&&(W+=`<text x="${ee.p50-Cv}" y="${U+3.5}" class="t-sub c-muted" text-anchor="end">${S(R)}</text>`);const Y=ja(C.p99),V=Y.length*vp,re=ee.p99+Cv,Q=re+V;[ee.p999,ee.max].filter(q=>q!==void 0).every(q=>q-4>Q+2||q+4<re-2)&&(W+=`<text x="${re}" y="${U+3.5}" class="t-sub${B?" c-negative":" c-muted"}">${S(Y)}</text>`),W+="</g>",A+=W}),A+="</g></svg>";const I=[{swatch:"node-dot",fill:"var(--ink)",stroke:"var(--ink)",label:"p50"}];j&&I.push({swatch:"node-dot",fill:"var(--paper)",stroke:"var(--muted)",label:"p90 · p95"}),I.push({swatch:"node-dot",fill:"var(--accent)",stroke:"var(--accent)",label:"p99"}),N&&I.push({swatch:"node-dot",fill:"var(--negative)",stroke:"var(--negative)",label:"p99 over the SLO"}),P&&I.push({swatch:"node-dot",fill:"var(--paper)",stroke:"var(--soft)",label:"max"}),t.some(C=>o(C)!==void 0)&&I.push({swatch:"line-dashed",stroke:"var(--ink)",label:"SLO"});const O=ot(I);return ct({tag:"PERCENTILES",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...O.length>0?{legendHtml:O}:{}},A)}var N2=520,T2=22,_2=18,HK=8,yp=14,WK=24,L2=14,Nv=6,I2=6.2,UK=7.4;function KK(e){if(!(e>0))return 1;const t=Math.pow(10,Math.floor(Math.log10(e/5))),n=[1,2,2.5,5,10].map(r=>r*t);let s=n[0]??1,o=1/0;for(const r of n){const i=Math.ceil(e/r-1e-9),l=i>=4&&i<=6?Math.abs(i-5):10+Math.abs(i-5);l<o&&(s=r,o=l)}return s}var Tv=e=>Math.round(e*1e6)/1e6,VK=e=>Number.isInteger(e)?String(e):String(Math.round(e*100)/100);function GK(e,t){return e.length<=t?e:t<2?"":`${e.slice(0,t-1)}…`}function j2(e){const t=e.map((o,r)=>({...o,i:r})).sort((o,r)=>o.x-r.x||o.i-r.i),n=[],s=new Array(e.length).fill(0);for(const o of t){const r=o.x-o.w/2;let i=n.findIndex(l=>l+6<=r);i<0&&(i=n.length,n.push(-1/0)),n[i]=o.x+o.w/2,s[o.i]=i}return s}function YK(e){const t=e.lanes,n=e.events??[],s=e.constraints??[],o=e.unit??"",r=o.length>2?` ${o}`:o,i=t.map(le=>{const J=[];for(const ue of le.states)J.includes(ue.state)||J.push(ue.state);return J}),l=t.flatMap(le=>le.states),d=Xn(l.map(le=>le.accent)),u=[...l.flatMap(le=>[le.from,le.to]),...n.map(le=>le.at),...s.flatMap(le=>[le.from,le.to])],p=Math.min(...u),h=Math.max(...u),m=KK(Math.max(h-p,1e-9)),g=Tv(Math.floor(p/m)*m),v=Tv(Math.max(Math.ceil(h/m)*m,g+m)),y=[];for(let le=g;le<=v+1e-9;le+=m)y.push(Tv(le));const b=Math.max(88,...t.map(le=>le.label.length*UK+8),...i.flatMap(le=>le.map(J=>J.length*I2+12))),E=yp+b,$=E+N2,A=le=>E+(le-g)/(v-g)*N2,T=n.map(le=>({x:A(le.at),w:le.label.length*Nv+10})),N=j2(T),j=n.length>0?Math.max(...N)+1:0,P=j>0?j*L2+8:0,I=s.map(le=>({x:(A(le.from)+A(le.to))/2,w:(le.label.length+4)*Nv+10})),O=j2(I),C=s.length>0?Math.max(...O)+1:0,D=C>0?C*24+4:0,U=10,X=U+P,B=X+D,te=le=>_2+(i[le]?.length??1)*T2+HK,ee=[];let H=B;for(let le=0;le<t.length;le++)ee.push(H),H+=te(le);const W=H,K=W+6,R=K+26,z=$+WK,Y=Sn("Timing diagram",e.title,[wt(t.length,"lane"),wt(n.length,"event")]);let V=`<svg viewBox="0 0 ${z} ${R}"${Y.attrs}>${Y.title}`;V+=`<g${ut}>`;for(const le of y){const J=A(le);V+=`<line x1="${J}" y1="${B}" x2="${J}" y2="${W}" stroke="var(--rule)" stroke-width="1"/>`}for(let le=1;le<t.length;le++){const J=ee[le]??0;V+=`<line x1="${yp}" y1="${J}" x2="${z-8}" y2="${J}" stroke="var(--rule)" stroke-width="1"/>`}V+="</g>",V+=`<line x1="${E}" y1="${K}" x2="${$}" y2="${K}" stroke="var(--rule-solid)" stroke-width="1"/>`;let re=-1/0;for(const le of y){const J=`${VK(le)}${r}`,ue=J.length*I2,ve=A(le);ve-ue/2<re+6||(V+=`<text x="${ve}" y="${K+14}" class="t-sub c-soft" text-anchor="middle">${S(J)}</text>`,re=ve+ue/2)}let Q=!1,ne=!1,Z=0;if(V+=`<g${he("lanes")}>`,t.forEach((le,J)=>{const ue=i[J]??[],ve=ee[J]??0,we=Me=>ve+_2+(Math.max(0,ue.indexOf(Me))+.5)*T2;let $e=`<g${_(`lanes.${J}`)} data-levels="${ue.length}">`;$e+=`<text x="${yp}" y="${ve+13}" class="t-name"${_(`lanes.${J}.label`)}>${S(le.label)}</text>`;for(const Me of ue)$e+=`<text x="${E-8}" y="${we(Me)+3.5}" class="t-sub c-soft tg-level" text-anchor="end">${S(Me)}</text>`;const je=le.states.map((Me,Be)=>({st:Me,si:Be,mark:d[Z+Be]})).sort((Me,Be)=>Me.st.from-Be.st.from||Me.si-Be.si);Z+=le.states.length;let De="";je.forEach((Me,Be)=>{const Ge=A(Me.st.from),fe=A(Me.st.to),ge=we(Me.st.state);if(De+=Be===0?`M ${Ge} ${ge} `:`V ${ge} `,Be>0){const Ce=je[Be-1],Fe=Ce!==void 0?A(Ce.st.to):Ge;Ge>Fe+.5&&(De+=`H ${Ge} `)}De+=`H ${fe} `}),$e+=`<path d="${De.trim()}" fill="none" stroke="var(--muted)" stroke-width="1.5" stroke-linejoin="round"/>`,$e+=`<g${he(`lanes.${J}.states`)}>`;for(const Me of je){const Be=A(Me.st.from),Ge=A(Me.st.to),fe=we(Me.st.state),ge=Me.mark==="negative"?"var(--negative)":Me.mark==="focal"?"var(--accent)":void 0;Me.mark==="negative"&&(Q=!0),Me.mark==="focal"&&(ne=!0);const Ce=Me.mark==="negative"?" c-negative":Me.mark==="focal"?" c-accent":"",Fe=Math.floor((Ge-Be-6)/Nv),qe=GK(Me.st.state,Fe),ze=qe!==Me.st.state?`<title>${S(Me.st.state)}</title>`:"";$e+=`<g${_(`lanes.${J}.states.${Me.si}`)}>`+(ge!==void 0?`<line x1="${Be}" y1="${fe}" x2="${Ge}" y2="${fe}" stroke="${ge}" stroke-width="2.25"/>`:"")+(qe!==""?`<text x="${(Be+Ge)/2}" y="${fe-5}" class="t-arrow${Ce}" text-anchor="middle">${ze}${S(qe)}</text>`:"")+"</g>"}$e+="</g></g>",V+=$e}),V+="</g>",s.length>0&&(V+=`<g${he("constraints")}>`,s.forEach((le,J)=>{const ue=A(le.from),ve=A(le.to),we=O[J]??0,$e=X+4+(C-1-we)*24+16;V+=`<g${_(`constraints.${J}`)}><path d="M ${ue} ${$e+5} V ${$e} H ${ve} V ${$e+5}" fill="none" stroke="var(--ink)" stroke-width="1"/><text x="${(ue+ve)/2}" y="${$e-4}" class="t-arrow c-ink" text-anchor="middle">{ ${S(le.label)} }</text></g>`}),V+="</g>"),n.length>0){const le=new Map(t.map((J,ue)=>[J.label,ue]));V+=`<g${he("events")}>`,n.forEach((J,ue)=>{const ve=A(J.at),we=N[ue]??0,$e=U+(j-1-we)*L2+10,je=J.lane!==void 0?le.get(J.lane):void 0,De=je!==void 0?ee[je]??B:B,Me=je!==void 0?(ee[je]??B)+te(je):W,Be=T[ue]?.w??0,Ge=Math.min(Math.max(ve,yp+Be/2),z-4-Be/2);V+=`<g${_(`events.${ue}`)}><line x1="${ve}" y1="${$e+4}" x2="${ve}" y2="${Me}" stroke="var(--muted)" stroke-width="1" stroke-dasharray="3 3"/><circle cx="${ve}" cy="${De}" r="2.5" fill="var(--muted)"/><text x="${Ge}" y="${$e}" class="t-arrow c-ink" text-anchor="middle"${_(`events.${ue}.label`)}>${S(J.label)}</text></g>`}),V+="</g>"}V+="</svg>";const q=[{swatch:"line",stroke:"var(--muted)",label:"state"}];Q&&q.push({swatch:"line",stroke:"var(--negative)",label:"failure state"}),ne&&q.push({swatch:"line",stroke:"var(--accent)",label:"highlighted state"}),n.length>0&&q.push({swatch:"line-dashed",stroke:"var(--muted)",label:"event"}),s.length>0&&q.push({swatch:"chip",chip:"{ }",label:"duration constraint"});const de=ot(q);return ct({tag:"TIMING",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...de.length>0?{legendHtml:de}:{}},V)}var XK={S:"Spoofing",T:"Tampering",R:"Repudiation",I:"Information disclosure",D:"Denial of service",E:"Elevation of privilege"},IA=6,jA=11,PA=34;function QK(e,t){return`<g class="tm-lock" fill="none" stroke="var(--muted)" stroke-width="1.2"><path d="M${e+1.5} ${t+4.5} V ${t+2.5} a 2.5 2.5 0 0 1 5 0 V ${t+4.5}"/><path d="M${e} ${t+4.5} h 8 v 5.5 h -8 z"/></g>`}function OA(e){return e==="plain"?32:16}function ZK(e,t,n,s,o){const r=OA(s),i=e-o/2,l=t-r/2,d=s==="plain"?" c-negative":"";let u=`<rect x="${i}" y="${l}" width="${o}" height="${r}" fill="var(--paper)"/>`;const p=s==="tls"?jA:0,h=n!==""?n.length*IA:0,m=e-(p+h)/2,g=l+11.5;if(s==="tls"&&(u+=QK(m,g-8.5)),n!==""&&(u+=`<text x="${m+p}" y="${g}" class="t-arrow${d}">${S(n)}</text>`),s==="plain"){const v=PA-4,y=l+16+1.5;u+=`<rect x="${e-v/2}" y="${y}" width="${v}" height="13" rx="2" fill="var(--negative-tint)" stroke="var(--negative)" stroke-width="1"/><text x="${e}" y="${y+9.5}" class="t-eyebrow c-negative" text-anchor="middle">plain</text>`}return u}function JK(e,t){const n=(t==="tls"?jA:0)+(e!==""?e.length*IA:0);return 6+Math.max(n,t==="plain"?PA:0)}function eV(e){return e==="tls"||e==="plain"||e==="internal"?e:"none"}var tV=/^\s*(.+?)\s*(?:->|→)\s*(.+?)\s*$/;function nV(e,t){if(e.length===0)return"";const n=o=>{const r=tV.exec(o);return r!==null&&r[1]!==void 0&&r[2]!==void 0?`${S(t(r[1])??r[1])} → ${S(t(r[2])??r[2])}`:S(t(o.trim())??o)},s=e.map((o,r)=>{const i=o.id!==void 0?`<td class="tm-id"${_(`threats.${r}.id`)}>${S(o.id)}</td>`:'<td class="tm-id"></td>',l=`<td><abbr class="tm-cat" title="${S(XK[o.category])}"${_(`threats.${r}.category`)}>${o.category}</abbr></td>`,d=`<td class="tm-target"${_(`threats.${r}.target`)}>${n(o.target)}</td>`,u=`<td class="tm-threat"${_(`threats.${r}.threat`)}>${S(o.threat)}</td>`,p=`<td class="tm-mit"${o.mitigation!==void 0?_(`threats.${r}.mitigation`):""}>${o.mitigation!==void 0?S(o.mitigation):'<span class="tm-none">—</span>'}</td>`,h=o.severity!==void 0?`<td><span class="rk-sev rk-sev-${o.severity}"${_(`threats.${r}.severity`)}>${S(o.severity)}</span></td>`:"<td></td>",m=o.status!==void 0?`<td><span class="rk-status tm-st-${o.status}"${_(`threats.${r}.status`)}>${S(o.status)}</span></td>`:"<td></td>";return`<tr class="tm-row"${_(`threats.${r}`)}>${i}${l}${d}${u}${p}${h}${m}</tr>`}).join("");return`<div class="tm-scroll"><table class="trk tm-table"><thead><tr><th>ID</th><th>STRIDE</th><th>Target</th><th>Threat</th><th>Mitigation</th><th>Severity</th><th>Status</th></tr></thead><tbody${he("threats")}>${s}</tbody></table></div>`}function sV(e){const t=e.edges??[],n=e.nodes,s=!(n.length>0&&n.every(R=>R.col!==void 0&&R.row!==void 0)),o=nr(n,t,e.dir??"LR"),r=148,i=o.map(R=>lt(R.name,20,3)),d=66+(Math.max(1,...i.map(R=>R.length))-1)*14,u=104,p=54,h=e.boundaries??[],m=Yi(h),g=(h.length>0?Gn.padX:26)+m.padX,v=(h.length>0?Gn.padTop:26)+m.padTop,y=(h.length>0?Gn.padBot:20)+m.padBot,b=wd(h),E=Math.max(1,...o.map(R=>R.col),b.cols),$=Math.max(1,...o.map(R=>R.row),b.rows),A=R=>g+(R-1)*(r+u),T=R=>v+(R-1)*(d+p),N=R=>({x:A(R.col),y:T(R.row),w:r,h:d}),j=new Map(o.map(R=>[R.id,R])),P=g*2+E*r+(E-1)*u,I=v+$*d+($-1)*p+y,O=tr({quick:s,cols:E,rows:$,cellW:r,cellH:d,gapX:u,gapY:p,padX:g,padTop:v}),C=Sn("Threat model",e.title,[wt(o.length,"node"),wt(t.length,"flow"),wt((e.threats??[]).length,"threat")]);let D=`<svg viewBox="0 0 ${P} ${I}"${C.attrs}${O}>${C.title}`;if(h.length>0){const R=xl(h,{xOf:A,yOf:T,cellW:r,cellH:d,gapX:u,gapY:p,skin:!0}).replace(/data-bl="groups"/g,'data-bl="boundaries"').replace(/data-bp="groups\./g,'data-bp="boundaries.');D+=`<g class="tm-bounds">${R}</g>`}const F=new Set,U=qs(t),X=Hs(t,R=>{const z=j.get(R);return z!==void 0?N(z):void 0}),B=[],te=o.map(R=>N(R));D+=`<g${he("edges")}>`,t.forEach((R,z)=>{const Y=j.get(R.from),V=j.get(R.to);if(!Y||!V)return;const re=eV(R.channel);F.add(re);const Q=Fs(N(Y),N(V),U[z]??0,X[z]??0),ne=re==="plain",Z=ne?"var(--negative)":"var(--muted)",q=ne?' stroke-dasharray="4 3"':"",de=ne?"skErr":"skArrow";D+=`<path d="${Q.d}" fill="none" stroke="${Z}" stroke-width="1.5"${q} marker-end="url(#${de})"${_(`edges.${z}`)}${ne?' data-channel="plain"':""}/>`;const le=R.label??"";if(le===""&&re!=="tls"&&re!=="plain")return;const J=JK(le,re),ue=Uy(Q.lx,Q.ly,te),ve=OA(re);te.push({x:ue.lx-J/2,y:ue.ly-ve/2,w:J,h:ve}),B.push(`<g${_(`edges.${z}`)}>${ZK(ue.lx,ue.ly,le,re,J)}</g>`)}),D+="</g>";const ee=new Set;D+=`<g${he("nodes")}>`,o.forEach((R,z)=>{const Y=N(R),V=tA(R.kind);ee.add(V);const re=nA(V,!1),Q=rA(i[z]??[],R.name,Y,!1,`nodes.${z}.name`);D+=`<g${_(`nodes.${z}`)}${Mo(R.col,R.row)}>${sA(V,Y,re)}${oA(Y,re)}${Q}</g>`}),D+="</g>",D+=B.join(""),D+="</svg>";const H=[];ee.has("process")&&H.push({swatch:"node",label:"process"}),ee.has("external")&&H.push({swatch:"node-dashed",label:"external entity"}),ee.has("store")&&H.push({swatch:"node-store",label:"data store"}),h.length>0&&H.push({swatch:"line-dashed",stroke:"var(--negative)",label:"trust boundary"}),F.has("none")&&H.push({swatch:"edge",label:"data flow"}),F.has("tls")&&H.push({swatch:"edge",label:"tls (lock)"}),F.has("internal")&&H.push({swatch:"edge",label:"internal"}),F.has("plain")&&H.push({swatch:"edge-negative-dashed",label:"plain — unencrypted"});const W=ot(H),K=nV(e.threats??[],R=>j.get(R)?.name);return ct({tag:"THREAT MODEL",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...W.length>0?{legendHtml:W}:{},...K.length>0?{footerHtml:K}:{}},D)}var oV=6,rV=4,tn=8,P2=24,O2=18,_v=124,R2=30,D2=22,iV=26,Lv=14,Iv=13;function aV(e,t,n){const s='fill="var(--paper)" stroke="var(--ink)" stroke-width="1.5"',o='fill="var(--muted)" stroke="var(--muted)" stroke-width="1"',r='fill="var(--paper-2)" stroke="var(--rule-solid)" stroke-width="1"';switch(e){case"input":case"output":return`<circle cx="${t}" cy="${n}" r="${tn}" ${s}/>`;case"conv":return`<rect x="${t-tn+1}" y="${n-tn+1}" width="${2*tn-2}" height="${2*tn-2}" ${o}/>`;case"pool":return`<rect x="${t-tn+1}" y="${n-tn+1}" width="${2*tn-2}" height="${2*tn-2}" rx="4" ${r}/>`;case"attention":return`<path d="M${t} ${n-tn-1} L${t+tn+1} ${n} L${t} ${n+tn+1} L${t-tn-1} ${n} z" ${o}/>`;case"norm":return`<circle cx="${t}" cy="${n}" r="${tn}" ${r}/>`;case"dropout":return`<circle cx="${t}" cy="${n}" r="${tn}" fill="var(--paper)" stroke="var(--rule-solid)" stroke-width="1" stroke-dasharray="3 2"/>`;case"recurrent":return`<circle cx="${t}" cy="${n}" r="${tn}" ${o}/><circle cx="${t}" cy="${n}" r="3" fill="var(--paper)"/>`;case"embedding":case"dense":return`<circle cx="${t}" cy="${n}" r="${tn}" ${o}/>`}}var lV={input:{swatch:"node-dot",label:"input"},output:{swatch:"node-dot",label:"output"},dense:{swatch:"node-dot",label:"dense",fill:"var(--muted)",stroke:"var(--muted)"},embedding:{swatch:"node-dot",label:"embedding",fill:"var(--muted)",stroke:"var(--muted)"},recurrent:{swatch:"node-dot",label:"recurrent",fill:"var(--muted)",stroke:"var(--muted)"},conv:{swatch:"fill",label:"conv",fill:"var(--muted)"},pool:{swatch:"node-fill2",label:"pool"},attention:{swatch:"node-dot",label:"attention",fill:"var(--muted)",stroke:"var(--muted)"},norm:{swatch:"node-dot",label:"norm",fill:"var(--paper-2)",stroke:"var(--rule-solid)"},dropout:{swatch:"node-dot",label:"dropout",stroke:"var(--rule-solid)",dash:"3 2"}};function cV(e,t,n){return e.kind!==void 0?e.kind:t===0?"input":t===n-1?"output":"dense"}function dV(e){const t=e.layers,n=t.length,s=Math.max(1,Math.min(12,Math.round(e.maxUnits??oV))),o=[],r=[];t.forEach((C,D)=>{const F=o[D-1]??rV,U=C.units!==void 0?Math.max(1,Math.round(C.units)):void 0,X=Math.min(U!==void 0?U:F,s);o.push(X),r.push(U!==void 0&&U>X)});const i=C=>((o[C]??1)-1)*P2+(r[C]===!0?O2:0)+2*tn,l=Math.max(...t.map((C,D)=>i(D))),d=D2+l/2,u=t.map((C,D)=>cV(C,D,n)),p=t.map(C=>lt(C.label,16,2)),h=Math.max(1,...p.map(C=>C.length)),m=(C,D)=>{const F=o[C]??1,U=d-i(C)/2+tn,X=r[C]===!0&&D===F-1?O2:0;return U+D*P2+X},g=C=>R2+_v/2+C*_v,v=D2+l+iV,y=C=>(C.units!==void 0?1:0)+(C.activation!==void 0?1:0)+(C.note!==void 0?1:0),b=Math.max(0,...t.map(y)),E=R2*2+n*_v,$=v+h*Lv+b*Iv+14,A=Sn("Neural network",e.title,[wt(n,"layer")]);let T=`<svg viewBox="0 0 ${E} ${$}"${A.attrs}>${A.title}`;T+='<g fill="none" stroke="var(--rule-solid)" stroke-width=".6" data-decorative="1">';for(let C=1;C<n;C++){if(t[C]?.connect==="none")continue;const D=g(C-1)+tn,F=g(C)-tn;for(let U=0;U<(o[C-1]??0);U++){const X=m(C-1,U);for(let B=0;B<(o[C]??0);B++)T+=`<line x1="${D}" y1="${X}" x2="${F}" y2="${m(C,B)}"/>`}}T+="</g>";const N=new Set;T+=`<g${he("layers")}>`,t.forEach((C,D)=>{const F=u[D]??"dense";N.add(F);const U=g(D),X=o[D]??1;let B=`<g${_(`layers.${D}`)}>`;for(let H=0;H<X;H++)B+=aV(F,U,m(D,H));if(r[D]===!0&&X>=2){const H=m(D,X-2)+tn,W=m(D,X-1)-tn,K=(H+W)/2;B+=`<g fill="var(--muted)" data-decorative="1"><circle cx="${U}" cy="${K-5}" r="1.2"/><circle cx="${U}" cy="${K}" r="1.2"/><circle cx="${U}" cy="${K+5}" r="1.2"/></g>`}const te=p[D]??[];let ee=v;if(B+=`<g${_(`layers.${D}.label`)}>`,te.forEach((H,W)=>{B+=`<text x="${U}" y="${ee+W*Lv}" class="t-name" text-anchor="middle">${S(H)}</text>`}),B+="</g>",ee+=h*Lv,C.units!==void 0&&(B+=`<text x="${U}" y="${ee}" class="t-sub c-ink" text-anchor="middle"${_(`layers.${D}.units`)}>${S(String(C.units))}</text>`,ee+=Iv),C.activation!==void 0&&(B+=`<text x="${U}" y="${ee}" class="t-sub" text-anchor="middle"${_(`layers.${D}.activation`)}>${S(C.activation)}</text>`,ee+=Iv),C.note!==void 0){const H=lt(C.note,18,1)[0]??"",W=H!==C.note?`<title>${S(C.note)}</title>`:"";B+=`<text x="${U}" y="${ee}" class="t-sub c-soft" text-anchor="middle"${_(`layers.${D}.note`)}>${W}${S(H)}</text>`}B+="</g>",T+=B}),T+="</g></svg>";const j=[...N].map(C=>lV[C]),P=ot(j),I=e.description!==void 0&&e.lede!==void 0?`${e.description} ${e.lede}`:e.description??e.lede,O=e.params!==void 0?`<div class="diagram-foot"><span${_("params")}><strong>Params</strong> ${S(e.params)}</span></div>`:"";return ct({tag:"NEURAL NET",...e.title!==void 0?{title:e.title}:{},...I!==void 0?{desc:I}:{},...P.length>0?{legendHtml:P}:{},...O.length>0?{footerHtml:O}:{}},T)}var xp=24,uV=7,Fo=15,pV=14,fV=10,jv=12,Pv=40,B2=36,kp=24;function hV(e,t,n){return e==="red"?"var(--negative)":e===void 0?"var(--muted)":n===1?"var(--accent)":Qi(t,n)}function mV(e){const t=e.nodes,n=new Map;t.forEach((W,K)=>n.set(W.id,K));const s=new Map,o=[];t.forEach((W,K)=>{const R=W.parent!==void 0?n.get(W.parent):void 0;R===void 0||R===K?o.push(K):s.set(R,[...s.get(R)??[],K])});const r=o.filter(W=>t[W]?.accent!==void 0&&t[W]?.accent!=="red"),i=new Map;o.forEach(W=>{const K=t[W]?.accent;i.set(W,hV(K,r.indexOf(W),r.length))});const l=[],d=new Set,u=W=>W.lines.length*Fo+(W.node.note!==void 0?pV:0)+fV,p=(W,K,R,z,Y)=>{if(d.has(W))return 0;d.add(W);const V=t[W];if(V===void 0)return 0;const re=lt(V.label,xp,2),Q=Math.max(24,...re.map(ve=>ve.length*uV),V.note!==void 0?Math.min(V.note.length,xp+4)*5.6:0),ne={node:V,index:W,depth:K,side:R,branch:z,lines:re,w:Q,y:Y};l.push(ne);const Z=s.get(W)??[];if(Z.length===0)return u(ne);let q=0;const de=[];for(const ve of Z){const we=l.length;q+=p(ve,K+1,R,z,Y+q);const $e=l[we];$e!==void 0&&$e.index===ve&&de.push($e)}const le=u(ne);q<le&&(q=le);const J=de[0],ue=de[de.length-1];return ne.y=J!==void 0&&ue!==void 0?(J.y+ue.y)/2:Y,q};let h=0,m=0;o.forEach((W,K)=>{const R=K%2===0?1:-1,z=R===1?h:m,Y=p(W,1,R,K,z+(z>0?jv:0));R===1?h+=Y+(z>0?jv:0):m+=Y+(z>0?jv:0)});const g=(W,K)=>Math.max(0,...l.filter(R=>R.side===W&&R.depth===K).map(R=>R.w)),v=Math.max(1,...l.map(W=>W.depth)),y=W=>{let K=0;for(let R=1;R<=v;R++){const z=g(W,R);z>0&&(K+=Pv+z)}return K},b=lt(e.center,xp,2),E=Math.max(60,...b.map(W=>W.length*7.5))+28,$=b.length>1?B2+Fo:B2,A=y(-1),T=y(1),N=Math.max(h,m,$),j=kp*2+A+E+T,P=kp*2+N,I=kp+A+E/2,O=kp+N/2,C=W=>O-(W===1?h:m)/2,D=W=>{let K=E/2;for(let R=1;R<W.depth;R++){const z=g(W.side,R);z>0&&(K+=Pv+z)}return K+=Pv,I+W.side*K},F=W=>C(W.side)+W.y+W.lines.length*Fo/2,U=W=>Math.round(W*10)/10,X=Sn("Mind map",e.center,[wt(o.length,"branch"),wt(t.length,"node")]);let B=`<svg viewBox="0 0 ${U(j)} ${U(P)}"${X.attrs}>${X.title}`;B+='<g fill="none" stroke-width="1.5" data-decorative="1">';for(const W of l){const K=i.get(W.branch)??"var(--muted)",R=D(W)-W.side*6,z=F(W)+W.lines.length*Fo/2+2;let Y,V;if(W.depth===1)Y=I+W.side*(E/2),V=O;else{const Q=l.find(ne=>ne.index===n.get(W.node.parent??""));if(Q===void 0)continue;Y=D(Q)+W.side*(Q.w+6),V=F(Q)+Q.lines.length*Fo/2+2}const re=Y+(R-Y)*.5;B+=`<path d="M${U(Y)} ${U(V)} Q${U(re)} ${U(z)} ${U(R)} ${U(z)}" stroke="${K}"/>`,B+=`<line x1="${U(R)}" y1="${U(z)}" x2="${U(R+W.side*(W.w+12))}" y2="${U(z)}" stroke="${K}" stroke-width="${W.depth===1?1.5:1}"/>`}B+="</g>",B+=`<g${_("center")}><rect x="${U(I-E/2)}" y="${U(O-$/2)}" width="${U(E)}" height="${$}" rx="${$/2}" fill="var(--paper)" stroke="var(--ink)" stroke-width="1.5"/>`,b.forEach((W,K)=>{B+=`<text x="${U(I)}" y="${U(O+4.5-(b.length-1)*Fo/2+K*Fo)}" class="t-name" text-anchor="middle">${S(W)}</text>`}),B+="</g>",B+=`<g${he("nodes")}>`;for(const W of l){const K=i.get(W.branch)??"var(--muted)",R=D(W),z=C(W.side)+W.y,Y=W.side===1?"start":"end",V=K!=="var(--muted)"?` style="fill:${K}"`:"";let re=`<g${_(`nodes.${W.index}`)}>`;if(W.lines.forEach((Q,ne)=>{re+=`<text x="${U(R)}" y="${U(z+11+ne*Fo)}" class="t-name" text-anchor="${Y}"${V}>${S(Q)}</text>`}),W.node.note!==void 0){const Q=lt(W.node.note,xp+4,1)[0]??"",ne=Q!==W.node.note?`<title>${S(W.node.note)}</title>`:"";re+=`<text x="${U(R)}" y="${U(z+W.lines.length*Fo+13)}" class="t-sub c-soft" text-anchor="${Y}"${_(`nodes.${W.index}.note`)}>${ne}${S(Q)}</text>`}re+="</g>",B+=re}B+="</g></svg>";const te=[],ee=new Set;for(const W of o){const K=i.get(W)??"var(--muted)";K==="var(--muted)"||ee.has(K)||(ee.add(K),te.push({swatch:"line",stroke:K,label:t[W]?.label??"",path:`nodes.${W}`}))}const H=ot(te);return ct({tag:"MIND MAP",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...H.length>0?{legendHtml:H}:{}},B)}var Cs=76,Dr=27,gV=2*Dr+22,Ov=2*Cs+44,kc=26,z2=30,Pa=118,bc=84,Rv=44,F2=22;function wc(e,t,n,s){const o=n-e,r=s-t;if(o===0&&r===0)return{x:e+Cs,y:t};const i=1/Math.sqrt(o*o/(Cs*Cs)+r*r/(Dr*Dr));return{x:e+o*i,y:t+r*i}}function vV(e,t,n){const s='fill="none" stroke="var(--ink)" stroke-width="1.5" stroke-linecap="round"';return e==="system"?`<rect x="${t-22}" y="${n-20}" width="44" height="40" rx="3" fill="var(--paper)" stroke="var(--ink)" stroke-width="1.25" stroke-dasharray="4 3"/><text x="${t}" y="${n+3.5}" class="t-eyebrow" text-anchor="middle">SYS</text>`:e==="time"?`<circle cx="${t}" cy="${n}" r="15" fill="var(--paper)" stroke="var(--ink)" stroke-width="1.5"/><path d="M${t} ${n-9} V${n} H${t+7}" ${s}/>`:`<circle cx="${t}" cy="${n-15}" r="6" fill="var(--paper)" stroke="var(--ink)" stroke-width="1.5"/><path d="M${t} ${n-9} V${n+6} M${t-11} ${n-3} H${t+11} M${t} ${n+6} L${t-9} ${n+20} M${t} ${n+6} L${t+9} ${n+20}" ${s}/>`}function yV(e){const t=e.actors,n=e.cases,s=e.links??[],o=e.relations??[],r=new Map(n.map((z,Y)=>[z.id,Y])),i=new Map(t.map((z,Y)=>[z.id,Y])),l=n.length>6?2:1,d=Math.ceil(n.length/l),u=n.some(z=>z.note!==void 0),p=gV+(u?12:0),h=kc*2+l*Ov-(Ov-2*Cs),m=z2+kc+d*p-(p-2*Dr)+kc,g=t.filter(z=>z.side!=="right"),v=t.filter(z=>z.side==="right"),y=g.length>0?Pa+Rv:0,b=v.length>0?Pa+Rv:0,E=20+y,$=F2,A=z=>{const Y=Math.floor(z/d),V=z%d;return{x:E+kc+Cs+Y*Ov,y:$+z2+kc+Dr+V*p}},T=z=>{const Y=z.map(Z=>{const q=s.filter(de=>de.from===Z.id&&r.has(de.to)).map(de=>A(r.get(de.to)??0).y);return{id:Z.id,y:q.length>0?q.reduce((de,le)=>de+le,0)/q.length:$+m/2}}),V=Y.map((Z,q)=>q).sort((Z,q)=>(Y[Z]?.y??0)-(Y[q]?.y??0)||Z-q),re=[],Q=$+bc/2;V.forEach((Z,q)=>{const de=re[q-1],le=Math.max(Y[Z]?.y??0,Q,de!==void 0?de+bc:-1/0);re.push(le)});const ne=new Map;return V.forEach((Z,q)=>ne.set(Y[Z]?.id??"",re[q]??0)),ne},N=T(g),j=T(v),P=z=>z.side==="right"?{x:E+h+Rv+Pa/2,y:j.get(z.id)??0}:{x:20+Pa/2,y:N.get(z.id)??0},I=Math.max($+m,...t.map(z=>P(z).y+bc/2)),O=20+y+h+b+20,C=I+F2,D=z=>Math.round(z*10)/10,F=Sn("Use-case diagram",e.system??e.title,[wt(t.length,"actor"),wt(n.length,"use case")]);let U=`<svg viewBox="0 0 ${D(O)} ${D(C)}"${F.attrs}>${F.title}`;U+='<defs><marker id="ucTri" viewBox="0 0 14 14" refX="13" refY="7" markerWidth="13" markerHeight="13" markerUnits="userSpaceOnUse" orient="auto-start-reverse"><path d="M1,1 L13,7 L1,13 z" fill="var(--paper)" stroke="var(--ink)" stroke-width="1.2"/></marker></defs>',U+=`<g${_("system")}><rect x="${E}" y="${$}" width="${D(h)}" height="${D(m)}" rx="8" fill="var(--paper-2)" stroke="var(--rule-solid)" stroke-width="1"/>`,e.system!==void 0&&(U+=`<text x="${E+14}" y="${$+19}" class="t-eyebrow">${S(e.system)}</text>`),U+="</g>";const X=[];U+=`<g${he("links")}>`,s.forEach((z,Y)=>{const V=t[i.get(z.from)??-1],re=r.get(z.to);if(V===void 0||re===void 0)return;const Q=P(V),ne=A(re),Z=wc(ne.x,ne.y,Q.x,Q.y),q=Q.x+(V.side==="right"?-24:24);U+=`<line x1="${D(q)}" y1="${D(Q.y)}" x2="${D(Z.x)}" y2="${D(Z.y)}" stroke="var(--muted)" stroke-width="1.25"${_(`links.${Y}`)}/>`,z.label!==void 0&&X.push({lx:(q+Z.x)/2,ly:(Q.y+Z.y)/2,label:z.label,path:`links.${Y}`})}),U+="</g>";const B=new Set;U+=`<g${he("relations")}>`,o.forEach((z,Y)=>{const V=r.get(z.from),re=r.get(z.to);if(V===void 0||re===void 0||V===re)return;B.add(z.kind);const Q=A(V),ne=A(re),Z=Math.floor(V/d)===Math.floor(re/d),q=Z&&Math.abs(V-re)===1,de='stroke="var(--muted)" stroke-width="1.25"',le=z.kind==="generalize"?"url(#ucTri)":"url(#skOpen)",J=z.kind==="generalize"?"":' stroke-dasharray="5 4"',ve=[z.kind==="generalize"?void 0:`«${z.kind}»`,z.label].filter(De=>De!==void 0).join(" ");let we,$e,je;if(Z&&!q){const De=Math.floor(V/d),Me=l===2?De===0?-1:1:v.length>0&&g.length===0?-1:1,Be=wc(Q.x,Q.y,Q.x+Me*Cs*2,Q.y+(ne.y-Q.y)*.3),Ge=wc(ne.x,ne.y,ne.x+Me*Cs*2,ne.y-(ne.y-Q.y)*.3),fe=Q.x+Me*(Cs+34),ge=(Q.y+ne.y)/2;we=`M${D(Be.x)} ${D(Be.y)} Q${D(fe)} ${D(ge)} ${D(Ge.x)} ${D(Ge.y)}`,$e=(Be.x+2*fe+Ge.x)/4,je=ge}else{const De=wc(Q.x,Q.y,ne.x,ne.y),Me=wc(ne.x,ne.y,Q.x,Q.y);we=`M${D(De.x)} ${D(De.y)} L${D(Me.x)} ${D(Me.y)}`,$e=(De.x+Me.x)/2,je=(De.y+Me.y)/2}U+=`<path d="${we}" fill="none" ${de}${J} marker-end="${le}"${_(`relations.${Y}`)}/>`,ve.length>0&&X.push({lx:$e,ly:je,label:ve,path:`relations.${Y}`})}),U+="</g>";const te=[];U+=`<g${he("cases")}>`,n.forEach((z,Y)=>{const V=A(Y);te.push({x:V.x-Cs,y:V.y-Dr,w:2*Cs,h:2*Dr});const re=lt(z.name,18,2),Q=z.note!==void 0?lt(z.note,22,1)[0]??"":void 0,ne=re.length*14+(Q!==void 0?12:0),Z=V.y+4.5-ne/2+7;let q=`<g${_(`cases.${Y}`)}><ellipse cx="${D(V.x)}" cy="${D(V.y)}" rx="${Cs}" ry="${Dr}" fill="var(--paper)" stroke="var(--ink)" stroke-width="1.5"/>`;if(q+=`<g${_(`cases.${Y}.name`)}>`,re.forEach((de,le)=>{q+=`<text x="${D(V.x)}" y="${D(Z+le*14)}" class="t-name" text-anchor="middle">${S(de)}</text>`}),q+="</g>",Q!==void 0){const de=Q!==z.note?`<title>${S(z.note)}</title>`:"";q+=`<text x="${D(V.x)}" y="${D(Z+re.length*14-1)}" class="t-sub" text-anchor="middle"${_(`cases.${Y}.note`)}>${de}${S(Q)}</text>`}q+="</g>",U+=q}),U+="</g>";const ee=new Set;U+=`<g${he("actors")}>`,t.forEach((z,Y)=>{const V=z.kind??"person";ee.add(V);const re=P(z);te.push({x:re.x-Pa/2,y:re.y-bc/2,w:Pa,h:bc});const Q=lt(z.name,16,2);let ne=`<g${_(`actors.${Y}`)}>${vV(V,re.x,re.y)}`;ne+=`<g${_(`actors.${Y}.name`)}>`,Q.forEach((Z,q)=>{ne+=`<text x="${D(re.x)}" y="${D(re.y+34+q*14)}" class="t-name" text-anchor="middle">${S(Z)}</text>`}),ne+="</g></g>",U+=ne}),U+="</g>";const{overlay:H,legend:W}=Ws(X,te,{skin:!0});U+=H,U+="</svg>";const K=[{swatch:"node-stadium",label:"use case"}];ee.has("system")&&K.push({swatch:"node-dashed",label:"external system"}),s.length>0&&K.push({swatch:"line",label:"association"}),B.has("include")&&K.push({swatch:"edge-dashed",label:"«include»"}),B.has("extend")&&K.push({swatch:"edge-dashed",label:"«extend»"}),B.has("generalize")&&K.push({swatch:"edge-implements",label:"generalizes"});const R=ot(K);return ct({tag:"USE CASE",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...R.length>0?{legendHtml:R}:{}},U+W)}var Dv=168,q2=128,H2=56,xV=54,ho=12,W2=26,U2=13,Vp=5,Cr={padX:18,padTop:42,padBot:14};function K2(e){const t=e??[];return t.length<=Vp?[...t]:[...t.slice(0,Vp),`+${t.length-Vp} more`]}function kV(e){const t=e.packages,n=e.deps??[],s=new Set(t.map(Q=>Q.id)),o=new Set(t.map(Q=>Q.parent).filter(Q=>Q!==void 0&&s.has(Q))),r=t.filter(Q=>!o.has(Q.id)),i=new Set(r.map(Q=>Q.id)),l=nr(r,n.filter(Q=>i.has(Q.from)&&i.has(Q.to)),e.dir??"LR"),d=new Map(l.map(Q=>[Q.id,Q])),u=new Map(t.map(Q=>[Q.id,Q])),p=(Q,ne=0)=>{const Z=Q.parent!==void 0?u.get(Q.parent):void 0;return Z===void 0||ne>t.length?0:1+p(Z,ne+1)},h=Math.max(0,...t.map(Q=>p(Q))),m=r.map(Q=>K2(Q.contains)),g=Math.max(0,...m.map(Q=>Q.length)),v=ho+W2+(g>0?6+g*U2+8:8),y=26+h*Cr.padX,b=26+h*Cr.padTop,E=20+h*Cr.padBot,$=Math.max(1,...l.map(Q=>Q.col)),A=Math.max(1,...l.map(Q=>Q.row)),T=Q=>y+(Q-1)*(Dv+q2),N=Q=>b+(Q-1)*(v+H2),j=y*2+$*Dv+($-1)*q2,P=b+A*v+(A-1)*H2+E,I=new Map,O=(Q,ne=0)=>{const Z=I.get(Q);if(Z!==void 0)return Z;const q=d.get(Q);if(q!==void 0){const $e={x:T(q.col),y:N(q.row),w:Dv,h:v};return I.set(Q,$e),$e}if(ne>t.length)return;const de=t.filter($e=>$e.parent===Q).map($e=>O($e.id,ne+1));let le=1/0,J=1/0,ue=-1/0,ve=-1/0;for(const $e of de)$e!==void 0&&(le=Math.min(le,$e.x),J=Math.min(J,$e.y),ue=Math.max(ue,$e.x+$e.w),ve=Math.max(ve,$e.y+$e.h));if(!Number.isFinite(le))return;const we={x:le-Cr.padX,y:J-Cr.padTop,w:ue-le+2*Cr.padX,h:ve-J+Cr.padTop+Cr.padBot};return I.set(Q,we),we},C=Sn("Package diagram",e.title,[wt(t.length,"package"),wt(n.length,"dependency","dependencies")]);let D=`<svg viewBox="0 0 ${j} ${P}"${C.attrs}>${C.title}`;const F=(Q,ne)=>{const Z=ne?"var(--ink)":"var(--rule-solid)",q=ne?1.5:1,de=ne?"var(--paper)":"var(--paper-2)",le=Math.min(xV,Q.w/2);return`<path d="M${Q.x} ${Q.y+ho} V${Q.y+2} Q${Q.x} ${Q.y} ${Q.x+2} ${Q.y} H${Q.x+le-2} Q${Q.x+le} ${Q.y} ${Q.x+le} ${Q.y+2} V${Q.y+ho}" fill="${de}" stroke="${Z}" stroke-width="${q}"/><rect x="${Q.x}" y="${Q.y+ho}" width="${Q.w}" height="${Q.h-ho}" fill="${de}" stroke="${Z}" stroke-width="${q}"/>`},U=t.map((Q,ne)=>({p:Q,pi:ne,depth:p(Q)})).filter(({p:Q})=>o.has(Q.id)).sort((Q,ne)=>Q.depth-ne.depth||Q.pi-ne.pi);let X=!1;D+=`<g${he("packages")}>`;for(const{p:Q,pi:ne}of U){const Z=O(Q.id);if(Z===void 0)continue;X=!0;const q=Q.stereotype!==void 0?`<text x="${Z.x+Z.w-10}" y="${Z.y+ho+16}" class="t-eyebrow" text-anchor="end"${_(`packages.${ne}.stereotype`)}>«${S(Q.stereotype)}»</text>`:"";D+=`<g${_(`packages.${ne}`)}>`+F(Z,!1)+`<text x="${Z.x+10}" y="${Z.y+ho+17}" class="t-name c-muted"${_(`packages.${ne}.name`)}>${S(Q.name)}</text>`+q+"</g>"}const B=[],te=new Set,ee=qs(n),H=Hs(n,Q=>O(Q));let W=`<g${he("deps")}>`;n.forEach((Q,ne)=>{const Z=O(Q.from),q=O(Q.to);if(Z===void 0||q===void 0||Q.from===Q.to)return;Q.kind!==void 0&&te.add(Q.kind);const de=Fs(Z,q,ee[ne]??0,H[ne]??0);W+=`<path d="${de.d}" fill="none" stroke="var(--muted)" stroke-width="1.5" stroke-dasharray="5 4" marker-end="url(#skArrow)"${_(`deps.${ne}`)}/>`;const le=[Q.kind!==void 0?`«${Q.kind}»`:void 0,Q.label].filter(J=>J!==void 0).join(" ");B.push({lx:de.lx,ly:de.ly,...le.length>0?{label:le}:{},path:`deps.${ne}`})}),W+="</g>";let K="";const R=[];t.forEach((Q,ne)=>{if(d.get(Q.id)===void 0)return;const q=O(Q.id);if(q===void 0)return;R.push(q);const de=K2(Q.contains),le=Q.stereotype!==void 0?12:20,J=lt(Q.name,le,1)[0]??"",ue=J!==Q.name?`<title>${S(Q.name)}</title>`:"";let ve=`<g${_(`packages.${ne}`)}>${F(q,!0)}`;if(ve+=`<text x="${q.x+10}" y="${q.y+ho+17}" class="t-name"${_(`packages.${ne}.name`)}>${ue}${S(J)}</text>`,Q.stereotype!==void 0&&(ve+=`<text x="${q.x+q.w-10}" y="${q.y+ho+16}" class="t-eyebrow" text-anchor="end"${_(`packages.${ne}.stereotype`)}>«${S(Q.stereotype)}»</text>`),de.length>0){const we=q.y+ho+W2;ve+=`<line x1="${q.x}" y1="${we}" x2="${q.x+q.w}" y2="${we}" stroke="var(--rule-solid)" stroke-width="1"/>`,ve+=`<g${he(`packages.${ne}.contains`)}>`,de.forEach(($e,je)=>{const De=je>=Vp,Me=De?"":_(`packages.${ne}.contains.${je}`);ve+=`<text x="${q.x+10}" y="${we+6+(je+1)*U2-2}" class="t-sub${De?" c-soft":" c-ink"}"${Me}>${S($e)}</text>`}),ve+="</g>"}ve+="</g>",K+=ve}),D+=K+"</g>"+W;const{overlay:z,legend:Y}=Ws(B,R,{skin:!0});D+=z+"</svg>";const V=[{swatch:"node",label:"package"}];X&&V.push({swatch:"node-fill2",label:"parent package"}),n.length>0&&V.push({swatch:"edge-dashed",label:"dependency"});for(const Q of["import","use","access","merge"])te.has(Q)&&V.push({swatch:"chip",chip:`«${Q}»`,label:Q});const re=ot(V);return ct({tag:"PACKAGES",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...re.length>0?{legendHtml:re}:{}},D+Y)}var bV=["critical","high","medium","low","info"],V2={critical:0,high:1,medium:2,low:3,info:4};function wV(e){return e.map((t,n)=>({f:t,i:n})).sort((t,n)=>V2[t.f.severity]-V2[n.f.severity]||t.i-n.i)}function $V(e){const t=new Map;for(const n of e)t.set(n.severity,(t.get(n.severity)??0)+1);return bV.filter(n=>(t.get(n)??0)>0).map(n=>({severity:n,n:t.get(n)??0}))}function G2(e,t=""){return`<span class="rk-sev rk-sev-${e} au-sev${t}">`}function SV(e){const t=e.findings,n=g=>t.some(v=>v[g]!==void 0&&String(v[g]).length>0),s={id:n("id"),evidence:n("evidence"),fix:n("fix"),owner:n("owner"),status:n("status")},o=[];e.scope!==void 0&&o.push(`<span class="au-m"${_("scope")}><span class="au-k">scope</span>${S(e.scope)}</span>`),e.date!==void 0&&o.push(`<span class="au-m"${_("date")}><span class="au-k">date</span>${S(e.date)}</span>`),e.auditor!==void 0&&o.push(`<span class="au-m"${_("auditor")}><span class="au-k">auditor</span>${S(e.auditor)}</span>`);const r=e.title!==void 0||o.length>0?'<div class="au-head">'+(e.title!==void 0?`<span class="au-title"${_("title")}>${S(e.title)}</span>`:"")+(o.length>0?`<span class="au-meta">${o.join("")}</span>`:"")+"</div>":"",i=e.description!==void 0?`<p class="au-desc"${_("description")}>${S(e.description)}</p>`:"",l=$V(t).map(({severity:g,n:v})=>`${G2(g," au-count")}<b class="au-n">${v}</b> ${g}</span>`).join(""),d=`<div class="au-counts"><span class="au-total t-sub">${t.length} finding${t.length===1?"":"s"}</span>${l}</div>`,u=(g,v="")=>`<th${v!==""?` class="${v}"`:""}>${g}</th>`,p="<thead><tr>"+(s.id?u("ID","au-c-id"):"")+u("Severity","au-c-sev")+u("Finding")+(s.evidence?u("Evidence"):"")+(s.fix?u("Fix"):"")+(s.owner?u("Owner","au-c-owner"):"")+(s.status?u("Status","au-c-status"):"")+"</tr></thead>",h=wV(t).map(({f:g,i:v})=>{const y=`findings.${v}`,b=g.area!==void 0?`<span class="au-area"${_(`${y}.area`)}>${S(g.area)}</span>`:"",E=g.ref!==void 0?`<span class="au-ref"${_(`${y}.ref`)}>${S(g.ref)}</span>`:"",$=g.status!==void 0?`<span class="rk-status au-st au-st-${g.status}"${_(`${y}.status`)}>${S(g.status)}</span>`:"";return`<tr class="au-row au-sev-row-${g.severity}"${_(y)}>`+(s.id?`<td class="au-id"${_(`${y}.id`)}>${S(g.id??"")}</td>`:"")+`<td class="au-c-sev">${G2(g.severity)}${S(g.severity)}</span></td><td class="au-finding"><span class="au-ftitle"${_(`${y}.title`)}>${S(g.title)}</span>${b}${E}</td>`+(s.evidence?`<td class="au-evidence"${_(`${y}.evidence`)}>${S(g.evidence??"")}</td>`:"")+(s.fix?`<td class="au-fix"${_(`${y}.fix`)}>${S(g.fix??"")}</td>`:"")+(s.owner?`<td class="au-owner"${_(`${y}.owner`)}>${S(g.owner??"")}</td>`:"")+(s.status?`<td class="au-c-status">${$}</td>`:"")+"</tr>"}).join(""),m=`<div class="au-scroll"><table class="au-table">${p}<tbody${he("findings")}>${h}</tbody></table></div>`;return`<div class="audit">${r}${i}${d}${m}</div>`}var EV={pass:"✓",fail:"✗",partial:"◐",na:"—",pending:"○"},MV={pass:"pass",fail:"fail",partial:"partial",na:"n/a",pending:"pending"};function AV(e){const t={pass:0,fail:0,partial:0,pending:0,na:0};for(const o of e)t[o.status]+=1;const n=t.pass+t.fail+t.partial+t.pending,s=n===0?null:(t.pass+t.partial/2)/n*100;return{...t,rate:s}}function Y2(e,t){const n=e.evidence!==void 0?`<span class="cl-evidence"${_(`${t}.evidence`)}>${S(e.evidence)}</span>`:"",s=e.note!==void 0?`<span class="cl-note"${_(`${t}.note`)}>${S(e.note)}</span>`:"",o=e.ref!==void 0?`<span class="cl-ref"${_(`${t}.ref`)}>${S(e.ref)}</span>`:"";return`<div class="cl-item cl-s-${e.status}"${_(t)}><span class="cl-verdict cl-v-${e.status}"${_(`${t}.status`)}><span class="cl-glyph" aria-hidden="true">${EV[e.status]}</span>${MV[e.status]}</span><div class="cl-body"><span class="cl-text"${_(`${t}.item`)}>${S(e.item)}</span>${n}${s}${o}</div></div>`}function CV(e){const t=e.items??[],n=e.groups??[],s=[...t,...n.flatMap(h=>h.items)],o=e.title!==void 0||e.standard!==void 0?'<div class="cl-head">'+(e.title!==void 0?`<span class="cl-title"${_("title")}>${S(e.title)}</span>`:"")+(e.standard!==void 0?`<span class="cl-standard"${_("standard")}>${S(e.standard)}</span>`:"")+"</div>":"",r=e.description!==void 0?`<p class="cl-desc"${_("description")}>${S(e.description)}</p>`:"";let i="";t.length>0&&(i+=`<div class="cl-items"${he("items")}>${t.map((h,m)=>Y2(h,`items.${m}`)).join("")}</div>`),n.length>0&&(i+=`<div class="cl-groups"${he("groups")}>`,n.forEach((h,m)=>{i+=`<div class="cl-group"${_(`groups.${m}`)}><div class="cl-group-label t-eyebrow"${_(`groups.${m}.label`)}>${S(h.label)}</div><div class="cl-items"${he(`groups.${m}.items`)}>${h.items.map((g,v)=>Y2(g,`groups.${m}.items.${v}`)).join("")}</div></div>`}),i+="</div>");const l=AV(s),d=[`${l.pass} pass`,`${l.fail} fail`];l.partial>0&&d.push(`${l.partial} partial`),l.pending>0&&d.push(`${l.pending} pending`),l.na>0&&d.push(`${l.na} n/a`);const u=l.rate===null?"—":`${Math.round(l.rate)}%`,p=s.length>0?`<div class="cl-foot"><span class="cl-counts">${d.join(" · ")}</span><span class="cl-rate">pass rate <b>${u}</b></span></div>`:"";return`<div class="checklist">${o}${r}${i}${p}</div>`}function Bv(e){return`<div class="evc-section">${S(e)}</div>`}function X2(e,t){const n=e.map((s,o)=>`<li${_(`${t}.${o}`)}>${S(s)}</li>`).join("");return`<ul class="mc-list"${he(t)}>${n}</ul>`}function NV(e){const t=e.some(o=>o.split!==void 0),n=e.some(o=>o.note!==void 0),s=e.map((o,r)=>{const i=`metrics.${r}`;return`<tr${_(i)}><td class="evc-fname"${_(`${i}.name`)}>${S(o.name)}</td><td class="mc-value"${_(`${i}.value`)}>${S(String(o.value))}</td>`+(t?`<td class="evc-type"${_(`${i}.split`)}>${S(o.split??"")}</td>`:"")+(n?`<td class="evc-desc"${_(`${i}.note`)}>${S(o.note??"")}</td>`:"")+"</tr>"}).join("");return'<table class="evc-table mc-metrics"><thead><tr><th>Metric</th><th class="mc-value">Value</th>'+(t?"<th>Split</th>":"")+(n?"<th>Note</th>":"")+`</tr></thead><tbody${he("metrics")}>${s}</tbody></table>`}function TV(e){const n='<div class="evc-head">'+('<span class="evc-eyebrow t-eyebrow">MODEL'+(e.version!==void 0?`<span class="evc-sep">·</span><span${_("version")}>${S(e.version)}</span>`:"")+"</span>")+`<span class="evc-name"${_("name")}>${S(e.name)}</span>`+(e.task!==void 0?`<span class="mc-task"${_("task")}><span class="t-eyebrow">task</span>${S(e.task)}</span>`:"")+"</div>",s=[];e.description!==void 0&&s.push(`<p class="evc-desc-p"${_("description")}>${S(e.description)}</p>`);const o=[],r=(u,p,h)=>{p!==void 0&&o.push(`<div class="mc-cell"${_(h)}><span class="mc-k t-eyebrow">${u}</span><span class="mc-v">${S(p)}</span></div>`)};r("architecture",e.architecture,"architecture"),r("params",e.params,"params"),r("owner",e.owner,"owner"),r("license",e.license,"license"),o.length>0&&s.push(`<div class="mc-spec">${o.join("")}</div>`);const i=[["Intended use","intendedUse",e.intendedUse],["Out of scope","outOfScope",e.outOfScope],["Training data","trainingData",e.trainingData]];for(const[u,p,h]of i)h!==void 0&&h.length>0&&s.push(Bv(u)+X2(h,p));const l=e.metrics??[];l.length>0&&s.push(Bv("Metrics")+NV(l));const d=[["Limitations","limitations",e.limitations],["Ethics","ethics",e.ethics]];for(const[u,p,h]of d)h!==void 0&&h.length>0&&s.push(Bv(u)+X2(h,p));return`<div class="modelcard">${n}<div class="evc-body">${s.join("")}</div></div>`}var Oa=8,bp=22,Xa=150,qr=50,Uc=14,_V=5,Q2=18,LV=16,IV=23,Z2=15,J2=13,jV={done:"var(--paper-2)",current:"var(--accent)",todo:"var(--paper)",negative:"var(--negative-tint)"},PV={done:"var(--rule-solid)",current:"var(--accent)",todo:"var(--ink)",negative:"var(--negative)"},OV={done:"t-name c-muted",current:"t-name ch-on-accent",todo:"t-name c-ink",negative:"t-name c-negative"};function eS(e,t,n){const s=lt(e,t,n),o=e.trim().split(/\s+/).join(" ");let r=s.join(" ")!==o;return{lines:s.map((l,d)=>l.length<=t&&!(r&&d===s.length-1)?l:(r=!0,`${l.slice(0,Math.max(1,t-1)).trimEnd()}…`)),cut:r}}function RV(e,t){const n=s=>s.toFixed(1);return[`${n(e)},${n(t)}`,`${n(e+Xa-Uc)},${n(t)}`,`${n(e+Xa)},${n(t+qr/2)}`,`${n(e+Xa-Uc)},${n(t+qr)}`,`${n(e)},${n(t+qr)}`,`${n(e+Uc)},${n(t+qr/2)}`].join(" ")}function DV(e){const t=e.steps,n=t.length,s=e.current!==void 0&&Number.isFinite(e.current)?Math.round(e.current):void 0,o=s!==void 0&&s>=1&&s<=n,r=(N,j)=>j==="red"?"negative":o?N+1===s?"current":N+1<s?"done":"todo":"todo",i=t.map(N=>eS(N.label,LV,2)),l=t.map(N=>N.desc!==void 0?eS(N.desc,IV,2):{lines:[],cut:!1}),d=Math.min(Oa,n),u=Math.ceil(n/Oa),p=Xa-Uc+_V,h=bp*2+(d-1)*p+Xa,m=[];for(let N=0;N<u;N+=1){const j=l.slice(N*Oa,(N+1)*Oa),P=Math.max(0,...j.map(I=>I.lines.length));m.push(qr+(P>0?8+P*J2:0))}const g=bp*2+m.reduce((N,j)=>N+j,0)+(u-1)*Q2,v=N=>N.toFixed(1),y=Hy("Process chevrons",e.title,[wt(n,"step")]);let b=`<svg viewBox="0 0 ${v(h)} ${v(g)}" role="img" aria-label="${S(y)}"><title>${S(y)}</title>`;const E=new Set;b+=`<g${he("steps")}>`;let $=bp;t.forEach((N,j)=>{const P=Math.floor(j/Oa),I=j%Oa;I===0&&P>0&&($+=(m[P-1]??qr)+Q2);const O=bp+I*p,C=$,D=r(j,N.accent);E.add(D);const F=i[j]??{lines:[N.label],cut:!1},U=l[j]??{lines:[],cut:!1},X=O+Xa/2+Uc/4;let B=`<g class="ch-step ch-${D}"${_(`steps.${j}`)}>`;(F.cut||U.cut)&&(B+=`<title>${S(N.desc!==void 0?`${N.label} — ${N.desc}`:N.label)}</title>`),B+=`<polygon points="${RV(O,C)}" fill="${jV[D]}" stroke="${PV[D]}" stroke-width="${D==="current"?1.5:1.25}" stroke-linejoin="round"/>`;const te=F.lines.length,ee=C+qr/2-(te-1)*Z2/2+4.5;if(F.lines.forEach((H,W)=>{B+=`<text x="${v(X)}" y="${v(ee+W*Z2)}" class="${OV[D]}" text-anchor="middle"${W===0?_(`steps.${j}.label`):""}>${S(H)}</text>`}),U.lines.length>0){const H=C+qr+8+10;U.lines.forEach((W,K)=>{B+=`<text x="${v(X)}" y="${v(H+K*J2)}" class="t-sub c-muted" text-anchor="middle"${K===0?_(`steps.${j}.desc`):""}>${S(W)}</text>`})}b+=B+"</g>"}),b+="</g></svg>";const A=[];E.has("done")&&A.push({swatch:"node-fill2",label:"done"}),E.has("current")&&A.push({swatch:"node-accent",label:"current step"}),E.has("todo")&&A.push({swatch:"node",label:o?"upcoming":"step"}),E.has("negative")&&A.push({swatch:"node-negative",label:"failure / exit"});const T=ot(A);return ct({tag:"CHEVRONS",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...T.length>0?{legendHtml:T}:{}},b)}var Nr=22,BV=150,zV=260,FV=26,$c=24,tS=6,zv=10,Fv=6,RA=6.4,qV=22,qv=15,HV={done:'fill="var(--paper-2)" stroke="var(--rule-solid)" stroke-width="1"',current:'fill="var(--paper)" stroke="var(--accent)" stroke-width="1.5"',next:'fill="var(--paper)" stroke="var(--ink)" stroke-width="1.25"',later:'fill="var(--paper)" stroke="var(--muted)" stroke-width="1.25" stroke-dasharray="4 3"',risk:'fill="var(--negative-tint)" stroke="var(--negative)" stroke-width="1.25"'},WV={done:"rm-label t-sub c-muted",current:"rm-label t-sub c-ink rm-current",next:"rm-label t-sub c-ink",later:"rm-label t-sub c-soft",risk:"rm-label t-sub c-negative"},UV={done:"node-fill2",current:"node-accent-outline",next:"node",later:"node-dashed",risk:"node-negative"},KV=["done","current","next","later","risk"];function VV(e){const t=[];return e.map(n=>{let s=t.findIndex(o=>o.every(r=>n.to<r.from||n.from>r.to));return s===-1&&(s=t.length,t.push([])),t[s]?.push({from:n.from,to:n.to}),{...n,lane:s}})}function GV(e,t){const n=Math.max(3,Math.floor(t/RA));return e.length<=n?{text:e,cut:!1}:{text:`${e.slice(0,n-1).trimEnd()}…`,cut:!0}}function YV(e){const t=e.periods,n=new Map;t.forEach((D,F)=>{n.has(D)||n.set(D,F)});const s=e.themes!==void 0?[...e.themes]:[];if(e.themes===void 0)for(const D of e.items)s.includes(D.theme)||s.push(D.theme);const o=new Map;for(const D of s)o.set(D,[]);e.items.forEach((D,F)=>{const U=o.get(D.theme),X=n.get(D.from),B=D.to!==void 0?n.get(D.to):X;U===void 0||X===void 0||B===void 0||U.push({i:F,item:D,from:Math.min(X,B),to:Math.max(X,B)})});const r=s.map(D=>VV(o.get(D)??[])),i=r.flat().filter(D=>D.from===D.to),l=Math.max(0,...i.map(D=>D.item.label.length*RA+16+Fv*2+4)),d=Math.min(zV,Math.max(BV,Math.ceil(l))),u=s.map(D=>lt(D,qV,3)),h=Nr+Math.max(60,...u.map(D=>Math.max(...D.map(F=>F.length))*7.2))+14,m=t.length*d,g=h+m+Nr,v=r.map((D,F)=>{const U=Math.max(1,...D.map(te=>te.lane+1)),X=U*$c+(U-1)*tS,B=(u[F]?.length??1)*qv;return Math.max(X,B)+zv*2}),y=Nr+FV,b=v.reduce((D,F)=>D+F,0),E=y+b+Nr,$=D=>D.toFixed(1),A=r.reduce((D,F)=>D+F.length,0),T=Hy("Roadmap",e.title,[wt(s.length,"theme"),wt(t.length,"period"),wt(A,"item")]);let N=`<svg viewBox="0 0 ${$(g)} ${$(E)}" role="img" aria-label="${S(T)}"><title>${S(T)}</title>`;N+=`<g${he("periods")}>`,t.forEach((D,F)=>{const U=h+F*d;N+=`<text x="${$(U+d/2)}" y="${$(Nr+12)}" class="t-eyebrow" text-anchor="middle"${_(`periods.${F}`)}>${S(D)}</text>`,N+=`<line x1="${$(U)}" y1="${$(y)}" x2="${$(U)}" y2="${$(y+b)}" stroke="var(--rule)" stroke-width="1"${ut}/>`}),N+="</g>",N+=`<line x1="${$(h+m)}" y1="${$(y)}" x2="${$(h+m)}" y2="${$(y+b)}" stroke="var(--rule)" stroke-width="1"${ut}/>`,N+=`<line x1="${$(Nr)}" y1="${$(y)}" x2="${$(h+m)}" y2="${$(y)}" stroke="var(--rule-solid)" stroke-width="1"/>`;const j=new Set;let P=y;N+=`<g${he("items")}>`,s.forEach((D,F)=>{const U=v[F]??$c+zv*2,X=u[F]??[D],B=P+U/2-(X.length-1)*qv/2+4.5,te=e.themes!==void 0?_(`themes.${F}`):"";X.forEach((ee,H)=>{N+=`<text x="${$(Nr)}" y="${$(B+H*qv)}" class="t-name c-ink rm-theme"${H===0?te:""}>${S(ee)}</text>`});for(const ee of r[F]??[]){const H=ee.item.status??"next";j.add(H);const W=h+ee.from*d+Fv,K=(ee.to-ee.from+1)*d-Fv*2,R=P+zv+ee.lane*($c+tS),z=GV(ee.item.label,K-16),Y=ee.item.note!==void 0?`${ee.item.label} — ${ee.item.note}`:ee.item.label;N+=`<g class="rm-item rm-${H}"${_(`items.${ee.i}`)}><title>${S(Y)}</title><rect x="${$(W)}" y="${$(R)}" width="${$(K)}" height="${$c}" rx="3" ${HV[H]}/><text x="${$(W+8)}" y="${$(R+$c/2+3.5)}" class="${WV[H]}"${_(`items.${ee.i}.label`)}>${S(z.text)}</text></g>`}P+=U,N+=`<line x1="${$(Nr)}" y1="${$(P)}" x2="${$(h+m)}" y2="${$(P)}" stroke="var(--rule)" stroke-width="1"${ut}/>`}),N+="</g>";const I=e.now!==void 0?n.get(e.now):void 0;if(I!==void 0){const D=h+I*d;N+=`<g class="rm-now"${_("now")}><line x1="${$(D)}" y1="${$(y-6)}" x2="${$(D)}" y2="${$(y+b)}" stroke="var(--ink)" stroke-width="1.25" stroke-dasharray="4 3"/><text x="${$(D+5)}" y="${$(y-9)}" class="t-eyebrow c-ink">now</text></g>`}N+="</svg>";const O=KV.filter(D=>j.has(D)).map(D=>({swatch:UV[D],label:D==="current"?"current — in progress":D==="next"?"next / planned":D}));I!==void 0&&O.push({swatch:"line-dashed",stroke:"var(--ink)",label:"now"});const C=ot(O);return ct({tag:"ROADMAP",...e.title!==void 0?{title:e.title}:{},...e.description!==void 0?{desc:e.description}:{},...C.length>0?{legendHtml:C}:{}},N)}var DA={meta:l8,callout:f8,table:K8,sequence:q8,erd:x8,userstory:Y8,timeline:G8,kanban:M8,prose:X8,glossary:Z8,proscons:J8,cvt:ez,stats:nz,code:hz,agenda:mz,tree:bz,pyramid:wz,flow:f9,state:h9,dfd:m9,journey:k9,gantt:E9,graph:M9,quadrant:A9,swimlane:N9,c4:j9,uml:D9,frontend:z9,cluster:tq,block:J9,felogic:lq,wireframe:pq,endpoint:vq,pullquote:yq,layers:kq,matrix:Sq,anatomy:Eq,composition:Mq,drivers:Cq,options:Tq,spec:Lq,list:Oq,stories:qq,pattern:Kq,gallery:Yq,chart:TH,figure:_H,steps:IH,faq:OH,envelope:BH,slo:HH,swot:UH,okr:YH,persona:ZH,changelog:tW,team:sW,heatmap:iW,scorecard:lW,risk:uW,palette:kW,typescale:$W,dodont:EW,inventory:CW,array:TW,linkedlist:IW,bintree:PW,hashmap:DW,agentloop:FW,trace:WW,prompt:GW,context:YW,archmap:tU,divider:nU,bignumber:oU,takeaways:rU,statustable:dU,cycle:uU,benchmark:mU,sankey:wU,gitgraph:$U,treemap:MU,packet:NU,venn:PU,wardley:qU,harvey:HU,scqa:UU,scenarios:KU,fishbone:GU,storymap:ZU,eventcontract:eK,saga:cK,slopegraph:mK,spans:CK,rollout:_K,perfbudget:DK,percentiles:qK,timing:YK,threatmodel:sV,neuralnet:dV,mindmap:mV,usecase:yV,pkg:kV,audit:SV,checklist:CV,modelcard:TV,chevrons:DV,roadmap:YV};function BA(){return'<svg width="0" height="0" style="position:absolute" aria-hidden="true"><defs><marker id="gArrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="var(--charcoal)"/></marker><marker id="gSoft" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="var(--gray)"/></marker><marker id="gErr" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="var(--negative)"/></marker><marker id="gTri" viewBox="0 0 14 14" refX="13" refY="7" markerWidth="14" markerHeight="14" orient="auto-start-reverse"><path d="M1,1 L13,7 L1,13 z" fill="var(--paper)" stroke="var(--purple)" stroke-width="1.2"/></marker><marker id="skArrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="var(--muted)"/></marker><marker id="skOpen" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path d="M1,1 L9,5 L1,9" fill="none" stroke="var(--muted)" stroke-width="1.6"/></marker><marker id="skErr" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="var(--negative)"/></marker><marker id="skAccent" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" fill="var(--accent)"/></marker><filter id="gshadow" x="-20%" y="-20%" width="140%" height="170%"><feDropShadow dx="0" dy="2" stdDeviation="3" flood-color="var(--ink)" flood-opacity="0.13"/></filter></defs></svg>'}var zA="textbook",XV={textbook:{label:"Editorial",vars:{}}};function QV(e){const t=XV[e].vars,n=[];for(const s of Object.keys(t))n.push(`${s}:${t[s]};`);return n.join("")}function FA(e){const t=new WeakMap;for(let n=0;n<e.length-1;n++){const s=e[n],o=e[n+1];if(s===void 0||o===void 0||s.kind!=="markdown"||o.kind==="markdown")continue;const r=Z6(s.text);r!==void 0&&t.set(o,r.text)}return t}function qA(e){return e<10?`0${e}`:String(e)}var ZV=new Set(["divider","takeaways"]);function JV(e){if(e===null||typeof e!="object")return{};const t=e,n={};return typeof t.title=="string"&&t.title.length>0&&(n.title=t.title),typeof t.lede=="string"&&t.lede.length>0&&(n.lede=t.lede),n}function eG(e,t,n,s){const o=`<div class="section-num">SECTION ${qA(e)} · ${S(t)}</div>`;if(n===void 0&&s===void 0)return`<div class="section-head bare">${o}</div>`;const r=n!==void 0?`<h2 class="section-title"${_("title")}>${S(n)}</h2>`:"",i=s!==void 0?`<p class="section-lede"${_("lede")}>${S(s)}</p>`:"";return'<div class="section-head">'+o+r+i+"</div>"}function tG(e,t){const n=DA[e];return n(t)}function nG(e,t){if(e.kind==="meta")return"";if(e.parseError!==void 0)return`<div class="err">${S(e.kind)} block — parse error:
2838
+ ${S(e.parseError)}</div>`;if(e.data===null||e.data===void 0)return"";const{title:n,lede:s}=JV(e.data),o=ZV.has(e.kind),r=!o&&n!==void 0&&typeof e.data=="object"?{...e.data,title:void 0}:e.data,i=tG(e.kind,r),l=t.headingFor.get(e),d=!o&&n!==void 0&&l!==void 0&&qM(l,n),u=n??(o?void 0:l);t.sectionNum+=1;const p=t.sectionNum,h=`section-${qA(p)}`;t.sections.push({id:h,num:p,label:Aw(e),...u!==void 0?{title:u}:{},...e.id!==void 0?{blockId:e.id}:{}});const m=eG(p,Aw(e),o||d?void 0:n,s),g=e.id!==void 0?`<span class="block-anchor" id="${S(e.id)}" aria-hidden="true"></span>`:"",v=e.id!==void 0?` data-block-id="${S(e.id)}"`:"";return`<section id="${h}" class="section-block"${v}>${g}${m}${i}</section>`}function T0(e,t){return e.kind==="markdown"?g0(e.text):nG(e,t)}function HA(e,t){let n=QV(e);if(t!==void 0)for(const s of Object.keys(t))n+=`${s}:${t[s]};`;return n}function Zi(e,t={}){const n=e.meta?.title??"Untitled",s=t.theme??zA,o=HA(s,t.themeVars),r={sectionNum:0,sections:[],headingFor:FA(e.segments)},i=e.segments.map(l=>{const d=r.sections.length,u=T0(l,r),p=r.sections.length>d?r.sections[r.sections.length-1]:void 0;return{html:u,...p!==void 0?{sectionId:p.id,sectionNum:p.num}:{}}});return{css:m4,themeVars:o,title:n,defs:BA(),cover:g4(e.meta),segments:i,sections:r.sections}}function sG(e,t={}){const{css:n,themeVars:s,title:o,defs:r,cover:i,segments:l,sections:d}=Zi(e,t),u=r+i+l.map(p=>p.html).join("");return{css:n,themeVars:s,body:u,title:o,sections:d}}var fn=e=>Array.isArray(e)?e.length:0;function oG(e){const t=[e.items,e.rows,e.stats,e.blocks,e.levels,e.terms,e.parts,e.gates,e.nodes,e.screens,e.classes,e.states,e.entities,e.tasks,e.columns,e.lanes,e.steps,e.clusters,e.personas,e.areas,e.series,e.causes];let n=0;for(const s of t)n=Math.max(n,fn(s));return n}var rG={drivers:2,persona:2,chart:2,erd:2,composition:2,wireframe:2,spec:1.5,timeline:1.5,table:1.4,benchmark:1.4,sankey:1.2,gitgraph:1.2,treemap:1.2,packet:1.4,wardley:1.2,harvey:1.4,scenarios:1.4,scqa:1.6,matrix:1.2,flow:1.2,state:1.2,dfd:1.2,graph:1.2,swimlane:1.2,c4:1.2,uml:1.2,frontend:1.2,cluster:1.2,block:1.2,felogic:1.2,archmap:1.2,cycle:1.2,fishbone:1.4,slopegraph:.9,eventcontract:1.4,saga:1.6,spans:.7,rollout:1.6,perfbudget:.8,percentiles:.8,timing:1.2,threatmodel:1.6,neuralnet:.7,mindmap:.7,usecase:1,pkg:1.2,audit:1,checklist:.8,modelcard:1.4,chevrons:.7,roadmap:.9};function iG(e){if(e.kind==="meta")return 0;if(e.parseError!==void 0||e.data===null||e.data===void 0)return 2;const t=e.data;if(e.kind==="callout"||e.kind==="pullquote")return 3;if(e.kind==="proscons")return 2+(fn(t.pros)+fn(t.cons))*1.1;if(e.kind==="cvt")return 2+(fn(t.current?.items)+fn(t.target?.items))*1.1;if(e.kind==="code"){let n=0,s=fn(t.blocks);for(const o of t.blocks??[])n+=String(o.code??"").split(`
2839
2839
  `).length;return typeof t.code=="string"&&(s+=1,n+=t.code.split(`
2840
- `).length),2+s*1.5+n*.35}if(e.kind==="sequence")return 2+fn(t.actors)*.6+fn(t.messages)*.9;if(e.kind==="options"){let n=0;const s=t.items??[];for(const o of s)n+=fn(o.pros)+fn(o.cons);return 2+fn(t.items)*2+n*.4}if(e.kind==="kanban"){let n=0;for(const s of t.columns??[])n+=fn(s.cards);return 2+fn(t.columns)+n*.7}if(e.kind==="storymap"){let n=0;for(const s of t.slices??[])for(const o of s.cells??[])n+=fn(o);return 2+fn(t.backbone)*.4+fn(t.slices)+n*.5}if(e.kind==="userstory")return 2+fn(t.criteria)*1.5+fn(t.links)*.4;if(e.kind==="statustable"){let n=0;const s=t.rows??[];for(const o of s)n+=fn(o.subtasks);return 2+(fn(t.rows)+n)*1.4}return 2+sG(t)*(oG[e.kind]??1.1)}var nS=10,iG=8,aG=2.2,lG=12.5;function cG(e,t={}){const n=e.meta?.title??"Untitled",s=t.theme??zA,o=HA(s,t.themeVars),r={sectionNum:0,sections:[],headingFor:FA(e.segments)},i=[];e.meta!==void 0&&i.push({label:"Cover",title:n,html:g4(e.meta)});const l=/^(#{1,2})\s+(.+?)\s*$/;if(e.segments.some(u=>u.kind==="markdown"&&u.text.split(`
2841
- `).some(p=>l.test(p)))){let u=[],p,h,m,g,v,y=!1,b;const E=T=>{const N=u.map(j=>j.h).join("");if(N.trim()!==""||p!==void 0&&!T){const j=u.filter(F=>F.block).length,P=u.reduce((F,U)=>F+U.chars,0),I=m??(g==="split"?"center":j>=2||j>=1&&P>240?"top":"center"),O=g==="split"&&N.trim()!==""?`<div class="sl-msg">${u.filter(F=>!F.block).map(F=>F.h).join("")}</div><div class="sl-exhibit">${u.filter(F=>F.block).map(F=>F.h).join("")}</div>`:N,C=F=>{if(F.kind!=="block")return;const U=F.data;return typeof U?.lede=="string"&&U.lede.length>0?U.lede:void 0},D=u.map(F=>C(F.part)).find(F=>F!==void 0);i.push({label:h??"Slide",...p!==void 0?{title:p}:{},...D!==void 0?{lede:D}:{},...v!==void 0?{source:v}:{},...b!==void 0?{part:b}:{},html:O,align:I,...g!==void 0?{layout:g}:{},...y?{nobuild:!0}:{},parts:u.map(F=>F.part)})}u=[],h=void 0,T||(p=void 0,m=void 0,g=void 0,v=void 0,y=!1)},$=()=>u.reduce((T,N)=>T+N.w,0),A=(T,N,j=0)=>{const P=T.html,I=T.kind==="block",O=I&&N>=iG;if(g!=="split"&&u.length>0){if(O){const C=u[u.length-1],D=C!==void 0&&!C.block&&C.w<=aG&&N<lG?u.pop():void 0;u.length>0&&E(!0),D!==void 0&&u.push(D)}else if($()+N>nS){const C=u.every(D=>!D.block);I&&C&&$()>=2&&N>=3?(g="split",m=void 0):E(!0)}}u.push({h:P,w:O?Math.max(N,nS+.5):N,block:I,chars:j,part:T})};for(const T of e.segments)if(T.kind!=="meta")if(T.kind==="markdown"){let N=[];const j=()=>{const P=N.join(`
2840
+ `).length),2+s*1.5+n*.35}if(e.kind==="sequence")return 2+fn(t.actors)*.6+fn(t.messages)*.9;if(e.kind==="options"){let n=0;const s=t.items??[];for(const o of s)n+=fn(o.pros)+fn(o.cons);return 2+fn(t.items)*2+n*.4}if(e.kind==="kanban"){let n=0;for(const s of t.columns??[])n+=fn(s.cards);return 2+fn(t.columns)+n*.7}if(e.kind==="storymap"){let n=0;for(const s of t.slices??[])for(const o of s.cells??[])n+=fn(o);return 2+fn(t.backbone)*.4+fn(t.slices)+n*.5}if(e.kind==="userstory")return 2+fn(t.criteria)*1.5+fn(t.links)*.4;if(e.kind==="statustable"){let n=0;const s=t.rows??[];for(const o of s)n+=fn(o.subtasks);return 2+(fn(t.rows)+n)*1.4}return 2+oG(t)*(rG[e.kind]??1.1)}var nS=10,aG=8,lG=2.2,cG=12.5;function dG(e,t={}){const n=e.meta?.title??"Untitled",s=t.theme??zA,o=HA(s,t.themeVars),r={sectionNum:0,sections:[],headingFor:FA(e.segments)},i=[];e.meta!==void 0&&i.push({label:"Cover",title:n,html:g4(e.meta)});const l=/^(#{1,2})\s+(.+?)\s*$/;if(e.segments.some(u=>u.kind==="markdown"&&u.text.split(`
2841
+ `).some(p=>l.test(p)))){let u=[],p,h,m,g,v,y=!1,b;const E=T=>{const N=u.map(j=>j.h).join("");if(N.trim()!==""||p!==void 0&&!T){const j=u.filter(F=>F.block).length,P=u.reduce((F,U)=>F+U.chars,0),I=m??(g==="split"?"center":j>=2||j>=1&&P>240?"top":"center"),O=g==="split"&&N.trim()!==""?`<div class="sl-msg">${u.filter(F=>!F.block).map(F=>F.h).join("")}</div><div class="sl-exhibit">${u.filter(F=>F.block).map(F=>F.h).join("")}</div>`:N,C=F=>{if(F.kind!=="block")return;const U=F.data;return typeof U?.lede=="string"&&U.lede.length>0?U.lede:void 0},D=u.map(F=>C(F.part)).find(F=>F!==void 0);i.push({label:h??"Slide",...p!==void 0?{title:p}:{},...D!==void 0?{lede:D}:{},...v!==void 0?{source:v}:{},...b!==void 0?{part:b}:{},html:O,align:I,...g!==void 0?{layout:g}:{},...y?{nobuild:!0}:{},parts:u.map(F=>F.part)})}u=[],h=void 0,T||(p=void 0,m=void 0,g=void 0,v=void 0,y=!1)},$=()=>u.reduce((T,N)=>T+N.w,0),A=(T,N,j=0)=>{const P=T.html,I=T.kind==="block",O=I&&N>=aG;if(g!=="split"&&u.length>0){if(O){const C=u[u.length-1],D=C!==void 0&&!C.block&&C.w<=lG&&N<cG?u.pop():void 0;u.length>0&&E(!0),D!==void 0&&u.push(D)}else if($()+N>nS){const C=u.every(D=>!D.block);I&&C&&$()>=2&&N>=3?(g="split",m=void 0):E(!0)}}u.push({h:P,w:O?Math.max(N,nS+.5):N,block:I,chars:j,part:T})};for(const T of e.segments)if(T.kind!=="meta")if(T.kind==="markdown"){let N=[];const j=()=>{const P=N.join(`
2842
2842
  `).trim();if(P!==""){const I=g0(N.join(`
2843
2843
  `));I.trim()!==""&&A({kind:"prose",html:I,text:P},Math.max(1,P.length/180),P.length)}N=[]};for(const P of T.text.split(`
2844
- `)){const I=l.exec(P);if(I!==null){j(),E(!1);const O=I[2]??"",C=FM(O);C!==void 0&&(v=C);const D=Q6(O);D==="split"?g="split":D!==void 0&&(m=D==="middle"||D==="center"?"center":D==="bottom"?"bottom":"top"),X6(O)&&(y=!0),p=by(O)}else N.push(P)}j()}else{if(T.kind==="divider"){const N=T.data,j=typeof N?.label=="string"?N.label:typeof N?.title=="string"?N.title:void 0;j!==void 0&&j!==""&&(u.length>0&&E(!1),b=j)}A({kind:"block",html:T0(T,r),type:T.kind,data:T.data},rG(T)),h=r.sections[r.sections.length-1]?.label}E(!1)}else{let u="",p=[];for(const h of e.segments){if(h.kind==="markdown"){const v=g0(h.text);v.trim()!==""&&(u+=v,p.push({kind:"prose",html:v,text:h.text.trim()}));continue}if(h.kind==="meta")continue;const m=T0(h,r),g=r.sections[r.sections.length-1];i.push({label:g?.label??"Section",...g?.title!==void 0?{title:g.title}:{},html:u+m,parts:[...p,{kind:"block",html:m,type:h.kind,data:h.data}]}),u="",p=[]}u.trim()!==""&&i.push({label:"Notes",html:u,parts:p})}return{css:m4,themeVars:o,title:n,defs:BA(),slides:i}}function WA(e){return e==="light"?{stamp:' data-theme="light"',style:""}:e==="system"?{stamp:"",style:`<style>${n8}</style>`}:{stamp:"",style:""}}function UA(e,t={}){const n=nG(e,t),s=n.themeVars.length>0?`
2844
+ `)){const I=l.exec(P);if(I!==null){j(),E(!1);const O=I[2]??"",C=FM(O);C!==void 0&&(v=C);const D=Q6(O);D==="split"?g="split":D!==void 0&&(m=D==="middle"||D==="center"?"center":D==="bottom"?"bottom":"top"),X6(O)&&(y=!0),p=by(O)}else N.push(P)}j()}else{if(T.kind==="divider"){const N=T.data,j=typeof N?.label=="string"?N.label:typeof N?.title=="string"?N.title:void 0;j!==void 0&&j!==""&&(u.length>0&&E(!1),b=j)}A({kind:"block",html:T0(T,r),type:T.kind,data:T.data},iG(T)),h=r.sections[r.sections.length-1]?.label}E(!1)}else{let u="",p=[];for(const h of e.segments){if(h.kind==="markdown"){const v=g0(h.text);v.trim()!==""&&(u+=v,p.push({kind:"prose",html:v,text:h.text.trim()}));continue}if(h.kind==="meta")continue;const m=T0(h,r),g=r.sections[r.sections.length-1];i.push({label:g?.label??"Section",...g?.title!==void 0?{title:g.title}:{},html:u+m,parts:[...p,{kind:"block",html:m,type:h.kind,data:h.data}]}),u="",p=[]}u.trim()!==""&&i.push({label:"Notes",html:u,parts:p})}return{css:m4,themeVars:o,title:n,defs:BA(),slides:i}}function WA(e){return e==="light"?{stamp:' data-theme="light"',style:""}:e==="system"?{stamp:"",style:`<style>${n8}</style>`}:{stamp:"",style:""}}function UA(e,t={}){const n=sG(e,t),s=n.themeVars.length>0?`
2845
2845
  <style>:root{${n.themeVars}}</style>`:"",o=WA(t.colorScheme);return`<!doctype html>
2846
2846
  <html lang="en"${o.stamp}>
2847
2847
  <head>
@@ -2856,7 +2856,7 @@ ${o8}
2856
2856
  `+n.body+`</div>
2857
2857
  </body>
2858
2858
  </html>
2859
- `}var dG={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"},Tr=e=>e.replace(/[&<>"]/g,t=>dG[t]??t),uG=`
2859
+ `}var uG={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"},Tr=e=>e.replace(/[&<>"]/g,t=>uG[t]??t),pG=`
2860
2860
  *{box-sizing:border-box;}
2861
2861
  html,body{margin:0;height:100%;}
2862
2862
  /* Deck chrome in the editorial skin (DESIGN.md): role tokens only, so the deck
@@ -3105,7 +3105,7 @@ body{background:var(--paper-2);font-family:var(--font-body);color:var(--ink);}
3105
3105
  @media print{@page{size:landscape;}.deck-nav{display:none;}.deck{display:block;padding:0;}
3106
3106
  .docskin.slide{display:flex!important;width:100%;aspect-ratio:auto;min-height:96vh;border-radius:0;box-shadow:none;page-break-after:always;}
3107
3107
  .docskin.slide .rv-hide{visibility:visible!important;opacity:1!important;}}
3108
- `,pG=`(function(){
3108
+ `,fG=`(function(){
3109
3109
  var slides=[].slice.call(document.querySelectorAll('.slide'));
3110
3110
  if(!slides.length)return;
3111
3111
  // SVGs with only a viewBox have no intrinsic size — inside a shrink-wrapped
@@ -3243,24 +3243,24 @@ body{background:var(--paper-2);font-family:var(--font-body);color:var(--ink);}
3243
3243
  window.addEventListener('resize',function(){fit(slides[i]);});
3244
3244
  var h=parseInt((location.hash||'').replace('#',''),10);
3245
3245
  show(isNaN(h)?0:h-1,'jump');
3246
- })();`;function KA(e,t={}){const{css:n,themeVars:s,title:o,defs:r,slides:i}=cG(e,t);let l=0;const d=[];for(const g of i)g.part!==void 0&&!d.includes(g.part)&&d.push(g.part);const u=i.map((g,v)=>{const y=v===0&&g.label==="Cover",b=g.html.includes('"dvd')&&(g.html.match(/section-block/g)??[]).length===1&&!g.html.includes('class="prose"'),E=g.title===void 0&&g.label==="Slide";let $="";if(!y){l+=1;const I=String(l).padStart(2,"0"),O=g.title??g.label;if(!b&&!E){const C=g.lede!==void 0?`<div class="slide-hd-sub">${Tr(g.lede)}</div>`:"",D=d.length>=2?'<div class="slide-track">'+d.map(F=>`<span class="slide-track-part${F===g.part?" on":""}">${Tr(F)}</span>`).join("")+"</div>":"";$=`<div class="slide-hd"><div class="slide-hd-l">${Tr(O)}${C}</div><div class="slide-hd-r">${D}<span>${I} · ${Tr(g.label)}</span></div></div>`}}const A=g.align==="top"?" sl-top":g.align==="bottom"?" sl-bottom":"",T=g.layout==="split"?" sl-split":"",N=g.source!==void 0?`<span class="slide-ft-src">Source: ${Tr(g.source)}</span>`:"",j=y?"":`<div class="slide-ft"><span>${Tr(o)}</span>${N}<span>${v+1} / ${i.length}</span></div>`,P=g.nobuild===!0?' data-nobuild=""':"";return`<div class="docskin slide${y?" slide-cover":""}"${P}>${$}<div class="slide-content${A}${T}"><div class="slide-inner">${g.html}</div></div>${j}</div>`}).join(""),h=`<div class="deck-nav"><button class="deck-btn" id="deck-prev" aria-label="Previous">‹</button><select class="deck-sel" id="deck-jump">${i.map((g,v)=>{const y=String(v+1).padStart(2,"0"),E=/class="dvd-title"[^>]*>([^<]+)</.exec(g.html)?.[1]??g.title??g.label;return`<option value="${v}">${y} · ${Tr(E)}</option>`}).join("")}</select><span class="deck-counter"><b id="deck-cur">1</b> / ${i.length}</span><button class="deck-btn" id="deck-next" aria-label="Next">›</button><span class="deck-live" id="deck-live" aria-live="polite" aria-atomic="true"></span></div>`,m=WA(t.colorScheme);return`<!doctype html><html lang="en"${m.stamp}><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${Tr(o)}</title><style>${n}</style><style>:root{${s}}</style>`+m.style+`<style>${uG}</style></head><body>`+r+`<div class="deck">${u}</div>`+h+`<script>${pG}<\/script></body></html>`}function Mh(e){return e?"dark":"light"}let Sc=null;function id(e,t){if(Sc!==null&&Sc.source===e&&Sc.slug===t)return Sc.value;const n=ys(e,t),s=wy(n,`${t}.md`);let o=null,r=null;try{o=Zi(n)}catch(l){r=l instanceof Error?l.message:String(l)}const i={doc:n,diagnostics:s,rendered:o,renderError:r};return Sc={source:e,slug:t,value:i},i}function fG(e,t){return e.slug===void 0?"refetch-all":t.currentSlug===null||e.slug!==t.currentSlug?"refresh-list":e.hash!==void 0&&t.baseHash!==null&&e.hash===t.baseHash?"ignore-echo":t.dirty?"conflict":"silent-refetch"}function hG(e,t,n){return!(t<0||t>=e.length||n<0||n>e.length||n===t||n===t+1||e[t]==="meta"||n===0&&e[0]==="meta")}function sS(e,t){return e!==null&&e!==""&&t!==null&&t!==""&&e!==t}const mG=800;function gG(e){return`\`\`\`meta
3246
+ })();`;function KA(e,t={}){const{css:n,themeVars:s,title:o,defs:r,slides:i}=dG(e,t);let l=0;const d=[];for(const g of i)g.part!==void 0&&!d.includes(g.part)&&d.push(g.part);const u=i.map((g,v)=>{const y=v===0&&g.label==="Cover",b=g.html.includes('"dvd')&&(g.html.match(/section-block/g)??[]).length===1&&!g.html.includes('class="prose"'),E=g.title===void 0&&g.label==="Slide";let $="";if(!y){l+=1;const I=String(l).padStart(2,"0"),O=g.title??g.label;if(!b&&!E){const C=g.lede!==void 0?`<div class="slide-hd-sub">${Tr(g.lede)}</div>`:"",D=d.length>=2?'<div class="slide-track">'+d.map(F=>`<span class="slide-track-part${F===g.part?" on":""}">${Tr(F)}</span>`).join("")+"</div>":"";$=`<div class="slide-hd"><div class="slide-hd-l">${Tr(O)}${C}</div><div class="slide-hd-r">${D}<span>${I} · ${Tr(g.label)}</span></div></div>`}}const A=g.align==="top"?" sl-top":g.align==="bottom"?" sl-bottom":"",T=g.layout==="split"?" sl-split":"",N=g.source!==void 0?`<span class="slide-ft-src">Source: ${Tr(g.source)}</span>`:"",j=y?"":`<div class="slide-ft"><span>${Tr(o)}</span>${N}<span>${v+1} / ${i.length}</span></div>`,P=g.nobuild===!0?' data-nobuild=""':"";return`<div class="docskin slide${y?" slide-cover":""}"${P}>${$}<div class="slide-content${A}${T}"><div class="slide-inner">${g.html}</div></div>${j}</div>`}).join(""),h=`<div class="deck-nav"><button class="deck-btn" id="deck-prev" aria-label="Previous">‹</button><select class="deck-sel" id="deck-jump">${i.map((g,v)=>{const y=String(v+1).padStart(2,"0"),E=/class="dvd-title"[^>]*>([^<]+)</.exec(g.html)?.[1]??g.title??g.label;return`<option value="${v}">${y} · ${Tr(E)}</option>`}).join("")}</select><span class="deck-counter"><b id="deck-cur">1</b> / ${i.length}</span><button class="deck-btn" id="deck-next" aria-label="Next">›</button><span class="deck-live" id="deck-live" aria-live="polite" aria-atomic="true"></span></div>`,m=WA(t.colorScheme);return`<!doctype html><html lang="en"${m.stamp}><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${Tr(o)}</title><style>${n}</style><style>:root{${s}}</style>`+m.style+`<style>${pG}</style></head><body>`+r+`<div class="deck">${u}</div>`+h+`<script>${fG}<\/script></body></html>`}function Mh(e){return e?"dark":"light"}let Sc=null;function id(e,t){if(Sc!==null&&Sc.source===e&&Sc.slug===t)return Sc.value;const n=ys(e,t),s=wy(n,`${t}.md`);let o=null,r=null;try{o=Zi(n)}catch(l){r=l instanceof Error?l.message:String(l)}const i={doc:n,diagnostics:s,rendered:o,renderError:r};return Sc={source:e,slug:t,value:i},i}function hG(e,t){return e.slug===void 0?"refetch-all":t.currentSlug===null||e.slug!==t.currentSlug?"refresh-list":e.hash!==void 0&&t.baseHash!==null&&e.hash===t.baseHash?"ignore-echo":t.dirty?"conflict":"silent-refetch"}function mG(e,t,n){return!(t<0||t>=e.length||n<0||n>e.length||n===t||n===t+1||e[t]==="meta"||n===0&&e[0]==="meta")}function sS(e,t){return e!==null&&e!==""&&t!==null&&t!==""&&e!==t}const gG=800;function vG(e){return`\`\`\`meta
3247
3247
  title: ${(e.split("/").pop()??e).replace(/[-_]+/g," ").replace(/^\w/,n=>n.toUpperCase())}
3248
3248
  subtitle: One-line description.
3249
3249
  tag: DRAFT
3250
3250
  \`\`\`
3251
- `}let vG=0,wp=null;const ke=vE()((e,t)=>{const n=()=>{wp!==null&&clearTimeout(wp),wp=setTimeout(()=>{wp=null;const r=t();r.autosave&&r.dirty&&r.conflict===null&&!r.saving&&r.save()},mG)},s=(r,i)=>{const l=t();e({undoStack:[...l.undoStack.slice(-99),l.source],redoStack:[],source:r,dirty:!0,...i!==void 0?{selection:i}:{}}),n()},o=async(r=!1)=>{const i=t();if(i.currentSlug===null||i.saving)return;const l=i.currentSlug,d=i.source;e({saving:!0});try{const u=await yw(l,d,i.baseHash??void 0,r);if(t().currentSlug!==l)return;u.ok?(e({baseHash:u.hash,savedSource:d,savedAt:Date.now(),dirty:t().source!==d,conflict:null}),t().refreshDocs()):e({conflict:u.conflict})}catch(u){t().toast(`Save failed: ${u.message}`,"error")}finally{e({saving:!1})}};return{meta:null,docs:[],currentSlug:null,source:"",savedSource:"",baseHash:null,dirty:!1,saving:!1,savedAt:null,autosave:!0,review:null,pendingDelete:null,pendingImport:null,mode:"home",selection:null,partSel:null,penMode:null,conflict:null,undoStack:[],redoStack:[],toasts:[],sheet:null,sheetDirty:!1,sheetFresh:!1,sheetReveal:null,slashHintAt:null,picker:null,dragging:null,loaded:!1,initialVersion:null,updateAvailable:!1,init:async()=>{try{let r=null,i=null;try{const h=await bB(window.location.href);h!==null&&(r=await xw(h.source,h.title??"shared"),window.history.replaceState(null,"",window.location.pathname),i=h.present?"present":"edit");const m=r===null?new URLSearchParams(window.location.search).get("template"):null;if(m!==null&&m!==""){const g=Ny[m];g===void 0?t().toast(`There is no “${m}” template.`,"error"):(r=await xw(g,m),window.history.replaceState(null,"",window.location.pathname),i="edit")}}catch(h){t().toast(`That link could not be opened: ${h.message}`,"error")}const[l,d]=await Promise.all([Pg(),vw()]);e({meta:l,docs:d,loaded:!0,initialVersion:l.version});const u=d[0],p=r??(t().currentSlug===null?u?.slug:void 0);p!==void 0&&await t().openDoc(p),i!==null&&e({mode:i})}catch(r){e({loaded:!0}),t().toast(`Could not reach the studio server: ${r.message}`,"error")}},refreshDocs:async()=>{try{e({docs:await vw()})}catch{}},openDoc:async r=>{try{const i=await Bp(r);e({currentSlug:r,source:i.source,savedSource:i.source,baseHash:i.hash,dirty:!1,selection:null,partSel:null,sheet:null,sheetDirty:!1,conflict:null,review:null,pendingDelete:null,pendingImport:null,undoStack:[],redoStack:[]})}catch(i){t().toast(`Could not open ${r}: ${i.message}`,"error")}},newDoc:async(r,i)=>{try{const l=i??gG(r),d=await yw(r,l);if(!d.ok){t().toast(`A doc named "${r}" already exists.`,"error");return}await t().refreshDocs(),e({currentSlug:r,source:l,savedSource:l,baseHash:d.hash,dirty:!1,selection:null,partSel:null,sheet:null,sheetDirty:!1,conflict:null,review:null,pendingDelete:null,pendingImport:null,undoStack:[],redoStack:[],savedAt:Date.now()}),t().openSheet($B(l,r),!0)}catch(l){t().toast(`Could not create ${r}: ${l.message}`,"error")}},applyOp:(r,i)=>{const l=t();if(l.currentSlug===null)return!1;try{const{doc:d}=id(l.source,l.currentSlug),u=r(l.source,d);return s(u,i),!0}catch(d){return t().toast(`Edit failed: ${d.message}`,"error"),!1}},moveBlock:(r,i)=>{const l=t();if(l.currentSlug===null)return!1;const{doc:d}=id(l.source,l.currentSlug);return hG(d.segments.map(u=>u.kind),r,i)?l.applyOp((u,p)=>tD(u,p,r,i),i<=r?i:i-1):!1},checkVersion:async()=>{const r=t().initialVersion;if(!(r===null||t().updateAvailable))try{const i=await Pg();sS(r,i.version)&&e({updateAvailable:!0})}catch{}},setMode:r=>{const i=t();r!==i.mode&&e({mode:r,...i.sheet!==null?{sheet:null,sheetDirty:!1,sheetFresh:!1}:{},...i.review!==null?{review:null}:{},...i.pendingDelete!==null?{pendingDelete:null}:{},...i.pendingImport!==null?{pendingImport:null}:{},...r!=="edit"?{partSel:null}:{}})},select:r=>e({selection:r,...r!==t().selection?{partSel:null}:{},...r!==t().slashHintAt?{slashHintAt:null}:{}}),setPartSel:r=>e({partSel:r}),setPenMode:r=>e({penMode:r}),save:async(r=!1)=>{const i=t();if(!(i.currentSlug===null||i.saving)){if(!r&&!i.autosave&&i.dirty){e({review:"save"});return}await o(r)}},applyReview:async()=>{const r=t().review;r!==null&&(e({review:null}),await o(),r==="enable-autosave"&&e({autosave:!0}))},cancelReview:()=>e({review:null}),requestDelete:r=>e({pendingDelete:r}),confirmDelete:()=>{const r=t().pendingDelete;r!==null&&(e({pendingDelete:null}),r.run())},cancelDelete:()=>e({pendingDelete:null}),requestImport:r=>e({pendingImport:r}),confirmImport:r=>{const i=t().pendingImport;i!==null&&(e({pendingImport:null}),i.create(r))},cancelImport:()=>e({pendingImport:null}),undo:()=>{const r=t(),i=r.undoStack[r.undoStack.length-1];i!==void 0&&(e({undoStack:r.undoStack.slice(0,-1),redoStack:[...r.redoStack,r.source],source:i,dirty:!0,selection:null,partSel:null}),n())},redo:()=>{const r=t(),i=r.redoStack[r.redoStack.length-1];i!==void 0&&(e({redoStack:r.redoStack.slice(0,-1),undoStack:[...r.undoStack.slice(-99),r.source],source:i,dirty:!0,selection:null,partSel:null}),n())},resolveConflict:r=>{const i=t();i.conflict!==null&&(r==="theirs"?e({undoStack:[...i.undoStack.slice(-99),i.source],redoStack:[],source:i.conflict.currentSource,savedSource:i.conflict.currentSource,baseHash:i.conflict.currentHash,dirty:!1,conflict:null,selection:null,partSel:null}):(e({conflict:null}),t().save(!0)))},setAutosave:r=>{if(r&&t().dirty&&t().conflict===null){e({review:"enable-autosave"});return}e({autosave:r}),r&&n()},setDragging:r=>e({dragging:r}),openSheet:(r,i=!1,l)=>e({sheet:r,sheetDirty:!1,sheetFresh:i,sheetReveal:l??null,selection:r,partSel:null,slashHintAt:null}),closeSheet:(r=!1)=>{const i=t().sheet;e({sheet:null,sheetDirty:!1,sheetFresh:!1,sheetReveal:null,slashHintAt:r&&i!==null?i:null})},setSheetDirty:r=>e({sheetDirty:r}),dismissSlashHint:()=>e({slashHintAt:null}),openPicker:(r={})=>{const i=t();e({picker:{view:r.view??"compact",index:r.index??null,anchor:r.anchor??null},...i.sheet!==null?{sheet:null,sheetDirty:!1,sheetFresh:!1}:{},...i.review!==null?{review:null}:{},...i.pendingDelete!==null?{pendingDelete:null}:{},...i.pendingImport!==null?{pendingImport:null}:{}})},closePicker:()=>e({picker:null}),expandPicker:()=>{const r=t().picker;r!==null&&r.view==="compact"&&e({picker:{...r,view:"browse",anchor:null}})},openLibrary:()=>t().openPicker({view:"browse"}),commitSheet:r=>{const i=t(),l=i.sheet;if(l===null)return!1;const d=i.applyOp((u,p)=>{const h=p.segments[l];if(h===void 0||h.kind==="markdown")throw new TypeError("the sheet block is gone — the doc changed under it");return h.raw===r?u:lh(u,p,l,r)},l);return d&&e({sheet:null,sheetDirty:!1,sheetFresh:!1,slashHintAt:l}),d},handleServerEvent:r=>{if(r.type==="meta"){Pg().then(u=>{const p=t();e({meta:u,...sS(p.initialVersion,u.version)?{updateAvailable:!0}:{}})});return}const i=t(),l=fG(r,{currentSlug:i.currentSlug,baseHash:i.baseHash,dirty:i.dirty});if(i.refreshDocs(),l==="ignore-echo"||l==="refresh-list")return;const d=i.currentSlug;if(d!==null){if(l==="silent-refetch"||l==="refetch-all"){if(i.sheet!==null&&i.sheetDirty)return;Bp(d).then(u=>{const p=t();if(p.currentSlug!==d||p.dirty||u.hash===p.baseHash)return;const h=p.selection,m=ys(u.source,d).segments.length;e({source:u.source,savedSource:u.source,baseHash:u.hash,dirty:!1,selection:h!==null&&h<m?h:null})});return}Bp(d).then(u=>{const p=t();p.currentSlug===d&&u.hash!==p.baseHash&&e({conflict:{currentHash:u.hash,currentSource:u.source}})})}},toast:(r,i="info")=>{const l=++vG;e({toasts:[...t().toasts,{id:l,message:r,tone:i}]}),setTimeout(()=>t().dismissToast(l),5e3)},dismissToast:r=>e({toasts:t().toasts.filter(i=>i.id!==r)})}});function Co(){const e=ke(n=>n.source),t=ke(n=>n.currentSlug)??"untitled";return id(e,t)}const VA="(prefers-color-scheme: dark)";function yG(){return typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia(VA).matches:!1}function Ah(){const[e,t]=oe.useState(yG);return oe.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const n=window.matchMedia(VA),s=o=>t(o.matches);return n.addEventListener("change",s),()=>n.removeEventListener("change",s)},[]),e}function GA(){const e=ke(n=>n.meta?.colorScheme??"dark"),t=Ah();return e==="system"?t?"dark":"light":e}function xG(){const e=GA();return oe.useEffect(()=>{typeof document>"u"||(document.documentElement.dataset.theme=e)},[e]),e}function kG(e){try{const t=JSON.parse(e);return t.type==="meta"?{type:"meta"}:t.type==="fs"?{type:"fs",...typeof t.slug=="string"?{slug:t.slug}:{},...typeof t.hash=="string"?{hash:t.hash}:{}}:null}catch{return null}}function bG(e,t,n=!0){const s=oe.useRef(e);s.current=e;const o=oe.useRef(t);o.current=t,oe.useEffect(()=>{if(!n)return;const r=new EventSource("/__events");return r.onopen=()=>o.current?.(),r.onmessage=i=>{const l=kG(i.data);l!==null&&s.current(l)},()=>r.close()},[n])}const qo=(e,t)=>({from:e,to:t});function ix(e){return{col:e.col,row:e.row}}const wG={flow:{nodesField:"nodes",idField:"id",labelField:"label",edgesField:"edges",edgeTextField:"label",edgeKinds:["error","dashed"],nodeKinds:[{kind:"process",label:"Process"},{kind:"decision",label:"Decision"},{kind:"start",label:"Start"},{kind:"end",label:"End"}],allowSelfLoop:!1,gridNodes:!0,groups:!0,newEdge:qo,newNode:({id:e,kind:t,label:n,cell:s})=>({id:e,label:n,kind:t,col:s.col,row:s.row})},dfd:{nodesField:"nodes",idField:"id",labelField:"name",edgesField:"edges",edgeTextField:"label",nodeKinds:[{kind:"process",label:"Process"},{kind:"external",label:"External"},{kind:"store",label:"Store"}],allowSelfLoop:!1,gridNodes:!0,groups:!0,newEdge:qo,newNode:({id:e,kind:t,label:n,cell:s})=>({id:e,name:n,kind:t,col:s.col,row:s.row})},state:{nodesField:"states",idField:"id",labelField:"name",edgesField:"transitions",edgeTextField:"event",nodeKinds:[{kind:"active",label:"Active"},{kind:"wait",label:"Wait"},{kind:"terminal",label:"Terminal"}],allowSelfLoop:!0,gridNodes:!0,groups:!0,newEdge:(e,t)=>({from:e,to:t,event:""}),newNode:({id:e,kind:t,label:n,cell:s})=>({id:e,name:n,kind:t,col:s.col,row:s.row})},c4:{nodesField:"nodes",idField:"id",labelField:"name",edgesField:"edges",edgeTextField:"label",edgeKinds:["solid","dashed","forbidden","error"],nodeKinds:[{kind:"person",label:"Person"},{kind:"system",label:"System"},{kind:"external",label:"External"},{kind:"store",label:"Store"},{kind:"container",label:"Container"},{kind:"component",label:"Component"}],allowSelfLoop:!1,gridNodes:!0,groups:!0,newEdge:qo,newNode:({id:e,kind:t,label:n,cell:s})=>({id:e,kind:t,name:n,col:s.col,row:s.row})},block:{nodesField:"nodes",idField:"id",labelField:"name",edgesField:"edges",edgeTextField:"label",edgeKinds:["solid","dashed","forbidden","error"],nodeKinds:[{kind:"service",label:"Service"},{kind:"client",label:"Client"},{kind:"db",label:"Database"},{kind:"queue",label:"Queue"},{kind:"cache",label:"Cache"},{kind:"gateway",label:"Gateway"},{kind:"external",label:"External"}],allowSelfLoop:!1,gridNodes:!0,groups:!0,newEdge:qo,newNode:({id:e,kind:t,label:n,cell:s})=>({id:e,name:n,kind:t,col:s.col,row:s.row})},graph:{nodesField:"nodes",idField:"id",labelField:"label",edgesField:"edges",edgeTextField:"label",nodeKinds:[{kind:"node",label:"Node"}],allowSelfLoop:!1,gridNodes:!0,groups:!1,newEdge:qo,newNode:({id:e,label:t,cell:n})=>({id:e,label:t,col:n.col,row:n.row})},swimlane:{nodesField:"steps",idField:"id",labelField:"label",edgesField:"links",edgeTextField:"label",nodeKinds:[{kind:"action",label:"Action"},{kind:"decision",label:"Decision"},{kind:"start",label:"Start"},{kind:"end",label:"End"},{kind:"wait",label:"Wait"}],allowSelfLoop:!1,gridNodes:!0,groups:!1,growRows:!1,placeFields:["col","lane"],writeCell:e=>({col:e.col,lane:e.row-1}),newEdge:qo,newNode:({id:e,kind:t,label:n,cell:s})=>({id:e,kind:t,label:n,col:s.col,lane:s.row-1})},sequence:{nodesField:"actors",idField:"id",labelField:"name",edgesField:"messages",edgeTextField:"label",edgeKinds:["sync","response","async","error","note"],nodeKinds:[],allowSelfLoop:!0,gridNodes:!1,groups:!1,allowDuplicateEdges:!0,columnTargets:!0,editEdgeOnConnect:!0,newEdge:(e,t)=>e===t?{from:e,to:t,kind:"note",label:"note"}:{from:e,to:t,label:"message"}},felogic:{nodesField:"nodes",idField:"id",labelField:"name",edgesField:"edges",edgeTextField:"label",edgeKinds:["uses","implements","reads","egress","https","api","dashed","async"],nodeKinds:[{kind:"component",label:"Component"},{kind:"service",label:"Service"},{kind:"controller",label:"Controller"},{kind:"repository",label:"Repository"},{kind:"adapter",label:"Adapter"},{kind:"model",label:"Model"},{kind:"db",label:"Database"},{kind:"queue",label:"Queue"},{kind:"external",label:"External"}],allowSelfLoop:!1,gridNodes:!0,groups:!0,newEdge:qo,newNode:({id:e,kind:t,label:n,cell:s})=>({id:e,name:n,kind:t,col:s.col,row:s.row})},cluster:{nodesField:"services",idField:"id",labelField:"label",edgesField:"edges",edgeTextField:"label",edgeKinds:["solid","dashed","forbidden","error"],memberField:"cluster",nodeKinds:[{kind:"service",label:"Service"},{kind:"db",label:"Database"},{kind:"queue",label:"Queue"},{kind:"cache",label:"Cache"},{kind:"gateway",label:"Gateway"},{kind:"external",label:"External"}],allowSelfLoop:!1,gridNodes:!1,groups:!1,newEdge:qo,newNode:({id:e,kind:t,label:n})=>({id:e,label:n,kind:t})},erd:{nodesField:"entities",idField:"name",labelField:"name",edgesField:"relations",edgeTextField:"label",nodeKinds:[],allowSelfLoop:!1,gridNodes:!1,groups:!1,edgeChoices:[{value:"1:1",label:"1:1 · one-to-one"},{value:"1:N",label:"1:N · one-to-many"},{value:"N:1",label:"N:1 · many-to-one"},{value:"N:M",label:"N:M · many-to-many"}],edgeChoiceField:"card",newEdge:qo}};function $n(e){return wG[e]??null}function Af(e,t){const n=new RegExp(`^${e.nodesField}\\.(\\d+)$`).exec(t);return n!==null?Number(n[1]):null}function Cf(e,t){const n=new RegExp(`^${e.edgesField}\\.(\\d+)$`).exec(t);return n!==null?Number(n[1]):null}function ax(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function lx(e,t){const n=ax(e)?.[t];return Array.isArray(n)?n:[]}function ad(e,t){return lx(t,e.nodesField).map(ax).filter(n=>n!==null)}function cx(e,t){const n=t[e.idField];return typeof n=="string"?n:null}function no(e,t,n){const o=ad(e,t).find(r=>cx(e,r)===n)?.[e.labelField];return typeof o=="string"&&o!==""?o:n}function Gp(e,t,n,s,o){if(n===s&&!e.allowSelfLoop)return null;const r=lx(t,e.edgesField);if(e.allowDuplicateEdges!==!0&&r.some(d=>{const u=ax(d);return u!==null&&u.from===n&&u.to===s}))return null;const i=o===void 0?e.newEdge(n,s):{...e.newEdge(n,s),...o};return[{path:[e.edgesField,r.length],value:i}]}function $G(e,t){const n=new Set(ad(e,t).map(r=>cx(e,r)).filter(r=>r!==null));let s=ad(e,t).length+1,o=`n${s}`;for(;n.has(o);)s+=1,o=`n${s}`;return o}function dx(e,t,n,s,o,r){const i=e.newNode;if(i===void 0)return null;const l=e.nodeKinds.find(b=>b.kind===s);if(l===void 0)return null;const d=ad(e,t),u=[],p=e.placeFields??["col","row"],h=e.writeCell??ix,g=!(d.length>0&&d.every(b=>p.every(E=>b[E]!==void 0)))&&o!==void 0&&o.length===d.length;g&&o.forEach((b,E)=>{for(const[$,A]of Object.entries(h(b)))u.push({path:[e.nodesField,E,$],value:A})});const v=$G(e,t),y=`New ${l.label.toLowerCase()}`;return u.push({path:[e.nodesField,d.length],value:{...i({id:v,kind:s,label:y,cell:n}),...r??{}}}),{sets:u,nodePath:`${e.nodesField}.${d.length}`,id:v,materialized:g}}function Nf(e,t,n,s,o,r){const l=ad(e,t).find(h=>cx(e,h)===n);if(l===void 0)return null;const d=e.memberField!==void 0&&l[e.memberField]!==void 0?{[e.memberField]:l[e.memberField]}:void 0,u=dx(e,t,s,o,r,d);if(u===null)return null;const p=lx(t,e.edgesField);return u.sets.push({path:[e.edgesField,p.length],value:e.newEdge(n,u.id)}),u}const SG=6;function Ch(e,t,n=SG){return Math.hypot(e,t)>n}const Nh={glossary:"terms",faq:"items",steps:"items",list:"items",takeaways:"items",agenda:"items",team:"members",stats:"stats",saga:"steps"};function Tf(e,t){let n;if(e==="sequence")return n=/^actors\.(\d+)$/.exec(t),n!==null?{mode:"reorder",listPath:"actors",index:Number(n[1])}:null;if(e==="table")return n=/^columns\.(\d+)$/.exec(t),n!==null?{mode:"table-cols",index:Number(n[1])}:(n=/^rows\.(\d+)(?:\.\d+)?$/.exec(t),n!==null?{mode:"reorder",listPath:"rows",index:Number(n[1])}:null);if(e==="kanban")return n=/^columns\.(\d+)\.cards\.(\d+)$/.exec(t),n!==null?{mode:"kanban-card",col:Number(n[1]),index:Number(n[2])}:(n=/^columns\.(\d+)(?:\.label)?$/.exec(t),n!==null?{mode:"reorder",listPath:"columns",index:Number(n[1])}:null);if(e==="timeline")return n=/^items\.(\d+)(?:\.\w+)?$/.exec(t),n!==null?{mode:"reorder",listPath:"items",index:Number(n[1])}:null;const s=Nh[e];if(s!==void 0)return n=new RegExp(`^${s}\\.(\\d+)(?:\\..+)?$`).exec(t),n!==null?{mode:"reorder",listPath:s,index:Number(n[1])}:null;if(e==="cycle")return n=/^steps\.(\d+)(?:\.label)?$/.exec(t),n!==null?{mode:"ring",listPath:"steps",index:Number(n[1])}:null;const o=$n(e);if(o!==null){if(o.gridNodes&&(n=new RegExp(`^${o.nodesField}\\.(\\d+)$`).exec(t),n!==null))return{mode:"grid-node",listPath:o.nodesField,index:Number(n[1])};if(o.groups&&(n=/^groups\.(\d+)$/.exec(t),n!==null))return{mode:"grid-group",index:Number(n[1])}}return null}function Th(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function EG(e,t){if(e==="sequence"||e==="table"||e==="kanban"||e==="timeline"||e==="cycle"||e in Nh)return!0;if($n(e)?.gridNodes!==!0)return!1;const n=Th(t)?.layers;return!(Array.isArray(n)&&n.length>0)}function ux(e){if(e.length===0)return"y";const t=e.map(r=>r.left+r.width/2),n=e.map(r=>r.top+r.height/2),s=Math.max(...t)-Math.min(...t),o=Math.max(...n)-Math.min(...n);return s>=o?"x":"y"}function oS(e,t){return e.map(n=>t==="x"?n.left+n.width/2:n.top+n.height/2)}function rS(e,t){let n=0;for(const s of e)t>s&&(n+=1);return n}function Vr(e,t,n){if(!Number.isInteger(t)||t<0||t>=e.length||!Number.isInteger(n)||n<0||n>e.length||n===t||n===t+1)return null;const s=e.slice(),[o]=s.splice(t,1);return s.splice(n>t?n-1:n,0,o),s}function iS(e,t,n){if(e.length===0)return 0;const s=l=>t==="x"?l.left:l.top,o=l=>t==="x"?l.left+l.width:l.top+l.height,r=e[0],i=e[e.length-1];return n<=0?s(r)-3:n>=e.length?o(i)+3:(o(e[n-1])+s(e[n]))/2}function MG(e,t,n){return Vr(Array.from({length:e},(s,o)=>o),t,n)}function YA(e,t,n){const s=Th(e),o=s!==null&&Array.isArray(s.columns)?s.columns:null;if(o===null)return null;const r=MG(o.length,t,n);if(r===null)return null;const i=[{path:["columns"],value:r.map(d=>o[d])}];return(s!==null&&Array.isArray(s.rows)?s.rows:[]).forEach((d,u)=>{if(!Array.isArray(d))return;const p=d.slice();for(;p.length<o.length;)p.push("");i.push({path:["rows",u],value:[...r.map(h=>p[h]),...p.slice(o.length)]})}),i}function aS(e){const t=Th(e);if(t===null)return null;const n=t.cards;return n===void 0?[]:Array.isArray(n)?n:null}function _0(e,t,n,s,o){const r=Th(e),i=r!==null&&Array.isArray(r.columns)?r.columns:null;if(i===null)return null;const l=aS(i[t]),d=aS(i[s]);if(l===null||d===null)return null;if(t===s){const h=Vr(l,n,o);return h===null?null:[{path:["columns",t,"cards"],value:h}]}const u=l[n];if(u===void 0)return null;const p=Math.max(0,Math.min(o,d.length));return[{path:["columns",t,"cards"],value:l.filter((h,m)=>m!==n)},p===d.length?{path:["columns",s,"cards",p],value:u}:{path:["columns",s,"cards"],value:[...d.slice(0,p),u,...d.slice(p)]}]}function lS(e,t,n){return Math.min(n,Math.max(t,Math.round(e)))}function wo(e,t,n){const s=t/e.scale,o=n/e.scale;return{col:lS((s-e.padX-e.cellW/2)/(e.cellW+e.gapX)+1,1,e.cols+1),row:lS((o-e.padTop-e.cellH/2)/(e.cellH+e.gapY)+1,1,e.rows+1)}}function _f(e,t,n,s=1){return{left:(e.padX+(t-1)*(e.cellW+e.gapX))*e.scale,top:(e.padTop+(n-1)*(e.cellH+e.gapY))*e.scale,width:(s*e.cellW+(s-1)*e.gapX)*e.scale,height:e.cellH*e.scale}}function XA(e){const{placements:t,index:n,target:s,quick:o}=e,r=e.field??"nodes",i=e.writeCell??(m=>({col:m.col,row:m.row})),l=t[n];if(l===void 0||l.col===s.col&&l.row===s.row)return null;const d=t.findIndex((m,g)=>g!==n&&m.col===s.col&&m.row===s.row),u=m=>m===n?s:m===d?l:t[m],p=[],h=m=>{for(const[g,v]of Object.entries(i(u(m))))p.push({path:[r,m,g],value:v})};return o?t.forEach((m,g)=>h(g)):(h(n),d>=0&&h(d)),{sets:p,swapped:d>=0?d:null,materialized:o}}const px="Auto-layout pinned — nodes now keep their positions";function QA(e){const t=Math.max(1,e.length);return{x:e.reduce((n,s)=>n+s.x,0)/t,y:e.reduce((n,s)=>n+s.y,0)/t}}function AG(e,t,n){const s=e.length;if(s<2)return null;const o=QA(e),r=e[0],i=Math.atan2(r.y-o.y,r.x-o.x),l=2*Math.PI/s,u=((Math.atan2(n-o.y,t-o.x)-i)%(2*Math.PI)+2*Math.PI)%(2*Math.PI);return Math.max(1,Math.min(s,Math.ceil(u/l)))}function CG(e,t){const n=Math.max(1,e.length),s=QA(e),o=e[0],r=Math.atan2(o.y-s.y,o.x-s.x),i=e.reduce((d,u)=>d+Math.hypot(u.x-s.x,u.y-s.y),0)/n,l=r+(t-.5)*(2*Math.PI/n);return{x:s.x+i*Math.cos(l),y:s.y+i*Math.sin(l)}}const NG=new Set(["string","number","boolean","enum"]);function TG(e){return e.arms.filter(t=>NG.has(t.kind))}function L0(e){const t=e.arms.filter(n=>n.kind==="object");return t.length===1?t[0]??null:null}function ZA(e){return e.arms.filter(t=>t.kind==="object")}function _h(e,t){const n=ZA(e),s=n[0]??null;if(n.length<=1||!fx(t))return s;const o=Object.keys(t);return n.find(i=>{const l=i.fields.filter(d=>!d.node.optional).map(d=>d.name);return l.length>0&&l.every(d=>o.includes(d))})??s}function Hv(e,t){return e.arms.some(n=>n.kind===t)}const _G=["v","value","text","label","name","title"];function JA(e){for(const n of _G)if(e.fields.some(s=>s.name===n))return n;return e.fields.find(n=>!n.node.optional&&(n.node.kind==="string"||n.node.kind==="union"))?.name??e.fields[0]?.name??"value"}function fx(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Lf(e,t){return fx(e)?e:{[JA(t)]:e??""}}function Lh(e,t){if(fx(e)){const n=e[JA(t)];return n??""}return e??""}function LG(e){const t=TG(e);if(t.length===0)return{kind:"opaque"};const n=new Set(t.map(s=>s.kind));if(n.size===1&&n.has("number"))return{kind:"number"};if(n.size===1&&n.has("boolean"))return{kind:"boolean"};if(n.size===1&&n.has("enum")){const s=[];for(const o of t)if(o.kind==="enum")for(const r of o.options)s.includes(r)||s.push(r);return{kind:"enum",options:s}}return{kind:"text",multiline:!1}}function IG(e,t){if(Hv(t,"number")&&e.trim()!==""){const n=Number(e);if(Number.isFinite(n))return{ok:!0,value:n}}if(Hv(t,"boolean")&&(e==="true"||e==="false"))return{ok:!0,value:e==="true"};if(Hv(t,"string"))return{ok:!0,value:e};for(const n of t.arms)if(n.kind==="enum"&&n.options.includes(e))return{ok:!0,value:e};return{ok:!1}}function ld(e){switch(e.kind){case"string":return"";case"number":return Math.max(0,e.min??0);case"boolean":return!1;case"enum":return e.options[0]??"";case"array":return Array.from({length:e.min??0},()=>ld(e.element));case"object":return eC(e);case"union":{const t=e.arms[0];return t!==void 0?ld(t):""}case"opaque":return null}}function eC(e){const t={};for(const n of e.fields)n.node.optional||(t[n.name]=ld(n.node));if(Object.keys(t).length===0){const n=e.fields.find(s=>s.node.kind==="string"||s.node.kind==="number"||s.node.kind==="enum");n!==void 0&&(t[n.name]=ld(n.node))}return t}function Dn(e){return e===""?[]:e.split(".").map(t=>/^\d+$/.test(t)?Number(t):t)}function If(e){return e.join(".")}function tC(e){return typeof e[e.length-1]=="number"}function as(e){return/(series|species)$/i.test(e)?e:/ies$/.test(e)?e.replace(/ies$/,"y"):/(ses|xes|zes|ches|shes)$/.test(e)?e.replace(/es$/,""):/s$/.test(e)&&!/ss$/.test(e)?e.replace(/s$/,""):e}function $o(e){const t=e.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").toLowerCase().trim();return t===""?e:t.charAt(0).toUpperCase()+t.slice(1)}function hx(e,t){let n=e;for(const s of t){if(n.kind==="array"&&typeof s=="number"){n=n.element;continue}if(n.kind==="object"&&typeof s=="string"){const o=n.fields.find(r=>r.name===s);if(o===void 0)return null;n=o.node;continue}if(n.kind==="union"&&typeof s=="string"){let o;for(const r of n.arms)if(r.kind==="object"&&(o=r.fields.find(i=>i.name===s),o!==void 0))break;if(o===void 0)return null;n=o.node;continue}return null}return n}function is(e,t){let n=e;for(const s of t){if(n===null||typeof n!="object")return;n=n[s]}return n}function Pr(e){const t=[];for(let n=0;n<e.length;n++){const s=e[n];if(typeof s=="string"){const o=e[n+1];typeof o=="number"?(t.push(`${$o(as(s))} ${o+1}`),n+=1):t.push($o(s))}else t.push(`Item ${s+1}`)}return t.join(" · ")}const jG=new Set(["label","title","name","text","summary","term","question"]);function Qa(e,t,n){const o=(e.kind==="union"?_h(e,t[t.length-1]):null)??e;if(o.kind==="array"){const d=t[t.length-1];return Array.isArray(d)&&d.length>0?d.map(()=>""):[""]}if(o.kind!=="object")return o.kind==="string"?`New ${n}`:ld(o);const r=eC(o),i=t[t.length-1],l=i!==null&&typeof i=="object"&&!Array.isArray(i)?i:null;for(const d of Object.keys(r))d==="id"?r[d]=PG(n,t):jG.has(d)?r[d]=`New ${n}`:l!==null&&l[d]!==void 0&&typeof l[d]!="object"?r[d]=l[d]:r[d]===null&&(r[d]="");return r}function PG(e,t){const n=new Set(t.map(r=>r!==null&&typeof r=="object"?String(r.id??""):""));let s=t.length+1,o=`${e}${s}`;for(;n.has(o);)s+=1,o=`${e}${s}`;return o}function nC(e,t,n){if(n!==null&&n.kind==="union")return IG(e,n);const s=n?.kind;if(s==="number"){const o=Number(e);return Number.isFinite(o)&&e.trim()!==""?{ok:!0,value:o}:{ok:!1}}if(s==="boolean")return e==="true"?{ok:!0,value:!0}:e==="false"?{ok:!0,value:!1}:{ok:!1};if(typeof t=="number"){const o=Number(e);return Number.isFinite(o)&&e.trim()!==""?{ok:!0,value:o}:{ok:!0,value:e}}return typeof t=="boolean"?e==="true"?{ok:!0,value:!0}:e==="false"?{ok:!0,value:!1}:{ok:!0,value:e}:{ok:!0,value:e}}function jf(e,t){if(e==="table"){const u=/^rows\.(\d+)\.(\d+)$/.exec(t);if(u!==null)return{kind:"table-cell",row:Number(u[1]),col:Number(u[2])}}const n=Tf(e,t);if(n!==null)return n.mode==="grid-node"?{kind:"grid",listPath:n.listPath,index:n.index}:n.mode==="grid-group"?{kind:"grid-group",index:n.index}:n.mode==="table-cols"?{kind:"table-col",index:n.index}:n.mode==="kanban-card"?{kind:"kanban-card",col:n.col,index:n.index}:{kind:"item",listPath:n.listPath,index:n.index};const s=Dn(t);let o=-1;for(let u=s.length-1;u>=0;u--)if(typeof s[u]=="number"){o=u;break}if(o<0)return{kind:"inert"};const r=If(s.slice(0,o)),i=s[o],l=Tf(e,`${r}.${i}`);if(l!==null&&l.mode==="grid-node")return{kind:"grid",listPath:l.listPath,index:i};const d=o<s.length-1?`.${If(s.slice(o+1))}`:"";return{kind:"item",listPath:r,index:i,...d!==""?{suffix:d}:{}}}function cS(e,t){const n=jf(e,t);switch(n.kind){case"item":return`${n.listPath}.${n.index}`;case"kanban-card":return`columns.${n.col}.cards.${n.index}`;case"grid":return`${n.listPath}.${n.index}`;case"grid-group":return`groups.${n.index}`;case"table-col":return`columns.${n.index}`;default:return null}}function OG(e){return e.kind!=="inert"}function sC(e){return e==="ArrowLeft"||e==="ArrowRight"}function oC(e){return e==="ArrowLeft"||e==="ArrowUp"?-1:1}function RG(e){if(e.axis==="x"!==sC(e.key))return null;const t=oC(e.key),n=e.index+t;return n<0||n>=e.length?null:{gap:t<0?e.index-1:e.index+2,newIndex:n}}function DG(e){const t=oC(e.key);if(sC(e.key)){const o=e.col+t;return o<0||o>=e.colsInRow(e.row)?null:{row:e.row,col:o}}const n=e.row+t;if(n<0||n>=e.rowCount)return null;const s=e.colsInRow(n);return s<=0?null:{row:n,col:Math.min(e.col,s-1)}}function rC(e,t){return t===e||t===e+1?e:t>e?t-1:t}function Wv(e,t,n){return`${e}.${rC(t,n)}`}function BG(e){if(e.fromCol===e.toCol)return`columns.${e.fromCol}.cards.${rC(e.fromIdx,e.gap)}`;const t=Math.max(0,Math.min(e.gap,e.targetLen));return`columns.${e.toCol}.cards.${t}`}function zG(e){return e.sheetOpen?"sheet":e.partSelected?"part":e.blockSelected?"block":"canvas"}let Yp=null;function FG(e){return Yp=e,()=>{Yp===e&&(Yp=null)}}function Ni(e){Yp?.(e)}function iC(e,t,n,s={}){const o=ke.getState(),r=n??ih(t);o.applyOp((l,d)=>Sy(l,d,e,t,r),e)&&(s.openSheet!==!1&&o.openSheet(e,!0),Ni("insert"))}function aC(e){ke.getState().applyOp((n,s)=>{const o=s.segments[e];if(o===void 0)throw new RangeError(`no segment ${e}`);return o.kind==="markdown"?eD(n,s,e+1,o.text):Sy(n,s,e+1,o.kind,o.raw)},e+1)}function lC(e){ke.getState().moveBlock(e,e-1)}function cC(e){ke.getState().moveBlock(e,e+2)}function dS(e){ke.getState().applyOp((t,n)=>Ey(t,n,e),null)}const qG=new Set(["text","desc","description","content","body","summary","lede"]),uS=["navy","blue","teal","green","amber","purple","red","gray"],HG=/^(color|fill|stroke|accent)$/i,WG=/^#[0-9a-f]{3,8}$/i,UG=new Set(["block","cluster"]),KG=new Set(["felogic"]),VG={from:"other-arrays",to:"other-arrays",source:"other-arrays",target:"other-arrays",parent:"own-array",cluster:["clusters"],status:{arrays:["statuses"],idField:"label"}};function Ih(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function pS(e){return e.length>=uS.length&&uS.every(t=>e.includes(t))}function GG(e){for(let t=e.length-1;t>=1;t--)if(typeof e[t]=="number"&&typeof e[t-1]=="string")return e[t-1];return null}function YG(e,t){const n=[];for(const s of e){if(typeof s=="string"){s!==""&&n.push({value:s});continue}const o=Ih(s);if(o===null)return[];if(t!==void 0){const l=o[t];typeof l=="string"&&l!==""&&n.push({value:l});continue}const r=typeof o.id=="string"&&o.id!==""?o.id:typeof o.name=="string"&&o.name!==""&&o.id===void 0?o.name:null;if(r===null)continue;const i=[o.name,o.label,o.title].find(l=>typeof l=="string"&&l!==""&&l!==r);n.push(i!==void 0?{value:r,label:i}:{value:r})}return n}function XG(e,t,n){const s=VG[e];if(s===void 0)return null;const o=Ih(t);if(o===null)return null;const r=GG(n);let i,l;s==="other-arrays"?i=Object.keys(o).filter(p=>p!==r):s==="own-array"?i=r!==null?[r]:[]:"arrays"in s?(i=s.arrays,l=s.idField):i=s;const d=new Set,u=[];for(const p of i){const h=o[p];if(Array.isArray(h))for(const m of YG(h,l))d.has(m.value)||(d.add(m.value),u.push(m))}return u.length>0?u:null}function QG(e){return UG.has(e)?Lz:KG.has(e)?tq:null}function Za(e){const{name:t,node:n,value:s}=e,o=n?.kind;if(o==="boolean")return{kind:"boolean"};if(o==="number")return{kind:"number"};if(o==="enum"){const l=n!==null&&n.kind==="enum"?n.options:[];return pS(l)?{kind:"accent",options:l}:{kind:"enum",options:l}}if(o==="array"||o==="object")return{kind:"opaque"};if(n!==null&&n.kind==="union"){if(s!==null&&typeof s=="object")return{kind:"opaque"};const l=LG(n);if(l.kind==="enum")return pS(l.options)?{kind:"accent",options:l.options}:l;if(l.kind!=="text")return l}if(typeof s!="string"&&s!==void 0&&s!==null&&o===void 0)return{kind:"text",multiline:!1};if(HG.test(t)||typeof s=="string"&&WG.test(s))return{kind:"color"};if(t==="kind"){const l=QG(e.blockKind);if(l!==null)return{kind:"options",options:l.map(d=>({value:d}))}}const r=XG(t,e.data,e.path);return r!==null?{kind:"options",options:r}:{kind:"text",multiline:qG.has(t)||typeof s=="string"&&(s.length>60||s.includes(`
3252
- `))}}const ZG=["title","label","name","text","value","summary","desc","description","question","term","caption","subtitle"],JG=/^(col|row|w|x|y|layer|span|family|external|figure)$/;function fS(e){return e==null||e===""||Array.isArray(e)&&e.length===0}function cl(e,t){const n=Ih(t)??{},s=new Set;for(const l of ZG){if(s.size>=3)break;const d=e.find(u=>u.name===l);d===void 0||!d.node.optional||!fS(n[d.name])||d.node.kind!=="string"&&d.node.kind!=="enum"&&d.node.kind!=="union"||s.add(d.name)}const o=[],r=[],i=[];for(const l of e){if(l.name==="id"){i.push(l);continue}const d=fS(n[l.name]);if(!l.node.optional||!d||l.node.kind==="array"||s.has(l.name)){o.push(l);continue}if(JG.test(l.name)){i.push(l);continue}r.push(l)}return{primary:o,more:r,advanced:i}}function hS(e,t){return e.kind==="union"?t===null||typeof t!="object":e.kind==="string"||e.kind==="number"||e.kind==="boolean"||e.kind==="enum"}function eY(e,t,n=4,s){const o=Ih(t)??{},{primary:r}=cl(e,t);let i=r.filter(l=>hS(l.node,o[l.name])).slice(0,n);if(s!==void 0&&!i.some(l=>l.name===s)){const l=e.find(d=>d.name===s&&hS(d.node,o[d.name]));l!==void 0&&(i=[...i,l])}return{visible:i,hidden:e.length-i.length}}function tY(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:{}}function mS(e){return e.kind==="string"||e.kind==="number"||e.kind==="boolean"||e.kind==="enum"||e.kind==="union"}function nY(e,t){const n=tY(t),s=[];for(const o of cl(e.fields,t).primary){const r=o.node.kind==="array"?o.node.element:null,i=l=>r===null?null:r.kind==="object"?r:r.kind==="union"&&l!==null&&typeof l=="object"?_h(r,l):null;if(r!==null&&(r.kind==="object"||r.kind==="union")){const l=Array.isArray(n[o.name])?n[o.name]:[];let d=!1;l.forEach((p,h)=>{const m=i(p);if(m!==null){d=!0;for(const g of cl(m.fields,p).primary)mS(g.node)&&s.push(`${o.name}.${h}.${g.name}`)}});const u=r.kind==="union"&&r.arms.every(p=>p.kind==="object");r.kind==="union"&&!d&&!u&&s.push(o.name)}else(mS(o.node)||o.node.kind==="array")&&s.push(o.name)}return s}function sY(e,t,n){const s=cl(e.fields,t).primary,o=s.findIndex(r=>r.name===n);return o<0?null:s[o+1]??null}function oY(e){return e.pristine?"exit":e.isLastField?"append":"advance"}function dC(e,t){if(e===t)return!0;if(e===null||t===null||typeof e!="object"||typeof t!="object"||Array.isArray(e)!==Array.isArray(t))return!1;const n=Object.keys(e),s=Object.keys(t);return n.length!==s.length?!1:n.every(o=>dC(e[o],t[o]))}function gS(e){return e==null||e===""||Array.isArray(e)&&e.length===0}function uC(e,t){return dC(e,t)||gS(e)?!0:typeof e!="object"||e===null||Array.isArray(e)?!1:Object.values(e).every(gS)}function rY(e,t,n){const s=t.trim().toLowerCase();return s===""||s===n.trim().toLowerCase()?e:e.filter(o=>o.value.toLowerCase().includes(s)||(o.label?.toLowerCase().includes(s)??!1))}const iY={canvas:[{keys:"↑↓",label:"select"},{keys:"/",label:"insert"},{keys:"⌘S",label:"save"},{keys:"?",label:"shortcuts"}],"canvas-selected":[{keys:"⏎",label:"edit"},{keys:"/",label:"insert"},{keys:"⌘D",label:"duplicate"},{keys:"⌘↑↓",label:"move"},{keys:"?",label:"shortcuts"}],part:[{keys:"⏎",label:"edit"},{keys:"←↑↓→",label:"move"},{keys:"⇥",label:"next part"},{keys:"⌫",label:"delete"},{keys:"esc",label:"back"}],sheet:[{keys:"⇥",label:"next field"},{keys:"⏎",label:"next row"},{keys:"⌘⏎",label:"done (in text: next)"},{keys:"esc",label:"cancel"}],home:[{keys:"click",label:"open a doc"},{keys:"⇧⌘P",label:"present"},{keys:"?",label:"shortcuts"}],present:[{keys:"← →",label:"previous / next slide"},{keys:"home end",label:"first / last slide"},{keys:"esc · ⇧⌘P",label:"back to Edit"}]};function aY(e,t){const n=iY[e];if(e==="canvas-selected"&&(t?.dragParts===!0||t?.parts===!0)){const s=[];return t.dragParts===!0?s.push({keys:"drag",label:"move parts"}):t.parts===!0&&s.push({keys:"click a part",label:"select it"}),[n[0],...s,...n.slice(1)]}return e==="part"&&t?.connectDots===!0?[...n.slice(0,2),{keys:"drag a dot",label:"connect"},...n.slice(2)]:n}function pC(e){if(e.kind==="markdown")return e.text.trim()!=="";const t=e.raw.trim();return t!==""&&t!==ih(e.kind).trim()}function Uv(e,t,n){const s=Dn(n),o=s[s.length-1];if(typeof o!="number")return!0;const r=s.slice(0,-1),i=hx(yy(e),r);if(i===null||i.kind!=="array")return!0;const l=is(t,r);if(!Array.isArray(l)||o>=l.length)return!0;const d=[...r].reverse().find(p=>typeof p=="string")??"item",u=Qa(i.element,l.slice(0,o),as(d));return!uC(l[o],u)}function wl(e){if(e===null||typeof e!="object")return!1;const t=e,n=typeof t.tagName=="string"?t.tagName.toUpperCase():"";return n==="INPUT"||n==="TEXTAREA"||n==="SELECT"?!0:t.isContentEditable===!0}function lY(e){return e.key!=="/"||e.metaKey||e.ctrlKey||e.altKey?!1:!wl(e.target)}const fC="chiltepin-studio-slash-used";function cY(){try{return window.localStorage.getItem(fC)==="1"}catch{return!0}}function dY(){try{window.localStorage.setItem(fC,"1")}catch{}}const vS=40;function Ua(e){if(e.kind==="markdown"){const n=e.text.replace(/\s+/g," ").trim();return n===""?"Text":n.length>vS?`${n.slice(0,vS)}…`:n}const t=e.data;if(t!==null&&typeof t=="object"&&!Array.isArray(t)){const n=t.title;if(typeof n=="string"&&n.trim()!=="")return n.trim()}return il[e.kind]}function yS(e){return e.kind==="markdown"?`markdown\0${e.text}`:`${e.kind}\0${e.raw}`}function hC(e,t,n){const s=ys(e,n).segments,o=ys(t,n).segments,r=new Array(s.length).fill(!1),i=new Map;o.forEach((v,y)=>{const b=yS(v);for(let E=0;E<s.length;E++)if(!r[E]&&yS(s[E])===b){r[E]=!0,i.set(y,E);return}});const l=new Set;let d=-1;for(const[v,y]of[...i.entries()].sort((b,E)=>b[0]-E[0]))y<d?l.add(v):d=y;const u=o.map((v,y)=>y).filter(v=>!i.has(v)),p=s.map((v,y)=>y).filter(v=>!r[v]),h=new Set,m=new Set(p);for(const v of u){const y=o[v].kind,b=p.find(E=>m.has(E)&&s[E].kind===y);b!==void 0&&(m.delete(b),h.add(v))}const g=[];return o.forEach((v,y)=>{l.has(y)?g.push({kind:v.kind,label:Ua(v),change:"reordered"}):h.has(y)?g.push({kind:v.kind,label:Ua(v),change:"edited"}):i.has(y)||g.push({kind:v.kind,label:Ua(v),change:"added"})}),s.forEach((v,y)=>{m.has(y)&&g.push({kind:v.kind,label:Ua(v),change:"removed"})}),g}function Ka(e){if(e==null)return!1;for(const t of e)if(t==="Files")return!0;return!1}function uY(e){return/(^|[\n{,])\s*(['"]?)(openapi|swagger)\2\s*:/.test(e)}function mC(e){return/^```[^\n]*\n([\s\S]*?)\n```\s*$/.exec(e)?.[1]??e}function pY(e){const t=e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"");return t===""?"api":t}function fY(e,t,n=0){let s=0;for(const o of t)e>(o.top+o.bottom)/2&&(s+=1);return Math.max(s,n)}const hY=e=>e.filter(t=>t.level==="warn").map(t=>t.message),xS=e=>e.filter(t=>t.level==="error").map(t=>t.message);function mY(e,t){const n=ID(t);let s=n.kind,o=s==="statustable"?_D(t):s==="chart"?LD(t):hw(t);if(o.data===null&&s!=="table"&&(s="table",o=hw(t)),o.data===null)return{kind:"error",message:`Could not import ${e}: ${xS(o.diagnostics).join("; ")}`};const r=xS(o.diagnostics);return r.length>0?{kind:"error",message:`CSV parse failed for ${e}: ${r.join("; ")}`}:{kind:"block",type:s,body:mC(o.fence),reason:n.reason,warnings:hY(o.diagnostics)}}function gY(e,t){if(!uY(t))return{kind:"unrecognized",message:`${e} is not a recognized import format (no openapi/swagger key).`};try{const n=qD(t),s=n.info.title;return{kind:"openapi",spec:n,title:s,defaultSlug:pY(s)}}catch(n){return{kind:"error",message:`Could not import ${e}: ${n.message}`}}}function vY(e,t,n){const s=n==="sql"?y6(t):n==="dbml"?_M(t):IM(t);if(!s.ok)return{kind:"error",message:`Could not import ${s.line!==void 0?`${e}:${s.line}`:e}: ${s.message}`};const o=Array.isArray(s.data.entities)?s.data.entities.length:0;return{kind:"block",type:"erd",body:mC(UR(s.data)),reason:`${o} ${o===1?"entity":"entities"} read from ${n==="sql"?"SQL DDL":n}`,warnings:[]}}function yY(e,t){const n=PD(e);return n===null?{kind:"unrecognized",message:`${e} is not a recognized import format — drop a .csv, a .sql / .dbml / .prisma schema, or an OpenAPI .yaml/.json.`}:n.id==="csv"?mY(e,t):n.id==="sql"||n.id==="dbml"||n.id==="prisma"?vY(e,t,n.id):gY(e,t)}async function gC(e,t){const n=ke.getState();if(n.mode!=="edit")return;let s;try{s=await e.text()}catch(i){n.toast(`Could not read ${e.name}: ${i.message}`,"error");return}const o=yY(e.name,s),r=ke.getState();switch(o.kind){case"block":{if(r.currentSlug===null){r.toast("Open a doc before importing a CSV.","error");return}iC(t,o.type,o.body,{openSheet:!1});const i=o.type==="table"?"":" · ⌘Z to undo";if(r.toast(`Imported ${e.name} as ${o.type} — ${o.reason}${i}`),o.warnings.length>0){const l=o.warnings[0]??"",d=o.warnings.length>1?` (+${o.warnings.length-1} more)`:"";r.toast(`CSV import warning: ${l}${d}`)}return}case"openapi":{r.requestImport({title:o.title,defaultSlug:o.defaultSlug,create:i=>{const l=i.split("/").pop()??i;ke.getState().newDoc(i,QD(o.spec,{slug:l}))}});return}case"unrecognized":r.toast(o.message);return;case"error":r.toast(o.message,"error");return}}function xY(e){const t=document.createElement("input");t.type="file",t.accept=".csv,.yaml,.yml,.json",t.style.display="none",t.onchange=()=>{const n=t.files?.[0];t.remove(),n!==void 0&&gC(n,e)},document.body.append(t),t.click()}var kY=gE();function Pf(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function Br(e,t){const n=Pf(e)?.[t];return Array.isArray(n)?n:[]}function $p(e,t,n){const s=[];return Br(e,"rows").forEach((o,r)=>{const i=Pf(o);i===null||!Array.isArray(i[t])||s.push({path:["rows",r,t],cells:i[t],pad:n})}),s}const jh={table:{colsPath:"columns",newHeader:()=>"New column",minCols:1,cellArrays:e=>Br(e,"rows").flatMap((t,n)=>Array.isArray(t)?[{path:["rows",n],cells:t,pad:""}]:[])},statustable:{colsPath:"columns",newHeader:()=>"New column",minCols:1,cellArrays:e=>{const t=$p(e,"cells","");return Br(e,"rows").forEach((n,s)=>{Br(n,"subtasks").forEach((o,r)=>{const i=Pf(o);i===null||!Array.isArray(i.cells)||t.push({path:["rows",s,"subtasks",r,"cells"],cells:i.cells,pad:""})})}),t}},matrix:{colsPath:"cols",newHeader:()=>"New column",minCols:1,cellArrays:e=>$p(e,"cells","")},journey:{colsPath:"stages",newHeader:()=>({label:"New stage"}),minCols:1,cellArrays:e=>{const t=$p(e,"cells",""),n=Br(e,"emotion");return n.length>0&&t.push({path:["emotion"],cells:n,pad:3}),t}},heatmap:{colsPath:"xLabels",newHeader:()=>"New",minCols:1,cellArrays:e=>$p(e,"values",0)},storymap:{colsPath:"backbone",newHeader:()=>({label:"New step"}),minCols:1,cellArrays:e=>Br(e,"slices").flatMap((t,n)=>{const s=Pf(t);return s!==null&&Array.isArray(s.cells)?[{path:["slices",n,"cells"],cells:s.cells,pad:[]}]:[]})}};function kS(e){return jh[e]??null}function bS(e,t){const n=jh[e];if(n===void 0)return null;const s=new RegExp(`^${n.colsPath}\\.(\\d+)$`).exec(t);return s!==null?Number(s[1]):null}function bY(e,t){const n=jh[e];if(n===void 0)return null;const s=Br(t,n.colsPath),o=[{path:[n.colsPath,s.length],value:n.newHeader(s.length)}];for(const r of n.cellArrays(t)){if(r.cells.length===s.length){o.push({path:[...r.path,s.length],value:r.pad});continue}const i=r.cells.slice();for(;i.length<s.length+1;)i.push(r.pad);o.push({path:r.path,value:i})}return{sets:o,headerPath:`${n.colsPath}.${s.length}`}}function wS(e,t,n){const s=jh[e];if(s===void 0)return null;const o=Br(t,s.colsPath);if(!Number.isInteger(n)||n<0||n>=o.length||o.length-1<s.minCols)return null;const r=[{path:[s.colsPath],value:o.filter((i,l)=>l!==n)}];for(const i of s.cellArrays(t))n>=i.cells.length||r.push({path:i.path,value:i.cells.filter((l,d)=>d!==n)});return r}const ki=8;function wY(e){const t=[];return e.forEach((n,s)=>{n.separator!==!0&&n.disabled!==!0&&t.push(s)}),t}function vC({items:e,at:t,depth:n,onPick:s,onClose:o,autoFocus:r}){const i=oe.useRef(null),[l,d]=oe.useState(null),[u,p]=oe.useState(-1),[h,m]=oe.useState(null),g=oe.useRef(null);oe.useLayoutEffect(()=>{const $=i.current;if($===null)return;const A=$.offsetWidth,T=$.offsetHeight;let N=t.x,j=t.y;N+A>window.innerWidth-ki&&(N=n>0?Math.max(ki,t.x-A-4-180):Math.max(ki,window.innerWidth-A-ki)),j+T>window.innerHeight-ki&&(j=Math.max(ki,window.innerHeight-T-ki)),d({x:N,y:j})},[t.x,t.y,n]),oe.useEffect(()=>{r&&i.current?.focus()},[r]),oe.useEffect(()=>()=>{g.current!==null&&clearTimeout(g.current)},[]);const v=$=>{const A=e[$],T=i.current?.querySelector(`[data-mi="${$}"]`);if(A===void 0||A.children===void 0||T===void 0||T===null)return;const N=T.getBoundingClientRect();m({index:$,at:{x:N.right+2,y:N.top-5}})},y=($,A)=>{p($);const T=e[$];g.current!==null&&clearTimeout(g.current),T!==void 0&&T.children!==void 0&&T.disabled!==!0?g.current=setTimeout(()=>v($),90):g.current=setTimeout(()=>m(null),120)},b=$=>{const A=e[$];if(!(A===void 0||A.disabled===!0||A.separator===!0)){if(A.children!==void 0){v($);return}s(A)}},E=$=>{if(h!==null)return;const A=wY(e);if(A.length===0)return;const T=A.indexOf(u),N=j=>{const P=A.length,I=T<0?j>0?0:P-1:(T+j+P)%P;p(A[I])};switch($.key){case"ArrowDown":$.preventDefault(),$.stopPropagation(),N(1);return;case"ArrowUp":$.preventDefault(),$.stopPropagation(),N(-1);return;case"Home":$.preventDefault(),p(A[0]);return;case"End":$.preventDefault(),p(A[A.length-1]);return;case"ArrowRight":$.preventDefault(),$.stopPropagation(),u>=0&&e[u]?.children!==void 0&&v(u);return;case"ArrowLeft":$.preventDefault(),$.stopPropagation(),n>0&&o();return;case"Enter":case" ":$.preventDefault(),$.stopPropagation(),u>=0&&b(u);return;case"Escape":$.preventDefault(),$.stopPropagation(),o();return}if($.key.length===1&&!$.metaKey&&!$.ctrlKey&&!$.altKey){const j=$.key.toLowerCase(),I=(T<0?A:[...A.slice(T+1),...A.slice(0,T+1)]).find(O=>(e[O]?.label??"").toLowerCase().startsWith(j));I!==void 0&&($.preventDefault(),p(I))}};return oe.useEffect(()=>{h===null&&r&&i.current?.focus()},[h,r]),w.jsxs(w.Fragment,{children:[w.jsx("div",{ref:i,className:"stu-menu",role:"menu",tabIndex:-1,"data-depth":n,style:{left:l?.x??t.x,top:l?.y??t.y,visibility:l===null?"hidden":"visible"},onKeyDown:E,onPointerDown:$=>$.stopPropagation(),onContextMenu:$=>$.preventDefault(),children:e.map(($,A)=>$.separator===!0?w.jsx("div",{className:"stu-menu-sep",role:"separator"},`s${A}`):w.jsxs("button",{type:"button",role:$.checked!==void 0?"menuitemcheckbox":"menuitem","aria-checked":$.checked,"aria-haspopup":$.children!==void 0?"menu":void 0,"aria-expanded":$.children!==void 0?h?.index===A:void 0,"aria-disabled":$.disabled===!0,"data-mi":A,tabIndex:-1,className:["stu-menu-item",$.danger===!0?"stu-menu-item-danger":"",$.disabled===!0?"stu-menu-item-disabled":"",u===A?"stu-menu-item-active":""].filter(Boolean).join(" "),onPointerEnter:()=>y(A),onClick:T=>{T.stopPropagation(),b(A)},children:[w.jsx("span",{className:"stu-menu-check","aria-hidden":"true",children:$.checked===!0?"✓":""}),w.jsx("span",{className:"stu-menu-label",children:$.label}),$.shortcut!==void 0&&$.children===void 0&&w.jsx("span",{className:"stu-menu-key",children:$.shortcut}),$.children!==void 0&&w.jsx("span",{className:"stu-menu-chev","aria-hidden":"true",children:"▸"})]},`${$.label}${A}`))}),h!==null&&e[h.index]?.children!==void 0&&w.jsx(vC,{items:e[h.index]?.children??[],at:h.at,depth:n+1,onPick:s,onClose:()=>m(null),autoFocus:!0})]})}function $Y({items:e,at:t,onPick:n,onClose:s}){return oe.useEffect(()=>{const o=l=>{l.target instanceof Element&&l.target.closest(".stu-menu")!==null||(l.preventDefault(),l.stopPropagation(),s())},r=()=>s(),i=l=>{l.key==="Escape"&&!(l.target instanceof Element&&l.target.closest(".stu-menu")!==null)&&(l.preventDefault(),l.stopPropagation(),s())};return window.addEventListener("pointerdown",o,!0),window.addEventListener("scroll",r,!0),window.addEventListener("resize",r),window.addEventListener("blur",r),window.addEventListener("keydown",i,!0),()=>{window.removeEventListener("pointerdown",o,!0),window.removeEventListener("scroll",r,!0),window.removeEventListener("resize",r),window.removeEventListener("blur",r),window.removeEventListener("keydown",i,!0)}},[s]),e.length===0?null:w.jsx(vC,{items:e,at:t,depth:0,onPick:n,onClose:s,autoFocus:!0})}function SY(e,t,n){if(t==="")return[];const s=[];for(let o=0;o<e.length;o++)o!==n&&e[o]===t&&s.push(o);return s}function I0(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function EY(e,t){if(e!=="sequence")return!1;const n=I0(t)?.messages;if(!Array.isArray(n))return!1;const s=n.filter(cd);return s.length===0?!1:s.every(o=>{const r=I0(o)?.summary;return typeof r!="string"||r===""})}function cd(e){const t=I0(e);return t===null?!0:!("frame"in t||"else"in t||"end"in t)}function MY(e,t){if(!Array.isArray(e))return t+1;let n=0;for(let s=0;s<=t&&s<e.length;s++)cd(e[s])&&(n+=1);return n}const $S=140,AY=140,SS=120,ES="cubic-bezier(0.2, 0.7, 0.2, 1)",Sp=.5;function CY(e,t){return Math.abs(e.left-t.left)<Sp&&Math.abs(e.top-t.top)<Sp&&Math.abs(e.width-t.width)<Sp&&Math.abs(e.height-t.height)<Sp}function NY(e,t,n,s={}){const o=[],r=[],i=[],l=[],d=s.moves!==!1;for(const[u,p]of t){const h=e.get(u);if(h===void 0){(n(u)?i:r).push(u);continue}CY(h,p)||(n(u)?i.push(u):d&&o.push({key:u,from:h,to:p}))}for(const u of e.keys())t.has(u)||l.push(u);return{moves:o,pops:r,crossfades:i,fades:l}}function TY(e,t){const n=e.left-t.left,s=e.top-t.top,o=t.width>0?e.width/t.width:1,r=t.height>0?e.height/t.height:1,i=Math.abs(o-1)>.01||Math.abs(r-1)>.01?` scale(${o.toFixed(4)}, ${r.toFixed(4)})`:"";return`translate(${n.toFixed(2)}px, ${s.toFixed(2)}px)${i}`}function mx(){return typeof window>"u"||typeof window.matchMedia!="function"?!0:window.matchMedia("(prefers-reduced-motion: reduce)").matches}function yC(e){const t=new Map;for(const n of Array.from(e.querySelectorAll("[data-bp]"))){if(n.closest(".stu-dx-hit")!==null||n.closest(".stu-dx-overlay")!==null)continue;const s=n.getAttribute("data-bp")??"";s!==""&&!t.has(s)&&t.set(s,n)}return t}function xC(e){const t=e.getBoundingClientRect(),n=new Map;for(const[s,o]of yC(e)){const r=o.getBoundingClientRect();n.set(s,{left:r.left-t.left,top:r.top-t.top,width:r.width,height:r.height})}return n}function Kc(e){return typeof e.animate=="function"&&"style"in e}function MS(e,t,n){const s=e.style.transformBox,o=e.style.transformOrigin;e.style.transformBox="fill-box",e.style.transformOrigin=t;const r=()=>{e.style.transformBox=s,e.style.transformOrigin=o};n.addEventListener("finish",r),n.addEventListener("cancel",r)}function _Y(e,t,n,s={}){const o=xC(e),r=NY(t,o,n,s);if(mx())return r;const i=yC(e);for(const l of r.moves){const d=i.get(l.key);if(d===void 0||!Kc(d))continue;const u=d.animate([{transform:TY(l.from,l.to)},{transform:"none"}],{duration:$S,easing:ES});MS(d,"0 0",u)}for(const l of r.pops){const d=i.get(l);if(d===void 0||!Kc(d))continue;const u=d.animate([{transform:"scale(0.92)",opacity:0},{transform:"none",opacity:1}],{duration:AY,easing:ES});MS(d,"center",u)}for(const l of r.crossfades){const d=i.get(l);d===void 0||!Kc(d)||d.animate([{opacity:0},{opacity:1}],{duration:$S,easing:"ease-out"})}return r}function AS(e,t,n){if(mx()||t.length===0){n();return}const s=new Set(t),o=Array.from(e.querySelectorAll("[data-bp]")).filter(d=>s.has(d.getAttribute("data-bp")??"")&&d.closest(".stu-dx-hit")===null&&d.closest(".stu-dx-overlay")===null&&Kc(d));if(o.length===0){n();return}let r=o.length,i=!1;const l=()=>{r-=1,r<=0&&!i&&(i=!0,n())};for(const d of o){if(!Kc(d))continue;const u=d.animate([{opacity:1},{opacity:0}],{duration:SS,easing:"ease-out",fill:"forwards"});u.addEventListener("finish",l),u.addEventListener("cancel",l)}setTimeout(()=>{i||(i=!0,n())},SS+80)}function rs(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function Ho(e,t){const n=rs(e)?.[t];return Array.isArray(n)?n:[]}function LY(e,t,n){return Ho(e,t).map(s=>rs(s)?.[n]).filter(s=>typeof s=="string"&&s!=="")}function IY(e,t,n,s){const o=$n(e);if(o!==null&&t===o.edgesField){const r=LY(s,o.nodesField,o.idField),i=r[0],l=r[1]??(o.allowSelfLoop?r[0]:r[1]);return i!==void 0&&l!==void 0?o.newEdge(i,l):n}if(e==="erd"&&t==="relations"){const r=Ho(s,"entities").map(l=>rs(l)?.name).filter(l=>typeof l=="string"&&l!==""),i=rs(n)??{};return r.length>=2?{...i,from:r[0],to:r[1]}:n}if(e==="statustable"&&/^rows(\.\d+\.subtasks)?$/.test(t)){const r=rs(n)??{},i=Ho(s,"columns"),l=Math.max(1,i.length),d=Array.from({length:l},(p,h)=>h===0?"New row":""),u=rs(Ho(s,"statuses")[0])?.label;return{...r,cells:d,status:typeof u=="string"?u:"todo"}}if(e==="matrix"&&t==="rows"){const r=rs(n)??{},i=Ho(s,"cols").length;return{...r,cells:Array.from({length:i},()=>"")}}if(e==="journey"&&t==="rows"){const r=rs(n)??{},i=Ho(s,"stages").length;return i===0?n:{...r,cells:Array.from({length:i},()=>"")}}if(e==="heatmap"&&t==="rows"){const r=rs(n)??{},i=Math.max(1,Ho(s,"xLabels").length);return{...r,values:Array.from({length:i},()=>0)}}if(e==="scorecard"&&t==="options"){const r=rs(n)??{},i=Ho(s,"criteria").length;return i===0?n:{...r,scores:Array.from({length:i},()=>0)}}if(e==="storymap"&&t==="slices"){const r=rs(n)??{},i=Ho(s,"backbone").length;return{...r,cells:Array.from({length:i},()=>[])}}return e==="prose"&&t==="blocks"?{type:"p",text:"New paragraph"}:e==="okr"&&t==="items"?{...rs(n)??{},krs:[{kr:"New key result",progress:0}]}:n}const jY={glossary:()=>({term:"New term",def:"What it means"}),faq:()=>({q:"New question",a:"The answer"}),steps:()=>({title:"New step"}),list:()=>({lead:"New item"}),takeaways:()=>({text:"New takeaway"}),agenda:()=>({title:"New item"}),team:()=>({name:"New member"}),stats:()=>({value:"0",label:"New stat"}),saga:()=>({id:"step",name:"New step",service:"Service"})};function kC(e,t){const n=jY[e];return n===void 0?null:j0(n(),t)}function j0(e,t){const n=rs(e),s=n?.id;if(n===null||typeof s!="string")return e;const o=new Set(t.map(d=>rs(d)?.id).filter(d=>typeof d=="string")),r=s.replace(/\d+$/,"")===""?"item":s.replace(/\d+$/,"");let i=r,l=2;for(;o.has(i);)i=`${r}${l}`,l+=1;return{...n,id:i}}function Ph(e){return $n(e)?.groups===!0}function CS(e,t,n,s,o){const r=wo(e,t,n),i=wo(e,s,o);return{col:Math.min(r.col,i.col),row:Math.min(r.row,i.row),cols:Math.abs(r.col-i.col)+1,rows:Math.abs(r.row-i.row)+1}}function bC(e,t,n){if(!Ph(e))return null;const s=t!==null&&typeof t=="object"&&!Array.isArray(t)?t:{},o=Array.isArray(s.groups)?s.groups:[],r={col:n.col,row:n.row,cols:n.cols,rows:n.rows,label:"Group"};return{sets:[{path:["groups",o.length],value:r}],groupPath:`groups.${o.length}`}}function wC(e){const t=/^groups\.(\d+)$/.exec(e);return t!==null?Number(t[1]):null}function Ji(e,t){const n=e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null,o=(n!==null&&Array.isArray(n.groups)?n.groups:null)?.[t];if(o==null||typeof o!="object"||Array.isArray(o))return null;const r=o,i=r.col,l=r.row;if(typeof i!="number"||typeof l!="number")return null;const d=typeof r.cols=="number"?r.cols:1,u=typeof r.rows=="number"?r.rows:1;return{col:i,row:l,cols:d,rows:u}}function PY(e,t){return{col:e==="nw"||e==="sw"?t.col+t.cols-1:t.col,row:e==="nw"||e==="ne"?t.row+t.rows-1:t.row}}function OY(e,t){return{col:Math.min(e.col,t.col),row:Math.min(e.row,t.row),cols:Math.abs(e.col-t.col)+1,rows:Math.abs(e.row-t.row)+1}}function $C(e,t,n,s,o){const r=(i,l)=>Math.max(1,Math.min(i,l));return{...e,col:r(e.col+t,s+2-e.cols),row:r(e.row+n,o+2-e.rows)}}function RY(e,t,n,s,o){if(t==="x"){const i=e.cols+n;return i<1||e.col+i-1>s+1?null:{...e,cols:i}}const r=e.rows+n;return r<1||e.row+r-1>o+1?null:{...e,rows:r}}function SC(e,t,n){const s=Ji(e,t);return s===null||s.col===n.col&&s.row===n.row&&s.cols===n.cols&&s.rows===n.rows?null:[{path:["groups",t,"col"],value:n.col},{path:["groups",t,"row"],value:n.row},{path:["groups",t,"cols"],value:n.cols},{path:["groups",t,"rows"],value:n.rows}]}function EC(e,t,n){const s=Ji(e,t);return s===null||s.col===n.col&&s.row===n.row?null:[{path:["groups",t,"col"],value:n.col},{path:["groups",t,"row"],value:n.row}]}function gx(e,t){return{left:(e.padX+(t.col-1)*(e.cellW+e.gapX))*e.scale,top:(e.padTop+(t.row-1)*(e.cellH+e.gapY))*e.scale,width:(t.cols*e.cellW+(t.cols-1)*e.gapX)*e.scale,height:(t.rows*e.cellH+(t.rows-1)*e.gapY)*e.scale}}function NS(e){return e.remove===!0}function DY(e,t,n=null){if(e==="sequence"&&t!==null){let r=/^actors\.(\d+)(?:\..+)?$/.exec(t);return r!==null?{type:"actor",index:Number(r[1])}:(r=/^messages\.(\d+)(?:\..+)?$/.exec(t),r!==null?{type:"message",index:Number(r[1])}:{type:"background"})}if(e==="erd"&&t!==null){let r=/^entities\.(\d+)\.columns\.(\d+)(?:\..+)?$/.exec(t);return r!==null?{type:"column",entity:Number(r[1]),index:Number(r[2])}:(r=/^entities\.(\d+)(?:\..+)?$/.exec(t),r!==null?{type:"entity",index:Number(r[1])}:(r=/^relations\.(\d+)(?:\..+)?$/.exec(t),r!==null?{type:"edge",index:Number(r[1])}:{type:"background"}))}const s=Nh[e];if(s!==void 0){if(t===null)return{type:"background"};const r=new RegExp(`^${s}\\.(\\d+)(?:\\..+)?$`).exec(t);return r!==null?{type:"item",index:Number(r[1])}:{type:"background"}}const o=$n(e);if(o!==null&&t!==null){const r=Af(o,t)??Af(o,t.replace(/^((?:[^.]+)\.\d+)\..+$/,"$1"));if(r!==null)return{type:"node",index:r};const i=Cf(o,t)??Cf(o,t.replace(/^((?:[^.]+)\.\d+)\..+$/,"$1"));if(i!==null)return{type:"edge",index:i};if(o.groups){const l=wC(t);if(l!==null)return{type:"group",index:l}}return{type:"background"}}return t===null&&n!==null&&o!==null&&o.gridNodes?{type:"cell",col:n.col,row:n.row}:{type:"background"}}const vs={label:"",separator:!0};function Kn(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function Zo(e,t){const n=Kn(e)?.[t];return Array.isArray(n)?n:[]}function Ds(e,t){return Zo(e,t).map(n=>Kn(n)??{})}function wn(e,t,n){const s={...e};return n===void 0?delete s[t]:s[t]=n,s}function dl(e){return e.length>0&&/^[a-z]/.test(e)?e.charAt(0).toUpperCase()+e.slice(1):e}const BY=[{dir:"right",arrow:"→"},{dir:"down",arrow:"↓"},{dir:"left",arrow:"←"},{dir:"up",arrow:"↑"}];function Oh(e,t){if(e.placements===null)return[];const n=Ds(e.data,t.nodesField);return e.placements.map((s,o)=>{const r=n[o]?.w;return{col:s.col,row:s.row,w:typeof r=="number"&&r>=1?Math.floor(r):1}})}function Rh(e,t,n){return e.some(s=>s.row===n&&t>=s.col&&t<s.col+s.w)}function zY(e,t,n,s){if(e.placements===null||e.grid===null)return null;const o=Oh(e,t),r=o[n];if(r===void 0)return null;const i=e.grid.cols+1,l=t.growRows===!1?e.grid.rows:e.grid.rows+1;let d=r.col,u=r.row;const p=()=>{s==="right"?d+=1:s==="left"?d-=1:s==="down"?u+=1:u-=1};for(s==="right"?d=r.col+r.w:p();d>=1&&u>=1&&d<=i&&u<=l;){if(!Rh(o,d,u))return{col:d,row:u};p()}return null}function FY(e,t){if(e.grid===null)return{col:1,row:1};const n=Oh(e,t);for(let s=1;s<=e.grid.rows;s++)for(let o=1;o<=e.grid.cols;o++)if(!Rh(n,o,s))return{col:o,row:s};return{col:e.grid.cols+1,row:1}}function qY(e,t,n,s){const o=Oh(e,t).filter((r,i)=>i!==s);for(let r=n.row;r<n.row+n.rows;r++)for(let i=n.col;i<n.col+n.cols;i++)if(!Rh(o,i,r))return{col:i,row:r};return null}function TS(e,t){return e.col>=t.col&&e.col<t.col+t.cols&&e.row>=t.row&&e.row<t.row+t.rows}function _S(e,t,n,s){const o=t.writeCell??(i=>({col:i.col,row:i.row})),r=[];e.quick&&e.placements!==null&&e.placements.forEach((i,l)=>{if(l!==n)for(const[d,u]of Object.entries(o(i)))r.push({path:[t.nodesField,l,d],value:u})});for(const[i,l]of Object.entries(o(s)))r.push({path:[t.nodesField,n,i],value:l});return r}function MC(e,t){const n=[...t.nodeKinds],s=new Set(n.map(o=>o.kind));for(const o of Ds(e.data,t.nodesField)){const r=o.kind;typeof r=="string"&&r!==""&&!s.has(r)&&(s.add(r),n.push({kind:r,label:dl(r)}))}return n}function HY(e,t){if(t.kind==="sequence")return JY(e,t);if(t.kind==="erd")return sX(e,t);const n=Nh[t.kind];if(n!==void 0)return iX(e,t,n);const s=$n(t.kind);if(s===null)return e.type==="background"?[Sd()]:[];switch(e.type){case"node":return UY(e.index,t,s);case"edge":return CC(e.index,t,s);case"group":return YY(e.index,t);case"cell":return XY(e,t,s);default:return QY(t,s)}}function Sd(){return{label:"Open YAML",shortcut:"⏎",action:{type:"openYaml"}}}function AC(e){if(!WY.has(e.kind))return null;const n=Kn(e.data)?.dir==="TB"?"TB":"LR";return{label:"Direction",children:["LR","TB"].map(s=>({label:s==="LR"?"Left → right":"Top → bottom",checked:n===s,op:()=>[{path:["dir"],value:s}]}))}}const WY=new Set(["flow","dfd","state","c4","block","felogic","erd"]);function UY(e,t,n){const s=Ds(t.data,n.nodesField),o=s[e];if(o===void 0)return[];const r=typeof o[n.idField]=="string"?o[n.idField]:"",i=`${n.nodesField}.${e}`,l=[],d=MC(t,n),u=d.length>1||d.length===1&&o.kind!==void 0;if(n.newNode!==void 0&&n.gridNodes)for(const{dir:p,arrow:h}of BY){const m=zY(t,n,e,p),g=y=>{if(m===null)return[];const b=Nf(n,t.data,r,m,y,t.placements??void 0);return b===null?[]:b.sets},v={select:`${n.nodesField}.${s.length}`,edit:n.labelField};l.push(n.nodeKinds.length===1?{label:`Add node ${h}`,disabled:m===null,op:()=>g(n.nodeKinds[0].kind),then:v}:{label:`Add node ${h}`,disabled:m===null,children:d.map(y=>({label:y.label,op:()=>g(y.kind),then:v}))})}else n.memberField!==void 0&&l.push({label:"Add node",children:d.map(p=>({label:p.label,op:()=>{const h=Nf(n,t.data,r,{col:1,row:1},p.kind);return h===null?[]:h.sets},then:{select:`${n.nodesField}.${s.length}`,edit:n.labelField}}))});if(u){const p=o.kind;l.push({label:"Change kind",children:d.map(h=>({label:h.label,checked:p===h.kind,op:()=>[{path:[n.nodesField,e],value:wn(o,"kind",h.kind)}]}))})}if(t.kind==="block"||t.kind==="cluster"){const p=typeof o.replicas=="number"?o.replicas:1,h=[1,2,3,5];l.push({label:"Replicas",children:[...h.map(m=>({label:m===1?"1 (single)":`×${m}`,checked:p===m,op:()=>[{path:[n.nodesField,e],value:wn(o,"replicas",m===1?void 0:m)}]})),{label:"Custom…",action:{type:"edit",path:i,field:"replicas"}}]})}return l.push(...GY(e,o,t,n)),l.push(vs),l.push({label:"Rename",shortcut:"⏎",action:{type:"edit",path:i,field:n.labelField}}),l.push({label:"Delete node",shortcut:"⌫",danger:!0,fades:[i,...KY(t,n,r).map(p=>`${n.edgesField}.${p}`)],op:()=>VY(t,n,e,r)}),l}function KY(e,t,n){const s=[];return Ds(e.data,t.edgesField).forEach((o,r)=>{(o.from===n||o.to===n)&&s.push(r)}),s}function VY(e,t,n,s){const o=Zo(e.data,t.nodesField),r=Ds(e.data,t.edgesField);return r.filter(l=>l.from===s||l.to===s).length===0?[{path:[t.nodesField,n],remove:!0}]:[{path:[t.nodesField],value:o.filter((l,d)=>d!==n)},{path:[t.edgesField],value:r.filter(l=>l.from!==s&&l.to!==s)}]}function GY(e,t,n,s){if(s.groups&&n.placements!==null){const o=Ds(n.data,"groups");if(o.length===0)return[];const r=n.placements[e],i=o.map((u,p)=>Ji(n.data,p)),l=i.findIndex(u=>u!==null&&r!==void 0&&TS(r,u)),d=[{label:"Add to group",children:o.map((u,p)=>{const h=i[p]??null,m=h!==null?qY(n,s,h,e):null;return{label:typeof u.label=="string"?u.label:`Group ${p+1}`,checked:l===p,disabled:l===p||m===null,op:()=>m===null?[]:_S(n,s,e,m)}})}];if(l>=0&&n.grid!==null){const u=Oh(n,s).filter((m,g)=>g!==e);let p=null;for(let m=1;m<=n.grid.rows+1&&p===null;m++)for(let g=1;g<=n.grid.cols+1;g++){const v={col:g,row:m};if(!Rh(u,g,m)&&!i.some(y=>y!==null&&TS(v,y))){p=v;break}}const h=p;d.push({label:"Remove from group",disabled:h===null,op:()=>h===null?[]:_S(n,s,e,h)})}return d}if(n.kind==="graph"){const o=new Set;for(const d of Ds(n.data,s.nodesField))typeof d.group=="number"&&o.add(d.group);const r=typeof t.group=="number"?t.group:null,i=o.size===0?1:Math.max(...o)+1,l=[{label:"Add to group",children:[...[...o].sort((d,u)=>d-u).map(d=>({label:`Group ${d}`,checked:r===d,disabled:r===d,op:()=>[{path:[s.nodesField,e],value:wn(t,"group",d)}]})),{label:`New group ${i}`,op:()=>[{path:[s.nodesField,e],value:wn(t,"group",i)}]}]}];return r!==null&&l.push({label:"Remove from group",op:()=>[{path:[s.nodesField,e],value:wn(t,"group",void 0)}]}),l}if(s.memberField!==void 0){const o=s.memberField,r=Ds(n.data,"clusters");return r.length<2?[]:[{label:"Move to cluster",children:r.map(i=>({label:typeof i.label=="string"?i.label:String(i.id??""),checked:t[o]===i.id,disabled:t[o]===i.id,op:()=>[{path:[s.nodesField,e],value:wn(t,o,i.id)}]}))}]}return[]}function CC(e,t,n){const o=Ds(t.data,n.edgesField)[e];if(o===void 0)return[];const r=`${n.edgesField}.${e}`,i=[];if(n.edgeKinds!==void 0){const l=typeof o.kind=="string"?o.kind:null,d=n.edgeKinds.includes("solid")?"solid":n.edgeKinds.includes("sync")?"sync":null;i.push({label:"Kind",children:n.edgeKinds.map(u=>({label:dl(u),checked:l===u||l===null&&u===d,op:()=>[{path:[n.edgesField,e],value:wn(o,"kind",u===d?void 0:u)}]}))})}else if(t.kind==="graph"){const l=o.dir==="undirected"?"undirected":"directed";i.push({label:"Direction",children:["directed","undirected"].map(d=>({label:dl(d),checked:l===d,op:()=>[{path:[n.edgesField,e],value:wn(o,"dir",d==="directed"?void 0:d)}]}))})}if(n.edgeChoices!==void 0&&n.edgeChoiceField!==void 0){const l=n.edgeChoiceField;i.push({label:"Cardinality",children:n.edgeChoices.map(d=>({label:d.label,checked:o[l]===d.value,op:()=>[{path:[n.edgesField,e],value:wn(o,l,d.value)}]}))})}return i.push({label:n.edgeTextField==="event"?"Edit event":"Edit label",shortcut:"⏎",action:{type:"edit",path:r,field:n.edgeTextField}}),i.push({label:"Reverse",disabled:o.from===o.to,op:()=>[{path:[n.edgesField,e],value:{...o,from:o.to,to:o.from}}]}),i.push(vs),i.push({label:"Delete edge",shortcut:"⌫",danger:!0,fades:[r],op:()=>[{path:[n.edgesField,e],remove:!0}]}),i}function YY(e,t){if(Zo(t.data,"groups")[e]===void 0)return[];const s=`groups.${e}`;return[{label:"Rename",shortcut:"⏎",action:{type:"edit",path:s,field:"label"}},vs,{label:"Delete group",shortcut:"⌫",danger:!0,fades:[s],op:()=>[{path:["groups",e],remove:!0}]}]}function NC(e,t,n,s){if(s.newNode===void 0)return null;const o=MC(n,s),r=Zo(n.data,s.nodesField).length,i={select:`${s.nodesField}.${r}`,edit:s.labelField},l=d=>{const u=dx(s,n.data,t,d,n.placements??void 0);return u===null?[]:u.sets};return s.nodeKinds.length===1?{label:e,op:()=>l(s.nodeKinds[0].kind),then:i}:{label:e,children:o.map(d=>({label:d.label,op:()=>l(d.kind),then:i}))}}function XY(e,t,n){const s=[],o=NC("Insert node here",{col:e.col,row:e.row},t,n);if(o!==null&&s.push(o),n.groups){const r=Zo(t.data,"groups").length;s.push({label:"Insert group here",op:()=>{const i=bC(t.kind,t.data,{col:e.col,row:e.row,cols:1,rows:1});return i===null?[]:i.sets},then:{select:`groups.${r}`,edit:"label"}})}return s}function QY(e,t){const n=[];if(t.gridNodes&&e.grid!==null){const o=NC("Insert node",FY(e,t),e,t);o!==null&&n.push(o)}const s=AC(e);return s!==null&&n.push(s),n.length>0&&n.push(vs),n.push(Sd()),n}const ZY=["sync","response","async","error","note"];function JY(e,t){const n=Ds(t.data,"actors"),s=Zo(t.data,"messages");if(e.type==="actor"){const o=n[e.index];if(o===void 0)return[];const r=typeof o.id=="string"?o.id:"",i=`actors.${e.index}`;return[{label:"Add message from here…",action:{type:"connect",fromIndex:e.index}},{label:"Add note here",op:()=>[{path:["messages",s.length],value:{from:r,to:r,kind:"note",label:"note"}}],then:{select:`messages.${s.length}`,edit:"label"}},vs,{label:"Rename",shortcut:"⏎",action:{type:"edit",path:i,field:"name"}},{label:"Delete actor",shortcut:"⌫",danger:!0,fades:[i,...s.flatMap((l,d)=>{const u=Kn(l);return u!==null&&(u.from===r||u.to===r)?[`messages.${d}`]:[]})],op:()=>{const l=s.filter(d=>{const u=Kn(d);return u===null||u.from!==r&&u.to!==r});return l.length===s.length?[{path:["actors",e.index],remove:!0}]:[{path:["actors"],value:n.filter((d,u)=>u!==e.index)},{path:["messages"],value:l}]}}]}if(e.type==="message"){const o=Kn(s[e.index]);if(o===null)return[];const r=`messages.${e.index}`;if(!cd(o))return[..."frame"in o?[{label:"Edit label",shortcut:"⏎",action:{type:"edit",path:r,field:"label"}}]:[],{label:"Delete marker",shortcut:"⌫",danger:!0,fades:[r],op:()=>[{path:["messages",e.index],remove:!0}]}];const i=typeof o.kind=="string"?o.kind:"sync",l=t.selected!==null?/^messages\.(\d+)$/.exec(t.selected):null,d=l!==null&&cd(s[Number(l[1])])?Number(l[1]):e.index,u=Math.min(d,e.index),p=Math.max(d,e.index),h=u===p?"":` (${p-u+1} messages)`;return[{label:"Kind",children:ZY.map(m=>({label:dl(m),checked:i===m,op:()=>[{path:["messages",e.index],value:wn(o,"kind",m==="sync"?void 0:m)}]}))},{label:"Edit label",shortcut:"⏎",action:{type:"edit",path:r,field:"label"}},{label:"Add step note",shortcut:"n",action:{type:"edit",path:r,field:"summary"}},{label:`Wrap in${h}`,children:lM.map(m=>({label:m,op:()=>[{path:["messages"],value:eX(s,u,p,m)}],then:{select:`messages.${u}`,edit:"label"}}))},{label:"Activate target",checked:o.activate===!0,op:()=>[{path:["messages",e.index],value:wn(o,"activate",o.activate===!0?void 0:!0)}]},{label:"Deactivate sender",checked:o.deactivate===!0,op:()=>[{path:["messages",e.index],value:wn(o,"deactivate",o.deactivate===!0?void 0:!0)}]},vs,{label:"Delete",shortcut:"⌫",danger:!0,fades:[r],op:()=>[{path:["messages",e.index],remove:!0}]}]}return[{label:"Add actor",op:()=>[{path:["actors",n.length],value:{id:tX(n),name:"New actor"}}],then:{select:`actors.${n.length}`,edit:"name"}},vs,Sd()]}function eX(e,t,n,s){return[...e.slice(0,t),{frame:s,label:""},...e.slice(t,n+1),{end:!0},...e.slice(n+1)]}function tX(e){const t=new Set(e.map(o=>String(o.id??"")));let n=e.length+1,s=`actor${n}`;for(;t.has(s);)n+=1,s=`actor${n}`;return s}const nX=[{key:"pk",label:"Primary key"},{key:"fk",label:"Foreign key"},{key:"unique",label:"Unique"},{key:"nullable",label:"Nullable"},{key:"index",label:"Indexed"}];function sX(e,t){const n=$n("erd"),s=Ds(t.data,"entities");if(e.type==="entity"){const i=s[e.index];if(i===void 0)return[];const l=typeof i.name=="string"?i.name:"",d=Zo(i,"columns"),u=`entities.${e.index}`,p=Ds(t.data,"relations");return[{label:"Add column",op:()=>[{path:["entities",e.index,"columns",d.length],value:{name:"new_column",type:"text"}}],then:{select:`${u}.columns.${d.length}`,edit:"name"}},{label:"Add relation to…",action:{type:"connect",fromIndex:e.index}},vs,{label:"Rename",shortcut:"⏎",action:{type:"edit",path:u,field:"name"}},{label:"Delete entity",shortcut:"⌫",danger:!0,fades:[u,...p.flatMap((h,m)=>h.from===l||h.to===l?[`relations.${m}`]:[])],op:()=>{const h=p.filter(m=>m.from!==l&&m.to!==l);return h.length===p.length?[{path:["entities",e.index],remove:!0}]:[{path:["entities"],value:s.filter((m,g)=>g!==e.index)},{path:["relations"],value:h}]}}]}if(e.type==="column"){const i=s[e.entity],l=i!==void 0?Kn(Zo(i,"columns")[e.index]):null;if(l===null)return[];const d=["entities",e.entity,"columns",e.index];return[...nX.map(u=>({label:u.label,checked:l[u.key]===!0,op:()=>[{path:[...d],value:wn(l,u.key,l[u.key]===!0?void 0:!0)}]})),vs,{label:"Rename",shortcut:"⏎",action:{type:"edit",path:d.join("."),field:"name"}},{label:"Delete column",shortcut:"⌫",danger:!0,fades:[d.join(".")],op:()=>[{path:[...d],remove:!0}]}]}if(e.type==="edge")return CC(e.index,t,n);const o=[{label:"Add entity",op:()=>[{path:["entities",s.length],value:{name:oX(s),columns:[{name:"id",type:"uuid",pk:!0}]}}],then:{select:`entities.${s.length}`,edit:"name"}}],r=AC(t);return r!==null&&o.push(r),o.push(vs,Sd()),o}function oX(e){const t=new Set(e.map(o=>String(o.name??"")));let n=e.length+1,s=`Entity${n}`;for(;t.has(s);)n+=1,s=`Entity${n}`;return s}const rX={glossary:{noun:"term",axis:"y",field:"term",min:0},faq:{noun:"question",axis:"y",field:"q",min:1},steps:{noun:"step",axis:"y",field:"title",min:1},list:{noun:"item",axis:"y",field:"lead",min:1},takeaways:{noun:"takeaway",axis:"y",field:"text",min:2,max:6},agenda:{noun:"item",axis:"y",field:"title",min:0},team:{noun:"member",axis:"y",field:"name",min:1},stats:{noun:"stat",axis:"x",field:"label",min:0},saga:{noun:"step",axis:"x",field:"name",min:1}};function iX(e,t,n){const s=rX[t.kind];if(s===void 0)return[];const o=Zo(t.data,n);if(e.type!=="item")return aX(t,n,s,o);const r=e.index,i=Kn(o[r]);if(i===null)return[];const l=o.length,d=s.max!==void 0&&l>=s.max,u=()=>kC(t.kind,o)??{},p=m=>m>=l?[{path:[n,l],value:u()}]:[{path:[n],value:[...o.slice(0,m),u(),...o.slice(m)]}],h=cX(r,i,t,n,o);return[...h,...h.length>0?[vs]:[],{label:s.axis==="x"?"Move left":"Move up",shortcut:s.axis==="x"?"⌥←":"⌥↑",disabled:r===0,op:()=>LS(n,o,r,r-1),then:{select:`${n}.${r-1}`}},{label:s.axis==="x"?"Move right":"Move down",shortcut:s.axis==="x"?"⌥→":"⌥↓",disabled:r>=l-1,op:()=>LS(n,o,r,r+2),then:{select:`${n}.${r+1}`}},{label:"Duplicate",disabled:d,op:()=>r===l-1?[{path:[n,l],value:j0(i,o)}]:[{path:[n],value:[...o.slice(0,r+1),j0(i,o),...o.slice(r+1)]}],then:{select:`${n}.${r+1}`}},{label:"Insert before",disabled:d,op:()=>p(r),then:{select:`${n}.${r}`,edit:s.field}},{label:"Insert after",disabled:d,op:()=>p(r+1),then:{select:`${n}.${r+1}`,edit:s.field}},vs,{label:"Delete",shortcut:"⌫",danger:!0,disabled:l<=s.min,fades:[`${n}.${r}`],op:()=>lX(t,n,o,r)}]}function aX(e,t,n,s){return[{label:`Add ${n.noun}`,disabled:n.max!==void 0&&s.length>=n.max,op:()=>[{path:[t,s.length],value:kC(e.kind,s)??{}}],then:{select:`${t}.${s.length}`,edit:n.field}},vs,Sd()]}function LS(e,t,n,s){const o=Vr(t,n,s);return o===null?[]:[{path:[e],value:o}]}function lX(e,t,n,s){const o=Kn(e.data);if(e.kind==="saga"&&o!==null&&o.failAt===Kn(n[s])?.id){const r=wn(o,"failAt",void 0);return[{path:[],value:{...r,[t]:n.filter((i,l)=>l!==s)}}]}return[{path:[t,s],remove:!0}]}function cX(e,t,n,s,o){return n.kind==="saga"?pX(e,t,n,s,o):n.kind==="stats"?[hX(e,t,s)]:[]}const dX=["ok","failed","skipped","compensated"];function uX(e,t,n){const s=Kn(t[n])?.status;if(typeof s=="string")return s;const o=Kn(e.data)?.failAt,r=o!==void 0?t.findIndex(i=>Kn(i)?.id===o):t.findIndex(i=>Kn(i)?.status==="failed");return r<0?"ok":n<r?"compensated":n===r?"failed":"skipped"}function pX(e,t,n,s,o){const r=typeof t.id=="string"?t.id:"",i=r!==""&&Kn(n.data)?.failAt===r,l=uX(n,o,e),d=[i?{label:"Clear failure point",checked:!0,op:()=>[{path:["failAt"],remove:!0}]}:{label:"Set as failure point",checked:!1,disabled:r==="",op:()=>r===""?[]:[{path:["failAt"],value:r}]},{label:"Status",children:dX.map(u=>({label:dl(u),checked:l===u,op:()=>[{path:[s,e],value:wn(t,"status",u)}]}))}];return typeof t.compensate=="string"&&d.push({label:"Remove compensation",op:()=>[{path:[s,e],value:wn(t,"compensate",void 0)}]}),d}const fX=["up","down","flat"];function hX(e,t,n){const s=t.trend;return{label:"Trend",children:[...fX.map(o=>({label:dl(o),checked:s===o,op:()=>[{path:[n,e],value:wn(t,"trend",o)}]})),{label:"None",checked:s===void 0,op:()=>[{path:[n,e],value:wn(t,"trend",void 0)}]}]}}function zn(e){return{width:e,height:e,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0}}function mX({size:e=14}){return w.jsxs("svg",{...zn(e),stroke:"none",fill:"currentColor",children:[w.jsx("circle",{cx:"5.5",cy:"3.5",r:"1.25"}),w.jsx("circle",{cx:"10.5",cy:"3.5",r:"1.25"}),w.jsx("circle",{cx:"5.5",cy:"8",r:"1.25"}),w.jsx("circle",{cx:"10.5",cy:"8",r:"1.25"}),w.jsx("circle",{cx:"5.5",cy:"12.5",r:"1.25"}),w.jsx("circle",{cx:"10.5",cy:"12.5",r:"1.25"})]})}function IS({size:e=14}){return w.jsxs("svg",{...zn(e),children:[w.jsx("rect",{x:"2",y:"2",width:"5",height:"5",rx:"1"}),w.jsx("rect",{x:"9",y:"2",width:"5",height:"5",rx:"1"}),w.jsx("rect",{x:"2",y:"9",width:"5",height:"5",rx:"1"}),w.jsx("rect",{x:"9",y:"9",width:"5",height:"5",rx:"1"})]})}function P0({size:e=14}){return w.jsxs("svg",{...zn(e),children:[w.jsx("path",{d:"M9.8 3.1 12.9 6.2 6.2 12.9 2.8 13.2 3.1 9.8Z"}),w.jsx("path",{d:"M8.6 4.3l3.1 3.1"})]})}function gX({size:e=14}){return w.jsxs("svg",{...zn(e),children:[w.jsx("path",{d:"M11.6 1.9a1.6 1.6 0 0 1 2.3 2.3L5.6 12.5l-3 .7.7-3Z"}),w.jsx("path",{d:"M10.2 3.3 12.5 5.6"}),w.jsx("path",{d:"M2 14.4h12"})]})}function TC({size:e=14}){return w.jsxs("svg",{...zn(e),children:[w.jsx("rect",{x:"5.5",y:"5.5",width:"8",height:"8",rx:"1.5"}),w.jsx("path",{d:"M10.5 3.5v-1a1 1 0 0 0-1-1h-6a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h1"})]})}function vX({size:e=14}){return w.jsxs("svg",{...zn(e),children:[w.jsx("path",{d:"M8 13V3"}),w.jsx("path",{d:"M3.8 7.2 8 3l4.2 4.2"})]})}function yX({size:e=14}){return w.jsxs("svg",{...zn(e),children:[w.jsx("path",{d:"M8 3v10"}),w.jsx("path",{d:"M3.8 8.8 8 13l4.2-4.2"})]})}function vx({size:e=14}){return w.jsxs("svg",{...zn(e),children:[w.jsx("path",{d:"M2.5 4h11"}),w.jsx("path",{d:"M5.5 4V2.8a1 1 0 0 1 1-1h3a1 1 0 0 1 1 1V4"}),w.jsx("path",{d:"M4 4l.7 9a1 1 0 0 0 1 .9h4.6a1 1 0 0 0 1-.9L12 4"}),w.jsx("path",{d:"M6.6 7v4M9.4 7v4"})]})}function dd({size:e=14}){return w.jsx("svg",{...zn(e),children:w.jsx("path",{d:"M8 3.2v9.6M3.2 8h9.6"})})}function Of({size:e=14}){return w.jsxs("svg",{...zn(e),children:[w.jsx("circle",{cx:"7",cy:"7",r:"4.4"}),w.jsx("path",{d:"m10.4 10.4 3.1 3.1"})]})}function Rf({size:e=14}){return w.jsx("svg",{...zn(e),children:w.jsx("path",{d:"m4 4 8 8M12 4l-8 8"})})}function xX({size:e=14}){return w.jsx("svg",{...zn(e),children:w.jsx("path",{d:"m4 6.2 4 4 4-4"})})}function _C({size:e=14}){return w.jsx("svg",{...zn(e),children:w.jsx("path",{d:"m3 8.6 3.3 3.4L13 4.6"})})}function Df({size:e=14}){return w.jsxs("svg",{...zn(e),children:[w.jsx("path",{d:"M4 1.8h5.2L12 4.6V14.2H4Z"}),w.jsx("path",{d:"M9 1.8v3h3"}),w.jsx("path",{d:"M6 8h4M6 10.5h4"})]})}function yx({size:e=14}){return w.jsxs("svg",{...zn(e),children:[w.jsx("rect",{x:"2.3",y:"2.3",width:"4.9",height:"4.9",rx:"1.1"}),w.jsx("rect",{x:"8.8",y:"2.3",width:"4.9",height:"4.9",rx:"1.1"}),w.jsx("rect",{x:"2.3",y:"8.8",width:"4.9",height:"4.9",rx:"1.1"}),w.jsx("rect",{x:"8.8",y:"8.8",width:"4.9",height:"4.9",rx:"1.1"})]})}function LC({size:e=14}){return w.jsxs("svg",{...zn(e),children:[w.jsx("path",{d:"M8 2.5v7"}),w.jsx("path",{d:"M5.2 6.9 8 9.7l2.8-2.8"}),w.jsx("path",{d:"M2.8 10.5v1.8a1.2 1.2 0 0 0 1.2 1.2h8a1.2 1.2 0 0 0 1.2-1.2v-1.8"})]})}const jS={navy:"#0e54a1",blue:"#2563eb",teal:"#0f766e",green:"#1f9747",amber:"#b45309",purple:"#7c3aed",red:"#b91c1c",gray:"#6b7280"};function kX(e){const t=uM[e];return jS[e]??(t!==void 0?jS[t]:void 0)??"#999"}const bX=[{hex:"#0e54a1",name:"navy"},{hex:"#1a6dbe",name:"blue"},{hex:"#0369a1",name:"sky"},{hex:"#0891b2",name:"cyan"},{hex:"#0f766e",name:"teal"},{hex:"#1f9747",name:"green"},{hex:"#f7952c",name:"orange"},{hex:"#b45309",name:"amber"},{hex:"#991b1b",name:"red"},{hex:"#7c3aed",name:"violet"},{hex:"#6b21a8",name:"purple"},{hex:"#4338ca",name:"indigo"},{hex:"#475569",name:"slate"},{hex:"#6b7280",name:"gray"}],O0=/^#[0-9a-f]{3,8}$/i;function IC(e){return e==null?"":typeof e=="string"?e:String(e)}function wX(e){if(!O0.test(e))return null;const t=e.slice(1);if(t.length===3||t.length===4){const[n,s,o]=[t[0]??"",t[1]??"",t[2]??""];return`#${n}${n}${s}${s}${o}${o}`.toLowerCase()}return`#${t.slice(0,6)}`.toLowerCase()}function $X({node:e,value:t,optional:n,multiline:s,autoFocus:o,handlers:r}){const i=IC(t),[l,d]=oe.useState(i),[u,p]=oe.useState(!1);oe.useEffect(()=>d(i),[i]);const h=g=>{if(l!==i)if(l===""&&n&&r.onDelete!==void 0)r.onDelete();else{const v=nC(l,t,e);if(!v.ok){p(!0);return}r.onCommit(v.value)}g&&r.onDone?.()},m=g=>{d(g),p(!1),r.onStage?.(g)};return s?w.jsx("textarea",{className:"stu-input stu-input-area",value:l,autoFocus:o,rows:3,spellCheck:!1,onChange:g=>m(g.target.value),onBlur:()=>h(!1),onKeyDown:g=>{(g.metaKey||g.ctrlKey)&&g.key==="Enter"&&h(!1)}}):w.jsx("input",{className:`stu-input ${u?"stu-input-invalid":""}`,type:"text",value:l,autoFocus:o,spellCheck:!1,onChange:g=>m(g.target.value),onBlur:()=>h(!1),onKeyDown:g=>{g.key==="Enter"&&(g.preventDefault(),h(!0))}})}function SX({value:e,optional:t,autoFocus:n,handlers:s}){const o=typeof e=="number"?String(e):"",[r,i]=oe.useState(o);oe.useEffect(()=>i(o),[o]);const l=u=>{if(r!==o)if(r.trim()===""&&t&&s.onDelete!==void 0)s.onDelete();else{const p=Number(r);Number.isFinite(p)&&r.trim()!==""&&s.onCommit(p)}u&&s.onDone?.()},d=u=>{const p=r.trim()!==""&&Number.isFinite(Number(r))?Number(r):0;s.onCommit(p+u)};return w.jsxs("div",{className:"stu-stepper",children:[w.jsx("button",{type:"button",className:"stu-step-btn","aria-label":"Decrement",tabIndex:-1,onClick:()=>d(-1),children:"−"}),w.jsx("input",{className:"stu-input stu-input-num",type:"text",inputMode:"decimal",value:r,autoFocus:n,onChange:u=>{i(u.target.value);const p=Number(u.target.value);Number.isFinite(p)&&u.target.value.trim()!==""&&s.onStage?.(p)},onBlur:()=>l(!1),onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),l(!0)),(u.key==="ArrowUp"||u.key==="ArrowDown")&&(u.preventDefault(),d(u.key==="ArrowUp"?1:-1))}}),w.jsx("button",{type:"button",className:"stu-step-btn","aria-label":"Increment",tabIndex:-1,onClick:()=>d(1),children:"+"})]})}function EX({value:e,handlers:t}){const n=e===!0;return w.jsxs("label",{className:"stu-toggle",children:[w.jsx("input",{type:"checkbox",checked:n,onChange:s=>t.onCommit(s.target.checked)}),w.jsx("span",{className:"stu-switch","aria-hidden":"true"}),w.jsx("span",{className:"stu-toggle-label",children:n?"yes":"no"})]})}function MX({value:e,options:t,optional:n,handlers:s}){const o=typeof e=="string"?e:"";return w.jsxs("div",{className:"stu-swatches",role:"radiogroup",children:[t.map(r=>w.jsx("button",{type:"button",role:"radio","aria-checked":o===r,className:`stu-swatch ${o===r?"stu-swatch-active":""}`,style:{background:kX(r)},title:r,tabIndex:-1,onClick:()=>s.onCommit(r)},r)),n&&o!==""&&w.jsx("button",{type:"button",className:"stu-swatch-clear",title:"Unset",tabIndex:-1,onClick:()=>s.onDelete?.(),children:"×"})]})}function AX({value:e,optional:t,handlers:n}){const s=IC(e),[o,r]=oe.useState(s),[i,l]=oe.useState(!1);oe.useEffect(()=>r(s),[s]);const d=(p,h=!1)=>{if(p===s){h&&n.onDone?.();return}if(p===""&&t&&n.onDelete!==void 0)n.onDelete();else if(O0.test(p))n.onCommit(p.toLowerCase());else{l(!0);return}h&&n.onDone?.()},u=s.toLowerCase();return w.jsxs("div",{className:"stu-colorctl",children:[w.jsxs("div",{className:"stu-swatches stu-swatches-wrap",role:"radiogroup",children:[bX.map(p=>w.jsx("button",{type:"button",role:"radio","aria-checked":u===p.hex,className:`stu-swatch stu-swatch-sm ${u===p.hex?"stu-swatch-active":""}`,style:{background:p.hex},title:`${p.name} ${p.hex}`,tabIndex:-1,onClick:()=>n.onCommit(p.hex)},p.hex)),t&&s!==""&&w.jsx("button",{type:"button",className:"stu-swatch-clear",title:"Unset",tabIndex:-1,onClick:()=>n.onDelete?.(),children:"×"})]}),w.jsxs("div",{className:"stu-colorrow",children:[w.jsx("input",{type:"color",className:"stu-colorpick","aria-label":"Pick a color",tabIndex:-1,value:wX(o)??"#0e54a1",onChange:p=>{r(p.target.value),l(!1),n.onStage?.(p.target.value)},onBlur:p=>d(p.target.value)}),w.jsx("input",{className:`stu-input stu-colorhex ${i?"stu-input-invalid":""}`,type:"text",value:o,placeholder:"#0e54a1",spellCheck:!1,onChange:p=>{r(p.target.value),l(!1),O0.test(p.target.value)&&n.onStage?.(p.target.value)},onBlur:()=>d(o),onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),d(o,!0))}})]})]})}function PS({value:e,options:t,optional:n,strict:s,autoFocus:o,handlers:r}){const i=typeof e=="string"?e:"",[l,d]=oe.useState(i),[u,p]=oe.useState(!1),[h,m]=oe.useState(0),[g,v]=oe.useState(!1),y=oe.useRef(null);oe.useEffect(()=>d(i),[i]);const b=rY(t,l,i);oe.useEffect(()=>{const T=y.current?.children[h];T instanceof HTMLElement&&T.scrollIntoView({block:"nearest"})},[h,u]);const E=T=>T===i?!0:T===""?n?((r.onDelete??(()=>r.onCommit("")))(),!0):!1:s&&!t.some(N=>N.value===T)?!1:(r.onCommit(T),!0),$=T=>{d(T),E(T),p(!1),r.onDone?.()},A=()=>{const T=b.findIndex(N=>N.value===i);m(T>=0?T:0),p(!0)};return w.jsxs("div",{className:"stu-combo","data-combo-open":u?"true":void 0,children:[w.jsx("input",{className:`stu-input ${g?"stu-input-invalid":""}`,type:"text",role:"combobox","aria-expanded":u,value:l,autoFocus:o,spellCheck:!1,onFocus:A,onChange:T=>{d(T.target.value),v(!1),m(0),p(!0)},onBlur:()=>{E(l)||d(i),p(!1),v(!1)},onKeyDown:T=>{if(T.key==="ArrowDown"||T.key==="ArrowUp"){if(T.preventDefault(),!u){A();return}m(N=>T.key==="ArrowDown"?Math.min(N+1,b.length-1):Math.max(N-1,0));return}if(T.key==="Enter"){T.preventDefault();const N=u?b[h]:void 0;if(N!==void 0)d(N.value),E(N.value),p(!1);else if(E(l))p(!1);else{v(!0);return}r.onDone?.();return}T.key==="Escape"&&u&&(T.preventDefault(),T.stopPropagation(),d(i),p(!1))}}),w.jsx("span",{className:"stu-combo-caret","aria-hidden":"true",children:"▾"}),u&&b.length>0&&w.jsx("ul",{className:"stu-combo-list",role:"listbox",ref:y,children:b.map((T,N)=>w.jsxs("li",{role:"option","aria-selected":N===h,className:`stu-combo-item ${N===h?"stu-combo-item-active":""}`,onMouseEnter:()=>m(N),onMouseDown:j=>{j.preventDefault(),$(T.value)},children:[w.jsx("span",{className:"stu-combo-value",children:T.value}),T.label!==void 0&&w.jsx("span",{className:"stu-combo-label",children:T.label})]},T.value))})]})}function Ja({resolved:e,node:t,value:n,optional:s,autoFocus:o,handlers:r}){switch(e.kind){case"boolean":return w.jsx(EX,{value:n,handlers:r});case"number":return w.jsx(SX,{value:n,optional:s,autoFocus:o,handlers:r});case"enum":return w.jsx(PS,{value:n,options:e.options.map(i=>({value:i})),optional:s,strict:!0,autoFocus:o,handlers:r});case"accent":return w.jsx(MX,{value:n,options:e.options,optional:s,handlers:r});case"color":return w.jsx(AX,{value:n,optional:s,handlers:r});case"options":return w.jsx(PS,{value:n,options:e.options,optional:s,strict:!1,autoFocus:o,handlers:r});case"text":return w.jsx($X,{node:t,value:n,optional:s,multiline:e.multiline,autoFocus:o,handlers:r});case"opaque":return null}}function Bf(e){return Array.from(e.querySelectorAll("input, textarea, select")).filter(t=>t.tabIndex>=0&&!t.hasAttribute("disabled"))}function zf(e){e.focus(),(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)&&e.select()}const Ep=264;function OS(e){for(let t=e.length-1;t>=0;t--){const n=e[t];if(typeof n=="string")return n}return""}function CX({value:e,onCommit:t}){const n=e===void 0?"":ly(e,{lineWidth:0}).replace(/\n$/,""),[s,o]=oe.useState(n),[r,i]=oe.useState(null),l=()=>{if(s!==n)try{t(ay(s)),i(null)}catch(d){i(d.message.split(`
3251
+ `}let yG=0,wp=null;const ke=vE()((e,t)=>{const n=()=>{wp!==null&&clearTimeout(wp),wp=setTimeout(()=>{wp=null;const r=t();r.autosave&&r.dirty&&r.conflict===null&&!r.saving&&r.save()},gG)},s=(r,i)=>{const l=t();e({undoStack:[...l.undoStack.slice(-99),l.source],redoStack:[],source:r,dirty:!0,...i!==void 0?{selection:i}:{}}),n()},o=async(r=!1)=>{const i=t();if(i.currentSlug===null||i.saving)return;const l=i.currentSlug,d=i.source;e({saving:!0});try{const u=await yw(l,d,i.baseHash??void 0,r);if(t().currentSlug!==l)return;u.ok?(e({baseHash:u.hash,savedSource:d,savedAt:Date.now(),dirty:t().source!==d,conflict:null}),t().refreshDocs()):e({conflict:u.conflict})}catch(u){t().toast(`Save failed: ${u.message}`,"error")}finally{e({saving:!1})}};return{meta:null,docs:[],currentSlug:null,source:"",savedSource:"",baseHash:null,dirty:!1,saving:!1,savedAt:null,autosave:!0,review:null,pendingDelete:null,pendingImport:null,mode:"home",selection:null,partSel:null,penMode:null,conflict:null,undoStack:[],redoStack:[],toasts:[],sheet:null,sheetDirty:!1,sheetFresh:!1,sheetReveal:null,slashHintAt:null,picker:null,dragging:null,loaded:!1,initialVersion:null,updateAvailable:!1,init:async()=>{try{let r=null,i=null;try{const h=await bB(window.location.href);h!==null&&(r=await xw(h.source,h.title??"shared"),window.history.replaceState(null,"",window.location.pathname),i=h.present?"present":"edit");const m=r===null?new URLSearchParams(window.location.search).get("template"):null;if(m!==null&&m!==""){const g=Ny[m];g===void 0?t().toast(`There is no “${m}” template.`,"error"):(r=await xw(g,m),window.history.replaceState(null,"",window.location.pathname),i="edit")}}catch(h){t().toast(`That link could not be opened: ${h.message}`,"error")}const[l,d]=await Promise.all([Pg(),vw()]);e({meta:l,docs:d,loaded:!0,initialVersion:l.version});const u=d[0],p=r??(t().currentSlug===null?u?.slug:void 0);p!==void 0&&await t().openDoc(p),i!==null&&e({mode:i})}catch(r){e({loaded:!0}),t().toast(`Could not reach the studio server: ${r.message}`,"error")}},refreshDocs:async()=>{try{e({docs:await vw()})}catch{}},openDoc:async r=>{try{const i=await Bp(r);e({currentSlug:r,source:i.source,savedSource:i.source,baseHash:i.hash,dirty:!1,selection:null,partSel:null,sheet:null,sheetDirty:!1,conflict:null,review:null,pendingDelete:null,pendingImport:null,undoStack:[],redoStack:[]})}catch(i){t().toast(`Could not open ${r}: ${i.message}`,"error")}},newDoc:async(r,i)=>{try{const l=i??vG(r),d=await yw(r,l);if(!d.ok){t().toast(`A doc named "${r}" already exists.`,"error");return}await t().refreshDocs(),e({currentSlug:r,source:l,savedSource:l,baseHash:d.hash,dirty:!1,selection:null,partSel:null,sheet:null,sheetDirty:!1,conflict:null,review:null,pendingDelete:null,pendingImport:null,undoStack:[],redoStack:[],savedAt:Date.now()}),t().openSheet($B(l,r),!0)}catch(l){t().toast(`Could not create ${r}: ${l.message}`,"error")}},applyOp:(r,i)=>{const l=t();if(l.currentSlug===null)return!1;try{const{doc:d}=id(l.source,l.currentSlug),u=r(l.source,d);return s(u,i),!0}catch(d){return t().toast(`Edit failed: ${d.message}`,"error"),!1}},moveBlock:(r,i)=>{const l=t();if(l.currentSlug===null)return!1;const{doc:d}=id(l.source,l.currentSlug);return mG(d.segments.map(u=>u.kind),r,i)?l.applyOp((u,p)=>tD(u,p,r,i),i<=r?i:i-1):!1},checkVersion:async()=>{const r=t().initialVersion;if(!(r===null||t().updateAvailable))try{const i=await Pg();sS(r,i.version)&&e({updateAvailable:!0})}catch{}},setMode:r=>{const i=t();r!==i.mode&&e({mode:r,...i.sheet!==null?{sheet:null,sheetDirty:!1,sheetFresh:!1}:{},...i.review!==null?{review:null}:{},...i.pendingDelete!==null?{pendingDelete:null}:{},...i.pendingImport!==null?{pendingImport:null}:{},...r!=="edit"?{partSel:null}:{}})},select:r=>e({selection:r,...r!==t().selection?{partSel:null}:{},...r!==t().slashHintAt?{slashHintAt:null}:{}}),setPartSel:r=>e({partSel:r}),setPenMode:r=>e({penMode:r}),save:async(r=!1)=>{const i=t();if(!(i.currentSlug===null||i.saving)){if(!r&&!i.autosave&&i.dirty){e({review:"save"});return}await o(r)}},applyReview:async()=>{const r=t().review;r!==null&&(e({review:null}),await o(),r==="enable-autosave"&&e({autosave:!0}))},cancelReview:()=>e({review:null}),requestDelete:r=>e({pendingDelete:r}),confirmDelete:()=>{const r=t().pendingDelete;r!==null&&(e({pendingDelete:null}),r.run())},cancelDelete:()=>e({pendingDelete:null}),requestImport:r=>e({pendingImport:r}),confirmImport:r=>{const i=t().pendingImport;i!==null&&(e({pendingImport:null}),i.create(r))},cancelImport:()=>e({pendingImport:null}),undo:()=>{const r=t(),i=r.undoStack[r.undoStack.length-1];i!==void 0&&(e({undoStack:r.undoStack.slice(0,-1),redoStack:[...r.redoStack,r.source],source:i,dirty:!0,selection:null,partSel:null}),n())},redo:()=>{const r=t(),i=r.redoStack[r.redoStack.length-1];i!==void 0&&(e({redoStack:r.redoStack.slice(0,-1),undoStack:[...r.undoStack.slice(-99),r.source],source:i,dirty:!0,selection:null,partSel:null}),n())},resolveConflict:r=>{const i=t();i.conflict!==null&&(r==="theirs"?e({undoStack:[...i.undoStack.slice(-99),i.source],redoStack:[],source:i.conflict.currentSource,savedSource:i.conflict.currentSource,baseHash:i.conflict.currentHash,dirty:!1,conflict:null,selection:null,partSel:null}):(e({conflict:null}),t().save(!0)))},setAutosave:r=>{if(r&&t().dirty&&t().conflict===null){e({review:"enable-autosave"});return}e({autosave:r}),r&&n()},setDragging:r=>e({dragging:r}),openSheet:(r,i=!1,l)=>e({sheet:r,sheetDirty:!1,sheetFresh:i,sheetReveal:l??null,selection:r,partSel:null,slashHintAt:null}),closeSheet:(r=!1)=>{const i=t().sheet;e({sheet:null,sheetDirty:!1,sheetFresh:!1,sheetReveal:null,slashHintAt:r&&i!==null?i:null})},setSheetDirty:r=>e({sheetDirty:r}),dismissSlashHint:()=>e({slashHintAt:null}),openPicker:(r={})=>{const i=t();e({picker:{view:r.view??"compact",index:r.index??null,anchor:r.anchor??null},...i.sheet!==null?{sheet:null,sheetDirty:!1,sheetFresh:!1}:{},...i.review!==null?{review:null}:{},...i.pendingDelete!==null?{pendingDelete:null}:{},...i.pendingImport!==null?{pendingImport:null}:{}})},closePicker:()=>e({picker:null}),expandPicker:()=>{const r=t().picker;r!==null&&r.view==="compact"&&e({picker:{...r,view:"browse",anchor:null}})},openLibrary:()=>t().openPicker({view:"browse"}),commitSheet:r=>{const i=t(),l=i.sheet;if(l===null)return!1;const d=i.applyOp((u,p)=>{const h=p.segments[l];if(h===void 0||h.kind==="markdown")throw new TypeError("the sheet block is gone — the doc changed under it");return h.raw===r?u:lh(u,p,l,r)},l);return d&&e({sheet:null,sheetDirty:!1,sheetFresh:!1,slashHintAt:l}),d},handleServerEvent:r=>{if(r.type==="meta"){Pg().then(u=>{const p=t();e({meta:u,...sS(p.initialVersion,u.version)?{updateAvailable:!0}:{}})});return}const i=t(),l=hG(r,{currentSlug:i.currentSlug,baseHash:i.baseHash,dirty:i.dirty});if(i.refreshDocs(),l==="ignore-echo"||l==="refresh-list")return;const d=i.currentSlug;if(d!==null){if(l==="silent-refetch"||l==="refetch-all"){if(i.sheet!==null&&i.sheetDirty)return;Bp(d).then(u=>{const p=t();if(p.currentSlug!==d||p.dirty||u.hash===p.baseHash)return;const h=p.selection,m=ys(u.source,d).segments.length;e({source:u.source,savedSource:u.source,baseHash:u.hash,dirty:!1,selection:h!==null&&h<m?h:null})});return}Bp(d).then(u=>{const p=t();p.currentSlug===d&&u.hash!==p.baseHash&&e({conflict:{currentHash:u.hash,currentSource:u.source}})})}},toast:(r,i="info")=>{const l=++yG;e({toasts:[...t().toasts,{id:l,message:r,tone:i}]}),setTimeout(()=>t().dismissToast(l),5e3)},dismissToast:r=>e({toasts:t().toasts.filter(i=>i.id!==r)})}});function Co(){const e=ke(n=>n.source),t=ke(n=>n.currentSlug)??"untitled";return id(e,t)}const VA="(prefers-color-scheme: dark)";function xG(){return typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia(VA).matches:!1}function Ah(){const[e,t]=oe.useState(xG);return oe.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const n=window.matchMedia(VA),s=o=>t(o.matches);return n.addEventListener("change",s),()=>n.removeEventListener("change",s)},[]),e}function GA(){const e=ke(n=>n.meta?.colorScheme??"dark"),t=Ah();return e==="system"?t?"dark":"light":e}function kG(){const e=GA();return oe.useEffect(()=>{typeof document>"u"||(document.documentElement.dataset.theme=e)},[e]),e}function bG(e){try{const t=JSON.parse(e);return t.type==="meta"?{type:"meta"}:t.type==="fs"?{type:"fs",...typeof t.slug=="string"?{slug:t.slug}:{},...typeof t.hash=="string"?{hash:t.hash}:{}}:null}catch{return null}}function wG(e,t,n=!0){const s=oe.useRef(e);s.current=e;const o=oe.useRef(t);o.current=t,oe.useEffect(()=>{if(!n)return;const r=new EventSource("/__events");return r.onopen=()=>o.current?.(),r.onmessage=i=>{const l=bG(i.data);l!==null&&s.current(l)},()=>r.close()},[n])}const qo=(e,t)=>({from:e,to:t});function ix(e){return{col:e.col,row:e.row}}const $G={flow:{nodesField:"nodes",idField:"id",labelField:"label",edgesField:"edges",edgeTextField:"label",edgeKinds:["error","dashed"],nodeKinds:[{kind:"process",label:"Process"},{kind:"decision",label:"Decision"},{kind:"start",label:"Start"},{kind:"end",label:"End"}],allowSelfLoop:!1,gridNodes:!0,groups:!0,newEdge:qo,newNode:({id:e,kind:t,label:n,cell:s})=>({id:e,label:n,kind:t,col:s.col,row:s.row})},dfd:{nodesField:"nodes",idField:"id",labelField:"name",edgesField:"edges",edgeTextField:"label",nodeKinds:[{kind:"process",label:"Process"},{kind:"external",label:"External"},{kind:"store",label:"Store"}],allowSelfLoop:!1,gridNodes:!0,groups:!0,newEdge:qo,newNode:({id:e,kind:t,label:n,cell:s})=>({id:e,name:n,kind:t,col:s.col,row:s.row})},state:{nodesField:"states",idField:"id",labelField:"name",edgesField:"transitions",edgeTextField:"event",nodeKinds:[{kind:"active",label:"Active"},{kind:"wait",label:"Wait"},{kind:"terminal",label:"Terminal"}],allowSelfLoop:!0,gridNodes:!0,groups:!0,newEdge:(e,t)=>({from:e,to:t,event:""}),newNode:({id:e,kind:t,label:n,cell:s})=>({id:e,name:n,kind:t,col:s.col,row:s.row})},c4:{nodesField:"nodes",idField:"id",labelField:"name",edgesField:"edges",edgeTextField:"label",edgeKinds:["solid","dashed","forbidden","error"],nodeKinds:[{kind:"person",label:"Person"},{kind:"system",label:"System"},{kind:"external",label:"External"},{kind:"store",label:"Store"},{kind:"container",label:"Container"},{kind:"component",label:"Component"}],allowSelfLoop:!1,gridNodes:!0,groups:!0,newEdge:qo,newNode:({id:e,kind:t,label:n,cell:s})=>({id:e,kind:t,name:n,col:s.col,row:s.row})},block:{nodesField:"nodes",idField:"id",labelField:"name",edgesField:"edges",edgeTextField:"label",edgeKinds:["solid","dashed","forbidden","error"],nodeKinds:[{kind:"service",label:"Service"},{kind:"client",label:"Client"},{kind:"db",label:"Database"},{kind:"queue",label:"Queue"},{kind:"cache",label:"Cache"},{kind:"gateway",label:"Gateway"},{kind:"external",label:"External"}],allowSelfLoop:!1,gridNodes:!0,groups:!0,newEdge:qo,newNode:({id:e,kind:t,label:n,cell:s})=>({id:e,name:n,kind:t,col:s.col,row:s.row})},graph:{nodesField:"nodes",idField:"id",labelField:"label",edgesField:"edges",edgeTextField:"label",nodeKinds:[{kind:"node",label:"Node"}],allowSelfLoop:!1,gridNodes:!0,groups:!1,newEdge:qo,newNode:({id:e,label:t,cell:n})=>({id:e,label:t,col:n.col,row:n.row})},swimlane:{nodesField:"steps",idField:"id",labelField:"label",edgesField:"links",edgeTextField:"label",nodeKinds:[{kind:"action",label:"Action"},{kind:"decision",label:"Decision"},{kind:"start",label:"Start"},{kind:"end",label:"End"},{kind:"wait",label:"Wait"}],allowSelfLoop:!1,gridNodes:!0,groups:!1,growRows:!1,placeFields:["col","lane"],writeCell:e=>({col:e.col,lane:e.row-1}),newEdge:qo,newNode:({id:e,kind:t,label:n,cell:s})=>({id:e,kind:t,label:n,col:s.col,lane:s.row-1})},sequence:{nodesField:"actors",idField:"id",labelField:"name",edgesField:"messages",edgeTextField:"label",edgeKinds:["sync","response","async","error","note"],nodeKinds:[],allowSelfLoop:!0,gridNodes:!1,groups:!1,allowDuplicateEdges:!0,columnTargets:!0,editEdgeOnConnect:!0,newEdge:(e,t)=>e===t?{from:e,to:t,kind:"note",label:"note"}:{from:e,to:t,label:"message"}},felogic:{nodesField:"nodes",idField:"id",labelField:"name",edgesField:"edges",edgeTextField:"label",edgeKinds:["uses","implements","reads","egress","https","api","dashed","async"],nodeKinds:[{kind:"component",label:"Component"},{kind:"service",label:"Service"},{kind:"controller",label:"Controller"},{kind:"repository",label:"Repository"},{kind:"adapter",label:"Adapter"},{kind:"model",label:"Model"},{kind:"db",label:"Database"},{kind:"queue",label:"Queue"},{kind:"external",label:"External"}],allowSelfLoop:!1,gridNodes:!0,groups:!0,newEdge:qo,newNode:({id:e,kind:t,label:n,cell:s})=>({id:e,name:n,kind:t,col:s.col,row:s.row})},cluster:{nodesField:"services",idField:"id",labelField:"label",edgesField:"edges",edgeTextField:"label",edgeKinds:["solid","dashed","forbidden","error"],memberField:"cluster",nodeKinds:[{kind:"service",label:"Service"},{kind:"db",label:"Database"},{kind:"queue",label:"Queue"},{kind:"cache",label:"Cache"},{kind:"gateway",label:"Gateway"},{kind:"external",label:"External"}],allowSelfLoop:!1,gridNodes:!1,groups:!1,newEdge:qo,newNode:({id:e,kind:t,label:n})=>({id:e,label:n,kind:t})},erd:{nodesField:"entities",idField:"name",labelField:"name",edgesField:"relations",edgeTextField:"label",nodeKinds:[],allowSelfLoop:!1,gridNodes:!1,groups:!1,edgeChoices:[{value:"1:1",label:"1:1 · one-to-one"},{value:"1:N",label:"1:N · one-to-many"},{value:"N:1",label:"N:1 · many-to-one"},{value:"N:M",label:"N:M · many-to-many"}],edgeChoiceField:"card",newEdge:qo}};function $n(e){return $G[e]??null}function Af(e,t){const n=new RegExp(`^${e.nodesField}\\.(\\d+)$`).exec(t);return n!==null?Number(n[1]):null}function Cf(e,t){const n=new RegExp(`^${e.edgesField}\\.(\\d+)$`).exec(t);return n!==null?Number(n[1]):null}function ax(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function lx(e,t){const n=ax(e)?.[t];return Array.isArray(n)?n:[]}function ad(e,t){return lx(t,e.nodesField).map(ax).filter(n=>n!==null)}function cx(e,t){const n=t[e.idField];return typeof n=="string"?n:null}function no(e,t,n){const o=ad(e,t).find(r=>cx(e,r)===n)?.[e.labelField];return typeof o=="string"&&o!==""?o:n}function Gp(e,t,n,s,o){if(n===s&&!e.allowSelfLoop)return null;const r=lx(t,e.edgesField);if(e.allowDuplicateEdges!==!0&&r.some(d=>{const u=ax(d);return u!==null&&u.from===n&&u.to===s}))return null;const i=o===void 0?e.newEdge(n,s):{...e.newEdge(n,s),...o};return[{path:[e.edgesField,r.length],value:i}]}function SG(e,t){const n=new Set(ad(e,t).map(r=>cx(e,r)).filter(r=>r!==null));let s=ad(e,t).length+1,o=`n${s}`;for(;n.has(o);)s+=1,o=`n${s}`;return o}function dx(e,t,n,s,o,r){const i=e.newNode;if(i===void 0)return null;const l=e.nodeKinds.find(b=>b.kind===s);if(l===void 0)return null;const d=ad(e,t),u=[],p=e.placeFields??["col","row"],h=e.writeCell??ix,g=!(d.length>0&&d.every(b=>p.every(E=>b[E]!==void 0)))&&o!==void 0&&o.length===d.length;g&&o.forEach((b,E)=>{for(const[$,A]of Object.entries(h(b)))u.push({path:[e.nodesField,E,$],value:A})});const v=SG(e,t),y=`New ${l.label.toLowerCase()}`;return u.push({path:[e.nodesField,d.length],value:{...i({id:v,kind:s,label:y,cell:n}),...r??{}}}),{sets:u,nodePath:`${e.nodesField}.${d.length}`,id:v,materialized:g}}function Nf(e,t,n,s,o,r){const l=ad(e,t).find(h=>cx(e,h)===n);if(l===void 0)return null;const d=e.memberField!==void 0&&l[e.memberField]!==void 0?{[e.memberField]:l[e.memberField]}:void 0,u=dx(e,t,s,o,r,d);if(u===null)return null;const p=lx(t,e.edgesField);return u.sets.push({path:[e.edgesField,p.length],value:e.newEdge(n,u.id)}),u}const EG=6;function Ch(e,t,n=EG){return Math.hypot(e,t)>n}const Nh={glossary:"terms",faq:"items",steps:"items",list:"items",takeaways:"items",agenda:"items",team:"members",stats:"stats",saga:"steps"};function Tf(e,t){let n;if(e==="sequence")return n=/^actors\.(\d+)$/.exec(t),n!==null?{mode:"reorder",listPath:"actors",index:Number(n[1])}:null;if(e==="table")return n=/^columns\.(\d+)$/.exec(t),n!==null?{mode:"table-cols",index:Number(n[1])}:(n=/^rows\.(\d+)(?:\.\d+)?$/.exec(t),n!==null?{mode:"reorder",listPath:"rows",index:Number(n[1])}:null);if(e==="kanban")return n=/^columns\.(\d+)\.cards\.(\d+)$/.exec(t),n!==null?{mode:"kanban-card",col:Number(n[1]),index:Number(n[2])}:(n=/^columns\.(\d+)(?:\.label)?$/.exec(t),n!==null?{mode:"reorder",listPath:"columns",index:Number(n[1])}:null);if(e==="timeline")return n=/^items\.(\d+)(?:\.\w+)?$/.exec(t),n!==null?{mode:"reorder",listPath:"items",index:Number(n[1])}:null;const s=Nh[e];if(s!==void 0)return n=new RegExp(`^${s}\\.(\\d+)(?:\\..+)?$`).exec(t),n!==null?{mode:"reorder",listPath:s,index:Number(n[1])}:null;if(e==="cycle")return n=/^steps\.(\d+)(?:\.label)?$/.exec(t),n!==null?{mode:"ring",listPath:"steps",index:Number(n[1])}:null;const o=$n(e);if(o!==null){if(o.gridNodes&&(n=new RegExp(`^${o.nodesField}\\.(\\d+)$`).exec(t),n!==null))return{mode:"grid-node",listPath:o.nodesField,index:Number(n[1])};if(o.groups&&(n=/^groups\.(\d+)$/.exec(t),n!==null))return{mode:"grid-group",index:Number(n[1])}}return null}function Th(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function MG(e,t){if(e==="sequence"||e==="table"||e==="kanban"||e==="timeline"||e==="cycle"||e in Nh)return!0;if($n(e)?.gridNodes!==!0)return!1;const n=Th(t)?.layers;return!(Array.isArray(n)&&n.length>0)}function ux(e){if(e.length===0)return"y";const t=e.map(r=>r.left+r.width/2),n=e.map(r=>r.top+r.height/2),s=Math.max(...t)-Math.min(...t),o=Math.max(...n)-Math.min(...n);return s>=o?"x":"y"}function oS(e,t){return e.map(n=>t==="x"?n.left+n.width/2:n.top+n.height/2)}function rS(e,t){let n=0;for(const s of e)t>s&&(n+=1);return n}function Vr(e,t,n){if(!Number.isInteger(t)||t<0||t>=e.length||!Number.isInteger(n)||n<0||n>e.length||n===t||n===t+1)return null;const s=e.slice(),[o]=s.splice(t,1);return s.splice(n>t?n-1:n,0,o),s}function iS(e,t,n){if(e.length===0)return 0;const s=l=>t==="x"?l.left:l.top,o=l=>t==="x"?l.left+l.width:l.top+l.height,r=e[0],i=e[e.length-1];return n<=0?s(r)-3:n>=e.length?o(i)+3:(o(e[n-1])+s(e[n]))/2}function AG(e,t,n){return Vr(Array.from({length:e},(s,o)=>o),t,n)}function YA(e,t,n){const s=Th(e),o=s!==null&&Array.isArray(s.columns)?s.columns:null;if(o===null)return null;const r=AG(o.length,t,n);if(r===null)return null;const i=[{path:["columns"],value:r.map(d=>o[d])}];return(s!==null&&Array.isArray(s.rows)?s.rows:[]).forEach((d,u)=>{if(!Array.isArray(d))return;const p=d.slice();for(;p.length<o.length;)p.push("");i.push({path:["rows",u],value:[...r.map(h=>p[h]),...p.slice(o.length)]})}),i}function aS(e){const t=Th(e);if(t===null)return null;const n=t.cards;return n===void 0?[]:Array.isArray(n)?n:null}function _0(e,t,n,s,o){const r=Th(e),i=r!==null&&Array.isArray(r.columns)?r.columns:null;if(i===null)return null;const l=aS(i[t]),d=aS(i[s]);if(l===null||d===null)return null;if(t===s){const h=Vr(l,n,o);return h===null?null:[{path:["columns",t,"cards"],value:h}]}const u=l[n];if(u===void 0)return null;const p=Math.max(0,Math.min(o,d.length));return[{path:["columns",t,"cards"],value:l.filter((h,m)=>m!==n)},p===d.length?{path:["columns",s,"cards",p],value:u}:{path:["columns",s,"cards"],value:[...d.slice(0,p),u,...d.slice(p)]}]}function lS(e,t,n){return Math.min(n,Math.max(t,Math.round(e)))}function wo(e,t,n){const s=t/e.scale,o=n/e.scale;return{col:lS((s-e.padX-e.cellW/2)/(e.cellW+e.gapX)+1,1,e.cols+1),row:lS((o-e.padTop-e.cellH/2)/(e.cellH+e.gapY)+1,1,e.rows+1)}}function _f(e,t,n,s=1){return{left:(e.padX+(t-1)*(e.cellW+e.gapX))*e.scale,top:(e.padTop+(n-1)*(e.cellH+e.gapY))*e.scale,width:(s*e.cellW+(s-1)*e.gapX)*e.scale,height:e.cellH*e.scale}}function XA(e){const{placements:t,index:n,target:s,quick:o}=e,r=e.field??"nodes",i=e.writeCell??(m=>({col:m.col,row:m.row})),l=t[n];if(l===void 0||l.col===s.col&&l.row===s.row)return null;const d=t.findIndex((m,g)=>g!==n&&m.col===s.col&&m.row===s.row),u=m=>m===n?s:m===d?l:t[m],p=[],h=m=>{for(const[g,v]of Object.entries(i(u(m))))p.push({path:[r,m,g],value:v})};return o?t.forEach((m,g)=>h(g)):(h(n),d>=0&&h(d)),{sets:p,swapped:d>=0?d:null,materialized:o}}const px="Auto-layout pinned — nodes now keep their positions";function QA(e){const t=Math.max(1,e.length);return{x:e.reduce((n,s)=>n+s.x,0)/t,y:e.reduce((n,s)=>n+s.y,0)/t}}function CG(e,t,n){const s=e.length;if(s<2)return null;const o=QA(e),r=e[0],i=Math.atan2(r.y-o.y,r.x-o.x),l=2*Math.PI/s,u=((Math.atan2(n-o.y,t-o.x)-i)%(2*Math.PI)+2*Math.PI)%(2*Math.PI);return Math.max(1,Math.min(s,Math.ceil(u/l)))}function NG(e,t){const n=Math.max(1,e.length),s=QA(e),o=e[0],r=Math.atan2(o.y-s.y,o.x-s.x),i=e.reduce((d,u)=>d+Math.hypot(u.x-s.x,u.y-s.y),0)/n,l=r+(t-.5)*(2*Math.PI/n);return{x:s.x+i*Math.cos(l),y:s.y+i*Math.sin(l)}}const TG=new Set(["string","number","boolean","enum"]);function _G(e){return e.arms.filter(t=>TG.has(t.kind))}function L0(e){const t=e.arms.filter(n=>n.kind==="object");return t.length===1?t[0]??null:null}function ZA(e){return e.arms.filter(t=>t.kind==="object")}function _h(e,t){const n=ZA(e),s=n[0]??null;if(n.length<=1||!fx(t))return s;const o=Object.keys(t);return n.find(i=>{const l=i.fields.filter(d=>!d.node.optional).map(d=>d.name);return l.length>0&&l.every(d=>o.includes(d))})??s}function Hv(e,t){return e.arms.some(n=>n.kind===t)}const LG=["v","value","text","label","name","title"];function JA(e){for(const n of LG)if(e.fields.some(s=>s.name===n))return n;return e.fields.find(n=>!n.node.optional&&(n.node.kind==="string"||n.node.kind==="union"))?.name??e.fields[0]?.name??"value"}function fx(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Lf(e,t){return fx(e)?e:{[JA(t)]:e??""}}function Lh(e,t){if(fx(e)){const n=e[JA(t)];return n??""}return e??""}function IG(e){const t=_G(e);if(t.length===0)return{kind:"opaque"};const n=new Set(t.map(s=>s.kind));if(n.size===1&&n.has("number"))return{kind:"number"};if(n.size===1&&n.has("boolean"))return{kind:"boolean"};if(n.size===1&&n.has("enum")){const s=[];for(const o of t)if(o.kind==="enum")for(const r of o.options)s.includes(r)||s.push(r);return{kind:"enum",options:s}}return{kind:"text",multiline:!1}}function jG(e,t){if(Hv(t,"number")&&e.trim()!==""){const n=Number(e);if(Number.isFinite(n))return{ok:!0,value:n}}if(Hv(t,"boolean")&&(e==="true"||e==="false"))return{ok:!0,value:e==="true"};if(Hv(t,"string"))return{ok:!0,value:e};for(const n of t.arms)if(n.kind==="enum"&&n.options.includes(e))return{ok:!0,value:e};return{ok:!1}}function ld(e){switch(e.kind){case"string":return"";case"number":return Math.max(0,e.min??0);case"boolean":return!1;case"enum":return e.options[0]??"";case"array":return Array.from({length:e.min??0},()=>ld(e.element));case"object":return eC(e);case"union":{const t=e.arms[0];return t!==void 0?ld(t):""}case"opaque":return null}}function eC(e){const t={};for(const n of e.fields)n.node.optional||(t[n.name]=ld(n.node));if(Object.keys(t).length===0){const n=e.fields.find(s=>s.node.kind==="string"||s.node.kind==="number"||s.node.kind==="enum");n!==void 0&&(t[n.name]=ld(n.node))}return t}function Dn(e){return e===""?[]:e.split(".").map(t=>/^\d+$/.test(t)?Number(t):t)}function If(e){return e.join(".")}function tC(e){return typeof e[e.length-1]=="number"}function as(e){return/(series|species)$/i.test(e)?e:/ies$/.test(e)?e.replace(/ies$/,"y"):/(ses|xes|zes|ches|shes)$/.test(e)?e.replace(/es$/,""):/s$/.test(e)&&!/ss$/.test(e)?e.replace(/s$/,""):e}function $o(e){const t=e.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").toLowerCase().trim();return t===""?e:t.charAt(0).toUpperCase()+t.slice(1)}function hx(e,t){let n=e;for(const s of t){if(n.kind==="array"&&typeof s=="number"){n=n.element;continue}if(n.kind==="object"&&typeof s=="string"){const o=n.fields.find(r=>r.name===s);if(o===void 0)return null;n=o.node;continue}if(n.kind==="union"&&typeof s=="string"){let o;for(const r of n.arms)if(r.kind==="object"&&(o=r.fields.find(i=>i.name===s),o!==void 0))break;if(o===void 0)return null;n=o.node;continue}return null}return n}function is(e,t){let n=e;for(const s of t){if(n===null||typeof n!="object")return;n=n[s]}return n}function Pr(e){const t=[];for(let n=0;n<e.length;n++){const s=e[n];if(typeof s=="string"){const o=e[n+1];typeof o=="number"?(t.push(`${$o(as(s))} ${o+1}`),n+=1):t.push($o(s))}else t.push(`Item ${s+1}`)}return t.join(" · ")}const PG=new Set(["label","title","name","text","summary","term","question"]);function Qa(e,t,n){const o=(e.kind==="union"?_h(e,t[t.length-1]):null)??e;if(o.kind==="array"){const d=t[t.length-1];return Array.isArray(d)&&d.length>0?d.map(()=>""):[""]}if(o.kind!=="object")return o.kind==="string"?`New ${n}`:ld(o);const r=eC(o),i=t[t.length-1],l=i!==null&&typeof i=="object"&&!Array.isArray(i)?i:null;for(const d of Object.keys(r))d==="id"?r[d]=OG(n,t):PG.has(d)?r[d]=`New ${n}`:l!==null&&l[d]!==void 0&&typeof l[d]!="object"?r[d]=l[d]:r[d]===null&&(r[d]="");return r}function OG(e,t){const n=new Set(t.map(r=>r!==null&&typeof r=="object"?String(r.id??""):""));let s=t.length+1,o=`${e}${s}`;for(;n.has(o);)s+=1,o=`${e}${s}`;return o}function nC(e,t,n){if(n!==null&&n.kind==="union")return jG(e,n);const s=n?.kind;if(s==="number"){const o=Number(e);return Number.isFinite(o)&&e.trim()!==""?{ok:!0,value:o}:{ok:!1}}if(s==="boolean")return e==="true"?{ok:!0,value:!0}:e==="false"?{ok:!0,value:!1}:{ok:!1};if(typeof t=="number"){const o=Number(e);return Number.isFinite(o)&&e.trim()!==""?{ok:!0,value:o}:{ok:!0,value:e}}return typeof t=="boolean"?e==="true"?{ok:!0,value:!0}:e==="false"?{ok:!0,value:!1}:{ok:!0,value:e}:{ok:!0,value:e}}function jf(e,t){if(e==="table"){const u=/^rows\.(\d+)\.(\d+)$/.exec(t);if(u!==null)return{kind:"table-cell",row:Number(u[1]),col:Number(u[2])}}const n=Tf(e,t);if(n!==null)return n.mode==="grid-node"?{kind:"grid",listPath:n.listPath,index:n.index}:n.mode==="grid-group"?{kind:"grid-group",index:n.index}:n.mode==="table-cols"?{kind:"table-col",index:n.index}:n.mode==="kanban-card"?{kind:"kanban-card",col:n.col,index:n.index}:{kind:"item",listPath:n.listPath,index:n.index};const s=Dn(t);let o=-1;for(let u=s.length-1;u>=0;u--)if(typeof s[u]=="number"){o=u;break}if(o<0)return{kind:"inert"};const r=If(s.slice(0,o)),i=s[o],l=Tf(e,`${r}.${i}`);if(l!==null&&l.mode==="grid-node")return{kind:"grid",listPath:l.listPath,index:i};const d=o<s.length-1?`.${If(s.slice(o+1))}`:"";return{kind:"item",listPath:r,index:i,...d!==""?{suffix:d}:{}}}function cS(e,t){const n=jf(e,t);switch(n.kind){case"item":return`${n.listPath}.${n.index}`;case"kanban-card":return`columns.${n.col}.cards.${n.index}`;case"grid":return`${n.listPath}.${n.index}`;case"grid-group":return`groups.${n.index}`;case"table-col":return`columns.${n.index}`;default:return null}}function RG(e){return e.kind!=="inert"}function sC(e){return e==="ArrowLeft"||e==="ArrowRight"}function oC(e){return e==="ArrowLeft"||e==="ArrowUp"?-1:1}function DG(e){if(e.axis==="x"!==sC(e.key))return null;const t=oC(e.key),n=e.index+t;return n<0||n>=e.length?null:{gap:t<0?e.index-1:e.index+2,newIndex:n}}function BG(e){const t=oC(e.key);if(sC(e.key)){const o=e.col+t;return o<0||o>=e.colsInRow(e.row)?null:{row:e.row,col:o}}const n=e.row+t;if(n<0||n>=e.rowCount)return null;const s=e.colsInRow(n);return s<=0?null:{row:n,col:Math.min(e.col,s-1)}}function rC(e,t){return t===e||t===e+1?e:t>e?t-1:t}function Wv(e,t,n){return`${e}.${rC(t,n)}`}function zG(e){if(e.fromCol===e.toCol)return`columns.${e.fromCol}.cards.${rC(e.fromIdx,e.gap)}`;const t=Math.max(0,Math.min(e.gap,e.targetLen));return`columns.${e.toCol}.cards.${t}`}function FG(e){return e.sheetOpen?"sheet":e.partSelected?"part":e.blockSelected?"block":"canvas"}let Yp=null;function qG(e){return Yp=e,()=>{Yp===e&&(Yp=null)}}function Ni(e){Yp?.(e)}function iC(e,t,n,s={}){const o=ke.getState(),r=n??ih(t);o.applyOp((l,d)=>Sy(l,d,e,t,r),e)&&(s.openSheet!==!1&&o.openSheet(e,!0),Ni("insert"))}function aC(e){ke.getState().applyOp((n,s)=>{const o=s.segments[e];if(o===void 0)throw new RangeError(`no segment ${e}`);return o.kind==="markdown"?eD(n,s,e+1,o.text):Sy(n,s,e+1,o.kind,o.raw)},e+1)}function lC(e){ke.getState().moveBlock(e,e-1)}function cC(e){ke.getState().moveBlock(e,e+2)}function dS(e){ke.getState().applyOp((t,n)=>Ey(t,n,e),null)}const HG=new Set(["text","desc","description","content","body","summary","lede"]),uS=["navy","blue","teal","green","amber","purple","red","gray"],WG=/^(color|fill|stroke|accent)$/i,UG=/^#[0-9a-f]{3,8}$/i,KG=new Set(["block","cluster"]),VG=new Set(["felogic"]),GG={from:"other-arrays",to:"other-arrays",source:"other-arrays",target:"other-arrays",parent:"own-array",cluster:["clusters"],status:{arrays:["statuses"],idField:"label"}};function Ih(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function pS(e){return e.length>=uS.length&&uS.every(t=>e.includes(t))}function YG(e){for(let t=e.length-1;t>=1;t--)if(typeof e[t]=="number"&&typeof e[t-1]=="string")return e[t-1];return null}function XG(e,t){const n=[];for(const s of e){if(typeof s=="string"){s!==""&&n.push({value:s});continue}const o=Ih(s);if(o===null)return[];if(t!==void 0){const l=o[t];typeof l=="string"&&l!==""&&n.push({value:l});continue}const r=typeof o.id=="string"&&o.id!==""?o.id:typeof o.name=="string"&&o.name!==""&&o.id===void 0?o.name:null;if(r===null)continue;const i=[o.name,o.label,o.title].find(l=>typeof l=="string"&&l!==""&&l!==r);n.push(i!==void 0?{value:r,label:i}:{value:r})}return n}function QG(e,t,n){const s=GG[e];if(s===void 0)return null;const o=Ih(t);if(o===null)return null;const r=YG(n);let i,l;s==="other-arrays"?i=Object.keys(o).filter(p=>p!==r):s==="own-array"?i=r!==null?[r]:[]:"arrays"in s?(i=s.arrays,l=s.idField):i=s;const d=new Set,u=[];for(const p of i){const h=o[p];if(Array.isArray(h))for(const m of XG(h,l))d.has(m.value)||(d.add(m.value),u.push(m))}return u.length>0?u:null}function ZG(e){return KG.has(e)?Iz:VG.has(e)?nq:null}function Za(e){const{name:t,node:n,value:s}=e,o=n?.kind;if(o==="boolean")return{kind:"boolean"};if(o==="number")return{kind:"number"};if(o==="enum"){const l=n!==null&&n.kind==="enum"?n.options:[];return pS(l)?{kind:"accent",options:l}:{kind:"enum",options:l}}if(o==="array"||o==="object")return{kind:"opaque"};if(n!==null&&n.kind==="union"){if(s!==null&&typeof s=="object")return{kind:"opaque"};const l=IG(n);if(l.kind==="enum")return pS(l.options)?{kind:"accent",options:l.options}:l;if(l.kind!=="text")return l}if(typeof s!="string"&&s!==void 0&&s!==null&&o===void 0)return{kind:"text",multiline:!1};if(WG.test(t)||typeof s=="string"&&UG.test(s))return{kind:"color"};if(t==="kind"){const l=ZG(e.blockKind);if(l!==null)return{kind:"options",options:l.map(d=>({value:d}))}}const r=QG(t,e.data,e.path);return r!==null?{kind:"options",options:r}:{kind:"text",multiline:HG.has(t)||typeof s=="string"&&(s.length>60||s.includes(`
3252
+ `))}}const JG=["title","label","name","text","value","summary","desc","description","question","term","caption","subtitle"],eY=/^(col|row|w|x|y|layer|span|family|external|figure)$/;function fS(e){return e==null||e===""||Array.isArray(e)&&e.length===0}function cl(e,t){const n=Ih(t)??{},s=new Set;for(const l of JG){if(s.size>=3)break;const d=e.find(u=>u.name===l);d===void 0||!d.node.optional||!fS(n[d.name])||d.node.kind!=="string"&&d.node.kind!=="enum"&&d.node.kind!=="union"||s.add(d.name)}const o=[],r=[],i=[];for(const l of e){if(l.name==="id"){i.push(l);continue}const d=fS(n[l.name]);if(!l.node.optional||!d||l.node.kind==="array"||s.has(l.name)){o.push(l);continue}if(eY.test(l.name)){i.push(l);continue}r.push(l)}return{primary:o,more:r,advanced:i}}function hS(e,t){return e.kind==="union"?t===null||typeof t!="object":e.kind==="string"||e.kind==="number"||e.kind==="boolean"||e.kind==="enum"}function tY(e,t,n=4,s){const o=Ih(t)??{},{primary:r}=cl(e,t);let i=r.filter(l=>hS(l.node,o[l.name])).slice(0,n);if(s!==void 0&&!i.some(l=>l.name===s)){const l=e.find(d=>d.name===s&&hS(d.node,o[d.name]));l!==void 0&&(i=[...i,l])}return{visible:i,hidden:e.length-i.length}}function nY(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:{}}function mS(e){return e.kind==="string"||e.kind==="number"||e.kind==="boolean"||e.kind==="enum"||e.kind==="union"}function sY(e,t){const n=nY(t),s=[];for(const o of cl(e.fields,t).primary){const r=o.node.kind==="array"?o.node.element:null,i=l=>r===null?null:r.kind==="object"?r:r.kind==="union"&&l!==null&&typeof l=="object"?_h(r,l):null;if(r!==null&&(r.kind==="object"||r.kind==="union")){const l=Array.isArray(n[o.name])?n[o.name]:[];let d=!1;l.forEach((p,h)=>{const m=i(p);if(m!==null){d=!0;for(const g of cl(m.fields,p).primary)mS(g.node)&&s.push(`${o.name}.${h}.${g.name}`)}});const u=r.kind==="union"&&r.arms.every(p=>p.kind==="object");r.kind==="union"&&!d&&!u&&s.push(o.name)}else(mS(o.node)||o.node.kind==="array")&&s.push(o.name)}return s}function oY(e,t,n){const s=cl(e.fields,t).primary,o=s.findIndex(r=>r.name===n);return o<0?null:s[o+1]??null}function rY(e){return e.pristine?"exit":e.isLastField?"append":"advance"}function dC(e,t){if(e===t)return!0;if(e===null||t===null||typeof e!="object"||typeof t!="object"||Array.isArray(e)!==Array.isArray(t))return!1;const n=Object.keys(e),s=Object.keys(t);return n.length!==s.length?!1:n.every(o=>dC(e[o],t[o]))}function gS(e){return e==null||e===""||Array.isArray(e)&&e.length===0}function uC(e,t){return dC(e,t)||gS(e)?!0:typeof e!="object"||e===null||Array.isArray(e)?!1:Object.values(e).every(gS)}function iY(e,t,n){const s=t.trim().toLowerCase();return s===""||s===n.trim().toLowerCase()?e:e.filter(o=>o.value.toLowerCase().includes(s)||(o.label?.toLowerCase().includes(s)??!1))}const aY={canvas:[{keys:"↑↓",label:"select"},{keys:"/",label:"insert"},{keys:"⌘S",label:"save"},{keys:"?",label:"shortcuts"}],"canvas-selected":[{keys:"⏎",label:"edit"},{keys:"/",label:"insert"},{keys:"⌘D",label:"duplicate"},{keys:"⌘↑↓",label:"move"},{keys:"?",label:"shortcuts"}],part:[{keys:"⏎",label:"edit"},{keys:"←↑↓→",label:"move"},{keys:"⇥",label:"next part"},{keys:"⌫",label:"delete"},{keys:"esc",label:"back"}],sheet:[{keys:"⇥",label:"next field"},{keys:"⏎",label:"next row"},{keys:"⌘⏎",label:"done (in text: next)"},{keys:"esc",label:"cancel"}],home:[{keys:"click",label:"open a doc"},{keys:"⇧⌘P",label:"present"},{keys:"?",label:"shortcuts"}],present:[{keys:"← →",label:"previous / next slide"},{keys:"home end",label:"first / last slide"},{keys:"esc · ⇧⌘P",label:"back to Edit"}]};function lY(e,t){const n=aY[e];if(e==="canvas-selected"&&(t?.dragParts===!0||t?.parts===!0)){const s=[];return t.dragParts===!0?s.push({keys:"drag",label:"move parts"}):t.parts===!0&&s.push({keys:"click a part",label:"select it"}),[n[0],...s,...n.slice(1)]}return e==="part"&&t?.connectDots===!0?[...n.slice(0,2),{keys:"drag a dot",label:"connect"},...n.slice(2)]:n}function pC(e){if(e.kind==="markdown")return e.text.trim()!=="";const t=e.raw.trim();return t!==""&&t!==ih(e.kind).trim()}function Uv(e,t,n){const s=Dn(n),o=s[s.length-1];if(typeof o!="number")return!0;const r=s.slice(0,-1),i=hx(yy(e),r);if(i===null||i.kind!=="array")return!0;const l=is(t,r);if(!Array.isArray(l)||o>=l.length)return!0;const d=[...r].reverse().find(p=>typeof p=="string")??"item",u=Qa(i.element,l.slice(0,o),as(d));return!uC(l[o],u)}function wl(e){if(e===null||typeof e!="object")return!1;const t=e,n=typeof t.tagName=="string"?t.tagName.toUpperCase():"";return n==="INPUT"||n==="TEXTAREA"||n==="SELECT"?!0:t.isContentEditable===!0}function cY(e){return e.key!=="/"||e.metaKey||e.ctrlKey||e.altKey?!1:!wl(e.target)}const fC="chiltepin-studio-slash-used";function dY(){try{return window.localStorage.getItem(fC)==="1"}catch{return!0}}function uY(){try{window.localStorage.setItem(fC,"1")}catch{}}const vS=40;function Ua(e){if(e.kind==="markdown"){const n=e.text.replace(/\s+/g," ").trim();return n===""?"Text":n.length>vS?`${n.slice(0,vS)}…`:n}const t=e.data;if(t!==null&&typeof t=="object"&&!Array.isArray(t)){const n=t.title;if(typeof n=="string"&&n.trim()!=="")return n.trim()}return il[e.kind]}function yS(e){return e.kind==="markdown"?`markdown\0${e.text}`:`${e.kind}\0${e.raw}`}function hC(e,t,n){const s=ys(e,n).segments,o=ys(t,n).segments,r=new Array(s.length).fill(!1),i=new Map;o.forEach((v,y)=>{const b=yS(v);for(let E=0;E<s.length;E++)if(!r[E]&&yS(s[E])===b){r[E]=!0,i.set(y,E);return}});const l=new Set;let d=-1;for(const[v,y]of[...i.entries()].sort((b,E)=>b[0]-E[0]))y<d?l.add(v):d=y;const u=o.map((v,y)=>y).filter(v=>!i.has(v)),p=s.map((v,y)=>y).filter(v=>!r[v]),h=new Set,m=new Set(p);for(const v of u){const y=o[v].kind,b=p.find(E=>m.has(E)&&s[E].kind===y);b!==void 0&&(m.delete(b),h.add(v))}const g=[];return o.forEach((v,y)=>{l.has(y)?g.push({kind:v.kind,label:Ua(v),change:"reordered"}):h.has(y)?g.push({kind:v.kind,label:Ua(v),change:"edited"}):i.has(y)||g.push({kind:v.kind,label:Ua(v),change:"added"})}),s.forEach((v,y)=>{m.has(y)&&g.push({kind:v.kind,label:Ua(v),change:"removed"})}),g}function Ka(e){if(e==null)return!1;for(const t of e)if(t==="Files")return!0;return!1}function pY(e){return/(^|[\n{,])\s*(['"]?)(openapi|swagger)\2\s*:/.test(e)}function mC(e){return/^```[^\n]*\n([\s\S]*?)\n```\s*$/.exec(e)?.[1]??e}function fY(e){const t=e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"");return t===""?"api":t}function hY(e,t,n=0){let s=0;for(const o of t)e>(o.top+o.bottom)/2&&(s+=1);return Math.max(s,n)}const mY=e=>e.filter(t=>t.level==="warn").map(t=>t.message),xS=e=>e.filter(t=>t.level==="error").map(t=>t.message);function gY(e,t){const n=ID(t);let s=n.kind,o=s==="statustable"?_D(t):s==="chart"?LD(t):hw(t);if(o.data===null&&s!=="table"&&(s="table",o=hw(t)),o.data===null)return{kind:"error",message:`Could not import ${e}: ${xS(o.diagnostics).join("; ")}`};const r=xS(o.diagnostics);return r.length>0?{kind:"error",message:`CSV parse failed for ${e}: ${r.join("; ")}`}:{kind:"block",type:s,body:mC(o.fence),reason:n.reason,warnings:mY(o.diagnostics)}}function vY(e,t){if(!pY(t))return{kind:"unrecognized",message:`${e} is not a recognized import format (no openapi/swagger key).`};try{const n=qD(t),s=n.info.title;return{kind:"openapi",spec:n,title:s,defaultSlug:fY(s)}}catch(n){return{kind:"error",message:`Could not import ${e}: ${n.message}`}}}function yY(e,t,n){const s=n==="sql"?y6(t):n==="dbml"?_M(t):IM(t);if(!s.ok)return{kind:"error",message:`Could not import ${s.line!==void 0?`${e}:${s.line}`:e}: ${s.message}`};const o=Array.isArray(s.data.entities)?s.data.entities.length:0;return{kind:"block",type:"erd",body:mC(UR(s.data)),reason:`${o} ${o===1?"entity":"entities"} read from ${n==="sql"?"SQL DDL":n}`,warnings:[]}}function xY(e,t){const n=PD(e);return n===null?{kind:"unrecognized",message:`${e} is not a recognized import format — drop a .csv, a .sql / .dbml / .prisma schema, or an OpenAPI .yaml/.json.`}:n.id==="csv"?gY(e,t):n.id==="sql"||n.id==="dbml"||n.id==="prisma"?yY(e,t,n.id):vY(e,t)}async function gC(e,t){const n=ke.getState();if(n.mode!=="edit")return;let s;try{s=await e.text()}catch(i){n.toast(`Could not read ${e.name}: ${i.message}`,"error");return}const o=xY(e.name,s),r=ke.getState();switch(o.kind){case"block":{if(r.currentSlug===null){r.toast("Open a doc before importing a CSV.","error");return}iC(t,o.type,o.body,{openSheet:!1});const i=o.type==="table"?"":" · ⌘Z to undo";if(r.toast(`Imported ${e.name} as ${o.type} — ${o.reason}${i}`),o.warnings.length>0){const l=o.warnings[0]??"",d=o.warnings.length>1?` (+${o.warnings.length-1} more)`:"";r.toast(`CSV import warning: ${l}${d}`)}return}case"openapi":{r.requestImport({title:o.title,defaultSlug:o.defaultSlug,create:i=>{const l=i.split("/").pop()??i;ke.getState().newDoc(i,QD(o.spec,{slug:l}))}});return}case"unrecognized":r.toast(o.message);return;case"error":r.toast(o.message,"error");return}}function kY(e){const t=document.createElement("input");t.type="file",t.accept=".csv,.yaml,.yml,.json",t.style.display="none",t.onchange=()=>{const n=t.files?.[0];t.remove(),n!==void 0&&gC(n,e)},document.body.append(t),t.click()}var bY=gE();function Pf(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function Br(e,t){const n=Pf(e)?.[t];return Array.isArray(n)?n:[]}function $p(e,t,n){const s=[];return Br(e,"rows").forEach((o,r)=>{const i=Pf(o);i===null||!Array.isArray(i[t])||s.push({path:["rows",r,t],cells:i[t],pad:n})}),s}const jh={table:{colsPath:"columns",newHeader:()=>"New column",minCols:1,cellArrays:e=>Br(e,"rows").flatMap((t,n)=>Array.isArray(t)?[{path:["rows",n],cells:t,pad:""}]:[])},statustable:{colsPath:"columns",newHeader:()=>"New column",minCols:1,cellArrays:e=>{const t=$p(e,"cells","");return Br(e,"rows").forEach((n,s)=>{Br(n,"subtasks").forEach((o,r)=>{const i=Pf(o);i===null||!Array.isArray(i.cells)||t.push({path:["rows",s,"subtasks",r,"cells"],cells:i.cells,pad:""})})}),t}},matrix:{colsPath:"cols",newHeader:()=>"New column",minCols:1,cellArrays:e=>$p(e,"cells","")},journey:{colsPath:"stages",newHeader:()=>({label:"New stage"}),minCols:1,cellArrays:e=>{const t=$p(e,"cells",""),n=Br(e,"emotion");return n.length>0&&t.push({path:["emotion"],cells:n,pad:3}),t}},heatmap:{colsPath:"xLabels",newHeader:()=>"New",minCols:1,cellArrays:e=>$p(e,"values",0)},storymap:{colsPath:"backbone",newHeader:()=>({label:"New step"}),minCols:1,cellArrays:e=>Br(e,"slices").flatMap((t,n)=>{const s=Pf(t);return s!==null&&Array.isArray(s.cells)?[{path:["slices",n,"cells"],cells:s.cells,pad:[]}]:[]})}};function kS(e){return jh[e]??null}function bS(e,t){const n=jh[e];if(n===void 0)return null;const s=new RegExp(`^${n.colsPath}\\.(\\d+)$`).exec(t);return s!==null?Number(s[1]):null}function wY(e,t){const n=jh[e];if(n===void 0)return null;const s=Br(t,n.colsPath),o=[{path:[n.colsPath,s.length],value:n.newHeader(s.length)}];for(const r of n.cellArrays(t)){if(r.cells.length===s.length){o.push({path:[...r.path,s.length],value:r.pad});continue}const i=r.cells.slice();for(;i.length<s.length+1;)i.push(r.pad);o.push({path:r.path,value:i})}return{sets:o,headerPath:`${n.colsPath}.${s.length}`}}function wS(e,t,n){const s=jh[e];if(s===void 0)return null;const o=Br(t,s.colsPath);if(!Number.isInteger(n)||n<0||n>=o.length||o.length-1<s.minCols)return null;const r=[{path:[s.colsPath],value:o.filter((i,l)=>l!==n)}];for(const i of s.cellArrays(t))n>=i.cells.length||r.push({path:i.path,value:i.cells.filter((l,d)=>d!==n)});return r}const ki=8;function $Y(e){const t=[];return e.forEach((n,s)=>{n.separator!==!0&&n.disabled!==!0&&t.push(s)}),t}function vC({items:e,at:t,depth:n,onPick:s,onClose:o,autoFocus:r}){const i=oe.useRef(null),[l,d]=oe.useState(null),[u,p]=oe.useState(-1),[h,m]=oe.useState(null),g=oe.useRef(null);oe.useLayoutEffect(()=>{const $=i.current;if($===null)return;const A=$.offsetWidth,T=$.offsetHeight;let N=t.x,j=t.y;N+A>window.innerWidth-ki&&(N=n>0?Math.max(ki,t.x-A-4-180):Math.max(ki,window.innerWidth-A-ki)),j+T>window.innerHeight-ki&&(j=Math.max(ki,window.innerHeight-T-ki)),d({x:N,y:j})},[t.x,t.y,n]),oe.useEffect(()=>{r&&i.current?.focus()},[r]),oe.useEffect(()=>()=>{g.current!==null&&clearTimeout(g.current)},[]);const v=$=>{const A=e[$],T=i.current?.querySelector(`[data-mi="${$}"]`);if(A===void 0||A.children===void 0||T===void 0||T===null)return;const N=T.getBoundingClientRect();m({index:$,at:{x:N.right+2,y:N.top-5}})},y=($,A)=>{p($);const T=e[$];g.current!==null&&clearTimeout(g.current),T!==void 0&&T.children!==void 0&&T.disabled!==!0?g.current=setTimeout(()=>v($),90):g.current=setTimeout(()=>m(null),120)},b=$=>{const A=e[$];if(!(A===void 0||A.disabled===!0||A.separator===!0)){if(A.children!==void 0){v($);return}s(A)}},E=$=>{if(h!==null)return;const A=$Y(e);if(A.length===0)return;const T=A.indexOf(u),N=j=>{const P=A.length,I=T<0?j>0?0:P-1:(T+j+P)%P;p(A[I])};switch($.key){case"ArrowDown":$.preventDefault(),$.stopPropagation(),N(1);return;case"ArrowUp":$.preventDefault(),$.stopPropagation(),N(-1);return;case"Home":$.preventDefault(),p(A[0]);return;case"End":$.preventDefault(),p(A[A.length-1]);return;case"ArrowRight":$.preventDefault(),$.stopPropagation(),u>=0&&e[u]?.children!==void 0&&v(u);return;case"ArrowLeft":$.preventDefault(),$.stopPropagation(),n>0&&o();return;case"Enter":case" ":$.preventDefault(),$.stopPropagation(),u>=0&&b(u);return;case"Escape":$.preventDefault(),$.stopPropagation(),o();return}if($.key.length===1&&!$.metaKey&&!$.ctrlKey&&!$.altKey){const j=$.key.toLowerCase(),I=(T<0?A:[...A.slice(T+1),...A.slice(0,T+1)]).find(O=>(e[O]?.label??"").toLowerCase().startsWith(j));I!==void 0&&($.preventDefault(),p(I))}};return oe.useEffect(()=>{h===null&&r&&i.current?.focus()},[h,r]),w.jsxs(w.Fragment,{children:[w.jsx("div",{ref:i,className:"stu-menu",role:"menu",tabIndex:-1,"data-depth":n,style:{left:l?.x??t.x,top:l?.y??t.y,visibility:l===null?"hidden":"visible"},onKeyDown:E,onPointerDown:$=>$.stopPropagation(),onContextMenu:$=>$.preventDefault(),children:e.map(($,A)=>$.separator===!0?w.jsx("div",{className:"stu-menu-sep",role:"separator"},`s${A}`):w.jsxs("button",{type:"button",role:$.checked!==void 0?"menuitemcheckbox":"menuitem","aria-checked":$.checked,"aria-haspopup":$.children!==void 0?"menu":void 0,"aria-expanded":$.children!==void 0?h?.index===A:void 0,"aria-disabled":$.disabled===!0,"data-mi":A,tabIndex:-1,className:["stu-menu-item",$.danger===!0?"stu-menu-item-danger":"",$.disabled===!0?"stu-menu-item-disabled":"",u===A?"stu-menu-item-active":""].filter(Boolean).join(" "),onPointerEnter:()=>y(A),onClick:T=>{T.stopPropagation(),b(A)},children:[w.jsx("span",{className:"stu-menu-check","aria-hidden":"true",children:$.checked===!0?"✓":""}),w.jsx("span",{className:"stu-menu-label",children:$.label}),$.shortcut!==void 0&&$.children===void 0&&w.jsx("span",{className:"stu-menu-key",children:$.shortcut}),$.children!==void 0&&w.jsx("span",{className:"stu-menu-chev","aria-hidden":"true",children:"▸"})]},`${$.label}${A}`))}),h!==null&&e[h.index]?.children!==void 0&&w.jsx(vC,{items:e[h.index]?.children??[],at:h.at,depth:n+1,onPick:s,onClose:()=>m(null),autoFocus:!0})]})}function SY({items:e,at:t,onPick:n,onClose:s}){return oe.useEffect(()=>{const o=l=>{l.target instanceof Element&&l.target.closest(".stu-menu")!==null||(l.preventDefault(),l.stopPropagation(),s())},r=()=>s(),i=l=>{l.key==="Escape"&&!(l.target instanceof Element&&l.target.closest(".stu-menu")!==null)&&(l.preventDefault(),l.stopPropagation(),s())};return window.addEventListener("pointerdown",o,!0),window.addEventListener("scroll",r,!0),window.addEventListener("resize",r),window.addEventListener("blur",r),window.addEventListener("keydown",i,!0),()=>{window.removeEventListener("pointerdown",o,!0),window.removeEventListener("scroll",r,!0),window.removeEventListener("resize",r),window.removeEventListener("blur",r),window.removeEventListener("keydown",i,!0)}},[s]),e.length===0?null:w.jsx(vC,{items:e,at:t,depth:0,onPick:n,onClose:s,autoFocus:!0})}function EY(e,t,n){if(t==="")return[];const s=[];for(let o=0;o<e.length;o++)o!==n&&e[o]===t&&s.push(o);return s}function I0(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function MY(e,t){if(e!=="sequence")return!1;const n=I0(t)?.messages;if(!Array.isArray(n))return!1;const s=n.filter(cd);return s.length===0?!1:s.every(o=>{const r=I0(o)?.summary;return typeof r!="string"||r===""})}function cd(e){const t=I0(e);return t===null?!0:!("frame"in t||"else"in t||"end"in t)}function AY(e,t){if(!Array.isArray(e))return t+1;let n=0;for(let s=0;s<=t&&s<e.length;s++)cd(e[s])&&(n+=1);return n}const $S=140,CY=140,SS=120,ES="cubic-bezier(0.2, 0.7, 0.2, 1)",Sp=.5;function NY(e,t){return Math.abs(e.left-t.left)<Sp&&Math.abs(e.top-t.top)<Sp&&Math.abs(e.width-t.width)<Sp&&Math.abs(e.height-t.height)<Sp}function TY(e,t,n,s={}){const o=[],r=[],i=[],l=[],d=s.moves!==!1;for(const[u,p]of t){const h=e.get(u);if(h===void 0){(n(u)?i:r).push(u);continue}NY(h,p)||(n(u)?i.push(u):d&&o.push({key:u,from:h,to:p}))}for(const u of e.keys())t.has(u)||l.push(u);return{moves:o,pops:r,crossfades:i,fades:l}}function _Y(e,t){const n=e.left-t.left,s=e.top-t.top,o=t.width>0?e.width/t.width:1,r=t.height>0?e.height/t.height:1,i=Math.abs(o-1)>.01||Math.abs(r-1)>.01?` scale(${o.toFixed(4)}, ${r.toFixed(4)})`:"";return`translate(${n.toFixed(2)}px, ${s.toFixed(2)}px)${i}`}function mx(){return typeof window>"u"||typeof window.matchMedia!="function"?!0:window.matchMedia("(prefers-reduced-motion: reduce)").matches}function yC(e){const t=new Map;for(const n of Array.from(e.querySelectorAll("[data-bp]"))){if(n.closest(".stu-dx-hit")!==null||n.closest(".stu-dx-overlay")!==null)continue;const s=n.getAttribute("data-bp")??"";s!==""&&!t.has(s)&&t.set(s,n)}return t}function xC(e){const t=e.getBoundingClientRect(),n=new Map;for(const[s,o]of yC(e)){const r=o.getBoundingClientRect();n.set(s,{left:r.left-t.left,top:r.top-t.top,width:r.width,height:r.height})}return n}function Kc(e){return typeof e.animate=="function"&&"style"in e}function MS(e,t,n){const s=e.style.transformBox,o=e.style.transformOrigin;e.style.transformBox="fill-box",e.style.transformOrigin=t;const r=()=>{e.style.transformBox=s,e.style.transformOrigin=o};n.addEventListener("finish",r),n.addEventListener("cancel",r)}function LY(e,t,n,s={}){const o=xC(e),r=TY(t,o,n,s);if(mx())return r;const i=yC(e);for(const l of r.moves){const d=i.get(l.key);if(d===void 0||!Kc(d))continue;const u=d.animate([{transform:_Y(l.from,l.to)},{transform:"none"}],{duration:$S,easing:ES});MS(d,"0 0",u)}for(const l of r.pops){const d=i.get(l);if(d===void 0||!Kc(d))continue;const u=d.animate([{transform:"scale(0.92)",opacity:0},{transform:"none",opacity:1}],{duration:CY,easing:ES});MS(d,"center",u)}for(const l of r.crossfades){const d=i.get(l);d===void 0||!Kc(d)||d.animate([{opacity:0},{opacity:1}],{duration:$S,easing:"ease-out"})}return r}function AS(e,t,n){if(mx()||t.length===0){n();return}const s=new Set(t),o=Array.from(e.querySelectorAll("[data-bp]")).filter(d=>s.has(d.getAttribute("data-bp")??"")&&d.closest(".stu-dx-hit")===null&&d.closest(".stu-dx-overlay")===null&&Kc(d));if(o.length===0){n();return}let r=o.length,i=!1;const l=()=>{r-=1,r<=0&&!i&&(i=!0,n())};for(const d of o){if(!Kc(d))continue;const u=d.animate([{opacity:1},{opacity:0}],{duration:SS,easing:"ease-out",fill:"forwards"});u.addEventListener("finish",l),u.addEventListener("cancel",l)}setTimeout(()=>{i||(i=!0,n())},SS+80)}function rs(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function Ho(e,t){const n=rs(e)?.[t];return Array.isArray(n)?n:[]}function IY(e,t,n){return Ho(e,t).map(s=>rs(s)?.[n]).filter(s=>typeof s=="string"&&s!=="")}function jY(e,t,n,s){const o=$n(e);if(o!==null&&t===o.edgesField){const r=IY(s,o.nodesField,o.idField),i=r[0],l=r[1]??(o.allowSelfLoop?r[0]:r[1]);return i!==void 0&&l!==void 0?o.newEdge(i,l):n}if(e==="erd"&&t==="relations"){const r=Ho(s,"entities").map(l=>rs(l)?.name).filter(l=>typeof l=="string"&&l!==""),i=rs(n)??{};return r.length>=2?{...i,from:r[0],to:r[1]}:n}if(e==="statustable"&&/^rows(\.\d+\.subtasks)?$/.test(t)){const r=rs(n)??{},i=Ho(s,"columns"),l=Math.max(1,i.length),d=Array.from({length:l},(p,h)=>h===0?"New row":""),u=rs(Ho(s,"statuses")[0])?.label;return{...r,cells:d,status:typeof u=="string"?u:"todo"}}if(e==="matrix"&&t==="rows"){const r=rs(n)??{},i=Ho(s,"cols").length;return{...r,cells:Array.from({length:i},()=>"")}}if(e==="journey"&&t==="rows"){const r=rs(n)??{},i=Ho(s,"stages").length;return i===0?n:{...r,cells:Array.from({length:i},()=>"")}}if(e==="heatmap"&&t==="rows"){const r=rs(n)??{},i=Math.max(1,Ho(s,"xLabels").length);return{...r,values:Array.from({length:i},()=>0)}}if(e==="scorecard"&&t==="options"){const r=rs(n)??{},i=Ho(s,"criteria").length;return i===0?n:{...r,scores:Array.from({length:i},()=>0)}}if(e==="storymap"&&t==="slices"){const r=rs(n)??{},i=Ho(s,"backbone").length;return{...r,cells:Array.from({length:i},()=>[])}}return e==="prose"&&t==="blocks"?{type:"p",text:"New paragraph"}:e==="okr"&&t==="items"?{...rs(n)??{},krs:[{kr:"New key result",progress:0}]}:n}const PY={glossary:()=>({term:"New term",def:"What it means"}),faq:()=>({q:"New question",a:"The answer"}),steps:()=>({title:"New step"}),list:()=>({lead:"New item"}),takeaways:()=>({text:"New takeaway"}),agenda:()=>({title:"New item"}),team:()=>({name:"New member"}),stats:()=>({value:"0",label:"New stat"}),saga:()=>({id:"step",name:"New step",service:"Service"})};function kC(e,t){const n=PY[e];return n===void 0?null:j0(n(),t)}function j0(e,t){const n=rs(e),s=n?.id;if(n===null||typeof s!="string")return e;const o=new Set(t.map(d=>rs(d)?.id).filter(d=>typeof d=="string")),r=s.replace(/\d+$/,"")===""?"item":s.replace(/\d+$/,"");let i=r,l=2;for(;o.has(i);)i=`${r}${l}`,l+=1;return{...n,id:i}}function Ph(e){return $n(e)?.groups===!0}function CS(e,t,n,s,o){const r=wo(e,t,n),i=wo(e,s,o);return{col:Math.min(r.col,i.col),row:Math.min(r.row,i.row),cols:Math.abs(r.col-i.col)+1,rows:Math.abs(r.row-i.row)+1}}function bC(e,t,n){if(!Ph(e))return null;const s=t!==null&&typeof t=="object"&&!Array.isArray(t)?t:{},o=Array.isArray(s.groups)?s.groups:[],r={col:n.col,row:n.row,cols:n.cols,rows:n.rows,label:"Group"};return{sets:[{path:["groups",o.length],value:r}],groupPath:`groups.${o.length}`}}function wC(e){const t=/^groups\.(\d+)$/.exec(e);return t!==null?Number(t[1]):null}function Ji(e,t){const n=e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null,o=(n!==null&&Array.isArray(n.groups)?n.groups:null)?.[t];if(o==null||typeof o!="object"||Array.isArray(o))return null;const r=o,i=r.col,l=r.row;if(typeof i!="number"||typeof l!="number")return null;const d=typeof r.cols=="number"?r.cols:1,u=typeof r.rows=="number"?r.rows:1;return{col:i,row:l,cols:d,rows:u}}function OY(e,t){return{col:e==="nw"||e==="sw"?t.col+t.cols-1:t.col,row:e==="nw"||e==="ne"?t.row+t.rows-1:t.row}}function RY(e,t){return{col:Math.min(e.col,t.col),row:Math.min(e.row,t.row),cols:Math.abs(e.col-t.col)+1,rows:Math.abs(e.row-t.row)+1}}function $C(e,t,n,s,o){const r=(i,l)=>Math.max(1,Math.min(i,l));return{...e,col:r(e.col+t,s+2-e.cols),row:r(e.row+n,o+2-e.rows)}}function DY(e,t,n,s,o){if(t==="x"){const i=e.cols+n;return i<1||e.col+i-1>s+1?null:{...e,cols:i}}const r=e.rows+n;return r<1||e.row+r-1>o+1?null:{...e,rows:r}}function SC(e,t,n){const s=Ji(e,t);return s===null||s.col===n.col&&s.row===n.row&&s.cols===n.cols&&s.rows===n.rows?null:[{path:["groups",t,"col"],value:n.col},{path:["groups",t,"row"],value:n.row},{path:["groups",t,"cols"],value:n.cols},{path:["groups",t,"rows"],value:n.rows}]}function EC(e,t,n){const s=Ji(e,t);return s===null||s.col===n.col&&s.row===n.row?null:[{path:["groups",t,"col"],value:n.col},{path:["groups",t,"row"],value:n.row}]}function gx(e,t){return{left:(e.padX+(t.col-1)*(e.cellW+e.gapX))*e.scale,top:(e.padTop+(t.row-1)*(e.cellH+e.gapY))*e.scale,width:(t.cols*e.cellW+(t.cols-1)*e.gapX)*e.scale,height:(t.rows*e.cellH+(t.rows-1)*e.gapY)*e.scale}}function NS(e){return e.remove===!0}function BY(e,t,n=null){if(e==="sequence"&&t!==null){let r=/^actors\.(\d+)(?:\..+)?$/.exec(t);return r!==null?{type:"actor",index:Number(r[1])}:(r=/^messages\.(\d+)(?:\..+)?$/.exec(t),r!==null?{type:"message",index:Number(r[1])}:{type:"background"})}if(e==="erd"&&t!==null){let r=/^entities\.(\d+)\.columns\.(\d+)(?:\..+)?$/.exec(t);return r!==null?{type:"column",entity:Number(r[1]),index:Number(r[2])}:(r=/^entities\.(\d+)(?:\..+)?$/.exec(t),r!==null?{type:"entity",index:Number(r[1])}:(r=/^relations\.(\d+)(?:\..+)?$/.exec(t),r!==null?{type:"edge",index:Number(r[1])}:{type:"background"}))}const s=Nh[e];if(s!==void 0){if(t===null)return{type:"background"};const r=new RegExp(`^${s}\\.(\\d+)(?:\\..+)?$`).exec(t);return r!==null?{type:"item",index:Number(r[1])}:{type:"background"}}const o=$n(e);if(o!==null&&t!==null){const r=Af(o,t)??Af(o,t.replace(/^((?:[^.]+)\.\d+)\..+$/,"$1"));if(r!==null)return{type:"node",index:r};const i=Cf(o,t)??Cf(o,t.replace(/^((?:[^.]+)\.\d+)\..+$/,"$1"));if(i!==null)return{type:"edge",index:i};if(o.groups){const l=wC(t);if(l!==null)return{type:"group",index:l}}return{type:"background"}}return t===null&&n!==null&&o!==null&&o.gridNodes?{type:"cell",col:n.col,row:n.row}:{type:"background"}}const vs={label:"",separator:!0};function Kn(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function Zo(e,t){const n=Kn(e)?.[t];return Array.isArray(n)?n:[]}function Ds(e,t){return Zo(e,t).map(n=>Kn(n)??{})}function wn(e,t,n){const s={...e};return n===void 0?delete s[t]:s[t]=n,s}function dl(e){return e.length>0&&/^[a-z]/.test(e)?e.charAt(0).toUpperCase()+e.slice(1):e}const zY=[{dir:"right",arrow:"→"},{dir:"down",arrow:"↓"},{dir:"left",arrow:"←"},{dir:"up",arrow:"↑"}];function Oh(e,t){if(e.placements===null)return[];const n=Ds(e.data,t.nodesField);return e.placements.map((s,o)=>{const r=n[o]?.w;return{col:s.col,row:s.row,w:typeof r=="number"&&r>=1?Math.floor(r):1}})}function Rh(e,t,n){return e.some(s=>s.row===n&&t>=s.col&&t<s.col+s.w)}function FY(e,t,n,s){if(e.placements===null||e.grid===null)return null;const o=Oh(e,t),r=o[n];if(r===void 0)return null;const i=e.grid.cols+1,l=t.growRows===!1?e.grid.rows:e.grid.rows+1;let d=r.col,u=r.row;const p=()=>{s==="right"?d+=1:s==="left"?d-=1:s==="down"?u+=1:u-=1};for(s==="right"?d=r.col+r.w:p();d>=1&&u>=1&&d<=i&&u<=l;){if(!Rh(o,d,u))return{col:d,row:u};p()}return null}function qY(e,t){if(e.grid===null)return{col:1,row:1};const n=Oh(e,t);for(let s=1;s<=e.grid.rows;s++)for(let o=1;o<=e.grid.cols;o++)if(!Rh(n,o,s))return{col:o,row:s};return{col:e.grid.cols+1,row:1}}function HY(e,t,n,s){const o=Oh(e,t).filter((r,i)=>i!==s);for(let r=n.row;r<n.row+n.rows;r++)for(let i=n.col;i<n.col+n.cols;i++)if(!Rh(o,i,r))return{col:i,row:r};return null}function TS(e,t){return e.col>=t.col&&e.col<t.col+t.cols&&e.row>=t.row&&e.row<t.row+t.rows}function _S(e,t,n,s){const o=t.writeCell??(i=>({col:i.col,row:i.row})),r=[];e.quick&&e.placements!==null&&e.placements.forEach((i,l)=>{if(l!==n)for(const[d,u]of Object.entries(o(i)))r.push({path:[t.nodesField,l,d],value:u})});for(const[i,l]of Object.entries(o(s)))r.push({path:[t.nodesField,n,i],value:l});return r}function MC(e,t){const n=[...t.nodeKinds],s=new Set(n.map(o=>o.kind));for(const o of Ds(e.data,t.nodesField)){const r=o.kind;typeof r=="string"&&r!==""&&!s.has(r)&&(s.add(r),n.push({kind:r,label:dl(r)}))}return n}function WY(e,t){if(t.kind==="sequence")return eX(e,t);if(t.kind==="erd")return oX(e,t);const n=Nh[t.kind];if(n!==void 0)return aX(e,t,n);const s=$n(t.kind);if(s===null)return e.type==="background"?[Sd()]:[];switch(e.type){case"node":return KY(e.index,t,s);case"edge":return CC(e.index,t,s);case"group":return XY(e.index,t);case"cell":return QY(e,t,s);default:return ZY(t,s)}}function Sd(){return{label:"Open YAML",shortcut:"⏎",action:{type:"openYaml"}}}function AC(e){if(!UY.has(e.kind))return null;const n=Kn(e.data)?.dir==="TB"?"TB":"LR";return{label:"Direction",children:["LR","TB"].map(s=>({label:s==="LR"?"Left → right":"Top → bottom",checked:n===s,op:()=>[{path:["dir"],value:s}]}))}}const UY=new Set(["flow","dfd","state","c4","block","felogic","erd"]);function KY(e,t,n){const s=Ds(t.data,n.nodesField),o=s[e];if(o===void 0)return[];const r=typeof o[n.idField]=="string"?o[n.idField]:"",i=`${n.nodesField}.${e}`,l=[],d=MC(t,n),u=d.length>1||d.length===1&&o.kind!==void 0;if(n.newNode!==void 0&&n.gridNodes)for(const{dir:p,arrow:h}of zY){const m=FY(t,n,e,p),g=y=>{if(m===null)return[];const b=Nf(n,t.data,r,m,y,t.placements??void 0);return b===null?[]:b.sets},v={select:`${n.nodesField}.${s.length}`,edit:n.labelField};l.push(n.nodeKinds.length===1?{label:`Add node ${h}`,disabled:m===null,op:()=>g(n.nodeKinds[0].kind),then:v}:{label:`Add node ${h}`,disabled:m===null,children:d.map(y=>({label:y.label,op:()=>g(y.kind),then:v}))})}else n.memberField!==void 0&&l.push({label:"Add node",children:d.map(p=>({label:p.label,op:()=>{const h=Nf(n,t.data,r,{col:1,row:1},p.kind);return h===null?[]:h.sets},then:{select:`${n.nodesField}.${s.length}`,edit:n.labelField}}))});if(u){const p=o.kind;l.push({label:"Change kind",children:d.map(h=>({label:h.label,checked:p===h.kind,op:()=>[{path:[n.nodesField,e],value:wn(o,"kind",h.kind)}]}))})}if(t.kind==="block"||t.kind==="cluster"){const p=typeof o.replicas=="number"?o.replicas:1,h=[1,2,3,5];l.push({label:"Replicas",children:[...h.map(m=>({label:m===1?"1 (single)":`×${m}`,checked:p===m,op:()=>[{path:[n.nodesField,e],value:wn(o,"replicas",m===1?void 0:m)}]})),{label:"Custom…",action:{type:"edit",path:i,field:"replicas"}}]})}return l.push(...YY(e,o,t,n)),l.push(vs),l.push({label:"Rename",shortcut:"⏎",action:{type:"edit",path:i,field:n.labelField}}),l.push({label:"Delete node",shortcut:"⌫",danger:!0,fades:[i,...VY(t,n,r).map(p=>`${n.edgesField}.${p}`)],op:()=>GY(t,n,e,r)}),l}function VY(e,t,n){const s=[];return Ds(e.data,t.edgesField).forEach((o,r)=>{(o.from===n||o.to===n)&&s.push(r)}),s}function GY(e,t,n,s){const o=Zo(e.data,t.nodesField),r=Ds(e.data,t.edgesField);return r.filter(l=>l.from===s||l.to===s).length===0?[{path:[t.nodesField,n],remove:!0}]:[{path:[t.nodesField],value:o.filter((l,d)=>d!==n)},{path:[t.edgesField],value:r.filter(l=>l.from!==s&&l.to!==s)}]}function YY(e,t,n,s){if(s.groups&&n.placements!==null){const o=Ds(n.data,"groups");if(o.length===0)return[];const r=n.placements[e],i=o.map((u,p)=>Ji(n.data,p)),l=i.findIndex(u=>u!==null&&r!==void 0&&TS(r,u)),d=[{label:"Add to group",children:o.map((u,p)=>{const h=i[p]??null,m=h!==null?HY(n,s,h,e):null;return{label:typeof u.label=="string"?u.label:`Group ${p+1}`,checked:l===p,disabled:l===p||m===null,op:()=>m===null?[]:_S(n,s,e,m)}})}];if(l>=0&&n.grid!==null){const u=Oh(n,s).filter((m,g)=>g!==e);let p=null;for(let m=1;m<=n.grid.rows+1&&p===null;m++)for(let g=1;g<=n.grid.cols+1;g++){const v={col:g,row:m};if(!Rh(u,g,m)&&!i.some(y=>y!==null&&TS(v,y))){p=v;break}}const h=p;d.push({label:"Remove from group",disabled:h===null,op:()=>h===null?[]:_S(n,s,e,h)})}return d}if(n.kind==="graph"){const o=new Set;for(const d of Ds(n.data,s.nodesField))typeof d.group=="number"&&o.add(d.group);const r=typeof t.group=="number"?t.group:null,i=o.size===0?1:Math.max(...o)+1,l=[{label:"Add to group",children:[...[...o].sort((d,u)=>d-u).map(d=>({label:`Group ${d}`,checked:r===d,disabled:r===d,op:()=>[{path:[s.nodesField,e],value:wn(t,"group",d)}]})),{label:`New group ${i}`,op:()=>[{path:[s.nodesField,e],value:wn(t,"group",i)}]}]}];return r!==null&&l.push({label:"Remove from group",op:()=>[{path:[s.nodesField,e],value:wn(t,"group",void 0)}]}),l}if(s.memberField!==void 0){const o=s.memberField,r=Ds(n.data,"clusters");return r.length<2?[]:[{label:"Move to cluster",children:r.map(i=>({label:typeof i.label=="string"?i.label:String(i.id??""),checked:t[o]===i.id,disabled:t[o]===i.id,op:()=>[{path:[s.nodesField,e],value:wn(t,o,i.id)}]}))}]}return[]}function CC(e,t,n){const o=Ds(t.data,n.edgesField)[e];if(o===void 0)return[];const r=`${n.edgesField}.${e}`,i=[];if(n.edgeKinds!==void 0){const l=typeof o.kind=="string"?o.kind:null,d=n.edgeKinds.includes("solid")?"solid":n.edgeKinds.includes("sync")?"sync":null;i.push({label:"Kind",children:n.edgeKinds.map(u=>({label:dl(u),checked:l===u||l===null&&u===d,op:()=>[{path:[n.edgesField,e],value:wn(o,"kind",u===d?void 0:u)}]}))})}else if(t.kind==="graph"){const l=o.dir==="undirected"?"undirected":"directed";i.push({label:"Direction",children:["directed","undirected"].map(d=>({label:dl(d),checked:l===d,op:()=>[{path:[n.edgesField,e],value:wn(o,"dir",d==="directed"?void 0:d)}]}))})}if(n.edgeChoices!==void 0&&n.edgeChoiceField!==void 0){const l=n.edgeChoiceField;i.push({label:"Cardinality",children:n.edgeChoices.map(d=>({label:d.label,checked:o[l]===d.value,op:()=>[{path:[n.edgesField,e],value:wn(o,l,d.value)}]}))})}return i.push({label:n.edgeTextField==="event"?"Edit event":"Edit label",shortcut:"⏎",action:{type:"edit",path:r,field:n.edgeTextField}}),i.push({label:"Reverse",disabled:o.from===o.to,op:()=>[{path:[n.edgesField,e],value:{...o,from:o.to,to:o.from}}]}),i.push(vs),i.push({label:"Delete edge",shortcut:"⌫",danger:!0,fades:[r],op:()=>[{path:[n.edgesField,e],remove:!0}]}),i}function XY(e,t){if(Zo(t.data,"groups")[e]===void 0)return[];const s=`groups.${e}`;return[{label:"Rename",shortcut:"⏎",action:{type:"edit",path:s,field:"label"}},vs,{label:"Delete group",shortcut:"⌫",danger:!0,fades:[s],op:()=>[{path:["groups",e],remove:!0}]}]}function NC(e,t,n,s){if(s.newNode===void 0)return null;const o=MC(n,s),r=Zo(n.data,s.nodesField).length,i={select:`${s.nodesField}.${r}`,edit:s.labelField},l=d=>{const u=dx(s,n.data,t,d,n.placements??void 0);return u===null?[]:u.sets};return s.nodeKinds.length===1?{label:e,op:()=>l(s.nodeKinds[0].kind),then:i}:{label:e,children:o.map(d=>({label:d.label,op:()=>l(d.kind),then:i}))}}function QY(e,t,n){const s=[],o=NC("Insert node here",{col:e.col,row:e.row},t,n);if(o!==null&&s.push(o),n.groups){const r=Zo(t.data,"groups").length;s.push({label:"Insert group here",op:()=>{const i=bC(t.kind,t.data,{col:e.col,row:e.row,cols:1,rows:1});return i===null?[]:i.sets},then:{select:`groups.${r}`,edit:"label"}})}return s}function ZY(e,t){const n=[];if(t.gridNodes&&e.grid!==null){const o=NC("Insert node",qY(e,t),e,t);o!==null&&n.push(o)}const s=AC(e);return s!==null&&n.push(s),n.length>0&&n.push(vs),n.push(Sd()),n}const JY=["sync","response","async","error","note"];function eX(e,t){const n=Ds(t.data,"actors"),s=Zo(t.data,"messages");if(e.type==="actor"){const o=n[e.index];if(o===void 0)return[];const r=typeof o.id=="string"?o.id:"",i=`actors.${e.index}`;return[{label:"Add message from here…",action:{type:"connect",fromIndex:e.index}},{label:"Add note here",op:()=>[{path:["messages",s.length],value:{from:r,to:r,kind:"note",label:"note"}}],then:{select:`messages.${s.length}`,edit:"label"}},vs,{label:"Rename",shortcut:"⏎",action:{type:"edit",path:i,field:"name"}},{label:"Delete actor",shortcut:"⌫",danger:!0,fades:[i,...s.flatMap((l,d)=>{const u=Kn(l);return u!==null&&(u.from===r||u.to===r)?[`messages.${d}`]:[]})],op:()=>{const l=s.filter(d=>{const u=Kn(d);return u===null||u.from!==r&&u.to!==r});return l.length===s.length?[{path:["actors",e.index],remove:!0}]:[{path:["actors"],value:n.filter((d,u)=>u!==e.index)},{path:["messages"],value:l}]}}]}if(e.type==="message"){const o=Kn(s[e.index]);if(o===null)return[];const r=`messages.${e.index}`;if(!cd(o))return[..."frame"in o?[{label:"Edit label",shortcut:"⏎",action:{type:"edit",path:r,field:"label"}}]:[],{label:"Delete marker",shortcut:"⌫",danger:!0,fades:[r],op:()=>[{path:["messages",e.index],remove:!0}]}];const i=typeof o.kind=="string"?o.kind:"sync",l=t.selected!==null?/^messages\.(\d+)$/.exec(t.selected):null,d=l!==null&&cd(s[Number(l[1])])?Number(l[1]):e.index,u=Math.min(d,e.index),p=Math.max(d,e.index),h=u===p?"":` (${p-u+1} messages)`;return[{label:"Kind",children:JY.map(m=>({label:dl(m),checked:i===m,op:()=>[{path:["messages",e.index],value:wn(o,"kind",m==="sync"?void 0:m)}]}))},{label:"Edit label",shortcut:"⏎",action:{type:"edit",path:r,field:"label"}},{label:"Add step note",shortcut:"n",action:{type:"edit",path:r,field:"summary"}},{label:`Wrap in${h}`,children:lM.map(m=>({label:m,op:()=>[{path:["messages"],value:tX(s,u,p,m)}],then:{select:`messages.${u}`,edit:"label"}}))},{label:"Activate target",checked:o.activate===!0,op:()=>[{path:["messages",e.index],value:wn(o,"activate",o.activate===!0?void 0:!0)}]},{label:"Deactivate sender",checked:o.deactivate===!0,op:()=>[{path:["messages",e.index],value:wn(o,"deactivate",o.deactivate===!0?void 0:!0)}]},vs,{label:"Delete",shortcut:"⌫",danger:!0,fades:[r],op:()=>[{path:["messages",e.index],remove:!0}]}]}return[{label:"Add actor",op:()=>[{path:["actors",n.length],value:{id:nX(n),name:"New actor"}}],then:{select:`actors.${n.length}`,edit:"name"}},vs,Sd()]}function tX(e,t,n,s){return[...e.slice(0,t),{frame:s,label:""},...e.slice(t,n+1),{end:!0},...e.slice(n+1)]}function nX(e){const t=new Set(e.map(o=>String(o.id??"")));let n=e.length+1,s=`actor${n}`;for(;t.has(s);)n+=1,s=`actor${n}`;return s}const sX=[{key:"pk",label:"Primary key"},{key:"fk",label:"Foreign key"},{key:"unique",label:"Unique"},{key:"nullable",label:"Nullable"},{key:"index",label:"Indexed"}];function oX(e,t){const n=$n("erd"),s=Ds(t.data,"entities");if(e.type==="entity"){const i=s[e.index];if(i===void 0)return[];const l=typeof i.name=="string"?i.name:"",d=Zo(i,"columns"),u=`entities.${e.index}`,p=Ds(t.data,"relations");return[{label:"Add column",op:()=>[{path:["entities",e.index,"columns",d.length],value:{name:"new_column",type:"text"}}],then:{select:`${u}.columns.${d.length}`,edit:"name"}},{label:"Add relation to…",action:{type:"connect",fromIndex:e.index}},vs,{label:"Rename",shortcut:"⏎",action:{type:"edit",path:u,field:"name"}},{label:"Delete entity",shortcut:"⌫",danger:!0,fades:[u,...p.flatMap((h,m)=>h.from===l||h.to===l?[`relations.${m}`]:[])],op:()=>{const h=p.filter(m=>m.from!==l&&m.to!==l);return h.length===p.length?[{path:["entities",e.index],remove:!0}]:[{path:["entities"],value:s.filter((m,g)=>g!==e.index)},{path:["relations"],value:h}]}}]}if(e.type==="column"){const i=s[e.entity],l=i!==void 0?Kn(Zo(i,"columns")[e.index]):null;if(l===null)return[];const d=["entities",e.entity,"columns",e.index];return[...sX.map(u=>({label:u.label,checked:l[u.key]===!0,op:()=>[{path:[...d],value:wn(l,u.key,l[u.key]===!0?void 0:!0)}]})),vs,{label:"Rename",shortcut:"⏎",action:{type:"edit",path:d.join("."),field:"name"}},{label:"Delete column",shortcut:"⌫",danger:!0,fades:[d.join(".")],op:()=>[{path:[...d],remove:!0}]}]}if(e.type==="edge")return CC(e.index,t,n);const o=[{label:"Add entity",op:()=>[{path:["entities",s.length],value:{name:rX(s),columns:[{name:"id",type:"uuid",pk:!0}]}}],then:{select:`entities.${s.length}`,edit:"name"}}],r=AC(t);return r!==null&&o.push(r),o.push(vs,Sd()),o}function rX(e){const t=new Set(e.map(o=>String(o.name??"")));let n=e.length+1,s=`Entity${n}`;for(;t.has(s);)n+=1,s=`Entity${n}`;return s}const iX={glossary:{noun:"term",axis:"y",field:"term",min:0},faq:{noun:"question",axis:"y",field:"q",min:1},steps:{noun:"step",axis:"y",field:"title",min:1},list:{noun:"item",axis:"y",field:"lead",min:1},takeaways:{noun:"takeaway",axis:"y",field:"text",min:2,max:6},agenda:{noun:"item",axis:"y",field:"title",min:0},team:{noun:"member",axis:"y",field:"name",min:1},stats:{noun:"stat",axis:"x",field:"label",min:0},saga:{noun:"step",axis:"x",field:"name",min:1}};function aX(e,t,n){const s=iX[t.kind];if(s===void 0)return[];const o=Zo(t.data,n);if(e.type!=="item")return lX(t,n,s,o);const r=e.index,i=Kn(o[r]);if(i===null)return[];const l=o.length,d=s.max!==void 0&&l>=s.max,u=()=>kC(t.kind,o)??{},p=m=>m>=l?[{path:[n,l],value:u()}]:[{path:[n],value:[...o.slice(0,m),u(),...o.slice(m)]}],h=dX(r,i,t,n,o);return[...h,...h.length>0?[vs]:[],{label:s.axis==="x"?"Move left":"Move up",shortcut:s.axis==="x"?"⌥←":"⌥↑",disabled:r===0,op:()=>LS(n,o,r,r-1),then:{select:`${n}.${r-1}`}},{label:s.axis==="x"?"Move right":"Move down",shortcut:s.axis==="x"?"⌥→":"⌥↓",disabled:r>=l-1,op:()=>LS(n,o,r,r+2),then:{select:`${n}.${r+1}`}},{label:"Duplicate",disabled:d,op:()=>r===l-1?[{path:[n,l],value:j0(i,o)}]:[{path:[n],value:[...o.slice(0,r+1),j0(i,o),...o.slice(r+1)]}],then:{select:`${n}.${r+1}`}},{label:"Insert before",disabled:d,op:()=>p(r),then:{select:`${n}.${r}`,edit:s.field}},{label:"Insert after",disabled:d,op:()=>p(r+1),then:{select:`${n}.${r+1}`,edit:s.field}},vs,{label:"Delete",shortcut:"⌫",danger:!0,disabled:l<=s.min,fades:[`${n}.${r}`],op:()=>cX(t,n,o,r)}]}function lX(e,t,n,s){return[{label:`Add ${n.noun}`,disabled:n.max!==void 0&&s.length>=n.max,op:()=>[{path:[t,s.length],value:kC(e.kind,s)??{}}],then:{select:`${t}.${s.length}`,edit:n.field}},vs,Sd()]}function LS(e,t,n,s){const o=Vr(t,n,s);return o===null?[]:[{path:[e],value:o}]}function cX(e,t,n,s){const o=Kn(e.data);if(e.kind==="saga"&&o!==null&&o.failAt===Kn(n[s])?.id){const r=wn(o,"failAt",void 0);return[{path:[],value:{...r,[t]:n.filter((i,l)=>l!==s)}}]}return[{path:[t,s],remove:!0}]}function dX(e,t,n,s,o){return n.kind==="saga"?fX(e,t,n,s,o):n.kind==="stats"?[mX(e,t,s)]:[]}const uX=["ok","failed","skipped","compensated"];function pX(e,t,n){const s=Kn(t[n])?.status;if(typeof s=="string")return s;const o=Kn(e.data)?.failAt,r=o!==void 0?t.findIndex(i=>Kn(i)?.id===o):t.findIndex(i=>Kn(i)?.status==="failed");return r<0?"ok":n<r?"compensated":n===r?"failed":"skipped"}function fX(e,t,n,s,o){const r=typeof t.id=="string"?t.id:"",i=r!==""&&Kn(n.data)?.failAt===r,l=pX(n,o,e),d=[i?{label:"Clear failure point",checked:!0,op:()=>[{path:["failAt"],remove:!0}]}:{label:"Set as failure point",checked:!1,disabled:r==="",op:()=>r===""?[]:[{path:["failAt"],value:r}]},{label:"Status",children:uX.map(u=>({label:dl(u),checked:l===u,op:()=>[{path:[s,e],value:wn(t,"status",u)}]}))}];return typeof t.compensate=="string"&&d.push({label:"Remove compensation",op:()=>[{path:[s,e],value:wn(t,"compensate",void 0)}]}),d}const hX=["up","down","flat"];function mX(e,t,n){const s=t.trend;return{label:"Trend",children:[...hX.map(o=>({label:dl(o),checked:s===o,op:()=>[{path:[n,e],value:wn(t,"trend",o)}]})),{label:"None",checked:s===void 0,op:()=>[{path:[n,e],value:wn(t,"trend",void 0)}]}]}}function zn(e){return{width:e,height:e,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0}}function gX({size:e=14}){return w.jsxs("svg",{...zn(e),stroke:"none",fill:"currentColor",children:[w.jsx("circle",{cx:"5.5",cy:"3.5",r:"1.25"}),w.jsx("circle",{cx:"10.5",cy:"3.5",r:"1.25"}),w.jsx("circle",{cx:"5.5",cy:"8",r:"1.25"}),w.jsx("circle",{cx:"10.5",cy:"8",r:"1.25"}),w.jsx("circle",{cx:"5.5",cy:"12.5",r:"1.25"}),w.jsx("circle",{cx:"10.5",cy:"12.5",r:"1.25"})]})}function IS({size:e=14}){return w.jsxs("svg",{...zn(e),children:[w.jsx("rect",{x:"2",y:"2",width:"5",height:"5",rx:"1"}),w.jsx("rect",{x:"9",y:"2",width:"5",height:"5",rx:"1"}),w.jsx("rect",{x:"2",y:"9",width:"5",height:"5",rx:"1"}),w.jsx("rect",{x:"9",y:"9",width:"5",height:"5",rx:"1"})]})}function P0({size:e=14}){return w.jsxs("svg",{...zn(e),children:[w.jsx("path",{d:"M9.8 3.1 12.9 6.2 6.2 12.9 2.8 13.2 3.1 9.8Z"}),w.jsx("path",{d:"M8.6 4.3l3.1 3.1"})]})}function vX({size:e=14}){return w.jsxs("svg",{...zn(e),children:[w.jsx("path",{d:"M11.6 1.9a1.6 1.6 0 0 1 2.3 2.3L5.6 12.5l-3 .7.7-3Z"}),w.jsx("path",{d:"M10.2 3.3 12.5 5.6"}),w.jsx("path",{d:"M2 14.4h12"})]})}function TC({size:e=14}){return w.jsxs("svg",{...zn(e),children:[w.jsx("rect",{x:"5.5",y:"5.5",width:"8",height:"8",rx:"1.5"}),w.jsx("path",{d:"M10.5 3.5v-1a1 1 0 0 0-1-1h-6a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h1"})]})}function yX({size:e=14}){return w.jsxs("svg",{...zn(e),children:[w.jsx("path",{d:"M8 13V3"}),w.jsx("path",{d:"M3.8 7.2 8 3l4.2 4.2"})]})}function xX({size:e=14}){return w.jsxs("svg",{...zn(e),children:[w.jsx("path",{d:"M8 3v10"}),w.jsx("path",{d:"M3.8 8.8 8 13l4.2-4.2"})]})}function vx({size:e=14}){return w.jsxs("svg",{...zn(e),children:[w.jsx("path",{d:"M2.5 4h11"}),w.jsx("path",{d:"M5.5 4V2.8a1 1 0 0 1 1-1h3a1 1 0 0 1 1 1V4"}),w.jsx("path",{d:"M4 4l.7 9a1 1 0 0 0 1 .9h4.6a1 1 0 0 0 1-.9L12 4"}),w.jsx("path",{d:"M6.6 7v4M9.4 7v4"})]})}function dd({size:e=14}){return w.jsx("svg",{...zn(e),children:w.jsx("path",{d:"M8 3.2v9.6M3.2 8h9.6"})})}function Of({size:e=14}){return w.jsxs("svg",{...zn(e),children:[w.jsx("circle",{cx:"7",cy:"7",r:"4.4"}),w.jsx("path",{d:"m10.4 10.4 3.1 3.1"})]})}function Rf({size:e=14}){return w.jsx("svg",{...zn(e),children:w.jsx("path",{d:"m4 4 8 8M12 4l-8 8"})})}function kX({size:e=14}){return w.jsx("svg",{...zn(e),children:w.jsx("path",{d:"m4 6.2 4 4 4-4"})})}function _C({size:e=14}){return w.jsx("svg",{...zn(e),children:w.jsx("path",{d:"m3 8.6 3.3 3.4L13 4.6"})})}function Df({size:e=14}){return w.jsxs("svg",{...zn(e),children:[w.jsx("path",{d:"M4 1.8h5.2L12 4.6V14.2H4Z"}),w.jsx("path",{d:"M9 1.8v3h3"}),w.jsx("path",{d:"M6 8h4M6 10.5h4"})]})}function yx({size:e=14}){return w.jsxs("svg",{...zn(e),children:[w.jsx("rect",{x:"2.3",y:"2.3",width:"4.9",height:"4.9",rx:"1.1"}),w.jsx("rect",{x:"8.8",y:"2.3",width:"4.9",height:"4.9",rx:"1.1"}),w.jsx("rect",{x:"2.3",y:"8.8",width:"4.9",height:"4.9",rx:"1.1"}),w.jsx("rect",{x:"8.8",y:"8.8",width:"4.9",height:"4.9",rx:"1.1"})]})}function LC({size:e=14}){return w.jsxs("svg",{...zn(e),children:[w.jsx("path",{d:"M8 2.5v7"}),w.jsx("path",{d:"M5.2 6.9 8 9.7l2.8-2.8"}),w.jsx("path",{d:"M2.8 10.5v1.8a1.2 1.2 0 0 0 1.2 1.2h8a1.2 1.2 0 0 0 1.2-1.2v-1.8"})]})}const jS={navy:"#0e54a1",blue:"#2563eb",teal:"#0f766e",green:"#1f9747",amber:"#b45309",purple:"#7c3aed",red:"#b91c1c",gray:"#6b7280"};function bX(e){const t=uM[e];return jS[e]??(t!==void 0?jS[t]:void 0)??"#999"}const wX=[{hex:"#0e54a1",name:"navy"},{hex:"#1a6dbe",name:"blue"},{hex:"#0369a1",name:"sky"},{hex:"#0891b2",name:"cyan"},{hex:"#0f766e",name:"teal"},{hex:"#1f9747",name:"green"},{hex:"#f7952c",name:"orange"},{hex:"#b45309",name:"amber"},{hex:"#991b1b",name:"red"},{hex:"#7c3aed",name:"violet"},{hex:"#6b21a8",name:"purple"},{hex:"#4338ca",name:"indigo"},{hex:"#475569",name:"slate"},{hex:"#6b7280",name:"gray"}],O0=/^#[0-9a-f]{3,8}$/i;function IC(e){return e==null?"":typeof e=="string"?e:String(e)}function $X(e){if(!O0.test(e))return null;const t=e.slice(1);if(t.length===3||t.length===4){const[n,s,o]=[t[0]??"",t[1]??"",t[2]??""];return`#${n}${n}${s}${s}${o}${o}`.toLowerCase()}return`#${t.slice(0,6)}`.toLowerCase()}function SX({node:e,value:t,optional:n,multiline:s,autoFocus:o,handlers:r}){const i=IC(t),[l,d]=oe.useState(i),[u,p]=oe.useState(!1);oe.useEffect(()=>d(i),[i]);const h=g=>{if(l!==i)if(l===""&&n&&r.onDelete!==void 0)r.onDelete();else{const v=nC(l,t,e);if(!v.ok){p(!0);return}r.onCommit(v.value)}g&&r.onDone?.()},m=g=>{d(g),p(!1),r.onStage?.(g)};return s?w.jsx("textarea",{className:"stu-input stu-input-area",value:l,autoFocus:o,rows:3,spellCheck:!1,onChange:g=>m(g.target.value),onBlur:()=>h(!1),onKeyDown:g=>{(g.metaKey||g.ctrlKey)&&g.key==="Enter"&&h(!1)}}):w.jsx("input",{className:`stu-input ${u?"stu-input-invalid":""}`,type:"text",value:l,autoFocus:o,spellCheck:!1,onChange:g=>m(g.target.value),onBlur:()=>h(!1),onKeyDown:g=>{g.key==="Enter"&&(g.preventDefault(),h(!0))}})}function EX({value:e,optional:t,autoFocus:n,handlers:s}){const o=typeof e=="number"?String(e):"",[r,i]=oe.useState(o);oe.useEffect(()=>i(o),[o]);const l=u=>{if(r!==o)if(r.trim()===""&&t&&s.onDelete!==void 0)s.onDelete();else{const p=Number(r);Number.isFinite(p)&&r.trim()!==""&&s.onCommit(p)}u&&s.onDone?.()},d=u=>{const p=r.trim()!==""&&Number.isFinite(Number(r))?Number(r):0;s.onCommit(p+u)};return w.jsxs("div",{className:"stu-stepper",children:[w.jsx("button",{type:"button",className:"stu-step-btn","aria-label":"Decrement",tabIndex:-1,onClick:()=>d(-1),children:"−"}),w.jsx("input",{className:"stu-input stu-input-num",type:"text",inputMode:"decimal",value:r,autoFocus:n,onChange:u=>{i(u.target.value);const p=Number(u.target.value);Number.isFinite(p)&&u.target.value.trim()!==""&&s.onStage?.(p)},onBlur:()=>l(!1),onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),l(!0)),(u.key==="ArrowUp"||u.key==="ArrowDown")&&(u.preventDefault(),d(u.key==="ArrowUp"?1:-1))}}),w.jsx("button",{type:"button",className:"stu-step-btn","aria-label":"Increment",tabIndex:-1,onClick:()=>d(1),children:"+"})]})}function MX({value:e,handlers:t}){const n=e===!0;return w.jsxs("label",{className:"stu-toggle",children:[w.jsx("input",{type:"checkbox",checked:n,onChange:s=>t.onCommit(s.target.checked)}),w.jsx("span",{className:"stu-switch","aria-hidden":"true"}),w.jsx("span",{className:"stu-toggle-label",children:n?"yes":"no"})]})}function AX({value:e,options:t,optional:n,handlers:s}){const o=typeof e=="string"?e:"";return w.jsxs("div",{className:"stu-swatches",role:"radiogroup",children:[t.map(r=>w.jsx("button",{type:"button",role:"radio","aria-checked":o===r,className:`stu-swatch ${o===r?"stu-swatch-active":""}`,style:{background:bX(r)},title:r,tabIndex:-1,onClick:()=>s.onCommit(r)},r)),n&&o!==""&&w.jsx("button",{type:"button",className:"stu-swatch-clear",title:"Unset",tabIndex:-1,onClick:()=>s.onDelete?.(),children:"×"})]})}function CX({value:e,optional:t,handlers:n}){const s=IC(e),[o,r]=oe.useState(s),[i,l]=oe.useState(!1);oe.useEffect(()=>r(s),[s]);const d=(p,h=!1)=>{if(p===s){h&&n.onDone?.();return}if(p===""&&t&&n.onDelete!==void 0)n.onDelete();else if(O0.test(p))n.onCommit(p.toLowerCase());else{l(!0);return}h&&n.onDone?.()},u=s.toLowerCase();return w.jsxs("div",{className:"stu-colorctl",children:[w.jsxs("div",{className:"stu-swatches stu-swatches-wrap",role:"radiogroup",children:[wX.map(p=>w.jsx("button",{type:"button",role:"radio","aria-checked":u===p.hex,className:`stu-swatch stu-swatch-sm ${u===p.hex?"stu-swatch-active":""}`,style:{background:p.hex},title:`${p.name} ${p.hex}`,tabIndex:-1,onClick:()=>n.onCommit(p.hex)},p.hex)),t&&s!==""&&w.jsx("button",{type:"button",className:"stu-swatch-clear",title:"Unset",tabIndex:-1,onClick:()=>n.onDelete?.(),children:"×"})]}),w.jsxs("div",{className:"stu-colorrow",children:[w.jsx("input",{type:"color",className:"stu-colorpick","aria-label":"Pick a color",tabIndex:-1,value:$X(o)??"#0e54a1",onChange:p=>{r(p.target.value),l(!1),n.onStage?.(p.target.value)},onBlur:p=>d(p.target.value)}),w.jsx("input",{className:`stu-input stu-colorhex ${i?"stu-input-invalid":""}`,type:"text",value:o,placeholder:"#0e54a1",spellCheck:!1,onChange:p=>{r(p.target.value),l(!1),O0.test(p.target.value)&&n.onStage?.(p.target.value)},onBlur:()=>d(o),onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),d(o,!0))}})]})]})}function PS({value:e,options:t,optional:n,strict:s,autoFocus:o,handlers:r}){const i=typeof e=="string"?e:"",[l,d]=oe.useState(i),[u,p]=oe.useState(!1),[h,m]=oe.useState(0),[g,v]=oe.useState(!1),y=oe.useRef(null);oe.useEffect(()=>d(i),[i]);const b=iY(t,l,i);oe.useEffect(()=>{const T=y.current?.children[h];T instanceof HTMLElement&&T.scrollIntoView({block:"nearest"})},[h,u]);const E=T=>T===i?!0:T===""?n?((r.onDelete??(()=>r.onCommit("")))(),!0):!1:s&&!t.some(N=>N.value===T)?!1:(r.onCommit(T),!0),$=T=>{d(T),E(T),p(!1),r.onDone?.()},A=()=>{const T=b.findIndex(N=>N.value===i);m(T>=0?T:0),p(!0)};return w.jsxs("div",{className:"stu-combo","data-combo-open":u?"true":void 0,children:[w.jsx("input",{className:`stu-input ${g?"stu-input-invalid":""}`,type:"text",role:"combobox","aria-expanded":u,value:l,autoFocus:o,spellCheck:!1,onFocus:A,onChange:T=>{d(T.target.value),v(!1),m(0),p(!0)},onBlur:()=>{E(l)||d(i),p(!1),v(!1)},onKeyDown:T=>{if(T.key==="ArrowDown"||T.key==="ArrowUp"){if(T.preventDefault(),!u){A();return}m(N=>T.key==="ArrowDown"?Math.min(N+1,b.length-1):Math.max(N-1,0));return}if(T.key==="Enter"){T.preventDefault();const N=u?b[h]:void 0;if(N!==void 0)d(N.value),E(N.value),p(!1);else if(E(l))p(!1);else{v(!0);return}r.onDone?.();return}T.key==="Escape"&&u&&(T.preventDefault(),T.stopPropagation(),d(i),p(!1))}}),w.jsx("span",{className:"stu-combo-caret","aria-hidden":"true",children:"▾"}),u&&b.length>0&&w.jsx("ul",{className:"stu-combo-list",role:"listbox",ref:y,children:b.map((T,N)=>w.jsxs("li",{role:"option","aria-selected":N===h,className:`stu-combo-item ${N===h?"stu-combo-item-active":""}`,onMouseEnter:()=>m(N),onMouseDown:j=>{j.preventDefault(),$(T.value)},children:[w.jsx("span",{className:"stu-combo-value",children:T.value}),T.label!==void 0&&w.jsx("span",{className:"stu-combo-label",children:T.label})]},T.value))})]})}function Ja({resolved:e,node:t,value:n,optional:s,autoFocus:o,handlers:r}){switch(e.kind){case"boolean":return w.jsx(MX,{value:n,handlers:r});case"number":return w.jsx(EX,{value:n,optional:s,autoFocus:o,handlers:r});case"enum":return w.jsx(PS,{value:n,options:e.options.map(i=>({value:i})),optional:s,strict:!0,autoFocus:o,handlers:r});case"accent":return w.jsx(AX,{value:n,options:e.options,optional:s,handlers:r});case"color":return w.jsx(CX,{value:n,optional:s,handlers:r});case"options":return w.jsx(PS,{value:n,options:e.options,optional:s,strict:!1,autoFocus:o,handlers:r});case"text":return w.jsx(SX,{node:t,value:n,optional:s,multiline:e.multiline,autoFocus:o,handlers:r});case"opaque":return null}}function Bf(e){return Array.from(e.querySelectorAll("input, textarea, select")).filter(t=>t.tabIndex>=0&&!t.hasAttribute("disabled"))}function zf(e){e.focus(),(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)&&e.select()}const Ep=264;function OS(e){for(let t=e.length-1;t>=0;t--){const n=e[t];if(typeof n=="string")return n}return""}function NX({value:e,onCommit:t}){const n=e===void 0?"":ly(e,{lineWidth:0}).replace(/\n$/,""),[s,o]=oe.useState(n),[r,i]=oe.useState(null),l=()=>{if(s!==n)try{t(ay(s)),i(null)}catch(d){i(d.message.split(`
3253
3253
  `)[0]??"invalid YAML")}};return w.jsxs(w.Fragment,{children:[w.jsx("textarea",{className:"stu-input stu-input-area stu-dx-yaml",value:s,autoFocus:!0,rows:Math.min(8,Math.max(3,n.split(`
3254
- `).length+1)),spellCheck:!1,onChange:d=>{o(d.target.value),i(null)},onBlur:l,onKeyDown:d=>{(d.metaKey||d.ctrlKey)&&d.key==="Enter"&&(d.preventDefault(),l())}}),r!==null&&w.jsx("div",{className:"stu-dx-err",children:r})]})}function NX({host:e,root:t,data:n,path:s,anchor:o,focusField:r,onClose:i,onMovedTo:l,onRemoveItem:d}){const u=oe.useRef(null),[p,h]=oe.useState(null),m=hx(t,s),g=is(n,s),v=tC(s),y=v?s.slice(0,-1):null,b=y!==null?RS(is(n,y)).length:0,E=v?s[s.length-1]:-1;oe.useLayoutEffect(()=>{const P=u.current,I=P?.offsetParent;if(P===null||I===null)return;const O=I.getBoundingClientRect(),C=P.offsetHeight,D=8;let F=o.left;const U=O.width-Ep-4;F>U&&(F=Math.max(0,U));const X=O.left+F;X+Ep>window.innerWidth-D&&(F-=X+Ep-(window.innerWidth-D));let B=o.top+o.height+6;O.top+B+C>window.innerHeight-D&&o.top-C-6>=0&&(B=o.top-C-6),h({left:Math.max(0,F),top:B})},[o.left,o.top,o.height,s.join(".")]),oe.useEffect(()=>{if(p===null)return;const P=u.current;if(P===null||P.contains(document.activeElement))return;((r!==void 0?P.querySelector(`[data-dx-field="${CSS.escape(r)}"]`):P)??P).querySelector("textarea, input, select")?.focus()},[p,r]),oe.useEffect(()=>{const P=I=>{if(I.key==="Escape"){const O=I.target instanceof HTMLElement?I.target:null;if(O!==null&&O.closest('[data-combo-open="true"]')!==null)return;I.stopPropagation(),I.preventDefault(),i()}};return window.addEventListener("keydown",P,!0),()=>window.removeEventListener("keydown",P,!0)},[i]);const $=P=>{const I=u.current;if(I===null)return;const O=P.target;if(P.key==="Tab"){const C=Bf(I);if(C.length===0)return;const D=C.indexOf(O);P.preventDefault();const F=P.shiftKey?C[D<=0?C.length-1:D-1]:C[D<0||D>=C.length-1?0:D+1];zf(F);return}if(P.key==="Enter"){const C=P.metaKey||P.ctrlKey;if(O.tagName==="TEXTAREA"&&!C)return;window.setTimeout(()=>{const D=Bf(I),F=D.indexOf(document.activeElement);F>=0&&F<D.length-1?zf(D[F+1]):i()},0)}};oe.useEffect(()=>{const P=I=>{const O=u.current;O!==null&&I.target instanceof Node&&!O.contains(I.target)&&setTimeout(i,0)};return document.addEventListener("pointerdown",P,!0),()=>document.removeEventListener("pointerdown",P,!0)},[i]);const A=P=>{if(y===null)return;const I=RS(is(n,y)).slice(),O=E+P;if(O<0||O>=I.length)return;const[C]=I.splice(E,1);I.splice(O,0,C),e.commitPath(y,I),l?.([...y,O].join(".")),i()},T=m!==null&&m.kind==="union"?_h(m,g):null,N=m!==null&&m.kind==="object"?m:T!==null&&g!==null&&typeof g=="object"&&!Array.isArray(g)?T:null;let j;if(m!==null&&(m.kind==="string"||m.kind==="number"||m.kind==="boolean"||m.kind==="enum"))j=w.jsx(Ja,{resolved:Za({blockKind:e.kind,name:OS(s),node:m,value:g,data:n,path:s}),node:m,value:g,optional:m.optional,autoFocus:!0,handlers:{onCommit:P=>e.commitPath(s,P),onDelete:()=>e.deletePath(s),onDone:i}});else if(N!==null){const P=TX(g),{visible:I,hidden:O}=eY(N.fields,g,4,r),C=r!==void 0&&I.some(D=>D.name===r)?r:I[0]?.name;j=w.jsxs("div",{className:"stu-dx-fields",children:[I.map(D=>w.jsxs("div",{className:"stu-dx-field","data-dx-field":D.name,children:[w.jsx("label",{className:"stu-dx-label",children:$o(D.name)}),w.jsx(Ja,{resolved:Za({blockKind:e.kind,name:D.name,node:D.node,value:P[D.name],data:n,path:[...s,D.name]}),node:D.node,value:P[D.name],optional:D.node.optional,autoFocus:D.name===C,handlers:{onCommit:F=>e.commitPath([...s,D.name],F),onDelete:()=>e.deletePath([...s,D.name])}})]},D.name)),O>0&&w.jsx("button",{type:"button",className:"stu-linkbtn stu-dx-more",tabIndex:-1,onClick:()=>{i(),e.openFull()},children:"More fields in the editor…"})]})}else if(g==null||typeof g!="object"){const P=m!==null&&m.kind!=="array"?m:null;j=w.jsx(Ja,{resolved:Za({blockKind:e.kind,name:OS(s),node:P,value:g,data:n,path:s}),node:P,value:g,optional:P?.optional??!0,autoFocus:!0,handlers:{onCommit:I=>e.commitPath(s,I),onDone:i}})}else j=w.jsxs(w.Fragment,{children:[w.jsx(CX,{value:g,onCommit:P=>e.commitPath(s,P)}),w.jsx("button",{type:"button",className:"stu-linkbtn stu-dx-more",onClick:()=>{i(),e.openFull()},children:"Edit block YAML"})]});return w.jsxs("div",{ref:u,className:"stu-dx-pop",role:"dialog","aria-label":`Edit ${Pr(s)}`,style:{width:Ep,left:p?.left??o.left,top:p?.top??o.top+o.height+6,visibility:p===null?"hidden":"visible"},onClick:P=>P.stopPropagation(),onPointerMove:P=>P.stopPropagation(),onKeyDown:$,children:[w.jsxs("div",{className:"stu-dx-pop-head",children:[w.jsx("span",{className:"stu-dx-pop-title",children:Pr(s)}),v&&w.jsxs("span",{className:"stu-dx-pop-tools",children:[w.jsx("button",{type:"button","aria-label":"Move up",tabIndex:-1,disabled:E<=0,onClick:()=>A(-1),children:"↑"}),w.jsx("button",{type:"button","aria-label":"Move down",tabIndex:-1,disabled:E>=b-1,onClick:()=>A(1),children:"↓"}),w.jsx("button",{type:"button",className:"stu-dx-remove-btn","aria-label":"Remove item",tabIndex:-1,onClick:()=>{d!==void 0?d():e.deletePath(s),i()},children:w.jsx(vx,{size:12})})]})]}),j]})}function TX(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:{}}function RS(e){return Array.isArray(e)?e:[]}const DS={ghost:null,drop:null,snap:null};function Xp(e,t){const n=e.getBoundingClientRect(),s=t.getBoundingClientRect();return{left:n.left-s.left,top:n.top-s.top,width:n.width,height:n.height}}function qi(e,t){return e.querySelector(`[data-bp="${CSS.escape(t)}"]`)}function Va(e,t,n){const s=[];for(let o=0;o<n;o++){const r=qi(e,`${t}.${o}`);if(r===null)return null;s.push(Xp(r,e))}return s}function Ts(e,t){const n=is(e,Dn(t));return Array.isArray(n)?n:null}function Nn(e,t){const n=e.getAttribute(t);if(n===null)return null;const s=Number(n);return Number.isFinite(s)?s:null}function Ao(e){const t=Nn(e,"data-cell-w"),n=Nn(e,"data-cell-h"),s=Nn(e,"data-gap-x"),o=Nn(e,"data-gap-y"),r=Nn(e,"data-pad-x"),i=Nn(e,"data-pad-top"),l=Nn(e,"data-cols"),d=Nn(e,"data-rows");if(t===null||n===null||s===null||o===null||r===null||i===null||l===null||d===null)return null;const u=e.viewBox.baseVal.width,p=e.getBoundingClientRect().width;return u<=0||p<=0?null:{cellW:t,cellH:n,gapX:s,gapY:o,padX:r,padTop:i,cols:l,rows:d,scale:p/u}}function xx(e,t,n){const s=[];for(let o=0;o<n;o++){const r=qi(e,`${t}.${o}`);if(r===null)return null;const i=Nn(r,"data-col"),l=Nn(r,"data-row");if(i===null||l===null)return null;s.push({col:i,row:l})}return s}function _X(e){const t=(e.textContent??"").replace(/\s+/g," ").trim();return t.length>42?`${t.slice(0,41)}…`:t}function kx(e,t,n){const s=Tf(t,n);if(s===null)return null;if(s.mode==="grid-node"||s.mode==="grid-group"){const o=s.mode==="grid-node"?`${s.listPath}.${s.index}`:`groups.${s.index}`,i=qi(e,o)?.closest("svg");if(i==null||!i.hasAttribute("data-grid"))return null}return s}function LX(e){const{host:t,data:n,html:s,wrapperRef:o,editorOpenRef:r,suppressClickRef:i,dragActiveRef:l,onDragStart:d,onDrop:u}=e,[p,h]=oe.useState(DS),m=oe.useRef(null),g=oe.useRef({host:t,data:n,onDragStart:d,onDrop:u});return g.current={host:t,data:n,onDragStart:d,onDrop:u},oe.useEffect(()=>{const v=o.current;if(v===null)return;const y=()=>{const P=m.current;m.current=null,l.current=!1,P!==null&&P.active&&(document.body.style.userSelect="",v.style.cursor=""),h(DS),window.removeEventListener("pointermove",$),window.removeEventListener("pointerup",T),window.removeEventListener("pointercancel",N),window.removeEventListener("keydown",b,!0)},b=P=>{P.key==="Escape"&&m.current?.active===!0&&(P.preventDefault(),P.stopPropagation(),y())},E=P=>{const I=g.current.data,O=P.target;if(O.mode==="reorder"||O.mode==="table-cols"){const B=O.mode==="table-cols"?"columns":O.listPath,te=Ts(I,B);if(te===null||te.length<2)return null;const ee=Va(v,B,te.length);if(ee===null)return null;const H=O.mode==="table-cols"?"x":ux(ee);return{kind:"reorder",compound:O.mode==="table-cols",listPath:B,index:O.index,axis:H,boxes:ee,centers:oS(ee,H),gap:null}}if(O.mode==="kanban-card"){const B=Ts(I,"columns");if(B===null||B.length===0)return null;const te=Va(v,"columns",B.length);if(te===null)return null;const ee=B.map((H,W)=>{const K=Array.isArray(H?.cards)?H.cards:[];return Va(v,`columns.${W}.cards`,K.length)??[]});return{kind:"kanban-card",col:O.col,index:O.index,colBoxes:te,cardBoxes:ee,to:null}}if(O.mode==="grid-group"){const B=P.itemEl.closest("svg");if(B===null||!B.hasAttribute("data-grid"))return null;const te=Ao(B);if(te===null)return null;const ee=Ji(I,O.index);if(ee===null)return null;const H=Xp(B,v),W=v.getBoundingClientRect(),K=wo(te,P.startX-W.left-H.left,P.startY-W.top-H.top);return{kind:"grid-group",index:O.index,geom:te,svgBox:H,range:ee,startCell:K,target:null}}if(O.mode==="ring"){const B=Ts(I,O.listPath);if(B===null||B.length<2)return null;const te=Va(v,O.listPath,B.length);return te===null?null:{kind:"ring",listPath:O.listPath,index:O.index,centers:te.map(ee=>({x:ee.left+ee.width/2,y:ee.top+ee.height/2})),gap:null}}const C=P.itemEl.closest("svg");if(C===null||!C.hasAttribute("data-grid"))return null;const D=Ao(C);if(D===null)return null;const F=$n(g.current.host.kind),U=Ts(I,O.listPath);if(U===null)return null;const X=xx(v,O.listPath,U.length);return X===null?null:{kind:"grid-node",listPath:O.listPath,index:O.index,geom:D,svgBox:Xp(C,v),placements:X,quick:C.hasAttribute("data-grid-auto"),w:Nn(P.itemEl,"data-w")??1,growRows:F?.growRows!==!1,writeCell:F?.writeCell??ix,cell:null}},$=P=>{const I=m.current;if(I===null||P.pointerId!==I.pointerId)return;if(!I.active){if(!Ch(P.clientX-I.startX,P.clientY-I.startY))return;const ee=E(I);if(ee===null){m.current=null;return}I.ctx=ee,I.active=!0,I.startBox=Xp(I.itemEl,v),I.label=_X(I.itemEl),l.current=!0,i.current=!0,document.body.style.userSelect="none",v.style.cursor="grabbing",g.current.onDragStart()}const O=v.getBoundingClientRect(),C=P.clientX-O.left,D=P.clientY-O.top,F={box:{left:I.startBox.left+(P.clientX-I.startX),top:I.startBox.top+(P.clientY-I.startY),width:I.startBox.width,height:I.startBox.height},label:I.label},U=I.ctx;if(U.kind==="ring"){if(U.gap=AG(U.centers,C,D),U.gap===null)return;const ee=CG(U.centers,U.gap);h({ghost:F,drop:{left:ee.x-5,top:ee.y-5,width:10,height:10},snap:null});return}if(U.kind==="grid-group"){const ee=wo(U.geom,C-U.svgBox.left,D-U.svgBox.top),H=$C(U.range,ee.col-U.startCell.col,ee.row-U.startCell.row,U.geom.cols,U.geom.rows);U.target=H;const W=gx(U.geom,H);h({ghost:F,drop:null,snap:{left:U.svgBox.left+W.left,top:U.svgBox.top+W.top,width:W.width,height:W.height}});return}if(U.kind==="reorder"){const ee=U.axis==="x"?C:D;U.gap=rS(U.centers,ee);const H=iS(U.boxes,U.axis,U.gap),W=Math.min(...U.boxes.map(z=>U.axis==="x"?z.top:z.left))-4,K=Math.max(...U.boxes.map(z=>U.axis==="x"?z.top+z.height:z.left+z.width))+4,R=U.axis==="x"?{left:H-1.5,top:W,width:3,height:K-W}:{left:W,top:H-1.5,width:K-W,height:3};h({ghost:F,drop:R,snap:null});return}if(U.kind==="kanban-card"){let ee=U.colBoxes.findIndex(Y=>C>=Y.left&&C<=Y.left+Y.width);if(ee<0){let Y=1/0;U.colBoxes.forEach((V,re)=>{const Q=Math.abs(C-(V.left+V.width/2));Q<Y&&(Y=Q,ee=re)})}const H=U.cardBoxes[ee]??[],W=rS(oS(H,"y"),D);U.to={col:ee,gap:W};const K=U.colBoxes[ee],R=H.length>0?iS(H,"y",W):K.top+Math.min(38,K.height-8),z={left:K.left+6,top:R-1.5,width:K.width-12,height:3};h({ghost:F,drop:z,snap:null});return}const X=wo(U.geom,C-U.svgBox.left,D-U.svgBox.top),B=U.growRows?X:{col:X.col,row:Math.min(X.row,U.geom.rows)};U.cell=B;const te=_f(U.geom,B.col,B.row,U.w);h({ghost:F,drop:null,snap:{left:U.svgBox.left+te.left,top:U.svgBox.top+te.top,width:te.width,height:te.height}})},A=P=>{const{host:I,data:O}=g.current,C=P.ctx;if(C===null)return null;if(C.kind==="reorder"){if(C.gap===null)return null;if(C.compound){const X=YA(O,C.index,C.gap);return X===null?null:(I.commitPaths(X),Wv("columns",C.index,C.gap))}const F=Ts(O,C.listPath);if(F===null)return null;const U=Vr(F,C.index,C.gap);return U===null?null:(I.commitPath([C.listPath],U),Wv(C.listPath,C.index,C.gap))}if(C.kind==="kanban-card"){if(C.to===null)return null;const F=_0(O,C.col,C.index,C.to.col,C.to.gap);return F===null?null:(I.commitPaths(F),BG({fromCol:C.col,fromIdx:C.index,toCol:C.to.col,gap:C.to.gap,targetLen:(C.cardBoxes[C.to.col]??[]).length}))}if(C.kind==="grid-group"){if(C.target===null)return null;const F=EC(O,C.index,C.target);return F===null?null:(I.commitPaths(F),`groups.${C.index}`)}if(C.kind==="ring"){if(C.gap===null)return null;const F=Ts(O,C.listPath);if(F===null)return null;const U=Vr(F,C.index,C.gap);return U===null?null:(I.commitPath([C.listPath],U),Wv(C.listPath,C.index,C.gap))}if(C.cell===null)return null;const D=XA({placements:C.placements,index:C.index,target:C.cell,quick:C.quick,field:C.listPath,writeCell:C.writeCell});return D===null?null:(I.commitPaths(D.sets),D.materialized&&I.notify?.(px),`${C.listPath}.${C.index}`)},T=P=>{const I=m.current;if(!(I===null||P.pointerId!==I.pointerId)){if(I.active){const O=A(I);O!==null&&g.current.onDrop?.(O)}y()}},N=()=>y(),j=P=>{if(P.button!==0||m.current!==null||(i.current=!1,r.current)||!(P.target instanceof Element)||P.target.closest(".stu-dx-overlay")!==null)return;const I=P.target.closest("[data-bp]");if(I===null||!v.contains(I))return;const O=I.getAttribute("data-bp")??"",C=kx(v,t.kind,O);if(C===null)return;const D=C.mode==="table-cols"?`columns.${C.index}`:C.mode==="kanban-card"?`columns.${C.col}.cards.${C.index}`:C.mode==="grid-group"?`groups.${C.index}`:`${C.listPath}.${C.index}`,F=qi(v,D);F!==null&&(m.current={pointerId:P.pointerId,startX:P.clientX,startY:P.clientY,path:O,target:C,itemEl:F,active:!1,startBox:{left:0,top:0,width:0,height:0},label:"",ctx:null},window.addEventListener("pointermove",$),window.addEventListener("pointerup",T),window.addEventListener("pointercancel",N),window.addEventListener("keydown",b,!0))};return v.addEventListener("pointerdown",j),()=>{v.removeEventListener("pointerdown",j),y()}},[o,t.kind,s]),p}function R0(e){const{wrap:t,host:n,data:s,path:o,key:r}=e,i=kx(t,n.kind,o);if(i===null)return null;const l=r==="ArrowLeft"||r==="ArrowUp"?-1:1,d=r==="ArrowLeft"||r==="ArrowRight";if(i.mode==="reorder"||i.mode==="table-cols"){const A=i.mode==="table-cols"?"columns":i.listPath,T=Ts(s,A);if(T===null)return null;const N=Va(t,A,T.length);if(N===null||(i.mode==="table-cols"?"x":ux(N))==="x"!==d)return null;const P=l<0?i.index-1:i.index+2;if(i.mode==="table-cols"){const O=YA(s,i.index,P);return O===null?null:(n.commitPaths(O),`columns.${i.index+l}`)}const I=Vr(T,i.index,P);return I===null?null:(n.commitPath([A],I),`${A}.${i.index+l}`)}if(i.mode==="kanban-card"){if(!d){const O=l<0?i.index-1:i.index+2,C=_0(s,i.col,i.index,i.col,O);return C===null?null:(n.commitPaths(C),`columns.${i.col}.cards.${i.index+l}`)}const A=Ts(s,"columns"),T=i.col+l;if(A===null||T<0||T>=A.length)return null;const N=A[T]?.cards,j=Array.isArray(N)?N.length:0,P=Math.min(i.index,j),I=_0(s,i.col,i.index,T,P);return I===null?null:(n.commitPaths(I),`columns.${T}.cards.${P}`)}if(i.mode==="grid-group"){const T=qi(t,`groups.${i.index}`)?.closest("svg");if(T==null)return null;const N=Ao(T),j=N!==null?Ji(s,i.index):null;if(N===null||j===null)return null;const P=$C(j,d?l:0,d?0:l,N.cols,N.rows),I=EC(s,i.index,P);return I===null?null:(n.commitPaths(I),o)}if(i.mode==="ring"){const A=Ts(s,i.listPath);if(A===null)return null;const T=l<0?i.index-1:i.index+2,N=Vr(A,i.index,T);return N===null?null:(n.commitPath([i.listPath],N),`${i.listPath}.${i.index+l}`)}const u=$n(n.kind),h=qi(t,`${i.listPath}.${i.index}`)?.closest("svg");if(h==null)return null;const m=Ao(h),g=Ts(s,i.listPath);if(m===null||g===null)return null;const v=xx(t,i.listPath,g.length);if(v===null)return null;const y=v[i.index];if(y===void 0)return null;const b=u?.growRows===!1?m.rows:m.rows+1,E={col:Math.max(1,Math.min(m.cols+1,y.col+(d?l:0))),row:Math.max(1,Math.min(b,y.row+(d?0:l)))},$=XA({placements:v,index:i.index,target:E,quick:h.hasAttribute("data-grid-auto"),field:i.listPath,writeCell:u?.writeCell??ix});return $===null?null:(n.commitPaths($.sets),$.materialized&&n.notify?.(px),o)}function IX(e){const{wrap:t,host:n,data:s,path:o,key:r}=e,i=jf(n.kind,o);if(i.kind==="inert")return null;if(i.kind==="grid-group"&&e.grow===!0){const u=qi(t,`groups.${i.index}`)?.closest("svg");if(u==null)return null;const p=Ao(u),h=p!==null?Ji(s,i.index):null;if(p===null||h===null)return null;const v=RY(h,r==="ArrowLeft"||r==="ArrowRight"?"x":"y",r==="ArrowLeft"||r==="ArrowUp"?-1:1,p.cols,p.rows),y=v!==null?SC(s,i.index,v):null;return y===null?null:(n.commitPaths(y),{path:o,moved:!0})}if(i.kind==="table-cell"){const d=Ts(s,"rows");if(d===null)return null;const u=DG({row:i.row,col:i.col,key:r,rowCount:d.length,colsInRow:p=>Array.isArray(d[p])?d[p].length:0});return u===null?null:{path:`rows.${u.row}.${u.col}`,moved:!1}}if(i.kind==="grid"&&`${i.listPath}.${i.index}`!==o)return R0({wrap:t,host:n,data:s,path:`${i.listPath}.${i.index}`,key:r})===null?null:{path:o,moved:!0};if(i.kind==="item"&&Tf(n.kind,o)===null){const d=Ts(s,i.listPath);if(d===null)return null;const u=Va(t,i.listPath,d.length);if(u===null)return null;const p=RG({axis:ux(u),key:r,index:i.index,length:d.length});if(p===null)return null;const h=Vr(d,i.index,p.gap);return h===null?null:(n.commitPath(Dn(i.listPath),h),{path:`${i.listPath}.${p.newIndex}${i.suffix??""}`,moved:!0})}const l=R0({wrap:t,host:n,data:s,path:o,key:r});return l===null?null:{path:l,moved:!0}}const BS={wire:null,target:null,snap:null,picker:null};function Kv(e,t){const n=e.getBoundingClientRect(),s=t.getBoundingClientRect();return{left:n.left-s.left,top:n.top-s.top,width:n.width,height:n.height}}function Mp(e,t){return e.querySelector(`[data-bp="${CSS.escape(t)}"]`)}function Ec(e,t){const s=(t!==null&&typeof t=="object"?t:{})[e.nodesField];return Array.isArray(s)?s.map(o=>{const r=o!==null&&typeof o=="object"?o[e.idField]:void 0;return typeof r=="string"?r:""}):[]}function jX(e){const{host:t,data:n,html:s,wrapperRef:o,suppressClickRef:r,dragActiveRef:i,onConnectStart:l,onNodeCreated:d,onEdgeCreated:u}=e,p=$n(t.kind),[h,m]=oe.useState(BS),g=oe.useRef(null),v=oe.useRef(null),y=oe.useRef(!1),b=oe.useRef({host:t,data:n,spec:p,onConnectStart:l,onNodeCreated:d,onEdgeCreated:u});b.current={host:t,data:n,spec:p,onConnectStart:l,onNodeCreated:d,onEdgeCreated:u};const E=oe.useRef(()=>{}),$=oe.useRef(()=>{}),A=oe.useRef(null),T=oe.useRef(null);oe.useEffect(()=>{const I=o.current;if(I===null||p===null)return;const O=()=>{v.current=null,y.current=!1,window.removeEventListener("pointerdown",F,!0)},C=()=>{const Y=g.current;g.current=null,i.current=!1,Y!==null&&Y.active&&(document.body.style.userSelect="",I.style.cursor=""),O(),m(BS),window.removeEventListener("pointermove",H),window.removeEventListener("pointerup",W),window.removeEventListener("pointercancel",K),window.removeEventListener("keydown",D,!0)};E.current=C;const D=Y=>{Y.key==="Escape"&&g.current?.active===!0&&(Y.preventDefault(),Y.stopPropagation(),C())},F=Y=>{Y.target instanceof Element&&Y.target.closest(".stu-dx-connect-picker")!==null||(r.current=!0,C())},U=Y=>Array.from({length:Y},(V,re)=>{const Q=Mp(I,`${p.nodesField}.${re}`);return Q===null?null:Kv(Q,I)}),X=(Y,V)=>Y.pointerId===-1||V.pointerId===Y.pointerId,B=Y=>{Y.active=!0,Y.boxes=U(Ec(p,b.current.data).length);const V=Mp(I,`${p.nodesField}.${Y.fromIndex}`)?.closest("svg")??null;if(Y.geom=V!==null?Ao(V):null,Y.svgBox=V!==null?Kv(V,I):null,p.columnTargets===!0&&Y.svgBox!==null){const re=Y.svgBox.top+Y.svgBox.height;Y.boxes=Y.boxes.map(Q=>Q===null?null:{...Q,height:re-Q.top})}i.current=!0,r.current=!0,document.body.style.userSelect="none",I.style.cursor="crosshair",b.current.onConnectStart()},te=()=>{y.current=!0,document.body.style.userSelect="",I.style.cursor="",i.current=!1,window.removeEventListener("pointermove",H),window.removeEventListener("pointerup",W),window.removeEventListener("pointercancel",K),window.removeEventListener("keydown",D,!0),window.addEventListener("pointerdown",F,!0)},ee=(Y,V,re,Q,ne)=>{v.current={mode:"edge",left:Q,top:ne,fromId:Y,toId:V},m({wire:{x1:re.x,y1:re.y,x2:Q,y2:ne},target:null,snap:null,picker:{left:Q,top:ne,title:"Cardinality",items:p.edgeChoices??[]}}),te()},H=Y=>{const V=g.current;if(V===null||!X(V,Y)||v.current!==null)return;if(!V.active){if(!Ch(Y.clientX-V.startX,Y.clientY-V.startY))return;B(V)}const re=I.getBoundingClientRect(),Q=Y.clientX-re.left,ne=Y.clientY-re.top;let Z=null;V.boxes.forEach((de,le)=>{de!==null&&Q>=de.left&&Q<=de.left+de.width&&ne>=de.top&&ne<=de.top+de.height&&(Z=le)}),Z===V.fromIndex&&!p.allowSelfLoop&&(Z=null),V.targetIndex=Z;let q=null;if(Z===null&&V.geom!==null&&V.svgBox!==null&&p.newNode!==void 0){const de=wo(V.geom,Q-V.svgBox.left,ne-V.svgBox.top),le=p.growRows===!1?{col:de.col,row:Math.min(de.row,V.geom.rows)}:de,J=_f(V.geom,le.col,le.row);q={left:V.svgBox.left+J.left,top:V.svgBox.top+J.top,width:J.width,height:J.height}}m({wire:{x1:V.anchor.x,y1:V.anchor.y,x2:Q,y2:ne},target:Z!==null?V.boxes[Z]:null,snap:q,picker:null})},W=Y=>{const V=g.current;if(V===null||!X(V,Y)||v.current!==null)return;if(!V.active){C();return}const{host:re,data:Q}=b.current,ne=I.getBoundingClientRect(),Z=Y.clientX-ne.left,q=Y.clientY-ne.top;if(V.targetIndex!==null){const ue=Ec(p,Q)[V.targetIndex]??"";if(ue===""){C();return}if(p.edgeChoices!==void 0&&p.edgeChoices.length>0){if(Gp(p,Q,V.fromId,ue)===null){re.notify?.(`${no(p,Q,V.fromId)} and ${no(p,Q,ue)} are already connected`),C();return}ee(V.fromId,ue,V.anchor,Z,q);return}const ve=Gp(p,Q,V.fromId,ue);if(ve===null)re.notify?.(`${no(p,Q,V.fromId)} and ${no(p,Q,ue)} are already connected`);else if(re.commitPaths(ve),p.editEdgeOnConnect===!0){const we=ve[0]?.path[1];typeof we=="number"&&b.current.onEdgeCreated?.(`${p.edgesField}.${we}`,p.edgeTextField)}else re.notify?.(`Connected ${no(p,Q,V.fromId)} → ${no(p,Q,ue)}`);C();return}if(V.geom===null||V.svgBox===null||p.newNode===void 0||p.nodeKinds.length===0){C();return}const de=wo(V.geom,Z-V.svgBox.left,q-V.svgBox.top),le=p.growRows===!1?{col:de.col,row:Math.min(de.row,V.geom.rows)}:de,J=_f(V.geom,le.col,le.row);if(p.nodeKinds.length===1){v.current={mode:"node",left:Z,top:q,cell:le,fromId:V.fromId,fromIndex:V.fromIndex},$.current(p.nodeKinds[0].kind);return}v.current={mode:"node",left:Z,top:q,cell:le,fromId:V.fromId,fromIndex:V.fromIndex},m({wire:{x1:V.anchor.x,y1:V.anchor.y,x2:Z,y2:q},target:null,snap:{left:V.svgBox.left+J.left,top:V.svgBox.top+J.top,width:J.width,height:J.height},picker:{left:Z,top:q,title:"Add & connect",items:p.nodeKinds.map(ue=>({value:ue.kind,label:ue.label}))}}),te()},K=()=>C(),R=(Y,V,re)=>{if(g.current!==null||v.current!==null)return;const Q=Ec(p,b.current.data)[V]??"";Q!==""&&(r.current=!1,g.current={pointerId:Y.pointerId,startX:Y.clientX,startY:Y.clientY,fromIndex:V,fromId:Q,anchor:re,active:!1,boxes:[],targetIndex:null,geom:null,svgBox:null},window.addEventListener("pointermove",H),window.addEventListener("pointerup",W),window.addEventListener("pointercancel",K),window.addEventListener("keydown",D,!0))};A.current=R;const z=Y=>{if(g.current!==null||v.current!==null)return;const V=Ec(p,b.current.data)[Y]??"",re=Mp(I,`${p.nodesField}.${Y}`);if(V===""||re===null)return;const Q=Kv(re,I),ne={x:Q.left+Q.width/2,y:Q.top+Q.height/2};r.current=!1;const Z={pointerId:-1,startX:0,startY:0,fromIndex:Y,fromId:V,anchor:ne,active:!1,boxes:[],targetIndex:null,geom:null,svgBox:null};g.current=Z,B(Z),m({wire:{x1:ne.x,y1:ne.y,x2:ne.x,y2:ne.y},target:null,snap:null,picker:null}),window.addEventListener("pointermove",H),window.addEventListener("pointerup",W),window.addEventListener("pointercancel",K),window.addEventListener("keydown",D,!0)};return T.current=z,()=>{C(),A.current=null,T.current=null}},[o,t.kind,p,s,i,r]);const N=I=>{const O=o.current,C=v.current;if(O===null||C===null||C.mode!=="node"||p===null)return;const{host:D,data:F,onNodeCreated:U}=b.current,X=Ec(p,F).length;let B=[];for(let W=0;W<X;W++){const K=Mp(O,`${p.nodesField}.${W}`),R=K!==null?Nn(K,"data-col"):null,z=K!==null?Nn(K,"data-row"):null;if(R===null||z===null){B=void 0;break}B.push({col:R,row:z})}const te=Nf(p,F,C.fromId,C.cell,I,B);if(E.current(),te===null)return;D.commitPaths(te.sets),te.materialized&&D.notify?.(px);const ee=p.nodeKinds.find(W=>W.kind===I),H=ee!==void 0?`New ${ee.label.toLowerCase()}`:te.id;D.notify?.(`Connected ${no(p,F,C.fromId)} → ${H}`),U(te.nodePath,p.labelField)};$.current=N;const j=I=>{const O=v.current;if(O===null||O.mode!=="edge"||p===null)return;const{host:C,data:D}=b.current,F=p.edgeChoiceField!==void 0?{[p.edgeChoiceField]:I}:void 0,U=Gp(p,D,O.fromId,O.toId,F);E.current(),U!==null&&(C.commitPaths(U),C.notify?.(`Connected ${no(p,D,O.fromId)} → ${no(p,D,O.toId)} (${I})`))};return{visuals:h,spec:p,start:(I,O,C)=>A.current?.(I.nativeEvent,O,C),armFrom:I=>T.current?.(I),pickerOpenRef:y,cancelPicker:()=>E.current(),choose:I=>{v.current?.mode==="edge"?j(I):N(I)}}}const jC=["rect","diamond","pill","ellipse","cylinder","hexagon","triangle"],Ff=64,D0=250,PC=Ff*4,PX=.8,OX=.7,zS=15*Math.PI/180,RX=2*Math.PI/180,_r=.5*(-1+Math.sqrt(5)),DX=.92,FS=5*Math.PI,BX=20,zX=5,FX=.08,qX=9,qS=.7,OC=.3,RC=5;function Gr(e,t){return Math.hypot(e.x-t.x,e.y-t.y)}function bx(e){let t=0;for(let n=1;n<e.length;n++)t+=Gr(e[n-1],e[n]);return t}function DC(e){let t=0,n=0;for(const s of e)t+=s.x,n+=s.y;return{x:t/e.length,y:n/e.length}}function wx(e){let t=1/0,n=1/0,s=-1/0,o=-1/0;for(const r of e)r.x<t&&(t=r.x),r.y<n&&(n=r.y),r.x>s&&(s=r.x),r.y>o&&(o=r.y);return{minX:t,minY:n,maxX:s,maxY:o}}function $x(e,t){const n=e.map(i=>({x:i.x,y:i.y})),s=bx(n)/(t-1);if(s<=0)return Array.from({length:t},()=>({...n[0]}));let o=0;const r=[{...n[0]}];for(let i=1;i<n.length;i++){const l=n[i-1],d=n[i],u=Gr(l,d);if(o+u>=s&&u>0){const p=(s-o)/u,h={x:l.x+p*(d.x-l.x),y:l.y+p*(d.y-l.y)};r.push(h),n.splice(i,0,h),o=0}else o+=u}for(;r.length<t;)r.push({...n[n.length-1]});return r.slice(0,t)}function HX(e){const t=wx(e),n=D0/Math.max(t.maxX-t.minX,t.maxY-t.minY,1e-6);return e.map(s=>({x:s.x*n,y:s.y*n}))}function WX(e){const t=DC(e);return e.map(n=>({x:n.x-t.x,y:n.y-t.y}))}function UX(e,t){if(t===0)return[...e];const n=DC(e),s=Math.cos(t),o=Math.sin(t);return e.map(r=>({x:(r.x-n.x)*s-(r.y-n.y)*o+n.x,y:(r.x-n.x)*o+(r.y-n.y)*s+n.y}))}function KX(e,t){const n=[];let s=0;for(let l=0;l<e.length;l++){const d=Gr(e[l],t[l]);n.push(d),s+=d}const o=s/e.length;n.sort((l,d)=>d-l);const r=Math.max(1,Math.round(e.length/4));let i=0;for(let l=0;l<r;l++)i+=n[l];return(1-qS)*o+qS*(i/r)}function BC(e,t){return WX($x(HX(e),t))}function VX(e,t=zX){if(e.length<3)return[...e];const n=$x(e,PC),s=Math.floor(t/2);return n.map((o,r)=>{if(r<s||r>=n.length-s)return o;let i=0,l=0;for(let d=r-s;d<=r+s;d++)i+=n[d].x,l+=n[d].y;return{x:i/t,y:l/t}})}function GX(e){let t=0,n=null;for(let s=1;s<e.length;s++){const o=e[s-1],r=e[s];if(Gr(o,r)<1e-6)continue;const i=Math.atan2(r.y-o.y,r.x-o.x);if(n!==null){let l=i-n;for(;l>Math.PI;)l-=2*Math.PI;for(;l<-Math.PI;)l+=2*Math.PI;t+=Math.abs(l)}n=i}return t}function YX(e){if(e.length<4)return[...e];const t=e[0],n=wx(e),s=.12*Math.hypot(n.maxX-n.minX,n.maxY-n.minY),o=bx(e);let r=0,i=-1,l=1/0;for(let d=1;d<e.length;d++){if(r+=Gr(e[d-1],e[d]),r<.6*o)continue;const u=Gr(e[d],t);u<=s&&u<l&&(l=u,i=d)}return i===-1?[...e]:e.slice(0,i+1)}function zC(e){let t=0;for(let n=0;n<e.length;n++){const s=e[n],o=e[(n+1)%e.length];t+=s.x*o.y-o.x*s.y}return t>=0?1:-1}function FC(e){const t=wx(e),n=Math.max(t.maxX-t.minX,1e-6),s=Math.max(t.maxY-t.minY,1e-6);return Math.min(RC,Math.max(OC,n/s))}function Ap(e){return[...e,e[0]]}function Mc(e,t,n,s,o,r,i){const l=[];for(let d=0;d<=i;d++){const u=o+(r-o)*d/i;l.push({x:e+n*Math.cos(u),y:t+s*Math.sin(u)})}return l}function XX(e,t){switch(e){case"rect":return Ap([{x:0,y:0},{x:t,y:0},{x:t,y:1},{x:0,y:1}]);case"diamond":return Ap([{x:t/2,y:0},{x:t,y:1/2},{x:t/2,y:1},{x:0,y:1/2}]);case"hexagon":return Ap([{x:t*.25,y:0},{x:t*.75,y:0},{x:t,y:1/2},{x:t*.75,y:1},{x:t*.25,y:1},{x:0,y:1/2}]);case"triangle":return Ap([{x:t/2,y:0},{x:t,y:1},{x:0,y:1}]);case"ellipse":return Mc(t/2,1/2,t/2,1/2,-Math.PI/2,1.5*Math.PI,96);case"pill":{const s=Math.min(t,1)/2;return t>=1?[{x:s,y:0},{x:t-s,y:0},...Mc(t-s,s,s,s,-Math.PI/2,Math.PI/2,24),{x:s,y:1},...Mc(s,s,s,s,Math.PI/2,1.5*Math.PI,24)]:[...Mc(s,s,s,s,Math.PI,2*Math.PI,24),{x:t,y:1-s},...Mc(s,1-s,s,s,0,Math.PI,24),{x:0,y:s}]}case"cylinder":{const o=[];for(let r=0;r<=24;r++){const i=r/24;o.push({x:i*t,y:.28*(1-Math.sin(Math.PI*i))})}return[...o,{x:t,y:1},{x:0,y:1},{x:0,y:.28}]}}}const HS=new Map,WS=1.25;function QX(e){const t=Math.round(Math.min(RC,Math.max(OC,e))*20)/20,n=HS.get(t);if(n!==void 0)return n;const s=[];for(const o of jC){if(o==="pill"&&t<WS&&t>1/WS)continue;const r=XX(o,t),i=BC(r,PC),l=zC(i);s.push({shape:o,dir:l,pts:i}),s.push({shape:o,dir:l===1?-1:1,pts:[...i].reverse()})}return HS.set(t,s),s}function ZX(e,t){const n=e.pts.length/(Ff-1),s=[];for(let o=0;o<Ff;o++)s.push(e.pts[((t+Math.round(o*n))%e.pts.length+e.pts.length)%e.pts.length]);return s}function JX(e,t){let n=0,s=1/0;for(let o=0;o<e.pts.length;o++){const r=Gr(e.pts[o],t);r<s&&(s=r,n=o)}return n}function eQ(e,t){const n=JX(t,e[0]),s=Math.round(t.pts.length*FX),o=Math.max(1,Math.round(s/qX));let r=1/0;for(let i=-s;i<=s;i+=o){const l=KX(e,ZX(t,n+i));l<r&&(r=l)}return r}function Cp(e,t,n,s){const o=UX(e,s),r=QX(FC(o)).find(i=>i.shape===t&&i.dir===n);return r===void 0?1/0:eQ(BC(o,Ff),r)}function tQ(e,t,n){let s=-zS,o=zS,r=_r*s+(1-_r)*o,i=Cp(e,t,n,r),l=(1-_r)*s+_r*o,d=Cp(e,t,n,l);for(;Math.abs(o-s)>RX;)i<d?(o=l,l=r,d=i,r=_r*s+(1-_r)*o,i=Cp(e,t,n,r)):(s=r,r=l,i=d,l=(1-_r)*s+_r*o,d=Cp(e,t,n,l));return Math.min(i,d)}function nQ(e,t={}){if(e.length<2)return;const n=bx(e);if(n<(t.minLength??12))return;const s=Gr(e[0],e[e.length-1])/n;if(s>=DX)return{shape:"line",score:s};const o=GX($x(e,BX));if(o>=FS)return{shape:"scribble",score:Math.min(1,o/(2*FS))};const r=sQ(e),i=r[0];if(i===void 0||i.score<PX)return;const l=r[1];return l!==void 0&&(1-i.score)/(1-l.score)>OX?{shape:void 0,score:i.score,ambiguous:!0,candidates:[i.shape,l.shape]}:{shape:i.shape,score:i.score}}function sQ(e){const t=VX(YX(e)),n=zC(t),s=FC(t),o=.5*Math.hypot(D0,D0/Math.max(s,1/s));return jC.map(r=>({shape:r,score:1-tQ(t,r,n)/o})).filter(r=>Number.isFinite(r.score)).sort((r,i)=>i.score-r.score)}function B0(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function oQ(e,t){const n=B0(t)?.[e.nodesField];return(Array.isArray(n)?n:[]).map(B0).filter(s=>s!==null)}function qC(e,t,n){return oQ(e,t).some(s=>s.kind===n)}const Vt=e=>()=>({kind:e}),Ra=(e,t)=>(n,s)=>({kind:qC(n,s,e)?t:e}),US=e=>({kind:"end",extra:{[e.labelField]:"Error exit"}}),Sx={flow:{rect:Vt("process"),diamond:Vt("decision"),pill:Ra("start","end"),ellipse:Ra("start","end"),triangle:US},swimlane:{rect:Vt("action"),diamond:Vt("decision"),pill:Ra("start","end"),ellipse:Ra("start","end"),triangle:US},state:{rect:Vt("active"),pill:Ra("start","terminal"),ellipse:Ra("start","terminal")},block:{rect:Vt("service"),diamond:Vt("gateway"),pill:Vt("client"),cylinder:Vt("db"),hexagon:(e,t)=>({kind:qC(e,t,"gateway")?"queue":"gateway"}),triangle:(e,t)=>B0(t)?.preset==="k8s"?{kind:"ingress"}:null},c4:{rect:Vt("container"),ellipse:Vt("person"),cylinder:Vt("store")},dfd:{rect:Vt("process"),ellipse:Vt("external"),cylinder:Vt("store")},felogic:{rect:Vt("component"),cylinder:Vt("db"),hexagon:Vt("queue")},graph:{rect:Vt("node"),diamond:Vt("node"),pill:Vt("node"),ellipse:Vt("node"),cylinder:Vt("node"),hexagon:Vt("node"),triangle:Vt("node")}};function rQ(e){const t=$n(e);return t!==null&&t.gridNodes&&t.newNode!==void 0&&Sx[e]!==void 0}function HC(e,t,n,s,o,r){const i=e.nodeKinds.find(h=>h.kind===s),l=i??e.nodeKinds[0];if(l===void 0)return null;const d=typeof r?.[e.labelField]=="string"?r[e.labelField]:`New ${(i?.label??s).toLowerCase()}`,u={...r??{}};i===void 0&&(u.kind=s,u[e.labelField]=d);const p=dx(e,t,n,l.kind,o,Object.keys(u).length>0?u:void 0);return p===null?null:{...p,label:d}}function iQ(e,t,n,s){const o=[];for(const r of s){const i=Sx[e]?.[r]?.(t,n);i!=null&&!o.includes(i.kind)&&o.push(i.kind)}return o}function aQ(e,t,n,s){const o=$n(t);if(o===null||o.newNode===void 0||!o.gridNodes)return{type:"none",reason:"This block has no grid to draw on"};const r=s.placements??void 0,i=p=>({type:"pick",first:iQ(t,o,s.data,p)});if(e===void 0)return i(s.candidates??[]);if(e==="line"){const p=s.line;if(p===void 0||p.fromId===null)return{type:"none",reason:""};if(p.toId!==null){if(p.toId===p.fromId)return{type:"none",reason:""};const g=Gp(o,s.data,p.fromId,p.toId);return g===null?{type:"none",reason:"Already connected"}:{type:"edge",sets:g,fromId:p.fromId,toId:p.toId}}const h=o.nodeKinds[0];if(h===void 0)return{type:"none",reason:""};const m=Nf(o,s.data,p.fromId,p.endCell,h.kind,r);return m===null?{type:"none",reason:""}:{type:"node",...m,kind:h.kind,label:`New ${h.label.toLowerCase()}`}}if(e==="scribble")return s.under!==void 0&&s.under!==null?{type:"delete",path:s.under}:{type:"none",reason:""};const l=Sx[t]?.[e],d=l===void 0?null:l(o,s.data);if(d===null)return i(s.candidates??[]);const u=HC(o,s.data,n,d.kind,r,d.extra);return u===null?i([e,...s.candidates??[]]):{type:"node",...u,kind:d.kind}}const lQ=160,Da={trail:[],fading:!1,flash:null,picker:null};function KS(e,t){const n=e.getBoundingClientRect(),s=t.getBoundingClientRect();return{left:n.left-s.left,top:n.top-s.top,width:n.width,height:n.height}}function cQ(e,t){return t.x>=e.left&&t.x<=e.left+e.width&&t.y>=e.top&&t.y<=e.top+e.height}function Np(e,t){const s=(t!==null&&typeof t=="object"?t:{})[e.nodesField];return Array.isArray(s)?s.map(o=>{const r=o!==null&&typeof o=="object"?o[e.idField]:void 0;return typeof r=="string"?r:""}):[]}function dQ(e,t){return e.nodeKinds.find(s=>s.kind===t)?.label??t.charAt(0).toUpperCase()+t.slice(1)}function uQ(e){const{host:t,data:n,html:s,wrapperRef:o,segIndex:r,suppressClickRef:i,dragActiveRef:l,onNodeCreated:d,onDelete:u}=e,p=r!==void 0&&rQ(t.kind),h=ke(N=>N.penMode!==null&&N.penMode.seg===r&&N.penMode.on),[m,g]=oe.useState(Da),v=oe.useRef(null),y=oe.useRef(null),b=oe.useRef(null),E=oe.useRef({host:t,data:n,onNodeCreated:d,onDelete:u});E.current={host:t,data:n,onNodeCreated:d,onDelete:u};const $=oe.useRef(!1);$.current=h,oe.useEffect(()=>{const N=ke.getState();if(r!==void 0){if(!p){N.penMode?.seg===r&&N.setPenMode(null);return}return N.penMode?.seg!==r&&N.setPenMode({seg:r,on:!1}),()=>{const j=ke.getState();j.penMode?.seg===r&&j.setPenMode(null)}}},[p,r]);const A=N=>{r!==void 0&&ke.getState().setPenMode({seg:r,on:N})};return oe.useEffect(()=>()=>{y.current!==null&&clearTimeout(y.current)},[]),oe.useEffect(()=>{const N=o.current;if(N===null||!p)return;const j=$n(t.kind);if(j===null)return;const P=()=>{y.current!==null&&(clearTimeout(y.current),y.current=null),g(Da)},I=W=>{if(mx()||W===null){P();return}g(K=>({...K,fading:!0,flash:W,picker:null})),y.current=setTimeout(P,lQ)},O=()=>{v.current=null,l.current=!1,window.removeEventListener("pointermove",B),window.removeEventListener("pointerup",te),window.removeEventListener("pointercancel",ee)},C=()=>Np(j,E.current.data).map((W,K)=>{const R=N.querySelector(`[data-bp="${CSS.escape(`${j.nodesField}.${K}`)}"]`);return R===null?null:KS(R,N)}),D=()=>{const W=Np(j,E.current.data).length,K=[];for(let R=0;R<W;R++){const z=N.querySelector(`[data-bp="${CSS.escape(`${j.nodesField}.${R}`)}"]`),Y=z!==null?Nn(z,"data-col"):null,V=z!==null?Nn(z,"data-row"):null;if(Y===null||V===null)return;K.push({col:Y,row:V})}return K},F=(W,K)=>{const R=W.geom;if(R===null)return{col:1,row:1};const z=wo(R,K.x-W.svgBox.left,K.y-W.svgBox.top);return j.growRows===!1?{col:z.col,row:Math.min(z.row,R.rows)}:z},U=(W,K)=>{if(W.geom===null)return null;const R=_f(W.geom,K.col,K.row);return{left:W.svgBox.left+R.left,top:W.svgBox.top+R.top,width:R.width,height:R.height}},X=(W,K)=>{E.current.host.commitPaths(W.sets),E.current.host.notify?.(`Drew ${W.label}`),I(K),E.current.onNodeCreated(W.nodePath,j.labelField)},B=W=>{const K=v.current;if(K===null||W.pointerId!==K.pointerId)return;W.preventDefault();const R=N.getBoundingClientRect();K.points.push({x:W.clientX-R.left,y:W.clientY-R.top}),g({trail:[...K.points],fading:!1,flash:null,picker:null})},te=W=>{const K=v.current;if(K===null||W.pointerId!==K.pointerId)return;O(),i.current=!0;const R=K.points,z=nQ(R);if(z===void 0){P();return}const{host:Y,data:V}=E.current,re=R.map(De=>De.x),Q=R.map(De=>De.y),ne={x:(Math.min(...re)+Math.max(...re))/2,y:(Math.min(...Q)+Math.max(...Q))/2},Z=R[0],q=R[R.length-1],de=C(),le=Np(j,V),J=De=>{for(let Me=de.length-1;Me>=0;Me--){const Be=de[Me],Ge=le[Me];if(Be!=null&&Ge!==void 0&&Ge!==""&&cQ(Be,De))return{id:Ge,path:`${j.nodesField}.${Me}`}}return null},ue=F(K,z.shape==="line"?q:ne),ve=J(Z),we=J(q),$e=J(ne),je=aQ(z.shape,t.kind,ue,{data:V,placements:D(),...z.candidates!==void 0?{candidates:z.candidates}:{},...z.shape==="line"?{line:{fromId:ve?.id??null,toId:we?.id??null,endCell:ue}}:{},under:$e?.path??null});if(je.type==="node"){X(je,U(K,ue));return}if(je.type==="edge"){Y.commitPaths(je.sets),Y.notify?.(`Connected ${no(j,V,je.fromId)} → ${no(j,V,je.toId)}`),I(null);return}if(je.type==="delete"){P(),E.current.onDelete(je.path);return}if(je.type==="pick"){const De=new Set(je.first),Me=[...je.first.map(Be=>({value:Be,label:dQ(j,Be)})),...j.nodeKinds.filter(Be=>!De.has(Be.kind)).map(Be=>({value:Be.kind,label:Be.label}))];if(Me.length===0){P();return}b.current=ue,g({trail:R,fading:!0,flash:U(K,ue),picker:{left:ne.x,top:ne.y,cell:ue,items:Me}});return}je.reason!==""&&Y.notify?.(je.reason),P()},ee=()=>{O(),P()},H=W=>{if(!$.current||W.button!==0||v.current!==null||!(W.target instanceof Element)||W.target.closest(".stu-dx-sketch-picker")!==null||b.current!==null)return;const K=W.target.closest("svg");if(K===null||!N.contains(K)||!K.hasAttribute("data-grid"))return;W.preventDefault(),W.stopPropagation();const R=N.getBoundingClientRect();v.current={pointerId:W.pointerId,svg:K,svgBox:KS(K,N),geom:Ao(K),points:[{x:W.clientX-R.left,y:W.clientY-R.top}]},l.current=!0,i.current=!0,window.addEventListener("pointermove",B),window.addEventListener("pointerup",te),window.addEventListener("pointercancel",ee)};return N.addEventListener("pointerdown",H,!0),()=>{N.removeEventListener("pointerdown",H,!0),O(),b.current=null,g(Da)}},[o,t.kind,p,s,l,i]),{on:h,visuals:m,available:p,toggle:()=>A(!$.current),leave:()=>{b.current=null,g(Da),A(!1)},choose:N=>{const j=o.current,P=b.current,I=$n(t.kind);if(b.current=null,j===null||P===null||I===null){g(Da);return}const{host:O,data:C}=E.current,D=[],F=Np(I,C).length;for(let X=0;X<F;X++){const B=j.querySelector(`[data-bp="${CSS.escape(`${I.nodesField}.${X}`)}"]`),te=B!==null?Nn(B,"data-col"):null,ee=B!==null?Nn(B,"data-row"):null;if(te===null||ee===null)break;D.push({col:te,row:ee})}const U=HC(I,C,P,N,D.length===F?D:void 0);g(Da),U!==null&&(O.commitPaths(U.sets),O.notify?.(`Drew ${U.label}`),E.current.onNodeCreated(U.nodePath,I.labelField))}}}const VS={box:null,snap:null};function pQ(e,t){const n=e.getBoundingClientRect(),s=t.getBoundingClientRect();return{left:n.left-s.left,top:n.top-s.top,width:n.width,height:n.height}}function fQ(e){const{host:t,data:n,html:s,wrapperRef:o,enabled:r,editorOpenRef:i,suppressClickRef:l,dragActiveRef:d,onMarqueeStart:u,onCreated:p}=e,[h,m]=oe.useState(VS),g=oe.useRef(null),v=oe.useRef({host:t,data:n,onMarqueeStart:u,onCreated:p});return v.current={host:t,data:n,onMarqueeStart:u,onCreated:p},oe.useEffect(()=>{const y=o.current;if(y===null||!r||!Ph(t.kind))return;const b=()=>{const j=g.current;g.current=null,d.current=!1,j!==null&&j.active&&(document.body.style.userSelect="",y.style.cursor=""),m(VS),window.removeEventListener("pointermove",$),window.removeEventListener("pointerup",A),window.removeEventListener("pointercancel",T),window.removeEventListener("keydown",E,!0)},E=j=>{j.key==="Escape"&&g.current?.active===!0&&(j.preventDefault(),j.stopPropagation(),b())},$=j=>{const P=g.current;if(P===null||j.pointerId!==P.pointerId)return;if(!P.active){if(!Ch(j.clientX-P.startX,j.clientY-P.startY))return;P.active=!0,d.current=!0,l.current=!0,document.body.style.userSelect="none",y.style.cursor="crosshair",v.current.onMarqueeStart()}const I=y.getBoundingClientRect(),O=P.startX-I.left,C=P.startY-I.top,D=j.clientX-I.left,F=j.clientY-I.top,U={left:Math.min(O,D),top:Math.min(C,F),width:Math.abs(D-O),height:Math.abs(F-C)},X=CS(P.geom,O-P.svgBox.left,C-P.svgBox.top,D-P.svgBox.left,F-P.svgBox.top),B=gx(P.geom,X);m({box:U,snap:{left:P.svgBox.left+B.left,top:P.svgBox.top+B.top,width:B.width,height:B.height}})},A=j=>{const P=g.current;if(P===null||j.pointerId!==P.pointerId)return;if(!P.active){b();return}const I=y.getBoundingClientRect(),O=CS(P.geom,P.startX-I.left-P.svgBox.left,P.startY-I.top-P.svgBox.top,j.clientX-I.left-P.svgBox.left,j.clientY-I.top-P.svgBox.top),{host:C,data:D,onCreated:F}=v.current,U=bC(C.kind,D,O);b(),U!==null&&(C.commitPaths(U.sets),F(U.groupPath,"label"))},T=()=>b(),N=j=>{if(j.button!==0||g.current!==null||i.current||!(j.target instanceof Element)||j.target.closest(".stu-dx-overlay")!==null||j.target.closest("[data-bp]")!==null)return;const P=j.target.closest("svg");if(P===null||!y.contains(P)||!P.hasAttribute("data-grid"))return;const I=Ao(P);I!==null&&(g.current={pointerId:j.pointerId,startX:j.clientX,startY:j.clientY,geom:I,svgBox:pQ(P,y),active:!1},window.addEventListener("pointermove",$),window.addEventListener("pointerup",A),window.addEventListener("pointercancel",T),window.addEventListener("keydown",E,!0))};return y.addEventListener("pointerdown",N),()=>{y.removeEventListener("pointerdown",N),b()}},[o,t.kind,r,s,d,l,i]),h}const GS={snap:null};function hQ(e,t){const n=e.getBoundingClientRect(),s=t.getBoundingClientRect();return{left:n.left-s.left,top:n.top-s.top,width:n.width,height:n.height}}function WC(e){return e==="nw"||e==="se"?"nwse-resize":"nesw-resize"}function mQ(e){const{host:t,data:n,html:s,wrapperRef:o,suppressClickRef:r,dragActiveRef:i,onResizeStart:l}=e,[d,u]=oe.useState(GS),p=oe.useRef(null),h=oe.useRef({host:t,data:n,onResizeStart:l});h.current={host:t,data:n,onResizeStart:l};const m=oe.useRef(null);return oe.useEffect(()=>{const g=o.current;if(g===null||!Ph(t.kind))return;const v=()=>{const T=p.current;p.current=null,i.current=!1,T!==null&&T.active&&(document.body.style.userSelect="",g.style.cursor=""),u(GS),window.removeEventListener("pointermove",b),window.removeEventListener("pointerup",E),window.removeEventListener("pointercancel",$),window.removeEventListener("keydown",y,!0)},y=T=>{T.key==="Escape"&&p.current?.active===!0&&(T.preventDefault(),T.stopPropagation(),v())},b=T=>{const N=p.current;if(N===null||T.pointerId!==N.pointerId)return;if(!N.active){if(!Ch(T.clientX-N.startX,T.clientY-N.startY))return;N.active=!0,i.current=!0,r.current=!0,document.body.style.userSelect="none",g.style.cursor=N.cursor,h.current.onResizeStart()}const j=g.getBoundingClientRect(),P=wo(N.geom,T.clientX-j.left-N.svgBox.left,T.clientY-j.top-N.svgBox.top),I=OY(N.fixed,P);N.next=I;const O=gx(N.geom,I);u({snap:{left:N.svgBox.left+O.left,top:N.svgBox.top+O.top,width:O.width,height:O.height}})},E=T=>{const N=p.current;if(N===null||T.pointerId!==N.pointerId)return;if(!N.active){v();return}const{host:j,data:P}=h.current,I=N.next!==null?SC(P,N.index,N.next):null;v(),I!==null&&j.commitPaths(I)},$=()=>v(),A=(T,N,j)=>{if(T.button!==0||p.current!==null)return;const I=g.querySelector(`[data-bp="${CSS.escape(`groups.${N}`)}"]`)?.closest("svg")??null;if(I===null||!I.hasAttribute("data-grid"))return;const O=Ao(I),C=O!==null?Ji(h.current.data,N):null;O===null||C===null||(r.current=!1,p.current={pointerId:T.pointerId,startX:T.clientX,startY:T.clientY,index:N,cursor:WC(j),fixed:PY(j,C),geom:O,svgBox:hQ(I,g),active:!1,next:null},window.addEventListener("pointermove",b),window.addEventListener("pointerup",E),window.addEventListener("pointercancel",$),window.addEventListener("keydown",y,!0))};return m.current=A,()=>{v(),m.current=null}},[o,t.kind,s,i,r]),{visuals:d,start:(g,v,y)=>m.current?.(g.nativeEvent,v,y)}}function gQ(e){return[{side:"top",x:e.left+e.width/2,y:e.top},{side:"right",x:e.left+e.width,y:e.top+e.height/2},{side:"bottom",x:e.left+e.width/2,y:e.top+e.height},{side:"left",x:e.left,y:e.top+e.height/2}]}function vQ(e){return[{corner:"nw",x:e.left,y:e.top},{corner:"ne",x:e.left+e.width,y:e.top},{corner:"sw",x:e.left,y:e.top+e.height},{corner:"se",x:e.left+e.width,y:e.top+e.height}]}function to(e,t){const n=e.getBoundingClientRect(),s=t.getBoundingClientRect();return{left:n.left-s.left,top:n.top-s.top,width:n.width,height:n.height}}function Tp(e,t,n){const s=Array.from(e.querySelectorAll("[data-bp]")).filter(r=>r.closest(".stu-dx-hit")===null),o=s.map(r=>r.getAttribute("data-bp")??"");return SY(o,t,n!==null?s.indexOf(n):-1).map(r=>s[r])}function yQ(e){const t=new Set,n=[];for(const s of Array.from(e.querySelectorAll("[data-bp]"))){const o=s.getAttribute("data-bp")??"";o!==""&&!t.has(o)&&(t.add(o),n.push(o))}return n}function UC({host:e,data:t,html:n,wrapperRef:s,segIndex:o,linkPath:r,onElementClick:i,pendingMenu:l,onPendingMenuConsumed:d}){const u=oe.useMemo(()=>yy(e.kind),[e.kind]),p=oe.useRef(null),h=oe.useCallback(ce=>{const Ee=s.current;Ee!==null&&(p.current={before:xC(Ee),moves:ce})},[s]),m=oe.useMemo(()=>({kind:e.kind,commitPath:(ce,Ee)=>{h(!0),e.commitPath(ce,Ee)},commitPaths:ce=>{h(!0),e.commitPaths(ce)},deletePath:ce=>{const Ee=s.current,Se=()=>{h(!1),e.deletePath(ce)};Ee===null?Se():AS(Ee,[If(ce)],Se)},openFull:()=>e.openFull(),...e.notify!==void 0?{notify:ce=>e.notify?.(ce)}:{}}),[e,h,s]),g=oe.useCallback(ce=>{const Ee=$n(m.kind);return Ee!==null&&ce.startsWith(`${Ee.edgesField}.`)||ce.startsWith("relations.")},[m.kind]);oe.useLayoutEffect(()=>{const ce=p.current,Ee=s.current;ce===null||Ee===null||(p.current=null,_Y(Ee,ce.before,g,{moves:ce.moves}))},[n,s,g]);const v=ke(ce=>o!==void 0&&ce.penMode?.seg===o&&ce.penMode.on);oe.useEffect(()=>{const ce=s.current;if(ce!==null)return ce.classList.toggle("stu-dx-penning",v),()=>ce.classList.remove("stu-dx-penning")},[v,s]);const[y,b]=oe.useState(null),E=oe.useRef(!1);E.current=y!==null;const[$,A]=oe.useState(null),[T,N]=oe.useState(null),[j,P]=oe.useState([]),[I,O]=oe.useState([]),[C,D]=oe.useState([]),[F,U]=oe.useState([]),[X,B]=oe.useState([]),te=oe.useRef(null),ee=oe.useRef(null),H=oe.useRef(!1);H.current=T!==null;const W=ke(ce=>ce.partSel),K=o!==void 0&&W!==null&&W.seg===o?W.path:null,[R,z]=oe.useState(null),[Y,V]=oe.useState([]),[re,Q]=oe.useState(!1),[ne,Z]=oe.useState([]),q=oe.useRef(null);q.current=K;const de=oe.useRef(!1),le=oe.useRef(!1),J=oe.useRef(null),ue=oe.useCallback(()=>{const ce=J.current;ce!==null&&(ce instanceof HTMLElement||ce instanceof SVGElement)&&(ce.style.cursor=""),J.current=null},[]),ve=oe.useCallback(ce=>{o!==void 0&&(ke.getState().setPartSel(ce===null?null:{seg:o,path:ce}),ce!==null&&Ni("part-select"))},[o]),we=LX({host:m,data:t,html:n,wrapperRef:s,editorOpenRef:H,suppressClickRef:de,dragActiveRef:le,onDragStart:()=>{A(null),ue()},onDrop:ce=>{ve(ce),Ni("part-move")}}),$e=jX({host:m,data:t,html:n,wrapperRef:s,suppressClickRef:de,dragActiveRef:le,onConnectStart:()=>{A(null),ue()},onNodeCreated:(ce,Ee)=>{ve(ce),te.current={path:ce,focusField:Ee}},onEdgeCreated:(ce,Ee)=>{ve(ce),te.current={path:ce,focusField:Ee}}}),je=oe.useRef($e);je.current=$e;const De=uQ({host:m,data:t,html:n,wrapperRef:s,segIndex:o,suppressClickRef:de,dragActiveRef:le,onNodeCreated:(ce,Ee)=>{ve(ce),te.current={path:ce,focusField:Ee}},onDelete:ce=>{const Ee=cS(m.kind,ce)??ce,Se=()=>{Nt.current(Ee),ke.getState().setPartSel(null)};if(!Uv(m.kind,t,Ee)){Se();return}const tt=s.current?.querySelector(`[data-bp="${CSS.escape(Ee)}"]`)?.getBoundingClientRect();ke.getState().requestDelete({label:Pr(Dn(Ee)),anchor:tt!==void 0?{x:tt.left+tt.width/2,y:tt.bottom}:{x:window.innerWidth/2,y:window.innerHeight/3},run:Se})}}),Me=oe.useRef(De);Me.current=De;const Be=oe.useCallback((ce,Ee)=>{if(ce.closest(".seq-steps")!==null)return"summary";const Se=je.current.spec;if(Se!==null&&Cf(Se,Ee)!==null)return Se.edgeTextField},[]),Ge=mQ({host:m,data:t,html:n,wrapperRef:s,suppressClickRef:de,dragActiveRef:le,onResizeStart:()=>{A(null),ue()}}),fe=fQ({host:m,data:t,html:n,wrapperRef:s,enabled:o!==void 0,editorOpenRef:H,suppressClickRef:de,dragActiveRef:le,onMarqueeStart:()=>{A(null),ue()},onCreated:(ce,Ee)=>{ve(ce),te.current={path:ce,focusField:Ee}}});oe.useEffect(()=>()=>{ee.current!==null&&clearTimeout(ee.current)},[]);const ge=oe.useCallback((ce,Ee,Se,st)=>{A(null),N({path:ce,anchor:to(Ee,Se),...st!==void 0?{focusField:st}:{}})},[]),Ce=oe.useCallback((ce,Ee,Se)=>{const st=Tp(Se,ce,Ee);st.length!==0&&(B(st.map(tt=>to(tt,Se))),Ee instanceof SVGElement&&st.find(Oe=>!(Oe instanceof SVGElement))?.scrollIntoView({block:"nearest",behavior:"smooth"}),ee.current!==null&&clearTimeout(ee.current),ee.current=setTimeout(()=>{ee.current=null,B([])},1400))},[]);oe.useEffect(()=>{const ce=s.current;if(ce===null)return;const Ee=Oe=>{if(!(Oe instanceof Element))return null;const Ye=Oe.closest("[data-bp]");return Ye!==null&&ce.contains(Ye)?Ye:null},Se=Oe=>{if(le.current||H.current||E.current||Oe.target instanceof Element&&Oe.target.closest(".stu-dx-overlay")!==null)return;const Ye=Ee(Oe.target);if(Ye===null){A(null),ue();return}const yt=Ye.getAttribute("data-bp")??"";Ye!==J.current&&(ue(),(Ye instanceof HTMLElement||Ye instanceof SVGElement)&&kx(ce,m.kind,yt)!==null&&(Ye.style.cursor="grab",J.current=Ye)),A(Ft=>{const Gt=to(Ye,ce);if(Ft!==null&&Ft.path===yt&&Ft.rect.top===Gt.top&&Ft.rect.left===Gt.left)return Ft;const ls=Tp(ce,yt,Ye).map(cs=>to(cs,ce));return{path:yt,rect:Gt,twins:ls}})},st=()=>{A(null),ue()},tt=Oe=>{if(de.current){de.current=!1;return}if(Oe.target instanceof Element&&Oe.target.closest(".stu-dx-overlay")!==null)return;const Ye=Ee(Oe.target);if(Ye===null){q.current!==null&&ve(null);return}const yt=Ye.getAttribute("data-bp")??"";if(i?.(yt)===!0)return;const Ft=Be(Ye,yt);if(o===void 0){ge(yt,Ye,ce,Ft),Ce(yt,Ye,ce);return}if(q.current===yt&&!H.current){ge(yt,Ye,ce,Ft),Ce(yt,Ye,ce);return}ve(yt)};return ce.addEventListener("pointermove",Se),ce.addEventListener("pointerleave",st),ce.addEventListener("click",tt),()=>{ce.removeEventListener("pointermove",Se),ce.removeEventListener("pointerleave",st),ce.removeEventListener("click",tt),ue()}},[s,i,ge,Ce,ue,Be,m.kind,o,ve]),oe.useEffect(()=>{const ce=s.current;if(ce===null)return;const Ee=Se=>{const st=ke.getState();if(st.pendingDelete!==null||st.review!==null)return;if(Se.key==="Escape"&&je.current.pickerOpenRef.current===!0){Se.preventDefault(),Se.stopPropagation(),je.current.cancelPicker();return}if(Se.key==="Escape"&&Me.current.on&&!H.current){Se.preventDefault(),Se.stopPropagation(),Me.current.leave();return}const tt=Se.key==="ArrowLeft"||Se.key==="ArrowRight"||Se.key==="ArrowUp"||Se.key==="ArrowDown";if(tt&&Se.altKey&&!Se.metaKey&&!Se.ctrlKey){const Oe=K??T?.path??$?.path??null;if(Oe===null)return;const Ye=R0({wrap:ce,host:m,data:t,path:Oe,key:Se.key});if(Ye===null)return;Se.preventDefault(),Se.stopPropagation(),N(null),A(null),ve(Ye);return}if(o!==void 0&&!H.current&&!wl(Se.target)&&!E.current){if(Se.key.toLowerCase()==="d"&&!Se.metaKey&&!Se.ctrlKey&&!Se.altKey&&!Se.shiftKey&&Me.current.available){Se.preventDefault(),Se.stopPropagation(),Me.current.toggle();return}if(Se.key==="F10"&&Se.shiftKey||Se.key==="ContextMenu"){Se.preventDefault(),Se.stopPropagation();const Oe=K!==null?ce.querySelector(`[data-bp="${CSS.escape(K)}"]`):null,Ye=(Oe??ce).getBoundingClientRect();ze.current?.(Oe,{x:Ye.left+8,y:Oe!==null?Ye.bottom+4:Ye.top+40});return}if(!(Se.metaKey||Se.ctrlKey||Se.altKey)){if(Se.key==="Tab"){const Oe=yQ(ce);if(Oe.length===0)return;if(Se.preventDefault(),Se.stopPropagation(),K===null){ve(Se.shiftKey?Oe[Oe.length-1]:Oe[0]);return}const Ye=Oe.indexOf(K),yt=Oe.length;ve(Oe[Ye<0?0:(Ye+(Se.shiftKey?-1:1)+yt)%yt]);return}if(K!==null){if(Se.key.toLowerCase()==="n"&&m.kind==="sequence"&&/^messages\.\d+$/.test(K)){const Oe=ce.querySelector(`[data-bp="${CSS.escape(K)}"]`);Oe!==null&&(Se.preventDefault(),Se.stopPropagation(),ge(K,Oe,ce,"summary"),Ce(K,Oe,ce));return}if(Se.key==="Enter"&&!Se.shiftKey){const Oe=ce.querySelector(`[data-bp="${CSS.escape(K)}"]`);if(Oe===null)return;Se.preventDefault(),Se.stopPropagation(),ge(K,Oe,ce,Be(Oe,K)),Ce(K,Oe,ce);return}if(Se.key==="Escape"){Se.preventDefault(),Se.stopPropagation(),ve(null);return}if(Se.key==="Backspace"||Se.key==="Delete"){const Oe=cS(m.kind,K);if(Oe===null)return;Se.preventDefault(),Se.stopPropagation();const Ye=()=>{const Gt=bS(m.kind,Oe);if(Gt!==null){const ls=wS(m.kind,t,Gt);if(ls===null){m.notify?.("Keep at least one column");return}m.commitPaths(ls)}else m.deletePath(Dn(Oe));ke.getState().setPartSel(null)};if(!Uv(m.kind,t,Oe)){Ye();return}const Ft=(ce.querySelector(`[data-bp="${CSS.escape(Oe)}"]`)??ce.querySelector(`[data-bp="${CSS.escape(K)}"]`))?.getBoundingClientRect();ke.getState().requestDelete({label:Pr(Dn(Oe)),anchor:Ft!==void 0?{x:Ft.left+Ft.width/2,y:Ft.bottom}:{x:window.innerWidth/2,y:window.innerHeight/3},run:Ye});return}if(tt){if(!OG(jf(m.kind,K)))return;Se.preventDefault(),Se.stopPropagation();const Oe=IX({wrap:ce,host:m,data:t,path:K,key:Se.key,grow:Se.shiftKey});Oe!==null&&(ve(Oe.path),Ni("part-move"))}}}}};return window.addEventListener("keydown",Ee,!0),()=>window.removeEventListener("keydown",Ee,!0)},[s,m,t,K,T,$,o,ve,ge,Ce,Be]),oe.useLayoutEffect(()=>{const ce=s.current;if(ce===null||K===null){z(null),V([]);return}const Ee=ce.querySelector(`[data-bp="${CSS.escape(K)}"]`);if(Ee===null){z(null),V([]),ve(null);return}z(to(Ee,ce)),V(Tp(ce,K,Ee).map(Se=>to(Se,ce))),Q(Ee.closest("svg")?.hasAttribute("data-grid")===!0)},[K,n,s,ve]),oe.useLayoutEffect(()=>{const ce=s.current;if(ce===null){Z([]);return}const Ee=[];for(const Se of Array.from(ce.querySelectorAll("svg"))){if(Se.closest(".stu-dx-hit")!==null)continue;const st=Se.getAttribute("viewBox")??"";if(st==="")continue;const tt=Array.from(Se.querySelectorAll("path[data-bp]")).map(Oe=>({bp:Oe.getAttribute("data-bp")??"",d:Oe.getAttribute("d")??""})).filter(Oe=>Oe.bp!==""&&Oe.d!=="");tt.length!==0&&Ee.push({box:to(Se,ce),viewBox:st,paths:tt})}Z(Ee)},[n,s]),oe.useLayoutEffect(()=>{const ce=s.current;if(ce===null||T===null){U([]);return}U(Tp(ce,T.path,null).map(Ee=>to(Ee,ce)))},[T,n,s]),oe.useLayoutEffect(()=>{const ce=s.current;if(ce===null)return;const Ee=[],Se=[];for(const Oe of Array.from(ce.querySelectorAll("[data-bl]"))){const Ye=Oe.getAttribute("data-bl")??"";if(Ye==="")continue;const yt=Dn(Ye),Ft=yt[yt.length-1];if(typeof Ft!="string")continue;const Gt=`+ Add ${as($o(Ft)).toLowerCase()}`;if(!yt.some(cs=>typeof cs=="number"))Ee.push({listPath:Ye,label:Gt});else if(!(Oe instanceof SVGElement)){const cs=to(Oe,ce);Se.push({listPath:Ye,label:Gt,at:{left:cs.left+8,top:cs.top+cs.height-11}})}}const st=kS(m.kind);if(st!==null){const Oe=is(t,[st.colsPath]),Ye=Array.isArray(Oe)?Oe.length:0,yt=Ye>0?ce.querySelector(`[data-bp="${CSS.escape(`${st.colsPath}.${Ye-1}`)}"]`):null,Ft=`+ Add ${as($o(st.colsPath)).toLowerCase()}`;if(yt!==null&&!(yt instanceof SVGElement)){const Gt=to(yt,ce);Se.push({listPath:st.colsPath,label:"+",at:{left:Gt.left+Gt.width+4,top:Gt.top+Gt.height/2-10}})}else Ee.some(Gt=>Gt.listPath===st.colsPath)||Ee.push({listPath:st.colsPath,label:Ft})}if(m.kind==="userstory")for(const Oe of["criteria","tags"])Ee.some(Ye=>Ye.listPath===Oe)||Ee.push({listPath:Oe,label:`+ Add ${as($o(Oe)).toLowerCase()}`});P(Ee),O(Se);const tt=te.current;if(tt!==null){const Oe=ce.querySelector(`[data-bp="${CSS.escape(tt.path)}"]`);Oe!==null&&(te.current=null,ge(tt.path,Oe,ce,tt.focusField))}},[n,t,s,ge,m.kind]),oe.useLayoutEffect(()=>{const ce=s.current;if(ce===null||r===null||r===void 0||r===""){D([]);return}const Ee=Array.from(ce.querySelectorAll("[data-bp]"));let st=Ee.filter(tt=>{const Oe=tt.getAttribute("data-bp")??"";return Oe===r||Oe.startsWith(`${r}.`)});if(st.length===0){let tt=-1,Oe=[];for(const Ye of Ee){const yt=Ye.getAttribute("data-bp")??"";(r===yt||r.startsWith(`${yt}.`))&&(yt.length>tt?(tt=yt.length,Oe=[Ye]):yt.length===tt&&Oe.push(Ye))}st=Oe}D(st.map(tt=>to(tt,ce)))},[r,n,s]);const Fe=(ce,Ee)=>{const Se=s.current;if(Se===null)return[];const st=ce?.getAttribute("data-bp")??null,tt=$n(m.kind),Ye=(ce??document.elementFromPoint(Ee.x,Ee.y))?.closest("svg")??Se.querySelector("svg[data-grid]");let yt=null,Ft=null,Gt=!1,ls=null;if(Ye!=null&&Ye.hasAttribute("data-grid")&&tt!==null){const Qr=Ao(Ye);if(Qr!==null){Ft={cols:Qr.cols,rows:Qr.rows},Gt=Ye.hasAttribute("data-grid-auto");const Ed=is(t,[tt.nodesField]);if(yt=xx(Se,tt.nodesField,Array.isArray(Ed)?Ed.length:0),st===null){const Md=Ye.getBoundingClientRect(),Ks=wo(Qr,Ee.x-Md.left,Ee.y-Md.top);ls=tt.growRows===!1?{col:Ks.col,row:Math.min(Ks.row,Qr.rows)}:Ks}}}const cs=DY(m.kind,st,ls);return HY(cs,{kind:m.kind,data:t,placements:yt,grid:Ft,quick:Gt,selected:q.current})},qe=(ce,Ee)=>{if(o===void 0)return;const Se=Fe(ce,Ee),st=ce?.getAttribute("data-bp")??null;st!==null&&st!==q.current&&ve(st),A(null),ue(),Se.length>0&&b({at:Ee,items:Se})},ze=oe.useRef(null);ze.current=qe,oe.useEffect(()=>{const ce=s.current;if(ce===null||o===void 0)return;const Ee=Se=>{if(H.current||le.current||Se.target instanceof Element&&Se.target.closest(".stu-dx-overlay")!==null)return;const st=Se.target instanceof Element?Se.target.closest("[data-bp]"):null;Se.preventDefault(),Se.stopPropagation(),ze.current?.(st!==null&&ce.contains(st)?st:null,{x:Se.clientX,y:Se.clientY})};return ce.addEventListener("contextmenu",Ee),()=>ce.removeEventListener("contextmenu",Ee)},[s,o]),oe.useLayoutEffect(()=>{if(l==null)return;const ce=s.current;if(d?.(),ce===null)return;const Se=document.elementFromPoint(l.x,l.y)?.closest("[data-bp]")??null;ze.current?.(Se!==null&&ce.contains(Se)?Se:null,l)},[l,d,s]);const Xe=oe.useCallback(()=>b(null),[]),pt=ce=>{b(null);const Ee=s.current;if(Ee===null)return;if(ce.action!==void 0){const tt=ce.action;if(tt.type==="openYaml")m.openFull();else if(tt.type==="connect"){const Oe=$n(m.kind);Oe!==null&&(ve(`${Oe.nodesField}.${tt.fromIndex}`),$e.armFrom(tt.fromIndex))}else{const Oe=Ee.querySelector(`[data-bp="${CSS.escape(tt.path)}"]`);Oe!==null?(ve(tt.path),ge(tt.path,Oe,Ee,tt.field)):m.openFull()}return}if(ce.op===void 0)return;const Se=ce.op();if(Se.length===0)return;const st=()=>{const tt=Se[0];Se.length===1&&tt!==void 0&&NS(tt)?(h(!1),e.deletePath(tt.path),ke.getState().setPartSel(null)):(h(ce.fades===void 0),e.commitPaths(Se.filter(Oe=>!NS(Oe)))),ce.then!==void 0&&(ve(ce.then.select),ce.then.edit!==void 0&&(te.current={path:ce.then.select,focusField:ce.then.edit}))};ce.fades!==void 0&&ce.fades.length>0?AS(Ee,ce.fades,st):st()},kt=ce=>{const Ee=kS(m.kind);if(Ee!==null&&ce===Ee.colsPath){const yt=bY(m.kind,t);if(yt===null)return;m.commitPaths(yt.sets),te.current={path:yt.headerPath};return}const Se=Dn(ce),st=hx(u,Se);if(st===null||st.kind!=="array")return;const tt=is(t,Se),Oe=Array.isArray(tt)?tt:[],Ye=[...Se].reverse().find(yt=>typeof yt=="string")??"item";m.commitPath([...Se,Oe.length],IY(m.kind,ce,Qa(st.element,Oe,as(Ye)),t)),te.current={path:If([...Se,Oe.length])}},St=ce=>{const Ee=bS(m.kind,ce);if(Ee!==null){const Se=wS(m.kind,t,Ee);return Se===null?(m.notify?.("Keep at least one column"),!1):(m.commitPaths(Se),!0)}return m.deletePath(Dn(ce)),!0},Nt=oe.useRef(St);Nt.current=St;const Bt=ce=>{if($===null)return;const Ee=$.path,Se=()=>{Nt.current(Ee)};if(A(null),!Uv(m.kind,t,Ee)){Se();return}const st=ce.currentTarget.getBoundingClientRect();ke.getState().requestDelete({label:Pr(Dn(Ee)),anchor:{x:st.left+st.width/2,y:st.bottom},run:Se})},dt=()=>{const ce=s.current;if(ce===null)return;const Ee=ce.querySelector('[data-bp="messages.0"]');Ee!==null?ge("messages.0",Ee,ce,"summary"):m.openFull()},_t=EY(m.kind,t),En=$!==null&&tC(Dn($.path)),zt=$!==null&&$.rect.top>=12,Et=o!==void 0&&$e.spec!==null&&K!==null?Af($e.spec,K):null,an=o!==void 0&&K!==null&&re&&Ph(m.kind)?wC(K):null,_n=K!==null?jf(m.kind,K):null,No=$e.spec!==null&&K!==null&&Cf($e.spec,K)!==null?$e.spec.edgeTextField:null,xs=m.kind==="sequence"&&K!==null?/^messages\.(\d+)$/.exec(K):null,sr=xs!==null&&cd(is(t,["messages",Number(xs[1])]))?{n:MY(is(t,["messages"]),Number(xs[1])),has:typeof is(t,["messages",Number(xs[1]),"summary"])=="string"&&is(t,["messages",Number(xs[1]),"summary"]).length>0}:null,$l=_n===null?"":No!==null?`⏎ edit ${No}${sr!==null?" · n note":""} · ⌫`:_n.kind==="table-cell"?"⏎ edit · ←↑↓→ cells":_n.kind==="grid-group"?"⏎ edit · ←↑↓→ move · drag corner → resize · ⌫":_n.kind!=="inert"?"⏎ edit · ←↑↓→ move · ⌫":"⏎ edit",Sl=R!==null&&R.top>=12;return w.jsxs(w.Fragment,{children:[ne.map((ce,Ee)=>w.jsx("svg",{className:"stu-dx-hit",viewBox:ce.viewBox,preserveAspectRatio:"none","aria-hidden":"true",style:{left:ce.box.left,top:ce.box.top,width:ce.box.width,height:ce.box.height},children:ce.paths.map((Se,st)=>w.jsx("path",{d:Se.d,"data-bp":Se.bp},st))},`hit${Ee}`)),w.jsxs("div",{className:"stu-dx-overlay",children:[C.map((ce,Ee)=>w.jsx("div",{className:"stu-dx-link",style:{left:ce.left-3,top:ce.top-3,width:ce.width+6,height:ce.height+6}},`lk${Ee}`)),T!==null&&F.map((ce,Ee)=>w.jsx("div",{className:"stu-dx-link",style:{left:ce.left-3,top:ce.top-3,width:ce.width+6,height:ce.height+6}},`ed${Ee}`)),X.map((ce,Ee)=>w.jsx("div",{className:"stu-dx-flash",style:{left:ce.left-3,top:ce.top-3,width:ce.width+6,height:ce.height+6}},`fl${Ee}`)),K!==null&&R!==null&&T===null&&w.jsxs(w.Fragment,{children:[w.jsx("div",{className:"stu-dx-sel",style:{left:R.left-3,top:R.top-3,width:R.width+6,height:R.height+6}}),Y.map((ce,Ee)=>w.jsx("div",{className:"stu-dx-link",style:{left:ce.left-3,top:ce.top-3,width:ce.width+6,height:ce.height+6}},`pt${Ee}`)),w.jsxs("div",{className:"stu-dx-chip",style:{left:Math.max(0,R.left-3),top:Sl?R.top-13:R.top+R.height-7},children:[Pr(Dn(K)),$l!==""&&w.jsxs("span",{className:"stu-dx-chip-keys",children:[" · ",$l]})]}),an!==null&&vQ(R).map(ce=>w.jsx("button",{type:"button",className:"stu-dx-resize","aria-label":`Resize the group from its ${ce.corner} corner`,title:"Drag to resize",style:{left:ce.x-5,top:ce.y-5,cursor:WC(ce.corner)},onPointerDown:Ee=>{Ee.stopPropagation(),Ge.start(Ee,an,ce.corner)},onClick:Ee=>Ee.stopPropagation()},ce.corner)),sr!==null&&w.jsx("button",{type:"button",className:"stu-dx-note",style:{left:Math.max(0,R.left-3),top:Sl?R.top+R.height+8:R.top-36},onPointerDown:ce=>ce.stopPropagation(),onClick:ce=>{ce.stopPropagation();const Ee=s.current;if(Ee===null||K===null)return;const Se=Ee.querySelector(`[data-bp="${CSS.escape(K)}"]`);Se!==null&&ge(K,Se,Ee,"summary")},children:sr.has?`✎ note ${sr.n}`:`+ add note ${sr.n}`}),Et!==null&&gQ(R).map(ce=>w.jsx("button",{type:"button",className:"stu-dx-dot","aria-label":`Connect from the ${ce.side} edge`,title:"Drag to connect",style:{left:ce.x-6,top:ce.y-6},onPointerDown:Ee=>{Ee.stopPropagation(),$e.start(Ee,Et,{x:ce.x,y:ce.y})},onClick:Ee=>Ee.stopPropagation()},ce.side))]}),De.visuals.flash!==null&&w.jsx("div",{className:"stu-dx-sketch-flash",style:{left:De.visuals.flash.left,top:De.visuals.flash.top,width:De.visuals.flash.width,height:De.visuals.flash.height}}),De.visuals.trail.length>1&&w.jsx("svg",{className:`stu-dx-ink ${De.visuals.fading?"stu-dx-ink-out":""}`,"aria-hidden":"true",children:w.jsx("polyline",{points:De.visuals.trail.map(ce=>`${ce.x},${ce.y}`).join(" ")})}),De.visuals.picker!==null&&w.jsxs("div",{className:"stu-dx-connect-picker stu-dx-sketch-picker",role:"menu","aria-label":"What did you draw?",style:{left:De.visuals.picker.left+6,top:De.visuals.picker.top+6},onClick:ce=>ce.stopPropagation(),children:[w.jsx("div",{className:"stu-dx-connect-picker-title",children:"What did you draw?"}),De.visuals.picker.items.map(ce=>w.jsx("button",{type:"button",role:"menuitem",onClick:Ee=>{Ee.stopPropagation(),De.choose(ce.value)},children:ce.label},ce.value))]}),$e.visuals.wire!==null&&w.jsxs("svg",{className:"stu-dx-wire","aria-hidden":"true",children:[w.jsx("line",{x1:$e.visuals.wire.x1,y1:$e.visuals.wire.y1,x2:$e.visuals.wire.x2,y2:$e.visuals.wire.y2}),w.jsx("circle",{cx:$e.visuals.wire.x2,cy:$e.visuals.wire.y2,r:4})]}),$e.visuals.snap!==null&&w.jsx("div",{className:"stu-dx-snap",style:{left:$e.visuals.snap.left,top:$e.visuals.snap.top,width:$e.visuals.snap.width,height:$e.visuals.snap.height}}),$e.visuals.target!==null&&w.jsx("div",{className:"stu-dx-connect-target",style:{left:$e.visuals.target.left-3,top:$e.visuals.target.top-3,width:$e.visuals.target.width+6,height:$e.visuals.target.height+6}}),Ge.visuals.snap!==null&&w.jsx("div",{className:"stu-dx-snap",style:{left:Ge.visuals.snap.left,top:Ge.visuals.snap.top,width:Ge.visuals.snap.width,height:Ge.visuals.snap.height}}),fe.snap!==null&&w.jsx("div",{className:"stu-dx-snap",style:{left:fe.snap.left,top:fe.snap.top,width:fe.snap.width,height:fe.snap.height}}),fe.box!==null&&w.jsx("div",{className:"stu-dx-marquee",style:{left:fe.box.left,top:fe.box.top,width:fe.box.width,height:fe.box.height}}),$e.visuals.picker!==null&&w.jsxs("div",{className:"stu-dx-connect-picker",role:"menu","aria-label":$e.visuals.picker.title,style:{left:$e.visuals.picker.left+6,top:$e.visuals.picker.top+6},onClick:ce=>ce.stopPropagation(),children:[w.jsx("div",{className:"stu-dx-connect-picker-title",children:$e.visuals.picker.title}),$e.visuals.picker.items.map(ce=>w.jsx("button",{type:"button",role:"menuitem",onClick:Ee=>{Ee.stopPropagation(),$e.choose(ce.value)},children:ce.label},ce.value))]}),we.snap!==null&&w.jsx("div",{className:"stu-dx-snap",style:{left:we.snap.left,top:we.snap.top,width:we.snap.width,height:we.snap.height}}),we.drop!==null&&w.jsx("div",{className:"stu-dx-drop",style:{left:we.drop.left,top:we.drop.top,width:we.drop.width,height:we.drop.height}}),we.ghost!==null&&w.jsx("div",{className:"stu-dx-ghost",style:{left:we.ghost.box.left,top:we.ghost.box.top,width:we.ghost.box.width,height:we.ghost.box.height},children:w.jsx("span",{children:we.ghost.label})}),$!==null&&T===null&&$.path!==K&&w.jsxs(w.Fragment,{children:[w.jsx("div",{className:"stu-dx-hl",style:{left:$.rect.left-3,top:$.rect.top-3,width:$.rect.width+6,height:$.rect.height+6}}),$.twins.map((ce,Ee)=>w.jsx("div",{className:"stu-dx-hl stu-dx-hl-twin",style:{left:ce.left-3,top:ce.top-3,width:ce.width+6,height:ce.height+6}},`tw${Ee}`)),w.jsx("div",{className:"stu-dx-chip",style:{left:Math.max(0,$.rect.left-3),top:zt?$.rect.top-13:$.rect.top+$.rect.height-7},children:Pr(Dn($.path))}),En&&w.jsx("button",{type:"button",className:"stu-dx-x","aria-label":`Remove ${Pr(Dn($.path))}`,title:"Remove",style:{left:$.rect.left+$.rect.width-8,top:$.rect.top-8},onClick:ce=>{ce.stopPropagation(),Bt(ce)},children:"×"})]}),I.map(ce=>w.jsx("button",{type:"button",className:"stu-dx-add stu-dx-add-spot",style:{left:ce.at?.left??0,top:ce.at?.top??0},onClick:Ee=>{Ee.stopPropagation(),kt(ce.listPath)},children:ce.label},ce.listPath)),y!==null&&kY.createPortal(w.jsx($Y,{items:y.items,at:y.at,onPick:pt,onClose:Xe}),document.body),T!==null&&w.jsx(NX,{host:m,root:u,data:t,path:Dn(T.path),anchor:T.anchor,focusField:T.focusField,onClose:()=>{N(null),Ni("micro-close")},onMovedTo:ce=>ve(ce),onRemoveItem:()=>Nt.current(T.path)})]}),(j.length>0||_t)&&w.jsxs("div",{className:"stu-dx-addbar",onClick:ce=>ce.stopPropagation(),children:[_t&&w.jsx("button",{type:"button",className:"stu-dx-add stu-dx-add-steps",title:"Describe each step — a Step-by-step list renders below the diagram",onClick:dt,children:"+ Add step descriptions"}),j.map(ce=>w.jsx("button",{type:"button",className:"stu-dx-add",onClick:()=>kt(ce.listPath),children:ce.label},ce.listPath))]})]})}function Ex(e,t,n){if(n.length<2)return{raw:e,expanded:null};const s=DM(e);if(!s.ok)return{raw:e,expanded:null};for(let o=0;o<n.length-1;o++){if(typeof n[o]!="number")continue;const r=n.slice(0,o+1),i=is(s.data,r),l=is(t,r);if(!(i===void 0||l===void 0)&&JSON.stringify(i)!==JSON.stringify(l))return{raw:Ai(e,r,l),expanded:r}}return{raw:e,expanded:null}}function Mx(e,t,n){let s=e;const o=new Set;for(const r of n){const i=r.join("\0");o.has(i)||(o.add(i),s=sD(s,r,t))}return s}function xQ(e,t,n,s,o){const r=t.segments[n];if(r===void 0||r.kind==="markdown")throw new TypeError(`segment ${n} is not a typed block`);const i=Ex(ch(r),r.data,s),l=Ai(i.raw,s,o,r.kind);return lh(e,t,n,Mx(l,r.kind,i.expanded===null?[]:[i.expanded]))}function kQ(e,t,n,s){const o=t.segments[n];if(o===void 0||o.kind==="markdown")throw new TypeError(`segment ${n} is not a typed block`);let r=ch(o);const i=[];for(const l of s){const d=Ex(r,o.data,l.path);r=d.raw,d.expanded!==null&&i.push(d.expanded)}for(const l of s)r=Ai(r,l.path,l.value,o.kind);return lh(e,t,n,Mx(r,o.kind,i))}function bQ(e,t,n,s){const o=t.segments[n];if(o===void 0||o.kind==="markdown")throw new TypeError(`segment ${n} is not a typed block`);const r=Ex(ch(o),o.data,s),i=h0(r.raw,s);return lh(e,t,n,Mx(i,o.kind,r.expanded===null?[]:[r.expanded]))}function wQ(e,t){return{kind:t,commitPath:(n,s)=>{ke.getState().applyOp((r,i)=>xQ(r,i,e,n,s),e)},commitPaths:n=>{ke.getState().applyOp((o,r)=>kQ(o,r,e,n),e)},deletePath:n=>{ke.getState().applyOp((o,r)=>bQ(o,r,e,n),e)},openFull:()=>ke.getState().openSheet(e),notify:n=>ke.getState().toast(n)}}function KC(e,t){return e.filter(n=>n.line!==void 0&&n.line>=t.startLine&&n.line<=t.endLine)}function $Q(e,t,n,s){const o=n.segments[s];return o===void 0?[]:KC(e,Xo(t,o))}function VC(e){let t=0,n=0;for(const s of e)s.level==="error"?t+=1:n+=1;return{errors:t,warnings:n}}function SQ(e,t,n){return n.segments.map((s,o)=>VC($Q(e,t,n,o)))}function Vv(e){ke.getState().openPicker({view:"compact",index:e.index,anchor:{x:e.x,y:e.y}})}function EQ(e){try{const t=JSON.parse(e);return t.kind==="move"&&typeof t.from=="number"?{kind:"move",from:t.from}:null}catch{return null}}function YS({minIndex:e}){const[t,n]=oe.useState(!1),s=oe.useRef(0);return oe.useEffect(()=>{const o=()=>{s.current=0,n(!1)},r=u=>{Ka(u.dataTransfer?.types)&&(s.current+=1,n(!0))},i=u=>{Ka(u.dataTransfer?.types)&&(u.preventDefault(),u.dataTransfer!==null&&(u.dataTransfer.dropEffect="copy"))},l=u=>{Ka(u.dataTransfer?.types)&&(s.current-=1,s.current<=0&&o())},d=u=>{if(!Ka(u.dataTransfer?.types))return;u.preventDefault(),o();const p=u.dataTransfer?.files[0];if(p===void 0)return;const h=Array.from(document.querySelectorAll("[data-seg]")).map(m=>({el:m,index:Number(m.getAttribute("data-seg"))})).sort((m,g)=>m.index-g.index).map(({el:m})=>{const g=m.getBoundingClientRect();return{top:g.top,bottom:g.bottom}});gC(p,fY(u.clientY,h,e))};return window.addEventListener("dragenter",r),window.addEventListener("dragover",i),window.addEventListener("dragleave",l),window.addEventListener("drop",d),window.addEventListener("dragend",o),()=>{window.removeEventListener("dragenter",r),window.removeEventListener("dragover",i),window.removeEventListener("dragleave",l),window.removeEventListener("drop",d),window.removeEventListener("dragend",o)}},[e]),t?w.jsx("div",{className:"stu-dropveil","aria-hidden":"true",children:w.jsxs("div",{className:"stu-dropveil-card",children:[w.jsx("div",{className:"stu-dropveil-title",children:"Drop to import"}),w.jsxs("div",{className:"stu-dropveil-sub",children:[w.jsx("code",{children:".csv"})," → table block · OpenAPI ",w.jsx("code",{children:".yaml"}),"/",w.jsx("code",{children:".json"})," → new doc"]})]})}):null}function XS({index:e,locked:t,onPlus:n}){const s=ke(l=>l.dragging),[o,r]=oe.useState(!1);if(t===!0)return w.jsx("div",{className:"stu-gap stu-gap-locked"});const i=l=>{if(Ka(l.dataTransfer.types))return;l.preventDefault(),r(!1);const d=ke.getState(),u=EQ(l.dataTransfer.getData("text/plain"))??d.dragging;if(d.setDragging(null),u===null)return;const p=u.from;e===p||e===p+1||d.moveBlock(p,e)};return w.jsxs("div",{className:`stu-gap ${s!==null?"stu-gap-armed":""} ${o?"stu-gap-over":""}`,onDragOver:l=>{Ka(l.dataTransfer.types)||(l.preventDefault(),r(!0))},onDragLeave:()=>r(!1),onDrop:i,children:[w.jsx("div",{className:"stu-gap-line"}),s===null&&w.jsx("button",{type:"button",className:"stu-gap-plus","aria-label":"Insert a block here",title:"Insert a block",onClick:l=>{l.stopPropagation();const d=l.currentTarget.getBoundingClientRect();n({index:e,x:d.left+d.width/2,y:d.bottom})},children:w.jsx(dd,{size:13})})]})}function MQ({index:e,text:t,onDone:n}){const[s,o]=oe.useState(t),r=oe.useRef(null),i=ke(d=>d.applyOp);oe.useEffect(()=>{const d=r.current;d!==null&&(d.focus(),d.setSelectionRange(d.value.length,d.value.length),d.style.height="auto",d.style.height=`${d.scrollHeight+2}px`)},[]);const l=()=>{s!==t&&i((d,u)=>J6(d,u,e,s)),n()};return w.jsx("textarea",{ref:r,className:"stu-prose-editor",value:s,onChange:d=>{o(d.target.value),d.target.style.height="auto",d.target.style.height=`${d.target.scrollHeight+2}px`},onBlur:l,onKeyDown:d=>{(d.metaKey||d.ctrlKey)&&d.key==="Enter"&&(d.preventDefault(),l()),d.key==="Escape"&&(d.stopPropagation(),n())}})}function AQ(){const e=ke(t=>t.penMode);return e===null?null:w.jsx("button",{type:"button",className:`stu-tool ${e.on?"stu-tool-on":""}`,title:"Draw a node — sketch a shape on the diagram (D)","aria-label":"Draw a node","aria-pressed":e.on,onClick:()=>ke.getState().setPenMode({seg:e.seg,on:!e.on}),children:w.jsx(gX,{size:13})})}function CQ({index:e,count:t,isMeta:n,metaFirst:s,onEdit:o,onDelete:r}){const i=ke(l=>l.setDragging);return n?w.jsx("div",{className:"stu-blocktools",onClick:l=>l.stopPropagation(),children:w.jsx("button",{type:"button",className:"stu-tool",title:"Edit","aria-label":"Edit",onClick:o,children:w.jsx(P0,{size:13})})}):w.jsxs("div",{className:"stu-blocktools",onClick:l=>l.stopPropagation(),children:[w.jsx("span",{className:"stu-tool stu-tool-grip",title:"Drag to move",draggable:!0,onDragStart:l=>{l.dataTransfer.setData("text/plain",JSON.stringify({kind:"move",from:e})),l.dataTransfer.effectAllowed="move",i({kind:"move",from:e})},onDragEnd:()=>i(null),children:w.jsx(mX,{size:13})}),w.jsx("button",{type:"button",className:"stu-tool",title:"Edit","aria-label":"Edit",onClick:o,children:w.jsx(P0,{size:13})}),w.jsx(AQ,{}),w.jsx("button",{type:"button",className:"stu-tool",title:"Duplicate","aria-label":"Duplicate",onClick:()=>aC(e),children:w.jsx(TC,{size:13})}),w.jsx("button",{type:"button",className:"stu-tool",title:"Move up","aria-label":"Move up",disabled:e===0||s&&e===1,onClick:()=>lC(e),children:w.jsx(vX,{size:13})}),w.jsx("button",{type:"button",className:"stu-tool",title:"Move down","aria-label":"Move down",disabled:e===t-1,onClick:()=>cC(e),children:w.jsx(yX,{size:13})}),w.jsx("button",{type:"button",className:"stu-tool stu-tool-danger",title:"Delete","aria-label":"Delete",onClick:r,children:w.jsx(vx,{size:13})})]})}const NQ={errors:0,warnings:0};function TQ({index:e,count:t,seg:n,html:s,metaFirst:o,levels:r}){const i=ke(D=>D.selection===e),l=ke(D=>D.select),d=ke(D=>D.openSheet),u=ke(D=>D.sheet!==null),[p,h]=oe.useState(!1),[m,g]=oe.useState(null),v=oe.useRef(null),y=n.kind==="markdown",b=!y&&n.kind!=="meta",E=b&&i&&!u&&s!=="",$=n.kind,A=oe.useMemo(()=>b&&$!=="markdown"?wQ(e,$):null,[b,e,$]),T=()=>{y?h(!0):d(e)},N=D=>{if(!pC(n)){dS(e);return}const F=D.currentTarget.getBoundingClientRect();ke.getState().requestDelete({label:Ua(n),anchor:{x:F.left+F.width/2,y:F.bottom},run:()=>dS(e)})};oe.useEffect(()=>{if(!i||u||p)return;const D=F=>{F.key!=="Enter"||F.metaKey||F.ctrlKey||F.altKey||F.shiftKey||wl(F.target)||(F.preventDefault(),T())};return window.addEventListener("keydown",D),()=>window.removeEventListener("keydown",D)},[i,u,p,e,y]);const j=D=>{D.target.closest("a")!==null&&D.preventDefault(),!p&&(l(e),y&&h(!0))},P=D=>{!b||p||u||s===""||E||(D.preventDefault(),l(e),g({x:D.clientX,y:D.clientY}))},I=oe.useCallback(()=>g(null),[]),O=D=>{p||E&&D.target.closest("[data-bp]")!==null||T()};let C;return y&&p?C=w.jsx(MQ,{index:e,text:n.text,onDone:()=>h(!1)}):n.kind==="meta"?C=w.jsxs("div",{className:"stu-placeholder stu-placeholder-meta",children:[w.jsx("span",{className:"stu-placeholder-chip",children:"cover"}),"Document cover — title, subtitle & tag. Double-click to edit."]}):s===""?C=w.jsxs("div",{className:"stu-placeholder stu-placeholder-empty",children:[w.jsx("span",{className:"stu-placeholder-chip",children:n.kind}),"Empty ",n.kind==="markdown"?"text":il[n.kind].toLowerCase()," block — double-click to fill it in."]}):C=w.jsx("div",{className:"stu-seg-html",dangerouslySetInnerHTML:{__html:s}}),w.jsxs("div",{ref:v,className:`stu-seg ${i?"stu-seg-selected":""} ${p?"stu-seg-editing":""} ${!p&&r.errors>0?"stu-seg-err":""}`,"data-seg":e,onClickCapture:j,onDoubleClick:O,onContextMenu:P,children:[!p&&w.jsx(CQ,{index:e,count:t,isMeta:n.kind==="meta",metaFirst:o,onEdit:T,onDelete:N}),!p&&(r.errors>0||r.warnings>0)&&w.jsxs("span",{className:`stu-seg-diag ${r.errors>0?"stu-seg-diag-err":"stu-seg-diag-warn"}`,children:[n.kind==="markdown"?"text":n.kind," ·"," ",r.errors>0?`${r.errors} error${r.errors===1?"":"s"}`:`${r.warnings} warning${r.warnings===1?"":"s"}`]}),C,E&&A!==null&&w.jsx(UC,{host:A,data:n.data,html:s,wrapperRef:v,segIndex:e,pendingMenu:m,onPendingMenuConsumed:I})]})}function _Q(){return w.jsx("div",{className:"stu-hero",children:w.jsxs("div",{className:"stu-hero-card",children:[w.jsx("div",{className:"stu-hero-mark","aria-hidden":"true"}),w.jsx("h1",{children:"Create your first doc"}),w.jsxs("p",{children:["This project has no docs yet. Open the doc switcher in the top bar and pick"," ",w.jsx("strong",{children:"New doc"}),", or run ",w.jsx("code",{children:"chiltepin init"})," in your terminal."]})]})})}function LQ(){const{doc:e,rendered:t,renderError:n,diagnostics:s}=Co(),o=ke(y=>y.source),r=ke(y=>y.docs),i=ke(y=>y.loaded),l=ke(y=>y.currentSlug),d=ke(y=>y.select),u=ke(y=>y.slashHintAt),p=GA(),h=u!==null&&!cY(),m=oe.useMemo(()=>SQ(s,o,e),[s,o,e]);if(i&&r.length===0)return w.jsxs("main",{className:"stu-canvas",children:[w.jsx(_Q,{}),w.jsx(YS,{minIndex:0})]});if(l===null||t===null)return w.jsx("main",{className:"stu-canvas",children:n!==null&&w.jsxs("div",{className:"stu-render-error",children:["Render failed: ",n]})});const g=e.segments.length,v=e.segments[0]?.kind==="meta";return w.jsxs("main",{className:"stu-canvas","data-tour":"canvas",onClick:()=>d(null),children:[w.jsx("style",{children:t.css}),w.jsx("div",{className:"stu-page","data-doc-theme":Mh(p==="dark"),onClick:y=>y.stopPropagation(),children:w.jsxs("div",{className:"docskin",children:[w.jsx("div",{dangerouslySetInnerHTML:{__html:t.defs}}),v?w.jsxs("div",{className:"stu-cover",role:"button",tabIndex:0,title:"Edit the cover — title, subtitle & tag",onClick:y=>{y.stopPropagation(),ke.getState().openSheet(0)},onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),ke.getState().openSheet(0))},children:[w.jsx("div",{dangerouslySetInnerHTML:{__html:t.cover}}),w.jsx("span",{className:"stu-cover-edit",children:"✎ Edit cover"})]}):w.jsx("div",{dangerouslySetInnerHTML:{__html:t.cover}}),w.jsx(XS,{index:0,locked:v,onPlus:Vv}),e.segments.map((y,b)=>w.jsxs("div",{children:[!(v&&b===0)&&w.jsx(TQ,{index:b,count:g,seg:y,html:t.segments[b]?.html??"",metaFirst:v,levels:m[b]??NQ}),h&&u===b&&w.jsxs("div",{className:"stu-slash-next",role:"note",children:["press ",w.jsx("kbd",{children:"/"})," for the next block"]}),w.jsx(XS,{index:b+1,onPlus:Vv})]},b)),g===0&&w.jsxs("div",{className:"stu-ghost",children:[w.jsx("button",{type:"button",className:"stu-ghost-plus","aria-label":"Add your first block",onClick:y=>{y.stopPropagation();const b=y.currentTarget.getBoundingClientRect();Vv({index:0,x:b.left+b.width/2,y:b.bottom})},children:w.jsx(dd,{size:16})}),w.jsxs("span",{children:["Press ",w.jsx("kbd",{children:"+"})," or ",w.jsx("kbd",{children:"/"})," to add your first block"]})]})]})}),w.jsx(YS,{minIndex:v?1:0})]})}function GC(e,t){return"```"+e+`
3254
+ `).length+1)),spellCheck:!1,onChange:d=>{o(d.target.value),i(null)},onBlur:l,onKeyDown:d=>{(d.metaKey||d.ctrlKey)&&d.key==="Enter"&&(d.preventDefault(),l())}}),r!==null&&w.jsx("div",{className:"stu-dx-err",children:r})]})}function TX({host:e,root:t,data:n,path:s,anchor:o,focusField:r,onClose:i,onMovedTo:l,onRemoveItem:d}){const u=oe.useRef(null),[p,h]=oe.useState(null),m=hx(t,s),g=is(n,s),v=tC(s),y=v?s.slice(0,-1):null,b=y!==null?RS(is(n,y)).length:0,E=v?s[s.length-1]:-1;oe.useLayoutEffect(()=>{const P=u.current,I=P?.offsetParent;if(P===null||I===null)return;const O=I.getBoundingClientRect(),C=P.offsetHeight,D=8;let F=o.left;const U=O.width-Ep-4;F>U&&(F=Math.max(0,U));const X=O.left+F;X+Ep>window.innerWidth-D&&(F-=X+Ep-(window.innerWidth-D));let B=o.top+o.height+6;O.top+B+C>window.innerHeight-D&&o.top-C-6>=0&&(B=o.top-C-6),h({left:Math.max(0,F),top:B})},[o.left,o.top,o.height,s.join(".")]),oe.useEffect(()=>{if(p===null)return;const P=u.current;if(P===null||P.contains(document.activeElement))return;((r!==void 0?P.querySelector(`[data-dx-field="${CSS.escape(r)}"]`):P)??P).querySelector("textarea, input, select")?.focus()},[p,r]),oe.useEffect(()=>{const P=I=>{if(I.key==="Escape"){const O=I.target instanceof HTMLElement?I.target:null;if(O!==null&&O.closest('[data-combo-open="true"]')!==null)return;I.stopPropagation(),I.preventDefault(),i()}};return window.addEventListener("keydown",P,!0),()=>window.removeEventListener("keydown",P,!0)},[i]);const $=P=>{const I=u.current;if(I===null)return;const O=P.target;if(P.key==="Tab"){const C=Bf(I);if(C.length===0)return;const D=C.indexOf(O);P.preventDefault();const F=P.shiftKey?C[D<=0?C.length-1:D-1]:C[D<0||D>=C.length-1?0:D+1];zf(F);return}if(P.key==="Enter"){const C=P.metaKey||P.ctrlKey;if(O.tagName==="TEXTAREA"&&!C)return;window.setTimeout(()=>{const D=Bf(I),F=D.indexOf(document.activeElement);F>=0&&F<D.length-1?zf(D[F+1]):i()},0)}};oe.useEffect(()=>{const P=I=>{const O=u.current;O!==null&&I.target instanceof Node&&!O.contains(I.target)&&setTimeout(i,0)};return document.addEventListener("pointerdown",P,!0),()=>document.removeEventListener("pointerdown",P,!0)},[i]);const A=P=>{if(y===null)return;const I=RS(is(n,y)).slice(),O=E+P;if(O<0||O>=I.length)return;const[C]=I.splice(E,1);I.splice(O,0,C),e.commitPath(y,I),l?.([...y,O].join(".")),i()},T=m!==null&&m.kind==="union"?_h(m,g):null,N=m!==null&&m.kind==="object"?m:T!==null&&g!==null&&typeof g=="object"&&!Array.isArray(g)?T:null;let j;if(m!==null&&(m.kind==="string"||m.kind==="number"||m.kind==="boolean"||m.kind==="enum"))j=w.jsx(Ja,{resolved:Za({blockKind:e.kind,name:OS(s),node:m,value:g,data:n,path:s}),node:m,value:g,optional:m.optional,autoFocus:!0,handlers:{onCommit:P=>e.commitPath(s,P),onDelete:()=>e.deletePath(s),onDone:i}});else if(N!==null){const P=_X(g),{visible:I,hidden:O}=tY(N.fields,g,4,r),C=r!==void 0&&I.some(D=>D.name===r)?r:I[0]?.name;j=w.jsxs("div",{className:"stu-dx-fields",children:[I.map(D=>w.jsxs("div",{className:"stu-dx-field","data-dx-field":D.name,children:[w.jsx("label",{className:"stu-dx-label",children:$o(D.name)}),w.jsx(Ja,{resolved:Za({blockKind:e.kind,name:D.name,node:D.node,value:P[D.name],data:n,path:[...s,D.name]}),node:D.node,value:P[D.name],optional:D.node.optional,autoFocus:D.name===C,handlers:{onCommit:F=>e.commitPath([...s,D.name],F),onDelete:()=>e.deletePath([...s,D.name])}})]},D.name)),O>0&&w.jsx("button",{type:"button",className:"stu-linkbtn stu-dx-more",tabIndex:-1,onClick:()=>{i(),e.openFull()},children:"More fields in the editor…"})]})}else if(g==null||typeof g!="object"){const P=m!==null&&m.kind!=="array"?m:null;j=w.jsx(Ja,{resolved:Za({blockKind:e.kind,name:OS(s),node:P,value:g,data:n,path:s}),node:P,value:g,optional:P?.optional??!0,autoFocus:!0,handlers:{onCommit:I=>e.commitPath(s,I),onDone:i}})}else j=w.jsxs(w.Fragment,{children:[w.jsx(NX,{value:g,onCommit:P=>e.commitPath(s,P)}),w.jsx("button",{type:"button",className:"stu-linkbtn stu-dx-more",onClick:()=>{i(),e.openFull()},children:"Edit block YAML"})]});return w.jsxs("div",{ref:u,className:"stu-dx-pop",role:"dialog","aria-label":`Edit ${Pr(s)}`,style:{width:Ep,left:p?.left??o.left,top:p?.top??o.top+o.height+6,visibility:p===null?"hidden":"visible"},onClick:P=>P.stopPropagation(),onPointerMove:P=>P.stopPropagation(),onKeyDown:$,children:[w.jsxs("div",{className:"stu-dx-pop-head",children:[w.jsx("span",{className:"stu-dx-pop-title",children:Pr(s)}),v&&w.jsxs("span",{className:"stu-dx-pop-tools",children:[w.jsx("button",{type:"button","aria-label":"Move up",tabIndex:-1,disabled:E<=0,onClick:()=>A(-1),children:"↑"}),w.jsx("button",{type:"button","aria-label":"Move down",tabIndex:-1,disabled:E>=b-1,onClick:()=>A(1),children:"↓"}),w.jsx("button",{type:"button",className:"stu-dx-remove-btn","aria-label":"Remove item",tabIndex:-1,onClick:()=>{d!==void 0?d():e.deletePath(s),i()},children:w.jsx(vx,{size:12})})]})]}),j]})}function _X(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:{}}function RS(e){return Array.isArray(e)?e:[]}const DS={ghost:null,drop:null,snap:null};function Xp(e,t){const n=e.getBoundingClientRect(),s=t.getBoundingClientRect();return{left:n.left-s.left,top:n.top-s.top,width:n.width,height:n.height}}function qi(e,t){return e.querySelector(`[data-bp="${CSS.escape(t)}"]`)}function Va(e,t,n){const s=[];for(let o=0;o<n;o++){const r=qi(e,`${t}.${o}`);if(r===null)return null;s.push(Xp(r,e))}return s}function Ts(e,t){const n=is(e,Dn(t));return Array.isArray(n)?n:null}function Nn(e,t){const n=e.getAttribute(t);if(n===null)return null;const s=Number(n);return Number.isFinite(s)?s:null}function Ao(e){const t=Nn(e,"data-cell-w"),n=Nn(e,"data-cell-h"),s=Nn(e,"data-gap-x"),o=Nn(e,"data-gap-y"),r=Nn(e,"data-pad-x"),i=Nn(e,"data-pad-top"),l=Nn(e,"data-cols"),d=Nn(e,"data-rows");if(t===null||n===null||s===null||o===null||r===null||i===null||l===null||d===null)return null;const u=e.viewBox.baseVal.width,p=e.getBoundingClientRect().width;return u<=0||p<=0?null:{cellW:t,cellH:n,gapX:s,gapY:o,padX:r,padTop:i,cols:l,rows:d,scale:p/u}}function xx(e,t,n){const s=[];for(let o=0;o<n;o++){const r=qi(e,`${t}.${o}`);if(r===null)return null;const i=Nn(r,"data-col"),l=Nn(r,"data-row");if(i===null||l===null)return null;s.push({col:i,row:l})}return s}function LX(e){const t=(e.textContent??"").replace(/\s+/g," ").trim();return t.length>42?`${t.slice(0,41)}…`:t}function kx(e,t,n){const s=Tf(t,n);if(s===null)return null;if(s.mode==="grid-node"||s.mode==="grid-group"){const o=s.mode==="grid-node"?`${s.listPath}.${s.index}`:`groups.${s.index}`,i=qi(e,o)?.closest("svg");if(i==null||!i.hasAttribute("data-grid"))return null}return s}function IX(e){const{host:t,data:n,html:s,wrapperRef:o,editorOpenRef:r,suppressClickRef:i,dragActiveRef:l,onDragStart:d,onDrop:u}=e,[p,h]=oe.useState(DS),m=oe.useRef(null),g=oe.useRef({host:t,data:n,onDragStart:d,onDrop:u});return g.current={host:t,data:n,onDragStart:d,onDrop:u},oe.useEffect(()=>{const v=o.current;if(v===null)return;const y=()=>{const P=m.current;m.current=null,l.current=!1,P!==null&&P.active&&(document.body.style.userSelect="",v.style.cursor=""),h(DS),window.removeEventListener("pointermove",$),window.removeEventListener("pointerup",T),window.removeEventListener("pointercancel",N),window.removeEventListener("keydown",b,!0)},b=P=>{P.key==="Escape"&&m.current?.active===!0&&(P.preventDefault(),P.stopPropagation(),y())},E=P=>{const I=g.current.data,O=P.target;if(O.mode==="reorder"||O.mode==="table-cols"){const B=O.mode==="table-cols"?"columns":O.listPath,te=Ts(I,B);if(te===null||te.length<2)return null;const ee=Va(v,B,te.length);if(ee===null)return null;const H=O.mode==="table-cols"?"x":ux(ee);return{kind:"reorder",compound:O.mode==="table-cols",listPath:B,index:O.index,axis:H,boxes:ee,centers:oS(ee,H),gap:null}}if(O.mode==="kanban-card"){const B=Ts(I,"columns");if(B===null||B.length===0)return null;const te=Va(v,"columns",B.length);if(te===null)return null;const ee=B.map((H,W)=>{const K=Array.isArray(H?.cards)?H.cards:[];return Va(v,`columns.${W}.cards`,K.length)??[]});return{kind:"kanban-card",col:O.col,index:O.index,colBoxes:te,cardBoxes:ee,to:null}}if(O.mode==="grid-group"){const B=P.itemEl.closest("svg");if(B===null||!B.hasAttribute("data-grid"))return null;const te=Ao(B);if(te===null)return null;const ee=Ji(I,O.index);if(ee===null)return null;const H=Xp(B,v),W=v.getBoundingClientRect(),K=wo(te,P.startX-W.left-H.left,P.startY-W.top-H.top);return{kind:"grid-group",index:O.index,geom:te,svgBox:H,range:ee,startCell:K,target:null}}if(O.mode==="ring"){const B=Ts(I,O.listPath);if(B===null||B.length<2)return null;const te=Va(v,O.listPath,B.length);return te===null?null:{kind:"ring",listPath:O.listPath,index:O.index,centers:te.map(ee=>({x:ee.left+ee.width/2,y:ee.top+ee.height/2})),gap:null}}const C=P.itemEl.closest("svg");if(C===null||!C.hasAttribute("data-grid"))return null;const D=Ao(C);if(D===null)return null;const F=$n(g.current.host.kind),U=Ts(I,O.listPath);if(U===null)return null;const X=xx(v,O.listPath,U.length);return X===null?null:{kind:"grid-node",listPath:O.listPath,index:O.index,geom:D,svgBox:Xp(C,v),placements:X,quick:C.hasAttribute("data-grid-auto"),w:Nn(P.itemEl,"data-w")??1,growRows:F?.growRows!==!1,writeCell:F?.writeCell??ix,cell:null}},$=P=>{const I=m.current;if(I===null||P.pointerId!==I.pointerId)return;if(!I.active){if(!Ch(P.clientX-I.startX,P.clientY-I.startY))return;const ee=E(I);if(ee===null){m.current=null;return}I.ctx=ee,I.active=!0,I.startBox=Xp(I.itemEl,v),I.label=LX(I.itemEl),l.current=!0,i.current=!0,document.body.style.userSelect="none",v.style.cursor="grabbing",g.current.onDragStart()}const O=v.getBoundingClientRect(),C=P.clientX-O.left,D=P.clientY-O.top,F={box:{left:I.startBox.left+(P.clientX-I.startX),top:I.startBox.top+(P.clientY-I.startY),width:I.startBox.width,height:I.startBox.height},label:I.label},U=I.ctx;if(U.kind==="ring"){if(U.gap=CG(U.centers,C,D),U.gap===null)return;const ee=NG(U.centers,U.gap);h({ghost:F,drop:{left:ee.x-5,top:ee.y-5,width:10,height:10},snap:null});return}if(U.kind==="grid-group"){const ee=wo(U.geom,C-U.svgBox.left,D-U.svgBox.top),H=$C(U.range,ee.col-U.startCell.col,ee.row-U.startCell.row,U.geom.cols,U.geom.rows);U.target=H;const W=gx(U.geom,H);h({ghost:F,drop:null,snap:{left:U.svgBox.left+W.left,top:U.svgBox.top+W.top,width:W.width,height:W.height}});return}if(U.kind==="reorder"){const ee=U.axis==="x"?C:D;U.gap=rS(U.centers,ee);const H=iS(U.boxes,U.axis,U.gap),W=Math.min(...U.boxes.map(z=>U.axis==="x"?z.top:z.left))-4,K=Math.max(...U.boxes.map(z=>U.axis==="x"?z.top+z.height:z.left+z.width))+4,R=U.axis==="x"?{left:H-1.5,top:W,width:3,height:K-W}:{left:W,top:H-1.5,width:K-W,height:3};h({ghost:F,drop:R,snap:null});return}if(U.kind==="kanban-card"){let ee=U.colBoxes.findIndex(Y=>C>=Y.left&&C<=Y.left+Y.width);if(ee<0){let Y=1/0;U.colBoxes.forEach((V,re)=>{const Q=Math.abs(C-(V.left+V.width/2));Q<Y&&(Y=Q,ee=re)})}const H=U.cardBoxes[ee]??[],W=rS(oS(H,"y"),D);U.to={col:ee,gap:W};const K=U.colBoxes[ee],R=H.length>0?iS(H,"y",W):K.top+Math.min(38,K.height-8),z={left:K.left+6,top:R-1.5,width:K.width-12,height:3};h({ghost:F,drop:z,snap:null});return}const X=wo(U.geom,C-U.svgBox.left,D-U.svgBox.top),B=U.growRows?X:{col:X.col,row:Math.min(X.row,U.geom.rows)};U.cell=B;const te=_f(U.geom,B.col,B.row,U.w);h({ghost:F,drop:null,snap:{left:U.svgBox.left+te.left,top:U.svgBox.top+te.top,width:te.width,height:te.height}})},A=P=>{const{host:I,data:O}=g.current,C=P.ctx;if(C===null)return null;if(C.kind==="reorder"){if(C.gap===null)return null;if(C.compound){const X=YA(O,C.index,C.gap);return X===null?null:(I.commitPaths(X),Wv("columns",C.index,C.gap))}const F=Ts(O,C.listPath);if(F===null)return null;const U=Vr(F,C.index,C.gap);return U===null?null:(I.commitPath([C.listPath],U),Wv(C.listPath,C.index,C.gap))}if(C.kind==="kanban-card"){if(C.to===null)return null;const F=_0(O,C.col,C.index,C.to.col,C.to.gap);return F===null?null:(I.commitPaths(F),zG({fromCol:C.col,fromIdx:C.index,toCol:C.to.col,gap:C.to.gap,targetLen:(C.cardBoxes[C.to.col]??[]).length}))}if(C.kind==="grid-group"){if(C.target===null)return null;const F=EC(O,C.index,C.target);return F===null?null:(I.commitPaths(F),`groups.${C.index}`)}if(C.kind==="ring"){if(C.gap===null)return null;const F=Ts(O,C.listPath);if(F===null)return null;const U=Vr(F,C.index,C.gap);return U===null?null:(I.commitPath([C.listPath],U),Wv(C.listPath,C.index,C.gap))}if(C.cell===null)return null;const D=XA({placements:C.placements,index:C.index,target:C.cell,quick:C.quick,field:C.listPath,writeCell:C.writeCell});return D===null?null:(I.commitPaths(D.sets),D.materialized&&I.notify?.(px),`${C.listPath}.${C.index}`)},T=P=>{const I=m.current;if(!(I===null||P.pointerId!==I.pointerId)){if(I.active){const O=A(I);O!==null&&g.current.onDrop?.(O)}y()}},N=()=>y(),j=P=>{if(P.button!==0||m.current!==null||(i.current=!1,r.current)||!(P.target instanceof Element)||P.target.closest(".stu-dx-overlay")!==null)return;const I=P.target.closest("[data-bp]");if(I===null||!v.contains(I))return;const O=I.getAttribute("data-bp")??"",C=kx(v,t.kind,O);if(C===null)return;const D=C.mode==="table-cols"?`columns.${C.index}`:C.mode==="kanban-card"?`columns.${C.col}.cards.${C.index}`:C.mode==="grid-group"?`groups.${C.index}`:`${C.listPath}.${C.index}`,F=qi(v,D);F!==null&&(m.current={pointerId:P.pointerId,startX:P.clientX,startY:P.clientY,path:O,target:C,itemEl:F,active:!1,startBox:{left:0,top:0,width:0,height:0},label:"",ctx:null},window.addEventListener("pointermove",$),window.addEventListener("pointerup",T),window.addEventListener("pointercancel",N),window.addEventListener("keydown",b,!0))};return v.addEventListener("pointerdown",j),()=>{v.removeEventListener("pointerdown",j),y()}},[o,t.kind,s]),p}function R0(e){const{wrap:t,host:n,data:s,path:o,key:r}=e,i=kx(t,n.kind,o);if(i===null)return null;const l=r==="ArrowLeft"||r==="ArrowUp"?-1:1,d=r==="ArrowLeft"||r==="ArrowRight";if(i.mode==="reorder"||i.mode==="table-cols"){const A=i.mode==="table-cols"?"columns":i.listPath,T=Ts(s,A);if(T===null)return null;const N=Va(t,A,T.length);if(N===null||(i.mode==="table-cols"?"x":ux(N))==="x"!==d)return null;const P=l<0?i.index-1:i.index+2;if(i.mode==="table-cols"){const O=YA(s,i.index,P);return O===null?null:(n.commitPaths(O),`columns.${i.index+l}`)}const I=Vr(T,i.index,P);return I===null?null:(n.commitPath([A],I),`${A}.${i.index+l}`)}if(i.mode==="kanban-card"){if(!d){const O=l<0?i.index-1:i.index+2,C=_0(s,i.col,i.index,i.col,O);return C===null?null:(n.commitPaths(C),`columns.${i.col}.cards.${i.index+l}`)}const A=Ts(s,"columns"),T=i.col+l;if(A===null||T<0||T>=A.length)return null;const N=A[T]?.cards,j=Array.isArray(N)?N.length:0,P=Math.min(i.index,j),I=_0(s,i.col,i.index,T,P);return I===null?null:(n.commitPaths(I),`columns.${T}.cards.${P}`)}if(i.mode==="grid-group"){const T=qi(t,`groups.${i.index}`)?.closest("svg");if(T==null)return null;const N=Ao(T),j=N!==null?Ji(s,i.index):null;if(N===null||j===null)return null;const P=$C(j,d?l:0,d?0:l,N.cols,N.rows),I=EC(s,i.index,P);return I===null?null:(n.commitPaths(I),o)}if(i.mode==="ring"){const A=Ts(s,i.listPath);if(A===null)return null;const T=l<0?i.index-1:i.index+2,N=Vr(A,i.index,T);return N===null?null:(n.commitPath([i.listPath],N),`${i.listPath}.${i.index+l}`)}const u=$n(n.kind),h=qi(t,`${i.listPath}.${i.index}`)?.closest("svg");if(h==null)return null;const m=Ao(h),g=Ts(s,i.listPath);if(m===null||g===null)return null;const v=xx(t,i.listPath,g.length);if(v===null)return null;const y=v[i.index];if(y===void 0)return null;const b=u?.growRows===!1?m.rows:m.rows+1,E={col:Math.max(1,Math.min(m.cols+1,y.col+(d?l:0))),row:Math.max(1,Math.min(b,y.row+(d?0:l)))},$=XA({placements:v,index:i.index,target:E,quick:h.hasAttribute("data-grid-auto"),field:i.listPath,writeCell:u?.writeCell??ix});return $===null?null:(n.commitPaths($.sets),$.materialized&&n.notify?.(px),o)}function jX(e){const{wrap:t,host:n,data:s,path:o,key:r}=e,i=jf(n.kind,o);if(i.kind==="inert")return null;if(i.kind==="grid-group"&&e.grow===!0){const u=qi(t,`groups.${i.index}`)?.closest("svg");if(u==null)return null;const p=Ao(u),h=p!==null?Ji(s,i.index):null;if(p===null||h===null)return null;const v=DY(h,r==="ArrowLeft"||r==="ArrowRight"?"x":"y",r==="ArrowLeft"||r==="ArrowUp"?-1:1,p.cols,p.rows),y=v!==null?SC(s,i.index,v):null;return y===null?null:(n.commitPaths(y),{path:o,moved:!0})}if(i.kind==="table-cell"){const d=Ts(s,"rows");if(d===null)return null;const u=BG({row:i.row,col:i.col,key:r,rowCount:d.length,colsInRow:p=>Array.isArray(d[p])?d[p].length:0});return u===null?null:{path:`rows.${u.row}.${u.col}`,moved:!1}}if(i.kind==="grid"&&`${i.listPath}.${i.index}`!==o)return R0({wrap:t,host:n,data:s,path:`${i.listPath}.${i.index}`,key:r})===null?null:{path:o,moved:!0};if(i.kind==="item"&&Tf(n.kind,o)===null){const d=Ts(s,i.listPath);if(d===null)return null;const u=Va(t,i.listPath,d.length);if(u===null)return null;const p=DG({axis:ux(u),key:r,index:i.index,length:d.length});if(p===null)return null;const h=Vr(d,i.index,p.gap);return h===null?null:(n.commitPath(Dn(i.listPath),h),{path:`${i.listPath}.${p.newIndex}${i.suffix??""}`,moved:!0})}const l=R0({wrap:t,host:n,data:s,path:o,key:r});return l===null?null:{path:l,moved:!0}}const BS={wire:null,target:null,snap:null,picker:null};function Kv(e,t){const n=e.getBoundingClientRect(),s=t.getBoundingClientRect();return{left:n.left-s.left,top:n.top-s.top,width:n.width,height:n.height}}function Mp(e,t){return e.querySelector(`[data-bp="${CSS.escape(t)}"]`)}function Ec(e,t){const s=(t!==null&&typeof t=="object"?t:{})[e.nodesField];return Array.isArray(s)?s.map(o=>{const r=o!==null&&typeof o=="object"?o[e.idField]:void 0;return typeof r=="string"?r:""}):[]}function PX(e){const{host:t,data:n,html:s,wrapperRef:o,suppressClickRef:r,dragActiveRef:i,onConnectStart:l,onNodeCreated:d,onEdgeCreated:u}=e,p=$n(t.kind),[h,m]=oe.useState(BS),g=oe.useRef(null),v=oe.useRef(null),y=oe.useRef(!1),b=oe.useRef({host:t,data:n,spec:p,onConnectStart:l,onNodeCreated:d,onEdgeCreated:u});b.current={host:t,data:n,spec:p,onConnectStart:l,onNodeCreated:d,onEdgeCreated:u};const E=oe.useRef(()=>{}),$=oe.useRef(()=>{}),A=oe.useRef(null),T=oe.useRef(null);oe.useEffect(()=>{const I=o.current;if(I===null||p===null)return;const O=()=>{v.current=null,y.current=!1,window.removeEventListener("pointerdown",F,!0)},C=()=>{const Y=g.current;g.current=null,i.current=!1,Y!==null&&Y.active&&(document.body.style.userSelect="",I.style.cursor=""),O(),m(BS),window.removeEventListener("pointermove",H),window.removeEventListener("pointerup",W),window.removeEventListener("pointercancel",K),window.removeEventListener("keydown",D,!0)};E.current=C;const D=Y=>{Y.key==="Escape"&&g.current?.active===!0&&(Y.preventDefault(),Y.stopPropagation(),C())},F=Y=>{Y.target instanceof Element&&Y.target.closest(".stu-dx-connect-picker")!==null||(r.current=!0,C())},U=Y=>Array.from({length:Y},(V,re)=>{const Q=Mp(I,`${p.nodesField}.${re}`);return Q===null?null:Kv(Q,I)}),X=(Y,V)=>Y.pointerId===-1||V.pointerId===Y.pointerId,B=Y=>{Y.active=!0,Y.boxes=U(Ec(p,b.current.data).length);const V=Mp(I,`${p.nodesField}.${Y.fromIndex}`)?.closest("svg")??null;if(Y.geom=V!==null?Ao(V):null,Y.svgBox=V!==null?Kv(V,I):null,p.columnTargets===!0&&Y.svgBox!==null){const re=Y.svgBox.top+Y.svgBox.height;Y.boxes=Y.boxes.map(Q=>Q===null?null:{...Q,height:re-Q.top})}i.current=!0,r.current=!0,document.body.style.userSelect="none",I.style.cursor="crosshair",b.current.onConnectStart()},te=()=>{y.current=!0,document.body.style.userSelect="",I.style.cursor="",i.current=!1,window.removeEventListener("pointermove",H),window.removeEventListener("pointerup",W),window.removeEventListener("pointercancel",K),window.removeEventListener("keydown",D,!0),window.addEventListener("pointerdown",F,!0)},ee=(Y,V,re,Q,ne)=>{v.current={mode:"edge",left:Q,top:ne,fromId:Y,toId:V},m({wire:{x1:re.x,y1:re.y,x2:Q,y2:ne},target:null,snap:null,picker:{left:Q,top:ne,title:"Cardinality",items:p.edgeChoices??[]}}),te()},H=Y=>{const V=g.current;if(V===null||!X(V,Y)||v.current!==null)return;if(!V.active){if(!Ch(Y.clientX-V.startX,Y.clientY-V.startY))return;B(V)}const re=I.getBoundingClientRect(),Q=Y.clientX-re.left,ne=Y.clientY-re.top;let Z=null;V.boxes.forEach((de,le)=>{de!==null&&Q>=de.left&&Q<=de.left+de.width&&ne>=de.top&&ne<=de.top+de.height&&(Z=le)}),Z===V.fromIndex&&!p.allowSelfLoop&&(Z=null),V.targetIndex=Z;let q=null;if(Z===null&&V.geom!==null&&V.svgBox!==null&&p.newNode!==void 0){const de=wo(V.geom,Q-V.svgBox.left,ne-V.svgBox.top),le=p.growRows===!1?{col:de.col,row:Math.min(de.row,V.geom.rows)}:de,J=_f(V.geom,le.col,le.row);q={left:V.svgBox.left+J.left,top:V.svgBox.top+J.top,width:J.width,height:J.height}}m({wire:{x1:V.anchor.x,y1:V.anchor.y,x2:Q,y2:ne},target:Z!==null?V.boxes[Z]:null,snap:q,picker:null})},W=Y=>{const V=g.current;if(V===null||!X(V,Y)||v.current!==null)return;if(!V.active){C();return}const{host:re,data:Q}=b.current,ne=I.getBoundingClientRect(),Z=Y.clientX-ne.left,q=Y.clientY-ne.top;if(V.targetIndex!==null){const ue=Ec(p,Q)[V.targetIndex]??"";if(ue===""){C();return}if(p.edgeChoices!==void 0&&p.edgeChoices.length>0){if(Gp(p,Q,V.fromId,ue)===null){re.notify?.(`${no(p,Q,V.fromId)} and ${no(p,Q,ue)} are already connected`),C();return}ee(V.fromId,ue,V.anchor,Z,q);return}const ve=Gp(p,Q,V.fromId,ue);if(ve===null)re.notify?.(`${no(p,Q,V.fromId)} and ${no(p,Q,ue)} are already connected`);else if(re.commitPaths(ve),p.editEdgeOnConnect===!0){const we=ve[0]?.path[1];typeof we=="number"&&b.current.onEdgeCreated?.(`${p.edgesField}.${we}`,p.edgeTextField)}else re.notify?.(`Connected ${no(p,Q,V.fromId)} → ${no(p,Q,ue)}`);C();return}if(V.geom===null||V.svgBox===null||p.newNode===void 0||p.nodeKinds.length===0){C();return}const de=wo(V.geom,Z-V.svgBox.left,q-V.svgBox.top),le=p.growRows===!1?{col:de.col,row:Math.min(de.row,V.geom.rows)}:de,J=_f(V.geom,le.col,le.row);if(p.nodeKinds.length===1){v.current={mode:"node",left:Z,top:q,cell:le,fromId:V.fromId,fromIndex:V.fromIndex},$.current(p.nodeKinds[0].kind);return}v.current={mode:"node",left:Z,top:q,cell:le,fromId:V.fromId,fromIndex:V.fromIndex},m({wire:{x1:V.anchor.x,y1:V.anchor.y,x2:Z,y2:q},target:null,snap:{left:V.svgBox.left+J.left,top:V.svgBox.top+J.top,width:J.width,height:J.height},picker:{left:Z,top:q,title:"Add & connect",items:p.nodeKinds.map(ue=>({value:ue.kind,label:ue.label}))}}),te()},K=()=>C(),R=(Y,V,re)=>{if(g.current!==null||v.current!==null)return;const Q=Ec(p,b.current.data)[V]??"";Q!==""&&(r.current=!1,g.current={pointerId:Y.pointerId,startX:Y.clientX,startY:Y.clientY,fromIndex:V,fromId:Q,anchor:re,active:!1,boxes:[],targetIndex:null,geom:null,svgBox:null},window.addEventListener("pointermove",H),window.addEventListener("pointerup",W),window.addEventListener("pointercancel",K),window.addEventListener("keydown",D,!0))};A.current=R;const z=Y=>{if(g.current!==null||v.current!==null)return;const V=Ec(p,b.current.data)[Y]??"",re=Mp(I,`${p.nodesField}.${Y}`);if(V===""||re===null)return;const Q=Kv(re,I),ne={x:Q.left+Q.width/2,y:Q.top+Q.height/2};r.current=!1;const Z={pointerId:-1,startX:0,startY:0,fromIndex:Y,fromId:V,anchor:ne,active:!1,boxes:[],targetIndex:null,geom:null,svgBox:null};g.current=Z,B(Z),m({wire:{x1:ne.x,y1:ne.y,x2:ne.x,y2:ne.y},target:null,snap:null,picker:null}),window.addEventListener("pointermove",H),window.addEventListener("pointerup",W),window.addEventListener("pointercancel",K),window.addEventListener("keydown",D,!0)};return T.current=z,()=>{C(),A.current=null,T.current=null}},[o,t.kind,p,s,i,r]);const N=I=>{const O=o.current,C=v.current;if(O===null||C===null||C.mode!=="node"||p===null)return;const{host:D,data:F,onNodeCreated:U}=b.current,X=Ec(p,F).length;let B=[];for(let W=0;W<X;W++){const K=Mp(O,`${p.nodesField}.${W}`),R=K!==null?Nn(K,"data-col"):null,z=K!==null?Nn(K,"data-row"):null;if(R===null||z===null){B=void 0;break}B.push({col:R,row:z})}const te=Nf(p,F,C.fromId,C.cell,I,B);if(E.current(),te===null)return;D.commitPaths(te.sets),te.materialized&&D.notify?.(px);const ee=p.nodeKinds.find(W=>W.kind===I),H=ee!==void 0?`New ${ee.label.toLowerCase()}`:te.id;D.notify?.(`Connected ${no(p,F,C.fromId)} → ${H}`),U(te.nodePath,p.labelField)};$.current=N;const j=I=>{const O=v.current;if(O===null||O.mode!=="edge"||p===null)return;const{host:C,data:D}=b.current,F=p.edgeChoiceField!==void 0?{[p.edgeChoiceField]:I}:void 0,U=Gp(p,D,O.fromId,O.toId,F);E.current(),U!==null&&(C.commitPaths(U),C.notify?.(`Connected ${no(p,D,O.fromId)} → ${no(p,D,O.toId)} (${I})`))};return{visuals:h,spec:p,start:(I,O,C)=>A.current?.(I.nativeEvent,O,C),armFrom:I=>T.current?.(I),pickerOpenRef:y,cancelPicker:()=>E.current(),choose:I=>{v.current?.mode==="edge"?j(I):N(I)}}}const jC=["rect","diamond","pill","ellipse","cylinder","hexagon","triangle"],Ff=64,D0=250,PC=Ff*4,OX=.8,RX=.7,zS=15*Math.PI/180,DX=2*Math.PI/180,_r=.5*(-1+Math.sqrt(5)),BX=.92,FS=5*Math.PI,zX=20,FX=5,qX=.08,HX=9,qS=.7,OC=.3,RC=5;function Gr(e,t){return Math.hypot(e.x-t.x,e.y-t.y)}function bx(e){let t=0;for(let n=1;n<e.length;n++)t+=Gr(e[n-1],e[n]);return t}function DC(e){let t=0,n=0;for(const s of e)t+=s.x,n+=s.y;return{x:t/e.length,y:n/e.length}}function wx(e){let t=1/0,n=1/0,s=-1/0,o=-1/0;for(const r of e)r.x<t&&(t=r.x),r.y<n&&(n=r.y),r.x>s&&(s=r.x),r.y>o&&(o=r.y);return{minX:t,minY:n,maxX:s,maxY:o}}function $x(e,t){const n=e.map(i=>({x:i.x,y:i.y})),s=bx(n)/(t-1);if(s<=0)return Array.from({length:t},()=>({...n[0]}));let o=0;const r=[{...n[0]}];for(let i=1;i<n.length;i++){const l=n[i-1],d=n[i],u=Gr(l,d);if(o+u>=s&&u>0){const p=(s-o)/u,h={x:l.x+p*(d.x-l.x),y:l.y+p*(d.y-l.y)};r.push(h),n.splice(i,0,h),o=0}else o+=u}for(;r.length<t;)r.push({...n[n.length-1]});return r.slice(0,t)}function WX(e){const t=wx(e),n=D0/Math.max(t.maxX-t.minX,t.maxY-t.minY,1e-6);return e.map(s=>({x:s.x*n,y:s.y*n}))}function UX(e){const t=DC(e);return e.map(n=>({x:n.x-t.x,y:n.y-t.y}))}function KX(e,t){if(t===0)return[...e];const n=DC(e),s=Math.cos(t),o=Math.sin(t);return e.map(r=>({x:(r.x-n.x)*s-(r.y-n.y)*o+n.x,y:(r.x-n.x)*o+(r.y-n.y)*s+n.y}))}function VX(e,t){const n=[];let s=0;for(let l=0;l<e.length;l++){const d=Gr(e[l],t[l]);n.push(d),s+=d}const o=s/e.length;n.sort((l,d)=>d-l);const r=Math.max(1,Math.round(e.length/4));let i=0;for(let l=0;l<r;l++)i+=n[l];return(1-qS)*o+qS*(i/r)}function BC(e,t){return UX($x(WX(e),t))}function GX(e,t=FX){if(e.length<3)return[...e];const n=$x(e,PC),s=Math.floor(t/2);return n.map((o,r)=>{if(r<s||r>=n.length-s)return o;let i=0,l=0;for(let d=r-s;d<=r+s;d++)i+=n[d].x,l+=n[d].y;return{x:i/t,y:l/t}})}function YX(e){let t=0,n=null;for(let s=1;s<e.length;s++){const o=e[s-1],r=e[s];if(Gr(o,r)<1e-6)continue;const i=Math.atan2(r.y-o.y,r.x-o.x);if(n!==null){let l=i-n;for(;l>Math.PI;)l-=2*Math.PI;for(;l<-Math.PI;)l+=2*Math.PI;t+=Math.abs(l)}n=i}return t}function XX(e){if(e.length<4)return[...e];const t=e[0],n=wx(e),s=.12*Math.hypot(n.maxX-n.minX,n.maxY-n.minY),o=bx(e);let r=0,i=-1,l=1/0;for(let d=1;d<e.length;d++){if(r+=Gr(e[d-1],e[d]),r<.6*o)continue;const u=Gr(e[d],t);u<=s&&u<l&&(l=u,i=d)}return i===-1?[...e]:e.slice(0,i+1)}function zC(e){let t=0;for(let n=0;n<e.length;n++){const s=e[n],o=e[(n+1)%e.length];t+=s.x*o.y-o.x*s.y}return t>=0?1:-1}function FC(e){const t=wx(e),n=Math.max(t.maxX-t.minX,1e-6),s=Math.max(t.maxY-t.minY,1e-6);return Math.min(RC,Math.max(OC,n/s))}function Ap(e){return[...e,e[0]]}function Mc(e,t,n,s,o,r,i){const l=[];for(let d=0;d<=i;d++){const u=o+(r-o)*d/i;l.push({x:e+n*Math.cos(u),y:t+s*Math.sin(u)})}return l}function QX(e,t){switch(e){case"rect":return Ap([{x:0,y:0},{x:t,y:0},{x:t,y:1},{x:0,y:1}]);case"diamond":return Ap([{x:t/2,y:0},{x:t,y:1/2},{x:t/2,y:1},{x:0,y:1/2}]);case"hexagon":return Ap([{x:t*.25,y:0},{x:t*.75,y:0},{x:t,y:1/2},{x:t*.75,y:1},{x:t*.25,y:1},{x:0,y:1/2}]);case"triangle":return Ap([{x:t/2,y:0},{x:t,y:1},{x:0,y:1}]);case"ellipse":return Mc(t/2,1/2,t/2,1/2,-Math.PI/2,1.5*Math.PI,96);case"pill":{const s=Math.min(t,1)/2;return t>=1?[{x:s,y:0},{x:t-s,y:0},...Mc(t-s,s,s,s,-Math.PI/2,Math.PI/2,24),{x:s,y:1},...Mc(s,s,s,s,Math.PI/2,1.5*Math.PI,24)]:[...Mc(s,s,s,s,Math.PI,2*Math.PI,24),{x:t,y:1-s},...Mc(s,1-s,s,s,0,Math.PI,24),{x:0,y:s}]}case"cylinder":{const o=[];for(let r=0;r<=24;r++){const i=r/24;o.push({x:i*t,y:.28*(1-Math.sin(Math.PI*i))})}return[...o,{x:t,y:1},{x:0,y:1},{x:0,y:.28}]}}}const HS=new Map,WS=1.25;function ZX(e){const t=Math.round(Math.min(RC,Math.max(OC,e))*20)/20,n=HS.get(t);if(n!==void 0)return n;const s=[];for(const o of jC){if(o==="pill"&&t<WS&&t>1/WS)continue;const r=QX(o,t),i=BC(r,PC),l=zC(i);s.push({shape:o,dir:l,pts:i}),s.push({shape:o,dir:l===1?-1:1,pts:[...i].reverse()})}return HS.set(t,s),s}function JX(e,t){const n=e.pts.length/(Ff-1),s=[];for(let o=0;o<Ff;o++)s.push(e.pts[((t+Math.round(o*n))%e.pts.length+e.pts.length)%e.pts.length]);return s}function eQ(e,t){let n=0,s=1/0;for(let o=0;o<e.pts.length;o++){const r=Gr(e.pts[o],t);r<s&&(s=r,n=o)}return n}function tQ(e,t){const n=eQ(t,e[0]),s=Math.round(t.pts.length*qX),o=Math.max(1,Math.round(s/HX));let r=1/0;for(let i=-s;i<=s;i+=o){const l=VX(e,JX(t,n+i));l<r&&(r=l)}return r}function Cp(e,t,n,s){const o=KX(e,s),r=ZX(FC(o)).find(i=>i.shape===t&&i.dir===n);return r===void 0?1/0:tQ(BC(o,Ff),r)}function nQ(e,t,n){let s=-zS,o=zS,r=_r*s+(1-_r)*o,i=Cp(e,t,n,r),l=(1-_r)*s+_r*o,d=Cp(e,t,n,l);for(;Math.abs(o-s)>DX;)i<d?(o=l,l=r,d=i,r=_r*s+(1-_r)*o,i=Cp(e,t,n,r)):(s=r,r=l,i=d,l=(1-_r)*s+_r*o,d=Cp(e,t,n,l));return Math.min(i,d)}function sQ(e,t={}){if(e.length<2)return;const n=bx(e);if(n<(t.minLength??12))return;const s=Gr(e[0],e[e.length-1])/n;if(s>=BX)return{shape:"line",score:s};const o=YX($x(e,zX));if(o>=FS)return{shape:"scribble",score:Math.min(1,o/(2*FS))};const r=oQ(e),i=r[0];if(i===void 0||i.score<OX)return;const l=r[1];return l!==void 0&&(1-i.score)/(1-l.score)>RX?{shape:void 0,score:i.score,ambiguous:!0,candidates:[i.shape,l.shape]}:{shape:i.shape,score:i.score}}function oQ(e){const t=GX(XX(e)),n=zC(t),s=FC(t),o=.5*Math.hypot(D0,D0/Math.max(s,1/s));return jC.map(r=>({shape:r,score:1-nQ(t,r,n)/o})).filter(r=>Number.isFinite(r.score)).sort((r,i)=>i.score-r.score)}function B0(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function rQ(e,t){const n=B0(t)?.[e.nodesField];return(Array.isArray(n)?n:[]).map(B0).filter(s=>s!==null)}function qC(e,t,n){return rQ(e,t).some(s=>s.kind===n)}const Vt=e=>()=>({kind:e}),Ra=(e,t)=>(n,s)=>({kind:qC(n,s,e)?t:e}),US=e=>({kind:"end",extra:{[e.labelField]:"Error exit"}}),Sx={flow:{rect:Vt("process"),diamond:Vt("decision"),pill:Ra("start","end"),ellipse:Ra("start","end"),triangle:US},swimlane:{rect:Vt("action"),diamond:Vt("decision"),pill:Ra("start","end"),ellipse:Ra("start","end"),triangle:US},state:{rect:Vt("active"),pill:Ra("start","terminal"),ellipse:Ra("start","terminal")},block:{rect:Vt("service"),diamond:Vt("gateway"),pill:Vt("client"),cylinder:Vt("db"),hexagon:(e,t)=>({kind:qC(e,t,"gateway")?"queue":"gateway"}),triangle:(e,t)=>B0(t)?.preset==="k8s"?{kind:"ingress"}:null},c4:{rect:Vt("container"),ellipse:Vt("person"),cylinder:Vt("store")},dfd:{rect:Vt("process"),ellipse:Vt("external"),cylinder:Vt("store")},felogic:{rect:Vt("component"),cylinder:Vt("db"),hexagon:Vt("queue")},graph:{rect:Vt("node"),diamond:Vt("node"),pill:Vt("node"),ellipse:Vt("node"),cylinder:Vt("node"),hexagon:Vt("node"),triangle:Vt("node")}};function iQ(e){const t=$n(e);return t!==null&&t.gridNodes&&t.newNode!==void 0&&Sx[e]!==void 0}function HC(e,t,n,s,o,r){const i=e.nodeKinds.find(h=>h.kind===s),l=i??e.nodeKinds[0];if(l===void 0)return null;const d=typeof r?.[e.labelField]=="string"?r[e.labelField]:`New ${(i?.label??s).toLowerCase()}`,u={...r??{}};i===void 0&&(u.kind=s,u[e.labelField]=d);const p=dx(e,t,n,l.kind,o,Object.keys(u).length>0?u:void 0);return p===null?null:{...p,label:d}}function aQ(e,t,n,s){const o=[];for(const r of s){const i=Sx[e]?.[r]?.(t,n);i!=null&&!o.includes(i.kind)&&o.push(i.kind)}return o}function lQ(e,t,n,s){const o=$n(t);if(o===null||o.newNode===void 0||!o.gridNodes)return{type:"none",reason:"This block has no grid to draw on"};const r=s.placements??void 0,i=p=>({type:"pick",first:aQ(t,o,s.data,p)});if(e===void 0)return i(s.candidates??[]);if(e==="line"){const p=s.line;if(p===void 0||p.fromId===null)return{type:"none",reason:""};if(p.toId!==null){if(p.toId===p.fromId)return{type:"none",reason:""};const g=Gp(o,s.data,p.fromId,p.toId);return g===null?{type:"none",reason:"Already connected"}:{type:"edge",sets:g,fromId:p.fromId,toId:p.toId}}const h=o.nodeKinds[0];if(h===void 0)return{type:"none",reason:""};const m=Nf(o,s.data,p.fromId,p.endCell,h.kind,r);return m===null?{type:"none",reason:""}:{type:"node",...m,kind:h.kind,label:`New ${h.label.toLowerCase()}`}}if(e==="scribble")return s.under!==void 0&&s.under!==null?{type:"delete",path:s.under}:{type:"none",reason:""};const l=Sx[t]?.[e],d=l===void 0?null:l(o,s.data);if(d===null)return i(s.candidates??[]);const u=HC(o,s.data,n,d.kind,r,d.extra);return u===null?i([e,...s.candidates??[]]):{type:"node",...u,kind:d.kind}}const cQ=160,Da={trail:[],fading:!1,flash:null,picker:null};function KS(e,t){const n=e.getBoundingClientRect(),s=t.getBoundingClientRect();return{left:n.left-s.left,top:n.top-s.top,width:n.width,height:n.height}}function dQ(e,t){return t.x>=e.left&&t.x<=e.left+e.width&&t.y>=e.top&&t.y<=e.top+e.height}function Np(e,t){const s=(t!==null&&typeof t=="object"?t:{})[e.nodesField];return Array.isArray(s)?s.map(o=>{const r=o!==null&&typeof o=="object"?o[e.idField]:void 0;return typeof r=="string"?r:""}):[]}function uQ(e,t){return e.nodeKinds.find(s=>s.kind===t)?.label??t.charAt(0).toUpperCase()+t.slice(1)}function pQ(e){const{host:t,data:n,html:s,wrapperRef:o,segIndex:r,suppressClickRef:i,dragActiveRef:l,onNodeCreated:d,onDelete:u}=e,p=r!==void 0&&iQ(t.kind),h=ke(N=>N.penMode!==null&&N.penMode.seg===r&&N.penMode.on),[m,g]=oe.useState(Da),v=oe.useRef(null),y=oe.useRef(null),b=oe.useRef(null),E=oe.useRef({host:t,data:n,onNodeCreated:d,onDelete:u});E.current={host:t,data:n,onNodeCreated:d,onDelete:u};const $=oe.useRef(!1);$.current=h,oe.useEffect(()=>{const N=ke.getState();if(r!==void 0){if(!p){N.penMode?.seg===r&&N.setPenMode(null);return}return N.penMode?.seg!==r&&N.setPenMode({seg:r,on:!1}),()=>{const j=ke.getState();j.penMode?.seg===r&&j.setPenMode(null)}}},[p,r]);const A=N=>{r!==void 0&&ke.getState().setPenMode({seg:r,on:N})};return oe.useEffect(()=>()=>{y.current!==null&&clearTimeout(y.current)},[]),oe.useEffect(()=>{const N=o.current;if(N===null||!p)return;const j=$n(t.kind);if(j===null)return;const P=()=>{y.current!==null&&(clearTimeout(y.current),y.current=null),g(Da)},I=W=>{if(mx()||W===null){P();return}g(K=>({...K,fading:!0,flash:W,picker:null})),y.current=setTimeout(P,cQ)},O=()=>{v.current=null,l.current=!1,window.removeEventListener("pointermove",B),window.removeEventListener("pointerup",te),window.removeEventListener("pointercancel",ee)},C=()=>Np(j,E.current.data).map((W,K)=>{const R=N.querySelector(`[data-bp="${CSS.escape(`${j.nodesField}.${K}`)}"]`);return R===null?null:KS(R,N)}),D=()=>{const W=Np(j,E.current.data).length,K=[];for(let R=0;R<W;R++){const z=N.querySelector(`[data-bp="${CSS.escape(`${j.nodesField}.${R}`)}"]`),Y=z!==null?Nn(z,"data-col"):null,V=z!==null?Nn(z,"data-row"):null;if(Y===null||V===null)return;K.push({col:Y,row:V})}return K},F=(W,K)=>{const R=W.geom;if(R===null)return{col:1,row:1};const z=wo(R,K.x-W.svgBox.left,K.y-W.svgBox.top);return j.growRows===!1?{col:z.col,row:Math.min(z.row,R.rows)}:z},U=(W,K)=>{if(W.geom===null)return null;const R=_f(W.geom,K.col,K.row);return{left:W.svgBox.left+R.left,top:W.svgBox.top+R.top,width:R.width,height:R.height}},X=(W,K)=>{E.current.host.commitPaths(W.sets),E.current.host.notify?.(`Drew ${W.label}`),I(K),E.current.onNodeCreated(W.nodePath,j.labelField)},B=W=>{const K=v.current;if(K===null||W.pointerId!==K.pointerId)return;W.preventDefault();const R=N.getBoundingClientRect();K.points.push({x:W.clientX-R.left,y:W.clientY-R.top}),g({trail:[...K.points],fading:!1,flash:null,picker:null})},te=W=>{const K=v.current;if(K===null||W.pointerId!==K.pointerId)return;O(),i.current=!0;const R=K.points,z=sQ(R);if(z===void 0){P();return}const{host:Y,data:V}=E.current,re=R.map(De=>De.x),Q=R.map(De=>De.y),ne={x:(Math.min(...re)+Math.max(...re))/2,y:(Math.min(...Q)+Math.max(...Q))/2},Z=R[0],q=R[R.length-1],de=C(),le=Np(j,V),J=De=>{for(let Me=de.length-1;Me>=0;Me--){const Be=de[Me],Ge=le[Me];if(Be!=null&&Ge!==void 0&&Ge!==""&&dQ(Be,De))return{id:Ge,path:`${j.nodesField}.${Me}`}}return null},ue=F(K,z.shape==="line"?q:ne),ve=J(Z),we=J(q),$e=J(ne),je=lQ(z.shape,t.kind,ue,{data:V,placements:D(),...z.candidates!==void 0?{candidates:z.candidates}:{},...z.shape==="line"?{line:{fromId:ve?.id??null,toId:we?.id??null,endCell:ue}}:{},under:$e?.path??null});if(je.type==="node"){X(je,U(K,ue));return}if(je.type==="edge"){Y.commitPaths(je.sets),Y.notify?.(`Connected ${no(j,V,je.fromId)} → ${no(j,V,je.toId)}`),I(null);return}if(je.type==="delete"){P(),E.current.onDelete(je.path);return}if(je.type==="pick"){const De=new Set(je.first),Me=[...je.first.map(Be=>({value:Be,label:uQ(j,Be)})),...j.nodeKinds.filter(Be=>!De.has(Be.kind)).map(Be=>({value:Be.kind,label:Be.label}))];if(Me.length===0){P();return}b.current=ue,g({trail:R,fading:!0,flash:U(K,ue),picker:{left:ne.x,top:ne.y,cell:ue,items:Me}});return}je.reason!==""&&Y.notify?.(je.reason),P()},ee=()=>{O(),P()},H=W=>{if(!$.current||W.button!==0||v.current!==null||!(W.target instanceof Element)||W.target.closest(".stu-dx-sketch-picker")!==null||b.current!==null)return;const K=W.target.closest("svg");if(K===null||!N.contains(K)||!K.hasAttribute("data-grid"))return;W.preventDefault(),W.stopPropagation();const R=N.getBoundingClientRect();v.current={pointerId:W.pointerId,svg:K,svgBox:KS(K,N),geom:Ao(K),points:[{x:W.clientX-R.left,y:W.clientY-R.top}]},l.current=!0,i.current=!0,window.addEventListener("pointermove",B),window.addEventListener("pointerup",te),window.addEventListener("pointercancel",ee)};return N.addEventListener("pointerdown",H,!0),()=>{N.removeEventListener("pointerdown",H,!0),O(),b.current=null,g(Da)}},[o,t.kind,p,s,l,i]),{on:h,visuals:m,available:p,toggle:()=>A(!$.current),leave:()=>{b.current=null,g(Da),A(!1)},choose:N=>{const j=o.current,P=b.current,I=$n(t.kind);if(b.current=null,j===null||P===null||I===null){g(Da);return}const{host:O,data:C}=E.current,D=[],F=Np(I,C).length;for(let X=0;X<F;X++){const B=j.querySelector(`[data-bp="${CSS.escape(`${I.nodesField}.${X}`)}"]`),te=B!==null?Nn(B,"data-col"):null,ee=B!==null?Nn(B,"data-row"):null;if(te===null||ee===null)break;D.push({col:te,row:ee})}const U=HC(I,C,P,N,D.length===F?D:void 0);g(Da),U!==null&&(O.commitPaths(U.sets),O.notify?.(`Drew ${U.label}`),E.current.onNodeCreated(U.nodePath,I.labelField))}}}const VS={box:null,snap:null};function fQ(e,t){const n=e.getBoundingClientRect(),s=t.getBoundingClientRect();return{left:n.left-s.left,top:n.top-s.top,width:n.width,height:n.height}}function hQ(e){const{host:t,data:n,html:s,wrapperRef:o,enabled:r,editorOpenRef:i,suppressClickRef:l,dragActiveRef:d,onMarqueeStart:u,onCreated:p}=e,[h,m]=oe.useState(VS),g=oe.useRef(null),v=oe.useRef({host:t,data:n,onMarqueeStart:u,onCreated:p});return v.current={host:t,data:n,onMarqueeStart:u,onCreated:p},oe.useEffect(()=>{const y=o.current;if(y===null||!r||!Ph(t.kind))return;const b=()=>{const j=g.current;g.current=null,d.current=!1,j!==null&&j.active&&(document.body.style.userSelect="",y.style.cursor=""),m(VS),window.removeEventListener("pointermove",$),window.removeEventListener("pointerup",A),window.removeEventListener("pointercancel",T),window.removeEventListener("keydown",E,!0)},E=j=>{j.key==="Escape"&&g.current?.active===!0&&(j.preventDefault(),j.stopPropagation(),b())},$=j=>{const P=g.current;if(P===null||j.pointerId!==P.pointerId)return;if(!P.active){if(!Ch(j.clientX-P.startX,j.clientY-P.startY))return;P.active=!0,d.current=!0,l.current=!0,document.body.style.userSelect="none",y.style.cursor="crosshair",v.current.onMarqueeStart()}const I=y.getBoundingClientRect(),O=P.startX-I.left,C=P.startY-I.top,D=j.clientX-I.left,F=j.clientY-I.top,U={left:Math.min(O,D),top:Math.min(C,F),width:Math.abs(D-O),height:Math.abs(F-C)},X=CS(P.geom,O-P.svgBox.left,C-P.svgBox.top,D-P.svgBox.left,F-P.svgBox.top),B=gx(P.geom,X);m({box:U,snap:{left:P.svgBox.left+B.left,top:P.svgBox.top+B.top,width:B.width,height:B.height}})},A=j=>{const P=g.current;if(P===null||j.pointerId!==P.pointerId)return;if(!P.active){b();return}const I=y.getBoundingClientRect(),O=CS(P.geom,P.startX-I.left-P.svgBox.left,P.startY-I.top-P.svgBox.top,j.clientX-I.left-P.svgBox.left,j.clientY-I.top-P.svgBox.top),{host:C,data:D,onCreated:F}=v.current,U=bC(C.kind,D,O);b(),U!==null&&(C.commitPaths(U.sets),F(U.groupPath,"label"))},T=()=>b(),N=j=>{if(j.button!==0||g.current!==null||i.current||!(j.target instanceof Element)||j.target.closest(".stu-dx-overlay")!==null||j.target.closest("[data-bp]")!==null)return;const P=j.target.closest("svg");if(P===null||!y.contains(P)||!P.hasAttribute("data-grid"))return;const I=Ao(P);I!==null&&(g.current={pointerId:j.pointerId,startX:j.clientX,startY:j.clientY,geom:I,svgBox:fQ(P,y),active:!1},window.addEventListener("pointermove",$),window.addEventListener("pointerup",A),window.addEventListener("pointercancel",T),window.addEventListener("keydown",E,!0))};return y.addEventListener("pointerdown",N),()=>{y.removeEventListener("pointerdown",N),b()}},[o,t.kind,r,s,d,l,i]),h}const GS={snap:null};function mQ(e,t){const n=e.getBoundingClientRect(),s=t.getBoundingClientRect();return{left:n.left-s.left,top:n.top-s.top,width:n.width,height:n.height}}function WC(e){return e==="nw"||e==="se"?"nwse-resize":"nesw-resize"}function gQ(e){const{host:t,data:n,html:s,wrapperRef:o,suppressClickRef:r,dragActiveRef:i,onResizeStart:l}=e,[d,u]=oe.useState(GS),p=oe.useRef(null),h=oe.useRef({host:t,data:n,onResizeStart:l});h.current={host:t,data:n,onResizeStart:l};const m=oe.useRef(null);return oe.useEffect(()=>{const g=o.current;if(g===null||!Ph(t.kind))return;const v=()=>{const T=p.current;p.current=null,i.current=!1,T!==null&&T.active&&(document.body.style.userSelect="",g.style.cursor=""),u(GS),window.removeEventListener("pointermove",b),window.removeEventListener("pointerup",E),window.removeEventListener("pointercancel",$),window.removeEventListener("keydown",y,!0)},y=T=>{T.key==="Escape"&&p.current?.active===!0&&(T.preventDefault(),T.stopPropagation(),v())},b=T=>{const N=p.current;if(N===null||T.pointerId!==N.pointerId)return;if(!N.active){if(!Ch(T.clientX-N.startX,T.clientY-N.startY))return;N.active=!0,i.current=!0,r.current=!0,document.body.style.userSelect="none",g.style.cursor=N.cursor,h.current.onResizeStart()}const j=g.getBoundingClientRect(),P=wo(N.geom,T.clientX-j.left-N.svgBox.left,T.clientY-j.top-N.svgBox.top),I=RY(N.fixed,P);N.next=I;const O=gx(N.geom,I);u({snap:{left:N.svgBox.left+O.left,top:N.svgBox.top+O.top,width:O.width,height:O.height}})},E=T=>{const N=p.current;if(N===null||T.pointerId!==N.pointerId)return;if(!N.active){v();return}const{host:j,data:P}=h.current,I=N.next!==null?SC(P,N.index,N.next):null;v(),I!==null&&j.commitPaths(I)},$=()=>v(),A=(T,N,j)=>{if(T.button!==0||p.current!==null)return;const I=g.querySelector(`[data-bp="${CSS.escape(`groups.${N}`)}"]`)?.closest("svg")??null;if(I===null||!I.hasAttribute("data-grid"))return;const O=Ao(I),C=O!==null?Ji(h.current.data,N):null;O===null||C===null||(r.current=!1,p.current={pointerId:T.pointerId,startX:T.clientX,startY:T.clientY,index:N,cursor:WC(j),fixed:OY(j,C),geom:O,svgBox:mQ(I,g),active:!1,next:null},window.addEventListener("pointermove",b),window.addEventListener("pointerup",E),window.addEventListener("pointercancel",$),window.addEventListener("keydown",y,!0))};return m.current=A,()=>{v(),m.current=null}},[o,t.kind,s,i,r]),{visuals:d,start:(g,v,y)=>m.current?.(g.nativeEvent,v,y)}}function vQ(e){return[{side:"top",x:e.left+e.width/2,y:e.top},{side:"right",x:e.left+e.width,y:e.top+e.height/2},{side:"bottom",x:e.left+e.width/2,y:e.top+e.height},{side:"left",x:e.left,y:e.top+e.height/2}]}function yQ(e){return[{corner:"nw",x:e.left,y:e.top},{corner:"ne",x:e.left+e.width,y:e.top},{corner:"sw",x:e.left,y:e.top+e.height},{corner:"se",x:e.left+e.width,y:e.top+e.height}]}function to(e,t){const n=e.getBoundingClientRect(),s=t.getBoundingClientRect();return{left:n.left-s.left,top:n.top-s.top,width:n.width,height:n.height}}function Tp(e,t,n){const s=Array.from(e.querySelectorAll("[data-bp]")).filter(r=>r.closest(".stu-dx-hit")===null),o=s.map(r=>r.getAttribute("data-bp")??"");return EY(o,t,n!==null?s.indexOf(n):-1).map(r=>s[r])}function xQ(e){const t=new Set,n=[];for(const s of Array.from(e.querySelectorAll("[data-bp]"))){const o=s.getAttribute("data-bp")??"";o!==""&&!t.has(o)&&(t.add(o),n.push(o))}return n}function UC({host:e,data:t,html:n,wrapperRef:s,segIndex:o,linkPath:r,onElementClick:i,pendingMenu:l,onPendingMenuConsumed:d}){const u=oe.useMemo(()=>yy(e.kind),[e.kind]),p=oe.useRef(null),h=oe.useCallback(ce=>{const Ee=s.current;Ee!==null&&(p.current={before:xC(Ee),moves:ce})},[s]),m=oe.useMemo(()=>({kind:e.kind,commitPath:(ce,Ee)=>{h(!0),e.commitPath(ce,Ee)},commitPaths:ce=>{h(!0),e.commitPaths(ce)},deletePath:ce=>{const Ee=s.current,Se=()=>{h(!1),e.deletePath(ce)};Ee===null?Se():AS(Ee,[If(ce)],Se)},openFull:()=>e.openFull(),...e.notify!==void 0?{notify:ce=>e.notify?.(ce)}:{}}),[e,h,s]),g=oe.useCallback(ce=>{const Ee=$n(m.kind);return Ee!==null&&ce.startsWith(`${Ee.edgesField}.`)||ce.startsWith("relations.")},[m.kind]);oe.useLayoutEffect(()=>{const ce=p.current,Ee=s.current;ce===null||Ee===null||(p.current=null,LY(Ee,ce.before,g,{moves:ce.moves}))},[n,s,g]);const v=ke(ce=>o!==void 0&&ce.penMode?.seg===o&&ce.penMode.on);oe.useEffect(()=>{const ce=s.current;if(ce!==null)return ce.classList.toggle("stu-dx-penning",v),()=>ce.classList.remove("stu-dx-penning")},[v,s]);const[y,b]=oe.useState(null),E=oe.useRef(!1);E.current=y!==null;const[$,A]=oe.useState(null),[T,N]=oe.useState(null),[j,P]=oe.useState([]),[I,O]=oe.useState([]),[C,D]=oe.useState([]),[F,U]=oe.useState([]),[X,B]=oe.useState([]),te=oe.useRef(null),ee=oe.useRef(null),H=oe.useRef(!1);H.current=T!==null;const W=ke(ce=>ce.partSel),K=o!==void 0&&W!==null&&W.seg===o?W.path:null,[R,z]=oe.useState(null),[Y,V]=oe.useState([]),[re,Q]=oe.useState(!1),[ne,Z]=oe.useState([]),q=oe.useRef(null);q.current=K;const de=oe.useRef(!1),le=oe.useRef(!1),J=oe.useRef(null),ue=oe.useCallback(()=>{const ce=J.current;ce!==null&&(ce instanceof HTMLElement||ce instanceof SVGElement)&&(ce.style.cursor=""),J.current=null},[]),ve=oe.useCallback(ce=>{o!==void 0&&(ke.getState().setPartSel(ce===null?null:{seg:o,path:ce}),ce!==null&&Ni("part-select"))},[o]),we=IX({host:m,data:t,html:n,wrapperRef:s,editorOpenRef:H,suppressClickRef:de,dragActiveRef:le,onDragStart:()=>{A(null),ue()},onDrop:ce=>{ve(ce),Ni("part-move")}}),$e=PX({host:m,data:t,html:n,wrapperRef:s,suppressClickRef:de,dragActiveRef:le,onConnectStart:()=>{A(null),ue()},onNodeCreated:(ce,Ee)=>{ve(ce),te.current={path:ce,focusField:Ee}},onEdgeCreated:(ce,Ee)=>{ve(ce),te.current={path:ce,focusField:Ee}}}),je=oe.useRef($e);je.current=$e;const De=pQ({host:m,data:t,html:n,wrapperRef:s,segIndex:o,suppressClickRef:de,dragActiveRef:le,onNodeCreated:(ce,Ee)=>{ve(ce),te.current={path:ce,focusField:Ee}},onDelete:ce=>{const Ee=cS(m.kind,ce)??ce,Se=()=>{Nt.current(Ee),ke.getState().setPartSel(null)};if(!Uv(m.kind,t,Ee)){Se();return}const tt=s.current?.querySelector(`[data-bp="${CSS.escape(Ee)}"]`)?.getBoundingClientRect();ke.getState().requestDelete({label:Pr(Dn(Ee)),anchor:tt!==void 0?{x:tt.left+tt.width/2,y:tt.bottom}:{x:window.innerWidth/2,y:window.innerHeight/3},run:Se})}}),Me=oe.useRef(De);Me.current=De;const Be=oe.useCallback((ce,Ee)=>{if(ce.closest(".seq-steps")!==null)return"summary";const Se=je.current.spec;if(Se!==null&&Cf(Se,Ee)!==null)return Se.edgeTextField},[]),Ge=gQ({host:m,data:t,html:n,wrapperRef:s,suppressClickRef:de,dragActiveRef:le,onResizeStart:()=>{A(null),ue()}}),fe=hQ({host:m,data:t,html:n,wrapperRef:s,enabled:o!==void 0,editorOpenRef:H,suppressClickRef:de,dragActiveRef:le,onMarqueeStart:()=>{A(null),ue()},onCreated:(ce,Ee)=>{ve(ce),te.current={path:ce,focusField:Ee}}});oe.useEffect(()=>()=>{ee.current!==null&&clearTimeout(ee.current)},[]);const ge=oe.useCallback((ce,Ee,Se,st)=>{A(null),N({path:ce,anchor:to(Ee,Se),...st!==void 0?{focusField:st}:{}})},[]),Ce=oe.useCallback((ce,Ee,Se)=>{const st=Tp(Se,ce,Ee);st.length!==0&&(B(st.map(tt=>to(tt,Se))),Ee instanceof SVGElement&&st.find(Oe=>!(Oe instanceof SVGElement))?.scrollIntoView({block:"nearest",behavior:"smooth"}),ee.current!==null&&clearTimeout(ee.current),ee.current=setTimeout(()=>{ee.current=null,B([])},1400))},[]);oe.useEffect(()=>{const ce=s.current;if(ce===null)return;const Ee=Oe=>{if(!(Oe instanceof Element))return null;const Ye=Oe.closest("[data-bp]");return Ye!==null&&ce.contains(Ye)?Ye:null},Se=Oe=>{if(le.current||H.current||E.current||Oe.target instanceof Element&&Oe.target.closest(".stu-dx-overlay")!==null)return;const Ye=Ee(Oe.target);if(Ye===null){A(null),ue();return}const yt=Ye.getAttribute("data-bp")??"";Ye!==J.current&&(ue(),(Ye instanceof HTMLElement||Ye instanceof SVGElement)&&kx(ce,m.kind,yt)!==null&&(Ye.style.cursor="grab",J.current=Ye)),A(Ft=>{const Gt=to(Ye,ce);if(Ft!==null&&Ft.path===yt&&Ft.rect.top===Gt.top&&Ft.rect.left===Gt.left)return Ft;const ls=Tp(ce,yt,Ye).map(cs=>to(cs,ce));return{path:yt,rect:Gt,twins:ls}})},st=()=>{A(null),ue()},tt=Oe=>{if(de.current){de.current=!1;return}if(Oe.target instanceof Element&&Oe.target.closest(".stu-dx-overlay")!==null)return;const Ye=Ee(Oe.target);if(Ye===null){q.current!==null&&ve(null);return}const yt=Ye.getAttribute("data-bp")??"";if(i?.(yt)===!0)return;const Ft=Be(Ye,yt);if(o===void 0){ge(yt,Ye,ce,Ft),Ce(yt,Ye,ce);return}if(q.current===yt&&!H.current){ge(yt,Ye,ce,Ft),Ce(yt,Ye,ce);return}ve(yt)};return ce.addEventListener("pointermove",Se),ce.addEventListener("pointerleave",st),ce.addEventListener("click",tt),()=>{ce.removeEventListener("pointermove",Se),ce.removeEventListener("pointerleave",st),ce.removeEventListener("click",tt),ue()}},[s,i,ge,Ce,ue,Be,m.kind,o,ve]),oe.useEffect(()=>{const ce=s.current;if(ce===null)return;const Ee=Se=>{const st=ke.getState();if(st.pendingDelete!==null||st.review!==null)return;if(Se.key==="Escape"&&je.current.pickerOpenRef.current===!0){Se.preventDefault(),Se.stopPropagation(),je.current.cancelPicker();return}if(Se.key==="Escape"&&Me.current.on&&!H.current){Se.preventDefault(),Se.stopPropagation(),Me.current.leave();return}const tt=Se.key==="ArrowLeft"||Se.key==="ArrowRight"||Se.key==="ArrowUp"||Se.key==="ArrowDown";if(tt&&Se.altKey&&!Se.metaKey&&!Se.ctrlKey){const Oe=K??T?.path??$?.path??null;if(Oe===null)return;const Ye=R0({wrap:ce,host:m,data:t,path:Oe,key:Se.key});if(Ye===null)return;Se.preventDefault(),Se.stopPropagation(),N(null),A(null),ve(Ye);return}if(o!==void 0&&!H.current&&!wl(Se.target)&&!E.current){if(Se.key.toLowerCase()==="d"&&!Se.metaKey&&!Se.ctrlKey&&!Se.altKey&&!Se.shiftKey&&Me.current.available){Se.preventDefault(),Se.stopPropagation(),Me.current.toggle();return}if(Se.key==="F10"&&Se.shiftKey||Se.key==="ContextMenu"){Se.preventDefault(),Se.stopPropagation();const Oe=K!==null?ce.querySelector(`[data-bp="${CSS.escape(K)}"]`):null,Ye=(Oe??ce).getBoundingClientRect();ze.current?.(Oe,{x:Ye.left+8,y:Oe!==null?Ye.bottom+4:Ye.top+40});return}if(!(Se.metaKey||Se.ctrlKey||Se.altKey)){if(Se.key==="Tab"){const Oe=xQ(ce);if(Oe.length===0)return;if(Se.preventDefault(),Se.stopPropagation(),K===null){ve(Se.shiftKey?Oe[Oe.length-1]:Oe[0]);return}const Ye=Oe.indexOf(K),yt=Oe.length;ve(Oe[Ye<0?0:(Ye+(Se.shiftKey?-1:1)+yt)%yt]);return}if(K!==null){if(Se.key.toLowerCase()==="n"&&m.kind==="sequence"&&/^messages\.\d+$/.test(K)){const Oe=ce.querySelector(`[data-bp="${CSS.escape(K)}"]`);Oe!==null&&(Se.preventDefault(),Se.stopPropagation(),ge(K,Oe,ce,"summary"),Ce(K,Oe,ce));return}if(Se.key==="Enter"&&!Se.shiftKey){const Oe=ce.querySelector(`[data-bp="${CSS.escape(K)}"]`);if(Oe===null)return;Se.preventDefault(),Se.stopPropagation(),ge(K,Oe,ce,Be(Oe,K)),Ce(K,Oe,ce);return}if(Se.key==="Escape"){Se.preventDefault(),Se.stopPropagation(),ve(null);return}if(Se.key==="Backspace"||Se.key==="Delete"){const Oe=cS(m.kind,K);if(Oe===null)return;Se.preventDefault(),Se.stopPropagation();const Ye=()=>{const Gt=bS(m.kind,Oe);if(Gt!==null){const ls=wS(m.kind,t,Gt);if(ls===null){m.notify?.("Keep at least one column");return}m.commitPaths(ls)}else m.deletePath(Dn(Oe));ke.getState().setPartSel(null)};if(!Uv(m.kind,t,Oe)){Ye();return}const Ft=(ce.querySelector(`[data-bp="${CSS.escape(Oe)}"]`)??ce.querySelector(`[data-bp="${CSS.escape(K)}"]`))?.getBoundingClientRect();ke.getState().requestDelete({label:Pr(Dn(Oe)),anchor:Ft!==void 0?{x:Ft.left+Ft.width/2,y:Ft.bottom}:{x:window.innerWidth/2,y:window.innerHeight/3},run:Ye});return}if(tt){if(!RG(jf(m.kind,K)))return;Se.preventDefault(),Se.stopPropagation();const Oe=jX({wrap:ce,host:m,data:t,path:K,key:Se.key,grow:Se.shiftKey});Oe!==null&&(ve(Oe.path),Ni("part-move"))}}}}};return window.addEventListener("keydown",Ee,!0),()=>window.removeEventListener("keydown",Ee,!0)},[s,m,t,K,T,$,o,ve,ge,Ce,Be]),oe.useLayoutEffect(()=>{const ce=s.current;if(ce===null||K===null){z(null),V([]);return}const Ee=ce.querySelector(`[data-bp="${CSS.escape(K)}"]`);if(Ee===null){z(null),V([]),ve(null);return}z(to(Ee,ce)),V(Tp(ce,K,Ee).map(Se=>to(Se,ce))),Q(Ee.closest("svg")?.hasAttribute("data-grid")===!0)},[K,n,s,ve]),oe.useLayoutEffect(()=>{const ce=s.current;if(ce===null){Z([]);return}const Ee=[];for(const Se of Array.from(ce.querySelectorAll("svg"))){if(Se.closest(".stu-dx-hit")!==null)continue;const st=Se.getAttribute("viewBox")??"";if(st==="")continue;const tt=Array.from(Se.querySelectorAll("path[data-bp]")).map(Oe=>({bp:Oe.getAttribute("data-bp")??"",d:Oe.getAttribute("d")??""})).filter(Oe=>Oe.bp!==""&&Oe.d!=="");tt.length!==0&&Ee.push({box:to(Se,ce),viewBox:st,paths:tt})}Z(Ee)},[n,s]),oe.useLayoutEffect(()=>{const ce=s.current;if(ce===null||T===null){U([]);return}U(Tp(ce,T.path,null).map(Ee=>to(Ee,ce)))},[T,n,s]),oe.useLayoutEffect(()=>{const ce=s.current;if(ce===null)return;const Ee=[],Se=[];for(const Oe of Array.from(ce.querySelectorAll("[data-bl]"))){const Ye=Oe.getAttribute("data-bl")??"";if(Ye==="")continue;const yt=Dn(Ye),Ft=yt[yt.length-1];if(typeof Ft!="string")continue;const Gt=`+ Add ${as($o(Ft)).toLowerCase()}`;if(!yt.some(cs=>typeof cs=="number"))Ee.push({listPath:Ye,label:Gt});else if(!(Oe instanceof SVGElement)){const cs=to(Oe,ce);Se.push({listPath:Ye,label:Gt,at:{left:cs.left+8,top:cs.top+cs.height-11}})}}const st=kS(m.kind);if(st!==null){const Oe=is(t,[st.colsPath]),Ye=Array.isArray(Oe)?Oe.length:0,yt=Ye>0?ce.querySelector(`[data-bp="${CSS.escape(`${st.colsPath}.${Ye-1}`)}"]`):null,Ft=`+ Add ${as($o(st.colsPath)).toLowerCase()}`;if(yt!==null&&!(yt instanceof SVGElement)){const Gt=to(yt,ce);Se.push({listPath:st.colsPath,label:"+",at:{left:Gt.left+Gt.width+4,top:Gt.top+Gt.height/2-10}})}else Ee.some(Gt=>Gt.listPath===st.colsPath)||Ee.push({listPath:st.colsPath,label:Ft})}if(m.kind==="userstory")for(const Oe of["criteria","tags"])Ee.some(Ye=>Ye.listPath===Oe)||Ee.push({listPath:Oe,label:`+ Add ${as($o(Oe)).toLowerCase()}`});P(Ee),O(Se);const tt=te.current;if(tt!==null){const Oe=ce.querySelector(`[data-bp="${CSS.escape(tt.path)}"]`);Oe!==null&&(te.current=null,ge(tt.path,Oe,ce,tt.focusField))}},[n,t,s,ge,m.kind]),oe.useLayoutEffect(()=>{const ce=s.current;if(ce===null||r===null||r===void 0||r===""){D([]);return}const Ee=Array.from(ce.querySelectorAll("[data-bp]"));let st=Ee.filter(tt=>{const Oe=tt.getAttribute("data-bp")??"";return Oe===r||Oe.startsWith(`${r}.`)});if(st.length===0){let tt=-1,Oe=[];for(const Ye of Ee){const yt=Ye.getAttribute("data-bp")??"";(r===yt||r.startsWith(`${yt}.`))&&(yt.length>tt?(tt=yt.length,Oe=[Ye]):yt.length===tt&&Oe.push(Ye))}st=Oe}D(st.map(tt=>to(tt,ce)))},[r,n,s]);const Fe=(ce,Ee)=>{const Se=s.current;if(Se===null)return[];const st=ce?.getAttribute("data-bp")??null,tt=$n(m.kind),Ye=(ce??document.elementFromPoint(Ee.x,Ee.y))?.closest("svg")??Se.querySelector("svg[data-grid]");let yt=null,Ft=null,Gt=!1,ls=null;if(Ye!=null&&Ye.hasAttribute("data-grid")&&tt!==null){const Qr=Ao(Ye);if(Qr!==null){Ft={cols:Qr.cols,rows:Qr.rows},Gt=Ye.hasAttribute("data-grid-auto");const Ed=is(t,[tt.nodesField]);if(yt=xx(Se,tt.nodesField,Array.isArray(Ed)?Ed.length:0),st===null){const Md=Ye.getBoundingClientRect(),Ks=wo(Qr,Ee.x-Md.left,Ee.y-Md.top);ls=tt.growRows===!1?{col:Ks.col,row:Math.min(Ks.row,Qr.rows)}:Ks}}}const cs=BY(m.kind,st,ls);return WY(cs,{kind:m.kind,data:t,placements:yt,grid:Ft,quick:Gt,selected:q.current})},qe=(ce,Ee)=>{if(o===void 0)return;const Se=Fe(ce,Ee),st=ce?.getAttribute("data-bp")??null;st!==null&&st!==q.current&&ve(st),A(null),ue(),Se.length>0&&b({at:Ee,items:Se})},ze=oe.useRef(null);ze.current=qe,oe.useEffect(()=>{const ce=s.current;if(ce===null||o===void 0)return;const Ee=Se=>{if(H.current||le.current||Se.target instanceof Element&&Se.target.closest(".stu-dx-overlay")!==null)return;const st=Se.target instanceof Element?Se.target.closest("[data-bp]"):null;Se.preventDefault(),Se.stopPropagation(),ze.current?.(st!==null&&ce.contains(st)?st:null,{x:Se.clientX,y:Se.clientY})};return ce.addEventListener("contextmenu",Ee),()=>ce.removeEventListener("contextmenu",Ee)},[s,o]),oe.useLayoutEffect(()=>{if(l==null)return;const ce=s.current;if(d?.(),ce===null)return;const Se=document.elementFromPoint(l.x,l.y)?.closest("[data-bp]")??null;ze.current?.(Se!==null&&ce.contains(Se)?Se:null,l)},[l,d,s]);const Xe=oe.useCallback(()=>b(null),[]),pt=ce=>{b(null);const Ee=s.current;if(Ee===null)return;if(ce.action!==void 0){const tt=ce.action;if(tt.type==="openYaml")m.openFull();else if(tt.type==="connect"){const Oe=$n(m.kind);Oe!==null&&(ve(`${Oe.nodesField}.${tt.fromIndex}`),$e.armFrom(tt.fromIndex))}else{const Oe=Ee.querySelector(`[data-bp="${CSS.escape(tt.path)}"]`);Oe!==null?(ve(tt.path),ge(tt.path,Oe,Ee,tt.field)):m.openFull()}return}if(ce.op===void 0)return;const Se=ce.op();if(Se.length===0)return;const st=()=>{const tt=Se[0];Se.length===1&&tt!==void 0&&NS(tt)?(h(!1),e.deletePath(tt.path),ke.getState().setPartSel(null)):(h(ce.fades===void 0),e.commitPaths(Se.filter(Oe=>!NS(Oe)))),ce.then!==void 0&&(ve(ce.then.select),ce.then.edit!==void 0&&(te.current={path:ce.then.select,focusField:ce.then.edit}))};ce.fades!==void 0&&ce.fades.length>0?AS(Ee,ce.fades,st):st()},kt=ce=>{const Ee=kS(m.kind);if(Ee!==null&&ce===Ee.colsPath){const yt=wY(m.kind,t);if(yt===null)return;m.commitPaths(yt.sets),te.current={path:yt.headerPath};return}const Se=Dn(ce),st=hx(u,Se);if(st===null||st.kind!=="array")return;const tt=is(t,Se),Oe=Array.isArray(tt)?tt:[],Ye=[...Se].reverse().find(yt=>typeof yt=="string")??"item";m.commitPath([...Se,Oe.length],jY(m.kind,ce,Qa(st.element,Oe,as(Ye)),t)),te.current={path:If([...Se,Oe.length])}},St=ce=>{const Ee=bS(m.kind,ce);if(Ee!==null){const Se=wS(m.kind,t,Ee);return Se===null?(m.notify?.("Keep at least one column"),!1):(m.commitPaths(Se),!0)}return m.deletePath(Dn(ce)),!0},Nt=oe.useRef(St);Nt.current=St;const Bt=ce=>{if($===null)return;const Ee=$.path,Se=()=>{Nt.current(Ee)};if(A(null),!Uv(m.kind,t,Ee)){Se();return}const st=ce.currentTarget.getBoundingClientRect();ke.getState().requestDelete({label:Pr(Dn(Ee)),anchor:{x:st.left+st.width/2,y:st.bottom},run:Se})},dt=()=>{const ce=s.current;if(ce===null)return;const Ee=ce.querySelector('[data-bp="messages.0"]');Ee!==null?ge("messages.0",Ee,ce,"summary"):m.openFull()},_t=MY(m.kind,t),En=$!==null&&tC(Dn($.path)),zt=$!==null&&$.rect.top>=12,Et=o!==void 0&&$e.spec!==null&&K!==null?Af($e.spec,K):null,an=o!==void 0&&K!==null&&re&&Ph(m.kind)?wC(K):null,_n=K!==null?jf(m.kind,K):null,No=$e.spec!==null&&K!==null&&Cf($e.spec,K)!==null?$e.spec.edgeTextField:null,xs=m.kind==="sequence"&&K!==null?/^messages\.(\d+)$/.exec(K):null,sr=xs!==null&&cd(is(t,["messages",Number(xs[1])]))?{n:AY(is(t,["messages"]),Number(xs[1])),has:typeof is(t,["messages",Number(xs[1]),"summary"])=="string"&&is(t,["messages",Number(xs[1]),"summary"]).length>0}:null,$l=_n===null?"":No!==null?`⏎ edit ${No}${sr!==null?" · n note":""} · ⌫`:_n.kind==="table-cell"?"⏎ edit · ←↑↓→ cells":_n.kind==="grid-group"?"⏎ edit · ←↑↓→ move · drag corner → resize · ⌫":_n.kind!=="inert"?"⏎ edit · ←↑↓→ move · ⌫":"⏎ edit",Sl=R!==null&&R.top>=12;return w.jsxs(w.Fragment,{children:[ne.map((ce,Ee)=>w.jsx("svg",{className:"stu-dx-hit",viewBox:ce.viewBox,preserveAspectRatio:"none","aria-hidden":"true",style:{left:ce.box.left,top:ce.box.top,width:ce.box.width,height:ce.box.height},children:ce.paths.map((Se,st)=>w.jsx("path",{d:Se.d,"data-bp":Se.bp},st))},`hit${Ee}`)),w.jsxs("div",{className:"stu-dx-overlay",children:[C.map((ce,Ee)=>w.jsx("div",{className:"stu-dx-link",style:{left:ce.left-3,top:ce.top-3,width:ce.width+6,height:ce.height+6}},`lk${Ee}`)),T!==null&&F.map((ce,Ee)=>w.jsx("div",{className:"stu-dx-link",style:{left:ce.left-3,top:ce.top-3,width:ce.width+6,height:ce.height+6}},`ed${Ee}`)),X.map((ce,Ee)=>w.jsx("div",{className:"stu-dx-flash",style:{left:ce.left-3,top:ce.top-3,width:ce.width+6,height:ce.height+6}},`fl${Ee}`)),K!==null&&R!==null&&T===null&&w.jsxs(w.Fragment,{children:[w.jsx("div",{className:"stu-dx-sel",style:{left:R.left-3,top:R.top-3,width:R.width+6,height:R.height+6}}),Y.map((ce,Ee)=>w.jsx("div",{className:"stu-dx-link",style:{left:ce.left-3,top:ce.top-3,width:ce.width+6,height:ce.height+6}},`pt${Ee}`)),w.jsxs("div",{className:"stu-dx-chip",style:{left:Math.max(0,R.left-3),top:Sl?R.top-13:R.top+R.height-7},children:[Pr(Dn(K)),$l!==""&&w.jsxs("span",{className:"stu-dx-chip-keys",children:[" · ",$l]})]}),an!==null&&yQ(R).map(ce=>w.jsx("button",{type:"button",className:"stu-dx-resize","aria-label":`Resize the group from its ${ce.corner} corner`,title:"Drag to resize",style:{left:ce.x-5,top:ce.y-5,cursor:WC(ce.corner)},onPointerDown:Ee=>{Ee.stopPropagation(),Ge.start(Ee,an,ce.corner)},onClick:Ee=>Ee.stopPropagation()},ce.corner)),sr!==null&&w.jsx("button",{type:"button",className:"stu-dx-note",style:{left:Math.max(0,R.left-3),top:Sl?R.top+R.height+8:R.top-36},onPointerDown:ce=>ce.stopPropagation(),onClick:ce=>{ce.stopPropagation();const Ee=s.current;if(Ee===null||K===null)return;const Se=Ee.querySelector(`[data-bp="${CSS.escape(K)}"]`);Se!==null&&ge(K,Se,Ee,"summary")},children:sr.has?`✎ note ${sr.n}`:`+ add note ${sr.n}`}),Et!==null&&vQ(R).map(ce=>w.jsx("button",{type:"button",className:"stu-dx-dot","aria-label":`Connect from the ${ce.side} edge`,title:"Drag to connect",style:{left:ce.x-6,top:ce.y-6},onPointerDown:Ee=>{Ee.stopPropagation(),$e.start(Ee,Et,{x:ce.x,y:ce.y})},onClick:Ee=>Ee.stopPropagation()},ce.side))]}),De.visuals.flash!==null&&w.jsx("div",{className:"stu-dx-sketch-flash",style:{left:De.visuals.flash.left,top:De.visuals.flash.top,width:De.visuals.flash.width,height:De.visuals.flash.height}}),De.visuals.trail.length>1&&w.jsx("svg",{className:`stu-dx-ink ${De.visuals.fading?"stu-dx-ink-out":""}`,"aria-hidden":"true",children:w.jsx("polyline",{points:De.visuals.trail.map(ce=>`${ce.x},${ce.y}`).join(" ")})}),De.visuals.picker!==null&&w.jsxs("div",{className:"stu-dx-connect-picker stu-dx-sketch-picker",role:"menu","aria-label":"What did you draw?",style:{left:De.visuals.picker.left+6,top:De.visuals.picker.top+6},onClick:ce=>ce.stopPropagation(),children:[w.jsx("div",{className:"stu-dx-connect-picker-title",children:"What did you draw?"}),De.visuals.picker.items.map(ce=>w.jsx("button",{type:"button",role:"menuitem",onClick:Ee=>{Ee.stopPropagation(),De.choose(ce.value)},children:ce.label},ce.value))]}),$e.visuals.wire!==null&&w.jsxs("svg",{className:"stu-dx-wire","aria-hidden":"true",children:[w.jsx("line",{x1:$e.visuals.wire.x1,y1:$e.visuals.wire.y1,x2:$e.visuals.wire.x2,y2:$e.visuals.wire.y2}),w.jsx("circle",{cx:$e.visuals.wire.x2,cy:$e.visuals.wire.y2,r:4})]}),$e.visuals.snap!==null&&w.jsx("div",{className:"stu-dx-snap",style:{left:$e.visuals.snap.left,top:$e.visuals.snap.top,width:$e.visuals.snap.width,height:$e.visuals.snap.height}}),$e.visuals.target!==null&&w.jsx("div",{className:"stu-dx-connect-target",style:{left:$e.visuals.target.left-3,top:$e.visuals.target.top-3,width:$e.visuals.target.width+6,height:$e.visuals.target.height+6}}),Ge.visuals.snap!==null&&w.jsx("div",{className:"stu-dx-snap",style:{left:Ge.visuals.snap.left,top:Ge.visuals.snap.top,width:Ge.visuals.snap.width,height:Ge.visuals.snap.height}}),fe.snap!==null&&w.jsx("div",{className:"stu-dx-snap",style:{left:fe.snap.left,top:fe.snap.top,width:fe.snap.width,height:fe.snap.height}}),fe.box!==null&&w.jsx("div",{className:"stu-dx-marquee",style:{left:fe.box.left,top:fe.box.top,width:fe.box.width,height:fe.box.height}}),$e.visuals.picker!==null&&w.jsxs("div",{className:"stu-dx-connect-picker",role:"menu","aria-label":$e.visuals.picker.title,style:{left:$e.visuals.picker.left+6,top:$e.visuals.picker.top+6},onClick:ce=>ce.stopPropagation(),children:[w.jsx("div",{className:"stu-dx-connect-picker-title",children:$e.visuals.picker.title}),$e.visuals.picker.items.map(ce=>w.jsx("button",{type:"button",role:"menuitem",onClick:Ee=>{Ee.stopPropagation(),$e.choose(ce.value)},children:ce.label},ce.value))]}),we.snap!==null&&w.jsx("div",{className:"stu-dx-snap",style:{left:we.snap.left,top:we.snap.top,width:we.snap.width,height:we.snap.height}}),we.drop!==null&&w.jsx("div",{className:"stu-dx-drop",style:{left:we.drop.left,top:we.drop.top,width:we.drop.width,height:we.drop.height}}),we.ghost!==null&&w.jsx("div",{className:"stu-dx-ghost",style:{left:we.ghost.box.left,top:we.ghost.box.top,width:we.ghost.box.width,height:we.ghost.box.height},children:w.jsx("span",{children:we.ghost.label})}),$!==null&&T===null&&$.path!==K&&w.jsxs(w.Fragment,{children:[w.jsx("div",{className:"stu-dx-hl",style:{left:$.rect.left-3,top:$.rect.top-3,width:$.rect.width+6,height:$.rect.height+6}}),$.twins.map((ce,Ee)=>w.jsx("div",{className:"stu-dx-hl stu-dx-hl-twin",style:{left:ce.left-3,top:ce.top-3,width:ce.width+6,height:ce.height+6}},`tw${Ee}`)),w.jsx("div",{className:"stu-dx-chip",style:{left:Math.max(0,$.rect.left-3),top:zt?$.rect.top-13:$.rect.top+$.rect.height-7},children:Pr(Dn($.path))}),En&&w.jsx("button",{type:"button",className:"stu-dx-x","aria-label":`Remove ${Pr(Dn($.path))}`,title:"Remove",style:{left:$.rect.left+$.rect.width-8,top:$.rect.top-8},onClick:ce=>{ce.stopPropagation(),Bt(ce)},children:"×"})]}),I.map(ce=>w.jsx("button",{type:"button",className:"stu-dx-add stu-dx-add-spot",style:{left:ce.at?.left??0,top:ce.at?.top??0},onClick:Ee=>{Ee.stopPropagation(),kt(ce.listPath)},children:ce.label},ce.listPath)),y!==null&&bY.createPortal(w.jsx(SY,{items:y.items,at:y.at,onPick:pt,onClose:Xe}),document.body),T!==null&&w.jsx(TX,{host:m,root:u,data:t,path:Dn(T.path),anchor:T.anchor,focusField:T.focusField,onClose:()=>{N(null),Ni("micro-close")},onMovedTo:ce=>ve(ce),onRemoveItem:()=>Nt.current(T.path)})]}),(j.length>0||_t)&&w.jsxs("div",{className:"stu-dx-addbar",onClick:ce=>ce.stopPropagation(),children:[_t&&w.jsx("button",{type:"button",className:"stu-dx-add stu-dx-add-steps",title:"Describe each step — a Step-by-step list renders below the diagram",onClick:dt,children:"+ Add step descriptions"}),j.map(ce=>w.jsx("button",{type:"button",className:"stu-dx-add",onClick:()=>kt(ce.listPath),children:ce.label},ce.listPath))]})]})}function Ex(e,t,n){if(n.length<2)return{raw:e,expanded:null};const s=DM(e);if(!s.ok)return{raw:e,expanded:null};for(let o=0;o<n.length-1;o++){if(typeof n[o]!="number")continue;const r=n.slice(0,o+1),i=is(s.data,r),l=is(t,r);if(!(i===void 0||l===void 0)&&JSON.stringify(i)!==JSON.stringify(l))return{raw:Ai(e,r,l),expanded:r}}return{raw:e,expanded:null}}function Mx(e,t,n){let s=e;const o=new Set;for(const r of n){const i=r.join("\0");o.has(i)||(o.add(i),s=sD(s,r,t))}return s}function kQ(e,t,n,s,o){const r=t.segments[n];if(r===void 0||r.kind==="markdown")throw new TypeError(`segment ${n} is not a typed block`);const i=Ex(ch(r),r.data,s),l=Ai(i.raw,s,o,r.kind);return lh(e,t,n,Mx(l,r.kind,i.expanded===null?[]:[i.expanded]))}function bQ(e,t,n,s){const o=t.segments[n];if(o===void 0||o.kind==="markdown")throw new TypeError(`segment ${n} is not a typed block`);let r=ch(o);const i=[];for(const l of s){const d=Ex(r,o.data,l.path);r=d.raw,d.expanded!==null&&i.push(d.expanded)}for(const l of s)r=Ai(r,l.path,l.value,o.kind);return lh(e,t,n,Mx(r,o.kind,i))}function wQ(e,t,n,s){const o=t.segments[n];if(o===void 0||o.kind==="markdown")throw new TypeError(`segment ${n} is not a typed block`);const r=Ex(ch(o),o.data,s),i=h0(r.raw,s);return lh(e,t,n,Mx(i,o.kind,r.expanded===null?[]:[r.expanded]))}function $Q(e,t){return{kind:t,commitPath:(n,s)=>{ke.getState().applyOp((r,i)=>kQ(r,i,e,n,s),e)},commitPaths:n=>{ke.getState().applyOp((o,r)=>bQ(o,r,e,n),e)},deletePath:n=>{ke.getState().applyOp((o,r)=>wQ(o,r,e,n),e)},openFull:()=>ke.getState().openSheet(e),notify:n=>ke.getState().toast(n)}}function KC(e,t){return e.filter(n=>n.line!==void 0&&n.line>=t.startLine&&n.line<=t.endLine)}function SQ(e,t,n,s){const o=n.segments[s];return o===void 0?[]:KC(e,Xo(t,o))}function VC(e){let t=0,n=0;for(const s of e)s.level==="error"?t+=1:n+=1;return{errors:t,warnings:n}}function EQ(e,t,n){return n.segments.map((s,o)=>VC(SQ(e,t,n,o)))}function Vv(e){ke.getState().openPicker({view:"compact",index:e.index,anchor:{x:e.x,y:e.y}})}function MQ(e){try{const t=JSON.parse(e);return t.kind==="move"&&typeof t.from=="number"?{kind:"move",from:t.from}:null}catch{return null}}function YS({minIndex:e}){const[t,n]=oe.useState(!1),s=oe.useRef(0);return oe.useEffect(()=>{const o=()=>{s.current=0,n(!1)},r=u=>{Ka(u.dataTransfer?.types)&&(s.current+=1,n(!0))},i=u=>{Ka(u.dataTransfer?.types)&&(u.preventDefault(),u.dataTransfer!==null&&(u.dataTransfer.dropEffect="copy"))},l=u=>{Ka(u.dataTransfer?.types)&&(s.current-=1,s.current<=0&&o())},d=u=>{if(!Ka(u.dataTransfer?.types))return;u.preventDefault(),o();const p=u.dataTransfer?.files[0];if(p===void 0)return;const h=Array.from(document.querySelectorAll("[data-seg]")).map(m=>({el:m,index:Number(m.getAttribute("data-seg"))})).sort((m,g)=>m.index-g.index).map(({el:m})=>{const g=m.getBoundingClientRect();return{top:g.top,bottom:g.bottom}});gC(p,hY(u.clientY,h,e))};return window.addEventListener("dragenter",r),window.addEventListener("dragover",i),window.addEventListener("dragleave",l),window.addEventListener("drop",d),window.addEventListener("dragend",o),()=>{window.removeEventListener("dragenter",r),window.removeEventListener("dragover",i),window.removeEventListener("dragleave",l),window.removeEventListener("drop",d),window.removeEventListener("dragend",o)}},[e]),t?w.jsx("div",{className:"stu-dropveil","aria-hidden":"true",children:w.jsxs("div",{className:"stu-dropveil-card",children:[w.jsx("div",{className:"stu-dropveil-title",children:"Drop to import"}),w.jsxs("div",{className:"stu-dropveil-sub",children:[w.jsx("code",{children:".csv"})," → table block · OpenAPI ",w.jsx("code",{children:".yaml"}),"/",w.jsx("code",{children:".json"})," → new doc"]})]})}):null}function XS({index:e,locked:t,onPlus:n}){const s=ke(l=>l.dragging),[o,r]=oe.useState(!1);if(t===!0)return w.jsx("div",{className:"stu-gap stu-gap-locked"});const i=l=>{if(Ka(l.dataTransfer.types))return;l.preventDefault(),r(!1);const d=ke.getState(),u=MQ(l.dataTransfer.getData("text/plain"))??d.dragging;if(d.setDragging(null),u===null)return;const p=u.from;e===p||e===p+1||d.moveBlock(p,e)};return w.jsxs("div",{className:`stu-gap ${s!==null?"stu-gap-armed":""} ${o?"stu-gap-over":""}`,onDragOver:l=>{Ka(l.dataTransfer.types)||(l.preventDefault(),r(!0))},onDragLeave:()=>r(!1),onDrop:i,children:[w.jsx("div",{className:"stu-gap-line"}),s===null&&w.jsx("button",{type:"button",className:"stu-gap-plus","aria-label":"Insert a block here",title:"Insert a block",onClick:l=>{l.stopPropagation();const d=l.currentTarget.getBoundingClientRect();n({index:e,x:d.left+d.width/2,y:d.bottom})},children:w.jsx(dd,{size:13})})]})}function AQ({index:e,text:t,onDone:n}){const[s,o]=oe.useState(t),r=oe.useRef(null),i=ke(d=>d.applyOp);oe.useEffect(()=>{const d=r.current;d!==null&&(d.focus(),d.setSelectionRange(d.value.length,d.value.length),d.style.height="auto",d.style.height=`${d.scrollHeight+2}px`)},[]);const l=()=>{s!==t&&i((d,u)=>J6(d,u,e,s)),n()};return w.jsx("textarea",{ref:r,className:"stu-prose-editor",value:s,onChange:d=>{o(d.target.value),d.target.style.height="auto",d.target.style.height=`${d.target.scrollHeight+2}px`},onBlur:l,onKeyDown:d=>{(d.metaKey||d.ctrlKey)&&d.key==="Enter"&&(d.preventDefault(),l()),d.key==="Escape"&&(d.stopPropagation(),n())}})}function CQ(){const e=ke(t=>t.penMode);return e===null?null:w.jsx("button",{type:"button",className:`stu-tool ${e.on?"stu-tool-on":""}`,title:"Draw a node — sketch a shape on the diagram (D)","aria-label":"Draw a node","aria-pressed":e.on,onClick:()=>ke.getState().setPenMode({seg:e.seg,on:!e.on}),children:w.jsx(vX,{size:13})})}function NQ({index:e,count:t,isMeta:n,metaFirst:s,onEdit:o,onDelete:r}){const i=ke(l=>l.setDragging);return n?w.jsx("div",{className:"stu-blocktools",onClick:l=>l.stopPropagation(),children:w.jsx("button",{type:"button",className:"stu-tool",title:"Edit","aria-label":"Edit",onClick:o,children:w.jsx(P0,{size:13})})}):w.jsxs("div",{className:"stu-blocktools",onClick:l=>l.stopPropagation(),children:[w.jsx("span",{className:"stu-tool stu-tool-grip",title:"Drag to move",draggable:!0,onDragStart:l=>{l.dataTransfer.setData("text/plain",JSON.stringify({kind:"move",from:e})),l.dataTransfer.effectAllowed="move",i({kind:"move",from:e})},onDragEnd:()=>i(null),children:w.jsx(gX,{size:13})}),w.jsx("button",{type:"button",className:"stu-tool",title:"Edit","aria-label":"Edit",onClick:o,children:w.jsx(P0,{size:13})}),w.jsx(CQ,{}),w.jsx("button",{type:"button",className:"stu-tool",title:"Duplicate","aria-label":"Duplicate",onClick:()=>aC(e),children:w.jsx(TC,{size:13})}),w.jsx("button",{type:"button",className:"stu-tool",title:"Move up","aria-label":"Move up",disabled:e===0||s&&e===1,onClick:()=>lC(e),children:w.jsx(yX,{size:13})}),w.jsx("button",{type:"button",className:"stu-tool",title:"Move down","aria-label":"Move down",disabled:e===t-1,onClick:()=>cC(e),children:w.jsx(xX,{size:13})}),w.jsx("button",{type:"button",className:"stu-tool stu-tool-danger",title:"Delete","aria-label":"Delete",onClick:r,children:w.jsx(vx,{size:13})})]})}const TQ={errors:0,warnings:0};function _Q({index:e,count:t,seg:n,html:s,metaFirst:o,levels:r}){const i=ke(D=>D.selection===e),l=ke(D=>D.select),d=ke(D=>D.openSheet),u=ke(D=>D.sheet!==null),[p,h]=oe.useState(!1),[m,g]=oe.useState(null),v=oe.useRef(null),y=n.kind==="markdown",b=!y&&n.kind!=="meta",E=b&&i&&!u&&s!=="",$=n.kind,A=oe.useMemo(()=>b&&$!=="markdown"?$Q(e,$):null,[b,e,$]),T=()=>{y?h(!0):d(e)},N=D=>{if(!pC(n)){dS(e);return}const F=D.currentTarget.getBoundingClientRect();ke.getState().requestDelete({label:Ua(n),anchor:{x:F.left+F.width/2,y:F.bottom},run:()=>dS(e)})};oe.useEffect(()=>{if(!i||u||p)return;const D=F=>{F.key!=="Enter"||F.metaKey||F.ctrlKey||F.altKey||F.shiftKey||wl(F.target)||(F.preventDefault(),T())};return window.addEventListener("keydown",D),()=>window.removeEventListener("keydown",D)},[i,u,p,e,y]);const j=D=>{D.target.closest("a")!==null&&D.preventDefault(),!p&&(l(e),y&&h(!0))},P=D=>{!b||p||u||s===""||E||(D.preventDefault(),l(e),g({x:D.clientX,y:D.clientY}))},I=oe.useCallback(()=>g(null),[]),O=D=>{p||E&&D.target.closest("[data-bp]")!==null||T()};let C;return y&&p?C=w.jsx(AQ,{index:e,text:n.text,onDone:()=>h(!1)}):n.kind==="meta"?C=w.jsxs("div",{className:"stu-placeholder stu-placeholder-meta",children:[w.jsx("span",{className:"stu-placeholder-chip",children:"cover"}),"Document cover — title, subtitle & tag. Double-click to edit."]}):s===""?C=w.jsxs("div",{className:"stu-placeholder stu-placeholder-empty",children:[w.jsx("span",{className:"stu-placeholder-chip",children:n.kind}),"Empty ",n.kind==="markdown"?"text":il[n.kind].toLowerCase()," block — double-click to fill it in."]}):C=w.jsx("div",{className:"stu-seg-html",dangerouslySetInnerHTML:{__html:s}}),w.jsxs("div",{ref:v,className:`stu-seg ${i?"stu-seg-selected":""} ${p?"stu-seg-editing":""} ${!p&&r.errors>0?"stu-seg-err":""}`,"data-seg":e,onClickCapture:j,onDoubleClick:O,onContextMenu:P,children:[!p&&w.jsx(NQ,{index:e,count:t,isMeta:n.kind==="meta",metaFirst:o,onEdit:T,onDelete:N}),!p&&(r.errors>0||r.warnings>0)&&w.jsxs("span",{className:`stu-seg-diag ${r.errors>0?"stu-seg-diag-err":"stu-seg-diag-warn"}`,children:[n.kind==="markdown"?"text":n.kind," ·"," ",r.errors>0?`${r.errors} error${r.errors===1?"":"s"}`:`${r.warnings} warning${r.warnings===1?"":"s"}`]}),C,E&&A!==null&&w.jsx(UC,{host:A,data:n.data,html:s,wrapperRef:v,segIndex:e,pendingMenu:m,onPendingMenuConsumed:I})]})}function LQ(){return w.jsx("div",{className:"stu-hero",children:w.jsxs("div",{className:"stu-hero-card",children:[w.jsx("div",{className:"stu-hero-mark","aria-hidden":"true"}),w.jsx("h1",{children:"Create your first doc"}),w.jsxs("p",{children:["This project has no docs yet. Open the doc switcher in the top bar and pick"," ",w.jsx("strong",{children:"New doc"}),", or run ",w.jsx("code",{children:"chiltepin init"})," in your terminal."]})]})})}function IQ(){const{doc:e,rendered:t,renderError:n,diagnostics:s}=Co(),o=ke(y=>y.source),r=ke(y=>y.docs),i=ke(y=>y.loaded),l=ke(y=>y.currentSlug),d=ke(y=>y.select),u=ke(y=>y.slashHintAt),p=GA(),h=u!==null&&!dY(),m=oe.useMemo(()=>EQ(s,o,e),[s,o,e]);if(i&&r.length===0)return w.jsxs("main",{className:"stu-canvas",children:[w.jsx(LQ,{}),w.jsx(YS,{minIndex:0})]});if(l===null||t===null)return w.jsx("main",{className:"stu-canvas",children:n!==null&&w.jsxs("div",{className:"stu-render-error",children:["Render failed: ",n]})});const g=e.segments.length,v=e.segments[0]?.kind==="meta";return w.jsxs("main",{className:"stu-canvas","data-tour":"canvas",onClick:()=>d(null),children:[w.jsx("style",{children:t.css}),w.jsx("div",{className:"stu-page","data-doc-theme":Mh(p==="dark"),onClick:y=>y.stopPropagation(),children:w.jsxs("div",{className:"docskin",children:[w.jsx("div",{dangerouslySetInnerHTML:{__html:t.defs}}),v?w.jsxs("div",{className:"stu-cover",role:"button",tabIndex:0,title:"Edit the cover — title, subtitle & tag",onClick:y=>{y.stopPropagation(),ke.getState().openSheet(0)},onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),ke.getState().openSheet(0))},children:[w.jsx("div",{dangerouslySetInnerHTML:{__html:t.cover}}),w.jsx("span",{className:"stu-cover-edit",children:"✎ Edit cover"})]}):w.jsx("div",{dangerouslySetInnerHTML:{__html:t.cover}}),w.jsx(XS,{index:0,locked:v,onPlus:Vv}),e.segments.map((y,b)=>w.jsxs("div",{children:[!(v&&b===0)&&w.jsx(_Q,{index:b,count:g,seg:y,html:t.segments[b]?.html??"",metaFirst:v,levels:m[b]??TQ}),h&&u===b&&w.jsxs("div",{className:"stu-slash-next",role:"note",children:["press ",w.jsx("kbd",{children:"/"})," for the next block"]}),w.jsx(XS,{index:b+1,onPlus:Vv})]},b)),g===0&&w.jsxs("div",{className:"stu-ghost",children:[w.jsx("button",{type:"button",className:"stu-ghost-plus","aria-label":"Add your first block",onClick:y=>{y.stopPropagation();const b=y.currentTarget.getBoundingClientRect();Vv({index:0,x:b.left+b.width/2,y:b.bottom})},children:w.jsx(dd,{size:16})}),w.jsxs("span",{children:["Press ",w.jsx("kbd",{children:"+"})," or ",w.jsx("kbd",{children:"/"})," to add your first block"]})]})]})}),w.jsx(YS,{minIndex:v?1:0})]})}function GC(e,t){return"```"+e+`
3255
3255
  `+(t===""?"":t+`
3256
3256
  `)+"```\n"}function z0(e,t){const n=GC(e,t),s=ys(n,"preview"),o=s.segments[0],r=o!==void 0&&o.kind!=="markdown"?o:void 0,i=wy(s,"preview.md"),l=n.split(`
3257
3257
  `).length,d=KC(i,{startLine:1,endLine:l});let u="";try{const p=Zi(s),h=e==="meta"?p.cover:p.segments[0]?.html??"";u=h===""?"":p.defs+h}catch{u=""}return{seg:r,html:u,diagnostics:d}}function YC(e,t){const n=[];e.split(`
3258
- `).forEach((r,i)=>{const l=/^([A-Za-z_][\w-]*)\s*:/.exec(r);l!==null&&l[1]!==void 0&&n.push({name:l[1],startLine:i+1})});const s=new Map,o=[];for(const r of t){if(r.line===void 0){o.push(r);continue}const i=r.line-1;let l=null;for(const u of n)if(u.startLine<=i)l=u.name;else break;if(l===null){o.push(r);continue}const d=s.get(l);d===void 0?s.set(l,[r]):d.push(r)}return{byField:s,rest:o}}function IQ(e,t,n){const s=t.segments.map(o=>Xo(e,o));return n.map(o=>{const r=o.line??null;let i=null;if(r!==null){const u=s.findIndex(p=>r>=p.startLine&&r<=p.endLine);i=u===-1?null:u}const l=i!==null?t.segments[i]:void 0;let d=null;if(l!==void 0&&l.kind!=="markdown"&&i!==null&&r!==null){const u=s[i];if(u!==void 0){const p={...o,line:r-u.startLine+1},{byField:h}=YC(l.raw,[p]);d=[...h.keys()][0]??null}}return{level:o.level,code:o.code,message:o.message,hint:o.hint??null,line:r,segIndex:i,segKind:l?.kind??null,field:d}})}function Ax(e,t){return t.slug!==null&&e.slug===t.slug?t.errors>0?{kind:"errors",count:t.errors}:{kind:"pass"}:e.errorCount===void 0?{kind:"unknown"}:e.errorCount>0?{kind:"errors",count:e.errorCount}:{kind:"pass"}}function jQ(e){const t=e.indexOf("/");return t===-1?"":e.slice(0,t)}function XC(e,t){const n=e.lastIndexOf("/");return n===-1?t:`${t}/${e.slice(0,n)}`}function PQ(e,t){const n=new Map;for(const o of e){const r=jQ(o.slug),i=n.get(r);i===void 0?n.set(r,[o]):i.push(o)}return[...n.keys()].sort((o,r)=>o===""?-1:r===""?1:o.localeCompare(r)).map(o=>({key:o,label:o===""?t:`${t} / ${o}`,docs:[...n.get(o)??[]].sort((r,i)=>r.title.localeCompare(i.title))}))}function F0(e,t=Date.now()){const n=Math.max(0,Math.floor((t-e)/1e3));if(n<60)return"just now";const s=Math.floor(n/60);if(s<60)return`${s}m ago`;const o=Math.floor(s/60);if(o<24)return`${o}h ago`;const r=Math.floor(o/24);return r<30?`${r}d ago`:new Date(e).toLocaleDateString()}const QS=new Map;function ZS(e){const t=QS.get(e);if(t!==void 0)return t;let n="";try{const s=ys(BM[e],`thumb-${e}`),o=Zi(s),r=e==="meta"?o.cover:o.segments[0]?.html??"";n=r===""?"":o.defs+r}catch{n=""}return QS.set(e,n),n}const JS=new Map;function OQ(e,t,n){const s=JS.get(e);if(s!==void 0)return s;let o="";try{const r=ys(t,n),i=Zi(r),l=new Set(["meta","callout","prose"]);let d="";for(let u=0;u<r.segments.length;u+=1){const p=r.segments[u],h=i.segments[u]?.html??"";if(!(p===void 0||p.kind==="markdown"||h==="")&&!l.has(p.kind)){d=h;break}}d===""&&(d=i.segments.find(u=>u.html!=="")?.html??i.cover),o=d===""?"":i.defs+d}catch{o=""}return JS.set(e,o),o}const RQ=820,DQ=.3;function BQ({status:e}){return e.kind==="unknown"?null:e.kind==="errors"?w.jsxs("span",{className:"stu-doclist-status stu-doclist-status-err",children:[e.count," error",e.count===1?"":"s"]}):w.jsx("span",{className:"stu-doclist-status stu-doclist-status-ok",children:"✓ pass"})}function zQ({doc:e,folder:t,edited:n,status:s,onOpen:o}){const[r,i]=oe.useState(null),l=oe.useRef(null),d=`${e.slug}@${String(e.mtimeMs)}`;return oe.useEffect(()=>{const u=l.current;if(u===null)return;let p=!1;const h=()=>{Bp(e.slug).then(g=>{p||i(OQ(d,g.source,e.slug))}).catch(()=>{p||i("")})};if(typeof IntersectionObserver>"u")return h(),()=>{p=!0};const m=new IntersectionObserver(g=>{g.some(v=>v.isIntersecting)&&(h(),m.disconnect())},{rootMargin:"160px"});return m.observe(u),()=>{p=!0,m.disconnect()}},[e.slug,d]),w.jsxs("button",{ref:l,type:"button",className:"stu-doccard",title:e.slug,onClick:o,children:[w.jsx("div",{className:"stu-doccard-thumb","aria-hidden":"true",children:r!==null&&r!==""?w.jsx("div",{className:"docskin stu-thumb-doc",style:{width:RQ,transform:`scale(${String(DQ)})`},dangerouslySetInnerHTML:{__html:r}}):w.jsx("div",{className:"stu-doccard-blank",children:w.jsx(Df,{size:22})})}),w.jsxs("div",{className:"stu-doccard-body",children:[w.jsx("span",{className:"stu-doccard-title",children:e.title}),w.jsxs("span",{className:"stu-doccard-meta",children:[w.jsx("span",{className:"stu-doccard-folder",children:t}),w.jsx("span",{className:"stu-doccard-edited stu-num",children:n}),w.jsx(BQ,{status:s})]})]})]})}const Gv=4;function QC({onClose:e,initial:t}){const n=ke(E=>E.newDoc),[s,o]=oe.useState(t??"blank"),[r,i]=oe.useState(t!==void 0&&t!=="blank"?t:""),[l,d]=oe.useState(""),[u,p]=oe.useState(!1),h=oe.useRef(null),m=oe.useRef(null);oe.useEffect(()=>{requestAnimationFrame(()=>h.current?.focus())},[]),oe.useEffect(()=>{const E=$=>{$.key==="Escape"&&($.stopPropagation(),e())};return window.addEventListener("keydown",E,!0),()=>window.removeEventListener("keydown",E,!0)},[e]);const g=l.trim().toLowerCase(),v=oe.useMemo(()=>g===""?kw:kw.filter(E=>E.id.includes(g)||E.title.toLowerCase().includes(g)||E.description.toLowerCase().includes(g)||E.blockTypes.some($=>$.includes(g))),[g]),y=E=>{o(E),u||i(E==="blank"?"":E)},b=()=>{const E=r.trim().replace(/\.md$/,"");if(E===""){h.current?.focus();return}const $=s==="blank"?void 0:Ny[s];n(E,$),e()};return w.jsx("div",{className:"stu-sheet-backdrop",onMouseDown:E=>{m.current!==null&&!m.current.contains(E.target)&&e()},children:w.jsxs("div",{className:"stu-tpl",ref:m,role:"dialog","aria-modal":"true","aria-label":"Create a new doc",children:[w.jsxs("div",{className:"stu-tpl-head",children:[w.jsx("h2",{children:"New doc"}),w.jsx("input",{ref:h,className:"stu-tpl-slug",type:"text",placeholder:"slug, e.g. guides/onboarding","aria-label":"Doc slug",value:r,onChange:E=>{i(E.target.value),p(E.target.value.trim()!=="")},onKeyDown:E=>{E.key==="Enter"&&(E.preventDefault(),b())}})]}),w.jsx("label",{className:"stu-tpl-filter",children:w.jsx("input",{type:"text",placeholder:"Filter — adr, migration, sequence…","aria-label":"Filter templates",value:l,onChange:E=>d(E.target.value)})}),w.jsxs("div",{className:"stu-tpl-body",role:"radiogroup","aria-label":"Starting point",children:[g===""&&w.jsxs("button",{type:"button",role:"radio","aria-checked":s==="blank",className:`stu-tpl-card ${s==="blank"?"stu-tpl-card-active":""}`,onClick:()=>y("blank"),onDoubleClick:b,children:[w.jsxs("span",{className:"stu-tpl-card-title",children:[w.jsx(Df,{size:13}),"Blank"]}),w.jsx("span",{className:"stu-tpl-card-desc",children:"Just the cover — start from nothing and insert blocks with “/”."})]}),v.map(E=>w.jsxs("button",{type:"button",role:"radio","aria-checked":s===E.id,className:`stu-tpl-card ${s===E.id?"stu-tpl-card-active":""}`,onClick:()=>y(E.id),onDoubleClick:b,children:[w.jsxs("span",{className:"stu-tpl-card-title",children:[w.jsx(Df,{size:13}),E.title]}),w.jsx("span",{className:"stu-tpl-card-desc",children:E.description}),w.jsxs("span",{className:"stu-tpl-card-chips","aria-hidden":"true",children:[E.blockTypes.slice(0,Gv).map($=>w.jsx("code",{children:$},$)),E.blockTypes.length>Gv&&w.jsxs("code",{children:["+",E.blockTypes.length-Gv]})]})]},E.id)),v.length===0&&w.jsxs("p",{className:"stu-tpl-none",children:["Nothing matches “",l,"”."]})]}),w.jsxs("div",{className:"stu-tpl-foot",children:[w.jsx("span",{className:"stu-tpl-hint",children:"Enter creates · Esc closes"}),w.jsx("button",{type:"button",className:"stu-btn",onClick:e,children:"Cancel"}),w.jsx("button",{type:"button",className:"stu-btn stu-btn-primary",onClick:b,children:"Create"})]})]})})}const FQ=[{id:"system-design",label:"system design"},{id:"adr",label:"ADR"},{id:"api-spec",label:"API spec"},{id:"postmortem",label:"postmortem"},{id:"blank",label:"blank"}];function qQ({docsDir:e}){const[t,n]=oe.useState(null);return w.jsxs("div",{className:"stu-doclist-empty",children:[w.jsxs("div",{className:"stu-doclist-empty-inner",children:[w.jsx("div",{className:"stu-doclist-empty-icon",children:w.jsx(Df,{size:26})}),w.jsx("div",{className:"stu-doclist-empty-title",children:"No documents yet"}),w.jsxs("p",{className:"stu-doclist-empty-sub",children:["Every doc is a Markdown file in ",w.jsxs("code",{children:[e,"/"]}),". Start from a template — delete what you don’t need."]}),w.jsx("button",{type:"button",className:"stu-btn stu-btn-primary",onClick:()=>n("blank"),children:"Create your first doc"}),w.jsx("div",{className:"stu-doclist-empty-chips",children:FQ.map(s=>w.jsx("button",{type:"button",className:"stu-doclist-empty-chip",onClick:()=>n(s.id),children:s.label},s.id))})]}),t!==null&&w.jsx(QC,{initial:t,onClose:()=>n(null)})]})}function HQ(){const e=ke(h=>h.docs),t=ke(h=>h.meta),n=ke(h=>h.currentSlug),s=ke(h=>h.openDoc),o=ke(h=>h.setMode),{diagnostics:r}=Co(),i=t?.docsDir??"docs",l=r.filter(h=>h.level==="error").length,d=oe.useMemo(()=>[...e].sort((h,m)=>m.mtimeMs-h.mtimeMs),[e]),u=oe.useMemo(()=>Zi(ys("","home-skin")).css,[]);if(e.length===0)return w.jsx(qQ,{docsDir:i});const p=h=>{s(h),o("edit")};return w.jsxs("div",{className:"stu-doclist",children:[w.jsx("style",{children:u}),w.jsx("div",{className:"stu-doclist-inner stu-doclist-inner-wide",children:w.jsx("div",{className:"stu-doclist-grid",children:d.map(h=>w.jsx(zQ,{doc:h,folder:XC(h.slug,i),edited:F0(h.mtimeMs),status:Ax(h,{slug:n,errors:l}),onOpen:()=>p(h.slug)},h.slug))})})]})}const eE=""+new URL("mark-CiYXXpnT.png",import.meta.url).href;function WQ({onClose:e}){const t=ke(o=>o.autosave),n=ke(o=>o.setAutosave),s=oe.useRef(null);return oe.useEffect(()=>{const o=i=>{s.current!==null&&!s.current.contains(i.target)&&e()},r=i=>{i.key==="Escape"&&(i.stopPropagation(),e())};return window.addEventListener("mousedown",o),window.addEventListener("keydown",r,!0),()=>{window.removeEventListener("mousedown",o),window.removeEventListener("keydown",r,!0)}},[e]),w.jsxs("div",{className:"stu-rail-settings",ref:s,role:"dialog","aria-label":"Settings",children:[w.jsx("div",{className:"stu-rail-settings-title",children:"Settings"}),w.jsxs("label",{className:"stu-autosave","data-tour":"autosave",children:[w.jsx("input",{type:"checkbox",checked:t,onChange:o=>n(o.target.checked)}),w.jsx("span",{className:"stu-switch","aria-hidden":"true"}),"Autosave"]}),w.jsx("p",{className:"stu-rail-settings-hint",children:"Off: ⌘S reviews every change before it touches the disk."})]})}function UQ(){const e=ke(I=>I.docs),t=ke(I=>I.meta),n=ke(I=>I.mode),s=ke(I=>I.currentSlug),o=ke(I=>I.openDoc),r=ke(I=>I.setMode),{diagnostics:i}=Co(),[l,d]=oe.useState(""),[u,p]=oe.useState(!1),[h,m]=oe.useState(!1),[g,v]=oe.useState(!1),y=oe.useRef(null),b=oe.useRef(null),E=t?.docsDir??"docs",$=i.filter(I=>I.level==="error").length,A=l.trim().toLowerCase(),T=oe.useMemo(()=>{const I=A===""?e:e.filter(O=>O.title.toLowerCase().includes(A)||O.slug.toLowerCase().includes(A));return PQ(I,E)},[e,A,E]);oe.useEffect(()=>{const I=O=>{(O.metaKey||O.ctrlKey)&&O.key.toLowerCase()==="k"&&(O.preventDefault(),v(!0),requestAnimationFrame(()=>y.current?.focus()))};return window.addEventListener("keydown",I),()=>window.removeEventListener("keydown",I)},[]),oe.useEffect(()=>{if(!g)return;const I=C=>{b.current!==null&&!b.current.contains(C.target)&&v(!1)},O=C=>{C.key==="Escape"&&(C.stopPropagation(),v(!1))};return window.addEventListener("mousedown",I),window.addEventListener("keydown",O,!0),()=>{window.removeEventListener("mousedown",I),window.removeEventListener("keydown",O,!0)}},[g]);const N=()=>{v(!1),r("home")},j=I=>{v(!1),o(I),ke.getState().mode!=="edit"&&r("edit")},P=n!=="home"&&s!==null?`/site/${s}.html`:"/site/";return w.jsxs("nav",{className:`stu-rail ${g?"stu-rail-drawer":""}`,"aria-label":"Documents",ref:b,"data-tour":"rail",children:[w.jsxs("div",{className:"stu-rail-mini","aria-hidden":g,children:[w.jsx("button",{type:"button",className:"stu-rail-mini-mark",title:"All documents",onClick:N,children:w.jsx("img",{src:eE,alt:""})}),w.jsx("button",{type:"button",className:"stu-rail-mini-btn",title:"Search docs (⌘K)",onClick:()=>{v(!0),requestAnimationFrame(()=>y.current?.focus())},children:w.jsx(Of,{size:15})}),w.jsx("button",{type:"button",className:`stu-rail-mini-btn ${n==="home"?"stu-rail-mini-on":""}`,title:"All documents",onClick:N,children:w.jsx(IS,{size:15})}),w.jsx("button",{type:"button",className:"stu-rail-mini-btn",title:"New doc",onClick:()=>p(!0),children:w.jsx(dd,{size:15})})]}),w.jsxs("div",{className:"stu-rail-full",children:[w.jsxs("button",{type:"button",className:"stu-rail-brand",title:"All documents",onClick:N,children:[w.jsx("img",{src:eE,alt:"",className:"stu-rail-mark","aria-hidden":"true"}),w.jsxs("span",{className:"stu-rail-name",children:["chiltepin ",w.jsx("em",{children:"studio"})]})]}),w.jsxs("label",{className:`stu-rail-search ${e.length===0?"stu-rail-search-off":""}`,children:[w.jsx(Of,{size:13}),w.jsx("input",{ref:y,type:"text",placeholder:"Search docs","aria-label":"Search docs",disabled:e.length===0,value:l,onChange:I=>d(I.target.value),onKeyDown:I=>{const O=T[0]?.docs[0];I.key==="Enter"&&A!==""&&O!==void 0&&j(O.slug)}}),w.jsx("kbd",{children:"⌘K"})]}),w.jsxs("button",{type:"button",className:"stu-rail-new",onClick:()=>p(!0),children:[w.jsx(dd,{size:12}),"New doc"]}),w.jsxs("button",{type:"button",className:`stu-rail-doc stu-rail-root ${n==="home"?"stu-rail-doc-on":""}`,onClick:N,children:[w.jsx(IS,{size:14}),w.jsx("span",{className:"stu-rail-doc-name",children:"All documents"})]}),w.jsxs("div",{className:"stu-rail-scroll",children:[T.map(I=>w.jsxs("div",{children:[w.jsxs("div",{className:"stu-rail-group",children:[w.jsx("span",{children:I.label}),w.jsx("span",{className:"stu-num",children:I.docs.length})]}),I.docs.map(O=>{const C=n!=="home"&&O.slug===s;return w.jsxs("button",{type:"button",className:`stu-rail-doc ${C?"stu-rail-doc-on":""}`,title:O.slug,onClick:()=>j(O.slug),children:[w.jsx("span",{className:"stu-rail-doc-name",children:O.title}),Ax(O,{slug:s,errors:$}).kind==="errors"&&w.jsx("span",{className:"stu-rail-dot","aria-label":"has errors"})]},O.slug)})]},I.key===""?".":I.key)),A!==""&&T.length===0&&w.jsx("div",{className:"stu-rail-none",children:"No matching docs"})]}),w.jsxs("div",{className:"stu-rail-foot",children:[jy&&w.jsx("a",{href:P,target:"_blank",rel:"noreferrer",title:"Open the built site in a new tab",children:"Site ↗"}),w.jsxs("div",{className:"stu-rail-foot-settings",children:[w.jsx("button",{type:"button",onClick:()=>m(!h),children:"Settings"}),h&&w.jsx(WQ,{onClose:()=>m(!1)})]})]})]}),u&&w.jsx(QC,{onClose:()=>p(!1)})]})}function KQ(e,t){return KA(ys(e,t))}function VQ(){const e=oe.useRef(null),t=ke(s=>s.setMode),n=oe.useMemo(()=>{const s=ke.getState();if(s.currentSlug===null)return{html:null,error:"No document open."};try{return{html:KQ(s.source,s.currentSlug),error:null}}catch(o){return{html:null,error:o instanceof Error?o.message:String(o)}}},[]);return oe.useEffect(()=>{const s=requestAnimationFrame(()=>e.current?.focus());return()=>cancelAnimationFrame(s)},[]),w.jsxs("div",{className:"stu-modearea",children:[n.html!==null?w.jsx("iframe",{ref:e,className:"stu-modeframe",srcDoc:n.html,title:"Presentation"}):w.jsx("div",{className:"stu-present-empty",children:n.error}),w.jsxs("button",{type:"button",className:"stu-present-back",onClick:()=>t("edit"),title:"Back to the editor (Esc)",children:[w.jsx("span",{"aria-hidden":"true",children:"←"})," Back to editor"]})]})}const _p=8;function GQ(){const e=ke(d=>d.pendingDelete),t=ke(d=>d.confirmDelete),n=ke(d=>d.cancelDelete),s=oe.useRef(null),o=oe.useRef(null),[r,i]=oe.useState(null),l=e!==null;return oe.useLayoutEffect(()=>{if(e===null){i(null);return}const d=s.current,u=d?.offsetWidth??240,p=d?.offsetHeight??92,h=Math.min(Math.max(e.anchor.x-u/2,_p),window.innerWidth-u-_p);let m=e.anchor.y+6;m+p>window.innerHeight-_p&&(m=Math.max(_p,e.anchor.y-p-12)),i({left:h,top:m})},[e]),oe.useEffect(()=>{l&&requestAnimationFrame(()=>o.current?.focus())},[l]),oe.useEffect(()=>{if(!l)return;const d=p=>{p.key==="Escape"?(p.preventDefault(),p.stopPropagation(),n()):(p.key==="Backspace"||p.key==="Delete")&&(p.preventDefault(),p.stopPropagation(),t())},u=p=>{s.current!==null&&!s.current.contains(p.target)&&n()};return window.addEventListener("keydown",d,!0),window.addEventListener("mousedown",u,!0),()=>{window.removeEventListener("keydown",d,!0),window.removeEventListener("mousedown",u,!0)}},[l,t,n]),e===null?null:w.jsxs("div",{ref:s,className:"stu-delpop",role:"alertdialog","aria-label":`Delete ${e.label}?`,style:r??{left:e.anchor.x,top:e.anchor.y,visibility:"hidden"},children:[w.jsxs("div",{className:"stu-delpop-text",children:[w.jsx("strong",{children:e.label})," — delete?"]}),w.jsxs("div",{className:"stu-delpop-row",children:[w.jsx("span",{className:"stu-delpop-hint",children:"⌫ again confirms · ⌘Z undoes"}),w.jsx("button",{type:"button",ref:o,className:"stu-btn stu-btn-sm",onClick:n,children:"Cancel"}),w.jsx("button",{type:"button",className:"stu-btn stu-btn-sm stu-btn-danger",onClick:t,children:"Delete"})]})]})}function Hi(e){return Array.isArray(e)?e.map(t=>Array.isArray(t)?t:[]):[]}function qf(e){return Array.isArray(e)?e:null}function Dh(e,t){const n=qf(e);return n!==null&&n.length>0?n.length:Hi(t).reduce((s,o)=>Math.max(s,o.length),0)}function ZC(e,t){const n=e.slice();for(;n.length<t;)n.push("");return n}function YQ(e){return Array.from({length:Math.max(1,e)},()=>"")}function XQ(e){return e.every(t=>t===""||t===null||t===void 0)}function tE(e,t){return[...Hi(t).map(s=>s.slice()),YQ(Dh(e,t))]}function QQ(e,t){return Hi(e).filter((n,s)=>s!==t).map(n=>n.slice())}function ZQ(e,t,n){const s=Dh(e,t),o=Math.max(0,Math.min(n,s)),r=qf(e),i=r!==null?[...r.slice(0,o),"",...r.slice(o)]:null,l=Hi(t).map(d=>{const u=ZC(d,Math.min(o,s));return[...u.slice(0,o),"",...u.slice(o)]});return{columns:i,rows:l}}function JQ(e,t,n){const s=Dh(e,t);if(n<0||n>=s)return{columns:qf(e)?.slice()??null,rows:Hi(t).map(l=>l.slice())};const o=qf(e),r=o!==null?o.filter((l,d)=>d!==n):null,i=Hi(t).map(l=>{const d=ZC(l,s);return[...d.slice(0,n),...d.slice(n+1)]});return{columns:r,rows:i}}function eZ(e){const t=Hi(e.rows),n=e.col>=e.colCount-1,s=e.row>=t.length-1,o=t[e.row]??[];return n?s&&XQ(o)?{kind:"exit"}:s?{kind:"append"}:{kind:"advance",row:e.row+1,col:0}:{kind:"advance",row:e.row,col:e.col+1}}function nE(e){return Array.isArray(e)?e:[]}function el(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function tZ(e,t){if(el(e)){const n=t!==null?Lh(e,t):"";return n==null?"":String(n)}return e==null?"":String(e)}function nZ(e,t){if(t.length!==1||e.kind!=="object")return null;const n=e.fields.find(s=>s.name==="columns");return n!==void 0&&n.node.kind==="array"?{node:n.node.element}:null}function sE({value:e,node:t,arm:n,gridPos:s,onCommit:o}){const r=tZ(e,n),[i,l]=oe.useState(r),[d,u]=oe.useState(!1);oe.useEffect(()=>l(r),[r]);const p=()=>{if(i===r)return;const h=nC(i,el(e)?void 0:e,t);if(!h.ok){u(!0);return}el(e)&&n!==null?o({...Lf(e,n),...Lf(h.value,n)}):o(h.value)};return w.jsx("input",{className:`stu-input stu-grid-input ${d?"stu-input-invalid":""}`,type:"text",value:i,spellCheck:!1,"data-grid-cell":s,onChange:h=>{l(h.target.value),u(!1)},onBlur:p,onKeyDown:h=>{h.key==="Enter"&&p()}})}const oE=224,rE=260;function iE({title:e,value:t,arm:n,node:s,ctx:o,path:r,anchor:i,onClose:l}){const d=oe.useRef(null),u=Lf(t,n),p=Math.max(8,Math.min(i.left-oE+24,window.innerWidth-oE-8)),m=i.bottom+rE>window.innerHeight-8&&i.top-rE>8?{left:p,bottom:window.innerHeight-i.top+4,top:"auto"}:{left:p,top:i.bottom+4};return oe.useEffect(()=>{const g=y=>{const b=d.current;b!==null&&y.target instanceof Node&&!b.contains(y.target)&&setTimeout(l,0)},v=y=>{if(y.key==="Escape"){const b=y.target instanceof HTMLElement?y.target:null;if(b!==null&&b.closest('[data-combo-open="true"]')!==null)return;y.stopPropagation(),y.preventDefault(),l()}};return document.addEventListener("pointerdown",g,!0),window.addEventListener("keydown",v,!0),()=>{document.removeEventListener("pointerdown",g,!0),window.removeEventListener("keydown",v,!0)}},[l]),w.jsxs("div",{ref:d,className:"stu-grid-pop",style:m,role:"dialog","aria-label":`${e} details`,onClick:g=>g.stopPropagation(),children:[w.jsx("div",{className:"stu-grid-pop-title",children:e}),n.fields.map(g=>w.jsxs("div",{className:"stu-dx-field",children:[w.jsx("label",{className:"stu-dx-label",children:$o(g.name)}),w.jsx(Ja,{resolved:Za({blockKind:o.blockKind,name:g.name,node:g.node,value:u[g.name],data:o.rootData,path:[...r,g.name]}),node:g.node,value:u[g.name],optional:g.node.optional,autoFocus:g.name===n.fields[0]?.name,handlers:{onCommit:v=>o.commitPath(r,{...u,[g.name]:v}),onDelete:()=>{const v={...u};delete v[g.name],o.commitPath(r,v)}}})]},g.name)),s!==null&&w.jsx("button",{type:"button",className:"stu-linkbtn stu-grid-pop-simplify",tabIndex:-1,onClick:()=>{o.commitPath(r,Lh(t,n)),l()},children:"Back to plain text"})]})}function sZ({path:e,value:t,element:n,ctx:s}){const o=nE(t).map(U=>nE(U)),r=n.element,i=r.kind==="union"?r:null,l=i!==null?L0(i):null,d=nZ(s.rootNode,e),u=d?.node??null,p=u!==null&&u.kind==="union"?u:null,h=p!==null?L0(p):null,m=d!==null&&el(s.rootData)?s.rootData.columns:void 0,g=d!==null&&Array.isArray(m)?m:null,v=Math.max(1,Dh(g??void 0,o)),y=oe.useRef(null),[b,E]=oe.useState(null),$=(U,X,B,te)=>{if(b!==null&&b.kind===U&&b.r===X&&b.c===B){E(null);return}const ee=te.currentTarget.getBoundingClientRect();E({kind:U,r:X,c:B,anchor:{left:ee.left,top:ee.top,bottom:ee.bottom}})},[A,T]=oe.useState(null),N=oe.useRef(0),j=U=>T({pos:U,n:++N.current});oe.useEffect(()=>{if(A===null)return;const U=setTimeout(()=>{const X=y.current?.querySelector(`[data-grid-cell="${CSS.escape(A.pos)}"]`);X!=null&&(X.focus(),X instanceof HTMLInputElement&&X.select())},60);return()=>clearTimeout(U)},[A]);const P=U=>{d!==null&&U.columns!==null&&s.commitPath(["columns"],U.columns),s.commitPath(e,U.rows)},I=()=>{P(ZQ(g??void 0,o,v)),j(d!==null?`h-${v}`:`0-${v}`)},O=U=>{E(null),P(JQ(g??void 0,o,U))},C=()=>{s.commitPath(e,tE(g??void 0,o)),j(`${o.length}-0`)},D=U=>{E(null),s.commitPath(e,QQ(o,U))},F=U=>{if(U.key!=="Enter")return;const B=U.target.getAttribute("data-grid-cell");if(B===null||B.startsWith("h-"))return;const[te,ee]=B.split("-"),H=Number(te),W=Number(ee);!Number.isInteger(H)||!Number.isInteger(W)||(U.preventDefault(),window.setTimeout(()=>{const K=eZ({rows:o,row:H,col:W,colCount:v});K.kind==="advance"?j(`${K.row}-${K.col}`):K.kind==="append"?(s.commitPath(e,tE(g??void 0,o)),j(`${o.length}-0`)):(s.deletePath([...e,H]),s.exitArray(e))},0))};return w.jsxs("div",{className:"stu-grid",ref:y,onKeyDown:F,children:[w.jsx("div",{className:"stu-grid-scroll",children:w.jsxs("table",{className:"stu-grid-table",children:[g!==null&&w.jsx("thead",{children:w.jsxs("tr",{children:[Array.from({length:v},(U,X)=>{const B=g[X],te=el(B)&&B.highlight===!0;return w.jsx("th",{className:te?"stu-grid-th-hl":"",children:w.jsxs("div",{className:"stu-grid-cellwrap","data-field-path":`columns.${X}`,children:[w.jsx(sE,{value:B,node:u,arm:h,gridPos:`h-${X}`,onCommit:ee=>s.commitPath(["columns",X],ee)}),w.jsxs("span",{className:"stu-grid-celltools",children:[h!==null&&w.jsx("button",{type:"button",className:"stu-grid-cellbtn",title:"Column details (align, highlight…)","aria-label":`Column ${X+1} details`,tabIndex:-1,onClick:ee=>$("col",-1,X,ee),children:"⋯"}),w.jsx("button",{type:"button",className:"stu-grid-cellbtn stu-grid-cellbtn-danger",title:"Remove column","aria-label":`Remove column ${X+1}`,tabIndex:-1,onClick:()=>O(X),children:"×"})]})]})},X)}),w.jsx("th",{className:"stu-grid-addcol-th",children:w.jsx("button",{type:"button",className:"stu-grid-addcol",title:"Add column","aria-label":"Add column",onClick:I,children:"+"})})]})}),w.jsx("tbody",{children:o.map((U,X)=>w.jsxs("tr",{children:[Array.from({length:v},(B,te)=>{const ee=U[te],H=el(ee)&&typeof ee.tone=="string";return w.jsx("td",{children:w.jsxs("div",{className:"stu-grid-cellwrap","data-field-path":`${e.join(".")}.${X}.${te}`,children:[w.jsx(sE,{value:ee,node:r,arm:l,gridPos:`${X}-${te}`,onCommit:W=>s.commitPath([...e,X,te],W)}),H&&w.jsx("span",{className:`stu-grid-tonedot stu-grid-tone-${String(ee.tone)}`,"aria-hidden":"true"}),l!==null&&w.jsx("span",{className:"stu-grid-celltools",children:w.jsx("button",{type:"button",className:"stu-grid-cellbtn",title:"Cell details (tone, highlight…)","aria-label":`Cell ${X+1}·${te+1} details`,tabIndex:-1,onClick:W=>$("cell",X,te,W),children:"⋯"})})]})},te)}),w.jsx("td",{className:"stu-grid-rowtools-td",children:w.jsx("button",{type:"button",className:"stu-grid-cellbtn stu-grid-cellbtn-danger stu-grid-rowdel",title:"Remove row","aria-label":`Remove row ${X+1}`,tabIndex:-1,onClick:()=>D(X),children:"×"})})]},X))})]})}),w.jsxs("div",{className:"stu-grid-foot",children:[w.jsx("button",{type:"button",className:"stu-addbtn stu-grid-addrow",onClick:C,children:"+ Add row"}),g===null&&w.jsx("button",{type:"button",className:"stu-addbtn stu-grid-addrow",onClick:I,children:"+ Add column"}),g===null&&d!==null&&o.length>0&&w.jsx("button",{type:"button",className:"stu-addbtn stu-grid-addrow",onClick:()=>{s.commitPath(["columns"],Array.from({length:v},()=>"")),j("h-0")},children:"+ Add header row"})]}),b!==null&&b.kind==="col"&&h!==null&&w.jsx(iE,{title:`Column ${b.c+1}`,value:(g??[])[b.c],arm:h,node:p,ctx:s,path:["columns",b.c],anchor:b.anchor,onClose:()=>E(null)}),b!==null&&b.kind==="cell"&&l!==null&&w.jsx(iE,{title:`Row ${b.r+1} · Cell ${b.c+1}`,value:o[b.r]?.[b.c],arm:l,node:i,ctx:s,path:[...e,b.r,b.c],anchor:b.anchor,onClose:()=>E(null)})]})}function ud(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:{}}function ul(e){return Array.isArray(e)?e:[]}function oZ({path:e,value:t,element:n,ctx:s}){const o=ul(t),[r,i]=oe.useState(""),l=()=>{const u=r.trim();if(u==="")return;const p=Number.isFinite(Number(u))&&(n.kind==="number"||n.kind==="union"&&n.arms.some(h=>h.kind==="number"));s.commitPath(e,[...o,p?Number(u):u]),i("")},d=u=>{if(u!==null&&typeof u=="object"&&n.kind==="union"){const p=L0(n);if(p!==null)return String(Lh(u,p))}return String(u)};return w.jsxs("div",{className:"stu-chips",children:[o.map((u,p)=>w.jsxs("span",{className:"stu-chip-item",children:[d(u),w.jsx("button",{type:"button","aria-label":`Remove ${d(u)}`,onClick:()=>s.commitPath(e,o.filter((h,m)=>m!==p)),children:"×"})]},p)),n.kind==="enum"?w.jsxs("select",{className:"stu-input stu-input-select stu-chips-add",value:"",onChange:u=>{u.target.value!==""&&s.commitPath(e,[...o,u.target.value])},children:[w.jsx("option",{value:"",children:"+ add…"}),n.options.map(u=>w.jsx("option",{value:u,children:u},u))]}):w.jsx("input",{className:"stu-input stu-chips-add",type:"text",placeholder:"+ add…",value:r,onChange:u=>i(u.target.value),onBlur:l,onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),l())}})]})}const rZ=["name","label","title","text","summary","term","question","value"];function iZ(e,t,n){if(t.kind==="object"){const s=ud(e);for(const o of rZ){const r=s[o];if(typeof r=="string"&&r!=="")return r}for(const o of t.fields){const r=s[o.name];if(typeof r=="string"&&r!=="")return r}}return typeof e=="string"&&e!==""?e:`Item ${n+1}`}function aZ({name:e,path:t,value:n,element:s,ctx:o}){const r=ul(n),[i,l]=oe.useState(()=>o.fresh&&ul(n).length>0?0:null),d=oe.useRef(r);d.current=r;const u=o.reveal,p=t.join(".");oe.useEffect(()=>{if(u==null||u.path!==p&&!u.path.startsWith(`${p}.`))return;const v=u.path.slice(p.length+1),y=Number(v.split(".")[0]);Number.isInteger(y)&&y>=0&&l(y)},[u,p]);const h=o.focusReq;oe.useEffect(()=>{if(h===null)return;if(h.path===p){d.current.length>0&&l(0);return}if(!h.path.startsWith(`${p}.`))return;const v=Number(h.path.slice(p.length+1).split(".")[0]);Number.isInteger(v)&&v>=0&&l(v)},[h,p]);const m=v=>o.commitPath(t,v),g=(v,y)=>{if(v.key!=="Enter")return;const b=v.target,E=v.metaKey||v.ctrlKey;if(b.tagName==="TEXTAREA"&&!E)return;const $=v.currentTarget;window.setTimeout(()=>{const A=Bf($),T=A.indexOf(document.activeElement),N=d.current[y],j=Qa(s,d.current.slice(0,y),as(e)),P=oY({isLastField:T<0||T===A.length-1,pristine:uC(N,j)});if(P==="advance"){const I=A[T+1];I!==void 0&&zf(I);return}if(P==="append"){const I=d.current;if(y<I.length-1){l(y+1),o.requestFocus(`${p}.${y+1}`);return}o.commitPath([...t,I.length],Qa(s,I,as(e))),l(I.length),o.requestFocus(`${p}.${I.length}`);return}o.deletePath([...t,y]),l(null),o.exitArray(t)},0)};return w.jsxs("div",{className:"stu-items",children:[r.map((v,y)=>w.jsxs("div",{className:`stu-item ${i===y?"stu-item-open":""}`,"data-field-path":`${p}.${y}`,children:[w.jsxs("div",{className:"stu-item-row",children:[w.jsxs("button",{type:"button",className:"stu-item-summary",tabIndex:-1,onClick:()=>l(i===y?null:y),children:[w.jsx("span",{className:`stu-item-caret ${i===y?"stu-item-caret-open":""}`,"aria-hidden":"true",children:"▸"}),w.jsx("span",{className:"stu-item-title",children:iZ(v,s,y)})]}),w.jsxs("div",{className:"stu-item-tools",children:[w.jsx("button",{type:"button","aria-label":"Move up",tabIndex:-1,disabled:y===0,onClick:()=>{const b=r.slice(),[E]=b.splice(y,1);b.splice(y-1,0,E),m(b)},children:"↑"}),w.jsx("button",{type:"button","aria-label":"Move down",tabIndex:-1,disabled:y===r.length-1,onClick:()=>{const b=r.slice(),[E]=b.splice(y,1);b.splice(y+1,0,E),m(b)},children:"↓"}),w.jsx("button",{type:"button","aria-label":"Remove",className:"stu-item-remove",tabIndex:-1,onClick:()=>o.deletePath([...t,y]),children:"×"})]})]}),i===y&&w.jsx("div",{className:"stu-item-fields",onKeyDown:b=>g(b,y),children:w.jsx(tN,{node:s,path:[...t,y],value:v,ctx:o})})]},y)),w.jsxs("button",{type:"button",className:"stu-addbtn",onClick:()=>{m([...r,Qa(s,r,as(e))]),l(r.length),o.requestFocus(`${p}.${r.length}`)},children:["+ Add ",as(e)]})]})}function JC({name:e,node:t,path:n,value:s,ctx:o}){const r=_h(t,s),i=r!==null&&s!==null&&typeof s=="object"&&!Array.isArray(s),l=i?null:w.jsx(Ja,{resolved:Za({blockKind:o.blockKind,name:e,node:t,value:s,data:o.rootData,path:n}),node:t,value:s,optional:t.optional,handlers:{onCommit:d=>o.commitPath(n,d),onDelete:()=>o.deletePath(n),onStage:d=>o.stagePath(n,d)}});return r===null?l??w.jsx(q0,{ctx:o}):w.jsxs("div",{className:"stu-union",children:[w.jsxs("div",{className:"stu-union-toggle",role:"group","aria-label":`${$o(e)} shape`,children:[w.jsx("button",{type:"button",className:`stu-union-seg ${i?"":"stu-union-seg-active"}`,"aria-pressed":!i,tabIndex:-1,onClick:()=>{i&&o.commitPath(n,Lh(s,r))},children:"Simple"}),w.jsx("button",{type:"button",className:`stu-union-seg ${i?"stu-union-seg-active":""}`,"aria-pressed":i,tabIndex:-1,onClick:()=>{i||o.commitPath(n,Lf(s,r))},children:"Detailed"})]}),i?w.jsx("div",{className:"stu-union-fields",children:w.jsx(eN,{node:r,path:n,value:s,ctx:o})}):l]})}function lZ({name:e,path:t,value:n,element:s,ctx:o}){const r=ul(n);return w.jsxs("div",{className:"stu-items stu-union-items",children:[r.map((i,l)=>w.jsxs("div",{className:"stu-union-item","data-field-path":`${t.join(".")}.${l}`,children:[w.jsx(JC,{name:as(e),node:s,path:[...t,l],value:i,ctx:o}),w.jsx("button",{type:"button","aria-label":`Remove ${as(e)} ${l+1}`,className:"stu-union-item-remove",tabIndex:-1,onClick:()=>o.deletePath([...t,l]),children:"×"})]},l)),w.jsxs("button",{type:"button",className:"stu-addbtn",onClick:()=>o.commitPath([...t,r.length],""),children:["+ Add ",as(e)]})]})}function eN({node:e,path:t,value:n,ctx:s,fieldDiags:o}){const r=ud(n);return w.jsx(w.Fragment,{children:e.fields.map(i=>w.jsx(nN,{name:i.name,node:i.node,path:[...t,i.name],value:r[i.name],ctx:s,diags:o?.get(i.name)},i.name))})}function aE({label:e,count:t,defaultOpen:n,openSignal:s,children:o}){const[r,i]=oe.useState(n);return oe.useEffect(()=>{s>0&&i(!0)},[s]),w.jsxs("div",{className:`stu-collapse ${r?"stu-collapse-open":""}`,children:[w.jsxs("button",{type:"button",className:"stu-collapse-head","aria-expanded":r,onClick:()=>i(!r),children:[w.jsx("span",{className:`stu-item-caret ${r?"stu-item-caret-open":""}`,"aria-hidden":"true",children:"▸"}),e,w.jsx("span",{className:"stu-collapse-count",children:t})]}),r&&w.jsx("div",{className:"stu-collapse-body",children:o})]})}function tN({node:e,path:t,value:n,ctx:s,fieldDiags:o}){const r=ud(n),{primary:i,more:l,advanced:d}=oe.useMemo(()=>cl(e.fields,n),[e,n]),u=s.reveal,p=t.join(".");let h=null;u!=null&&(p===""?h=u.path.split(".")[0]??null:u.path.startsWith(`${p}.`)&&(h=u.path.slice(p.length+1).split(".")[0]??null));const m=b=>h!==null&&b.some(E=>E.name===h)?u?.n??0:0,g=b=>b.some(E=>(o?.get(E.name)?.length??0)>0),v=t.length===0&&e.fields.some(b=>b.node.kind==="array"&&b.node.element.kind==="array")&&e.fields.some(b=>b.name==="columns"&&b.node.kind==="array"),y=b=>v&&b.name==="columns"&&t.length===0?null:w.jsx(nN,{name:b.name,node:b.node,path:[...t,b.name],value:r[b.name],ctx:s,diags:o?.get(b.name)},b.name);return w.jsxs(w.Fragment,{children:[i.map(y),l.length>0&&w.jsx(aE,{label:"More fields",count:l.length,defaultOpen:g(l),openSignal:m(l),children:l.map(y)}),d.length>0&&w.jsx(aE,{label:"Advanced",count:d.length,defaultOpen:g(d),openSignal:m(d),children:d.map(y)})]})}function Lp({diags:e}){return e===void 0||e.length===0?null:w.jsx("div",{className:"stu-field-diags",children:e.map((t,n)=>w.jsx("div",{className:`stu-field-diag stu-field-diag-${t.level}`,children:t.message},n))})}function nN({name:e,node:t,path:n,value:s,ctx:o,diags:r}){const i=w.jsxs("label",{className:"stu-field-label",children:[$o(e),t.optional&&w.jsx("span",{className:"stu-optional",children:"optional"})]});let l;switch(t.kind){case"string":case"number":case"boolean":case"enum":{const d=Za({blockKind:o.blockKind,name:e,node:t,value:s,data:o.rootData,path:n});l=w.jsx(Ja,{resolved:d,node:t,value:s,optional:t.optional,handlers:{onCommit:u=>o.commitPath(n,u),onDelete:()=>o.deletePath(n),onStage:u=>o.stagePath(n,u)}});break}case"union":l=w.jsx(JC,{name:e,node:t,path:n,value:s,ctx:o});break;case"array":if(t.element.kind==="object")return w.jsxs("div",{className:"stu-field stu-field-block","data-field-path":n.join("."),children:[i,w.jsx(aZ,{name:e,path:n,value:s,element:t.element,ctx:o}),w.jsx(Lp,{diags:r})]});if(t.element.kind==="array")return w.jsxs("div",{className:"stu-field stu-field-block","data-field-path":n.join("."),children:[i,w.jsx(sZ,{path:n,value:s,element:t.element,ctx:o}),w.jsx(Lp,{diags:r})]});t.element.kind==="opaque"?l=w.jsx(q0,{ctx:o}):t.element.kind==="union"&&ZA(t.element).length>0?l=w.jsx(lZ,{name:e,path:n,value:s,element:t.element,ctx:o}):l=w.jsx(oZ,{path:n,value:s,element:t.element,ctx:o});break;case"object":return w.jsxs("fieldset",{className:"stu-fieldset","data-field-path":n.join("."),children:[w.jsxs("legend",{children:[$o(e),t.optional&&w.jsx("span",{className:"stu-optional",children:"optional"})]}),w.jsx(eN,{node:t,path:n,value:s,ctx:o}),w.jsx(Lp,{diags:r})]});case"opaque":l=w.jsx(q0,{ctx:o});break}return w.jsxs("div",{className:"stu-field","data-field-path":n.join("."),children:[i,l,w.jsx(Lp,{diags:r})]})}function q0({ctx:e}){return w.jsxs("div",{className:"stu-opaque",children:["This field holds free-form content —"," ",w.jsx("button",{type:"button",className:"stu-linkbtn",onClick:e.openYaml,children:"open the YAML tab"})," ","to edit it."]})}function cZ({seg:e,fresh:t=!1,commitPath:n,deletePath:s,stagePath:o,openYaml:r,fieldDiags:i,reveal:l}){const d=yy(e.kind),u=oe.useRef(null),p=oe.useRef(e.data);p.current=e.data;const[h,m]=oe.useState(null),g=oe.useRef(0),v=b=>m({path:b,n:++g.current}),y={blockKind:e.kind,rootData:e.data,rootNode:d,fresh:t,commitPath:n,deletePath:s,stagePath:o,openYaml:r,reveal:l,focusReq:h,requestFocus:v,exitArray:b=>{if(b.length!==1||typeof b[0]!="string"||d.kind!=="object")return;const E=sY(d,p.current,b[0]);if(E!==null)if(E.node.kind==="array"&&E.node.element.kind==="object"){const $=ul(ud(p.current)[E.name]);v($.length>0?`${E.name}.0`:E.name)}else v(E.name)}};return oe.useEffect(()=>{if(d.kind!=="object")return;const b=cl(d.fields,p.current).primary[0];if(t&&b!==void 0&&b.node.kind==="array"&&b.node.element.kind==="object"&&ul(ud(p.current)[b.name]).length===0){n([b.name,0],Qa(b.node.element,[],as(b.name))),v(`${b.name}.0`);return}const E=nY(d,p.current);E[0]!==void 0&&v(E[0])},[]),oe.useEffect(()=>{if(h===null)return;const b=setTimeout(()=>{const E=u.current;if(E===null)return;const $=E.querySelector(`[data-field-path="${CSS.escape(h.path)}"]`);if($===null)return;const A=Bf($)[0]??$.querySelector(".stu-addbtn");A!=null&&zf(A)},60);return()=>clearTimeout(b)},[h]),d.kind!=="object"?w.jsxs("div",{className:"stu-opaque stu-opaque-block",children:["This block's schema has no structural form description —"," ",w.jsx("button",{type:"button",className:"stu-linkbtn",onClick:r,children:"edit it as YAML"}),"."]}):w.jsx("div",{className:"stu-form",ref:u,children:w.jsx(tN,{node:d,path:[],value:e.data,ctx:y,fieldDiags:i})})}const dZ=250;function lE({diags:e}){return e.length===0?null:w.jsx("div",{className:"stu-sheet-diags",children:e.map((t,n)=>w.jsxs("div",{className:`stu-diag stu-diag-${t.level}`,children:[w.jsx("span",{className:"stu-diag-code",children:t.code}),w.jsx("div",{className:"stu-diag-msg",children:t.message}),t.hint!==void 0&&w.jsx("div",{className:"stu-diag-hint",children:t.hint})]},n))})}function uZ({seg:e,revealField:t}){const n=Ah(),s=ke(Z=>Z.closeSheet),o=ke(Z=>Z.commitSheet),r=ke(Z=>Z.setSheetDirty),i=ke(Z=>Z.sheetFresh),l=Ko(e.sourceType)?ch(e):e.raw,[d,u]=oe.useState(l),[p,h]=oe.useState(l),m=oe.useRef(d);m.current=d;const g=oe.useRef(null),v=d!==l;oe.useEffect(()=>{r(v)},[v,r]),oe.useEffect(()=>()=>{g.current!==null&&clearTimeout(g.current)},[]);const y=Z=>{g.current!==null&&clearTimeout(g.current),m.current=Z,u(Z),h(Z)},b=Z=>{g.current!==null&&clearTimeout(g.current),g.current=setTimeout(()=>{g.current=null;try{h(Z())}catch{}},dZ)},E=oe.useMemo(()=>z0(e.kind,d),[e.kind,d]),$=oe.useMemo(()=>p===d?E:z0(e.kind,p),[e.kind,p,d,E]),A=E.seg?.parseError,[T,N]=oe.useState(A!==void 0?"yaml":"form"),[j,P]=oe.useState(!1);oe.useEffect(()=>{A!==void 0&&N("yaml")},[A]);const{byField:I,rest:O}=oe.useMemo(()=>YC(d,E.diagnostics),[d,E.diagnostics]),C=()=>{Ni("sheet-done");const Z=document.activeElement;Z instanceof HTMLElement&&Z.blur();const q=m.current;q===l?s(!0):o(q)},D=()=>s();oe.useEffect(()=>{const Z=q=>{if(ke.getState().review!==null)return;const de=q.target instanceof HTMLElement?q.target:null;if(q.key==="Escape"){if(de!==null&&de.closest('[data-combo-open="true"]')!==null||document.querySelector(".stu-grid-pop, .stu-sheet .stu-dx-pop")!==null)return;q.stopPropagation(),D();return}if((q.metaKey||q.ctrlKey)&&q.key==="Enter"){if(de?.tagName==="TEXTAREA"&&de.closest(".stu-item-fields")!==null)return;q.preventDefault(),C()}};return window.addEventListener("keydown",Z,!0),()=>window.removeEventListener("keydown",Z,!0)},[d,v]);const F=(Z,q)=>{y(Ai(m.current,Z,q,e.kind)),(typeof q!="object"||q===null)&&Ni("field-commit")},U=Z=>{y(h0(m.current,Z))},X=(Z,q)=>{b(()=>Ai(m.current,Z,q,e.kind))},B=oe.useRef(null),te=oe.useRef(null),[ee,H]=oe.useState(null),[W,K]=oe.useState(t!==null?{path:t,n:1}:null),R=oe.useRef(t!==null?1:0);oe.useEffect(()=>{ke.getState().sheetReveal!==null&&ke.setState({sheetReveal:null})},[]);const z=oe.useMemo(()=>({kind:e.kind,commitPath:(Z,q)=>y(Ai(m.current,Z,q,e.kind)),commitPaths:Z=>{let q=m.current;for(const de of Z)q=Ai(q,de.path,de.value,e.kind);y(q)},deletePath:Z=>y(h0(m.current,Z)),openFull:()=>N("yaml"),notify:Z=>ke.getState().toast(Z)}),[e.kind]),Y=Z=>{const q=B.current;if(q===null)return null;let de=null,le=-1;for(const J of Array.from(q.querySelectorAll("[data-field-path]"))){const ue=J.getAttribute("data-field-path")??"";(Z===ue||Z.startsWith(`${ue}.`))&&ue.length>le&&(de=J,le=ue.length)}return de},V=Z=>T!=="form"||Y(Z)===null?!1:(K({path:Z,n:++R.current}),!0);oe.useEffect(()=>{if(W===null)return;const Z=setTimeout(()=>{const q=Y(W.path);q!==null&&(q.scrollIntoView({block:"center",behavior:"smooth"}),q.classList.add("stu-field-flash"),q.querySelector("input, textarea, select")?.focus({preventScroll:!0}),setTimeout(()=>q.classList.remove("stu-field-flash"),1400))},60);return()=>clearTimeout(Z)},[W]);const re=Z=>{const q=Z.target.closest("[data-field-path]");H(q!==null?q.getAttribute("data-field-path"):null)},Q=Z=>{const q=Z.target.closest("[data-field-path]");q!==null&&H(q.getAttribute("data-field-path"))},ne=td.find(Z=>Z.id===Rp[e.kind]);return w.jsx("div",{className:"stu-sheet-backdrop",onMouseDown:Z=>{Z.target===Z.currentTarget&&!v&&D()},children:w.jsxs("div",{className:"stu-sheet",role:"dialog","aria-modal":"true","aria-label":`Edit ${il[e.kind]}`,children:[w.jsxs("header",{className:"stu-sheet-head",children:[w.jsxs("div",{className:"stu-sheet-title",children:[w.jsx("h2",{children:il[e.kind]}),w.jsx("span",{className:"stu-kind-chip",children:e.kind}),w.jsx("span",{className:"stu-family-label",children:ne?.label??""})]}),w.jsxs("div",{className:"stu-tabs stu-sheet-tabs",role:"tablist",children:[w.jsx("button",{type:"button",role:"tab","aria-selected":T==="form",className:`stu-tab ${T==="form"?"stu-tab-active":""}`,onClick:()=>N("form"),disabled:A!==void 0,children:"Form"}),w.jsx("button",{type:"button",role:"tab","aria-selected":T==="yaml",className:`stu-tab ${T==="yaml"?"stu-tab-active":""}`,onClick:()=>N("yaml"),children:"YAML"})]}),w.jsxs("div",{className:"stu-sheet-actions",children:[w.jsx("button",{type:"button",className:"stu-btn stu-sheet-prevbtn","aria-pressed":j,title:j?"Hide the in-panel preview":"Show a preview of this block in the panel",onClick:()=>P(!j),children:"Preview"}),w.jsx("button",{type:"button",className:"stu-btn",onClick:D,children:"Cancel"}),w.jsx("button",{type:"button",className:"stu-btn stu-btn-primary",onClick:C,children:"Done"})]})]}),w.jsxs("div",{className:"stu-sheet-body",children:[w.jsx("div",{className:"stu-sheet-form",ref:B,onMouseOver:re,onMouseLeave:()=>H(null),onFocusCapture:Q,children:T==="form"&&E.seg!==void 0?w.jsxs(w.Fragment,{children:[w.jsx(cZ,{seg:E.seg,fresh:i,commitPath:F,deletePath:U,stagePath:X,openYaml:()=>N("yaml"),fieldDiags:I,reveal:W}),w.jsx(lE,{diags:O})]}):w.jsxs("div",{className:"stu-sheet-yaml",children:[A!==void 0&&w.jsxs("div",{className:"stu-diag stu-diag-error",children:[w.jsx("span",{className:"stu-diag-code",children:"YAML"}),w.jsx("div",{className:"stu-diag-msg",children:A})]}),w.jsx("textarea",{className:"stu-yaml-editor",value:d,onChange:Z=>{const q=Z.target.value;u(q),b(()=>q)},spellCheck:!1}),w.jsx(lE,{diags:A===void 0?O:[]})]})}),w.jsxs("div",{className:`stu-sheet-preview ${j?"stu-sheet-preview-open":""}`,children:[w.jsx("span",{className:"stu-sheet-preview-label",children:"Preview"}),w.jsx("div",{className:"stu-sheet-preview-scroll",children:$.html!==""?w.jsxs("div",{className:"stu-sheet-preview-wrap","data-doc-theme":Mh(n),ref:te,children:[w.jsx("div",{className:"docskin stu-sheet-preview-doc",dangerouslySetInnerHTML:{__html:$.html}}),w.jsx(UC,{host:z,data:E.seg?.data,html:$.html,wrapperRef:te,linkPath:ee,onElementClick:V})]}):w.jsx("div",{className:"stu-sheet-preview-empty",children:"Nothing to preview yet — fill in the fields."})})]})]})]})})}function pZ(){const e=ke(o=>o.sheet),t=ke(o=>o.sheetReveal),{doc:n}=Co(),s=e!==null?n.segments[e]:void 0;return e===null||s===void 0||s.kind==="markdown"?null:w.jsx(uZ,{seg:s,revealField:t},`${e}:${s.kind}:${s.raw}`)}function fZ(){const e=ke(u=>u.pendingImport),t=ke(u=>u.confirmImport),n=ke(u=>u.cancelImport),[s,o]=oe.useState(""),r=oe.useRef(null),i=oe.useRef(null),l=e!==null;if(oe.useEffect(()=>{e!==null&&(o(e.defaultSlug),requestAnimationFrame(()=>r.current?.select()))},[e]),oe.useEffect(()=>{if(!l)return;const u=p=>{p.key==="Escape"&&(p.stopPropagation(),n())};return window.addEventListener("keydown",u,!0),()=>window.removeEventListener("keydown",u,!0)},[l,n]),e===null)return null;const d=()=>{const u=s.trim().replace(/\.md$/,"");if(u===""){r.current?.focus();return}t(u)};return w.jsx("div",{className:"stu-sheet-backdrop",onMouseDown:u=>{i.current!==null&&!i.current.contains(u.target)&&n()},children:w.jsxs("div",{className:"stu-import",ref:i,role:"dialog","aria-modal":"true","aria-label":"Create a doc from an OpenAPI spec",children:[w.jsxs("div",{className:"stu-import-head",children:[w.jsx("span",{className:"stu-import-glyph",children:w.jsx(LC,{size:15})}),w.jsx("h2",{children:"Import OpenAPI spec"})]}),w.jsxs("p",{className:"stu-import-text",children:["Create ",w.jsxs("code",{children:[s.trim()===""?e.defaultSlug:s.trim(),".md"]})," from"," ",w.jsx("strong",{children:e.title}),"? The doc gets a cover, an endpoint table, one sequence diagram per endpoint, and an ERD of the schemas."]}),w.jsx("input",{ref:r,className:"stu-import-slug",type:"text","aria-label":"Doc slug",placeholder:"slug, e.g. api/orders",value:s,onChange:u=>o(u.target.value),onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),d())}}),w.jsxs("div",{className:"stu-import-foot",children:[w.jsx("span",{className:"stu-import-hint",children:"Enter creates · Esc cancels"}),w.jsx("button",{type:"button",className:"stu-btn",onClick:n,children:"Cancel"}),w.jsx("button",{type:"button",className:"stu-btn stu-btn-primary",onClick:d,children:"Create doc"})]})]})})}function hZ({change:e}){return w.jsxs("span",{className:`stu-review-glyph stu-review-glyph-${e}`,"aria-hidden":"true",children:[e==="edited"&&w.jsx(P0,{size:11}),e==="added"&&w.jsx(dd,{size:11}),e==="removed"&&w.jsx(vx,{size:11}),e==="reordered"&&"⇅"]})}function mZ(){const e=ke(v=>v.review),t=ke(v=>v.currentSlug),n=ke(v=>v.savedSource),s=ke(v=>v.source),o=ke(v=>v.docs),r=Ah(),i=ke(v=>v.applyReview),l=ke(v=>v.cancelReview),d=oe.useRef(null),{diagnostics:u}=Co(),p=e!==null&&t!==null,h=u.filter(v=>v.level==="error").length,m=oe.useMemo(()=>p?hC(n,s,t):[],[p,n,s,t]);if(oe.useEffect(()=>{p&&requestAnimationFrame(()=>d.current?.focus())},[p]),oe.useEffect(()=>{if(!p)return;const v=y=>{y.key==="Escape"?(y.preventDefault(),y.stopPropagation(),l()):(y.key==="Enter"||(y.metaKey||y.ctrlKey)&&y.key.toLowerCase()==="s")&&(y.preventDefault(),y.stopPropagation(),i())};return window.addEventListener("keydown",v,!0),()=>window.removeEventListener("keydown",v,!0)},[p,i,l]),!p)return null;const g=o.find(v=>v.slug===t)?.file??`${t}.md`;return w.jsx("div",{className:"stu-review-backdrop","data-surface":Mh(r),onMouseDown:v=>{v.target===v.currentTarget&&l()},children:w.jsxs("div",{className:"stu-review",role:"dialog","aria-modal":"true","aria-label":"Review changes",children:[w.jsxs("header",{className:"stu-review-head",children:[w.jsxs("h2",{children:["Apply changes to ",w.jsx("code",{children:g}),"?"]}),w.jsx("p",{className:"stu-review-sub",children:m.length===0?"Nothing structural changed.":w.jsxs(w.Fragment,{children:[w.jsxs("strong",{className:"stu-review-count",children:[m.length," change",m.length===1?"":"s"]})," ","since the last save"]})})]}),w.jsx("div",{className:"stu-review-list",children:m.length===0?w.jsx("div",{className:"stu-review-empty",children:"Formatting-only changes (whitespace)"}):w.jsx("ul",{children:m.map((v,y)=>w.jsxs("li",{className:"stu-review-item",children:[w.jsx(hZ,{change:v.change}),w.jsx("span",{className:"stu-review-label",children:v.label}),w.jsxs("span",{className:"stu-review-kind",children:[v.kind==="markdown"?"Text":il[v.kind]," · ",v.change]})]},y))})}),h>0&&w.jsxs("p",{className:"stu-review-errline",role:"alert",children:[h," error",h===1?"":"s"," — Apply anyway?"]}),w.jsxs("footer",{className:"stu-review-foot",children:[w.jsx("button",{type:"button",className:"stu-btn",onClick:l,children:"Cancel"}),w.jsx("button",{type:"button",ref:d,className:"stu-btn stu-btn-primary",onClick:()=>{i()},children:"Apply ▸"})]})]})})}const gZ=new Map(td.map(e=>[e.id,e.label])),Wi=Zf.filter(e=>e!=="meta").map(e=>({type:e,label:il[e],description:O6[e],family:Rp[e],familyLabel:gZ.get(Rp[e])??Rp[e]})),vZ=new Map(Wi.map(e=>[e.type,e]));function yZ(e){const t=io[e]?.patch??{};return Object.entries(t).map(([n,s])=>`${n}: ${String(s)}`).join(", ")}const xZ=Object.entries(io).flatMap(([e,t])=>{const n=vZ.get(t.type);if(n===void 0)return[];const s=yZ(e);return[{...n,alias:e,label:`${n.label} — matches ${e}${s===""?"":` (${s})`}`,description:t.description}]});function sN(e){return e.alias===void 0?ih(e.type):kZ(e.alias)}function kZ(e){const t=io[e];if(t===void 0)throw new RangeError(`unknown block alias: ${e}`);let n=ih(t.type);for(const[s,o]of Object.entries(t.patch??{})){const r=`${s}: ${String(o)}`,i=new RegExp(`^${s}:.*$`,"m");n=i.test(n)?n.replace(i,r):`${r}
3259
- ${n}`}return n}function bZ(e,t){if(e.alias!==void 0)return e.alias===t?110:e.alias.startsWith(t)?85:e.alias.includes(t)?45:0;const n=e.type,s=e.label.toLowerCase();return n===t?100:n.startsWith(t)?80:s.startsWith(t)?70:s.split(/[\s/&-]+/).some(o=>o.startsWith(t))?60:s.includes(t)?50:n.includes(t)?45:e.description.toLowerCase().includes(t)?25:e.familyLabel.toLowerCase().includes(t)?15:0}const wZ=[...Wi,...xZ];function oN(e){const t=e.trim().toLowerCase().split(/\s+/).filter(s=>s!=="");if(t.length===0)return[...Wi];const n=[];return wZ.forEach((s,o)=>{let r=0;for(const i of t){const l=bZ(s,i);if(l===0)return;r+=l}n.push({item:s,rank:r,order:o})}),n.sort((s,o)=>o.rank-s.rank||s.order-o.order),n.map(s=>s.item)}const $Z=new Map(Wi.map(e=>[e.type,e]));function SZ(e,t){return oN(e).slice(0,t)}function EZ(e){const t=new Map;for(const n of oN(e)){if(t.has(n.type))continue;const s=$Z.get(n.type);s!==void 0&&t.set(n.type,n.alias===void 0?{item:s}:{item:s,alias:n.alias})}return t}function MZ(e,t){const n=EZ(e),s=new Map;let o=0;for(const l of Wi){const d=n.get(l.type);if(d===void 0)continue;o+=1;const u=s.get(l.family);u===void 0?s.set(l.family,[d]):u.push(d)}const r=new Map(td.map(l=>[l.id,s.get(l.id)?.length??0])),i=td.filter(l=>t==="all"||l.id===t).map(l=>({family:l.id,label:l.label,hits:s.get(l.id)??[]})).filter(l=>l.hits.length>0);return{groups:i,shown:i.reduce((l,d)=>l+d.hits.length,0),total:Wi.length,familyCounts:r,matched:o}}function rN(e){return sN(e.alias===void 0?{type:e.item.type}:{type:e.item.type,alias:e.alias})}function cE(e){const t=io[e]?.patch??{};return Object.entries(t).map(([n,s])=>`${n}: ${String(s)}`).join(", ")}function AZ(e,t){return e!==null?e+1:t}function CZ(e,t,n){return e??AZ(t,n)}function NZ(e){return e==="ArrowLeft"||e==="ArrowRight"||e==="ArrowUp"||e==="ArrowDown"||e==="Home"||e==="End"}function TZ(e,t,n,s){if(s<=0)return 0;const o=Math.max(1,n),r=Math.min(Math.max(e,0),s-1);switch(t){case"ArrowLeft":return Math.max(0,r-1);case"ArrowRight":return Math.min(s-1,r+1);case"ArrowUp":return Math.max(0,r-o);case"ArrowDown":return Math.min(s-1,r+o);case"Home":return 0;case"End":return s-1}}const _Z=760,LZ=.235;function IZ({type:e}){const[t,n]=oe.useState(null),s=oe.useRef(null);return oe.useEffect(()=>{const o=s.current;if(o===null)return;if(typeof IntersectionObserver>"u"){n(ZS(e));return}const r=new IntersectionObserver(i=>{i.some(l=>l.isIntersecting)&&(n(ZS(e)),r.disconnect())},{rootMargin:"120px"});return r.observe(o),()=>r.disconnect()},[e]),w.jsx("div",{ref:s,className:"stu-thumb","aria-hidden":"true",children:t!==null&&t!==""?w.jsx("div",{className:"docskin stu-thumb-doc",style:{width:_Z,transform:`scale(${LZ})`},dangerouslySetInnerHTML:{__html:t}}):w.jsx("div",{className:"stu-thumb-blank",children:e})})}const jZ=9,dE=420,uE=420,PZ=new Map(td.map(e=>[e.id,e.label]));function iN(e){const t=ke.getState(),{doc:n}=id(t.source,t.currentSlug??"untitled");return CZ(e,t.selection,n.segments.length)}function aN(e,t,n){const s=ke.getState();if(s.currentSlug===null)return;const o=iN(e);s.mode!=="edit"&&s.setMode("edit"),s.closePicker(),iC(o,t,n)}function lN({pinned:e}){const t=ke(n=>n.currentSlug);return w.jsxs("button",{type:"button",className:"stu-picker-import",disabled:t===null,title:t===null?"Open a doc first":void 0,onClick:()=>{const n=ke.getState(),s=iN(e);n.mode!=="edit"&&n.setMode("edit"),n.closePicker(),xY(s)},children:[w.jsx(LC,{size:13}),"Import from file…",w.jsx("span",{className:"stu-picker-import-hint",children:".csv → block · OpenAPI .yaml/.json → new doc"})]})}function OZ({picker:e,query:t,setQuery:n}){const s=ke(v=>v.closePicker),o=ke(v=>v.expandPicker),[r,i]=oe.useState(0),l=oe.useRef(null),d=oe.useRef(null),u=oe.useRef(null),p=oe.useMemo(()=>SZ(t,jZ),[t]);oe.useEffect(()=>{requestAnimationFrame(()=>l.current?.focus())},[]),oe.useEffect(()=>i(0),[t]),oe.useEffect(()=>{const v=d.current?.children[r];v instanceof HTMLElement&&v.scrollIntoView({block:"nearest"})},[r]),oe.useEffect(()=>{const v=y=>{u.current!==null&&!u.current.contains(y.target)&&s()};return window.addEventListener("mousedown",v),()=>window.removeEventListener("mousedown",v)},[s]);const h=v=>aN(e.index,v.type,sN(v)),m=v=>{if(v.key==="Escape"){v.preventDefault(),v.stopPropagation(),s();return}if(v.key==="ArrowDown"){v.preventDefault(),i(y=>Math.min(y+1,p.length-1));return}if(v.key==="ArrowUp"){v.preventDefault(),i(y=>Math.max(y-1,0));return}if(v.key==="Enter"){v.preventDefault();const y=p[r];y!==void 0&&h(y)}},g=oe.useMemo(()=>{const v=e.anchor;if(v===null)return;const y=window.innerWidth,b=window.innerHeight,E=Math.min(Math.max(v.x-dE/2,12),Math.max(12,y-dE-12)),$=v.y+10,A=$+uE>b-12?Math.max(12,v.y-uE-14):$;return{left:E,top:A}},[e.anchor]);return w.jsxs("div",{className:`stu-picker-compact ${e.anchor===null?"stu-picker-compact-centered":""}`,ref:u,...g!==void 0?{style:g}:{},role:"dialog","aria-label":"Insert a block",children:[w.jsxs("div",{className:"stu-picker-search",children:[w.jsx(Of,{size:14}),w.jsx("input",{ref:l,type:"text",placeholder:`Search ${Wi.length} block types…`,value:t,onChange:v=>n(v.target.value),onKeyDown:m}),w.jsx("kbd",{children:"esc"})]}),w.jsxs("ul",{className:"stu-picker-list",ref:d,role:"listbox",children:[p.map((v,y)=>w.jsx("li",{children:w.jsxs("button",{type:"button",role:"option","aria-selected":y===r,className:`stu-picker-item ${y===r?"stu-picker-item-active":""}`,onMouseEnter:()=>i(y),onClick:()=>h(v),children:[w.jsx("span",{className:"stu-picker-item-name",children:v.label}),w.jsx("span",{className:"stu-card-type",children:v.type}),w.jsx("span",{className:"stu-picker-item-fam",children:v.familyLabel})]})},v.alias??v.type)),p.length===0&&w.jsx("li",{className:"stu-picker-none",children:"No matching blocks"})]}),w.jsxs("div",{className:"stu-picker-foot",children:[w.jsx(lN,{pinned:e.index}),w.jsxs("button",{type:"button",className:"stu-picker-import",onClick:o,children:[w.jsx(yx,{size:13}),"Browse all blocks",w.jsx("span",{className:"stu-picker-import-hint",children:"gallery with previews →"})]})]})]})}function RZ(e){return Array.from(e.querySelectorAll('button, input, [tabindex="0"]')).filter(t=>t.tabIndex>=0&&!t.hasAttribute("disabled")&&t.offsetParent!==null)}function cN(e,t){if(e.key!=="Tab"||t===null)return;const n=RZ(t),s=n[0],o=n[n.length-1];if(s===void 0||o===void 0)return;const r=document.activeElement;e.shiftKey&&(r===s||!t.contains(r))?(e.preventDefault(),o.focus()):!e.shiftKey&&r===o&&(e.preventDefault(),s.focus())}function DZ(e){if(e===null)return 1;const t=Array.from(e.children),n=t[0];return n===void 0?1:Math.max(1,t.filter(s=>s.offsetTop===n.offsetTop).length)}function BZ({hit:e,index:t,roving:n,onOpen:s,onRove:o}){return w.jsxs("button",{type:"button",className:"stu-card stu-picker-card","data-libcard":t,tabIndex:n?0:-1,onFocus:()=>o(t),onClick:()=>s(e),"aria-label":`${e.item.label} (${e.item.type}) — open details`,"aria-haspopup":"dialog",children:[w.jsx(IZ,{type:e.item.type}),w.jsxs("span",{className:"stu-card-head",children:[w.jsx("span",{className:"stu-card-name",children:e.item.label}),w.jsx("span",{className:"stu-card-type",children:e.item.type})]}),w.jsx("span",{className:"stu-card-desc",children:e.item.description}),e.alias!==void 0&&w.jsxs("span",{className:"stu-picker-also",children:["also: ",e.alias]})]})}function zZ({hit:e,canInsert:t,onClose:n,onInsert:s}){const o=Ah(),r=oe.useRef(null),i=oe.useRef(null),[l,d]=oe.useState(!1),u=oe.useMemo(()=>rN(e),[e]),p=oe.useMemo(()=>GC(e.item.type,u).trimEnd(),[e,u]),h=oe.useMemo(()=>z0(e.item.type,u),[e,u]);oe.useEffect(()=>{requestAnimationFrame(()=>i.current?.focus())},[]),oe.useEffect(()=>{if(!l)return;const g=setTimeout(()=>d(!1),1600);return()=>clearTimeout(g)},[l]);const m=()=>{navigator.clipboard?.writeText(p+`
3260
- `).then(()=>d(!0),()=>{})};return w.jsx("div",{className:"stu-picker-detail-backdrop",onMouseDown:g=>{r.current!==null&&!r.current.contains(g.target)&&n()},children:w.jsxs("div",{className:"stu-picker-detail",ref:r,role:"dialog","aria-modal":"true","aria-label":`${e.item.label} block details`,onKeyDown:g=>{if(g.key==="Enter"&&(g.metaKey||g.ctrlKey)&&t){g.preventDefault(),s(e);return}cN(g,r.current)},children:[w.jsxs("header",{className:"stu-picker-detail-head",children:[w.jsxs("div",{className:"stu-picker-detail-title",children:[w.jsx("h3",{children:e.item.label}),w.jsx("span",{className:"stu-card-type",children:e.item.type}),w.jsx("span",{className:"stu-picker-detail-fam",children:e.item.familyLabel})]}),w.jsx("button",{type:"button",className:"stu-picker-x","aria-label":"Close details",onClick:n,children:w.jsx(Rf,{size:13})})]}),w.jsx("p",{className:"stu-picker-detail-desc",children:e.item.description}),e.alias!==void 0&&w.jsxs("p",{className:"stu-picker-detail-alias",children:["also answers to: ",w.jsx("code",{children:e.alias}),cE(e.alias)!==""&&w.jsxs(w.Fragment,{children:[" — inserts as ",w.jsx("code",{children:cE(e.alias)})]})]}),w.jsxs("div",{className:"stu-picker-detail-body",children:[w.jsxs("div",{className:"stu-picker-pane stu-picker-pane-preview",children:[w.jsx("div",{className:"stu-picker-pane-label",children:"Preview"}),w.jsx("div",{className:"stu-picker-preview","data-doc-theme":Mh(o),children:h.html!==""?w.jsx("div",{className:"docskin stu-picker-preview-doc",dangerouslySetInnerHTML:{__html:h.html}}):w.jsx("div",{className:"stu-picker-preview-blank",children:e.item.type})})]}),w.jsxs("div",{className:"stu-picker-pane stu-picker-pane-yaml",children:[w.jsxs("div",{className:"stu-picker-pane-label",children:["Template",w.jsxs("button",{type:"button",className:"stu-picker-copy",onClick:m,children:[w.jsx(TC,{size:12}),l?"Copied":"Copy"]})]}),w.jsx("pre",{className:"stu-picker-yaml",tabIndex:0,children:p})]})]}),w.jsxs("footer",{className:"stu-picker-detail-foot",children:[w.jsx("span",{className:"stu-picker-detail-hint",children:"⏎ insert · esc back to the gallery"}),w.jsx("button",{type:"button",className:"stu-btn",onClick:n,children:"Close"}),w.jsx("button",{ref:i,type:"button",className:"stu-btn stu-btn-primary",disabled:!t,title:t?"Insert into the doc":"Open a doc first",onClick:()=>s(e),children:"Insert into doc"})]})]})})}function FZ({picker:e,query:t,setQuery:n}){const s=ke(O=>O.closePicker),o=ke(O=>O.currentSlug),[r,i]=oe.useState("all"),[l,d]=oe.useState(null),[u,p]=oe.useState(0),h=oe.useRef(null),m=oe.useRef(null),g=oe.useRef(null),v=oe.useRef(null);v.current=l;const y=oe.useMemo(()=>MZ(t,r),[t,r]),b=oe.useMemo(()=>y.groups.flatMap(O=>O.hits),[y]),E=oe.useRef(0);E.current=u;const $=O=>{const C=h.current?.querySelector(`[data-libcard="${O}"]`);C?.focus(),C?.scrollIntoView({block:"nearest"})},A=oe.useMemo(()=>({css:Zi(ys("","picker-skin")).css}),[]);oe.useEffect(()=>(g.current=document.activeElement instanceof HTMLElement?document.activeElement:null,requestAnimationFrame(()=>m.current?.focus()),()=>g.current?.focus()),[]),oe.useEffect(()=>p(0),[t,r]),oe.useEffect(()=>{const O=C=>{C.key==="Escape"&&(C.preventDefault(),C.stopPropagation(),v.current!==null?(d(null),requestAnimationFrame(()=>$(E.current))):s())};return window.addEventListener("keydown",O,!0),()=>window.removeEventListener("keydown",O,!0)},[s]);const T=O=>d(O),N=()=>{d(null),requestAnimationFrame(()=>$(E.current))},j=O=>aN(e.index,O.item.type,rN(O)),P=O=>{const C=O.target,D=C.getAttribute("data-libcard");if(D===null||!NZ(O.key))return;O.preventDefault();const F=DZ(C.parentElement),U=TZ(Number(D),O.key,F,b.length);p(U),$(U)},I=(O,C,D)=>w.jsxs("button",{type:"button",className:`stu-picker-pill ${r===O?"stu-picker-pill-active":""} ${D===0?"stu-picker-pill-empty":""}`,"aria-pressed":r===O,onClick:()=>i(r===O?"all":O),children:[C,w.jsx("span",{className:"stu-picker-pill-count",children:D})]},O);return w.jsx("div",{className:"stu-picker-backdrop",children:w.jsxs("div",{className:"stu-picker-browse",ref:h,role:"dialog","aria-modal":"true","aria-label":"Block library",onKeyDown:O=>{l===null&&cN(O,h.current)},children:[w.jsx("style",{children:A.css}),w.jsxs("header",{className:"stu-picker-head",children:[w.jsxs("div",{className:"stu-picker-title",children:[w.jsx("span",{className:"stu-picker-title-icon",children:w.jsx(yx,{size:16})}),w.jsx("h2",{children:"Block library"}),w.jsxs("span",{className:"stu-picker-title-count",children:["· ",y.total," blocks"]}),w.jsx("button",{type:"button",className:"stu-picker-x","aria-label":"Close the block library",onClick:s,children:w.jsx(Rf,{size:14})})]}),w.jsxs("div",{className:"stu-picker-browse-search",children:[w.jsx(Of,{size:14}),w.jsx("input",{ref:m,type:"text",placeholder:"Search blocks — try “waterfall”, “diagram”, “api”…","aria-label":"Search blocks",value:t,onChange:O=>n(O.target.value),onKeyDown:O=>{(O.key==="Enter"||O.key==="ArrowDown")&&b.length>0&&(O.preventDefault(),$(0))}}),w.jsxs("span",{className:"stu-picker-showing","aria-live":"polite",children:["Showing ",y.shown," of ",y.total]})]}),w.jsxs("div",{className:"stu-picker-pills",role:"group","aria-label":"Filter by family",children:[I("all","All",y.matched),[...y.familyCounts].map(([O,C])=>I(O,PZ.get(O)??O,C))]})]}),w.jsx("div",{className:"stu-picker-body",onKeyDown:P,children:b.length===0?w.jsxs("div",{className:"stu-picker-empty",children:["Nothing matches “",t.trim(),"”",r!=="all"?" in this family":""," — try another word or clear the search."]}):(()=>{let O=0;return y.groups.map(C=>{const D=O;return O+=C.hits.length,w.jsxs("section",{className:"stu-picker-fam","aria-label":C.label,children:[w.jsxs("div",{className:"stu-picker-famhead",children:[C.label,w.jsx("span",{className:"stu-picker-count",children:C.hits.length})]}),w.jsx("div",{className:"stu-cardgrid stu-picker-grid",children:C.hits.map((F,U)=>w.jsx(BZ,{hit:F,index:D+U,roving:D+U===u,onOpen:T,onRove:p},F.item.type))})]},C.family)})})()}),w.jsx("div",{className:"stu-picker-foot",children:w.jsx(lN,{pinned:e.index})}),l!==null&&w.jsx(zZ,{hit:l,canInsert:o!==null,onClose:N,onInsert:j})]})})}function qZ({picker:e}){const[t,n]=oe.useState("");return e.view==="compact"?w.jsx(OZ,{picker:e,query:t,setQuery:n}):w.jsx(FZ,{picker:e,query:t,setQuery:n})}function HZ(){const e=ke(t=>t.picker);return e===null?null:w.jsx(qZ,{picker:e})}const yo="tutorial-playground",WZ="```meta\ntitle: Tutorial playground\nsubtitle: A scratch doc for the studio tour — yours to keep or delete.\ntag: TUTORIAL\n```\n",so=[{id:"welcome",target:'[data-tour="topbar"]',title:"Welcome to Chiltepin Studio",body:"This is a visual editor over plain Markdown files — every edit you make here rewrites a fenced YAML block in a real file on disk. The files stay the single source of truth; the studio is just a nicer pair of hands. You are in a scratch doc, so play freely.",advance:null},{id:"insert",target:'[data-tour="canvas"]',title:"Insert your first block",body:'Press / to open the insert menu, type "seq", and hit ⏎ to insert a Sequence diagram. Every one of the 107 block types inserts this way.',keys:["/","type seq","⏎"],advance:"insert"},{id:"fill",target:".stu-sheet-form",title:"Fill it in — no YAML required",body:"The sheet is a real form over the block's schema. Type a title, then ride the rhythm: ⇥ hops fields, ⏎ moves through rows and adds new ones when you run off the end. Commit any field to continue.",keys:["type a title","⇥ next field","⏎ next row"],advance:"field-commit",needsSheet:!0},{id:"done",target:".stu-sheet-actions",title:"Done — one clean edit",body:"Press ⌘⏎ (or click Done). The whole sheet session lands as ONE edit — one undo step, one autosave, one surgical rewrite of the block in your file.",keys:["⌘⏎"],advance:"sheet-done",needsSheet:!0},{id:"part",target:'[data-seg="1"]',title:"Click a diagram part",body:"Diagrams are directly editable. Click any part of the diagram — an actor, an arrow — to select just that part. (⇥ also cycles through parts.)",keys:["click a part","⇥ cycles"],advance:"part-select",needsBlock:!0},{id:"move",target:'[data-seg="1"]',title:"Move it with the arrows",body:"With a part selected, plain arrow keys move it: list items reorder, grid nodes hop cells, table cells navigate. Try ← or → on your selected part.",keys:["←","→"],advance:"part-move",needsBlock:!0},{id:"micro",target:'[data-seg="1"]',title:"Edit in place, escape out",body:"Press ⏎ to open the micro-editor for exactly that value — edit it, then Esc to close. Esc always pops out one level: editor → part → block → canvas.",keys:["⏎ edit","esc close"],advance:"micro-close",needsBlock:!0},{id:"save",target:'[data-tour="save"]',title:"Saving is automatic",body:`The status text by the Save button tracks the file: "unsaved changes" while you type, "saved" when the write lands (about a second later). Prefer to review first? Flip Autosave off in the rail's Settings and ⌘S opens a review of every change before anything touches the disk.`,keys:["⌘S"],advance:null},{id:"finish",target:'[data-tour="topbar"]',title:"That's the tour",body:"Share ▾ copies a link or exports the document as HTML, slides or PDF; Present shows it as a deck. Press ? anytime for every keyboard shortcut, and the README covers the full block catalog.",keys:["?"],advance:null}],H0={status:"idle",step:0};function pE(e){return e>=so.length-1?{status:"finished",step:so.length-1}:{status:"running",step:e+1}}function UZ(e,t){switch(t.type){case"start":return{status:"running",step:0};case"skip":return e.status==="idle"?e:H0;case"close":return H0;case"next":return e.status==="running"?pE(e.step):e;case"back":return e.status==="running"?{status:"running",step:Math.max(0,e.step-1)}:e;case"action":{if(e.status!=="running")return e;const n=so[e.step];return n!==void 0&&n.advance===t.action?pE(e.step):e}case"break":return e.status==="running"?{status:"interrupted",step:e.step}:e;case"resume":return e.status==="interrupted"?{status:"running",step:Math.max(0,Math.min(t.step,so.length-1))}:e}}function KZ(e){const t=so[e.current];if(t===void 0)return 0;const n=so.findIndex(o=>o.id==="insert"),s=so.findIndex(o=>o.id==="part");return t.needsSheet===!0&&!e.sheetOpen?e.hasBlock?s:n:t.needsBlock===!0&&!e.hasBlock?n:e.current}const VZ="chiltepin-studio-tour";function fE(e){try{window.localStorage.setItem(VZ,e)}catch{}}const GZ=`tone: success
3258
+ `).forEach((r,i)=>{const l=/^([A-Za-z_][\w-]*)\s*:/.exec(r);l!==null&&l[1]!==void 0&&n.push({name:l[1],startLine:i+1})});const s=new Map,o=[];for(const r of t){if(r.line===void 0){o.push(r);continue}const i=r.line-1;let l=null;for(const u of n)if(u.startLine<=i)l=u.name;else break;if(l===null){o.push(r);continue}const d=s.get(l);d===void 0?s.set(l,[r]):d.push(r)}return{byField:s,rest:o}}function jQ(e,t,n){const s=t.segments.map(o=>Xo(e,o));return n.map(o=>{const r=o.line??null;let i=null;if(r!==null){const u=s.findIndex(p=>r>=p.startLine&&r<=p.endLine);i=u===-1?null:u}const l=i!==null?t.segments[i]:void 0;let d=null;if(l!==void 0&&l.kind!=="markdown"&&i!==null&&r!==null){const u=s[i];if(u!==void 0){const p={...o,line:r-u.startLine+1},{byField:h}=YC(l.raw,[p]);d=[...h.keys()][0]??null}}return{level:o.level,code:o.code,message:o.message,hint:o.hint??null,line:r,segIndex:i,segKind:l?.kind??null,field:d}})}function Ax(e,t){return t.slug!==null&&e.slug===t.slug?t.errors>0?{kind:"errors",count:t.errors}:{kind:"pass"}:e.errorCount===void 0?{kind:"unknown"}:e.errorCount>0?{kind:"errors",count:e.errorCount}:{kind:"pass"}}function PQ(e){const t=e.indexOf("/");return t===-1?"":e.slice(0,t)}function XC(e,t){const n=e.lastIndexOf("/");return n===-1?t:`${t}/${e.slice(0,n)}`}function OQ(e,t){const n=new Map;for(const o of e){const r=PQ(o.slug),i=n.get(r);i===void 0?n.set(r,[o]):i.push(o)}return[...n.keys()].sort((o,r)=>o===""?-1:r===""?1:o.localeCompare(r)).map(o=>({key:o,label:o===""?t:`${t} / ${o}`,docs:[...n.get(o)??[]].sort((r,i)=>r.title.localeCompare(i.title))}))}function F0(e,t=Date.now()){const n=Math.max(0,Math.floor((t-e)/1e3));if(n<60)return"just now";const s=Math.floor(n/60);if(s<60)return`${s}m ago`;const o=Math.floor(s/60);if(o<24)return`${o}h ago`;const r=Math.floor(o/24);return r<30?`${r}d ago`:new Date(e).toLocaleDateString()}const QS=new Map;function ZS(e){const t=QS.get(e);if(t!==void 0)return t;let n="";try{const s=ys(BM[e],`thumb-${e}`),o=Zi(s),r=e==="meta"?o.cover:o.segments[0]?.html??"";n=r===""?"":o.defs+r}catch{n=""}return QS.set(e,n),n}const JS=new Map;function RQ(e,t,n){const s=JS.get(e);if(s!==void 0)return s;let o="";try{const r=ys(t,n),i=Zi(r),l=new Set(["meta","callout","prose"]);let d="";for(let u=0;u<r.segments.length;u+=1){const p=r.segments[u],h=i.segments[u]?.html??"";if(!(p===void 0||p.kind==="markdown"||h==="")&&!l.has(p.kind)){d=h;break}}d===""&&(d=i.segments.find(u=>u.html!=="")?.html??i.cover),o=d===""?"":i.defs+d}catch{o=""}return JS.set(e,o),o}const DQ=820,BQ=.3;function zQ({status:e}){return e.kind==="unknown"?null:e.kind==="errors"?w.jsxs("span",{className:"stu-doclist-status stu-doclist-status-err",children:[e.count," error",e.count===1?"":"s"]}):w.jsx("span",{className:"stu-doclist-status stu-doclist-status-ok",children:"✓ pass"})}function FQ({doc:e,folder:t,edited:n,status:s,onOpen:o}){const[r,i]=oe.useState(null),l=oe.useRef(null),d=`${e.slug}@${String(e.mtimeMs)}`;return oe.useEffect(()=>{const u=l.current;if(u===null)return;let p=!1;const h=()=>{Bp(e.slug).then(g=>{p||i(RQ(d,g.source,e.slug))}).catch(()=>{p||i("")})};if(typeof IntersectionObserver>"u")return h(),()=>{p=!0};const m=new IntersectionObserver(g=>{g.some(v=>v.isIntersecting)&&(h(),m.disconnect())},{rootMargin:"160px"});return m.observe(u),()=>{p=!0,m.disconnect()}},[e.slug,d]),w.jsxs("button",{ref:l,type:"button",className:"stu-doccard",title:e.slug,onClick:o,children:[w.jsx("div",{className:"stu-doccard-thumb","aria-hidden":"true",children:r!==null&&r!==""?w.jsx("div",{className:"docskin stu-thumb-doc",style:{width:DQ,transform:`scale(${String(BQ)})`},dangerouslySetInnerHTML:{__html:r}}):w.jsx("div",{className:"stu-doccard-blank",children:w.jsx(Df,{size:22})})}),w.jsxs("div",{className:"stu-doccard-body",children:[w.jsx("span",{className:"stu-doccard-title",children:e.title}),w.jsxs("span",{className:"stu-doccard-meta",children:[w.jsx("span",{className:"stu-doccard-folder",children:t}),w.jsx("span",{className:"stu-doccard-edited stu-num",children:n}),w.jsx(zQ,{status:s})]})]})]})}const Gv=4;function QC({onClose:e,initial:t}){const n=ke(E=>E.newDoc),[s,o]=oe.useState(t??"blank"),[r,i]=oe.useState(t!==void 0&&t!=="blank"?t:""),[l,d]=oe.useState(""),[u,p]=oe.useState(!1),h=oe.useRef(null),m=oe.useRef(null);oe.useEffect(()=>{requestAnimationFrame(()=>h.current?.focus())},[]),oe.useEffect(()=>{const E=$=>{$.key==="Escape"&&($.stopPropagation(),e())};return window.addEventListener("keydown",E,!0),()=>window.removeEventListener("keydown",E,!0)},[e]);const g=l.trim().toLowerCase(),v=oe.useMemo(()=>g===""?kw:kw.filter(E=>E.id.includes(g)||E.title.toLowerCase().includes(g)||E.description.toLowerCase().includes(g)||E.blockTypes.some($=>$.includes(g))),[g]),y=E=>{o(E),u||i(E==="blank"?"":E)},b=()=>{const E=r.trim().replace(/\.md$/,"");if(E===""){h.current?.focus();return}const $=s==="blank"?void 0:Ny[s];n(E,$),e()};return w.jsx("div",{className:"stu-sheet-backdrop",onMouseDown:E=>{m.current!==null&&!m.current.contains(E.target)&&e()},children:w.jsxs("div",{className:"stu-tpl",ref:m,role:"dialog","aria-modal":"true","aria-label":"Create a new doc",children:[w.jsxs("div",{className:"stu-tpl-head",children:[w.jsx("h2",{children:"New doc"}),w.jsx("input",{ref:h,className:"stu-tpl-slug",type:"text",placeholder:"slug, e.g. guides/onboarding","aria-label":"Doc slug",value:r,onChange:E=>{i(E.target.value),p(E.target.value.trim()!=="")},onKeyDown:E=>{E.key==="Enter"&&(E.preventDefault(),b())}})]}),w.jsx("label",{className:"stu-tpl-filter",children:w.jsx("input",{type:"text",placeholder:"Filter — adr, migration, sequence…","aria-label":"Filter templates",value:l,onChange:E=>d(E.target.value)})}),w.jsxs("div",{className:"stu-tpl-body",role:"radiogroup","aria-label":"Starting point",children:[g===""&&w.jsxs("button",{type:"button",role:"radio","aria-checked":s==="blank",className:`stu-tpl-card ${s==="blank"?"stu-tpl-card-active":""}`,onClick:()=>y("blank"),onDoubleClick:b,children:[w.jsxs("span",{className:"stu-tpl-card-title",children:[w.jsx(Df,{size:13}),"Blank"]}),w.jsx("span",{className:"stu-tpl-card-desc",children:"Just the cover — start from nothing and insert blocks with “/”."})]}),v.map(E=>w.jsxs("button",{type:"button",role:"radio","aria-checked":s===E.id,className:`stu-tpl-card ${s===E.id?"stu-tpl-card-active":""}`,onClick:()=>y(E.id),onDoubleClick:b,children:[w.jsxs("span",{className:"stu-tpl-card-title",children:[w.jsx(Df,{size:13}),E.title]}),w.jsx("span",{className:"stu-tpl-card-desc",children:E.description}),w.jsxs("span",{className:"stu-tpl-card-chips","aria-hidden":"true",children:[E.blockTypes.slice(0,Gv).map($=>w.jsx("code",{children:$},$)),E.blockTypes.length>Gv&&w.jsxs("code",{children:["+",E.blockTypes.length-Gv]})]})]},E.id)),v.length===0&&w.jsxs("p",{className:"stu-tpl-none",children:["Nothing matches “",l,"”."]})]}),w.jsxs("div",{className:"stu-tpl-foot",children:[w.jsx("span",{className:"stu-tpl-hint",children:"Enter creates · Esc closes"}),w.jsx("button",{type:"button",className:"stu-btn",onClick:e,children:"Cancel"}),w.jsx("button",{type:"button",className:"stu-btn stu-btn-primary",onClick:b,children:"Create"})]})]})})}const qQ=[{id:"system-design",label:"system design"},{id:"adr",label:"ADR"},{id:"api-spec",label:"API spec"},{id:"postmortem",label:"postmortem"},{id:"blank",label:"blank"}];function HQ({docsDir:e}){const[t,n]=oe.useState(null);return w.jsxs("div",{className:"stu-doclist-empty",children:[w.jsxs("div",{className:"stu-doclist-empty-inner",children:[w.jsx("div",{className:"stu-doclist-empty-icon",children:w.jsx(Df,{size:26})}),w.jsx("div",{className:"stu-doclist-empty-title",children:"No documents yet"}),w.jsxs("p",{className:"stu-doclist-empty-sub",children:["Every doc is a Markdown file in ",w.jsxs("code",{children:[e,"/"]}),". Start from a template — delete what you don’t need."]}),w.jsx("button",{type:"button",className:"stu-btn stu-btn-primary",onClick:()=>n("blank"),children:"Create your first doc"}),w.jsx("div",{className:"stu-doclist-empty-chips",children:qQ.map(s=>w.jsx("button",{type:"button",className:"stu-doclist-empty-chip",onClick:()=>n(s.id),children:s.label},s.id))})]}),t!==null&&w.jsx(QC,{initial:t,onClose:()=>n(null)})]})}function WQ(){const e=ke(h=>h.docs),t=ke(h=>h.meta),n=ke(h=>h.currentSlug),s=ke(h=>h.openDoc),o=ke(h=>h.setMode),{diagnostics:r}=Co(),i=t?.docsDir??"docs",l=r.filter(h=>h.level==="error").length,d=oe.useMemo(()=>[...e].sort((h,m)=>m.mtimeMs-h.mtimeMs),[e]),u=oe.useMemo(()=>Zi(ys("","home-skin")).css,[]);if(e.length===0)return w.jsx(HQ,{docsDir:i});const p=h=>{s(h),o("edit")};return w.jsxs("div",{className:"stu-doclist",children:[w.jsx("style",{children:u}),w.jsx("div",{className:"stu-doclist-inner stu-doclist-inner-wide",children:w.jsx("div",{className:"stu-doclist-grid",children:d.map(h=>w.jsx(FQ,{doc:h,folder:XC(h.slug,i),edited:F0(h.mtimeMs),status:Ax(h,{slug:n,errors:l}),onOpen:()=>p(h.slug)},h.slug))})})]})}const eE=""+new URL("mark-CiYXXpnT.png",import.meta.url).href;function UQ({onClose:e}){const t=ke(o=>o.autosave),n=ke(o=>o.setAutosave),s=oe.useRef(null);return oe.useEffect(()=>{const o=i=>{s.current!==null&&!s.current.contains(i.target)&&e()},r=i=>{i.key==="Escape"&&(i.stopPropagation(),e())};return window.addEventListener("mousedown",o),window.addEventListener("keydown",r,!0),()=>{window.removeEventListener("mousedown",o),window.removeEventListener("keydown",r,!0)}},[e]),w.jsxs("div",{className:"stu-rail-settings",ref:s,role:"dialog","aria-label":"Settings",children:[w.jsx("div",{className:"stu-rail-settings-title",children:"Settings"}),w.jsxs("label",{className:"stu-autosave","data-tour":"autosave",children:[w.jsx("input",{type:"checkbox",checked:t,onChange:o=>n(o.target.checked)}),w.jsx("span",{className:"stu-switch","aria-hidden":"true"}),"Autosave"]}),w.jsx("p",{className:"stu-rail-settings-hint",children:"Off: ⌘S reviews every change before it touches the disk."})]})}function KQ(){const e=ke(I=>I.docs),t=ke(I=>I.meta),n=ke(I=>I.mode),s=ke(I=>I.currentSlug),o=ke(I=>I.openDoc),r=ke(I=>I.setMode),{diagnostics:i}=Co(),[l,d]=oe.useState(""),[u,p]=oe.useState(!1),[h,m]=oe.useState(!1),[g,v]=oe.useState(!1),y=oe.useRef(null),b=oe.useRef(null),E=t?.docsDir??"docs",$=i.filter(I=>I.level==="error").length,A=l.trim().toLowerCase(),T=oe.useMemo(()=>{const I=A===""?e:e.filter(O=>O.title.toLowerCase().includes(A)||O.slug.toLowerCase().includes(A));return OQ(I,E)},[e,A,E]);oe.useEffect(()=>{const I=O=>{(O.metaKey||O.ctrlKey)&&O.key.toLowerCase()==="k"&&(O.preventDefault(),v(!0),requestAnimationFrame(()=>y.current?.focus()))};return window.addEventListener("keydown",I),()=>window.removeEventListener("keydown",I)},[]),oe.useEffect(()=>{if(!g)return;const I=C=>{b.current!==null&&!b.current.contains(C.target)&&v(!1)},O=C=>{C.key==="Escape"&&(C.stopPropagation(),v(!1))};return window.addEventListener("mousedown",I),window.addEventListener("keydown",O,!0),()=>{window.removeEventListener("mousedown",I),window.removeEventListener("keydown",O,!0)}},[g]);const N=()=>{v(!1),r("home")},j=I=>{v(!1),o(I),ke.getState().mode!=="edit"&&r("edit")},P=n!=="home"&&s!==null?`/site/${s}.html`:"/site/";return w.jsxs("nav",{className:`stu-rail ${g?"stu-rail-drawer":""}`,"aria-label":"Documents",ref:b,"data-tour":"rail",children:[w.jsxs("div",{className:"stu-rail-mini","aria-hidden":g,children:[w.jsx("button",{type:"button",className:"stu-rail-mini-mark",title:"All documents",onClick:N,children:w.jsx("img",{src:eE,alt:""})}),w.jsx("button",{type:"button",className:"stu-rail-mini-btn",title:"Search docs (⌘K)",onClick:()=>{v(!0),requestAnimationFrame(()=>y.current?.focus())},children:w.jsx(Of,{size:15})}),w.jsx("button",{type:"button",className:`stu-rail-mini-btn ${n==="home"?"stu-rail-mini-on":""}`,title:"All documents",onClick:N,children:w.jsx(IS,{size:15})}),w.jsx("button",{type:"button",className:"stu-rail-mini-btn",title:"New doc",onClick:()=>p(!0),children:w.jsx(dd,{size:15})})]}),w.jsxs("div",{className:"stu-rail-full",children:[w.jsxs("button",{type:"button",className:"stu-rail-brand",title:"All documents",onClick:N,children:[w.jsx("img",{src:eE,alt:"",className:"stu-rail-mark","aria-hidden":"true"}),w.jsxs("span",{className:"stu-rail-name",children:["chiltepin ",w.jsx("em",{children:"studio"})]})]}),w.jsxs("label",{className:`stu-rail-search ${e.length===0?"stu-rail-search-off":""}`,children:[w.jsx(Of,{size:13}),w.jsx("input",{ref:y,type:"text",placeholder:"Search docs","aria-label":"Search docs",disabled:e.length===0,value:l,onChange:I=>d(I.target.value),onKeyDown:I=>{const O=T[0]?.docs[0];I.key==="Enter"&&A!==""&&O!==void 0&&j(O.slug)}}),w.jsx("kbd",{children:"⌘K"})]}),w.jsxs("button",{type:"button",className:"stu-rail-new",onClick:()=>p(!0),children:[w.jsx(dd,{size:12}),"New doc"]}),w.jsxs("button",{type:"button",className:`stu-rail-doc stu-rail-root ${n==="home"?"stu-rail-doc-on":""}`,onClick:N,children:[w.jsx(IS,{size:14}),w.jsx("span",{className:"stu-rail-doc-name",children:"All documents"})]}),w.jsxs("div",{className:"stu-rail-scroll",children:[T.map(I=>w.jsxs("div",{children:[w.jsxs("div",{className:"stu-rail-group",children:[w.jsx("span",{children:I.label}),w.jsx("span",{className:"stu-num",children:I.docs.length})]}),I.docs.map(O=>{const C=n!=="home"&&O.slug===s;return w.jsxs("button",{type:"button",className:`stu-rail-doc ${C?"stu-rail-doc-on":""}`,title:O.slug,onClick:()=>j(O.slug),children:[w.jsx("span",{className:"stu-rail-doc-name",children:O.title}),Ax(O,{slug:s,errors:$}).kind==="errors"&&w.jsx("span",{className:"stu-rail-dot","aria-label":"has errors"})]},O.slug)})]},I.key===""?".":I.key)),A!==""&&T.length===0&&w.jsx("div",{className:"stu-rail-none",children:"No matching docs"})]}),w.jsxs("div",{className:"stu-rail-foot",children:[jy&&w.jsx("a",{href:P,target:"_blank",rel:"noreferrer",title:"Open the built site in a new tab",children:"Site ↗"}),w.jsxs("div",{className:"stu-rail-foot-settings",children:[w.jsx("button",{type:"button",onClick:()=>m(!h),children:"Settings"}),h&&w.jsx(UQ,{onClose:()=>m(!1)})]})]})]}),u&&w.jsx(QC,{onClose:()=>p(!1)})]})}function VQ(e,t){return KA(ys(e,t))}function GQ(){const e=oe.useRef(null),t=ke(s=>s.setMode),n=oe.useMemo(()=>{const s=ke.getState();if(s.currentSlug===null)return{html:null,error:"No document open."};try{return{html:VQ(s.source,s.currentSlug),error:null}}catch(o){return{html:null,error:o instanceof Error?o.message:String(o)}}},[]);return oe.useEffect(()=>{const s=requestAnimationFrame(()=>e.current?.focus());return()=>cancelAnimationFrame(s)},[]),w.jsxs("div",{className:"stu-modearea",children:[n.html!==null?w.jsx("iframe",{ref:e,className:"stu-modeframe",srcDoc:n.html,title:"Presentation"}):w.jsx("div",{className:"stu-present-empty",children:n.error}),w.jsxs("button",{type:"button",className:"stu-present-back",onClick:()=>t("edit"),title:"Back to the editor (Esc)",children:[w.jsx("span",{"aria-hidden":"true",children:"←"})," Back to editor"]})]})}const _p=8;function YQ(){const e=ke(d=>d.pendingDelete),t=ke(d=>d.confirmDelete),n=ke(d=>d.cancelDelete),s=oe.useRef(null),o=oe.useRef(null),[r,i]=oe.useState(null),l=e!==null;return oe.useLayoutEffect(()=>{if(e===null){i(null);return}const d=s.current,u=d?.offsetWidth??240,p=d?.offsetHeight??92,h=Math.min(Math.max(e.anchor.x-u/2,_p),window.innerWidth-u-_p);let m=e.anchor.y+6;m+p>window.innerHeight-_p&&(m=Math.max(_p,e.anchor.y-p-12)),i({left:h,top:m})},[e]),oe.useEffect(()=>{l&&requestAnimationFrame(()=>o.current?.focus())},[l]),oe.useEffect(()=>{if(!l)return;const d=p=>{p.key==="Escape"?(p.preventDefault(),p.stopPropagation(),n()):(p.key==="Backspace"||p.key==="Delete")&&(p.preventDefault(),p.stopPropagation(),t())},u=p=>{s.current!==null&&!s.current.contains(p.target)&&n()};return window.addEventListener("keydown",d,!0),window.addEventListener("mousedown",u,!0),()=>{window.removeEventListener("keydown",d,!0),window.removeEventListener("mousedown",u,!0)}},[l,t,n]),e===null?null:w.jsxs("div",{ref:s,className:"stu-delpop",role:"alertdialog","aria-label":`Delete ${e.label}?`,style:r??{left:e.anchor.x,top:e.anchor.y,visibility:"hidden"},children:[w.jsxs("div",{className:"stu-delpop-text",children:[w.jsx("strong",{children:e.label})," — delete?"]}),w.jsxs("div",{className:"stu-delpop-row",children:[w.jsx("span",{className:"stu-delpop-hint",children:"⌫ again confirms · ⌘Z undoes"}),w.jsx("button",{type:"button",ref:o,className:"stu-btn stu-btn-sm",onClick:n,children:"Cancel"}),w.jsx("button",{type:"button",className:"stu-btn stu-btn-sm stu-btn-danger",onClick:t,children:"Delete"})]})]})}function Hi(e){return Array.isArray(e)?e.map(t=>Array.isArray(t)?t:[]):[]}function qf(e){return Array.isArray(e)?e:null}function Dh(e,t){const n=qf(e);return n!==null&&n.length>0?n.length:Hi(t).reduce((s,o)=>Math.max(s,o.length),0)}function ZC(e,t){const n=e.slice();for(;n.length<t;)n.push("");return n}function XQ(e){return Array.from({length:Math.max(1,e)},()=>"")}function QQ(e){return e.every(t=>t===""||t===null||t===void 0)}function tE(e,t){return[...Hi(t).map(s=>s.slice()),XQ(Dh(e,t))]}function ZQ(e,t){return Hi(e).filter((n,s)=>s!==t).map(n=>n.slice())}function JQ(e,t,n){const s=Dh(e,t),o=Math.max(0,Math.min(n,s)),r=qf(e),i=r!==null?[...r.slice(0,o),"",...r.slice(o)]:null,l=Hi(t).map(d=>{const u=ZC(d,Math.min(o,s));return[...u.slice(0,o),"",...u.slice(o)]});return{columns:i,rows:l}}function eZ(e,t,n){const s=Dh(e,t);if(n<0||n>=s)return{columns:qf(e)?.slice()??null,rows:Hi(t).map(l=>l.slice())};const o=qf(e),r=o!==null?o.filter((l,d)=>d!==n):null,i=Hi(t).map(l=>{const d=ZC(l,s);return[...d.slice(0,n),...d.slice(n+1)]});return{columns:r,rows:i}}function tZ(e){const t=Hi(e.rows),n=e.col>=e.colCount-1,s=e.row>=t.length-1,o=t[e.row]??[];return n?s&&QQ(o)?{kind:"exit"}:s?{kind:"append"}:{kind:"advance",row:e.row+1,col:0}:{kind:"advance",row:e.row,col:e.col+1}}function nE(e){return Array.isArray(e)?e:[]}function el(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function nZ(e,t){if(el(e)){const n=t!==null?Lh(e,t):"";return n==null?"":String(n)}return e==null?"":String(e)}function sZ(e,t){if(t.length!==1||e.kind!=="object")return null;const n=e.fields.find(s=>s.name==="columns");return n!==void 0&&n.node.kind==="array"?{node:n.node.element}:null}function sE({value:e,node:t,arm:n,gridPos:s,onCommit:o}){const r=nZ(e,n),[i,l]=oe.useState(r),[d,u]=oe.useState(!1);oe.useEffect(()=>l(r),[r]);const p=()=>{if(i===r)return;const h=nC(i,el(e)?void 0:e,t);if(!h.ok){u(!0);return}el(e)&&n!==null?o({...Lf(e,n),...Lf(h.value,n)}):o(h.value)};return w.jsx("input",{className:`stu-input stu-grid-input ${d?"stu-input-invalid":""}`,type:"text",value:i,spellCheck:!1,"data-grid-cell":s,onChange:h=>{l(h.target.value),u(!1)},onBlur:p,onKeyDown:h=>{h.key==="Enter"&&p()}})}const oE=224,rE=260;function iE({title:e,value:t,arm:n,node:s,ctx:o,path:r,anchor:i,onClose:l}){const d=oe.useRef(null),u=Lf(t,n),p=Math.max(8,Math.min(i.left-oE+24,window.innerWidth-oE-8)),m=i.bottom+rE>window.innerHeight-8&&i.top-rE>8?{left:p,bottom:window.innerHeight-i.top+4,top:"auto"}:{left:p,top:i.bottom+4};return oe.useEffect(()=>{const g=y=>{const b=d.current;b!==null&&y.target instanceof Node&&!b.contains(y.target)&&setTimeout(l,0)},v=y=>{if(y.key==="Escape"){const b=y.target instanceof HTMLElement?y.target:null;if(b!==null&&b.closest('[data-combo-open="true"]')!==null)return;y.stopPropagation(),y.preventDefault(),l()}};return document.addEventListener("pointerdown",g,!0),window.addEventListener("keydown",v,!0),()=>{document.removeEventListener("pointerdown",g,!0),window.removeEventListener("keydown",v,!0)}},[l]),w.jsxs("div",{ref:d,className:"stu-grid-pop",style:m,role:"dialog","aria-label":`${e} details`,onClick:g=>g.stopPropagation(),children:[w.jsx("div",{className:"stu-grid-pop-title",children:e}),n.fields.map(g=>w.jsxs("div",{className:"stu-dx-field",children:[w.jsx("label",{className:"stu-dx-label",children:$o(g.name)}),w.jsx(Ja,{resolved:Za({blockKind:o.blockKind,name:g.name,node:g.node,value:u[g.name],data:o.rootData,path:[...r,g.name]}),node:g.node,value:u[g.name],optional:g.node.optional,autoFocus:g.name===n.fields[0]?.name,handlers:{onCommit:v=>o.commitPath(r,{...u,[g.name]:v}),onDelete:()=>{const v={...u};delete v[g.name],o.commitPath(r,v)}}})]},g.name)),s!==null&&w.jsx("button",{type:"button",className:"stu-linkbtn stu-grid-pop-simplify",tabIndex:-1,onClick:()=>{o.commitPath(r,Lh(t,n)),l()},children:"Back to plain text"})]})}function oZ({path:e,value:t,element:n,ctx:s}){const o=nE(t).map(U=>nE(U)),r=n.element,i=r.kind==="union"?r:null,l=i!==null?L0(i):null,d=sZ(s.rootNode,e),u=d?.node??null,p=u!==null&&u.kind==="union"?u:null,h=p!==null?L0(p):null,m=d!==null&&el(s.rootData)?s.rootData.columns:void 0,g=d!==null&&Array.isArray(m)?m:null,v=Math.max(1,Dh(g??void 0,o)),y=oe.useRef(null),[b,E]=oe.useState(null),$=(U,X,B,te)=>{if(b!==null&&b.kind===U&&b.r===X&&b.c===B){E(null);return}const ee=te.currentTarget.getBoundingClientRect();E({kind:U,r:X,c:B,anchor:{left:ee.left,top:ee.top,bottom:ee.bottom}})},[A,T]=oe.useState(null),N=oe.useRef(0),j=U=>T({pos:U,n:++N.current});oe.useEffect(()=>{if(A===null)return;const U=setTimeout(()=>{const X=y.current?.querySelector(`[data-grid-cell="${CSS.escape(A.pos)}"]`);X!=null&&(X.focus(),X instanceof HTMLInputElement&&X.select())},60);return()=>clearTimeout(U)},[A]);const P=U=>{d!==null&&U.columns!==null&&s.commitPath(["columns"],U.columns),s.commitPath(e,U.rows)},I=()=>{P(JQ(g??void 0,o,v)),j(d!==null?`h-${v}`:`0-${v}`)},O=U=>{E(null),P(eZ(g??void 0,o,U))},C=()=>{s.commitPath(e,tE(g??void 0,o)),j(`${o.length}-0`)},D=U=>{E(null),s.commitPath(e,ZQ(o,U))},F=U=>{if(U.key!=="Enter")return;const B=U.target.getAttribute("data-grid-cell");if(B===null||B.startsWith("h-"))return;const[te,ee]=B.split("-"),H=Number(te),W=Number(ee);!Number.isInteger(H)||!Number.isInteger(W)||(U.preventDefault(),window.setTimeout(()=>{const K=tZ({rows:o,row:H,col:W,colCount:v});K.kind==="advance"?j(`${K.row}-${K.col}`):K.kind==="append"?(s.commitPath(e,tE(g??void 0,o)),j(`${o.length}-0`)):(s.deletePath([...e,H]),s.exitArray(e))},0))};return w.jsxs("div",{className:"stu-grid",ref:y,onKeyDown:F,children:[w.jsx("div",{className:"stu-grid-scroll",children:w.jsxs("table",{className:"stu-grid-table",children:[g!==null&&w.jsx("thead",{children:w.jsxs("tr",{children:[Array.from({length:v},(U,X)=>{const B=g[X],te=el(B)&&B.highlight===!0;return w.jsx("th",{className:te?"stu-grid-th-hl":"",children:w.jsxs("div",{className:"stu-grid-cellwrap","data-field-path":`columns.${X}`,children:[w.jsx(sE,{value:B,node:u,arm:h,gridPos:`h-${X}`,onCommit:ee=>s.commitPath(["columns",X],ee)}),w.jsxs("span",{className:"stu-grid-celltools",children:[h!==null&&w.jsx("button",{type:"button",className:"stu-grid-cellbtn",title:"Column details (align, highlight…)","aria-label":`Column ${X+1} details`,tabIndex:-1,onClick:ee=>$("col",-1,X,ee),children:"⋯"}),w.jsx("button",{type:"button",className:"stu-grid-cellbtn stu-grid-cellbtn-danger",title:"Remove column","aria-label":`Remove column ${X+1}`,tabIndex:-1,onClick:()=>O(X),children:"×"})]})]})},X)}),w.jsx("th",{className:"stu-grid-addcol-th",children:w.jsx("button",{type:"button",className:"stu-grid-addcol",title:"Add column","aria-label":"Add column",onClick:I,children:"+"})})]})}),w.jsx("tbody",{children:o.map((U,X)=>w.jsxs("tr",{children:[Array.from({length:v},(B,te)=>{const ee=U[te],H=el(ee)&&typeof ee.tone=="string";return w.jsx("td",{children:w.jsxs("div",{className:"stu-grid-cellwrap","data-field-path":`${e.join(".")}.${X}.${te}`,children:[w.jsx(sE,{value:ee,node:r,arm:l,gridPos:`${X}-${te}`,onCommit:W=>s.commitPath([...e,X,te],W)}),H&&w.jsx("span",{className:`stu-grid-tonedot stu-grid-tone-${String(ee.tone)}`,"aria-hidden":"true"}),l!==null&&w.jsx("span",{className:"stu-grid-celltools",children:w.jsx("button",{type:"button",className:"stu-grid-cellbtn",title:"Cell details (tone, highlight…)","aria-label":`Cell ${X+1}·${te+1} details`,tabIndex:-1,onClick:W=>$("cell",X,te,W),children:"⋯"})})]})},te)}),w.jsx("td",{className:"stu-grid-rowtools-td",children:w.jsx("button",{type:"button",className:"stu-grid-cellbtn stu-grid-cellbtn-danger stu-grid-rowdel",title:"Remove row","aria-label":`Remove row ${X+1}`,tabIndex:-1,onClick:()=>D(X),children:"×"})})]},X))})]})}),w.jsxs("div",{className:"stu-grid-foot",children:[w.jsx("button",{type:"button",className:"stu-addbtn stu-grid-addrow",onClick:C,children:"+ Add row"}),g===null&&w.jsx("button",{type:"button",className:"stu-addbtn stu-grid-addrow",onClick:I,children:"+ Add column"}),g===null&&d!==null&&o.length>0&&w.jsx("button",{type:"button",className:"stu-addbtn stu-grid-addrow",onClick:()=>{s.commitPath(["columns"],Array.from({length:v},()=>"")),j("h-0")},children:"+ Add header row"})]}),b!==null&&b.kind==="col"&&h!==null&&w.jsx(iE,{title:`Column ${b.c+1}`,value:(g??[])[b.c],arm:h,node:p,ctx:s,path:["columns",b.c],anchor:b.anchor,onClose:()=>E(null)}),b!==null&&b.kind==="cell"&&l!==null&&w.jsx(iE,{title:`Row ${b.r+1} · Cell ${b.c+1}`,value:o[b.r]?.[b.c],arm:l,node:i,ctx:s,path:[...e,b.r,b.c],anchor:b.anchor,onClose:()=>E(null)})]})}function ud(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:{}}function ul(e){return Array.isArray(e)?e:[]}function rZ({path:e,value:t,element:n,ctx:s}){const o=ul(t),[r,i]=oe.useState(""),l=()=>{const u=r.trim();if(u==="")return;const p=Number.isFinite(Number(u))&&(n.kind==="number"||n.kind==="union"&&n.arms.some(h=>h.kind==="number"));s.commitPath(e,[...o,p?Number(u):u]),i("")},d=u=>{if(u!==null&&typeof u=="object"&&n.kind==="union"){const p=L0(n);if(p!==null)return String(Lh(u,p))}return String(u)};return w.jsxs("div",{className:"stu-chips",children:[o.map((u,p)=>w.jsxs("span",{className:"stu-chip-item",children:[d(u),w.jsx("button",{type:"button","aria-label":`Remove ${d(u)}`,onClick:()=>s.commitPath(e,o.filter((h,m)=>m!==p)),children:"×"})]},p)),n.kind==="enum"?w.jsxs("select",{className:"stu-input stu-input-select stu-chips-add",value:"",onChange:u=>{u.target.value!==""&&s.commitPath(e,[...o,u.target.value])},children:[w.jsx("option",{value:"",children:"+ add…"}),n.options.map(u=>w.jsx("option",{value:u,children:u},u))]}):w.jsx("input",{className:"stu-input stu-chips-add",type:"text",placeholder:"+ add…",value:r,onChange:u=>i(u.target.value),onBlur:l,onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),l())}})]})}const iZ=["name","label","title","text","summary","term","question","value"];function aZ(e,t,n){if(t.kind==="object"){const s=ud(e);for(const o of iZ){const r=s[o];if(typeof r=="string"&&r!=="")return r}for(const o of t.fields){const r=s[o.name];if(typeof r=="string"&&r!=="")return r}}return typeof e=="string"&&e!==""?e:`Item ${n+1}`}function lZ({name:e,path:t,value:n,element:s,ctx:o}){const r=ul(n),[i,l]=oe.useState(()=>o.fresh&&ul(n).length>0?0:null),d=oe.useRef(r);d.current=r;const u=o.reveal,p=t.join(".");oe.useEffect(()=>{if(u==null||u.path!==p&&!u.path.startsWith(`${p}.`))return;const v=u.path.slice(p.length+1),y=Number(v.split(".")[0]);Number.isInteger(y)&&y>=0&&l(y)},[u,p]);const h=o.focusReq;oe.useEffect(()=>{if(h===null)return;if(h.path===p){d.current.length>0&&l(0);return}if(!h.path.startsWith(`${p}.`))return;const v=Number(h.path.slice(p.length+1).split(".")[0]);Number.isInteger(v)&&v>=0&&l(v)},[h,p]);const m=v=>o.commitPath(t,v),g=(v,y)=>{if(v.key!=="Enter")return;const b=v.target,E=v.metaKey||v.ctrlKey;if(b.tagName==="TEXTAREA"&&!E)return;const $=v.currentTarget;window.setTimeout(()=>{const A=Bf($),T=A.indexOf(document.activeElement),N=d.current[y],j=Qa(s,d.current.slice(0,y),as(e)),P=rY({isLastField:T<0||T===A.length-1,pristine:uC(N,j)});if(P==="advance"){const I=A[T+1];I!==void 0&&zf(I);return}if(P==="append"){const I=d.current;if(y<I.length-1){l(y+1),o.requestFocus(`${p}.${y+1}`);return}o.commitPath([...t,I.length],Qa(s,I,as(e))),l(I.length),o.requestFocus(`${p}.${I.length}`);return}o.deletePath([...t,y]),l(null),o.exitArray(t)},0)};return w.jsxs("div",{className:"stu-items",children:[r.map((v,y)=>w.jsxs("div",{className:`stu-item ${i===y?"stu-item-open":""}`,"data-field-path":`${p}.${y}`,children:[w.jsxs("div",{className:"stu-item-row",children:[w.jsxs("button",{type:"button",className:"stu-item-summary",tabIndex:-1,onClick:()=>l(i===y?null:y),children:[w.jsx("span",{className:`stu-item-caret ${i===y?"stu-item-caret-open":""}`,"aria-hidden":"true",children:"▸"}),w.jsx("span",{className:"stu-item-title",children:aZ(v,s,y)})]}),w.jsxs("div",{className:"stu-item-tools",children:[w.jsx("button",{type:"button","aria-label":"Move up",tabIndex:-1,disabled:y===0,onClick:()=>{const b=r.slice(),[E]=b.splice(y,1);b.splice(y-1,0,E),m(b)},children:"↑"}),w.jsx("button",{type:"button","aria-label":"Move down",tabIndex:-1,disabled:y===r.length-1,onClick:()=>{const b=r.slice(),[E]=b.splice(y,1);b.splice(y+1,0,E),m(b)},children:"↓"}),w.jsx("button",{type:"button","aria-label":"Remove",className:"stu-item-remove",tabIndex:-1,onClick:()=>o.deletePath([...t,y]),children:"×"})]})]}),i===y&&w.jsx("div",{className:"stu-item-fields",onKeyDown:b=>g(b,y),children:w.jsx(tN,{node:s,path:[...t,y],value:v,ctx:o})})]},y)),w.jsxs("button",{type:"button",className:"stu-addbtn",onClick:()=>{m([...r,Qa(s,r,as(e))]),l(r.length),o.requestFocus(`${p}.${r.length}`)},children:["+ Add ",as(e)]})]})}function JC({name:e,node:t,path:n,value:s,ctx:o}){const r=_h(t,s),i=r!==null&&s!==null&&typeof s=="object"&&!Array.isArray(s),l=i?null:w.jsx(Ja,{resolved:Za({blockKind:o.blockKind,name:e,node:t,value:s,data:o.rootData,path:n}),node:t,value:s,optional:t.optional,handlers:{onCommit:d=>o.commitPath(n,d),onDelete:()=>o.deletePath(n),onStage:d=>o.stagePath(n,d)}});return r===null?l??w.jsx(q0,{ctx:o}):w.jsxs("div",{className:"stu-union",children:[w.jsxs("div",{className:"stu-union-toggle",role:"group","aria-label":`${$o(e)} shape`,children:[w.jsx("button",{type:"button",className:`stu-union-seg ${i?"":"stu-union-seg-active"}`,"aria-pressed":!i,tabIndex:-1,onClick:()=>{i&&o.commitPath(n,Lh(s,r))},children:"Simple"}),w.jsx("button",{type:"button",className:`stu-union-seg ${i?"stu-union-seg-active":""}`,"aria-pressed":i,tabIndex:-1,onClick:()=>{i||o.commitPath(n,Lf(s,r))},children:"Detailed"})]}),i?w.jsx("div",{className:"stu-union-fields",children:w.jsx(eN,{node:r,path:n,value:s,ctx:o})}):l]})}function cZ({name:e,path:t,value:n,element:s,ctx:o}){const r=ul(n);return w.jsxs("div",{className:"stu-items stu-union-items",children:[r.map((i,l)=>w.jsxs("div",{className:"stu-union-item","data-field-path":`${t.join(".")}.${l}`,children:[w.jsx(JC,{name:as(e),node:s,path:[...t,l],value:i,ctx:o}),w.jsx("button",{type:"button","aria-label":`Remove ${as(e)} ${l+1}`,className:"stu-union-item-remove",tabIndex:-1,onClick:()=>o.deletePath([...t,l]),children:"×"})]},l)),w.jsxs("button",{type:"button",className:"stu-addbtn",onClick:()=>o.commitPath([...t,r.length],""),children:["+ Add ",as(e)]})]})}function eN({node:e,path:t,value:n,ctx:s,fieldDiags:o}){const r=ud(n);return w.jsx(w.Fragment,{children:e.fields.map(i=>w.jsx(nN,{name:i.name,node:i.node,path:[...t,i.name],value:r[i.name],ctx:s,diags:o?.get(i.name)},i.name))})}function aE({label:e,count:t,defaultOpen:n,openSignal:s,children:o}){const[r,i]=oe.useState(n);return oe.useEffect(()=>{s>0&&i(!0)},[s]),w.jsxs("div",{className:`stu-collapse ${r?"stu-collapse-open":""}`,children:[w.jsxs("button",{type:"button",className:"stu-collapse-head","aria-expanded":r,onClick:()=>i(!r),children:[w.jsx("span",{className:`stu-item-caret ${r?"stu-item-caret-open":""}`,"aria-hidden":"true",children:"▸"}),e,w.jsx("span",{className:"stu-collapse-count",children:t})]}),r&&w.jsx("div",{className:"stu-collapse-body",children:o})]})}function tN({node:e,path:t,value:n,ctx:s,fieldDiags:o}){const r=ud(n),{primary:i,more:l,advanced:d}=oe.useMemo(()=>cl(e.fields,n),[e,n]),u=s.reveal,p=t.join(".");let h=null;u!=null&&(p===""?h=u.path.split(".")[0]??null:u.path.startsWith(`${p}.`)&&(h=u.path.slice(p.length+1).split(".")[0]??null));const m=b=>h!==null&&b.some(E=>E.name===h)?u?.n??0:0,g=b=>b.some(E=>(o?.get(E.name)?.length??0)>0),v=t.length===0&&e.fields.some(b=>b.node.kind==="array"&&b.node.element.kind==="array")&&e.fields.some(b=>b.name==="columns"&&b.node.kind==="array"),y=b=>v&&b.name==="columns"&&t.length===0?null:w.jsx(nN,{name:b.name,node:b.node,path:[...t,b.name],value:r[b.name],ctx:s,diags:o?.get(b.name)},b.name);return w.jsxs(w.Fragment,{children:[i.map(y),l.length>0&&w.jsx(aE,{label:"More fields",count:l.length,defaultOpen:g(l),openSignal:m(l),children:l.map(y)}),d.length>0&&w.jsx(aE,{label:"Advanced",count:d.length,defaultOpen:g(d),openSignal:m(d),children:d.map(y)})]})}function Lp({diags:e}){return e===void 0||e.length===0?null:w.jsx("div",{className:"stu-field-diags",children:e.map((t,n)=>w.jsx("div",{className:`stu-field-diag stu-field-diag-${t.level}`,children:t.message},n))})}function nN({name:e,node:t,path:n,value:s,ctx:o,diags:r}){const i=w.jsxs("label",{className:"stu-field-label",children:[$o(e),t.optional&&w.jsx("span",{className:"stu-optional",children:"optional"})]});let l;switch(t.kind){case"string":case"number":case"boolean":case"enum":{const d=Za({blockKind:o.blockKind,name:e,node:t,value:s,data:o.rootData,path:n});l=w.jsx(Ja,{resolved:d,node:t,value:s,optional:t.optional,handlers:{onCommit:u=>o.commitPath(n,u),onDelete:()=>o.deletePath(n),onStage:u=>o.stagePath(n,u)}});break}case"union":l=w.jsx(JC,{name:e,node:t,path:n,value:s,ctx:o});break;case"array":if(t.element.kind==="object")return w.jsxs("div",{className:"stu-field stu-field-block","data-field-path":n.join("."),children:[i,w.jsx(lZ,{name:e,path:n,value:s,element:t.element,ctx:o}),w.jsx(Lp,{diags:r})]});if(t.element.kind==="array")return w.jsxs("div",{className:"stu-field stu-field-block","data-field-path":n.join("."),children:[i,w.jsx(oZ,{path:n,value:s,element:t.element,ctx:o}),w.jsx(Lp,{diags:r})]});t.element.kind==="opaque"?l=w.jsx(q0,{ctx:o}):t.element.kind==="union"&&ZA(t.element).length>0?l=w.jsx(cZ,{name:e,path:n,value:s,element:t.element,ctx:o}):l=w.jsx(rZ,{path:n,value:s,element:t.element,ctx:o});break;case"object":return w.jsxs("fieldset",{className:"stu-fieldset","data-field-path":n.join("."),children:[w.jsxs("legend",{children:[$o(e),t.optional&&w.jsx("span",{className:"stu-optional",children:"optional"})]}),w.jsx(eN,{node:t,path:n,value:s,ctx:o}),w.jsx(Lp,{diags:r})]});case"opaque":l=w.jsx(q0,{ctx:o});break}return w.jsxs("div",{className:"stu-field","data-field-path":n.join("."),children:[i,l,w.jsx(Lp,{diags:r})]})}function q0({ctx:e}){return w.jsxs("div",{className:"stu-opaque",children:["This field holds free-form content —"," ",w.jsx("button",{type:"button",className:"stu-linkbtn",onClick:e.openYaml,children:"open the YAML tab"})," ","to edit it."]})}function dZ({seg:e,fresh:t=!1,commitPath:n,deletePath:s,stagePath:o,openYaml:r,fieldDiags:i,reveal:l}){const d=yy(e.kind),u=oe.useRef(null),p=oe.useRef(e.data);p.current=e.data;const[h,m]=oe.useState(null),g=oe.useRef(0),v=b=>m({path:b,n:++g.current}),y={blockKind:e.kind,rootData:e.data,rootNode:d,fresh:t,commitPath:n,deletePath:s,stagePath:o,openYaml:r,reveal:l,focusReq:h,requestFocus:v,exitArray:b=>{if(b.length!==1||typeof b[0]!="string"||d.kind!=="object")return;const E=oY(d,p.current,b[0]);if(E!==null)if(E.node.kind==="array"&&E.node.element.kind==="object"){const $=ul(ud(p.current)[E.name]);v($.length>0?`${E.name}.0`:E.name)}else v(E.name)}};return oe.useEffect(()=>{if(d.kind!=="object")return;const b=cl(d.fields,p.current).primary[0];if(t&&b!==void 0&&b.node.kind==="array"&&b.node.element.kind==="object"&&ul(ud(p.current)[b.name]).length===0){n([b.name,0],Qa(b.node.element,[],as(b.name))),v(`${b.name}.0`);return}const E=sY(d,p.current);E[0]!==void 0&&v(E[0])},[]),oe.useEffect(()=>{if(h===null)return;const b=setTimeout(()=>{const E=u.current;if(E===null)return;const $=E.querySelector(`[data-field-path="${CSS.escape(h.path)}"]`);if($===null)return;const A=Bf($)[0]??$.querySelector(".stu-addbtn");A!=null&&zf(A)},60);return()=>clearTimeout(b)},[h]),d.kind!=="object"?w.jsxs("div",{className:"stu-opaque stu-opaque-block",children:["This block's schema has no structural form description —"," ",w.jsx("button",{type:"button",className:"stu-linkbtn",onClick:r,children:"edit it as YAML"}),"."]}):w.jsx("div",{className:"stu-form",ref:u,children:w.jsx(tN,{node:d,path:[],value:e.data,ctx:y,fieldDiags:i})})}const uZ=250;function lE({diags:e}){return e.length===0?null:w.jsx("div",{className:"stu-sheet-diags",children:e.map((t,n)=>w.jsxs("div",{className:`stu-diag stu-diag-${t.level}`,children:[w.jsx("span",{className:"stu-diag-code",children:t.code}),w.jsx("div",{className:"stu-diag-msg",children:t.message}),t.hint!==void 0&&w.jsx("div",{className:"stu-diag-hint",children:t.hint})]},n))})}function pZ({seg:e,revealField:t}){const n=Ah(),s=ke(Z=>Z.closeSheet),o=ke(Z=>Z.commitSheet),r=ke(Z=>Z.setSheetDirty),i=ke(Z=>Z.sheetFresh),l=Ko(e.sourceType)?ch(e):e.raw,[d,u]=oe.useState(l),[p,h]=oe.useState(l),m=oe.useRef(d);m.current=d;const g=oe.useRef(null),v=d!==l;oe.useEffect(()=>{r(v)},[v,r]),oe.useEffect(()=>()=>{g.current!==null&&clearTimeout(g.current)},[]);const y=Z=>{g.current!==null&&clearTimeout(g.current),m.current=Z,u(Z),h(Z)},b=Z=>{g.current!==null&&clearTimeout(g.current),g.current=setTimeout(()=>{g.current=null;try{h(Z())}catch{}},uZ)},E=oe.useMemo(()=>z0(e.kind,d),[e.kind,d]),$=oe.useMemo(()=>p===d?E:z0(e.kind,p),[e.kind,p,d,E]),A=E.seg?.parseError,[T,N]=oe.useState(A!==void 0?"yaml":"form"),[j,P]=oe.useState(!1);oe.useEffect(()=>{A!==void 0&&N("yaml")},[A]);const{byField:I,rest:O}=oe.useMemo(()=>YC(d,E.diagnostics),[d,E.diagnostics]),C=()=>{Ni("sheet-done");const Z=document.activeElement;Z instanceof HTMLElement&&Z.blur();const q=m.current;q===l?s(!0):o(q)},D=()=>s();oe.useEffect(()=>{const Z=q=>{if(ke.getState().review!==null)return;const de=q.target instanceof HTMLElement?q.target:null;if(q.key==="Escape"){if(de!==null&&de.closest('[data-combo-open="true"]')!==null||document.querySelector(".stu-grid-pop, .stu-sheet .stu-dx-pop")!==null)return;q.stopPropagation(),D();return}if((q.metaKey||q.ctrlKey)&&q.key==="Enter"){if(de?.tagName==="TEXTAREA"&&de.closest(".stu-item-fields")!==null)return;q.preventDefault(),C()}};return window.addEventListener("keydown",Z,!0),()=>window.removeEventListener("keydown",Z,!0)},[d,v]);const F=(Z,q)=>{y(Ai(m.current,Z,q,e.kind)),(typeof q!="object"||q===null)&&Ni("field-commit")},U=Z=>{y(h0(m.current,Z))},X=(Z,q)=>{b(()=>Ai(m.current,Z,q,e.kind))},B=oe.useRef(null),te=oe.useRef(null),[ee,H]=oe.useState(null),[W,K]=oe.useState(t!==null?{path:t,n:1}:null),R=oe.useRef(t!==null?1:0);oe.useEffect(()=>{ke.getState().sheetReveal!==null&&ke.setState({sheetReveal:null})},[]);const z=oe.useMemo(()=>({kind:e.kind,commitPath:(Z,q)=>y(Ai(m.current,Z,q,e.kind)),commitPaths:Z=>{let q=m.current;for(const de of Z)q=Ai(q,de.path,de.value,e.kind);y(q)},deletePath:Z=>y(h0(m.current,Z)),openFull:()=>N("yaml"),notify:Z=>ke.getState().toast(Z)}),[e.kind]),Y=Z=>{const q=B.current;if(q===null)return null;let de=null,le=-1;for(const J of Array.from(q.querySelectorAll("[data-field-path]"))){const ue=J.getAttribute("data-field-path")??"";(Z===ue||Z.startsWith(`${ue}.`))&&ue.length>le&&(de=J,le=ue.length)}return de},V=Z=>T!=="form"||Y(Z)===null?!1:(K({path:Z,n:++R.current}),!0);oe.useEffect(()=>{if(W===null)return;const Z=setTimeout(()=>{const q=Y(W.path);q!==null&&(q.scrollIntoView({block:"center",behavior:"smooth"}),q.classList.add("stu-field-flash"),q.querySelector("input, textarea, select")?.focus({preventScroll:!0}),setTimeout(()=>q.classList.remove("stu-field-flash"),1400))},60);return()=>clearTimeout(Z)},[W]);const re=Z=>{const q=Z.target.closest("[data-field-path]");H(q!==null?q.getAttribute("data-field-path"):null)},Q=Z=>{const q=Z.target.closest("[data-field-path]");q!==null&&H(q.getAttribute("data-field-path"))},ne=td.find(Z=>Z.id===Rp[e.kind]);return w.jsx("div",{className:"stu-sheet-backdrop",onMouseDown:Z=>{Z.target===Z.currentTarget&&!v&&D()},children:w.jsxs("div",{className:"stu-sheet",role:"dialog","aria-modal":"true","aria-label":`Edit ${il[e.kind]}`,children:[w.jsxs("header",{className:"stu-sheet-head",children:[w.jsxs("div",{className:"stu-sheet-title",children:[w.jsx("h2",{children:il[e.kind]}),w.jsx("span",{className:"stu-kind-chip",children:e.kind}),w.jsx("span",{className:"stu-family-label",children:ne?.label??""})]}),w.jsxs("div",{className:"stu-tabs stu-sheet-tabs",role:"tablist",children:[w.jsx("button",{type:"button",role:"tab","aria-selected":T==="form",className:`stu-tab ${T==="form"?"stu-tab-active":""}`,onClick:()=>N("form"),disabled:A!==void 0,children:"Form"}),w.jsx("button",{type:"button",role:"tab","aria-selected":T==="yaml",className:`stu-tab ${T==="yaml"?"stu-tab-active":""}`,onClick:()=>N("yaml"),children:"YAML"})]}),w.jsxs("div",{className:"stu-sheet-actions",children:[w.jsx("button",{type:"button",className:"stu-btn stu-sheet-prevbtn","aria-pressed":j,title:j?"Hide the in-panel preview":"Show a preview of this block in the panel",onClick:()=>P(!j),children:"Preview"}),w.jsx("button",{type:"button",className:"stu-btn",onClick:D,children:"Cancel"}),w.jsx("button",{type:"button",className:"stu-btn stu-btn-primary",onClick:C,children:"Done"})]})]}),w.jsxs("div",{className:"stu-sheet-body",children:[w.jsx("div",{className:"stu-sheet-form",ref:B,onMouseOver:re,onMouseLeave:()=>H(null),onFocusCapture:Q,children:T==="form"&&E.seg!==void 0?w.jsxs(w.Fragment,{children:[w.jsx(dZ,{seg:E.seg,fresh:i,commitPath:F,deletePath:U,stagePath:X,openYaml:()=>N("yaml"),fieldDiags:I,reveal:W}),w.jsx(lE,{diags:O})]}):w.jsxs("div",{className:"stu-sheet-yaml",children:[A!==void 0&&w.jsxs("div",{className:"stu-diag stu-diag-error",children:[w.jsx("span",{className:"stu-diag-code",children:"YAML"}),w.jsx("div",{className:"stu-diag-msg",children:A})]}),w.jsx("textarea",{className:"stu-yaml-editor",value:d,onChange:Z=>{const q=Z.target.value;u(q),b(()=>q)},spellCheck:!1}),w.jsx(lE,{diags:A===void 0?O:[]})]})}),w.jsxs("div",{className:`stu-sheet-preview ${j?"stu-sheet-preview-open":""}`,children:[w.jsx("span",{className:"stu-sheet-preview-label",children:"Preview"}),w.jsx("div",{className:"stu-sheet-preview-scroll",children:$.html!==""?w.jsxs("div",{className:"stu-sheet-preview-wrap","data-doc-theme":Mh(n),ref:te,children:[w.jsx("div",{className:"docskin stu-sheet-preview-doc",dangerouslySetInnerHTML:{__html:$.html}}),w.jsx(UC,{host:z,data:E.seg?.data,html:$.html,wrapperRef:te,linkPath:ee,onElementClick:V})]}):w.jsx("div",{className:"stu-sheet-preview-empty",children:"Nothing to preview yet — fill in the fields."})})]})]})]})})}function fZ(){const e=ke(o=>o.sheet),t=ke(o=>o.sheetReveal),{doc:n}=Co(),s=e!==null?n.segments[e]:void 0;return e===null||s===void 0||s.kind==="markdown"?null:w.jsx(pZ,{seg:s,revealField:t},`${e}:${s.kind}:${s.raw}`)}function hZ(){const e=ke(u=>u.pendingImport),t=ke(u=>u.confirmImport),n=ke(u=>u.cancelImport),[s,o]=oe.useState(""),r=oe.useRef(null),i=oe.useRef(null),l=e!==null;if(oe.useEffect(()=>{e!==null&&(o(e.defaultSlug),requestAnimationFrame(()=>r.current?.select()))},[e]),oe.useEffect(()=>{if(!l)return;const u=p=>{p.key==="Escape"&&(p.stopPropagation(),n())};return window.addEventListener("keydown",u,!0),()=>window.removeEventListener("keydown",u,!0)},[l,n]),e===null)return null;const d=()=>{const u=s.trim().replace(/\.md$/,"");if(u===""){r.current?.focus();return}t(u)};return w.jsx("div",{className:"stu-sheet-backdrop",onMouseDown:u=>{i.current!==null&&!i.current.contains(u.target)&&n()},children:w.jsxs("div",{className:"stu-import",ref:i,role:"dialog","aria-modal":"true","aria-label":"Create a doc from an OpenAPI spec",children:[w.jsxs("div",{className:"stu-import-head",children:[w.jsx("span",{className:"stu-import-glyph",children:w.jsx(LC,{size:15})}),w.jsx("h2",{children:"Import OpenAPI spec"})]}),w.jsxs("p",{className:"stu-import-text",children:["Create ",w.jsxs("code",{children:[s.trim()===""?e.defaultSlug:s.trim(),".md"]})," from"," ",w.jsx("strong",{children:e.title}),"? The doc gets a cover, an endpoint table, one sequence diagram per endpoint, and an ERD of the schemas."]}),w.jsx("input",{ref:r,className:"stu-import-slug",type:"text","aria-label":"Doc slug",placeholder:"slug, e.g. api/orders",value:s,onChange:u=>o(u.target.value),onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),d())}}),w.jsxs("div",{className:"stu-import-foot",children:[w.jsx("span",{className:"stu-import-hint",children:"Enter creates · Esc cancels"}),w.jsx("button",{type:"button",className:"stu-btn",onClick:n,children:"Cancel"}),w.jsx("button",{type:"button",className:"stu-btn stu-btn-primary",onClick:d,children:"Create doc"})]})]})})}function mZ({change:e}){return w.jsxs("span",{className:`stu-review-glyph stu-review-glyph-${e}`,"aria-hidden":"true",children:[e==="edited"&&w.jsx(P0,{size:11}),e==="added"&&w.jsx(dd,{size:11}),e==="removed"&&w.jsx(vx,{size:11}),e==="reordered"&&"⇅"]})}function gZ(){const e=ke(v=>v.review),t=ke(v=>v.currentSlug),n=ke(v=>v.savedSource),s=ke(v=>v.source),o=ke(v=>v.docs),r=Ah(),i=ke(v=>v.applyReview),l=ke(v=>v.cancelReview),d=oe.useRef(null),{diagnostics:u}=Co(),p=e!==null&&t!==null,h=u.filter(v=>v.level==="error").length,m=oe.useMemo(()=>p?hC(n,s,t):[],[p,n,s,t]);if(oe.useEffect(()=>{p&&requestAnimationFrame(()=>d.current?.focus())},[p]),oe.useEffect(()=>{if(!p)return;const v=y=>{y.key==="Escape"?(y.preventDefault(),y.stopPropagation(),l()):(y.key==="Enter"||(y.metaKey||y.ctrlKey)&&y.key.toLowerCase()==="s")&&(y.preventDefault(),y.stopPropagation(),i())};return window.addEventListener("keydown",v,!0),()=>window.removeEventListener("keydown",v,!0)},[p,i,l]),!p)return null;const g=o.find(v=>v.slug===t)?.file??`${t}.md`;return w.jsx("div",{className:"stu-review-backdrop","data-surface":Mh(r),onMouseDown:v=>{v.target===v.currentTarget&&l()},children:w.jsxs("div",{className:"stu-review",role:"dialog","aria-modal":"true","aria-label":"Review changes",children:[w.jsxs("header",{className:"stu-review-head",children:[w.jsxs("h2",{children:["Apply changes to ",w.jsx("code",{children:g}),"?"]}),w.jsx("p",{className:"stu-review-sub",children:m.length===0?"Nothing structural changed.":w.jsxs(w.Fragment,{children:[w.jsxs("strong",{className:"stu-review-count",children:[m.length," change",m.length===1?"":"s"]})," ","since the last save"]})})]}),w.jsx("div",{className:"stu-review-list",children:m.length===0?w.jsx("div",{className:"stu-review-empty",children:"Formatting-only changes (whitespace)"}):w.jsx("ul",{children:m.map((v,y)=>w.jsxs("li",{className:"stu-review-item",children:[w.jsx(mZ,{change:v.change}),w.jsx("span",{className:"stu-review-label",children:v.label}),w.jsxs("span",{className:"stu-review-kind",children:[v.kind==="markdown"?"Text":il[v.kind]," · ",v.change]})]},y))})}),h>0&&w.jsxs("p",{className:"stu-review-errline",role:"alert",children:[h," error",h===1?"":"s"," — Apply anyway?"]}),w.jsxs("footer",{className:"stu-review-foot",children:[w.jsx("button",{type:"button",className:"stu-btn",onClick:l,children:"Cancel"}),w.jsx("button",{type:"button",ref:d,className:"stu-btn stu-btn-primary",onClick:()=>{i()},children:"Apply ▸"})]})]})})}const vZ=new Map(td.map(e=>[e.id,e.label])),Wi=Zf.filter(e=>e!=="meta").map(e=>({type:e,label:il[e],description:O6[e],family:Rp[e],familyLabel:vZ.get(Rp[e])??Rp[e]})),yZ=new Map(Wi.map(e=>[e.type,e]));function xZ(e){const t=io[e]?.patch??{};return Object.entries(t).map(([n,s])=>`${n}: ${String(s)}`).join(", ")}const kZ=Object.entries(io).flatMap(([e,t])=>{const n=yZ.get(t.type);if(n===void 0)return[];const s=xZ(e);return[{...n,alias:e,label:`${n.label} — matches ${e}${s===""?"":` (${s})`}`,description:t.description}]});function sN(e){return e.alias===void 0?ih(e.type):bZ(e.alias)}function bZ(e){const t=io[e];if(t===void 0)throw new RangeError(`unknown block alias: ${e}`);let n=ih(t.type);for(const[s,o]of Object.entries(t.patch??{})){const r=`${s}: ${String(o)}`,i=new RegExp(`^${s}:.*$`,"m");n=i.test(n)?n.replace(i,r):`${r}
3259
+ ${n}`}return n}function wZ(e,t){if(e.alias!==void 0)return e.alias===t?110:e.alias.startsWith(t)?85:e.alias.includes(t)?45:0;const n=e.type,s=e.label.toLowerCase();return n===t?100:n.startsWith(t)?80:s.startsWith(t)?70:s.split(/[\s/&-]+/).some(o=>o.startsWith(t))?60:s.includes(t)?50:n.includes(t)?45:e.description.toLowerCase().includes(t)?25:e.familyLabel.toLowerCase().includes(t)?15:0}const $Z=[...Wi,...kZ];function oN(e){const t=e.trim().toLowerCase().split(/\s+/).filter(s=>s!=="");if(t.length===0)return[...Wi];const n=[];return $Z.forEach((s,o)=>{let r=0;for(const i of t){const l=wZ(s,i);if(l===0)return;r+=l}n.push({item:s,rank:r,order:o})}),n.sort((s,o)=>o.rank-s.rank||s.order-o.order),n.map(s=>s.item)}const SZ=new Map(Wi.map(e=>[e.type,e]));function EZ(e,t){return oN(e).slice(0,t)}function MZ(e){const t=new Map;for(const n of oN(e)){if(t.has(n.type))continue;const s=SZ.get(n.type);s!==void 0&&t.set(n.type,n.alias===void 0?{item:s}:{item:s,alias:n.alias})}return t}function AZ(e,t){const n=MZ(e),s=new Map;let o=0;for(const l of Wi){const d=n.get(l.type);if(d===void 0)continue;o+=1;const u=s.get(l.family);u===void 0?s.set(l.family,[d]):u.push(d)}const r=new Map(td.map(l=>[l.id,s.get(l.id)?.length??0])),i=td.filter(l=>t==="all"||l.id===t).map(l=>({family:l.id,label:l.label,hits:s.get(l.id)??[]})).filter(l=>l.hits.length>0);return{groups:i,shown:i.reduce((l,d)=>l+d.hits.length,0),total:Wi.length,familyCounts:r,matched:o}}function rN(e){return sN(e.alias===void 0?{type:e.item.type}:{type:e.item.type,alias:e.alias})}function cE(e){const t=io[e]?.patch??{};return Object.entries(t).map(([n,s])=>`${n}: ${String(s)}`).join(", ")}function CZ(e,t){return e!==null?e+1:t}function NZ(e,t,n){return e??CZ(t,n)}function TZ(e){return e==="ArrowLeft"||e==="ArrowRight"||e==="ArrowUp"||e==="ArrowDown"||e==="Home"||e==="End"}function _Z(e,t,n,s){if(s<=0)return 0;const o=Math.max(1,n),r=Math.min(Math.max(e,0),s-1);switch(t){case"ArrowLeft":return Math.max(0,r-1);case"ArrowRight":return Math.min(s-1,r+1);case"ArrowUp":return Math.max(0,r-o);case"ArrowDown":return Math.min(s-1,r+o);case"Home":return 0;case"End":return s-1}}const LZ=760,IZ=.235;function jZ({type:e}){const[t,n]=oe.useState(null),s=oe.useRef(null);return oe.useEffect(()=>{const o=s.current;if(o===null)return;if(typeof IntersectionObserver>"u"){n(ZS(e));return}const r=new IntersectionObserver(i=>{i.some(l=>l.isIntersecting)&&(n(ZS(e)),r.disconnect())},{rootMargin:"120px"});return r.observe(o),()=>r.disconnect()},[e]),w.jsx("div",{ref:s,className:"stu-thumb","aria-hidden":"true",children:t!==null&&t!==""?w.jsx("div",{className:"docskin stu-thumb-doc",style:{width:LZ,transform:`scale(${IZ})`},dangerouslySetInnerHTML:{__html:t}}):w.jsx("div",{className:"stu-thumb-blank",children:e})})}const PZ=9,dE=420,uE=420,OZ=new Map(td.map(e=>[e.id,e.label]));function iN(e){const t=ke.getState(),{doc:n}=id(t.source,t.currentSlug??"untitled");return NZ(e,t.selection,n.segments.length)}function aN(e,t,n){const s=ke.getState();if(s.currentSlug===null)return;const o=iN(e);s.mode!=="edit"&&s.setMode("edit"),s.closePicker(),iC(o,t,n)}function lN({pinned:e}){const t=ke(n=>n.currentSlug);return w.jsxs("button",{type:"button",className:"stu-picker-import",disabled:t===null,title:t===null?"Open a doc first":void 0,onClick:()=>{const n=ke.getState(),s=iN(e);n.mode!=="edit"&&n.setMode("edit"),n.closePicker(),kY(s)},children:[w.jsx(LC,{size:13}),"Import from file…",w.jsx("span",{className:"stu-picker-import-hint",children:".csv → block · OpenAPI .yaml/.json → new doc"})]})}function RZ({picker:e,query:t,setQuery:n}){const s=ke(v=>v.closePicker),o=ke(v=>v.expandPicker),[r,i]=oe.useState(0),l=oe.useRef(null),d=oe.useRef(null),u=oe.useRef(null),p=oe.useMemo(()=>EZ(t,PZ),[t]);oe.useEffect(()=>{requestAnimationFrame(()=>l.current?.focus())},[]),oe.useEffect(()=>i(0),[t]),oe.useEffect(()=>{const v=d.current?.children[r];v instanceof HTMLElement&&v.scrollIntoView({block:"nearest"})},[r]),oe.useEffect(()=>{const v=y=>{u.current!==null&&!u.current.contains(y.target)&&s()};return window.addEventListener("mousedown",v),()=>window.removeEventListener("mousedown",v)},[s]);const h=v=>aN(e.index,v.type,sN(v)),m=v=>{if(v.key==="Escape"){v.preventDefault(),v.stopPropagation(),s();return}if(v.key==="ArrowDown"){v.preventDefault(),i(y=>Math.min(y+1,p.length-1));return}if(v.key==="ArrowUp"){v.preventDefault(),i(y=>Math.max(y-1,0));return}if(v.key==="Enter"){v.preventDefault();const y=p[r];y!==void 0&&h(y)}},g=oe.useMemo(()=>{const v=e.anchor;if(v===null)return;const y=window.innerWidth,b=window.innerHeight,E=Math.min(Math.max(v.x-dE/2,12),Math.max(12,y-dE-12)),$=v.y+10,A=$+uE>b-12?Math.max(12,v.y-uE-14):$;return{left:E,top:A}},[e.anchor]);return w.jsxs("div",{className:`stu-picker-compact ${e.anchor===null?"stu-picker-compact-centered":""}`,ref:u,...g!==void 0?{style:g}:{},role:"dialog","aria-label":"Insert a block",children:[w.jsxs("div",{className:"stu-picker-search",children:[w.jsx(Of,{size:14}),w.jsx("input",{ref:l,type:"text",placeholder:`Search ${Wi.length} block types…`,value:t,onChange:v=>n(v.target.value),onKeyDown:m}),w.jsx("kbd",{children:"esc"})]}),w.jsxs("ul",{className:"stu-picker-list",ref:d,role:"listbox",children:[p.map((v,y)=>w.jsx("li",{children:w.jsxs("button",{type:"button",role:"option","aria-selected":y===r,className:`stu-picker-item ${y===r?"stu-picker-item-active":""}`,onMouseEnter:()=>i(y),onClick:()=>h(v),children:[w.jsx("span",{className:"stu-picker-item-name",children:v.label}),w.jsx("span",{className:"stu-card-type",children:v.type}),w.jsx("span",{className:"stu-picker-item-fam",children:v.familyLabel})]})},v.alias??v.type)),p.length===0&&w.jsx("li",{className:"stu-picker-none",children:"No matching blocks"})]}),w.jsxs("div",{className:"stu-picker-foot",children:[w.jsx(lN,{pinned:e.index}),w.jsxs("button",{type:"button",className:"stu-picker-import",onClick:o,children:[w.jsx(yx,{size:13}),"Browse all blocks",w.jsx("span",{className:"stu-picker-import-hint",children:"gallery with previews →"})]})]})]})}function DZ(e){return Array.from(e.querySelectorAll('button, input, [tabindex="0"]')).filter(t=>t.tabIndex>=0&&!t.hasAttribute("disabled")&&t.offsetParent!==null)}function cN(e,t){if(e.key!=="Tab"||t===null)return;const n=DZ(t),s=n[0],o=n[n.length-1];if(s===void 0||o===void 0)return;const r=document.activeElement;e.shiftKey&&(r===s||!t.contains(r))?(e.preventDefault(),o.focus()):!e.shiftKey&&r===o&&(e.preventDefault(),s.focus())}function BZ(e){if(e===null)return 1;const t=Array.from(e.children),n=t[0];return n===void 0?1:Math.max(1,t.filter(s=>s.offsetTop===n.offsetTop).length)}function zZ({hit:e,index:t,roving:n,onOpen:s,onRove:o}){return w.jsxs("button",{type:"button",className:"stu-card stu-picker-card","data-libcard":t,tabIndex:n?0:-1,onFocus:()=>o(t),onClick:()=>s(e),"aria-label":`${e.item.label} (${e.item.type}) — open details`,"aria-haspopup":"dialog",children:[w.jsx(jZ,{type:e.item.type}),w.jsxs("span",{className:"stu-card-head",children:[w.jsx("span",{className:"stu-card-name",children:e.item.label}),w.jsx("span",{className:"stu-card-type",children:e.item.type})]}),w.jsx("span",{className:"stu-card-desc",children:e.item.description}),e.alias!==void 0&&w.jsxs("span",{className:"stu-picker-also",children:["also: ",e.alias]})]})}function FZ({hit:e,canInsert:t,onClose:n,onInsert:s}){const o=Ah(),r=oe.useRef(null),i=oe.useRef(null),[l,d]=oe.useState(!1),u=oe.useMemo(()=>rN(e),[e]),p=oe.useMemo(()=>GC(e.item.type,u).trimEnd(),[e,u]),h=oe.useMemo(()=>z0(e.item.type,u),[e,u]);oe.useEffect(()=>{requestAnimationFrame(()=>i.current?.focus())},[]),oe.useEffect(()=>{if(!l)return;const g=setTimeout(()=>d(!1),1600);return()=>clearTimeout(g)},[l]);const m=()=>{navigator.clipboard?.writeText(p+`
3260
+ `).then(()=>d(!0),()=>{})};return w.jsx("div",{className:"stu-picker-detail-backdrop",onMouseDown:g=>{r.current!==null&&!r.current.contains(g.target)&&n()},children:w.jsxs("div",{className:"stu-picker-detail",ref:r,role:"dialog","aria-modal":"true","aria-label":`${e.item.label} block details`,onKeyDown:g=>{if(g.key==="Enter"&&(g.metaKey||g.ctrlKey)&&t){g.preventDefault(),s(e);return}cN(g,r.current)},children:[w.jsxs("header",{className:"stu-picker-detail-head",children:[w.jsxs("div",{className:"stu-picker-detail-title",children:[w.jsx("h3",{children:e.item.label}),w.jsx("span",{className:"stu-card-type",children:e.item.type}),w.jsx("span",{className:"stu-picker-detail-fam",children:e.item.familyLabel})]}),w.jsx("button",{type:"button",className:"stu-picker-x","aria-label":"Close details",onClick:n,children:w.jsx(Rf,{size:13})})]}),w.jsx("p",{className:"stu-picker-detail-desc",children:e.item.description}),e.alias!==void 0&&w.jsxs("p",{className:"stu-picker-detail-alias",children:["also answers to: ",w.jsx("code",{children:e.alias}),cE(e.alias)!==""&&w.jsxs(w.Fragment,{children:[" — inserts as ",w.jsx("code",{children:cE(e.alias)})]})]}),w.jsxs("div",{className:"stu-picker-detail-body",children:[w.jsxs("div",{className:"stu-picker-pane stu-picker-pane-preview",children:[w.jsx("div",{className:"stu-picker-pane-label",children:"Preview"}),w.jsx("div",{className:"stu-picker-preview","data-doc-theme":Mh(o),children:h.html!==""?w.jsx("div",{className:"docskin stu-picker-preview-doc",dangerouslySetInnerHTML:{__html:h.html}}):w.jsx("div",{className:"stu-picker-preview-blank",children:e.item.type})})]}),w.jsxs("div",{className:"stu-picker-pane stu-picker-pane-yaml",children:[w.jsxs("div",{className:"stu-picker-pane-label",children:["Template",w.jsxs("button",{type:"button",className:"stu-picker-copy",onClick:m,children:[w.jsx(TC,{size:12}),l?"Copied":"Copy"]})]}),w.jsx("pre",{className:"stu-picker-yaml",tabIndex:0,children:p})]})]}),w.jsxs("footer",{className:"stu-picker-detail-foot",children:[w.jsx("span",{className:"stu-picker-detail-hint",children:"⏎ insert · esc back to the gallery"}),w.jsx("button",{type:"button",className:"stu-btn",onClick:n,children:"Close"}),w.jsx("button",{ref:i,type:"button",className:"stu-btn stu-btn-primary",disabled:!t,title:t?"Insert into the doc":"Open a doc first",onClick:()=>s(e),children:"Insert into doc"})]})]})})}function qZ({picker:e,query:t,setQuery:n}){const s=ke(O=>O.closePicker),o=ke(O=>O.currentSlug),[r,i]=oe.useState("all"),[l,d]=oe.useState(null),[u,p]=oe.useState(0),h=oe.useRef(null),m=oe.useRef(null),g=oe.useRef(null),v=oe.useRef(null);v.current=l;const y=oe.useMemo(()=>AZ(t,r),[t,r]),b=oe.useMemo(()=>y.groups.flatMap(O=>O.hits),[y]),E=oe.useRef(0);E.current=u;const $=O=>{const C=h.current?.querySelector(`[data-libcard="${O}"]`);C?.focus(),C?.scrollIntoView({block:"nearest"})},A=oe.useMemo(()=>({css:Zi(ys("","picker-skin")).css}),[]);oe.useEffect(()=>(g.current=document.activeElement instanceof HTMLElement?document.activeElement:null,requestAnimationFrame(()=>m.current?.focus()),()=>g.current?.focus()),[]),oe.useEffect(()=>p(0),[t,r]),oe.useEffect(()=>{const O=C=>{C.key==="Escape"&&(C.preventDefault(),C.stopPropagation(),v.current!==null?(d(null),requestAnimationFrame(()=>$(E.current))):s())};return window.addEventListener("keydown",O,!0),()=>window.removeEventListener("keydown",O,!0)},[s]);const T=O=>d(O),N=()=>{d(null),requestAnimationFrame(()=>$(E.current))},j=O=>aN(e.index,O.item.type,rN(O)),P=O=>{const C=O.target,D=C.getAttribute("data-libcard");if(D===null||!TZ(O.key))return;O.preventDefault();const F=BZ(C.parentElement),U=_Z(Number(D),O.key,F,b.length);p(U),$(U)},I=(O,C,D)=>w.jsxs("button",{type:"button",className:`stu-picker-pill ${r===O?"stu-picker-pill-active":""} ${D===0?"stu-picker-pill-empty":""}`,"aria-pressed":r===O,onClick:()=>i(r===O?"all":O),children:[C,w.jsx("span",{className:"stu-picker-pill-count",children:D})]},O);return w.jsx("div",{className:"stu-picker-backdrop",children:w.jsxs("div",{className:"stu-picker-browse",ref:h,role:"dialog","aria-modal":"true","aria-label":"Block library",onKeyDown:O=>{l===null&&cN(O,h.current)},children:[w.jsx("style",{children:A.css}),w.jsxs("header",{className:"stu-picker-head",children:[w.jsxs("div",{className:"stu-picker-title",children:[w.jsx("span",{className:"stu-picker-title-icon",children:w.jsx(yx,{size:16})}),w.jsx("h2",{children:"Block library"}),w.jsxs("span",{className:"stu-picker-title-count",children:["· ",y.total," blocks"]}),w.jsx("button",{type:"button",className:"stu-picker-x","aria-label":"Close the block library",onClick:s,children:w.jsx(Rf,{size:14})})]}),w.jsxs("div",{className:"stu-picker-browse-search",children:[w.jsx(Of,{size:14}),w.jsx("input",{ref:m,type:"text",placeholder:"Search blocks — try “waterfall”, “diagram”, “api”…","aria-label":"Search blocks",value:t,onChange:O=>n(O.target.value),onKeyDown:O=>{(O.key==="Enter"||O.key==="ArrowDown")&&b.length>0&&(O.preventDefault(),$(0))}}),w.jsxs("span",{className:"stu-picker-showing","aria-live":"polite",children:["Showing ",y.shown," of ",y.total]})]}),w.jsxs("div",{className:"stu-picker-pills",role:"group","aria-label":"Filter by family",children:[I("all","All",y.matched),[...y.familyCounts].map(([O,C])=>I(O,OZ.get(O)??O,C))]})]}),w.jsx("div",{className:"stu-picker-body",onKeyDown:P,children:b.length===0?w.jsxs("div",{className:"stu-picker-empty",children:["Nothing matches “",t.trim(),"”",r!=="all"?" in this family":""," — try another word or clear the search."]}):(()=>{let O=0;return y.groups.map(C=>{const D=O;return O+=C.hits.length,w.jsxs("section",{className:"stu-picker-fam","aria-label":C.label,children:[w.jsxs("div",{className:"stu-picker-famhead",children:[C.label,w.jsx("span",{className:"stu-picker-count",children:C.hits.length})]}),w.jsx("div",{className:"stu-cardgrid stu-picker-grid",children:C.hits.map((F,U)=>w.jsx(zZ,{hit:F,index:D+U,roving:D+U===u,onOpen:T,onRove:p},F.item.type))})]},C.family)})})()}),w.jsx("div",{className:"stu-picker-foot",children:w.jsx(lN,{pinned:e.index})}),l!==null&&w.jsx(FZ,{hit:l,canInsert:o!==null,onClose:N,onInsert:j})]})})}function HZ({picker:e}){const[t,n]=oe.useState("");return e.view==="compact"?w.jsx(RZ,{picker:e,query:t,setQuery:n}):w.jsx(qZ,{picker:e,query:t,setQuery:n})}function WZ(){const e=ke(t=>t.picker);return e===null?null:w.jsx(HZ,{picker:e})}const yo="tutorial-playground",UZ="```meta\ntitle: Tutorial playground\nsubtitle: A scratch doc for the studio tour — yours to keep or delete.\ntag: TUTORIAL\n```\n",so=[{id:"welcome",target:'[data-tour="topbar"]',title:"Welcome to Chiltepin Studio",body:"This is a visual editor over plain Markdown files — every edit you make here rewrites a fenced YAML block in a real file on disk. The files stay the single source of truth; the studio is just a nicer pair of hands. You are in a scratch doc, so play freely.",advance:null},{id:"insert",target:'[data-tour="canvas"]',title:"Insert your first block",body:'Press / to open the insert menu, type "seq", and hit ⏎ to insert a Sequence diagram. Every one of the 107 block types inserts this way.',keys:["/","type seq","⏎"],advance:"insert"},{id:"fill",target:".stu-sheet-form",title:"Fill it in — no YAML required",body:"The sheet is a real form over the block's schema. Type a title, then ride the rhythm: ⇥ hops fields, ⏎ moves through rows and adds new ones when you run off the end. Commit any field to continue.",keys:["type a title","⇥ next field","⏎ next row"],advance:"field-commit",needsSheet:!0},{id:"done",target:".stu-sheet-actions",title:"Done — one clean edit",body:"Press ⌘⏎ (or click Done). The whole sheet session lands as ONE edit — one undo step, one autosave, one surgical rewrite of the block in your file.",keys:["⌘⏎"],advance:"sheet-done",needsSheet:!0},{id:"part",target:'[data-seg="1"]',title:"Click a diagram part",body:"Diagrams are directly editable. Click any part of the diagram — an actor, an arrow — to select just that part. (⇥ also cycles through parts.)",keys:["click a part","⇥ cycles"],advance:"part-select",needsBlock:!0},{id:"move",target:'[data-seg="1"]',title:"Move it with the arrows",body:"With a part selected, plain arrow keys move it: list items reorder, grid nodes hop cells, table cells navigate. Try ← or → on your selected part.",keys:["←","→"],advance:"part-move",needsBlock:!0},{id:"micro",target:'[data-seg="1"]',title:"Edit in place, escape out",body:"Press ⏎ to open the micro-editor for exactly that value — edit it, then Esc to close. Esc always pops out one level: editor → part → block → canvas.",keys:["⏎ edit","esc close"],advance:"micro-close",needsBlock:!0},{id:"save",target:'[data-tour="save"]',title:"Saving is automatic",body:`The status text by the Save button tracks the file: "unsaved changes" while you type, "saved" when the write lands (about a second later). Prefer to review first? Flip Autosave off in the rail's Settings and ⌘S opens a review of every change before anything touches the disk.`,keys:["⌘S"],advance:null},{id:"finish",target:'[data-tour="topbar"]',title:"That's the tour",body:"Share ▾ copies a link or exports the document as HTML, slides or PDF; Present shows it as a deck. Press ? anytime for every keyboard shortcut, and the README covers the full block catalog.",keys:["?"],advance:null}],H0={status:"idle",step:0};function pE(e){return e>=so.length-1?{status:"finished",step:so.length-1}:{status:"running",step:e+1}}function KZ(e,t){switch(t.type){case"start":return{status:"running",step:0};case"skip":return e.status==="idle"?e:H0;case"close":return H0;case"next":return e.status==="running"?pE(e.step):e;case"back":return e.status==="running"?{status:"running",step:Math.max(0,e.step-1)}:e;case"action":{if(e.status!=="running")return e;const n=so[e.step];return n!==void 0&&n.advance===t.action?pE(e.step):e}case"break":return e.status==="running"?{status:"interrupted",step:e.step}:e;case"resume":return e.status==="interrupted"?{status:"running",step:Math.max(0,Math.min(t.step,so.length-1))}:e}}function VZ(e){const t=so[e.current];if(t===void 0)return 0;const n=so.findIndex(o=>o.id==="insert"),s=so.findIndex(o=>o.id==="part");return t.needsSheet===!0&&!e.sheetOpen?e.hasBlock?s:n:t.needsBlock===!0&&!e.hasBlock?n:e.current}const GZ="chiltepin-studio-tour";function fE(e){try{window.localStorage.setItem(GZ,e)}catch{}}const YZ=`tone: success
3261
3261
  title: Tour complete 🎉
3262
3262
  body: >-
3263
3263
  This scratch doc is a real file — docs/tutorial-playground.md — and it is
3264
3264
  yours. The studio deliberately has no delete button (files are the source
3265
3265
  of truth), so remove the file from disk whenever you are done with it.
3266
- `;let Ac=null;const Ic=vE()((e,t)=>{const n=s=>{const o=t().state,r=UZ(o,s);if(r===o)return;e({state:r});const i=r.status==="running"||r.status==="interrupted";i&&Ac===null?Ac=FG(l=>t().dispatch({type:"action",action:l})):!i&&Ac!==null&&(Ac(),Ac=null),r.status==="finished"&&fE("done"),s.type==="skip"&&fE("dismissed")};return{state:H0,dispatch:n,start:async()=>{const s=ke.getState();s.setMode("edit"),s.currentSlug!==yo&&(s.docs.some(r=>r.slug===yo)?await s.openDoc(yo):await s.newDoc(yo,WZ)),ke.getState().closeSheet(),n({type:"start"})},skip:()=>n({type:"skip"}),addFarewell:()=>{const s=ke.getState();s.currentSlug===yo&&s.applyOp((o,r)=>Sy(o,r,r.segments.length,"callout",GZ),null)}}}),Hf="chiltepin-studio-shortcutbar-dismissed",YZ=["chiltepin-studio-hint-dismissed","chiltepin-studio-direct-hint-dismissed"];function XZ(){try{let e=window.localStorage.getItem(Hf)==="1";for(const t of YZ)window.localStorage.getItem(t)!==null&&(e=!0,window.localStorage.removeItem(t));return e&&window.localStorage.setItem(Hf,"1"),e}catch{return!0}}const QZ=[{title:"Canvas",rows:[{keys:"↑ ↓ · j k",label:"select block"},{keys:"⏎",label:"edit selection"},{keys:"⌘D",label:"duplicate"},{keys:"⌘↑ ⌘↓",label:"move block"},{keys:"⌫",label:"delete block"},{keys:"⌘Z / ⇧⌘Z",label:"undo / redo"},{keys:"esc",label:"deselect"}]},{title:"Diagram parts",rows:[{keys:"click · ⇥",label:"select a part (⇥ cycles)"},{keys:"⏎ · dbl-click",label:"edit the selected part"},{keys:"←↑↓→",label:"move it — grid cell / reorder · table cells: navigate"},{keys:"⌫",label:"delete the selected item"},{keys:"esc",label:"back to the block"},{keys:"drag",label:"move with the pointer"},{keys:"drag a dot",label:"connect nodes — drop on empty space to add one"},{keys:"D",label:"pen mode — draw a shape to add the node it means"},{keys:"right-click · ⇧F10",label:"menu — add / kind / group / wrap / delete"},{keys:"n",label:"sequence message: add / edit its numbered step note"},{keys:"⌥←↑↓→",label:"nudge the hovered part"}]},{title:"Editor",rows:[{keys:"⇥ / ⇧⇥",label:"next / previous field"},{keys:"⏎",label:"next field · new row on the last one"},{keys:"⏎ (empty row)",label:"leave the list"},{keys:"⌘⏎",label:"done — inside a text area: next"},{keys:"type · ↑↓ · ⏎",label:"filter and pick in dropdowns"},{keys:"esc",label:"cancel"}]},{title:"Insert",rows:[{keys:"/",label:"insert after selection"},{keys:"type",label:"filter block types"},{keys:"⏎",label:"insert and start typing"},{keys:"+",label:"hover a gap between blocks — same picker, pinned there"},{keys:"Library",label:"browse every block — the picker footer, or the top bar"}]},{title:"Studio",rows:[{keys:"rail",label:"docs by folder · New doc · All documents · Settings (autosave)"},{keys:"⌘K",label:"search docs — opens the rail drawer on narrow windows"},{keys:"check chip",label:"validation results — rows jump to the block & field"},{keys:"⌘S",label:"save now — with autosave off, review first"},{keys:"⇧⌘P",label:"Present — the current doc as slides · esc returns"},{keys:"Share ▾",label:"copy link · export HTML / slides / PDF · open the site"}]}];function ZZ(){const e=ke(T=>T.sheet!==null),t=ke(T=>T.selection!==null),n=ke(T=>T.selection),{doc:s,rendered:o}=Co(),[r,i]=oe.useState(XZ),[l,d]=oe.useState(!1);oe.useEffect(()=>{const T=N=>{if(N.key==="?"&&!N.metaKey&&!N.ctrlKey&&!wl(N.target)){N.preventDefault(),N.stopPropagation(),d(j=>!j),i(!1);try{window.localStorage.removeItem(Hf)}catch{}return}N.key==="Escape"&&l&&(N.preventDefault(),N.stopPropagation(),d(!1))};return window.addEventListener("keydown",T,!0),()=>window.removeEventListener("keydown",T,!0)},[l]);const u=ke(T=>T.partSel),p=u!==null,h=ke(T=>T.mode),m=h!=="edit"?h:e?"sheet":p?"part":t?"canvas-selected":"canvas",g=n!==null?s.segments[n]:void 0,v=g!==void 0&&g.kind!=="markdown"&&g.kind!=="meta"&&EG(g.kind,g.data),y=n!==null&&(o?.segments[n]?.html.includes("data-bp")??!1),b=u!==null?s.segments[u.seg]:void 0,E=b!==void 0&&b.kind!=="markdown"?$n(b.kind):null,$=u!==null&&E!==null&&Af(E,u.path)!==null,A=()=>{i(!0);try{window.localStorage.setItem(Hf,"1")}catch{}};return w.jsxs(w.Fragment,{children:[!r&&w.jsxs("div",{className:"stu-keybar",role:"note","data-ctx":m,"data-tour":"keybar",children:[aY(m,{dragParts:v,connectDots:$,parts:y}).map(T=>w.jsxs("span",{className:"stu-keybar-hint",children:[w.jsx("kbd",{children:T.keys})," ",T.label]},T.keys)),w.jsx("button",{type:"button",className:"stu-keybar-x","aria-label":"Hide shortcuts bar (press ? to bring it back)",onClick:A,children:w.jsx(Rf,{size:10})})]}),l&&w.jsx("div",{className:"stu-keys-backdrop",onMouseDown:()=>d(!1),children:w.jsxs("div",{className:"stu-keys-card",role:"dialog","aria-label":"Keyboard shortcuts",onMouseDown:T=>T.stopPropagation(),children:[w.jsxs("header",{children:[w.jsx("h2",{children:"Keyboard shortcuts"}),w.jsx("button",{type:"button","aria-label":"Close",onClick:()=>d(!1),children:w.jsx(Rf,{size:12})})]}),w.jsx("div",{className:"stu-keys-cols",children:QZ.map(T=>w.jsxs("section",{children:[w.jsx("h3",{children:T.title}),T.rows.map(N=>w.jsxs("div",{className:"stu-keys-row",children:[w.jsx("kbd",{children:N.keys}),w.jsx("span",{children:N.label})]},N.keys))]},T.title))}),w.jsxs("footer",{children:["press ",w.jsx("kbd",{children:"?"})," anytime to toggle this card",w.jsx("button",{type:"button",className:"stu-keys-tour",onClick:()=>{d(!1),Ic.getState().start()},children:"▸ Take the interactive tour"})]})]})})]})}function JZ(){const e=ke(n=>n.toasts),t=ke(n=>n.dismissToast);return e.length===0?null:w.jsx("div",{className:"stu-toasts",role:"status",children:e.map(n=>w.jsxs("div",{className:`stu-toast stu-toast-${n.tone}`,children:[w.jsx("span",{children:n.message}),w.jsx("button",{type:"button","aria-label":"Dismiss",onClick:()=>t(n.id),children:"×"})]},n.id))})}function eJ(){return ke(t=>t.updateAvailable)?w.jsxs("div",{className:"stu-update",role:"status",children:[w.jsx("span",{children:"Studio was updated —"}),w.jsx("button",{type:"button",className:"stu-update-btn",onClick:()=>window.location.reload(),children:"Reload"})]}):null}function tJ(){const e=ke(n=>n.conflict),t=ke(n=>n.resolveConflict);return e===null?null:w.jsxs("div",{className:"stu-conflict",role:"alertdialog","aria-label":"File changed on disk",children:[w.jsxs("div",{className:"stu-conflict-msg",children:[w.jsx("strong",{children:"This file changed on disk."}),w.jsx("span",{children:"Your unsaved edits overlap with the change."})]}),w.jsxs("div",{className:"stu-conflict-actions",children:[w.jsx("button",{type:"button",className:"stu-btn",onClick:()=>t("theirs"),children:"Reload theirs"}),w.jsx("button",{type:"button",className:"stu-btn stu-btn-primary",onClick:()=>t("mine"),children:"Keep mine"})]})]})}function Cx(e){return e.split("/").pop()??e}function Nx(e,t,n){const s=URL.createObjectURL(new Blob([t],{type:n})),o=document.createElement("a");o.href=s,o.download=e,document.body.appendChild(o),o.click(),o.remove(),URL.revokeObjectURL(s)}function nJ(e,t){Nx(`${Cx(t)}.html`,UA(e),"text/html;charset=utf-8")}function sJ(e,t){Nx(`${Cx(t)}.slides.html`,KA(e),"text/html;charset=utf-8")}async function oJ(e,t){await rJ("pdf",UA(e),`${Cx(t)}.pdf`,"PDF")}async function rJ(e,t,n,s){const o=await fetch(`/api/export/${e}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({html:t})});if(!o.ok){let r=`${s} export failed (${o.status})`;try{const i=await o.json();typeof i.error=="string"&&(r=i.error)}catch{}throw new Error(r)}Nx(n,await o.blob(),"application/pdf")}function dN(e,t,n){oe.useEffect(()=>{if(!e)return;const s=r=>{t.current!==null&&!t.current.contains(r.target)&&n()},o=r=>{r.key==="Escape"&&(r.stopPropagation(),n())};return window.addEventListener("mousedown",s),window.addEventListener("keydown",o,!0),()=>{window.removeEventListener("mousedown",s),window.removeEventListener("keydown",o,!0)}},[e,t,n])}function iJ({row:e,onOpen:t}){return w.jsxs("div",{className:`stu-checkrow stu-checkrow-${e.level}`,children:[w.jsx("span",{className:"stu-checkrow-code",children:e.code}),w.jsxs("span",{className:"stu-checkrow-msg",children:[e.message,e.line!==null&&w.jsxs("span",{className:"stu-checkrow-line",children:[" · line ",e.line]}),e.hint!==null&&w.jsx("span",{className:"stu-checkrow-hint",children:e.hint})]}),e.segIndex!==null&&w.jsx("button",{type:"button",className:"stu-checkrow-open",onClick:()=>t(e),children:e.segKind==="markdown"?"Open block →":"Open field →"})]})}function aJ(){const e=ke(h=>h.source),{doc:t,diagnostics:n}=Co(),[s,o]=oe.useState(!1),r=oe.useRef(null);dN(s,r,()=>o(!1));const{errors:i,warnings:l}=VC(n),d=oe.useMemo(()=>s?IQ(e,t,n):[],[s,e,t,n]),u=h=>{if(o(!1),h.segIndex===null)return;const m=ke.getState();if(h.segKind==="markdown"){m.select(h.segIndex),document.querySelector(`[data-seg="${h.segIndex}"]`)?.scrollIntoView({block:"center",behavior:"smooth"});return}m.openSheet(h.segIndex,!1,h.field??void 0)},p=i>0?`${i} error${i===1?"":"s"}`:"pass";return w.jsxs("div",{className:"stu-checkwrap",ref:r,children:[w.jsxs("button",{type:"button",className:`stu-checkchip ${i>0?"stu-checkchip-err":"stu-checkchip-ok"}`,"aria-haspopup":"dialog","aria-expanded":s,title:i>0?`${p} — click for details`:"chiltepin check passes — click for details",onClick:()=>o(!s),children:[i===0&&w.jsx(_C,{size:10}),p,w.jsx("span",{className:"stu-checkchip-caret","aria-hidden":"true",children:"▾"})]}),s&&w.jsxs("div",{className:"stu-checkpop",role:"dialog","aria-label":"Check results",children:[w.jsx("span",{className:"stu-checkpop-caret","aria-hidden":"true"}),w.jsxs("header",{className:"stu-checkpop-head",children:[w.jsx("b",{children:"chiltepin check"}),i>0&&w.jsxs("span",{className:"stu-checkpop-chip stu-checkpop-chip-err",children:[i," error",i===1?"":"s"]}),l>0&&w.jsxs("span",{className:"stu-checkpop-chip stu-checkpop-chip-warn",children:[l," warning",l===1?"":"s"]}),i===0&&l===0&&w.jsx("span",{className:"stu-checkpop-chip stu-checkpop-chip-ok",children:"✓ pass"})]}),w.jsx("div",{className:"stu-checkpop-rows",children:d.length===0?w.jsx("div",{className:"stu-checkpop-empty",children:"No issues — this doc publishes clean."}):d.map((h,m)=>w.jsx(iJ,{row:h,onOpen:u},m))}),w.jsxs("footer",{className:"stu-checkpop-foot",children:[w.jsx("span",{children:"Errors block publish · warnings never do"}),w.jsx("span",{className:"stu-checkpop-ran",children:"checked live"})]})]})]})}function lJ(){const e=ke(g=>g.docs),t=ke(g=>g.currentSlug),{diagnostics:n}=Co(),[s,o]=oe.useState(!1),r=oe.useRef(null);dN(s,r,()=>o(!1));const i=n.filter(g=>g.level==="error").length,l=oe.useMemo(()=>e.map(g=>({doc:g,status:Ax(g,{slug:t,errors:i})})),[e,t,i]),d=l.some(g=>g.status.kind!=="unknown");if(e.length===0||!d)return null;const u=l.filter(g=>g.status.kind==="errors"),p=u.reduce((g,v)=>g+v.status.count,0),h=g=>{o(!1);const v=ke.getState();v.openDoc(g),v.setMode("edit")},m=p>0?`${p} error${p===1?"":"s"}`:"pass";return w.jsxs("div",{className:"stu-checkwrap",ref:r,children:[w.jsxs("button",{type:"button",className:`stu-checkchip ${p>0?"stu-checkchip-err":"stu-checkchip-ok"}`,"aria-haspopup":"dialog","aria-expanded":s,title:p>0?`${u.length} doc${u.length===1?"":"s"} failing — click for the list`:"chiltepin check passes across all docs",onClick:()=>o(!s),children:[p===0&&w.jsx(_C,{size:10}),m,w.jsx("span",{className:"stu-checkchip-caret","aria-hidden":"true",children:"▾"})]}),s&&w.jsxs("div",{className:"stu-checkpop",role:"dialog","aria-label":"Check results, all documents",children:[w.jsx("span",{className:"stu-checkpop-caret","aria-hidden":"true"}),w.jsxs("header",{className:"stu-checkpop-head",children:[w.jsx("b",{children:"chiltepin check"}),p>0?w.jsxs("span",{className:"stu-checkpop-chip stu-checkpop-chip-err",children:[p," error",p===1?"":"s"," · ",u.length," doc",u.length===1?"":"s"]}):w.jsx("span",{className:"stu-checkpop-chip stu-checkpop-chip-ok",children:"✓ pass"})]}),w.jsx("div",{className:"stu-checkpop-rows",children:u.length===0?w.jsx("div",{className:"stu-checkpop-empty",children:"All documents publish clean."}):u.map(g=>w.jsxs("button",{type:"button",className:"stu-checkpop-docrow",title:g.doc.slug,onClick:()=>h(g.doc.slug),children:[w.jsx("span",{className:"stu-checkpop-docname",children:g.doc.title}),w.jsxs("span",{className:"stu-checkpop-doccount",children:[g.status.count," error",g.status.count===1?"":"s"]})]},g.doc.slug))}),w.jsxs("footer",{className:"stu-checkpop-foot",children:[w.jsx("span",{children:"Errors block publish · warnings never do"}),w.jsx("span",{className:"stu-checkpop-ran",children:"checked live"})]})]})]})}function cJ(){const e=ke(t=>t.openLibrary);return w.jsxs("button",{type:"button",className:"stu-libbtn",title:"Browse all block types",onClick:e,children:[w.jsx(yx,{size:13}),"Library"]})}function uN(e,t,n){oe.useEffect(()=>{if(!e)return;const s=r=>{t.current!==null&&!t.current.contains(r.target)&&n()},o=r=>{r.key==="Escape"&&(r.stopPropagation(),n())};return window.addEventListener("mousedown",s),window.addEventListener("keydown",o,!0),()=>{window.removeEventListener("mousedown",s),window.removeEventListener("keydown",o,!0)}},[e,t,n])}function pN({onDone:e}){const t=ke(h=>h.currentSlug),n=ke(h=>h.toast),{doc:s}=Co(),[o,r]=oe.useState(!1),i=async h=>{const{source:m,docs:g,currentSlug:v}=ke.getState(),y=g.find(b=>b.slug===v)?.title;try{const b=await kB(window.location.href.split(/[?#]/)[0]??"/",m,{present:h,...y!==void 0?{title:y}:{}});if(b.length>mB){n("This document is too big to share as a link — export it instead","error");return}await navigator.clipboard.writeText(b),n(h?"Deck link copied":"Share link copied","info"),e()}catch(b){n(`Could not build a share link: ${b.message}`,"error")}},l=t??"document",d=()=>{nJ(s,l),n("Exported HTML page","info"),e()},u=()=>{sJ(s,l),n("Exported slide deck","info"),e()},p=async()=>{r(!0);try{await oJ(s,l),n("Exported PDF","info"),e()}catch(h){n(`PDF export failed: ${h.message}`,"error")}finally{r(!1)}};return w.jsxs(w.Fragment,{children:[w.jsx("button",{type:"button",role:"menuitem",className:"stu-export-item",onClick:()=>{i(!1)},children:"Copy link"}),w.jsx("button",{type:"button",role:"menuitem",className:"stu-export-item",onClick:()=>{i(!0)},children:"Copy deck link"}),w.jsx("div",{className:"stu-export-sep",role:"separator"}),w.jsx("button",{type:"button",role:"menuitem",className:"stu-export-item",onClick:d,children:"Export HTML page"}),w.jsx("button",{type:"button",role:"menuitem",className:"stu-export-item",onClick:u,children:"Export slide deck"}),jy&&w.jsxs(w.Fragment,{children:[w.jsx("button",{type:"button",role:"menuitem",className:"stu-export-item",disabled:o,onClick:()=>{p()},children:o?"Exporting PDF…":"Export PDF"}),w.jsx("div",{className:"stu-export-sep",role:"separator"}),w.jsx("a",{className:"stu-export-item",role:"menuitem",href:t!==null?`/site/${t}.html`:"/site/",target:"_blank",rel:"noreferrer",onClick:e,children:"Open site ↗"})]})]})}function dJ(){const e=ke(o=>o.currentSlug),[t,n]=oe.useState(!1),s=oe.useRef(null);return uN(t,s,()=>n(!1)),w.jsxs("div",{className:"stu-export",ref:s,children:[w.jsxs("button",{type:"button",className:"stu-libbtn",disabled:e===null,"aria-haspopup":"menu","aria-expanded":t,title:"Share, export, or open the site",onClick:()=>n(!t),children:["Share",w.jsx(xX,{size:11})]}),t&&w.jsx("div",{className:"stu-export-pop",role:"menu",children:w.jsx(pN,{onDone:()=>n(!1)})})]})}function uJ(){const e=ke(d=>d.mode),t=ke(d=>d.setMode),n=ke(d=>d.openLibrary),s=ke(d=>d.currentSlug),[o,r]=oe.useState(!1),i=oe.useRef(null);uN(o,i,()=>r(!1));const l=e!=="home"&&s!==null;return w.jsxs("div",{className:"stu-export stu-topbar-more",ref:i,children:[w.jsx("button",{type:"button",className:"stu-libbtn stu-morebtn","aria-label":"More actions","aria-haspopup":"menu","aria-expanded":o,title:"More actions",onClick:()=>r(!o),children:"⋯"}),o&&w.jsxs("div",{className:"stu-export-pop",role:"menu",children:[e==="edit"&&w.jsx("button",{type:"button",role:"menuitem",className:"stu-export-item",onClick:()=>{r(!1),n()},children:"Block library"}),l&&w.jsx("button",{type:"button",role:"menuitem",className:"stu-export-item",onClick:()=>{r(!1),t(e==="present"?"edit":"present")},children:e==="present"?"Back to editing":"▶ Present"}),l&&w.jsxs(w.Fragment,{children:[w.jsx("div",{className:"stu-export-sep",role:"separator"}),w.jsx(pN,{onDone:()=>r(!1)})]})]})]})}function pJ(){const e=ke(s=>s.mode),t=ke(s=>s.setMode),n=e==="present";return w.jsx("button",{type:"button",className:`stu-libbtn stu-present ${n?"stu-present-on":""}`,title:n?"Back to editing (Esc)":"Present this doc as slides (⇧⌘P)",onClick:()=>t(n?"edit":"present"),children:"▶ Present"})}function fJ(){const e=ke(g=>g.dirty),t=ke(g=>g.saving),n=ke(g=>g.conflict),s=ke(g=>g.savedAt),o=ke(g=>g.autosave),r=ke(g=>g.currentSlug),i=ke(g=>g.savedSource),l=ke(g=>g.source),d=ke(g=>g.save),u=ke(g=>g.docs.find(v=>v.slug===g.currentSlug)?.mtimeMs??null),p=!o&&e&&n===null&&!t,h=oe.useMemo(()=>p&&r!==null?hC(i,l,r).length:0,[p,i,l,r]),m=n!==null?"conflict":t?"saving…":e?h>0?`${h} unsaved change${h===1?"":"s"}`:"unsaved changes":s!==null?`saved ${F0(s)}`:u!==null?`saved ${F0(u)}`:"";return w.jsxs("span",{className:"stu-savewrap","data-tour":"save",children:[w.jsx("button",{type:"button",className:"stu-btn stu-btn-primary stu-savebtn",disabled:r===null||t,title:o?"Save now (⌘S)":"Review and apply changes (⌘S)",onClick:()=>{d()},children:"Save"}),w.jsx("span",{className:"stu-savemeta",children:m})]})}function hJ(){const e=ke(i=>i.mode),t=ke(i=>i.docs),n=ke(i=>i.currentSlug),s=ke(i=>i.meta?.docsDir??"docs"),{doc:o}=Co();if(e==="home"||n===null)return w.jsxs("span",{className:"stu-crumb",children:[w.jsx("b",{children:"All documents"}),t.length>0&&w.jsxs(w.Fragment,{children:[" · ",w.jsx("span",{className:"stu-num",children:t.length})]})]});const r=o.meta?.title??n;return w.jsxs("span",{className:"stu-crumb",title:n,children:[XC(n,s)," / ",w.jsx("b",{children:r})]})}function mJ(){const e=ke(s=>s.mode),t=ke(s=>s.currentSlug),n=e!=="home"&&t!==null;return w.jsxs("header",{className:"stu-topbar","data-tour":"topbar",children:[w.jsx(hJ,{}),w.jsx("span",{className:"stu-spacer"}),n&&w.jsx(aJ,{}),e==="home"&&w.jsx(lJ,{}),w.jsxs("div",{className:"stu-topbar-wide",children:[e==="edit"&&w.jsx(cJ,{}),n&&w.jsx(dJ,{}),n&&w.jsx(pJ,{})]}),n&&w.jsx(fJ,{}),w.jsx(uJ,{})]})}const $i=316,On=12,gJ=250,vJ=4;function yJ(e,t){return e===null||t===null?e===t:e.left===t.left&&e.top===t.top&&e.width===t.width&&e.height===t.height}function xJ(e,t){const n=window.innerWidth,s=window.innerHeight;if(e.width*e.height>.55*n*s)return{left:n-$i-On*2,top:s-t-56};const o=Math.max(On,Math.min(e.left,n-$i-On)),r=e.top+e.height+On;if(r+t<=s-On)return{left:o,top:r};if(e.top-t-On>=On)return{left:o,top:e.top-t-On};const i=e.left+e.width+On,l=Math.max(On,Math.min(e.top,s-t-On));return i+$i<=n-On?{left:i,top:l}:e.left-$i-On>=On?{left:e.left-$i-On,top:l}:{left:(n-$i)/2,top:Math.max(On,(s-t)/2)}}function kJ({current:e}){return w.jsx("div",{className:"stu-tour-dots","aria-label":`Step ${e+1} of ${so.length}`,children:so.map((t,n)=>w.jsx("span",{className:`stu-tour-dot ${n===e?"stu-tour-dot-active":""} ${n<e?"stu-tour-dot-done":""}`,"aria-hidden":"true"},t.id))})}function hE({title:e,children:t}){return w.jsxs(w.Fragment,{children:[w.jsx("div",{className:"stu-tour-dim","aria-hidden":"true"}),w.jsxs("div",{className:"stu-tour-card stu-tour-card-center",role:"dialog","aria-label":e,children:[w.jsx("h3",{className:"stu-tour-title",children:e}),t]})]})}function bJ(){const e=Ic(y=>y.state),t=Ic(y=>y.dispatch),n=Ic(y=>y.skip),s=Ic(y=>y.addFarewell),o=ke(y=>y.currentSlug),r=ke(y=>y.sheet!==null),i=e.status==="running",l=so[e.step]??null,[d,u]=oe.useState(null),[p,h]=oe.useState(null),m=oe.useRef(null),g=oe.useRef(0);if(oe.useEffect(()=>{if(!i||l===null){u(null);return}g.current=0;const y=()=>{const E=document.querySelector(l.target);if(E===null){g.current+=1,g.current>=vJ?t({type:"break"}):u(null);return}g.current=0;const $=E.getBoundingClientRect(),A={left:$.left,top:$.top,width:$.width,height:$.height};u(T=>yJ(T,A)?T:A)};y();const b=window.setInterval(y,gJ);return window.addEventListener("resize",y),window.addEventListener("scroll",y,!0),()=>{window.clearInterval(b),window.removeEventListener("resize",y),window.removeEventListener("scroll",y,!0)}},[i,e.step,l,t]),oe.useLayoutEffect(()=>{if(d===null){h(null);return}const y=m.current?.offsetHeight??220;h(xJ(d,y))},[d,e.step]),oe.useEffect(()=>{if(!(!i||l===null)){if(o!==null&&o!==yo){t({type:"break"});return}l.needsSheet===!0&&!r&&t({type:"break"})}},[i,l,o,r,t]),oe.useEffect(()=>{if(e.status==="idle")return;const y=b=>{if(b.key==="Escape"){e.status==="running"?t({type:"break"}):e.status==="interrupted"?n():t({type:"close"});return}e.status==="running"&&!wl(b.target)&&(b.key==="ArrowRight"&&l?.advance===null?(b.preventDefault(),t({type:"next"})):b.key==="ArrowLeft"&&e.step>0&&l?.advance===null&&(b.preventDefault(),t({type:"back"})))};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[e,l,t,n]),oe.useEffect(()=>{if(!i||l===null||l.advance!==null)return;const y=setTimeout(()=>{m.current?.querySelector(".stu-tour-next")?.focus()},80);return()=>clearTimeout(y)},[i,e.step,l]),e.status==="idle")return null;if(e.status==="interrupted"){const y=()=>{const b=ke.getState(),E=()=>{const $=ke.getState(),A=document.querySelector('[data-seg="1"]')!==null&&$.currentSlug===yo;t({type:"resume",step:KZ({current:e.step,sheetOpen:ke.getState().sheet!==null,hasBlock:A})})};b.currentSlug!==yo?b.openDoc(yo).then(()=>setTimeout(E,120)):E()};return w.jsxs(hE,{title:"Paused — you wandered off the path",children:[w.jsxs("p",{className:"stu-tour-body",children:["No harm done: everything you just did was real. Pick the tour back up where it makes sense, or skip it — you can restart it anytime from the ",w.jsx("kbd",{children:"?"})," shortcuts card."]}),w.jsxs("div",{className:"stu-tour-actions",children:[w.jsx("button",{type:"button",className:"stu-btn",onClick:n,children:"Skip tour"}),w.jsx("button",{type:"button",className:"stu-btn stu-btn-primary stu-tour-next",autoFocus:!0,onClick:y,children:"Resume tour"})]})]})}if(e.status==="finished")return w.jsxs(hE,{title:"That's the studio — 2 minutes, no YAML",children:[w.jsxs("p",{className:"stu-tour-body",children:["Your playground doc is a real file (",w.jsxs("code",{children:["docs/",yo,".md"]}),") and it stays on disk — the studio never deletes files, because the files are the source of truth. Leave a note in it, or just get back to your own docs."]}),w.jsxs("div",{className:"stu-tour-actions",children:[w.jsx("button",{type:"button",className:"stu-btn",onClick:()=>{s(),t({type:"close"})},children:"Leave a farewell note"}),w.jsx("button",{type:"button",className:"stu-btn stu-btn-primary stu-tour-next",autoFocus:!0,onClick:()=>t({type:"close"}),children:"Done"})]})]});if(l===null)return null;const v=e.step===so.length-1;return w.jsxs(w.Fragment,{children:[d!==null&&w.jsx("div",{className:"stu-tour-spot","aria-hidden":"true",style:{left:d.left-6,top:d.top-6,width:d.width+12,height:d.height+12}}),w.jsxs("div",{ref:m,className:"stu-tour-card",role:"dialog","aria-label":`Tour step ${e.step+1}: ${l.title}`,style:{left:p?.left??(window.innerWidth-$i)/2,top:p?.top??window.innerHeight-280,visibility:d===null||p===null?"hidden":"visible"},children:[w.jsx(kJ,{current:e.step}),w.jsx("h3",{className:"stu-tour-title",children:l.title}),w.jsx("p",{className:"stu-tour-body",children:l.body}),l.keys!==void 0&&w.jsx("div",{className:"stu-tour-keys",children:l.keys.map(y=>w.jsx("kbd",{children:y},y))}),l.advance!==null&&w.jsxs("div",{className:"stu-tour-wait",children:[w.jsx("span",{className:"stu-tour-pulse","aria-hidden":"true"}),"try it for real — it advances by itself"]}),w.jsxs("div",{className:"stu-tour-actions",children:[w.jsx("button",{type:"button",className:"stu-linkbtn stu-tour-skip",onClick:n,children:"Skip tour"}),w.jsx("span",{className:"stu-tour-spacer"}),w.jsx("button",{type:"button",className:"stu-btn",disabled:e.step===0,onClick:()=>t({type:"back"}),children:"Back"}),w.jsx("button",{type:"button",className:`stu-btn stu-tour-next ${l.advance===null?"stu-btn-primary":""}`,onClick:()=>t({type:"next"}),children:v?"Finish":l.advance===null?"Next":"Skip step"})]})]})]})}function wJ(){xG();const e=ke(s=>s.init),t=ke(s=>s.handleServerEvent);oe.useEffect(()=>{e()},[e]),bG(t,()=>{ke.getState().checkVersion()},jy),oe.useEffect(()=>{const s=()=>{ke.getState().checkVersion()};return window.addEventListener("focus",s),()=>window.removeEventListener("focus",s)},[]),oe.useEffect(()=>{const s=o=>{const r=ke.getState();if(r.review!==null||r.pendingDelete!==null||r.picker!==null)return;const i=o.metaKey||o.ctrlKey;if(i&&o.shiftKey&&o.key.toLowerCase()==="p"){o.preventDefault(),r.setMode(r.mode==="present"?"edit":"present");return}if(i&&o.key.toLowerCase()==="s"){o.preventDefault(),r.save();return}if(r.mode!=="edit"){o.key==="Escape"&&r.mode!=="home"&&(o.preventDefault(),r.setMode("edit"));return}const l=zG({sheetOpen:r.sheet!==null,partSelected:r.partSel!==null,blockSelected:r.selection!==null});if(l==="sheet"||wl(o.target))return;if(i&&o.key.toLowerCase()==="z"){o.preventDefault(),o.shiftKey?r.redo():r.undo();return}if(l==="part")return;if(lY(o)&&r.currentSlug!==null){o.preventDefault(),dY(),r.dismissSlashHint(),r.openPicker({view:"compact"});return}const d=r.selection,{doc:u}=id(r.source,r.currentSlug??"untitled"),p=u.segments.length;if(i&&d!==null&&(o.key==="ArrowUp"||o.key==="ArrowDown")){o.preventDefault(),o.key==="ArrowUp"?lC(d):cC(d);return}if(i&&o.key.toLowerCase()==="d"){o.preventDefault(),d!==null&&u.segments[d]?.kind!=="meta"&&aC(d);return}const h=o.key==="ArrowDown"||o.key==="j"?1:o.key==="ArrowUp"||o.key==="k"?-1:0;if(h!==0&&!i&&!o.altKey&&!o.shiftKey){if(p===0)return;o.preventDefault();const m=u.segments[0]?.kind==="meta"?1:0;if(p<=m)return;const g=d===null?h===1?m:p-1:Math.min(p-1,Math.max(m,d+h));r.select(g),document.querySelector(`[data-seg="${g}"]`)?.scrollIntoView({block:"nearest",behavior:"smooth"});return}if((o.key==="Delete"||o.key==="Backspace")&&d!==null){o.preventDefault();const m=u.segments[d];if(m===void 0||m.kind==="meta")return;const g=()=>{ke.getState().applyOp((y,b)=>Ey(y,b,d),null)};if(!pC(m)){g();return}const v=document.querySelector(`[data-seg="${d}"]`)?.getBoundingClientRect();r.requestDelete({label:Ua(m),anchor:v!==void 0?{x:v.left+v.width/2,y:v.top+Math.min(v.height/2,48)}:{x:window.innerWidth/2,y:120},run:g});return}o.key==="Escape"&&r.select(null)};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[]);const n=ke(s=>s.mode);return w.jsxs("div",{className:"stu-app",children:[w.jsxs("div",{className:"stu-shell",children:[n!=="present"&&w.jsx(UQ,{}),w.jsxs("div",{className:"stu-main",children:[w.jsx(mJ,{}),n==="home"?w.jsx(HQ,{}):n==="edit"?w.jsx(LQ,{}):w.jsx(VQ,{})]})]}),w.jsx(pZ,{}),w.jsx(HZ,{}),w.jsx(mZ,{}),w.jsx(GQ,{}),w.jsx(fZ,{}),w.jsx(tJ,{}),w.jsx(eJ,{}),w.jsx(ZZ,{}),w.jsx(JZ,{}),w.jsx(bJ,{})]})}const mE=document.getElementById("root");mE!==null&&u_.createRoot(mE).render(w.jsx(oe.StrictMode,{children:w.jsx(wJ,{})}));
3266
+ `;let Ac=null;const Ic=vE()((e,t)=>{const n=s=>{const o=t().state,r=KZ(o,s);if(r===o)return;e({state:r});const i=r.status==="running"||r.status==="interrupted";i&&Ac===null?Ac=qG(l=>t().dispatch({type:"action",action:l})):!i&&Ac!==null&&(Ac(),Ac=null),r.status==="finished"&&fE("done"),s.type==="skip"&&fE("dismissed")};return{state:H0,dispatch:n,start:async()=>{const s=ke.getState();s.setMode("edit"),s.currentSlug!==yo&&(s.docs.some(r=>r.slug===yo)?await s.openDoc(yo):await s.newDoc(yo,UZ)),ke.getState().closeSheet(),n({type:"start"})},skip:()=>n({type:"skip"}),addFarewell:()=>{const s=ke.getState();s.currentSlug===yo&&s.applyOp((o,r)=>Sy(o,r,r.segments.length,"callout",YZ),null)}}}),Hf="chiltepin-studio-shortcutbar-dismissed",XZ=["chiltepin-studio-hint-dismissed","chiltepin-studio-direct-hint-dismissed"];function QZ(){try{let e=window.localStorage.getItem(Hf)==="1";for(const t of XZ)window.localStorage.getItem(t)!==null&&(e=!0,window.localStorage.removeItem(t));return e&&window.localStorage.setItem(Hf,"1"),e}catch{return!0}}const ZZ=[{title:"Canvas",rows:[{keys:"↑ ↓ · j k",label:"select block"},{keys:"⏎",label:"edit selection"},{keys:"⌘D",label:"duplicate"},{keys:"⌘↑ ⌘↓",label:"move block"},{keys:"⌫",label:"delete block"},{keys:"⌘Z / ⇧⌘Z",label:"undo / redo"},{keys:"esc",label:"deselect"}]},{title:"Diagram parts",rows:[{keys:"click · ⇥",label:"select a part (⇥ cycles)"},{keys:"⏎ · dbl-click",label:"edit the selected part"},{keys:"←↑↓→",label:"move it — grid cell / reorder · table cells: navigate"},{keys:"⌫",label:"delete the selected item"},{keys:"esc",label:"back to the block"},{keys:"drag",label:"move with the pointer"},{keys:"drag a dot",label:"connect nodes — drop on empty space to add one"},{keys:"D",label:"pen mode — draw a shape to add the node it means"},{keys:"right-click · ⇧F10",label:"menu — add / kind / group / wrap / delete"},{keys:"n",label:"sequence message: add / edit its numbered step note"},{keys:"⌥←↑↓→",label:"nudge the hovered part"}]},{title:"Editor",rows:[{keys:"⇥ / ⇧⇥",label:"next / previous field"},{keys:"⏎",label:"next field · new row on the last one"},{keys:"⏎ (empty row)",label:"leave the list"},{keys:"⌘⏎",label:"done — inside a text area: next"},{keys:"type · ↑↓ · ⏎",label:"filter and pick in dropdowns"},{keys:"esc",label:"cancel"}]},{title:"Insert",rows:[{keys:"/",label:"insert after selection"},{keys:"type",label:"filter block types"},{keys:"⏎",label:"insert and start typing"},{keys:"+",label:"hover a gap between blocks — same picker, pinned there"},{keys:"Library",label:"browse every block — the picker footer, or the top bar"}]},{title:"Studio",rows:[{keys:"rail",label:"docs by folder · New doc · All documents · Settings (autosave)"},{keys:"⌘K",label:"search docs — opens the rail drawer on narrow windows"},{keys:"check chip",label:"validation results — rows jump to the block & field"},{keys:"⌘S",label:"save now — with autosave off, review first"},{keys:"⇧⌘P",label:"Present — the current doc as slides · esc returns"},{keys:"Share ▾",label:"copy link · export HTML / slides / PDF · open the site"}]}];function JZ(){const e=ke(T=>T.sheet!==null),t=ke(T=>T.selection!==null),n=ke(T=>T.selection),{doc:s,rendered:o}=Co(),[r,i]=oe.useState(QZ),[l,d]=oe.useState(!1);oe.useEffect(()=>{const T=N=>{if(N.key==="?"&&!N.metaKey&&!N.ctrlKey&&!wl(N.target)){N.preventDefault(),N.stopPropagation(),d(j=>!j),i(!1);try{window.localStorage.removeItem(Hf)}catch{}return}N.key==="Escape"&&l&&(N.preventDefault(),N.stopPropagation(),d(!1))};return window.addEventListener("keydown",T,!0),()=>window.removeEventListener("keydown",T,!0)},[l]);const u=ke(T=>T.partSel),p=u!==null,h=ke(T=>T.mode),m=h!=="edit"?h:e?"sheet":p?"part":t?"canvas-selected":"canvas",g=n!==null?s.segments[n]:void 0,v=g!==void 0&&g.kind!=="markdown"&&g.kind!=="meta"&&MG(g.kind,g.data),y=n!==null&&(o?.segments[n]?.html.includes("data-bp")??!1),b=u!==null?s.segments[u.seg]:void 0,E=b!==void 0&&b.kind!=="markdown"?$n(b.kind):null,$=u!==null&&E!==null&&Af(E,u.path)!==null,A=()=>{i(!0);try{window.localStorage.setItem(Hf,"1")}catch{}};return w.jsxs(w.Fragment,{children:[!r&&w.jsxs("div",{className:"stu-keybar",role:"note","data-ctx":m,"data-tour":"keybar",children:[lY(m,{dragParts:v,connectDots:$,parts:y}).map(T=>w.jsxs("span",{className:"stu-keybar-hint",children:[w.jsx("kbd",{children:T.keys})," ",T.label]},T.keys)),w.jsx("button",{type:"button",className:"stu-keybar-x","aria-label":"Hide shortcuts bar (press ? to bring it back)",onClick:A,children:w.jsx(Rf,{size:10})})]}),l&&w.jsx("div",{className:"stu-keys-backdrop",onMouseDown:()=>d(!1),children:w.jsxs("div",{className:"stu-keys-card",role:"dialog","aria-label":"Keyboard shortcuts",onMouseDown:T=>T.stopPropagation(),children:[w.jsxs("header",{children:[w.jsx("h2",{children:"Keyboard shortcuts"}),w.jsx("button",{type:"button","aria-label":"Close",onClick:()=>d(!1),children:w.jsx(Rf,{size:12})})]}),w.jsx("div",{className:"stu-keys-cols",children:ZZ.map(T=>w.jsxs("section",{children:[w.jsx("h3",{children:T.title}),T.rows.map(N=>w.jsxs("div",{className:"stu-keys-row",children:[w.jsx("kbd",{children:N.keys}),w.jsx("span",{children:N.label})]},N.keys))]},T.title))}),w.jsxs("footer",{children:["press ",w.jsx("kbd",{children:"?"})," anytime to toggle this card",w.jsx("button",{type:"button",className:"stu-keys-tour",onClick:()=>{d(!1),Ic.getState().start()},children:"▸ Take the interactive tour"})]})]})})]})}function eJ(){const e=ke(n=>n.toasts),t=ke(n=>n.dismissToast);return e.length===0?null:w.jsx("div",{className:"stu-toasts",role:"status",children:e.map(n=>w.jsxs("div",{className:`stu-toast stu-toast-${n.tone}`,children:[w.jsx("span",{children:n.message}),w.jsx("button",{type:"button","aria-label":"Dismiss",onClick:()=>t(n.id),children:"×"})]},n.id))})}function tJ(){return ke(t=>t.updateAvailable)?w.jsxs("div",{className:"stu-update",role:"status",children:[w.jsx("span",{children:"Studio was updated —"}),w.jsx("button",{type:"button",className:"stu-update-btn",onClick:()=>window.location.reload(),children:"Reload"})]}):null}function nJ(){const e=ke(n=>n.conflict),t=ke(n=>n.resolveConflict);return e===null?null:w.jsxs("div",{className:"stu-conflict",role:"alertdialog","aria-label":"File changed on disk",children:[w.jsxs("div",{className:"stu-conflict-msg",children:[w.jsx("strong",{children:"This file changed on disk."}),w.jsx("span",{children:"Your unsaved edits overlap with the change."})]}),w.jsxs("div",{className:"stu-conflict-actions",children:[w.jsx("button",{type:"button",className:"stu-btn",onClick:()=>t("theirs"),children:"Reload theirs"}),w.jsx("button",{type:"button",className:"stu-btn stu-btn-primary",onClick:()=>t("mine"),children:"Keep mine"})]})]})}function Cx(e){return e.split("/").pop()??e}function Nx(e,t,n){const s=URL.createObjectURL(new Blob([t],{type:n})),o=document.createElement("a");o.href=s,o.download=e,document.body.appendChild(o),o.click(),o.remove(),URL.revokeObjectURL(s)}function sJ(e,t){Nx(`${Cx(t)}.html`,UA(e),"text/html;charset=utf-8")}function oJ(e,t){Nx(`${Cx(t)}.slides.html`,KA(e),"text/html;charset=utf-8")}async function rJ(e,t){await iJ("pdf",UA(e),`${Cx(t)}.pdf`,"PDF")}async function iJ(e,t,n,s){const o=await fetch(`/api/export/${e}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({html:t})});if(!o.ok){let r=`${s} export failed (${o.status})`;try{const i=await o.json();typeof i.error=="string"&&(r=i.error)}catch{}throw new Error(r)}Nx(n,await o.blob(),"application/pdf")}function dN(e,t,n){oe.useEffect(()=>{if(!e)return;const s=r=>{t.current!==null&&!t.current.contains(r.target)&&n()},o=r=>{r.key==="Escape"&&(r.stopPropagation(),n())};return window.addEventListener("mousedown",s),window.addEventListener("keydown",o,!0),()=>{window.removeEventListener("mousedown",s),window.removeEventListener("keydown",o,!0)}},[e,t,n])}function aJ({row:e,onOpen:t}){return w.jsxs("div",{className:`stu-checkrow stu-checkrow-${e.level}`,children:[w.jsx("span",{className:"stu-checkrow-code",children:e.code}),w.jsxs("span",{className:"stu-checkrow-msg",children:[e.message,e.line!==null&&w.jsxs("span",{className:"stu-checkrow-line",children:[" · line ",e.line]}),e.hint!==null&&w.jsx("span",{className:"stu-checkrow-hint",children:e.hint})]}),e.segIndex!==null&&w.jsx("button",{type:"button",className:"stu-checkrow-open",onClick:()=>t(e),children:e.segKind==="markdown"?"Open block →":"Open field →"})]})}function lJ(){const e=ke(h=>h.source),{doc:t,diagnostics:n}=Co(),[s,o]=oe.useState(!1),r=oe.useRef(null);dN(s,r,()=>o(!1));const{errors:i,warnings:l}=VC(n),d=oe.useMemo(()=>s?jQ(e,t,n):[],[s,e,t,n]),u=h=>{if(o(!1),h.segIndex===null)return;const m=ke.getState();if(h.segKind==="markdown"){m.select(h.segIndex),document.querySelector(`[data-seg="${h.segIndex}"]`)?.scrollIntoView({block:"center",behavior:"smooth"});return}m.openSheet(h.segIndex,!1,h.field??void 0)},p=i>0?`${i} error${i===1?"":"s"}`:"pass";return w.jsxs("div",{className:"stu-checkwrap",ref:r,children:[w.jsxs("button",{type:"button",className:`stu-checkchip ${i>0?"stu-checkchip-err":"stu-checkchip-ok"}`,"aria-haspopup":"dialog","aria-expanded":s,title:i>0?`${p} — click for details`:"chiltepin check passes — click for details",onClick:()=>o(!s),children:[i===0&&w.jsx(_C,{size:10}),p,w.jsx("span",{className:"stu-checkchip-caret","aria-hidden":"true",children:"▾"})]}),s&&w.jsxs("div",{className:"stu-checkpop",role:"dialog","aria-label":"Check results",children:[w.jsx("span",{className:"stu-checkpop-caret","aria-hidden":"true"}),w.jsxs("header",{className:"stu-checkpop-head",children:[w.jsx("b",{children:"chiltepin check"}),i>0&&w.jsxs("span",{className:"stu-checkpop-chip stu-checkpop-chip-err",children:[i," error",i===1?"":"s"]}),l>0&&w.jsxs("span",{className:"stu-checkpop-chip stu-checkpop-chip-warn",children:[l," warning",l===1?"":"s"]}),i===0&&l===0&&w.jsx("span",{className:"stu-checkpop-chip stu-checkpop-chip-ok",children:"✓ pass"})]}),w.jsx("div",{className:"stu-checkpop-rows",children:d.length===0?w.jsx("div",{className:"stu-checkpop-empty",children:"No issues — this doc publishes clean."}):d.map((h,m)=>w.jsx(aJ,{row:h,onOpen:u},m))}),w.jsxs("footer",{className:"stu-checkpop-foot",children:[w.jsx("span",{children:"Errors block publish · warnings never do"}),w.jsx("span",{className:"stu-checkpop-ran",children:"checked live"})]})]})]})}function cJ(){const e=ke(g=>g.docs),t=ke(g=>g.currentSlug),{diagnostics:n}=Co(),[s,o]=oe.useState(!1),r=oe.useRef(null);dN(s,r,()=>o(!1));const i=n.filter(g=>g.level==="error").length,l=oe.useMemo(()=>e.map(g=>({doc:g,status:Ax(g,{slug:t,errors:i})})),[e,t,i]),d=l.some(g=>g.status.kind!=="unknown");if(e.length===0||!d)return null;const u=l.filter(g=>g.status.kind==="errors"),p=u.reduce((g,v)=>g+v.status.count,0),h=g=>{o(!1);const v=ke.getState();v.openDoc(g),v.setMode("edit")},m=p>0?`${p} error${p===1?"":"s"}`:"pass";return w.jsxs("div",{className:"stu-checkwrap",ref:r,children:[w.jsxs("button",{type:"button",className:`stu-checkchip ${p>0?"stu-checkchip-err":"stu-checkchip-ok"}`,"aria-haspopup":"dialog","aria-expanded":s,title:p>0?`${u.length} doc${u.length===1?"":"s"} failing — click for the list`:"chiltepin check passes across all docs",onClick:()=>o(!s),children:[p===0&&w.jsx(_C,{size:10}),m,w.jsx("span",{className:"stu-checkchip-caret","aria-hidden":"true",children:"▾"})]}),s&&w.jsxs("div",{className:"stu-checkpop",role:"dialog","aria-label":"Check results, all documents",children:[w.jsx("span",{className:"stu-checkpop-caret","aria-hidden":"true"}),w.jsxs("header",{className:"stu-checkpop-head",children:[w.jsx("b",{children:"chiltepin check"}),p>0?w.jsxs("span",{className:"stu-checkpop-chip stu-checkpop-chip-err",children:[p," error",p===1?"":"s"," · ",u.length," doc",u.length===1?"":"s"]}):w.jsx("span",{className:"stu-checkpop-chip stu-checkpop-chip-ok",children:"✓ pass"})]}),w.jsx("div",{className:"stu-checkpop-rows",children:u.length===0?w.jsx("div",{className:"stu-checkpop-empty",children:"All documents publish clean."}):u.map(g=>w.jsxs("button",{type:"button",className:"stu-checkpop-docrow",title:g.doc.slug,onClick:()=>h(g.doc.slug),children:[w.jsx("span",{className:"stu-checkpop-docname",children:g.doc.title}),w.jsxs("span",{className:"stu-checkpop-doccount",children:[g.status.count," error",g.status.count===1?"":"s"]})]},g.doc.slug))}),w.jsxs("footer",{className:"stu-checkpop-foot",children:[w.jsx("span",{children:"Errors block publish · warnings never do"}),w.jsx("span",{className:"stu-checkpop-ran",children:"checked live"})]})]})]})}function dJ(){const e=ke(t=>t.openLibrary);return w.jsxs("button",{type:"button",className:"stu-libbtn",title:"Browse all block types",onClick:e,children:[w.jsx(yx,{size:13}),"Library"]})}function uN(e,t,n){oe.useEffect(()=>{if(!e)return;const s=r=>{t.current!==null&&!t.current.contains(r.target)&&n()},o=r=>{r.key==="Escape"&&(r.stopPropagation(),n())};return window.addEventListener("mousedown",s),window.addEventListener("keydown",o,!0),()=>{window.removeEventListener("mousedown",s),window.removeEventListener("keydown",o,!0)}},[e,t,n])}function pN({onDone:e}){const t=ke(h=>h.currentSlug),n=ke(h=>h.toast),{doc:s}=Co(),[o,r]=oe.useState(!1),i=async h=>{const{source:m,docs:g,currentSlug:v}=ke.getState(),y=g.find(b=>b.slug===v)?.title;try{const b=await kB(window.location.href.split(/[?#]/)[0]??"/",m,{present:h,...y!==void 0?{title:y}:{}});if(b.length>mB){n("This document is too big to share as a link — export it instead","error");return}await navigator.clipboard.writeText(b),n(h?"Deck link copied":"Share link copied","info"),e()}catch(b){n(`Could not build a share link: ${b.message}`,"error")}},l=t??"document",d=()=>{sJ(s,l),n("Exported HTML page","info"),e()},u=()=>{oJ(s,l),n("Exported slide deck","info"),e()},p=async()=>{r(!0);try{await rJ(s,l),n("Exported PDF","info"),e()}catch(h){n(`PDF export failed: ${h.message}`,"error")}finally{r(!1)}};return w.jsxs(w.Fragment,{children:[w.jsx("button",{type:"button",role:"menuitem",className:"stu-export-item",onClick:()=>{i(!1)},children:"Copy link"}),w.jsx("button",{type:"button",role:"menuitem",className:"stu-export-item",onClick:()=>{i(!0)},children:"Copy deck link"}),w.jsx("div",{className:"stu-export-sep",role:"separator"}),w.jsx("button",{type:"button",role:"menuitem",className:"stu-export-item",onClick:d,children:"Export HTML page"}),w.jsx("button",{type:"button",role:"menuitem",className:"stu-export-item",onClick:u,children:"Export slide deck"}),jy&&w.jsxs(w.Fragment,{children:[w.jsx("button",{type:"button",role:"menuitem",className:"stu-export-item",disabled:o,onClick:()=>{p()},children:o?"Exporting PDF…":"Export PDF"}),w.jsx("div",{className:"stu-export-sep",role:"separator"}),w.jsx("a",{className:"stu-export-item",role:"menuitem",href:t!==null?`/site/${t}.html`:"/site/",target:"_blank",rel:"noreferrer",onClick:e,children:"Open site ↗"})]})]})}function uJ(){const e=ke(o=>o.currentSlug),[t,n]=oe.useState(!1),s=oe.useRef(null);return uN(t,s,()=>n(!1)),w.jsxs("div",{className:"stu-export",ref:s,children:[w.jsxs("button",{type:"button",className:"stu-libbtn",disabled:e===null,"aria-haspopup":"menu","aria-expanded":t,title:"Share, export, or open the site",onClick:()=>n(!t),children:["Share",w.jsx(kX,{size:11})]}),t&&w.jsx("div",{className:"stu-export-pop",role:"menu",children:w.jsx(pN,{onDone:()=>n(!1)})})]})}function pJ(){const e=ke(d=>d.mode),t=ke(d=>d.setMode),n=ke(d=>d.openLibrary),s=ke(d=>d.currentSlug),[o,r]=oe.useState(!1),i=oe.useRef(null);uN(o,i,()=>r(!1));const l=e!=="home"&&s!==null;return w.jsxs("div",{className:"stu-export stu-topbar-more",ref:i,children:[w.jsx("button",{type:"button",className:"stu-libbtn stu-morebtn","aria-label":"More actions","aria-haspopup":"menu","aria-expanded":o,title:"More actions",onClick:()=>r(!o),children:"⋯"}),o&&w.jsxs("div",{className:"stu-export-pop",role:"menu",children:[e==="edit"&&w.jsx("button",{type:"button",role:"menuitem",className:"stu-export-item",onClick:()=>{r(!1),n()},children:"Block library"}),l&&w.jsx("button",{type:"button",role:"menuitem",className:"stu-export-item",onClick:()=>{r(!1),t(e==="present"?"edit":"present")},children:e==="present"?"Back to editing":"▶ Present"}),l&&w.jsxs(w.Fragment,{children:[w.jsx("div",{className:"stu-export-sep",role:"separator"}),w.jsx(pN,{onDone:()=>r(!1)})]})]})]})}function fJ(){const e=ke(s=>s.mode),t=ke(s=>s.setMode),n=e==="present";return w.jsx("button",{type:"button",className:`stu-libbtn stu-present ${n?"stu-present-on":""}`,title:n?"Back to editing (Esc)":"Present this doc as slides (⇧⌘P)",onClick:()=>t(n?"edit":"present"),children:"▶ Present"})}function hJ(){const e=ke(g=>g.dirty),t=ke(g=>g.saving),n=ke(g=>g.conflict),s=ke(g=>g.savedAt),o=ke(g=>g.autosave),r=ke(g=>g.currentSlug),i=ke(g=>g.savedSource),l=ke(g=>g.source),d=ke(g=>g.save),u=ke(g=>g.docs.find(v=>v.slug===g.currentSlug)?.mtimeMs??null),p=!o&&e&&n===null&&!t,h=oe.useMemo(()=>p&&r!==null?hC(i,l,r).length:0,[p,i,l,r]),m=n!==null?"conflict":t?"saving…":e?h>0?`${h} unsaved change${h===1?"":"s"}`:"unsaved changes":s!==null?`saved ${F0(s)}`:u!==null?`saved ${F0(u)}`:"";return w.jsxs("span",{className:"stu-savewrap","data-tour":"save",children:[w.jsx("button",{type:"button",className:"stu-btn stu-btn-primary stu-savebtn",disabled:r===null||t,title:o?"Save now (⌘S)":"Review and apply changes (⌘S)",onClick:()=>{d()},children:"Save"}),w.jsx("span",{className:"stu-savemeta",children:m})]})}function mJ(){const e=ke(i=>i.mode),t=ke(i=>i.docs),n=ke(i=>i.currentSlug),s=ke(i=>i.meta?.docsDir??"docs"),{doc:o}=Co();if(e==="home"||n===null)return w.jsxs("span",{className:"stu-crumb",children:[w.jsx("b",{children:"All documents"}),t.length>0&&w.jsxs(w.Fragment,{children:[" · ",w.jsx("span",{className:"stu-num",children:t.length})]})]});const r=o.meta?.title??n;return w.jsxs("span",{className:"stu-crumb",title:n,children:[XC(n,s)," / ",w.jsx("b",{children:r})]})}function gJ(){const e=ke(s=>s.mode),t=ke(s=>s.currentSlug),n=e!=="home"&&t!==null;return w.jsxs("header",{className:"stu-topbar","data-tour":"topbar",children:[w.jsx(mJ,{}),w.jsx("span",{className:"stu-spacer"}),n&&w.jsx(lJ,{}),e==="home"&&w.jsx(cJ,{}),w.jsxs("div",{className:"stu-topbar-wide",children:[e==="edit"&&w.jsx(dJ,{}),n&&w.jsx(uJ,{}),n&&w.jsx(fJ,{})]}),n&&w.jsx(hJ,{}),w.jsx(pJ,{})]})}const $i=316,On=12,vJ=250,yJ=4;function xJ(e,t){return e===null||t===null?e===t:e.left===t.left&&e.top===t.top&&e.width===t.width&&e.height===t.height}function kJ(e,t){const n=window.innerWidth,s=window.innerHeight;if(e.width*e.height>.55*n*s)return{left:n-$i-On*2,top:s-t-56};const o=Math.max(On,Math.min(e.left,n-$i-On)),r=e.top+e.height+On;if(r+t<=s-On)return{left:o,top:r};if(e.top-t-On>=On)return{left:o,top:e.top-t-On};const i=e.left+e.width+On,l=Math.max(On,Math.min(e.top,s-t-On));return i+$i<=n-On?{left:i,top:l}:e.left-$i-On>=On?{left:e.left-$i-On,top:l}:{left:(n-$i)/2,top:Math.max(On,(s-t)/2)}}function bJ({current:e}){return w.jsx("div",{className:"stu-tour-dots","aria-label":`Step ${e+1} of ${so.length}`,children:so.map((t,n)=>w.jsx("span",{className:`stu-tour-dot ${n===e?"stu-tour-dot-active":""} ${n<e?"stu-tour-dot-done":""}`,"aria-hidden":"true"},t.id))})}function hE({title:e,children:t}){return w.jsxs(w.Fragment,{children:[w.jsx("div",{className:"stu-tour-dim","aria-hidden":"true"}),w.jsxs("div",{className:"stu-tour-card stu-tour-card-center",role:"dialog","aria-label":e,children:[w.jsx("h3",{className:"stu-tour-title",children:e}),t]})]})}function wJ(){const e=Ic(y=>y.state),t=Ic(y=>y.dispatch),n=Ic(y=>y.skip),s=Ic(y=>y.addFarewell),o=ke(y=>y.currentSlug),r=ke(y=>y.sheet!==null),i=e.status==="running",l=so[e.step]??null,[d,u]=oe.useState(null),[p,h]=oe.useState(null),m=oe.useRef(null),g=oe.useRef(0);if(oe.useEffect(()=>{if(!i||l===null){u(null);return}g.current=0;const y=()=>{const E=document.querySelector(l.target);if(E===null){g.current+=1,g.current>=yJ?t({type:"break"}):u(null);return}g.current=0;const $=E.getBoundingClientRect(),A={left:$.left,top:$.top,width:$.width,height:$.height};u(T=>xJ(T,A)?T:A)};y();const b=window.setInterval(y,vJ);return window.addEventListener("resize",y),window.addEventListener("scroll",y,!0),()=>{window.clearInterval(b),window.removeEventListener("resize",y),window.removeEventListener("scroll",y,!0)}},[i,e.step,l,t]),oe.useLayoutEffect(()=>{if(d===null){h(null);return}const y=m.current?.offsetHeight??220;h(kJ(d,y))},[d,e.step]),oe.useEffect(()=>{if(!(!i||l===null)){if(o!==null&&o!==yo){t({type:"break"});return}l.needsSheet===!0&&!r&&t({type:"break"})}},[i,l,o,r,t]),oe.useEffect(()=>{if(e.status==="idle")return;const y=b=>{if(b.key==="Escape"){e.status==="running"?t({type:"break"}):e.status==="interrupted"?n():t({type:"close"});return}e.status==="running"&&!wl(b.target)&&(b.key==="ArrowRight"&&l?.advance===null?(b.preventDefault(),t({type:"next"})):b.key==="ArrowLeft"&&e.step>0&&l?.advance===null&&(b.preventDefault(),t({type:"back"})))};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[e,l,t,n]),oe.useEffect(()=>{if(!i||l===null||l.advance!==null)return;const y=setTimeout(()=>{m.current?.querySelector(".stu-tour-next")?.focus()},80);return()=>clearTimeout(y)},[i,e.step,l]),e.status==="idle")return null;if(e.status==="interrupted"){const y=()=>{const b=ke.getState(),E=()=>{const $=ke.getState(),A=document.querySelector('[data-seg="1"]')!==null&&$.currentSlug===yo;t({type:"resume",step:VZ({current:e.step,sheetOpen:ke.getState().sheet!==null,hasBlock:A})})};b.currentSlug!==yo?b.openDoc(yo).then(()=>setTimeout(E,120)):E()};return w.jsxs(hE,{title:"Paused — you wandered off the path",children:[w.jsxs("p",{className:"stu-tour-body",children:["No harm done: everything you just did was real. Pick the tour back up where it makes sense, or skip it — you can restart it anytime from the ",w.jsx("kbd",{children:"?"})," shortcuts card."]}),w.jsxs("div",{className:"stu-tour-actions",children:[w.jsx("button",{type:"button",className:"stu-btn",onClick:n,children:"Skip tour"}),w.jsx("button",{type:"button",className:"stu-btn stu-btn-primary stu-tour-next",autoFocus:!0,onClick:y,children:"Resume tour"})]})]})}if(e.status==="finished")return w.jsxs(hE,{title:"That's the studio — 2 minutes, no YAML",children:[w.jsxs("p",{className:"stu-tour-body",children:["Your playground doc is a real file (",w.jsxs("code",{children:["docs/",yo,".md"]}),") and it stays on disk — the studio never deletes files, because the files are the source of truth. Leave a note in it, or just get back to your own docs."]}),w.jsxs("div",{className:"stu-tour-actions",children:[w.jsx("button",{type:"button",className:"stu-btn",onClick:()=>{s(),t({type:"close"})},children:"Leave a farewell note"}),w.jsx("button",{type:"button",className:"stu-btn stu-btn-primary stu-tour-next",autoFocus:!0,onClick:()=>t({type:"close"}),children:"Done"})]})]});if(l===null)return null;const v=e.step===so.length-1;return w.jsxs(w.Fragment,{children:[d!==null&&w.jsx("div",{className:"stu-tour-spot","aria-hidden":"true",style:{left:d.left-6,top:d.top-6,width:d.width+12,height:d.height+12}}),w.jsxs("div",{ref:m,className:"stu-tour-card",role:"dialog","aria-label":`Tour step ${e.step+1}: ${l.title}`,style:{left:p?.left??(window.innerWidth-$i)/2,top:p?.top??window.innerHeight-280,visibility:d===null||p===null?"hidden":"visible"},children:[w.jsx(bJ,{current:e.step}),w.jsx("h3",{className:"stu-tour-title",children:l.title}),w.jsx("p",{className:"stu-tour-body",children:l.body}),l.keys!==void 0&&w.jsx("div",{className:"stu-tour-keys",children:l.keys.map(y=>w.jsx("kbd",{children:y},y))}),l.advance!==null&&w.jsxs("div",{className:"stu-tour-wait",children:[w.jsx("span",{className:"stu-tour-pulse","aria-hidden":"true"}),"try it for real — it advances by itself"]}),w.jsxs("div",{className:"stu-tour-actions",children:[w.jsx("button",{type:"button",className:"stu-linkbtn stu-tour-skip",onClick:n,children:"Skip tour"}),w.jsx("span",{className:"stu-tour-spacer"}),w.jsx("button",{type:"button",className:"stu-btn",disabled:e.step===0,onClick:()=>t({type:"back"}),children:"Back"}),w.jsx("button",{type:"button",className:`stu-btn stu-tour-next ${l.advance===null?"stu-btn-primary":""}`,onClick:()=>t({type:"next"}),children:v?"Finish":l.advance===null?"Next":"Skip step"})]})]})]})}function $J(){kG();const e=ke(s=>s.init),t=ke(s=>s.handleServerEvent);oe.useEffect(()=>{e()},[e]),wG(t,()=>{ke.getState().checkVersion()},jy),oe.useEffect(()=>{const s=()=>{ke.getState().checkVersion()};return window.addEventListener("focus",s),()=>window.removeEventListener("focus",s)},[]),oe.useEffect(()=>{const s=o=>{const r=ke.getState();if(r.review!==null||r.pendingDelete!==null||r.picker!==null)return;const i=o.metaKey||o.ctrlKey;if(i&&o.shiftKey&&o.key.toLowerCase()==="p"){o.preventDefault(),r.setMode(r.mode==="present"?"edit":"present");return}if(i&&o.key.toLowerCase()==="s"){o.preventDefault(),r.save();return}if(r.mode!=="edit"){o.key==="Escape"&&r.mode!=="home"&&(o.preventDefault(),r.setMode("edit"));return}const l=FG({sheetOpen:r.sheet!==null,partSelected:r.partSel!==null,blockSelected:r.selection!==null});if(l==="sheet"||wl(o.target))return;if(i&&o.key.toLowerCase()==="z"){o.preventDefault(),o.shiftKey?r.redo():r.undo();return}if(l==="part")return;if(cY(o)&&r.currentSlug!==null){o.preventDefault(),uY(),r.dismissSlashHint(),r.openPicker({view:"compact"});return}const d=r.selection,{doc:u}=id(r.source,r.currentSlug??"untitled"),p=u.segments.length;if(i&&d!==null&&(o.key==="ArrowUp"||o.key==="ArrowDown")){o.preventDefault(),o.key==="ArrowUp"?lC(d):cC(d);return}if(i&&o.key.toLowerCase()==="d"){o.preventDefault(),d!==null&&u.segments[d]?.kind!=="meta"&&aC(d);return}const h=o.key==="ArrowDown"||o.key==="j"?1:o.key==="ArrowUp"||o.key==="k"?-1:0;if(h!==0&&!i&&!o.altKey&&!o.shiftKey){if(p===0)return;o.preventDefault();const m=u.segments[0]?.kind==="meta"?1:0;if(p<=m)return;const g=d===null?h===1?m:p-1:Math.min(p-1,Math.max(m,d+h));r.select(g),document.querySelector(`[data-seg="${g}"]`)?.scrollIntoView({block:"nearest",behavior:"smooth"});return}if((o.key==="Delete"||o.key==="Backspace")&&d!==null){o.preventDefault();const m=u.segments[d];if(m===void 0||m.kind==="meta")return;const g=()=>{ke.getState().applyOp((y,b)=>Ey(y,b,d),null)};if(!pC(m)){g();return}const v=document.querySelector(`[data-seg="${d}"]`)?.getBoundingClientRect();r.requestDelete({label:Ua(m),anchor:v!==void 0?{x:v.left+v.width/2,y:v.top+Math.min(v.height/2,48)}:{x:window.innerWidth/2,y:120},run:g});return}o.key==="Escape"&&r.select(null)};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[]);const n=ke(s=>s.mode);return w.jsxs("div",{className:"stu-app",children:[w.jsxs("div",{className:"stu-shell",children:[n!=="present"&&w.jsx(KQ,{}),w.jsxs("div",{className:"stu-main",children:[w.jsx(gJ,{}),n==="home"?w.jsx(WQ,{}):n==="edit"?w.jsx(IQ,{}):w.jsx(GQ,{})]})]}),w.jsx(fZ,{}),w.jsx(WZ,{}),w.jsx(gZ,{}),w.jsx(YQ,{}),w.jsx(hZ,{}),w.jsx(nJ,{}),w.jsx(tJ,{}),w.jsx(JZ,{}),w.jsx(eJ,{}),w.jsx(wJ,{})]})}const mE=document.getElementById("root");mE!==null&&u_.createRoot(mE).render(w.jsx(oe.StrictMode,{children:w.jsx($J,{})}));