grooph 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +33 -31
  2. package/THIRD-PARTY-NOTICES.md +5 -1
  3. package/dist/app/assets/App-CT9KxzfQ.css +1 -0
  4. package/dist/app/assets/App-D1pDFbEY.js +5 -0
  5. package/dist/app/assets/EmbedApp-CTausQWY.js +1 -0
  6. package/dist/app/assets/ExportPanel-CbRH4C69.js +8 -0
  7. package/dist/app/assets/Import-DF0XLxRI.js +1 -0
  8. package/dist/app/assets/SketchView-BjeUHG4X.js +143 -0
  9. package/dist/app/assets/{brakes-BJPDrrJT.js → brakes-B9b3hDX8.js} +1 -1
  10. package/dist/app/assets/{builtins-D_22fKRF.js → builtins-DzyPaYdd.js} +1 -1
  11. package/dist/app/assets/{compile-BAvi-rd0.js → compile-DL2budwP.js} +8 -8
  12. package/dist/app/assets/{front-BRl7rl-u.js → front-OxfL-OaD.js} +1 -1
  13. package/dist/app/assets/full-C0asYORc.js +1 -0
  14. package/dist/app/assets/graph-more-Dn_hNa20.js +2 -0
  15. package/dist/app/assets/graph-stage-CwNePnN4.js +4 -0
  16. package/dist/app/assets/graph-views-CmkQ41zC.js +2 -0
  17. package/dist/app/assets/{index-CeaKwKuU.js → index-B5ZkSF4L.js} +2 -2
  18. package/dist/app/assets/mermaid-read-cyqJ32v-.js +17 -0
  19. package/dist/app/assets/{plan-templates-BQu8G2sX.js → plan-templates-u2fF3GnS.js} +1 -1
  20. package/dist/app/assets/runs-BA5HKtsx.js +1 -0
  21. package/dist/app/assets/screens-CMMuexid.js +16 -0
  22. package/dist/app/assets/share-DV3wsAsJ.js +8 -0
  23. package/dist/app/assets/site-looks.v1.css +223 -0
  24. package/dist/app/assets/space-Cuy4YqyZ.js +1 -0
  25. package/dist/app/assets/styles-Dlp-yYlE.css +1 -0
  26. package/dist/app/assets/templates-DbAhWvP6.js +2 -0
  27. package/dist/app/assets/{themes-DtOBrLk0.js → themes-C34TrvOJ.js} +1 -1
  28. package/dist/app/assets/{units-DOIUgOIU.js → units-DlniUjfH.js} +1 -1
  29. package/dist/app/assets/{views-CLwg5VNv.js → views-CFqRShXD.js} +2 -1
  30. package/dist/app/grooph-app.json +1 -1
  31. package/dist/app/index.html +14 -11
  32. package/dist/app/llms.txt +6 -7
  33. package/dist/app/manifest.webmanifest +1 -1
  34. package/dist/app/og.png +0 -0
  35. package/dist/app/routes.json +42 -33
  36. package/dist/app/sw.js +7 -2
  37. package/dist/browser/grooph.d.ts +44 -0
  38. package/dist/browser/grooph.global.js +7 -0
  39. package/dist/browser/grooph.js +7 -0
  40. package/dist/bundle/grooph.js +6734 -2536
  41. package/hooks/grooph-event.mjs +163 -14
  42. package/package.json +14 -6
  43. package/dist/app/assets/App-48y1Ec5B.js +0 -5
  44. package/dist/app/assets/App-Cv1auMeh.css +0 -1
  45. package/dist/app/assets/EmbedApp-390Z2d4x.js +0 -1
  46. package/dist/app/assets/ExportPanel-Ca3wBB38.js +0 -8
  47. package/dist/app/assets/Import-ByMI7Uz9.js +0 -1
  48. package/dist/app/assets/graph-more-393HTgQE.js +0 -2
  49. package/dist/app/assets/graph-stage-BkrQGQ-z.js +0 -4
  50. package/dist/app/assets/graph-views-COQF_QTQ.js +0 -2
  51. package/dist/app/assets/runs-DcjRi7S6.js +0 -1
  52. package/dist/app/assets/screens-aIjMSzZg.js +0 -16
  53. package/dist/app/assets/share-BzIzB4EY.js +0 -8
  54. package/dist/app/assets/space-DWgrlnfB.js +0 -1
  55. package/dist/app/assets/styles-BA1aVO9R.css +0 -1
  56. package/dist/app/assets/templates-CoNTzuuz.js +0 -2
  57. package/dist/app/demo/run.txt +0 -1
@@ -0,0 +1,4 @@
1
+ import{a as e,c as t,t as n}from"./index-B5ZkSF4L.js";import{C as r,D as i,Kt as a,T as o,Xt as s,Yt as c,an as l,qt as u,tn as d,w as f}from"./share-DV3wsAsJ.js";import{t as p}from"./full-C0asYORc.js";var m={agent:[`agent`,`Agent`],check:[`check`,`Check`],"human-gate":[`gate`,`Human gate`],merge:[`gate`,`Merge`],stop:[`stop`,`Stop`]};function h(e){let t=e.groups??[],n=new Map(t.map(e=>[e,t.filter(t=>t.id!==e.id&&e.members.includes(t.id))])),r=new Map(t.map(e=>{let t=new Set,r=new Set([e]);for(let i=[...n.get(e)];i.length;){let e=i.pop();t.add(e.id),r.has(e)||(r.add(e),i.push(...n.get(e)))}return[e,t]})),i=new Map,a=e=>{if(i.has(e))return i.get(e);let n=t.filter(t=>t.id!==e&&t.members.includes(e)),a=(n.find(e=>!n.some(t=>t.id!==e.id&&r.get(e).has(t.id)))??n[0])?.id??null;return i.set(e,a),a},o=(n,r)=>r.has(n)?[]:(r.add(n),[...e.nodes.filter(e=>a(e.id)===n).map(e=>e.id),...t.filter(e=>a(e.id)===n).flatMap(e=>o(e.id,r))]);return t.map(e=>({id:e.id,name:e.name||e.id,from:e.from??null,nodes:o(e.id,new Set),inside:a(e.id)}))}var g=e=>e<640?2:4;function _(e,t,n,r=!1){let o=f(e),p=new Map(o.flat().map((e,t)=>[e,t])),g=t,_=t=>e.nodes.some(e=>e.id===t),v=t=>e.nodes.find(e=>e.id===t)?.name||t,b=e=>e.members.filter(_),x=t=>b(t).length?e.loops.filter(e=>e.id!==t.id&&b(e).length>b(t).length&&b(t).every(t=>e.members.includes(t))).sort((e,t)=>b(e).length-b(t).length)[0]?.id??null:null,S=e.loops.map(t=>{let n=e=>t.stops.find(t=>t.kind===e),r=n(`budget`),i=t.stops.flatMap(e=>e.kind===`max-iterations`?[e.n]:[]),a=t.stops.flatMap(e=>e.kind===`budget`&&e.measure===`dispatches`?[e.limit]:[]);return{id:t.id,name:t.name||t.id,inside:x(t),members:b(t).sort((e,t)=>(p.get(e)??0)-(p.get(t)??0)),own:[],back:t.back,stops:t.stops.map(u),brakes:t.stops.flatMap(e=>e.kind===`max-iterations`?[{kind:e.kind,n:e.n}]:e.kind===`budget`?[{kind:e.kind,measure:e.measure,limit:e.limit}]:e.kind===`human`?[{kind:e.kind,every:e.every??null}]:[]),cap:i.length?i.reduce((e,t)=>Math.min(e,t)):null,budget:r?{measure:r.measure,limit:r.limit}:null,dispatches:a.length?a.reduce((e,t)=>Math.min(e,t)):null,human:n(`human`)?.every??null,perRound:t.members.map(t=>e.nodes.find(e=>e.id===t)).filter(e=>e?.kind===`check`||e?.kind===`agent`&&e.role!==`lead`&&!d(e)).length}}),C=e=>S.filter(t=>t.members.includes(e)).sort((e,t)=>e.members.length-t.members.length)[0]?.id??null;for(let e of S)e.own=e.members.filter(t=>C(t)===e.id);let w=new Map(e.loops.flatMap(e=>e.back.map(t=>[t,e.id]))),T=e.edges.filter(e=>_(e.from)&&_(e.to)),E=T.filter(e=>!w.has(e.id)&&p.has(e.from)&&p.has(e.to)).sort((e,t)=>p.get(e.from)-p.get(t.from)||p.get(e.to)-p.get(t.to)),D=[...w].flatMap(([e,t])=>T.filter(t=>t.id===e&&p.has(t.from)&&p.has(t.to)).map(e=>({e,loop:t}))),O={narrow:r,id:e.id,name:e.name||e.id,rows:o,nodes:e.nodes.map(e=>({id:e.id,name:e.name||e.id,kind:d(e)?`person`:m[e.kind][0],word:d(e)?a.person:m[e.kind][1],line:e.kind===`agent`?d(e)?`${a.person} · ${l(e)}`:[l(e),e.model?.tier??`session default`,e.effort].filter(Boolean).join(` · `):m[e.kind][1],tier:e.kind===`agent`&&!d(e)?e.model?.tier??`unset`:null,loop:C(e.id),at:[g[e.id]?.x??0,g[e.id]?.y??0]})),edges:T.map(e=>({id:e.id,from:e.from,to:e.to,when:c(e)?s(e):``,back:w.get(e.id)??null,on:e.when})),loops:S,groups:h(e),pass:[...E.map(e=>({e,loop:null})),...D].map(({e,loop:t})=>({edge:e.id,loop:t,says:`${e.from===e.to?`${v(e.from)} to itself`:`${v(e.from)} to ${v(e.to)}`}${c(e)===`always`?``:` · when ${s(e)}`}${t?` · back into ${S.find(e=>e.id===t).name}: another round, until ${S.find(e=>e.id===t).stops.join(`; `)}`:``}`}))};if(n?.length){let t=i(n,e),r=new Map,a=[],o=e=>!!S.find(t=>t.id===e)?.inside,s=(e,t)=>{for(let n=S.find(t=>t.id===e)?.inside;n;n=S.find(e=>e.id===n)?.inside)if(n===t)return!0;return!1},c=Object.create(null),l=Object.create(null),u=y(O.edges),f=!1;for(let{focus:e,note:n}of t.steps.slice(1))if(e&&n){if(e.kind===`node`&&_(e.id)){let t=C(e.id),r=u.into(e.id).flatMap(e=>e.back?[e.back]:[]);for(let e of S)r.some(t=>s(e.id,t))&&delete l[e.id];t&&o(t)&&n.round!==void 0&&(f||=r.some(e=>s(t,e))?n.round!==0:r.includes(t)&&n.round<=(l[t]??-1),c[t]=l[t]=n.round),u.at(e.id,{round:null,outcome:n.outcome??null,verdict:n.verdict??null,open:n.outcome===`started`})}else e.kind===`loop`&&(n.round!==void 0&&(f||=n.round>(c[e.id]??n.round),c[e.id]=void 0),n.stop!==void 0&&u.stopped(e.id,n.stop===`human`))}let p=Object.create(null),m=Object.create(null),h=y(O.edges),g=t.steps.slice(1).map(t=>{let n=t.note,i=t.focus??{kind:`graph`},c=i.kind===`graph`||(i.kind===`node`?_(i.id):i.kind===`edge`?T.some(e=>e.id===i.id):S.some(e=>e.id===i.id))?i:{kind:`graph`},l=n.proposal?.summary??n.amendment?.summary??n.text??``,u=c.kind===`node`?e.nodes.find(e=>e.id===c.id):void 0,g=u?C(u.id):c.kind===`loop`?c.id:null,v=f&&u&&o(g)?void 0:n.round;for(let e of new Set(u?h.into(u.id).flatMap(e=>e.back?[e.back]:[]):[])){(e!==g||v===void 0)&&(p[e]=(p[e]??0)+1);for(let t of S)s(t.id,e)&&(p[t.id]=0)}let y=g?p[g]=v??p[g]??0:null;u&&h.at(u.id,{round:y,outcome:n.outcome??null,verdict:n.verdict??null,open:n.outcome===`started`}),c.kind===`loop`&&n.stop!==void 0&&h.stopped(c.id,n.stop===`human`);for(let e in p)m[e]=Math.max(m[e]??0,p[e]);let b={says:t.caption,about:c.kind,id:`id`in c?c.id:null,round:y,outcome:n.outcome??null,verdict:n.verdict??null,what:n.proposal?`proposal`:n.amendment?`amendment`:null,open:n.outcome===`started`,stop:c.kind===`loop`?n.stop??null:null,words:l.length>150?`${l.slice(0,l.lastIndexOf(` `,150))} …`:l};if(u&&(u.kind===`agent`||u.kind===`check`)&&!d(u)&&n.outcome&&n.outcome!==`started`){let e=e=>(Date.parse(n.ended??``)-Date.parse(e??``))/6e4,t=e(n.started)>=0?e(n.started):e(r.get(u.id));b.dispatch=a.push({node:u.id,loop:g,round:y,outcome:n.outcome??null,minutes:t>=0?t:null})-1,r.delete(u.id)}else u&&n.outcome===`started`&&n.started&&r.set(u.id,n.started);return b});O.run={end:t.end.line,at:t.end.at&&_(t.end.at.id)?t.end.at.id:null,dispatches:a,most:m,notes:g,rounds:Object.assign(Object.create(null),Object.fromEntries(t.end.loops.map(e=>[e.loop,e.round??-1])))}}return O}function v(e,t,n){for(let r=e.find(e=>e.id===t)?.inside??null,i=0;r&&i<=e.length;r=e.find(e=>e.id===r)?.inside??null,i+=1)if(r===n)return!0;return!1}function y(e){let t=new Map,n=new Map,[r,i,a,o]=[0,null,null,null];return{into(r,s){if(a===r)return[];let c=n.get(r)??-1;return[...t].filter(([e,t])=>!t.open&&(e===r||t.k>c)).sort(([e,t],[n,r])=>Number(n===i)-Number(e===i)||r.k-t.k).flatMap(([t,n])=>{let i=e.filter(e=>e.from===t&&e.to===r&&!(e.back&&n.not.has(e.back)&&(s||e.back!==o))),a=i.find(e=>typeof e.on==`object`&&e.on.verdict===n.verdict)??i.find(e=>typeof e.on==`string`&&e.on===n.routes)??i.find(e=>e.on===void 0||e.on===`always`);return a?[{...a,r0:n.round??0}]:[]})},at(e,s){r+=1;let c=t.get(e);(s.open?!c||c.open:(s.outcome??s.verdict)!==null)&&t.set(e,{...s,k:r,routes:s.outcome===`invalid-evidence`&&c?.outcome===`invalid-evidence`&&!c.open&&c.round===s.round?`fail`:s.outcome,not:new Set}),n.set(e,r),[i,a,o]=[e,s.open?e:null,s.open||(s.outcome??s.verdict)!==null?null:o]},stopped(e,n){for(let n of t.values())n.not.add(e);(n||o===e)&&(o=n?e:null)}}}function b(e){let t=t=>e.edges.find(e=>e.id===t);if(!e.run)return e.pass.length?[{says:e.pass.length===1?`The graph's one edge is lit.`:`All ${e.pass.length} steps are lit. Move the slider or press Play to follow a first pass, one edge at a time.`},...e.pass.map((n,r)=>{let i=t(n.edge);return{says:`Step ${r+1} of ${e.pass.length}: ${n.says}`,edge:i.id,nodes:[i.from,i.to],from:i.from,to:i.to,r0:0,r1:+!!n.loop,...n.loop?{loops:[]}:{}}})]:[{says:`This graph has no edges to step through.`}];let{notes:n,dispatches:r,end:i}=e.run,a=e.loops.flatMap(e=>{let t=[...new Set(r.flatMap(t=>t.loop===e.id&&t.round!==null?[t.round]:[]))];return t.length?[`round${t.length===1?``:`s`} ${t.length>2?`${t.slice(0,-1).join(`, `)} and ${t[t.length-1]}`:t.join(` and `)} of ${e.name}`]:[]}),o=[{says:`The whole run: ${r.length} dispatch${r.length===1?``:`es`}${a.length?`, in ${a.join(`; `)}`:``}. ${i} Move the slider or press Play to follow its ${n.length} notes.`}],s=y(e.edges),c=0,l=null;n.forEach((t,r)=>{let i=`Note ${r+1} of ${n.length}`,a={says:``,...t.dispatch===void 0?{}:{dispatch:t.dispatch}};if(t.about===`node`&&t.id){let e=t.round??0,[n,...r]=s.into(t.id);Object.assign(a,{says:`${i}: ${t.says}`,nodes:[t.id],to:t.id,r1:e},n?{edge:n.id,from:n.from,r0:n.r0}:{},r.length?{also:r.map(e=>({edge:e.id,r0:e.r0}))}:{}),s.at(t.id,{round:t.round,outcome:t.outcome,verdict:t.verdict,open:t.open}),[c,l]=[e,t.id]}else if(t.about===`loop`&&t.id)Object.assign(a,{says:`${i}: ${t.says}`,loops:[t.id]}),t.stop&&s.stopped(t.id,t.stop===`human`);else if(t.about===`edge`&&t.id){let n=e.edges.find(e=>e.id===t.id);Object.assign(a,{says:t.what?`${i}, a ${t.what} about the edge ${t.says}, not a move along it: ${t.words}`:`${i}, at the edge ${t.says}: ${t.words}`},n?{edge:n.id,nodes:[n.from,n.to],about:!0,r0:c}:{})}else a.says=`${i}, ${t.what?`an ${t.what}`:`about the run`}: ${t.words}`;o.push(a)});let u=o[n.map(e=>e.about===`graph`&&e.outcome!==null).lastIndexOf(!0)+1],d=e.run.at;if(d&&d!==l&&u!==o[0]&&!u.nodes&&!u.edge&&!u.loops){let[e,...t]=s.into(d,!0);e&&Object.assign(u,{nodes:[d],to:d,edge:e.id,from:e.from,r0:e.r0,r1:0},t.length?{also:t.map(e=>({edge:e.id,r0:e.r0}))}:{})}return o}var x=Math.PI*2,S=(e,t,n)=>[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n,e[2]+(t[2]-e[2])*n],C=(e,t)=>e.find(e=>e.id===t),w=(e,t)=>`loop-${e.loops.findIndex(e=>e.id===t)%4}`,T=(e,t,n={stand:!0})=>({t:`card`,at:t,id:e.id,key:`node:${e.id}`,...n}),E=(e,t,n,r=40,i=0,a=x)=>Array.from({length:r+1},(o,s)=>[e[0]+t*Math.cos(i+(a-i)*s/r),n,e[2]+t*Math.sin(i+(a-i)*s/r)]),D=e=>{let t=new Map(e.rows.flat().map((e,t)=>[e,t]));return n=>t.get(n)??e.rows.flat().length};function O(e,t){let n=D(e),r=e.loops.filter(e=>e.inside===t.id),i=t.members.filter(e=>!t.own.includes(e)&&!r.some(t=>t.members.includes(e)));return[...t.own.map(e=>({node:e,first:n(e)})),...r.map(e=>({loop:e,first:Math.min(...e.members.map(n))})),...i.map(e=>({away:e,first:n(e)}))].sort((e,t)=>e.first-t.first)}var k=(e,t)=>e.findIndex(e=>e.node===t||e.away===t||!!e.loop?.members.includes(t));function A(e){let t=D(e);return[...e.nodes.filter(e=>!e.loop).map(e=>({node:e.id,first:t(e.id)})),...e.loops.filter(e=>!e.inside).map(e=>({loop:e,first:Math.min(...e.members.map(t))}))].sort((e,t)=>e.first-t.first)}var j=(e,t,n,r=16)=>Array.from({length:r+1},(i,a)=>{let o=S(e,t,a/r);return[o[0],o[1]+n*4*(a/r)*(1-a/r),o[2]]}),M=(e,t,n,r={})=>({t:`line`,pts:n,stroke:t.back?w(e,t.back):`ink-2`,...t.back?{dash:[6,4]}:{},w:t.back?1.8:1.4,arrow:!0,key:`edge:${t.id}`,inset:[2,1],from:t.from,to:t.to,...r}),N=(e,t)=>{let n=Math.max(0,Math.min(1,t))*(e.length-1),r=Math.min(e.length-2,Math.floor(n));return e.length<2?e[0]:S(e[r],e[r+1],n-r)};function P(e,t,n){let[r,i]=[{},{}];for(let a of t.slice(1,n+1)){let t=a.to;if(!t)continue;let n=new Set(a.about?[]:[a.edge,...(a.also??[]).map(e=>e.edge)].flatMap(t=>e.edges.find(e=>e.id===t)?.back??[]));for(let t of n)for(let n of e.loops)v(e.loops,n.id,t)&&(i[n.id]=0);for(let o of e.loops){if(!o.members.includes(t))continue;o.own.includes(t)?i[o.id]=a.r1??0:i[o.id]=(i[o.id]??0)+ +!!n.has(o.id);let s=O(e,o),c=i[o.id]+Math.max(0,k(s,t))/s.length;r[o.id]={now:c,most:Math.max(c,r[o.id]?.most??0)}}}return r}function F(e,t,n){let r=t[n],i=e=>e.edge&&!e.about?[{edge:e.edge,r0:e.r0??0},...e.also??[]].map(t=>({...t,r1:e.r1??0})):[],a=r.about&&r.edge?[`edge:${r.edge}`]:i(r).flatMap(e=>[`edge:${e.edge}`,`edge:${e.edge}@${e.r0}>${e.r1}`]),o=[...(r.nodes??[]).map(e=>`node:${e}`),...a,...(r.loops??[]).map(e=>`loop:${e}`)],s={k:n,lit:o.length?new Set(o):null,took:e.run?t.flatMap((e,t)=>i(e).map(e=>({...e,step:t}))):[]};return r.about&&r.edge&&(s.about={edge:r.edge,r0:r.r0??0}),e.run&&n>0&&(s.dispatches=t.slice(1,n+1).filter(e=>e.dispatch!==void 0).length),e.run&&(s.until=P(e,t,n||t.length-1)),s}var I=84,[L,R]=[.8,.4];function z(e,t){let n=[...e.map(e=>({loop:e,name:e.name,ids:e.members,sub:`loop`,depth:0})),...t.filter(e=>e.from).map(e=>({group:e,name:e.name,ids:e.nodes,sub:`subgrooph, from ${e.from}`,depth:0}))].filter(e=>e.ids.length>0),r=(e,t,n)=>{for(let r=t.inside,i=0;r&&i<=e.length;r=e.find(e=>e.id===r)?.inside??null,i+=1)if(r===n.id)return!0;return!1},i=(e,t)=>e.ids.every(e=>t.ids.includes(e)),a=(n,a)=>n!==a&&(n.loop&&a.loop?r(e,a.loop,n.loop):n.group&&a.group?r(t,a.group,n.group):n.group?i(a,n):i(a,n)&&n.ids.length>a.ids.length);for(let e of n)e.depth=n.filter(t=>a(t,e)).length+1;return n}var B={yaw:-.86,pitch:.16},V=e=>{let t=[],n=Object.create(null),r=z(e.loops,e.groups),i=e=>Math.max(0,...r.filter(t=>t.ids.includes(e)).map(e=>e.depth));for(let t of e.nodes)n[t.id]=[t.at[0]*L,-t.at[1]*R,i(t.id)*I];for(let r of e.nodes)t.push(T(r,n[r.id],{moves:[[L,0,0],[0,-R,0]]}));let a=(e,t)=>{let r=e.map(e=>n[e]);return[Math.min(...r.map(e=>e[0]))-58-t,Math.max(...r.map(e=>e[0]))+58+t,Math.min(...r.map(e=>e[1]))-22-t,Math.max(...r.map(e=>e[1]))+22+t]},[o,s,c,l]=a(e.nodes.map(e=>e.id),42);t.push({t:`poly`,pts:[[o,c,-8],[s,c,-8],[s,l,-8],[o,l,-8]],fill:`floor`,fa:.7,stroke:`line-strong`,lift:-600}),t.push({t:`text`,at:[o+4,l+10,-8],text:`the picture`,fill:`ink-3`,size:10});for(let n of r){let[r,i,o,s]=a(n.ids,8+(4-Math.min(4,n.depth))*9),c=n.depth*I-12,l=n.loop?w(e,n.loop.id):`ink-3`;t.push({t:`poly`,pts:[[r,o,c],[i,o,c],[i,s,c],[r,s,c]],fill:l,fa:n.loop?.15:.08,stroke:l,...n.loop?{key:`loop:${n.loop.id}`}:{dash:[5,4]},w:1.3,lift:n.depth*30-80});let[u,d]=[[[r+4,s+10,c],[i-4,s+10,c]],[[r+4,o-10,c],[i-4,o-10,c]]],[f,p]=n.depth%2?[u,d]:[d,u];t.push({t:`text`,at:f[0],text:`${n.name} · ${n.sub}`,fill:l,size:10.5,bold:!0,max:200,or:[{at:f[1],align:`right`},{at:p[0]},{at:p[1],align:`right`},{at:[r-6,(o+s)/2,c],align:`right`},{at:[i+6,(o+s)/2,c]}]}),t.push({t:`line`,pts:[[r,o,-8],[i,o,-8],[i,s,-8],[r,s,-8],[r,o,-8]],stroke:l,w:1,dash:[2,4],alpha:.6})}let u=Object.create(null);return e.edges.forEach((r,i)=>{let[a,o]=[n[r.from],n[r.to]],s=e.edges.slice(0,i).filter(e=>e.from===r.from&&e.to===r.to||e.from===r.to&&e.to===r.from).length,c=r.back||r.from===r.to,l=(c?70+Math.abs(a[1]-o[1])*.2:0)+22*s,d=c?50:0,[f,p]=r.from===r.to?[1,0]:[o[1]-a[1],a[0]-o[0]],m=(f<0||!f&&p>0?-l:l)/(Math.hypot(f,p)||1);u[r.id]=l?Array.from({length:19},(e,t)=>(e=>[e[0]+m*f*4*(t/18)*(1-t/18),e[1]+m*p*4*(t/18)*(1-t/18),e[2]])(S([a[0]+d,a[1],a[2]],[o[0]+d,o[1],o[2]],t/18))):[a,o],t.push(M(e,r,u[r.id],{inset:[4,8]}))}),{prims:t,node:e=>n[e],path:e=>u[e]}},H=54,U=(e,t)=>{let n=t.cap??Math.max(e.run?(e.run.most[t.id]??-1)+1:1,1)+2;return Number.isFinite(n)?Math.min(50,Math.max(1,n)):50};function W(e,t){let n=e.cap,r=e.brakes.findIndex(e=>e.kind===`max-iterations`&&e.n===n),i=e.brakes.map((e,i)=>{if(e.kind!==`human`||!e.every||!(e.every>=1))return null;let a=Array.from({length:Math.floor(t/e.every)},(t,n)=>(n+1)*e.every);return{within:a,drawn:a.filter(e=>n===null||e<n||e===n&&i<r)}}),a=[...new Set(i.flatMap(e=>e?.drawn??[]))].sort((e,t)=>e-t),o=e.dispatches!==null&&e.perRound?e.dispatches/e.perRound:null,s=o!==null&&o<=t+1.5?o:null,c=e.brakes.map((r,a)=>{if(r.kind===`max-iterations`)return`max iterations: ${r.n}${r.n===n?` (the lid, over round ${r.n-1}${r.n>t?`: not drawn, above the ${t} rounds shown`:``})`:` (a looser cap: the lid stops the loop first)`}`;if(r.kind===`human`){let e=i[a];if(!e)return`human halt (no place on the way up)`;let t=e.drawn.length?`the amber ring${e.drawn.length===1?``:`s`}`:e.within.length?`no ring: only at the lid, where the cap is looked at first`:`not within the rounds drawn`;return`a person is asked every ${r.every===1?`round`:`${r.every} rounds`} (${t})`}if(r.measure!==`dispatches`||!e.perRound)return`budget: ${r.limit} ${r.measure} (no place on the way up)`;let[o,c]=[Math.floor(r.limit/e.perRound),r.limit%e.perRound];return`budget: ${r.limit} dispatches, at most ${o} full round${o===1?``:`s`}${c?` and ${c} more`:``}${r.limit===e.dispatches?s===null?` (not drawn: above the rounds shown)`:` (the dashed ring, a reading)`:` (a looser budget)`}`});return n===null&&c.unshift(`no lid: no cap on rounds`),{words:c,lid:n,asked:a,budget:s}}var G=e=>e===`pass`?`ok`:e===`fail`?`bad`:`ink-3`,K={yaw:-.42,pitch:.3},q=(e,t)=>{let n=[],r=Object.create(null),i=Object.create(null),a=t=>Math.max(e.narrow?76:64,O(e,t).length*(e.narrow?31:27)),o=(e,t,n=0)=>[e.c[0]-(e.r+n)*Math.cos(x*t),e.c[1]+t*H,e.c[2]+(e.r+n)*Math.sin(x*t)],s=(e,t,n)=>{let r=Math.max(1,Math.ceil(Math.abs(n-t)*36));return Array.from({length:r+1},(i,a)=>o(e,t+(n-t)*a/r))};function c(c,l){let u=O(e,c),d=Math.max(1,u.length),f=i[c.id]={c:l,r:a(c),stops:u,k:d},p=w(e,c.id),m=e.run?t.until?.[c.id]??null:null,h=e.run?m?.most??null:(d-1)/d,g=U(e,c);n.push({t:`poly`,pts:E(l,f.r+12,l[1]),fill:`floor`,fa:.8,stroke:`line`,lift:-400}),n.push({t:`line`,pts:[[l[0],l[1],l[2]],[l[0],l[1]+g*H,l[2]]],stroke:`line-strong`,w:1}),n.push({t:`line`,pts:s(f,0,g),stroke:p,w:1.3,alpha:.5,dash:[3,4]}),h!==null&&h>0&&n.push({t:`line`,pts:s(f,0,Math.min(h,g)),stroke:p,w:3.2,key:`loop:${c.id}`});let _=W(c,g);_.lid!==null&&_.lid<=g&&n.push({t:`poly`,pts:E(l,f.r+18,l[1]+_.lid*H),fill:`brake`,fa:.24,stroke:`brake`,w:1.8,lift:300});for(let e of _.asked)n.push({t:`line`,pts:E(l,f.r+(e===_.lid?9:18),l[1]+e*H),stroke:`k-gate`,w:2.2,lift:320});_.budget!==null&&n.push({t:`line`,pts:E(l,f.r+18,l[1]+_.budget*H),stroke:`brake`,w:1.2,dash:[4,4],alpha:.85});let v=Math.max(g,_.budget??0),y=e.run?m===null?`
2
+ not entered`:`\nround ${Math.floor(m.now)}${c.cap?`, lid over round ${c.cap-1}`:``}`:``;n.push({t:`text`,at:[l[0],l[1]+v*H+46,l[2]],text:`${c.name}${y}`,align:`center`,up:!0,fill:p,size:11,bold:!0,max:Math.max(120,2*f.r+30)}),u.forEach((t,i)=>{if(t.node){let a=o(f,i/d,46);r[t.node]=[a[0],a[1]-30,a[2]],n.push(T(C(e.nodes,t.node),r[t.node],{stand:!0,small:e.narrow}),{t:`line`,pts:[o(f,i/d),o(f,i/d,30)],stroke:p,w:1,alpha:.7})}else t.loop?n.push({t:`text`,at:o(f,i/d,e.narrow?84:34),text:`${t.loop.name}: the spiral ${e.narrow?`above`:`beside`}`,align:`center`,fill:w(e,t.loop.id),size:10.5,bold:!0,max:96}):t.away&&n.push({t:`text`,at:o(f,i/d,34),text:`${C(e.nodes,t.away).name}: on ${C(e.loops,C(e.nodes,t.away).loop).name}`,align:`center`,fill:`ink-3`,size:10.5,max:96})});let b=(e.run?.dispatches??[]).flatMap((e,n)=>{let r=u.findIndex(t=>t.node===e.node);return r<0||e.round===null?[]:[{d:e,i:r,round:e.round,shown:t.dispatches===void 0||n<t.dispatches}]}),x=new Map,S=new Map;for(let{i:e,round:t}of b)S.set(`${t}:${e}`,(S.get(`${t}:${e}`)??0)+1);for(let{d:e,i:t,round:r,shown:i}of b){let a=`${r}:${t}`,s=(x.get(a)??-1)+1;x.set(a,s);let c=Math.min(13,(f.r-10)/Math.max(1,S.get(a)-1));i&&r<g&&n.push({t:`dot`,at:o(f,r+t/d,-c*s),r:6,fill:G(e.outcome),stroke:`card`})}}let l=[],u=t=>(e.loops.filter(e=>e.inside===t.id).forEach(u),void l.push({loop:t,first:0}));for(let t of A(e))t.loop?u(t.loop):l.push(t);let d=l.findIndex(e=>e.loop),f=l.length-1-[...l].reverse().findIndex(e=>e.loop),p=0;if(e.narrow&&d>=0){let t=0;for(let n of l){let i=n.loop?U(e,n.loop):0,[o,s]=n.loop?[Math.max(i,W(n.loop,i).budget??0)*H+96,.3*(a(n.loop)+50)+56]:[23,23];t+=o,n.loop?c(n.loop,[0,-t,0]):r[n.node]=[-60,-t,0],t+=s}}else l.forEach((e,t)=>{if(e.loop){let t=a(e.loop)+40;c(e.loop,[p+t,0,0]),p+=2*t+56}else d>=0&&t>d&&t<f&&(r[e.node]=[p+20,0,130],p+=190)});e.narrow&&d>=0||(d>=0?(l.slice(0,d).reverse().forEach((e,t)=>r[e.node]=[-170-t*56,0,-230-t*124]),l.slice(f+1).forEach((e,t)=>r[e.node]=[p-6+t*20,0,130+t*124])):(l.forEach((t,n)=>r[t.node]=e.narrow?[0,(l.length-1-n)*52,0]:[n*20,0,(n-(l.length-1)/2)*150]),n.push({t:`text`,at:e.narrow?[60,l.length*52+10,0]:[10*l.length,60,-75*l.length],text:`No loop in this graph: nothing goes round, and there is no spiral to draw.`,align:`center`,up:!0,fill:`ink-3`,size:11,max:220})));for(let t of l)t.node&&n.push(T(C(e.nodes,t.node),r[t.node],{stand:!0,side:!0,small:d>=0}),{t:`dot`,at:r[t.node],r:3,fill:`ink-2`,lift:-3990});let m=(t,n=0)=>{let a=e.loops.find(n=>n.id===C(e.nodes,t).loop),s=a&&i[a.id],c=s?s.stops.findIndex(e=>e.node===t):-1;return s&&c>=0?o(s,n+c/s.k):r[t]},h=t=>e.loops.find(e=>e.own.includes(t.from)&&e.own.includes(t.to)),g=(t,n=0,r=0)=>{let a=C(e.edges,t),c=e.edges.slice(0,e.edges.indexOf(a)).filter(e=>e.from===a.from&&e.to===a.to).length,u=h(a);if(u){let t=i[u.id],[l,d]=[t.stops.findIndex(e=>e.node===a.from),t.stops.findIndex(e=>e.node===a.to)],f=a.back===u.id;if(!a.back&&d===l+1||f&&l===t.k-1&&d===0)return s(t,n+l/t.k,(f?n+1:r)+d/t.k);let p=!a.back||f?r:v(e.loops,u.id,a.back)?0:e.run?r:n;return j(o(t,n+l/t.k),o(t,p+d/t.k),26+14*c,18)}let d=(t,n)=>C(e.nodes,t).loop?n:0,f=C(e.nodes,a.to).loop,p=a.back?f&&v(e.loops,f,a.back)?0:f===a.back||e.run?d(a.to,r):0:d(a.to,r),g=e=>l.findIndex(t=>t.node===e||!!t.loop?.own.includes(e)),[_,y]=[g(a.from),g(a.to)].sort((e,t)=>e-t),b=C(e.nodes,a.from).loop&&f?0:26*l.slice(_+1,y).filter(e=>e.node).length,[x,S]=[m(a.from,d(a.from,n)),m(a.to,p)];if(!e.narrow)return j(x,S,(a.back?40:b)+14*c,18);let w=e=>e.own.includes(a.from)||e.own.includes(a.to),T=e.loops.flatMap(t=>[i[t.id].c[1]+U(e,t)*H,...w(t)&&Math.abs((t.own.includes(a.from)?x:S)[1]-i[t.id].c[1])>=H?[i[t.id].c[1]]:[]].map(e=>({loop:t,u:(e-x[1])/(S[1]-x[1]||1)}))).filter(e=>e.u>0&&e.u<1),E=T.find(e=>w(e.loop))?.loop,D=!b&&(E?(E.own.includes(a.from)?x:S)[0]>0:x[0]>0&&S[0]>0)?1:-1,O=a.back?40:b*1.3;for(let{loop:e,u:t}of T)O=Math.max(O,(i[e.id].r+30-D*(x[0]+(S[0]-x[0])*t))/Math.max(.36,4*t*(1-t)));return O+=26*c+12*n+10*r,j(x,S,0,18).map((e,t)=>[e[0]+D*O*4*(t/18)*(1-t/18),e[1],e[2]])},_=new Set,y=(r,a,o,s={})=>{let c=`edge:${r.id}@${a}>${o}`;if(_.has(c))return;_.add(c);let l=r.back?void 0:h(r),u=l&&i[l.id],d=!!u&&u.stops.findIndex(e=>e.node===r.to)===u.stops.findIndex(e=>e.node===r.from)+1;n.push(M(e,r,g(r.id,a,o),{key:c,...d&&l?{hide:!t.lit?.has(c),stroke:w(e,l.id),w:3.2}:{},...s}))};for(let n of e.edges){let r=t.took.filter(e=>e.edge===n.id&&(t.k===0||e.step<=t.k));if(!e.run)y(n,0,+!!n.back);else if(r.length)for(let e of r)y(n,e.r0,e.r1);else t.took.some(e=>e.edge===n.id)||y(n,0,+!!n.back,{alpha:.3})}if(t.about){let r=C(e.edges,t.about.edge);n.some(e=>e.key?.startsWith(`edge:${r.id}@`))||y(r,0,+!!r.back,{alpha:.3});for(let e of n)e.key?.startsWith(`edge:${r.id}@`)&&(e.hide=!1,t.lit?.add(e.key))}for(let e of n)e.t!==`card`&&(e.grow=!0);return{prims:n,node:m,path:g}};function ee(e,t,n){let r=(e,t)=>{let n=[...e],r=t;for(;n.length>2&&r>0;){let e=Math.hypot(n[1][0]-n[0][0],n[1][1]-n[0][1]);if(e>r)break;r-=e,n.shift()}let i=Math.hypot(n[1][0]-n[0][0],n[1][1]-n[0][1]);return i>r+1&&(n[0]=[n[0][0]+(n[1][0]-n[0][0])*r/i,n[0][1]+(n[1][1]-n[0][1])*r/i]),n};return r(r(e,t).reverse(),n).reverse()}function J(e,[t,n,r,i]){let a=e=>e[0]>t&&e[0]<t+r&&e[1]>n&&e[1]<n+i;if(e.length<2||!a(e[e.length-1]))return null;let o=e.length-1;for(;o>0&&a(e[o-1]);)--o;if(o===0)return null;let[s,c]=[e[o-1],e[o]],[l,u]=[0,1];for(let e=0;e<12;e+=1)a([s[0]+(c[0]-s[0])*((l+u)/2),s[1]+(c[1]-s[1])*((l+u)/2)])?u=(l+u)/2:l=(l+u)/2;return[...e.slice(0,o),[s[0]+(c[0]-s[0])*l,s[1]+(c[1]-s[1])*l]]}function Y(e){let[t,n]=[1/0,-1/0];for(let r of e)[t,n]=[Math.min(t,r),Math.max(n,r)];return[t,n]}var X=t(e(),1),Z=`.s3{grid-template-rows:auto minmax(var(--s3-tall,180px), 1fr);min-height:100%;font:13px/1.4 var(--font);color:var(--ink);grid-auto-rows:min-content;gap:10px;padding:0 12px;display:grid}.s3-bar,.s3-steps{flex-wrap:wrap;align-items:center;gap:6px;display:flex}.s3-bar span{color:var(--ink-3);text-wrap:pretty;flex:8rem;font-size:12.5px}.s3 button:not(.s3-card){border:1px solid var(--line-strong);background:var(--surface);min-width:40px;min-height:40px;color:var(--ink);font:600 13px/1 var(--font);cursor:pointer;border-radius:10px;padding:0 12px}.s3 button.is-on{border-color:var(--accent);background:var(--accent-soft)}.s3-steps input{min-width:0;height:40px;accent-color:var(--accent);flex:8rem}.s3-frame{border:1px solid var(--line);background:var(--bg);touch-action:none;cursor:grab;-webkit-user-select:none;user-select:none;border-radius:14px;min-height:0;position:relative;overflow:hidden}.s3-frame:active{cursor:grabbing}.s3-frame[data-moves] .s3-card{cursor:grab}.s3-frame:focus-visible{outline:2px solid var(--focus);outline-offset:2px}.s3-frame canvas{width:100%;height:100%;position:absolute;inset:0}.s3-card{transform-origin:0 0;border:1px solid var(--line-strong);border-left:4px solid var(--kind-stop);background:var(--surface);width:106px;color:var(--ink);font:inherit;text-align:left;cursor:pointer;border-radius:7px;padding:4px 6px 5px 9px;position:absolute;top:0;left:0}.s3-card[data-kind=agent]{border-left-color:var(--kind-agent)}.s3-card[data-kind=check]{border-left-color:var(--kind-check)}.s3-card[data-kind=person],.s3-card[data-kind=gate]{border-left-color:var(--kind-human-gate)}.s3-card b,.s3-card span{white-space:nowrap;text-overflow:ellipsis;display:block;overflow:hidden}.s3-card b{-webkit-line-clamp:2;white-space:normal;overflow-wrap:anywhere;-webkit-box-orient:vertical;display:-webkit-box}.s3-bar .s3-tight,.s3[data-tight] .s3-bar span:first-child{display:none}.s3[data-tight] .s3-bar .s3-tight{color:var(--ink);display:block}.s3-card b{font-size:11.5px;font-weight:600;line-height:1.25}.s3-card span{color:var(--ink-3);font-size:9.5px;line-height:1.3}.s3-card.is-small{width:max-content;min-width:56px;max-width:150px;padding-block:3px}.s3-card.is-small span{display:none}.s3-card.is-small[data-kind=person] span{display:block}.s3-card.is-small b{white-space:nowrap;display:block}.s3-card.is-lit{border-color:var(--accent);background:var(--accent-soft);box-shadow:0 0 0 1px var(--accent)}.s3-token{z-index:100000;box-sizing:border-box;border:3px solid var(--accent);pointer-events:none;border-radius:50%;position:absolute;top:0;left:0}.s3-card.is-dim{opacity:.62}.s3-card:focus-visible{outline:2px solid var(--focus);outline-offset:2px}.s3-says{text-wrap:pretty;min-height:2.8em;display:block}.s3[data-kind=spiral]{grid-template-rows:auto minmax(max(330px, var(--s3-tall,0px)), 1fr)}.s3-key{color:var(--ink-2);text-wrap:pretty;gap:4px;margin:0;padding:0;font-size:12.5px;list-style:none;display:grid}.s3-note{color:var(--ink-3);text-wrap:pretty;margin:0;font-size:12.5px}.s3-more{gap:8px;font-size:12.5px;display:grid}.s3-more>summary{width:max-content;min-height:32px;color:var(--ink-2);cursor:pointer;padding:6px 0;font-weight:600}`,te=Math.PI*2,Q=(e,t,n)=>Math.max(t,Math.min(n,e)),ne={ink:`--ink`,"ink-2":`--ink-2`,"ink-3":`--ink-3`,line:`--line`,"line-strong":`--line-strong`,card:`--surface`,ground:`--bg`,floor:`--surface-2`,accent:`--accent`,"accent-soft":`--accent-soft`,"loop-0":`--loop-0`,"loop-1":`--loop-1`,"loop-2":`--loop-2`,"loop-3":`--loop-3`,"k-agent":`--kind-agent`,"k-check":`--kind-check`,"k-gate":`--kind-human-gate`,"k-stop":`--kind-stop`,ok:`--ok`,bad:`--warning`,brake:`--error`},re=.8,ie=.9;function ae(e,t,n,r,i=0,a){let o=t.getContext(`2d`);if(!o)throw Error(`no 2D context`);let s=o,c={...r,zoom:1},l=[],u=1,d=[0,0,0],f=[0,0],p={},m=`system-ui, sans-serif`,[h,g]=[0,0],_=0,v=0,y=!1,b=``,x=!1,S=new Map,C=0,w=!1,T=e.appendChild(document.createElement(`i`));T.className=`s3-token`,T.hidden=!0;let E=e=>`pts`in e?e.pts:[e.at],D=e=>{let[t,n,r]=[e[0]-d[0],e[1]-d[1],e[2]-d[2]],[i,a,o,s]=[Math.cos(c.yaw),Math.sin(c.yaw),Math.cos(c.pitch),Math.sin(c.pitch)],[l,u]=[t*i+r*a,-t*a+r*i];return[l,n*o-u*s,n*s+u*o]},O=(e,t)=>t*2600/(2600-e*t),k=e=>{let[t,n,r]=D(e),i=O(r,u*c.zoom);return[h/2+(t-f[0])*i,g/2-(n-f[1])*i,r,i]},A=(e,t=1)=>{let n=p[e]??e;return t>=1?n:`color-mix(in srgb, ${n} ${Math.round(t*100)}%, transparent)`},j=e=>n.querySelector(`[data-node="${CSS.escape(e)}"]`),M=(e,t,n,r,i)=>{let a=Q(i,.72,1.15),[o,s]=[t.offsetWidth*a,t.offsetHeight*a];return[e.side?n+9:n-o/2,e.stand&&!e.side?r-s-13:r-s/2,o,s,a]};function N(){if(!l.length||!h||!g)return;let n=l.flatMap(E);d=[0,1,2].map(e=>(([e,t])=>(e+t)/2)(Y(n.map(t=>t[e]))));let a={...c};Object.assign(c,r,{zoom:1});let o=new Map(l.flatMap(e=>e.t===`card`&&e.small?[[e.id,j(e.id)?.offsetWidth??88]]:[])),s=(e,t)=>{let n=(e.t===`card`&&e.small?o.get(e.id)*t:106)/2+5;return e.t===`card`?e.side?e.small?[8,n*2,14,14]:[8,128,22,22]:e.stand?[n,n,Math.max(60,(j(e.id)?.offsetHeight??0)*1.15+14),8]:[58,58,24,24]:e.t===`text`?[8,8,e.up?16*e.text.split(`
3
+ `).length*1.6:12,12]:[3,3,3,3]},p=l.flatMap(e=>E(e).map(t=>[D(t),e])),m=e=>{let t=p.map(([t,n])=>[t,O(t[2],e),s(n,Q(O(t[2],e),.72,1.15))]);return[Y(t.map(([e,t,n])=>e[0]*t-n[0]))[0],Y(t.map(([e,t,n])=>e[0]*t+n[1]))[1],Y(t.map(([e,t,n])=>-e[1]*t-n[2]))[0],Y(t.map(([e,t,n])=>-e[1]*t+n[3]))[1]]},v=(e,t)=>{let[n,r]=[.05,1.5];for(let i=0;i<18;i+=1){let i=(n+r)/2,[a,o,s,c]=m(i);o-a<=e-16&&c-s<=t-16?n=i:r=i}return n},y=e.parentElement,S=y?.parentElement;if(i&&y&&S){let n=l.flatMap(e=>e.t===`card`&&j(e.id)?[[e,j(e.id),D(e.at)]]:[]),r=()=>`${h}|${S.clientHeight}|${y.style.getPropertyValue(`--s3-tall`)?`held`:g}|${n.map(([e,t,n])=>`${e.id}:${t.offsetHeight}:${n.map(Math.round).join(`,`)}`).join(`|`)}`;if(r()!==b&&w)C||=requestAnimationFrame(()=>(C=0,N(),F()));else if(r()!==b){let a=(e,t=i)=>{let[r,a,o,s]=m(e),[c,l]=[(r+a)/2/e,-(o+s)/2/e],u=n.map(([t,n,r])=>M(t,n,(r[0]-c)*O(r[2],e),-(r[1]-l)*O(r[2],e),O(r[2],e)));return u.every((e,n)=>u.every((r,i)=>i<=n||e[0]>=r[0]+r[2]+t||r[0]>=e[0]+e[2]+t||e[1]>=r[1]+r[3]+t||r[1]>=e[1]+e[3]+t))},o=()=>(g=Math.round(t.getBoundingClientRect().height),t.height=g*_,v(h,g)),s=S.scrollTop;y.style.removeProperty(`--s3-tall`),delete y.dataset.tight;let c=o();if(g&&(!a(c)||c<ie)){let t=v(h,1e6),n=a(c)?c:t;for(let e=1;e<=24&&!a(c);e+=1){let[r,i]=[c+(t-c)*(e-1)/24,c+(t-c)*e/24];if(a(i)){for(let e=0;e<10;e+=1)a((r+i)/2)?i=(r+i)/2:r=(r+i)/2;n=i;break}}let r=e=>Math.ceil(m(e)[3]-m(e)[2])+18,i=(e,t)=>t&&e instanceof HTMLElement?e.offsetHeight+10+i(e.nextElementSibling,t-1):0,s=S.clientHeight-e.offsetTop-i(e.nextElementSibling,2)-parseFloat(getComputedStyle(S).paddingBottom),l=a(c)?g:r(n),u=Math.min(Math.max(l,Math.min(r(Math.max(n,Math.min(t,ie))),s)),Math.round(S.clientHeight*re));u>g?(y.style.setProperty(`--s3-tall`,`${u}px`),a(o(),0)||(y.dataset.tight=``)):a(c,0)||(y.dataset.tight=``)}`tight`in y.dataset&&o(),x=`tight`in y.dataset,S.scrollTop=s,b=r()}}u=v(h,g);let[T,k,A,P]=m(u);f=[(T+k)/2/u,-(A+P)/2/u],Object.assign(c,a)}let P=e=>{s.beginPath(),e.forEach((e,t)=>t?s.lineTo(e[0],e[1]):s.moveTo(e[0],e[1]))};function F(){if(e.parentElement?.toggleAttribute(`data-tight`,x&&c.zoom<=1),cancelAnimationFrame(v),v=0,!h||!g)return;let r=getComputedStyle(t);for(let[e,t]of Object.entries(ne))p[e]=r.getPropertyValue(t).trim();m=r.fontFamily,s.setTransform(_,0,0,_,0,0),s.clearRect(0,0,h,g);let i=Z.lit,a=e=>i&&e.key&&!i.has(e.key)?.42:1,o=Z.grown,u=l.filter(e=>!e.hide&&!(e.grow&&o<=0)).map(e=>{let t=E(e).map(k);return{p:e,pts:t,depth:t.reduce((e,t)=>e+t[2],0)/t.length+(e.t===`poly`?-90:e.t===`line`?-20:e.t===`dot`?4e3:e.t===`text`?60:0)+(e.lift??0)}}).sort((e,t)=>e.depth-t.depth),d=new Map;T.hidden=!0,u.forEach(({p:e,pts:t},n)=>{if(e.t!==`card`)return;let r=j(e.id);if(!r)return;let a=!!(i&&e.key&&i.has(e.key)),[o,s,c,l,u]=M(e,r,t[0][0],t[0][1],t[0][3]);d.set(e.id,[o,s,c,l]),r.style.transform=`translate(${o.toFixed(1)}px,${s.toFixed(1)}px) scale(${u.toFixed(3)})`,r.style.zIndex=String(n),r.hidden=!1,r.classList.toggle(`is-lit`,a),r.classList.toggle(`is-dim`,!!i&&!a)});let f=[],y=(e,t)=>Math.max(0,Math.min(e[0]+e[2],t[0]+t[2])-Math.max(e[0],t[0]))*Math.max(0,Math.min(e[1]+e[3],t[1]+t[3])-Math.max(e[1],t[1]));u.forEach(({p:e,pts:t})=>{if(e.t===`card`)return;let n=!!(i&&e.key&&i.has(e.key)),r=t;if(s.globalAlpha=a(e)*(e.alpha??1)*(e.grow&&e.t!==`line`?o:1),s.setLineDash(`dash`in e&&e.dash?e.dash:[]),s.lineJoin=s.lineCap=`round`,e.t===`poly`)P(r),s.closePath(),e.fill&&(s.fillStyle=A(e.fill,n?Math.min(1,(e.fa??1)*1.8):e.fa??1),s.fill()),e.stroke&&(s.strokeStyle=A(n?`accent`:e.stroke),s.lineWidth=(e.w??1)*(n?2:1),s.stroke());else if(e.t===`line`){let[t,i]=[e.from?d.get(e.from):void 0,e.to?d.get(e.to):void 0],a=[i?J(r,i):null,t?J([...r].reverse(),t):null];if(a[0]&&(r=a[0]),a[1]&&(r=J([...r].reverse(),t)?.reverse()??r),e.inset&&(r=ee(r,a[1]?2:e.inset[0],a[0]?1:e.inset[1])),e.grow&&o<1&&(r=r.slice(0,Math.max(2,Math.ceil(r.length*o)))),P(r),s.strokeStyle=A(e.stroke??`ink-2`),s.lineWidth=(e.w??1.4)*(n?2.1:1),s.stroke(),e.arrow&&r.length>1&&!(e.grow&&o<1)){let[t,n]=[r[r.length-2],r[r.length-1]],i=Math.atan2(n[1]-t[1],n[0]-t[0]);s.setLineDash([]),s.beginPath(),s.moveTo(n[0],n[1]),s.lineTo(n[0]-9*Math.cos(i-.42),n[1]-9*Math.sin(i-.42)),s.lineTo(n[0]-9*Math.cos(i+.42),n[1]-9*Math.sin(i+.42)),s.closePath(),s.fillStyle=A(e.stroke??`ink-2`),s.fill()}}else if(e.t===`dot`&&e.over){let t=e.r??5;T.style.cssText=`width:${t*2}px;height:${t*2}px;transform:translate(${(r[0][0]-t).toFixed(1)}px,${(r[0][1]-t).toFixed(1)}px)`,T.hidden=!1}else if(e.t===`dot`)s.beginPath(),s.arc(r[0][0],r[0][1],e.r??5,0,te),e.fill&&(s.fillStyle=A(e.fill),s.fill()),e.stroke&&(s.strokeStyle=A(e.stroke),s.lineWidth=e.w??2,s.stroke());else{let t=e.size??11;s.font=`${e.bold?600:400} ${t}px ${m}`,s.textBaseline=`middle`,s.textAlign=`left`;let n=Math.min(e.max??220,h-12),i=e.text.split(`
4
+ `).flatMap((t,r)=>{let i=[``];for(let e of t.split(` `)){let t=i[i.length-1]?`${i[i.length-1]} ${e}`:e;s.measureText(t).width>n&&i[i.length-1]?i.push(e):i[i.length-1]=t}return i.map(t=>({text:t,head:r<(e.heads??0)}))}),a=Math.max(...i.map(({text:e})=>s.measureText(e).width)),o=[{at:r[0],align:e.align},...(e.or??[]).map(e=>({at:k(e.at),align:e.align}))].map(n=>{let r=Q(n.at[0]-(n.align===`center`?a/2:n.align===`right`?a:0),4,Math.max(4,h-4-a)),o=i.length*(t+3),s=[r,n.at[1]-(e.up?o-(t+3)/2:o/2),a,o];return{...n,box:s,under:[...d.values(),...f].reduce((e,t)=>e+y(s,t),0)}}),c=o[S.get(e.text)??-1],l=e.or?c&&c.under<=.1*c.box[2]*c.box[3]?c:o.find(e=>e.under===0)??[...o].sort((e,t)=>e.under-t.under)[0]:o[0];e.or&&(f.push(l.box),S.set(e.text,o.indexOf(l))),i.forEach(({text:n,head:r},a)=>{let o=s.measureText(n).width,c=Q(l.at[0]-(l.align===`center`?o/2:l.align===`right`?o:0),4,Math.max(4,h-4-o)),u=l.at[1]+(e.up?a-(i.length-1):a-(i.length-1)/2)*(t+3);s.strokeStyle=A(`ground`,.9),s.lineWidth=3.5,s.setLineDash([]),s.strokeText(n,c,u),s.fillStyle=A(r&&e.headFill?e.headFill:e.fill??`ink-2`),s.fillText(n,c,u)})}}),s.globalAlpha=1,s.setLineDash([]);for(let e of n.querySelectorAll(`[data-node]`))d.has(e.dataset.node)||(e.hidden=!0)}let I=()=>{v||=requestAnimationFrame(F)};function L(){let e=t.getBoundingClientRect(),[n,r]=[Math.round(e.width),Math.round(e.height)];(n!==h||r!==g||_!==(devicePixelRatio||1))&&([h,g]=[n,r],_=devicePixelRatio||1,t.width=h*_,t.height=g*_,N())}let R=[],z=(t,n,r)=>{e.addEventListener(t,n,r),R.push(()=>e.removeEventListener(t,n,r))},B=new Map,V=0,H=[0,0],U,W=e=>l.find(t=>t.t===`card`&&t.id===e&&!!t.moves);z(`pointerdown`,e=>{if(e.pointerType===`mouse`&&e.button!==0)return;B.set(e.pointerId,[e.clientX,e.clientY]),H=[e.clientX,e.clientY],V=0,y=!1;let t=e.target.closest?.(`.s3-card`)?.dataset.node;B.size===1&&(U=a&&W(t)?{id:t,by:[0,0]}:void 0)});let G=(e,t,n)=>{let r=k(e.at),[[i,a],[o,s]]=e.moves.map(t=>{let n=k([e.at[0]+t[0]*10,e.at[1]+t[1]*10,e.at[2]+t[2]*10]);return[(n[0]-r[0])/10,(n[1]-r[1])/10]}),c=i*s-o*a;return Math.abs(c)<.05*Math.hypot(i,a)*Math.hypot(o,s)?void 0:[(t*s-n*o)/c,(n*i-t*a)/c]};z(`pointermove`,t=>{let n=B.get(t.pointerId);if(!n||t.pointerType===`mouse`&&!(t.buttons&1))return void B.delete(t.pointerId);if(!(!y&&B.size===1&&Math.hypot(t.clientX-H[0],t.clientY-H[1])<6)){if(y||e.setPointerCapture(t.pointerId),y=!0,B.set(t.pointerId,[t.clientX,t.clientY]),U&&B.size===1){let e=G(W(U.id),t.clientX-n[0],t.clientY-n[1]);e&&a.moving(U.id,U.by=[U.by[0]+e[0],U.by[1]+e[1]]);return}if(B.size===1)c.yaw=Q(c.yaw+(t.clientX-n[0])*.009,-1.9,1.9),c.pitch=Q(c.pitch+(t.clientY-n[1])*.007,-.15,1.45);else if(B.size===2){let[e,t]=[...B.values()],n=Math.hypot(e[0]-t[0],e[1]-t[1]);V&&(c.zoom=Q(c.zoom*n/V,.5,3.2)),V=n}I()}});let K=e=>void(B.delete(e.pointerId),V=0);if(z(`pointerup`,e=>{U&&(U.by[0]||U.by[1])&&a.moved(U.id,U.by),U=void 0,K(e)}),z(`pointercancel`,e=>{U&&a.moving(U.id,[0,0]),U=void 0,K(e)}),z(`wheel`,e=>{e.ctrlKey&&(e.preventDefault(),c.zoom=Q(c.zoom*Math.exp(-e.deltaY*.01),.5,3.2),I())},{passive:!1}),z(`keydown`,t=>{if(t.target!==e||t.altKey||t.ctrlKey||t.metaKey)return;let n={ArrowLeft:[-.12,0],ArrowRight:[.12,0],ArrowUp:[0,-.1],ArrowDown:[0,.1]}[t.key];if(n)c.yaw=Q(c.yaw+n[0],-1.9,1.9),c.pitch=Q(c.pitch+n[1],-.15,1.45);else if(t.key===`+`||t.key===`=`)c.zoom=Q(c.zoom*1.2,.5,3.2);else if(t.key===`-`)c.zoom=Q(c.zoom/1.2,.5,3.2);else if(t.key===`0`||t.key===`Home`)Object.assign(c,r,{zoom:1});else return;t.preventDefault(),I()}),typeof ResizeObserver==`function`){let n=new ResizeObserver(()=>{w=!0,L(),i&&N(),w=!1,F()});n.observe(t),i&&e.parentElement?.parentElement&&n.observe(e.parentElement.parentElement),R.push(()=>n.disconnect())}let q=matchMedia(`(prefers-color-scheme: dark)`);q.addEventListener(`change`,I);let X=new MutationObserver(I);X.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-theme`]}),X.observe(e,{attributes:!0,attributeFilter:[`data-look`]}),R.push(()=>q.removeEventListener(`change`,I),()=>X.disconnect(),()=>cancelAnimationFrame(v),()=>cancelAnimationFrame(C),()=>T.remove());let Z={lit:null,grown:1,set(e,t){l=e;for(let e of l)e.t===`card`&&j(e.id)?.classList.toggle(`is-small`,!!e.small);L(),t||N()},draw(){L(),F()},ask:I,reset:()=>(Object.assign(c,r,{zoom:1}),N(),I()),zoom:e=>(c.zoom=Q(c.zoom*e,.5,3.2),I()),dragged:()=>y,off:()=>R.forEach(e=>e())};return Z}var $=n(),oe={arch:j,by:C,card:T,circle:E,edgeLine:M,ground:A,hue:w,lerp:S,stations:O,TAU:x,under:v},se={panes:{view:V,start:B,as:`panes`,apart:2,moves:!0,says:`Every node is where the picture has it, one pane toward you for each loop or subgrooph around it; loops that only share a node are panes at one depth. An edge that changes depth is entering or leaving a loop or a subgrooph.`},spiral:{view:q,start:K,as:`a spiral for each loop`,apart:7,says:`A round of a loop is one turn upward, and a brake that counts rounds is a place on the way up. A loop inside another is a spiral of its own, where its rounds start afresh; a node two loops share stands on one of them.`,brakes:!0}},ce=!1,le=()=>matchMedia(`(prefers-reduced-motion: reduce)`).matches,ue=(e,t,n)=>({...e,nodes:e.nodes.map(e=>e.id===t?{...e,at:[e.at[0]+n[0],e.at[1]+n[1]]}:e)});function de({doc:e,kind:t,its:n,wide:i,of:a,drawn:s,play:c}){if(!ce){let e=document.createElement(`style`);e.textContent=Z+p,document.head.append(e),ce=!0}let l=n??se[t],[u,d]=(0,X.useState)(i<640),f=(0,X.useMemo)(()=>_(e,o(e,g(i),r).positions,a.notes,u),[e,i,a.notes,u]),m=e=>[...f.loops.filter(t=>t.members.includes(e)).sort((e,t)=>e.members.length-t.members.length).map(e=>`in the loop ${e.name}`),...f.groups.filter(t=>t.nodes.includes(e)).sort((e,t)=>e.nodes.length-t.nodes.length).map(e=>`in the ${e.from?`subgrooph`:`group`} ${e.name}`)].join(`, `),h=(0,X.useMemo)(()=>b(f),[f]),[v,y]=(0,X.useState)(0),[x,S]=(0,X.useState)(!!c),C=Math.min(v,h.length-1),w=h[C],T=(0,X.useRef)(null),E=(0,X.useRef)(null),D=(0,X.useRef)(null),O=(0,X.useRef)(void 0),k=(0,X.useRef)(0),A=(0,X.useRef)(!1),j=(0,X.useRef)(0),M=!!(a.onNodeMove&&l.moves),P=(0,X.useRef)({model:f,steps:h,k:C,of:a,kept:!1});Object.assign(P.current,{model:f,steps:h,k:C,of:a}),(0,X.useLayoutEffect)(()=>{let e=()=>d(T.current.clientWidth<640);e();let t=new ResizeObserver(e);return t.observe(T.current),()=>t.disconnect()},[]),(0,X.useLayoutEffect)(()=>{let e=P.current,t=M?{moving:(t,n)=>(S(!1),O.current.set(l.view(ue(e.model,t,n),F(e.model,e.steps,e.k)).prims,!0),O.current.ask()),moved:(t,n)=>{let r=e.model.nodes.find(e=>e.id===t),i={x:Math.round(r.at[0]+n[0]),y:Math.round(r.at[1]+n[1])};(i.x!==r.at[0]||i.y!==r.at[1])&&(e.kept=!0,e.of.onNodeMove(t,i))}}:void 0,n=O.current=ae(T.current,E.current,D.current,l.start,l.apart,t),r=0,i;return le()||(n.grown=0,i=setTimeout(()=>{let e=performance.now(),t=i=>{n.grown=Math.min(1,(i-e)/700),n.draw(),n.grown<1&&(r=requestAnimationFrame(t))};r=requestAnimationFrame(t)},330)),()=>(clearTimeout(i),cancelAnimationFrame(r),cancelAnimationFrame(k.current),n.off())},[t]),(0,X.useLayoutEffect)(()=>{let e=O.current,t=F(f,h,C),n=P.current.kept;P.current.kept=!1;let r=l.view(f,t);e.lit=t.lit,cancelAnimationFrame(k.current);let i=w.edge&&!w.about?r.path(w.edge,w.r0,w.r1):null;if(i&&i.length>1&&C===j.current+1&&!le()){let t={t:`dot`,at:i[0],r:9.5,over:!0};e.set([...r.prims,t],n);let a=performance.now(),o=n=>{let r=Math.min(1,(n-a)/620);t.at=N(i,1-(1-r)**3),t.hide=r===1,e.draw(),r<1&&(k.current=requestAnimationFrame(o))};k.current=requestAnimationFrame(o)}else e.set(r.prims,n);j.current=C,e.draw(),A.current||(A.current=!0,s?.())},[f,t,C]),(0,X.useEffect)(()=>{if(!x)return;if(C>=h.length-1)return S(!1);let e=setTimeout(()=>y(C+1),C===0?150:1150);return()=>clearTimeout(e)},[x,C,h.length]);let I=e=>(S(!1),y(Math.max(0,Math.min(h.length-1,e)))),L=f.run?`note`:`step`;return(0,$.jsxs)(`div`,{className:`s3`,"data-picture":`space`,"data-kind":t,children:[(0,$.jsxs)(`div`,{className:`s3-bar`,children:[(0,$.jsx)(`span`,{children:M?`Drag a card to move it, or the rest to turn. Pinch to move in and out.`:`Drag to turn. Pinch to move in and out.`}),(0,$.jsx)(`span`,{className:`s3-tight`,children:`Not every card has room here. Move in to read them, or close the details if they are open under this view.`}),(0,$.jsx)(`button`,{type:`button`,"aria-label":`Move out`,onClick:()=>O.current?.zoom(.8),children:`−`}),(0,$.jsx)(`button`,{type:`button`,"aria-label":`Move in`,onClick:()=>O.current?.zoom(1.25),children:`+`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>O.current?.reset(),children:`Starting view`})]}),(0,$.jsxs)(`div`,{ref:T,className:`s3-frame`,"data-moves":M?``:void 0,tabIndex:0,role:`group`,"aria-label":`${f.name} as ${l.as}: ${f.nodes.length} card${f.nodes.length===1?``:`s`}, ${f.edges.length} edge${f.edges.length===1?``:`s`}${f.loops.length?`, and ${f.loops.length===1?`the loop`:`the loops`} ${f.loops.map(e=>e.name).join(`, `)}`:``}. Drag to turn it; the arrow keys turn it too, and plus and minus move in and out.`,children:[(0,$.jsx)(`canvas`,{ref:E,"aria-hidden":`true`}),(0,$.jsx)(`div`,{ref:D,children:f.nodes.map(e=>(0,$.jsxs)(`button`,{type:`button`,className:`s3-card`,"data-node":e.id,"data-kind":e.kind,"aria-label":`${e.word} ${e.name}`,...m(e.id)?{"aria-description":m(e.id)}:{},onClick:t=>(t.detail===0||!O.current?.dragged())&&a.onNodeTap?.(e.id),children:[(0,$.jsx)(`b`,{children:e.name}),(0,$.jsx)(`span`,{children:e.line})]},e.id))})]}),(0,$.jsxs)(`div`,{className:`s3-steps`,children:[(0,$.jsx)(`button`,{type:`button`,className:x?`is-on`:void 0,onClick:()=>x?S(!1):(C>=h.length-1&&y(0),S(!0)),children:x?`Pause`:`Play`}),(0,$.jsx)(`button`,{type:`button`,"aria-label":`Previous ${L}`,onClick:()=>I(C-1),children:`‹`}),(0,$.jsx)(`button`,{type:`button`,"aria-label":`Next ${L}`,onClick:()=>I(C+1),children:`›`}),(0,$.jsx)(`input`,{type:`range`,min:0,max:h.length-1,step:1,value:C,"aria-label":f.run?`Note, in the order the run wrote them`:`Step, in the order a first pass takes them`,onChange:e=>I(Number(e.target.value))})]}),(0,$.jsx)(`output`,{className:`s3-says`,"aria-live":`polite`,children:w.says}),l.brakes&&f.loops.length?(0,$.jsx)(`ul`,{className:`s3-key`,"aria-label":`Each loop's brakes`,children:f.loops.map((e,t)=>(0,$.jsxs)(`li`,{children:[(0,$.jsx)(`b`,{style:{color:`var(--loop-${t%4})`},children:e.name}),` `,W(e,U(f,e)).words.join(`; `)]},e.id))}):null,l.under?.(f,F(f,h,C)),(0,$.jsxs)(`details`,{className:`s3-more`,open:!u,children:[(0,$.jsx)(`summary`,{children:`About this view`}),(0,$.jsxs)(`p`,{className:`s3-note`,children:[l.says,t===`panes`&&!f.loops.length&&!f.groups.some(e=>e.from)?` This graph has no loop and no subgrooph, so nothing is lifted.`:``,a.onNodeMove&&!l.moves?` Here the loops place the cards: to move a node, use Panes, Columns, or the picture.`:``]})]})]})}export{de as Stage3,oe as tools};
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/graph-stage-CwNePnN4.js","assets/index-B5ZkSF4L.js","assets/share-DV3wsAsJ.js","assets/full-C0asYORc.js","assets/space-Cuy4YqyZ.js","assets/graph-more-Dn_hNa20.js","assets/SketchView-BjeUHG4X.js","assets/App-D1pDFbEY.js","assets/templates-DbAhWvP6.js","assets/runs-BA5HKtsx.js","assets/App-CT9KxzfQ.css","assets/mermaid-read-cyqJ32v-.js","assets/screens-CMMuexid.js","assets/screens-DWbqIw6l.css"])))=>i.map(i=>d[i]);
2
+ import{a as e,c as t,n,r,t as i}from"./index-B5ZkSF4L.js";import{D as a,S as o,Xt as s,Yt as c,an as l,qt as u,u as d,w as f}from"./share-DV3wsAsJ.js";var p=[[`stairs`,`Stairs`,`Each loop is a floor with its own nodes standing on it; a loop inside it has a floor of its own.`],[`panes`,`Panes`,`The picture as it is, with each loop and each subgrooph lifted toward you on a pane of its own.`],[`spiral`,`Spiral`,`Each loop is a spiral: a round is one turn upward, and the brakes that count rounds are places on the way up, the lid where max iterations stops it.`],[`rings`,`Rings`,`Each loop is a ring, with its own nodes standing around it; a loop inside another is a ring standing on the outer one.`],[`columns`,`Columns`,`Every node where the picture has it, an agent as a column: taller for a higher tier (an order, not a model), and on a run a block for each dispatch, as tall as its own minutes.`]],m={"human-gate":[`Human gate`,`gate`],check:[`Check`,`check`],merge:[`Merge`,`merge`],stop:[`Stop`,`stop`]};function h(e){let t=new Map(f(e).flat().map((e,t)=>[e,t])),n=e=>!!e&&t.has(e.from)&&t.has(e.to),r=new Map(e.loops.flatMap(e=>e.back.map(t=>[t,e]))),i=e.edges.filter(e=>n(e)&&!r.has(e.id)).sort((e,n)=>t.get(e.from)-t.get(n.from)||t.get(e.to)-t.get(n.to)),a=[...r].map(([t,n])=>({edge:e.edges.find(e=>e.id===t),loop:n})).filter(e=>n(e.edge));return[...i.map(e=>({edge:e})),...a]}function g(e,t,n,r){let[,,,,,,,,,,,,,,,i,,,,,,,p,,,,g,,_]=d,v=i(`auto`),y=t=>e.nodes.find(e=>e.id===t)?.name||t,b=f(e).flat(),x=new Map(b.map((e,t)=>[e,t])),S=e.loops.map((e,t)=>({loop:e,k:t,members:new Set(e.members)})),C=(e.groups??[]).filter(e=>e.from),w=e=>{let t=S.filter(t=>t.members.has(e)).sort((e,t)=>e.members.size-t.members.size)[0];if(t)return`loop ${t.loop.id}`;let n=C.find(t=>t.members.includes(e));return n?`unit ${n.id}`:``},T=new Map;for(let t of b){let n=e.nodes.find(e=>e.id===t);(T.get(w(t))??T.set(w(t),[]).get(w(t))).push(n)}let E=e=>{let t=e.kind===`agent`&&e.by===`person`,[r,i]=e.kind===`agent`?t?[`Person · ${l(e)}`,`gate`]:[l(e),`accent`]:m[e.kind],a=e.kind===`agent`&&!t&&e.model?e.model.tier:``,s=_(e.name||e.id,n-16,12.5,3,`bold`),c=7+s.length*15+13+(a?11.5:0)+6;return{id:e.id,h:c,svg:()=>{let t=e.kind===`human-gate`?{fill:v(`gate-soft`),stroke:v(`gate`),rx:12,width:1.8}:{fill:v(`surface`),stroke:v(e.kind===`agent`?`line-strong`:i),rx:e.kind===`stop`?2:8,width:e.kind===`agent`?1:1.4},l=5,u=s.map(e=>g(8,l+=15,e,{size:12.5,fill:v(`ink`),weight:`bold`}));return`<g data-node="${o(e.id)}" data-kind="${e.kind}">${p(.7,.7,n-1.4,c-1.4,{...t,mark:`card`})}${u.join(``)}${g(8,l+=13,_(r,n-16,9.5,1,`bold`)[0],{size:9.5,fill:v(i),weight:`bold`})}${a?g(8,l+11.5,a,{size:9,fill:v(`ink-3`)}):``}</g>`}}},D=[...T.keys()].filter(e=>e!==``).sort((e,t)=>x.get(T.get(e)[0].id)-x.get(T.get(t)[0].id)),O=[...T.has(``)||D.length===0?[``]:[],...D].map((t,n)=>{let r=(T.get(t)??[]).map(E),i=S.find(e=>`loop ${e.loop.id}`===t),a=C.find(e=>`unit ${e.id}`===t);if(i){let e=S.filter(e=>e!==i&&i.loop.members.every(t=>e.members.has(t))).sort((e,t)=>e.members.size-t.members.size)[0];return{cls:``,mark:`data-loop="${o(i.loop.id)}"`,name:i.loop.name||i.loop.id,place:`loop`,sub:`${e?`inside ${e.loop.name||e.loop.id} · `:``}stops: ${i.loop.stops.map(u).join(`; `)}`,gap:n===0?0:1,items:r}}return a?{cls:``,mark:`data-unit="${o(a.id)}"`,name:a.name||a.id,place:`subgrooph`,sub:`from ${a.from}`,gap:n===0?0:1,items:r}:{cls:` is-people`,mark:`data-outside=""`,name:D.length?`Outside any loop`:e.name||e.id,place:``,sub:D.length?`what a run passes once`:`no loop`,gap:0,items:r}}),k=h(e),A=k.map(({edge:t,loop:n},r)=>({id:t.id,n:r+1,from:t.from,to:t.to,style:n?{color:`loop-${e.loops.indexOf(n)%4}`,dash:`6 4`,width:2.2}:{color:`ink-2`,width:1.6}})),j=k.length,M=[{short:`all steps`,says:j===0?`This graph has no edges to step through.`:j===1?`The graph's one edge is lit.`:`All ${j} steps are lit. Move the slider or press Play to follow a first pass, one edge at a time.`}];k.forEach(({edge:e,loop:t},n)=>{let r=c(e)===`always`?``:` · when ${s(e)}`;M.push({handoff:e.id,short:`step ${n+1} of ${j}`,says:`Step ${n+1} of ${j}: ${e.from===e.to?`${y(e.from)} to itself`:`${y(e.from)} to ${y(e.to)}`}${r}${t?` · back into ${t.name||t.id}: another round, until ${t.stops.map(u).join(`; `)}`:``}`})});let N={title:e.name||e.id,sheets:O,links:A,per:t,link:`edge`,links_:`edges`,none:` · no nodes`,flat:` The picture shows the same graph, flat. <button type="button" data-flat="picture">Picture</button>`};if(r?.length){let t=a(r,e),n=new Set(O.map(e=>e.mark)),i=t=>t?.kind===`edge`?{handoff:t.id}:t?.kind===`node`?{ends:[t.id]}:t?.kind===`loop`?n.has(`data-loop="${o(t.id)}"`)?{sheet:`data-loop="${o(t.id)}"`}:{ends:e.loops.find(e=>e.id===t.id)?.members??[]}:{};return{...N,stops:t.steps.map((e,t)=>t===0?{short:`before the run`,says:`Before the run: ${r.length} note${r.length===1?``:`s`} to follow. Move the slider or press Play.`}:{short:`note ${t} of ${r.length}`,says:`Note ${t} of ${r.length}: ${e.caption}`,alone:!0,...i(e.focus)}),step:`note`,range:`Note, in the order the run wrote them`,note:`The run's own notes, in the order it wrote them. ${t.end.line}`}}return{...N,stops:M,range:`Step, in the order a first pass takes them`,note:`The edges a first pass takes, in order, and then one turn of each loop. An order, not a clock: a graph records no times.`}}var _=t(e(),1),v=()=>typeof document.startViewTransition!=`function`||matchMedia(`(prefers-reduced-motion: reduce)`).matches,y=[],b=0;function x(e,t){if(v())return t(()=>{},()=>{});let n=[],r=++b,i=e=>{if(r===b){for(let e of y)for(let t of[`name`,`class`])e.style.removeProperty(`view-transition-${t}`);y=[];for(let[t,r]of e)t.style.setProperty(`view-transition-name`,`gv${n.includes(r)?n.indexOf(r):n.push(r)-1}`),t.style.setProperty(`view-transition-class`,`gv`),y.push(t)}};i(e());let a=document.startViewTransition(()=>new Promise(n=>t(()=>(i(e()),n()),()=>a.skipTransition())));a.ready.catch(()=>{});let o=()=>i([]);a.finished.then(o,o)}var S=`.graph-views{z-index:6;pointer-events:none;position:absolute;inset:0}.stage:has(>.graph-views)>.loop-legend{right:196px}.stage:has(>.graph-views.is-space)>.loop-legend{display:none}.graph-switch{z-index:2;pointer-events:auto;box-shadow:var(--shadow);flex-wrap:nowrap;position:absolute;top:26px;right:10px}.graph-switch .seg{min-width:78px;min-height:36px}.graph-views-note{z-index:2;border:1px solid var(--line-strong);background:var(--surface);text-align:center;pointer-events:auto;border-radius:10px;width:min(92%,44ch);margin:0;padding:8px 12px;font-size:13px;position:absolute;top:74px;left:50%;transform:translate(-50%)}.graph-space{z-index:1;background:var(--bg);pointer-events:auto;padding:118px 0 104px;position:absolute;inset:0;overflow:auto}.graph-space .map-picture{padding:0}@media (max-width:899px){.run-view:has(>.run-stage>.graph-views.is-space){grid-template-rows:auto minmax(220px,82dvh) minmax(0,1fr)}}.run-stage .graph-space{padding-bottom:16px}.run-stage:has(>.graph-views.is-space)>.canvas-size{display:none}@media (min-width:1100px){.graph-space{padding:118px 28px 104px}}@media (max-width:899px){[data-space-folds] .sheet-body{display:none}[data-space-folds] .sheet-toggle{visibility:hidden}}.graph-kinds{z-index:2;pointer-events:auto;box-shadow:var(--shadow);flex-wrap:nowrap;position:absolute;top:74px;right:10px}.graph-kinds .seg{min-width:62px;min-height:36px}.graph-views.is-space .graph-views-note{top:118px}.graph-views.is-space:has(>.graph-views-note)>.graph-space{padding-top:188px}::view-transition-group(.gv){animation-duration:.3s}::view-transition-old(root){animation-duration:.3s}::view-transition-new(root){animation-duration:.3s}::view-transition-old(.gv){animation:.3s both gv-goes}::view-transition-new(.gv){animation:.3s both gv-comes}@keyframes gv-goes{35%{opacity:1}65%,to{opacity:0}}@keyframes gv-comes{0%,35%{opacity:0}65%{opacity:1}}`,C=i(),w,T,E,D,O=!1,k=e=>e===`stairs`?`space`:e===`rings`||e===`columns`?`more`:`stage`,A=e=>!!(e===`stairs`?T:E&&(k(e)===`stage`||D)),j,M=()=>{if(j)return j;try{let e=sessionStorage.getItem(`groophSpace`);return p.find(([t])=>t===e)?.[0]??`stairs`}catch{return`stairs`}},N=e=>{j=e;try{sessionStorage.setItem(`groophSpace`,e)}catch{}},ee=class extends _.Component{state={lost:!1};static getDerivedStateFromError(){return{lost:!0}}componentDidCatch(){this.props.lost()}render(){return this.state.lost?null:this.props.children}};function P({doc:e,of:t}){let[i,a]=(0,_.useState)(`picture`),[o,s]=(0,_.useState)(M),[c,l]=(0,_.useState)(`picture`),[u,f]=(0,_.useState)(T),[h,v]=(0,_.useState)(E),[y,b]=(0,_.useState)(D),[j,P]=(0,_.useState)(!!t.sketch?.start),[F,te]=(0,_.useState)(w),[ne,I]=(0,_.useState)(),L=(0,_.useRef)({}),[re,ie]=(0,_.useState)(3),R=(0,_.useRef)({doc:e,at:innerWidth});R.current.doc!==e&&(R.current={doc:e,at:innerWidth});let z=(0,_.useRef)(null),ae=(0,_.useRef)(void 0),[B,oe]=(0,_.useState)(!1),[se,V]=(0,_.useState)(!1),H=e=>{oe(e),V(!1);let t=z.current;e&&t&&document.fullscreenEnabled&&!document.fullscreenElement?t.requestFullscreen?.().catch(()=>void 0):!e&&document.fullscreenElement===t&&document.exitFullscreen?.().catch(()=>void 0)};if(!O){let e=document.createElement(`style`);e.textContent=S,document.head.append(e),O=!0}let ce=()=>{let t=z.current?.parentElement;if(!t)return[];let n=[...t.querySelectorAll(`.space-card, .s3-card`)].map(e=>[e,e.dataset.node??e.querySelector(`[data-node]`)?.dataset.node??``]),[r,i]=[t,t.querySelector(n.length?`.space-scene, .s3-frame`:`.react-flow`)??t].map(e=>e.getBoundingClientRect());return(n.length?n:[...t.querySelectorAll(`.react-flow__node[data-id]`)].map(e=>[e,e.dataset.id])).filter(([t,n])=>{let a=t.getBoundingClientRect();return e.nodes.some(e=>e.id===n)&&a.left>Math.max(r.left,i.left)-1&&a.right<Math.min(r.right,i.right)+1&&a.top>Math.max(r.top,i.top)-1&&a.bottom<Math.min(r.bottom,i.bottom)+1})},U=(0,_.useRef)(`picture`),W=(0,_.useRef)(c),G=(0,_.useRef)({}),K=(0,_.useRef)([]),le=(0,_.useRef)(`picture`),q=e=>void z.current?.closest(`.editor`)?.toggleAttribute(`data-space-folds`,!!e&&e!==`picture`),ue=(0,_.useRef)(0),[de,fe]=(0,_.useState)(0),pe=(e,t)=>{if(!z.current)return e();x(ce,(n,r)=>{if(!z.current)return n();t()&&r(),K.current.push([++ue.current,n]),e(),fe(ue.current)})},J=()=>{let e=U.current;e===`picture`?l(e):A(e)&&(l(e),k(e)===`space`&&N(e)),a(e===`picture`?`picture`:`space`),e!==`picture`&&s(e)},Y=e=>{if(I(void 0),q(e),e===U.current)return;U.current=e;let t=e===`picture`?void 0:k(e);if(t&&!(t===`space`?u:t===`more`?h&&y:h)){if(a(`space`),s(e),G.current[t])return;G.current[t]=!0;let i=()=>U.current!==`picture`&&k(U.current)===t,o=()=>n(`graph-stage`,()=>r(()=>import(`./graph-stage-CwNePnN4.js`),__vite__mapDeps([0,1,2,3])));(t===`space`?n(`space`,()=>r(()=>import(`./space-Cuy4YqyZ.js`),__vite__mapDeps([4,3]))).then(e=>()=>f(T=e)):t===`stage`?o().then(e=>()=>v(E=e)):Promise.all([o(),n(`graph-more`,()=>r(()=>import(`./graph-more-Dn_hNa20.js`),__vite__mapDeps([5,1])))]).then(([e,t])=>()=>(v(E=e),b(D=t)))).then(e=>{L.current[t]=!1;let n=()=>(e(),i()?J():void 0);i()?pe(n,()=>!i()):n()},()=>{G.current[t]=!1,L.current[t]=!0;let e=i();e&&q(U.current=W.current),U.current===`picture`?(s(t===`space`?`panes`:`stairs`),I(t!==`space`&&!L.current.space?`That view in three dimensions could not be fetched. The picture shows the same graph, and so do the stairs.`:`The view in three dimensions could not be fetched. The picture shows the same graph.`)):I(`That view could not be fetched. This one shows the same graph.`),e&&J()})}else e!==`picture`||W.current!==`picture`?pe(J,()=>U.current===W.current):J()},X=(0,_.useMemo)(()=>c===`stairs`&&u?u.scene(d,g(e,re,u.CARD,t.notes)):void 0,[e,c,u,re,t.notes]),Z=c!==`picture`&&c!==`stairs`&&h&&(k(c)===`stage`||y)?c:void 0,me=(0,_.useMemo)(()=>h&&y?y.MORE(h.tools):{},[h,y]);(0,_.useLayoutEffect)(()=>{let t=z.current?.querySelector(`.space`);if(!t||!u||!X)return;let n=t=>e.nodes.find(e=>e.id===t)?.name||t;for(let r of t.querySelectorAll(`[data-node]`)){let t=e.nodes.find(e=>e.id===r.dataset.node);r.setAttribute(`tabindex`,`0`),r.setAttribute(`role`,`button`),r.setAttribute(`aria-label`,`${t?.kind===`agent`?t.by===`person`?`Person`:`Agent`:m[t?.kind]?.[0]??`Node`} ${n(r.dataset.node)}`)}for(let e of t.querySelectorAll(`[data-edge]`)){let t=X.arcs.find(t=>t.id===e.dataset.edge);e.setAttribute(`role`,`img`),t&&e.setAttribute(`aria-label`,`Step ${t.n}: ${n(t.from)} to ${n(t.to)}`)}return u.attach(t,X,ae.current??=u.held(),()=>Y(`picture`))},[X]);let he=e=>void(K.current=K.current.filter(([t,n])=>t>e||(n(),!1)));(0,_.useLayoutEffect)(()=>{W.current=c,(c===`picture`||c===`stairs`)&&(le.current=c),he(de)}),(0,_.useEffect)(()=>{let e=z.current?.closest(`.editor`),t=()=>e?.querySelector(`.sheet:not(.sheet-rail)`)?.getAttribute(`aria-label`),n=e=>{let n=t();e.target instanceof Element&&e.target.closest(`.topbar,.sheet-head`)?q():requestAnimationFrame(()=>t()!==n&&q())};return e?.addEventListener(`click`,n,!0),()=>(e?.removeEventListener(`click`,n,!0),e?.removeAttribute(`data-space-folds`))},[]),(0,_.useEffect)(()=>()=>he(1/0),[]),(0,_.useEffect)(()=>{let e=z.current?.parentElement;if(!e||typeof ResizeObserver!=`function`)return;let t=new ResizeObserver(()=>ie(e.clientWidth<640?3:e.clientWidth<900?4:6));return t.observe(e),()=>t.disconnect()},[]);let Q=e=>(q(),t.onNodeTap?.(e)),ge=e=>{I(void 0),e&&U.current!==`picture`&&(U.current=`picture`,l(`picture`),a(`picture`)),P(e),e||q(U.current)};(0,_.useEffect)(()=>{if(!t.sketch)return;j&&z.current?.closest(`.editor`)?.toggleAttribute(`data-space-folds`,!0);let e=/^(#\/g\/[^/?]+)(\?new|\?sketch)?$/.exec(location.hash),i=e?j?`${e[1]}?sketch`:e[2]===`?sketch`?e[1]:location.hash:location.hash;i!==location.hash&&history.replaceState(history.state,``,i),j&&!F&&n(`SketchView`,()=>r(()=>import(`./SketchView-BjeUHG4X.js`),__vite__mapDeps([6,1,2,7,8,9,10,11,12,13]))).then(e=>te(w=e),()=>{P(!1),q(),I(`The drawing could not be fetched. It needs a connection the first time. The picture shows the same graph.`)})},[j]);let _e=e=>{let t=e instanceof Element?e.closest(`[data-node]`):null;return t&&Q(t.dataset.node),!!t},ve=()=>{let e=le.current;q(U.current=e),l(e),a(e===`picture`?`picture`:`space`),s(`stairs`),I(e===`picture`?`That view cannot be drawn in this browser. The picture shows the same graph.`:`That view cannot be drawn in this browser. This one shows the same graph.`)},$=!!X||!!Z;return(0,_.useEffect)(()=>{if(!B)return;if(!$)return H(!1);let e=setTimeout(()=>V(!0),2600),t=()=>{V(!1),clearTimeout(e),e=setTimeout(()=>V(!0),2600)},n=e=>{e.key===`Escape`&&!document.fullscreenElement?H(!1):t()},r=()=>{document.fullscreenElement||oe(!1)};return addEventListener(`pointermove`,t),addEventListener(`pointerdown`,t),addEventListener(`keydown`,n),document.addEventListener(`fullscreenchange`,r),()=>{clearTimeout(e),removeEventListener(`pointermove`,t),removeEventListener(`pointerdown`,t),removeEventListener(`keydown`,n),document.removeEventListener(`fullscreenchange`,r)}},[B,$]),(0,C.jsxs)(`div`,{ref:z,className:`graph-views${$?` is-space`:``}${$&&B?` is-focus`:``}${$&&B&&se?` is-idle`:``}${j?` is-sketch`:``}`,children:[$?(0,C.jsxs)(`button`,{type:`button`,className:`graph-full`,"aria-pressed":B,onClick:()=>H(!B),children:[(0,C.jsx)(`svg`,{viewBox:`0 0 20 20`,"aria-hidden":`true`,children:(0,C.jsx)(`path`,{d:B?`M8 3v5H3M12 3v5h5M8 17v-5H3M12 17v-5h5`:`M3 8V3h5M17 8V3h-5M3 12v5h5M17 12v5h-5`})}),B?`Exit`:`Full screen`]}):null,(0,C.jsx)(`div`,{className:`segmented graph-switch`,role:`radiogroup`,"aria-label":`View of the graph`,children:(t.sketch?[`sketch`,`picture`,`space`]:[`picture`,`space`]).map(e=>{let t=e===`sketch`?j:!j&&i===e;return(0,C.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":t,className:t?`seg seg-on`:`seg`,onClick:()=>e===`sketch`?ge(!0):(ge(!1),Y(e===`picture`?`picture`:o)),children:e===`sketch`?`Sketch`:e===`picture`?`Picture`:`3D`},e)})}),$?(0,C.jsx)(`div`,{className:`segmented graph-kinds`,role:`radiogroup`,"aria-label":`Kind of view in three dimensions`,children:p.map(([e,t,n])=>(0,C.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":o===e,"aria-description":n,title:n,className:o===e?`seg seg-on`:`seg`,onClick:()=>Y(e),children:t},e))}):null,ne?(0,C.jsx)(`p`,{className:`graph-views-note`,role:`status`,children:ne}):null,j&&F&&t.sketch?(0,C.jsx)(F.SketchView,{doc:e,host:{...t.sketch,open:Q}}):null,X?(0,C.jsx)(`div`,{className:`graph-space map-stage`,"data-keep":B?250:t.notes?326:346,children:(0,C.jsx)(`div`,{className:`map-picture`,onClick:e=>void _e(e.target),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&_e(e.target)&&e.preventDefault()},dangerouslySetInnerHTML:{__html:X.html}})}):Z&&h?(0,C.jsx)(`div`,{className:`graph-space`,children:(0,C.jsx)(ee,{lost:ve,children:(0,C.jsx)(h.Stage3,{doc:e,kind:Z,...me[Z]?{its:me[Z]}:{},wide:R.current.at,of:{...t,onNodeTap:Q},drawn:()=>N(Z)})},Z)}):null]})}export{P as Views};