@roudanio/maze 0.3.1 → 0.3.2
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 +1 -0
- package/dist/maze.iife.js +1 -1
- package/dist/maze.js +72 -69
- package/dist/maze.umd.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,6 +26,7 @@ The game includes a fog of war effect.
|
|
|
26
26
|
- **Configuration**:
|
|
27
27
|
- **Global**: Modify `defaultRenderConfig.fogRadius` in `src/utils/utils.ts`.
|
|
28
28
|
- **Per Level**: Add `fogRadius` to the level config object in `LEVEL_CONFIG`.
|
|
29
|
+
- **Toggle**: Use `fogEnabled` in `LevelConfig` to enable/disable fog for specific levels.
|
|
29
30
|
|
|
30
31
|
## Testing
|
|
31
32
|
|
package/dist/maze.iife.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var Maze=(function(){"use strict";var le,N,Ie,H,Fe,Re,De,Oe,ye,be,Te,$e,te={},Ue=[],Mt=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,ce=Array.isArray;function B(e,t){for(var n in t)e[n]=t[n];return e}function Se(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function Lt(e,t,n){var o,i,s,a={};for(s in t)s=="key"?o=t[s]:s=="ref"?i=t[s]:a[s]=t[s];if(arguments.length>2&&(a.children=arguments.length>3?le.call(arguments,2):n),typeof e=="function"&&e.defaultProps!=null)for(s in e.defaultProps)a[s]===void 0&&(a[s]=e.defaultProps[s]);return ue(e,a,o,i,null)}function ue(e,t,n,o,i){var s={type:e,props:t,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++Ie,__i:-1,__u:0};return i==null&&N.vnode!=null&&N.vnode(s),s}function de(e){return e.children}function he(e,t){this.props=e,this.context=t}function K(e,t){if(t==null)return e.__?K(e.__,e.__i+1):null;for(var n;t<e.__k.length;t++)if((n=e.__k[t])!=null&&n.__e!=null)return n.__e;return typeof e.type=="function"?K(e):null}function Ge(e){var t,n;if((e=e.__)!=null&&e.__c!=null){for(e.__e=e.__c.base=null,t=0;t<e.__k.length;t++)if((n=e.__k[t])!=null&&n.__e!=null){e.__e=e.__c.base=n.__e;break}return Ge(e)}}function ke(e){(!e.__d&&(e.__d=!0)&&H.push(e)&&!fe.__r++||Fe!=N.debounceRendering)&&((Fe=N.debounceRendering)||Re)(fe)}function fe(){for(var e,t,n,o,i,s,a,r=1;H.length;)H.length>r&&H.sort(De),e=H.shift(),r=H.length,e.__d&&(n=void 0,o=void 0,i=(o=(t=e).__v).__e,s=[],a=[],t.__P&&((n=B({},o)).__v=o.__v+1,N.vnode&&N.vnode(n),Ee(t.__P,n,o,t.__n,t.__P.namespaceURI,32&o.__u?[i]:null,s,i??K(o),!!(32&o.__u),a),n.__v=o.__v,n.__.__k[n.__i]=n,Ve(s,n,a),o.__e=o.__=null,n.__e!=i&&Ge(n)));fe.__r=0}function je(e,t,n,o,i,s,a,r,c,l,d){var u,h,f,m,g,v,w,y=o&&o.__k||Ue,T=t.length;for(c=Nt(n,t,y,c,T),u=0;u<T;u++)(f=n.__k[u])!=null&&(h=f.__i==-1?te:y[f.__i]||te,f.__i=u,v=Ee(e,f,h,i,s,a,r,c,l,d),m=f.__e,f.ref&&h.ref!=f.ref&&(h.ref&&Me(h.ref,null,f),d.push(f.ref,f.__c||m,f)),g==null&&m!=null&&(g=m),(w=!!(4&f.__u))||h.__k===f.__k?c=We(f,c,e,w):typeof f.type=="function"&&v!==void 0?c=v:m&&(c=m.nextSibling),f.__u&=-7);return n.__e=g,c}function Nt(e,t,n,o,i){var s,a,r,c,l,d=n.length,u=d,h=0;for(e.__k=new Array(i),s=0;s<i;s++)(a=t[s])!=null&&typeof a!="boolean"&&typeof a!="function"?(c=s+h,(a=e.__k[s]=typeof a=="string"||typeof a=="number"||typeof a=="bigint"||a.constructor==String?ue(null,a,null,null,null):ce(a)?ue(de,{children:a},null,null,null):a.constructor==null&&a.__b>0?ue(a.type,a.props,a.key,a.ref?a.ref:null,a.__v):a).__=e,a.__b=e.__b+1,r=null,(l=a.__i=At(a,n,c,u))!=-1&&(u--,(r=n[l])&&(r.__u|=2)),r==null||r.__v==null?(l==-1&&(i>d?h--:i<d&&h++),typeof a.type!="function"&&(a.__u|=4)):l!=c&&(l==c-1?h--:l==c+1?h++:(l>c?h--:h++,a.__u|=4))):e.__k[s]=null;if(u)for(s=0;s<d;s++)(r=n[s])!=null&&(2&r.__u)==0&&(r.__e==o&&(o=K(r)),Xe(r,r));return o}function We(e,t,n,o){var i,s;if(typeof e.type=="function"){for(i=e.__k,s=0;i&&s<i.length;s++)i[s]&&(i[s].__=e,t=We(i[s],t,n,o));return t}e.__e!=t&&(o&&(t&&e.type&&!t.parentNode&&(t=K(e)),n.insertBefore(e.__e,t||null)),t=e.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function At(e,t,n,o){var i,s,a,r=e.key,c=e.type,l=t[n],d=l!=null&&(2&l.__u)==0;if(l===null&&e.key==null||d&&r==l.key&&c==l.type)return n;if(o>(d?1:0)){for(i=n-1,s=n+1;i>=0||s<t.length;)if((l=t[a=i>=0?i--:s++])!=null&&(2&l.__u)==0&&r==l.key&&c==l.type)return a}return-1}function qe(e,t,n){t[0]=="-"?e.setProperty(t,n??""):e[t]=n==null?"":typeof n!="number"||Mt.test(t)?n:n+"px"}function me(e,t,n,o,i){var s,a;e:if(t=="style")if(typeof n=="string")e.style.cssText=n;else{if(typeof o=="string"&&(e.style.cssText=o=""),o)for(t in o)n&&t in n||qe(e.style,t,"");if(n)for(t in n)o&&n[t]==o[t]||qe(e.style,t,n[t])}else if(t[0]=="o"&&t[1]=="n")s=t!=(t=t.replace(Oe,"$1")),a=t.toLowerCase(),t=a in e||t=="onFocusOut"||t=="onFocusIn"?a.slice(2):t.slice(2),e.l||(e.l={}),e.l[t+s]=n,n?o?n.u=o.u:(n.u=ye,e.addEventListener(t,s?Te:be,s)):e.removeEventListener(t,s?Te:be,s);else{if(i=="http://www.w3.org/2000/svg")t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(t!="width"&&t!="height"&&t!="href"&&t!="list"&&t!="form"&&t!="tabIndex"&&t!="download"&&t!="rowSpan"&&t!="colSpan"&&t!="role"&&t!="popover"&&t in e)try{e[t]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&t[4]!="-"?e.removeAttribute(t):e.setAttribute(t,t=="popover"&&n==1?"":n))}}function Be(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t.t==null)t.t=ye++;else if(t.t<n.u)return;return n(N.event?N.event(t):t)}}}function Ee(e,t,n,o,i,s,a,r,c,l){var d,u,h,f,m,g,v,w,y,T,p,z,C,S,k,L,E,M=t.type;if(t.constructor!=null)return null;128&n.__u&&(c=!!(32&n.__u),s=[r=t.__e=n.__e]),(d=N.__b)&&d(t);e:if(typeof M=="function")try{if(w=t.props,y="prototype"in M&&M.prototype.render,T=(d=M.contextType)&&o[d.__c],p=d?T?T.props.value:d.__:o,n.__c?v=(u=t.__c=n.__c).__=u.__E:(y?t.__c=u=new M(w,p):(t.__c=u=new he(w,p),u.constructor=M,u.render=xt),T&&T.sub(u),u.props=w,u.state||(u.state={}),u.context=p,u.__n=o,h=u.__d=!0,u.__h=[],u._sb=[]),y&&u.__s==null&&(u.__s=u.state),y&&M.getDerivedStateFromProps!=null&&(u.__s==u.state&&(u.__s=B({},u.__s)),B(u.__s,M.getDerivedStateFromProps(w,u.__s))),f=u.props,m=u.state,u.__v=t,h)y&&M.getDerivedStateFromProps==null&&u.componentWillMount!=null&&u.componentWillMount(),y&&u.componentDidMount!=null&&u.__h.push(u.componentDidMount);else{if(y&&M.getDerivedStateFromProps==null&&w!==f&&u.componentWillReceiveProps!=null&&u.componentWillReceiveProps(w,p),!u.__e&&u.shouldComponentUpdate!=null&&u.shouldComponentUpdate(w,u.__s,p)===!1||t.__v==n.__v){for(t.__v!=n.__v&&(u.props=w,u.state=u.__s,u.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(b){b&&(b.__=t)}),z=0;z<u._sb.length;z++)u.__h.push(u._sb[z]);u._sb=[],u.__h.length&&a.push(u);break e}u.componentWillUpdate!=null&&u.componentWillUpdate(w,u.__s,p),y&&u.componentDidUpdate!=null&&u.__h.push(function(){u.componentDidUpdate(f,m,g)})}if(u.context=p,u.props=w,u.__P=e,u.__e=!1,C=N.__r,S=0,y){for(u.state=u.__s,u.__d=!1,C&&C(t),d=u.render(u.props,u.state,u.context),k=0;k<u._sb.length;k++)u.__h.push(u._sb[k]);u._sb=[]}else do u.__d=!1,C&&C(t),d=u.render(u.props,u.state,u.context),u.state=u.__s;while(u.__d&&++S<25);u.state=u.__s,u.getChildContext!=null&&(o=B(B({},o),u.getChildContext())),y&&!h&&u.getSnapshotBeforeUpdate!=null&&(g=u.getSnapshotBeforeUpdate(f,m)),L=d,d!=null&&d.type===de&&d.key==null&&(L=He(d.props.children)),r=je(e,ce(L)?L:[L],t,n,o,i,s,a,r,c,l),u.base=t.__e,t.__u&=-161,u.__h.length&&a.push(u),v&&(u.__E=u.__=null)}catch(b){if(t.__v=null,c||s!=null)if(b.then){for(t.__u|=c?160:128;r&&r.nodeType==8&&r.nextSibling;)r=r.nextSibling;s[s.indexOf(r)]=null,t.__e=r}else{for(E=s.length;E--;)Se(s[E]);ze(t)}else t.__e=n.__e,t.__k=n.__k,b.then||ze(t);N.__e(b,t,n)}else s==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):r=t.__e=Pt(n.__e,t,n,o,i,s,a,c,l);return(d=N.diffed)&&d(t),128&t.__u?void 0:r}function ze(e){e&&e.__c&&(e.__c.__e=!0),e&&e.__k&&e.__k.forEach(ze)}function Ve(e,t,n){for(var o=0;o<n.length;o++)Me(n[o],n[++o],n[++o]);N.__c&&N.__c(t,e),e.some(function(i){try{e=i.__h,i.__h=[],e.some(function(s){s.call(i)})}catch(s){N.__e(s,i.__v)}})}function He(e){return typeof e!="object"||e==null||e.__b&&e.__b>0?e:ce(e)?e.map(He):B({},e)}function Pt(e,t,n,o,i,s,a,r,c){var l,d,u,h,f,m,g,v=n.props,w=t.props,y=t.type;if(y=="svg"?i="http://www.w3.org/2000/svg":y=="math"?i="http://www.w3.org/1998/Math/MathML":i||(i="http://www.w3.org/1999/xhtml"),s!=null){for(l=0;l<s.length;l++)if((f=s[l])&&"setAttribute"in f==!!y&&(y?f.localName==y:f.nodeType==3)){e=f,s[l]=null;break}}if(e==null){if(y==null)return document.createTextNode(w);e=document.createElementNS(i,y,w.is&&w),r&&(N.__m&&N.__m(t,s),r=!1),s=null}if(y==null)v===w||r&&e.data==w||(e.data=w);else{if(s=s&&le.call(e.childNodes),v=n.props||te,!r&&s!=null)for(v={},l=0;l<e.attributes.length;l++)v[(f=e.attributes[l]).name]=f.value;for(l in v)if(f=v[l],l!="children"){if(l=="dangerouslySetInnerHTML")u=f;else if(!(l in w)){if(l=="value"&&"defaultValue"in w||l=="checked"&&"defaultChecked"in w)continue;me(e,l,null,f,i)}}for(l in w)f=w[l],l=="children"?h=f:l=="dangerouslySetInnerHTML"?d=f:l=="value"?m=f:l=="checked"?g=f:r&&typeof f!="function"||v[l]===f||me(e,l,f,v[l],i);if(d)r||u&&(d.__html==u.__html||d.__html==e.innerHTML)||(e.innerHTML=d.__html),t.__k=[];else if(u&&(e.innerHTML=""),je(t.type=="template"?e.content:e,ce(h)?h:[h],t,n,o,y=="foreignObject"?"http://www.w3.org/1999/xhtml":i,s,a,s?s[0]:n.__k&&K(n,0),r,c),s!=null)for(l=s.length;l--;)Se(s[l]);r||(l="value",y=="progress"&&m==null?e.removeAttribute("value"):m!=null&&(m!==e[l]||y=="progress"&&!m||y=="option"&&m!=v[l])&&me(e,l,m,v[l],i),l="checked",g!=null&&g!=e[l]&&me(e,l,g,v[l],i))}return e}function Me(e,t,n){try{if(typeof e=="function"){var o=typeof e.__u=="function";o&&e.__u(),o&&t==null||(e.__u=e(t))}else e.current=t}catch(i){N.__e(i,n)}}function Xe(e,t,n){var o,i;if(N.unmount&&N.unmount(e),(o=e.ref)&&(o.current&&o.current!=e.__e||Me(o,null,t)),(o=e.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(s){N.__e(s,t)}o.base=o.__P=null}if(o=e.__k)for(i=0;i<o.length;i++)o[i]&&Xe(o[i],t,n||typeof e.type!="function");n||Se(e.__e),e.__c=e.__=e.__e=void 0}function xt(e,t,n){return this.constructor(e,n)}function Ye(e,t,n){var o,i,s,a;t==document&&(t=document.documentElement),N.__&&N.__(e,t),i=(o=!1)?null:t.__k,s=[],a=[],Ee(t,e=t.__k=Lt(de,null,[e]),i||te,te,t.namespaceURI,i?null:t.firstChild?le.call(t.childNodes):null,s,i?i.__e:t.firstChild,o,a),Ve(s,e,a)}function It(e){function t(n){var o,i;return this.getChildContext||(o=new Set,(i={})[t.__c]=this,this.getChildContext=function(){return i},this.componentWillUnmount=function(){o=null},this.shouldComponentUpdate=function(s){this.props.value!=s.value&&o.forEach(function(a){a.__e=!0,ke(a)})},this.sub=function(s){o.add(s);var a=s.componentWillUnmount;s.componentWillUnmount=function(){o&&o.delete(s),a&&a.call(s)}}),n.children}return t.__c="__cC"+$e++,t.__=e,t.Provider=t.__l=(t.Consumer=function(n,o){return n.children(o)}).contextType=t,t}le=Ue.slice,N={__e:function(e,t,n,o){for(var i,s,a;t=t.__;)if((i=t.__c)&&!i.__)try{if((s=i.constructor)&&s.getDerivedStateFromError!=null&&(i.setState(s.getDerivedStateFromError(e)),a=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(e,o||{}),a=i.__d),a)return i.__E=i}catch(r){e=r}throw e}},Ie=0,he.prototype.setState=function(e,t){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=B({},this.state),typeof e=="function"&&(e=e(B({},n),this.props)),e&&B(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),ke(this))},he.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),ke(this))},he.prototype.render=de,H=[],Re=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,De=function(e,t){return e.__v.__b-t.__v.__b},fe.__r=0,Oe=/(PointerCapture)$|Capture$/i,ye=0,be=Be(!1),Te=Be(!0),$e=0;var Ft=0;function _(e,t,n,o,i,s){t||(t={});var a,r,c=t;if("ref"in c)for(r in c={},t)r=="ref"?a=t[r]:c[r]=t[r];var l={type:e,props:c,key:n,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Ft,__i:-1,__u:0,__source:i,__self:s};if(typeof e=="function"&&(a=e.defaultProps))for(r in a)c[r]===void 0&&(c[r]=a[r]);return N.vnode&&N.vnode(l),l}var J,P,Le,Ke,ne=0,Je=[],D=N,Qe=D.__b,Ze=D.__r,et=D.diffed,tt=D.__c,nt=D.unmount,ot=D.__;function _e(e,t){D.__h&&D.__h(P,e,ne||t),ne=0;var n=P.__H||(P.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function U(e){return ne=1,Rt(at,e)}function Rt(e,t,n){var o=_e(J++,2);if(o.t=e,!o.__c&&(o.__=[at(void 0,t),function(r){var c=o.__N?o.__N[0]:o.__[0],l=o.t(c,r);c!==l&&(o.__N=[l,o.__[1]],o.__c.setState({}))}],o.__c=P,!P.__f)){var i=function(r,c,l){if(!o.__c.__H)return!0;var d=o.__c.__H.__.filter(function(h){return!!h.__c});if(d.every(function(h){return!h.__N}))return!s||s.call(this,r,c,l);var u=o.__c.props!==r;return d.forEach(function(h){if(h.__N){var f=h.__[0];h.__=h.__N,h.__N=void 0,f!==h.__[0]&&(u=!0)}}),s&&s.call(this,r,c,l)||u};P.__f=!0;var s=P.shouldComponentUpdate,a=P.componentWillUpdate;P.componentWillUpdate=function(r,c,l){if(this.__e){var d=s;s=void 0,i(r,c,l),s=d}a&&a.call(this,r,c,l)},P.shouldComponentUpdate=i}return o.__N||o.__}function I(e,t){var n=_e(J++,3);!D.__s&&st(n.__H,t)&&(n.__=e,n.u=t,P.__H.__h.push(n))}function R(e){return ne=5,Q(function(){return{current:e}},[])}function Q(e,t){var n=_e(J++,7);return st(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function rt(e,t){return ne=8,Q(function(){return e},t)}function Dt(e){var t=P.context[e.__c],n=_e(J++,9);return n.c=e,t?(n.__==null&&(n.__=!0,t.sub(P)),t.props.value):e.__}function Ot(){for(var e;e=Je.shift();)if(e.__P&&e.__H)try{e.__H.__h.forEach(ve),e.__H.__h.forEach(Ne),e.__H.__h=[]}catch(t){e.__H.__h=[],D.__e(t,e.__v)}}D.__b=function(e){P=null,Qe&&Qe(e)},D.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),ot&&ot(e,t)},D.__r=function(e){Ze&&Ze(e),J=0;var t=(P=e.__c).__H;t&&(Le===P?(t.__h=[],P.__h=[],t.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.forEach(ve),t.__h.forEach(Ne),t.__h=[],J=0)),Le=P},D.diffed=function(e){et&&et(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(Je.push(t)!==1&&Ke===D.requestAnimationFrame||((Ke=D.requestAnimationFrame)||$t)(Ot)),t.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),Le=P=null},D.__c=function(e,t){t.some(function(n){try{n.__h.forEach(ve),n.__h=n.__h.filter(function(o){return!o.__||Ne(o)})}catch(o){t.some(function(i){i.__h&&(i.__h=[])}),t=[],D.__e(o,n.__v)}}),tt&&tt(e,t)},D.unmount=function(e){nt&&nt(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.forEach(function(o){try{ve(o)}catch(i){t=i}}),n.__H=void 0,t&&D.__e(t,n.__v))};var it=typeof requestAnimationFrame=="function";function $t(e){var t,n=function(){clearTimeout(o),it&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(n,35);it&&(t=requestAnimationFrame(n))}function ve(e){var t=P,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),P=t}function Ne(e){var t=P;e.__c=e.__(),P=t}function st(e,t){return!e||e.length!==t.length||t.some(function(n,o){return n!==e[o]})}function at(e,t){return typeof t=="function"?t(e):t}const Ut=e=>({saveGameData(t){try{localStorage.setItem(e,JSON.stringify(t))}catch(n){console.error("Failed to save maze game data:",n)}},loadGameData(){try{const t=localStorage.getItem(e);return t?JSON.parse(t):null}catch(t){return console.error("Failed to load maze game data:",t),null}},resetGameData(){try{localStorage.removeItem(e)}catch(t){console.error("Failed to reset maze game data:",t)}}}),lt=It(void 0),ct={currentLevel:1,highestUnlockedLevel:1,currentTier:1,highestUnlockedTier:1,levelScores:{},totalScore:0},ut={isGameActive:!0,levelTransitioning:!1,maze:null,playerCell:{row:0,col:0},exitCell:{row:0,col:0},foodCells:[],fogEnabled:!0,playerAtExit:!1,foodCollected:0,totalFoodCount:0,showClue:!1,playerPath:[],visitCounts:{}},Gt=({children:e,config:t})=>{const n=Ut(t.lcPrefix+"progress"),o=n.loadGameData(),i=t.renderConfig?.fogEnabled??!0,s=()=>({...ut,fogEnabled:i}),[a,r]=U(()=>o||{...ct});I(()=>{const f=Object.values(a.levelScores).reduce((m,g)=>m+g,0);r(m=>({...m,totalScore:f}))},[a.levelScores]),I(()=>{n.saveGameData(a)},[a.currentLevel,a.highestUnlockedLevel,a.currentTier,a.highestUnlockedTier,a.levelScores,a.totalScore]);const[c,l]=U({...s()}),d=R(c);I(()=>{d.current=c},[c]);const u=Q(()=>[c.playerAtExit?1:0,c.foodCollected===c.totalFoodCount?1:0,c.showClue?0:1],[c.playerAtExit,c.foodCollected,c.totalFoodCount,c.showClue]),h=()=>{n.resetGameData(),r({...ct}),l({...s()})};return _(lt.Provider,{value:{gameProgress:a,setGameProgress:r,gamePlayState:c,setGamePlayState:l,gamePlayStateRef:d,currentScore:u,config:t,resetGame:h},children:e})},oe=()=>{const e=Dt(lt);if(!e)throw new Error("useGameContext must be used within a GameProvider");return e},re=e=>Q(()=>{const t=e.map(r=>r.length),n=t.reduce((r,c)=>r+c,0),o=e.length,i=r=>{if(r<1||r>n)return 0;let c=0;for(let l=0;l<t.length;l++)if(c+=t[l],r<=c)return l+1;return 0},s=r=>r<1||r>o?0:t.slice(0,r-1).reduce((c,l)=>c+l,0)+1,a={getTotalLevels:()=>n,getTotalTiers:()=>o,getTierLevelsRange:r=>{if(r<1||r>o)return[0,0];const c=s(r),l=c+t[r-1]-1;return[c,l]},getTierByLevel:i,getFirstLevelOfTier:s,getLevelConfig:r=>{if(r<1||r>n)return null;const c=i(r),l=s(c),d=r-l;return e[c-1][d]},getTierConfig:r=>r<1||r>o?null:e[r-1],isLevelUnlocked:(r,c)=>r<=c,isTierUnlocked:(r,c)=>r<=c,getNextLevelInfo:r=>{if(r>=n)return null;const c=r+1,l=i(r),d=i(c);return{nextLevel:c,nextTier:d,isTierChange:d>l}},getCurrentTierProgress:(r,c)=>{const[l,d]=a.getTierLevelsRange(c),u=r-l+1,h=d-l+1;return{current:u,total:h}},isLastLevelInTier:r=>{const c=i(r),[,l]=a.getTierLevelsRange(c);return r===l},getPreviousLevelInfo:r=>{if(r<=1)return null;const c=r-1,l=i(r),d=i(c);return{prevLevel:c,prevTier:d,isTierChange:d<l}}};return a},[e]),jt=({onTierChange:e,disabled:t})=>{const{gameProgress:n,config:o}=oe(),{i18n:i,levelConfig:s}=o,{currentTier:a,highestUnlockedTier:r}=n,l=re(s).getTotalTiers();return _("div",{className:"tier-selector",children:_("select",{value:a,onChange:d=>{d.target&&d.target.value&&e(Number(d.target.value))},disabled:t,className:"tier-dropdown",children:Array.from({length:l},(d,u)=>u+1).map(d=>_("option",{value:d,disabled:d>r,children:i.tier+" "+d},`tier-${d}`))})})},Wt=({onLevelChange:e,disabled:t})=>{const{gameProgress:n,config:o}=oe(),{i18n:i,levelConfig:s}=o,{currentTier:a,levelScores:r,currentLevel:c,highestUnlockedLevel:l}=n,d=re(s),u=Q(()=>{const[h,f]=d.getTierLevelsRange(a);return Array.from({length:f-h+1},(m,g)=>{const v=h+g,w=r[v]||0;return{level:v,score:w}})},[a,r]);return _("div",{className:"level-selector",children:_("select",{value:c,onChange:h=>{h.target&&h.target.value&&e(Number(h.target.value))},disabled:t,className:"level-dropdown",children:u.map(({level:h,score:f})=>_("option",{value:h,disabled:h>l,children:`${i.level} ${h} ${"★".repeat(f)}`},`level-${h}`))})})},ie=({isOpen:e,title:t,className:n="",message:o,children:i,noConfirm:s=!1,noCancel:a=!1,confirmText:r="OK",cancelText:c="Cancel",confirmClass:l="",cancelClass:d="",onConfirm:u,onCancel:h})=>{const f=R(null);return I(()=>{const m=g=>{g.key==="Escape"&&h?.()};return e&&document.addEventListener("keydown",m),()=>{document.removeEventListener("keydown",m)}},[e,h]),_("div",{className:`maze-dialog-overlay ${e?"maze-dialog-visible":""}`,children:_("div",{className:"maze-dialog "+n,ref:f,children:[_("div",{className:"maze-dialog-title",children:t}),_("div",{className:"maze-dialog-content",children:i||_("div",{className:"maze-dialog-message",children:o})}),(!a||!s)&&_("div",{className:"maze-dialog-buttons",children:[!a&&_("button",{type:"button",className:"maze-dialog-cancel "+d,onClick:h,children:c}),!s&&_("button",{type:"button",className:"maze-dialog-confirm "+l,onClick:u,children:r})]})]})})},j={container:null,attachTo(e){return this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.container=document.createElement("div"),this.container.className="toast-container position-bottom",e.appendChild(this.container),this.container},currentToast:null,currentTimer:null,show(e,t=2e3){if(!this.container){console.warn("NativeToast: container not initialized, please call attachTo first");return}this.currentToast&&this.container.contains(this.currentToast)&&(this.container.removeChild(this.currentToast),this.currentToast=null),this.currentTimer&&(clearTimeout(this.currentTimer),this.currentTimer=null);const n=document.createElement("div");n.className="toast-message toast-visible",n.textContent=e,this.container.appendChild(n),this.currentToast=n,this.currentTimer=setTimeout(()=>{n.classList.remove("toast-visible"),setTimeout(()=>{this.container&&this.container.contains(n)&&(this.container.removeChild(n),this.currentToast===n&&(this.currentToast=null))},300),this.currentTimer=null},t)},clearAll(){if(this.container)for(;this.container.firstChild;)this.container.removeChild(this.container.firstChild)}},qt=()=>{const{gameProgress:e,setGameProgress:t,gamePlayState:n,setGamePlayState:o,gamePlayStateRef:i,resetGame:s,config:a}=oe(),{i18n:r,levelConfig:c}=a,l=re(c),{levelTransitioning:d,showClue:u}=n,{highestUnlockedLevel:h,totalScore:f}=e,m=l.getTotalLevels(),[g,v]=U(!1),[w,y]=U(!1),[T,p]=U(!1),z=O=>{const $=l.getFirstLevelOfTier(O);l.isLevelUnlocked($,h)&&(t(G=>({...G,currentTier:O})),C($))},C=O=>{l.isLevelUnlocked(O,h)&&(t($=>({...$,currentLevel:O})),j.show(r.levelGoToast.replace("%LEVEL%",O.toString())))},S=()=>{v(!0)},k=()=>{v(!1)},L=()=>{p(!0)},E=()=>{p(!1)},M=()=>{j.show(u?r.cluePathDisabled:r.cluePathEnabled),o(()=>({...i.current,showClue:!i.current.showClue})),p(!1)},b=()=>{y(!0)},A=()=>{s(),y(!1),j.show(r.resetDoneToast)},x=()=>{y(!1)};return _("div",{class:"game-panel-container",children:[_("div",{className:"game-controls",children:[_("div",{className:"selectors-container",children:[_(jt,{onTierChange:z,disabled:d}),_(Wt,{onLevelChange:C,disabled:d})]}),_("button",{className:`settings-clue-button ${u?"clue-on":"clue-off"}`,disabled:u,title:"Toggle Clue",onClick:L,children:u?r.clueOn:r.clueOff})]}),_("div",{className:"game-settings",children:_("span",{className:"game-settings-icon",onClick:S,children:"★ "+f})}),_(ie,{isOpen:g,title:r.settings,noConfirm:!0,cancelText:r.close,onCancel:k,children:[_("div",{className:"settings-stats",children:[_("div",{children:r.levelComplete+`: ${h}/${m}`}),_("div",{children:r.starsCollected+": "+f}),_("div",{children:r.avgStarPerLevel+": "+(f/h).toFixed(2)})]}),_("div",{className:"settings-item-box",children:[_("button",{className:"settings-reset-button",title:"Reset Game",onClick:b,children:r.reset}),_("div",{className:"settings-item-tip",children:r.resetTip})]})]}),_(ie,{isOpen:w,title:r.confirmReset,message:r.confirmResetMessage,confirmText:r.reset,cancelText:r.cancel,onConfirm:A,onCancel:x}),_(ie,{isOpen:T,title:r.confirmClue,message:r.confirmClueMessage,confirmText:r.confirm,cancelText:r.cancel,onConfirm:M,onCancel:E})]})};function Ae(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Bt(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function Pe(e,t,n){return t&&Bt(e.prototype,t),e}function dt(e){return+e.replace(/px/,"")}function Vt(e){var t=window.devicePixelRatio,n=getComputedStyle(e),o=dt(n.getPropertyValue("width")),i=dt(n.getPropertyValue("height"));e.setAttribute("width",(o*t).toString()),e.setAttribute("height",(i*t).toString())}function W(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,o=Math.random()*(t-e)+e;return Math.floor(o*Math.pow(10,n))/Math.pow(10,n)}function ht(e){return e[W(0,e.length)]}var Ht=.00125,Xt=5e-4,Yt=9e-4,Kt=1e-5,Jt=6,Qt=80,Zt=.9,en=1.7,tn=.2,nn=.6,on=.03,rn=.07,ft=15,mt=82,sn=100,an=250,ln=40,cn=["#fcf403","#62fc03","#f4fc03","#03e7fc","#03fca5","#a503fc","#fc03ad","#fc03c2"];function _t(e){var t=1920;return Math.log(e)/Math.log(t)}var vt=(function(){function e(t){Ae(this,e);var n=t.initialPosition,o=t.direction,i=t.confettiRadius,s=t.confettiColors,a=t.emojis,r=t.emojiSize,c=t.canvasWidth,l=W(Zt,en,3),d=l*_t(c);this.confettiSpeed={x:d,y:d},this.finalConfettiSpeedX=W(tn,nn,3),this.rotationSpeed=a.length?.01:W(on,rn,3)*_t(c),this.dragForceCoefficient=W(Xt,Yt,6),this.radius={x:i,y:i},this.initialRadius=i,this.rotationAngle=o==="left"?W(0,.2,3):W(-.2,0,3),this.emojiSize=r,this.emojiRotationAngle=W(0,2*Math.PI),this.radiusYUpdateDirection="down";var u=o==="left"?W(mt,ft)*Math.PI/180:W(-ft,-mt)*Math.PI/180;this.absCos=Math.abs(Math.cos(u)),this.absSin=Math.abs(Math.sin(u));var h=W(-150,0),f={x:n.x+(o==="left"?-h:h)*this.absCos,y:n.y-h*this.absSin};this.currentPosition=Object.assign({},f),this.initialPosition=Object.assign({},f),this.color=a.length?null:ht(s),this.emoji=a.length?ht(a):null,this.createdAt=new Date().getTime(),this.direction=o}return Pe(e,[{key:"draw",value:function(n){var o=this.currentPosition,i=this.radius,s=this.color,a=this.emoji,r=this.rotationAngle,c=this.emojiRotationAngle,l=this.emojiSize,d=window.devicePixelRatio;s?(n.fillStyle=s,n.beginPath(),n.ellipse(o.x*d,o.y*d,i.x*d,i.y*d,r,0,2*Math.PI),n.fill()):a&&(n.font="".concat(l,"px serif"),n.save(),n.translate(d*o.x,d*o.y),n.rotate(c),n.textAlign="center",n.fillText(a,0,0),n.restore())}},{key:"updatePosition",value:function(n,o){var i=this.confettiSpeed,s=this.dragForceCoefficient,a=this.finalConfettiSpeedX,r=this.radiusYUpdateDirection,c=this.rotationSpeed,l=this.createdAt,d=this.direction,u=o-l;if(i.x>a&&(this.confettiSpeed.x-=s*n),this.currentPosition.x+=i.x*(d==="left"?-this.absCos:this.absCos)*n,this.currentPosition.y=this.initialPosition.y-i.y*this.absSin*u+Ht*Math.pow(u,2)/2,this.rotationSpeed-=this.emoji?1e-4:Kt*n,this.rotationSpeed<0&&(this.rotationSpeed=0),this.emoji){this.emojiRotationAngle+=this.rotationSpeed*n%(2*Math.PI);return}r==="down"?(this.radius.y-=n*c,this.radius.y<=0&&(this.radius.y=0,this.radiusYUpdateDirection="up")):(this.radius.y+=n*c,this.radius.y>=this.initialRadius&&(this.radius.y=this.initialRadius,this.radiusYUpdateDirection="down"))}},{key:"getIsVisibleOnCanvas",value:function(n){return this.currentPosition.y<n+sn}}]),e})();function un(){var e=document.createElement("canvas");return e.style.position="fixed",e.style.width="100%",e.style.height="100%",e.style.top="0",e.style.left="0",e.style.zIndex="1000",e.style.pointerEvents="none",document.body.appendChild(e),e}function dn(e){var t=e.confettiRadius,n=t===void 0?Jt:t,o=e.confettiNumber,i=o===void 0?e.confettiesNumber||(e.emojis?ln:an):o,s=e.confettiColors,a=s===void 0?cn:s,r=e.emojis,c=r===void 0?e.emojies||[]:r,l=e.emojiSize,d=l===void 0?Qt:l;return e.emojies&&console.error("emojies argument is deprecated, please use emojis instead"),e.confettiesNumber&&console.error("confettiesNumber argument is deprecated, please use confettiNumber instead"),{confettiRadius:n,confettiNumber:i,confettiColors:a,emojis:c,emojiSize:d}}var hn=(function(){function e(t){var n=this;Ae(this,e),this.canvasContext=t,this.shapes=[],this.promise=new Promise(function(o){return n.resolvePromise=o})}return Pe(e,[{key:"getBatchCompletePromise",value:function(){return this.promise}},{key:"addShapes",value:function(){var n;(n=this.shapes).push.apply(n,arguments)}},{key:"complete",value:function(){var n;return this.shapes.length?!1:((n=this.resolvePromise)===null||n===void 0||n.call(this),!0)}},{key:"processShapes",value:function(n,o,i){var s=this,a=n.timeDelta,r=n.currentTime;this.shapes=this.shapes.filter(function(c){return c.updatePosition(a,r),c.draw(s.canvasContext),i?c.getIsVisibleOnCanvas(o):!0})}}]),e})(),fn=(function(){function e(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Ae(this,e),this.activeConfettiBatches=[],this.canvas=t.canvas||un(),this.canvasContext=this.canvas.getContext("2d"),this.requestAnimationFrameRequested=!1,this.lastUpdated=new Date().getTime(),this.iterationIndex=0,this.loop=this.loop.bind(this),requestAnimationFrame(this.loop)}return Pe(e,[{key:"loop",value:function(){this.requestAnimationFrameRequested=!1,Vt(this.canvas);var n=new Date().getTime(),o=n-this.lastUpdated,i=this.canvas.offsetHeight,s=this.iterationIndex%10===0;this.activeConfettiBatches=this.activeConfettiBatches.filter(function(a){return a.processShapes({timeDelta:o,currentTime:n},i,s),s?!a.complete():!0}),this.iterationIndex++,this.queueAnimationFrameIfNeeded(n)}},{key:"queueAnimationFrameIfNeeded",value:function(n){this.requestAnimationFrameRequested||this.activeConfettiBatches.length<1||(this.requestAnimationFrameRequested=!0,this.lastUpdated=n||new Date().getTime(),requestAnimationFrame(this.loop))}},{key:"addConfetti",value:function(){for(var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},o=dn(n),i=o.confettiRadius,s=o.confettiNumber,a=o.confettiColors,r=o.emojis,c=o.emojiSize,l=this.canvas.getBoundingClientRect(),d=l.width,u=l.height,h=u*5/7,f={x:0,y:h},m={x:d,y:h},g=new hn(this.canvasContext),v=0;v<s/2;v++){var w=new vt({initialPosition:f,direction:"right",confettiRadius:i,confettiColors:a,confettiNumber:s,emojis:r,emojiSize:c,canvasWidth:d}),y=new vt({initialPosition:m,direction:"left",confettiRadius:i,confettiColors:a,confettiNumber:s,emojis:r,emojiSize:c,canvasWidth:d});g.addShapes(w,y)}return this.activeConfettiBatches.push(g),this.queueAnimationFrameIfNeeded(),g.getBatchCompletePromise()}},{key:"clearCanvas",value:function(){this.activeConfettiBatches=[]}},{key:"destroyCanvas",value:function(){this.canvas.remove()}}]),e})();const mn=new fn,xe=3,_n=({onRetry:e})=>{const{config:t,currentScore:n,gamePlayState:o,setGamePlayState:i,gameProgress:s,setGameProgress:a}=oe(),{i18n:r,levelConfig:c}=t,[l,d,u]=n,{foodCollected:h,totalFoodCount:f,playerAtExit:m,levelTransitioning:g}=o,{currentLevel:v}=s,[w,y]=U(!1);I(()=>{m&&g&&(mn.addConfetti(),j.show(r.levelCompleteToast),y(!0))},[m,g]);const T=re(c),p=T.getTotalLevels(),z=Q(()=>v>=p,[v,p]),C=()=>{y(!1),j.show(r.levelRestartToast),e?.()},S=()=>{y(!1),i(E=>({...E,isGameActive:!0,levelTransitioning:!1}))},k=()=>{y(!1);const E=T.getNextLevelInfo(v);if(!E)return;const{nextLevel:M,nextTier:b,isTierChange:A}=E;A&&j.show(r.tierUnlockedToast.replace("%TIER%",b.toString())),a(x=>({...x,currentLevel:M,currentTier:b,highestUnlockedLevel:Math.max(x.highestUnlockedLevel,M),highestUnlockedTier:Math.max(x.highestUnlockedTier,b),levelScores:{...x.levelScores,[x.currentLevel]:Math.max(Object.values(n).filter(Boolean).length,x.levelScores[x.currentLevel]||0)}}))},L=()=>{y(!1),a(E=>{const M=Math.max(Object.values(n).filter(Boolean).length,E.levelScores[E.currentLevel]||0),b={...E.levelScores,[E.currentLevel]:M};let A=0,x=0;const O=Object.entries(b).sort(($,G)=>Number($[0])-Number(G[0]));for(const[$,G]of O)if(G<xe){A=Number($),x=T.getTierByLevel(A);break}return(A>0&&A!==v||M<xe)&&j.show(r.notCompleteLevel),(A===0||M<xe)&&e?.(),{...E,currentLevel:A||E.currentLevel,currentTier:x||E.currentTier,levelScores:b}})};return I(()=>{const E=document.querySelector(".maze-game-container"),M=b=>{w&&((b.key===" "||b.code==="Space")&&E&&(E.contains(document.activeElement)||document.activeElement===document.body)&&(b.preventDefault(),z?L():k()),(b.key==="r"||b.code==="KeyR")&&C(),(b.key==="c"||b.code==="KeyC")&&S())};return window.addEventListener("keydown",M),()=>window.removeEventListener("keydown",M)},[w,z]),_(ie,{className:"level-complete-dialog",isOpen:w,title:r.congratulations,cancelText:r.retry+" (R)",onCancel:C,noConfirm:!!d,confirmText:r.continue+" (C)",onConfirm:S,confirmClass:"maze-continue-btn",children:[_("div",{className:"maze-summary-message",children:[!!l&&_("div",{children:"★ - "+r.findYourExit}),_("div",{children:u?"★ - "+r.withoutClue:"☆ - "+r.withClue}),_("div",{children:(d?"★ - "+r.collectAllStars:"☆ - "+r.notCollectAllStars)+` (${h}/${f})`})]}),z&&_("div",{className:"all-levels-completed",children:r.allLevelsCompleted}),_("div",{className:"maze-go-next",children:z?_("button",{className:"maze-go-next-btn",type:"button",onClick:L,children:[_("span",{children:r.lastOK}),_("span",{className:"spacebar-tip",children:`(${r.spacebarTip})`})]}):_("button",{className:"maze-go-next-btn",type:"button",onClick:k,children:[_("span",{children:r.nextLevel}),_("span",{className:"spacebar-tip",children:`(${r.spacebarTip})`})]})}),!d&&_("div",{className:"not-all-stars-collected",children:r.continueMessage})]})},gt=(e,t)=>{const n=R({canvasWidth:0,canvasHeight:0});return I(()=>{const o=()=>{const s=e.current;if(!s)return;const a=s.parentElement;if(!a)return;const r=a.clientWidth;if(r===0)return;const c=window.devicePixelRatio||1;s.style.width=`${r}px`,s.style.height=`${r}px`;const l=r*c,d=r*c;s.width=l,s.height=d,n.current={canvasWidth:l,canvasHeight:d},t?.()};o();let i=null;return window.ResizeObserver&&e.current&&(i=new ResizeObserver(o),i.observe(e.current.parentElement)),window.addEventListener("resize",o),()=>{window.removeEventListener("resize",o),i?.disconnect()}},[e,t]),n},pt=(e,t,n)=>{const o=R({cellWidth:0,cellHeight:0});return I(()=>{const i=()=>{const a=e.current,r=t.maze;if(!a||!r)return;const{rows:c,cols:l}=r;if(c<=0||l<=0)return;const d=(a.width-n*2)/l,u=(a.height-n*2)/c;o.current={cellWidth:d,cellHeight:u}};i();let s=null;return e.current&&window.ResizeObserver&&(s=new ResizeObserver(i),s.observe(e.current)),()=>{e.current&&s?.disconnect()}},[e,t.maze,n]),o},ge={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]},wt=({gamePlayStateRef:e,setGamePlayState:t,moveSpeed:n,moveSpeedRef:o,playerRadius:i,onFoodCollected:s,onExitReached:a,onFirstMove:r})=>{const c=()=>o?.current??n??.03,l=R(!1),d=R(new Set),u=R(!1),h=rt((T,p)=>{const z=e.current;if(!z.maze)return{canMove:!1,newCell:null};const C=c(),[S,k]=ge[T];if(Ct(p,S,k,i,C,z.maze))return{canMove:!1,newCell:null};const{row:E,col:M}=p,b=E+S*C,A=M+k*C,x=-.5,O=z.maze.rows,$=z.maze.cols;if(b<x||b>=O||A<x||A>=$)return{canMove:!1,newCell:null};const G=E<0?0:Math.floor(E),X=M<0?0:Math.floor(M),V=b<0?0:Math.floor(b),ee=A<0?0:Math.floor(A);return V!==G||ee!==X?z.maze.isValid(V,ee)?{canMove:!0,newCell:{row:V,col:ee}}:{canMove:!1,newCell:null}:{canMove:!0,newCell:null}},[i,c]),f=()=>{const T=e.current,{row:p,col:z}=T.playerCell,C=i*2,S=T.foodCells.findIndex(E=>Math.sqrt(Math.pow(p-E.row,2)+Math.pow(z-E.col,2))<C);S!==-1&&s&&(s(),e.current={...e.current,foodCollected:e.current.foodCollected+1,foodCells:e.current.foodCells.filter((E,M)=>M!==S)});const L=pn(T.playerCell,T.exitCell,T.maze);L&&!e.current.playerAtExit?(e.current={...e.current,playerAtExit:!0,isGameActive:!1,levelTransitioning:!0},a&&a(),requestIdleCallback(()=>{t(()=>({...e.current}))},{timeout:10})):!L&&e.current.playerAtExit&&(e.current={...e.current,playerAtExit:!1,isGameActive:!0,levelTransitioning:!1})},m=T=>{const p=e.current,z=Math.round(T.row),C=Math.round(T.col),S=p.playerPath[p.playerPath.length-1],k=S.row===z&&S.col===C,L=Math.abs(S.row-z),E=Math.abs(S.col-C);if((L===1&&E===0||L===0&&E===1)&&!k){const b=`${S.row},${S.col}-${z},${C}`;e.current={...e.current,playerPath:[...e.current.playerPath,{row:z,col:C}],visitCounts:{...e.current.visitCounts,[b]:(e.current.visitCounts[b]||0)+1}}}},g=()=>{if(l.current||d.current.size===0)return;const T=e.current;!T.playerCell||!Array.from(d.current).some(z=>{const{canMove:C}=h(z,T.playerCell);return C})||(!u.current&&r&&(u.current=!0,r()),l.current=!0)};I(()=>{const T=C=>{if(C.key==="ArrowUp"||C.key==="ArrowDown"||C.key==="ArrowLeft"||C.key==="ArrowRight"||C.key===" "){const S=document.activeElement;if(S&&(S.tagName==="INPUT"||S.tagName==="TEXTAREA"||S.getAttribute("contenteditable")==="true"))return;C.preventDefault()}},p=C=>{const S=C.key;if(!(S in ge))return;const k=document.activeElement;k&&(k.tagName==="INPUT"||k.tagName==="TEXTAREA"||k.getAttribute("contenteditable")==="true")||(C.preventDefault(),e.current.isGameActive&&(d.current.has(S)||(d.current.add(S),l.current||g())))},z=C=>{const S=C.key;if(!(S in ge))return;const k=document.activeElement;k&&(k.tagName==="INPUT"||k.tagName==="TEXTAREA"||k.getAttribute("contenteditable")==="true")||(C.preventDefault(),d.current.delete(S),d.current.size===0&&w())};return window.addEventListener("keydown",T,{capture:!0}),window.addEventListener("keydown",p),window.addEventListener("keyup",z),()=>{window.removeEventListener("keydown",T,{capture:!0}),window.removeEventListener("keydown",p),window.removeEventListener("keyup",z)}},[]);const v=rt(()=>{if(!l.current||d.current.size===0)return e.current.playerCell;const T=c(),p=e.current.playerCell;let z=0,C=0,S=0;for(const Y of d.current){const{canMove:F}=h(Y,p);if(F){const[q,se]=ge[Y];z+=q,C+=se,S++}}if(S===0)return e.current.playerCell;const k=Math.sqrt(z*z+C*C),L=k>0?z/k:0,E=k>0?C/k:0,M=Number((p.row+L*T).toFixed(2)),b=Number((p.col+E*T).toFixed(2)),A=M-p.row,x=b-p.col,O=Math.sqrt(A*A+x*x);if(O>0){const Y=A/O,F=x/O;if(Ct(p,Y,F,i,O,e.current.maze))return e.current.playerCell}e.current.playerCell={row:M,col:b},f();const $=p.row<0?0:Math.round(p.row),G=p.col<0?0:Math.round(p.col),X=M<0?0:Math.round(M),V=b<0?0:Math.round(b);return(X!==$||V!==G)&&m({row:X,col:V}),e.current.playerCell},[c,h]),w=()=>{l.current=!1,d.current.clear()};return{updatePlayerPos:v,resetMovingState:w,resetFirstMoveState:()=>{u.current=!1}}};function Ct(e,t,n,o,i,s){const a=e.row+t*i,r=e.col+n*i,c={row:a,col:r},l=[],d=e.row<0?0:Math.floor(e.row),u=e.col<0?0:Math.floor(e.col);l.push({row:d,col:u});const h=[[-1,0],[1,0],[0,-1],[0,1],[-1,-1],[-1,1],[1,-1],[1,1]];for(const[f,m]of h){const g=d+f,v=u+m;s.isValid(g,v)&&l.push({row:g,col:v})}for(const f of l){const m=vn(f.row,f.col,s);for(const g of m)if(gn(c,g)<o)return!0}return!1}function vn(e,t,n){const o=[],i=n.grid[e][t];return i.walls.top&&o.push({start:{row:e-.5,col:t-.5},end:{row:e-.5,col:t+.5}}),i.walls.right&&o.push({start:{row:e-.5,col:t+.5},end:{row:e+.5,col:t+.5}}),i.walls.bottom&&o.push({start:{row:e+.5,col:t-.5},end:{row:e+.5,col:t+.5}}),i.walls.left&&o.push({start:{row:e-.5,col:t-.5},end:{row:e+.5,col:t-.5}}),o}function gn(e,t){const{start:n,end:o}=t,i=o.col-n.col,s=o.row-n.row,a=e.col-n.col,r=e.row-n.row,c=i*i+s*s;if(c===0)return Math.sqrt(a*a+r*r);const l=Math.max(0,Math.min(1,(a*i+r*s)/c)),d=n.col+l*i,u=n.row+l*s,h=e.col-d,f=e.row-u;return Math.sqrt(h*h+f*f)}function pn(e,t,n){if(!n.isValid(t.row,t.col))return!1;const o=e.col>=t.col-.5&&e.col<=t.col+.5,i=e.row>=t.row+.5,s=e.row>=t.row-.5;return o&&i&&s}function Z(e,t,n,o,i){return{x:i+t*n+n/2,y:i+e*o+o/2}}function wn(e,t,n,o,i,s){e.save(),e.beginPath();for(let a=0;a<i*2;a++){const r=a%2===0?o:s,c=Math.PI*a/i;e.lineTo(t+r*Math.sin(c),n+r*Math.cos(c))}e.closePath(),e.fill(),e.restore()}function Cn({ctx:e,canvasWidth:t,canvasHeight:n,cellWidth:o,cellHeight:i,padding:s,playerCell:a,walls:r,fogRadius:c,fogColor:l,fogSoftness:d}){const u=Math.max(c,0)*Math.max(o,i)||0;if(u<=0)return;const h=Z(a.row,a.col,o,i,s),f=yn(h,r,u);e.save(),e.fillStyle=l,e.fillRect(0,0,t,n),e.globalCompositeOperation="destination-out";const m=Math.max(Math.min(o,i)*.25,2);e.filter=`blur(${m}px)`;const g=Math.max(Math.min(d,1),0),v=e.createRadialGradient(h.x,h.y,Math.max(u*.2,6),h.x,h.y,u);v.addColorStop(0,"rgba(0, 0, 0, 1)"),v.addColorStop(Math.max(.25,g-.1),"rgba(0, 0, 0, 1)"),v.addColorStop(1,"rgba(0, 0, 0, 0)"),e.fillStyle=v,f.length>=3?(e.beginPath(),f.forEach((w,y)=>{y===0?e.moveTo(w.x,w.y):e.lineTo(w.x,w.y)}),e.closePath(),e.fill()):(e.beginPath(),e.arc(h.x,h.y,u,0,Math.PI*2),e.fill()),e.restore()}function yn(e,t,n){const i=[];if(t.forEach(a=>{i.push(Math.atan2(a.y1-e.y,a.x1-e.x)-1e-4,Math.atan2(a.y1-e.y,a.x1-e.x),Math.atan2(a.y1-e.y,a.x1-e.x)+1e-4,Math.atan2(a.y2-e.y,a.x2-e.x)-1e-4,Math.atan2(a.y2-e.y,a.x2-e.x),Math.atan2(a.y2-e.y,a.x2-e.x)+1e-4)}),i.length===0)for(let a=0;a<24;a++)i.push(a/24*Math.PI*2);return Array.from(new Set(i)).sort((a,r)=>a-r).map(a=>bn(e,a,t,n))}function bn(e,t,n,o){const i={x:Math.cos(t),y:Math.sin(t)};let s={x:e.x+i.x*o,y:e.y+i.y*o,distance:o};for(const a of n){const r=Tn(e,i,{x:a.x1,y:a.y1},{x:a.x2,y:a.y2},o);r&&r.distance<s.distance&&(s=r)}return{x:s.x,y:s.y}}function Tn(e,t,n,o,i){const s={x:o.x-n.x,y:o.y-n.y},a=t.x*s.y-t.y*s.x;if(Math.abs(a)<1e-6)return null;const r={x:n.x-e.x,y:n.y-e.y},c=(r.x*s.y-r.y*s.x)/a,l=(r.x*t.y-r.y*t.x)/a;return c<0||l<0||l>1||c>i?null:{x:e.x+t.x*c,y:e.y+t.y*c,distance:c}}function yt(e,t,n,o){const i=[];for(let s=0;s<e.rows;s++)for(let a=0;a<e.cols;a++){const r=e.grid[s][a],c=o+a*t,l=o+s*n;r.walls.top&&i.push({x1:c,y1:l,x2:c+t,y2:l}),r.walls.right&&i.push({x1:c+t,y1:l,x2:c+t,y2:l+n}),r.walls.bottom&&i.push({x1:c,y1:l+n,x2:c+t,y2:l+n}),r.walls.left&&i.push({x1:c,y1:l,x2:c,y2:l+n})}return i}function Sn({ctx:e,maze:t,cellWidth:n,cellHeight:o,padding:i,wallColor:s,wallWidth:a,walls:r}){e.save(),e.strokeStyle=s,e.lineWidth=a,e.lineCap="round",e.beginPath(),(r??yt(t,n,o,i)).forEach(l=>{e.moveTo(l.x1,l.y1),e.lineTo(l.x2,l.y2)}),e.stroke(),e.restore()}function kn({ctx:e,playerCell:t,playerRadius:n,cellWidth:o,cellHeight:i,padding:s,playerColor:a}){const{x:r,y:c}=Z(t.row,t.col,o,i,s),l=Math.min(o,i)*Math.min(n,.5);e.save(),e.fillStyle=a,e.beginPath(),e.arc(r,c,l,0,Math.PI*2),e.fill(),e.restore()}function En({ctx:e,maze:t,exitCell:n,cellWidth:o,cellHeight:i,padding:s,exitColor:a,exitWallWidth:r,exitDashArray:c=[8,12]}){const{row:l,col:d}=n;if(!t.isValid(l,d))return;const u=s+d*o,h=s+l*i;e.save(),e.globalCompositeOperation="destination-out",e.lineWidth=r,e.lineCap="round",e.beginPath(),e.moveTo(u,h+i),e.lineTo(u+o,h+i),e.stroke(),e.globalCompositeOperation="source-over",e.strokeStyle=a,e.lineWidth=r,e.setLineDash(c),e.beginPath(),e.moveTo(u,h+i),e.lineTo(u+o,h+i),e.stroke(),e.restore()}function zn({ctx:e,foodCells:t,cellWidth:n,cellHeight:o,padding:i,foodColor:s}){e.fillStyle=s,e.shadowColor="rgba(255, 215, 64, 0.9)",e.shadowBlur=Math.max(Math.min(n,o)*.28,3);const a=Math.min(n,o)*.25;t.forEach(r=>{const{x:c,y:l}=Z(r.row,r.col,n,o,i);wn(e,c,l,a*1.25,5,a*.62)}),e.shadowBlur=0,e.strokeStyle="rgba(255,255,255,0.5)",e.lineWidth=Math.max(a*.3,1),t.forEach(r=>{const{x:c,y:l}=Z(r.row,r.col,n,o,i);e.beginPath(),e.arc(c,l,a*1.05,0,Math.PI*2),e.stroke()})}function Mn({ctx:e,playerPath:t,visitCounts:n,cellWidth:o,cellHeight:i,padding:s,clueColor:a}){if(!(!t||t.length<2||!n)){e.save();for(let r=1;r<t.length;r++){const c=t[r-1],l=t[r],d=`${c.row},${c.col}-${l.row},${l.col}`,u=`${l.row},${l.col}-${c.row},${c.col}`,h=(n[d]||0)+(n[u]||0),f=Math.min(.2+h*.1,.9),m=Math.max(3,o*.1)+h*.5;try{e.strokeStyle=a.replace(")",`, ${f})`).replace("rgb(","rgba(")}catch{e.strokeStyle=`rgba(255, 0, 0, ${f})`}e.lineWidth=m,e.lineCap="round",e.lineJoin="round";const{x:g,y:v}=Z(c.row,c.col,o,i,s),{x:w,y}=Z(l.row,l.col,o,i,s);e.beginPath(),e.moveTo(g,v),e.lineTo(w,y),e.stroke()}e.restore()}}function bt(e,t,n,o,i){if(!e||!t.maze)return;const{canvasWidth:s,canvasHeight:a}=n,{cellWidth:r,cellHeight:c}=o,{maze:l,playerCell:d,exitCell:u,foodCells:h,showClue:f,playerPath:m,visitCounts:g}=t,{padding:v,wallWidth:w,wallColor:y,playerColor:T,playerRadius:p,foodColor:z,backgroundColor:C,clueColor:S,fogEnabled:k,fogRadius:L,fogColor:E,fogSoftness:M,exitColor:b,exitWallWidth:A,exitDashArray:x}=i;e.clearRect(0,0,s,a),e.save(),e.fillStyle=C,e.fillRect(0,0,s,a),e.restore(),f&&Mn({ctx:e,playerPath:m,visitCounts:g,cellWidth:r,cellHeight:c,padding:v,clueColor:S});const O=yt(l,r,c,v);(t.fogEnabled??!0)&&k&&Cn({ctx:e,canvasWidth:s,canvasHeight:a,cellWidth:r,cellHeight:c,padding:v,playerCell:d,walls:O,fogRadius:L,fogColor:E,fogSoftness:M}),Sn({ctx:e,maze:l,cellWidth:r,cellHeight:c,padding:v,wallColor:y,wallWidth:w,walls:O}),En({ctx:e,maze:l,exitCell:u,cellWidth:r,cellHeight:c,padding:v,exitColor:b,exitWallWidth:A,exitDashArray:x}),kn({ctx:e,playerCell:d,playerRadius:p,cellWidth:r,cellHeight:c,padding:v,playerColor:T}),zn({ctx:e,foodCells:h,cellWidth:r,cellHeight:c,padding:v,foodColor:z})}function Ln(e){return function(){let t=e+=1831565813;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}}class Nn{constructor(t,n){this.row=t,this.col=n}visited=!1;walls={top:!0,right:!0,bottom:!0,left:!0}}class Tt{rows;cols;grid;seed;random;constructor(t,n,o,i,s={row:0,col:0},a={row:t-1,col:n-1}){this.rows=t,this.cols=n,this.seed=i??Math.floor(Math.random()*1e6),this.random=Ln(this.seed),this.grid=this.initializeGrid(),this.generate(o,s,a)}initializeGrid(){const t=[];for(let n=0;n<this.rows;n++){t[n]=[];for(let o=0;o<this.cols;o++)t[n][o]=new Nn(n,o)}return t}isValid(t,n){return t>=0&&t<this.rows&&n>=0&&n<this.cols}getNeighbors(t,n){const o=[],i=[{r:-1,c:0},{r:0,c:1},{r:1,c:0},{r:0,c:-1}];for(const s of i){const a=t+s.r,r=n+s.c;this.isValid(a,r)&&o.push({row:a,col:r})}return o}getUnvisitedNeighbors(t,n){return this.getNeighbors(t,n).filter(o=>!this.grid[o.row][o.col].visited)}getVisitedNeighbors(t,n){return this.getNeighbors(t,n).filter(o=>this.grid[o.row][o.col].visited)}removeWall(t,n,o,i){const s=this.grid[t][n],a=this.grid[o][i];t===o+1?(s.walls.top=!1,a.walls.bottom=!1):t===o-1?(s.walls.bottom=!1,a.walls.top=!1):n===i+1?(s.walls.left=!1,a.walls.right=!1):n===i-1&&(s.walls.right=!1,a.walls.left=!1)}generate(t,n={row:0,col:0},o={row:this.rows-1,col:this.cols-1}){switch(t){case"backtracking":this.generateWithBacktracking();break;case"prims":this.generateWithPrims();break;default:throw new Error(`Unknown maze generation method: ${t}`)}this.addOpenings(n,o)}generateWithBacktracking(){const t=[],n=this.randomNumber(this.rows),o=this.randomNumber(this.cols);let i={row:n,col:o};for(this.grid[n][o].visited=!0,t.push(i);t.length>0;){i=t[t.length-1];const{row:s,col:a}=i,r=this.getUnvisitedNeighbors(s,a);if(r.length>0){const c=this.randomPick(r),{row:l,col:d}=c;this.removeWall(s,a,l,d),this.grid[l][d].visited=!0,t.push(c)}else t.pop()}}generateWithPrims(){const t=[],n=(s,a)=>{const r=this.getNeighbors(s,a);for(const c of r)!this.grid[c.row][c.col].visited&&!t.some(l=>l.row===c.row&&l.col===c.col)&&t.push(c)},o=this.randomNumber(this.rows),i=this.randomNumber(this.cols);for(this.grid[o][i].visited=!0,n(o,i);t.length>0;){const s=this.randomNumber(t.length),a=t[s],{row:r,col:c}=a,l=this.getVisitedNeighbors(r,c);if(l.length>0){const d=this.randomPick(l);this.removeWall(r,c,d.row,d.col),this.grid[r][c].visited=!0,n(r,c)}t.splice(s,1)}}addOpenings(t,n){this.grid[t.row][t.col].walls.top=!1,this.isValid(n.row,n.col)&&(this.grid[n.row][n.col].walls.bottom=!1)}randomNumber(t){return Math.floor(this.random()*t)}randomPick(t){return t[Math.floor(this.random()*t.length)]}}const St=(e,t,n)=>{if(!e.isValid(t,n))return!1;const o=e.grid[t][n];return!o.walls.top||!o.walls.right||!o.walls.bottom||!o.walls.left},An=e=>e===1?2:e>=2&&e<=5?3:e>=6&&e<=11?4:e>=12&&e<=15?5:6,Pn=(e,t)=>{if(!t)return console.error(`Cannot find Level ${e}'s config.`),null;const{size:n,seed:o,method:i,entry:s,exit:a}=t,r=n,c=n,l=s||{row:0,col:0},d=a||{row:r-1,col:c-1},u=new Tt(r,c,i,o,l,d),h=An(e),f=[];for(let m=0;m<h;m++){let g;do g={row:Math.floor(u.random()*r),col:Math.floor(u.random()*c)};while(g.row===l.row&&g.col===l.col||g.row===d.row&&g.col===d.col||!St(u,g.row,g.col)||f.some(v=>v.row===g.row&&v.col===g.col));f.push(g)}return{isGameActive:!0,levelTransitioning:!1,maze:u,playerCell:l,exitCell:d,foodCells:f,playerAtExit:!1,foodCollected:0,totalFoodCount:h,showClue:!1,playerPath:[l],visitCounts:{[`${l.row},${l.col}`]:1}}},xn=({size:e,seed:t,method:n,foodCount:o,foodRace:i,clue:s,fogEnabled:a=!0})=>{const r=e,c=e,l={row:0,col:0},d={row:r-1,col:c-1},u=new Tt(r,c,n,t,l,d),h=[];if(i)for(let f=0;f<o;f++){let m,g=0;do m={row:Math.floor(u.random()*r),col:Math.floor(u.random()*c)},g++;while(g<50&&(m.row===l.row&&m.col===l.col||m.row===d.row&&m.col===d.col||!St(u,m.row,m.col)||h.some(v=>v.row===m.row&&v.col===m.col)));g<50&&h.push(m)}return{isGameActive:!0,levelTransitioning:!1,maze:u,playerCell:l,exitCell:d,foodCells:h,playerAtExit:!1,foodCollected:0,totalFoodCount:i?o:0,fogEnabled:a,showClue:s,playerPath:[l],visitCounts:{[`${l.row},${l.col}`]:1}}};function In(){const{setGamePlayState:e,gamePlayState:t,gamePlayStateRef:n,gameProgress:o,config:i}=oe(),s=R(null),a=R(null),{i18n:r,levelConfig:c,renderConfig:l}=i,d=re(c),u=R(d.getLevelConfig(o.currentLevel));I(()=>{s.current&&j.attachTo(s.current)},[]);const h=R(),f=gt(a,()=>{h.current?.()}),m=pt(a,t,l.padding);I(()=>{u.current=d.getLevelConfig(o.currentLevel)},[o.currentLevel]);const g=()=>{const T=Pn(o.currentLevel,u.current);T&&e(p=>({...p,...T}))};I(()=>{g()},[o.currentLevel]);const v=()=>{g()},{updatePlayerPos:w,resetMovingState:y}=wt({gamePlayStateRef:n,setGamePlayState:e,playerRadius:l.playerRadius,moveSpeed:l.gridMoveSpeed,onFoodCollected:()=>{const T=n.current.totalFoodCount-n.current.foodCollected-1;T>0?j.show(r.foodCollectedToast.replace("%NUM%",T.toString()),3e3):j.show(r.allFoodCollectedToast)}});return I(()=>{y()},[o.currentLevel,y]),I(()=>{let T,p=!document.hidden;const z=()=>{const k=a.current?.getContext("2d"),L=n.current;if(!(p&&L?.isGameActive&&k&&L?.maze)){T=requestAnimationFrame(z);return}w(),C(),T=requestAnimationFrame(z)},C=()=>{const k=a.current?.getContext("2d"),L=n.current;if(k&&L?.maze){const E=u.current?.wallWidth||l?.wallWidth,M=u.current?.exitColor||l?.exitColor,b=u.current?.exitWallWidth||l?.exitWallWidth,A=u.current?.exitDashArray||l?.exitDashArray;bt(k,L,f.current,m.current,{...l,wallWidth:E,exitColor:M,exitWallWidth:b,exitDashArray:A})}};h.current=C;const S=k=>{const L=p;p=!document.hidden&&document.visibilityState==="visible"&&(!k||k.type!=="blur"),!L&&p?n.current?.levelTransitioning===!1&&e({...n.current,isGameActive:!0}):L&&!p&&e({...n.current,isGameActive:!1})};return document.addEventListener("visibilitychange",S),window.addEventListener("blur",S),window.addEventListener("focus",S),T=requestAnimationFrame(z),()=>{cancelAnimationFrame(T),document.removeEventListener("visibilitychange",S),window.removeEventListener("blur",S),window.removeEventListener("focus",S)}},[]),I(()=>{j.show(r.useArrowKeyTips,3e3)},[]),_("div",{className:"maze-game-container",children:[_(qt,{}),_(_n,{onRetry:v}),_("div",{className:"maze-canvas-container",ref:s,children:_("canvas",{ref:a,className:"maze-game-canvas"})})]})}const Fn=e=>{const t=Math.floor(e/60),n=e%60;return`${t.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`},Rn=({timer:e})=>{const[t,n]=U(e),o=R(),i=R(!1),s=R(0);return I(()=>{const a=()=>{!i.current&&!o.current&&(i.current=!0,o.current=setInterval(()=>{n(c=>(s.current=e-c+1,c<=1?(clearInterval(o.current),window.dispatchEvent(new CustomEvent("maze:timeUp")),0):c-1))},1e3))},r=()=>{clearInterval(o.current),o.current=void 0,window.dispatchEvent(new CustomEvent("maze:timeUsed",{detail:{timeUsed:s.current}}))};return window.addEventListener("maze:firstMove",a),window.addEventListener("maze:gameSuccess",r),()=>{window.removeEventListener("maze:firstMove",a),window.removeEventListener("maze:gameSuccess",r),clearInterval(o.current)}},[e]),I(()=>{o.current&&(clearInterval(o.current),o.current=void 0),n(e),i.current=!1,s.current=0},[e]),_("div",{className:"single-maze-timer",children:_("span",{className:`maze-timer-text ${t<=10&&i.current?"maze-timer-warning":""}`,children:["⏱️ ",Fn(t)]})})};function Dn({config:e}){const{size:t,seed:n,method:o,foodCount:i,foodRace:s,clue:a,renderConfig:r,successCallback:c,failCallback:l,timer:d,i18n:u}=e,h=r.fogEnabled??!0,[f,m]=U({...ut,fogEnabled:h}),[g,v]=U(!1),[w,y]=U(!0),[T,p]=U(!1),[z,C]=U(""),S=R(0),k=R(!1),L=R(!1),E=R(null),M=R(null),b=R(f),A=R(),x=gt(E,()=>{A.current?.()}),O=pt(E,f,r.padding);I(()=>{b.current=f},[f]);const{updatePlayerPos:$,resetMovingState:G,resetFirstMoveState:X}=wt({gamePlayStateRef:b,setGamePlayState:m,playerRadius:r.playerRadius,moveSpeed:r.gridMoveSpeed,onFoodCollected:()=>{console.log("Food collected in single maze")},onExitReached:()=>{if(!k.current){if(s&&b.current.foodCollected<b.current.totalFoodCount){C(`⭐️ ${u.foodMsg}`),p(!0),m(F=>({...F,isGameActive:!1}));return}m(F=>({...F,isGameActive:!1})),ee()}},onFirstMove:()=>{window.dispatchEvent(new CustomEvent("maze:firstMove"))}}),V=()=>{k.current=!0,C(`⏰ ${u.failMsg}`),p(!0),m({...b.current,isGameActive:!1})},ee=()=>{k.current=!0,L.current=!0,C(`🎉 ${u.successMsg}`),p(!0),m(F=>({...F,isGameActive:!1})),window.dispatchEvent(new CustomEvent("maze:gameSuccess"))},Y=()=>{if(p(!1),!k.current){m(F=>({...F,isGameActive:!0}));return}y(!1),m(F=>({...F,showClue:!0})),L.current?c?.(S.current):l?.()};return I(()=>{(async()=>{v(!0);try{const q=xn({size:t,seed:n,method:o,foodCount:i,foodRace:s,clue:a,fogEnabled:b.current.fogEnabled??h});b.current=q,m(q)}catch(q){console.error("Error generating single maze:",q)}finally{v(!1)}})()},[e,h]),I(()=>{let F;const q=!document.hidden,se=()=>{const Ce=E.current?.getContext("2d"),ae=b.current;if(!(q&&ae?.isGameActive&&Ce&&ae?.maze)){F=requestAnimationFrame(se);return}$(),zt(),F=requestAnimationFrame(se)},zt=()=>{const Ce=E.current?.getContext("2d"),ae=b.current;Ce&&ae?.maze&&bt(Ce,ae,x.current,O.current,r)};return A.current=zt,F=requestAnimationFrame(se),()=>{cancelAnimationFrame(F)}},[]),I(()=>{G(),X()},[e,G,X]),I(()=>{const F=q=>{S.current=q.detail.timeUsed};return window.addEventListener("maze:timeUsed",F),window.addEventListener("maze:timeUp",V),()=>{window.removeEventListener("maze:timeUsed",F),window.removeEventListener("maze:timeUp",V)}},[]),g?_("div",{className:"single-maze-loading",children:_("div",{children:"Generating maze..."})}):f?_("div",{className:"maze-game-container",children:[_("div",{className:"single-maze-toolbar",children:w&&_(Rn,{timer:d})}),_("div",{className:"single-maze-canvas-container",ref:M,children:_("canvas",{ref:E,className:"maze-game-canvas"})}),_(ie,{isOpen:T,title:z,noConfirm:!0,cancelText:"OK",onCancel:Y})]}):_("div",{className:"single-maze-error",children:_("div",{children:"Failed to generate maze"})})}const kt=[[{size:8,seed:12345,method:"backtracking",wallWidth:4,exitWallWidth:6,exitDashArray:[8,12]},{size:8,seed:23456,method:"backtracking",exitColor:"#33f",exitWallWidth:4,exitDashArray:[8,16]},{size:8,seed:34567,method:"prims"},{size:8,seed:45678,method:"backtracking"},{size:9,seed:56789,method:"prims"},{size:9,seed:67890,method:"backtracking"},{size:9,seed:78901,method:"prims"},{size:9,seed:89012,method:"backtracking"},{size:10,seed:90123,method:"prims"},{size:11,seed:11111,method:"backtracking"},{size:12,seed:22222,method:"prims"},{size:13,seed:33333,method:"backtracking"}],[{size:12,seed:44444,method:"prims"},{size:12,seed:55555,method:"backtracking"},{size:12,seed:66666,method:"prims"},{size:12,seed:77777,method:"backtracking"},{size:13,seed:88888,method:"prims"},{size:13,seed:99999,method:"backtracking"},{size:13,seed:12121,method:"prims"},{size:14,seed:23232,method:"backtracking"},{size:15,seed:34343,method:"prims"},{size:16,seed:45454,method:"backtracking"},{size:17,seed:56565,method:"prims"},{size:18,seed:67676,method:"backtracking"}],[{size:19,seed:78787,method:"prims"},{size:20,seed:89898,method:"backtracking"},{size:21,seed:90909,method:"prims"},{size:22,seed:10101,method:"backtracking"},{size:23,seed:20202,method:"prims"},{size:25,seed:30303,method:"backtracking"},{size:27,seed:40404,method:"prims"},{size:29,seed:50505,method:"backtracking"},{size:31,seed:60606,method:"prims"},{size:33,seed:70707,method:"backtracking"},{size:37,seed:80808,method:"prims"},{size:40,seed:90909,method:"backtracking"}],[{size:41,seed:10111,method:"prims"},{size:42,seed:11121,method:"backtracking"},{size:43,seed:12131,method:"prims"},{size:44,seed:13141,method:"backtracking"},{size:45,seed:14151,method:"prims"},{size:46,seed:15161,method:"backtracking"},{size:47,seed:16171,method:"prims"},{size:48,seed:17181,method:"backtracking"},{size:49,seed:18191,method:"prims"},{size:50,seed:19201,method:"backtracking"},{size:51,seed:20211,method:"prims"},{size:52,seed:21221,method:"backtracking"}],[{size:53,seed:22231,method:"prims"},{size:54,seed:23241,method:"backtracking"},{size:55,seed:24251,method:"prims"},{size:56,seed:25261,method:"backtracking"},{size:57,seed:26271,method:"prims"},{size:58,seed:27281,method:"backtracking"},{size:59,seed:28291,method:"prims"},{size:60,seed:29301,method:"backtracking"},{size:62,seed:30311,method:"prims"},{size:64,seed:31321,method:"backtracking"},{size:66,seed:32331,method:"prims"},{size:68,seed:33341,method:"backtracking"}]],Et={gridMoveSpeed:.07,padding:10,wallWidth:2,wallColor:"#222",foodColor:"#FFD54F",clueColor:"rgb(255,0,0)",backgroundColor:"#ffffff",playerColor:"#4CAF50",playerRadius:.2,fogEnabled:!0,fogRadius:3.6,fogColor:"rgba(8, 10, 18, 0.9)",fogSoftness:.55,exitColor:"#F44336",exitWallWidth:4,exitDashArray:[8,12]},pe={lcPrefix:"maze-",i18n:{reset:"Reset",resetTip:"Reset all game data and highest score.",confirmReset:"Confirm Reset",confirmResetMessage:"Are you sure you want to reset the game? All progress will be lost.",cancel:"Cancel",close:"Close",confirm:"Confirm",resetDoneToast:"Game reset! Starting from Level 1...",confirmClue:"Confirm to turn on clue?",confirmClueMessage:"Are you sure you want to turn on clue? Your will lose 1 ★.",level:"Level",tier:"Tier",settings:"Settings",clueOn:"Clue: ON",clueOff:"Clue: OFF",foodCollectedToast:"Food collected! %NUM% remaining.",allFoodCollectedToast:"All food collected! Head to the exit.",congratulations:"Congratulations!",findYourExit:"Find your exit!",withoutClue:"Without clue!",withClue:"You used the clue!",collectAllStars:"Collect all stars!",notCollectAllStars:"Not collect all stars.",nextLevel:"Next Level ➤",spacebarTip:"Spacebar",retry:"Retry",levelComplete:"Level Complete",starsCollected:"Stars Collected",avgStarPerLevel:"Avg. Stars per Level",levelCompleteToast:"Level completed! 🎉",tierUnlockedToast:"Tier %TIER% unlocked! 🎉",levelGoToast:"Level %LEVEL% - Go!",levelRestartToast:"Level restarted",allLevelsCompleted:"You completed all levels!",lastOK:"OK",notCompleteLevel:"You still have levels not collected all stars! Try again to collect them all!",continueMessage:"You still have levels where you haven't collected all stars. Try again to collect them all!",continue:"Continue",cluePathEnabled:"Clue Path Enabled",cluePathDisabled:"Clue Path Disabled",useArrowKeyTips:"Use arrow keys to navigate the maze. Press'C' to toggle path clue.",fogOn:"Fog: ON",fogOff:"Fog: OFF",fogEnabledToast:"Fog enabled",fogDisabledToast:"Fog disabled"},renderConfig:Et,levelConfig:kt},we={i18n:{successMsg:"Congratulations! You completed the maze!",failMsg:"Time is up!",foodMsg:"Please collect all stars before leaving!",fogOn:"Fog: ON",fogOff:"Fog: OFF"},size:8,seed:12345,method:"backtracking",clue:!1,foodCount:0,foodRace:!1,renderConfig:Et,timer:600,successCallback:()=>{console.log("🎉 Single maze completed successfully!")},failCallback:()=>{console.log("⏰ Time is up! Game failed.")}};function On({config:e={}}){const t={...pe.i18n,...e.i18n||{}},n={...pe.renderConfig,...e.renderConfig||{}},o=e.levelConfig||kt,i={...pe,...e,i18n:t,levelConfig:o,renderConfig:n};return _(Gt,{config:i,children:_(In,{})})}function $n({config:e={}}){const t={...we.i18n,...e.i18n||{}},n={...we.renderConfig,...e.renderConfig||{}},o={...we,...e,i18n:t,renderConfig:n};return _(Dn,{config:o})}const Un={root:"https://unpkg.com/@roudanio/maze@0.3.1/dist/",...pe};`${JSON.stringify(Un,null,2)}`;const Gn={root:"https://unpkg.com/@roudanio/maze@0.3.1/dist/",...we};return`${JSON.stringify(Gn,(e,t)=>typeof t=="function"?t.toString():t,2)}`,{showNotice(){console.warn("Cannot find the root element");const e=document.createElement("div");e.style.textAlign="center",e.style.padding="20px",e.innerHTML="Cannot find the root element",document.body.append(e)},addLoadingIndicator(e){const t=document.createElement("div"),n=document.createElement("div");t.style.cssText=`
|
|
1
|
+
var Maze=(function(){"use strict";var le,N,Ie,H,Re,Fe,De,Oe,ye,be,Te,$e,te={},Ue=[],Mt=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,ce=Array.isArray;function B(e,t){for(var n in t)e[n]=t[n];return e}function Se(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function Lt(e,t,n){var o,i,s,a={};for(s in t)s=="key"?o=t[s]:s=="ref"?i=t[s]:a[s]=t[s];if(arguments.length>2&&(a.children=arguments.length>3?le.call(arguments,2):n),typeof e=="function"&&e.defaultProps!=null)for(s in e.defaultProps)a[s]===void 0&&(a[s]=e.defaultProps[s]);return ue(e,a,o,i,null)}function ue(e,t,n,o,i){var s={type:e,props:t,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++Ie,__i:-1,__u:0};return i==null&&N.vnode!=null&&N.vnode(s),s}function de(e){return e.children}function he(e,t){this.props=e,this.context=t}function K(e,t){if(t==null)return e.__?K(e.__,e.__i+1):null;for(var n;t<e.__k.length;t++)if((n=e.__k[t])!=null&&n.__e!=null)return n.__e;return typeof e.type=="function"?K(e):null}function Ge(e){var t,n;if((e=e.__)!=null&&e.__c!=null){for(e.__e=e.__c.base=null,t=0;t<e.__k.length;t++)if((n=e.__k[t])!=null&&n.__e!=null){e.__e=e.__c.base=n.__e;break}return Ge(e)}}function ke(e){(!e.__d&&(e.__d=!0)&&H.push(e)&&!fe.__r++||Re!=N.debounceRendering)&&((Re=N.debounceRendering)||Fe)(fe)}function fe(){for(var e,t,n,o,i,s,a,r=1;H.length;)H.length>r&&H.sort(De),e=H.shift(),r=H.length,e.__d&&(n=void 0,o=void 0,i=(o=(t=e).__v).__e,s=[],a=[],t.__P&&((n=B({},o)).__v=o.__v+1,N.vnode&&N.vnode(n),Ee(t.__P,n,o,t.__n,t.__P.namespaceURI,32&o.__u?[i]:null,s,i??K(o),!!(32&o.__u),a),n.__v=o.__v,n.__.__k[n.__i]=n,Ve(s,n,a),o.__e=o.__=null,n.__e!=i&&Ge(n)));fe.__r=0}function je(e,t,n,o,i,s,a,r,c,l,d){var u,h,f,m,g,v,w,y=o&&o.__k||Ue,T=t.length;for(c=Nt(n,t,y,c,T),u=0;u<T;u++)(f=n.__k[u])!=null&&(h=f.__i==-1?te:y[f.__i]||te,f.__i=u,v=Ee(e,f,h,i,s,a,r,c,l,d),m=f.__e,f.ref&&h.ref!=f.ref&&(h.ref&&Me(h.ref,null,f),d.push(f.ref,f.__c||m,f)),g==null&&m!=null&&(g=m),(w=!!(4&f.__u))||h.__k===f.__k?c=We(f,c,e,w):typeof f.type=="function"&&v!==void 0?c=v:m&&(c=m.nextSibling),f.__u&=-7);return n.__e=g,c}function Nt(e,t,n,o,i){var s,a,r,c,l,d=n.length,u=d,h=0;for(e.__k=new Array(i),s=0;s<i;s++)(a=t[s])!=null&&typeof a!="boolean"&&typeof a!="function"?(c=s+h,(a=e.__k[s]=typeof a=="string"||typeof a=="number"||typeof a=="bigint"||a.constructor==String?ue(null,a,null,null,null):ce(a)?ue(de,{children:a},null,null,null):a.constructor==null&&a.__b>0?ue(a.type,a.props,a.key,a.ref?a.ref:null,a.__v):a).__=e,a.__b=e.__b+1,r=null,(l=a.__i=At(a,n,c,u))!=-1&&(u--,(r=n[l])&&(r.__u|=2)),r==null||r.__v==null?(l==-1&&(i>d?h--:i<d&&h++),typeof a.type!="function"&&(a.__u|=4)):l!=c&&(l==c-1?h--:l==c+1?h++:(l>c?h--:h++,a.__u|=4))):e.__k[s]=null;if(u)for(s=0;s<d;s++)(r=n[s])!=null&&(2&r.__u)==0&&(r.__e==o&&(o=K(r)),Xe(r,r));return o}function We(e,t,n,o){var i,s;if(typeof e.type=="function"){for(i=e.__k,s=0;i&&s<i.length;s++)i[s]&&(i[s].__=e,t=We(i[s],t,n,o));return t}e.__e!=t&&(o&&(t&&e.type&&!t.parentNode&&(t=K(e)),n.insertBefore(e.__e,t||null)),t=e.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function At(e,t,n,o){var i,s,a,r=e.key,c=e.type,l=t[n],d=l!=null&&(2&l.__u)==0;if(l===null&&e.key==null||d&&r==l.key&&c==l.type)return n;if(o>(d?1:0)){for(i=n-1,s=n+1;i>=0||s<t.length;)if((l=t[a=i>=0?i--:s++])!=null&&(2&l.__u)==0&&r==l.key&&c==l.type)return a}return-1}function qe(e,t,n){t[0]=="-"?e.setProperty(t,n??""):e[t]=n==null?"":typeof n!="number"||Mt.test(t)?n:n+"px"}function me(e,t,n,o,i){var s,a;e:if(t=="style")if(typeof n=="string")e.style.cssText=n;else{if(typeof o=="string"&&(e.style.cssText=o=""),o)for(t in o)n&&t in n||qe(e.style,t,"");if(n)for(t in n)o&&n[t]==o[t]||qe(e.style,t,n[t])}else if(t[0]=="o"&&t[1]=="n")s=t!=(t=t.replace(Oe,"$1")),a=t.toLowerCase(),t=a in e||t=="onFocusOut"||t=="onFocusIn"?a.slice(2):t.slice(2),e.l||(e.l={}),e.l[t+s]=n,n?o?n.u=o.u:(n.u=ye,e.addEventListener(t,s?Te:be,s)):e.removeEventListener(t,s?Te:be,s);else{if(i=="http://www.w3.org/2000/svg")t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(t!="width"&&t!="height"&&t!="href"&&t!="list"&&t!="form"&&t!="tabIndex"&&t!="download"&&t!="rowSpan"&&t!="colSpan"&&t!="role"&&t!="popover"&&t in e)try{e[t]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&t[4]!="-"?e.removeAttribute(t):e.setAttribute(t,t=="popover"&&n==1?"":n))}}function Be(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t.t==null)t.t=ye++;else if(t.t<n.u)return;return n(N.event?N.event(t):t)}}}function Ee(e,t,n,o,i,s,a,r,c,l){var d,u,h,f,m,g,v,w,y,T,p,z,C,S,k,L,E,M=t.type;if(t.constructor!=null)return null;128&n.__u&&(c=!!(32&n.__u),s=[r=t.__e=n.__e]),(d=N.__b)&&d(t);e:if(typeof M=="function")try{if(w=t.props,y="prototype"in M&&M.prototype.render,T=(d=M.contextType)&&o[d.__c],p=d?T?T.props.value:d.__:o,n.__c?v=(u=t.__c=n.__c).__=u.__E:(y?t.__c=u=new M(w,p):(t.__c=u=new he(w,p),u.constructor=M,u.render=xt),T&&T.sub(u),u.props=w,u.state||(u.state={}),u.context=p,u.__n=o,h=u.__d=!0,u.__h=[],u._sb=[]),y&&u.__s==null&&(u.__s=u.state),y&&M.getDerivedStateFromProps!=null&&(u.__s==u.state&&(u.__s=B({},u.__s)),B(u.__s,M.getDerivedStateFromProps(w,u.__s))),f=u.props,m=u.state,u.__v=t,h)y&&M.getDerivedStateFromProps==null&&u.componentWillMount!=null&&u.componentWillMount(),y&&u.componentDidMount!=null&&u.__h.push(u.componentDidMount);else{if(y&&M.getDerivedStateFromProps==null&&w!==f&&u.componentWillReceiveProps!=null&&u.componentWillReceiveProps(w,p),!u.__e&&u.shouldComponentUpdate!=null&&u.shouldComponentUpdate(w,u.__s,p)===!1||t.__v==n.__v){for(t.__v!=n.__v&&(u.props=w,u.state=u.__s,u.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(b){b&&(b.__=t)}),z=0;z<u._sb.length;z++)u.__h.push(u._sb[z]);u._sb=[],u.__h.length&&a.push(u);break e}u.componentWillUpdate!=null&&u.componentWillUpdate(w,u.__s,p),y&&u.componentDidUpdate!=null&&u.__h.push(function(){u.componentDidUpdate(f,m,g)})}if(u.context=p,u.props=w,u.__P=e,u.__e=!1,C=N.__r,S=0,y){for(u.state=u.__s,u.__d=!1,C&&C(t),d=u.render(u.props,u.state,u.context),k=0;k<u._sb.length;k++)u.__h.push(u._sb[k]);u._sb=[]}else do u.__d=!1,C&&C(t),d=u.render(u.props,u.state,u.context),u.state=u.__s;while(u.__d&&++S<25);u.state=u.__s,u.getChildContext!=null&&(o=B(B({},o),u.getChildContext())),y&&!h&&u.getSnapshotBeforeUpdate!=null&&(g=u.getSnapshotBeforeUpdate(f,m)),L=d,d!=null&&d.type===de&&d.key==null&&(L=He(d.props.children)),r=je(e,ce(L)?L:[L],t,n,o,i,s,a,r,c,l),u.base=t.__e,t.__u&=-161,u.__h.length&&a.push(u),v&&(u.__E=u.__=null)}catch(b){if(t.__v=null,c||s!=null)if(b.then){for(t.__u|=c?160:128;r&&r.nodeType==8&&r.nextSibling;)r=r.nextSibling;s[s.indexOf(r)]=null,t.__e=r}else{for(E=s.length;E--;)Se(s[E]);ze(t)}else t.__e=n.__e,t.__k=n.__k,b.then||ze(t);N.__e(b,t,n)}else s==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):r=t.__e=Pt(n.__e,t,n,o,i,s,a,c,l);return(d=N.diffed)&&d(t),128&t.__u?void 0:r}function ze(e){e&&e.__c&&(e.__c.__e=!0),e&&e.__k&&e.__k.forEach(ze)}function Ve(e,t,n){for(var o=0;o<n.length;o++)Me(n[o],n[++o],n[++o]);N.__c&&N.__c(t,e),e.some(function(i){try{e=i.__h,i.__h=[],e.some(function(s){s.call(i)})}catch(s){N.__e(s,i.__v)}})}function He(e){return typeof e!="object"||e==null||e.__b&&e.__b>0?e:ce(e)?e.map(He):B({},e)}function Pt(e,t,n,o,i,s,a,r,c){var l,d,u,h,f,m,g,v=n.props,w=t.props,y=t.type;if(y=="svg"?i="http://www.w3.org/2000/svg":y=="math"?i="http://www.w3.org/1998/Math/MathML":i||(i="http://www.w3.org/1999/xhtml"),s!=null){for(l=0;l<s.length;l++)if((f=s[l])&&"setAttribute"in f==!!y&&(y?f.localName==y:f.nodeType==3)){e=f,s[l]=null;break}}if(e==null){if(y==null)return document.createTextNode(w);e=document.createElementNS(i,y,w.is&&w),r&&(N.__m&&N.__m(t,s),r=!1),s=null}if(y==null)v===w||r&&e.data==w||(e.data=w);else{if(s=s&&le.call(e.childNodes),v=n.props||te,!r&&s!=null)for(v={},l=0;l<e.attributes.length;l++)v[(f=e.attributes[l]).name]=f.value;for(l in v)if(f=v[l],l!="children"){if(l=="dangerouslySetInnerHTML")u=f;else if(!(l in w)){if(l=="value"&&"defaultValue"in w||l=="checked"&&"defaultChecked"in w)continue;me(e,l,null,f,i)}}for(l in w)f=w[l],l=="children"?h=f:l=="dangerouslySetInnerHTML"?d=f:l=="value"?m=f:l=="checked"?g=f:r&&typeof f!="function"||v[l]===f||me(e,l,f,v[l],i);if(d)r||u&&(d.__html==u.__html||d.__html==e.innerHTML)||(e.innerHTML=d.__html),t.__k=[];else if(u&&(e.innerHTML=""),je(t.type=="template"?e.content:e,ce(h)?h:[h],t,n,o,y=="foreignObject"?"http://www.w3.org/1999/xhtml":i,s,a,s?s[0]:n.__k&&K(n,0),r,c),s!=null)for(l=s.length;l--;)Se(s[l]);r||(l="value",y=="progress"&&m==null?e.removeAttribute("value"):m!=null&&(m!==e[l]||y=="progress"&&!m||y=="option"&&m!=v[l])&&me(e,l,m,v[l],i),l="checked",g!=null&&g!=e[l]&&me(e,l,g,v[l],i))}return e}function Me(e,t,n){try{if(typeof e=="function"){var o=typeof e.__u=="function";o&&e.__u(),o&&t==null||(e.__u=e(t))}else e.current=t}catch(i){N.__e(i,n)}}function Xe(e,t,n){var o,i;if(N.unmount&&N.unmount(e),(o=e.ref)&&(o.current&&o.current!=e.__e||Me(o,null,t)),(o=e.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(s){N.__e(s,t)}o.base=o.__P=null}if(o=e.__k)for(i=0;i<o.length;i++)o[i]&&Xe(o[i],t,n||typeof e.type!="function");n||Se(e.__e),e.__c=e.__=e.__e=void 0}function xt(e,t,n){return this.constructor(e,n)}function Ye(e,t,n){var o,i,s,a;t==document&&(t=document.documentElement),N.__&&N.__(e,t),i=(o=!1)?null:t.__k,s=[],a=[],Ee(t,e=t.__k=Lt(de,null,[e]),i||te,te,t.namespaceURI,i?null:t.firstChild?le.call(t.childNodes):null,s,i?i.__e:t.firstChild,o,a),Ve(s,e,a)}function It(e){function t(n){var o,i;return this.getChildContext||(o=new Set,(i={})[t.__c]=this,this.getChildContext=function(){return i},this.componentWillUnmount=function(){o=null},this.shouldComponentUpdate=function(s){this.props.value!=s.value&&o.forEach(function(a){a.__e=!0,ke(a)})},this.sub=function(s){o.add(s);var a=s.componentWillUnmount;s.componentWillUnmount=function(){o&&o.delete(s),a&&a.call(s)}}),n.children}return t.__c="__cC"+$e++,t.__=e,t.Provider=t.__l=(t.Consumer=function(n,o){return n.children(o)}).contextType=t,t}le=Ue.slice,N={__e:function(e,t,n,o){for(var i,s,a;t=t.__;)if((i=t.__c)&&!i.__)try{if((s=i.constructor)&&s.getDerivedStateFromError!=null&&(i.setState(s.getDerivedStateFromError(e)),a=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(e,o||{}),a=i.__d),a)return i.__E=i}catch(r){e=r}throw e}},Ie=0,he.prototype.setState=function(e,t){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=B({},this.state),typeof e=="function"&&(e=e(B({},n),this.props)),e&&B(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),ke(this))},he.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),ke(this))},he.prototype.render=de,H=[],Fe=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,De=function(e,t){return e.__v.__b-t.__v.__b},fe.__r=0,Oe=/(PointerCapture)$|Capture$/i,ye=0,be=Be(!1),Te=Be(!0),$e=0;var Rt=0;function _(e,t,n,o,i,s){t||(t={});var a,r,c=t;if("ref"in c)for(r in c={},t)r=="ref"?a=t[r]:c[r]=t[r];var l={type:e,props:c,key:n,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Rt,__i:-1,__u:0,__source:i,__self:s};if(typeof e=="function"&&(a=e.defaultProps))for(r in a)c[r]===void 0&&(c[r]=a[r]);return N.vnode&&N.vnode(l),l}var J,x,Le,Ke,ne=0,Je=[],O=N,Qe=O.__b,Ze=O.__r,et=O.diffed,tt=O.__c,nt=O.unmount,ot=O.__;function _e(e,t){O.__h&&O.__h(x,e,ne||t),ne=0;var n=x.__H||(x.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function U(e){return ne=1,Ft(at,e)}function Ft(e,t,n){var o=_e(J++,2);if(o.t=e,!o.__c&&(o.__=[at(void 0,t),function(r){var c=o.__N?o.__N[0]:o.__[0],l=o.t(c,r);c!==l&&(o.__N=[l,o.__[1]],o.__c.setState({}))}],o.__c=x,!x.__f)){var i=function(r,c,l){if(!o.__c.__H)return!0;var d=o.__c.__H.__.filter(function(h){return!!h.__c});if(d.every(function(h){return!h.__N}))return!s||s.call(this,r,c,l);var u=o.__c.props!==r;return d.forEach(function(h){if(h.__N){var f=h.__[0];h.__=h.__N,h.__N=void 0,f!==h.__[0]&&(u=!0)}}),s&&s.call(this,r,c,l)||u};x.__f=!0;var s=x.shouldComponentUpdate,a=x.componentWillUpdate;x.componentWillUpdate=function(r,c,l){if(this.__e){var d=s;s=void 0,i(r,c,l),s=d}a&&a.call(this,r,c,l)},x.shouldComponentUpdate=i}return o.__N||o.__}function I(e,t){var n=_e(J++,3);!O.__s&&st(n.__H,t)&&(n.__=e,n.u=t,x.__H.__h.push(n))}function D(e){return ne=5,Q(function(){return{current:e}},[])}function Q(e,t){var n=_e(J++,7);return st(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function rt(e,t){return ne=8,Q(function(){return e},t)}function Dt(e){var t=x.context[e.__c],n=_e(J++,9);return n.c=e,t?(n.__==null&&(n.__=!0,t.sub(x)),t.props.value):e.__}function Ot(){for(var e;e=Je.shift();)if(e.__P&&e.__H)try{e.__H.__h.forEach(ve),e.__H.__h.forEach(Ne),e.__H.__h=[]}catch(t){e.__H.__h=[],O.__e(t,e.__v)}}O.__b=function(e){x=null,Qe&&Qe(e)},O.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),ot&&ot(e,t)},O.__r=function(e){Ze&&Ze(e),J=0;var t=(x=e.__c).__H;t&&(Le===x?(t.__h=[],x.__h=[],t.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.forEach(ve),t.__h.forEach(Ne),t.__h=[],J=0)),Le=x},O.diffed=function(e){et&&et(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(Je.push(t)!==1&&Ke===O.requestAnimationFrame||((Ke=O.requestAnimationFrame)||$t)(Ot)),t.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),Le=x=null},O.__c=function(e,t){t.some(function(n){try{n.__h.forEach(ve),n.__h=n.__h.filter(function(o){return!o.__||Ne(o)})}catch(o){t.some(function(i){i.__h&&(i.__h=[])}),t=[],O.__e(o,n.__v)}}),tt&&tt(e,t)},O.unmount=function(e){nt&&nt(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.forEach(function(o){try{ve(o)}catch(i){t=i}}),n.__H=void 0,t&&O.__e(t,n.__v))};var it=typeof requestAnimationFrame=="function";function $t(e){var t,n=function(){clearTimeout(o),it&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(n,35);it&&(t=requestAnimationFrame(n))}function ve(e){var t=x,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),x=t}function Ne(e){var t=x;e.__c=e.__(),x=t}function st(e,t){return!e||e.length!==t.length||t.some(function(n,o){return n!==e[o]})}function at(e,t){return typeof t=="function"?t(e):t}const Ut=e=>({saveGameData(t){try{localStorage.setItem(e,JSON.stringify(t))}catch(n){console.error("Failed to save maze game data:",n)}},loadGameData(){try{const t=localStorage.getItem(e);return t?JSON.parse(t):null}catch(t){return console.error("Failed to load maze game data:",t),null}},resetGameData(){try{localStorage.removeItem(e)}catch(t){console.error("Failed to reset maze game data:",t)}}}),lt=It(void 0),ct={currentLevel:1,highestUnlockedLevel:1,currentTier:1,highestUnlockedTier:1,levelScores:{},totalScore:0},ut={isGameActive:!0,levelTransitioning:!1,maze:null,playerCell:{row:0,col:0},exitCell:{row:0,col:0},foodCells:[],fogEnabled:!1,playerAtExit:!1,foodCollected:0,totalFoodCount:0,showClue:!1,playerPath:[],visitCounts:{}},Gt=({children:e,config:t})=>{const n=Ut(t.lcPrefix+"progress"),o=n.loadGameData(),i=t.renderConfig?.fogEnabled??!0,s=()=>({...ut,fogEnabled:i}),[a,r]=U(()=>o||{...ct});I(()=>{const f=Object.values(a.levelScores).reduce((m,g)=>m+g,0);r(m=>({...m,totalScore:f}))},[a.levelScores]),I(()=>{n.saveGameData(a)},[a.currentLevel,a.highestUnlockedLevel,a.currentTier,a.highestUnlockedTier,a.levelScores,a.totalScore]);const[c,l]=U({...s()}),d=D(c);I(()=>{d.current=c},[c]);const u=Q(()=>[c.playerAtExit?1:0,c.foodCollected===c.totalFoodCount?1:0,c.showClue?0:1],[c.playerAtExit,c.foodCollected,c.totalFoodCount,c.showClue]),h=()=>{n.resetGameData(),r({...ct}),l({...s()})};return _(lt.Provider,{value:{gameProgress:a,setGameProgress:r,gamePlayState:c,setGamePlayState:l,gamePlayStateRef:d,currentScore:u,config:t,resetGame:h},children:e})},oe=()=>{const e=Dt(lt);if(!e)throw new Error("useGameContext must be used within a GameProvider");return e},re=e=>Q(()=>{const t=e.map(r=>r.length),n=t.reduce((r,c)=>r+c,0),o=e.length,i=r=>{if(r<1||r>n)return 0;let c=0;for(let l=0;l<t.length;l++)if(c+=t[l],r<=c)return l+1;return 0},s=r=>r<1||r>o?0:t.slice(0,r-1).reduce((c,l)=>c+l,0)+1,a={getTotalLevels:()=>n,getTotalTiers:()=>o,getTierLevelsRange:r=>{if(r<1||r>o)return[0,0];const c=s(r),l=c+t[r-1]-1;return[c,l]},getTierByLevel:i,getFirstLevelOfTier:s,getLevelConfig:r=>{if(r<1||r>n)return null;const c=i(r),l=s(c),d=r-l;return e[c-1][d]},getTierConfig:r=>r<1||r>o?null:e[r-1],isLevelUnlocked:(r,c)=>r<=c,isTierUnlocked:(r,c)=>r<=c,getNextLevelInfo:r=>{if(r>=n)return null;const c=r+1,l=i(r),d=i(c);return{nextLevel:c,nextTier:d,isTierChange:d>l}},getCurrentTierProgress:(r,c)=>{const[l,d]=a.getTierLevelsRange(c),u=r-l+1,h=d-l+1;return{current:u,total:h}},isLastLevelInTier:r=>{const c=i(r),[,l]=a.getTierLevelsRange(c);return r===l},getPreviousLevelInfo:r=>{if(r<=1)return null;const c=r-1,l=i(r),d=i(c);return{prevLevel:c,prevTier:d,isTierChange:d<l}}};return a},[e]),jt=({onTierChange:e,disabled:t})=>{const{gameProgress:n,config:o}=oe(),{i18n:i,levelConfig:s}=o,{currentTier:a,highestUnlockedTier:r}=n,l=re(s).getTotalTiers();return _("div",{className:"tier-selector",children:_("select",{value:a,onChange:d=>{d.target&&d.target.value&&e(Number(d.target.value))},disabled:t,className:"tier-dropdown",children:Array.from({length:l},(d,u)=>u+1).map(d=>_("option",{value:d,disabled:d>r,children:i.tier+" "+d},`tier-${d}`))})})},Wt=({onLevelChange:e,disabled:t})=>{const{gameProgress:n,config:o}=oe(),{i18n:i,levelConfig:s}=o,{currentTier:a,levelScores:r,currentLevel:c,highestUnlockedLevel:l}=n,d=re(s),u=Q(()=>{const[h,f]=d.getTierLevelsRange(a);return Array.from({length:f-h+1},(m,g)=>{const v=h+g,w=r[v]||0;return{level:v,score:w}})},[a,r]);return _("div",{className:"level-selector",children:_("select",{value:c,onChange:h=>{h.target&&h.target.value&&e(Number(h.target.value))},disabled:t,className:"level-dropdown",children:u.map(({level:h,score:f})=>_("option",{value:h,disabled:h>l,children:`${i.level} ${h} ${"★".repeat(f)}`},`level-${h}`))})})},ie=({isOpen:e,title:t,className:n="",message:o,children:i,noConfirm:s=!1,noCancel:a=!1,confirmText:r="OK",cancelText:c="Cancel",confirmClass:l="",cancelClass:d="",onConfirm:u,onCancel:h})=>{const f=D(null);return I(()=>{const m=g=>{g.key==="Escape"&&h?.()};return e&&document.addEventListener("keydown",m),()=>{document.removeEventListener("keydown",m)}},[e,h]),_("div",{className:`maze-dialog-overlay ${e?"maze-dialog-visible":""}`,children:_("div",{className:"maze-dialog "+n,ref:f,children:[_("div",{className:"maze-dialog-title",children:t}),_("div",{className:"maze-dialog-content",children:i||_("div",{className:"maze-dialog-message",children:o})}),(!a||!s)&&_("div",{className:"maze-dialog-buttons",children:[!a&&_("button",{type:"button",className:"maze-dialog-cancel "+d,onClick:h,children:c}),!s&&_("button",{type:"button",className:"maze-dialog-confirm "+l,onClick:u,children:r})]})]})})},j={container:null,attachTo(e){return this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.container=document.createElement("div"),this.container.className="toast-container position-bottom",e.appendChild(this.container),this.container},currentToast:null,currentTimer:null,show(e,t=2e3){if(!this.container){console.warn("NativeToast: container not initialized, please call attachTo first");return}this.currentToast&&this.container.contains(this.currentToast)&&(this.container.removeChild(this.currentToast),this.currentToast=null),this.currentTimer&&(clearTimeout(this.currentTimer),this.currentTimer=null);const n=document.createElement("div");n.className="toast-message toast-visible",n.textContent=e,this.container.appendChild(n),this.currentToast=n,this.currentTimer=setTimeout(()=>{n.classList.remove("toast-visible"),setTimeout(()=>{this.container&&this.container.contains(n)&&(this.container.removeChild(n),this.currentToast===n&&(this.currentToast=null))},300),this.currentTimer=null},t)},clearAll(){if(this.container)for(;this.container.firstChild;)this.container.removeChild(this.container.firstChild)}},qt=()=>{const{gameProgress:e,setGameProgress:t,gamePlayState:n,setGamePlayState:o,gamePlayStateRef:i,resetGame:s,config:a}=oe(),{i18n:r,levelConfig:c}=a,l=re(c),{levelTransitioning:d,showClue:u}=n,{highestUnlockedLevel:h,totalScore:f}=e,m=l.getTotalLevels(),[g,v]=U(!1),[w,y]=U(!1),[T,p]=U(!1),z=R=>{const $=l.getFirstLevelOfTier(R);l.isLevelUnlocked($,h)&&(t(G=>({...G,currentTier:R})),C($))},C=R=>{l.isLevelUnlocked(R,h)&&(t($=>({...$,currentLevel:R})),j.show(r.levelGoToast.replace("%LEVEL%",R.toString())))},S=()=>{v(!0)},k=()=>{v(!1)},L=()=>{p(!0)},E=()=>{p(!1)},M=()=>{j.show(u?r.cluePathDisabled:r.cluePathEnabled),o(()=>({...i.current,showClue:!i.current.showClue})),p(!1)},b=()=>{y(!0)},A=()=>{s(),y(!1),j.show(r.resetDoneToast)},P=()=>{y(!1)};return _("div",{class:"game-panel-container",children:[_("div",{className:"game-controls",children:[_("div",{className:"selectors-container",children:[_(jt,{onTierChange:z,disabled:d}),_(Wt,{onLevelChange:C,disabled:d})]}),_("button",{className:`settings-clue-button ${u?"clue-on":"clue-off"}`,disabled:u,title:"Toggle Clue",onClick:L,children:u?r.clueOn:r.clueOff})]}),_("div",{className:"game-settings",children:_("span",{className:"game-settings-icon",onClick:S,children:"★ "+f})}),_(ie,{isOpen:g,title:r.settings,noConfirm:!0,cancelText:r.close,onCancel:k,children:[_("div",{className:"settings-stats",children:[_("div",{children:r.levelComplete+`: ${h}/${m}`}),_("div",{children:r.starsCollected+": "+f}),_("div",{children:r.avgStarPerLevel+": "+(f/h).toFixed(2)})]}),_("div",{className:"settings-item-box",children:[_("button",{className:"settings-reset-button",title:"Reset Game",onClick:b,children:r.reset}),_("div",{className:"settings-item-tip",children:r.resetTip})]})]}),_(ie,{isOpen:w,title:r.confirmReset,message:r.confirmResetMessage,confirmText:r.reset,cancelText:r.cancel,onConfirm:A,onCancel:P}),_(ie,{isOpen:T,title:r.confirmClue,message:r.confirmClueMessage,confirmText:r.confirm,cancelText:r.cancel,onConfirm:M,onCancel:E})]})};function Ae(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Bt(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function Pe(e,t,n){return t&&Bt(e.prototype,t),e}function dt(e){return+e.replace(/px/,"")}function Vt(e){var t=window.devicePixelRatio,n=getComputedStyle(e),o=dt(n.getPropertyValue("width")),i=dt(n.getPropertyValue("height"));e.setAttribute("width",(o*t).toString()),e.setAttribute("height",(i*t).toString())}function W(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,o=Math.random()*(t-e)+e;return Math.floor(o*Math.pow(10,n))/Math.pow(10,n)}function ht(e){return e[W(0,e.length)]}var Ht=.00125,Xt=5e-4,Yt=9e-4,Kt=1e-5,Jt=6,Qt=80,Zt=.9,en=1.7,tn=.2,nn=.6,on=.03,rn=.07,ft=15,mt=82,sn=100,an=250,ln=40,cn=["#fcf403","#62fc03","#f4fc03","#03e7fc","#03fca5","#a503fc","#fc03ad","#fc03c2"];function _t(e){var t=1920;return Math.log(e)/Math.log(t)}var vt=(function(){function e(t){Ae(this,e);var n=t.initialPosition,o=t.direction,i=t.confettiRadius,s=t.confettiColors,a=t.emojis,r=t.emojiSize,c=t.canvasWidth,l=W(Zt,en,3),d=l*_t(c);this.confettiSpeed={x:d,y:d},this.finalConfettiSpeedX=W(tn,nn,3),this.rotationSpeed=a.length?.01:W(on,rn,3)*_t(c),this.dragForceCoefficient=W(Xt,Yt,6),this.radius={x:i,y:i},this.initialRadius=i,this.rotationAngle=o==="left"?W(0,.2,3):W(-.2,0,3),this.emojiSize=r,this.emojiRotationAngle=W(0,2*Math.PI),this.radiusYUpdateDirection="down";var u=o==="left"?W(mt,ft)*Math.PI/180:W(-ft,-mt)*Math.PI/180;this.absCos=Math.abs(Math.cos(u)),this.absSin=Math.abs(Math.sin(u));var h=W(-150,0),f={x:n.x+(o==="left"?-h:h)*this.absCos,y:n.y-h*this.absSin};this.currentPosition=Object.assign({},f),this.initialPosition=Object.assign({},f),this.color=a.length?null:ht(s),this.emoji=a.length?ht(a):null,this.createdAt=new Date().getTime(),this.direction=o}return Pe(e,[{key:"draw",value:function(n){var o=this.currentPosition,i=this.radius,s=this.color,a=this.emoji,r=this.rotationAngle,c=this.emojiRotationAngle,l=this.emojiSize,d=window.devicePixelRatio;s?(n.fillStyle=s,n.beginPath(),n.ellipse(o.x*d,o.y*d,i.x*d,i.y*d,r,0,2*Math.PI),n.fill()):a&&(n.font="".concat(l,"px serif"),n.save(),n.translate(d*o.x,d*o.y),n.rotate(c),n.textAlign="center",n.fillText(a,0,0),n.restore())}},{key:"updatePosition",value:function(n,o){var i=this.confettiSpeed,s=this.dragForceCoefficient,a=this.finalConfettiSpeedX,r=this.radiusYUpdateDirection,c=this.rotationSpeed,l=this.createdAt,d=this.direction,u=o-l;if(i.x>a&&(this.confettiSpeed.x-=s*n),this.currentPosition.x+=i.x*(d==="left"?-this.absCos:this.absCos)*n,this.currentPosition.y=this.initialPosition.y-i.y*this.absSin*u+Ht*Math.pow(u,2)/2,this.rotationSpeed-=this.emoji?1e-4:Kt*n,this.rotationSpeed<0&&(this.rotationSpeed=0),this.emoji){this.emojiRotationAngle+=this.rotationSpeed*n%(2*Math.PI);return}r==="down"?(this.radius.y-=n*c,this.radius.y<=0&&(this.radius.y=0,this.radiusYUpdateDirection="up")):(this.radius.y+=n*c,this.radius.y>=this.initialRadius&&(this.radius.y=this.initialRadius,this.radiusYUpdateDirection="down"))}},{key:"getIsVisibleOnCanvas",value:function(n){return this.currentPosition.y<n+sn}}]),e})();function un(){var e=document.createElement("canvas");return e.style.position="fixed",e.style.width="100%",e.style.height="100%",e.style.top="0",e.style.left="0",e.style.zIndex="1000",e.style.pointerEvents="none",document.body.appendChild(e),e}function dn(e){var t=e.confettiRadius,n=t===void 0?Jt:t,o=e.confettiNumber,i=o===void 0?e.confettiesNumber||(e.emojis?ln:an):o,s=e.confettiColors,a=s===void 0?cn:s,r=e.emojis,c=r===void 0?e.emojies||[]:r,l=e.emojiSize,d=l===void 0?Qt:l;return e.emojies&&console.error("emojies argument is deprecated, please use emojis instead"),e.confettiesNumber&&console.error("confettiesNumber argument is deprecated, please use confettiNumber instead"),{confettiRadius:n,confettiNumber:i,confettiColors:a,emojis:c,emojiSize:d}}var hn=(function(){function e(t){var n=this;Ae(this,e),this.canvasContext=t,this.shapes=[],this.promise=new Promise(function(o){return n.resolvePromise=o})}return Pe(e,[{key:"getBatchCompletePromise",value:function(){return this.promise}},{key:"addShapes",value:function(){var n;(n=this.shapes).push.apply(n,arguments)}},{key:"complete",value:function(){var n;return this.shapes.length?!1:((n=this.resolvePromise)===null||n===void 0||n.call(this),!0)}},{key:"processShapes",value:function(n,o,i){var s=this,a=n.timeDelta,r=n.currentTime;this.shapes=this.shapes.filter(function(c){return c.updatePosition(a,r),c.draw(s.canvasContext),i?c.getIsVisibleOnCanvas(o):!0})}}]),e})(),fn=(function(){function e(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Ae(this,e),this.activeConfettiBatches=[],this.canvas=t.canvas||un(),this.canvasContext=this.canvas.getContext("2d"),this.requestAnimationFrameRequested=!1,this.lastUpdated=new Date().getTime(),this.iterationIndex=0,this.loop=this.loop.bind(this),requestAnimationFrame(this.loop)}return Pe(e,[{key:"loop",value:function(){this.requestAnimationFrameRequested=!1,Vt(this.canvas);var n=new Date().getTime(),o=n-this.lastUpdated,i=this.canvas.offsetHeight,s=this.iterationIndex%10===0;this.activeConfettiBatches=this.activeConfettiBatches.filter(function(a){return a.processShapes({timeDelta:o,currentTime:n},i,s),s?!a.complete():!0}),this.iterationIndex++,this.queueAnimationFrameIfNeeded(n)}},{key:"queueAnimationFrameIfNeeded",value:function(n){this.requestAnimationFrameRequested||this.activeConfettiBatches.length<1||(this.requestAnimationFrameRequested=!0,this.lastUpdated=n||new Date().getTime(),requestAnimationFrame(this.loop))}},{key:"addConfetti",value:function(){for(var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},o=dn(n),i=o.confettiRadius,s=o.confettiNumber,a=o.confettiColors,r=o.emojis,c=o.emojiSize,l=this.canvas.getBoundingClientRect(),d=l.width,u=l.height,h=u*5/7,f={x:0,y:h},m={x:d,y:h},g=new hn(this.canvasContext),v=0;v<s/2;v++){var w=new vt({initialPosition:f,direction:"right",confettiRadius:i,confettiColors:a,confettiNumber:s,emojis:r,emojiSize:c,canvasWidth:d}),y=new vt({initialPosition:m,direction:"left",confettiRadius:i,confettiColors:a,confettiNumber:s,emojis:r,emojiSize:c,canvasWidth:d});g.addShapes(w,y)}return this.activeConfettiBatches.push(g),this.queueAnimationFrameIfNeeded(),g.getBatchCompletePromise()}},{key:"clearCanvas",value:function(){this.activeConfettiBatches=[]}},{key:"destroyCanvas",value:function(){this.canvas.remove()}}]),e})();const mn=new fn,xe=3,_n=({onRetry:e})=>{const{config:t,currentScore:n,gamePlayState:o,setGamePlayState:i,gameProgress:s,setGameProgress:a}=oe(),{i18n:r,levelConfig:c}=t,[l,d,u]=n,{foodCollected:h,totalFoodCount:f,playerAtExit:m,levelTransitioning:g}=o,{currentLevel:v}=s,[w,y]=U(!1);I(()=>{m&&g&&(mn.addConfetti(),j.show(r.levelCompleteToast),y(!0))},[m,g]);const T=re(c),p=T.getTotalLevels(),z=Q(()=>v>=p,[v,p]),C=()=>{y(!1),j.show(r.levelRestartToast),e?.()},S=()=>{y(!1),i(E=>({...E,isGameActive:!0,levelTransitioning:!1}))},k=()=>{y(!1);const E=T.getNextLevelInfo(v);if(!E)return;const{nextLevel:M,nextTier:b,isTierChange:A}=E;A&&j.show(r.tierUnlockedToast.replace("%TIER%",b.toString())),a(P=>({...P,currentLevel:M,currentTier:b,highestUnlockedLevel:Math.max(P.highestUnlockedLevel,M),highestUnlockedTier:Math.max(P.highestUnlockedTier,b),levelScores:{...P.levelScores,[P.currentLevel]:Math.max(Object.values(n).filter(Boolean).length,P.levelScores[P.currentLevel]||0)}}))},L=()=>{y(!1),a(E=>{const M=Math.max(Object.values(n).filter(Boolean).length,E.levelScores[E.currentLevel]||0),b={...E.levelScores,[E.currentLevel]:M};let A=0,P=0;const R=Object.entries(b).sort(($,G)=>Number($[0])-Number(G[0]));for(const[$,G]of R)if(G<xe){A=Number($),P=T.getTierByLevel(A);break}return(A>0&&A!==v||M<xe)&&j.show(r.notCompleteLevel),(A===0||M<xe)&&e?.(),{...E,currentLevel:A||E.currentLevel,currentTier:P||E.currentTier,levelScores:b}})};return I(()=>{const E=document.querySelector(".maze-game-container"),M=b=>{w&&((b.key===" "||b.code==="Space")&&E&&(E.contains(document.activeElement)||document.activeElement===document.body)&&(b.preventDefault(),z?L():k()),(b.key==="r"||b.code==="KeyR")&&C(),(b.key==="c"||b.code==="KeyC")&&S())};return window.addEventListener("keydown",M),()=>window.removeEventListener("keydown",M)},[w,z]),_(ie,{className:"level-complete-dialog",isOpen:w,title:r.congratulations,cancelText:r.retry+" (R)",onCancel:C,noConfirm:!!d,confirmText:r.continue+" (C)",onConfirm:S,confirmClass:"maze-continue-btn",children:[_("div",{className:"maze-summary-message",children:[!!l&&_("div",{children:"★ - "+r.findYourExit}),_("div",{children:u?"★ - "+r.withoutClue:"☆ - "+r.withClue}),_("div",{children:(d?"★ - "+r.collectAllStars:"☆ - "+r.notCollectAllStars)+` (${h}/${f})`})]}),z&&_("div",{className:"all-levels-completed",children:r.allLevelsCompleted}),_("div",{className:"maze-go-next",children:z?_("button",{className:"maze-go-next-btn",type:"button",onClick:L,children:[_("span",{children:r.lastOK}),_("span",{className:"spacebar-tip",children:`(${r.spacebarTip})`})]}):_("button",{className:"maze-go-next-btn",type:"button",onClick:k,children:[_("span",{children:r.nextLevel}),_("span",{className:"spacebar-tip",children:`(${r.spacebarTip})`})]})}),!d&&_("div",{className:"not-all-stars-collected",children:r.continueMessage})]})},gt=(e,t)=>{const n=D({canvasWidth:0,canvasHeight:0});return I(()=>{const o=()=>{const s=e.current;if(!s)return;const a=s.parentElement;if(!a)return;const r=a.clientWidth;if(r===0)return;const c=window.devicePixelRatio||1;s.style.width=`${r}px`,s.style.height=`${r}px`;const l=r*c,d=r*c;s.width=l,s.height=d,n.current={canvasWidth:l,canvasHeight:d},t?.()};o();let i=null;return window.ResizeObserver&&e.current&&(i=new ResizeObserver(o),i.observe(e.current.parentElement)),window.addEventListener("resize",o),()=>{window.removeEventListener("resize",o),i?.disconnect()}},[e,t]),n},pt=(e,t,n)=>{const o=D({cellWidth:0,cellHeight:0});return I(()=>{const i=()=>{const a=e.current,r=t.maze;if(!a||!r)return;const{rows:c,cols:l}=r;if(c<=0||l<=0)return;const d=(a.width-n*2)/l,u=(a.height-n*2)/c;o.current={cellWidth:d,cellHeight:u}};i();let s=null;return e.current&&window.ResizeObserver&&(s=new ResizeObserver(i),s.observe(e.current)),()=>{e.current&&s?.disconnect()}},[e,t.maze,n]),o},ge={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]},wt=({gamePlayStateRef:e,setGamePlayState:t,moveSpeed:n,moveSpeedRef:o,playerRadius:i,onFoodCollected:s,onExitReached:a,onFirstMove:r})=>{const c=()=>o?.current??n??.03,l=D(!1),d=D(new Set),u=D(!1),h=rt((T,p)=>{const z=e.current;if(!z.maze)return{canMove:!1,newCell:null};const C=c(),[S,k]=ge[T];if(Ct(p,S,k,i,C,z.maze))return{canMove:!1,newCell:null};const{row:E,col:M}=p,b=E+S*C,A=M+k*C,P=-.5,R=z.maze.rows,$=z.maze.cols;if(b<P||b>=R||A<P||A>=$)return{canMove:!1,newCell:null};const G=E<0?0:Math.floor(E),X=M<0?0:Math.floor(M),V=b<0?0:Math.floor(b),ee=A<0?0:Math.floor(A);return V!==G||ee!==X?z.maze.isValid(V,ee)?{canMove:!0,newCell:{row:V,col:ee}}:{canMove:!1,newCell:null}:{canMove:!0,newCell:null}},[i,c]),f=()=>{const T=e.current,{row:p,col:z}=T.playerCell,C=i*2,S=T.foodCells.findIndex(E=>Math.sqrt(Math.pow(p-E.row,2)+Math.pow(z-E.col,2))<C);S!==-1&&s&&(s(),e.current={...e.current,foodCollected:e.current.foodCollected+1,foodCells:e.current.foodCells.filter((E,M)=>M!==S)});const L=pn(T.playerCell,T.exitCell,T.maze);L&&!e.current.playerAtExit?(e.current={...e.current,playerAtExit:!0,isGameActive:!1,levelTransitioning:!0},a&&a(),requestIdleCallback(()=>{t(()=>({...e.current}))},{timeout:10})):!L&&e.current.playerAtExit&&(e.current={...e.current,playerAtExit:!1,isGameActive:!0,levelTransitioning:!1})},m=T=>{const p=e.current,z=Math.round(T.row),C=Math.round(T.col),S=p.playerPath[p.playerPath.length-1],k=S.row===z&&S.col===C,L=Math.abs(S.row-z),E=Math.abs(S.col-C);if((L===1&&E===0||L===0&&E===1)&&!k){const b=`${S.row},${S.col}-${z},${C}`;e.current={...e.current,playerPath:[...e.current.playerPath,{row:z,col:C}],visitCounts:{...e.current.visitCounts,[b]:(e.current.visitCounts[b]||0)+1}}}},g=()=>{if(l.current||d.current.size===0)return;const T=e.current;!T.playerCell||!Array.from(d.current).some(z=>{const{canMove:C}=h(z,T.playerCell);return C})||(!u.current&&r&&(u.current=!0,r()),l.current=!0)};I(()=>{const T=C=>{if(C.key==="ArrowUp"||C.key==="ArrowDown"||C.key==="ArrowLeft"||C.key==="ArrowRight"||C.key===" "){const S=document.activeElement;if(S&&(S.tagName==="INPUT"||S.tagName==="TEXTAREA"||S.getAttribute("contenteditable")==="true"))return;C.preventDefault()}},p=C=>{const S=C.key;if(!(S in ge))return;const k=document.activeElement;k&&(k.tagName==="INPUT"||k.tagName==="TEXTAREA"||k.getAttribute("contenteditable")==="true")||(C.preventDefault(),e.current.isGameActive&&(d.current.has(S)||(d.current.add(S),l.current||g())))},z=C=>{const S=C.key;if(!(S in ge))return;const k=document.activeElement;k&&(k.tagName==="INPUT"||k.tagName==="TEXTAREA"||k.getAttribute("contenteditable")==="true")||(C.preventDefault(),d.current.delete(S),d.current.size===0&&w())};return window.addEventListener("keydown",T,{capture:!0}),window.addEventListener("keydown",p),window.addEventListener("keyup",z),()=>{window.removeEventListener("keydown",T,{capture:!0}),window.removeEventListener("keydown",p),window.removeEventListener("keyup",z)}},[]);const v=rt(()=>{if(!l.current||d.current.size===0)return e.current.playerCell;const T=c(),p=e.current.playerCell;let z=0,C=0,S=0;for(const Y of d.current){const{canMove:F}=h(Y,p);if(F){const[q,se]=ge[Y];z+=q,C+=se,S++}}if(S===0)return e.current.playerCell;const k=Math.sqrt(z*z+C*C),L=k>0?z/k:0,E=k>0?C/k:0,M=Number((p.row+L*T).toFixed(2)),b=Number((p.col+E*T).toFixed(2)),A=M-p.row,P=b-p.col,R=Math.sqrt(A*A+P*P);if(R>0){const Y=A/R,F=P/R;if(Ct(p,Y,F,i,R,e.current.maze))return e.current.playerCell}e.current.playerCell={row:M,col:b},f();const $=p.row<0?0:Math.round(p.row),G=p.col<0?0:Math.round(p.col),X=M<0?0:Math.round(M),V=b<0?0:Math.round(b);return(X!==$||V!==G)&&m({row:X,col:V}),e.current.playerCell},[c,h]),w=()=>{l.current=!1,d.current.clear()};return{updatePlayerPos:v,resetMovingState:w,resetFirstMoveState:()=>{u.current=!1}}};function Ct(e,t,n,o,i,s){const a=e.row+t*i,r=e.col+n*i,c={row:a,col:r},l=[],d=e.row<0?0:Math.floor(e.row),u=e.col<0?0:Math.floor(e.col);l.push({row:d,col:u});const h=[[-1,0],[1,0],[0,-1],[0,1],[-1,-1],[-1,1],[1,-1],[1,1]];for(const[f,m]of h){const g=d+f,v=u+m;s.isValid(g,v)&&l.push({row:g,col:v})}for(const f of l){const m=vn(f.row,f.col,s);for(const g of m)if(gn(c,g)<o)return!0}return!1}function vn(e,t,n){const o=[],i=n.grid[e][t];return i.walls.top&&o.push({start:{row:e-.5,col:t-.5},end:{row:e-.5,col:t+.5}}),i.walls.right&&o.push({start:{row:e-.5,col:t+.5},end:{row:e+.5,col:t+.5}}),i.walls.bottom&&o.push({start:{row:e+.5,col:t-.5},end:{row:e+.5,col:t+.5}}),i.walls.left&&o.push({start:{row:e-.5,col:t-.5},end:{row:e+.5,col:t-.5}}),o}function gn(e,t){const{start:n,end:o}=t,i=o.col-n.col,s=o.row-n.row,a=e.col-n.col,r=e.row-n.row,c=i*i+s*s;if(c===0)return Math.sqrt(a*a+r*r);const l=Math.max(0,Math.min(1,(a*i+r*s)/c)),d=n.col+l*i,u=n.row+l*s,h=e.col-d,f=e.row-u;return Math.sqrt(h*h+f*f)}function pn(e,t,n){if(!n.isValid(t.row,t.col))return!1;const o=e.col>=t.col-.5&&e.col<=t.col+.5,i=e.row>=t.row+.5,s=e.row>=t.row-.5;return o&&i&&s}function Z(e,t,n,o,i){return{x:i+t*n+n/2,y:i+e*o+o/2}}function wn(e,t,n,o,i,s){e.save(),e.beginPath();for(let a=0;a<i*2;a++){const r=a%2===0?o:s,c=Math.PI*a/i;e.lineTo(t+r*Math.sin(c),n+r*Math.cos(c))}e.closePath(),e.fill(),e.restore()}function Cn({ctx:e,canvasWidth:t,canvasHeight:n,cellWidth:o,cellHeight:i,padding:s,playerCell:a,walls:r,fogRadius:c,fogColor:l,fogSoftness:d}){const u=Math.max(c,0)*Math.max(o,i)||0;if(u<=0)return;const h=Z(a.row,a.col,o,i,s),f=yn(h,r,u);e.save(),e.fillStyle=l,e.fillRect(0,0,t,n),e.globalCompositeOperation="destination-out";const m=Math.max(Math.min(o,i)*.25,2);e.filter=`blur(${m}px)`;const g=Math.max(Math.min(d,1),0),v=e.createRadialGradient(h.x,h.y,Math.max(u*.2,6),h.x,h.y,u);v.addColorStop(0,"rgba(0, 0, 0, 1)"),v.addColorStop(Math.max(.25,g-.1),"rgba(0, 0, 0, 1)"),v.addColorStop(1,"rgba(0, 0, 0, 0)"),e.fillStyle=v,f.length>=3?(e.beginPath(),f.forEach((w,y)=>{y===0?e.moveTo(w.x,w.y):e.lineTo(w.x,w.y)}),e.closePath(),e.fill()):(e.beginPath(),e.arc(h.x,h.y,u,0,Math.PI*2),e.fill()),e.restore()}function yn(e,t,n){const i=[];if(t.forEach(a=>{i.push(Math.atan2(a.y1-e.y,a.x1-e.x)-1e-4,Math.atan2(a.y1-e.y,a.x1-e.x),Math.atan2(a.y1-e.y,a.x1-e.x)+1e-4,Math.atan2(a.y2-e.y,a.x2-e.x)-1e-4,Math.atan2(a.y2-e.y,a.x2-e.x),Math.atan2(a.y2-e.y,a.x2-e.x)+1e-4)}),i.length===0)for(let a=0;a<24;a++)i.push(a/24*Math.PI*2);return Array.from(new Set(i)).sort((a,r)=>a-r).map(a=>bn(e,a,t,n))}function bn(e,t,n,o){const i={x:Math.cos(t),y:Math.sin(t)};let s={x:e.x+i.x*o,y:e.y+i.y*o,distance:o};for(const a of n){const r=Tn(e,i,{x:a.x1,y:a.y1},{x:a.x2,y:a.y2},o);r&&r.distance<s.distance&&(s=r)}return{x:s.x,y:s.y}}function Tn(e,t,n,o,i){const s={x:o.x-n.x,y:o.y-n.y},a=t.x*s.y-t.y*s.x;if(Math.abs(a)<1e-6)return null;const r={x:n.x-e.x,y:n.y-e.y},c=(r.x*s.y-r.y*s.x)/a,l=(r.x*t.y-r.y*t.x)/a;return c<0||l<0||l>1||c>i?null:{x:e.x+t.x*c,y:e.y+t.y*c,distance:c}}function yt(e,t,n,o){const i=[];for(let s=0;s<e.rows;s++)for(let a=0;a<e.cols;a++){const r=e.grid[s][a],c=o+a*t,l=o+s*n;r.walls.top&&i.push({x1:c,y1:l,x2:c+t,y2:l}),r.walls.right&&i.push({x1:c+t,y1:l,x2:c+t,y2:l+n}),r.walls.bottom&&i.push({x1:c,y1:l+n,x2:c+t,y2:l+n}),r.walls.left&&i.push({x1:c,y1:l,x2:c,y2:l+n})}return i}function Sn({ctx:e,maze:t,cellWidth:n,cellHeight:o,padding:i,wallColor:s,wallWidth:a,walls:r}){e.save(),e.strokeStyle=s,e.lineWidth=a,e.lineCap="round",e.beginPath(),(r??yt(t,n,o,i)).forEach(l=>{e.moveTo(l.x1,l.y1),e.lineTo(l.x2,l.y2)}),e.stroke(),e.restore()}function kn({ctx:e,playerCell:t,playerRadius:n,cellWidth:o,cellHeight:i,padding:s,playerColor:a}){const{x:r,y:c}=Z(t.row,t.col,o,i,s),l=Math.min(o,i)*Math.min(n,.5);e.save(),e.fillStyle=a,e.beginPath(),e.arc(r,c,l,0,Math.PI*2),e.fill(),e.restore()}function En({ctx:e,maze:t,exitCell:n,cellWidth:o,cellHeight:i,padding:s,exitColor:a,exitWallWidth:r,exitDashArray:c=[8,12]}){const{row:l,col:d}=n;if(!t.isValid(l,d))return;const u=s+d*o,h=s+l*i;e.save(),e.globalCompositeOperation="destination-out",e.lineWidth=r,e.lineCap="round",e.beginPath(),e.moveTo(u,h+i),e.lineTo(u+o,h+i),e.stroke(),e.globalCompositeOperation="source-over",e.strokeStyle=a,e.lineWidth=r,e.setLineDash(c),e.beginPath(),e.moveTo(u,h+i),e.lineTo(u+o,h+i),e.stroke(),e.restore()}function zn({ctx:e,foodCells:t,cellWidth:n,cellHeight:o,padding:i,foodColor:s}){e.fillStyle=s,e.shadowColor="rgba(255, 215, 64, 0.9)",e.shadowBlur=Math.max(Math.min(n,o)*.28,3);const a=Math.min(n,o)*.25;t.forEach(r=>{const{x:c,y:l}=Z(r.row,r.col,n,o,i);wn(e,c,l,a*1.25,5,a*.62)}),e.shadowBlur=0,e.strokeStyle="rgba(255,255,255,0.5)",e.lineWidth=Math.max(a*.3,1),t.forEach(r=>{const{x:c,y:l}=Z(r.row,r.col,n,o,i);e.beginPath(),e.arc(c,l,a*1.05,0,Math.PI*2),e.stroke()})}function Mn({ctx:e,playerPath:t,visitCounts:n,cellWidth:o,cellHeight:i,padding:s,clueColor:a}){if(!(!t||t.length<2||!n)){e.save();for(let r=1;r<t.length;r++){const c=t[r-1],l=t[r],d=`${c.row},${c.col}-${l.row},${l.col}`,u=`${l.row},${l.col}-${c.row},${c.col}`,h=(n[d]||0)+(n[u]||0),f=Math.min(.2+h*.1,.9),m=Math.max(3,o*.1)+h*.5;try{e.strokeStyle=a.replace(")",`, ${f})`).replace("rgb(","rgba(")}catch{e.strokeStyle=`rgba(255, 0, 0, ${f})`}e.lineWidth=m,e.lineCap="round",e.lineJoin="round";const{x:g,y:v}=Z(c.row,c.col,o,i,s),{x:w,y}=Z(l.row,l.col,o,i,s);e.beginPath(),e.moveTo(g,v),e.lineTo(w,y),e.stroke()}e.restore()}}function bt(e,t,n,o,i){if(!e||!t.maze)return;const{canvasWidth:s,canvasHeight:a}=n,{cellWidth:r,cellHeight:c}=o,{maze:l,playerCell:d,exitCell:u,foodCells:h,showClue:f,playerPath:m,visitCounts:g}=t,{padding:v,wallWidth:w,wallColor:y,playerColor:T,playerRadius:p,foodColor:z,backgroundColor:C,clueColor:S,fogEnabled:k,fogRadius:L,fogColor:E,fogSoftness:M,exitColor:b,exitWallWidth:A,exitDashArray:P}=i;e.clearRect(0,0,s,a),e.save(),e.fillStyle=C,e.fillRect(0,0,s,a),e.restore(),f&&Mn({ctx:e,playerPath:m,visitCounts:g,cellWidth:r,cellHeight:c,padding:v,clueColor:S});const R=yt(l,r,c,v);k&&Cn({ctx:e,canvasWidth:s,canvasHeight:a,cellWidth:r,cellHeight:c,padding:v,playerCell:d,walls:R,fogRadius:L,fogColor:E,fogSoftness:M}),Sn({ctx:e,maze:l,cellWidth:r,cellHeight:c,padding:v,wallColor:y,wallWidth:w,walls:R}),En({ctx:e,maze:l,exitCell:u,cellWidth:r,cellHeight:c,padding:v,exitColor:b,exitWallWidth:A,exitDashArray:P}),kn({ctx:e,playerCell:d,playerRadius:p,cellWidth:r,cellHeight:c,padding:v,playerColor:T}),zn({ctx:e,foodCells:h,cellWidth:r,cellHeight:c,padding:v,foodColor:z})}function Ln(e){return function(){let t=e+=1831565813;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}}class Nn{constructor(t,n){this.row=t,this.col=n}visited=!1;walls={top:!0,right:!0,bottom:!0,left:!0}}class Tt{rows;cols;grid;seed;random;constructor(t,n,o,i,s={row:0,col:0},a={row:t-1,col:n-1}){this.rows=t,this.cols=n,this.seed=i??Math.floor(Math.random()*1e6),this.random=Ln(this.seed),this.grid=this.initializeGrid(),this.generate(o,s,a)}initializeGrid(){const t=[];for(let n=0;n<this.rows;n++){t[n]=[];for(let o=0;o<this.cols;o++)t[n][o]=new Nn(n,o)}return t}isValid(t,n){return t>=0&&t<this.rows&&n>=0&&n<this.cols}getNeighbors(t,n){const o=[],i=[{r:-1,c:0},{r:0,c:1},{r:1,c:0},{r:0,c:-1}];for(const s of i){const a=t+s.r,r=n+s.c;this.isValid(a,r)&&o.push({row:a,col:r})}return o}getUnvisitedNeighbors(t,n){return this.getNeighbors(t,n).filter(o=>!this.grid[o.row][o.col].visited)}getVisitedNeighbors(t,n){return this.getNeighbors(t,n).filter(o=>this.grid[o.row][o.col].visited)}removeWall(t,n,o,i){const s=this.grid[t][n],a=this.grid[o][i];t===o+1?(s.walls.top=!1,a.walls.bottom=!1):t===o-1?(s.walls.bottom=!1,a.walls.top=!1):n===i+1?(s.walls.left=!1,a.walls.right=!1):n===i-1&&(s.walls.right=!1,a.walls.left=!1)}generate(t,n={row:0,col:0},o={row:this.rows-1,col:this.cols-1}){switch(t){case"backtracking":this.generateWithBacktracking();break;case"prims":this.generateWithPrims();break;default:throw new Error(`Unknown maze generation method: ${t}`)}this.addOpenings(n,o)}generateWithBacktracking(){const t=[],n=this.randomNumber(this.rows),o=this.randomNumber(this.cols);let i={row:n,col:o};for(this.grid[n][o].visited=!0,t.push(i);t.length>0;){i=t[t.length-1];const{row:s,col:a}=i,r=this.getUnvisitedNeighbors(s,a);if(r.length>0){const c=this.randomPick(r),{row:l,col:d}=c;this.removeWall(s,a,l,d),this.grid[l][d].visited=!0,t.push(c)}else t.pop()}}generateWithPrims(){const t=[],n=(s,a)=>{const r=this.getNeighbors(s,a);for(const c of r)!this.grid[c.row][c.col].visited&&!t.some(l=>l.row===c.row&&l.col===c.col)&&t.push(c)},o=this.randomNumber(this.rows),i=this.randomNumber(this.cols);for(this.grid[o][i].visited=!0,n(o,i);t.length>0;){const s=this.randomNumber(t.length),a=t[s],{row:r,col:c}=a,l=this.getVisitedNeighbors(r,c);if(l.length>0){const d=this.randomPick(l);this.removeWall(r,c,d.row,d.col),this.grid[r][c].visited=!0,n(r,c)}t.splice(s,1)}}addOpenings(t,n){this.grid[t.row][t.col].walls.top=!1,this.isValid(n.row,n.col)&&(this.grid[n.row][n.col].walls.bottom=!1)}randomNumber(t){return Math.floor(this.random()*t)}randomPick(t){return t[Math.floor(this.random()*t.length)]}}const St=(e,t,n)=>{if(!e.isValid(t,n))return!1;const o=e.grid[t][n];return!o.walls.top||!o.walls.right||!o.walls.bottom||!o.walls.left},An=e=>e===1?2:e>=2&&e<=5?3:e>=6&&e<=11?4:e>=12&&e<=15?5:6,Pn=(e,t)=>{if(!t)return console.error(`Cannot find Level ${e}'s config.`),null;const{size:n,seed:o,method:i,entry:s,exit:a}=t,r=n,c=n,l=s||{row:0,col:0},d=a||{row:r-1,col:c-1},u=new Tt(r,c,i,o,l,d),h=An(e),f=[];for(let m=0;m<h;m++){let g;do g={row:Math.floor(u.random()*r),col:Math.floor(u.random()*c)};while(g.row===l.row&&g.col===l.col||g.row===d.row&&g.col===d.col||!St(u,g.row,g.col)||f.some(v=>v.row===g.row&&v.col===g.col));f.push(g)}return{isGameActive:!0,levelTransitioning:!1,maze:u,playerCell:l,exitCell:d,foodCells:f,playerAtExit:!1,foodCollected:0,totalFoodCount:h,showClue:!1,playerPath:[l],visitCounts:{[`${l.row},${l.col}`]:1}}},xn=({size:e,seed:t,method:n,foodCount:o,foodRace:i,clue:s,fogEnabled:a=!0})=>{const r=e,c=e,l={row:0,col:0},d={row:r-1,col:c-1},u=new Tt(r,c,n,t,l,d),h=[];if(i)for(let f=0;f<o;f++){let m,g=0;do m={row:Math.floor(u.random()*r),col:Math.floor(u.random()*c)},g++;while(g<50&&(m.row===l.row&&m.col===l.col||m.row===d.row&&m.col===d.col||!St(u,m.row,m.col)||h.some(v=>v.row===m.row&&v.col===m.col)));g<50&&h.push(m)}return{isGameActive:!0,levelTransitioning:!1,maze:u,playerCell:l,exitCell:d,foodCells:h,playerAtExit:!1,foodCollected:0,totalFoodCount:i?o:0,fogEnabled:a,showClue:s,playerPath:[l],visitCounts:{[`${l.row},${l.col}`]:1}}};function In(){const{setGamePlayState:e,gamePlayState:t,gamePlayStateRef:n,gameProgress:o,config:i}=oe(),s=D(null),a=D(null),{i18n:r,levelConfig:c,renderConfig:l}=i,d=re(c),u=D(d.getLevelConfig(o.currentLevel));I(()=>{s.current&&j.attachTo(s.current)},[]);const h=D(),f=gt(a,()=>{h.current?.()}),m=pt(a,t,l.padding);I(()=>{u.current=d.getLevelConfig(o.currentLevel)},[o.currentLevel]);const g=()=>{const T=Pn(o.currentLevel,u.current);T&&e(p=>({...p,...T}))};I(()=>{g()},[o.currentLevel]);const v=()=>{g()},{updatePlayerPos:w,resetMovingState:y}=wt({gamePlayStateRef:n,setGamePlayState:e,playerRadius:l.playerRadius,moveSpeed:l.gridMoveSpeed,onFoodCollected:()=>{const T=n.current.totalFoodCount-n.current.foodCollected-1;T>0?j.show(r.foodCollectedToast.replace("%NUM%",T.toString()),3e3):j.show(r.allFoodCollectedToast)}});return I(()=>{y()},[o.currentLevel,y]),I(()=>{let T,p=!document.hidden;const z=()=>{const k=a.current?.getContext("2d"),L=n.current;if(!(p&&L?.isGameActive&&k&&L?.maze)){T=requestAnimationFrame(z);return}w(),C(),T=requestAnimationFrame(z)},C=()=>{const k=a.current?.getContext("2d"),L=n.current;if(k&&L?.maze){const E=u.current?.wallWidth||l?.wallWidth,M=u.current?.exitColor||l?.exitColor,b=u.current?.exitWallWidth||l?.exitWallWidth,A=u.current?.exitDashArray||l?.exitDashArray,P=u.current?.fogRadius||l?.fogRadius,R=u.current?.fogEnabled??l?.fogEnabled;bt(k,L,f.current,m.current,{...l,wallWidth:E,exitColor:M,exitWallWidth:b,exitDashArray:A,fogRadius:P,fogEnabled:R})}};h.current=C;const S=k=>{const L=p;p=!document.hidden&&document.visibilityState==="visible"&&(!k||k.type!=="blur"),!L&&p?n.current?.levelTransitioning===!1&&e({...n.current,isGameActive:!0}):L&&!p&&e({...n.current,isGameActive:!1})};return document.addEventListener("visibilitychange",S),window.addEventListener("blur",S),window.addEventListener("focus",S),T=requestAnimationFrame(z),()=>{cancelAnimationFrame(T),document.removeEventListener("visibilitychange",S),window.removeEventListener("blur",S),window.removeEventListener("focus",S)}},[]),I(()=>{j.show(r.useArrowKeyTips,3e3)},[]),_("div",{className:"maze-game-container",children:[_(qt,{}),_(_n,{onRetry:v}),_("div",{className:"maze-canvas-container",ref:s,children:_("canvas",{ref:a,className:"maze-game-canvas"})})]})}const Rn=e=>{const t=Math.floor(e/60),n=e%60;return`${t.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`},Fn=({timer:e})=>{const[t,n]=U(e),o=D(),i=D(!1),s=D(0);return I(()=>{const a=()=>{!i.current&&!o.current&&(i.current=!0,o.current=setInterval(()=>{n(c=>(s.current=e-c+1,c<=1?(clearInterval(o.current),window.dispatchEvent(new CustomEvent("maze:timeUp")),0):c-1))},1e3))},r=()=>{clearInterval(o.current),o.current=void 0,window.dispatchEvent(new CustomEvent("maze:timeUsed",{detail:{timeUsed:s.current}}))};return window.addEventListener("maze:firstMove",a),window.addEventListener("maze:gameSuccess",r),()=>{window.removeEventListener("maze:firstMove",a),window.removeEventListener("maze:gameSuccess",r),clearInterval(o.current)}},[e]),I(()=>{o.current&&(clearInterval(o.current),o.current=void 0),n(e),i.current=!1,s.current=0},[e]),_("div",{className:"single-maze-timer",children:_("span",{className:`maze-timer-text ${t<=10&&i.current?"maze-timer-warning":""}`,children:["⏱️ ",Rn(t)]})})};function Dn({config:e}){const{size:t,seed:n,method:o,foodCount:i,foodRace:s,clue:a,renderConfig:r,successCallback:c,failCallback:l,timer:d,i18n:u}=e,h=r.fogEnabled??!0,[f,m]=U({...ut,fogEnabled:h}),[g,v]=U(!1),[w,y]=U(!0),[T,p]=U(!1),[z,C]=U(""),S=D(0),k=D(!1),L=D(!1),E=D(null),M=D(null),b=D(f),A=D(),P=gt(E,()=>{A.current?.()}),R=pt(E,f,r.padding);I(()=>{b.current=f},[f]);const{updatePlayerPos:$,resetMovingState:G,resetFirstMoveState:X}=wt({gamePlayStateRef:b,setGamePlayState:m,playerRadius:r.playerRadius,moveSpeed:r.gridMoveSpeed,onFoodCollected:()=>{console.log("Food collected in single maze")},onExitReached:()=>{if(!k.current){if(s&&b.current.foodCollected<b.current.totalFoodCount){C(`⭐️ ${u.foodMsg}`),p(!0),m(F=>({...F,isGameActive:!1}));return}m(F=>({...F,isGameActive:!1})),ee()}},onFirstMove:()=>{window.dispatchEvent(new CustomEvent("maze:firstMove"))}}),V=()=>{k.current=!0,C(`⏰ ${u.failMsg}`),p(!0),m({...b.current,isGameActive:!1})},ee=()=>{k.current=!0,L.current=!0,C(`🎉 ${u.successMsg}`),p(!0),m(F=>({...F,isGameActive:!1})),window.dispatchEvent(new CustomEvent("maze:gameSuccess"))},Y=()=>{if(p(!1),!k.current){m(F=>({...F,isGameActive:!0}));return}y(!1),m(F=>({...F,showClue:!0})),L.current?c?.(S.current):l?.()};return I(()=>{(async()=>{v(!0);try{const q=xn({size:t,seed:n,method:o,foodCount:i,foodRace:s,clue:a,fogEnabled:b.current.fogEnabled??h});b.current=q,m(q)}catch(q){console.error("Error generating single maze:",q)}finally{v(!1)}})()},[e,h]),I(()=>{let F;const q=!document.hidden,se=()=>{const Ce=E.current?.getContext("2d"),ae=b.current;if(!(q&&ae?.isGameActive&&Ce&&ae?.maze)){F=requestAnimationFrame(se);return}$(),zt(),F=requestAnimationFrame(se)},zt=()=>{const Ce=E.current?.getContext("2d"),ae=b.current;Ce&&ae?.maze&&bt(Ce,ae,P.current,R.current,r)};return A.current=zt,F=requestAnimationFrame(se),()=>{cancelAnimationFrame(F)}},[]),I(()=>{G(),X()},[e,G,X]),I(()=>{const F=q=>{S.current=q.detail.timeUsed};return window.addEventListener("maze:timeUsed",F),window.addEventListener("maze:timeUp",V),()=>{window.removeEventListener("maze:timeUsed",F),window.removeEventListener("maze:timeUp",V)}},[]),g?_("div",{className:"single-maze-loading",children:_("div",{children:"Generating maze..."})}):f?_("div",{className:"maze-game-container",children:[_("div",{className:"single-maze-toolbar",children:w&&_(Fn,{timer:d})}),_("div",{className:"single-maze-canvas-container",ref:M,children:_("canvas",{ref:E,className:"maze-game-canvas"})}),_(ie,{isOpen:T,title:z,noConfirm:!0,cancelText:"OK",onCancel:Y})]}):_("div",{className:"single-maze-error",children:_("div",{children:"Failed to generate maze"})})}const kt=[[{size:8,seed:12345,method:"backtracking",wallWidth:4,exitWallWidth:6,exitDashArray:[8,12]},{size:8,seed:23456,fogEnabled:!0,method:"backtracking",exitColor:"#33f",exitWallWidth:4,exitDashArray:[8,16]},{size:8,seed:34567,method:"prims"},{size:8,seed:45678,method:"backtracking"},{size:9,seed:56789,method:"prims"},{size:9,seed:67890,method:"backtracking"},{size:9,seed:78901,method:"prims"},{size:9,seed:89012,method:"backtracking"},{size:10,seed:90123,method:"prims"},{size:11,seed:11111,method:"backtracking"},{size:12,seed:22222,method:"prims"},{size:13,seed:33333,method:"backtracking"}],[{size:12,seed:44444,method:"prims"},{size:12,seed:55555,method:"backtracking"},{size:12,seed:66666,method:"prims"},{size:12,seed:77777,method:"backtracking"},{size:13,seed:88888,method:"prims"},{size:13,seed:99999,method:"backtracking"},{size:13,seed:12121,method:"prims"},{size:14,seed:23232,method:"backtracking"},{size:15,seed:34343,method:"prims"},{size:16,seed:45454,method:"backtracking"},{size:17,seed:56565,method:"prims"},{size:18,seed:67676,method:"backtracking"}],[{size:19,seed:78787,method:"prims"},{size:20,seed:89898,method:"backtracking"},{size:21,seed:90909,method:"prims"},{size:22,seed:10101,method:"backtracking"},{size:23,seed:20202,method:"prims"},{size:25,seed:30303,method:"backtracking"},{size:27,seed:40404,method:"prims"},{size:29,seed:50505,method:"backtracking"},{size:31,seed:60606,method:"prims"},{size:33,seed:70707,method:"backtracking"},{size:37,seed:80808,method:"prims"},{size:40,seed:90909,method:"backtracking"}],[{size:41,seed:10111,method:"prims"},{size:42,seed:11121,method:"backtracking"},{size:43,seed:12131,method:"prims"},{size:44,seed:13141,method:"backtracking"},{size:45,seed:14151,method:"prims"},{size:46,seed:15161,method:"backtracking"},{size:47,seed:16171,method:"prims"},{size:48,seed:17181,method:"backtracking"},{size:49,seed:18191,method:"prims"},{size:50,seed:19201,method:"backtracking"},{size:51,seed:20211,method:"prims"},{size:52,seed:21221,method:"backtracking"}],[{size:53,seed:22231,method:"prims"},{size:54,seed:23241,method:"backtracking"},{size:55,seed:24251,method:"prims"},{size:56,seed:25261,method:"backtracking"},{size:57,seed:26271,method:"prims"},{size:58,seed:27281,method:"backtracking"},{size:59,seed:28291,method:"prims"},{size:60,seed:29301,method:"backtracking"},{size:62,seed:30311,method:"prims"},{size:64,seed:31321,method:"backtracking"},{size:66,seed:32331,method:"prims"},{size:68,seed:33341,method:"backtracking"}]],Et={gridMoveSpeed:.07,padding:10,wallWidth:2,wallColor:"#222",foodColor:"#FFD54F",clueColor:"rgb(255,0,0)",backgroundColor:"#ffffff",playerColor:"#4CAF50",playerRadius:.2,fogEnabled:!1,fogRadius:3.6,fogColor:"rgba(8, 10, 18, 0.9)",fogSoftness:.55,exitColor:"#F44336",exitWallWidth:4,exitDashArray:[8,12]},pe={lcPrefix:"maze-",i18n:{reset:"Reset",resetTip:"Reset all game data and highest score.",confirmReset:"Confirm Reset",confirmResetMessage:"Are you sure you want to reset the game? All progress will be lost.",cancel:"Cancel",close:"Close",confirm:"Confirm",resetDoneToast:"Game reset! Starting from Level 1...",confirmClue:"Confirm to turn on clue?",confirmClueMessage:"Are you sure you want to turn on clue? Your will lose 1 ★.",level:"Level",tier:"Tier",settings:"Settings",clueOn:"Clue: ON",clueOff:"Clue: OFF",foodCollectedToast:"Food collected! %NUM% remaining.",allFoodCollectedToast:"All food collected! Head to the exit.",congratulations:"Congratulations!",findYourExit:"Find your exit!",withoutClue:"Without clue!",withClue:"You used the clue!",collectAllStars:"Collect all stars!",notCollectAllStars:"Not collect all stars.",nextLevel:"Next Level ➤",spacebarTip:"Spacebar",retry:"Retry",levelComplete:"Level Complete",starsCollected:"Stars Collected",avgStarPerLevel:"Avg. Stars per Level",levelCompleteToast:"Level completed! 🎉",tierUnlockedToast:"Tier %TIER% unlocked! 🎉",levelGoToast:"Level %LEVEL% - Go!",levelRestartToast:"Level restarted",allLevelsCompleted:"You completed all levels!",lastOK:"OK",notCompleteLevel:"You still have levels not collected all stars! Try again to collect them all!",continueMessage:"You still have levels where you haven't collected all stars. Try again to collect them all!",continue:"Continue",cluePathEnabled:"Clue Path Enabled",cluePathDisabled:"Clue Path Disabled",useArrowKeyTips:"Use arrow keys to navigate the maze. Press'C' to toggle path clue.",fogOn:"Fog: ON",fogOff:"Fog: OFF",fogEnabledToast:"Fog enabled",fogDisabledToast:"Fog disabled"},renderConfig:Et,levelConfig:kt},we={i18n:{successMsg:"Congratulations! You completed the maze!",failMsg:"Time is up!",foodMsg:"Please collect all stars before leaving!",fogOn:"Fog: ON",fogOff:"Fog: OFF"},size:8,seed:12345,method:"backtracking",clue:!1,foodCount:0,foodRace:!1,renderConfig:Et,timer:600,successCallback:()=>{console.log("🎉 Single maze completed successfully!")},failCallback:()=>{console.log("⏰ Time is up! Game failed.")}};function On({config:e={}}){const t={...pe.i18n,...e.i18n||{}},n={...pe.renderConfig,...e.renderConfig||{}},o=e.levelConfig||kt,i={...pe,...e,i18n:t,levelConfig:o,renderConfig:n};return _(Gt,{config:i,children:_(In,{})})}function $n({config:e={}}){const t={...we.i18n,...e.i18n||{}},n={...we.renderConfig,...e.renderConfig||{}},o={...we,...e,i18n:t,renderConfig:n};return _(Dn,{config:o})}const Un={root:"https://unpkg.com/@roudanio/maze@0.3.2/dist/",...pe};`${JSON.stringify(Un,null,2)}`;const Gn={root:"https://unpkg.com/@roudanio/maze@0.3.2/dist/",...we};return`${JSON.stringify(Gn,(e,t)=>typeof t=="function"?t.toString():t,2)}`,{showNotice(){console.warn("Cannot find the root element");const e=document.createElement("div");e.style.textAlign="center",e.style.padding="20px",e.innerHTML="Cannot find the root element",document.body.append(e)},addLoadingIndicator(e){const t=document.createElement("div"),n=document.createElement("div");t.style.cssText=`
|
|
2
2
|
height: 30px;
|
|
3
3
|
width: 100%;
|
|
4
4
|
border: solid 2px #999;
|
package/dist/maze.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var ge, N, nt, Y,
|
|
1
|
+
var ge, N, nt, Y, Re, ot, rt, it, Me, Te, Se, st, re = {}, at = [], Mt = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i, pe = Array.isArray;
|
|
2
2
|
function V(e, t) {
|
|
3
3
|
for (var n in t) e[n] = t[n];
|
|
4
4
|
return e;
|
|
@@ -38,7 +38,7 @@ function lt(e) {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
function ke(e) {
|
|
41
|
-
(!e.__d && (e.__d = !0) && Y.push(e) && !ve.__r++ ||
|
|
41
|
+
(!e.__d && (e.__d = !0) && Y.push(e) && !ve.__r++ || Re != N.debounceRendering) && ((Re = N.debounceRendering) || ot)(ve);
|
|
42
42
|
}
|
|
43
43
|
function ve() {
|
|
44
44
|
for (var e, t, n, o, i, s, a, r = 1; Y.length; ) Y.length > r && Y.sort(rt), e = Y.shift(), r = Y.length, e.__d && (n = void 0, o = void 0, i = (o = (t = e).__v).__e, s = [], a = [], t.__P && ((n = V({}, o)).__v = o.__v + 1, N.vnode && N.vnode(n), Ne(t.__P, n, o, t.__n, t.__P.namespaceURI, 32 & o.__u ? [i] : null, s, i ?? J(o), !!(32 & o.__u), a), n.__v = o.__v, n.__.__k[n.__i] = n, dt(s, n, a), o.__e = o.__ = null, n.__e != i && lt(n)));
|
|
@@ -75,15 +75,15 @@ function At(e, t, n, o) {
|
|
|
75
75
|
}
|
|
76
76
|
return -1;
|
|
77
77
|
}
|
|
78
|
-
function
|
|
78
|
+
function Fe(e, t, n) {
|
|
79
79
|
t[0] == "-" ? e.setProperty(t, n ?? "") : e[t] = n == null ? "" : typeof n != "number" || Mt.test(t) ? n : n + "px";
|
|
80
80
|
}
|
|
81
81
|
function ce(e, t, n, o, i) {
|
|
82
82
|
var s, a;
|
|
83
83
|
e: if (t == "style") if (typeof n == "string") e.style.cssText = n;
|
|
84
84
|
else {
|
|
85
|
-
if (typeof o == "string" && (e.style.cssText = o = ""), o) for (t in o) n && t in n ||
|
|
86
|
-
if (n) for (t in n) o && n[t] == o[t] ||
|
|
85
|
+
if (typeof o == "string" && (e.style.cssText = o = ""), o) for (t in o) n && t in n || Fe(e.style, t, "");
|
|
86
|
+
if (n) for (t in n) o && n[t] == o[t] || Fe(e.style, t, n[t]);
|
|
87
87
|
}
|
|
88
88
|
else if (t[0] == "o" && t[1] == "n") s = t != (t = t.replace(it, "$1")), a = t.toLowerCase(), t = a in e || t == "onFocusOut" || t == "onFocusIn" ? a.slice(2) : t.slice(2), e.l || (e.l = {}), e.l[t + s] = n, n ? o ? n.u = o.u : (n.u = Me, e.addEventListener(t, s ? Se : Te, s)) : e.removeEventListener(t, s ? Se : Te, s);
|
|
89
89
|
else {
|
|
@@ -260,12 +260,12 @@ ge = at.slice, N = { __e: function(e, t, n, o) {
|
|
|
260
260
|
}, he.prototype.render = we, Y = [], ot = typeof Promise == "function" ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout, rt = function(e, t) {
|
|
261
261
|
return e.__v.__b - t.__v.__b;
|
|
262
262
|
}, ve.__r = 0, it = /(PointerCapture)$|Capture$/i, Me = 0, Te = De(!1), Se = De(!0), st = 0;
|
|
263
|
-
var
|
|
263
|
+
var Rt = 0;
|
|
264
264
|
function _(e, t, n, o, i, s) {
|
|
265
265
|
t || (t = {});
|
|
266
266
|
var a, r, c = t;
|
|
267
267
|
if ("ref" in c) for (r in c = {}, t) r == "ref" ? a = t[r] : c[r] = t[r];
|
|
268
|
-
var l = { type: e, props: c, key: n, ref: a, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: --
|
|
268
|
+
var l = { type: e, props: c, key: n, ref: a, __k: null, __: null, __b: 0, __e: null, __c: null, constructor: void 0, __v: --Rt, __i: -1, __u: 0, __source: i, __self: s };
|
|
269
269
|
if (typeof e == "function" && (a = e.defaultProps)) for (r in a) c[r] === void 0 && (c[r] = a[r]);
|
|
270
270
|
return N.vnode && N.vnode(l), l;
|
|
271
271
|
}
|
|
@@ -276,9 +276,9 @@ function Ce(e, t) {
|
|
|
276
276
|
return e >= n.__.length && n.__.push({}), n.__[e];
|
|
277
277
|
}
|
|
278
278
|
function G(e) {
|
|
279
|
-
return ie = 1,
|
|
279
|
+
return ie = 1, Ft(vt, e);
|
|
280
280
|
}
|
|
281
|
-
function
|
|
281
|
+
function Ft(e, t, n) {
|
|
282
282
|
var o = Ce(Q++, 2);
|
|
283
283
|
if (o.t = e, !o.__c && (o.__ = [vt(void 0, t), function(r) {
|
|
284
284
|
var c = o.__N ? o.__N[0] : o.__[0], l = o.t(c, r);
|
|
@@ -316,7 +316,7 @@ function F(e, t) {
|
|
|
316
316
|
var n = Ce(Q++, 3);
|
|
317
317
|
!O.__s && _t(n.__H, t) && (n.__ = e, n.u = t, x.__H.__h.push(n));
|
|
318
318
|
}
|
|
319
|
-
function
|
|
319
|
+
function D(e) {
|
|
320
320
|
return ie = 5, ee(function() {
|
|
321
321
|
return { current: e };
|
|
322
322
|
}, []);
|
|
@@ -440,7 +440,7 @@ const Ut = (e) => ({
|
|
|
440
440
|
playerCell: { row: 0, col: 0 },
|
|
441
441
|
exitCell: { row: 0, col: 0 },
|
|
442
442
|
foodCells: [],
|
|
443
|
-
fogEnabled: !
|
|
443
|
+
fogEnabled: !1,
|
|
444
444
|
playerAtExit: !1,
|
|
445
445
|
foodCollected: 0,
|
|
446
446
|
totalFoodCount: 0,
|
|
@@ -470,7 +470,7 @@ const Ut = (e) => ({
|
|
|
470
470
|
]);
|
|
471
471
|
const [c, l] = G({
|
|
472
472
|
...s()
|
|
473
|
-
}), d =
|
|
473
|
+
}), d = D(c);
|
|
474
474
|
F(() => {
|
|
475
475
|
d.current = c;
|
|
476
476
|
}, [c]);
|
|
@@ -611,7 +611,7 @@ const Ut = (e) => ({
|
|
|
611
611
|
onConfirm: u,
|
|
612
612
|
onCancel: h
|
|
613
613
|
}) => {
|
|
614
|
-
const f =
|
|
614
|
+
const f = D(null);
|
|
615
615
|
return F(() => {
|
|
616
616
|
const m = (g) => {
|
|
617
617
|
g.key === "Escape" && h?.();
|
|
@@ -656,11 +656,11 @@ const Ut = (e) => ({
|
|
|
656
656
|
this.container.removeChild(this.container.firstChild);
|
|
657
657
|
}
|
|
658
658
|
}, qt = () => {
|
|
659
|
-
const { gameProgress: e, setGameProgress: t, gamePlayState: n, setGamePlayState: o, gamePlayStateRef: i, resetGame: s, config: a } = se(), { i18n: r, levelConfig: c } = a, l = ae(c), { levelTransitioning: d, showClue: u } = n, { highestUnlockedLevel: h, totalScore: f } = e, m = l.getTotalLevels(), [g, v] = G(!1), [w, y] = G(!1), [T, p] = G(!1), z = (
|
|
660
|
-
const $ = l.getFirstLevelOfTier(
|
|
661
|
-
l.isLevelUnlocked($, h) && (t((U) => ({ ...U, currentTier:
|
|
662
|
-
}, C = (
|
|
663
|
-
l.isLevelUnlocked(
|
|
659
|
+
const { gameProgress: e, setGameProgress: t, gamePlayState: n, setGamePlayState: o, gamePlayStateRef: i, resetGame: s, config: a } = se(), { i18n: r, levelConfig: c } = a, l = ae(c), { levelTransitioning: d, showClue: u } = n, { highestUnlockedLevel: h, totalScore: f } = e, m = l.getTotalLevels(), [g, v] = G(!1), [w, y] = G(!1), [T, p] = G(!1), z = (I) => {
|
|
660
|
+
const $ = l.getFirstLevelOfTier(I);
|
|
661
|
+
l.isLevelUnlocked($, h) && (t((U) => ({ ...U, currentTier: I })), C($));
|
|
662
|
+
}, C = (I) => {
|
|
663
|
+
l.isLevelUnlocked(I, h) && (t(($) => ({ ...$, currentLevel: I })), q.show(r.levelGoToast.replace("%LEVEL%", I.toString())));
|
|
664
664
|
}, S = () => {
|
|
665
665
|
v(!0);
|
|
666
666
|
}, k = () => {
|
|
@@ -977,8 +977,8 @@ const mn = new fn(), be = 3, _n = ({ onRetry: e }) => {
|
|
|
977
977
|
[E.currentLevel]: M
|
|
978
978
|
};
|
|
979
979
|
let A = 0, P = 0;
|
|
980
|
-
const
|
|
981
|
-
for (const [$, U] of
|
|
980
|
+
const I = Object.entries(b).sort(($, U) => Number($[0]) - Number(U[0]));
|
|
981
|
+
for (const [$, U] of I)
|
|
982
982
|
if (U < be) {
|
|
983
983
|
A = Number($), P = T.getTierByLevel(A);
|
|
984
984
|
break;
|
|
@@ -1027,7 +1027,7 @@ const mn = new fn(), be = 3, _n = ({ onRetry: e }) => {
|
|
|
1027
1027
|
}
|
|
1028
1028
|
);
|
|
1029
1029
|
}, wt = (e, t) => {
|
|
1030
|
-
const n =
|
|
1030
|
+
const n = D({
|
|
1031
1031
|
canvasWidth: 0,
|
|
1032
1032
|
canvasHeight: 0
|
|
1033
1033
|
});
|
|
@@ -1052,7 +1052,7 @@ const mn = new fn(), be = 3, _n = ({ onRetry: e }) => {
|
|
|
1052
1052
|
};
|
|
1053
1053
|
}, [e, t]), n;
|
|
1054
1054
|
}, Ct = (e, t, n) => {
|
|
1055
|
-
const o =
|
|
1055
|
+
const o = D({ cellWidth: 0, cellHeight: 0 });
|
|
1056
1056
|
return F(() => {
|
|
1057
1057
|
const i = () => {
|
|
1058
1058
|
const a = e.current, r = t.maze;
|
|
@@ -1086,7 +1086,7 @@ const mn = new fn(), be = 3, _n = ({ onRetry: e }) => {
|
|
|
1086
1086
|
onExitReached: a,
|
|
1087
1087
|
onFirstMove: r
|
|
1088
1088
|
}) => {
|
|
1089
|
-
const c = () => o?.current ?? n ?? 0.03, l =
|
|
1089
|
+
const c = () => o?.current ?? n ?? 0.03, l = D(!1), d = D(/* @__PURE__ */ new Set()), u = D(!1), h = Ve(
|
|
1090
1090
|
(T, p) => {
|
|
1091
1091
|
const z = e.current;
|
|
1092
1092
|
if (!z.maze)
|
|
@@ -1101,8 +1101,8 @@ const mn = new fn(), be = 3, _n = ({ onRetry: e }) => {
|
|
|
1101
1101
|
z.maze
|
|
1102
1102
|
))
|
|
1103
1103
|
return { canMove: !1, newCell: null };
|
|
1104
|
-
const { row: E, col: M } = p, b = E + S * C, A = M + k * C, P = -0.5,
|
|
1105
|
-
if (b < P || b >=
|
|
1104
|
+
const { row: E, col: M } = p, b = E + S * C, A = M + k * C, P = -0.5, I = z.maze.rows, $ = z.maze.cols;
|
|
1105
|
+
if (b < P || b >= I || A < P || A >= $)
|
|
1106
1106
|
return { canMove: !1, newCell: null };
|
|
1107
1107
|
const U = E < 0 ? 0 : Math.floor(E), H = M < 0 ? 0 : Math.floor(M), B = b < 0 ? 0 : Math.floor(b), K = A < 0 ? 0 : Math.floor(A);
|
|
1108
1108
|
return B !== U || K !== H ? z.maze.isValid(B, K) ? {
|
|
@@ -1189,23 +1189,23 @@ const mn = new fn(), be = 3, _n = ({ onRetry: e }) => {
|
|
|
1189
1189
|
const T = c(), p = e.current.playerCell;
|
|
1190
1190
|
let z = 0, C = 0, S = 0;
|
|
1191
1191
|
for (const X of d.current) {
|
|
1192
|
-
const { canMove:
|
|
1193
|
-
if (
|
|
1192
|
+
const { canMove: R } = h(X, p);
|
|
1193
|
+
if (R) {
|
|
1194
1194
|
const [j, te] = ue[X];
|
|
1195
1195
|
z += j, C += te, S++;
|
|
1196
1196
|
}
|
|
1197
1197
|
}
|
|
1198
1198
|
if (S === 0)
|
|
1199
1199
|
return e.current.playerCell;
|
|
1200
|
-
const k = Math.sqrt(z * z + C * C), L = k > 0 ? z / k : 0, E = k > 0 ? C / k : 0, M = Number((p.row + L * T).toFixed(2)), b = Number((p.col + E * T).toFixed(2)), A = M - p.row, P = b - p.col,
|
|
1201
|
-
if (
|
|
1202
|
-
const X = A /
|
|
1200
|
+
const k = Math.sqrt(z * z + C * C), L = k > 0 ? z / k : 0, E = k > 0 ? C / k : 0, M = Number((p.row + L * T).toFixed(2)), b = Number((p.col + E * T).toFixed(2)), A = M - p.row, P = b - p.col, I = Math.sqrt(A * A + P * P);
|
|
1201
|
+
if (I > 0) {
|
|
1202
|
+
const X = A / I, R = P / I;
|
|
1203
1203
|
if (tt(
|
|
1204
1204
|
p,
|
|
1205
1205
|
X,
|
|
1206
|
-
|
|
1206
|
+
R,
|
|
1207
1207
|
i,
|
|
1208
|
-
|
|
1208
|
+
I,
|
|
1209
1209
|
e.current.maze
|
|
1210
1210
|
))
|
|
1211
1211
|
return e.current.playerCell;
|
|
@@ -1534,8 +1534,8 @@ function Tt(e, t, n, o, i) {
|
|
|
1534
1534
|
padding: v,
|
|
1535
1535
|
clueColor: S
|
|
1536
1536
|
});
|
|
1537
|
-
const
|
|
1538
|
-
|
|
1537
|
+
const I = bt(l, r, c, v);
|
|
1538
|
+
k && Cn({
|
|
1539
1539
|
ctx: e,
|
|
1540
1540
|
canvasWidth: s,
|
|
1541
1541
|
canvasHeight: a,
|
|
@@ -1543,7 +1543,7 @@ function Tt(e, t, n, o, i) {
|
|
|
1543
1543
|
cellHeight: c,
|
|
1544
1544
|
padding: v,
|
|
1545
1545
|
playerCell: d,
|
|
1546
|
-
walls:
|
|
1546
|
+
walls: I,
|
|
1547
1547
|
fogRadius: L,
|
|
1548
1548
|
fogColor: E,
|
|
1549
1549
|
fogSoftness: M
|
|
@@ -1555,7 +1555,7 @@ function Tt(e, t, n, o, i) {
|
|
|
1555
1555
|
padding: v,
|
|
1556
1556
|
wallColor: y,
|
|
1557
1557
|
wallWidth: w,
|
|
1558
|
-
walls:
|
|
1558
|
+
walls: I
|
|
1559
1559
|
}), En({
|
|
1560
1560
|
ctx: e,
|
|
1561
1561
|
maze: l,
|
|
@@ -1807,11 +1807,11 @@ const kt = (e, t, n) => {
|
|
|
1807
1807
|
};
|
|
1808
1808
|
};
|
|
1809
1809
|
function In() {
|
|
1810
|
-
const { setGamePlayState: e, gamePlayState: t, gamePlayStateRef: n, gameProgress: o, config: i } = se(), s =
|
|
1810
|
+
const { setGamePlayState: e, gamePlayState: t, gamePlayStateRef: n, gameProgress: o, config: i } = se(), s = D(null), a = D(null), { i18n: r, levelConfig: c, renderConfig: l } = i, d = ae(c), u = D(d.getLevelConfig(o.currentLevel));
|
|
1811
1811
|
F(() => {
|
|
1812
1812
|
s.current && q.attachTo(s.current);
|
|
1813
1813
|
}, []);
|
|
1814
|
-
const h =
|
|
1814
|
+
const h = D(), f = wt(a, () => {
|
|
1815
1815
|
h.current?.();
|
|
1816
1816
|
}), m = Ct(a, t, l.padding);
|
|
1817
1817
|
F(() => {
|
|
@@ -1853,13 +1853,15 @@ function In() {
|
|
|
1853
1853
|
}, C = () => {
|
|
1854
1854
|
const k = a.current?.getContext("2d"), L = n.current;
|
|
1855
1855
|
if (k && L?.maze) {
|
|
1856
|
-
const E = u.current?.wallWidth || l?.wallWidth, M = u.current?.exitColor || l?.exitColor, b = u.current?.exitWallWidth || l?.exitWallWidth, A = u.current?.exitDashArray || l?.exitDashArray;
|
|
1856
|
+
const E = u.current?.wallWidth || l?.wallWidth, M = u.current?.exitColor || l?.exitColor, b = u.current?.exitWallWidth || l?.exitWallWidth, A = u.current?.exitDashArray || l?.exitDashArray, P = u.current?.fogRadius || l?.fogRadius, I = u.current?.fogEnabled ?? l?.fogEnabled;
|
|
1857
1857
|
Tt(k, L, f.current, m.current, {
|
|
1858
1858
|
...l,
|
|
1859
1859
|
wallWidth: E,
|
|
1860
1860
|
exitColor: M,
|
|
1861
1861
|
exitWallWidth: b,
|
|
1862
|
-
exitDashArray: A
|
|
1862
|
+
exitDashArray: A,
|
|
1863
|
+
fogRadius: P,
|
|
1864
|
+
fogEnabled: I
|
|
1863
1865
|
});
|
|
1864
1866
|
}
|
|
1865
1867
|
};
|
|
@@ -1885,11 +1887,11 @@ function In() {
|
|
|
1885
1887
|
/* @__PURE__ */ _("div", { className: "maze-canvas-container", ref: s, children: /* @__PURE__ */ _("canvas", { ref: a, className: "maze-game-canvas" }) })
|
|
1886
1888
|
] });
|
|
1887
1889
|
}
|
|
1888
|
-
const
|
|
1890
|
+
const Rn = (e) => {
|
|
1889
1891
|
const t = Math.floor(e / 60), n = e % 60;
|
|
1890
1892
|
return `${t.toString().padStart(2, "0")}:${n.toString().padStart(2, "0")}`;
|
|
1891
|
-
},
|
|
1892
|
-
const [t, n] = G(e), o =
|
|
1893
|
+
}, Fn = ({ timer: e }) => {
|
|
1894
|
+
const [t, n] = G(e), o = D(), i = D(!1), s = D(0);
|
|
1893
1895
|
return F(() => {
|
|
1894
1896
|
const a = () => {
|
|
1895
1897
|
!i.current && !o.current && (i.current = !0, o.current = setInterval(() => {
|
|
@@ -1909,16 +1911,16 @@ const Fn = (e) => {
|
|
|
1909
1911
|
o.current && (clearInterval(o.current), o.current = void 0), n(e), i.current = !1, s.current = 0;
|
|
1910
1912
|
}, [e]), /* @__PURE__ */ _("div", { className: "single-maze-timer", children: /* @__PURE__ */ _("span", { className: `maze-timer-text ${t <= 10 && i.current ? "maze-timer-warning" : ""}`, children: [
|
|
1911
1913
|
"⏱️ ",
|
|
1912
|
-
|
|
1914
|
+
Rn(t)
|
|
1913
1915
|
] }) });
|
|
1914
1916
|
};
|
|
1915
1917
|
function Dn({ config: e }) {
|
|
1916
1918
|
const { size: t, seed: n, method: o, foodCount: i, foodRace: s, clue: a, renderConfig: r, successCallback: c, failCallback: l, timer: d, i18n: u } = e, h = r.fogEnabled ?? !0, [f, m] = G({
|
|
1917
1919
|
...pt,
|
|
1918
1920
|
fogEnabled: h
|
|
1919
|
-
}), [g, v] = G(!1), [w, y] = G(!0), [T, p] = G(!1), [z, C] = G(""), S =
|
|
1921
|
+
}), [g, v] = G(!1), [w, y] = G(!0), [T, p] = G(!1), [z, C] = G(""), S = D(0), k = D(!1), L = D(!1), E = D(null), M = D(null), b = D(f), A = D(), P = wt(E, () => {
|
|
1920
1922
|
A.current?.();
|
|
1921
|
-
}),
|
|
1923
|
+
}), I = Ct(E, f, r.padding);
|
|
1922
1924
|
F(() => {
|
|
1923
1925
|
b.current = f;
|
|
1924
1926
|
}, [f]);
|
|
@@ -1933,15 +1935,15 @@ function Dn({ config: e }) {
|
|
|
1933
1935
|
onExitReached: () => {
|
|
1934
1936
|
if (!k.current) {
|
|
1935
1937
|
if (s && b.current.foodCollected < b.current.totalFoodCount) {
|
|
1936
|
-
C(`⭐️ ${u.foodMsg}`), p(!0), m((
|
|
1937
|
-
...
|
|
1938
|
+
C(`⭐️ ${u.foodMsg}`), p(!0), m((R) => ({
|
|
1939
|
+
...R,
|
|
1938
1940
|
isGameActive: !1
|
|
1939
1941
|
// Disable controls while popup is shown
|
|
1940
1942
|
}));
|
|
1941
1943
|
return;
|
|
1942
1944
|
}
|
|
1943
|
-
m((
|
|
1944
|
-
...
|
|
1945
|
+
m((R) => ({
|
|
1946
|
+
...R,
|
|
1945
1947
|
isGameActive: !1
|
|
1946
1948
|
})), K();
|
|
1947
1949
|
}
|
|
@@ -1955,20 +1957,20 @@ function Dn({ config: e }) {
|
|
|
1955
1957
|
isGameActive: !1
|
|
1956
1958
|
});
|
|
1957
1959
|
}, K = () => {
|
|
1958
|
-
k.current = !0, L.current = !0, C(`🎉 ${u.successMsg}`), p(!0), m((
|
|
1959
|
-
...
|
|
1960
|
+
k.current = !0, L.current = !0, C(`🎉 ${u.successMsg}`), p(!0), m((R) => ({
|
|
1961
|
+
...R,
|
|
1960
1962
|
isGameActive: !1
|
|
1961
1963
|
})), window.dispatchEvent(new CustomEvent("maze:gameSuccess"));
|
|
1962
1964
|
}, X = () => {
|
|
1963
1965
|
if (p(!1), !k.current) {
|
|
1964
|
-
m((
|
|
1965
|
-
...
|
|
1966
|
+
m((R) => ({
|
|
1967
|
+
...R,
|
|
1966
1968
|
isGameActive: !0
|
|
1967
1969
|
}));
|
|
1968
1970
|
return;
|
|
1969
1971
|
}
|
|
1970
|
-
y(!1), m((
|
|
1971
|
-
...
|
|
1972
|
+
y(!1), m((R) => ({
|
|
1973
|
+
...R,
|
|
1972
1974
|
showClue: !0
|
|
1973
1975
|
})), L.current ? c?.(S.current) : l?.();
|
|
1974
1976
|
};
|
|
@@ -1993,32 +1995,32 @@ function Dn({ config: e }) {
|
|
|
1993
1995
|
}
|
|
1994
1996
|
})();
|
|
1995
1997
|
}, [e, h]), F(() => {
|
|
1996
|
-
let
|
|
1998
|
+
let R;
|
|
1997
1999
|
const j = !document.hidden, te = () => {
|
|
1998
2000
|
const le = E.current?.getContext("2d"), ne = b.current;
|
|
1999
2001
|
if (!(j && ne?.isGameActive && le && ne?.maze)) {
|
|
2000
|
-
|
|
2002
|
+
R = requestAnimationFrame(te);
|
|
2001
2003
|
return;
|
|
2002
2004
|
}
|
|
2003
|
-
$(), Ie(),
|
|
2005
|
+
$(), Ie(), R = requestAnimationFrame(te);
|
|
2004
2006
|
}, Ie = () => {
|
|
2005
2007
|
const le = E.current?.getContext("2d"), ne = b.current;
|
|
2006
|
-
le && ne?.maze && Tt(le, ne, P.current,
|
|
2008
|
+
le && ne?.maze && Tt(le, ne, P.current, I.current, r);
|
|
2007
2009
|
};
|
|
2008
|
-
return A.current = Ie,
|
|
2009
|
-
cancelAnimationFrame(
|
|
2010
|
+
return A.current = Ie, R = requestAnimationFrame(te), () => {
|
|
2011
|
+
cancelAnimationFrame(R);
|
|
2010
2012
|
};
|
|
2011
2013
|
}, []), F(() => {
|
|
2012
2014
|
U(), H();
|
|
2013
2015
|
}, [e, U, H]), F(() => {
|
|
2014
|
-
const
|
|
2016
|
+
const R = (j) => {
|
|
2015
2017
|
S.current = j.detail.timeUsed;
|
|
2016
2018
|
};
|
|
2017
|
-
return window.addEventListener("maze:timeUsed",
|
|
2018
|
-
window.removeEventListener("maze:timeUsed",
|
|
2019
|
+
return window.addEventListener("maze:timeUsed", R), window.addEventListener("maze:timeUp", B), () => {
|
|
2020
|
+
window.removeEventListener("maze:timeUsed", R), window.removeEventListener("maze:timeUp", B);
|
|
2019
2021
|
};
|
|
2020
2022
|
}, []), g ? /* @__PURE__ */ _("div", { className: "single-maze-loading", children: /* @__PURE__ */ _("div", { children: "Generating maze..." }) }) : f ? /* @__PURE__ */ _("div", { className: "maze-game-container", children: [
|
|
2021
|
-
/* @__PURE__ */ _("div", { className: "single-maze-toolbar", children: w && /* @__PURE__ */ _(
|
|
2023
|
+
/* @__PURE__ */ _("div", { className: "single-maze-toolbar", children: w && /* @__PURE__ */ _(Fn, { timer: d }) }),
|
|
2022
2024
|
/* @__PURE__ */ _("div", { className: "single-maze-canvas-container", ref: M, children: /* @__PURE__ */ _("canvas", { ref: E, className: "maze-game-canvas" }) }),
|
|
2023
2025
|
/* @__PURE__ */ _(oe, { isOpen: T, title: z, noConfirm: !0, cancelText: "OK", onCancel: X })
|
|
2024
2026
|
] }) : /* @__PURE__ */ _("div", { className: "single-maze-error", children: /* @__PURE__ */ _("div", { children: "Failed to generate maze" }) });
|
|
@@ -2046,6 +2048,7 @@ const Et = [
|
|
|
2046
2048
|
{
|
|
2047
2049
|
size: 8,
|
|
2048
2050
|
seed: 23456,
|
|
2051
|
+
fogEnabled: !0,
|
|
2049
2052
|
method: "backtracking",
|
|
2050
2053
|
exitColor: "#33f",
|
|
2051
2054
|
exitWallWidth: 4,
|
|
@@ -2191,7 +2194,7 @@ const Et = [
|
|
|
2191
2194
|
backgroundColor: "#ffffff",
|
|
2192
2195
|
playerColor: "#4CAF50",
|
|
2193
2196
|
playerRadius: 0.2,
|
|
2194
|
-
fogEnabled: !
|
|
2197
|
+
fogEnabled: !1,
|
|
2195
2198
|
fogRadius: 3.6,
|
|
2196
2199
|
fogColor: "rgba(8, 10, 18, 0.9)",
|
|
2197
2200
|
fogSoftness: 0.55,
|
|
@@ -2303,12 +2306,12 @@ function Un({ config: e = {} }) {
|
|
|
2303
2306
|
return /* @__PURE__ */ _(Dn, { config: o });
|
|
2304
2307
|
}
|
|
2305
2308
|
const Gn = {
|
|
2306
|
-
root: "https://unpkg.com/@roudanio/maze@0.3.
|
|
2309
|
+
root: "https://unpkg.com/@roudanio/maze@0.3.2/dist/",
|
|
2307
2310
|
...me
|
|
2308
2311
|
};
|
|
2309
2312
|
`${JSON.stringify(Gn, null, 2)}`;
|
|
2310
2313
|
const jn = {
|
|
2311
|
-
root: "https://unpkg.com/@roudanio/maze@0.3.
|
|
2314
|
+
root: "https://unpkg.com/@roudanio/maze@0.3.2/dist/",
|
|
2312
2315
|
..._e
|
|
2313
2316
|
};
|
|
2314
2317
|
`${JSON.stringify(
|
package/dist/maze.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(H,N){typeof exports=="object"&&typeof module<"u"?module.exports=N():typeof define=="function"&&define.amd?define(N):(H=typeof globalThis<"u"?globalThis:H||self,H.Maze=N())})(this,(function(){"use strict";var H,N,Ie,X,Fe,Re,De,Oe,ye,be,Te,$e,ne={},Ue=[],Mt=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,ce=Array.isArray;function B(e,t){for(var n in t)e[n]=t[n];return e}function Se(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function Lt(e,t,n){var o,i,s,a={};for(s in t)s=="key"?o=t[s]:s=="ref"?i=t[s]:a[s]=t[s];if(arguments.length>2&&(a.children=arguments.length>3?H.call(arguments,2):n),typeof e=="function"&&e.defaultProps!=null)for(s in e.defaultProps)a[s]===void 0&&(a[s]=e.defaultProps[s]);return ue(e,a,o,i,null)}function ue(e,t,n,o,i){var s={type:e,props:t,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++Ie,__i:-1,__u:0};return i==null&&N.vnode!=null&&N.vnode(s),s}function de(e){return e.children}function he(e,t){this.props=e,this.context=t}function J(e,t){if(t==null)return e.__?J(e.__,e.__i+1):null;for(var n;t<e.__k.length;t++)if((n=e.__k[t])!=null&&n.__e!=null)return n.__e;return typeof e.type=="function"?J(e):null}function Ge(e){var t,n;if((e=e.__)!=null&&e.__c!=null){for(e.__e=e.__c.base=null,t=0;t<e.__k.length;t++)if((n=e.__k[t])!=null&&n.__e!=null){e.__e=e.__c.base=n.__e;break}return Ge(e)}}function ke(e){(!e.__d&&(e.__d=!0)&&X.push(e)&&!fe.__r++||Fe!=N.debounceRendering)&&((Fe=N.debounceRendering)||Re)(fe)}function fe(){for(var e,t,n,o,i,s,a,r=1;X.length;)X.length>r&&X.sort(De),e=X.shift(),r=X.length,e.__d&&(n=void 0,o=void 0,i=(o=(t=e).__v).__e,s=[],a=[],t.__P&&((n=B({},o)).__v=o.__v+1,N.vnode&&N.vnode(n),Ee(t.__P,n,o,t.__n,t.__P.namespaceURI,32&o.__u?[i]:null,s,i??J(o),!!(32&o.__u),a),n.__v=o.__v,n.__.__k[n.__i]=n,Ve(s,n,a),o.__e=o.__=null,n.__e!=i&&Ge(n)));fe.__r=0}function je(e,t,n,o,i,s,a,r,c,l,d){var u,h,f,m,g,v,w,y=o&&o.__k||Ue,T=t.length;for(c=Nt(n,t,y,c,T),u=0;u<T;u++)(f=n.__k[u])!=null&&(h=f.__i==-1?ne:y[f.__i]||ne,f.__i=u,v=Ee(e,f,h,i,s,a,r,c,l,d),m=f.__e,f.ref&&h.ref!=f.ref&&(h.ref&&Me(h.ref,null,f),d.push(f.ref,f.__c||m,f)),g==null&&m!=null&&(g=m),(w=!!(4&f.__u))||h.__k===f.__k?c=We(f,c,e,w):typeof f.type=="function"&&v!==void 0?c=v:m&&(c=m.nextSibling),f.__u&=-7);return n.__e=g,c}function Nt(e,t,n,o,i){var s,a,r,c,l,d=n.length,u=d,h=0;for(e.__k=new Array(i),s=0;s<i;s++)(a=t[s])!=null&&typeof a!="boolean"&&typeof a!="function"?(c=s+h,(a=e.__k[s]=typeof a=="string"||typeof a=="number"||typeof a=="bigint"||a.constructor==String?ue(null,a,null,null,null):ce(a)?ue(de,{children:a},null,null,null):a.constructor==null&&a.__b>0?ue(a.type,a.props,a.key,a.ref?a.ref:null,a.__v):a).__=e,a.__b=e.__b+1,r=null,(l=a.__i=At(a,n,c,u))!=-1&&(u--,(r=n[l])&&(r.__u|=2)),r==null||r.__v==null?(l==-1&&(i>d?h--:i<d&&h++),typeof a.type!="function"&&(a.__u|=4)):l!=c&&(l==c-1?h--:l==c+1?h++:(l>c?h--:h++,a.__u|=4))):e.__k[s]=null;if(u)for(s=0;s<d;s++)(r=n[s])!=null&&(2&r.__u)==0&&(r.__e==o&&(o=J(r)),Xe(r,r));return o}function We(e,t,n,o){var i,s;if(typeof e.type=="function"){for(i=e.__k,s=0;i&&s<i.length;s++)i[s]&&(i[s].__=e,t=We(i[s],t,n,o));return t}e.__e!=t&&(o&&(t&&e.type&&!t.parentNode&&(t=J(e)),n.insertBefore(e.__e,t||null)),t=e.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function At(e,t,n,o){var i,s,a,r=e.key,c=e.type,l=t[n],d=l!=null&&(2&l.__u)==0;if(l===null&&e.key==null||d&&r==l.key&&c==l.type)return n;if(o>(d?1:0)){for(i=n-1,s=n+1;i>=0||s<t.length;)if((l=t[a=i>=0?i--:s++])!=null&&(2&l.__u)==0&&r==l.key&&c==l.type)return a}return-1}function qe(e,t,n){t[0]=="-"?e.setProperty(t,n??""):e[t]=n==null?"":typeof n!="number"||Mt.test(t)?n:n+"px"}function me(e,t,n,o,i){var s,a;e:if(t=="style")if(typeof n=="string")e.style.cssText=n;else{if(typeof o=="string"&&(e.style.cssText=o=""),o)for(t in o)n&&t in n||qe(e.style,t,"");if(n)for(t in n)o&&n[t]==o[t]||qe(e.style,t,n[t])}else if(t[0]=="o"&&t[1]=="n")s=t!=(t=t.replace(Oe,"$1")),a=t.toLowerCase(),t=a in e||t=="onFocusOut"||t=="onFocusIn"?a.slice(2):t.slice(2),e.l||(e.l={}),e.l[t+s]=n,n?o?n.u=o.u:(n.u=ye,e.addEventListener(t,s?Te:be,s)):e.removeEventListener(t,s?Te:be,s);else{if(i=="http://www.w3.org/2000/svg")t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(t!="width"&&t!="height"&&t!="href"&&t!="list"&&t!="form"&&t!="tabIndex"&&t!="download"&&t!="rowSpan"&&t!="colSpan"&&t!="role"&&t!="popover"&&t in e)try{e[t]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&t[4]!="-"?e.removeAttribute(t):e.setAttribute(t,t=="popover"&&n==1?"":n))}}function Be(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t.t==null)t.t=ye++;else if(t.t<n.u)return;return n(N.event?N.event(t):t)}}}function Ee(e,t,n,o,i,s,a,r,c,l){var d,u,h,f,m,g,v,w,y,T,p,z,C,S,k,L,E,M=t.type;if(t.constructor!=null)return null;128&n.__u&&(c=!!(32&n.__u),s=[r=t.__e=n.__e]),(d=N.__b)&&d(t);e:if(typeof M=="function")try{if(w=t.props,y="prototype"in M&&M.prototype.render,T=(d=M.contextType)&&o[d.__c],p=d?T?T.props.value:d.__:o,n.__c?v=(u=t.__c=n.__c).__=u.__E:(y?t.__c=u=new M(w,p):(t.__c=u=new he(w,p),u.constructor=M,u.render=xt),T&&T.sub(u),u.props=w,u.state||(u.state={}),u.context=p,u.__n=o,h=u.__d=!0,u.__h=[],u._sb=[]),y&&u.__s==null&&(u.__s=u.state),y&&M.getDerivedStateFromProps!=null&&(u.__s==u.state&&(u.__s=B({},u.__s)),B(u.__s,M.getDerivedStateFromProps(w,u.__s))),f=u.props,m=u.state,u.__v=t,h)y&&M.getDerivedStateFromProps==null&&u.componentWillMount!=null&&u.componentWillMount(),y&&u.componentDidMount!=null&&u.__h.push(u.componentDidMount);else{if(y&&M.getDerivedStateFromProps==null&&w!==f&&u.componentWillReceiveProps!=null&&u.componentWillReceiveProps(w,p),!u.__e&&u.shouldComponentUpdate!=null&&u.shouldComponentUpdate(w,u.__s,p)===!1||t.__v==n.__v){for(t.__v!=n.__v&&(u.props=w,u.state=u.__s,u.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(b){b&&(b.__=t)}),z=0;z<u._sb.length;z++)u.__h.push(u._sb[z]);u._sb=[],u.__h.length&&a.push(u);break e}u.componentWillUpdate!=null&&u.componentWillUpdate(w,u.__s,p),y&&u.componentDidUpdate!=null&&u.__h.push(function(){u.componentDidUpdate(f,m,g)})}if(u.context=p,u.props=w,u.__P=e,u.__e=!1,C=N.__r,S=0,y){for(u.state=u.__s,u.__d=!1,C&&C(t),d=u.render(u.props,u.state,u.context),k=0;k<u._sb.length;k++)u.__h.push(u._sb[k]);u._sb=[]}else do u.__d=!1,C&&C(t),d=u.render(u.props,u.state,u.context),u.state=u.__s;while(u.__d&&++S<25);u.state=u.__s,u.getChildContext!=null&&(o=B(B({},o),u.getChildContext())),y&&!h&&u.getSnapshotBeforeUpdate!=null&&(g=u.getSnapshotBeforeUpdate(f,m)),L=d,d!=null&&d.type===de&&d.key==null&&(L=He(d.props.children)),r=je(e,ce(L)?L:[L],t,n,o,i,s,a,r,c,l),u.base=t.__e,t.__u&=-161,u.__h.length&&a.push(u),v&&(u.__E=u.__=null)}catch(b){if(t.__v=null,c||s!=null)if(b.then){for(t.__u|=c?160:128;r&&r.nodeType==8&&r.nextSibling;)r=r.nextSibling;s[s.indexOf(r)]=null,t.__e=r}else{for(E=s.length;E--;)Se(s[E]);ze(t)}else t.__e=n.__e,t.__k=n.__k,b.then||ze(t);N.__e(b,t,n)}else s==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):r=t.__e=Pt(n.__e,t,n,o,i,s,a,c,l);return(d=N.diffed)&&d(t),128&t.__u?void 0:r}function ze(e){e&&e.__c&&(e.__c.__e=!0),e&&e.__k&&e.__k.forEach(ze)}function Ve(e,t,n){for(var o=0;o<n.length;o++)Me(n[o],n[++o],n[++o]);N.__c&&N.__c(t,e),e.some(function(i){try{e=i.__h,i.__h=[],e.some(function(s){s.call(i)})}catch(s){N.__e(s,i.__v)}})}function He(e){return typeof e!="object"||e==null||e.__b&&e.__b>0?e:ce(e)?e.map(He):B({},e)}function Pt(e,t,n,o,i,s,a,r,c){var l,d,u,h,f,m,g,v=n.props,w=t.props,y=t.type;if(y=="svg"?i="http://www.w3.org/2000/svg":y=="math"?i="http://www.w3.org/1998/Math/MathML":i||(i="http://www.w3.org/1999/xhtml"),s!=null){for(l=0;l<s.length;l++)if((f=s[l])&&"setAttribute"in f==!!y&&(y?f.localName==y:f.nodeType==3)){e=f,s[l]=null;break}}if(e==null){if(y==null)return document.createTextNode(w);e=document.createElementNS(i,y,w.is&&w),r&&(N.__m&&N.__m(t,s),r=!1),s=null}if(y==null)v===w||r&&e.data==w||(e.data=w);else{if(s=s&&H.call(e.childNodes),v=n.props||ne,!r&&s!=null)for(v={},l=0;l<e.attributes.length;l++)v[(f=e.attributes[l]).name]=f.value;for(l in v)if(f=v[l],l!="children"){if(l=="dangerouslySetInnerHTML")u=f;else if(!(l in w)){if(l=="value"&&"defaultValue"in w||l=="checked"&&"defaultChecked"in w)continue;me(e,l,null,f,i)}}for(l in w)f=w[l],l=="children"?h=f:l=="dangerouslySetInnerHTML"?d=f:l=="value"?m=f:l=="checked"?g=f:r&&typeof f!="function"||v[l]===f||me(e,l,f,v[l],i);if(d)r||u&&(d.__html==u.__html||d.__html==e.innerHTML)||(e.innerHTML=d.__html),t.__k=[];else if(u&&(e.innerHTML=""),je(t.type=="template"?e.content:e,ce(h)?h:[h],t,n,o,y=="foreignObject"?"http://www.w3.org/1999/xhtml":i,s,a,s?s[0]:n.__k&&J(n,0),r,c),s!=null)for(l=s.length;l--;)Se(s[l]);r||(l="value",y=="progress"&&m==null?e.removeAttribute("value"):m!=null&&(m!==e[l]||y=="progress"&&!m||y=="option"&&m!=v[l])&&me(e,l,m,v[l],i),l="checked",g!=null&&g!=e[l]&&me(e,l,g,v[l],i))}return e}function Me(e,t,n){try{if(typeof e=="function"){var o=typeof e.__u=="function";o&&e.__u(),o&&t==null||(e.__u=e(t))}else e.current=t}catch(i){N.__e(i,n)}}function Xe(e,t,n){var o,i;if(N.unmount&&N.unmount(e),(o=e.ref)&&(o.current&&o.current!=e.__e||Me(o,null,t)),(o=e.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(s){N.__e(s,t)}o.base=o.__P=null}if(o=e.__k)for(i=0;i<o.length;i++)o[i]&&Xe(o[i],t,n||typeof e.type!="function");n||Se(e.__e),e.__c=e.__=e.__e=void 0}function xt(e,t,n){return this.constructor(e,n)}function Ye(e,t,n){var o,i,s,a;t==document&&(t=document.documentElement),N.__&&N.__(e,t),i=(o=!1)?null:t.__k,s=[],a=[],Ee(t,e=t.__k=Lt(de,null,[e]),i||ne,ne,t.namespaceURI,i?null:t.firstChild?H.call(t.childNodes):null,s,i?i.__e:t.firstChild,o,a),Ve(s,e,a)}function It(e){function t(n){var o,i;return this.getChildContext||(o=new Set,(i={})[t.__c]=this,this.getChildContext=function(){return i},this.componentWillUnmount=function(){o=null},this.shouldComponentUpdate=function(s){this.props.value!=s.value&&o.forEach(function(a){a.__e=!0,ke(a)})},this.sub=function(s){o.add(s);var a=s.componentWillUnmount;s.componentWillUnmount=function(){o&&o.delete(s),a&&a.call(s)}}),n.children}return t.__c="__cC"+$e++,t.__=e,t.Provider=t.__l=(t.Consumer=function(n,o){return n.children(o)}).contextType=t,t}H=Ue.slice,N={__e:function(e,t,n,o){for(var i,s,a;t=t.__;)if((i=t.__c)&&!i.__)try{if((s=i.constructor)&&s.getDerivedStateFromError!=null&&(i.setState(s.getDerivedStateFromError(e)),a=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(e,o||{}),a=i.__d),a)return i.__E=i}catch(r){e=r}throw e}},Ie=0,he.prototype.setState=function(e,t){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=B({},this.state),typeof e=="function"&&(e=e(B({},n),this.props)),e&&B(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),ke(this))},he.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),ke(this))},he.prototype.render=de,X=[],Re=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,De=function(e,t){return e.__v.__b-t.__v.__b},fe.__r=0,Oe=/(PointerCapture)$|Capture$/i,ye=0,be=Be(!1),Te=Be(!0),$e=0;var Ft=0;function _(e,t,n,o,i,s){t||(t={});var a,r,c=t;if("ref"in c)for(r in c={},t)r=="ref"?a=t[r]:c[r]=t[r];var l={type:e,props:c,key:n,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Ft,__i:-1,__u:0,__source:i,__self:s};if(typeof e=="function"&&(a=e.defaultProps))for(r in a)c[r]===void 0&&(c[r]=a[r]);return N.vnode&&N.vnode(l),l}var Q,P,Le,Ke,oe=0,Je=[],D=N,Qe=D.__b,Ze=D.__r,et=D.diffed,tt=D.__c,nt=D.unmount,ot=D.__;function _e(e,t){D.__h&&D.__h(P,e,oe||t),oe=0;var n=P.__H||(P.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function U(e){return oe=1,Rt(at,e)}function Rt(e,t,n){var o=_e(Q++,2);if(o.t=e,!o.__c&&(o.__=[at(void 0,t),function(r){var c=o.__N?o.__N[0]:o.__[0],l=o.t(c,r);c!==l&&(o.__N=[l,o.__[1]],o.__c.setState({}))}],o.__c=P,!P.__f)){var i=function(r,c,l){if(!o.__c.__H)return!0;var d=o.__c.__H.__.filter(function(h){return!!h.__c});if(d.every(function(h){return!h.__N}))return!s||s.call(this,r,c,l);var u=o.__c.props!==r;return d.forEach(function(h){if(h.__N){var f=h.__[0];h.__=h.__N,h.__N=void 0,f!==h.__[0]&&(u=!0)}}),s&&s.call(this,r,c,l)||u};P.__f=!0;var s=P.shouldComponentUpdate,a=P.componentWillUpdate;P.componentWillUpdate=function(r,c,l){if(this.__e){var d=s;s=void 0,i(r,c,l),s=d}a&&a.call(this,r,c,l)},P.shouldComponentUpdate=i}return o.__N||o.__}function I(e,t){var n=_e(Q++,3);!D.__s&&st(n.__H,t)&&(n.__=e,n.u=t,P.__H.__h.push(n))}function R(e){return oe=5,Z(function(){return{current:e}},[])}function Z(e,t){var n=_e(Q++,7);return st(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function rt(e,t){return oe=8,Z(function(){return e},t)}function Dt(e){var t=P.context[e.__c],n=_e(Q++,9);return n.c=e,t?(n.__==null&&(n.__=!0,t.sub(P)),t.props.value):e.__}function Ot(){for(var e;e=Je.shift();)if(e.__P&&e.__H)try{e.__H.__h.forEach(ve),e.__H.__h.forEach(Ne),e.__H.__h=[]}catch(t){e.__H.__h=[],D.__e(t,e.__v)}}D.__b=function(e){P=null,Qe&&Qe(e)},D.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),ot&&ot(e,t)},D.__r=function(e){Ze&&Ze(e),Q=0;var t=(P=e.__c).__H;t&&(Le===P?(t.__h=[],P.__h=[],t.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.forEach(ve),t.__h.forEach(Ne),t.__h=[],Q=0)),Le=P},D.diffed=function(e){et&&et(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(Je.push(t)!==1&&Ke===D.requestAnimationFrame||((Ke=D.requestAnimationFrame)||$t)(Ot)),t.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),Le=P=null},D.__c=function(e,t){t.some(function(n){try{n.__h.forEach(ve),n.__h=n.__h.filter(function(o){return!o.__||Ne(o)})}catch(o){t.some(function(i){i.__h&&(i.__h=[])}),t=[],D.__e(o,n.__v)}}),tt&&tt(e,t)},D.unmount=function(e){nt&&nt(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.forEach(function(o){try{ve(o)}catch(i){t=i}}),n.__H=void 0,t&&D.__e(t,n.__v))};var it=typeof requestAnimationFrame=="function";function $t(e){var t,n=function(){clearTimeout(o),it&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(n,35);it&&(t=requestAnimationFrame(n))}function ve(e){var t=P,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),P=t}function Ne(e){var t=P;e.__c=e.__(),P=t}function st(e,t){return!e||e.length!==t.length||t.some(function(n,o){return n!==e[o]})}function at(e,t){return typeof t=="function"?t(e):t}const Ut=e=>({saveGameData(t){try{localStorage.setItem(e,JSON.stringify(t))}catch(n){console.error("Failed to save maze game data:",n)}},loadGameData(){try{const t=localStorage.getItem(e);return t?JSON.parse(t):null}catch(t){return console.error("Failed to load maze game data:",t),null}},resetGameData(){try{localStorage.removeItem(e)}catch(t){console.error("Failed to reset maze game data:",t)}}}),lt=It(void 0),ct={currentLevel:1,highestUnlockedLevel:1,currentTier:1,highestUnlockedTier:1,levelScores:{},totalScore:0},ut={isGameActive:!0,levelTransitioning:!1,maze:null,playerCell:{row:0,col:0},exitCell:{row:0,col:0},foodCells:[],fogEnabled:!0,playerAtExit:!1,foodCollected:0,totalFoodCount:0,showClue:!1,playerPath:[],visitCounts:{}},Gt=({children:e,config:t})=>{const n=Ut(t.lcPrefix+"progress"),o=n.loadGameData(),i=t.renderConfig?.fogEnabled??!0,s=()=>({...ut,fogEnabled:i}),[a,r]=U(()=>o||{...ct});I(()=>{const f=Object.values(a.levelScores).reduce((m,g)=>m+g,0);r(m=>({...m,totalScore:f}))},[a.levelScores]),I(()=>{n.saveGameData(a)},[a.currentLevel,a.highestUnlockedLevel,a.currentTier,a.highestUnlockedTier,a.levelScores,a.totalScore]);const[c,l]=U({...s()}),d=R(c);I(()=>{d.current=c},[c]);const u=Z(()=>[c.playerAtExit?1:0,c.foodCollected===c.totalFoodCount?1:0,c.showClue?0:1],[c.playerAtExit,c.foodCollected,c.totalFoodCount,c.showClue]),h=()=>{n.resetGameData(),r({...ct}),l({...s()})};return _(lt.Provider,{value:{gameProgress:a,setGameProgress:r,gamePlayState:c,setGamePlayState:l,gamePlayStateRef:d,currentScore:u,config:t,resetGame:h},children:e})},re=()=>{const e=Dt(lt);if(!e)throw new Error("useGameContext must be used within a GameProvider");return e},ie=e=>Z(()=>{const t=e.map(r=>r.length),n=t.reduce((r,c)=>r+c,0),o=e.length,i=r=>{if(r<1||r>n)return 0;let c=0;for(let l=0;l<t.length;l++)if(c+=t[l],r<=c)return l+1;return 0},s=r=>r<1||r>o?0:t.slice(0,r-1).reduce((c,l)=>c+l,0)+1,a={getTotalLevels:()=>n,getTotalTiers:()=>o,getTierLevelsRange:r=>{if(r<1||r>o)return[0,0];const c=s(r),l=c+t[r-1]-1;return[c,l]},getTierByLevel:i,getFirstLevelOfTier:s,getLevelConfig:r=>{if(r<1||r>n)return null;const c=i(r),l=s(c),d=r-l;return e[c-1][d]},getTierConfig:r=>r<1||r>o?null:e[r-1],isLevelUnlocked:(r,c)=>r<=c,isTierUnlocked:(r,c)=>r<=c,getNextLevelInfo:r=>{if(r>=n)return null;const c=r+1,l=i(r),d=i(c);return{nextLevel:c,nextTier:d,isTierChange:d>l}},getCurrentTierProgress:(r,c)=>{const[l,d]=a.getTierLevelsRange(c),u=r-l+1,h=d-l+1;return{current:u,total:h}},isLastLevelInTier:r=>{const c=i(r),[,l]=a.getTierLevelsRange(c);return r===l},getPreviousLevelInfo:r=>{if(r<=1)return null;const c=r-1,l=i(r),d=i(c);return{prevLevel:c,prevTier:d,isTierChange:d<l}}};return a},[e]),jt=({onTierChange:e,disabled:t})=>{const{gameProgress:n,config:o}=re(),{i18n:i,levelConfig:s}=o,{currentTier:a,highestUnlockedTier:r}=n,l=ie(s).getTotalTiers();return _("div",{className:"tier-selector",children:_("select",{value:a,onChange:d=>{d.target&&d.target.value&&e(Number(d.target.value))},disabled:t,className:"tier-dropdown",children:Array.from({length:l},(d,u)=>u+1).map(d=>_("option",{value:d,disabled:d>r,children:i.tier+" "+d},`tier-${d}`))})})},Wt=({onLevelChange:e,disabled:t})=>{const{gameProgress:n,config:o}=re(),{i18n:i,levelConfig:s}=o,{currentTier:a,levelScores:r,currentLevel:c,highestUnlockedLevel:l}=n,d=ie(s),u=Z(()=>{const[h,f]=d.getTierLevelsRange(a);return Array.from({length:f-h+1},(m,g)=>{const v=h+g,w=r[v]||0;return{level:v,score:w}})},[a,r]);return _("div",{className:"level-selector",children:_("select",{value:c,onChange:h=>{h.target&&h.target.value&&e(Number(h.target.value))},disabled:t,className:"level-dropdown",children:u.map(({level:h,score:f})=>_("option",{value:h,disabled:h>l,children:`${i.level} ${h} ${"★".repeat(f)}`},`level-${h}`))})})},se=({isOpen:e,title:t,className:n="",message:o,children:i,noConfirm:s=!1,noCancel:a=!1,confirmText:r="OK",cancelText:c="Cancel",confirmClass:l="",cancelClass:d="",onConfirm:u,onCancel:h})=>{const f=R(null);return I(()=>{const m=g=>{g.key==="Escape"&&h?.()};return e&&document.addEventListener("keydown",m),()=>{document.removeEventListener("keydown",m)}},[e,h]),_("div",{className:`maze-dialog-overlay ${e?"maze-dialog-visible":""}`,children:_("div",{className:"maze-dialog "+n,ref:f,children:[_("div",{className:"maze-dialog-title",children:t}),_("div",{className:"maze-dialog-content",children:i||_("div",{className:"maze-dialog-message",children:o})}),(!a||!s)&&_("div",{className:"maze-dialog-buttons",children:[!a&&_("button",{type:"button",className:"maze-dialog-cancel "+d,onClick:h,children:c}),!s&&_("button",{type:"button",className:"maze-dialog-confirm "+l,onClick:u,children:r})]})]})})},j={container:null,attachTo(e){return this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.container=document.createElement("div"),this.container.className="toast-container position-bottom",e.appendChild(this.container),this.container},currentToast:null,currentTimer:null,show(e,t=2e3){if(!this.container){console.warn("NativeToast: container not initialized, please call attachTo first");return}this.currentToast&&this.container.contains(this.currentToast)&&(this.container.removeChild(this.currentToast),this.currentToast=null),this.currentTimer&&(clearTimeout(this.currentTimer),this.currentTimer=null);const n=document.createElement("div");n.className="toast-message toast-visible",n.textContent=e,this.container.appendChild(n),this.currentToast=n,this.currentTimer=setTimeout(()=>{n.classList.remove("toast-visible"),setTimeout(()=>{this.container&&this.container.contains(n)&&(this.container.removeChild(n),this.currentToast===n&&(this.currentToast=null))},300),this.currentTimer=null},t)},clearAll(){if(this.container)for(;this.container.firstChild;)this.container.removeChild(this.container.firstChild)}},qt=()=>{const{gameProgress:e,setGameProgress:t,gamePlayState:n,setGamePlayState:o,gamePlayStateRef:i,resetGame:s,config:a}=re(),{i18n:r,levelConfig:c}=a,l=ie(c),{levelTransitioning:d,showClue:u}=n,{highestUnlockedLevel:h,totalScore:f}=e,m=l.getTotalLevels(),[g,v]=U(!1),[w,y]=U(!1),[T,p]=U(!1),z=O=>{const $=l.getFirstLevelOfTier(O);l.isLevelUnlocked($,h)&&(t(G=>({...G,currentTier:O})),C($))},C=O=>{l.isLevelUnlocked(O,h)&&(t($=>({...$,currentLevel:O})),j.show(r.levelGoToast.replace("%LEVEL%",O.toString())))},S=()=>{v(!0)},k=()=>{v(!1)},L=()=>{p(!0)},E=()=>{p(!1)},M=()=>{j.show(u?r.cluePathDisabled:r.cluePathEnabled),o(()=>({...i.current,showClue:!i.current.showClue})),p(!1)},b=()=>{y(!0)},A=()=>{s(),y(!1),j.show(r.resetDoneToast)},x=()=>{y(!1)};return _("div",{class:"game-panel-container",children:[_("div",{className:"game-controls",children:[_("div",{className:"selectors-container",children:[_(jt,{onTierChange:z,disabled:d}),_(Wt,{onLevelChange:C,disabled:d})]}),_("button",{className:`settings-clue-button ${u?"clue-on":"clue-off"}`,disabled:u,title:"Toggle Clue",onClick:L,children:u?r.clueOn:r.clueOff})]}),_("div",{className:"game-settings",children:_("span",{className:"game-settings-icon",onClick:S,children:"★ "+f})}),_(se,{isOpen:g,title:r.settings,noConfirm:!0,cancelText:r.close,onCancel:k,children:[_("div",{className:"settings-stats",children:[_("div",{children:r.levelComplete+`: ${h}/${m}`}),_("div",{children:r.starsCollected+": "+f}),_("div",{children:r.avgStarPerLevel+": "+(f/h).toFixed(2)})]}),_("div",{className:"settings-item-box",children:[_("button",{className:"settings-reset-button",title:"Reset Game",onClick:b,children:r.reset}),_("div",{className:"settings-item-tip",children:r.resetTip})]})]}),_(se,{isOpen:w,title:r.confirmReset,message:r.confirmResetMessage,confirmText:r.reset,cancelText:r.cancel,onConfirm:A,onCancel:x}),_(se,{isOpen:T,title:r.confirmClue,message:r.confirmClueMessage,confirmText:r.confirm,cancelText:r.cancel,onConfirm:M,onCancel:E})]})};function Ae(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Bt(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function Pe(e,t,n){return t&&Bt(e.prototype,t),e}function dt(e){return+e.replace(/px/,"")}function Vt(e){var t=window.devicePixelRatio,n=getComputedStyle(e),o=dt(n.getPropertyValue("width")),i=dt(n.getPropertyValue("height"));e.setAttribute("width",(o*t).toString()),e.setAttribute("height",(i*t).toString())}function W(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,o=Math.random()*(t-e)+e;return Math.floor(o*Math.pow(10,n))/Math.pow(10,n)}function ht(e){return e[W(0,e.length)]}var Ht=.00125,Xt=5e-4,Yt=9e-4,Kt=1e-5,Jt=6,Qt=80,Zt=.9,en=1.7,tn=.2,nn=.6,on=.03,rn=.07,ft=15,mt=82,sn=100,an=250,ln=40,cn=["#fcf403","#62fc03","#f4fc03","#03e7fc","#03fca5","#a503fc","#fc03ad","#fc03c2"];function _t(e){var t=1920;return Math.log(e)/Math.log(t)}var vt=(function(){function e(t){Ae(this,e);var n=t.initialPosition,o=t.direction,i=t.confettiRadius,s=t.confettiColors,a=t.emojis,r=t.emojiSize,c=t.canvasWidth,l=W(Zt,en,3),d=l*_t(c);this.confettiSpeed={x:d,y:d},this.finalConfettiSpeedX=W(tn,nn,3),this.rotationSpeed=a.length?.01:W(on,rn,3)*_t(c),this.dragForceCoefficient=W(Xt,Yt,6),this.radius={x:i,y:i},this.initialRadius=i,this.rotationAngle=o==="left"?W(0,.2,3):W(-.2,0,3),this.emojiSize=r,this.emojiRotationAngle=W(0,2*Math.PI),this.radiusYUpdateDirection="down";var u=o==="left"?W(mt,ft)*Math.PI/180:W(-ft,-mt)*Math.PI/180;this.absCos=Math.abs(Math.cos(u)),this.absSin=Math.abs(Math.sin(u));var h=W(-150,0),f={x:n.x+(o==="left"?-h:h)*this.absCos,y:n.y-h*this.absSin};this.currentPosition=Object.assign({},f),this.initialPosition=Object.assign({},f),this.color=a.length?null:ht(s),this.emoji=a.length?ht(a):null,this.createdAt=new Date().getTime(),this.direction=o}return Pe(e,[{key:"draw",value:function(n){var o=this.currentPosition,i=this.radius,s=this.color,a=this.emoji,r=this.rotationAngle,c=this.emojiRotationAngle,l=this.emojiSize,d=window.devicePixelRatio;s?(n.fillStyle=s,n.beginPath(),n.ellipse(o.x*d,o.y*d,i.x*d,i.y*d,r,0,2*Math.PI),n.fill()):a&&(n.font="".concat(l,"px serif"),n.save(),n.translate(d*o.x,d*o.y),n.rotate(c),n.textAlign="center",n.fillText(a,0,0),n.restore())}},{key:"updatePosition",value:function(n,o){var i=this.confettiSpeed,s=this.dragForceCoefficient,a=this.finalConfettiSpeedX,r=this.radiusYUpdateDirection,c=this.rotationSpeed,l=this.createdAt,d=this.direction,u=o-l;if(i.x>a&&(this.confettiSpeed.x-=s*n),this.currentPosition.x+=i.x*(d==="left"?-this.absCos:this.absCos)*n,this.currentPosition.y=this.initialPosition.y-i.y*this.absSin*u+Ht*Math.pow(u,2)/2,this.rotationSpeed-=this.emoji?1e-4:Kt*n,this.rotationSpeed<0&&(this.rotationSpeed=0),this.emoji){this.emojiRotationAngle+=this.rotationSpeed*n%(2*Math.PI);return}r==="down"?(this.radius.y-=n*c,this.radius.y<=0&&(this.radius.y=0,this.radiusYUpdateDirection="up")):(this.radius.y+=n*c,this.radius.y>=this.initialRadius&&(this.radius.y=this.initialRadius,this.radiusYUpdateDirection="down"))}},{key:"getIsVisibleOnCanvas",value:function(n){return this.currentPosition.y<n+sn}}]),e})();function un(){var e=document.createElement("canvas");return e.style.position="fixed",e.style.width="100%",e.style.height="100%",e.style.top="0",e.style.left="0",e.style.zIndex="1000",e.style.pointerEvents="none",document.body.appendChild(e),e}function dn(e){var t=e.confettiRadius,n=t===void 0?Jt:t,o=e.confettiNumber,i=o===void 0?e.confettiesNumber||(e.emojis?ln:an):o,s=e.confettiColors,a=s===void 0?cn:s,r=e.emojis,c=r===void 0?e.emojies||[]:r,l=e.emojiSize,d=l===void 0?Qt:l;return e.emojies&&console.error("emojies argument is deprecated, please use emojis instead"),e.confettiesNumber&&console.error("confettiesNumber argument is deprecated, please use confettiNumber instead"),{confettiRadius:n,confettiNumber:i,confettiColors:a,emojis:c,emojiSize:d}}var hn=(function(){function e(t){var n=this;Ae(this,e),this.canvasContext=t,this.shapes=[],this.promise=new Promise(function(o){return n.resolvePromise=o})}return Pe(e,[{key:"getBatchCompletePromise",value:function(){return this.promise}},{key:"addShapes",value:function(){var n;(n=this.shapes).push.apply(n,arguments)}},{key:"complete",value:function(){var n;return this.shapes.length?!1:((n=this.resolvePromise)===null||n===void 0||n.call(this),!0)}},{key:"processShapes",value:function(n,o,i){var s=this,a=n.timeDelta,r=n.currentTime;this.shapes=this.shapes.filter(function(c){return c.updatePosition(a,r),c.draw(s.canvasContext),i?c.getIsVisibleOnCanvas(o):!0})}}]),e})(),fn=(function(){function e(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Ae(this,e),this.activeConfettiBatches=[],this.canvas=t.canvas||un(),this.canvasContext=this.canvas.getContext("2d"),this.requestAnimationFrameRequested=!1,this.lastUpdated=new Date().getTime(),this.iterationIndex=0,this.loop=this.loop.bind(this),requestAnimationFrame(this.loop)}return Pe(e,[{key:"loop",value:function(){this.requestAnimationFrameRequested=!1,Vt(this.canvas);var n=new Date().getTime(),o=n-this.lastUpdated,i=this.canvas.offsetHeight,s=this.iterationIndex%10===0;this.activeConfettiBatches=this.activeConfettiBatches.filter(function(a){return a.processShapes({timeDelta:o,currentTime:n},i,s),s?!a.complete():!0}),this.iterationIndex++,this.queueAnimationFrameIfNeeded(n)}},{key:"queueAnimationFrameIfNeeded",value:function(n){this.requestAnimationFrameRequested||this.activeConfettiBatches.length<1||(this.requestAnimationFrameRequested=!0,this.lastUpdated=n||new Date().getTime(),requestAnimationFrame(this.loop))}},{key:"addConfetti",value:function(){for(var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},o=dn(n),i=o.confettiRadius,s=o.confettiNumber,a=o.confettiColors,r=o.emojis,c=o.emojiSize,l=this.canvas.getBoundingClientRect(),d=l.width,u=l.height,h=u*5/7,f={x:0,y:h},m={x:d,y:h},g=new hn(this.canvasContext),v=0;v<s/2;v++){var w=new vt({initialPosition:f,direction:"right",confettiRadius:i,confettiColors:a,confettiNumber:s,emojis:r,emojiSize:c,canvasWidth:d}),y=new vt({initialPosition:m,direction:"left",confettiRadius:i,confettiColors:a,confettiNumber:s,emojis:r,emojiSize:c,canvasWidth:d});g.addShapes(w,y)}return this.activeConfettiBatches.push(g),this.queueAnimationFrameIfNeeded(),g.getBatchCompletePromise()}},{key:"clearCanvas",value:function(){this.activeConfettiBatches=[]}},{key:"destroyCanvas",value:function(){this.canvas.remove()}}]),e})();const mn=new fn,xe=3,_n=({onRetry:e})=>{const{config:t,currentScore:n,gamePlayState:o,setGamePlayState:i,gameProgress:s,setGameProgress:a}=re(),{i18n:r,levelConfig:c}=t,[l,d,u]=n,{foodCollected:h,totalFoodCount:f,playerAtExit:m,levelTransitioning:g}=o,{currentLevel:v}=s,[w,y]=U(!1);I(()=>{m&&g&&(mn.addConfetti(),j.show(r.levelCompleteToast),y(!0))},[m,g]);const T=ie(c),p=T.getTotalLevels(),z=Z(()=>v>=p,[v,p]),C=()=>{y(!1),j.show(r.levelRestartToast),e?.()},S=()=>{y(!1),i(E=>({...E,isGameActive:!0,levelTransitioning:!1}))},k=()=>{y(!1);const E=T.getNextLevelInfo(v);if(!E)return;const{nextLevel:M,nextTier:b,isTierChange:A}=E;A&&j.show(r.tierUnlockedToast.replace("%TIER%",b.toString())),a(x=>({...x,currentLevel:M,currentTier:b,highestUnlockedLevel:Math.max(x.highestUnlockedLevel,M),highestUnlockedTier:Math.max(x.highestUnlockedTier,b),levelScores:{...x.levelScores,[x.currentLevel]:Math.max(Object.values(n).filter(Boolean).length,x.levelScores[x.currentLevel]||0)}}))},L=()=>{y(!1),a(E=>{const M=Math.max(Object.values(n).filter(Boolean).length,E.levelScores[E.currentLevel]||0),b={...E.levelScores,[E.currentLevel]:M};let A=0,x=0;const O=Object.entries(b).sort(($,G)=>Number($[0])-Number(G[0]));for(const[$,G]of O)if(G<xe){A=Number($),x=T.getTierByLevel(A);break}return(A>0&&A!==v||M<xe)&&j.show(r.notCompleteLevel),(A===0||M<xe)&&e?.(),{...E,currentLevel:A||E.currentLevel,currentTier:x||E.currentTier,levelScores:b}})};return I(()=>{const E=document.querySelector(".maze-game-container"),M=b=>{w&&((b.key===" "||b.code==="Space")&&E&&(E.contains(document.activeElement)||document.activeElement===document.body)&&(b.preventDefault(),z?L():k()),(b.key==="r"||b.code==="KeyR")&&C(),(b.key==="c"||b.code==="KeyC")&&S())};return window.addEventListener("keydown",M),()=>window.removeEventListener("keydown",M)},[w,z]),_(se,{className:"level-complete-dialog",isOpen:w,title:r.congratulations,cancelText:r.retry+" (R)",onCancel:C,noConfirm:!!d,confirmText:r.continue+" (C)",onConfirm:S,confirmClass:"maze-continue-btn",children:[_("div",{className:"maze-summary-message",children:[!!l&&_("div",{children:"★ - "+r.findYourExit}),_("div",{children:u?"★ - "+r.withoutClue:"☆ - "+r.withClue}),_("div",{children:(d?"★ - "+r.collectAllStars:"☆ - "+r.notCollectAllStars)+` (${h}/${f})`})]}),z&&_("div",{className:"all-levels-completed",children:r.allLevelsCompleted}),_("div",{className:"maze-go-next",children:z?_("button",{className:"maze-go-next-btn",type:"button",onClick:L,children:[_("span",{children:r.lastOK}),_("span",{className:"spacebar-tip",children:`(${r.spacebarTip})`})]}):_("button",{className:"maze-go-next-btn",type:"button",onClick:k,children:[_("span",{children:r.nextLevel}),_("span",{className:"spacebar-tip",children:`(${r.spacebarTip})`})]})}),!d&&_("div",{className:"not-all-stars-collected",children:r.continueMessage})]})},gt=(e,t)=>{const n=R({canvasWidth:0,canvasHeight:0});return I(()=>{const o=()=>{const s=e.current;if(!s)return;const a=s.parentElement;if(!a)return;const r=a.clientWidth;if(r===0)return;const c=window.devicePixelRatio||1;s.style.width=`${r}px`,s.style.height=`${r}px`;const l=r*c,d=r*c;s.width=l,s.height=d,n.current={canvasWidth:l,canvasHeight:d},t?.()};o();let i=null;return window.ResizeObserver&&e.current&&(i=new ResizeObserver(o),i.observe(e.current.parentElement)),window.addEventListener("resize",o),()=>{window.removeEventListener("resize",o),i?.disconnect()}},[e,t]),n},pt=(e,t,n)=>{const o=R({cellWidth:0,cellHeight:0});return I(()=>{const i=()=>{const a=e.current,r=t.maze;if(!a||!r)return;const{rows:c,cols:l}=r;if(c<=0||l<=0)return;const d=(a.width-n*2)/l,u=(a.height-n*2)/c;o.current={cellWidth:d,cellHeight:u}};i();let s=null;return e.current&&window.ResizeObserver&&(s=new ResizeObserver(i),s.observe(e.current)),()=>{e.current&&s?.disconnect()}},[e,t.maze,n]),o},ge={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]},wt=({gamePlayStateRef:e,setGamePlayState:t,moveSpeed:n,moveSpeedRef:o,playerRadius:i,onFoodCollected:s,onExitReached:a,onFirstMove:r})=>{const c=()=>o?.current??n??.03,l=R(!1),d=R(new Set),u=R(!1),h=rt((T,p)=>{const z=e.current;if(!z.maze)return{canMove:!1,newCell:null};const C=c(),[S,k]=ge[T];if(Ct(p,S,k,i,C,z.maze))return{canMove:!1,newCell:null};const{row:E,col:M}=p,b=E+S*C,A=M+k*C,x=-.5,O=z.maze.rows,$=z.maze.cols;if(b<x||b>=O||A<x||A>=$)return{canMove:!1,newCell:null};const G=E<0?0:Math.floor(E),Y=M<0?0:Math.floor(M),V=b<0?0:Math.floor(b),te=A<0?0:Math.floor(A);return V!==G||te!==Y?z.maze.isValid(V,te)?{canMove:!0,newCell:{row:V,col:te}}:{canMove:!1,newCell:null}:{canMove:!0,newCell:null}},[i,c]),f=()=>{const T=e.current,{row:p,col:z}=T.playerCell,C=i*2,S=T.foodCells.findIndex(E=>Math.sqrt(Math.pow(p-E.row,2)+Math.pow(z-E.col,2))<C);S!==-1&&s&&(s(),e.current={...e.current,foodCollected:e.current.foodCollected+1,foodCells:e.current.foodCells.filter((E,M)=>M!==S)});const L=pn(T.playerCell,T.exitCell,T.maze);L&&!e.current.playerAtExit?(e.current={...e.current,playerAtExit:!0,isGameActive:!1,levelTransitioning:!0},a&&a(),requestIdleCallback(()=>{t(()=>({...e.current}))},{timeout:10})):!L&&e.current.playerAtExit&&(e.current={...e.current,playerAtExit:!1,isGameActive:!0,levelTransitioning:!1})},m=T=>{const p=e.current,z=Math.round(T.row),C=Math.round(T.col),S=p.playerPath[p.playerPath.length-1],k=S.row===z&&S.col===C,L=Math.abs(S.row-z),E=Math.abs(S.col-C);if((L===1&&E===0||L===0&&E===1)&&!k){const b=`${S.row},${S.col}-${z},${C}`;e.current={...e.current,playerPath:[...e.current.playerPath,{row:z,col:C}],visitCounts:{...e.current.visitCounts,[b]:(e.current.visitCounts[b]||0)+1}}}},g=()=>{if(l.current||d.current.size===0)return;const T=e.current;!T.playerCell||!Array.from(d.current).some(z=>{const{canMove:C}=h(z,T.playerCell);return C})||(!u.current&&r&&(u.current=!0,r()),l.current=!0)};I(()=>{const T=C=>{if(C.key==="ArrowUp"||C.key==="ArrowDown"||C.key==="ArrowLeft"||C.key==="ArrowRight"||C.key===" "){const S=document.activeElement;if(S&&(S.tagName==="INPUT"||S.tagName==="TEXTAREA"||S.getAttribute("contenteditable")==="true"))return;C.preventDefault()}},p=C=>{const S=C.key;if(!(S in ge))return;const k=document.activeElement;k&&(k.tagName==="INPUT"||k.tagName==="TEXTAREA"||k.getAttribute("contenteditable")==="true")||(C.preventDefault(),e.current.isGameActive&&(d.current.has(S)||(d.current.add(S),l.current||g())))},z=C=>{const S=C.key;if(!(S in ge))return;const k=document.activeElement;k&&(k.tagName==="INPUT"||k.tagName==="TEXTAREA"||k.getAttribute("contenteditable")==="true")||(C.preventDefault(),d.current.delete(S),d.current.size===0&&w())};return window.addEventListener("keydown",T,{capture:!0}),window.addEventListener("keydown",p),window.addEventListener("keyup",z),()=>{window.removeEventListener("keydown",T,{capture:!0}),window.removeEventListener("keydown",p),window.removeEventListener("keyup",z)}},[]);const v=rt(()=>{if(!l.current||d.current.size===0)return e.current.playerCell;const T=c(),p=e.current.playerCell;let z=0,C=0,S=0;for(const K of d.current){const{canMove:F}=h(K,p);if(F){const[q,ae]=ge[K];z+=q,C+=ae,S++}}if(S===0)return e.current.playerCell;const k=Math.sqrt(z*z+C*C),L=k>0?z/k:0,E=k>0?C/k:0,M=Number((p.row+L*T).toFixed(2)),b=Number((p.col+E*T).toFixed(2)),A=M-p.row,x=b-p.col,O=Math.sqrt(A*A+x*x);if(O>0){const K=A/O,F=x/O;if(Ct(p,K,F,i,O,e.current.maze))return e.current.playerCell}e.current.playerCell={row:M,col:b},f();const $=p.row<0?0:Math.round(p.row),G=p.col<0?0:Math.round(p.col),Y=M<0?0:Math.round(M),V=b<0?0:Math.round(b);return(Y!==$||V!==G)&&m({row:Y,col:V}),e.current.playerCell},[c,h]),w=()=>{l.current=!1,d.current.clear()};return{updatePlayerPos:v,resetMovingState:w,resetFirstMoveState:()=>{u.current=!1}}};function Ct(e,t,n,o,i,s){const a=e.row+t*i,r=e.col+n*i,c={row:a,col:r},l=[],d=e.row<0?0:Math.floor(e.row),u=e.col<0?0:Math.floor(e.col);l.push({row:d,col:u});const h=[[-1,0],[1,0],[0,-1],[0,1],[-1,-1],[-1,1],[1,-1],[1,1]];for(const[f,m]of h){const g=d+f,v=u+m;s.isValid(g,v)&&l.push({row:g,col:v})}for(const f of l){const m=vn(f.row,f.col,s);for(const g of m)if(gn(c,g)<o)return!0}return!1}function vn(e,t,n){const o=[],i=n.grid[e][t];return i.walls.top&&o.push({start:{row:e-.5,col:t-.5},end:{row:e-.5,col:t+.5}}),i.walls.right&&o.push({start:{row:e-.5,col:t+.5},end:{row:e+.5,col:t+.5}}),i.walls.bottom&&o.push({start:{row:e+.5,col:t-.5},end:{row:e+.5,col:t+.5}}),i.walls.left&&o.push({start:{row:e-.5,col:t-.5},end:{row:e+.5,col:t-.5}}),o}function gn(e,t){const{start:n,end:o}=t,i=o.col-n.col,s=o.row-n.row,a=e.col-n.col,r=e.row-n.row,c=i*i+s*s;if(c===0)return Math.sqrt(a*a+r*r);const l=Math.max(0,Math.min(1,(a*i+r*s)/c)),d=n.col+l*i,u=n.row+l*s,h=e.col-d,f=e.row-u;return Math.sqrt(h*h+f*f)}function pn(e,t,n){if(!n.isValid(t.row,t.col))return!1;const o=e.col>=t.col-.5&&e.col<=t.col+.5,i=e.row>=t.row+.5,s=e.row>=t.row-.5;return o&&i&&s}function ee(e,t,n,o,i){return{x:i+t*n+n/2,y:i+e*o+o/2}}function wn(e,t,n,o,i,s){e.save(),e.beginPath();for(let a=0;a<i*2;a++){const r=a%2===0?o:s,c=Math.PI*a/i;e.lineTo(t+r*Math.sin(c),n+r*Math.cos(c))}e.closePath(),e.fill(),e.restore()}function Cn({ctx:e,canvasWidth:t,canvasHeight:n,cellWidth:o,cellHeight:i,padding:s,playerCell:a,walls:r,fogRadius:c,fogColor:l,fogSoftness:d}){const u=Math.max(c,0)*Math.max(o,i)||0;if(u<=0)return;const h=ee(a.row,a.col,o,i,s),f=yn(h,r,u);e.save(),e.fillStyle=l,e.fillRect(0,0,t,n),e.globalCompositeOperation="destination-out";const m=Math.max(Math.min(o,i)*.25,2);e.filter=`blur(${m}px)`;const g=Math.max(Math.min(d,1),0),v=e.createRadialGradient(h.x,h.y,Math.max(u*.2,6),h.x,h.y,u);v.addColorStop(0,"rgba(0, 0, 0, 1)"),v.addColorStop(Math.max(.25,g-.1),"rgba(0, 0, 0, 1)"),v.addColorStop(1,"rgba(0, 0, 0, 0)"),e.fillStyle=v,f.length>=3?(e.beginPath(),f.forEach((w,y)=>{y===0?e.moveTo(w.x,w.y):e.lineTo(w.x,w.y)}),e.closePath(),e.fill()):(e.beginPath(),e.arc(h.x,h.y,u,0,Math.PI*2),e.fill()),e.restore()}function yn(e,t,n){const i=[];if(t.forEach(a=>{i.push(Math.atan2(a.y1-e.y,a.x1-e.x)-1e-4,Math.atan2(a.y1-e.y,a.x1-e.x),Math.atan2(a.y1-e.y,a.x1-e.x)+1e-4,Math.atan2(a.y2-e.y,a.x2-e.x)-1e-4,Math.atan2(a.y2-e.y,a.x2-e.x),Math.atan2(a.y2-e.y,a.x2-e.x)+1e-4)}),i.length===0)for(let a=0;a<24;a++)i.push(a/24*Math.PI*2);return Array.from(new Set(i)).sort((a,r)=>a-r).map(a=>bn(e,a,t,n))}function bn(e,t,n,o){const i={x:Math.cos(t),y:Math.sin(t)};let s={x:e.x+i.x*o,y:e.y+i.y*o,distance:o};for(const a of n){const r=Tn(e,i,{x:a.x1,y:a.y1},{x:a.x2,y:a.y2},o);r&&r.distance<s.distance&&(s=r)}return{x:s.x,y:s.y}}function Tn(e,t,n,o,i){const s={x:o.x-n.x,y:o.y-n.y},a=t.x*s.y-t.y*s.x;if(Math.abs(a)<1e-6)return null;const r={x:n.x-e.x,y:n.y-e.y},c=(r.x*s.y-r.y*s.x)/a,l=(r.x*t.y-r.y*t.x)/a;return c<0||l<0||l>1||c>i?null:{x:e.x+t.x*c,y:e.y+t.y*c,distance:c}}function yt(e,t,n,o){const i=[];for(let s=0;s<e.rows;s++)for(let a=0;a<e.cols;a++){const r=e.grid[s][a],c=o+a*t,l=o+s*n;r.walls.top&&i.push({x1:c,y1:l,x2:c+t,y2:l}),r.walls.right&&i.push({x1:c+t,y1:l,x2:c+t,y2:l+n}),r.walls.bottom&&i.push({x1:c,y1:l+n,x2:c+t,y2:l+n}),r.walls.left&&i.push({x1:c,y1:l,x2:c,y2:l+n})}return i}function Sn({ctx:e,maze:t,cellWidth:n,cellHeight:o,padding:i,wallColor:s,wallWidth:a,walls:r}){e.save(),e.strokeStyle=s,e.lineWidth=a,e.lineCap="round",e.beginPath(),(r??yt(t,n,o,i)).forEach(l=>{e.moveTo(l.x1,l.y1),e.lineTo(l.x2,l.y2)}),e.stroke(),e.restore()}function kn({ctx:e,playerCell:t,playerRadius:n,cellWidth:o,cellHeight:i,padding:s,playerColor:a}){const{x:r,y:c}=ee(t.row,t.col,o,i,s),l=Math.min(o,i)*Math.min(n,.5);e.save(),e.fillStyle=a,e.beginPath(),e.arc(r,c,l,0,Math.PI*2),e.fill(),e.restore()}function En({ctx:e,maze:t,exitCell:n,cellWidth:o,cellHeight:i,padding:s,exitColor:a,exitWallWidth:r,exitDashArray:c=[8,12]}){const{row:l,col:d}=n;if(!t.isValid(l,d))return;const u=s+d*o,h=s+l*i;e.save(),e.globalCompositeOperation="destination-out",e.lineWidth=r,e.lineCap="round",e.beginPath(),e.moveTo(u,h+i),e.lineTo(u+o,h+i),e.stroke(),e.globalCompositeOperation="source-over",e.strokeStyle=a,e.lineWidth=r,e.setLineDash(c),e.beginPath(),e.moveTo(u,h+i),e.lineTo(u+o,h+i),e.stroke(),e.restore()}function zn({ctx:e,foodCells:t,cellWidth:n,cellHeight:o,padding:i,foodColor:s}){e.fillStyle=s,e.shadowColor="rgba(255, 215, 64, 0.9)",e.shadowBlur=Math.max(Math.min(n,o)*.28,3);const a=Math.min(n,o)*.25;t.forEach(r=>{const{x:c,y:l}=ee(r.row,r.col,n,o,i);wn(e,c,l,a*1.25,5,a*.62)}),e.shadowBlur=0,e.strokeStyle="rgba(255,255,255,0.5)",e.lineWidth=Math.max(a*.3,1),t.forEach(r=>{const{x:c,y:l}=ee(r.row,r.col,n,o,i);e.beginPath(),e.arc(c,l,a*1.05,0,Math.PI*2),e.stroke()})}function Mn({ctx:e,playerPath:t,visitCounts:n,cellWidth:o,cellHeight:i,padding:s,clueColor:a}){if(!(!t||t.length<2||!n)){e.save();for(let r=1;r<t.length;r++){const c=t[r-1],l=t[r],d=`${c.row},${c.col}-${l.row},${l.col}`,u=`${l.row},${l.col}-${c.row},${c.col}`,h=(n[d]||0)+(n[u]||0),f=Math.min(.2+h*.1,.9),m=Math.max(3,o*.1)+h*.5;try{e.strokeStyle=a.replace(")",`, ${f})`).replace("rgb(","rgba(")}catch{e.strokeStyle=`rgba(255, 0, 0, ${f})`}e.lineWidth=m,e.lineCap="round",e.lineJoin="round";const{x:g,y:v}=ee(c.row,c.col,o,i,s),{x:w,y}=ee(l.row,l.col,o,i,s);e.beginPath(),e.moveTo(g,v),e.lineTo(w,y),e.stroke()}e.restore()}}function bt(e,t,n,o,i){if(!e||!t.maze)return;const{canvasWidth:s,canvasHeight:a}=n,{cellWidth:r,cellHeight:c}=o,{maze:l,playerCell:d,exitCell:u,foodCells:h,showClue:f,playerPath:m,visitCounts:g}=t,{padding:v,wallWidth:w,wallColor:y,playerColor:T,playerRadius:p,foodColor:z,backgroundColor:C,clueColor:S,fogEnabled:k,fogRadius:L,fogColor:E,fogSoftness:M,exitColor:b,exitWallWidth:A,exitDashArray:x}=i;e.clearRect(0,0,s,a),e.save(),e.fillStyle=C,e.fillRect(0,0,s,a),e.restore(),f&&Mn({ctx:e,playerPath:m,visitCounts:g,cellWidth:r,cellHeight:c,padding:v,clueColor:S});const O=yt(l,r,c,v);(t.fogEnabled??!0)&&k&&Cn({ctx:e,canvasWidth:s,canvasHeight:a,cellWidth:r,cellHeight:c,padding:v,playerCell:d,walls:O,fogRadius:L,fogColor:E,fogSoftness:M}),Sn({ctx:e,maze:l,cellWidth:r,cellHeight:c,padding:v,wallColor:y,wallWidth:w,walls:O}),En({ctx:e,maze:l,exitCell:u,cellWidth:r,cellHeight:c,padding:v,exitColor:b,exitWallWidth:A,exitDashArray:x}),kn({ctx:e,playerCell:d,playerRadius:p,cellWidth:r,cellHeight:c,padding:v,playerColor:T}),zn({ctx:e,foodCells:h,cellWidth:r,cellHeight:c,padding:v,foodColor:z})}function Ln(e){return function(){let t=e+=1831565813;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}}class Nn{constructor(t,n){this.row=t,this.col=n}visited=!1;walls={top:!0,right:!0,bottom:!0,left:!0}}class Tt{rows;cols;grid;seed;random;constructor(t,n,o,i,s={row:0,col:0},a={row:t-1,col:n-1}){this.rows=t,this.cols=n,this.seed=i??Math.floor(Math.random()*1e6),this.random=Ln(this.seed),this.grid=this.initializeGrid(),this.generate(o,s,a)}initializeGrid(){const t=[];for(let n=0;n<this.rows;n++){t[n]=[];for(let o=0;o<this.cols;o++)t[n][o]=new Nn(n,o)}return t}isValid(t,n){return t>=0&&t<this.rows&&n>=0&&n<this.cols}getNeighbors(t,n){const o=[],i=[{r:-1,c:0},{r:0,c:1},{r:1,c:0},{r:0,c:-1}];for(const s of i){const a=t+s.r,r=n+s.c;this.isValid(a,r)&&o.push({row:a,col:r})}return o}getUnvisitedNeighbors(t,n){return this.getNeighbors(t,n).filter(o=>!this.grid[o.row][o.col].visited)}getVisitedNeighbors(t,n){return this.getNeighbors(t,n).filter(o=>this.grid[o.row][o.col].visited)}removeWall(t,n,o,i){const s=this.grid[t][n],a=this.grid[o][i];t===o+1?(s.walls.top=!1,a.walls.bottom=!1):t===o-1?(s.walls.bottom=!1,a.walls.top=!1):n===i+1?(s.walls.left=!1,a.walls.right=!1):n===i-1&&(s.walls.right=!1,a.walls.left=!1)}generate(t,n={row:0,col:0},o={row:this.rows-1,col:this.cols-1}){switch(t){case"backtracking":this.generateWithBacktracking();break;case"prims":this.generateWithPrims();break;default:throw new Error(`Unknown maze generation method: ${t}`)}this.addOpenings(n,o)}generateWithBacktracking(){const t=[],n=this.randomNumber(this.rows),o=this.randomNumber(this.cols);let i={row:n,col:o};for(this.grid[n][o].visited=!0,t.push(i);t.length>0;){i=t[t.length-1];const{row:s,col:a}=i,r=this.getUnvisitedNeighbors(s,a);if(r.length>0){const c=this.randomPick(r),{row:l,col:d}=c;this.removeWall(s,a,l,d),this.grid[l][d].visited=!0,t.push(c)}else t.pop()}}generateWithPrims(){const t=[],n=(s,a)=>{const r=this.getNeighbors(s,a);for(const c of r)!this.grid[c.row][c.col].visited&&!t.some(l=>l.row===c.row&&l.col===c.col)&&t.push(c)},o=this.randomNumber(this.rows),i=this.randomNumber(this.cols);for(this.grid[o][i].visited=!0,n(o,i);t.length>0;){const s=this.randomNumber(t.length),a=t[s],{row:r,col:c}=a,l=this.getVisitedNeighbors(r,c);if(l.length>0){const d=this.randomPick(l);this.removeWall(r,c,d.row,d.col),this.grid[r][c].visited=!0,n(r,c)}t.splice(s,1)}}addOpenings(t,n){this.grid[t.row][t.col].walls.top=!1,this.isValid(n.row,n.col)&&(this.grid[n.row][n.col].walls.bottom=!1)}randomNumber(t){return Math.floor(this.random()*t)}randomPick(t){return t[Math.floor(this.random()*t.length)]}}const St=(e,t,n)=>{if(!e.isValid(t,n))return!1;const o=e.grid[t][n];return!o.walls.top||!o.walls.right||!o.walls.bottom||!o.walls.left},An=e=>e===1?2:e>=2&&e<=5?3:e>=6&&e<=11?4:e>=12&&e<=15?5:6,Pn=(e,t)=>{if(!t)return console.error(`Cannot find Level ${e}'s config.`),null;const{size:n,seed:o,method:i,entry:s,exit:a}=t,r=n,c=n,l=s||{row:0,col:0},d=a||{row:r-1,col:c-1},u=new Tt(r,c,i,o,l,d),h=An(e),f=[];for(let m=0;m<h;m++){let g;do g={row:Math.floor(u.random()*r),col:Math.floor(u.random()*c)};while(g.row===l.row&&g.col===l.col||g.row===d.row&&g.col===d.col||!St(u,g.row,g.col)||f.some(v=>v.row===g.row&&v.col===g.col));f.push(g)}return{isGameActive:!0,levelTransitioning:!1,maze:u,playerCell:l,exitCell:d,foodCells:f,playerAtExit:!1,foodCollected:0,totalFoodCount:h,showClue:!1,playerPath:[l],visitCounts:{[`${l.row},${l.col}`]:1}}},xn=({size:e,seed:t,method:n,foodCount:o,foodRace:i,clue:s,fogEnabled:a=!0})=>{const r=e,c=e,l={row:0,col:0},d={row:r-1,col:c-1},u=new Tt(r,c,n,t,l,d),h=[];if(i)for(let f=0;f<o;f++){let m,g=0;do m={row:Math.floor(u.random()*r),col:Math.floor(u.random()*c)},g++;while(g<50&&(m.row===l.row&&m.col===l.col||m.row===d.row&&m.col===d.col||!St(u,m.row,m.col)||h.some(v=>v.row===m.row&&v.col===m.col)));g<50&&h.push(m)}return{isGameActive:!0,levelTransitioning:!1,maze:u,playerCell:l,exitCell:d,foodCells:h,playerAtExit:!1,foodCollected:0,totalFoodCount:i?o:0,fogEnabled:a,showClue:s,playerPath:[l],visitCounts:{[`${l.row},${l.col}`]:1}}};function In(){const{setGamePlayState:e,gamePlayState:t,gamePlayStateRef:n,gameProgress:o,config:i}=re(),s=R(null),a=R(null),{i18n:r,levelConfig:c,renderConfig:l}=i,d=ie(c),u=R(d.getLevelConfig(o.currentLevel));I(()=>{s.current&&j.attachTo(s.current)},[]);const h=R(),f=gt(a,()=>{h.current?.()}),m=pt(a,t,l.padding);I(()=>{u.current=d.getLevelConfig(o.currentLevel)},[o.currentLevel]);const g=()=>{const T=Pn(o.currentLevel,u.current);T&&e(p=>({...p,...T}))};I(()=>{g()},[o.currentLevel]);const v=()=>{g()},{updatePlayerPos:w,resetMovingState:y}=wt({gamePlayStateRef:n,setGamePlayState:e,playerRadius:l.playerRadius,moveSpeed:l.gridMoveSpeed,onFoodCollected:()=>{const T=n.current.totalFoodCount-n.current.foodCollected-1;T>0?j.show(r.foodCollectedToast.replace("%NUM%",T.toString()),3e3):j.show(r.allFoodCollectedToast)}});return I(()=>{y()},[o.currentLevel,y]),I(()=>{let T,p=!document.hidden;const z=()=>{const k=a.current?.getContext("2d"),L=n.current;if(!(p&&L?.isGameActive&&k&&L?.maze)){T=requestAnimationFrame(z);return}w(),C(),T=requestAnimationFrame(z)},C=()=>{const k=a.current?.getContext("2d"),L=n.current;if(k&&L?.maze){const E=u.current?.wallWidth||l?.wallWidth,M=u.current?.exitColor||l?.exitColor,b=u.current?.exitWallWidth||l?.exitWallWidth,A=u.current?.exitDashArray||l?.exitDashArray;bt(k,L,f.current,m.current,{...l,wallWidth:E,exitColor:M,exitWallWidth:b,exitDashArray:A})}};h.current=C;const S=k=>{const L=p;p=!document.hidden&&document.visibilityState==="visible"&&(!k||k.type!=="blur"),!L&&p?n.current?.levelTransitioning===!1&&e({...n.current,isGameActive:!0}):L&&!p&&e({...n.current,isGameActive:!1})};return document.addEventListener("visibilitychange",S),window.addEventListener("blur",S),window.addEventListener("focus",S),T=requestAnimationFrame(z),()=>{cancelAnimationFrame(T),document.removeEventListener("visibilitychange",S),window.removeEventListener("blur",S),window.removeEventListener("focus",S)}},[]),I(()=>{j.show(r.useArrowKeyTips,3e3)},[]),_("div",{className:"maze-game-container",children:[_(qt,{}),_(_n,{onRetry:v}),_("div",{className:"maze-canvas-container",ref:s,children:_("canvas",{ref:a,className:"maze-game-canvas"})})]})}const Fn=e=>{const t=Math.floor(e/60),n=e%60;return`${t.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`},Rn=({timer:e})=>{const[t,n]=U(e),o=R(),i=R(!1),s=R(0);return I(()=>{const a=()=>{!i.current&&!o.current&&(i.current=!0,o.current=setInterval(()=>{n(c=>(s.current=e-c+1,c<=1?(clearInterval(o.current),window.dispatchEvent(new CustomEvent("maze:timeUp")),0):c-1))},1e3))},r=()=>{clearInterval(o.current),o.current=void 0,window.dispatchEvent(new CustomEvent("maze:timeUsed",{detail:{timeUsed:s.current}}))};return window.addEventListener("maze:firstMove",a),window.addEventListener("maze:gameSuccess",r),()=>{window.removeEventListener("maze:firstMove",a),window.removeEventListener("maze:gameSuccess",r),clearInterval(o.current)}},[e]),I(()=>{o.current&&(clearInterval(o.current),o.current=void 0),n(e),i.current=!1,s.current=0},[e]),_("div",{className:"single-maze-timer",children:_("span",{className:`maze-timer-text ${t<=10&&i.current?"maze-timer-warning":""}`,children:["⏱️ ",Fn(t)]})})};function Dn({config:e}){const{size:t,seed:n,method:o,foodCount:i,foodRace:s,clue:a,renderConfig:r,successCallback:c,failCallback:l,timer:d,i18n:u}=e,h=r.fogEnabled??!0,[f,m]=U({...ut,fogEnabled:h}),[g,v]=U(!1),[w,y]=U(!0),[T,p]=U(!1),[z,C]=U(""),S=R(0),k=R(!1),L=R(!1),E=R(null),M=R(null),b=R(f),A=R(),x=gt(E,()=>{A.current?.()}),O=pt(E,f,r.padding);I(()=>{b.current=f},[f]);const{updatePlayerPos:$,resetMovingState:G,resetFirstMoveState:Y}=wt({gamePlayStateRef:b,setGamePlayState:m,playerRadius:r.playerRadius,moveSpeed:r.gridMoveSpeed,onFoodCollected:()=>{console.log("Food collected in single maze")},onExitReached:()=>{if(!k.current){if(s&&b.current.foodCollected<b.current.totalFoodCount){C(`⭐️ ${u.foodMsg}`),p(!0),m(F=>({...F,isGameActive:!1}));return}m(F=>({...F,isGameActive:!1})),te()}},onFirstMove:()=>{window.dispatchEvent(new CustomEvent("maze:firstMove"))}}),V=()=>{k.current=!0,C(`⏰ ${u.failMsg}`),p(!0),m({...b.current,isGameActive:!1})},te=()=>{k.current=!0,L.current=!0,C(`🎉 ${u.successMsg}`),p(!0),m(F=>({...F,isGameActive:!1})),window.dispatchEvent(new CustomEvent("maze:gameSuccess"))},K=()=>{if(p(!1),!k.current){m(F=>({...F,isGameActive:!0}));return}y(!1),m(F=>({...F,showClue:!0})),L.current?c?.(S.current):l?.()};return I(()=>{(async()=>{v(!0);try{const q=xn({size:t,seed:n,method:o,foodCount:i,foodRace:s,clue:a,fogEnabled:b.current.fogEnabled??h});b.current=q,m(q)}catch(q){console.error("Error generating single maze:",q)}finally{v(!1)}})()},[e,h]),I(()=>{let F;const q=!document.hidden,ae=()=>{const Ce=E.current?.getContext("2d"),le=b.current;if(!(q&&le?.isGameActive&&Ce&&le?.maze)){F=requestAnimationFrame(ae);return}$(),zt(),F=requestAnimationFrame(ae)},zt=()=>{const Ce=E.current?.getContext("2d"),le=b.current;Ce&&le?.maze&&bt(Ce,le,x.current,O.current,r)};return A.current=zt,F=requestAnimationFrame(ae),()=>{cancelAnimationFrame(F)}},[]),I(()=>{G(),Y()},[e,G,Y]),I(()=>{const F=q=>{S.current=q.detail.timeUsed};return window.addEventListener("maze:timeUsed",F),window.addEventListener("maze:timeUp",V),()=>{window.removeEventListener("maze:timeUsed",F),window.removeEventListener("maze:timeUp",V)}},[]),g?_("div",{className:"single-maze-loading",children:_("div",{children:"Generating maze..."})}):f?_("div",{className:"maze-game-container",children:[_("div",{className:"single-maze-toolbar",children:w&&_(Rn,{timer:d})}),_("div",{className:"single-maze-canvas-container",ref:M,children:_("canvas",{ref:E,className:"maze-game-canvas"})}),_(se,{isOpen:T,title:z,noConfirm:!0,cancelText:"OK",onCancel:K})]}):_("div",{className:"single-maze-error",children:_("div",{children:"Failed to generate maze"})})}const kt=[[{size:8,seed:12345,method:"backtracking",wallWidth:4,exitWallWidth:6,exitDashArray:[8,12]},{size:8,seed:23456,method:"backtracking",exitColor:"#33f",exitWallWidth:4,exitDashArray:[8,16]},{size:8,seed:34567,method:"prims"},{size:8,seed:45678,method:"backtracking"},{size:9,seed:56789,method:"prims"},{size:9,seed:67890,method:"backtracking"},{size:9,seed:78901,method:"prims"},{size:9,seed:89012,method:"backtracking"},{size:10,seed:90123,method:"prims"},{size:11,seed:11111,method:"backtracking"},{size:12,seed:22222,method:"prims"},{size:13,seed:33333,method:"backtracking"}],[{size:12,seed:44444,method:"prims"},{size:12,seed:55555,method:"backtracking"},{size:12,seed:66666,method:"prims"},{size:12,seed:77777,method:"backtracking"},{size:13,seed:88888,method:"prims"},{size:13,seed:99999,method:"backtracking"},{size:13,seed:12121,method:"prims"},{size:14,seed:23232,method:"backtracking"},{size:15,seed:34343,method:"prims"},{size:16,seed:45454,method:"backtracking"},{size:17,seed:56565,method:"prims"},{size:18,seed:67676,method:"backtracking"}],[{size:19,seed:78787,method:"prims"},{size:20,seed:89898,method:"backtracking"},{size:21,seed:90909,method:"prims"},{size:22,seed:10101,method:"backtracking"},{size:23,seed:20202,method:"prims"},{size:25,seed:30303,method:"backtracking"},{size:27,seed:40404,method:"prims"},{size:29,seed:50505,method:"backtracking"},{size:31,seed:60606,method:"prims"},{size:33,seed:70707,method:"backtracking"},{size:37,seed:80808,method:"prims"},{size:40,seed:90909,method:"backtracking"}],[{size:41,seed:10111,method:"prims"},{size:42,seed:11121,method:"backtracking"},{size:43,seed:12131,method:"prims"},{size:44,seed:13141,method:"backtracking"},{size:45,seed:14151,method:"prims"},{size:46,seed:15161,method:"backtracking"},{size:47,seed:16171,method:"prims"},{size:48,seed:17181,method:"backtracking"},{size:49,seed:18191,method:"prims"},{size:50,seed:19201,method:"backtracking"},{size:51,seed:20211,method:"prims"},{size:52,seed:21221,method:"backtracking"}],[{size:53,seed:22231,method:"prims"},{size:54,seed:23241,method:"backtracking"},{size:55,seed:24251,method:"prims"},{size:56,seed:25261,method:"backtracking"},{size:57,seed:26271,method:"prims"},{size:58,seed:27281,method:"backtracking"},{size:59,seed:28291,method:"prims"},{size:60,seed:29301,method:"backtracking"},{size:62,seed:30311,method:"prims"},{size:64,seed:31321,method:"backtracking"},{size:66,seed:32331,method:"prims"},{size:68,seed:33341,method:"backtracking"}]],Et={gridMoveSpeed:.07,padding:10,wallWidth:2,wallColor:"#222",foodColor:"#FFD54F",clueColor:"rgb(255,0,0)",backgroundColor:"#ffffff",playerColor:"#4CAF50",playerRadius:.2,fogEnabled:!0,fogRadius:3.6,fogColor:"rgba(8, 10, 18, 0.9)",fogSoftness:.55,exitColor:"#F44336",exitWallWidth:4,exitDashArray:[8,12]},pe={lcPrefix:"maze-",i18n:{reset:"Reset",resetTip:"Reset all game data and highest score.",confirmReset:"Confirm Reset",confirmResetMessage:"Are you sure you want to reset the game? All progress will be lost.",cancel:"Cancel",close:"Close",confirm:"Confirm",resetDoneToast:"Game reset! Starting from Level 1...",confirmClue:"Confirm to turn on clue?",confirmClueMessage:"Are you sure you want to turn on clue? Your will lose 1 ★.",level:"Level",tier:"Tier",settings:"Settings",clueOn:"Clue: ON",clueOff:"Clue: OFF",foodCollectedToast:"Food collected! %NUM% remaining.",allFoodCollectedToast:"All food collected! Head to the exit.",congratulations:"Congratulations!",findYourExit:"Find your exit!",withoutClue:"Without clue!",withClue:"You used the clue!",collectAllStars:"Collect all stars!",notCollectAllStars:"Not collect all stars.",nextLevel:"Next Level ➤",spacebarTip:"Spacebar",retry:"Retry",levelComplete:"Level Complete",starsCollected:"Stars Collected",avgStarPerLevel:"Avg. Stars per Level",levelCompleteToast:"Level completed! 🎉",tierUnlockedToast:"Tier %TIER% unlocked! 🎉",levelGoToast:"Level %LEVEL% - Go!",levelRestartToast:"Level restarted",allLevelsCompleted:"You completed all levels!",lastOK:"OK",notCompleteLevel:"You still have levels not collected all stars! Try again to collect them all!",continueMessage:"You still have levels where you haven't collected all stars. Try again to collect them all!",continue:"Continue",cluePathEnabled:"Clue Path Enabled",cluePathDisabled:"Clue Path Disabled",useArrowKeyTips:"Use arrow keys to navigate the maze. Press'C' to toggle path clue.",fogOn:"Fog: ON",fogOff:"Fog: OFF",fogEnabledToast:"Fog enabled",fogDisabledToast:"Fog disabled"},renderConfig:Et,levelConfig:kt},we={i18n:{successMsg:"Congratulations! You completed the maze!",failMsg:"Time is up!",foodMsg:"Please collect all stars before leaving!",fogOn:"Fog: ON",fogOff:"Fog: OFF"},size:8,seed:12345,method:"backtracking",clue:!1,foodCount:0,foodRace:!1,renderConfig:Et,timer:600,successCallback:()=>{console.log("🎉 Single maze completed successfully!")},failCallback:()=>{console.log("⏰ Time is up! Game failed.")}};function On({config:e={}}){const t={...pe.i18n,...e.i18n||{}},n={...pe.renderConfig,...e.renderConfig||{}},o=e.levelConfig||kt,i={...pe,...e,i18n:t,levelConfig:o,renderConfig:n};return _(Gt,{config:i,children:_(In,{})})}function $n({config:e={}}){const t={...we.i18n,...e.i18n||{}},n={...we.renderConfig,...e.renderConfig||{}},o={...we,...e,i18n:t,renderConfig:n};return _(Dn,{config:o})}const Un={root:"https://unpkg.com/@roudanio/maze@0.3.1/dist/",...pe};`${JSON.stringify(Un,null,2)}`;const Gn={root:"https://unpkg.com/@roudanio/maze@0.3.1/dist/",...we};return`${JSON.stringify(Gn,(e,t)=>typeof t=="function"?t.toString():t,2)}`,{showNotice(){console.warn("Cannot find the root element");const e=document.createElement("div");e.style.textAlign="center",e.style.padding="20px",e.innerHTML="Cannot find the root element",document.body.append(e)},addLoadingIndicator(e){const t=document.createElement("div"),n=document.createElement("div");t.style.cssText=`
|
|
1
|
+
(function(H,N){typeof exports=="object"&&typeof module<"u"?module.exports=N():typeof define=="function"&&define.amd?define(N):(H=typeof globalThis<"u"?globalThis:H||self,H.Maze=N())})(this,(function(){"use strict";var H,N,Ie,X,Re,Fe,De,Oe,ye,be,Te,$e,ne={},Ue=[],Mt=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,ce=Array.isArray;function B(e,t){for(var n in t)e[n]=t[n];return e}function Se(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function Lt(e,t,n){var o,i,s,a={};for(s in t)s=="key"?o=t[s]:s=="ref"?i=t[s]:a[s]=t[s];if(arguments.length>2&&(a.children=arguments.length>3?H.call(arguments,2):n),typeof e=="function"&&e.defaultProps!=null)for(s in e.defaultProps)a[s]===void 0&&(a[s]=e.defaultProps[s]);return ue(e,a,o,i,null)}function ue(e,t,n,o,i){var s={type:e,props:t,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++Ie,__i:-1,__u:0};return i==null&&N.vnode!=null&&N.vnode(s),s}function de(e){return e.children}function he(e,t){this.props=e,this.context=t}function J(e,t){if(t==null)return e.__?J(e.__,e.__i+1):null;for(var n;t<e.__k.length;t++)if((n=e.__k[t])!=null&&n.__e!=null)return n.__e;return typeof e.type=="function"?J(e):null}function Ge(e){var t,n;if((e=e.__)!=null&&e.__c!=null){for(e.__e=e.__c.base=null,t=0;t<e.__k.length;t++)if((n=e.__k[t])!=null&&n.__e!=null){e.__e=e.__c.base=n.__e;break}return Ge(e)}}function ke(e){(!e.__d&&(e.__d=!0)&&X.push(e)&&!fe.__r++||Re!=N.debounceRendering)&&((Re=N.debounceRendering)||Fe)(fe)}function fe(){for(var e,t,n,o,i,s,a,r=1;X.length;)X.length>r&&X.sort(De),e=X.shift(),r=X.length,e.__d&&(n=void 0,o=void 0,i=(o=(t=e).__v).__e,s=[],a=[],t.__P&&((n=B({},o)).__v=o.__v+1,N.vnode&&N.vnode(n),Ee(t.__P,n,o,t.__n,t.__P.namespaceURI,32&o.__u?[i]:null,s,i??J(o),!!(32&o.__u),a),n.__v=o.__v,n.__.__k[n.__i]=n,Ve(s,n,a),o.__e=o.__=null,n.__e!=i&&Ge(n)));fe.__r=0}function je(e,t,n,o,i,s,a,r,c,l,d){var u,h,f,m,g,v,w,y=o&&o.__k||Ue,T=t.length;for(c=Nt(n,t,y,c,T),u=0;u<T;u++)(f=n.__k[u])!=null&&(h=f.__i==-1?ne:y[f.__i]||ne,f.__i=u,v=Ee(e,f,h,i,s,a,r,c,l,d),m=f.__e,f.ref&&h.ref!=f.ref&&(h.ref&&Me(h.ref,null,f),d.push(f.ref,f.__c||m,f)),g==null&&m!=null&&(g=m),(w=!!(4&f.__u))||h.__k===f.__k?c=We(f,c,e,w):typeof f.type=="function"&&v!==void 0?c=v:m&&(c=m.nextSibling),f.__u&=-7);return n.__e=g,c}function Nt(e,t,n,o,i){var s,a,r,c,l,d=n.length,u=d,h=0;for(e.__k=new Array(i),s=0;s<i;s++)(a=t[s])!=null&&typeof a!="boolean"&&typeof a!="function"?(c=s+h,(a=e.__k[s]=typeof a=="string"||typeof a=="number"||typeof a=="bigint"||a.constructor==String?ue(null,a,null,null,null):ce(a)?ue(de,{children:a},null,null,null):a.constructor==null&&a.__b>0?ue(a.type,a.props,a.key,a.ref?a.ref:null,a.__v):a).__=e,a.__b=e.__b+1,r=null,(l=a.__i=At(a,n,c,u))!=-1&&(u--,(r=n[l])&&(r.__u|=2)),r==null||r.__v==null?(l==-1&&(i>d?h--:i<d&&h++),typeof a.type!="function"&&(a.__u|=4)):l!=c&&(l==c-1?h--:l==c+1?h++:(l>c?h--:h++,a.__u|=4))):e.__k[s]=null;if(u)for(s=0;s<d;s++)(r=n[s])!=null&&(2&r.__u)==0&&(r.__e==o&&(o=J(r)),Xe(r,r));return o}function We(e,t,n,o){var i,s;if(typeof e.type=="function"){for(i=e.__k,s=0;i&&s<i.length;s++)i[s]&&(i[s].__=e,t=We(i[s],t,n,o));return t}e.__e!=t&&(o&&(t&&e.type&&!t.parentNode&&(t=J(e)),n.insertBefore(e.__e,t||null)),t=e.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function At(e,t,n,o){var i,s,a,r=e.key,c=e.type,l=t[n],d=l!=null&&(2&l.__u)==0;if(l===null&&e.key==null||d&&r==l.key&&c==l.type)return n;if(o>(d?1:0)){for(i=n-1,s=n+1;i>=0||s<t.length;)if((l=t[a=i>=0?i--:s++])!=null&&(2&l.__u)==0&&r==l.key&&c==l.type)return a}return-1}function qe(e,t,n){t[0]=="-"?e.setProperty(t,n??""):e[t]=n==null?"":typeof n!="number"||Mt.test(t)?n:n+"px"}function me(e,t,n,o,i){var s,a;e:if(t=="style")if(typeof n=="string")e.style.cssText=n;else{if(typeof o=="string"&&(e.style.cssText=o=""),o)for(t in o)n&&t in n||qe(e.style,t,"");if(n)for(t in n)o&&n[t]==o[t]||qe(e.style,t,n[t])}else if(t[0]=="o"&&t[1]=="n")s=t!=(t=t.replace(Oe,"$1")),a=t.toLowerCase(),t=a in e||t=="onFocusOut"||t=="onFocusIn"?a.slice(2):t.slice(2),e.l||(e.l={}),e.l[t+s]=n,n?o?n.u=o.u:(n.u=ye,e.addEventListener(t,s?Te:be,s)):e.removeEventListener(t,s?Te:be,s);else{if(i=="http://www.w3.org/2000/svg")t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(t!="width"&&t!="height"&&t!="href"&&t!="list"&&t!="form"&&t!="tabIndex"&&t!="download"&&t!="rowSpan"&&t!="colSpan"&&t!="role"&&t!="popover"&&t in e)try{e[t]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&t[4]!="-"?e.removeAttribute(t):e.setAttribute(t,t=="popover"&&n==1?"":n))}}function Be(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t.t==null)t.t=ye++;else if(t.t<n.u)return;return n(N.event?N.event(t):t)}}}function Ee(e,t,n,o,i,s,a,r,c,l){var d,u,h,f,m,g,v,w,y,T,p,z,C,S,k,L,E,M=t.type;if(t.constructor!=null)return null;128&n.__u&&(c=!!(32&n.__u),s=[r=t.__e=n.__e]),(d=N.__b)&&d(t);e:if(typeof M=="function")try{if(w=t.props,y="prototype"in M&&M.prototype.render,T=(d=M.contextType)&&o[d.__c],p=d?T?T.props.value:d.__:o,n.__c?v=(u=t.__c=n.__c).__=u.__E:(y?t.__c=u=new M(w,p):(t.__c=u=new he(w,p),u.constructor=M,u.render=xt),T&&T.sub(u),u.props=w,u.state||(u.state={}),u.context=p,u.__n=o,h=u.__d=!0,u.__h=[],u._sb=[]),y&&u.__s==null&&(u.__s=u.state),y&&M.getDerivedStateFromProps!=null&&(u.__s==u.state&&(u.__s=B({},u.__s)),B(u.__s,M.getDerivedStateFromProps(w,u.__s))),f=u.props,m=u.state,u.__v=t,h)y&&M.getDerivedStateFromProps==null&&u.componentWillMount!=null&&u.componentWillMount(),y&&u.componentDidMount!=null&&u.__h.push(u.componentDidMount);else{if(y&&M.getDerivedStateFromProps==null&&w!==f&&u.componentWillReceiveProps!=null&&u.componentWillReceiveProps(w,p),!u.__e&&u.shouldComponentUpdate!=null&&u.shouldComponentUpdate(w,u.__s,p)===!1||t.__v==n.__v){for(t.__v!=n.__v&&(u.props=w,u.state=u.__s,u.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(b){b&&(b.__=t)}),z=0;z<u._sb.length;z++)u.__h.push(u._sb[z]);u._sb=[],u.__h.length&&a.push(u);break e}u.componentWillUpdate!=null&&u.componentWillUpdate(w,u.__s,p),y&&u.componentDidUpdate!=null&&u.__h.push(function(){u.componentDidUpdate(f,m,g)})}if(u.context=p,u.props=w,u.__P=e,u.__e=!1,C=N.__r,S=0,y){for(u.state=u.__s,u.__d=!1,C&&C(t),d=u.render(u.props,u.state,u.context),k=0;k<u._sb.length;k++)u.__h.push(u._sb[k]);u._sb=[]}else do u.__d=!1,C&&C(t),d=u.render(u.props,u.state,u.context),u.state=u.__s;while(u.__d&&++S<25);u.state=u.__s,u.getChildContext!=null&&(o=B(B({},o),u.getChildContext())),y&&!h&&u.getSnapshotBeforeUpdate!=null&&(g=u.getSnapshotBeforeUpdate(f,m)),L=d,d!=null&&d.type===de&&d.key==null&&(L=He(d.props.children)),r=je(e,ce(L)?L:[L],t,n,o,i,s,a,r,c,l),u.base=t.__e,t.__u&=-161,u.__h.length&&a.push(u),v&&(u.__E=u.__=null)}catch(b){if(t.__v=null,c||s!=null)if(b.then){for(t.__u|=c?160:128;r&&r.nodeType==8&&r.nextSibling;)r=r.nextSibling;s[s.indexOf(r)]=null,t.__e=r}else{for(E=s.length;E--;)Se(s[E]);ze(t)}else t.__e=n.__e,t.__k=n.__k,b.then||ze(t);N.__e(b,t,n)}else s==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):r=t.__e=Pt(n.__e,t,n,o,i,s,a,c,l);return(d=N.diffed)&&d(t),128&t.__u?void 0:r}function ze(e){e&&e.__c&&(e.__c.__e=!0),e&&e.__k&&e.__k.forEach(ze)}function Ve(e,t,n){for(var o=0;o<n.length;o++)Me(n[o],n[++o],n[++o]);N.__c&&N.__c(t,e),e.some(function(i){try{e=i.__h,i.__h=[],e.some(function(s){s.call(i)})}catch(s){N.__e(s,i.__v)}})}function He(e){return typeof e!="object"||e==null||e.__b&&e.__b>0?e:ce(e)?e.map(He):B({},e)}function Pt(e,t,n,o,i,s,a,r,c){var l,d,u,h,f,m,g,v=n.props,w=t.props,y=t.type;if(y=="svg"?i="http://www.w3.org/2000/svg":y=="math"?i="http://www.w3.org/1998/Math/MathML":i||(i="http://www.w3.org/1999/xhtml"),s!=null){for(l=0;l<s.length;l++)if((f=s[l])&&"setAttribute"in f==!!y&&(y?f.localName==y:f.nodeType==3)){e=f,s[l]=null;break}}if(e==null){if(y==null)return document.createTextNode(w);e=document.createElementNS(i,y,w.is&&w),r&&(N.__m&&N.__m(t,s),r=!1),s=null}if(y==null)v===w||r&&e.data==w||(e.data=w);else{if(s=s&&H.call(e.childNodes),v=n.props||ne,!r&&s!=null)for(v={},l=0;l<e.attributes.length;l++)v[(f=e.attributes[l]).name]=f.value;for(l in v)if(f=v[l],l!="children"){if(l=="dangerouslySetInnerHTML")u=f;else if(!(l in w)){if(l=="value"&&"defaultValue"in w||l=="checked"&&"defaultChecked"in w)continue;me(e,l,null,f,i)}}for(l in w)f=w[l],l=="children"?h=f:l=="dangerouslySetInnerHTML"?d=f:l=="value"?m=f:l=="checked"?g=f:r&&typeof f!="function"||v[l]===f||me(e,l,f,v[l],i);if(d)r||u&&(d.__html==u.__html||d.__html==e.innerHTML)||(e.innerHTML=d.__html),t.__k=[];else if(u&&(e.innerHTML=""),je(t.type=="template"?e.content:e,ce(h)?h:[h],t,n,o,y=="foreignObject"?"http://www.w3.org/1999/xhtml":i,s,a,s?s[0]:n.__k&&J(n,0),r,c),s!=null)for(l=s.length;l--;)Se(s[l]);r||(l="value",y=="progress"&&m==null?e.removeAttribute("value"):m!=null&&(m!==e[l]||y=="progress"&&!m||y=="option"&&m!=v[l])&&me(e,l,m,v[l],i),l="checked",g!=null&&g!=e[l]&&me(e,l,g,v[l],i))}return e}function Me(e,t,n){try{if(typeof e=="function"){var o=typeof e.__u=="function";o&&e.__u(),o&&t==null||(e.__u=e(t))}else e.current=t}catch(i){N.__e(i,n)}}function Xe(e,t,n){var o,i;if(N.unmount&&N.unmount(e),(o=e.ref)&&(o.current&&o.current!=e.__e||Me(o,null,t)),(o=e.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(s){N.__e(s,t)}o.base=o.__P=null}if(o=e.__k)for(i=0;i<o.length;i++)o[i]&&Xe(o[i],t,n||typeof e.type!="function");n||Se(e.__e),e.__c=e.__=e.__e=void 0}function xt(e,t,n){return this.constructor(e,n)}function Ye(e,t,n){var o,i,s,a;t==document&&(t=document.documentElement),N.__&&N.__(e,t),i=(o=!1)?null:t.__k,s=[],a=[],Ee(t,e=t.__k=Lt(de,null,[e]),i||ne,ne,t.namespaceURI,i?null:t.firstChild?H.call(t.childNodes):null,s,i?i.__e:t.firstChild,o,a),Ve(s,e,a)}function It(e){function t(n){var o,i;return this.getChildContext||(o=new Set,(i={})[t.__c]=this,this.getChildContext=function(){return i},this.componentWillUnmount=function(){o=null},this.shouldComponentUpdate=function(s){this.props.value!=s.value&&o.forEach(function(a){a.__e=!0,ke(a)})},this.sub=function(s){o.add(s);var a=s.componentWillUnmount;s.componentWillUnmount=function(){o&&o.delete(s),a&&a.call(s)}}),n.children}return t.__c="__cC"+$e++,t.__=e,t.Provider=t.__l=(t.Consumer=function(n,o){return n.children(o)}).contextType=t,t}H=Ue.slice,N={__e:function(e,t,n,o){for(var i,s,a;t=t.__;)if((i=t.__c)&&!i.__)try{if((s=i.constructor)&&s.getDerivedStateFromError!=null&&(i.setState(s.getDerivedStateFromError(e)),a=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(e,o||{}),a=i.__d),a)return i.__E=i}catch(r){e=r}throw e}},Ie=0,he.prototype.setState=function(e,t){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=B({},this.state),typeof e=="function"&&(e=e(B({},n),this.props)),e&&B(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),ke(this))},he.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),ke(this))},he.prototype.render=de,X=[],Fe=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,De=function(e,t){return e.__v.__b-t.__v.__b},fe.__r=0,Oe=/(PointerCapture)$|Capture$/i,ye=0,be=Be(!1),Te=Be(!0),$e=0;var Rt=0;function _(e,t,n,o,i,s){t||(t={});var a,r,c=t;if("ref"in c)for(r in c={},t)r=="ref"?a=t[r]:c[r]=t[r];var l={type:e,props:c,key:n,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Rt,__i:-1,__u:0,__source:i,__self:s};if(typeof e=="function"&&(a=e.defaultProps))for(r in a)c[r]===void 0&&(c[r]=a[r]);return N.vnode&&N.vnode(l),l}var Q,x,Le,Ke,oe=0,Je=[],O=N,Qe=O.__b,Ze=O.__r,et=O.diffed,tt=O.__c,nt=O.unmount,ot=O.__;function _e(e,t){O.__h&&O.__h(x,e,oe||t),oe=0;var n=x.__H||(x.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function U(e){return oe=1,Ft(at,e)}function Ft(e,t,n){var o=_e(Q++,2);if(o.t=e,!o.__c&&(o.__=[at(void 0,t),function(r){var c=o.__N?o.__N[0]:o.__[0],l=o.t(c,r);c!==l&&(o.__N=[l,o.__[1]],o.__c.setState({}))}],o.__c=x,!x.__f)){var i=function(r,c,l){if(!o.__c.__H)return!0;var d=o.__c.__H.__.filter(function(h){return!!h.__c});if(d.every(function(h){return!h.__N}))return!s||s.call(this,r,c,l);var u=o.__c.props!==r;return d.forEach(function(h){if(h.__N){var f=h.__[0];h.__=h.__N,h.__N=void 0,f!==h.__[0]&&(u=!0)}}),s&&s.call(this,r,c,l)||u};x.__f=!0;var s=x.shouldComponentUpdate,a=x.componentWillUpdate;x.componentWillUpdate=function(r,c,l){if(this.__e){var d=s;s=void 0,i(r,c,l),s=d}a&&a.call(this,r,c,l)},x.shouldComponentUpdate=i}return o.__N||o.__}function I(e,t){var n=_e(Q++,3);!O.__s&&st(n.__H,t)&&(n.__=e,n.u=t,x.__H.__h.push(n))}function D(e){return oe=5,Z(function(){return{current:e}},[])}function Z(e,t){var n=_e(Q++,7);return st(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function rt(e,t){return oe=8,Z(function(){return e},t)}function Dt(e){var t=x.context[e.__c],n=_e(Q++,9);return n.c=e,t?(n.__==null&&(n.__=!0,t.sub(x)),t.props.value):e.__}function Ot(){for(var e;e=Je.shift();)if(e.__P&&e.__H)try{e.__H.__h.forEach(ve),e.__H.__h.forEach(Ne),e.__H.__h=[]}catch(t){e.__H.__h=[],O.__e(t,e.__v)}}O.__b=function(e){x=null,Qe&&Qe(e)},O.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),ot&&ot(e,t)},O.__r=function(e){Ze&&Ze(e),Q=0;var t=(x=e.__c).__H;t&&(Le===x?(t.__h=[],x.__h=[],t.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.forEach(ve),t.__h.forEach(Ne),t.__h=[],Q=0)),Le=x},O.diffed=function(e){et&&et(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(Je.push(t)!==1&&Ke===O.requestAnimationFrame||((Ke=O.requestAnimationFrame)||$t)(Ot)),t.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),Le=x=null},O.__c=function(e,t){t.some(function(n){try{n.__h.forEach(ve),n.__h=n.__h.filter(function(o){return!o.__||Ne(o)})}catch(o){t.some(function(i){i.__h&&(i.__h=[])}),t=[],O.__e(o,n.__v)}}),tt&&tt(e,t)},O.unmount=function(e){nt&&nt(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.forEach(function(o){try{ve(o)}catch(i){t=i}}),n.__H=void 0,t&&O.__e(t,n.__v))};var it=typeof requestAnimationFrame=="function";function $t(e){var t,n=function(){clearTimeout(o),it&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(n,35);it&&(t=requestAnimationFrame(n))}function ve(e){var t=x,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),x=t}function Ne(e){var t=x;e.__c=e.__(),x=t}function st(e,t){return!e||e.length!==t.length||t.some(function(n,o){return n!==e[o]})}function at(e,t){return typeof t=="function"?t(e):t}const Ut=e=>({saveGameData(t){try{localStorage.setItem(e,JSON.stringify(t))}catch(n){console.error("Failed to save maze game data:",n)}},loadGameData(){try{const t=localStorage.getItem(e);return t?JSON.parse(t):null}catch(t){return console.error("Failed to load maze game data:",t),null}},resetGameData(){try{localStorage.removeItem(e)}catch(t){console.error("Failed to reset maze game data:",t)}}}),lt=It(void 0),ct={currentLevel:1,highestUnlockedLevel:1,currentTier:1,highestUnlockedTier:1,levelScores:{},totalScore:0},ut={isGameActive:!0,levelTransitioning:!1,maze:null,playerCell:{row:0,col:0},exitCell:{row:0,col:0},foodCells:[],fogEnabled:!1,playerAtExit:!1,foodCollected:0,totalFoodCount:0,showClue:!1,playerPath:[],visitCounts:{}},Gt=({children:e,config:t})=>{const n=Ut(t.lcPrefix+"progress"),o=n.loadGameData(),i=t.renderConfig?.fogEnabled??!0,s=()=>({...ut,fogEnabled:i}),[a,r]=U(()=>o||{...ct});I(()=>{const f=Object.values(a.levelScores).reduce((m,g)=>m+g,0);r(m=>({...m,totalScore:f}))},[a.levelScores]),I(()=>{n.saveGameData(a)},[a.currentLevel,a.highestUnlockedLevel,a.currentTier,a.highestUnlockedTier,a.levelScores,a.totalScore]);const[c,l]=U({...s()}),d=D(c);I(()=>{d.current=c},[c]);const u=Z(()=>[c.playerAtExit?1:0,c.foodCollected===c.totalFoodCount?1:0,c.showClue?0:1],[c.playerAtExit,c.foodCollected,c.totalFoodCount,c.showClue]),h=()=>{n.resetGameData(),r({...ct}),l({...s()})};return _(lt.Provider,{value:{gameProgress:a,setGameProgress:r,gamePlayState:c,setGamePlayState:l,gamePlayStateRef:d,currentScore:u,config:t,resetGame:h},children:e})},re=()=>{const e=Dt(lt);if(!e)throw new Error("useGameContext must be used within a GameProvider");return e},ie=e=>Z(()=>{const t=e.map(r=>r.length),n=t.reduce((r,c)=>r+c,0),o=e.length,i=r=>{if(r<1||r>n)return 0;let c=0;for(let l=0;l<t.length;l++)if(c+=t[l],r<=c)return l+1;return 0},s=r=>r<1||r>o?0:t.slice(0,r-1).reduce((c,l)=>c+l,0)+1,a={getTotalLevels:()=>n,getTotalTiers:()=>o,getTierLevelsRange:r=>{if(r<1||r>o)return[0,0];const c=s(r),l=c+t[r-1]-1;return[c,l]},getTierByLevel:i,getFirstLevelOfTier:s,getLevelConfig:r=>{if(r<1||r>n)return null;const c=i(r),l=s(c),d=r-l;return e[c-1][d]},getTierConfig:r=>r<1||r>o?null:e[r-1],isLevelUnlocked:(r,c)=>r<=c,isTierUnlocked:(r,c)=>r<=c,getNextLevelInfo:r=>{if(r>=n)return null;const c=r+1,l=i(r),d=i(c);return{nextLevel:c,nextTier:d,isTierChange:d>l}},getCurrentTierProgress:(r,c)=>{const[l,d]=a.getTierLevelsRange(c),u=r-l+1,h=d-l+1;return{current:u,total:h}},isLastLevelInTier:r=>{const c=i(r),[,l]=a.getTierLevelsRange(c);return r===l},getPreviousLevelInfo:r=>{if(r<=1)return null;const c=r-1,l=i(r),d=i(c);return{prevLevel:c,prevTier:d,isTierChange:d<l}}};return a},[e]),jt=({onTierChange:e,disabled:t})=>{const{gameProgress:n,config:o}=re(),{i18n:i,levelConfig:s}=o,{currentTier:a,highestUnlockedTier:r}=n,l=ie(s).getTotalTiers();return _("div",{className:"tier-selector",children:_("select",{value:a,onChange:d=>{d.target&&d.target.value&&e(Number(d.target.value))},disabled:t,className:"tier-dropdown",children:Array.from({length:l},(d,u)=>u+1).map(d=>_("option",{value:d,disabled:d>r,children:i.tier+" "+d},`tier-${d}`))})})},Wt=({onLevelChange:e,disabled:t})=>{const{gameProgress:n,config:o}=re(),{i18n:i,levelConfig:s}=o,{currentTier:a,levelScores:r,currentLevel:c,highestUnlockedLevel:l}=n,d=ie(s),u=Z(()=>{const[h,f]=d.getTierLevelsRange(a);return Array.from({length:f-h+1},(m,g)=>{const v=h+g,w=r[v]||0;return{level:v,score:w}})},[a,r]);return _("div",{className:"level-selector",children:_("select",{value:c,onChange:h=>{h.target&&h.target.value&&e(Number(h.target.value))},disabled:t,className:"level-dropdown",children:u.map(({level:h,score:f})=>_("option",{value:h,disabled:h>l,children:`${i.level} ${h} ${"★".repeat(f)}`},`level-${h}`))})})},se=({isOpen:e,title:t,className:n="",message:o,children:i,noConfirm:s=!1,noCancel:a=!1,confirmText:r="OK",cancelText:c="Cancel",confirmClass:l="",cancelClass:d="",onConfirm:u,onCancel:h})=>{const f=D(null);return I(()=>{const m=g=>{g.key==="Escape"&&h?.()};return e&&document.addEventListener("keydown",m),()=>{document.removeEventListener("keydown",m)}},[e,h]),_("div",{className:`maze-dialog-overlay ${e?"maze-dialog-visible":""}`,children:_("div",{className:"maze-dialog "+n,ref:f,children:[_("div",{className:"maze-dialog-title",children:t}),_("div",{className:"maze-dialog-content",children:i||_("div",{className:"maze-dialog-message",children:o})}),(!a||!s)&&_("div",{className:"maze-dialog-buttons",children:[!a&&_("button",{type:"button",className:"maze-dialog-cancel "+d,onClick:h,children:c}),!s&&_("button",{type:"button",className:"maze-dialog-confirm "+l,onClick:u,children:r})]})]})})},j={container:null,attachTo(e){return this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.container=document.createElement("div"),this.container.className="toast-container position-bottom",e.appendChild(this.container),this.container},currentToast:null,currentTimer:null,show(e,t=2e3){if(!this.container){console.warn("NativeToast: container not initialized, please call attachTo first");return}this.currentToast&&this.container.contains(this.currentToast)&&(this.container.removeChild(this.currentToast),this.currentToast=null),this.currentTimer&&(clearTimeout(this.currentTimer),this.currentTimer=null);const n=document.createElement("div");n.className="toast-message toast-visible",n.textContent=e,this.container.appendChild(n),this.currentToast=n,this.currentTimer=setTimeout(()=>{n.classList.remove("toast-visible"),setTimeout(()=>{this.container&&this.container.contains(n)&&(this.container.removeChild(n),this.currentToast===n&&(this.currentToast=null))},300),this.currentTimer=null},t)},clearAll(){if(this.container)for(;this.container.firstChild;)this.container.removeChild(this.container.firstChild)}},qt=()=>{const{gameProgress:e,setGameProgress:t,gamePlayState:n,setGamePlayState:o,gamePlayStateRef:i,resetGame:s,config:a}=re(),{i18n:r,levelConfig:c}=a,l=ie(c),{levelTransitioning:d,showClue:u}=n,{highestUnlockedLevel:h,totalScore:f}=e,m=l.getTotalLevels(),[g,v]=U(!1),[w,y]=U(!1),[T,p]=U(!1),z=R=>{const $=l.getFirstLevelOfTier(R);l.isLevelUnlocked($,h)&&(t(G=>({...G,currentTier:R})),C($))},C=R=>{l.isLevelUnlocked(R,h)&&(t($=>({...$,currentLevel:R})),j.show(r.levelGoToast.replace("%LEVEL%",R.toString())))},S=()=>{v(!0)},k=()=>{v(!1)},L=()=>{p(!0)},E=()=>{p(!1)},M=()=>{j.show(u?r.cluePathDisabled:r.cluePathEnabled),o(()=>({...i.current,showClue:!i.current.showClue})),p(!1)},b=()=>{y(!0)},A=()=>{s(),y(!1),j.show(r.resetDoneToast)},P=()=>{y(!1)};return _("div",{class:"game-panel-container",children:[_("div",{className:"game-controls",children:[_("div",{className:"selectors-container",children:[_(jt,{onTierChange:z,disabled:d}),_(Wt,{onLevelChange:C,disabled:d})]}),_("button",{className:`settings-clue-button ${u?"clue-on":"clue-off"}`,disabled:u,title:"Toggle Clue",onClick:L,children:u?r.clueOn:r.clueOff})]}),_("div",{className:"game-settings",children:_("span",{className:"game-settings-icon",onClick:S,children:"★ "+f})}),_(se,{isOpen:g,title:r.settings,noConfirm:!0,cancelText:r.close,onCancel:k,children:[_("div",{className:"settings-stats",children:[_("div",{children:r.levelComplete+`: ${h}/${m}`}),_("div",{children:r.starsCollected+": "+f}),_("div",{children:r.avgStarPerLevel+": "+(f/h).toFixed(2)})]}),_("div",{className:"settings-item-box",children:[_("button",{className:"settings-reset-button",title:"Reset Game",onClick:b,children:r.reset}),_("div",{className:"settings-item-tip",children:r.resetTip})]})]}),_(se,{isOpen:w,title:r.confirmReset,message:r.confirmResetMessage,confirmText:r.reset,cancelText:r.cancel,onConfirm:A,onCancel:P}),_(se,{isOpen:T,title:r.confirmClue,message:r.confirmClueMessage,confirmText:r.confirm,cancelText:r.cancel,onConfirm:M,onCancel:E})]})};function Ae(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Bt(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function Pe(e,t,n){return t&&Bt(e.prototype,t),e}function dt(e){return+e.replace(/px/,"")}function Vt(e){var t=window.devicePixelRatio,n=getComputedStyle(e),o=dt(n.getPropertyValue("width")),i=dt(n.getPropertyValue("height"));e.setAttribute("width",(o*t).toString()),e.setAttribute("height",(i*t).toString())}function W(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,o=Math.random()*(t-e)+e;return Math.floor(o*Math.pow(10,n))/Math.pow(10,n)}function ht(e){return e[W(0,e.length)]}var Ht=.00125,Xt=5e-4,Yt=9e-4,Kt=1e-5,Jt=6,Qt=80,Zt=.9,en=1.7,tn=.2,nn=.6,on=.03,rn=.07,ft=15,mt=82,sn=100,an=250,ln=40,cn=["#fcf403","#62fc03","#f4fc03","#03e7fc","#03fca5","#a503fc","#fc03ad","#fc03c2"];function _t(e){var t=1920;return Math.log(e)/Math.log(t)}var vt=(function(){function e(t){Ae(this,e);var n=t.initialPosition,o=t.direction,i=t.confettiRadius,s=t.confettiColors,a=t.emojis,r=t.emojiSize,c=t.canvasWidth,l=W(Zt,en,3),d=l*_t(c);this.confettiSpeed={x:d,y:d},this.finalConfettiSpeedX=W(tn,nn,3),this.rotationSpeed=a.length?.01:W(on,rn,3)*_t(c),this.dragForceCoefficient=W(Xt,Yt,6),this.radius={x:i,y:i},this.initialRadius=i,this.rotationAngle=o==="left"?W(0,.2,3):W(-.2,0,3),this.emojiSize=r,this.emojiRotationAngle=W(0,2*Math.PI),this.radiusYUpdateDirection="down";var u=o==="left"?W(mt,ft)*Math.PI/180:W(-ft,-mt)*Math.PI/180;this.absCos=Math.abs(Math.cos(u)),this.absSin=Math.abs(Math.sin(u));var h=W(-150,0),f={x:n.x+(o==="left"?-h:h)*this.absCos,y:n.y-h*this.absSin};this.currentPosition=Object.assign({},f),this.initialPosition=Object.assign({},f),this.color=a.length?null:ht(s),this.emoji=a.length?ht(a):null,this.createdAt=new Date().getTime(),this.direction=o}return Pe(e,[{key:"draw",value:function(n){var o=this.currentPosition,i=this.radius,s=this.color,a=this.emoji,r=this.rotationAngle,c=this.emojiRotationAngle,l=this.emojiSize,d=window.devicePixelRatio;s?(n.fillStyle=s,n.beginPath(),n.ellipse(o.x*d,o.y*d,i.x*d,i.y*d,r,0,2*Math.PI),n.fill()):a&&(n.font="".concat(l,"px serif"),n.save(),n.translate(d*o.x,d*o.y),n.rotate(c),n.textAlign="center",n.fillText(a,0,0),n.restore())}},{key:"updatePosition",value:function(n,o){var i=this.confettiSpeed,s=this.dragForceCoefficient,a=this.finalConfettiSpeedX,r=this.radiusYUpdateDirection,c=this.rotationSpeed,l=this.createdAt,d=this.direction,u=o-l;if(i.x>a&&(this.confettiSpeed.x-=s*n),this.currentPosition.x+=i.x*(d==="left"?-this.absCos:this.absCos)*n,this.currentPosition.y=this.initialPosition.y-i.y*this.absSin*u+Ht*Math.pow(u,2)/2,this.rotationSpeed-=this.emoji?1e-4:Kt*n,this.rotationSpeed<0&&(this.rotationSpeed=0),this.emoji){this.emojiRotationAngle+=this.rotationSpeed*n%(2*Math.PI);return}r==="down"?(this.radius.y-=n*c,this.radius.y<=0&&(this.radius.y=0,this.radiusYUpdateDirection="up")):(this.radius.y+=n*c,this.radius.y>=this.initialRadius&&(this.radius.y=this.initialRadius,this.radiusYUpdateDirection="down"))}},{key:"getIsVisibleOnCanvas",value:function(n){return this.currentPosition.y<n+sn}}]),e})();function un(){var e=document.createElement("canvas");return e.style.position="fixed",e.style.width="100%",e.style.height="100%",e.style.top="0",e.style.left="0",e.style.zIndex="1000",e.style.pointerEvents="none",document.body.appendChild(e),e}function dn(e){var t=e.confettiRadius,n=t===void 0?Jt:t,o=e.confettiNumber,i=o===void 0?e.confettiesNumber||(e.emojis?ln:an):o,s=e.confettiColors,a=s===void 0?cn:s,r=e.emojis,c=r===void 0?e.emojies||[]:r,l=e.emojiSize,d=l===void 0?Qt:l;return e.emojies&&console.error("emojies argument is deprecated, please use emojis instead"),e.confettiesNumber&&console.error("confettiesNumber argument is deprecated, please use confettiNumber instead"),{confettiRadius:n,confettiNumber:i,confettiColors:a,emojis:c,emojiSize:d}}var hn=(function(){function e(t){var n=this;Ae(this,e),this.canvasContext=t,this.shapes=[],this.promise=new Promise(function(o){return n.resolvePromise=o})}return Pe(e,[{key:"getBatchCompletePromise",value:function(){return this.promise}},{key:"addShapes",value:function(){var n;(n=this.shapes).push.apply(n,arguments)}},{key:"complete",value:function(){var n;return this.shapes.length?!1:((n=this.resolvePromise)===null||n===void 0||n.call(this),!0)}},{key:"processShapes",value:function(n,o,i){var s=this,a=n.timeDelta,r=n.currentTime;this.shapes=this.shapes.filter(function(c){return c.updatePosition(a,r),c.draw(s.canvasContext),i?c.getIsVisibleOnCanvas(o):!0})}}]),e})(),fn=(function(){function e(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Ae(this,e),this.activeConfettiBatches=[],this.canvas=t.canvas||un(),this.canvasContext=this.canvas.getContext("2d"),this.requestAnimationFrameRequested=!1,this.lastUpdated=new Date().getTime(),this.iterationIndex=0,this.loop=this.loop.bind(this),requestAnimationFrame(this.loop)}return Pe(e,[{key:"loop",value:function(){this.requestAnimationFrameRequested=!1,Vt(this.canvas);var n=new Date().getTime(),o=n-this.lastUpdated,i=this.canvas.offsetHeight,s=this.iterationIndex%10===0;this.activeConfettiBatches=this.activeConfettiBatches.filter(function(a){return a.processShapes({timeDelta:o,currentTime:n},i,s),s?!a.complete():!0}),this.iterationIndex++,this.queueAnimationFrameIfNeeded(n)}},{key:"queueAnimationFrameIfNeeded",value:function(n){this.requestAnimationFrameRequested||this.activeConfettiBatches.length<1||(this.requestAnimationFrameRequested=!0,this.lastUpdated=n||new Date().getTime(),requestAnimationFrame(this.loop))}},{key:"addConfetti",value:function(){for(var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},o=dn(n),i=o.confettiRadius,s=o.confettiNumber,a=o.confettiColors,r=o.emojis,c=o.emojiSize,l=this.canvas.getBoundingClientRect(),d=l.width,u=l.height,h=u*5/7,f={x:0,y:h},m={x:d,y:h},g=new hn(this.canvasContext),v=0;v<s/2;v++){var w=new vt({initialPosition:f,direction:"right",confettiRadius:i,confettiColors:a,confettiNumber:s,emojis:r,emojiSize:c,canvasWidth:d}),y=new vt({initialPosition:m,direction:"left",confettiRadius:i,confettiColors:a,confettiNumber:s,emojis:r,emojiSize:c,canvasWidth:d});g.addShapes(w,y)}return this.activeConfettiBatches.push(g),this.queueAnimationFrameIfNeeded(),g.getBatchCompletePromise()}},{key:"clearCanvas",value:function(){this.activeConfettiBatches=[]}},{key:"destroyCanvas",value:function(){this.canvas.remove()}}]),e})();const mn=new fn,xe=3,_n=({onRetry:e})=>{const{config:t,currentScore:n,gamePlayState:o,setGamePlayState:i,gameProgress:s,setGameProgress:a}=re(),{i18n:r,levelConfig:c}=t,[l,d,u]=n,{foodCollected:h,totalFoodCount:f,playerAtExit:m,levelTransitioning:g}=o,{currentLevel:v}=s,[w,y]=U(!1);I(()=>{m&&g&&(mn.addConfetti(),j.show(r.levelCompleteToast),y(!0))},[m,g]);const T=ie(c),p=T.getTotalLevels(),z=Z(()=>v>=p,[v,p]),C=()=>{y(!1),j.show(r.levelRestartToast),e?.()},S=()=>{y(!1),i(E=>({...E,isGameActive:!0,levelTransitioning:!1}))},k=()=>{y(!1);const E=T.getNextLevelInfo(v);if(!E)return;const{nextLevel:M,nextTier:b,isTierChange:A}=E;A&&j.show(r.tierUnlockedToast.replace("%TIER%",b.toString())),a(P=>({...P,currentLevel:M,currentTier:b,highestUnlockedLevel:Math.max(P.highestUnlockedLevel,M),highestUnlockedTier:Math.max(P.highestUnlockedTier,b),levelScores:{...P.levelScores,[P.currentLevel]:Math.max(Object.values(n).filter(Boolean).length,P.levelScores[P.currentLevel]||0)}}))},L=()=>{y(!1),a(E=>{const M=Math.max(Object.values(n).filter(Boolean).length,E.levelScores[E.currentLevel]||0),b={...E.levelScores,[E.currentLevel]:M};let A=0,P=0;const R=Object.entries(b).sort(($,G)=>Number($[0])-Number(G[0]));for(const[$,G]of R)if(G<xe){A=Number($),P=T.getTierByLevel(A);break}return(A>0&&A!==v||M<xe)&&j.show(r.notCompleteLevel),(A===0||M<xe)&&e?.(),{...E,currentLevel:A||E.currentLevel,currentTier:P||E.currentTier,levelScores:b}})};return I(()=>{const E=document.querySelector(".maze-game-container"),M=b=>{w&&((b.key===" "||b.code==="Space")&&E&&(E.contains(document.activeElement)||document.activeElement===document.body)&&(b.preventDefault(),z?L():k()),(b.key==="r"||b.code==="KeyR")&&C(),(b.key==="c"||b.code==="KeyC")&&S())};return window.addEventListener("keydown",M),()=>window.removeEventListener("keydown",M)},[w,z]),_(se,{className:"level-complete-dialog",isOpen:w,title:r.congratulations,cancelText:r.retry+" (R)",onCancel:C,noConfirm:!!d,confirmText:r.continue+" (C)",onConfirm:S,confirmClass:"maze-continue-btn",children:[_("div",{className:"maze-summary-message",children:[!!l&&_("div",{children:"★ - "+r.findYourExit}),_("div",{children:u?"★ - "+r.withoutClue:"☆ - "+r.withClue}),_("div",{children:(d?"★ - "+r.collectAllStars:"☆ - "+r.notCollectAllStars)+` (${h}/${f})`})]}),z&&_("div",{className:"all-levels-completed",children:r.allLevelsCompleted}),_("div",{className:"maze-go-next",children:z?_("button",{className:"maze-go-next-btn",type:"button",onClick:L,children:[_("span",{children:r.lastOK}),_("span",{className:"spacebar-tip",children:`(${r.spacebarTip})`})]}):_("button",{className:"maze-go-next-btn",type:"button",onClick:k,children:[_("span",{children:r.nextLevel}),_("span",{className:"spacebar-tip",children:`(${r.spacebarTip})`})]})}),!d&&_("div",{className:"not-all-stars-collected",children:r.continueMessage})]})},gt=(e,t)=>{const n=D({canvasWidth:0,canvasHeight:0});return I(()=>{const o=()=>{const s=e.current;if(!s)return;const a=s.parentElement;if(!a)return;const r=a.clientWidth;if(r===0)return;const c=window.devicePixelRatio||1;s.style.width=`${r}px`,s.style.height=`${r}px`;const l=r*c,d=r*c;s.width=l,s.height=d,n.current={canvasWidth:l,canvasHeight:d},t?.()};o();let i=null;return window.ResizeObserver&&e.current&&(i=new ResizeObserver(o),i.observe(e.current.parentElement)),window.addEventListener("resize",o),()=>{window.removeEventListener("resize",o),i?.disconnect()}},[e,t]),n},pt=(e,t,n)=>{const o=D({cellWidth:0,cellHeight:0});return I(()=>{const i=()=>{const a=e.current,r=t.maze;if(!a||!r)return;const{rows:c,cols:l}=r;if(c<=0||l<=0)return;const d=(a.width-n*2)/l,u=(a.height-n*2)/c;o.current={cellWidth:d,cellHeight:u}};i();let s=null;return e.current&&window.ResizeObserver&&(s=new ResizeObserver(i),s.observe(e.current)),()=>{e.current&&s?.disconnect()}},[e,t.maze,n]),o},ge={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]},wt=({gamePlayStateRef:e,setGamePlayState:t,moveSpeed:n,moveSpeedRef:o,playerRadius:i,onFoodCollected:s,onExitReached:a,onFirstMove:r})=>{const c=()=>o?.current??n??.03,l=D(!1),d=D(new Set),u=D(!1),h=rt((T,p)=>{const z=e.current;if(!z.maze)return{canMove:!1,newCell:null};const C=c(),[S,k]=ge[T];if(Ct(p,S,k,i,C,z.maze))return{canMove:!1,newCell:null};const{row:E,col:M}=p,b=E+S*C,A=M+k*C,P=-.5,R=z.maze.rows,$=z.maze.cols;if(b<P||b>=R||A<P||A>=$)return{canMove:!1,newCell:null};const G=E<0?0:Math.floor(E),Y=M<0?0:Math.floor(M),V=b<0?0:Math.floor(b),te=A<0?0:Math.floor(A);return V!==G||te!==Y?z.maze.isValid(V,te)?{canMove:!0,newCell:{row:V,col:te}}:{canMove:!1,newCell:null}:{canMove:!0,newCell:null}},[i,c]),f=()=>{const T=e.current,{row:p,col:z}=T.playerCell,C=i*2,S=T.foodCells.findIndex(E=>Math.sqrt(Math.pow(p-E.row,2)+Math.pow(z-E.col,2))<C);S!==-1&&s&&(s(),e.current={...e.current,foodCollected:e.current.foodCollected+1,foodCells:e.current.foodCells.filter((E,M)=>M!==S)});const L=pn(T.playerCell,T.exitCell,T.maze);L&&!e.current.playerAtExit?(e.current={...e.current,playerAtExit:!0,isGameActive:!1,levelTransitioning:!0},a&&a(),requestIdleCallback(()=>{t(()=>({...e.current}))},{timeout:10})):!L&&e.current.playerAtExit&&(e.current={...e.current,playerAtExit:!1,isGameActive:!0,levelTransitioning:!1})},m=T=>{const p=e.current,z=Math.round(T.row),C=Math.round(T.col),S=p.playerPath[p.playerPath.length-1],k=S.row===z&&S.col===C,L=Math.abs(S.row-z),E=Math.abs(S.col-C);if((L===1&&E===0||L===0&&E===1)&&!k){const b=`${S.row},${S.col}-${z},${C}`;e.current={...e.current,playerPath:[...e.current.playerPath,{row:z,col:C}],visitCounts:{...e.current.visitCounts,[b]:(e.current.visitCounts[b]||0)+1}}}},g=()=>{if(l.current||d.current.size===0)return;const T=e.current;!T.playerCell||!Array.from(d.current).some(z=>{const{canMove:C}=h(z,T.playerCell);return C})||(!u.current&&r&&(u.current=!0,r()),l.current=!0)};I(()=>{const T=C=>{if(C.key==="ArrowUp"||C.key==="ArrowDown"||C.key==="ArrowLeft"||C.key==="ArrowRight"||C.key===" "){const S=document.activeElement;if(S&&(S.tagName==="INPUT"||S.tagName==="TEXTAREA"||S.getAttribute("contenteditable")==="true"))return;C.preventDefault()}},p=C=>{const S=C.key;if(!(S in ge))return;const k=document.activeElement;k&&(k.tagName==="INPUT"||k.tagName==="TEXTAREA"||k.getAttribute("contenteditable")==="true")||(C.preventDefault(),e.current.isGameActive&&(d.current.has(S)||(d.current.add(S),l.current||g())))},z=C=>{const S=C.key;if(!(S in ge))return;const k=document.activeElement;k&&(k.tagName==="INPUT"||k.tagName==="TEXTAREA"||k.getAttribute("contenteditable")==="true")||(C.preventDefault(),d.current.delete(S),d.current.size===0&&w())};return window.addEventListener("keydown",T,{capture:!0}),window.addEventListener("keydown",p),window.addEventListener("keyup",z),()=>{window.removeEventListener("keydown",T,{capture:!0}),window.removeEventListener("keydown",p),window.removeEventListener("keyup",z)}},[]);const v=rt(()=>{if(!l.current||d.current.size===0)return e.current.playerCell;const T=c(),p=e.current.playerCell;let z=0,C=0,S=0;for(const K of d.current){const{canMove:F}=h(K,p);if(F){const[q,ae]=ge[K];z+=q,C+=ae,S++}}if(S===0)return e.current.playerCell;const k=Math.sqrt(z*z+C*C),L=k>0?z/k:0,E=k>0?C/k:0,M=Number((p.row+L*T).toFixed(2)),b=Number((p.col+E*T).toFixed(2)),A=M-p.row,P=b-p.col,R=Math.sqrt(A*A+P*P);if(R>0){const K=A/R,F=P/R;if(Ct(p,K,F,i,R,e.current.maze))return e.current.playerCell}e.current.playerCell={row:M,col:b},f();const $=p.row<0?0:Math.round(p.row),G=p.col<0?0:Math.round(p.col),Y=M<0?0:Math.round(M),V=b<0?0:Math.round(b);return(Y!==$||V!==G)&&m({row:Y,col:V}),e.current.playerCell},[c,h]),w=()=>{l.current=!1,d.current.clear()};return{updatePlayerPos:v,resetMovingState:w,resetFirstMoveState:()=>{u.current=!1}}};function Ct(e,t,n,o,i,s){const a=e.row+t*i,r=e.col+n*i,c={row:a,col:r},l=[],d=e.row<0?0:Math.floor(e.row),u=e.col<0?0:Math.floor(e.col);l.push({row:d,col:u});const h=[[-1,0],[1,0],[0,-1],[0,1],[-1,-1],[-1,1],[1,-1],[1,1]];for(const[f,m]of h){const g=d+f,v=u+m;s.isValid(g,v)&&l.push({row:g,col:v})}for(const f of l){const m=vn(f.row,f.col,s);for(const g of m)if(gn(c,g)<o)return!0}return!1}function vn(e,t,n){const o=[],i=n.grid[e][t];return i.walls.top&&o.push({start:{row:e-.5,col:t-.5},end:{row:e-.5,col:t+.5}}),i.walls.right&&o.push({start:{row:e-.5,col:t+.5},end:{row:e+.5,col:t+.5}}),i.walls.bottom&&o.push({start:{row:e+.5,col:t-.5},end:{row:e+.5,col:t+.5}}),i.walls.left&&o.push({start:{row:e-.5,col:t-.5},end:{row:e+.5,col:t-.5}}),o}function gn(e,t){const{start:n,end:o}=t,i=o.col-n.col,s=o.row-n.row,a=e.col-n.col,r=e.row-n.row,c=i*i+s*s;if(c===0)return Math.sqrt(a*a+r*r);const l=Math.max(0,Math.min(1,(a*i+r*s)/c)),d=n.col+l*i,u=n.row+l*s,h=e.col-d,f=e.row-u;return Math.sqrt(h*h+f*f)}function pn(e,t,n){if(!n.isValid(t.row,t.col))return!1;const o=e.col>=t.col-.5&&e.col<=t.col+.5,i=e.row>=t.row+.5,s=e.row>=t.row-.5;return o&&i&&s}function ee(e,t,n,o,i){return{x:i+t*n+n/2,y:i+e*o+o/2}}function wn(e,t,n,o,i,s){e.save(),e.beginPath();for(let a=0;a<i*2;a++){const r=a%2===0?o:s,c=Math.PI*a/i;e.lineTo(t+r*Math.sin(c),n+r*Math.cos(c))}e.closePath(),e.fill(),e.restore()}function Cn({ctx:e,canvasWidth:t,canvasHeight:n,cellWidth:o,cellHeight:i,padding:s,playerCell:a,walls:r,fogRadius:c,fogColor:l,fogSoftness:d}){const u=Math.max(c,0)*Math.max(o,i)||0;if(u<=0)return;const h=ee(a.row,a.col,o,i,s),f=yn(h,r,u);e.save(),e.fillStyle=l,e.fillRect(0,0,t,n),e.globalCompositeOperation="destination-out";const m=Math.max(Math.min(o,i)*.25,2);e.filter=`blur(${m}px)`;const g=Math.max(Math.min(d,1),0),v=e.createRadialGradient(h.x,h.y,Math.max(u*.2,6),h.x,h.y,u);v.addColorStop(0,"rgba(0, 0, 0, 1)"),v.addColorStop(Math.max(.25,g-.1),"rgba(0, 0, 0, 1)"),v.addColorStop(1,"rgba(0, 0, 0, 0)"),e.fillStyle=v,f.length>=3?(e.beginPath(),f.forEach((w,y)=>{y===0?e.moveTo(w.x,w.y):e.lineTo(w.x,w.y)}),e.closePath(),e.fill()):(e.beginPath(),e.arc(h.x,h.y,u,0,Math.PI*2),e.fill()),e.restore()}function yn(e,t,n){const i=[];if(t.forEach(a=>{i.push(Math.atan2(a.y1-e.y,a.x1-e.x)-1e-4,Math.atan2(a.y1-e.y,a.x1-e.x),Math.atan2(a.y1-e.y,a.x1-e.x)+1e-4,Math.atan2(a.y2-e.y,a.x2-e.x)-1e-4,Math.atan2(a.y2-e.y,a.x2-e.x),Math.atan2(a.y2-e.y,a.x2-e.x)+1e-4)}),i.length===0)for(let a=0;a<24;a++)i.push(a/24*Math.PI*2);return Array.from(new Set(i)).sort((a,r)=>a-r).map(a=>bn(e,a,t,n))}function bn(e,t,n,o){const i={x:Math.cos(t),y:Math.sin(t)};let s={x:e.x+i.x*o,y:e.y+i.y*o,distance:o};for(const a of n){const r=Tn(e,i,{x:a.x1,y:a.y1},{x:a.x2,y:a.y2},o);r&&r.distance<s.distance&&(s=r)}return{x:s.x,y:s.y}}function Tn(e,t,n,o,i){const s={x:o.x-n.x,y:o.y-n.y},a=t.x*s.y-t.y*s.x;if(Math.abs(a)<1e-6)return null;const r={x:n.x-e.x,y:n.y-e.y},c=(r.x*s.y-r.y*s.x)/a,l=(r.x*t.y-r.y*t.x)/a;return c<0||l<0||l>1||c>i?null:{x:e.x+t.x*c,y:e.y+t.y*c,distance:c}}function yt(e,t,n,o){const i=[];for(let s=0;s<e.rows;s++)for(let a=0;a<e.cols;a++){const r=e.grid[s][a],c=o+a*t,l=o+s*n;r.walls.top&&i.push({x1:c,y1:l,x2:c+t,y2:l}),r.walls.right&&i.push({x1:c+t,y1:l,x2:c+t,y2:l+n}),r.walls.bottom&&i.push({x1:c,y1:l+n,x2:c+t,y2:l+n}),r.walls.left&&i.push({x1:c,y1:l,x2:c,y2:l+n})}return i}function Sn({ctx:e,maze:t,cellWidth:n,cellHeight:o,padding:i,wallColor:s,wallWidth:a,walls:r}){e.save(),e.strokeStyle=s,e.lineWidth=a,e.lineCap="round",e.beginPath(),(r??yt(t,n,o,i)).forEach(l=>{e.moveTo(l.x1,l.y1),e.lineTo(l.x2,l.y2)}),e.stroke(),e.restore()}function kn({ctx:e,playerCell:t,playerRadius:n,cellWidth:o,cellHeight:i,padding:s,playerColor:a}){const{x:r,y:c}=ee(t.row,t.col,o,i,s),l=Math.min(o,i)*Math.min(n,.5);e.save(),e.fillStyle=a,e.beginPath(),e.arc(r,c,l,0,Math.PI*2),e.fill(),e.restore()}function En({ctx:e,maze:t,exitCell:n,cellWidth:o,cellHeight:i,padding:s,exitColor:a,exitWallWidth:r,exitDashArray:c=[8,12]}){const{row:l,col:d}=n;if(!t.isValid(l,d))return;const u=s+d*o,h=s+l*i;e.save(),e.globalCompositeOperation="destination-out",e.lineWidth=r,e.lineCap="round",e.beginPath(),e.moveTo(u,h+i),e.lineTo(u+o,h+i),e.stroke(),e.globalCompositeOperation="source-over",e.strokeStyle=a,e.lineWidth=r,e.setLineDash(c),e.beginPath(),e.moveTo(u,h+i),e.lineTo(u+o,h+i),e.stroke(),e.restore()}function zn({ctx:e,foodCells:t,cellWidth:n,cellHeight:o,padding:i,foodColor:s}){e.fillStyle=s,e.shadowColor="rgba(255, 215, 64, 0.9)",e.shadowBlur=Math.max(Math.min(n,o)*.28,3);const a=Math.min(n,o)*.25;t.forEach(r=>{const{x:c,y:l}=ee(r.row,r.col,n,o,i);wn(e,c,l,a*1.25,5,a*.62)}),e.shadowBlur=0,e.strokeStyle="rgba(255,255,255,0.5)",e.lineWidth=Math.max(a*.3,1),t.forEach(r=>{const{x:c,y:l}=ee(r.row,r.col,n,o,i);e.beginPath(),e.arc(c,l,a*1.05,0,Math.PI*2),e.stroke()})}function Mn({ctx:e,playerPath:t,visitCounts:n,cellWidth:o,cellHeight:i,padding:s,clueColor:a}){if(!(!t||t.length<2||!n)){e.save();for(let r=1;r<t.length;r++){const c=t[r-1],l=t[r],d=`${c.row},${c.col}-${l.row},${l.col}`,u=`${l.row},${l.col}-${c.row},${c.col}`,h=(n[d]||0)+(n[u]||0),f=Math.min(.2+h*.1,.9),m=Math.max(3,o*.1)+h*.5;try{e.strokeStyle=a.replace(")",`, ${f})`).replace("rgb(","rgba(")}catch{e.strokeStyle=`rgba(255, 0, 0, ${f})`}e.lineWidth=m,e.lineCap="round",e.lineJoin="round";const{x:g,y:v}=ee(c.row,c.col,o,i,s),{x:w,y}=ee(l.row,l.col,o,i,s);e.beginPath(),e.moveTo(g,v),e.lineTo(w,y),e.stroke()}e.restore()}}function bt(e,t,n,o,i){if(!e||!t.maze)return;const{canvasWidth:s,canvasHeight:a}=n,{cellWidth:r,cellHeight:c}=o,{maze:l,playerCell:d,exitCell:u,foodCells:h,showClue:f,playerPath:m,visitCounts:g}=t,{padding:v,wallWidth:w,wallColor:y,playerColor:T,playerRadius:p,foodColor:z,backgroundColor:C,clueColor:S,fogEnabled:k,fogRadius:L,fogColor:E,fogSoftness:M,exitColor:b,exitWallWidth:A,exitDashArray:P}=i;e.clearRect(0,0,s,a),e.save(),e.fillStyle=C,e.fillRect(0,0,s,a),e.restore(),f&&Mn({ctx:e,playerPath:m,visitCounts:g,cellWidth:r,cellHeight:c,padding:v,clueColor:S});const R=yt(l,r,c,v);k&&Cn({ctx:e,canvasWidth:s,canvasHeight:a,cellWidth:r,cellHeight:c,padding:v,playerCell:d,walls:R,fogRadius:L,fogColor:E,fogSoftness:M}),Sn({ctx:e,maze:l,cellWidth:r,cellHeight:c,padding:v,wallColor:y,wallWidth:w,walls:R}),En({ctx:e,maze:l,exitCell:u,cellWidth:r,cellHeight:c,padding:v,exitColor:b,exitWallWidth:A,exitDashArray:P}),kn({ctx:e,playerCell:d,playerRadius:p,cellWidth:r,cellHeight:c,padding:v,playerColor:T}),zn({ctx:e,foodCells:h,cellWidth:r,cellHeight:c,padding:v,foodColor:z})}function Ln(e){return function(){let t=e+=1831565813;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}}class Nn{constructor(t,n){this.row=t,this.col=n}visited=!1;walls={top:!0,right:!0,bottom:!0,left:!0}}class Tt{rows;cols;grid;seed;random;constructor(t,n,o,i,s={row:0,col:0},a={row:t-1,col:n-1}){this.rows=t,this.cols=n,this.seed=i??Math.floor(Math.random()*1e6),this.random=Ln(this.seed),this.grid=this.initializeGrid(),this.generate(o,s,a)}initializeGrid(){const t=[];for(let n=0;n<this.rows;n++){t[n]=[];for(let o=0;o<this.cols;o++)t[n][o]=new Nn(n,o)}return t}isValid(t,n){return t>=0&&t<this.rows&&n>=0&&n<this.cols}getNeighbors(t,n){const o=[],i=[{r:-1,c:0},{r:0,c:1},{r:1,c:0},{r:0,c:-1}];for(const s of i){const a=t+s.r,r=n+s.c;this.isValid(a,r)&&o.push({row:a,col:r})}return o}getUnvisitedNeighbors(t,n){return this.getNeighbors(t,n).filter(o=>!this.grid[o.row][o.col].visited)}getVisitedNeighbors(t,n){return this.getNeighbors(t,n).filter(o=>this.grid[o.row][o.col].visited)}removeWall(t,n,o,i){const s=this.grid[t][n],a=this.grid[o][i];t===o+1?(s.walls.top=!1,a.walls.bottom=!1):t===o-1?(s.walls.bottom=!1,a.walls.top=!1):n===i+1?(s.walls.left=!1,a.walls.right=!1):n===i-1&&(s.walls.right=!1,a.walls.left=!1)}generate(t,n={row:0,col:0},o={row:this.rows-1,col:this.cols-1}){switch(t){case"backtracking":this.generateWithBacktracking();break;case"prims":this.generateWithPrims();break;default:throw new Error(`Unknown maze generation method: ${t}`)}this.addOpenings(n,o)}generateWithBacktracking(){const t=[],n=this.randomNumber(this.rows),o=this.randomNumber(this.cols);let i={row:n,col:o};for(this.grid[n][o].visited=!0,t.push(i);t.length>0;){i=t[t.length-1];const{row:s,col:a}=i,r=this.getUnvisitedNeighbors(s,a);if(r.length>0){const c=this.randomPick(r),{row:l,col:d}=c;this.removeWall(s,a,l,d),this.grid[l][d].visited=!0,t.push(c)}else t.pop()}}generateWithPrims(){const t=[],n=(s,a)=>{const r=this.getNeighbors(s,a);for(const c of r)!this.grid[c.row][c.col].visited&&!t.some(l=>l.row===c.row&&l.col===c.col)&&t.push(c)},o=this.randomNumber(this.rows),i=this.randomNumber(this.cols);for(this.grid[o][i].visited=!0,n(o,i);t.length>0;){const s=this.randomNumber(t.length),a=t[s],{row:r,col:c}=a,l=this.getVisitedNeighbors(r,c);if(l.length>0){const d=this.randomPick(l);this.removeWall(r,c,d.row,d.col),this.grid[r][c].visited=!0,n(r,c)}t.splice(s,1)}}addOpenings(t,n){this.grid[t.row][t.col].walls.top=!1,this.isValid(n.row,n.col)&&(this.grid[n.row][n.col].walls.bottom=!1)}randomNumber(t){return Math.floor(this.random()*t)}randomPick(t){return t[Math.floor(this.random()*t.length)]}}const St=(e,t,n)=>{if(!e.isValid(t,n))return!1;const o=e.grid[t][n];return!o.walls.top||!o.walls.right||!o.walls.bottom||!o.walls.left},An=e=>e===1?2:e>=2&&e<=5?3:e>=6&&e<=11?4:e>=12&&e<=15?5:6,Pn=(e,t)=>{if(!t)return console.error(`Cannot find Level ${e}'s config.`),null;const{size:n,seed:o,method:i,entry:s,exit:a}=t,r=n,c=n,l=s||{row:0,col:0},d=a||{row:r-1,col:c-1},u=new Tt(r,c,i,o,l,d),h=An(e),f=[];for(let m=0;m<h;m++){let g;do g={row:Math.floor(u.random()*r),col:Math.floor(u.random()*c)};while(g.row===l.row&&g.col===l.col||g.row===d.row&&g.col===d.col||!St(u,g.row,g.col)||f.some(v=>v.row===g.row&&v.col===g.col));f.push(g)}return{isGameActive:!0,levelTransitioning:!1,maze:u,playerCell:l,exitCell:d,foodCells:f,playerAtExit:!1,foodCollected:0,totalFoodCount:h,showClue:!1,playerPath:[l],visitCounts:{[`${l.row},${l.col}`]:1}}},xn=({size:e,seed:t,method:n,foodCount:o,foodRace:i,clue:s,fogEnabled:a=!0})=>{const r=e,c=e,l={row:0,col:0},d={row:r-1,col:c-1},u=new Tt(r,c,n,t,l,d),h=[];if(i)for(let f=0;f<o;f++){let m,g=0;do m={row:Math.floor(u.random()*r),col:Math.floor(u.random()*c)},g++;while(g<50&&(m.row===l.row&&m.col===l.col||m.row===d.row&&m.col===d.col||!St(u,m.row,m.col)||h.some(v=>v.row===m.row&&v.col===m.col)));g<50&&h.push(m)}return{isGameActive:!0,levelTransitioning:!1,maze:u,playerCell:l,exitCell:d,foodCells:h,playerAtExit:!1,foodCollected:0,totalFoodCount:i?o:0,fogEnabled:a,showClue:s,playerPath:[l],visitCounts:{[`${l.row},${l.col}`]:1}}};function In(){const{setGamePlayState:e,gamePlayState:t,gamePlayStateRef:n,gameProgress:o,config:i}=re(),s=D(null),a=D(null),{i18n:r,levelConfig:c,renderConfig:l}=i,d=ie(c),u=D(d.getLevelConfig(o.currentLevel));I(()=>{s.current&&j.attachTo(s.current)},[]);const h=D(),f=gt(a,()=>{h.current?.()}),m=pt(a,t,l.padding);I(()=>{u.current=d.getLevelConfig(o.currentLevel)},[o.currentLevel]);const g=()=>{const T=Pn(o.currentLevel,u.current);T&&e(p=>({...p,...T}))};I(()=>{g()},[o.currentLevel]);const v=()=>{g()},{updatePlayerPos:w,resetMovingState:y}=wt({gamePlayStateRef:n,setGamePlayState:e,playerRadius:l.playerRadius,moveSpeed:l.gridMoveSpeed,onFoodCollected:()=>{const T=n.current.totalFoodCount-n.current.foodCollected-1;T>0?j.show(r.foodCollectedToast.replace("%NUM%",T.toString()),3e3):j.show(r.allFoodCollectedToast)}});return I(()=>{y()},[o.currentLevel,y]),I(()=>{let T,p=!document.hidden;const z=()=>{const k=a.current?.getContext("2d"),L=n.current;if(!(p&&L?.isGameActive&&k&&L?.maze)){T=requestAnimationFrame(z);return}w(),C(),T=requestAnimationFrame(z)},C=()=>{const k=a.current?.getContext("2d"),L=n.current;if(k&&L?.maze){const E=u.current?.wallWidth||l?.wallWidth,M=u.current?.exitColor||l?.exitColor,b=u.current?.exitWallWidth||l?.exitWallWidth,A=u.current?.exitDashArray||l?.exitDashArray,P=u.current?.fogRadius||l?.fogRadius,R=u.current?.fogEnabled??l?.fogEnabled;bt(k,L,f.current,m.current,{...l,wallWidth:E,exitColor:M,exitWallWidth:b,exitDashArray:A,fogRadius:P,fogEnabled:R})}};h.current=C;const S=k=>{const L=p;p=!document.hidden&&document.visibilityState==="visible"&&(!k||k.type!=="blur"),!L&&p?n.current?.levelTransitioning===!1&&e({...n.current,isGameActive:!0}):L&&!p&&e({...n.current,isGameActive:!1})};return document.addEventListener("visibilitychange",S),window.addEventListener("blur",S),window.addEventListener("focus",S),T=requestAnimationFrame(z),()=>{cancelAnimationFrame(T),document.removeEventListener("visibilitychange",S),window.removeEventListener("blur",S),window.removeEventListener("focus",S)}},[]),I(()=>{j.show(r.useArrowKeyTips,3e3)},[]),_("div",{className:"maze-game-container",children:[_(qt,{}),_(_n,{onRetry:v}),_("div",{className:"maze-canvas-container",ref:s,children:_("canvas",{ref:a,className:"maze-game-canvas"})})]})}const Rn=e=>{const t=Math.floor(e/60),n=e%60;return`${t.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`},Fn=({timer:e})=>{const[t,n]=U(e),o=D(),i=D(!1),s=D(0);return I(()=>{const a=()=>{!i.current&&!o.current&&(i.current=!0,o.current=setInterval(()=>{n(c=>(s.current=e-c+1,c<=1?(clearInterval(o.current),window.dispatchEvent(new CustomEvent("maze:timeUp")),0):c-1))},1e3))},r=()=>{clearInterval(o.current),o.current=void 0,window.dispatchEvent(new CustomEvent("maze:timeUsed",{detail:{timeUsed:s.current}}))};return window.addEventListener("maze:firstMove",a),window.addEventListener("maze:gameSuccess",r),()=>{window.removeEventListener("maze:firstMove",a),window.removeEventListener("maze:gameSuccess",r),clearInterval(o.current)}},[e]),I(()=>{o.current&&(clearInterval(o.current),o.current=void 0),n(e),i.current=!1,s.current=0},[e]),_("div",{className:"single-maze-timer",children:_("span",{className:`maze-timer-text ${t<=10&&i.current?"maze-timer-warning":""}`,children:["⏱️ ",Rn(t)]})})};function Dn({config:e}){const{size:t,seed:n,method:o,foodCount:i,foodRace:s,clue:a,renderConfig:r,successCallback:c,failCallback:l,timer:d,i18n:u}=e,h=r.fogEnabled??!0,[f,m]=U({...ut,fogEnabled:h}),[g,v]=U(!1),[w,y]=U(!0),[T,p]=U(!1),[z,C]=U(""),S=D(0),k=D(!1),L=D(!1),E=D(null),M=D(null),b=D(f),A=D(),P=gt(E,()=>{A.current?.()}),R=pt(E,f,r.padding);I(()=>{b.current=f},[f]);const{updatePlayerPos:$,resetMovingState:G,resetFirstMoveState:Y}=wt({gamePlayStateRef:b,setGamePlayState:m,playerRadius:r.playerRadius,moveSpeed:r.gridMoveSpeed,onFoodCollected:()=>{console.log("Food collected in single maze")},onExitReached:()=>{if(!k.current){if(s&&b.current.foodCollected<b.current.totalFoodCount){C(`⭐️ ${u.foodMsg}`),p(!0),m(F=>({...F,isGameActive:!1}));return}m(F=>({...F,isGameActive:!1})),te()}},onFirstMove:()=>{window.dispatchEvent(new CustomEvent("maze:firstMove"))}}),V=()=>{k.current=!0,C(`⏰ ${u.failMsg}`),p(!0),m({...b.current,isGameActive:!1})},te=()=>{k.current=!0,L.current=!0,C(`🎉 ${u.successMsg}`),p(!0),m(F=>({...F,isGameActive:!1})),window.dispatchEvent(new CustomEvent("maze:gameSuccess"))},K=()=>{if(p(!1),!k.current){m(F=>({...F,isGameActive:!0}));return}y(!1),m(F=>({...F,showClue:!0})),L.current?c?.(S.current):l?.()};return I(()=>{(async()=>{v(!0);try{const q=xn({size:t,seed:n,method:o,foodCount:i,foodRace:s,clue:a,fogEnabled:b.current.fogEnabled??h});b.current=q,m(q)}catch(q){console.error("Error generating single maze:",q)}finally{v(!1)}})()},[e,h]),I(()=>{let F;const q=!document.hidden,ae=()=>{const Ce=E.current?.getContext("2d"),le=b.current;if(!(q&&le?.isGameActive&&Ce&&le?.maze)){F=requestAnimationFrame(ae);return}$(),zt(),F=requestAnimationFrame(ae)},zt=()=>{const Ce=E.current?.getContext("2d"),le=b.current;Ce&&le?.maze&&bt(Ce,le,P.current,R.current,r)};return A.current=zt,F=requestAnimationFrame(ae),()=>{cancelAnimationFrame(F)}},[]),I(()=>{G(),Y()},[e,G,Y]),I(()=>{const F=q=>{S.current=q.detail.timeUsed};return window.addEventListener("maze:timeUsed",F),window.addEventListener("maze:timeUp",V),()=>{window.removeEventListener("maze:timeUsed",F),window.removeEventListener("maze:timeUp",V)}},[]),g?_("div",{className:"single-maze-loading",children:_("div",{children:"Generating maze..."})}):f?_("div",{className:"maze-game-container",children:[_("div",{className:"single-maze-toolbar",children:w&&_(Fn,{timer:d})}),_("div",{className:"single-maze-canvas-container",ref:M,children:_("canvas",{ref:E,className:"maze-game-canvas"})}),_(se,{isOpen:T,title:z,noConfirm:!0,cancelText:"OK",onCancel:K})]}):_("div",{className:"single-maze-error",children:_("div",{children:"Failed to generate maze"})})}const kt=[[{size:8,seed:12345,method:"backtracking",wallWidth:4,exitWallWidth:6,exitDashArray:[8,12]},{size:8,seed:23456,fogEnabled:!0,method:"backtracking",exitColor:"#33f",exitWallWidth:4,exitDashArray:[8,16]},{size:8,seed:34567,method:"prims"},{size:8,seed:45678,method:"backtracking"},{size:9,seed:56789,method:"prims"},{size:9,seed:67890,method:"backtracking"},{size:9,seed:78901,method:"prims"},{size:9,seed:89012,method:"backtracking"},{size:10,seed:90123,method:"prims"},{size:11,seed:11111,method:"backtracking"},{size:12,seed:22222,method:"prims"},{size:13,seed:33333,method:"backtracking"}],[{size:12,seed:44444,method:"prims"},{size:12,seed:55555,method:"backtracking"},{size:12,seed:66666,method:"prims"},{size:12,seed:77777,method:"backtracking"},{size:13,seed:88888,method:"prims"},{size:13,seed:99999,method:"backtracking"},{size:13,seed:12121,method:"prims"},{size:14,seed:23232,method:"backtracking"},{size:15,seed:34343,method:"prims"},{size:16,seed:45454,method:"backtracking"},{size:17,seed:56565,method:"prims"},{size:18,seed:67676,method:"backtracking"}],[{size:19,seed:78787,method:"prims"},{size:20,seed:89898,method:"backtracking"},{size:21,seed:90909,method:"prims"},{size:22,seed:10101,method:"backtracking"},{size:23,seed:20202,method:"prims"},{size:25,seed:30303,method:"backtracking"},{size:27,seed:40404,method:"prims"},{size:29,seed:50505,method:"backtracking"},{size:31,seed:60606,method:"prims"},{size:33,seed:70707,method:"backtracking"},{size:37,seed:80808,method:"prims"},{size:40,seed:90909,method:"backtracking"}],[{size:41,seed:10111,method:"prims"},{size:42,seed:11121,method:"backtracking"},{size:43,seed:12131,method:"prims"},{size:44,seed:13141,method:"backtracking"},{size:45,seed:14151,method:"prims"},{size:46,seed:15161,method:"backtracking"},{size:47,seed:16171,method:"prims"},{size:48,seed:17181,method:"backtracking"},{size:49,seed:18191,method:"prims"},{size:50,seed:19201,method:"backtracking"},{size:51,seed:20211,method:"prims"},{size:52,seed:21221,method:"backtracking"}],[{size:53,seed:22231,method:"prims"},{size:54,seed:23241,method:"backtracking"},{size:55,seed:24251,method:"prims"},{size:56,seed:25261,method:"backtracking"},{size:57,seed:26271,method:"prims"},{size:58,seed:27281,method:"backtracking"},{size:59,seed:28291,method:"prims"},{size:60,seed:29301,method:"backtracking"},{size:62,seed:30311,method:"prims"},{size:64,seed:31321,method:"backtracking"},{size:66,seed:32331,method:"prims"},{size:68,seed:33341,method:"backtracking"}]],Et={gridMoveSpeed:.07,padding:10,wallWidth:2,wallColor:"#222",foodColor:"#FFD54F",clueColor:"rgb(255,0,0)",backgroundColor:"#ffffff",playerColor:"#4CAF50",playerRadius:.2,fogEnabled:!1,fogRadius:3.6,fogColor:"rgba(8, 10, 18, 0.9)",fogSoftness:.55,exitColor:"#F44336",exitWallWidth:4,exitDashArray:[8,12]},pe={lcPrefix:"maze-",i18n:{reset:"Reset",resetTip:"Reset all game data and highest score.",confirmReset:"Confirm Reset",confirmResetMessage:"Are you sure you want to reset the game? All progress will be lost.",cancel:"Cancel",close:"Close",confirm:"Confirm",resetDoneToast:"Game reset! Starting from Level 1...",confirmClue:"Confirm to turn on clue?",confirmClueMessage:"Are you sure you want to turn on clue? Your will lose 1 ★.",level:"Level",tier:"Tier",settings:"Settings",clueOn:"Clue: ON",clueOff:"Clue: OFF",foodCollectedToast:"Food collected! %NUM% remaining.",allFoodCollectedToast:"All food collected! Head to the exit.",congratulations:"Congratulations!",findYourExit:"Find your exit!",withoutClue:"Without clue!",withClue:"You used the clue!",collectAllStars:"Collect all stars!",notCollectAllStars:"Not collect all stars.",nextLevel:"Next Level ➤",spacebarTip:"Spacebar",retry:"Retry",levelComplete:"Level Complete",starsCollected:"Stars Collected",avgStarPerLevel:"Avg. Stars per Level",levelCompleteToast:"Level completed! 🎉",tierUnlockedToast:"Tier %TIER% unlocked! 🎉",levelGoToast:"Level %LEVEL% - Go!",levelRestartToast:"Level restarted",allLevelsCompleted:"You completed all levels!",lastOK:"OK",notCompleteLevel:"You still have levels not collected all stars! Try again to collect them all!",continueMessage:"You still have levels where you haven't collected all stars. Try again to collect them all!",continue:"Continue",cluePathEnabled:"Clue Path Enabled",cluePathDisabled:"Clue Path Disabled",useArrowKeyTips:"Use arrow keys to navigate the maze. Press'C' to toggle path clue.",fogOn:"Fog: ON",fogOff:"Fog: OFF",fogEnabledToast:"Fog enabled",fogDisabledToast:"Fog disabled"},renderConfig:Et,levelConfig:kt},we={i18n:{successMsg:"Congratulations! You completed the maze!",failMsg:"Time is up!",foodMsg:"Please collect all stars before leaving!",fogOn:"Fog: ON",fogOff:"Fog: OFF"},size:8,seed:12345,method:"backtracking",clue:!1,foodCount:0,foodRace:!1,renderConfig:Et,timer:600,successCallback:()=>{console.log("🎉 Single maze completed successfully!")},failCallback:()=>{console.log("⏰ Time is up! Game failed.")}};function On({config:e={}}){const t={...pe.i18n,...e.i18n||{}},n={...pe.renderConfig,...e.renderConfig||{}},o=e.levelConfig||kt,i={...pe,...e,i18n:t,levelConfig:o,renderConfig:n};return _(Gt,{config:i,children:_(In,{})})}function $n({config:e={}}){const t={...we.i18n,...e.i18n||{}},n={...we.renderConfig,...e.renderConfig||{}},o={...we,...e,i18n:t,renderConfig:n};return _(Dn,{config:o})}const Un={root:"https://unpkg.com/@roudanio/maze@0.3.2/dist/",...pe};`${JSON.stringify(Un,null,2)}`;const Gn={root:"https://unpkg.com/@roudanio/maze@0.3.2/dist/",...we};return`${JSON.stringify(Gn,(e,t)=>typeof t=="function"?t.toString():t,2)}`,{showNotice(){console.warn("Cannot find the root element");const e=document.createElement("div");e.style.textAlign="center",e.style.padding="20px",e.innerHTML="Cannot find the root element",document.body.append(e)},addLoadingIndicator(e){const t=document.createElement("div"),n=document.createElement("div");t.style.cssText=`
|
|
2
2
|
height: 30px;
|
|
3
3
|
width: 100%;
|
|
4
4
|
border: solid 2px #999;
|