@miadi/stateloom-web 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/server/.next/BUILD_ID +1 -1
- package/server/.next/build-manifest.json +4 -4
- package/server/.next/server/app/_global-error/page/build-manifest.json +2 -2
- package/server/.next/server/app/_global-error/page.js +1 -1
- package/server/.next/server/app/_global-error/page.js.nft.json +1 -1
- package/server/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/server/.next/server/app/_global-error.html +2 -2
- package/server/.next/server/app/_global-error.rsc +1 -1
- package/server/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
- package/server/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/server/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/server/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/server/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/server/.next/server/app/_not-found/page/build-manifest.json +2 -2
- package/server/.next/server/app/_not-found/page.js +1 -1
- package/server/.next/server/app/_not-found/page.js.nft.json +1 -1
- package/server/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/server/.next/server/app/_not-found.html +1 -1
- package/server/.next/server/app/_not-found.rsc +2 -2
- package/server/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
- package/server/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/server/.next/server/app/_not-found.segments/_index.segment.rsc +2 -2
- package/server/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/server/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/server/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
- package/server/.next/server/app/api/file/route.js.nft.json +1 -1
- package/server/.next/server/app/api/rispec/route.js.nft.json +1 -1
- package/server/.next/server/app/api/watch/route.js +3 -2
- package/server/.next/server/app/api/watch/route.js.nft.json +1 -1
- package/server/.next/server/app/index.html +1 -1
- package/server/.next/server/app/index.rsc +3 -3
- package/server/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
- package/server/.next/server/app/index.segments/_full.segment.rsc +3 -3
- package/server/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/server/.next/server/app/index.segments/_index.segment.rsc +2 -2
- package/server/.next/server/app/index.segments/_tree.segment.rsc +2 -2
- package/server/.next/server/app/page/build-manifest.json +2 -2
- package/server/.next/server/app/page.js +1 -1
- package/server/.next/server/app/page.js.nft.json +1 -1
- package/server/.next/server/app/page_client-reference-manifest.js +1 -1
- package/server/.next/server/chunks/[root-of-the-server]__2046b812._.js +2 -2
- package/server/.next/server/chunks/[root-of-the-server]__87bf4b91._.js +1 -1
- package/server/.next/server/chunks/[root-of-the-server]__95b05635._.js +8 -0
- package/server/.next/server/chunks/ssr/[root-of-the-server]__2955c0d8._.js +3 -0
- package/server/.next/server/chunks/ssr/{[root-of-the-server]__b4e7f753._.js → [root-of-the-server]__385c85a7._.js} +2 -2
- package/server/.next/server/chunks/ssr/[root-of-the-server]__a977f174._.js +3 -0
- package/server/.next/server/chunks/ssr/[root-of-the-server]__ac84e72e._.js +3 -0
- package/server/.next/server/chunks/ssr/[root-of-the-server]__edbb995c._.js +3 -3
- package/server/.next/server/chunks/ssr/{[root-of-the-server]__9cafe12a._.js → [root-of-the-server]__f25b51be._.js} +2 -2
- package/server/.next/server/middleware-build-manifest.js +2 -2
- package/server/.next/server/pages/404.html +1 -1
- package/server/.next/server/pages/500.html +2 -2
- package/server/.next/static/chunks/2c679fab817159f2.css +1 -0
- package/server/.next/static/chunks/{8a03c0d2436d4c0f.js → 662d1b0ce457c16b.js} +1 -1
- package/server/.next/static/chunks/{367d28d76d2be05f.js → 7921d7703dd690a6.js} +4 -4
- package/server/.next/static/chunks/aea5b1716c68391c.js +1 -0
- package/server/.next/static/chunks/{turbopack-8f57da603e40457d.js → turbopack-34fc7de1568e2a7f.js} +1 -1
- package/server/package-lock.json +2 -2
- package/server/package.json +1 -1
- package/server/src/app/api/file/route.ts +20 -6
- package/server/src/app/api/watch/route.ts +11 -3
- package/server/src/components/BridgeProvider.tsx +10 -3
- package/server/src/components/DocSwitcher.tsx +84 -0
- package/server/src/components/SocketBridgeProvider.tsx +11 -4
- package/server/src/components/Toolbar.tsx +11 -3
- package/server/src/lib/docParam.ts +51 -0
- package/server/src/lib/layoutMemory.ts +20 -2
- package/server/src/lib/projectFile.ts +68 -1
- package/server/stateloom-web.json +2 -2
- package/server/tsconfig.tsbuildinfo +1 -1
- package/server/.next/server/chunks/[root-of-the-server]__0a18d740._.js +0 -8
- package/server/.next/server/chunks/ssr/[root-of-the-server]__517c9b38._.js +0 -3
- package/server/.next/server/chunks/ssr/[root-of-the-server]__632c82d7._.js +0 -3
- package/server/.next/server/chunks/ssr/[root-of-the-server]__ecf19999._.js +0 -3
- package/server/.next/static/chunks/b6bd7719e3445512.css +0 -1
- /package/server/.next/static/{GkITWCpEKNsMrqxlkqzGB → vPEqV8SJpTDJWGy_fRuh4}/_buildManifest.js +0 -0
- /package/server/.next/static/{GkITWCpEKNsMrqxlkqzGB → vPEqV8SJpTDJWGy_fRuh4}/_clientMiddlewareManifest.json +0 -0
- /package/server/.next/static/{GkITWCpEKNsMrqxlkqzGB → vPEqV8SJpTDJWGy_fRuh4}/_ssgManifest.js +0 -0
|
@@ -3,11 +3,11 @@ module.exports=[92509,(a,b,c)=>{b.exports=a.x("url",()=>require("url"))},21517,(
|
|
|
3
3
|
${f}
|
|
4
4
|
\`\`\`
|
|
5
5
|
`:`${f}
|
|
6
|
-
`)],{type:`${bs[a]};charset=utf-8`})}else{let b=function(a={}){let b="u"<typeof document?null:document.getElementById(bo);if(!b)return null;let c=function(a){let b=a.querySelector(":scope > g");if(!b)return null;try{let a=b.getBBox();return a.width>0&&a.height>0?a:null}catch{return null}}(b);if(!c)return null;let d=a.padding??48,e=a.background??bp,f=Math.round(c.x-d),g=Math.round(c.y-d),h=Math.round(c.width+2*d),i=Math.round(c.height+2*d),j=b.cloneNode(!0);j.removeAttribute("id"),j.removeAttribute("class"),j.removeAttribute("style"),j.setAttribute("xmlns","http://www.w3.org/2000/svg"),j.setAttribute("width",String(h)),j.setAttribute("height",String(i)),j.setAttribute("viewBox",`${f} ${g} ${h} ${i}`),j.setAttribute("font-family","ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif"),function a(b){for(let c of Array.from(b.children)){if("transparent"===c.getAttribute("fill")||"transparent"===c.getAttribute("stroke")){c.remove();continue}c.removeAttribute("class"),c.removeAttribute("style"),a(c)}}(j);let k=j.querySelector(":scope > g");k?.removeAttribute("transform");let l=document.createElementNS("http://www.w3.org/2000/svg","rect");return l.setAttribute("x",String(f)),l.setAttribute("y",String(g)),l.setAttribute("width",String(h)),l.setAttribute("height",String(i)),l.setAttribute("fill",e),j.insertBefore(l,j.firstChild),new XMLSerializer().serializeToString(j)}(c);if(!b)throw Error("nothing on the board to export yet");g="svg"===a?new Blob([b],{type:`${bs.svg};charset=utf-8`}):await (f=c.scale??2,new Promise((c,d)=>{let e=b.match(/width="(\d+)"\s+height="(\d+)"/),g=e?Number(e[1]):1200,h=e?Number(e[2]):800,i=URL.createObjectURL(new Blob([b],{type:"image/svg+xml;charset=utf-8"})),j=new Image;j.onload=()=>{URL.revokeObjectURL(i);let b=document.createElement("canvas");b.width=Math.max(1,Math.round(g*f)),b.height=Math.max(1,Math.round(h*f));let e=b.getContext("2d");e?(e.fillStyle=bp,e.fillRect(0,0,b.width,b.height),e.drawImage(j,0,0,b.width,b.height),b.toBlob(a=>a?c(a):d(Error("the canvas produced no image")),bs[a],"jpeg"===a?.92:void 0)):d(Error("this browser gave no 2d context to draw into"))},j.onerror=()=>{URL.revokeObjectURL(i),d(Error("the browser could not read the serialized board"))},j.src=i}))}let h=function({doc:a,machine:b,format:c,at:d}){let e,f,g=a0(b??"")||a0(a?(a.split(/[/\\]/).pop()??a).replace(/\.smdf\.json$/i,"").replace(/\.json$/i,""):"")||"statemachine",h=a&&(e=a.match(/(?:^|[/\\-])ep(?:isode)?-?(\d{2,4})(?:[/\\-]|$)/i))?`ep${e[1]}`:null,i=h?`${h}--`:"";return`${i}${g}--${(f=a=>String(a).padStart(2,"0"))(d.getFullYear()%100)+f(d.getMonth()+1)+f(d.getDate())+f(d.getHours())+f(d.getMinutes())+f(d.getSeconds())}.${c}`}({doc:b.docPath??b.fileName??null,machine:b.definition?.settings?.name??null,format:bt[a]??String(a),at:(void 0)??new Date}),i=URL.createObjectURL(g),j=document.createElement("a");return j.href=i,j.download=h,j.click(),URL.revokeObjectURL(i),h}async function bv(){try{let a=await fetch("/api/file",{cache:"no-store"});if(a.ok){let b=(await a.json())?.path;if("string"==typeof b&&b.length>0)return b}}catch{}return bk.getState().fileName??"untitled"}function bw(a,b){return 1===b?16*a:2===b?400*a:a}function bx(a){return!!a&&"string"==typeof a.tagName&&(!!a.isContentEditable||["INPUT","TEXTAREA","SELECT","BUTTON","OPTION"].includes(a.tagName))}function by({mark:a,x:b,y:c,color:d}){return(0,h.jsxs)("g",{transform:`translate(${b} ${c}) scale(0.5)`,fill:"none",stroke:d,strokeWidth:a.strokeWidth,strokeLinecap:"round",strokeLinejoin:"round",className:"pointer-events-none",children:[(a.circles??[]).map((a,b)=>(0,h.jsx)("circle",{cx:a.cx,cy:a.cy,r:a.r,fill:a.filled?d:"none"},`c${b}`)),a.paths.map((a,b)=>(0,h.jsx)("path",{d:a},`p${b}`))]})}function bz(){let a,b,c=bk(a=>a.definition),d=bk(a=>a.layout),e=bk(a=>a.selection),f=bk(a=>a.select),g=bk(a=>a.clearSelection),j=bk(a=>a.setStatePosition),k=bk(a=>a.drawMode),l=bk(a=>a.drawSource),m=bk(a=>a.setDrawSource),n=bk(a=>a.setDrawMode),o=bk(a=>a.addTransition),p=bk(a=>a.showContextMenu),q=bk(a=>a.removeState),r=bk(a=>a.undo),s=bk(a=>a.redo),t=bk(a=>a.errors),u=bk(a=>a.navigationPath),v=bk(a=>a.currentParent),w=bk(a=>a.navigateInto),x=bk(a=>a.navigateUp),y=bk(a=>a.getCurrentChildren),z=bk(a=>a.activeStates),A=bk(a=>a.viewport),B=bk(a=>a.setViewport),C=(0,i.useRef)(null),[D,E]=(0,i.useState)(null),F=(0,i.useRef)(null),G=(0,i.useCallback)(a=>{F.current=a,E(a)},[]),[H,I]=(0,i.useState)(null),J=(0,i.useRef)(!1),[K,L]=(0,i.useState)(!1),M=(0,i.useRef)(null),[N,O]=(0,i.useState)(!1),P=(0,i.useRef)(!1),Q=(0,i.useRef)(new Map),R=(0,i.useRef)(new Map),S=(0,i.useRef)(null),[T,U]=(0,i.useState)(!1),V=(0,i.useRef)(null),W=(0,i.useRef)(!1),[X,Y]=(0,i.useState)(!1);a=(0,i.useRef)(!1),b=(0,i.useRef)(null),(0,i.useEffect)(()=>{let c=!1,d=null;(async()=>{let d=await bv();if(c)return;b.current=d;let e=null;e&&bk.getState().hydrateLayout(e.positions,e.viewport),a.current=!0})();let e=bk.subscribe((c,e)=>{a.current&&b.current&&(c.layout!==e.layout||c.viewport!==e.viewport)&&(d&&clearTimeout(d),d=setTimeout(()=>{let a=bk.getState();b.current,function(a,b){let c={};for(let[d,e]of Object.entries(a)){let a=b[d];a&&(e.x!==a.x||e.y!==a.y||e.width!==a.width||e.height!==a.height)&&(c[d]=e)};}(a.layout.positions,aP(a.definition)),a.viewport},300))});return()=>{c=!0,d&&clearTimeout(d),e()}},[]);let Z=(0,i.useCallback)((a,b)=>{let c=C.current?.getBoundingClientRect();return{x:a-(c?.left??0),y:b-(c?.top??0)}},[]),$=(0,i.useCallback)(a=>{let b=Q.current.get(a);Q.current.delete(a),b?.hasPointerCapture?.(a)&&b.releasePointerCapture?.(a)},[]),_=(0,i.useCallback)(a=>{let b=V.current;b&&(void 0===a||b.pointerId===a)&&(clearTimeout(b.timer),V.current=null)},[]),aa=(0,i.useCallback)((a,b)=>{if("touch"!==a.pointerType)return;_();let{pointerId:c,clientX:d,clientY:e}=a,f=setTimeout(()=>{V.current=null,G(null),M.current=null,O(!1),W.current=!0,navigator.vibrate?.(10),p(d,e,b)},500);V.current={pointerId:c,x:d,y:e,target:b,timer:f}},[_,p,G]);(0,i.useEffect)(()=>{},[]),(0,i.useEffect)(()=>{let a=a=>{R.current.delete(a.pointerId)};return window.addEventListener("pointerup",a),window.addEventListener("pointercancel",a),()=>{window.removeEventListener("pointerup",a),window.removeEventListener("pointercancel",a)}},[]),(0,i.useEffect)(()=>()=>_(),[_]);let ab=(0,i.useRef)(new Set),ac=(0,i.useRef)(new Map),ad=(0,i.useRef)(v),ae=(0,i.useRef)(new Set),[af,ag]=(0,i.useState)(new Set),[ah,ai]=(0,i.useState)(new Set),[aj,ak]=(0,i.useState)(new Map),al=y(),am=c.events.flatMap(a=>a.events??[]),an=X?10/A.scale:0,ao=X?28/A.scale:0,ap=X?"px-3 py-2":"px-1.5 py-0.5";(0,i.useEffect)(()=>{let a=a=>{(a.ctrlKey||a.metaKey)&&"z"===a.key&&(a.preventDefault(),r()),(a.ctrlKey||a.metaKey)&&("y"===a.key||a.shiftKey&&"z"===a.key)&&(a.preventDefault(),s()),"Escape"===a.key&&(n("select"),I(null)),"Delete"===a.key&&"state"===e.kind&&e.id&&(q(e.id),g())};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[r,s,n,e,q,g]);let aq=(0,i.useCallback)(a=>d.positions[a]??{x:100,y:100,width:160,height:60},[d]),ar=(0,i.useCallback)(a=>t.some(b=>b.element===a),[t]),as=(0,i.useCallback)(a=>{let b=bk.getState().viewport;M.current={pointerId:a.pointerId,startX:a.clientX,startY:a.clientY,origX:b.x,origY:b.y},P.current=!1,O(!0);let c=C.current;c&&(Q.current.set(a.pointerId,c),c.setPointerCapture(a.pointerId))},[]),at=(0,i.useCallback)(()=>{let a=[...R.current.entries()];if(a.length<2)return;let[[b,c],[d,e]]=a;_(),G(null),M.current=null;let f=Math.max(1,Math.hypot(e.x-c.x,e.y-c.y)),g=Z((c.x+e.x)/2,(c.y+e.y)/2);S.current={a:b,b:d,startDist:f,startMidX:g.x,startMidY:g.y,start:bk.getState().viewport},P.current=!0,U(!0);let h=C.current;if(h){for(let a of[b,d])if(!Q.current.has(a))try{h.setPointerCapture(a),Q.current.set(a,h)}catch{}}},[_,Z,G]),au=(0,i.useCallback)(a=>{if(W.current=!1,"touch"!==a.pointerType)return;Y(!0),R.current.set(a.pointerId,{x:a.clientX,y:a.clientY});let b=R.current.size;b<2||(a.stopPropagation(),2===b&&at())},[at]),av=(0,i.useCallback)((a,b)=>{if(0!==a.button||J.current)return;if(a.stopPropagation(),aa(a,{kind:"state",id:b}),"transition"===k)return void(l?l!==b&&I({stateName:l,targetName:b,x:a.clientX,y:a.clientY}):m(b));f("state",b);let c=aq(b);G({name:b,pointerId:a.pointerId,startX:a.clientX,startY:a.clientY,origX:c.x,origY:c.y});let d=a.currentTarget;Q.current.set(a.pointerId,d),d.setPointerCapture?.(a.pointerId)},[f,aq,k,l,m,aa,G]),aw=(0,i.useCallback)(a=>{if("touch"===a.pointerType){aa(a,{kind:"canvas"}),as(a);return}(1===a.button||0===a.button&&J.current)&&(a.preventDefault(),as(a))},[aa,as]),ax=(0,i.useCallback)(a=>{R.current.has(a.pointerId)&&R.current.set(a.pointerId,{x:a.clientX,y:a.clientY});let b=V.current;b&&b.pointerId===a.pointerId&&Math.hypot(a.clientX-b.x,a.clientY-b.y)>8&&_(a.pointerId);let c=S.current;if(c){if(a.pointerId!==c.a&&a.pointerId!==c.b)return;let b=R.current.get(c.a),d=R.current.get(c.b);if(!b||!d)return;let e=Math.hypot(d.x-b.x,d.y-b.y),f=Z((b.x+d.x)/2,(b.y+d.y)/2);B(a6(a8(c.start,c.start.scale*(e/c.startDist),{x:c.startMidX,y:c.startMidY}),f.x-c.startMidX,f.y-c.startMidY));return}let d=M.current;if(d){if(d.pointerId!==a.pointerId)return;let b=a.clientX-d.startX,c=a.clientY-d.startY,e=8*("touch"===a.pointerType);(Math.abs(b)>e||Math.abs(c)>e)&&(P.current=!0);let f=bk.getState().viewport.scale;B({x:d.origX+b,y:d.origY+c,scale:f});return}if(!D||D.pointerId!==a.pointerId)return;let e=bk.getState().viewport.scale,f=(a.clientX-D.startX)/e,g=(a.clientY-D.startY)/e,h=aq(D.name);j(D.name,{...h,x:Math.max(0,D.origX+f),y:Math.max(0,D.origY+g)})},[D,aq,j,B,_,Z]),ay=(0,i.useCallback)(a=>{R.current.delete(a.pointerId),_(a.pointerId),$(a.pointerId);let b=S.current;if(b&&(b.a===a.pointerId||b.b===a.pointerId)){S.current=null,U(!1);let c=b.a===a.pointerId?b.b:b.a,d=R.current.get(c);if(d){let a=bk.getState().viewport;M.current={pointerId:c,startX:d.x,startY:d.y,origX:a.x,origY:a.y},P.current=!0,O(!0)}}M.current?.pointerId===a.pointerId&&(M.current=null),F.current?.pointerId===a.pointerId&&G(null),M.current||O(!1),S.current||U(!1)},[_,$,G]);(0,i.useEffect)(()=>{let a=C.current;if(!a)return;let b=a=>{a.preventDefault();let b=bk.getState().viewport,c=bw(a.deltaX,a.deltaMode),d=bw(a.deltaY,a.deltaMode);if(a.ctrlKey||a.metaKey){let c=a7(b,Math.exp(-(.0025*d)),Z(a.clientX,a.clientY));c!==b&&B(c);return}let e=a.shiftKey?-(c||d):-c,f=a.shiftKey?0:-d;(0!==e||0!==f)&&B(a6(b,e,f))};return a.addEventListener("wheel",b,{passive:!1}),()=>a.removeEventListener("wheel",b)},[B,Z]),(0,i.useEffect)(()=>{let a=a=>{"Space"!==a.code||a.repeat||bx(a.target)||bx(document.activeElement)||(a.preventDefault(),J.current=!0,L(!0))},b=a=>{"Space"===a.code&&(J.current=!1,L(!1))},c=()=>{J.current=!1,L(!1)};return window.addEventListener("keydown",a),window.addEventListener("keyup",b),window.addEventListener("blur",c),()=>{window.removeEventListener("keydown",a),window.removeEventListener("keyup",b),window.removeEventListener("blur",c)}},[]);let az=(0,i.useCallback)(a=>{let b=C.current?.getBoundingClientRect(),c={x:(b?.width??0)/2,y:(b?.height??0)/2},d=bk.getState().viewport,e=a7(d,a,c);e!==d&&B(e)},[B]),aA=(0,i.useCallback)(()=>{let a=C.current?.getBoundingClientRect(),b={x:(a?.width??0)/2,y:(a?.height??0)/2};B(a8(bk.getState().viewport,1,b))},[B]),aB=(0,i.useCallback)(()=>{let a=C.current?.getBoundingClientRect();if(!a)return;let b=al.map(a=>aq(a.name));B(b.length?function(a,b,c,d={}){let e=d.padding??48,f=d.maxScale??1,g=d.limits??a3;if(0===a.length||b<=0||c<=0)return{...a4};let h=1/0,i=1/0,j=-1/0,k=-1/0;for(let b of a)h=Math.min(h,b.x),i=Math.min(i,b.y),j=Math.max(j,b.x+b.width),k=Math.max(k,b.y+b.height);let l=Math.max(1,j-h),m=Math.max(1,k-i),n=a5(Math.min(f,Math.min(Math.max(1,b-2*e)/l,Math.max(1,c-2*e)/m)),g);return{x:(b-l*n)/2-h*n,y:(c-m*n)/2-i*n,scale:n}}(b,a.width,a.height):{...a4})},[al,aq,B]),aC=(0,i.useCallback)((a,b)=>{a.preventDefault(),a.stopPropagation(),p(a.clientX,a.clientY,b?{kind:"state",id:b}:{kind:"canvas"})},[p]),aD=(0,i.useMemo)(()=>{let a=new Set(al.map(a=>a.name)),b=[];for(let c of al)for(let[d,e]of(c.transitions??[]).entries())e.nextState&&a.has(e.nextState)&&b.push({from:c.name,to:e.nextState,event:e.event,stateName:c.name,index:d,condition:e.condition});return b},[al]),aE=(0,i.useMemo)(()=>{let a=function(a,b){let c=a.map(({from:a,to:c})=>{var d,e;return a===c?null:(d=b(a),(e=b(c)).y>=d.y+d.height?["bottom","top"]:e.y+e.height<=d.y?["top","bottom"]:e.x>=d.x+d.width?["right","left"]:e.x+e.width<=d.x?["left","right"]:["bottom","top"])}),d=new Map,e=(a,b,c)=>{let e=`${a}\0${b}`,f=d.get(e);f?f.push(c):d.set(e,[c])},f=(a,b)=>"top"===b||"bottom"===b?a.x+a.width/2:a.y+a.height/2;a.forEach((a,d)=>{let g=c[d];if(!g)return;let[h,i]=g;e(a.from,h,{edge:d,toward:f(b(a.to),h),role:"out"}),e(a.to,i,{edge:d,toward:f(b(a.from),i),role:"in"})});let g=new Map;for(let[a,c]of d){let[d,e]=a.split("\0"),f=b(d),h=[...c].sort((a,b)=>a.toward===b.toward?a.edge-b.edge:a.toward-b.toward);h.forEach((a,b)=>{g.set(`${a.edge}\0${a.role}`,function(a,b,c,d){let e="top"===b||"bottom"===b,f=e?a.width:a.height,g=e?a.x+a.width/2:a.y+a.height/2,h=d>1?Math.min(.72*f,40*(d-1)):0,i=d>1?g-h/2+h*c/(d-1):g;return"top"===b?{x:i,y:a.y}:"bottom"===b?{x:i,y:a.y+a.height}:"left"===b?{x:a.x,y:i}:{x:a.x+a.width,y:i}}(f,e,b,h.length))})}return a.map((a,d)=>{let e=c[d];if(!e){var f;let c,d,e;return c=(f=b(a.from)).x+f.width,d=f.y+.35*f.height,a$({x:c,y:d},{x:c+44,y:d-12},{x:c+44,y:(e=f.y+.65*f.height)+12},{x:c,y:e})}let h=g.get(`${d}\0out`),i=g.get(`${d}\0in`);var j=e[0];if("top"===j||"bottom"===j){let a=(h.y+i.y)/2;return a$(h,{x:h.x,y:a},{x:i.x,y:a},i)}let k=(h.x+i.x)/2;return a$(h,{x:k,y:h.y},{x:k,y:i.y},i)})}(aD,aq),b=new Map((function(a,b,c={}){let{along:d,aside:e,across:f}={...aV,...c},g=a.map((a,b)=>({label:a,i:b,width:aS(a).width})).sort((a,b)=>a.width===b.width?a.i-b.i:b.width-a.width),h=[];for(let{label:a}of g){let{width:c,height:g}=aS(a),i=8*!!a.glyph,j=null,k=1/0;a:for(let l of f)for(let f of e)for(let e of d){let d=a.at(e),m=d.x+f*c,n=d.y+l*g,o={x:m-c/2,y:n-18,width:c,height:g},p=[...h,...b].filter(a=>aU(o,a)).length,q={...o,cx:m+i,cy:n,label:a};if(0===p){j=q;break a}p<k&&(k=p,j=q)}j&&h.push(j)}return h})(aD.map((b,c)=>{let d=aq(b.from);return{id:`${b.stateName}:${b.index}`,event:b.event,condition:b.condition,glyph:!0,at:b.from===b.to?()=>({x:d.x+d.width+44+30,y:d.y+d.height/2+4}):a[c].at}}),al.map(a=>aq(a.name))).map(a=>[a.label.id,a]));return aD.flatMap((c,d)=>{let e=`${c.stateName}:${c.index}`,f=b.get(e);return f?[{arrow:c,id:e,curve:a[d],spot:f}]:[]})},[aD,al,aq]);return(0,i.useEffect)(()=>{let a=new Set(al.map(a=>a.name)),b=new Set(aD.map(a=>`${a.stateName}:${a.index}`)),c=ad.current===v,d=[...a].filter(a=>!ab.current.has(a));d.length&&ag(a=>{let b=new Set(a);return d.forEach(a=>b.add(a)),b});let e=[...b].filter(a=>!ae.current.has(a));e.length&&ai(a=>{let b=new Set(a);return e.forEach(a=>b.add(a)),b}),ag(b=>{let c=!1,d=new Set(b);return b.forEach(b=>{a.has(b)||(d.delete(b),c=!0)}),c?d:b}),ai(a=>{let c=!1,d=new Set(a);return a.forEach(a=>{b.has(a)||(d.delete(a),c=!0)}),c?d:a}),c?ak(b=>{let c=new Map(b),d=!1;return ac.current.forEach((b,e)=>{a.has(e)||c.has(e)||(c.set(e,b),d=!0)}),a.forEach(a=>{c.delete(a)&&(d=!0)}),d?c:b}):ak(a=>a.size?new Map:a),ab.current=a,ac.current=new Map(al.map(a=>[a.name,{state:a,pos:aq(a.name)}])),ae.current=b,ad.current=v},[al,v,aD,aq]),(0,h.jsxs)("div",{className:"relative w-full h-full",style:{touchAction:"none"},"data-pinch-owner":bl,children:[u.length>1&&(0,h.jsx)("div",{className:"absolute top-2 left-2 z-10 flex items-center gap-1 bg-gray-900/90 border border-gray-700 rounded-lg px-3 py-1.5 text-sm",children:u.map((a,b)=>(0,h.jsxs)("span",{className:"flex items-center gap-1",children:[b>0&&(0,h.jsx)("span",{className:"text-gray-600",children:"›"}),(0,h.jsx)("button",{className:`hover:text-blue-400 ${b===u.length-1?"text-blue-400 font-semibold":"text-gray-400"}`,onClick:()=>x(b),children:a})]},a))}),(0,h.jsxs)("svg",{ref:C,id:bo,className:"w-full h-full bg-gray-950",style:{cursor:N?"grabbing":K?"grab":void 0,touchAction:"none",...X?{WebkitUserSelect:"none",userSelect:"none",WebkitTouchCallout:"none"}:{}},onPointerDownCapture:au,onPointerDown:aw,onPointerMove:ax,onPointerUp:ay,onPointerCancel:ay,onAuxClick:a=>a.preventDefault(),onClick:a=>{if(W.current){W.current=!1,a.stopPropagation();return}if(P.current){P.current=!1;return}a.target?.tagName==="svg"&&(g(),I(null))},onContextMenu:a=>aC(a),children:[(0,h.jsxs)("defs",{children:[(0,h.jsx)("marker",{id:"arrowhead",markerWidth:"10",markerHeight:"7",refX:"10",refY:"3.5",orient:"auto",children:(0,h.jsx)("polygon",{points:"0 0, 10 3.5, 0 7",fill:"#94a3b8"})}),(0,h.jsx)("marker",{id:"arrowhead-blue",markerWidth:"10",markerHeight:"7",refX:"10",refY:"3.5",orient:"auto",children:(0,h.jsx)("polygon",{points:"0 0, 10 3.5, 0 7",fill:"#3b82f6"})})]}),"transition"===k&&l&&(0,h.jsxs)("text",{x:"50%",y:"30",fill:"#f59e0b",fontSize:13,textAnchor:"middle",className:"pointer-events-none select-none",children:['Click target state to create transition from "',l,'"']}),(0,h.jsxs)("g",{transform:`translate(${A.x} ${A.y}) scale(${A.scale})`,style:N||T?{pointerEvents:"none"}:void 0,children:[aE.map(({arrow:a,id:b,curve:c,spot:d})=>{let g="transition"===e.kind&&e.id===b,i=ah.has(b),j=c.at(.5),k=Math.hypot(j.x-d.cx,j.y-d.cy)>4;return(0,h.jsxs)("g",{children:[X&&(0,h.jsx)("path",{d:c.path,fill:"none",stroke:"transparent",strokeWidth:ao,strokeLinecap:"round",pointerEvents:"stroke",onClick:a=>{a.stopPropagation(),f("transition",b)}}),(0,h.jsx)("path",{d:c.path,fill:"none",pathLength:1,stroke:g?"#3b82f6":"#94a3b8",strokeWidth:g?2.5:1.5,markerEnd:g?"url(#arrowhead-blue)":"url(#arrowhead)",className:`cursor-pointer hover:stroke-blue-400${i?" sm-edge-enter":""}`,onClick:a=>{a.stopPropagation(),f("transition",b)}}),(0,h.jsxs)("g",{className:"cursor-pointer",onClick:a=>{a.stopPropagation(),f("transition",b)},children:[k&&(0,h.jsx)("line",{x1:j.x,y1:j.y,x2:d.cx,y2:d.cy-5,stroke:g?"#3b82f6":"#334155",strokeWidth:1,strokeDasharray:"2 3",className:"pointer-events-none"}),X&&(0,h.jsx)("rect",{x:d.x-an,y:d.y-an,width:d.width+2*an,height:d.height+2*an,fill:"transparent",pointerEvents:"all"}),(0,h.jsx)("rect",{x:d.x,y:d.y,width:d.width,height:d.height,rx:4,fill:g?"#1e3a5f":"#1e293b",stroke:g?"#3b82f6":"#334155",strokeWidth:1,className:"hover:fill-gray-800"}),(0,h.jsx)(by,{mark:function(a){let b=a.toLowerCase();for(let{glyph:a,words:c}of aY)if(c.some(a=>b.includes(a)))return a;return aX}(a.event),x:aT(d).x,y:aT(d).y,color:g?"#93c5fd":"#7c93b0"}),(0,h.jsx)("text",{x:d.cx,y:d.cy-5,fill:g?"#93c5fd":"#94a3b8",fontSize:11,fontWeight:500,textAnchor:"middle",className:"pointer-events-none select-none",children:a.event}),a.condition&&(0,h.jsxs)("text",{x:d.cx,y:d.cy+7,fill:"#64748b",fontSize:9,textAnchor:"middle",className:"select-none",children:[(0,h.jsx)("title",{children:a.condition}),aR(a.condition)]})]})]},`arrow-${b}`)}),al.map(a=>{let b=aq(a.name),c="state"===e.kind&&e.id===a.name,d="final"===a.kind,f="history"===a.kind,g=(a.states?.length??0)>0,i=l===a.name,j=ar(a.name),m=(a.onEntry?.actions?.length??0)>0,n=(a.onExit?.actions?.length??0)>0,o=z.includes(a.name),p=af.has(a.name);return(0,h.jsxs)("g",{onPointerDown:b=>av(b,a.name),onDoubleClick:b=>{b.stopPropagation(),g&&w(a.name)},onContextMenu:b=>aC(b,a.name),className:K?void 0:"transition"===k?"cursor-crosshair":g?"cursor-pointer":"cursor-grab active:cursor-grabbing",children:[X&&(0,h.jsx)("rect",{x:b.x-an,y:b.y-an,width:b.width+2*an,height:b.height+2*an,rx:12,fill:"transparent",pointerEvents:"all"}),(0,h.jsxs)("g",{className:p?"sm-node-enter":void 0,children:[(0,h.jsx)("rect",{x:b.x,y:b.y,width:b.width,height:b.height,rx:f?30:d?4:8,fill:i?"#1e3a5f":d?"#1e293b":g?"#0c1020":"#0f172a",stroke:j?"#ef4444":c?"#3b82f6":i?"#f59e0b":"#475569",strokeWidth:c?2.5:j?2:1.5,strokeDasharray:d?"6 3":g?"4 2":void 0,className:o?"sm-node-active":void 0}),(0,h.jsx)("text",{x:b.x+b.width/2,y:b.y+(m||n?b.height/2:b.height/2+5),fill:"#e2e8f0",fontSize:14,fontWeight:600,textAnchor:"middle",className:"pointer-events-none select-none",children:a.name}),a.kind&&"normal"!==a.kind&&(0,h.jsx)("text",{x:b.x+b.width-8,y:b.y+14,fill:"#64748b",fontSize:10,textAnchor:"end",className:"pointer-events-none select-none",children:a.kind}),m&&(0,h.jsx)("text",{x:b.x+6,y:b.y+b.height-6,fill:"#22c55e",fontSize:9,className:"pointer-events-none select-none",children:"▸entry"}),n&&(0,h.jsx)("text",{x:b.x+b.width-6,y:b.y+b.height-6,fill:"#f97316",fontSize:9,textAnchor:"end",className:"pointer-events-none select-none",children:"exit◂"}),j&&(0,h.jsx)("text",{x:b.x+6,y:b.y+14,fill:"#ef4444",fontSize:12,className:"pointer-events-none select-none",children:"⚠"}),g&&(0,h.jsxs)("text",{x:b.x+b.width/2,y:b.y+b.height-6,fill:"#6366f1",fontSize:9,textAnchor:"middle",className:"pointer-events-none select-none",children:["▼ ",a.states?.length," children — double-click to enter"]})]})]},a.name)}),Array.from(aj.entries()).map(([a,{state:b,pos:c}])=>{let d="final"===b.kind,e=(b.states?.length??0)>0;return(0,h.jsxs)("g",{className:"sm-node-exit",style:{pointerEvents:"none"},onAnimationEnd:b=>{"sm-node-out"===b.animationName&&ak(b=>{if(!b.has(a))return b;let c=new Map(b);return c.delete(a),c})},children:[(0,h.jsx)("rect",{x:c.x,y:c.y,width:c.width,height:c.height,rx:"history"===b.kind?30:d?4:8,fill:d?"#1e293b":e?"#0c1020":"#0f172a",stroke:"#475569",strokeWidth:1.5,strokeDasharray:d?"6 3":e?"4 2":void 0}),(0,h.jsx)("text",{x:c.x+c.width/2,y:c.y+c.height/2+5,fill:"#e2e8f0",fontSize:14,fontWeight:600,textAnchor:"middle",className:"select-none",children:a})]},`exit-${a}`)})]}),0===al.length&&(0,h.jsx)("text",{x:"50%",y:"50%",fill:"#475569",fontSize:16,textAnchor:"middle",children:X?"Press and hold to add a state, or load a .smdf.json file":"Right-click to add a state, or load a .smdf.json file"})]}),(0,h.jsxs)("div",{className:"absolute bottom-3 left-3 z-10 flex items-center gap-0.5 bg-gray-900/90 border border-gray-700 rounded-lg px-1.5 py-1 text-xs text-gray-400 select-none",children:[(0,h.jsx)("button",{className:`${ap} rounded hover:bg-gray-800 hover:text-gray-200 disabled:opacity-40 disabled:hover:bg-transparent`,title:"Zoom out (Ctrl + wheel down, or pinch in)",disabled:A.scale<=a3.min,onClick:()=>az(.8),children:"−"}),(0,h.jsxs)("button",{className:`${ap} rounded hover:bg-gray-800 hover:text-gray-200 tabular-nums min-w-[3.25rem]`,title:"Reset zoom to 100%",onClick:aA,children:[Math.round(100*A.scale),"%"]}),(0,h.jsx)("button",{className:`${ap} rounded hover:bg-gray-800 hover:text-gray-200 disabled:opacity-40 disabled:hover:bg-transparent`,title:"Zoom in (Ctrl + wheel up, or pinch out)",disabled:A.scale>=a3.max,onClick:()=>az(1.25),children:"+"}),(0,h.jsx)("span",{className:"text-gray-700 px-0.5",children:"|"}),(0,h.jsx)("button",{className:`${ap} rounded hover:bg-gray-800 hover:text-gray-200`,title:"Fit the whole machine in view",onClick:aB,children:"⤢ Fit"}),(0,h.jsx)("span",{className:"text-gray-700 px-0.5",children:"|"}),(0,h.jsx)("span",{className:"px-1 text-[10px] text-gray-600",title:X?"Drag to pan · pinch with two fingers to zoom · press and hold for the menu · double-tap a composite to enter it":"Wheel scrolls · Shift+wheel scrolls sideways · Ctrl+wheel zooms at the cursor · middle-drag or Space+drag pans",children:T?"pinching":N?"panning":X?"drag · pinch · hold":K?"space to pan":"wheel · ⌃wheel · space"})]}),H&&(0,h.jsxs)("div",{className:"absolute z-50 bg-gray-900 border border-gray-700 rounded-lg shadow-xl p-2 min-w-[160px]",style:{left:H.x,top:H.y-80},onClick:a=>a.stopPropagation(),children:[(0,h.jsxs)("div",{className:"text-xs text-gray-400 mb-1 px-1",children:[H.stateName," → ",H.targetName]}),(0,h.jsx)("div",{className:"text-xs text-gray-500 mb-1 px-1",children:"Select event:"}),0===am.length?(0,h.jsx)("div",{className:"text-xs text-gray-600 px-1 py-2",children:"No events defined. Add events first."}):am.map(a=>(0,h.jsx)("button",{className:"block w-full text-left text-sm text-gray-300 hover:bg-gray-800 px-2 py-1 rounded",onClick:()=>{var b;return b=a.id,void(H&&(o(H.stateName,{event:b,nextState:H.targetName}),I(null),m(null),n("select")))},children:a.id},a.id)),(0,h.jsx)("button",{className:"block w-full text-left text-xs text-gray-500 hover:text-gray-300 px-2 py-1 mt-1 border-t border-gray-800",onClick:()=>{I(null),m(null)},children:"Cancel"})]})]})}function bA({label:a,actions:b,onChange:c}){let d=(a,d)=>c(b.map((b,c)=>c===a?{...b,...d}:b));return(0,h.jsxs)("div",{children:[(0,h.jsxs)("div",{className:"flex items-center justify-between",children:[(0,h.jsx)("span",{className:"text-xs font-medium text-gray-500",children:a}),(0,h.jsx)("button",{onClick:()=>c([...b,{action:"code",code:""}]),className:"text-xs text-blue-500 hover:text-blue-400",children:"+ action"})]}),b.map((a,e)=>(0,h.jsxs)("div",{className:"flex items-start gap-1 mt-1",children:[(0,h.jsxs)("select",{className:"bg-gray-800 border border-gray-700 rounded px-1 py-0.5 text-xs text-gray-200",value:a.action,onChange:a=>d(e,{action:a.target.value}),children:[(0,h.jsx)("option",{value:"code",children:"Code"}),(0,h.jsx)("option",{value:"timerStart",children:"Timer Start"}),(0,h.jsx)("option",{value:"timerStop",children:"Timer Stop"})]}),"code"===a.action?(0,h.jsx)("textarea",{className:"flex-1 bg-gray-800 border border-gray-700 rounded px-1 py-0.5 text-xs text-gray-200 h-10 font-mono",value:a.code??"",placeholder:"// action code...",onChange:a=>d(e,{code:a.target.value})}):(0,h.jsx)("input",{className:"flex-1 bg-gray-800 border border-gray-700 rounded px-1 py-0.5 text-xs text-gray-200",value:a.name??"",placeholder:"Timer name",onChange:a=>d(e,{name:a.target.value})}),(0,h.jsx)("button",{onClick:()=>c(b.filter((a,b)=>b!==e)),className:"text-red-600 hover:text-red-400 text-xs mt-0.5",children:"✕"})]},e)),0===b.length&&(0,h.jsx)("span",{className:"text-xs text-gray-700 italic",children:"none"})]})}function bB(){let a=bk(a=>a.definition),b=bk(a=>a.selection),c=bk(a=>a.updateState),d=bk(a=>a.removeState);bk(a=>a.addAction),bk(a=>a.removeAction);let e=bk(a=>a.updateTransition),f=bk(a=>a.removeTransition);if(!b.kind||!b.id)return(0,h.jsx)("div",{className:"p-3 text-xs text-gray-500",children:"Select a state or transition to edit its properties."});let g=(a,b)=>{if(a.name===b)return a;for(let c of a.states??[]){let a=g(c,b);if(a)return a}return null};if("state"===b.kind){let e=g(a.state,b.id);if(!e)return(0,h.jsx)("div",{className:"p-3 text-gray-500 text-xs",children:"State not found"});let i=e.onEntry?.actions??[],j=e.onExit?.actions??[];return(0,h.jsxs)("div",{className:"p-3 space-y-3 text-sm md:overflow-y-auto md:max-h-[calc(100vh-160px)]",children:[(0,h.jsxs)("h3",{className:"text-xs font-semibold text-gray-400",children:["State: ",e.name]}),(0,h.jsxs)("label",{className:"block",children:[(0,h.jsx)("span",{className:"text-xs text-gray-500",children:"Name"}),(0,h.jsx)("input",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-sm text-gray-200",value:e.name,onChange:a=>c(b.id,{name:a.target.value})})]}),(0,h.jsxs)("label",{className:"block",children:[(0,h.jsx)("span",{className:"text-xs text-gray-500",children:"Kind"}),(0,h.jsxs)("select",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-sm text-gray-200",value:e.kind??"normal",onChange:a=>c(b.id,{kind:a.target.value}),children:[(0,h.jsx)("option",{value:"normal",children:"Normal"}),(0,h.jsx)("option",{value:"final",children:"Final"}),(0,h.jsx)("option",{value:"history",children:"History"})]})]}),(0,h.jsxs)("label",{className:"block",children:[(0,h.jsx)("span",{className:"text-xs text-gray-500",children:"Description"}),(0,h.jsx)("textarea",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-xs text-gray-200 h-12",value:e.description??"",onChange:a=>c(b.id,{description:a.target.value||void 0})})]}),(0,h.jsx)(bA,{label:"▸ onEntry Actions",actions:i,onChange:a=>c(b.id,{onEntry:{actions:a}})}),(0,h.jsx)(bA,{label:"◂ onExit Actions",actions:j,onChange:a=>c(b.id,{onExit:{actions:a}})}),(0,h.jsxs)("div",{children:[(0,h.jsx)("span",{className:"text-xs font-medium text-gray-500",children:"Transitions"}),(e.transitions??[]).map((a,c)=>(0,h.jsxs)("div",{className:"flex items-center gap-1 text-xs text-gray-400 py-1 border-b border-gray-800/50",children:[(0,h.jsxs)("span",{className:"flex-1",children:[a.event," → ",a.nextState??"(internal)"]}),a.condition&&(0,h.jsxs)("span",{className:"text-gray-600",children:["[",a.condition,"]"]}),(0,h.jsx)("button",{onClick:()=>f(b.id,c),className:"text-red-600 hover:text-red-400",children:"✕"})]},c)),(e.transitions?.length??0)===0&&(0,h.jsx)("span",{className:"text-xs text-gray-700 italic",children:"none"})]}),(0,h.jsx)("button",{onClick:()=>d(b.id),className:"text-red-500 hover:text-red-400 text-xs mt-2",children:"🗑 Delete State"})]})}if("transition"===b.kind){let[c,d]=b.id.split(":"),i=parseInt(d,10),j=g(a.state,c),k=j?.transitions?.[i];if(!k)return(0,h.jsx)("div",{className:"p-3 text-gray-500 text-xs",children:"Transition not found"});let l=bh(a),m=(function a(b){let c=[b];for(let d of b.states??[])c.push(...a(d));return c})(a.state).map(a=>a.name).filter(a=>"Root"!==a);return(0,h.jsxs)("div",{className:"p-3 space-y-3 text-sm",children:[(0,h.jsx)("h3",{className:"text-xs font-semibold text-gray-400",children:"Transition"}),(0,h.jsxs)("label",{className:"block",children:[(0,h.jsx)("span",{className:"text-xs text-gray-500",children:"Event"}),(0,h.jsx)("select",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-sm text-gray-200",value:k.event,onChange:a=>e(c,i,{event:a.target.value}),children:l.map(a=>(0,h.jsx)("option",{value:a,children:a},a))})]}),(0,h.jsxs)("label",{className:"block",children:[(0,h.jsx)("span",{className:"text-xs text-gray-500",children:"Target State"}),(0,h.jsxs)("select",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-sm text-gray-200",value:k.nextState??"",onChange:a=>e(c,i,{nextState:a.target.value||void 0}),children:[(0,h.jsx)("option",{value:"",children:"(internal transition)"}),m.map(a=>(0,h.jsx)("option",{value:a,children:a},a))]})]}),(0,h.jsxs)("label",{className:"block",children:[(0,h.jsx)("span",{className:"text-xs text-gray-500",children:"Condition (guard)"}),(0,h.jsx)("textarea",{rows:3,className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-sm text-gray-200 resize-y leading-snug",value:k.condition??"",onChange:a=>e(c,i,{condition:a.target.value||void 0})})]}),(0,h.jsx)("button",{onClick:()=>f(c,i),className:"text-red-500 hover:text-red-400 text-xs",children:"🗑 Delete Transition"})]})}return null}let bC=["string","int","float","bool","object"];function bD(){let a=bk(a=>a.definition),b=bk(a=>a.addEvent),c=bk(a=>a.updateEvent),d=bk(a=>a.removeEvent),e=bk(a=>a.addParameter),f=bk(a=>a.removeParameter),g=bk(a=>a.updateParameter),j=bk(a=>a.updateEventSource),k=bk(a=>a.select),l=bk(a=>a.selection),[m,n]=(0,i.useState)(""),[o,p]=(0,i.useState)(null),[q,r]=(0,i.useState)(null);return(0,h.jsxs)("div",{className:"p-3 text-sm",children:[a.events.map((a,b)=>(0,h.jsxs)("div",{className:"mb-3",children:[(0,h.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,h.jsx)("span",{className:"text-xs font-semibold text-gray-500",children:"Source:"}),(0,h.jsx)("input",{className:"flex-1 bg-transparent border-b border-gray-700 text-xs text-gray-300 px-1 py-0.5 focus:border-blue-500 outline-none",value:a.name,onChange:a=>j(b,{name:a.target.value})}),void 0!==a.feeder&&(0,h.jsx)("input",{className:"w-24 bg-transparent border-b border-gray-700 text-xs text-gray-400 px-1 py-0.5 focus:border-blue-500 outline-none",value:a.feeder??"",placeholder:"Feeder...",onChange:a=>j(b,{feeder:a.target.value||void 0})}),void 0===a.feeder&&(0,h.jsx)("button",{className:"text-xs text-gray-600 hover:text-gray-400",title:"Add feeder class",onClick:()=>j(b,{feeder:`${a.name}Feeder`}),children:"+feeder"})]}),(0,h.jsx)("div",{className:"-mx-1 overflow-x-auto px-1",children:(0,h.jsxs)("table",{className:"w-full text-xs",children:[(0,h.jsx)("thead",{children:(0,h.jsxs)("tr",{className:"text-gray-600 border-b border-gray-800",children:[(0,h.jsx)("th",{className:"text-left py-1 font-medium",children:"ID"}),(0,h.jsx)("th",{className:"text-left py-1 font-medium",children:"Description"}),(0,h.jsx)("th",{className:"text-left py-1 font-medium",children:"Params"}),(0,h.jsx)("th",{className:"w-6"})]})}),(0,h.jsx)("tbody",{children:(a.events??[]).map(a=>(0,h.jsxs)(i.Fragment,{children:[(0,h.jsxs)("tr",{className:`border-b border-gray-800/50 hover:bg-gray-800/30 cursor-pointer ${"event"===l.kind&&l.id===a.id?"bg-blue-900/30":""}`,onClick:()=>{k("event",a.id),p(o===a.id?null:a.id)},children:[(0,h.jsx)("td",{className:"py-1 pr-1",children:q===a.id?(0,h.jsx)("input",{autoFocus:!0,className:"w-full bg-gray-800 border border-gray-700 rounded px-1 text-gray-200",value:a.id,onChange:b=>c(a.id,{id:b.target.value}),onBlur:()=>r(null),onKeyDown:a=>"Enter"===a.key&&r(null),onClick:a=>a.stopPropagation()}):(0,h.jsx)("span",{className:"text-gray-300",onDoubleClick:b=>{b.stopPropagation(),r(a.id)},children:a.id})}),(0,h.jsx)("td",{className:"py-1 pr-1 text-gray-500 truncate max-w-[80px]",children:a.description??"—"}),(0,h.jsx)("td",{className:"py-1 text-gray-500",children:(a.parameters?.length??0)>0?a.parameters.map(a=>`${a.name}:${a.type}`).join(", "):"—"}),(0,h.jsx)("td",{className:"py-1",children:(0,h.jsx)("button",{onClick:b=>{b.stopPropagation(),d(a.id)},className:"text-red-600 hover:text-red-400",children:"✕"})})]}),o===a.id&&(0,h.jsx)("tr",{children:(0,h.jsx)("td",{colSpan:4,className:"py-2 px-1 bg-gray-900/50",children:(0,h.jsxs)("div",{className:"space-y-2",children:[(0,h.jsxs)("label",{className:"block",children:[(0,h.jsx)("span",{className:"text-gray-600",children:"Description"}),(0,h.jsx)("input",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-0.5 text-gray-200 mt-0.5",value:a.description??"",onChange:b=>c(a.id,{description:b.target.value||void 0})})]}),(0,h.jsxs)("div",{children:[(0,h.jsx)("span",{className:"text-gray-600",children:"Parameters"}),(a.parameters??[]).map((b,c)=>(0,h.jsxs)("div",{className:"flex items-center gap-1 mt-1",children:[(0,h.jsx)("input",{className:"flex-1 bg-gray-800 border border-gray-700 rounded px-1 py-0.5 text-gray-200",value:b.name,placeholder:"name",onChange:b=>g(a.id,c,{name:b.target.value})}),(0,h.jsx)("select",{className:"bg-gray-800 border border-gray-700 rounded px-1 py-0.5 text-gray-200",value:b.type,onChange:b=>g(a.id,c,{type:b.target.value}),children:bC.map(a=>(0,h.jsx)("option",{value:a,children:a},a))}),(0,h.jsx)("button",{onClick:()=>f(a.id,c),className:"text-red-600 hover:text-red-400",children:"✕"})]},c)),(0,h.jsx)("button",{className:"text-blue-500 hover:text-blue-400 mt-1",onClick:()=>e(a.id,{name:"param",type:"string"}),children:"+ parameter"})]}),(0,h.jsxs)("div",{className:"mt-1",children:[(0,h.jsx)("span",{className:"text-gray-600",children:"Generated method:"}),(0,h.jsxs)("code",{className:"block bg-gray-800 rounded px-2 py-1 text-green-400 mt-0.5 font-mono",children:["on_",a.id.toLowerCase(),"(context",(a.parameters??[]).map(a=>`, ${a.name}: ${a.type}`).join(""),")"]})]})]})})})]},a.id))})]})})]},b)),(0,h.jsxs)("div",{className:"flex gap-1 mt-2",children:[(0,h.jsx)("input",{className:"flex-1 bg-gray-800 border border-gray-700 rounded px-2 py-1 text-gray-200",placeholder:"New event ID...",value:m,onChange:a=>n(a.target.value),onKeyDown:a=>{"Enter"===a.key&&m.trim()&&(b({id:m.trim()}),n(""))}}),(0,h.jsx)("button",{onClick:()=>{m.trim()&&(b({id:m.trim()}),n(""))},className:"bg-blue-600 hover:bg-blue-500 text-white px-2 py-1 rounded",children:"+"})]})]})}function bE(){let a=bk(a=>a.definition.settings),b=bk(a=>a.definition.settings.context),c=bk(a=>a.updateSettings);return(0,h.jsxs)("div",{className:"p-3 space-y-3 text-sm",children:[(0,h.jsx)("h3",{className:"text-xs font-semibold text-gray-400",children:"Machine Settings"}),(0,h.jsxs)("label",{className:"block",children:[(0,h.jsx)("span",{className:"text-xs text-gray-500",children:"Namespace"}),(0,h.jsx)("input",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-sm text-gray-200",value:a.namespace,onChange:a=>c({namespace:a.target.value})})]}),(0,h.jsxs)("label",{className:"block",children:[(0,h.jsx)("span",{className:"text-xs text-gray-500",children:"Name"}),(0,h.jsx)("input",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-sm text-gray-200",value:a.name??"",onChange:a=>c({name:a.target.value||void 0})})]}),(0,h.jsxs)("label",{className:"block",children:[(0,h.jsx)("span",{className:"text-xs text-gray-500",children:"Description"}),(0,h.jsx)("textarea",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-xs text-gray-200 h-12",value:a.description??"",onChange:a=>c({description:a.target.value||void 0})})]}),(0,h.jsxs)("label",{className:"flex items-center gap-2 text-sm text-gray-300",children:[(0,h.jsx)("input",{type:"checkbox",checked:a.asynchronous,onChange:a=>c({asynchronous:a.target.checked}),className:"rounded bg-gray-800 border-gray-600"}),"Asynchronous"]}),(0,h.jsx)("hr",{className:"border-gray-800"}),(0,h.jsx)("h4",{className:"text-xs font-semibold text-gray-500",children:"Context"}),(0,h.jsxs)("label",{className:"block",children:[(0,h.jsx)("span",{className:"text-xs text-gray-500",children:"Context Class"}),(0,h.jsx)("input",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-xs text-gray-200",value:b?.className??"",placeholder:"e.g. MyStateMachineContext",onChange:a=>c({context:{...b,className:a.target.value||void 0}})})]}),(0,h.jsxs)("label",{className:"block",children:[(0,h.jsx)("span",{className:"text-xs text-gray-500",children:"Base Class"}),(0,h.jsx)("input",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-xs text-gray-200",value:b?.baseClass??"",placeholder:"e.g. Context",onChange:a=>c({context:{...b,baseClass:a.target.value||void 0}})})]}),(0,h.jsx)("hr",{className:"border-gray-800"}),(0,h.jsx)("h4",{className:"text-xs font-semibold text-gray-500",children:"Imports"}),(0,h.jsx)("textarea",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-xs text-gray-200 h-16 font-mono",value:(a.imports??[]).join("\n"),placeholder:"One import per line",onChange:a=>c({imports:a.target.value?a.target.value.split("\n"):[]})}),(0,h.jsx)("hr",{className:"border-gray-800"}),(0,h.jsx)("h4",{className:"text-xs font-semibold text-gray-500",children:"Object References"}),(0,h.jsx)("textarea",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-xs text-gray-200 h-12 font-mono",value:(a.objects??[]).map(a=>`${a.name}: ${a.type}`).join("\n"),placeholder:"name: type (one per line)",onChange:a=>{c({objects:a.target.value.split("\n").filter(a=>a.includes(":")).map(a=>{let[b,c]=a.split(":").map(a=>a.trim());return{name:b,type:c}})})}}),(0,h.jsx)("hr",{className:"border-gray-800"}),(0,h.jsx)("h4",{className:"text-xs font-semibold text-gray-500",children:"Code Generation"}),(0,h.jsxs)("label",{className:"block",children:[(0,h.jsx)("span",{className:"text-xs text-gray-500",children:"Target Language"}),(0,h.jsxs)("select",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-xs text-gray-200",value:a.targetLanguage??"python",onChange:a=>c({targetLanguage:a.target.value}),children:[(0,h.jsx)("option",{value:"python",children:"Python"}),(0,h.jsx)("option",{value:"typescript",children:"TypeScript"}),(0,h.jsx)("option",{value:"csharp",children:"C#"})]})]})]})}function bF(){let a=bk(a=>a.errors),b=bk(a=>a.validate),c=bk(a=>a.select);return(0,h.jsxs)("div",{className:"p-3",children:[(0,h.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,h.jsxs)("h3",{className:"text-xs font-semibold text-gray-400",children:["Validation ",a.length>0&&(0,h.jsxs)("span",{className:"text-red-500",children:["(",a.length,")"]})]}),(0,h.jsx)("button",{onClick:()=>b(),className:"text-xs bg-gray-700 hover:bg-gray-600 text-gray-300 px-2 py-0.5 rounded",children:"Re-check"})]}),0===a.length?(0,h.jsxs)("div",{className:"flex items-center gap-2 text-green-500 text-xs",children:[(0,h.jsx)("span",{children:"✓"}),(0,h.jsx)("span",{children:"Definition is valid"})]}):(0,h.jsx)("div",{className:"space-y-0.5",children:a.map((a,b)=>(0,h.jsxs)("div",{className:`flex items-start gap-1.5 text-[13px] py-2.5 border-b border-gray-800/50 md:text-xs md:py-1 ${a.element?"cursor-pointer hover:bg-gray-800/30":""}`,onClick:()=>{a.element&&c("state",a.element)},title:a.element?`Click to select "${a.element}"`:void 0,children:[(0,h.jsx)("span",{className:`font-mono text-[10px] mt-0.5 ${"error"===a.severity?"text-red-600":"text-yellow-600"}`,children:a.ruleId}),(0,h.jsx)("span",{className:`flex-1 ${"error"===a.severity?"text-red-400":"text-yellow-400"}`,children:a.message}),a.element&&(0,h.jsxs)("span",{className:"text-gray-600 text-[10px]",children:["→ ",a.element]})]},b))})]})}function bG(){let a=bk(a=>a.definition),b=bk(a=>a.fileName),c=bk(a=>a.docPath),d=bk(a=>a.dirty),e=bk(a=>a.loadFromJson),f=bk(a=>a.exportJson),g=bk(a=>a.addState),j=bk(a=>a.validate),k=bk(a=>a.showCodePreview),l=bk(a=>a.setShowCodePreview),m=bk(a=>a.setGeneratedCode),n=bk(a=>a.drawMode),o=bk(a=>a.setDrawMode),p=bk(a=>a.arrangeLayout),q=bk(a=>a.undo),r=bk(a=>a.redo),s=bk(a=>a.undoStack),t=bk(a=>a.redoStack),u=bk(a=>a.remoteStatus),v=bk(a=>a.remoteMessage),w=bk(a=>a.setRemoteStatus),x=bk(a=>a.setRemoteMtime),y=bk(a=>a.applyRemote),z=(0,i.useRef)(null),[A,B]=(0,i.useState)(!1),[C,D]=(0,i.useState)(""),[E,F]=(0,i.useState)(!1),[G,H]=(0,i.useState)("png"),[I,J]=(0,i.useState)(!1),[K,L]=(0,i.useState)(null),[M,N]=(0,i.useState)(null),O=async()=>{let a=f();F(!0);try{let b=await fetch("/api/file",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:a})});if(b.ok){let a=await b.json();x(a.mtime),bk.setState({dirty:!1}),w("synced",null)}else{let a=await b.json().catch(()=>({error:"unknown"}));w("error",`Save failed: ${a.error??b.statusText}`)}}catch(a){w("error",`Save failed: ${a}`)}finally{F(!1)}},P=async()=>{J(!0),L(null);try{let d=await bu(G,{definition:a,docPath:c,fileName:b});N(d)}catch(a){L(a instanceof Error?a.message:String(a))}finally{J(!1)}},Q=async()=>{try{let a=await fetch("/api/file",{cache:"no-store"});if(!a.ok)return void w("error","Reload failed");let b=await a.json();b.exists&&b.content?y(b.content,b.mtime,b.path.split("/").pop()):w("idle",`No file at ${b.path}`)}catch(a){w("error",`Reload failed: ${a}`)}},R=()=>{C.trim()&&(g(null,{name:C.trim(),kind:"normal"}),D(""),B(!1))},[S,T]=(0,i.useState)("python"),U=async()=>{try{let a=await fetch("/api/rispec",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({})});if(a.ok){let b=await a.json();m(b.rispec)}else{let b=await a.json().catch(()=>({error:"Unknown"}));m(`# RISE rispec generation failed
|
|
6
|
+
`)],{type:`${bs[a]};charset=utf-8`})}else{let b=function(a={}){let b="u"<typeof document?null:document.getElementById(bo);if(!b)return null;let c=function(a){let b=a.querySelector(":scope > g");if(!b)return null;try{let a=b.getBBox();return a.width>0&&a.height>0?a:null}catch{return null}}(b);if(!c)return null;let d=a.padding??48,e=a.background??bp,f=Math.round(c.x-d),g=Math.round(c.y-d),h=Math.round(c.width+2*d),i=Math.round(c.height+2*d),j=b.cloneNode(!0);j.removeAttribute("id"),j.removeAttribute("class"),j.removeAttribute("style"),j.setAttribute("xmlns","http://www.w3.org/2000/svg"),j.setAttribute("width",String(h)),j.setAttribute("height",String(i)),j.setAttribute("viewBox",`${f} ${g} ${h} ${i}`),j.setAttribute("font-family","ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif"),function a(b){for(let c of Array.from(b.children)){if("transparent"===c.getAttribute("fill")||"transparent"===c.getAttribute("stroke")){c.remove();continue}c.removeAttribute("class"),c.removeAttribute("style"),a(c)}}(j);let k=j.querySelector(":scope > g");k?.removeAttribute("transform");let l=document.createElementNS("http://www.w3.org/2000/svg","rect");return l.setAttribute("x",String(f)),l.setAttribute("y",String(g)),l.setAttribute("width",String(h)),l.setAttribute("height",String(i)),l.setAttribute("fill",e),j.insertBefore(l,j.firstChild),new XMLSerializer().serializeToString(j)}(c);if(!b)throw Error("nothing on the board to export yet");g="svg"===a?new Blob([b],{type:`${bs.svg};charset=utf-8`}):await (f=c.scale??2,new Promise((c,d)=>{let e=b.match(/width="(\d+)"\s+height="(\d+)"/),g=e?Number(e[1]):1200,h=e?Number(e[2]):800,i=URL.createObjectURL(new Blob([b],{type:"image/svg+xml;charset=utf-8"})),j=new Image;j.onload=()=>{URL.revokeObjectURL(i);let b=document.createElement("canvas");b.width=Math.max(1,Math.round(g*f)),b.height=Math.max(1,Math.round(h*f));let e=b.getContext("2d");e?(e.fillStyle=bp,e.fillRect(0,0,b.width,b.height),e.drawImage(j,0,0,b.width,b.height),b.toBlob(a=>a?c(a):d(Error("the canvas produced no image")),bs[a],"jpeg"===a?.92:void 0)):d(Error("this browser gave no 2d context to draw into"))},j.onerror=()=>{URL.revokeObjectURL(i),d(Error("the browser could not read the serialized board"))},j.src=i}))}let h=function({doc:a,machine:b,format:c,at:d}){let e,f,g=a0(b??"")||a0(a?(a.split(/[/\\]/).pop()??a).replace(/\.smdf\.json$/i,"").replace(/\.json$/i,""):"")||"statemachine",h=a&&(e=a.match(/(?:^|[/\\-])ep(?:isode)?-?(\d{2,4})(?:[/\\-]|$)/i))?`ep${e[1]}`:null,i=h?`${h}--`:"";return`${i}${g}--${(f=a=>String(a).padStart(2,"0"))(d.getFullYear()%100)+f(d.getMonth()+1)+f(d.getDate())+f(d.getHours())+f(d.getMinutes())+f(d.getSeconds())}.${c}`}({doc:b.docPath??b.fileName??null,machine:b.definition?.settings?.name??null,format:bt[a]??String(a),at:(void 0)??new Date}),i=URL.createObjectURL(g),j=document.createElement("a");return j.href=i,j.download=h,j.click(),URL.revokeObjectURL(i),h}let bv="stateloom.layout.v1:";async function bw(){try{let{requestedDoc:b,docQuery:c}=await a.A(65614),d=await fetch(`/api/file${c(b())}`,{cache:"no-store"});if(d.ok){let a=(await d.json())?.path;if("string"==typeof a&&a.length>0)return a}}catch{}return bk.getState().fileName??"untitled"}function bx(a,b){return 1===b?16*a:2===b?400*a:a}function by(a){return!!a&&"string"==typeof a.tagName&&(!!a.isContentEditable||["INPUT","TEXTAREA","SELECT","BUTTON","OPTION"].includes(a.tagName))}function bz({mark:a,x:b,y:c,color:d}){return(0,h.jsxs)("g",{transform:`translate(${b} ${c}) scale(0.5)`,fill:"none",stroke:d,strokeWidth:a.strokeWidth,strokeLinecap:"round",strokeLinejoin:"round",className:"pointer-events-none",children:[(a.circles??[]).map((a,b)=>(0,h.jsx)("circle",{cx:a.cx,cy:a.cy,r:a.r,fill:a.filled?d:"none"},`c${b}`)),a.paths.map((a,b)=>(0,h.jsx)("path",{d:a},`p${b}`))]})}function bA(){let a,b,c=bk(a=>a.definition),d=bk(a=>a.layout),e=bk(a=>a.selection),f=bk(a=>a.select),g=bk(a=>a.clearSelection),j=bk(a=>a.setStatePosition),k=bk(a=>a.drawMode),l=bk(a=>a.drawSource),m=bk(a=>a.setDrawSource),n=bk(a=>a.setDrawMode),o=bk(a=>a.addTransition),p=bk(a=>a.showContextMenu),q=bk(a=>a.removeState),r=bk(a=>a.undo),s=bk(a=>a.redo),t=bk(a=>a.errors),u=bk(a=>a.navigationPath),v=bk(a=>a.currentParent),w=bk(a=>a.navigateInto),x=bk(a=>a.navigateUp),y=bk(a=>a.getCurrentChildren),z=bk(a=>a.activeStates),A=bk(a=>a.viewport),B=bk(a=>a.setViewport),C=(0,i.useRef)(null),[D,E]=(0,i.useState)(null),F=(0,i.useRef)(null),G=(0,i.useCallback)(a=>{F.current=a,E(a)},[]),[H,I]=(0,i.useState)(null),J=(0,i.useRef)(!1),[K,L]=(0,i.useState)(!1),M=(0,i.useRef)(null),[N,O]=(0,i.useState)(!1),P=(0,i.useRef)(!1),Q=(0,i.useRef)(new Map),R=(0,i.useRef)(new Map),S=(0,i.useRef)(null),[T,U]=(0,i.useState)(!1),V=(0,i.useRef)(null),W=(0,i.useRef)(!1),[X,Y]=(0,i.useState)(!1);a=(0,i.useRef)(!1),b=(0,i.useRef)(null),(0,i.useEffect)(()=>{let c=!1,d=null;(async()=>{let d=await bw();if(c)return;b.current=d;let e=null;e&&bk.getState().hydrateLayout(e.positions,e.viewport),a.current=!0})();let e=bk.subscribe((c,e)=>{a.current&&b.current&&(c.layout!==e.layout||c.viewport!==e.viewport)&&(d&&clearTimeout(d),d=setTimeout(()=>{let a=bk.getState();b.current,function(a,b){let c={};for(let[d,e]of Object.entries(a)){let a=b[d];a&&(e.x!==a.x||e.y!==a.y||e.width!==a.width||e.height!==a.height)&&(c[d]=e)};}(a.layout.positions,aP(a.definition)),a.viewport},300))});return()=>{c=!0,d&&clearTimeout(d),e()}},[]);let Z=(0,i.useCallback)((a,b)=>{let c=C.current?.getBoundingClientRect();return{x:a-(c?.left??0),y:b-(c?.top??0)}},[]),$=(0,i.useCallback)(a=>{let b=Q.current.get(a);Q.current.delete(a),b?.hasPointerCapture?.(a)&&b.releasePointerCapture?.(a)},[]),_=(0,i.useCallback)(a=>{let b=V.current;b&&(void 0===a||b.pointerId===a)&&(clearTimeout(b.timer),V.current=null)},[]),aa=(0,i.useCallback)((a,b)=>{if("touch"!==a.pointerType)return;_();let{pointerId:c,clientX:d,clientY:e}=a,f=setTimeout(()=>{V.current=null,G(null),M.current=null,O(!1),W.current=!0,navigator.vibrate?.(10),p(d,e,b)},500);V.current={pointerId:c,x:d,y:e,target:b,timer:f}},[_,p,G]);(0,i.useEffect)(()=>{},[]),(0,i.useEffect)(()=>{let a=a=>{R.current.delete(a.pointerId)};return window.addEventListener("pointerup",a),window.addEventListener("pointercancel",a),()=>{window.removeEventListener("pointerup",a),window.removeEventListener("pointercancel",a)}},[]),(0,i.useEffect)(()=>()=>_(),[_]);let ab=(0,i.useRef)(new Set),ac=(0,i.useRef)(new Map),ad=(0,i.useRef)(v),ae=(0,i.useRef)(new Set),[af,ag]=(0,i.useState)(new Set),[ah,ai]=(0,i.useState)(new Set),[aj,ak]=(0,i.useState)(new Map),al=y(),am=c.events.flatMap(a=>a.events??[]),an=X?10/A.scale:0,ao=X?28/A.scale:0,ap=X?"px-3 py-2":"px-1.5 py-0.5";(0,i.useEffect)(()=>{let a=a=>{(a.ctrlKey||a.metaKey)&&"z"===a.key&&(a.preventDefault(),r()),(a.ctrlKey||a.metaKey)&&("y"===a.key||a.shiftKey&&"z"===a.key)&&(a.preventDefault(),s()),"Escape"===a.key&&(n("select"),I(null)),"Delete"===a.key&&"state"===e.kind&&e.id&&(q(e.id),g())};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[r,s,n,e,q,g]);let aq=(0,i.useCallback)(a=>d.positions[a]??{x:100,y:100,width:160,height:60},[d]),ar=(0,i.useCallback)(a=>t.some(b=>b.element===a),[t]),as=(0,i.useCallback)(a=>{let b=bk.getState().viewport;M.current={pointerId:a.pointerId,startX:a.clientX,startY:a.clientY,origX:b.x,origY:b.y},P.current=!1,O(!0);let c=C.current;c&&(Q.current.set(a.pointerId,c),c.setPointerCapture(a.pointerId))},[]),at=(0,i.useCallback)(()=>{let a=[...R.current.entries()];if(a.length<2)return;let[[b,c],[d,e]]=a;_(),G(null),M.current=null;let f=Math.max(1,Math.hypot(e.x-c.x,e.y-c.y)),g=Z((c.x+e.x)/2,(c.y+e.y)/2);S.current={a:b,b:d,startDist:f,startMidX:g.x,startMidY:g.y,start:bk.getState().viewport},P.current=!0,U(!0);let h=C.current;if(h){for(let a of[b,d])if(!Q.current.has(a))try{h.setPointerCapture(a),Q.current.set(a,h)}catch{}}},[_,Z,G]),au=(0,i.useCallback)(a=>{if(W.current=!1,"touch"!==a.pointerType)return;Y(!0),R.current.set(a.pointerId,{x:a.clientX,y:a.clientY});let b=R.current.size;b<2||(a.stopPropagation(),2===b&&at())},[at]),av=(0,i.useCallback)((a,b)=>{if(0!==a.button||J.current)return;if(a.stopPropagation(),aa(a,{kind:"state",id:b}),"transition"===k)return void(l?l!==b&&I({stateName:l,targetName:b,x:a.clientX,y:a.clientY}):m(b));f("state",b);let c=aq(b);G({name:b,pointerId:a.pointerId,startX:a.clientX,startY:a.clientY,origX:c.x,origY:c.y});let d=a.currentTarget;Q.current.set(a.pointerId,d),d.setPointerCapture?.(a.pointerId)},[f,aq,k,l,m,aa,G]),aw=(0,i.useCallback)(a=>{if("touch"===a.pointerType){aa(a,{kind:"canvas"}),as(a);return}(1===a.button||0===a.button&&J.current)&&(a.preventDefault(),as(a))},[aa,as]),ax=(0,i.useCallback)(a=>{R.current.has(a.pointerId)&&R.current.set(a.pointerId,{x:a.clientX,y:a.clientY});let b=V.current;b&&b.pointerId===a.pointerId&&Math.hypot(a.clientX-b.x,a.clientY-b.y)>8&&_(a.pointerId);let c=S.current;if(c){if(a.pointerId!==c.a&&a.pointerId!==c.b)return;let b=R.current.get(c.a),d=R.current.get(c.b);if(!b||!d)return;let e=Math.hypot(d.x-b.x,d.y-b.y),f=Z((b.x+d.x)/2,(b.y+d.y)/2);B(a6(a8(c.start,c.start.scale*(e/c.startDist),{x:c.startMidX,y:c.startMidY}),f.x-c.startMidX,f.y-c.startMidY));return}let d=M.current;if(d){if(d.pointerId!==a.pointerId)return;let b=a.clientX-d.startX,c=a.clientY-d.startY,e=8*("touch"===a.pointerType);(Math.abs(b)>e||Math.abs(c)>e)&&(P.current=!0);let f=bk.getState().viewport.scale;B({x:d.origX+b,y:d.origY+c,scale:f});return}if(!D||D.pointerId!==a.pointerId)return;let e=bk.getState().viewport.scale,f=(a.clientX-D.startX)/e,g=(a.clientY-D.startY)/e,h=aq(D.name);j(D.name,{...h,x:Math.max(0,D.origX+f),y:Math.max(0,D.origY+g)})},[D,aq,j,B,_,Z]),ay=(0,i.useCallback)(a=>{R.current.delete(a.pointerId),_(a.pointerId),$(a.pointerId);let b=S.current;if(b&&(b.a===a.pointerId||b.b===a.pointerId)){S.current=null,U(!1);let c=b.a===a.pointerId?b.b:b.a,d=R.current.get(c);if(d){let a=bk.getState().viewport;M.current={pointerId:c,startX:d.x,startY:d.y,origX:a.x,origY:a.y},P.current=!0,O(!0)}}M.current?.pointerId===a.pointerId&&(M.current=null),F.current?.pointerId===a.pointerId&&G(null),M.current||O(!1),S.current||U(!1)},[_,$,G]);(0,i.useEffect)(()=>{let a=C.current;if(!a)return;let b=a=>{a.preventDefault();let b=bk.getState().viewport,c=bx(a.deltaX,a.deltaMode),d=bx(a.deltaY,a.deltaMode);if(a.ctrlKey||a.metaKey){let c=a7(b,Math.exp(-(.0025*d)),Z(a.clientX,a.clientY));c!==b&&B(c);return}let e=a.shiftKey?-(c||d):-c,f=a.shiftKey?0:-d;(0!==e||0!==f)&&B(a6(b,e,f))};return a.addEventListener("wheel",b,{passive:!1}),()=>a.removeEventListener("wheel",b)},[B,Z]),(0,i.useEffect)(()=>{let a=a=>{"Space"!==a.code||a.repeat||by(a.target)||by(document.activeElement)||(a.preventDefault(),J.current=!0,L(!0))},b=a=>{"Space"===a.code&&(J.current=!1,L(!1))},c=()=>{J.current=!1,L(!1)};return window.addEventListener("keydown",a),window.addEventListener("keyup",b),window.addEventListener("blur",c),()=>{window.removeEventListener("keydown",a),window.removeEventListener("keyup",b),window.removeEventListener("blur",c)}},[]);let az=(0,i.useCallback)(a=>{let b=C.current?.getBoundingClientRect(),c={x:(b?.width??0)/2,y:(b?.height??0)/2},d=bk.getState().viewport,e=a7(d,a,c);e!==d&&B(e)},[B]),aA=(0,i.useCallback)(()=>{let a=C.current?.getBoundingClientRect(),b={x:(a?.width??0)/2,y:(a?.height??0)/2};B(a8(bk.getState().viewport,1,b))},[B]),aB=(0,i.useCallback)(()=>{let a=C.current?.getBoundingClientRect();if(!a)return;let b=al.map(a=>aq(a.name));B(b.length?function(a,b,c,d={}){let e=d.padding??48,f=d.maxScale??1,g=d.limits??a3;if(0===a.length||b<=0||c<=0)return{...a4};let h=1/0,i=1/0,j=-1/0,k=-1/0;for(let b of a)h=Math.min(h,b.x),i=Math.min(i,b.y),j=Math.max(j,b.x+b.width),k=Math.max(k,b.y+b.height);let l=Math.max(1,j-h),m=Math.max(1,k-i),n=a5(Math.min(f,Math.min(Math.max(1,b-2*e)/l,Math.max(1,c-2*e)/m)),g);return{x:(b-l*n)/2-h*n,y:(c-m*n)/2-i*n,scale:n}}(b,a.width,a.height):{...a4})},[al,aq,B]),aC=(0,i.useCallback)((a,b)=>{a.preventDefault(),a.stopPropagation(),p(a.clientX,a.clientY,b?{kind:"state",id:b}:{kind:"canvas"})},[p]),aD=(0,i.useMemo)(()=>{let a=new Set(al.map(a=>a.name)),b=[];for(let c of al)for(let[d,e]of(c.transitions??[]).entries())e.nextState&&a.has(e.nextState)&&b.push({from:c.name,to:e.nextState,event:e.event,stateName:c.name,index:d,condition:e.condition});return b},[al]),aE=(0,i.useMemo)(()=>{let a=function(a,b){let c=a.map(({from:a,to:c})=>{var d,e;return a===c?null:(d=b(a),(e=b(c)).y>=d.y+d.height?["bottom","top"]:e.y+e.height<=d.y?["top","bottom"]:e.x>=d.x+d.width?["right","left"]:e.x+e.width<=d.x?["left","right"]:["bottom","top"])}),d=new Map,e=(a,b,c)=>{let e=`${a}\0${b}`,f=d.get(e);f?f.push(c):d.set(e,[c])},f=(a,b)=>"top"===b||"bottom"===b?a.x+a.width/2:a.y+a.height/2;a.forEach((a,d)=>{let g=c[d];if(!g)return;let[h,i]=g;e(a.from,h,{edge:d,toward:f(b(a.to),h),role:"out"}),e(a.to,i,{edge:d,toward:f(b(a.from),i),role:"in"})});let g=new Map;for(let[a,c]of d){let[d,e]=a.split("\0"),f=b(d),h=[...c].sort((a,b)=>a.toward===b.toward?a.edge-b.edge:a.toward-b.toward);h.forEach((a,b)=>{g.set(`${a.edge}\0${a.role}`,function(a,b,c,d){let e="top"===b||"bottom"===b,f=e?a.width:a.height,g=e?a.x+a.width/2:a.y+a.height/2,h=d>1?Math.min(.72*f,40*(d-1)):0,i=d>1?g-h/2+h*c/(d-1):g;return"top"===b?{x:i,y:a.y}:"bottom"===b?{x:i,y:a.y+a.height}:"left"===b?{x:a.x,y:i}:{x:a.x+a.width,y:i}}(f,e,b,h.length))})}return a.map((a,d)=>{let e=c[d];if(!e){var f;let c,d,e;return c=(f=b(a.from)).x+f.width,d=f.y+.35*f.height,a$({x:c,y:d},{x:c+44,y:d-12},{x:c+44,y:(e=f.y+.65*f.height)+12},{x:c,y:e})}let h=g.get(`${d}\0out`),i=g.get(`${d}\0in`);var j=e[0];if("top"===j||"bottom"===j){let a=(h.y+i.y)/2;return a$(h,{x:h.x,y:a},{x:i.x,y:a},i)}let k=(h.x+i.x)/2;return a$(h,{x:k,y:h.y},{x:k,y:i.y},i)})}(aD,aq),b=new Map((function(a,b,c={}){let{along:d,aside:e,across:f}={...aV,...c},g=a.map((a,b)=>({label:a,i:b,width:aS(a).width})).sort((a,b)=>a.width===b.width?a.i-b.i:b.width-a.width),h=[];for(let{label:a}of g){let{width:c,height:g}=aS(a),i=8*!!a.glyph,j=null,k=1/0;a:for(let l of f)for(let f of e)for(let e of d){let d=a.at(e),m=d.x+f*c,n=d.y+l*g,o={x:m-c/2,y:n-18,width:c,height:g},p=[...h,...b].filter(a=>aU(o,a)).length,q={...o,cx:m+i,cy:n,label:a};if(0===p){j=q;break a}p<k&&(k=p,j=q)}j&&h.push(j)}return h})(aD.map((b,c)=>{let d=aq(b.from);return{id:`${b.stateName}:${b.index}`,event:b.event,condition:b.condition,glyph:!0,at:b.from===b.to?()=>({x:d.x+d.width+44+30,y:d.y+d.height/2+4}):a[c].at}}),al.map(a=>aq(a.name))).map(a=>[a.label.id,a]));return aD.flatMap((c,d)=>{let e=`${c.stateName}:${c.index}`,f=b.get(e);return f?[{arrow:c,id:e,curve:a[d],spot:f}]:[]})},[aD,al,aq]);return(0,i.useEffect)(()=>{let a=new Set(al.map(a=>a.name)),b=new Set(aD.map(a=>`${a.stateName}:${a.index}`)),c=ad.current===v,d=[...a].filter(a=>!ab.current.has(a));d.length&&ag(a=>{let b=new Set(a);return d.forEach(a=>b.add(a)),b});let e=[...b].filter(a=>!ae.current.has(a));e.length&&ai(a=>{let b=new Set(a);return e.forEach(a=>b.add(a)),b}),ag(b=>{let c=!1,d=new Set(b);return b.forEach(b=>{a.has(b)||(d.delete(b),c=!0)}),c?d:b}),ai(a=>{let c=!1,d=new Set(a);return a.forEach(a=>{b.has(a)||(d.delete(a),c=!0)}),c?d:a}),c?ak(b=>{let c=new Map(b),d=!1;return ac.current.forEach((b,e)=>{a.has(e)||c.has(e)||(c.set(e,b),d=!0)}),a.forEach(a=>{c.delete(a)&&(d=!0)}),d?c:b}):ak(a=>a.size?new Map:a),ab.current=a,ac.current=new Map(al.map(a=>[a.name,{state:a,pos:aq(a.name)}])),ae.current=b,ad.current=v},[al,v,aD,aq]),(0,h.jsxs)("div",{className:"relative w-full h-full",style:{touchAction:"none"},"data-pinch-owner":bl,children:[u.length>1&&(0,h.jsx)("div",{className:"absolute top-2 left-2 z-10 flex items-center gap-1 bg-gray-900/90 border border-gray-700 rounded-lg px-3 py-1.5 text-sm",children:u.map((a,b)=>(0,h.jsxs)("span",{className:"flex items-center gap-1",children:[b>0&&(0,h.jsx)("span",{className:"text-gray-600",children:"›"}),(0,h.jsx)("button",{className:`hover:text-blue-400 ${b===u.length-1?"text-blue-400 font-semibold":"text-gray-400"}`,onClick:()=>x(b),children:a})]},a))}),(0,h.jsxs)("svg",{ref:C,id:bo,className:"w-full h-full bg-gray-950",style:{cursor:N?"grabbing":K?"grab":void 0,touchAction:"none",...X?{WebkitUserSelect:"none",userSelect:"none",WebkitTouchCallout:"none"}:{}},onPointerDownCapture:au,onPointerDown:aw,onPointerMove:ax,onPointerUp:ay,onPointerCancel:ay,onAuxClick:a=>a.preventDefault(),onClick:a=>{if(W.current){W.current=!1,a.stopPropagation();return}if(P.current){P.current=!1;return}a.target?.tagName==="svg"&&(g(),I(null))},onContextMenu:a=>aC(a),children:[(0,h.jsxs)("defs",{children:[(0,h.jsx)("marker",{id:"arrowhead",markerWidth:"10",markerHeight:"7",refX:"10",refY:"3.5",orient:"auto",children:(0,h.jsx)("polygon",{points:"0 0, 10 3.5, 0 7",fill:"#94a3b8"})}),(0,h.jsx)("marker",{id:"arrowhead-blue",markerWidth:"10",markerHeight:"7",refX:"10",refY:"3.5",orient:"auto",children:(0,h.jsx)("polygon",{points:"0 0, 10 3.5, 0 7",fill:"#3b82f6"})})]}),"transition"===k&&l&&(0,h.jsxs)("text",{x:"50%",y:"30",fill:"#f59e0b",fontSize:13,textAnchor:"middle",className:"pointer-events-none select-none",children:['Click target state to create transition from "',l,'"']}),(0,h.jsxs)("g",{transform:`translate(${A.x} ${A.y}) scale(${A.scale})`,style:N||T?{pointerEvents:"none"}:void 0,children:[aE.map(({arrow:a,id:b,curve:c,spot:d})=>{let g="transition"===e.kind&&e.id===b,i=ah.has(b),j=c.at(.5),k=Math.hypot(j.x-d.cx,j.y-d.cy)>4;return(0,h.jsxs)("g",{children:[X&&(0,h.jsx)("path",{d:c.path,fill:"none",stroke:"transparent",strokeWidth:ao,strokeLinecap:"round",pointerEvents:"stroke",onClick:a=>{a.stopPropagation(),f("transition",b)}}),(0,h.jsx)("path",{d:c.path,fill:"none",pathLength:1,stroke:g?"#3b82f6":"#94a3b8",strokeWidth:g?2.5:1.5,markerEnd:g?"url(#arrowhead-blue)":"url(#arrowhead)",className:`cursor-pointer hover:stroke-blue-400${i?" sm-edge-enter":""}`,onClick:a=>{a.stopPropagation(),f("transition",b)}}),(0,h.jsxs)("g",{className:"cursor-pointer",onClick:a=>{a.stopPropagation(),f("transition",b)},children:[k&&(0,h.jsx)("line",{x1:j.x,y1:j.y,x2:d.cx,y2:d.cy-5,stroke:g?"#3b82f6":"#334155",strokeWidth:1,strokeDasharray:"2 3",className:"pointer-events-none"}),X&&(0,h.jsx)("rect",{x:d.x-an,y:d.y-an,width:d.width+2*an,height:d.height+2*an,fill:"transparent",pointerEvents:"all"}),(0,h.jsx)("rect",{x:d.x,y:d.y,width:d.width,height:d.height,rx:4,fill:g?"#1e3a5f":"#1e293b",stroke:g?"#3b82f6":"#334155",strokeWidth:1,className:"hover:fill-gray-800"}),(0,h.jsx)(bz,{mark:function(a){let b=a.toLowerCase();for(let{glyph:a,words:c}of aY)if(c.some(a=>b.includes(a)))return a;return aX}(a.event),x:aT(d).x,y:aT(d).y,color:g?"#93c5fd":"#7c93b0"}),(0,h.jsx)("text",{x:d.cx,y:d.cy-5,fill:g?"#93c5fd":"#94a3b8",fontSize:11,fontWeight:500,textAnchor:"middle",className:"pointer-events-none select-none",children:a.event}),a.condition&&(0,h.jsxs)("text",{x:d.cx,y:d.cy+7,fill:"#64748b",fontSize:9,textAnchor:"middle",className:"select-none",children:[(0,h.jsx)("title",{children:a.condition}),aR(a.condition)]})]})]},`arrow-${b}`)}),al.map(a=>{let b=aq(a.name),c="state"===e.kind&&e.id===a.name,d="final"===a.kind,f="history"===a.kind,g=(a.states?.length??0)>0,i=l===a.name,j=ar(a.name),m=(a.onEntry?.actions?.length??0)>0,n=(a.onExit?.actions?.length??0)>0,o=z.includes(a.name),p=af.has(a.name);return(0,h.jsxs)("g",{onPointerDown:b=>av(b,a.name),onDoubleClick:b=>{b.stopPropagation(),g&&w(a.name)},onContextMenu:b=>aC(b,a.name),className:K?void 0:"transition"===k?"cursor-crosshair":g?"cursor-pointer":"cursor-grab active:cursor-grabbing",children:[X&&(0,h.jsx)("rect",{x:b.x-an,y:b.y-an,width:b.width+2*an,height:b.height+2*an,rx:12,fill:"transparent",pointerEvents:"all"}),(0,h.jsxs)("g",{className:p?"sm-node-enter":void 0,children:[(0,h.jsx)("rect",{x:b.x,y:b.y,width:b.width,height:b.height,rx:f?30:d?4:8,fill:i?"#1e3a5f":d?"#1e293b":g?"#0c1020":"#0f172a",stroke:j?"#ef4444":c?"#3b82f6":i?"#f59e0b":"#475569",strokeWidth:c?2.5:j?2:1.5,strokeDasharray:d?"6 3":g?"4 2":void 0,className:o?"sm-node-active":void 0}),(0,h.jsx)("text",{x:b.x+b.width/2,y:b.y+(m||n?b.height/2:b.height/2+5),fill:"#e2e8f0",fontSize:14,fontWeight:600,textAnchor:"middle",className:"pointer-events-none select-none",children:a.name}),a.kind&&"normal"!==a.kind&&(0,h.jsx)("text",{x:b.x+b.width-8,y:b.y+14,fill:"#64748b",fontSize:10,textAnchor:"end",className:"pointer-events-none select-none",children:a.kind}),m&&(0,h.jsx)("text",{x:b.x+6,y:b.y+b.height-6,fill:"#22c55e",fontSize:9,className:"pointer-events-none select-none",children:"▸entry"}),n&&(0,h.jsx)("text",{x:b.x+b.width-6,y:b.y+b.height-6,fill:"#f97316",fontSize:9,textAnchor:"end",className:"pointer-events-none select-none",children:"exit◂"}),j&&(0,h.jsx)("text",{x:b.x+6,y:b.y+14,fill:"#ef4444",fontSize:12,className:"pointer-events-none select-none",children:"⚠"}),g&&(0,h.jsxs)("text",{x:b.x+b.width/2,y:b.y+b.height-6,fill:"#6366f1",fontSize:9,textAnchor:"middle",className:"pointer-events-none select-none",children:["▼ ",a.states?.length," children — double-click to enter"]})]})]},a.name)}),Array.from(aj.entries()).map(([a,{state:b,pos:c}])=>{let d="final"===b.kind,e=(b.states?.length??0)>0;return(0,h.jsxs)("g",{className:"sm-node-exit",style:{pointerEvents:"none"},onAnimationEnd:b=>{"sm-node-out"===b.animationName&&ak(b=>{if(!b.has(a))return b;let c=new Map(b);return c.delete(a),c})},children:[(0,h.jsx)("rect",{x:c.x,y:c.y,width:c.width,height:c.height,rx:"history"===b.kind?30:d?4:8,fill:d?"#1e293b":e?"#0c1020":"#0f172a",stroke:"#475569",strokeWidth:1.5,strokeDasharray:d?"6 3":e?"4 2":void 0}),(0,h.jsx)("text",{x:c.x+c.width/2,y:c.y+c.height/2+5,fill:"#e2e8f0",fontSize:14,fontWeight:600,textAnchor:"middle",className:"select-none",children:a})]},`exit-${a}`)})]}),0===al.length&&(0,h.jsx)("text",{x:"50%",y:"50%",fill:"#475569",fontSize:16,textAnchor:"middle",children:X?"Press and hold to add a state, or load a .smdf.json file":"Right-click to add a state, or load a .smdf.json file"})]}),(0,h.jsxs)("div",{className:"absolute bottom-3 left-3 z-10 flex items-center gap-0.5 bg-gray-900/90 border border-gray-700 rounded-lg px-1.5 py-1 text-xs text-gray-400 select-none",children:[(0,h.jsx)("button",{className:`${ap} rounded hover:bg-gray-800 hover:text-gray-200 disabled:opacity-40 disabled:hover:bg-transparent`,title:"Zoom out (Ctrl + wheel down, or pinch in)",disabled:A.scale<=a3.min,onClick:()=>az(.8),children:"−"}),(0,h.jsxs)("button",{className:`${ap} rounded hover:bg-gray-800 hover:text-gray-200 tabular-nums min-w-[3.25rem]`,title:"Reset zoom to 100%",onClick:aA,children:[Math.round(100*A.scale),"%"]}),(0,h.jsx)("button",{className:`${ap} rounded hover:bg-gray-800 hover:text-gray-200 disabled:opacity-40 disabled:hover:bg-transparent`,title:"Zoom in (Ctrl + wheel up, or pinch out)",disabled:A.scale>=a3.max,onClick:()=>az(1.25),children:"+"}),(0,h.jsx)("span",{className:"text-gray-700 px-0.5",children:"|"}),(0,h.jsx)("button",{className:`${ap} rounded hover:bg-gray-800 hover:text-gray-200`,title:"Fit the whole machine in view",onClick:aB,children:"⤢ Fit"}),(0,h.jsx)("span",{className:"text-gray-700 px-0.5",children:"|"}),(0,h.jsx)("span",{className:"px-1 text-[10px] text-gray-600",title:X?"Drag to pan · pinch with two fingers to zoom · press and hold for the menu · double-tap a composite to enter it":"Wheel scrolls · Shift+wheel scrolls sideways · Ctrl+wheel zooms at the cursor · middle-drag or Space+drag pans",children:T?"pinching":N?"panning":X?"drag · pinch · hold":K?"space to pan":"wheel · ⌃wheel · space"})]}),H&&(0,h.jsxs)("div",{className:"absolute z-50 bg-gray-900 border border-gray-700 rounded-lg shadow-xl p-2 min-w-[160px]",style:{left:H.x,top:H.y-80},onClick:a=>a.stopPropagation(),children:[(0,h.jsxs)("div",{className:"text-xs text-gray-400 mb-1 px-1",children:[H.stateName," → ",H.targetName]}),(0,h.jsx)("div",{className:"text-xs text-gray-500 mb-1 px-1",children:"Select event:"}),0===am.length?(0,h.jsx)("div",{className:"text-xs text-gray-600 px-1 py-2",children:"No events defined. Add events first."}):am.map(a=>(0,h.jsx)("button",{className:"block w-full text-left text-sm text-gray-300 hover:bg-gray-800 px-2 py-1 rounded",onClick:()=>{var b;return b=a.id,void(H&&(o(H.stateName,{event:b,nextState:H.targetName}),I(null),m(null),n("select")))},children:a.id},a.id)),(0,h.jsx)("button",{className:"block w-full text-left text-xs text-gray-500 hover:text-gray-300 px-2 py-1 mt-1 border-t border-gray-800",onClick:()=>{I(null),m(null)},children:"Cancel"})]})]})}function bB({label:a,actions:b,onChange:c}){let d=(a,d)=>c(b.map((b,c)=>c===a?{...b,...d}:b));return(0,h.jsxs)("div",{children:[(0,h.jsxs)("div",{className:"flex items-center justify-between",children:[(0,h.jsx)("span",{className:"text-xs font-medium text-gray-500",children:a}),(0,h.jsx)("button",{onClick:()=>c([...b,{action:"code",code:""}]),className:"text-xs text-blue-500 hover:text-blue-400",children:"+ action"})]}),b.map((a,e)=>(0,h.jsxs)("div",{className:"flex items-start gap-1 mt-1",children:[(0,h.jsxs)("select",{className:"bg-gray-800 border border-gray-700 rounded px-1 py-0.5 text-xs text-gray-200",value:a.action,onChange:a=>d(e,{action:a.target.value}),children:[(0,h.jsx)("option",{value:"code",children:"Code"}),(0,h.jsx)("option",{value:"timerStart",children:"Timer Start"}),(0,h.jsx)("option",{value:"timerStop",children:"Timer Stop"})]}),"code"===a.action?(0,h.jsx)("textarea",{className:"flex-1 bg-gray-800 border border-gray-700 rounded px-1 py-0.5 text-xs text-gray-200 h-10 font-mono",value:a.code??"",placeholder:"// action code...",onChange:a=>d(e,{code:a.target.value})}):(0,h.jsx)("input",{className:"flex-1 bg-gray-800 border border-gray-700 rounded px-1 py-0.5 text-xs text-gray-200",value:a.name??"",placeholder:"Timer name",onChange:a=>d(e,{name:a.target.value})}),(0,h.jsx)("button",{onClick:()=>c(b.filter((a,b)=>b!==e)),className:"text-red-600 hover:text-red-400 text-xs mt-0.5",children:"✕"})]},e)),0===b.length&&(0,h.jsx)("span",{className:"text-xs text-gray-700 italic",children:"none"})]})}function bC(){let a=bk(a=>a.definition),b=bk(a=>a.selection),c=bk(a=>a.updateState),d=bk(a=>a.removeState);bk(a=>a.addAction),bk(a=>a.removeAction);let e=bk(a=>a.updateTransition),f=bk(a=>a.removeTransition);if(!b.kind||!b.id)return(0,h.jsx)("div",{className:"p-3 text-xs text-gray-500",children:"Select a state or transition to edit its properties."});let g=(a,b)=>{if(a.name===b)return a;for(let c of a.states??[]){let a=g(c,b);if(a)return a}return null};if("state"===b.kind){let e=g(a.state,b.id);if(!e)return(0,h.jsx)("div",{className:"p-3 text-gray-500 text-xs",children:"State not found"});let i=e.onEntry?.actions??[],j=e.onExit?.actions??[];return(0,h.jsxs)("div",{className:"p-3 space-y-3 text-sm md:overflow-y-auto md:max-h-[calc(100vh-160px)]",children:[(0,h.jsxs)("h3",{className:"text-xs font-semibold text-gray-400",children:["State: ",e.name]}),(0,h.jsxs)("label",{className:"block",children:[(0,h.jsx)("span",{className:"text-xs text-gray-500",children:"Name"}),(0,h.jsx)("input",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-sm text-gray-200",value:e.name,onChange:a=>c(b.id,{name:a.target.value})})]}),(0,h.jsxs)("label",{className:"block",children:[(0,h.jsx)("span",{className:"text-xs text-gray-500",children:"Kind"}),(0,h.jsxs)("select",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-sm text-gray-200",value:e.kind??"normal",onChange:a=>c(b.id,{kind:a.target.value}),children:[(0,h.jsx)("option",{value:"normal",children:"Normal"}),(0,h.jsx)("option",{value:"final",children:"Final"}),(0,h.jsx)("option",{value:"history",children:"History"})]})]}),(0,h.jsxs)("label",{className:"block",children:[(0,h.jsx)("span",{className:"text-xs text-gray-500",children:"Description"}),(0,h.jsx)("textarea",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-xs text-gray-200 h-12",value:e.description??"",onChange:a=>c(b.id,{description:a.target.value||void 0})})]}),(0,h.jsx)(bB,{label:"▸ onEntry Actions",actions:i,onChange:a=>c(b.id,{onEntry:{actions:a}})}),(0,h.jsx)(bB,{label:"◂ onExit Actions",actions:j,onChange:a=>c(b.id,{onExit:{actions:a}})}),(0,h.jsxs)("div",{children:[(0,h.jsx)("span",{className:"text-xs font-medium text-gray-500",children:"Transitions"}),(e.transitions??[]).map((a,c)=>(0,h.jsxs)("div",{className:"flex items-center gap-1 text-xs text-gray-400 py-1 border-b border-gray-800/50",children:[(0,h.jsxs)("span",{className:"flex-1",children:[a.event," → ",a.nextState??"(internal)"]}),a.condition&&(0,h.jsxs)("span",{className:"text-gray-600",children:["[",a.condition,"]"]}),(0,h.jsx)("button",{onClick:()=>f(b.id,c),className:"text-red-600 hover:text-red-400",children:"✕"})]},c)),(e.transitions?.length??0)===0&&(0,h.jsx)("span",{className:"text-xs text-gray-700 italic",children:"none"})]}),(0,h.jsx)("button",{onClick:()=>d(b.id),className:"text-red-500 hover:text-red-400 text-xs mt-2",children:"🗑 Delete State"})]})}if("transition"===b.kind){let[c,d]=b.id.split(":"),i=parseInt(d,10),j=g(a.state,c),k=j?.transitions?.[i];if(!k)return(0,h.jsx)("div",{className:"p-3 text-gray-500 text-xs",children:"Transition not found"});let l=bh(a),m=(function a(b){let c=[b];for(let d of b.states??[])c.push(...a(d));return c})(a.state).map(a=>a.name).filter(a=>"Root"!==a);return(0,h.jsxs)("div",{className:"p-3 space-y-3 text-sm",children:[(0,h.jsx)("h3",{className:"text-xs font-semibold text-gray-400",children:"Transition"}),(0,h.jsxs)("label",{className:"block",children:[(0,h.jsx)("span",{className:"text-xs text-gray-500",children:"Event"}),(0,h.jsx)("select",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-sm text-gray-200",value:k.event,onChange:a=>e(c,i,{event:a.target.value}),children:l.map(a=>(0,h.jsx)("option",{value:a,children:a},a))})]}),(0,h.jsxs)("label",{className:"block",children:[(0,h.jsx)("span",{className:"text-xs text-gray-500",children:"Target State"}),(0,h.jsxs)("select",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-sm text-gray-200",value:k.nextState??"",onChange:a=>e(c,i,{nextState:a.target.value||void 0}),children:[(0,h.jsx)("option",{value:"",children:"(internal transition)"}),m.map(a=>(0,h.jsx)("option",{value:a,children:a},a))]})]}),(0,h.jsxs)("label",{className:"block",children:[(0,h.jsx)("span",{className:"text-xs text-gray-500",children:"Condition (guard)"}),(0,h.jsx)("textarea",{rows:3,className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-sm text-gray-200 resize-y leading-snug",value:k.condition??"",onChange:a=>e(c,i,{condition:a.target.value||void 0})})]}),(0,h.jsx)("button",{onClick:()=>f(c,i),className:"text-red-500 hover:text-red-400 text-xs",children:"🗑 Delete Transition"})]})}return null}let bD=["string","int","float","bool","object"];function bE(){let a=bk(a=>a.definition),b=bk(a=>a.addEvent),c=bk(a=>a.updateEvent),d=bk(a=>a.removeEvent),e=bk(a=>a.addParameter),f=bk(a=>a.removeParameter),g=bk(a=>a.updateParameter),j=bk(a=>a.updateEventSource),k=bk(a=>a.select),l=bk(a=>a.selection),[m,n]=(0,i.useState)(""),[o,p]=(0,i.useState)(null),[q,r]=(0,i.useState)(null);return(0,h.jsxs)("div",{className:"p-3 text-sm",children:[a.events.map((a,b)=>(0,h.jsxs)("div",{className:"mb-3",children:[(0,h.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,h.jsx)("span",{className:"text-xs font-semibold text-gray-500",children:"Source:"}),(0,h.jsx)("input",{className:"flex-1 bg-transparent border-b border-gray-700 text-xs text-gray-300 px-1 py-0.5 focus:border-blue-500 outline-none",value:a.name,onChange:a=>j(b,{name:a.target.value})}),void 0!==a.feeder&&(0,h.jsx)("input",{className:"w-24 bg-transparent border-b border-gray-700 text-xs text-gray-400 px-1 py-0.5 focus:border-blue-500 outline-none",value:a.feeder??"",placeholder:"Feeder...",onChange:a=>j(b,{feeder:a.target.value||void 0})}),void 0===a.feeder&&(0,h.jsx)("button",{className:"text-xs text-gray-600 hover:text-gray-400",title:"Add feeder class",onClick:()=>j(b,{feeder:`${a.name}Feeder`}),children:"+feeder"})]}),(0,h.jsx)("div",{className:"-mx-1 overflow-x-auto px-1",children:(0,h.jsxs)("table",{className:"w-full text-xs",children:[(0,h.jsx)("thead",{children:(0,h.jsxs)("tr",{className:"text-gray-600 border-b border-gray-800",children:[(0,h.jsx)("th",{className:"text-left py-1 font-medium",children:"ID"}),(0,h.jsx)("th",{className:"text-left py-1 font-medium",children:"Description"}),(0,h.jsx)("th",{className:"text-left py-1 font-medium",children:"Params"}),(0,h.jsx)("th",{className:"w-6"})]})}),(0,h.jsx)("tbody",{children:(a.events??[]).map(a=>(0,h.jsxs)(i.Fragment,{children:[(0,h.jsxs)("tr",{className:`border-b border-gray-800/50 hover:bg-gray-800/30 cursor-pointer ${"event"===l.kind&&l.id===a.id?"bg-blue-900/30":""}`,onClick:()=>{k("event",a.id),p(o===a.id?null:a.id)},children:[(0,h.jsx)("td",{className:"py-1 pr-1",children:q===a.id?(0,h.jsx)("input",{autoFocus:!0,className:"w-full bg-gray-800 border border-gray-700 rounded px-1 text-gray-200",value:a.id,onChange:b=>c(a.id,{id:b.target.value}),onBlur:()=>r(null),onKeyDown:a=>"Enter"===a.key&&r(null),onClick:a=>a.stopPropagation()}):(0,h.jsx)("span",{className:"text-gray-300",onDoubleClick:b=>{b.stopPropagation(),r(a.id)},children:a.id})}),(0,h.jsx)("td",{className:"py-1 pr-1 text-gray-500 truncate max-w-[80px]",children:a.description??"—"}),(0,h.jsx)("td",{className:"py-1 text-gray-500",children:(a.parameters?.length??0)>0?a.parameters.map(a=>`${a.name}:${a.type}`).join(", "):"—"}),(0,h.jsx)("td",{className:"py-1",children:(0,h.jsx)("button",{onClick:b=>{b.stopPropagation(),d(a.id)},className:"text-red-600 hover:text-red-400",children:"✕"})})]}),o===a.id&&(0,h.jsx)("tr",{children:(0,h.jsx)("td",{colSpan:4,className:"py-2 px-1 bg-gray-900/50",children:(0,h.jsxs)("div",{className:"space-y-2",children:[(0,h.jsxs)("label",{className:"block",children:[(0,h.jsx)("span",{className:"text-gray-600",children:"Description"}),(0,h.jsx)("input",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-0.5 text-gray-200 mt-0.5",value:a.description??"",onChange:b=>c(a.id,{description:b.target.value||void 0})})]}),(0,h.jsxs)("div",{children:[(0,h.jsx)("span",{className:"text-gray-600",children:"Parameters"}),(a.parameters??[]).map((b,c)=>(0,h.jsxs)("div",{className:"flex items-center gap-1 mt-1",children:[(0,h.jsx)("input",{className:"flex-1 bg-gray-800 border border-gray-700 rounded px-1 py-0.5 text-gray-200",value:b.name,placeholder:"name",onChange:b=>g(a.id,c,{name:b.target.value})}),(0,h.jsx)("select",{className:"bg-gray-800 border border-gray-700 rounded px-1 py-0.5 text-gray-200",value:b.type,onChange:b=>g(a.id,c,{type:b.target.value}),children:bD.map(a=>(0,h.jsx)("option",{value:a,children:a},a))}),(0,h.jsx)("button",{onClick:()=>f(a.id,c),className:"text-red-600 hover:text-red-400",children:"✕"})]},c)),(0,h.jsx)("button",{className:"text-blue-500 hover:text-blue-400 mt-1",onClick:()=>e(a.id,{name:"param",type:"string"}),children:"+ parameter"})]}),(0,h.jsxs)("div",{className:"mt-1",children:[(0,h.jsx)("span",{className:"text-gray-600",children:"Generated method:"}),(0,h.jsxs)("code",{className:"block bg-gray-800 rounded px-2 py-1 text-green-400 mt-0.5 font-mono",children:["on_",a.id.toLowerCase(),"(context",(a.parameters??[]).map(a=>`, ${a.name}: ${a.type}`).join(""),")"]})]})]})})})]},a.id))})]})})]},b)),(0,h.jsxs)("div",{className:"flex gap-1 mt-2",children:[(0,h.jsx)("input",{className:"flex-1 bg-gray-800 border border-gray-700 rounded px-2 py-1 text-gray-200",placeholder:"New event ID...",value:m,onChange:a=>n(a.target.value),onKeyDown:a=>{"Enter"===a.key&&m.trim()&&(b({id:m.trim()}),n(""))}}),(0,h.jsx)("button",{onClick:()=>{m.trim()&&(b({id:m.trim()}),n(""))},className:"bg-blue-600 hover:bg-blue-500 text-white px-2 py-1 rounded",children:"+"})]})]})}function bF(){let a=bk(a=>a.definition.settings),b=bk(a=>a.definition.settings.context),c=bk(a=>a.updateSettings);return(0,h.jsxs)("div",{className:"p-3 space-y-3 text-sm",children:[(0,h.jsx)("h3",{className:"text-xs font-semibold text-gray-400",children:"Machine Settings"}),(0,h.jsxs)("label",{className:"block",children:[(0,h.jsx)("span",{className:"text-xs text-gray-500",children:"Namespace"}),(0,h.jsx)("input",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-sm text-gray-200",value:a.namespace,onChange:a=>c({namespace:a.target.value})})]}),(0,h.jsxs)("label",{className:"block",children:[(0,h.jsx)("span",{className:"text-xs text-gray-500",children:"Name"}),(0,h.jsx)("input",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-sm text-gray-200",value:a.name??"",onChange:a=>c({name:a.target.value||void 0})})]}),(0,h.jsxs)("label",{className:"block",children:[(0,h.jsx)("span",{className:"text-xs text-gray-500",children:"Description"}),(0,h.jsx)("textarea",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-xs text-gray-200 h-12",value:a.description??"",onChange:a=>c({description:a.target.value||void 0})})]}),(0,h.jsxs)("label",{className:"flex items-center gap-2 text-sm text-gray-300",children:[(0,h.jsx)("input",{type:"checkbox",checked:a.asynchronous,onChange:a=>c({asynchronous:a.target.checked}),className:"rounded bg-gray-800 border-gray-600"}),"Asynchronous"]}),(0,h.jsx)("hr",{className:"border-gray-800"}),(0,h.jsx)("h4",{className:"text-xs font-semibold text-gray-500",children:"Context"}),(0,h.jsxs)("label",{className:"block",children:[(0,h.jsx)("span",{className:"text-xs text-gray-500",children:"Context Class"}),(0,h.jsx)("input",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-xs text-gray-200",value:b?.className??"",placeholder:"e.g. MyStateMachineContext",onChange:a=>c({context:{...b,className:a.target.value||void 0}})})]}),(0,h.jsxs)("label",{className:"block",children:[(0,h.jsx)("span",{className:"text-xs text-gray-500",children:"Base Class"}),(0,h.jsx)("input",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-xs text-gray-200",value:b?.baseClass??"",placeholder:"e.g. Context",onChange:a=>c({context:{...b,baseClass:a.target.value||void 0}})})]}),(0,h.jsx)("hr",{className:"border-gray-800"}),(0,h.jsx)("h4",{className:"text-xs font-semibold text-gray-500",children:"Imports"}),(0,h.jsx)("textarea",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-xs text-gray-200 h-16 font-mono",value:(a.imports??[]).join("\n"),placeholder:"One import per line",onChange:a=>c({imports:a.target.value?a.target.value.split("\n"):[]})}),(0,h.jsx)("hr",{className:"border-gray-800"}),(0,h.jsx)("h4",{className:"text-xs font-semibold text-gray-500",children:"Object References"}),(0,h.jsx)("textarea",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-xs text-gray-200 h-12 font-mono",value:(a.objects??[]).map(a=>`${a.name}: ${a.type}`).join("\n"),placeholder:"name: type (one per line)",onChange:a=>{c({objects:a.target.value.split("\n").filter(a=>a.includes(":")).map(a=>{let[b,c]=a.split(":").map(a=>a.trim());return{name:b,type:c}})})}}),(0,h.jsx)("hr",{className:"border-gray-800"}),(0,h.jsx)("h4",{className:"text-xs font-semibold text-gray-500",children:"Code Generation"}),(0,h.jsxs)("label",{className:"block",children:[(0,h.jsx)("span",{className:"text-xs text-gray-500",children:"Target Language"}),(0,h.jsxs)("select",{className:"w-full bg-gray-800 border border-gray-700 rounded px-2 py-1 text-xs text-gray-200",value:a.targetLanguage??"python",onChange:a=>c({targetLanguage:a.target.value}),children:[(0,h.jsx)("option",{value:"python",children:"Python"}),(0,h.jsx)("option",{value:"typescript",children:"TypeScript"}),(0,h.jsx)("option",{value:"csharp",children:"C#"})]})]})]})}function bG(){let a=bk(a=>a.errors),b=bk(a=>a.validate),c=bk(a=>a.select);return(0,h.jsxs)("div",{className:"p-3",children:[(0,h.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,h.jsxs)("h3",{className:"text-xs font-semibold text-gray-400",children:["Validation ",a.length>0&&(0,h.jsxs)("span",{className:"text-red-500",children:["(",a.length,")"]})]}),(0,h.jsx)("button",{onClick:()=>b(),className:"text-xs bg-gray-700 hover:bg-gray-600 text-gray-300 px-2 py-0.5 rounded",children:"Re-check"})]}),0===a.length?(0,h.jsxs)("div",{className:"flex items-center gap-2 text-green-500 text-xs",children:[(0,h.jsx)("span",{children:"✓"}),(0,h.jsx)("span",{children:"Definition is valid"})]}):(0,h.jsx)("div",{className:"space-y-0.5",children:a.map((a,b)=>(0,h.jsxs)("div",{className:`flex items-start gap-1.5 text-[13px] py-2.5 border-b border-gray-800/50 md:text-xs md:py-1 ${a.element?"cursor-pointer hover:bg-gray-800/30":""}`,onClick:()=>{a.element&&c("state",a.element)},title:a.element?`Click to select "${a.element}"`:void 0,children:[(0,h.jsx)("span",{className:`font-mono text-[10px] mt-0.5 ${"error"===a.severity?"text-red-600":"text-yellow-600"}`,children:a.ruleId}),(0,h.jsx)("span",{className:`flex-1 ${"error"===a.severity?"text-red-400":"text-yellow-400"}`,children:a.message}),a.element&&(0,h.jsxs)("span",{className:"text-gray-600 text-[10px]",children:["→ ",a.element]})]},b))})]})}var bH=a.i(41455);function bI(){let a=(0,bH.useRequestedDoc)(),[b,c]=(0,i.useState)(!1),[d,e]=(0,i.useState)(""),f=a=>{c(!1),e(""),(0,bH.navigateToDoc)(a)},g=b?(function(){try{let a=[];for(let b=0;b<window.localStorage.length;b++){let c=window.localStorage.key(b);c?.startsWith(bv)&&a.push(c.slice(bv.length))}return a.sort()}catch{return[]}})().filter(b=>b.startsWith("/")&&b!==a):[];return(0,h.jsxs)("span",{className:"relative inline-flex",children:[(0,h.jsx)("button",{onClick:()=>c(a=>!a),className:"toolbar-btn",title:a?`Document: ${a}`:"Switch document",children:"⇄"}),b&&(0,h.jsxs)("div",{className:"absolute left-0 top-full z-50 mt-1 w-72 rounded border border-gray-700 bg-gray-900 p-2 shadow-lg",children:[(0,h.jsx)("div",{className:"mb-1 text-[10px] uppercase tracking-wide text-gray-500",children:"switch document"}),a&&(0,h.jsx)("button",{onClick:()=>f(null),className:"block w-full truncate rounded px-1.5 py-1 text-left text-xs text-gray-300 hover:bg-gray-800",title:"Return to the default project file",children:"⌂ default document"}),g.map(a=>(0,h.jsxs)("button",{onClick:()=>f(a),className:"block w-full truncate rounded px-1.5 py-1 text-left text-xs text-gray-300 hover:bg-gray-800",title:a,children:[a.split("/").pop(),(0,h.jsx)("span",{className:"ml-1 text-[10px] text-gray-600",children:a})]},a)),(0,h.jsxs)("form",{onSubmit:a=>{a.preventDefault(),d.trim()&&f(d.trim())},className:"mt-1 flex gap-1",children:[(0,h.jsx)("input",{value:d,onChange:a=>e(a.target.value),placeholder:"/absolute/path/to/doc.smdf.json",className:"min-w-0 flex-1 rounded border border-gray-700 bg-gray-950 px-1.5 py-1 text-xs text-gray-200 placeholder:text-gray-600"}),(0,h.jsx)("button",{type:"submit",className:"toolbar-btn",title:"Open this document",children:"→"})]})]})]})}function bJ(){let a=bk(a=>a.definition),b=bk(a=>a.fileName),c=bk(a=>a.docPath),d=bk(a=>a.dirty),e=bk(a=>a.loadFromJson),f=bk(a=>a.exportJson),g=bk(a=>a.addState),j=bk(a=>a.validate),k=bk(a=>a.showCodePreview),l=bk(a=>a.setShowCodePreview),m=bk(a=>a.setGeneratedCode),n=bk(a=>a.drawMode),o=bk(a=>a.setDrawMode),p=bk(a=>a.arrangeLayout),q=bk(a=>a.undo),r=bk(a=>a.redo),s=bk(a=>a.undoStack),t=bk(a=>a.redoStack),u=bk(a=>a.remoteStatus),v=bk(a=>a.remoteMessage),w=bk(a=>a.setRemoteStatus),x=bk(a=>a.setRemoteMtime),y=bk(a=>a.applyRemote),z=(0,bH.useRequestedDoc)(),A=(0,i.useRef)(null),[B,C]=(0,i.useState)(!1),[D,E]=(0,i.useState)(""),[F,G]=(0,i.useState)(!1),[H,I]=(0,i.useState)("png"),[J,K]=(0,i.useState)(!1),[L,M]=(0,i.useState)(null),[N,O]=(0,i.useState)(null),P=async()=>{let a=f();G(!0);try{let b=await fetch(`/api/file${(0,bH.docQuery)(z)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:a})});if(b.ok){let a=await b.json();x(a.mtime),bk.setState({dirty:!1}),w("synced",null)}else{let a=await b.json().catch(()=>({error:"unknown"}));w("error",`Save failed: ${a.error??b.statusText}`)}}catch(a){w("error",`Save failed: ${a}`)}finally{G(!1)}},Q=async()=>{K(!0),M(null);try{let d=await bu(H,{definition:a,docPath:c,fileName:b});O(d)}catch(a){M(a instanceof Error?a.message:String(a))}finally{K(!1)}},R=async()=>{try{let a=await fetch(`/api/file${(0,bH.docQuery)(z)}`,{cache:"no-store"});if(!a.ok)return void w("error","Reload failed");let b=await a.json();b.exists&&b.content?y(b.content,b.mtime,b.path.split("/").pop()):w("idle",`No file at ${b.path}`)}catch(a){w("error",`Reload failed: ${a}`)}},S=()=>{D.trim()&&(g(null,{name:D.trim(),kind:"normal"}),E(""),C(!1))},[T,U]=(0,i.useState)("python"),V=async()=>{try{let a=await fetch("/api/rispec",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({})});if(a.ok){let b=await a.json();m(b.rispec)}else{let b=await a.json().catch(()=>({error:"Unknown"}));m(`# RISE rispec generation failed
|
|
7
7
|
${b.error}`)}}catch(a){m(`# RISE rispec generation failed
|
|
8
|
-
${a}`)}l(!0)},
|
|
8
|
+
${a}`)}l(!0)},W=async()=>{let a=f();try{let b=await fetch("/api/generate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({definition:a,language:T})});if(b.ok){let a=await b.json();m(a.code)}else{let c=await b.json().catch(()=>({error:"Unknown error"}));m(`// Code generation failed: ${c.error}
|
|
9
9
|
// Showing definition JSON as fallback:
|
|
10
10
|
${a}`)}}catch{m(`// Backend unavailable — showing definition JSON
|
|
11
|
-
${a}`)}l(!0)};return(0,h.jsxs)("div",{className:"flex flex-col gap-1.5 px-2 py-1.5 bg-gray-900 border-b border-gray-800 md:flex-row md:flex-wrap md:items-center md:px-3",children:[(0,h.jsxs)("div",{className:"toolbar-ident",children:[(0,h.jsx)("input",{ref:z,type:"file",accept:".json,.smdf.json",onChange:a=>{let b=a.target.files?.[0];if(!b)return;let c=new FileReader;c.onload=a=>{e(a.target?.result,b.name)},c.readAsText(b),a.target.value=""},className:"hidden"}),(0,h.jsxs)("span",{className:"text-xs text-gray-400 mr-1 truncate max-w-[50vw] md:max-w-none",children:[b??"untitled.smdf.json",d&&(0,h.jsx)("span",{className:"text-yellow-500 ml-0.5",children:"●"})]}),"synced"===u&&(0,h.jsx)("span",{className:"text-[10px] text-emerald-500",title:"In sync with disk",children:"⌁ synced"}),"remote-changed"===u&&(0,h.jsx)("span",{className:"text-[10px] text-amber-400",title:v??"",children:"↻ remote changed"}),"error"===u&&(0,h.jsx)("span",{className:"text-[10px] text-red-400",title:v??"",children:"⚠ disk error"}),"idle"===u&&(0,h.jsx)("span",{className:"text-[10px] text-gray-600",title:v??"No file bound",children:"○ no disk"}),(0,h.jsx)("div",{className:"flex-1"})]}),(0,h.jsxs)("div",{className:"toolbar-strip",children:[(0,h.jsx)("button",{onClick:q,disabled:0===s.length,className:"toolbar-btn disabled:opacity-30",title:"Undo (Ctrl+Z)",children:"↩"}),(0,h.jsx)("button",{onClick:r,disabled:0===t.length,className:"toolbar-btn disabled:opacity-30",title:"Redo (Ctrl+Y)",children:"↪"}),(0,h.jsx)("div",{className:"w-px h-4 bg-gray-700"}),(0,h.jsx)("button",{onClick:p,className:"toolbar-btn",title:"Arrange states into layers (auto-layout)",children:"⤢ Arrange"}),(0,h.jsx)("div",{className:"w-px h-4 bg-gray-700"}),(0,h.jsx)("button",{onClick:()=>o("select"===n?"transition":"select"),className:`toolbar-btn ${"transition"===n?"!bg-amber-700 !text-white":""}`,title:"transition"===n?"Exit draw mode (Esc)":"Draw transition mode",children:"transition"===n?"✏️ Drawing":"↗ Draw"}),(0,h.jsx)("div",{className:"w-px h-4 bg-gray-700"}),(0,h.jsx)("button",{onClick:()=>z.current?.click(),className:"toolbar-btn",title:"Open local .smdf.json (browser)",children:"📂"}),(0,h.jsx)("button",{onClick:O,disabled:E,className:"toolbar-btn disabled:opacity-40",title:"Save to disk (STATELOOM_PROJECT_FILE)",children:"💾 Disk"}),(0,h.jsx)("button",{onClick:Q,className:"toolbar-btn",title:"Reload from disk",children:"🔄"}),(0,h.jsx)("button",{onClick:()=>{let a=new Blob([f()],{type:"application/json"}),c=URL.createObjectURL(a),d=document.createElement("a");d.href=c,d.download=b??"statemachine.smdf.json",d.click(),URL.revokeObjectURL(c)},className:"toolbar-btn",title:"Download as file",children:"📥"}),(0,h.jsx)("select",{value:G,onChange:a=>{H(a.target.value),N(null),L(null)},className:"bg-gray-800 border border-gray-700 rounded text-xs text-gray-300 px-1 py-0.5",title:"Export format",children:bq.map(a=>(0,h.jsx)("option",{value:a,children:br[a]},a))}),(0,h.jsx)("button",{onClick:P,disabled:I,className:`toolbar-btn disabled:opacity-40 ${K?"!text-red-400":""}`,title:K??`Export the board as ${br[G]}`,children:I?"…":"🖼 Export"}),M&&!K&&(0,h.jsxs)("span",{className:"text-[10px] text-emerald-500 truncate max-w-[40vw] md:max-w-[16rem]",title:M,children:["⤓ ",M]}),(0,h.jsx)("div",{className:"w-px h-4 bg-gray-700"}),A?(0,h.jsxs)("div",{className:"flex items-center gap-1",children:[(0,h.jsx)("input",{autoFocus:!0,className:"bg-gray-800 border border-gray-700 rounded px-2 py-0.5 text-xs text-gray-200 w-32 md:w-24",placeholder:"State name...",value:C,onChange:a=>D(a.target.value),onKeyDown:a=>{"Enter"===a.key&&R(),"Escape"===a.key&&B(!1)}}),(0,h.jsx)("button",{onClick:R,className:"toolbar-btn-sm",children:"✓"}),(0,h.jsx)("button",{onClick:()=>B(!1),className:"toolbar-btn-sm",children:"✕"})]}):(0,h.jsx)("button",{onClick:()=>B(!0),className:"toolbar-btn",children:"+State"}),(0,h.jsx)("div",{className:"w-px h-4 bg-gray-700"}),(0,h.jsx)("button",{onClick:()=>j(),className:"toolbar-btn",children:"✓ Validate"}),(0,h.jsxs)("select",{value:S,onChange:a=>T(a.target.value),className:"bg-gray-800 border border-gray-700 rounded text-xs text-gray-300 px-1 py-0.5",children:[(0,h.jsx)("option",{value:"python",children:"Python"}),(0,h.jsx)("option",{value:"typescript",children:"TypeScript"})]}),(0,h.jsx)("button",{onClick:V,className:"toolbar-btn",children:"⚡ Generate"}),(0,h.jsx)("button",{onClick:U,className:"toolbar-btn",title:"Generate RISE rispec markdown",children:"📜 RISE"}),(0,h.jsxs)("button",{onClick:()=>l(!k),className:`toolbar-btn ${k?"text-blue-400":""}`,children:["</>"," Code"]})]})]})}function bH(){let a=bk(a=>a.generatedCode),b=bk(a=>a.showCodePreview),c=bk(a=>a.setShowCodePreview);return b?(0,h.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/60 p-2 md:p-0",children:(0,h.jsxs)("div",{className:"bg-gray-900 border border-gray-700 rounded-lg shadow-xl w-full max-h-[85dvh] md:w-[80%] md:max-w-3xl md:max-h-[80dvh] flex flex-col",children:[(0,h.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b border-gray-800",children:[(0,h.jsx)("h3",{className:"text-sm font-semibold text-gray-300",children:"Generated Definition (JSON)"}),(0,h.jsx)("button",{onClick:()=>c(!1),className:"text-gray-500 hover:text-gray-300 text-lg min-h-11 min-w-11 md:min-h-0 md:min-w-0","aria-label":"Close preview",children:"✕"})]}),(0,h.jsx)("pre",{className:"flex-1 overflow-auto overscroll-contain p-4 text-[11px] leading-relaxed text-green-400 font-mono md:text-sm",children:a??"No code generated yet"}),(0,h.jsx)("div",{className:"flex justify-end px-4 py-2 border-t border-gray-800",children:(0,h.jsx)("button",{onClick:()=>{a&&navigator.clipboard.writeText(a)},className:"text-xs bg-gray-700 hover:bg-gray-600 text-gray-300 px-4 py-3 rounded md:px-3 md:py-1",children:"Copy to Clipboard"})})]})}):null}function bI(){let a=bk(a=>a.applyRemote),b=bk(a=>a.setRemoteStatus),c=bk(a=>a.setRemoteMtime);return(0,i.useEffect)(()=>{let d=!1;async function e(){try{let a=await fetch("/api/file",{cache:"no-store"});if(!a.ok)return null;return await a.json()}catch{return null}}(async()=>{let c=await e();d||(c?.path&&bk.getState().setDocPath(c.path),c?.exists&&c.content?a(c.content,c.mtime,c.path.split("/").pop()):b("idle",c?`No file at ${c.path}`:null))})();let f=new EventSource("/api/watch");return f.addEventListener("hello",a=>{try{let b=JSON.parse(a.data);"number"==typeof b?.mtime&&c(b.mtime)}catch{}}),f.addEventListener("change",async d=>{let f=0;try{f=JSON.parse(d.data)?.mtime??0}catch{}if(f<=(bk.getState().remoteMtime??0))return;let g=await e();g?.exists&&g.content&&(bk.getState().dirty?(b("remote-changed",`Disk changed at ${new Date(g.mtime).toLocaleTimeString()} — local has unsaved edits`),c(g.mtime)):a(g.content,g.mtime,g.path.split("/").pop()))}),f.addEventListener("error",()=>{b("error","Watch stream disconnected")}),()=>{d=!0,f.close()}},[a,b,c]),null}function bJ({url:a}){let b=bk(a=>a.presence);return((0,i.useEffect)(()=>{if(!a)return;let b=!1,c=null,d=null,e=null,f=null;return(async()=>{let g="";try{let a=await fetch("/api/file",{cache:"no-store"});a.ok&&(g=(await a.json())?.path??"")}catch{}b||(g&&bk.getState().setDocPath(g),(c=function(a){let{onFull:b,onPatch:c,onPresence:d,...e}=a,f=function(a){let{url:b,role:c,docId:d,name:e,token:f}=a,g=!1!==a.autoResync,h=aB(b,{auth:{token:f},autoConnect:!1}),i="disconnected",j=0,k="",l=[],m={patch:new Set,full:new Set,ack:new Set,presence:new Set,error:new Set,status:new Set};function n(a,b){for(let c of[...m[a]])c(b)}function o(a){i!==a&&(i=a,n("status",a))}function p(a){h.emit("def:request",{docId:d,sinceSeq:a})}function q(a){"number"==typeof a&&(g&&a>j+1&&p(j),j=Math.max(j,a))}function r(){n("presence",[...l])}function s(){return h.connected?Promise.resolve():new Promise((a,b)=>{o("connecting");let c=()=>{e(),a()},d=a=>{e(),b(a)},e=()=>{h.off("connect",c),h.off("connect_error",d)};h.once("connect",c),h.once("connect_error",d),h.connect()})}async function t(){return await s(),new Promise((a,b)=>{h.emit("bridge:join",{docId:d,role:c,name:e},c=>{if(!c||c.error){let a=c?.error??{code:"join_failed",message:"no join ack"};n("error",a),b(Error(`${a.code}: ${a.message}`));return}k=c.selfId,l=c.presence?[...c.presence]:[],j=c.snapshot?.seq??0,r(),a({selfId:k,snapshot:c.snapshot,presence:[...l]})})})}return h.on("connect",()=>o("connected")),h.on("disconnect",()=>o("disconnected")),h.on("connect_error",a=>{o("error"),n("error",{code:"connect_error",message:a?.message??String(a)})}),h.on("def:patch",a=>{q(a?.seq),a?.origin&&a.origin===k||n("patch",a)}),h.on("def:full",a=>{q(a?.seq),a?.origin&&a.origin===k||n("full",a)}),h.on("def:ack",a=>{n("ack",a)}),h.on("bridge:error",a=>{n("error",{code:a?.code??"error",message:a?.message??""})}),h.on("presence:list",a=>{l=Array.isArray(a)?[...a]:[],r()}),h.on("presence:join",a=>{let b=a1(a);b&&(l=[...l.filter(a=>a.clientId!==b),a],r())}),h.on("presence:leave",a=>{let b=a1(a);b&&(l=l.filter(a=>a.clientId!==b),r())}),h.on("presence:update",a=>{let b=a1(a);if(!b)return;let c=l.findIndex(a=>a.clientId===b);if(-1===c)l=[...l,a];else{let b={...l[c],...a};l=l.map((a,d)=>d===c?b:a)}r()}),{connect:s,join:t,emitPatch:function(a,b,c){h.emit("def:patch",{docId:d,ops:a,origin:k,baseSeq:c,mtime:b})},emitFull:function(a,b){h.emit("def:full",{docId:d,def:a,origin:k,mtime:b})},request:p,updatePresence:function(a){h.emit("presence:update",{docId:d,clientId:k,cursor:a.cursor,selection:a.selection})},on:function(a,b){let c=m[a];return c.add(b),()=>c.delete(b)},disconnect:function(){h.connected&&k&&h.emit("bridge:leave",{docId:d,clientId:k}),h.disconnect(),o("disconnected")},get status(){return i},get lastSeq(){return j},get presence(){return[...l]}}}(e),g=null,h=0,i=[],j=[],k={status:f.status,def:null,seq:0,presence:[],activeStates:[]},l=new Set;function m(){for(let a of(k={status:f.status,def:g,seq:h,presence:i,activeStates:j},[...l]))a()}return f.on("status",()=>m()),f.on("full",a=>{g=a.def,"number"==typeof a.seq&&(h=a.seq),b?.(a),m()}),f.on("patch",a=>{"number"==typeof a.seq&&(h=a.seq);let b=a.ops??[],d=b.filter(a2),e=b.filter(a=>!a2(a));e.length>0&&g&&(g=aG(g,e));for(let a of d)"runtime.enter"===a.op?j.includes(a.state)||(j=[...j,a.state]):"runtime.exit"===a.op&&j.includes(a.state)&&(j=j.filter(b=>b!==a.state));c?.(a),m()}),f.on("presence",a=>{i=a,d?.(a),m()}),{getSnapshot:function(){return k},subscribe:function(a){return l.add(a),()=>{l.delete(a)}},emitPatch:function(a){f.emitPatch(a)},emitFull:function(a){f.emitFull(a)},enter:function(a,b,c){let d={op:"runtime.enter",state:a,...void 0!==b?{from:b}:{},...void 0!==c?{eventId:c}:{}};f.emitPatch([d])},exit:function(a){f.emitPatch([{op:"runtime.exit",state:a}])},connect:function(){f.join().then(a=>{g=a.snapshot.def,h=a.snapshot.seq,i=a.presence,null!==g&&b?.({docId:a.snapshot.docId,def:g,seq:h,mtime:a.snapshot.mtime,origin:"join"}),m()}).catch(()=>{m()})},disconnect:function(){f.disconnect()}}}({url:a,role:"web",docId:g,name:"web-designer",onFull:a=>{bk.getState().applyRemote(JSON.stringify({stateMachine:a.def}),a.mtime??Date.now(),g&&g.split("/").pop()||void 0),f=a.def},onPatch:a=>{bk.getState().applyRemoteOps(a.ops,a.mtime??Date.now(),a.seq),f=bk.getState().definition},onPresence:a=>{bk.getState().setPresence(a)}})).connect(),d=bk.subscribe((a,b)=>{a.definition===b.definition||a._applyingRemote||(e&&clearTimeout(e),e=setTimeout(()=>{var a,b;let d,e;if(!c||"connected"!==c.getSnapshot().status)return;let g=bk.getState().definition;if(null===f){c.emitFull(g),f=g;return}let h=(a=f,b=g,d=a??{settings:{namespace:"",asynchronous:!1},events:[],state:{name:b.state.name,states:[]}},function(a,b,c){let d={},e=!1,f=new Set([...Object.keys(a.settings),...Object.keys(b.settings)]),g=a.settings,h=b.settings;for(let a of f)aJ(g[a],h[a])||void 0===h[a]||(d[a]=h[a],e=!0);e&&c.push({op:"settings.update",patch:d})}(d,b,e=[]),function(a,b,c){let d=a.events,e=b.events,f=Math.min(d.length,e.length);for(let a=0;a<f;a++)!function(a,b,c,d){let e={},f=!1;for(let a of["name","file","feeder","description","timers"])aJ(b[a],c[a])||void 0===c[a]||(e[a]=c[a],f=!0);f&&d.push({op:"eventSource.update",index:a,patch:e});let g=b.events??[],h=c.events??[],i=new Set(h.map(a=>a.id));for(let a of g)i.has(a.id)||d.push({op:"event.remove",id:a.id});let j=g.filter(a=>i.has(a.id)),k=0;for(;k<h.length;){let b=h[k];k<j.length&&j[k].id===b.id?(function(a,b,c){let d={},e=!1;for(let c of["name","description","preAction","postAction"])aJ(a[c],b[c])||void 0===b[c]||(d[c]=b[c],e=!0);e&&c.push({op:"event.update",id:b.id,patch:d})}(j[k],b,d),function(a,b,c,d){let e=Math.min(b.length,c.length);for(let f=0;f<e;f++)if(!aJ(b[f],c[f])){let e={};b[f].name!==c[f].name&&(e.name=c[f].name),b[f].type!==c[f].type&&(e.type=c[f].type),d.push({op:"parameter.update",eventId:a,index:f,patch:e})}for(let b=e;b<c.length;b++)d.push({op:"parameter.add",eventId:a,parameter:c[b],index:b});for(let e=b.length-1;e>=c.length;e--)d.push({op:"parameter.remove",eventId:a,index:e})}(b.id,j[k].parameters??[],b.parameters??[],d)):(d.push({op:"event.add",sourceIndex:a,event:b,index:k}),j.splice(k,0,b)),k++}}(a,d[a],e[a],c);for(let a=d.length;a<e.length;a++)c.push({op:"eventSource.add",source:e[a]});for(let a=d.length-1;a>=e.length;a--)c.push({op:"eventSource.remove",index:a})}(d,b,e),function(a,b,c){let d=aH(a.state),e=aH(b.state),f=new Map(d.map(a=>[a.name,a])),g=new Map(e.map(a=>[a.name,a])),h=aI(a.state),i=aI(b.state),j=[];for(let a of e){if(f.has(a.name))continue;let b=i.get(a.name)??null,{states:d,transitions:e,...g}=a;c.push({op:"state.add",parent:b,state:{...g}}),e&&e.length>0&&j.push({state:a.name,transitions:e})}for(let a of e){if(!f.has(a.name))continue;let b=h.get(a.name)??null,d=i.get(a.name)??null;b!==d&&null!==d&&c.push({op:"state.nest",child:a.name,newParent:d})}for(let a of e){let b=f.get(a.name);if(!b)continue;let d={},e=!1;aJ(b.kind,a.kind)||void 0===a.kind||(d.kind=a.kind,e=!0),aJ(b.description,a.description)||void 0===a.description||(d.description=a.description,e=!0),e&&c.push({op:"state.update",name:a.name,patch:d}),aK(a.name,"onEntry",b.onEntry?.actions??[],a.onEntry?.actions??[],c),aK(a.name,"onExit",b.onExit?.actions??[],a.onExit?.actions??[],c)}for(let a of j)a.transitions.forEach((b,d)=>{c.push({op:"transition.add",state:a.state,transition:b,index:d})});for(let a of e){let b=f.get(a.name);b&&function(a,b,c,d){let e=Math.min(b.length,c.length);for(let f=0;f<e;f++){if(aJ(b[f],c[f]))continue;let e={};for(let a of["event","nextState","condition","description","actions"])aJ(b[f][a],c[f][a])||void 0===c[f][a]||(e[a]=c[f][a]);Object.keys(e).length>0&&d.push({op:"transition.update",state:a,index:f,patch:e})}for(let b=e;b<c.length;b++)d.push({op:"transition.add",state:a,transition:c[b],index:b});for(let e=b.length-1;e>=c.length;e--)d.push({op:"transition.remove",state:a,index:e})}(a.name,b.transitions??[],a.transitions??[],c)}for(let a=d.length-1;a>=0;a--){let b=d[a];if(g.has(b.name))continue;let e=b.transitions??[];for(let a=e.length-1;a>=0;a--)c.push({op:"transition.remove",state:b.name,index:a});c.push({op:"state.remove",name:b.name})}}(d,b,e),e);0!==h.length&&(c.emitPatch(h),f=g)},60))}))})(),()=>{b=!0,e&&clearTimeout(e),d&&d(),c&&c.disconnect()}},[a]),0===b.length)?null:(0,h.jsx)("div",{className:"presence-dock flex gap-1 pointer-events-none",children:b.map(a=>(0,h.jsx)("span",{title:`${a.role}${a.name?` \xb7 ${a.name}`:""}`,className:"text-[10px] leading-none px-2 py-1 rounded-full text-white/95 shadow font-medium",style:{backgroundColor:a.color??function(a){let b=0;for(let c=0;c<a.length;c++)b=Math.imul(b,31)+a.charCodeAt(c)|0;let c=(b%360+360)%360;return`hsl(${c}, 65%, 55%)`}(a.clientId)},children:a.role},a.clientId))})}function bK(){let a=process.env.NEXT_PUBLIC_STATELOOM_BRIDGE_URL??process.env.NEXT_PUBLIC_SMCRAFT_BRIDGE_URL;return"string"==typeof a&&a.length>0?a:void 0}let bL=null;function bM(){let a=bK(),[b,c]=(0,i.useState)(a);return((0,i.useEffect)(()=>{let a=!0;return(bL||(bL=(async()=>{let a=bK()??null;try{let b=await fetch("/api/config",{cache:"no-store"});if(b.ok){let c=await b.json();return{bridgeUrl:c.bridgeUrl||a,projectFile:c.projectFile??null}}}catch{}return{bridgeUrl:a,projectFile:null}})())).then(b=>{a&&b.bridgeUrl&&c(b.bridgeUrl)}),()=>{a=!1}},[]),"string"==typeof b&&b.length>0)?(0,h.jsx)(bJ,{url:b}):(0,h.jsx)(bI,{})}function bN(a){return Number.isFinite(a)?Math.min(1.75,Math.max(.75,a)):1}function bO(a){"u">typeof document&&(document.documentElement.style.fontSize=`${16*bN(a)}px`)}let bP=1,bQ=!1,bR=new Set;function bS(){return bQ||(bQ=!0,bP=1),bP}function bT(){return 1}function bU(a){return bR.add(a),()=>{bR.delete(a)}}function bV(a,b){let c=bN(a);if(bO(c),b,bQ=!0,c!==bP)for(let a of(bP=c,bR))a()}function bW(a,b){return Math.max(1,Math.hypot(b.clientX-a.clientX,b.clientY-a.clientY))}function bX(a,b){for(let c=0;c<a.length;c++)if(a[c].identifier===b)return a[c];return null}function bY(){let a=(0,i.useSyncExternalStore)(bU,bS,bT),b=(0,i.useRef)(null),c=(0,i.useRef)(null),d=(0,i.useRef)(null);(0,i.useEffect)(()=>{bO(a)},[a]);let e=(0,i.useCallback)(a=>{c.current=a,null===d.current&&(d.current=requestAnimationFrame(()=>{d.current=null,null!==c.current&&bV(c.current,!1)}))},[]),f=(0,i.useCallback)(()=>{c.current=null,bV(1,!0)},[]);return((0,i.useEffect)(()=>{let a=()=>{let a=b.current;if(b.current=null,!a?.engaged)return;null!==d.current&&(cancelAnimationFrame(d.current),d.current=null);let e=c.current??bS();c.current=null,bV(bN(e),!0)},f=c=>{if(2!==c.touches.length){b.current&&a();return}let[d,e]=[c.touches[0],c.touches[1]];bn(d.target)||bn(e.target)||(b.current={a:d.identifier,b:e.identifier,startScale:bS(),startDist:bW(d,e),engaged:!1})},g=a=>{let c=b.current;if(!c)return;let d=bX(a.touches,c.a),f=bX(a.touches,c.b);if(!d||!f)return;a.preventDefault();let g=bW(d,f);if(!c.engaged){if(12>Math.abs(g-c.startDist))return;c.engaged=!0,c.startDist=g;return}e(bN(c.startScale*(g/c.startDist)))},h=c=>{let d=b.current;d&&(bX(c.touches,d.a)&&bX(c.touches,d.b)||a())};return document.addEventListener("touchstart",f,{passive:!0,capture:!0}),document.addEventListener("touchmove",g,{passive:!1,capture:!0}),document.addEventListener("touchend",h,{passive:!0,capture:!0}),document.addEventListener("touchcancel",h,{passive:!0,capture:!0}),()=>{document.removeEventListener("touchstart",f,{capture:!0}),document.removeEventListener("touchmove",g,{capture:!0}),document.removeEventListener("touchend",h,{capture:!0}),document.removeEventListener("touchcancel",h,{capture:!0}),null!==d.current&&cancelAnimationFrame(d.current)}},[e]),1===a)?null:(0,h.jsxs)("div",{className:"ui-scale-pill",role:"status","aria-live":"polite",children:[(0,h.jsxs)("span",{children:["UI ",Math.round(100*a),"%"]}),(0,h.jsx)("button",{type:"button",onClick:f,"aria-label":"Reset interface size to 100 percent",children:"Reset"})]})}function bZ(){let[a,b]=(0,i.useState)("properties"),[c,d]=(0,i.useState)(!1),e=bk(a=>a.errors),f=bk(a=>a.contextMenu),g=bk(a=>a.hideContextMenu),j=bk(a=>a.addState),k=bk(a=>a.removeState),l=bk(a=>a.setDrawMode),m=bk(a=>a.setDrawSource),n=[{id:"properties",label:"Properties",icon:"🎛"},{id:"events",label:"Events",icon:"⚡"},{id:"settings",label:"Settings",icon:"⚙"},{id:"validation",label:"Errors",icon:"⚠",badge:e.length||void 0}],o=n.find(b=>b.id===a)?.label??"";return(0,h.jsxs)("div",{className:"app-shell dock-offset flex flex-col overflow-hidden",onClick:()=>f.visible&&g(),children:[(0,h.jsx)(bM,{}),(0,h.jsx)(bY,{}),(0,h.jsx)(bG,{}),(0,h.jsxs)("div",{className:"flex flex-1 min-h-0 overflow-hidden relative",children:[(0,h.jsx)("div",{className:"flex-1 overflow-hidden",children:(0,h.jsx)(bz,{})}),c&&(0,h.jsx)("div",{className:"fixed inset-0 z-20 bg-black/50 md:hidden",onClick:()=>d(!1),"aria-hidden":"true"}),(0,h.jsxs)("aside",{className:`safe-x fixed inset-x-0 bottom-0 z-30 h-[70dvh] flex flex-col overflow-hidden rounded-t-2xl border-t border-gray-800 bg-gray-900 shadow-2xl transition-transform duration-200 ease-out ${c?"translate-y-0":"translate-y-full pointer-events-none"} md:static md:z-auto md:h-auto md:w-80 md:translate-y-0 md:pointer-events-auto md:rounded-none md:border-t-0 md:border-l md:shadow-none md:transition-none`,children:[(0,h.jsxs)("div",{className:"md:hidden",children:[(0,h.jsx)("div",{className:"flex justify-center pt-2 pb-1",children:(0,h.jsx)("span",{className:"h-1 w-10 rounded-full bg-gray-700"})}),(0,h.jsxs)("div",{className:"flex items-center justify-between border-b border-gray-800 px-4 pb-2",children:[(0,h.jsx)("h2",{className:"text-sm font-semibold text-gray-300",children:o}),(0,h.jsx)("button",{onClick:()=>d(!1),className:"-mr-2 px-3 py-2 text-lg text-gray-400","aria-label":"Close panel",children:"✕"})]})]}),(0,h.jsx)("div",{className:"hidden border-b border-gray-800 md:flex",children:n.map(c=>(0,h.jsxs)("button",{onClick:()=>b(c.id),className:`flex-1 text-xs py-2 px-1 text-center transition-colors relative ${a===c.id?"text-blue-400 border-b-2 border-blue-400 bg-gray-800/50":"text-gray-500 hover:text-gray-300"}`,children:[c.label,void 0!==c.badge&&c.badge>0&&(0,h.jsx)("span",{className:"absolute top-1 right-1 bg-red-600 text-white text-[9px] rounded-full px-1 min-w-[14px]",children:c.badge})]},c.id))}),(0,h.jsxs)("div",{className:"touch-targets dock-offset flex-1 overflow-y-auto overscroll-contain",children:["properties"===a&&(0,h.jsx)(bB,{}),"events"===a&&(0,h.jsx)(bD,{}),"settings"===a&&(0,h.jsx)(bE,{}),"validation"===a&&(0,h.jsx)(bF,{})]})]}),(0,h.jsx)(bH,{})]}),(0,h.jsx)("nav",{className:"dock-safe safe-x fixed inset-x-0 bottom-0 z-40 flex border-t border-gray-800 bg-gray-900/95 backdrop-blur-md md:hidden",children:n.map(e=>{let f=c&&a===e.id;return(0,h.jsxs)("button",{onClick:()=>{var c;return c=e.id,void(d(b=>!(b&&a===c)),b(c))},"aria-pressed":f,className:`relative flex h-14 flex-1 flex-col items-center justify-center gap-0.5 text-[11px] transition-colors ${f?"text-blue-400":"text-gray-500"}`,children:[(0,h.jsx)("span",{className:"text-base leading-none",children:e.icon}),(0,h.jsx)("span",{children:e.label}),void 0!==e.badge&&e.badge>0&&(0,h.jsx)("span",{className:"absolute top-1 right-1/2 translate-x-4 rounded-full bg-red-600 px-1 text-[10px] leading-4 text-white min-w-[16px]",children:e.badge}),f&&(0,h.jsx)("span",{className:"absolute inset-x-4 top-0 h-0.5 rounded-full bg-blue-400"})]},e.id)})}),f.visible&&(0,h.jsx)("div",{className:"fixed z-50 bg-gray-900 border border-gray-700 rounded-lg shadow-xl py-1 min-w-[180px] md:min-w-[140px]",style:{left:f.x,top:f.y,maxWidth:"calc(100vw - 1rem)",maxHeight:"calc(100dvh - 1rem)",overflowY:"auto",transform:"translate(0, 0)"},onClick:a=>a.stopPropagation(),children:f.target?.kind==="state"?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)("button",{className:"block w-full text-left text-sm text-gray-300 hover:bg-gray-800 px-4 py-3 md:text-xs md:px-3 md:py-1.5",onClick:()=>{l("transition"),m(f.target.id),g()},children:"↗ Draw transition from here"}),(0,h.jsx)("button",{className:"block w-full text-left text-sm text-red-400 hover:bg-gray-800 px-4 py-3 md:text-xs md:px-3 md:py-1.5",onClick:()=>{f.target?.id&&k(f.target.id),g()},children:"🗑 Delete state"})]}):(0,h.jsx)(h.Fragment,{children:(0,h.jsx)("button",{className:"block w-full text-left text-sm text-gray-300 hover:bg-gray-800 px-4 py-3 md:text-xs md:px-3 md:py-1.5",onClick:()=>{let a=prompt("State name:");a&&j(null,{name:a,kind:"normal"}),g()},children:"+ Add state here"})})})]})}a.s(["default",()=>bZ],95421)}];
|
|
11
|
+
${a}`)}l(!0)};return(0,h.jsxs)("div",{className:"flex flex-col gap-1.5 px-2 py-1.5 bg-gray-900 border-b border-gray-800 md:flex-row md:flex-wrap md:items-center md:px-3",children:[(0,h.jsxs)("div",{className:"toolbar-ident",children:[(0,h.jsx)("input",{ref:A,type:"file",accept:".json,.smdf.json",onChange:a=>{let b=a.target.files?.[0];if(!b)return;let c=new FileReader;c.onload=a=>{e(a.target?.result,b.name)},c.readAsText(b),a.target.value=""},className:"hidden"}),(0,h.jsxs)("span",{className:"text-xs text-gray-400 mr-1 truncate max-w-[50vw] md:max-w-none",children:[b??"untitled.smdf.json",d&&(0,h.jsx)("span",{className:"text-yellow-500 ml-0.5",children:"●"})]}),(0,h.jsx)(bI,{}),"synced"===u&&(0,h.jsx)("span",{className:"text-[10px] text-emerald-500",title:"In sync with disk",children:"⌁ synced"}),"remote-changed"===u&&(0,h.jsx)("span",{className:"text-[10px] text-amber-400",title:v??"",children:"↻ remote changed"}),"error"===u&&(0,h.jsx)("span",{className:"text-[10px] text-red-400",title:v??"",children:"⚠ disk error"}),"idle"===u&&(0,h.jsx)("span",{className:"text-[10px] text-gray-600",title:v??"No file bound",children:"○ no disk"}),(0,h.jsx)("div",{className:"flex-1"})]}),(0,h.jsxs)("div",{className:"toolbar-strip",children:[(0,h.jsx)("button",{onClick:q,disabled:0===s.length,className:"toolbar-btn disabled:opacity-30",title:"Undo (Ctrl+Z)",children:"↩"}),(0,h.jsx)("button",{onClick:r,disabled:0===t.length,className:"toolbar-btn disabled:opacity-30",title:"Redo (Ctrl+Y)",children:"↪"}),(0,h.jsx)("div",{className:"w-px h-4 bg-gray-700"}),(0,h.jsx)("button",{onClick:p,className:"toolbar-btn",title:"Arrange states into layers (auto-layout)",children:"⤢ Arrange"}),(0,h.jsx)("div",{className:"w-px h-4 bg-gray-700"}),(0,h.jsx)("button",{onClick:()=>o("select"===n?"transition":"select"),className:`toolbar-btn ${"transition"===n?"!bg-amber-700 !text-white":""}`,title:"transition"===n?"Exit draw mode (Esc)":"Draw transition mode",children:"transition"===n?"✏️ Drawing":"↗ Draw"}),(0,h.jsx)("div",{className:"w-px h-4 bg-gray-700"}),(0,h.jsx)("button",{onClick:()=>A.current?.click(),className:"toolbar-btn",title:"Open local .smdf.json (browser)",children:"📂"}),(0,h.jsx)("button",{onClick:P,disabled:F,className:"toolbar-btn disabled:opacity-40",title:"Save to disk (STATELOOM_PROJECT_FILE)",children:"💾 Disk"}),(0,h.jsx)("button",{onClick:R,className:"toolbar-btn",title:"Reload from disk",children:"🔄"}),(0,h.jsx)("button",{onClick:()=>{let a=new Blob([f()],{type:"application/json"}),c=URL.createObjectURL(a),d=document.createElement("a");d.href=c,d.download=b??"statemachine.smdf.json",d.click(),URL.revokeObjectURL(c)},className:"toolbar-btn",title:"Download as file",children:"📥"}),(0,h.jsx)("select",{value:H,onChange:a=>{I(a.target.value),O(null),M(null)},className:"bg-gray-800 border border-gray-700 rounded text-xs text-gray-300 px-1 py-0.5",title:"Export format",children:bq.map(a=>(0,h.jsx)("option",{value:a,children:br[a]},a))}),(0,h.jsx)("button",{onClick:Q,disabled:J,className:`toolbar-btn disabled:opacity-40 ${L?"!text-red-400":""}`,title:L??`Export the board as ${br[H]}`,children:J?"…":"🖼 Export"}),N&&!L&&(0,h.jsxs)("span",{className:"text-[10px] text-emerald-500 truncate max-w-[40vw] md:max-w-[16rem]",title:N,children:["⤓ ",N]}),(0,h.jsx)("div",{className:"w-px h-4 bg-gray-700"}),B?(0,h.jsxs)("div",{className:"flex items-center gap-1",children:[(0,h.jsx)("input",{autoFocus:!0,className:"bg-gray-800 border border-gray-700 rounded px-2 py-0.5 text-xs text-gray-200 w-32 md:w-24",placeholder:"State name...",value:D,onChange:a=>E(a.target.value),onKeyDown:a=>{"Enter"===a.key&&S(),"Escape"===a.key&&C(!1)}}),(0,h.jsx)("button",{onClick:S,className:"toolbar-btn-sm",children:"✓"}),(0,h.jsx)("button",{onClick:()=>C(!1),className:"toolbar-btn-sm",children:"✕"})]}):(0,h.jsx)("button",{onClick:()=>C(!0),className:"toolbar-btn",children:"+State"}),(0,h.jsx)("div",{className:"w-px h-4 bg-gray-700"}),(0,h.jsx)("button",{onClick:()=>j(),className:"toolbar-btn",children:"✓ Validate"}),(0,h.jsxs)("select",{value:T,onChange:a=>U(a.target.value),className:"bg-gray-800 border border-gray-700 rounded text-xs text-gray-300 px-1 py-0.5",children:[(0,h.jsx)("option",{value:"python",children:"Python"}),(0,h.jsx)("option",{value:"typescript",children:"TypeScript"})]}),(0,h.jsx)("button",{onClick:W,className:"toolbar-btn",children:"⚡ Generate"}),(0,h.jsx)("button",{onClick:V,className:"toolbar-btn",title:"Generate RISE rispec markdown",children:"📜 RISE"}),(0,h.jsxs)("button",{onClick:()=>l(!k),className:`toolbar-btn ${k?"text-blue-400":""}`,children:["</>"," Code"]})]})]})}function bK(){let a=bk(a=>a.generatedCode),b=bk(a=>a.showCodePreview),c=bk(a=>a.setShowCodePreview);return b?(0,h.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/60 p-2 md:p-0",children:(0,h.jsxs)("div",{className:"bg-gray-900 border border-gray-700 rounded-lg shadow-xl w-full max-h-[85dvh] md:w-[80%] md:max-w-3xl md:max-h-[80dvh] flex flex-col",children:[(0,h.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b border-gray-800",children:[(0,h.jsx)("h3",{className:"text-sm font-semibold text-gray-300",children:"Generated Definition (JSON)"}),(0,h.jsx)("button",{onClick:()=>c(!1),className:"text-gray-500 hover:text-gray-300 text-lg min-h-11 min-w-11 md:min-h-0 md:min-w-0","aria-label":"Close preview",children:"✕"})]}),(0,h.jsx)("pre",{className:"flex-1 overflow-auto overscroll-contain p-4 text-[11px] leading-relaxed text-green-400 font-mono md:text-sm",children:a??"No code generated yet"}),(0,h.jsx)("div",{className:"flex justify-end px-4 py-2 border-t border-gray-800",children:(0,h.jsx)("button",{onClick:()=>{a&&navigator.clipboard.writeText(a)},className:"text-xs bg-gray-700 hover:bg-gray-600 text-gray-300 px-4 py-3 rounded md:px-3 md:py-1",children:"Copy to Clipboard"})})]})}):null}function bL(){let a=bk(a=>a.applyRemote),b=bk(a=>a.setRemoteStatus),c=bk(a=>a.setRemoteMtime),d=(0,bH.useRequestedDoc)();return(0,i.useEffect)(()=>{let e=!1,f=(0,bH.docQuery)(d);async function g(){try{let a=await fetch(`/api/file${f}`,{cache:"no-store"});if(!a.ok)return null;return await a.json()}catch{return null}}(async()=>{let c=await g();e||(c?.path&&bk.getState().setDocPath(c.path),c?.exists&&c.content?a(c.content,c.mtime,c.path.split("/").pop()):b("idle",c?`No file at ${c.path}`:null))})();let h=new EventSource(`/api/watch${f}`);return h.addEventListener("hello",a=>{try{let b=JSON.parse(a.data);"number"==typeof b?.mtime&&c(b.mtime)}catch{}}),h.addEventListener("change",async d=>{let e=0;try{e=JSON.parse(d.data)?.mtime??0}catch{}if(e<=(bk.getState().remoteMtime??0))return;let f=await g();f?.exists&&f.content&&(bk.getState().dirty?(b("remote-changed",`Disk changed at ${new Date(f.mtime).toLocaleTimeString()} — local has unsaved edits`),c(f.mtime)):a(f.content,f.mtime,f.path.split("/").pop()))}),h.addEventListener("error",()=>{b("error","Watch stream disconnected")}),()=>{e=!0,h.close()}},[a,b,c,d]),null}function bM({url:a}){let b=bk(a=>a.presence),c=(0,bH.useRequestedDoc)();return((0,i.useEffect)(()=>{if(!a)return;let b=!1,d=null,e=null,f=null,g=null;return(async()=>{let h="";try{let a=await fetch(`/api/file${(0,bH.docQuery)(c)}`,{cache:"no-store"});a.ok&&(h=(await a.json())?.path??"")}catch{}b||(h&&bk.getState().setDocPath(h),(d=function(a){let{onFull:b,onPatch:c,onPresence:d,...e}=a,f=function(a){let{url:b,role:c,docId:d,name:e,token:f}=a,g=!1!==a.autoResync,h=aB(b,{auth:{token:f},autoConnect:!1}),i="disconnected",j=0,k="",l=[],m={patch:new Set,full:new Set,ack:new Set,presence:new Set,error:new Set,status:new Set};function n(a,b){for(let c of[...m[a]])c(b)}function o(a){i!==a&&(i=a,n("status",a))}function p(a){h.emit("def:request",{docId:d,sinceSeq:a})}function q(a){"number"==typeof a&&(g&&a>j+1&&p(j),j=Math.max(j,a))}function r(){n("presence",[...l])}function s(){return h.connected?Promise.resolve():new Promise((a,b)=>{o("connecting");let c=()=>{e(),a()},d=a=>{e(),b(a)},e=()=>{h.off("connect",c),h.off("connect_error",d)};h.once("connect",c),h.once("connect_error",d),h.connect()})}async function t(){return await s(),new Promise((a,b)=>{h.emit("bridge:join",{docId:d,role:c,name:e},c=>{if(!c||c.error){let a=c?.error??{code:"join_failed",message:"no join ack"};n("error",a),b(Error(`${a.code}: ${a.message}`));return}k=c.selfId,l=c.presence?[...c.presence]:[],j=c.snapshot?.seq??0,r(),a({selfId:k,snapshot:c.snapshot,presence:[...l]})})})}return h.on("connect",()=>o("connected")),h.on("disconnect",()=>o("disconnected")),h.on("connect_error",a=>{o("error"),n("error",{code:"connect_error",message:a?.message??String(a)})}),h.on("def:patch",a=>{q(a?.seq),a?.origin&&a.origin===k||n("patch",a)}),h.on("def:full",a=>{q(a?.seq),a?.origin&&a.origin===k||n("full",a)}),h.on("def:ack",a=>{n("ack",a)}),h.on("bridge:error",a=>{n("error",{code:a?.code??"error",message:a?.message??""})}),h.on("presence:list",a=>{l=Array.isArray(a)?[...a]:[],r()}),h.on("presence:join",a=>{let b=a1(a);b&&(l=[...l.filter(a=>a.clientId!==b),a],r())}),h.on("presence:leave",a=>{let b=a1(a);b&&(l=l.filter(a=>a.clientId!==b),r())}),h.on("presence:update",a=>{let b=a1(a);if(!b)return;let c=l.findIndex(a=>a.clientId===b);if(-1===c)l=[...l,a];else{let b={...l[c],...a};l=l.map((a,d)=>d===c?b:a)}r()}),{connect:s,join:t,emitPatch:function(a,b,c){h.emit("def:patch",{docId:d,ops:a,origin:k,baseSeq:c,mtime:b})},emitFull:function(a,b){h.emit("def:full",{docId:d,def:a,origin:k,mtime:b})},request:p,updatePresence:function(a){h.emit("presence:update",{docId:d,clientId:k,cursor:a.cursor,selection:a.selection})},on:function(a,b){let c=m[a];return c.add(b),()=>c.delete(b)},disconnect:function(){h.connected&&k&&h.emit("bridge:leave",{docId:d,clientId:k}),h.disconnect(),o("disconnected")},get status(){return i},get lastSeq(){return j},get presence(){return[...l]}}}(e),g=null,h=0,i=[],j=[],k={status:f.status,def:null,seq:0,presence:[],activeStates:[]},l=new Set;function m(){for(let a of(k={status:f.status,def:g,seq:h,presence:i,activeStates:j},[...l]))a()}return f.on("status",()=>m()),f.on("full",a=>{g=a.def,"number"==typeof a.seq&&(h=a.seq),b?.(a),m()}),f.on("patch",a=>{"number"==typeof a.seq&&(h=a.seq);let b=a.ops??[],d=b.filter(a2),e=b.filter(a=>!a2(a));e.length>0&&g&&(g=aG(g,e));for(let a of d)"runtime.enter"===a.op?j.includes(a.state)||(j=[...j,a.state]):"runtime.exit"===a.op&&j.includes(a.state)&&(j=j.filter(b=>b!==a.state));c?.(a),m()}),f.on("presence",a=>{i=a,d?.(a),m()}),{getSnapshot:function(){return k},subscribe:function(a){return l.add(a),()=>{l.delete(a)}},emitPatch:function(a){f.emitPatch(a)},emitFull:function(a){f.emitFull(a)},enter:function(a,b,c){let d={op:"runtime.enter",state:a,...void 0!==b?{from:b}:{},...void 0!==c?{eventId:c}:{}};f.emitPatch([d])},exit:function(a){f.emitPatch([{op:"runtime.exit",state:a}])},connect:function(){f.join().then(a=>{g=a.snapshot.def,h=a.snapshot.seq,i=a.presence,null!==g&&b?.({docId:a.snapshot.docId,def:g,seq:h,mtime:a.snapshot.mtime,origin:"join"}),m()}).catch(()=>{m()})},disconnect:function(){f.disconnect()}}}({url:a,role:"web",docId:h,name:"web-designer",onFull:a=>{bk.getState().applyRemote(JSON.stringify({stateMachine:a.def}),a.mtime??Date.now(),h&&h.split("/").pop()||void 0),g=a.def},onPatch:a=>{bk.getState().applyRemoteOps(a.ops,a.mtime??Date.now(),a.seq),g=bk.getState().definition},onPresence:a=>{bk.getState().setPresence(a)}})).connect(),e=bk.subscribe((a,b)=>{a.definition===b.definition||a._applyingRemote||(f&&clearTimeout(f),f=setTimeout(()=>{var a,b;let c,e;if(!d||"connected"!==d.getSnapshot().status)return;let f=bk.getState().definition;if(null===g){d.emitFull(f),g=f;return}let h=(a=g,b=f,c=a??{settings:{namespace:"",asynchronous:!1},events:[],state:{name:b.state.name,states:[]}},function(a,b,c){let d={},e=!1,f=new Set([...Object.keys(a.settings),...Object.keys(b.settings)]),g=a.settings,h=b.settings;for(let a of f)aJ(g[a],h[a])||void 0===h[a]||(d[a]=h[a],e=!0);e&&c.push({op:"settings.update",patch:d})}(c,b,e=[]),function(a,b,c){let d=a.events,e=b.events,f=Math.min(d.length,e.length);for(let a=0;a<f;a++)!function(a,b,c,d){let e={},f=!1;for(let a of["name","file","feeder","description","timers"])aJ(b[a],c[a])||void 0===c[a]||(e[a]=c[a],f=!0);f&&d.push({op:"eventSource.update",index:a,patch:e});let g=b.events??[],h=c.events??[],i=new Set(h.map(a=>a.id));for(let a of g)i.has(a.id)||d.push({op:"event.remove",id:a.id});let j=g.filter(a=>i.has(a.id)),k=0;for(;k<h.length;){let b=h[k];k<j.length&&j[k].id===b.id?(function(a,b,c){let d={},e=!1;for(let c of["name","description","preAction","postAction"])aJ(a[c],b[c])||void 0===b[c]||(d[c]=b[c],e=!0);e&&c.push({op:"event.update",id:b.id,patch:d})}(j[k],b,d),function(a,b,c,d){let e=Math.min(b.length,c.length);for(let f=0;f<e;f++)if(!aJ(b[f],c[f])){let e={};b[f].name!==c[f].name&&(e.name=c[f].name),b[f].type!==c[f].type&&(e.type=c[f].type),d.push({op:"parameter.update",eventId:a,index:f,patch:e})}for(let b=e;b<c.length;b++)d.push({op:"parameter.add",eventId:a,parameter:c[b],index:b});for(let e=b.length-1;e>=c.length;e--)d.push({op:"parameter.remove",eventId:a,index:e})}(b.id,j[k].parameters??[],b.parameters??[],d)):(d.push({op:"event.add",sourceIndex:a,event:b,index:k}),j.splice(k,0,b)),k++}}(a,d[a],e[a],c);for(let a=d.length;a<e.length;a++)c.push({op:"eventSource.add",source:e[a]});for(let a=d.length-1;a>=e.length;a--)c.push({op:"eventSource.remove",index:a})}(c,b,e),function(a,b,c){let d=aH(a.state),e=aH(b.state),f=new Map(d.map(a=>[a.name,a])),g=new Map(e.map(a=>[a.name,a])),h=aI(a.state),i=aI(b.state),j=[];for(let a of e){if(f.has(a.name))continue;let b=i.get(a.name)??null,{states:d,transitions:e,...g}=a;c.push({op:"state.add",parent:b,state:{...g}}),e&&e.length>0&&j.push({state:a.name,transitions:e})}for(let a of e){if(!f.has(a.name))continue;let b=h.get(a.name)??null,d=i.get(a.name)??null;b!==d&&null!==d&&c.push({op:"state.nest",child:a.name,newParent:d})}for(let a of e){let b=f.get(a.name);if(!b)continue;let d={},e=!1;aJ(b.kind,a.kind)||void 0===a.kind||(d.kind=a.kind,e=!0),aJ(b.description,a.description)||void 0===a.description||(d.description=a.description,e=!0),e&&c.push({op:"state.update",name:a.name,patch:d}),aK(a.name,"onEntry",b.onEntry?.actions??[],a.onEntry?.actions??[],c),aK(a.name,"onExit",b.onExit?.actions??[],a.onExit?.actions??[],c)}for(let a of j)a.transitions.forEach((b,d)=>{c.push({op:"transition.add",state:a.state,transition:b,index:d})});for(let a of e){let b=f.get(a.name);b&&function(a,b,c,d){let e=Math.min(b.length,c.length);for(let f=0;f<e;f++){if(aJ(b[f],c[f]))continue;let e={};for(let a of["event","nextState","condition","description","actions"])aJ(b[f][a],c[f][a])||void 0===c[f][a]||(e[a]=c[f][a]);Object.keys(e).length>0&&d.push({op:"transition.update",state:a,index:f,patch:e})}for(let b=e;b<c.length;b++)d.push({op:"transition.add",state:a,transition:c[b],index:b});for(let e=b.length-1;e>=c.length;e--)d.push({op:"transition.remove",state:a,index:e})}(a.name,b.transitions??[],a.transitions??[],c)}for(let a=d.length-1;a>=0;a--){let b=d[a];if(g.has(b.name))continue;let e=b.transitions??[];for(let a=e.length-1;a>=0;a--)c.push({op:"transition.remove",state:b.name,index:a});c.push({op:"state.remove",name:b.name})}}(c,b,e),e);0!==h.length&&(d.emitPatch(h),g=f)},60))}))})(),()=>{b=!0,f&&clearTimeout(f),e&&e(),d&&d.disconnect()}},[a,c]),0===b.length)?null:(0,h.jsx)("div",{className:"presence-dock flex gap-1 pointer-events-none",children:b.map(a=>(0,h.jsx)("span",{title:`${a.role}${a.name?` \xb7 ${a.name}`:""}`,className:"text-[10px] leading-none px-2 py-1 rounded-full text-white/95 shadow font-medium",style:{backgroundColor:a.color??function(a){let b=0;for(let c=0;c<a.length;c++)b=Math.imul(b,31)+a.charCodeAt(c)|0;let c=(b%360+360)%360;return`hsl(${c}, 65%, 55%)`}(a.clientId)},children:a.role},a.clientId))})}function bN(){let a=process.env.NEXT_PUBLIC_STATELOOM_BRIDGE_URL??process.env.NEXT_PUBLIC_SMCRAFT_BRIDGE_URL;return"string"==typeof a&&a.length>0?a:void 0}let bO=null;function bP(){let a=bN(),[b,c]=(0,i.useState)(a);return((0,i.useEffect)(()=>{let a=!0;return(bO||(bO=(async()=>{let a=bN()??null;try{let b=await fetch("/api/config",{cache:"no-store"});if(b.ok){let c=await b.json();return{bridgeUrl:c.bridgeUrl||a,projectFile:c.projectFile??null}}}catch{}return{bridgeUrl:a,projectFile:null}})())).then(b=>{a&&b.bridgeUrl&&c(b.bridgeUrl)}),()=>{a=!1}},[]),"string"==typeof b&&b.length>0)?(0,h.jsx)(bM,{url:b}):(0,h.jsx)(bL,{})}function bQ(a){return Number.isFinite(a)?Math.min(1.75,Math.max(.75,a)):1}function bR(a){"u">typeof document&&(document.documentElement.style.fontSize=`${16*bQ(a)}px`)}let bS=1,bT=!1,bU=new Set;function bV(){return bT||(bT=!0,bS=1),bS}function bW(){return 1}function bX(a){return bU.add(a),()=>{bU.delete(a)}}function bY(a,b){let c=bQ(a);if(bR(c),b,bT=!0,c!==bS)for(let a of(bS=c,bU))a()}function bZ(a,b){return Math.max(1,Math.hypot(b.clientX-a.clientX,b.clientY-a.clientY))}function b$(a,b){for(let c=0;c<a.length;c++)if(a[c].identifier===b)return a[c];return null}function b_(){let a=(0,i.useSyncExternalStore)(bX,bV,bW),b=(0,i.useRef)(null),c=(0,i.useRef)(null),d=(0,i.useRef)(null);(0,i.useEffect)(()=>{bR(a)},[a]);let e=(0,i.useCallback)(a=>{c.current=a,null===d.current&&(d.current=requestAnimationFrame(()=>{d.current=null,null!==c.current&&bY(c.current,!1)}))},[]),f=(0,i.useCallback)(()=>{c.current=null,bY(1,!0)},[]);return((0,i.useEffect)(()=>{let a=()=>{let a=b.current;if(b.current=null,!a?.engaged)return;null!==d.current&&(cancelAnimationFrame(d.current),d.current=null);let e=c.current??bV();c.current=null,bY(bQ(e),!0)},f=c=>{if(2!==c.touches.length){b.current&&a();return}let[d,e]=[c.touches[0],c.touches[1]];bn(d.target)||bn(e.target)||(b.current={a:d.identifier,b:e.identifier,startScale:bV(),startDist:bZ(d,e),engaged:!1})},g=a=>{let c=b.current;if(!c)return;let d=b$(a.touches,c.a),f=b$(a.touches,c.b);if(!d||!f)return;a.preventDefault();let g=bZ(d,f);if(!c.engaged){if(12>Math.abs(g-c.startDist))return;c.engaged=!0,c.startDist=g;return}e(bQ(c.startScale*(g/c.startDist)))},h=c=>{let d=b.current;d&&(b$(c.touches,d.a)&&b$(c.touches,d.b)||a())};return document.addEventListener("touchstart",f,{passive:!0,capture:!0}),document.addEventListener("touchmove",g,{passive:!1,capture:!0}),document.addEventListener("touchend",h,{passive:!0,capture:!0}),document.addEventListener("touchcancel",h,{passive:!0,capture:!0}),()=>{document.removeEventListener("touchstart",f,{capture:!0}),document.removeEventListener("touchmove",g,{capture:!0}),document.removeEventListener("touchend",h,{capture:!0}),document.removeEventListener("touchcancel",h,{capture:!0}),null!==d.current&&cancelAnimationFrame(d.current)}},[e]),1===a)?null:(0,h.jsxs)("div",{className:"ui-scale-pill",role:"status","aria-live":"polite",children:[(0,h.jsxs)("span",{children:["UI ",Math.round(100*a),"%"]}),(0,h.jsx)("button",{type:"button",onClick:f,"aria-label":"Reset interface size to 100 percent",children:"Reset"})]})}function b0(){let[a,b]=(0,i.useState)("properties"),[c,d]=(0,i.useState)(!1),e=bk(a=>a.errors),f=bk(a=>a.contextMenu),g=bk(a=>a.hideContextMenu),j=bk(a=>a.addState),k=bk(a=>a.removeState),l=bk(a=>a.setDrawMode),m=bk(a=>a.setDrawSource),n=[{id:"properties",label:"Properties",icon:"🎛"},{id:"events",label:"Events",icon:"⚡"},{id:"settings",label:"Settings",icon:"⚙"},{id:"validation",label:"Errors",icon:"⚠",badge:e.length||void 0}],o=n.find(b=>b.id===a)?.label??"";return(0,h.jsxs)("div",{className:"app-shell dock-offset flex flex-col overflow-hidden",onClick:()=>f.visible&&g(),children:[(0,h.jsx)(bP,{}),(0,h.jsx)(b_,{}),(0,h.jsx)(bJ,{}),(0,h.jsxs)("div",{className:"flex flex-1 min-h-0 overflow-hidden relative",children:[(0,h.jsx)("div",{className:"flex-1 overflow-hidden",children:(0,h.jsx)(bA,{})}),c&&(0,h.jsx)("div",{className:"fixed inset-0 z-20 bg-black/50 md:hidden",onClick:()=>d(!1),"aria-hidden":"true"}),(0,h.jsxs)("aside",{className:`safe-x fixed inset-x-0 bottom-0 z-30 h-[70dvh] flex flex-col overflow-hidden rounded-t-2xl border-t border-gray-800 bg-gray-900 shadow-2xl transition-transform duration-200 ease-out ${c?"translate-y-0":"translate-y-full pointer-events-none"} md:static md:z-auto md:h-auto md:w-80 md:translate-y-0 md:pointer-events-auto md:rounded-none md:border-t-0 md:border-l md:shadow-none md:transition-none`,children:[(0,h.jsxs)("div",{className:"md:hidden",children:[(0,h.jsx)("div",{className:"flex justify-center pt-2 pb-1",children:(0,h.jsx)("span",{className:"h-1 w-10 rounded-full bg-gray-700"})}),(0,h.jsxs)("div",{className:"flex items-center justify-between border-b border-gray-800 px-4 pb-2",children:[(0,h.jsx)("h2",{className:"text-sm font-semibold text-gray-300",children:o}),(0,h.jsx)("button",{onClick:()=>d(!1),className:"-mr-2 px-3 py-2 text-lg text-gray-400","aria-label":"Close panel",children:"✕"})]})]}),(0,h.jsx)("div",{className:"hidden border-b border-gray-800 md:flex",children:n.map(c=>(0,h.jsxs)("button",{onClick:()=>b(c.id),className:`flex-1 text-xs py-2 px-1 text-center transition-colors relative ${a===c.id?"text-blue-400 border-b-2 border-blue-400 bg-gray-800/50":"text-gray-500 hover:text-gray-300"}`,children:[c.label,void 0!==c.badge&&c.badge>0&&(0,h.jsx)("span",{className:"absolute top-1 right-1 bg-red-600 text-white text-[9px] rounded-full px-1 min-w-[14px]",children:c.badge})]},c.id))}),(0,h.jsxs)("div",{className:"touch-targets dock-offset flex-1 overflow-y-auto overscroll-contain",children:["properties"===a&&(0,h.jsx)(bC,{}),"events"===a&&(0,h.jsx)(bE,{}),"settings"===a&&(0,h.jsx)(bF,{}),"validation"===a&&(0,h.jsx)(bG,{})]})]}),(0,h.jsx)(bK,{})]}),(0,h.jsx)("nav",{className:"dock-safe safe-x fixed inset-x-0 bottom-0 z-40 flex border-t border-gray-800 bg-gray-900/95 backdrop-blur-md md:hidden",children:n.map(e=>{let f=c&&a===e.id;return(0,h.jsxs)("button",{onClick:()=>{var c;return c=e.id,void(d(b=>!(b&&a===c)),b(c))},"aria-pressed":f,className:`relative flex h-14 flex-1 flex-col items-center justify-center gap-0.5 text-[11px] transition-colors ${f?"text-blue-400":"text-gray-500"}`,children:[(0,h.jsx)("span",{className:"text-base leading-none",children:e.icon}),(0,h.jsx)("span",{children:e.label}),void 0!==e.badge&&e.badge>0&&(0,h.jsx)("span",{className:"absolute top-1 right-1/2 translate-x-4 rounded-full bg-red-600 px-1 text-[10px] leading-4 text-white min-w-[16px]",children:e.badge}),f&&(0,h.jsx)("span",{className:"absolute inset-x-4 top-0 h-0.5 rounded-full bg-blue-400"})]},e.id)})}),f.visible&&(0,h.jsx)("div",{className:"fixed z-50 bg-gray-900 border border-gray-700 rounded-lg shadow-xl py-1 min-w-[180px] md:min-w-[140px]",style:{left:f.x,top:f.y,maxWidth:"calc(100vw - 1rem)",maxHeight:"calc(100dvh - 1rem)",overflowY:"auto",transform:"translate(0, 0)"},onClick:a=>a.stopPropagation(),children:f.target?.kind==="state"?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)("button",{className:"block w-full text-left text-sm text-gray-300 hover:bg-gray-800 px-4 py-3 md:text-xs md:px-3 md:py-1.5",onClick:()=>{l("transition"),m(f.target.id),g()},children:"↗ Draw transition from here"}),(0,h.jsx)("button",{className:"block w-full text-left text-sm text-red-400 hover:bg-gray-800 px-4 py-3 md:text-xs md:px-3 md:py-1.5",onClick:()=>{f.target?.id&&k(f.target.id),g()},children:"🗑 Delete state"})]}):(0,h.jsx)(h.Fragment,{children:(0,h.jsx)("button",{className:"block w-full text-left text-sm text-gray-300 hover:bg-gray-800 px-4 py-3 md:text-xs md:px-3 md:py-1.5",onClick:()=>{let a=prompt("State name:");a&&j(null,{name:a,kind:"normal"}),g()},children:"+ Add state here"})})})]})}a.s(["default",()=>b0],95421)}];
|
|
12
12
|
|
|
13
13
|
//# sourceMappingURL=%5Broot-of-the-server%5D__edbb995c._.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
module.exports=[18622,(a,b,c)=>{b.exports=a.x("next/dist/compiled/next-server/app-page-turbo.runtime.prod.js",()=>require("next/dist/compiled/next-server/app-page-turbo.runtime.prod.js"))},56704,(a,b,c)=>{b.exports=a.x("next/dist/server/app-render/work-async-storage.external.js",()=>require("next/dist/server/app-render/work-async-storage.external.js"))},32319,(a,b,c)=>{b.exports=a.x("next/dist/server/app-render/work-unit-async-storage.external.js",()=>require("next/dist/server/app-render/work-unit-async-storage.external.js"))},24725,(a,b,c)=>{b.exports=a.x("next/dist/server/app-render/after-task-async-storage.external.js",()=>require("next/dist/server/app-render/after-task-async-storage.external.js"))},20635,(a,b,c)=>{b.exports=a.x("next/dist/server/app-render/action-async-storage.external.js",()=>require("next/dist/server/app-render/action-async-storage.external.js"))},43285,(a,b,c)=>{b.exports=a.x("next/dist/server/app-render/dynamic-access-async-storage.external.js",()=>require("next/dist/server/app-render/dynamic-access-async-storage.external.js"))},
|
|
1
|
+
module.exports=[18622,(a,b,c)=>{b.exports=a.x("next/dist/compiled/next-server/app-page-turbo.runtime.prod.js",()=>require("next/dist/compiled/next-server/app-page-turbo.runtime.prod.js"))},56704,(a,b,c)=>{b.exports=a.x("next/dist/server/app-render/work-async-storage.external.js",()=>require("next/dist/server/app-render/work-async-storage.external.js"))},32319,(a,b,c)=>{b.exports=a.x("next/dist/server/app-render/work-unit-async-storage.external.js",()=>require("next/dist/server/app-render/work-unit-async-storage.external.js"))},24725,(a,b,c)=>{b.exports=a.x("next/dist/server/app-render/after-task-async-storage.external.js",()=>require("next/dist/server/app-render/after-task-async-storage.external.js"))},20635,(a,b,c)=>{b.exports=a.x("next/dist/server/app-render/action-async-storage.external.js",()=>require("next/dist/server/app-render/action-async-storage.external.js"))},43285,(a,b,c)=>{b.exports=a.x("next/dist/server/app-render/dynamic-access-async-storage.external.js",()=>require("next/dist/server/app-render/dynamic-access-async-storage.external.js"))},56856,(a,b,c)=>{"use strict";b.exports=a.r(40881).vendored["react-ssr"].ReactJsxRuntime},40881,(a,b,c)=>{"use strict";b.exports=a.r(18622)},55132,(a,b,c)=>{"use strict";b.exports=a.r(40881).vendored["react-ssr"].React},21824,(a,b,c)=>{"use strict";Object.defineProperty(c,"__esModule",{value:!0}),Object.defineProperty(c,"HandleISRError",{enumerable:!0,get:function(){return e}});let d=a.r(56704).workAsyncStorage;function e({error:a}){if(d){let b=d.getStore();if(b?.isStaticGeneration)throw a&&console.error(a),a}return null}("function"==typeof c.default||"object"==typeof c.default&&null!==c.default)&&void 0===c.default.__esModule&&(Object.defineProperty(c.default,"__esModule",{value:!0}),Object.assign(c.default,c),b.exports=c.default)},61905,(a,b,c)=>{"use strict";Object.defineProperty(c,"__esModule",{value:!0}),Object.defineProperty(c,"default",{enumerable:!0,get:function(){return h}});let d=a.r(56856),e=a.r(21824),f={fontFamily:'system-ui,"Segoe UI",Roboto,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji"',height:"100vh",textAlign:"center",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},g={fontSize:"14px",fontWeight:400,lineHeight:"28px",margin:"0 8px"},h=function({error:a}){let b=a?.digest;return(0,d.jsxs)("html",{id:"__next_error__",children:[(0,d.jsx)("head",{}),(0,d.jsxs)("body",{children:[(0,d.jsx)(e.HandleISRError,{error:a}),(0,d.jsx)("div",{style:f,children:(0,d.jsxs)("div",{children:[(0,d.jsxs)("h2",{style:g,children:["Application error: a ",b?"server":"client","-side exception has occurred while loading ",window.location.hostname," (see the"," ",b?"server logs":"browser console"," for more information)."]}),b?(0,d.jsx)("p",{style:g,children:`Digest: ${b}`}):null]})})]})]})};("function"==typeof c.default||"object"==typeof c.default&&null!==c.default)&&void 0===c.default.__esModule&&(Object.defineProperty(c.default,"__esModule",{value:!0}),Object.assign(c.default,c),b.exports=c.default)}];
|
|
2
2
|
|
|
3
|
-
//# sourceMappingURL=%5Broot-of-the-server%
|
|
3
|
+
//# sourceMappingURL=%5Broot-of-the-server%5D__f25b51be._.js.map
|
|
@@ -8,10 +8,10 @@ globalThis.__BUILD_MANIFEST = {
|
|
|
8
8
|
],
|
|
9
9
|
"lowPriorityFiles": [],
|
|
10
10
|
"rootMainFiles": [
|
|
11
|
-
"static/chunks/
|
|
11
|
+
"static/chunks/662d1b0ce457c16b.js",
|
|
12
12
|
"static/chunks/5e1795a806bd6c51.js",
|
|
13
13
|
"static/chunks/96818f5620f039a1.js",
|
|
14
|
-
"static/chunks/turbopack-
|
|
14
|
+
"static/chunks/turbopack-34fc7de1568e2a7f.js"
|
|
15
15
|
]
|
|
16
16
|
};
|
|
17
17
|
globalThis.__BUILD_MANIFEST.lowPriorityFiles = [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<!DOCTYPE html><!--
|
|
1
|
+
<!DOCTYPE html><!--vPEqV8SJpTDJWGy_fRuh4--><html lang="en" class="dark"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, viewport-fit=cover, user-scalable=no, interactive-widget=resizes-content"/><link rel="stylesheet" href="/_next/static/chunks/2c679fab817159f2.css" data-precedence="next"/><link rel="preload" as="script" fetchPriority="low" href="/_next/static/chunks/662d1b0ce457c16b.js"/><script src="/_next/static/chunks/5e1795a806bd6c51.js" async=""></script><script src="/_next/static/chunks/96818f5620f039a1.js" async=""></script><script src="/_next/static/chunks/turbopack-34fc7de1568e2a7f.js" async=""></script><script src="/_next/static/chunks/7a768100bec00db1.js" async=""></script><meta name="robots" content="noindex"/><title>404: This page could not be found.</title><meta name="theme-color" content="#030712"/><meta name="color-scheme" content="dark"/><title>SMCraft Designer</title><meta name="description" content="Visual State Machine Designer"/><link rel="icon" href="/favicon.ico?favicon.0b3bf435.ico" sizes="256x256" type="image/x-icon"/><script src="/_next/static/chunks/a6dad97d9634a72d.js" noModule=""></script></head><body class="antialiased"><div hidden=""><!--$--><!--/$--></div><script>try{var s=parseFloat(localStorage.getItem("stateloom.uiScale.v1"));if(s>=0.75&&s<=1.75)document.documentElement.style.fontSize=(16*s)+"px"}catch(e){}</script><div style="font-family:system-ui,"Segoe UI",Roboto,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";height:100vh;text-align:center;display:flex;flex-direction:column;align-items:center;justify-content:center"><div><style>body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}</style><h1 class="next-error-h1" style="display:inline-block;margin:0 20px 0 0;padding:0 23px 0 0;font-size:24px;font-weight:500;vertical-align:top;line-height:49px">404</h1><div style="display:inline-block"><h2 style="font-size:14px;font-weight:400;line-height:49px;margin:0">This page could not be found.</h2></div></div></div><!--$--><!--/$--><script src="/_next/static/chunks/662d1b0ce457c16b.js" id="_R_" async=""></script><script>(self.__next_f=self.__next_f||[]).push([0])</script><script>self.__next_f.push([1,"1:\"$Sreact.fragment\"\n2:I[88287,[\"/_next/static/chunks/7a768100bec00db1.js\"],\"default\"]\n3:I[74895,[\"/_next/static/chunks/7a768100bec00db1.js\"],\"default\"]\n4:I[51858,[\"/_next/static/chunks/7a768100bec00db1.js\"],\"OutletBoundary\"]\n5:\"$Sreact.suspense\"\n7:I[51858,[\"/_next/static/chunks/7a768100bec00db1.js\"],\"ViewportBoundary\"]\n9:I[51858,[\"/_next/static/chunks/7a768100bec00db1.js\"],\"MetadataBoundary\"]\nb:I[52576,[\"/_next/static/chunks/7a768100bec00db1.js\"],\"default\"]\n:HL[\"/_next/static/chunks/2c679fab817159f2.css\",\"style\"]\n"])</script><script>self.__next_f.push([1,"0:{\"P\":null,\"b\":\"vPEqV8SJpTDJWGy_fRuh4\",\"c\":[\"\",\"_not-found\"],\"q\":\"\",\"i\":false,\"f\":[[[\"\",{\"children\":[\"/_not-found\",{\"children\":[\"__PAGE__\",{}]}]},\"$undefined\",\"$undefined\",true],[[\"$\",\"$1\",\"c\",{\"children\":[[[\"$\",\"link\",\"0\",{\"rel\":\"stylesheet\",\"href\":\"/_next/static/chunks/2c679fab817159f2.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\",\"nonce\":\"$undefined\"}]],[\"$\",\"html\",null,{\"lang\":\"en\",\"className\":\"dark\",\"children\":[\"$\",\"body\",null,{\"className\":\"antialiased\",\"children\":[[\"$\",\"script\",null,{\"dangerouslySetInnerHTML\":{\"__html\":\"try{var s=parseFloat(localStorage.getItem(\\\"stateloom.uiScale.v1\\\"));if(s\u003e=0.75\u0026\u0026s\u003c=1.75)document.documentElement.style.fontSize=(16*s)+\\\"px\\\"}catch(e){}\"}}],[\"$\",\"$L2\",null,{\"parallelRouterKey\":\"children\",\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$L3\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":[[[\"$\",\"title\",null,{\"children\":\"404: This page could not be found.\"}],[\"$\",\"div\",null,{\"style\":{\"fontFamily\":\"system-ui,\\\"Segoe UI\\\",Roboto,Helvetica,Arial,sans-serif,\\\"Apple Color Emoji\\\",\\\"Segoe UI Emoji\\\"\",\"height\":\"100vh\",\"textAlign\":\"center\",\"display\":\"flex\",\"flexDirection\":\"column\",\"alignItems\":\"center\",\"justifyContent\":\"center\"},\"children\":[\"$\",\"div\",null,{\"children\":[[\"$\",\"style\",null,{\"dangerouslySetInnerHTML\":{\"__html\":\"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}\"}}],[\"$\",\"h1\",null,{\"className\":\"next-error-h1\",\"style\":{\"display\":\"inline-block\",\"margin\":\"0 20px 0 0\",\"padding\":\"0 23px 0 0\",\"fontSize\":24,\"fontWeight\":500,\"verticalAlign\":\"top\",\"lineHeight\":\"49px\"},\"children\":404}],[\"$\",\"div\",null,{\"style\":{\"display\":\"inline-block\"},\"children\":[\"$\",\"h2\",null,{\"style\":{\"fontSize\":14,\"fontWeight\":400,\"lineHeight\":\"49px\",\"margin\":0},\"children\":\"This page could not be found.\"}]}]]}]}]],[]],\"forbidden\":\"$undefined\",\"unauthorized\":\"$undefined\"}]]}]}]]}],{\"children\":[[\"$\",\"$1\",\"c\",{\"children\":[null,[\"$\",\"$L2\",null,{\"parallelRouterKey\":\"children\",\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$L3\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":\"$undefined\",\"forbidden\":\"$undefined\",\"unauthorized\":\"$undefined\"}]]}],{\"children\":[[\"$\",\"$1\",\"c\",{\"children\":[[[\"$\",\"title\",null,{\"children\":\"404: This page could not be found.\"}],[\"$\",\"div\",null,{\"style\":\"$0:f:0:1:0:props:children:1:props:children:props:children:1:props:notFound:0:1:props:style\",\"children\":[\"$\",\"div\",null,{\"children\":[[\"$\",\"style\",null,{\"dangerouslySetInnerHTML\":{\"__html\":\"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}\"}}],[\"$\",\"h1\",null,{\"className\":\"next-error-h1\",\"style\":\"$0:f:0:1:0:props:children:1:props:children:props:children:1:props:notFound:0:1:props:children:props:children:1:props:style\",\"children\":404}],[\"$\",\"div\",null,{\"style\":\"$0:f:0:1:0:props:children:1:props:children:props:children:1:props:notFound:0:1:props:children:props:children:2:props:style\",\"children\":[\"$\",\"h2\",null,{\"style\":\"$0:f:0:1:0:props:children:1:props:children:props:children:1:props:notFound:0:1:props:children:props:children:2:props:children:props:style\",\"children\":\"This page could not be found.\"}]}]]}]}]],null,[\"$\",\"$L4\",null,{\"children\":[\"$\",\"$5\",null,{\"name\":\"Next.MetadataOutlet\",\"children\":\"$@6\"}]}]]}],{},null,false,false]},null,false,false]},null,false,false],[\"$\",\"$1\",\"h\",{\"children\":[[\"$\",\"meta\",null,{\"name\":\"robots\",\"content\":\"noindex\"}],[\"$\",\"$L7\",null,{\"children\":\"$L8\"}],[\"$\",\"div\",null,{\"hidden\":true,\"children\":[\"$\",\"$L9\",null,{\"children\":[\"$\",\"$5\",null,{\"name\":\"Next.Metadata\",\"children\":\"$La\"}]}]}],null]}],false]],\"m\":\"$undefined\",\"G\":[\"$b\",\"$undefined\"],\"S\":true}\n"])</script><script>self.__next_f.push([1,"8:[[\"$\",\"meta\",\"0\",{\"charSet\":\"utf-8\"}],[\"$\",\"meta\",\"1\",{\"name\":\"viewport\",\"content\":\"width=device-width, initial-scale=1, maximum-scale=1, viewport-fit=cover, user-scalable=no, interactive-widget=resizes-content\"}],[\"$\",\"meta\",\"2\",{\"name\":\"theme-color\",\"content\":\"#030712\"}],[\"$\",\"meta\",\"3\",{\"name\":\"color-scheme\",\"content\":\"dark\"}]]\n"])</script><script>self.__next_f.push([1,"c:I[49310,[\"/_next/static/chunks/7a768100bec00db1.js\"],\"IconMark\"]\n6:null\na:[[\"$\",\"title\",\"0\",{\"children\":\"SMCraft Designer\"}],[\"$\",\"meta\",\"1\",{\"name\":\"description\",\"content\":\"Visual State Machine Designer\"}],[\"$\",\"link\",\"2\",{\"rel\":\"icon\",\"href\":\"/favicon.ico?favicon.0b3bf435.ico\",\"sizes\":\"256x256\",\"type\":\"image/x-icon\"}],[\"$\",\"$Lc\",\"3\",{}]]\n"])</script></body></html>
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
<!DOCTYPE html><!--
|
|
2
|
-
@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}</style><h1 class="next-error-h1" style="display:inline-block;margin:0 20px 0 0;padding-right:23px;font-size:24px;font-weight:500;vertical-align:top">500</h1><div style="display:inline-block"><h2 style="font-size:14px;font-weight:400;line-height:28px">Internal Server Error.</h2></div></div></div><!--$--><!--/$--><script src="/_next/static/chunks/
|
|
1
|
+
<!DOCTYPE html><!--vPEqV8SJpTDJWGy_fRuh4--><html id="__next_error__"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="preload" as="script" fetchPriority="low" href="/_next/static/chunks/662d1b0ce457c16b.js"/><script src="/_next/static/chunks/5e1795a806bd6c51.js" async=""></script><script src="/_next/static/chunks/96818f5620f039a1.js" async=""></script><script src="/_next/static/chunks/turbopack-34fc7de1568e2a7f.js" async=""></script><script src="/_next/static/chunks/7a768100bec00db1.js" async=""></script><title>500: Internal Server Error.</title><link rel="icon" href="/favicon.ico?favicon.0b3bf435.ico" sizes="256x256" type="image/x-icon"/><script src="/_next/static/chunks/a6dad97d9634a72d.js" noModule=""></script></head><body><div hidden=""><!--$--><!--/$--></div><div style="font-family:system-ui,"Segoe UI",Roboto,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";height:100vh;text-align:center;display:flex;flex-direction:column;align-items:center;justify-content:center"><div style="line-height:48px"><style>body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}
|
|
2
|
+
@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}</style><h1 class="next-error-h1" style="display:inline-block;margin:0 20px 0 0;padding-right:23px;font-size:24px;font-weight:500;vertical-align:top">500</h1><div style="display:inline-block"><h2 style="font-size:14px;font-weight:400;line-height:28px">Internal Server Error.</h2></div></div></div><!--$--><!--/$--><script src="/_next/static/chunks/662d1b0ce457c16b.js" id="_R_" async=""></script><script>(self.__next_f=self.__next_f||[]).push([0])</script><script>self.__next_f.push([1,"1:\"$Sreact.fragment\"\n2:I[88287,[\"/_next/static/chunks/7a768100bec00db1.js\"],\"default\"]\n3:I[74895,[\"/_next/static/chunks/7a768100bec00db1.js\"],\"default\"]\n4:I[51858,[\"/_next/static/chunks/7a768100bec00db1.js\"],\"OutletBoundary\"]\n5:\"$Sreact.suspense\"\n7:I[51858,[\"/_next/static/chunks/7a768100bec00db1.js\"],\"ViewportBoundary\"]\n9:I[51858,[\"/_next/static/chunks/7a768100bec00db1.js\"],\"MetadataBoundary\"]\nb:I[52576,[\"/_next/static/chunks/7a768100bec00db1.js\"],\"default\"]\n"])</script><script>self.__next_f.push([1,"0:{\"P\":null,\"b\":\"vPEqV8SJpTDJWGy_fRuh4\",\"c\":[\"\",\"_global-error\"],\"q\":\"\",\"i\":false,\"f\":[[[\"\",{\"children\":[\"__PAGE__\",{}]}],[[\"$\",\"$1\",\"c\",{\"children\":[null,[\"$\",\"$L2\",null,{\"parallelRouterKey\":\"children\",\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$L3\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":\"$undefined\",\"forbidden\":\"$undefined\",\"unauthorized\":\"$undefined\"}]]}],{\"children\":[[\"$\",\"$1\",\"c\",{\"children\":[[\"$\",\"html\",null,{\"id\":\"__next_error__\",\"children\":[[\"$\",\"head\",null,{\"children\":[\"$\",\"title\",null,{\"children\":\"500: Internal Server Error.\"}]}],[\"$\",\"body\",null,{\"children\":[\"$\",\"div\",null,{\"style\":{\"fontFamily\":\"system-ui,\\\"Segoe UI\\\",Roboto,Helvetica,Arial,sans-serif,\\\"Apple Color Emoji\\\",\\\"Segoe UI Emoji\\\"\",\"height\":\"100vh\",\"textAlign\":\"center\",\"display\":\"flex\",\"flexDirection\":\"column\",\"alignItems\":\"center\",\"justifyContent\":\"center\"},\"children\":[\"$\",\"div\",null,{\"style\":{\"lineHeight\":\"48px\"},\"children\":[[\"$\",\"style\",null,{\"dangerouslySetInnerHTML\":{\"__html\":\"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}\\n@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}\"}}],[\"$\",\"h1\",null,{\"className\":\"next-error-h1\",\"style\":{\"display\":\"inline-block\",\"margin\":\"0 20px 0 0\",\"paddingRight\":23,\"fontSize\":24,\"fontWeight\":500,\"verticalAlign\":\"top\"},\"children\":\"500\"}],[\"$\",\"div\",null,{\"style\":{\"display\":\"inline-block\"},\"children\":[\"$\",\"h2\",null,{\"style\":{\"fontSize\":14,\"fontWeight\":400,\"lineHeight\":\"28px\"},\"children\":\"Internal Server Error.\"}]}]]}]}]}]]}],null,[\"$\",\"$L4\",null,{\"children\":[\"$\",\"$5\",null,{\"name\":\"Next.MetadataOutlet\",\"children\":\"$@6\"}]}]]}],{},null,false,false]},null,false,false],[\"$\",\"$1\",\"h\",{\"children\":[null,[\"$\",\"$L7\",null,{\"children\":\"$L8\"}],[\"$\",\"div\",null,{\"hidden\":true,\"children\":[\"$\",\"$L9\",null,{\"children\":[\"$\",\"$5\",null,{\"name\":\"Next.Metadata\",\"children\":\"$La\"}]}]}],null]}],false]],\"m\":\"$undefined\",\"G\":[\"$b\",\"$undefined\"],\"S\":true}\n"])</script><script>self.__next_f.push([1,"8:[[\"$\",\"meta\",\"0\",{\"charSet\":\"utf-8\"}],[\"$\",\"meta\",\"1\",{\"name\":\"viewport\",\"content\":\"width=device-width, initial-scale=1\"}]]\n"])</script><script>self.__next_f.push([1,"c:I[49310,[\"/_next/static/chunks/7a768100bec00db1.js\"],\"IconMark\"]\n6:null\na:[[\"$\",\"link\",\"0\",{\"rel\":\"icon\",\"href\":\"/favicon.ico?favicon.0b3bf435.ico\",\"sizes\":\"256x256\",\"type\":\"image/x-icon\"}],[\"$\",\"$Lc\",\"1\",{}]]\n"])</script></body></html>
|