@roudanio/maze 0.1.4 → 0.1.6

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