pixelclaw 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -2
- package/dist/LICENSE +21 -0
- package/dist/THIRD_PARTY_LICENSES.txt +545 -0
- package/dist/pixelclaw.js +712 -0
- package/dist/skill/SKILL.md +281 -0
- package/dist/skill/commands.md +840 -0
- package/dist/skill/manifest.md +64 -0
- package/dist/ui/assets/index-B6jqjzS4.js +53 -0
- package/dist/ui/assets/index-C0sgn8Z3.css +1 -0
- package/dist/ui/index.html +14 -0
- package/package.json +50 -4
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
(function(){const a=document.createElement("link").relList;if(a&&a.supports&&a.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))l(i);new MutationObserver(i=>{for(const r of i)if(r.type==="childList")for(const f of r.addedNodes)f.tagName==="LINK"&&f.rel==="modulepreload"&&l(f)}).observe(document,{childList:!0,subtree:!0});function s(i){const r={};return i.integrity&&(r.integrity=i.integrity),i.referrerPolicy&&(r.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?r.credentials="include":i.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function l(i){if(i.ep)return;i.ep=!0;const r=s(i);fetch(i.href,r)}})();var Kf={exports:{}},Uo={};var Ag;function t$(){if(Ag)return Uo;Ag=1;var t=Symbol.for("react.transitional.element"),a=Symbol.for("react.fragment");function s(l,i,r){var f=null;if(r!==void 0&&(f=""+r),i.key!==void 0&&(f=""+i.key),"key"in i){r={};for(var u in i)u!=="key"&&(r[u]=i[u])}else r=i;return i=r.ref,{$$typeof:t,type:l,key:f,ref:i!==void 0?i:null,props:r}}return Uo.Fragment=a,Uo.jsx=s,Uo.jsxs=s,Uo}var qg;function n$(){return qg||(qg=1,Kf.exports=t$()),Kf.exports}var k=n$(),Jf={exports:{}},Ee={};var Rg;function a$(){if(Rg)return Ee;Rg=1;var t=Symbol.for("react.transitional.element"),a=Symbol.for("react.portal"),s=Symbol.for("react.fragment"),l=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),r=Symbol.for("react.consumer"),f=Symbol.for("react.context"),u=Symbol.for("react.forward_ref"),h=Symbol.for("react.suspense"),d=Symbol.for("react.memo"),p=Symbol.for("react.lazy"),y=Symbol.for("react.activity"),w=Symbol.for("react.view_transition"),x=Symbol.iterator;function b(U){return U===null||typeof U!="object"?null:(U=x&&U[x]||U["@@iterator"],typeof U=="function"?U:null)}var v={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},$=Object.assign,_={};function j(U,V,P){this.props=U,this.context=V,this.refs=_,this.updater=P||v}j.prototype.isReactComponent={},j.prototype.setState=function(U,V){if(typeof U!="object"&&typeof U!="function"&&U!=null)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,U,V,"setState")},j.prototype.forceUpdate=function(U){this.updater.enqueueForceUpdate(this,U,"forceUpdate")};function N(){}N.prototype=j.prototype;function M(U,V,P){this.props=U,this.context=V,this.refs=_,this.updater=P||v}var A=M.prototype=new N;A.constructor=M,$(A,j.prototype),A.isPureReactComponent=!0;var z=Array.isArray;function E(){}var R={H:null,A:null,T:null,S:null},B=Object.prototype.hasOwnProperty;function K(U,V,P){var ie=P.ref;return{$$typeof:t,type:U,key:V,ref:ie!==void 0?ie:null,props:P}}function J(U,V){return K(U.type,V,U.props)}function T(U){return typeof U=="object"&&U!==null&&U.$$typeof===t}function D(U){var V={"=":"=0",":":"=2"};return"$"+U.replace(/[=:]/g,function(P){return V[P]})}var L=/\/+/g;function Y(U,V){return typeof U=="object"&&U!==null&&U.key!=null?D(""+U.key):V.toString(36)}function O(U){switch(U.status){case"fulfilled":return U.value;case"rejected":throw U.reason;default:switch(typeof U.status=="string"?U.then(E,E):(U.status="pending",U.then(function(V){U.status==="pending"&&(U.status="fulfilled",U.value=V)},function(V){U.status==="pending"&&(U.status="rejected",U.reason=V)})),U.status){case"fulfilled":return U.value;case"rejected":throw U.reason}}throw U}function H(U,V,P,ie,ye){var F=typeof U;(F==="undefined"||F==="boolean")&&(U=null);var pe=!1;if(U===null)pe=!0;else switch(F){case"bigint":case"string":case"number":pe=!0;break;case"object":switch(U.$$typeof){case t:case a:pe=!0;break;case p:return pe=U._init,H(pe(U._payload),V,P,ie,ye)}}if(pe)return ye=ye(U),pe=ie===""?"."+Y(U,0):ie,z(ye)?(P="",pe!=null&&(P=pe.replace(L,"$&/")+"/"),H(ye,V,P,"",function(Re){return Re})):ye!=null&&(T(ye)&&(ye=J(ye,P+(ye.key==null||U&&U.key===ye.key?"":(""+ye.key).replace(L,"$&/")+"/")+pe)),V.push(ye)),1;pe=0;var fe=ie===""?".":ie+":";if(z(U))for(var ge=0;ge<U.length;ge++)ie=U[ge],F=fe+Y(ie,ge),pe+=H(ie,V,P,F,ye);else if(ge=b(U),typeof ge=="function")for(U=ge.call(U),ge=0;!(ie=U.next()).done;)ie=ie.value,F=fe+Y(ie,ge++),pe+=H(ie,V,P,F,ye);else if(F==="object"){if(typeof U.then=="function")return H(O(U),V,P,ie,ye);throw V=String(U),Error("Objects are not valid as a React child (found: "+(V==="[object Object]"?"object with keys {"+Object.keys(U).join(", ")+"}":V)+"). If you meant to render a collection of children, use an array instead.")}return pe}function G(U,V,P){if(U==null)return U;var ie=[],ye=0;return H(U,ie,"","",function(F){return V.call(P,F,ye++)}),ie}function Z(U){if(U._status===-1){var V=U._result,P=V();P.then(function(ie){(U._status===0||U._status===-1)&&(U._status=1,U._result=ie,P.status===void 0&&(P.status="fulfilled",P.value=ie))},function(ie){(U._status===0||U._status===-1)&&(U._status=2,U._result=ie,P.status===void 0&&(P.status="rejected",P.reason=ie))}),U._status===-1&&(U._status=0,U._result=P)}if(U._status===1)return U._result.default;throw U._result}var W=typeof reportError=="function"?reportError:function(U){if(typeof window=="object"&&typeof window.ErrorEvent=="function"){var V=new window.ErrorEvent("error",{bubbles:!0,cancelable:!0,message:typeof U=="object"&&U!==null&&typeof U.message=="string"?String(U.message):String(U),error:U});if(!window.dispatchEvent(V))return}else if(typeof process=="object"&&typeof process.emit=="function"){process.emit("uncaughtException",U);return}console.error(U)};function se(U){var V=R.T,P={};P.types=V!==null?V.types:null,R.T=P;try{var ie=U(),ye=R.S;ye!==null&&ye(P,ie),typeof ie=="object"&&ie!==null&&typeof ie.then=="function"&&ie.then(E,W)}catch(F){W(F)}finally{V!==null&&P.types!==null&&(V.types=P.types),R.T=V}}function ue(U){var V=R.T;if(V!==null){var P=V.types;P===null?V.types=[U]:P.indexOf(U)===-1&&P.push(U)}else se(ue.bind(null,U))}var te={map:G,forEach:function(U,V,P){G(U,function(){V.apply(this,arguments)},P)},count:function(U){var V=0;return G(U,function(){V++}),V},toArray:function(U){return G(U,function(V){return V})||[]},only:function(U){if(!T(U))throw Error("React.Children.only expected to receive a single React element child.");return U}};return Ee.Activity=y,Ee.Children=te,Ee.Component=j,Ee.Fragment=s,Ee.Profiler=i,Ee.PureComponent=M,Ee.StrictMode=l,Ee.Suspense=h,Ee.ViewTransition=w,Ee.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=R,Ee.__COMPILER_RUNTIME={__proto__:null,c:function(U){return R.H.useMemoCache(U)}},Ee.addTransitionType=ue,Ee.cache=function(U){return function(){return U.apply(null,arguments)}},Ee.cacheSignal=function(){return null},Ee.cloneElement=function(U,V,P){if(U==null)throw Error("The argument must be a React element, but you passed "+U+".");var ie=$({},U.props),ye=U.key;if(V!=null)for(F in V.key!==void 0&&(ye=""+V.key),V)!B.call(V,F)||F==="key"||F==="__self"||F==="__source"||F==="ref"&&V.ref===void 0||(ie[F]=V[F]);var F=arguments.length-2;if(F===1)ie.children=P;else if(1<F){for(var pe=Array(F),fe=0;fe<F;fe++)pe[fe]=arguments[fe+2];ie.children=pe}return K(U.type,ye,ie)},Ee.createContext=function(U){return U={$$typeof:f,_currentValue:U,_currentValue2:U,_threadCount:0,Provider:null,Consumer:null},U.Provider=U,U.Consumer={$$typeof:r,_context:U},U},Ee.createElement=function(U,V,P){var ie,ye={},F=null;if(V!=null)for(ie in V.key!==void 0&&(F=""+V.key),V)B.call(V,ie)&&ie!=="key"&&ie!=="__self"&&ie!=="__source"&&(ye[ie]=V[ie]);var pe=arguments.length-2;if(pe===1)ye.children=P;else if(1<pe){for(var fe=Array(pe),ge=0;ge<pe;ge++)fe[ge]=arguments[ge+2];ye.children=fe}if(U&&U.defaultProps)for(ie in pe=U.defaultProps,pe)ye[ie]===void 0&&(ye[ie]=pe[ie]);return K(U,F,ye)},Ee.createRef=function(){return{current:null}},Ee.forwardRef=function(U){return{$$typeof:u,render:U}},Ee.isValidElement=T,Ee.lazy=function(U){return{$$typeof:p,_payload:{_status:-1,_result:U},_init:Z}},Ee.memo=function(U,V){return{$$typeof:d,type:U,compare:V===void 0?null:V}},Ee.startTransition=se,Ee.unstable_useCacheRefresh=function(){return R.H.useCacheRefresh()},Ee.use=function(U){return R.H.use(U)},Ee.useActionState=function(U,V,P){return R.H.useActionState(U,V,P)},Ee.useCallback=function(U,V){return R.H.useCallback(U,V)},Ee.useContext=function(U){return R.H.useContext(U)},Ee.useDebugValue=function(){},Ee.useDeferredValue=function(U,V){return R.H.useDeferredValue(U,V)},Ee.useEffect=function(U,V){return R.H.useEffect(U,V)},Ee.useEffectEvent=function(U){return R.H.useEffectEvent(U)},Ee.useId=function(){return R.H.useId()},Ee.useImperativeHandle=function(U,V,P){return R.H.useImperativeHandle(U,V,P)},Ee.useInsertionEffect=function(U,V){return R.H.useInsertionEffect(U,V)},Ee.useLayoutEffect=function(U,V){return R.H.useLayoutEffect(U,V)},Ee.useMemo=function(U,V){return R.H.useMemo(U,V)},Ee.useOptimistic=function(U,V){return R.H.useOptimistic(U,V)},Ee.useReducer=function(U,V,P){return R.H.useReducer(U,V,P)},Ee.useRef=function(U){return R.H.useRef(U)},Ee.useState=function(U){return R.H.useState(U)},Ee.useSyncExternalStore=function(U,V,P){return R.H.useSyncExternalStore(U,V,P)},Ee.useTransition=function(){return R.H.useTransition()},Ee.version="19.3.1",Ee}var Dg;function Th(){return Dg||(Dg=1,Jf.exports=a$()),Jf.exports}var he=Th(),Wf={exports:{}},Ho={},If={exports:{}},Ff={};var Ug;function l$(){return Ug||(Ug=1,(function(t){function a(O,H){var G=O.length;O.push(H);e:for(;0<G;){var Z=G-1>>>1,W=O[Z];if(0<i(W,H))O[Z]=H,O[G]=W,G=Z;else break e}}function s(O){return O.length===0?null:O[0]}function l(O){if(O.length===0)return null;var H=O[0],G=O.pop();if(G!==H){O[0]=G;e:for(var Z=0,W=O.length,se=W>>>1;Z<se;){var ue=2*(Z+1)-1,te=O[ue],U=ue+1,V=O[U];if(0>i(te,G))U<W&&0>i(V,te)?(O[Z]=V,O[U]=G,Z=U):(O[Z]=te,O[ue]=G,Z=ue);else if(U<W&&0>i(V,G))O[Z]=V,O[U]=G,Z=U;else break e}}return H}function i(O,H){var G=O.sortIndex-H.sortIndex;return G!==0?G:O.id-H.id}if(t.unstable_now=void 0,typeof performance=="object"&&typeof performance.now=="function"){var r=performance;t.unstable_now=function(){return r.now()}}else{var f=Date,u=f.now();t.unstable_now=function(){return f.now()-u}}var h=[],d=[],p=1,y=null,w=3,x=!1,b=!1,v=!1,$=!1,_=typeof setTimeout=="function"?setTimeout:null,j=typeof clearTimeout=="function"?clearTimeout:null,N=typeof setImmediate<"u"?setImmediate:null;function M(O){for(var H=s(d);H!==null;){if(H.callback===null)l(d);else if(H.startTime<=O)l(d),H.sortIndex=H.expirationTime,a(h,H);else break;H=s(d)}}function A(O){if(v=!1,M(O),!b)if(s(h)!==null)b=!0,z||(z=!0,T());else{var H=s(d);H!==null&&Y(A,H.startTime-O)}}var z=!1,E=-1,R=5,B=-1;function K(){return $?!0:!(t.unstable_now()-B<R)}function J(){if($=!1,z){var O=t.unstable_now();B=O;var H=!0;try{e:{b=!1,v&&(v=!1,j(E),E=-1),x=!0;var G=w;try{t:{for(M(O),y=s(h);y!==null&&!(y.expirationTime>O&&K());){var Z=y.callback;if(typeof Z=="function"){y.callback=null,w=y.priorityLevel;var W=Z(y.expirationTime<=O);if(O=t.unstable_now(),typeof W=="function"){y.callback=W,M(O),H=!0;break t}y===s(h)&&l(h),M(O)}else l(h);y=s(h)}if(y!==null)H=!0;else{var se=s(d);se!==null&&Y(A,se.startTime-O),H=!1}}break e}finally{y=null,w=G,x=!1}H=void 0}}finally{H?T():z=!1}}}var T;if(typeof N=="function")T=function(){N(J)};else if(typeof MessageChannel<"u"){var D=new MessageChannel,L=D.port2;D.port1.onmessage=J,T=function(){L.postMessage(null)}}else T=function(){_(J,0)};function Y(O,H){E=_(function(){O(t.unstable_now())},H)}t.unstable_IdlePriority=5,t.unstable_ImmediatePriority=1,t.unstable_LowPriority=4,t.unstable_NormalPriority=3,t.unstable_Profiling=null,t.unstable_UserBlockingPriority=2,t.unstable_cancelCallback=function(O){O.callback=null},t.unstable_forceFrameRate=function(O){0>O||125<O?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):R=0<O?Math.floor(1e3/O):5},t.unstable_getCurrentPriorityLevel=function(){return w},t.unstable_next=function(O){switch(w){case 1:case 2:case 3:var H=3;break;default:H=w}var G=w;w=H;try{return O()}finally{w=G}},t.unstable_requestPaint=function(){$=!0},t.unstable_runWithPriority=function(O,H){switch(O){case 1:case 2:case 3:case 4:case 5:break;default:O=3}var G=w;w=O;try{return H()}finally{w=G}},t.unstable_scheduleCallback=function(O,H,G){var Z=t.unstable_now();switch(typeof G=="object"&&G!==null?(G=G.delay,G=typeof G=="number"&&0<G?Z+G:Z):G=Z,O){case 1:var W=-1;break;case 2:W=250;break;case 5:W=1073741823;break;case 4:W=1e4;break;default:W=5e3}return W=G+W,O={id:p++,callback:H,priorityLevel:O,startTime:G,expirationTime:W,sortIndex:-1},G>Z?(O.sortIndex=G,a(d,O),s(h)===null&&O===s(d)&&(v?(j(E),E=-1):v=!0,Y(A,G-Z))):(O.sortIndex=W,a(h,O),b||x||(b=!0,z||(z=!0,T()))),O},t.unstable_shouldYield=K,t.unstable_wrapCallback=function(O){var H=w;return function(){var G=w;w=H;try{return O.apply(this,arguments)}finally{w=G}}}})(Ff)),Ff}var Hg;function s$(){return Hg||(Hg=1,If.exports=l$()),If.exports}var Pf={exports:{}},Rt={};var Lg;function o$(){if(Lg)return Rt;Lg=1;var t=Th();function a(p){var y="https://react.dev/errors/"+p;if(1<arguments.length){y+="?args[]="+encodeURIComponent(arguments[1]);for(var w=2;w<arguments.length;w++)y+="&args[]="+encodeURIComponent(arguments[w])}return"Minified React error #"+p+"; visit "+y+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}function s(){}var l={d:{f:s,r:function(){throw Error(a(522))},D:s,C:s,L:s,m:s,X:s,S:s,M:s},p:0,findDOMNode:null},i=Symbol.for("react.portal"),r=Symbol.for("react.recoverable"),f=Symbol.for("react.optimistic_key");function u(p,y,w){var x=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:i,key:x==null?null:x===f?f:""+x,children:p,containerInfo:y,implementation:w}}var h=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function d(p,y){if(p==="font")return"";if(typeof y=="string")return y==="use-credentials"?y:""}return Rt.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=l,Rt.browser=function(p){return{$$typeof:r,_reason:p}},Rt.createPortal=function(p,y){var w=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!y||y.nodeType!==1&&y.nodeType!==9&&y.nodeType!==11)throw Error(a(299));return u(p,y,null,w)},Rt.flushSync=function(p){var y=h.T,w=l.p;try{if(h.T=null,l.p=2,p)return p()}finally{h.T=y,l.p=w,l.d.f()}},Rt.preconnect=function(p,y){typeof p=="string"&&(y?(y=y.crossOrigin,y=typeof y=="string"?y==="use-credentials"?y:"":void 0):y=null,l.d.C(p,y))},Rt.prefetchDNS=function(p){typeof p=="string"&&l.d.D(p)},Rt.preinit=function(p,y){if(typeof p=="string"&&y&&typeof y.as=="string"){var w=y.as,x=d(w,y.crossOrigin),b=typeof y.integrity=="string"?y.integrity:void 0,v=typeof y.fetchPriority=="string"?y.fetchPriority:void 0;w==="style"?l.d.S(p,typeof y.precedence=="string"?y.precedence:void 0,{crossOrigin:x,integrity:b,fetchPriority:v}):w==="script"&&l.d.X(p,{crossOrigin:x,integrity:b,fetchPriority:v,nonce:typeof y.nonce=="string"?y.nonce:void 0})}},Rt.preinitModule=function(p,y){if(typeof p=="string")if(typeof y=="object"&&y!==null){if(y.as==null||y.as==="script"){var w=d(y.as,y.crossOrigin);l.d.M(p,{crossOrigin:w,integrity:typeof y.integrity=="string"?y.integrity:void 0,nonce:typeof y.nonce=="string"?y.nonce:void 0,fetchPriority:typeof y.fetchPriority=="string"?y.fetchPriority:void 0})}}else y==null&&l.d.M(p)},Rt.preload=function(p,y){if(typeof p=="string"&&typeof y=="object"&&y!==null&&typeof y.as=="string"){var w=y.as,x=d(w,y.crossOrigin);l.d.L(p,w,{crossOrigin:x,integrity:typeof y.integrity=="string"?y.integrity:void 0,nonce:typeof y.nonce=="string"?y.nonce:void 0,type:typeof y.type=="string"?y.type:void 0,fetchPriority:typeof y.fetchPriority=="string"?y.fetchPriority:void 0,referrerPolicy:typeof y.referrerPolicy=="string"?y.referrerPolicy:void 0,imageSrcSet:typeof y.imageSrcSet=="string"?y.imageSrcSet:void 0,imageSizes:typeof y.imageSizes=="string"?y.imageSizes:void 0,media:typeof y.media=="string"?y.media:void 0})}},Rt.preloadModule=function(p,y){if(typeof p=="string")if(y){var w=d(y.as,y.crossOrigin);l.d.m(p,{as:typeof y.as=="string"&&y.as!=="script"?y.as:void 0,crossOrigin:w,integrity:typeof y.integrity=="string"?y.integrity:void 0,nonce:typeof y.nonce=="string"?y.nonce:void 0,fetchPriority:typeof y.fetchPriority=="string"?y.fetchPriority:void 0})}else l.d.m(p)},Rt.requestFormReset=function(p){l.d.r(p)},Rt.unstable_batchedUpdates=function(p,y){return p(y)},Rt.useFormState=function(p,y,w){return h.H.useFormState(p,y,w)},Rt.useFormStatus=function(){return h.H.useHostTransitionStatus()},Rt.version="19.3.1",Rt}var Bg;function i$(){if(Bg)return Pf.exports;Bg=1;function t(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(t)}catch(a){console.error(a)}}return t(),Pf.exports=o$(),Pf.exports}var Yg;function r$(){if(Yg)return Ho;Yg=1;var t=s$(),a=Th(),s=i$();function l(e){var n="https://react.dev/errors/"+e;if(1<arguments.length){n+="?args[]="+encodeURIComponent(arguments[1]);for(var o=2;o<arguments.length;o++)n+="&args[]="+encodeURIComponent(arguments[o])}return"Minified React error #"+e+"; visit "+n+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}function i(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function r(e){for(var n=e,o=n;o&&!o.alternate;)n=o,(n.flags&4098)!==0&&(e=n.return),o=n.return;for(;n.return;)n=n.return;return n.tag===3?e:null}function f(e){if(e.tag===13){var n=e.memoizedState;if(n===null&&(e=e.alternate,e!==null&&(n=e.memoizedState)),n!==null)return n.dehydrated}return null}function u(e){if(e.tag===31){var n=e.memoizedState;if(n===null&&(e=e.alternate,e!==null&&(n=e.memoizedState)),n!==null)return n.dehydrated}return null}function h(e){if(r(e)!==e)throw Error(l(188))}function d(e){var n=e.alternate;if(!n){if(n=r(e),n===null)throw Error(l(188));return n!==e?null:e}for(var o=e,c=n;;){var m=o.return;if(m===null)break;var g=m.alternate;if(g===null){if(c=m.return,c!==null){o=c;continue}break}if(m.child===g.child){for(g=m.child;g;){if(g===o)return h(m),e;if(g===c)return h(m),n;g=g.sibling}throw Error(l(188))}if(o.return!==c.return)o=m,c=g;else{for(var S=!1,q=m.child;q;){if(q===o){S=!0,o=m,c=g;break}if(q===c){S=!0,c=m,o=g;break}q=q.sibling}if(!S){for(q=g.child;q;){if(q===o){S=!0,o=g,c=m;break}if(q===c){S=!0,c=g,o=m;break}q=q.sibling}if(!S)throw Error(l(189))}}if(o.alternate!==c)throw Error(l(190))}if(o.tag!==3)throw Error(l(188));return o.stateNode.current===o?e:n}function p(e){var n=e.tag;if(n===5||n===26||n===27||n===6)return e;for(e=e.child;e!==null;){if(n=p(e),n!==null)return n;e=e.sibling}return null}function y(e,n,o,c,m,g){for(;e!==null;){if((e.tag===5||e.tag===27||e.tag===6)&&o(e,c,m,g)||(e.tag!==22||e.memoizedState===null)&&(n||e.tag!==5&&e.tag!==27)&&y(e.child,n,o,c,m,g))return!0;e=e.sibling}return!1}function w(e){for(e=e.return;e!==null;){if(e.tag===3||e.tag===5||e.tag===27)return e;e=e.return}return null}function x(e){var n=!1;for(e=e.return;e!==null&&(e.tag===4&&(n=!0),!(e.tag===3||e.tag===5||e.tag===27));)e=e.return;return n}function b(e){var n=[null,null],o=w(e);return o===null||v(n,e,o.child,{foundSelf:!1}),n}function v(e,n,o,c){for(;o!==null;){if(o===n)c.foundSelf=!0;else if(o.tag===5||o.tag===27||o.tag===6){if(c.foundSelf)return e[1]=o,!0;e[0]=o}else if((o.tag!==22||o.memoizedState===null)&&v(e,n,o.child,c))return!0;o=o.sibling}return!1}function $(e){switch(e.tag){case 5:case 27:case 6:return e.stateNode;case 3:return e.stateNode.containerInfo;default:throw Error(l(559))}}var _=null,j=null;function N(e,n,o){return e===o?!0:e===n?(_=e,!0):!1}function M(e,n,o){return e===o?(j=e,!1):e===n?(j!==null&&(_=e),!0):!1}function A(e){if(e===null)return null;do e=e===null?null:e.return;while(e&&e.tag!==5&&e.tag!==27&&e.tag!==3);return e||null}function z(e,n,o){for(var c=0,m=e;m;m=o(m))c++;m=0;for(var g=n;g;g=o(g))m++;for(;0<c-m;)e=o(e),c--;for(;0<m-c;)n=o(n),m--;for(;c--;){if(e===n||n!==null&&e===n.alternate)return e;e=o(e),n=o(n)}return null}var E=Object.assign,R=Symbol.for("react.element"),B=Symbol.for("react.transitional.element"),K=Symbol.for("react.portal"),J=Symbol.for("react.fragment"),T=Symbol.for("react.strict_mode"),D=Symbol.for("react.profiler"),L=Symbol.for("react.consumer"),Y=Symbol.for("react.context"),O=Symbol.for("react.forward_ref"),H=Symbol.for("react.suspense"),G=Symbol.for("react.suspense_list"),Z=Symbol.for("react.memo"),W=Symbol.for("react.lazy"),se=Symbol.for("react.activity"),ue=Symbol.for("react.legacy_hidden"),te=Symbol.for("react.memo_cache_sentinel"),U=Symbol.for("react.view_transition"),V=Symbol.for("react.recoverable"),P=Symbol.iterator;function ie(e){return e===null||typeof e!="object"?null:(e=P&&e[P]||e["@@iterator"],typeof e=="function"?e:null)}var ye=Symbol.for("react.client.reference");function F(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===ye?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case J:return"Fragment";case D:return"Profiler";case T:return"StrictMode";case H:return"Suspense";case G:return"SuspenseList";case se:return"Activity";case U:return"ViewTransition"}if(typeof e=="object")switch(e.$$typeof){case K:return"Portal";case Y:return e.displayName||"Context";case L:return(e._context.displayName||"Context")+".Consumer";case O:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case Z:return n=e.displayName||null,n!==null?n:F(e.type)||"Memo";case W:n=e._payload,e=e._init;try{return F(e(n))}catch{}}return null}var pe=Array.isArray,fe=a.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,ge=s.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,Re={pending:!1,data:null,method:null,action:null},rt=[],Se=-1;function be(e){return{current:e}}function $e(e){0>Se||(e.current=rt[Se],rt[Se]=null,Se--)}function Me(e,n){Se++,rt[Se]=e.current,e.current=n}var Ge=be(null),mt=be(null),ct=be(null),X=be(null);function we(e,n){switch(Me(ct,n),Me(mt,e),Me(Ge,null),n.nodeType){case 9:case 11:e=(e=n.documentElement)&&(e=e.namespaceURI)?Gy(e):0;break;default:if(e=n.tagName,n=n.namespaceURI)n=Gy(n),e=Xy(n,e);else switch(e){case"svg":e=1;break;case"math":e=2;break;default:e=0}}$e(Ge),Me(Ge,e)}function Te(){$e(Ge),$e(mt),$e(ct)}function Ve(e){var n=e.memoizedState;n!==null&&(js._currentValue=n.memoizedState,Me(X,e)),n=Ge.current;var o=Xy(n,e.type);n!==o&&(Me(mt,e),Me(Ge,o))}function De(e){mt.current===e&&($e(Ge),$e(mt)),X.current===e&&($e(X),js._currentValue=Re)}var zt,Qt;function Ht(e){if(zt===void 0)try{throw Error()}catch(o){var n=o.stack.trim().match(/\n( *(at )?)/);zt=n&&n[1]||"",Qt=-1<o.stack.indexOf(`
|
|
2
|
+
at`)?" (<anonymous>)":-1<o.stack.indexOf("@")?"@unknown:0:0":""}return`
|
|
3
|
+
`+zt+e+Qt}var Pn=!1;function En(e,n){if(!e||Pn)return"";Pn=!0;var o=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var c={DetermineComponentFrameRoot:function(){try{if(n){var me=function(){throw Error()};if(Object.defineProperty(me.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(me,[])}catch(xe){var ee=xe}Reflect.construct(e,[],me)}else{try{me.call()}catch(xe){ee=xe}me=!1;try{var re=Object.getOwnPropertyDescriptor(e.prototype,"props");Object.defineProperty(e.prototype,"props",{configurable:!0,set:function(){throw Error()}}),me=!0,new e}finally{me&&(re!==void 0?Object.defineProperty(e.prototype,"props",re):delete e.prototype.props)}}}else{try{throw Error()}catch(xe){ee=xe}(me=e())&&typeof me.catch=="function"&&me.catch(function(){})}}catch(xe){if(xe&&ee&&typeof xe.stack=="string")return[xe.stack,ee.stack]}return[null,null]}};c.DetermineComponentFrameRoot.displayName="DetermineComponentFrameRoot";var m=Object.getOwnPropertyDescriptor(c.DetermineComponentFrameRoot,"name");m&&m.configurable&&Object.defineProperty(c.DetermineComponentFrameRoot,"name",{value:"DetermineComponentFrameRoot"});var g=c.DetermineComponentFrameRoot(),S=g[0],q=g[1];if(S&&q){var Q=S.split(`
|
|
4
|
+
`),le=q.split(`
|
|
5
|
+
`);for(m=c=0;c<Q.length&&!Q[c].includes("DetermineComponentFrameRoot");)c++;for(;m<le.length&&!le[m].includes("DetermineComponentFrameRoot");)m++;if(c===Q.length||m===le.length)for(c=Q.length-1,m=le.length-1;1<=c&&0<=m&&Q[c]!==le[m];)m--;for(;1<=c&&0<=m;c--,m--)if(Q[c]!==le[m]){if(c!==1||m!==1)do if(c--,m--,0>m||Q[c]!==le[m]){var ce=`
|
|
6
|
+
`+Q[c].replace(" at new "," at ");return e.displayName&&ce.includes("<anonymous>")&&(ce=ce.replace("<anonymous>",e.displayName)),ce}while(1<=c&&0<=m);break}}}finally{Pn=!1,Error.prepareStackTrace=o}return(o=e?e.displayName||e.name:"")?Ht(o):""}function ui(e,n){switch(e.tag){case 26:case 27:case 5:return Ht(e.type);case 16:return Ht("Lazy");case 13:return e.child!==n&&n!==null?Ht("Suspense Fallback"):Ht("Suspense");case 19:return Ht("SuspenseList");case 0:case 15:return En(e.type,!1);case 11:return En(e.type.render,!1);case 1:return En(e.type,!0);case 31:return Ht("Activity");case 30:return Ht("ViewTransition");default:return""}}function Gs(e){try{var n="",o=null;do n+=ui(e,o),o=e,e=e.return;while(e);return n}catch(c){return`
|
|
7
|
+
Error generating stack: `+c.message+`
|
|
8
|
+
`+c.stack}}var gc=Object.prototype.hasOwnProperty,wc=t.unstable_scheduleCallback,vc=t.unstable_cancelCallback,o1=t.unstable_shouldYield,i1=t.unstable_requestPaint,ln=t.unstable_now,r1=t.unstable_getCurrentPriorityLevel,hd=t.unstable_ImmediatePriority,dd=t.unstable_UserBlockingPriority,fi=t.unstable_NormalPriority,c1=t.unstable_LowPriority,md=t.unstable_IdlePriority,u1=t.log,f1=t.unstable_setDisableYieldValue,Xs=null,sn=null;function ba(e){if(typeof u1=="function"&&f1(e),sn&&typeof sn.setStrictMode=="function")try{sn.setStrictMode(Xs,e)}catch{}}var on=Math.clz32?Math.clz32:m1,h1=Math.log,d1=Math.LN2;function m1(e){return e>>>=0,e===0?32:31-(h1(e)/d1|0)|0}var hi=256,di=262144,mi=4194304;function ol(e){var n=e&42;if(n!==0)return n;switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:return 64;case 128:return 128;case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:return e&-e;case 262144:case 524288:case 1048576:case 2097152:return e&3932160;case 4194304:case 8388608:case 16777216:case 33554432:return e&62914560;case 67108864:return 67108864;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 0;default:return e}}function pi(e,n,o){var c=e.pendingLanes;if(c===0)return 0;var m=0,g=e.suspendedLanes,S=e.pingedLanes;e=e.warmLanes;var q=c&134217727;return q!==0?(c=q&~g,c!==0?m=ol(c):(S&=q,S!==0?m=ol(S):o||(o=q&~e,o!==0&&(m=ol(o))))):(q=c&~g,q!==0?m=ol(q):S!==0?m=ol(S):o||(o=c&~e,o!==0&&(m=ol(o)))),m===0?0:n!==0&&n!==m&&(n&g)===0&&(g=m&-m,o=n&-n,g>=o||g===32&&(o&4194048)!==0)?n:m}function Zs(e,n){return(e.pendingLanes&~(e.suspendedLanes&~e.pingedLanes)&n)===0}function pd(e,n){(n&8)!==0&&(n|=n&32);var o=e.entangledLanes;if(o!==0)for(e=e.entanglements,o&=n;0<o;){var c=31-on(o),m=1<<c;n|=e[c],o&=~m}return n}function p1(e,n){switch(e){case 1:case 2:case 4:case 8:case 64:return n+250;case 16:case 32:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return n+5e3;case 4194304:case 8388608:case 16777216:case 33554432:return-1;case 67108864:case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function yd(){var e=mi;return mi<<=1,(mi&62914560)===0&&(mi=4194304),e}function xc(e){for(var n=[],o=0;31>o;o++)n.push(e);return n}function Qs(e,n){e.pendingLanes|=n,n!==268435456&&(e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0)}function y1(e,n,o,c,m,g){var S=e.pendingLanes;e.pendingLanes=o,e.suspendedLanes=0,e.pingedLanes=0,e.warmLanes=0,e.expiredLanes&=o,e.entangledLanes&=o,e.errorRecoveryDisabledLanes&=o,e.shellSuspendCounter=0;var q=e.entanglements,Q=e.expirationTimes,le=e.hiddenUpdates;for(o=S&~o;0<o;){var ce=31-on(o),me=1<<ce;q[ce]=0,Q[ce]=-1;var ee=le[ce];if(ee!==null)for(le[ce]=null,ce=0;ce<ee.length;ce++){var re=ee[ce];re!==null&&(re.lane&=-536870913)}o&=~me}c!==0&&gd(e,c,0),g!==0&&m===0&&e.tag!==0&&(e.suspendedLanes|=g&~(S&~n))}function gd(e,n,o){e.pendingLanes|=n,e.suspendedLanes&=~n;var c=31-on(n);e.entangledLanes|=n,e.entanglements[c]=e.entanglements[c]|1073741824|o&261930}function wd(e,n){var o=e.entangledLanes|=n;for(e=e.entanglements;o;){var c=31-on(o),m=1<<c;m&n|e[c]&n&&(e[c]|=n),o&=~m}}function vd(e,n){var o=n&-n;return o=(o&42)!==0?1:bc(o),(o&(e.suspendedLanes|n))!==0?0:o}function bc(e){switch(e){case 2:e=1;break;case 8:e=4;break;case 32:e=16;break;case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:e=128;break;case 268435456:e=134217728;break;default:e=0}return e}function $c(e){return e&=-e,2<e?8<e?(e&134217727)!==0?32:268435456:8:2}function xd(){var e=ge.p;return e!==0?e:(e=window.event,e===void 0?32:Ng(e.type))}function bd(e,n){var o=ge.p;try{return ge.p=e,n()}finally{ge.p=o}}var ea=Math.random().toString(36).slice(2),Ct="__reactFiber$"+ea,Vt="__reactProps$"+ea,Hl="__reactContainer$"+ea,$d="__reactEvents$"+ea,g1="__reactListeners$"+ea,w1="__reactHandles$"+ea,kd="__reactResources$"+ea,Vs="__reactMarker$"+ea,yi="__reactLoad$"+ea;function gi(e){delete e[Ct],delete e[Vt],delete e[g1],delete e[w1]}function il(e){var n;if(n=e[Ct])return n;for(var o=e.parentNode;o;){if(n=o[Hl]||o[Ct]){if(o=n.alternate,n.child!==null||o!==null&&o.child!==null)for(e=ig(e);e!==null;){if(o=e[Ct])return o;e=ig(e)}return n}e=o,o=e.parentNode}return null}function Ll(e){if(e=e[Ct]||e[Hl]){var n=e.tag;if(n===5||n===6||n===13||n===31||n===26||n===27||n===3)return e}return null}function Ks(e){var n=e.tag;if(n===5||n===26||n===27||n===6)return e.stateNode;throw Error(l(33))}function Bl(e){var n=e[kd];return n||(n=e[kd]={hoistableStyles:new Map,hoistableScripts:new Map}),n}function kt(e){e[Vs]=!0}function _d(e){e[yi]=void 0}var jd=new Set,Sd={};function rl(e,n){Yl(e,n),Yl(e+"Capture",n)}function Yl(e,n){for(Sd[e]=n,e=0;e<n.length;e++)jd.add(n[e])}var v1=RegExp("^[:A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD][:A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040]*$"),Nd={},Md={};function x1(e){return gc.call(Md,e)?!0:gc.call(Nd,e)?!1:v1.test(e)?Md[e]=!0:(Nd[e]=!0,!1)}var Ke=!1;function zd(){var e=Ke;return Ke=!1,e}function wi(e,n,o){if(x1(n))if(o===null)e.removeAttribute(n);else{switch(typeof o){case"undefined":case"function":case"symbol":e.removeAttribute(n);return;case"boolean":var c=n.toLowerCase().slice(0,5);if(c!=="data-"&&c!=="aria-"){e.removeAttribute(n);return}}e.setAttribute(n,o)}}function vi(e,n,o){if(o===null)e.removeAttribute(n);else{switch(typeof o){case"undefined":case"function":case"symbol":case"boolean":e.removeAttribute(n);return}e.setAttribute(n,o)}}function ta(e,n,o,c){if(c===null)e.removeAttribute(o);else{switch(typeof c){case"undefined":case"function":case"symbol":case"boolean":e.removeAttribute(o);return}e.setAttributeNS(n,o,c)}}function rn(e){switch(typeof e){case"bigint":case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function Cd(e){var n=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(n==="checkbox"||n==="radio")}function b1(e,n,o){var c=Object.getOwnPropertyDescriptor(e.constructor.prototype,n);if(!e.hasOwnProperty(n)&&typeof c<"u"&&typeof c.get=="function"&&typeof c.set=="function"){var m=c.get,g=c.set;return Object.defineProperty(e,n,{configurable:!0,get:function(){return m.call(this)},set:function(S){o=""+S,g.call(this,S)}}),Object.defineProperty(e,n,{enumerable:c.enumerable}),{getValue:function(){return o},setValue:function(S){o=""+S},stopTracking:function(){e._valueTracker=null,delete e[n]}}}}function kc(e){if(!e._valueTracker){var n=Cd(e)?"checked":"value";e._valueTracker=b1(e,n,""+e[n])}}function Ed(e){if(!e)return!1;var n=e._valueTracker;if(!n)return!0;var o=n.getValue(),c="";return e&&(c=Cd(e)?e.checked?"true":"false":e.value),e=c,e!==o?(n.setValue(e),!0):!1}var $1=/[\n"\\]/g;function xn(e){return e.replace($1,function(n){return"\\"+n.charCodeAt(0).toString(16)+" "})}function _c(e,n,o,c,m,g,S,q){e.name="",S!=null&&typeof S!="function"&&typeof S!="symbol"&&typeof S!="boolean"?e.type=S:e.removeAttribute("type"),n!=null?S==="number"?(n===0&&e.value===""||e.value!=n)&&(e.value=""+rn(n)):e.value!==""+rn(n)&&(e.value=""+rn(n)):S!=="submit"&&S!=="reset"||e.removeAttribute("value"),n!=null?S==="number"&&e.value==n?jc(e,rn(e.value)):jc(e,rn(n)):o!=null?jc(e,rn(o)):c!=null&&e.removeAttribute("value"),m==null&&g!=null&&(e.defaultChecked=!!g),m!=null&&(e.checked=m&&typeof m!="function"&&typeof m!="symbol"),q!=null&&typeof q!="function"&&typeof q!="symbol"&&typeof q!="boolean"?e.name=""+rn(q):e.removeAttribute("name")}function Td(e,n,o,c,m,g,S,q){if(g!=null&&typeof g!="function"&&typeof g!="symbol"&&typeof g!="boolean"&&(e.type=g),n!=null||o!=null){if(!(g!=="submit"&&g!=="reset"||n!=null)){kc(e);return}o=o!=null?""+rn(o):"",n=n!=null?""+rn(n):o,q||n===e.value||(e.value=n),e.defaultValue=n}c=c??m,c=typeof c!="function"&&typeof c!="symbol"&&!!c,e.checked=q?e.checked:!!c,e.defaultChecked=!!c,S!=null&&typeof S!="function"&&typeof S!="symbol"&&typeof S!="boolean"&&(e.name=S),kc(e)}function jc(e,n){e.defaultValue!==""+n&&(e.defaultValue=""+n)}function Gl(e,n,o,c){if(e=e.options,n){n={};for(var m=0;m<o.length;m++)n["$"+o[m]]=!0;for(o=0;o<e.length;o++)m=n.hasOwnProperty("$"+e[o].value),e[o].selected!==m&&(e[o].selected=m),m&&c&&(e[o].defaultSelected=!0)}else{for(o=""+rn(o),n=null,m=0;m<e.length;m++){if(e[m].value===o){e[m].selected=!0,c&&(e[m].defaultSelected=!0);return}n!==null||e[m].disabled||(n=e[m])}n!==null&&(n.selected=!0)}}function Od(e,n,o){if(n!=null&&(n=""+rn(n),n!==e.value&&(e.value=n),o==null)){e.defaultValue!==n&&(e.defaultValue=n);return}e.defaultValue=o!=null?""+rn(o):""}function Ad(e,n,o,c){if(n==null){if(c!=null){if(o!=null)throw Error(l(92));if(pe(c)){if(1<c.length)throw Error(l(93));c=c[0]}o=c}o==null&&(o=""),n=o}o=rn(n),e.defaultValue=o,c=e.textContent,c===o&&c!==""&&c!==null&&(e.value=c),kc(e)}function Xl(e,n){if(n){var o=e.firstChild;if(o&&o===e.lastChild&&o.nodeType===3){o.nodeValue=n;return}}e.textContent=n}var k1=new Set("animationIterationCount aspectRatio borderImageOutset borderImageSlice borderImageWidth boxFlex boxFlexGroup boxOrdinalGroup columnCount columns flex flexGrow flexPositive flexShrink flexNegative flexOrder gridArea gridRow gridRowEnd gridRowSpan gridRowStart gridColumn gridColumnEnd gridColumnSpan gridColumnStart fontWeight lineClamp lineHeight opacity order orphans scale tabSize widows zIndex zoom fillOpacity floodOpacity stopOpacity strokeDasharray strokeDashoffset strokeMiterlimit strokeOpacity strokeWidth MozAnimationIterationCount MozBoxFlex MozBoxFlexGroup MozLineClamp msAnimationIterationCount msFlex msZoom msFlexGrow msFlexNegative msFlexOrder msFlexPositive msFlexShrink msGridColumn msGridColumnSpan msGridRow msGridRowSpan WebkitAnimationIterationCount WebkitBoxFlex WebKitBoxFlexGroup WebkitBoxOrdinalGroup WebkitColumnCount WebkitColumns WebkitFlex WebkitFlexGrow WebkitFlexPositive WebkitFlexShrink WebkitLineClamp".split(" "));function qd(e,n,o){var c=n.indexOf("--")===0;o==null||typeof o=="boolean"||o===""?c?e.setProperty(n,""):n==="float"?e.cssFloat="":e[n]="":c?e.setProperty(n,o):typeof o!="number"||o===0||k1.has(n)?n==="float"?e.cssFloat=o:e[n]=(""+o).trim():e[n]=o+"px"}function Rd(e,n,o){if(n!=null&&typeof n!="object")throw Error(l(62));if(e=e.style,o!=null){for(var c in o)!o.hasOwnProperty(c)||n!=null&&n.hasOwnProperty(c)||(c.indexOf("--")===0?e.setProperty(c,""):c==="float"?e.cssFloat="":e[c]="",Ke=!0);for(var m in n)c=n[m],n.hasOwnProperty(m)&&o[m]!==c&&(qd(e,m,c),Ke=!0)}else for(var g in n)n.hasOwnProperty(g)&&qd(e,g,n[g])}function Sc(e){if(e.indexOf("-")===-1)return!1;switch(e){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var _1=new Map([["acceptCharset","accept-charset"],["htmlFor","for"],["httpEquiv","http-equiv"],["crossOrigin","crossorigin"],["accentHeight","accent-height"],["alignmentBaseline","alignment-baseline"],["arabicForm","arabic-form"],["baselineShift","baseline-shift"],["capHeight","cap-height"],["clipPath","clip-path"],["clipRule","clip-rule"],["colorInterpolation","color-interpolation"],["colorInterpolationFilters","color-interpolation-filters"],["colorProfile","color-profile"],["colorRendering","color-rendering"],["dominantBaseline","dominant-baseline"],["enableBackground","enable-background"],["fillOpacity","fill-opacity"],["fillRule","fill-rule"],["floodColor","flood-color"],["floodOpacity","flood-opacity"],["fontFamily","font-family"],["fontSize","font-size"],["fontSizeAdjust","font-size-adjust"],["fontStretch","font-stretch"],["fontStyle","font-style"],["fontVariant","font-variant"],["fontWeight","font-weight"],["glyphName","glyph-name"],["glyphOrientationHorizontal","glyph-orientation-horizontal"],["glyphOrientationVertical","glyph-orientation-vertical"],["horizAdvX","horiz-adv-x"],["horizOriginX","horiz-origin-x"],["imageRendering","image-rendering"],["letterSpacing","letter-spacing"],["lightingColor","lighting-color"],["markerEnd","marker-end"],["markerMid","marker-mid"],["markerStart","marker-start"],["maskType","mask-type"],["overlinePosition","overline-position"],["overlineThickness","overline-thickness"],["paintOrder","paint-order"],["panose-1","panose-1"],["pointerEvents","pointer-events"],["renderingIntent","rendering-intent"],["shapeRendering","shape-rendering"],["stopColor","stop-color"],["stopOpacity","stop-opacity"],["strikethroughPosition","strikethrough-position"],["strikethroughThickness","strikethrough-thickness"],["strokeDasharray","stroke-dasharray"],["strokeDashoffset","stroke-dashoffset"],["strokeLinecap","stroke-linecap"],["strokeLinejoin","stroke-linejoin"],["strokeMiterlimit","stroke-miterlimit"],["strokeOpacity","stroke-opacity"],["strokeWidth","stroke-width"],["textAnchor","text-anchor"],["textDecoration","text-decoration"],["textRendering","text-rendering"],["transformOrigin","transform-origin"],["underlinePosition","underline-position"],["underlineThickness","underline-thickness"],["unicodeBidi","unicode-bidi"],["unicodeRange","unicode-range"],["unitsPerEm","units-per-em"],["vAlphabetic","v-alphabetic"],["vHanging","v-hanging"],["vIdeographic","v-ideographic"],["vMathematical","v-mathematical"],["vectorEffect","vector-effect"],["vertAdvY","vert-adv-y"],["vertOriginX","vert-origin-x"],["vertOriginY","vert-origin-y"],["wordSpacing","word-spacing"],["writingMode","writing-mode"],["xmlnsXlink","xmlns:xlink"],["xHeight","x-height"]]),j1=/^[\u0000-\u001F ]*j[\r\n\t]*a[\r\n\t]*v[\r\n\t]*a[\r\n\t]*s[\r\n\t]*c[\r\n\t]*r[\r\n\t]*i[\r\n\t]*p[\r\n\t]*t[\r\n\t]*:/i;function xi(e){return j1.test(""+e)?"javascript:throw new Error('React has blocked a javascript: URL as a security precaution.')":e}function Ln(){}var Nc=null;function Mc(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Zl=null,Ql=null;function Dd(e){var n=Ll(e);if(n&&(e=n.stateNode)){var o=e[Vt]||null;e:switch(e=n.stateNode,n.type){case"input":if(_c(e,o.value,o.defaultValue,o.defaultValue,o.checked,o.defaultChecked,o.type,o.name),n=o.name,o.type==="radio"&&n!=null){for(o=e;o.parentNode;)o=o.parentNode;for(o=o.querySelectorAll('input[name="'+xn(""+n)+'"][type="radio"]'),n=0;n<o.length;n++){var c=o[n];if(c!==e&&c.form===e.form){var m=c[Vt]||null;if(!m)throw Error(l(90));_c(c,m.value,m.defaultValue,m.defaultValue,m.checked,m.defaultChecked,m.type,m.name)}}for(n=0;n<o.length;n++)c=o[n],c.form===e.form&&Ed(c)}break e;case"textarea":Od(e,o.value,o.defaultValue);break e;case"select":n=o.value,n!=null&&Gl(e,!!o.multiple,n,!1)}}}var zc=!1;function Ud(e,n,o){if(zc)return e(n,o);zc=!0;try{var c=e(n);return c}finally{if(zc=!1,(Zl!==null||Ql!==null)&&(xr(),Zl&&(n=Zl,e=Ql,Ql=Zl=null,Dd(n),e)))for(n=0;n<e.length;n++)Dd(e[n])}}function Js(e,n){var o=e.stateNode;if(o===null)return null;var c=o[Vt]||null;if(c===null)return null;o=c[n];e:switch(n){case"onClick":case"onClickCapture":case"onDoubleClick":case"onDoubleClickCapture":case"onMouseDown":case"onMouseDownCapture":case"onMouseMove":case"onMouseMoveCapture":case"onMouseUp":case"onMouseUpCapture":case"onMouseEnter":(c=!c.disabled)||(e=e.type,c=!(e==="button"||e==="input"||e==="select"||e==="textarea")),e=!c;break e;default:e=!1}if(e)return null;if(o&&typeof o!="function")throw Error(l(231,n,typeof o));return o}var na=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),Cc=!1;if(na)try{var Ws={};Object.defineProperty(Ws,"passive",{get:function(){Cc=!0}}),window.addEventListener("test",Ws,Ws),window.removeEventListener("test",Ws,Ws)}catch{Cc=!1}var $a=null,Ec=null,bi=null;function Hd(){if(bi)return bi;var e,n=Ec,o=n.length,c,m="value"in $a?$a.value:$a.textContent,g=m.length;for(e=0;e<o&&n[e]===m[e];e++);var S=o-e;for(c=1;c<=S&&n[o-c]===m[g-c];c++);return bi=m.slice(e,1<c?1-c:void 0)}function $i(e){var n=e.keyCode;return"charCode"in e?(e=e.charCode,e===0&&n===13&&(e=13)):e=n,e===10&&(e=13),32<=e||e===13?e:0}function ki(){return!0}function Ld(){return!1}function Lt(e){function n(o,c,m,g,S){this._reactName=o,this._targetInst=m,this.type=c,this.nativeEvent=g,this.target=S,this.currentTarget=null;for(var q in e)e.hasOwnProperty(q)&&(o=e[q],this[q]=o?o(g):g[q]);return this.isDefaultPrevented=(g.defaultPrevented!=null?g.defaultPrevented:g.returnValue===!1)?ki:Ld,this.isPropagationStopped=Ld,this}return E(n.prototype,{preventDefault:function(){this.defaultPrevented=!0;var o=this.nativeEvent;o&&(o.preventDefault?o.preventDefault():typeof o.returnValue!="unknown"&&(o.returnValue=!1),this.isDefaultPrevented=ki)},stopPropagation:function(){var o=this.nativeEvent;o&&(o.stopPropagation?o.stopPropagation():typeof o.cancelBubble!="unknown"&&(o.cancelBubble=!0),this.isPropagationStopped=ki)},persist:function(){},isPersistent:ki}),n}var ka={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},_i=Lt(ka),Is=E({},ka,{view:0,detail:0}),S1=Lt(Is),Tc,Oc,Fs,ji=E({},Is,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:qc,button:0,buttons:0,relatedTarget:function(e){return e.relatedTarget===void 0?e.fromElement===e.srcElement?e.toElement:e.fromElement:e.relatedTarget},movementX:function(e){return"movementX"in e?e.movementX:(e!==Fs&&(Fs&&e.type==="mousemove"?(Tc=e.screenX-Fs.screenX,Oc=e.screenY-Fs.screenY):Oc=Tc=0,Fs=e),Tc)},movementY:function(e){return"movementY"in e?e.movementY:Oc}}),Bd=Lt(ji),N1=E({},ji,{dataTransfer:0}),M1=Lt(N1),z1=E({},Is,{relatedTarget:0}),Ac=Lt(z1),C1=E({},ka,{animationName:0,elapsedTime:0,pseudoElement:0}),E1=Lt(C1),T1=E({},ka,{clipboardData:function(e){return"clipboardData"in e?e.clipboardData:window.clipboardData}}),O1=Lt(T1),A1=E({},ka,{data:0}),Yd=Lt(A1),q1={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},R1={8:"Backspace",9:"Tab",12:"Clear",13:"Enter",16:"Shift",17:"Control",18:"Alt",19:"Pause",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",45:"Insert",46:"Delete",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NumLock",145:"ScrollLock",224:"Meta"},D1={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function U1(e){var n=this.nativeEvent;return n.getModifierState?n.getModifierState(e):(e=D1[e])?!!n[e]:!1}function qc(){return U1}var H1=E({},Is,{key:function(e){if(e.key){var n=q1[e.key]||e.key;if(n!=="Unidentified")return n}return e.type==="keypress"?(e=$i(e),e===13?"Enter":String.fromCharCode(e)):e.type==="keydown"||e.type==="keyup"?R1[e.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:qc,charCode:function(e){return e.type==="keypress"?$i(e):0},keyCode:function(e){return e.type==="keydown"||e.type==="keyup"?e.keyCode:0},which:function(e){return e.type==="keypress"?$i(e):e.type==="keydown"||e.type==="keyup"?e.keyCode:0}}),L1=Lt(H1),B1=E({},ji,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),Gd=Lt(B1),Y1=E({},ka,{submitter:0}),G1=Lt(Y1),X1=E({},Is,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:qc}),Z1=Lt(X1),Q1=E({},ka,{propertyName:0,elapsedTime:0,pseudoElement:0}),V1=Lt(Q1),K1=E({},ji,{deltaX:function(e){return"deltaX"in e?e.deltaX:"wheelDeltaX"in e?-e.wheelDeltaX:0},deltaY:function(e){return"deltaY"in e?e.deltaY:"wheelDeltaY"in e?-e.wheelDeltaY:"wheelDelta"in e?-e.wheelDelta:0},deltaZ:0,deltaMode:0}),J1=Lt(K1),W1=E({},ka,{newState:0,oldState:0,source:0}),I1=Lt(W1),F1=[9,13,27,32],Rc=na&&"CompositionEvent"in window,Ps=null;na&&"documentMode"in document&&(Ps=document.documentMode);var P1=na&&"TextEvent"in window&&!Ps,Xd=na&&(!Rc||Ps&&8<Ps&&11>=Ps),Zd=" ",Qd=!1;function Vd(e,n){switch(e){case"keyup":return F1.indexOf(n.keyCode)!==-1;case"keydown":return n.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function Kd(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Vl=!1;function ex(e,n){switch(e){case"compositionend":return Kd(n);case"keypress":return n.which!==32?null:(Qd=!0,Zd);case"textInput":return e=n.data,e===Zd&&Qd?null:e;default:return null}}function tx(e,n){if(Vl)return e==="compositionend"||!Rc&&Vd(e,n)?(e=Hd(),bi=Ec=$a=null,Vl=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(n.ctrlKey||n.altKey||n.metaKey)||n.ctrlKey&&n.altKey){if(n.char&&1<n.char.length)return n.char;if(n.which)return String.fromCharCode(n.which)}return null;case"compositionend":return Xd&&n.locale!=="ko"?null:n.data;default:return null}}var nx={color:!0,date:!0,datetime:!0,"datetime-local":!0,email:!0,month:!0,number:!0,password:!0,range:!0,search:!0,tel:!0,text:!0,time:!0,url:!0,week:!0};function Jd(e){var n=e&&e.nodeName&&e.nodeName.toLowerCase();return n==="input"?!!nx[e.type]:n==="textarea"}function Wd(e,n,o,c){Zl?Ql?Ql.push(c):Ql=[c]:Zl=c,n=Sr(n,"onChange"),0<n.length&&(o=new _i("onChange","change",null,o,c),e.push({event:o,listeners:n}))}var eo=null,to=null;function ax(e){Dy(e,0)}function Si(e){var n=Ks(e);if(Ed(n))return e}function Id(e,n){if(e==="change")return n}var Fd=!1;if(na){var Dc;if(na){var Uc="oninput"in document;if(!Uc){var Pd=document.createElement("div");Pd.setAttribute("oninput","return;"),Uc=typeof Pd.oninput=="function"}Dc=Uc}else Dc=!1;Fd=Dc&&(!document.documentMode||9<document.documentMode)}function em(){eo&&(eo.detachEvent("onpropertychange",tm),to=eo=null)}function tm(e){if(e.propertyName==="value"&&Si(to)){var n=[];Wd(n,to,e,Mc(e)),Ud(ax,n)}}function lx(e,n,o){e==="focusin"?(em(),eo=n,to=o,eo.attachEvent("onpropertychange",tm)):e==="focusout"&&em()}function sx(e){if(e==="selectionchange"||e==="keyup"||e==="keydown")return Si(to)}function ox(e,n){if(e==="click")return Si(n)}function ix(e,n){if(e==="input"||e==="change")return Si(n)}function rx(e,n){return e===n&&(e!==0||1/e===1/n)||e!==e&&n!==n}var cn=typeof Object.is=="function"?Object.is:rx;function no(e,n){if(cn(e,n))return!0;if(typeof e!="object"||e===null||typeof n!="object"||n===null)return!1;var o=Object.keys(e),c=Object.keys(n);if(o.length!==c.length)return!1;for(c=0;c<o.length;c++){var m=o[c];if(!gc.call(n,m)||!cn(e[m],n[m]))return!1}return!0}function Hc(e){if(e=e||(typeof document<"u"?document:void 0),typeof e>"u")return null;try{return e.activeElement||e.body}catch{return e.body}}function nm(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function am(e,n){var o=nm(e);e=0;for(var c;o;){if(o.nodeType===3){if(c=e+o.textContent.length,e<=n&&c>=n)return{node:o,offset:n-e};e=c}e:{for(;o;){if(o.nextSibling){o=o.nextSibling;break e}o=o.parentNode}o=void 0}o=nm(o)}}function lm(e,n){return e&&n?e===n?!0:e&&e.nodeType===3?!1:n&&n.nodeType===3?lm(e,n.parentNode):"contains"in e?e.contains(n):e.compareDocumentPosition?!!(e.compareDocumentPosition(n)&16):!1:!1}function sm(e){e=e!=null&&e.ownerDocument!=null&&e.ownerDocument.defaultView!=null?e.ownerDocument.defaultView:window;for(var n=Hc(e.document);n instanceof e.HTMLIFrameElement;){try{var o=typeof n.contentWindow.location.href=="string"}catch{o=!1}if(o)e=n.contentWindow;else break;n=Hc(e.document)}return n}function Lc(e){var n=e&&e.nodeName&&e.nodeName.toLowerCase();return n&&(n==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||n==="textarea"||e.contentEditable==="true")}var cx=na&&"documentMode"in document&&11>=document.documentMode,Kl=null,Bc=null,ao=null,Yc=!1;function om(e,n,o){var c=o.window===o?o.document:o.nodeType===9?o:o.ownerDocument;Yc||Kl==null||Kl!==Hc(c)||(c=Kl,"selectionStart"in c&&Lc(c)?c={start:c.selectionStart,end:c.selectionEnd}:(c=(c.ownerDocument&&c.ownerDocument.defaultView||window).getSelection(),c={anchorNode:c.anchorNode,anchorOffset:c.anchorOffset,focusNode:c.focusNode,focusOffset:c.focusOffset}),ao&&no(ao,c)||(ao=c,c=Sr(Bc,"onSelect"),0<c.length&&(n=new _i("onSelect","select",null,n,o),e.push({event:n,listeners:c}),n.target=Kl)))}function cl(e,n){var o={};return o[e.toLowerCase()]=n.toLowerCase(),o["Webkit"+e]="webkit"+n,o["Moz"+e]="moz"+n,o}var Jl={animationend:cl("Animation","AnimationEnd"),animationiteration:cl("Animation","AnimationIteration"),animationstart:cl("Animation","AnimationStart"),transitionrun:cl("Transition","TransitionRun"),transitionstart:cl("Transition","TransitionStart"),transitioncancel:cl("Transition","TransitionCancel"),transitionend:cl("Transition","TransitionEnd")},Gc={},im={};na&&(im=document.createElement("div").style,"AnimationEvent"in window||(delete Jl.animationend.animation,delete Jl.animationiteration.animation,delete Jl.animationstart.animation),"TransitionEvent"in window||delete Jl.transitionend.transition);function ul(e){if(Gc[e])return Gc[e];if(!Jl[e])return e;var n=Jl[e],o;for(o in n)if(n.hasOwnProperty(o)&&o in im)return Gc[e]=n[o];return e}var rm=ul("animationend"),cm=ul("animationiteration"),um=ul("animationstart"),ux=ul("transitionrun"),fx=ul("transitionstart"),hx=ul("transitioncancel"),fm=ul("transitionend"),hm=new Map,Xc="abort auxClick beforeToggle cancel canPlay canPlayThrough click close contextMenu copy cut drag dragEnd dragEnter dragExit dragLeave dragOver dragStart drop durationChange emptied encrypted ended error fullscreenChange fullscreenError gotPointerCapture input invalid keyDown keyPress keyUp load loadedData loadedMetadata loadStart lostPointerCapture mouseDown mouseMove mouseOut mouseOver mouseUp paste pause play playing pointerCancel pointerDown pointerMove pointerOut pointerOver pointerUp progress rateChange reset resize seeked seeking stalled submit suspend timeUpdate touchCancel touchEnd touchStart volumeChange scroll toggle touchMove waiting wheel".split(" ");Xc.push("scrollEnd");function Tn(e,n){hm.set(e,n),rl(n,[e])}var dx=0;function aa(e,n){if(e.name!=null&&e.name!=="auto")return e.name;if(n.autoName!==null)return n.autoName;e=Rn.identifierPrefix;var o=dx++;return e="_"+e+"t_"+o.toString(32)+"_",n.autoName=e}function dm(e){if(e==null||typeof e=="string")return e;var n=null,o=ps;if(o!==null)for(var c=0;c<o.length;c++){var m=e[o[c]];if(m!=null){if(m==="none")return"none";n=n==null?m:n+(" "+m)}}return n??e.default}function la(e,n){return e=dm(e),n=dm(n),n==null?e==="auto"?null:e:n==="auto"?null:n}var Ni=typeof reportError=="function"?reportError:function(e){if(typeof window=="object"&&typeof window.ErrorEvent=="function"){var n=new window.ErrorEvent("error",{bubbles:!0,cancelable:!0,message:typeof e=="object"&&e!==null&&typeof e.message=="string"?String(e.message):String(e),error:e});if(!window.dispatchEvent(n))return}else if(typeof process=="object"&&typeof process.emit=="function"){process.emit("uncaughtException",e);return}console.error(e)},bn=[],Wl=0,Zc=0;function Mi(){for(var e=Wl,n=Zc=Wl=0;n<e;){var o=bn[n];bn[n++]=null;var c=bn[n];bn[n++]=null;var m=bn[n];bn[n++]=null;var g=bn[n];if(bn[n++]=null,c!==null&&m!==null){var S=c.pending;S===null?m.next=m:(m.next=S.next,S.next=m),c.pending=m}g!==0&&mm(o,m,g)}}function zi(e,n,o,c){bn[Wl++]=e,bn[Wl++]=n,bn[Wl++]=o,bn[Wl++]=c,Zc|=c,e.lanes|=c,e=e.alternate,e!==null&&(e.lanes|=c)}function Qc(e,n,o,c){return zi(e,n,o,c),Ci(e)}function fl(e,n){return zi(e,null,null,n),Ci(e)}function mm(e,n,o){e.lanes|=o;var c=e.alternate;c!==null&&(c.lanes|=o);for(var m=!1,g=e.return;g!==null;)g.childLanes|=o,c=g.alternate,c!==null&&(c.childLanes|=o),g.tag===22&&(e=g.stateNode,e===null||e._visibility&1||(m=!0)),e=g,g=g.return;return e.tag===3?(g=e.stateNode,m&&n!==null&&(m=31-on(o),e=g.hiddenUpdates,c=e[m],c===null?e[m]=[n]:c.push(n),n.lane=o|536870912),g):null}function Ci(e){if(50<So)throw So=0,vr=null,Error(l(185));for(var n=e.return;n!==null;)e=n,n=e.return;return e.tag===3?e.stateNode:null}var Il={};function mx(e,n,o,c){this.tag=e,this.key=o,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.refCleanup=this.ref=null,this.pendingProps=n,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=c,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function Kt(e,n,o,c){return new mx(e,n,o,c)}function Vc(e){return e=e.prototype,!(!e||!e.isReactComponent)}function sa(e,n){var o=e.alternate;return o===null?(o=Kt(e.tag,n,e.key,e.mode),o.elementType=e.elementType,o.type=e.type,o.stateNode=e.stateNode,o.alternate=e,e.alternate=o):(o.pendingProps=n,o.type=e.type,o.flags=0,o.subtreeFlags=0,o.deletions=null),o.flags=e.flags&1206910976,o.childLanes=e.childLanes,o.lanes=e.lanes,o.child=e.child,o.memoizedProps=e.memoizedProps,o.memoizedState=e.memoizedState,o.updateQueue=e.updateQueue,n=e.dependencies,o.dependencies=n===null?null:{lanes:n.lanes,firstContext:n.firstContext},o.sibling=e.sibling,o.index=e.index,o.ref=e.ref,o.refCleanup=e.refCleanup,o}function pm(e,n){e.flags&=1206910978;var o=e.alternate;return o===null?(e.childLanes=0,e.lanes=n,e.child=null,e.subtreeFlags=0,e.memoizedProps=null,e.memoizedState=null,e.updateQueue=null,e.dependencies=null,e.stateNode=null):(e.childLanes=o.childLanes,e.lanes=o.lanes,e.child=o.child,e.subtreeFlags=0,e.deletions=null,e.memoizedProps=o.memoizedProps,e.memoizedState=o.memoizedState,e.updateQueue=o.updateQueue,e.type=o.type,n=o.dependencies,e.dependencies=n===null?null:{lanes:n.lanes,firstContext:n.firstContext}),e}function Ei(e,n,o,c,m,g){var S=0;if(c=e,typeof c=="function")Vc(c)&&(S=1);else if(typeof c=="string")S=Yb(e,o,Ge.current)?26:e==="html"||e==="head"||e==="body"?27:5;else e:switch(c){case se:return e=Kt(31,o,n,m),e.elementType=se,e.lanes=g,e;case J:return hl(o.children,m,g,n);case T:S=8,m|=24;break;case D:return e=Kt(12,o,n,m|2),e.elementType=D,e.lanes=g,e;case H:return e=Kt(13,o,n,m),e.elementType=H,e.lanes=g,e;case G:return e=Kt(19,o,n,m),e.elementType=G,e.lanes=g,e;case ue:case U:return e=m|32,e=Kt(30,o,n,e),e.elementType=U,e.lanes=g,e.stateNode={autoName:null,paired:null,clones:null,ref:null},e;default:if(typeof c=="object"&&c!==null)switch(c.$$typeof){case Y:S=10;break e;case L:S=9;break e;case O:S=11;break e;case Z:S=14;break e;case W:S=16,c=null;break e}S=29,o=Error(l(130,e===null?"null":typeof e,"")),c=null}return n=Kt(S,o,n,m),n.elementType=e,n.type=c,n.lanes=g,n}function hl(e,n,o,c){return e=Kt(7,e,c,n),e.lanes=o,e}function Kc(e,n,o){return e=Kt(6,e,null,n),e.lanes=o,e}function ym(e){var n=Kt(18,null,null,0);return n.stateNode=e,n}function Jc(e,n,o){return n=Kt(4,e.children!==null?e.children:[],e.key,n),n.lanes=o,n.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},n}var gm=new WeakMap;function $n(e,n){if(typeof e=="object"&&e!==null){var o=gm.get(e);return o!==void 0?o:(n={value:e,source:n,stack:Gs(n)},gm.set(e,n),n)}return{value:e,source:n,stack:Gs(n)}}var Fl=[],Pl=0,Ti=null,lo=0,kn=[],_n=0,_a=null,Bn=1,Yn="";function oa(e,n){Fl[Pl++]=lo,Fl[Pl++]=Ti,Ti=e,lo=n}function wm(e,n,o){kn[_n++]=Bn,kn[_n++]=Yn,kn[_n++]=_a,_a=e;var c=Bn;e=Yn;var m=32-on(c)-1;c&=~(1<<m),o+=1;var g=32-on(n)+m;if(30<g){var S=m-m%5;g=(c&(1<<S)-1).toString(32),c>>=S,m-=S,Bn=1<<32-on(n)+m|o<<m|c,Yn=g+e}else Bn=1<<g|o<<m|c,Yn=e}function Oi(e){e.return!==null&&(oa(e,1),wm(e,1,0))}function Wc(e){for(;e===Ti;)Ti=Fl[--Pl],Fl[Pl]=null,lo=Fl[--Pl],Fl[Pl]=null;for(;e===_a;)_a=kn[--_n],kn[_n]=null,Yn=kn[--_n],kn[_n]=null,Bn=kn[--_n],kn[_n]=null}function vm(e,n){kn[_n++]=Bn,kn[_n++]=Yn,kn[_n++]=_a,Bn=n.id,Yn=n.overflow,_a=e}var _t=null,ot=null,qe=!1,ja=null,jn=!1,Ic=Error(l(519));function Sa(e){var n=Error(l(418,1<arguments.length&&arguments[1]!==void 0&&arguments[1]?"text":"HTML",""));throw so($n(n,e)),Ic}function xm(e){var n=e.stateNode,o=e.type,c=e.memoizedProps;switch(n[Ct]=e,n[Vt]=c,o){case"dialog":He("cancel",n),He("close",n);break;case"iframe":case"object":case"embed":He("load",n);break;case"video":case"audio":for(o=0;o<Mo.length;o++)He(Mo[o],n);break;case"source":He("error",n);break;case"img":case"image":case"link":He("error",n),He("load",n);break;case"details":He("toggle",n);break;case"input":He("invalid",n),Td(n,c.value,c.defaultValue,c.checked,c.defaultChecked,c.type,c.name,!0);break;case"select":He("invalid",n);break;case"textarea":He("invalid",n),Ad(n,c.value,c.defaultValue,c.children)}o=c.children,typeof o!="string"&&typeof o!="number"&&typeof o!="bigint"||n.textContent===""+o||c.suppressHydrationWarning===!0||By(n.textContent,o)?(c.popover!=null&&(He("beforetoggle",n),He("toggle",n)),c.onScroll!=null&&He("scroll",n),c.onScrollEnd!=null&&He("scrollend",n),c.onClick!=null&&(n.onclick=Ln),n=!0):n=!1,n||Sa(e,!0)}function Ai(e){for(_t=e.return;_t;)switch(_t.tag){case 5:case 31:case 13:jn=!1;return;case 27:case 3:jn=!0;return;default:_t=_t.return}}function es(e){if(e!==_t)return!1;if(!qe)return Ai(e),qe=!0,!1;var n=e.tag,o;if((o=n!==3&&n!==27)&&((o=n===5)&&(o=e.type,o=!(o!=="form"&&o!=="button")||Mf(e.type,e.memoizedProps)),o=!o),o&&ot&&Sa(e),Ai(e),n===13){if(e=e.memoizedState,e=e!==null?e.dehydrated:null,!e)throw Error(l(317));ot=og(e)}else if(n===31){if(e=e.memoizedState,e=e!==null?e.dehydrated:null,!e)throw Error(l(317));ot=og(e)}else n===27?(n=ot,Ya(e.type)?(e=Df,Df=null,ot=e):ot=n):ot=_t?Nn(e.stateNode.nextSibling):null;return!0}function dl(){ot=_t=null,qe=!1}function Fc(){var e=ja;return e!==null&&(It===null?It=e:It.push.apply(It,e),ja=null),e}function so(e){ja===null?ja=[e]:ja.push(e)}var Pc=be(null),ml=null,ia=null;function Na(e,n,o){Me(Pc,n._currentValue),n._currentValue=o}function ra(e){e._currentValue=Pc.current,$e(Pc)}function qi(e,n,o){for(;e!==null;){var c=e.alternate;if((e.childLanes&n)!==n?(e.childLanes|=n,c!==null&&(c.childLanes|=n)):c!==null&&(c.childLanes&n)!==n&&(c.childLanes|=n),e===o)break;e=e.return}}function eu(e,n,o,c){var m=e.child;for(m!==null&&(m.return=e);m!==null;){var g=m.dependencies;if(g!==null){var S=m.child;g=g.firstContext;e:for(;g!==null;){var q=g;g=m;for(var Q=0;Q<n.length;Q++)if(q.context===n[Q]){g.lanes|=o,q=g.alternate,q!==null&&(q.lanes|=o),qi(g.return,o,e),c||(S=null);break e}g=q.next}}else if(m.tag===18){if(S=m.return,S===null)throw Error(l(341));S.lanes|=o,g=S.alternate,g!==null&&(g.lanes|=o),qi(S,o,e),S=null}else m.tag===13&&m.memoizedState!==null&&m.memoizedState.dehydrated===null?(m.lanes|=o,S=m.alternate,S!==null&&(S.lanes|=o),qi(m.return,o,e),S=m.child,S=S!==null?S.sibling:null):S=m.child;if(S!==null)S.return=m;else for(S=m;S!==null;){if(S===e){S=null;break}if(m=S.sibling,m!==null){m.return=S.return,S=m;break}S=S.return}m=S}}function pl(e,n,o,c){e=null;for(var m=n,g=!1;m!==null;){if(!g){if((m.flags&524288)!==0)g=!0;else if((m.flags&262144)!==0)break}if(m.tag===10){var S=m.alternate;if(S===null)throw Error(l(387));if(S=S.memoizedProps,S!==null){var q=m.type;cn(m.pendingProps.value,S.value)||(e!==null?e.push(q):e=[q])}}else if(m===X.current){if(S=m.alternate,S===null)throw Error(l(387));S.memoizedState.memoizedState!==m.memoizedState.memoizedState&&(e!==null?e.push(js):e=[js])}m=m.return}return e!==null&&eu(n,e,o,c),n.flags|=262144,e!==null}function Ri(e){for(e=e.firstContext;e!==null;){if(!cn(e.context._currentValue,e.memoizedValue))return!0;e=e.next}return!1}function yl(e){ml=e,ia=null,e=e.dependencies,e!==null&&(e.firstContext=null)}function Et(e){return bm(ml,e)}function Di(e,n){return ml===null&&yl(e),bm(e,n)}function bm(e,n){var o=n._currentValue;if(n={context:n,memoizedValue:o,next:null},ia===null){if(e===null)throw Error(l(308));ia=n,e.dependencies={lanes:0,firstContext:n},e.flags|=524288}else ia=ia.next=n;return o}var px=typeof AbortController<"u"?AbortController:function(){var e=[],n=this.signal={aborted:!1,addEventListener:function(o,c){e.push(c)}};this.abort=function(){n.aborted=!0,e.forEach(function(o){return o()})}},yx=t.unstable_scheduleCallback,gx=t.unstable_NormalPriority,gt={$$typeof:Y,Consumer:null,Provider:null,_currentValue:null,_currentValue2:null,_threadCount:0};function tu(){return{controller:new px,data:new Map,refCount:0}}function oo(e){e.refCount--,e.refCount===0&&yx(gx,function(){e.controller.abort()})}function $m(e,n){if((e.pendingLanes&4194048)!==0){var o=e.transitionTypes;for(o===null&&(o=e.transitionTypes=[]),e=0;e<n.length;e++){var c=n[e];o.indexOf(c)===-1&&o.push(c)}}}var io=null;function wx(e){var n=e.transitionTypes;return e.transitionTypes=null,n}var ro=null,nu=0,gl=0,ts=null;function vx(e,n){if(ro===null){var o=ro=[];nu=0,gl=vf(),ts={status:"pending",value:void 0,then:function(c){o.push(c)}}}return nu++,n.then(km,km),n}function km(){if(--nu===0&&(io=null,ro!==null)){ts!==null&&(ts.status="fulfilled");var e=ro;ro=null,gl=0,ts=null;for(var n=0;n<e.length;n++)(0,e[n])()}}function xx(e,n){var o=[],c={status:"pending",value:null,reason:null,then:function(m){o.push(m)}};return e.then(function(){c.status="fulfilled",c.value=n;for(var m=0;m<o.length;m++)(0,o[m])(n)},function(m){for(c.status="rejected",c.reason=m,m=0;m<o.length;m++)(0,o[m])(void 0)}),c}var _m=fe.S;fe.S=function(e,n){if(yy=ln(),typeof n=="object"&&n!==null&&typeof n.then=="function"&&vx(e,n),io!==null)for(var o=vs;o!==null;)$m(o,io),o=o.next;if(o=e.types,o!==null){for(var c=vs;c!==null;)$m(c,o),c=c.next;if(gl!==0){c=io,c===null&&(c=io=[]);for(var m=0;m<o.length;m++){var g=o[m];c.indexOf(g)===-1&&c.push(g)}}}_m!==null&&_m(e,n)};var wl=be(null);function au(){var e=wl.current;return e!==null?e:st.pooledCache}function Ui(e,n){n===null?Me(wl,wl.current):Me(wl,n.pool)}function jm(){var e=au();return e===null?null:{parent:gt._currentValue,pool:e}}var ns=Error(l(460)),lu=Error(l(474)),Hi=Error(l(542)),Li={then:function(){}};function Sm(e){return e=e.status,e==="fulfilled"||e==="rejected"}function Nm(e,n,o){switch(o=e[o],o===void 0?e.push(n):o!==n&&(n.then(Ln,Ln),n=o),n.status){case"fulfilled":return n.value;case"rejected":throw e=n.reason,zm(e),e===void 0&&!("reason"in n)?Error(l(600)):e;default:if(typeof n.status=="string")n.then(Ln,Ln);else{if(e=st,e!==null&&100<e.shellSuspendCounter)throw Error(l(482));e=n,e.status="pending",e.then(function(c){if(n.status==="pending"){var m=n;m.status="fulfilled",m.value=c}},function(c){if(n.status==="pending"){var m=n;m.status="rejected",m.reason=c}})}switch(n.status){case"fulfilled":return n.value;case"rejected":throw e=n.reason,zm(e),e}throw xl=n,ns}}function vl(e){try{var n=e._init;return n(e._payload)}catch(o){throw o!==null&&typeof o=="object"&&typeof o.then=="function"?(xl=o,ns):o}}var xl=null;function Mm(){if(xl===null)throw Error(l(459));var e=xl;return xl=null,e}function zm(e){if(e===ns||e===Hi)throw Error(l(483))}var as=null,co=0;function Bi(e){var n=co;return co+=1,as===null&&(as=[]),Nm(as,e,n)}function Ma(e,n){n=n.props.ref,e.ref=n!==void 0?n:null}function Yi(e,n){throw n.$$typeof===R?Error(l(525)):(e=Object.prototype.toString.call(n),Error(l(31,e==="[object Object]"?"object with keys {"+Object.keys(n).join(", ")+"}":e)))}function Cm(e){function n(ae,I){if(e){var oe=ae.deletions;oe===null?(ae.deletions=[I],ae.flags|=16):oe.push(I)}}function o(ae,I){if(!e)return null;for(;I!==null;)n(ae,I),I=I.sibling;return null}function c(ae){for(var I=new Map;ae!==null;)ae.key===null?I.set(ae.index,ae):I.set(ae.key,ae),ae=ae.sibling;return I}function m(ae,I){return ae=sa(ae,I),ae.index=0,ae.sibling=null,ae}function g(ae,I,oe){return ae.index=oe,e?(oe=ae.alternate,oe!==null?(oe=oe.index,oe<I?(ae.flags|=2,I):oe):(ae.flags|=134217730,I)):(ae.flags|=1048576,I)}function S(ae){return e&&ae.alternate===null&&(ae.flags|=134217730),ae}function q(ae,I,oe,de){return I===null||I.tag!==6?(I=Kc(oe,ae.mode,de),I.return=ae,I):(I=m(I,oe),I.return=ae,I)}function Q(ae,I,oe,de){var ke=oe.type;return ke===J?(ae=ce(ae,I,oe.props.children,de,oe.key),Ma(ae,oe),ae):I!==null&&(I.elementType===ke||typeof ke=="object"&&ke!==null&&ke.$$typeof===W&&vl(ke)===I.type)?(I=m(I,oe.props),Ma(I,oe),I.return=ae,I):(I=Ei(oe.type,oe.key,oe.props,null,ae.mode,de),Ma(I,oe),I.return=ae,I)}function le(ae,I,oe,de){return I===null||I.tag!==4||I.stateNode.containerInfo!==oe.containerInfo||I.stateNode.implementation!==oe.implementation?(I=Jc(oe,ae.mode,de),I.return=ae,I):(I=m(I,oe.children||[]),I.return=ae,I)}function ce(ae,I,oe,de,ke){return I===null||I.tag!==7?(I=hl(oe,ae.mode,de,ke),I.return=ae,I):(I=m(I,oe),I.return=ae,I)}function me(ae,I,oe){if(typeof I=="string"&&I!==""||typeof I=="number"||typeof I=="bigint")return I=Kc(""+I,ae.mode,oe),I.return=ae,I;if(typeof I=="object"&&I!==null){switch(I.$$typeof){case B:return oe=Ei(I.type,I.key,I.props,null,ae.mode,oe),Ma(oe,I),oe.return=ae,oe;case K:return I=Jc(I,ae.mode,oe),I.return=ae,I;case W:return I=vl(I),me(ae,I,oe)}if(pe(I)||ie(I))return I=hl(I,ae.mode,oe,null),I.return=ae,I;if(typeof I.then=="function")return me(ae,Bi(I),oe);if(I.$$typeof===Y)return me(ae,Di(ae,I),oe);Yi(ae,I)}return null}function ee(ae,I,oe,de){var ke=I!==null?I.key:null;if(typeof oe=="string"&&oe!==""||typeof oe=="number"||typeof oe=="bigint")return ke!==null?null:q(ae,I,""+oe,de);if(typeof oe=="object"&&oe!==null){switch(oe.$$typeof){case B:return oe.key===ke?Q(ae,I,oe,de):null;case K:return oe.key===ke?le(ae,I,oe,de):null;case W:return oe=vl(oe),ee(ae,I,oe,de)}if(pe(oe)||ie(oe))return ke!==null?null:ce(ae,I,oe,de,null);if(typeof oe.then=="function")return ee(ae,I,Bi(oe),de);if(oe.$$typeof===Y)return ee(ae,I,Di(ae,oe),de);Yi(ae,oe)}return null}function re(ae,I,oe,de,ke){if(typeof de=="string"&&de!==""||typeof de=="number"||typeof de=="bigint")return ae=ae.get(oe)||null,q(I,ae,""+de,ke);if(typeof de=="object"&&de!==null){switch(de.$$typeof){case B:return ae=ae.get(de.key===null?oe:de.key)||null,Q(I,ae,de,ke);case K:return ae=ae.get(de.key===null?oe:de.key)||null,le(I,ae,de,ke);case W:return de=vl(de),re(ae,I,oe,de,ke)}if(pe(de)||ie(de))return ae=ae.get(oe)||null,ce(I,ae,de,ke,null);if(typeof de.then=="function")return re(ae,I,oe,Bi(de),ke);if(de.$$typeof===Y)return re(ae,I,oe,Di(I,de),ke);Yi(I,de)}return null}function xe(ae,I,oe,de){for(var ke=null,Ye=null,Ne=I,ze=I=0,xt=null;Ne!==null&&ze<oe.length;ze++){Ne.index>ze?(xt=Ne,Ne=null):xt=Ne.sibling;var Xe=ee(ae,Ne,oe[ze],de);if(Xe===null){Ne===null&&(Ne=xt);break}e&&Ne&&Xe.alternate===null&&n(ae,Ne),I=g(Xe,I,ze),Ye===null?ke=Xe:Ye.sibling=Xe,Ye=Xe,Ne=xt}if(ze===oe.length)return o(ae,Ne),qe&&oa(ae,ze),ke;if(Ne===null){for(;ze<oe.length;ze++)Ne=me(ae,oe[ze],de),Ne!==null&&(I=g(Ne,I,ze),Ye===null?ke=Ne:Ye.sibling=Ne,Ye=Ne);return qe&&oa(ae,ze),ke}for(Ne=c(Ne);ze<oe.length;ze++)xt=re(Ne,ae,ze,oe[ze],de),xt!==null&&(e&&(Xe=xt.alternate,Xe!==null&&Ne.delete(Xe.key===null?ze:Xe.key)),I=g(xt,I,ze),Ye===null?ke=xt:Ye.sibling=xt,Ye=xt);return e&&Ne.forEach(function(Va){return n(ae,Va)}),qe&&oa(ae,ze),ke}function je(ae,I,oe,de){if(oe==null)throw Error(l(151));for(var ke=null,Ye=null,Ne=I,ze=I=0,xt=null,Xe=oe.next();Ne!==null&&!Xe.done;ze++,Xe=oe.next()){Ne.index>ze?(xt=Ne,Ne=null):xt=Ne.sibling;var Va=ee(ae,Ne,Xe.value,de);if(Va===null){Ne===null&&(Ne=xt);break}e&&Ne&&Va.alternate===null&&n(ae,Ne),I=g(Va,I,ze),Ye===null?ke=Va:Ye.sibling=Va,Ye=Va,Ne=xt}if(Xe.done)return o(ae,Ne),qe&&oa(ae,ze),ke;if(Ne===null){for(;!Xe.done;ze++,Xe=oe.next())Xe=me(ae,Xe.value,de),Xe!==null&&(I=g(Xe,I,ze),Ye===null?ke=Xe:Ye.sibling=Xe,Ye=Xe);return qe&&oa(ae,ze),ke}for(Ne=c(Ne);!Xe.done;ze++,Xe=oe.next())Xe=re(Ne,ae,ze,Xe.value,de),Xe!==null&&(e&&(xt=Xe.alternate,xt!==null&&Ne.delete(xt.key===null?ze:xt.key)),I=g(Xe,I,ze),Ye===null?ke=Xe:Ye.sibling=Xe,Ye=Xe);return e&&Ne.forEach(function(e$){return n(ae,e$)}),qe&&oa(ae,ze),ke}function Ae(ae,I,oe,de){if(typeof oe=="object"&&oe!==null&&oe.type===J&&oe.key===null&&oe.props.ref===void 0&&(oe=oe.props.children),typeof oe=="object"&&oe!==null){switch(oe.$$typeof){case B:e:{for(var ke=oe.key;I!==null;){if(I.key===ke){if(ke=oe.type,ke===J){if(I.tag===7){o(ae,I.sibling),de=m(I,oe.props.children),Ma(de,oe),de.return=ae,ae=de;break e}}else if(I.elementType===ke||typeof ke=="object"&&ke!==null&&ke.$$typeof===W&&vl(ke)===I.type){o(ae,I.sibling),de=m(I,oe.props),Ma(de,oe),de.return=ae,ae=de;break e}o(ae,I);break}else n(ae,I);I=I.sibling}oe.type===J?(de=hl(oe.props.children,ae.mode,de,oe.key),Ma(de,oe),de.return=ae,ae=de):(de=Ei(oe.type,oe.key,oe.props,null,ae.mode,de),Ma(de,oe),de.return=ae,ae=de)}return S(ae);case K:e:{for(ke=oe.key;I!==null;){if(I.key===ke)if(I.tag===4&&I.stateNode.containerInfo===oe.containerInfo&&I.stateNode.implementation===oe.implementation){o(ae,I.sibling),de=m(I,oe.children||[]),de.return=ae,ae=de;break e}else{o(ae,I);break}else n(ae,I);I=I.sibling}de=Jc(oe,ae.mode,de),de.return=ae,ae=de}return S(ae);case W:return oe=vl(oe),Ae(ae,I,oe,de)}if(pe(oe))return xe(ae,I,oe,de);if(ie(oe)){if(ke=ie(oe),typeof ke!="function")throw Error(l(150));return oe=ke.call(oe),je(ae,I,oe,de)}if(typeof oe.then=="function")return Ae(ae,I,Bi(oe),de);if(oe.$$typeof===Y)return Ae(ae,I,Di(ae,oe),de);Yi(ae,oe)}return typeof oe=="string"&&oe!==""||typeof oe=="number"||typeof oe=="bigint"?(oe=""+oe,I!==null&&I.tag===6?(o(ae,I.sibling),de=m(I,oe),de.return=ae,ae=de):(o(ae,I),de=Kc(oe,ae.mode,de),de.return=ae,ae=de),S(ae)):o(ae,I)}return function(ae,I,oe,de){try{co=0;var ke=Ae(ae,I,oe,de);return as=null,ke}catch(Ne){if(Ne===ns||Ne===Hi)throw Ne;var Ye=Kt(29,Ne,null,ae.mode);return Ye.lanes=de,Ye.return=ae,Ye}}}var bl=Cm(!0),Em=Cm(!1),za=!1;function su(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,lanes:0,hiddenCallbacks:null},callbacks:null}}function ou(e,n){e=e.updateQueue,n.updateQueue===e&&(n.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,callbacks:null})}function Ca(e){return{lane:e,tag:0,payload:null,callback:null,next:null}}function Ea(e,n,o){var c=e.updateQueue;if(c===null)return null;if(c=c.shared,(Je&2)!==0){var m=c.pending;return m===null?n.next=n:(n.next=m.next,m.next=n),c.pending=n,n=Ci(e),mm(e,null,o),n}return zi(e,c,n,o),Ci(e)}function uo(e,n,o){if(n=n.updateQueue,n!==null&&(n=n.shared,(o&4194048)!==0)){var c=n.lanes;c&=e.pendingLanes,o|=c,n.lanes=o,wd(e,o)}}function iu(e,n){var o=e.updateQueue,c=e.alternate;if(c!==null&&(c=c.updateQueue,o===c)){var m=null,g=null;if(o=o.firstBaseUpdate,o!==null){do{var S={lane:o.lane,tag:o.tag,payload:o.payload,callback:null,next:null};g===null?m=g=S:g=g.next=S,o=o.next}while(o!==null);g===null?m=g=n:g=g.next=n}else m=g=n;o={baseState:c.baseState,firstBaseUpdate:m,lastBaseUpdate:g,shared:c.shared,callbacks:c.callbacks},e.updateQueue=o;return}e=o.lastBaseUpdate,e===null?o.firstBaseUpdate=n:e.next=n,o.lastBaseUpdate=n}var ru=!1;function fo(){if(ru){var e=ts;if(e!==null)throw e}}function ho(e,n,o,c){ru=!1;var m=e.updateQueue;za=!1;var g=m.firstBaseUpdate,S=m.lastBaseUpdate,q=m.shared.pending;if(q!==null){m.shared.pending=null;var Q=q,le=Q.next;Q.next=null,S===null?g=le:S.next=le,S=Q;var ce=e.alternate;ce!==null&&(ce=ce.updateQueue,q=ce.lastBaseUpdate,q!==S&&(q===null?ce.firstBaseUpdate=le:q.next=le,ce.lastBaseUpdate=Q))}if(g!==null){var me=m.baseState;S=0,ce=le=Q=null,q=g;do{var ee=q.lane&-536870913,re=ee!==q.lane;if(re?(Be&ee)===ee:(c&ee)===ee){ee!==0&&ee===gl&&(ru=!0),ce!==null&&(ce=ce.next={lane:0,tag:q.tag,payload:q.payload,callback:null,next:null});e:{var xe=e,je=q;ee=n;var Ae=o;switch(je.tag){case 1:if(xe=je.payload,typeof xe=="function"){me=xe.call(Ae,me,ee);break e}me=xe;break e;case 3:xe.flags=xe.flags&-65537|128;case 0:if(xe=je.payload,ee=typeof xe=="function"?xe.call(Ae,me,ee):xe,ee==null)break e;me=E({},me,ee);break e;case 2:za=!0}}ee=q.callback,ee!==null&&(e.flags|=64,re&&(e.flags|=8192),re=m.callbacks,re===null?m.callbacks=[ee]:re.push(ee))}else re={lane:ee,tag:q.tag,payload:q.payload,callback:q.callback,next:null},ce===null?(le=ce=re,Q=me):ce=ce.next=re,S|=ee;if(q=q.next,q===null){if(q=m.shared.pending,q===null)break;re=q,q=re.next,re.next=null,m.lastBaseUpdate=re,m.shared.pending=null}}while(!0);ce===null&&(Q=me),m.baseState=Q,m.firstBaseUpdate=le,m.lastBaseUpdate=ce,g===null&&(m.shared.lanes=0),Ua|=S,e.lanes=S,e.memoizedState=me}}function Tm(e,n){if(typeof e!="function")throw Error(l(191,e));e.call(n)}function Om(e,n){var o=e.callbacks;if(o!==null)for(e.callbacks=null,e=0;e<o.length;e++)Tm(o[e],n)}var Ta=be(null),Gi=be(0);function Am(e,n){e=da,Me(Gi,e),Me(Ta,n),da=e|n.baseLanes}function cu(){Me(Gi,da),Me(Ta,Ta.current)}function uu(){da=Gi.current,$e(Ta),$e(Gi)}var Tt=be(null),Dt=null;function Oa(e){var n=e.alternate;Me(Ot,Ot.current&1),Me(Tt,e),Dt===null&&(n===null||Ta.current!==null||n.memoizedState!==null)&&(Dt=e)}function fu(e){Me(Ot,Ot.current),Me(Tt,e),Dt===null&&(Dt=e)}function qm(e){e.tag===22?(Me(Ot,Ot.current),Me(Tt,e),Dt===null&&(Dt=e)):Aa()}function Aa(){Me(Ot,Ot.current),Me(Tt,Tt.current)}function un(e){$e(Tt),Dt===e&&(Dt=null),$e(Ot)}var Ot=be(0);function mo(e,n){Me(Tt,Tt.current),Me(Ot,n)}function hu(e){$e(Ot),$e(Tt),Dt===e&&(Dt=null)}function Xi(e){for(var n=e;n!==null;){if(n.tag===13){var o=n.memoizedState;if(o!==null&&(o=o.dehydrated,o===null||qf(o)||Rf(o)))return n}else if(n.tag===19&&n.memoizedProps.revealOrder!=="independent"){if((n.flags&128)!==0)return n}else if(n.child!==null){n.child.return=n,n=n.child;continue}if(n===e)break;for(;n.sibling===null;){if(n.return===null||n.return===e)return null;n=n.return}n.sibling.return=n.return,n=n.sibling}return null}var ca=0,Oe=null,lt=null,wt=null,Zi=!1,ls=!1,$l=!1,Qi=0,po=0,ss=null,bx=0;function ht(){throw Error(l(321))}function du(e,n){if(n===null)return!1;for(var o=0;o<n.length&&o<e.length;o++)if(!cn(e[o],n[o]))return!1;return!0}function mu(e,n,o,c,m,g){return ca=g,Oe=n,n.memoizedState=null,n.updateQueue=null,n.lanes=0,fe.H=e===null||e.memoizedState===null?wp:vp,$l=!1,g=o(c,m),$l=!1,ls&&(g=Dm(n,o,c,m)),Rm(e),g}function Rm(e){fe.H=Pi;var n=lt!==null&<.next!==null;if(ca=0,wt=lt=Oe=null,Zi=!1,po=0,ss=null,n)throw Error(l(300));e===null||vt||(e=e.dependencies,e!==null&&Ri(e)&&(vt=!0))}function Dm(e,n,o,c){Oe=e;var m=0;do{if(ls&&(ss=null),po=0,ls=!1,25<=m)throw Error(l(301));if(m+=1,wt=lt=null,e.updateQueue!=null){var g=e.updateQueue;g.lastEffect=null,g.events=null,g.stores=null,g.memoCache!=null&&(g.memoCache.index=0)}fe.H=zx,g=n(o,c)}while(ls);return g}function $x(){var e=fe.H,n=e.useState()[0];return n=typeof n.then=="function"?yo(n):n,e=e.useState()[0],(lt!==null?lt.memoizedState:null)!==e&&(Oe.flags|=1024),n}function pu(){var e=Qi!==0;return Qi=0,e}function yu(e,n,o){n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~o}function gu(e){if(Zi){for(e=e.memoizedState;e!==null;){var n=e.queue;n!==null&&(n.pending=null),e=e.next}Zi=!1}ca=0,wt=lt=Oe=null,ls=!1,po=Qi=0,ss=null}function Bt(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return wt===null?Oe.memoizedState=wt=e:wt=wt.next=e,wt}function pt(){if(lt===null){var e=Oe.alternate;e=e!==null?e.memoizedState:null}else e=lt.next;var n=wt===null?Oe.memoizedState:wt.next;if(n!==null)wt=n,lt=e;else{if(e===null)throw Oe.alternate===null?Error(l(467)):Error(l(310));lt=e,e={memoizedState:lt.memoizedState,baseState:lt.baseState,baseQueue:lt.baseQueue,queue:lt.queue,next:null},wt===null?Oe.memoizedState=wt=e:wt=wt.next=e}return wt}function Vi(){return{lastEffect:null,events:null,stores:null,memoCache:null}}function yo(e){var n=po;return po+=1,ss===null&&(ss=[]),e=Nm(ss,e,n),n=Oe,(wt===null?n.memoizedState:wt.next)===null&&(n=n.alternate,fe.H=n===null||n.memoizedState===null?wp:vp),e}function Ki(e){if(e!==null&&typeof e=="object"){if(typeof e.then=="function")return yo(e);if(e.$$typeof===V)return;if(e.$$typeof===Y)return Et(e)}throw Error(l(438,String(e)))}function wu(e){var n=null,o=Oe.updateQueue;if(o!==null&&(n=o.memoCache),n==null){var c=Oe.alternate;c!==null&&(c=c.updateQueue,c!==null&&(c=c.memoCache,c!=null&&(n={data:c.data.map(function(m){return m.slice()}),index:0})))}if(n==null&&(n={data:[],index:0}),o===null&&(o=Vi(),Oe.updateQueue=o),o.memoCache=n,o=n.data[n.index],o===void 0)for(o=n.data[n.index]=Array(e),c=0;c<e;c++)o[c]=te;return n.index++,o}function ua(e,n){return typeof n=="function"?n(e):n}function Ji(e){var n=pt();return vu(n,lt,e)}function vu(e,n,o){var c=e.queue;if(c===null)throw Error(l(311));c.lastRenderedReducer=o;var m=e.baseQueue,g=c.pending;if(g!==null){if(m!==null){var S=m.next;m.next=g.next,g.next=S}n.baseQueue=m=g,c.pending=null}if(g=e.baseState,m===null)e.memoizedState=g;else{n=m.next;var q=S=null,Q=null,le=n,ce=!1;do{var me=le.lane&-536870913;if(me!==le.lane?(Be&me)===me:(ca&me)===me){var ee=le.revertLane;if(ee===0)Q!==null&&(Q=Q.next={lane:0,revertLane:0,gesture:null,action:le.action,hasEagerState:le.hasEagerState,eagerState:le.eagerState,next:null}),me===gl&&(ce=!0);else if((ca&ee)===ee){le=le.next,ee===gl&&(ce=!0);continue}else me={lane:0,revertLane:le.revertLane,gesture:null,action:le.action,hasEagerState:le.hasEagerState,eagerState:le.eagerState,next:null},Q===null?(q=Q=me,S=g):Q=Q.next=me,Oe.lanes|=ee,Ua|=ee;me=le.action,$l&&o(g,me),g=le.hasEagerState?le.eagerState:o(g,me)}else ee={lane:me,revertLane:le.revertLane,gesture:le.gesture,action:le.action,hasEagerState:le.hasEagerState,eagerState:le.eagerState,next:null},Q===null?(q=Q=ee,S=g):Q=Q.next=ee,Oe.lanes|=me,Ua|=me;le=le.next}while(le!==null&&le!==n);if(Q===null?S=g:Q.next=q,!cn(g,e.memoizedState)&&(vt=!0,ce&&(o=ts,o!==null)))throw o;e.memoizedState=g,e.baseState=S,e.baseQueue=Q,c.lastRenderedState=g}return m===null&&(c.lanes=0),[e.memoizedState,c.dispatch]}function xu(e){var n=pt(),o=n.queue;if(o===null)throw Error(l(311));o.lastRenderedReducer=e;var c=o.dispatch,m=o.pending,g=n.memoizedState;if(m!==null){o.pending=null;var S=m=m.next;do g=e(g,S.action),S=S.next;while(S!==m);cn(g,n.memoizedState)||(vt=!0),n.memoizedState=g,n.baseQueue===null&&(n.baseState=g),o.lastRenderedState=g}return[g,c]}function Um(e,n,o){var c=Oe,m=pt(),g=qe;if(g){if(o===void 0)throw Error(l(407));o=o()}else o=n();var S=!cn((lt||m).memoizedState,o);if(S&&(m.memoizedState=o,vt=!0),m=m.queue,ku(Bm.bind(null,c,m,e),[e]),e=m.getSnapshot!==n||S||wt!==null&&(wt.memoizedState.tag&1)!==0,os(e?9:8,{destroy:void 0},Lm.bind(null,c,m,o,n),null),e){if(c.flags|=2048,st===null)throw Error(l(349));g||(ca&127)!==0||Hm(c,n,o)}return o}function Hm(e,n,o){e.flags|=16384,e={getSnapshot:n,value:o},n=Oe.updateQueue,n===null?(n=Vi(),Oe.updateQueue=n,n.stores=[e]):(o=n.stores,o===null?n.stores=[e]:o.push(e))}function Lm(e,n,o,c){n.value=o,n.getSnapshot=c,Ym(n)&&Gm(e)}function Bm(e,n,o){return o(function(){Ym(n)&&Gm(e)})}function Ym(e){var n=e.getSnapshot;e=e.value;try{var o=n();return!cn(e,o)}catch{return!0}}function Gm(e){var n=fl(e,2);n!==null&&Ft(n,e,2)}function bu(e){var n=Bt();if(typeof e=="function"){var o=e;if(e=o(),$l){ba(!0);try{o()}finally{ba(!1)}}}return n.memoizedState=n.baseState=e,n.queue={pending:null,lanes:0,dispatch:null,lastRenderedReducer:ua,lastRenderedState:e},n}function Xm(e,n,o,c){return e.baseState=o,vu(e,lt,typeof c=="function"?c:ua)}function kx(e,n,o,c,m){if(Fi(e))throw Error(l(485));if(e=n.action,e!==null){var g={payload:m,action:e,next:null,isTransition:!0,status:"pending",value:null,reason:null,listeners:[],then:function(S){g.listeners.push(S)}};fe.T!==null?o(!0):g.isTransition=!1,c(g),o=n.pending,o===null?(g.next=n.pending=g,Zm(n,g)):(g.next=o.next,n.pending=o.next=g)}}function Zm(e,n){var o=n.action,c=n.payload,m=e.state;if(n.isTransition){var g=fe.T,S={};S.types=g!==null?g.types:null,fe.T=S;try{var q=o(m,c),Q=fe.S;Q!==null&&Q(S,q),Qm(e,n,q)}catch(le){$u(e,n,le)}finally{g!==null&&S.types!==null&&(g.types=S.types),fe.T=g}}else try{g=o(m,c),Qm(e,n,g)}catch(le){$u(e,n,le)}}function Qm(e,n,o){o!==null&&typeof o=="object"&&typeof o.then=="function"?o.then(function(c){Vm(e,n,c)},function(c){return $u(e,n,c)}):Vm(e,n,o)}function Vm(e,n,o){n.status="fulfilled",n.value=o,Km(n),e.state=o,n=e.pending,n!==null&&(o=n.next,o===n?e.pending=null:(o=o.next,n.next=o,Zm(e,o)))}function $u(e,n,o){var c=e.pending;if(e.pending=null,c!==null){c=c.next;do n.status="rejected",n.reason=o,Km(n),n=n.next;while(n!==c)}e.action=null}function Km(e){e=e.listeners;for(var n=0;n<e.length;n++)(0,e[n])()}function Jm(e,n){return n}function Wm(e,n){if(qe){var o=st.formState;if(o!==null){e:{var c=Oe;if(qe){if(ot){t:{for(var m=ot,g=jn;m.nodeType!==8;){if(!g){m=null;break t}if(m=Nn(m.nextSibling),m===null){m=null;break t}}g=m.data,m=g==="F!"||g==="F"?m:null}if(m){ot=Nn(m.nextSibling),c=m.data==="F!";break e}}Sa(c)}c=!1}c&&(n=o[0])}}return o=Bt(),o.memoizedState=o.baseState=n,c={pending:null,lanes:0,dispatch:null,lastRenderedReducer:Jm,lastRenderedState:n},o.queue=c,o=pp.bind(null,Oe,c),c.dispatch=o,c=bu(!1),g=Mu.bind(null,Oe,!1,c.queue),c=Bt(),m={state:n,dispatch:null,action:e,pending:null},c.queue=m,o=kx.bind(null,Oe,m,g,o),m.dispatch=o,c.memoizedState=e,[n,o,!1]}function Im(e){var n=pt();return Fm(n,lt,e)}function Fm(e,n,o){if(n=vu(e,n,Jm)[0],e=Ji(ua)[0],typeof n=="object"&&n!==null&&typeof n.then=="function")try{var c=yo(n)}catch(S){throw S===ns?Hi:S}else c=n;n=pt();var m=n.queue,g=m.dispatch;return o!==n.memoizedState&&(Oe.flags|=2048,os(9,{destroy:void 0},_x.bind(null,m,o),null)),[c,g,e]}function _x(e,n){e.action=n}function Pm(e){var n=pt(),o=lt;if(o!==null)return Fm(n,o,e);pt(),n=n.memoizedState,o=pt();var c=o.queue.dispatch;return o.memoizedState=e,[n,c,!1]}function os(e,n,o,c){return e={tag:e,create:o,deps:c,inst:n,next:null},n=Oe.updateQueue,n===null&&(n=Vi(),Oe.updateQueue=n),o=n.lastEffect,o===null?n.lastEffect=e.next=e:(c=o.next,o.next=e,e.next=c,n.lastEffect=e),e}function ep(){return pt().memoizedState}function Wi(e,n,o,c){var m=Bt();Oe.flags|=e,m.memoizedState=os(1|n,{destroy:void 0},o,c===void 0?null:c)}function Ii(e,n,o,c){var m=pt();c=c===void 0?null:c;var g=m.memoizedState.inst;lt!==null&&c!==null&&du(c,lt.memoizedState.deps)?m.memoizedState=os(n,g,o,c):(Oe.flags|=e,m.memoizedState=os(1|n,g,o,c))}function tp(e,n){Wi(8390656,8,e,n)}function ku(e,n){Ii(2048,8,e,n)}function jx(e){Oe.flags|=4;var n=Oe.updateQueue;if(n===null)n=Vi(),Oe.updateQueue=n,n.events=[e];else{var o=n.events;o===null?n.events=[e]:o.push(e)}}function np(e){var n=pt().memoizedState;return jx({ref:n,nextImpl:e}),function(){if((Je&2)!==0)throw Error(l(440));return n.impl.apply(void 0,arguments)}}function ap(e,n){return Ii(4,2,e,n)}function lp(e,n){return Ii(4,4,e,n)}function sp(e,n){if(typeof n=="function"){e=e();var o=n(e);return function(){typeof o=="function"?o():n(null)}}if(n!=null)return e=e(),n.current=e,function(){n.current=null}}function op(e,n,o){o=o!=null?o.concat([e]):null,Ii(4,4,sp.bind(null,n,e),o)}function _u(){}function ip(e,n){var o=pt();n=n===void 0?null:n;var c=o.memoizedState;return n!==null&&du(n,c[1])?c[0]:(o.memoizedState=[e,n],e)}function rp(e,n){var o=pt();n=n===void 0?null:n;var c=o.memoizedState;if(n!==null&&du(n,c[1]))return c[0];if(c=e(),$l){ba(!0);try{e()}finally{ba(!1)}}return o.memoizedState=[c,n],c}function ju(e,n,o){return o===void 0||(ca&1073741824)!==0&&(Be&261930)===0?e.memoizedState=n:(e.memoizedState=o,e=wy(),Oe.lanes|=e,Ua|=e,o)}function cp(e,n,o,c){return cn(o,n)?o:Ta.current!==null?(e=ju(e,o,c),cn(e,n)||(vt=!0),e):(ca&106)===0||(ca&1073741824)!==0&&(Be&261930)===0?(vt=!0,e.memoizedState=o):(e=wy(),Oe.lanes|=e,Ua|=e,n)}function up(e,n,o,c,m){var g=ge.p;ge.p=g!==0&&8>g?g:8;var S=fe.T,q={};q.types=S!==null?S.types:null,fe.T=q,Mu(e,!1,n,o);try{var Q=m(),le=fe.S;if(le!==null&&le(q,Q),Q!==null&&typeof Q=="object"&&typeof Q.then=="function"){var ce=xx(Q,c);go(e,n,ce,mn(e))}else go(e,n,c,mn(e))}catch(me){go(e,n,{then:function(){},status:"rejected",reason:me},mn())}finally{ge.p=g,S!==null&&q.types!==null&&(S.types=q.types),fe.T=S}}function Sx(){}function Su(e,n,o,c){if(e.tag!==5)throw Error(l(476));var m=fp(e).queue;up(e,m,n,Re,o===null?Sx:function(){return hp(e),o(c)})}function fp(e){var n=e.memoizedState;if(n!==null)return n;n={memoizedState:Re,baseState:Re,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:ua,lastRenderedState:Re},next:null};var o={};return n.next={memoizedState:o,baseState:o,baseQueue:null,queue:{pending:null,lanes:0,dispatch:null,lastRenderedReducer:ua,lastRenderedState:o},next:null},e.memoizedState=n,e=e.alternate,e!==null&&(e.memoizedState=n),n}function hp(e){var n=fp(e);n.next===null&&(n=e.alternate.memoizedState),go(e,n.next.queue,{},mn())}function Nu(){return Et(js)}function dp(){return pt().memoizedState}function mp(){return pt().memoizedState}function Nx(e){for(var n=e.return;n!==null;){switch(n.tag){case 24:case 3:var o=mn();e=Ca(o);var c=Ea(n,e,o);c!==null&&(Ft(c,n,o),uo(c,n,o)),n={cache:tu()},e.payload=n;return}n=n.return}}function Mx(e,n,o){var c=mn();o={lane:c,revertLane:0,gesture:null,action:o,hasEagerState:!1,eagerState:null,next:null},Fi(e)?yp(n,o):(o=Qc(e,n,o,c),o!==null&&(Ft(o,e,c),gp(o,n,c)))}function pp(e,n,o){var c=mn();go(e,n,o,c)}function go(e,n,o,c){var m={lane:c,revertLane:0,gesture:null,action:o,hasEagerState:!1,eagerState:null,next:null};if(Fi(e))yp(n,m);else{var g=e.alternate;if(e.lanes===0&&(g===null||g.lanes===0)&&(g=n.lastRenderedReducer,g!==null))try{var S=n.lastRenderedState,q=g(S,o);if(m.hasEagerState=!0,m.eagerState=q,cn(q,S))return zi(e,n,m,0),st===null&&Mi(),!1}catch{}if(o=Qc(e,n,m,c),o!==null)return Ft(o,e,c),gp(o,n,c),!0}return!1}function Mu(e,n,o,c){if(c={lane:2,revertLane:vf(),gesture:null,action:c,hasEagerState:!1,eagerState:null,next:null},Fi(e)){if(n)throw Error(l(479))}else n=Qc(e,o,c,2),n!==null&&Ft(n,e,2)}function Fi(e){var n=e.alternate;return e===Oe||n!==null&&n===Oe}function yp(e,n){ls=Zi=!0;var o=e.pending;o===null?n.next=n:(n.next=o.next,o.next=n),e.pending=n}function gp(e,n,o){if((o&4194048)!==0){var c=n.lanes;c&=e.pendingLanes,o|=c,n.lanes=o,wd(e,o)}}var Pi={readContext:Et,use:Ki,useCallback:ht,useContext:ht,useEffect:ht,useImperativeHandle:ht,useLayoutEffect:ht,useInsertionEffect:ht,useMemo:ht,useReducer:ht,useRef:ht,useState:ht,useDebugValue:ht,useDeferredValue:ht,useTransition:ht,useSyncExternalStore:ht,useId:ht,useHostTransitionStatus:ht,useFormState:ht,useActionState:ht,useOptimistic:ht,useMemoCache:ht,useCacheRefresh:ht,useEffectEvent:ht},wp={readContext:Et,use:Ki,useCallback:function(e,n){return Bt().memoizedState=[e,n===void 0?null:n],e},useContext:Et,useEffect:tp,useImperativeHandle:function(e,n,o){o=o!=null?o.concat([e]):null,Wi(4194308,4,sp.bind(null,n,e),o)},useLayoutEffect:function(e,n){return Wi(4194308,4,e,n)},useInsertionEffect:function(e,n){Wi(4,2,e,n)},useMemo:function(e,n){var o=Bt();n=n===void 0?null:n;var c=e();if($l){ba(!0);try{e()}finally{ba(!1)}}return o.memoizedState=[c,n],c},useReducer:function(e,n,o){var c=Bt();if(o!==void 0){var m=o(n);if($l){ba(!0);try{o(n)}finally{ba(!1)}}}else m=n;return c.memoizedState=c.baseState=m,e={pending:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:m},c.queue=e,e=e.dispatch=Mx.bind(null,Oe,e),[c.memoizedState,e]},useRef:function(e){var n=Bt();return e={current:e},n.memoizedState=e},useState:function(e){e=bu(e);var n=e.queue,o=pp.bind(null,Oe,n);return n.dispatch=o,[e.memoizedState,o]},useDebugValue:_u,useDeferredValue:function(e,n){var o=Bt();return ju(o,e,n)},useTransition:function(){var e=bu(!1);return e=up.bind(null,Oe,e.queue,!0,!1),Bt().memoizedState=e,[!1,e]},useSyncExternalStore:function(e,n,o){var c=Oe,m=Bt();if(qe){if(o===void 0)throw Error(l(407));o=o()}else{if(o=n(),st===null)throw Error(l(349));(Be&127)!==0||Hm(c,n,o)}m.memoizedState=o;var g={value:o,getSnapshot:n};return m.queue=g,tp(Bm.bind(null,c,g,e),[e]),c.flags|=2048,os(9,{destroy:void 0},Lm.bind(null,c,g,o,n),null),o},useId:function(){var e=Bt(),n=st.identifierPrefix;if(qe){var o=Yn,c=Bn;o=(c&~(1<<32-on(c)-1)).toString(32)+o,n="_"+n+"R_"+o,o=Qi++,0<o&&(n+="H"+o.toString(32)),n+="_"}else o=bx++,n="_"+n+"r_"+o.toString(32)+"_";return e.memoizedState=n},useHostTransitionStatus:Nu,useFormState:Wm,useActionState:Wm,useOptimistic:function(e){var n=Bt();n.memoizedState=n.baseState=e;var o={pending:null,lanes:0,dispatch:null,lastRenderedReducer:null,lastRenderedState:null};return n.queue=o,n=Mu.bind(null,Oe,!0,o),o.dispatch=n,[e,n]},useMemoCache:wu,useCacheRefresh:function(){return Bt().memoizedState=Nx.bind(null,Oe)},useEffectEvent:function(e){var n=Bt(),o={impl:e};return n.memoizedState=o,function(){if((Je&2)!==0)throw Error(l(440));return o.impl.apply(void 0,arguments)}}},vp={readContext:Et,use:Ki,useCallback:ip,useContext:Et,useEffect:ku,useImperativeHandle:op,useInsertionEffect:ap,useLayoutEffect:lp,useMemo:rp,useReducer:Ji,useRef:ep,useState:function(){return Ji(ua)},useDebugValue:_u,useDeferredValue:function(e,n){var o=pt();return cp(o,lt.memoizedState,e,n)},useTransition:function(){var e=Ji(ua)[0],n=pt().memoizedState;return[typeof e=="boolean"?e:yo(e),n]},useSyncExternalStore:Um,useId:dp,useHostTransitionStatus:Nu,useFormState:Im,useActionState:Im,useOptimistic:function(e,n){var o=pt();return Xm(o,lt,e,n)},useMemoCache:wu,useCacheRefresh:mp,useEffectEvent:np},zx={readContext:Et,use:Ki,useCallback:ip,useContext:Et,useEffect:ku,useImperativeHandle:op,useInsertionEffect:ap,useLayoutEffect:lp,useMemo:rp,useReducer:xu,useRef:ep,useState:function(){return xu(ua)},useDebugValue:_u,useDeferredValue:function(e,n){var o=pt();return lt===null?ju(o,e,n):cp(o,lt.memoizedState,e,n)},useTransition:function(){var e=xu(ua)[0],n=pt().memoizedState;return[typeof e=="boolean"?e:yo(e),n]},useSyncExternalStore:Um,useId:dp,useHostTransitionStatus:Nu,useFormState:Pm,useActionState:Pm,useOptimistic:function(e,n){var o=pt();return lt!==null?Xm(o,lt,e,n):(o.baseState=e,[e,o.queue.dispatch])},useMemoCache:wu,useCacheRefresh:mp,useEffectEvent:np};function zu(e,n,o,c){n=e.memoizedState,o=o(c,n),o=o==null?n:E({},n,o),e.memoizedState=o,e.lanes===0&&(e.updateQueue.baseState=o)}var Cu={enqueueSetState:function(e,n,o){e=e._reactInternals;var c=mn(),m=Ca(c);m.payload=n,o!=null&&(m.callback=o),n=Ea(e,m,c),n!==null&&(Ft(n,e,c),uo(n,e,c))},enqueueReplaceState:function(e,n,o){e=e._reactInternals;var c=mn(),m=Ca(c);m.tag=1,m.payload=n,o!=null&&(m.callback=o),n=Ea(e,m,c),n!==null&&(Ft(n,e,c),uo(n,e,c))},enqueueForceUpdate:function(e,n){e=e._reactInternals;var o=mn(),c=Ca(o);c.tag=2,n!=null&&(c.callback=n),n=Ea(e,c,o),n!==null&&(Ft(n,e,o),uo(n,e,o))}};function xp(e,n,o,c,m,g,S){return e=e.stateNode,typeof e.shouldComponentUpdate=="function"?e.shouldComponentUpdate(c,g,S):n.prototype&&n.prototype.isPureReactComponent?!no(o,c)||!no(m,g):!0}function bp(e,n,o,c){e=n.state,typeof n.componentWillReceiveProps=="function"&&n.componentWillReceiveProps(o,c),typeof n.UNSAFE_componentWillReceiveProps=="function"&&n.UNSAFE_componentWillReceiveProps(o,c),n.state!==e&&Cu.enqueueReplaceState(n,n.state,null)}function kl(e,n){var o=n;if("ref"in n){o={};for(var c in n)c!=="ref"&&(o[c]=n[c])}if(e=e.defaultProps){o===n&&(o=E({},o));for(var m in e)o[m]===void 0&&(o[m]=e[m])}return o}function $p(e){Ni(e)}function kp(e){console.error(e)}function _p(e){Ni(e)}function er(e,n){try{var o=e.onUncaughtError;o(n.value,{componentStack:n.stack})}catch(c){setTimeout(function(){throw c})}}function jp(e,n,o){try{var c=e.onCaughtError;c(o.value,{componentStack:o.stack,errorBoundary:n.tag===1?n.stateNode:null})}catch(m){setTimeout(function(){throw m})}}function Eu(e,n,o){return o=Ca(o),o.tag=3,o.payload={element:null},o.callback=function(){er(e,n)},o}function Sp(e){return e=Ca(e),e.tag=3,e}function Np(e,n,o,c){var m=o.type.getDerivedStateFromError;if(typeof m=="function"){var g=c.value;e.payload=function(){return m(g)},e.callback=function(){jp(n,o,c)}}var S=o.stateNode;S!==null&&typeof S.componentDidCatch=="function"&&(e.callback=function(){jp(n,o,c),typeof m!="function"&&(Ha===null?Ha=new Set([this]):Ha.add(this));var q=c.stack;this.componentDidCatch(c.value,{componentStack:q!==null?q:""})})}function Cx(e,n,o,c,m){if(o.flags|=32768,c!==null&&typeof c=="object"&&typeof c.then=="function"){if(n=o.alternate,n!==null&&pl(n,o,m,!0),o=Tt.current,o!==null){switch(o.tag){case 31:case 13:case 19:return Dt===null?br():o.alternate===null&&dt===0&&(dt=3),o.flags&=-257,o.flags|=65536,o.lanes=m,c===Li?o.flags|=16384:(n=o.updateQueue,n===null?o.updateQueue=new Set([c]):n.add(c),yf(e,c,m)),!1;case 22:return o.flags|=65536,c===Li?o.flags|=16384:(n=o.updateQueue,n===null?(n={transitions:null,markerInstances:null,retryQueue:new Set([c])},o.updateQueue=n):(o=n.retryQueue,o===null?n.retryQueue=new Set([c]):o.add(c)),yf(e,c,m)),!1}throw Error(l(435,o.tag))}return yf(e,c,m),br(),!1}if(qe)return n=Tt.current,n!==null?((n.flags&65536)===0&&(n.flags|=256),n.flags|=65536,n.lanes=m,c!==Ic&&(e=Error(l(422),{cause:c}),so($n(e,o)))):(c!==Ic&&(n=Error(l(423),{cause:c}),so($n(n,o))),e=e.current.alternate,e.flags|=65536,m&=-m,e.lanes|=m,c=$n(c,o),m=Eu(e.stateNode,c,m),iu(e,m),dt!==4&&(dt=2)),!1;var g=Error(l(520),{cause:c});if(g=$n(g,o),jo===null?jo=[g]:jo.push(g),dt!==4&&(dt=2),n===null)return!0;c=$n(c,o),o=n;do{switch(o.tag){case 3:return o.flags|=65536,e=m&-m,o.lanes|=e,e=Eu(o.stateNode,c,e),iu(o,e),!1;case 1:if(n=o.type,g=o.stateNode,(o.flags&128)===0&&(typeof n.getDerivedStateFromError=="function"||g!==null&&typeof g.componentDidCatch=="function"&&(Ha===null||!Ha.has(g))))return o.flags|=65536,m&=-m,o.lanes|=m,m=Sp(m),Np(m,e,o,c),iu(o,m),!1;break;case 22:if(o.memoizedState!==null)return o.flags|=65536,!1}o=o.return}while(o!==null);return!1}var Tu=Error(l(461)),vt=!1;function $t(e,n,o,c){n.child=e===null?Em(n,null,o,c):bl(n,e.child,o,c)}function Mp(e,n,o,c,m){o=o.render;var g=n.ref;if("ref"in c){var S={};for(var q in c)q!=="ref"&&(S[q]=c[q])}else S=c;return yl(n),c=mu(e,n,o,S,g,m),q=pu(),e!==null&&!vt?(yu(e,n,m),fa(e,n,m)):(qe&&q&&Oi(n),n.flags|=1,$t(e,n,c,m),n.child)}function zp(e,n,o,c,m){if(e===null){var g=o.type;return typeof g=="function"&&!Vc(g)&&g.defaultProps===void 0&&o.compare===null?(n.tag=15,n.type=g,Cp(e,n,g,c,m)):(e=Ei(o.type,null,c,n,n.mode,m),e.ref=n.ref,e.return=n,n.child=e)}if(g=e.child,!Lu(e,m)){var S=g.memoizedProps;if(o=o.compare,o=o!==null?o:no,o(S,c)&&e.ref===n.ref)return fa(e,n,m)}return n.flags|=1,e=sa(g,c),e.ref=n.ref,e.return=n,n.child=e}function Cp(e,n,o,c,m){if(e!==null){var g=e.memoizedProps;if(no(g,c)&&e.ref===n.ref)if(vt=!1,n.pendingProps=c=g,Lu(e,m))(e.flags&131072)!==0&&(vt=!0);else return n.lanes=e.lanes,fa(e,n,m)}return Ou(e,n,o,c,m)}function Ep(e,n,o,c){var m=c.children,g=e!==null?e.memoizedState:null;if(e===null&&n.stateNode===null&&(n.stateNode={_visibility:1,_pendingMarkers:null,_retryCache:null,_transitions:null}),c.mode==="hidden"){if((n.flags&128)!==0){if(g=g!==null?g.baseLanes|o:o,e!==null){for(c=n.child=e.child,m=0;c!==null;)m=m|c.lanes|c.childLanes,c=c.sibling;c=m&~g}else c=0,n.child=null;return Tp(e,n,g,o,c)}if((o&536870912)!==0)n.memoizedState={baseLanes:0,cachePool:null},e!==null&&Ui(n,g!==null?g.cachePool:null),g!==null?Am(n,g):cu(),qm(n);else return c=n.lanes=536870912,Tp(e,n,g!==null?g.baseLanes|o:o,o,c)}else g!==null?(Ui(n,g.cachePool),Am(n,g),Aa(),n.memoizedState=null):(e!==null&&Ui(n,null),cu(),Aa());return $t(e,n,m,o),n.child}function wo(e,n){return e!==null&&e.tag===22||n.stateNode!==null||(n.stateNode={_visibility:1,_pendingMarkers:null,_retryCache:null,_transitions:null}),n.sibling}function Tp(e,n,o,c,m){var g=au();return g=g===null?null:{parent:gt._currentValue,pool:g},n.memoizedState={baseLanes:o,cachePool:g},e!==null&&Ui(n,null),cu(),qm(n),e!==null&&pl(e,n,c,!0),n.childLanes=m,null}function tr(e,n){return n=nr({mode:n.mode,children:n.children},e.mode),n.ref=e.ref,e.child=n,n.return=e,n}function Op(e,n,o){return bl(n,e.child,null,o),e=tr(n,n.pendingProps),e.flags|=2,un(n),n.memoizedState=null,e}function Ex(e,n,o){var c=n.pendingProps,m=(n.flags&128)!==0;if(n.flags&=-129,e===null){if(qe){if(c.mode==="hidden")return e=tr(n,c),n.lanes=536870912,e.memoizedState={baseLanes:0,cachePool:null},wo(null,e);if(fu(n),(e=ot)?(e=sg(e,jn),e=e!==null&&e.data==="&"?e:null,e!==null&&(n.memoizedState={dehydrated:e,treeContext:_a!==null?{id:Bn,overflow:Yn}:null,retryLane:536870912,hydrationErrors:null},o=ym(e),o.return=n,n.child=o,_t=n,ot=null)):e=null,e===null)throw Sa(n);return n.lanes=536870912,null}return tr(n,c)}var g=e.memoizedState;if(g!==null){var S=g.dehydrated;if(fu(n),m)if(n.flags&256)n.flags&=-257,n=Op(e,n,o);else if(n.memoizedState!==null)n.child=e.child,n.flags|=128,n=null;else throw Error(l(558));else if(vt||pl(e,n,o,!1),m=(o&e.childLanes)!==0,vt||m){if(Ta.current===null){if(c=st,c!==null&&(S=vd(c,o),S!==0&&S!==g.retryLane))throw g.retryLane=S,fl(e,S),Ft(c,e,S),Tu;br()}n=Op(e,n,o)}else e=g.treeContext,ot=Nn(S.nextSibling),_t=n,qe=!0,ja=null,jn=!1,e!==null&&vm(n,e),n=tr(n,c),n.flags|=134221824;return n}return e=sa(e.child,{mode:c.mode,children:c.children}),e.ref=n.ref,n.child=e,e.return=n,e}function is(e,n){var o=n.ref;if(o===null)e!==null&&e.ref!==null&&(n.flags|=4194816);else{if(typeof o!="function"&&typeof o!="object")throw Error(l(284));(e===null||e.ref!==o)&&(n.flags|=4194816)}}function Ou(e,n,o,c,m){return yl(n),o=mu(e,n,o,c,void 0,m),c=pu(),e!==null&&!vt?(yu(e,n,m),fa(e,n,m)):(qe&&c&&Oi(n),n.flags|=1,$t(e,n,o,m),n.child)}function Ap(e,n,o,c,m,g){return yl(n),n.updateQueue=null,o=Dm(n,c,o,m),Rm(e),c=pu(),e!==null&&!vt?(yu(e,n,g),fa(e,n,g)):(qe&&c&&Oi(n),n.flags|=1,$t(e,n,o,g),n.child)}function qp(e,n,o,c,m){if(yl(n),n.stateNode===null){var g=Il,S=o.contextType;typeof S=="object"&&S!==null&&(g=Et(S)),g=new o(c,g),n.memoizedState=g.state!==null&&g.state!==void 0?g.state:null,g.updater=Cu,n.stateNode=g,g._reactInternals=n,g=n.stateNode,g.props=c,g.state=n.memoizedState,g.refs={},su(n),S=o.contextType,g.context=typeof S=="object"&&S!==null?Et(S):Il,g.state=n.memoizedState,S=o.getDerivedStateFromProps,typeof S=="function"&&(zu(n,o,S,c),g.state=n.memoizedState),typeof o.getDerivedStateFromProps=="function"||typeof g.getSnapshotBeforeUpdate=="function"||typeof g.UNSAFE_componentWillMount!="function"&&typeof g.componentWillMount!="function"||(S=g.state,typeof g.componentWillMount=="function"&&g.componentWillMount(),typeof g.UNSAFE_componentWillMount=="function"&&g.UNSAFE_componentWillMount(),S!==g.state&&Cu.enqueueReplaceState(g,g.state,null),ho(n,c,g,m),fo(),g.state=n.memoizedState),typeof g.componentDidMount=="function"&&(n.flags|=4194308),c=!0}else if(e===null){g=n.stateNode;var q=n.memoizedProps,Q=kl(o,q);g.props=Q;var le=g.context,ce=o.contextType;S=Il,typeof ce=="object"&&ce!==null&&(S=Et(ce));var me=o.getDerivedStateFromProps;ce=typeof me=="function"||typeof g.getSnapshotBeforeUpdate=="function",q=n.pendingProps!==q,ce||typeof g.UNSAFE_componentWillReceiveProps!="function"&&typeof g.componentWillReceiveProps!="function"||(q||le!==S)&&bp(n,g,c,S),za=!1;var ee=n.memoizedState;g.state=ee,ho(n,c,g,m),fo(),le=n.memoizedState,q||ee!==le||za?(typeof me=="function"&&(zu(n,o,me,c),le=n.memoizedState),(Q=za||xp(n,o,Q,c,ee,le,S))?(ce||typeof g.UNSAFE_componentWillMount!="function"&&typeof g.componentWillMount!="function"||(typeof g.componentWillMount=="function"&&g.componentWillMount(),typeof g.UNSAFE_componentWillMount=="function"&&g.UNSAFE_componentWillMount()),typeof g.componentDidMount=="function"&&(n.flags|=4194308)):(typeof g.componentDidMount=="function"&&(n.flags|=4194308),n.memoizedProps=c,n.memoizedState=le),g.props=c,g.state=le,g.context=S,c=Q):(typeof g.componentDidMount=="function"&&(n.flags|=4194308),c=!1)}else{g=n.stateNode,ou(e,n),S=n.memoizedProps,ce=kl(o,S),g.props=ce,me=n.pendingProps,ee=g.context,le=o.contextType,Q=Il,typeof le=="object"&&le!==null&&(Q=Et(le)),q=o.getDerivedStateFromProps,(le=typeof q=="function"||typeof g.getSnapshotBeforeUpdate=="function")||typeof g.UNSAFE_componentWillReceiveProps!="function"&&typeof g.componentWillReceiveProps!="function"||(S!==me||ee!==Q)&&bp(n,g,c,Q),za=!1,ee=n.memoizedState,g.state=ee,ho(n,c,g,m),fo();var re=n.memoizedState;S!==me||ee!==re||za||e!==null&&e.dependencies!==null&&Ri(e.dependencies)?(typeof q=="function"&&(zu(n,o,q,c),re=n.memoizedState),(ce=za||xp(n,o,ce,c,ee,re,Q)||e!==null&&e.dependencies!==null&&Ri(e.dependencies))?(le||typeof g.UNSAFE_componentWillUpdate!="function"&&typeof g.componentWillUpdate!="function"||(typeof g.componentWillUpdate=="function"&&g.componentWillUpdate(c,re,Q),typeof g.UNSAFE_componentWillUpdate=="function"&&g.UNSAFE_componentWillUpdate(c,re,Q)),typeof g.componentDidUpdate=="function"&&(n.flags|=4),typeof g.getSnapshotBeforeUpdate=="function"&&(n.flags|=1024)):(typeof g.componentDidUpdate!="function"||S===e.memoizedProps&&ee===e.memoizedState||(n.flags|=4),typeof g.getSnapshotBeforeUpdate!="function"||S===e.memoizedProps&&ee===e.memoizedState||(n.flags|=1024),n.memoizedProps=c,n.memoizedState=re),g.props=c,g.state=re,g.context=Q,c=ce):(typeof g.componentDidUpdate!="function"||S===e.memoizedProps&&ee===e.memoizedState||(n.flags|=4),typeof g.getSnapshotBeforeUpdate!="function"||S===e.memoizedProps&&ee===e.memoizedState||(n.flags|=1024),c=!1)}return g=c,is(e,n),c=(n.flags&128)!==0,g||c?(g=n.stateNode,o=c&&typeof o.getDerivedStateFromError!="function"?null:g.render(),n.flags|=1,e!==null&&c?(n.child=bl(n,e.child,null,m),n.child=bl(n,null,o,m)):$t(e,n,o,m),n.memoizedState=g.state,e=n.child):e=fa(e,n,m),e}function Rp(e,n,o,c){return dl(),n.flags|=256,$t(e,n,o,c),n.child}var Au={dehydrated:null,treeContext:null,retryLane:0,hydrationErrors:null};function qu(e){return{baseLanes:e,cachePool:jm()}}function Ru(e,n,o){return e=e!==null?e.childLanes&~o:0,n&&(e|=dn),e}function Dp(e,n,o){var c=n.pendingProps,m=!1,g=(n.flags&128)!==0,S;if((S=g)||(S=e!==null&&e.memoizedState===null?!1:(Ot.current&2)!==0),S&&(m=!0,n.flags&=-129),S=(n.flags&32)!==0,n.flags&=-33,e===null){if(qe){if(m?Oa(n):Aa(),(e=ot)?(e=sg(e,jn),e=e!==null&&e.data!=="&"?e:null,e!==null&&(n.memoizedState={dehydrated:e,treeContext:_a!==null?{id:Bn,overflow:Yn}:null,retryLane:536870912,hydrationErrors:null},o=ym(e),o.return=n,n.child=o,_t=n,ot=null)):e=null,e===null)throw Sa(n);return Rf(e)?n.lanes=32:n.lanes=536870912,null}return g=c.children,c=c.fallback,m?(Aa(),m=n.mode,g=nr({mode:"hidden",children:g},m),c=hl(c,m,o,null),g.return=n,c.return=n,g.sibling=c,n.child=g,c=n.child,c.memoizedState=qu(o),c.childLanes=Ru(e,S,o),n.memoizedState=Au,wo(null,c)):(Oa(n),Du(n,g))}var q=e.memoizedState;if(q!==null){var Q=q.dehydrated;if(Q!==null)return Tx(e,n,g,S,c,Q,q,o)}return m?(Aa(),m=c.fallback,g=n.mode,q=e.child,Q=q.sibling,c=sa(q,{mode:"hidden",children:c.children}),c.subtreeFlags=q.subtreeFlags&1206910976,Q!==null?m=sa(Q,m):(m=hl(m,g,o,null),m.flags|=2),m.return=n,c.return=n,c.sibling=m,n.child=c,wo(null,c),c=n.child,m=e.child.memoizedState,m===null?m=qu(o):(g=m.cachePool,g!==null?(q=gt._currentValue,g=g.parent!==q?{parent:q,pool:q}:g):g=jm(),m={baseLanes:m.baseLanes|o,cachePool:g}),c.memoizedState=m,c.childLanes=Ru(e,S,o),n.memoizedState=Au,wo(e.child,c)):(Oa(n),o=e.child,e=o.sibling,o=sa(o,{mode:"visible",children:c.children}),o.return=n,o.sibling=null,e!==null&&(S=n.deletions,S===null?(n.deletions=[e],n.flags|=16):S.push(e)),n.child=o,n.memoizedState=null,o)}function Du(e,n){return n=nr({mode:"visible",children:n},e.mode),n.return=e,e.child=n}function nr(e,n){return e=Kt(22,e,null,n),e.lanes=0,e}function ar(e,n,o){return bl(n,e.child,null,o),e=Du(n,n.pendingProps.children),e.flags|=2,n.memoizedState=null,e}function Tx(e,n,o,c,m,g,S,q){if(o)return n.flags&256?(Oa(n),n.flags&=-257,ar(e,n,q)):n.memoizedState!==null?(Aa(),n.child=e.child,n.flags|=128,null):(Aa(),g=m.fallback,S=n.mode,m=nr({mode:"visible",children:m.children},S),g=hl(g,S,q,null),g.flags|=2,m.return=n,g.return=n,m.sibling=g,n.child=m,bl(n,e.child,null,q),m=n.child,m.memoizedState=qu(q),m.childLanes=Ru(e,c,q),n.memoizedState=Au,wo(null,m));if(Oa(n),Rf(g)){if(c=g.nextSibling&&g.nextSibling.dataset,c)var Q=c.dgst;return c=Q,c!==""&&(m=Error(l(419)),m.stack="",m.digest=c,so({value:m,source:null,stack:null})),ar(e,n,q)}if(vt||pl(e,n,q,!1),c=(q&e.childLanes)!==0,vt||c){if(Ta.current!==null)return ar(e,n,q);if(c=st,c!==null&&(m=vd(c,q),m!==0&&m!==S.retryLane))throw S.retryLane=m,fl(e,m),Ft(c,e,m),Tu;return qf(g)||br(),ar(e,n,q)}return qf(g)?(n.flags|=192,n.child=e.child,null):(e=S.treeContext,ot=Nn(g.nextSibling),_t=n,qe=!0,ja=null,jn=!1,e!==null&&vm(n,e),n=Du(n,m.children),n.flags|=134221824,n)}function Up(e,n,o){e.lanes|=n;var c=e.alternate;c!==null&&(c.lanes|=n),qi(e.return,n,o)}function Hp(e){for(var n=null;e!==null;){var o=e.alternate;o!==null&&Xi(o)===null&&(n=e),e=e.sibling}return n}function lr(e,n,o,c,m,g){var S=e.memoizedState;S===null?e.memoizedState={isBackwards:n,rendering:null,renderingStartTime:0,last:c,tail:o,tailMode:m,treeForkCount:g}:(S.isBackwards=n,S.rendering=null,S.renderingStartTime=0,S.last=c,S.tail=o,S.tailMode=m,S.treeForkCount=g)}function Uu(e){var n=e.child;for(e.child=null;n!==null;){var o=n.sibling;n.sibling=e.child,e.child=n,n=o}}function Hu(e,n,o){var c=n.pendingProps,m=c.revealOrder,g=c.tail;c=c.children;var S=Ot.current;if(n.flags&128)return mo(n,S),null;var q=(S&2)!==0;if(q?(S=S&1|2,n.flags|=128):S&=1,mo(n,S),m==="backwards"&&e!==null?(Uu(e),$t(e,n,c,o),Uu(e)):$t(e,n,c,o),c=qe?lo:0,!q&&e!==null&&(e.flags&128)!==0)e:for(e=n.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&Up(e,o,n);else if(e.tag===19)Up(e,o,n);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===n)break e;for(;e.sibling===null;){if(e.return===null||e.return===n)break e;e=e.return}e.sibling.return=e.return,e=e.sibling}switch(m){case"backwards":o=Hp(n.child),o===null?(m=n.child,n.child=null):(m=o.sibling,o.sibling=null,Uu(n)),lr(n,!0,m,null,g,c);break;case"unstable_legacy-backwards":for(o=null,m=n.child,n.child=null;m!==null;){if(e=m.alternate,e!==null&&Xi(e)===null){n.child=m;break}e=m.sibling,m.sibling=o,o=m,m=e}lr(n,!0,o,null,g,c);break;case"together":lr(n,!1,null,null,void 0,c);break;case"independent":n.memoizedState=null;break;default:o=Hp(n.child),o===null?(m=n.child,n.child=null):(m=o.sibling,o.sibling=null),lr(n,!1,m,o,g,c)}return n.child}function Lp(e,n,o){var c=n.pendingProps;return Na(n,n.type,c.value),$t(e,n,c.children,o),n.child}function fa(e,n,o){if(e!==null&&(n.dependencies=e.dependencies),Ua|=n.lanes,(o&n.childLanes)===0)if(e!==null){if(pl(e,n,o,!1),(o&n.childLanes)===0)return null}else return null;if(e!==null&&n.child!==e.child)throw Error(l(153));if(n.child!==null){for(e=n.child,o=sa(e,e.pendingProps),n.child=o,o.return=n;e.sibling!==null;)e=e.sibling,o=o.sibling=sa(e,e.pendingProps),o.return=n;o.sibling=null}return n.child}function Lu(e,n){return(e.lanes&n)!==0?!0:(e=e.dependencies,!!(e!==null&&Ri(e)))}function Ox(e,n,o){switch(n.tag){case 3:we(n,n.stateNode.containerInfo),Na(n,gt,e.memoizedState.cache),dl();break;case 27:case 5:Ve(n);break;case 4:we(n,n.stateNode.containerInfo);break;case 10:Na(n,n.type,n.memoizedProps.value);break;case 31:if(n.memoizedState!==null)return n.flags|=128,fu(n),null;break;case 13:var c=n.memoizedState;if(c!==null){if(c.dehydrated!==null)return Oa(n),n.flags|=128,null;c=pl(e,n,o,!1);var m=n.child.childLanes;return c||(o&m)!==0?Dp(e,n,o):(Oa(n),e=fa(e,n,o),e!==null?e.sibling:null)}Oa(n);break;case 19:if(n.flags&128)return Hu(e,n,o);if(m=(e.flags&128)!==0,c=(o&n.childLanes)!==0,c||(pl(e,n,o,!1),c=(o&n.childLanes)!==0),m){if(c)return Hu(e,n,o);n.flags|=128}if(m=n.memoizedState,m!==null&&(m.rendering=null,m.tail=null,m.lastEffect=null),mo(n,Ot.current),c)break;return null;case 22:return n.lanes=0,Ep(e,n,o,n.pendingProps);case 24:Na(n,gt,e.memoizedState.cache)}return fa(e,n,o)}function Bp(e,n,o){if(e!==null)if(e.memoizedProps!==n.pendingProps)vt=!0;else{if(!Lu(e,o)&&(n.flags&128)===0)return vt=!1,Ox(e,n,o);vt=(e.flags&131072)!==0}else vt=!1,qe&&(n.flags&1048576)!==0&&wm(n,lo,n.index);switch(n.lanes=0,n.tag){case 16:e:{var c=n.pendingProps;if(e=vl(n.elementType),n.type=e,typeof e=="function")Vc(e)?(c=kl(e,c),n.tag=1,n=qp(null,n,e,c,o)):(n.tag=0,n=Ou(null,n,e,c,o));else{if(e!=null){var m=e.$$typeof;if(m===O){n.tag=11,n=Mp(null,n,e,c,o);break e}else if(m===Z){n.tag=14,n=zp(null,n,e,c,o);break e}else if(m===Y){n.tag=10,n.type=e,n=Lp(null,n,o);break e}}throw n=F(e)||e,Error(l(306,n,""))}}return n;case 0:return Ou(e,n,n.type,n.pendingProps,o);case 1:return c=n.type,m=kl(c,n.pendingProps),qp(e,n,c,m,o);case 3:e:{if(we(n,n.stateNode.containerInfo),e===null)throw Error(l(387));c=n.pendingProps;var g=n.memoizedState;m=g.element,ou(e,n),ho(n,c,null,o);var S=n.memoizedState;if(c=S.cache,Na(n,gt,c),c!==g.cache&&eu(n,[gt],o,!0),fo(),c=S.element,g.isDehydrated)if(g={element:c,isDehydrated:!1,cache:S.cache},n.updateQueue.baseState=g,n.memoizedState=g,n.flags&256){n=Rp(e,n,c,o);break e}else if(c!==m){m=$n(Error(l(424)),n),so(m),n=Rp(e,n,c,o);break e}else for(e=n.stateNode.containerInfo,e.nodeType===9?e=e.body:e=e.nodeName==="HTML"?e.ownerDocument.body:e,ot=Nn(e.firstChild),_t=n,qe=!0,ja=null,jn=!0,o=Em(n,null,c,o),n.child=o;o;)o.flags=o.flags&-3|134221824,o=o.sibling;else{if(dl(),c===m){n=fa(e,n,o);break e}$t(e,n,c,o)}n=n.child}return n;case 26:return is(e,n),e===null?(o=hg(n.type,null,n.pendingProps,null))?n.memoizedState=o:qe||(n.stateNode=Zy(n.type,n.pendingProps,ct.current,n)):n.memoizedState=hg(n.type,e.memoizedProps,n.pendingProps,e.memoizedState),null;case 27:return Ve(n),e===null&&qe&&(c=n.stateNode=rg(n.type,n.pendingProps,ct.current),_t=n,jn=!0,m=ot,Ya(n.type)?(Df=m,ot=Nn(c.firstChild)):ot=m),$t(e,n,n.pendingProps.children,o),is(e,n),e===null&&(n.flags|=4194304),n.child;case 5:return e===null&&qe&&((m=c=ot)&&(c=Nb(c,n.type,n.pendingProps,jn),c!==null?(n.stateNode=c,_t=n,ot=Nn(c.firstChild),jn=!1,m=!0):m=!1),m||Sa(n)),Ve(n),m=n.type,g=n.pendingProps,S=e!==null?e.memoizedProps:null,c=g.children,Mf(m,g)?c=null:S!==null&&Mf(m,S)&&(n.flags|=32),n.memoizedState!==null&&(m=mu(e,n,$x,null,null,o),js._currentValue=m),is(e,n),$t(e,n,c,o),n.child;case 6:return e===null&&qe&&((e=o=ot)&&(o=Mb(o,n.pendingProps,jn),o!==null?(n.stateNode=o,_t=n,ot=null,e=!0):e=!1),e||Sa(n)),null;case 13:return Dp(e,n,o);case 4:return we(n,n.stateNode.containerInfo),c=n.pendingProps,e===null?n.child=bl(n,null,c,o):$t(e,n,c,o),n.child;case 11:return Mp(e,n,n.type,n.pendingProps,o);case 7:return c=n.pendingProps,is(e,n),$t(e,n,c,o),n.child;case 8:return $t(e,n,n.pendingProps.children,o),n.child;case 12:return $t(e,n,n.pendingProps.children,o),n.child;case 10:return Lp(e,n,o);case 9:return m=n.type._context,c=n.pendingProps.children,yl(n),m=Et(m),c=c(m),n.flags|=1,$t(e,n,c,o),n.child;case 14:return zp(e,n,n.type,n.pendingProps,o);case 15:return Cp(e,n,n.type,n.pendingProps,o);case 19:return Hu(e,n,o);case 31:return Ex(e,n,o);case 22:return Ep(e,n,o,n.pendingProps);case 24:return yl(n),c=Et(gt),e===null?(m=au(),m===null&&(m=st,g=tu(),m.pooledCache=g,g.refCount++,g!==null&&(m.pooledCacheLanes|=o),m=g),n.memoizedState={parent:c,cache:m},su(n),Na(n,gt,m)):((e.lanes&o)!==0&&(ou(e,n),ho(n,null,null,o),fo()),m=e.memoizedState,g=n.memoizedState,m.parent!==c?(m={parent:c,cache:c},n.memoizedState=m,n.lanes===0&&(n.memoizedState=n.updateQueue.baseState=m),Na(n,gt,c)):(c=g.cache,Na(n,gt,c),c!==m.cache&&eu(n,[gt],o,!0))),$t(e,n,n.pendingProps.children,o),n.child;case 30:return n.stateNode===null&&(n.stateNode={autoName:null,paired:null,clones:null,ref:null}),c=n.pendingProps,c.name!=null&&c.name!=="auto"?n.flags|=e===null?18882560:18874368:qe&&Oi(n),e!==null&&e.memoizedProps.name!==c.name?n.flags|=4194816:is(e,n),$t(e,n,c.children,o),n.child;case 29:throw n.pendingProps}throw Error(l(156,n.tag))}function ha(e){e.flags|=4}function Bu(e,n,o,c,m){var g;if((g=(e.mode&32)!==0)&&(g=o===null?yg(n,c):yg(n,c)&&(c.src!==o.src||c.srcSet!==o.srcSet)),g){if(e.flags|=16777216,(m&335544128)===m)if(e.stateNode.complete)e.flags|=8192;else if($y())e.flags|=8192;else throw xl=Li,lu}else e.flags&=-16777217}function Yp(e,n){if(n.type!=="stylesheet"||(n.state.loading&4)!==0)e.flags&=-16777217;else if(e.flags|=16777216,!gg(n))if($y())e.flags|=8192;else throw xl=Li,lu}function sr(e,n){n!==null&&(e.flags|=4),e.flags&16384&&(n=e.tag!==22?yd():536870912,e.lanes|=n,hs|=n)}function vo(e,n){if(!qe)switch(e.tailMode){case"visible":break;case"collapsed":for(var o=e.tail,c=null;o!==null;)o.alternate!==null&&(c=o),o=o.sibling;c===null?n||e.tail===null?e.tail=null:e.tail.sibling=null:c.sibling=null;break;default:for(n=e.tail,o=null;n!==null;)n.alternate!==null&&(o=n),n=n.sibling;o===null?e.tail=null:o.sibling=null}}function it(e){var n=e.alternate!==null&&e.alternate.child===e.child,o=0,c=0;if(n)for(var m=e.child;m!==null;)o|=m.lanes|m.childLanes,c|=m.subtreeFlags&1206910976,c|=m.flags&1206910976,m.return=e,m=m.sibling;else for(m=e.child;m!==null;)o|=m.lanes|m.childLanes,c|=m.subtreeFlags,c|=m.flags,m.return=e,m=m.sibling;return e.subtreeFlags|=c,e.childLanes=o,n}function Ax(e,n,o){var c=n.pendingProps;switch(Wc(n),n.tag){case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return it(n),null;case 1:return it(n),null;case 3:return o=n.stateNode,c=null,e!==null&&(c=e.memoizedState.cache),n.memoizedState.cache!==c&&(n.flags|=2048),ra(gt),Te(),o.pendingContext&&(o.context=o.pendingContext,o.pendingContext=null),(e===null||e.child===null)&&(es(n)?ha(n):e===null||e.memoizedState.isDehydrated&&(n.flags&256)===0||(n.flags|=1024,Fc())),it(n),null;case 26:var m=n.type,g=n.memoizedState;return e===null?(ha(n),g!==null?(it(n),Yp(n,g)):(it(n),Bu(n,m,null,c,o))):g?g!==e.memoizedState?(ha(n),it(n),Yp(n,g)):(it(n),n.flags&=-16777217):(e=e.memoizedProps,e!==c&&ha(n),it(n),Bu(n,m,e,c,o)),null;case 27:if(De(n),o=ct.current,m=n.type,e!==null&&n.stateNode!=null)e.memoizedProps!==c&&ha(n);else{if(!c){if(n.stateNode===null)throw Error(l(166));return it(n),n.subtreeFlags&=-33554433,null}e=Ge.current,es(n)?xm(n):(e=rg(m,c,o),n.stateNode=e,ha(n))}return it(n),n.subtreeFlags&=-33554433,null;case 5:if(De(n),m=n.type,e!==null&&n.stateNode!=null)e.memoizedProps!==c&&ha(n);else{if(!c){if(n.stateNode===null)throw Error(l(166));return it(n),n.subtreeFlags&=-33554433,null}if(g=Ge.current,es(n))xm(n);else{var S=Co(ct.current);switch(g){case 1:g=S.createElementNS("http://www.w3.org/2000/svg",m);break;case 2:g=S.createElementNS("http://www.w3.org/1998/Math/MathML",m);break;default:switch(m){case"svg":g=S.createElementNS("http://www.w3.org/2000/svg",m);break;case"math":g=S.createElementNS("http://www.w3.org/1998/Math/MathML",m);break;case"script":g=S.createElement("div"),g.innerHTML="<script><\/script>",g=g.removeChild(g.firstChild);break;case"select":g=typeof c.is=="string"?S.createElement("select",{is:c.is}):S.createElement("select"),c.multiple?g.multiple=!0:c.size&&(g.size=c.size);break;default:g=typeof c.is=="string"?S.createElement(m,{is:c.is}):S.createElement(m)}}g[Ct]=n,g[Vt]=c;e:for(S=n.child;S!==null;){if(S.tag===5||S.tag===6)g.appendChild(S.stateNode);else if(S.tag!==4&&S.tag!==27&&S.child!==null){S.child.return=S,S=S.child;continue}if(S===n)break e;for(;S.sibling===null;){if(S.return===null||S.return===n)break e;S=S.return}S.sibling.return=S.return,S=S.sibling}n.stateNode=g;e:switch(qt(g,m,c),m){case"button":case"input":case"select":case"textarea":c=!!c.autoFocus;break e;case"img":c=!0;break e;default:c=!1}c&&ha(n)}}return it(n),n.subtreeFlags&=-33554433,Bu(n,n.type,e===null?null:e.memoizedProps,n.pendingProps,o),null;case 6:if(e&&n.stateNode!=null)e.memoizedProps!==c&&ha(n);else{if(typeof c!="string"&&n.stateNode===null)throw Error(l(166));if(e=ct.current,es(n)){if(e=n.stateNode,o=n.memoizedProps,c=null,m=_t,m!==null)switch(m.tag){case 27:case 5:c=m.memoizedProps}e[Ct]=n,e=!!(e.nodeValue===o||c!==null&&c.suppressHydrationWarning===!0||By(e.nodeValue,o)),e||Sa(n,!0)}else e=Co(e).createTextNode(c),e[Ct]=n,n.stateNode=e}return it(n),null;case 31:if(o=n.memoizedState,e===null||e.memoizedState!==null){if(c=es(n),o!==null){if(e===null){if(!c)throw Error(l(318));if(e=n.memoizedState,e=e!==null?e.dehydrated:null,!e)throw Error(l(557));e[Ct]=n}else dl(),(n.flags&128)===0&&(n.memoizedState=null),n.flags|=4;it(n),e=!1}else o=Fc(),e!==null&&e.memoizedState!==null&&(e.memoizedState.hydrationErrors=o),e=!0;if(!e)return n.flags&256?(un(n),n):(un(n),null);if((n.flags&128)!==0)throw Error(l(558))}return it(n),null;case 13:if(c=n.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(m=es(n),c!==null&&c.dehydrated!==null){if(e===null){if(!m)throw Error(l(318));if(m=n.memoizedState,m=m!==null?m.dehydrated:null,!m)throw Error(l(317));m[Ct]=n}else dl(),(n.flags&128)===0&&(n.memoizedState=null),n.flags|=4;it(n),m=!1}else m=Fc(),e!==null&&e.memoizedState!==null&&(e.memoizedState.hydrationErrors=m),m=!0;if(!m)return n.flags&256?(un(n),n):(un(n),null)}return un(n),(n.flags&128)!==0?(n.lanes=o,n):(o=c!==null,e=e!==null&&e.memoizedState!==null,o&&(c=n.child,m=null,c.alternate!==null&&c.alternate.memoizedState!==null&&c.alternate.memoizedState.cachePool!==null&&(m=c.alternate.memoizedState.cachePool.pool),g=null,c.memoizedState!==null&&c.memoizedState.cachePool!==null&&(g=c.memoizedState.cachePool.pool),g!==m&&(c.flags|=2048)),o!==e&&o&&(n.child.flags|=8192),sr(n,n.updateQueue),it(n),null);case 4:return Te(),e===null&&kf(n.stateNode.containerInfo),n.flags|=67108864,it(n),null;case 10:return ra(n.type),it(n),null;case 19:if(hu(n),c=n.memoizedState,c===null)return it(n),null;if(m=(n.flags&128)!==0,g=c.rendering,g===null)if(m)vo(c,!1);else{if(dt!==0||e!==null&&(e.flags&128)!==0)for(e=n.child;e!==null;){if(g=Xi(e),g!==null){for(n.flags|=128,vo(c,!1),e=g.updateQueue,n.updateQueue=e,sr(n,e),n.subtreeFlags=0,e=o,o=n.child;o!==null;)pm(o,e),o=o.sibling;return mo(n,Ot.current&1|2),qe&&oa(n,c.treeForkCount),n.child}e=e.sibling}c.tail!==null&&ln()>gr&&(n.flags|=128,m=!0,vo(c,!1),n.lanes=4194304)}else{if(!m)if(e=Xi(g),e!==null){if(n.flags|=128,m=!0,e=e.updateQueue,n.updateQueue=e,sr(n,e),vo(c,!0),c.tail===null&&c.tailMode!=="collapsed"&&c.tailMode!=="visible"&&!g.alternate&&!qe)return it(n),null}else 2*ln()-c.renderingStartTime>gr&&o!==536870912&&(n.flags|=128,m=!0,vo(c,!1),n.lanes=4194304);c.isBackwards?(g.sibling=n.child,n.child=g):(e=c.last,e!==null?e.sibling=g:n.child=g,c.last=g)}if(c.tail!==null){e=c.tail;e:{for(o=e;o!==null;){if(o.alternate!==null){o=!1;break e}o=o.sibling}o=!0}return c.rendering=e,c.tail=e.sibling,c.renderingStartTime=ln(),e.sibling=null,g=Ot.current,g=m?g&1|2:g&1,c.tailMode==="visible"||c.tailMode==="collapsed"||!o||qe?mo(n,g):(o=g,Me(Tt,n),Me(Ot,o),Dt===null&&(Dt=n)),qe&&oa(n,c.treeForkCount),e}return it(n),null;case 22:case 23:return un(n),uu(),c=n.memoizedState!==null,e!==null?e.memoizedState!==null!==c&&(n.flags|=8192):c&&(n.flags|=8192),c?(o&536870912)!==0&&(n.flags&128)===0&&(it(n),n.subtreeFlags&6&&(n.flags|=8192)):it(n),o=n.updateQueue,o!==null&&sr(n,o.retryQueue),o=null,e!==null&&e.memoizedState!==null&&e.memoizedState.cachePool!==null&&(o=e.memoizedState.cachePool.pool),c=null,n.memoizedState!==null&&n.memoizedState.cachePool!==null&&(c=n.memoizedState.cachePool.pool),c!==o&&(n.flags|=2048),e!==null&&$e(wl),null;case 24:return o=null,e!==null&&(o=e.memoizedState.cache),n.memoizedState.cache!==o&&(n.flags|=2048),ra(gt),it(n),null;case 25:return null;case 30:return n.flags|=33554432,it(n),null}throw Error(l(156,n.tag))}function qx(e,n){switch(Wc(n),n.tag){case 1:return e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 3:return ra(gt),Te(),e=n.flags,(e&65536)!==0&&(e&128)===0?(n.flags=e&-65537|128,n):null;case 26:case 27:case 5:return De(n),null;case 31:if(n.memoizedState!==null){if(un(n),n.alternate===null)throw Error(l(340));dl()}return e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 13:if(un(n),e=n.memoizedState,e!==null&&e.dehydrated!==null){if(n.alternate===null)throw Error(l(340));dl()}return e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 19:return hu(n),e=n.flags,e&65536?(n.flags=e&-65537|128,e=n.memoizedState,e!==null&&(e.rendering=null,e.tail=null),n.flags|=4,n):null;case 4:return Te(),null;case 10:return ra(n.type),null;case 22:case 23:return un(n),uu(),e!==null&&$e(wl),e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 24:return ra(gt),null;case 25:return null;default:return null}}function Gp(e,n){switch(Wc(n),n.tag){case 3:ra(gt),Te();break;case 26:case 27:case 5:De(n);break;case 4:Te();break;case 31:n.memoizedState!==null&&un(n);break;case 13:un(n);break;case 19:hu(n);break;case 10:ra(n.type);break;case 22:case 23:un(n),uu(),e!==null&&$e(wl);break;case 24:ra(gt)}}function xo(e,n){try{var o=n.updateQueue,c=o!==null?o.lastEffect:null;if(c!==null){var m=c.next;o=m;do{if((o.tag&e)===e){c=void 0;var g=o.create,S=o.inst;c=g(),S.destroy=c}o=o.next}while(o!==m)}}catch(q){Fe(n,n.return,q)}}function qa(e,n,o){try{var c=n.updateQueue,m=c!==null?c.lastEffect:null;if(m!==null){var g=m.next;c=g;do{if((c.tag&e)===e){var S=c.inst,q=S.destroy;if(q!==void 0){S.destroy=void 0,m=n;var Q=o,le=q;try{le()}catch(ce){Fe(m,Q,ce)}}}c=c.next}while(c!==g)}}catch(ce){Fe(n,n.return,ce)}}function Xp(e){var n=e.updateQueue;if(n!==null){var o=e.stateNode;try{Om(n,o)}catch(c){Fe(e,e.return,c)}}}function Zp(e,n,o){o.props=kl(e.type,e.memoizedProps),o.state=e.memoizedState;try{o.componentWillUnmount()}catch(c){Fe(e,n,c)}}function Gn(e,n){try{var o=e.ref;if(o!==null){switch(e.tag){case 26:case 27:case 5:var c=e.stateNode;break;case 30:var m=e.stateNode,g=aa(e.memoizedProps,m);(m.ref===null||m.ref.name!==g)&&(m.ref=Fy(g)),c=m.ref;break;case 7:if(e.stateNode===null){var S=new pn(e);y(e.child,!1,jb,S,void 0,void 0),e.stateNode=S}c=e.stateNode;break;default:c=e.stateNode}typeof o=="function"?e.refCleanup=o(c):o.current=c}}catch(q){Fe(e,n,q)}}function At(e,n){var o=e.ref,c=e.refCleanup;if(o!==null)if(typeof c=="function")try{c()}catch(m){Fe(e,n,m)}finally{e.refCleanup=null,e=e.alternate,e!=null&&(e.refCleanup=null)}else if(typeof o=="function")try{o(null)}catch(m){Fe(e,n,m)}else o.current=null}function or(e,n){if((e.tag===5||e.tag===27||e.tag===6)&&e.alternate===null&&n!==null)for(var o=0;o<n.length;o++)lg(e.stateNode,n[o])}function Qp(e){for(var n=e.return;n!==null&&(Gu(n)&&lg(e.stateNode,n.stateNode),!Yu(n));)n=n.return}function bo(e){for(var n=e.return;n!==null&&(Gu(n)&&Sb(e.stateNode,n.stateNode),!Yu(n));)n=n.return}function Yu(e){return e.tag===5||e.tag===3||e.tag===27}function Gu(e){return e&&e.tag===7&&e.stateNode!==null}function Xu(e){var n=e.type,o=e.memoizedProps,c=e.stateNode;try{e:switch(n){case"button":case"input":case"select":case"textarea":o.autoFocus&&c.focus();break e;case"img":o.src?c.src=o.src:o.srcSet&&(c.srcset=o.srcSet)}}catch(m){Fe(e,e.return,m)}}function Zu(e,n,o){try{var c=e.stateNode;ib(c,e.type,o,n),c[Vt]=n}catch(m){Fe(e,e.return,m)}}function Vp(e){return e.tag===5||e.tag===3||e.tag===26||e.tag===27&&Ya(e.type)||e.tag===4}function Qu(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||Vp(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.tag===27&&Ya(e.type)||e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function Vu(e,n,o,c){var m=e.tag;if(m===5||m===6)m=e.stateNode,n?(o.nodeType===9?o.body:o.nodeName==="HTML"?o.ownerDocument.body:o).insertBefore(m,n):(n=o.nodeType===9?o.body:o.nodeName==="HTML"?o.ownerDocument.body:o,n.appendChild(m),o=o._reactRootContainer,o!=null||n.onclick!==null||(n.onclick=Ln)),or(e,c),Ke=!0;else if(m!==4&&(m===27&&(or(e,c),c=null,Ya(e.type)&&(o=e.stateNode,n=null)),e=e.child,e!==null))for(Vu(e,n,o,c),e=e.sibling;e!==null;)Vu(e,n,o,c),e=e.sibling}function ir(e,n,o,c){var m=e.tag;if(m===5||m===6)m=e.stateNode,n?o.insertBefore(m,n):o.appendChild(m),or(e,c),Ke=!0;else if(m!==4&&(m===27&&(or(e,c),c=null,Ya(e.type)&&(o=e.stateNode)),e=e.child,e!==null))for(ir(e,n,o,c),e=e.sibling;e!==null;)ir(e,n,o,c),e=e.sibling}function Kp(e){var n=e.stateNode,o=e.memoizedProps;try{for(var c=e.type,m=n.attributes;m.length;)n.removeAttributeNode(m[0]);qt(n,c,o),n[Ct]=e,n[Vt]=o}catch(g){Fe(e,e.return,g)}}var rr=!1,fn=null;function Jp(e){(e.tag===30||(e.subtreeFlags&33554432)!==0)&&(rr=!0)}var Xn=null;function Wp(){var e=Xn;return Xn=null,e}var Jt=0;function rs(e,n,o,c,m){return Jt=0,Ip(e.child,n,o,c,m)}function Ip(e,n,o,c,m){for(var g=!1;e!==null;){if(e.tag===5){var S=e.stateNode;if(c!==null){var q=Ef(S);c.push(q),q.view&&(g=!0)}else g||Ef(S).view&&(g=!0);rr=!0,Wy(S,Jt===0?n:n+"_"+Jt,o),Jt++}else(e.tag!==22||e.memoizedState===null)&&(e.tag===30&&m||Ip(e.child,n,o,c,m)&&(g=!0));e=e.sibling}return g}function Zn(e,n){for(;e!==null;)e.tag===5?Iy(e.stateNode,e.memoizedProps):(e.tag!==22||e.memoizedState===null)&&(e.tag===30&&n||Zn(e.child,n)),e=e.sibling}function cr(e){if((e.subtreeFlags&18874368)!==0)for(e=e.child;e!==null;){if((e.tag!==22||e.memoizedState===null)&&(cr(e),e.tag===30&&(e.flags&18874368)!==0&&e.stateNode.paired)){var n=e.memoizedProps;if(n.name==null||n.name==="auto")throw Error(l(544));var o=n.name;n=la(n.default,n.share),n!=="none"&&(rs(e,o,n,null,!1)||Zn(e.child,!1))}e=e.sibling}}function Ku(e,n){if(e.tag===30){var o=e.stateNode,c=e.memoizedProps,m=aa(c,o),g=la(c.default,o.paired?c.share:c.enter);g!=="none"?rs(e,m,g,null,!1)?(cr(e),o.paired||n||ys(e,c.onEnter)):Zn(e.child,!1):cr(e)}else if((e.subtreeFlags&33554432)!==0)for(e=e.child;e!==null;)Ku(e,n),e=e.sibling;else cr(e)}function Ju(e){if(fn!==null&&fn.size!==0){var n=fn;if((e.subtreeFlags&18874368)!==0)for(e=e.child;e!==null;){if(e.tag!==22||e.memoizedState===null){if(e.tag===30&&(e.flags&18874368)!==0){var o=e.memoizedProps,c=o.name;if(c!=null&&c!=="auto"){var m=n.get(c);if(m!==void 0){var g=la(o.default,o.share);if(g!=="none"&&(rs(e,c,g,null,!1)?(g=e.stateNode,m.paired=g,g.paired=m,ys(e,o.onShare)):Zn(e.child,!1)),n.delete(c),n.size===0)break}}}Ju(e)}e=e.sibling}}}function Wu(e){if(e.tag===30){var n=e.memoizedProps,o=aa(n,e.stateNode),c=fn!==null?fn.get(o):void 0,m=la(n.default,c!==void 0?n.share:n.exit);m!=="none"&&(rs(e,o,m,null,!1)?c!==void 0?(m=e.stateNode,c.paired=m,m.paired=c,fn.delete(o),ys(e,n.onShare)):ys(e,n.onExit):Zn(e.child,!1)),fn!==null&&Ju(e)}else if((e.subtreeFlags&33554432)!==0)for(e=e.child;e!==null;)Wu(e),e=e.sibling;else fn!==null&&Ju(e)}function Fp(e){for(e=e.child;e!==null;){if(e.tag===30){var n=e.memoizedProps,o=aa(n,e.stateNode);n=la(n.default,n.update),e.flags&=-5,n!=="none"&&rs(e,o,n,e.memoizedState=[],!1)}else(e.subtreeFlags&33554432)!==0&&Fp(e);e=e.sibling}}function Iu(e){if((e.subtreeFlags&18874368)!==0)for(e=e.child;e!==null;){if(e.tag!==22||e.memoizedState===null){if(e.tag===30&&(e.flags&18874368)!==0){var n=e.stateNode;n.paired!==null&&(n.paired=null,Zn(e.child,!1))}Iu(e)}e=e.sibling}}function ur(e){if(e.tag===30)e.stateNode.paired=null,Zn(e.child,!1),Iu(e);else if((e.subtreeFlags&33554432)!==0)for(e=e.child;e!==null;)ur(e),e=e.sibling;else Iu(e)}function Pp(e){for(e=e.child;e!==null;)e.tag===30?Zn(e.child,!1):(e.subtreeFlags&33554432)!==0&&Pp(e),e=e.sibling}function Fu(e,n,o,c,m,g,S){for(var q=!1;n!==null;){if(n.tag===5){var Q=n.stateNode;if(g!==null&&Jt<g.length){var le=g[Jt],ce=Ef(Q);(le.view||ce.view)&&(q=!0);var me;if(me=(e.flags&4)===0)if(ce.clip)me=!0;else{me=le.rect;var ee=ce.rect;me=me.y!==ee.y||me.x!==ee.x||me.height!==ee.height||me.width!==ee.width}me&&(e.flags|=4),ce.abs?ce=!le.abs:(le=le.rect,ce=ce.rect,ce=le.height!==ce.height||le.width!==ce.width),ce&&(e.flags|=32)}else e.flags|=32;(e.flags&4)!==0&&Wy(Q,Jt===0?o:o+"_"+Jt,m),q&&(e.flags&4)!==0||(Xn===null&&(Xn=[]),Xn.push(Q,Jt===0?c:c+"_"+Jt,n.memoizedProps)),Jt++}else(n.tag!==22||n.memoizedState===null)&&(n.tag===30&&S?e.flags|=n.flags&32:Fu(e,n.child,o,c,m,g,S)&&(q=!0));n=n.sibling}return q}function ey(e,n){for(e=e.child;e!==null;){if(e.tag===30){var o=e.memoizedProps,c=e.stateNode,m=aa(o,c),g=la(o.default,o.update),S;S=e.memoizedState,e.memoizedState=null,c=e;var q=e.child;Jt=0,m=Fu(c,q,m,m,g,S,!1),(e.flags&4)!==0&&m&&ys(e,o.onUpdate)}else(e.subtreeFlags&33554432)!==0&&ey(e);e=e.sibling}}var jt=!1,We=!1,Qn=!1,Pu=!1,ty=typeof WeakSet=="function"?WeakSet:Set,St=null,Vn=!1,$o=!1,fr=!1,ef=!1;function Rx(e,n,o){if(e=e.containerInfo,Sf=Ss,e=sm(e),Lc(e)){if("selectionStart"in e)var c={start:e.selectionStart,end:e.selectionEnd};else e:{c=(c=e.ownerDocument)&&c.defaultView||window;var m=c.getSelection&&c.getSelection();if(m&&m.rangeCount!==0){c=m.anchorNode;var g=m.anchorOffset,S=m.focusNode;m=m.focusOffset;try{c.nodeType,S.nodeType}catch{c=null;break e}var q=0,Q=-1,le=-1,ce=0,me=0,ee=e,re=null;t:for(;;){for(var xe;ee!==c||g!==0&&ee.nodeType!==3||(Q=q+g),ee!==S||m!==0&&ee.nodeType!==3||(le=q+m),ee.nodeType===3&&(q+=ee.nodeValue.length),(xe=ee.firstChild)!==null;)re=ee,ee=xe;for(;;){if(ee===e)break t;if(re===c&&++ce===g&&(Q=q),re===S&&++me===m&&(le=q),(xe=ee.nextSibling)!==null)break;ee=re,re=ee.parentNode}ee=xe}c=Q===-1||le===-1?null:{start:Q,end:le}}else c=null}c=c||{start:0,end:0}}else c=null;for(Nf={focusedElem:e,selectionRange:c},Ss=!1,o=(o&335544064)===o,St=n,n=o?9270:1024;St!==null;){if(e=St,o&&(c=e.deletions,c!==null))for(g=0;g<c.length;g++)o&&Wu(c[g]);if(e.alternate===null&&(e.flags&2)!==0)o&&Jp(e),hr(o);else{if(e.tag===22){if(c=e.alternate,e.memoizedState!==null){c!==null&&c.memoizedState===null&&o&&Wu(c),hr(o);continue}else if(c!==null&&c.memoizedState!==null){o&&Jp(e),hr(o);continue}}c=e.child,(e.subtreeFlags&n)!==0&&c!==null?(c.return=e,St=c):(o&&Fp(e),hr(o))}}fn=null}function hr(e){for(;St!==null;){var n=St,o=e,c=n.alternate,m=n.flags;switch(n.tag){case 0:case 11:case 15:break;case 1:if((m&1024)!==0&&c!==null){o=void 0,m=c.memoizedProps,c=c.memoizedState;var g=n.stateNode;try{var S=kl(n.type,m);o=g.getSnapshotBeforeUpdate(S,c),g.__reactInternalSnapshotBeforeUpdate=o}catch(q){Fe(n,n.return,q)}}break;case 3:if((m&1024)!==0){if(c=n.stateNode.containerInfo,o=c.nodeType,o===9)Af(c);else if(o===1)switch(c.nodeName){case"HEAD":case"HTML":case"BODY":Af(c);break;default:c.textContent=""}}break;case 5:case 26:case 27:case 6:case 4:case 17:break;case 30:o&&c!==null&&(o=aa(c.memoizedProps,c.stateNode),m=n.memoizedProps,m=la(m.default,m.update),m!=="none"&&rs(c,o,m,c.memoizedState=[],!0));break;default:if((m&1024)!==0)throw Error(l(163))}if(c=n.sibling,c!==null){c.return=n.return,St=c;break}St=n.return}}function ny(e,n,o){var c=o.flags;switch(o.tag){case 0:case 11:case 15:Kn(e,o),c&4&&xo(5,o);break;case 1:if(Kn(e,o),c&4)if(e=o.stateNode,n===null)try{e.componentDidMount()}catch(S){Fe(o,o.return,S)}else{var m=kl(o.type,n.memoizedProps);n=n.memoizedState;try{e.componentDidUpdate(m,n,e.__reactInternalSnapshotBeforeUpdate)}catch(S){Fe(o,o.return,S)}}c&64&&Xp(o),c&512&&Gn(o,o.return);break;case 3:if(Kn(e,o),c&64&&(e=o.updateQueue,e!==null)){if(n=null,o.child!==null)switch(o.child.tag){case 27:case 5:n=o.child.stateNode;break;case 1:n=o.child.stateNode}try{Om(e,n)}catch(S){Fe(o,o.return,S)}}break;case 27:n===null&&c&4&&Kp(o);case 26:case 5:Kn(e,o),n===null&&c&4&&Xu(o),c&512&&Gn(o,o.return);break;case 12:Kn(e,o);break;case 31:Kn(e,o),c&4&&oy(e,o);break;case 13:Kn(e,o),c&4&&iy(e,o),c&64&&(e=o.memoizedState,e!==null&&(e=e.dehydrated,e!==null&&(o=Kx.bind(null,o),zb(e,o))));break;case 22:if(c=o.memoizedState!==null||jt,!c){var g=n!==null&&n.memoizedState!==null||We;n=jt,m=We,jt=c,(We=g)&&!m?(c=2,(o.subtreeFlags&8772)!==0&&(c|=1),qn(e,o,c)):Kn(e,o),jt=n,We=m}break;case 30:Kn(e,o),c&512&&Gn(o,o.return);break;case 7:c&512&&Gn(o,o.return);default:Kn(e,o)}}function tf(e,n){for(e=e.child;e!==null;)ay(e,n),e=e.sibling}function ay(e,n){switch(e.tag){case 5:case 26:try{var o=e.stateNode;if(n){var c=o.style;typeof c.setProperty=="function"?c.setProperty("display","none","important"):c.display="none"}else{var m=e.stateNode,g=e.memoizedProps.style,S=g!=null&&g.hasOwnProperty("display")?g.display:null;m.style.display=S==null||typeof S=="boolean"?"":(""+S).trim()}}catch(Q){Fe(e,e.return,Q)}nf(e,n);break;case 6:try{e.stateNode.nodeValue=n?"":e.memoizedProps,Ke=!0}catch(Q){Fe(e,e.return,Q)}break;case 18:try{var q=e.stateNode;n?Jy(q,!0):Jy(e.stateNode,!1)}catch(Q){Fe(e,e.return,Q)}break;case 22:case 23:e.memoizedState===null&&tf(e,n);break;default:tf(e,n)}}function nf(e,n){if(e.subtreeFlags&67108864)for(e=e.child;e!==null;){e:{var o=e,c=n;switch(o.tag){case 4:ay(o,c);break e;case 22:o.memoizedState===null&&nf(o,c);break e;default:nf(o,c)}}e=e.sibling}}function ly(e){var n=e.alternate;n!==null&&(e.alternate=null,ly(n)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(n=e.stateNode,n!==null&&gi(n)),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}var ut=null,Wt=!1;function On(e,n,o){for(o=o.child;o!==null;)sy(e,n,o),o=o.sibling}function sy(e,n,o){if(sn&&typeof sn.onCommitFiberUnmount=="function")try{sn.onCommitFiberUnmount(Xs,o)}catch{}switch(o.tag){case 26:We||At(o,n),On(e,n,o),o.memoizedState?o.memoizedState.count--:o.stateNode&&!We&&(o=o.stateNode,o.parentNode.removeChild(o));break;case 27:We||At(o,n),bo(o);var c=ut,m=Wt;Ya(o.type)&&(ut=o.stateNode,Wt=!1),On(e,n,o),cg(o.stateNode,o.type,o.memoizedProps),ut=c,Wt=m;break;case 5:We||At(o,n),bo(o);case 6:if(o.tag===6&&bo(o),c=ut,m=Wt,ut=null,On(e,n,o),ut=c,Wt=m,ut!==null)if(Wt)try{(ut.nodeType===9?ut.body:ut.nodeName==="HTML"?ut.ownerDocument.body:ut).removeChild(o.stateNode),Ke=!0}catch(g){Fe(o,n,g)}else try{ut.removeChild(o.stateNode),Ke=!0}catch(g){Fe(o,n,g)}break;case 18:ut!==null&&(Wt?(e=ut,Ky(e.nodeType===9?e.body:e.nodeName==="HTML"?e.ownerDocument.body:e,o.stateNode),Ns(e)):Ky(ut,o.stateNode));break;case 4:c=ut,m=Wt,ut=o.stateNode.containerInfo,Wt=!0,On(e,n,o),ut=c,Wt=m;break;case 0:case 11:case 14:case 15:qa(2,o,n),We||qa(4,o,n),On(e,n,o);break;case 1:We||(At(o,n),c=o.stateNode,typeof c.componentWillUnmount=="function"&&Zp(o,n,c)),On(e,n,o);break;case 21:On(e,n,o);break;case 22:We=(c=We)||o.memoizedState!==null,On(e,n,o),We=c;break;case 30:At(o,n),On(e,n,o);break;case 7:We||At(o,n),On(e,n,o);break;default:On(e,n,o)}}function oy(e,n){if(n.memoizedState===null&&(e=n.alternate,e!==null&&(e=e.memoizedState,e!==null))){e=e.dehydrated;try{Ns(e)}catch(o){Fe(n,n.return,o)}}}function iy(e,n){if(n.memoizedState===null&&(e=n.alternate,e!==null&&(e=e.memoizedState,e!==null&&(e=e.dehydrated,e!==null))))try{Ns(e)}catch(o){Fe(n,n.return,o)}}function Dx(e){switch(e.tag){case 31:case 13:case 19:var n=e.stateNode;return n===null&&(n=e.stateNode=new ty),n;case 22:return e=e.stateNode,n=e._retryCache,n===null&&(n=e._retryCache=new ty),n;default:throw Error(l(435,e.tag))}}function dr(e,n){var o=Dx(e);n.forEach(function(c){if(!o.has(c)){o.add(c);var m=Jx.bind(null,e,c);c.then(m,m)}})}function Yt(e,n,o){var c=n.deletions;if(c!==null)for(var m=0;m<c.length;m++){var g=c[m],S=e,q=n,Q=q;e:for(;Q!==null;){switch(Q.tag){case 27:if(Ya(Q.type)){ut=Q.stateNode,Wt=!1;break e}break;case 5:ut=Q.stateNode,Wt=!1;break e;case 3:case 4:ut=Q.stateNode.containerInfo,Wt=!0;break e}Q=Q.return}if(ut===null)throw Error(l(160));sy(S,q,g),ut=null,Wt=!1,S=g.alternate,S!==null&&(S.return=null),g.return=null}if(n.subtreeFlags&13886)for(n=n.child;n!==null;)ry(n,e,o),n=n.sibling}var An=null;function ry(e,n,o){var c=e.alternate,m=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(m&4&&(c=e.updateQueue,c=c!==null?c.events:null,c!==null))for(var g=0;g<c.length;g++){var S=c[g];S.ref.impl=S.nextImpl}Yt(n,e,o),Gt(e),m&4&&(qa(3,e,e.return),xo(3,e),qa(5,e,e.return));break;case 1:Yt(n,e,o),Gt(e),m&512&&(We||c===null||At(c,c.return)),m&64&&jt&&(e=e.updateQueue,e!==null&&(n=e.callbacks,n!==null&&(o=e.shared.hiddenCallbacks,e.shared.hiddenCallbacks=o===null?n:o.concat(n))));break;case 26:if(g=An,Yt(n,e,o),Gt(e),m&512&&(We||c===null||At(c,c.return)),m&4)if(m=c!==null?c.memoizedState:null,o=e.memoizedState,c===null)if(o===null)if(e.stateNode===null)if(jt)e.stateNode=Zy(e.type,e.memoizedProps,n.containerInfo,e);else{e:{n=e.type,o=e.memoizedProps,m=g.ownerDocument||g;t:switch(n){case"title":c=m.getElementsByTagName("title")[0],(!c||c[Vs]||c[Ct]||c.namespaceURI==="http://www.w3.org/2000/svg"||c.hasAttribute("itemprop"))&&(c=m.createElement(n),m.head.insertBefore(c,m.querySelector("head > title"))),qt(c,n,o),c[Ct]=e,kt(c),n=c;break e;case"link":if(g=pg("link","href",m).get(n+(o.href||""))){for(S=0;S<g.length;S++)if(c=g[S],c.getAttribute("href")===(o.href==null||o.href===""?null:o.href)&&c.getAttribute("rel")===(o.rel==null?null:o.rel)&&c.getAttribute("title")===(o.title==null?null:o.title)&&c.getAttribute("crossorigin")===(o.crossOrigin==null?null:o.crossOrigin)){g.splice(S,1);break t}}c=m.createElement(n),qt(c,n,o),m.head.appendChild(c);break;case"meta":if(g=pg("meta","content",m).get(n+(o.content||""))){for(S=0;S<g.length;S++)if(c=g[S],c.getAttribute("content")===(o.content==null?null:""+o.content)&&c.getAttribute("name")===(o.name==null?null:o.name)&&c.getAttribute("property")===(o.property==null?null:o.property)&&c.getAttribute("http-equiv")===(o.httpEquiv==null?null:o.httpEquiv)&&c.getAttribute("charset")===(o.charSet==null?null:o.charSet)){g.splice(S,1);break t}}c=m.createElement(n),qt(c,n,o),m.head.appendChild(c);break;default:throw Error(l(468,n))}c[Ct]=e,kt(c),n=c}e.stateNode=n}else jt||Bf(g,e.type,e.stateNode);else e.stateNode=mg(g,o,e.memoizedProps);else m!==o?(m===null?(n=c.stateNode,n===null||We||n.parentNode.removeChild(n)):m.count--,o===null?jt||Bf(g,e.type,e.stateNode):mg(g,o,e.memoizedProps)):o===null&&e.stateNode!==null&&Zu(e,e.memoizedProps,c.memoizedProps);break;case 27:Yt(n,e,o),Gt(e),m&512&&(We||c===null||At(c,c.return)),c!==null&&m&4&&Zu(e,e.memoizedProps,c.memoizedProps);break;case 5:if(g=Qn,Qn=!1,Yt(n,e,o),Qn=g,Gt(e),m&512&&(We||c===null||At(c,c.return)),e.flags&32){n=e.stateNode;try{Xl(n,""),Ke=!0}catch(ce){Fe(e,e.return,ce)}}m&4&&e.stateNode!=null&&(n=e.memoizedProps,Zu(e,n,c!==null?c.memoizedProps:n)),m&1024&&(Pu=!0);break;case 6:if(Yt(n,e,o),Gt(e),m&4){if(e.stateNode===null)throw Error(l(162));n=e.memoizedProps,o=e.stateNode;try{o.nodeValue=n,Ke=!0}catch(ce){Fe(e,e.return,ce)}}break;case 3:if(Ke=!1,Mr=null,g=An,An=Eo(n.containerInfo),Yt(n,e,o),An=g,Gt(e),m&4&&c!==null&&c.memoizedState.isDehydrated)try{Ns(n.containerInfo)}catch(ce){Fe(e,e.return,ce)}Pu&&(Pu=!1,cy(e)),Ke=!1;break;case 4:m=Qn,Qn=jt,c=zd(),g=An,An=Eo(e.stateNode.containerInfo),Yt(n,e,o),Gt(e),An=g,Ke&&$o&&(fr=!0),Ke=c,Qn=m;break;case 12:Yt(n,e,o),Gt(e);break;case 31:Yt(n,e,o),Gt(e),m&4&&(n=e.updateQueue,n!==null&&(e.updateQueue=null,dr(e,n)));break;case 13:Yt(n,e,o),Gt(e),e.child.flags&8192&&e.memoizedState!==null!=(c!==null&&c.memoizedState!==null)&&(yr=ln()),m&4&&(n=e.updateQueue,n!==null&&(e.updateQueue=null,dr(e,n)));break;case 22:g=e.memoizedState!==null,S=c!==null&&c.memoizedState!==null;var q=jt,Q=We,le=Qn;jt=q||g,Qn=le||g,We=Q||S,Yt(n,e,o),We=Q,Qn=le,jt=q,Gt(e),m&8192&&(n=e.stateNode,n._visibility=g?n._visibility&-2:n._visibility|1,!g||c===null||S||jt||We||(n=S||We,o=jt,c=We,jt=g||jt,We=n,Ra(e,2),jt=o,We=c),!g&&Qn||tf(e,g)),m&4&&(n=e.updateQueue,n!==null&&(o=n.retryQueue,o!==null&&(n.retryQueue=null,dr(e,o))));break;case 19:Yt(n,e,o),Gt(e),m&4&&(n=e.updateQueue,n!==null&&(e.updateQueue=null,dr(e,n)));break;case 30:m&512&&(We||c===null||At(c,c.return)),m=zd(),g=$o,S=(o&335544064)===o,q=e.memoizedProps,$o=S&&la(q.default,q.update)!=="none",Yt(n,e,o),Gt(e),S&&c!==null&&Ke&&(e.flags|=4),$o=g,Ke=m;break;case 21:break;case 7:m&512&&(We||c===null||At(c,c.return)),c&&c.stateNode!==null&&(c.stateNode._fragmentFiber=e);default:Yt(n,e,o),Gt(e)}}function Gt(e){var n=e.flags;if(n&2){try{for(var o,c=e.return;c!==null;){if(Vp(c)){o=c;break}c=c.return}c=null;for(var m=e.return;m!==null;){if(Gu(m)){var g=m.stateNode;c===null?c=[g]:c.push(g)}if(Yu(m))break;m=m.return}var S=c;if(o==null)throw Error(l(160));switch(o.tag){case 27:var q=o.stateNode,Q=Qu(e);ir(e,Q,q,S);break;case 5:var le=o.stateNode;o.flags&32&&(Xl(le,""),o.flags&=-33);var ce=Qu(e);ir(e,ce,le,S);break;case 3:case 4:var me=o.stateNode.containerInfo,ee=Qu(e);Vu(e,ee,me,S);break;default:throw Error(l(161))}}catch(re){Fe(e,e.return,re)}e.flags&=-3}n&4096&&(e.flags&=-4097)}function cy(e){if(e.subtreeFlags&1024)for(e=e.child;e!==null;){var n=e;cy(n),n.tag===5&&n.flags&1024&&(n=n.stateNode,Ss=!0,n.reset(),Ss=!1),e=e.sibling}}function cs(e,n){if(n.subtreeFlags&9270)for(n=n.child;n!==null;)uy(n,e),n=n.sibling;else ey(n)}function uy(e,n){var o=e.alternate;if(o===null)Ku(e,!1);else switch(e.tag){case 3:if(ef=Vn=!1,Wp(),cs(n,e),!Vn&&!fr){if(e=Xn,e!==null)for(var c=0;c<e.length;c+=3){o=e[c];var m=e[c+1];Iy(o,e[c+2]),o=o.ownerDocument.documentElement,o!==null&&o.animate({opacity:[0,0],pointerEvents:["none","none"]},{duration:0,fill:"forwards",pseudoElement:"::view-transition-group("+m+")"})}e=n.containerInfo,e=e.nodeType===9?e.documentElement:e.ownerDocument.documentElement,e!==null&&e.style.viewTransitionName===""&&(e.style.viewTransitionName="none",e.animate({opacity:[0,0],pointerEvents:["none","none"]},{duration:0,fill:"forwards",pseudoElement:"::view-transition-group(root)"}),e.animate({width:[0,0],height:[0,0]},{duration:0,fill:"forwards",pseudoElement:"::view-transition"})),ef=!0}Xn=null;break;case 5:cs(n,e);break;case 4:c=Vn,Vn=!1,cs(n,e),Vn&&(fr=!0),Vn=c;break;case 22:e.memoizedState===null&&(o.memoizedState!==null?Ku(e,!1):cs(n,e));break;case 30:c=Vn,m=Wp(),Vn=!1,cs(n,e),Vn&&(e.flags|=4);var g=e.memoizedProps,S=e.stateNode;n=aa(g,S),S=aa(o.memoizedProps,S);var q=la(g.default,g.update);q==="none"?n=!1:(g=o.memoizedState,o.memoizedState=null,o=e.child,Jt=0,n=Fu(e,o,n,S,q,g,!0),Jt!==(g===null?0:g.length)&&(e.flags|=32)),(e.flags&4)!==0&&n?(ys(e,e.memoizedProps.onUpdate),Xn=m):m!==null&&(m.push.apply(m,Xn),Xn=m),Vn=(e.flags&32)!==0?!0:c;break;default:cs(n,e)}}function Kn(e,n){if(n.subtreeFlags&8772)for(n=n.child;n!==null;)ny(e,n.alternate,n),n=n.sibling}function Ra(e,n){for(e=e.child;e!==null;){var o=e,c=n;switch(o.tag){case 0:case 11:case 14:case 15:qa(4,o,o.return),Ra(o,c);break;case 1:At(o,o.return);var m=o.stateNode;typeof m.componentWillUnmount=="function"&&Zp(o,o.return,m),Ra(o,c);break;case 27:(c&2)!==0&&cg(o.stateNode,o.type,o.memoizedProps);case 5:At(o,o.return),o.tag!==5&&o.tag!==27||bo(o),Ra(o,c);break;case 6:bo(o);break;case 26:At(o,o.return),m=o.stateNode,o.memoizedState!==null||m===null||We||m.parentNode.removeChild(m),Ra(o,c);break;case 22:o.memoizedState===null&&Ra(o,c);break;case 30:At(o,o.return),Ra(o,c);break;case 7:At(o,o.return);default:Ra(o,c)}e=e.sibling}}function qn(e,n,o){for(o=(n.subtreeFlags&8772)!==0?o:o&-2,n=n.child;n!==null;){var c=n.alternate,m=e,g=n,S=g.flags,q=(o&1)!==0;switch(g.tag){case 0:case 11:case 15:qn(m,g,o),xo(4,g);break;case 1:if(qn(m,g,o),c=g,m=c.stateNode,typeof m.componentDidMount=="function")try{m.componentDidMount()}catch(ce){Fe(c,c.return,ce)}if(c=g,m=c.updateQueue,m!==null){var Q=c.stateNode;try{var le=m.shared.hiddenCallbacks;if(le!==null)for(m.shared.hiddenCallbacks=null,m=0;m<le.length;m++)Tm(le[m],Q)}catch(ce){Fe(c,c.return,ce)}}q&&S&64&&Xp(g),Gn(g,g.return);break;case 27:(o&2)!==0&&Kp(g);case 5:g.tag!==5&&g.tag!==27||Qp(g),qn(m,g,o),q&&c===null&&S&4&&Xu(g),Gn(g,g.return);break;case 6:Qp(g);break;case 26:Q=g.stateNode,g.memoizedState!==null||Q===null||jt||Bf(Eo(Q.ownerDocument),g.type,Q),qn(m,g,o),q&&c===null&&S&4&&Xu(g),Gn(g,g.return);break;case 12:qn(m,g,o);break;case 31:qn(m,g,o),q&&S&4&&oy(m,g);break;case 13:qn(m,g,o),q&&S&4&&iy(m,g);break;case 22:g.memoizedState===null&&qn(m,g,o),Gn(g,g.return);break;case 30:qn(m,g,o),Gn(g,g.return);break;case 7:Gn(g,g.return);default:qn(m,g,o)}n=n.sibling}}function af(e,n){var o=null;e!==null&&e.memoizedState!==null&&e.memoizedState.cachePool!==null&&(o=e.memoizedState.cachePool.pool),e=null,n.memoizedState!==null&&n.memoizedState.cachePool!==null&&(e=n.memoizedState.cachePool.pool),e!==o&&(e!=null&&e.refCount++,o!=null&&oo(o))}function lf(e,n){e=null,n.alternate!==null&&(e=n.alternate.memoizedState.cache),n=n.memoizedState.cache,n!==e&&(n.refCount++,e!=null&&oo(e))}function Sn(e,n,o,c){var m=(o&335544064)===o;if(n.subtreeFlags&(m?10262:10256))for(n=n.child;n!==null;)fy(e,n,o,c),n=n.sibling;else m&&Pp(n)}function fy(e,n,o,c){var m=(o&335544064)===o;m&&n.alternate===null&&n.return!==null&&n.return.alternate!==null&&ur(n);var g=n.flags;switch(n.tag){case 0:case 11:case 15:Sn(e,n,o,c),g&2048&&xo(9,n);break;case 1:Sn(e,n,o,c);break;case 3:Sn(e,n,o,c),m&&ef&&(e=e.containerInfo,e=e.nodeType===9?e.body:e.nodeName==="HTML"?e.ownerDocument.body:e,e.style.viewTransitionName==="root"&&(e.style.viewTransitionName=""),e=e.ownerDocument.documentElement,e!==null&&e.style.viewTransitionName==="none"&&(e.style.viewTransitionName="")),g&2048&&(g=null,n.alternate!==null&&(g=n.alternate.memoizedState.cache),n=n.memoizedState.cache,n!==g&&(n.refCount++,g!=null&&oo(g)));break;case 12:if(g&2048){Sn(e,n,o,c),g=n.stateNode;try{var S=n.memoizedProps,q=S.id,Q=S.onPostCommit;typeof Q=="function"&&Q(q,n.alternate===null?"mount":"update",g.passiveEffectDuration,-0)}catch(le){Fe(n,n.return,le)}}else Sn(e,n,o,c);break;case 31:Sn(e,n,o,c);break;case 13:Sn(e,n,o,c);break;case 23:break;case 22:S=n.stateNode,q=n.alternate,n.memoizedState!==null?(m&&q!==null&&q.memoizedState===null&&ur(q),S._visibility&2?Sn(e,n,o,c):ko(e,n)):(m&&q!==null&&q.memoizedState!==null&&ur(n),S._visibility&2?Sn(e,n,o,c):(S._visibility|=2,us(e,n,o,c,(n.subtreeFlags&10256)!==0||!1))),g&2048&&af(q,n);break;case 24:Sn(e,n,o,c),g&2048&&lf(n.alternate,n);break;case 30:m&&(g=n.alternate,g!==null&&(Zn(g.child,!0),Zn(n.child,!0))),Sn(e,n,o,c);break;default:Sn(e,n,o,c)}}function us(e,n,o,c,m){for(m=m&&((n.subtreeFlags&10256)!==0||!1),n=n.child;n!==null;){var g=e,S=n,q=o,Q=c,le=S.flags;switch(S.tag){case 0:case 11:case 15:us(g,S,q,Q,m),xo(8,S);break;case 23:break;case 22:var ce=S.stateNode;S.memoizedState!==null?ce._visibility&2?us(g,S,q,Q,m):ko(g,S):(ce._visibility|=2,us(g,S,q,Q,m)),m&&le&2048&&af(S.alternate,S);break;case 24:us(g,S,q,Q,m),m&&le&2048&&lf(S.alternate,S);break;default:us(g,S,q,Q,m)}n=n.sibling}}function ko(e,n){if(n.subtreeFlags&10256)for(n=n.child;n!==null;){var o=e,c=n,m=c.flags;switch(c.tag){case 22:ko(o,c),m&2048&&af(c.alternate,c);break;case 24:ko(o,c),m&2048&&lf(c.alternate,c);break;default:ko(o,c)}n=n.sibling}}var _l=8192;function jl(e,n,o){if(e.subtreeFlags&_l)for(e=e.child;e!==null;)hy(e,n,o),e=e.sibling}function hy(e,n,o){switch(e.tag){case 26:jl(e,n,o),e.flags&_l&&(e.memoizedState!==null?Gb(o,An,e.memoizedState,e.memoizedProps):(e=e.stateNode,(n&335544128)===n&&vg(o,e)));break;case 5:jl(e,n,o),e.flags&_l&&(e=e.stateNode,(n&335544128)===n&&vg(o,e));break;case 3:case 4:var c=An;An=Eo(e.stateNode.containerInfo),jl(e,n,o),An=c;break;case 22:e.memoizedState===null&&(c=e.alternate,c!==null&&c.memoizedState!==null?(c=_l,_l=16777216,jl(e,n,o),_l=c):jl(e,n,o));break;case 30:if((e.flags&_l)!==0&&(c=e.memoizedProps.name,c!=null&&c!=="auto")){var m=e.stateNode;m.paired=null,fn===null&&(fn=new Map),fn.set(c,m)}jl(e,n,o);break;default:jl(e,n,o)}}function dy(e){var n=e.alternate;if(n!==null&&(e=n.child,e!==null)){n.child=null;do n=e.sibling,e.sibling=null,e=n;while(e!==null)}}function _o(e){var n=e.deletions;if((e.flags&16)!==0){if(n!==null)for(var o=0;o<n.length;o++){var c=n[o];St=c,py(c,e)}dy(e)}if(e.subtreeFlags&10256)for(e=e.child;e!==null;)my(e),e=e.sibling}function my(e){switch(e.tag){case 0:case 11:case 15:_o(e),e.flags&2048&&qa(9,e,e.return);break;case 3:_o(e);break;case 12:_o(e);break;case 22:var n=e.stateNode;e.memoizedState!==null&&n._visibility&2&&(e.return===null||e.return.tag!==13)?(n._visibility&=-3,mr(e)):_o(e);break;default:_o(e)}}function mr(e){var n=e.deletions;if((e.flags&16)!==0){if(n!==null)for(var o=0;o<n.length;o++){var c=n[o];St=c,py(c,e)}dy(e)}for(e=e.child;e!==null;){switch(n=e,n.tag){case 0:case 11:case 15:qa(8,n,n.return),mr(n);break;case 22:o=n.stateNode,o._visibility&2&&(o._visibility&=-3,mr(n));break;default:mr(n)}e=e.sibling}}function py(e,n){for(;St!==null;){var o=St;switch(o.tag){case 0:case 11:case 15:qa(8,o,n);break;case 23:case 22:if(o.memoizedState!==null&&o.memoizedState.cachePool!==null){var c=o.memoizedState.cachePool.pool;c!=null&&c.refCount++}break;case 24:oo(o.memoizedState.cache)}if(c=o.child,c!==null)c.return=o,St=c;else e:for(o=e;St!==null;){c=St;var m=c.sibling,g=c.return;if(ly(c),c===o){St=null;break e}if(m!==null){m.return=g,St=m;break e}St=g}}}var Ux={getCacheForType:function(e){var n=Et(gt),o=n.data.get(e);return o===void 0&&(o=e(),n.data.set(e,o)),o},cacheSignal:function(){return Et(gt).controller.signal}},Hx=typeof WeakMap=="function"?WeakMap:Map,Je=0,st=null,Ue=null,Be=0,Ie=0,hn=null,Da=!1,fs=!1,sf=!1,da=0,dt=0,Ua=0,Sl=0,pr=0,dn=0,hs=0,jo=null,It=null,of=!1,yr=0,yy=0,gr=1/0,wr=null,Ha=null,ft=0,Rn=null,Nl=null,Jn=0,rf=0,cf=null,gy=null,ds=null,ms=null,ps=null,So=0,vr=null;function mn(){return(Je&2)!==0&&Be!==0?Be&-Be:fe.T!==null?vf():xd()}function wy(){if(dn===0)if((Be&536870912)===0||qe){var e=di;di<<=1,(di&3932160)===0&&(di=262144),dn=e}else dn=536870912;return e=Tt.current,e!==null&&(e.flags|=32),dn}function ys(e,n){if(n!=null){var o=e.stateNode,c=o.ref;c===null&&(c=o.ref=Fy(aa(e.memoizedProps,o))),ms===null&&(ms=[]),ms.push(n.bind(null,c))}}function Ft(e,n,o){(e===st&&(Ie===2||Ie===9)||e.cancelPendingCommit!==null)&&(gs(e,0),La(e,Be,dn,!1)),Qs(e,o),((Je&2)===0||e!==st)&&(e===st&&((Je&2)===0&&(Sl|=o),dt===4&&La(e,Be,dn,!1)),Wn(e))}function vy(e,n,o){if((Je&6)!==0)throw Error(l(327));var c=!o&&(n&127)===0&&(n&e.expiredLanes)===0||Zs(e,n),m=c?Yx(e,n):ff(e,n,!0),g=c;do{if(m===0){fs&&!c&&La(e,n,0,!1);break}else{if(o=e.current.alternate,g&&!Lx(o)){m=ff(e,n,!1),g=!1;continue}if(m===2){if(g=n,e.errorRecoveryDisabledLanes&g)var S=0;else S=e.pendingLanes&-536870913,S=S!==0?S:S&536870912?536870912:0;if(S!==0){n=S;e:{var q=e;m=jo;var Q=q.current.memoizedState.isDehydrated;if(Q&&(gs(q,S).flags|=256),S=ff(q,S,!1),S!==2&&S!==6){if(sf&&!Q){q.errorRecoveryDisabledLanes|=g,Sl|=g,m=4;break e}g=It,It=m,g!==null&&(It===null?It=g:It.push.apply(It,g))}m=S}if(g=!1,m!==2)continue}}if(m===1){gs(e,0),La(e,n,0,!0);break}e:{switch(c=e,g=m,g){case 0:case 1:throw Error(l(345));case 4:if((n&4194048)!==n&&(n&62914560)!==n)break;case 6:La(c,n,dn,!Da);break e;case 2:It=null;break;case 3:case 5:break;default:throw Error(l(329))}if((n&62914560)===n&&(m=yr+300-ln(),10<m)){if(La(c,n,dn,!Da),pi(c,0,!0)!==0)break e;Jn=n,c.timeoutHandle=Cf(xy.bind(null,c,o,It,wr,of,n,dn,Sl,hs,Da,g,"Throttled",-0,0),m);break e}xy(c,o,It,wr,of,n,dn,Sl,hs,Da,g,null,-0,0)}}break}while(!0);Wn(e)}function xy(e,n,o,c,m,g,S,q,Q,le,ce,me,ee,re){e.timeoutHandle=-1;var xe=n.subtreeFlags,je=(g&335544064)===g;if(me=null,(je||xe&8192||(xe&16785408)===16785408)&&(me={stylesheets:null,count:0,imgCount:0,imgBytes:0,suspenseyImages:[],waitingForImages:!0,waitingForViewTransition:!1,unsuspend:Ln},fn=null,hy(n,g,me),je&&(xe=me,je=e.containerInfo,je=(je.nodeType===9?je:je.ownerDocument).__reactViewTransition,je!=null&&(xe.count++,xe.waitingForViewTransition=!0,xe=Ao.bind(xe),je.finished.then(xe,xe))),xe=(g&62914560)===g?yr-ln():(g&4194048)===g?yy-ln():0,xe=Xb(me,xe),xe!==null)){Jn=g,e.cancelPendingCommit=xe(My.bind(null,e,n,g,o,c,m,S,q,Q,le,ce,me,null,ee,re)),La(e,g,S,!le);return}My(e,n,g,o,c,m,S,q,Q,le,ce,me)}function Lx(e){for(var n=e;;){var o=n.tag;if((o===0||o===11||o===15)&&n.flags&16384&&(o=n.updateQueue,o!==null&&(o=o.stores,o!==null)))for(var c=0;c<o.length;c++){var m=o[c],g=m.getSnapshot;m=m.value;try{if(!cn(g(),m))return!1}catch{return!1}}if(o=n.child,n.subtreeFlags&16384&&o!==null)o.return=n,n=o;else{if(n===e)break;for(;n.sibling===null;){if(n.return===null||n.return===e)return!0;n=n.return}n.sibling.return=n.return,n=n.sibling}}return!0}function La(e,n,o,c){n=pd(e,n),n&=~pr,n&=~Sl,e.suspendedLanes|=n,e.pingedLanes&=~n,c&&(e.warmLanes|=n),c=e.expirationTimes;for(var m=n;0<m;){var g=31-on(m),S=1<<g;c[g]=-1,m&=~S}o!==0&&gd(e,o,n)}function xr(){return(Je&6)===0?(No(0),!1):!0}function uf(){if(Ue!==null){if(Ie===0)var e=Ue.return;else e=Ue,ia=ml=null,gu(e),as=null,co=0,e=Ue;for(;e!==null;)Gp(e.alternate,e),e=e.return;Ue=null}}function gs(e,n){var o=e.timeoutHandle;return o!==-1&&(e.timeoutHandle=-1,ub(o)),o=e.cancelPendingCommit,o!==null&&(e.cancelPendingCommit=null,o()),Jn=0,uf(),st=e,Ue=o=sa(e.current,null),Be=n,Ie=0,hn=null,Da=!1,fs=Zs(e,n),sf=!1,hs=dn=pr=Sl=Ua=dt=0,It=jo=null,of=!1,da=pd(e,n),Mi(),o}function by(e,n){Oe=null,fe.H=Pi,n===ns||n===Hi?(n=Mm(),Ie=3):n===lu?(n=Mm(),Ie=4):Ie=n===Tu?8:n!==null&&typeof n=="object"&&typeof n.then=="function"?6:1,hn=n,Ue===null&&(dt=1,er(e,$n(n,e.current)))}function $y(){var e=Tt.current;return e===null?!0:(Be&4194048)===Be?Dt===null:(Be&62914560)===Be||(Be&536870912)!==0?e===Dt:!1}function ky(){var e=fe.H;return fe.H=Pi,e===null?Pi:e}function _y(){var e=fe.A;return fe.A=Ux,e}function br(){dt=4,Da||(Be&4194048)!==Be&&Tt.current!==null||(fs=!0),(Ua&134217727)===0&&(Sl&134217727)===0||st===null||La(st,Be,dn,!1)}function ff(e,n,o){var c=Je;Je|=2;var m=ky(),g=_y();(st!==e||Be!==n)&&(wr=null,gs(e,n)),n=!1;var S=dt;e:do try{if(Ie!==0&&Ue!==null){var q=Ue,Q=hn;switch(Ie){case 8:uf(),S=6;break e;case 3:case 2:case 9:case 6:Tt.current===null&&(n=!0);var le=Ie;if(Ie=0,hn=null,ws(e,q,Q,le),o&&fs){S=0;break e}break;default:le=Ie,Ie=0,hn=null,ws(e,q,Q,le)}}Bx(),S=dt;break}catch(ce){by(e,ce)}while(!0);return n&&e.shellSuspendCounter++,ia=ml=null,Je=c,fe.H=m,fe.A=g,Ue===null&&(st=null,Be=0,Mi()),S}function Bx(){for(;Ue!==null;)jy(Ue)}function Yx(e,n){var o=Je;Je|=2;var c=ky(),m=_y();st!==e||Be!==n?(wr=null,gr=ln()+500,gs(e,n)):fs=Zs(e,n);e:do try{if(Ie!==0&&Ue!==null){n=Ue;var g=hn;t:switch(Ie){case 1:Ie=0,hn=null,ws(e,n,g,1);break;case 2:case 9:if(Sm(g)){Ie=0,hn=null,Sy(n);break}n=function(){Ie!==2&&Ie!==9||st!==e||(Ie=7),Wn(e)},g.then(n,n);break e;case 3:Ie=7;break e;case 4:Ie=5;break e;case 7:Sm(g)?(Ie=0,hn=null,Sy(n)):(Ie=0,hn=null,ws(e,n,g,7));break;case 5:var S=null;switch(Ue.tag){case 26:S=Ue.memoizedState;case 5:case 27:var q=Ue;if(S?gg(S):q.stateNode.complete){Ie=0,hn=null;var Q=q.sibling;if(Q!==null)Ue=Q;else{var le=q.return;le!==null?(Ue=le,$r(le)):Ue=null}break t}}Ie=0,hn=null,ws(e,n,g,5);break;case 6:Ie=0,hn=null,ws(e,n,g,6);break;case 8:uf(),dt=6;break e;default:throw Error(l(462))}}Gx();break}catch(ce){by(e,ce)}while(!0);return ia=ml=null,fe.H=c,fe.A=m,Je=o,Ue!==null?0:(st=null,Be=0,Mi(),dt)}function Gx(){for(;Ue!==null&&!o1();)jy(Ue)}function jy(e){var n=Bp(e.alternate,e,da);e.memoizedProps=e.pendingProps,n===null?$r(e):Ue=n}function Sy(e){var n=e,o=n.alternate;switch(n.tag){case 15:case 0:n=Ap(o,n,n.pendingProps,n.type,void 0,Be);break;case 11:n=Ap(o,n,n.pendingProps,n.type.render,n.ref,Be);break;case 5:gu(n);var c=n;c===_t&&(qe?(Ai(c),c.tag===5&&c.stateNode!=null&&(ot=c.stateNode)):(Ai(c),qe=!0));default:Gp(o,n),n=Ue=pm(n,da),n=Bp(o,n,da)}e.memoizedProps=e.pendingProps,n===null?$r(e):Ue=n}function ws(e,n,o,c){ia=ml=null,gu(n),as=null,co=0;var m=n.return;try{if(Cx(e,m,n,o,Be)){dt=1,er(e,$n(o,e.current)),Ue=null;return}}catch(g){if(m!==null)throw Ue=m,g;dt=1,er(e,$n(o,e.current)),Ue=null;return}n.flags&32768?(qe||c===1?e=!0:fs||(Be&536870912)!==0?e=!1:(Da=e=!0,(c===2||c===9||c===3||c===6)&&(c=Tt.current,c!==null&&c.tag===13&&(c.flags|=16384))),Ny(n,e)):$r(n)}function $r(e){var n=e;do{if((n.flags&32768)!==0){Ny(n,Da);return}e=n.return;var o=Ax(n.alternate,n,da);if(o!==null){Ue=o;return}if(n=n.sibling,n!==null){Ue=n;return}Ue=n=e}while(n!==null);dt===0&&(dt=5)}function Ny(e,n){do{var o=qx(e.alternate,e);if(o!==null){o.flags&=32767,Ue=o;return}if(o=e.return,o!==null&&(o.flags|=32768,o.subtreeFlags=0,o.deletions=null),!n&&(e=e.sibling,e!==null)){Ue=e;return}Ue=e=o}while(e!==null);dt=6,Ue=null}function My(e,n,o,c,m,g,S,q,Q,le,ce,me){e.cancelPendingCommit=null;do kr();while(ft!==0);if((Je&6)!==0)throw Error(l(327));if(n!==null){if(n===e.current)throw Error(l(177));e===st&&(Ue=st=null,Be=0),Nl=n,Rn=e,Jn=o,cf=m,gy=c,Xx(e,n,o,S,q,Q,me)}}function Xx(e,n,o,c,m,g,S){var q=n.lanes|n.childLanes;if(rf=q,q|=Zc,y1(e,o,q,c,m,g),ms=null,(o&335544064)===o?(ps=wx(e),c=10262):(ps=null,c=10256),(n.subtreeFlags&c)!==0||(n.flags&c)!==0?(e.callbackNode=null,e.callbackPriority=0,Wx(fi,function(){return pf(),null})):(e.callbackNode=null,e.callbackPriority=0),rr=!1,c=(n.flags&13878)!==0,(n.subtreeFlags&13878)!==0||c){c=fe.T,fe.T=null,m=ge.p,ge.p=2,g=Je,Je|=4;try{Rx(e,n,o)}finally{Je=g,ge.p=m,fe.T=c}}ft=1,rr?ds=yb(S,e.containerInfo,ps,hf,df,Qx,mf,pf,Zx):(hf(),df(),mf())}function Zx(e){if(ft!==0){var n=Rn.onRecoverableError;n(e,{componentStack:null})}}function Qx(){ft===3&&(ft=0,uy(Nl,Rn),ft=4)}function hf(){if(ft===1){ft=0;var e=Rn,n=Nl,o=Jn,c=(n.flags&13878)!==0;if((n.subtreeFlags&13878)!==0||c){c=fe.T,fe.T=null;var m=ge.p;ge.p=2;var g=Je;Je|=4;try{$o=fr=!1,ry(n,e,o),o=Nf;var S=sm(e.containerInfo),q=o.focusedElem,Q=o.selectionRange;if(S!==q&&q&&q.ownerDocument&&lm(q.ownerDocument.documentElement,q)){if(Q!==null&&Lc(q)){var le=Q.start,ce=Q.end;if(ce===void 0&&(ce=le),"selectionStart"in q)q.selectionStart=le,q.selectionEnd=Math.min(ce,q.value.length);else{var me=q.ownerDocument||document,ee=me&&me.defaultView||window;if(ee.getSelection){var re=ee.getSelection(),xe=q.textContent.length,je=Math.min(Q.start,xe),Ae=Q.end===void 0?je:Math.min(Q.end,xe);!re.extend&&je>Ae&&(S=Ae,Ae=je,je=S);var ae=am(q,je),I=am(q,Ae);if(ae&&I&&(re.rangeCount!==1||re.anchorNode!==ae.node||re.anchorOffset!==ae.offset||re.focusNode!==I.node||re.focusOffset!==I.offset)){var oe=me.createRange();oe.setStart(ae.node,ae.offset),re.removeAllRanges(),je>Ae?(re.addRange(oe),re.extend(I.node,I.offset)):(oe.setEnd(I.node,I.offset),re.addRange(oe))}}}}for(me=[],re=q;re=re.parentNode;)re.nodeType===1&&me.push({element:re,left:re.scrollLeft,top:re.scrollTop});for(typeof q.focus=="function"&&q.focus(),q=0;q<me.length;q++){var de=me[q];de.element.scrollLeft=de.left,de.element.scrollTop=de.top}}Ss=!!Sf,Nf=Sf=null}finally{Je=g,ge.p=m,fe.T=c}}e.current=n,ft=2}}function df(){if(ft===2){ft=0;var e=Rn,n=Nl,o=(n.flags&8772)!==0;if((n.subtreeFlags&8772)!==0||o){o=fe.T,fe.T=null;var c=ge.p;ge.p=2;var m=Je;Je|=4;try{ny(e,n.alternate,n)}finally{Je=m,ge.p=c,fe.T=o}}ft=3}}function mf(){if(ft===4||ft===3){ft=0;var e=ds;ds=null,i1();var n=Rn,o=Nl,c=Jn,m=gy,g=(c&335544064)===c?10262:10256;if((o.subtreeFlags&g)!==0||(o.flags&g)!==0?ft=5:(ft=0,Nl=Rn=null,zy(n,n.pendingLanes)),g=n.pendingLanes,g===0&&(Ha=null),$c(c),o=o.stateNode,sn&&typeof sn.onCommitFiberRoot=="function")try{sn.onCommitFiberRoot(Xs,o,void 0,(o.current.flags&128)===128)}catch{}if(m!==null){o=fe.T,g=ge.p,ge.p=2,fe.T=null;try{for(var S=n.onRecoverableError,q=0;q<m.length;q++){var Q=m[q];S(Q.value,{componentStack:Q.stack})}}finally{fe.T=o,ge.p=g}}if(m=ms,S=ps,ps=null,m!==null&&(ms=null,S===null&&(S=[]),e!==null))for(Q=0;Q<m.length;Q++)o=(0,m[Q])(S),o!==void 0&&e.finished.finally(o);(Jn&3)!==0&&kr(),Wn(n),g=n.pendingLanes,(c&261930)!==0&&(g&42)!==0?n===vr?So++:(So=0,vr=n):(So=0,vr=null),No(0)}}function zy(e,n){(e.pooledCacheLanes&=n)===0&&(n=e.pooledCache,n!=null&&(e.pooledCache=null,oo(n)))}function kr(){return ds!==null&&(ds.skipTransition(),ds=null),hf(),df(),mf(),pf()}function pf(){if(ft!==5)return!1;var e=Rn,n=rf;rf=0;var o=$c(Jn),c=fe.T,m=ge.p;try{ge.p=32>o?32:o,fe.T=null,o=cf,cf=null;var g=Rn,S=Jn;if(ft=0,Nl=Rn=null,Jn=0,(Je&6)!==0)throw Error(l(331));var q=Je;if(Je|=4,my(g.current),fy(g,g.current,S,o),Je=q,No(0,!1),sn&&typeof sn.onPostCommitFiberRoot=="function")try{sn.onPostCommitFiberRoot(Xs,g)}catch{}return!0}finally{ge.p=m,fe.T=c,zy(e,n)}}function Cy(e,n,o){n=$n(o,n),n=Eu(e.stateNode,n,2),e=Ea(e,n,2),e!==null&&(Qs(e,2),Wn(e))}function Fe(e,n,o){if(e.tag===3)Cy(e,e,o);else for(;n!==null;){if(n.tag===3){Cy(n,e,o);break}else if(n.tag===1){var c=n.stateNode;if(typeof n.type.getDerivedStateFromError=="function"||typeof c.componentDidCatch=="function"&&(Ha===null||!Ha.has(c))){e=$n(o,e),o=Sp(2),c=Ea(n,o,2),c!==null&&(Np(o,c,n,e),Qs(c,2),Wn(c));break}}n=n.return}}function yf(e,n,o){var c=e.pingCache;if(c===null){c=e.pingCache=new Hx;var m=new Set;c.set(n,m)}else m=c.get(n),m===void 0&&(m=new Set,c.set(n,m));m.has(o)||(sf=!0,m.add(o),e=Vx.bind(null,e,n,o),n.then(e,e))}function Vx(e,n,o){var c=e.pingCache;c!==null&&c.delete(n),e.pingedLanes|=e.suspendedLanes&o,e.warmLanes&=~o,st===e&&(Be&o)===o&&((dt===4||dt===3&&(Be&62914560)===Be&&300>ln()-yr)&&(Je&2)===0?gs(e,0):pr|=o,hs===Be&&(hs=0)),Wn(e)}function Ey(e,n){n===0&&(n=yd()),e=fl(e,n),e!==null&&(Qs(e,n),Wn(e))}function Kx(e){var n=e.memoizedState,o=0;n!==null&&(o=n.retryLane),Ey(e,o)}function Jx(e,n){var o=0;switch(e.tag){case 31:case 13:var c=e.stateNode,m=e.memoizedState;m!==null&&(o=m.retryLane);break;case 19:c=e.stateNode;break;case 22:c=e.stateNode._retryCache;break;default:throw Error(l(314))}c!==null&&c.delete(n),Ey(e,o)}function Wx(e,n){return wc(e,n)}var vs=null,xs=null,gf=!1,_r=!1,wf=!1,Ba=0;function Wn(e){e!==xs&&e.next===null&&(xs===null?vs=xs=e:xs=xs.next=e),_r=!0,gf||(gf=!0,Fx())}function No(e,n){if(!wf&&_r){wf=!0;do for(var o=!1,c=vs;c!==null;){if(e!==0){var m=c.pendingLanes;if(m===0)var g=0;else{var S=c.suspendedLanes,q=c.pingedLanes;g=(1<<31-on(42|e)+1)-1,g&=m&~(S&~q),g=g&201326741?g&201326741|1:g?g|2:0}g!==0&&(o=!0,qy(c,g))}else g=Be,g=pi(c,c===st?g:0,c.cancelPendingCommit!==null||c.timeoutHandle!==-1),(g&3)===0||Zs(c,g)||(o=!0,qy(c,g));c=c.next}while(o);wf=!1}}function Ix(){Ty()}function Ty(){_r=gf=!1;var e=0;Ba!==0&&cb()&&(e=Ba);for(var n=ln(),o=null,c=vs;c!==null;){var m=c.next,g=Oy(c,n);g===0?(c.next=null,o===null?vs=m:o.next=m,m===null&&(xs=o)):(o=c,(e!==0||(g&3)!==0)&&(_r=!0)),c=m}ft!==0&&ft!==5||No(e),Ba!==0&&(Ba=0)}function Oy(e,n){for(var o=e.suspendedLanes,c=e.pingedLanes,m=e.expirationTimes,g=e.pendingLanes&-62914561;0<g;){var S=31-on(g),q=1<<S,Q=m[S];Q===-1?((q&o)===0||(q&c)!==0)&&(m[S]=p1(q,n)):Q<=n&&(e.expiredLanes|=q),g&=~q}if(n=st,o=Be,o=pi(e,e===n?o:0,e.cancelPendingCommit!==null||e.timeoutHandle!==-1),c=e.callbackNode,o===0||e===n&&(Ie===2||Ie===9)||e.cancelPendingCommit!==null)return c!==null&&c!==null&&vc(c),e.callbackNode=null,e.callbackPriority=0;if((o&3)===0||Zs(e,o)){if(n=o&-o,n===e.callbackPriority)return n;switch(c!==null&&vc(c),$c(o)){case 2:case 8:o=dd;break;case 32:o=fi;break;case 268435456:o=md;break;default:o=fi}return c=Ay.bind(null,e),o=wc(o,c),e.callbackPriority=n,e.callbackNode=o,n}return c!==null&&c!==null&&vc(c),e.callbackPriority=2,e.callbackNode=null,2}function Ay(e,n){if(ft!==0&&ft!==5)return e.callbackNode=null,e.callbackPriority=0,null;var o=e.callbackNode;if(kr()&&e.callbackNode!==o)return null;var c=Be;return c=pi(e,e===st?c:0,e.cancelPendingCommit!==null||e.timeoutHandle!==-1),c===0?null:(vy(e,c,n),Oy(e,ln()),e.callbackNode!=null&&e.callbackNode===o?Ay.bind(null,e):null)}function qy(e,n){if(kr())return null;vy(e,n,!0)}function Fx(){fb(function(){(Je&6)!==0?wc(hd,Ix):Ty()})}function vf(){if(Ba===0){var e=gl;e===0&&(e=hi,hi<<=1,(hi&261888)===0&&(hi=256)),Ba=e}return Ba}function Ry(e){return e==null||typeof e=="symbol"||typeof e=="boolean"?null:typeof e=="function"?e:xi(e)}function Px(e,n,o,c,m){if(n==="submit"&&o&&o.stateNode===m){var g=Ry((m[Vt]||null).action),S=c.submitter;S&&(n=(n=S[Vt]||null)?Ry(n.formAction):S.getAttribute("formAction"),n!==null&&(g=n,S=null));var q=new _i("action","action",null,c,m);e.push({event:q,listeners:[{instance:null,listener:function(){if(c.defaultPrevented){if(Ba!==0){var Q=new FormData(m,S);Su(o,{pending:!0,data:Q,method:m.method,action:g},null,Q)}}else typeof g=="function"&&(q.preventDefault(),Q=new FormData(m,S),Su(o,{pending:!0,data:Q,method:m.method,action:g},g,Q))},currentTarget:m}]})}}for(var xf=0;xf<Xc.length;xf++){var bf=Xc[xf],eb=bf.toLowerCase(),tb=bf[0].toUpperCase()+bf.slice(1);Tn(eb,"on"+tb)}Tn(rm,"onAnimationEnd"),Tn(cm,"onAnimationIteration"),Tn(um,"onAnimationStart"),Tn("dblclick","onDoubleClick"),Tn("focusin","onFocus"),Tn("focusout","onBlur"),Tn(ux,"onTransitionRun"),Tn(fx,"onTransitionStart"),Tn(hx,"onTransitionCancel"),Tn(fm,"onTransitionEnd"),Yl("onMouseEnter",["mouseout","mouseover"]),Yl("onMouseLeave",["mouseout","mouseover"]),Yl("onPointerEnter",["pointerout","pointerover"]),Yl("onPointerLeave",["pointerout","pointerover"]),rl("onChange","change click focusin focusout input keydown keyup selectionchange".split(" ")),rl("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" ")),rl("onBeforeInput",["compositionend","keypress","textInput","paste"]),rl("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" ")),rl("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" ")),rl("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var Mo="abort canplay canplaythrough durationchange emptied encrypted ended error loadeddata loadedmetadata loadstart pause play playing progress ratechange resize seeked seeking stalled suspend timeupdate volumechange waiting".split(" "),nb=new Set("beforetoggle cancel close invalid load scroll scrollend toggle".split(" ").concat(Mo));function Dy(e,n){n=(n&4)!==0;for(var o=0;o<e.length;o++){var c=e[o],m=c.event;c=c.listeners;e:{var g=void 0;if(n)for(var S=c.length-1;0<=S;S--){var q=c[S],Q=q.instance,le=q.currentTarget;if(q=q.listener,Q!==g&&m.isPropagationStopped())break e;g=q,m.currentTarget=le;try{g(m)}catch(ce){Ni(ce)}m.currentTarget=null,g=Q}else for(S=0;S<c.length;S++){if(q=c[S],Q=q.instance,le=q.currentTarget,q=q.listener,Q!==g&&m.isPropagationStopped())break e;g=q,m.currentTarget=le;try{g(m)}catch(ce){Ni(ce)}m.currentTarget=null,g=Q}}}}function He(e,n){var o=n[$d];o===void 0&&(o=n[$d]=new Set);var c=e+"__bubble";o.has(c)||(Uy(n,e,2,!1),o.add(c))}function $f(e,n,o){var c=0;n&&(c|=4),Uy(o,e,c,n)}var jr="_reactListening"+Math.random().toString(36).slice(2);function kf(e){if(!e[jr]){e[jr]=!0,jd.forEach(function(o){o!=="selectionchange"&&(nb.has(o)||$f(o,!1,e),$f(o,!0,e))});var n=e.nodeType===9?e:e.ownerDocument;n===null||n[jr]||(n[jr]=!0,$f("selectionchange",!1,n))}}function Uy(e,n,o,c){switch(Ng(n)){case 2:var m=Kb;break;case 8:m=Jb;break;default:m=Gf}o=m.bind(null,n,o,e),m=void 0,!Cc||n!=="touchstart"&&n!=="touchmove"&&n!=="wheel"||(m=!0),c?m!==void 0?e.addEventListener(n,o,{capture:!0,passive:m}):e.addEventListener(n,o,!0):m!==void 0?e.addEventListener(n,o,{passive:m}):e.addEventListener(n,o,!1)}function _f(e,n,o,c,m){var g=c;if((n&1)===0&&(n&2)===0&&c!==null)e:for(;;){if(c===null)return;var S=c.tag;if(S===3||S===4){var q=c.stateNode.containerInfo;if(q===m)break;if(S===4)for(S=c.return;S!==null;){var Q=S.tag;if((Q===3||Q===4)&&S.stateNode.containerInfo===m)return;S=S.return}for(;q!==null;){if(S=il(q),S===null)return;if(Q=S.tag,Q===5||Q===6||Q===26||Q===27){c=g=S;continue e}q=q.parentNode}}c=c.return}Ud(function(){var le=g,ce=Mc(o),me=[];e:{var ee=hm.get(e);if(ee!==void 0){var re=_i,xe=e;switch(e){case"keypress":if($i(o)===0)break e;case"keydown":case"keyup":re=L1;break;case"focusin":xe="focus",re=Ac;break;case"focusout":xe="blur",re=Ac;break;case"beforeblur":case"afterblur":re=Ac;break;case"click":if(o.button===2)break e;case"auxclick":case"dblclick":case"mousedown":case"mousemove":case"mouseup":case"mouseout":case"mouseover":case"contextmenu":re=Bd;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":re=M1;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":re=Z1;break;case rm:case cm:case um:re=E1;break;case fm:re=V1;break;case"scroll":case"scrollend":re=S1;break;case"wheel":re=J1;break;case"copy":case"cut":case"paste":re=O1;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":re=Gd;break;case"submit":re=G1;break;case"toggle":case"beforetoggle":re=I1}var je=(n&4)!==0,Ae=!je&&(e==="scroll"||e==="scrollend"),ae=je?ee!==null?ee+"Capture":null:ee;je=[];for(var I=le,oe;I!==null;){var de=I;if(oe=de.stateNode,de=de.tag,de!==5&&de!==26&&de!==27||oe===null||ae===null||(de=Js(I,ae),de!=null&&je.push(zo(I,de,oe))),Ae)break;I=I.return}0<je.length&&(ee=new re(ee,xe,null,o,ce),me.push({event:ee,listeners:je}))}}if((n&7)===0){e:{if(re=e==="mouseover"||e==="pointerover",ee=e==="mouseout"||e==="pointerout",re&&o!==Nc&&(xe=o.relatedTarget||o.fromElement)&&(il(xe)||xe[Hl]))break e;(ee||re)&&(xe=ce.window===ce?ce:(re=ce.ownerDocument)?re.defaultView||re.parentWindow:window,ee?(re=o.relatedTarget||o.toElement,ee=le,re=re?il(re):null,re!==null&&(Ae=r(re),je=re.tag,re!==Ae||je!==5&&je!==27&&je!==6)&&(re=null)):(ee=null,re=le),ee!==re&&(je=Bd,de="onMouseLeave",ae="onMouseEnter",I="mouse",(e==="pointerout"||e==="pointerover")&&(je=Gd,de="onPointerLeave",ae="onPointerEnter",I="pointer"),Ae=ee==null?xe:Ks(ee),oe=re==null?xe:Ks(re),xe=new je(de,I+"leave",ee,o,ce),xe.target=Ae,xe.relatedTarget=oe,de=null,il(ce)===le&&(je=new je(ae,I+"enter",re,o,ce),je.target=oe,je.relatedTarget=Ae,de=je),Ae=de,je=ee&&re?z(ee,re,ab):null,ee!==null&&Hy(me,xe,ee,je,!1),re!==null&&Ae!==null&&Hy(me,Ae,re,je,!0)))}e:{if(ee=le?Ks(le):window,re=ee.nodeName&&ee.nodeName.toLowerCase(),re==="select"||re==="input"&&ee.type==="file")var ke=Id;else if(Jd(ee))if(Fd)ke=ix;else{ke=sx;var Ye=lx}else re=ee.nodeName,!re||re.toLowerCase()!=="input"||ee.type!=="checkbox"&&ee.type!=="radio"?le&&Sc(le.elementType)&&(ke=Id):ke=ox;if(ke&&(ke=ke(e,le))){Wd(me,ke,o,ce);break e}Ye&&Ye(e,ee,le)}switch(Ye=le?Ks(le):window,e){case"focusin":(Jd(Ye)||Ye.contentEditable==="true")&&(Kl=Ye,Bc=le,ao=null);break;case"focusout":ao=Bc=Kl=null;break;case"mousedown":Yc=!0;break;case"contextmenu":case"mouseup":case"dragend":Yc=!1,om(me,o,ce);break;case"selectionchange":if(cx)break;case"keydown":case"keyup":om(me,o,ce)}var Ne;if(Rc)e:{switch(e){case"compositionstart":var ze="onCompositionStart";break e;case"compositionend":ze="onCompositionEnd";break e;case"compositionupdate":ze="onCompositionUpdate";break e}ze=void 0}else Vl?Vd(e,o)&&(ze="onCompositionEnd"):e==="keydown"&&o.keyCode===229&&(ze="onCompositionStart");ze&&(Xd&&o.locale!=="ko"&&(Vl||ze!=="onCompositionStart"?ze==="onCompositionEnd"&&Vl&&(Ne=Hd()):($a=ce,Ec="value"in $a?$a.value:$a.textContent,Vl=!0)),Ye=Sr(le,ze),0<Ye.length&&(ze=new Yd(ze,e,null,o,ce),me.push({event:ze,listeners:Ye}),Ne?ze.data=Ne:(Ne=Kd(o),Ne!==null&&(ze.data=Ne)))),(Ne=P1?ex(e,o):tx(e,o))&&(ze=Sr(le,"onBeforeInput"),0<ze.length&&(Ye=new Yd("onBeforeInput","beforeinput",null,o,ce),me.push({event:Ye,listeners:ze}),Ye.data=Ne)),Px(me,e,le,o,ce)}Dy(me,n)})}function zo(e,n,o){return{instance:e,listener:n,currentTarget:o}}function Sr(e,n){for(var o=n+"Capture",c=[];e!==null;){var m=e,g=m.stateNode;if(m=m.tag,m!==5&&m!==26&&m!==27||g===null||(m=Js(e,o),m!=null&&c.unshift(zo(e,m,g)),m=Js(e,n),m!=null&&c.push(zo(e,m,g))),e.tag===3)return c;e=e.return}return[]}function ab(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5&&e.tag!==27);return e||null}function Hy(e,n,o,c,m){for(var g=n._reactName,S=[];o!==null&&o!==c;){var q=o,Q=q.alternate,le=q.stateNode;if(q=q.tag,Q!==null&&Q===c)break;q!==5&&q!==26&&q!==27||le===null||(Q=le,m?(le=Js(o,g),le!=null&&S.unshift(zo(o,le,Q))):m||(le=Js(o,g),le!=null&&S.push(zo(o,le,Q)))),o=o.return}S.length!==0&&e.push({event:n,listeners:S})}var lb=/\r\n?/g,sb=/\u0000|\uFFFD/g;function Ly(e){return(typeof e=="string"?e:""+e).replace(lb,`
|
|
9
|
+
`).replace(sb,"")}function By(e,n){return n=Ly(n),Ly(e)===n}function Pe(e,n,o,c,m,g){switch(o){case"children":if(typeof c=="string")n==="body"||n==="textarea"&&c===""||Xl(e,c);else if(typeof c=="number"||typeof c=="bigint")n!=="body"&&Xl(e,""+c);else return;break;case"className":vi(e,"class",c);break;case"tabIndex":vi(e,"tabindex",c);break;case"dir":case"role":case"viewBox":case"width":case"height":vi(e,o,c);break;case"style":Rd(e,c,g);return;case"data":if(n!=="object"){vi(e,"data",c);break}case"src":case"href":if(c===""&&(n!=="a"||o!=="href")){e.removeAttribute(o);break}if(c==null||typeof c=="function"||typeof c=="symbol"||typeof c=="boolean"){e.removeAttribute(o);break}c=xi(c),e.setAttribute(o,c);break;case"action":case"formAction":if(typeof c=="function"){e.setAttribute(o,"javascript:throw new Error('A React form was unexpectedly submitted. If you called form.submit() manually, consider using form.requestSubmit() instead. If you\\'re trying to use event.stopPropagation() in a submit event handler, consider also calling event.preventDefault().')");break}else typeof g=="function"&&(o==="formAction"?(n!=="input"&&Pe(e,n,"name",m.name,m,null),Pe(e,n,"formEncType",m.formEncType,m,null),Pe(e,n,"formMethod",m.formMethod,m,null),Pe(e,n,"formTarget",m.formTarget,m,null)):(Pe(e,n,"encType",m.encType,m,null),Pe(e,n,"method",m.method,m,null),Pe(e,n,"target",m.target,m,null)));if(c==null||typeof c=="symbol"||typeof c=="boolean"){e.removeAttribute(o);break}c=xi(c),e.setAttribute(o,c);break;case"onClick":c!=null&&(e.onclick=Ln);return;case"onScroll":c!=null&&He("scroll",e);return;case"onScrollEnd":c!=null&&He("scrollend",e);return;case"dangerouslySetInnerHTML":if(c!=null){if(typeof c!="object"||!("__html"in c))throw Error(l(61));if(o=c.__html,o!=null){if(m.children!=null)throw Error(l(60));g?.__html!==o&&(e.innerHTML=o)}}break;case"multiple":e.multiple=c&&typeof c!="function"&&typeof c!="symbol";break;case"muted":e.muted=c&&typeof c!="function"&&typeof c!="symbol";break;case"suppressContentEditableWarning":case"suppressHydrationWarning":case"defaultValue":case"defaultChecked":case"innerHTML":case"ref":break;case"autoFocus":break;case"xlinkHref":if(c==null||typeof c=="function"||typeof c=="boolean"||typeof c=="symbol"){e.removeAttribute("xlink:href");break}o=xi(c),e.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",o);break;case"contentEditable":case"spellCheck":case"draggable":case"value":case"autoReverse":case"externalResourcesRequired":case"focusable":case"preserveAlpha":c!=null&&typeof c!="function"&&typeof c!="symbol"?e.setAttribute(o,c):e.removeAttribute(o);break;case"inert":case"allowFullScreen":case"async":case"autoPlay":case"controls":case"credentialless":case"default":case"defer":case"disabled":case"disablePictureInPicture":case"disableRemotePlayback":case"formNoValidate":case"hidden":case"loop":case"noModule":case"noValidate":case"open":case"playsInline":case"readOnly":case"required":case"reversed":case"scoped":case"seamless":case"itemScope":c&&typeof c!="function"&&typeof c!="symbol"?e.setAttribute(o,""):e.removeAttribute(o);break;case"capture":case"download":c===!0?e.setAttribute(o,""):c!==!1&&c!=null&&typeof c!="function"&&typeof c!="symbol"?e.setAttribute(o,c):e.removeAttribute(o);break;case"cols":case"rows":case"size":case"span":c!=null&&typeof c!="function"&&typeof c!="symbol"&&!isNaN(c)&&1<=c?e.setAttribute(o,c):e.removeAttribute(o);break;case"rowSpan":case"start":c==null||typeof c=="function"||typeof c=="symbol"||isNaN(c)?e.removeAttribute(o):e.setAttribute(o,c);break;case"popover":He("beforetoggle",e),He("toggle",e),wi(e,"popover",c);break;case"xlinkActuate":ta(e,"http://www.w3.org/1999/xlink","xlink:actuate",c);break;case"xlinkArcrole":ta(e,"http://www.w3.org/1999/xlink","xlink:arcrole",c);break;case"xlinkRole":ta(e,"http://www.w3.org/1999/xlink","xlink:role",c);break;case"xlinkShow":ta(e,"http://www.w3.org/1999/xlink","xlink:show",c);break;case"xlinkTitle":ta(e,"http://www.w3.org/1999/xlink","xlink:title",c);break;case"xlinkType":ta(e,"http://www.w3.org/1999/xlink","xlink:type",c);break;case"xmlBase":ta(e,"http://www.w3.org/XML/1998/namespace","xml:base",c);break;case"xmlLang":ta(e,"http://www.w3.org/XML/1998/namespace","xml:lang",c);break;case"xmlSpace":ta(e,"http://www.w3.org/XML/1998/namespace","xml:space",c);break;case"is":wi(e,"is",c);break;case"innerText":case"textContent":return;default:if(!(2<o.length)||o[0]!=="o"&&o[0]!=="O"||o[1]!=="n"&&o[1]!=="N")o=_1.get(o)||o,wi(e,o,c);else return}Ke=!0}function jf(e,n,o,c,m,g){switch(o){case"style":Rd(e,c,g);return;case"dangerouslySetInnerHTML":if(c!=null){if(typeof c!="object"||!("__html"in c))throw Error(l(61));if(o=c.__html,o!=null){if(m.children!=null)throw Error(l(60));g?.__html!==o&&(e.innerHTML=o)}}break;case"children":if(typeof c=="string")Xl(e,c);else if(typeof c=="number"||typeof c=="bigint")Xl(e,""+c);else return;break;case"onScroll":c!=null&&He("scroll",e);return;case"onScrollEnd":c!=null&&He("scrollend",e);return;case"onClick":c!=null&&(e.onclick=Ln);return;case"suppressContentEditableWarning":case"suppressHydrationWarning":case"innerHTML":case"ref":return;case"innerText":case"textContent":return;default:if(!Sd.hasOwnProperty(o))e:{if(o[0]==="o"&&o[1]==="n"&&(m=o.endsWith("Capture"),g=o.slice(2,m?o.length-7:void 0),n=e[Vt]||null,n=n!=null?n[o]:null,typeof n=="function"&&e.removeEventListener(g,n,m),typeof c=="function")){typeof n!="function"&&n!==null&&(o in e?e[o]=null:e.hasAttribute(o)&&e.removeAttribute(o)),e.addEventListener(g,c,m);break e}Ke=!0,o in e?e[o]=c:c===!0?e.setAttribute(o,""):wi(e,o,c)}return}Ke=!0}function qt(e,n,o){switch(n){case"div":case"span":case"svg":case"path":case"a":case"g":case"p":case"li":break;case"img":He("error",e),He("load",e);var c=!1,m=!1,g;for(g in o)if(o.hasOwnProperty(g)){var S=o[g];if(S!=null)switch(g){case"src":c=!0;break;case"srcSet":m=!0;break;case"children":case"dangerouslySetInnerHTML":throw Error(l(137,n));default:Pe(e,n,g,S,o,null)}}m&&Pe(e,n,"srcSet",o.srcSet,o,null),c&&Pe(e,n,"src",o.src,o,null);return;case"input":He("invalid",e);var q=g=S=m=null,Q=null,le=null;for(c in o)if(o.hasOwnProperty(c)){var ce=o[c];if(ce!=null)switch(c){case"name":m=ce;break;case"type":S=ce;break;case"checked":Q=ce;break;case"defaultChecked":le=ce;break;case"value":g=ce;break;case"defaultValue":q=ce;break;case"children":case"dangerouslySetInnerHTML":if(ce!=null)throw Error(l(137,n));break;default:Pe(e,n,c,ce,o,null)}}Td(e,g,q,Q,le,S,m,!1);return;case"select":He("invalid",e),c=S=g=null;for(m in o)if(o.hasOwnProperty(m)&&(q=o[m],q!=null))switch(m){case"value":g=q;break;case"defaultValue":S=q;break;case"multiple":c=q;default:Pe(e,n,m,q,o,null)}n=g,o=S,e.multiple=!!c,n!=null?Gl(e,!!c,n,!1):o!=null&&Gl(e,!!c,o,!0);return;case"textarea":He("invalid",e),g=m=c=null;for(S in o)if(o.hasOwnProperty(S)&&(q=o[S],q!=null))switch(S){case"value":c=q;break;case"defaultValue":m=q;break;case"children":g=q;break;case"dangerouslySetInnerHTML":if(q!=null)throw Error(l(91));break;default:Pe(e,n,S,q,o,null)}Ad(e,c,m,g);return;case"option":for(Q in o)o.hasOwnProperty(Q)&&(c=o[Q],c!=null)&&(Q==="selected"?e.selected=c&&typeof c!="function"&&typeof c!="symbol":Pe(e,n,Q,c,o,null));return;case"dialog":He("beforetoggle",e),He("toggle",e),He("cancel",e),He("close",e);break;case"iframe":case"object":He("load",e);break;case"video":case"audio":for(c=0;c<Mo.length;c++)He(Mo[c],e);break;case"image":He("error",e),He("load",e);break;case"details":He("toggle",e);break;case"embed":case"source":case"link":He("error",e),He("load",e);case"area":case"base":case"br":case"col":case"hr":case"keygen":case"meta":case"param":case"track":case"wbr":case"menuitem":for(le in o)if(o.hasOwnProperty(le)&&(c=o[le],c!=null))switch(le){case"children":case"dangerouslySetInnerHTML":throw Error(l(137,n));default:Pe(e,n,le,c,o,null)}return;default:if(Sc(n)){for(ce in o)o.hasOwnProperty(ce)&&(c=o[ce],c!==void 0&&jf(e,n,ce,c,o,void 0));return}}for(q in o)o.hasOwnProperty(q)&&(c=o[q],c!=null&&Pe(e,n,q,c,o,null))}var ob={};function ib(e,n,o,c){switch(n){case"div":case"span":case"svg":case"path":case"a":case"g":case"p":case"li":break;case"input":var m=null,g=null,S=null,q=null,Q=null,le=null,ce=null;for(re in o){var me=o[re];if(o.hasOwnProperty(re)&&me!=null)switch(re){case"checked":break;case"value":break;case"defaultValue":Q=me;default:c.hasOwnProperty(re)||Pe(e,n,re,null,c,me)}}for(var ee in c){var re=c[ee];if(me=o[ee],c.hasOwnProperty(ee)&&(re!=null||me!=null))switch(ee){case"type":re!==me&&(Ke=!0),g=re;break;case"name":re!==me&&(Ke=!0),m=re;break;case"checked":re!==me&&(Ke=!0),le=re;break;case"defaultChecked":re!==me&&(Ke=!0),ce=re;break;case"value":re!==me&&(Ke=!0),S=re;break;case"defaultValue":re!==me&&(Ke=!0),q=re;break;case"children":case"dangerouslySetInnerHTML":if(re!=null)throw Error(l(137,n));break;default:re!==me&&Pe(e,n,ee,re,c,me)}}_c(e,S,q,Q,le,ce,g,m);return;case"select":re=S=q=ee=null;for(g in o)if(Q=o[g],o.hasOwnProperty(g)&&Q!=null)switch(g){case"value":break;case"multiple":re=Q;default:c.hasOwnProperty(g)||Pe(e,n,g,null,c,Q)}for(m in c)if(g=c[m],Q=o[m],c.hasOwnProperty(m)&&(g!=null||Q!=null))switch(m){case"value":g!==Q&&(Ke=!0),ee=g;break;case"defaultValue":g!==Q&&(Ke=!0),q=g;break;case"multiple":g!==Q&&(Ke=!0),S=g;default:g!==Q&&Pe(e,n,m,g,c,Q)}n=q,o=S,c=re,ee!=null?Gl(e,!!o,ee,!1):!!c!=!!o&&(n!=null?Gl(e,!!o,n,!0):Gl(e,!!o,o?[]:"",!1));return;case"textarea":re=ee=null;for(q in o)if(m=o[q],o.hasOwnProperty(q)&&m!=null&&!c.hasOwnProperty(q))switch(q){case"value":break;case"children":break;default:Pe(e,n,q,null,c,m)}for(S in c)if(m=c[S],g=o[S],c.hasOwnProperty(S)&&(m!=null||g!=null))switch(S){case"value":m!==g&&(Ke=!0),ee=m;break;case"defaultValue":m!==g&&(Ke=!0),re=m;break;case"children":break;case"dangerouslySetInnerHTML":if(m!=null)throw Error(l(91));break;default:m!==g&&Pe(e,n,S,m,c,g)}Od(e,ee,re);return;case"option":for(var xe in o)ee=o[xe],o.hasOwnProperty(xe)&&ee!=null&&!c.hasOwnProperty(xe)&&(xe==="selected"?e.selected=!1:Pe(e,n,xe,null,c,ee));for(Q in c)ee=c[Q],re=o[Q],c.hasOwnProperty(Q)&&ee!==re&&(ee!=null||re!=null)&&(Q==="selected"?(ee!==re&&(Ke=!0),e.selected=ee&&typeof ee!="function"&&typeof ee!="symbol"):Pe(e,n,Q,ee,c,re));return;case"img":case"link":case"area":case"base":case"br":case"col":case"embed":case"hr":case"keygen":case"meta":case"param":case"source":case"track":case"wbr":case"menuitem":for(var je in o)ee=o[je],o.hasOwnProperty(je)&&ee!=null&&!c.hasOwnProperty(je)&&Pe(e,n,je,null,c,ee);for(le in c)if(ee=c[le],re=o[le],c.hasOwnProperty(le)&&ee!==re&&(ee!=null||re!=null))switch(le){case"children":case"dangerouslySetInnerHTML":if(ee!=null)throw Error(l(137,n));break;default:Pe(e,n,le,ee,c,re)}return;default:if(Sc(n)){for(var Ae in o)ee=o[Ae],o.hasOwnProperty(Ae)&&ee!==void 0&&!c.hasOwnProperty(Ae)&&jf(e,n,Ae,void 0,c,ee);for(ce in c)ee=c[ce],re=o[ce],!c.hasOwnProperty(ce)||ee===re||ee===void 0&&re===void 0||jf(e,n,ce,ee,c,re);return}}for(var ae in o)ee=o[ae],o.hasOwnProperty(ae)&&ee!=null&&!c.hasOwnProperty(ae)&&Pe(e,n,ae,null,c,ee);for(me in c)ee=c[me],re=o[me],!c.hasOwnProperty(me)||ee===re||ee==null&&re==null||Pe(e,n,me,ee,c,re)}function Yy(e){switch(e){case"css":case"script":case"font":case"img":case"image":case"input":case"link":return!0;default:return!1}}function rb(){if(typeof performance.getEntriesByType=="function"){for(var e=0,n=0,o=performance.getEntriesByType("resource"),c=0;c<o.length;c++){var m=o[c],g=m.transferSize,S=m.initiatorType,q=m.duration;if(g&&q&&Yy(S)){for(S=0,q=m.responseEnd,c+=1;c<o.length;c++){var Q=o[c],le=Q.startTime;if(le>q)break;var ce=Q.transferSize,me=Q.initiatorType;ce&&Yy(me)&&(Q=Q.responseEnd,S+=ce*(Q<q?1:(q-le)/(Q-le)))}if(--c,n+=8*(g+S)/(m.duration/1e3),e++,10<e)break}}if(0<e)return n/e/1e6}return navigator.connection&&(e=navigator.connection.downlink,typeof e=="number")?e:5}var Sf=null,Nf=null;function Co(e){return e.nodeType===9?e:e.ownerDocument}function Gy(e){switch(e){case"http://www.w3.org/2000/svg":return 1;case"http://www.w3.org/1998/Math/MathML":return 2;default:return 0}}function Xy(e,n){if(e===0)switch(n){case"svg":return 1;case"math":return 2;default:return 0}return e===1&&n==="foreignObject"?0:e}function Zy(e,n,o,c){return o=Co(o).createElement(e),o[Ct]=c,o[Vt]=n,qt(o,e,n),kt(o),o}function Mf(e,n){return e==="textarea"||e==="noscript"||typeof n.children=="string"||typeof n.children=="number"||typeof n.children=="bigint"||typeof n.dangerouslySetInnerHTML=="object"&&n.dangerouslySetInnerHTML!==null&&n.dangerouslySetInnerHTML.__html!=null}var zf=null;function cb(){var e=window.event;return e&&e.type==="popstate"?e===zf?!1:(zf=e,!0):(zf=null,!1)}var Cf=typeof setTimeout=="function"?setTimeout:void 0,ub=typeof clearTimeout=="function"?clearTimeout:void 0,Qy=typeof Promise=="function"?Promise:void 0,Vy=typeof requestAnimationFrame=="function"?requestAnimationFrame:Cf,fb=typeof queueMicrotask=="function"?queueMicrotask:typeof Qy<"u"?function(e){return Qy.resolve(null).then(e).catch(hb)}:Cf;function hb(e){setTimeout(function(){throw e})}function Ya(e){return e==="head"}function Ky(e,n){var o=n,c=0;do{var m=o.nextSibling;if(e.removeChild(o),m&&m.nodeType===8)if(o=m.data,o==="/$"||o==="/&"){if(c===0){e.removeChild(m),Ns(n);return}c--}else if(o==="$"||o==="$?"||o==="$~"||o==="$!"||o==="&")c++;else if(o==="html")Uf(e.ownerDocument.documentElement);else if(o==="head"){o=e.ownerDocument.head,Uf(o);for(var g=o.firstChild;g;){var S=g.nextSibling,q=g.nodeName;g[Vs]||q==="SCRIPT"||q==="STYLE"||q==="LINK"&&g.rel.toLowerCase()==="stylesheet"||o.removeChild(g),g=S}}else o==="body"&&Uf(e.ownerDocument.body);o=m}while(o);Ns(n)}function Jy(e,n){var o=e;e=0;do{var c=o.nextSibling;if(o.nodeType===1?n?(o._stashedDisplay=o.style.display,o.style.display="none"):(o.style.display=o._stashedDisplay||"",o.getAttribute("style")===""&&o.removeAttribute("style")):o.nodeType===3&&(n?(o._stashedText=o.nodeValue,o.nodeValue=""):o.nodeValue=o._stashedText||""),c&&c.nodeType===8)if(o=c.data,o==="/$"){if(e===0)break;e--}else o!=="$"&&o!=="$?"&&o!=="$~"&&o!=="$!"||e++;o=c}while(o)}function Wy(e,n,o){if(n=CSS.escape(n)!==n?"r-"+btoa(n).replace(/=/g,""):n,e.style.viewTransitionName=n,o!=null&&(e.style.viewTransitionClass=o),o=getComputedStyle(e),o.display==="inline"){if(n=e.getClientRects(),n.length===1)var c=1;else for(var m=c=0;m<n.length;m++){var g=n[m];0<g.width&&0<g.height&&c++}c===1&&(e=e.style,e.display=n.length===1?"inline-block":"block",e.marginTop="-"+o.paddingTop,e.marginBottom="-"+o.paddingBottom)}}function Iy(e,n){e=e.style,n=n.style;var o=n!=null?n.hasOwnProperty("viewTransitionName")?n.viewTransitionName:n.hasOwnProperty("view-transition-name")?n["view-transition-name"]:null:null;e.viewTransitionName=o==null||typeof o=="boolean"?"":(""+o).trim(),o=n!=null?n.hasOwnProperty("viewTransitionClass")?n.viewTransitionClass:n.hasOwnProperty("view-transition-class")?n["view-transition-class"]:null:null,e.viewTransitionClass=o==null||typeof o=="boolean"?"":(""+o).trim(),e.display==="inline-block"&&(n==null?e.display=e.margin="":(o=n.display,e.display=o==null||typeof o=="boolean"?"":o,o=n.margin,o!=null?e.margin=o:(o=n.hasOwnProperty("marginTop")?n.marginTop:n["margin-top"],e.marginTop=o==null||typeof o=="boolean"?"":o,n=n.hasOwnProperty("marginBottom")?n.marginBottom:n["margin-bottom"],e.marginBottom=n==null||typeof n=="boolean"?"":n)))}function db(e,n,o){return o=o.ownerDocument.defaultView,{rect:e,abs:n.position==="absolute"||n.position==="fixed",clip:n.clipPath!=="none"||n.overflow!=="visible"||n.filter!=="none"||n.mask!=="none"||n.mask!=="none"||n.borderRadius!=="0px",view:0<=e.bottom&&0<=e.right&&e.top<=o.innerHeight&&e.left<=o.innerWidth}}function Ef(e){var n=e.getBoundingClientRect(),o=getComputedStyle(e);return db(n,o,e)}function mb(e){return e.documentElement.clientHeight}function pb(e){this.addEventListener("load",e),this.addEventListener("error",e)}function yb(e,n,o,c,m,g,S,q,Q){var le=n.nodeType===9?n:n.ownerDocument;try{var ce=le.startViewTransition({update:function(){var ee=le.defaultView,re=ee.navigation&&ee.navigation.transition,xe=le.fonts.status;c();var je=[];if(xe==="loaded"&&(mb(le),le.fonts.status==="loading"&&je.push(le.fonts.ready)),xe=je.length,e!==null)for(var Ae=e.suspenseyImages,ae=0,I=0;I<Ae.length;I++){var oe=Ae[I];if(!oe.complete){var de=oe.getBoundingClientRect();if(0<de.bottom&&0<de.right&&de.top<ee.innerHeight&&de.left<ee.innerWidth){if(ae+=wg(oe),ae>zr){je.length=xe;break}oe=new Promise(pb.bind(oe)),je.push(oe)}}}if(0<je.length)return ee=Promise.race([Promise.all(je),new Promise(function(ke){return setTimeout(ke,500)})]).then(m,m),(re?Promise.allSettled([re.finished,ee]):ee).then(g,g);if(m(),re)return re.finished.then(g,g);g()},types:o});le.__reactViewTransition=ce;var me=[];return ce.ready.then(function(){for(var ee=le.documentElement.getAnimations({subtree:!0}),re=0;re<ee.length;re++){var xe=ee[re],je=xe.effect,Ae=je.pseudoElement;if(Ae!=null&&Ae.startsWith("::view-transition")){me.push(xe),xe=je.getKeyframes();for(var ae=Ae=void 0,I=!0,oe=0;oe<xe.length;oe++){var de=xe[oe],ke=de.width;if(Ae===void 0)Ae=ke;else if(Ae!==ke){I=!1;break}if(ke=de.height,ae===void 0)ae=ke;else if(ae!==ke){I=!1;break}delete de.width,delete de.height,de.transform==="none"&&delete de.transform}I&&Ae!==void 0&&ae!==void 0&&(je.setKeyframes(xe),I=getComputedStyle(je.target,je.pseudoElement),I.width!==Ae||I.height!==ae)&&(I=xe[0],I.width=Ae,I.height=ae,I=xe[xe.length-1],I.width=Ae,I.height=ae,je.setKeyframes(xe))}}S()},function(ee){le.__reactViewTransition===ce&&(le.__reactViewTransition=null);try{typeof ee=="object"&&ee!==null&&ee.name==="InvalidStateError"&&(ee.message==="View transition was skipped because document visibility state is hidden."||ee.message==="Skipping view transition because document visibility state has become hidden."||ee.message==="Skipping view transition because viewport size changed."||ee.message==="Transition was aborted because of invalid state")&&(ee=null),ee!==null&&Q(ee)}finally{c(),m(),S()}}),ce.finished.finally(function(){for(var ee=0;ee<me.length;ee++)me[ee].cancel();le.__reactViewTransition===ce&&(le.__reactViewTransition=null),q()}),ce}catch{return c(),m(),S(),null}}function Ml(e,n){this._scope=document.documentElement,this._selector="::view-transition-"+e+"("+n+")"}Ml.prototype.animate=function(e,n){return n=typeof n=="number"?{duration:n}:E({},n),n.pseudoElement=this._selector,this._scope.animate(e,n)},Ml.prototype.getAnimations=function(){for(var e=this._scope,n=this._selector,o=e.getAnimations({subtree:!0}),c=[],m=0;m<o.length;m++){var g=o[m].effect;g!==null&&g.target===e&&g.pseudoElement===n&&c.push(o[m])}return c},Ml.prototype.getComputedStyle=function(){return getComputedStyle(this._scope,this._selector)};function Fy(e){return{name:e,group:new Ml("group",e),imagePair:new Ml("image-pair",e),old:new Ml("old",e),new:new Ml("new",e)}}function pn(e){this._fragmentFiber=e,this._observers=this._eventListeners=null}pn.prototype.addEventListener=function(e,n,o){var c=null,m=null;if(!(o!=null&&typeof o!="boolean"&&(c=o.signal||null,c!==null&&c.aborted))){this._eventListeners===null&&(this._eventListeners=[]);var g=this._eventListeners;if(eg(g,e,n,o)===-1){var S=this,q=n;o!=null&&typeof o!="boolean"&&o.once===!0&&(q=function(Q){S.removeEventListener(e,n,o),typeof n=="function"?n.call(this,Q):n.handleEvent(Q)}),c!==null&&(m=S.removeEventListener.bind(S,e,n,o),c.addEventListener("abort",m,{once:!0}),m=c.removeEventListener.bind(c,"abort",m)),c=bs(o),g.push({type:e,listener:n,optionsOrUseCapture:o,attachedListener:q,cleanup:m}),y(this._fragmentFiber.child,!1,gb,e,q,c)}this._eventListeners=g}};function gb(e,n,o,c){return $(e).addEventListener(n,o,c),!1}pn.prototype.removeEventListener=function(e,n,o){var c=this._eventListeners;if(c!==null&&(n=eg(c,e,n,o),n!==-1)){var m=c[n];o=m.attachedListener;var g=m.cleanup;m=bs(m.optionsOrUseCapture),y(this._fragmentFiber.child,!1,wb,e,o,m),c.splice(n,1),g!==null&&g()}};function wb(e,n,o,c){return $(e).removeEventListener(n,o,c),!1}function bs(e){return e!=null&&typeof e!="boolean"&&(e.once===!0||e.signal instanceof AbortSignal)?{capture:e.capture,passive:e.passive}:e}function Py(e){return e==null?"c=0":typeof e=="boolean"?"c="+(e?"1":"0"):"c="+(e.capture?"1":"0")}function eg(e,n,o,c){if(e.length===0)return-1;c=Py(c);for(var m=0;m<e.length;m++){var g=e[m];if(g.type===n&&g.listener===o&&Py(g.optionsOrUseCapture)===c)return m}return-1}pn.prototype.dispatchEvent=function(e){var n=w(this._fragmentFiber);if(n===null)return!0;n=$(n);var o=this._eventListeners;if(o!==null&&0<o.length||!e.bubbles){var c=n.nodeType===9?n.createComment(""):document.createTextNode("");if(o)for(var m=0;m<o.length;m++){var g=o[m];c.addEventListener(g.type,g.attachedListener,bs(g.optionsOrUseCapture))}if(n.appendChild(c),e=c.dispatchEvent(e),o)for(m=0;m<o.length;m++)g=o[m],c.removeEventListener(g.type,g.attachedListener,bs(g.optionsOrUseCapture));return n.removeChild(c),e}return n.dispatchEvent(e)},pn.prototype.focus=function(e){y(this._fragmentFiber.child,!0,tg,e,void 0,void 0)};function tg(e,n){return e.tag===6?!1:(e=$(e),Cb(e,n))}pn.prototype.focusLast=function(e){var n=[];y(this._fragmentFiber.child,!0,Tf,n,void 0,void 0);for(var o=n.length-1;0<=o&&!tg(n[o],e);o--);};function Tf(e,n){return n.push(e),!1}pn.prototype.blur=function(){var e=w(this._fragmentFiber);e!==null&&(e=$(e),e=Co(e).activeElement,e!==null&&y(this._fragmentFiber.child,!1,vb,e,void 0,void 0))};function vb(e,n){return e.tag===6?!1:(e=$(e),e===n||e.contains(n)?(n.blur(),!0):!1)}pn.prototype.observeUsing=function(e){this._observers===null&&(this._observers=new Set),this._observers.add(e),y(this._fragmentFiber.child,!1,xb,e,void 0,void 0)};function xb(e,n){return e.tag===6||(e=$(e),n.observe(e)),!1}pn.prototype.unobserveUsing=function(e){var n=this._observers;if(n!==null&&n.has(e)){n.delete(e),y(this._fragmentFiber.child,!1,bb,e,void 0,void 0);for(var o=n=0;o<Dn.length;o++){var c=Dn[o];c.fragmentInstance===this&&c.observer===e?e.unobserve(c.instance):Dn[n++]=c}Dn.length=n}};function bb(e,n){return e.tag===6||(e=$(e),n.unobserve(e)),!1}var Dn=[],Of=!1;function $b(e,n,o){Dn.push({fragmentInstance:e,observer:n,instance:o}),Of||(Of=!0,Eb(function(){Of=!1;var c=Dn;Dn=[];for(var m=0;m<c.length;m++){var g=c[m];g.observer.unobserve(g.instance)}}))}pn.prototype.getClientRects=function(){var e=[];return y(this._fragmentFiber.child,!1,kb,e,void 0,void 0),e};function kb(e,n){if(e.tag===6){e=e.stateNode;var o=e.ownerDocument.createRange();o.selectNodeContents(e),n.push.apply(n,o.getClientRects())}else e=$(e),n.push.apply(n,e.getClientRects());return!1}pn.prototype.getRootNode=function(e){var n=w(this._fragmentFiber);return n===null?this:$(n).getRootNode(e)},pn.prototype.compareDocumentPosition=function(e){var n=w(this._fragmentFiber);if(n===null)return Node.DOCUMENT_POSITION_DISCONNECTED;var o=[];y(this._fragmentFiber.child,!1,Tf,o,void 0,void 0);var c=$(n);if(o.length===0){if(o=c,x(this._fragmentFiber)){e:{for(n=this._fragmentFiber.return;n!==null;){if(n.tag===4){n=n.stateNode.containerInfo;break e}if(n.tag===3||n.tag===5||n.tag===27)break;n=n.return}n=null}n!=null&&(o=n)}n=this._fragmentFiber;var m=c=o.compareDocumentPosition(e);return o===e?m=Node.DOCUMENT_POSITION_CONTAINS:c&Node.DOCUMENT_POSITION_CONTAINED_BY&&(o=b(n)[1],o===null?m=Node.DOCUMENT_POSITION_PRECEDING:(e=$(o).compareDocumentPosition(e),m=e===0||e&Node.DOCUMENT_POSITION_FOLLOWING?Node.DOCUMENT_POSITION_FOLLOWING:Node.DOCUMENT_POSITION_PRECEDING)),m|=Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC}n=$(o[0]),m=$(o[o.length-1]);var g=x(this._fragmentFiber)?n.parentElement:c;if(g==null)return Node.DOCUMENT_POSITION_DISCONNECTED;c=g.compareDocumentPosition(n)&Node.DOCUMENT_POSITION_CONTAINED_BY,g=g.compareDocumentPosition(m)&Node.DOCUMENT_POSITION_CONTAINED_BY;var S=n.compareDocumentPosition(e),q=m.compareDocumentPosition(e),Q=S&Node.DOCUMENT_POSITION_CONTAINED_BY||q&Node.DOCUMENT_POSITION_CONTAINED_BY;return q=c&&g&&S&Node.DOCUMENT_POSITION_FOLLOWING&&q&Node.DOCUMENT_POSITION_PRECEDING,n=c&&n===e||g&&m===e||Q||q?Node.DOCUMENT_POSITION_CONTAINED_BY:!c&&n===e||!g&&m===e?Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC:S,n&Node.DOCUMENT_POSITION_DISCONNECTED||n&Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC||_b(n,this._fragmentFiber,o[0],o[o.length-1],e)?n:Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC};function _b(e,n,o,c,m){var g=il(m);if(e&Node.DOCUMENT_POSITION_CONTAINED_BY){if(o=!!g)e:{for(;g!==null;){if(g.tag===7&&(g===n||g.alternate===n)){o=!0;break e}g=g.return}o=!1}return o}if(e&Node.DOCUMENT_POSITION_CONTAINS){if(g===null)return g=m.ownerDocument,m===g||m===g.documentElement||m===g.body;e:{for(g=n,n=w(n);g!==null;){if(!(g.tag!==5&&g.tag!==3&&g.tag!==27||g!==n&&g.alternate!==n)){g=!0;break e}g=g.return}g=!1}return g}return e&Node.DOCUMENT_POSITION_PRECEDING?((n=!!g)&&!(n=g===o)&&(n=z(o,g,A),n===null?n=!1:(y(n,!0,N,g,o),g=_,_=null,n=g!==null)),n):e&Node.DOCUMENT_POSITION_FOLLOWING?((n=!!g)&&!(n=g===c)&&(n=z(c,g,A),n===null?n=!1:(y(n,!0,M,g,c),g=_,j=_=null,n=g!==null)),n):!1}function ng(e,n){var o=e.ownerDocument.createRange();o.selectNodeContents(e),e=o.getBoundingClientRect(),window.scrollTo(window.scrollX+e.left,n?window.scrollY+e.top:window.scrollY+e.bottom-window.innerHeight)}pn.prototype.scrollIntoView=function(e){if(typeof e=="object")throw Error(l(566));var n=[];y(this._fragmentFiber.child,!1,Tf,n,void 0,void 0);var o=e!==!1;if(n.length===0){var c=b(this._fragmentFiber);if(c=o?c[1]||c[0]||w(this._fragmentFiber):c[0]||c[1],c===null)return;if(c.tag===6){e=$(c),ng(e,o);return}if(c=$(c),c.nodeType!==9){if(c.nodeType===11){o="host"in c?c.host:null,o!==null&&o.scrollIntoView(e);return}c.scrollIntoView(e)}}for(c=o?n.length-1:0;c!==(o?-1:n.length);){var m=n[c];m.tag===6?(m=$(m),ng(m,o)):$(m).scrollIntoView(e),c+=o?-1:1}};function jb(e,n){return e=$(e),ag(e,n),!1}function ag(e,n){e.reactFragments==null&&(e.reactFragments=new Set),e.reactFragments.add(n)}function lg(e,n){var o=n._eventListeners;if(o!==null)for(var c=0;c<o.length;c++){var m=o[c];e.addEventListener(m.type,m.attachedListener,bs(m.optionsOrUseCapture))}e.nodeType!==3&&(o=n._observers,o!==null&&o.forEach(function(g){for(var S=0,q=0;q<Dn.length;q++){var Q=Dn[q];(Q.fragmentInstance!==n||Q.observer!==g||Q.instance!==e)&&(Dn[S++]=Q)}Dn.length=S,g.observe(e)}),ag(e,n))}function Sb(e,n){var o=n._eventListeners;if(o!==null)for(var c=0;c<o.length;c++){var m=o[c];e.removeEventListener(m.type,m.attachedListener,bs(m.optionsOrUseCapture))}e.nodeType!==3&&(o=n._observers,o!==null&&o.forEach(function(g){typeof g.rootMargin=="string"?$b(n,g,e):g.unobserve(e)}),e.reactFragments!=null&&e.reactFragments.delete(n))}function Af(e){var n=e.firstChild;for(n&&n.nodeType===10&&(n=n.nextSibling);n;){var o=n;switch(n=n.nextSibling,o.nodeName){case"HTML":case"HEAD":case"BODY":Af(o),gi(o);continue;case"SCRIPT":case"STYLE":continue;case"LINK":if(o.rel.toLowerCase()==="stylesheet")continue}e.removeChild(o)}}function Nb(e,n,o,c){for(;e.nodeType===1;){var m=o;if(e.nodeName.toLowerCase()!==n.toLowerCase()){if(!c&&(e.nodeName!=="INPUT"||e.type!=="hidden"))break}else if(c){if(!e[Vs])switch(n){case"meta":if(!e.hasAttribute("itemprop"))break;return e;case"link":if(g=e.getAttribute("rel"),g==="stylesheet"&&e.hasAttribute("data-precedence"))break;if(g!==m.rel||e.getAttribute("href")!==(m.href==null||m.href===""?null:m.href)||e.getAttribute("crossorigin")!==(m.crossOrigin==null?null:m.crossOrigin)||e.getAttribute("title")!==(m.title==null?null:m.title))break;return e;case"style":if(e.hasAttribute("data-precedence"))break;return e;case"script":if(g=e.getAttribute("src"),(g!==(m.src==null?null:m.src)||e.getAttribute("type")!==(m.type==null?null:m.type)||e.getAttribute("crossorigin")!==(m.crossOrigin==null?null:m.crossOrigin))&&g&&e.hasAttribute("async")&&!e.hasAttribute("itemprop"))break;return e;default:return e}}else if(n==="input"&&e.type==="hidden"){var g=m.name==null?null:""+m.name;if(m.type==="hidden"&&e.getAttribute("name")===g)return e}else return e;if(e=Nn(e.nextSibling),e===null)break}return null}function Mb(e,n,o){if(n==="")return null;for(;e.nodeType!==3;)if((e.nodeType!==1||e.nodeName!=="INPUT"||e.type!=="hidden")&&!o||(e=Nn(e.nextSibling),e===null))return null;return e}function sg(e,n){for(;e.nodeType!==8;)if((e.nodeType!==1||e.nodeName!=="INPUT"||e.type!=="hidden")&&!n||(e=Nn(e.nextSibling),e===null))return null;return e}function qf(e){return e.data==="$?"||e.data==="$~"}function Rf(e){return e.data==="$!"||e.data==="$?"&&e.ownerDocument.readyState!=="loading"}function zb(e,n){var o=e.ownerDocument;if(e.data==="$~")e._reactRetry=n;else if(e.data!=="$?"||o.readyState!=="loading")n();else{var c=function(){n(),o.removeEventListener("DOMContentLoaded",c)};o.addEventListener("DOMContentLoaded",c),e._reactRetry=c}}function Nn(e){for(;e!=null;e=e.nextSibling){var n=e.nodeType;if(n===1||n===3)break;if(n===8){if(n=e.data,n==="$"||n==="$!"||n==="$?"||n==="$~"||n==="&"||n==="F!"||n==="F")break;if(n==="/$"||n==="/&")return null}}return e}var Df=null;function og(e){e=e.nextSibling;for(var n=0;e;){if(e.nodeType===8){var o=e.data;if(o==="/$"||o==="/&"){if(n===0)return Nn(e.nextSibling);n--}else o!=="$"&&o!=="$!"&&o!=="$?"&&o!=="$~"&&o!=="&"||n++}e=e.nextSibling}return null}function ig(e){e=e.previousSibling;for(var n=0;e;){if(e.nodeType===8){var o=e.data;if(o==="$"||o==="$!"||o==="$?"||o==="$~"||o==="&"){if(n===0)return e;n--}else o!=="/$"&&o!=="/&"||n++}e=e.previousSibling}return null}function Cb(e,n){function o(){c=!0}if(e.ownerDocument.activeElement===e)return!0;var c=!1;try{e.ownerDocument.addEventListener("focus",o,!0),(e.focus||HTMLElement.prototype.focus).call(e,n)}finally{e.ownerDocument.removeEventListener("focus",o,!0)}return c}function Eb(e){Vy(function(){Vy(function(n){return e(n)})})}function rg(e,n,o){switch(n=Co(o),e){case"html":if(e=n.documentElement,!e)throw Error(l(452));return e;case"head":if(e=n.head,!e)throw Error(l(453));return e;case"body":if(e=n.body,!e)throw Error(l(454));return e;default:throw Error(l(451))}}function cg(e,n,o){for(var c in o){var m=o[c];o.hasOwnProperty(c)&&m!=null&&Pe(e,n,c,null,ob,m)}o.dangerouslySetInnerHTML!=null&&(e.textContent=""),e.onclick===Ln&&(e.onclick=null),gi(e)}function Uf(e){for(var n=e.attributes;n.length;)e.removeAttributeNode(n[0]);gi(e)}var Mn=new Map,ug=new Set;function Eo(e){if(typeof e.getRootNode=="function"){var n=e.getRootNode();if(n.nodeType===9||n.nodeType===11)return n}return e.nodeType===9?e:e.ownerDocument}var ma=ge.d;ge.d={f:Tb,r:Ob,D:Ab,C:qb,L:Rb,m:Db,X:Hb,S:Ub,M:Lb};function Tb(){var e=ma.f(),n=xr();return e||n}function Ob(e){var n=Ll(e);n!==null&&n.tag===5&&n.type==="form"?hp(n):ma.r(e)}var $s=typeof document>"u"?null:document;function fg(e,n,o){var c=$s;if(c&&typeof n=="string"&&n){var m=xn(n);m='link[rel="'+e+'"][href="'+m+'"]',typeof o=="string"&&(m+='[crossorigin="'+o+'"]'),ug.has(m)||(ug.add(m),e={rel:e,crossOrigin:o,href:n},c.querySelector(m)===null&&(n=c.createElement("link"),qt(n,"link",e),kt(n),c.head.appendChild(n)))}}function Ab(e){ma.D(e),fg("dns-prefetch",e,null)}function qb(e,n){ma.C(e,n),fg("preconnect",e,n)}function Rb(e,n,o){ma.L(e,n,o);var c=$s;if(c&&e&&n){var m='link[rel="preload"][as="'+xn(n)+'"]';n==="image"&&o&&o.imageSrcSet?(m+='[imagesrcset="'+xn(o.imageSrcSet)+'"]',typeof o.imageSizes=="string"&&(m+='[imagesizes="'+xn(o.imageSizes)+'"]')):m+='[href="'+xn(e)+'"]';var g=m;switch(n){case"style":g=ks(e);break;case"script":g=_s(e)}if(!(Mn.has(g)||(e=E({rel:"preload",href:n==="image"&&o&&o.imageSrcSet?void 0:e,as:n},o),Mn.set(g,e),c.querySelector(m)!==null||n==="style"&&c.querySelector(To(g))||n==="script"&&c.querySelector(Oo(g))))){var S=c.createElement("link");qt(S,"link",e),n==="style"&&(S[yi]=!0,S.onload=S.onerror=function(){_d(S)}),kt(S),c.head.appendChild(S)}}}function Db(e,n){ma.m(e,n);var o=$s;if(o&&e){var c=n&&typeof n.as=="string"?n.as:"script",m='link[rel="modulepreload"][as="'+xn(c)+'"][href="'+xn(e)+'"]',g=m;switch(c){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":g=_s(e)}if(!Mn.has(g)&&(e=E({rel:"modulepreload",href:e},n),Mn.set(g,e),o.querySelector(m)===null)){switch(c){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":if(o.querySelector(Oo(g)))return}c=o.createElement("link"),qt(c,"link",e),kt(c),o.head.appendChild(c)}}}function Ub(e,n,o){ma.S(e,n,o);var c=$s;if(c&&e){var m=Bl(c).hoistableStyles,g=ks(e);n=n||"default";var S=m.get(g);if(!S){var q={loading:0,preload:null};if(S=c.querySelector(To(g)))q.loading=5;else{e=E({rel:"stylesheet",href:e,"data-precedence":n},o),(o=Mn.get(g))&&Hf(e,o);var Q=S=c.createElement("link");kt(Q),qt(Q,"link",e),Q._p=new Promise(function(le,ce){Q.onload=le,Q.onerror=ce}),Q.addEventListener("load",function(){q.loading|=1}),Q.addEventListener("error",function(){q.loading|=2}),q.loading|=4,Nr(S,n,c)}S={type:"stylesheet",instance:S,count:1,state:q},m.set(g,S)}}}function Hb(e,n){ma.X(e,n);var o=$s;if(o&&e){var c=Bl(o).hoistableScripts,m=_s(e),g=c.get(m);g||(g=o.querySelector(Oo(m)),g||(e=E({src:e,async:!0},n),(n=Mn.get(m))&&Lf(e,n),g=o.createElement("script"),kt(g),qt(g,"link",e),o.head.appendChild(g)),g={type:"script",instance:g,count:1,state:null},c.set(m,g))}}function Lb(e,n){ma.M(e,n);var o=$s;if(o&&e){var c=Bl(o).hoistableScripts,m=_s(e),g=c.get(m);g||(g=o.querySelector(Oo(m)),g||(e=E({src:e,async:!0,type:"module"},n),(n=Mn.get(m))&&Lf(e,n),g=o.createElement("script"),kt(g),qt(g,"link",e),o.head.appendChild(g)),g={type:"script",instance:g,count:1,state:null},c.set(m,g))}}function hg(e,n,o,c){var m=(m=ct.current)?Eo(m):null;if(!m)throw Error(l(446));switch(e){case"meta":case"title":return null;case"style":return typeof o.precedence=="string"&&typeof o.href=="string"?(o=ks(o.href),n=Bl(m).hoistableStyles,c=n.get(o),c||(c={type:"style",instance:null,count:0,state:null},n.set(o,c)),c):{type:"void",instance:null,count:0,state:null};case"link":if(o.rel==="stylesheet"&&typeof o.href=="string"&&typeof o.precedence=="string"){e=ks(o.href);var g=Bl(m).hoistableStyles,S=g.get(e);if(S||(m=m.ownerDocument||m,S={type:"stylesheet",instance:null,count:0,state:{loading:0,preload:null}},g.set(e,S),(g=m.querySelector(To(e)))?g._p||(S.instance=g,S.state.loading=5):(g=Mn.get(e),g||(g={rel:"preload",as:"style",href:o.href,crossOrigin:o.crossOrigin,integrity:o.integrity,media:o.media,hrefLang:o.hrefLang,referrerPolicy:o.referrerPolicy},Mn.set(e,g)),Bb(m,e,g,S.state))),n&&c===null)throw Error(l(528,""));return S}if(n&&c!==null)throw Error(l(529,""));return null;case"script":return n=o.async,o=o.src,typeof o=="string"&&n&&typeof n!="function"&&typeof n!="symbol"?(o=_s(o),n=Bl(m).hoistableScripts,c=n.get(o),c||(c={type:"script",instance:null,count:0,state:null},n.set(o,c)),c):{type:"void",instance:null,count:0,state:null};default:throw Error(l(444,e))}}function ks(e){return'href="'+xn(e)+'"'}function To(e){return'link[rel="stylesheet"]['+e+"]"}function dg(e){return E({},e,{"data-precedence":e.precedence,precedence:null})}function Bb(e,n,o,c){if(n=e.querySelector('link[rel="preload"][as="style"]['+n+"]")){if(n[yi]!==!0){c.loading=1;return}}else n=e.createElement("link"),n[yi]=!0,n.onload=n.onerror=_d.bind(null,n),qt(n,"link",o),kt(n),e.head.appendChild(n);c.preload=n,n.addEventListener("load",function(){return c.loading|=1}),n.addEventListener("error",function(){return c.loading|=2})}function _s(e){return'[src="'+xn(e)+'"]'}function Oo(e){return"script[async]"+e}function mg(e,n,o){if(n.count++,n.instance===null)switch(n.type){case"style":var c=e.querySelector('style[data-href~="'+xn(o.href)+'"]');if(c)return n.instance=c,kt(c),c;var m=E({},o,{"data-href":o.href,"data-precedence":o.precedence,href:null,precedence:null});return c=(e.ownerDocument||e).createElement("style"),kt(c),qt(c,"style",m),Nr(c,o.precedence,e),n.instance=c;case"stylesheet":m=ks(o.href);var g=e.querySelector(To(m));if(g)return n.state.loading|=4,n.instance=g,kt(g),g;c=dg(o),(m=Mn.get(m))&&Hf(c,m),g=(e.ownerDocument||e).createElement("link"),kt(g);var S=g;return S._p=new Promise(function(q,Q){S.onload=q,S.onerror=Q}),qt(g,"link",c),n.state.loading|=4,Nr(g,o.precedence,e),n.instance=g;case"script":return g=_s(o.src),(m=e.querySelector(Oo(g)))?(n.instance=m,kt(m),m):(c=o,(m=Mn.get(g))&&(c=E({},o),Lf(c,m)),e=e.ownerDocument||e,m=e.createElement("script"),kt(m),qt(m,"link",c),e.head.appendChild(m),n.instance=m);case"void":return null;default:throw Error(l(443,n.type))}else n.type==="stylesheet"&&(n.state.loading&4)===0&&(c=n.instance,n.state.loading|=4,Nr(c,o.precedence,e));return n.instance}function Nr(e,n,o){for(var c=o.querySelectorAll('link[rel="stylesheet"][data-precedence],style[data-precedence]'),m=c.length?c[c.length-1]:null,g=m,S=0;S<c.length;S++){var q=c[S];if(q.dataset.precedence===n)g=q;else if(g!==m)break}g?g.parentNode.insertBefore(e,g.nextSibling):(n=o.nodeType===9?o.head:o,n.insertBefore(e,n.firstChild))}function Hf(e,n){e.crossOrigin==null&&(e.crossOrigin=n.crossOrigin),e.referrerPolicy==null&&(e.referrerPolicy=n.referrerPolicy),e.title==null&&(e.title=n.title)}function Lf(e,n){e.crossOrigin==null&&(e.crossOrigin=n.crossOrigin),e.referrerPolicy==null&&(e.referrerPolicy=n.referrerPolicy),e.integrity==null&&(e.integrity=n.integrity)}var Mr=null;function pg(e,n,o){if(Mr===null){var c=new Map,m=Mr=new Map;m.set(o,c)}else m=Mr,c=m.get(o),c||(c=new Map,m.set(o,c));if(c.has(e))return c;for(c.set(e,null),o=o.getElementsByTagName(e),m=0;m<o.length;m++){var g=o[m];if(!(g[Vs]||g[Ct]||e==="link"&&g.getAttribute("rel")==="stylesheet")&&g.namespaceURI!=="http://www.w3.org/2000/svg"){var S=g.getAttribute(n)||"";S=e+S;var q=c.get(S);q?q.push(g):c.set(S,[g])}}return c}function Bf(e,n,o){e=e.ownerDocument||e,e.head.insertBefore(o,n==="title"?e.querySelector("head > title"):null)}function Yb(e,n,o){if(o===1||n.itemProp!=null)return!1;switch(e){case"meta":case"title":return!0;case"style":if(typeof n.precedence!="string"||typeof n.href!="string"||n.href==="")break;return!0;case"link":if(typeof n.rel!="string"||typeof n.href!="string"||n.href===""||n.onLoad||n.onError)break;return n.rel==="stylesheet"?(e=n.disabled,typeof n.precedence=="string"&&e==null):!0;case"script":if(n.async&&typeof n.async!="function"&&typeof n.async!="symbol"&&!n.onLoad&&!n.onError&&n.src&&typeof n.src=="string")return!0}return!1}function yg(e,n){return e==="img"&&n.src!=null&&n.src!==""&&n.onLoad==null&&n.loading!=="lazy"}function gg(e){return!(e.type==="stylesheet"&&(e.state.loading&3)===0)}function wg(e){return(e.width||100)*(e.height||100)*(typeof devicePixelRatio=="number"?devicePixelRatio:1)*.25}function vg(e,n){typeof n.decode=="function"&&(e.imgCount++,n.complete||(e.imgBytes+=wg(n),e.suspenseyImages.push(n)),e=Zb.bind(e),n.decode().then(e,e))}function Gb(e,n,o,c){if(o.type==="stylesheet"&&(typeof c.media!="string"||matchMedia(c.media).matches!==!1)&&(o.state.loading&4)===0){if(o.instance===null){var m=ks(c.href),g=n.querySelector(To(m));if(g){n=g._p,n!==null&&typeof n=="object"&&typeof n.then=="function"&&(e.count++,e=Ao.bind(e),n.then(e,e)),o.state.loading|=4,o.instance=g,kt(g);return}g=n.ownerDocument||n,c=dg(c),(m=Mn.get(m))&&Hf(c,m),g=g.createElement("link"),kt(g);var S=g;S._p=new Promise(function(q,Q){S.onload=q,S.onerror=Q}),qt(g,"link",c),o.instance=g}e.stylesheets===null&&(e.stylesheets=new Map),e.stylesheets.set(o,n),(n=o.state.preload)&&(o.state.loading&3)===0&&(e.count++,o=Ao.bind(e),n.addEventListener("load",o),n.addEventListener("error",o))}}var zr=0;function Xb(e,n){return e.stylesheets&&e.count===0&&Er(e,e.stylesheets),0<e.count||0<e.imgCount?function(o){var c=setTimeout(function(){if(e.stylesheets&&Er(e,e.stylesheets),e.unsuspend){var g=e.unsuspend;e.unsuspend=null,g()}},6e4+n);0<e.imgBytes&&zr===0&&(zr=62500*rb());var m=setTimeout(function(){if(e.waitingForImages=!1,e.count===0&&(e.stylesheets&&Er(e,e.stylesheets),e.unsuspend)){var g=e.unsuspend;e.unsuspend=null,g()}},(e.imgBytes>zr?50:800)+n);return e.unsuspend=o,function(){e.unsuspend=null,clearTimeout(c),clearTimeout(m)}}:null}function xg(e){if(e.count===0&&(e.imgCount===0||!e.waitingForImages)){if(e.stylesheets)Er(e,e.stylesheets);else if(e.unsuspend){var n=e.unsuspend;e.unsuspend=null,n()}}}function Ao(){this.count--,xg(this)}function Zb(){this.imgCount--,xg(this)}var Cr=null;function Er(e,n){e.stylesheets=null,e.unsuspend!==null&&(e.count++,Cr=new Map,n.forEach(Qb,e),Cr=null,Ao.call(e))}function Qb(e,n){if(!(n.state.loading&4)){var o=Cr.get(e);if(o)var c=o.get(null);else{o=new Map,Cr.set(e,o);for(var m=e.querySelectorAll("link[data-precedence],style[data-precedence]"),g=0;g<m.length;g++){var S=m[g];(S.nodeName==="LINK"||S.getAttribute("media")!=="not all")&&(o.set(S.dataset.precedence,S),c=S)}c&&o.set(null,c)}m=n.instance,S=m.getAttribute("data-precedence"),g=o.get(S)||c,g===c&&o.set(null,m),o.set(S,m),this.count++,c=Ao.bind(this),m.addEventListener("load",c),m.addEventListener("error",c),g?g.parentNode.insertBefore(m,g.nextSibling):(e=e.nodeType===9?e.head:e,e.insertBefore(m,e.firstChild)),n.state.loading|=4}}var js={$$typeof:Y,Provider:null,Consumer:null,_currentValue:Re,_currentValue2:Re,_threadCount:0};function Vb(e,n,o,c,m,g,S,q,Q){this.tag=1,this.containerInfo=e,this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.next=this.pendingContext=this.context=this.cancelPendingCommit=null,this.callbackPriority=0,this.expirationTimes=xc(-1),this.entangledLanes=this.shellSuspendCounter=this.errorRecoveryDisabledLanes=this.expiredLanes=this.warmLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=xc(0),this.hiddenUpdates=xc(null),this.identifierPrefix=c,this.onUncaughtError=m,this.onCaughtError=g,this.onRecoverableError=S,this.pooledCache=null,this.pooledCacheLanes=0,this.formState=Q,this.transitionTypes=null,this.incompleteTransitions=new Map}function bg(e,n,o,c,m,g,S,q,Q,le,ce,me){return e=new Vb(e,n,o,S,Q,le,ce,me,q),n=1,g===!0&&(n|=24),g=Kt(3,null,null,n),e.current=g,g.stateNode=e,n=tu(),n.refCount++,e.pooledCache=n,n.refCount++,g.memoizedState={element:c,isDehydrated:o,cache:n},su(g),e}function $g(e){return e?(e=Il,e):Il}function kg(e,n,o,c,m,g){m=$g(m),c.context===null?c.context=m:c.pendingContext=m,c=Ca(n),c.payload={element:o},g=g===void 0?null:g,g!==null&&(c.callback=g),o=Ea(e,c,n),o!==null&&(Ft(o,e,n),uo(o,e,n))}function _g(e,n){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var o=e.retryLane;e.retryLane=o!==0&&o<n?o:n}}function Yf(e,n){_g(e,n),(e=e.alternate)&&_g(e,n)}function jg(e){if(e.tag===13||e.tag===31){var n=fl(e,67108864);n!==null&&Ft(n,e,67108864),Yf(e,67108864)}}function Sg(e){if(e.tag===13||e.tag===31){var n=mn();n=bc(n);var o=fl(e,n);o!==null&&Ft(o,e,n),Yf(e,n)}}var Ss=!0;function Kb(e,n,o,c){var m=fe.T;fe.T=null;var g=ge.p;try{ge.p=2,Gf(e,n,o,c)}finally{ge.p=g,fe.T=m}}function Jb(e,n,o,c){var m=fe.T;fe.T=null;var g=ge.p;try{ge.p=8,Gf(e,n,o,c)}finally{ge.p=g,fe.T=m}}function Gf(e,n,o,c){if(Ss){var m=Xf(c);if(m===null)_f(e,n,c,Tr,o),Mg(e,c);else if(Ib(m,e,n,o,c))c.stopPropagation();else if(Mg(e,c),n&4&&-1<Wb.indexOf(e)){for(;m!==null;){var g=Ll(m);if(g!==null)switch(g.tag){case 3:if(g=g.stateNode,g.current.memoizedState.isDehydrated){var S=ol(g.pendingLanes);if(S!==0){var q=g;for(q.pendingLanes|=2,q.entangledLanes|=2;S;){var Q=1<<31-on(S);q.entanglements[1]|=Q,S&=~Q}Wn(g),(Je&6)===0&&(gr=ln()+500,No(0))}}break;case 31:case 13:q=fl(g,2),q!==null&&Ft(q,g,2),xr(),Yf(g,2)}if(g=Xf(c),g===null&&_f(e,n,c,Tr,o),g===m)break;m=g}m!==null&&c.stopPropagation()}else _f(e,n,c,null,o)}}function Xf(e){return e=Mc(e),Zf(e)}var Tr=null;function Zf(e){if(Tr=null,e=il(e),e!==null){var n=r(e);if(n===null)e=null;else{var o=n.tag;if(o===13){if(e=f(n),e!==null)return e;e=null}else if(o===31){if(e=u(n),e!==null)return e;e=null}else if(o===3){if(n.stateNode.current.memoizedState.isDehydrated)return n.tag===3?n.stateNode.containerInfo:null;e=null}else n!==e&&(e=null)}}return Tr=e,null}function Ng(e){switch(e){case"beforetoggle":case"cancel":case"click":case"close":case"contextmenu":case"copy":case"cut":case"auxclick":case"dblclick":case"dragend":case"dragstart":case"drop":case"focusin":case"focusout":case"input":case"invalid":case"keydown":case"keypress":case"keyup":case"mousedown":case"mouseup":case"paste":case"pause":case"play":case"pointercancel":case"pointerdown":case"pointerup":case"ratechange":case"reset":case"seeked":case"submit":case"toggle":case"touchcancel":case"touchend":case"touchstart":case"volumechange":case"change":case"selectionchange":case"textInput":case"compositionstart":case"compositionend":case"compositionupdate":case"beforeblur":case"afterblur":case"beforeinput":case"blur":case"fullscreenchange":case"fullscreenerror":case"focus":case"hashchange":case"popstate":case"select":case"selectstart":return 2;case"drag":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"mousemove":case"mouseout":case"mouseover":case"pointermove":case"pointerout":case"pointerover":case"resize":case"scroll":case"touchmove":case"wheel":case"mouseenter":case"mouseleave":case"pointerenter":case"pointerleave":return 8;case"message":switch(r1()){case hd:return 2;case dd:return 8;case fi:case c1:return 32;case md:return 268435456;default:return 32}default:return 32}}var Qf=!1,Ga=null,Xa=null,Za=null,qo=new Map,Ro=new Map,Qa=[],Wb="mousedown mouseup touchcancel touchend touchstart auxclick dblclick pointercancel pointerdown pointerup dragend dragstart drop compositionend compositionstart keydown keypress keyup input textInput copy cut paste click change contextmenu reset".split(" ");function Mg(e,n){switch(e){case"focusin":case"focusout":Ga=null;break;case"dragenter":case"dragleave":Xa=null;break;case"mouseover":case"mouseout":Za=null;break;case"pointerover":case"pointerout":qo.delete(n.pointerId);break;case"gotpointercapture":case"lostpointercapture":Ro.delete(n.pointerId)}}function Do(e,n,o,c,m,g){return e===null||e.nativeEvent!==g?(e={blockedOn:n,domEventName:o,eventSystemFlags:c,nativeEvent:g,targetContainers:[m]},n!==null&&(n=Ll(n),n!==null&&jg(n)),e):(e.eventSystemFlags|=c,n=e.targetContainers,m!==null&&n.indexOf(m)===-1&&n.push(m),e)}function Ib(e,n,o,c,m){switch(n){case"focusin":return Ga=Do(Ga,e,n,o,c,m),!0;case"dragenter":return Xa=Do(Xa,e,n,o,c,m),!0;case"mouseover":return Za=Do(Za,e,n,o,c,m),!0;case"pointerover":var g=m.pointerId;return qo.set(g,Do(qo.get(g)||null,e,n,o,c,m)),!0;case"gotpointercapture":return g=m.pointerId,Ro.set(g,Do(Ro.get(g)||null,e,n,o,c,m)),!0}return!1}function zg(e){var n=il(e.target);if(n!==null){var o=r(n);if(o!==null){if(n=o.tag,n===13){if(n=f(o),n!==null){e.blockedOn=n,bd(e.priority,function(){Sg(o)});return}}else if(n===31){if(n=u(o),n!==null){e.blockedOn=n,bd(e.priority,function(){Sg(o)});return}}else if(n===3&&o.stateNode.current.memoizedState.isDehydrated){e.blockedOn=o.tag===3?o.stateNode.containerInfo:null;return}}}e.blockedOn=null}function Or(e){if(e.blockedOn!==null)return!1;for(var n=e.targetContainers;0<n.length;){var o=Xf(e.nativeEvent);if(o===null){o=e.nativeEvent;var c=new o.constructor(o.type,o);Nc=c,o.target.dispatchEvent(c),Nc=null}else return n=Ll(o),n!==null&&jg(n),e.blockedOn=o,!1;n.shift()}return!0}function Cg(e,n,o){Or(e)&&o.delete(n)}function Fb(){Qf=!1,Ga!==null&&Or(Ga)&&(Ga=null),Xa!==null&&Or(Xa)&&(Xa=null),Za!==null&&Or(Za)&&(Za=null),qo.forEach(Cg),Ro.forEach(Cg)}function Ar(e,n){e.blockedOn===n&&(e.blockedOn=null,Qf||(Qf=!0,t.unstable_scheduleCallback(t.unstable_NormalPriority,Fb)))}var qr=null;function Eg(e){qr!==e&&(qr=e,t.unstable_scheduleCallback(t.unstable_NormalPriority,function(){qr===e&&(qr=null);for(var n=0;n<e.length;n+=3){var o=e[n],c=e[n+1],m=e[n+2];if(typeof c!="function"){if(Zf(c||o)===null)continue;break}var g=Ll(o);g!==null&&(e.splice(n,3),n-=3,Su(g,{pending:!0,data:m,method:o.method,action:c},c,m))}}))}function Ns(e){function n(Q){return Ar(Q,e)}Ga!==null&&Ar(Ga,e),Xa!==null&&Ar(Xa,e),Za!==null&&Ar(Za,e),qo.forEach(n),Ro.forEach(n);for(var o=0;o<Qa.length;o++){var c=Qa[o];c.blockedOn===e&&(c.blockedOn=null)}for(;0<Qa.length&&(o=Qa[0],o.blockedOn===null);)zg(o),o.blockedOn===null&&Qa.shift();if(o=(e.ownerDocument||e).$$reactFormReplay,o!=null)for(c=0;c<o.length;c+=3){var m=o[c],g=o[c+1],S=m[Vt]||null;if(typeof g=="function")S||Eg(o);else if(S){var q=null;if(g&&g.hasAttribute("formAction")){if(m=g,S=g[Vt]||null)q=S.formAction;else if(Zf(m)!==null)continue}else q=S.action;typeof q=="function"?o[c+1]=q:(o.splice(c,3),c-=3),Eg(o)}}}function Tg(){function e(g){g.canIntercept&&g.info==="react-transition"&&g.intercept({handler:function(){return new Promise(function(S){return m=S})},focusReset:"manual",scroll:"manual"})}function n(){m!==null&&(m(),m=null),c||setTimeout(o,20)}function o(){if(!c&&!navigation.transition){var g=navigation.currentEntry;g&&g.url!=null&&navigation.navigate(g.url,{state:g.getState(),info:"react-transition",history:"replace"})}}if(typeof navigation=="object"){var c=!1,m=null;return navigation.addEventListener("navigate",e),navigation.addEventListener("navigatesuccess",n),navigation.addEventListener("navigateerror",n),setTimeout(o,100),function(){c=!0,navigation.removeEventListener("navigate",e),navigation.removeEventListener("navigatesuccess",n),navigation.removeEventListener("navigateerror",n),m!==null&&(m(),m=null)}}}function Vf(e){this._internalRoot=e}Rr.prototype.render=Vf.prototype.render=function(e){var n=this._internalRoot;if(n===null)throw Error(l(409));var o=n.current,c=mn();kg(o,c,e,n,null,null)},Rr.prototype.unmount=Vf.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var n=e.containerInfo;kg(e.current,2,null,e,null,null),xr(),n[Hl]=null}};function Rr(e){this._internalRoot=e}Rr.prototype.unstable_scheduleHydration=function(e){if(e){var n=xd();e={blockedOn:null,target:e,priority:n};for(var o=0;o<Qa.length&&n!==0&&n<Qa[o].priority;o++);Qa.splice(o,0,e),o===0&&zg(e)}};var Og=a.version;if(Og!=="19.3.1")throw Error(l(527,Og,"19.3.1"));ge.findDOMNode=function(e){var n=e._reactInternals;if(n===void 0)throw typeof e.render=="function"?Error(l(188)):(e=Object.keys(e).join(","),Error(l(268,e)));return e=d(n),e=e!==null?p(e):null,e=e===null?null:e.stateNode,e};var Pb={bundleType:0,version:"19.3.1",rendererPackageName:"react-dom",currentDispatcherRef:fe,reconcilerVersion:"19.3.1"};if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"){var Dr=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!Dr.isDisabled&&Dr.supportsFiber)try{Xs=Dr.inject(Pb),sn=Dr}catch{}}return Ho.createRoot=function(e,n){if(!i(e))throw Error(l(299));var o=!1,c="",m=$p,g=kp,S=_p;return n!=null&&(n.unstable_strictMode===!0&&(o=!0),n.identifierPrefix!==void 0&&(c=n.identifierPrefix),n.onUncaughtError!==void 0&&(m=n.onUncaughtError),n.onCaughtError!==void 0&&(g=n.onCaughtError),n.onRecoverableError!==void 0&&(S=n.onRecoverableError)),n=bg(e,1,!1,null,null,o,c,null,m,g,S,Tg),e[Hl]=n.current,kf(e),new Vf(n)},Ho.hydrateRoot=function(e,n,o){if(!i(e))throw Error(l(299));var c=!1,m="",g=$p,S=kp,q=_p,Q=null;return o!=null&&(o.unstable_strictMode===!0&&(c=!0),o.identifierPrefix!==void 0&&(m=o.identifierPrefix),o.onUncaughtError!==void 0&&(g=o.onUncaughtError),o.onCaughtError!==void 0&&(S=o.onCaughtError),o.onRecoverableError!==void 0&&(q=o.onRecoverableError),o.formState!==void 0&&(Q=o.formState)),n=bg(e,1,!0,n,o??null,c,m,Q,g,S,q,Tg),n.context=$g(null),o=n.current,c=mn(),c=bc(c),m=Ca(c),m.callback=null,Ea(o,m,c),o=c,n.current.lanes=o,Qs(n,o),Wn(n),e[Hl]=n.current,kf(e),new Rr(n)},Ho.version="19.3.1",Ho}var Gg;function c$(){if(Gg)return Wf.exports;Gg=1;function t(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(t)}catch(a){console.error(a)}}return t(),Wf.exports=r$(),Wf.exports}var u$=c$();const ne=65535,Xr=["tile","sprite","sheet","icon","family","overlay","object","map","font"],Xg=["tone","full","channel"],f$=["cycle","pingpong","wave","sparkle"],Oh=10;function h$(t){return t.iconMode??(t.palette.entries.some(a=>a.role)?"tone":"full")}function y0(t){return{...t,chars:[...t.chars],advances:{...t.advances}}}function d$(t){return{...t,at:[t.at[0],t.at[1]],anchor:[t.anchor[0],t.anchor[1]],flags:[...t.flags]}}function g0(t){return{tile:t.tile,entries:t.entries.map(a=>({...a,anchor:[a.anchor[0],a.anchor[1]]}))}}function zl(t,a={}){return{name:t,hidden:!1,locked:!1,reference:!1,...a}}function m$(t){const a=new Uint16Array(t.width*t.height).fill(t.bg),s=t.family?[zl("ground"),zl("band")]:t.map?[zl("floor",{map:{kind:"tiles"}})]:[zl("main")],l=t.family?[[a],[new Uint16Array(t.width*t.height).fill(ne)]]:[[a]];return{kind:t.kind,name:t.name,width:t.width,height:t.height,cellW:t.cellW,cellH:t.cellH,wrap:t.wrap,palette:t.palette,paletteLocked:!1,layers:s,frameCount:1,cels:l,ctx:{},home:{layer:t.family?1:0,frame:0},notes:[],stamps:{},macros:{},ticks:[Oh],tags:[],views:[],pivot:null,ground:null,family:t.family?w0(t.family):null,overlay:t.overlay?v0(t.overlay):null,footprint:null,variantOf:null,densityOf:null,map:t.map?g0(t.map):null,marks:[],iconMode:null,font:t.font?y0(t.font):null}}function w0(t){return{...t,geometry:{...t.geometry,bands:t.geometry.bands.map(a=>({...a}))},detached:[...t.detached],terrain:t.terrain.slice()}}function v0(t){return{...t,anchor:t.anchor?[t.anchor[0],t.anchor[1]]:null,spread:[t.spread[0],t.spread[1]]}}function p$(t){return t.map(a=>{const s=new Map;return a.map(l=>{let i=s.get(l);return i||s.set(l,i=l.slice()),i})})}function y$(t){return{...t,sel:t.sel?t.sel.slice():null,mirror:t.mirror?{...t.mirror}:null,brush:t.brush?{...t.brush}:null}}function Wa(t){return{...t,layers:t.layers.map(a=>({...a})),cels:p$(t.cels),ticks:[...t.ticks],tags:t.tags.map(a=>({...a})),views:t.views.map(a=>({...a})),pivot:t.pivot?[t.pivot[0],t.pivot[1]]:null,ctx:Object.fromEntries(Object.entries(t.ctx).map(([a,s])=>[a,y$(s)])),home:{...t.home},family:t.family?w0(t.family):null,overlay:t.overlay?v0(t.overlay):null,footprint:t.footprint?d$(t.footprint):null,map:t.map?g0(t.map):null,notes:t.notes.map(a=>({...a})),marks:t.marks.map(a=>({...a})),font:t.font?y0(t.font):null,stamps:Object.fromEntries(Object.entries(t.stamps).map(([a,s])=>[a,{...s,px:s.px.slice()}])),macros:Object.fromEntries(Object.entries(t.macros).map(([a,s])=>[a,{params:[...s.params],body:s.body}]))}}function et(t,a){return t.ctx[a]??{layer:t.home.layer,frame:t.home.frame,sel:null,mirror:null,brush:null}}function Zt(t,a,s){const l={...et(t,a),...s};l.layer===t.home.layer&&l.frame===t.home.frame&&!l.sel&&!l.mirror&&!l.brush?delete t.ctx[a]:t.ctx[a]=l}function Dl(t,a,s){const l=Object.keys(t.ctx).map(i=>[i,et(t,i)]);t.home={layer:a(t.home.layer),frame:s(t.home.frame)};for(const[i,r]of l)t.ctx[i]={...r,layer:a(r.layer),frame:s(r.frame)};for(const[i]of l)Zt(t,i,{})}function g$(t){return t.layers.flatMap((a,s)=>a.hidden||a.reference?[]:[s])}function Ce(t,a=0){return x0(t,a,g$(t))}function w$(t,a=0){const s=t.layers.flatMap((l,i)=>l.reference&&!l.hidden?[i]:[]);return s.length?x0(t,a,s):null}function x0(t,a,s){const l=new Uint16Array(t.width*t.height).fill(ne);for(const i of s){const r=t.cels[i][a];for(let f=0;f<l.length;f++)r[f]!==ne&&(l[f]=r[f])}return l}function v$(t){let a=2166136261,s=1523705862;const l=i=>{a=Math.imul(a^i&65535,16777619)>>>0,s=Math.imul(s^i*31+7&65535,1540483477)>>>0,s=(s^s>>>15)>>>0};for(const i of[t.width,t.height,t.frameCount,...t.ticks])l(i);for(let i=0;i<t.frameCount;i++)for(const r of Ce(t,i))l(r);if(t.map){for(const i of JSON.stringify([t.map.entries,t.layers.map(r=>r.map??null)]))l(i.charCodeAt(0));for(const i of t.cels)for(const r of i)for(const f of r)l(f)}return a.toString(16).padStart(8,"0")+s.toString(16).padStart(8,"0")}const Un=["black","white","light","dark","darkest"];function Ah(t){return Un.includes(t)}const Zg=256,b0=new Set(["."," ","|"]),Ms=/^[A-Za-z][A-Za-z0-9_-]*$/,x$=/^#?([0-9a-fA-F]{6})$/;class Pt extends Error{}function vn(t){const a=parseInt(t.slice(1),16);return[a>>16&255,a>>8&255,a&255]}function $0(t){const a=x$.exec(t.trim());return a?"#"+a[1].toLowerCase():null}function b$(t){if(!t.name||!Ms.test(t.name))throw new Pt(`palette name '${t.name}' must match ${Ms}`);if(t.entries.length===0)throw new Pt(`palette '${t.name}' has no entries`);if(t.entries.length>Zg)throw new Pt(`palette '${t.name}' has ${t.entries.length} entries; the limit is ${Zg}`);const a=new Set,s=new Set;for(const l of t.entries){if([...l.key].length!==1)throw new Pt(`entry '${l.name}': key '${l.key}' must be one character`);if(b0.has(l.key)||/\s/.test(l.key))throw new Pt(`entry '${l.name}': key '${l.key}' is reserved`);if(a.has(l.key))throw new Pt(`duplicate key '${l.key}'`);if(!Ms.test(l.name))throw new Pt(`entry name '${l.name}' must match ${Ms}`);if(l.name==="none")throw new Pt("'none' is reserved (it means transparent)");if(s.has(l.name))throw new Pt(`duplicate entry name '${l.name}'`);if(!/^#[0-9a-f]{6}$/.test(l.hex))throw new Pt(`entry '${l.name}': colour '${l.hex}' must be #rrggbb`);if(l.role!==void 0&&!Ah(l.role))throw new Pt(`entry '${l.name}': role '${l.role}' must be one of ${Un.join(", ")}`);a.add(l.key),s.add(l.name)}for(const[l,i]of Object.entries(t.ramps)){if(!Ms.test(l))throw new Pt(`ramp name '${l}' must match ${Ms}`);if(i.length===0)throw new Pt(`ramp '${l}' is empty`);for(const r of i)if(!s.has(r))throw new Pt(`ramp '${l}' names unknown entry '${r}'`)}return t}function $$(t){const a=[],s="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&'()*+,-/:;<=>?@[\\]^_`{}~";for(const l of s)a.length<t&&a.push(l);for(let l=192;a.length<t;l++)l!==215&&l!==247&&a.push(String.fromCodePoint(l));return a}const k0={black:"#000000",white:"#ffffff",light:"#cccccc",dark:"#6e6e6e",darkest:"#282828"};function k$(t){return[...t.entries.map(a=>`${a.key} ${a.name} ${a.hex}${a.role?` role=${a.role}`:""}`),...Object.entries(t.ramps).map(([a,s])=>`ramp ${a} ${s.join(" ")}`)]}function _$(t,a){const s=[],l={};for(let i=0;i<a.length;i++){const r=a[i];if(r.trim()==="")continue;const f=r.split(" ").filter(y=>y!=="");if(f[0]==="ramp"){if(f.length<3)return{row:i,col:0,message:"palette row: 'ramp <name> <entry> ...' needs a name and entries"};if(l[f[1]])return{row:i,col:5,message:`palette row: ramp '${f[1]}' given twice`};l[f[1]]=f.slice(2);continue}const u=[...r][0],h=r.slice(u.length).split(" ").filter(y=>y!=="");if(r[u.length]!==" "||h.length<2||h.length>3)return{row:i,col:0,message:"palette row: expected '<key> <name> #rrggbb [role=<role>]' or 'ramp <name> <entries...>'"};const d=$0(h[1]);if(!d||!h[1].startsWith("#"))return{row:i,col:r.indexOf(h[1]),message:`palette row: '${h[1]}' is not a colour like #a4552e`};let p;if(h[2]!==void 0){const y=/^role=(.*)$/.exec(h[2]);if(!y||!Ah(y[1]))return{row:i,col:r.indexOf(h[2]),message:`palette row: '${h[2]}' should be role=${Un.join("|")}`};p=y[1]}s.push(p?{key:u,name:h[0],hex:d,role:p}:{key:u,name:h[0],hex:d})}try{return{palette:b$({name:t,entries:s,ramps:l})}}catch(i){return{row:0,col:0,message:i.message}}}class C extends Error{line;col;constructor(a,s,l){super(l),this.line=a,this.col=s}}const j$=/^-?\d+$/,S$=/^(-?\d+),(-?\d+)$/,N$=/^(\d+)x(\d+)$/,M$=/^@cell\((\d+),(\d+)\)$/,z$=/^@cell\(([a-z][a-z0-9_]*)\)$/,C$=/^([A-Za-z_][A-Za-z0-9_-]*)=/,E$=/^[a-z][a-z0-9_-]*$/,T$=1<<20;function O$(t,a,s,l){let i;const r=(f,u)=>{const h=Number(f);if(Math.abs(h)>T$)throw new C(a,u,`number ${f} is out of range`);return h};if(i=C$.exec(t)){const f=i[1],u=s+f.length+1;return l!==null?{t:"kv",key:f,value:l,quoted:!0,vcol:u,line:a,col:s}:{t:"kv",key:f,value:t.slice(f.length+1),quoted:!1,vcol:u,line:a,col:s}}if(l!==null){if(t.startsWith('"'))return{t:"string",v:l,line:a,col:s};throw new C(a,s,`unexpected quote in '${t}'`)}return j$.test(t)?{t:"int",v:r(t,s),line:a,col:s}:(i=S$.exec(t))?{t:"point",x:r(i[1],s),y:r(i[2],s),line:a,col:s}:(i=N$.exec(t))?{t:"size",w:r(i[1],s),h:r(i[2],s),line:a,col:s}:(i=M$.exec(t))?{t:"cell",cx:r(i[1],s),cy:r(i[2],s),line:a,col:s}:(i=z$.exec(t))?{t:"cell",cx:-1,cy:-1,name:i[1],line:a,col:s}:{t:"word",v:t,line:a,col:s}}function A$(t){const a=t.filter(l=>l.text.trim()!=="");if(a.length>0&&a.every(l=>l.text.trimStart().startsWith("|")))return t.map(l=>{if(l.text.trim()==="")return{...l,text:""};const i=l.text.indexOf("|")+1;let r=l.text.slice(i);const f=r.lastIndexOf("|");return f>=0&&r.slice(f+1).trim()===""&&(r=r.slice(0,f)),{text:r,line:l.line,col:l.col+i}});let s=1/0;for(const l of a)s=Math.min(s,l.text.length-l.text.trimStart().length);return Number.isFinite(s)||(s=0),t.map(l=>l.text.trim()===""?{...l,text:""}:{text:l.text.slice(s),line:l.line,col:l.col+s})}function Ls(t){const a=t.split(/\r?\n/),s=[],l=[];let i=[];const r=()=>{if(i.length===0)return;const f=i[0];f.t!=="word"||!E$.test(f.v)?l.push({line:f.line,col:f.col,message:"expected a command name"}):s.push({name:f.v,line:f.line,col:f.col,args:i.slice(1)}),i=[]};for(let f=0;f<a.length;f++){let u=a[f],h=f+1,d=0,p=!1;for(;d<u.length;){const y=u[d];if(y===" "||y===" "){d++;continue}if(y==="#")break;if(y===";"){r(),d++;continue}const w=d;let x=null;try{if(y==="{"){const v=q$(a,f,d);i.push({t:"body",text:v.text,bodyLine:h,bodyCol:d+2,line:h,col:d+1}),f=v.endLine,u=a[f],h=f+1,d=v.endCol+1;continue}for(;d<u.length&&u[d]!==" "&&u[d]!==" "&&u[d]!==";";)if(u[d]==='"'){if(x!==null)throw new C(h,d+1,"a token may hold only one quoted string");let v=d+1,$="";for(;v<u.length&&u[v]!=='"';)u[v]==="\\"&&v+1<u.length?($+=u[v+1],v+=2):($+=u[v],v++);if(v>=u.length)throw new C(h,d+1,"unterminated string");x=$,d=v+1}else d++;const b=u.slice(w,d);if(b==="<<"){const v=u.slice(d).trim();if(v!==""&&!v.startsWith("#"))throw new C(h,d+2,"'<<' must end the line; the block starts on the next line");const $=[];let _=f+1;for(;_<a.length&&a[_].trim()!==">>";)$.push({text:a[_],line:_+1,col:1}),_++;if(_>=a.length)throw new C(h,w+1,"block opened here is never closed with '>>'");i.push({t:"block",rows:A$($),line:h,col:w+1}),f=_,d=u.length;break}i.push(O$(b,h,w+1,x))}catch(b){if(!(b instanceof C))throw b;l.push({line:b.line,col:b.col,message:b.message}),i=[],p=!0,(b.message.startsWith("block opened")||b.message.startsWith("'{' opened"))&&(f=a.length);break}}p||r()}return r(),{commands:s,errors:l}}function q$(t,a,s){let l=0,i="";for(let r=a;r<t.length;r++){const f=t[r];let u=r===a?s:0;if(r>a&&/<<\s*(#.*)?$/.test(t[r-1])){let h=r;for(;h<t.length&&t[h].trim()!==">>";)i+=t[h]+`
|
|
10
|
+
`,h++;if(h>=t.length)break;r=h,i+=t[h]+`
|
|
11
|
+
`;continue}for(;u<f.length;u++){const h=f[u];if(h==='"'){let d=u+1;for(;d<f.length&&f[d]!=='"';)d+=f[d]==="\\"?2:1;i+=f.slice(u,d+1),u=d;continue}if(h==="#"&&(u===0||f[u-1]===" "||f[u-1]===" "))break;if(!(h==="{"&&(l++,l===1))){if(h==="}"&&(l--,l===0))return{text:i,endLine:r,endCol:u};i+=h}}i+=`
|
|
12
|
+
`}throw new C(a+1,s+1,"'{' opened here is never closed with '}'")}function wa(t){return'"'+t.replace(/\\/g,"\\\\").replace(/"/g,'\\"')+'"'}const Fa=["S","N","E","W","SE","SW","NE","NW"];function Cl(t){return{E:"W",W:"E",SE:"SW",SW:"SE",NE:"NW",NW:"NE"}[t]??null}function qh(t,a,s,l,i){t.cels.forEach((f,u)=>f.splice(a,0,...Array.from({length:s},(h,d)=>l(u,d)))),t.ticks.splice(a,0,...i),t.frameCount+=s;const r=f=>{a<=f.from?(f.from+=s,f.to+=s):a<=f.to&&(f.to+=s)};t.tags.forEach(r),t.views.forEach(r),Dl(t,f=>f,f=>f>=a?f+s:f)}function _0(t,a){for(const l of t.cels)l.splice(a,1);t.ticks.splice(a,1),t.frameCount--;const s=l=>l.filter(i=>(a<i.from?(i.from--,i.to--):a<=i.to&&i.to--,i.to>=i.from));t.tags=s(t.tags),t.views=s(t.views),Dl(t,l=>l,l=>l>a?l-1:Math.min(l,t.frameCount-1))}function j0(t,a){return s=>s===t?a:t<s&&s<=a?s-1:a<=s&&s<t?s+1:s}function R$(t,a,s){for(const r of t.cels){const[f]=r.splice(a,1);r.splice(s,0,f)}const[l]=t.ticks.splice(a,1);t.ticks.splice(s,0,l);const i=j0(a,s);for(const r of[...t.tags,...t.views]){const f=Array.from({length:r.to-r.from+1},(u,h)=>i(r.from+h));r.from=Math.min(...f),r.to=Math.max(...f)}Dl(t,r=>r,i)}function D$(t,a,s){const l=new Uint16Array(t.length);for(let i=0;i<s;i++)for(let r=0;r<a;r++)l[i*a+r]=t[i*a+a-1-r];return l}function Vo(t,a){return t.views.find(s=>s.from<=a&&a<=s.to)??null}function U$(t){for(const a of t.views){if(!a.mirror)continue;const s=t.views.find(i=>i.name===a.mirror&&!i.mirror);if(!s){a.mirror=null;continue}const l=s.to-s.from+1;for(;a.to-a.from+1<l;)qh(t,a.to+1,1,()=>new Uint16Array(t.width*t.height).fill(ne),[Oh]),a.to++;for(;a.to-a.from+1>l;)_0(t,a.to);for(let i=0;i<l;i++)t.ticks[a.from+i]=t.ticks[s.from+i],t.cels.forEach(r=>{r[a.from+i]=D$(r[s.from+i],t.width,t.height)})}}function Pa(t){const a=r=>Array.from({length:r.to-r.from+1},(f,u)=>r.from+u),s=(r,f)=>f.from<=r.from&&r.to<=f.to,l=[],i=[...t.views].sort((r,f)=>Fa.indexOf(r.name)-Fa.indexOf(f.name));for(const r of i)t.tags.some(f=>s(f,r))||l.push({name:r.name,frames:a(r),loop:"cycle",view:r.name,mirror:!!r.mirror});for(const r of t.tags){const f=t.views.find(u=>s(r,u))??null;l.push({name:r.name,frames:a(r),loop:r.loop,view:f?.name??null,mirror:!!f?.mirror})}return l.length||l.push({name:"all",frames:a({from:0,to:t.frameCount-1}),loop:"cycle",view:null,mirror:!1}),l}function sc(t){return t.loop!=="pingpong"||t.frames.length<3?t.frames:[...t.frames,...t.frames.slice(1,-1).reverse()]}function S0(t,a){return sc(a).reduce((s,l)=>s+t.ticks[l],0)}function El(t,a,s){const l=sc(a),i=S0(t,a);let r=i>0?(s%i+i)%i:0;for(const f of l){if(r<t.ticks[f])return f;r-=t.ticks[f]}return l[0]}function ll(t,a,s=0){const l=new Uint8Array(t*a*4);if(s)for(let i=0;i<t*a;i++)H$(l,i*4,s);return{width:t,height:a,data:l}}function H$(t,a,s){t[a]=s>>>24&255,t[a+1]=s>>>16&255,t[a+2]=s>>>8&255,t[a+3]=s&255}(()=>{const t=new Uint32Array(256);for(let a=0;a<256;a++){let s=a;for(let l=0;l<8;l++)s=s&1?3988292384^s>>>1:s>>>1;t[a]=s>>>0}return t})();function Cs(t){const a=String.fromCodePoint(t);return/^[A-Za-z0-9]$/.test(a)?a:`U+${t.toString(16).toUpperCase().padStart(4,"0")}`}function L$(t){const a=[];for(let s=0;s<t.length;){let l=s;for(;l+1<t.length&&t[l+1]===t[l]+1;)l++;a.push(l>s?`${t[s]}-${t[l]}`:String(t[s])),s=l+1}return a.join(",")}function Qg(t,a){if(a){const i=[...t].map(r=>r.codePointAt(0));return i.length?i:"chars= is empty"}const s=i=>{if(/^\d+$/.test(i))return Number(i);const r=/^U\+([0-9A-Fa-f]{1,6})$/.exec(i);return r?parseInt(r[1],16):null},l=[];for(const i of t.split(",")){const r=/^([^-]+)-([^-]+)$/.exec(i),f=s(r?r[1]:i),u=r?s(r[2]):f;if(f===null||u===null||u<f||u>1114111)return`chars=: '${i}' is not a code point or a range a-b (decimal or U+hex)`;for(let h=f;h<=u;h++)l.push(h)}return new Set(l).size!==l.length?"chars=: a code point is listed twice":l.length>4096?"chars=: at most 4096 glyphs":l}function Rh(t,a){const s=t.font.cols;return[a%s*t.cellW,Math.floor(a/s)*t.cellH]}function Dh(t,a,s=0,l){const i=l??Ce(t,s),[r,f]=Rh(t,a),u=new Uint16Array(t.cellW*t.cellH);for(let h=0;h<t.cellH;h++)for(let d=0;d<t.cellW;d++)u[h*t.cellW+d]=i[(f+h)*t.width+r+d];return u}function N0(t,a,s){let l=a,i=s,r=-1,f=-1;for(let u=0;u<s;u++)for(let h=0;h<a;h++)t[u*a+h]!==ne&&(h<l&&(l=h),h>r&&(r=h),u<i&&(i=u),u>f&&(f=u));return r<0?null:[l,i,r,f]}function B$(t,a,s){const l=t.font,i=l.chars[a];if(l.advances[i]!==void 0)return l.advances[i];const r=N0(Dh(t,a,0,s),t.cellW,t.cellH);return r?r[2]+1:Math.ceil(t.cellW/2)}function M0(t){const a=Ce(t,0);return t.font.chars.map((s,l)=>({cp:s,cell:Rh(t,l),advance:B$(t,l,a),box:N0(Dh(t,l,0,a),t.cellW,t.cellH)}))}function Y$(t,a,s){const l=t.font,i=M0(t),r=Ce(t,0),f=new Map(l.chars.map((x,b)=>[x,b])),u=a.split(`
|
|
13
|
+
`),h=x=>[...x].reduce((b,v)=>{const $=f.get(v.codePointAt(0));return b+($===void 0?Math.ceil(t.cellW/2):i[$].advance)+l.spacing},0),d=Math.max(1,...u.map(h)),p=Math.max(1,(u.length-1)*l.line+t.cellH),y=ll(d,p),w=s.map(vn);return u.forEach((x,b)=>{let v=0;for(const $ of x){const _=f.get($.codePointAt(0));if(_===void 0){v+=Math.ceil(t.cellW/2)+l.spacing;continue}const j=Dh(t,_,0,r);for(let N=0;N<t.cellH;N++)for(let M=0;M<t.cellW;M++){const A=j[N*t.cellW+M];if(A===ne||v+M>=d)continue;const z=w[A];y.data.set([z[0],z[1],z[2],255],((b*l.line+N)*d+v+M)*4)}v+=i[_].advance+l.spacing}}),y}function eh(t,a,s){const l=(1-Math.abs(2*s-1))*a,i=(t%360+360)%360/60,r=l*(1-Math.abs(i%2-1)),[f,u,h]=i<1?[l,r,0]:i<2?[r,l,0]:i<3?[0,l,r]:i<4?[0,r,l]:i<5?[r,0,l]:[l,0,r],d=s-l/2;return"#"+[f,u,h].map(p=>Math.round((p+d)*255).toString(16).padStart(2,"0")).join("")}function Lo(t,a,s,l,i){return{name:t,colours:{black:"#000000",white:"#ffffff",light:eh(a,i,.6),dark:eh(s,i,.5),darkest:eh(l,i,.4)}}}const Vg=[{name:"grey",colours:{...k0}},Lo("moss",95,115,140,.45),Lo("ember",38,18,352,.65),Lo("tide",185,205,228,.5),Lo("dusk",290,265,240,.35),Lo("sand",48,32,18,.5)];function li(t,a){return!a||!t.entries.some(s=>s.role)?t:{...t,entries:t.entries.map(s=>s.role?{...s,hex:a.colours[s.role]}:s)}}function Uh(t){return t.entries.some(a=>a.role)}const G$="blob47",X$="8 neighbours with the corner rule (a diagonal counts only when both sides next to it are the same terrain): 47 variants",Z$="8",Q$=!0,V$=8,K$=["o","nesw","ew","ns","nesw_ne_se_sw_nw"],J$=[{name:"o",key:0,quads:["outer","outer","outer","outer"]},{name:"n",key:1,quads:["vert","vert","outer","outer"]},{name:"e",key:4,quads:["outer","horiz","outer","horiz"]},{name:"ne",key:5,quads:["vert","inner","outer","horiz"]},{name:"ne_ne",key:7,quads:["vert","in","outer","horiz"]},{name:"s",key:16,quads:["outer","outer","vert","vert"]},{name:"ns",key:17,quads:["vert","vert","vert","vert"]},{name:"es",key:20,quads:["outer","horiz","vert","inner"]},{name:"nes",key:21,quads:["vert","inner","vert","inner"]},{name:"nes_ne",key:23,quads:["vert","in","vert","inner"]},{name:"es_se",key:28,quads:["outer","horiz","vert","in"]},{name:"nes_se",key:29,quads:["vert","inner","vert","in"]},{name:"nes_ne_se",key:31,quads:["vert","in","vert","in"]},{name:"w",key:64,quads:["horiz","outer","horiz","outer"]},{name:"nw",key:65,quads:["inner","vert","horiz","outer"]},{name:"ew",key:68,quads:["horiz","horiz","horiz","horiz"]},{name:"new",key:69,quads:["inner","inner","horiz","horiz"]},{name:"new_ne",key:71,quads:["inner","in","horiz","horiz"]},{name:"sw",key:80,quads:["horiz","outer","inner","vert"]},{name:"nsw",key:81,quads:["inner","vert","inner","vert"]},{name:"esw",key:84,quads:["horiz","horiz","inner","inner"]},{name:"nesw",key:85,quads:["inner","inner","inner","inner"]},{name:"nesw_ne",key:87,quads:["inner","in","inner","inner"]},{name:"esw_se",key:92,quads:["horiz","horiz","inner","in"]},{name:"nesw_se",key:93,quads:["inner","inner","inner","in"]},{name:"nesw_ne_se",key:95,quads:["inner","in","inner","in"]},{name:"sw_sw",key:112,quads:["horiz","outer","in","vert"]},{name:"nsw_sw",key:113,quads:["inner","vert","in","vert"]},{name:"esw_sw",key:116,quads:["horiz","horiz","in","inner"]},{name:"nesw_sw",key:117,quads:["inner","inner","in","inner"]},{name:"nesw_ne_sw",key:119,quads:["inner","in","in","inner"]},{name:"esw_se_sw",key:124,quads:["horiz","horiz","in","in"]},{name:"nesw_se_sw",key:125,quads:["inner","inner","in","in"]},{name:"nesw_ne_se_sw",key:127,quads:["inner","in","in","in"]},{name:"nw_nw",key:193,quads:["in","vert","horiz","outer"]},{name:"new_nw",key:197,quads:["in","inner","horiz","horiz"]},{name:"new_ne_nw",key:199,quads:["in","in","horiz","horiz"]},{name:"nsw_nw",key:209,quads:["in","vert","inner","vert"]},{name:"nesw_nw",key:213,quads:["in","inner","inner","inner"]},{name:"nesw_ne_nw",key:215,quads:["in","in","inner","inner"]},{name:"nesw_se_nw",key:221,quads:["in","inner","inner","in"]},{name:"nesw_ne_se_nw",key:223,quads:["in","in","inner","in"]},{name:"nsw_sw_nw",key:241,quads:["in","vert","in","vert"]},{name:"nesw_sw_nw",key:245,quads:["in","inner","in","inner"]},{name:"nesw_ne_sw_nw",key:247,quads:["in","in","in","inner"]},{name:"nesw_se_sw_nw",key:253,quads:["in","inner","in","in"]},{name:"nesw_ne_se_sw_nw",key:255,quads:["in","in","in","in"]}],W$={name:G$,description:X$,neighbours:Z$,cornerRule:Q$,columns:V$,pieces:K$,variants:J$},I$="blob47-round",F$="blob47 with rounder inner corners: edges bend into each inner corner and the cell outside it rounds it off (161 variants + 15 fillets; family band fillet=<px>)",P$="8",e2="either",t2=!0,n2=8,a2=["o","nesw","ew","ns","nesw_ne_se_sw_nw","ns_ne_se_sw_nw","ew_ne_se_sw_nw","f_ne_se_sw_nw"],l2=JSON.parse('[{"name":"o","key":0,"quads":["outer","outer","outer","outer"]},{"name":"n","key":1,"quads":["vert","vert","outer","outer"]},{"name":"n_ne","key":3,"quads":["vert","vround","outer","outer"]},{"name":"e","key":4,"quads":["outer","horiz","outer","horiz"]},{"name":"ne","key":5,"quads":["vert","inner","outer","horiz"]},{"name":"e_ne","key":6,"quads":["outer","hround","outer","horiz"]},{"name":"ne_ne","key":7,"quads":["vert","in","outer","horiz"]},{"name":"e_se","key":12,"quads":["outer","horiz","outer","hround"]},{"name":"ne_se","key":13,"quads":["vert","inner","outer","hround"]},{"name":"e_ne_se","key":14,"quads":["outer","hround","outer","hround"]},{"name":"ne_ne_se","key":15,"quads":["vert","in","outer","hround"]},{"name":"s","key":16,"quads":["outer","outer","vert","vert"]},{"name":"ns","key":17,"quads":["vert","vert","vert","vert"]},{"name":"ns_ne","key":19,"quads":["vert","vround","vert","vert"]},{"name":"es","key":20,"quads":["outer","horiz","vert","inner"]},{"name":"nes","key":21,"quads":["vert","inner","vert","inner"]},{"name":"es_ne","key":22,"quads":["outer","hround","vert","inner"]},{"name":"nes_ne","key":23,"quads":["vert","in","vert","inner"]},{"name":"s_se","key":24,"quads":["outer","outer","vert","vround"]},{"name":"ns_se","key":25,"quads":["vert","vert","vert","vround"]},{"name":"ns_ne_se","key":27,"quads":["vert","vround","vert","vround"]},{"name":"es_se","key":28,"quads":["outer","horiz","vert","in"]},{"name":"nes_se","key":29,"quads":["vert","inner","vert","in"]},{"name":"es_ne_se","key":30,"quads":["outer","hround","vert","in"]},{"name":"nes_ne_se","key":31,"quads":["vert","in","vert","in"]},{"name":"s_sw","key":48,"quads":["outer","outer","vround","vert"]},{"name":"ns_sw","key":49,"quads":["vert","vert","vround","vert"]},{"name":"ns_ne_sw","key":51,"quads":["vert","vround","vround","vert"]},{"name":"es_sw","key":52,"quads":["outer","horiz","vround","inner"]},{"name":"nes_sw","key":53,"quads":["vert","inner","vround","inner"]},{"name":"es_ne_sw","key":54,"quads":["outer","hround","vround","inner"]},{"name":"nes_ne_sw","key":55,"quads":["vert","in","vround","inner"]},{"name":"s_se_sw","key":56,"quads":["outer","outer","vround","vround"]},{"name":"ns_se_sw","key":57,"quads":["vert","vert","vround","vround"]},{"name":"ns_ne_se_sw","key":59,"quads":["vert","vround","vround","vround"]},{"name":"es_se_sw","key":60,"quads":["outer","horiz","vround","in"]},{"name":"nes_se_sw","key":61,"quads":["vert","inner","vround","in"]},{"name":"es_ne_se_sw","key":62,"quads":["outer","hround","vround","in"]},{"name":"nes_ne_se_sw","key":63,"quads":["vert","in","vround","in"]},{"name":"w","key":64,"quads":["horiz","outer","horiz","outer"]},{"name":"nw","key":65,"quads":["inner","vert","horiz","outer"]},{"name":"nw_ne","key":67,"quads":["inner","vround","horiz","outer"]},{"name":"ew","key":68,"quads":["horiz","horiz","horiz","horiz"]},{"name":"new","key":69,"quads":["inner","inner","horiz","horiz"]},{"name":"ew_ne","key":70,"quads":["horiz","hround","horiz","horiz"]},{"name":"new_ne","key":71,"quads":["inner","in","horiz","horiz"]},{"name":"ew_se","key":76,"quads":["horiz","horiz","horiz","hround"]},{"name":"new_se","key":77,"quads":["inner","inner","horiz","hround"]},{"name":"ew_ne_se","key":78,"quads":["horiz","hround","horiz","hround"]},{"name":"new_ne_se","key":79,"quads":["inner","in","horiz","hround"]},{"name":"sw","key":80,"quads":["horiz","outer","inner","vert"]},{"name":"nsw","key":81,"quads":["inner","vert","inner","vert"]},{"name":"nsw_ne","key":83,"quads":["inner","vround","inner","vert"]},{"name":"esw","key":84,"quads":["horiz","horiz","inner","inner"]},{"name":"nesw","key":85,"quads":["inner","inner","inner","inner"]},{"name":"esw_ne","key":86,"quads":["horiz","hround","inner","inner"]},{"name":"nesw_ne","key":87,"quads":["inner","in","inner","inner"]},{"name":"sw_se","key":88,"quads":["horiz","outer","inner","vround"]},{"name":"nsw_se","key":89,"quads":["inner","vert","inner","vround"]},{"name":"nsw_ne_se","key":91,"quads":["inner","vround","inner","vround"]},{"name":"esw_se","key":92,"quads":["horiz","horiz","inner","in"]},{"name":"nesw_se","key":93,"quads":["inner","inner","inner","in"]},{"name":"esw_ne_se","key":94,"quads":["horiz","hround","inner","in"]},{"name":"nesw_ne_se","key":95,"quads":["inner","in","inner","in"]},{"name":"w_sw","key":96,"quads":["horiz","outer","hround","outer"]},{"name":"nw_sw","key":97,"quads":["inner","vert","hround","outer"]},{"name":"nw_ne_sw","key":99,"quads":["inner","vround","hround","outer"]},{"name":"ew_sw","key":100,"quads":["horiz","horiz","hround","horiz"]},{"name":"new_sw","key":101,"quads":["inner","inner","hround","horiz"]},{"name":"ew_ne_sw","key":102,"quads":["horiz","hround","hround","horiz"]},{"name":"new_ne_sw","key":103,"quads":["inner","in","hround","horiz"]},{"name":"ew_se_sw","key":108,"quads":["horiz","horiz","hround","hround"]},{"name":"new_se_sw","key":109,"quads":["inner","inner","hround","hround"]},{"name":"ew_ne_se_sw","key":110,"quads":["horiz","hround","hround","hround"]},{"name":"new_ne_se_sw","key":111,"quads":["inner","in","hround","hround"]},{"name":"sw_sw","key":112,"quads":["horiz","outer","in","vert"]},{"name":"nsw_sw","key":113,"quads":["inner","vert","in","vert"]},{"name":"nsw_ne_sw","key":115,"quads":["inner","vround","in","vert"]},{"name":"esw_sw","key":116,"quads":["horiz","horiz","in","inner"]},{"name":"nesw_sw","key":117,"quads":["inner","inner","in","inner"]},{"name":"esw_ne_sw","key":118,"quads":["horiz","hround","in","inner"]},{"name":"nesw_ne_sw","key":119,"quads":["inner","in","in","inner"]},{"name":"sw_se_sw","key":120,"quads":["horiz","outer","in","vround"]},{"name":"nsw_se_sw","key":121,"quads":["inner","vert","in","vround"]},{"name":"nsw_ne_se_sw","key":123,"quads":["inner","vround","in","vround"]},{"name":"esw_se_sw","key":124,"quads":["horiz","horiz","in","in"]},{"name":"nesw_se_sw","key":125,"quads":["inner","inner","in","in"]},{"name":"esw_ne_se_sw","key":126,"quads":["horiz","hround","in","in"]},{"name":"nesw_ne_se_sw","key":127,"quads":["inner","in","in","in"]},{"name":"n_nw","key":129,"quads":["vround","vert","outer","outer"]},{"name":"n_ne_nw","key":131,"quads":["vround","vround","outer","outer"]},{"name":"ne_nw","key":133,"quads":["vround","inner","outer","horiz"]},{"name":"ne_ne_nw","key":135,"quads":["vround","in","outer","horiz"]},{"name":"ne_se_nw","key":141,"quads":["vround","inner","outer","hround"]},{"name":"ne_ne_se_nw","key":143,"quads":["vround","in","outer","hround"]},{"name":"ns_nw","key":145,"quads":["vround","vert","vert","vert"]},{"name":"ns_ne_nw","key":147,"quads":["vround","vround","vert","vert"]},{"name":"nes_nw","key":149,"quads":["vround","inner","vert","inner"]},{"name":"nes_ne_nw","key":151,"quads":["vround","in","vert","inner"]},{"name":"ns_se_nw","key":153,"quads":["vround","vert","vert","vround"]},{"name":"ns_ne_se_nw","key":155,"quads":["vround","vround","vert","vround"]},{"name":"nes_se_nw","key":157,"quads":["vround","inner","vert","in"]},{"name":"nes_ne_se_nw","key":159,"quads":["vround","in","vert","in"]},{"name":"ns_sw_nw","key":177,"quads":["vround","vert","vround","vert"]},{"name":"ns_ne_sw_nw","key":179,"quads":["vround","vround","vround","vert"]},{"name":"nes_sw_nw","key":181,"quads":["vround","inner","vround","inner"]},{"name":"nes_ne_sw_nw","key":183,"quads":["vround","in","vround","inner"]},{"name":"ns_se_sw_nw","key":185,"quads":["vround","vert","vround","vround"]},{"name":"ns_ne_se_sw_nw","key":187,"quads":["vround","vround","vround","vround"]},{"name":"nes_se_sw_nw","key":189,"quads":["vround","inner","vround","in"]},{"name":"nes_ne_se_sw_nw","key":191,"quads":["vround","in","vround","in"]},{"name":"w_nw","key":192,"quads":["hround","outer","horiz","outer"]},{"name":"nw_nw","key":193,"quads":["in","vert","horiz","outer"]},{"name":"nw_ne_nw","key":195,"quads":["in","vround","horiz","outer"]},{"name":"ew_nw","key":196,"quads":["hround","horiz","horiz","horiz"]},{"name":"new_nw","key":197,"quads":["in","inner","horiz","horiz"]},{"name":"ew_ne_nw","key":198,"quads":["hround","hround","horiz","horiz"]},{"name":"new_ne_nw","key":199,"quads":["in","in","horiz","horiz"]},{"name":"ew_se_nw","key":204,"quads":["hround","horiz","horiz","hround"]},{"name":"new_se_nw","key":205,"quads":["in","inner","horiz","hround"]},{"name":"ew_ne_se_nw","key":206,"quads":["hround","hround","horiz","hround"]},{"name":"new_ne_se_nw","key":207,"quads":["in","in","horiz","hround"]},{"name":"sw_nw","key":208,"quads":["hround","outer","inner","vert"]},{"name":"nsw_nw","key":209,"quads":["in","vert","inner","vert"]},{"name":"nsw_ne_nw","key":211,"quads":["in","vround","inner","vert"]},{"name":"esw_nw","key":212,"quads":["hround","horiz","inner","inner"]},{"name":"nesw_nw","key":213,"quads":["in","inner","inner","inner"]},{"name":"esw_ne_nw","key":214,"quads":["hround","hround","inner","inner"]},{"name":"nesw_ne_nw","key":215,"quads":["in","in","inner","inner"]},{"name":"sw_se_nw","key":216,"quads":["hround","outer","inner","vround"]},{"name":"nsw_se_nw","key":217,"quads":["in","vert","inner","vround"]},{"name":"nsw_ne_se_nw","key":219,"quads":["in","vround","inner","vround"]},{"name":"esw_se_nw","key":220,"quads":["hround","horiz","inner","in"]},{"name":"nesw_se_nw","key":221,"quads":["in","inner","inner","in"]},{"name":"esw_ne_se_nw","key":222,"quads":["hround","hround","inner","in"]},{"name":"nesw_ne_se_nw","key":223,"quads":["in","in","inner","in"]},{"name":"w_sw_nw","key":224,"quads":["hround","outer","hround","outer"]},{"name":"nw_sw_nw","key":225,"quads":["in","vert","hround","outer"]},{"name":"nw_ne_sw_nw","key":227,"quads":["in","vround","hround","outer"]},{"name":"ew_sw_nw","key":228,"quads":["hround","horiz","hround","horiz"]},{"name":"new_sw_nw","key":229,"quads":["in","inner","hround","horiz"]},{"name":"ew_ne_sw_nw","key":230,"quads":["hround","hround","hround","horiz"]},{"name":"new_ne_sw_nw","key":231,"quads":["in","in","hround","horiz"]},{"name":"ew_se_sw_nw","key":236,"quads":["hround","horiz","hround","hround"]},{"name":"new_se_sw_nw","key":237,"quads":["in","inner","hround","hround"]},{"name":"ew_ne_se_sw_nw","key":238,"quads":["hround","hround","hround","hround"]},{"name":"new_ne_se_sw_nw","key":239,"quads":["in","in","hround","hround"]},{"name":"sw_sw_nw","key":240,"quads":["hround","outer","in","vert"]},{"name":"nsw_sw_nw","key":241,"quads":["in","vert","in","vert"]},{"name":"nsw_ne_sw_nw","key":243,"quads":["in","vround","in","vert"]},{"name":"esw_sw_nw","key":244,"quads":["hround","horiz","in","inner"]},{"name":"nesw_sw_nw","key":245,"quads":["in","inner","in","inner"]},{"name":"esw_ne_sw_nw","key":246,"quads":["hround","hround","in","inner"]},{"name":"nesw_ne_sw_nw","key":247,"quads":["in","in","in","inner"]},{"name":"sw_se_sw_nw","key":248,"quads":["hround","outer","in","vround"]},{"name":"nsw_se_sw_nw","key":249,"quads":["in","vert","in","vround"]},{"name":"nsw_ne_se_sw_nw","key":251,"quads":["in","vround","in","vround"]},{"name":"esw_se_sw_nw","key":252,"quads":["hround","horiz","in","in"]},{"name":"nesw_se_sw_nw","key":253,"quads":["in","inner","in","in"]},{"name":"esw_ne_se_sw_nw","key":254,"quads":["hround","hround","in","in"]},{"name":"nesw_ne_se_sw_nw","key":255,"quads":["in","in","in","in"]},{"name":"f_ne","key":2,"quads":["out","fillet","out","out"],"on":"fillet"},{"name":"f_se","key":8,"quads":["out","out","out","fillet"],"on":"fillet"},{"name":"f_ne_se","key":10,"quads":["out","fillet","out","fillet"],"on":"fillet"},{"name":"f_sw","key":32,"quads":["out","out","fillet","out"],"on":"fillet"},{"name":"f_ne_sw","key":34,"quads":["out","fillet","fillet","out"],"on":"fillet"},{"name":"f_se_sw","key":40,"quads":["out","out","fillet","fillet"],"on":"fillet"},{"name":"f_ne_se_sw","key":42,"quads":["out","fillet","fillet","fillet"],"on":"fillet"},{"name":"f_nw","key":128,"quads":["fillet","out","out","out"],"on":"fillet"},{"name":"f_ne_nw","key":130,"quads":["fillet","fillet","out","out"],"on":"fillet"},{"name":"f_se_nw","key":136,"quads":["fillet","out","out","fillet"],"on":"fillet"},{"name":"f_ne_se_nw","key":138,"quads":["fillet","fillet","out","fillet"],"on":"fillet"},{"name":"f_sw_nw","key":160,"quads":["fillet","out","fillet","out"],"on":"fillet"},{"name":"f_ne_sw_nw","key":162,"quads":["fillet","fillet","fillet","out"],"on":"fillet"},{"name":"f_se_sw_nw","key":168,"quads":["fillet","out","fillet","fillet"],"on":"fillet"},{"name":"f_ne_se_sw_nw","key":170,"quads":["fillet","fillet","fillet","fillet"],"on":"fillet"}]'),s2={name:I$,description:F$,neighbours:P$,cornerRule:e2,fillets:t2,columns:n2,pieces:a2,variants:l2},o2="bridge8",i2="a deck joined along one axis (east-west wins when both): single, the two ends and the middle of each axis: 8 variants. A tile with no bridge beside it is the east-west single; the north-south single is placed by name",r2="axis",c2=[1,4],u2={endh:"horiz",endv:"vert"},f2=4,h2=["h","h_ew","v","v_ns"],d2=[{name:"h",key:0,quads:["endh","endh","endh","endh"]},{name:"h_e",key:4,quads:["endh","horiz","endh","horiz"]},{name:"h_ew",key:68,quads:["horiz","horiz","horiz","horiz"]},{name:"h_w",key:64,quads:["horiz","endh","horiz","endh"]},{name:"v",key:null,quads:["endv","endv","endv","endv"]},{name:"v_s",key:16,quads:["endv","endv","vert","vert"]},{name:"v_ns",key:17,quads:["vert","vert","vert","vert"]},{name:"v_n",key:1,quads:["vert","vert","endv","endv"]}],m2={name:o2,description:i2,neighbours:r2,inset:c2,kinds:u2,columns:f2,pieces:h2,variants:d2},p2="face",y2="blob47 and a cliff's faces in the cells around it: south faces below the terrain (ends, joins, inner corners), side faces beside its east and west edges, corners where they meet, and alternate looks of the long middles: 47 + 28 variants",g2="8",w2=!0,v2=8,x2=["o","nesw","ew","ns","nesw_ne_se_sw_nw","face_o","face_ew","face_ie_iw","side_e","side_e_ns","side_w","side_w_ns","corner_ew"],b2=!0,$2=!0,k2={faceend:"out",facemid:"out",faceinner:"out",sidetop:"out",sidemid:"out",sidebot:"out",cornere:"out",cornerw:"out"},_2=[{name:"o",key:0,quads:["outer","outer","outer","outer"]},{name:"n",key:1,quads:["vert","vert","outer","outer"]},{name:"e",key:4,quads:["outer","horiz","outer","horiz"]},{name:"ne",key:5,quads:["vert","inner","outer","horiz"]},{name:"ne_ne",key:7,quads:["vert","in","outer","horiz"]},{name:"s",key:16,quads:["outer","outer","vert","vert"]},{name:"ns",key:17,quads:["vert","vert","vert","vert"]},{name:"es",key:20,quads:["outer","horiz","vert","inner"]},{name:"nes",key:21,quads:["vert","inner","vert","inner"]},{name:"nes_ne",key:23,quads:["vert","in","vert","inner"]},{name:"es_se",key:28,quads:["outer","horiz","vert","in"]},{name:"nes_se",key:29,quads:["vert","inner","vert","in"]},{name:"nes_ne_se",key:31,quads:["vert","in","vert","in"]},{name:"w",key:64,quads:["horiz","outer","horiz","outer"]},{name:"nw",key:65,quads:["inner","vert","horiz","outer"]},{name:"ew",key:68,quads:["horiz","horiz","horiz","horiz"]},{name:"new",key:69,quads:["inner","inner","horiz","horiz"]},{name:"new_ne",key:71,quads:["inner","in","horiz","horiz"]},{name:"sw",key:80,quads:["horiz","outer","inner","vert"]},{name:"nsw",key:81,quads:["inner","vert","inner","vert"]},{name:"esw",key:84,quads:["horiz","horiz","inner","inner"]},{name:"nesw",key:85,quads:["inner","inner","inner","inner"]},{name:"nesw_ne",key:87,quads:["inner","in","inner","inner"]},{name:"esw_se",key:92,quads:["horiz","horiz","inner","in"]},{name:"nesw_se",key:93,quads:["inner","inner","inner","in"]},{name:"nesw_ne_se",key:95,quads:["inner","in","inner","in"]},{name:"sw_sw",key:112,quads:["horiz","outer","in","vert"]},{name:"nsw_sw",key:113,quads:["inner","vert","in","vert"]},{name:"esw_sw",key:116,quads:["horiz","horiz","in","inner"]},{name:"nesw_sw",key:117,quads:["inner","inner","in","inner"]},{name:"nesw_ne_sw",key:119,quads:["inner","in","in","inner"]},{name:"esw_se_sw",key:124,quads:["horiz","horiz","in","in"]},{name:"nesw_se_sw",key:125,quads:["inner","inner","in","in"]},{name:"nesw_ne_se_sw",key:127,quads:["inner","in","in","in"]},{name:"nw_nw",key:193,quads:["in","vert","horiz","outer"]},{name:"new_nw",key:197,quads:["in","inner","horiz","horiz"]},{name:"new_ne_nw",key:199,quads:["in","in","horiz","horiz"]},{name:"nsw_nw",key:209,quads:["in","vert","inner","vert"]},{name:"nesw_nw",key:213,quads:["in","inner","inner","inner"]},{name:"nesw_ne_nw",key:215,quads:["in","in","inner","inner"]},{name:"nesw_se_nw",key:221,quads:["in","inner","inner","in"]},{name:"nesw_ne_se_nw",key:223,quads:["in","in","inner","in"]},{name:"nsw_sw_nw",key:241,quads:["in","vert","in","vert"]},{name:"nesw_sw_nw",key:245,quads:["in","inner","in","inner"]},{name:"nesw_ne_sw_nw",key:247,quads:["in","in","in","inner"]},{name:"nesw_se_sw_nw",key:253,quads:["in","inner","in","in"]},{name:"nesw_ne_se_sw_nw",key:255,quads:["in","in","in","in"]},{name:"face_o",key:0,quads:["faceend","faceend","faceend","faceend"],on:"face"},{name:"face_e",key:4,quads:["faceend","facemid","faceend","facemid"],on:"face"},{name:"face_ew",key:68,quads:["facemid","facemid","facemid","facemid"],on:"face"},{name:"face_w",key:64,quads:["facemid","faceend","facemid","faceend"],on:"face"},{name:"face_ie",key:8,quads:["faceend","faceinner","faceend","faceinner"],on:"face"},{name:"face_iw",key:32,quads:["faceinner","faceend","faceinner","faceend"],on:"face"},{name:"face_e_iw",key:36,quads:["faceinner","facemid","faceinner","facemid"],on:"face"},{name:"face_ie_iw",key:40,quads:["faceinner","faceinner","faceinner","faceinner"],on:"face"},{name:"face_ie_w",key:72,quads:["facemid","faceinner","facemid","faceinner"],on:"face"},{name:"side_e",key:64,quads:["sidetop@nw","out","sidebot@sw","out"],on:"side"},{name:"side_e_n",key:65,quads:["sidemid@nw","out","sidebot@sw","out"],on:"side"},{name:"side_e_s",key:80,quads:["sidetop@nw","out","sidemid@sw","out"],on:"side"},{name:"side_e_ns",key:81,quads:["sidemid@nw","out","sidemid@sw","out"],on:"side"},{name:"side_w",key:4,quads:["out","sidetop@ne","out","sidebot@se"],on:"side"},{name:"side_w_n",key:5,quads:["out","sidemid@ne","out","sidebot@se"],on:"side"},{name:"side_w_s",key:20,quads:["out","sidetop@ne","out","sidemid@se"],on:"side"},{name:"side_w_ns",key:21,quads:["out","sidemid@ne","out","sidemid@se"],on:"side"},{name:"side_ew",key:68,quads:["sidetop@nw","sidetop@ne","sidebot@sw","sidebot@se"],on:"side"},{name:"side_ew_n",key:69,quads:["sidemid@nw","sidemid@ne","sidebot@sw","sidebot@se"],on:"side"},{name:"side_ew_s",key:84,quads:["sidetop@nw","sidetop@ne","sidemid@sw","sidemid@se"],on:"side"},{name:"side_ew_ns",key:85,quads:["sidemid@nw","sidemid@ne","sidemid@sw","sidemid@se"],on:"side"},{name:"corner_e",key:128,quads:["cornere","out","out","out"],on:"corner"},{name:"corner_w",key:2,quads:["out","cornerw","out","out"],on:"corner"},{name:"corner_ew",key:130,quads:["cornere","cornerw","out","out"],on:"corner"},{name:"face_ew_b",key:null,quads:["facemid","facemid","facemid","facemid"],on:"face",alt:"face_ew"},{name:"face_ew_c",key:null,quads:["facemid","facemid","facemid","facemid"],on:"face",alt:"face_ew"},{name:"side_e_ns_b",key:null,quads:["sidemid@nw","out","sidemid@sw","out"],on:"side",alt:"side_e_ns"},{name:"side_w_ns_b",key:null,quads:["out","sidemid@ne","out","sidemid@se"],on:"side",alt:"side_w_ns"}],j2={name:p2,description:y2,neighbours:g2,cornerRule:w2,columns:v2,pieces:x2,faces:b2,sides:$2,kinds:k2,variants:_2},S2="lane",N2="a path that fills where it is wide (a diagonal counts when both sides next to it are the lane) and turns diagonally (a lone diagonal draws a strip to that corner, and the cells beside it the strip's edge): 82 variants + 15",M2="8",z2="diagonal",C2=[1,4],E2=8,T2=["o","nesw","ew","ns","nesw_ne_se_sw_nw","o_ne","o_se","d_ne_se_sw_nw","o_sw","o_nw","n_se","s_ne","n_sw","w_se"],O2=[{name:"o",key:0,quads:["outer","outer","outer","outer"]},{name:"n",key:1,quads:["vert","vert","outer","outer"]},{name:"o_ne",key:2,quads:["diagside","diag","diagcap","diagside"]},{name:"e",key:4,quads:["outer","horiz","outer","horiz"]},{name:"ne",key:5,quads:["vert","inner","outer","horiz"]},{name:"ne_ne",key:7,quads:["vert","in","outer","horiz"]},{name:"o_se",key:8,quads:["diagcap","diagside","diagside","diag"]},{name:"n_se",key:9,quads:["vert","vert","outerdiag","diag"]},{name:"o_ne_se",key:10,quads:["diagside","diag","diagside","diag"]},{name:"s",key:16,quads:["outer","outer","vert","vert"]},{name:"ns",key:17,quads:["vert","vert","vert","vert"]},{name:"s_ne",key:18,quads:["outerdiag","diag","vert","vert"]},{name:"es",key:20,quads:["outer","horiz","vert","inner"]},{name:"nes",key:21,quads:["vert","inner","vert","inner"]},{name:"nes_ne",key:23,quads:["vert","in","vert","inner"]},{name:"es_se",key:28,quads:["outer","horiz","vert","in"]},{name:"nes_se",key:29,quads:["vert","inner","vert","in"]},{name:"nes_ne_se",key:31,quads:["vert","in","vert","in"]},{name:"o_sw",key:32,quads:["diagside","diagcap","diag","diagside"]},{name:"n_sw",key:33,quads:["vert","vert","diag","outerdiag"]},{name:"o_ne_sw",key:34,quads:["diagside","diag","diag","diagside"]},{name:"e_sw",key:36,quads:["outerdiag","horiz","diag","horiz"]},{name:"ne_sw",key:37,quads:["vert","inner","diag","horiz"]},{name:"ne_ne_sw",key:39,quads:["vert","in","diag","horiz"]},{name:"o_se_sw",key:40,quads:["diagside","diagside","diag","diag"]},{name:"n_se_sw",key:41,quads:["vert","vert","diag","diag"]},{name:"o_ne_se_sw",key:42,quads:["diagside","diag","diag","diag"]},{name:"w",key:64,quads:["horiz","outer","horiz","outer"]},{name:"nw",key:65,quads:["inner","vert","horiz","outer"]},{name:"w_ne",key:66,quads:["horiz","diag","horiz","outerdiag"]},{name:"ew",key:68,quads:["horiz","horiz","horiz","horiz"]},{name:"new",key:69,quads:["inner","inner","horiz","horiz"]},{name:"new_ne",key:71,quads:["inner","in","horiz","horiz"]},{name:"w_se",key:72,quads:["horiz","outerdiag","horiz","diag"]},{name:"nw_se",key:73,quads:["inner","vert","horiz","diag"]},{name:"w_ne_se",key:74,quads:["horiz","diag","horiz","diag"]},{name:"sw",key:80,quads:["horiz","outer","inner","vert"]},{name:"nsw",key:81,quads:["inner","vert","inner","vert"]},{name:"sw_ne",key:82,quads:["horiz","diag","inner","vert"]},{name:"esw",key:84,quads:["horiz","horiz","inner","inner"]},{name:"nesw",key:85,quads:["inner","inner","inner","inner"]},{name:"nesw_ne",key:87,quads:["inner","in","inner","inner"]},{name:"esw_se",key:92,quads:["horiz","horiz","inner","in"]},{name:"nesw_se",key:93,quads:["inner","inner","inner","in"]},{name:"nesw_ne_se",key:95,quads:["inner","in","inner","in"]},{name:"sw_sw",key:112,quads:["horiz","outer","in","vert"]},{name:"nsw_sw",key:113,quads:["inner","vert","in","vert"]},{name:"sw_ne_sw",key:114,quads:["horiz","diag","in","vert"]},{name:"esw_sw",key:116,quads:["horiz","horiz","in","inner"]},{name:"nesw_sw",key:117,quads:["inner","inner","in","inner"]},{name:"nesw_ne_sw",key:119,quads:["inner","in","in","inner"]},{name:"esw_se_sw",key:124,quads:["horiz","horiz","in","in"]},{name:"nesw_se_sw",key:125,quads:["inner","inner","in","in"]},{name:"nesw_ne_se_sw",key:127,quads:["inner","in","in","in"]},{name:"o_nw",key:128,quads:["diag","diagside","diagside","diagcap"]},{name:"o_ne_nw",key:130,quads:["diag","diag","diagside","diagside"]},{name:"e_nw",key:132,quads:["diag","horiz","outerdiag","horiz"]},{name:"o_se_nw",key:136,quads:["diag","diagside","diagside","diag"]},{name:"o_ne_se_nw",key:138,quads:["diag","diag","diagside","diag"]},{name:"s_nw",key:144,quads:["diag","outerdiag","vert","vert"]},{name:"s_ne_nw",key:146,quads:["diag","diag","vert","vert"]},{name:"es_nw",key:148,quads:["diag","horiz","vert","inner"]},{name:"es_se_nw",key:156,quads:["diag","horiz","vert","in"]},{name:"o_sw_nw",key:160,quads:["diag","diagside","diag","diagside"]},{name:"o_ne_sw_nw",key:162,quads:["diag","diag","diag","diagside"]},{name:"e_sw_nw",key:164,quads:["diag","horiz","diag","horiz"]},{name:"o_se_sw_nw",key:168,quads:["diag","diagside","diag","diag"]},{name:"o_ne_se_sw_nw",key:170,quads:["diag","diag","diag","diag"]},{name:"nw_nw",key:193,quads:["in","vert","horiz","outer"]},{name:"new_nw",key:197,quads:["in","inner","horiz","horiz"]},{name:"new_ne_nw",key:199,quads:["in","in","horiz","horiz"]},{name:"nw_se_nw",key:201,quads:["in","vert","horiz","diag"]},{name:"nsw_nw",key:209,quads:["in","vert","inner","vert"]},{name:"nesw_nw",key:213,quads:["in","inner","inner","inner"]},{name:"nesw_ne_nw",key:215,quads:["in","in","inner","inner"]},{name:"nesw_se_nw",key:221,quads:["in","inner","inner","in"]},{name:"nesw_ne_se_nw",key:223,quads:["in","in","inner","in"]},{name:"nsw_sw_nw",key:241,quads:["in","vert","in","vert"]},{name:"nesw_sw_nw",key:245,quads:["in","inner","in","inner"]},{name:"nesw_ne_sw_nw",key:247,quads:["in","in","in","inner"]},{name:"nesw_se_sw_nw",key:253,quads:["in","inner","in","in"]},{name:"nesw_ne_se_sw_nw",key:255,quads:["in","in","in","in"]},{name:"d_ne",key:2,quads:["out","diagfill","out","out"],on:"fillet"},{name:"d_se",key:8,quads:["out","out","out","diagfill"],on:"fillet"},{name:"d_ne_se",key:10,quads:["out","diagfill","out","diagfill"],on:"fillet"},{name:"d_sw",key:32,quads:["out","out","diagfill","out"],on:"fillet"},{name:"d_ne_sw",key:34,quads:["out","diagfill","diagfill","out"],on:"fillet"},{name:"d_se_sw",key:40,quads:["out","out","diagfill","diagfill"],on:"fillet"},{name:"d_ne_se_sw",key:42,quads:["out","diagfill","diagfill","diagfill"],on:"fillet"},{name:"d_nw",key:128,quads:["diagfill","out","out","out"],on:"fillet"},{name:"d_ne_nw",key:130,quads:["diagfill","diagfill","out","out"],on:"fillet"},{name:"d_se_nw",key:136,quads:["diagfill","out","out","diagfill"],on:"fillet"},{name:"d_ne_se_nw",key:138,quads:["diagfill","diagfill","out","diagfill"],on:"fillet"},{name:"d_sw_nw",key:160,quads:["diagfill","out","diagfill","out"],on:"fillet"},{name:"d_ne_sw_nw",key:162,quads:["diagfill","diagfill","diagfill","out"],on:"fillet"},{name:"d_se_sw_nw",key:168,quads:["diagfill","out","diagfill","diagfill"],on:"fillet"},{name:"d_ne_se_sw_nw",key:170,quads:["diagfill","diagfill","diagfill","diagfill"],on:"fillet"}],A2={name:S2,description:N2,neighbours:M2,cornerRule:z2,inset:C2,columns:E2,pieces:T2,variants:O2},q2="path",R2="4 neighbours: a strip through the middle of the tile toward each joined side (roads, rivers, fences): 16 variants",D2="4",U2=[1,4],H2=8,L2=["o","nesw","ew","ns"],B2=[{name:"o",key:0,quads:["outer","outer","outer","outer"]},{name:"n",key:1,quads:["vert","vert","outer","outer"]},{name:"e",key:4,quads:["outer","horiz","outer","horiz"]},{name:"ne",key:5,quads:["vert","inner","outer","horiz"]},{name:"s",key:16,quads:["outer","outer","vert","vert"]},{name:"ns",key:17,quads:["vert","vert","vert","vert"]},{name:"es",key:20,quads:["outer","horiz","vert","inner"]},{name:"nes",key:21,quads:["vert","inner","vert","inner"]},{name:"w",key:64,quads:["horiz","outer","horiz","outer"]},{name:"nw",key:65,quads:["inner","vert","horiz","outer"]},{name:"ew",key:68,quads:["horiz","horiz","horiz","horiz"]},{name:"new",key:69,quads:["inner","inner","horiz","horiz"]},{name:"sw",key:80,quads:["horiz","outer","inner","vert"]},{name:"nsw",key:81,quads:["inner","vert","inner","vert"]},{name:"esw",key:84,quads:["horiz","horiz","inner","inner"]},{name:"nesw",key:85,quads:["inner","inner","inner","inner"]}],Y2={name:q2,description:R2,neighbours:D2,inset:U2,columns:H2,pieces:L2,variants:B2},G2="single",X2="one tile whatever its neighbours (plain ground, props): 1 variant",Z2="none",Q2=1,V2=["o"],K2=[{name:"o",key:0,quads:["in","in","in","in"]}],J2={name:G2,description:X2,neighbours:Z2,columns:Q2,pieces:V2,variants:K2},W2="wang16-corner",I2="corner Wang tiles: each of the four corners is in or out, and the edge runs through the middle of the tile: 16 variants",F2="corners",P2=8,ek=["ne_se_sw_nw","ne_se_sw","ne_se_nw","ne_sw_nw","se_sw_nw","ne_sw","se_nw"],tk=[{name:"o",key:0,quads:["out","out","out","out"]},{name:"ne",key:2,quads:["out","outer@sw","out","out"]},{name:"se",key:8,quads:["out","out","out","outer@nw"]},{name:"ne_se",key:10,quads:["out","vert@sw","out","vert@nw"]},{name:"sw",key:32,quads:["out","out","outer@ne","out"]},{name:"ne_sw",key:34,quads:["out","outer@sw","outer@ne","out"]},{name:"se_sw",key:40,quads:["out","out","horiz@ne","horiz@nw"]},{name:"ne_se_sw",key:42,quads:["out","vert@sw","horiz@ne","inner@nw"]},{name:"nw",key:128,quads:["outer@se","out","out","out"]},{name:"ne_nw",key:130,quads:["horiz@se","horiz@sw","out","out"]},{name:"se_nw",key:136,quads:["outer@se","out","out","outer@nw"]},{name:"ne_se_nw",key:138,quads:["horiz@se","inner@sw","out","vert@nw"]},{name:"sw_nw",key:160,quads:["vert@se","out","vert@ne","out"]},{name:"ne_sw_nw",key:162,quads:["inner@se","horiz@sw","vert@ne","out"]},{name:"se_sw_nw",key:168,quads:["vert@se","out","inner@ne","horiz@nw"]},{name:"ne_se_sw_nw",key:170,quads:["in@se","in@sw","in@ne","in@nw"]}],nk={name:W2,description:I2,neighbours:F2,columns:P2,pieces:ek,variants:tk},Ur=(1n<<64n)-1n,ak=6364136223846793005n;class nn{state=0n;inc=1n;constructor(a,s=54){this.inc=(BigInt(s)<<1n|1n)&Ur,this.state=0n,this.nextU32(),this.state=this.state+(BigInt(a)&Ur)&Ur,this.nextU32()}nextU32(){const a=this.state;this.state=a*ak+this.inc&Ur;const s=Number((a>>18n^a)>>27n&0xffffffffn),l=Number(a>>59n);return(s>>>l|s<<(32-l&31))>>>0}nextInt(a){if(!Number.isInteger(a)||a<=0||a>4294967296)throw new RangeError(`nextInt: bad bound ${a}`);const s=(4294967296-a)%a;for(;;){const l=this.nextU32();if(l>=s)return l%a}}range(a,s){return a+this.nextInt(s-a+1)}}function z0(t){return t.nextU32()%2147483647+1}function lk(t){let a=2166136261;for(let s=0;s<t.length;s++)a^=t.charCodeAt(s),a=Math.imul(a,16777619)>>>0;return a>>>0}const Ja={N:1,NE:2,E:4,SE:8,S:16,SW:32,W:64,NW:128},sk=[[1,0,-1],[2,1,-1],[4,1,0],[8,1,1],[16,0,1],[32,-1,1],[64,-1,0],[128,-1,-1]],Kg=["in","out","outer","inner","horiz","vert","vround","hround","fillet","diag","diagcap","diagside","outerdiag","diagfill"],ok=["diag","diagcap","diagside","outerdiag","diagfill"],C0=["nw","ne","sw","se"],Hh=t=>t==="face"||t==="side"||t==="corner";class ya extends Error{}function ik(t,a,s){const[l,i]=a.split("@"),r=Kg.includes(l)?l:t.kinds?.[l];if(!r||!Kg.includes(r))throw new ya(`scheme ${t.name}: unknown quadrant kind '${l}'`);const f=i===void 0?s:C0.indexOf(i);if(f<0)throw new ya(`scheme ${t.name}: '${a}' faces no corner (nw, ne, sw, se)`);return{kind:l,base:r,face:f}}function Lh(t){const a=new Map,s=new Map,l=new Map,i=new Map,r=new Map,f=new Map;t.variants.forEach((y,w)=>{if(!/^[a-z][a-z0-9_]*$/.test(y.name))throw new ya(`scheme ${t.name}: '${y.name}' is not a usable variant name`);if(a.has(y.name))throw new ya(`scheme ${t.name}: variant '${y.name}' twice`);if(y.quads.length!==4)throw new ya(`scheme ${t.name}: variant '${y.name}' needs 4 quads`);if(a.set(y.name,w),y.key===null)return;const x=y.on==="face"?l:y.on==="side"?i:y.on==="corner"?r:y.on==="fillet"?f:s;if(x.has(y.key))throw new ya(`scheme ${t.name}: key ${y.key} is both ${t.variants[x.get(y.key)].name} and ${y.name}`);x.set(y.key,w)});const u=t.variants.map(y=>y.quads.map((w,x)=>ik(t,w,x))),h=t.pieces.map(y=>{const w=a.get(y);if(w===void 0)throw new ya(`scheme ${t.name}: piece '${y}' is not a variant`);return w}),d=t.variants.map((y,w)=>h.includes(w)?null:u[w].map((x,b)=>{for(const v of h){const $=u[v].findIndex(_=>_.kind===x.kind&&_.face===x.face);if($>=0)return[v,$]}if(x.base==="out")return[-1,b];throw new ya(`scheme ${t.name}: no piece has the ${x.kind}@${C0[x.face]} quadrant variant '${y.name}' needs`)})),p=new Map;return t.variants.forEach((y,w)=>{if(!y.alt)return;const x=a.get(y.alt);if(x===void 0)throw new ya(`scheme ${t.name}: '${y.name}' is a look of '${y.alt}', which it does not have`);p.set(x,[...p.get(x)??[x],w])}),{...t,quadSpecs:u,sources:d,byName:a,byKey:s,faceByKey:l,sideByKey:i,cornerByKey:r,filletByKey:f,alts:p}}const ph=new Map([W$,s2,nk,Y2,m2,J2,j2,A2].map(t=>[t.name,Lh(t)]));function E0(t){return ph.get(t)}function Jg(t,a){const{N:s,NE:l,E:i,SE:r,S:f,SW:u,W:h,NW:d}=Ja;switch(t.neighbours){case"none":return 0;case"corners":return a&(l|r|u|d);case"4":return a&(s|i|f|h);case"axis":return a&(i|h)?a&(i|h):a&(s|f);case"8":{let p=a&(s|i|f|h);if(!t.cornerRule)return a&255;if(t.cornerRule==="diagonal"){for(const[y,w,x]of[[l,s,i],[r,f,i],[u,f,h],[d,s,h]])a&y&&!!(a&w)==!!(a&x)&&(p|=y);return p}if(t.cornerRule==="either"){for(const[y,w,x]of[[l,s,i],[r,f,i],[u,f,h],[d,s,h]])a&y&&a&(w|x)&&(p|=y);return p}return a&s&&a&i&&a&l&&(p|=l),a&f&&a&i&&a&r&&(p|=r),a&f&&a&h&&a&u&&(p|=u),a&s&&a&h&&a&d&&(p|=d),p}}}function Wg(t,a,s){if(t.neighbours==="corners"||a)return t.byKey.get(Jg(t,s))??null;if(t.fillets){const{N:y,NE:w,E:x,SE:b,S:v,SW:$,W:_,NW:j}=Ja,N=((s&(y|x|w))===(y|x|w)?w:0)|((s&(v|x|b))===(v|x|b)?b:0)|((s&(v|_|$))===(v|_|$)?$:0)|((s&(y|_|j))===(y|_|j)?j:0);return N?t.filletByKey.get(N)??null:null}if(t.cornerRule==="diagonal"){const{N:y,NE:w,E:x,SE:b,S:v,SW:$,W:_,NW:j}=Ja,N=((s&(y|x))===(y|x)&&!(s&w)?w:0)|((s&(v|x))===(v|x)&&!(s&b)?b:0)|((s&(v|_))===(v|_)&&!(s&$)?$:0)|((s&(y|_))===(y|_)&&!(s&j)?j:0);return N?t.filletByKey.get(N)??null:null}if(!t.faces)return null;const{N:l,NE:i,E:r,SE:f,S:u,SW:h,W:d,NW:p}=Ja;if(s&l){const y=(s&r?f:s&i?r:0)|(s&d?h:s&p?d:0);return t.faceByKey.get(y)??t.faceByKey.get(y&(r|d))??null}if(!t.sides)return null;if(s&(r|d)){const y=s&(r|d)|(s&d&&s&p||s&r&&s&i?l:0)|(s&u?0:u);return t.sideByKey.get(y)??null}return t.cornerByKey.get(s&(i|p))??null}function rk(...t){let a=625341585;for(const s of t)a=Math.imul(a^(s|0),2654435761)>>>0,a=(a^a>>>15)>>>0,a=Math.imul(a,2246822519)>>>0,a=(a^a>>>13)>>>0;return a}function ck(t,a,s,l){if(a===null)return null;const i=t.alts.get(a);return i?i[rk(s,l,64206)%i.length]:a}function T0(t){return t.variants.flatMap((a,s)=>a.key===null?[]:[s])}const uk=(t,a)=>t.neighbours==="corners"?a.cols+1:a.cols;function oc(t,a,s="not",l=!0){const i=uk(t,a),r=a.cells.length/i,f=(h,d)=>h>=0&&d>=0&&h<i&&d<r?a.cells[d*i+h]===1:s!=="same"?s==="terrain":a.cells[Math.min(r-1,Math.max(0,d))*i+Math.min(i-1,Math.max(0,h))]===1,u=[];for(let h=0;h<a.rows;h++)for(let d=0;d<a.cols;d++){if(t.neighbours==="corners"){const w=(f(d+1,h)?Ja.NE:0)|(f(d+1,h+1)?Ja.SE:0)|(f(d,h+1)?Ja.SW:0)|(f(d,h)?Ja.NW:0);u.push(Wg(t,!0,w));continue}let p=0;for(const[w,x,b]of sk)f(d+x,h+b)&&(p|=w);const y=Wg(t,f(d,h),p);u.push(l?ck(t,y,d,h):y)}return u}const Ig=t=>t.bands.reduce((a,s)=>a+s.w,0);function fk(t,a,s,l,i,r){const f=t/2,u=a&1?f:0,h=a&2?f:0,d=s&1?u+f-1-l:l-u,p=s&2?h+f-1-i:i-h;return[2*(d-r)+1,2*(p-r)+1]}const Xt=t=>t*t;function yh(t,a,s,l,i){return O0(t,a,s,l,i)}function O0(t,a,s,l,i){switch(t){case"in":return!1;case"out":return!0;case"horiz":case"hround":return s<l;case"vert":case"vround":return a<l;case"fillet":case"diag":case"diagcap":case"diagside":case"outerdiag":case"diagfill":return!0;case"outer":return a>=i||s>=i?Math.min(a,s)<l:i-l<0||Xt(i-a)+Xt(i-s)>Xt(i-l);case"inner":return a>0&&s>0?l>0&&Xt(a)+Xt(s)<Xt(l):a>0?a<l:s>0?s<l:!0}}function hk(t,a,s,l,i,r){const f=Math.floor((i*99+35)/70)-l;if(f<=0)return!0;const u=Math.abs(a-s)>=f,h=Math.abs(a+s-2*r)>=f;switch(t){case"diag":return u;case"diagfill":return a+s>=f;case"diagcap":return u||h;default:return h}}function Fg(t,a,s,l,i){const r=Xt(l+i);switch(t){case"inner":return Xt(a+i)+Xt(s+i)<r;case"vround":return s<=i?Xt(a+i)+Xt(s-i)<r:a<l;case"hround":return a<=i?Xt(a-i)+Xt(s+i)<r:s<l;case"fillet":return a<=i&&s<=i?Xt(a-i)+Xt(s-i)<r:!0;default:return yh(t,a,s,l,0)}}function dk(t,a,s,l,i,r,f=0,u=0){const[h,d]=fk(a,s,t.face,l,i,r.inset),p=h-f,y=d-u;if(ok.includes(t.base)){const v=2*(Ig(r)+r.radius),$=j=>hk(t.base,p+2*r.inset,y+2*r.inset,j,a-2*r.inset,a)&&(t.base!=="outerdiag"||O0("outer",p,y,j,v));if($(0))return-1;let _=0;for(let j=0;j<r.bands.length;j++)if(_+=2*r.bands[j].w,$(_))return j;return r.bands.length}const w=2*(r.fillet??0);if((w>0||t.base==="vround"||t.base==="hround"||t.base==="fillet")&&t.base!=="outer"&&t.base!=="in"&&t.base!=="out"&&t.base!=="vert"&&t.base!=="horiz"){if(Fg(t.base,p,y,0,w))return-1;let v=0;for(let $=0;$<r.bands.length;$++)if(v+=2*r.bands[$].w,Fg(t.base,p,y,v,w))return $;return r.bands.length}const x=2*(Ig(r)+r.radius);if(yh(t.base,p,y,0,x))return-1;let b=0;for(let v=0;v<r.bands.length;v++)if(b+=2*r.bands[v].w,yh(t.base,p,y,b,x))return v;return r.bands.length}const mk=(t,a,s)=>(s>=t/2?2:0)|(a>=t/2?1:0);function pk(t,a,s,l){const i=new Int8Array(s*s),r=l.jitter&&l.jitter.px>0?yk(s,l.jitter.px,l.jitter.seed):null;for(let f=0;f<s;f++)for(let u=0;u<s;u++){const h=mk(s,u,f);i[f*s+u]=dk(t.quadSpecs[a][h],s,h,u,f,l,r?r.u[f]:0,r?r.v[u]:0)}return i}function yk(t,a,s){const l=Math.max(2,Math.floor(t/5)),i=new nn(s,11),r=()=>{const u=Array.from({length:l},()=>i.nextInt(4*a+1)-2*a),h=new Int32Array(t);for(let d=0;d<t;d++){const p=(2*d+1)*l,y=2*t,w=Math.floor(p/y),x=p-w*y;h[d]=Math.round((u[w%l]*(y-x)+u[(w+1)%l]*x)/y)}return h},f=r();return{u:r(),v:f}}function gk(t,a){return t.inset?Math.floor(a*t.inset[0]/t.inset[1]):0}function wk(t){const a=f=>{const u=f/255;return u<=.04045?u/12.92:((u+.055)/1.055)**2.4},[s,l,i]=vn(t),r=.2126*a(s)+.7152*a(l)+.0722*a(i);return r>216/24389?116*Math.cbrt(r)-16:24389/27*r}function vk(t){return t.views.length?[...new Set(t.views.filter(a=>!a.mirror).map(a=>a.from))]:[0]}function Jr(t,a){if(t.width!==a.width||t.height!==a.height||t.frameCount!==a.frameCount)return!1;const s=new Map,l=new Map;let i=!1;for(let r=0;r<t.frameCount;r++){const f=Ce(t,r),u=Ce(a,r);for(let h=0;h<f.length;h++){const d=f[h],p=u[h];if(d===ne!=(p===ne))return!1;if(d!==ne){if((s.get(d)??p)!==p||(l.get(p)??d)!==d)return!1;s.set(d,p),l.set(p,d)}}}for(const[r,f]of s)(t.palette.entries[r].hex.toLowerCase()!==a.palette.entries[f].hex.toLowerCase()||t.palette.entries[r].role!==a.palette.entries[f].role)&&(i=!0);return i&&s.size>0}function xk(t,a,s){const l=[];let i=0,r=0,f=0,u=a,h=s,d=-1,p=-1;const y=new Int32Array(a*s),w=new Int32Array(a*s);for(let v=0;v<s;v++)for(let $=0;$<a;){if(t[v*a+$]===ne){$++;continue}let _=$;for(;_<a&&t[v*a+_]!==ne;)_++;for(let j=$;j<_;j++)y[v*a+j]=_-$;$=_}for(let v=0;v<a;v++)for(let $=0;$<s;){if(t[$*a+v]===ne){$++;continue}let _=$;for(;_<s&&t[_*a+v]!==ne;)_++;for(let j=$;j<_;j++)w[j*a+v]=_-$;$=_}for(let v=0;v<s;v++)for(let $=0;$<a;$++){const _=v*a+$;t[_]!==ne&&(l.push(Math.min(y[_],w[_])),i++,r+=$,f+=v,u=Math.min(u,$),h=Math.min(h,v),d=Math.max(d,$),p=Math.max(p,v))}if(!i)return{stroke:null,fill:null,centre:null};const x=r/i,b=f/i;return{stroke:A0(l),fill:(d-u+1)*(p-h+1)/(a*s),centre:{x,y:b,off:Math.hypot(x-(a-1)/2,b-(s-1)/2)}}}function Pg(t,a){const s=t.palette,l=s.entries.map(L=>wk(L.hex)),i=new Set(s.entries.flatMap((L,Y)=>a.includes(L.name)?[Y]:[]));if(!i.size&&!t.wrap){let L=-1;for(const Y of Ce(t,0))Y!==ne&&(L<0||l[Y]<l[L])&&(L=Y);L>=0&&i.add(L)}const r=t.width,f=t.height;let u=0,h=0,d=0,p=0,y=0,w=0,x=0,b=0,v=0,$=r,_=f,j=-1,N=-1;const M=new Map,A=new Map,z=new Map,E=new Map;for(const[L,Y]of Object.entries(s.ramps))for(const O of Y){const H=s.entries.findIndex(G=>G.name===O);H>=0&&!E.has(H)&&!i.has(H)&&E.set(H,L)}const R=vk(t);for(const L of R){const Y=Ce(t,L),O=(G,Z)=>t.wrap?Y[(Z+f)%f*r+(G+r)%r]:G<0||Z<0||G>=r||Z>=f?ne:Y[Z*r+G];for(let G=0;G<f;G++)for(let Z=0;Z<r;Z++){const W=Y[G*r+Z];if(W===ne)continue;u++,h+=l[W],L===R[0]&&($=Math.min($,Z),_=Math.min(_,G),j=Math.max(j,Z),N=Math.max(N,G));const se=E.get(W);if(se&&((M.get(se)??M.set(se,new Set).get(se)).add(W),z.set(se,(z.get(se)??0)+1),A.set(W,(A.get(W)??0)+1)),!t.wrap&&[[1,0],[-1,0],[0,1],[0,-1]].some(([ue,te])=>O(Z+ue,G+te)===ne)&&(d++,i.has(W)&&p++),se)for(const[ue,te]of[[1,0],[0,1]]){const U=O(Z+ue,G+te);if(U===ne||U===W||E.get(U)!==se)continue;const V=l[U]-l[W];y+=ue*V,w+=te*V,x+=Math.abs(V)}}const H=new Uint8Array(r*f);for(let G=0;G<Y.length;G++){const Z=Y[G];if(Z===ne||i.has(Z)||H[G])continue;let W=0;const se=[G];for(H[G]=1;se.length;){const ue=se.pop();W++;const te=ue%r,U=Math.floor(ue/r);for(const[V,P]of[[1,0],[-1,0],[0,1],[0,-1]]){let ie=te+V,ye=U+P;if(t.wrap)ie=(ie+r)%r,ye=(ye+f)%f;else if(ie<0||ye<0||ie>=r||ye>=f)continue;const F=ye*r+ie;!H[F]&&Y[F]===Z&&(H[F]=1,se.push(F))}}b++,v+=W}}if(!u)return{box:null,lightness:null,outline:null,light:null,cluster:null,steps:null,material:null,stroke:null,fill:null,centre:null};const B=Math.hypot(y,w),K=x>0?B/x:0,J=Math.max(3,Math.floor(u/100)),T=[...M.values()].map(L=>[...L].filter(Y=>(A.get(Y)??0)>=J).length).filter(L=>L>0),D=[...z].sort((L,Y)=>Y[1]-L[1]||(L[0]<Y[0]?-1:1))[0]?.[0]??null;return{box:j>=0?{x:$,y:_,w:j-$+1,h:N-_+1}:null,lightness:h/u,outline:t.wrap?null:d?p/d:null,light:t.wrap||K<.1?null:{x:y/B,y:w/B,strength:K},cluster:b?v/b/Math.sqrt(u/R.length):null,steps:T.length?T.reduce((L,Y)=>L+Y,0)/T.length:null,material:D,...xk(Ce(t,R[0]),r,f)}}const zn={n:[0,-1],ne:[1,-1],e:[1,0],se:[1,1],s:[0,1],sw:[-1,1],w:[-1,0],nw:[-1,-1]};function bk(t){const a=[...t].sort((l,i)=>l-i),s=l=>{const i=l*(a.length-1),r=Math.floor(i);return r+1<a.length?a[r]+(a[r+1]-a[r])*(i-r):a[r]};return[s(.25),s(.75)]}function A0(t){const a=[...t].sort((s,l)=>s-l);return a.length%2?a[(a.length-1)/2]:(a[a.length/2-1]+a[a.length/2])/2}const pa=t=>Math.round(t*10)/10,th=t=>Math.round(t*100)/100;function q0(t,a,s){const l=a.filter(p=>Jr(p.doc,t)||Jr(t,p.doc)).map(p=>p.name),i=a.filter(p=>p.doc!==t&&!l.includes(p.name)),r=Pg(t,s.ink),f=i.map(p=>({name:p.name,m:Pg(p.doc,s.ink)})),u=[];if(s.height!==void 0&&r.box){const p=r.box.h-s.height;u.push({name:"height",value:r.box.h,limit:`${s.height} ± ${s.heightTol}`,pass:Math.abs(p)<=s.heightTol,detail:`the drawn shape is ${r.box.h} px tall (rows ${r.box.y}..${r.box.y+r.box.h-1}); the manifest plans ${s.height}`})}const h=(p,y,w,x,b,v=!1,$=!1,_=!1)=>{const j=w(r),N=f.filter(z=>!$||z.m.material!==null&&z.m.material===r.material).map(z=>w(z.m)).filter(z=>z!==null);if(j===null||N.length<2)return;const M=A0([...N,j]);if(_){const[z,E]=bk([...N,j]),R=j<z?z-j:j>E?j-E:0,B=z===E?b(z):`${b(z)}..${b(E)}`;u.push({name:y,value:j,limit:`± ${b(x)} of the set's ${B}`,pass:R<=x,detail:`${b(j)} against the set's middle half ${B} (with ${N.length} others)`});return}const A=v?M>0?Math.max(j/M,M/j):1:Math.abs(j-M);u.push({name:y,value:j,limit:v?`× ${x} of the set's ${b(M)}`:`± ${b(x)} of the set's ${b(M)}`,pass:A<=x,detail:`${b(j)} against the set's median ${b(M)} (with ${N.length} others${$?` mostly in ${r.material}`:""})`})};if(h("lightness","lightness",p=>p.lightness,s.maxL,p=>String(pa(p)),!1,!0),h("outline","outline share",p=>p.outline,s.maxOutline,p=>String(th(p))),h("cluster","cluster size",p=>p.cluster,s.maxCluster,p=>String(th(p)),!0),h("steps","ramp steps",p=>p.steps,s.maxSteps,p=>String(pa(p)),!1,!1,!0),s.icon&&(h("stroke","stroke weight",p=>p.stroke,s.icon.maxStroke,p=>String(pa(p))),h("fill","box fill",p=>p.fill,s.icon.maxFill,p=>String(th(p))),r.centre)){const p=r.centre;u.push({name:"optical centre",value:pa(p.off),limit:`≤ ${s.icon.maxCentre} px from the canvas centre`,pass:p.off<=s.icon.maxCentre,detail:`the drawn pixels' centre is at ${pa(p.x)},${pa(p.y)}, ${pa(p.off)} px from the canvas centre ${pa((t.width-1)/2)},${pa((t.height-1)/2)}`})}const d=s.light&&zn[s.light]?zn[s.light]:(()=>{const p=f.flatMap(x=>x.m.light?[x.m.light]:[]);if(p.length<2)return null;const y=p.reduce((x,b)=>x+b.x,0),w=p.reduce((x,b)=>x+b.y,0);return Math.hypot(y,w)>0?[y,w]:null})();if(d&&!t.wrap){const p=Math.hypot(d[0],d[1]);if(r.light){const y=(r.light.x*d[0]+r.light.y*d[1])/p,w=Math.acos(Math.max(-1,Math.min(1,y)))*180/Math.PI,x=Object.entries(zn).sort((b,v)=>{const $=(b[1][0]*r.light.x+b[1][1]*r.light.y)/Math.hypot(...b[1]);return(v[1][0]*r.light.x+v[1][1]*r.light.y)/Math.hypot(...v[1])-$})[0][0];u.push({name:"light",value:Math.round(w),limit:`≤ ${s.maxAngle}° from ${s.light??"the set's"}`,pass:w<=s.maxAngle,detail:`lit from the ${x} (${Math.round(w)}° from ${s.light?`the style guide's ${s.light}`:"the set's light"})`})}else u.push({name:"light",value:null,limit:"",pass:null,detail:"no clear lit side (flat shading)"})}return{parts:u,recolours:l,peers:i.map(p=>p.name),box:r.box}}const ew=(t,a)=>(t%a+a)%a;function yn(t,a,s){return t.wrap?ew(s,t.height)*t.width+ew(a,t.width):a<0||s<0||a>=t.width||s>=t.height?-1:s*t.width+a}function Bh(t,a){const s=Math.abs(a[0]-t[0])>=Math.abs(a[1]-t[1]),l=b=>s?[b[0],b[1]]:[b[1],b[0]],[i,r]=[l(t),l(a)],f=r[0]<i[0]||r[0]===i[0]&&r[1]<i[1],[u,h]=f?[r,i]:[i,r],d=h[0]-u[0]+1,p=Math.abs(h[1]-u[1])+1,y=h[1]<u[1]?-1:1,w=b=>{const v=2*b*d+p,$=2*p;let _=Math.floor(v/$);return v%$===0&&2*b<=p&&(_-=1),_},x=[];for(let b=0;b<p;b++)for(let v=w(b);v<w(b+1);v++){const $=u[0]+v,_=u[1]+y*b;x.push(s?[$,_]:[_,$])}return f&&x.reverse(),x}function R0(t,a){const s=[],l=new Set;for(let i=0;i<t.length;i++){if(i===0){s.push(t[0]);continue}const r=Bh(t[i-1],t[i]);for(let f=1;f<r.length;f++)s.push(r[f]);if(i<t.length-1){const[f,u,h]=[t[i-1],t[i],t[i+1]],d=f[0]===u[0]||f[1]===u[1],p=u[0]===h[0]||u[1]===h[1];d&&p&&l.add(s.length-1)}}return a?D0(s,l):Ko(s)}function Wr(t,a){const s=t.length?[t[0]]:[];for(let i=1;i<t.length;i++){const r=Bh(t[i-1],t[i]);for(let f=1;f<r.length;f++)s.push(r[f])}const l=Ko(s);return a?D0(l,new Set):l}function D0(t,a){if(t.length<3)return Ko(t);const s=[t[0]];for(let l=1;l<t.length-1;l++){const i=s[s.length-1],r=t[l],f=t[l+1];Math.abs(i[0]-f[0])===1&&Math.abs(i[1]-f[1])===1&&(i[0]===r[0]||i[1]===r[1])&&(f[0]===r[0]||f[1]===r[1])&&!a.has(l)||s.push(r)}return s.push(t[t.length-1]),Ko(s)}function Ko(t){return t.filter((a,s)=>s===0||a[0]!==t[s-1][0]||a[1]!==t[s-1][1])}function Ir(t,a){let s=Math.floor(t/a);return s*a>t?s--:(s+1)*a<=t&&s++,s}function $k(t,a){const s=t.length-1;let l=0;for(let u=1;u<t.length;u++)l+=Math.max(Math.abs(t[u][0]-t[u-1][0]),Math.abs(t[u][1]-t[u-1][1]));const i=Math.max(2,Math.min(s===3?1024:8192,2*l)),r=i**s,f=[];for(let u=0;u<=i;u++){const h=i-u,d=s===3?[h*h*h,3*h*h*u,3*h*u*u,u*u*u]:[h*h,2*h*u,u*u];let p=0,y=0;for(let w=0;w<=s;w++)p+=d[w]*t[w][0],y+=d[w]*t[w][1];f.push([Ir(2*p+r,2*r),Ir(2*y+r,2*r)])}return Wr(Ko(f),a)}function U0(t,a,s){const l=R0([...t,t[0]],s);if(!a)return gh(l);const i=[...l],r=t.map(u=>u[1]),f=t.length;for(let u=Math.min(...r);u<=Math.max(...r);u++){const h=[];for(let d=0;d<f;d++){const[p,y]=t[d],[w,x]=t[(d+1)%f];if(y===x||u<Math.min(y,x)||u>=Math.max(y,x))continue;const b=p*(x-y)+(u-y)*(w-p),v=x-y;h.push(v>0?[b,v]:[-b,-v])}h.sort((d,p)=>d[0]*p[1]-p[0]*d[1]);for(let d=0;d+1<h.length;d+=2){const[p,y]=h[d],[w,x]=h[d+1];for(let b=-Ir(-p,y);b<=Ir(w,x);b++)i.push([b,u])}}return gh(i)}function si(t,a,s,l,i){const r=[];for(let f=0;f<l;f++)for(let u=0;u<s;u++)(i||f===0||f===l-1||u===0||u===s-1)&&r.push([t+u,a+f]);return r}function ic(t,a,s,l,i){const r=new Map,f=[],u=(v,$)=>{f.push([v,$]);const _=r.get($);_?(_[0]=Math.min(_[0],v),_[1]=Math.max(_[1],v)):r.set($,[v,v])};let h=Math.abs(s-t);const d=Math.abs(l-a);let p=d&1,y=4*(1-h)*d*d,w=4*(p+1)*h*h,x=y+w+p*h*h;t>s&&(t=s,s+=h),a>l&&(a=l),a+=d+1>>1,l=a-p,h*=8*h,p=8*d*d;do{u(s,a),u(t,a),u(t,l),u(s,l);const v=2*x;v<=w&&(a++,l--,w+=h,x+=w),(v>=y||2*x>w)&&(t++,s--,y+=p,x+=y)}while(t<=s);for(;a-l<=d;)u(t-1,a),u(s+1,a++),u(t-1,l),u(s+1,l--);if(!i)return gh(f);const b=[];for(const[v,[$,_]]of[...r.entries()].sort((j,N)=>j[0]-N[0]))for(let j=$;j<=_;j++)b.push([j,v]);return b}function gh(t){const a=new Set;return t.filter(([s,l])=>a.has(`${s},${l}`)?!1:(a.add(`${s},${l}`),!0))}function H0(t,a,s,l,i,r){const f=yn(t,a,s),u=t.mask;if(f<0||u&&!u[f])return;const h=t.pixels[f];if(h===l)return;if(i){for(let y=0;y<t.pixels.length;y++)t.pixels[y]===h&&(!u||u[y])&&(t.pixels[y]=l);return}const d=r===4?[[1,0],[-1,0],[0,1],[0,-1]]:[[1,0],[-1,0],[0,1],[0,-1],[1,1],[1,-1],[-1,1],[-1,-1]],p=[f];for(t.pixels[f]=l;p.length;){const y=p.pop(),w=y%t.width,x=(y-w)/t.width;for(const[b,v]of d){const $=yn(t,w+b,x+v);$>=0&&t.pixels[$]===h&&(!u||u[$])&&(t.pixels[$]=l,p.push($))}}}const Fr=Object.keys(zn);function L0(t){const a=t&&zn[t]?zn[t]:zn.nw;return Object.entries(zn).find(([,s])=>s[0]===-a[0]&&s[1]===-a[1])[0]}function B0(t,a,s,l){let i=-1,r=-1;for(let b=0;b<s;b++)for(let v=0;v<a;v++)t[b*a+v]!==ne&&(i<0&&(i=b),r=b);if(r<0)return null;const f=Math.max(1,Math.floor((r-i+1)/3));let u=a,h=-1;for(let b=r-f+1;b<=r;b++)for(let v=0;v<a;v++)t[b*a+v]!==ne&&(u=Math.min(u,v),h=Math.max(h,v));const d=h-u+3,p=Math.max(2,Math.floor((d+1)/3)),y=Math.max(1,Math.floor(d/6)),[w,x]=zn[l]??[1,1];return{x:u-1+w*y,y:r-(p>>1)+x*y,w:d,h:p}}const Y0=t=>ic(t.x,t.y,t.x+t.w-1,t.y+t.h-1,!0);function kk(t,a){const s=t.map((r,f)=>f),l=new Set;for(const{palette:r,map:f}of a)for(const u of Object.values(r.ramps)){const h=u.map(d=>r.entries.findIndex(p=>p.name===d));for(let d=1;d<h.length;d++){const p=f[h[d]],y=f[h[d-1]];p===void 0||y===void 0||l.has(p)||(s[p]=y,l.add(p))}}const i=t.map(r=>ql(r.hex));return t.forEach((r,f)=>{if(l.has(f))return;let u=-1;for(let h=0;h<t.length;h++)i[f]-i[h]>=6&&(u<0||i[h]>i[u])&&(u=h);u>=0&&(s[f]=u)}),s}function G0(t){const a=new Map(t.map(l=>[l.name,l.doc])),s=new Map;for(const l of[...t].sort((i,r)=>i.name<r.name?-1:i.name>r.name?1:0)){const i=l.doc.variantOf;i&&s.set(i,[...s.get(i)??[],l.doc])}return{get:l=>a.get(l),family:l=>{const i=a.get(l);return i?[i,...(s.get(l)??[]).filter(r=>_k(i,r))]:[]}}}function _k(t,a){return t.width!==a.width||t.height!==a.height?!1:t.family||a.family?!!t.family&&!!a.family&&t.family.scheme===a.family.scheme&&t.family.tile===a.family.tile:!0}const oi=t=>[Math.max(1,Math.floor(t.width/t.cellW)),Math.max(1,Math.floor(t.height/t.cellH))];function ga(t){if(t.footprint)return t.footprint;const[a,s]=oi(t);return{cols:a,rows:s,at:[0,0],anchor:[0,s-1],flags:Array.from({length:s},()=>".".repeat(a))}}function Yh(t,a,s){const l=t.flags[s]?.[a]??".";return{block:l==="b"||l==="x",roof:l==="r"||l==="x"}}const wh=(t,a,s)=>a>=t.at[0]&&s>=t.at[1]&&a<t.at[0]+t.cols&&s<t.at[1]+t.rows;function el(t,a,s){return{x:a-t.anchor[0],y:s-t.anchor[1],w:t.cols,h:t.rows}}function Gh(t,a=["tiles","objects"]){const s=[];return t.layers.forEach((l,i)=>{if(!l.map||!a.includes(l.map.kind))return;const r=t.cels[i][0];for(let f=0;f<r.length;f++)r[f]!==ne&&s.push({layer:i,entry:r[f],x:f%t.width,y:Math.floor(f/t.width)})}),s}function Bs(t,a){const s=t.layers[a]?.map?.kind,l=Gh(t).filter(r=>s==="objects"?t.layers[r.layer].map.kind==="objects":r.layer===a),i=new Int32Array(t.width*t.height).fill(-1);return l.forEach((r,f)=>{const u=el(t.map.entries[r.entry],r.x,r.y);for(let h=u.y;h<u.y+u.h;h++)for(let d=u.x;d<u.x+u.w;d++)d>=0&&h>=0&&d<t.width&&h<t.height&&(i[h*t.width+d]=f)}),{grid:i,placed:l}}function Zr(t,a,s,l){const{grid:i,placed:r}=Bs(t,a),f=s>=0&&l>=0&&s<t.width&&l<t.height?i[l*t.width+s]:-1;return f>=0?r[f]:null}function jk(t,a,s){const l=t.cels[a][0],i=t.width,r=t.height,f=(d,p)=>l[Math.min(p,r-1)*i+Math.min(d,i-1)]===1?1:0;if(s.neighbours!=="corners")return{cols:i,rows:r,cells:Uint8Array.from(l,d=>d===1?1:0)};const u=t.layers[a].map?.kind==="terrain"?t.layers[a].map.border:void 0,h=new Uint8Array((i+1)*(r+1));for(let d=0;d<=r;d++)for(let p=0;p<=i;p++){const y=p===0||d===0||p===i||d===r;h[d*(i+1)+p]=y&&u?u==="terrain"?1:0:f(p,d)}return{cols:i,rows:r,cells:h}}function Sk(t,a,s,l){const i=new Map,r=(u,h)=>{const d=h.reduce((y,w)=>y+w.weight,0);let p=u%d;for(const y of h){if(p<y.weight)return y.name;p-=y.weight}return h[0].name},f=(u,h,d)=>{if(u<0||h<0||u>=s||h>=l||d(h*s+u))return null;const p=h*s+u,y=i.get(p);if(y!==void 0)return y;let w=r(Rs(u,h,a,7170424),t);const x=f(u-1,h,d),b=f(u,h-1,d);return w===x&&w===b&&(t.length>2||w===f(u-1,h-1,d))&&t.length>1&&(w=r(Rs(u,h,a,7170425),t.filter($=>$.name!==w))),i.set(p,w),w};return(u,h,d)=>f(u,h,d)}class Nk{entries;maps=new Map;constructor(a){this.entries=a.map(s=>({name:s.name,hex:s.hex}))}of(a){let s=this.maps.get(a);return s||(s=a.palette.entries.map(l=>{let i=this.entries.findIndex(r=>r.name===l.name&&r.hex===l.hex);return i<0&&(i=this.entries.findIndex(r=>r.hex===l.hex)),i<0&&(this.entries.push({name:l.name,hex:l.hex}),i=this.entries.length-1),i}),this.maps.set(a,s),s)}}const Hr=(t,a)=>!t.variants[a].on&&t.variants[a].quads.every(s=>s==="in"||s.startsWith("in@"));function tw(t,a){if(t.frameCount<2)return 0;const s=Pa(t)[0];return sc(s).length?El(t,s,a):0}function Xh(t,a,s={}){const l=t.map,i=l.tile,r=t.width,f=t.height,u=r*i,h=f*i,d=s.tick??0,p=new Nk(t.palette.entries),y=new Uint16Array(u*h).fill(ne),w=Array.from({length:r*f},()=>null),x=Array.from({length:r*f},()=>null),b=[],v=new Map,$=new Set,_=Y=>{$.add(Y);const O=tw(Y,d);let H=v.get(Y);H||v.set(Y,H=new Map);let G=H.get(O);if(!G){const Z=p.of(Y);G=Ce(Y,O).map(W=>W===ne?W:Z[W]),H.set(O,G)}return G},j=(Y,O,H,G,Z,W,se,ue)=>{for(let te=0;te<W;te++){const U=ue+te;if(!(U<0||U>=h))for(let V=0;V<Z;V++){const P=se+V;if(P<0||P>=u)continue;const ie=Y[(G+te)*O+H+V];ie!==ne&&(y[U*u+P]=ie)}}},N=new Map,M=Y=>{const O=tw(Y,d);let H=N.get(Y);H||N.set(Y,H=new Map);let G=H.get(O);if(!G){const Z=p.of(Y);G=new Uint16Array(Y.width*Y.height).fill(ne),Y.layers.forEach((W,se)=>{if(W.hidden||W.reference||W.underlay||W.name===ii)return;const ue=Y.cels[se][O];for(let te=0;te<ue.length;te++)ue[te]!==ne&&(G[te]=Z[ue[te]])}),H.set(O,G)}return G},A=new Set,z=Y=>{const O=a.family(Y);return!O.length&&!A.has(Y)&&(A.add(Y),b.push(`no asset '${Y}'`)),O},E=new Map,R=(Y,O,H,G)=>{if(Y.length<2)return Y[0];let Z=E.get(G);Z||E.set(G,Z=new Int16Array(r*f).fill(-1));const W=Rs(O,H,G,90);let se=W%Y.length;const ue=O>0?Z[H*r+O-1]:-1,te=H>0?Z[(H-1)*r+O]:-1;return se===ue&&se===te&&(se=(se+1+(W>>>16)%(Y.length-1))%Y.length),O>=0&&H>=0&&O<r&&H<f&&(Z[H*r+O]=se),Y[se]},B=[];t.layers.forEach((Y,O)=>{const H=Y.map;if(!H||Y.hidden||H.kind==="objects"||s.groundOnly&&H.kind==="overlay")return;const G=t.cels[O][0];if(H.kind==="terrain"){const te=z(H.family).filter(ie=>ie.family);if(!te.length){a.get(H.family)&&b.push(`layer ${Y.name}: '${H.family}' is not a family`);return}const U=yt(te[0].family),V=oc(U,jk(t,O,U),H.border??"same"),P=H.mix?Sk(H.mix,H.seed??1,r,f):null;V.forEach((ie,ye)=>{const F=ye%r,pe=Math.floor(ye/r);if(ie===null&&!H.outside)return;if(P&&ie!==null&&Hr(U,ie)){const Se=P(F,pe,$e=>$e<0||V[$e]===null||!Hr(U,V[$e])),be=a.get(Se);if(!be){b.push(`layer ${Y.name}: mix= names '${Se}', which is not drawn`);return}if(be.width!==i||be.height!==i){b.push(`layer ${Y.name}: mix= tile '${Se}' is ${be.width}x${be.height}, not ${i}x${i}`);return}j(_(be),be.width,0,0,i,i,F*i,pe*i),w[ye]={asset:Se,variant:U.variants[ie].name,edge:!1,...H.outside?{base:!0}:{},...H.walkable?{walkable:!0}:{}},x[ye]=ie;return}const fe=R(te,F,pe,O),ge=tn(fe.family),[Re,rt]=ie===null?ge.outside:ge.cells[ie];if(ie!==null&&Hh(U.variants[ie].on)&&!H.outside)j(M(fe),fe.width,Re*i,rt*i,i,i,F*i,pe*i);else if(ie!==null&&U.variants[ie].on&&!H.outside){const Se=ri(U,i,fe.family.geometry)[ie],be=_(fe);for(let $e=0;$e<i;$e++)for(let Me=0;Me<i;Me++){if(ev(fe.family.geometry,Se[$e*i+Me]))continue;const Ge=be[(rt*i+$e)*fe.width+Re*i+Me];Ge!==ne&&(y[(pe*i+$e)*u+F*i+Me]=Ge)}}else j(_(fe),fe.width,Re*i,rt*i,i,i,F*i,pe*i);w[ye]={asset:fe.name,variant:ie===null?"outside":U.variants[ie].name,edge:ie!==null&&!Hr(U,ie),...H.outside?{base:!0}:{},...H.walkable?{walkable:!0}:{}},x[ye]=ie});return}if(H.kind==="tiles"){for(let te=0;te<G.length;te++){const U=G[te];if(U===ne)continue;const V=l.entries[U],P=te%r,ie=Math.floor(te/r),ye=V.exact&&a.get(V.name)?[a.get(V.name)]:z(V.name);if(!ye.length)continue;const F=el(V,P,ie);if(V.variant){const ge=R(ye,P,ie,O),Re=ge.family?yt(ge.family).byName.get(V.variant):void 0;if(Re===void 0){b.push(`${V.name} has no variant '${V.variant}'`);continue}const[rt,Se]=tn(ge.family).cells[Re];j(_(ge),ge.width,rt*i,Se*i,i,i,F.x*i,F.y*i),F.x>=0&&F.y>=0&&F.x<r&&F.y<f&&(w[F.y*r+F.x]={asset:ge.name,variant:V.variant,edge:!Hr(yt(ge.family),Re)});continue}const pe=R(ye,P,ie,O),fe=ga(pe);j(_(pe),pe.width,0,0,pe.width,pe.height,(F.x-fe.at[0])*i,(F.y-fe.at[1])*i);for(let ge=F.y;ge<F.y+F.h;ge++)for(let Re=F.x;Re<F.x+F.w;Re++)Re>=0&&ge>=0&&Re<r&&ge<f&&(w[ge*r+Re]={asset:pe.name,variant:null,edge:!1})}return}const Z=a.get(H.overlay);if(!Z?.overlay){b.push(`layer ${Y.name}: no overlay '${H.overlay}'`);return}const W=Mk(t,H),se=p.of(Z),ue=new Map;for(let te=0;te<W.length;te++){if(!W[te])continue;const U=te%r,V=Math.floor(te/r),P=sv(Z,U,V,d);if(P===null)continue;const ie=ue.get(P)??ue.set(P,Ce(Z,P)).get(P);ov(Z,P,U,V,i,(ye,F,pe)=>{ye>=0&&F>=0&&ye<u&&F<h&&(y[F*u+ye]=se[pe])},ie)}});const K=y.slice();if(!s.groundOnly){for(const Y of Gh(t,["objects"])){if(t.layers[Y.layer].hidden)continue;const O=l.entries[Y.entry],H=z(O.name),G=H.length?R(H,Y.x,Y.y,Y.layer):null,Z=G?ga(G):{cols:O.cols,rows:O.rows,at:[0,0],anchor:O.anchor,flags:[]},W=el(O,Y.x,Y.y);B.push({...Y,doc:G,name:O.name,fp:Z,px:(W.x-Z.at[0])*i,py:(W.y-Z.at[1])*i,base:W.y+W.h-1}),G&&G.cellW!==i&&b.push(`${O.name}: its cells are ${G.cellW} px, the map's ${i}`)}B.sort((Y,O)=>Y.base-O.base||Y.layer-O.layer||Y.x-O.x||Y.y-O.y)}const J=B.filter(Y=>Y.doc&&t.layers[Y.layer].map.shadow);if(J.length){const Y=kk(p.entries,[...$].map(O=>({palette:O.palette,map:p.of(O)})));for(const O of J){const H=t.layers[O.layer].map.shadow,G=B0(_(O.doc),O.doc.width,O.doc.height,H.dir);if(!G)continue;const Z=H.c==="darker"?-1:p.entries.findIndex(W=>W.name===H.c);if(H.c!=="darker"&&Z<0){b.push(`layer ${t.layers[O.layer].name}: no colour '${H.c}' for shadows`);continue}for(const[W,se]of Y0(G)){const ue=O.px+W,te=O.py+se;if(ue<0||te<0||ue>=u||te>=h)continue;const U=y[te*u+ue];U!==ne&&(y[te*u+ue]=Z<0?Y[U]:Z)}}}const T=new Int32Array(u*h).fill(-1),D=new Int32Array(u*h).fill(-1),L=(Y,O)=>{const H=B[Y];if(!H.doc)return;const G=_(H.doc),[Z,W]=oi(H.doc);for(let se=0;se<W;se++)for(let ue=0;ue<Z;ue++)if(!(O&&!Yh(H.fp,ue,se).roof))for(let te=0;te<H.doc.cellH;te++)for(let U=0;U<H.doc.cellW;U++){const V=ue*H.doc.cellW+U,P=se*H.doc.cellH+te,ie=G[P*H.doc.width+V];if(ie===ne)continue;const ye=H.px+V,F=H.py+P;ye<0||F<0||ye>=u||F>=h||(y[F*u+ye]=ie,(O?D:T)[F*u+ye]=Y)}};return B.forEach((Y,O)=>L(O,!1)),B.forEach((Y,O)=>L(O,!0)),{px:y,w:u,h,t:i,variants:x,cols:r,rows:f,palette:p.entries,ground:K,top:w,objects:B,roofOwner:D,artOwner:T,problems:b}}function Mk(t,a){const s=t.width*t.height;if(a.on==="all")return new Uint8Array(s).fill(1);const[l,i]=a.on.split(":"),r=t.layers.findIndex(h=>h.name===l),f=i==="out";if(r<0)return new Uint8Array(s);const u=t.cels[r][0];return Uint8Array.from(u,h=>h!==ne!==f?1:0)}const zk=t=>[parseInt(t.slice(1,3),16),parseInt(t.slice(3,5),16),parseInt(t.slice(5,7),16)];function Ck(t,a={}){const s=a.scale??1,l=a.region??{x:0,y:0,w:t.cols,h:t.rows},i=t.t,r=l.w*i*s,f=l.h*i*s,u=new Uint8Array(r*f*4),h=t.palette.map(x=>zk(a.hex?a.hex(x.name,x.hex):x.hex));for(let x=0;x<l.h*i;x++)for(let b=0;b<l.w*i;b++){const v=l.x*i+b,$=l.y*i+x,_=v>=0&&$>=0&&v<t.w&&$<t.h?t.px[$*t.w+v]:ne,j=_===ne?(v>>2)+($>>2)&1?[204,204,204]:[238,238,238]:h[_];for(let N=0;N<s;N++)for(let M=0;M<s;M++){const A=((x*s+N)*r+b*s+M)*4;u[A]=j[0],u[A+1]=j[1],u[A+2]=j[2],u[A+3]=255}}const d=(x,b,v,$=1)=>{if(x<0||b<0||x>=r||b>=f)return;const _=(b*r+x)*4;u[_]=Math.round(u[_]*(1-$)+v[0]*$),u[_+1]=Math.round(u[_+1]*(1-$)+v[1]*$),u[_+2]=Math.round(u[_+2]*(1-$)+v[2]*$)};if(a.grid){for(let x=0;x<=l.h;x++)for(let b=0;b<r;b++)d(b,Math.min(f-1,x*i*s),[0,0,0],.18);for(let x=0;x<=l.w;x++)for(let b=0;b<f;b++)d(Math.min(r-1,x*i*s),b,[0,0,0],.18)}const p=new Set((a.marks??[]).map(([x,b])=>`${x},${b}`)),y=(x,b)=>p.has(`${x},${b}`),w=Math.max(1,s);for(const[x,b]of a.marks??[]){const v=(x-l.x)*i*s,$=(b-l.y)*i*s,_=i*s;for(let j=0;j<_;j++)for(let N=0;N<w;N++)y(x,b-1)||d(v+j,$+N,[255,0,200]),y(x,b+1)||d(v+j,$+_-1-N,[255,0,200]),y(x-1,b)||d(v+N,$+j,[255,0,200]),y(x+1,b)||d(v+_-1-N,$+j,[255,0,200]);for(let j=0;j<_;j+=2)for(let N=(j>>1)%2;N<_;N+=2)d(v+N,$+j,[255,0,200],.3)}return{width:r,height:f,data:u}}function nw(t,a,s,l,i){const r=Math.min(t.cols,Math.ceil(l/t.t)),f=Math.min(t.rows,Math.ceil(i/t.t)),u=Math.max(0,Math.min(t.cols-r,a-Math.floor(r/2))),h=Math.max(0,Math.min(t.rows-f,s-Math.floor(f/2)));return{x:u,y:h,w:r,h:f,px:[l,i]}}const Ek={seam:1,edgeRun:4,motif:10,window:4,lattice:.3,latticeContrast:18};function Tk(t){const a=new Int32Array(t.cols*t.rows),s=new Map;for(let l=0;l<t.rows;l++)for(let i=0;i<t.cols;i++){let r=2166136261,f=19088743;for(let d=0;d<t.t;d++)for(let p=0;p<t.t;p++){const y=t.ground[(l*t.t+d)*t.w+i*t.t+p];r=Math.imul(r^y,16777619)>>>0,f=Math.imul(f+y+1,2654435761)>>>0}const u=`${r}:${f}`;let h=s.get(u);h===void 0&&s.set(u,h=s.size),a[l*t.cols+i]=h}return a}function Ok(t,a,s){const l=new Map;for(let r=0;r<t.t;r++)for(let f=0;f<t.t;f++){const u=t.ground[(s*t.t+r)*t.w+a*t.t+f];l.set(u,(l.get(u)??0)+1)}return Math.max(...l.values())>=t.t*t.t*.97}function X0(t,a,s={},l=Xh(t,a)){const i={...Ek,...s},r=O=>String(Number(O.toFixed(2))),f=[],u=l.cols,h=l.rows,d=Ih({px:l.ground,w:l.w,h:l.h,t:l.t,variants:l.variants},{palette:{entries:l.palette}});f.push({id:"seam",score:d.score,limit:i.seam,pass:d.score<=i.seam,shown:r(d.score),limitText:`≤ ${i.seam}`,groups:[],detail:`the tile grid over the whole ground: jump x ${r(d.jx)} y ${r(d.jy)}, line x ${r(d.lx)} y ${r(d.ly)}`});const p=Tk(l),y=new Uint8Array(u*h);for(let O=0;O<h;O++)for(let H=0;H<u;H++)y[O*u+H]=Ok(l,H,O)?1:0;const w=[],x=(O,H)=>!!l.top[H*u+O]?.edge&&!y[H*u+O];for(const O of[!0,!1]){const H=O?h:u,G=O?u:h;for(let Z=0;Z<H;Z++){let W=0;for(let se=1;se<=G;se++){const ue=ie=>O?[ie,Z]:[Z,ie],[te,U]=ue(W);if(se<G&&x(...ue(se))&&p[ue(se)[1]*u+ue(se)[0]]===p[U*u+te])continue;const P=se-W;if(x(te,U)&&P>i.edgeRun){const ie=l.top[U*u+te];w.push({cells:Array.from({length:P},(ye,F)=>ue(W+F)),name:`${ie.asset}.${ie.variant}`})}W=se}}}w.reduce((O,H)=>Math.max(O,H.cells.length),0);let b=0;for(let O=0;O<h;O++)for(let H=0;H<u;H++){if(!x(H,O))continue;let G=1;for(;H+G<u&&x(H+G,O)&&p[O*u+H+G]===p[O*u+H];)G++;for(b=Math.max(b,G),G=1;O+G<h&&x(H,O+G)&&p[(O+G)*u+H]===p[O*u+H];)G++;b=Math.max(b,G)}const v=Math.min(i.window,u,h),$=[];let _=0;for(let O=0;O+v<=h;O++)for(let H=0;H+v<=u;H++){const G=new Map;for(let se=0;se<v;se++)for(let ue=0;ue<v;ue++){const te=(O+se)*u+H+ue;y[te]||!l.top[te]||G.set(p[te],(G.get(p[te])??0)+1)}let Z=0,W=-1;for(const[se,ue]of G)ue>Z&&(Z=ue,W=se);_=Math.max(_,Z),Z>i.motif&&$.push({x:H,y:O,n:Z,key:W})}const j=new Uint8Array(u*h);for(const O of $)for(let H=0;H<v;H++)for(let G=0;G<v;G++){const Z=(O.y+H)*u+O.x+G;p[Z]===O.key&&(j[Z]=1)}const N=[];for(let O=0;O<j.length;O++)j[O]&&N.push([O%u,Math.floor(O/u)]);const M=new Map;for(const[O,H]of N){const G=l.top[H*u+O],Z=`${G.asset}${G.variant?`.${G.variant}`:""}`;M.set(Z,(M.get(Z)??0)+1)}const A=O=>{const H=O.map(Z=>Z[0]),G=O.map(Z=>Z[1]);return`${Math.min(...H)},${Math.min(...G)} ${Math.max(...H)-Math.min(...H)+1}x${Math.max(...G)-Math.min(...G)+1}`},z=b<=i.edgeRun,E=_<=i.motif,R=[...w.map(O=>({label:`${O.cells.length} ${O.name} in a row at ${A(O.cells)}`,cells:O.cells})),...N.length?[{label:`the same tile over and over (${[...M].map(([O,H])=>`${O} ×${H}`).join(", ")})`,cells:N}]:[]];f.push({id:"repetition",score:Math.max(b/i.edgeRun,_/i.motif),limit:1,pass:z&&E,shown:`run ${b} · ${_}/${v*v}`,limitText:`run ≤ ${i.edgeRun}, ≤ ${i.motif}/${v*v}`,groups:R,detail:[`longest straight run of one edge tile: ${b}${w.length?` (${w.slice(0,4).map(O=>`${O.name} ×${O.cells.length} at ${A(O.cells)}`).join("; ")})`:""}`,`most of one textured tile in a ${v}x${v} window: ${_} of ${v*v}${N.length?` (hot spots: ${[...M].map(([O,H])=>`${O} on ${H} cells`).join(", ")})`:""}`,...z&&E?[]:["texture variants (an asset with variant of=<base>) break the pattern: the map picks among them cell by cell"]].join("; "),parts:[{name:"edge run",value:b,limit:`≤ ${i.edgeRun}`,pass:z,detail:"the same edge tile in a straight line"},{name:"motif",value:_,limit:`≤ ${i.motif} of ${v*v}`,pass:E,detail:`one textured tile in a ${v}x${v} window`}]}),f.push(Ak(l,a,y,i));const B=[],K=new Map;l.objects.forEach((O,H)=>{const G=t.map.entries[O.entry],Z=el(G,O.x,O.y),W=[];for(let P=Z.y;P<Z.y+Z.h;P++)for(let ie=Z.x;ie<Z.x+Z.w;ie++)W.push([ie,P]);const se=`${O.name} at ${O.x},${O.y}`;if(!O.doc){B.push({label:`${se}: no such asset`,cells:W});return}const ue=W.filter(([P,ie])=>P<0||ie<0||P>=u||ie>=h);ue.length&&B.push({label:`${se}: off the map`,cells:W.filter(P=>!ue.includes(P))});const te=ga(O.doc);(te.cols!==G.cols||te.rows!==G.rows||te.anchor[0]!==G.anchor[0]||te.anchor[1]!==G.anchor[1])&&B.push({label:`${se}: placed as ${G.cols}x${G.rows} anchor ${G.anchor.join(",")}, its footprint is now ${te.cols}x${te.rows} anchor ${te.anchor.join(",")} (place it again)`,cells:W});const U=[],V=[];for(const[P,ie]of W){if(P<0||ie<0||P>=u||ie>=h)continue;const ye=ie*u+P;K.has(ye)?U.push([P,ie]):K.set(ye,H);const F=l.top[ye];F?!F.walkable&&(F.variant==="outside"||F.edge&&F.base)&&V.push([P,ie]):V.push([P,ie])}if(U.length&&B.push({label:`${se}: overlaps ${l.objects[K.get(U[0][1]*u+U[0][0])].name}`,cells:U}),V.length){const P=l.top[V[0][1]*u+V[0][0]];B.push({label:`${se}: stands on ${P?P.variant==="outside"?`${P.asset}'s outside ground`:`the edge tile ${P.asset}.${P.variant}`:"nothing"} (${V.length} of ${W.length} cells)`,cells:V})}}),f.push({id:"footprint",score:B.length,limit:0,pass:B.length===0,shown:String(B.length),limitText:"0",groups:B,detail:B.length?B.slice(0,6).map(O=>O.label).join("; "):`${l.objects.length} objects, every footprint on plain ground`});const J=[],T=l.t;l.objects.forEach((O,H)=>{if(!O.doc)return;const[G,Z]=oi(O.doc),W=Ce(O.doc,0),se=[];for(let ue=0;ue<Z;ue++)for(let te=0;te<G;te++){if(wh(O.fp,te,ue)||Yh(O.fp,te,ue).roof)continue;let U=!1;for(let V=0;V<O.doc.cellH&&!U;V++)for(let P=0;P<O.doc.cellW;P++)if(W[(ue*O.doc.cellH+V)*O.doc.width+te*O.doc.cellW+P]!==ne){U=!0;break}U&&se.push([Math.floor(O.px/T)+te,Math.floor(O.py/T)+ue])}se.length&&J.push({label:`${O.name} at ${O.x},${O.y}: art outside its footprint is not a roof (an actor walking behind would be drawn over it)`,cells:se})});const D=new Map;for(let O=0;O<l.roofOwner.length;O++){const H=l.roofOwner[O],G=l.artOwner[O];if(H<0||G<0||G===H||l.objects[G].base<=l.objects[H].base)continue;const Z=`${H}>${G}`;let W=D.get(Z);W||D.set(Z,W=new Set),W.add(Math.floor(Math.floor(O/l.w)/T)*u+Math.floor(O%l.w/T))}for(const[O,H]of D){const[G,Z]=O.split(">").map(Number),W=l.objects[G],se=l.objects[Z];J.push({label:`${W.name} at ${W.x},${W.y}: its roof hides ${se.name} at ${se.x},${se.y}, which stands in front of it`,cells:[...H].map(ue=>[ue%u,Math.floor(ue/u)])})}f.push({id:"draworder",score:J.length,limit:0,pass:J.length===0,shown:String(J.length),limitText:"0",groups:J,detail:J.length?J.slice(0,6).map(O=>O.label).join("; "):"objects in order of their base row; overhangs are roofs; no roof hides what stands in front"});const L=[],Y=new Map;for(let O=0;O<h;O++)for(let H=0;H<u;H++){const G=l.top[O*u+H];if(!G||!G.variant||G.variant==="outside")continue;let Z=!0;for(let W=0;W<T&&Z;W++)for(let se=0;se<T;se++)if(l.ground[(O*T+W)*l.w+H*T+se]!==ne){Z=!1;break}if(Z){const W=`${G.asset}.${G.variant}`;Y.set(W,[...Y.get(W)??[],[H,O]])}}for(const[O,H]of Y)L.push({label:`${O} is not drawn`,cells:H});for(const O of l.problems)L.push({label:O,cells:[]});return f.push({id:"coverage",score:L.length,limit:0,pass:L.length===0,shown:String(L.length),limitText:"0",groups:L,detail:L.length?L.map(O=>O.label).join("; "):"every tile and object the map names exists and is drawn"}),f}function Ak(t,a,s,l){const{t:i,cols:r,rows:f}=t,u=i*i,h=Math.max(2,Math.round(u/128)),d=Math.max(0,Math.round(i/16)-1),p=Math.ceil(i*.75),y=t.palette.map(te=>Kk(te.hex)),w=te=>{let U=te;for(let V=0;V<8;V++){const P=a.get(U)?.variantOf;if(!P||!a.get(P))break;U=P}return U},x=Array.from({length:r*f},()=>null),b=Array.from({length:r*f},()=>null),v=new Int32Array(u),$=te=>te.sort((U,V)=>U-V)[te.length>>1];for(let te=0;te<f;te++)for(let U=0;U<r;U++){const V=te*r+U,P=t.top[V];if(!P||P.edge||s[V])continue;const ie=[],ye=[],F=[];for(let Se=0;Se<i;Se++)for(let be=0;be<i;be++){const $e=t.ground[(te*i+Se)*t.w+U*i+be];if(v[Se*i+be]=$e===ne?-1:$e,$e!==ne){const Me=y[$e];ie.push(Me[0]),ye.push(Me[1]),F.push(Me[2])}}if(ie.length<u*.9)continue;const pe=[$(ie),$(ye),$(F)],fe=new Uint8Array(u);for(let Se=0;Se<u;Se++){if(v[Se]<0)continue;const be=y[v[Se]];Math.hypot(be[0]-pe[0],be[1]-pe[1],be[2]-pe[2])>=l.latticeContrast&&(fe[Se]=1)}const ge=[],Re=new Uint8Array(u);for(let Se=0;Se<u;Se++){if(!fe[Se]||Re[Se])continue;const be=[Se];Re[Se]=1;let $e=i,Me=i,Ge=-1,mt=-1,ct=0,X=0;for(let we=0;we<be.length;we++){const Te=be[we],Ve=Te%i,De=Te/i|0;$e=Math.min($e,Ve),Ge=Math.max(Ge,Ve),Me=Math.min(Me,De),mt=Math.max(mt,De),ct+=Ve,X+=De;for(let zt=-1;zt<=1;zt++)for(let Qt=-1;Qt<=1;Qt++){const Ht=Ve+Qt,Pn=De+zt;if(Ht<0||Pn<0||Ht>=i||Pn>=i)continue;const En=Pn*i+Ht;fe[En]&&!Re[En]&&(Re[En]=1,be.push(En))}}be.length<h||Ge-$e+1>p||mt-Me+1>p||ge.push({at:Math.floor(X/be.length)*i+Math.floor(ct/be.length),weight:be.length,pts:be})}if(x[V]=`${w(P.asset)}.${P.variant??""}`,!ge.length)continue;const rt=ge.reduce((Se,be)=>Se+be.weight,0);for(const Se of ge)Se.weight/=rt;b[V]=ge}const _=te=>{const U=new Float64Array(u);for(const V of te){const P=V.at%i,ie=V.at/i|0;for(let ye=-d;ye<=d;ye++)for(let F=-d;F<=d;F++){const pe=P+F,fe=ie+ye;pe>=0&&fe>=0&&pe<i&&fe<i&&(U[fe*i+pe]=Math.max(U[fe*i+pe],V.weight))}}return U},j=new Map;for(let te=0;te<x.length;te++){const U=x[te];if(!U)continue;let V=j.get(U);if(V||j.set(U,V={cells:0,shown:new Float64Array(u),count:new Int32Array(u)}),V.cells++,!b[te])continue;const P=_(b[te]);for(let ie=0;ie<u;ie++)P[ie]>0&&(V.shown[ie]+=P[ie],V.count[ie]++)}const N=8;let M=null;for(const[te,U]of j){if(U.cells<N)continue;let V=0;for(let ie=1;ie<u;ie++)U.shown[ie]>U.shown[V]&&(V=ie);const P=U.shown[V]/U.cells;(!M||P>M.share)&&(M={ground:te,share:P,n:U.count[V],cells:U.cells,at:V})}const A=te=>`${Math.round(te*100)}%`,z=`≤ ${A(l.lattice)}`,E={id:"lattice",limit:l.lattice,limitText:z};if(!M||M.n===0){const te=[...j.values()].reduce((U,V)=>U+(V.cells>=N?1:0),0);return{...E,score:0,pass:!0,shown:"0%",groups:[],detail:te?`no mark comes back at the same spot of the cell (${te} ground${te===1?"":"s"} looked at)`:"no stretch of plain ground big enough to show a lattice"}}const R=[],B=new Map,K=new Int32Array(u),J=M.at%i,T=M.at/i|0;for(let te=0;te<x.length;te++){if(x[te]!==M.ground||!b[te])continue;const U=b[te].filter(P=>Math.abs(P.at%i-J)<=d&&Math.abs((P.at/i|0)-T)<=d);if(!U.length)continue;R.push([te%r,Math.floor(te/r)]);const V=t.top[te].asset;B.set(V,(B.get(V)??0)+1);for(const P of U)for(const ie of P.pts)K[ie]++}let D=i,L=i,Y=-1,O=-1;const H=K.reduce((te,U)=>Math.max(te,U),0);for(let te=0;te<u;te++)if(K[te]>=H*.75){const U=te%i,V=te/i|0;D=Math.min(D,U),Y=Math.max(Y,U),L=Math.min(L,V),O=Math.max(O,V)}const[G]=M.ground.split("."),Z=M.share<=l.lattice,W=`${D},${L} ${Y-D+1}x${O-L+1}`,se=Math.abs(M.share-M.n/M.cells)>.005?` (as ${A(M.share*M.cells/M.n)} of their marking, on average)`:"",ue=`a mark at ${W} of the cell (${[...B].map(([te,U])=>`${te} ×${U}`).join(", ")}) comes back on the tile pitch`;return{...E,score:Number(M.share.toFixed(3)),pass:Z,shown:A(M.share),groups:Z?[]:[{label:ue,cells:R}],detail:`${Z?`the mark most often at one spot: at ${W} of the cell (${[...B].map(([te,U])=>`${te} ×${U}`).join(", ")})`:ue}: ${M.n} of the ${M.cells} cells of ${G}'s ground show it at the same spot${se}`+(Z?"":`; give ${G} texture variants that move or leave out the mark (variant of=${G}) and fill with a mix of them (tiles <layer> fill mix=${G}:1,<variant>:2,...; a terrain's inside: layer set <layer> mix=…), or soften the mark`)}}function qk(t,a,s=0){const l=Ce(t,s),i=Ce(a,Math.min(s,a.frameCount-1)),r=(x,b)=>{const v=new Map;let $=0,_=0;for(const j of x){if(j===ne)continue;const N=b.palette.entries[j].hex;v.set(N,(v.get(N)??0)+1),_+=ql(N),$++}return{n:v,tot:Math.max(1,$),l:_/Math.max(1,$)}},f=r(l,t),u=r(i,a);let h=0;for(const x of new Set([...f.n.keys(),...u.n.keys()]))h+=Math.abs((f.n.get(x)??0)/f.tot-(u.n.get(x)??0)/u.tot);const d=Math.abs(f.l-u.l),p=[],y=t.width,w=t.height;if(a.width===y&&a.height===w&&!t.family)for(let x=0;x<w;x++)for(let b=0;b<y;b++){if(b!==0&&x!==0&&b!==y-1&&x!==w-1)continue;const v=l[x*y+b],$=i[x*y+b],_=v===ne?"":t.palette.entries[v].hex,j=$===ne?"":a.palette.entries[$].hex;_!==j&&p.push([b,x])}return{l1:h,dl:d,border:p,ok:h<.3&&d<2}}function Rk(t){const a=t.trim(),s=/^(\d+),(\d+)(?:\s+|,)(\d+)x(\d+)$/.exec(a)??/^(\d+),(\d+),(\d+),(\d+)$/.exec(a);if(!s)return null;const[l,i,r,f]=s.slice(1).map(Number);return{x:l,y:i,w:r,h:f}}function aw(t,a){let s=Math.floor(t/a);return s*a>t?s--:(s+1)*a<=t&&s++,s}function vh(t){let a=Math.floor(Math.sqrt(t));for(;a*a>t;)a--;for(;(a+1)*(a+1)<=t;)a++;return a}function rc(t,a=0,s=1){const l=t.value.trim();let i=null,r;if((r=/^(\d+)\/(\d+)$/.exec(l))&&Number(r[2])>0)i={num:Number(r[1]),den:Number(r[2]),text:`${Number(r[1])}/${Number(r[2])}`};else if((r=/^(\d*)(?:\.(\d{1,6}))?(%?)$/.exec(l))&&(r[1]||r[2])){const f=r[2]??"";let u=Number((r[1]||"0")+f),h=10**f.length;r[3]&&(h*=100);let d=f.length+(r[3]?2:0);for(;d>0&&u%10===0;)u/=10,h/=10,d--;const p=Math.floor(u/h),y=String(u-p*h).padStart(d,"0");i={num:u,den:h,text:d?`${p}.${y}`:String(p)}}if(!i)throw new C(t.line,t.vcol,`${t.key}= must be a number like 0.25, 3/16 or 25%`);if(i.num*1<a*i.den||i.num>s*i.den)throw new C(t.line,t.vcol,`${t.key}= must be between ${a} and ${s}`);return i}function gn(t,a,s){if(!/^-?\d+$/.test(t.value))throw new C(t.line,t.vcol,`${t.key}= must be a whole number`);const l=Number(t.value);if(l<a||l>s)throw new C(t.line,t.vcol,`${t.key}= must be ${a}..${s}`);return l}function Pr(t,a,s){const l=/^(\d+)(?:\.\.(\d+))?$/.exec(t.value);if(!l)throw new C(t.line,t.vcol,`${t.key}= must be a range like 2..4`);const i=Number(l[1]),r=Number(l[2]??l[1]);if(i<a||r>s||i>r)throw new C(t.line,t.vcol,`${t.key}= must be within ${a}..${s}, smallest first`);return[i,r]}function Z0(t,a){const s=t.value.split(",");if(!s.every(i=>/^\d+$/.test(i)))throw new C(t.line,t.vcol,`${t.key}= must be whole numbers like 1,6,2`);const l=s.map(Number);if(l.length!==a)throw new C(t.line,t.vcol,`${t.key}= needs ${a} weights (one per colour), not ${l.length}`);if(l.every(i=>i===0))throw new C(t.line,t.vcol,`${t.key}= needs a weight above 0`);if(l.some(i=>i>1e4))throw new C(t.line,t.vcol,`${t.key}= weights must be at most 10000`);return l}function cc(t,a){const s=t.value,l=a.ramps[s],i=u=>a.entries.findIndex(h=>h.name===u||[...u].length===1&&h.key===u);if(l)return{name:s,idx:l.map(i),text:s};const r=s.split(",");if(r.length<2){const u=Object.keys(a.ramps);throw new C(t.line,t.vcol,`unknown ramp '${s}' (palette '${a.name}' ramps: ${u.length?u.join(", "):"none"}; or list entries: ramp=a,b,c)`)}const f=[];for(const u of r){const h=i(u);if(h<0)throw new C(t.line,t.vcol,`ramp: '${u}' is not an entry of palette '${a.name}'`);f.push(h)}return{name:null,idx:f,text:f.map(u=>a.entries[u].name).join(",")}}function Zh(t,a){const s=t.entries[a]?.name,l=[];for(const i of Object.values(t.ramps)){const r=i.indexOf(s??"");r>=0&&l.push({ramp:i.map(f=>t.entries.findIndex(u=>u.name===f)),at:r})}return l}const Qh=[30,31,36],uc=[204,204,204],Vh=[238,238,238],lw=[255,0,200];function tl(t,a,s,l,i=255){if(a<0||s<0||a>=t.width||s>=t.height)return;const r=(s*t.width+a)*4;t.data[r]=l[0],t.data[r+1]=l[1],t.data[r+2]=l[2],t.data[r+3]=i}function Jo(t,a,s,l,i,r){for(let f=0;f<i;f++)for(let u=0;u<l;u++)tl(t,a+u,s+f,r)}function As(t,a){return li(t.palette,a).entries.map(s=>vn(s.hex))}function Kh(t,a,s,l,i,r,f){for(const[u,h]of i){if(u<0||h<0||u>=r||h>=f)continue;const d=a+u*l,p=s+h*l;if(l<4){for(let b=0;b<l;b++)for(let v=0;v<l;v++)tl(t,d+v,p+b,lw);continue}const y=l+Math.max(2,l>>1),w=l>=8?4:2,x=(y>>1)+1;for(let b=-x;b<l+x;b++)for(let v=-x;v<l+x;v++){const $=2*v+1-l,_=2*b+1-l,j=$*$+_*_;j<=y*y&&j>(y-w)*(y-w)&&tl(t,d+v,p+b,lw)}}}function xh(t,a=0,s){const l=Ce(t,a),i=As(t,s),r=ll(t.width,t.height);for(let f=0;f<l.length;f++){if(l[f]===ne)continue;const u=i[l[f]];r.data.set([u[0],u[1],u[2],255],f*4)}return r}function Dk(t,a=0,s={}){const i=t.width,r=t.height,f=s.scale??4,u=ll(8+3*i+8+3*f*i+8,8+Math.max(3*r,3*f*r)+8);Jo(u,0,0,u.width,u.height,Qh);const h=Ce(t,a),d=As(t,s.theme),p=(y,w,x)=>{for(let b=0;b<3;b++)for(let v=0;v<3;v++)for(let $=0;$<r;$++)for(let _=0;_<i;_++){const j=h[$*i+_],N=(v*i+_)*x,M=(b*r+$)*x;for(let A=0;A<x;A++)for(let z=0;z<x;z++){const E=j===ne?((N+z>>2)+(M+A>>2))%2?uc:Vh:d[j];tl(u,y+N+z,w+M+A,E)}}};return p(8,8,1),p(8+3*i+8,8,f),s.marks?.length&&Kh(u,8+3*i+8+f*i,8+f*r,f,s.marks,i,r),u}const Uk=[88,94,102];function Hk(t,a={}){const s=Math.max(1,a.scale??2),l=8,i=8,r=Math.max(1,...t.map(_=>_.doc.height)),f=i*2+t.reduce((_,j)=>_+j.doc.width,0)+l*Math.max(0,t.length-1),u=i*2+r,h=[],d=a.ground?Ce(a.ground,0):null,p=a.ground?As(a.ground,a.theme):[];for(let _=0;_<u;_++)for(let j=0;j<f;j++){const N=d?d[_%a.ground.height*a.ground.width+j%a.ground.width]:ne;h.push(N===ne?Uk:p[N])}let y=i;const w=[i,i+r-(t[0]?.doc.height??0)];for(const _ of t){const j=Ce(_.doc,_.frame??0),N=As(_.doc,a.theme),M=i+r-_.doc.height;for(let A=0;A<_.doc.height;A++)for(let z=0;z<_.doc.width;z++){const E=j[A*_.doc.width+z];E!==ne&&(h[(M+A)*f+y+z]=N[E])}y+=_.doc.width+l}const x=8,b=s===1,v=b?0:u+x,$=ll(x+Math.max(f,f*s)+x,x+v+u*s+x);Jo($,0,0,$.width,$.height,Qh);for(let _=0;_<u;_++)for(let j=0;j<f;j++){const N=h[_*f+j];b||tl($,x+j,x+_,N);for(let M=0;M<s;M++)for(let A=0;A<s;A++)tl($,x+j*s+A,x+v+_*s+M,N)}return a.marks?.length&&t[0]&&Kh($,x+w[0]*s,x+v+w[1]*s,s,a.marks,t[0].doc.width,t[0].doc.height),$}function Lk(t,a,s={}){const l=s.scale??Math.max(1,Math.min(4,Math.floor(96/Math.max(t.width,t.height)))),i=8,r=t.width*l,f=t.height*l,u=Math.max(4,Math.floor(r/Un.length)),h=Math.max(1,a.length),d=ll(i+h*(r+i),i+f+4+6+i);Jo(d,0,0,d.width,d.height,Qh);const p=Ce(t,s.frame??0),y=Math.max(2,l>>1);return a.forEach((w,x)=>{const b=i+x*(r+i),v=As(t,w);for(let $=0;$<t.height;$++)for(let _=0;_<t.width;_++){const j=p[$*t.width+_];for(let N=0;N<l;N++)for(let M=0;M<l;M++){const A=j===ne?(((_*l+M)/y|0)+(($*l+N)/y|0))%2?uc:Vh:v[j];tl(d,b+_*l+M,i+$*l+N,A)}}Un.forEach(($,_)=>Jo(d,b+_*u,i+f+4,u,6,vn(w.colours[$])))}),d}function Q0(t,a,s){const l=t.overlay?a.ground??null:t;if(!l)throw new Error("a map of an overlay needs a ground tile or family under it");const i=[...t.overlay?[t]:[],...a.overlays??[]],r=li(l.palette,a.theme).entries.map(d=>({name:d.name,hex:d.hex})),f=i.map(d=>U_(d,r));let u,h=null;if(l.family){const d=yt(l.family),p=a.cols??a.terrain?.cols??Go.cols,y=a.rows??a.terrain?.rows??Go.rows;h=a.terrain??nv(d,p,y,a.seed??Go.seed),u=fc(l,h,a.frame??H_(l,s))}else{const d=l.width;u=O_(l,a.cols??Math.max(4,Math.ceil(288/d)),a.rows??Math.max(3,Math.ceil(216/l.height)),a.frame??(l.frameCount>1?El(l,Pa(l)[0],s):0))}return D_(u,f,s,l.family?l:null),{base:l,img:u,colours:r.map(d=>vn(d.hex)),overlays:f,terrain:h}}function Bk(t,a){const{img:s}=t,l=ll(s.w*a,s.h*a);for(let i=0;i<s.h;i++)for(let r=0;r<s.w;r++){const f=s.px[i*s.w+r];Jo(l,r*a,i*a,a,a,f===ne?((r>>2)+(i>>2))%2?uc:Vh:t.colours[f])}return l}function V0(t,a={}){return Bk(Q0(t,a,a.tick??0),a.scale??2)}function Yk(t,a={}){const s=Q0(t,a,a.tick??0),{img:l,base:i}=s,r={...l,px:l.px.slice()};i.family&&!a.terrain&&lv(r,i,0);const f=Ih(r,i),u=d=>String(Number(d.toFixed(2))),h=[`${l.w/l.t}x${l.h/l.t} tiles of ${l.t} px${i.family&&!a.terrain?`, a random island (seed ${a.seed??Go.seed})`:""}; seam ${u(f.score)} (jump x ${u(f.jx)} y ${u(f.jy)}, line x ${u(f.lx)} y ${u(f.ly)}; about 1 or less reads as no seam)`];if(i.family){const d=yt(i.family),p=new Map;for(const w of l.variants)w!==null&&p.set(w,(p.get(w)??0)+1);const y=[...p.keys()].sort((w,x)=>w-x);h.push(`${y.length} of ${d.variants.length} variants on the map: ${y.map(w=>`${d.variants[w].name}×${p.get(w)}`).join(" ")}`)}return s.overlays.length&&h.push(`overlays: ${s.overlays.map(d=>`${d.name} (${d.overlay.mode} on ${d.overlay.on}, every ${d.overlay.every})`).join(", ")}`),h.join(`
|
|
14
|
+
`)}function Gk(t,a,s={}){const l=t.family,i=yt(l),r=l.tile,f=s.frame??0,u=As(t,s.theme),h=av(i,a),d=fc(t,h??{cols:3,rows:3,cells:new Uint8Array(i.neighbours==="corners"?16:9)},f);if(!h){const[y,w]=tn(l).cells[a],x=Ce(t,f);for(let b=0;b<r;b++)for(let v=0;v<r;v++)d.px[(r+b)*d.w+r+v]=x[(w*r+b)*t.width+y*r+v]}const p=ll(d.w,d.h);for(let y=0;y<d.h;y++)for(let w=0;w<d.w;w++){const x=d.px[y*d.w+w],b=w>=r&&w<2*r&&y>=r&&y<2*r,v=x===ne?uc:u[x];tl(p,w,y,b?v:[Math.round(v[0]*.55+20),Math.round(v[1]*.55+20),Math.round(v[2]*.55+22)])}return p}const sw=t=>{const[a,s,l]=vn(t);return 299*a+587*s+114*l};function ow(t,a){const s=new Map;for(const r of t)s.set(r,(s.get(r)??0)+1);let l=ne,i=-1;for(const[r,f]of s)if(!(f<i)){if(f===i){if(r===ne)continue;if(l!==ne){const u=sw(a.entries[r].hex),h=sw(a.entries[l].hex);if(u>h||u===h&&r>l)continue}}l=r,i=f}return l}const iw=new Map([["mode",(t,a,s)=>ow(t,s)],["nearest",(t,a)=>t[(a>>1)*a+(a>>1)]],["ink-vote",(t,a,s,l)=>{const i=l.ink??s.entries.filter(y=>/^(ink|outline|black)$/.test(y.name)).map(y=>y.name),r=new Set(i.map(y=>s.entries.findIndex(w=>w.name===y)).filter(y=>y>=0)),[f,u]=l.share??[1,4],h=new Map;for(const y of t)r.has(y)&&h.set(y,(h.get(y)??0)+1);let d=-1,p=0;for(const[y,w]of h)(w>p||w===p&&y<d)&&(d=y,p=w);return d>=0&&p*u>=f*t.length?d:ow(t,s)}]]);function Xk(t,a,s,l,i,r="mode",f={}){const u=iw.get(r);if(!u)throw new Error(`unknown reducer '${r}' (reducers: ${[...iw.keys()].join(", ")})`);const h=Math.floor(a/l),d=Math.floor(s/l),p=new Uint16Array(h*d),y=new Uint16Array(l*l);for(let w=0;w<d;w++)for(let x=0;x<h;x++){for(let b=0;b<l;b++)for(let v=0;v<l;v++)y[b*l+v]=t[(w*l+b)*a+x*l+v];p[w*h+x]=u(y,l,i,f)}return p}function rw(t,a,s,l){const i=new Uint16Array(a*l*s*l);for(let r=0;r<s*l;r++)for(let f=0;f<a*l;f++)i[r*a*l+f]=t[Math.floor(r/l)*a+Math.floor(f/l)];return i}function Zk(t,a,s){const l=a.entries.map(i=>{let r=s.entries.findIndex(f=>f.name===i.name);return r<0&&(r=s.entries.findIndex(f=>f.hex===i.hex)),r<0?ne:r});return t.map(i=>i===ne?i:l[i])}function K0(t,a,s,l="mode",i={},r=0){const f=Math.min(r,a.frameCount-1),u=Xk(Ce(a,f),a.width,a.height,s,a.palette,l,i),h=Zk(u,a.palette,t.palette),d=Ce(t,Math.min(r,t.frameCount-1)),p=[];let y=0;const w=Math.min(t.width,Math.floor(a.width/s)),x=Math.min(t.height,Math.floor(a.height/s));for(let b=0;b<x;b++)for(let v=0;v<w;v++){const $=d[b*t.width+v],_=h[b*w+v];($!==ne||_!==ne)&&y++,$!==_&&p.push([v,b])}return{pts:p,share:y?p.length/y:0,reduced:h}}const nh=[40,42,48];function Qk(t,a,s={}){const{reducer:l="ink-vote",frame:i=0,scale:r=2,...f}=s,u=[{d:1,doc:t},...a.filter($=>$.densityOf).map($=>({d:$.densityOf.d,doc:$}))].sort(($,_)=>$.d-_.d),h=u[u.length-1],d=u.map($=>({img:xh($.doc,Math.min(i,$.doc.frameCount-1)),s:h.d/$.d*r,label:`${$.d}x ${$.doc.name}`})),p=u.map($=>`${$.d}x ${$.doc.name} ${$.doc.width}x${$.doc.height}${$.d===1?" (base)":""}`);if(h.d>1){const $=K0(t,h.doc,h.d,l,f,i),_={...t,cels:[[$.reduced]],layers:[{name:"reduced",hidden:!1,locked:!1,reference:!1}]};d.push({img:xh(_,0),s:h.d*r,label:`${h.d}x reduced`,marks:$.pts}),p.push(`${h.d}x reduced by ${h.d} with ${l}: ${$.pts.length} pixels differ from ${t.name} (${($.share*100).toFixed(1)}%)${$.pts.length?` at ${$.pts.slice(0,12).map(([j,N])=>`${j},${N}`).join(" ")}${$.pts.length>12?" …":""}`:""}`)}else p.push("no higher-density copies (density of=<asset> d=<n> on a copy made with scale <n>)");const y=8,w=d.reduce(($,_)=>$+_.img.width*_.s+y,y),x=Math.max(...d.map($=>$.img.height*$.s))+2*y,b=ll(w,x);for(let $=0;$<w*x;$++)b.data.set([nh[0],nh[1],nh[2],255],$*4);let v=y;for(const $ of d){for(let _=0;_<$.img.height*$.s;_++)for(let j=0;j<$.img.width*$.s;j++){const N=(Math.floor(_/$.s)*$.img.width+Math.floor(j/$.s))*4;$.img.data[N+3]&&b.data.set($.img.data.subarray(N,N+4),((y+_)*w+v+j)*4)}$.marks?.length&&Kh(b,v,y,$.s,$.marks,$.img.width,$.img.height),v+=$.img.width*$.s+y}return{img:b,text:[...p,`panels: ${d.map($=>$.label).join(" | ")}`].join(`
|
|
15
|
+
`)}}const J0=["palette","orphans","jaggies","banding","outline","seam","coverage","readability","revert","repetition","lattice","anim","views","fit","variant","footprint","draworder","density","consistency","font","margin","pieces"];function Vk(t,a){if(!t.groups.some(i=>i.frame!==void 0))return t.flagged;const s=new Set,l=[];for(const i of t.groups)if(!(i.frame!==void 0&&i.frame!==a))for(const r of i.pts){const f=r[1]*65536+r[0];s.has(f)||(s.add(f),l.push(r))}return l}const ec={palette:{all:{max:0}},orphans:{all:{max:1,texture:!1},tile:{max:2,texture:!0},family:{max:2,texture:!0},overlay:{off:!0},font:{off:!0}},jaggies:{all:{max:0,area:1152},tile:{max:2},family:{max:2},font:{off:!0}},banding:{all:{max:.5,minEdges:8},font:{off:!0}},outline:{all:{min:.85},font:{off:!0}},seam:{all:{max:1}},coverage:{all:{max:0},font:{off:!0}},readability:{all:{min:.8,delta:15,maxIou:.9,minSpread:25},font:{off:!0}},revert:{all:{max:.15}},repetition:{all:{max:3,contrast:3},map:{edgeRun:4,motif:10},font:{off:!0}},anim:{all:{minDiff:.08,maxDiff:.35,maxPivot:1,maxGround:0,maxArea:.15},tile:{minDiff:.03},family:{minDiff:.01},overlay:{minDiff:0,maxDiff:1}},views:{all:{min:.2}},fit:{all:{max:0},font:{off:!0}},variant:{all:{maxL1:.3,maxDl:2}},footprint:{all:{max:0}},draworder:{all:{max:0}},lattice:{all:{max:.3,contrast:18}},density:{all:{max:.25}},consistency:{all:{max:0,maxL:18,maxOutline:.3,maxAngle:90,maxCluster:3,maxSteps:1.5,heightTol:2},family:{off:!0},overlay:{off:!0},font:{off:!0},icon:{maxStroke:1,maxFill:.2,maxCentre:1.5}},font:{all:{max:0,maxLine:0}},margin:{all:{max:0,bottom:!0},object:{off:!0},tile:{off:!0},family:{off:!0},map:{off:!0},font:{off:!0},overlay:{off:!0},sheet:{off:!0}},pieces:{all:{max:0,min:4},tile:{off:!0},family:{off:!0},map:{off:!0},font:{off:!0},overlay:{off:!0},icon:{off:!0},sheet:{off:!0}}};function Bo(t,a,s,l){const i=ec[t],r={...i.all,...i[a]??{}},f=h=>{if(h&&typeof h=="object")for(const[d,p]of Object.entries(h))(typeof p=="number"||typeof p=="boolean")&&(r[d]=p)},u=s?.checks?.[t];return u&&typeof u=="object"&&(f(u),f(u[a])),l&&f(s?.assets?.[l]?.checks?.[t]),r}function qs(t){const[a,s,l]=vn(t);return .299*a+.587*s+.114*l}function ql(t){const a=f=>{const u=f/255;return u<=.04045?u/12.92:((u+.055)/1.055)**2.4},[s,l,i]=vn(t),r=.2126*a(s)+.7152*a(l)+.0722*a(i);return r>216/24389?116*Math.cbrt(r)-16:24389/27*r}function Kk(t){const a=d=>{const p=d/255;return p<=.04045?p/12.92:((p+.055)/1.055)**2.4},[s,l,i]=vn(t).map(a),r=d=>d>216/24389?Math.cbrt(d):(24389/27*d+16)/116,f=r((.4124564*s+.3575761*l+.1804375*i)/.95047),u=r(.2126729*s+.7151522*l+.072175*i),h=r((.0193339*s+.119192*l+.9503041*i)/1.08883);return[116*u-16,500*(f-u),200*(u-h)]}function Jk(t,a){const s=Ce(t,a),{width:l,height:i,wrap:r}=t,f=(u,h)=>r?(h%i+i)%i*l+(u%l+l)%l:u<0||h<0||u>=l||h>=i?-1:h*l+u;return{doc:t,w:l,h:i,wrap:r,px:s,at:f,get:(u,h)=>{const d=f(u,h);return d<0?ne:s[d]}}}const en=[[1,0],[0,1],[-1,0],[0,-1]],Rl=[[1,0],[1,1],[0,1],[-1,1],[-1,0],[-1,-1],[0,-1],[1,-1]],Ut=(t,a)=>[a%t.w,Math.floor(a/t.w)],Ze=(t,a=2)=>String(Number(t.toFixed(a)));function tt(t,a){const s=(a.groups??[]).map(r=>{const f=new Set;return{label:r.label,pts:r.pts.filter(u=>{const h=u[1]*65536+u[0];return f.has(h)?!1:(f.add(h),!0)})}}),l=new Set,i=[];for(const r of s)for(const f of r.pts){const u=f[1]*65536+f[0];l.has(u)||(l.add(u),i.push(f))}return{id:t,score:null,shown:"—",limit:"",flagged:i,groups:s,...a}}const nt=(t,a)=>tt(t,{status:"skip",detail:a}),Tl=t=>t.wrap||t.kind==="family"||t.kind==="overlay";function Wk(t,a,s){const l=t.doc.palette,i=t.doc.kind==="icon"?h$(t.doc):null,r=Uh(l)||i==="tone",f=$=>vn($).every(_=>_===0||_===255),u=s.style?.palettes?.length?new Set(s.style.palettes.flatMap($=>$.entries.map(_=>_.hex))):null,h=new Map(Object.entries(s.style?.reserved??{}).filter(([,$])=>!$.includes(t.doc.name))),d=new Map,p=($,_)=>{d.has($)||d.set($,[]),d.get($).push(Ut(t,_))};let y=0;for(let $=0;$<t.px.length;$++){const _=t.px[$];if(_===ne)continue;y++;const j=l.entries[_];j?i==="channel"&&(j.role||!f(j.hex))?p(`${j.name} ${j.role??j.hex} is not a pure channel colour (channel icons use channels of 0 or 255)`,$):i==="full"&&j.role?p(`${j.name} is a role in a full-colour icon (drawn as is)`,$):r&&i!=="channel"&&i!=="full"&&!j.role?p(`${j.name} is a fixed colour in ${i==="tone"?"a tone icon (recoloured through roles)":"role art"}`,$):u&&!j.role&&!u.has(j.hex)?p(`${j.name} ${j.hex} is not in the style palettes`,$):h.has(j.name)&&p(`${j.name} is reserved for ${h.get(j.name).join(", ")} (style.reserved)`,$):p(`index ${_} is not a palette entry`,$)}const w=[...d].map(([$,_])=>({label:$,pts:_})),x=w.reduce(($,_)=>$+_.pts.length,0),b=Number(a.max),v=i==="channel"?"pure channel colours":r&&i!=="full"?"role entries":u?`the style palettes (${s.style.palettes.map($=>$.name).join(", ")})`:`palette '${l.name}'`;return tt("palette",{status:x<=b?"pass":"fail",score:x,shown:String(x),limit:`≤ ${b}`,groups:w,detail:x===0?`all ${y} px are ${/^(role entries|pure channel colours)$/.test(v)?v:`in ${v}`}`:`${x} px outside ${v}: ${w.map($=>`${$.label} (${$.pts.length})`).join("; ")}`})}function W0(t,a,s){let l=1/0;for(const i of Zh(t,a)){const r=i.ramp.indexOf(s);r>=0&&(l=Math.min(l,Math.abs(r-i.at)))}return l}function Ik(t,a,s){const l=t.px[a],i=new Set([a]),r=[a];for(;r.length&&i.size<s;){const f=r.pop(),[u,h]=Ut(t,f);for(const[d,p]of Rl){const y=t.at(u+d,h+p);y>=0&&!i.has(y)&&t.px[y]===l&&(i.add(y),r.push(y))}}return i.size}function Fk(t,a){const s=[],l=[];let i=0,r=0;for(let p=0;p<t.px.length;p++){const y=t.px[p];if(y===ne)continue;i++;const[w,x]=Ut(t,p);if(en.some(([v,$])=>t.get(w+v,x+$)===y))continue;const b=Ik(t,p,3);if(!(b>2)){if(a.texture){const v=new Map;for(const[_,j]of en){const N=t.get(w+_,x+j);N!==ne&&v.set(N,(v.get(N)??0)+1)}const $=[...v].sort((_,j)=>j[1]-_[1]||_[0]-j[0])[0]?.[0];if($!==void 0&&W0(t.doc.palette,y,$)===1){r++;continue}}(b===1?s:l).push([w,x])}}const f=s.length+l.length,u=i?100*f/i:0,h=Number(a.max),d=[...s.length?[{label:"lone pixel (no neighbour shares its colour)",pts:s}]:[],...l.length?[{label:"near-orphan (a diagonal pair)",pts:l}]:[]];return tt("orphans",{status:u<=h?"pass":"fail",score:u,shown:`${Ze(u,1)}%`,limit:`≤ ${h}%`,groups:d,detail:`${f} stray px in ${i} (${s.length} lone, ${l.length} near-orphans)${a.texture?`; ${r} one ramp step from their surroundings allowed as texture`:""}`})}function Pk(t){const a=new Map;for(const s of t)a.set(s,(a.get(s)??0)+1);return[...a].sort((s,l)=>l[1]-s[1]||s[0]-l[0])[0][0]}function cw(t,a,s){const l=t.get(a,s);return Rl.filter(([i,r])=>t.get(a+i,s+r)===l).map(([i,r])=>[a+i,s+r])}const Yo=(t,a)=>t[0]===a[0]&&t[1]===a[1];function uw(t,a,s,l){const i=[],r=(p,y)=>{let w=y[0]-p[0],x=y[1]-p[1];return l&&(w>1&&(w-=a),w<-1&&(w+=a),x>1&&(x-=s),x<-1&&(x+=s)),[w,x]},f=p=>{const y=p.map(w=>w.length);for(let w=2;w<=y.length-3;w++){const x=y[w-1],b=y[w],v=y[w+1];(b>x&&b>v||b<x&&b<v)&&Math.max(x,b,v)-Math.min(x,b,v)>=2&&i.push(p[w])}};let u=null,h=null,d=t.length?[[t[0]]]:[];for(let p=1;p<t.length;p++){const y=r(t[p-1],t[p]),w=y[0]===0!=(y[1]===0),x=(v,$)=>!v||!$||(v[0]!==0?v[0]===$[0]:v[1]===$[1]);let b;w?b=u?Yo(u,y):x(y,h):b=h?Yo(h,y):x(u,y),b||(f(d),d=[[t[p-1]]],u=null,h=null),w?(u=y,d[d.length-1].push(t[p])):(h=y,d.push([t[p]]))}return f(d),i}function e_(t){const a=new Uint8Array(t.px.length),s=[],l=(i,r)=>t.get(i,r)!==ne;for(let i=0;i<t.px.length;i++){if(t.px[i]===ne||a[i])continue;const r=[i];for(a[i]=1;r.length;){const w=r.pop(),[x,b]=Ut(t,w);for(const[v,$]of Rl){const _=t.at(x+v,b+$);_>=0&&!a[_]&&t.px[_]!==ne&&(a[_]=1,r.push(_))}}const f=Ut(t,i),u=[[-1,0],[-1,-1],[0,-1],[1,-1],[1,0],[1,1],[0,1],[-1,1]],h=(w,x)=>u.findIndex(([b,v])=>b===w&&v===x),d=[f];let p=f,y=0;for(let w=0;w<4*t.px.length+8;w++){let x=1;for(;x<=8&&!l(p[0]+u[(y+x)%8][0],p[1]+u[(y+x)%8][1]);)x++;if(x>8)break;const b=u[(y+x)%8],v=u[(y+x-1)%8],$=[p[0]+b[0],p[1]+b[1]];if(Yo(p,f)&&d.length>1&&Yo($,d[1]))break;y=h(v[0]-b[0],v[1]-b[1]),p=$,d.push(p)}d.length>1&&Yo(d[d.length-1],f)&&d.pop(),s.push(d)}return s}function t_(t,a){const s=new Int8Array(t.px.length).fill(-1);for(let r=0;r<t.px.length;r++){if(t.px[r]===ne)continue;const[f,u]=Ut(t,r);s[r]=cw(t,f,u).length}const l=new Uint8Array(t.px.length),i=[];for(let r=0;r<t.px.length;r++){if(s[r]!==1||l[r])continue;const f=[];let u=r;for(;;){l[u]=1;const h=Ut(t,u);f.push(h);const d=cw(t,h[0],h[1]).map(([p,y])=>t.at(p,y)).filter(p=>!l[p]);if(d.length!==1||s[d[0]]!==1&&s[d[0]]!==2)break;u=d[0]}f.length>=a&&i.push(f)}return i}function bh(t,a,s,l){return a!==ne&&s!==ne&&!l.has(a)&&!l.has(s)&&W0(t.doc.palette,a,s)===1}function n_(t,a,s,l){const i=t.get(a,s);let r=!1;for(const[f,u]of Rl){const h=t.get(a+f,s+u);if(!(h===i||l.has(h)&&!l.has(i))){if(!bh(t,i,h,l))return!1;r=!0}}return r}function a_(t,a,s={}){if(t.doc.family)return nt("jaggies","a family is judged on its map (its textures are checked as tiles)");const l=Jh(t,s.style);let i=0;const r=Tl(t.doc)?Pk(t.px):-1,f=[];for(let A=0;A<t.px.length;A++){const z=t.px[A];if(z===ne||z===r)continue;const[E,R]=Ut(t,A),B=en.filter(([Y,O])=>t.get(E+Y,R+O)===z);if(B.length!==2)continue;const K=B.find(([,Y])=>Y===0),J=B.find(([Y])=>Y===0);if(!K||!J||t.get(E+K[0]+J[0],R+J[1])===z)continue;const T=t.get(E+J[0]-K[0],R+J[1])===z||t.get(E+K[0],R-J[1])===z,D=t.get(E+K[0],R+J[1]),L=!l.has(z)&&en.every(([Y,O])=>t.get(E+Y,R+O)!==ne);T&&L&&(bh(t,z,D,l)||l.has(D)&&Rl.some(([Y,O])=>bh(t,z,t.get(E+Y,R+O),l)))?i++:T&&f.push([E,R])}let u=0;{const A=E=>t.at(E[0],E[1]),z=new Set(f.map(A));for(const E of f){if(!z.has(A(E)))continue;u++;const R=[E];for(z.delete(A(E));R.length;){const[B,K]=R.pop();for(const[J,T]of en){const D=t.at(B+J,K+T);z.has(D)&&(z.delete(D),R.push(Ut(t,D)))}}}}const h=new Map,d=A=>{for(const z of A)h.set(z.map(E=>t.at(E[0],E[1])).sort((E,R)=>E-R).join(","),z)};for(const A of t_(t,6))if(t.get(A[0][0],A[0][1])!==r){if(A.every(([z,E])=>n_(t,z,E,l))){i++;continue}d(uw(A,t.w,t.h,t.wrap))}if(!Tl(t.doc))for(const A of e_(t))d(uw(A,t.w,t.h,!1));const p=[...h.values()].flat(),y=[],w=[];if(!Tl(t.doc)){const A=(z,E)=>t.get(z,E)!==ne;for(let z=0;z<t.h;z++)for(let E=0;E<t.w;E++){const R=en.filter(([B,K])=>A(E+B,z+K));if(A(E,z)){if(R.length!==1)continue;const[B,K]=[E+R[0][0],z+R[0][1]],J=en.filter(([D,L])=>A(B+D,K+L)).length,T=Rl.filter(([D,L])=>A(E+D,z+L)).length;J>=3&&T<=3&&y.push([E,z])}else if(R.length===4)w.push([E,z]);else if(R.length===3){const B=en.find(([K,J])=>!A(E+K,z+J));A(E-2*B[0],z-2*B[1])&&w.push([E,z])}}}const x=[...f.length?[{label:"doubled L-corner",pts:f}]:[],...p.length?[{label:"irregular step run",pts:p}]:[],...y.length?[{label:"spike on the outline",pts:y}]:[],...w.length?[{label:"notch in the outline",pts:w}]:[]],b=h.size,v=u+b+y.length+w.length,$=t.doc,_=Number(a.max)>0&&($.wrap||$.family)?Math.max(1,Math.floor($.cellW*$.cellH/576)):1,j=$.kind==="object"?$.width*$.height:$.cellW*$.cellH,N=!$.wrap&&!$.family&&Number(a.area)>0?Math.floor(j/Number(a.area)):0,M=Number(a.max)*_+N;return tt("jaggies",{status:v<=M?"pass":"fail",score:v,shown:String(v),limit:`≤ ${M}`,groups:x,detail:(v===0?"lines and outlines step evenly":`${u} doubled L-corners, ${b} irregular step runs, ${y.length} spikes, ${w.length} notches`)+(i?`; ${i} steps between neighbouring entries of one ramp are shading, not counted`:"")})}function l_(t){const a=new Int32Array(t.px.length).fill(0),s=[];for(let l=0;l<t.px.length;l++){if(t.px[l]===ne)continue;const[i,r]=Ut(t,l);en.some(([f,u])=>t.get(i+f,r+u)===ne)&&(a[l]=1,s.push(l))}for(let l=0;l<s.length;l++){const i=s[l],[r,f]=Ut(t,i);for(const[u,h]of en){const d=t.at(r+u,f+h);d>=0&&t.px[d]!==ne&&a[d]===0&&(a[d]=a[i]+1,s.push(d))}}return a}function Jh(t,a){const s=t.doc.palette,l=a?.outline?.length?a.outline:["ink","outline","black"],i=new Set(s.entries.flatMap((f,u)=>l.includes(f.name)||f.role==="black"?[u]:[]));if(i.size||a?.outline?.length)return i;let r=-1;for(const f of new Set(t.px))f!==ne&&(r<0||qs(s.entries[f].hex)<qs(s.entries[r].hex))&&(r=f);return new Set(r>=0?[r]:[])}function s_(t,a,s){const l=Object.keys(t.ramps),i=t.entries[a]?.name,r=t.entries[s]?.name;return l.findIndex(f=>t.ramps[f].includes(i)&&t.ramps[f].includes(r))}function o_(t,a,s){if(Tl(t.doc))return nt("banding","tiles have no silhouette to band along");const l=t.doc.palette,i=l_(t),r=Jh(t,s.style),f=l.entries.map(j=>qs(j.hex)),u=Object.keys(l.ramps).length>0,h=Object.keys(l.ramps),d=new Map;for(let j=0;j<t.px.length;j++){const N=t.px[j];if(N===ne||r.has(N))continue;const[M,A]=Ut(t,j);en.forEach(([z,E],R)=>{const B=t.at(M+z,A+E);if(B<0)return;const K=t.px[B];if(K===ne||K===N||r.has(K)||i[B]!==i[j]+1)return;const J=u?s_(l,N,K):0;if(J<0)return;const T=Math.sign(f[K]-f[N]);if(!T)return;d.has(J)||d.set(J,{count:en.map(()=>[0,0]),edges:[]});const D=d.get(J);D.count[R][T>0?0:1]++,D.edges.push({p:[M,A],sign:T})})}const p=Number(a.minEdges),y=Number(a.max),w=["west","top","east","bottom"];let x={score:0,ramp:-1,sign:0,net:[0,0,0,0],n:0},b=0;for(const[j,N]of d){if(b+=N.edges.length,N.edges.length<p)continue;const M=N.count.map(([E,R])=>E+R>=2?(E-R)/(E+R):0),A=Math.sign(M[0]),z=A!==0&&M.every(E=>Math.sign(E)===A)?Math.min(...M.map(Math.abs)):0;(z>x.score||x.ramp<0)&&(x={score:z,ramp:j,sign:A,net:M,n:N.edges.length})}const v=u&&x.ramp>=0?`ramp ${h[x.ramp]}`:"the colours";if(x.ramp<0)return tt("banding",{status:"pass",score:0,shown:"0",limit:`≤ ${y}`,detail:`${b} ramp steps follow the outline; too few to band`});const $=x.score>y,_=$?d.get(x.ramp).edges.filter(j=>j.sign===x.sign).map(j=>j.p):[];return tt("banding",{status:$?"fail":"pass",score:x.score,shown:Ze(x.score),limit:`≤ ${y}`,groups:$?[{label:`pillow shading in ${v}: it gets ${x.sign>0?"lighter":"darker"} inward on every side`,pts:_}]:[],detail:`${v}: ${x.n} ramp steps along the outline; inward ${x.net.map((j,N)=>`${w[N]} ${j>0?"+":""}${Ze(j)}`).join(", ")}`+($?" (the same on every side: light one side and shade the other)":"")})}function I0(t){const a=[];for(let s=0;s<t.px.length;s++){if(t.px[s]===ne)continue;const[l,i]=Ut(t,s);en.some(([r,f])=>t.get(l+r,i+f)===ne)&&a.push(s)}return a}function i_(t,a,s){if(Tl(t.doc))return nt("outline","tiles have no silhouette");const l=I0(t);if(!l.length)return nt("outline","nothing drawn");const i=Jh(t,s.style),r=l.filter(d=>!i.has(t.px[d])),f=1-r.length/l.length,u=Number(a.min),h=[...i].filter(d=>t.px.includes(d)||i.size===1).map(d=>t.doc.palette.entries[d].name).join(", ")||"none";return tt("outline",{status:f>=u?"pass":"fail",score:f,shown:Ze(f),limit:`≥ ${u}`,groups:r.length?[{label:`silhouette edge not in the outline colour (${h})`,pts:r.map(d=>Ut(t,d))}]:[],detail:`${l.length-r.length} of ${l.length} silhouette edge px are ${h}${r.length?`; ${r.length} gaps`:""}`})}const Es=t=>t.length?t.reduce((a,s)=>a+s,0)/t.length:0,fw=t=>{const a=Es(t);return Math.sqrt(Es(t.map(s=>(s-a)*(s-a))))};function tc(t,a,s,l,i){const r=[];for(let v=0;v<=s-2;v++){let $=0;for(let _=0;_<l;_++)t[_*s+v]!==t[_*s+v+1]&&$++;r.push($/l)}const f=r.map((v,$)=>($+1)%i===0),u=r.filter((v,$)=>f[$]),h=r.filter((v,$)=>!f[$]),d=(Es(u)-Es(h))/(fw(h)+.02),p=[];for(let v=0;v<s;v++){let $=0;for(let _=0;_<l;_++)$+=a[_*s+v];p.push($/l)}const y=p.map((v,$)=>(($+1)%i===0||$%i===0)&&$!==0&&$!==s-1),w=p.filter((v,$)=>y[$]),x=p.filter((v,$)=>!y[$]),b=Math.abs(Es(w)-Es(x))/(fw(x)+2);return{jump:d,line:b}}function r_(t,a=0){const s=Ce(t,a),{width:l,height:i}=t,r=t.palette.entries.map(b=>qs(b.hex)),f=3*l,u=3*i,h=new Int32Array(f*u),d=new Float64Array(f*u),p=new Int32Array(f*u),y=new Float64Array(f*u);for(let b=0;b<u;b++)for(let v=0;v<f;v++){const $=s[b%i*l+v%l],_=$===ne?-1:$,j=$===ne?0:r[$];h[b*f+v]=_,d[b*f+v]=j,p[v*u+b]=_,y[v*u+b]=j}const w=tc(h,d,f,u,l),x=tc(p,y,u,f,i);return{score:Math.max(w.jump,x.jump,w.line,x.line,0),jx:w.jump,jy:x.jump,lx:w.line,ly:x.line}}function c_(t,a,s){if(t.doc.family){const h=t.doc,{cols:d,rows:p,seed:y}=Go,w=fc(h,nv(yt(h.family),d,p,y),s.frame??0),x=lv(w,h,s.frame??0),b=Ih(w,h),v=Number(a.max);return tt("seam",{status:b.score<=v?"pass":"fail",score:b.score,shown:Ze(b.score),limit:`≤ ${v}`,detail:`over a ${d}x${p} island (seed ${y}${x?`; its ${x} face cells as the outside under them`:""}): jump x ${Ze(b.jx)} y ${Ze(b.jy)}; line x ${Ze(b.lx)} y ${Ze(b.ly)} (view map shows it)`})}if(!t.wrap)return nt("seam","not a wrap (tile) document");const l=r_(t.doc,s.frame??0),i=Number(a.max),r=[],{w:f,h:u}=t;if(l.jx>i||l.lx>i){const h=[];for(let d=0;d<u;d++)(l.lx>i||t.get(f-1,d)!==t.get(0,d))&&h.push([0,d],[f-1,d]);r.push({label:l.lx>i?"left and right edge columns stand out (a line at the seam)":"the colour changes across the left-right seam",pts:h})}if(l.jy>i||l.ly>i){const h=[];for(let d=0;d<f;d++)(l.ly>i||t.get(d,u-1)!==t.get(d,0))&&h.push([d,0],[d,u-1]);r.push({label:l.ly>i?"top and bottom edge rows stand out (a line at the seam)":"the colour changes across the top-bottom seam",pts:h})}return tt("seam",{status:l.score<=i?"pass":"fail",score:l.score,shown:Ze(l.score),limit:`≤ ${i}`,groups:r,detail:`jump x ${Ze(l.jx)} y ${Ze(l.jy)}; line x ${Ze(l.lx)} y ${Ze(l.ly)} (about 1 or less reads as no seam)`})}function u_(t,a){const s=t.family,l=yt(s),i=tn(s),r=s.tile,f=[],u=[],h=[["inside",i.inside],["outside",i.outside],...l.variants.map((w,x)=>[w.name,i.cells[x]])],d=(w,x,b)=>{for(let v=0;v<r;v++)for(let $=0;$<r;$++)if(w[(b*r+v)*t.width+x*r+$]!==ne)return!1;return!0},p=Array.from({length:t.frameCount},(w,x)=>x).every(w=>d(Ce(t,w),i.outside[0],i.outside[1])&&!d(Ce(t,w),i.inside[0],i.inside[1]));for(let w=0;w<t.frameCount;w++){const x=Ce(t,w);for(const[b,[v,$]]of h){if(p&&(b==="outside"||l.variants[l.byName.get(b)??-1]?.on)||!d(x,v,$))continue;f.push(`${b}${t.frameCount>1?` (frame ${w+1})`:""} is empty`);const _=[];for(let j=0;j<r;j++)_.push([v*r+j,$*r],[v*r+j,$*r+r-1]);u.push({label:`${b} is empty`,pts:_,...t.frameCount>1?{frame:w}:{}})}}const y=Number(a.max);return tt("coverage",{status:f.length<=y?"pass":"fail",score:f.length,shown:String(f.length),limit:`≤ ${y}`,groups:u,detail:f.length?f.join("; "):`${l.name}: all ${l.variants.length} variants and ${p?"the inside texture drawn (the outside left empty: the ground below shows)":"both textures drawn"}${t.frameCount>1?` on ${t.frameCount} frames`:""}${s.detached.length?` (${s.detached.length} detached)`:""}`})}function f_(t,a,s){const l=t.doc;if(l.family)return u_(l,a);const i=[],r=[],f=l.densityOf?.d??1,u=s.style?.sizes?.[l.kind]?.split("|").map(d=>d.trim()).map(d=>f===1?d:d.replace(/^(\d+)x(\d+)$/,(p,y,w)=>`${Number(y)*f}x${Number(w)*f}`)).join("|");u&&!u.split("|").includes(`${l.width}x${l.height}`)&&i.push(`size ${l.width}x${l.height} is not the style's ${u} for a ${l.kind}${f>1?` at ${f}x`:""}`),(l.width%l.cellW||l.height%l.cellH)&&i.push(`size ${l.width}x${l.height} is not a whole number of ${l.cellW}x${l.cellH} cells`);for(let d=0;d<l.frameCount;d++){const p=Ce(l,d);if(p.every(y=>y===ne)){i.push(`frame ${d+1} is empty`);continue}if(!(l.cellW>=l.width&&l.cellH>=l.height))for(let y=0;y+l.cellH<=l.height;y+=l.cellH)for(let w=0;w+l.cellW<=l.width;w+=l.cellW){let x=!0;for(let v=y;v<y+l.cellH&&x;v++)for(let $=w;$<w+l.cellW;$++)if(p[v*l.width+$]!==ne){x=!1;break}if(!x)continue;i.push(`cell (${w/l.cellW},${y/l.cellH})${l.frameCount>1?` of frame ${d+1}`:""} is empty`);const b=[];for(let v=0;v<l.cellW;v++)b.push([w+v,y],[w+v,y+l.cellH-1]);for(let v=1;v<l.cellH-1;v++)b.push([w,y+v],[w+l.cellW-1,y+v]);r.push({label:`empty cell (${w/l.cellW},${y/l.cellH})`,pts:b})}}const h=Number(a.max);return tt("coverage",{status:i.length<=h?"pass":"fail",score:i.length,shown:String(i.length),limit:`≤ ${h}`,groups:r,detail:i.length?i.join("; "):`${l.frameCount} frame${l.frameCount>1?"s":""}, every cell drawn${u?`, size ${u}`:""} (autotile names come with schemes)`})}function h_(t,a,s){if(Tl(t.doc))return nt("readability","tiles are ground, not figures");const i=t.doc.palette.entries.map(j=>ql(j.hex)),r=[];for(let j=0;j<t.px.length;j++)t.px[j]!==ne&&r.push(j);if(!r.length)return nt("readability","nothing drawn");const f=[],u=[];let h=null;const d=Number(a.delta),p=s.ground;if(p){const j=Ce(p,0),N=p.palette.entries.map(R=>ql(R.hex)),M=(R,B)=>{const K=j[(B%p.height+p.height)%p.height*p.width+(R%p.width+p.width)%p.width];return K===ne?null:N[K]},A=[];let z=0;for(const R of I0(t)){const[B,K]=Ut(t,R);let J=-1;for(const[T,D]of en){if(t.get(B+T,K+D)!==ne)continue;const L=M(B+T,K+D);L!==null&&(J=Math.max(J,Math.abs(i[t.px[R]]-L)))}J<0||(z++,J<d&&A.push([B,K]))}h=z?1-A.length/z:1;const E=Number(a.min);f.push({name:"edge contrast",value:h,limit:`≥ ${E}`,pass:h>=E,detail:`${z-A.length} of ${z} edge px differ from '${p.name}' by ΔL* ≥ ${d}`}),A.length&&u.push({label:`edge too close to the ground '${p.name}' (ΔL* < ${d})`,pts:A})}else f.push({name:"edge contrast",value:null,limit:"",pass:null,detail:"no ground tile to judge against"});const y=(s.set??[]).filter(j=>!j.doc.wrap&&j.doc.width===t.w&&j.doc.height===t.h&&j.doc.name!==t.doc.name),w=y.filter(j=>!Jr(j.doc,t.doc)&&!Jr(t.doc,j.doc));if(w.length){const j=t.px.map(A=>A===ne?0:1);let N={name:"",iou:0};for(const A of w){const z=Ce(A.doc,Math.min(s.frame??0,A.doc.frameCount-1));let E=0,R=0;for(let K=0;K<z.length;K++){const J=j[K],T=z[K]!==ne?1:0;J&&T&&E++,(J||T)&&R++}const B=R?E/R:0;(B>N.iou||!N.name)&&(N={name:A.name,iou:B})}const M=Number(a.maxIou);f.push({name:"distinct silhouette",value:N.iou,limit:`≤ ${M}`,pass:N.iou<=M,detail:`most like '${N.name}' (IoU ${Ze(N.iou)})${w.length<y.length?`; recolours not compared: ${y.filter(A=>!w.includes(A)).map(A=>A.name).join(", ")}`:""}`})}else y.length&&f.push({name:"distinct silhouette",value:null,limit:"",pass:null,detail:`only recolours to compare with (${y.map(j=>j.name).join(", ")})`});const x=r.map(j=>i[t.px[j]]).sort((j,N)=>j-N),b=j=>x[Math.min(x.length-1,Math.floor(j*x.length))],v=b(.95)-b(.05),$=Number(a.minSpread);f.push({name:"lightness spread",value:v,limit:`≥ ${$}`,pass:v>=$,detail:`L* ${Ze(b(.05),0)}..${Ze(b(.95),0)} inside the sprite`});const _=f.some(j=>j.pass===!1);return tt("readability",{status:_?"fail":"pass",score:h,shown:h===null?_?"✗":"✓":Ze(h),limit:f[0].limit||"",groups:u,parts:f,detail:f.map(j=>`${j.name}: ${j.detail}`).join("; ")})}function d_(t,a,s){const l=s.ref;if(!l)return nt("revert","no reference asset (give ref=<asset>)");const i=Ce(l,Math.min(s.frame??0,l.frameCount-1)),r=[];let f=0;for(let d=0;d<t.h;d++)for(let p=0;p<t.w;p++){const y=t.px[d*t.w+p],w=p<l.width&&d<l.height?i[d*l.width+p]:ne;y===ne&&w===ne||(f++,y!==ne&&w!==ne&&t.doc.palette.entries[y].hex===l.palette.entries[w].hex&&r.push([p,d]))}const u=f?r.length/f:0,h=Number(a.max);return tt("revert",{status:u<=h?"pass":"fail",score:u,shown:`${Ze(100*u,0)}%`,limit:`≤ ${Ze(100*h,0)}%`,groups:u>h?[{label:`same colour as '${l.name}'`,pts:r}]:[],detail:`${r.length} of ${f} px are unchanged from '${l.name}'`})}function m_(t,a=0,s=ec.repetition.all.contrast,l=ec.repetition.all.max){const i=Ce(t,a),{width:r,height:f}=t,u=t.palette.entries.map(w=>ql(w.hex)),h=Float64Array.from(i,w=>w===ne?0:u[w]),d=h.reduce((w,x)=>w+x,0)/h.length;let p={score:0,axis:"rows",from:0,width:1,delta:0,spread:0,limit:l},y=-1;for(const w of["rows","columns"]){const x=w==="rows"?f:r,b=w==="rows"?r:f,v=(_,j)=>w==="rows"?h[_*r+j]:h[j*r+_],$=Math.max(1,Math.floor(x/24));for(let _=1;_<=Math.min(6*Math.max(1,Math.floor(x/24)),Math.floor(x/4))||_===1;_++){const j=new Float64Array(b);for(let N=0;N<x;N++){j.fill(0);for(let J=0;J<_;J++){const T=(N+J)%x;for(let D=0;D<b;D++)j[D]+=v(T,D)}let M=0;for(let J=0;J<b;J++)M+=j[J]/=_;M/=b;let A=0;for(let J=0;J<b;J++)A+=(j[J]-M)**2;const z=Math.sqrt(A/b),E=M-d,R=Math.abs(E)*Math.sqrt(_/$),B=Math.max(l,s*z*Math.sqrt(_/$/b)),K=R/B;K>y+1e-9&&(y=K,p={score:R,axis:w,from:N,width:_,delta:E,spread:z,limit:B})}if(x<4)break}}return p}function p_(t,a,s){if(!t.wrap)return nt("repetition","not a wrap (tile) document");const l=Number(a.max),i=m_(t.doc,s.frame??0,Number(a.contrast??0),l),r=i.score>i.limit,f=i.axis==="rows"?t.h:t.w,u=i.axis==="rows"?t.w:t.h,h=[];for(let M=0;M<i.width;M++)for(let A=0;A<u;A++){const z=(i.from+M)%f;h.push(i.axis==="rows"?[A,z]:[z,A])}const d=new Map;for(const M of t.px)d.set(M,(d.get(M)??0)+1);const p=[...d].sort((M,A)=>A[1]-M[1]||M[0]-A[0])[0][0],y=M=>M===ne?0:ql(t.doc.palette.entries[M].hex),w=h.filter(([M,A])=>{const z=t.get(M,A);return z!==p&&Math.sign(y(z)-y(p))===Math.sign(i.delta)}),x=w.length?w:h,b=(i.from+i.width-1)%f,v=i.width===1?`${i.axis==="rows"?"row":"column"} ${i.from}`:`${i.axis} ${i.from}-${b}`,$=i.delta<0?"darker":"lighter",_=i.limit>l+1e-9,j=_?`≤ ${Ze(i.limit,1)}`:`≤ ${l}`,N=_?`; limit raised from ${l} by its spread along the band (σ ${Ze(i.spread,1)}): an uneven band is a mark, not a stripe`:"";return tt("repetition",{status:r?"fail":"pass",score:i.score,shown:Ze(i.score,1),limit:j,groups:r?[{label:`${v}: ${$} than the rest (ΔL* ${Ze(Math.abs(i.delta),1)}), a stripe when tiled`,pts:x}]:[],detail:`most visible stripe: ${v}, ${$} by ΔL* ${Ze(Math.abs(i.delta),1)} (score ΔL*·√width ${Ze(i.score,1)}${N})`})}const bt=t=>`${Ze(t*100,1)}%`;function y_(t,a){const s=t.doc;if(s.frameCount<2)return nt("anim","one frame");const l=Pa(s).filter(D=>!D.mirror&&D.frames.length>=2);if(!l.length)return nt("anim","no sequence of two frames or more (mirror views follow their source)");const i=Tl(s),r=[],f=D=>r[D]??=Ce(s,D),u=D=>f(D).reduce((L,Y)=>L+(Y!==ne?1:0),0),h=(D,L)=>{const Y=[];for(let O=0;O<s.width*s.height;O++)L(O)&&Y.push(Ut(t,O));return Y},[d,p,y,w,x]=[a.minDiff,a.maxDiff,a.maxPivot,a.maxGround,a.maxArea].map(Number),b=[],v=[];let $=0,_="",j=0,N="",M=0,A="";for(const D of l){const L=D.frames,Y=L.slice(1).map((se,ue)=>({a:L[ue],b:se,seam:!1}));D.loop==="cycle"&&L.length>=3&&Y.push({a:L.at(-1),b:L[0],seam:!0});for(const{a:se,b:ue,seam:te}of Y){const U=f(se),V=f(ue);let P=0,ie=0;for(let F=0;F<U.length;F++)(U[F]!==ne||V[F]!==ne)&&ie++,U[F]!==V[F]&&P++;const ye=ie?P/ie:0;if(v.push({s:D.name,a:se,b:ue,v:ye,seam:te}),ye<d||ye>p){const F=ye<d?P?"too little changes (it barely moves)":"the frames are the same (a held frame: give it more ticks instead)":"too much changes (it jumps)";b.push({label:`${D.name} ${te?"loop seam ":""}${se+1}→${ue+1}: ${bt(ye)} of the pixels change; ${F}`,pts:h(ue,pe=>U[pe]!==V[pe]),frame:ue})}if(!i){const F=u(se),pe=u(ue),fe=Math.max(F,pe)?Math.abs(F-pe)/Math.max(F,pe):0;fe>M&&(M=fe,A=`${D.name} ${se+1}→${ue+1}`),fe>x&&b.push({label:`${D.name} ${se+1}→${ue+1}: the silhouette ${pe>F?"grows":"shrinks"} by ${bt(fe)}`,pts:h(ue,ge=>U[ge]===ne!=(V[ge]===ne)),frame:ue})}}if(i)continue;const O=L.map(se=>{let ue=0,te=0;return f(se).forEach((U,V)=>{U!==ne&&(ue+=V%s.width,te++)}),te?ue/te:0}),H=L.map(se=>{const ue=f(se);for(let te=s.height-1;te>=0;te--)for(let U=0;U<s.width;U++)if(ue[te*s.width+U]!==ne)return te;return-1}),G=O.reduce((se,ue)=>se+ue,0)/O.length,Z=Math.max(...O)-Math.min(...O);if(Z>$&&($=Z,_=D.name),Z>y){const se=O.reduce((U,V,P)=>Math.abs(V-G)>Math.abs(O[U]-G)?P:U,0),ue=f(L[se]),te=f(L[se===0?1:0]);b.push({label:`${D.name} frame ${L[se]+1}: the sprite sits ${Ze(O[se]-G,1)} px off the sequence's centre (it slides; drift ${Ze(Z,1)} px)`,pts:h(L[se],U=>ue[U]!==ne&&te[U]===ne),frame:L[se]})}const W=s.ground??H[0];L.forEach((se,ue)=>{const te=Math.abs(H[ue]-W);if(!(H[ue]<0)&&(te>j&&(j=te,N=`${D.name} frame ${se+1}`),te>w)){const U=f(se);b.push({label:`${D.name} frame ${se+1}: the lowest row is ${H[ue]}, the ground is ${W} (${H[ue]<W?"it floats":"it sinks"})`,pts:h(se,V=>Math.floor(V/s.width)===H[ue]&&U[V]!==ne),frame:se})}})}const z=v.filter(D=>!D.seam),E=Math.min(...z.map(D=>D.v)),R=Math.max(...z.map(D=>D.v)),B=v.filter(D=>D.seam),K=[{name:"frame diff",value:R,limit:`${bt(d)}–${bt(p)}`,pass:E>=d&&R<=p,detail:`pairs change ${bt(E)}..${bt(R)} of their pixels`}];if(B.length){const D=B.filter(Y=>Y.v<d||Y.v>p),L=D[0]??B[0];K.push({name:"loop seam",value:L.v,limit:`${bt(d)}–${bt(p)}`,pass:!D.length,detail:`${L.s} ${L.a+1}→${L.b+1} changes ${bt(L.v)}`})}i||(K.push({name:"pivot drift",value:$,limit:`≤ ${y} px`,pass:$<=y,detail:`${Ze($,1)} px${_?` (${_})`:""}`}),K.push({name:"ground drift",value:j,limit:`≤ ${w} px`,pass:j<=w,detail:`${j} px${N?` (${N})`:""} from ${s.ground!==null?`the ground line ${s.ground}`:"the first frame's lowest row"}`}),K.push({name:"area jump",value:M,limit:`≤ ${bt(x)}`,pass:M<=x,detail:`${bt(M)}${A?` (${A})`:""}`}));const J=v.reduce((D,L)=>Math.max(d-L.v,L.v-p)>Math.max(d-D.v,D.v-p)?L:D,v[0]),T=K.some(D=>!D.pass);return tt("anim",{status:T?"fail":"pass",score:J.v,shown:bt(J.v),limit:`${bt(d)}–${bt(p)}`,groups:b,parts:K,detail:`${l.map(D=>D.name).join(", ")}: `+K.map(D=>`${D.name} ${D.detail}${D.pass?"":` (limit ${D.limit})`}`).join("; ")})}function g_(t,a){const s=t.doc,l=s.views.filter(u=>!u.mirror);if(l.length<2)return nt("views","fewer than two views (a mirror view counts as its source)");const i=Number(a.min),r=[];for(let u=0;u<l.length;u++)for(let h=u+1;h<l.length;h++){const d=l[u],p=l[h];if(Cl(d.name)===p.name)continue;const y=Ce(s,d.from),w=Ce(s,p.from);let x=0,b=0;for(let v=0;v<y.length;v++)(y[v]!==ne||w[v]!==ne)&&b++,y[v]!==w[v]&&x++;r.push({a:d.name,b:p.name,v:b?x/b:0})}if(!r.length)return nt("views","only views facing each other (they are meant to be mirror images)");const f=r.reduce((u,h)=>h.v<u.v?h:u);return tt("views",{status:f.v>=i?"pass":"fail",score:f.v,shown:bt(f.v),limit:`≥ ${bt(i)}`,detail:r.map(u=>`${u.a}/${u.b} differ by ${bt(u.v)}`).join(", ")+(f.v<i?`; ${f.a} and ${f.b} look too alike`:"")})}function w_(t,a){const s=t.doc,[l,i]=oi(s);if(s.family||s.overlay||s.kind==="sheet")return nt("fit",`a ${s.kind} is not placed as one piece`);if(!s.footprint&&l*i===1)return nt("fit","one cell, no footprint");if(s.width%s.cellW||s.height%s.cellH)return nt("fit",`the canvas is not whole ${s.cellW}x${s.cellH} cells`);const r=s.footprint??{cols:l,rows:i,at:[0,0],flags:[]},f=[],u=(p,y)=>{const w=[];for(let x=0;x<s.cellW;x++)w.push([p*s.cellW+x,y*s.cellH],[p*s.cellW+x,y*s.cellH+s.cellH-1]);for(let x=1;x<s.cellH-1;x++)w.push([p*s.cellW,y*s.cellH+x],[p*s.cellW+s.cellW-1,y*s.cellH+x]);return w};for(let p=0;p<i;p++)for(let y=0;y<l;y++){const w=[];for(let x=0;x<s.cellH;x++)for(let b=0;b<s.cellW;b++)t.px[(p*s.cellH+x)*s.width+y*s.cellW+b]!==ne&&w.push([y*s.cellW+b,p*s.cellH+x]);wh(r,y,p)&&!w.length&&f.push({label:`footprint cell ${y},${p} is empty`,pts:u(y,p)}),!wh(r,y,p)&&w.length&&!Yh(r,y,p).roof&&f.push({label:`cell ${y},${p} overhangs the footprint but is not a roof (r): actors behind would be drawn over it`,pts:w})}const h=f.length,d=Number(a.max);return tt("fit",{status:h<=d?"pass":"fail",score:h,shown:String(h),limit:`≤ ${d}`,groups:f,detail:h?f.map(p=>p.label).join("; "):`${l}x${i} cells, footprint ${r.cols}x${r.rows} at ${r.at.join(",")} drawn${l*i>r.cols*r.rows?", overhangs are roofs":""}`})}function v_(t,a,s){const l=t.doc;if(!l.variantOf)return nt("variant","not a variant (variant of=<asset>)");const i=s.world?.get(l.variantOf);if(!i)return tt("variant",{status:"fail",score:null,shown:"?",limit:"",detail:`no asset '${l.variantOf}' to be a variant of`});const r=qk(i,l,s.frame??0),f=r.l1<Number(a.maxL1)&&r.dl<Number(a.maxDl);return tt("variant",{status:f?"pass":"fail",score:r.l1,shown:`${Ze(r.l1)} · ΔL* ${Ze(r.dl,1)}`,limit:`< ${a.maxL1} · < ${a.maxDl}`,groups:r.border.length?[{label:`border pixels unlike ${l.variantOf}'s (a seam where they meet, unless the textures blend)`,pts:r.border}]:[],detail:`colour mix against ${l.variantOf}: L1 ${Ze(r.l1)}, ΔL* ${Ze(r.dl,1)}${f?"":" (too different: on a map it reads as a patch)"}; ${r.border.length?`${r.border.length} border pixels differ`:"same border"}`})}function x_(t,a,s){const l=t.doc;if(!l.densityOf)return nt("density","not a density copy (density of=<asset> d=<n>)");const i=s.world?.get(l.densityOf.of);if(!i)return tt("density",{status:"fail",score:null,shown:"?",limit:"",detail:`no asset '${l.densityOf.of}' to be a density of`});const r=l.densityOf.d;if(i.width*r!==l.width||i.height*r!==l.height)return tt("density",{status:"fail",score:null,shown:"size",limit:"",detail:`${l.width}x${l.height} is not ${r} x ${l.densityOf.of}'s ${i.width}x${i.height}`});const{reducer:f="ink-vote",...u}=s.style?.density??{},h=K0(i,l,r,f,u,s.frame??0),d=Number(a.max),p=h.pts.flatMap(([y,w])=>Array.from({length:r*r},(x,b)=>[y*r+b%r,w*r+Math.floor(b/r)]));return tt("density",{status:h.share<=d?"pass":"fail",score:h.share,shown:bt(h.share),limit:`≤ ${bt(d)}`,groups:h.pts.length?[{label:`blocks the ${f} reducer turns into another colour than ${l.densityOf.of} has`,pts:p}]:[],detail:`reduced by ${r} with ${f}: ${h.pts.length} of ${l.densityOf.of}'s pixels differ (${bt(h.share)})`})}const ah=t=>()=>nt(t,"a map check (on map documents)");function b_(t,a,s){const l=t.doc;if(l.family||l.overlay)return nt("consistency","judged on its maps");const i=(s.peers??[]).filter(b=>b.doc!==l&&b.name!==l.name),r=Math.max(1,Math.min(l.width,l.height)/16),f=Math.max(1,l.cellH/24),u=l.kind==="icon"?{maxStroke:Number(a.maxStroke)*r,maxFill:Number(a.maxFill),maxCentre:Number(a.maxCentre)*r}:void 0;if(!i.length&&s.expect?.height===void 0&&!u)return nt("consistency","no set to compare with (plan it in the manifest)");const h=q0(l,i,{ink:s.style?.outline??["ink","outline","black"],light:s.style?.light,height:s.expect?.height,maxL:Number(a.maxL),maxOutline:Number(a.maxOutline),maxAngle:Number(a.maxAngle),maxCluster:Number(a.maxCluster),maxSteps:Number(a.maxSteps),heightTol:Math.round(Number(a.heightTol)*f),...u?{icon:u}:{}}),d=h.parts.filter(b=>b.pass===!1),p=[];if(h.box&&d.some(b=>b.name==="height")){const b=[];for(let v=h.box.x;v<h.box.x+h.box.w;v++)b.push([v,h.box.y],[v,h.box.y+h.box.h-1]);p.push({label:"the drawn shape's top and bottom rows (its height is off the plan)",pts:b})}const y=d.filter(b=>["stroke weight","box fill","optical centre"].includes(b.name));if(h.box&&y.length){const b=[],v=h.box;for(let $=v.x;$<v.x+v.w;$++)b.push([$,v.y],[$,v.y+v.h-1]);for(let $=v.y;$<v.y+v.h;$++)b.push([v.x,$],[v.x+v.w-1,$]);p.push({label:`the drawn box (${y.map($=>$.name).join(", ")} off the icon set)`,pts:b})}const w=Number(a.max),x=h.peers.length?`against ${h.peers.length} in its set (${h.peers.slice(0,6).join(", ")}${h.peers.length>6?", …":""})`:"against the plan";return tt("consistency",{status:d.length<=w?"pass":"fail",score:d.length,shown:String(d.length),limit:`≤ ${w}`,groups:p,parts:h.parts.map(b=>({...b})),detail:`${d.length?`outliers: ${d.map(b=>`${b.name} ${b.detail}`).join("; ")}`:"no outliers"} ${x}${h.recolours.length?`; recolours of each other, not compared: ${h.recolours.join(", ")}`:""}`})}function $_(t,a){const s=t.doc;if(!s.font)return nt("font","not a glyph sheet");const l=s.font,i=M0(s),r=[],f=[],u=(z,E)=>{const R=[];for(let B=0;B<s.cellW;B++)t.get(z.cell[0]+B,z.cell[1]+E)!==ne&&R.push([z.cell[0]+B,z.cell[1]+E]);return R},h=z=>{const E=new Map;for(const R of z)E.set(R,(E.get(R)??0)+1);return[...E].sort((R,B)=>B[1]-R[1]||B[0]-R[0])[0]?.[0]},d=(z,E)=>{const R=i.filter(T=>T.box&&z.includes(String.fromCodePoint(T.cp)));if(R.length<2)return null;const B=R.map(T=>l.baseline-T.box[1]+1),K=h(B),J=R.filter((T,D)=>B[D]!==K);return J.length&&(f.push(`${E} ${K}: ${J.map(T=>`${Cs(T.cp)} ${l.baseline-T.box[1]+1}`).join(", ")}`),r.push({label:`${E} is not ${K}`,pts:J.flatMap(T=>u(T,T.box[1]))})),K},p=d("ABCDEFGHIJKLMNOPRSTUVWXYZ","cap height"),y=d("acemnorsuvwxz","x-height"),x=i.filter(z=>z.box&&/^[A-PR-Za-fhik-ortuv-xz0-9]$/.test(String.fromCodePoint(z.cp))).filter(z=>z.box[3]!==l.baseline);x.length&&(f.push(`off the baseline (row ${l.baseline}): ${x.map(z=>`${Cs(z.cp)} ends on row ${z.box[3]}`).join(", ")}`),r.push({label:`not standing on the baseline (row ${l.baseline})`,pts:x.flatMap(z=>u(z,z.box[3]))}));const b=i.filter(z=>z.box&&(z.advance===0||z.box[2]>=z.advance));b.length&&(f.push(`drawn past the advance: ${b.map(z=>`${Cs(z.cp)} (advance ${z.advance}, ink to column ${z.box[2]})`).join(", ")}`),r.push({label:"drawn past its advance",pts:b.flatMap(z=>{const E=[];for(let R=0;R<s.cellH;R++)for(let B=Math.max(z.advance,0);B<s.cellW;B++)t.get(z.cell[0]+B,z.cell[1]+R)!==ne&&E.push([z.cell[0]+B,z.cell[1]+R]);return E})}));const v=i.filter(z=>!z.box&&!/\s/u.test(String.fromCodePoint(z.cp)));v.length&&(f.push(`not drawn: ${v.map(z=>Cs(z.cp)).join(" ")}`),r.push({label:"an empty glyph cell",pts:v.map(z=>[z.cell[0],z.cell[1]])}));const $=i.filter(z=>z.box),_=$.length?Math.max(...$.map(z=>z.box[3]))-Math.min(...$.map(z=>z.box[1]))+1:0;_&&l.line<_&&f.push(`the line height ${l.line} is less than the glyphs' ${_} rows (lines would overlap)`);const j=Number(a.maxLine);j>0&&l.line>j&&f.push(`the line height ${l.line} is over the limit ${j}`);const N=f.length,M=Number(a.max),A=i.length-$.length;return tt("font",{status:N<=M?"pass":"fail",score:N,shown:String(N),limit:`≤ ${M}`,groups:r,detail:`${N?f.join("; "):"metrics agree"} (${$.length} of ${i.length} glyphs drawn${A?`, ${A} empty`:""}; cap height ${p??"—"}, x-height ${y??"—"}, baseline row ${l.baseline}, line ${l.line}${j>0?` of at most ${j}`:""})`})}function F0(t){if(t.kind==="object")return[{x:0,y:0,w:t.width,h:t.height}];const a=[];for(let s=0;s+t.cellH<=t.height;s+=t.cellH)for(let l=0;l+t.cellW<=t.width;l+=t.cellW)a.push({x:l,y:s,w:t.cellW,h:t.cellH});return a}function k_(t,a){const s=t.doc;if(s.wrap||s.family||s.map)return nt("margin","tiles and families join their neighbours");const l=Number(a.max)>=0&&a.bottom===!1?["top","left","right","bottom"]:["top","left","right"],i=new Map,r=(d,p,y)=>{i.has(d)||i.set(d,[]),i.get(d).push([p,y])};for(const d of F0(s)){for(let p=d.x;p<d.x+d.w;p++)t.get(p,d.y)!==ne&&r("top",p,d.y),l.includes("bottom")&&t.get(p,d.y+d.h-1)!==ne&&r("bottom",p,d.y+d.h-1);for(let p=d.y;p<d.y+d.h;p++)t.get(d.x,p)!==ne&&r("left",d.x,p),t.get(d.x+d.w-1,p)!==ne&&r("right",d.x+d.w-1,p)}const f=l.filter(d=>i.has(d)).map(d=>({label:`art on the ${d} edge of its ${s.kind==="object"?"canvas":"cell"}`,pts:i.get(d)})),u=f.reduce((d,p)=>d+p.pts.length,0),h=Number(a.max);return tt("margin",{status:u<=h?"pass":"fail",score:u,shown:String(u),limit:`≤ ${h}`,groups:f,detail:u===0?`a clear pixel all round${l.includes("bottom")?"":" but the bottom (where it stands)"}`:`${u} px on the edge (${f.map(d=>`${d.label.replace(/^art on the | edge.*$/g,"")} ${d.pts.length}`).join(", ")}): move it in, or make the canvas bigger`})}function __(t,a){const s=t.doc;if(s.wrap||s.family||s.map)return nt("pieces","tiles and families are texture");const l=Number(a.min),i=[];let r=0;for(const u of F0(s)){const h=new Uint8Array(u.w*u.h),d=[];for(let p=0;p<u.h;p++)for(let y=0;y<u.w;y++){if(h[p*u.w+y]||t.get(u.x+y,u.y+p)===ne)continue;const w=[],x=[[y,p]];for(h[p*u.w+y]=1;x.length;){const[b,v]=x.pop();w.push([u.x+b,u.y+v]);for(const[$,_]of Rl){const j=b+$,N=v+_;j<0||N<0||j>=u.w||N>=u.h||h[N*u.w+j]||t.get(u.x+j,u.y+N)===ne||(h[N*u.w+j]=1,x.push([j,N]))}}d.push(w)}d.sort((p,y)=>y.length-p.length);for(const p of d.slice(1)){if(p.length<l)continue;r++;const y=p.map(x=>x[0]),w=p.map(x=>x[1]);i.push({label:`a part apart from the rest: ${p.length} px at ${Math.min(...y)},${Math.min(...w)} ${Math.max(...y)-Math.min(...y)+1}x${Math.max(...w)-Math.min(...w)+1}`,pts:p})}}const f=Number(a.max);return tt("pieces",{status:r<=f?"pass":"fail",score:r,shown:String(r),limit:`≤ ${f}`,groups:i,detail:r===0?"one piece":`${r} part${r>1?"s":""} not touching the rest (${i.map(u=>u.label.replace(/^a part apart from the rest: /,"")).join("; ")}): join it, or turn pieces off for this asset if it is meant to float`})}const Lr={palette:Wk,orphans:Fk,jaggies:a_,banding:o_,outline:i_,seam:c_,coverage:f_,readability:h_,revert:d_,repetition:p_,anim:y_,views:g_,fit:w_,variant:v_,footprint:ah("footprint"),lattice:ah("lattice"),draworder:ah("draworder"),density:x_,consistency:b_,font:$_,margin:k_,pieces:__},j_=new Set(["font","consistency","coverage","anim","views","footprint","draworder","lattice"]);function S_(t,a,s){const l=Gh(t,["objects"]),r=[...new Set(l.map(d=>t.map.entries[d.entry].name))].flatMap(d=>{const p=s.world.get(d);return p&&!p.family&&!p.wrap?[{name:d,doc:p}]:[]});if(r.length<3)return nt("consistency",`fewer than three kinds of object on the map (${r.length})`);const f=[],u=[];for(const d of r){const y=q0(d.doc,r.filter(w=>w!==d),{ink:s.style?.outline??["ink","outline","black"],light:s.style?.light,maxL:Number(a.maxL),maxOutline:Number(a.maxOutline),maxAngle:Number(a.maxAngle),maxCluster:Number(a.maxCluster),maxSteps:Number(a.maxSteps),heightTol:Number(a.heightTol)}).parts.filter(w=>w.pass===!1);y.length&&(u.push(`${d.name}: ${y.map(w=>`${w.name} ${w.detail}`).join("; ")}`),f.push({label:`${d.name} stands out (${y.map(w=>w.name).join(", ")})`,pts:l.filter(w=>t.map.entries[w.entry].name===d.name).map(w=>[w.x,w.y])}))}const h=Number(a.max);return tt("consistency",{status:f.length<=h?"pass":"fail",score:f.length,shown:String(f.length),limit:`≤ ${h}`,groups:f,detail:u.length?u.join(" | "):`${r.length} kinds of object on the map, none out of step with the rest`})}function N_(t,a,s){if(!s.world)return a.map(h=>nt(h,"a map is checked with the project's assets"));const l=Bo("repetition","map",s.style,t.name),i=Bo("seam","map",s.style,t.name),r=Bo("lattice","map",s.style,t.name),f=Xh(t,s.world),u=X0(t,s.world,{edgeRun:Number(l.edgeRun),motif:Number(l.motif),seam:Number(i.max),lattice:Number(r.max),latticeContrast:Number(r.contrast)},f);return a.map(h=>{const d=Bo(h,"map",s.style,t.name);if(d.off===!0)return nt(h,"turned off in the style guide");if(h==="consistency")return S_(t,d,s);const p=u.find(y=>y.id===h);return p?tt(h,{status:p.pass?"pass":"fail",score:p.score,shown:p.shown,limit:p.limitText,detail:p.detail,groups:p.groups.map(y=>({label:y.label,pts:y.cells})),...p.parts?{parts:p.parts.map(y=>({name:y.name,value:y.value,limit:y.limit,pass:y.pass,detail:y.detail}))}:{}}):nt(h,"checked on the assets the map names, not on the map")})}function hw(t,a,s){const l=a.filter(y=>y.r.status!=="skip");if(!l.length)return a[0].r;const i=l[0].r.limit.startsWith("≥"),r=l.filter(y=>y.r.status==="fail"),u=(r.length?r:l).reduce((y,w)=>(w.r.score??0)*(i?-1:1)>(y.r.score??0)*(i?-1:1)?w:y),h=l.flatMap(y=>y.r.groups.map(w=>({...w,label:`frame ${y.f+1}: ${w.label}`,frame:y.f}))),d=r.length>1?` (fails on frames ${r.map(y=>y.f+1).join(", ")})`:"";return tt(t,{...u.r,groups:h,detail:`frame ${u.f+1}: ${u.r.detail}${d}${s}`,frame:u.f})}function M_(t,a=J0,s={}){if(t.map)return N_(t,a,s);let l=s.frame!==void 0?[s.frame]:Array.from({length:t.frameCount},(u,h)=>h),i="";if(l.length>1&&s.budget!==void 0&&t.width*t.height*t.frameCount>s.budget){const u=Math.min(s.focus??0,t.frameCount-1);l=[u],i=` (frame ${u+1} of ${t.frameCount} only: a large canvas; \`check\` covers every frame)`}const r=new Map,f=u=>r.get(u)??r.set(u,Jk(t,u)).get(u);return a.map(u=>{const h=Bo(u,t.kind,s.style,t.name);if(h.off===!0)return nt(u,ec[u][t.kind]?.off===!0?`not checked on a ${t.kind}`:"turned off in the style guide");if(j_.has(u)||l.length===1&&t.frameCount===1)return Lr[u](f(l[0]),h,s);if(l.length===1){const d=Lr[u](f(l[0]),h,{...s,frame:l[0]});return d.status==="skip"?d:hw(u,[{f:l[0],r:d}],i)}return hw(u,l.map(d=>({f:d,r:Lr[u](f(d),h,{...s,frame:d})})),i)})}const ii="ground",Wo="band",dw=new Map;function yt(t){if(t.def){const s=JSON.stringify(t.def),l=dw.get(s);if(l)return l;const i=Lh(t.def);return dw.set(s,i),i}const a=E0(t.scheme);if(!a)throw new Error(`unknown scheme '${t.scheme}'`);return a}function P0(t,a,s){const l=t.variants.length,i=Math.max(2,t.columns,a),r=Math.ceil(l/t.columns),f=t.variants.map((u,h)=>[h%t.columns,1+Math.floor(h/t.columns)]);return{cols:i,rows:1+r+s,inside:[0,0],outside:[1,0],cells:f,mapRow:1+r}}const tn=t=>P0(yt(t),t.mapCols,t.mapRows);function Wh(t,a){const s=tn(t);if(a==="inside")return s.inside;if(a==="outside")return s.outside;const l=yt(t).byName.get(a);return l===void 0?null:s.cells[l]}function z_(t,a,s){const l=tn(t),i=Math.floor(a/t.tile),r=Math.floor(s/t.tile);if(i===l.inside[0]&&r===l.inside[1])return"inside";if(i===l.outside[0]&&r===l.outside[1])return"outside";if(t.mapRows&&r>=l.mapRow&&i<t.mapCols)return"map";const f=l.cells.findIndex(([u,h])=>u===i&&h===r);return f<0?null:yt(t).variants[f].name}const Br=new Map;function ri(t,a,s){const l=`${t.name}|${a}|${s.inset}|${s.radius}|${s.fillet??""}|${s.jitter?`${s.jitter.px}:${s.jitter.seed}`:""}|${s.bands.map(r=>`${r.w}:${r.fill}`).join(",")}`;let i=Br.get(l);return i||(i=t.variants.map((r,f)=>pk(t,f,a,s)),Br.size>64&&Br.clear(),Br.set(l,i)),i}function ev(t,a){return a<0||a<t.bands.length&&t.bands[a].fill==="outside"}const C_=(t,a)=>a>=0&&a<t.bands.length;function E_(t,a,s,l,i,r,f,u){for(let h=0;h<u;h++){const d=(l+h)*a+s;t.copyWithin((r+h)*a+i,d,d+f)}}function mw(t,a,s,l,i){const r=new Uint16Array(i*i).fill(ne);return t.layers.forEach((f,u)=>{if(f.hidden||f.reference)return;const h=t.cels[u][a];for(let d=0;d<i;d++)for(let p=0;p<i;p++){const y=h[(l*i+d)*t.width+s*i+p];y!==ne&&(r[d*i+p]=y)}}),r}const pw=new WeakMap;function T_(t,a,s,l){let i=pw.get(l);return i||(i=l.map(r=>Uint8Array.from(r,f=>ev(s,f)?1:0)),pw.set(l,i)),i}function yw(t){const a=t.family;if(!a)return;const s=yt(a),l=a.tile,i=l/2,r=t.width,f=tn(a),u=ri(s,l,a.geometry),h=t.layers.findIndex(w=>w.name===ii),d=t.layers.findIndex(w=>w.name===Wo),p=new Set(a.detached.map(w=>s.byName.get(w))),y=new Set;for(let w=0;w<t.frameCount;w++){if(h>=0&&!y.has(t.cels[h][w])){const x=t.cels[h][w];y.add(x);const b=mw(t,w,f.inside[0],f.inside[1],l),v=mw(t,w,f.outside[0],f.outside[1],l),$=T_(s,l,a.geometry,u);for(let _=0;_<s.variants.length;_++){const[j,N]=f.cells[_],M=$[_];for(let A=0;A<l;A++){const z=(N*l+A)*r+j*l;for(let E=0;E<l;E++){const R=A*l+E;x[z+E]=M[R]?v[R]:b[R]}}}}if(d>=0&&!y.has(t.cels[d][w])){const x=t.cels[d][w];y.add(x);for(let b=0;b<s.variants.length;b++){const v=s.sources[b];if(!v||p.has(b))continue;const[$,_]=f.cells[b];v.forEach(([j,N],M)=>{if(j<0){for(let E=0;E<i;E++)x.fill(ne,(_*l+(M&2?i:0)+E)*r+$*l+(M&1?i:0),(_*l+(M&2?i:0)+E)*r+$*l+(M&1?i:0)+i);return}const[A,z]=f.cells[j];E_(x,r,A*l+(N&1?i:0),z*l+(N&2?i:0),$*l+(M&1?i:0),_*l+(M&2?i:0),i,i)})}}}}function tv(t,a,s,l,i){const r=new Uint16Array(i*i);for(let f=0;f<i;f++)r.set(t.subarray((l*i+f)*a+s*i,(l*i+f)*a+s*i+i),f*i);return r}function fc(t,a,s=0){const l=t.family,i=yt(l),r=l.tile,f=tn(l),u=Ce(t,s),h=oc(i,a),d=new Map,p=b=>{const v=b??-1;let $=d.get(v);if(!$){const[_,j]=b===null?f.outside:f.cells[b];d.set(v,$=tv(u,t.width,_,j,r))}return $},y=a.cols*r,w=a.rows*r,x=new Uint16Array(y*w);return h.forEach((b,v)=>{const $=p(b),_=v%a.cols*r,j=Math.floor(v/a.cols)*r;for(let N=0;N<r;N++)x.set($.subarray(N*r,N*r+r),(j+N)*y+_)}),{px:x,w:y,h:w,t:r,variants:h}}function O_(t,a,s,l=0){const i=Ce(t,l),r=a*t.width,f=s*t.height,u=new Uint16Array(r*f);for(let h=0;h<f;h++)for(let d=0;d<r;d++)u[h*r+d]=i[h%t.height*t.width+d%t.width];return{px:u,w:r,h:f,t:t.width,variants:Array.from({length:a*s},()=>null)}}function Rs(...t){let a=2654435769;for(const s of t)a=Math.imul(a^(s|0),2246822507)>>>0,a=(a^a>>>13)>>>0,a=Math.imul(a,3266489909)>>>0,a=(a^a>>>16)>>>0;return a}function nv(t,a,s,l){const i=t.neighbours==="corners"?a+1:a,r=t.neighbours==="corners"?s+1:s,f=new nn(l,346),u=2,h=Math.floor(i/u)+2,d=Math.floor(r/u)+2,p=Array.from({length:h*d},()=>f.nextInt(256)),y=new Uint8Array(i*r);for(let w=0;w<r;w++)for(let x=0;x<i;x++){const b=Math.floor(x/u),v=Math.floor(w/u),$=x%u,_=w%u,j=p[v*h+b],N=p[v*h+b+1],M=p[(v+1)*h+b],A=p[(v+1)*h+b+1],z=Math.floor(((j*(u-$)+N*$)*(u-_)+(M*(u-$)+A*$)*_)/(u*u)),E=2*x-(i-1),R=2*w-(r-1),B=Math.floor(E*E*256/((i-1)*(i-1)||1)+R*R*256/((r-1)*(r-1)||1)),K=x===0||w===0||x===i-1||w===r-1;y[w*i+x]=!K&&(z-128)*2+150-B>0?1:0}return{cols:a,rows:s,cells:y}}function Qr(t,a){const s=new Array(t.variants.length).fill(0);for(const l of oc(t,a,"not",!1))l!==null&&s[l]++;return s}function av(t,a){const s=t.variants[a];if(s.key===null)return null;if(t.neighbours==="corners"){const r=new Uint8Array(16),f=s.key;return f&128&&(r[5]=1),f&2&&(r[6]=1),f&32&&(r[9]=1),f&8&&(r[10]=1),{cols:3,rows:3,cells:r}}const l=new Uint8Array(9);if(s.on==="fillet"){const r=t.cornerRule==="diagonal";for(const[f,u]of[[2,[1,2,5]],[8,[5,8,7]],[32,[7,6,3]],[128,[3,0,1]]])if(s.key&f)for(const h of u)(!r||h!==u[1])&&(l[h]=1);return{cols:3,rows:3,cells:l}}if(s.on==="face")return l[1]=1,s.key&4&&(l[2]=1),s.key&64&&(l[0]=1),s.key&8&&(l[2]=l[5]=1),s.key&32&&(l[0]=l[3]=1),{cols:3,rows:3,cells:l};if(s.on==="side")return s.key&64&&(l[3]=1),s.key&4&&(l[5]=1),s.key&1&&(s.key&64&&(l[0]=1),s.key&4&&(l[2]=1)),s.key&16||(l[7]=1,s.key&64&&(l[6]=1),s.key&4&&(l[8]=1)),{cols:3,rows:3,cells:l};if(s.on==="corner")return s.key&128&&(l[0]=1),s.key&2&&(l[2]=1),{cols:3,rows:3,cells:l};l[4]=1;const i=[[1,1],[2,2],[4,5],[8,8],[16,7],[32,6],[64,3],[128,0]];for(const[r,f]of i)s.key&r&&(l[f]=1);return{cols:3,rows:3,cells:l}}function A_(t,a,s,l,i=1){const r=t.neighbours==="corners",f=r?a+1:a,u=r?s+1:s,h=T0(t),d=new nn(l,3086),p=v=>{for(let $=v.length-1;$>0;$--){const _=d.nextInt($+1);[v[$],v[_]]=[v[_],v[$]]}return v},y=r?2:3,w=v=>{const $=av(t,v).cells;return r?Uint8Array.from([$[5],$[6],$[9],$[10]]):$},x=f-y+1,b=u-y+1;for(let v=0;v<8;v++){const $={cols:a,rows:s,cells:new Uint8Array(f*u)};let _=Qr(t,$),j=!0;const N=new Map(h.map(E=>[E,w(E).reduce((R,B)=>R+B,0)]));for(const E of p([...h]).sort((R,B)=>N.get(B)-N.get(R))){const R=w(E);for(;_[E]<i;){const B=p(Array.from({length:x*b},(D,L)=>L)),K=D=>{const L=D%x,Y=Math.floor(D/x);let O=0;for(let H=0;H<y;H++)for(let G=0;G<y;G++)$.cells[(Y+H)*f+L+G]!==R[H*y+G]&&O++;return O},J=new Map(B.map(D=>[D,K(D)]));B.sort((D,L)=>J.get(D)-J.get(L));let T=!1;for(const D of B){const L=D%x,Y=Math.floor(D/x),O=$.cells.slice();for(let G=0;G<y;G++)for(let Z=0;Z<y;Z++)$.cells[(Y+G)*f+L+Z]=R[G*y+Z];const H=Qr(t,$);if(H[E]>_[E]&&h.every(G=>G===E||H[G]>=Math.min(i,_[G]))){_=H,T=!0;break}$.cells.set(O)}if(!T){j=!1;break}}}if(j)return $;const M=E=>{const R=Qr(t,E);return h.reduce((B,K)=>B+Math.min(i,R[K]),0)},A=h.length*i;let z=M($);for(let E=0;E<60&&z<A;E++){let R=0,B=-1;const K=d.nextInt($.cells.length);for(let J=0;J<$.cells.length;J++){const T=(K+J)%$.cells.length;$.cells[T]^=1;const D=M($);$.cells[T]^=1,D-z>R&&(R=D-z,B=T)}if(B<0){const J=d.nextInt($.cells.length);$.cells[J]^=1,z=M($);continue}$.cells[B]^=1,z+=R}if(z>=A)return $}return null}function lv(t,a,s=0){const l=a.family;if(!l)return 0;const i=yt(l),r=t.t,f=t.w/r,u=t.variants.flatMap((y,w)=>y!==null&&Hh(i.variants[y].on)?[w]:[]);if(!u.length)return 0;const[h,d]=tn(l).outside,p=Ce(a,s);for(const y of u){const w=y%f*r,x=Math.floor(y/f)*r;for(let b=0;b<r;b++)for(let v=0;v<r;v++)t.px[(x+b)*t.w+w+v]=p[(d*r+b)*a.width+h*r+v]}return u.length}function Ih(t,a){const{w:s,h:l,t:i}=t,r=a.palette.entries.map(w=>qs(w.hex)),f=new Int32Array(s*l),u=new Float64Array(s*l),h=new Int32Array(s*l),d=new Float64Array(s*l);for(let w=0;w<l;w++)for(let x=0;x<s;x++){const b=t.px[w*s+x],v=b===ne?-1:b,$=b===ne?0:r[b];f[w*s+x]=v,u[w*s+x]=$,h[x*l+w]=v,d[x*l+w]=$}const p=tc(f,u,s,l,i),y=tc(h,d,l,s,i);return{score:Math.max(p.jump,y.jump,p.line,y.line,0),jx:p.jump,jy:y.jump,lx:p.line,ly:y.line}}const Go={cols:12,rows:10,seed:1};function gw(t,a){let s=0,l=1/0;return t.forEach((i,r)=>{let f=0;for(const u of t)if(u!==i)for(let h=0;h<i.length;h++)a(h)&&i[h]!==u[h]&&f++;f<l&&(l=f,s=r)}),s}function q_(t,a){const s=t.family,l=yt(s),i=s.tile,r=tn(s),f={cols:s.mapCols,rows:s.mapRows,cells:s.terrain},u=oc(l,f),h=t.layers.findIndex(v=>v.name===Wo),d=t.layers.findIndex(v=>v.name===ii),p=ri(l,i,s.geometry),y=new Map,w=[],x=t.width,b=new Set(s.detached);for(let v=0;v<t.frameCount;v++){const $=Ce(t,v),_=j=>tv($,x,j%s.mapCols,r.mapRow+Math.floor(j/s.mapCols),i);if(l.variants.forEach((j,N)=>{const M=u.flatMap((J,T)=>J===N?[T]:[]);if(!M.length){v===0&&j.key!==null&&w.push(j.name);return}const A=J=>!!j.on||C_(s.geometry,p[N][J]),z=M.map(_),E=gw(z,A);if(v===0&&y.set(N,{tile:M[E],of:M.length}),h<0)return;const R=t.cels[h][v],[B,K]=r.cells[N];for(let J=0;J<i;J++)for(let T=0;T<i;T++)R[(K*i+J)*x+B*i+T]=A(J*i+T)?z[E][J*i+T]:ne;l.pieces.includes(j.name)||b.add(j.name)}),a&&d>=0){const j=l.variants.findIndex(E=>!E.on&&E.quads.every(R=>R==="in"||R.startsWith("in@"))),N=u.flatMap((E,R)=>E===j?[R]:[]),M=u.flatMap((E,R)=>{if(E!==null)return[];if(l.neighbours==="corners")return[];const B=R%s.mapCols,K=Math.floor(R/s.mapCols);for(let J=-1;J<=1;J++)for(let T=-1;T<=1;T++){const D=B+T,L=K+J;if(D>=0&&L>=0&&D<s.mapCols&&L<s.mapRows&&s.terrain[L*s.mapCols+D])return[]}return[R]}),A=l.neighbours==="corners"?u.flatMap((E,R)=>E!==null&&l.variants[E].key===0?[R]:[]):[],z=t.cels[d][v];for(const[E,R]of[[r.inside,N],[r.outside,l.neighbours==="corners"?A:M]]){if(!R.length)continue;const B=R.map(_),K=B[gw(B,()=>!0)];for(let J=0;J<i;J++)z.set(K.subarray(J*i,J*i+i),(E[1]*i+J)*x+E[0]*i)}}}return s.detached=l.variants.map(v=>v.name).filter(v=>b.has(v)),{chosen:y,missing:w}}const R_=t=>{const a=Pa(t)[0];return t.overlay?.mode==="pingpong"?{...a,loop:"pingpong"}:a};function sv(t,a,s,l){const i=t.overlay;if(Rs(i.seed,a,s)%i.every!==0)return null;const r=R_(t),f=Math.max(1,S0(t,r));if(i.mode==="cycle"||i.mode==="pingpong")return El(t,r,l);if(i.mode==="wave")return El(t,r,l+Math.floor((a+s)*f/8));const u=f+i.rest,h=(l+Rs(i.seed,a,s,7)%u)%u;return h<f?El(t,r,h):null}function ov(t,a,s,l,i,r,f){const u=t.overlay,h=f??Ce(t,a),d=Rs(u.seed,s,l,1),p=(u.anchor?u.anchor[0]:Math.floor((i-t.width)/2))+(u.spread[0]?d%(2*u.spread[0]+1)-u.spread[0]:0),y=(u.anchor?u.anchor[1]:Math.floor((i-t.height)/2))+(u.spread[1]?(d>>>8)%(2*u.spread[1]+1)-u.spread[1]:0);for(let w=0;w<t.height;w++)for(let x=0;x<t.width;x++){const b=h[w*t.width+x];b!==ne&&r(s*i+p+x,l*i+y+w,b)}}function D_(t,a,s,l){const i=l?.family?yt(l.family):null;for(const r of a){const f=r.overlay;if(!f)continue;const u=t.w/t.t,h=new Map;t.variants.forEach((d,p)=>{const y=p%u,w=Math.floor(p/u),x=d!==null&&!i?.variants[d].on;if(f.on==="outside"&&x||f.on==="inside"&&!x)return;const b=sv(r,y,w,s);if(b===null)return;const v=h.get(b)??h.set(b,Ce(r,b)).get(b);ov(r,b,y,w,t.t,($,_,j)=>{$>=0&&_>=0&&$<t.w&&_<t.h&&(t.px[_*t.w+$]=j)},v)})}}function U_(t,a){const s=t.palette.entries.map(i=>{let r=a.findIndex(f=>f.name===i.name&&f.hex===i.hex);return r<0&&(r=a.findIndex(f=>f.hex===i.hex)),r<0&&(a.push({name:i.name,hex:i.hex}),r=a.length-1),r}),l=t.cels.map(i=>i.map(r=>r.map(f=>f===ne?f:s[f])));return{...t,cels:l}}function H_(t,a){if(t.frameCount<2)return 0;const s=Pa(t)[0];return sc(s).length?El(t,s,a):0}function L_(){return{mode:"cycle",on:"outside",anchor:null,spread:[0,0],every:1,rest:60,seed:1}}function wn(t,a,s=!0){const l=et(t,a);return{width:t.width,height:t.height,wrap:t.wrap,pixels:t.cels[l.layer][l.frame],mask:s?l.sel:null}}function B_(t,a){if(!a)return[[0,0]];if(a.shape==="stamp"){const i=t.stamps[a.stamp];if(!i)return[[0,0]];const r=[];for(let f=0;f<i.h;f++)for(let u=0;u<i.w;u++)i.px[f*i.w+u]!==ne&&r.push([u-(i.w>>1),f-(i.h>>1)]);return r.length?r:[[0,0]]}const s=a.size,l=[];for(let i=0;i<s;i++)for(let r=0;r<s;r++){if(a.shape==="circle"){const f=2*r-(s-1),u=2*i-(s-1);if(f*f+u*u>s*s-s+1)continue}l.push([r-(s>>1),i-(s>>1)])}return l}function Fh(t,a,s){const l=et(t,a).mirror;if(!l)return s;const i=[...s],r=(f,u,h)=>{const d=[...f];return u&&(d[0]=l.x2-f[0]),h&&(d[1]=l.y2-f[1]),d};for(const f of s)l.x2!==null&&i.push(r(f,!0,!1)),l.y2!==null&&i.push(r(f,!1,!0)),l.x2!==null&&l.y2!==null&&i.push(r(f,!0,!0));return i}function Y_(t,a,s,l,i={}){const r=wn(t,a);let f=s;if(i.brush){const u=B_(t,et(t,a).brush);(u.length!==1||u[0][0]!==0||u[0][1]!==0)&&(f=s.flatMap(([h,d])=>u.map(([p,y])=>[h+p,d+y])))}i.mirror&&(f=Fh(t,a,f));for(const[u,h]of f)iv(r,u,h,l)}function Fn(t,a,s,l){const i=wn(t,a);for(const[r,f,u]of l?Fh(t,a,s):s)iv(i,r,f,u)}function iv(t,a,s,l){const i=yn(t,a,s);i>=0&&(!t.mask||t.mask[i])&&(t.pixels[i]=l)}const G_=2;function Xo(t,a,s){return{t:"kv",key:t,value:a,quoted:!1,vcol:s.col,line:s.line,col:s.col}}class _e{cmd;positional=[];opts=new Map;flags=[];cell=null;next=0;constructor(a,s,l=[]){this.cmd=a;for(const i of a.args)if(i.t==="kv"){if(!s.includes(i.key)){const r=s.length?` (options: ${s.join(", ")})`:"";throw new C(i.line,i.col,`${a.name} has no option '${i.key}'${r}`)}if(this.opts.has(i.key))throw new C(i.line,i.col,`option '${i.key}' given twice`);this.opts.set(i.key,i)}else if(i.t==="cell"){if(this.cell)throw new C(i.line,i.col,"@cell given twice");this.cell=i}else i.t==="word"&&l.includes(i.v)?this.flags.push(i):this.positional.push(i)}where(){const a=this.positional[this.next-1];return a?[a.line,a.col+Io(a).length+1]:[this.cmd.line,this.cmd.col+this.cmd.name.length+1]}peek(){return this.positional[this.next]}take(a,s){const l=this.positional[this.next];if(!l){const[i,r]=this.where();throw new C(i,r,`${this.cmd.name}: expected ${s}`)}if(l.t!==a)throw new C(l.line,l.col,`${this.cmd.name}: expected ${s}`);return this.next++,l}rest(){const a=this.positional.slice(this.next);return this.next=this.positional.length,a}done(){const a=this.positional[this.next];if(a)throw new C(a.line,a.col,`${this.cmd.name}: unexpected '${Io(a)}'`)}cellOrigin(a){if(!this.cell)return{dx:0,dy:0,text:""};if(this.cell.name!==void 0){const f=a.family?Wh(a.family,this.cell.name):null;if(!f)throw new C(this.cell.line,this.cell.col,a.family?`@cell(${this.cell.name}): no such cell (inside, outside, or a variant of ${a.family.scheme})`:`@cell(${this.cell.name}): cells by name are a family's`);return{dx:f[0]*a.cellW,dy:f[1]*a.cellH,text:` @cell(${this.cell.name})`}}const{cx:s,cy:l}=this.cell,i=Math.floor(a.width/a.cellW),r=Math.floor(a.height/a.cellH);if(s>=i||l>=r)throw new C(this.cell.line,this.cell.col,`@cell(${s},${l}) is outside the ${i}x${r} cell grid`);return{dx:s*a.cellW,dy:l*a.cellH,text:` @cell(${s},${l})`}}flag(a,s){const l=this.flags.filter(i=>a.includes(i.v));if(l.length>1)throw new C(l[1].line,l[1].col,`choose one of ${a.join(" or ")}`);return l[0]?.v??s}choice(a,s,l){const i=this.opts.get(a);if(!i)return l;if(!s.includes(i.value))throw new C(i.line,i.vcol,`${a}= must be one of ${s.join(", ")}`);return i.value}}function Io(t){switch(t.t){case"word":return t.v;case"int":return String(t.v);case"point":return`${t.x},${t.y}`;case"size":return`${t.w}x${t.h}`;case"cell":return t.name!==void 0?`@cell(${t.name})`:`@cell(${t.cx},${t.cy})`;case"string":return wa(t.v);case"kv":return`${t.key}=${t.quoted?wa(t.value):t.value}`;case"block":return"<<";case"body":return"{"}}function Qe(t,a){if(!a.doc)throw new C(t.line,t.col,"there is no document yet: start with 'new'");return a.doc}function at(t,a){const s=Qe(t,a);if(s.map)throw new C(t.line,t.col,`${t.name}: a map holds tiles and objects by name, not pixels (terrain, place, move, road, scatter, map gen)`);const l=s.layers[et(s,a.by).layer];if(l.locked)throw new C(t.line,t.col,`layer '${l.name}' is locked (layer set ${l.name} locked=off to draw on it)`);const i=et(s,a.by).frame,r=Vo(s,i);if(r?.mirror){const f=s.views.find(h=>h.name===r.mirror),u=f?` (frame ${f.from+i-r.from+1})`:"";throw new C(t.line,t.col,`frame ${i+1} is in view ${r.name}, a live mirror of ${r.mirror}: draw on ${r.mirror}${u}, or view ${r.name} mirror=off`)}return s}const ve=t=>({k:"fn",run:t}),nl=(t,a,s=!0)=>ve((l,i)=>Y_(l,i,t,a,{brush:s,mirror:!0}));function an(t,a,s,l){if(t==="none")return{index:ne,name:"none"};let i=a.entries.findIndex(r=>r.name===t);if(i<0&&[...t].length===1&&(i=a.entries.findIndex(r=>r.key===t)),i<0&&t.startsWith("#")){const r=t.toLowerCase();if(i=a.entries.findIndex(f=>f.hex===r),i<0)throw new C(s,l,`c=${t} is not in palette '${a.name}'`)}if(i<0){const r=a.entries.map(u=>u.name),f=r.length>12?r.slice(0,12).join(", ")+", ...":r.join(", ");throw new C(s,l,`unknown colour '${t}' (palette '${a.name}': ${f}, none)`)}return{index:i,name:a.entries[i].name}}function sl(t,a){const s=t.opts.get("c");if(!s)throw new C(t.cmd.line,t.cmd.col,`${t.cmd.name}: missing c=<colour>`);return an(s.value,a.palette,s.line,s.vcol)}const Ph=(t,a,s)=>a||s?t.map(([l,i])=>[l+a,i+s]):t;function X_(t){return{name:t.name,description:t.description,neighbours:t.neighbours,...t.cornerRule!==void 0?{cornerRule:t.cornerRule}:{},...t.inset?{inset:t.inset}:{},...t.kinds?{kinds:t.kinds}:{},...t.faces!==void 0?{faces:t.faces}:{},...t.sides!==void 0?{sides:t.sides}:{},...t.fillets!==void 0?{fillets:t.fillets}:{},columns:t.columns,pieces:t.pieces,variants:t.variants.map(a=>({name:a.name,key:a.key,quads:a.quads,...a.on?{on:a.on}:{},...a.alt?{alt:a.alt}:{}}))}}const Z_={name:"new",summary:"new <kind> <name> <W>x<H> [palette=<name>] [wrap=on|off] [cell=<W>x<H>] [bg=<colour>|none] [<< palette rows >>] (new family <name> <T>x<T> scheme=<scheme> [map=<C>x<R>]: an autotile family of T px tiles; new map <name> <C>x<R> [tile=<T>]: a map of C x R cells of T px)",normalise(t,a){if(a.doc)throw new C(t.line,t.col,"new must be the first command of a tape (this document already exists)");const s=new _e(t,["palette","wrap","cell","bg","scheme","def","map","tile","chars","cols","baseline","line","spacing"]),l=s.take("word",`a kind (${Xr.join(", ")})`);if(!Xr.includes(l.v))throw new C(l.line,l.col,`unknown kind '${l.v}' (kinds: ${Xr.join(", ")})`);const i=l.v,r=s.take("word","a document name");if(!/^[a-z][a-z0-9_-]*$/.test(r.v))throw new C(r.line,r.col,"document names use a-z, 0-9, _ and -, starting with a letter");const f=a.defaults?.asset?.(i,r.v),u=s.peek()?.t!=="size"&&f?.size?{w:f.size[0],h:f.size[1],line:r.line,col:r.col}:s.take("size","a size like 24x24 (or plan the asset in the manifest)"),h=s.peek()?.t==="block"?s.take("block","palette rows"):null;if(s.done(),u.w<1||u.h<1||u.w>4096||u.h>4096)throw new C(u.line,u.col,"size must be 1..4096 on each side");const d=a.lang??G_,p=s.opts.get("palette"),y=p?.value??f?.palette??a.defaultPalette;let w;if(h){if(d<2)throw new C(h.line,h.col,"a palette block needs tape language 2");if(!y||!/^[A-Za-z][A-Za-z0-9_-]*$/.test(y))throw new C(p?.line??t.line,p?.vcol??t.col,"new: a palette block needs palette=<name>");const L=_$(y,h.rows.map(Y=>Y.text));if("message"in L){const Y=h.rows[L.row];throw new C(Y?.line??h.line,(Y?.col??h.col)+L.col,L.message)}w=L.palette}else{if(!y)throw new C(t.line,t.col,"new: no palette= given and the project has no default palette");const L=a.palette(y);if(!L)throw new C(p?.line??t.line,p?.vcol??t.col,`unknown palette '${y}'`);w=L}const x=s.choice("wrap",["on","off"],i==="tile"?"on":"off")==="on";let b=u.w,v=u.h;const $=s.opts.get("cell")??(f?.cell&&i!=="family"&&i!=="map"?Xo("cell",`${f.cell[0]}x${f.cell[1]}`,t):void 0);if($){const L=/^(\d+)x(\d+)$/.exec($.value);if(!L||Number(L[1])<1||Number(L[2])<1)throw new C($.line,$.vcol,"cell= must be a size like 24x24");b=Number(L[1]),v=Number(L[2])}const _=s.opts.get("bg"),j=_?an(_.value,w,_.line,_.vcol):{index:ne,name:"none"},N=s.opts.get("scheme")??(i==="family"&&f?.scheme?Xo("scheme",f.scheme,t):void 0),M=s.opts.get("map");let A,z,E;const R=["chars","cols","baseline","line","spacing"].flatMap(L=>s.opts.get(L)?[s.opts.get(L)]:[]);if(i!=="font"&&R.length)throw new C(R[0].line,R[0].col,`${R[0].key}= is for new font`);let B=u.w,K=u.h,J="";const T=s.opts.get("tile");if(T&&i!=="map")throw new C(T.line,T.col,"tile= is for new map");if(i==="family"){if(u.w!==u.h||u.w%2||u.w<4||u.w>256)throw new C(u.line,u.col,`a family's tiles are square, even and 4..256 px (${u.w}x${u.h})`);if(!N)throw new C(t.line,t.col,`new family: missing scheme=<scheme> (${[...ph.keys()].join(", ")})`);const L=s.opts.get("def");let Y=null,O=L||a.scheme?.(N.value)?void 0:E0(N.value);if(!O){try{const W=L?JSON.parse(L.value):a.scheme?.(N.value)??null;Y=W?X_(W):null,Y&&(O=Lh(Y))}catch(W){throw new C((L??N).line,(L??N).vcol,`scheme '${N.value}': ${W.message}`)}if(Y&&Y.name!==N.value)throw new C(N.line,N.vcol,`def= holds scheme '${Y.name}', not '${N.value}'`)}if(!O)throw new C(N.line,N.vcol,`unknown scheme '${N.value}' (schemes: ${[...ph.keys()].join(", ")}, or the project's schemes/*.json)`);if(x)throw new C(s.opts.get("wrap").line,s.opts.get("wrap").vcol,"a family sheet does not wrap (its textures are tiles that do)");if($&&(b!==u.w||v!==u.h))throw new C($.line,$.vcol,`a family's cells are its tiles (${u.w}x${u.h})`);let H=0,G=0;if(M){const W=/^(\d+)x(\d+)$/.exec(M.value);if(!W||Number(W[1])<3||Number(W[2])<3||Number(W[1])>64||Number(W[2])>64)throw new C(M.line,M.vcol,"map= must be a size in tiles like 12x10 (3..64 each way)");H=Number(W[1]),G=Number(W[2])}const Z=P0(O,H,G);B=Z.cols*u.w,K=Z.rows*u.h,b=u.w,v=u.h,A={scheme:O.name,tile:u.w,geometry:{inset:gk(O,u.w),radius:0,bands:[]},detached:[],mapCols:H,mapRows:G,terrain:new Uint8Array,def:Y},J=` scheme=${O.name}${Y?` def=${wa(JSON.stringify(Y))}`:""}${H?` map=${H}x${G}`:""}`}else if(i==="map"){if(u.w>512||u.h>512)throw new C(u.line,u.col,"a map is at most 512x512 cells");for(const Y of[N,M,$,s.opts.get("wrap"),_])if(Y)throw new C(Y.line,Y.col,`new map takes no ${Y.key}= (its cells are tile= px)`);let L=a.defaults?.grid??24;if(T){if(!/^\d+$/.test(T.value)||Number(T.value)<4||Number(T.value)>256)throw new C(T.line,T.vcol,"tile= must be the cell size in pixels, 4..256");L=Number(T.value)}b=1,v=1,z={tile:L,entries:[]},J=` tile=${L}`}else for(const L of[N,M,s.opts.get("def")])if(L)throw new C(L.line,L.col,`${L.key}= is for new family`);if(i==="font"){const L=s.opts.get("chars")??(f?.chars?{...Xo("chars",f.chars,t),quoted:!/^[0-9U+,\-]+$/.test(f.chars)}:void 0),Y=L?Qg(L.value,L.quoted):Qg("32-126",!1);if(typeof Y=="string")throw new C(L.line,L.vcol,Y);if(x)throw new C(s.opts.get("wrap").line,s.opts.get("wrap").vcol,"a glyph sheet does not wrap");if($&&(b!==u.w||v!==u.h))throw new C($.line,$.vcol,`a font's cells are its glyph size (${u.w}x${u.h})`);const O=(Z,W,se,ue)=>{const te=s.opts.get(Z);if(!te)return ue;if(!/^\d+$/.test(te.value)||Number(te.value)<W||Number(te.value)>se)throw new C(te.line,te.vcol,`${Z}= must be ${W}..${se}`);return Number(te.value)},H=O("cols",1,256,Math.min(16,Y.length)),G=Math.ceil(Y.length/H);if(u.w>256||u.h>256)throw new C(u.line,u.col,"a glyph cell is at most 256x256");if(H*u.w>4096||G*u.h>4096)throw new C(u.line,u.col,`${Y.length} glyphs in ${H} columns make a ${H*u.w}x${G*u.h} sheet, over 4096`);E={chars:Y,cols:H,baseline:O("baseline",0,u.h-1,u.h-1),line:O("line",1,1024,u.h+1),spacing:O("spacing",0,64,1),advances:{}},B=H*u.w,K=G*u.h,b=u.w,v=u.h,J=` chars=${L$(Y)} cols=${H} baseline=${E.baseline} line=${E.line} spacing=${E.spacing}`}const D=z?`new map ${r.v} ${u.w}x${u.h}${J} palette=${w.name}`:i==="font"?`new font ${r.v} ${u.w}x${u.h} palette=${w.name} wrap=off cell=${b}x${v} bg=${j.name}${J}`:`new ${i} ${r.v} ${u.w}x${u.h}${J} palette=${w.name} wrap=${x?"on":"off"} cell=${b}x${v} bg=${j.name}`;return{text:d>=2?`${D} <<
|
|
16
|
+
${va(k$(w))}>>`:D,op:{k:"new",kind:i,name:r.v,width:B,height:K,cellW:b,cellH:v,wrap:x,palette:w,bg:j.index,...A?{family:A}:{},...z?{map:z}:{},...E?{font:E}:{},...i==="overlay"?{overlay:L_()}:{}}}}},Q_={name:"px",summary:"px <x,y> [<x,y> ...] c=<colour>",normalise(t,a){const s=at(t,a),l=new _e(t,["c"]),i=l.cellOrigin(s),r=[];r.push(Cn(l.take("point","a point x,y")));for(const u of l.rest()){if(u.t!=="point")throw new C(u.line,u.col,"px: expected a point x,y");r.push(Cn(u))}const f=sl(l,s);return{text:`px${i.text} ${r.map(xa).join(" ")} c=${f.name}`,op:nl(Ph(r,i.dx,i.dy),f.index)}}},V_={name:"line",summary:"line <x,y> <x,y> [<x,y> ...] c=<colour> [pp=on|off]",normalise(t,a){const s=at(t,a),l=new _e(t,["c","pp"]),i=l.cellOrigin(s),r=[Cn(l.take("point","a start point x,y")),Cn(l.take("point","an end point x,y"))];for(const h of l.rest()){if(h.t!=="point")throw new C(h.line,h.col,"line: expected a point x,y");r.push(Cn(h))}const f=sl(l,s),u=l.choice("pp",["on","off"],"on");return{text:`line${i.text} ${r.map(xa).join(" ")} c=${f.name} pp=${u}`,op:nl(R0(Ph(r,i.dx,i.dy),u==="on"),f.index)}}},K_={name:"rect",summary:"rect <x,y> <W>x<H> c=<colour> [outline|fill]",normalise(t,a){const s=at(t,a),l=new _e(t,["c"],["outline","fill"]),i=l.cellOrigin(s),r=l.take("point","a corner x,y"),f=l.take("size","a size WxH");if(l.done(),f.w<1||f.h<1)throw new C(f.line,f.col,"rect: size must be at least 1x1");const u=sl(l,s),h=l.flag(["outline","fill"],"outline");return{text:`rect${i.text} ${r.x},${r.y} ${f.w}x${f.h} c=${u.name} ${h}`,op:nl(si(r.x+i.dx,r.y+i.dy,f.w,f.h,h==="fill"),u.index,h==="outline")}}},J_={name:"ellipse",summary:"ellipse <cx,cy> r=<RX>x<RY>|r=<R> c=<colour> [outline|fill] or ellipse <x,y> <W>x<H> c=<colour> [outline|fill]",normalise(t,a){const s=at(t,a),l=new _e(t,["c","r"],["outline","fill"]),i=l.cellOrigin(s),r=l.take("point","a centre x,y (with r=) or a corner x,y (with a size)"),f=l.opts.get("r");let u,h;if(f){const w=/^(\d+)(?:x(\d+))?$/.exec(f.value);if(!w)throw new C(f.line,f.vcol,"r= must be a radius like 5 or 5x3");const x=Number(w[1]),b=Number(w[2]??w[1]);l.done(),u=[r.x-x,r.y-b,r.x+x,r.y+b],h=`${r.x},${r.y} r=${x}x${b}`}else{const w=l.take("size","a size WxH (or r=<radius>)");if(l.done(),w.w<1||w.h<1)throw new C(w.line,w.col,"ellipse: size must be at least 1x1");u=[r.x,r.y,r.x+w.w-1,r.y+w.h-1],h=`${r.x},${r.y} ${w.w}x${w.h}`}const d=sl(l,s),p=l.flag(["outline","fill"],"outline"),y=ic(u[0]+i.dx,u[1]+i.dy,u[2]+i.dx,u[3]+i.dy,p==="fill");return{text:`ellipse${i.text} ${h} c=${d.name} ${p}`,op:nl(y,d.index,p==="outline")}}},W_={name:"fill",summary:"fill <x,y> c=<colour> [mode=contiguous|global] [conn=4|8]",normalise(t,a){const s=at(t,a),l=new _e(t,["c","mode","conn"]),i=l.cellOrigin(s),r=l.take("point","a start point x,y");l.done();const f=r.x+i.dx,u=r.y+i.dy;if(!s.wrap&&(f<0||u<0||f>=s.width||u>=s.height))throw new C(r.line,r.col,`fill: ${r.x},${r.y} is outside the ${s.width}x${s.height} canvas`);const h=sl(l,s),d=l.choice("mode",["contiguous","global"],"contiguous"),p=l.choice("conn",["4","8"],"4");return{text:`fill${i.text} ${r.x},${r.y} c=${h.name} mode=${d} conn=${p}`,op:ve((y,w)=>{for(const[x,b]of Fh(y,w,[[f,u]]))H0(wn(y,w),x,b,h.index,d==="global",p==="8"?8:4)})}}},I_={name:"paint",summary:"paint <x,y> << rows of palette keys ('.' leaves a pixel, ' ' clears it) >>",normalise(t,a){const s=at(t,a),l=new _e(t,[]),i=l.cellOrigin(s),r=l.take("point","a top-left corner x,y"),f=l.take("block","a block: '<<' at the end of the line, rows, then '>>'");l.done();const u=new Map(s.palette.entries.map((w,x)=>[w.key,x])),h=f.rows.map(w=>[...w.text].map((x,b)=>{if(x===".")return null;if(x===" ")return ne;const v=u.get(x);if(v===void 0)throw new C(w.line,w.col+b,`paint: '${x}' is not a key in palette '${s.palette.name}'`);return v})),d=r.x+i.dx,p=r.y+i.dy,y=[];return h.forEach((w,x)=>w.forEach((b,v)=>{b!==null&&y.push([d+v,p+x,b])})),{text:`paint${i.text} ${r.x},${r.y} <<
|
|
17
|
+
${va(f.rows.map(w=>w.text))}>>`,op:ve((w,x)=>Fn(w,x,y,!0))}}};function va(t){const a=t.some(s=>s.startsWith(" ")||s.endsWith(" ")||s.trim()===">>");return t.map(s=>a?` |${s}|
|
|
18
|
+
`:s===""?`
|
|
19
|
+
`:` ${s}
|
|
20
|
+
`).join("")}const F_={name:"undo",summary:"undo [group=<group>] [by=<author>] (default: the latest group still in effect, or that author's latest)",normalise(t,a){Qe(t,a);const s=new _e(t,["group","by"]);s.done();const l=s.opts.get("group"),i=s.opts.get("by");if(l&&i)throw new C(i.line,i.col,"undo: give group= or by=, not both");const r=a.undoTarget(l?.value??null,i?.value??null),f=l??i;if("error"in r)throw new C(f?.line??t.line,f?.vcol??t.col,r.error);return{text:`undo group=${r.group}`,op:{k:"undo",group:r.group}}}},P_={name:"redo",summary:"redo [group=<undo group>] [by=<author>] (takes back an undo: the latest one still in effect, or that author's)",normalise(t,a){Qe(t,a);const s=new _e(t,["group","by"]);s.done();const l=s.opts.get("group"),i=s.opts.get("by");if(l&&i)throw new C(i.line,i.col,"redo: give group= or by=, not both");const r=a.redoTarget(l?.value??null,i?.value??null),f=l??i;if("error"in r)throw new C(f?.line??t.line,f?.vcol??t.col,r.error);return{text:`redo group=${r.group}`,op:{k:"undo",group:r.group}}}},lh=["pencil","eraser"],ej={name:"stroke",summary:"stroke pencil c=<colour> [pp=on|off] <x,y> [<x,y> ...] or stroke eraser <x,y> [<x,y> ...] (one drag of a tool)",normalise(t,a){const s=at(t,a),l=new _e(t,["c","pp"]),i=l.cellOrigin(s),r=l.take("word",`a tool (${lh.join(", ")})`);if(!lh.includes(r.v))throw new C(r.line,r.col,`stroke: unknown tool '${r.v}' (tools: ${lh.join(", ")})`);const f=[],u=l.rest();if(!u.length)throw new C(r.line,r.col+r.v.length+1,"stroke: expected a point x,y");for(const y of u){if(y.t!=="point")throw new C(y.line,y.col,"stroke: expected a point x,y");f.push(Cn(y))}const h=Ph(f,i.dx,i.dy);if(r.v==="eraser"){for(const y of["c","pp"]){const w=l.opts.get(y);if(w)throw new C(w.line,w.col,`stroke eraser takes no ${y}=`)}return{text:`stroke${i.text} eraser ${f.map(xa).join(" ")}`,op:nl(Wr(h,!1),ne)}}const d=sl(l,s),p=l.choice("pp",["on","off"],"on");return{text:`stroke${i.text} pencil c=${d.name} pp=${p} ${f.map(xa).join(" ")}`,op:nl(Wr(h,p==="on"),d.index)}}},tj={name:"palette",summary:"palette set <entry> [hex=#rrggbb] [role=<role>|none] | palette add [<name>] hex=#rrggbb|role=<role> [key=<k>] | palette lock | palette unlock | palette save as=<name>",normalise(t,a){const s=Qe(t,a),l=new _e(t,["hex","key","as","role"]),i=l.take("word","set, add, lock, unlock or save");if(i.v==="lock"||i.v==="unlock"){l.done();for(const N of l.opts.values())throw new C(N.line,N.col,`palette ${i.v} takes no options`);const j=i.v==="lock";return{text:`palette ${i.v}`,op:ve(N=>{N.paletteLocked=j})}}if(i.v==="save"){l.done();const j=l.opts.get("as");if(!j)throw new C(t.line,t.col,"palette save: missing as=<palette name> (the project palette to write)");if(!/^[A-Za-z][A-Za-z0-9_-]*$/.test(j.value))throw new C(j.line,j.vcol,"as= must be a palette name (letters, digits, _ and -)");for(const N of["hex","key","role"]){const M=l.opts.get(N);if(M)throw new C(M.line,M.col,`palette save takes no ${N}=`)}return{text:`palette save as=${j.value}`,op:ve(()=>{})}}if(i.v!=="set"&&i.v!=="add")throw new C(i.line,i.col,"palette: expected set, add, lock, unlock or save");if(s.paletteLocked)throw new C(i.line,i.col,`palette '${s.palette.name}' is locked (palette unlock to change it)`);const r=l.opts.get("as");if(r)throw new C(r.line,r.col,`palette ${i.v} takes no as=`);const f=l.opts.get("hex"),u=l.opts.get("role");let h=null;if(f&&(h=$0(f.value),!h||!f.value.startsWith("#")))throw new C(f.line,f.vcol,"hex= must be a colour like #a4552e");if(u&&!Ah(u.value)&&!(i.v==="set"&&u.value==="none"))throw new C(u.line,u.vcol,`role= must be one of ${Un.join(", ")}${i.v==="set"?" or none":""}`);const d=s.palette;if(i.v==="set"){if(!f&&!u)throw new C(t.line,t.col,"palette set: missing hex=#rrggbb (or role=)");const j=l.peek()?.t==="int"?(E=>({...E,v:String(E.v)}))(l.take("int","an entry")):l.take("word","an entry name or key");l.done();const N=l.opts.get("key");if(N)throw new C(N.line,N.col,"palette set changes a colour only; keys stay");const M=d.entries.findIndex(E=>E.name===j.v||[...j.v].length===1&&E.key===j.v);if(M<0)throw new C(j.line,j.col,`palette '${d.name}' has no entry '${j.v}'`);const A=d.entries.map((E,R)=>{if(R!==M)return E;const B={key:E.key,name:E.name,hex:h??E.hex},K=u?u.value:E.role;return K&&K!=="none"?{...B,role:K}:B});return{text:`palette set ${d.entries[M].name}${h?` hex=${h}`:""}${u?` role=${u.value}`:""}`,op:ve(E=>{E.palette={...d,entries:A}})}}if(d.entries.length>=256)throw new C(i.line,i.col,`palette '${d.name}' is full (256 entries)`);if(!h&&!u)throw new C(t.line,t.col,"palette add: missing hex=#rrggbb (or role=)");const p=u?u.value:void 0;h??=k0[p];const y=new Set(d.entries.map(j=>j.name)),w=new Set(d.entries.map(j=>j.key)),x=l.peek()?.t==="word"?l.take("word","a name"):null;l.done();let b;if(x){if(b=x.v,!/^[A-Za-z][A-Za-z0-9_-]*$/.test(b)||b==="none")throw new C(x.line,x.col,`'${b}' is not a usable entry name`);if(y.has(b))throw new C(x.line,x.col,`palette '${d.name}' already has an entry '${b}'`)}else{let j=d.entries.length;for(;y.has(`c${j}`);)j++;b=`c${j}`}const v=l.opts.get("key");let $;if(v){if($=v.value,[...$].length!==1||b0.has($)||/\s/.test($)||$==='"'||$===";")throw new C(v.line,v.vcol,'key= must be one character other than . | ; " and space');if(w.has($))throw new C(v.line,v.vcol,`key '${$}' is taken`)}else $=$$(512).find(j=>!w.has(j)&&j!=='"'&&j!==";");const _=[...d.entries,p?{key:$,name:b,hex:h,role:p}:{key:$,name:b,hex:h}];return{text:`palette add ${b} hex=${h} key=${$}${p?` role=${p}`:""}`,op:ve(j=>{j.palette={...d,entries:_}})}}},nj=/^n[1-9]\d*$/,aj={name:"note",summary:'note <x,y> [<W>x<H>] "text" (pins a note to a pixel or a region) or note done <id>',normalise(t,a){const s=Qe(t,a),l=new _e(t,["id"]),i=l.peek();if(i?.t==="word"&&i.v==="done"){l.take("word","done");const x=l.take("word","a note id like n1");if(l.done(),!s.notes.some(b=>b.id===x.v))throw new C(x.line,x.col,`no open note '${x.v}'${s.notes.length?` (open: ${s.notes.map(b=>b.id).join(", ")})`:""}`);return{text:`note done ${x.v}`,op:ve(b=>{b.notes=b.notes.filter(v=>v.id!==x.v)})}}const r=l.take("point","a point x,y (or done <id>)"),f=l.peek()?.t==="size"?l.take("size","a size WxH"):null,u=l.take("string","the note text in quotes");l.done();const h=f?.w??1,d=f?.h??1;if(h<1||d<1)throw new C(f.line,f.col,"note: size must be at least 1x1");if(r.x<0||r.y<0||r.x+h>s.width||r.y+d>s.height)throw new C(r.line,r.col,`note: ${r.x},${r.y}${f?` ${h}x${d}`:""} is outside the ${s.width}x${s.height} canvas`);const p=u.v.trim();if(!p)throw new C(u.line,u.col,"note: the text is empty");if(p.length>1e3)throw new C(u.line,u.col,"note: the text is longer than 1000 characters");const y=l.opts.get("id"),w=y?.value??a.noteId();if(!nj.test(w))throw new C(y.line,y.vcol,"id= must look like n1");if(s.notes.some(x=>x.id===w))throw new C(y?.line??t.line,y?.vcol??t.col,`note '${w}' is already open`);return{text:`note ${r.x},${r.y}${f?` ${h}x${d}`:""} ${wa(p)} id=${w}`,op:ve(x=>{x.notes=[...x.notes,{id:w,x:r.x,y:r.y,w:h,h:d,text:p}]})}}},lj={name:"fork",summary:"fork <from> <to> [at=<seq>] (starts the tape of asset <to> as a copy of <from> up to command <seq>)",normalise(t,a){const s=Qe(t,a),l=new _e(t,["at"]),i=l.take("word","the asset forked from"),r=l.take("word","the new asset's name");if(l.done(),s.name!==i.v)throw new C(i.line,i.col,`fork: this tape is '${s.name}', not '${i.v}'`);if(!/^[a-z][a-z0-9_-]*$/.test(r.v))throw new C(r.line,r.col,"document names use a-z, 0-9, _ and -, starting with a letter");if(r.v===i.v)throw new C(r.line,r.col,"fork: the new asset needs another name");const f=l.opts.get("at"),u=f?Number(f.value):a.seq-1;if(!Number.isInteger(u)||u!==a.seq-1)throw new C(f?.line??t.line,f?.vcol??t.col,`fork: at=${f?.value} must be the command just before this one (#${a.seq-1})`);return{text:`fork ${i.v} ${r.v} at=${u}`,op:{k:"fork",name:r.v}}}};function Cn(t){return[t.x,t.y]}function xa(t){return`${t[0]},${t[1]}`}const Ds=new Map;function Le(t){Ds.set(t.name,t)}for(const t of[Z_,Q_,V_,K_,J_,W_,I_,ej,tj,aj,lj,F_,P_])Le(t);function Fo(t,a){const s=Ds.get(t.name);if(!s)throw new C(t.line,t.col,`unknown command '${t.name}' (commands: ${[...Ds.keys()].join(", ")})`);return s.normalise(t,a)}function Po(t,a,s=""){if(a.k==="new"){const l=m$(a);return yw(l),l}if(!t)throw new Error("applyOp: no document");if(a.k==="fork")t.name=a.name;else if(a.k==="fn")a.run(t,s),t.views.length&&U$(t),t.family&&yw(t);else throw new Error("applyOp: undo is applied by replay");return t}const $h=(t,a)=>a?$h(a,t%a):t;function rv(t,a){const s=new Set(t.map(h=>h.name)),l=a.assetNames?.()??[],i=t.map(h=>[h.name,...l.filter(d=>d!==h.name&&!s.has(d)&&a.asset?.(d)?.variantOf===h.name&&a.asset?.(d)?.kind==="tile").sort()]),r=i.reduce((h,d)=>h*d.length/$h(h,d.length),1),f=[];i.forEach((h,d)=>{for(const p of h)f.some(y=>y.name===p)||f.push({name:p,weight:t[d].weight*r/h.length})});const u=f.reduce((h,d)=>$h(h,d.weight),0)||1;return f.map(h=>({name:h.name,weight:h.weight/u}))}function cv(t){const a=[];for(const s of t.value.split(",")){const l=/^([a-z][a-z0-9_-]*)(?::(\d+))?$/.exec(s);if(!l)throw new C(t.line,t.vcol,`mix= is a list of one-cell tiles with weights: mix=<tile>:<weight>,<tile>:<weight>,... ('${s}' is not <tile> or <tile>:<weight>)`);const i=l[2]===void 0?1:Number(l[2]);if(i<1||i>1e3)throw new C(t.line,t.vcol,`mix=: ${l[1]}'s weight must be 1..1000`);if(a.some(r=>r.name===l[1]))throw new C(t.line,t.vcol,`mix=: ${l[1]} is named twice`);a.push({name:l[1],weight:i})}if(a.length>64)throw new C(t.line,t.vcol,"mix=: at most 64 tiles");return a}function sj(t,a){const s=t.opts.get("seed");if(!s)return a.newSeed();if(!/^\d+$/.test(s.value)||Number(s.value)<1||Number(s.value)>2147483647)throw new C(s.line,s.vcol,"seed= must be a whole number 1..2147483647");return Number(s.value)}const oj=/^[A-Za-z][A-Za-z0-9_-]*$/,uv=new Set(["add","set","remove","rename","move","merge"]),ij=t=>t?"on":"off";function ww(t,a){const s=t.layers.findIndex(l=>l.name===a.v);if(s<0)throw new C(a.line,a.col,`no layer '${a.v}' (layers: ${t.layers.map(l=>l.name).join(", ")})`);return s}function vw(t,a){if(!oj.test(a.v)||uv.has(a.v))throw new C(a.line,a.col,`'${a.v}' is not a usable layer name`);if(t.layers.some(s=>s.name===a.v))throw new C(a.line,a.col,`there is already a layer '${a.v}'`)}function xw(t,a){const s=new Map(a.map((l,i)=>[l,i]));t.layers=a.map(l=>t.layers[l]),t.cels=a.map(l=>t.cels[l]),Dl(t,l=>s.get(l)??0,l=>l)}function bw(t,a,s){const l=t.opts.get("above"),i=t.opts.get("below");if(l&&i)throw new C(i.line,i.col,"give above= or below=, not both");const r=l??i,f=r?.value??s,u=a.layers.findIndex(h=>h.name===f);if(u<0)throw new C(r?.line??t.cmd.line,r?.vcol??t.cmd.col,`no layer '${f}'`);return i?{at:u,text:`below=${f}`}:{at:u+1,text:`above=${f}`}}function rj(t){const a={};for(const s of["hidden","locked","reference"])t.opts.has(s)&&(a[s]=t.choice(s,["on","off"],"off")==="on");return a}const cj={name:"layer",summary:"layer <name> | layer add <name> [above=|below=<layer>] [reference] | (maps) layer add <name> terrain=<family> [outside=on|off] [walkable=on|off] [border=same|terrain|not] [mix=<tile>:<weight>,... [variants=spread|named] [seed=]] | tiles | objects [shadow=darker|<colour>|off] [shadowdir=<dir>] | overlay=<overlay> on=<layer>|<layer>:out|all | layer set <name> [hidden=] [locked=] [reference=] [walkable=] [border=] [mix=…|none] [shadow=darker|<colour>|off [shadowdir=]] | layer rename <name> <new> | layer move <name> above=|below=<layer> | layer merge <name> | layer remove <name> (border: past the map's edge a cell counts as its own (same, the default), as terrain, or not; mix: the terrain's inside cells drawn as a seeded scatter of one-cell tiles by weight)",normalise(t,a){const s=Qe(t,a),l=t.args[0],i=!!s.map&&l?.t==="word"&&l.v==="add",r=new _e(t,["above","below","hidden","locked","reference","terrain","outside","walkable","overlay","on","border","mix","seed","variants","shadow","shadowdir"],i?["reference","tiles","objects"]:["reference"]),f=r.take("word","a layer name, or add, set, rename, move, merge or remove"),u=(p=[])=>{for(const y of r.opts.values())if(!p.includes(y.key))throw new C(y.line,y.col,`layer ${f.v} takes no ${y.key}=`);if(!p.includes("flag")&&r.flags.length)throw new C(r.flags[0].line,r.flags[0].col,`layer ${f.v}: unexpected '${r.flags[0].v}'`)};if(!uv.has(f.v)){r.done(),u();const p=ww(s,f);return{text:`layer ${f.v}`,op:ve((y,w)=>Zt(y,w,{layer:p}))}}if(f.v==="add"){const p=r.take("word","a name for the new layer");if(r.done(),vw(s,p),s.map&&(p.v==="tiles"||p.v==="objects"))throw new C(p.line,p.col,`'${p.v}' says what a map layer holds; name the layer something else (layer add props objects)`);let y,w="";s.map?(y=uj(r,s,a),w=fj(y),u(["above","below","flag","terrain","outside","walkable","overlay","on","border","mix","seed","variants","shadow","shadowdir"])):u(["above","below","flag"]);const x=bw(r,s,s.layers[et(s,a.by).layer].name),b=!s.map&&r.flags.length>0;return{text:`layer add ${p.v}${w} ${x.text}${b?" reference":""}`,op:ve(v=>{const $=v.width*v.height,_=v.layers.map((j,N)=>N);v.layers.push(zl(p.v,{reference:b,...y?{map:y}:{}})),v.cels.push(Array.from({length:v.frameCount},()=>new Uint16Array($).fill(ne))),_.splice(x.at,0,v.layers.length-1),xw(v,_)})}}const h=r.take("word","a layer name"),d=ww(s,h);if(f.v==="set"){if(r.done(),r.opts.get("shadow")||r.opts.get("shadowdir")){const v=r.opts.get("shadow")??r.opts.get("shadowdir");if(s.layers[d].map?.kind!=="objects")throw new C(v.line,v.col,`${v.key}= goes with an objects layer`);u(["shadow","shadowdir"]);const $=s.layers[d].map.shadow,_=fv(r,s,a,$);return{text:`layer set ${h.v} ${_?`shadow=${_.c} shadowdir=${_.dir}`:"shadow=off"}`,op:ve(j=>{j.layers[d].map=_?{kind:"objects",shadow:_}:{kind:"objects"}})}}const p=r.opts.get("walkable"),y=r.opts.get("border"),w=r.opts.get("mix");if(p||y||w){const v=s.layers[d].map,$=p??y??w;if(v?.kind!=="terrain")throw new C($.line,$.col,`${$.key}= goes with a terrain layer`);u(["walkable","border","mix","seed","variants"]);const _={},j=[];if(p){const M=r.choice("walkable",["on","off"],"off")==="on";_.walkable=M,j.push(`walkable=${M?"on":"off"}`)}if(y){const M=hv(r);_.border=M,j.push(`border=${M??"same"}`)}let N=!1;if(w)if(w.value==="none"){N=!0,j.push("mix=none");for(const M of["seed","variants"])if(r.opts.get(M))throw new C(r.opts.get(M).line,r.opts.get(M).col,`${M}= goes with a mix`)}else{const M=dv(r,a);_.mix=M.mix,_.seed=M.seed,j.push(M.text)}else for(const M of["seed","variants"])if(r.opts.get(M))throw new C(r.opts.get(M).line,r.opts.get(M).col,`${M}= goes with mix=`);return{text:`layer set ${h.v} ${j.join(" ")}`,op:ve(M=>{const A={...M.layers[d].map,..._};A.walkable||delete A.walkable,A.border||delete A.border,N&&(delete A.mix,delete A.seed),M.layers[d].map=A})}}u(["hidden","locked","reference"]);const x=rj(r);if(!Object.keys(x).length)throw new C(t.line,t.col,"layer set: give hidden=, locked= or reference= (on or off)");const b=["hidden","locked","reference"].flatMap(v=>x[v]===void 0?[]:[`${v}=${ij(x[v])}`]);return{text:`layer set ${h.v} ${b.join(" ")}`,op:ve(v=>{Object.assign(v.layers[d],x)})}}if(f.v==="rename"){const p=r.take("word","the new name");return r.done(),u(),vw(s,p),{text:`layer rename ${h.v} ${p.v}`,op:ve(y=>{y.layers[d].name=p.v})}}if(f.v==="move"){if(r.done(),u(["above","below"]),!r.opts.has("above")&&!r.opts.has("below"))throw new C(t.line,t.col,"layer move: give above=<layer> or below=<layer>");const p=bw(r,s,""),y=r.opts.get("above")??r.opts.get("below");if(y.value===h.v)throw new C(y.line,y.vcol,"layer move: a layer cannot move relative to itself");return{text:`layer move ${h.v} ${p.text}`,op:ve(w=>{const x=w.layers.map((b,v)=>v);x.splice(p.at,0,d),x.splice(p.at<=d?d+1:d,1),xw(w,x)})}}if(f.v==="merge"){if(r.done(),u(),s.map)throw new C(f.line,f.col,"layer merge: a map's layers hold different things; move or remove them instead");if(d===0)throw new C(h.line,h.col,`layer merge: '${h.v}' is the bottom layer; there is nothing below to merge into`);const p=s.layers[d-1];if(p.locked)throw new C(h.line,h.col,`layer merge: '${p.name}' below is locked`);return{text:`layer merge ${h.v}`,op:ve(y=>{y.cels[d-1]=y.cels[d-1].map(w=>w.slice());for(let w=0;w<y.frameCount;w++){const x=y.cels[d][w],b=y.cels[d-1][w];for(let v=0;v<x.length;v++)x[v]!==ne&&(b[v]=x[v])}$w(y,d)})}}if(r.done(),u(),s.layers.length===1)throw new C(h.line,h.col,`layer remove: '${h.v}' is the only layer`);return{text:`layer remove ${h.v}`,op:ve(p=>$w(p,d))}}};function fv(t,a,s,l){const i=t.opts.get("shadow"),r=s.defaults?.shadow,f=i?i.value:l?.c??r?.c;if(!f||f==="off"){if(t.opts.get("shadowdir")&&f==="off")throw new C(t.opts.get("shadowdir").line,t.opts.get("shadowdir").col,"shadowdir= goes with a shadow");return}const u=f==="darker"?f:an(f,a.palette,i?.line??t.cmd.line,i?.vcol??t.cmd.col).name,h=t.choice("shadowdir",Fr,l?.dir??(r?.dir&&Fr.includes(r.dir)?r.dir:L0(s.defaults?.light)));return{c:u,dir:h}}function hv(t){const a=t.choice("border",["same","terrain","not"],"same");return a==="same"?void 0:a}function dv(t,a){const s=t.opts.get("mix");if(!s)return null;const l=t.opts.get("variants");if(l&&l.value!=="spread"&&l.value!=="named")throw new C(l.line,l.vcol,"variants= is spread (a tile's weight shared with its texture variants) or named (only the tiles the mix names)");const i=cv(s),r=l?.value==="named"?i:rv(i,a);for(const u of r){const h=a.asset?.(u.name);if(h&&h.kind!=="tile")throw new C(s.line,s.vcol,`mix= takes one-cell tiles; '${u.name}' is a ${h.kind}`)}const f=sj(t,a);return{mix:r,seed:f,text:`mix=${r.map(u=>`${u.name}:${u.weight}`).join(",")} variants=named seed=${f}`}}function uj(t,a,s){const l=t.opts.get("terrain"),i=t.opts.get("overlay"),r=[l?"terrain":"",i?"overlay":"",...t.flags.filter(h=>h.v==="tiles"||h.v==="objects").map(h=>h.v)].filter(Boolean);if(r.length!==1)throw new C(t.cmd.line,t.cmd.col,"layer add: a map layer holds one thing: terrain=<family>, tiles, objects or overlay=<overlay> on=<where>");const f=t.flags.find(h=>h.v==="reference");if(f)throw new C(f.line,f.col,"layer add: a map has no reference layers");const u=(h,d)=>{if(!/^[a-z][a-z0-9_-]*$/.test(h))throw new C(d.line,d.vcol,`'${h}' is not an asset name`);return h};for(const h of["shadow","shadowdir"]){const d=t.opts.get(h);if(d&&!t.flags.some(p=>p.v==="objects"))throw new C(d.line,d.col,`${h}= goes with objects`)}for(const h of["outside","walkable","on","border","mix"]){const d=t.opts.get(h);if(d&&!(h!=="on"&&l||h==="on"&&i))throw new C(d.line,d.col,`${h}= goes with ${h!=="on"?"terrain=":"overlay="}`)}for(const h of["seed","variants"])if(t.opts.get(h)&&!t.opts.get("mix"))throw new C(t.opts.get(h).line,t.opts.get(h).col,`${h}= goes with mix=`);if(l){const h=t.choice("walkable",["on","off"],"off")==="on",d=hv(t),p=dv(t,s);return{kind:"terrain",family:u(l.value,l),outside:t.choice("outside",["on","off"],"off")==="on",...h?{walkable:h}:{},...d?{border:d}:{},...p?{mix:p.mix,seed:p.seed}:{}}}if(i){const h=t.opts.get("on"),d=h?.value??"all",[p,y]=d.split(":");if(d!=="all"&&(!a.layers.some(w=>w.name===p&&w.map?.kind==="terrain")||y!==void 0&&y!=="out"))throw new C(h.line,h.vcol,`on= must be all, a terrain layer, or a terrain layer:out (terrain layers: ${a.layers.filter(w=>w.map?.kind==="terrain").map(w=>w.name).join(", ")||"none"})`);return{kind:"overlay",overlay:u(i.value,i),on:d}}if(r[0]==="objects"){const h=fv(t,a,s);return h?{kind:"objects",shadow:h}:{kind:"objects"}}return{kind:"tiles"}}function fj(t){return t.kind==="terrain"?` terrain=${t.family} outside=${t.outside?"on":"off"}${t.walkable?" walkable=on":""}${t.border?` border=${t.border}`:""}`+(t.mix?` mix=${t.mix.map(a=>`${a.name}:${a.weight}`).join(",")} variants=named seed=${t.seed}`:""):t.kind==="overlay"?` overlay=${t.overlay} on=${t.on}`:t.kind==="objects"&&t.shadow?` objects shadow=${t.shadow.c} shadowdir=${t.shadow.dir}`:` ${t.kind}`}function $w(t,a){t.layers.splice(a,1),t.cels.splice(a,1),Dl(t,s=>s>a?s-1:s===a?Math.max(0,a-1):s,s=>s)}const hj=new Set(["add","remove","move","set"]);function sh(t,a,s,l,i=t.frameCount){if(!a||a.t!=="int")throw new C(a?.line??s.line,a?.col??s.col,`frame: expected ${l}`);if(a.v<1||a.v>i)throw new C(a.line,a.col,`frame ${a.v} does not exist (frames 1..${t.frameCount})`);return a.v}function oh(t,a,s=t.frameCount){if(!/^\d+$/.test(a.value)||Number(a.value)<1||Number(a.value)>s)throw new C(a.line,a.vcol,`${a.key}= must be a frame 1..${s}`);return Number(a.value)}function hc(t,a,s){const l=()=>new C(a?.line??s.line,a?.col??s.col,`${s.name}: expected frames as <n>, <a>-<b> or all (frames 1..${t.frameCount})`);if(!a)throw l();let i,r;if(a.t==="int")i=r=a.v;else if(a.t==="word"&&a.v==="all")i=1,r=t.frameCount;else if(a.t==="word"&&/^\d+-\d+$/.test(a.v))[i,r]=a.v.split("-").map(Number);else throw l();if(i<1||r>t.frameCount||i>r)throw new C(a.line,a.col,`${s.name}: frames ${i}-${r} are not within 1..${t.frameCount}`);return{from:i,to:r,text:i===r?String(i):`${i}-${r}`}}function kw(t){if(!/^\d+$/.test(t.value)||Number(t.value)<1||Number(t.value)>65535)throw new C(t.line,t.vcol,"ticks= must be a whole number 1..65535");return Number(t.value)}function Yr(t,a,s,l){const i=Vo(t,a);if(i?.mirror)throw new C(s.line,s.col,`${l}: frame ${a+1} is in view ${i.name}, a live mirror of ${i.mirror} (change ${i.mirror}, or view ${i.name} mirror=off)`)}const dj={name:"frame",summary:"frame <n> | frame add [<n>] [copy=<m>|link=<m>|empty] [ticks=<t>] | frame set <n>|<a>-<b>|all ticks=<t> | frame remove <n> | frame move <n> to=<m> (frames count from 1; ticks are game ticks)",normalise(t,a){const s=Qe(t,a),l=new _e(t,["copy","to","link","ticks"],["empty"]),i=l.peek(),r=(y,w=[])=>{for(const x of l.opts.values())if(!w.includes(x.key))throw new C(x.line,x.col,`${y} takes no ${x.key}=`)};if(i?.t==="int"){const y=sh(s,l.take("int","a frame number"),t,"a frame number");return l.done(),r("frame <n>"),{text:`frame ${y}`,op:ve((w,x)=>Zt(w,x,{frame:y-1}))}}const f=l.take("word","a frame number, or add, set, remove or move");if(!hj.has(f.v))throw new C(f.line,f.col,"frame: expected a frame number, add, set, remove or move");if(f.v==="set"){const y=hc(s,l.rest()[0],t);if(r("frame set",["ticks"]),l.flags.length)throw new C(l.flags[0].line,l.flags[0].col,`frame set: unexpected '${l.flags[0].v}'`);const w=l.opts.get("ticks");if(!w)throw new C(t.line,t.col,"frame set: give ticks=<t>");const x=kw(w),b=v=>!Vo(s,v)?.mirror;return y.from===y.to&&Yr(s,y.from-1,t,"frame set"),{text:`frame set ${y.text} ticks=${x}`,op:ve(v=>{for(let $=y.from-1;$<y.to;$++)b($)&&(v.ticks[$]=x)})}}if(f.v==="add"){const y=l.peek()?.t==="int"?sh(s,l.take("int","a position"),t,"a position",s.frameCount+1):s.frameCount+1;l.done(),r("frame add",["copy","link","ticks"]);const w=l.opts.get("copy"),x=l.opts.get("link"),b=l.flags.length>0;if([w,x,b||void 0].filter(Boolean).length>1)throw new C(t.line,t.col,"frame add: give one of copy=, link= or empty");const v=x?oh(s,x):w?oh(s,w):et(s,a.by).frame+1;x&&Yr(s,v-1,x,"frame add link=");const $=l.opts.get("ticks"),_=$?kw($):null,j=x?`link=${v}`:b?"empty":`copy=${v}`;return{text:`frame add ${y} ${j}${_!==null?` ticks=${_}`:""}`,op:ve(N=>{const M=N.width*N.height,A=z=>b?new Uint16Array(M).fill(ne):x?N.cels[z][v-1]:N.cels[z][v-1].slice();qh(N,y-1,1,A,[_??N.ticks[v-1]])})}}const u=sh(s,l.take("int","a frame number"),t,"a frame number");if(f.v==="remove"){if(l.done(),r("frame remove"),s.frameCount===1)throw new C(t.line,t.col,"frame remove: frame 1 is the only frame");return Yr(s,u-1,t,"frame remove"),{text:`frame remove ${u}`,op:ve(y=>_0(y,u-1))}}l.done(),r("frame move",["to"]);const h=l.opts.get("to");if(!h)throw new C(t.line,t.col,"frame move: missing to=<n>");const d=oh(s,h),p=j0(u-1,d-1);for(const y of s.views){const w=Array.from({length:y.to-y.from+1},(b,v)=>p(y.from+v)),x=Math.min(...w);if(Math.max(...w)-x!==w.length-1)throw new C(h.line,h.vcol,`frame move: view ${y.name} would no longer be one run of frames`)}return Vo(s,u-1)?.mirror&&Yr(s,u-1,t,"frame move"),{text:`frame move ${u} to=${d}`,op:ve(y=>R$(y,u-1,d-1))}}};Le(cj);Le(dj);const _w=["add","sub","and"];function ih(t,a){const s={width:t.width,height:t.height,wrap:t.wrap},l=new Uint8Array(t.width*t.height);for(const[i,r]of a){const f=yn(s,i,r);f>=0&&(l[f]=1)}return l}function mj(t,a,s){let l;if(s==="replace")l=a;else{l=new Uint8Array(a.length);for(let i=0;i<a.length;i++){const r=t?t[i]:0;l[i]=s==="add"?r|a[i]:s==="sub"?r&(a[i]^1):r&a[i]}}return l.some(i=>i)?l:null}function pj(t,a,s,l,i,r){const f={width:t.width,height:t.height,wrap:t.wrap},u=new Uint8Array(a.length),h=yn(f,s,l),d=a[h];if(i){for(let w=0;w<a.length;w++)a[w]===d&&(u[w]=1);return u}const p=r===4?[[1,0],[-1,0],[0,1],[0,-1]]:[[1,0],[-1,0],[0,1],[0,-1],[1,1],[1,-1],[-1,1],[-1,-1]],y=[h];for(u[h]=1;y.length;){const w=y.pop(),x=w%t.width,b=(w-x)/t.width;for(const[v,$]of p){const _=yn(f,x+v,b+$);_>=0&&!u[_]&&a[_]===d&&(u[_]=1,y.push(_))}}return u}const jw="rect, ellipse, lasso, wand, colour, layer, all, none or invert",yj={name:"select",summary:"select rect <x,y> <W>x<H> | ellipse <cx,cy> r=<RX>x<RY> | ellipse <x,y> <W>x<H> | lasso <x,y> <x,y> <x,y>... | wand <x,y> [mode=contiguous|global] [conn=4|8] | colour c=<colour> | layer [<name>] | all | none | invert [add|sub|and]",normalise(t,a){const s=Qe(t,a),l=new _e(t,["r","mode","conn","c"],_w),i=l.cellOrigin(s),r=l.take("word",jw),f=l.flag(_w,"replace"),u=f==="replace"?"":` ${f}`,h=y=>{for(const w of l.opts.values())if(!y.includes(w.key))throw new C(w.line,w.col,`select ${r.v} takes no ${w.key}=`)},d=(y,w)=>({text:`select${i.text} ${y}${u}`,op:ve((x,b)=>Zt(x,b,{sel:mj(et(x,b).sel,w(x,b),f)}))}),p=y=>[y[0]+i.dx,y[1]+i.dy];switch(r.v){case"all":case"none":case"invert":{if(l.done(),h([]),f!=="replace")throw new C(t.line,t.col,`select ${r.v} takes no ${f}`);return r.v==="none"?{text:`select${i.text} none`,op:ve((y,w)=>Zt(y,w,{sel:null}))}:r.v==="all"?{text:`select${i.text} all`,op:ve((y,w)=>Zt(y,w,{sel:new Uint8Array(y.width*y.height).fill(1)}))}:{text:`select${i.text} invert`,op:ve((y,w)=>{const x=et(y,w).sel,b=new Uint8Array(y.width*y.height);for(let v=0;v<b.length;v++)b[v]=x?x[v]^1:1;Zt(y,w,{sel:b.some(v=>v)?b:null})})}}case"rect":{const y=l.take("point","a corner x,y"),w=l.take("size","a size WxH");if(l.done(),h([]),w.w<1||w.h<1)throw new C(w.line,w.col,"select: size must be at least 1x1");const x=ih(s,si(y.x+i.dx,y.y+i.dy,w.w,w.h,!0));return d(`rect ${y.x},${y.y} ${w.w}x${w.h}`,()=>x)}case"ellipse":{const y=l.take("point","a centre x,y (with r=) or a corner x,y (with a size)"),w=l.opts.get("r");h(["r"]);let x,b;if(w){const $=/^(\d+)(?:x(\d+))?$/.exec(w.value);if(!$)throw new C(w.line,w.vcol,"r= must be a radius like 5 or 5x3");const _=Number($[1]),j=Number($[2]??$[1]);l.done(),x=[y.x-_,y.y-j,y.x+_,y.y+j],b=`${y.x},${y.y} r=${_}x${j}`}else{const $=l.take("size","a size WxH (or r=<radius>)");if(l.done(),$.w<1||$.h<1)throw new C($.line,$.col,"select: size must be at least 1x1");x=[y.x,y.y,y.x+$.w-1,y.y+$.h-1],b=`${y.x},${y.y} ${$.w}x${$.h}`}const v=ih(s,ic(x[0]+i.dx,x[1]+i.dy,x[2]+i.dx,x[3]+i.dy,!0));return d(`ellipse ${b}`,()=>v)}case"lasso":{const y=[];for(const x of l.rest()){if(x.t!=="point")throw new C(x.line,x.col,"select lasso: expected a point x,y");y.push(Cn(x))}if(h([]),y.length<3)throw new C(t.line,t.col,"select lasso: give at least 3 points");const w=ih(s,U0(y.map(p),!0,!1));return d(`lasso ${y.map(xa).join(" ")}`,()=>w)}case"wand":{const y=l.take("point","a point x,y");l.done(),h(["mode","conn"]);const w=l.choice("mode",["contiguous","global"],"contiguous"),x=l.choice("conn",["4","8"],"4"),b=y.x+i.dx,v=y.y+i.dy;if(!s.wrap&&(b<0||v<0||b>=s.width||v>=s.height))throw new C(y.line,y.col,`select wand: ${y.x},${y.y} is outside the canvas`);return d(`wand ${y.x},${y.y} mode=${w} conn=${x}`,($,_)=>pj($,wn($,_).pixels,b,v,w==="global",x==="8"?8:4))}case"colour":case"color":{l.done(),h(["c"]);const y=l.opts.get("c");if(!y)throw new C(t.line,t.col,"select colour: missing c=<colour>");const w=an(y.value,s.palette,y.line,y.vcol);return d(`colour c=${w.name}`,(x,b)=>{const v=wn(x,b).pixels;return Uint8Array.from(v,$=>$===w.index?1:0)})}case"layer":{const y=l.peek()?.t==="word"?l.take("word","a layer name"):null;l.done(),h([]);const w=y?s.layers.findIndex(b=>b.name===y.v):et(s,a.by).layer;if(w<0)throw new C(y.line,y.col,`no layer '${y.v}'`);const x=s.layers[w].name;return d(`layer ${x}`,(b,v)=>{const $=b.layers.findIndex(j=>j.name===x),_=b.cels[$][et(b,v).frame];return Uint8Array.from(_,j=>j===ne?0:1)})}default:throw new C(r.line,r.col,`select: '${r.v}' is not a selection (${jw})`)}}},gj={name:"deselect",summary:"deselect (the same as select none)",normalise(t,a){return Qe(t,a),new _e(t,[]).done(),{text:"deselect",op:ve((s,l)=>Zt(s,l,{sel:null}))}}},wj={name:"clear",summary:"clear (clears the selected pixels of your layer, or all of it, to transparent)",normalise(t,a){return at(t,a),new _e(t,[]).done(),{text:"clear",op:ve((s,l)=>{const i=wn(s,l);for(let r=0;r<i.pixels.length;r++)(!i.mask||i.mask[r])&&(i.pixels[r]=ne)})}}};Le(yj);Le(gj);Le(wj);const Sw=(t,a)=>(t%a+a)%a;function dc(t,a){const s=et(t,a).sel;if(!s)return{mask:null,x:0,y:0,w:t.width,h:t.height};let l=t.width,i=t.height,r=-1,f=-1;for(let u=0;u<s.length;u++){if(!s[u])continue;const h=u%t.width,d=(u-h)/t.width;l=Math.min(l,h),r=Math.max(r,h),i=Math.min(i,d),f=Math.max(f,d)}return{mask:s,x:l,y:i,w:r-l+1,h:f-i+1}}function ed(t,a,s){const l=wn(t,a,!1),i=dc(t,a),r=[];for(let u=0;u<l.pixels.length;u++){if(i.mask&&!i.mask[u])continue;const h=u%t.width,d=(u-h)/t.width;r.push([...s(h,d),l.pixels[u]]),l.pixels[u]=ne}const f=i.mask?new Uint8Array(i.mask.length):null;for(const[u,h,d]of r){const p=yn(l,u,h);p<0||(l.pixels[p]=d,f&&(f[p]=1))}i.mask&&Zt(t,a,{sel:f.some(u=>u)?f:null})}function td(t,a,s,l){const i=t.flags.find(f=>f.v==="sel"),r=t.flags.find(f=>f.v==="wrap");if(r&&!l)throw new C(r.line,r.col,`${t.cmd.name}: unexpected 'wrap'`);if(i&&!et(a,s).sel)throw new C(i.line,i.col,`${t.cmd.name} sel: nothing is selected`);return{sel:!!i,wrap:!!r}}const nd=t=>`${t.sel?" sel":""}${t.wrap?" wrap":""}`,vj={name:"shift",summary:"shift <dx,dy> [sel] [wrap] (moves the selected pixels, or your whole layer; wrap: around the selection's box or the canvas)",normalise(t,a){const s=at(t,a),l=new _e(t,[],["sel","wrap"]),i=l.take("point","an offset dx,dy");l.done();const r=td(l,s,a.by,!0);return{text:`shift ${i.x},${i.y}${nd(r)}`,op:ve((f,u)=>{const h=dc(f,u);ed(f,u,r.wrap?(d,p)=>[h.x+Sw(d-h.x+i.x,h.w),h.y+Sw(p-h.y+i.y,h.h)]:(d,p)=>[d+i.x,p+i.y])})}}},xj={name:"flip",summary:"flip h|v [sel] (mirrors the selected pixels within their box, or your whole layer)",normalise(t,a){const s=at(t,a),l=new _e(t,[],["sel"]),i=l.take("word","h or v");if(i.v!=="h"&&i.v!=="v")throw new C(i.line,i.col,"flip: expected h (left-right) or v (top-bottom)");l.done();const r=td(l,s,a.by,!1);return{text:`flip ${i.v}${nd(r)}`,op:ve((f,u)=>{const h=dc(f,u);ed(f,u,i.v==="h"?(d,p)=>[2*h.x+h.w-1-d,p]:(d,p)=>[d,2*h.y+h.h-1-p])})}}},bj={name:"rotate",summary:"rotate 90|180|270 [sel] (clockwise, about the middle of the selection's box or the canvas)",normalise(t,a){const s=at(t,a),l=new _e(t,[],["sel"]),i=l.take("int","90, 180 or 270");if(![90,180,270].includes(i.v))throw new C(i.line,i.col,"rotate: the angle must be 90, 180 or 270 (clockwise)");l.done();const r=td(l,s,a.by,!1);return{text:`rotate ${i.v}${nd(r)}`,op:ve((f,u)=>{const h=dc(f,u),d=h.x+Math.floor((h.w-h.h)/2),p=h.y+Math.floor((h.h-h.w)/2);ed(f,u,(y,w)=>{const x=y-h.x,b=w-h.y;return i.v===180?[h.x+h.w-1-x,h.y+h.h-1-b]:i.v===90?[d+h.h-1-b,p+x]:[d+b,p+h.w-1-x]})})}}};function Nw(t){const a=/^(-?\d+)(\.5|\.0)?$/.exec(t.value);if(!a)throw new C(t.line,t.vcol,`${t.key}= must be a pixel position like 12 or 11.5`);return 2*Number(a[1])+(a[2]===".5"?t.value.startsWith("-")?-1:1:0)}const rh=t=>t%2===0?String(t/2):`${(t-1)/2}.5`,$j={name:"mirror",summary:"mirror [x=<a>] [y=<b>] live (later strokes are mirrored) | mirror off | mirror x=<a> from=left|right or mirror y=<b> from=top|bottom (copies one side over the other once)",normalise(t,a){const s=Qe(t,a),l=new _e(t,["x","y","from"],["live","off"]);l.done();const i=l.flags.find($=>$.v==="off"),r=l.flags.find($=>$.v==="live"),f=l.opts.get("x"),u=l.opts.get("y"),h=l.opts.get("from");if(i){if(r||f||u||h)throw new C(i.line,i.col,"mirror off takes nothing else");return{text:"mirror off",op:ve(($,_)=>Zt($,_,{mirror:null}))}}if(r&&h)throw new C(h.line,h.col,"mirror: give live or from=, not both");let d=f?Nw(f):null;const p=u?Nw(u):null;if(r)return d===null&&p===null&&(d=s.width-1),{text:`mirror ${[d!==null?`x=${rh(d)}`:"",p!==null?`y=${rh(p)}`:""].filter(Boolean).join(" ")} live`,op:ve((_,j)=>Zt(_,j,{mirror:{x2:d,y2:p}}))};if(at(t,a),f&&u)throw new C(u.line,u.col,"mirror from=: give one axis, x= or y=");d===null&&p===null&&(d=s.width-1);const y=d!==null,w=h?h.value:y?"left":"top",x=y?["left","right"]:["top","bottom"];if(!x.includes(w))throw new C(h.line,h.vcol,`from= must be ${x.join(" or ")} for a ${y?"vertical (x=)":"horizontal (y=)"} axis`);const b=y?d:p,v=w===x[0];return{text:`mirror ${y?"x":"y"}=${rh(b)} from=${w}`,op:ve(($,_)=>{const j=wn($,_),N=j.pixels.slice();for(let M=0;M<N.length;M++){const A=M%$.width,z=(M-A)/$.width,E=y?A:z;if(v?2*E>=b:2*E<=b)continue;const R=yn(j,y?b-A:A,y?z:b-z);R>=0&&(!j.mask||j.mask[R])&&(j.pixels[R]=N[M])}})}}};Le(vj);Le(xj);Le(bj);Le($j);const kj={name:"curve",summary:"curve <x,y> <x,y> <x,y> [<x,y>] c=<colour> [pp=on|off] (quadratic with 3 points, cubic with 4; the middle points pull the curve)",normalise(t,a){const s=at(t,a),l=new _e(t,["c","pp"]),i=l.cellOrigin(s),r=[];for(const d of l.rest()){if(d.t!=="point")throw new C(d.line,d.col,"curve: expected a point x,y");r.push(Cn(d))}if(r.length<3||r.length>4)throw new C(t.line,t.col,"curve: give 3 points (quadratic) or 4 (cubic): start, control point(s), end");const f=sl(l,s),u=l.choice("pp",["on","off"],"on"),h=r.map(([d,p])=>[d+i.dx,p+i.dy]);return{text:`curve${i.text} ${r.map(xa).join(" ")} c=${f.name} pp=${u}`,op:nl($k(h,u==="on"),f.index)}}},_j={name:"polygon",summary:"polygon <x,y> <x,y> <x,y> [...] c=<colour> [outline|fill] (closed; fill takes pixels whose centre is inside)",normalise(t,a){const s=at(t,a),l=new _e(t,["c"],["outline","fill"]),i=l.cellOrigin(s),r=[];for(const d of l.rest()){if(d.t!=="point")throw new C(d.line,d.col,"polygon: expected a point x,y");r.push(Cn(d))}if(r.length<3)throw new C(t.line,t.col,"polygon: give at least 3 points");const f=sl(l,s),u=l.flag(["outline","fill"],"outline"),h=r.map(([d,p])=>[d+i.dx,p+i.dy]);return{text:`polygon${i.text} ${r.map(xa).join(" ")} c=${f.name} ${u}`,op:nl(U0(h,u==="fill",!0),f.index,u==="outline")}}};function Vr(t){if(t===1)return[[0]];const a=Vr(t/2),s=[];for(let l=0;l<t;l++){s.push([]);for(let i=0;i<t;i++){const r=[0,2,3,1][(l>=t/2?2:0)+(i>=t/2?1:0)];s[l].push(4*a[l%(t/2)][i%(t/2)]+r)}}return s}const mc={checker:[[0,1],[1,0]],bayer2:Vr(2),bayer4:Vr(4),bayer8:Vr(8),hlines:[[0],[1]],vlines:[[0,1]]},nc=Object.keys(mc);function mv(t,a,s,l,i){const r=Math.max(...t.flat())+1,f=t[(s%t.length+t.length)%t.length][(a%t[0].length+t[0].length)%t[0].length];return 2*l*r>(2*f+1)*i}function pv(t,a){const s=t.take("point","a corner x,y"),l=t.take("size","a size WxH");if(l.w<1||l.h<1)throw new C(l.line,l.col,`${a}: size must be at least 1x1`);return{x:s.x,y:s.y,w:l.w,h:l.h,text:`${s.x},${s.y} ${l.w}x${l.h}`}}const jj={name:"dither",summary:`dither <x,y> <W>x<H> a=<colour> b=<colour> [pattern=${nc.join("|")}] [level=<0..1>] (b covers the share 'level' of the box)`,normalise(t,a){const s=at(t,a),l=new _e(t,["a","b","pattern","level"]),i=l.cellOrigin(s),r=pv(l,"dither");l.done();const f=b=>{const v=l.opts.get(b);if(!v)throw new C(t.line,t.col,`dither: missing ${b}=<colour>`);return an(v.value,s.palette,v.line,v.vcol)},u=f("a"),h=f("b"),d=l.choice("pattern",nc,"bayer4"),p=l.opts.get("level"),y=p?rc(p):{num:1,den:2,text:"0.5"},w=mc[d],x=si(r.x+i.dx,r.y+i.dy,r.w,r.h,!0).map(([b,v])=>[b,v,mv(w,b,v,y.num,y.den)?h.index:u.index]);return{text:`dither${i.text} ${r.text} a=${u.name} b=${h.name} pattern=${d} level=${y.text}`,op:ve((b,v)=>Fn(b,v,x,!1))}}},Mw=["down","up","right","left","radial"],Sj={name:"gradient",summary:`gradient <x,y> <W>x<H> ramp=<ramp|a,b,c> [dir=${Mw.join("|")}] [steps=<n>] [pattern=none|${nc.join("|")}] (banded, or dithered between bands)`,normalise(t,a){const s=at(t,a),l=new _e(t,["ramp","dir","steps","pattern"]),i=l.cellOrigin(s),r=pv(l,"gradient");l.done();const f=l.opts.get("ramp");if(!f)throw new C(t.line,t.col,"gradient: missing ramp=<ramp> (a palette ramp, or entries a,b,c)");const u=cc(f,s.palette),h=l.choice("dir",Mw,"down"),d=l.opts.get("steps"),p=d?gn(d,2,u.idx.length):u.idx.length;if(p<2)throw new C(f.line,f.vcol,"gradient: the ramp needs at least 2 colours");const y=l.choice("pattern",["none",...nc],"none"),w=Array.from({length:p},(A,z)=>u.idx[aw(2*z*(u.idx.length-1)+(p-1),2*(p-1))]),x=y==="none"?null:mc[y],b=r.x+i.dx,v=r.y+i.dy,$=2*b+r.w-1,_=2*v+r.h-1,j=(r.w-1)**2+(r.h-1)**2,N=(A,z)=>{switch(h){case"down":return[z-v,r.h-1];case"up":return[v+r.h-1-z,r.h-1];case"right":return[A-b,r.w-1];case"left":return[b+r.w-1-A,r.w-1];default:return[vh(4*((2*A-$)**2+(2*z-_)**2)),vh(4*j)||1]}},M=si(b,v,r.w,r.h,!0).map(([A,z])=>{const[E,R]=N(A,z);if(R<=0)return[A,z,w[0]];const B=E*(p-1),K=Math.min(p-1,aw(B,R)),J=B-K*R;if(K===p-1)return[A,z,w[K]];const T=x?mv(x,A,z,J,R):2*J>=R;return[A,z,w[T?K+1:K]]});return{text:`gradient${i.text} ${r.text} ramp=${u.text} dir=${h} steps=${p} pattern=${y}`,op:ve((A,z)=>Fn(A,z,M,!1))}}},Nj={name:"ramp",summary:"ramp <name> = <entry> <entry> ... (defines or replaces a ramp of this document's palette, darkest first)",normalise(t,a){const s=Qe(t,a),l=new _e(t,[]),i=l.take("word","a ramp name");if(!/^[A-Za-z][A-Za-z0-9_-]*$/.test(i.v))throw new C(i.line,i.col,`'${i.v}' is not a usable ramp name`);const r=l.take("word","'='");if(r.v!=="=")throw new C(r.line,r.col,"ramp: expected '=' after the name");const f=[];for(const u of l.rest()){const h=u.t==="word"?u.v:u.t==="int"?String(u.v):null;if(h===null)throw new C(u.line,u.col,"ramp: expected an entry name or key");if(f.push(an(h,s.palette,u.line,u.col).name),f.at(-1)==="none")throw new C(u.line,u.col,"ramp: 'none' cannot be in a ramp")}if(f.length<2)throw new C(t.line,t.col,"ramp: give at least 2 entries, darkest first");if(s.paletteLocked)throw new C(t.line,t.col,`palette '${s.palette.name}' is locked (palette unlock to change its ramps)`);return{text:`ramp ${i.v} = ${f.join(" ")}`,op:ve(u=>{u.palette={...u.palette,ramps:{...u.palette.ramps,[i.v]:f}}})}}};Le(kj);Le(_j);Le(jj);Le(Sj);Le(Nj);const Zo=[[0,-1],[1,0],[0,1],[-1,0]],Mj=[...Zo,[1,-1],[1,1],[-1,1],[-1,-1]];function yv(t,a,s,l){const i=yn(t,s,l);return i<0?ne:a[i]}const zj={name:"outline",summary:"outline c=<colour> [mode=outer|inner] [corners=on|off] [from=<layer>] (around the shapes on your layer, or on another layer)",normalise(t,a){const s=at(t,a),l=new _e(t,["c","mode","corners","from"]);l.done();const i=a.defaults?.outline?.find(w=>s.palette.entries.some(x=>x.name===w)),r=l.opts.get("c")??(i?Xo("c",i,t):void 0);if(!r)throw new C(t.line,t.col,"outline: missing c=<colour> (or give the style guide an outline colour)");const f=an(r.value,s.palette,r.line,r.vcol),u=l.choice("mode",["outer","inner"],"outer"),h=l.choice("corners",["on","off"],"off"),d=l.opts.get("from"),p=d?s.layers.findIndex(w=>w.name===d.value):-1;if(d&&p<0)throw new C(d.line,d.vcol,`no layer '${d.value}'`);if(d&&u==="inner")throw new C(d.line,d.col,"outline: from= goes with mode=outer (an inner outline is drawn on the shape itself)");const y=h==="on"?Mj:Zo;return{text:`outline c=${f.name} mode=${u} corners=${h}${d?` from=${d.value}`:""}`,op:ve((w,x)=>{const b=wn(w,x),v=p>=0?w.cels[p][et(w,x).frame]:b.pixels.slice(),$=b.pixels.slice();for(let _=0;_<v.length;_++){if(b.mask&&!b.mask[_])continue;const j=_%w.width,N=(_-j)/w.width,M=v[_]!==ne;if(u==="outer"?M||$[_]!==ne:!M)continue;y.some(([z,E])=>yv(b,v,j+z,N+E)!==ne==(u==="outer"))&&(b.pixels[_]=f.index)}})}}},ch={n:[0,-1],ne:[1,-1],e:[1,0],se:[1,1],s:[0,1],sw:[-1,1],w:[-1,0],nw:[-1,-1]},Cj={name:"shade",summary:"shade light=n|ne|e|se|s|sw|w|nw [ramp=<ramp>|all] [edge=<n>] (each shape's lit edge a ramp step lighter, its far edge a step darker)",normalise(t,a){const s=at(t,a),l=new _e(t,["light","ramp","edge"]);l.done();const i=a.defaults?.light&&a.defaults.light in ch?a.defaults.light:void 0;if(!l.opts.has("light")&&!i)throw new C(t.line,t.col,"shade: missing light=<direction> (n, ne, e, se, s, sw, w, nw), or a light in the style guide");const r=l.choice("light",Object.keys(ch),i??"nw"),f=l.opts.get("ramp"),u=f&&f.value!=="all"?cc(f,s.palette):null,h=l.opts.get("edge"),d=h?gn(h,1,8):1,[p,y]=ch[r];return{text:`shade light=${r} ramp=${u?u.text:"all"} edge=${d}`,op:ve((w,x)=>{const b=wn(w,x),v=b.pixels.slice(),$=new Map,_=j=>{if(!$.has(j)){const N=u?u.idx.includes(j)?{ramp:u.idx,at:u.idx.indexOf(j)}:null:Zh(w.palette,j)[0]??null;$.set(j,N)}return $.get(j)};for(let j=0;j<v.length;j++){const N=v[j];if(N===ne||b.mask&&!b.mask[j])continue;const M=_(N);if(!M)continue;const A=j%w.width,z=(j-A)/w.width,E=(T,D)=>{for(let L=1;L<=d;L++){const Y=yv(b,v,A+T*L,z+D*L);if(Y===ne||!M.ramp.includes(Y))return!0}return!1},R=(T,D)=>T!==0&&E(T,0)||D!==0&&E(0,D),B=R(p,y),K=R(-p,-y);if(B===K)continue;const J=M.at+(B?1:-1);J>=0&&J<M.ramp.length&&(b.pixels[j]=M.ramp[J])}})}}},Ej={name:"clean",summary:"clean orphans [size=<n>] [keep=none|texture] (pixels or clusters of up to n that share no 4-neighbour's colour take the colour around them)",normalise(t,a){at(t,a);const s=new _e(t,["size","keep"]),l=s.take("word","orphans");if(l.v!=="orphans")throw new C(l.line,l.col,"clean: expected orphans");s.done();const i=s.opts.get("size"),r=i?gn(i,1,64):1,f=s.choice("keep",["none","texture"],"none");return{text:`clean orphans size=${r} keep=${f}`,op:ve((u,h)=>Tj(u,wn(u,h),r,f==="texture"))}}};function Tj(t,a,s,l){const i=a.pixels.slice(),r=new Uint8Array(i.length);for(let f=0;f<i.length;f++){if(r[f])continue;const u=i[f],h=[f];r[f]=1;for(let x=0;x<h.length&&h.length<=s;x++){const b=h[x],v=b%t.width,$=(b-v)/t.width;for(const[_,j]of Zo){const N=yn(a,v+_,$+j);N>=0&&!r[N]&&i[N]===u&&(r[N]=1,h.push(N))}}if(h.length>s){for(let x=0;x<h.length;x++){const b=h[x],v=b%t.width,$=(b-v)/t.width;for(const[_,j]of Zo){const N=yn(a,v+_,$+j);N>=0&&!r[N]&&i[N]===u&&(r[N]=1,h.push(N))}}continue}const d=new Set(h),p=new Map;for(const x of h){const b=x%t.width,v=(x-b)/t.width;for(const[$,_]of Zo){const j=yn(a,b+$,v+_);j<0||d.has(j)||p.set(i[j],(p.get(i[j])??0)+1)}}let y=-1,w=0;for(const[x,b]of[...p.entries()].sort((v,$)=>v[0]-$[0]))b>w&&(y=x,w=b);if(!(y<0||y===u)&&!(l&&u!==ne&&y!==ne&&Zh(t.palette,u).some(x=>Math.abs(x.ramp.indexOf(y)-x.at)===1&&x.ramp.includes(y))))for(const x of h)(!a.mask||a.mask[x])&&(a.pixels[x]=y)}}const Oj={name:"shadow",summary:"shadow [<x,y> <W>x<H>] [c=<colour>] [dir=n|ne|e|se|s|sw|w|nw] (an ellipse on the ground under the art, away from the light; the style guide's colour and direction)",normalise(t,a){const s=at(t,a),l=new _e(t,["c","dir"]),i=l.cellOrigin(s);let r=null;if(l.peek()?.t==="point"){const y=l.take("point","a corner x,y"),w=l.take("size","a size WxH");r={x:y.x+i.dx,y:y.y+i.dy,w:w.w,h:w.h}}l.done();const f=a.defaults?.shadow,u=l.choice("dir",Fr,f?.dir&&Fr.includes(f.dir)?f.dir:L0(a.defaults?.light)),h=l.opts.get("c")??(f?.c&&f.c!=="darker"?Xo("c",f.c,t):void 0);if(!h)throw new C(t.line,t.col,`shadow: give c=<colour>${f?.c==="darker"?" (the style guide's shadow is darker, a step down the ramps of the ground under it: maps draw that; a sprite has no ground)":" (or a shadow colour in the style guide: style.shadow.c)"}`);const d=an(h.value,s.palette,h.line,h.vcol);if(!r){const y=et(s,a.by).frame;if(r=B0(Ce(s,y),s.width,s.height,u),!r)throw new C(t.line,t.col,"shadow: nothing is drawn yet to cast one (or give its box x,y WxH)")}const p=r;return{text:`shadow ${p.x},${p.y} ${p.w}x${p.h} c=${d.name} dir=${u}`,op:ve((y,w)=>{const x=wn(y,w),b=Ce(y,et(y,w).frame);for(const[v,$]of Y0(p)){if(v<0||$<0||v>=y.width||$>=y.height)continue;const _=$*y.width+v;b[_]!==ne||x.mask&&!x.mask[_]||(x.pixels[_]=d.index)}})}}};Le(zj);Le(Oj);Le(Cj);Le(Ej);const Hn=(t,a)=>(t%a+a)%a;function Ys(t,a,s){const l=t.cellOrigin(a);if(t.peek()?.t!=="point")return t.cell?{x:l.dx,y:l.dy,w:a.cellW,h:a.cellH,text:`${l.text} 0,0 ${a.cellW}x${a.cellH}`}:{x:0,y:0,w:a.width,h:a.height,text:` 0,0 ${a.width}x${a.height}`};const i=t.take("point","a corner x,y"),r=t.take("size","a size WxH");if(r.w<1||r.h<1)throw new C(r.line,r.col,`${s}: size must be at least 1x1`);return{x:i.x+l.dx,y:i.y+l.dy,w:r.w,h:r.h,text:`${l.text} ${i.x},${i.y} ${r.w}x${r.h}`}}function ci(t,a){const s=t.opts.get("seed");return s?gn(s,0,2147483647):a.newSeed()}function pc(t,a){return t.choice("wrap",["on","off"],a.wrap?"on":"off")==="on"}function yc(t,a){const s=a.reduce((i,r)=>i+r,0);let l=t.nextInt(s);for(let i=0;i<a.length;i++){if(l<a[i])return i;l-=a[i]}return a.length-1}function ad(t,a,s){const l=t.opts.get("ramp");if(!l)throw new C(s.line,s.col,`${s.name}: missing ramp=<ramp> (a palette ramp, or entries a,b,c)`);const i=cc(l,a.palette),r=t.opts.get("weights"),f=r?Z0(r,i.idx.length):i.idx.map(()=>1);return{ramp:i,weights:f}}function ld(t,a){return(s,l)=>a?[t.x+Hn(s,t.w),t.y+Hn(l,t.h)]:s<0||l<0||s>=t.w||l>=t.h?null:[t.x+s,t.y+l]}const Aj={name:"noise",summary:"noise [<x,y> <W>x<H>] ramp=<ramp> [weights=<w,w,..>] [cluster=<a>..<b>] [density=<0..1>] [base=<entry>|keep] [wrap=on|off] [seed=<n>] (clustered specks on a ramp)",normalise(t,a){const s=at(t,a),l=new _e(t,["ramp","weights","cluster","density","base","wrap","seed"]),i=Ys(l,s,"noise");l.done();const{ramp:r,weights:f}=ad(l,s,t),u=l.opts.get("cluster"),h=Math.max(1,Math.floor(s.cellW/24)),[d,p]=u?Pr(u,1,64):[h,3*h],y=l.opts.get("density"),w=y?rc(y):{num:15,den:100,text:"0.15"},x=l.opts.get("base");let b=r.idx[f.indexOf(Math.max(...f))],v=s.palette.entries[b].name;if(x&&x.value==="keep")b=null,v="keep";else if(x){const B=an(x.value,s.palette,x.line,x.vcol);b=B.index,v=B.name}const $=pc(l,s),_=ci(l,a),j=r.idx.map((B,K)=>B===b?0:f[K]);if(j.every(B=>B===0))throw new C(t.line,t.col,"noise: the ramp has no colour other than the base to scatter (check weights=)");const N=[];if(b!==null)for(let B=0;B<i.h;B++)for(let K=0;K<i.w;K++)N.push([i.x+K,i.y+B,b]);const M=new nn(_,1),A=ld(i,$),z=Math.floor((w.num*i.w*i.h*2+w.den)/(2*w.den)),E=new Uint8Array(i.w*i.h);let R=0;for(let B=0;R<z&&B<z*4+16;B++){const K=M.range(d,p),J=r.idx[yc(M,j)],T=[[M.nextInt(i.w),M.nextInt(i.h)]],D=(Y,O)=>`${Hn(Y,i.w)},${Hn(O,i.h)}`,L=new Set([D(...T[0])]);for(let Y=0;T.length<K&&Y<K*8;Y++){const[O,H]=T[M.nextInt(T.length)],[G,Z]=[[1,0],[-1,0],[0,1],[0,-1]][M.nextInt(4)],W=O+G,se=H+Z;!A(W,se)||L.has(D(W,se))||(L.add(D(W,se)),T.push([W,se]))}for(const[Y,O]of T){const H=A(Y,O);if(!H)continue;N.push([H[0],H[1],J]);const G=(H[1]-i.y)*i.w+(H[0]-i.x);E[G]||(E[G]=1,R++)}}return{text:`noise${i.text} ramp=${r.text} weights=${f.join(",")} cluster=${d}..${p} density=${w.text} base=${v} wrap=${$?"on":"off"} seed=${_}`,op:ve((B,K)=>Fn(B,K,N,!1))}}},qj={name:"scatter",summary:"scatter [<x,y> <W>x<H>] stamp=<name>[,<name>..]|c=<colour> count=<n> [minDist=<n>] [flip=on|off] [wrap=on|off] [seed=<n>] (places stamps by their middle, at least minDist apart)",normalise(t,a){const s=at(t,a),l=new _e(t,["stamp","c","count","minDist","flip","wrap","seed"]),i=Ys(l,s,"scatter");l.done();const r=l.opts.get("stamp"),f=l.opts.get("c");if(!!r==!!f)throw new C(t.line,t.col,"scatter: give stamp=<name> or c=<colour> (one of them)");let u,h;if(r){const A=r.value.split(",");h=A.map(z=>{const E=s.stamps[z];if(!E)throw new C(r.line,r.vcol,`no stamp '${z}' (stamps: ${Object.keys(s.stamps).join(", ")||"none; make one with stamp save"})`);return E}),u=`stamp=${A.join(",")}`}else{const A=an(f.value,s.palette,f.line,f.vcol);h=[{w:1,h:1,px:Uint16Array.of(A.index)}],u=`c=${A.name}`}const d=l.opts.get("count");if(!d)throw new C(t.line,t.col,"scatter: missing count=<n>");const p=gn(d,1,1e4),y=l.opts.get("minDist"),w=y?gn(y,0,4096):0,x=l.choice("flip",["on","off"],"off")==="on",b=pc(l,s),v=ci(l,a),$=new nn(v,2),_=[],j=(A,z)=>{let E=Math.abs(A[0]-z[0]),R=Math.abs(A[1]-z[1]);return b&&(E=Math.min(E,i.w-E),R=Math.min(R,i.h-R)),E*E+R*R};for(let A=0;_.length<p&&A<p*30;A++){const z=[$.nextInt(i.w),$.nextInt(i.h)];_.some(E=>j(z,E)<w*w)||_.push(z)}const N=ld(i,b),M=[];for(const[A,z]of _){const E=h[$.nextInt(h.length)],R=x&&$.nextInt(2)===1;for(let B=0;B<E.h;B++)for(let K=0;K<E.w;K++){const J=E.px[B*E.w+(R?E.w-1-K:K)];if(J===ne)continue;const T=N(A-(E.w>>1)+K,z-(E.h>>1)+B);T&&M.push([T[0],T[1],J])}}return{text:`scatter${i.text} ${u} count=${p} minDist=${w} flip=${x?"on":"off"} wrap=${b?"on":"off"} seed=${v}`,op:ve((A,z)=>Fn(A,z,M,!1))}}};function gv(t,a){const s=t.opts.get("gap");if(!s)return{index:null,text:"none"};if(s.value==="none")return{index:null,text:"none"};const l=an(s.value,a.palette,s.line,s.vcol);return{index:l.index,text:l.name}}const Rj={name:"voronoi",summary:"voronoi [<x,y> <W>x<H>] cells=<n> ramp=<ramp> [weights=<w,..>] [gap=<colour>|none] [relax=<n>] [wrap=on|off] [seed=<n>] (stones: cells of the nearest point, each a ramp colour, 1-px gaps)",normalise(t,a){const s=at(t,a),l=new _e(t,["cells","ramp","weights","gap","relax","wrap","seed"]),i=Ys(l,s,"voronoi");l.done();const{ramp:r,weights:f}=ad(l,s,t),u=l.opts.get("cells");if(!u)throw new C(t.line,t.col,"voronoi: missing cells=<n>");const h=gn(u,1,Math.max(1,Math.min(4096,i.w*i.h))),d=gv(l,s),p=l.opts.get("relax"),y=p?gn(p,0,8):1,w=pc(l,s),x=ci(l,a),b=new nn(x,3),v=vh(Math.floor(i.w*i.h*36/(100*h))),$=(R,B,K)=>{const J=B-R;if(!w)return J;const T=Hn(J,K);return T*2>K?T-K:T},_=(R,B,K)=>{const J=$(K[0],R,i.w),T=$(K[1],B,i.h);return J*J+T*T};let j=[];for(let R=0;j.length<h&&R<h*50;R++){const B=[b.nextInt(i.w),b.nextInt(i.h)];R<h*40&&j.some(K=>_(B[0],B[1],K)<v*v)||j.push(B)}const N=new Int32Array(i.w*i.h),M=()=>{for(let R=0;R<i.h;R++)for(let B=0;B<i.w;B++){let K=0,J=1/0;j.forEach((T,D)=>{const L=_(B,R,T);L<J&&(J=L,K=D)}),N[R*i.w+B]=K}};M();for(let R=0;R<y;R++){const B=new Array(j.length).fill(0),K=new Array(j.length).fill(0),J=new Array(j.length).fill(0);for(let T=0;T<i.h;T++)for(let D=0;D<i.w;D++){const L=N[T*i.w+D];B[L]+=$(j[L][0],D,i.w),K[L]+=$(j[L][1],T,i.h),J[L]++}j=j.map((T,D)=>{if(!J[D])return T;const L=T[0]+Math.floor((2*B[D]+J[D])/(2*J[D])),Y=T[1]+Math.floor((2*K[D]+J[D])/(2*J[D]));return w?[Hn(L,i.w),Hn(Y,i.h)]:[Math.max(0,Math.min(i.w-1,L)),Math.max(0,Math.min(i.h-1,Y))]}),M()}const A=j.map(()=>r.idx[yc(b,f)]),z=ld(i,w),E=[];for(let R=0;R<i.h;R++)for(let B=0;B<i.w;B++){const K=N[R*i.w+B];let J=!1;if(d.index!==null)for(const[T,D]of[[1,0],[-1,0],[0,1],[0,-1]]){const L=z(B+T,R+D);if(L&&N[(L[1]-i.y)*i.w+(L[0]-i.x)]<K){J=!0;break}}E.push([i.x+B,i.y+R,J?d.index:A[K]])}return{text:`voronoi${i.text} cells=${h} ramp=${r.text} weights=${f.join(",")} gap=${d.text} relax=${y} wrap=${w?"on":"off"} seed=${x}`,op:ve((R,B)=>Fn(R,B,E,!1))}}},Dj={name:"bricks",summary:"bricks [<x,y> <W>x<H>] size=<W>x<H> ramp=<ramp> [weights=<w,..>] [gap=<colour>|none] [offset=<n>] [seed=<n>] (courses of bricks with 1-px joints; every other course shifted)",normalise(t,a){const s=at(t,a),l=new _e(t,["size","ramp","weights","gap","offset","seed"]),i=Ys(l,s,"bricks");l.done();const r=l.opts.get("size"),f=r?/^(\d+)x(\d+)$/.exec(r.value):null;if(!r||!f||Number(f[1])<2||Number(f[2])<2)throw new C(r?.line??t.line,r?.vcol??t.col,"bricks: size= must be a brick size like 8x4 (joints included), at least 2x2");const u=Number(f[1]),h=Number(f[2]),{ramp:d,weights:p}=ad(l,s,t),y=gv(l,s),w=l.opts.get("offset"),x=w?gn(w,0,u-1):u>>1,b=ci(l,a),v=new nn(b,4),$=Math.ceil(i.h/h),_=Math.ceil(i.w/u)+1,j=Array.from({length:$*_},()=>d.idx[yc(v,p)]),N=[];for(let M=0;M<i.h;M++)for(let A=0;A<i.w;A++){const z=Math.floor(M/h),E=A+(z%2?x:0),R=i.w%u===0?Math.floor(E/u)%(i.w/u):Math.floor(E/u),B=M%h===h-1||E%u===u-1;B&&y.index===null||N.push([i.x+A,i.y+M,B?y.index:j[z*_+R]])}return{text:`bricks${i.text} size=${u}x${h} ramp=${d.text} weights=${p.join(",")} gap=${y.text} offset=${x} seed=${b}`,op:ve((M,A)=>Fn(M,A,N,!1))}}};Le(Aj);Le(qj);Le(Rj);Le(Dj);function wv(t,a){const s=a.defaults?.light&&a.defaults.light in zn?a.defaults.light:"nw",l=t.choice("light",Object.keys(zn),s);return{name:l,dir:zn[l]}}function vv(t,a,s,l){const i=t.opts.get("ramp");if(!i)throw new C(s.line,s.col,`${s.name}: missing ramp=<ramp> (a palette ramp, darkest first, or entries a,b,c)`);const r=cc(i,a.palette);if(r.idx.length<l)throw new C(i.line,i.vcol,`${s.name}: ramp= needs at least ${l} colours (darkest first), not ${r.idx.length}`);return r}function xv(t,a,s,l){const i=t.opts.get(s);if(!i)return{index:l,text:l===null?"none":a.palette.entries[l].name};if(i.value==="none")return{index:null,text:"none"};const r=an(i.value,a.palette,i.line,i.vcol);return{index:r.index,text:r.name}}const bv=t=>Math.max(8,Math.min(t.cellW,t.cellH));function $v(t,a,s,l,i){const r=t.opts.get("gap"),f=r?gn(r,0,16):1,u=pc(t,a),h=ci(t,s),d=t.opts.get("edges");if(d&&!u)throw new C(d.line,d.col,"edges= goes with wrap=on (with wrap=off nothing crosses the box's edge)");const p=d?gn(d,0,2147483647):h;return{box:l,wrap:u,gap:f,density:i,seed:h,edges:p}}const kv=t=>`gap=${t.gap} wrap=${t.wrap?"on":"off"}${t.wrap?` edges=${t.edges}`:""} seed=${t.seed}`;class zw{n;len;wmax;unit;C;S1;S2;Y;mis;total=0;constructor(a,s){this.n=a,this.len=s,this.unit=Math.max(1,Math.floor(a/24)),this.wmax=Math.max(1,Math.min(6*this.unit,a>>2)),this.C=new Float64Array(a*this.wmax*s),this.S1=new Float64Array(a*this.wmax),this.S2=new Float64Array(a*this.wmax),this.Y=new Float64Array(a),this.mis=new Float64Array(a)}recolour(a,s,l,i){const r=this.n,f=i((a-1+r)%r),u=i((a+1)%r);this.mis[(a-1+r)%r]+=(f!==l?1:0)-(f!==s?1:0),this.mis[a]+=(u!==l?1:0)-(u!==s?1:0)}jump(){const{n:a,len:s}=this;if(a<4)return 0;let l=0;for(let r=0;r<a-1;r++)l+=this.mis[r]/s;l/=a-1;let i=0;for(let r=0;r<a-1;r++)i+=(this.mis[r]/s-l)**2;return(this.mis[a-1]/s-l)/(Math.sqrt(i/(a-1))+.02)}add(a,s,l,i){const{n:r,wmax:f,len:u}=this;this.total+=l,this.Y[a]+=i;for(let h=1;h<=f;h++)for(let d=0;d<h;d++){const p=(a-d+r)%r*f+h-1,y=this.C[p*u+s];this.C[p*u+s]=y+l,this.S1[p]+=l,this.S2[p]+=2*y*l+l*l}}bands(){const{n:a,wmax:s,len:l,unit:i}=this,r=this.total/(a*l);let f=0,u=0;for(let h=0;h<a*s;h++){const d=h%s+1,p=this.S1[h]/(l*d),y=Math.max(0,this.S2[h]/(l*d*d)-p*p),x=Math.abs(p-r)*Math.sqrt(d/i)/Math.max(3,3*Math.sqrt(y)*Math.sqrt(d/i/l));u+=x*x,x>f&&(f=x)}return[f,u]}line(){const{n:a,len:s}=this;if(a<4)return 0;let l=0;for(let f=1;f<a-1;f++)l+=this.Y[f]/s;l/=a-2;let i=0;for(let f=1;f<a-1;f++)i+=(this.Y[f]/s-l)**2;const r=Math.sqrt(i/(a-2));return Math.abs((this.Y[0]+this.Y[a-1])/(2*s)-l)/(r+2)}}function _v(t,a,s,l,i,r){const{box:f,wrap:u,gap:h}=t,d=f.w,p=f.h,y=Math.floor((t.density.num*d*p*2+t.density.den)/(2*t.density.den)),w=(L,Y)=>u?Hn(Y,p)*d+Hn(L,d):L<0||Y<0||L>=d||Y>=p?-1:Y*d+L,x=(L,Y)=>L[0]+Y.w>d||L[1]+Y.h>p,b=(L,Y,O)=>{const H={baseL:L,baseY:Y,baseC:O,occ:new Uint8Array(d*p),lum:L.slice(),luma:Y.slice(),cls:new Int32Array(d*p).fill(-2),rows:new zw(p,d),cols:new zw(d,p),covered:0};for(let G=0;G<p;G++)for(let Z=0;Z<d;Z++)H.rows.add(G,Z,L[G*d+Z],Y[G*d+Z]),H.cols.add(Z,G,L[G*d+Z],Y[G*d+Z]);for(let G=0;G<d*p;G++)v(H,G,O[G]);return H},v=(L,Y,O)=>{const H=Y%d,G=Math.floor(Y/d),Z=L.cls[Y];Z!==O&&(L.rows.recolour(G,Z,O,W=>L.cls[W*d+H]),L.cols.recolour(H,Z,O,W=>L.cls[G*d+W]),L.cls[Y]=O)},$=(L,Y,O,H)=>{for(const[G,Z,W]of O.px){const se=w(Y[0]+G,Y[1]+Z);if(se<0)continue;const ue=H?s[W]:L.baseL[se],te=H?l[W]:L.baseY[se],U=ue-L.lum[se],V=te-L.luma[se];L.lum[se]=ue,L.luma[se]=te;const P=se%d,ie=Math.floor(se/d);L.rows.add(ie,P,U,V),L.cols.add(P,ie,U,V),L.occ[se]=H?1:0,L.covered+=H?1:-1,v(L,se,H?W:L.baseC[se])}},_=(L,Y,O)=>{for(const[H,G]of O.px)for(let Z=-h;Z<=h;Z++)for(let W=-h;W<=h;W++){const se=w(Y[0]+H+W,Y[1]+G+Z);if(se>=0&&L.occ[se])return!1}return!0},j=L=>{const Y=L.rows.bands(),O=L.cols.bands(),H=u?Math.max(L.rows.line(),L.cols.line(),L.rows.jump(),L.cols.jump())/.8:0;return[Math.max(Y[0],O[0],H),Y[1]+O[1]+H*H]},N=(L,Y,O)=>{$(L,Y,O,!0);const H=j(L);return $(L,Y,O,!1),H},M=(L,Y)=>L[0]<Y[0]-1e-9||L[0]<=Y[0]+1e-9&&L[1]<Y[1]-1e-9,A=(L,Y,O,H=0)=>{const G=new nn(L,r+(Y?0:16)+32*H),Z=(U,V)=>{if(u){const P=[Hn(U[0],d),Hn(U[1],p)];return!Y&&x(P,V)?null:P}return U[0]<0||U[1]<0||U[0]+V.w>d||U[1]+V.h>p?null:U},W=U=>Z(u?[G.nextInt(d),G.nextInt(p)]:[G.nextInt(d-U.w+1),G.nextInt(p-U.h+1)],U),se=[];for(let U=0;O.covered<y&&U<64+3*y;U++){const V=i(G);if(V.w>d||V.h>p)continue;let P=null,ie=1/0;for(let ye=0;ye<8;ye++){const F=W(V);if(!F||!_(O,F,V))continue;const pe=N(O,F,V)[1];pe<ie&&(ie=pe,P=F)}P&&($(O,P,V,!0),se.push({at:P,s:V}))}const ue=.8,te=()=>{for(let U=0;U<8;U++){let V=!1;for(const P of se){if(j(O)[0]<=ue)return;$(O,P.at,P.s,!1);let ie=P.at,ye=N(O,P.at,P.s);const F=[];for(let fe=-2;fe<=2;fe++)for(let ge=-2;ge<=2;ge++)(ge||fe)&&F.push(Z([P.at[0]+ge,P.at[1]+fe],P.s));for(let fe=0;fe<8;fe++)F.push(W(P.s));for(const fe of F){if(!fe||!_(O,fe,P.s))continue;const ge=N(O,fe,P.s);M(ge,ye)&&(ye=ge,ie=fe)}let pe=P.s;for(const fe of P.s.alts??[]){if(fe===P.s)continue;const ge=N(O,ie,fe);M(ge,ye)&&(ye=ge,pe=fe)}(ie!==P.at||pe!==P.s)&&(V=!0),P.at=ie,P.s=pe,$(O,P.at,P.s,!0)}if(!V)break}};te();for(let U=0;U<8&&O.covered<y+(y>>2)&&j(O)[0]>ue;U++){const V=i(G),P=j(O);let ie=null,ye=P;const F=d*p<=1024;for(let pe=0;pe<(F?d*p:64);pe++){const fe=F?Z([pe%d,Math.floor(pe/d)],V):W(V);if(!fe||!_(O,fe,V))continue;const ge=N(O,fe,V);M(ge,ye)&&(ye=ge,ie=fe)}ie&&($(O,ie,V,!0),se.push({at:ie,s:V}),te())}return{placed:se,cost:j(O)}},z=d*p<=400?4:d*p<=1024?3:2,E=(L,Y,O)=>{let H=A(L,Y,O());for(let G=1;G<z&&H.cost[0]>.8;G++){const Z=A(L,Y,O(),G);M(Z.cost,H.cost)&&(H=Z)}return H.placed};let R;if(!u)R=E(t.seed,!0,()=>b(a.l,a.y,a.c));else{const L=a.l.reduce((H,G)=>H+G,0)/(d*p),Y=a.y.reduce((H,G)=>H+G,0)/(d*p),O=E(t.edges,!0,()=>b(new Float64Array(d*p).fill(L),new Float64Array(d*p).fill(Y),new Int32Array(d*p).fill(-1))).filter(({at:H,s:G})=>x(H,G));R=[...O,...E(t.seed,!1,()=>{const H=b(a.l,a.y,a.c);for(const{at:G,s:Z}of O)$(H,G,Z,!0);return H})]}const B=[],K=new Map;for(const{at:L,s:Y}of R)for(const[O,H,G]of Y.px){const Z=w(L[0]+O,L[1]+H);Z>=0&&K.set(Z,G)}const J=new Map;for(const L of a.c)J.set(L,(J.get(L)??0)+1);const T=[...J].sort((L,Y)=>Y[1]-L[1]||L[0]-Y[0])[0]?.[0]??-1,D=new Set;for(const[L,Y]of K){if(Y===T||T<0)continue;const O=L%d,H=Math.floor(L/d);for(let G=-1;G<=1;G++)for(let Z=-1;Z<=1;Z++){const W=w(O+Z,H+G);W>=0&&!K.has(W)&&a.c[W]===Y&&D.add(W)}}for(const L of[...D].sort((Y,O)=>Y-O))B.push([f.x+L%d,f.y+Math.floor(L/d),T]);for(const[L,Y]of K)B.push([f.x+L%d,f.y+Math.floor(L/d),Y]);return B}function jv(t,a,s){const l=t.palette.entries.map(d=>ql(d.hex)),i=t.palette.entries.map(d=>qs(d.hex)),r=Ce(t,et(t,a).frame),f=new Float64Array(s.w*s.h),u=new Float64Array(s.w*s.h),h=new Int32Array(s.w*s.h);for(let d=0;d<s.h;d++)for(let p=0;p<s.w;p++){const y=s.x+p,w=s.y+d,x=y<t.width&&w<t.height?r[w*t.width+y]:ne;f[d*s.w+p]=x===ne?50:l[x],u[d*s.w+p]=x===ne?128:i[x],h[d*s.w+p]=x===ne?-1:x}return{under:{l:f,y:u,c:h},L:l,Y:i}}function Uj(t,a){const s=new Uint8Array(t*a);for(let l=0;l<a;l++)for(let i=0;i<t;i++){const r=(2*i+1-t)*a,f=(2*l+1-a)*t;r*r+f*f<=t*t*a*a&&(s[l*t+i]=1)}return s}const Cw=[[1,0],[1,1],[0,1],[-1,1],[-1,0],[-1,-1],[0,-1],[1,-1]];function Hj(t,a,s,l){const i=Uj(t,a),[r,f]=s,u=(N,M)=>N>=0&&M>=0&&N<t&&M<a&&i[M*t+N]===1,h=new Array(t*a).fill(-1),d=new Array(t*a).fill(0);for(let N=0;N<a;N++)for(let M=0;M<t;M++){if(!i[N*t+M])continue;let A=0,z=0;for(const[E,R]of Cw)u(M+E,N+R)||(A+=E,z+=R);d[N*t+M]=A*r+z*f,h[N*t+M]=d[N*t+M]<0?l.dark:l.body}const p=(N,M)=>u(N,M)&&h[M*t+N]===l.dark;for(let N=0;N<a;N++)for(let M=0;M<t;M++){if(!p(M,N))continue;const A=[-1,1].filter(E=>p(M+E,N)),z=[-1,1].filter(E=>p(M,N+E));A.length===1&&z.length===1&&!u(M+A[0],N+z[0])&&(h[N*t+M]=l.body)}const y=t>=5&&a>=4,w=(N,M)=>u(N,M)&&h[M*t+N]===l.body,x=[];for(let N=0;N<a;N++)for(let M=0;M<t;M++){const A=N*t+M;h[A]===l.body&&(y&&Cw.some(([z,E])=>!u(M+z,N+E))||x.push({k:A,s:4*(r*(2*M+1-t)+f*(2*N+1-a))-Math.abs(f*(2*M+1-t))-Math.abs(r*(2*N+1-a))}))}x.sort((N,M)=>M.s-N.s||N.k-M.k);const b=[[1,0],[-1,0],[0,1],[0,-1]],v=N=>{const M=N.map(z=>h[z]);for(const z of N)h[z]=l.lit;let A=N.length>1||N.every(z=>{const E=z%t,R=Math.floor(z/t),B=b.map(([J,T])=>u(E+J,R+T)?h[(R+T)*t+E+J]:-1),K=B.filter(J=>J===l.body).length;return K>=2&&B.filter(J=>J!==l.body&&J!==l.lit).length<K});for(let z=0;A&&z<a;z++)for(let E=0;E<t;E++)if(w(E,z)&&!b.some(([R,B])=>w(E+R,z+B))){A=!1;break}return A||N.forEach((z,E)=>{h[z]=M[E]}),A},$=N=>{const M=N%t,A=Math.floor(N/t),[z,E]=f!==0?[r===0?1:-r,0]:[0,1];return w(M+z,A+E)?(A+E)*t+M+z:null};let _=!1;for(const{k:N}of x)if(v([N])){if(_=!0,t>=8){const M=$(N);M!==null&&v([M])}break}for(const{k:N}of _?[]:x){const M=$(N);if(M!==null&&v([N,M]))break}const j=[];for(let N=0;N<a;N++)for(let M=0;M<t;M++)h[N*t+M]>=0&&j.push([M,N,h[N*t+M]]);return{w:t,h:a,px:j}}const Lj=(t,a)=>Math.max(2,Math.min(t,t-1-(t>>2)+a)),Bj={name:"pebbles",summary:"pebbles [<x,y> <W>x<H>] ramp=<ramp> [weights=<w,..>] [size=<a>..<b>] [density=<0..1>] [gap=<n>] [light=<dir>] [cast=<colour>|none] [wrap=on|off] [edges=<seed>] [seed=<n>] (stones: a body tone, a shadow side and a lit pixel from the light, never overlapping)",normalise(t,a){const s=at(t,a),l=new _e(t,["ramp","weights","size","density","gap","light","cast","wrap","edges","seed"]),i=Ys(l,s,"pebbles");l.done();const r=vv(l,s,t,3),f=r.idx.slice(1,-1),u=l.opts.get("weights"),h=u?Z0(u,f.length):f.map(()=>1),d=bv(s),p=l.opts.get("size"),y=Math.max(3,Math.floor((d+4)/9)),[w,x]=p?Pr(p,3,64):[y,Math.max(y+1,Math.floor((2*d+4)/9))],b=l.opts.get("density"),v=b?rc(b):{num:3,den:10,text:"0.3"},$=wv(l,a),_=xv(l,s,"cast",null),j=$v(l,s,a,i,v),N=B=>{const K=B.range(w,x),J=Lj(K,B.nextInt(2)),T=yc(B,h),D=Y=>M(Hj(K,J,$.dir,{dark:r.idx[Y],body:r.idx[Y+1],lit:r.idx[Y+2]})),L=D(T);L.alts=h.flatMap((Y,O)=>Y>0?[O===T?L:D(O)]:[]);for(const Y of L.alts)Y.alts=L.alts;return L},M=B=>{if(_.index===null)return B;const K=new Set(B.px.map(([G,Z])=>`${G},${Z}`)),[J,T]=$.dir,L=[...B.px.map(([G,Z])=>[G-J,Z-T,_.index]).filter(([G,Z])=>!K.has(`${G},${Z}`)),...B.px],Y=Math.min(...L.map(G=>G[0])),O=Math.min(...L.map(G=>G[1])),H=L.map(([G,Z,W])=>[G-Y,Z-O,W]);return{w:Math.max(...H.map(G=>G[0]))+1,h:Math.max(...H.map(G=>G[1]))+1,px:H}},{under:A,L:z,Y:E}=jv(s,a.by,i),R=_v(j,A,z,E,N,7);return{text:`pebbles${i.text} ramp=${r.text} weights=${h.join(",")} size=${w}..${x} density=${v.text} light=${$.name} cast=${_.text} ${kv(j)}`,op:ve((B,K)=>Fn(B,K,R,!1))}}};function Yj(t,a,s,l,i,r){const f=i[i.length-1],u=i[i.length-2],h=i[Math.max(0,i.length-3)],d=a>=8?2:1,p=[];for(let b=0;b<t;b++){const v=2*b-(t-1),$=Math.sign(v),_=$*Math.ceil(Math.abs(v)/2)*d,j=Math.max(3,a-Math.ceil(Math.abs(v)/2)*Math.max(1,a>>2)-(s[b]??0)),N=$===0?l[1]<0||l[0]===0?f:u:l[0]===0?u:$===Math.sign(l[0])?f:h;for(const[M,A]of Bh([b,a-1],[b+_,a-j]))p.push([M,A,N])}if(r!==null)for(let b=0;b<t;b++)p.push([b,a,r]);const y=Math.min(...p.map(b=>b[0])),w=Math.min(...p.map(b=>b[1])),x=p.map(([b,v,$])=>[b-y,v-w,$]);return{w:Math.max(...x.map(b=>b[0]))+1,h:Math.max(...x.map(b=>b[1]))+1,px:x}}const Gj={name:"tufts",summary:"tufts [<x,y> <W>x<H>] ramp=<ramp> [size=<a>..<b>] [blades=<a>..<b>] [density=<0..1>] [gap=<n>] [light=<dir>] [foot=<colour>|none] [wrap=on|off] [edges=<seed>] [seed=<n>] (tufts of blades lit from the light, never overlapping)",normalise(t,a){const s=at(t,a),l=new _e(t,["ramp","size","blades","density","gap","light","foot","wrap","edges","seed"]),i=Ys(l,s,"tufts");l.done();const r=vv(l,s,t,3),f=bv(s),u=l.opts.get("size"),h=Math.max(3,Math.floor((f+2)/6)),[d,p]=u?Pr(u,3,64):[h,Math.max(h+1,Math.floor((f+2)/4))],y=l.opts.get("blades"),[w,x]=y?Pr(y,1,9):f<20?[2,3]:f<32?[3,4]:[3,5],b=l.opts.get("density"),v=b?rc(b):{num:2,den:10,text:"0.2"},$=wv(l,a),_=xv(l,s,"foot",r.idx[0]),j=$v(l,s,a,i,v),{under:N,L:M,Y:A}=jv(s,a.by,i),E=_v(j,N,M,A,R=>{const B=R.range(w,x),K=R.range(d,p),J=Array.from({length:B},()=>R.nextInt(2)),T=[K-1,K,K+1].filter(D=>D>=d&&D<=p).map(D=>Yj(B,D,J,$.dir,r.idx,_.index));for(const D of T)D.alts=T;return T[T.length>2?1:K>d?T.length-1:0]},8);return{text:`tufts${i.text} ramp=${r.text} size=${d}..${p} blades=${w}..${x} density=${v.text} light=${$.name} foot=${_.text} ${kv(j)}`,op:ve((R,B)=>Fn(R,B,E,!1))}}};Le(Bj);Le(Gj);const Xj=/^[a-z][a-z0-9_-]*$/,Zj=new Set(["save","remove"]),Qj={name:"stamp",summary:"stamp save <name> <x,y> <W>x<H> | stamp save <name> << rows >> | stamp <name> <x,y> [flip=none|h|v|hv] | stamp remove <name>",normalise(t,a){const s=Qe(t,a),l=new _e(t,["flip"]),i=l.cellOrigin(s),r=l.take("word","save, remove or a stamp name");if(r.v==="save"){const w=l.take("word","a name for the stamp");if(!Xj.test(w.v)||Zj.has(w.v))throw new C(w.line,w.col,"stamp names use a-z, 0-9, _ and -, starting with a letter (not save or remove)");if(l.opts.has("flip"))throw new C(t.line,t.col,"stamp save takes no flip=");if(l.peek()?.t==="block"){const v=l.take("block","a block");l.done();const $=new Map(s.palette.entries.map((A,z)=>[A.key,z])),_=v.rows.map(A=>[...A.text].map((z,E)=>{if(z==="."||z===" ")return ne;const R=$.get(z);if(R===void 0)throw new C(A.line,A.col+E,`stamp: '${z}' is not a key in palette '${s.palette.name}'`);return R})),j=Math.max(0,..._.map(A=>A.length)),N=_.length;if(j<1||N<1)throw new C(v.line,v.col,"stamp save: the block is empty");const M=new Uint16Array(j*N).fill(ne);return _.forEach((A,z)=>A.forEach((E,R)=>{M[z*j+R]=E})),{text:`stamp save ${w.v} <<
|
|
21
|
+
${va(v.rows.map(A=>A.text))}>>`,op:ve(A=>{A.stamps={...A.stamps,[w.v]:{w:j,h:N,px:M}}})}}const x=l.take("point","a corner x,y (or a block: <<)"),b=l.take("size","a size WxH");if(l.done(),b.w<1||b.h<1||b.w>256||b.h>256)throw new C(b.line,b.col,"stamp save: size must be 1x1 to 256x256");return{text:`stamp${i.text} save ${w.v} ${x.x},${x.y} ${b.w}x${b.h}`,op:ve((v,$)=>{const _=wn(v,$),j=new Uint16Array(b.w*b.h).fill(ne);for(let N=0;N<b.h;N++)for(let M=0;M<b.w;M++){const A=yn(_,x.x+i.dx+M,x.y+i.dy+N);A>=0&&(!_.mask||_.mask[A])&&(j[N*b.w+M]=_.pixels[A])}v.stamps={...v.stamps,[w.v]:{w:b.w,h:b.h,px:j}}})}}if(r.v==="remove"){const w=l.take("word","a stamp name");if(l.done(),!s.stamps[w.v])throw new C(w.line,w.col,`no stamp '${w.v}'`);return{text:`stamp remove ${w.v}`,op:ve(x=>{const{[w.v]:b,...v}=x.stamps;x.stamps=v;for(const[$,_]of Object.entries(x.ctx))_.brush?.shape==="stamp"&&_.brush.stamp===w.v&&Zt(x,$,{brush:null})})}}at(t,a);const f=s.stamps[r.v];if(!f)throw new C(r.line,r.col,`no stamp '${r.v}' (stamps: ${Object.keys(s.stamps).join(", ")||"none; make one with stamp save"})`);const u=l.take("point","where its top-left goes, x,y");l.done();const h=l.choice("flip",["none","h","v","hv"],"none"),d=u.x+i.dx,p=u.y+i.dy,y=[];for(let w=0;w<f.h;w++)for(let x=0;x<f.w;x++){const b=h.includes("h")?f.w-1-x:x,v=h.includes("v")?f.h-1-w:w,$=f.px[v*f.w+b];$!==ne&&y.push([d+x,p+w,$])}return{text:`stamp${i.text} ${r.v} ${u.x},${u.y} flip=${h}`,op:ve((w,x)=>Fn(w,x,y,!0))}}},Vj={name:"brush",summary:"brush square <n> | brush circle <n> | brush stamp <name> | brush off (the shape px, line, curve, stroke and outlines draw with)",normalise(t,a){const s=Qe(t,a),l=new _e(t,[]),i=l.take("word","square, circle, stamp or off");if(i.v==="off")return l.done(),{text:"brush off",op:ve((u,h)=>Zt(u,h,{brush:null}))};if(i.v==="stamp"){const u=l.take("word","a stamp name");if(l.done(),!s.stamps[u.v])throw new C(u.line,u.col,`no stamp '${u.v}'`);return{text:`brush stamp ${u.v}`,op:ve((h,d)=>Zt(h,d,{brush:{shape:"stamp",stamp:u.v}}))}}if(i.v!=="square"&&i.v!=="circle")throw new C(i.line,i.col,"brush: expected square, circle, stamp or off");const r=l.take("int","a size in pixels");if(l.done(),r.v<1||r.v>32)throw new C(r.line,r.col,"brush: size must be 1..32");const f=i.v;return{text:`brush ${f} ${r.v}`,op:ve((u,h)=>Zt(u,h,{brush:r.v===1?null:{shape:f,size:r.v}}))}}};Le(Qj);Le(Vj);const Kj=/^[a-z][a-z0-9_]*$/,Sv=new Set(["new","fork","undo","redo","note","def"]),Ew=8;function Jj(t){const a=t.split(`
|
|
22
|
+
`).map(l=>l.replace(/\s+$/,""));for(;a.length&&a[0].trim()==="";)a.shift();for(;a.length&&a.at(-1).trim()==="";)a.pop();let s=1/0;for(const l of a)l.trim()&&(s=Math.min(s,l.length-l.trimStart().length));return a.map(l=>l.slice(Number.isFinite(s)?s:0)).join(`
|
|
23
|
+
`)}function Wj(t){return t.includes(`
|
|
24
|
+
`)?`{
|
|
25
|
+
${t.split(`
|
|
26
|
+
`).map(a=>a?` ${a}`:"").join(`
|
|
27
|
+
`)}
|
|
28
|
+
}`:`{ ${t} }`}function Tw(t,a){let s=0;const l=()=>{for(;t[s]===" ";)s++},i=()=>{if(l(),t[s]==="("){s++;const p=f();if(l(),t[s]!==")")throw new Error("expected ')'");return s++,p}if(t[s]==="-")return s++,-i();const h=/^(\d+|[a-z_][a-z0-9_]*)/.exec(t.slice(s));if(!h)throw new Error("expected a number or a parameter");if(s+=h[1].length,/^\d/.test(h[1]))return Number(h[1]);const d=a.get(h[1]);if(d===void 0)throw new Error(`unknown parameter '${h[1]}'`);if(!/^-?\d+$/.test(d))throw new Error(`parameter '${h[1]}' is '${d}', not a number`);return Number(d)},r=()=>{let h=i();for(;;){l();const d=t[s];if(d!=="*"&&d!=="/")return h;s++;const p=i();if(d==="/"&&p===0)throw new Error("division by zero");h=d==="*"?h*p:Math.floor(h/p)}},f=()=>{let h=r();for(;;){l();const d=t[s];if(d!=="+"&&d!=="-")return h;s++,h=d==="+"?h+r():h-r()}},u=f();if(l(),s<t.length)throw new Error(`unexpected '${t[s]}'`);return u}function Nv(t,a){const s=new Map(t.params.map((l,i)=>[l,a[i]]));return t.body.replace(/\$\(([^()]*(?:\([^()]*\)[^()]*)*)\)|\$([a-z_][a-z0-9_]*)((?:[+\-*/]\d+)*)/g,(l,i,r,f)=>{if(i!==void 0)return String(Tw(i,s));const u=s.get(r);if(u===void 0)throw new Error(`unknown parameter '$${r}'`);if(!f)return u;let h=Tw(r,s);for(const[,d,p]of f.matchAll(/([+\-*/])(\d+)/g)){const y=Number(p);if(d==="/"&&y===0)throw new Error("division by zero");h=d==="+"?h+y:d==="-"?h-y:d==="*"?h*y:Math.floor(h/y)}return String(h)})}const Ij={name:"def",summary:"def <name>(<param>,...) { <commands> } (a macro: $param in the body, $x+1 or $(x*2+y) for arithmetic)",normalise(t,a){Qe(t,a);const s=t.args.find(w=>w.t==="body");if(!s)throw new C(t.line,t.col,"def: expected a body in braces: def name(a,b) { ... }");const l=t.args.slice(0,t.args.indexOf(s)),i=t.args.slice(t.args.indexOf(s)+1);if(i.length)throw new C(i[0].line,i[0].col,`def: unexpected '${Io(i[0])}' after the body`);const r=l.map(Io).join(""),f=/^([a-z][a-z0-9_]*)\(([a-z0-9_,]*)\)$/.exec(r);if(!f)throw new C(l[0]?.line??t.line,l[0]?.col??t.col,"def: expected name(param,...) before the body, like tuft(x,y)");const u=f[1];if(Ds.has(u))throw new C(l[0].line,l[0].col,`def: '${u}' is a command name`);const h=f[2]?f[2].split(","):[];if(h.some(w=>!Kj.test(w)))throw new C(l[0].line,l[0].col,"def: parameters are names like x, y, c");if(new Set(h).size!==h.length)throw new C(l[0].line,l[0].col,"def: a parameter is named twice");const d=Jj(s.text);if(!d.trim())throw new C(s.line,s.col,"def: the body is empty");let p;try{p=Nv({params:h,body:d},h.map(()=>"0"))}catch(w){throw new C(s.line,s.col,`def ${u}: ${w.message}`)}const y=Ls(p);if(y.errors.length)throw new C(s.line,s.col,`def ${u}: body line ${y.errors[0].line}: ${y.errors[0].message}`);for(const w of y.commands){if(Sv.has(w.name))throw new C(s.line,s.col,`def ${u}: '${w.name}' cannot be used in a macro`);if(!Ds.has(w.name))throw new C(s.line,s.col,`def ${u}: unknown command '${w.name}' in the body`)}return{text:`def ${u}(${h.join(",")}) ${Wj(d)}`,op:{k:"fn",run:w=>{w.macros={...w.macros,[u]:{params:h,body:d}}}}}}},Fj={name:"call",summary:"call <name> <args...> [seed=<n>] (runs a macro; a point x,y fills two parameters)",normalise(t,a){const s=Qe(t,a),l=new _e(t,["seed"]),i=l.take("word","a macro name"),r=s.macros[i.v];if(!r){const _=Object.keys(s.macros);throw new C(i.line,i.col,`no macro '${i.v}' (${_.length?`macros: ${_.join(", ")}`:"define one with def"})`)}const f=[],u=[];for(const _ of l.rest()){if(_.t==="point")f.push(String(_.x),String(_.y));else if(_.t==="int")f.push(String(_.v));else if(_.t==="word")f.push(_.v);else throw new C(_.line,_.col,"call: arguments are numbers, points x,y or words");u.push(Io(_))}if(f.length!==r.params.length)throw new C(i.line,i.col,`call ${i.v}: takes ${r.params.length} value(s) (${r.params.join(", ")}), got ${f.length}`);const h=(a.depth??0)+1;if(h>Ew)throw new C(t.line,t.col,`call ${i.v}: macros call each other more than ${Ew} deep`);const d=l.opts.get("seed");let p=d?gn(d,0,2147483647):null,y=0,w;try{w=Nv(r,f)}catch(_){throw new C(t.line,t.col,`call ${i.v}: ${_.message}`)}const x=Ls(w);if(x.errors.length)throw new C(t.line,t.col,`call ${i.v}: body line ${x.errors[0].line}: ${x.errors[0].message}`);let b=Wa(s);const v=[];for(const _ of x.commands){if(Sv.has(_.name))throw new C(t.line,t.col,`call ${i.v}: '${_.name}' cannot be used in a macro`);const j={...a,doc:b,depth:h,newSeed:()=>(p===null&&(p=a.newSeed()),z0(new nn(p,1e3+y++))),undoTarget:()=>({error:"not in a macro"}),redoTarget:()=>({error:"not in a macro"})};try{const N=Fo(_,j);b=Po(b,N.op,a.by),v.push(N.op)}catch(N){throw N instanceof C?new C(t.line,t.col,`call ${i.v}: body line ${N.line}: ${N.message}`):N}}const $=p!==null&&(d||y>0)?` seed=${p}`:"";return{text:`call ${i.v}${u.length?" "+u.join(" "):""}${$}`,op:{k:"fn",run:(_,j)=>{for(const N of v)Po(_,N,j)}}}}};Le(Ij);Le(Fj);const Pj=/^[A-Za-z][A-Za-z0-9_-]*$/,eS=new Set(["add","set","remove","all"]),Ow=["cycle","pingpong"];function sd(t,a){if(t.flags.length)throw new C(t.flags[0].line,t.flags[0].col,`${a}: unexpected '${t.flags[0].v}'`)}function Kr(t,a,s){for(const l of t.opts.values())if(!s.includes(l.key))throw new C(l.line,l.col,`${a} takes no ${l.key}=`)}function Mv(t,a){const s=a.opts.get("frames");if(!s)return null;const l=/^\d+$/.test(s.value)?{t:"int",v:Number(s.value),line:s.line,col:s.vcol}:{t:"word",v:s.value,line:s.line,col:s.vcol};return hc(t,l,a.cmd)}const tS={name:"tag",summary:"tag add <name> <a>-<b> [loop=cycle|pingpong] | tag set <name> [frames=<a>-<b>] [loop=cycle|pingpong] | tag remove <name> (a named run of frames: walk_s, idle)",normalise(t,a){const s=Qe(t,a),l=new _e(t,["loop","frames"]);sd(l,"tag");const i=l.take("word","add, set or remove");if(!["add","set","remove"].includes(i.v))throw new C(i.line,i.col,"tag: expected add, set or remove");const r=l.take("word","a tag name"),f=s.tags.findIndex(p=>p.name===r.v);if(i.v==="add"){if(!Pj.test(r.v)||eS.has(r.v))throw new C(r.line,r.col,`'${r.v}' is not a usable tag name`);if(f>=0)throw new C(r.line,r.col,`there is already a tag '${r.v}'`);const p=hc(s,l.rest()[0],t);Kr(l,"tag add",["loop"]);const y=l.choice("loop",Ow,"cycle");return{text:`tag add ${r.v} ${p.text} loop=${y}`,op:ve(w=>{w.tags.push({name:r.v,from:p.from-1,to:p.to-1,loop:y})})}}if(f<0)throw new C(r.line,r.col,`no tag '${r.v}'${s.tags.length?` (tags: ${s.tags.map(p=>p.name).join(", ")})`:""}`);if(l.done(),i.v==="remove")return Kr(l,"tag remove",[]),{text:`tag remove ${r.v}`,op:ve(p=>{p.tags=p.tags.filter(y=>y.name!==r.v)})};Kr(l,"tag set",["loop","frames"]);const u=Mv(s,l),h=l.opts.get("loop");if(!u&&!h)throw new C(t.line,t.col,"tag set: give frames=<a>-<b> or loop=");const d=h?l.choice("loop",Ow,"cycle"):null;return{text:`tag set ${r.v}${u?` frames=${u.from}-${u.to}`:""}${d?` loop=${d}`:""}`,op:ve(p=>{const y=p.tags.find(w=>w.name===r.v);u&&(y.from=u.from-1,y.to=u.to-1),d&&(y.loop=d)})}}};function Aw(t){if(!Fa.includes(t.v))throw new C(t.line,t.col,`view: '${t.v}' is not a direction (${Fa.join(", ")})`);return t.v}const nS={name:"view",summary:"view <dir> frames=<a>-<b> | view <dir> mirror=<dir>|off | view remove <dir> (directions S N E W SE SW NE NW; a mirror view is its source flipped left to right, kept up to date)",normalise(t,a){const s=Qe(t,a),l=new _e(t,["frames","mirror"]);sd(l,"view");const i=l.take("word","a direction, or remove");if(i.v==="remove"){const p=l.take("word","a direction");l.done(),Kr(l,"view remove",[]);const y=Aw(p);if(!s.views.some(w=>w.name===y))throw new C(p.line,p.col,`there is no view ${y}`);if(s.views.some(w=>w.mirror===y))throw new C(p.line,p.col,`view ${y} is the source of mirror view ${s.views.find(w=>w.mirror===y).name} (turn that off first)`);return{text:`view remove ${y}`,op:ve(w=>{w.views=w.views.filter(x=>x.name!==y)})}}const r=Aw(i);l.done();const f=Mv(s,l),u=l.opts.get("mirror");if(!!f==!!u)throw new C(t.line,t.col,`view ${r}: give frames=<a>-<b> or mirror=<dir>|off`);const h=s.views.find(p=>p.name===r);if(f){if(h?.mirror)throw new C(t.line,t.col,`view ${r} is a mirror of ${h.mirror}: view ${r} mirror=off first`);const p=s.views.find(y=>y.name!==r&&y.from<=f.to-1&&f.from-1<=y.to);if(p)throw new C(t.line,t.col,`view ${r}: frames ${f.text} overlap view ${p.name} (${p.from+1}-${p.to+1})`);return{text:`view ${r} frames=${f.from}-${f.to}`,op:ve(y=>{const w=y.views.find(x=>x.name===r);w?(w.from=f.from-1,w.to=f.to-1):y.views.push({name:r,from:f.from-1,to:f.to-1,mirror:null})})}}if(u.value==="off"){if(!h?.mirror)throw new C(u.line,u.vcol,`view ${r} is not a mirror`);return{text:`view ${r} mirror=off`,op:ve(p=>{p.views.find(y=>y.name===r).mirror=null})}}const d=s.views.find(p=>p.name===u.value);if(!Fa.includes(u.value))throw new C(u.line,u.vcol,`mirror= must be a direction (${Fa.join(", ")}) or off`);if(!d)throw new C(u.line,u.vcol,`there is no view ${u.value} to mirror (view ${u.value} frames=<a>-<b> first)`);if(d.name===r)throw new C(u.line,u.vcol,"a view cannot mirror itself");if(d.mirror)throw new C(u.line,u.vcol,`view ${d.name} is itself a mirror (of ${d.mirror})`);if(s.views.some(p=>p.mirror===r))throw new C(t.line,t.col,`view ${r} is the source of another mirror`);if(Cl(r)!==d.name)throw new C(u.line,u.vcol,`view ${r} faces the other way from ${Cl(r)??"no view"}, not ${d.name} (a mirror flips left to right)`);return{text:`view ${r} mirror=${d.name}`,op:ve(p=>{let y=p.views.find(w=>w.name===r);if(!y){const w=p.views.find(v=>v.name===d.name),x=p.frameCount,b=w.to-w.from+1;qh(p,x,b,()=>new Uint16Array(p.width*p.height).fill(ne),Array.from({length:b},()=>Oh)),p.views.push(y={name:r,from:x,to:x+b-1,mirror:null})}y.mirror=d.name})}}};function aS(t,a,s){const l=a.opts.get("layer");if(!l){const r=et(t,s).layer;return{layers:[r],text:`layer=${t.layers[r].name}`}}if(l.value==="all")return{layers:t.layers.map((r,f)=>f),text:"layer=all"};const i=t.layers.findIndex(r=>r.name===l.value);if(i<0)throw new C(l.line,l.vcol,`no layer '${l.value}'`);return{layers:[i],text:`layer=${l.value}`}}function lS(t,a,s){for(let l=s.from-1;l<s.to;l++){const i=Vo(t,l);if(i?.mirror)throw new C(a.line,a.col,`${a.name}: frame ${l+1} is in view ${i.name}, a live mirror of ${i.mirror}`)}}const sS={name:"cel",summary:"cel link <a>-<b> [layer=<name>|all] | cel unlink <a>-<b> [layer=<name>|all] (linked cels share their pixels: draw on one, all change; link copies frame <a>'s pixels)",normalise(t,a){const s=Qe(t,a),l=new _e(t,["layer"]);sd(l,"cel");const i=l.take("word","link or unlink");if(i.v!=="link"&&i.v!=="unlink")throw new C(i.line,i.col,"cel: expected link or unlink");const r=hc(s,l.rest()[0],t);if(i.v==="link"&&r.from===r.to)throw new C(t.line,t.col,"cel link: give two or more frames (<a>-<b>)");lS(s,t,r);const f=aS(s,l,a.by);return{text:`cel ${i.v} ${r.from}-${r.to} ${f.text}`,op:ve(u=>{for(const h of f.layers){const d=u.cels[h];for(let p=r.from-1;p<r.to;p++)i.v==="link"?d[p]=d[r.from-1]:(d.indexOf(d[p])!==p||d.lastIndexOf(d[p])!==p)&&(d[p]=d[p].slice())}})}}},oS={name:"pivot",summary:"pivot <x,y> | pivot off (the pixel the sprite stands on: an export field, and what pivot drift is measured from)",normalise(t,a){const s=Qe(t,a),l=new _e(t,[],["off"]);if(l.flags.length)return l.done(),{text:"pivot off",op:ve(r=>{r.pivot=null})};const i=Cn(l.take("point","a pixel x,y (or off)"));if(l.done(),i[0]<0||i[1]<0||i[0]>=s.width||i[1]>=s.height)throw new C(t.line,t.col,`pivot ${i[0]},${i[1]} is outside the ${s.width}x${s.height} canvas`);return{text:`pivot ${i[0]},${i[1]}`,op:ve(r=>{r.pivot=[i[0],i[1]]})}}},iS={name:"ground",summary:"ground <y> | ground off (the row the feet rest on: every frame should touch it)",normalise(t,a){const s=Qe(t,a),l=new _e(t,[],["off"]);if(l.flags.length)return l.done(),{text:"ground off",op:ve(r=>{r.ground=null})};const i=l.take("int","a row y (or off)");if(l.done(),i.v<0||i.v>=s.height)throw new C(i.line,i.col,`ground ${i.v} is outside rows 0..${s.height-1}`);return{text:`ground ${i.v}`,op:ve(r=>{r.ground=i.v})}}};for(const t of[tS,nS,sS,oS,iS])Le(t);function rS(t,a){const s=Qe(t,a);if(!s.family)throw new C(t.line,t.col,`${t.name}: '${s.name}' is not a family (new family <name> <T>x<T> scheme=…)`);return{doc:s,f:s.family}}function zv(t){if(t.flags.length)throw new C(t.flags[0].line,t.flags[0].col,`${t.cmd.name}: unexpected '${t.flags[0].v}'`)}function Ol(t,a,s){for(const l of t.opts.values())if(!s.includes(l.key))throw new C(l.line,l.col,`${a} takes no ${l.key}=`)}function Mt(t,a,s,l,i){const r=t.opts.get(a);if(!r)return i;if(!/^\d+$/.test(r.value)||Number(r.value)<s||Number(r.value)>l)throw new C(r.line,r.vcol,`${a}= must be a whole number ${s}..${l}`);return Number(r.value)}const Us=(t,a)=>t.layers.findIndex(s=>s.name===a);function qw(t,a,s,l,i){const r=Ce(t,a),f=new Map;for(let d=0;d<i;d++)for(let p=0;p<i;p++){const y=r[(l*i+d)*t.width+s*i+p];y!==ne&&f.set(y,(f.get(y)??0)+1)}let u=ne,h=0;for(const[d,p]of f)(p>h||p===h&&d<u)&&(u=d,h=p);return u}function Cv(t,a,s,l){const i=t.opts.get("from"),r=tn(s),f=yt(s),u=s.tile,h=r.mapRow*u,d=a.width,p=new Map(a.palette.entries.map((Z,W)=>[W,Z.key])),y=t.rest(),w=y.at(-1)?.t==="block"?y.pop():null,x=(Z,W)=>{if(Z===r.inside[0]&&W===r.inside[1])return"inside";if(Z===r.outside[0]&&W===r.outside[1])return"outside";const se=r.cells.findIndex(([ue,te])=>ue===Z&&te===W);return se>=0?f.variants[se].name:`${Z}:${W}`},b=Z=>{const W=/^(\d+):(\d+)$/.exec(Z);return W?Number(W[1])<d/u&&Number(W[2])<r.mapRow?[Number(W[1]),Number(W[2])]:null:Wh(s,Z)};if(!w&&!t.opts.get("cells")){if(y.length)throw new C(y[0].line,y[0].col,`family band from=: the band comes from '${i.value}' (give nothing else)`);Ol(t,"family band from=",["from"]);const Z=l.asset?.(i.value);if(!Z)throw new C(i.line,i.vcol,`family band: no asset '${i.value}' to copy the band from (not this one)`);const W=Z.family;if(!W||W.scheme!==s.scheme||W.tile!==u)throw new C(i.line,i.vcol,`family band: '${i.value}' is not a ${s.scheme} family of ${u}px tiles`);const se=W.geometry,ue=be=>be==="outside"||be==="inside"?be:Z.palette.entries[be].name;for(const be of se.bands)if(typeof be.fill=="number"&&!a.palette.entries.some($e=>$e.name===ue(be.fill)))throw new C(i.line,i.vcol,`family band: '${i.value}' uses ${ue(be.fill)}, which palette '${a.palette.name}' does not have`);const te=`${se.bands.map(be=>`${be.w}:${ue(be.fill)}`).join(" ")} radius=${se.radius} inset=${se.inset}${se.fillet!==void 0?` fillet=${se.fillet}`:""}${se.jitter?` jitter=${se.jitter.px} seed=${se.jitter.seed}`:""}`,U=W.detached,V=Math.min(Z.frameCount,a.frameCount),P=Us(Z,Wo),ie=new Set(U),ye=tn(W),F=new Set(f.variants.map((be,$e)=>f.sources[$e]&&!ie.has(be.name)?`${ye.cells[$e][0]},${ye.cells[$e][1]}`:"").filter(Boolean)),pe=(be,$e,Me)=>P>=0?Z.cels[P][be][Me*Z.width+$e]:ne,fe=[];for(let be=0;be<r.mapRow;be++)for(let $e=0;$e<d/u;$e++){if(F.has(`${$e},${be}`))continue;let Me=!1;for(let Ge=0;Ge<V&&!Me;Ge++)for(let mt=0;mt<u&&!Me;mt++)for(let ct=0;ct<u;ct++)if(pe(Ge,$e*u+ct,be*u+mt)!==ne){Me=!0;break}Me&&fe.push([$e,be])}const ge=[];for(let be=0;be<V;be++)for(let $e=0;$e<u;$e++){let Me="";for(const[Ge,mt]of fe)for(let ct=0;ct<u;ct++){const X=pe(be,Ge*u+ct,mt*u+$e);if(X===ne){Me+=".";continue}const we=a.palette.entries.findIndex(Te=>Te.name===Z.palette.entries[X].name);if(we<0)throw new C(i.line,i.vcol,`family band: '${i.value}' uses ${Z.palette.entries[X].name}, which palette '${a.palette.name}' does not have`);Me+=p.get(we)}ge.push(Me)}const Re=`band from=${i.value} ${te} detached=${U.length?U.join(","):"none"} frames=${V} cells=${fe.length?fe.map(([be,$e])=>x(be,$e)).join(","):"none"}${fe.length?` <<
|
|
29
|
+
${va(ge)}>>`:""}`,rt=Ls(`family ${Re}`);if(rt.errors.length||rt.commands.length!==1)throw new C(i.line,i.vcol,`family band from=: ${rt.errors[0]?.message??"could not record the band"}`);const Se=new _e(rt.commands[0],["radius","inset","fillet","jitter","draw","from","frame","seed","copies","fill","textures","detached","frames","cells"]);return Se.take("word","band"),Cv(Se,a,s,l)}Ol(t,"family band from=",["from","radius","inset","fillet","jitter","seed","detached","frames","cells"]);const v=[],$=[];for(const Z of y){const W=Z.t==="word"?/^(\d+):(.+)$/.exec(Z.v):null;if(!W)throw new C(Z.line,Z.col,"family band: expected <width>:<colour|outside|inside>");const se=W[2]==="outside"||W[2]==="inside"?W[2]:an(W[2],a.palette,Z.line,Z.col).index;v.push({w:Number(W[1]),fill:se}),$.push(`${W[1]}:${W[2]}`)}const _=u/2,j=Mt(t,"radius",0,_,0),N=Mt(t,"inset",0,_-1,0),A=t.opts.get("fillet")?Mt(t,"fillet",1,_,1):void 0,z=Mt(t,"jitter",0,_,0),E=z?Mt(t,"seed",1,2147483647,1):0,R=t.opts.get("detached")?.value??"none",B=R==="none"?[]:R.split(",");for(const Z of B)if(!f.byName.has(Z))throw new C(t.opts.get("detached").line,t.opts.get("detached").vcol,`${f.name} has no variant '${Z}'`);const K=Mt(t,"frames",1,a.frameCount,1),J=t.opts.get("cells"),T=[];if(J&&J.value!=="none")for(const Z of J.value.split(",")){const W=b(Z);if(!W)throw new C(J.line,J.vcol,`family band from=: '${Z}' is not a cell of the sheet (a variant, inside, outside or <cx>:<cy>)`);T.push(W)}const D=J?T.length*u:d,L=J?T.length?K*u:0:K*h,Y=w?.rows??[];if(Y.length!==L||Y.some(Z=>Z.text.length!==D)){const Z=w??J;throw new C(Z.line,Z.col,`family band from=: the rows must be ${K} frame${K===1?"":"s"} of ${D}x${J?u:h}${J?` (the ${T.length} cells side by side)`:""}`)}const O=new Map(a.palette.entries.map((Z,W)=>[Z.key,W])),H=Y.map(Z=>[...Z.text].map((W,se)=>{if(W===".")return ne;const ue=O.get(W);if(ue===void 0)throw new C(Z.line,Z.col+se,`'${W}' is not a key in palette '${a.palette.name}'`);return ue})),G={inset:N,radius:j,bands:v,...A!==void 0?{fillet:A}:{},...z?{jitter:{px:z,seed:E}}:{}};return{text:`band from=${i.value} ${$.join(" ")} radius=${j} inset=${N}${A!==void 0?` fillet=${A}`:""}${z?` jitter=${z} seed=${E}`:""} detached=${R} frames=${K}${J?` cells=${J.value}`:""}${Y.length?` <<
|
|
30
|
+
${va(Y.map(Z=>Z.text))}>>`:""}`,run:Z=>{const W=Z.family;W.geometry=G,W.detached=f.variants.map(te=>te.name).filter(te=>B.includes(te));const se=Us(Z,Wo);if(se<0)return;const ue=new Set;for(let te=0;te<K;te++){const U=Z.cels[se][te];if(!ue.has(U)){if(ue.add(U),!J){for(let V=0;V<h;V++)for(let P=0;P<d;P++)U[V*d+P]=H[te*h+V][P];continue}U.fill(ne,0,h*d),T.forEach(([V,P],ie)=>{for(let ye=0;ye<u;ye++)for(let F=0;F<u;F++)U[(P*u+ye)*d+V*u+F]=H[te*u+ye][ie*u+F]})}}}}}function cS(t,a,s,l){const i=t.rest();if(!i.length)throw new C(t.cmd.line,t.cmd.col,"family band: give the band from the edge in, as <width>:<colour|outside|inside> (e.g. 3:outside 1:foam 2:sand1)");const r=[],f=[];for(const _ of i){const j=_.t==="word"?_.v:"",N=/^(\d+):(.+)$/.exec(j);if(!N)throw new C(_.line,_.col,"family band: expected <width>:<colour|outside|inside>, like 2:foam");const M=Number(N[1]);if(M<1)throw new C(_.line,_.col,"family band: a width is at least 1");let A,z;if(N[2]==="outside"||N[2]==="inside")A=N[2],z=N[2];else{const E=an(N[2],a.palette,_.line,_.col+N[1].length+1);if(E.index===ne)throw new C(_.line,_.col,"family band: a band needs a colour, outside or inside (not none)");A=E.index,z=E.name}r.push({w:M,fill:A}),f.push(`${M}:${z}`)}const u=!!yt(s).fillets;Ol(t,"family band",u?["radius","inset","draw","fillet","jitter","seed"]:["radius","inset","draw","jitter","seed"]);const h=s.tile/2,d=Mt(t,"radius",0,h,0),p=Mt(t,"inset",0,h-1,s.geometry.inset),y=t.choice("draw",["on","off"],"on")==="on",w=r.reduce((_,j)=>_+j.w,0);if(p+w+d>h)throw new C(t.cmd.line,t.cmd.col,`family band: the inset (${p}), the band (${w}) and the corner radius (${d}) must fit in half a tile (${h} px)`);const x=u?Mt(t,"fillet",1,h,s.geometry.fillet??Math.min(h,w||1)):void 0,b=Mt(t,"jitter",0,Math.max(0,h-p-w-d),0);if(!b&&t.opts.get("seed"))throw new C(t.opts.get("seed").line,t.opts.get("seed").col,"family band: seed= goes with jitter=");const v=b?t.opts.get("seed")?Mt(t,"seed",1,2147483647,1):l.newSeed():0,$={inset:p,radius:d,bands:r,...x!==void 0?{fillet:x}:{},...b?{jitter:{px:b,seed:v}}:{}};return{text:`band ${f.join(" ")} radius=${d} inset=${p}${x!==void 0?` fillet=${x}`:""}${b?` jitter=${b} seed=${v}`:""} draw=${y?"on":"off"}`,run:_=>{const j=_.family;j.geometry=$;const N=Us(_,Wo);if(!y||N<0)return;const M=yt(j),A=j.tile,z=tn(j),E=ri(M,A,$),R=M.pieces.map(K=>M.byName.get(K)).filter(K=>!Hh(M.variants[K].on)),B=new Set;for(const K of _.cels[N])if(!B.has(K)){B.add(K);for(const J of R){const[T,D]=z.cells[J];for(let L=0;L<A;L++)for(let Y=0;Y<A;Y++){const O=E[J][L*A+Y],H=O>=0&&O<r.length?r[O].fill:"inside";K[(D*A+L)*_.width+T*A+Y]=typeof H=="number"?H:ne}}}}}}function uS(t,a,s,l){const i=t.take("word","inside or outside");if(i.v!=="inside"&&i.v!=="outside")throw new C(i.line,i.col,"family texture: expected inside or outside");const r=t.peek()?.t==="block"?t.take("block","texture rows"):null;t.done(),Ol(t,"family texture",["from","frame"]);const f=s.tile,u=t.opts.get("from"),h=t.opts.get("frame");let d,p=1;if(r)d=r.rows.map(v=>v.text),h&&(p=Mt(t,"frame",1,4096,1));else{if(!u)throw new C(t.cmd.line,t.cmd.col,"family texture: give from=<tile asset> or the rows in a block");const v=l.asset?.(u.value);if(!v)throw new C(u.line,u.vcol,`family texture: no asset '${u.value}' to copy from`);if(v.width!==f||v.height!==f)throw new C(u.line,u.vcol,`family texture: '${u.value}' is ${v.width}x${v.height}, the family's tiles are ${f}x${f}`);p=Mt(t,"frame",1,v.frameCount,1);const $=Ce(v,p-1),_=v.palette.entries.map(N=>{let M=a.palette.entries.findIndex(A=>A.name===N.name);return M<0&&(M=a.palette.entries.findIndex(A=>A.hex===N.hex)),M}),j=[...new Set([...$].filter(N=>N!==ne&&_[N]<0).map(N=>v.palette.entries[N].name))];if(j.length)throw new C(u.line,u.vcol,`family texture: ${j.join(", ")} ${j.length>1?"are":"is"} not in palette '${a.palette.name}' (palette add first)`);d=Array.from({length:f},(N,M)=>Array.from({length:f},(A,z)=>{const E=$[M*f+z];return E===ne?" ":a.palette.entries[_[E]].key}).join(""))}if(d.length!==f||d.some(v=>[...v].length!==f))throw new C(r?.line??t.cmd.line,r?.col??t.cmd.col,`family texture: the rows must be ${f} rows of ${f} keys`);const y=new Map(a.palette.entries.map((v,$)=>[v.key,$])),w=new Uint16Array(f*f);d.forEach((v,$)=>[...v].forEach((_,j)=>{const N=_===" "?ne:y.get(_);if(N===void 0){const M=r?.rows[$];throw new C(M?.line??t.cmd.line,(M?.col??t.cmd.col)+j,`family texture: '${_}' is not a key in palette '${a.palette.name}'`)}w[$*f+j]=N}));const[x,b]=Wh(s,i.v);return{text:`texture ${i.v}${u?` from=${u.value} frame=${p}`:""} <<
|
|
31
|
+
${va(d)}>>`,run:(v,$)=>{const _=Us(v,ii);if(_<0)return;const j=v.cels[_][et(v,$).frame];for(let N=0;N<f;N++)j.set(w.subarray(N*f,N*f+f),(b*f+N)*v.width+x*f)}}}const fS={name:"family",summary:"family band <w>:<colour|outside|inside>… [radius=<r>] [inset=<n>] [draw=on|off] | family texture inside|outside from=<tile> [frame=<n>] | family detach|attach <variant>|all | family coverage [seed=<n>] [copies=<n>] [fill=on|off] | family cut [textures=on|off]",normalise(t,a){const{doc:s,f:l}=rS(t,a),i=new _e(t,["radius","inset","fillet","jitter","draw","from","frame","seed","copies","fill","textures","detached","frames","cells"]);zv(i);const r=i.take("word","band, texture, detach, attach, coverage or cut"),f=yt(l);if(r.v==="band"&&i.opts.get("from")){const u=Cv(i,s,l,a);return{text:`family ${u.text}`,op:ve(h=>u.run(h))}}if(l.bandOf&&["cut","detach","attach"].includes(r.v))throw new C(r.line,r.col,`family ${r.v}: '${s.name}' inherits its band from '${l.bandOf}': do it there, or make the band its own (variant of=${l.bandOf} band=own)`);if(r.v==="band"&&l.bandOf)throw new C(r.line,r.col,`family band: '${s.name}' inherits its band from '${l.bandOf}' (variant of=${l.bandOf} band=inherit): fix the band there, or make it its own (variant of=${l.bandOf} band=own)`);if(r.v==="band"){const u=cS(i,s,l,a);return{text:`family ${u.text}`,op:ve(h=>u.run(h))}}if(r.v==="texture"){const u=uS(i,s,l,a);return{text:`family ${u.text}`,op:ve(u.run)}}if(r.v==="detach"||r.v==="attach"){const u=i.take("word","a variant name or all");i.done(),Ol(i,`family ${r.v}`,[]);const h=new Set(f.pieces);let d;if(u.v==="all")d=f.variants.map(y=>y.name).filter(y=>!h.has(y));else{if(!f.byName.has(u.v))throw new C(u.line,u.col,`${f.name} has no variant '${u.v}'`);if(h.has(u.v))throw new C(u.line,u.col,`'${u.v}' is a piece: pieces are always drawn by hand (the other variants are built from them)`);d=[u.v]}const p=r.v==="detach";return{text:`family ${r.v} ${u.v}`,op:ve(y=>{const w=y.family,x=new Set(w.detached);for(const b of d)p?x.add(b):x.delete(b);w.detached=f.variants.map(b=>b.name).filter(b=>x.has(b))})}}if(r.v==="coverage"){if(i.done(),Ol(i,"family coverage",["seed","copies","fill"]),!l.mapCols)throw new C(t.line,t.col,"family coverage: this family has no map area (new family … map=<C>x<R>)");const h=i.opts.get("seed")?Mt(i,"seed",1,2147483647,1):a.newSeed(),d=Mt(i,"copies",1,8,1),p=i.choice("fill",["on","off"],"off")==="on",y=A_(f,l.mapCols,l.mapRows,h,d);if(!y)throw new C(t.line,t.col,`family coverage: no ${l.mapCols}x${l.mapRows} layout with every variant ${d>1?`${d} times `:""}was found from seed ${h} (try another seed, fewer copies, or a bigger map)`);return{text:`family coverage seed=${h} copies=${d} fill=${p?"on":"off"}`,op:ve(w=>{const x=w.family;x.terrain=y.cells.slice();const b=tn(x),v=x.tile;let $=Us(w,"template");$<0&&(w.layers.unshift(zl("template",{reference:!0})),w.cels.unshift(Array.from({length:w.frameCount},()=>new Uint16Array(w.width*w.height).fill(ne))),Dl(w,M=>M+1,M=>M),$=0);const _=Us(w,ii),j=ri(f,v,x.geometry),N=x.geometry;for(let M=0;M<w.frameCount;M++){const A=qw(w,M,b.inside[0],b.inside[1],v),z=qw(w,M,b.outside[0],b.outside[1],v),E=fc(w,y,M),R=w.cels[$][M];if(E.variants.forEach((B,K)=>{const J=K%x.mapCols,T=b.mapRow+Math.floor(K/x.mapCols);for(let D=0;D<v;D++)for(let L=0;L<v;L++){const Y=B===null?-1:j[B][D*v+L],O=Y>=0&&Y<N.bands.length?N.bands[Y].fill:null,H=typeof O=="number"?O:Y<0||O==="outside"?z:A;R[(T*v+D)*w.width+J*v+L]=H}}),p&&_>=0){const B=w.cels[_][M];for(let K=0;K<E.h;K++)for(let J=0;J<E.w;J++)B[(b.mapRow*v+K)*w.width+J]=E.px[K*E.w+J]}}})}}if(r.v==="cut"){if(i.done(),Ol(i,"family cut",["textures"]),!l.terrain.length)throw new C(t.line,t.col,"family cut: lay out the coverage map first (family coverage), then paint it");if(!l.geometry.bands.length)throw new C(t.line,t.col,"family cut: the band's widths say what to keep from the map (family band … draw=off first)");const u=i.choice("textures",["on","off"],"off")==="on",h={cols:l.mapCols,rows:l.mapRows,cells:l.terrain},d=Qr(f,h),p=T0(f).filter(y=>!d[y]).map(y=>f.variants[y].name);if(p.length)throw new C(t.line,t.col,`family cut: the map has no tile of ${p.join(", ")} (lay it out again with family coverage)`);return{text:`family cut textures=${u?"on":"off"}`,op:ve(y=>{q_(y,u)})}}throw new C(r.line,r.col,"family: expected band, texture, detach, attach, coverage or cut")}},hS=/^(-?\d+),(-?\d+)$/,dS={name:"overlay",summary:"overlay set [mode=cycle|pingpong|wave|sparkle] [on=outside|inside|all] [anchor=<x,y>|centre] [spread=<dx>x<dy>] [every=<n>] [rest=<ticks>] [seed=<n>] (how an overlay plays over a map's tiles)",normalise(t,a){const s=Qe(t,a);if(!s.overlay)throw new C(t.line,t.col,`overlay: '${s.name}' is not an overlay (new overlay <name> <W>x<H>)`);const l=new _e(t,["mode","on","anchor","spread","every","rest","seed"]);zv(l);const i=l.take("word","set");if(i.v!=="set")throw new C(i.line,i.col,"overlay: expected set");l.done();const r=s.overlay,f=l.choice("mode",[...f$],r.mode),u=l.choice("on",["outside","inside","all"],r.on);let h=r.anchor;const d=l.opts.get("anchor");if(d){const $=hS.exec(d.value);if(d.value==="centre"||d.value==="center")h=null;else if($)h=[Number($[1]),Number($[2])];else throw new C(d.line,d.vcol,"anchor= must be a pixel x,y in the tile, or centre")}let p=r.spread;const y=l.opts.get("spread");if(y){const $=/^(\d+)x(\d+)$/.exec(y.value);if(!$)throw new C(y.line,y.vcol,"spread= must be like 4x2 (pixels either way across and down)");p=[Number($[1]),Number($[2])]}const w=Mt(l,"every",1,1e3,r.every),x=Mt(l,"rest",0,1e5,r.rest),b=Mt(l,"seed",1,2147483647,r.seed),v={mode:f,on:u,anchor:h,spread:[p[0],p[1]],every:w,rest:x,seed:b};return{text:`overlay set mode=${f} on=${u} anchor=${h?`${h[0]},${h[1]}`:"centre"} spread=${p[0]}x${p[1]} every=${w} rest=${x} seed=${b}`,op:ve($=>{$.overlay={...v,anchor:v.anchor?[v.anchor[0],v.anchor[1]]:null,spread:[v.spread[0],v.spread[1]]}})}}};for(const t of[fS,dS])Le(t);function Ul(t,a){const s=Qe(t,a);if(!s.map)throw new C(t.line,t.col,`${t.name}: '${s.name}' is not a map (new map <name> <C>x<R> tile=<T>)`);return s}function al(t,a,s){const l=t.layers.findIndex(r=>r.name===a.v),i=t.layers.filter(r=>r.map&&s.includes(r.map.kind)).map(r=>r.name);if(l<0||!s.includes(t.layers[l].map?.kind??""))throw new C(a.line,a.col,`no ${s.join(" or ")} layer '${a.v}' (${i.length?i.join(", "):`none yet: layer add <name> ${s[0]==="terrain"?"terrain=<family>":s[0]}`})`);if(t.layers[l].locked)throw new C(a.line,a.col,`layer '${a.v}' is locked`);return l}function od(t,a,s){const l=t.opts.get("layer");if(l)return al(a,{v:l.value,line:l.line,col:l.vcol},["tiles","objects"]);const i=et(a,s).layer,r=a.layers[i];if(r.map?.kind!=="tiles"&&r.map?.kind!=="objects")throw new C(t.cmd.line,t.cmd.col,`${t.cmd.name}: your layer '${r.name}' is not a tiles or objects layer (give layer=<name>)`);if(r.locked)throw new C(t.cmd.line,t.cmd.col,`layer '${r.name}' is locked`);return i}function ei(t,a,s){if(!/^-?\d+$/.test(t.value)||Number(t.value)<a||Number(t.value)>s)throw new C(t.line,t.vcol,`${t.key}= must be a whole number ${a}..${s}`);return Number(t.value)}const id=(t,a)=>{const s=t.opts.get("seed");return s?ei(s,1,2147483647):a.newSeed()},Ts=(t,a,s)=>a>=0&&s>=0&&a<t.width&&s<t.height,uh=["rect","ellipse","brush","fill","paint","clear"],mS={name:"terrain",summary:"terrain <layer> rect <x,y> <W>x<H> | ellipse <x,y> <W>x<H> | brush <x,y>... [size=<n>] | fill <x,y> | paint <x,y> << rows of # and . >> | clear [erase] (paints a terrain layer; the family's scheme picks the edge tiles)",normalise(t,a){const s=Ul(t,a),l=new _e(t,["size"],["erase"]),i=l.take("word","a terrain layer"),r=al(s,i,["terrain"]),f=l.take("word",uh.join(", "));if(!uh.includes(f.v))throw new C(f.line,f.col,`terrain: expected ${uh.join(", ")}`);const u=l.flags.length>0,h=u?ne:1,d=l.opts.get("size");if(d&&f.v!=="brush")throw new C(d.line,d.col,"size= goes with brush");const p=u?" erase":"";let y=[],w;if(f.v==="rect"||f.v==="ellipse"){const x=l.take("point","a corner x,y"),b=l.take("size","a size WxH");if(l.done(),b.w<1||b.h<1)throw new C(b.line,b.col,"terrain: size must be at least 1x1");y=f.v==="rect"?si(x.x,x.y,b.w,b.h,!0):ic(x.x,x.y,x.x+b.w-1,x.y+b.h-1,!0),w=`${f.v} ${x.x},${x.y} ${b.w}x${b.h}`}else if(f.v==="brush"){const x=[];for(const $ of l.rest()){if($.t!=="point")throw new C($.line,$.col,"terrain brush: expected a point x,y");x.push(Cn($))}if(!x.length)throw new C(f.line,f.col+6,"terrain brush: expected a point x,y");const b=d?ei(d,1,32):1,v=-Math.floor((b-1)/2);for(const[$,_]of Wr(x,!1))for(let j=0;j<b;j++)for(let N=0;N<b;N++)y.push([$+v+N,_+v+j]);w=`brush ${x.map(xa).join(" ")} size=${b}`}else if(f.v==="fill"){const x=l.take("point","a start x,y");if(l.done(),!Ts(s,x.x,x.y))throw new C(x.line,x.col,`terrain fill: ${x.x},${x.y} is off the ${s.width}x${s.height} map`);return w=`fill ${x.x},${x.y}`,{text:`terrain ${i.v} ${w}${p}`,op:ve(b=>H0({width:b.width,height:b.height,wrap:!1,pixels:b.cels[r][0]},x.x,x.y,h,!1,4))}}else if(f.v==="paint"){const x=l.take("point","a top-left x,y"),b=l.take("block","a block of rows: '#' terrain, '-' not, '.' leave");if(l.done(),u)throw new C(l.flags[0].line,l.flags[0].col,"terrain paint: the rows say what is terrain ('#') and what is not ('-')");const v=[];return b.rows.forEach(($,_)=>[...$.text].forEach((j,N)=>{if(j==="#")v.push([x.x+N,x.y+_,1]);else if(j==="-")v.push([x.x+N,x.y+_,ne]);else if(j!==".")throw new C($.line,$.col+N,`terrain paint: '${j}' is not '#' (terrain), '-' (not) or '.' (leave)`)})),{text:`terrain ${i.v} paint ${x.x},${x.y} <<
|
|
32
|
+
${b.rows.map($=>` ${$.text}
|
|
33
|
+
`).join("")}>>`,op:ve($=>{const _=$.cels[r][0];for(const[j,N,M]of v)Ts($,j,N)&&(_[N*$.width+j]=M)})}}else{if(l.done(),u)throw new C(l.flags[0].line,l.flags[0].col,"terrain clear takes no erase");return{text:`terrain ${i.v} clear`,op:ve(x=>{x.cels[r][0].fill(ne)})}}return{text:`terrain ${i.v} ${w}${p}`,op:ve(x=>{const b=x.cels[r][0];for(const[v,$]of y)Ts(x,v,$)&&(b[$*x.width+v]=h)})}}};function Ev(t){if(t.t!=="word")throw new C(t.line,t.col,"expected an asset name (or <family>.<variant>)");const a=/^([a-z][a-z0-9_-]*)(?:\.([a-z][a-z0-9_]*))?$/.exec(t.v);if(!a)throw new C(t.line,t.col,`'${t.v}' is not an asset name (or <family>.<variant>)`);return{name:a[1],variant:a[2]??null}}function kh(t,a,s,l,i,r){const f=t.opts.get("cells"),u=t.opts.get("anchor");if(f||u){if(!f||!u)throw new C((f??u).line,(f??u).col,"give cells= and anchor= together (or neither: they are read from the asset)");const p=/^(\d+)x(\d+)$/.exec(f.value);if(!p||Number(p[1])<1||Number(p[2])<1||Number(p[1])>64||Number(p[2])>64)throw new C(f.line,f.vcol,"cells= must be a footprint like 2x2");const y=/^(\d+),(\d+)$/.exec(u.value),w=Number(p[1]),x=Number(p[2]);if(!y||Number(y[1])>=w||Number(y[2])>=x)throw new C(u.line,u.vcol,`anchor= must be a cell of the ${w}x${x} footprint, like 0,${x-1}`);return{cols:w,rows:x,anchor:[Number(y[1]),Number(y[2])]}}const h=a.asset?.(s);if(!h)throw new C(i.line,i.col,`no asset '${s}' to place`);if(l!==null){if(!h.family)throw new C(i.line,i.col,`'${s}' is not a family, so it has no variant '${l}'`);return{cols:1,rows:1,anchor:[0,0]}}if(h.family||h.overlay||h.map)throw new C(i.line,i.col,`'${s}' is a ${h.kind}: ${h.family?"paint it as a terrain layer (layer add <name> terrain="+s+"), or place one of its variants by name ("+s+".<variant>)":h.overlay?"add it as an overlay layer":"maps do not nest"}`);if(r==="tiles"&&(h.width%h.cellW||h.height%h.cellH))throw new C(i.line,i.col,`'${s}' is ${h.width}x${h.height}, not whole cells of ${h.cellW}x${h.cellH}`);const d=ga(h);return{cols:d.cols,rows:d.rows,anchor:d.anchor}}function Tv(t){return`cells=${t.cols}x${t.rows} anchor=${t.anchor[0]},${t.anchor[1]}`}function Hs(t,a){const s=t.map;let l=s.entries.findIndex(i=>i.name===a.name&&i.variant===a.variant&&i.cols===a.cols&&i.rows===a.rows&&i.anchor[0]===a.anchor[0]&&i.anchor[1]===a.anchor[1]&&!i.exact==!a.exact);return l<0&&(s.entries.push({...a,anchor:[a.anchor[0],a.anchor[1]]}),l=s.entries.length-1),l}function Ov(t,a,s,l,i,r,f){const u=el({...s},l,i);if(u.x<0||u.y<0||u.x+u.w>t.width||u.y+u.h>t.height)throw new C(r.line,r.col,`the ${s.cols}x${s.rows} footprint at ${u.x},${u.y} runs off the ${t.width}x${t.height} map`);const{grid:h,placed:d}=Bs(t,a);for(let p=u.y;p<u.y+u.h;p++)for(let y=u.x;y<u.x+u.w;y++){const w=h[p*t.width+y];if(w<0)continue;const x=d[w];if(f&&x.x===f.x&&x.y===f.y&&x.layer===f.layer)continue;const b=t.map.entries[x.entry];throw new C(r.line,r.col,`${y},${p} is taken by ${b.name}${b.variant?`.${b.variant}`:""} at ${x.x},${x.y} (on layer ${t.layers[x.layer].name})`)}}const pS={name:"place",summary:"place <asset>|<family>.<variant> <x,y> [layer=<tiles or objects layer>] [cells=<C>x<R> anchor=<x,y>] (by its anchor cell; footprints may not overlap)",normalise(t,a){const s=Ul(t,a),l=new _e(t,["layer","cells","anchor"]),i=l.take("word","an asset name"),r=Ev(i),f=l.take("point","the cell x,y for its anchor");l.done();const u=od(l,s,a.by),h=s.layers[u].map.kind;if(r.variant&&h!=="tiles")throw new C(i.line,i.col,"a family's variant goes on a tiles layer");const d=kh(l,a,r.name,r.variant,i,h);Ov(s,u,d,f.x,f.y,f);const p={name:r.name,variant:r.variant,...d};return{text:`place ${i.v} ${f.x},${f.y} layer=${s.layers[u].name} ${Tv(d)}`,op:ve(y=>{y.cels[u][0][f.y*y.width+f.x]=Hs(y,p)})}}};function Av(t,a,s,l){const i=t.opts.get("layer"),r=i?[od(t,a,s)]:a.layers.map((f,u)=>u).filter(f=>a.layers[f].map?.kind==="objects"||a.layers[f].map?.kind==="tiles").reverse();for(const f of r){const{grid:u,placed:h}=Bs(a,f),d=Ts(a,l.x,l.y)?u[l.y*a.width+l.x]:-1;if(d<0)continue;const p=h[d];if(!(p.layer!==f&&i)){if(a.layers[p.layer].locked)throw new C(l.line,l.col,`layer '${a.layers[p.layer].name}' is locked`);return{li:p.layer,x:p.x,y:p.y,entry:a.map.entries[p.entry]}}}throw new C(l.line,l.col,`nothing is placed at ${l.x},${l.y}${i?` on layer ${i.value}`:""}`)}const yS={name:"move",summary:"move <x,y> <x,y> [layer=<layer>] (moves what is placed at the first cell so its anchor is at the second)",normalise(t,a){const s=Ul(t,a),l=new _e(t,["layer"]),i=l.take("point","a cell x,y with something placed on it"),r=l.take("point","the cell x,y for its anchor");l.done();const f=Av(l,s,a.by,i);return Ov(s,f.li,f.entry,r.x,r.y,r,{x:f.x,y:f.y,layer:f.li}),{text:`move ${f.x},${f.y} ${r.x},${r.y} layer=${s.layers[f.li].name}`,op:ve(u=>{const h=u.cels[f.li][0],d=h[f.y*u.width+f.x];h[f.y*u.width+f.x]=ne,h[r.y*u.width+r.x]=d})}}},gS={name:"remove",summary:"remove <x,y> [layer=<layer>] (takes away what is placed on that cell)",normalise(t,a){const s=Ul(t,a),l=new _e(t,["layer"]),i=l.take("point","a cell x,y with something placed on it");l.done();const r=Av(l,s,a.by,i);return{text:`remove ${r.x},${r.y} layer=${s.layers[r.li].name}`,op:ve(f=>{f.cels[r.li][0][r.y*f.width+r.x]=ne})}}};function Rw(t){const a=t.layers.find(s=>s.name==="band");a&&(a.locked=!1)}function wS(t,a,s,l,i){const r=new nn(l,7170424),f=new Map,u=w=>f.get(w)??i(w),h=t.reduce((w,x)=>w+x.weight,0),d=new Map(t.map(w=>[w.name,0])),p=w=>Math.max(0,w.weight*a.length-d.get(w.name)*h),y=(w,x)=>{const b=w.reduce(($,_)=>$+x(_),0);if(!b)return null;let v=r.nextInt(b);for(const $ of w){if(v<x($))return $;v-=x($)}return null};return a.map(w=>{const x=w%s,b=x>0?u(w-1):null,v=u(w-s),$=x>0?u(w-s-1):null,_=t.length===2?b&&b===v&&b===$?[b]:[]:[b,v],j=new Set(_.filter(z=>!!z)),N=t.filter(z=>!j.has(z.name)),M=N.length?N:t,A=y(M,p)??y(M,z=>z.weight);return f.set(w,A.name),d.set(A.name,d.get(A.name)+1),A.name})}const vS={name:"tiles",summary:"tiles <tiles layer> fill <asset>|<family>.<variant>|mix=<tile>:<weight>,... [<x,y> <W>x<H>] [replace] [variants=spread|named] [seed=] (lays a one-cell tile on every empty cell of the layer, or of the box; replace also covers one-cell tiles already there; the map picks among the tile's texture variants. mix=: a seeded scatter of several tiles by weight, no two equal neighbours where it can help it; each tile's weight is shared with its texture variants the mix does not name, unless variants=named; each cell shows the tile drawn for it)",normalise(t,a){const s=Ul(t,a),l=new _e(t,["cells","anchor","mix","seed","variants"],["replace"]),i=l.take("word","a tiles layer"),r=al(s,i,["tiles"]),f=l.take("word","fill");if(f.v!=="fill")throw new C(f.line,f.col,"tiles: expected fill");const u=l.opts.get("mix"),h=u?null:l.take("word","an asset name (or mix=<tile>:<weight>,...)"),d=h?Ev(h):null;let p={x:0,y:0,w:s.width,h:s.height};if(l.peek()?.t==="point"){const R=l.take("point","a corner x,y"),B=l.take("size","a size WxH");if(B.w<1||B.h<1)throw new C(B.line,B.col,"tiles fill: the box must be at least 1x1");p={x:R.x,y:R.y,w:B.w,h:B.h}}l.done();const y=l.flags.some(R=>R.v==="replace");for(const R of["seed","variants"])if(!u&&l.opts.get(R))throw new C(l.opts.get(R).line,l.opts.get(R).col,`${R}= goes with mix=`);const w=l.opts.get("variants");if(w&&w.value!=="spread"&&w.value!=="named")throw new C(w.line,w.vcol,"variants= is spread (a tile's weight shared with its texture variants) or named (only the tiles the mix names)");const x=u?cv(u):null,b=x?w?.value==="named"?x:rv(x,a):null,v=kh(l,a,b?b[0].name:d.name,d?.variant??null,h??u,"tiles");if(b&&!l.opts.get("cells"))for(const R of b){const B=kh(l,a,R.name,null,u,"tiles"),K=a.asset?.(R.name);if(B.cols!==1||B.rows!==1||K&&K.kind!=="tile")throw new C(u.line,u.vcol,`mix= takes one-cell tiles; '${R.name}' is ${K&&K.kind!=="tile"?`a ${K.kind}`:`${B.cols}x${B.rows} cells`}`)}if(v.cols!==1||v.rows!==1)throw new C(h.line,h.col,`tiles fill lays one-cell tiles; '${d.name}' is ${v.cols}x${v.rows} cells (place it instead)`);const{grid:$,placed:_}=Bs(s,r),j=[];for(let R=Math.max(0,p.y);R<Math.min(s.height,p.y+p.h);R++)for(let B=Math.max(0,p.x);B<Math.min(s.width,p.x+p.w);B++){const K=$[R*s.width+B];if(K<0){j.push(R*s.width+B);continue}const J=_[K],T=s.map.entries[J.entry];y&&T.cols===1&&T.rows===1&&J.x===B&&J.y===R&&j.push(R*s.width+B)}const N=`${p.x},${p.y} ${p.w}x${p.h} ${Tv(v)}${y?" replace":""}`;if(!b){const R={name:d.name,variant:d.variant,...v};return{text:`tiles ${i.v} fill ${h.v} ${N}`,op:ve(B=>{const K=Hs(B,R),J=B.cels[r][0];for(const T of j)J[T]=K})}}const M=id(l,a),A=new Set(j),z=R=>{if(R<0||A.has(R))return null;const B=$[R];return B<0?null:s.map.entries[_[B].entry].name},E=wS(b,j,s.width,M,z);return{text:`tiles ${i.v} fill mix=${b.map(R=>`${R.name}:${R.weight}`).join(",")} ${N} variants=named seed=${M}`,op:ve(R=>{const B=new Map,K=T=>B.get(T)??B.set(T,Hs(R,{name:T,variant:null,...v,exact:!0})).get(T),J=R.cels[r][0];j.forEach((T,D)=>{J[T]=K(E[D])})})}}};function qv(t){const a=[t[0]];for(let s=1;s<t.length;s++){let[l,i]=a[a.length-1];const[r,f]=t[s];for(;l!==r;)l+=Math.sign(r-l),a.push([l,i]);for(;i!==f;)i+=Math.sign(f-i),a.push([l,i])}return a}const xS={name:"road",summary:"road <terrain layer> <x,y> <x,y> [<x,y>...] [width=<n>] (lays the terrain along x then y between each pair of points)",normalise(t,a){const s=Ul(t,a),l=new _e(t,["width"]),i=l.take("word","a terrain layer (a path family)"),r=al(s,i,["terrain"]),f=[];for(const p of l.rest()){if(p.t!=="point")throw new C(p.line,p.col,"road: expected a point x,y");f.push(Cn(p))}if(f.length<2)throw new C(t.line,t.col,"road: give at least two points");const u=l.opts.get("width"),h=u?ei(u,1,8):1,d=qv(f);return{text:`road ${i.v} ${f.map(xa).join(" ")} width=${h}`,op:ve(p=>{const y=p.cels[r][0];for(const[w,x]of d)for(let b=0;b<h;b++)for(let v=0;v<h;v++)Ts(p,w+v,x+b)&&(y[(x+b)*p.width+w+v]=1)})}}},Rv=/^(\d+)x(\d+):(\d+),(\d+)$/;function bS(t,a,s){const l=new _e(t,["count","on","off","minDist","layer","seed","fp"]),i=l.take("word","the assets to scatter (house or tree,bush)"),r=i.v.split(",");for(const T of r)if(!/^[a-z][a-z0-9_-]*$/.test(T))throw new C(i.line,i.col,`'${T}' is not an asset name`);const f=l.peek()?.t==="point"?{p:l.take("point","a corner"),s:l.take("size","a size in cells")}:null;l.done();const u=od(l,s,a.by),h=l.opts.get("count");if(!h)throw new C(t.line,t.col,"scatter: missing count=<n>");const d=ei(h,1,1e4),p=l.opts.get("minDist"),y=p?ei(p,0,512):1,w=l.opts.get("on"),x=w?al(s,{v:w.value,line:w.line,col:w.vcol},["terrain"]):-1,b=l.opts.get("off"),v=b?al(s,{v:b.value,line:b.line,col:b.vcol},["terrain"]):-1,$=l.opts.get("fp");let _;if($){const T=$.value.split("/");if(T.length!==r.length)throw new C($.line,$.vcol,"fp= needs one footprint per asset, like 2x2:0,1/1x1:0,0");_=T.map(D=>{const L=Rv.exec(D);if(!L||Number(L[3])>=Number(L[1])||Number(L[4])>=Number(L[2]))throw new C($.line,$.vcol,"fp= footprints look like 2x2:0,1 (cells, then the anchor)");return{cols:Number(L[1]),rows:Number(L[2]),anchor:[Number(L[3]),Number(L[4])]}})}else _=r.map(T=>{const D=a.asset?.(T);if(!D)throw new C(i.line,i.col,`no asset '${T}' to scatter`);const L=ga(D);return{cols:L.cols,rows:L.rows,anchor:L.anchor}});const j=id(l,a),N=f?f.p.x:0,M=f?f.p.y:0,A=f?f.s.w:s.width,z=f?f.s.h:s.height,E=new nn(j,23719),R={...s,cels:s.cels.map((T,D)=>D===u?[T[0].slice()]:T),map:{tile:s.map.tile,entries:s.map.entries.map(T=>({...T}))}},B=x>=0?s.cels[x][0]:null,K=v>=0?s.cels[v][0]:null,J=[];for(let T=0;J.length<d&&T<d*40;T++){const D=E.nextInt(r.length),L=_[D],Y=N+E.nextInt(A),O=M+E.nextInt(z),H=el({name:r[D],...L},Y,O);if(H.x<N||H.y<M||H.x+H.w>N+A||H.y+H.h>M+z||H.x<0||H.y<0||H.x+H.w>s.width||H.y+H.h>s.height)continue;let G=!0;for(let W=H.y;W<H.y+H.h&&G;W++)for(let se=H.x;se<H.x+H.w;se++)if(B&&B[W*s.width+se]!==1||K&&K[W*s.width+se]===1){G=!1;break}if(!G||J.some(W=>Math.max(Math.abs(W.x-Y),Math.abs(W.y-O))<y))continue;const{grid:Z}=Bs(R,u);for(let W=H.y;W<H.y+H.h&&G;W++)for(let se=H.x;se<H.x+H.w;se++)if(Z[W*s.width+se]>=0){G=!1;break}G&&(R.cels[u][0][O*s.width+Y]=Hs(R,{name:r[D],variant:null,...L}),J.push({x:Y,y:O,k:D}))}return{text:`scatter ${i.v}${f?` ${f.p.x},${f.p.y} ${f.s.w}x${f.s.h}`:""} count=${d}${w?` on=${w.value}`:""}${b?` off=${b.value}`:""} minDist=${y} layer=${s.layers[u].name} fp=${_.map(T=>`${T.cols}x${T.rows}:${T.anchor[0]},${T.anchor[1]}`).join("/")} seed=${j}`,op:ve(T=>{for(const D of J)T.cels[u][0][D.y*T.width+D.x]=Hs(T,{name:r[D.k],variant:null,..._[D.k]})})}}function Dv(t,a,s,l=2,i=!0){const r=(f,u)=>f<0||u<0||f>=a||u>=s?0:t[u*a+f];for(let f=0;f<l;f++){const u=t.slice();for(let h=0;h<s;h++)for(let d=0;d<a;d++){let p=0;for(let y=-1;y<=1;y++)for(let w=-1;w<=1;w++)p+=r(d+w,h+y);u[h*a+d]=p>=5?1:0}t.set(u)}for(let f=0;f<4;f++){let u=!1;for(let h=0;h<s;h++)for(let d=0;d<a;d++){const p=t[h*a+d];[r(d+1,h),r(d-1,h),r(d,h+1),r(d,h-1)].filter(w=>w===p).length<2&&(t[h*a+d]=p?0:1,u=!0)}if(!u)break}if(i)for(let f=0;f<s;f++)for(let u=0;u<a;u++)(u===0||f===0||u===a-1||f===s-1)&&(t[f*a+u]=0)}function Dw(t,a,s,l){const i=Math.floor(t/s)+2,r=Math.floor(a/s)+2,f=Array.from({length:i*r},()=>l.nextInt(256)),u=new Int32Array(t*a);for(let h=0;h<a;h++)for(let d=0;d<t;d++){const p=Math.floor(d/s),y=Math.floor(h/s),w=d%s,x=h%s,b=f[y*i+p],v=f[y*i+p+1],$=f[(y+1)*i+p],_=f[(y+1)*i+p+1];u[h*t+d]=Math.floor(((b*(s-w)+v*w)*(s-x)+($*(s-w)+_*w)*x)/(s*s))}return u}function $S(t,a,s,l=2){const i=Dw(t,a,4,s),r=Dw(t,a,2,s),f=new Uint8Array(t*a);for(let u=0;u<a;u++)for(let h=0;h<t;h++){const d=2*h-(t-1),p=2*u-(a-1),y=Math.floor(d*d*256/((t-1-2*l)**2||1)+p*p*256/((a-1-2*l)**2||1)),w=(i[u*t+h]*3+r[u*t+h])/4;f[u*t+h]=w-128+200-y>0?1:0}return Dv(f,t,a,2,!0),f}function _h(t,a,s,l){const i=t.slice();for(let r=0;r<s;r++)for(let f=0;f<a;f++)if(t[r*a+f])for(let u=-l;u<=l&&i[r*a+f];u++)for(let h=-l;h<=l;h++){const d=f+h,p=r+u;if(d<0||p<0||d>=a||p>=s||!t[p*a+d]){i[r*a+f]=0;break}}return i}const fh=["island","village","dungeon"];function Uv(t,a,s,l,i){const r=new nn(l,1766);if(t==="dungeon"){const w=new Uint8Array(a*s),x=[];for(let b=0;b<200&&x.length<Math.max(3,Math.floor(a*s/90));b++){const v=4+r.nextInt(5),$=3+r.nextInt(4),_=1+r.nextInt(Math.max(1,a-v-2)),j=1+r.nextInt(Math.max(1,s-$-2));x.some(([N,M,A,z])=>_<N+A+2&&N<_+v+2&&j<M+z+2&&M<j+$+2)||x.push([_,j,v,$])}x.sort((b,v)=>b[0]-v[0]);for(const[b,v,$,_]of x)for(let j=0;j<_;j++)for(let N=0;N<$;N++)w[(v+j)*a+b+N]=1;for(let b=1;b<x.length;b++){const[v,$,_,j]=x[b-1],[N,M,A,z]=x[b];for(const[E,R]of qv([[v+(_>>1),$+(j>>1)],[N+(A>>1),M+(z>>1)]]))w[R*a+E]=1,R+1<s-1&&(w[(R+1)*a+E]=1)}return[w,...Array.from({length:i-1},()=>new Uint8Array(a*s))]}const f=$S(a,s,r,t==="village"?1:2);if(t==="island")return[f,...Array.from({length:i-1},()=>new Uint8Array(a*s))];const u=_h(f,a,s,2);Dv(u,a,s,1,!0);const h=new Uint8Array(a*s),d=_h(u,a,s,1),p=Math.floor(a/2)+r.nextInt(5)-2,y=Math.floor(s/2)+r.nextInt(5)-2;for(let w=0;w<a;w++)d[y*a+w]&&(h[y*a+w]=1);for(let w=0;w<s;w++)d[w*a+p]&&(h[w*a+p]=1);return[f,u,h,...Array.from({length:Math.max(0,i-3)},()=>new Uint8Array(a*s))].slice(0,Math.max(1,i))}function kS(t,a,s,l){const[i,r,f]=Uv(t,a,s,l,3);return t==="village"?r.map((u,h)=>u&&!f[h]?1:0):_h(i,a,s,1)}const _S=/^([a-z][a-z0-9_-]*)(?::(\d+))?$/;function jS(t,a,s,l,i){const r=new nn(i,2846),f=t.width,u=t.height,h=new Uint8Array(f*u),{grid:d}=Bs(t,a);for(let w=0;w<f*u;w++)d[w]>=0&&(h[w]=1);const p=s.map((w,x)=>({o:w,k:x})).sort((w,x)=>x.o.fp.cols*x.o.fp.rows-w.o.fp.cols*w.o.fp.rows||w.k-x.k),y=[];for(const{o:w,k:x}of p)for(let b=0;b<w.count;b++)for(let v=0;v<400;v++){const $=r.nextInt(f),_=r.nextInt(u),j=el({name:w.name,...w.fp},$,_);if(j.x<0||j.y<0||j.x+j.w>f||j.y+j.h>u)continue;let N=!0;for(let M=j.y-1;M<=j.y+j.h&&N;M++)for(let A=j.x-1;A<=j.x+j.w;A++){const z=A>=j.x&&A<j.x+j.w&&M>=j.y&&M<j.y+j.h;if(z&&(!l[M*f+A]||h[M*f+A])){N=!1;break}if(!z&&Ts(t,A,M)&&h[M*f+A]){N=!1;break}}if(N){for(let M=j.y;M<j.y+j.h;M++)for(let A=j.x;A<j.x+j.w;A++)h[M*f+A]=1;y.push({x:$,y:_,k:x});break}}return y}const SS={name:"map",summary:"map gen island|village|dungeon [layers=<terrain layer>,..] [objects=<asset>[:<n>],..] [layer=<objects layer>] [seed=<n>] (lays out the terrain layers for a quick scene and stands the objects on it (default: the objects the manifest says the map uses); edit it after)",normalise(t,a){const s=Ul(t,a),l=new _e(t,["layers","seed","objects","layer","fp"]),i=l.take("word","gen");if(i.v!=="gen")throw new C(i.line,i.col,"map: expected gen");const r=l.take("word",fh.join(", "));if(!fh.includes(r.v))throw new C(r.line,r.col,`map gen: expected ${fh.join(", ")}`);l.done();const f=l.opts.get("layers"),u=s.layers.flatMap(z=>z.map?.kind==="terrain"?[z.name]:[]),h=f?f.value.split(","):u.slice(0,r.v==="village"?3:1);if(!h.length)throw new C(t.line,t.col,"map gen: the map has no terrain layers (layer add <name> terrain=<family>)");const d=h.map(z=>al(s,{v:z,line:f?.line??t.line,col:f?.vcol??t.col},["terrain"])),p=l.opts.get("objects"),y=p?{line:p.line,col:p.vcol}:{line:t.line,col:t.col};let w=[];if(p)w=p.value.split(",").map(z=>{const E=_S.exec(z);if(!E)throw new C(p.line,p.vcol,"objects= is a list like well,house:2,tree:3");return{name:E[1],count:E[2]?Math.max(1,Math.min(64,Number(E[2]))):1}});else{const z=a.defaults?.mapObjects?.(s.name)??[];s.layers.some(R=>R.map?.kind==="objects")&&(w=z.filter(R=>{const B=a.asset?.(R);return!!B&&!B.map&&!B.family&&!B.overlay}).map(R=>({name:R,count:1})))}const x=id(l,a),b=Uv(r.v,s.width,s.height,x,d.length),v=z=>d.forEach((E,R)=>{z.cels[E][0].set(Uint16Array.from(b[R],B=>B?1:ne))});if(!w.length){if(l.opts.get("layer")||l.opts.get("fp"))throw new C(t.line,t.col,"map gen: layer= and fp= go with objects=");return{text:`map gen ${r.v} layers=${h.join(",")} seed=${x}`,op:ve(v)}}const $=l.opts.get("layer");let _;if($)_=al(s,{v:$.value,line:$.line,col:$.vcol},["objects"]);else if(_=s.layers.findIndex(z=>z.map?.kind==="objects"),_<0)throw new C(y.line,y.col,"map gen: the map has no objects layer to stand objects on (layer add <name> objects)");if(s.layers[_].locked)throw new C(y.line,y.col,`layer '${s.layers[_].name}' is locked`);const j=l.opts.get("fp");let N;if(j){const z=j.value.split("/");if(z.length!==w.length)throw new C(j.line,j.vcol,"fp= needs one footprint per object, like 2x2:0,1/1x1:0,0");N=z.map(E=>{const R=Rv.exec(E);if(!R||Number(R[3])>=Number(R[1])||Number(R[4])>=Number(R[2]))throw new C(j.line,j.vcol,"fp= footprints look like 2x2:0,1 (cells, then the anchor)");return{cols:Number(R[1]),rows:Number(R[2]),anchor:[Number(R[3]),Number(R[4])]}})}else N=w.map(z=>{const E=a.asset?.(z.name);if(!E)throw new C(y.line,y.col,`map gen: no asset '${z.name}' to stand on the map`);const R=ga(E);return{cols:R.cols,rows:R.rows,anchor:R.anchor}});const M=w.map((z,E)=>({...z,fp:N[E]})),A=jS(s,_,M,kS(r.v,s.width,s.height,x),x);return{text:`map gen ${r.v} layers=${h.join(",")} objects=${w.map(z=>z.count>1?`${z.name}:${z.count}`:z.name).join(",")} layer=${s.layers[_].name} fp=${N.map(z=>`${z.cols}x${z.rows}:${z.anchor[0]},${z.anchor[1]}`).join("/")} seed=${x}`,op:ve(z=>{v(z);for(const E of A)z.cels[_][0][E.y*z.width+E.x]=Hs(z,{name:M[E.k].name,variant:null,...M[E.k].fp})})}}},NS=new Set([".","b","r","x"]),MS={name:"footprint",summary:"footprint <C>x<R> [at=<cx,cy>] [anchor=<x,y>] [<< a row per cell row of the art: . b (blocks) r (roof: drawn above actors) x (both) >>] | footprint off",normalise(t,a){const s=Qe(t,a);if(s.map||s.family||s.overlay)throw new C(t.line,t.col,`footprint: a ${s.kind} is not placed on a map as an object`);const l=new _e(t,["at","anchor"]);if(l.peek()?.t==="word"&&l.peek().v==="off")return l.take("word","off"),l.done(),{text:"footprint off",op:ve(x=>{x.footprint=null})};if(s.width%s.cellW||s.height%s.cellH)throw new C(t.line,t.col,`footprint: the ${s.width}x${s.height} canvas is not whole cells of ${s.cellW}x${s.cellH} (new … cell=<W>x<H>)`);const[i,r]=oi(s),f=l.take("size","the footprint in cells, like 2x2"),u=l.peek()?.t==="block"?l.take("block","flag rows"):null;if(l.done(),f.w<1||f.h<1||f.w>i||f.h>r)throw new C(f.line,f.col,`footprint: ${f.w}x${f.h} must fit the art's ${i}x${r} cells`);const h=(x,b,v,$,_)=>{if(!x)return b;const j=/^(\d+),(\d+)$/.exec(x.value);if(!j||Number(j[1])>=$||Number(j[2])>=_)throw new C(x.line,x.vcol,`${x.key}= must be ${v} (x 0..${$-1}, y 0..${_-1})`);return[Number(j[1]),Number(j[2])]},d=h(l.opts.get("at"),[0,r-f.h],"the footprint's top-left art cell",i-f.w+1,r-f.h+1),p=h(l.opts.get("anchor"),[0,f.h-1],"a cell of the footprint",f.w,f.h);let y;if(u){if(y=u.rows.map(x=>x.text),y.length!==r||y.some(x=>x.length!==i))throw new C(u.line,u.col,`footprint: the flags are ${r} rows of ${i} (one per cell of the art)`);u.rows.forEach(x=>[...x.text].forEach((b,v)=>{if(!NS.has(b))throw new C(x.line,x.col+v,`footprint: '${b}' is not . b r or x`)}))}else y=Array.from({length:r},(x,b)=>Array.from({length:i},(v,$)=>$>=d[0]&&b>=d[1]&&$<d[0]+f.w&&b<d[1]+f.h?"b":".").join(""));const w={cols:f.w,rows:f.h,at:d,anchor:p,flags:y};return{text:`footprint ${f.w}x${f.h} at=${d[0]},${d[1]} anchor=${p[0]},${p[1]} <<
|
|
34
|
+
${y.map(x=>` ${x}
|
|
35
|
+
`).join("")}>>`,op:ve(x=>{x.footprint={...w,at:[d[0],d[1]],anchor:[p[0],p[1]],flags:[...y]}})}}},zS={name:"variant",summary:"variant of=<asset> [band=inherit|own] | variant off (this asset is a texture variant of another: maps pick among them cell by cell; check variant compares their colour mix; band=inherit: a family variant takes its band from the base, now and after every change to it, and overrides only the textures)",normalise(t,a){const s=Qe(t,a),l=new _e(t,["of","band"]);if(l.peek()?.t==="word"&&l.peek().v==="off")return l.take("word","off"),l.done(),{text:"variant off",op:ve(f=>{f.variantOf=null,f.family?.bandOf&&(delete f.family.bandOf,Rw(f))})};l.done();const i=l.opts.get("of");if(!i)throw new C(t.line,t.col,"variant: give of=<the asset this is a variant of> (or off)");if(!/^[a-z][a-z0-9_-]*$/.test(i.value))throw new C(i.line,i.vcol,`'${i.value}' is not an asset name`);if(i.value===s.name)throw new C(i.line,i.vcol,"an asset is not a variant of itself");if(s.map)throw new C(t.line,t.col,"variant: a map has no variants");const r=l.choice("band",["inherit","own"],"own");if(r==="inherit"){if(!s.family)throw new C(l.opts.get("band").line,l.opts.get("band").col,"variant: band=inherit is for a family's texture variant");const f=a.asset?.(i.value);if(f&&(!f.family||f.family.scheme!==s.family.scheme||f.family.tile!==s.family.tile))throw new C(i.line,i.vcol,`variant: '${i.value}' is not a ${s.family.scheme} family of ${s.family.tile}px tiles, so its band does not fit`)}return{text:`variant of=${i.value}${r==="inherit"?" band=inherit":""}`,op:ve(f=>{if(f.variantOf=i.value,!!f.family)if(r==="inherit"){f.family.bandOf=i.value;const u=f.layers.find(h=>h.name==="band");u&&(u.locked=!0)}else f.family.bandOf&&(delete f.family.bandOf,Rw(f))})}}};for(const t of[mS,vS,pS,yS,gS,xS,SS,MS,zS])Le(t);const Uw=Ds.get("scatter");Le({name:"scatter",summary:`${Uw.summary} | (maps) scatter <asset>[,<asset>..] [<x,y> <W>x<H>] count=<n> [on=<terrain layer>] [off=<terrain layer>] [minDist=<n>] [layer=<objects layer>] [seed=<n>]`,normalise(t,a){return a.doc?.map?bS(t,a,a.doc):Uw.normalise(t,a)}});const CS={name:"import",summary:`import <x,y> [from="<file>"] [blob=<sha256>] << rows of palette keys ('.' is transparent) >> | import <x,y> asset=<name> region=<x,y,WxH> [layer=<layer>] (an imported image's pixels, or a region of another asset's art (one layer of it, or its flat art); replaces the rectangle on your layer and frame)`,normalise(t,a){const s=at(t,a),l=new _e(t,["from","blob","asset","region","layer"]),i=l.take("point","a top-left corner x,y"),r=l.peek()?.t==="block"?l.take("block","the image's rows in a block"):null;l.done();let f=l.opts.get("from")?.value;const u=l.opts.get("blob");if(u&&!/^[0-9a-f]{8,64}$/.test(u.value))throw new C(u.line,u.vcol,"blob= is the image's sha256 in hex");const h=l.opts.get("asset");let d,p;if(h){for(const B of["from","blob"])if(l.opts.get(B))throw new C(l.opts.get(B).line,l.opts.get(B).col,`import: asset= takes no ${B}=`);if(r)throw new C(r.line,r.col,"import: asset= reads the rows from the asset");const v=a.asset?.(h.value);if(!v)throw new C(h.line,h.vcol,`import: no asset '${h.value}' to read (not this one)`);const $=l.opts.get("region"),_=$?Rk($.value):null;if(!$||!_)throw new C($?.line??t.line,$?.vcol??t.col,`import: give region=<x,y,WxH> of '${h.value}' (or "x,y WxH")`);const{x:j,y:N,w:M,h:A}=_;if(M<1||A<1||j+M>v.width||N+A>v.height)throw new C($.line,$.vcol,`import: region ${$.value} is outside '${v.name}' (${v.width}x${v.height})`);const z=l.opts.get("layer"),E=z?v.layers.findIndex(B=>B.name===z.value):-1;if(z&&E<0)throw new C(z.line,z.vcol,`import: '${v.name}' has no layer '${z.value}'`);const R=E>=0?v.cels[E][0]:Ce(v,0);d=Array.from({length:A},(B,K)=>Array.from({length:M},(J,T)=>{const D=R[(N+K)*v.width+j+T];if(D===ne)return".";const L=v.palette.entries[D].name,Y=s.palette.entries.findIndex(O=>O.name===L);if(Y<0)throw new C(h.line,h.vcol,`import: '${v.name}' uses ${L}, which palette '${s.palette.name}' does not have`);return s.palette.entries[Y].key}).join("")),p=d.map(()=>({line:t.line,col:t.col})),f=`${v.name}${E>=0?`:${v.layers[E].name}`:""} ${j},${N},${M}x${A}`}else{for(const v of["region","layer"])if(l.opts.get(v))throw new C(l.opts.get(v).line,l.opts.get(v).col,`import: ${v}= goes with asset=`);if(!r)throw new C(t.line,t.col,"import: expected the image's rows in a block (or asset= region=)");d=r.rows.map(v=>v.text),p=r.rows}const y=new Map(s.palette.entries.map((v,$)=>[v.key,$])),w=d.map((v,$)=>[...v].map((_,j)=>{if(_===".")return ne;const N=y.get(_);if(N===void 0)throw new C(p[$].line,p[$].col+j,`import: '${_}' is not a key in palette '${s.palette.name}'`);return N})),x=Math.max(0,...w.map(v=>v.length)),b=`${f?` from=${wa(f)}`:""}${u?` blob=${u.value}`:""}`;return{text:`import ${i.x},${i.y}${b} <<
|
|
36
|
+
${va(d)}>>`,op:ve((v,$)=>{const _=et(v,$),j=v.cels[_.layer][_.frame];w.forEach((N,M)=>{const A=i.y+M;if(!(A<0||A>=v.height))for(let z=0;z<x;z++){const E=i.x+z;E<0||E>=v.width||(j[A*v.width+E]=N[z]??ne)}})})}}};function ES(t,a){const s=t.width,l=t.height;t.cels=t.cels.map(i=>{const r=new Map;return i.map(f=>r.get(f)??r.set(f,rw(f,s,l,a)).get(f))});for(const i of Object.values(t.stamps))i.px=rw(i.px,i.w,i.h,a),i.w*=a,i.h*=a;t.width*=a,t.height*=a,t.cellW*=a,t.cellH*=a,t.notes=t.notes.map(i=>({...i,x:i.x*a,y:i.y*a,w:i.w*a,h:i.h*a})),t.pivot&&(t.pivot=[t.pivot[0]*a+(a>>1),t.pivot[1]*a+a-1]),t.ground!==null&&(t.ground=t.ground*a+a-1);for(const i of Object.keys(t.ctx))t.ctx[i]={...t.ctx[i],sel:null,mirror:null}}const TS={name:"scale",summary:"scale <n> (the whole document n times larger, nearest neighbour: every layer, frame and stamp, the cell grid, pivot, ground and notes; selections and symmetry are dropped)",normalise(t,a){const s=Qe(t,a),l=new _e(t,[]),i=l.take("int","a factor 2..8");if(l.done(),i.v<2||i.v>8)throw new C(i.line,i.col,"scale: the factor is 2..8");if(s.map||s.family)throw new C(t.line,t.col,`scale: a ${s.kind} is not scaled (its cells are tiles)`);if(s.width*i.v>4096||s.height*i.v>4096)throw new C(i.line,i.col,`scale: ${s.width*i.v}x${s.height*i.v} is over 4096`);return{text:`scale ${i.v}`,op:ve(r=>ES(r,i.v))}}},OS={name:"density",summary:"density of=<asset> d=<2|4|n> | density off (this asset is <asset> at n times its size: the density check reduces it and compares; exports write it as that level)",normalise(t,a){const s=Qe(t,a),l=new _e(t,["of","d"]);if(l.peek()?.t==="word"&&l.peek().v==="off")return l.take("word","off"),l.done(),{text:"density off",op:ve(h=>{h.densityOf=null})};l.done();const i=l.opts.get("of"),r=l.opts.get("d");if(!i||!r)throw new C(t.line,t.col,"density: give of=<the base asset> d=<times its size> (or off)");if(!/^[a-z][a-z0-9_-]*$/.test(i.value))throw new C(i.line,i.vcol,`'${i.value}' is not an asset name`);if(i.value===s.name)throw new C(i.line,i.vcol,"an asset is not a density of itself");if(s.map)throw new C(t.line,t.col,"density: a map has no densities");const f=gn(r,2,8);if(s.width%f||s.height%f)throw new C(r.line,r.vcol,`density: ${s.width}x${s.height} is not a whole ${f} times a base size`);const u=a.asset?.(i.value);if(u&&(u.width*f!==s.width||u.height*f!==s.height))throw new C(r.line,r.vcol,`density: '${i.value}' is ${u.width}x${u.height}; ${f} times that is ${u.width*f}x${u.height*f}, not ${s.width}x${s.height}`);return{text:`density of=${i.value} d=${f}`,op:ve(h=>{h.densityOf={of:i.value,d:f}})}}};for(const t of[CS,TS,OS])Le(t);const AS={name:"mark",summary:`mark <name> ["text"] (names this point on the tape; reviewed, approved and rejected set the asset's status)`,normalise(t,a){Qe(t,a);const s=new _e(t,[]),l=s.take("word","a mark name (reviewed, approved, rejected, or your own)"),i=s.peek()?.t==="string"?s.take("string","the text in quotes"):null;if(s.done(),!/^[a-z][a-z0-9_-]*$/.test(l.v))throw new C(l.line,l.col,"mark names use a-z, 0-9, _ and -, starting with a letter");const r=i?i.v.trim():"";if(i&&r.length>1e3)throw new C(i.line,i.col,"mark: the text is longer than 1000 characters");const f=a.seq;return{text:`mark ${l.v}${r?` ${wa(r)}`:""}`,op:ve((u,h)=>{u.marks=[...u.marks,{name:l.v,seq:f,by:h,text:r,art:v$(u)}]})}}};Le(AS);function Hv(t,a){if(!a.font)throw new C(t.line,t.col,`${t.name}: '${a.name}' is a ${a.kind}, not a font (new font <name> <W>x<H> chars=…)`);return a}function qS(t,a){if(!t)throw new C(a.line,a.col+a.name.length+1,'glyph: expected a character (a letter or digit, U+XXXX, or "c")');const s=t.t==="word"||t.t==="string"?t.v:t.t==="int"?String(t.v):"",l=/^U\+([0-9A-Fa-f]{1,6})$/.exec(s);if(t.t!=="string"&&l)return parseInt(l[1],16);if([...s].length===1&&(t.t==="string"||/^[A-Za-z0-9]$/.test(s)))return s.codePointAt(0);throw new C(t.line,t.col,`glyph: '${s}' is not one character (letters and digits as themselves; anything else as U+XXXX or "c")`)}const RS={name:"glyph",summary:`glyph <char> [advance=<n>|auto] [<< rows of palette keys >>] (a font's glyph: the rows replace its cell from the top-left on your layer and frame; <char> is a letter or digit, U+XXXX or "c"; advance= sets its width, auto measures its ink)`,normalise(t,a){const s=Hv(t,at(t,a)),l=new _e(t,["advance"]),i=qS(l.positional[0],t),r=l.rest()[0],f=l.positional.find(x=>x.t==="block");for(const x of l.positional.slice(1))if(x!==f)throw new C(x.line,x.col,`glyph: unexpected '${x.t==="word"?x.v:"…"}'`);const u=s.font.chars.indexOf(i);if(u<0)throw new C(r.line,r.col,`glyph: ${Cs(i)} is not one of the font's characters`);const h=l.opts.get("advance");let d=null;if(h)if(h.value==="auto")d="auto";else if(/^\d+$/.test(h.value)&&Number(h.value)<=1024)d=Number(h.value);else throw new C(h.line,h.vcol,"advance= is a width in pixels (0..1024) or auto");if(!f&&d===null)throw new C(t.line,t.col,"glyph: give rows (<< … >>), advance= or both");const p=new Map(s.palette.entries.map((x,b)=>[x.key,b])),y=f?f.rows.map(x=>{if([...x.text].length>s.cellW)throw new C(x.line,x.col+s.cellW,`glyph: a row is wider than the ${s.cellW} px cell`);return[...x.text].map((b,v)=>{if(b==="."||b===" ")return ne;const $=p.get(b);if($===void 0)throw new C(x.line,x.col+v,`glyph: '${b}' is not a key in palette '${s.palette.name}'`);return $})}):null;if(y&&y.length>s.cellH)throw new C(f.line,f.col,`glyph: ${y.length} rows; the cell is ${s.cellH} high`);return{text:`glyph ${Cs(i)}${d!==null?` advance=${d}`:""}${f?` <<
|
|
37
|
+
${va(f.rows.map(x=>x.text))}>>`:""}`,op:ve((x,b)=>{if(y){const v=et(x,b),$=x.cels[v.layer][v.frame],[_,j]=Rh(x,u);for(let N=0;N<x.cellH;N++)for(let M=0;M<x.cellW;M++)$[(j+N)*x.width+_+M]=y[N]?.[M]??ne}d==="auto"?delete x.font.advances[i]:d!==null&&(x.font.advances[i]=d)})}}},DS={name:"font",summary:"font set [baseline=<row>] [line=<px>] [spacing=<px>] (a font's metrics: the cell row glyphs stand on, the line height, the pixels after each advance)",normalise(t,a){const s=Hv(t,Qe(t,a)),l=new _e(t,["baseline","line","spacing"]),i=l.take("word","set");if(i.v!=="set")throw new C(i.line,i.col,"font: expected 'set'");l.done();const r=s.font,f=(p,y)=>{const w=l.opts.get(p);if(!w)return r[p];if(!/^\d+$/.test(w.value)||Number(w.value)>y||p==="line"&&Number(w.value)<1)throw new C(w.line,w.vcol,`${p}= must be ${p==="line"?1:0}..${y}`);return Number(w.value)};if(!l.opts.size)throw new C(t.line,t.col,"font set: give baseline=, line= or spacing=");const u=f("baseline",s.cellH-1),h=f("line",1024),d=f("spacing",64);return{text:`font set baseline=${u} line=${h} spacing=${d}`,op:ve(p=>{Object.assign(p.font,{baseline:u,line:h,spacing:d})})}}},US={name:"icon",summary:"icon mode=tone|full|channel (how an icon is exported: tone art is recoloured by the game through role entries; full art is drawn as is; channel art is pure-RGB channel masks)",normalise(t,a){const s=Qe(t,a);if(s.kind!=="icon")throw new C(t.line,t.col,`icon: '${s.name}' is a ${s.kind}, not an icon`);const l=new _e(t,["mode"]);if(l.done(),!l.opts.get("mode"))throw new C(t.line,t.col,`icon: give mode=${Xg.join("|")}`);const i=l.choice("mode",[...Xg],"full");return{text:`icon mode=${i}`,op:ve(r=>{r.iconMode=i})}}};for(const t of[RS,DS,US])Le(t);const HS=128;function LS(t,a,s,l,i,r){const f=t+l>>1,u=t-l,h=a-i,d=s-r;return((512+f)*u*u>>8)+4*h*h+((767-f)*d*d>>8)}function BS(t,a,s){const l=a.entries.map((d,p)=>vn(d.hex)),i=new Map;l.forEach(([d,p,y],w)=>{const x=d<<16|p<<8|y;i.has(x)||i.set(x,w)});const r=new Map,f=new Uint16Array(t.width*t.height);let u=0,h=0;for(let d=0;d<f.length;d++){const p=t.data[d*4],y=t.data[d*4+1],w=t.data[d*4+2];if(t.data[d*4+3]<HS){f[d]=ne;continue}const b=p<<16|y<<8|w,v=i.get(b);if(v!==void 0){f[d]=v;continue}let $=r.get(b);if(!$){let _=0,j=1/0;l.forEach(([N,M,A],z)=>{const E=LS(p,y,w,N,M,A);E<j&&(j=E,_=z)}),r.set(b,$=[_,j])}f[d]=$[0],u++,h=Math.max(h,$[1])}return{px:f,inexact:u,worst:h}}const Hw=.8,Lw=.85;function Lv(t,a){const s=t.width,l=t.height,i=t.data,r=a==="x"?s-1:l-1,f=new Float64Array(Math.max(0,r)),u=a==="x"?4:s*4;for(let h=0;h<(a==="x"?l:l-1);h++)for(let d=0;d<(a==="x"?s-1:s);d++){const p=(h*s+d)*4,y=i[p+3]<128,w=i[p+u+3]<128,x=y||w?y===w?0:765:Math.abs(i[p]-i[p+u])+Math.abs(i[p+1]-i[p+u+1])+Math.abs(i[p+2]-i[p+u+2]);f[a==="x"?d:h]+=x}return f}function jh(t,a,s){const l=2*Math.PI/a,i=Math.cos(l),r=Math.sin(l);let f=i,u=r,h=0,d=0;for(let w=0;w<t.length;w++){h+=t[w]*f,d+=t[w]*u;const x=f*i-u*r;u=f*r+u*i,f=x}const p=Math.hypot(h,d)/(s||1);let y=Math.atan2(d,h)/(2*Math.PI)*a;return y<0&&(y+=a),{m:p,o:y}}function Bw(t,a,s){const l=Lv(t,a),i=a==="x"?t.width:t.height,r=l.reduce((v,$)=>v+$,0),f=r/Math.max(1,l.length);for(let v=0;v<l.length;v++)l[v]-=f;const u=s?Math.max(1.5,s*.85):1.5,h=s?Math.min(i/2,s*1.15):Math.min(64,i/8),d=1+.25/Math.max(16,i),p=[];for(let v=u;v<=h;v*=d)p.push({p:v,...jh(l,v,r)});if(!p.length)return{pitch:u,offset:0,score:0};const y=Math.max(...p.map(v=>v.m)),w=p.filter((v,$)=>v.m>=.5*y&&v.m>=(p[$-1]?.m??-1)&&v.m>=(p[$+1]?.m??-1)),x=(s?void 0:w.at(-1))??p.find(v=>v.m===y);let b=x;for(let v=x.p*(1-1/i);v<=x.p*(1+1/i);v*=1+.02/i){const $=jh(l,v,r);$.m>b.m&&(b={p:v,...$})}return{pitch:b.p,offset:b.o,score:b.m}}function Yw(t,a,s){const l=Lv(t,a),i=l.reduce((u,h)=>u+h,0),r=i/Math.max(1,l.length);for(let u=0;u<l.length;u++)l[u]-=r;const f=jh(l,s,i);return{pitch:s,offset:f.o,score:f.m}}function YS(t,a,s){if(s){const h=Yw(t,"x",t.width/s.cols),d=Yw(t,"y",t.height/s.rows),p=y=>y.offset>y.pitch/2?-1:0;return{x:h,y:d,cols:s.cols,rows:s.rows,i0:p(h),j0:p(d)}}const l=Bw(t,"x",a?.x),i=Bw(t,"y",a?.y),r=(h,d)=>{const p=x=>Math.min(d,h.offset+(x+1)*h.pitch)-Math.max(0,h.offset+x*h.pitch),y=p(-1)>=h.pitch/2?-1:0;let w=y;for(;p(w+1)>=h.pitch/2;)w++;return{k0:y,n:w-y+1}},f=r(l,t.width),u=r(i,t.height);return{x:l,y:i,cols:f.n,rows:u.n,i0:f.k0,j0:u.k0}}function GS(t){const a=t.sort((s,l)=>s-l);return a.length%2?a[(a.length-1)/2]:(a[a.length/2-1]+a[a.length/2])/2}function XS(t,a){const s=t.width,l=t.height,i=t.data,r={width:a.cols,height:a.rows,data:new Uint8Array(a.cols*a.rows*4)},f=($,_,j,N)=>{const M=$.offset+_*$.pitch,A=M+$.pitch;let z=Math.ceil(M+$.pitch*N),E=Math.floor(A-$.pitch*N-1e-9);return z=Math.max(0,z),E=Math.min(j-1,E),E<z&&(z=E=Math.min(j-1,Math.max(0,Math.floor((M+A)/2)))),[z,E]};for(let $=0;$<a.rows;$++)for(let _=0;_<a.cols;_++){const[j,N]=f(a.x,a.i0+_,s,.25),[M,A]=f(a.y,a.j0+$,l,.25),z=[[],[],[],[]];for(let E=M;E<=A;E++)for(let R=j;R<=N;R++)for(let B=0;B<4;B++)z[B].push(i[(E*s+R)*4+B]);for(let E=0;E<4;E++)r.data[($*a.cols+_)*4+E]=Math.round(GS(z[E]))}const u=new Float64Array(a.cols*a.rows*3),h=new Float64Array(a.cols*a.rows),d=($,_,j,N)=>{const M=Math.floor(($+.5-_.offset)/_.pitch)-j;return M>=0&&M<N?M:-1},p=Int32Array.from({length:s},($,_)=>d(_,a.x,a.i0,a.cols)),y=Int32Array.from({length:l},($,_)=>d(_,a.y,a.j0,a.rows));let w=0;const x=[0,0,0];for(let $=0;$<l;$++)for(let _=0;_<s;_++){if(p[_]<0||y[$]<0)continue;const j=y[$]*a.cols+p[_],N=($*s+_)*4;for(let M=0;M<3;M++)u[j*3+M]+=i[N+M],x[M]+=i[N+M];h[j]++,w++}let b=0,v=0;for(let $=0;$<l;$++)for(let _=0;_<s;_++){if(p[_]<0||y[$]<0)continue;const j=y[$]*a.cols+p[_],N=($*s+_)*4;for(let M=0;M<3;M++){const A=i[N+M];b+=(A-x[M]/w)**2,v+=(A-u[j*3+M]/h[j])**2}}return{img:r,r2:b>0?1-v/b:1}}function ZS(t,a){const s=t.width*t.height,l=new Int32Array(s),i=new Map;for(let d=0;d<t.height;d++)for(let p=0;p<t.width;p++){const y=Math.min(a.width-1,Math.floor((p+.5)*a.width/t.width)),x=(Math.min(a.height-1,Math.floor((d+.5)*a.height/t.height))*a.width+y)*4,b=a.data[x+3]<128?-1:a.data[x]<<16|a.data[x+1]<<8|a.data[x+2];i.has(b)||i.set(b,i.size),l[d*t.width+p]=i.get(b)}const r=i.size;if(r<2)return null;const f=new Float64Array(r*3),u=new Float64Array(r);for(let d=0;d<s;d++){for(let p=0;p<3;p++)f[l[d]*3+p]+=t.data[d*4+p];u[l[d]]++}for(let d=0;d<r;d++)for(let p=0;p<3;p++)f[d*3+p]/=u[d];let h=0;for(let d=0;d<s;d++){let p=-1,y=1/0;for(let w=0;w<r;w++){let x=0;for(let b=0;b<3;b++)x+=(t.data[d*4+b]-f[w*3+b])**2;x<y&&(y=x,p=w)}p===l[d]&&h++}return h/s}function QS(t,a,s={}){const l=YS(t,s.hint,s.cells),{img:i,r2:r}=XS(t,l),f=BS(i,a),u=s.layout?ZS(i,s.layout):null,h=[];return r<Hw&&h.push(`block R² ${r.toFixed(2)} is below ${Hw}`),u!==null&&u<Lw&&h.push(`material match ${u.toFixed(2)} is below ${Lw}`),{fit:l,px:f.px,r2:r,material:u,inexact:f.inexact,worst:f.worst,reroll:h}}const Bv=/^[a-z][a-z0-9_-]*$/,Gw=/^[0-9a-f]{64}$/,VS=/^(\d+)x(\d+)$/,Xw=["from","prompt","provider","model","quality","cost"];function Yv(t,a,s,l){t.layers.splice(a,0,zl(s,l)),t.cels.splice(a,0,Array.from({length:t.frameCount},()=>new Uint16Array(t.width*t.height).fill(ne))),Dl(t,i=>i>=a?i+1:i,i=>i)}function Zw(t,a){const s=VS.exec(t.value);if(!s||Number(s[1])<1||Number(s[2])<1||Number(s[1])>16384||Number(s[2])>16384)throw new C(t.line,t.vcol,`${a} is a size like 1536x1024`);return[Number(s[1]),Number(s[2])]}function Gv(t){const a=/^(-?\d+),(-?\d+)$/.exec(t.value);if(!a)throw new C(t.line,t.vcol,"at= is a point x,y");return[Number(a[1]),Number(a[2])]}function Qw(t,a){throw new C(t.line,t.col,`underlay ${a} runs through the server (the MCP run tool, the watch view or pixelclaw run), which writes the image into blobs/ and this line as underlay <layer> blob=…`)}const KS={name:"underlay",summary:'underlay generate "<prompt>" [layer=<name>] [layout=<template.png|layer>] [size=<W>x<H>] [provider=openai|fake] [model=] [quality=] [cap=<usd>] | underlay import <file.png> [layer=<name>] [layout=<template.png|layer>] | underlay <layer> blob=<sha256> image=<W>x<H> [at=<x,y>] [size=<W>x<H>] [layout=<sha256>] (an image under the art on a reference layer, never exported; the first two forms run through the server and are written as the third)',normalise(t,a){const s=Qe(t,a),l=t.args[0];l?.t==="word"&&l.v==="generate"&&Qw(t,"generate"),l?.t==="word"&&l.v==="import"&&Qw(t,"import");const i=new _e(t,["blob","image","at","size","layout",...Xw]),r=i.take("word","a layer name (or generate / import)");if(i.done(),!Bv.test(r.v))throw new C(r.line,r.col,`'${r.v}' is not a usable layer name`);if(s.map)throw new C(t.line,t.col,"underlay: a map shows its tiles; put the underlay on a sheet of the same size in pixels");const f=i.opts.get("blob");if(!f)throw new C(t.line,t.col,"underlay: give blob=<sha256> (or underlay generate / underlay import)");if(!Gw.test(f.value))throw new C(f.line,f.vcol,"blob= is the image's sha256 (64 hex digits)");const u=i.opts.get("image");let h,d;if(u)[h,d]=Zw(u,"image=");else{const j=a.image?.(f.value);if(!j)throw new C(f.line,f.vcol,"underlay: give image=<W>x<H> (the blob's size); the image is not readable here");h=j.width,d=j.height}const[p,y]=i.opts.get("at")?Gv(i.opts.get("at")):[0,0],[w,x]=i.opts.get("size")?Zw(i.opts.get("size"),"size="):[s.width,s.height],b=i.opts.get("layout");if(b&&!Gw.test(b.value))throw new C(b.line,b.vcol,"layout= is the flat template's sha256 here (the server reads a file or layer and writes its hash)");const v=s.layers.findIndex(j=>j.name===r.v);if(v>=0&&!s.layers[v].reference)throw new C(r.line,r.col,`layer '${r.v}' is an art layer; an underlay goes on a reference layer (a new name makes one)`);if(v>=0&&s.cels[v].some(j=>j.some(N=>N!==ne)))throw new C(r.line,r.col,`layer '${r.v}' has pixels; an underlay goes on its own reference layer`);const $={blob:f.value,iw:h,ih:d,x:p,y,w,h:x,layout:b?.value??null},_=Xw.flatMap(j=>{const N=i.opts.get(j);if(!N)return[];if(j==="cost"&&!/^\d+(\.\d+)?$/.test(N.value))throw new C(N.line,N.vcol,"cost= is in US dollars, like 0.05");return[` ${j}=${N.quoted||/[\s";#]/.test(N.value)||!N.value?wa(N.value):N.value}`]}).join("");return{text:`underlay ${r.v} blob=${$.blob} image=${h}x${d} at=${p},${y} size=${w}x${x}${$.layout?` layout=${$.layout}`:""}${_}`,op:ve(j=>{let N=j.layers.findIndex(M=>M.name===r.v);N<0&&(Yv(j,0,r.v,{reference:!0}),N=0),j.layers[N]={...j.layers[N],underlay:$}})}}},JS={name:"snap",summary:"snap [from=<underlay layer>] [into=<new layer>] [fit=placement|free] (fits the underlay's pixel grid, quantises each block to the palette into a new draft layer, and reports block R² and, with the layout it was made from, the material match; below 0.8 or 0.85 it suggests a reroll)",normalise(t,a){const s=Qe(t,a);if(s.map)throw new C(t.line,t.col,"snap: a map holds cells by name");const l=new _e(t,["from","into","fit","at","grid","pitch","offset","r2","material"]),i=l.peek()?.t==="block"?l.take("block","rows"):null;l.done();const r=l.opts.get("from"),f=s.layers.filter(j=>j.underlay),u=r?s.layers.find(j=>j.name===r.value):f.length===1?f[0]:void 0;if(!u?.underlay)throw new C(r?.line??t.line,r?.vcol??t.col,r?`snap: layer '${r.value}' has no underlay`:f.length?`snap: give from=<layer> (underlays: ${f.map(j=>j.name).join(", ")})`:"snap: there is no underlay (underlay generate / import first)");const h=l.opts.get("fit");if(h&&h.value!=="placement"&&h.value!=="free")throw new C(h.line,h.vcol,"snap: fit= is placement (the placement's grid, the default) or free");const d=h?.value==="free",p=l.opts.get("into"),y=p?.value??"draft";if(!Bv.test(y))throw new C(p.line,p.vcol,`'${y}' is not a usable layer name`);if(s.layers.some(j=>j.name===y))throw new C(p?.line??t.line,p?.vcol??t.col,`snap: there is already a layer '${y}' (snap makes a new draft layer; give into=<name>)`);const w=u.underlay,x=new Map(s.palette.entries.map((j,N)=>[j.key,N]));let b,v,$;if(i)b=i.rows.map(j=>j.text),i.rows.forEach(j=>[...j.text].forEach((N,M)=>{if(N!=="."&&!x.has(N))throw new C(j.line,j.col+M,`snap: '${N}' is not a key in palette '${s.palette.name}'`)})),v=l.opts.get("at")?Gv(l.opts.get("at")):[w.x,w.y],$=["grid","pitch","offset","r2","material"].flatMap(j=>l.opts.get(j)?[` ${j}=${l.opts.get(j).value}`]:[]).join("");else{const j=a.image?.(w.blob);if(!j)throw new C(t.line,t.col,`snap: the underlay image (blobs/${w.blob}.png) is not readable here; run snap through the server`);if(j.width!==w.iw||j.height!==w.ih)throw new C(t.line,t.col,`snap: the blob is ${j.width}x${j.height}, the underlay says ${w.iw}x${w.ih}`);const N=w.layout?a.image?.(w.layout)??null:null,M=QS(j,s.palette,{hint:{x:w.iw/w.w,y:w.ih/w.h},...d?{}:{cells:{cols:w.w,rows:w.h}},layout:N}),A=s.palette.entries.map(R=>R.key);b=Array.from({length:M.fit.rows},(R,B)=>Array.from({length:M.fit.cols},(K,J)=>{const T=M.px[B*M.fit.cols+J];return T===ne?".":A[T]}).join("")),v=[w.x+Math.round((M.fit.x.offset+M.fit.i0*M.fit.x.pitch)*w.w/w.iw),w.y+Math.round((M.fit.y.offset+M.fit.j0*M.fit.y.pitch)*w.h/w.ih)];const z=R=>R.toFixed(2),E=R=>R.toFixed(3);$=` grid=${M.fit.cols}x${M.fit.rows} pitch=${E(M.fit.x.pitch)}x${E(M.fit.y.pitch)} offset=${z(M.fit.x.offset)},${z(M.fit.y.offset)} r2=${z(M.r2)} material=${M.material===null?"none":z(M.material)}`}const _=b.map(j=>[...j].map(N=>N==="."?ne:x.get(N)));return{text:`snap from=${u.name} into=${y}${d?" fit=free":""} at=${v[0]},${v[1]}${$} <<
|
|
38
|
+
${va(b)}>>`,op:ve(j=>{Yv(j,j.layers.length,y,{});const N=j.cels[j.layers.length-1];for(const M of N)_.forEach((A,z)=>A.forEach((E,R)=>{const B=v[0]+R,K=v[1]+z;B>=0&&K>=0&&B<j.width&&K<j.height&&(M[K*j.width+B]=E)}))})}}};for(const t of[KS,JS])Le(t);const Sh=/^(?:undo|redo) group=(\S+)$/;function rd(t){const a=new Map;for(const s of t){let l=a.get(s.group);l||a.set(s.group,l={id:s.group,by:s.by,undoTargets:[],hasNew:!1,onlyUndo:!0});const i=Sh.exec(s.cmd);i?l.undoTargets.push(i[1]):l.onlyUndo=!1,(s.cmd.startsWith("new ")||s.cmd.startsWith("fork "))&&(l.hasNew=!0)}return[...a.values()]}function ti(t){const a=rd(t),s=new Set,l=new Set;for(let i=a.length-1;i>=0;i--){const r=a[i];if(!s.has(r.id)){l.add(r.id);for(const f of r.undoTargets)s.add(f)}}return l}function WS(t){return t==="human"||t.startsWith("human:")?"h":"g"}function IS(t,a="g"){let s=0;const l=new RegExp(`^${a}(\\d+)$`);for(const i of t){const r=l.exec(i.group);r&&(s=Math.max(s,Number(r[1])))}return`${a}${s+1}`}function Xv(t,a,s=null,l){const i=rd(t).filter(f=>f.id!==l),r=ti(t);if(a!==null){if(a===l)return{error:"a batch cannot undo its own group"};const f=i.find(u=>u.id===a);return f?r.has(a)?f.hasNew?{error:`group '${a}' created the document and cannot be undone`}:{group:a}:{error:`group '${a}' is already undone`}:{error:`no group '${a}' on this tape`}}for(let f=i.length-1;f>=0;f--){const u=i[f];if(!(s!==null&&u.by!==s)&&r.has(u.id)&&!u.onlyUndo&&!u.hasNew)return{group:u.id}}return{error:s!==null?`nothing of ${s}'s to undo`:"nothing to undo"}}function Zv(t,a,s=null,l){const i=rd(t).filter(h=>h.id!==l),r=new Map(i.map(h=>[h.id,h])),f=ti(t),u=h=>h.onlyUndo&&h.undoTargets.every(d=>!r.get(d)?.onlyUndo);if(a!==null){const h=r.get(a);return h?!h.onlyUndo||!u(h)?{error:`group '${a}' is not an undo, so there is nothing to redo`}:f.has(a)?{group:a}:{error:`group '${a}' is already taken back`}:{error:`no group '${a}' on this tape`}}for(let h=i.length-1;h>=0;h--){const d=i[h];if(!(s!==null&&d.by!==s)){if(!d.onlyUndo)break;if(u(d)&&f.has(d.id))return{group:d.id}}}return{error:s!==null?`nothing of ${s}'s to redo`:"nothing to redo"}}const FS=/^note .* id=n(\d+)$/;function PS(t){let a=0;for(const s of t){const l=FS.exec(s.cmd);l&&(a=Math.max(a,Number(l[1])))}return`n${a+1}`}function cd(t,a,s,l,i,r,f,u,h,d){return{...h?{image:h}:{},...f?{asset:f}:{},...d?{assetNames:d}:{},...u?{defaults:u}:{},doc:t,seq:i,by:r,palette:p=>l.get(p),defaultPalette:l.defaultName,scheme:p=>l.scheme?.(p),newSeed:()=>z0(new nn(i,lk(t?.name??"doc"))),undoTarget:(p,y)=>Xv(a,p,y??null,s),redoTarget:(p,y)=>Zv(a,p,y??null,s),noteId:()=>PS(a)}}class Al{snaps=[];every;constructor(a=100){this.every=a}static key(a,s,l){const i=new Set;for(let r=0;r<s;r++){const f=a[r];!l.has(f.group)&&!Sh.test(f.cmd)&&i.add(f.group)}return[...i].sort().join(" ")}record(a,s){const l=a.length;l===0||l%this.every!==0||this.snaps.some(i=>i.n===l&&i.last===a[l-1])||(this.snaps=this.snaps.filter(i=>i.n!==l),this.snaps.push({n:l,last:a[l-1],undone:Al.key(a,l,ti(a)),doc:s?Wa(s):null}))}get size(){return this.snaps.length}replay(a,s){const l=ti(a);this.snaps=this.snaps.filter(f=>f.n<=a.length&&a[f.n-1]===f.last);let i={n:0,doc:null};for(const f of[...this.snaps].sort((u,h)=>h.n-u.n))if(Al.key(a,f.n,l)===f.undone){i=f;break}let r=i.doc?Wa(i.doc):null;for(let f=i.n;f<a.length;f++){const u=a[f];if(l.has(u.group)&&!Sh.test(u.cmd)){const{commands:d,errors:p}=Ls(u.cmd);if(p.length||d.length!==1)throw new Error(`tape seq ${u.seq}: '${u.cmd}' does not parse`);const y=Fo(d[0],cd(r,[],u.group,s,u.seq,u.by));r=Po(r,y.op,u.by)}const h=f+1;h%this.every===0&&h<a.length&&!this.snaps.some(d=>d.n===h&&d.last===u)&&(this.snaps=this.snaps.filter(d=>d.n!==h),this.snaps.push({n:h,last:u,undone:Al.key(a,h,l),doc:r?Wa(r):null}))}return r}}function Qv(t,a,s){return(s??new Al).replay(t,a)}function eN(t,a){if(!a)return 0;const s=t&&t.width===a.width&&t.height===a.height;let l=0;for(let i=0;i<a.frameCount;i++){const r=Ce(a,i),f=s&&i<t.frameCount?Ce(t,i):null;if(!f){l+=r.length;continue}for(let u=0;u<r.length;u++)r[u]!==f[u]&&l++}return l}function tN(t,a,s){const{commands:l,errors:i}=Ls(a);let r=t.doc?Wa(t.doc):null;const f=[...t.entries],u=t.cache??new Al,h=IS(t.entries,WS(s.by));let d=(t.entries[t.entries.length-1]?.seq??0)+1;const p=[],y=[];for(const w of l)try{const x=Fo(w,cd(r,f,h,s.palettes,d,s.by,s.assets,s.defaults,s.images,s.assetNames)),b={seq:d,by:s.by,...s.at?{at:s.at}:{},group:h,cmd:x.text};f.push(b),p.push(b),d++,r=x.op.k==="undo"?Qv(f,s.palettes,u):Po(r,x.op,s.by),u.record(f,r);const v=/^palette save as=(\S+)$/.exec(x.text);v&&r&&y.push({name:v[1],palette:r.palette})}catch(x){if(!(x instanceof C))throw x;i.push({line:x.line,col:x.col,message:x.message})}return i.length?{ok:!1,errors:i.sort((w,x)=>w.line-x.line||w.col-x.col)}:{ok:!0,state:{doc:r,entries:f,cache:u},added:p,group:p.length?h:null,changed:eN(t.doc,r),saves:y}}class ni{doc=null;done=[];palettes;cache=new Al;constructor(a){this.palettes=a}static resume(a,s,l){const i=new ni(a);return i.doc=s?Wa(s):null,i.done.push(...l),i}step(a){const{commands:s,errors:l}=Ls(a.cmd);if(l.length||s.length!==1)return l[0]?`does not parse: ${l[0].message}`:`holds ${s.length} commands`;try{const i=cd(this.doc,this.done,a.group,this.palettes,a.seq,a.by);let r=Fo(s[0],i);return r.text!==a.cmd&&aN(a.cmd)&&(r=Fo(s[0],{...i,lang:1})),r.text!==a.cmd?`not in normal form: expected '${r.text}'`:(this.done.push(a),this.doc=r.op.k==="undo"?Qv(this.done,this.palettes,this.cache):Po(this.doc,r.op,a.by),this.cache.record(this.done,this.doc),null)}catch(i){if(!(i instanceof C))throw i;return i.message}}}class nN{palettes;every;snaps=[];constructor(a,s=100){this.palettes=a,this.every=s}docAt(a,s){s=Math.max(0,Math.min(s,a.length)),this.snaps=this.snaps.filter(r=>r.n<=a.length&&a[r.n-1]===r.last);let l;for(const r of this.snaps)r.n<=s&&(!l||r.n>l.n)&&(l=r);const i=ni.resume(this.palettes,l?.doc??null,a.slice(0,l?.n??0));for(let r=l?.n??0;r<s;r++){const f=i.step(a[r]);if(f!==null)return{doc:i.doc,problem:`#${a[r].seq}: ${f}`};(r+1)%this.every===0&&!this.snaps.some(u=>u.n===r+1)&&this.snaps.push({n:r+1,last:a[r],doc:i.doc?Wa(i.doc):null})}return{doc:i.doc,problem:null}}seed(a,s,l){s<1||s>a.length||this.snaps.some(i=>i.n===s)||this.snaps.push({n:s,last:a[s-1],doc:l?Wa(l):null})}docAfter(a,s){let l=0;for(;l<a.length&&a[l].seq<=s;)l++;return this.docAt(a,l)}get size(){return this.snaps.length}}const aN=t=>t.startsWith("new ")&&!t.includes(`
|
|
39
|
+
`);function lN(t,a){const s=[],l=t??{},i=(l.palettes??[]).flatMap(r=>{const f=a(r);return f||s.push(`style.palettes: no palette '${r}' in the project`),f?[f]:[]});return{style:{...i.length?{palettes:i}:{},...l.outline?{outline:l.outline}:{},...l.sizes?{sizes:l.sizes}:{},...l.checks?{checks:l.checks}:{},...l.assets?{assets:l.assets}:{},...l.density?{density:l.density}:{},...l.light?{light:l.light}:{},...l.reserved?{reserved:l.reserved}:{}},problems:s}}function Os(t,a=24){const s=t?.drawScale;return typeof s=="number"&&Number.isInteger(s)&&s>=1&&s<=16?s:a>=48?1:2}function sN(t,a=24){const s=/^(\d+)x(\d+)$/.exec(t?.camera??"");return s&&Number(s[1])>0&&Number(s[2])>0?[Number(s[1]),Number(s[2])]:[16*a,9*a]}function Nh(t,a,s,l){const i=l??s?.assets?.[t]?.ground??s?.ground;return i?a.find(r=>r.name===i)??null:[...a].sort((r,f)=>r.name<f.name?-1:1).find(r=>r.doc.wrap&&r.name!==t)??null}function Vv(t,a,s,l,i){const r=i??l?.assets?.[t]?.set;if(r)return s.filter(h=>r.includes(h.name)&&h.name!==t);const f=h=>{let d=h;for(let p=0;p<32;p++){const y=s.find(w=>w.name===d)?.forkOf;if(!y)break;d=y}return d},u=f(t);return s.filter(h=>h.name!==t&&!h.doc.wrap&&h.doc.kind===a.kind&&h.doc.width===a.width&&h.doc.height===a.height&&f(h.name)!==u)}function oN(t,a,s,l,i,r={}){const{style:f,problems:u}=lN(l,i);r.setChecks&&(f.checks=iN(f.checks??{},r.setChecks));const h=Nh(t,s,l,r.ground);r.ground&&!h&&u.push(`no asset '${r.ground}' to use as ground`);const d=r.ref?s.find(p=>p.name===r.ref)??null:null;return r.ref&&!d&&u.push(`no asset '${r.ref}' to compare with`),{ctx:{frame:r.frame,style:f,ground:h?.doc??null,ref:d?.doc??null,set:Vv(t,a,s,l,r.set).map(p=>({name:p.name,doc:p.doc})),...a.map||a.variantOf||a.densityOf?{world:G0(s)}:{},peers:(r.peers?s.filter(p=>r.peers.includes(p.name)&&ac(p.doc)===ac(a)):cN(t,a,s)).map(p=>({name:p.name,doc:p.doc})),...r.expect?{expect:r.expect}:{}},problems:u}}function iN(t,a){const s={...t};for(const[l,i]of Object.entries(a)){const r=s[l];s[l]=r&&typeof r=="object"&&i&&typeof i=="object"?{...r,...i}:i}return s}const rN=t=>!t.wrap&&!t.family&&!t.overlay&&!t.map&&!t.font&&t.kind!=="icon";function cN(t,a,s){const l=ac(a);return l==="other"?[]:s.filter(i=>i.name!==t&&ac(i.doc)===l&&!i.doc.densityOf&&!a.densityOf)}function ac(t){return t.wrap&&!t.family?"tile":rN(t)?"figure":t.kind==="icon"?"icon":"other"}const uN="pixelclaw-profile",fN=1,hN="aseprite",dN="One .aseprite file per asset (indexed: layers, frames and durations, linked cels, tags, views as tags named 'view S'); density copies as <asset>@<d>x.aseprite",mN="aseprite",pN="names",yN={format:uN,version:fN,name:hN,description:dN,layout:mN,variants:pN},gN="pixelclaw-profile",wN=1,vN="aseprite-json",xN="Aseprite's sheet export: a PNG of each asset's frames in a row and the JSON Aseprite writes (frames with durations, tags, and views as tags named 'view S')",bN="aseprite-json",$N="names",kN="bake",_N="sprite",jN={format:gN,version:wN,name:vN,description:xN,layout:bN,variants:$N,mirrors:kN,oversized:_N},SN="pixelclaw-profile",NN=1,MN="atlas",zN="One atlas page (trimmed images, shelf-packed) with JSON records: every column, including frame, ticks, view, pivot and footprint",CN="atlas",EN={name:"atlas",width:256,padding:1,trim:!0},TN={format:"json",columns:["sprite","x","y","w","h","cropX","cropY","frameW","frameH","pivotX","pivotY","asset","frame","n","view","ticks","ms","cols","rows","anchorX","anchorY","flags","variant"]},ON="frames",AN="bake",qN="sprite",RN={format:SN,version:NN,name:MN,description:zN,layout:CN,page:EN,records:TN,variants:ON,mirrors:AN,oversized:qN},DN="pixelclaw-profile",UN=1,HN="godot",LN="Godot 4: a TileSet resource (.tres) per autotile family with one terrain set (match corners and sides for blob47, corners for wang16-corner, sides for path), frames as tile animations, and each tile's name as custom data",BN="godot",YN="names",GN={format:DN,version:UN,name:HN,description:LN,layout:BN,variants:YN},XN="pixelclaw-profile",ZN=1,QN="png",VN="Loose PNGs: one file per image, named <asset>, <asset>_<n> for frames, <asset>_<view>_<n> for directions, <family>_<variant> for autotile variants; mirror views written flipped; texture variants under their own names",KN="loose",JN="{name}.png",WN="names",IN="bake",FN="sprite",PN={format:XN,version:ZN,name:QN,description:VN,layout:KN,image:JN,variants:WN,mirrors:IN,oversized:FN},eM="pixelclaw-profile",tM=1,nM="tiled",aM="Tiled: a .tsx per autotile family (its sheet, frames as tile animations, a wang set: mixed for blob47, corner for wang16-corner, edge for path), a collection tileset of every other image, and a .tmx per map that uses them",lM="tiled",sM="names",oM="bake",iM="sprite",rM={format:eM,version:tM,name:nM,description:aM,layout:lM,variants:sM,mirrors:oM,oversized:iM},Vw=["loose","atlas","sheet","tiled","godot","aseprite-json","aseprite"];class Nt extends Error{}const Kw=["sprite","x","y","w","h","cropX","cropY","frameW","frameH","pivotX","pivotY","page","asset","frame","n","view","mirror","ticks","ms","d","cols","rows","anchorX","anchorY","flags","variant","kind","mode"],Jw=["asset","name","kind","mode","frames","names","first","ticks","ms","frameTicks","loop","tags","views","directions","mirror","w","h","cols","rows","anchorX","anchorY","pivotX","pivotY","variants","scheme"],zs=["asset","n","view","cx","cy","variant","sides","corners","shape","name","d","page","stem"],Ww=["lone","end","straight","corner","tee","cross"],cM=["ne","se","sw","nw"];function Gr(t,a,s){return t.replace(/\{\{|\}\}|\{([A-Za-z][A-Za-z0-9]*)\}/g,(l,i)=>{if(l==="{{")return"{";if(l==="}}")return"}";if(s&&!s.includes(i))throw new Nt(`unknown placeholder {${i}} (known: ${s.join(", ")})`);const r=a[i];if(r===void 0)throw new Nt(`placeholder {${i}} has no value here`);return String(r)})}function uM(t){const a=`profile '${t?.name??"?"}'`;if(!t||typeof t!="object")throw new Nt("a profile is a JSON object");if(!/^[a-z][a-z0-9_-]*$/.test(t.name??""))throw new Nt(`${a}: name uses a-z, 0-9, _ and -`);if(!Vw.includes(t.layout))throw new Nt(`${a}: layout must be one of ${Vw.join(", ")}`);const s=t.names??{};for(const[l,i]of Object.entries(s))l!=="start"&&Gr(String(i),Object.fromEntries(zs.map(r=>[r,""])),zs);for(const[l,i]of Object.entries(t.autotile??{})){for(const r of[i.template,...Object.values(i.names??{})])r&&Gr(r,Object.fromEntries(zs.map(f=>[f,""])),zs);if(i.sides&&!/^(?=.*n)(?=.*e)(?=.*s)(?=.*w)[nesw]{4}$/.test(i.sides))throw new Nt(`${a}: autotile.${l}.sides orders the letters n, e, s and w`);if(i.corners!==void 0&&(typeof i.corners!="string"||[...new Set(i.corners.split(","))].sort().join()!==[...cM].sort().join()||i.corners.split(",").length!==4))throw new Nt(`${a}: autotile.${l}.corners orders the corners ne, se, sw and nw, like "nw,ne,se,sw"`);for(const[r,f]of Object.entries(i.shapes??{})){if(!Ww.includes(r))throw new Nt(`${a}: autotile.${l}.shapes.${r} is not a shape (${Ww.join(", ")})`);Gr(String(f),Object.fromEntries(zs.map(u=>[u,""])),zs)}}for(const l of Object.keys(t.roles??{}))if(!Un.includes(l))throw new Nt(`${a}: roles.${l} is not a role (${Un.join(", ")})`);for(const[l,i]of Object.entries(t.roles??{}))if(!/^#[0-9a-fA-F]{6}$/.test(String(i)))throw new Nt(`${a}: roles.${l} must be #rrggbb`);for(const[l,i]of Object.entries(t.colours??{})){if(!/^([a-z][a-z0-9_-]*\.)?[a-z][a-z0-9_]*$/i.test(l))throw new Nt(`${a}: colours: '${l}' is not an entry name (or <palette>.<entry>)`);if(!/^#[0-9a-fA-F]{6}$/.test(String(i))){if(!Un.includes(String(i)))throw new Nt(`${a}: colours.${l} must be #rrggbb or a role (${Un.join(", ")})`);if(!t.roles?.[i])throw new Nt(`${a}: colours.${l} is the role '${i}', which roles does not give a colour`)}}if(t.density&&(!Array.isArray(t.density.levels)||!t.density.levels.length||t.density.levels.some(l=>![1,2,3,4,6,8].includes(l))))throw new Nt(`${a}: density.levels lists sizes like 1, 2, 4`);for(const l of t.records?.columns??[])if(!Kw.includes(l))throw new Nt(`${a}: records.columns: '${l}' is not a column (${Kw.join(", ")})`);if(t.fonts){if(t.fonts.format&&!["strip","bmfont","both","sheet"].includes(t.fonts.format))throw new Nt(`${a}: fonts.format is strip, bmfont, both or sheet`);if(t.fonts.separator&&!/^#[0-9a-fA-F]{6}$/.test(t.fonts.separator))throw new Nt(`${a}: fonts.separator must be #rrggbb`);if(t.fonts.maxLine!==void 0&&(!Number.isInteger(t.fonts.maxLine)||t.fonts.maxLine<1))throw new Nt(`${a}: fonts.maxLine is a line height in pixels`)}if(t.snippets)for(const l of Object.values(t.snippets.templates??{}))Gr(l,Object.fromEntries(Jw.map(i=>[i,""])),Jw);return t}new Map([PN,RN,rM,GN,jN,yN].map(t=>[t.name,uM(t)]));const Qo=["planned","drafted","checked","reviewed","approved","exported"];function fM(t,a,s){const[l,i]=s.cell,[r,f]=s.offset??[0,0],[u,h]=s.gap??[0,0];if(l<1||i<1||r<0||f<0||u<0||h<0)return[];const d=[];for(let p=0,y=f;y+i<=a;p++,y+=i+h)for(let w=0,x=r;x+l<=t;w++,x+=l+u)d.push({col:w,row:p,x,y});return d}const Kv="{name}_{n}";function Mh(t,a="imported"){return t.toLowerCase().replace(/[^a-z0-9_-]+/g,"_").replace(/^[^a-z]+/,"").replace(/_+$/,"")||a}function Iw(t,a){let s;if(a.names){if(a.names.length<t.length)return`${t.length} cells but only ${a.names.length} names`;s=a.names.slice(0,t.length)}else{const i=a.pattern?.trim()||Kv;s=t.map((r,f)=>Mh(i.replace(/\{name\}/g,a.base).replace(/\{n\}/g,String(f+1)).replace(/\{col\}/g,String(r.col)).replace(/\{row\}/g,String(r.row)),a.base))}const l=new Set;for(const i of s){if(l.has(i))return`the name '${i}' comes out twice (put {n}, or {col} and {row}, in the pattern)`;l.add(i)}return s}const Fw=new Map;function hM(t,a){let s=Fw.get(t);return s||(s=new Image,s.onload=a,s.src=`/api/blob/${t}.png?token=${encodeURIComponent(new URLSearchParams(location.search).get("token")??"")}`,Fw.set(t,s)),s.complete&&s.naturalWidth?s:null}const Ia=[1,2,3,4,6,8,12,16,20,24,32,40,48,64],dM=16384,mM="#cccccc",pM="#eeeeee";function Jv(t,a){return a&&t.wrap?{mx:Math.ceil(t.width/2),my:Math.ceil(t.height/2)}:{mx:0,my:0}}function yM(t,a,s,l=!1){const{mx:i,my:r}=Jv(t,l);let f=1;for(const u of Ia)(t.width+2*i)*u<=a&&(t.height+2*r)*u<=s&&(f=u);return f}function Pw(t){return Ia.filter(a=>Math.max(t.width,t.height)*a<=dM).at(-1)??1}function hh(t,a,s,l,i,r=1){t.lineWidth=r,t.setLineDash([4,4]);for(const[f,u]of[[l,0],[i,4]])t.strokeStyle=f,t.lineDashOffset=u,t.strokeRect(a.x*s+r/2,a.y*s+r/2,a.w*s-r,a.h*s-r);t.setLineDash([])}function gM(t,a,s,l,i){const r=new Path2D,f=(u,h)=>u>=0&&h>=0&&u<a.width&&h<a.height&&!!s[h*a.width+u];for(let u=0;u<a.height;u++)for(let h=0;h<a.width;h++){if(!f(h,u))continue;const d=(h+i[0])*l,p=(u+i[1])*l;f(h,u-1)||(r.moveTo(d,p+.5),r.lineTo(d+l,p+.5)),f(h,u+1)||(r.moveTo(d,p+l-.5),r.lineTo(d+l,p+l-.5)),f(h-1,u)||(r.moveTo(d+.5,p),r.lineTo(d+.5,p+l)),f(h+1,u)||(r.moveTo(d+l-.5,p),r.lineTo(d+l-.5,p+l))}t.lineWidth=1,t.setLineDash([4,4]);for(const[u,h]of[["#ffffff",0],["#000000",4]])t.strokeStyle=u,t.lineDashOffset=h,t.stroke(r);t.setLineDash([])}function e0(t,a,s){const l=document.createElement("canvas");l.width=t.width,l.height=t.height;const i=xh(t,a,s),r=w$(t,a);if(r){const f=li(t.palette,s).entries.map(u=>vn(u.hex));for(let u=0;u<r.length;u++){if(r[u]===ne||i.data[u*4+3])continue;const h=f[r[u]];i.data.set([h[0],h[1],h[2],128],u*4)}}return l.getContext("2d").putImageData(new ImageData(new Uint8ClampedArray(i.data),t.width,t.height),0,0),l}function t0(t,a,s,l,i=!1){const r=Math.max(2,a>>1),f=document.createElement("canvas");f.width=f.height=r*2;const u=f.getContext("2d");u.fillStyle=i?"#2a2c33":pM,u.fillRect(0,0,r*2,r*2),u.fillStyle=i?"#33363e":mM,u.fillRect(r,0,r,r),u.fillRect(0,r,r,r),t.fillStyle=t.createPattern(f,"repeat"),t.fillRect(0,0,s,l)}function wM(t){const a=he.useRef(null),s=he.useRef(null),l=he.useRef(null),i=he.useRef(null),r=he.useRef(null),[f,u]=he.useState({w:0,h:0}),[,h]=he.useState(0);he.useLayoutEffect(()=>{const _=a.current;if(!_)return;const j=new ResizeObserver(()=>u({w:_.clientWidth,h:_.clientHeight}));return j.observe(_),()=>j.disconnect()},[]);const d=t.doc,p=d?t.zoom==="fit"?yM(d,f.w-48,f.h-48,t.ghosts):Math.min(t.zoom,Pw(d)):1,{mx:y,my:w}=d?Jv(d,t.ghosts):{mx:0,my:0};he.useEffect(()=>{t.onEffectiveZoom(p)},[p]),he.useLayoutEffect(()=>{const _=s.current;if(!_||!d)return;const j=d.width*p,N=d.height*p;_.width!==j&&(_.width=j),_.height!==N&&(_.height=N);const M=_.getContext("2d");M.imageSmoothingEnabled=!1,t0(M,p,j,N,!!d.font);for(const E of d.layers){if(!E.underlay||E.hidden)continue;const R=E.underlay,B=hM(R.blob,()=>h(K=>K+1));B&&(M.imageSmoothingEnabled=!0,M.globalAlpha=.5,M.drawImage(B,R.x*p,R.y*p,R.w*p,R.h*p),M.globalAlpha=1,M.imageSmoothingEnabled=!1)}const A=e0(d,t.frame,t.theme);for(const[E,R]of[[t.onion.prev,"rgb(255,90,60)"],[t.onion.next,"rgb(60,140,255)"]]){if(E===null||E===t.frame||E>=d.frameCount)continue;const B=e0(d,E,t.theme),K=B.getContext("2d");K.globalCompositeOperation="source-atop",K.fillStyle=R,K.globalAlpha=.55,K.fillRect(0,0,B.width,B.height),M.globalAlpha=.45,M.drawImage(B,0,0,j,N),M.globalAlpha=1}if(M.drawImage(A,0,0,j,N),t.pixelGrid&&p>=4){for(let E=1;E<d.width;E++)M.fillStyle=E%8===0?"rgba(20,20,28,0.45)":"rgba(20,20,28,0.18)",M.fillRect(E*p,0,1,N);for(let E=1;E<d.height;E++)M.fillStyle=E%8===0?"rgba(20,20,28,0.45)":"rgba(20,20,28,0.18)",M.fillRect(0,E*p,j,1)}if(t.cellGrid&&(d.cellW<d.width||d.cellH<d.height)){const E=p>=8?2:1;M.fillStyle="rgba(255,79,216,0.9)";for(let R=d.cellW;R<d.width;R+=d.cellW)M.fillRect(R*p-(E>>1),0,E,N);for(let R=d.cellH;R<d.height;R+=d.cellH)M.fillRect(0,R*p-(E>>1),j,E)}const z=i.current;if(z&&(y||w)){const E=(d.width+2*y)*p,R=(d.height+2*w)*p;z.width!==E&&(z.width=E),z.height!==R&&(z.height=R);const B=z.getContext("2d");B.imageSmoothingEnabled=!1,t0(B,p,E,R);for(let K=-1;K<=1;K++)for(let J=-1;J<=1;J++)B.drawImage(A,(y+J*d.width)*p,(w+K*d.height)*p,j,N);B.fillStyle="rgba(22,23,27,0.42)",B.fillRect(0,0,E,R)}}),he.useLayoutEffect(()=>{const _=l.current;if(!_||!d)return;const j=d.width*p,N=d.height*p;_.width!==j&&(_.width=j),_.height!==N&&(_.height=N);const M=_.getContext("2d");M.clearRect(0,0,j,N);const A=t.overlay;for(const z of A.otherSels){M.fillStyle="rgba(108,196,255,0.2)";for(let E=0;E<z.length;E++)z[E]&&M.fillRect(E%d.width*p,Math.floor(E/d.width)*p,p,p)}if(A.mySel&&gM(M,d,A.mySel,p,A.selOffset??[0,0]),M.fillStyle="rgba(64,220,230,0.95)",A.ground!==null)for(let z=0;z<j;z+=6)M.fillRect(z,(A.ground+1)*p-1,4,Math.max(1,p>>3));if(A.pivot){const[z,E]=A.pivot;M.strokeStyle="rgba(64,220,230,0.95)",M.lineWidth=Math.max(1,p>>3),M.strokeRect(z*p+.5,E*p+.5,p-1,p-1),M.fillRect(z*p+(p>>1)-1,E*p-p,2,p*3),M.fillRect(z*p-p,E*p+(p>>1)-1,p*3,2)}if(A.mirror){if(M.strokeStyle="rgba(80,220,255,0.9)",M.lineWidth=1,M.setLineDash([6,3]),M.beginPath(),A.mirror.x2!==null){const z=Math.round((A.mirror.x2+1)/2*p)+.5;M.moveTo(z,0),M.lineTo(z,N)}if(A.mirror.y2!==null){const z=Math.round((A.mirror.y2+1)/2*p)+.5;M.moveTo(0,z),M.lineTo(j,z)}M.stroke(),M.setLineDash([])}for(const z of A.notes){const E=z.id===A.activeNote;M.fillStyle=E?"rgba(255,214,10,0.28)":"rgba(255,214,10,0.12)",M.fillRect(z.x*p,z.y*p,z.w*p,z.h*p),hh(M,z,p,"#ffd60a","#3a2f00",E?2:1)}if(A.draft&&hh(M,A.draft,p,"#ffd60a","#000000",2),A.marquee&&(A.marqueeEllipse&&(M.strokeStyle="#ffffff",M.setLineDash([4,4]),M.beginPath(),M.ellipse((A.marquee.x+A.marquee.w/2)*p,(A.marquee.y+A.marquee.h/2)*p,A.marquee.w*p/2,A.marquee.h*p/2,0,0,Math.PI*2),M.stroke(),M.setLineDash([])),hh(M,A.marquee,p,"#ffffff","#000000")),A.lasso&&A.lasso.length>1&&(M.strokeStyle="#ffffff",M.lineWidth=1,M.setLineDash([4,4]),M.beginPath(),A.lasso.forEach(([z,E],R)=>R?M.lineTo((z+.5)*p,(E+.5)*p):M.moveTo((z+.5)*p,(E+.5)*p)),M.stroke(),M.setLineDash([])),A.marks.length)for(const z of[0,1]){M.strokeStyle=z?"#ff00c8":"rgba(0,0,0,0.55)",M.lineWidth=z?2:4;for(const[E,R]of A.marks){if(p<4){z&&(M.fillStyle="#ff00c8",M.fillRect(E*p,R*p,p,p));continue}M.beginPath(),M.arc((E+.5)*p,(R+.5)*p,p*.5+Math.max(2,p*.22),0,Math.PI*2),M.stroke()}}if(A.hover&&p>=4&&!t.travel){const z=(A.hover[0]%d.width+d.width)%d.width,E=(A.hover[1]%d.height+d.height)%d.height;M.strokeStyle="rgba(255,255,255,0.75)",M.lineWidth=1,M.strokeRect(z*p+.5,E*p+.5,p-1,p-1)}});const x=he.useRef(()=>{});x.current=_=>{if(!d||!(_.ctrlKey||_.metaKey))return;_.preventDefault();const j=Ia.indexOf(p),N=Ia[Math.max(0,Math.min(Ia.length-1,j+(_.deltaY<0?1:-1)))];t.onZoom(Math.min(N,Pw(d)))},he.useEffect(()=>{const _=a.current,j=N=>x.current(N);return _.addEventListener("wheel",j,{passive:!1}),()=>_.removeEventListener("wheel",j)},[]);const b=_=>{const j=r.current.getBoundingClientRect();return[Math.floor((_.clientX-j.left)/p),Math.floor((_.clientY-j.top)/p)]},v=_=>d?d.wrap&&(y||w)?_[0]>=-y&&_[1]>=-w&&_[0]<d.width+y&&_[1]<d.height+w?_:null:_[0]>=0&&_[1]>=0&&_[0]<d.width&&_[1]<d.height?_:null:null,$=t.pointer;return k.jsx("div",{className:`stage${t.travel?" travel":""}`,ref:a,children:d?k.jsxs("div",{className:"frame-area",style:{width:(d.width+2*y)*p,height:(d.height+2*w)*p,cursor:$?t.cursor:"default"},"data-testid":"frame-area",onPointerDown:_=>{!$||_.button>0||(_.currentTarget.setPointerCapture(_.pointerId),$.down(b(_),{alt:_.altKey,shift:_.shiftKey,button:_.button}))},onPointerMove:_=>{if(!$)return;const j=b(_);$.move(_.buttons?j:v(j))},onPointerUp:_=>$?.up(b(_)),onPointerCancel:()=>$?.up(null),onPointerLeave:_=>{_.buttons||$?.move(null)},children:[(y>0||w>0)&&k.jsx("canvas",{ref:i,className:"ghosts","data-testid":"ghosts",style:{width:(d.width+2*y)*p,height:(d.height+2*w)*p}}),k.jsxs("div",{className:"art",ref:r,style:{left:y*p,top:w*p,width:d.width*p,height:d.height*p},"data-testid":"art",children:[k.jsx("canvas",{ref:s,"data-testid":"canvas","data-asset":t.asset??"","data-seq":t.seq??"","data-zoom":p,"data-frame":t.frame,style:{width:d.width*p,height:d.height*p}}),k.jsx("canvas",{ref:l,className:"overlay",style:{width:d.width*p,height:d.height*p}}),t.overlay.notes.map(_=>k.jsxs("div",{className:`note-label${_.id===t.overlay.activeNote?" on":""}`,"data-note":_.id,style:{left:_.x*p,top:_.y*p},title:`${_.id} at ${_.x},${_.y}${_.w>1||_.h>1?` ${_.w}x${_.h}`:""}: ${_.text}`,onPointerDown:j=>j.stopPropagation(),onClick:()=>t.onNote(_.id===t.overlay.activeNote?null:_.id),children:[k.jsx("b",{children:_.id})," ",_.id===t.overlay.activeNote||_.text.length<=28?_.text:_.text.slice(0,26)+"…"]},_.id))]})]}):k.jsx("div",{className:"empty",children:t.asset?"Waiting for the first command…":"No assets yet. When the agent creates one, it appears here."})})}const vM=[{id:"pencil",label:"Pencil",key:"B",icon:"✎",hint:"drag to draw; pixel-perfect by default; the brush size is in the options bar"},{id:"eraser",label:"Eraser",key:"E",icon:"⌫",hint:"drag to clear pixels"},{id:"line",label:"Line",key:"L",icon:"╱",hint:"drag from one end to the other"},{id:"rect",label:"Rectangle",key:"U",icon:"▭",hint:"drag a box; F toggles filled"},{id:"ellipse",label:"Ellipse",key:"Shift+U",icon:"◯",hint:"drag a box; F toggles filled"},{id:"fill",label:"Fill",key:"G",icon:"◧",hint:"click to flood-fill an area"},{id:"gradient",label:"Gradient",key:"Shift+G",icon:"▤",hint:"drag from where colour A starts to where colour B ends; fills your selection, or the canvas, along the ramp between them"},{id:"dither",label:"Dither",key:"D",icon:"▚",hint:"drag a box: colour A dithered over colour B at the level in the options bar"},{id:"picker",label:"Colour picker",key:"I",icon:"◉",hint:"click a pixel to use its colour (or Alt+click with a drawing tool)"},{id:"select",label:"Rectangle select",key:"M",icon:"⬚",hint:"drag to select; Shift adds, Alt subtracts; drag inside to move; Delete clears; Esc deselects"},{id:"select-ellipse",label:"Ellipse select",key:"Shift+M",icon:"◌",hint:"drag a box to select an ellipse; Shift adds, Alt subtracts"},{id:"lasso",label:"Lasso",key:"Q",icon:"➰",hint:"drag around an area to select it; Shift adds, Alt subtracts"},{id:"wand",label:"Magic wand",key:"W",icon:"✦",hint:"click to select touching pixels of one colour on your layer (or all of that colour); Shift adds, Alt subtracts"},{id:"move",label:"Move",key:"V",icon:"✣",hint:"drag to move the selection (or your whole layer); arrow keys nudge"},{id:"stamp",label:"Stamp",key:"S",icon:"❖",hint:"click to place the chosen stamp (see Stamps); save one from a selection"},{id:"note",label:"Note",key:"N",icon:"✍︎",hint:"click a pixel or drag a region, then write a note for the agent"},{id:"pivot",label:"Pivot and ground",key:"P",icon:"⌖",hint:"click the pixel the sprite stands on (pivot); Shift+click a row to set the ground line"}],n0={b:"pencil",e:"eraser",l:"line",u:"rect",U:"ellipse",g:"fill",G:"gradient",d:"dither",i:"picker",m:"select",M:"select-ellipse",q:"lasso",w:"wand",v:"move",s:"stamp",n:"note",p:"pivot"},xM=["select","select-ellipse","lasso","wand"],bM=["pencil","eraser","line","rect","ellipse"],dh=(t,a)=>({x:Math.min(t[0],a[0]),y:Math.min(t[1],a[1]),w:Math.abs(t[0]-a[0])+1,h:Math.abs(t[1]-a[1])+1}),Ka=t=>`${t.x},${t.y} ${t.w}x${t.h}`,a0=t=>t%2===0?String(t/2):`${(t-1)/2}.5`;function l0(t,a){let s=t.width,l=t.height,i=-1,r=-1;for(let f=0;f<a.length;f++){if(!a[f])continue;const u=f%t.width,h=(f-u)/t.width;s=Math.min(s,u),i=Math.max(i,u),l=Math.min(l,h),r=Math.max(r,h)}return i<0?null:{x:s,y:l,w:i-s+1,h:r-l+1}}function $M(t){const a=[];for(const s of t)if(!(a.length&&a.at(-1)[0]===s[0]&&a.at(-1)[1]===s[1])){if(a.length>=2){const l=a.at(-2),i=a.at(-1);(i[0]-l[0])*(s[1]-l[1])===(i[1]-l[1])*(s[0]-l[0])&&a.pop()}a.push(s)}return a}class ai{tool="pencil";colour="";colour2="";filled=!1;pixelPerfect=!0;brushSize=1;brushShape="square";mirrorX=!1;mirrorY=!1;wandGlobal=!1;gradientPattern="none";ditherPattern="bayer4";ditherLevel=.5;stamp=null;layerName=null;frame=null;frameSel=null;onionPrev=!1;onionNext=!1;guides=!0;playing=null;playSeq=null;drag=null;combine="";preview=null;noteDraft=null;hover=null;activeNote=null;lastTool="pencil";store;inflight=Promise.resolve();constructor(a){this.store=a}changed(){this.store.changed()}get doc(){const a=this.store.current;return!a||this.store.travel!==null||this.store.status!=="open"||a.problem?null:a.cursor.doc}get editable(){return this.doc!==null}colourName(a,s=!1){const l=s?this.colour2:this.colour;return l==="none"||a.palette.entries.some(i=>i.name===l)?l:a.palette.entries[s?Math.min(1,a.palette.entries.length-1):0]?.name??"none"}setTool(a){a!=="picker"&&(this.lastTool=a),this.tool=a,this.drag=null,this.preview=null,this.changed()}setColour(a,s=!1){s?this.colour2=a:this.colour=a,this.changed()}swapColours(a){const s=this.colourName(a);this.colour=this.colourName(a,!0),this.colour2=s,this.changed()}layerIndex(a){const s=this.layerName===null?-1:a.layers.findIndex(l=>l.name===this.layerName);return s>=0?s:Math.min(et(a,this.store.me).layer,a.layers.length-1)}frameIndex(a){const s=this.frame??et(a,this.store.me).frame;return Math.max(0,Math.min(a.frameCount-1,s))}setLayer(a){this.layerName=a,this.changed()}setFrame(a){this.frame=a,this.changed()}prefix(a){const s=et(a,this.store.me),l=[],i=this.layerIndex(a);i!==s.layer&&l.push(`layer ${a.layers[i].name}`);const r=this.frameIndex(a);r!==s.frame&&l.push(`frame ${r+1}`);const f=this.mirrorX?a.width-1:null,u=this.mirrorY?a.height-1:null,h=s.mirror;f===null&&u===null?h&&l.push("mirror off"):(!h||h.x2!==f||h.y2!==u)&&l.push(`mirror ${[f!==null?`x=${a0(f)}`:"",u!==null?`y=${a0(u)}`:""].filter(Boolean).join(" ")} live`);const d=s.brush;return this.brushSize<=1?d&&l.push("brush off"):(!d||d.shape!==this.brushShape||d.size!==this.brushSize)&&l.push(`brush ${this.brushShape} ${this.brushSize}`),l}mySel(a){return et(a,this.store.me).sel}down(a,s={}){this.store.catchUp();const l=this.doc;if(!l)return;this.store.follow&&this.store.setFollow(!1),this.noteDraft=null;const i=xM.includes(this.tool);if(this.tool==="picker"||s.alt&&!i){this.pick(l,a);return}switch(this.combine=i?s.shift?" add":s.alt?" sub":"":"",this.tool){case"pencil":case"eraser":case"lasso":this.drag={kind:"points",pts:[a]};break;case"line":case"rect":case"ellipse":case"note":case"gradient":case"dither":case"select-ellipse":this.drag={kind:"box",a,b:a};break;case"select":{const r=this.mySel(l),f=a[1]*l.width+a[0],u=!!r&&a[0]>=0&&a[1]>=0&&a[0]<l.width&&a[1]<l.height&&!!r[f];this.drag=u&&!this.combine?{kind:"move",a,b:a}:{kind:"box",a,b:a};break}case"move":this.drag={kind:"move",a,b:a};break;case"wand":if(!l.wrap&&(a[0]<0||a[1]<0||a[0]>=l.width||a[1]>=l.height))return;this.commit(`select wand ${a[0]},${a[1]} mode=${this.wandGlobal?"global":"contiguous"} conn=4${this.combine}`);return;case"fill":if(!l.wrap&&(a[0]<0||a[1]<0||a[0]>=l.width||a[1]>=l.height))return;this.commit(`fill ${a[0]},${a[1]} c=${this.colourName(l)}`);return;case"pivot":if(a[0]<0||a[1]<0||a[0]>=l.width||a[1]>=l.height)return;this.commit(s.shift?`ground ${a[1]}`:`pivot ${a[0]},${a[1]}`,{context:!1});return;case"stamp":{const r=this.stamp?l.stamps[this.stamp]:void 0;if(!r)return;this.commit(`stamp ${this.stamp} ${a[0]-(r.w>>1)},${a[1]-(r.h>>1)}`);return}}this.updatePreview()}move(a){this.hover=a;const s=this.drag;if(s&&a){if(s.kind==="points"){const l=s.pts[s.pts.length-1];(l[0]!==a[0]||l[1]!==a[1])&&s.pts.push(a)}else s.b=a;this.updatePreview()}this.changed()}up(a){const s=this.drag;if(!s)return;if(a&&this.move(a),this.drag=null,this.tool==="note"&&s.kind==="box"){this.noteDraft=this.clampRect(dh(s.a,s.b)),this.preview=null,this.changed();return}const l=this.gestureText(s);if(!l){this.preview=null,this.changed();return}this.commit(l)}cancel(){this.drag=null,this.preview=null,this.noteDraft=null,this.changed()}gestureText(a){const s=this.doc;if(!s)return null;const l=this.colourName(s);if(a.kind==="points"){if(this.tool==="lasso"){const u=$M(a.pts);return u.length>=3?`select lasso ${u.map(h=>`${h[0]},${h[1]}`).join(" ")}${this.combine}`:null}const f=a.pts.map(u=>`${u[0]},${u[1]}`).join(" ");return this.tool==="eraser"?`stroke eraser ${f}`:`stroke pencil c=${l} pp=${this.pixelPerfect?"on":"off"} ${f}`}if(a.kind==="move"){const f=a.b[0]-a.a[0],u=a.b[1]-a.a[1];return f===0&&u===0?null:`shift ${f},${u}`}const i=this.filled?"fill":"outline",r=dh(a.a,a.b);switch(this.tool){case"line":return`line ${a.a[0]},${a.a[1]} ${a.b[0]},${a.b[1]} c=${l}`;case"rect":return`rect ${Ka(r)} c=${l} ${i}`;case"ellipse":return`ellipse ${Ka(r)} c=${l} ${i}`;case"select":return`select rect ${Ka(this.clampRect(r))}${this.combine}`;case"select-ellipse":return`select ellipse ${Ka(r)}${this.combine}`;case"dither":return`dither ${Ka(r)} a=${this.colourName(s,!0)} b=${l} pattern=${this.ditherPattern} level=${this.ditherLevel}`;case"gradient":return this.gradientText(s,a.a,a.b);default:return null}}gradientText(a,s,l){const i=l[0]-s[0],r=l[1]-s[1];if(i===0&&r===0)return null;const f=Math.abs(i)>=Math.abs(r)?i>0?"right":"left":r>0?"down":"up",u=this.mySel(a),h=(u&&l0(a,u))??{x:0,y:0,w:a.width,h:a.height},d=this.colourName(a),p=this.colourName(a,!0);if(d==="none"||p==="none"||d===p)return null;let y=`${d},${p}`;for(const[w,x]of Object.entries(a.palette.ramps)){const b=x.indexOf(d),v=x.indexOf(p);if(!(b<0||v<0)){b===0&&v===x.length-1?y=w:y=(b<v?x.slice(b,v+1):x.slice(v,b+1).reverse()).join(",");break}}return`gradient ${Ka(h)} ramp=${y} dir=${f} pattern=${this.gradientPattern}`}clampRect(a){const s=this.doc;if(!s)return a;const l=Math.max(0,a.x),i=Math.max(0,a.y),r=Math.min(s.width,a.x+a.w),f=Math.min(s.height,a.y+a.h);return{x:l,y:i,w:Math.max(1,r-l),h:Math.max(1,f-i)}}get marquee(){const a=this.drag;return a?.kind==="box"&&(this.tool==="select"||this.tool==="select-ellipse"||this.tool==="note"||this.tool==="dither")?dh(a.a,a.b):null}get lassoPath(){const a=this.drag;return a?.kind==="points"&&this.tool==="lasso"?a.pts:null}get dragOffset(){const a=this.drag;return a?.kind==="move"?[a.b[0]-a.a[0],a.b[1]-a.a[1]]:null}updatePreview(){const a=this.drag,s=a&&!(this.tool==="lasso"||this.tool==="select"||this.tool==="select-ellipse")?this.gestureText(a):null;this.preview=s?{text:s,doc:this.apply(this.withContext(s))}:null}withContext(a){const s=this.doc;return s?[...this.prefix(s),a].join(`
|
|
40
|
+
`):a}apply(a){const s=this.store.current;if(!s||!s.cursor.doc)return null;const l=tN({doc:s.cursor.doc,entries:s.cursor.done},a,{by:this.store.me,palettes:this.store.paletteSource,assets:i=>i===s.name?void 0:this.store.assets.get(i)?.cursor.doc??void 0,assetNames:()=>[...this.store.assets.keys()]});return l.ok?l.state.doc:null}previewDoc(){return this.preview?.doc??null}pick(a,s){const[l,i]=s;if(l<0||i<0||l>=a.width||i>=a.height)return;const r=Ce(a,this.frameIndex(a))[i*a.width+l];this.colour=r===ne?"none":a.palette.entries[r].name,this.tool==="picker"&&(this.tool=this.lastTool),this.changed()}async commit(a,s={}){const l=this.store.current;if(!l)return!1;const i=s.context===!1?a:this.withContext(a);this.preview={text:i,doc:this.apply(i)},this.changed();const r=this.store.send(l.name,i),f=this.inflight;this.inflight=f.then(()=>r);const u=await r;return this.preview?.text===i&&(this.preview=null),this.changed(),u.ok}writeNote(a){const s=this.noteDraft;if(!s||!a.trim())return Promise.resolve(!1);this.noteDraft=null;const l=s.w===1&&s.h===1?`${s.x},${s.y}`:Ka(s);return this.commit(`note ${l} ${wa(a.trim().replace(/\s+/g," "))}`,{context:!1})}closeNote(a){return this.commit(`note done ${a.id}`,{context:!1})}canUndo(){const a=this.store.current;return!!a&&this.editable&&"group"in Xv(a.tape,null,this.store.me)}canRedo(){const a=this.store.current;return!!a&&this.editable&&"group"in Zv(a.tape,null,this.store.me)}undo(){this.inflight=this.inflight.then(()=>this.canUndo()?this.commit(`undo by=${this.store.me}`,{context:!1}):void 0)}redo(){this.inflight=this.inflight.then(()=>this.canRedo()?this.commit(`redo by=${this.store.me}`,{context:!1}):void 0)}act(a,s={}){this.editable&&this.commit(a,s)}hasSel(){const a=this.doc;return!!a&&!!this.mySel(a)}deselect(){this.hasSel()&&this.act("deselect",{context:!1})}saveStamp(a){const s=this.doc,l=s&&this.mySel(s),i=s&&l?l0(s,l):null;return!s||!i?Promise.resolve(!1):this.commit(`stamp save ${a} ${Ka(i)}`).then(r=>(r&&(this.stamp=a,this.changed()),r))}addLayer(){const a=this.doc;if(!a)return;let s=a.layers.length+1;for(;a.layers.some(i=>i.name===`layer${s}`);)s++;const l=`layer${s}`;this.commit(`layer add ${l} above=${a.layers[this.layerIndex(a)].name}`,{context:!1}).then(i=>i&&this.setLayer(l))}moveLayer(a,s){const l=this.doc;if(!l)return;const i=l.layers.findIndex(f=>f.name===a),r=l.layers[i+s];r&&this.act(`layer move ${a} ${s>0?"above":"below"}=${r.name}`,{context:!1})}addFrame(){const a=this.doc;if(!a)return;const s=this.frameIndex(a);this.commit(`frame add ${s+2} copy=${s+1}`,{context:!1}).then(l=>l&&this.setFrame(s+1))}removeFrame(){const a=this.doc;if(!a||a.frameCount<2)return;const s=this.frameIndex(a);this.commit(`frame remove ${s+1}`,{context:!1}).then(l=>l&&this.setFrame(Math.max(0,s-1)))}frames(a){const s=this.frameSel;if(s&&s.to<a.frameCount)return s;const l=this.frameIndex(a);return{from:l,to:l}}pickFrame(a,s,l){if(l){const i=this.frameSel?.from??this.frameIndex(a);this.frameSel={from:Math.min(i,s),to:Math.max(i,s)},this.changed();return}(!this.frameSel||s<this.frameSel.from||s>this.frameSel.to)&&(this.frameSel=null),this.setFrame(s)}static rangeText(a){return a.from===a.to?String(a.from+1):`${a.from+1}-${a.to+1}`}setTicks(a,s){this.act(`frame set ${ai.rangeText(this.frames(a))} ticks=${s}`,{context:!1})}addTag(a,s,l){this.act(`tag add ${s} ${ai.rangeText(this.frames(a))} loop=${l}`,{context:!1})}setView(a,s){const l=this.frames(a);this.act(`view ${s} frames=${l.from+1}-${l.to+1}`,{context:!1})}link(a,s){const l=this.frames(a),i=a.layers[this.layerIndex(a)].name;this.act(`cel ${s?"link":"unlink"} ${l.from+1}-${l.to+1} layer=${i}`,{context:!1})}toggle(a){this[a]=!this[a],this.changed()}play(a){this.playing=a===null?null:{seq:a,start:performance.now()},this.changed()}stepFrame(a){const s=this.store.shownDoc().doc;s&&this.setFrame((this.frameIndex(s)+a+s.frameCount)%s.frameCount)}key(a){const s=a.metaKey||a.ctrlKey,l=a.key;if(s&&(l==="z"||l==="Z"))return a.shiftKey?this.redo():this.undo(),!0;if(s&&l==="y")return this.redo(),!0;if(s&&l==="d")return this.deselect(),!0;if(s&&l==="a")return this.act("select all",{context:!1}),!0;if(s&&(l==="i"||l==="I")&&a.shiftKey)return this.act("select invert",{context:!1}),!0;if(s||a.altKey)return!1;if(l==="Escape")return this.drag||this.noteDraft?this.cancel():this.deselect(),!0;if((l==="Delete"||l==="Backspace")&&this.hasSel())return this.act("clear"),!0;const i={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]};if(i[l]&&(this.hasSel()||this.tool==="move"))return this.act(`shift ${i[l][0]},${i[l][1]}`),!0;if(a.shiftKey&&(l==="H"||l==="V"))return this.act(`flip ${l.toLowerCase()}`),!0;if(a.shiftKey&&l==="R")return this.act("rotate 90"),!0;if(l==="Enter"&&this.playSeq)return this.play(this.playing?null:this.playSeq),!0;if(l==="["||l==="]")return this.stepFrame(l==="]"?1:-1),!0;if(l==="x"||l==="X"){const f=this.doc;return f&&this.swapColours(f),!0}if(l==="f"||l==="F")return this.filled=!this.filled,this.changed(),!0;const r=n0[a.shiftKey?l.toUpperCase():l.toLowerCase()]??n0[l.toLowerCase()];return r?(this.setTool(r),!0):!1}usesBrush(){return bM.includes(this.tool)}}const s0=Object.keys(mc);function kM({results:t,store:a}){const s=t.filter(l=>l.status!=="skip");return s.length?k.jsx("span",{className:"checks","data-testid":"checks",children:s.map(l=>k.jsxs("button",{className:`chip check ${l.status}${a.marked.has(l.id)?" on":""}`,"data-check":l.id,"data-status":l.status,title:`${l.id}: ${l.shown} (${l.limit})
|
|
41
|
+
${l.detail}${l.flagged.length?`
|
|
42
|
+
click to circle the ${l.flagged.length} flagged px`:""}`,onClick:()=>a.toggleCheck(l.id),children:[l.id," ",l.status==="fail"||!/^[01]$/.test(l.shown)?k.jsx("span",{className:"score",children:l.shown}):null," ",l.status==="pass"?"✓":"✗"]},l.id))}):null}function _M(t){const a=t.map(r=>r[0]),s=t.map(r=>r[1]),l=Math.min(...a),i=Math.min(...s);return{x:l,y:i,w:Math.max(...a)-l+1,h:Math.max(...s)-i+1}}function jM(t){const a=[...t],s=[];for(;a.length;){const l=[a.shift()];for(let i=0;i<l.length;i++)for(let r=a.length-1;r>=0;r--)Math.max(Math.abs(a[r][0]-l[i][0]),Math.abs(a[r][1]-l[i][1]))<=2&&l.push(...a.splice(r,1));s.push(l)}return s}const o0=(t,a=16)=>t.slice(0,a).map(([s,l])=>`${s},${l}`).join(" ")+(t.length>a?` … +${t.length-a}`:"");function SM({result:t,ed:a,editable:s,onClose:l}){const i=(r,f)=>{const u=jM(f).sort((h,d)=>d.length-h.length).slice(0,6).map(h=>{const d=_M(h);return`note ${d.w===1&&d.h===1?`${d.x},${d.y}`:`${d.x},${d.y} ${d.w}x${d.h}`} ${wa(`${t.id}: ${r} (${o0(h,12)})`.slice(0,900))}`});a.commit(u.join(`
|
|
43
|
+
`),{context:!1})};return k.jsxs("div",{className:`banner check-details ${t.status}`,"data-testid":"check-details","data-check":t.id,children:[k.jsxs("div",{className:"cd-head",children:[k.jsx("b",{children:t.id})," ",k.jsx("span",{className:"score",children:t.shown})," ",k.jsxs("span",{className:"dim",children:["(",t.limit||"no threshold",")"]}),k.jsx("span",{className:"cd-detail",children:t.detail}),k.jsx("span",{className:"spacer"}),k.jsx("button",{onClick:l,title:"Hide the marks and these details","data-testid":"check-close",children:"✕"})]}),t.groups.map(r=>k.jsxs("div",{className:"cd-group",children:[k.jsx("span",{className:"mark-dot"})," ",r.label,": ",k.jsx("span",{className:"mono",children:o0(r.pts)}),s&&k.jsx("button",{className:"mini",onClick:()=>i(r.label,r.pts),title:"Pin notes on these pixels for the agent (one per cluster)","data-testid":"check-pin",children:"📌 note"})]},r.label)),t.parts?.map(r=>k.jsxs("div",{className:"cd-group",children:[r.pass===null?"–":r.pass?"✓":"✗"," ",r.name,": ",r.detail,r.limit?` (${r.limit})`:""]},r.name))]})}function NM({img:t,testid:a}){const s=he.useRef(null);return he.useLayoutEffect(()=>{const l=s.current;l&&(l.width=t.width,l.height=t.height,l.getContext("2d").putImageData(new ImageData(new Uint8ClampedArray(t.data),t.width,t.height),0,0))},[t]),k.jsx("canvas",{ref:s,"data-testid":a,style:{width:t.width,height:t.height}})}function MM(t){const a=new Set(t.font.chars.map(r=>String.fromCodePoint(r))),s=r=>[...r].filter(f=>f===" "||a.has(f)).join("").trim(),l=["THE QUICK BROWN FOX","JUMPS OVER THE LAZY DOG","the quick brown fox","0123456789 !?.,:"].map(s).filter(r=>r.replace(/ /g,"").length>=4);if(l.length)return l.join(`
|
|
44
|
+
`);const i=t.font.chars.map(r=>String.fromCodePoint(r));return Array.from({length:Math.ceil(i.length/16)},(r,f)=>i.slice(f*16,f*16+16).join("")).join(`
|
|
45
|
+
`)}function i0(t,a,s,l=2){const i=(t.width+l*2)*a,r=(t.height+l*2)*a,f={width:i,height:r,data:new Uint8Array(i*r*4)};for(let u=0;u<r;u++)for(let h=0;h<i;h++){const d=Math.floor(h/a)-l,p=Math.floor(u/a)-l,y=d>=0&&p>=0&&d<t.width&&p<t.height?(p*t.width+d)*4:-1;f.data.set(y>=0&&t.data[y+3]?[t.data[y],t.data[y+1],t.data[y+2],255]:[...s,255],(u*i+h)*4)}return f}function zM({doc:t,frame:a,store:s,marks:l}){const i=t.font?["text"]:t.family||t.overlay?["map","themes"]:t.wrap?["3x3","themes"]:["game","themes"],r=s.assetDocs(),f=t.densityOf?.of??(r.some($=>$.doc.densityOf?.of===(s.current?.name??t.name))?s.current?.name??t.name:null),u=f?[...i,"density"]:i,[h,d]=he.useState("3x3"),p=u.includes(h)?h:u[0],[y,w]=he.useState(!0),x=s.current?.name??t.name;let b=null,v="";if(y)if(p==="text"){const $=MM(t),_=Y$(t,$,li(t.palette,s.themeObj()).entries.map(A=>A.hex)),j=_.width*2>300?1:2,N=i0(_,j,[24,26,32]),M=i0(_,j,[232,230,222]);b={width:N.width,height:N.height*2,data:new Uint8Array([...N.data,...M.data])},v=`line ${t.font.line} px, baseline row ${t.font.baseline}, spacing ${t.font.spacing}; ${t.font.chars.length} glyphs`}else if(p==="map"){const $=s.assetDocs(),_=t.overlay?$.find(j=>j.doc.family)??Nh(x,$,s.style):null;if(t.family||_){const j=t.family?.tile??_?.doc.cellW??24,N=Math.max(6,Math.min(12,Math.round(288/j)));b=V0(t,{cols:N,rows:Math.round(N*3/4),seed:1,scale:1,theme:s.themeObj(),ground:_?.doc??null}),v=t.family?"a random island; the seam and more in the map view (toolbar)":`over ${_.name}`}else v="no family or tile to show it over"}else if(p==="density"){const $=r.find(_=>_.name===f)?.doc;if($){const _=s.style?.density??{},j=Qk($,r.filter(N=>N.doc.densityOf?.of===f).map(N=>N.doc),{frame:a,scale:1,reducer:_.reducer,ink:_.ink,share:_.share});b=j.img,v=j.text.split(`
|
|
46
|
+
`).filter(N=>/ reduced |no higher/.test(N)).join(" ")}else v=`no asset '${f}'`}else if(p==="3x3")b=Dk(t,a,{theme:s.themeObj(),marks:l,scale:t.width<=32?2:1});else if(p==="game"){const $=s.assetDocs(),_=Nh(x,$,s.style),j=Vv(x,t,$,s.style).slice(0,5);b=Hk([{doc:t,frame:a},...j.map(N=>({doc:N.doc}))],{ground:_?.doc??null,scale:Os(s.style,s.project?.grid),theme:s.themeObj(),marks:l}),v=`${_?`on ${_.name}`:"no ground tile"}${j.length?`, beside ${j.map(N=>N.name).join(", ")}`:""}; ${Os(s.style,s.project?.grid)===1?"at 1x, the draw scale":`1x and ${Os(s.style,s.project?.grid)}x`}`}else b=Lk(t,s.themes.slice(0,6),{frame:a,scale:Math.max(1,Math.min(2,Math.floor(48/Math.max(t.width,t.height))))}),v=Uh(t.palette)?s.themes.slice(0,6).map($=>$.name).join(" · "):"no role colours: the art looks the same under every theme";return k.jsxs("div",{className:"preview","data-testid":"preview",children:[k.jsxs("div",{className:"panel-title",children:["Preview",u.map($=>k.jsx("button",{className:`mini${$===p&&y?" on":""}`,"data-tab":$,onClick:()=>{d($),w(!0)},children:$},$)),k.jsx("span",{className:"spacer"}),k.jsx("button",{className:"mini",onClick:()=>w(!y),title:y?"Hide the preview":"Show the preview",children:y?"▾":"▸"})]}),b&&k.jsxs("div",{className:"preview-body",children:[k.jsx(NM,{img:b,testid:`preview-${p}`}),v&&k.jsx("div",{className:"dim",children:v})]})]})}function CM({ed:t,disabled:a}){return k.jsx("div",{className:"tools","data-testid":"tools",children:vM.map(s=>k.jsx("button",{className:t.tool===s.id?"on":"",disabled:a,"data-tool":s.id,"aria-label":s.label,title:`${s.label} (${s.key}): ${s.hint}`,onClick:()=>t.setTool(s.id),children:s.icon},s.id))})}const r0=/^#[0-9a-f]{6}$/;function EM({palette:t,ed:a,editable:s,locked:l,theme:i,themes:r,onTheme:f}){const[u,h]=he.useState(null),d=a.doc?a.colourName(a.doc):a.colour,p=a.doc?a.colourName(a.doc,!0):a.colour2,y=s&&!l,w=Uh(t),x=li(t,r.find(v=>v.name===i)),b=async()=>{if(!u||!r0.test(u.hex))return;let v;if(u.name===null)v=`palette add${u.newName.trim()?` ${u.newName.trim()}`:""} hex=${u.hex}${u.role?` role=${u.role}`:""}`;else{const $=u.was,_=u.hex!==$.hex?` hex=${u.hex}`:"",j=u.role!==$.role?` role=${u.role||"none"}`:"";if(!_&&!j){h(null);return}v=`palette set ${u.name}${_}${j}`}await a.commit(v,{context:!1})&&h(null)};return k.jsxs(k.Fragment,{children:[k.jsxs("div",{className:"panel-title",children:["Palette ",k.jsx("span",{className:"dim",children:t.name}),l&&k.jsx("span",{className:"dim",title:"The palette is locked (palette unlock to change it)","data-testid":"palette-locked",children:"🔒"}),k.jsx("span",{className:"spacer"}),s&&k.jsx("button",{className:"mini",title:l?"Unlock the palette (palette unlock)":"Lock the palette: no more colour edits (palette lock)","data-testid":"palette-lock",onClick:()=>{a.commit(l?"palette unlock":"palette lock",{context:!1})},children:l?"unlock":"lock"}),y&&k.jsx("button",{className:"mini",title:"Add a colour to this asset's palette","data-testid":"palette-add",onClick:()=>h({name:null,hex:"#808080",newName:"",role:"",was:null}),children:"+"})]}),w&&k.jsxs("label",{className:"theme-row",title:"Show role colours under a preview theme (only for looking: nothing is written)",children:["theme",k.jsxs("select",{className:"theme-select",value:i??"",onChange:v=>f(v.target.value||null),"data-testid":"theme",children:[k.jsx("option",{value:"",children:"own colours"}),r.map(v=>k.jsx("option",{value:v.name,children:v.name},v.name))]})]}),u&&k.jsxs("div",{className:"palette-edit","data-testid":"palette-edit",children:[k.jsx("input",{type:"color",value:u.hex,onChange:v=>h({...u,hex:v.target.value})}),k.jsx("input",{className:"hex",value:u.hex,spellCheck:!1,"aria-label":"hex",onChange:v=>h({...u,hex:v.target.value.toLowerCase()}),onKeyDown:v=>{v.key==="Enter"&&b(),v.key==="Escape"&&h(null)}}),u.name===null&&k.jsx("input",{className:"pname",placeholder:"name",value:u.newName,"aria-label":"name",onChange:v=>h({...u,newName:v.target.value})}),k.jsxs("select",{value:u.role,onChange:v=>h({...u,role:v.target.value}),"data-testid":"palette-role",title:"A role makes the entry recolourable: themes show it in their colour (palette … role=)",children:[k.jsx("option",{value:"",children:"no role"}),Un.map(v=>k.jsx("option",{value:v,children:v},v))]}),k.jsx("button",{onClick:()=>{b()},disabled:!r0.test(u.hex),"data-testid":"palette-save",title:u.name===null?"Add this colour (palette add)":`Set ${u.name} (palette set)`,children:u.name===null?"Add":"Set"}),k.jsx("button",{onClick:()=>h(null),title:"Cancel (Esc)",children:"✕"})]}),k.jsxs("div",{className:"swatches","data-testid":"swatches",children:[k.jsxs("div",{className:`swatch${d==="none"?" on":""}${p==="none"?" two":""}`,title:"none: transparent (draws by clearing)",onClick:()=>a.setColour("none"),onContextMenu:v=>{v.preventDefault(),a.setColour("none",!0)},"data-colour":"none",children:[k.jsx("span",{className:"chip-colour none"}),k.jsx("span",{className:"key",children:"·"}),k.jsx("span",{className:"sname",children:"none"}),d==="none"&&k.jsx("span",{className:"ab",children:"A"}),p==="none"&&k.jsx("span",{className:"ab b",children:"B"})]}),t.entries.map((v,$)=>k.jsxs("div",{className:`swatch${d===v.name?" on":""}${p===v.name?" two":""}`,title:`${v.name} ${v.hex}${v.role?` role ${v.role}`:""} key ${v.key} (click: colour A, right-click: colour B${y?", double-click to change the colour or role":""})`,"data-colour":v.name,onClick:()=>a.setColour(v.name),onContextMenu:_=>{_.preventDefault(),a.setColour(v.name,!0)},onDoubleClick:()=>y&&h({name:v.name,hex:v.hex,newName:"",role:v.role??"",was:{hex:v.hex,role:v.role??""}}),children:[k.jsx("span",{className:"chip-colour",style:{background:x.entries[$].hex}}),k.jsx("span",{className:"key",children:v.key}),k.jsx("span",{className:"sname",children:v.name}),v.role&&k.jsx("span",{className:"role","data-role":v.role,children:v.role}),d===v.name&&k.jsx("span",{className:"ab",children:"A"}),p===v.name&&k.jsx("span",{className:"ab b",children:"B"})]},v.key))]})]})}function TM(t){const a=new Map;for(const s of t){const l=/ id=(n\d+)$/.exec(s.cmd)?.[1];l&&s.cmd.startsWith("note ")&&a.set(l,s.by)}return a}function OM({doc:t,tape:a,ed:s,editable:l,active:i,onActive:r}){if(t.notes.length===0)return null;const f=TM(a);return k.jsxs(k.Fragment,{children:[k.jsxs("div",{className:"panel-title",children:["Notes ",k.jsxs("span",{className:"dim",children:[t.notes.length," open"]})]}),k.jsx("ul",{className:"notes","data-testid":"notes",children:t.notes.map(u=>k.jsxs("li",{className:u.id===i?"on":"",onClick:()=>r(u.id===i?null:u.id),children:[k.jsx("span",{className:"nid",children:u.id}),k.jsxs("span",{className:"ntext",children:[u.text,k.jsxs("span",{className:"dim",children:[" · ",u.x,",",u.y,u.w>1||u.h>1?` ${u.w}×${u.h}`:""," · ",f.get(u.id)??"?"]})]}),l&&k.jsx("button",{className:"mini",title:"Close this note (note done)",onClick:h=>{h.stopPropagation(),s.closeNote(u)},children:"✓"})]},u.id))})]})}function AM({s:t,palette:a}){const s=he.useRef(null);he.useEffect(()=>{const i=s.current;if(!i)return;i.width=t.w,i.height=t.h;const r=new ImageData(t.w,t.h);for(let f=0;f<t.px.length;f++){if(t.px[f]===ne)continue;const[u,h,d]=vn(a.entries[t.px[f]]?.hex??"#ff00ff");r.data.set([u,h,d,255],f*4)}i.getContext("2d").putImageData(r,0,0)},[t,a]);const l=Math.max(1,Math.min(4,Math.floor(32/Math.max(t.w,t.h))));return k.jsx("canvas",{ref:s,style:{width:t.w*l,height:t.h*l}})}function qM({doc:t,ed:a,editable:s}){const[l,i]=he.useState(null),r=Object.keys(t.stamps).sort(),f=()=>{let u=r.length+1;for(;t.stamps[`stamp${u}`];)u++;return`stamp${u}`};return k.jsxs(k.Fragment,{children:[k.jsxs("div",{className:"panel-title",children:["Stamps ",k.jsx("span",{className:"dim",children:r.length||""}),k.jsx("span",{className:"spacer"}),s&&l===null&&k.jsx("button",{className:"mini",disabled:!a.hasSel(),title:"Save your selection as a stamp (stamp save)","data-testid":"stamp-save",onClick:()=>i(f()),children:"+ stamp"})]}),l!==null&&k.jsxs("form",{className:"palette-edit",onSubmit:u=>{u.preventDefault(),a.saveStamp(l).then(h=>h&&i(null))},children:[k.jsx("input",{value:l,onChange:u=>i(u.target.value),"aria-label":"stamp name",autoFocus:!0}),k.jsx("button",{type:"submit","data-testid":"stamp-save-ok",children:"Save"}),k.jsx("button",{type:"button",onClick:()=>i(null),children:"✕"})]}),k.jsx("div",{className:"stamps","data-testid":"stamps",children:r.map(u=>k.jsxs("button",{className:`stamp${a.stamp===u?" on":""}`,"data-stamp":u,title:`${u} (${t.stamps[u].w}x${t.stamps[u].h}): click, then click the canvas to place it`,onClick:()=>{a.stamp=u,a.setTool("stamp")},children:[k.jsx(AM,{s:t.stamps[u],palette:t.palette}),k.jsx("span",{children:u})]},u))})]})}const RM=[{key:"hidden",on:"◌",off:"◉",title:"Hidden (not in the art): layer set … hidden=on|off"},{key:"locked",on:"🔒︎",off:"·",title:"Locked (refuses drawing): layer set … locked=on|off"},{key:"reference",on:"R",off:"·",title:"Reference (a guide under the art, never exported): layer set … reference=on|off"}];function c0(t,a){const s=[];for(let l=0;l<t;){const i=a.find(r=>r.from===l);i?(s.push({r:i,span:i.to-i.from+1}),l=i.to+1):(s.push({r:null,at:l}),l++)}return s}function DM({doc:t,ed:a,editable:s,frameShown:l}){const[i,r]=he.useState(null),[f,u]=he.useState(null),[h,d]=he.useState(""),[p,y]=he.useState(()=>new Set),w=T=>y(D=>{const L=new Set(D);return L.has(T)?L.delete(T):L.add(T),L}),x=(T,D,L)=>k.jsxs("th",{colSpan:4,className:"rowhead fold","data-testid":`tl-fold-${T}`,onClick:()=>w(T),title:`${p.has(T)?"Show":"Hide"} the ${D} row${L!==void 0?"s":""} (only for looking)`,children:[p.has(T)?"▸":"▾"," ",D,p.has(T)&&L!==void 0?` (${L})`:""]}),b=a.layerIndex(t),v=a.frameIndex(t),$=t.layers[b],_=a.frames(t),j=T=>_.from<=T&&T<=_.to,N=Pa(t),M=N.find(T=>T.name===a.playSeq)??N[0];a.playSeq!==M.name&&(a.playSeq=M.name);const A=(T,D)=>t.cels[T][D].some(L=>L!==ne),z=(T,D)=>{const L=t.cels[T];return L.flatMap((Y,O)=>O!==D&&Y===L[D]?[O+1]:[])},E=T=>t.views.find(D=>D.mirror&&D.from<=T&&T<=D.to)??null,R=t.layers.map((T,D)=>D).reverse(),B=ai.rangeText(_),K=Fa.filter(T=>!t.views.some(D=>D.name===T)),J=t.views.filter(T=>!T.mirror&&Cl(T.name)&&!t.views.some(D=>D.name===Cl(T.name)));return k.jsxs("div",{className:`timeline${p.has("all")?" folded":""}`,"data-testid":"timeline",children:[k.jsxs("div",{className:"tl-bar",children:[k.jsx("button",{className:"mini","data-testid":"tl-fold-all",onClick:()=>w("all"),title:p.has("all")?"Show the timeline":"Fold the timeline away (only for looking)",children:p.has("all")?"▸":"▾"}),k.jsx("span",{className:"tl-title",children:"Layers"}),k.jsx("button",{className:"mini",disabled:!s,onClick:()=>a.addLayer(),title:`New layer above ${$.name} (layer add)`,"data-testid":"layer-add",children:"+"}),k.jsx("button",{className:"mini",disabled:!s||b===t.layers.length-1,onClick:()=>a.moveLayer($.name,1),title:`Move ${$.name} up (layer move)`,"data-testid":"layer-up",children:"↑"}),k.jsx("button",{className:"mini",disabled:!s||b===0,onClick:()=>a.moveLayer($.name,-1),title:`Move ${$.name} down (layer move)`,"data-testid":"layer-down",children:"↓"}),k.jsx("button",{className:"mini",disabled:!s||b===0,onClick:()=>a.act(`layer merge ${$.name}`,{context:!1}),title:`Merge ${$.name} into the layer below (layer merge)`,"data-testid":"layer-merge",children:"⤓"}),k.jsx("button",{className:"mini",disabled:!s||t.layers.length<2,onClick:()=>a.act(`layer remove ${$.name}`,{context:!1}),title:`Remove ${$.name} (layer remove)`,"data-testid":"layer-remove",children:"✕"}),k.jsx("span",{className:"spacer"}),k.jsx("span",{className:"tl-title",children:"Frames"}),k.jsx("button",{className:"mini",onClick:()=>a.stepFrame(-1),disabled:t.frameCount<2,title:"Previous frame ([)",children:"◀"}),k.jsxs("span",{className:"dim","data-testid":"frame-now",children:[l+1," / ",t.frameCount]}),k.jsx("button",{className:"mini",onClick:()=>a.stepFrame(1),disabled:t.frameCount<2,title:"Next frame (])",children:"▶"}),k.jsx("button",{className:"mini",disabled:!s,onClick:()=>a.addFrame(),title:`New frame after ${v+1}, a copy of it (frame add)`,"data-testid":"frame-add",children:"+"}),k.jsx("button",{className:"mini",disabled:!s||t.frameCount<2,onClick:()=>a.removeFrame(),title:`Remove frame ${v+1} (frame remove)`,"data-testid":"frame-remove",children:"✕"})]}),!p.has("all")&&k.jsxs("div",{className:"tl-bar tl-anim",children:[k.jsx("button",{className:`mini play${a.playing?" on":""}`,"data-testid":"play",disabled:t.frameCount<2,onClick:()=>a.play(a.playing?null:M.name),title:`${a.playing?"Stop":"Play"} ${M.name} at the game's speed (Enter); only for looking`,children:a.playing?"⏸":"▶"}),k.jsx("select",{value:M.name,"data-testid":"play-seq",title:"The sequence to play: a view or a tag (all frames when there is neither)",onChange:T=>{a.playSeq=T.target.value,a.playing?a.play(T.target.value):a.play(null)},children:N.map(T=>k.jsxs("option",{value:T.name,children:[T.name,T.loop==="pingpong"?" ⇄":""]},T.name))}),k.jsx("span",{className:"tl-title",children:"Onion"}),k.jsxs("label",{className:"chk",title:"Show the frame before yours in its view or tag, tinted red, under yours (only for looking)",children:[k.jsx("input",{type:"checkbox",checked:a.onionPrev,"data-testid":"onion-prev",onChange:()=>a.toggle("onionPrev")}),"◁"]}),k.jsxs("label",{className:"chk",title:"Show the frame after yours in its view or tag, tinted blue, under yours (only for looking; with two frames, the one before)",children:[k.jsx("input",{type:"checkbox",checked:a.onionNext,"data-testid":"onion-next",onChange:()=>a.toggle("onionNext")}),"▷"]}),k.jsxs("label",{className:"chk",title:"Show the pivot and the ground line (set them with the ⌖ tool, P)",children:[k.jsx("input",{type:"checkbox",checked:a.guides,"data-testid":"guides",onChange:()=>a.toggle("guides")}),"⌖"]}),k.jsx("span",{className:"spacer"}),k.jsxs("span",{className:"tl-title",title:"Shift+click frame numbers to choose several",children:["Frames ",B]}),k.jsx("button",{className:"mini",disabled:!s,"data-testid":"link",title:`Link ${$.name}'s cels on frames ${B}: they share pixels (cel link)`,onClick:()=>a.link(t,!0),children:"⛓"}),k.jsx("button",{className:"mini",disabled:!s,"data-testid":"unlink",title:`Unlink ${$.name}'s cels on frames ${B} (cel unlink)`,onClick:()=>a.link(t,!1),children:"⛓̸"}),k.jsxs("select",{value:"",disabled:!s,"data-testid":"view-set",title:`Make frames ${B} a direction (view … frames=)`,onChange:T=>{T.target.value&&a.setView(t,T.target.value)},children:[k.jsx("option",{value:"",children:"view…"}),Fa.filter(T=>K.includes(T)||t.views.some(D=>D.name===T&&!D.mirror)).map(T=>k.jsx("option",{value:T,children:T},T))]}),k.jsxs("select",{value:"",disabled:!s||!J.length,"data-testid":"mirror-add",title:"Add a direction that mirrors another live (view W mirror=E)",onChange:T=>{const D=J.find(L=>L.name===T.target.value);D&&a.act(`view ${Cl(D.name)} mirror=${D.name}`,{context:!1})},children:[k.jsx("option",{value:"",children:"mirror…"}),J.map(T=>k.jsxs("option",{value:T.name,children:[Cl(T.name)," ⇋ ",T.name]},T.name))]}),k.jsx("form",{className:"tagform",onSubmit:T=>{T.preventDefault(),h.trim()&&(a.addTag(t,h.trim(),"cycle"),d(""))},children:k.jsx("input",{value:h,disabled:!s,placeholder:"tag","aria-label":"tag the chosen frames","data-testid":"tag-name",onChange:T=>d(T.target.value),title:`Name frames ${B} (tag add; Enter)`})})]}),!p.has("all")&&k.jsx("div",{className:"tl-grid",children:k.jsxs("table",{children:[k.jsxs("thead",{children:[k.jsxs("tr",{className:"tl-ticks",children:[x("ticks","frame · ticks"),Array.from({length:t.frameCount},(T,D)=>k.jsxs("th",{className:`fhead${D===l?" fnow":""}${j(D)&&a.frameSel?" fsel":""}`,"data-frame-head":D+1,onClick:L=>a.pickFrame(t,D,L.shiftKey),onDoubleClick:()=>s&&!E(D)&&u({f:D,v:String(t.ticks[D])}),title:`Frame ${D+1}: ${t.ticks[D]} ticks. Click to draw on it, Shift+click to choose frames, double-click to change its ticks (frame set)`,children:[k.jsx("div",{children:D+1}),p.has("ticks")?null:f?.f===D?k.jsx("form",{onSubmit:L=>{L.preventDefault();const Y=Number(f.v);Number.isInteger(Y)&&Y>=1&&Y!==t.ticks[D]&&a.act(`frame set ${j(D)?B:D+1} ticks=${Y}`,{context:!1}),u(null)},children:k.jsx("input",{autoFocus:!0,className:"ticks-in",value:f.v,"aria-label":"ticks","data-testid":"ticks-input",onChange:L=>u({f:D,v:L.target.value}),onBlur:()=>u(null),onKeyDown:L=>{L.key==="Escape"&&u(null)}})}):k.jsx("div",{className:"ticks",children:t.ticks[D]})]},D))]}),k.jsxs("tr",{className:"tl-views",children:[x("views","views",t.views.length),p.has("views")?k.jsx("th",{colSpan:t.frameCount}):c0(t.frameCount,t.views).map(T=>T.r?k.jsxs("th",{colSpan:T.span,className:`band view${T.r.mirror?" mirror":""}`,"data-view":T.r.name,title:T.r.mirror?`View ${T.r.name}: a live mirror of ${T.r.mirror}`:`View ${T.r.name}: frames ${T.r.from+1}-${T.r.to+1}`,children:[T.r.mirror?`${T.r.name} ⇋ ${T.r.mirror}`:T.r.name,k.jsx("button",{className:"x",disabled:!s,title:T.r.mirror?`Unlink the mirror (view ${T.r.name} mirror=off)`:`Remove view ${T.r.name} (view remove)`,onClick:()=>a.act(T.r.mirror?`view ${T.r.name} mirror=off`:`view remove ${T.r.name}`,{context:!1}),children:"✕"})]},`v${T.r.name}`):k.jsx("th",{},`e${T.at}`))]}),t.tags.length>0&&p.has("tags")&&k.jsxs("tr",{className:"tl-tags",children:[x("tags","tags",t.tags.length),k.jsx("th",{colSpan:t.frameCount})]}),!p.has("tags")&&t.tags.map(T=>k.jsxs("tr",{className:"tl-tags",children:[T===t.tags[0]?x("tags","tags",t.tags.length):k.jsx("th",{colSpan:4,className:"rowhead"}),c0(t.frameCount,[T]).map(D=>D.r?k.jsxs("th",{colSpan:D.span,className:"band tag","data-tag":T.name,title:`Tag ${T.name}: frames ${T.from+1}-${T.to+1}, ${T.loop}`,children:[T.name,k.jsx("button",{className:"x",disabled:!s,"data-testid":`tag-loop-${T.name}`,title:`Loop: ${T.loop} (click for ${T.loop==="cycle"?"pingpong":"cycle"}; tag set)`,onClick:()=>a.act(`tag set ${T.name} loop=${T.loop==="cycle"?"pingpong":"cycle"}`,{context:!1}),children:T.loop==="cycle"?"↻":"⇄"}),k.jsx("button",{className:"x",disabled:!s,title:`Remove tag ${T.name} (tag remove)`,onClick:()=>a.act(`tag remove ${T.name}`,{context:!1}),children:"✕"})]},"t"):k.jsx("th",{},`e${D.at}`))]},T.name))]}),k.jsxs("tbody",{children:[t.layers.length>1&&k.jsxs("tr",{className:"tl-layers-head",children:[x("layers","layers",t.layers.length),k.jsx("th",{colSpan:t.frameCount})]}),(p.has("layers")?R.filter(T=>T===b):R).map(T=>{const D=t.layers[T];return k.jsxs("tr",{className:T===b?"on":"","data-layer":D.name,children:[RM.map(L=>k.jsx("td",{className:`flag${D[L.key]?" set":""}`,children:k.jsx("button",{className:"flagbtn",disabled:!s,title:L.title,"data-flag":L.key,onClick:()=>a.act(`layer set ${D.name} ${L.key}=${D[L.key]?"off":"on"}`,{context:!1}),children:D[L.key]?L.on:L.off})},L.key)),k.jsx("td",{className:"lname",onClick:()=>a.setLayer(D.name),onDoubleClick:()=>s&&r({from:D.name,to:D.name}),title:"Click to draw on this layer; double-click to rename",children:i?.from===D.name?k.jsx("form",{onSubmit:L=>{L.preventDefault(),i.to&&i.to!==D.name&&(a.act(`layer rename ${D.name} ${i.to}`,{context:!1}),a.layerName===D.name&&(a.layerName=i.to)),r(null)},children:k.jsx("input",{autoFocus:!0,value:i.to,"aria-label":"layer name",onChange:L=>r({...i,to:L.target.value}),onBlur:()=>r(null),onKeyDown:L=>{L.key==="Escape"&&r(null)}})}):D.name}),Array.from({length:t.frameCount},(L,Y)=>{const O=z(T,Y),H=E(Y);return k.jsx("td",{className:`cel${Y===l?" fnow":""}${T===b&&Y===v?" here":""}${j(Y)&&a.frameSel?" fsel":""}${H?" mirrored":""}`,"data-cel":`${D.name}:${Y+1}`,"data-linked":O.length?O.join(","):void 0,title:`${D.name}, frame ${Y+1}${O.length?`; linked with frame${O.length>1?"s":""} ${O.join(", ")}`:""}${H?`; mirrors ${H.mirror} (draw there)`:""}`,onClick:G=>{a.setLayer(D.name),a.pickFrame(t,Y,G.shiftKey)},children:H?"⇋":O.length?A(T,Y)?"◆":"◇":A(T,Y)?"●":"○"},Y)})]},D.name)})]})]})})]})}function Wv({img:t,k:a=1,testid:s}){const l=he.useRef(null);return he.useLayoutEffect(()=>{const i=l.current;i&&(i.width=t.width,i.height=t.height,i.getContext("2d").putImageData(new ImageData(new Uint8ClampedArray(t.data),t.width,t.height),0,0))},[t]),k.jsx("canvas",{ref:l,"data-testid":s,style:{width:t.width*a,height:t.height*a}})}function UM({doc:t,ed:a,editable:s,frame:l,theme:i}){const r=t.family,f=yt(r),u=new Set(f.pieces),h=new Set(r.detached),d=r.tile<=16?3:r.tile<=32?2:1,p=r.geometry,y=p.bands.length?p.bands.map(w=>`${w.w}:${typeof w.fill=="number"?t.palette.entries[w.fill]?.name:w.fill}`).join(" "):"none";return k.jsxs("div",{className:"family-view","data-testid":"family-variants",children:[k.jsxs("div",{className:"family-head",children:[k.jsx("b",{children:f.name})," ",k.jsxs("span",{className:"dim",children:[f.variants.length," variants of ",r.tile,"×",r.tile," · band ",y," · radius ",p.radius," · inset ",p.inset]}),k.jsx("span",{className:"spacer"}),r.mapCols>0&&k.jsxs(k.Fragment,{children:[k.jsx("button",{className:"mini",disabled:!s,"data-testid":"family-coverage",onClick:()=>a.act("family coverage",{context:!1}),title:`Lay out the ${r.mapCols}x${r.mapRows} coverage map so it holds every variant, with a flat template to paint over (family coverage)`,children:"coverage map"}),k.jsx("button",{className:"mini",disabled:!s||!r.terrain.length||!p.bands.length,"data-testid":"family-cut",onClick:()=>a.act("family cut",{context:!1}),title:"Cut every variant from the painted map: the medoid tile of each, its band only (family cut)",children:"cut from map"})]})]}),k.jsxs("div",{className:"dim family-legend",children:["Each variant sits in the middle of the neighbourhood that makes it. ",k.jsx("span",{className:"piece-tag",children:"piece"})," drawn by hand on layer band, the others built from their quadrants; ",k.jsx("span",{className:"detached-tag",children:"detached"})," drawn by hand."]}),k.jsx("div",{className:"family-grid",children:f.variants.map((w,x)=>{const b=u.has(w.name),v=h.has(w.name);return k.jsxs("div",{className:`variant${b?" piece":""}${v?" detached":""}`,"data-variant":w.name,children:[k.jsx(Wv,{img:Gk(t,x,{frame:l,theme:i}),k:d}),k.jsxs("div",{className:"vname",children:[k.jsx("span",{className:"mono",title:`@cell(${w.name})`,children:w.name}),b?k.jsx("span",{className:"piece-tag",children:"piece"}):k.jsx("button",{className:"mini",disabled:!s,"data-testid":`variant-${v?"attach":"detach"}-${w.name}`,title:v?`Build it from the pieces again (family attach ${w.name})`:`Draw it by hand from now on (family detach ${w.name})`,onClick:()=>a.act(`family ${v?"attach":"detach"} ${w.name}`,{context:!1}),children:v?"attach":"detach"})]})]},w.name)})})]})}const HM=["12x10","16x12","24x16"];function LM({doc:t,store:a,frame:s}){const[l,i]=he.useState("16x12"),[r,f]=he.useState(1),[u,h]=he.useState(!0),[d,p]=he.useState(0),y=a.assetDocs().filter(z=>z.doc.overlay),[w,x]=he.useState(()=>y.map(z=>z.name)),[b,v]=l.split("x").map(Number),$=y.filter(z=>w.includes(z.name)).map(z=>z.doc),_=t.frameCount>1||$.length>0,j=a.project?.tickRate??60;he.useEffect(()=>{if(!u||!_)return;const z=performance.now(),E=setInterval(()=>p(Math.floor((performance.now()-z)*j/1e3)),1e3/15);return()=>clearInterval(E)},[u,_,j]);const N={cols:b,rows:v,seed:r,overlays:$,theme:a.themeObj(),scale:Os(a.style,a.project?.grid),tick:d,..._&&u?{}:{frame:s}},M=V0(t,N),A=Yk(t,{...N,tick:0});return k.jsxs("div",{className:"family-view","data-testid":"family-map",children:[k.jsxs("div",{className:"family-head",children:[k.jsx("span",{className:"dim",children:"map"}),k.jsx("select",{value:l,onChange:z=>i(z.target.value),"data-testid":"map-size",title:"The map's size in tiles (only for looking)",children:HM.map(z=>k.jsx("option",{children:z},z))}),k.jsx("span",{className:"dim",children:"seed"}),k.jsx("input",{className:"num",type:"number",min:1,value:r,"data-testid":"map-seed",onChange:z=>f(Math.max(1,Number(z.target.value)||1)),title:"The random island's seed (only for looking)"}),k.jsx("button",{className:"mini","data-testid":"map-reroll",onClick:()=>f(r+1),title:"Another random island (only for looking)",children:"⟳ another"}),_&&k.jsx("button",{className:"mini","data-testid":"map-play",onClick:()=>h(!u),title:"Play the map at the game's speed (only for looking)",children:u?"⏸":"▶"}),y.map(z=>k.jsxs("label",{className:"chk",title:`Play overlay ${z.name} (${z.doc.overlay.mode} on ${z.doc.overlay.on}) over the map`,children:[k.jsx("input",{type:"checkbox",checked:w.includes(z.name),"data-testid":`map-overlay-${z.name}`,onChange:()=>x(w.includes(z.name)?w.filter(E=>E!==z.name):[...w,z.name])})," ",z.name]},z.name))]}),k.jsx("div",{className:"dim map-text","data-testid":"map-text",children:A}),k.jsx("div",{className:"map-body",children:k.jsx(Wv,{img:M,testid:"map-canvas"})})]})}const BM=[{id:"brush",label:"✎ paint",tip:"Paint the terrain layer cell by cell (terrain <layer> brush …)"},{id:"rect",label:"▭ rect",tip:"Paint a rectangle of terrain; hold Shift to erase it (terrain <layer> rect …)"},{id:"erase",label:"⌫ erase",tip:"Erase the terrain layer cell by cell (terrain <layer> brush … erase)"},{id:"fill",label:"▦ fill",tip:"Lay the chosen one-cell tile on every empty cell of the tiles layer; drag to fill a box (tiles <layer> fill <asset>)"},{id:"place",label:"⊕ place",tip:"Place the chosen asset by its anchor cell (place <asset> x,y)"},{id:"move",label:"✣ move",tip:"Drag something placed to another cell (move x,y x,y)"},{id:"remove",label:"✕ remove",tip:"Take away what is placed on a cell (remove x,y)"},{id:"camera",label:"▣ camera",tip:"Click to stand the camera there: the game's screen around that cell (only for looking)"}];function YM({doc:t,store:a,ed:s,editable:l}){const[i,r]=he.useState("brush"),[f,u]=he.useState(1),[h,d]=he.useState(null),[p,y]=he.useState(null),[w,x]=he.useState(null),[b,v]=he.useState(null),[$,_]=he.useState(!1),[j,N]=he.useState(!1),[M,A]=he.useState(null),[z,E]=he.useState(null),R=he.useRef(null),B=a.assetDocs(),K=he.useMemo(()=>G0(B),[a.getVersion()]),J=he.useMemo(()=>Xh(t,K),[t,K]),T=t.map.tile,D=t.layers.filter(X=>X.map?.kind==="terrain").map(X=>X.name),L=t.layers.filter(X=>X.map?.kind==="objects"||X.map?.kind==="tiles").map(X=>X.name),Y=B.filter(X=>!X.doc.family&&!X.doc.overlay&&!X.doc.map&&X.doc.cellW===T),O=t.layers.filter(X=>X.map?.kind==="tiles").map(X=>X.name),H=Y.filter(X=>{const we=ga(X.doc);return we.cols===1&&we.rows===1&&X.doc.kind==="tile"}),G=h&&O.includes(h)?h:O[0]??null,Z=p&&H.some(X=>X.name===p)?p:H[0]?.name??null,W=w?H.filter(X=>(w[X.name]??0)>0).map(X=>`${X.name}:${w[X.name]}`).join(","):"",se=()=>{const X={};for(const we of H)X[we.name]=we.name===Z||Z&&we.doc.variantOf===Z?1:0;x(X)},ue=h&&D.includes(h)?h:D[0]??null,te=h&&L.includes(h)?h:L.find(X=>t.layers.find(we=>we.name===X).map.kind==="objects")??L[0]??null,U=p&&Y.some(X=>X.name===p)?p:Y.find(X=>X.doc.kind==="object")?.name??Y[0]?.name??null,V=t.layers.find(X=>X.name===ue)?.map,P=V?.kind==="terrain"&&!!V.walkable,ie=V?.kind==="terrain"?V.border??"same":"same",ye=V?.kind==="terrain"&&V.mix?V.mix.map(X=>`${X.name}:${X.weight}`).join(","):"",F=sN(a.style,a.project?.grid),pe=b&&$?nw(J,b[0],b[1],F[0],F[1]):null,fe=pe?{x:pe.x,y:pe.y,w:pe.w,h:pe.h}:{x:0,y:0,w:t.width,h:t.height},ge=pe?Math.max(f,Os(a.style,a.project?.grid)):f,Re=he.useMemo(()=>j?X0(t,K,{},J):[],[j,t,K,J]),rt=Re.filter(X=>!X.pass).flatMap(X=>X.groups.flatMap(we=>we.cells));he.useLayoutEffect(()=>{const X=R.current;if(!X)return;const we=Ck(J,{scale:ge,region:fe,marks:rt});X.width=we.width,X.height=we.height;const Te=X.getContext("2d");Te.putImageData(new ImageData(new Uint8ClampedArray(we.data),we.width,we.height),0,0);const Ve=(De,zt,Qt,Ht,Pn,En)=>{const ui=(De-fe.x)*T*ge,Gs=(zt-fe.y)*T*ge;En&&(Te.fillStyle=En,Te.fillRect(ui,Gs,Qt*T*ge,Ht*T*ge)),Te.strokeStyle=Pn,Te.lineWidth=2,Te.strokeRect(ui+1,Gs+1,Qt*T*ge-2,Ht*T*ge-2)};if(z&&(i==="brush"||i==="erase"))for(const[De,zt]of z.cells)Ve(De,zt,1,1,"transparent",i==="erase"?"rgba(255,80,80,0.35)":"rgba(80,220,255,0.35)");if(z&&(i==="rect"||i==="fill")){const De=mh(z.from,z.to);Ve(De.x,De.y,De.w,De.h,z.shift?"#ff5050":"#50dcff",z.shift?"rgba(255,80,80,0.2)":"rgba(80,220,255,0.2)")}if(z&&i==="move"){const De=Zr(t,t.layers.findIndex(zt=>zt.name===(te??"")),z.from[0],z.from[1]);if(De){const zt=t.map.entries[De.entry],Qt=el(zt,De.x+z.to[0]-z.from[0],De.y+z.to[1]-z.from[1]);Ve(Qt.x,Qt.y,Qt.w,Qt.h,"#ffd84a","rgba(255,216,74,0.25)")}}if(M&&!z)if(i==="place"&&U){const De=ga(B.find(zt=>zt.name===U).doc);Ve(M[0]-De.anchor[0],M[1]-De.anchor[1],De.cols,De.rows,"#ffd84a")}else Ve(M[0],M[1],1,1,"rgba(255,255,255,0.8)");if(b&&!$){const De=nw(J,b[0],b[1],F[0],F[1]);Ve(De.x,De.y,De.w,De.h,"#ff4fd8")}}),he.useEffect(()=>{!l&&i!=="camera"&&r("camera")},[l,i]);const Se=X=>{const we=R.current.getBoundingClientRect();return[fe.x+Math.floor((X.clientX-we.left)/(T*ge)),fe.y+Math.floor((X.clientY-we.top)/(T*ge))]},be=([X,we])=>X>=0&&we>=0&&X<t.width&&we<t.height,$e=X=>s.act(X,{context:!1}),Me=X=>{const we=Se(X);if(be(we)){if(i==="camera"){v(we);return}if(l){if(i==="place"){const Te=B.find(De=>De.name===U);if(!Te||!te)return;const Ve=ga(Te.doc);$e(`place ${Te.name} ${we[0]},${we[1]} layer=${te} cells=${Ve.cols}x${Ve.rows} anchor=${Ve.anchor[0]},${Ve.anchor[1]}`);return}if(i==="remove"){t.layers.findIndex(Ve=>Ve.map?.kind==="objects"||Ve.map?.kind==="tiles")>=0&&$e(`remove ${we[0]},${we[1]}`);return}E({from:we,to:we,cells:[we],shift:X.shiftKey})}}},Ge=X=>{const we=Se(X);if(A(be(we)?we:null),!z)return;const Te=z.cells[z.cells.length-1];we[0]===Te[0]&&we[1]===Te[1]||E({...z,to:we,cells:i==="brush"||i==="erase"?[...z.cells,we]:z.cells,shift:z.shift||X.shiftKey})},mt=()=>{if(!z)return;const X=z;if(E(null),(i==="brush"||i==="erase")&&ue){const we=X.cells.filter((Te,Ve)=>Ve===0||Te[0]!==X.cells[Ve-1][0]||Te[1]!==X.cells[Ve-1][1]);$e(`terrain ${ue} brush ${we.map(Te=>`${Te[0]},${Te[1]}`).join(" ")} size=1${i==="erase"?" erase":""}`)}else if(i==="rect"&&ue){const we=mh(X.from,X.to);$e(`terrain ${ue} rect ${we.x},${we.y} ${we.w}x${we.h}${X.shift?" erase":""}`)}else if(i==="fill"&&G&&(W||!w&&Z)){const we=mh(X.from,X.to);$e(`tiles ${G} fill ${w?`mix=${W} variants=named`:Z}${we.w>1||we.h>1?` ${we.x},${we.y} ${we.w}x${we.h}`:""}`)}else if(i==="move"){const we=t.layers.findIndex(Ve=>Ve.name===te),Te=Zr(t,we,X.from[0],X.from[1])??t.layers.map((Ve,De)=>Zr(t,De,X.from[0],X.from[1])).find(Boolean)??null;if(!Te||X.to[0]===X.from[0]&&X.to[1]===X.from[1])return;$e(`move ${Te.x},${Te.y} ${Te.x+X.to[0]-X.from[0]},${Te.y+X.to[1]-X.from[1]} layer=${t.layers[Te.layer].name}`)}},ct=M?GM(t,J,M):"";return k.jsxs("div",{className:"map-editor","data-testid":"map-editor",children:[k.jsxs("div",{className:"family-head map-tools",children:[k.jsx("span",{className:"seg","data-testid":"map-tools",children:BM.map(X=>k.jsx("button",{className:i===X.id?"on":"","data-tool":X.id,title:X.tip,disabled:!l&&X.id!=="camera",onClick:()=>r(X.id),children:X.label},X.id))}),(i==="brush"||i==="rect"||i==="erase")&&k.jsx("select",{value:ue??"",onChange:X=>d(X.target.value),"data-testid":"map-terrain",title:"The terrain layer you paint (its family's scheme picks the edge tiles)",children:D.map(X=>k.jsx("option",{children:X},X))}),(i==="brush"||i==="rect"||i==="erase")&&ue&&k.jsxs("label",{className:"chk",title:"Objects may stand on this terrain layer's filled ground and edges (layer set <layer> walkable=on|off): ground, not sea",children:[k.jsx("input",{type:"checkbox",checked:P,disabled:!l,"data-testid":"map-walkable",onChange:X=>$e(`layer set ${ue} walkable=${X.target.checked?"on":"off"}`)})," walkable"]}),(i==="brush"||i==="rect"||i==="erase")&&ue&&k.jsxs("label",{className:"chk",title:"Past the map's edge: the edge cell's own terrain (same: no band along the border), terrain, or not terrain (layer set <layer> border=same|terrain|not)",children:["border ",k.jsxs("select",{value:ie,disabled:!l,"data-testid":"map-border",onChange:X=>$e(`layer set ${ue} border=${X.target.value}`),children:[k.jsx("option",{value:"same",children:"same"}),k.jsx("option",{value:"terrain",children:"terrain"}),k.jsx("option",{value:"not",children:"not"})]})]}),(i==="brush"||i==="rect"||i==="erase")&&ue&&k.jsxs("label",{className:"chk",title:"The terrain's inside cells as a seeded scatter of one-cell tiles by weight, e.g. meadow:2,clover:1 (each tile's weight shared with its texture variants); empty: the family's own inside (layer set <layer> mix=…|none). Enter to apply",children:["inside ",k.jsx("input",{defaultValue:ye,placeholder:"family's own",disabled:!l,"data-testid":"map-inside-mix",size:30,onKeyDown:X=>{if(X.key==="Enter"){const we=X.currentTarget.value.trim();$e(`layer set ${ue} mix=${we||"none"}`)}}},`${ue}:${ye}`)]}),i==="fill"&&k.jsxs(k.Fragment,{children:[k.jsx("select",{value:G??"",onChange:X=>d(X.target.value),"data-testid":"map-fill-layer",title:"The tiles layer you fill",children:O.map(X=>k.jsx("option",{children:X},X))}),k.jsxs("select",{value:w?"(mix)":Z??"",onChange:X=>{X.target.value==="(mix)"?se():(x(null),y(X.target.value))},"data-testid":"map-fill-tile",title:"The one-cell tile laid on every empty cell (the map picks among its texture variants), or a mix of tiles by weight",children:[H.map(X=>k.jsx("option",{value:X.name,children:X.name},X.name)),k.jsx("option",{value:"(mix)",children:"mix…"})]}),w&&k.jsx("span",{className:"mix","data-testid":"map-fill-mix",title:"A seeded scatter of these tiles by weight, no two equal neighbours where it can help it (tiles <layer> fill mix=<tile>:<weight>,...); 0 leaves a tile out",children:H.map(X=>k.jsxs("label",{className:(w[X.name]??0)>0?"on":"",children:[X.name,k.jsx("input",{type:"number",min:0,max:99,value:w[X.name]??0,"data-testid":`map-mix-${X.name}`,onChange:we=>x({...w,[X.name]:Math.max(0,Math.min(99,Math.floor(Number(we.target.value)||0)))})})]},X.name))})]}),(i==="place"||i==="move")&&k.jsx("select",{value:te??"",onChange:X=>d(X.target.value),"data-testid":"map-layer",title:"The tiles or objects layer you place on",children:L.map(X=>k.jsx("option",{children:X},X))}),i==="place"&&k.jsx("select",{value:U??"",onChange:X=>y(X.target.value),"data-testid":"map-asset",title:"What you place (objects and tiles of the map's cell size)",children:Y.map(X=>k.jsxs("option",{value:X.name,children:[X.name," ",X.doc.width,"×",X.doc.height]},X.name))}),k.jsx("span",{className:"spacer"}),k.jsx("span",{className:"seg",title:"The map at 1x or at the game's scale (only for looking)",children:[1,2].map(X=>k.jsxs("button",{className:f===X?"on":"","data-testid":`map-zoom-${X}`,onClick:()=>u(X),children:[X,"×"]},X))}),k.jsxs("label",{className:"chk",title:"Show only the camera's screen, at the game's scale (only for looking)",children:[k.jsx("input",{type:"checkbox",checked:$,disabled:!b,"data-testid":"map-camera-view",onChange:X=>_(X.target.checked)})," camera view"]}),k.jsxs("label",{className:"chk",title:"Outline the cells the map checks flag (only for looking)",children:[k.jsx("input",{type:"checkbox",checked:j,"data-testid":"map-marks",onChange:X=>N(X.target.checked)})," hot spots"]})]}),k.jsxs("div",{className:"dim map-text","data-testid":"map-status",children:[t.width,"×",t.height," cells of ",T," px",b?` · camera at ${b[0]},${b[1]} (${F[0]}×${F[1]} px)`:"",ct?` · ${ct}`:"",j&&` · ${Re.filter(X=>!X.pass).map(X=>`${X.id} ✗`).join(" ")||"map checks pass"}`]}),k.jsx("div",{className:"map-body",children:k.jsx("canvas",{ref:R,"data-testid":"map-edit-canvas",style:{cursor:i==="move"?"move":"crosshair"},onMouseDown:Me,onMouseMove:Ge,onMouseUp:mt,onMouseLeave:()=>{A(null),mt()}})})]})}function mh(t,a){const s=Math.min(t[0],a[0]),l=Math.min(t[1],a[1]);return{x:s,y:l,w:Math.abs(t[0]-a[0])+1,h:Math.abs(t[1]-a[1])+1}}function GM(t,a,[s,l]){const i=a.top[l*t.width+s],r=t.layers.flatMap((f,u)=>{if(f.map?.kind!=="objects"&&f.map?.kind!=="tiles")return[];const h=Zr(t,u,s,l);if(!h||h.layer!==u)return[];const d=t.map.entries[h.entry];return[`${d.name}${d.variant?`.${d.variant}`:""} (anchor ${h.x},${h.y})`]});return t.cels.map(f=>f[0][l*t.width+s]),`${s},${l}: ${i?`${i.asset}${i.variant?`.${i.variant}`:""}${i.walkable?" (walkable)":""}`:"nothing"}${r.length?` · ${[...new Set(r)].join(", ")}`:""}`}const zh=/\.(png|aseprite|ase)$/i;async function XM(t){const a=[],s=[...t.items].map(i=>i.webkitGetAsEntry?.()).filter(i=>!!i);if(!s.length)return[...t.files].filter(i=>zh.test(i.name));const l=async i=>{if(i.isFile){const r=await new Promise((f,u)=>i.file(f,u));zh.test(r.name)&&a.push(r)}else if(i.isDirectory){const r=i.createReader(),f=[];for(;;){const u=await new Promise((h,d)=>r.readEntries(h,d));if(!u.length)break;f.push(...u)}for(const u of f.sort((h,d)=>h.name.localeCompare(d.name)))await l(u)}};for(const i of s)await l(i);return a}function Iv({store:t,plan:a,children:s}){const[l,i]=he.useState(null),[r,f]=he.useState(!1);return k.jsxs("div",{className:`drop-zone${r?" over":""}`,"data-testid":"drop-zone",onDragOver:u=>{u.dataTransfer.types.includes("Files")&&(u.preventDefault(),f(!0))},onDragLeave:u=>{u.currentTarget===u.target&&f(!1)},onDrop:u=>{u.preventDefault(),f(!1),XM(u.dataTransfer).then(h=>{h.length&&i(h)})},children:[s,r&&k.jsx("div",{className:"drop-hint",children:"Drop a sheet, a folder of PNGs or an .aseprite file to import it"}),l&&k.jsx(Pv,{files:l,store:t,plan:a,onClose:()=>i(null)})]})}function Fv({store:t,plan:a}){const s=he.useRef(null),[l,i]=he.useState(null);return k.jsxs(k.Fragment,{children:[k.jsx("button",{onClick:()=>s.current?.click(),"data-testid":"import-open",title:"Import a PNG sheet, PNGs or an .aseprite file into the gallery (or drop them on the page)",children:"Import…"}),k.jsx("input",{ref:s,type:"file",accept:".png,.aseprite,.ase",multiple:!0,hidden:!0,"data-testid":"import-input",onChange:r=>{const f=[...r.target.files??[]].filter(u=>zh.test(u.name));r.target.value="",f.length&&i(f)}}),l&&k.jsx(Pv,{files:l,store:t,plan:a,onClose:()=>i(null)})]})}const In=(t,a=0)=>/^\d+$/.test(t.trim())?Number(t):a;function Pv({files:t,store:a,plan:s,onClose:l}){const i=t.length===1&&/\.png$/i.test(t[0].name)?t[0]:null,r=24,[f,u]=he.useState(null),[h,d]=he.useState({w:String(r),h:String(r)}),[p,y]=he.useState({x:"0",y:"0"}),[w,x]=he.useState({x:"0",y:"0"}),[b,v]=he.useState(!0),[$,_]=he.useState("pattern"),[j,N]=he.useState(Kv),[M,A]=he.useState("tile"),z=s.sets.filter(F=>F.name!=="unplanned").map(F=>F.name),[E,R]=he.useState(z[0]??""),[B,K]=he.useState(a.defaultPalette??[...a.palettes.keys()][0]??""),[J,T]=he.useState(!1),[D,L]=he.useState(!1),[Y,O]=he.useState(!1),[H,G]=he.useState(null);he.useEffect(()=>{if(!i)return;const F=URL.createObjectURL(i),pe=new Image;return pe.onload=()=>{const fe=document.createElement("canvas");fe.width=pe.naturalWidth,fe.height=pe.naturalHeight;const ge=fe.getContext("2d");ge.drawImage(pe,0,0);const Re=ge.getImageData(0,0,fe.width,fe.height).data,rt=new Uint8ClampedArray(fe.width*fe.height);for(let Se=0;Se<rt.length;Se++)rt[Se]=Re[Se*4+3];u({url:F,w:fe.width,h:fe.height,alpha:rt}),fe.width<=r&&fe.height<=r&&v(!1)},pe.src=F,()=>URL.revokeObjectURL(F)},[i]);const Z=In(h.w,1),W=In(h.h,1),se=he.useMemo(()=>f&&b?fM(f.w,f.h,{cell:[Z,W],offset:[In(p.x),In(p.y)],gap:[In(w.x),In(w.y)]}):[],[f,b,Z,W,p,w]),ue=he.useMemo(()=>f?se.map(F=>{for(let pe=F.y;pe<F.y+W;pe++)for(let fe=F.x;fe<F.x+Z;fe++)if(f.alpha[pe*f.w+fe]>=128)return!0;return!1}):[],[se,f]),te=se.filter((F,pe)=>ue[pe]),U=Mh((t[0]?.name??"imported").replace(/\.[^.]+$/,"")),V=s.assets.filter(F=>F.planned&&!F.exists&&(!E||F.set===E)).map(F=>F.name),P=i&&b?$==="manifest"?Iw(te,{base:U,names:V}):Iw(te,{base:U,pattern:j}):t.map(F=>Mh(F.name.replace(/\.[^.]+$/,""))),ie=async()=>{O(!0);const F={kind:M,...E?{set:E}:{},...J?{build:!0}:{palette:B},...M==="tile"&&D?{wrap:!0}:{},...i&&b?{slice:{cell:[Z,W],offset:[In(p.x),In(p.y)],gap:[In(w.x),In(w.y)]},...$==="manifest"?{names:P}:{pattern:j}}:{}},pe=await a.importFiles(t,F);O(!1),G(pe)},ye=f?Math.max(1,Math.min(6,Math.floor(420/Math.max(f.w,f.h)))):1;return k.jsx("div",{className:"dialog-back",onClick:l,children:k.jsxs("div",{className:"dialog import","data-testid":"import-dialog",onClick:F=>F.stopPropagation(),children:[k.jsxs("div",{className:"panel-title",children:["Import ",t.length===1?t[0].name:`${t.length} files`]}),H?k.jsxs("div",{className:"import-result","data-testid":"import-result",children:[H.error?k.jsx("div",{className:"banner error",children:H.error}):k.jsxs(k.Fragment,{children:[k.jsxs("p",{children:[H.created?.length??0," asset",H.created?.length===1?"":"s"," made",H.added?.length?`; ${H.added.length} added to the plan`:"",". Each has had every check run:"]}),k.jsx("ul",{className:"import-list",children:H.created?.map(F=>k.jsxs("li",{"data-testid":`imported-${F.name}`,children:[k.jsx("b",{className:"mono",children:F.name})," ",k.jsxs("span",{className:"dim",children:[F.kind," ",F.size]})," ",F.failing.length?F.failing.map(pe=>k.jsx("span",{className:"chk fail",children:pe},pe)):k.jsxs("span",{className:"chk pass",children:[F.checks," checks ✓"]}),F.inexact>0&&k.jsxs("span",{className:"dim",children:[" · ",F.inexact," px to the nearest colour"]})]},F.name))}),H.notes?.map(F=>k.jsx("div",{className:"dim",children:F},F))]}),k.jsxs("div",{className:"card-actions",children:[k.jsx("button",{onClick:l,"data-testid":"import-close",children:"Close"}),!H.error&&k.jsx("button",{onClick:()=>{l(),a.setTab("gallery")},children:"Show in the gallery"})]})]}):k.jsxs("div",{className:"import-body",children:[i&&f&&k.jsxs("div",{className:"slice-view",style:{width:f.w*ye,height:f.h*ye},children:[k.jsx("img",{src:f.url,alt:"",style:{width:f.w*ye,height:f.h*ye}}),se.map((F,pe)=>k.jsx("div",{className:`slice-cell${ue[pe]?"":" empty"}`,style:{left:F.x*ye,top:F.y*ye,width:Z*ye,height:W*ye},title:ue[pe]?Array.isArray(P)?P[te.indexOf(F)]:"":"empty: skipped",children:ue[pe]&&Array.isArray(P)&&ye*Z>=40&&k.jsx("span",{children:P[te.indexOf(F)]})},pe))]}),k.jsxs("div",{className:"import-form",children:[i&&k.jsxs(k.Fragment,{children:[k.jsxs("label",{className:"row",children:[k.jsx("input",{type:"checkbox",checked:b,onChange:F=>v(F.target.checked),"data-testid":"slice-on"})," slice into one asset per cell"]}),b&&k.jsxs(k.Fragment,{children:[k.jsxs("label",{children:["cell ",k.jsx("input",{value:h.w,onChange:F=>d({...h,w:F.target.value}),size:3,"data-testid":"cell-w"})," x ",k.jsx("input",{value:h.h,onChange:F=>d({...h,h:F.target.value}),size:3,"data-testid":"cell-h"})]}),k.jsxs("label",{children:["offset ",k.jsx("input",{value:p.x,onChange:F=>y({...p,x:F.target.value}),size:3})," , ",k.jsx("input",{value:p.y,onChange:F=>y({...p,y:F.target.value}),size:3})]}),k.jsxs("label",{children:["gap ",k.jsx("input",{value:w.x,onChange:F=>x({...w,x:F.target.value}),size:3})," , ",k.jsx("input",{value:w.y,onChange:F=>x({...w,y:F.target.value}),size:3})]}),k.jsxs("div",{className:"row",children:["names",k.jsxs("label",{children:[k.jsx("input",{type:"radio",checked:$==="pattern",onChange:()=>_("pattern")})," pattern"]}),k.jsx("input",{value:j,onChange:F=>N(F.target.value),disabled:$!=="pattern","data-testid":"pattern"}),k.jsxs("label",{title:"The planned, undrawn entries of the set, in order",children:[k.jsx("input",{type:"radio",checked:$==="manifest",onChange:()=>_("manifest"),"data-testid":"names-manifest"})," the plan's entries"]})]})]})]}),k.jsxs("label",{children:["kind ",k.jsx("select",{value:M,onChange:F=>A(F.target.value),"data-testid":"import-kind",children:["tile","sprite","object","icon","sheet"].map(F=>k.jsx("option",{children:F},F))})]}),M==="tile"&&k.jsxs("label",{className:"row",children:[k.jsx("input",{type:"checkbox",checked:D,onChange:F=>L(F.target.checked)})," seamless (wrap)"]}),k.jsxs("label",{children:["set ",k.jsxs("select",{value:E,onChange:F=>R(F.target.value),"data-testid":"import-set",children:[k.jsx("option",{value:"",children:"(its kind)"}),z.map(F=>k.jsx("option",{children:F},F))]})]}),k.jsxs("div",{className:"row",children:["colours",k.jsxs("label",{children:[k.jsx("input",{type:"radio",checked:!J,onChange:()=>T(!1)})," quantise to"]}),k.jsx("select",{value:B,onChange:F=>K(F.target.value),disabled:J,children:[...a.palettes.keys()].map(F=>k.jsx("option",{children:F},F))}),k.jsxs("label",{children:[k.jsx("input",{type:"radio",checked:J,onChange:()=>T(!0),"data-testid":"adopt"})," adopt the image's"]})]}),k.jsx("div",{className:"import-names","data-testid":"import-names",children:typeof P=="string"?k.jsx("span",{className:"flag",children:P}):k.jsxs(k.Fragment,{children:[P.length," asset",P.length===1?"":"s",": ",k.jsx("span",{className:"mono",children:P.join(", ")}),i&&b&&se.length>te.length&&k.jsxs("span",{className:"dim",children:[" (",se.length-te.length," empty cells skipped)"]})]})}),k.jsxs("div",{className:"card-actions",children:[k.jsx("button",{className:"ask-claude",disabled:Y||typeof P=="string"||!P.length,onClick:()=>{ie()},"data-testid":"import-go",children:Y?"Importing…":"Import"}),k.jsx("button",{onClick:l,children:"Cancel"})]})]})]})]})})}function e1(t){return t.startsWith("~/")?`~/${e1(t.slice(2))}`:/^[A-Za-z0-9_./:@%+=,-]+$/.test(t)?t:`'${t.replace(/'/g,"'\\''")}'`}function ZM(t,a){if(!a||a==="/")return t;const s=a.replace(/\/+$/,"");return t===s?"~":t.startsWith(`${s}/`)?`~${t.slice(s.length)}`:t}function QM(t){const a=e1(t),s=`pixelclaw await ${a}`,l=`pixelclaw work ${a}`;return`People ask for changes in the PixelClaw dashboard for the project at ${t}. Run \`${s}\` in the background (it waits, prints what was asked and a cursor, then exits). Each time it exits, read what it printed and take each request. If you have PixelClaw's MCP tools, use the work tool: claim it, draw or change the art, post progress, finish it with done, or ask one question with blocked. Otherwise use the CLI: \`${l} claim\` (prints what is asked), draw with \`pixelclaw run ${a} -e "<commands>"\` and look with \`pixelclaw view\` and \`pixelclaw check\`, post \`${l} progress "<note>"\`, finish with \`${l} done "<what changed>"\` (refused while a check fails: fix it and finish again), or ask with \`${l} block "<one clear question>"\`. Then start \`${s} --since <the cursor it printed>\` in the background again. Keep doing this until I say stop.`}const VM=120*1e3;function t1(t=5e3){const[a,s]=he.useState(()=>Date.now());return he.useEffect(()=>{const l=setInterval(()=>s(Date.now()),t);return()=>clearInterval(l)},[t]),a}function KM(t){const a=t.events.filter(s=>s.type==="reply").at(-1);return Date.parse(a?.at??t.at)}function n1(t,a,s){if(a.state!=="open"||(a.seen??[]).length)return!1;const l=t.presence;return l?!l.listening||s-KM(a)>VM:!1}async function JM(t){try{return await navigator.clipboard.writeText(t),!0}catch{return!1}}function WM({store:t,why:a}){const[s,l]=he.useState(null),[i,r]=he.useState(!1),f=t.project?.dir?ZM(t.project.dir,t.project.home):"<project folder>",u=QM(f),h=t.worker;return k.jsxs("div",{className:"no-listener","data-testid":"no-listener",role:"status",children:[k.jsx("div",{children:k.jsxs("b",{children:["⚠ ",a]})}),k.jsxs("div",{className:"card-actions",children:[k.jsx("button",{onClick:()=>{JM(u).then(l)},"data-testid":"copy-prompt",title:"Copy a prompt to paste into a Claude Code session",children:"Copy prompt for Claude"}),h?.enabled&&!h.running&&k.jsx("button",{className:"ask-claude",disabled:i,"data-testid":"start-worker",onClick:()=>{r(!0),t.workerAction("start").then(d=>{r(!1),t.error=d.ok?null:d.error??"refused",t.changed()})},title:"Run Claude Code headless on the open requests, up to the project's budget cap",children:"Start the worker"})]}),s!==null&&k.jsxs("div",{className:"dim","data-testid":"prompt-copied",children:[s?"Copied. Paste it into a Claude Code session in this project.":"Could not copy; select the prompt below.",k.jsx("pre",{className:"prompt-text","data-testid":"prompt-text",children:u})]})]})}function IM({store:t}){const a=t.presence;if(!a)return null;const s=a.worker?"the worker":a.waiters.length?a.waiters[0].by:a.agents[0]?.by??"";return k.jsx("span",{className:`chip listener-chip ${a.listening?"on":"off"}`,"data-testid":"listener-chip","data-listening":a.listening,title:a.listening?"An agent is waiting for requests, took a request recently, or the worker is running":"Requests you file now wait until an agent is started on this project",children:a.listening?`● ${s} is listening`:"○ no agent is listening"})}const lc={planned:"not drawn yet",drafted:"drawn; checks failing",checked:"every check passes",reviewed:"blind review done",approved:"approved by a person",exported:"exported to the game"};function a1(t){const[a,s]=he.useState(null),[l,i]=he.useState(null),r=t.planVersion;return he.useEffect(()=>{let f=!0;const u=setTimeout(()=>{fetch(`/api/plan?token=${encodeURIComponent(t.token)}`).then(h=>h.json()).then(h=>{f&&(h.error?i(h.error):(s(h),i(null),t.requests=h.requests,t.changed()))}).catch(h=>{f&&i(String(h))})},a?300:0);return()=>{f=!1,clearTimeout(u)}},[r,t.token]),{plan:a,error:l}}function FM({src:t,box:a}){const[s,l]=he.useState(null),i=s?Math.max(1,Math.floor(a/Math.max(s.w,s.h))):1,r=s&&Math.max(s.w,s.h)>a?a/Math.max(s.w,s.h):i;return k.jsx("img",{src:t,alt:"",draggable:!1,onLoad:f=>l({w:f.currentTarget.naturalWidth,h:f.currentTarget.naturalHeight}),style:s?{width:Math.round(s.w*r),height:Math.round(s.h*r)}:{visibility:"hidden"}})}const ud=["open","claimed","blocked"],PM={draw:"Claude to draw it",change:"for changes",new:"for this new asset"};function u0({q:t,store:a}){const s=t1(),[l,i]=he.useState(""),[r,f]=he.useState(!1),u=a.lastWrite(t.asset),h=t.events.filter(v=>v.type==="claim").at(-1)?.at??"",d=t.state==="claimed"&&!!u&&u.by===t.claimedBy&&u.at>=h,p=v=>(v??"").replace(/^human:/,"")||"someone",y=async v=>{f(!0);const $=await a.request(v);return f(!1),$.ok?a.error=null:a.error=$.error??"refused",a.changed(),$.ok},w=t.seen??[],x=n1(a,t,s),b=t.state==="open"?w.length?"seen":"sent":t.state==="claimed"?"working":t.state;return k.jsxs("div",{className:`req req-${t.state}${d?" working":""}${x?" unattended":""}`,"data-testid":`request-${t.id}`,"data-state":t.state,"data-stage":b,title:`${t.id}: ${t.kind} asked by ${t.by} at ${t.at}`,children:[k.jsxs("div",{className:"req-head",children:[k.jsx("span",{className:"req-id mono",children:t.id}),t.state==="open"&&k.jsxs("span",{children:[k.jsx("b",{"data-testid":"stage",children:w.length?`seen by ${w.map(v=>v.by).join(", ")}`:"sent"})," · ",p(t.by)," asked ",PM[t.kind],t.note?k.jsxs(k.Fragment,{children:[": ",k.jsxs("i",{children:["“",t.note,"”"]})]}):"",t.events.some(v=>v.type==="reply")?" (answered; waiting for an agent)":""]}),t.state==="claimed"&&(d?k.jsxs("span",{className:"claude-working","data-testid":"working",children:[k.jsx("span",{className:"pulse"}),"Claude is working on this",t.latest?k.jsxs(k.Fragment,{children:[": ",k.jsx("i",{children:t.latest})]}):""]}):k.jsxs("span",{children:["claimed by ",t.claimedBy,t.latest?k.jsxs(k.Fragment,{children:[": ",k.jsx("i",{children:t.latest})]}):""]})),t.state==="blocked"&&k.jsxs("span",{children:["Claude asks: ",k.jsxs("b",{children:["“",t.question,"”"]})]}),t.state==="done"&&k.jsxs("span",{children:["✓ done: ",t.latest]}),t.state==="cancelled"&&k.jsx("span",{className:"dim",children:"withdrawn"})]}),x&&k.jsx(WM,{store:a,why:a.presence?.listening?"Nobody has picked this up for a couple of minutes. It is only a note in the project until an agent takes it.":"No agent is listening. Nobody has this request yet; it waits in the project until an agent is started."}),t.state==="blocked"&&k.jsxs("form",{className:"card-actions ask",onSubmit:v=>{v.preventDefault(),l.trim()&&y({action:"reply",id:t.id,text:l.trim()}).then($=>{$&&i("")})},children:[k.jsx("input",{value:l,onChange:v=>i(v.target.value),placeholder:"your answer","aria-label":"your answer","data-testid":"reply-text"}),k.jsx("button",{type:"submit",disabled:!l.trim()||r,"data-testid":"reply-send",children:"Answer"})]}),ud.includes(t.state)&&k.jsx("button",{className:"link",disabled:r,onClick:()=>{y({action:"cancel",id:t.id})},"data-testid":"cancel",title:"Withdraw this request",children:"withdraw"})]})}function e3({a:t,store:a,requests:s}){const[l,i]=he.useState(null),[r,f]=he.useState(""),[u,h]=he.useState(!1),d=s.filter(j=>j.asset===t.name),p=d.filter(j=>ud.includes(j.state)),y=d.filter(j=>j.state==="done").at(-1),w=t.exists&&t.status==="reviewed",x=!t.exists&&t.planned&&!p.some(j=>j.kind==="draw"||j.kind==="new"),b=t.exists&&!p.some(j=>j.kind==="change"),v=async j=>{h(!0);const N=await a.send(t.name,j);return h(!1),N.ok},$=async()=>{h(!0);const j=l==="draw"?await a.request({action:"request",kind:"draw",asset:t.name,note:r.trim()}):await a.request({action:"request",kind:"change",asset:t.name,note:r.trim()});h(!1),a.error=j.ok?null:j.error??"refused",a.changed(),j.ok&&(i(null),f(""))},_=()=>{t.exists&&(a.select(t.name),a.setTab("editor"))};return k.jsxs("div",{className:`dash-card st-${t.status}${t.planned?"":" unplanned"}${p.length?" has-request":""}`,"data-testid":`card-${t.name}`,"data-status":t.status,children:[k.jsx("button",{className:"thumb",onClick:_,disabled:!t.exists,title:t.exists?`Open ${t.name} in the editor`:"Not drawn yet",children:t.exists?k.jsx(FM,{src:`/api/preview/${t.name}.png?token=${encodeURIComponent(a.token)}&v=${t.seq??0}`,box:96}):k.jsx("span",{className:"planned-box",children:t.size})}),k.jsxs("div",{className:"card-body",children:[k.jsxs("div",{className:"card-head",children:[k.jsx("b",{className:"mono",children:t.name}),k.jsx("span",{className:`badge st-${t.status}`,title:lc[t.status],"data-testid":"status",children:t.status})]}),k.jsxs("div",{className:"dim",children:[t.kind," ",t.size,t.notes?` · ${t.notes} note${t.notes===1?"":"s"}`:""]}),t.description&&k.jsx("div",{className:"desc",children:t.description}),t.exists&&k.jsx("div",{className:"card-checks",title:t.checks.map(j=>`${j.id} ${j.shown} ${j.status==="pass"?"✓":"✗"}`).join(`
|
|
47
|
+
`),children:t.failing.length?t.failing.map(j=>k.jsx("span",{className:"chk fail",children:j},j)):k.jsxs("span",{className:"chk pass",children:[t.checks.length," checks ✓"]})}),t.status!=="exported"&&k.jsxs("div",{className:"next",children:["→ ",t.next]}),t.status==="exported"&&t.exported&&k.jsxs("div",{className:"next dim",children:[t.exported.profile," → ",t.exported.dir]}),t.flags.map(j=>k.jsx("div",{className:"flag",children:j},j)),p.map(j=>k.jsx(u0,{q:j,store:a},j.id)),!p.length&&y&&k.jsx(u0,{q:y,store:a}),!l&&(w||x||b)&&k.jsxs("div",{className:"card-actions",children:[w&&k.jsx("button",{className:"approve",disabled:u,onClick:()=>{v("mark approved")},"data-testid":"approve",title:"Approve this asset (mark approved, on its tape with your name)",children:"✓ Approve"}),x&&k.jsx("button",{className:"ask-claude",disabled:u,onClick:()=>i("draw"),"data-testid":"draw",title:"Ask Claude to draw this planned asset (a request it takes with its work tool)",children:"Draw this…"}),b&&k.jsx("button",{disabled:u,onClick:()=>i("change"),"data-testid":"reject",title:"Ask Claude for changes (a request, and mark rejected on the tape with your reason)",children:"Ask for changes…"})]}),l&&k.jsxs("form",{className:"card-actions ask",onSubmit:j=>{j.preventDefault(),(l==="draw"||r.trim())&&$()},children:[k.jsx("input",{autoFocus:!0,value:r,onChange:j=>f(j.target.value),placeholder:l==="draw"?"anything Claude should know? (optional)":"what should change?","aria-label":l==="draw"?"a note for Claude":"what should change",onKeyDown:j=>{j.key==="Escape"&&i(null)},"data-testid":"reject-text"}),k.jsx("button",{type:"submit",disabled:l==="change"&&!r.trim()||u,"data-testid":"reject-send",children:l==="draw"?"Ask Claude":"Send"}),k.jsx("button",{type:"button",onClick:()=>i(null),children:"Cancel"})]})]})]})}function t3({plan:t,store:a,onClose:s}){const[l,i]=he.useState({name:"",kind:"sprite",size:"24x24",set:t.sets.find(y=>y.name!=="unplanned")?.name??"",description:"",height:"",note:""}),[r,f]=he.useState(!1),[u,h]=he.useState(null),d=y=>w=>i({...l,[y]:w.target.value}),p=async()=>{f(!0);const y={name:l.name.trim(),kind:l.kind,size:l.size.trim(),...l.set?{set:l.set}:{},...l.description.trim()?{description:l.description.trim()}:{},...l.height?{height:Number(l.height)}:{}},w=await a.request({action:"request",kind:"new",entry:y,note:l.note.trim()});f(!1),w.ok?s():h(w.error??"refused")};return k.jsx("div",{className:"dialog-back",onClick:s,children:k.jsxs("form",{className:"dialog add-asset","data-testid":"add-asset",onClick:y=>y.stopPropagation(),onSubmit:y=>{y.preventDefault(),p()},children:[k.jsx("div",{className:"panel-title",children:"Add an asset"}),k.jsx("p",{className:"dim",children:"A new entry in the plan (manifest.json), and a request for Claude to draw it."}),k.jsxs("label",{children:["name ",k.jsx("input",{value:l.name,onChange:d("name"),placeholder:"lantern","data-testid":"add-name",autoFocus:!0})]}),k.jsxs("label",{children:["kind ",k.jsx("select",{value:l.kind,onChange:d("kind"),"data-testid":"add-kind",children:Xr.map(y=>k.jsx("option",{children:y},y))})]}),k.jsxs("label",{children:["size ",k.jsx("input",{value:l.size,onChange:d("size"),placeholder:"24x24","data-testid":"add-size"})]}),k.jsxs("label",{children:["set ",k.jsxs("select",{value:l.set,onChange:d("set"),"data-testid":"add-set",children:[k.jsx("option",{value:"",children:"(its kind)"}),t.sets.filter(y=>y.name!=="unplanned").map(y=>k.jsx("option",{children:y.name},y.name))]})]}),k.jsxs("label",{children:["height ",k.jsx("input",{value:l.height,onChange:d("height"),placeholder:"drawn height in px (props, figures)"})]}),k.jsxs("label",{className:"wide",children:["what it is ",k.jsx("input",{value:l.description,onChange:d("description"),placeholder:"what it should read as","data-testid":"add-description"})]}),k.jsxs("label",{className:"wide",children:["note for Claude ",k.jsx("input",{value:l.note,onChange:d("note"),placeholder:"optional","data-testid":"add-note"})]}),u&&k.jsx("div",{className:"banner error","data-testid":"add-error",children:u}),k.jsxs("div",{className:"card-actions",children:[k.jsx("button",{type:"submit",className:"ask-claude",disabled:r||!l.name.trim(),"data-testid":"add-send",children:"Add and ask Claude"}),k.jsx("button",{type:"button",onClick:s,children:"Cancel"})]})]})})}function n3({store:t}){const a=t.worker,[s,l]=he.useState(!1),[i,r]=he.useState(!1),f=he.useRef(null);if(he.useEffect(()=>{s&&t.loadWorker()},[s]),he.useEffect(()=>{f.current?.scrollTo(0,f.current.scrollHeight)},[t.workerLog.length,s]),!a?.enabled)return null;const u=async h=>{r(!0);const d=await t.workerAction(h);r(!1),t.error=d.ok?null:d.error??"refused",d.ok&&h==="start"&&l(!0),t.changed()};return k.jsxs("div",{className:"worker","data-testid":"worker",children:[a.running?k.jsx("button",{onClick:()=>{u("stop")},disabled:i,"data-testid":"worker-stop",children:"■ Stop Claude"}):k.jsx("button",{className:"ask-claude",onClick:()=>{u("start")},disabled:i,"data-testid":"worker-start",title:"Run Claude Code headless on the open requests, with only the PixelClaw tools, up to the project's budget cap (project.json worker; docs/worker.md)",children:"▶ Start Claude"}),k.jsx("span",{className:"dim","data-testid":"worker-status",children:a.running?`working · $${a.spent.toFixed(2)} of $${a.cap.toFixed(2)} spent · session ${a.sessions}`:`${a.stopped?`stopped: ${a.stopped} · `:""}$${(a.spent||0).toFixed(2)} of $${(a.cap||0).toFixed(2)} cap spent`}),k.jsx("button",{className:s?"on":"",onClick:()=>l(!s),"data-testid":"worker-log-toggle",children:"Log"}),s&&k.jsx("pre",{className:"worker-log",ref:f,"data-testid":"worker-log",children:t.workerLog.join(`
|
|
48
|
+
`)||"nothing yet"})]})}function a3({store:t}){const{plan:a,error:s}=a1(t),[l,i]=he.useState("all"),[r,f]=he.useState(null),[u,h]=he.useState(!1),d=t.requests,p=t1(),y=he.useMemo(()=>d.filter(b=>ud.includes(b.state)),[d]);if(!a)return k.jsx("div",{className:"dashboard","data-testid":"dashboard",children:k.jsx("div",{className:"dim pad",children:s??"Loading the plan…"})});const w=a.assets.filter(b=>b.planned),x=b=>(l==="all"||b.set===l)&&(!r||b.status===r);return k.jsx(Iv,{store:t,plan:a,children:k.jsxs("div",{className:"dashboard","data-testid":"dashboard",children:[k.jsxs("div",{className:"dash-top",children:[k.jsxs("div",{className:"dash-row",children:[k.jsxs("div",{className:"dash-theme",children:[k.jsx("b",{children:a.project}),a.theme?k.jsxs("span",{className:"dim",children:[" · ",a.theme]}):k.jsx("span",{className:"dim",children:" · no manifest yet: the agent writes the plan (manifest.json) with its plan tool."})]}),k.jsx("span",{className:"spacer"}),k.jsx(IM,{store:t}),k.jsx(n3,{store:t})]}),a.manifest.errors.length>0&&k.jsxs("div",{className:"banner error","data-testid":"manifest-errors",children:["manifest.json has problems: ",a.manifest.errors.map(b=>`${b.path||"(top)"}: ${b.message}`).join(" · ")]}),w.length>0&&k.jsx("div",{className:"dash-progress",title:"Planned assets by status",children:Qo.map(b=>a.counts[b]>0&&k.jsx("span",{className:`seg-bar st-${b}`,style:{flexGrow:a.counts[b]}},b))}),k.jsxs("div",{className:"dash-filters",children:[k.jsxs("span",{className:"dim",children:[w.length," planned:"]}),Qo.map(b=>k.jsxs("button",{className:`badge st-${b}${r===b?" on":""}`,onClick:()=>f(r===b?null:b),"data-testid":`filter-${b}`,title:`${lc[b]}: show only these`,children:[a.counts[b]," ",b]},b)),k.jsx("span",{className:"spacer"}),y.length>0&&(()=>{const b=y.filter(_=>_.state!=="blocked").length,v=y.length-b,$=y.filter(_=>n1(t,_,p)).length;return k.jsx("span",{className:`chip req-chip${$?" unattended":""}`,"data-testid":"requests-count",title:y.map(_=>`${_.id} ${_.kind} ${_.asset}: ${_.state}`).join(`
|
|
49
|
+
`),children:[b?`${b} request${b===1?"":"s"} for Claude`:"",v?`${v} waiting for your answer`:"",$?t.presence?.listening?`${$} unseen for 2 minutes`:"no agent is listening":""].filter(Boolean).join(" · ")})})(),a.manifest.exists&&!a.manifest.errors.length&&k.jsx("button",{onClick:()=>h(!0),"data-testid":"add-asset-open",title:"Add an asset to the plan and ask Claude to draw it",children:"+ Add an asset"}),k.jsx(Fv,{store:t,plan:a}),k.jsxs("label",{className:"dim",children:["set ",k.jsxs("select",{value:l,onChange:b=>i(b.target.value),"data-testid":"set-filter",children:[k.jsx("option",{value:"all",children:"all"}),a.sets.map(b=>k.jsx("option",{value:b.name,children:b.name},b.name))]})]})]})]}),a.scenes.length>0&&k.jsxs("section",{className:"dash-set dash-scenes","data-testid":"scenes",children:[k.jsxs("div",{className:"panel-title",children:["scenes",k.jsx("span",{className:"dim",children:" · what each place still needs"})]}),k.jsx("div",{className:"scene-list",children:a.scenes.map(b=>k.jsxs("div",{className:`scene${b.missing.length||b.unfinished.length?"":" complete"}`,"data-testid":`scene-${b.name}`,children:[k.jsx("b",{className:"mono",children:b.name}),b.description&&k.jsxs("span",{className:"dim",children:[" ",b.description]}),k.jsxs("div",{className:"scene-gaps",children:[b.missing.length===0&&b.unfinished.length===0&&k.jsx("span",{className:"chk pass",children:"everything drawn and checked"}),b.missing.map(v=>k.jsx("span",{className:"chk missing",title:"not drawn yet",children:v},v)),b.unfinished.map(v=>k.jsx("span",{className:"chk fail",title:"drawn; checks failing",children:v},v)),k.jsxs("span",{className:"dim",children:[" ",b.needs.length-b.missing.length," of ",b.needs.length," drawn"]})]})]},b.name))})]}),a.sets.filter(b=>l==="all"||b.name===l).map(b=>{const v=b.assets.map($=>a.assets.find(_=>_.name===$)).filter(x);return v.length?k.jsxs("section",{className:"dash-set","data-testid":`set-${b.name}`,children:[k.jsxs("div",{className:"panel-title",children:[b.name,b.description&&k.jsxs("span",{className:"dim",children:[" ",b.description]}),k.jsxs("span",{className:"dim",children:[" · ",v.length]})]}),k.jsx("div",{className:"dash-grid",children:v.map($=>k.jsx(e3,{a:$,store:t,requests:d},$.name))})]},b.name):null}),t.error&&k.jsx("div",{className:"banner error floating","data-testid":"error",children:t.error}),u&&k.jsx(t3,{plan:a,store:t,onClose:()=>h(!1)})]})})}function f0({a:t,store:a,scale:s,max:l}){const i=he.useRef(null),[r,f]=he.useState(null),u=t.seq??0;he.useEffect(()=>{if(!t.exists)return;const w=new Image;w.onload=()=>f(w),w.src=`/api/strip/${t.name}.png?token=${encodeURIComponent(a.token)}&v=${u}`},[t.name,u,t.exists]);const h=t.ticks.length>1?t.ticks.length:1,d=r?Math.floor(r.naturalWidth/h):t.width,p=r?r.naturalHeight:t.height,y=l&&Math.max(d,p)*s>l?l/Math.max(d,p):s;return he.useEffect(()=>{const w=i.current;if(!w||!r)return;const x=w.getContext("2d");x.imageSmoothingEnabled=!1;let b=0,v=0;const $=a.project?.tickRate??60,_=()=>{if(x.clearRect(0,0,w.width,w.height),x.drawImage(r,b*d,0,d,p,0,0,w.width,w.height),h>1){const j=Math.max(16,(t.ticks[b]??10)*1e3/$);b=(b+1)%h,v=window.setTimeout(_,j)}};return _(),()=>clearTimeout(v)},[r,y,h]),t.exists?k.jsx("canvas",{ref:i,width:Math.max(1,Math.round(d*y)),height:Math.max(1,Math.round(p*y)),"data-frames":h,"data-testid":`sprite-${t.name}`}):k.jsx("span",{className:"planned-box",style:{width:Math.max(24,(t.width||24)*s),height:Math.max(24,(t.height||24)*s)},children:"planned"})}const l3={name:"name",set:"set",kind:"kind",status:"status",recent:"recently changed",size:"size"};function s3({store:t}){const{plan:a,error:s}=a1(t),[l,i]=he.useState("all"),[r,f]=he.useState("all"),[u,h]=he.useState("all"),[d,p]=he.useState("any"),[y,w]=he.useState("set"),[x,b]=he.useState(null),[v,$]=he.useState([]),[_,j]=he.useState(!1),[N,M]=he.useState(1),A=Math.max(1,Math.min(4,Os(t.style,t.project?.grid))),z=he.useMemo(()=>{if(!a)return[];const D=x?a.assets.find(H=>H.name===x):null,L=H=>(l==="all"||H.set===l)&&(r==="all"||H.kind===r)&&(u==="all"||H.status===u)&&(d==="any"||(d==="none"?H.exists&&H.failing.length===0:H.failing.includes(d)))&&(!D||H.name===D.name||D.uses.includes(H.name)||D.usedBy.includes(H.name)),Y=(H,G)=>{switch(y){case"name":return H.name.localeCompare(G.name);case"kind":return H.kind.localeCompare(G.kind)||H.name.localeCompare(G.name);case"status":return Qo.indexOf(H.status)-Qo.indexOf(G.status)||H.name.localeCompare(G.name);case"recent":return(G.at??"").localeCompare(H.at??"")||H.name.localeCompare(G.name);case"size":return G.width*G.height-H.width*H.height||H.name.localeCompare(G.name);default:return 0}},O=a.assets.filter(L);return y==="set"?O:[...O].sort(Y)},[a,l,r,u,d,y,x]);if(!a)return k.jsx("div",{className:"dashboard","data-testid":"gallery",children:k.jsx("div",{className:"dim pad",children:s??"Loading…"})});const E=[...new Set(a.assets.map(D=>D.kind))].sort(),R=[...new Set(a.assets.flatMap(D=>D.failing))].sort(),B=D=>$(v.includes(D)?v.filter(L=>L!==D):[...v,D]),K=D=>{D.exists&&(t.select(D.name),t.setTab("editor"))},J=D=>a.assets.find(L=>L.name===D),T=(D,L)=>D.length>0&&k.jsxs("div",{className:"gal-rel",children:[L," ",D.map(Y=>k.jsx("button",{className:"link mono",onClick:()=>b(Y),title:`Show ${Y} and what it is linked with`,children:Y},Y))]});return k.jsx(Iv,{store:t,plan:a,children:k.jsxs("div",{className:"dashboard gallery","data-testid":"gallery",children:[k.jsxs("div",{className:"dash-top",children:[k.jsxs("div",{className:"dash-filters",children:[k.jsx("b",{children:a.project}),k.jsxs("span",{className:"dim",children:[" · ",z.length," of ",a.assets.length," at game scale (",A,"x)"]}),k.jsx("span",{className:"spacer"}),k.jsxs("label",{className:"dim",children:["set ",k.jsxs("select",{value:l,onChange:D=>i(D.target.value),"data-testid":"g-set",children:[k.jsx("option",{value:"all",children:"all"}),a.sets.map(D=>k.jsx("option",{children:D.name},D.name))]})]}),k.jsxs("label",{className:"dim",children:["kind ",k.jsxs("select",{value:r,onChange:D=>f(D.target.value),"data-testid":"g-kind",children:[k.jsx("option",{value:"all",children:"all"}),E.map(D=>k.jsx("option",{children:D},D))]})]}),k.jsxs("label",{className:"dim",children:["status ",k.jsxs("select",{value:u,onChange:D=>h(D.target.value),"data-testid":"g-status",children:[k.jsx("option",{value:"all",children:"all"}),Qo.map(D=>k.jsx("option",{title:lc[D],children:D},D))]})]}),k.jsxs("label",{className:"dim",children:["checks ",k.jsxs("select",{value:d,onChange:D=>p(D.target.value),"data-testid":"g-failing",children:[k.jsx("option",{value:"any",children:"any"}),k.jsx("option",{value:"none",children:"all pass"}),R.map(D=>k.jsxs("option",{value:D,children:["failing ",D]},D))]})]}),k.jsxs("label",{className:"dim",children:["sort ",k.jsx("select",{value:y,onChange:D=>w(D.target.value),"data-testid":"g-sort",children:Object.entries(l3).map(([D,L])=>k.jsx("option",{value:D,children:L},D))})]}),k.jsx(Fv,{store:t,plan:a}),k.jsxs("button",{disabled:v.length<2,className:_?"on":"",onClick:()=>j(!_),"data-testid":"compare",title:"Select assets (the box on each), then compare them side by side",children:["Compare (",v.length,")"]})]}),x&&k.jsxs("div",{className:"dash-filters",children:[k.jsxs("span",{className:"chip",children:["showing ",k.jsx("b",{className:"mono",children:x})," with ",J(x)?.uses.length?"what it uses":"the maps that use it"]}),k.jsx("button",{className:"link",onClick:()=>b(null),"data-testid":"g-related-clear",children:"show all"})]})]}),_&&v.length>1&&k.jsxs("div",{className:"compare","data-testid":"compare-view",children:[k.jsx("div",{className:"compare-tools",children:k.jsx("span",{className:"seg",children:[1,2,4].map(D=>k.jsx("button",{className:N===D?"on":"",onClick:()=>M(D),title:`${D*A}x: the game's scale${D>1?` times ${D}`:""}`,children:D===1?"game scale":`×${D}`},D))})}),k.jsx("div",{className:"compare-row",children:v.map(D=>J(D)).filter(D=>!!D).map(D=>k.jsxs("figure",{children:[k.jsx(f0,{a:D,store:t,scale:A*N,max:480*N}),k.jsxs("figcaption",{className:"mono",children:[D.name," ",k.jsx("span",{className:`badge st-${D.status}`,children:D.status})]})]},D.name))})]}),k.jsx("div",{className:"gal-grid",children:z.map(D=>k.jsxs("div",{className:`gal-item st-${D.status}${v.includes(D.name)?" picked":""}`,"data-testid":`g-${D.name}`,"data-status":D.status,children:[k.jsx("button",{className:"gal-art",onClick:()=>K(D),disabled:!D.exists,title:D.exists?`Open ${D.name} in the editor`:"planned: not drawn yet",children:k.jsx(f0,{a:D,store:t,scale:A,max:360})}),k.jsxs("div",{className:"gal-meta",children:[k.jsx("label",{className:"gal-pick",title:"Select to compare",children:k.jsx("input",{type:"checkbox",checked:v.includes(D.name),onChange:()=>B(D.name),"data-testid":`pick-${D.name}`})}),k.jsx("b",{className:"mono",children:D.name}),k.jsx("span",{className:`badge st-${D.status}`,title:lc[D.status],children:D.status})]}),k.jsxs("div",{className:"dim small",children:[D.set," · ",D.kind," ",D.exists?`${D.width}x${D.height}`:D.size,D.ticks.length>1?` · ${D.ticks.length} frames`:""]}),D.failing.length>0&&k.jsx("div",{className:"card-checks",children:D.failing.map(L=>k.jsx("span",{className:"chk fail",children:L},L))}),T(D.uses,"uses"),T(D.usedBy,"in")]},D.name))})]})})}const l1=/^human:[A-Za-z0-9_.-]{1,32}$/,o3=["editor","dashboard","gallery"],h0=t=>t==="human"||t.startsWith("human:");function i3(){const t=new URLSearchParams(location.search).get("name"),a=(()=>{try{return localStorage.getItem("pixelclaw.author")}catch{return null}})();for(const s of[t&&(t.startsWith("human:")?t:`human:${t}`),a])if(s&&l1.test(s))return s;return"human:guest"}const d0=1<<18,r3=[1,2,4,8,16,32,60,1/0];class c3{status="connecting";project=null;palettes=new Map;defaultPalette=null;assets=new Map;selected=null;follow=!0;paused=!1;speed=8;travel=null;eye=null;me=i3();error=null;style={};themes=Vg;theme=null;marked=new Set;openCheck=null;tab=o3.includes(new URLSearchParams(location.search).get("tab")??"")?new URLSearchParams(location.search).get("tab"):"editor";requests=[];worker=null;presence=null;workerLog=[];planVersion=0;token="";styleVersion=0;checkCache=null;queue=[];travelCache=null;nextId=0;waiting=new Map;answers=new Map;listeners=new Set;version=0;ws=null;retry=null;raf=0;budget=0;lastTick=0;idle=!0;source={get:a=>this.palettes.get(a)};get paletteSource(){return this.source}subscribe=a=>(this.listeners.add(a),()=>this.listeners.delete(a));getVersion=()=>this.version;changed(){this.version++;for(const a of this.listeners)a()}model(a,s){return{name:a,tape:s,cursor:new ni(this.source),problem:null,timeline:new nN(this.source)}}setMe(a){const s=a.startsWith("human:")?a:`human:${a}`;if(!l1.test(s))return!1;this.me=s;try{localStorage.setItem("pixelclaw.author",s)}catch{}return this.changed(),!0}send(a,s){const l=this.ws;if(!l||l.readyState!==WebSocket.OPEN)return Promise.resolve({ok:!1,errors:[{line:0,col:0,message:"not connected"}]});const i=++this.nextId;return l.send(JSON.stringify({type:"run",id:i,asset:a,commands:s,by:this.me})),new Promise(r=>this.waiting.set(i,f=>{this.error=f.ok?null:f.errors.map(u=>u.line?`${u.line}:${u.col}: ${u.message}`:u.message).join(`
|
|
50
|
+
`),this.changed(),r(f)}))}request(a){return this.ask({type:"request",body:a})}workerAction(a){return this.ask({type:"worker",action:a})}ask(a){const s=this.ws;if(!s||s.readyState!==WebSocket.OPEN)return Promise.resolve({ok:!1,error:"not connected"});const l=++this.nextId;return s.send(JSON.stringify({...a,id:l,by:this.me})),new Promise(i=>this.answers.set(l,i))}async importFiles(a,s){const l=await Promise.all(a.map(async i=>{const r=new Uint8Array(await i.arrayBuffer());let f="";for(let u=0;u<r.length;u+=32768)f+=String.fromCharCode(...r.subarray(u,u+32768));return{name:i.name,data:btoa(f)}}));try{return await(await fetch(`/api/import?token=${encodeURIComponent(this.token)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:l,options:s,by:this.me})})).json()}catch(i){return{error:String(i)}}}async loadWorker(){try{const a=await(await fetch(`/api/worker?token=${encodeURIComponent(this.token)}`)).json();this.worker=a.status,this.workerLog=a.log,this.changed()}catch{}}lastWrite(a){const s=this.assets.get(a)?.tape.at(-1);return s?{by:s.by,at:s.at??""}:null}setTab(a){this.tab=a;const s=new URL(location.href);a!=="editor"?s.searchParams.set("tab",a):s.searchParams.delete("tab"),history.replaceState(null,"",s),this.changed()}connect(a){this.token=a;const s=`${location.protocol==="https:"?"wss":"ws"}://${location.host}/ws?token=${encodeURIComponent(a)}`,l=new WebSocket(s);this.ws=l,l.onopen=()=>{this.status="open",this.changed()},l.onmessage=i=>this.receive(JSON.parse(String(i.data))),l.onclose=()=>{this.ws=null,this.status="closed",this.changed(),this.retry=setTimeout(()=>this.connect(a),1e3)}}disconnect(){this.retry&&clearTimeout(this.retry),this.ws?.close(),cancelAnimationFrame(this.raf)}receive(a){if(a.type==="hello")this.load(a.snapshot),this.planVersion++;else if(a.type==="palettes")this.palettes=new Map(a.palettes.map(s=>[s.name,s])),this.defaultPalette=a.defaultPalette;else if(a.type==="eye")this.eye=a.eye;else if(a.type==="style")this.style=a.style,this.themes=a.themes,this.styleVersion++;else if(a.type==="result"){const s=this.waiting.get(a.id);this.waiting.delete(a.id),s?.(a.ok?{ok:!0,asset:a.asset,group:a.group,seq:a.seq}:{ok:!1,errors:a.errors})}else if(a.type==="plan")this.planVersion++;else if(a.type==="answer"){const s=this.answers.get(a.id);this.answers.delete(a.id),s?.({ok:a.ok,...a.error?{error:a.error}:{},...a.request?{request:a.request}:{}})}else if(a.type==="requests")this.requests=a.requests;else if(a.type==="worker")this.worker=a.status;else if(a.type==="presence")this.presence=a.presence;else if(a.type==="workerLog")this.workerLog=[...this.workerLog,...a.lines].slice(-500);else if(a.type==="batch"){this.planVersion++;let s=this.assets.get(a.asset);(!s||a.reset)&&(s=this.model(a.asset,[]),this.assets.set(a.asset,s),this.travel!==null&&this.selected===a.asset&&(this.travel=null));const l=this.pending(s)===0;s.tape.push(...a.entries),this.selected||(this.selected=a.asset),h0(a.by)&&l&&!this.paused?this.advance(s,a.entries.length):this.queue.push(a.asset),this.schedule()}this.changed()}load(a){this.project=a.project,this.palettes=new Map(a.palettes.map(s=>[s.name,s])),this.defaultPalette=a.defaultPalette,this.style=a.style??{},this.themes=a.themes??Vg,this.styleVersion++,this.eye=a.eye,this.worker=a.worker??null,this.presence=a.presence??null,this.queue=[],this.travel=null,this.assets=new Map;for(const s of a.assets){const l=this.model(s.name,s.entries),i=l.timeline.docAt(l.tape,l.tape.length);i.problem?this.advance(l,l.tape.length):l.cursor=ni.resume(this.source,i.doc,l.tape),this.assets.set(s.name,l)}(!this.selected||!this.assets.has(this.selected))&&(this.selected=a.live??a.assets[0]?.name??null)}pending(a){return a?a.tape.length-a.cursor.done.length:0}advance(a,s){for(let l=0;l<s&&!a.problem;l++){const i=a.tape[a.cursor.done.length];if(!i)break;const r=a.cursor.step(i);r&&(a.problem=`#${i.seq}: ${r}`)}}schedule(){this.raf||(this.lastTick=performance.now(),this.raf=requestAnimationFrame(this.tick))}tick=a=>{this.raf=0;const s=Math.min(250,a-this.lastTick);if(this.lastTick=a,this.paused)return;for(const i of this.assets.values())for(;this.pending(i)>0&&!i.problem&&h0(i.tape[i.cursor.done.length].by);)this.advance(i,1);let l=this.selected?this.assets.get(this.selected):void 0;if(this.follow&&this.pending(l)===0){this.queue=this.queue.filter(r=>this.pending(this.assets.get(r))>0);const i=this.queue[0];i&&i!==this.selected&&(this.selected=i,this.travel=null,l=this.assets.get(i),this.budget=0)}if(!l||this.pending(l)===0||l.problem){this.idle=!0,this.budget=0,this.changed();return}if(this.speed===1/0)this.advance(l,this.pending(l));else{this.idle?this.budget=1:this.budget+=s*this.speed/1e3,this.idle=!1;const i=Math.max(1,Math.ceil(this.speed/60)),r=Math.min(Math.floor(this.budget),i);this.budget=Math.min(this.budget-r,i),this.advance(l,r)}this.changed(),this.schedule()};setPaused(a){this.paused=a,a||this.schedule(),this.changed()}setSpeed(a){this.speed=a,this.changed()}setFollow(a){this.follow=a,a&&this.schedule(),this.changed()}jumpToLive(){for(const a of this.assets.values())this.advance(a,this.pending(a));this.queue=[],this.travel=null,this.paused=!1,this.changed()}select(a){this.assets.has(a)&&(this.selected=a,this.travel=null,this.schedule(),this.changed())}setTravel(a){this.travel=a,this.changed()}catchUp(){const a=this.current;a&&this.pending(a)>0&&(this.advance(a,this.pending(a)),this.queue=this.queue.filter(s=>s!==a.name),this.changed())}get current(){return this.selected?this.assets.get(this.selected):void 0}shownDoc(){const a=this.current;if(!a)return{doc:null,seq:null};if(this.travel===null)return{doc:a.cursor.doc,seq:a.cursor.done.at(-1)?.seq??null};const s=`${a.name}:${this.travel}:${a.tape.length}:${a.tape[0]?.seq??0}`;return this.travelCache?.key!==s&&(this.travelCache={key:s,doc:a.timeline.docAfter(a.tape,this.travel).doc}),{doc:this.travelCache.doc,seq:this.travel}}assetDocs(){const a=[];for(const s of this.assets.values()){if(!s.cursor.doc)continue;const l=s.tape.map(i=>/^fork (\S+) \S+ at=\d+$/.exec(i.cmd)).find(Boolean);a.push({name:s.name,doc:s.cursor.doc,forkOf:l?.[1]??null})}return a}themeObj(){return this.theme?this.themes.find(a=>a.name===this.theme)??null:null}setTheme(a){this.theme=a,this.changed()}checksFor(a,s){const l=this.current;if(!l)return[];let i=0;for(const u of this.assets.values())i+=u.cursor.done.length;const r=a.width*a.height*a.frameCount>d0,f=`${l.name}:${this.travel}:${l.cursor.done.length}:${r?s:""}:${i}:${this.styleVersion}`;if(this.checkCache?.key!==f){const u=performance.now(),h=this.pending(l)>0&&this.checkCache?.asset===l.name;if(r&&h&&u-this.checkCache.at<500)return this.checkCache.results;const{ctx:d}=oN(l.name,a,this.assetDocs(),this.style,p=>this.palettes.get(p));this.checkCache={key:f,asset:l.name,at:u,results:M_(a,J0,{...d,budget:d0,focus:s})}}return this.checkCache.results}toggleCheck(a){this.marked.has(a)?(this.marked.delete(a),this.openCheck===a&&(this.openCheck=[...this.marked].at(-1)??null)):(this.marked.add(a),this.openCheck=a),this.changed()}closeChecks(){this.marked.clear(),this.openCheck=null,this.changed()}undoneCache=null;undoneGroups(a){const s=this.undoneCache;if(s&&s.tape===a.tape&&s.n===a.tape.length)return s.set;const l=ti(a.tape),i=new Set(a.tape.map(r=>r.group).filter(r=>!l.has(r)));return this.undoneCache={tape:a.tape,n:a.tape.length,set:i},i}}function Ch(t){return t==="claude"?"by-claude":t.startsWith("human")?"by-human":"by-other"}function s1(t){return t?new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}):""}const Eh=18,m0=28,p0=600;function u3(t){const a=[],s=new Map;let l=0,i=null;return t.forEach((r,f)=>{r.group!==i&&(i=r.group,a.push({kind:"group",e:r,i:f,top:l,h:m0}),l+=m0);const u=Eh*(1+(r.cmd.match(/\n/g)?.length??0));s.set(r.seq,l),a.push({kind:"cmd",e:r,i:f,top:l,h:u}),l+=u}),{rows:a,height:l+8,topOf:s}}function f3(t,a){let s=0,l=t.length;for(;s<l;){const i=s+l>>1;t[i].top+t[i].h<=a?s=i+1:l=i}return s}function h3({asset:t,undone:a,travel:s,follow:l,onPick:i}){const r=he.useRef(null),[f,u]=he.useState({top:0,h:600}),h=t?.cursor.done.length??0,d=t&&h>0?t.tape[h-1].seq:null,p=t?.tape,y=p?.length??0,{rows:w,height:x,topOf:b}=he.useMemo(()=>u3(p??[]),[p,y]);if(he.useLayoutEffect(()=>{const _=r.current;if(!_)return;const j=new ResizeObserver(()=>u({top:_.scrollTop,h:_.clientHeight}));return j.observe(_),()=>j.disconnect()},[]),he.useLayoutEffect(()=>{const _=r.current;if(!_||s!==null||!l||d===null)return;const j=b.get(d);j!==void 0&&(j<_.scrollTop||j+Eh>_.scrollTop+_.clientHeight)&&(_.scrollTop=Math.max(0,j+Eh-_.clientHeight+8),u({top:_.scrollTop,h:_.clientHeight}))},[d,s,l,b]),!t)return k.jsx("div",{className:"tape-list",ref:r,"data-testid":"tape"});const v=f3(w,f.top-p0),$=[];for(let _=v;_<w.length&&w[_].top<f.top+f.h+p0;_++){const{kind:j,e:N,i:M,top:A,h:z}=w[_],E={top:A,height:z};if(j==="group"){$.push(k.jsxs("div",{style:E,className:`group-row ${Ch(N.by)}${a.has(N.group)?" undone":""}`,children:[k.jsx("span",{className:"author",children:N.by}),k.jsx("span",{className:"gid",children:N.group}),a.has(N.group)&&k.jsx("span",{className:"tag",children:"undone"}),k.jsx("span",{className:"at",children:s1(N.at)})]},`g-${N.group}-${N.seq}`));continue}const[R,...B]=N.cmd.split(`
|
|
51
|
+
`),K=M<h?N.seq===d?" head":"":" pending";$.push(k.jsxs("div",{"data-seq":N.seq,style:E,className:`cmd-row ${Ch(N.by)}${K}${a.has(N.group)?" undone":""}${s===N.seq?" picked":""}${s!==null&&N.seq>s?" future":""}`,title:`#${N.seq} by ${N.by}, group ${N.group}${N.at?`, ${N.at}`:""}. Click to see the document at this point.
|
|
52
|
+
${N.cmd}`,onClick:()=>i(N.seq),children:[k.jsxs("span",{className:"seq",children:["#",N.seq]}),k.jsxs("span",{className:"cmd",children:[R,B.length>0&&k.jsx("span",{className:"block",children:B.join(`
|
|
53
|
+
`)})]})]},N.seq))}return k.jsx("div",{className:"tape-list",ref:r,"data-testid":"tape","data-lines":y,onScroll:_=>u({top:_.currentTarget.scrollTop,h:_.currentTarget.clientHeight}),children:k.jsx("div",{className:"tape-inner",style:{height:x},children:$})})}function d3(t){return t===1/0?"instant":`${t}/s`}function m3(t,a){const s=Math.max(1,Math.min(Math.floor(innerWidth*.92/t),Math.floor(innerHeight*.85/a)));return{width:t*s,height:a*s}}const p3=/^fork (\S+) \S+ at=(\d+)$/;function y3(t){return t instanceof HTMLElement&&(t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.tagName==="SELECT"||t.isContentEditable)}function g3(t,a){for(const s of"bcdefghijklmnopqrstuvwxyz")if(!a(`${t}_${s}`))return`${t}_${s}`;return`${t}_branch`}function w3({store:t}){he.useSyncExternalStore(t.subscribe,t.getVersion);const a=he.useMemo(()=>{const X=new ai(t);return window.pixelclawEditor=X,X},[t]),[s,l]=he.useState("fit"),[i,r]=he.useState(1),[f,u]=he.useState(!0),[h,d]=he.useState(!0),[p,y]=he.useState(!0),[w,x]=he.useState(!1),[b,v]=he.useState(null),[$,_]=he.useState(null),[j,N]=he.useState(""),[M,A]=he.useState("sheet"),[z,E]=he.useState(""),R=he.useRef(null),B=t.current,{doc:K,seq:J}=t.shownDoc(),T=a.previewDoc()??K,D=t.pending(B),L=[...t.assets.values()].reduce((X,we)=>X+t.pending(we),0),Y=t.travel===null&&L===0&&!t.paused,O=T?.palette??(t.defaultPalette?t.palettes.get(t.defaultPalette):void 0),H=B?.tape.at(-1)?.by,G=a.editable,Z=T?a.frameIndex(T):0,[W,se]=he.useState(0),ue=T&&a.playing?Pa(T).find(X=>X.name===a.playing.seq)??null:null,te=t.project?.tickRate??60;he.useEffect(()=>{if(!a.playing)return;let X=0;const we=()=>{se(Math.floor((performance.now()-a.playing.start)*te/1e3)),X=requestAnimationFrame(we)};return X=requestAnimationFrame(we),()=>cancelAnimationFrame(X)},[a.playing,a,te]);const U=T&&ue?El(T,ue,W):Z,V=T?Pa(T).find(X=>X.frames.includes(Z)):null,P=X=>{if(!V||V.frames.length<2)return null;const we=V.frames.indexOf(Z);return V.frames[(we+X+V.frames.length)%V.frames.length]},ie=a.onionPrev&&!ue?P(-1):null,ye=a.onionNext&&!ue?P(1):null,F={prev:ie,next:ye===ie?null:ye},pe=T?et(T,t.me):null,fe=T&&(a.mirrorX||a.mirrorY)?{x2:a.mirrorX?T.width-1:null,y2:a.mirrorY?T.height-1:null}:null,ge=K?t.checksFor(K,Z):[],Re=ge.filter(X=>t.marked.has(X.id)).flatMap(X=>Vk(X,U)),rt=ge.find(X=>X.id===t.openCheck&&t.marked.has(X.id)),Se=X=>{X();const we=document.activeElement;(we instanceof HTMLSelectElement||we instanceof HTMLInputElement&&we.type==="checkbox")&&we.blur(),t.changed()};he.useEffect(()=>{const X=we=>{y3(we.target)||a.key(we)&&we.preventDefault()};return window.addEventListener("keydown",X),()=>window.removeEventListener("keydown",X)},[a]),he.useEffect(()=>{a.noteDraft&&R.current?.focus()},[a.noteDraft]);const be=X=>{const we=Ia.indexOf(i);l(Ia[Math.max(0,Math.min(Ia.length-1,(we<0?0:we)+X))])},$e=async()=>{if(!B||t.travel===null||!b)return;const X=t.travel;(await t.send(b,`fork ${B.name} ${b} at=${X}`)).ok&&(v(null),t.select(b))},Me=async()=>{const X=j.trim();if(!X)return;t.catchUp();const we=await t.send(/^\s*(new|fork)\b/.test(X)?"":B?.name??"",X);we.ok&&(N(""),we.asset!==B?.name&&t.select(we.asset))},Ge=a.noteDraft,mt=t.tab!=="editor",ct=k.jsxs("span",{className:"seg tabs","data-testid":"tabs",children:[k.jsx("button",{className:mt?"":"on",onClick:()=>t.setTab("editor"),"data-tab":"editor",children:"Editor"}),k.jsx("button",{className:t.tab==="dashboard"?"on":"",onClick:()=>t.setTab("dashboard"),"data-tab":"dashboard",title:"The plan: every planned asset by set, with its status; ask Claude for work",children:"Dashboard"}),k.jsx("button",{className:t.tab==="gallery"?"on":"",onClick:()=>t.setTab("gallery"),"data-tab":"gallery",title:"Every asset at game scale: filter, sort, compare",children:"Gallery"})]});return mt?k.jsxs("div",{className:"app dash",children:[k.jsxs("header",{children:[k.jsx("span",{className:"logo",children:"PixelClaw"}),ct,k.jsx("span",{className:"crumbs",children:t.project?.name??"…"}),k.jsx("span",{className:"spacer"}),k.jsxs("span",{className:"chip me",title:"The name your approvals are written with on the tape",children:["you: ",k.jsx("b",{children:t.me})]}),k.jsx("span",{className:`chip conn-${t.status}`,"data-testid":"status",children:t.status==="open"?"● connected":t.status==="connecting"?"connecting…":"reconnecting…"})]}),t.tab==="gallery"?k.jsx(s3,{store:t}):k.jsx(a3,{store:t})]}):k.jsxs("div",{className:"app",children:[k.jsxs("header",{children:[k.jsx("span",{className:"logo",children:"PixelClaw"}),ct,k.jsxs("span",{className:"crumbs",children:[t.project?.name??"…",B&&k.jsxs(k.Fragment,{children:[" ",k.jsx("span",{className:"sep",children:"▸"})," ",B.name]}),T&&k.jsxs("span",{className:"meta",children:[" ",T.kind," ",T.width,"×",T.height,T.wrap?" · wrap":""," · ",T.palette.name]})]}),k.jsx("span",{className:"spacer"}),k.jsx(kM,{results:ge,store:t}),t.travel!==null&&k.jsxs("span",{className:"chip travel-chip",children:["viewing #",t.travel," · read-only"]}),t.paused&&k.jsx("span",{className:"chip paused-chip",children:"paused"}),$===null?k.jsxs("button",{className:"chip me","data-testid":"me",title:"The name your edits are written with on the tape. Click to change it.",onClick:()=>_(t.me.slice(6)),children:[k.jsx("span",{className:"xwide-only",children:"you: "}),k.jsx("b",{children:t.me})]}):k.jsxs("form",{className:"me-form",onSubmit:X=>{X.preventDefault(),t.setMe($)&&_(null)},children:["human:",k.jsx("input",{autoFocus:!0,value:$,onChange:X=>_(X.target.value),onBlur:()=>_(null),"aria-label":"your name"})]}),k.jsx("span",{className:`chip conn-${t.status}`,"data-testid":"status",children:t.status==="open"?Y?"● live":"● connected":t.status==="connecting"?"connecting…":"reconnecting…"})]}),k.jsxs("aside",{className:"left",children:[k.jsxs("div",{className:"panel-title",children:["Assets",k.jsxs("label",{className:"follow",title:"Show whichever asset the agent is drawing on (turns off when you start editing)",children:[k.jsx("input",{type:"checkbox",checked:t.follow,onChange:X=>t.setFollow(X.target.checked)})," follow"]})]}),k.jsxs("ul",{className:"assets","data-testid":"assets",children:[[...t.assets.values()].map(X=>{const we=t.pending(X),Te=X.tape.map(Ve=>p3.exec(Ve.cmd)).find(Boolean);return k.jsxs("li",{className:X.name===t.selected?"selected":"",onClick:()=>t.select(X.name),title:Te?`a branch of ${Te[1]} at #${Te[2]}`:void 0,children:[k.jsx("span",{className:`dot${we>0?" busy":""}`,children:we>0?"●":"○"}),k.jsxs("span",{className:"name",children:[X.name,Te&&k.jsxs("span",{className:"dim",children:[" ⑂ ",Te[1]]})]}),k.jsx("span",{className:"count",children:X.tape.length})]},X.name)}),t.assets.size===0&&k.jsx("li",{className:"none",children:"none yet"})]}),!T?.map&&k.jsxs(k.Fragment,{children:[k.jsx("div",{className:"panel-title",children:"Tools"}),k.jsx(CM,{ed:a,disabled:!G})]}),O&&!T?.map&&k.jsx(EM,{palette:O,ed:a,editable:G,locked:!!T?.paletteLocked,theme:t.theme,themes:t.themes,onTheme:X=>t.setTheme(X)}),T&&!T.map&&k.jsx(qM,{doc:T,ed:a,editable:G})]}),k.jsxs("main",{children:[k.jsxs("div",{className:"toolbar",children:[!T?.map&&k.jsxs(k.Fragment,{children:[k.jsx("button",{onClick:()=>be(-1),disabled:!T,title:"Zoom out (Ctrl/⌘ + wheel)",children:"−"}),k.jsx("span",{className:"zoom","data-testid":"zoom",children:T?`${i}×`:""}),k.jsx("button",{onClick:()=>be(1),disabled:!T,title:"Zoom in (Ctrl/⌘ + wheel)",children:"+"}),k.jsx("button",{className:s==="fit"?"on":"",disabled:!T,onClick:()=>l("fit"),children:"Fit"}),k.jsx("span",{className:"gap"}),k.jsxs("label",{children:[k.jsx("input",{type:"checkbox",checked:f,onChange:X=>u(X.target.checked),"data-testid":"pixel-grid"})," ",k.jsx("span",{className:"wide-only",children:"pixel grid"}),k.jsx("span",{className:"narrow-only",children:"grid"})]}),k.jsxs("label",{children:[k.jsx("input",{type:"checkbox",checked:h,onChange:X=>d(X.target.checked)})," ",k.jsx("span",{className:"wide-only",children:"cell grid"}),k.jsx("span",{className:"narrow-only",children:"cells"})]}),T?.wrap&&k.jsxs("label",{title:"Show half a tile of the neighbouring copies around a wrap document (draw on them: strokes wrap)",children:[k.jsx("input",{type:"checkbox",checked:p,onChange:X=>y(X.target.checked),"data-testid":"ghosts-toggle"})," ",k.jsx("span",{className:"wide-only",children:"wrap ghosts"}),k.jsx("span",{className:"narrow-only",children:"ghosts"})]}),T?.family&&M==="sheet"&&a.hover&&k.jsx("span",{className:"dim mono","data-testid":"family-cell",title:"The family cell under the pointer (@cell(<name>) in commands)",children:z_(T.family,a.hover[0],a.hover[1])??""}),T?.family&&k.jsx("span",{className:"seg","data-testid":"family-mode",title:"A family: its sheet (draw here), every variant among its neighbours, or a sample map (only for looking)",children:["sheet","variants","map"].map(X=>k.jsx("button",{className:M===X?"on":"","data-mode":X,onClick:()=>A(X),children:X},X))}),k.jsx("span",{className:"gap"}),T&&G&&k.jsx(k.Fragment,{children:k.jsxs("span",{className:"colour-now",title:"Colour A draws (I or Alt+click picks one); colour B (right-click a swatch) ends gradients and grounds dithers. X swaps them.","data-testid":"colour",children:[k.jsx("span",{className:"ab",children:"A"}),k.jsx("span",{className:`chip-colour${a.colourName(T)==="none"?" none":""}`,style:{background:T.palette.entries.find(X=>X.name===a.colourName(T))?.hex}}),a.colourName(T),k.jsx("span",{className:"ab b",children:"B"}),k.jsx("span",{className:`chip-colour${a.colourName(T,!0)==="none"?" none":""}`,"data-testid":"colour2",style:{background:T.palette.entries.find(X=>X.name===a.colourName(T,!0))?.hex}}),k.jsx("span",{"data-testid":"colour2-name",children:a.colourName(T,!0)})]})})]}),k.jsx("span",{className:"spacer"}),k.jsxs("button",{onClick:()=>a.undo(),disabled:!a.canUndo(),title:`Undo your last edit (Ctrl/⌘+Z): undo by=${t.me}`,"data-testid":"undo",children:["↶ ",k.jsx("span",{className:"xwide-only",children:"Undo"})]}),k.jsxs("button",{onClick:()=>a.redo(),disabled:!a.canRedo(),title:`Redo your last undo (Ctrl/⌘+Shift+Z): redo by=${t.me}`,"data-testid":"redo",children:["↷ ",k.jsx("span",{className:"xwide-only",children:"Redo"})]}),T&&J!==null&&k.jsxs("span",{className:"dim",title:`The canvas shows the document after command #${J}`,children:[k.jsx("span",{className:"xwide-only",children:"after "}),"#",J]})]}),T&&G&&!T.map&&(!T.family||M==="sheet")&&k.jsxs("div",{className:"options","data-testid":"options",children:[(a.tool==="rect"||a.tool==="ellipse")&&k.jsxs("label",{title:"Filled shapes (F)",children:[k.jsx("input",{type:"checkbox",checked:a.filled,onChange:X=>Se(()=>{a.filled=X.target.checked})})," filled"]}),a.tool==="pencil"&&k.jsxs("label",{title:"Pixel-perfect pencil: no doubled L-corners",children:[k.jsx("input",{type:"checkbox",checked:a.pixelPerfect,onChange:X=>Se(()=>{a.pixelPerfect=X.target.checked})})," pixel-perfect"]}),a.usesBrush()&&k.jsxs("span",{className:"opt",title:"The brush pencil, eraser, lines and outlines draw with (brush square|circle <n>)",children:["brush",k.jsxs("select",{value:a.brushShape,onChange:X=>Se(()=>{a.brushShape=X.target.value}),"data-testid":"brush-shape",children:[k.jsx("option",{value:"square",children:"square"}),k.jsx("option",{value:"circle",children:"circle"})]}),k.jsx("input",{type:"number",min:1,max:8,value:a.brushSize,className:"num","aria-label":"brush size","data-testid":"brush-size",onChange:X=>Se(()=>{a.brushSize=Math.max(1,Math.min(8,Number(X.target.value)||1))}),onKeyDown:X=>{(X.key==="Enter"||X.key==="Escape")&&X.currentTarget.blur()}})]}),a.tool==="wand"&&k.jsxs("label",{title:"Select every pixel of the colour, not only the touching ones (mode=global)",children:[k.jsx("input",{type:"checkbox",checked:a.wandGlobal,onChange:X=>Se(()=>{a.wandGlobal=X.target.checked}),"data-testid":"wand-global"})," whole colour"]}),a.tool==="gradient"&&k.jsxs("span",{className:"opt",children:["pattern",k.jsx("select",{value:a.gradientPattern,onChange:X=>Se(()=>{a.gradientPattern=X.target.value}),"data-testid":"gradient-pattern",children:["none",...s0].map(X=>k.jsx("option",{children:X},X))})]}),a.tool==="dither"&&k.jsxs("span",{className:"opt",children:["pattern",k.jsx("select",{value:a.ditherPattern,onChange:X=>Se(()=>{a.ditherPattern=X.target.value}),"data-testid":"dither-pattern",children:s0.map(X=>k.jsx("option",{children:X},X))}),"level",k.jsx("select",{value:String(a.ditherLevel),onChange:X=>Se(()=>{a.ditherLevel=Number(X.target.value)}),"data-testid":"dither-level",children:[.125,.25,.375,.5,.625,.75,.875].map(X=>k.jsx("option",{value:String(X),children:X},X))})]}),k.jsxs("span",{className:"opt sym",title:"Symmetry: your strokes are mirrored across the middle (mirror … live); the guides show the axes",children:["mirror",k.jsx("button",{className:a.mirrorX?"on":"",onClick:()=>Se(()=>{a.mirrorX=!a.mirrorX}),"data-testid":"mirror-x",title:"Mirror left-right",children:"⇹"}),k.jsx("button",{className:a.mirrorY?"on":"",onClick:()=>Se(()=>{a.mirrorY=!a.mirrorY}),"data-testid":"mirror-y",title:"Mirror top-bottom",children:"⇵"})]}),k.jsx("span",{className:"spacer"}),k.jsxs("span",{className:"opt",title:pe?.sel?"These act on your selection":"These act on your whole layer (select first to act on part of it)",children:[k.jsx("span",{className:"dim opt-label",children:pe?.sel?"selection:":"layer:"}),k.jsx("button",{onClick:()=>a.act("flip h"),title:"Flip left-right (Shift+H): flip h","data-testid":"flip-h",children:"⇋"}),k.jsx("button",{onClick:()=>a.act("flip v"),title:"Flip top-bottom (Shift+V): flip v","data-testid":"flip-v",children:"⇵"}),k.jsx("button",{onClick:()=>a.act("rotate 90"),title:"Rotate 90° clockwise (Shift+R): rotate 90","data-testid":"rotate",children:"⟳"}),k.jsx("button",{onClick:()=>a.act(`outline c=${a.colourName(T)}`),title:"Outline the shapes in colour A: outline","data-testid":"outline",children:"◘"}),k.jsx("button",{onClick:()=>a.act("clean orphans"),title:"Remove lone pixels: clean orphans","data-testid":"clean",children:"⌧"}),pe?.sel&&k.jsx("button",{onClick:()=>a.deselect(),title:"Deselect (Esc)","data-testid":"deselect",children:"✕"})]})]}),t.travel!==null&&B&&k.jsxs("div",{className:"banner",children:["Viewing the document after #",t.travel," (read-only).",k.jsx("button",{onClick:()=>t.setTravel(null),children:"Back to live"}),b===null?k.jsx("button",{onClick:()=>v(g3(B.name,X=>t.assets.has(X))),"data-testid":"branch",title:"Start a new asset from this point (a fork); the original stays as it is",children:"⑂ Branch here…"}):k.jsxs("form",{className:"inline-form",onSubmit:X=>{X.preventDefault(),$e()},children:["new asset ",k.jsx("input",{value:b,onChange:X=>v(X.target.value),"aria-label":"branch name",autoFocus:!0}),k.jsx("button",{type:"submit","data-testid":"branch-create",children:"Create branch"}),k.jsx("button",{type:"button",onClick:()=>v(null),children:"Cancel"})]})]}),Ge&&k.jsxs("form",{className:"banner note-banner","data-testid":"note-form",onSubmit:X=>{X.preventDefault(),a.writeNote(z).then(we=>we&&E(""))},children:["Note at ",Ge.x,",",Ge.y,Ge.w>1||Ge.h>1?` ${Ge.w}×${Ge.h}`:"",":",k.jsx("input",{ref:R,value:z,onChange:X=>E(X.target.value),placeholder:"what should the agent know?",onKeyDown:X=>{X.key==="Escape"&&a.cancel()},"aria-label":"note text"}),k.jsx("button",{type:"submit",disabled:!z.trim(),children:"Pin note"}),k.jsx("button",{type:"button",onClick:()=>a.cancel(),children:"Cancel"})]}),rt&&k.jsx(SM,{result:rt,ed:a,editable:G,onClose:()=>t.closeChecks()}),t.error&&k.jsx("div",{className:"banner error","data-testid":"error",children:t.error}),B?.problem&&k.jsxs("div",{className:"banner error",children:["This tape does not replay: ",B.problem]}),T?.family&&M==="variants"&&k.jsx(UM,{doc:T,ed:a,editable:G,frame:U,theme:t.themeObj()}),T?.family&&M==="map"&&k.jsx(LM,{doc:T,store:t,frame:U}),T?.map&&k.jsx(YM,{doc:T,store:t,ed:a,editable:G}),!T?.map&&(!T?.family||M==="sheet")&&k.jsx(wM,{doc:T,frame:U,onion:F,zoom:s,pixelGrid:f,cellGrid:h,ghosts:p,theme:t.themeObj(),seq:J,asset:B?.name??null,travel:t.travel!==null,overlay:{mySel:pe?.sel??null,selOffset:a.dragOffset,otherSels:T?Object.entries(T.ctx).flatMap(([X,we])=>X!==t.me&&we.sel?[we.sel]:[]):[],marquee:a.marquee,marqueeEllipse:a.tool==="select-ellipse",lasso:a.lassoPath,mirror:G?fe:null,notes:T?.notes??[],activeNote:a.activeNote,hover:a.hover,draft:Ge,marks:Re,pivot:T&&a.guides&&!T.wrap?T.pivot:null,ground:T&&a.guides&&!T.wrap?T.ground:null},pointer:G?{down:(X,we)=>a.down(X,we),move:X=>a.move(X),up:X=>a.up(X)}:null,cursor:a.tool==="move"?"move":a.tool==="picker"?"copy":"crosshair",onNote:X=>{a.activeNote=X,t.changed()},onZoom:l,onEffectiveZoom:r}),T&&!T.map&&k.jsx(DM,{doc:T,ed:a,editable:G,frameShown:U})]}),k.jsxs("aside",{className:"right",children:[k.jsxs("div",{className:"panel-title",children:["Tape",B&&k.jsxs("span",{className:"dim",children:[" ",B.tape.length," commands"]}),k.jsx("span",{className:"spacer"}),H&&k.jsx("span",{className:`legend ${Ch(H)}`,children:H})]}),k.jsx(h3,{asset:B,undone:B?t.undoneGroups(B):new Set,travel:t.travel,follow:t.follow,onPick:X=>t.setTravel(X)}),k.jsxs("form",{className:"cmdline",onSubmit:X=>{X.preventDefault(),Me()},children:[k.jsx("span",{className:"prompt",children:">"}),k.jsx("input",{value:j,onChange:X=>N(X.target.value),placeholder:"type a command…",spellCheck:!1,disabled:t.status!=="open","aria-label":"command line","data-testid":"cmdline",title:`Commands run on the shown asset as ${t.me}, as one undo group (';' between commands)`})]}),k.jsxs("div",{className:"controls","data-testid":"controls",children:[k.jsx("button",{onClick:()=>t.setPaused(!t.paused),"data-testid":"pause",children:t.paused?"▶ Play":"❚❚ Pause"}),k.jsx("select",{value:String(t.speed),onChange:X=>t.setSpeed(Number(X.target.value)),title:"Playback speed (commands per second)","data-testid":"speed",children:r3.map(X=>k.jsx("option",{value:String(X),children:d3(X)},String(X)))}),k.jsx("button",{onClick:()=>t.jumpToLive(),disabled:Y,"data-testid":"live",children:"Jump to live ⏭"}),k.jsx("span",{className:"spacer"}),k.jsx("span",{className:"dim","data-testid":"waiting",children:D>0?`${D} to play`:L>0?`${L} waiting`:""})]}),K&&!K.map&&k.jsx(zM,{doc:K,frame:Z,store:t,marks:Re}),T&&B&&k.jsx(OM,{doc:T,tape:B.tape,ed:a,editable:G,active:a.activeNote,onActive:X=>{a.activeNote=X,t.changed()}}),k.jsxs("div",{className:"panel-title",children:["Claude's eye ",k.jsx("span",{className:"dim",children:"the last image the agent saw"})]}),k.jsx("div",{className:"eye","data-testid":"eye",children:t.eye?k.jsxs(k.Fragment,{children:[k.jsx("img",{src:`data:image/png;base64,${t.eye.png}`,alt:`${t.eye.asset} ${t.eye.mode}`,onClick:()=>x(!0)}),k.jsxs("div",{className:"dim",children:[t.eye.asset," · ",t.eye.mode," · ",t.eye.width,"×",t.eye.height," · ",s1(t.eye.at)]})]}):k.jsx("div",{className:"dim",children:"Nothing yet. When the agent looks at a view, it shows here."})})]}),w&&t.eye&&k.jsxs("div",{className:"modal",onClick:()=>x(!1),children:[k.jsx("img",{src:`data:image/png;base64,${t.eye.png}`,alt:"",style:m3(t.eye.width,t.eye.height)}),k.jsx("div",{className:"dim",children:t.eye.path})]})]})}const v3=new URLSearchParams(location.search).get("token")??"",fd=new c3;fd.connect(v3);window.pixelclaw=fd;u$.createRoot(document.getElementById("root")).render(k.jsx(he.StrictMode,{children:k.jsx(w3,{store:fd})}));
|