@roudanio/maze 0.2.4 → 0.2.5

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/dist/maze.iife.js CHANGED
@@ -1,4 +1,4 @@
1
- var Maze=function(){"use strict";var se,M,xe,V,Re,Fe,De,Oe,ye,be,Te,$e,ee={},Ue=[],Tt=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,le=Array.isArray;function H(e,t){for(var n in t)e[n]=t[n];return e}function ke(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function kt(e,t,n){var o,i,s,l={};for(s in t)s=="key"?o=t[s]:s=="ref"?i=t[s]:l[s]=t[s];if(arguments.length>2&&(l.children=arguments.length>3?se.call(arguments,2):n),typeof e=="function"&&e.defaultProps!=null)for(s in e.defaultProps)l[s]==null&&(l[s]=e.defaultProps[s]);return ae(e,l,o,i,null)}function ae(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??++xe,__i:-1,__u:0};return i==null&&M.vnode!=null&&M.vnode(s),s}function ce(e){return e.children}function ue(e,t){this.props=e,this.context=t}function Y(e,t){if(t==null)return e.__?Y(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"?Y(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 Se(e){(!e.__d&&(e.__d=!0)&&V.push(e)&&!de.__r++||Re!=M.debounceRendering)&&((Re=M.debounceRendering)||Fe)(de)}function de(){for(var e,t,n,o,i,s,l,r=1;V.length;)V.length>r&&V.sort(De),e=V.shift(),r=V.length,e.__d&&(n=void 0,i=(o=(t=e).__v).__e,s=[],l=[],t.__P&&((n=H({},o)).__v=o.__v+1,M.vnode&&M.vnode(n),ze(t.__P,n,o,t.__n,t.__P.namespaceURI,32&o.__u?[i]:null,s,i??Y(o),!!(32&o.__u),l),n.__v=o.__v,n.__.__k[n.__i]=n,Be(s,n,l),n.__e!=i&&Ge(n)));de.__r=0}function We(e,t,n,o,i,s,l,r,a,c,d){var u,h,f,g,_,v,T=o&&o.__k||Ue,b=t.length;for(a=St(n,t,T,a,b),u=0;u<b;u++)(f=n.__k[u])!=null&&(h=f.__i==-1?ee:T[f.__i]||ee,f.__i=u,v=ze(e,f,h,i,s,l,r,a,c,d),g=f.__e,f.ref&&h.ref!=f.ref&&(h.ref&&Ee(h.ref,null,f),d.push(f.ref,f.__c||g,f)),_==null&&g!=null&&(_=g),4&f.__u||h.__k===f.__k?a=je(f,a,e):typeof f.type=="function"&&v!==void 0?a=v:g&&(a=g.nextSibling),f.__u&=-7);return n.__e=_,a}function St(e,t,n,o,i){var s,l,r,a,c,d=n.length,u=d,h=0;for(e.__k=new Array(i),s=0;s<i;s++)(l=t[s])!=null&&typeof l!="boolean"&&typeof l!="function"?(a=s+h,(l=e.__k[s]=typeof l=="string"||typeof l=="number"||typeof l=="bigint"||l.constructor==String?ae(null,l,null,null,null):le(l)?ae(ce,{children:l},null,null,null):l.constructor==null&&l.__b>0?ae(l.type,l.props,l.key,l.ref?l.ref:null,l.__v):l).__=e,l.__b=e.__b+1,r=null,(c=l.__i=zt(l,n,a,u))!=-1&&(u--,(r=n[c])&&(r.__u|=2)),r==null||r.__v==null?(c==-1&&(i>d?h--:i<d&&h++),typeof l.type!="function"&&(l.__u|=4)):c!=a&&(c==a-1?h--:c==a+1?h++:(c>a?h--:h++,l.__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=Y(r)),Xe(r,r));return o}function je(e,t,n){var o,i;if(typeof e.type=="function"){for(o=e.__k,i=0;o&&i<o.length;i++)o[i]&&(o[i].__=e,t=je(o[i],t,n));return t}e.__e!=t&&(t&&e.type&&!n.contains(t)&&(t=Y(e)),n.insertBefore(e.__e,t||null),t=e.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function zt(e,t,n,o){var i,s,l=e.key,r=e.type,a=t[n];if(a===null&&e.key==null||a&&l==a.key&&r==a.type&&(2&a.__u)==0)return n;if(o>(a!=null&&(2&a.__u)==0?1:0))for(i=n-1,s=n+1;i>=0||s<t.length;){if(i>=0){if((a=t[i])&&(2&a.__u)==0&&l==a.key&&r==a.type)return i;i--}if(s<t.length){if((a=t[s])&&(2&a.__u)==0&&l==a.key&&r==a.type)return s;s++}}return-1}function qe(e,t,n){t[0]=="-"?e.setProperty(t,n??""):e[t]=n==null?"":typeof n!="number"||Tt.test(t)?n:n+"px"}function he(e,t,n,o,i){var s;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")),t=t.toLowerCase()in e||t=="onFocusOut"||t=="onFocusIn"?t.toLowerCase().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 He(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(M.event?M.event(t):t)}}}function ze(e,t,n,o,i,s,l,r,a,c){var d,u,h,f,g,_,v,T,b,C,p,S,w,y,z,N,E,k=t.type;if(t.constructor!=null)return null;128&n.__u&&(a=!!(32&n.__u),s=[r=t.__e=n.__e]),(d=M.__b)&&d(t);e:if(typeof k=="function")try{if(T=t.props,b="prototype"in k&&k.prototype.render,C=(d=k.contextType)&&o[d.__c],p=d?C?C.props.value:d.__:o,n.__c?v=(u=t.__c=n.__c).__=u.__E:(b?t.__c=u=new k(T,p):(t.__c=u=new ue(T,p),u.constructor=k,u.render=Lt),C&&C.sub(u),u.props=T,u.state||(u.state={}),u.context=p,u.__n=o,h=u.__d=!0,u.__h=[],u._sb=[]),b&&u.__s==null&&(u.__s=u.state),b&&k.getDerivedStateFromProps!=null&&(u.__s==u.state&&(u.__s=H({},u.__s)),H(u.__s,k.getDerivedStateFromProps(T,u.__s))),f=u.props,g=u.state,u.__v=t,h)b&&k.getDerivedStateFromProps==null&&u.componentWillMount!=null&&u.componentWillMount(),b&&u.componentDidMount!=null&&u.__h.push(u.componentDidMount);else{if(b&&k.getDerivedStateFromProps==null&&T!==f&&u.componentWillReceiveProps!=null&&u.componentWillReceiveProps(T,p),!u.__e&&u.shouldComponentUpdate!=null&&u.shouldComponentUpdate(T,u.__s,p)===!1||t.__v==n.__v){for(t.__v!=n.__v&&(u.props=T,u.state=u.__s,u.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(L){L&&(L.__=t)}),S=0;S<u._sb.length;S++)u.__h.push(u._sb[S]);u._sb=[],u.__h.length&&l.push(u);break e}u.componentWillUpdate!=null&&u.componentWillUpdate(T,u.__s,p),b&&u.componentDidUpdate!=null&&u.__h.push(function(){u.componentDidUpdate(f,g,_)})}if(u.context=p,u.props=T,u.__P=e,u.__e=!1,w=M.__r,y=0,b){for(u.state=u.__s,u.__d=!1,w&&w(t),d=u.render(u.props,u.state,u.context),z=0;z<u._sb.length;z++)u.__h.push(u._sb[z]);u._sb=[]}else do u.__d=!1,w&&w(t),d=u.render(u.props,u.state,u.context),u.state=u.__s;while(u.__d&&++y<25);u.state=u.__s,u.getChildContext!=null&&(o=H(H({},o),u.getChildContext())),b&&!h&&u.getSnapshotBeforeUpdate!=null&&(_=u.getSnapshotBeforeUpdate(f,g)),N=d,d!=null&&d.type===ce&&d.key==null&&(N=Ve(d.props.children)),r=We(e,le(N)?N:[N],t,n,o,i,s,l,r,a,c),u.base=t.__e,t.__u&=-161,u.__h.length&&l.push(u),v&&(u.__E=u.__=null)}catch(L){if(t.__v=null,a||s!=null)if(L.then){for(t.__u|=a?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--;)ke(s[E]);else t.__e=n.__e,t.__k=n.__k;M.__e(L,t,n)}else s==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):r=t.__e=Et(n.__e,t,n,o,i,s,l,a,c);return(d=M.diffed)&&d(t),128&t.__u?void 0:r}function Be(e,t,n){for(var o=0;o<n.length;o++)Ee(n[o],n[++o],n[++o]);M.__c&&M.__c(t,e),e.some(function(i){try{e=i.__h,i.__h=[],e.some(function(s){s.call(i)})}catch(s){M.__e(s,i.__v)}})}function Ve(e){return typeof e!="object"||e==null||e.__b&&e.__b>0?e:le(e)?e.map(Ve):H({},e)}function Et(e,t,n,o,i,s,l,r,a){var c,d,u,h,f,g,_,v=n.props,T=t.props,b=t.type;if(b=="svg"?i="http://www.w3.org/2000/svg":b=="math"?i="http://www.w3.org/1998/Math/MathML":i||(i="http://www.w3.org/1999/xhtml"),s!=null){for(c=0;c<s.length;c++)if((f=s[c])&&"setAttribute"in f==!!b&&(b?f.localName==b:f.nodeType==3)){e=f,s[c]=null;break}}if(e==null){if(b==null)return document.createTextNode(T);e=document.createElementNS(i,b,T.is&&T),r&&(M.__m&&M.__m(t,s),r=!1),s=null}if(b==null)v===T||r&&e.data==T||(e.data=T);else{if(s=s&&se.call(e.childNodes),v=n.props||ee,!r&&s!=null)for(v={},c=0;c<e.attributes.length;c++)v[(f=e.attributes[c]).name]=f.value;for(c in v)if(f=v[c],c!="children"){if(c=="dangerouslySetInnerHTML")u=f;else if(!(c in T)){if(c=="value"&&"defaultValue"in T||c=="checked"&&"defaultChecked"in T)continue;he(e,c,null,f,i)}}for(c in T)f=T[c],c=="children"?h=f:c=="dangerouslySetInnerHTML"?d=f:c=="value"?g=f:c=="checked"?_=f:r&&typeof f!="function"||v[c]===f||he(e,c,f,v[c],i);if(d)r||u&&(d.__html==u.__html||d.__html==e.innerHTML)||(e.innerHTML=d.__html),t.__k=[];else if(u&&(e.innerHTML=""),We(t.type=="template"?e.content:e,le(h)?h:[h],t,n,o,b=="foreignObject"?"http://www.w3.org/1999/xhtml":i,s,l,s?s[0]:n.__k&&Y(n,0),r,a),s!=null)for(c=s.length;c--;)ke(s[c]);r||(c="value",b=="progress"&&g==null?e.removeAttribute("value"):g!=null&&(g!==e[c]||b=="progress"&&!g||b=="option"&&g!=v[c])&&he(e,c,g,v[c],i),c="checked",_!=null&&_!=e[c]&&he(e,c,_,v[c],i))}return e}function Ee(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){M.__e(i,n)}}function Xe(e,t,n){var o,i;if(M.unmount&&M.unmount(e),(o=e.ref)&&(o.current&&o.current!=e.__e||Ee(o,null,t)),(o=e.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(s){M.__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||ke(e.__e),e.__c=e.__=e.__e=void 0}function Lt(e,t,n){return this.constructor(e,n)}function Ye(e,t,n){var o,i,s,l;t==document&&(t=document.documentElement),M.__&&M.__(e,t),i=(o=!1)?null:t.__k,s=[],l=[],ze(t,e=t.__k=kt(ce,null,[e]),i||ee,ee,t.namespaceURI,i?null:t.firstChild?se.call(t.childNodes):null,s,i?i.__e:t.firstChild,o,l),Be(s,e,l)}function Nt(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(l){l.__e=!0,Se(l)})},this.sub=function(s){o.add(s);var l=s.componentWillUnmount;s.componentWillUnmount=function(){o&&o.delete(s),l&&l.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}se=Ue.slice,M={__e:function(e,t,n,o){for(var i,s,l;t=t.__;)if((i=t.__c)&&!i.__)try{if((s=i.constructor)&&s.getDerivedStateFromError!=null&&(i.setState(s.getDerivedStateFromError(e)),l=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(e,o||{}),l=i.__d),l)return i.__E=i}catch(r){e=r}throw e}},xe=0,ue.prototype.setState=function(e,t){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=H({},this.state),typeof e=="function"&&(e=e(H({},n),this.props)),e&&H(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),Se(this))},ue.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),Se(this))},ue.prototype.render=ce,V=[],Fe=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,De=function(e,t){return e.__v.__b-t.__v.__b},de.__r=0,Oe=/(PointerCapture)$|Capture$/i,ye=0,be=He(!1),Te=He(!0),$e=0;var Mt=0;function m(e,t,n,o,i,s){t||(t={});var l,r,a=t;if("ref"in a)for(r in a={},t)r=="ref"?l=t[r]:a[r]=t[r];var c={type:e,props:a,key:n,ref:l,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Mt,__i:-1,__u:0,__source:i,__self:s};if(typeof e=="function"&&(l=e.defaultProps))for(r in l)a[r]===void 0&&(a[r]=l[r]);return M.vnode&&M.vnode(c),c}var K,A,Le,Ke,te=0,Je=[],F=M,Ze=F.__b,Qe=F.__r,et=F.diffed,tt=F.__c,nt=F.unmount,ot=F.__;function fe(e,t){F.__h&&F.__h(A,e,te||t),te=0;var n=A.__H||(A.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function U(e){return te=1,At(lt,e)}function At(e,t,n){var o=fe(K++,2);if(o.t=e,!o.__c&&(o.__=[lt(void 0,t),function(r){var a=o.__N?o.__N[0]:o.__[0],c=o.t(a,r);a!==c&&(o.__N=[c,o.__[1]],o.__c.setState({}))}],o.__c=A,!A.__f)){var i=function(r,a,c){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,a,c);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,a,c)||u};A.__f=!0;var s=A.shouldComponentUpdate,l=A.componentWillUpdate;A.componentWillUpdate=function(r,a,c){if(this.__e){var d=s;s=void 0,i(r,a,c),s=d}l&&l.call(this,r,a,c)},A.shouldComponentUpdate=i}return o.__N||o.__}function I(e,t){var n=fe(K++,3);!F.__s&&st(n.__H,t)&&(n.__=e,n.u=t,A.__H.__h.push(n))}function x(e){return te=5,J(function(){return{current:e}},[])}function J(e,t){var n=fe(K++,7);return st(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function rt(e,t){return te=8,J(function(){return e},t)}function Pt(e){var t=A.context[e.__c],n=fe(K++,9);return n.c=e,t?(n.__==null&&(n.__=!0,t.sub(A)),t.props.value):e.__}function It(){for(var e;e=Je.shift();)if(e.__P&&e.__H)try{e.__H.__h.forEach(me),e.__H.__h.forEach(Ne),e.__H.__h=[]}catch(t){e.__H.__h=[],F.__e(t,e.__v)}}F.__b=function(e){A=null,Ze&&Ze(e)},F.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),ot&&ot(e,t)},F.__r=function(e){Qe&&Qe(e),K=0;var t=(A=e.__c).__H;t&&(Le===A?(t.__h=[],A.__h=[],t.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.forEach(me),t.__h.forEach(Ne),t.__h=[],K=0)),Le=A},F.diffed=function(e){et&&et(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(Je.push(t)!==1&&Ke===F.requestAnimationFrame||((Ke=F.requestAnimationFrame)||xt)(It)),t.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),Le=A=null},F.__c=function(e,t){t.some(function(n){try{n.__h.forEach(me),n.__h=n.__h.filter(function(o){return!o.__||Ne(o)})}catch(o){t.some(function(i){i.__h&&(i.__h=[])}),t=[],F.__e(o,n.__v)}}),tt&&tt(e,t)},F.unmount=function(e){nt&&nt(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.forEach(function(o){try{me(o)}catch(i){t=i}}),n.__H=void 0,t&&F.__e(t,n.__v))};var it=typeof requestAnimationFrame=="function";function xt(e){var t,n=function(){clearTimeout(o),it&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(n,100);it&&(t=requestAnimationFrame(n))}function me(e){var t=A,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),A=t}function Ne(e){var t=A;e.__c=e.__(),A=t}function st(e,t){return!e||e.length!==t.length||t.some(function(n,o){return n!==e[o]})}function lt(e,t){return typeof t=="function"?t(e):t}const Rt=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)}}}),at=Nt(void 0),ct={currentLevel:1,highestUnlockedLevel:1,currentTier:1,highestUnlockedTier:1,levelScores:{},totalScore:0},Me={isGameActive:!0,levelTransitioning:!1,maze:null,playerCell:{row:0,col:0},exitCell:{row:0,col:0},foodCells:[],playerAtExit:!1,foodCollected:0,totalFoodCount:0,showClue:!1,playerPath:[],visitCounts:{}},Ft=({children:e,config:t})=>{const n=Rt(t.lcPrefix+"progress"),o=n.loadGameData(),[i,s]=U(()=>o||{...ct});I(()=>{const u=Object.values(i.levelScores).reduce((h,f)=>h+f,0);s(h=>({...h,totalScore:u}))},[i.levelScores]),I(()=>{n.saveGameData(i)},[i.currentLevel,i.highestUnlockedLevel,i.currentTier,i.highestUnlockedTier,i.levelScores,i.totalScore]);const[l,r]=U({...Me}),a=x(l);I(()=>{a.current=l},[l]);const c=J(()=>[l.playerAtExit?1:0,l.foodCollected===l.totalFoodCount?1:0,l.showClue?0:1],[l.playerAtExit,l.foodCollected,l.totalFoodCount,l.showClue]),d=()=>{n.resetGameData(),s({...ct}),r({...Me})};return m(at.Provider,{value:{gameProgress:i,setGameProgress:s,gamePlayState:l,setGamePlayState:r,gamePlayStateRef:a,currentScore:c,config:t,resetGame:d},children:e})},ne=()=>{const e=Pt(at);if(!e)throw new Error("useGameContext must be used within a GameProvider");return e},oe=e=>J(()=>{const t=e.map(r=>r.length),n=t.reduce((r,a)=>r+a,0),o=e.length,i=r=>{if(r<1||r>n)return 0;let a=0;for(let c=0;c<t.length;c++)if(a+=t[c],r<=a)return c+1;return 0},s=r=>r<1||r>o?0:t.slice(0,r-1).reduce((a,c)=>a+c,0)+1,l={getTotalLevels:()=>n,getTotalTiers:()=>o,getTierLevelsRange:r=>{if(r<1||r>o)return[0,0];const a=s(r),c=a+t[r-1]-1;return[a,c]},getTierByLevel:i,getFirstLevelOfTier:s,getLevelConfig:r=>{if(r<1||r>n)return null;const a=i(r),c=s(a),d=r-c;return e[a-1][d]},getTierConfig:r=>r<1||r>o?null:e[r-1],isLevelUnlocked:(r,a)=>r<=a,isTierUnlocked:(r,a)=>r<=a,getNextLevelInfo:r=>{if(r>=n)return null;const a=r+1,c=i(r),d=i(a);return{nextLevel:a,nextTier:d,isTierChange:d>c}},getCurrentTierProgress:(r,a)=>{const[c,d]=l.getTierLevelsRange(a),u=r-c+1,h=d-c+1;return{current:u,total:h}},isLastLevelInTier:r=>{const a=i(r),[,c]=l.getTierLevelsRange(a);return r===c},getPreviousLevelInfo:r=>{if(r<=1)return null;const a=r-1,c=i(r),d=i(a);return{prevLevel:a,prevTier:d,isTierChange:d<c}}};return l},[e]),Dt=({onTierChange:e,disabled:t})=>{const{gameProgress:n,config:o}=ne(),{i18n:i,levelConfig:s}=o,{currentTier:l,highestUnlockedTier:r}=n,c=oe(s).getTotalTiers();return m("div",{className:"tier-selector",children:m("select",{value:l,onChange:d=>{d.target&&d.target.value&&e(Number(d.target.value))},disabled:t,className:"tier-dropdown",children:Array.from({length:c},(d,u)=>u+1).map(d=>m("option",{value:d,disabled:d>r,children:i.tier+" "+d},`tier-${d}`))})})},Ot=({onLevelChange:e,disabled:t})=>{const{gameProgress:n,config:o}=ne(),{i18n:i,levelConfig:s}=o,{currentTier:l,levelScores:r,currentLevel:a,highestUnlockedLevel:c}=n,d=oe(s),u=J(()=>{const[h,f]=d.getTierLevelsRange(l);return Array.from({length:f-h+1},(g,_)=>{const v=h+_,T=r[v]||0;return{level:v,score:T}})},[l,r]);return m("div",{className:"level-selector",children:m("select",{value:a,onChange:h=>{h.target&&h.target.value&&e(Number(h.target.value))},disabled:t,className:"level-dropdown",children:u.map(({level:h,score:f})=>m("option",{value:h,disabled:h>c,children:`${i.level} ${h} ${"★".repeat(f)}`},`level-${h}`))})})},re=({isOpen:e,title:t,className:n="",message:o,children:i,noConfirm:s=!1,noCancel:l=!1,confirmText:r="OK",cancelText:a="Cancel",confirmClass:c="",cancelClass:d="",onConfirm:u,onCancel:h})=>{const f=x(null);return I(()=>{const g=_=>{_.key==="Escape"&&h?.()};return e&&document.addEventListener("keydown",g),()=>{document.removeEventListener("keydown",g)}},[e,h]),m("div",{className:`maze-dialog-overlay ${e?"maze-dialog-visible":""}`,children:m("div",{className:"maze-dialog "+n,ref:f,children:[m("div",{className:"maze-dialog-title",children:t}),m("div",{className:"maze-dialog-content",children:i||m("div",{className:"maze-dialog-message",children:o})}),(!l||!s)&&m("div",{className:"maze-dialog-buttons",children:[!l&&m("button",{type:"button",className:"maze-dialog-cancel "+d,onClick:h,children:a}),!s&&m("button",{type:"button",className:"maze-dialog-confirm "+c,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)}},$t=()=>{const{gameProgress:e,setGameProgress:t,gamePlayState:n,setGamePlayState:o,gamePlayStateRef:i,resetGame:s,config:l}=ne(),{i18n:r,levelConfig:a}=l,c=oe(a),{levelTransitioning:d,showClue:u}=n,{highestUnlockedLevel:h,totalScore:f}=e,g=c.getTotalLevels(),[_,v]=U(!1),[T,b]=U(!1),[C,p]=U(!1),S=O=>{const $=c.getFirstLevelOfTier(O);c.isLevelUnlocked($,h)&&(t(G=>({...G,currentTier:O})),w($))},w=O=>{c.isLevelUnlocked(O,h)&&(t($=>({...$,currentLevel:O})),j.show(r.levelGoToast.replace("%LEVEL%",O.toString())))},y=()=>{v(!0)},z=()=>{v(!1)},N=()=>{p(!0)},E=()=>{p(!1)},k=()=>{j.show(u?r.cluePathDisabled:r.cluePathEnabled),o(()=>({...i.current,showClue:!i.current.showClue})),p(!1)},L=()=>{b(!0)},P=()=>{s(),b(!1),j.show(r.resetDoneToast)},R=()=>{b(!1)};return m("div",{class:"game-panel-container",children:[m("div",{className:"game-controls",children:[m("div",{className:"selectors-container",children:[m(Dt,{onTierChange:S,disabled:d}),m(Ot,{onLevelChange:w,disabled:d})]}),m("button",{className:`settings-clue-button ${u?"clue-on":"clue-off"}`,disabled:u,title:"Toggle Clue",onClick:N,children:u?r.clueOn:r.clueOff})]}),m("div",{className:"game-settings",children:m("span",{className:"game-settings-icon",onClick:y,children:"★ "+f})}),m(re,{isOpen:_,title:r.settings,noConfirm:!0,cancelText:r.close,onCancel:z,children:[m("div",{className:"settings-stats",children:[m("div",{children:r.levelComplete+`: ${h}/${g}`}),m("div",{children:r.starsCollected+": "+f}),m("div",{children:r.avgStarPerLevel+": "+(f/h).toFixed(2)})]}),m("div",{className:"settings-item-box",children:[m("button",{className:"settings-reset-button",title:"Reset Game",onClick:L,children:r.reset}),m("div",{className:"settings-item-tip",children:r.resetTip})]})]}),m(re,{isOpen:T,title:r.confirmReset,message:r.confirmResetMessage,confirmText:r.reset,cancelText:r.cancel,onConfirm:P,onCancel:R}),m(re,{isOpen:C,title:r.confirmClue,message:r.confirmClueMessage,confirmText:r.confirm,cancelText:r.cancel,onConfirm:k,onCancel:E})]})};function Ae(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Ut(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&&Ut(e.prototype,t),e}function ut(e){return+e.replace(/px/,"")}function Gt(e){var t=window.devicePixelRatio,n=getComputedStyle(e),o=ut(n.getPropertyValue("width")),i=ut(n.getPropertyValue("height"));e.setAttribute("width",(o*t).toString()),e.setAttribute("height",(i*t).toString())}function q(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 dt(e){return e[q(0,e.length)]}var Wt=.00125,jt=5e-4,qt=9e-4,Ht=1e-5,Bt=6,Vt=80,Xt=.9,Yt=1.7,Kt=.2,Jt=.6,Zt=.03,Qt=.07,en=15,tn=82,nn=100,on=250,rn=40,sn=["#fcf403","#62fc03","#f4fc03","#03e7fc","#03fca5","#a503fc","#fc03ad","#fc03c2"];function ht(e){var t=1920;return Math.log(e)/Math.log(t)}var ft=function(){function e(t){Ae(this,e);var n=t.initialPosition,o=t.direction,i=t.confettiRadius,s=t.confettiColors,l=t.emojis,r=t.emojiSize,a=t.canvasWidth,c=q(Xt,Yt,3),d=c*ht(a);this.confettiSpeed={x:d,y:d},this.finalConfettiSpeedX=q(Kt,Jt,3),this.rotationSpeed=l.length?.01:q(Zt,Qt,3)*ht(a),this.dragForceCoefficient=q(jt,qt,6),this.radius={x:i,y:i},this.initialRadius=i,this.rotationAngle=o==="left"?q(0,.2,3):q(-.2,0,3),this.emojiSize=r,this.emojiRotationAngle=q(0,2*Math.PI),this.radiusYUpdateDirection="down";var u=o==="left"?q(tn,en)*Math.PI/180:q(-15,-82)*Math.PI/180;this.absCos=Math.abs(Math.cos(u)),this.absSin=Math.abs(Math.sin(u));var h=q(-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=l.length?null:dt(s),this.emoji=l.length?dt(l):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,l=this.emoji,r=this.rotationAngle,a=this.emojiRotationAngle,c=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()):l&&(n.font="".concat(c,"px serif"),n.save(),n.translate(d*o.x,d*o.y),n.rotate(a),n.textAlign="center",n.fillText(l,0,0),n.restore())}},{key:"updatePosition",value:function(n,o){var i=this.confettiSpeed,s=this.dragForceCoefficient,l=this.finalConfettiSpeedX,r=this.radiusYUpdateDirection,a=this.rotationSpeed,c=this.createdAt,d=this.direction,u=o-c;if(i.x>l&&(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+Wt*Math.pow(u,2)/2,this.rotationSpeed-=this.emoji?1e-4:Ht*n,this.rotationSpeed<0&&(this.rotationSpeed=0),this.emoji){this.emojiRotationAngle+=this.rotationSpeed*n%(2*Math.PI);return}r==="down"?(this.radius.y-=n*a,this.radius.y<=0&&(this.radius.y=0,this.radiusYUpdateDirection="up")):(this.radius.y+=n*a,this.radius.y>=this.initialRadius&&(this.radius.y=this.initialRadius,this.radiusYUpdateDirection="down"))}},{key:"getIsVisibleOnCanvas",value:function(n){return this.currentPosition.y<n+nn}}]),e}();function ln(){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 an(e){var t=e.confettiRadius,n=t===void 0?Bt:t,o=e.confettiNumber,i=o===void 0?e.confettiesNumber||(e.emojis?rn:on):o,s=e.confettiColors,l=s===void 0?sn:s,r=e.emojis,a=r===void 0?e.emojies||[]:r,c=e.emojiSize,d=c===void 0?Vt:c;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:l,emojis:a,emojiSize:d}}var cn=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,l=n.timeDelta,r=n.currentTime;this.shapes=this.shapes.filter(function(a){return a.updatePosition(l,r),a.draw(s.canvasContext),i?a.getIsVisibleOnCanvas(o):!0})}}]),e}(),un=function(){function e(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Ae(this,e),this.activeConfettiBatches=[],this.canvas=t.canvas||ln(),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,Gt(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(l){return l.processShapes({timeDelta:o,currentTime:n},i,s),s?!l.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=an(n),i=o.confettiRadius,s=o.confettiNumber,l=o.confettiColors,r=o.emojis,a=o.emojiSize,c=this.canvas.getBoundingClientRect(),d=c.width,u=c.height,h=u*5/7,f={x:0,y:h},g={x:d,y:h},_=new cn(this.canvasContext),v=0;v<s/2;v++){var T=new ft({initialPosition:f,direction:"right",confettiRadius:i,confettiColors:l,confettiNumber:s,emojis:r,emojiSize:a,canvasWidth:d}),b=new ft({initialPosition:g,direction:"left",confettiRadius:i,confettiColors:l,confettiNumber:s,emojis:r,emojiSize:a,canvasWidth:d});_.addShapes(T,b)}return this.activeConfettiBatches.push(_),this.queueAnimationFrameIfNeeded(),_.getBatchCompletePromise()}},{key:"clearCanvas",value:function(){this.activeConfettiBatches=[]}},{key:"destroyCanvas",value:function(){this.canvas.remove()}}]),e}();const dn=new un,Ie=3,hn=({onRetry:e})=>{const{config:t,currentScore:n,gamePlayState:o,setGamePlayState:i,gameProgress:s,setGameProgress:l}=ne(),{i18n:r,levelConfig:a}=t,[c,d,u]=n,{foodCollected:h,totalFoodCount:f,playerAtExit:g,levelTransitioning:_}=o,{currentLevel:v}=s,[T,b]=U(!1);I(()=>{g&&_&&(dn.addConfetti(),j.show(r.levelCompleteToast),b(!0))},[g,_]);const C=oe(a),p=C.getTotalLevels(),S=J(()=>v>=p,[v,p]),w=()=>{b(!1),j.show(r.levelRestartToast),e?.()},y=()=>{b(!1),i(E=>({...E,isGameActive:!0,levelTransitioning:!1}))},z=()=>{b(!1);const E=C.getNextLevelInfo(v);if(!E)return;const{nextLevel:k,nextTier:L,isTierChange:P}=E;P&&j.show(r.tierUnlockedToast.replace("%TIER%",L.toString())),l(R=>({...R,currentLevel:k,currentTier:L,highestUnlockedLevel:Math.max(R.highestUnlockedLevel,k),highestUnlockedTier:Math.max(R.highestUnlockedTier,L),levelScores:{...R.levelScores,[R.currentLevel]:Math.max(Object.values(n).filter(Boolean).length,R.levelScores[R.currentLevel]||0)}}))},N=()=>{b(!1),l(E=>{const k=Math.max(Object.values(n).filter(Boolean).length,E.levelScores[E.currentLevel]||0),L={...E.levelScores,[E.currentLevel]:k};let P=0,R=0;const O=Object.entries(L).sort(($,G)=>Number($[0])-Number(G[0]));for(const[$,G]of O)if(G<Ie){P=Number($),R=C.getTierByLevel(P);break}return(P>0&&P!==v||k<Ie)&&j.show(r.notCompleteLevel),(P===0||k<Ie)&&e?.(),{...E,currentLevel:P||E.currentLevel,currentTier:R||E.currentTier,levelScores:L}})};return I(()=>{const E=document.querySelector(".maze-game-container"),k=L=>{T&&((L.key===" "||L.code==="Space")&&E&&(E.contains(document.activeElement)||document.activeElement===document.body)&&(L.preventDefault(),S?N():z()),(L.key==="r"||L.code==="KeyR")&&w(),(L.key==="c"||L.code==="KeyC")&&y())};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[T,S]),m(re,{className:"level-complete-dialog",isOpen:T,title:r.congratulations,cancelText:r.retry+" (R)",onCancel:w,noConfirm:!!d,confirmText:r.continue+" (C)",onConfirm:y,confirmClass:"maze-continue-btn",children:[m("div",{className:"maze-summary-message",children:[!!c&&m("div",{children:"★ - "+r.findYourExit}),m("div",{children:u?"★ - "+r.withoutClue:"☆ - "+r.withClue}),m("div",{children:(d?"★ - "+r.collectAllStars:"☆ - "+r.notCollectAllStars)+` (${h}/${f})`})]}),S&&m("div",{className:"all-levels-completed",children:r.allLevelsCompleted}),m("div",{className:"maze-go-next",children:S?m("button",{className:"maze-go-next-btn",type:"button",onClick:N,children:[m("span",{children:r.lastOK}),m("span",{className:"spacebar-tip",children:`(${r.spacebarTip})`})]}):m("button",{className:"maze-go-next-btn",type:"button",onClick:z,children:[m("span",{children:r.nextLevel}),m("span",{className:"spacebar-tip",children:`(${r.spacebarTip})`})]})}),!d&&m("div",{className:"not-all-stars-collected",children:r.continueMessage})]})},mt=(e,t)=>{const n=x({canvasWidth:0,canvasHeight:0});return I(()=>{const o=()=>{const s=e.current;if(!s)return;const l=s.parentElement;if(!l)return;const r=l.clientWidth;if(r===0)return;const a=window.devicePixelRatio||1;s.style.width=`${r}px`,s.style.height=`${r}px`;const c=r*a,d=r*a;s.width=c,s.height=d,n.current={canvasWidth:c,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},_t=(e,t,n)=>{const o=x({cellWidth:0,cellHeight:0});return I(()=>{const i=()=>{const l=e.current,r=t.maze;if(!l||!r)return;const{rows:a,cols:c}=r;if(a<=0||c<=0)return;const d=(l.width-n*2)/c,u=(l.height-n*2)/a;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},_e={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]},vt=({gamePlayStateRef:e,setGamePlayState:t,moveSpeed:n,moveSpeedRef:o,playerRadius:i,onFoodCollected:s,onExitReached:l,onFirstMove:r})=>{const a=()=>o?.current??n??.03,c=x(!1),d=x(new Set),u=x(!1),h=rt((C,p)=>{const S=e.current;if(!S.maze)return{canMove:!1,newCell:null};const w=a(),[y,z]=_e[C];if(gt(p,y,z,i,w,S.maze))return{canMove:!1,newCell:null};const{row:E,col:k}=p,L=E+y*w,P=k+z*w,R=-.5,O=S.maze.rows,$=S.maze.cols;if(L<R||L>=O||P<R||P>=$)return{canMove:!1,newCell:null};const G=E<0?0:Math.floor(E),X=k<0?0:Math.floor(k),B=L<0?0:Math.floor(L),Z=P<0?0:Math.floor(P);return B!==G||Z!==X?S.maze.isValid(B,Z)?{canMove:!0,newCell:{row:B,col:Z}}:{canMove:!1,newCell:null}:{canMove:!0,newCell:null}},[i,a]),f=()=>{const C=e.current,{row:p,col:S}=C.playerCell,w=i*2,y=C.foodCells.findIndex(E=>Math.sqrt(Math.pow(p-E.row,2)+Math.pow(S-E.col,2))<w);y!==-1&&s&&(s(),e.current={...e.current,foodCollected:e.current.foodCollected+1,foodCells:e.current.foodCells.filter((E,k)=>k!==y)});const N=_n(C.playerCell,C.exitCell,C.maze);N&&!e.current.playerAtExit?(e.current={...e.current,playerAtExit:!0,isGameActive:!1,levelTransitioning:!0},l&&l(),requestIdleCallback(()=>{t(()=>({...e.current}))},{timeout:10})):!N&&e.current.playerAtExit&&(e.current={...e.current,playerAtExit:!1,isGameActive:!0,levelTransitioning:!1})},g=C=>{const p=e.current,S=Math.round(C.row),w=Math.round(C.col),y=p.playerPath[p.playerPath.length-1],z=y.row===S&&y.col===w,N=Math.abs(y.row-S),E=Math.abs(y.col-w);if((N===1&&E===0||N===0&&E===1)&&!z){const L=`${y.row},${y.col}-${S},${w}`;e.current={...e.current,playerPath:[...e.current.playerPath,{row:S,col:w}],visitCounts:{...e.current.visitCounts,[L]:(e.current.visitCounts[L]||0)+1}}}},_=()=>{if(c.current||d.current.size===0)return;const C=e.current;!C.playerCell||!Array.from(d.current).some(S=>{const{canMove:w}=h(S,C.playerCell);return w})||(!u.current&&r&&(u.current=!0,r()),c.current=!0)};I(()=>{const C=w=>{if(w.key==="ArrowUp"||w.key==="ArrowDown"||w.key==="ArrowLeft"||w.key==="ArrowRight"||w.key===" "){const y=document.activeElement;if(y&&(y.tagName==="INPUT"||y.tagName==="TEXTAREA"||y.getAttribute("contenteditable")==="true"))return;w.preventDefault()}},p=w=>{const y=w.key;if(!(y in _e))return;const z=document.activeElement;z&&(z.tagName==="INPUT"||z.tagName==="TEXTAREA"||z.getAttribute("contenteditable")==="true")||(w.preventDefault(),e.current.isGameActive&&(d.current.has(y)||(d.current.add(y),c.current||_())))},S=w=>{const y=w.key;if(!(y in _e))return;const z=document.activeElement;z&&(z.tagName==="INPUT"||z.tagName==="TEXTAREA"||z.getAttribute("contenteditable")==="true")||(w.preventDefault(),d.current.delete(y),d.current.size===0&&T())};return window.addEventListener("keydown",C,{capture:!0}),window.addEventListener("keydown",p),window.addEventListener("keyup",S),()=>{window.removeEventListener("keydown",C,{capture:!0}),window.removeEventListener("keydown",p),window.removeEventListener("keyup",S)}},[]);const v=rt(()=>{if(!c.current||d.current.size===0)return e.current.playerCell;const C=a(),p=e.current.playerCell;let S=0,w=0,y=0;for(const D of d.current){const{canMove:W}=h(D,p);if(W){const[Q,we]=_e[D];S+=Q,w+=we,y++}}if(y===0)return e.current.playerCell;const z=Math.sqrt(S*S+w*w),N=z>0?S/z:0,E=z>0?w/z:0,k=Number((p.row+N*C).toFixed(2)),L=Number((p.col+E*C).toFixed(2)),P=k-p.row,R=L-p.col,O=Math.sqrt(P*P+R*R);if(O>0){const D=P/O,W=R/O;if(gt(p,D,W,i,O,e.current.maze))return e.current.playerCell}e.current.playerCell={row:k,col:L},f();const $=p.row<0?0:Math.round(p.row),G=p.col<0?0:Math.round(p.col),X=k<0?0:Math.round(k),B=L<0?0:Math.round(L);return(X!==$||B!==G)&&g({row:X,col:B}),e.current.playerCell},[a,h]),T=()=>{c.current=!1,d.current.clear()};return{updatePlayerPos:v,resetMovingState:T,resetFirstMoveState:()=>{u.current=!1}}};function gt(e,t,n,o,i,s){const l=e.row+t*i,r=e.col+n*i,a={row:l,col:r},c=[],d=e.row<0?0:Math.floor(e.row),u=e.col<0?0:Math.floor(e.col);c.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,g]of h){const _=d+f,v=u+g;s.isValid(_,v)&&c.push({row:_,col:v})}for(const f of c){const g=fn(f.row,f.col,s);for(const _ of g)if(mn(a,_)<o)return!0}return!1}function fn(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 mn(e,t){const{start:n,end:o}=t,i=o.col-n.col,s=o.row-n.row,l=e.col-n.col,r=e.row-n.row,a=i*i+s*s;if(a===0)return Math.sqrt(l*l+r*r);const c=Math.max(0,Math.min(1,(l*i+r*s)/a)),d=n.col+c*i,u=n.row+c*s,h=e.col-d,f=e.row-u;return Math.sqrt(h*h+f*f)}function _n(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 pt(e,t,n,o,i){if(!e||!t.maze)return;const{canvasWidth:s,canvasHeight:l}=n,{cellWidth:r,cellHeight:a}=o,{maze:c,playerCell:d,exitCell:u,foodCells:h,showClue:f,playerPath:g,visitCounts:_}=t,{padding:v,wallWidth:T,wallColor:b,playerColor:C,playerRadius:p,foodColor:S,backgroundColor:w,clueColor:y,exitColor:z,exitWallWidth:N,exitDashArray:E}=i;e.clearRect(0,0,s,l),e.save(),e.fillStyle=w,e.fillRect(0,0,s,l),e.restore(),f&&yn({ctx:e,playerPath:g,visitCounts:_,cellWidth:r,cellHeight:a,padding:v,clueColor:y}),vn({ctx:e,maze:c,cellWidth:r,cellHeight:a,padding:v,wallColor:b,wallWidth:T}),pn({ctx:e,maze:c,exitCell:u,cellWidth:r,cellHeight:a,padding:v,exitColor:z,exitWallWidth:N,exitDashArray:E}),wn({ctx:e,foodCells:h,cellWidth:r,cellHeight:a,padding:v,foodColor:S}),gn({ctx:e,playerCell:d,playerRadius:p,cellWidth:r,cellHeight:a,padding:v,playerColor:C})}function vn({ctx:e,maze:t,cellWidth:n,cellHeight:o,padding:i,wallColor:s,wallWidth:l}){e.save(),e.strokeStyle=s,e.lineWidth=l,e.lineCap="round",e.beginPath(),bn(t,n,o,i).forEach(a=>{e.moveTo(a.x1,a.y1),e.lineTo(a.x2,a.y2)}),e.stroke(),e.restore()}function gn({ctx:e,playerCell:t,playerRadius:n,cellWidth:o,cellHeight:i,padding:s,playerColor:l}){const{x:r,y:a}=ve(t.row,t.col,o,i,s),c=Math.min(o,i)*Math.min(n,.5);e.save(),e.fillStyle=l,e.beginPath(),e.arc(r,a,c,0,Math.PI*2),e.fill(),e.restore()}function pn({ctx:e,maze:t,exitCell:n,cellWidth:o,cellHeight:i,padding:s,exitColor:l,exitWallWidth:r,exitDashArray:a=[8,12]}){const{row:c,col:d}=n;if(!t.isValid(c,d))return;const u=s+d*o,h=s+c*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=l,e.lineWidth=r,e.setLineDash(a),e.beginPath(),e.moveTo(u,h+i),e.lineTo(u+o,h+i),e.stroke(),e.restore()}function wn({ctx:e,foodCells:t,cellWidth:n,cellHeight:o,padding:i,foodColor:s}){e.fillStyle=s;const l=Math.min(n,o)*.25;t.forEach(r=>{const{x:a,y:c}=ve(r.row,r.col,n,o,i);Cn(e,a,c,l*1.2,5,l*.6)})}function Cn(e,t,n,o,i,s){e.save(),e.beginPath();for(let l=0;l<i*2;l++){const r=l%2===0?o:s,a=Math.PI*l/i;e.lineTo(t+r*Math.sin(a),n+r*Math.cos(a))}e.closePath(),e.fill(),e.restore()}function yn({ctx:e,playerPath:t,visitCounts:n,cellWidth:o,cellHeight:i,padding:s,clueColor:l}){if(!(!t||t.length<2||!n)){e.save();for(let r=1;r<t.length;r++){const a=t[r-1],c=t[r],d=`${a.row},${a.col}-${c.row},${c.col}`,u=`${c.row},${c.col}-${a.row},${a.col}`,h=(n[d]||0)+(n[u]||0),f=Math.min(.2+h*.1,.9),g=Math.max(3,o*.1)+h*.5;try{e.strokeStyle=l.replace(")",`, ${f})`).replace("rgb(","rgba(")}catch{e.strokeStyle=`rgba(255, 0, 0, ${f})`}e.lineWidth=g,e.lineCap="round",e.lineJoin="round";const{x:_,y:v}=ve(a.row,a.col,o,i,s),{x:T,y:b}=ve(c.row,c.col,o,i,s);e.beginPath(),e.moveTo(_,v),e.lineTo(T,b),e.stroke()}e.restore()}}function bn(e,t,n,o){const i=[];for(let s=0;s<e.rows;s++)for(let l=0;l<e.cols;l++){const r=e.grid[s][l],a=o+l*t,c=o+s*n;r.walls.top&&i.push({x1:a,y1:c,x2:a+t,y2:c}),r.walls.right&&i.push({x1:a+t,y1:c,x2:a+t,y2:c+n}),r.walls.bottom&&i.push({x1:a,y1:c+n,x2:a+t,y2:c+n}),r.walls.left&&i.push({x1:a,y1:c,x2:a,y2:c+n})}return i}function ve(e,t,n,o,i){return{x:i+t*n+n/2,y:i+e*o+o/2}}function Tn(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 kn{constructor(t,n){this.row=t,this.col=n}visited=!1;walls={top:!0,right:!0,bottom:!0,left:!0}}class wt{rows;cols;grid;seed;random;constructor(t,n,o,i,s={row:0,col:0},l={row:t-1,col:n-1}){this.rows=t,this.cols=n,this.seed=i??Math.floor(Math.random()*1e6),this.random=Tn(this.seed),this.grid=this.initializeGrid(),this.generate(o,s,l)}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 kn(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 l=t+s.r,r=n+s.c;this.isValid(l,r)&&o.push({row:l,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],l=this.grid[o][i];t===o+1?(s.walls.top=!1,l.walls.bottom=!1):t===o-1?(s.walls.bottom=!1,l.walls.top=!1):n===i+1?(s.walls.left=!1,l.walls.right=!1):n===i-1&&(s.walls.right=!1,l.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:l}=i,r=this.getUnvisitedNeighbors(s,l);if(r.length>0){const a=this.randomPick(r),{row:c,col:d}=a;this.removeWall(s,l,c,d),this.grid[c][d].visited=!0,t.push(a)}else t.pop()}}generateWithPrims(){const t=[],n=(s,l)=>{const r=this.getNeighbors(s,l);for(const a of r)!this.grid[a.row][a.col].visited&&!t.some(c=>c.row===a.row&&c.col===a.col)&&t.push(a)},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),l=t[s],{row:r,col:a}=l,c=this.getVisitedNeighbors(r,a);if(c.length>0){const d=this.randomPick(c);this.removeWall(r,a,d.row,d.col),this.grid[r][a].visited=!0,n(r,a)}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 Ct=(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},Sn=e=>e===1?2:e>=2&&e<=5?3:e>=6&&e<=11?4:e>=12&&e<=15?5:6,zn=(e,t)=>{if(!t)return console.error(`Cannot find Level ${e}'s config.`),null;const{size:n,seed:o,method:i,entry:s,exit:l}=t,r=n,a=n,c=s||{row:0,col:0},d=l||{row:r-1,col:a-1},u=new wt(r,a,i,o,c,d),h=Sn(e),f=[];for(let g=0;g<h;g++){let _;do _={row:Math.floor(u.random()*r),col:Math.floor(u.random()*a)};while(_.row===c.row&&_.col===c.col||_.row===d.row&&_.col===d.col||!Ct(u,_.row,_.col)||f.some(v=>v.row===_.row&&v.col===_.col));f.push(_)}return{isGameActive:!0,levelTransitioning:!1,maze:u,playerCell:c,exitCell:d,foodCells:f,playerAtExit:!1,foodCollected:0,totalFoodCount:h,showClue:!1,playerPath:[c],visitCounts:{[`${c.row},${c.col}`]:1}}},En=({size:e,seed:t,method:n,foodCount:o,foodRace:i,clue:s})=>{const l=e,r=e,a={row:0,col:0},c={row:l-1,col:r-1},d=new wt(l,r,n,t,a,c),u=[];if(i)for(let h=0;h<o;h++){let f,g=0;do f={row:Math.floor(d.random()*l),col:Math.floor(d.random()*r)},g++;while(g<50&&(f.row===a.row&&f.col===a.col||f.row===c.row&&f.col===c.col||!Ct(d,f.row,f.col)||u.some(_=>_.row===f.row&&_.col===f.col)));g<50&&u.push(f)}return{isGameActive:!0,levelTransitioning:!1,maze:d,playerCell:a,exitCell:c,foodCells:u,playerAtExit:!1,foodCollected:0,totalFoodCount:i?o:0,showClue:s,playerPath:[a],visitCounts:{[`${a.row},${a.col}`]:1}}};function Ln(){const{setGamePlayState:e,gamePlayState:t,gamePlayStateRef:n,gameProgress:o,config:i}=ne(),s=x(null),l=x(null),{i18n:r,levelConfig:a,renderConfig:c}=i,d=oe(a),u=x(d.getLevelConfig(o.currentLevel));I(()=>{s.current&&j.attachTo(s.current)},[]);const h=x(),f=mt(l,()=>{h.current?.()}),g=_t(l,t,c.padding);I(()=>{u.current=d.getLevelConfig(o.currentLevel)},[o.currentLevel]);const _=()=>{const C=zn(o.currentLevel,u.current);C&&e(p=>({...p,...C}))};I(()=>{_()},[o.currentLevel]);const v=()=>{_()},{updatePlayerPos:T,resetMovingState:b}=vt({gamePlayStateRef:n,setGamePlayState:e,playerRadius:c.playerRadius,moveSpeed:c.gridMoveSpeed,onFoodCollected:()=>{const C=n.current.totalFoodCount-n.current.foodCollected-1;C>0?j.show(r.foodCollectedToast.replace("%NUM%",C.toString()),3e3):j.show(r.allFoodCollectedToast)}});return I(()=>{b()},[o.currentLevel,b]),I(()=>{let C,p=!document.hidden;const S=()=>{const z=l.current?.getContext("2d"),N=n.current;if(!(p&&N?.isGameActive&&z&&N?.maze)){C=requestAnimationFrame(S);return}T(),w(),C=requestAnimationFrame(S)},w=()=>{const z=l.current?.getContext("2d"),N=n.current;if(z&&N?.maze){const E=u.current?.wallWidth||c?.wallWidth,k=u.current?.exitColor||c?.exitColor,L=u.current?.exitWallWidth||c?.exitWallWidth,P=u.current?.exitDashArray||c?.exitDashArray;pt(z,N,f.current,g.current,{...c,wallWidth:E,exitColor:k,exitWallWidth:L,exitDashArray:P})}};h.current=w;const y=z=>{const N=p;p=!document.hidden&&document.visibilityState==="visible"&&(!z||z.type!=="blur"),!N&&p?n.current?.levelTransitioning===!1&&e({...n.current,isGameActive:!0}):N&&!p&&e({...n.current,isGameActive:!1})};return document.addEventListener("visibilitychange",y),window.addEventListener("blur",y),window.addEventListener("focus",y),C=requestAnimationFrame(S),()=>{cancelAnimationFrame(C),document.removeEventListener("visibilitychange",y),window.removeEventListener("blur",y),window.removeEventListener("focus",y)}},[]),I(()=>{j.show(r.useArrowKeyTips,3e3)},[]),m("div",{className:"maze-game-container",children:[m($t,{}),m(hn,{onRetry:v}),m("div",{className:"maze-canvas-container",ref:s,children:m("canvas",{ref:l,className:"maze-game-canvas"})})]})}const Nn=e=>{const t=Math.floor(e/60),n=e%60;return`${t.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`},Mn=({timer:e})=>{const[t,n]=U(e),o=x(),i=x(!1),s=x(0);return I(()=>{const l=()=>{!i.current&&!o.current&&(i.current=!0,o.current=setInterval(()=>{n(a=>(s.current=e-a+1,a<=1?(clearInterval(o.current),window.dispatchEvent(new CustomEvent("maze:timeUp")),0):a-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",l),window.addEventListener("maze:gameSuccess",r),()=>{window.removeEventListener("maze:firstMove",l),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]),m("div",{className:"single-maze-timer",children:m("span",{className:`maze-timer-text ${t<=10&&i.current?"maze-timer-warning":""}`,children:["⏱️ ",Nn(t)]})})};function An({config:e}){const{size:t,seed:n,method:o,foodCount:i,foodRace:s,clue:l,renderConfig:r,successCallback:a,failCallback:c,timer:d,i18n:u}=e,[h,f]=U({...Me}),[g,_]=U(!1),[v,T]=U(!0),[b,C]=U(!1),[p,S]=U(""),w=x(0),y=x(!1),z=x(!1),N=x(null),E=x(null),k=x(h),L=x(),P=mt(N,()=>{L.current?.()}),R=_t(N,h,r.padding);I(()=>{k.current=h},[h]);const{updatePlayerPos:O,resetMovingState:$,resetFirstMoveState:G}=vt({gamePlayStateRef:k,setGamePlayState:f,playerRadius:r.playerRadius,moveSpeed:r.gridMoveSpeed,onFoodCollected:()=>{console.log("Food collected in single maze")},onExitReached:()=>{if(!y.current){if(s&&k.current.foodCollected<k.current.totalFoodCount){S(`⭐️ ${u.foodMsg}`),C(!0),requestAnimationFrame(()=>{f(D=>({...D,playerAtExit:!1,isGameActive:!0,levelTransitioning:!1}))});return}B()}},onFirstMove:()=>{window.dispatchEvent(new CustomEvent("maze:firstMove"))}}),X=()=>{y.current=!0,S(`⏰ ${u.failMsg}`),C(!0),f({...k.current,isGameActive:!1})},B=()=>{y.current=!0,z.current=!0,S(`🎉 ${u.successMsg}`),C(!0),window.dispatchEvent(new CustomEvent("maze:gameSuccess"))},Z=()=>{C(!1),y.current&&(T(!1),f(D=>({...D,showClue:!0})),z.current?a?.(w.current):c?.())};return I(()=>{(async()=>{_(!0);try{const W=En({size:t,seed:n,method:o,foodCount:i,foodRace:s,clue:l});k.current=W,f(W)}catch(W){console.error("Error generating single maze:",W)}finally{_(!1)}})()},[e]),I(()=>{let D;const W=!document.hidden,Q=()=>{const Ce=N.current?.getContext("2d"),ie=k.current;if(!(W&&ie?.isGameActive&&Ce&&ie?.maze)){D=requestAnimationFrame(Q);return}O(),we(),D=requestAnimationFrame(Q)},we=()=>{const Ce=N.current?.getContext("2d"),ie=k.current;Ce&&ie?.maze&&pt(Ce,ie,P.current,R.current,r)};return L.current=we,D=requestAnimationFrame(Q),()=>{cancelAnimationFrame(D)}},[]),I(()=>{$(),G()},[e,$,G]),I(()=>{const D=W=>{w.current=W.detail.timeUsed};return window.addEventListener("maze:timeUsed",D),window.addEventListener("maze:timeUp",X),()=>{window.removeEventListener("maze:timeUsed",D),window.removeEventListener("maze:timeUp",X)}},[]),g?m("div",{className:"single-maze-loading",children:m("div",{children:"Generating maze..."})}):h?m("div",{className:"maze-game-container",children:[v&&m(Mn,{timer:d}),m("div",{className:"single-maze-canvas-container",ref:E,children:m("canvas",{ref:N,className:"maze-game-canvas"})}),m(re,{isOpen:b,title:p,noConfirm:!0,cancelText:"OK",onCancel:Z})]}):m("div",{className:"single-maze-error",children:m("div",{children:"Failed to generate maze"})})}const yt=[[{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"}]],bt={gridMoveSpeed:.07,padding:10,wallWidth:2,wallColor:"#000000",foodColor:"#4CAF50",clueColor:"rgb(255,0,0)",backgroundColor:"#ffffff",playerColor:"#4CAF50",playerRadius:.2,exitColor:"#F44336",exitWallWidth:4,exitDashArray:[8,12]},ge={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."},renderConfig:bt,levelConfig:yt},pe={i18n:{successMsg:"Congratulations! You completed the maze!",failMsg:"Time is up!",foodMsg:"Please collect all stars before leaving!"},size:8,seed:12345,method:"backtracking",clue:!1,foodCount:0,foodRace:!1,renderConfig:bt,timer:10*60,successCallback:()=>{console.log("🎉 Single maze completed successfully!")},failCallback:()=>{console.log("⏰ Time is up! Game failed.")}};function Pn({config:e={}}){const t={...ge.i18n,...e.i18n||{}},n={...ge.renderConfig,...e.renderConfig||{}},o=e.levelConfig||yt,i={...ge,...e,i18n:t,levelConfig:o,renderConfig:n};return m(Ft,{config:i,children:m(Ln,{})})}function In({config:e={}}){const t={...pe.i18n,...e.i18n||{}},n={...pe.renderConfig,...e.renderConfig||{}},o={...pe,...e,i18n:t,renderConfig:n};return m(An,{config:o})}const xn={root:"https://unpkg.com/@roudanio/maze@0.2.4/dist/",...ge};`${JSON.stringify(xn,null,2)}`;const Rn={root:"https://unpkg.com/@roudanio/maze@0.2.4/dist/",...pe};return`${JSON.stringify(Rn,(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 se,M,xe,V,Re,Fe,De,Oe,ye,be,Te,$e,ee={},Ue=[],Tt=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,le=Array.isArray;function H(e,t){for(var n in t)e[n]=t[n];return e}function ke(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function kt(e,t,n){var o,i,s,l={};for(s in t)s=="key"?o=t[s]:s=="ref"?i=t[s]:l[s]=t[s];if(arguments.length>2&&(l.children=arguments.length>3?se.call(arguments,2):n),typeof e=="function"&&e.defaultProps!=null)for(s in e.defaultProps)l[s]==null&&(l[s]=e.defaultProps[s]);return ae(e,l,o,i,null)}function ae(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??++xe,__i:-1,__u:0};return i==null&&M.vnode!=null&&M.vnode(s),s}function ce(e){return e.children}function ue(e,t){this.props=e,this.context=t}function Y(e,t){if(t==null)return e.__?Y(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"?Y(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 Se(e){(!e.__d&&(e.__d=!0)&&V.push(e)&&!de.__r++||Re!=M.debounceRendering)&&((Re=M.debounceRendering)||Fe)(de)}function de(){for(var e,t,n,o,i,s,l,r=1;V.length;)V.length>r&&V.sort(De),e=V.shift(),r=V.length,e.__d&&(n=void 0,i=(o=(t=e).__v).__e,s=[],l=[],t.__P&&((n=H({},o)).__v=o.__v+1,M.vnode&&M.vnode(n),ze(t.__P,n,o,t.__n,t.__P.namespaceURI,32&o.__u?[i]:null,s,i??Y(o),!!(32&o.__u),l),n.__v=o.__v,n.__.__k[n.__i]=n,Be(s,n,l),n.__e!=i&&Ge(n)));de.__r=0}function We(e,t,n,o,i,s,l,r,a,c,d){var u,h,f,g,_,v,T=o&&o.__k||Ue,b=t.length;for(a=St(n,t,T,a,b),u=0;u<b;u++)(f=n.__k[u])!=null&&(h=f.__i==-1?ee:T[f.__i]||ee,f.__i=u,v=ze(e,f,h,i,s,l,r,a,c,d),g=f.__e,f.ref&&h.ref!=f.ref&&(h.ref&&Ee(h.ref,null,f),d.push(f.ref,f.__c||g,f)),_==null&&g!=null&&(_=g),4&f.__u||h.__k===f.__k?a=je(f,a,e):typeof f.type=="function"&&v!==void 0?a=v:g&&(a=g.nextSibling),f.__u&=-7);return n.__e=_,a}function St(e,t,n,o,i){var s,l,r,a,c,d=n.length,u=d,h=0;for(e.__k=new Array(i),s=0;s<i;s++)(l=t[s])!=null&&typeof l!="boolean"&&typeof l!="function"?(a=s+h,(l=e.__k[s]=typeof l=="string"||typeof l=="number"||typeof l=="bigint"||l.constructor==String?ae(null,l,null,null,null):le(l)?ae(ce,{children:l},null,null,null):l.constructor==null&&l.__b>0?ae(l.type,l.props,l.key,l.ref?l.ref:null,l.__v):l).__=e,l.__b=e.__b+1,r=null,(c=l.__i=zt(l,n,a,u))!=-1&&(u--,(r=n[c])&&(r.__u|=2)),r==null||r.__v==null?(c==-1&&(i>d?h--:i<d&&h++),typeof l.type!="function"&&(l.__u|=4)):c!=a&&(c==a-1?h--:c==a+1?h++:(c>a?h--:h++,l.__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=Y(r)),Xe(r,r));return o}function je(e,t,n){var o,i;if(typeof e.type=="function"){for(o=e.__k,i=0;o&&i<o.length;i++)o[i]&&(o[i].__=e,t=je(o[i],t,n));return t}e.__e!=t&&(t&&e.type&&!n.contains(t)&&(t=Y(e)),n.insertBefore(e.__e,t||null),t=e.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function zt(e,t,n,o){var i,s,l=e.key,r=e.type,a=t[n];if(a===null&&e.key==null||a&&l==a.key&&r==a.type&&(2&a.__u)==0)return n;if(o>(a!=null&&(2&a.__u)==0?1:0))for(i=n-1,s=n+1;i>=0||s<t.length;){if(i>=0){if((a=t[i])&&(2&a.__u)==0&&l==a.key&&r==a.type)return i;i--}if(s<t.length){if((a=t[s])&&(2&a.__u)==0&&l==a.key&&r==a.type)return s;s++}}return-1}function qe(e,t,n){t[0]=="-"?e.setProperty(t,n??""):e[t]=n==null?"":typeof n!="number"||Tt.test(t)?n:n+"px"}function he(e,t,n,o,i){var s;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")),t=t.toLowerCase()in e||t=="onFocusOut"||t=="onFocusIn"?t.toLowerCase().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 He(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(M.event?M.event(t):t)}}}function ze(e,t,n,o,i,s,l,r,a,c){var d,u,h,f,g,_,v,T,b,C,p,S,w,y,z,N,E,k=t.type;if(t.constructor!=null)return null;128&n.__u&&(a=!!(32&n.__u),s=[r=t.__e=n.__e]),(d=M.__b)&&d(t);e:if(typeof k=="function")try{if(T=t.props,b="prototype"in k&&k.prototype.render,C=(d=k.contextType)&&o[d.__c],p=d?C?C.props.value:d.__:o,n.__c?v=(u=t.__c=n.__c).__=u.__E:(b?t.__c=u=new k(T,p):(t.__c=u=new ue(T,p),u.constructor=k,u.render=Lt),C&&C.sub(u),u.props=T,u.state||(u.state={}),u.context=p,u.__n=o,h=u.__d=!0,u.__h=[],u._sb=[]),b&&u.__s==null&&(u.__s=u.state),b&&k.getDerivedStateFromProps!=null&&(u.__s==u.state&&(u.__s=H({},u.__s)),H(u.__s,k.getDerivedStateFromProps(T,u.__s))),f=u.props,g=u.state,u.__v=t,h)b&&k.getDerivedStateFromProps==null&&u.componentWillMount!=null&&u.componentWillMount(),b&&u.componentDidMount!=null&&u.__h.push(u.componentDidMount);else{if(b&&k.getDerivedStateFromProps==null&&T!==f&&u.componentWillReceiveProps!=null&&u.componentWillReceiveProps(T,p),!u.__e&&u.shouldComponentUpdate!=null&&u.shouldComponentUpdate(T,u.__s,p)===!1||t.__v==n.__v){for(t.__v!=n.__v&&(u.props=T,u.state=u.__s,u.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(L){L&&(L.__=t)}),S=0;S<u._sb.length;S++)u.__h.push(u._sb[S]);u._sb=[],u.__h.length&&l.push(u);break e}u.componentWillUpdate!=null&&u.componentWillUpdate(T,u.__s,p),b&&u.componentDidUpdate!=null&&u.__h.push(function(){u.componentDidUpdate(f,g,_)})}if(u.context=p,u.props=T,u.__P=e,u.__e=!1,w=M.__r,y=0,b){for(u.state=u.__s,u.__d=!1,w&&w(t),d=u.render(u.props,u.state,u.context),z=0;z<u._sb.length;z++)u.__h.push(u._sb[z]);u._sb=[]}else do u.__d=!1,w&&w(t),d=u.render(u.props,u.state,u.context),u.state=u.__s;while(u.__d&&++y<25);u.state=u.__s,u.getChildContext!=null&&(o=H(H({},o),u.getChildContext())),b&&!h&&u.getSnapshotBeforeUpdate!=null&&(_=u.getSnapshotBeforeUpdate(f,g)),N=d,d!=null&&d.type===ce&&d.key==null&&(N=Ve(d.props.children)),r=We(e,le(N)?N:[N],t,n,o,i,s,l,r,a,c),u.base=t.__e,t.__u&=-161,u.__h.length&&l.push(u),v&&(u.__E=u.__=null)}catch(L){if(t.__v=null,a||s!=null)if(L.then){for(t.__u|=a?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--;)ke(s[E]);else t.__e=n.__e,t.__k=n.__k;M.__e(L,t,n)}else s==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):r=t.__e=Et(n.__e,t,n,o,i,s,l,a,c);return(d=M.diffed)&&d(t),128&t.__u?void 0:r}function Be(e,t,n){for(var o=0;o<n.length;o++)Ee(n[o],n[++o],n[++o]);M.__c&&M.__c(t,e),e.some(function(i){try{e=i.__h,i.__h=[],e.some(function(s){s.call(i)})}catch(s){M.__e(s,i.__v)}})}function Ve(e){return typeof e!="object"||e==null||e.__b&&e.__b>0?e:le(e)?e.map(Ve):H({},e)}function Et(e,t,n,o,i,s,l,r,a){var c,d,u,h,f,g,_,v=n.props,T=t.props,b=t.type;if(b=="svg"?i="http://www.w3.org/2000/svg":b=="math"?i="http://www.w3.org/1998/Math/MathML":i||(i="http://www.w3.org/1999/xhtml"),s!=null){for(c=0;c<s.length;c++)if((f=s[c])&&"setAttribute"in f==!!b&&(b?f.localName==b:f.nodeType==3)){e=f,s[c]=null;break}}if(e==null){if(b==null)return document.createTextNode(T);e=document.createElementNS(i,b,T.is&&T),r&&(M.__m&&M.__m(t,s),r=!1),s=null}if(b==null)v===T||r&&e.data==T||(e.data=T);else{if(s=s&&se.call(e.childNodes),v=n.props||ee,!r&&s!=null)for(v={},c=0;c<e.attributes.length;c++)v[(f=e.attributes[c]).name]=f.value;for(c in v)if(f=v[c],c!="children"){if(c=="dangerouslySetInnerHTML")u=f;else if(!(c in T)){if(c=="value"&&"defaultValue"in T||c=="checked"&&"defaultChecked"in T)continue;he(e,c,null,f,i)}}for(c in T)f=T[c],c=="children"?h=f:c=="dangerouslySetInnerHTML"?d=f:c=="value"?g=f:c=="checked"?_=f:r&&typeof f!="function"||v[c]===f||he(e,c,f,v[c],i);if(d)r||u&&(d.__html==u.__html||d.__html==e.innerHTML)||(e.innerHTML=d.__html),t.__k=[];else if(u&&(e.innerHTML=""),We(t.type=="template"?e.content:e,le(h)?h:[h],t,n,o,b=="foreignObject"?"http://www.w3.org/1999/xhtml":i,s,l,s?s[0]:n.__k&&Y(n,0),r,a),s!=null)for(c=s.length;c--;)ke(s[c]);r||(c="value",b=="progress"&&g==null?e.removeAttribute("value"):g!=null&&(g!==e[c]||b=="progress"&&!g||b=="option"&&g!=v[c])&&he(e,c,g,v[c],i),c="checked",_!=null&&_!=e[c]&&he(e,c,_,v[c],i))}return e}function Ee(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){M.__e(i,n)}}function Xe(e,t,n){var o,i;if(M.unmount&&M.unmount(e),(o=e.ref)&&(o.current&&o.current!=e.__e||Ee(o,null,t)),(o=e.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(s){M.__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||ke(e.__e),e.__c=e.__=e.__e=void 0}function Lt(e,t,n){return this.constructor(e,n)}function Ye(e,t,n){var o,i,s,l;t==document&&(t=document.documentElement),M.__&&M.__(e,t),i=(o=!1)?null:t.__k,s=[],l=[],ze(t,e=t.__k=kt(ce,null,[e]),i||ee,ee,t.namespaceURI,i?null:t.firstChild?se.call(t.childNodes):null,s,i?i.__e:t.firstChild,o,l),Be(s,e,l)}function Nt(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(l){l.__e=!0,Se(l)})},this.sub=function(s){o.add(s);var l=s.componentWillUnmount;s.componentWillUnmount=function(){o&&o.delete(s),l&&l.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}se=Ue.slice,M={__e:function(e,t,n,o){for(var i,s,l;t=t.__;)if((i=t.__c)&&!i.__)try{if((s=i.constructor)&&s.getDerivedStateFromError!=null&&(i.setState(s.getDerivedStateFromError(e)),l=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(e,o||{}),l=i.__d),l)return i.__E=i}catch(r){e=r}throw e}},xe=0,ue.prototype.setState=function(e,t){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=H({},this.state),typeof e=="function"&&(e=e(H({},n),this.props)),e&&H(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),Se(this))},ue.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),Se(this))},ue.prototype.render=ce,V=[],Fe=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,De=function(e,t){return e.__v.__b-t.__v.__b},de.__r=0,Oe=/(PointerCapture)$|Capture$/i,ye=0,be=He(!1),Te=He(!0),$e=0;var Mt=0;function m(e,t,n,o,i,s){t||(t={});var l,r,a=t;if("ref"in a)for(r in a={},t)r=="ref"?l=t[r]:a[r]=t[r];var c={type:e,props:a,key:n,ref:l,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Mt,__i:-1,__u:0,__source:i,__self:s};if(typeof e=="function"&&(l=e.defaultProps))for(r in l)a[r]===void 0&&(a[r]=l[r]);return M.vnode&&M.vnode(c),c}var K,P,Le,Ke,te=0,Je=[],D=M,Ze=D.__b,Qe=D.__r,et=D.diffed,tt=D.__c,nt=D.unmount,ot=D.__;function fe(e,t){D.__h&&D.__h(P,e,te||t),te=0;var n=P.__H||(P.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function U(e){return te=1,At(lt,e)}function At(e,t,n){var o=fe(K++,2);if(o.t=e,!o.__c&&(o.__=[lt(void 0,t),function(r){var a=o.__N?o.__N[0]:o.__[0],c=o.t(a,r);a!==c&&(o.__N=[c,o.__[1]],o.__c.setState({}))}],o.__c=P,!P.__f)){var i=function(r,a,c){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,a,c);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,a,c)||u};P.__f=!0;var s=P.shouldComponentUpdate,l=P.componentWillUpdate;P.componentWillUpdate=function(r,a,c){if(this.__e){var d=s;s=void 0,i(r,a,c),s=d}l&&l.call(this,r,a,c)},P.shouldComponentUpdate=i}return o.__N||o.__}function x(e,t){var n=fe(K++,3);!D.__s&&st(n.__H,t)&&(n.__=e,n.u=t,P.__H.__h.push(n))}function R(e){return te=5,J(function(){return{current:e}},[])}function J(e,t){var n=fe(K++,7);return st(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function rt(e,t){return te=8,J(function(){return e},t)}function Pt(e){var t=P.context[e.__c],n=fe(K++,9);return n.c=e,t?(n.__==null&&(n.__=!0,t.sub(P)),t.props.value):e.__}function It(){for(var e;e=Je.shift();)if(e.__P&&e.__H)try{e.__H.__h.forEach(me),e.__H.__h.forEach(Ne),e.__H.__h=[]}catch(t){e.__H.__h=[],D.__e(t,e.__v)}}D.__b=function(e){P=null,Ze&&Ze(e)},D.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),ot&&ot(e,t)},D.__r=function(e){Qe&&Qe(e),K=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(me),t.__h.forEach(Ne),t.__h=[],K=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)||xt)(It)),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(me),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{me(o)}catch(i){t=i}}),n.__H=void 0,t&&D.__e(t,n.__v))};var it=typeof requestAnimationFrame=="function";function xt(e){var t,n=function(){clearTimeout(o),it&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(n,100);it&&(t=requestAnimationFrame(n))}function me(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 lt(e,t){return typeof t=="function"?t(e):t}const Rt=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)}}}),at=Nt(void 0),ct={currentLevel:1,highestUnlockedLevel:1,currentTier:1,highestUnlockedTier:1,levelScores:{},totalScore:0},Me={isGameActive:!0,levelTransitioning:!1,maze:null,playerCell:{row:0,col:0},exitCell:{row:0,col:0},foodCells:[],playerAtExit:!1,foodCollected:0,totalFoodCount:0,showClue:!1,playerPath:[],visitCounts:{}},Ft=({children:e,config:t})=>{const n=Rt(t.lcPrefix+"progress"),o=n.loadGameData(),[i,s]=U(()=>o||{...ct});x(()=>{const u=Object.values(i.levelScores).reduce((h,f)=>h+f,0);s(h=>({...h,totalScore:u}))},[i.levelScores]),x(()=>{n.saveGameData(i)},[i.currentLevel,i.highestUnlockedLevel,i.currentTier,i.highestUnlockedTier,i.levelScores,i.totalScore]);const[l,r]=U({...Me}),a=R(l);x(()=>{a.current=l},[l]);const c=J(()=>[l.playerAtExit?1:0,l.foodCollected===l.totalFoodCount?1:0,l.showClue?0:1],[l.playerAtExit,l.foodCollected,l.totalFoodCount,l.showClue]),d=()=>{n.resetGameData(),s({...ct}),r({...Me})};return m(at.Provider,{value:{gameProgress:i,setGameProgress:s,gamePlayState:l,setGamePlayState:r,gamePlayStateRef:a,currentScore:c,config:t,resetGame:d},children:e})},ne=()=>{const e=Pt(at);if(!e)throw new Error("useGameContext must be used within a GameProvider");return e},oe=e=>J(()=>{const t=e.map(r=>r.length),n=t.reduce((r,a)=>r+a,0),o=e.length,i=r=>{if(r<1||r>n)return 0;let a=0;for(let c=0;c<t.length;c++)if(a+=t[c],r<=a)return c+1;return 0},s=r=>r<1||r>o?0:t.slice(0,r-1).reduce((a,c)=>a+c,0)+1,l={getTotalLevels:()=>n,getTotalTiers:()=>o,getTierLevelsRange:r=>{if(r<1||r>o)return[0,0];const a=s(r),c=a+t[r-1]-1;return[a,c]},getTierByLevel:i,getFirstLevelOfTier:s,getLevelConfig:r=>{if(r<1||r>n)return null;const a=i(r),c=s(a),d=r-c;return e[a-1][d]},getTierConfig:r=>r<1||r>o?null:e[r-1],isLevelUnlocked:(r,a)=>r<=a,isTierUnlocked:(r,a)=>r<=a,getNextLevelInfo:r=>{if(r>=n)return null;const a=r+1,c=i(r),d=i(a);return{nextLevel:a,nextTier:d,isTierChange:d>c}},getCurrentTierProgress:(r,a)=>{const[c,d]=l.getTierLevelsRange(a),u=r-c+1,h=d-c+1;return{current:u,total:h}},isLastLevelInTier:r=>{const a=i(r),[,c]=l.getTierLevelsRange(a);return r===c},getPreviousLevelInfo:r=>{if(r<=1)return null;const a=r-1,c=i(r),d=i(a);return{prevLevel:a,prevTier:d,isTierChange:d<c}}};return l},[e]),Dt=({onTierChange:e,disabled:t})=>{const{gameProgress:n,config:o}=ne(),{i18n:i,levelConfig:s}=o,{currentTier:l,highestUnlockedTier:r}=n,c=oe(s).getTotalTiers();return m("div",{className:"tier-selector",children:m("select",{value:l,onChange:d=>{d.target&&d.target.value&&e(Number(d.target.value))},disabled:t,className:"tier-dropdown",children:Array.from({length:c},(d,u)=>u+1).map(d=>m("option",{value:d,disabled:d>r,children:i.tier+" "+d},`tier-${d}`))})})},Ot=({onLevelChange:e,disabled:t})=>{const{gameProgress:n,config:o}=ne(),{i18n:i,levelConfig:s}=o,{currentTier:l,levelScores:r,currentLevel:a,highestUnlockedLevel:c}=n,d=oe(s),u=J(()=>{const[h,f]=d.getTierLevelsRange(l);return Array.from({length:f-h+1},(g,_)=>{const v=h+_,T=r[v]||0;return{level:v,score:T}})},[l,r]);return m("div",{className:"level-selector",children:m("select",{value:a,onChange:h=>{h.target&&h.target.value&&e(Number(h.target.value))},disabled:t,className:"level-dropdown",children:u.map(({level:h,score:f})=>m("option",{value:h,disabled:h>c,children:`${i.level} ${h} ${"★".repeat(f)}`},`level-${h}`))})})},re=({isOpen:e,title:t,className:n="",message:o,children:i,noConfirm:s=!1,noCancel:l=!1,confirmText:r="OK",cancelText:a="Cancel",confirmClass:c="",cancelClass:d="",onConfirm:u,onCancel:h})=>{const f=R(null);return x(()=>{const g=_=>{_.key==="Escape"&&h?.()};return e&&document.addEventListener("keydown",g),()=>{document.removeEventListener("keydown",g)}},[e,h]),m("div",{className:`maze-dialog-overlay ${e?"maze-dialog-visible":""}`,children:m("div",{className:"maze-dialog "+n,ref:f,children:[m("div",{className:"maze-dialog-title",children:t}),m("div",{className:"maze-dialog-content",children:i||m("div",{className:"maze-dialog-message",children:o})}),(!l||!s)&&m("div",{className:"maze-dialog-buttons",children:[!l&&m("button",{type:"button",className:"maze-dialog-cancel "+d,onClick:h,children:a}),!s&&m("button",{type:"button",className:"maze-dialog-confirm "+c,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)}},$t=()=>{const{gameProgress:e,setGameProgress:t,gamePlayState:n,setGamePlayState:o,gamePlayStateRef:i,resetGame:s,config:l}=ne(),{i18n:r,levelConfig:a}=l,c=oe(a),{levelTransitioning:d,showClue:u}=n,{highestUnlockedLevel:h,totalScore:f}=e,g=c.getTotalLevels(),[_,v]=U(!1),[T,b]=U(!1),[C,p]=U(!1),S=O=>{const $=c.getFirstLevelOfTier(O);c.isLevelUnlocked($,h)&&(t(G=>({...G,currentTier:O})),w($))},w=O=>{c.isLevelUnlocked(O,h)&&(t($=>({...$,currentLevel:O})),j.show(r.levelGoToast.replace("%LEVEL%",O.toString())))},y=()=>{v(!0)},z=()=>{v(!1)},N=()=>{p(!0)},E=()=>{p(!1)},k=()=>{j.show(u?r.cluePathDisabled:r.cluePathEnabled),o(()=>({...i.current,showClue:!i.current.showClue})),p(!1)},L=()=>{b(!0)},I=()=>{s(),b(!1),j.show(r.resetDoneToast)},F=()=>{b(!1)};return m("div",{class:"game-panel-container",children:[m("div",{className:"game-controls",children:[m("div",{className:"selectors-container",children:[m(Dt,{onTierChange:S,disabled:d}),m(Ot,{onLevelChange:w,disabled:d})]}),m("button",{className:`settings-clue-button ${u?"clue-on":"clue-off"}`,disabled:u,title:"Toggle Clue",onClick:N,children:u?r.clueOn:r.clueOff})]}),m("div",{className:"game-settings",children:m("span",{className:"game-settings-icon",onClick:y,children:"★ "+f})}),m(re,{isOpen:_,title:r.settings,noConfirm:!0,cancelText:r.close,onCancel:z,children:[m("div",{className:"settings-stats",children:[m("div",{children:r.levelComplete+`: ${h}/${g}`}),m("div",{children:r.starsCollected+": "+f}),m("div",{children:r.avgStarPerLevel+": "+(f/h).toFixed(2)})]}),m("div",{className:"settings-item-box",children:[m("button",{className:"settings-reset-button",title:"Reset Game",onClick:L,children:r.reset}),m("div",{className:"settings-item-tip",children:r.resetTip})]})]}),m(re,{isOpen:T,title:r.confirmReset,message:r.confirmResetMessage,confirmText:r.reset,cancelText:r.cancel,onConfirm:I,onCancel:F}),m(re,{isOpen:C,title:r.confirmClue,message:r.confirmClueMessage,confirmText:r.confirm,cancelText:r.cancel,onConfirm:k,onCancel:E})]})};function Ae(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Ut(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&&Ut(e.prototype,t),e}function ut(e){return+e.replace(/px/,"")}function Gt(e){var t=window.devicePixelRatio,n=getComputedStyle(e),o=ut(n.getPropertyValue("width")),i=ut(n.getPropertyValue("height"));e.setAttribute("width",(o*t).toString()),e.setAttribute("height",(i*t).toString())}function q(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 dt(e){return e[q(0,e.length)]}var Wt=.00125,jt=5e-4,qt=9e-4,Ht=1e-5,Bt=6,Vt=80,Xt=.9,Yt=1.7,Kt=.2,Jt=.6,Zt=.03,Qt=.07,en=15,tn=82,nn=100,on=250,rn=40,sn=["#fcf403","#62fc03","#f4fc03","#03e7fc","#03fca5","#a503fc","#fc03ad","#fc03c2"];function ht(e){var t=1920;return Math.log(e)/Math.log(t)}var ft=function(){function e(t){Ae(this,e);var n=t.initialPosition,o=t.direction,i=t.confettiRadius,s=t.confettiColors,l=t.emojis,r=t.emojiSize,a=t.canvasWidth,c=q(Xt,Yt,3),d=c*ht(a);this.confettiSpeed={x:d,y:d},this.finalConfettiSpeedX=q(Kt,Jt,3),this.rotationSpeed=l.length?.01:q(Zt,Qt,3)*ht(a),this.dragForceCoefficient=q(jt,qt,6),this.radius={x:i,y:i},this.initialRadius=i,this.rotationAngle=o==="left"?q(0,.2,3):q(-.2,0,3),this.emojiSize=r,this.emojiRotationAngle=q(0,2*Math.PI),this.radiusYUpdateDirection="down";var u=o==="left"?q(tn,en)*Math.PI/180:q(-15,-82)*Math.PI/180;this.absCos=Math.abs(Math.cos(u)),this.absSin=Math.abs(Math.sin(u));var h=q(-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=l.length?null:dt(s),this.emoji=l.length?dt(l):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,l=this.emoji,r=this.rotationAngle,a=this.emojiRotationAngle,c=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()):l&&(n.font="".concat(c,"px serif"),n.save(),n.translate(d*o.x,d*o.y),n.rotate(a),n.textAlign="center",n.fillText(l,0,0),n.restore())}},{key:"updatePosition",value:function(n,o){var i=this.confettiSpeed,s=this.dragForceCoefficient,l=this.finalConfettiSpeedX,r=this.radiusYUpdateDirection,a=this.rotationSpeed,c=this.createdAt,d=this.direction,u=o-c;if(i.x>l&&(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+Wt*Math.pow(u,2)/2,this.rotationSpeed-=this.emoji?1e-4:Ht*n,this.rotationSpeed<0&&(this.rotationSpeed=0),this.emoji){this.emojiRotationAngle+=this.rotationSpeed*n%(2*Math.PI);return}r==="down"?(this.radius.y-=n*a,this.radius.y<=0&&(this.radius.y=0,this.radiusYUpdateDirection="up")):(this.radius.y+=n*a,this.radius.y>=this.initialRadius&&(this.radius.y=this.initialRadius,this.radiusYUpdateDirection="down"))}},{key:"getIsVisibleOnCanvas",value:function(n){return this.currentPosition.y<n+nn}}]),e}();function ln(){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 an(e){var t=e.confettiRadius,n=t===void 0?Bt:t,o=e.confettiNumber,i=o===void 0?e.confettiesNumber||(e.emojis?rn:on):o,s=e.confettiColors,l=s===void 0?sn:s,r=e.emojis,a=r===void 0?e.emojies||[]:r,c=e.emojiSize,d=c===void 0?Vt:c;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:l,emojis:a,emojiSize:d}}var cn=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,l=n.timeDelta,r=n.currentTime;this.shapes=this.shapes.filter(function(a){return a.updatePosition(l,r),a.draw(s.canvasContext),i?a.getIsVisibleOnCanvas(o):!0})}}]),e}(),un=function(){function e(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Ae(this,e),this.activeConfettiBatches=[],this.canvas=t.canvas||ln(),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,Gt(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(l){return l.processShapes({timeDelta:o,currentTime:n},i,s),s?!l.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=an(n),i=o.confettiRadius,s=o.confettiNumber,l=o.confettiColors,r=o.emojis,a=o.emojiSize,c=this.canvas.getBoundingClientRect(),d=c.width,u=c.height,h=u*5/7,f={x:0,y:h},g={x:d,y:h},_=new cn(this.canvasContext),v=0;v<s/2;v++){var T=new ft({initialPosition:f,direction:"right",confettiRadius:i,confettiColors:l,confettiNumber:s,emojis:r,emojiSize:a,canvasWidth:d}),b=new ft({initialPosition:g,direction:"left",confettiRadius:i,confettiColors:l,confettiNumber:s,emojis:r,emojiSize:a,canvasWidth:d});_.addShapes(T,b)}return this.activeConfettiBatches.push(_),this.queueAnimationFrameIfNeeded(),_.getBatchCompletePromise()}},{key:"clearCanvas",value:function(){this.activeConfettiBatches=[]}},{key:"destroyCanvas",value:function(){this.canvas.remove()}}]),e}();const dn=new un,Ie=3,hn=({onRetry:e})=>{const{config:t,currentScore:n,gamePlayState:o,setGamePlayState:i,gameProgress:s,setGameProgress:l}=ne(),{i18n:r,levelConfig:a}=t,[c,d,u]=n,{foodCollected:h,totalFoodCount:f,playerAtExit:g,levelTransitioning:_}=o,{currentLevel:v}=s,[T,b]=U(!1);x(()=>{g&&_&&(dn.addConfetti(),j.show(r.levelCompleteToast),b(!0))},[g,_]);const C=oe(a),p=C.getTotalLevels(),S=J(()=>v>=p,[v,p]),w=()=>{b(!1),j.show(r.levelRestartToast),e?.()},y=()=>{b(!1),i(E=>({...E,isGameActive:!0,levelTransitioning:!1}))},z=()=>{b(!1);const E=C.getNextLevelInfo(v);if(!E)return;const{nextLevel:k,nextTier:L,isTierChange:I}=E;I&&j.show(r.tierUnlockedToast.replace("%TIER%",L.toString())),l(F=>({...F,currentLevel:k,currentTier:L,highestUnlockedLevel:Math.max(F.highestUnlockedLevel,k),highestUnlockedTier:Math.max(F.highestUnlockedTier,L),levelScores:{...F.levelScores,[F.currentLevel]:Math.max(Object.values(n).filter(Boolean).length,F.levelScores[F.currentLevel]||0)}}))},N=()=>{b(!1),l(E=>{const k=Math.max(Object.values(n).filter(Boolean).length,E.levelScores[E.currentLevel]||0),L={...E.levelScores,[E.currentLevel]:k};let I=0,F=0;const O=Object.entries(L).sort(($,G)=>Number($[0])-Number(G[0]));for(const[$,G]of O)if(G<Ie){I=Number($),F=C.getTierByLevel(I);break}return(I>0&&I!==v||k<Ie)&&j.show(r.notCompleteLevel),(I===0||k<Ie)&&e?.(),{...E,currentLevel:I||E.currentLevel,currentTier:F||E.currentTier,levelScores:L}})};return x(()=>{const E=document.querySelector(".maze-game-container"),k=L=>{T&&((L.key===" "||L.code==="Space")&&E&&(E.contains(document.activeElement)||document.activeElement===document.body)&&(L.preventDefault(),S?N():z()),(L.key==="r"||L.code==="KeyR")&&w(),(L.key==="c"||L.code==="KeyC")&&y())};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[T,S]),m(re,{className:"level-complete-dialog",isOpen:T,title:r.congratulations,cancelText:r.retry+" (R)",onCancel:w,noConfirm:!!d,confirmText:r.continue+" (C)",onConfirm:y,confirmClass:"maze-continue-btn",children:[m("div",{className:"maze-summary-message",children:[!!c&&m("div",{children:"★ - "+r.findYourExit}),m("div",{children:u?"★ - "+r.withoutClue:"☆ - "+r.withClue}),m("div",{children:(d?"★ - "+r.collectAllStars:"☆ - "+r.notCollectAllStars)+` (${h}/${f})`})]}),S&&m("div",{className:"all-levels-completed",children:r.allLevelsCompleted}),m("div",{className:"maze-go-next",children:S?m("button",{className:"maze-go-next-btn",type:"button",onClick:N,children:[m("span",{children:r.lastOK}),m("span",{className:"spacebar-tip",children:`(${r.spacebarTip})`})]}):m("button",{className:"maze-go-next-btn",type:"button",onClick:z,children:[m("span",{children:r.nextLevel}),m("span",{className:"spacebar-tip",children:`(${r.spacebarTip})`})]})}),!d&&m("div",{className:"not-all-stars-collected",children:r.continueMessage})]})},mt=(e,t)=>{const n=R({canvasWidth:0,canvasHeight:0});return x(()=>{const o=()=>{const s=e.current;if(!s)return;const l=s.parentElement;if(!l)return;const r=l.clientWidth;if(r===0)return;const a=window.devicePixelRatio||1;s.style.width=`${r}px`,s.style.height=`${r}px`;const c=r*a,d=r*a;s.width=c,s.height=d,n.current={canvasWidth:c,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},_t=(e,t,n)=>{const o=R({cellWidth:0,cellHeight:0});return x(()=>{const i=()=>{const l=e.current,r=t.maze;if(!l||!r)return;const{rows:a,cols:c}=r;if(a<=0||c<=0)return;const d=(l.width-n*2)/c,u=(l.height-n*2)/a;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},_e={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]},vt=({gamePlayStateRef:e,setGamePlayState:t,moveSpeed:n,moveSpeedRef:o,playerRadius:i,onFoodCollected:s,onExitReached:l,onFirstMove:r})=>{const a=()=>o?.current??n??.03,c=R(!1),d=R(new Set),u=R(!1),h=rt((C,p)=>{const S=e.current;if(!S.maze)return{canMove:!1,newCell:null};const w=a(),[y,z]=_e[C];if(gt(p,y,z,i,w,S.maze))return{canMove:!1,newCell:null};const{row:E,col:k}=p,L=E+y*w,I=k+z*w,F=-.5,O=S.maze.rows,$=S.maze.cols;if(L<F||L>=O||I<F||I>=$)return{canMove:!1,newCell:null};const G=E<0?0:Math.floor(E),X=k<0?0:Math.floor(k),B=L<0?0:Math.floor(L),Z=I<0?0:Math.floor(I);return B!==G||Z!==X?S.maze.isValid(B,Z)?{canMove:!0,newCell:{row:B,col:Z}}:{canMove:!1,newCell:null}:{canMove:!0,newCell:null}},[i,a]),f=()=>{const C=e.current,{row:p,col:S}=C.playerCell,w=i*2,y=C.foodCells.findIndex(E=>Math.sqrt(Math.pow(p-E.row,2)+Math.pow(S-E.col,2))<w);y!==-1&&s&&(s(),e.current={...e.current,foodCollected:e.current.foodCollected+1,foodCells:e.current.foodCells.filter((E,k)=>k!==y)});const N=_n(C.playerCell,C.exitCell,C.maze);N&&!e.current.playerAtExit?(e.current={...e.current,playerAtExit:!0,isGameActive:!1,levelTransitioning:!0},l&&l(),requestIdleCallback(()=>{t(()=>({...e.current}))},{timeout:10})):!N&&e.current.playerAtExit&&(e.current={...e.current,playerAtExit:!1,isGameActive:!0,levelTransitioning:!1})},g=C=>{const p=e.current,S=Math.round(C.row),w=Math.round(C.col),y=p.playerPath[p.playerPath.length-1],z=y.row===S&&y.col===w,N=Math.abs(y.row-S),E=Math.abs(y.col-w);if((N===1&&E===0||N===0&&E===1)&&!z){const L=`${y.row},${y.col}-${S},${w}`;e.current={...e.current,playerPath:[...e.current.playerPath,{row:S,col:w}],visitCounts:{...e.current.visitCounts,[L]:(e.current.visitCounts[L]||0)+1}}}},_=()=>{if(c.current||d.current.size===0)return;const C=e.current;!C.playerCell||!Array.from(d.current).some(S=>{const{canMove:w}=h(S,C.playerCell);return w})||(!u.current&&r&&(u.current=!0,r()),c.current=!0)};x(()=>{const C=w=>{if(w.key==="ArrowUp"||w.key==="ArrowDown"||w.key==="ArrowLeft"||w.key==="ArrowRight"||w.key===" "){const y=document.activeElement;if(y&&(y.tagName==="INPUT"||y.tagName==="TEXTAREA"||y.getAttribute("contenteditable")==="true"))return;w.preventDefault()}},p=w=>{const y=w.key;if(!(y in _e))return;const z=document.activeElement;z&&(z.tagName==="INPUT"||z.tagName==="TEXTAREA"||z.getAttribute("contenteditable")==="true")||(w.preventDefault(),e.current.isGameActive&&(d.current.has(y)||(d.current.add(y),c.current||_())))},S=w=>{const y=w.key;if(!(y in _e))return;const z=document.activeElement;z&&(z.tagName==="INPUT"||z.tagName==="TEXTAREA"||z.getAttribute("contenteditable")==="true")||(w.preventDefault(),d.current.delete(y),d.current.size===0&&T())};return window.addEventListener("keydown",C,{capture:!0}),window.addEventListener("keydown",p),window.addEventListener("keyup",S),()=>{window.removeEventListener("keydown",C,{capture:!0}),window.removeEventListener("keydown",p),window.removeEventListener("keyup",S)}},[]);const v=rt(()=>{if(!c.current||d.current.size===0)return e.current.playerCell;const C=a(),p=e.current.playerCell;let S=0,w=0,y=0;for(const A of d.current){const{canMove:W}=h(A,p);if(W){const[Q,we]=_e[A];S+=Q,w+=we,y++}}if(y===0)return e.current.playerCell;const z=Math.sqrt(S*S+w*w),N=z>0?S/z:0,E=z>0?w/z:0,k=Number((p.row+N*C).toFixed(2)),L=Number((p.col+E*C).toFixed(2)),I=k-p.row,F=L-p.col,O=Math.sqrt(I*I+F*F);if(O>0){const A=I/O,W=F/O;if(gt(p,A,W,i,O,e.current.maze))return e.current.playerCell}e.current.playerCell={row:k,col:L},f();const $=p.row<0?0:Math.round(p.row),G=p.col<0?0:Math.round(p.col),X=k<0?0:Math.round(k),B=L<0?0:Math.round(L);return(X!==$||B!==G)&&g({row:X,col:B}),e.current.playerCell},[a,h]),T=()=>{c.current=!1,d.current.clear()};return{updatePlayerPos:v,resetMovingState:T,resetFirstMoveState:()=>{u.current=!1}}};function gt(e,t,n,o,i,s){const l=e.row+t*i,r=e.col+n*i,a={row:l,col:r},c=[],d=e.row<0?0:Math.floor(e.row),u=e.col<0?0:Math.floor(e.col);c.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,g]of h){const _=d+f,v=u+g;s.isValid(_,v)&&c.push({row:_,col:v})}for(const f of c){const g=fn(f.row,f.col,s);for(const _ of g)if(mn(a,_)<o)return!0}return!1}function fn(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 mn(e,t){const{start:n,end:o}=t,i=o.col-n.col,s=o.row-n.row,l=e.col-n.col,r=e.row-n.row,a=i*i+s*s;if(a===0)return Math.sqrt(l*l+r*r);const c=Math.max(0,Math.min(1,(l*i+r*s)/a)),d=n.col+c*i,u=n.row+c*s,h=e.col-d,f=e.row-u;return Math.sqrt(h*h+f*f)}function _n(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 pt(e,t,n,o,i){if(!e||!t.maze)return;const{canvasWidth:s,canvasHeight:l}=n,{cellWidth:r,cellHeight:a}=o,{maze:c,playerCell:d,exitCell:u,foodCells:h,showClue:f,playerPath:g,visitCounts:_}=t,{padding:v,wallWidth:T,wallColor:b,playerColor:C,playerRadius:p,foodColor:S,backgroundColor:w,clueColor:y,exitColor:z,exitWallWidth:N,exitDashArray:E}=i;e.clearRect(0,0,s,l),e.save(),e.fillStyle=w,e.fillRect(0,0,s,l),e.restore(),f&&yn({ctx:e,playerPath:g,visitCounts:_,cellWidth:r,cellHeight:a,padding:v,clueColor:y}),vn({ctx:e,maze:c,cellWidth:r,cellHeight:a,padding:v,wallColor:b,wallWidth:T}),pn({ctx:e,maze:c,exitCell:u,cellWidth:r,cellHeight:a,padding:v,exitColor:z,exitWallWidth:N,exitDashArray:E}),wn({ctx:e,foodCells:h,cellWidth:r,cellHeight:a,padding:v,foodColor:S}),gn({ctx:e,playerCell:d,playerRadius:p,cellWidth:r,cellHeight:a,padding:v,playerColor:C})}function vn({ctx:e,maze:t,cellWidth:n,cellHeight:o,padding:i,wallColor:s,wallWidth:l}){e.save(),e.strokeStyle=s,e.lineWidth=l,e.lineCap="round",e.beginPath(),bn(t,n,o,i).forEach(a=>{e.moveTo(a.x1,a.y1),e.lineTo(a.x2,a.y2)}),e.stroke(),e.restore()}function gn({ctx:e,playerCell:t,playerRadius:n,cellWidth:o,cellHeight:i,padding:s,playerColor:l}){const{x:r,y:a}=ve(t.row,t.col,o,i,s),c=Math.min(o,i)*Math.min(n,.5);e.save(),e.fillStyle=l,e.beginPath(),e.arc(r,a,c,0,Math.PI*2),e.fill(),e.restore()}function pn({ctx:e,maze:t,exitCell:n,cellWidth:o,cellHeight:i,padding:s,exitColor:l,exitWallWidth:r,exitDashArray:a=[8,12]}){const{row:c,col:d}=n;if(!t.isValid(c,d))return;const u=s+d*o,h=s+c*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=l,e.lineWidth=r,e.setLineDash(a),e.beginPath(),e.moveTo(u,h+i),e.lineTo(u+o,h+i),e.stroke(),e.restore()}function wn({ctx:e,foodCells:t,cellWidth:n,cellHeight:o,padding:i,foodColor:s}){e.fillStyle=s;const l=Math.min(n,o)*.25;t.forEach(r=>{const{x:a,y:c}=ve(r.row,r.col,n,o,i);Cn(e,a,c,l*1.2,5,l*.6)})}function Cn(e,t,n,o,i,s){e.save(),e.beginPath();for(let l=0;l<i*2;l++){const r=l%2===0?o:s,a=Math.PI*l/i;e.lineTo(t+r*Math.sin(a),n+r*Math.cos(a))}e.closePath(),e.fill(),e.restore()}function yn({ctx:e,playerPath:t,visitCounts:n,cellWidth:o,cellHeight:i,padding:s,clueColor:l}){if(!(!t||t.length<2||!n)){e.save();for(let r=1;r<t.length;r++){const a=t[r-1],c=t[r],d=`${a.row},${a.col}-${c.row},${c.col}`,u=`${c.row},${c.col}-${a.row},${a.col}`,h=(n[d]||0)+(n[u]||0),f=Math.min(.2+h*.1,.9),g=Math.max(3,o*.1)+h*.5;try{e.strokeStyle=l.replace(")",`, ${f})`).replace("rgb(","rgba(")}catch{e.strokeStyle=`rgba(255, 0, 0, ${f})`}e.lineWidth=g,e.lineCap="round",e.lineJoin="round";const{x:_,y:v}=ve(a.row,a.col,o,i,s),{x:T,y:b}=ve(c.row,c.col,o,i,s);e.beginPath(),e.moveTo(_,v),e.lineTo(T,b),e.stroke()}e.restore()}}function bn(e,t,n,o){const i=[];for(let s=0;s<e.rows;s++)for(let l=0;l<e.cols;l++){const r=e.grid[s][l],a=o+l*t,c=o+s*n;r.walls.top&&i.push({x1:a,y1:c,x2:a+t,y2:c}),r.walls.right&&i.push({x1:a+t,y1:c,x2:a+t,y2:c+n}),r.walls.bottom&&i.push({x1:a,y1:c+n,x2:a+t,y2:c+n}),r.walls.left&&i.push({x1:a,y1:c,x2:a,y2:c+n})}return i}function ve(e,t,n,o,i){return{x:i+t*n+n/2,y:i+e*o+o/2}}function Tn(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 kn{constructor(t,n){this.row=t,this.col=n}visited=!1;walls={top:!0,right:!0,bottom:!0,left:!0}}class wt{rows;cols;grid;seed;random;constructor(t,n,o,i,s={row:0,col:0},l={row:t-1,col:n-1}){this.rows=t,this.cols=n,this.seed=i??Math.floor(Math.random()*1e6),this.random=Tn(this.seed),this.grid=this.initializeGrid(),this.generate(o,s,l)}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 kn(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 l=t+s.r,r=n+s.c;this.isValid(l,r)&&o.push({row:l,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],l=this.grid[o][i];t===o+1?(s.walls.top=!1,l.walls.bottom=!1):t===o-1?(s.walls.bottom=!1,l.walls.top=!1):n===i+1?(s.walls.left=!1,l.walls.right=!1):n===i-1&&(s.walls.right=!1,l.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:l}=i,r=this.getUnvisitedNeighbors(s,l);if(r.length>0){const a=this.randomPick(r),{row:c,col:d}=a;this.removeWall(s,l,c,d),this.grid[c][d].visited=!0,t.push(a)}else t.pop()}}generateWithPrims(){const t=[],n=(s,l)=>{const r=this.getNeighbors(s,l);for(const a of r)!this.grid[a.row][a.col].visited&&!t.some(c=>c.row===a.row&&c.col===a.col)&&t.push(a)},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),l=t[s],{row:r,col:a}=l,c=this.getVisitedNeighbors(r,a);if(c.length>0){const d=this.randomPick(c);this.removeWall(r,a,d.row,d.col),this.grid[r][a].visited=!0,n(r,a)}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 Ct=(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},Sn=e=>e===1?2:e>=2&&e<=5?3:e>=6&&e<=11?4:e>=12&&e<=15?5:6,zn=(e,t)=>{if(!t)return console.error(`Cannot find Level ${e}'s config.`),null;const{size:n,seed:o,method:i,entry:s,exit:l}=t,r=n,a=n,c=s||{row:0,col:0},d=l||{row:r-1,col:a-1},u=new wt(r,a,i,o,c,d),h=Sn(e),f=[];for(let g=0;g<h;g++){let _;do _={row:Math.floor(u.random()*r),col:Math.floor(u.random()*a)};while(_.row===c.row&&_.col===c.col||_.row===d.row&&_.col===d.col||!Ct(u,_.row,_.col)||f.some(v=>v.row===_.row&&v.col===_.col));f.push(_)}return{isGameActive:!0,levelTransitioning:!1,maze:u,playerCell:c,exitCell:d,foodCells:f,playerAtExit:!1,foodCollected:0,totalFoodCount:h,showClue:!1,playerPath:[c],visitCounts:{[`${c.row},${c.col}`]:1}}},En=({size:e,seed:t,method:n,foodCount:o,foodRace:i,clue:s})=>{const l=e,r=e,a={row:0,col:0},c={row:l-1,col:r-1},d=new wt(l,r,n,t,a,c),u=[];if(i)for(let h=0;h<o;h++){let f,g=0;do f={row:Math.floor(d.random()*l),col:Math.floor(d.random()*r)},g++;while(g<50&&(f.row===a.row&&f.col===a.col||f.row===c.row&&f.col===c.col||!Ct(d,f.row,f.col)||u.some(_=>_.row===f.row&&_.col===f.col)));g<50&&u.push(f)}return{isGameActive:!0,levelTransitioning:!1,maze:d,playerCell:a,exitCell:c,foodCells:u,playerAtExit:!1,foodCollected:0,totalFoodCount:i?o:0,showClue:s,playerPath:[a],visitCounts:{[`${a.row},${a.col}`]:1}}};function Ln(){const{setGamePlayState:e,gamePlayState:t,gamePlayStateRef:n,gameProgress:o,config:i}=ne(),s=R(null),l=R(null),{i18n:r,levelConfig:a,renderConfig:c}=i,d=oe(a),u=R(d.getLevelConfig(o.currentLevel));x(()=>{s.current&&j.attachTo(s.current)},[]);const h=R(),f=mt(l,()=>{h.current?.()}),g=_t(l,t,c.padding);x(()=>{u.current=d.getLevelConfig(o.currentLevel)},[o.currentLevel]);const _=()=>{const C=zn(o.currentLevel,u.current);C&&e(p=>({...p,...C}))};x(()=>{_()},[o.currentLevel]);const v=()=>{_()},{updatePlayerPos:T,resetMovingState:b}=vt({gamePlayStateRef:n,setGamePlayState:e,playerRadius:c.playerRadius,moveSpeed:c.gridMoveSpeed,onFoodCollected:()=>{const C=n.current.totalFoodCount-n.current.foodCollected-1;C>0?j.show(r.foodCollectedToast.replace("%NUM%",C.toString()),3e3):j.show(r.allFoodCollectedToast)}});return x(()=>{b()},[o.currentLevel,b]),x(()=>{let C,p=!document.hidden;const S=()=>{const z=l.current?.getContext("2d"),N=n.current;if(!(p&&N?.isGameActive&&z&&N?.maze)){C=requestAnimationFrame(S);return}T(),w(),C=requestAnimationFrame(S)},w=()=>{const z=l.current?.getContext("2d"),N=n.current;if(z&&N?.maze){const E=u.current?.wallWidth||c?.wallWidth,k=u.current?.exitColor||c?.exitColor,L=u.current?.exitWallWidth||c?.exitWallWidth,I=u.current?.exitDashArray||c?.exitDashArray;pt(z,N,f.current,g.current,{...c,wallWidth:E,exitColor:k,exitWallWidth:L,exitDashArray:I})}};h.current=w;const y=z=>{const N=p;p=!document.hidden&&document.visibilityState==="visible"&&(!z||z.type!=="blur"),!N&&p?n.current?.levelTransitioning===!1&&e({...n.current,isGameActive:!0}):N&&!p&&e({...n.current,isGameActive:!1})};return document.addEventListener("visibilitychange",y),window.addEventListener("blur",y),window.addEventListener("focus",y),C=requestAnimationFrame(S),()=>{cancelAnimationFrame(C),document.removeEventListener("visibilitychange",y),window.removeEventListener("blur",y),window.removeEventListener("focus",y)}},[]),x(()=>{j.show(r.useArrowKeyTips,3e3)},[]),m("div",{className:"maze-game-container",children:[m($t,{}),m(hn,{onRetry:v}),m("div",{className:"maze-canvas-container",ref:s,children:m("canvas",{ref:l,className:"maze-game-canvas"})})]})}const Nn=e=>{const t=Math.floor(e/60),n=e%60;return`${t.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`},Mn=({timer:e})=>{const[t,n]=U(e),o=R(),i=R(!1),s=R(0);return x(()=>{const l=()=>{!i.current&&!o.current&&(i.current=!0,o.current=setInterval(()=>{n(a=>(s.current=e-a+1,a<=1?(clearInterval(o.current),window.dispatchEvent(new CustomEvent("maze:timeUp")),0):a-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",l),window.addEventListener("maze:gameSuccess",r),()=>{window.removeEventListener("maze:firstMove",l),window.removeEventListener("maze:gameSuccess",r),clearInterval(o.current)}},[e]),x(()=>{o.current&&(clearInterval(o.current),o.current=void 0),n(e),i.current=!1,s.current=0},[e]),m("div",{className:"single-maze-timer",children:m("span",{className:`maze-timer-text ${t<=10&&i.current?"maze-timer-warning":""}`,children:["⏱️ ",Nn(t)]})})};function An({config:e}){const{size:t,seed:n,method:o,foodCount:i,foodRace:s,clue:l,renderConfig:r,successCallback:a,failCallback:c,timer:d,i18n:u}=e,[h,f]=U({...Me}),[g,_]=U(!1),[v,T]=U(!0),[b,C]=U(!1),[p,S]=U(""),w=R(0),y=R(!1),z=R(!1),N=R(null),E=R(null),k=R(h),L=R(),I=mt(N,()=>{L.current?.()}),F=_t(N,h,r.padding);x(()=>{k.current=h},[h]);const{updatePlayerPos:O,resetMovingState:$,resetFirstMoveState:G}=vt({gamePlayStateRef:k,setGamePlayState:f,playerRadius:r.playerRadius,moveSpeed:r.gridMoveSpeed,onFoodCollected:()=>{console.log("Food collected in single maze")},onExitReached:()=>{if(!y.current){if(s&&k.current.foodCollected<k.current.totalFoodCount){S(`⭐️ ${u.foodMsg}`),C(!0),f(A=>({...A,isGameActive:!1}));return}f(A=>({...A,isGameActive:!1})),B()}},onFirstMove:()=>{window.dispatchEvent(new CustomEvent("maze:firstMove"))}}),X=()=>{y.current=!0,S(`⏰ ${u.failMsg}`),C(!0),f({...k.current,isGameActive:!1})},B=()=>{y.current=!0,z.current=!0,S(`🎉 ${u.successMsg}`),C(!0),f(A=>({...A,isGameActive:!1})),window.dispatchEvent(new CustomEvent("maze:gameSuccess"))},Z=()=>{if(C(!1),!y.current){f(A=>({...A,isGameActive:!0}));return}T(!1),f(A=>({...A,showClue:!0})),z.current?a?.(w.current):c?.()};return x(()=>{(async()=>{_(!0);try{const W=En({size:t,seed:n,method:o,foodCount:i,foodRace:s,clue:l});k.current=W,f(W)}catch(W){console.error("Error generating single maze:",W)}finally{_(!1)}})()},[e]),x(()=>{let A;const W=!document.hidden,Q=()=>{const Ce=N.current?.getContext("2d"),ie=k.current;if(!(W&&ie?.isGameActive&&Ce&&ie?.maze)){A=requestAnimationFrame(Q);return}O(),we(),A=requestAnimationFrame(Q)},we=()=>{const Ce=N.current?.getContext("2d"),ie=k.current;Ce&&ie?.maze&&pt(Ce,ie,I.current,F.current,r)};return L.current=we,A=requestAnimationFrame(Q),()=>{cancelAnimationFrame(A)}},[]),x(()=>{$(),G()},[e,$,G]),x(()=>{const A=W=>{w.current=W.detail.timeUsed};return window.addEventListener("maze:timeUsed",A),window.addEventListener("maze:timeUp",X),()=>{window.removeEventListener("maze:timeUsed",A),window.removeEventListener("maze:timeUp",X)}},[]),g?m("div",{className:"single-maze-loading",children:m("div",{children:"Generating maze..."})}):h?m("div",{className:"maze-game-container",children:[v&&m(Mn,{timer:d}),m("div",{className:"single-maze-canvas-container",ref:E,children:m("canvas",{ref:N,className:"maze-game-canvas"})}),m(re,{isOpen:b,title:p,noConfirm:!0,cancelText:"OK",onCancel:Z})]}):m("div",{className:"single-maze-error",children:m("div",{children:"Failed to generate maze"})})}const yt=[[{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"}]],bt={gridMoveSpeed:.07,padding:10,wallWidth:2,wallColor:"#000000",foodColor:"#4CAF50",clueColor:"rgb(255,0,0)",backgroundColor:"#ffffff",playerColor:"#4CAF50",playerRadius:.2,exitColor:"#F44336",exitWallWidth:4,exitDashArray:[8,12]},ge={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."},renderConfig:bt,levelConfig:yt},pe={i18n:{successMsg:"Congratulations! You completed the maze!",failMsg:"Time is up!",foodMsg:"Please collect all stars before leaving!"},size:8,seed:12345,method:"backtracking",clue:!1,foodCount:0,foodRace:!1,renderConfig:bt,timer:10*60,successCallback:()=>{console.log("🎉 Single maze completed successfully!")},failCallback:()=>{console.log("⏰ Time is up! Game failed.")}};function Pn({config:e={}}){const t={...ge.i18n,...e.i18n||{}},n={...ge.renderConfig,...e.renderConfig||{}},o=e.levelConfig||yt,i={...ge,...e,i18n:t,levelConfig:o,renderConfig:n};return m(Ft,{config:i,children:m(Ln,{})})}function In({config:e={}}){const t={...pe.i18n,...e.i18n||{}},n={...pe.renderConfig,...e.renderConfig||{}},o={...pe,...e,i18n:t,renderConfig:n};return m(An,{config:o})}const xn={root:"https://unpkg.com/@roudanio/maze@0.2.5/dist/",...ge};`${JSON.stringify(xn,null,2)}`;const Rn={root:"https://unpkg.com/@roudanio/maze@0.2.5/dist/",...pe};return`${JSON.stringify(Rn,(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
@@ -270,10 +270,10 @@ function m(e, t, n, o, i, s) {
270
270
  if (typeof e == "function" && (l = e.defaultProps)) for (r in l) a[r] === void 0 && (a[r] = l[r]);
271
271
  return M.vnode && M.vnode(c), c;
272
272
  }
273
- var Z, P, ye, Oe, oe = 0, dt = [], F = M, $e = F.__b, Ue = F.__r, Ge = F.diffed, We = F.__c, je = F.unmount, qe = F.__;
273
+ var Z, I, ye, Oe, oe = 0, dt = [], D = M, $e = D.__b, Ue = D.__r, Ge = D.diffed, We = D.__c, je = D.unmount, qe = D.__;
274
274
  function Ce(e, t) {
275
- F.__h && F.__h(P, e, oe || t), oe = 0;
276
- var n = P.__H || (P.__H = { __: [], __h: [] });
275
+ D.__h && D.__h(I, e, oe || t), oe = 0;
276
+ var n = I.__H || (I.__H = { __: [], __h: [] });
277
277
  return e >= n.__.length && n.__.push({}), n.__[e];
278
278
  }
279
279
  function W(e) {
@@ -284,7 +284,7 @@ function At(e, t, n) {
284
284
  if (o.t = e, !o.__c && (o.__ = [ft(void 0, t), function(r) {
285
285
  var a = o.__N ? o.__N[0] : o.__[0], c = o.t(a, r);
286
286
  a !== c && (o.__N = [c, o.__[1]], o.__c.setState({}));
287
- }], o.__c = P, !P.__f)) {
287
+ }], o.__c = I, !I.__f)) {
288
288
  var i = function(r, a, c) {
289
289
  if (!o.__c.__H) return !0;
290
290
  var d = o.__c.__H.__.filter(function(h) {
@@ -301,23 +301,23 @@ function At(e, t, n) {
301
301
  }
302
302
  }), s && s.call(this, r, a, c) || u;
303
303
  };
304
- P.__f = !0;
305
- var s = P.shouldComponentUpdate, l = P.componentWillUpdate;
306
- P.componentWillUpdate = function(r, a, c) {
304
+ I.__f = !0;
305
+ var s = I.shouldComponentUpdate, l = I.componentWillUpdate;
306
+ I.componentWillUpdate = function(r, a, c) {
307
307
  if (this.__e) {
308
308
  var d = s;
309
309
  s = void 0, i(r, a, c), s = d;
310
310
  }
311
311
  l && l.call(this, r, a, c);
312
- }, P.shouldComponentUpdate = i;
312
+ }, I.shouldComponentUpdate = i;
313
313
  }
314
314
  return o.__N || o.__;
315
315
  }
316
- function I(e, t) {
316
+ function x(e, t) {
317
317
  var n = Ce(Z++, 3);
318
- !F.__s && ht(n.__H, t) && (n.__ = e, n.u = t, P.__H.__h.push(n));
318
+ !D.__s && ht(n.__H, t) && (n.__ = e, n.u = t, I.__H.__h.push(n));
319
319
  }
320
- function R(e) {
320
+ function F(e) {
321
321
  return oe = 5, Q(function() {
322
322
  return { current: e };
323
323
  }, []);
@@ -332,33 +332,33 @@ function He(e, t) {
332
332
  }, t);
333
333
  }
334
334
  function Pt(e) {
335
- var t = P.context[e.__c], n = Ce(Z++, 9);
336
- return n.c = e, t ? (n.__ == null && (n.__ = !0, t.sub(P)), t.props.value) : e.__;
335
+ var t = I.context[e.__c], n = Ce(Z++, 9);
336
+ return n.c = e, t ? (n.__ == null && (n.__ = !0, t.sub(I)), t.props.value) : e.__;
337
337
  }
338
338
  function It() {
339
339
  for (var e; e = dt.shift(); ) if (e.__P && e.__H) try {
340
340
  e.__H.__h.forEach(he), e.__H.__h.forEach(ze), e.__H.__h = [];
341
341
  } catch (t) {
342
- e.__H.__h = [], F.__e(t, e.__v);
342
+ e.__H.__h = [], D.__e(t, e.__v);
343
343
  }
344
344
  }
345
- F.__b = function(e) {
346
- P = null, $e && $e(e);
347
- }, F.__ = function(e, t) {
345
+ D.__b = function(e) {
346
+ I = null, $e && $e(e);
347
+ }, D.__ = function(e, t) {
348
348
  e && t.__k && t.__k.__m && (e.__m = t.__k.__m), qe && qe(e, t);
349
- }, F.__r = function(e) {
349
+ }, D.__r = function(e) {
350
350
  Ue && Ue(e), Z = 0;
351
- var t = (P = e.__c).__H;
352
- t && (ye === P ? (t.__h = [], P.__h = [], t.__.forEach(function(n) {
351
+ var t = (I = e.__c).__H;
352
+ t && (ye === I ? (t.__h = [], I.__h = [], t.__.forEach(function(n) {
353
353
  n.__N && (n.__ = n.__N), n.u = n.__N = void 0;
354
- })) : (t.__h.forEach(he), t.__h.forEach(ze), t.__h = [], Z = 0)), ye = P;
355
- }, F.diffed = function(e) {
354
+ })) : (t.__h.forEach(he), t.__h.forEach(ze), t.__h = [], Z = 0)), ye = I;
355
+ }, D.diffed = function(e) {
356
356
  Ge && Ge(e);
357
357
  var t = e.__c;
358
- t && t.__H && (t.__H.__h.length && (dt.push(t) !== 1 && Oe === F.requestAnimationFrame || ((Oe = F.requestAnimationFrame) || xt)(It)), t.__H.__.forEach(function(n) {
358
+ t && t.__H && (t.__H.__h.length && (dt.push(t) !== 1 && Oe === D.requestAnimationFrame || ((Oe = D.requestAnimationFrame) || xt)(It)), t.__H.__.forEach(function(n) {
359
359
  n.u && (n.__H = n.u), n.u = void 0;
360
- })), ye = P = null;
361
- }, F.__c = function(e, t) {
360
+ })), ye = I = null;
361
+ }, D.__c = function(e, t) {
362
362
  t.some(function(n) {
363
363
  try {
364
364
  n.__h.forEach(he), n.__h = n.__h.filter(function(o) {
@@ -367,10 +367,10 @@ F.__b = function(e) {
367
367
  } catch (o) {
368
368
  t.some(function(i) {
369
369
  i.__h && (i.__h = []);
370
- }), t = [], F.__e(o, n.__v);
370
+ }), t = [], D.__e(o, n.__v);
371
371
  }
372
372
  }), We && We(e, t);
373
- }, F.unmount = function(e) {
373
+ }, D.unmount = function(e) {
374
374
  je && je(e);
375
375
  var t, n = e.__c;
376
376
  n && n.__H && (n.__H.__.forEach(function(o) {
@@ -379,7 +379,7 @@ F.__b = function(e) {
379
379
  } catch (i) {
380
380
  t = i;
381
381
  }
382
- }), n.__H = void 0, t && F.__e(t, n.__v));
382
+ }), n.__H = void 0, t && D.__e(t, n.__v));
383
383
  };
384
384
  var Be = typeof requestAnimationFrame == "function";
385
385
  function xt(e) {
@@ -389,12 +389,12 @@ function xt(e) {
389
389
  Be && (t = requestAnimationFrame(n));
390
390
  }
391
391
  function he(e) {
392
- var t = P, n = e.__c;
393
- typeof n == "function" && (e.__c = void 0, n()), P = t;
392
+ var t = I, n = e.__c;
393
+ typeof n == "function" && (e.__c = void 0, n()), I = t;
394
394
  }
395
395
  function ze(e) {
396
- var t = P;
397
- e.__c = e.__(), P = t;
396
+ var t = I;
397
+ e.__c = e.__(), I = t;
398
398
  }
399
399
  function ht(e, t) {
400
400
  return !e || e.length !== t.length || t.some(function(n, o) {
@@ -449,7 +449,7 @@ const Rt = (e) => ({
449
449
  visitCounts: {}
450
450
  }, Ft = ({ children: e, config: t }) => {
451
451
  const n = Rt(t.lcPrefix + "progress"), o = n.loadGameData(), [i, s] = W(() => o || { ...Ve });
452
- I(() => {
452
+ x(() => {
453
453
  const u = Object.values(i.levelScores).reduce(
454
454
  (h, f) => h + f,
455
455
  0
@@ -458,7 +458,7 @@ const Rt = (e) => ({
458
458
  ...h,
459
459
  totalScore: u
460
460
  }));
461
- }, [i.levelScores]), I(() => {
461
+ }, [i.levelScores]), x(() => {
462
462
  n.saveGameData(i);
463
463
  }, [
464
464
  i.currentLevel,
@@ -470,8 +470,8 @@ const Rt = (e) => ({
470
470
  ]);
471
471
  const [l, r] = W({
472
472
  ...Ee
473
- }), a = R(l);
474
- I(() => {
473
+ }), a = F(l);
474
+ x(() => {
475
475
  a.current = l;
476
476
  }, [l]);
477
477
  const c = Q(() => [
@@ -632,8 +632,8 @@ const Rt = (e) => ({
632
632
  onConfirm: u,
633
633
  onCancel: h
634
634
  }) => {
635
- const f = R(null);
636
- return I(() => {
635
+ const f = F(null);
636
+ return x(() => {
637
637
  const g = (_) => {
638
638
  _.key === "Escape" && h?.();
639
639
  };
@@ -730,9 +730,9 @@ const Rt = (e) => ({
730
730
  })), p(!1);
731
731
  }, L = () => {
732
732
  b(!0);
733
- }, A = () => {
733
+ }, P = () => {
734
734
  s(), b(!1), q.show(r.resetDoneToast);
735
- }, x = () => {
735
+ }, R = () => {
736
736
  b(!1);
737
737
  };
738
738
  return /* @__PURE__ */ m("div", { class: "game-panel-container", children: [
@@ -802,8 +802,8 @@ const Rt = (e) => ({
802
802
  message: r.confirmResetMessage,
803
803
  confirmText: r.reset,
804
804
  cancelText: r.cancel,
805
- onConfirm: A,
806
- onCancel: x
805
+ onConfirm: P,
806
+ onCancel: R
807
807
  }
808
808
  ),
809
809
  /* @__PURE__ */ m(
@@ -1017,7 +1017,7 @@ const dn = new un(), be = 3, hn = ({ onRetry: e }) => {
1017
1017
  gameProgress: s,
1018
1018
  setGameProgress: l
1019
1019
  } = re(), { i18n: r, levelConfig: a } = t, [c, d, u] = n, { foodCollected: h, totalFoodCount: f, playerAtExit: g, levelTransitioning: _ } = o, { currentLevel: v } = s, [T, b] = W(!1);
1020
- I(() => {
1020
+ x(() => {
1021
1021
  g && _ && (dn.addConfetti(), q.show(r.levelCompleteToast), b(!0));
1022
1022
  }, [g, _]);
1023
1023
  const C = ie(a), p = C.getTotalLevels(), S = Q(() => v >= p, [v, p]), w = () => {
@@ -1032,20 +1032,20 @@ const dn = new un(), be = 3, hn = ({ onRetry: e }) => {
1032
1032
  b(!1);
1033
1033
  const E = C.getNextLevelInfo(v);
1034
1034
  if (!E) return;
1035
- const { nextLevel: k, nextTier: L, isTierChange: A } = E;
1036
- A && q.show(
1035
+ const { nextLevel: k, nextTier: L, isTierChange: P } = E;
1036
+ P && q.show(
1037
1037
  r.tierUnlockedToast.replace("%TIER%", L.toString())
1038
- ), l((x) => ({
1039
- ...x,
1038
+ ), l((R) => ({
1039
+ ...R,
1040
1040
  currentLevel: k,
1041
1041
  currentTier: L,
1042
- highestUnlockedLevel: Math.max(x.highestUnlockedLevel, k),
1043
- highestUnlockedTier: Math.max(x.highestUnlockedTier, L),
1042
+ highestUnlockedLevel: Math.max(R.highestUnlockedLevel, k),
1043
+ highestUnlockedTier: Math.max(R.highestUnlockedTier, L),
1044
1044
  levelScores: {
1045
- ...x.levelScores,
1046
- [x.currentLevel]: Math.max(
1045
+ ...R.levelScores,
1046
+ [R.currentLevel]: Math.max(
1047
1047
  Object.values(n).filter(Boolean).length,
1048
- x.levelScores[x.currentLevel] || 0
1048
+ R.levelScores[R.currentLevel] || 0
1049
1049
  )
1050
1050
  }
1051
1051
  }));
@@ -1058,24 +1058,24 @@ const dn = new un(), be = 3, hn = ({ onRetry: e }) => {
1058
1058
  ...E.levelScores,
1059
1059
  [E.currentLevel]: k
1060
1060
  };
1061
- let A = 0, x = 0;
1061
+ let P = 0, R = 0;
1062
1062
  const O = Object.entries(L).sort(
1063
1063
  ($, U) => Number($[0]) - Number(U[0])
1064
1064
  );
1065
1065
  for (const [$, U] of O)
1066
1066
  if (U < be) {
1067
- A = Number($), x = C.getTierByLevel(A);
1067
+ P = Number($), R = C.getTierByLevel(P);
1068
1068
  break;
1069
1069
  }
1070
- return (A > 0 && A !== v || k < be) && q.show(r.notCompleteLevel), (A === 0 || k < be) && e?.(), {
1070
+ return (P > 0 && P !== v || k < be) && q.show(r.notCompleteLevel), (P === 0 || k < be) && e?.(), {
1071
1071
  ...E,
1072
- currentLevel: A || E.currentLevel,
1073
- currentTier: x || E.currentTier,
1072
+ currentLevel: P || E.currentLevel,
1073
+ currentTier: R || E.currentTier,
1074
1074
  levelScores: L
1075
1075
  };
1076
1076
  });
1077
1077
  };
1078
- return I(() => {
1078
+ return x(() => {
1079
1079
  const E = document.querySelector(".maze-game-container"), k = (L) => {
1080
1080
  T && ((L.key === " " || L.code === "Space") && E && (E.contains(document.activeElement) || document.activeElement === document.body) && (L.preventDefault(), S ? N() : z()), (L.key === "r" || L.code === "KeyR") && w(), (L.key === "c" || L.code === "KeyC") && y());
1081
1081
  };
@@ -1127,11 +1127,11 @@ const dn = new un(), be = 3, hn = ({ onRetry: e }) => {
1127
1127
  }
1128
1128
  );
1129
1129
  }, _t = (e, t) => {
1130
- const n = R({
1130
+ const n = F({
1131
1131
  canvasWidth: 0,
1132
1132
  canvasHeight: 0
1133
1133
  });
1134
- return I(() => {
1134
+ return x(() => {
1135
1135
  const o = () => {
1136
1136
  const s = e.current;
1137
1137
  if (!s) return;
@@ -1152,8 +1152,8 @@ const dn = new un(), be = 3, hn = ({ onRetry: e }) => {
1152
1152
  };
1153
1153
  }, [e, t]), n;
1154
1154
  }, vt = (e, t, n) => {
1155
- const o = R({ cellWidth: 0, cellHeight: 0 });
1156
- return I(() => {
1155
+ const o = F({ cellWidth: 0, cellHeight: 0 });
1156
+ return x(() => {
1157
1157
  const i = () => {
1158
1158
  const l = e.current, r = t.maze;
1159
1159
  if (!l || !r) return;
@@ -1186,7 +1186,7 @@ const dn = new un(), be = 3, hn = ({ onRetry: e }) => {
1186
1186
  onExitReached: l,
1187
1187
  onFirstMove: r
1188
1188
  }) => {
1189
- const a = () => o?.current ?? n ?? 0.03, c = R(!1), d = R(/* @__PURE__ */ new Set()), u = R(!1), h = He(
1189
+ const a = () => o?.current ?? n ?? 0.03, c = F(!1), d = F(/* @__PURE__ */ new Set()), u = F(!1), h = He(
1190
1190
  (C, p) => {
1191
1191
  const S = e.current;
1192
1192
  if (!S.maze)
@@ -1201,10 +1201,10 @@ const dn = new un(), be = 3, hn = ({ onRetry: e }) => {
1201
1201
  S.maze
1202
1202
  ))
1203
1203
  return { canMove: !1, newCell: null };
1204
- const { row: E, col: k } = p, L = E + y * w, A = k + z * w, x = -0.5, O = S.maze.rows, $ = S.maze.cols;
1205
- if (L < x || L >= O || A < x || A >= $)
1204
+ const { row: E, col: k } = p, L = E + y * w, P = k + z * w, R = -0.5, O = S.maze.rows, $ = S.maze.cols;
1205
+ if (L < R || L >= O || P < R || P >= $)
1206
1206
  return { canMove: !1, newCell: null };
1207
- const U = E < 0 ? 0 : Math.floor(E), V = k < 0 ? 0 : Math.floor(k), B = L < 0 ? 0 : Math.floor(L), Y = A < 0 ? 0 : Math.floor(A);
1207
+ const U = E < 0 ? 0 : Math.floor(E), V = k < 0 ? 0 : Math.floor(k), B = L < 0 ? 0 : Math.floor(L), Y = P < 0 ? 0 : Math.floor(P);
1208
1208
  return B !== U || Y !== V ? S.maze.isValid(B, Y) ? {
1209
1209
  canMove: !0,
1210
1210
  newCell: { row: B, col: Y }
@@ -1273,7 +1273,7 @@ const dn = new un(), be = 3, hn = ({ onRetry: e }) => {
1273
1273
  }
1274
1274
  ) || (!u.current && r && (u.current = !0, r()), c.current = !0);
1275
1275
  };
1276
- I(() => {
1276
+ x(() => {
1277
1277
  const C = (w) => {
1278
1278
  if (w.key === "ArrowUp" || w.key === "ArrowDown" || w.key === "ArrowLeft" || w.key === "ArrowRight" || w.key === " ") {
1279
1279
  const y = document.activeElement;
@@ -1304,10 +1304,10 @@ const dn = new un(), be = 3, hn = ({ onRetry: e }) => {
1304
1304
  return e.current.playerCell;
1305
1305
  const C = a(), p = e.current.playerCell;
1306
1306
  let S = 0, w = 0, y = 0;
1307
- for (const D of d.current) {
1308
- const { canMove: G } = h(D, p);
1307
+ for (const A of d.current) {
1308
+ const { canMove: G } = h(A, p);
1309
1309
  if (G) {
1310
- const [K, se] = ce[D];
1310
+ const [K, se] = ce[A];
1311
1311
  S += K, w += se, y++;
1312
1312
  }
1313
1313
  }
@@ -1317,12 +1317,12 @@ const dn = new un(), be = 3, hn = ({ onRetry: e }) => {
1317
1317
  (p.row + N * C).toFixed(2)
1318
1318
  ), L = Number(
1319
1319
  (p.col + E * C).toFixed(2)
1320
- ), A = k - p.row, x = L - p.col, O = Math.sqrt(A * A + x * x);
1320
+ ), P = k - p.row, R = L - p.col, O = Math.sqrt(P * P + R * R);
1321
1321
  if (O > 0) {
1322
- const D = A / O, G = x / O;
1322
+ const A = P / O, G = R / O;
1323
1323
  if (Ze(
1324
1324
  p,
1325
- D,
1325
+ A,
1326
1326
  G,
1327
1327
  i,
1328
1328
  O,
@@ -1866,20 +1866,20 @@ function Ln() {
1866
1866
  gamePlayStateRef: n,
1867
1867
  gameProgress: o,
1868
1868
  config: i
1869
- } = re(), s = R(null), l = R(null), { i18n: r, levelConfig: a, renderConfig: c } = i, d = ie(a), u = R(
1869
+ } = re(), s = F(null), l = F(null), { i18n: r, levelConfig: a, renderConfig: c } = i, d = ie(a), u = F(
1870
1870
  d.getLevelConfig(o.currentLevel)
1871
1871
  );
1872
- I(() => {
1872
+ x(() => {
1873
1873
  s.current && q.attachTo(s.current);
1874
1874
  }, []);
1875
- const h = R(), f = _t(l, () => {
1875
+ const h = F(), f = _t(l, () => {
1876
1876
  h.current?.();
1877
1877
  }), g = vt(
1878
1878
  l,
1879
1879
  t,
1880
1880
  c.padding
1881
1881
  );
1882
- I(() => {
1882
+ x(() => {
1883
1883
  u.current = d.getLevelConfig(
1884
1884
  o.currentLevel
1885
1885
  );
@@ -1894,7 +1894,7 @@ function Ln() {
1894
1894
  ...C
1895
1895
  }));
1896
1896
  };
1897
- I(() => {
1897
+ x(() => {
1898
1898
  _();
1899
1899
  }, [o.currentLevel]);
1900
1900
  const v = () => {
@@ -1912,9 +1912,9 @@ function Ln() {
1912
1912
  ) : q.show(r.allFoodCollectedToast);
1913
1913
  }
1914
1914
  });
1915
- return I(() => {
1915
+ return x(() => {
1916
1916
  b();
1917
- }, [o.currentLevel, b]), I(() => {
1917
+ }, [o.currentLevel, b]), x(() => {
1918
1918
  let C, p = !document.hidden;
1919
1919
  const S = () => {
1920
1920
  const z = l.current?.getContext("2d"), N = n.current;
@@ -1926,13 +1926,13 @@ function Ln() {
1926
1926
  }, w = () => {
1927
1927
  const z = l.current?.getContext("2d"), N = n.current;
1928
1928
  if (z && N?.maze) {
1929
- const E = u.current?.wallWidth || c?.wallWidth, k = u.current?.exitColor || c?.exitColor, L = u.current?.exitWallWidth || c?.exitWallWidth, A = u.current?.exitDashArray || c?.exitDashArray;
1929
+ const E = u.current?.wallWidth || c?.wallWidth, k = u.current?.exitColor || c?.exitColor, L = u.current?.exitWallWidth || c?.exitWallWidth, P = u.current?.exitDashArray || c?.exitDashArray;
1930
1930
  pt(z, N, f.current, g.current, {
1931
1931
  ...c,
1932
1932
  wallWidth: E,
1933
1933
  exitColor: k,
1934
1934
  exitWallWidth: L,
1935
- exitDashArray: A
1935
+ exitDashArray: P
1936
1936
  });
1937
1937
  }
1938
1938
  };
@@ -1950,7 +1950,7 @@ function Ln() {
1950
1950
  return document.addEventListener("visibilitychange", y), window.addEventListener("blur", y), window.addEventListener("focus", y), C = requestAnimationFrame(S), () => {
1951
1951
  cancelAnimationFrame(C), document.removeEventListener("visibilitychange", y), window.removeEventListener("blur", y), window.removeEventListener("focus", y);
1952
1952
  };
1953
- }, []), I(() => {
1953
+ }, []), x(() => {
1954
1954
  q.show(r.useArrowKeyTips, 3e3);
1955
1955
  }, []), /* @__PURE__ */ m("div", { className: "maze-game-container", children: [
1956
1956
  /* @__PURE__ */ m($t, {}),
@@ -1962,8 +1962,8 @@ const Nn = (e) => {
1962
1962
  const t = Math.floor(e / 60), n = e % 60;
1963
1963
  return `${t.toString().padStart(2, "0")}:${n.toString().padStart(2, "0")}`;
1964
1964
  }, Mn = ({ timer: e }) => {
1965
- const [t, n] = W(e), o = R(), i = R(!1), s = R(0);
1966
- return I(() => {
1965
+ const [t, n] = W(e), o = F(), i = F(!1), s = F(0);
1966
+ return x(() => {
1967
1967
  const l = () => {
1968
1968
  !i.current && !o.current && (i.current = !0, o.current = setInterval(() => {
1969
1969
  n((a) => (s.current = e - a + 1, a <= 1 ? (clearInterval(o.current), window.dispatchEvent(new CustomEvent("maze:timeUp")), 0) : a - 1));
@@ -1978,7 +1978,7 @@ const Nn = (e) => {
1978
1978
  return window.addEventListener("maze:firstMove", l), window.addEventListener("maze:gameSuccess", r), () => {
1979
1979
  window.removeEventListener("maze:firstMove", l), window.removeEventListener("maze:gameSuccess", r), clearInterval(o.current);
1980
1980
  };
1981
- }, [e]), I(() => {
1981
+ }, [e]), x(() => {
1982
1982
  o.current && (clearInterval(o.current), o.current = void 0), n(e), i.current = !1, s.current = 0;
1983
1983
  }, [e]), /* @__PURE__ */ m("div", { className: "single-maze-timer", children: /* @__PURE__ */ m(
1984
1984
  "span",
@@ -2006,10 +2006,10 @@ function An({ config: e }) {
2006
2006
  i18n: u
2007
2007
  } = e, [h, f] = W({
2008
2008
  ...Ee
2009
- }), [g, _] = W(!1), [v, T] = W(!0), [b, C] = W(!1), [p, S] = W(""), w = R(0), y = R(!1), z = R(!1), N = R(null), E = R(null), k = R(h), L = R(), A = _t(N, () => {
2009
+ }), [g, _] = W(!1), [v, T] = W(!0), [b, C] = W(!1), [p, S] = W(""), w = F(0), y = F(!1), z = F(!1), N = F(null), E = F(null), k = F(h), L = F(), P = _t(N, () => {
2010
2010
  L.current?.();
2011
- }), x = vt(N, h, r.padding);
2012
- I(() => {
2011
+ }), R = vt(N, h, r.padding);
2012
+ x(() => {
2013
2013
  k.current = h;
2014
2014
  }, [h]);
2015
2015
  const { updatePlayerPos: O, resetMovingState: $, resetFirstMoveState: U } = gt({
@@ -2023,17 +2023,17 @@ function An({ config: e }) {
2023
2023
  onExitReached: () => {
2024
2024
  if (!y.current) {
2025
2025
  if (s && k.current.foodCollected < k.current.totalFoodCount) {
2026
- S(`⭐️ ${u.foodMsg}`), C(!0), requestAnimationFrame(() => {
2027
- f((D) => ({
2028
- ...D,
2029
- playerAtExit: !1,
2030
- isGameActive: !0,
2031
- levelTransitioning: !1
2032
- }));
2033
- });
2026
+ S(`⭐️ ${u.foodMsg}`), C(!0), f((A) => ({
2027
+ ...A,
2028
+ isGameActive: !1
2029
+ // Disable controls while popup is shown
2030
+ }));
2034
2031
  return;
2035
2032
  }
2036
- B();
2033
+ f((A) => ({
2034
+ ...A,
2035
+ isGameActive: !1
2036
+ })), B();
2037
2037
  }
2038
2038
  },
2039
2039
  onFirstMove: () => {
@@ -2045,14 +2045,24 @@ function An({ config: e }) {
2045
2045
  isGameActive: !1
2046
2046
  });
2047
2047
  }, B = () => {
2048
- y.current = !0, z.current = !0, S(`🎉 ${u.successMsg}`), C(!0), window.dispatchEvent(new CustomEvent("maze:gameSuccess"));
2048
+ y.current = !0, z.current = !0, S(`🎉 ${u.successMsg}`), C(!0), f((A) => ({
2049
+ ...A,
2050
+ isGameActive: !1
2051
+ })), window.dispatchEvent(new CustomEvent("maze:gameSuccess"));
2049
2052
  }, Y = () => {
2050
- C(!1), y.current && (T(!1), f((D) => ({
2051
- ...D,
2053
+ if (C(!1), !y.current) {
2054
+ f((A) => ({
2055
+ ...A,
2056
+ isGameActive: !0
2057
+ }));
2058
+ return;
2059
+ }
2060
+ T(!1), f((A) => ({
2061
+ ...A,
2052
2062
  showClue: !0
2053
- })), z.current ? a?.(w.current) : c?.());
2063
+ })), z.current ? a?.(w.current) : c?.();
2054
2064
  };
2055
- return I(() => {
2065
+ return x(() => {
2056
2066
  (async () => {
2057
2067
  _(!0);
2058
2068
  try {
@@ -2071,38 +2081,38 @@ function An({ config: e }) {
2071
2081
  _(!1);
2072
2082
  }
2073
2083
  })();
2074
- }, [e]), I(() => {
2075
- let D;
2084
+ }, [e]), x(() => {
2085
+ let A;
2076
2086
  const G = !document.hidden, K = () => {
2077
2087
  const le = N.current?.getContext("2d"), ee = k.current;
2078
2088
  if (!(G && ee?.isGameActive && le && ee?.maze)) {
2079
- D = requestAnimationFrame(K);
2089
+ A = requestAnimationFrame(K);
2080
2090
  return;
2081
2091
  }
2082
- O(), se(), D = requestAnimationFrame(K);
2092
+ O(), se(), A = requestAnimationFrame(K);
2083
2093
  }, se = () => {
2084
2094
  const le = N.current?.getContext("2d"), ee = k.current;
2085
2095
  le && ee?.maze && pt(
2086
2096
  le,
2087
2097
  ee,
2088
- A.current,
2089
- x.current,
2098
+ P.current,
2099
+ R.current,
2090
2100
  r
2091
2101
  );
2092
2102
  };
2093
- return L.current = se, D = requestAnimationFrame(K), () => {
2094
- cancelAnimationFrame(D);
2103
+ return L.current = se, A = requestAnimationFrame(K), () => {
2104
+ cancelAnimationFrame(A);
2095
2105
  };
2096
- }, []), I(() => {
2106
+ }, []), x(() => {
2097
2107
  $(), U();
2098
- }, [e, $, U]), I(() => {
2099
- const D = (G) => {
2108
+ }, [e, $, U]), x(() => {
2109
+ const A = (G) => {
2100
2110
  w.current = G.detail.timeUsed;
2101
2111
  };
2102
- return window.addEventListener("maze:timeUsed", D), window.addEventListener("maze:timeUp", V), () => {
2112
+ return window.addEventListener("maze:timeUsed", A), window.addEventListener("maze:timeUp", V), () => {
2103
2113
  window.removeEventListener(
2104
2114
  "maze:timeUsed",
2105
- D
2115
+ A
2106
2116
  ), window.removeEventListener("maze:timeUp", V);
2107
2117
  };
2108
2118
  }, []), g ? /* @__PURE__ */ m("div", { className: "single-maze-loading", children: /* @__PURE__ */ m("div", { children: "Generating maze..." }) }) : h ? /* @__PURE__ */ m("div", { className: "maze-game-container", children: [
@@ -2392,12 +2402,12 @@ function xn({
2392
2402
  return /* @__PURE__ */ m(An, { config: o });
2393
2403
  }
2394
2404
  const Rn = {
2395
- root: "https://unpkg.com/@roudanio/maze@0.2.4/dist/",
2405
+ root: "https://unpkg.com/@roudanio/maze@0.2.5/dist/",
2396
2406
  ...fe
2397
2407
  };
2398
2408
  `${JSON.stringify(Rn, null, 2)}`;
2399
2409
  const Fn = {
2400
- root: "https://unpkg.com/@roudanio/maze@0.2.4/dist/",
2410
+ root: "https://unpkg.com/@roudanio/maze@0.2.5/dist/",
2401
2411
  ...me
2402
2412
  };
2403
2413
  `${JSON.stringify(
package/dist/maze.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(B,M){typeof exports=="object"&&typeof module<"u"?module.exports=M():typeof define=="function"&&define.amd?define(M):(B=typeof globalThis<"u"?globalThis:B||self,B.Maze=M())})(this,function(){"use strict";var B,M,xe,X,Re,Fe,De,Oe,ye,be,Te,$e,te={},Ue=[],Tt=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,le=Array.isArray;function H(e,t){for(var n in t)e[n]=t[n];return e}function ke(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function kt(e,t,n){var o,i,s,l={};for(s in t)s=="key"?o=t[s]:s=="ref"?i=t[s]:l[s]=t[s];if(arguments.length>2&&(l.children=arguments.length>3?B.call(arguments,2):n),typeof e=="function"&&e.defaultProps!=null)for(s in e.defaultProps)l[s]==null&&(l[s]=e.defaultProps[s]);return ae(e,l,o,i,null)}function ae(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??++xe,__i:-1,__u:0};return i==null&&M.vnode!=null&&M.vnode(s),s}function ce(e){return e.children}function ue(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 Se(e){(!e.__d&&(e.__d=!0)&&X.push(e)&&!de.__r++||Re!=M.debounceRendering)&&((Re=M.debounceRendering)||Fe)(de)}function de(){for(var e,t,n,o,i,s,l,r=1;X.length;)X.length>r&&X.sort(De),e=X.shift(),r=X.length,e.__d&&(n=void 0,i=(o=(t=e).__v).__e,s=[],l=[],t.__P&&((n=H({},o)).__v=o.__v+1,M.vnode&&M.vnode(n),ze(t.__P,n,o,t.__n,t.__P.namespaceURI,32&o.__u?[i]:null,s,i??K(o),!!(32&o.__u),l),n.__v=o.__v,n.__.__k[n.__i]=n,Be(s,n,l),n.__e!=i&&Ge(n)));de.__r=0}function je(e,t,n,o,i,s,l,r,a,c,d){var u,h,f,g,_,v,T=o&&o.__k||Ue,b=t.length;for(a=St(n,t,T,a,b),u=0;u<b;u++)(f=n.__k[u])!=null&&(h=f.__i==-1?te:T[f.__i]||te,f.__i=u,v=ze(e,f,h,i,s,l,r,a,c,d),g=f.__e,f.ref&&h.ref!=f.ref&&(h.ref&&Ee(h.ref,null,f),d.push(f.ref,f.__c||g,f)),_==null&&g!=null&&(_=g),4&f.__u||h.__k===f.__k?a=We(f,a,e):typeof f.type=="function"&&v!==void 0?a=v:g&&(a=g.nextSibling),f.__u&=-7);return n.__e=_,a}function St(e,t,n,o,i){var s,l,r,a,c,d=n.length,u=d,h=0;for(e.__k=new Array(i),s=0;s<i;s++)(l=t[s])!=null&&typeof l!="boolean"&&typeof l!="function"?(a=s+h,(l=e.__k[s]=typeof l=="string"||typeof l=="number"||typeof l=="bigint"||l.constructor==String?ae(null,l,null,null,null):le(l)?ae(ce,{children:l},null,null,null):l.constructor==null&&l.__b>0?ae(l.type,l.props,l.key,l.ref?l.ref:null,l.__v):l).__=e,l.__b=e.__b+1,r=null,(c=l.__i=zt(l,n,a,u))!=-1&&(u--,(r=n[c])&&(r.__u|=2)),r==null||r.__v==null?(c==-1&&(i>d?h--:i<d&&h++),typeof l.type!="function"&&(l.__u|=4)):c!=a&&(c==a-1?h--:c==a+1?h++:(c>a?h--:h++,l.__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){var o,i;if(typeof e.type=="function"){for(o=e.__k,i=0;o&&i<o.length;i++)o[i]&&(o[i].__=e,t=We(o[i],t,n));return t}e.__e!=t&&(t&&e.type&&!n.contains(t)&&(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 zt(e,t,n,o){var i,s,l=e.key,r=e.type,a=t[n];if(a===null&&e.key==null||a&&l==a.key&&r==a.type&&(2&a.__u)==0)return n;if(o>(a!=null&&(2&a.__u)==0?1:0))for(i=n-1,s=n+1;i>=0||s<t.length;){if(i>=0){if((a=t[i])&&(2&a.__u)==0&&l==a.key&&r==a.type)return i;i--}if(s<t.length){if((a=t[s])&&(2&a.__u)==0&&l==a.key&&r==a.type)return s;s++}}return-1}function qe(e,t,n){t[0]=="-"?e.setProperty(t,n??""):e[t]=n==null?"":typeof n!="number"||Tt.test(t)?n:n+"px"}function he(e,t,n,o,i){var s;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")),t=t.toLowerCase()in e||t=="onFocusOut"||t=="onFocusIn"?t.toLowerCase().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 He(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(M.event?M.event(t):t)}}}function ze(e,t,n,o,i,s,l,r,a,c){var d,u,h,f,g,_,v,T,b,C,p,S,w,y,z,N,E,k=t.type;if(t.constructor!=null)return null;128&n.__u&&(a=!!(32&n.__u),s=[r=t.__e=n.__e]),(d=M.__b)&&d(t);e:if(typeof k=="function")try{if(T=t.props,b="prototype"in k&&k.prototype.render,C=(d=k.contextType)&&o[d.__c],p=d?C?C.props.value:d.__:o,n.__c?v=(u=t.__c=n.__c).__=u.__E:(b?t.__c=u=new k(T,p):(t.__c=u=new ue(T,p),u.constructor=k,u.render=Lt),C&&C.sub(u),u.props=T,u.state||(u.state={}),u.context=p,u.__n=o,h=u.__d=!0,u.__h=[],u._sb=[]),b&&u.__s==null&&(u.__s=u.state),b&&k.getDerivedStateFromProps!=null&&(u.__s==u.state&&(u.__s=H({},u.__s)),H(u.__s,k.getDerivedStateFromProps(T,u.__s))),f=u.props,g=u.state,u.__v=t,h)b&&k.getDerivedStateFromProps==null&&u.componentWillMount!=null&&u.componentWillMount(),b&&u.componentDidMount!=null&&u.__h.push(u.componentDidMount);else{if(b&&k.getDerivedStateFromProps==null&&T!==f&&u.componentWillReceiveProps!=null&&u.componentWillReceiveProps(T,p),!u.__e&&u.shouldComponentUpdate!=null&&u.shouldComponentUpdate(T,u.__s,p)===!1||t.__v==n.__v){for(t.__v!=n.__v&&(u.props=T,u.state=u.__s,u.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(L){L&&(L.__=t)}),S=0;S<u._sb.length;S++)u.__h.push(u._sb[S]);u._sb=[],u.__h.length&&l.push(u);break e}u.componentWillUpdate!=null&&u.componentWillUpdate(T,u.__s,p),b&&u.componentDidUpdate!=null&&u.__h.push(function(){u.componentDidUpdate(f,g,_)})}if(u.context=p,u.props=T,u.__P=e,u.__e=!1,w=M.__r,y=0,b){for(u.state=u.__s,u.__d=!1,w&&w(t),d=u.render(u.props,u.state,u.context),z=0;z<u._sb.length;z++)u.__h.push(u._sb[z]);u._sb=[]}else do u.__d=!1,w&&w(t),d=u.render(u.props,u.state,u.context),u.state=u.__s;while(u.__d&&++y<25);u.state=u.__s,u.getChildContext!=null&&(o=H(H({},o),u.getChildContext())),b&&!h&&u.getSnapshotBeforeUpdate!=null&&(_=u.getSnapshotBeforeUpdate(f,g)),N=d,d!=null&&d.type===ce&&d.key==null&&(N=Ve(d.props.children)),r=je(e,le(N)?N:[N],t,n,o,i,s,l,r,a,c),u.base=t.__e,t.__u&=-161,u.__h.length&&l.push(u),v&&(u.__E=u.__=null)}catch(L){if(t.__v=null,a||s!=null)if(L.then){for(t.__u|=a?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--;)ke(s[E]);else t.__e=n.__e,t.__k=n.__k;M.__e(L,t,n)}else s==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):r=t.__e=Et(n.__e,t,n,o,i,s,l,a,c);return(d=M.diffed)&&d(t),128&t.__u?void 0:r}function Be(e,t,n){for(var o=0;o<n.length;o++)Ee(n[o],n[++o],n[++o]);M.__c&&M.__c(t,e),e.some(function(i){try{e=i.__h,i.__h=[],e.some(function(s){s.call(i)})}catch(s){M.__e(s,i.__v)}})}function Ve(e){return typeof e!="object"||e==null||e.__b&&e.__b>0?e:le(e)?e.map(Ve):H({},e)}function Et(e,t,n,o,i,s,l,r,a){var c,d,u,h,f,g,_,v=n.props,T=t.props,b=t.type;if(b=="svg"?i="http://www.w3.org/2000/svg":b=="math"?i="http://www.w3.org/1998/Math/MathML":i||(i="http://www.w3.org/1999/xhtml"),s!=null){for(c=0;c<s.length;c++)if((f=s[c])&&"setAttribute"in f==!!b&&(b?f.localName==b:f.nodeType==3)){e=f,s[c]=null;break}}if(e==null){if(b==null)return document.createTextNode(T);e=document.createElementNS(i,b,T.is&&T),r&&(M.__m&&M.__m(t,s),r=!1),s=null}if(b==null)v===T||r&&e.data==T||(e.data=T);else{if(s=s&&B.call(e.childNodes),v=n.props||te,!r&&s!=null)for(v={},c=0;c<e.attributes.length;c++)v[(f=e.attributes[c]).name]=f.value;for(c in v)if(f=v[c],c!="children"){if(c=="dangerouslySetInnerHTML")u=f;else if(!(c in T)){if(c=="value"&&"defaultValue"in T||c=="checked"&&"defaultChecked"in T)continue;he(e,c,null,f,i)}}for(c in T)f=T[c],c=="children"?h=f:c=="dangerouslySetInnerHTML"?d=f:c=="value"?g=f:c=="checked"?_=f:r&&typeof f!="function"||v[c]===f||he(e,c,f,v[c],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,le(h)?h:[h],t,n,o,b=="foreignObject"?"http://www.w3.org/1999/xhtml":i,s,l,s?s[0]:n.__k&&K(n,0),r,a),s!=null)for(c=s.length;c--;)ke(s[c]);r||(c="value",b=="progress"&&g==null?e.removeAttribute("value"):g!=null&&(g!==e[c]||b=="progress"&&!g||b=="option"&&g!=v[c])&&he(e,c,g,v[c],i),c="checked",_!=null&&_!=e[c]&&he(e,c,_,v[c],i))}return e}function Ee(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){M.__e(i,n)}}function Xe(e,t,n){var o,i;if(M.unmount&&M.unmount(e),(o=e.ref)&&(o.current&&o.current!=e.__e||Ee(o,null,t)),(o=e.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(s){M.__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||ke(e.__e),e.__c=e.__=e.__e=void 0}function Lt(e,t,n){return this.constructor(e,n)}function Ye(e,t,n){var o,i,s,l;t==document&&(t=document.documentElement),M.__&&M.__(e,t),i=(o=!1)?null:t.__k,s=[],l=[],ze(t,e=t.__k=kt(ce,null,[e]),i||te,te,t.namespaceURI,i?null:t.firstChild?B.call(t.childNodes):null,s,i?i.__e:t.firstChild,o,l),Be(s,e,l)}function Nt(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(l){l.__e=!0,Se(l)})},this.sub=function(s){o.add(s);var l=s.componentWillUnmount;s.componentWillUnmount=function(){o&&o.delete(s),l&&l.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}B=Ue.slice,M={__e:function(e,t,n,o){for(var i,s,l;t=t.__;)if((i=t.__c)&&!i.__)try{if((s=i.constructor)&&s.getDerivedStateFromError!=null&&(i.setState(s.getDerivedStateFromError(e)),l=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(e,o||{}),l=i.__d),l)return i.__E=i}catch(r){e=r}throw e}},xe=0,ue.prototype.setState=function(e,t){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=H({},this.state),typeof e=="function"&&(e=e(H({},n),this.props)),e&&H(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),Se(this))},ue.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),Se(this))},ue.prototype.render=ce,X=[],Fe=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,De=function(e,t){return e.__v.__b-t.__v.__b},de.__r=0,Oe=/(PointerCapture)$|Capture$/i,ye=0,be=He(!1),Te=He(!0),$e=0;var Mt=0;function m(e,t,n,o,i,s){t||(t={});var l,r,a=t;if("ref"in a)for(r in a={},t)r=="ref"?l=t[r]:a[r]=t[r];var c={type:e,props:a,key:n,ref:l,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Mt,__i:-1,__u:0,__source:i,__self:s};if(typeof e=="function"&&(l=e.defaultProps))for(r in l)a[r]===void 0&&(a[r]=l[r]);return M.vnode&&M.vnode(c),c}var J,A,Le,Ke,ne=0,Je=[],F=M,Ze=F.__b,Qe=F.__r,et=F.diffed,tt=F.__c,nt=F.unmount,ot=F.__;function fe(e,t){F.__h&&F.__h(A,e,ne||t),ne=0;var n=A.__H||(A.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function U(e){return ne=1,At(lt,e)}function At(e,t,n){var o=fe(J++,2);if(o.t=e,!o.__c&&(o.__=[lt(void 0,t),function(r){var a=o.__N?o.__N[0]:o.__[0],c=o.t(a,r);a!==c&&(o.__N=[c,o.__[1]],o.__c.setState({}))}],o.__c=A,!A.__f)){var i=function(r,a,c){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,a,c);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,a,c)||u};A.__f=!0;var s=A.shouldComponentUpdate,l=A.componentWillUpdate;A.componentWillUpdate=function(r,a,c){if(this.__e){var d=s;s=void 0,i(r,a,c),s=d}l&&l.call(this,r,a,c)},A.shouldComponentUpdate=i}return o.__N||o.__}function I(e,t){var n=fe(J++,3);!F.__s&&st(n.__H,t)&&(n.__=e,n.u=t,A.__H.__h.push(n))}function x(e){return ne=5,Z(function(){return{current:e}},[])}function Z(e,t){var n=fe(J++,7);return st(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function rt(e,t){return ne=8,Z(function(){return e},t)}function Pt(e){var t=A.context[e.__c],n=fe(J++,9);return n.c=e,t?(n.__==null&&(n.__=!0,t.sub(A)),t.props.value):e.__}function It(){for(var e;e=Je.shift();)if(e.__P&&e.__H)try{e.__H.__h.forEach(me),e.__H.__h.forEach(Ne),e.__H.__h=[]}catch(t){e.__H.__h=[],F.__e(t,e.__v)}}F.__b=function(e){A=null,Ze&&Ze(e)},F.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),ot&&ot(e,t)},F.__r=function(e){Qe&&Qe(e),J=0;var t=(A=e.__c).__H;t&&(Le===A?(t.__h=[],A.__h=[],t.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.forEach(me),t.__h.forEach(Ne),t.__h=[],J=0)),Le=A},F.diffed=function(e){et&&et(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(Je.push(t)!==1&&Ke===F.requestAnimationFrame||((Ke=F.requestAnimationFrame)||xt)(It)),t.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),Le=A=null},F.__c=function(e,t){t.some(function(n){try{n.__h.forEach(me),n.__h=n.__h.filter(function(o){return!o.__||Ne(o)})}catch(o){t.some(function(i){i.__h&&(i.__h=[])}),t=[],F.__e(o,n.__v)}}),tt&&tt(e,t)},F.unmount=function(e){nt&&nt(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.forEach(function(o){try{me(o)}catch(i){t=i}}),n.__H=void 0,t&&F.__e(t,n.__v))};var it=typeof requestAnimationFrame=="function";function xt(e){var t,n=function(){clearTimeout(o),it&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(n,100);it&&(t=requestAnimationFrame(n))}function me(e){var t=A,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),A=t}function Ne(e){var t=A;e.__c=e.__(),A=t}function st(e,t){return!e||e.length!==t.length||t.some(function(n,o){return n!==e[o]})}function lt(e,t){return typeof t=="function"?t(e):t}const Rt=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)}}}),at=Nt(void 0),ct={currentLevel:1,highestUnlockedLevel:1,currentTier:1,highestUnlockedTier:1,levelScores:{},totalScore:0},Me={isGameActive:!0,levelTransitioning:!1,maze:null,playerCell:{row:0,col:0},exitCell:{row:0,col:0},foodCells:[],playerAtExit:!1,foodCollected:0,totalFoodCount:0,showClue:!1,playerPath:[],visitCounts:{}},Ft=({children:e,config:t})=>{const n=Rt(t.lcPrefix+"progress"),o=n.loadGameData(),[i,s]=U(()=>o||{...ct});I(()=>{const u=Object.values(i.levelScores).reduce((h,f)=>h+f,0);s(h=>({...h,totalScore:u}))},[i.levelScores]),I(()=>{n.saveGameData(i)},[i.currentLevel,i.highestUnlockedLevel,i.currentTier,i.highestUnlockedTier,i.levelScores,i.totalScore]);const[l,r]=U({...Me}),a=x(l);I(()=>{a.current=l},[l]);const c=Z(()=>[l.playerAtExit?1:0,l.foodCollected===l.totalFoodCount?1:0,l.showClue?0:1],[l.playerAtExit,l.foodCollected,l.totalFoodCount,l.showClue]),d=()=>{n.resetGameData(),s({...ct}),r({...Me})};return m(at.Provider,{value:{gameProgress:i,setGameProgress:s,gamePlayState:l,setGamePlayState:r,gamePlayStateRef:a,currentScore:c,config:t,resetGame:d},children:e})},oe=()=>{const e=Pt(at);if(!e)throw new Error("useGameContext must be used within a GameProvider");return e},re=e=>Z(()=>{const t=e.map(r=>r.length),n=t.reduce((r,a)=>r+a,0),o=e.length,i=r=>{if(r<1||r>n)return 0;let a=0;for(let c=0;c<t.length;c++)if(a+=t[c],r<=a)return c+1;return 0},s=r=>r<1||r>o?0:t.slice(0,r-1).reduce((a,c)=>a+c,0)+1,l={getTotalLevels:()=>n,getTotalTiers:()=>o,getTierLevelsRange:r=>{if(r<1||r>o)return[0,0];const a=s(r),c=a+t[r-1]-1;return[a,c]},getTierByLevel:i,getFirstLevelOfTier:s,getLevelConfig:r=>{if(r<1||r>n)return null;const a=i(r),c=s(a),d=r-c;return e[a-1][d]},getTierConfig:r=>r<1||r>o?null:e[r-1],isLevelUnlocked:(r,a)=>r<=a,isTierUnlocked:(r,a)=>r<=a,getNextLevelInfo:r=>{if(r>=n)return null;const a=r+1,c=i(r),d=i(a);return{nextLevel:a,nextTier:d,isTierChange:d>c}},getCurrentTierProgress:(r,a)=>{const[c,d]=l.getTierLevelsRange(a),u=r-c+1,h=d-c+1;return{current:u,total:h}},isLastLevelInTier:r=>{const a=i(r),[,c]=l.getTierLevelsRange(a);return r===c},getPreviousLevelInfo:r=>{if(r<=1)return null;const a=r-1,c=i(r),d=i(a);return{prevLevel:a,prevTier:d,isTierChange:d<c}}};return l},[e]),Dt=({onTierChange:e,disabled:t})=>{const{gameProgress:n,config:o}=oe(),{i18n:i,levelConfig:s}=o,{currentTier:l,highestUnlockedTier:r}=n,c=re(s).getTotalTiers();return m("div",{className:"tier-selector",children:m("select",{value:l,onChange:d=>{d.target&&d.target.value&&e(Number(d.target.value))},disabled:t,className:"tier-dropdown",children:Array.from({length:c},(d,u)=>u+1).map(d=>m("option",{value:d,disabled:d>r,children:i.tier+" "+d},`tier-${d}`))})})},Ot=({onLevelChange:e,disabled:t})=>{const{gameProgress:n,config:o}=oe(),{i18n:i,levelConfig:s}=o,{currentTier:l,levelScores:r,currentLevel:a,highestUnlockedLevel:c}=n,d=re(s),u=Z(()=>{const[h,f]=d.getTierLevelsRange(l);return Array.from({length:f-h+1},(g,_)=>{const v=h+_,T=r[v]||0;return{level:v,score:T}})},[l,r]);return m("div",{className:"level-selector",children:m("select",{value:a,onChange:h=>{h.target&&h.target.value&&e(Number(h.target.value))},disabled:t,className:"level-dropdown",children:u.map(({level:h,score:f})=>m("option",{value:h,disabled:h>c,children:`${i.level} ${h} ${"★".repeat(f)}`},`level-${h}`))})})},ie=({isOpen:e,title:t,className:n="",message:o,children:i,noConfirm:s=!1,noCancel:l=!1,confirmText:r="OK",cancelText:a="Cancel",confirmClass:c="",cancelClass:d="",onConfirm:u,onCancel:h})=>{const f=x(null);return I(()=>{const g=_=>{_.key==="Escape"&&h?.()};return e&&document.addEventListener("keydown",g),()=>{document.removeEventListener("keydown",g)}},[e,h]),m("div",{className:`maze-dialog-overlay ${e?"maze-dialog-visible":""}`,children:m("div",{className:"maze-dialog "+n,ref:f,children:[m("div",{className:"maze-dialog-title",children:t}),m("div",{className:"maze-dialog-content",children:i||m("div",{className:"maze-dialog-message",children:o})}),(!l||!s)&&m("div",{className:"maze-dialog-buttons",children:[!l&&m("button",{type:"button",className:"maze-dialog-cancel "+d,onClick:h,children:a}),!s&&m("button",{type:"button",className:"maze-dialog-confirm "+c,onClick:u,children:r})]})]})})},W={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)}},$t=()=>{const{gameProgress:e,setGameProgress:t,gamePlayState:n,setGamePlayState:o,gamePlayStateRef:i,resetGame:s,config:l}=oe(),{i18n:r,levelConfig:a}=l,c=re(a),{levelTransitioning:d,showClue:u}=n,{highestUnlockedLevel:h,totalScore:f}=e,g=c.getTotalLevels(),[_,v]=U(!1),[T,b]=U(!1),[C,p]=U(!1),S=O=>{const $=c.getFirstLevelOfTier(O);c.isLevelUnlocked($,h)&&(t(G=>({...G,currentTier:O})),w($))},w=O=>{c.isLevelUnlocked(O,h)&&(t($=>({...$,currentLevel:O})),W.show(r.levelGoToast.replace("%LEVEL%",O.toString())))},y=()=>{v(!0)},z=()=>{v(!1)},N=()=>{p(!0)},E=()=>{p(!1)},k=()=>{W.show(u?r.cluePathDisabled:r.cluePathEnabled),o(()=>({...i.current,showClue:!i.current.showClue})),p(!1)},L=()=>{b(!0)},P=()=>{s(),b(!1),W.show(r.resetDoneToast)},R=()=>{b(!1)};return m("div",{class:"game-panel-container",children:[m("div",{className:"game-controls",children:[m("div",{className:"selectors-container",children:[m(Dt,{onTierChange:S,disabled:d}),m(Ot,{onLevelChange:w,disabled:d})]}),m("button",{className:`settings-clue-button ${u?"clue-on":"clue-off"}`,disabled:u,title:"Toggle Clue",onClick:N,children:u?r.clueOn:r.clueOff})]}),m("div",{className:"game-settings",children:m("span",{className:"game-settings-icon",onClick:y,children:"★ "+f})}),m(ie,{isOpen:_,title:r.settings,noConfirm:!0,cancelText:r.close,onCancel:z,children:[m("div",{className:"settings-stats",children:[m("div",{children:r.levelComplete+`: ${h}/${g}`}),m("div",{children:r.starsCollected+": "+f}),m("div",{children:r.avgStarPerLevel+": "+(f/h).toFixed(2)})]}),m("div",{className:"settings-item-box",children:[m("button",{className:"settings-reset-button",title:"Reset Game",onClick:L,children:r.reset}),m("div",{className:"settings-item-tip",children:r.resetTip})]})]}),m(ie,{isOpen:T,title:r.confirmReset,message:r.confirmResetMessage,confirmText:r.reset,cancelText:r.cancel,onConfirm:P,onCancel:R}),m(ie,{isOpen:C,title:r.confirmClue,message:r.confirmClueMessage,confirmText:r.confirm,cancelText:r.cancel,onConfirm:k,onCancel:E})]})};function Ae(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Ut(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&&Ut(e.prototype,t),e}function ut(e){return+e.replace(/px/,"")}function Gt(e){var t=window.devicePixelRatio,n=getComputedStyle(e),o=ut(n.getPropertyValue("width")),i=ut(n.getPropertyValue("height"));e.setAttribute("width",(o*t).toString()),e.setAttribute("height",(i*t).toString())}function q(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 dt(e){return e[q(0,e.length)]}var jt=.00125,Wt=5e-4,qt=9e-4,Ht=1e-5,Bt=6,Vt=80,Xt=.9,Yt=1.7,Kt=.2,Jt=.6,Zt=.03,Qt=.07,en=15,tn=82,nn=100,on=250,rn=40,sn=["#fcf403","#62fc03","#f4fc03","#03e7fc","#03fca5","#a503fc","#fc03ad","#fc03c2"];function ht(e){var t=1920;return Math.log(e)/Math.log(t)}var ft=function(){function e(t){Ae(this,e);var n=t.initialPosition,o=t.direction,i=t.confettiRadius,s=t.confettiColors,l=t.emojis,r=t.emojiSize,a=t.canvasWidth,c=q(Xt,Yt,3),d=c*ht(a);this.confettiSpeed={x:d,y:d},this.finalConfettiSpeedX=q(Kt,Jt,3),this.rotationSpeed=l.length?.01:q(Zt,Qt,3)*ht(a),this.dragForceCoefficient=q(Wt,qt,6),this.radius={x:i,y:i},this.initialRadius=i,this.rotationAngle=o==="left"?q(0,.2,3):q(-.2,0,3),this.emojiSize=r,this.emojiRotationAngle=q(0,2*Math.PI),this.radiusYUpdateDirection="down";var u=o==="left"?q(tn,en)*Math.PI/180:q(-15,-82)*Math.PI/180;this.absCos=Math.abs(Math.cos(u)),this.absSin=Math.abs(Math.sin(u));var h=q(-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=l.length?null:dt(s),this.emoji=l.length?dt(l):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,l=this.emoji,r=this.rotationAngle,a=this.emojiRotationAngle,c=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()):l&&(n.font="".concat(c,"px serif"),n.save(),n.translate(d*o.x,d*o.y),n.rotate(a),n.textAlign="center",n.fillText(l,0,0),n.restore())}},{key:"updatePosition",value:function(n,o){var i=this.confettiSpeed,s=this.dragForceCoefficient,l=this.finalConfettiSpeedX,r=this.radiusYUpdateDirection,a=this.rotationSpeed,c=this.createdAt,d=this.direction,u=o-c;if(i.x>l&&(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+jt*Math.pow(u,2)/2,this.rotationSpeed-=this.emoji?1e-4:Ht*n,this.rotationSpeed<0&&(this.rotationSpeed=0),this.emoji){this.emojiRotationAngle+=this.rotationSpeed*n%(2*Math.PI);return}r==="down"?(this.radius.y-=n*a,this.radius.y<=0&&(this.radius.y=0,this.radiusYUpdateDirection="up")):(this.radius.y+=n*a,this.radius.y>=this.initialRadius&&(this.radius.y=this.initialRadius,this.radiusYUpdateDirection="down"))}},{key:"getIsVisibleOnCanvas",value:function(n){return this.currentPosition.y<n+nn}}]),e}();function ln(){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 an(e){var t=e.confettiRadius,n=t===void 0?Bt:t,o=e.confettiNumber,i=o===void 0?e.confettiesNumber||(e.emojis?rn:on):o,s=e.confettiColors,l=s===void 0?sn:s,r=e.emojis,a=r===void 0?e.emojies||[]:r,c=e.emojiSize,d=c===void 0?Vt:c;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:l,emojis:a,emojiSize:d}}var cn=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,l=n.timeDelta,r=n.currentTime;this.shapes=this.shapes.filter(function(a){return a.updatePosition(l,r),a.draw(s.canvasContext),i?a.getIsVisibleOnCanvas(o):!0})}}]),e}(),un=function(){function e(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Ae(this,e),this.activeConfettiBatches=[],this.canvas=t.canvas||ln(),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,Gt(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(l){return l.processShapes({timeDelta:o,currentTime:n},i,s),s?!l.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=an(n),i=o.confettiRadius,s=o.confettiNumber,l=o.confettiColors,r=o.emojis,a=o.emojiSize,c=this.canvas.getBoundingClientRect(),d=c.width,u=c.height,h=u*5/7,f={x:0,y:h},g={x:d,y:h},_=new cn(this.canvasContext),v=0;v<s/2;v++){var T=new ft({initialPosition:f,direction:"right",confettiRadius:i,confettiColors:l,confettiNumber:s,emojis:r,emojiSize:a,canvasWidth:d}),b=new ft({initialPosition:g,direction:"left",confettiRadius:i,confettiColors:l,confettiNumber:s,emojis:r,emojiSize:a,canvasWidth:d});_.addShapes(T,b)}return this.activeConfettiBatches.push(_),this.queueAnimationFrameIfNeeded(),_.getBatchCompletePromise()}},{key:"clearCanvas",value:function(){this.activeConfettiBatches=[]}},{key:"destroyCanvas",value:function(){this.canvas.remove()}}]),e}();const dn=new un,Ie=3,hn=({onRetry:e})=>{const{config:t,currentScore:n,gamePlayState:o,setGamePlayState:i,gameProgress:s,setGameProgress:l}=oe(),{i18n:r,levelConfig:a}=t,[c,d,u]=n,{foodCollected:h,totalFoodCount:f,playerAtExit:g,levelTransitioning:_}=o,{currentLevel:v}=s,[T,b]=U(!1);I(()=>{g&&_&&(dn.addConfetti(),W.show(r.levelCompleteToast),b(!0))},[g,_]);const C=re(a),p=C.getTotalLevels(),S=Z(()=>v>=p,[v,p]),w=()=>{b(!1),W.show(r.levelRestartToast),e?.()},y=()=>{b(!1),i(E=>({...E,isGameActive:!0,levelTransitioning:!1}))},z=()=>{b(!1);const E=C.getNextLevelInfo(v);if(!E)return;const{nextLevel:k,nextTier:L,isTierChange:P}=E;P&&W.show(r.tierUnlockedToast.replace("%TIER%",L.toString())),l(R=>({...R,currentLevel:k,currentTier:L,highestUnlockedLevel:Math.max(R.highestUnlockedLevel,k),highestUnlockedTier:Math.max(R.highestUnlockedTier,L),levelScores:{...R.levelScores,[R.currentLevel]:Math.max(Object.values(n).filter(Boolean).length,R.levelScores[R.currentLevel]||0)}}))},N=()=>{b(!1),l(E=>{const k=Math.max(Object.values(n).filter(Boolean).length,E.levelScores[E.currentLevel]||0),L={...E.levelScores,[E.currentLevel]:k};let P=0,R=0;const O=Object.entries(L).sort(($,G)=>Number($[0])-Number(G[0]));for(const[$,G]of O)if(G<Ie){P=Number($),R=C.getTierByLevel(P);break}return(P>0&&P!==v||k<Ie)&&W.show(r.notCompleteLevel),(P===0||k<Ie)&&e?.(),{...E,currentLevel:P||E.currentLevel,currentTier:R||E.currentTier,levelScores:L}})};return I(()=>{const E=document.querySelector(".maze-game-container"),k=L=>{T&&((L.key===" "||L.code==="Space")&&E&&(E.contains(document.activeElement)||document.activeElement===document.body)&&(L.preventDefault(),S?N():z()),(L.key==="r"||L.code==="KeyR")&&w(),(L.key==="c"||L.code==="KeyC")&&y())};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[T,S]),m(ie,{className:"level-complete-dialog",isOpen:T,title:r.congratulations,cancelText:r.retry+" (R)",onCancel:w,noConfirm:!!d,confirmText:r.continue+" (C)",onConfirm:y,confirmClass:"maze-continue-btn",children:[m("div",{className:"maze-summary-message",children:[!!c&&m("div",{children:"★ - "+r.findYourExit}),m("div",{children:u?"★ - "+r.withoutClue:"☆ - "+r.withClue}),m("div",{children:(d?"★ - "+r.collectAllStars:"☆ - "+r.notCollectAllStars)+` (${h}/${f})`})]}),S&&m("div",{className:"all-levels-completed",children:r.allLevelsCompleted}),m("div",{className:"maze-go-next",children:S?m("button",{className:"maze-go-next-btn",type:"button",onClick:N,children:[m("span",{children:r.lastOK}),m("span",{className:"spacebar-tip",children:`(${r.spacebarTip})`})]}):m("button",{className:"maze-go-next-btn",type:"button",onClick:z,children:[m("span",{children:r.nextLevel}),m("span",{className:"spacebar-tip",children:`(${r.spacebarTip})`})]})}),!d&&m("div",{className:"not-all-stars-collected",children:r.continueMessage})]})},mt=(e,t)=>{const n=x({canvasWidth:0,canvasHeight:0});return I(()=>{const o=()=>{const s=e.current;if(!s)return;const l=s.parentElement;if(!l)return;const r=l.clientWidth;if(r===0)return;const a=window.devicePixelRatio||1;s.style.width=`${r}px`,s.style.height=`${r}px`;const c=r*a,d=r*a;s.width=c,s.height=d,n.current={canvasWidth:c,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},_t=(e,t,n)=>{const o=x({cellWidth:0,cellHeight:0});return I(()=>{const i=()=>{const l=e.current,r=t.maze;if(!l||!r)return;const{rows:a,cols:c}=r;if(a<=0||c<=0)return;const d=(l.width-n*2)/c,u=(l.height-n*2)/a;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},_e={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]},vt=({gamePlayStateRef:e,setGamePlayState:t,moveSpeed:n,moveSpeedRef:o,playerRadius:i,onFoodCollected:s,onExitReached:l,onFirstMove:r})=>{const a=()=>o?.current??n??.03,c=x(!1),d=x(new Set),u=x(!1),h=rt((C,p)=>{const S=e.current;if(!S.maze)return{canMove:!1,newCell:null};const w=a(),[y,z]=_e[C];if(gt(p,y,z,i,w,S.maze))return{canMove:!1,newCell:null};const{row:E,col:k}=p,L=E+y*w,P=k+z*w,R=-.5,O=S.maze.rows,$=S.maze.cols;if(L<R||L>=O||P<R||P>=$)return{canMove:!1,newCell:null};const G=E<0?0:Math.floor(E),Y=k<0?0:Math.floor(k),V=L<0?0:Math.floor(L),Q=P<0?0:Math.floor(P);return V!==G||Q!==Y?S.maze.isValid(V,Q)?{canMove:!0,newCell:{row:V,col:Q}}:{canMove:!1,newCell:null}:{canMove:!0,newCell:null}},[i,a]),f=()=>{const C=e.current,{row:p,col:S}=C.playerCell,w=i*2,y=C.foodCells.findIndex(E=>Math.sqrt(Math.pow(p-E.row,2)+Math.pow(S-E.col,2))<w);y!==-1&&s&&(s(),e.current={...e.current,foodCollected:e.current.foodCollected+1,foodCells:e.current.foodCells.filter((E,k)=>k!==y)});const N=_n(C.playerCell,C.exitCell,C.maze);N&&!e.current.playerAtExit?(e.current={...e.current,playerAtExit:!0,isGameActive:!1,levelTransitioning:!0},l&&l(),requestIdleCallback(()=>{t(()=>({...e.current}))},{timeout:10})):!N&&e.current.playerAtExit&&(e.current={...e.current,playerAtExit:!1,isGameActive:!0,levelTransitioning:!1})},g=C=>{const p=e.current,S=Math.round(C.row),w=Math.round(C.col),y=p.playerPath[p.playerPath.length-1],z=y.row===S&&y.col===w,N=Math.abs(y.row-S),E=Math.abs(y.col-w);if((N===1&&E===0||N===0&&E===1)&&!z){const L=`${y.row},${y.col}-${S},${w}`;e.current={...e.current,playerPath:[...e.current.playerPath,{row:S,col:w}],visitCounts:{...e.current.visitCounts,[L]:(e.current.visitCounts[L]||0)+1}}}},_=()=>{if(c.current||d.current.size===0)return;const C=e.current;!C.playerCell||!Array.from(d.current).some(S=>{const{canMove:w}=h(S,C.playerCell);return w})||(!u.current&&r&&(u.current=!0,r()),c.current=!0)};I(()=>{const C=w=>{if(w.key==="ArrowUp"||w.key==="ArrowDown"||w.key==="ArrowLeft"||w.key==="ArrowRight"||w.key===" "){const y=document.activeElement;if(y&&(y.tagName==="INPUT"||y.tagName==="TEXTAREA"||y.getAttribute("contenteditable")==="true"))return;w.preventDefault()}},p=w=>{const y=w.key;if(!(y in _e))return;const z=document.activeElement;z&&(z.tagName==="INPUT"||z.tagName==="TEXTAREA"||z.getAttribute("contenteditable")==="true")||(w.preventDefault(),e.current.isGameActive&&(d.current.has(y)||(d.current.add(y),c.current||_())))},S=w=>{const y=w.key;if(!(y in _e))return;const z=document.activeElement;z&&(z.tagName==="INPUT"||z.tagName==="TEXTAREA"||z.getAttribute("contenteditable")==="true")||(w.preventDefault(),d.current.delete(y),d.current.size===0&&T())};return window.addEventListener("keydown",C,{capture:!0}),window.addEventListener("keydown",p),window.addEventListener("keyup",S),()=>{window.removeEventListener("keydown",C,{capture:!0}),window.removeEventListener("keydown",p),window.removeEventListener("keyup",S)}},[]);const v=rt(()=>{if(!c.current||d.current.size===0)return e.current.playerCell;const C=a(),p=e.current.playerCell;let S=0,w=0,y=0;for(const D of d.current){const{canMove:j}=h(D,p);if(j){const[ee,we]=_e[D];S+=ee,w+=we,y++}}if(y===0)return e.current.playerCell;const z=Math.sqrt(S*S+w*w),N=z>0?S/z:0,E=z>0?w/z:0,k=Number((p.row+N*C).toFixed(2)),L=Number((p.col+E*C).toFixed(2)),P=k-p.row,R=L-p.col,O=Math.sqrt(P*P+R*R);if(O>0){const D=P/O,j=R/O;if(gt(p,D,j,i,O,e.current.maze))return e.current.playerCell}e.current.playerCell={row:k,col:L},f();const $=p.row<0?0:Math.round(p.row),G=p.col<0?0:Math.round(p.col),Y=k<0?0:Math.round(k),V=L<0?0:Math.round(L);return(Y!==$||V!==G)&&g({row:Y,col:V}),e.current.playerCell},[a,h]),T=()=>{c.current=!1,d.current.clear()};return{updatePlayerPos:v,resetMovingState:T,resetFirstMoveState:()=>{u.current=!1}}};function gt(e,t,n,o,i,s){const l=e.row+t*i,r=e.col+n*i,a={row:l,col:r},c=[],d=e.row<0?0:Math.floor(e.row),u=e.col<0?0:Math.floor(e.col);c.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,g]of h){const _=d+f,v=u+g;s.isValid(_,v)&&c.push({row:_,col:v})}for(const f of c){const g=fn(f.row,f.col,s);for(const _ of g)if(mn(a,_)<o)return!0}return!1}function fn(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 mn(e,t){const{start:n,end:o}=t,i=o.col-n.col,s=o.row-n.row,l=e.col-n.col,r=e.row-n.row,a=i*i+s*s;if(a===0)return Math.sqrt(l*l+r*r);const c=Math.max(0,Math.min(1,(l*i+r*s)/a)),d=n.col+c*i,u=n.row+c*s,h=e.col-d,f=e.row-u;return Math.sqrt(h*h+f*f)}function _n(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 pt(e,t,n,o,i){if(!e||!t.maze)return;const{canvasWidth:s,canvasHeight:l}=n,{cellWidth:r,cellHeight:a}=o,{maze:c,playerCell:d,exitCell:u,foodCells:h,showClue:f,playerPath:g,visitCounts:_}=t,{padding:v,wallWidth:T,wallColor:b,playerColor:C,playerRadius:p,foodColor:S,backgroundColor:w,clueColor:y,exitColor:z,exitWallWidth:N,exitDashArray:E}=i;e.clearRect(0,0,s,l),e.save(),e.fillStyle=w,e.fillRect(0,0,s,l),e.restore(),f&&yn({ctx:e,playerPath:g,visitCounts:_,cellWidth:r,cellHeight:a,padding:v,clueColor:y}),vn({ctx:e,maze:c,cellWidth:r,cellHeight:a,padding:v,wallColor:b,wallWidth:T}),pn({ctx:e,maze:c,exitCell:u,cellWidth:r,cellHeight:a,padding:v,exitColor:z,exitWallWidth:N,exitDashArray:E}),wn({ctx:e,foodCells:h,cellWidth:r,cellHeight:a,padding:v,foodColor:S}),gn({ctx:e,playerCell:d,playerRadius:p,cellWidth:r,cellHeight:a,padding:v,playerColor:C})}function vn({ctx:e,maze:t,cellWidth:n,cellHeight:o,padding:i,wallColor:s,wallWidth:l}){e.save(),e.strokeStyle=s,e.lineWidth=l,e.lineCap="round",e.beginPath(),bn(t,n,o,i).forEach(a=>{e.moveTo(a.x1,a.y1),e.lineTo(a.x2,a.y2)}),e.stroke(),e.restore()}function gn({ctx:e,playerCell:t,playerRadius:n,cellWidth:o,cellHeight:i,padding:s,playerColor:l}){const{x:r,y:a}=ve(t.row,t.col,o,i,s),c=Math.min(o,i)*Math.min(n,.5);e.save(),e.fillStyle=l,e.beginPath(),e.arc(r,a,c,0,Math.PI*2),e.fill(),e.restore()}function pn({ctx:e,maze:t,exitCell:n,cellWidth:o,cellHeight:i,padding:s,exitColor:l,exitWallWidth:r,exitDashArray:a=[8,12]}){const{row:c,col:d}=n;if(!t.isValid(c,d))return;const u=s+d*o,h=s+c*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=l,e.lineWidth=r,e.setLineDash(a),e.beginPath(),e.moveTo(u,h+i),e.lineTo(u+o,h+i),e.stroke(),e.restore()}function wn({ctx:e,foodCells:t,cellWidth:n,cellHeight:o,padding:i,foodColor:s}){e.fillStyle=s;const l=Math.min(n,o)*.25;t.forEach(r=>{const{x:a,y:c}=ve(r.row,r.col,n,o,i);Cn(e,a,c,l*1.2,5,l*.6)})}function Cn(e,t,n,o,i,s){e.save(),e.beginPath();for(let l=0;l<i*2;l++){const r=l%2===0?o:s,a=Math.PI*l/i;e.lineTo(t+r*Math.sin(a),n+r*Math.cos(a))}e.closePath(),e.fill(),e.restore()}function yn({ctx:e,playerPath:t,visitCounts:n,cellWidth:o,cellHeight:i,padding:s,clueColor:l}){if(!(!t||t.length<2||!n)){e.save();for(let r=1;r<t.length;r++){const a=t[r-1],c=t[r],d=`${a.row},${a.col}-${c.row},${c.col}`,u=`${c.row},${c.col}-${a.row},${a.col}`,h=(n[d]||0)+(n[u]||0),f=Math.min(.2+h*.1,.9),g=Math.max(3,o*.1)+h*.5;try{e.strokeStyle=l.replace(")",`, ${f})`).replace("rgb(","rgba(")}catch{e.strokeStyle=`rgba(255, 0, 0, ${f})`}e.lineWidth=g,e.lineCap="round",e.lineJoin="round";const{x:_,y:v}=ve(a.row,a.col,o,i,s),{x:T,y:b}=ve(c.row,c.col,o,i,s);e.beginPath(),e.moveTo(_,v),e.lineTo(T,b),e.stroke()}e.restore()}}function bn(e,t,n,o){const i=[];for(let s=0;s<e.rows;s++)for(let l=0;l<e.cols;l++){const r=e.grid[s][l],a=o+l*t,c=o+s*n;r.walls.top&&i.push({x1:a,y1:c,x2:a+t,y2:c}),r.walls.right&&i.push({x1:a+t,y1:c,x2:a+t,y2:c+n}),r.walls.bottom&&i.push({x1:a,y1:c+n,x2:a+t,y2:c+n}),r.walls.left&&i.push({x1:a,y1:c,x2:a,y2:c+n})}return i}function ve(e,t,n,o,i){return{x:i+t*n+n/2,y:i+e*o+o/2}}function Tn(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 kn{constructor(t,n){this.row=t,this.col=n}visited=!1;walls={top:!0,right:!0,bottom:!0,left:!0}}class wt{rows;cols;grid;seed;random;constructor(t,n,o,i,s={row:0,col:0},l={row:t-1,col:n-1}){this.rows=t,this.cols=n,this.seed=i??Math.floor(Math.random()*1e6),this.random=Tn(this.seed),this.grid=this.initializeGrid(),this.generate(o,s,l)}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 kn(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 l=t+s.r,r=n+s.c;this.isValid(l,r)&&o.push({row:l,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],l=this.grid[o][i];t===o+1?(s.walls.top=!1,l.walls.bottom=!1):t===o-1?(s.walls.bottom=!1,l.walls.top=!1):n===i+1?(s.walls.left=!1,l.walls.right=!1):n===i-1&&(s.walls.right=!1,l.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:l}=i,r=this.getUnvisitedNeighbors(s,l);if(r.length>0){const a=this.randomPick(r),{row:c,col:d}=a;this.removeWall(s,l,c,d),this.grid[c][d].visited=!0,t.push(a)}else t.pop()}}generateWithPrims(){const t=[],n=(s,l)=>{const r=this.getNeighbors(s,l);for(const a of r)!this.grid[a.row][a.col].visited&&!t.some(c=>c.row===a.row&&c.col===a.col)&&t.push(a)},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),l=t[s],{row:r,col:a}=l,c=this.getVisitedNeighbors(r,a);if(c.length>0){const d=this.randomPick(c);this.removeWall(r,a,d.row,d.col),this.grid[r][a].visited=!0,n(r,a)}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 Ct=(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},Sn=e=>e===1?2:e>=2&&e<=5?3:e>=6&&e<=11?4:e>=12&&e<=15?5:6,zn=(e,t)=>{if(!t)return console.error(`Cannot find Level ${e}'s config.`),null;const{size:n,seed:o,method:i,entry:s,exit:l}=t,r=n,a=n,c=s||{row:0,col:0},d=l||{row:r-1,col:a-1},u=new wt(r,a,i,o,c,d),h=Sn(e),f=[];for(let g=0;g<h;g++){let _;do _={row:Math.floor(u.random()*r),col:Math.floor(u.random()*a)};while(_.row===c.row&&_.col===c.col||_.row===d.row&&_.col===d.col||!Ct(u,_.row,_.col)||f.some(v=>v.row===_.row&&v.col===_.col));f.push(_)}return{isGameActive:!0,levelTransitioning:!1,maze:u,playerCell:c,exitCell:d,foodCells:f,playerAtExit:!1,foodCollected:0,totalFoodCount:h,showClue:!1,playerPath:[c],visitCounts:{[`${c.row},${c.col}`]:1}}},En=({size:e,seed:t,method:n,foodCount:o,foodRace:i,clue:s})=>{const l=e,r=e,a={row:0,col:0},c={row:l-1,col:r-1},d=new wt(l,r,n,t,a,c),u=[];if(i)for(let h=0;h<o;h++){let f,g=0;do f={row:Math.floor(d.random()*l),col:Math.floor(d.random()*r)},g++;while(g<50&&(f.row===a.row&&f.col===a.col||f.row===c.row&&f.col===c.col||!Ct(d,f.row,f.col)||u.some(_=>_.row===f.row&&_.col===f.col)));g<50&&u.push(f)}return{isGameActive:!0,levelTransitioning:!1,maze:d,playerCell:a,exitCell:c,foodCells:u,playerAtExit:!1,foodCollected:0,totalFoodCount:i?o:0,showClue:s,playerPath:[a],visitCounts:{[`${a.row},${a.col}`]:1}}};function Ln(){const{setGamePlayState:e,gamePlayState:t,gamePlayStateRef:n,gameProgress:o,config:i}=oe(),s=x(null),l=x(null),{i18n:r,levelConfig:a,renderConfig:c}=i,d=re(a),u=x(d.getLevelConfig(o.currentLevel));I(()=>{s.current&&W.attachTo(s.current)},[]);const h=x(),f=mt(l,()=>{h.current?.()}),g=_t(l,t,c.padding);I(()=>{u.current=d.getLevelConfig(o.currentLevel)},[o.currentLevel]);const _=()=>{const C=zn(o.currentLevel,u.current);C&&e(p=>({...p,...C}))};I(()=>{_()},[o.currentLevel]);const v=()=>{_()},{updatePlayerPos:T,resetMovingState:b}=vt({gamePlayStateRef:n,setGamePlayState:e,playerRadius:c.playerRadius,moveSpeed:c.gridMoveSpeed,onFoodCollected:()=>{const C=n.current.totalFoodCount-n.current.foodCollected-1;C>0?W.show(r.foodCollectedToast.replace("%NUM%",C.toString()),3e3):W.show(r.allFoodCollectedToast)}});return I(()=>{b()},[o.currentLevel,b]),I(()=>{let C,p=!document.hidden;const S=()=>{const z=l.current?.getContext("2d"),N=n.current;if(!(p&&N?.isGameActive&&z&&N?.maze)){C=requestAnimationFrame(S);return}T(),w(),C=requestAnimationFrame(S)},w=()=>{const z=l.current?.getContext("2d"),N=n.current;if(z&&N?.maze){const E=u.current?.wallWidth||c?.wallWidth,k=u.current?.exitColor||c?.exitColor,L=u.current?.exitWallWidth||c?.exitWallWidth,P=u.current?.exitDashArray||c?.exitDashArray;pt(z,N,f.current,g.current,{...c,wallWidth:E,exitColor:k,exitWallWidth:L,exitDashArray:P})}};h.current=w;const y=z=>{const N=p;p=!document.hidden&&document.visibilityState==="visible"&&(!z||z.type!=="blur"),!N&&p?n.current?.levelTransitioning===!1&&e({...n.current,isGameActive:!0}):N&&!p&&e({...n.current,isGameActive:!1})};return document.addEventListener("visibilitychange",y),window.addEventListener("blur",y),window.addEventListener("focus",y),C=requestAnimationFrame(S),()=>{cancelAnimationFrame(C),document.removeEventListener("visibilitychange",y),window.removeEventListener("blur",y),window.removeEventListener("focus",y)}},[]),I(()=>{W.show(r.useArrowKeyTips,3e3)},[]),m("div",{className:"maze-game-container",children:[m($t,{}),m(hn,{onRetry:v}),m("div",{className:"maze-canvas-container",ref:s,children:m("canvas",{ref:l,className:"maze-game-canvas"})})]})}const Nn=e=>{const t=Math.floor(e/60),n=e%60;return`${t.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`},Mn=({timer:e})=>{const[t,n]=U(e),o=x(),i=x(!1),s=x(0);return I(()=>{const l=()=>{!i.current&&!o.current&&(i.current=!0,o.current=setInterval(()=>{n(a=>(s.current=e-a+1,a<=1?(clearInterval(o.current),window.dispatchEvent(new CustomEvent("maze:timeUp")),0):a-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",l),window.addEventListener("maze:gameSuccess",r),()=>{window.removeEventListener("maze:firstMove",l),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]),m("div",{className:"single-maze-timer",children:m("span",{className:`maze-timer-text ${t<=10&&i.current?"maze-timer-warning":""}`,children:["⏱️ ",Nn(t)]})})};function An({config:e}){const{size:t,seed:n,method:o,foodCount:i,foodRace:s,clue:l,renderConfig:r,successCallback:a,failCallback:c,timer:d,i18n:u}=e,[h,f]=U({...Me}),[g,_]=U(!1),[v,T]=U(!0),[b,C]=U(!1),[p,S]=U(""),w=x(0),y=x(!1),z=x(!1),N=x(null),E=x(null),k=x(h),L=x(),P=mt(N,()=>{L.current?.()}),R=_t(N,h,r.padding);I(()=>{k.current=h},[h]);const{updatePlayerPos:O,resetMovingState:$,resetFirstMoveState:G}=vt({gamePlayStateRef:k,setGamePlayState:f,playerRadius:r.playerRadius,moveSpeed:r.gridMoveSpeed,onFoodCollected:()=>{console.log("Food collected in single maze")},onExitReached:()=>{if(!y.current){if(s&&k.current.foodCollected<k.current.totalFoodCount){S(`⭐️ ${u.foodMsg}`),C(!0),requestAnimationFrame(()=>{f(D=>({...D,playerAtExit:!1,isGameActive:!0,levelTransitioning:!1}))});return}V()}},onFirstMove:()=>{window.dispatchEvent(new CustomEvent("maze:firstMove"))}}),Y=()=>{y.current=!0,S(`⏰ ${u.failMsg}`),C(!0),f({...k.current,isGameActive:!1})},V=()=>{y.current=!0,z.current=!0,S(`🎉 ${u.successMsg}`),C(!0),window.dispatchEvent(new CustomEvent("maze:gameSuccess"))},Q=()=>{C(!1),y.current&&(T(!1),f(D=>({...D,showClue:!0})),z.current?a?.(w.current):c?.())};return I(()=>{(async()=>{_(!0);try{const j=En({size:t,seed:n,method:o,foodCount:i,foodRace:s,clue:l});k.current=j,f(j)}catch(j){console.error("Error generating single maze:",j)}finally{_(!1)}})()},[e]),I(()=>{let D;const j=!document.hidden,ee=()=>{const Ce=N.current?.getContext("2d"),se=k.current;if(!(j&&se?.isGameActive&&Ce&&se?.maze)){D=requestAnimationFrame(ee);return}O(),we(),D=requestAnimationFrame(ee)},we=()=>{const Ce=N.current?.getContext("2d"),se=k.current;Ce&&se?.maze&&pt(Ce,se,P.current,R.current,r)};return L.current=we,D=requestAnimationFrame(ee),()=>{cancelAnimationFrame(D)}},[]),I(()=>{$(),G()},[e,$,G]),I(()=>{const D=j=>{w.current=j.detail.timeUsed};return window.addEventListener("maze:timeUsed",D),window.addEventListener("maze:timeUp",Y),()=>{window.removeEventListener("maze:timeUsed",D),window.removeEventListener("maze:timeUp",Y)}},[]),g?m("div",{className:"single-maze-loading",children:m("div",{children:"Generating maze..."})}):h?m("div",{className:"maze-game-container",children:[v&&m(Mn,{timer:d}),m("div",{className:"single-maze-canvas-container",ref:E,children:m("canvas",{ref:N,className:"maze-game-canvas"})}),m(ie,{isOpen:b,title:p,noConfirm:!0,cancelText:"OK",onCancel:Q})]}):m("div",{className:"single-maze-error",children:m("div",{children:"Failed to generate maze"})})}const yt=[[{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"}]],bt={gridMoveSpeed:.07,padding:10,wallWidth:2,wallColor:"#000000",foodColor:"#4CAF50",clueColor:"rgb(255,0,0)",backgroundColor:"#ffffff",playerColor:"#4CAF50",playerRadius:.2,exitColor:"#F44336",exitWallWidth:4,exitDashArray:[8,12]},ge={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."},renderConfig:bt,levelConfig:yt},pe={i18n:{successMsg:"Congratulations! You completed the maze!",failMsg:"Time is up!",foodMsg:"Please collect all stars before leaving!"},size:8,seed:12345,method:"backtracking",clue:!1,foodCount:0,foodRace:!1,renderConfig:bt,timer:10*60,successCallback:()=>{console.log("🎉 Single maze completed successfully!")},failCallback:()=>{console.log("⏰ Time is up! Game failed.")}};function Pn({config:e={}}){const t={...ge.i18n,...e.i18n||{}},n={...ge.renderConfig,...e.renderConfig||{}},o=e.levelConfig||yt,i={...ge,...e,i18n:t,levelConfig:o,renderConfig:n};return m(Ft,{config:i,children:m(Ln,{})})}function In({config:e={}}){const t={...pe.i18n,...e.i18n||{}},n={...pe.renderConfig,...e.renderConfig||{}},o={...pe,...e,i18n:t,renderConfig:n};return m(An,{config:o})}const xn={root:"https://unpkg.com/@roudanio/maze@0.2.4/dist/",...ge};`${JSON.stringify(xn,null,2)}`;const Rn={root:"https://unpkg.com/@roudanio/maze@0.2.4/dist/",...pe};return`${JSON.stringify(Rn,(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(B,M){typeof exports=="object"&&typeof module<"u"?module.exports=M():typeof define=="function"&&define.amd?define(M):(B=typeof globalThis<"u"?globalThis:B||self,B.Maze=M())})(this,function(){"use strict";var B,M,xe,X,Re,Fe,De,Oe,ye,be,Te,$e,te={},Ue=[],Tt=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,le=Array.isArray;function H(e,t){for(var n in t)e[n]=t[n];return e}function ke(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function kt(e,t,n){var o,i,s,l={};for(s in t)s=="key"?o=t[s]:s=="ref"?i=t[s]:l[s]=t[s];if(arguments.length>2&&(l.children=arguments.length>3?B.call(arguments,2):n),typeof e=="function"&&e.defaultProps!=null)for(s in e.defaultProps)l[s]==null&&(l[s]=e.defaultProps[s]);return ae(e,l,o,i,null)}function ae(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??++xe,__i:-1,__u:0};return i==null&&M.vnode!=null&&M.vnode(s),s}function ce(e){return e.children}function ue(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 Se(e){(!e.__d&&(e.__d=!0)&&X.push(e)&&!de.__r++||Re!=M.debounceRendering)&&((Re=M.debounceRendering)||Fe)(de)}function de(){for(var e,t,n,o,i,s,l,r=1;X.length;)X.length>r&&X.sort(De),e=X.shift(),r=X.length,e.__d&&(n=void 0,i=(o=(t=e).__v).__e,s=[],l=[],t.__P&&((n=H({},o)).__v=o.__v+1,M.vnode&&M.vnode(n),ze(t.__P,n,o,t.__n,t.__P.namespaceURI,32&o.__u?[i]:null,s,i??K(o),!!(32&o.__u),l),n.__v=o.__v,n.__.__k[n.__i]=n,Be(s,n,l),n.__e!=i&&Ge(n)));de.__r=0}function je(e,t,n,o,i,s,l,r,a,c,d){var u,h,f,g,_,v,T=o&&o.__k||Ue,b=t.length;for(a=St(n,t,T,a,b),u=0;u<b;u++)(f=n.__k[u])!=null&&(h=f.__i==-1?te:T[f.__i]||te,f.__i=u,v=ze(e,f,h,i,s,l,r,a,c,d),g=f.__e,f.ref&&h.ref!=f.ref&&(h.ref&&Ee(h.ref,null,f),d.push(f.ref,f.__c||g,f)),_==null&&g!=null&&(_=g),4&f.__u||h.__k===f.__k?a=We(f,a,e):typeof f.type=="function"&&v!==void 0?a=v:g&&(a=g.nextSibling),f.__u&=-7);return n.__e=_,a}function St(e,t,n,o,i){var s,l,r,a,c,d=n.length,u=d,h=0;for(e.__k=new Array(i),s=0;s<i;s++)(l=t[s])!=null&&typeof l!="boolean"&&typeof l!="function"?(a=s+h,(l=e.__k[s]=typeof l=="string"||typeof l=="number"||typeof l=="bigint"||l.constructor==String?ae(null,l,null,null,null):le(l)?ae(ce,{children:l},null,null,null):l.constructor==null&&l.__b>0?ae(l.type,l.props,l.key,l.ref?l.ref:null,l.__v):l).__=e,l.__b=e.__b+1,r=null,(c=l.__i=zt(l,n,a,u))!=-1&&(u--,(r=n[c])&&(r.__u|=2)),r==null||r.__v==null?(c==-1&&(i>d?h--:i<d&&h++),typeof l.type!="function"&&(l.__u|=4)):c!=a&&(c==a-1?h--:c==a+1?h++:(c>a?h--:h++,l.__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){var o,i;if(typeof e.type=="function"){for(o=e.__k,i=0;o&&i<o.length;i++)o[i]&&(o[i].__=e,t=We(o[i],t,n));return t}e.__e!=t&&(t&&e.type&&!n.contains(t)&&(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 zt(e,t,n,o){var i,s,l=e.key,r=e.type,a=t[n];if(a===null&&e.key==null||a&&l==a.key&&r==a.type&&(2&a.__u)==0)return n;if(o>(a!=null&&(2&a.__u)==0?1:0))for(i=n-1,s=n+1;i>=0||s<t.length;){if(i>=0){if((a=t[i])&&(2&a.__u)==0&&l==a.key&&r==a.type)return i;i--}if(s<t.length){if((a=t[s])&&(2&a.__u)==0&&l==a.key&&r==a.type)return s;s++}}return-1}function qe(e,t,n){t[0]=="-"?e.setProperty(t,n??""):e[t]=n==null?"":typeof n!="number"||Tt.test(t)?n:n+"px"}function he(e,t,n,o,i){var s;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")),t=t.toLowerCase()in e||t=="onFocusOut"||t=="onFocusIn"?t.toLowerCase().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 He(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(M.event?M.event(t):t)}}}function ze(e,t,n,o,i,s,l,r,a,c){var d,u,h,f,g,_,v,T,b,C,p,S,w,y,z,N,E,k=t.type;if(t.constructor!=null)return null;128&n.__u&&(a=!!(32&n.__u),s=[r=t.__e=n.__e]),(d=M.__b)&&d(t);e:if(typeof k=="function")try{if(T=t.props,b="prototype"in k&&k.prototype.render,C=(d=k.contextType)&&o[d.__c],p=d?C?C.props.value:d.__:o,n.__c?v=(u=t.__c=n.__c).__=u.__E:(b?t.__c=u=new k(T,p):(t.__c=u=new ue(T,p),u.constructor=k,u.render=Lt),C&&C.sub(u),u.props=T,u.state||(u.state={}),u.context=p,u.__n=o,h=u.__d=!0,u.__h=[],u._sb=[]),b&&u.__s==null&&(u.__s=u.state),b&&k.getDerivedStateFromProps!=null&&(u.__s==u.state&&(u.__s=H({},u.__s)),H(u.__s,k.getDerivedStateFromProps(T,u.__s))),f=u.props,g=u.state,u.__v=t,h)b&&k.getDerivedStateFromProps==null&&u.componentWillMount!=null&&u.componentWillMount(),b&&u.componentDidMount!=null&&u.__h.push(u.componentDidMount);else{if(b&&k.getDerivedStateFromProps==null&&T!==f&&u.componentWillReceiveProps!=null&&u.componentWillReceiveProps(T,p),!u.__e&&u.shouldComponentUpdate!=null&&u.shouldComponentUpdate(T,u.__s,p)===!1||t.__v==n.__v){for(t.__v!=n.__v&&(u.props=T,u.state=u.__s,u.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(L){L&&(L.__=t)}),S=0;S<u._sb.length;S++)u.__h.push(u._sb[S]);u._sb=[],u.__h.length&&l.push(u);break e}u.componentWillUpdate!=null&&u.componentWillUpdate(T,u.__s,p),b&&u.componentDidUpdate!=null&&u.__h.push(function(){u.componentDidUpdate(f,g,_)})}if(u.context=p,u.props=T,u.__P=e,u.__e=!1,w=M.__r,y=0,b){for(u.state=u.__s,u.__d=!1,w&&w(t),d=u.render(u.props,u.state,u.context),z=0;z<u._sb.length;z++)u.__h.push(u._sb[z]);u._sb=[]}else do u.__d=!1,w&&w(t),d=u.render(u.props,u.state,u.context),u.state=u.__s;while(u.__d&&++y<25);u.state=u.__s,u.getChildContext!=null&&(o=H(H({},o),u.getChildContext())),b&&!h&&u.getSnapshotBeforeUpdate!=null&&(_=u.getSnapshotBeforeUpdate(f,g)),N=d,d!=null&&d.type===ce&&d.key==null&&(N=Ve(d.props.children)),r=je(e,le(N)?N:[N],t,n,o,i,s,l,r,a,c),u.base=t.__e,t.__u&=-161,u.__h.length&&l.push(u),v&&(u.__E=u.__=null)}catch(L){if(t.__v=null,a||s!=null)if(L.then){for(t.__u|=a?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--;)ke(s[E]);else t.__e=n.__e,t.__k=n.__k;M.__e(L,t,n)}else s==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):r=t.__e=Et(n.__e,t,n,o,i,s,l,a,c);return(d=M.diffed)&&d(t),128&t.__u?void 0:r}function Be(e,t,n){for(var o=0;o<n.length;o++)Ee(n[o],n[++o],n[++o]);M.__c&&M.__c(t,e),e.some(function(i){try{e=i.__h,i.__h=[],e.some(function(s){s.call(i)})}catch(s){M.__e(s,i.__v)}})}function Ve(e){return typeof e!="object"||e==null||e.__b&&e.__b>0?e:le(e)?e.map(Ve):H({},e)}function Et(e,t,n,o,i,s,l,r,a){var c,d,u,h,f,g,_,v=n.props,T=t.props,b=t.type;if(b=="svg"?i="http://www.w3.org/2000/svg":b=="math"?i="http://www.w3.org/1998/Math/MathML":i||(i="http://www.w3.org/1999/xhtml"),s!=null){for(c=0;c<s.length;c++)if((f=s[c])&&"setAttribute"in f==!!b&&(b?f.localName==b:f.nodeType==3)){e=f,s[c]=null;break}}if(e==null){if(b==null)return document.createTextNode(T);e=document.createElementNS(i,b,T.is&&T),r&&(M.__m&&M.__m(t,s),r=!1),s=null}if(b==null)v===T||r&&e.data==T||(e.data=T);else{if(s=s&&B.call(e.childNodes),v=n.props||te,!r&&s!=null)for(v={},c=0;c<e.attributes.length;c++)v[(f=e.attributes[c]).name]=f.value;for(c in v)if(f=v[c],c!="children"){if(c=="dangerouslySetInnerHTML")u=f;else if(!(c in T)){if(c=="value"&&"defaultValue"in T||c=="checked"&&"defaultChecked"in T)continue;he(e,c,null,f,i)}}for(c in T)f=T[c],c=="children"?h=f:c=="dangerouslySetInnerHTML"?d=f:c=="value"?g=f:c=="checked"?_=f:r&&typeof f!="function"||v[c]===f||he(e,c,f,v[c],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,le(h)?h:[h],t,n,o,b=="foreignObject"?"http://www.w3.org/1999/xhtml":i,s,l,s?s[0]:n.__k&&K(n,0),r,a),s!=null)for(c=s.length;c--;)ke(s[c]);r||(c="value",b=="progress"&&g==null?e.removeAttribute("value"):g!=null&&(g!==e[c]||b=="progress"&&!g||b=="option"&&g!=v[c])&&he(e,c,g,v[c],i),c="checked",_!=null&&_!=e[c]&&he(e,c,_,v[c],i))}return e}function Ee(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){M.__e(i,n)}}function Xe(e,t,n){var o,i;if(M.unmount&&M.unmount(e),(o=e.ref)&&(o.current&&o.current!=e.__e||Ee(o,null,t)),(o=e.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(s){M.__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||ke(e.__e),e.__c=e.__=e.__e=void 0}function Lt(e,t,n){return this.constructor(e,n)}function Ye(e,t,n){var o,i,s,l;t==document&&(t=document.documentElement),M.__&&M.__(e,t),i=(o=!1)?null:t.__k,s=[],l=[],ze(t,e=t.__k=kt(ce,null,[e]),i||te,te,t.namespaceURI,i?null:t.firstChild?B.call(t.childNodes):null,s,i?i.__e:t.firstChild,o,l),Be(s,e,l)}function Nt(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(l){l.__e=!0,Se(l)})},this.sub=function(s){o.add(s);var l=s.componentWillUnmount;s.componentWillUnmount=function(){o&&o.delete(s),l&&l.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}B=Ue.slice,M={__e:function(e,t,n,o){for(var i,s,l;t=t.__;)if((i=t.__c)&&!i.__)try{if((s=i.constructor)&&s.getDerivedStateFromError!=null&&(i.setState(s.getDerivedStateFromError(e)),l=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(e,o||{}),l=i.__d),l)return i.__E=i}catch(r){e=r}throw e}},xe=0,ue.prototype.setState=function(e,t){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=H({},this.state),typeof e=="function"&&(e=e(H({},n),this.props)),e&&H(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),Se(this))},ue.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),Se(this))},ue.prototype.render=ce,X=[],Fe=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,De=function(e,t){return e.__v.__b-t.__v.__b},de.__r=0,Oe=/(PointerCapture)$|Capture$/i,ye=0,be=He(!1),Te=He(!0),$e=0;var Mt=0;function m(e,t,n,o,i,s){t||(t={});var l,r,a=t;if("ref"in a)for(r in a={},t)r=="ref"?l=t[r]:a[r]=t[r];var c={type:e,props:a,key:n,ref:l,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Mt,__i:-1,__u:0,__source:i,__self:s};if(typeof e=="function"&&(l=e.defaultProps))for(r in l)a[r]===void 0&&(a[r]=l[r]);return M.vnode&&M.vnode(c),c}var J,P,Le,Ke,ne=0,Je=[],D=M,Ze=D.__b,Qe=D.__r,et=D.diffed,tt=D.__c,nt=D.unmount,ot=D.__;function fe(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,At(lt,e)}function At(e,t,n){var o=fe(J++,2);if(o.t=e,!o.__c&&(o.__=[lt(void 0,t),function(r){var a=o.__N?o.__N[0]:o.__[0],c=o.t(a,r);a!==c&&(o.__N=[c,o.__[1]],o.__c.setState({}))}],o.__c=P,!P.__f)){var i=function(r,a,c){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,a,c);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,a,c)||u};P.__f=!0;var s=P.shouldComponentUpdate,l=P.componentWillUpdate;P.componentWillUpdate=function(r,a,c){if(this.__e){var d=s;s=void 0,i(r,a,c),s=d}l&&l.call(this,r,a,c)},P.shouldComponentUpdate=i}return o.__N||o.__}function x(e,t){var n=fe(J++,3);!D.__s&&st(n.__H,t)&&(n.__=e,n.u=t,P.__H.__h.push(n))}function R(e){return ne=5,Z(function(){return{current:e}},[])}function Z(e,t){var n=fe(J++,7);return st(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function rt(e,t){return ne=8,Z(function(){return e},t)}function Pt(e){var t=P.context[e.__c],n=fe(J++,9);return n.c=e,t?(n.__==null&&(n.__=!0,t.sub(P)),t.props.value):e.__}function It(){for(var e;e=Je.shift();)if(e.__P&&e.__H)try{e.__H.__h.forEach(me),e.__H.__h.forEach(Ne),e.__H.__h=[]}catch(t){e.__H.__h=[],D.__e(t,e.__v)}}D.__b=function(e){P=null,Ze&&Ze(e)},D.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),ot&&ot(e,t)},D.__r=function(e){Qe&&Qe(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(me),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)||xt)(It)),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(me),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{me(o)}catch(i){t=i}}),n.__H=void 0,t&&D.__e(t,n.__v))};var it=typeof requestAnimationFrame=="function";function xt(e){var t,n=function(){clearTimeout(o),it&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(n,100);it&&(t=requestAnimationFrame(n))}function me(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 lt(e,t){return typeof t=="function"?t(e):t}const Rt=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)}}}),at=Nt(void 0),ct={currentLevel:1,highestUnlockedLevel:1,currentTier:1,highestUnlockedTier:1,levelScores:{},totalScore:0},Me={isGameActive:!0,levelTransitioning:!1,maze:null,playerCell:{row:0,col:0},exitCell:{row:0,col:0},foodCells:[],playerAtExit:!1,foodCollected:0,totalFoodCount:0,showClue:!1,playerPath:[],visitCounts:{}},Ft=({children:e,config:t})=>{const n=Rt(t.lcPrefix+"progress"),o=n.loadGameData(),[i,s]=U(()=>o||{...ct});x(()=>{const u=Object.values(i.levelScores).reduce((h,f)=>h+f,0);s(h=>({...h,totalScore:u}))},[i.levelScores]),x(()=>{n.saveGameData(i)},[i.currentLevel,i.highestUnlockedLevel,i.currentTier,i.highestUnlockedTier,i.levelScores,i.totalScore]);const[l,r]=U({...Me}),a=R(l);x(()=>{a.current=l},[l]);const c=Z(()=>[l.playerAtExit?1:0,l.foodCollected===l.totalFoodCount?1:0,l.showClue?0:1],[l.playerAtExit,l.foodCollected,l.totalFoodCount,l.showClue]),d=()=>{n.resetGameData(),s({...ct}),r({...Me})};return m(at.Provider,{value:{gameProgress:i,setGameProgress:s,gamePlayState:l,setGamePlayState:r,gamePlayStateRef:a,currentScore:c,config:t,resetGame:d},children:e})},oe=()=>{const e=Pt(at);if(!e)throw new Error("useGameContext must be used within a GameProvider");return e},re=e=>Z(()=>{const t=e.map(r=>r.length),n=t.reduce((r,a)=>r+a,0),o=e.length,i=r=>{if(r<1||r>n)return 0;let a=0;for(let c=0;c<t.length;c++)if(a+=t[c],r<=a)return c+1;return 0},s=r=>r<1||r>o?0:t.slice(0,r-1).reduce((a,c)=>a+c,0)+1,l={getTotalLevels:()=>n,getTotalTiers:()=>o,getTierLevelsRange:r=>{if(r<1||r>o)return[0,0];const a=s(r),c=a+t[r-1]-1;return[a,c]},getTierByLevel:i,getFirstLevelOfTier:s,getLevelConfig:r=>{if(r<1||r>n)return null;const a=i(r),c=s(a),d=r-c;return e[a-1][d]},getTierConfig:r=>r<1||r>o?null:e[r-1],isLevelUnlocked:(r,a)=>r<=a,isTierUnlocked:(r,a)=>r<=a,getNextLevelInfo:r=>{if(r>=n)return null;const a=r+1,c=i(r),d=i(a);return{nextLevel:a,nextTier:d,isTierChange:d>c}},getCurrentTierProgress:(r,a)=>{const[c,d]=l.getTierLevelsRange(a),u=r-c+1,h=d-c+1;return{current:u,total:h}},isLastLevelInTier:r=>{const a=i(r),[,c]=l.getTierLevelsRange(a);return r===c},getPreviousLevelInfo:r=>{if(r<=1)return null;const a=r-1,c=i(r),d=i(a);return{prevLevel:a,prevTier:d,isTierChange:d<c}}};return l},[e]),Dt=({onTierChange:e,disabled:t})=>{const{gameProgress:n,config:o}=oe(),{i18n:i,levelConfig:s}=o,{currentTier:l,highestUnlockedTier:r}=n,c=re(s).getTotalTiers();return m("div",{className:"tier-selector",children:m("select",{value:l,onChange:d=>{d.target&&d.target.value&&e(Number(d.target.value))},disabled:t,className:"tier-dropdown",children:Array.from({length:c},(d,u)=>u+1).map(d=>m("option",{value:d,disabled:d>r,children:i.tier+" "+d},`tier-${d}`))})})},Ot=({onLevelChange:e,disabled:t})=>{const{gameProgress:n,config:o}=oe(),{i18n:i,levelConfig:s}=o,{currentTier:l,levelScores:r,currentLevel:a,highestUnlockedLevel:c}=n,d=re(s),u=Z(()=>{const[h,f]=d.getTierLevelsRange(l);return Array.from({length:f-h+1},(g,_)=>{const v=h+_,T=r[v]||0;return{level:v,score:T}})},[l,r]);return m("div",{className:"level-selector",children:m("select",{value:a,onChange:h=>{h.target&&h.target.value&&e(Number(h.target.value))},disabled:t,className:"level-dropdown",children:u.map(({level:h,score:f})=>m("option",{value:h,disabled:h>c,children:`${i.level} ${h} ${"★".repeat(f)}`},`level-${h}`))})})},ie=({isOpen:e,title:t,className:n="",message:o,children:i,noConfirm:s=!1,noCancel:l=!1,confirmText:r="OK",cancelText:a="Cancel",confirmClass:c="",cancelClass:d="",onConfirm:u,onCancel:h})=>{const f=R(null);return x(()=>{const g=_=>{_.key==="Escape"&&h?.()};return e&&document.addEventListener("keydown",g),()=>{document.removeEventListener("keydown",g)}},[e,h]),m("div",{className:`maze-dialog-overlay ${e?"maze-dialog-visible":""}`,children:m("div",{className:"maze-dialog "+n,ref:f,children:[m("div",{className:"maze-dialog-title",children:t}),m("div",{className:"maze-dialog-content",children:i||m("div",{className:"maze-dialog-message",children:o})}),(!l||!s)&&m("div",{className:"maze-dialog-buttons",children:[!l&&m("button",{type:"button",className:"maze-dialog-cancel "+d,onClick:h,children:a}),!s&&m("button",{type:"button",className:"maze-dialog-confirm "+c,onClick:u,children:r})]})]})})},W={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)}},$t=()=>{const{gameProgress:e,setGameProgress:t,gamePlayState:n,setGamePlayState:o,gamePlayStateRef:i,resetGame:s,config:l}=oe(),{i18n:r,levelConfig:a}=l,c=re(a),{levelTransitioning:d,showClue:u}=n,{highestUnlockedLevel:h,totalScore:f}=e,g=c.getTotalLevels(),[_,v]=U(!1),[T,b]=U(!1),[C,p]=U(!1),S=O=>{const $=c.getFirstLevelOfTier(O);c.isLevelUnlocked($,h)&&(t(G=>({...G,currentTier:O})),w($))},w=O=>{c.isLevelUnlocked(O,h)&&(t($=>({...$,currentLevel:O})),W.show(r.levelGoToast.replace("%LEVEL%",O.toString())))},y=()=>{v(!0)},z=()=>{v(!1)},N=()=>{p(!0)},E=()=>{p(!1)},k=()=>{W.show(u?r.cluePathDisabled:r.cluePathEnabled),o(()=>({...i.current,showClue:!i.current.showClue})),p(!1)},L=()=>{b(!0)},I=()=>{s(),b(!1),W.show(r.resetDoneToast)},F=()=>{b(!1)};return m("div",{class:"game-panel-container",children:[m("div",{className:"game-controls",children:[m("div",{className:"selectors-container",children:[m(Dt,{onTierChange:S,disabled:d}),m(Ot,{onLevelChange:w,disabled:d})]}),m("button",{className:`settings-clue-button ${u?"clue-on":"clue-off"}`,disabled:u,title:"Toggle Clue",onClick:N,children:u?r.clueOn:r.clueOff})]}),m("div",{className:"game-settings",children:m("span",{className:"game-settings-icon",onClick:y,children:"★ "+f})}),m(ie,{isOpen:_,title:r.settings,noConfirm:!0,cancelText:r.close,onCancel:z,children:[m("div",{className:"settings-stats",children:[m("div",{children:r.levelComplete+`: ${h}/${g}`}),m("div",{children:r.starsCollected+": "+f}),m("div",{children:r.avgStarPerLevel+": "+(f/h).toFixed(2)})]}),m("div",{className:"settings-item-box",children:[m("button",{className:"settings-reset-button",title:"Reset Game",onClick:L,children:r.reset}),m("div",{className:"settings-item-tip",children:r.resetTip})]})]}),m(ie,{isOpen:T,title:r.confirmReset,message:r.confirmResetMessage,confirmText:r.reset,cancelText:r.cancel,onConfirm:I,onCancel:F}),m(ie,{isOpen:C,title:r.confirmClue,message:r.confirmClueMessage,confirmText:r.confirm,cancelText:r.cancel,onConfirm:k,onCancel:E})]})};function Ae(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Ut(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&&Ut(e.prototype,t),e}function ut(e){return+e.replace(/px/,"")}function Gt(e){var t=window.devicePixelRatio,n=getComputedStyle(e),o=ut(n.getPropertyValue("width")),i=ut(n.getPropertyValue("height"));e.setAttribute("width",(o*t).toString()),e.setAttribute("height",(i*t).toString())}function q(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 dt(e){return e[q(0,e.length)]}var jt=.00125,Wt=5e-4,qt=9e-4,Ht=1e-5,Bt=6,Vt=80,Xt=.9,Yt=1.7,Kt=.2,Jt=.6,Zt=.03,Qt=.07,en=15,tn=82,nn=100,on=250,rn=40,sn=["#fcf403","#62fc03","#f4fc03","#03e7fc","#03fca5","#a503fc","#fc03ad","#fc03c2"];function ht(e){var t=1920;return Math.log(e)/Math.log(t)}var ft=function(){function e(t){Ae(this,e);var n=t.initialPosition,o=t.direction,i=t.confettiRadius,s=t.confettiColors,l=t.emojis,r=t.emojiSize,a=t.canvasWidth,c=q(Xt,Yt,3),d=c*ht(a);this.confettiSpeed={x:d,y:d},this.finalConfettiSpeedX=q(Kt,Jt,3),this.rotationSpeed=l.length?.01:q(Zt,Qt,3)*ht(a),this.dragForceCoefficient=q(Wt,qt,6),this.radius={x:i,y:i},this.initialRadius=i,this.rotationAngle=o==="left"?q(0,.2,3):q(-.2,0,3),this.emojiSize=r,this.emojiRotationAngle=q(0,2*Math.PI),this.radiusYUpdateDirection="down";var u=o==="left"?q(tn,en)*Math.PI/180:q(-15,-82)*Math.PI/180;this.absCos=Math.abs(Math.cos(u)),this.absSin=Math.abs(Math.sin(u));var h=q(-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=l.length?null:dt(s),this.emoji=l.length?dt(l):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,l=this.emoji,r=this.rotationAngle,a=this.emojiRotationAngle,c=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()):l&&(n.font="".concat(c,"px serif"),n.save(),n.translate(d*o.x,d*o.y),n.rotate(a),n.textAlign="center",n.fillText(l,0,0),n.restore())}},{key:"updatePosition",value:function(n,o){var i=this.confettiSpeed,s=this.dragForceCoefficient,l=this.finalConfettiSpeedX,r=this.radiusYUpdateDirection,a=this.rotationSpeed,c=this.createdAt,d=this.direction,u=o-c;if(i.x>l&&(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+jt*Math.pow(u,2)/2,this.rotationSpeed-=this.emoji?1e-4:Ht*n,this.rotationSpeed<0&&(this.rotationSpeed=0),this.emoji){this.emojiRotationAngle+=this.rotationSpeed*n%(2*Math.PI);return}r==="down"?(this.radius.y-=n*a,this.radius.y<=0&&(this.radius.y=0,this.radiusYUpdateDirection="up")):(this.radius.y+=n*a,this.radius.y>=this.initialRadius&&(this.radius.y=this.initialRadius,this.radiusYUpdateDirection="down"))}},{key:"getIsVisibleOnCanvas",value:function(n){return this.currentPosition.y<n+nn}}]),e}();function ln(){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 an(e){var t=e.confettiRadius,n=t===void 0?Bt:t,o=e.confettiNumber,i=o===void 0?e.confettiesNumber||(e.emojis?rn:on):o,s=e.confettiColors,l=s===void 0?sn:s,r=e.emojis,a=r===void 0?e.emojies||[]:r,c=e.emojiSize,d=c===void 0?Vt:c;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:l,emojis:a,emojiSize:d}}var cn=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,l=n.timeDelta,r=n.currentTime;this.shapes=this.shapes.filter(function(a){return a.updatePosition(l,r),a.draw(s.canvasContext),i?a.getIsVisibleOnCanvas(o):!0})}}]),e}(),un=function(){function e(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Ae(this,e),this.activeConfettiBatches=[],this.canvas=t.canvas||ln(),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,Gt(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(l){return l.processShapes({timeDelta:o,currentTime:n},i,s),s?!l.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=an(n),i=o.confettiRadius,s=o.confettiNumber,l=o.confettiColors,r=o.emojis,a=o.emojiSize,c=this.canvas.getBoundingClientRect(),d=c.width,u=c.height,h=u*5/7,f={x:0,y:h},g={x:d,y:h},_=new cn(this.canvasContext),v=0;v<s/2;v++){var T=new ft({initialPosition:f,direction:"right",confettiRadius:i,confettiColors:l,confettiNumber:s,emojis:r,emojiSize:a,canvasWidth:d}),b=new ft({initialPosition:g,direction:"left",confettiRadius:i,confettiColors:l,confettiNumber:s,emojis:r,emojiSize:a,canvasWidth:d});_.addShapes(T,b)}return this.activeConfettiBatches.push(_),this.queueAnimationFrameIfNeeded(),_.getBatchCompletePromise()}},{key:"clearCanvas",value:function(){this.activeConfettiBatches=[]}},{key:"destroyCanvas",value:function(){this.canvas.remove()}}]),e}();const dn=new un,Ie=3,hn=({onRetry:e})=>{const{config:t,currentScore:n,gamePlayState:o,setGamePlayState:i,gameProgress:s,setGameProgress:l}=oe(),{i18n:r,levelConfig:a}=t,[c,d,u]=n,{foodCollected:h,totalFoodCount:f,playerAtExit:g,levelTransitioning:_}=o,{currentLevel:v}=s,[T,b]=U(!1);x(()=>{g&&_&&(dn.addConfetti(),W.show(r.levelCompleteToast),b(!0))},[g,_]);const C=re(a),p=C.getTotalLevels(),S=Z(()=>v>=p,[v,p]),w=()=>{b(!1),W.show(r.levelRestartToast),e?.()},y=()=>{b(!1),i(E=>({...E,isGameActive:!0,levelTransitioning:!1}))},z=()=>{b(!1);const E=C.getNextLevelInfo(v);if(!E)return;const{nextLevel:k,nextTier:L,isTierChange:I}=E;I&&W.show(r.tierUnlockedToast.replace("%TIER%",L.toString())),l(F=>({...F,currentLevel:k,currentTier:L,highestUnlockedLevel:Math.max(F.highestUnlockedLevel,k),highestUnlockedTier:Math.max(F.highestUnlockedTier,L),levelScores:{...F.levelScores,[F.currentLevel]:Math.max(Object.values(n).filter(Boolean).length,F.levelScores[F.currentLevel]||0)}}))},N=()=>{b(!1),l(E=>{const k=Math.max(Object.values(n).filter(Boolean).length,E.levelScores[E.currentLevel]||0),L={...E.levelScores,[E.currentLevel]:k};let I=0,F=0;const O=Object.entries(L).sort(($,G)=>Number($[0])-Number(G[0]));for(const[$,G]of O)if(G<Ie){I=Number($),F=C.getTierByLevel(I);break}return(I>0&&I!==v||k<Ie)&&W.show(r.notCompleteLevel),(I===0||k<Ie)&&e?.(),{...E,currentLevel:I||E.currentLevel,currentTier:F||E.currentTier,levelScores:L}})};return x(()=>{const E=document.querySelector(".maze-game-container"),k=L=>{T&&((L.key===" "||L.code==="Space")&&E&&(E.contains(document.activeElement)||document.activeElement===document.body)&&(L.preventDefault(),S?N():z()),(L.key==="r"||L.code==="KeyR")&&w(),(L.key==="c"||L.code==="KeyC")&&y())};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[T,S]),m(ie,{className:"level-complete-dialog",isOpen:T,title:r.congratulations,cancelText:r.retry+" (R)",onCancel:w,noConfirm:!!d,confirmText:r.continue+" (C)",onConfirm:y,confirmClass:"maze-continue-btn",children:[m("div",{className:"maze-summary-message",children:[!!c&&m("div",{children:"★ - "+r.findYourExit}),m("div",{children:u?"★ - "+r.withoutClue:"☆ - "+r.withClue}),m("div",{children:(d?"★ - "+r.collectAllStars:"☆ - "+r.notCollectAllStars)+` (${h}/${f})`})]}),S&&m("div",{className:"all-levels-completed",children:r.allLevelsCompleted}),m("div",{className:"maze-go-next",children:S?m("button",{className:"maze-go-next-btn",type:"button",onClick:N,children:[m("span",{children:r.lastOK}),m("span",{className:"spacebar-tip",children:`(${r.spacebarTip})`})]}):m("button",{className:"maze-go-next-btn",type:"button",onClick:z,children:[m("span",{children:r.nextLevel}),m("span",{className:"spacebar-tip",children:`(${r.spacebarTip})`})]})}),!d&&m("div",{className:"not-all-stars-collected",children:r.continueMessage})]})},mt=(e,t)=>{const n=R({canvasWidth:0,canvasHeight:0});return x(()=>{const o=()=>{const s=e.current;if(!s)return;const l=s.parentElement;if(!l)return;const r=l.clientWidth;if(r===0)return;const a=window.devicePixelRatio||1;s.style.width=`${r}px`,s.style.height=`${r}px`;const c=r*a,d=r*a;s.width=c,s.height=d,n.current={canvasWidth:c,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},_t=(e,t,n)=>{const o=R({cellWidth:0,cellHeight:0});return x(()=>{const i=()=>{const l=e.current,r=t.maze;if(!l||!r)return;const{rows:a,cols:c}=r;if(a<=0||c<=0)return;const d=(l.width-n*2)/c,u=(l.height-n*2)/a;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},_e={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]},vt=({gamePlayStateRef:e,setGamePlayState:t,moveSpeed:n,moveSpeedRef:o,playerRadius:i,onFoodCollected:s,onExitReached:l,onFirstMove:r})=>{const a=()=>o?.current??n??.03,c=R(!1),d=R(new Set),u=R(!1),h=rt((C,p)=>{const S=e.current;if(!S.maze)return{canMove:!1,newCell:null};const w=a(),[y,z]=_e[C];if(gt(p,y,z,i,w,S.maze))return{canMove:!1,newCell:null};const{row:E,col:k}=p,L=E+y*w,I=k+z*w,F=-.5,O=S.maze.rows,$=S.maze.cols;if(L<F||L>=O||I<F||I>=$)return{canMove:!1,newCell:null};const G=E<0?0:Math.floor(E),Y=k<0?0:Math.floor(k),V=L<0?0:Math.floor(L),Q=I<0?0:Math.floor(I);return V!==G||Q!==Y?S.maze.isValid(V,Q)?{canMove:!0,newCell:{row:V,col:Q}}:{canMove:!1,newCell:null}:{canMove:!0,newCell:null}},[i,a]),f=()=>{const C=e.current,{row:p,col:S}=C.playerCell,w=i*2,y=C.foodCells.findIndex(E=>Math.sqrt(Math.pow(p-E.row,2)+Math.pow(S-E.col,2))<w);y!==-1&&s&&(s(),e.current={...e.current,foodCollected:e.current.foodCollected+1,foodCells:e.current.foodCells.filter((E,k)=>k!==y)});const N=_n(C.playerCell,C.exitCell,C.maze);N&&!e.current.playerAtExit?(e.current={...e.current,playerAtExit:!0,isGameActive:!1,levelTransitioning:!0},l&&l(),requestIdleCallback(()=>{t(()=>({...e.current}))},{timeout:10})):!N&&e.current.playerAtExit&&(e.current={...e.current,playerAtExit:!1,isGameActive:!0,levelTransitioning:!1})},g=C=>{const p=e.current,S=Math.round(C.row),w=Math.round(C.col),y=p.playerPath[p.playerPath.length-1],z=y.row===S&&y.col===w,N=Math.abs(y.row-S),E=Math.abs(y.col-w);if((N===1&&E===0||N===0&&E===1)&&!z){const L=`${y.row},${y.col}-${S},${w}`;e.current={...e.current,playerPath:[...e.current.playerPath,{row:S,col:w}],visitCounts:{...e.current.visitCounts,[L]:(e.current.visitCounts[L]||0)+1}}}},_=()=>{if(c.current||d.current.size===0)return;const C=e.current;!C.playerCell||!Array.from(d.current).some(S=>{const{canMove:w}=h(S,C.playerCell);return w})||(!u.current&&r&&(u.current=!0,r()),c.current=!0)};x(()=>{const C=w=>{if(w.key==="ArrowUp"||w.key==="ArrowDown"||w.key==="ArrowLeft"||w.key==="ArrowRight"||w.key===" "){const y=document.activeElement;if(y&&(y.tagName==="INPUT"||y.tagName==="TEXTAREA"||y.getAttribute("contenteditable")==="true"))return;w.preventDefault()}},p=w=>{const y=w.key;if(!(y in _e))return;const z=document.activeElement;z&&(z.tagName==="INPUT"||z.tagName==="TEXTAREA"||z.getAttribute("contenteditable")==="true")||(w.preventDefault(),e.current.isGameActive&&(d.current.has(y)||(d.current.add(y),c.current||_())))},S=w=>{const y=w.key;if(!(y in _e))return;const z=document.activeElement;z&&(z.tagName==="INPUT"||z.tagName==="TEXTAREA"||z.getAttribute("contenteditable")==="true")||(w.preventDefault(),d.current.delete(y),d.current.size===0&&T())};return window.addEventListener("keydown",C,{capture:!0}),window.addEventListener("keydown",p),window.addEventListener("keyup",S),()=>{window.removeEventListener("keydown",C,{capture:!0}),window.removeEventListener("keydown",p),window.removeEventListener("keyup",S)}},[]);const v=rt(()=>{if(!c.current||d.current.size===0)return e.current.playerCell;const C=a(),p=e.current.playerCell;let S=0,w=0,y=0;for(const A of d.current){const{canMove:j}=h(A,p);if(j){const[ee,we]=_e[A];S+=ee,w+=we,y++}}if(y===0)return e.current.playerCell;const z=Math.sqrt(S*S+w*w),N=z>0?S/z:0,E=z>0?w/z:0,k=Number((p.row+N*C).toFixed(2)),L=Number((p.col+E*C).toFixed(2)),I=k-p.row,F=L-p.col,O=Math.sqrt(I*I+F*F);if(O>0){const A=I/O,j=F/O;if(gt(p,A,j,i,O,e.current.maze))return e.current.playerCell}e.current.playerCell={row:k,col:L},f();const $=p.row<0?0:Math.round(p.row),G=p.col<0?0:Math.round(p.col),Y=k<0?0:Math.round(k),V=L<0?0:Math.round(L);return(Y!==$||V!==G)&&g({row:Y,col:V}),e.current.playerCell},[a,h]),T=()=>{c.current=!1,d.current.clear()};return{updatePlayerPos:v,resetMovingState:T,resetFirstMoveState:()=>{u.current=!1}}};function gt(e,t,n,o,i,s){const l=e.row+t*i,r=e.col+n*i,a={row:l,col:r},c=[],d=e.row<0?0:Math.floor(e.row),u=e.col<0?0:Math.floor(e.col);c.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,g]of h){const _=d+f,v=u+g;s.isValid(_,v)&&c.push({row:_,col:v})}for(const f of c){const g=fn(f.row,f.col,s);for(const _ of g)if(mn(a,_)<o)return!0}return!1}function fn(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 mn(e,t){const{start:n,end:o}=t,i=o.col-n.col,s=o.row-n.row,l=e.col-n.col,r=e.row-n.row,a=i*i+s*s;if(a===0)return Math.sqrt(l*l+r*r);const c=Math.max(0,Math.min(1,(l*i+r*s)/a)),d=n.col+c*i,u=n.row+c*s,h=e.col-d,f=e.row-u;return Math.sqrt(h*h+f*f)}function _n(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 pt(e,t,n,o,i){if(!e||!t.maze)return;const{canvasWidth:s,canvasHeight:l}=n,{cellWidth:r,cellHeight:a}=o,{maze:c,playerCell:d,exitCell:u,foodCells:h,showClue:f,playerPath:g,visitCounts:_}=t,{padding:v,wallWidth:T,wallColor:b,playerColor:C,playerRadius:p,foodColor:S,backgroundColor:w,clueColor:y,exitColor:z,exitWallWidth:N,exitDashArray:E}=i;e.clearRect(0,0,s,l),e.save(),e.fillStyle=w,e.fillRect(0,0,s,l),e.restore(),f&&yn({ctx:e,playerPath:g,visitCounts:_,cellWidth:r,cellHeight:a,padding:v,clueColor:y}),vn({ctx:e,maze:c,cellWidth:r,cellHeight:a,padding:v,wallColor:b,wallWidth:T}),pn({ctx:e,maze:c,exitCell:u,cellWidth:r,cellHeight:a,padding:v,exitColor:z,exitWallWidth:N,exitDashArray:E}),wn({ctx:e,foodCells:h,cellWidth:r,cellHeight:a,padding:v,foodColor:S}),gn({ctx:e,playerCell:d,playerRadius:p,cellWidth:r,cellHeight:a,padding:v,playerColor:C})}function vn({ctx:e,maze:t,cellWidth:n,cellHeight:o,padding:i,wallColor:s,wallWidth:l}){e.save(),e.strokeStyle=s,e.lineWidth=l,e.lineCap="round",e.beginPath(),bn(t,n,o,i).forEach(a=>{e.moveTo(a.x1,a.y1),e.lineTo(a.x2,a.y2)}),e.stroke(),e.restore()}function gn({ctx:e,playerCell:t,playerRadius:n,cellWidth:o,cellHeight:i,padding:s,playerColor:l}){const{x:r,y:a}=ve(t.row,t.col,o,i,s),c=Math.min(o,i)*Math.min(n,.5);e.save(),e.fillStyle=l,e.beginPath(),e.arc(r,a,c,0,Math.PI*2),e.fill(),e.restore()}function pn({ctx:e,maze:t,exitCell:n,cellWidth:o,cellHeight:i,padding:s,exitColor:l,exitWallWidth:r,exitDashArray:a=[8,12]}){const{row:c,col:d}=n;if(!t.isValid(c,d))return;const u=s+d*o,h=s+c*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=l,e.lineWidth=r,e.setLineDash(a),e.beginPath(),e.moveTo(u,h+i),e.lineTo(u+o,h+i),e.stroke(),e.restore()}function wn({ctx:e,foodCells:t,cellWidth:n,cellHeight:o,padding:i,foodColor:s}){e.fillStyle=s;const l=Math.min(n,o)*.25;t.forEach(r=>{const{x:a,y:c}=ve(r.row,r.col,n,o,i);Cn(e,a,c,l*1.2,5,l*.6)})}function Cn(e,t,n,o,i,s){e.save(),e.beginPath();for(let l=0;l<i*2;l++){const r=l%2===0?o:s,a=Math.PI*l/i;e.lineTo(t+r*Math.sin(a),n+r*Math.cos(a))}e.closePath(),e.fill(),e.restore()}function yn({ctx:e,playerPath:t,visitCounts:n,cellWidth:o,cellHeight:i,padding:s,clueColor:l}){if(!(!t||t.length<2||!n)){e.save();for(let r=1;r<t.length;r++){const a=t[r-1],c=t[r],d=`${a.row},${a.col}-${c.row},${c.col}`,u=`${c.row},${c.col}-${a.row},${a.col}`,h=(n[d]||0)+(n[u]||0),f=Math.min(.2+h*.1,.9),g=Math.max(3,o*.1)+h*.5;try{e.strokeStyle=l.replace(")",`, ${f})`).replace("rgb(","rgba(")}catch{e.strokeStyle=`rgba(255, 0, 0, ${f})`}e.lineWidth=g,e.lineCap="round",e.lineJoin="round";const{x:_,y:v}=ve(a.row,a.col,o,i,s),{x:T,y:b}=ve(c.row,c.col,o,i,s);e.beginPath(),e.moveTo(_,v),e.lineTo(T,b),e.stroke()}e.restore()}}function bn(e,t,n,o){const i=[];for(let s=0;s<e.rows;s++)for(let l=0;l<e.cols;l++){const r=e.grid[s][l],a=o+l*t,c=o+s*n;r.walls.top&&i.push({x1:a,y1:c,x2:a+t,y2:c}),r.walls.right&&i.push({x1:a+t,y1:c,x2:a+t,y2:c+n}),r.walls.bottom&&i.push({x1:a,y1:c+n,x2:a+t,y2:c+n}),r.walls.left&&i.push({x1:a,y1:c,x2:a,y2:c+n})}return i}function ve(e,t,n,o,i){return{x:i+t*n+n/2,y:i+e*o+o/2}}function Tn(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 kn{constructor(t,n){this.row=t,this.col=n}visited=!1;walls={top:!0,right:!0,bottom:!0,left:!0}}class wt{rows;cols;grid;seed;random;constructor(t,n,o,i,s={row:0,col:0},l={row:t-1,col:n-1}){this.rows=t,this.cols=n,this.seed=i??Math.floor(Math.random()*1e6),this.random=Tn(this.seed),this.grid=this.initializeGrid(),this.generate(o,s,l)}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 kn(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 l=t+s.r,r=n+s.c;this.isValid(l,r)&&o.push({row:l,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],l=this.grid[o][i];t===o+1?(s.walls.top=!1,l.walls.bottom=!1):t===o-1?(s.walls.bottom=!1,l.walls.top=!1):n===i+1?(s.walls.left=!1,l.walls.right=!1):n===i-1&&(s.walls.right=!1,l.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:l}=i,r=this.getUnvisitedNeighbors(s,l);if(r.length>0){const a=this.randomPick(r),{row:c,col:d}=a;this.removeWall(s,l,c,d),this.grid[c][d].visited=!0,t.push(a)}else t.pop()}}generateWithPrims(){const t=[],n=(s,l)=>{const r=this.getNeighbors(s,l);for(const a of r)!this.grid[a.row][a.col].visited&&!t.some(c=>c.row===a.row&&c.col===a.col)&&t.push(a)},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),l=t[s],{row:r,col:a}=l,c=this.getVisitedNeighbors(r,a);if(c.length>0){const d=this.randomPick(c);this.removeWall(r,a,d.row,d.col),this.grid[r][a].visited=!0,n(r,a)}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 Ct=(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},Sn=e=>e===1?2:e>=2&&e<=5?3:e>=6&&e<=11?4:e>=12&&e<=15?5:6,zn=(e,t)=>{if(!t)return console.error(`Cannot find Level ${e}'s config.`),null;const{size:n,seed:o,method:i,entry:s,exit:l}=t,r=n,a=n,c=s||{row:0,col:0},d=l||{row:r-1,col:a-1},u=new wt(r,a,i,o,c,d),h=Sn(e),f=[];for(let g=0;g<h;g++){let _;do _={row:Math.floor(u.random()*r),col:Math.floor(u.random()*a)};while(_.row===c.row&&_.col===c.col||_.row===d.row&&_.col===d.col||!Ct(u,_.row,_.col)||f.some(v=>v.row===_.row&&v.col===_.col));f.push(_)}return{isGameActive:!0,levelTransitioning:!1,maze:u,playerCell:c,exitCell:d,foodCells:f,playerAtExit:!1,foodCollected:0,totalFoodCount:h,showClue:!1,playerPath:[c],visitCounts:{[`${c.row},${c.col}`]:1}}},En=({size:e,seed:t,method:n,foodCount:o,foodRace:i,clue:s})=>{const l=e,r=e,a={row:0,col:0},c={row:l-1,col:r-1},d=new wt(l,r,n,t,a,c),u=[];if(i)for(let h=0;h<o;h++){let f,g=0;do f={row:Math.floor(d.random()*l),col:Math.floor(d.random()*r)},g++;while(g<50&&(f.row===a.row&&f.col===a.col||f.row===c.row&&f.col===c.col||!Ct(d,f.row,f.col)||u.some(_=>_.row===f.row&&_.col===f.col)));g<50&&u.push(f)}return{isGameActive:!0,levelTransitioning:!1,maze:d,playerCell:a,exitCell:c,foodCells:u,playerAtExit:!1,foodCollected:0,totalFoodCount:i?o:0,showClue:s,playerPath:[a],visitCounts:{[`${a.row},${a.col}`]:1}}};function Ln(){const{setGamePlayState:e,gamePlayState:t,gamePlayStateRef:n,gameProgress:o,config:i}=oe(),s=R(null),l=R(null),{i18n:r,levelConfig:a,renderConfig:c}=i,d=re(a),u=R(d.getLevelConfig(o.currentLevel));x(()=>{s.current&&W.attachTo(s.current)},[]);const h=R(),f=mt(l,()=>{h.current?.()}),g=_t(l,t,c.padding);x(()=>{u.current=d.getLevelConfig(o.currentLevel)},[o.currentLevel]);const _=()=>{const C=zn(o.currentLevel,u.current);C&&e(p=>({...p,...C}))};x(()=>{_()},[o.currentLevel]);const v=()=>{_()},{updatePlayerPos:T,resetMovingState:b}=vt({gamePlayStateRef:n,setGamePlayState:e,playerRadius:c.playerRadius,moveSpeed:c.gridMoveSpeed,onFoodCollected:()=>{const C=n.current.totalFoodCount-n.current.foodCollected-1;C>0?W.show(r.foodCollectedToast.replace("%NUM%",C.toString()),3e3):W.show(r.allFoodCollectedToast)}});return x(()=>{b()},[o.currentLevel,b]),x(()=>{let C,p=!document.hidden;const S=()=>{const z=l.current?.getContext("2d"),N=n.current;if(!(p&&N?.isGameActive&&z&&N?.maze)){C=requestAnimationFrame(S);return}T(),w(),C=requestAnimationFrame(S)},w=()=>{const z=l.current?.getContext("2d"),N=n.current;if(z&&N?.maze){const E=u.current?.wallWidth||c?.wallWidth,k=u.current?.exitColor||c?.exitColor,L=u.current?.exitWallWidth||c?.exitWallWidth,I=u.current?.exitDashArray||c?.exitDashArray;pt(z,N,f.current,g.current,{...c,wallWidth:E,exitColor:k,exitWallWidth:L,exitDashArray:I})}};h.current=w;const y=z=>{const N=p;p=!document.hidden&&document.visibilityState==="visible"&&(!z||z.type!=="blur"),!N&&p?n.current?.levelTransitioning===!1&&e({...n.current,isGameActive:!0}):N&&!p&&e({...n.current,isGameActive:!1})};return document.addEventListener("visibilitychange",y),window.addEventListener("blur",y),window.addEventListener("focus",y),C=requestAnimationFrame(S),()=>{cancelAnimationFrame(C),document.removeEventListener("visibilitychange",y),window.removeEventListener("blur",y),window.removeEventListener("focus",y)}},[]),x(()=>{W.show(r.useArrowKeyTips,3e3)},[]),m("div",{className:"maze-game-container",children:[m($t,{}),m(hn,{onRetry:v}),m("div",{className:"maze-canvas-container",ref:s,children:m("canvas",{ref:l,className:"maze-game-canvas"})})]})}const Nn=e=>{const t=Math.floor(e/60),n=e%60;return`${t.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`},Mn=({timer:e})=>{const[t,n]=U(e),o=R(),i=R(!1),s=R(0);return x(()=>{const l=()=>{!i.current&&!o.current&&(i.current=!0,o.current=setInterval(()=>{n(a=>(s.current=e-a+1,a<=1?(clearInterval(o.current),window.dispatchEvent(new CustomEvent("maze:timeUp")),0):a-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",l),window.addEventListener("maze:gameSuccess",r),()=>{window.removeEventListener("maze:firstMove",l),window.removeEventListener("maze:gameSuccess",r),clearInterval(o.current)}},[e]),x(()=>{o.current&&(clearInterval(o.current),o.current=void 0),n(e),i.current=!1,s.current=0},[e]),m("div",{className:"single-maze-timer",children:m("span",{className:`maze-timer-text ${t<=10&&i.current?"maze-timer-warning":""}`,children:["⏱️ ",Nn(t)]})})};function An({config:e}){const{size:t,seed:n,method:o,foodCount:i,foodRace:s,clue:l,renderConfig:r,successCallback:a,failCallback:c,timer:d,i18n:u}=e,[h,f]=U({...Me}),[g,_]=U(!1),[v,T]=U(!0),[b,C]=U(!1),[p,S]=U(""),w=R(0),y=R(!1),z=R(!1),N=R(null),E=R(null),k=R(h),L=R(),I=mt(N,()=>{L.current?.()}),F=_t(N,h,r.padding);x(()=>{k.current=h},[h]);const{updatePlayerPos:O,resetMovingState:$,resetFirstMoveState:G}=vt({gamePlayStateRef:k,setGamePlayState:f,playerRadius:r.playerRadius,moveSpeed:r.gridMoveSpeed,onFoodCollected:()=>{console.log("Food collected in single maze")},onExitReached:()=>{if(!y.current){if(s&&k.current.foodCollected<k.current.totalFoodCount){S(`⭐️ ${u.foodMsg}`),C(!0),f(A=>({...A,isGameActive:!1}));return}f(A=>({...A,isGameActive:!1})),V()}},onFirstMove:()=>{window.dispatchEvent(new CustomEvent("maze:firstMove"))}}),Y=()=>{y.current=!0,S(`⏰ ${u.failMsg}`),C(!0),f({...k.current,isGameActive:!1})},V=()=>{y.current=!0,z.current=!0,S(`🎉 ${u.successMsg}`),C(!0),f(A=>({...A,isGameActive:!1})),window.dispatchEvent(new CustomEvent("maze:gameSuccess"))},Q=()=>{if(C(!1),!y.current){f(A=>({...A,isGameActive:!0}));return}T(!1),f(A=>({...A,showClue:!0})),z.current?a?.(w.current):c?.()};return x(()=>{(async()=>{_(!0);try{const j=En({size:t,seed:n,method:o,foodCount:i,foodRace:s,clue:l});k.current=j,f(j)}catch(j){console.error("Error generating single maze:",j)}finally{_(!1)}})()},[e]),x(()=>{let A;const j=!document.hidden,ee=()=>{const Ce=N.current?.getContext("2d"),se=k.current;if(!(j&&se?.isGameActive&&Ce&&se?.maze)){A=requestAnimationFrame(ee);return}O(),we(),A=requestAnimationFrame(ee)},we=()=>{const Ce=N.current?.getContext("2d"),se=k.current;Ce&&se?.maze&&pt(Ce,se,I.current,F.current,r)};return L.current=we,A=requestAnimationFrame(ee),()=>{cancelAnimationFrame(A)}},[]),x(()=>{$(),G()},[e,$,G]),x(()=>{const A=j=>{w.current=j.detail.timeUsed};return window.addEventListener("maze:timeUsed",A),window.addEventListener("maze:timeUp",Y),()=>{window.removeEventListener("maze:timeUsed",A),window.removeEventListener("maze:timeUp",Y)}},[]),g?m("div",{className:"single-maze-loading",children:m("div",{children:"Generating maze..."})}):h?m("div",{className:"maze-game-container",children:[v&&m(Mn,{timer:d}),m("div",{className:"single-maze-canvas-container",ref:E,children:m("canvas",{ref:N,className:"maze-game-canvas"})}),m(ie,{isOpen:b,title:p,noConfirm:!0,cancelText:"OK",onCancel:Q})]}):m("div",{className:"single-maze-error",children:m("div",{children:"Failed to generate maze"})})}const yt=[[{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"}]],bt={gridMoveSpeed:.07,padding:10,wallWidth:2,wallColor:"#000000",foodColor:"#4CAF50",clueColor:"rgb(255,0,0)",backgroundColor:"#ffffff",playerColor:"#4CAF50",playerRadius:.2,exitColor:"#F44336",exitWallWidth:4,exitDashArray:[8,12]},ge={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."},renderConfig:bt,levelConfig:yt},pe={i18n:{successMsg:"Congratulations! You completed the maze!",failMsg:"Time is up!",foodMsg:"Please collect all stars before leaving!"},size:8,seed:12345,method:"backtracking",clue:!1,foodCount:0,foodRace:!1,renderConfig:bt,timer:10*60,successCallback:()=>{console.log("🎉 Single maze completed successfully!")},failCallback:()=>{console.log("⏰ Time is up! Game failed.")}};function Pn({config:e={}}){const t={...ge.i18n,...e.i18n||{}},n={...ge.renderConfig,...e.renderConfig||{}},o=e.levelConfig||yt,i={...ge,...e,i18n:t,levelConfig:o,renderConfig:n};return m(Ft,{config:i,children:m(Ln,{})})}function In({config:e={}}){const t={...pe.i18n,...e.i18n||{}},n={...pe.renderConfig,...e.renderConfig||{}},o={...pe,...e,i18n:t,renderConfig:n};return m(An,{config:o})}const xn={root:"https://unpkg.com/@roudanio/maze@0.2.5/dist/",...ge};`${JSON.stringify(xn,null,2)}`;const Rn={root:"https://unpkg.com/@roudanio/maze@0.2.5/dist/",...pe};return`${JSON.stringify(Rn,(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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roudanio/maze",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "js-confetti": "^0.12.0",