@roudanio/maze 0.0.13 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/maze.iife.js +3 -3
- package/dist/maze.js +647 -592
- package/dist/maze.umd.js +3 -3
- package/package.json +1 -1
package/dist/maze.iife.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var Maze=function(){"use strict";var K,L,ye,j,be,ke,Te,Le,ue,de,he,ze,V={},Se=[],rt=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,J=Array.isArray;function $(t,e){for(var n in e)t[n]=e[n];return t}function _e(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function it(t,e,n){var o,i,s,a={};for(s in e)s=="key"?o=e[s]:s=="ref"?i=e[s]:a[s]=e[s];if(arguments.length>2&&(a.children=arguments.length>3?K.call(arguments,2):n),typeof t=="function"&&t.defaultProps!=null)for(s in t.defaultProps)a[s]==null&&(a[s]=t.defaultProps[s]);return Z(t,a,o,i,null)}function Z(t,e,n,o,i){var s={type:t,props:e,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++ye,__i:-1,__u:0};return i==null&&L.vnode!=null&&L.vnode(s),s}function Q(t){return t.children}function ee(t,e){this.props=t,this.context=e}function W(t,e){if(e==null)return t.__?W(t.__,t.__i+1):null;for(var n;e<t.__k.length;e++)if((n=t.__k[e])!=null&&n.__e!=null)return n.__e;return typeof t.type=="function"?W(t):null}function Ne(t){var e,n;if((t=t.__)!=null&&t.__c!=null){for(t.__e=t.__c.base=null,e=0;e<t.__k.length;e++)if((n=t.__k[e])!=null&&n.__e!=null){t.__e=t.__c.base=n.__e;break}return Ne(t)}}function fe(t){(!t.__d&&(t.__d=!0)&&j.push(t)&&!te.__r++||be!=L.debounceRendering)&&((be=L.debounceRendering)||ke)(te)}function te(){for(var t,e,n,o,i,s,a,r=1;j.length;)j.length>r&&j.sort(Te),t=j.shift(),r=j.length,t.__d&&(n=void 0,i=(o=(e=t).__v).__e,s=[],a=[],e.__P&&((n=$({},o)).__v=o.__v+1,L.vnode&&L.vnode(n),me(e.__P,n,o,e.__n,e.__P.namespaceURI,32&o.__u?[i]:null,s,i??W(o),!!(32&o.__u),a),n.__v=o.__v,n.__.__k[n.__i]=n,Ie(s,n,a),n.__e!=i&&Ne(n)));te.__r=0}function Ee(t,e,n,o,i,s,a,r,l,c,d){var u,h,_,v,p,m,g=o&&o.__k||Se,f=e.length;for(l=st(n,e,g,l,f),u=0;u<f;u++)(_=n.__k[u])!=null&&(h=_.__i==-1?V:g[_.__i]||V,_.__i=u,m=me(t,_,h,i,s,a,r,l,c,d),v=_.__e,_.ref&&h.ref!=_.ref&&(h.ref&&ve(h.ref,null,_),d.push(_.ref,_.__c||v,_)),p==null&&v!=null&&(p=v),4&_.__u||h.__k===_.__k?l=Ae(_,l,t):typeof _.type=="function"&&m!==void 0?l=m:v&&(l=v.nextSibling),_.__u&=-7);return n.__e=p,l}function st(t,e,n,o,i){var s,a,r,l,c,d=n.length,u=d,h=0;for(t.__k=new Array(i),s=0;s<i;s++)(a=e[s])!=null&&typeof a!="boolean"&&typeof a!="function"?(l=s+h,(a=t.__k[s]=typeof a=="string"||typeof a=="number"||typeof a=="bigint"||a.constructor==String?Z(null,a,null,null,null):J(a)?Z(Q,{children:a},null,null,null):a.constructor==null&&a.__b>0?Z(a.type,a.props,a.key,a.ref?a.ref:null,a.__v):a).__=t,a.__b=t.__b+1,r=null,(c=a.__i=lt(a,n,l,u))!=-1&&(u--,(r=n[c])&&(r.__u|=2)),r==null||r.__v==null?(c==-1&&(i>d?h--:i<d&&h++),typeof a.type!="function"&&(a.__u|=4)):c!=l&&(c==l-1?h--:c==l+1?h++:(c>l?h--:h++,a.__u|=4))):t.__k[s]=null;if(u)for(s=0;s<d;s++)(r=n[s])!=null&&(2&r.__u)==0&&(r.__e==o&&(o=W(r)),De(r,r));return o}function Ae(t,e,n){var o,i;if(typeof t.type=="function"){for(o=t.__k,i=0;o&&i<o.length;i++)o[i]&&(o[i].__=t,e=Ae(o[i],e,n));return e}t.__e!=e&&(e&&t.type&&!n.contains(e)&&(e=W(t)),n.insertBefore(t.__e,e||null),e=t.__e);do e=e&&e.nextSibling;while(e!=null&&e.nodeType==8);return e}function lt(t,e,n,o){var i,s,a=t.key,r=t.type,l=e[n];if(l===null&&t.key==null||l&&a==l.key&&r==l.type&&(2&l.__u)==0)return n;if(o>(l!=null&&(2&l.__u)==0?1:0))for(i=n-1,s=n+1;i>=0||s<e.length;){if(i>=0){if((l=e[i])&&(2&l.__u)==0&&a==l.key&&r==l.type)return i;i--}if(s<e.length){if((l=e[s])&&(2&l.__u)==0&&a==l.key&&r==l.type)return s;s++}}return-1}function Me(t,e,n){e[0]=="-"?t.setProperty(e,n??""):t[e]=n==null?"":typeof n!="number"||rt.test(e)?n:n+"px"}function ne(t,e,n,o,i){var s;e:if(e=="style")if(typeof n=="string")t.style.cssText=n;else{if(typeof o=="string"&&(t.style.cssText=o=""),o)for(e in o)n&&e in n||Me(t.style,e,"");if(n)for(e in n)o&&n[e]==o[e]||Me(t.style,e,n[e])}else if(e[0]=="o"&&e[1]=="n")s=e!=(e=e.replace(Le,"$1")),e=e.toLowerCase()in t||e=="onFocusOut"||e=="onFocusIn"?e.toLowerCase().slice(2):e.slice(2),t.l||(t.l={}),t.l[e+s]=n,n?o?n.u=o.u:(n.u=ue,t.addEventListener(e,s?he:de,s)):t.removeEventListener(e,s?he:de,s);else{if(i=="http://www.w3.org/2000/svg")e=e.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(e!="width"&&e!="height"&&e!="href"&&e!="list"&&e!="form"&&e!="tabIndex"&&e!="download"&&e!="rowSpan"&&e!="colSpan"&&e!="role"&&e!="popover"&&e in t)try{t[e]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&e[4]!="-"?t.removeAttribute(e):t.setAttribute(e,e=="popover"&&n==1?"":n))}}function Pe(t){return function(e){if(this.l){var n=this.l[e.type+t];if(e.t==null)e.t=ue++;else if(e.t<n.u)return;return n(L.event?L.event(e):e)}}}function me(t,e,n,o,i,s,a,r,l,c){var d,u,h,_,v,p,m,g,f,w,y,b,k,T,A,N,M,S=e.type;if(e.constructor!=null)return null;128&n.__u&&(l=!!(32&n.__u),s=[r=e.__e=n.__e]),(d=L.__b)&&d(e);e:if(typeof S=="function")try{if(g=e.props,f="prototype"in S&&S.prototype.render,w=(d=S.contextType)&&o[d.__c],y=d?w?w.props.value:d.__:o,n.__c?m=(u=e.__c=n.__c).__=u.__E:(f?e.__c=u=new S(g,y):(e.__c=u=new ee(g,y),u.constructor=S,u.render=ct),w&&w.sub(u),u.props=g,u.state||(u.state={}),u.context=y,u.__n=o,h=u.__d=!0,u.__h=[],u._sb=[]),f&&u.__s==null&&(u.__s=u.state),f&&S.getDerivedStateFromProps!=null&&(u.__s==u.state&&(u.__s=$({},u.__s)),$(u.__s,S.getDerivedStateFromProps(g,u.__s))),_=u.props,v=u.state,u.__v=e,h)f&&S.getDerivedStateFromProps==null&&u.componentWillMount!=null&&u.componentWillMount(),f&&u.componentDidMount!=null&&u.__h.push(u.componentDidMount);else{if(f&&S.getDerivedStateFromProps==null&&g!==_&&u.componentWillReceiveProps!=null&&u.componentWillReceiveProps(g,y),!u.__e&&u.shouldComponentUpdate!=null&&u.shouldComponentUpdate(g,u.__s,y)===!1||e.__v==n.__v){for(e.__v!=n.__v&&(u.props=g,u.state=u.__s,u.__d=!1),e.__e=n.__e,e.__k=n.__k,e.__k.some(function(I){I&&(I.__=e)}),b=0;b<u._sb.length;b++)u.__h.push(u._sb[b]);u._sb=[],u.__h.length&&a.push(u);break e}u.componentWillUpdate!=null&&u.componentWillUpdate(g,u.__s,y),f&&u.componentDidUpdate!=null&&u.__h.push(function(){u.componentDidUpdate(_,v,p)})}if(u.context=y,u.props=g,u.__P=t,u.__e=!1,k=L.__r,T=0,f){for(u.state=u.__s,u.__d=!1,k&&k(e),d=u.render(u.props,u.state,u.context),A=0;A<u._sb.length;A++)u.__h.push(u._sb[A]);u._sb=[]}else do u.__d=!1,k&&k(e),d=u.render(u.props,u.state,u.context),u.state=u.__s;while(u.__d&&++T<25);u.state=u.__s,u.getChildContext!=null&&(o=$($({},o),u.getChildContext())),f&&!h&&u.getSnapshotBeforeUpdate!=null&&(p=u.getSnapshotBeforeUpdate(_,v)),N=d,d!=null&&d.type===Q&&d.key==null&&(N=Fe(d.props.children)),r=Ee(t,J(N)?N:[N],e,n,o,i,s,a,r,l,c),u.base=e.__e,e.__u&=-161,u.__h.length&&a.push(u),m&&(u.__E=u.__=null)}catch(I){if(e.__v=null,l||s!=null)if(I.then){for(e.__u|=l?160:128;r&&r.nodeType==8&&r.nextSibling;)r=r.nextSibling;s[s.indexOf(r)]=null,e.__e=r}else for(M=s.length;M--;)_e(s[M]);else e.__e=n.__e,e.__k=n.__k;L.__e(I,e,n)}else s==null&&e.__v==n.__v?(e.__k=n.__k,e.__e=n.__e):r=e.__e=at(n.__e,e,n,o,i,s,a,l,c);return(d=L.diffed)&&d(e),128&e.__u?void 0:r}function Ie(t,e,n){for(var o=0;o<n.length;o++)ve(n[o],n[++o],n[++o]);L.__c&&L.__c(e,t),t.some(function(i){try{t=i.__h,i.__h=[],t.some(function(s){s.call(i)})}catch(s){L.__e(s,i.__v)}})}function Fe(t){return typeof t!="object"||t==null||t.__b&&t.__b>0?t:J(t)?t.map(Fe):$({},t)}function at(t,e,n,o,i,s,a,r,l){var c,d,u,h,_,v,p,m=n.props,g=e.props,f=e.type;if(f=="svg"?i="http://www.w3.org/2000/svg":f=="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((_=s[c])&&"setAttribute"in _==!!f&&(f?_.localName==f:_.nodeType==3)){t=_,s[c]=null;break}}if(t==null){if(f==null)return document.createTextNode(g);t=document.createElementNS(i,f,g.is&&g),r&&(L.__m&&L.__m(e,s),r=!1),s=null}if(f==null)m===g||r&&t.data==g||(t.data=g);else{if(s=s&&K.call(t.childNodes),m=n.props||V,!r&&s!=null)for(m={},c=0;c<t.attributes.length;c++)m[(_=t.attributes[c]).name]=_.value;for(c in m)if(_=m[c],c!="children"){if(c=="dangerouslySetInnerHTML")u=_;else if(!(c in g)){if(c=="value"&&"defaultValue"in g||c=="checked"&&"defaultChecked"in g)continue;ne(t,c,null,_,i)}}for(c in g)_=g[c],c=="children"?h=_:c=="dangerouslySetInnerHTML"?d=_:c=="value"?v=_:c=="checked"?p=_:r&&typeof _!="function"||m[c]===_||ne(t,c,_,m[c],i);if(d)r||u&&(d.__html==u.__html||d.__html==t.innerHTML)||(t.innerHTML=d.__html),e.__k=[];else if(u&&(t.innerHTML=""),Ee(e.type=="template"?t.content:t,J(h)?h:[h],e,n,o,f=="foreignObject"?"http://www.w3.org/1999/xhtml":i,s,a,s?s[0]:n.__k&&W(n,0),r,l),s!=null)for(c=s.length;c--;)_e(s[c]);r||(c="value",f=="progress"&&v==null?t.removeAttribute("value"):v!=null&&(v!==t[c]||f=="progress"&&!v||f=="option"&&v!=m[c])&&ne(t,c,v,m[c],i),c="checked",p!=null&&p!=t[c]&&ne(t,c,p,m[c],i))}return t}function ve(t,e,n){try{if(typeof t=="function"){var o=typeof t.__u=="function";o&&t.__u(),o&&e==null||(t.__u=t(e))}else t.current=e}catch(i){L.__e(i,n)}}function De(t,e,n){var o,i;if(L.unmount&&L.unmount(t),(o=t.ref)&&(o.current&&o.current!=t.__e||ve(o,null,e)),(o=t.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(s){L.__e(s,e)}o.base=o.__P=null}if(o=t.__k)for(i=0;i<o.length;i++)o[i]&&De(o[i],e,n||typeof t.type!="function");n||_e(t.__e),t.__c=t.__=t.__e=void 0}function ct(t,e,n){return this.constructor(t,n)}function ut(t,e,n){var o,i,s,a;e==document&&(e=document.documentElement),L.__&&L.__(t,e),i=(o=!1)?null:e.__k,s=[],a=[],me(e,t=e.__k=it(Q,null,[t]),i||V,V,e.namespaceURI,i?null:e.firstChild?K.call(e.childNodes):null,s,i?i.__e:e.firstChild,o,a),Ie(s,t,a)}function dt(t){function e(n){var o,i;return this.getChildContext||(o=new Set,(i={})[e.__c]=this,this.getChildContext=function(){return i},this.componentWillUnmount=function(){o=null},this.shouldComponentUpdate=function(s){this.props.value!=s.value&&o.forEach(function(a){a.__e=!0,fe(a)})},this.sub=function(s){o.add(s);var a=s.componentWillUnmount;s.componentWillUnmount=function(){o&&o.delete(s),a&&a.call(s)}}),n.children}return e.__c="__cC"+ze++,e.__=t,e.Provider=e.__l=(e.Consumer=function(n,o){return n.children(o)}).contextType=e,e}K=Se.slice,L={__e:function(t,e,n,o){for(var i,s,a;e=e.__;)if((i=e.__c)&&!i.__)try{if((s=i.constructor)&&s.getDerivedStateFromError!=null&&(i.setState(s.getDerivedStateFromError(t)),a=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(t,o||{}),a=i.__d),a)return i.__E=i}catch(r){t=r}throw t}},ye=0,ee.prototype.setState=function(t,e){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=$({},this.state),typeof t=="function"&&(t=t($({},n),this.props)),t&&$(n,t),t!=null&&this.__v&&(e&&this._sb.push(e),fe(this))},ee.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),fe(this))},ee.prototype.render=Q,j=[],ke=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,Te=function(t,e){return t.__v.__b-e.__v.__b},te.__r=0,Le=/(PointerCapture)$|Capture$/i,ue=0,de=Pe(!1),he=Pe(!0),ze=0;var ht=0;function C(t,e,n,o,i,s){e||(e={});var a,r,l=e;if("ref"in l)for(r in l={},e)r=="ref"?a=e[r]:l[r]=e[r];var c={type:t,props:l,key:n,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--ht,__i:-1,__u:0,__source:i,__self:s};if(typeof t=="function"&&(a=t.defaultProps))for(r in a)l[r]===void 0&&(l[r]=a[r]);return L.vnode&&L.vnode(c),c}var H,z,pe,Oe,Y=0,Re=[],E=L,xe=E.__b,$e=E.__r,Ue=E.diffed,je=E.__c,Ge=E.unmount,We=E.__;function oe(t,e){E.__h&&E.__h(z,t,Y||e),Y=0;var n=z.__H||(z.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function q(t){return Y=1,_t(Be,t)}function _t(t,e,n){var o=oe(H++,2);if(o.t=t,!o.__c&&(o.__=[Be(void 0,e),function(r){var l=o.__N?o.__N[0]:o.__[0],c=o.t(l,r);l!==c&&(o.__N=[c,o.__[1]],o.__c.setState({}))}],o.__c=z,!z.__f)){var i=function(r,l,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,l,c);var u=o.__c.props!==r;return d.forEach(function(h){if(h.__N){var _=h.__[0];h.__=h.__N,h.__N=void 0,_!==h.__[0]&&(u=!0)}}),s&&s.call(this,r,l,c)||u};z.__f=!0;var s=z.shouldComponentUpdate,a=z.componentWillUpdate;z.componentWillUpdate=function(r,l,c){if(this.__e){var d=s;s=void 0,i(r,l,c),s=d}a&&a.call(this,r,l,c)},z.shouldComponentUpdate=i}return o.__N||o.__}function P(t,e){var n=oe(H++,3);!E.__s&&qe(n.__H,e)&&(n.__=t,n.u=e,z.__H.__h.push(n))}function R(t){return Y=5,G(function(){return{current:t}},[])}function G(t,e){var n=oe(H++,7);return qe(n.__H,e)&&(n.__=t(),n.__H=e,n.__h=t),n.__}function ft(t,e){return Y=8,G(function(){return t},e)}function mt(t){var e=z.context[t.__c],n=oe(H++,9);return n.c=t,e?(n.__==null&&(n.__=!0,e.sub(z)),e.props.value):t.__}function vt(){for(var t;t=Re.shift();)if(t.__P&&t.__H)try{t.__H.__h.forEach(re),t.__H.__h.forEach(ge),t.__H.__h=[]}catch(e){t.__H.__h=[],E.__e(e,t.__v)}}E.__b=function(t){z=null,xe&&xe(t)},E.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),We&&We(t,e)},E.__r=function(t){$e&&$e(t),H=0;var e=(z=t.__c).__H;e&&(pe===z?(e.__h=[],z.__h=[],e.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(e.__h.forEach(re),e.__h.forEach(ge),e.__h=[],H=0)),pe=z},E.diffed=function(t){Ue&&Ue(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(Re.push(e)!==1&&Oe===E.requestAnimationFrame||((Oe=E.requestAnimationFrame)||pt)(vt)),e.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),pe=z=null},E.__c=function(t,e){e.some(function(n){try{n.__h.forEach(re),n.__h=n.__h.filter(function(o){return!o.__||ge(o)})}catch(o){e.some(function(i){i.__h&&(i.__h=[])}),e=[],E.__e(o,n.__v)}}),je&&je(t,e)},E.unmount=function(t){Ge&&Ge(t);var e,n=t.__c;n&&n.__H&&(n.__H.__.forEach(function(o){try{re(o)}catch(i){e=i}}),n.__H=void 0,e&&E.__e(e,n.__v))};var He=typeof requestAnimationFrame=="function";function pt(t){var e,n=function(){clearTimeout(o),He&&cancelAnimationFrame(e),setTimeout(t)},o=setTimeout(n,100);He&&(e=requestAnimationFrame(n))}function re(t){var e=z,n=t.__c;typeof n=="function"&&(t.__c=void 0,n()),z=e}function ge(t){var e=z;t.__c=t.__(),z=e}function qe(t,e){return!t||t.length!==e.length||e.some(function(n,o){return n!==t[o]})}function Be(t,e){return typeof e=="function"?e(t):e}const gt=t=>({saveGameData(e){try{localStorage.setItem(t,JSON.stringify(e))}catch(n){console.error("Failed to save maze game data:",n)}},loadGameData(){try{const e=localStorage.getItem(t);return e?JSON.parse(e):null}catch(e){return console.error("Failed to load maze game data:",e),null}},resetGameData(){try{localStorage.removeItem(t)}catch(e){console.error("Failed to reset maze game data:",e)}}}),Ve=dt(void 0),Ye={currentLevel:1,highestUnlockedLevel:1,currentTier:1,highestUnlockedTier:1,levelScores:{}},Xe={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:{}},Ct=({children:t,config:e})=>{const n=gt(e.lcPrefix+"progress"),o=n.loadGameData(),[i,s]=q(()=>o||{...Ye});P(()=>{n.saveGameData(i)},[i.currentLevel,i.highestUnlockedLevel,i.currentTier,i.highestUnlockedTier,i.levelScores]);const a=G(()=>Object.values(i.levelScores).reduce((h,_)=>h+_,0),[i.levelScores]),[r,l]=q({...Xe}),c=R(r);P(()=>{c.current=r},[r]);const d=G(()=>[r.playerAtExit?1:0,r.foodCollected===r.totalFoodCount?1:0,r.showClue?0:1],[r.playerAtExit,r.foodCollected,r.totalFoodCount,r.showClue]),u=()=>{n.resetGameData(),s({...Ye}),l({...Xe})};return C(Ve.Provider,{value:{gameProgress:i,setGameProgress:s,gamePlayState:r,setGamePlayState:l,gamePlayStateRef:c,currentScore:d,totalScore:a,config:e,resetGame:u},children:t})},B=()=>{const t=mt(Ve);if(!t)throw new Error("useGameContext must be used within a GameProvider");return t},X=t=>G(()=>{const e=t.map(r=>r.length),n=e.reduce((r,l)=>r+l,0),o=t.length,i=r=>{if(r<1||r>n)return 0;let l=0;for(let c=0;c<e.length;c++)if(l+=e[c],r<=l)return c+1;return 0},s=r=>r<1||r>o?0:e.slice(0,r-1).reduce((l,c)=>l+c,0)+1,a={getTotalLevels:()=>n,getTotalTiers:()=>o,getTierLevelsRange:r=>{if(r<1||r>o)return[0,0];const l=s(r),c=l+e[r-1]-1;return[l,c]},getTierByLevel:i,getFirstLevelOfTier:s,getLevelConfig:r=>{if(r<1||r>n)return null;const l=i(r),c=s(l),d=r-c;return t[l-1][d]},getTierConfig:r=>r<1||r>o?null:t[r-1],isLevelUnlocked:(r,l)=>r<=l,isTierUnlocked:(r,l)=>r<=l,getNextLevelInfo:r=>{if(r>=n)return null;const l=r+1,c=i(r),d=i(l);return{nextLevel:l,nextTier:d,isTierChange:d>c}},getCurrentTierProgress:(r,l)=>{const[c,d]=a.getTierLevelsRange(l),u=r-c+1,h=d-c+1;return{current:u,total:h}},isLastLevelInTier:r=>{const l=i(r),[,c]=a.getTierLevelsRange(l);return r===c},getPreviousLevelInfo:r=>{if(r<=1)return null;const l=r-1,c=i(r),d=i(l);return{prevLevel:l,prevTier:d,isTierChange:d<c}}};return a},[t]),wt=({onTierChange:t,disabled:e})=>{const{gameProgress:n,config:o}=B(),{i18n:i,levelConfig:s}=o,{currentTier:a,highestUnlockedTier:r}=n,c=X(s).getTotalTiers();return C("div",{className:"tier-selector",children:C("select",{value:a,onChange:d=>{d.target&&d.target.value&&t(Number(d.target.value))},disabled:e,className:"tier-dropdown",children:Array.from({length:c},(d,u)=>u+1).map(d=>C("option",{value:d,disabled:d>r,children:i.tier+" "+d},`tier-${d}`))})})},yt=({onLevelChange:t,disabled:e})=>{const{gameProgress:n,config:o}=B(),{i18n:i,levelConfig:s}=o,{currentTier:a,levelScores:r,currentLevel:l,highestUnlockedLevel:c}=n,d=X(s),u=G(()=>{const[h,_]=d.getTierLevelsRange(a);return Array.from({length:_-h+1},(v,p)=>{const m=h+p,g=r[m]||0;return{level:m,score:g}})},[a,r]);return C("div",{className:"level-selector",children:C("select",{value:l,onChange:h=>{h.target&&h.target.value&&t(Number(h.target.value))},disabled:e,className:"level-dropdown",children:u.map(({level:h,score:_})=>C("option",{value:h,disabled:h>c,children:`${i.level} ${h} ${"★".repeat(_)}`},`level-${h}`))})})},ie=({isOpen:t,title:e,className:n="",message:o,children:i,noConfirm:s=!1,noCancel:a=!1,confirmText:r="OK",cancelText:l="Cancel",onConfirm:c,onCancel:d})=>{const u=R(null);return P(()=>{const h=_=>{_.key==="Escape"&&d?.()};return t&&document.addEventListener("keydown",h),()=>{document.removeEventListener("keydown",h)}},[t,d]),C("div",{className:`maze-dialog-overlay ${t?"maze-dialog-visible":""}`,children:C("div",{className:"maze-dialog "+n,ref:u,children:[C("div",{className:"maze-dialog-title",children:e}),C("div",{className:"maze-dialog-content",children:i||C("div",{className:"maze-dialog-message",children:o})}),(!a||!s)&&C("div",{className:"maze-dialog-buttons",children:[!a&&C("button",{type:"button",className:"maze-dialog-cancel",onClick:d,children:l}),!s&&C("button",{type:"button",className:"maze-dialog-confirm",onClick:c,children:r})]})]})})},x={container:null,attachTo(t){return this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.container=document.createElement("div"),this.container.className="toast-container position-top",t.appendChild(this.container),this.container},currentToast:null,currentTimer:null,show(t,e="info",n=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 o=document.createElement("div");o.className=`toast-message type-${e} toast-visible`,o.textContent=t,this.container.appendChild(o),this.currentToast=o,this.currentTimer=setTimeout(()=>{o.classList.remove("toast-visible"),setTimeout(()=>{this.container&&this.container.contains(o)&&(this.container.removeChild(o),this.currentToast===o&&(this.currentToast=null))},300),this.currentTimer=null},n)},clearAll(){if(this.container)for(;this.container.firstChild;)this.container.removeChild(this.container.firstChild)}},bt=()=>{const{gameProgress:t,setGameProgress:e,gamePlayState:n,setGamePlayState:o,gamePlayStateRef:i,totalScore:s,resetGame:a,config:r}=B(),{i18n:l,levelConfig:c}=r,d=X(c),{levelTransitioning:u,showClue:h}=n,{highestUnlockedLevel:_}=t,v=d.getTotalLevels(),[p,m]=q(!1),[g,f]=q(!1),[w,y]=q(!1),b=O=>{const U=d.getFirstLevelOfTier(O);d.isLevelUnlocked(U,_)&&(e(ce=>({...ce,currentTier:O})),k(U))},k=O=>{d.isLevelUnlocked(O,_)&&(e(U=>({...U,currentLevel:O})),x.show(l.levelGoToast.replace("%LEVEL%",O.toString()),"success"))},T=()=>{m(!0)},A=()=>{m(!1)},N=()=>{y(!0)},M=()=>{y(!1)},S=()=>{x.show(h?l.cluePathDisabled:l.cluePathEnabled),o(()=>({...i.current,showClue:!i.current.showClue})),y(!1)},I=()=>{f(!0)},F=()=>{a(),f(!1),x.show(l.resetDoneToast)},ot=()=>{f(!1)};return C("div",{class:"game-panel-container",children:[C("div",{className:"game-controls",children:[C("div",{className:"selectors-container",children:[C(wt,{onTierChange:b,disabled:u}),C(yt,{onLevelChange:k,disabled:u})]}),C("button",{className:`settings-clue-button ${h?"clue-on":"clue-off"}`,disabled:h,title:"Toggle Clue",onClick:N,children:h?l.clueOn:l.clueOff})]}),C("div",{className:"game-settings",children:C("span",{className:"game-settings-icon",onClick:T,children:"★ "+s})}),C(ie,{isOpen:p,title:l.settings,noConfirm:!0,cancelText:l.close,onCancel:A,children:[C("div",{className:"settings-stats",children:[C("div",{children:l.levelComplete+`: ${_}/${v}`}),C("div",{children:l.starsCollected+": "+s}),C("div",{children:l.avgStarPerLevel+": "+(s/_).toFixed(2)})]}),C("div",{className:"settings-item-box",children:[C("button",{className:"settings-reset-button",title:"Reset Game",onClick:I,children:l.reset}),C("div",{className:"settings-item-tip",children:l.resetTip})]})]}),C(ie,{isOpen:g,title:l.confirmReset,message:l.confirmResetMessage,confirmText:l.reset,cancelText:l.cancel,onConfirm:F,onCancel:ot}),C(ie,{isOpen:w,title:l.confirmClue,message:l.confirmClueMessage,confirmText:l.confirm,cancelText:l.cancel,onConfirm:S,onCancel:M})]})};function Ce(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function kt(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function we(t,e,n){return e&&kt(t.prototype,e),t}function Ke(t){return+t.replace(/px/,"")}function Tt(t){var e=window.devicePixelRatio,n=getComputedStyle(t),o=Ke(n.getPropertyValue("width")),i=Ke(n.getPropertyValue("height"));t.setAttribute("width",(o*e).toString()),t.setAttribute("height",(i*e).toString())}function D(t,e){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,o=Math.random()*(e-t)+t;return Math.floor(o*Math.pow(10,n))/Math.pow(10,n)}function Je(t){return t[D(0,t.length)]}var Lt=.00125,zt=5e-4,St=9e-4,Nt=1e-5,Et=6,At=80,Mt=.9,Pt=1.7,It=.2,Ft=.6,Dt=.03,Ot=.07,Rt=15,xt=82,$t=100,Ut=250,jt=40,Gt=["#fcf403","#62fc03","#f4fc03","#03e7fc","#03fca5","#a503fc","#fc03ad","#fc03c2"];function Ze(t){var e=1920;return Math.log(t)/Math.log(e)}var Qe=function(){function t(e){Ce(this,t);var n=e.initialPosition,o=e.direction,i=e.confettiRadius,s=e.confettiColors,a=e.emojis,r=e.emojiSize,l=e.canvasWidth,c=D(Mt,Pt,3),d=c*Ze(l);this.confettiSpeed={x:d,y:d},this.finalConfettiSpeedX=D(It,Ft,3),this.rotationSpeed=a.length?.01:D(Dt,Ot,3)*Ze(l),this.dragForceCoefficient=D(zt,St,6),this.radius={x:i,y:i},this.initialRadius=i,this.rotationAngle=o==="left"?D(0,.2,3):D(-.2,0,3),this.emojiSize=r,this.emojiRotationAngle=D(0,2*Math.PI),this.radiusYUpdateDirection="down";var u=o==="left"?D(xt,Rt)*Math.PI/180:D(-15,-82)*Math.PI/180;this.absCos=Math.abs(Math.cos(u)),this.absSin=Math.abs(Math.sin(u));var h=D(-150,0),_={x:n.x+(o==="left"?-h:h)*this.absCos,y:n.y-h*this.absSin};this.currentPosition=Object.assign({},_),this.initialPosition=Object.assign({},_),this.color=a.length?null:Je(s),this.emoji=a.length?Je(a):null,this.createdAt=new Date().getTime(),this.direction=o}return we(t,[{key:"draw",value:function(n){var o=this.currentPosition,i=this.radius,s=this.color,a=this.emoji,r=this.rotationAngle,l=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()):a&&(n.font="".concat(c,"px serif"),n.save(),n.translate(d*o.x,d*o.y),n.rotate(l),n.textAlign="center",n.fillText(a,0,0),n.restore())}},{key:"updatePosition",value:function(n,o){var i=this.confettiSpeed,s=this.dragForceCoefficient,a=this.finalConfettiSpeedX,r=this.radiusYUpdateDirection,l=this.rotationSpeed,c=this.createdAt,d=this.direction,u=o-c;if(i.x>a&&(this.confettiSpeed.x-=s*n),this.currentPosition.x+=i.x*(d==="left"?-this.absCos:this.absCos)*n,this.currentPosition.y=this.initialPosition.y-i.y*this.absSin*u+Lt*Math.pow(u,2)/2,this.rotationSpeed-=this.emoji?1e-4:Nt*n,this.rotationSpeed<0&&(this.rotationSpeed=0),this.emoji){this.emojiRotationAngle+=this.rotationSpeed*n%(2*Math.PI);return}r==="down"?(this.radius.y-=n*l,this.radius.y<=0&&(this.radius.y=0,this.radiusYUpdateDirection="up")):(this.radius.y+=n*l,this.radius.y>=this.initialRadius&&(this.radius.y=this.initialRadius,this.radiusYUpdateDirection="down"))}},{key:"getIsVisibleOnCanvas",value:function(n){return this.currentPosition.y<n+$t}}]),t}();function Wt(){var t=document.createElement("canvas");return t.style.position="fixed",t.style.width="100%",t.style.height="100%",t.style.top="0",t.style.left="0",t.style.zIndex="1000",t.style.pointerEvents="none",document.body.appendChild(t),t}function Ht(t){var e=t.confettiRadius,n=e===void 0?Et:e,o=t.confettiNumber,i=o===void 0?t.confettiesNumber||(t.emojis?jt:Ut):o,s=t.confettiColors,a=s===void 0?Gt:s,r=t.emojis,l=r===void 0?t.emojies||[]:r,c=t.emojiSize,d=c===void 0?At:c;return t.emojies&&console.error("emojies argument is deprecated, please use emojis instead"),t.confettiesNumber&&console.error("confettiesNumber argument is deprecated, please use confettiNumber instead"),{confettiRadius:n,confettiNumber:i,confettiColors:a,emojis:l,emojiSize:d}}var qt=function(){function t(e){var n=this;Ce(this,t),this.canvasContext=e,this.shapes=[],this.promise=new Promise(function(o){return n.resolvePromise=o})}return we(t,[{key:"getBatchCompletePromise",value:function(){return this.promise}},{key:"addShapes",value:function(){var n;(n=this.shapes).push.apply(n,arguments)}},{key:"complete",value:function(){var n;return this.shapes.length?!1:((n=this.resolvePromise)===null||n===void 0||n.call(this),!0)}},{key:"processShapes",value:function(n,o,i){var s=this,a=n.timeDelta,r=n.currentTime;this.shapes=this.shapes.filter(function(l){return l.updatePosition(a,r),l.draw(s.canvasContext),i?l.getIsVisibleOnCanvas(o):!0})}}]),t}(),Bt=function(){function t(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Ce(this,t),this.activeConfettiBatches=[],this.canvas=e.canvas||Wt(),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 we(t,[{key:"loop",value:function(){this.requestAnimationFrameRequested=!1,Tt(this.canvas);var n=new Date().getTime(),o=n-this.lastUpdated,i=this.canvas.offsetHeight,s=this.iterationIndex%10===0;this.activeConfettiBatches=this.activeConfettiBatches.filter(function(a){return a.processShapes({timeDelta:o,currentTime:n},i,s),s?!a.complete():!0}),this.iterationIndex++,this.queueAnimationFrameIfNeeded(n)}},{key:"queueAnimationFrameIfNeeded",value:function(n){this.requestAnimationFrameRequested||this.activeConfettiBatches.length<1||(this.requestAnimationFrameRequested=!0,this.lastUpdated=n||new Date().getTime(),requestAnimationFrame(this.loop))}},{key:"addConfetti",value:function(){for(var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},o=Ht(n),i=o.confettiRadius,s=o.confettiNumber,a=o.confettiColors,r=o.emojis,l=o.emojiSize,c=this.canvas.getBoundingClientRect(),d=c.width,u=c.height,h=u*5/7,_={x:0,y:h},v={x:d,y:h},p=new qt(this.canvasContext),m=0;m<s/2;m++){var g=new Qe({initialPosition:_,direction:"right",confettiRadius:i,confettiColors:a,confettiNumber:s,emojis:r,emojiSize:l,canvasWidth:d}),f=new Qe({initialPosition:v,direction:"left",confettiRadius:i,confettiColors:a,confettiNumber:s,emojis:r,emojiSize:l,canvasWidth:d});p.addShapes(g,f)}return this.activeConfettiBatches.push(p),this.queueAnimationFrameIfNeeded(),p.getBatchCompletePromise()}},{key:"clearCanvas",value:function(){this.activeConfettiBatches=[]}},{key:"destroyCanvas",value:function(){this.canvas.remove()}}]),t}();const Vt=new Bt,Yt=({onRetry:t})=>{const{config:e,currentScore:n,gamePlayState:o,setGamePlayState:i,gameProgress:s,setGameProgress:a}=B(),{i18n:r,levelConfig:l}=e,[c,d,u]=n,{foodCollected:h,totalFoodCount:_,playerAtExit:v,levelTransitioning:p}=o,{currentLevel:m}=s,[g,f]=q(!1);P(()=>{v&&p&&(Vt.addConfetti(),x.show(r.levelCompleteToast,"success"),f(!0))},[v,p]);const w=X(l),y=w.getTotalLevels(),b=G(()=>m>=y,[m,y]),k=()=>{f(!1),x.show(r.levelRestartToast,"info"),t?.()},T=()=>{f(!1),i(N=>({...N,isGameActive:!0,levelTransitioning:!1}))},A=()=>{f(!1);const N=w.getNextLevelInfo(m);if(!N)return;const{nextLevel:M,nextTier:S,isTierChange:I}=N;I&&x.show(r.tierUnlockedToast.replace("%TIER%",S.toString()),"success"),a(F=>({...F,currentLevel:M,currentTier:S,highestUnlockedLevel:Math.max(F.highestUnlockedLevel,M),highestUnlockedTier:Math.max(F.highestUnlockedTier,S),levelScores:{...F.levelScores,[F.currentLevel]:Math.max(Object.values(n).filter(Boolean).length,F.levelScores[F.currentLevel]||0)}}))};return C(ie,{className:"level-complete-dialog",isOpen:g,title:r.congratulations,cancelText:r.retry,onCancel:k,noConfirm:!!d,confirmText:r.continue,onConfirm:T,children:[C("div",{className:"maze-summary-message",children:[!!c&&C("div",{children:"★ - "+r.findYourExit}),C("div",{children:u?"★ - "+r.withoutClue:"☆ - "+r.withClue}),C("div",{children:(d?"★ - "+r.collectAllStars:"☆ - "+r.notCollectAllStars)+` (${h}/${_})`})]}),b&&C("div",{className:"all-levels-completed",children:r.allLevelsCompleted}),C("div",{className:"go-next-level",children:b?"OK":C("button",{type:"button",onClick:A,children:r.nextLevel})}),!d&&C("div",{className:"not-all-stars-collected",children:r.continueMessage})]})},Xt=(t,e)=>{const n=R({canvasWidth:0,canvasHeight:0});return P(()=>{const o=()=>{const s=t.current;if(!s)return;const a=s.parentElement;if(!a)return;const r=a.clientWidth,l=window.devicePixelRatio||1;s.style.width=`${r}px`,s.style.height=`${r}px`;const c=r*l,d=r*l;s.width=c,s.height=d,n.current={canvasWidth:c,canvasHeight:d}};o();let i=null;return window.ResizeObserver&&(i=new ResizeObserver(o),i.observe(t.current.parentElement)),window.addEventListener("resize",o),()=>{window.removeEventListener("resize",o),i?.disconnect()}},[t,e]),n},Kt=t=>{const{config:e,gamePlayState:{maze:n}}=B(),o=R({cellWidth:0,cellHeight:0});return P(()=>{const i=e.renderConfig.padding,s=()=>{const r=t.current;if(!r||!n)return;const{rows:l,cols:c}=n;if(l<=0||c<=0)return;const d=(r.width-i*2)/c,u=(r.height-i*2)/l;o.current={cellWidth:d,cellHeight:u}};s();let a=null;return t.current&&window.ResizeObserver&&(a=new ResizeObserver(s),a.observe(t.current)),()=>{t.current&&a?.disconnect()}},[t,n]),o},se={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]},Jt=({containerRef:t,gamePlayStateRef:e,setGamePlayState:n,moveSpeed:o,playerRadius:i,onFoodCollected:s})=>{const a=R(!1),r=R(new Set),l=(v,p)=>{const m=e.current;if(!m.maze)return{canMove:!1,newCell:null};const[g,f]=se[v];if(et(p,g,f,i,o,m.maze))return{canMove:!1,newCell:null};const{row:y,col:b}=p,k=y+g*o,T=b+f*o,A=Math.floor(y),N=Math.floor(b),M=Math.floor(k),S=Math.floor(T);return M!==A||S!==N?m.maze.isValid(M,S)?{canMove:!0,newCell:{row:M,col:S}}:{canMove:!1,newCell:null}:{canMove:!0,newCell:null}},c=()=>{const v=e.current,{row:p,col:m}=v.playerCell,g=i*2,f=v.foodCells.findIndex(b=>Math.sqrt(Math.pow(p-b.row,2)+Math.pow(m-b.col,2))<g);f!==-1&&s&&(s(),e.current={...e.current,foodCollected:e.current.foodCollected+1,foodCells:e.current.foodCells.filter((b,k)=>k!==f)});const y=Qt(v.playerCell,v.exitCell,v.maze,i);y&&!e.current.playerAtExit?(e.current={...e.current,playerAtExit:!0,isGameActive:!1,levelTransitioning:!0},requestIdleCallback(()=>{n(()=>({...e.current}))},{timeout:10})):!y&&e.current.playerAtExit&&(e.current={...e.current,playerAtExit:!1,isGameActive:!0,levelTransitioning:!1})},d=v=>{const p=e.current,m=Math.round(v.row),g=Math.round(v.col),f=p.playerPath[p.playerPath.length-1],w=f.row===m&&f.col===g,y=Math.abs(f.row-m),b=Math.abs(f.col-g);if((y===1&&b===0||y===0&&b===1)&&!w){const T=`${f.row},${f.col}-${m},${g}`;e.current={...e.current,playerPath:[...e.current.playerPath,{row:m,col:g}],visitCounts:{...e.current.visitCounts,[T]:(e.current.visitCounts[T]||0)+1}}}},u=()=>{if(a.current||r.current.size===0)return;const v=e.current;!v.playerCell||!Array.from(r.current).some(m=>{const{canMove:g}=l(m,v.playerCell);return g})||(a.current=!0)};P(()=>{const v=w=>{(w.key==="ArrowUp"||w.key==="ArrowDown"||w.key==="ArrowLeft"||w.key==="ArrowRight"||w.key===" ")&&w.preventDefault()},p=w=>{const y=w.key;y in se&&(w.preventDefault(),e.current.isGameActive&&(r.current.has(y)||(r.current.add(y),a.current||u())))},m=w=>{const y=w.key;y in se&&(w.preventDefault(),r.current.delete(y),r.current.size===0&&_())},g=w=>{w.preventDefault();const y=e.current;if(!y.isGameActive||!y.maze||a.current)return;const b=w.touches[0],k=document.elementFromPoint(b.clientX,b.clientY);let T=null;k&&(k.classList.contains("maze-up")?T="ArrowUp":k.classList.contains("maze-down")?T="ArrowDown":k.classList.contains("maze-left")?T="ArrowLeft":k.classList.contains("maze-right")&&(T="ArrowRight")),T&&(r.current.clear(),r.current.add(T),u())},f=()=>{_()};return window.addEventListener("keydown",v,{capture:!0}),window.addEventListener("keydown",p),window.addEventListener("keyup",m),t.current?.addEventListener("touchstart",g,{passive:!1}),t.current?.addEventListener("touchend",f),()=>{window.removeEventListener("keydown",v,{capture:!0}),window.removeEventListener("keydown",p),window.removeEventListener("keyup",m),t.current?.removeEventListener("touchstart",g),t.current?.removeEventListener("touchend",f)}},[]);const h=ft(()=>{if(!a.current||r.current.size===0)return e.current.playerCell;const v=e.current.playerCell;let p=0,m=0,g=0;for(const O of r.current){const{canMove:U}=l(O,v);if(U){const[ce,gn]=se[O];p+=ce,m+=gn,g++}}if(g===0)return e.current.playerCell;const f=Math.sqrt(p*p+m*m),w=f>0?p/f:0,y=f>0?m/f:0,b=Number((v.row+w*o).toFixed(2)),k=Number((v.col+y*o).toFixed(2)),T=b-v.row,A=k-v.col,N=Math.sqrt(T*T+A*A);if(N>0){const O=T/N,U=A/N;if(et(v,O,U,i,N,e.current.maze))return e.current.playerCell}e.current.playerCell={row:b,col:k},c();const M=Math.round(v.row),S=Math.round(v.col),I=Math.round(b),F=Math.round(k);return(I!==M||F!==S)&&d({row:I,col:F}),e.current.playerCell},[o]),_=()=>{a.current=!1,r.current.clear()};return{updatePlayerPos:h,resetMovingState:_}};function et(t,e,n,o,i,s){const a=t.row+e*i,r=t.col+n*i,l={row:a,col:r},c=[],d=Math.floor(t.row),u=Math.floor(t.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[_,v]of h){const p=d+_,m=u+v;s.isValid(p,m)&&c.push({row:p,col:m})}for(const _ of c){const v=Zt(_.row,_.col,s);for(const p of v)if(tt(l,p)<o)return!0}return!1}function Zt(t,e,n){const o=[],i=n.grid[t][e];return i.walls.top&&o.push({start:{row:t-.5,col:e-.5},end:{row:t-.5,col:e+.5}}),i.walls.right&&o.push({start:{row:t-.5,col:e+.5},end:{row:t+.5,col:e+.5}}),i.walls.bottom&&o.push({start:{row:t+.5,col:e-.5},end:{row:t+.5,col:e+.5}}),i.walls.left&&o.push({start:{row:t-.5,col:e-.5},end:{row:t+.5,col:e-.5}}),o}function tt(t,e){const{start:n,end:o}=e,i=o.col-n.col,s=o.row-n.row,a=t.col-n.col,r=t.row-n.row,l=i*i+s*s;if(l===0)return Math.sqrt(a*a+r*r);const c=Math.max(0,Math.min(1,(a*i+r*s)/l)),d=n.col+c*i,u=n.row+c*s,h=t.col-d,_=t.row-u;return Math.sqrt(h*h+_*_)}function Qt(t,e,n,o){if(Math.sqrt(Math.pow(t.row-e.row,2)+Math.pow(t.col-e.col,2))>1.5||!n.isValid(e.row,e.col))return!1;if(n.grid[e.row][e.col].walls.bottom){const a={start:{row:e.row+.5,col:e.col-.5},end:{row:e.row+.5,col:e.col+.5}};if(tt(t,a)<=o+.05)return!0}return!1}function en(t,e,n,o,i){if(!t||!e.maze)return;const{canvasWidth:s,canvasHeight:a}=n,{cellWidth:r,cellHeight:l}=o,{maze:c,playerCell:d,exitCell:u,foodCells:h,showClue:_,playerPath:v,visitCounts:p}=e,{padding:m,wallWidth:g,wallColor:f,playerColor:w,playerRadius:y,exitColor:b,foodColor:k,backgroundColor:T,clueColor:A}=i;t.clearRect(0,0,s,a),t.save(),t.fillStyle=T,t.fillRect(0,0,s,a),t.restore(),_&&ln({ctx:t,playerPath:v,visitCounts:p,cellWidth:r,cellHeight:l,padding:m,clueColor:A}),tn({ctx:t,maze:c,cellWidth:r,cellHeight:l,padding:m,wallColor:f,wallWidth:g}),on({ctx:t,maze:c,exitCell:u,cellWidth:r,cellHeight:l,padding:m,exitColor:b,wallWidth:g}),rn({ctx:t,foodCells:h,cellWidth:r,cellHeight:l,padding:m,foodColor:k}),nn({ctx:t,playerCell:d,playerRadius:y,cellWidth:r,cellHeight:l,padding:m,playerColor:w})}function tn({ctx:t,maze:e,cellWidth:n,cellHeight:o,padding:i,wallColor:s,wallWidth:a}){t.save(),t.strokeStyle=s,t.lineWidth=a,t.lineCap="round",t.beginPath(),an(e,n,o,i).forEach(l=>{t.moveTo(l.x1,l.y1),t.lineTo(l.x2,l.y2)}),t.stroke(),t.restore()}function nn({ctx:t,playerCell:e,playerRadius:n,cellWidth:o,cellHeight:i,padding:s,playerColor:a}){const{x:r,y:l}=le(e.row,e.col,o,i,s),c=Math.min(o,i)*Math.min(n,.5);t.save(),t.fillStyle=a,t.beginPath(),t.arc(r,l,c,0,Math.PI*2),t.fill(),t.restore()}function on({ctx:t,maze:e,exitCell:n,cellWidth:o,cellHeight:i,padding:s,exitColor:a,wallWidth:r}){const{row:l,col:c}=n;if(!e.isValid(l,c))return;const d=e.grid[l][c],u=s+c*o,h=s+l*i;t.save(),t.globalCompositeOperation="destination-out",t.lineWidth=r+2,t.lineCap="round",t.beginPath(),d.walls.bottom&&(t.moveTo(u,h+i),t.lineTo(u+o,h+i)),t.stroke(),t.globalCompositeOperation="source-over",t.strokeStyle=a,t.lineWidth=r+2,t.setLineDash([8,12]),t.beginPath(),d.walls.bottom&&(t.moveTo(u,h+i),t.lineTo(u+o,h+i)),t.stroke(),t.restore()}function rn({ctx:t,foodCells:e,cellWidth:n,cellHeight:o,padding:i,foodColor:s}){t.fillStyle=s;const a=Math.min(n,o)*.25;e.forEach(r=>{const{x:l,y:c}=le(r.row,r.col,n,o,i);sn(t,l,c,a*1.2,5,a*.6)})}function sn(t,e,n,o,i,s){t.save(),t.beginPath();for(let a=0;a<i*2;a++){const r=a%2===0?o:s,l=Math.PI*a/i;t.lineTo(e+r*Math.sin(l),n+r*Math.cos(l))}t.closePath(),t.fill(),t.restore()}function ln({ctx:t,playerPath:e,visitCounts:n,cellWidth:o,cellHeight:i,padding:s,clueColor:a}){if(!(!e||e.length<2||!n)){t.save();for(let r=1;r<e.length;r++){const l=e[r-1],c=e[r],d=`${l.row},${l.col}-${c.row},${c.col}`,u=`${c.row},${c.col}-${l.row},${l.col}`,h=(n[d]||0)+(n[u]||0),_=Math.min(.2+h*.1,.9),v=Math.max(3,o*.1)+h*.5;try{t.strokeStyle=a.replace(")",`, ${_})`).replace("rgb(","rgba(")}catch{t.strokeStyle=`rgba(255, 0, 0, ${_})`}t.lineWidth=v,t.lineCap="round",t.lineJoin="round";const{x:p,y:m}=le(l.row,l.col,o,i,s),{x:g,y:f}=le(c.row,c.col,o,i,s);t.beginPath(),t.moveTo(p,m),t.lineTo(g,f),t.stroke()}t.restore()}}function an(t,e,n,o){const i=[];for(let s=0;s<t.rows;s++)for(let a=0;a<t.cols;a++){const r=t.grid[s][a],l=o+a*e,c=o+s*n;r.walls.top&&i.push({x1:l,y1:c,x2:l+e,y2:c}),r.walls.right&&i.push({x1:l+e,y1:c,x2:l+e,y2:c+n}),r.walls.bottom&&i.push({x1:l,y1:c+n,x2:l+e,y2:c+n}),r.walls.left&&i.push({x1:l,y1:c,x2:l,y2:c+n})}return i}function le(t,e,n,o,i){return{x:i+e*n+n/2,y:i+t*o+o/2}}function cn(t){return function(){let e=t+=1831565813;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}}class un{constructor(e,n){this.row=e,this.col=n}visited=!1;walls={top:!0,right:!0,bottom:!0,left:!0}}class dn{rows;cols;grid;seed;random;constructor(e,n,o,i,s={row:0,col:0}){this.rows=e,this.cols=n,this.seed=i??Math.floor(Math.random()*1e6),this.random=cn(this.seed),this.grid=this.initializeGrid(),this.generate(o,s)}initializeGrid(){const e=[];for(let n=0;n<this.rows;n++){e[n]=[];for(let o=0;o<this.cols;o++)e[n][o]=new un(n,o)}return e}isValid(e,n){return e>=0&&e<this.rows&&n>=0&&n<this.cols}getNeighbors(e,n){const o=[],i=[{r:-1,c:0},{r:0,c:1},{r:1,c:0},{r:0,c:-1}];for(const s of i){const a=e+s.r,r=n+s.c;this.isValid(a,r)&&o.push({row:a,col:r})}return o}getUnvisitedNeighbors(e,n){return this.getNeighbors(e,n).filter(o=>!this.grid[o.row][o.col].visited)}getVisitedNeighbors(e,n){return this.getNeighbors(e,n).filter(o=>this.grid[o.row][o.col].visited)}removeWall(e,n,o,i){const s=this.grid[e][n],a=this.grid[o][i];e===o+1?(s.walls.top=!1,a.walls.bottom=!1):e===o-1?(s.walls.bottom=!1,a.walls.top=!1):n===i+1?(s.walls.left=!1,a.walls.right=!1):n===i-1&&(s.walls.right=!1,a.walls.left=!1)}generate(e,n={row:0,col:0}){switch(e){case"backtracking":this.generateWithBacktracking();break;case"prims":this.generateWithPrims();break;default:throw new Error(`Unknown maze generation method: ${e}`)}this.addOpenings(n)}generateWithBacktracking(){const e=[],n=this.randomNumber(this.rows),o=this.randomNumber(this.cols);let i={row:n,col:o};for(this.grid[n][o].visited=!0,e.push(i);e.length>0;){i=e[e.length-1];const{row:s,col:a}=i,r=this.getUnvisitedNeighbors(s,a);if(r.length>0){const l=this.randomPick(r),{row:c,col:d}=l;this.removeWall(s,a,c,d),this.grid[c][d].visited=!0,e.push(l)}else e.pop()}}generateWithPrims(){const e=[],n=(s,a)=>{const r=this.getNeighbors(s,a);for(const l of r)!this.grid[l.row][l.col].visited&&!e.some(c=>c.row===l.row&&c.col===l.col)&&e.push(l)},o=this.randomNumber(this.rows),i=this.randomNumber(this.cols);for(this.grid[o][i].visited=!0,n(o,i);e.length>0;){const s=this.randomNumber(e.length),a=e[s],{row:r,col:l}=a,c=this.getVisitedNeighbors(r,l);if(c.length>0){const d=this.randomPick(c);this.removeWall(r,l,d.row,d.col),this.grid[r][l].visited=!0,n(r,l)}e.splice(s,1)}}addOpenings(e){this.grid[e.row][e.col].walls.top=!1}randomNumber(e){return Math.floor(this.random()*e)}randomPick(e){return e[Math.floor(this.random()*e.length)]}}const hn=(t,e,n)=>{if(!t.isValid(e,n))return!1;const o=t.grid[e][n];return!o.walls.top||!o.walls.right||!o.walls.bottom||!o.walls.left},_n=t=>t===1?2:t>=2&&t<=5?3:t>=6&&t<=11?4:t>=12&&t<=15?5:6,fn=(t,e)=>{if(!e)return console.error(`Cannot find Level ${t}'s config.`),null;const{size:n,seed:o,method:i,entry:s,exit:a}=e,r=n,l=n,c=s||{row:0,col:0},d=a||{row:r-1,col:l-1},u=new dn(r,l,i,o,s),h=_n(t),_=[];for(let v=0;v<h;v++){let p;do p={row:Math.floor(u.random()*r),col:Math.floor(u.random()*l)};while(p.row===c.row&&p.col===c.col||p.row===d.row&&p.col===d.col||!hn(u,p.row,p.col)||_.some(m=>m.row===p.row&&m.col===p.col));_.push(p)}return{isGameActive:!0,levelTransitioning:!1,maze:u,playerCell:c,exitCell:d,foodCells:_,playerAtExit:!1,foodCollected:0,totalFoodCount:h,showClue:!1,playerPath:[c],visitCounts:{[`${c.row},${c.col}`]:1}}};function mn(){const{setGamePlayState:t,gamePlayStateRef:e,gameProgress:n,config:o}=B(),i=R(null),s=R(null),a=R(null),{i18n:r,levelConfig:l,renderConfig:c}=o,d=X(l),u=R(d.getLevelConfig(n.currentLevel));P(()=>{i.current&&x.attachTo(i.current)},[]);const h=Xt(a),_=Kt(a);P(()=>{u.current=d.getLevelConfig(n.currentLevel)},[n.currentLevel]);const v=()=>{const f=fn(n.currentLevel,u.current);f&&t(w=>({...w,...f}))};P(()=>{v()},[n.currentLevel]);const p=()=>{v()},{updatePlayerPos:m,resetMovingState:g}=Jt({containerRef:s,gamePlayStateRef:e,setGamePlayState:t,playerRadius:c.playerRadius,moveSpeed:c.gridMoveSpeed,onFoodCollected:()=>{const f=e.current.totalFoodCount-e.current.foodCollected-1;f>0?x.show(r.foodCollectedToast.replace("%NUM%",f.toString()),"success",3e3):x.show(r.allFoodCollectedToast,"success")}});return P(()=>{g()},[n.currentLevel,g]),P(()=>{let f,w=!document.hidden;const y=()=>{const k=a.current?.getContext("2d"),T=e.current;if(!(w&&T?.isGameActive&&k&&T?.maze)){f=requestAnimationFrame(y);return}const N=u.current?.wallWidth||c?.wallWidth;m(),en(k,T,h.current,_.current,{...c,wallWidth:N}),f=requestAnimationFrame(y)},b=k=>{const T=w;w=!document.hidden&&document.visibilityState==="visible"&&(!k||k.type!=="blur"),!T&&w?e.current?.levelTransitioning===!1&&t({...e.current,isGameActive:!0}):T&&!w&&t({...e.current,isGameActive:!1})};return document.addEventListener("visibilitychange",b),window.addEventListener("blur",b),window.addEventListener("focus",b),f=requestAnimationFrame(y),()=>{cancelAnimationFrame(f),document.removeEventListener("visibilitychange",b),window.removeEventListener("blur",b),window.removeEventListener("focus",b)}},[]),P(()=>{x.show(r.useArrowKeyTips,"info",3e3)},[]),C("div",{className:"maze-game-container",ref:i,children:[C(bt,{}),C(Yt,{onRetry:p}),C("div",{className:"maze-canvas-container",ref:s,children:[C("canvas",{ref:a,className:"maze-game-canvas"}),C("div",{className:"maze-touch-area maze-up"}),C("div",{className:"maze-touch-area maze-down"}),C("div",{className:"maze-touch-area maze-left"}),C("div",{className:"maze-touch-area maze-right"})]})]})}const nt=[[{size:8,seed:12345,method:"backtracking",wallWidth:4},{size:8,seed:23456,method:"backtracking"},{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"}]],ae={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 ➤",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!",continueMessage:"You haven't collected all stars. You can click 'Continue' button to collect all stars.",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:{gridMoveSpeed:.03,padding:10,wallWidth:2,wallColor:"#000000",exitColor:"#F44336",foodColor:"#4CAF50",clueColor:"rgb(255,0,0)",backgroundColor:"#ffffff",playerColor:"#4CAF50",playerRadius:.2},levelConfig:nt};function vn({config:t={}}){const e={...ae.i18n,...t.i18n||{}},n={...ae.renderConfig,...t.renderConfig||{}},o=t.levelConfig||nt,i={...ae,...t,i18n:e,levelConfig:o,renderConfig:n};return C(Ct,{config:i,children:C(mn,{})})}const pn={root:"https://unpkg.com/@roudanio/maze@0.0.13/dist/",...ae};return`${JSON.stringify(pn,null,2)}`,{async init(t,e){const n=typeof t=="string"?document.querySelector(t):t;if(!n){console.warn("Cannot find the root element");const l=document.createElement("div");l.style.textAlign="center",l.style.padding="20px",l.innerHTML="Cannot find the root element",document.body.append(l);return}let{root:o=location.origin}=e;o.at(-1)!=="/"&&(o+="/");const i=document.createElement("div"),s=document.createElement("div");i.style.cssText=`
|
|
1
|
+
var Maze=function(){"use strict";var K,S,ye,W,be,ke,Te,Le,ue,de,he,Se,V={},ze=[],rt=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,J=Array.isArray;function $(t,e){for(var n in e)t[n]=e[n];return t}function fe(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function it(t,e,n){var o,i,s,l={};for(s in e)s=="key"?o=e[s]:s=="ref"?i=e[s]:l[s]=e[s];if(arguments.length>2&&(l.children=arguments.length>3?K.call(arguments,2):n),typeof t=="function"&&t.defaultProps!=null)for(s in t.defaultProps)l[s]==null&&(l[s]=t.defaultProps[s]);return Z(t,l,o,i,null)}function Z(t,e,n,o,i){var s={type:t,props:e,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++ye,__i:-1,__u:0};return i==null&&S.vnode!=null&&S.vnode(s),s}function Q(t){return t.children}function ee(t,e){this.props=t,this.context=e}function j(t,e){if(e==null)return t.__?j(t.__,t.__i+1):null;for(var n;e<t.__k.length;e++)if((n=t.__k[e])!=null&&n.__e!=null)return n.__e;return typeof t.type=="function"?j(t):null}function Ne(t){var e,n;if((t=t.__)!=null&&t.__c!=null){for(t.__e=t.__c.base=null,e=0;e<t.__k.length;e++)if((n=t.__k[e])!=null&&n.__e!=null){t.__e=t.__c.base=n.__e;break}return Ne(t)}}function _e(t){(!t.__d&&(t.__d=!0)&&W.push(t)&&!te.__r++||be!=S.debounceRendering)&&((be=S.debounceRendering)||ke)(te)}function te(){for(var t,e,n,o,i,s,l,r=1;W.length;)W.length>r&&W.sort(Te),t=W.shift(),r=W.length,t.__d&&(n=void 0,i=(o=(e=t).__v).__e,s=[],l=[],e.__P&&((n=$({},o)).__v=o.__v+1,S.vnode&&S.vnode(n),me(e.__P,n,o,e.__n,e.__P.namespaceURI,32&o.__u?[i]:null,s,i??j(o),!!(32&o.__u),l),n.__v=o.__v,n.__.__k[n.__i]=n,Ie(s,n,l),n.__e!=i&&Ne(n)));te.__r=0}function Ae(t,e,n,o,i,s,l,r,a,c,d){var u,h,f,m,g,_,p=o&&o.__k||ze,v=e.length;for(a=st(n,e,p,a,v),u=0;u<v;u++)(f=n.__k[u])!=null&&(h=f.__i==-1?V:p[f.__i]||V,f.__i=u,_=me(t,f,h,i,s,l,r,a,c,d),m=f.__e,f.ref&&h.ref!=f.ref&&(h.ref&&ve(h.ref,null,f),d.push(f.ref,f.__c||m,f)),g==null&&m!=null&&(g=m),4&f.__u||h.__k===f.__k?a=Ee(f,a,t):typeof f.type=="function"&&_!==void 0?a=_:m&&(a=m.nextSibling),f.__u&=-7);return n.__e=g,a}function st(t,e,n,o,i){var s,l,r,a,c,d=n.length,u=d,h=0;for(t.__k=new Array(i),s=0;s<i;s++)(l=e[s])!=null&&typeof l!="boolean"&&typeof l!="function"?(a=s+h,(l=t.__k[s]=typeof l=="string"||typeof l=="number"||typeof l=="bigint"||l.constructor==String?Z(null,l,null,null,null):J(l)?Z(Q,{children:l},null,null,null):l.constructor==null&&l.__b>0?Z(l.type,l.props,l.key,l.ref?l.ref:null,l.__v):l).__=t,l.__b=t.__b+1,r=null,(c=l.__i=lt(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))):t.__k[s]=null;if(u)for(s=0;s<d;s++)(r=n[s])!=null&&(2&r.__u)==0&&(r.__e==o&&(o=j(r)),De(r,r));return o}function Ee(t,e,n){var o,i;if(typeof t.type=="function"){for(o=t.__k,i=0;o&&i<o.length;i++)o[i]&&(o[i].__=t,e=Ee(o[i],e,n));return e}t.__e!=e&&(e&&t.type&&!n.contains(e)&&(e=j(t)),n.insertBefore(t.__e,e||null),e=t.__e);do e=e&&e.nextSibling;while(e!=null&&e.nodeType==8);return e}function lt(t,e,n,o){var i,s,l=t.key,r=t.type,a=e[n];if(a===null&&t.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<e.length;){if(i>=0){if((a=e[i])&&(2&a.__u)==0&&l==a.key&&r==a.type)return i;i--}if(s<e.length){if((a=e[s])&&(2&a.__u)==0&&l==a.key&&r==a.type)return s;s++}}return-1}function Me(t,e,n){e[0]=="-"?t.setProperty(e,n??""):t[e]=n==null?"":typeof n!="number"||rt.test(e)?n:n+"px"}function ne(t,e,n,o,i){var s;e:if(e=="style")if(typeof n=="string")t.style.cssText=n;else{if(typeof o=="string"&&(t.style.cssText=o=""),o)for(e in o)n&&e in n||Me(t.style,e,"");if(n)for(e in n)o&&n[e]==o[e]||Me(t.style,e,n[e])}else if(e[0]=="o"&&e[1]=="n")s=e!=(e=e.replace(Le,"$1")),e=e.toLowerCase()in t||e=="onFocusOut"||e=="onFocusIn"?e.toLowerCase().slice(2):e.slice(2),t.l||(t.l={}),t.l[e+s]=n,n?o?n.u=o.u:(n.u=ue,t.addEventListener(e,s?he:de,s)):t.removeEventListener(e,s?he:de,s);else{if(i=="http://www.w3.org/2000/svg")e=e.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(e!="width"&&e!="height"&&e!="href"&&e!="list"&&e!="form"&&e!="tabIndex"&&e!="download"&&e!="rowSpan"&&e!="colSpan"&&e!="role"&&e!="popover"&&e in t)try{t[e]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&e[4]!="-"?t.removeAttribute(e):t.setAttribute(e,e=="popover"&&n==1?"":n))}}function Pe(t){return function(e){if(this.l){var n=this.l[e.type+t];if(e.t==null)e.t=ue++;else if(e.t<n.u)return;return n(S.event?S.event(e):e)}}}function me(t,e,n,o,i,s,l,r,a,c){var d,u,h,f,m,g,_,p,v,y,w,b,k,T,z,L,M,N=e.type;if(e.constructor!=null)return null;128&n.__u&&(a=!!(32&n.__u),s=[r=e.__e=n.__e]),(d=S.__b)&&d(e);e:if(typeof N=="function")try{if(p=e.props,v="prototype"in N&&N.prototype.render,y=(d=N.contextType)&&o[d.__c],w=d?y?y.props.value:d.__:o,n.__c?_=(u=e.__c=n.__c).__=u.__E:(v?e.__c=u=new N(p,w):(e.__c=u=new ee(p,w),u.constructor=N,u.render=ct),y&&y.sub(u),u.props=p,u.state||(u.state={}),u.context=w,u.__n=o,h=u.__d=!0,u.__h=[],u._sb=[]),v&&u.__s==null&&(u.__s=u.state),v&&N.getDerivedStateFromProps!=null&&(u.__s==u.state&&(u.__s=$({},u.__s)),$(u.__s,N.getDerivedStateFromProps(p,u.__s))),f=u.props,m=u.state,u.__v=e,h)v&&N.getDerivedStateFromProps==null&&u.componentWillMount!=null&&u.componentWillMount(),v&&u.componentDidMount!=null&&u.__h.push(u.componentDidMount);else{if(v&&N.getDerivedStateFromProps==null&&p!==f&&u.componentWillReceiveProps!=null&&u.componentWillReceiveProps(p,w),!u.__e&&u.shouldComponentUpdate!=null&&u.shouldComponentUpdate(p,u.__s,w)===!1||e.__v==n.__v){for(e.__v!=n.__v&&(u.props=p,u.state=u.__s,u.__d=!1),e.__e=n.__e,e.__k=n.__k,e.__k.some(function(P){P&&(P.__=e)}),b=0;b<u._sb.length;b++)u.__h.push(u._sb[b]);u._sb=[],u.__h.length&&l.push(u);break e}u.componentWillUpdate!=null&&u.componentWillUpdate(p,u.__s,w),v&&u.componentDidUpdate!=null&&u.__h.push(function(){u.componentDidUpdate(f,m,g)})}if(u.context=w,u.props=p,u.__P=t,u.__e=!1,k=S.__r,T=0,v){for(u.state=u.__s,u.__d=!1,k&&k(e),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,k&&k(e),d=u.render(u.props,u.state,u.context),u.state=u.__s;while(u.__d&&++T<25);u.state=u.__s,u.getChildContext!=null&&(o=$($({},o),u.getChildContext())),v&&!h&&u.getSnapshotBeforeUpdate!=null&&(g=u.getSnapshotBeforeUpdate(f,m)),L=d,d!=null&&d.type===Q&&d.key==null&&(L=xe(d.props.children)),r=Ae(t,J(L)?L:[L],e,n,o,i,s,l,r,a,c),u.base=e.__e,e.__u&=-161,u.__h.length&&l.push(u),_&&(u.__E=u.__=null)}catch(P){if(e.__v=null,a||s!=null)if(P.then){for(e.__u|=a?160:128;r&&r.nodeType==8&&r.nextSibling;)r=r.nextSibling;s[s.indexOf(r)]=null,e.__e=r}else for(M=s.length;M--;)fe(s[M]);else e.__e=n.__e,e.__k=n.__k;S.__e(P,e,n)}else s==null&&e.__v==n.__v?(e.__k=n.__k,e.__e=n.__e):r=e.__e=at(n.__e,e,n,o,i,s,l,a,c);return(d=S.diffed)&&d(e),128&e.__u?void 0:r}function Ie(t,e,n){for(var o=0;o<n.length;o++)ve(n[o],n[++o],n[++o]);S.__c&&S.__c(e,t),t.some(function(i){try{t=i.__h,i.__h=[],t.some(function(s){s.call(i)})}catch(s){S.__e(s,i.__v)}})}function xe(t){return typeof t!="object"||t==null||t.__b&&t.__b>0?t:J(t)?t.map(xe):$({},t)}function at(t,e,n,o,i,s,l,r,a){var c,d,u,h,f,m,g,_=n.props,p=e.props,v=e.type;if(v=="svg"?i="http://www.w3.org/2000/svg":v=="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==!!v&&(v?f.localName==v:f.nodeType==3)){t=f,s[c]=null;break}}if(t==null){if(v==null)return document.createTextNode(p);t=document.createElementNS(i,v,p.is&&p),r&&(S.__m&&S.__m(e,s),r=!1),s=null}if(v==null)_===p||r&&t.data==p||(t.data=p);else{if(s=s&&K.call(t.childNodes),_=n.props||V,!r&&s!=null)for(_={},c=0;c<t.attributes.length;c++)_[(f=t.attributes[c]).name]=f.value;for(c in _)if(f=_[c],c!="children"){if(c=="dangerouslySetInnerHTML")u=f;else if(!(c in p)){if(c=="value"&&"defaultValue"in p||c=="checked"&&"defaultChecked"in p)continue;ne(t,c,null,f,i)}}for(c in p)f=p[c],c=="children"?h=f:c=="dangerouslySetInnerHTML"?d=f:c=="value"?m=f:c=="checked"?g=f:r&&typeof f!="function"||_[c]===f||ne(t,c,f,_[c],i);if(d)r||u&&(d.__html==u.__html||d.__html==t.innerHTML)||(t.innerHTML=d.__html),e.__k=[];else if(u&&(t.innerHTML=""),Ae(e.type=="template"?t.content:t,J(h)?h:[h],e,n,o,v=="foreignObject"?"http://www.w3.org/1999/xhtml":i,s,l,s?s[0]:n.__k&&j(n,0),r,a),s!=null)for(c=s.length;c--;)fe(s[c]);r||(c="value",v=="progress"&&m==null?t.removeAttribute("value"):m!=null&&(m!==t[c]||v=="progress"&&!m||v=="option"&&m!=_[c])&&ne(t,c,m,_[c],i),c="checked",g!=null&&g!=t[c]&&ne(t,c,g,_[c],i))}return t}function ve(t,e,n){try{if(typeof t=="function"){var o=typeof t.__u=="function";o&&t.__u(),o&&e==null||(t.__u=t(e))}else t.current=e}catch(i){S.__e(i,n)}}function De(t,e,n){var o,i;if(S.unmount&&S.unmount(t),(o=t.ref)&&(o.current&&o.current!=t.__e||ve(o,null,e)),(o=t.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(s){S.__e(s,e)}o.base=o.__P=null}if(o=t.__k)for(i=0;i<o.length;i++)o[i]&&De(o[i],e,n||typeof t.type!="function");n||fe(t.__e),t.__c=t.__=t.__e=void 0}function ct(t,e,n){return this.constructor(t,n)}function ut(t,e,n){var o,i,s,l;e==document&&(e=document.documentElement),S.__&&S.__(t,e),i=(o=!1)?null:e.__k,s=[],l=[],me(e,t=e.__k=it(Q,null,[t]),i||V,V,e.namespaceURI,i?null:e.firstChild?K.call(e.childNodes):null,s,i?i.__e:e.firstChild,o,l),Ie(s,t,l)}function dt(t){function e(n){var o,i;return this.getChildContext||(o=new Set,(i={})[e.__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,_e(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 e.__c="__cC"+Se++,e.__=t,e.Provider=e.__l=(e.Consumer=function(n,o){return n.children(o)}).contextType=e,e}K=ze.slice,S={__e:function(t,e,n,o){for(var i,s,l;e=e.__;)if((i=e.__c)&&!i.__)try{if((s=i.constructor)&&s.getDerivedStateFromError!=null&&(i.setState(s.getDerivedStateFromError(t)),l=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(t,o||{}),l=i.__d),l)return i.__E=i}catch(r){t=r}throw t}},ye=0,ee.prototype.setState=function(t,e){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=$({},this.state),typeof t=="function"&&(t=t($({},n),this.props)),t&&$(n,t),t!=null&&this.__v&&(e&&this._sb.push(e),_e(this))},ee.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),_e(this))},ee.prototype.render=Q,W=[],ke=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,Te=function(t,e){return t.__v.__b-e.__v.__b},te.__r=0,Le=/(PointerCapture)$|Capture$/i,ue=0,de=Pe(!1),he=Pe(!0),Se=0;var ht=0;function C(t,e,n,o,i,s){e||(e={});var l,r,a=e;if("ref"in a)for(r in a={},e)r=="ref"?l=e[r]:a[r]=e[r];var c={type:t,props:a,key:n,ref:l,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--ht,__i:-1,__u:0,__source:i,__self:s};if(typeof t=="function"&&(l=t.defaultProps))for(r in l)a[r]===void 0&&(a[r]=l[r]);return S.vnode&&S.vnode(c),c}var G,A,ge,Fe,Y=0,Oe=[],E=S,Re=E.__b,$e=E.__r,Ue=E.diffed,We=E.__c,je=E.unmount,Ge=E.__;function oe(t,e){E.__h&&E.__h(A,t,Y||e),Y=0;var n=A.__H||(A.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function H(t){return Y=1,ft(Be,t)}function ft(t,e,n){var o=oe(G++,2);if(o.t=t,!o.__c&&(o.__=[Be(void 0,e),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(t,e){var n=oe(G++,3);!E.__s&&qe(n.__H,e)&&(n.__=t,n.u=e,A.__H.__h.push(n))}function D(t){return Y=5,q(function(){return{current:t}},[])}function q(t,e){var n=oe(G++,7);return qe(n.__H,e)&&(n.__=t(),n.__H=e,n.__h=t),n.__}function _t(t,e){return Y=8,q(function(){return t},e)}function mt(t){var e=A.context[t.__c],n=oe(G++,9);return n.c=t,e?(n.__==null&&(n.__=!0,e.sub(A)),e.props.value):t.__}function vt(){for(var t;t=Oe.shift();)if(t.__P&&t.__H)try{t.__H.__h.forEach(re),t.__H.__h.forEach(pe),t.__H.__h=[]}catch(e){t.__H.__h=[],E.__e(e,t.__v)}}E.__b=function(t){A=null,Re&&Re(t)},E.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),Ge&&Ge(t,e)},E.__r=function(t){$e&&$e(t),G=0;var e=(A=t.__c).__H;e&&(ge===A?(e.__h=[],A.__h=[],e.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(e.__h.forEach(re),e.__h.forEach(pe),e.__h=[],G=0)),ge=A},E.diffed=function(t){Ue&&Ue(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&(Oe.push(e)!==1&&Fe===E.requestAnimationFrame||((Fe=E.requestAnimationFrame)||gt)(vt)),e.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),ge=A=null},E.__c=function(t,e){e.some(function(n){try{n.__h.forEach(re),n.__h=n.__h.filter(function(o){return!o.__||pe(o)})}catch(o){e.some(function(i){i.__h&&(i.__h=[])}),e=[],E.__e(o,n.__v)}}),We&&We(t,e)},E.unmount=function(t){je&&je(t);var e,n=t.__c;n&&n.__H&&(n.__H.__.forEach(function(o){try{re(o)}catch(i){e=i}}),n.__H=void 0,e&&E.__e(e,n.__v))};var He=typeof requestAnimationFrame=="function";function gt(t){var e,n=function(){clearTimeout(o),He&&cancelAnimationFrame(e),setTimeout(t)},o=setTimeout(n,100);He&&(e=requestAnimationFrame(n))}function re(t){var e=A,n=t.__c;typeof n=="function"&&(t.__c=void 0,n()),A=e}function pe(t){var e=A;t.__c=t.__(),A=e}function qe(t,e){return!t||t.length!==e.length||e.some(function(n,o){return n!==t[o]})}function Be(t,e){return typeof e=="function"?e(t):e}const pt=t=>({saveGameData(e){try{localStorage.setItem(t,JSON.stringify(e))}catch(n){console.error("Failed to save maze game data:",n)}},loadGameData(){try{const e=localStorage.getItem(t);return e?JSON.parse(e):null}catch(e){return console.error("Failed to load maze game data:",e),null}},resetGameData(){try{localStorage.removeItem(t)}catch(e){console.error("Failed to reset maze game data:",e)}}}),Ve=dt(void 0),Ye={currentLevel:1,highestUnlockedLevel:1,currentTier:1,highestUnlockedTier:1,levelScores:{},totalScore:0},Xe={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:{}},Ct=({children:t,config:e})=>{const n=pt(e.lcPrefix+"progress"),o=n.loadGameData(),[i,s]=H(()=>o||{...Ye});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]=H({...Xe}),a=D(l);I(()=>{a.current=l},[l]);const c=q(()=>[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({...Ye}),r({...Xe})};return C(Ve.Provider,{value:{gameProgress:i,setGameProgress:s,gamePlayState:l,setGamePlayState:r,gamePlayStateRef:a,currentScore:c,config:e,resetGame:d},children:t})},B=()=>{const t=mt(Ve);if(!t)throw new Error("useGameContext must be used within a GameProvider");return t},X=t=>q(()=>{const e=t.map(r=>r.length),n=e.reduce((r,a)=>r+a,0),o=t.length,i=r=>{if(r<1||r>n)return 0;let a=0;for(let c=0;c<e.length;c++)if(a+=e[c],r<=a)return c+1;return 0},s=r=>r<1||r>o?0:e.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+e[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 t[a-1][d]},getTierConfig:r=>r<1||r>o?null:t[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},[t]),wt=({onTierChange:t,disabled:e})=>{const{gameProgress:n,config:o}=B(),{i18n:i,levelConfig:s}=o,{currentTier:l,highestUnlockedTier:r}=n,c=X(s).getTotalTiers();return C("div",{className:"tier-selector",children:C("select",{value:l,onChange:d=>{d.target&&d.target.value&&t(Number(d.target.value))},disabled:e,className:"tier-dropdown",children:Array.from({length:c},(d,u)=>u+1).map(d=>C("option",{value:d,disabled:d>r,children:i.tier+" "+d},`tier-${d}`))})})},yt=({onLevelChange:t,disabled:e})=>{const{gameProgress:n,config:o}=B(),{i18n:i,levelConfig:s}=o,{currentTier:l,levelScores:r,currentLevel:a,highestUnlockedLevel:c}=n,d=X(s),u=q(()=>{const[h,f]=d.getTierLevelsRange(l);return Array.from({length:f-h+1},(m,g)=>{const _=h+g,p=r[_]||0;return{level:_,score:p}})},[l,r]);return C("div",{className:"level-selector",children:C("select",{value:a,onChange:h=>{h.target&&h.target.value&&t(Number(h.target.value))},disabled:e,className:"level-dropdown",children:u.map(({level:h,score:f})=>C("option",{value:h,disabled:h>c,children:`${i.level} ${h} ${"★".repeat(f)}`},`level-${h}`))})})},ie=({isOpen:t,title:e,className:n="",message:o,children:i,noConfirm:s=!1,noCancel:l=!1,confirmText:r="OK",cancelText:a="Cancel",onConfirm:c,onCancel:d})=>{const u=D(null);return I(()=>{const h=f=>{f.key==="Escape"&&d?.()};return t&&document.addEventListener("keydown",h),()=>{document.removeEventListener("keydown",h)}},[t,d]),C("div",{className:`maze-dialog-overlay ${t?"maze-dialog-visible":""}`,children:C("div",{className:"maze-dialog "+n,ref:u,children:[C("div",{className:"maze-dialog-title",children:e}),C("div",{className:"maze-dialog-content",children:i||C("div",{className:"maze-dialog-message",children:o})}),(!l||!s)&&C("div",{className:"maze-dialog-buttons",children:[!l&&C("button",{type:"button",className:"maze-dialog-cancel",onClick:d,children:a}),!s&&C("button",{type:"button",className:"maze-dialog-confirm",onClick:c,children:r})]})]})})},R={container:null,attachTo(t){return this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.container=document.createElement("div"),this.container.className="toast-container position-top",t.appendChild(this.container),this.container},currentToast:null,currentTimer:null,show(t,e="info",n=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 o=document.createElement("div");o.className=`toast-message type-${e} toast-visible`,o.textContent=t,this.container.appendChild(o),this.currentToast=o,this.currentTimer=setTimeout(()=>{o.classList.remove("toast-visible"),setTimeout(()=>{this.container&&this.container.contains(o)&&(this.container.removeChild(o),this.currentToast===o&&(this.currentToast=null))},300),this.currentTimer=null},n)},clearAll(){if(this.container)for(;this.container.firstChild;)this.container.removeChild(this.container.firstChild)}},bt=()=>{const{gameProgress:t,setGameProgress:e,gamePlayState:n,setGamePlayState:o,gamePlayStateRef:i,resetGame:s,config:l}=B(),{i18n:r,levelConfig:a}=l,c=X(a),{levelTransitioning:d,showClue:u}=n,{highestUnlockedLevel:h,totalScore:f}=t,m=c.getTotalLevels(),[g,_]=H(!1),[p,v]=H(!1),[y,w]=H(!1),b=O=>{const U=c.getFirstLevelOfTier(O);c.isLevelUnlocked(U,h)&&(e(ce=>({...ce,currentTier:O})),k(U))},k=O=>{c.isLevelUnlocked(O,h)&&(e(U=>({...U,currentLevel:O})),R.show(r.levelGoToast.replace("%LEVEL%",O.toString()),"success"))},T=()=>{_(!0)},z=()=>{_(!1)},L=()=>{w(!0)},M=()=>{w(!1)},N=()=>{R.show(u?r.cluePathDisabled:r.cluePathEnabled),o(()=>({...i.current,showClue:!i.current.showClue})),w(!1)},P=()=>{v(!0)},x=()=>{s(),v(!1),R.show(r.resetDoneToast)},ot=()=>{v(!1)};return C("div",{class:"game-panel-container",children:[C("div",{className:"game-controls",children:[C("div",{className:"selectors-container",children:[C(wt,{onTierChange:b,disabled:d}),C(yt,{onLevelChange:k,disabled:d})]}),C("button",{className:`settings-clue-button ${u?"clue-on":"clue-off"}`,disabled:u,title:"Toggle Clue",onClick:L,children:u?r.clueOn:r.clueOff})]}),C("div",{className:"game-settings",children:C("span",{className:"game-settings-icon",onClick:T,children:"★ "+f})}),C(ie,{isOpen:g,title:r.settings,noConfirm:!0,cancelText:r.close,onCancel:z,children:[C("div",{className:"settings-stats",children:[C("div",{children:r.levelComplete+`: ${h}/${m}`}),C("div",{children:r.starsCollected+": "+f}),C("div",{children:r.avgStarPerLevel+": "+(f/h).toFixed(2)})]}),C("div",{className:"settings-item-box",children:[C("button",{className:"settings-reset-button",title:"Reset Game",onClick:P,children:r.reset}),C("div",{className:"settings-item-tip",children:r.resetTip})]})]}),C(ie,{isOpen:p,title:r.confirmReset,message:r.confirmResetMessage,confirmText:r.reset,cancelText:r.cancel,onConfirm:x,onCancel:ot}),C(ie,{isOpen:y,title:r.confirmClue,message:r.confirmClueMessage,confirmText:r.confirm,cancelText:r.cancel,onConfirm:N,onCancel:M})]})};function Ce(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function kt(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function we(t,e,n){return e&&kt(t.prototype,e),t}function Ke(t){return+t.replace(/px/,"")}function Tt(t){var e=window.devicePixelRatio,n=getComputedStyle(t),o=Ke(n.getPropertyValue("width")),i=Ke(n.getPropertyValue("height"));t.setAttribute("width",(o*e).toString()),t.setAttribute("height",(i*e).toString())}function F(t,e){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,o=Math.random()*(e-t)+t;return Math.floor(o*Math.pow(10,n))/Math.pow(10,n)}function Je(t){return t[F(0,t.length)]}var Lt=.00125,St=5e-4,zt=9e-4,Nt=1e-5,At=6,Et=80,Mt=.9,Pt=1.7,It=.2,xt=.6,Dt=.03,Ft=.07,Ot=15,Rt=82,$t=100,Ut=250,Wt=40,jt=["#fcf403","#62fc03","#f4fc03","#03e7fc","#03fca5","#a503fc","#fc03ad","#fc03c2"];function Ze(t){var e=1920;return Math.log(t)/Math.log(e)}var Qe=function(){function t(e){Ce(this,t);var n=e.initialPosition,o=e.direction,i=e.confettiRadius,s=e.confettiColors,l=e.emojis,r=e.emojiSize,a=e.canvasWidth,c=F(Mt,Pt,3),d=c*Ze(a);this.confettiSpeed={x:d,y:d},this.finalConfettiSpeedX=F(It,xt,3),this.rotationSpeed=l.length?.01:F(Dt,Ft,3)*Ze(a),this.dragForceCoefficient=F(St,zt,6),this.radius={x:i,y:i},this.initialRadius=i,this.rotationAngle=o==="left"?F(0,.2,3):F(-.2,0,3),this.emojiSize=r,this.emojiRotationAngle=F(0,2*Math.PI),this.radiusYUpdateDirection="down";var u=o==="left"?F(Rt,Ot)*Math.PI/180:F(-15,-82)*Math.PI/180;this.absCos=Math.abs(Math.cos(u)),this.absSin=Math.abs(Math.sin(u));var h=F(-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:Je(s),this.emoji=l.length?Je(l):null,this.createdAt=new Date().getTime(),this.direction=o}return we(t,[{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+Lt*Math.pow(u,2)/2,this.rotationSpeed-=this.emoji?1e-4:Nt*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+$t}}]),t}();function Gt(){var t=document.createElement("canvas");return t.style.position="fixed",t.style.width="100%",t.style.height="100%",t.style.top="0",t.style.left="0",t.style.zIndex="1000",t.style.pointerEvents="none",document.body.appendChild(t),t}function Ht(t){var e=t.confettiRadius,n=e===void 0?At:e,o=t.confettiNumber,i=o===void 0?t.confettiesNumber||(t.emojis?Wt:Ut):o,s=t.confettiColors,l=s===void 0?jt:s,r=t.emojis,a=r===void 0?t.emojies||[]:r,c=t.emojiSize,d=c===void 0?Et:c;return t.emojies&&console.error("emojies argument is deprecated, please use emojis instead"),t.confettiesNumber&&console.error("confettiesNumber argument is deprecated, please use confettiNumber instead"),{confettiRadius:n,confettiNumber:i,confettiColors:l,emojis:a,emojiSize:d}}var qt=function(){function t(e){var n=this;Ce(this,t),this.canvasContext=e,this.shapes=[],this.promise=new Promise(function(o){return n.resolvePromise=o})}return we(t,[{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})}}]),t}(),Bt=function(){function t(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Ce(this,t),this.activeConfettiBatches=[],this.canvas=e.canvas||Gt(),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 we(t,[{key:"loop",value:function(){this.requestAnimationFrameRequested=!1,Tt(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=Ht(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},m={x:d,y:h},g=new qt(this.canvasContext),_=0;_<s/2;_++){var p=new Qe({initialPosition:f,direction:"right",confettiRadius:i,confettiColors:l,confettiNumber:s,emojis:r,emojiSize:a,canvasWidth:d}),v=new Qe({initialPosition:m,direction:"left",confettiRadius:i,confettiColors:l,confettiNumber:s,emojis:r,emojiSize:a,canvasWidth:d});g.addShapes(p,v)}return this.activeConfettiBatches.push(g),this.queueAnimationFrameIfNeeded(),g.getBatchCompletePromise()}},{key:"clearCanvas",value:function(){this.activeConfettiBatches=[]}},{key:"destroyCanvas",value:function(){this.canvas.remove()}}]),t}();const Vt=new Bt,Yt=({onRetry:t})=>{const{config:e,currentScore:n,gamePlayState:o,setGamePlayState:i,gameProgress:s,setGameProgress:l}=B(),{i18n:r,levelConfig:a}=e,[c,d,u]=n,{foodCollected:h,totalFoodCount:f,playerAtExit:m,levelTransitioning:g}=o,{currentLevel:_}=s,[p,v]=H(!1);I(()=>{m&&g&&(Vt.addConfetti(),R.show(r.levelCompleteToast,"success"),v(!0))},[m,g]);const y=X(a),w=y.getTotalLevels(),b=q(()=>_>=w,[_,w]),k=()=>{v(!1),R.show(r.levelRestartToast,"info"),t?.()},T=()=>{v(!1),i(L=>({...L,isGameActive:!0,levelTransitioning:!1}))},z=()=>{v(!1);const L=y.getNextLevelInfo(_);if(!L)return;const{nextLevel:M,nextTier:N,isTierChange:P}=L;P&&R.show(r.tierUnlockedToast.replace("%TIER%",N.toString()),"success"),l(x=>({...x,currentLevel:M,currentTier:N,highestUnlockedLevel:Math.max(x.highestUnlockedLevel,M),highestUnlockedTier:Math.max(x.highestUnlockedTier,N),levelScores:{...x.levelScores,[x.currentLevel]:Math.max(Object.values(n).filter(Boolean).length,x.levelScores[x.currentLevel]||0)}}))};return C(ie,{className:"level-complete-dialog",isOpen:p,title:r.congratulations,cancelText:r.retry,onCancel:k,noConfirm:!!d,confirmText:r.continue,onConfirm:T,children:[C("div",{className:"maze-summary-message",children:[!!c&&C("div",{children:"★ - "+r.findYourExit}),C("div",{children:u?"★ - "+r.withoutClue:"☆ - "+r.withClue}),C("div",{children:(d?"★ - "+r.collectAllStars:"☆ - "+r.notCollectAllStars)+` (${h}/${f})`})]}),b&&C("div",{className:"all-levels-completed",children:r.allLevelsCompleted}),C("div",{className:"go-next-level",children:b?"OK":C("button",{type:"button",onClick:z,children:r.nextLevel})}),!d&&C("div",{className:"not-all-stars-collected",children:r.continueMessage})]})},Xt=(t,e)=>{const n=D({canvasWidth:0,canvasHeight:0});return I(()=>{const o=()=>{const s=t.current;if(!s)return;const l=s.parentElement;if(!l)return;const r=l.clientWidth,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},e?.()};o();let i=null;return window.ResizeObserver&&(i=new ResizeObserver(o),i.observe(t.current.parentElement)),window.addEventListener("resize",o),()=>{window.removeEventListener("resize",o),i?.disconnect()}},[t,e]),n},Kt=t=>{const{config:e,gamePlayState:{maze:n}}=B(),o=D({cellWidth:0,cellHeight:0});return I(()=>{const i=e.renderConfig.padding,s=()=>{const r=t.current;if(!r||!n)return;const{rows:a,cols:c}=n;if(a<=0||c<=0)return;const d=(r.width-i*2)/c,u=(r.height-i*2)/a;o.current={cellWidth:d,cellHeight:u}};s();let l=null;return t.current&&window.ResizeObserver&&(l=new ResizeObserver(s),l.observe(t.current)),()=>{t.current&&l?.disconnect()}},[t,n]),o},se={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]},Jt=({containerRef:t,gamePlayStateRef:e,setGamePlayState:n,moveSpeed:o,playerRadius:i,onFoodCollected:s})=>{const l=D(!1),r=D(new Set),a=(m,g)=>{const _=e.current;if(!_.maze)return{canMove:!1,newCell:null};const[p,v]=se[m];if(et(g,p,v,i,o,_.maze))return{canMove:!1,newCell:null};const{row:w,col:b}=g,k=w+p*o,T=b+v*o,z=Math.floor(w),L=Math.floor(b),M=Math.floor(k),N=Math.floor(T);return M!==z||N!==L?_.maze.isValid(M,N)?{canMove:!0,newCell:{row:M,col:N}}:{canMove:!1,newCell:null}:{canMove:!0,newCell:null}},c=()=>{const m=e.current,{row:g,col:_}=m.playerCell,p=i*2,v=m.foodCells.findIndex(b=>Math.sqrt(Math.pow(g-b.row,2)+Math.pow(_-b.col,2))<p);v!==-1&&s&&(s(),e.current={...e.current,foodCollected:e.current.foodCollected+1,foodCells:e.current.foodCells.filter((b,k)=>k!==v)});const w=Qt(m.playerCell,m.exitCell,m.maze,i);w&&!e.current.playerAtExit?(e.current={...e.current,playerAtExit:!0,isGameActive:!1,levelTransitioning:!0},requestIdleCallback(()=>{n(()=>({...e.current}))},{timeout:10})):!w&&e.current.playerAtExit&&(e.current={...e.current,playerAtExit:!1,isGameActive:!0,levelTransitioning:!1})},d=m=>{const g=e.current,_=Math.round(m.row),p=Math.round(m.col),v=g.playerPath[g.playerPath.length-1],y=v.row===_&&v.col===p,w=Math.abs(v.row-_),b=Math.abs(v.col-p);if((w===1&&b===0||w===0&&b===1)&&!y){const T=`${v.row},${v.col}-${_},${p}`;e.current={...e.current,playerPath:[...e.current.playerPath,{row:_,col:p}],visitCounts:{...e.current.visitCounts,[T]:(e.current.visitCounts[T]||0)+1}}}},u=()=>{if(l.current||r.current.size===0)return;const m=e.current;!m.playerCell||!Array.from(r.current).some(_=>{const{canMove:p}=a(_,m.playerCell);return p})||(l.current=!0)};I(()=>{const m=y=>{(y.key==="ArrowUp"||y.key==="ArrowDown"||y.key==="ArrowLeft"||y.key==="ArrowRight"||y.key===" ")&&y.preventDefault()},g=y=>{const w=y.key;w in se&&(y.preventDefault(),e.current.isGameActive&&(r.current.has(w)||(r.current.add(w),l.current||u())))},_=y=>{const w=y.key;w in se&&(y.preventDefault(),r.current.delete(w),r.current.size===0&&f())},p=y=>{y.preventDefault();const w=e.current;if(!w.isGameActive||!w.maze||l.current)return;const b=y.touches[0],k=document.elementFromPoint(b.clientX,b.clientY);let T=null;k&&(k.classList.contains("maze-up")?T="ArrowUp":k.classList.contains("maze-down")?T="ArrowDown":k.classList.contains("maze-left")?T="ArrowLeft":k.classList.contains("maze-right")&&(T="ArrowRight")),T&&(r.current.clear(),r.current.add(T),u())},v=()=>{f()};return window.addEventListener("keydown",m,{capture:!0}),window.addEventListener("keydown",g),window.addEventListener("keyup",_),t.current?.addEventListener("touchstart",p,{passive:!1}),t.current?.addEventListener("touchend",v),()=>{window.removeEventListener("keydown",m,{capture:!0}),window.removeEventListener("keydown",g),window.removeEventListener("keyup",_),t.current?.removeEventListener("touchstart",p),t.current?.removeEventListener("touchend",v)}},[]);const h=_t(()=>{if(!l.current||r.current.size===0)return e.current.playerCell;const m=e.current.playerCell;let g=0,_=0,p=0;for(const O of r.current){const{canMove:U}=a(O,m);if(U){const[ce,pn]=se[O];g+=ce,_+=pn,p++}}if(p===0)return e.current.playerCell;const v=Math.sqrt(g*g+_*_),y=v>0?g/v:0,w=v>0?_/v:0,b=Number((m.row+y*o).toFixed(2)),k=Number((m.col+w*o).toFixed(2)),T=b-m.row,z=k-m.col,L=Math.sqrt(T*T+z*z);if(L>0){const O=T/L,U=z/L;if(et(m,O,U,i,L,e.current.maze))return e.current.playerCell}e.current.playerCell={row:b,col:k},c();const M=Math.round(m.row),N=Math.round(m.col),P=Math.round(b),x=Math.round(k);return(P!==M||x!==N)&&d({row:P,col:x}),e.current.playerCell},[o]),f=()=>{l.current=!1,r.current.clear()};return{updatePlayerPos:h,resetMovingState:f}};function et(t,e,n,o,i,s){const l=t.row+e*i,r=t.col+n*i,a={row:l,col:r},c=[],d=Math.floor(t.row),u=Math.floor(t.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,m]of h){const g=d+f,_=u+m;s.isValid(g,_)&&c.push({row:g,col:_})}for(const f of c){const m=Zt(f.row,f.col,s);for(const g of m)if(tt(a,g)<o)return!0}return!1}function Zt(t,e,n){const o=[],i=n.grid[t][e];return i.walls.top&&o.push({start:{row:t-.5,col:e-.5},end:{row:t-.5,col:e+.5}}),i.walls.right&&o.push({start:{row:t-.5,col:e+.5},end:{row:t+.5,col:e+.5}}),i.walls.bottom&&o.push({start:{row:t+.5,col:e-.5},end:{row:t+.5,col:e+.5}}),i.walls.left&&o.push({start:{row:t-.5,col:e-.5},end:{row:t+.5,col:e-.5}}),o}function tt(t,e){const{start:n,end:o}=e,i=o.col-n.col,s=o.row-n.row,l=t.col-n.col,r=t.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=t.col-d,f=t.row-u;return Math.sqrt(h*h+f*f)}function Qt(t,e,n,o){if(Math.sqrt(Math.pow(t.row-e.row,2)+Math.pow(t.col-e.col,2))>1.5||!n.isValid(e.row,e.col))return!1;if(n.grid[e.row][e.col].walls.bottom){const l={start:{row:e.row+.5,col:e.col-.5},end:{row:e.row+.5,col:e.col+.5}},r=tt(t,l),a=.05;if(console.log("Distance between player point to exit wall: ",r),console.log("collision condition: playerRadius + COLLISION_TOLERANCE: ",o+a),r<=o+a)return console.log("collision true: ",o+a),!0}return!1}function en(t,e,n,o,i){if(!t||!e.maze)return;const{canvasWidth:s,canvasHeight:l}=n,{cellWidth:r,cellHeight:a}=o,{maze:c,playerCell:d,exitCell:u,foodCells:h,showClue:f,playerPath:m,visitCounts:g}=e,{padding:_,wallWidth:p,wallColor:v,playerColor:y,playerRadius:w,foodColor:b,backgroundColor:k,clueColor:T,exitColor:z,exitWallWidth:L,exitDashArray:M}=i;t.clearRect(0,0,s,l),t.save(),t.fillStyle=k,t.fillRect(0,0,s,l),t.restore(),f&&ln({ctx:t,playerPath:m,visitCounts:g,cellWidth:r,cellHeight:a,padding:_,clueColor:T}),tn({ctx:t,maze:c,cellWidth:r,cellHeight:a,padding:_,wallColor:v,wallWidth:p}),on({ctx:t,maze:c,exitCell:u,cellWidth:r,cellHeight:a,padding:_,exitColor:z,exitWallWidth:L,exitDashArray:M}),rn({ctx:t,foodCells:h,cellWidth:r,cellHeight:a,padding:_,foodColor:b}),nn({ctx:t,playerCell:d,playerRadius:w,cellWidth:r,cellHeight:a,padding:_,playerColor:y})}function tn({ctx:t,maze:e,cellWidth:n,cellHeight:o,padding:i,wallColor:s,wallWidth:l}){t.save(),t.strokeStyle=s,t.lineWidth=l,t.lineCap="round",t.beginPath(),an(e,n,o,i).forEach(a=>{t.moveTo(a.x1,a.y1),t.lineTo(a.x2,a.y2)}),t.stroke(),t.restore()}function nn({ctx:t,playerCell:e,playerRadius:n,cellWidth:o,cellHeight:i,padding:s,playerColor:l}){const{x:r,y:a}=le(e.row,e.col,o,i,s),c=Math.min(o,i)*Math.min(n,.5);t.save(),t.fillStyle=l,t.beginPath(),t.arc(r,a,c,0,Math.PI*2),t.fill(),t.restore()}function on({ctx:t,maze:e,exitCell:n,cellWidth:o,cellHeight:i,padding:s,exitColor:l,exitWallWidth:r,exitDashArray:a=[8,12]}){const{row:c,col:d}=n;if(!e.isValid(c,d))return;const u=e.grid[c][d],h=s+d*o,f=s+c*i;t.save(),t.globalCompositeOperation="destination-out",t.lineWidth=r,t.lineCap="round",t.beginPath(),u.walls.bottom&&(t.moveTo(h,f+i),t.lineTo(h+o,f+i)),t.stroke(),t.globalCompositeOperation="source-over",t.strokeStyle=l,t.lineWidth=r,t.setLineDash(a),t.beginPath(),u.walls.bottom&&(t.moveTo(h,f+i),t.lineTo(h+o,f+i)),t.stroke(),t.restore()}function rn({ctx:t,foodCells:e,cellWidth:n,cellHeight:o,padding:i,foodColor:s}){t.fillStyle=s;const l=Math.min(n,o)*.25;e.forEach(r=>{const{x:a,y:c}=le(r.row,r.col,n,o,i);sn(t,a,c,l*1.2,5,l*.6)})}function sn(t,e,n,o,i,s){t.save(),t.beginPath();for(let l=0;l<i*2;l++){const r=l%2===0?o:s,a=Math.PI*l/i;t.lineTo(e+r*Math.sin(a),n+r*Math.cos(a))}t.closePath(),t.fill(),t.restore()}function ln({ctx:t,playerPath:e,visitCounts:n,cellWidth:o,cellHeight:i,padding:s,clueColor:l}){if(!(!e||e.length<2||!n)){t.save();for(let r=1;r<e.length;r++){const a=e[r-1],c=e[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),m=Math.max(3,o*.1)+h*.5;try{t.strokeStyle=l.replace(")",`, ${f})`).replace("rgb(","rgba(")}catch{t.strokeStyle=`rgba(255, 0, 0, ${f})`}t.lineWidth=m,t.lineCap="round",t.lineJoin="round";const{x:g,y:_}=le(a.row,a.col,o,i,s),{x:p,y:v}=le(c.row,c.col,o,i,s);t.beginPath(),t.moveTo(g,_),t.lineTo(p,v),t.stroke()}t.restore()}}function an(t,e,n,o){const i=[];for(let s=0;s<t.rows;s++)for(let l=0;l<t.cols;l++){const r=t.grid[s][l],a=o+l*e,c=o+s*n;r.walls.top&&i.push({x1:a,y1:c,x2:a+e,y2:c}),r.walls.right&&i.push({x1:a+e,y1:c,x2:a+e,y2:c+n}),r.walls.bottom&&i.push({x1:a,y1:c+n,x2:a+e,y2:c+n}),r.walls.left&&i.push({x1:a,y1:c,x2:a,y2:c+n})}return i}function le(t,e,n,o,i){return{x:i+e*n+n/2,y:i+t*o+o/2}}function cn(t){return function(){let e=t+=1831565813;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}}class un{constructor(e,n){this.row=e,this.col=n}visited=!1;walls={top:!0,right:!0,bottom:!0,left:!0}}class dn{rows;cols;grid;seed;random;constructor(e,n,o,i,s={row:0,col:0}){this.rows=e,this.cols=n,this.seed=i??Math.floor(Math.random()*1e6),this.random=cn(this.seed),this.grid=this.initializeGrid(),this.generate(o,s)}initializeGrid(){const e=[];for(let n=0;n<this.rows;n++){e[n]=[];for(let o=0;o<this.cols;o++)e[n][o]=new un(n,o)}return e}isValid(e,n){return e>=0&&e<this.rows&&n>=0&&n<this.cols}getNeighbors(e,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=e+s.r,r=n+s.c;this.isValid(l,r)&&o.push({row:l,col:r})}return o}getUnvisitedNeighbors(e,n){return this.getNeighbors(e,n).filter(o=>!this.grid[o.row][o.col].visited)}getVisitedNeighbors(e,n){return this.getNeighbors(e,n).filter(o=>this.grid[o.row][o.col].visited)}removeWall(e,n,o,i){const s=this.grid[e][n],l=this.grid[o][i];e===o+1?(s.walls.top=!1,l.walls.bottom=!1):e===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(e,n={row:0,col:0}){switch(e){case"backtracking":this.generateWithBacktracking();break;case"prims":this.generateWithPrims();break;default:throw new Error(`Unknown maze generation method: ${e}`)}this.addOpenings(n)}generateWithBacktracking(){const e=[],n=this.randomNumber(this.rows),o=this.randomNumber(this.cols);let i={row:n,col:o};for(this.grid[n][o].visited=!0,e.push(i);e.length>0;){i=e[e.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,e.push(a)}else e.pop()}}generateWithPrims(){const e=[],n=(s,l)=>{const r=this.getNeighbors(s,l);for(const a of r)!this.grid[a.row][a.col].visited&&!e.some(c=>c.row===a.row&&c.col===a.col)&&e.push(a)},o=this.randomNumber(this.rows),i=this.randomNumber(this.cols);for(this.grid[o][i].visited=!0,n(o,i);e.length>0;){const s=this.randomNumber(e.length),l=e[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)}e.splice(s,1)}}addOpenings(e){this.grid[e.row][e.col].walls.top=!1}randomNumber(e){return Math.floor(this.random()*e)}randomPick(e){return e[Math.floor(this.random()*e.length)]}}const hn=(t,e,n)=>{if(!t.isValid(e,n))return!1;const o=t.grid[e][n];return!o.walls.top||!o.walls.right||!o.walls.bottom||!o.walls.left},fn=t=>t===1?2:t>=2&&t<=5?3:t>=6&&t<=11?4:t>=12&&t<=15?5:6,_n=(t,e)=>{if(!e)return console.error(`Cannot find Level ${t}'s config.`),null;const{size:n,seed:o,method:i,entry:s,exit:l}=e,r=n,a=n,c=s||{row:0,col:0},d=l||{row:r-1,col:a-1},u=new dn(r,a,i,o,s),h=fn(t),f=[];for(let m=0;m<h;m++){let g;do g={row:Math.floor(u.random()*r),col:Math.floor(u.random()*a)};while(g.row===c.row&&g.col===c.col||g.row===d.row&&g.col===d.col||!hn(u,g.row,g.col)||f.some(_=>_.row===g.row&&_.col===g.col));f.push(g)}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}}};function mn(){const{setGamePlayState:t,gamePlayStateRef:e,gameProgress:n,config:o}=B(),i=D(null),s=D(null),l=D(null),{i18n:r,levelConfig:a,renderConfig:c}=o,d=X(a),u=D(d.getLevelConfig(n.currentLevel));I(()=>{i.current&&R.attachTo(i.current)},[]);const h=D(),f=Xt(l,()=>{h.current?.()}),m=Kt(l);I(()=>{u.current=d.getLevelConfig(n.currentLevel)},[n.currentLevel]);const g=()=>{const y=_n(n.currentLevel,u.current);y&&t(w=>({...w,...y}))};I(()=>{g()},[n.currentLevel]);const _=()=>{g()},{updatePlayerPos:p,resetMovingState:v}=Jt({containerRef:s,gamePlayStateRef:e,setGamePlayState:t,playerRadius:c.playerRadius,moveSpeed:c.gridMoveSpeed,onFoodCollected:()=>{const y=e.current.totalFoodCount-e.current.foodCollected-1;y>0?R.show(r.foodCollectedToast.replace("%NUM%",y.toString()),"success",3e3):R.show(r.allFoodCollectedToast,"success")}});return I(()=>{v()},[n.currentLevel,v]),I(()=>{let y,w=!document.hidden;const b=()=>{const z=l.current?.getContext("2d"),L=e.current;if(!(w&&L?.isGameActive&&z&&L?.maze)){y=requestAnimationFrame(b);return}p(),k(),y=requestAnimationFrame(b)},k=()=>{const z=l.current?.getContext("2d"),L=e.current;if(z&&L?.maze){const M=u.current?.wallWidth||c?.wallWidth,N=u.current?.exitColor||c?.exitColor,P=u.current?.exitWallWidth||c?.exitWallWidth,x=u.current?.exitDashArray||c?.exitDashArray;en(z,L,f.current,m.current,{...c,wallWidth:M,exitColor:N,exitWallWidth:P,exitDashArray:x})}};h.current=k;const T=z=>{const L=w;w=!document.hidden&&document.visibilityState==="visible"&&(!z||z.type!=="blur"),!L&&w?e.current?.levelTransitioning===!1&&t({...e.current,isGameActive:!0}):L&&!w&&t({...e.current,isGameActive:!1})};return document.addEventListener("visibilitychange",T),window.addEventListener("blur",T),window.addEventListener("focus",T),y=requestAnimationFrame(b),()=>{cancelAnimationFrame(y),document.removeEventListener("visibilitychange",T),window.removeEventListener("blur",T),window.removeEventListener("focus",T)}},[]),I(()=>{R.show(r.useArrowKeyTips,"info",3e3)},[]),C("div",{className:"maze-game-container",ref:i,children:[C(bt,{}),C(Yt,{onRetry:_}),C("div",{className:"maze-canvas-container",ref:s,children:[C("canvas",{ref:l,className:"maze-game-canvas"}),C("div",{className:"maze-touch-area maze-up"}),C("div",{className:"maze-touch-area maze-down"}),C("div",{className:"maze-touch-area maze-left"}),C("div",{className:"maze-touch-area maze-right"})]})]})}const nt=[[{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"}]],ae={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 ➤",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!",continueMessage:"You haven't collected all stars. You can click 'Continue' button to collect all stars.",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:{gridMoveSpeed:.03,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]},levelConfig:nt};function vn({config:t={}}){const e={...ae.i18n,...t.i18n||{}},n={...ae.renderConfig,...t.renderConfig||{}},o=t.levelConfig||nt,i={...ae,...t,i18n:e,levelConfig:o,renderConfig:n};return C(Ct,{config:i,children:C(mn,{})})}const gn={root:"https://unpkg.com/@roudanio/maze@0.1.0/dist/",...ae};return`${JSON.stringify(gn,null,2)}`,{async init(t,e){const n=typeof t=="string"?document.querySelector(t):t;if(!n){console.warn("Cannot find the root element");const a=document.createElement("div");a.style.textAlign="center",a.style.padding="20px",a.innerHTML="Cannot find the root element",document.body.append(a);return}let{root:o=location.origin}=e;o.at(-1)!=="/"&&(o+="/");const i=document.createElement("div"),s=document.createElement("div");i.style.cssText=`
|
|
2
2
|
height: 30px;
|
|
3
3
|
width: 100%;
|
|
4
4
|
border: solid 2px #999;
|
|
@@ -10,8 +10,8 @@ var Maze=function(){"use strict";var K,L,ye,j,be,ke,Te,Le,ue,de,he,ze,V={},Se=[]
|
|
|
10
10
|
animation: loading 1.5s ease-in-out;
|
|
11
11
|
transition: width 1.5s ease-in-out;
|
|
12
12
|
transition: width 1.5s ease-in-out;
|
|
13
|
-
`,i.append(s),n.append(i);const
|
|
13
|
+
`,i.append(s),n.append(i);const l=document.createElement("style");l.innerHTML=`
|
|
14
14
|
@keyframes loading {
|
|
15
15
|
0% { width: 0%; }
|
|
16
16
|
100% { width: 99%; }
|
|
17
|
-
}`,document.head.appendChild(
|
|
17
|
+
}`,document.head.appendChild(l),await(async a=>new Promise((c,d)=>{const u=document.createElement("link");u.rel="stylesheet",u.type="text/css",u.href=a,u.onload=c,u.onerror=d,document.head.appendChild(u)}))(o+"maze.css"),ut(C(vn,{config:e}),n)}}}();
|