@roudanio/maze 0.1.2 → 0.1.3

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 Z,L,ke,U,Te,ze,Se,Le,de,he,fe,Ne,V={},Ae=[],st=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,Q=Array.isArray;function O(t,e){for(var n in e)t[n]=e[n];return t}function _e(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function lt(t,e,n){var o,i,s,c={};for(s in e)s=="key"?o=e[s]:s=="ref"?i=e[s]:c[s]=e[s];if(arguments.length>2&&(c.children=arguments.length>3?Z.call(arguments,2):n),typeof t=="function"&&t.defaultProps!=null)for(s in t.defaultProps)c[s]==null&&(c[s]=t.defaultProps[s]);return ee(t,c,o,i,null)}function ee(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??++ke,__i:-1,__u:0};return i==null&&L.vnode!=null&&L.vnode(s),s}function te(t){return t.children}function ne(t,e){this.props=t,this.context=e}function W(t,e){if(e==null)return t.__?W(t.__,t.__i+1):null;for(var n;e<t.__k.length;e++)if((n=t.__k[e])!=null&&n.__e!=null)return n.__e;return typeof t.type=="function"?W(t):null}function Ee(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 Ee(t)}}function me(t){(!t.__d&&(t.__d=!0)&&U.push(t)&&!oe.__r++||Te!=L.debounceRendering)&&((Te=L.debounceRendering)||ze)(oe)}function oe(){for(var t,e,n,o,i,s,c,r=1;U.length;)U.length>r&&U.sort(Se),t=U.shift(),r=U.length,t.__d&&(n=void 0,i=(o=(e=t).__v).__e,s=[],c=[],e.__P&&((n=O({},o)).__v=o.__v+1,L.vnode&&L.vnode(n),ve(e.__P,n,o,e.__n,e.__P.namespaceURI,32&o.__u?[i]:null,s,i??W(o),!!(32&o.__u),c),n.__v=o.__v,n.__.__k[n.__i]=n,De(s,n,c),n.__e!=i&&Ee(n)));oe.__r=0}function Me(t,e,n,o,i,s,c,r,l,a,d){var u,h,f,w,p,_,v=o&&o.__k||Ae,m=e.length;for(l=at(n,e,v,l,m),u=0;u<m;u++)(f=n.__k[u])!=null&&(h=f.__i==-1?V:v[f.__i]||V,f.__i=u,_=ve(t,f,h,i,s,c,r,l,a,d),w=f.__e,f.ref&&h.ref!=f.ref&&(h.ref&&ge(h.ref,null,f),d.push(f.ref,f.__c||w,f)),p==null&&w!=null&&(p=w),4&f.__u||h.__k===f.__k?l=Pe(f,l,t):typeof f.type=="function"&&_!==void 0?l=_:w&&(l=w.nextSibling),f.__u&=-7);return n.__e=p,l}function at(t,e,n,o,i){var s,c,r,l,a,d=n.length,u=d,h=0;for(t.__k=new Array(i),s=0;s<i;s++)(c=e[s])!=null&&typeof c!="boolean"&&typeof c!="function"?(l=s+h,(c=t.__k[s]=typeof c=="string"||typeof c=="number"||typeof c=="bigint"||c.constructor==String?ee(null,c,null,null,null):Q(c)?ee(te,{children:c},null,null,null):c.constructor==null&&c.__b>0?ee(c.type,c.props,c.key,c.ref?c.ref:null,c.__v):c).__=t,c.__b=t.__b+1,r=null,(a=c.__i=ct(c,n,l,u))!=-1&&(u--,(r=n[a])&&(r.__u|=2)),r==null||r.__v==null?(a==-1&&(i>d?h--:i<d&&h++),typeof c.type!="function"&&(c.__u|=4)):a!=l&&(a==l-1?h--:a==l+1?h++:(a>l?h--:h++,c.__u|=4))):t.__k[s]=null;if(u)for(s=0;s<d;s++)(r=n[s])!=null&&(2&r.__u)==0&&(r.__e==o&&(o=W(r)),Re(r,r));return o}function Pe(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=Pe(o[i],e,n));return e}t.__e!=e&&(e&&t.type&&!n.contains(e)&&(e=W(t)),n.insertBefore(t.__e,e||null),e=t.__e);do e=e&&e.nextSibling;while(e!=null&&e.nodeType==8);return e}function ct(t,e,n,o){var i,s,c=t.key,r=t.type,l=e[n];if(l===null&&t.key==null||l&&c==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&&c==l.key&&r==l.type)return i;i--}if(s<e.length){if((l=e[s])&&(2&l.__u)==0&&c==l.key&&r==l.type)return s;s++}}return-1}function Ie(t,e,n){e[0]=="-"?t.setProperty(e,n??""):t[e]=n==null?"":typeof n!="number"||st.test(e)?n:n+"px"}function re(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||Ie(t.style,e,"");if(n)for(e in n)o&&n[e]==o[e]||Ie(t.style,e,n[e])}else if(e[0]=="o"&&e[1]=="n")s=e!=(e=e.replace(Le,"$1")),e=e.toLowerCase()in t||e=="onFocusOut"||e=="onFocusIn"?e.toLowerCase().slice(2):e.slice(2),t.l||(t.l={}),t.l[e+s]=n,n?o?n.u=o.u:(n.u=de,t.addEventListener(e,s?fe:he,s)):t.removeEventListener(e,s?fe:he,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 xe(t){return function(e){if(this.l){var n=this.l[e.type+t];if(e.t==null)e.t=de++;else if(e.t<n.u)return;return n(L.event?L.event(e):e)}}}function ve(t,e,n,o,i,s,c,r,l,a){var d,u,h,f,w,p,_,v,m,y,C,k,T,S,z,b,M,N=e.type;if(e.constructor!=null)return null;128&n.__u&&(l=!!(32&n.__u),s=[r=e.__e=n.__e]),(d=L.__b)&&d(e);e:if(typeof N=="function")try{if(v=e.props,m="prototype"in N&&N.prototype.render,y=(d=N.contextType)&&o[d.__c],C=d?y?y.props.value:d.__:o,n.__c?_=(u=e.__c=n.__c).__=u.__E:(m?e.__c=u=new N(v,C):(e.__c=u=new ne(v,C),u.constructor=N,u.render=dt),y&&y.sub(u),u.props=v,u.state||(u.state={}),u.context=C,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=O({},u.__s)),O(u.__s,N.getDerivedStateFromProps(v,u.__s))),f=u.props,w=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,C),!u.__e&&u.shouldComponentUpdate!=null&&u.shouldComponentUpdate(v,u.__s,C)===!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)}),k=0;k<u._sb.length;k++)u.__h.push(u._sb[k]);u._sb=[],u.__h.length&&c.push(u);break e}u.componentWillUpdate!=null&&u.componentWillUpdate(v,u.__s,C),m&&u.componentDidUpdate!=null&&u.__h.push(function(){u.componentDidUpdate(f,w,p)})}if(u.context=C,u.props=v,u.__P=t,u.__e=!1,T=L.__r,S=0,m){for(u.state=u.__s,u.__d=!1,T&&T(e),d=u.render(u.props,u.state,u.context),z=0;z<u._sb.length;z++)u.__h.push(u._sb[z]);u._sb=[]}else do u.__d=!1,T&&T(e),d=u.render(u.props,u.state,u.context),u.state=u.__s;while(u.__d&&++S<25);u.state=u.__s,u.getChildContext!=null&&(o=O(O({},o),u.getChildContext())),m&&!h&&u.getSnapshotBeforeUpdate!=null&&(p=u.getSnapshotBeforeUpdate(f,w)),b=d,d!=null&&d.type===te&&d.key==null&&(b=Fe(d.props.children)),r=Me(t,Q(b)?b:[b],e,n,o,i,s,c,r,l,a),u.base=e.__e,e.__u&=-161,u.__h.length&&c.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(M=s.length;M--;)_e(s[M]);else e.__e=n.__e,e.__k=n.__k;L.__e(P,e,n)}else s==null&&e.__v==n.__v?(e.__k=n.__k,e.__e=n.__e):r=e.__e=ut(n.__e,e,n,o,i,s,c,l,a);return(d=L.diffed)&&d(e),128&e.__u?void 0:r}function De(t,e,n){for(var o=0;o<n.length;o++)ge(n[o],n[++o],n[++o]);L.__c&&L.__c(e,t),t.some(function(i){try{t=i.__h,i.__h=[],t.some(function(s){s.call(i)})}catch(s){L.__e(s,i.__v)}})}function Fe(t){return typeof t!="object"||t==null||t.__b&&t.__b>0?t:Q(t)?t.map(Fe):O({},t)}function ut(t,e,n,o,i,s,c,r,l){var a,d,u,h,f,w,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(a=0;a<s.length;a++)if((f=s[a])&&"setAttribute"in f==!!m&&(m?f.localName==m:f.nodeType==3)){t=f,s[a]=null;break}}if(t==null){if(m==null)return document.createTextNode(v);t=document.createElementNS(i,m,v.is&&v),r&&(L.__m&&L.__m(e,s),r=!1),s=null}if(m==null)_===v||r&&t.data==v||(t.data=v);else{if(s=s&&Z.call(t.childNodes),_=n.props||V,!r&&s!=null)for(_={},a=0;a<t.attributes.length;a++)_[(f=t.attributes[a]).name]=f.value;for(a in _)if(f=_[a],a!="children"){if(a=="dangerouslySetInnerHTML")u=f;else if(!(a in v)){if(a=="value"&&"defaultValue"in v||a=="checked"&&"defaultChecked"in v)continue;re(t,a,null,f,i)}}for(a in v)f=v[a],a=="children"?h=f:a=="dangerouslySetInnerHTML"?d=f:a=="value"?w=f:a=="checked"?p=f:r&&typeof f!="function"||_[a]===f||re(t,a,f,_[a],i);if(d)r||u&&(d.__html==u.__html||d.__html==t.innerHTML)||(t.innerHTML=d.__html),e.__k=[];else if(u&&(t.innerHTML=""),Me(e.type=="template"?t.content:t,Q(h)?h:[h],e,n,o,m=="foreignObject"?"http://www.w3.org/1999/xhtml":i,s,c,s?s[0]:n.__k&&W(n,0),r,l),s!=null)for(a=s.length;a--;)_e(s[a]);r||(a="value",m=="progress"&&w==null?t.removeAttribute("value"):w!=null&&(w!==t[a]||m=="progress"&&!w||m=="option"&&w!=_[a])&&re(t,a,w,_[a],i),a="checked",p!=null&&p!=t[a]&&re(t,a,p,_[a],i))}return t}function ge(t,e,n){try{if(typeof t=="function"){var o=typeof t.__u=="function";o&&t.__u(),o&&e==null||(t.__u=t(e))}else t.current=e}catch(i){L.__e(i,n)}}function Re(t,e,n){var o,i;if(L.unmount&&L.unmount(t),(o=t.ref)&&(o.current&&o.current!=t.__e||ge(o,null,e)),(o=t.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(s){L.__e(s,e)}o.base=o.__P=null}if(o=t.__k)for(i=0;i<o.length;i++)o[i]&&Re(o[i],e,n||typeof t.type!="function");n||_e(t.__e),t.__c=t.__=t.__e=void 0}function dt(t,e,n){return this.constructor(t,n)}function ht(t,e,n){var o,i,s,c;e==document&&(e=document.documentElement),L.__&&L.__(t,e),i=(o=!1)?null:e.__k,s=[],c=[],ve(e,t=e.__k=lt(te,null,[t]),i||V,V,e.namespaceURI,i?null:e.firstChild?Z.call(e.childNodes):null,s,i?i.__e:e.firstChild,o,c),De(s,t,c)}function ft(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(c){c.__e=!0,me(c)})},this.sub=function(s){o.add(s);var c=s.componentWillUnmount;s.componentWillUnmount=function(){o&&o.delete(s),c&&c.call(s)}}),n.children}return e.__c="__cC"+Ne++,e.__=t,e.Provider=e.__l=(e.Consumer=function(n,o){return n.children(o)}).contextType=e,e}Z=Ae.slice,L={__e:function(t,e,n,o){for(var i,s,c;e=e.__;)if((i=e.__c)&&!i.__)try{if((s=i.constructor)&&s.getDerivedStateFromError!=null&&(i.setState(s.getDerivedStateFromError(t)),c=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(t,o||{}),c=i.__d),c)return i.__E=i}catch(r){t=r}throw t}},ke=0,ne.prototype.setState=function(t,e){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=O({},this.state),typeof t=="function"&&(t=t(O({},n),this.props)),t&&O(n,t),t!=null&&this.__v&&(e&&this._sb.push(e),me(this))},ne.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),me(this))},ne.prototype.render=te,U=[],ze=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,Se=function(t,e){return t.__v.__b-e.__v.__b},oe.__r=0,Le=/(PointerCapture)$|Capture$/i,de=0,he=xe(!1),fe=xe(!0),Ne=0;var _t=0;function g(t,e,n,o,i,s){e||(e={});var c,r,l=e;if("ref"in l)for(r in l={},e)r=="ref"?c=e[r]:l[r]=e[r];var a={type:t,props:l,key:n,ref:c,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--_t,__i:-1,__u:0,__source:i,__self:s};if(typeof t=="function"&&(c=t.defaultProps))for(r in c)l[r]===void 0&&(l[r]=c[r]);return L.vnode&&L.vnode(a),a}var j,A,pe,Oe,Y=0,$e=[],E=L,Ue=E.__b,We=E.__r,je=E.diffed,Ge=E.__c,He=E.unmount,qe=E.__;function ie(t,e){E.__h&&E.__h(A,t,Y||e),Y=0;var n=A.__H||(A.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function G(t){return Y=1,mt(Ye,t)}function mt(t,e,n){var o=ie(j++,2);if(o.t=t,!o.__c&&(o.__=[Ye(void 0,e),function(r){var l=o.__N?o.__N[0]:o.__[0],a=o.t(l,r);l!==a&&(o.__N=[a,o.__[1]],o.__c.setState({}))}],o.__c=A,!A.__f)){var i=function(r,l,a){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,a);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,a)||u};A.__f=!0;var s=A.shouldComponentUpdate,c=A.componentWillUpdate;A.componentWillUpdate=function(r,l,a){if(this.__e){var d=s;s=void 0,i(r,l,a),s=d}c&&c.call(this,r,l,a)},A.shouldComponentUpdate=i}return o.__N||o.__}function x(t,e){var n=ie(j++,3);!E.__s&&Ve(n.__H,e)&&(n.__=t,n.u=e,A.__H.__h.push(n))}function D(t){return Y=5,H(function(){return{current:t}},[])}function H(t,e){var n=ie(j++,7);return Ve(n.__H,e)&&(n.__=t(),n.__H=e,n.__h=t),n.__}function vt(t,e){return Y=8,H(function(){return t},e)}function gt(t){var e=A.context[t.__c],n=ie(j++,9);return n.c=t,e?(n.__==null&&(n.__=!0,e.sub(A)),e.props.value):t.__}function pt(){for(var t;t=$e.shift();)if(t.__P&&t.__H)try{t.__H.__h.forEach(se),t.__H.__h.forEach(Ce),t.__H.__h=[]}catch(e){t.__H.__h=[],E.__e(e,t.__v)}}E.__b=function(t){A=null,Ue&&Ue(t)},E.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),qe&&qe(t,e)},E.__r=function(t){We&&We(t),j=0;var e=(A=t.__c).__H;e&&(pe===A?(e.__h=[],A.__h=[],e.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(e.__h.forEach(se),e.__h.forEach(Ce),e.__h=[],j=0)),pe=A},E.diffed=function(t){je&&je(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&($e.push(e)!==1&&Oe===E.requestAnimationFrame||((Oe=E.requestAnimationFrame)||Ct)(pt)),e.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),pe=A=null},E.__c=function(t,e){e.some(function(n){try{n.__h.forEach(se),n.__h=n.__h.filter(function(o){return!o.__||Ce(o)})}catch(o){e.some(function(i){i.__h&&(i.__h=[])}),e=[],E.__e(o,n.__v)}}),Ge&&Ge(t,e)},E.unmount=function(t){He&&He(t);var e,n=t.__c;n&&n.__H&&(n.__H.__.forEach(function(o){try{se(o)}catch(i){e=i}}),n.__H=void 0,e&&E.__e(e,n.__v))};var Be=typeof requestAnimationFrame=="function";function Ct(t){var e,n=function(){clearTimeout(o),Be&&cancelAnimationFrame(e),setTimeout(t)},o=setTimeout(n,100);Be&&(e=requestAnimationFrame(n))}function se(t){var e=A,n=t.__c;typeof n=="function"&&(t.__c=void 0,n()),A=e}function Ce(t){var e=A;t.__c=t.__(),A=e}function Ve(t,e){return!t||t.length!==e.length||e.some(function(n,o){return n!==t[o]})}function Ye(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)}}}),Xe=ft(void 0),Ke={currentLevel:1,highestUnlockedLevel:1,currentTier:1,highestUnlockedTier:1,levelScores:{},totalScore:0},Je={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]=G(()=>o||{...Ke});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[c,r]=G({...Je}),l=D(c);x(()=>{l.current=c},[c]);const a=H(()=>[c.playerAtExit?1:0,c.foodCollected===c.totalFoodCount?1:0,c.showClue?0:1],[c.playerAtExit,c.foodCollected,c.totalFoodCount,c.showClue]),d=()=>{n.resetGameData(),s({...Ke}),r({...Je})};return g(Xe.Provider,{value:{gameProgress:i,setGameProgress:s,gamePlayState:c,setGamePlayState:r,gamePlayStateRef:l,currentScore:a,config:e,resetGame:d},children:t})},q=()=>{const t=gt(Xe);if(!t)throw new Error("useGameContext must be used within a GameProvider");return t},X=t=>H(()=>{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 a=0;a<e.length;a++)if(l+=e[a],r<=l)return a+1;return 0},s=r=>r<1||r>o?0:e.slice(0,r-1).reduce((l,a)=>l+a,0)+1,c={getTotalLevels:()=>n,getTotalTiers:()=>o,getTierLevelsRange:r=>{if(r<1||r>o)return[0,0];const l=s(r),a=l+e[r-1]-1;return[l,a]},getTierByLevel:i,getFirstLevelOfTier:s,getLevelConfig:r=>{if(r<1||r>n)return null;const l=i(r),a=s(l),d=r-a;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,a=i(r),d=i(l);return{nextLevel:l,nextTier:d,isTierChange:d>a}},getCurrentTierProgress:(r,l)=>{const[a,d]=c.getTierLevelsRange(l),u=r-a+1,h=d-a+1;return{current:u,total:h}},isLastLevelInTier:r=>{const l=i(r),[,a]=c.getTierLevelsRange(l);return r===a},getPreviousLevelInfo:r=>{if(r<=1)return null;const l=r-1,a=i(r),d=i(l);return{prevLevel:l,prevTier:d,isTierChange:d<a}}};return c},[t]),bt=({onTierChange:t,disabled:e})=>{const{gameProgress:n,config:o}=q(),{i18n:i,levelConfig:s}=o,{currentTier:c,highestUnlockedTier:r}=n,a=X(s).getTotalTiers();return g("div",{className:"tier-selector",children:g("select",{value:c,onChange:d=>{d.target&&d.target.value&&t(Number(d.target.value))},disabled:e,className:"tier-dropdown",children:Array.from({length:a},(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:c,levelScores:r,currentLevel:l,highestUnlockedLevel:a}=n,d=X(s),u=H(()=>{const[h,f]=d.getTierLevelsRange(c);return Array.from({length:f-h+1},(w,p)=>{const _=h+p,v=r[_]||0;return{level:_,score:v}})},[c,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>a,children:`${i.level} ${h} ${"★".repeat(f)}`},`level-${h}`))})})},le=({isOpen:t,title:e,className:n="",message:o,children:i,noConfirm:s=!1,noCancel:c=!1,confirmText:r="OK",cancelText:l="Cancel",onConfirm:a,onCancel:d})=>{const u=D(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})}),(!c||!s)&&g("div",{className:"maze-dialog-buttons",children:[!c&&g("button",{type:"button",className:"maze-dialog-cancel",onClick:d,children:l}),!s&&g("button",{type:"button",className:"maze-dialog-confirm",onClick:a,children:r})]})]})})},R={container:null,attachTo(t){return this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.container=document.createElement("div"),this.container.className="toast-container position-top",t.appendChild(this.container),this.container},currentToast:null,currentTimer:null,show(t,e="info",n=2e3){if(!this.container){console.warn("NativeToast: container not initialized, please call attachTo first");return}this.currentToast&&this.container.contains(this.currentToast)&&(this.container.removeChild(this.currentToast),this.currentToast=null),this.currentTimer&&(clearTimeout(this.currentTimer),this.currentTimer=null);const o=document.createElement("div");o.className=`toast-message type-${e} toast-visible`,o.textContent=t,this.container.appendChild(o),this.currentToast=o,this.currentTimer=setTimeout(()=>{o.classList.remove("toast-visible"),setTimeout(()=>{this.container&&this.container.contains(o)&&(this.container.removeChild(o),this.currentToast===o&&(this.currentToast=null))},300),this.currentTimer=null},n)},clearAll(){if(this.container)for(;this.container.firstChild;)this.container.removeChild(this.container.firstChild)}},Tt=()=>{const{gameProgress:t,setGameProgress:e,gamePlayState:n,setGamePlayState:o,gamePlayStateRef:i,resetGame:s,config:c}=q(),{i18n:r,levelConfig:l}=c,a=X(l),{levelTransitioning:d,showClue:u}=n,{highestUnlockedLevel:h,totalScore:f}=t,w=a.getTotalLevels(),[p,_]=G(!1),[v,m]=G(!1),[y,C]=G(!1),k=$=>{const J=a.getFirstLevelOfTier($);a.isLevelUnlocked(J,h)&&(e(B=>({...B,currentTier:$})),T(J))},T=$=>{a.isLevelUnlocked($,h)&&(e(J=>({...J,currentLevel:$})),R.show(r.levelGoToast.replace("%LEVEL%",$.toString()),"success"))},S=()=>{_(!0)},z=()=>{_(!1)},b=()=>{C(!0)},M=()=>{C(!1)},N=()=>{R.show(u?r.cluePathDisabled:r.cluePathEnabled),o(()=>({...i.current,showClue:!i.current.showClue})),C(!1)},P=()=>{m(!0)},I=()=>{s(),m(!1),R.show(r.resetDoneToast)},K=()=>{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:k,disabled:d}),g(kt,{onLevelChange:T,disabled:d})]}),g("button",{className:`settings-clue-button ${u?"clue-on":"clue-off"}`,disabled:u,title:"Toggle Clue",onClick:b,children:u?r.clueOn:r.clueOff})]}),g("div",{className:"game-settings",children:g("span",{className:"game-settings-icon",onClick:S,children:"★ "+f})}),g(le,{isOpen:p,title:r.settings,noConfirm:!0,cancelText:r.close,onCancel:z,children:[g("div",{className:"settings-stats",children:[g("div",{children:r.levelComplete+`: ${h}/${w}`}),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(le,{isOpen:v,title:r.confirmReset,message:r.confirmResetMessage,confirmText:r.reset,cancelText:r.cancel,onConfirm:I,onCancel:K}),g(le,{isOpen:y,title:r.confirmClue,message:r.confirmClueMessage,confirmText:r.confirm,cancelText:r.cancel,onConfirm:N,onCancel:M})]})};function we(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function zt(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 ye(t,e,n){return e&&zt(t.prototype,e),t}function Ze(t){return+t.replace(/px/,"")}function St(t){var e=window.devicePixelRatio,n=getComputedStyle(t),o=Ze(n.getPropertyValue("width")),i=Ze(n.getPropertyValue("height"));t.setAttribute("width",(o*e).toString()),t.setAttribute("height",(i*e).toString())}function F(t,e){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,o=Math.random()*(e-t)+t;return Math.floor(o*Math.pow(10,n))/Math.pow(10,n)}function Qe(t){return t[F(0,t.length)]}var Lt=.00125,Nt=5e-4,At=9e-4,Et=1e-5,Mt=6,Pt=80,It=.9,xt=1.7,Dt=.2,Ft=.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 et(t){var e=1920;return Math.log(t)/Math.log(e)}var tt=function(){function t(e){we(this,t);var n=e.initialPosition,o=e.direction,i=e.confettiRadius,s=e.confettiColors,c=e.emojis,r=e.emojiSize,l=e.canvasWidth,a=F(It,xt,3),d=a*et(l);this.confettiSpeed={x:d,y:d},this.finalConfettiSpeedX=F(Dt,Ft,3),this.rotationSpeed=c.length?.01:F(Rt,Ot,3)*et(l),this.dragForceCoefficient=F(Nt,At,6),this.radius={x:i,y:i},this.initialRadius=i,this.rotationAngle=o==="left"?F(0,.2,3):F(-.2,0,3),this.emojiSize=r,this.emojiRotationAngle=F(0,2*Math.PI),this.radiusYUpdateDirection="down";var u=o==="left"?F(Ut,$t)*Math.PI/180:F(-15,-82)*Math.PI/180;this.absCos=Math.abs(Math.cos(u)),this.absSin=Math.abs(Math.sin(u));var h=F(-150,0),f={x:n.x+(o==="left"?-h:h)*this.absCos,y:n.y-h*this.absSin};this.currentPosition=Object.assign({},f),this.initialPosition=Object.assign({},f),this.color=c.length?null:Qe(s),this.emoji=c.length?Qe(c):null,this.createdAt=new Date().getTime(),this.direction=o}return ye(t,[{key:"draw",value:function(n){var o=this.currentPosition,i=this.radius,s=this.color,c=this.emoji,r=this.rotationAngle,l=this.emojiRotationAngle,a=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()):c&&(n.font="".concat(a,"px serif"),n.save(),n.translate(d*o.x,d*o.y),n.rotate(l),n.textAlign="center",n.fillText(c,0,0),n.restore())}},{key:"updatePosition",value:function(n,o){var i=this.confettiSpeed,s=this.dragForceCoefficient,c=this.finalConfettiSpeedX,r=this.radiusYUpdateDirection,l=this.rotationSpeed,a=this.createdAt,d=this.direction,u=o-a;if(i.x>c&&(this.confettiSpeed.x-=s*n),this.currentPosition.x+=i.x*(d==="left"?-this.absCos:this.absCos)*n,this.currentPosition.y=this.initialPosition.y-i.y*this.absSin*u+Lt*Math.pow(u,2)/2,this.rotationSpeed-=this.emoji?1e-4:Et*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 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 Bt(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,c=s===void 0?Ht:s,r=t.emojis,l=r===void 0?t.emojies||[]:r,a=t.emojiSize,d=a===void 0?Pt:a;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:c,emojis:l,emojiSize:d}}var Vt=function(){function t(e){var n=this;we(this,t),this.canvasContext=e,this.shapes=[],this.promise=new Promise(function(o){return n.resolvePromise=o})}return ye(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,c=n.timeDelta,r=n.currentTime;this.shapes=this.shapes.filter(function(l){return l.updatePosition(c,r),l.draw(s.canvasContext),i?l.getIsVisibleOnCanvas(o):!0})}}]),t}(),Yt=function(){function t(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};we(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 ye(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(c){return c.processShapes({timeDelta:o,currentTime:n},i,s),s?!c.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=Bt(n),i=o.confettiRadius,s=o.confettiNumber,c=o.confettiColors,r=o.emojis,l=o.emojiSize,a=this.canvas.getBoundingClientRect(),d=a.width,u=a.height,h=u*5/7,f={x:0,y:h},w={x:d,y:h},p=new Vt(this.canvasContext),_=0;_<s/2;_++){var v=new tt({initialPosition:f,direction:"right",confettiRadius:i,confettiColors:c,confettiNumber:s,emojis:r,emojiSize:l,canvasWidth:d}),m=new tt({initialPosition:w,direction:"left",confettiRadius:i,confettiColors:c,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 Xt=new Yt,Kt=({onRetry:t})=>{const{config:e,currentScore:n,gamePlayState:o,setGamePlayState:i,gameProgress:s,setGameProgress:c}=q(),{i18n:r,levelConfig:l}=e,[a,d,u]=n,{foodCollected:h,totalFoodCount:f,playerAtExit:w,levelTransitioning:p}=o,{currentLevel:_}=s,[v,m]=G(!1);x(()=>{w&&p&&(Xt.addConfetti(),R.show(r.levelCompleteToast,"success"),m(!0))},[w,p]);const y=X(l),C=y.getTotalLevels(),k=H(()=>_>=C,[_,C]),T=()=>{m(!1),R.show(r.levelRestartToast,"info"),t?.()},S=()=>{m(!1),i(b=>({...b,isGameActive:!0,levelTransitioning:!1}))},z=()=>{m(!1);const b=y.getNextLevelInfo(_);if(!b)return;const{nextLevel:M,nextTier:N,isTierChange:P}=b;P&&R.show(r.tierUnlockedToast.replace("%TIER%",N.toString()),"success"),c(I=>({...I,currentLevel:M,currentTier:N,highestUnlockedLevel:Math.max(I.highestUnlockedLevel,M),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(le,{className:"level-complete-dialog",isOpen:v,title:r.congratulations,cancelText:r.retry,onCancel:T,noConfirm:!!d,confirmText:r.continue,onConfirm:S,children:[g("div",{className:"maze-summary-message",children:[!!a&&g("div",{children:"★ - "+r.findYourExit}),g("div",{children:u?"★ - "+r.withoutClue:"☆ - "+r.withClue}),g("div",{children:(d?"★ - "+r.collectAllStars:"☆ - "+r.notCollectAllStars)+` (${h}/${f})`})]}),k&&g("div",{className:"all-levels-completed",children:r.allLevelsCompleted}),g("div",{className:"go-next-level",children:k?"OK":g("button",{type:"button",onClick:z,children:r.nextLevel})}),!d&&g("div",{className:"not-all-stars-collected",children:r.continueMessage})]})},Jt=(t,e)=>{const n=D({canvasWidth:0,canvasHeight:0});return x(()=>{const o=()=>{const s=t.current;if(!s)return;const c=s.parentElement;if(!c)return;const r=c.clientWidth,l=window.devicePixelRatio||1;s.style.width=`${r}px`,s.style.height=`${r}px`;const a=r*l,d=r*l;s.width=a,s.height=d,n.current={canvasWidth:a,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=D({cellWidth:0,cellHeight:0});return x(()=>{const i=e.renderConfig.padding,s=()=>{const r=t.current;if(!r||!n)return;const{rows:l,cols:a}=n;if(l<=0||a<=0)return;const d=(r.width-i*2)/a,u=(r.height-i*2)/l;o.current={cellWidth:d,cellHeight:u}};s();let c=null;return t.current&&window.ResizeObserver&&(c=new ResizeObserver(s),c.observe(t.current)),()=>{t.current&&c?.disconnect()}},[t,n]),o},ae={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]},Qt=({containerRef:t,gamePlayStateRef:e,setGamePlayState:n,moveSpeed:o,playerRadius:i,exitWallWidth:s,getCellSizeInPixels:c,onFoodCollected:r})=>{const l=D(!1),a=D(new Set),d=(_,v)=>{const m=e.current;if(!m.maze)return{canMove:!1,newCell:null};const[y,C]=ae[_];if(nt(v,y,C,i,o,m.maze))return{canMove:!1,newCell:null};const{row:T,col:S}=v,z=T+y*o,b=S+C*o,M=Math.floor(T),N=Math.floor(S),P=Math.floor(z),I=Math.floor(b);return P!==M||I!==N?m.maze.isValid(P,I)?{canMove:!0,newCell:{row:P,col:I}}:{canMove:!1,newCell:null}:{canMove:!0,newCell:null}},u=()=>{const _=e.current,{row:v,col:m}=_.playerCell,y=i*2,C=_.foodCells.findIndex(S=>Math.sqrt(Math.pow(v-S.row,2)+Math.pow(m-S.col,2))<y);C!==-1&&r&&(r(),e.current={...e.current,foodCollected:e.current.foodCollected+1,foodCells:e.current.foodCells.filter((S,z)=>z!==C)});const T=tn(_.playerCell,_.exitCell,_.maze,i,s,c);T&&!e.current.playerAtExit?(e.current={...e.current,playerAtExit:!0,isGameActive:!1,levelTransitioning:!0},requestIdleCallback(()=>{n(()=>({...e.current}))},{timeout:10})):!T&&e.current.playerAtExit&&(e.current={...e.current,playerAtExit:!1,isGameActive:!0,levelTransitioning:!1})},h=_=>{const v=e.current,m=Math.round(_.row),y=Math.round(_.col),C=v.playerPath[v.playerPath.length-1],k=C.row===m&&C.col===y,T=Math.abs(C.row-m),S=Math.abs(C.col-y);if((T===1&&S===0||T===0&&S===1)&&!k){const b=`${C.row},${C.col}-${m},${y}`;e.current={...e.current,playerPath:[...e.current.playerPath,{row:m,col:y}],visitCounts:{...e.current.visitCounts,[b]:(e.current.visitCounts[b]||0)+1}}}},f=()=>{if(l.current||a.current.size===0)return;const _=e.current;!_.playerCell||!Array.from(a.current).some(m=>{const{canMove:y}=d(m,_.playerCell);return y})||(l.current=!0)};x(()=>{const _=k=>{(k.key==="ArrowUp"||k.key==="ArrowDown"||k.key==="ArrowLeft"||k.key==="ArrowRight"||k.key===" ")&&k.preventDefault()},v=k=>{const T=k.key;T in ae&&(k.preventDefault(),e.current.isGameActive&&(a.current.has(T)||(a.current.add(T),l.current||f())))},m=k=>{const T=k.key;T in ae&&(k.preventDefault(),a.current.delete(T),a.current.size===0&&p())},y=k=>{k.preventDefault();const T=e.current;if(!T.isGameActive||!T.maze||l.current)return;const S=k.touches[0],z=document.elementFromPoint(S.clientX,S.clientY);let b=null;z&&(z.classList.contains("maze-up")?b="ArrowUp":z.classList.contains("maze-down")?b="ArrowDown":z.classList.contains("maze-left")?b="ArrowLeft":z.classList.contains("maze-right")&&(b="ArrowRight")),b&&(a.current.clear(),a.current.add(b),f())},C=()=>{p()};return window.addEventListener("keydown",_,{capture:!0}),window.addEventListener("keydown",v),window.addEventListener("keyup",m),t.current?.addEventListener("touchstart",y,{passive:!1}),t.current?.addEventListener("touchend",C),()=>{window.removeEventListener("keydown",_,{capture:!0}),window.removeEventListener("keydown",v),window.removeEventListener("keyup",m),t.current?.removeEventListener("touchstart",y),t.current?.removeEventListener("touchend",C)}},[]);const w=vt(()=>{if(!l.current||a.current.size===0)return e.current.playerCell;const _=e.current.playerCell;let v=0,m=0,y=0;for(const B of a.current){const{canMove:be}=d(B,_);if(be){const[it,wn]=ae[B];v+=it,m+=wn,y++}}if(y===0)return e.current.playerCell;const C=Math.sqrt(v*v+m*m),k=C>0?v/C:0,T=C>0?m/C:0,S=Number((_.row+k*o).toFixed(2)),z=Number((_.col+T*o).toFixed(2)),b=S-_.row,M=z-_.col,N=Math.sqrt(b*b+M*M);if(N>0){const B=b/N,be=M/N;if(nt(_,B,be,i,N,e.current.maze))return e.current.playerCell}e.current.playerCell={row:S,col:z},u();const P=Math.round(_.row),I=Math.round(_.col),K=Math.round(S),$=Math.round(z);return(K!==P||$!==I)&&h({row:K,col:$}),e.current.playerCell},[o]),p=()=>{l.current=!1,a.current.clear()};return{updatePlayerPos:w,resetMovingState:p}};function nt(t,e,n,o,i,s){const c=t.row+e*i,r=t.col+n*i,l={row:c,col:r},a=[],d=Math.floor(t.row),u=Math.floor(t.col);a.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,w]of h){const p=d+f,_=u+w;s.isValid(p,_)&&a.push({row:p,col:_})}for(const f of a){const w=en(f.row,f.col,s);for(const p of w)if(ot(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 ot(t,e){const{start:n,end:o}=e,i=o.col-n.col,s=o.row-n.row,c=t.col-n.col,r=t.row-n.row,l=i*i+s*s;if(l===0)return Math.sqrt(c*c+r*r);const a=Math.max(0,Math.min(1,(c*i+r*s)/l)),d=n.col+a*i,u=n.row+a*s,h=t.col-d,f=t.row-u;return Math.sqrt(h*h+f*f)}function tn(t,e,n,o,i,s){if(Math.sqrt(Math.pow(t.row-e.row,2)+Math.pow(t.col-e.col,2))>1.5||!n.isValid(e.row,e.col))return!1;if(n.grid[e.row][e.col].walls.bottom){let l=0;if(s&&i){const h=s();l=i/h}else l=(i||3)/100;const a=l*.5,d={start:{row:e.row+.5-a,col:e.col-.5},end:{row:e.row+.5-a,col:e.col+.5}};if(ot(t,d)<=o*1.5)return!0}return!1}function nn(t,e,n,o,i){if(!t||!e.maze)return;const{canvasWidth:s,canvasHeight:c}=n,{cellWidth:r,cellHeight:l}=o,{maze:a,playerCell:d,exitCell:u,foodCells:h,showClue:f,playerPath:w,visitCounts:p}=e,{padding:_,wallWidth:v,wallColor:m,playerColor:y,playerRadius:C,foodColor:k,backgroundColor:T,clueColor:S,exitColor:z,exitWallWidth:b,exitDashArray:M}=i;t.clearRect(0,0,s,c),t.save(),t.fillStyle=T,t.fillRect(0,0,s,c),t.restore(),f&&cn({ctx:t,playerPath:w,visitCounts:p,cellWidth:r,cellHeight:l,padding:_,clueColor:S}),on({ctx:t,maze:a,cellWidth:r,cellHeight:l,padding:_,wallColor:m,wallWidth:v}),sn({ctx:t,maze:a,exitCell:u,cellWidth:r,cellHeight:l,padding:_,exitColor:z,exitWallWidth:b,exitDashArray:M}),ln({ctx:t,foodCells:h,cellWidth:r,cellHeight:l,padding:_,foodColor:k}),rn({ctx:t,playerCell:d,playerRadius:C,cellWidth:r,cellHeight:l,padding:_,playerColor:y})}function on({ctx:t,maze:e,cellWidth:n,cellHeight:o,padding:i,wallColor:s,wallWidth:c}){t.save(),t.strokeStyle=s,t.lineWidth=c,t.lineCap="round",t.beginPath(),un(e,n,o,i).forEach(l=>{t.moveTo(l.x1,l.y1),t.lineTo(l.x2,l.y2)}),t.stroke(),t.restore()}function rn({ctx:t,playerCell:e,playerRadius:n,cellWidth:o,cellHeight:i,padding:s,playerColor:c}){const{x:r,y:l}=ce(e.row,e.col,o,i,s),a=Math.min(o,i)*Math.min(n,.5);t.save(),t.fillStyle=c,t.beginPath(),t.arc(r,l,a,0,Math.PI*2),t.fill(),t.restore()}function sn({ctx:t,maze:e,exitCell:n,cellWidth:o,cellHeight:i,padding:s,exitColor:c,exitWallWidth:r,exitDashArray:l=[8,12]}){const{row:a,col:d}=n;if(!e.isValid(a,d))return;const u=e.grid[a][d],h=s+d*o,f=s+a*i;t.save(),t.globalCompositeOperation="destination-out",t.lineWidth=r,t.lineCap="round",t.beginPath(),u.walls.bottom&&(t.moveTo(h,f+i),t.lineTo(h+o,f+i)),t.stroke(),t.globalCompositeOperation="source-over",t.strokeStyle=c,t.lineWidth=r,t.setLineDash(l),t.beginPath(),u.walls.bottom&&(t.moveTo(h,f+i),t.lineTo(h+o,f+i)),t.stroke(),t.restore()}function ln({ctx:t,foodCells:e,cellWidth:n,cellHeight:o,padding:i,foodColor:s}){t.fillStyle=s;const c=Math.min(n,o)*.25;e.forEach(r=>{const{x:l,y:a}=ce(r.row,r.col,n,o,i);an(t,l,a,c*1.2,5,c*.6)})}function an(t,e,n,o,i,s){t.save(),t.beginPath();for(let c=0;c<i*2;c++){const r=c%2===0?o:s,l=Math.PI*c/i;t.lineTo(e+r*Math.sin(l),n+r*Math.cos(l))}t.closePath(),t.fill(),t.restore()}function cn({ctx:t,playerPath:e,visitCounts:n,cellWidth:o,cellHeight:i,padding:s,clueColor:c}){if(!(!e||e.length<2||!n)){t.save();for(let r=1;r<e.length;r++){const l=e[r-1],a=e[r],d=`${l.row},${l.col}-${a.row},${a.col}`,u=`${a.row},${a.col}-${l.row},${l.col}`,h=(n[d]||0)+(n[u]||0),f=Math.min(.2+h*.1,.9),w=Math.max(3,o*.1)+h*.5;try{t.strokeStyle=c.replace(")",`, ${f})`).replace("rgb(","rgba(")}catch{t.strokeStyle=`rgba(255, 0, 0, ${f})`}t.lineWidth=w,t.lineCap="round",t.lineJoin="round";const{x:p,y:_}=ce(l.row,l.col,o,i,s),{x:v,y:m}=ce(a.row,a.col,o,i,s);t.beginPath(),t.moveTo(p,_),t.lineTo(v,m),t.stroke()}t.restore()}}function un(t,e,n,o){const i=[];for(let s=0;s<t.rows;s++)for(let c=0;c<t.cols;c++){const r=t.grid[s][c],l=o+c*e,a=o+s*n;r.walls.top&&i.push({x1:l,y1:a,x2:l+e,y2:a}),r.walls.right&&i.push({x1:l+e,y1:a,x2:l+e,y2:a+n}),r.walls.bottom&&i.push({x1:l,y1:a+n,x2:l+e,y2:a+n}),r.walls.left&&i.push({x1:l,y1:a,x2:l,y2:a+n})}return i}function ce(t,e,n,o,i){return{x:i+e*n+n/2,y:i+t*o+o/2}}function dn(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 hn{constructor(e,n){this.row=e,this.col=n}visited=!1;walls={top:!0,right:!0,bottom:!0,left:!0}}class fn{rows;cols;grid;seed;random;constructor(e,n,o,i,s={row:0,col:0}){this.rows=e,this.cols=n,this.seed=i??Math.floor(Math.random()*1e6),this.random=dn(this.seed),this.grid=this.initializeGrid(),this.generate(o,s)}initializeGrid(){const e=[];for(let n=0;n<this.rows;n++){e[n]=[];for(let o=0;o<this.cols;o++)e[n][o]=new hn(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 c=e+s.r,r=n+s.c;this.isValid(c,r)&&o.push({row:c,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],c=this.grid[o][i];e===o+1?(s.walls.top=!1,c.walls.bottom=!1):e===o-1?(s.walls.bottom=!1,c.walls.top=!1):n===i+1?(s.walls.left=!1,c.walls.right=!1):n===i-1&&(s.walls.right=!1,c.walls.left=!1)}generate(e,n={row:0,col:0}){switch(e){case"backtracking":this.generateWithBacktracking();break;case"prims":this.generateWithPrims();break;default:throw new Error(`Unknown maze generation method: ${e}`)}this.addOpenings(n)}generateWithBacktracking(){const e=[],n=this.randomNumber(this.rows),o=this.randomNumber(this.cols);let i={row:n,col:o};for(this.grid[n][o].visited=!0,e.push(i);e.length>0;){i=e[e.length-1];const{row:s,col:c}=i,r=this.getUnvisitedNeighbors(s,c);if(r.length>0){const l=this.randomPick(r),{row:a,col:d}=l;this.removeWall(s,c,a,d),this.grid[a][d].visited=!0,e.push(l)}else e.pop()}}generateWithPrims(){const e=[],n=(s,c)=>{const r=this.getNeighbors(s,c);for(const l of r)!this.grid[l.row][l.col].visited&&!e.some(a=>a.row===l.row&&a.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),c=e[s],{row:r,col:l}=c,a=this.getVisitedNeighbors(r,l);if(a.length>0){const d=this.randomPick(a);this.removeWall(r,l,d.row,d.col),this.grid[r][l].visited=!0,n(r,l)}e.splice(s,1)}}addOpenings(e){this.grid[e.row][e.col].walls.top=!1}randomNumber(e){return Math.floor(this.random()*e)}randomPick(e){return e[Math.floor(this.random()*e.length)]}}const _n=(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},mn=t=>t===1?2:t>=2&&t<=5?3:t>=6&&t<=11?4:t>=12&&t<=15?5:6,vn=(t,e)=>{if(!e)return console.error(`Cannot find Level ${t}'s config.`),null;const{size:n,seed:o,method:i,entry:s,exit:c}=e,r=n,l=n,a=s||{row:0,col:0},d=c||{row:r-1,col:l-1},u=new fn(r,l,i,o,s),h=mn(t),f=[];for(let w=0;w<h;w++){let p;do p={row:Math.floor(u.random()*r),col:Math.floor(u.random()*l)};while(p.row===a.row&&p.col===a.col||p.row===d.row&&p.col===d.col||!_n(u,p.row,p.col)||f.some(_=>_.row===p.row&&_.col===p.col));f.push(p)}return{isGameActive:!0,levelTransitioning:!1,maze:u,playerCell:a,exitCell:d,foodCells:f,playerAtExit:!1,foodCollected:0,totalFoodCount:h,showClue:!1,playerPath:[a],visitCounts:{[`${a.row},${a.col}`]:1}}};function gn(){const{setGamePlayState:t,gamePlayStateRef:e,gameProgress:n,config:o}=q(),i=D(null),s=D(null),c=D(null),{i18n:r,levelConfig:l,renderConfig:a}=o,d=X(l),u=D(d.getLevelConfig(n.currentLevel));x(()=>{i.current&&R.attachTo(i.current)},[]);const h=D(),f=Jt(c,()=>{h.current?.()}),w=Zt(c);x(()=>{u.current=d.getLevelConfig(n.currentLevel)},[n.currentLevel]);const p=()=>{const y=vn(n.currentLevel,u.current);y&&t(C=>({...C,...y}))};x(()=>{p()},[n.currentLevel]);const _=()=>{p()},{updatePlayerPos:v,resetMovingState:m}=Qt({containerRef:s,gamePlayStateRef:e,setGamePlayState:t,playerRadius:a.playerRadius,moveSpeed:a.gridMoveSpeed,exitWallWidth:u.current?.exitWallWidth||a?.exitWallWidth,getCellSizeInPixels:()=>w.current.cellWidth,onFoodCollected:()=>{const y=e.current.totalFoodCount-e.current.foodCollected-1;y>0?R.show(r.foodCollectedToast.replace("%NUM%",y.toString()),"success",3e3):R.show(r.allFoodCollectedToast,"success")}});return x(()=>{m()},[n.currentLevel,m]),x(()=>{let y,C=!document.hidden;const k=()=>{const z=c.current?.getContext("2d"),b=e.current;if(!(C&&b?.isGameActive&&z&&b?.maze)){y=requestAnimationFrame(k);return}v(),T(),y=requestAnimationFrame(k)},T=()=>{const z=c.current?.getContext("2d"),b=e.current;if(z&&b?.maze){const M=u.current?.wallWidth||a?.wallWidth,N=u.current?.exitColor||a?.exitColor,P=u.current?.exitWallWidth||a?.exitWallWidth,I=u.current?.exitDashArray||a?.exitDashArray;nn(z,b,f.current,w.current,{...a,wallWidth:M,exitColor:N,exitWallWidth:P,exitDashArray:I})}};h.current=T;const S=z=>{const b=C;C=!document.hidden&&document.visibilityState==="visible"&&(!z||z.type!=="blur"),!b&&C?e.current?.levelTransitioning===!1&&t({...e.current,isGameActive:!0}):b&&!C&&t({...e.current,isGameActive:!1})};return document.addEventListener("visibilitychange",S),window.addEventListener("blur",S),window.addEventListener("focus",S),y=requestAnimationFrame(k),()=>{cancelAnimationFrame(y),document.removeEventListener("visibilitychange",S),window.removeEventListener("blur",S),window.removeEventListener("focus",S)}},[]),x(()=>{R.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:c,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 rt=[[{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"}]],ue={lcPrefix:"maze-",i18n:{reset:"Reset",resetTip:"Reset all game data and highest score.",confirmReset:"Confirm Reset",confirmResetMessage:"Are you sure you want to reset the game? All progress will be lost.",cancel:"Cancel",close:"Close",confirm:"Confirm",resetDoneToast:"Game reset! Starting from Level 1...",confirmClue:"Confirm to turn on clue?",confirmClueMessage:"Are you sure you want to turn on clue? Your will lose 1 ★.",level:"Level",tier:"Tier",settings:"Settings",clueOn:"Clue: ON",clueOff:"Clue: OFF",foodCollectedToast:"Food collected! %NUM% remaining.",allFoodCollectedToast:"All food collected! Head to the exit.",congratulations:"Congratulations!",findYourExit:"Find your exit!",withoutClue:"Without clue!",withClue:"You used the clue!",collectAllStars:"Collect all stars!",notCollectAllStars:"Not collect all stars.",nextLevel:"Next Level ➤",retry:"Retry",levelComplete:"Level Complete",starsCollected:"Stars Collected",avgStarPerLevel:"Avg. Stars per Level",levelCompleteToast:"Level completed! 🎉",tierUnlockedToast:"Tier %TIER% unlocked! 🎉",levelGoToast:"Level %LEVEL% - Go!",levelRestartToast:"Level restarted",allLevelsCompleted:"You completed all levels!",continueMessage:"You haven't collected all stars. You can click 'Continue' button to collect all stars.",continue:"Continue",cluePathEnabled:"Clue Path Enabled",cluePathDisabled:"Clue Path Disabled",useArrowKeyTips:"Use arrow keys to navigate the maze. Press'C' to toggle path clue."},renderConfig:{gridMoveSpeed:.03,padding:10,wallWidth:2,wallColor:"#000000",foodColor:"#4CAF50",clueColor:"rgb(255,0,0)",backgroundColor:"#ffffff",playerColor:"#4CAF50",playerRadius:.2,exitColor:"#F44336",exitWallWidth:4,exitDashArray:[8,12]},levelConfig:rt};function pn({config:t={}}){const e={...ue.i18n,...t.i18n||{}},n={...ue.renderConfig,...t.renderConfig||{}},o=t.levelConfig||rt,i={...ue,...t,i18n:e,levelConfig:o,renderConfig:n};return g(yt,{config:i,children:g(gn,{})})}const Cn={root:"https://unpkg.com/@roudanio/maze@0.1.2/dist/",...ue};return`${JSON.stringify(Cn,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 Z,L,ke,U,Te,ze,Se,Le,de,he,fe,Ne,V={},Ae=[],st=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,Q=Array.isArray;function O(t,e){for(var n in e)t[n]=e[n];return t}function _e(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function lt(t,e,n){var o,i,s,c={};for(s in e)s=="key"?o=e[s]:s=="ref"?i=e[s]:c[s]=e[s];if(arguments.length>2&&(c.children=arguments.length>3?Z.call(arguments,2):n),typeof t=="function"&&t.defaultProps!=null)for(s in t.defaultProps)c[s]==null&&(c[s]=t.defaultProps[s]);return ee(t,c,o,i,null)}function ee(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??++ke,__i:-1,__u:0};return i==null&&L.vnode!=null&&L.vnode(s),s}function te(t){return t.children}function ne(t,e){this.props=t,this.context=e}function W(t,e){if(e==null)return t.__?W(t.__,t.__i+1):null;for(var n;e<t.__k.length;e++)if((n=t.__k[e])!=null&&n.__e!=null)return n.__e;return typeof t.type=="function"?W(t):null}function Ee(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 Ee(t)}}function me(t){(!t.__d&&(t.__d=!0)&&U.push(t)&&!oe.__r++||Te!=L.debounceRendering)&&((Te=L.debounceRendering)||ze)(oe)}function oe(){for(var t,e,n,o,i,s,c,r=1;U.length;)U.length>r&&U.sort(Se),t=U.shift(),r=U.length,t.__d&&(n=void 0,i=(o=(e=t).__v).__e,s=[],c=[],e.__P&&((n=O({},o)).__v=o.__v+1,L.vnode&&L.vnode(n),ve(e.__P,n,o,e.__n,e.__P.namespaceURI,32&o.__u?[i]:null,s,i??W(o),!!(32&o.__u),c),n.__v=o.__v,n.__.__k[n.__i]=n,De(s,n,c),n.__e!=i&&Ee(n)));oe.__r=0}function Me(t,e,n,o,i,s,c,r,l,a,d){var u,h,f,C,p,_,v=o&&o.__k||Ae,m=e.length;for(l=at(n,e,v,l,m),u=0;u<m;u++)(f=n.__k[u])!=null&&(h=f.__i==-1?V:v[f.__i]||V,f.__i=u,_=ve(t,f,h,i,s,c,r,l,a,d),C=f.__e,f.ref&&h.ref!=f.ref&&(h.ref&&ge(h.ref,null,f),d.push(f.ref,f.__c||C,f)),p==null&&C!=null&&(p=C),4&f.__u||h.__k===f.__k?l=Pe(f,l,t):typeof f.type=="function"&&_!==void 0?l=_:C&&(l=C.nextSibling),f.__u&=-7);return n.__e=p,l}function at(t,e,n,o,i){var s,c,r,l,a,d=n.length,u=d,h=0;for(t.__k=new Array(i),s=0;s<i;s++)(c=e[s])!=null&&typeof c!="boolean"&&typeof c!="function"?(l=s+h,(c=t.__k[s]=typeof c=="string"||typeof c=="number"||typeof c=="bigint"||c.constructor==String?ee(null,c,null,null,null):Q(c)?ee(te,{children:c},null,null,null):c.constructor==null&&c.__b>0?ee(c.type,c.props,c.key,c.ref?c.ref:null,c.__v):c).__=t,c.__b=t.__b+1,r=null,(a=c.__i=ct(c,n,l,u))!=-1&&(u--,(r=n[a])&&(r.__u|=2)),r==null||r.__v==null?(a==-1&&(i>d?h--:i<d&&h++),typeof c.type!="function"&&(c.__u|=4)):a!=l&&(a==l-1?h--:a==l+1?h++:(a>l?h--:h++,c.__u|=4))):t.__k[s]=null;if(u)for(s=0;s<d;s++)(r=n[s])!=null&&(2&r.__u)==0&&(r.__e==o&&(o=W(r)),Re(r,r));return o}function Pe(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=Pe(o[i],e,n));return e}t.__e!=e&&(e&&t.type&&!n.contains(e)&&(e=W(t)),n.insertBefore(t.__e,e||null),e=t.__e);do e=e&&e.nextSibling;while(e!=null&&e.nodeType==8);return e}function ct(t,e,n,o){var i,s,c=t.key,r=t.type,l=e[n];if(l===null&&t.key==null||l&&c==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&&c==l.key&&r==l.type)return i;i--}if(s<e.length){if((l=e[s])&&(2&l.__u)==0&&c==l.key&&r==l.type)return s;s++}}return-1}function Ie(t,e,n){e[0]=="-"?t.setProperty(e,n??""):t[e]=n==null?"":typeof n!="number"||st.test(e)?n:n+"px"}function re(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||Ie(t.style,e,"");if(n)for(e in n)o&&n[e]==o[e]||Ie(t.style,e,n[e])}else if(e[0]=="o"&&e[1]=="n")s=e!=(e=e.replace(Le,"$1")),e=e.toLowerCase()in t||e=="onFocusOut"||e=="onFocusIn"?e.toLowerCase().slice(2):e.slice(2),t.l||(t.l={}),t.l[e+s]=n,n?o?n.u=o.u:(n.u=de,t.addEventListener(e,s?fe:he,s)):t.removeEventListener(e,s?fe:he,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 xe(t){return function(e){if(this.l){var n=this.l[e.type+t];if(e.t==null)e.t=de++;else if(e.t<n.u)return;return n(L.event?L.event(e):e)}}}function ve(t,e,n,o,i,s,c,r,l,a){var d,u,h,f,C,p,_,v,m,y,w,k,T,S,z,b,M,N=e.type;if(e.constructor!=null)return null;128&n.__u&&(l=!!(32&n.__u),s=[r=e.__e=n.__e]),(d=L.__b)&&d(e);e:if(typeof N=="function")try{if(v=e.props,m="prototype"in N&&N.prototype.render,y=(d=N.contextType)&&o[d.__c],w=d?y?y.props.value:d.__:o,n.__c?_=(u=e.__c=n.__c).__=u.__E:(m?e.__c=u=new N(v,w):(e.__c=u=new ne(v,w),u.constructor=N,u.render=dt),y&&y.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=O({},u.__s)),O(u.__s,N.getDerivedStateFromProps(v,u.__s))),f=u.props,C=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)}),k=0;k<u._sb.length;k++)u.__h.push(u._sb[k]);u._sb=[],u.__h.length&&c.push(u);break e}u.componentWillUpdate!=null&&u.componentWillUpdate(v,u.__s,w),m&&u.componentDidUpdate!=null&&u.__h.push(function(){u.componentDidUpdate(f,C,p)})}if(u.context=w,u.props=v,u.__P=t,u.__e=!1,T=L.__r,S=0,m){for(u.state=u.__s,u.__d=!1,T&&T(e),d=u.render(u.props,u.state,u.context),z=0;z<u._sb.length;z++)u.__h.push(u._sb[z]);u._sb=[]}else do u.__d=!1,T&&T(e),d=u.render(u.props,u.state,u.context),u.state=u.__s;while(u.__d&&++S<25);u.state=u.__s,u.getChildContext!=null&&(o=O(O({},o),u.getChildContext())),m&&!h&&u.getSnapshotBeforeUpdate!=null&&(p=u.getSnapshotBeforeUpdate(f,C)),b=d,d!=null&&d.type===te&&d.key==null&&(b=Fe(d.props.children)),r=Me(t,Q(b)?b:[b],e,n,o,i,s,c,r,l,a),u.base=e.__e,e.__u&=-161,u.__h.length&&c.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(M=s.length;M--;)_e(s[M]);else e.__e=n.__e,e.__k=n.__k;L.__e(P,e,n)}else s==null&&e.__v==n.__v?(e.__k=n.__k,e.__e=n.__e):r=e.__e=ut(n.__e,e,n,o,i,s,c,l,a);return(d=L.diffed)&&d(e),128&e.__u?void 0:r}function De(t,e,n){for(var o=0;o<n.length;o++)ge(n[o],n[++o],n[++o]);L.__c&&L.__c(e,t),t.some(function(i){try{t=i.__h,i.__h=[],t.some(function(s){s.call(i)})}catch(s){L.__e(s,i.__v)}})}function Fe(t){return typeof t!="object"||t==null||t.__b&&t.__b>0?t:Q(t)?t.map(Fe):O({},t)}function ut(t,e,n,o,i,s,c,r,l){var a,d,u,h,f,C,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(a=0;a<s.length;a++)if((f=s[a])&&"setAttribute"in f==!!m&&(m?f.localName==m:f.nodeType==3)){t=f,s[a]=null;break}}if(t==null){if(m==null)return document.createTextNode(v);t=document.createElementNS(i,m,v.is&&v),r&&(L.__m&&L.__m(e,s),r=!1),s=null}if(m==null)_===v||r&&t.data==v||(t.data=v);else{if(s=s&&Z.call(t.childNodes),_=n.props||V,!r&&s!=null)for(_={},a=0;a<t.attributes.length;a++)_[(f=t.attributes[a]).name]=f.value;for(a in _)if(f=_[a],a!="children"){if(a=="dangerouslySetInnerHTML")u=f;else if(!(a in v)){if(a=="value"&&"defaultValue"in v||a=="checked"&&"defaultChecked"in v)continue;re(t,a,null,f,i)}}for(a in v)f=v[a],a=="children"?h=f:a=="dangerouslySetInnerHTML"?d=f:a=="value"?C=f:a=="checked"?p=f:r&&typeof f!="function"||_[a]===f||re(t,a,f,_[a],i);if(d)r||u&&(d.__html==u.__html||d.__html==t.innerHTML)||(t.innerHTML=d.__html),e.__k=[];else if(u&&(t.innerHTML=""),Me(e.type=="template"?t.content:t,Q(h)?h:[h],e,n,o,m=="foreignObject"?"http://www.w3.org/1999/xhtml":i,s,c,s?s[0]:n.__k&&W(n,0),r,l),s!=null)for(a=s.length;a--;)_e(s[a]);r||(a="value",m=="progress"&&C==null?t.removeAttribute("value"):C!=null&&(C!==t[a]||m=="progress"&&!C||m=="option"&&C!=_[a])&&re(t,a,C,_[a],i),a="checked",p!=null&&p!=t[a]&&re(t,a,p,_[a],i))}return t}function ge(t,e,n){try{if(typeof t=="function"){var o=typeof t.__u=="function";o&&t.__u(),o&&e==null||(t.__u=t(e))}else t.current=e}catch(i){L.__e(i,n)}}function Re(t,e,n){var o,i;if(L.unmount&&L.unmount(t),(o=t.ref)&&(o.current&&o.current!=t.__e||ge(o,null,e)),(o=t.__c)!=null){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(s){L.__e(s,e)}o.base=o.__P=null}if(o=t.__k)for(i=0;i<o.length;i++)o[i]&&Re(o[i],e,n||typeof t.type!="function");n||_e(t.__e),t.__c=t.__=t.__e=void 0}function dt(t,e,n){return this.constructor(t,n)}function ht(t,e,n){var o,i,s,c;e==document&&(e=document.documentElement),L.__&&L.__(t,e),i=(o=!1)?null:e.__k,s=[],c=[],ve(e,t=e.__k=lt(te,null,[t]),i||V,V,e.namespaceURI,i?null:e.firstChild?Z.call(e.childNodes):null,s,i?i.__e:e.firstChild,o,c),De(s,t,c)}function ft(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(c){c.__e=!0,me(c)})},this.sub=function(s){o.add(s);var c=s.componentWillUnmount;s.componentWillUnmount=function(){o&&o.delete(s),c&&c.call(s)}}),n.children}return e.__c="__cC"+Ne++,e.__=t,e.Provider=e.__l=(e.Consumer=function(n,o){return n.children(o)}).contextType=e,e}Z=Ae.slice,L={__e:function(t,e,n,o){for(var i,s,c;e=e.__;)if((i=e.__c)&&!i.__)try{if((s=i.constructor)&&s.getDerivedStateFromError!=null&&(i.setState(s.getDerivedStateFromError(t)),c=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(t,o||{}),c=i.__d),c)return i.__E=i}catch(r){t=r}throw t}},ke=0,ne.prototype.setState=function(t,e){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=O({},this.state),typeof t=="function"&&(t=t(O({},n),this.props)),t&&O(n,t),t!=null&&this.__v&&(e&&this._sb.push(e),me(this))},ne.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),me(this))},ne.prototype.render=te,U=[],ze=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,Se=function(t,e){return t.__v.__b-e.__v.__b},oe.__r=0,Le=/(PointerCapture)$|Capture$/i,de=0,he=xe(!1),fe=xe(!0),Ne=0;var _t=0;function g(t,e,n,o,i,s){e||(e={});var c,r,l=e;if("ref"in l)for(r in l={},e)r=="ref"?c=e[r]:l[r]=e[r];var a={type:t,props:l,key:n,ref:c,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--_t,__i:-1,__u:0,__source:i,__self:s};if(typeof t=="function"&&(c=t.defaultProps))for(r in c)l[r]===void 0&&(l[r]=c[r]);return L.vnode&&L.vnode(a),a}var j,A,pe,Oe,Y=0,$e=[],E=L,Ue=E.__b,We=E.__r,je=E.diffed,Ge=E.__c,He=E.unmount,qe=E.__;function ie(t,e){E.__h&&E.__h(A,t,Y||e),Y=0;var n=A.__H||(A.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function G(t){return Y=1,mt(Ye,t)}function mt(t,e,n){var o=ie(j++,2);if(o.t=t,!o.__c&&(o.__=[Ye(void 0,e),function(r){var l=o.__N?o.__N[0]:o.__[0],a=o.t(l,r);l!==a&&(o.__N=[a,o.__[1]],o.__c.setState({}))}],o.__c=A,!A.__f)){var i=function(r,l,a){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,a);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,a)||u};A.__f=!0;var s=A.shouldComponentUpdate,c=A.componentWillUpdate;A.componentWillUpdate=function(r,l,a){if(this.__e){var d=s;s=void 0,i(r,l,a),s=d}c&&c.call(this,r,l,a)},A.shouldComponentUpdate=i}return o.__N||o.__}function x(t,e){var n=ie(j++,3);!E.__s&&Ve(n.__H,e)&&(n.__=t,n.u=e,A.__H.__h.push(n))}function D(t){return Y=5,H(function(){return{current:t}},[])}function H(t,e){var n=ie(j++,7);return Ve(n.__H,e)&&(n.__=t(),n.__H=e,n.__h=t),n.__}function vt(t,e){return Y=8,H(function(){return t},e)}function gt(t){var e=A.context[t.__c],n=ie(j++,9);return n.c=t,e?(n.__==null&&(n.__=!0,e.sub(A)),e.props.value):t.__}function pt(){for(var t;t=$e.shift();)if(t.__P&&t.__H)try{t.__H.__h.forEach(se),t.__H.__h.forEach(we),t.__H.__h=[]}catch(e){t.__H.__h=[],E.__e(e,t.__v)}}E.__b=function(t){A=null,Ue&&Ue(t)},E.__=function(t,e){t&&e.__k&&e.__k.__m&&(t.__m=e.__k.__m),qe&&qe(t,e)},E.__r=function(t){We&&We(t),j=0;var e=(A=t.__c).__H;e&&(pe===A?(e.__h=[],A.__h=[],e.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(e.__h.forEach(se),e.__h.forEach(we),e.__h=[],j=0)),pe=A},E.diffed=function(t){je&&je(t);var e=t.__c;e&&e.__H&&(e.__H.__h.length&&($e.push(e)!==1&&Oe===E.requestAnimationFrame||((Oe=E.requestAnimationFrame)||wt)(pt)),e.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),pe=A=null},E.__c=function(t,e){e.some(function(n){try{n.__h.forEach(se),n.__h=n.__h.filter(function(o){return!o.__||we(o)})}catch(o){e.some(function(i){i.__h&&(i.__h=[])}),e=[],E.__e(o,n.__v)}}),Ge&&Ge(t,e)},E.unmount=function(t){He&&He(t);var e,n=t.__c;n&&n.__H&&(n.__H.__.forEach(function(o){try{se(o)}catch(i){e=i}}),n.__H=void 0,e&&E.__e(e,n.__v))};var Be=typeof requestAnimationFrame=="function";function wt(t){var e,n=function(){clearTimeout(o),Be&&cancelAnimationFrame(e),setTimeout(t)},o=setTimeout(n,100);Be&&(e=requestAnimationFrame(n))}function se(t){var e=A,n=t.__c;typeof n=="function"&&(t.__c=void 0,n()),A=e}function we(t){var e=A;t.__c=t.__(),A=e}function Ve(t,e){return!t||t.length!==e.length||e.some(function(n,o){return n!==t[o]})}function Ye(t,e){return typeof e=="function"?e(t):e}const Ct=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)}}}),Xe=ft(void 0),Ke={currentLevel:1,highestUnlockedLevel:1,currentTier:1,highestUnlockedTier:1,levelScores:{},totalScore:0},Je={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=Ct(e.lcPrefix+"progress"),o=n.loadGameData(),[i,s]=G(()=>o||{...Ke});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[c,r]=G({...Je}),l=D(c);x(()=>{l.current=c},[c]);const a=H(()=>[c.playerAtExit?1:0,c.foodCollected===c.totalFoodCount?1:0,c.showClue?0:1],[c.playerAtExit,c.foodCollected,c.totalFoodCount,c.showClue]),d=()=>{n.resetGameData(),s({...Ke}),r({...Je})};return g(Xe.Provider,{value:{gameProgress:i,setGameProgress:s,gamePlayState:c,setGamePlayState:r,gamePlayStateRef:l,currentScore:a,config:e,resetGame:d},children:t})},q=()=>{const t=gt(Xe);if(!t)throw new Error("useGameContext must be used within a GameProvider");return t},X=t=>H(()=>{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 a=0;a<e.length;a++)if(l+=e[a],r<=l)return a+1;return 0},s=r=>r<1||r>o?0:e.slice(0,r-1).reduce((l,a)=>l+a,0)+1,c={getTotalLevels:()=>n,getTotalTiers:()=>o,getTierLevelsRange:r=>{if(r<1||r>o)return[0,0];const l=s(r),a=l+e[r-1]-1;return[l,a]},getTierByLevel:i,getFirstLevelOfTier:s,getLevelConfig:r=>{if(r<1||r>n)return null;const l=i(r),a=s(l),d=r-a;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,a=i(r),d=i(l);return{nextLevel:l,nextTier:d,isTierChange:d>a}},getCurrentTierProgress:(r,l)=>{const[a,d]=c.getTierLevelsRange(l),u=r-a+1,h=d-a+1;return{current:u,total:h}},isLastLevelInTier:r=>{const l=i(r),[,a]=c.getTierLevelsRange(l);return r===a},getPreviousLevelInfo:r=>{if(r<=1)return null;const l=r-1,a=i(r),d=i(l);return{prevLevel:l,prevTier:d,isTierChange:d<a}}};return c},[t]),bt=({onTierChange:t,disabled:e})=>{const{gameProgress:n,config:o}=q(),{i18n:i,levelConfig:s}=o,{currentTier:c,highestUnlockedTier:r}=n,a=X(s).getTotalTiers();return g("div",{className:"tier-selector",children:g("select",{value:c,onChange:d=>{d.target&&d.target.value&&t(Number(d.target.value))},disabled:e,className:"tier-dropdown",children:Array.from({length:a},(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:c,levelScores:r,currentLevel:l,highestUnlockedLevel:a}=n,d=X(s),u=H(()=>{const[h,f]=d.getTierLevelsRange(c);return Array.from({length:f-h+1},(C,p)=>{const _=h+p,v=r[_]||0;return{level:_,score:v}})},[c,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>a,children:`${i.level} ${h} ${"★".repeat(f)}`},`level-${h}`))})})},le=({isOpen:t,title:e,className:n="",message:o,children:i,noConfirm:s=!1,noCancel:c=!1,confirmText:r="OK",cancelText:l="Cancel",onConfirm:a,onCancel:d})=>{const u=D(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})}),(!c||!s)&&g("div",{className:"maze-dialog-buttons",children:[!c&&g("button",{type:"button",className:"maze-dialog-cancel",onClick:d,children:l}),!s&&g("button",{type:"button",className:"maze-dialog-confirm",onClick:a,children:r})]})]})})},R={container:null,attachTo(t){return this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this.container=document.createElement("div"),this.container.className="toast-container position-top",t.appendChild(this.container),this.container},currentToast:null,currentTimer:null,show(t,e="info",n=2e3){if(!this.container){console.warn("NativeToast: container not initialized, please call attachTo first");return}this.currentToast&&this.container.contains(this.currentToast)&&(this.container.removeChild(this.currentToast),this.currentToast=null),this.currentTimer&&(clearTimeout(this.currentTimer),this.currentTimer=null);const o=document.createElement("div");o.className=`toast-message type-${e} toast-visible`,o.textContent=t,this.container.appendChild(o),this.currentToast=o,this.currentTimer=setTimeout(()=>{o.classList.remove("toast-visible"),setTimeout(()=>{this.container&&this.container.contains(o)&&(this.container.removeChild(o),this.currentToast===o&&(this.currentToast=null))},300),this.currentTimer=null},n)},clearAll(){if(this.container)for(;this.container.firstChild;)this.container.removeChild(this.container.firstChild)}},Tt=()=>{const{gameProgress:t,setGameProgress:e,gamePlayState:n,setGamePlayState:o,gamePlayStateRef:i,resetGame:s,config:c}=q(),{i18n:r,levelConfig:l}=c,a=X(l),{levelTransitioning:d,showClue:u}=n,{highestUnlockedLevel:h,totalScore:f}=t,C=a.getTotalLevels(),[p,_]=G(!1),[v,m]=G(!1),[y,w]=G(!1),k=$=>{const J=a.getFirstLevelOfTier($);a.isLevelUnlocked(J,h)&&(e(B=>({...B,currentTier:$})),T(J))},T=$=>{a.isLevelUnlocked($,h)&&(e(J=>({...J,currentLevel:$})),R.show(r.levelGoToast.replace("%LEVEL%",$.toString()),"success"))},S=()=>{_(!0)},z=()=>{_(!1)},b=()=>{w(!0)},M=()=>{w(!1)},N=()=>{R.show(u?r.cluePathDisabled:r.cluePathEnabled),o(()=>({...i.current,showClue:!i.current.showClue})),w(!1)},P=()=>{m(!0)},I=()=>{s(),m(!1),R.show(r.resetDoneToast)},K=()=>{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:k,disabled:d}),g(kt,{onLevelChange:T,disabled:d})]}),g("button",{className:`settings-clue-button ${u?"clue-on":"clue-off"}`,disabled:u,title:"Toggle Clue",onClick:b,children:u?r.clueOn:r.clueOff})]}),g("div",{className:"game-settings",children:g("span",{className:"game-settings-icon",onClick:S,children:"★ "+f})}),g(le,{isOpen:p,title:r.settings,noConfirm:!0,cancelText:r.close,onCancel:z,children:[g("div",{className:"settings-stats",children:[g("div",{children:r.levelComplete+`: ${h}/${C}`}),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(le,{isOpen:v,title:r.confirmReset,message:r.confirmResetMessage,confirmText:r.reset,cancelText:r.cancel,onConfirm:I,onCancel:K}),g(le,{isOpen:y,title:r.confirmClue,message:r.confirmClueMessage,confirmText:r.confirm,cancelText:r.cancel,onConfirm:N,onCancel:M})]})};function Ce(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function zt(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 ye(t,e,n){return e&&zt(t.prototype,e),t}function Ze(t){return+t.replace(/px/,"")}function St(t){var e=window.devicePixelRatio,n=getComputedStyle(t),o=Ze(n.getPropertyValue("width")),i=Ze(n.getPropertyValue("height"));t.setAttribute("width",(o*e).toString()),t.setAttribute("height",(i*e).toString())}function F(t,e){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,o=Math.random()*(e-t)+t;return Math.floor(o*Math.pow(10,n))/Math.pow(10,n)}function Qe(t){return t[F(0,t.length)]}var Lt=.00125,Nt=5e-4,At=9e-4,Et=1e-5,Mt=6,Pt=80,It=.9,xt=1.7,Dt=.2,Ft=.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 et(t){var e=1920;return Math.log(t)/Math.log(e)}var tt=function(){function t(e){Ce(this,t);var n=e.initialPosition,o=e.direction,i=e.confettiRadius,s=e.confettiColors,c=e.emojis,r=e.emojiSize,l=e.canvasWidth,a=F(It,xt,3),d=a*et(l);this.confettiSpeed={x:d,y:d},this.finalConfettiSpeedX=F(Dt,Ft,3),this.rotationSpeed=c.length?.01:F(Rt,Ot,3)*et(l),this.dragForceCoefficient=F(Nt,At,6),this.radius={x:i,y:i},this.initialRadius=i,this.rotationAngle=o==="left"?F(0,.2,3):F(-.2,0,3),this.emojiSize=r,this.emojiRotationAngle=F(0,2*Math.PI),this.radiusYUpdateDirection="down";var u=o==="left"?F(Ut,$t)*Math.PI/180:F(-15,-82)*Math.PI/180;this.absCos=Math.abs(Math.cos(u)),this.absSin=Math.abs(Math.sin(u));var h=F(-150,0),f={x:n.x+(o==="left"?-h:h)*this.absCos,y:n.y-h*this.absSin};this.currentPosition=Object.assign({},f),this.initialPosition=Object.assign({},f),this.color=c.length?null:Qe(s),this.emoji=c.length?Qe(c):null,this.createdAt=new Date().getTime(),this.direction=o}return ye(t,[{key:"draw",value:function(n){var o=this.currentPosition,i=this.radius,s=this.color,c=this.emoji,r=this.rotationAngle,l=this.emojiRotationAngle,a=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()):c&&(n.font="".concat(a,"px serif"),n.save(),n.translate(d*o.x,d*o.y),n.rotate(l),n.textAlign="center",n.fillText(c,0,0),n.restore())}},{key:"updatePosition",value:function(n,o){var i=this.confettiSpeed,s=this.dragForceCoefficient,c=this.finalConfettiSpeedX,r=this.radiusYUpdateDirection,l=this.rotationSpeed,a=this.createdAt,d=this.direction,u=o-a;if(i.x>c&&(this.confettiSpeed.x-=s*n),this.currentPosition.x+=i.x*(d==="left"?-this.absCos:this.absCos)*n,this.currentPosition.y=this.initialPosition.y-i.y*this.absSin*u+Lt*Math.pow(u,2)/2,this.rotationSpeed-=this.emoji?1e-4:Et*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 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 Bt(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,c=s===void 0?Ht:s,r=t.emojis,l=r===void 0?t.emojies||[]:r,a=t.emojiSize,d=a===void 0?Pt:a;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:c,emojis:l,emojiSize:d}}var Vt=function(){function t(e){var n=this;Ce(this,t),this.canvasContext=e,this.shapes=[],this.promise=new Promise(function(o){return n.resolvePromise=o})}return ye(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,c=n.timeDelta,r=n.currentTime;this.shapes=this.shapes.filter(function(l){return l.updatePosition(c,r),l.draw(s.canvasContext),i?l.getIsVisibleOnCanvas(o):!0})}}]),t}(),Yt=function(){function t(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Ce(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 ye(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(c){return c.processShapes({timeDelta:o,currentTime:n},i,s),s?!c.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=Bt(n),i=o.confettiRadius,s=o.confettiNumber,c=o.confettiColors,r=o.emojis,l=o.emojiSize,a=this.canvas.getBoundingClientRect(),d=a.width,u=a.height,h=u*5/7,f={x:0,y:h},C={x:d,y:h},p=new Vt(this.canvasContext),_=0;_<s/2;_++){var v=new tt({initialPosition:f,direction:"right",confettiRadius:i,confettiColors:c,confettiNumber:s,emojis:r,emojiSize:l,canvasWidth:d}),m=new tt({initialPosition:C,direction:"left",confettiRadius:i,confettiColors:c,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 Xt=new Yt,Kt=({onRetry:t})=>{const{config:e,currentScore:n,gamePlayState:o,setGamePlayState:i,gameProgress:s,setGameProgress:c}=q(),{i18n:r,levelConfig:l}=e,[a,d,u]=n,{foodCollected:h,totalFoodCount:f,playerAtExit:C,levelTransitioning:p}=o,{currentLevel:_}=s,[v,m]=G(!1);x(()=>{C&&p&&(Xt.addConfetti(),R.show(r.levelCompleteToast,"success"),m(!0))},[C,p]);const y=X(l),w=y.getTotalLevels(),k=H(()=>_>=w,[_,w]),T=()=>{m(!1),R.show(r.levelRestartToast,"info"),t?.()},S=()=>{m(!1),i(b=>({...b,isGameActive:!0,levelTransitioning:!1}))},z=()=>{m(!1);const b=y.getNextLevelInfo(_);if(!b)return;const{nextLevel:M,nextTier:N,isTierChange:P}=b;P&&R.show(r.tierUnlockedToast.replace("%TIER%",N.toString()),"success"),c(I=>({...I,currentLevel:M,currentTier:N,highestUnlockedLevel:Math.max(I.highestUnlockedLevel,M),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(le,{className:"level-complete-dialog",isOpen:v,title:r.congratulations,cancelText:r.retry,onCancel:T,noConfirm:!!d,confirmText:r.continue,onConfirm:S,children:[g("div",{className:"maze-summary-message",children:[!!a&&g("div",{children:"★ - "+r.findYourExit}),g("div",{children:u?"★ - "+r.withoutClue:"☆ - "+r.withClue}),g("div",{children:(d?"★ - "+r.collectAllStars:"☆ - "+r.notCollectAllStars)+` (${h}/${f})`})]}),k&&g("div",{className:"all-levels-completed",children:r.allLevelsCompleted}),g("div",{className:"go-next-level",children:k?"OK":g("button",{type:"button",onClick:z,children:r.nextLevel})}),!d&&g("div",{className:"not-all-stars-collected",children:r.continueMessage})]})},Jt=(t,e)=>{const n=D({canvasWidth:0,canvasHeight:0});return x(()=>{const o=()=>{const s=t.current;if(!s)return;const c=s.parentElement;if(!c)return;const r=c.clientWidth,l=window.devicePixelRatio||1;s.style.width=`${r}px`,s.style.height=`${r}px`;const a=r*l,d=r*l;s.width=a,s.height=d,n.current={canvasWidth:a,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=D({cellWidth:0,cellHeight:0});return x(()=>{const i=e.renderConfig.padding,s=()=>{const r=t.current;if(!r||!n)return;const{rows:l,cols:a}=n;if(l<=0||a<=0)return;const d=(r.width-i*2)/a,u=(r.height-i*2)/l;o.current={cellWidth:d,cellHeight:u}};s();let c=null;return t.current&&window.ResizeObserver&&(c=new ResizeObserver(s),c.observe(t.current)),()=>{t.current&&c?.disconnect()}},[t,n]),o},ae={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]},Qt=({containerRef:t,gamePlayStateRef:e,setGamePlayState:n,moveSpeed:o,playerRadius:i,exitWallWidth:s,getCellSizeInPixels:c,onFoodCollected:r})=>{const l=D(!1),a=D(new Set),d=(_,v)=>{const m=e.current;if(!m.maze)return{canMove:!1,newCell:null};const[y,w]=ae[_];if(nt(v,y,w,i,o,m.maze))return{canMove:!1,newCell:null};const{row:T,col:S}=v,z=T+y*o,b=S+w*o,M=Math.floor(T),N=Math.floor(S),P=Math.floor(z),I=Math.floor(b);return P!==M||I!==N?m.maze.isValid(P,I)?{canMove:!0,newCell:{row:P,col:I}}:{canMove:!1,newCell:null}:{canMove:!0,newCell:null}},u=()=>{const _=e.current,{row:v,col:m}=_.playerCell,y=i*2,w=_.foodCells.findIndex(S=>Math.sqrt(Math.pow(v-S.row,2)+Math.pow(m-S.col,2))<y);w!==-1&&r&&(r(),e.current={...e.current,foodCollected:e.current.foodCollected+1,foodCells:e.current.foodCells.filter((S,z)=>z!==w)});const T=tn(_.playerCell,_.exitCell,_.maze,i,s,c);T&&!e.current.playerAtExit?(e.current={...e.current,playerAtExit:!0,isGameActive:!1,levelTransitioning:!0},requestIdleCallback(()=>{n(()=>({...e.current}))},{timeout:10})):!T&&e.current.playerAtExit&&(e.current={...e.current,playerAtExit:!1,isGameActive:!0,levelTransitioning:!1})},h=_=>{const v=e.current,m=Math.round(_.row),y=Math.round(_.col),w=v.playerPath[v.playerPath.length-1],k=w.row===m&&w.col===y,T=Math.abs(w.row-m),S=Math.abs(w.col-y);if((T===1&&S===0||T===0&&S===1)&&!k){const b=`${w.row},${w.col}-${m},${y}`;e.current={...e.current,playerPath:[...e.current.playerPath,{row:m,col:y}],visitCounts:{...e.current.visitCounts,[b]:(e.current.visitCounts[b]||0)+1}}}},f=()=>{if(l.current||a.current.size===0)return;const _=e.current;!_.playerCell||!Array.from(a.current).some(m=>{const{canMove:y}=d(m,_.playerCell);return y})||(l.current=!0)};x(()=>{const _=k=>{(k.key==="ArrowUp"||k.key==="ArrowDown"||k.key==="ArrowLeft"||k.key==="ArrowRight"||k.key===" ")&&k.preventDefault()},v=k=>{const T=k.key;T in ae&&(k.preventDefault(),e.current.isGameActive&&(a.current.has(T)||(a.current.add(T),l.current||f())))},m=k=>{const T=k.key;T in ae&&(k.preventDefault(),a.current.delete(T),a.current.size===0&&p())},y=k=>{k.preventDefault();const T=e.current;if(!T.isGameActive||!T.maze||l.current)return;const S=k.touches[0],z=document.elementFromPoint(S.clientX,S.clientY);let b=null;z&&(z.classList.contains("maze-up")?b="ArrowUp":z.classList.contains("maze-down")?b="ArrowDown":z.classList.contains("maze-left")?b="ArrowLeft":z.classList.contains("maze-right")&&(b="ArrowRight")),b&&(a.current.clear(),a.current.add(b),f())},w=()=>{p()};return window.addEventListener("keydown",_,{capture:!0}),window.addEventListener("keydown",v),window.addEventListener("keyup",m),t.current?.addEventListener("touchstart",y,{passive:!1}),t.current?.addEventListener("touchend",w),()=>{window.removeEventListener("keydown",_,{capture:!0}),window.removeEventListener("keydown",v),window.removeEventListener("keyup",m),t.current?.removeEventListener("touchstart",y),t.current?.removeEventListener("touchend",w)}},[]);const C=vt(()=>{if(!l.current||a.current.size===0)return e.current.playerCell;const _=e.current.playerCell;let v=0,m=0,y=0;for(const B of a.current){const{canMove:be}=d(B,_);if(be){const[it,Cn]=ae[B];v+=it,m+=Cn,y++}}if(y===0)return e.current.playerCell;const w=Math.sqrt(v*v+m*m),k=w>0?v/w:0,T=w>0?m/w:0,S=Number((_.row+k*o).toFixed(2)),z=Number((_.col+T*o).toFixed(2)),b=S-_.row,M=z-_.col,N=Math.sqrt(b*b+M*M);if(N>0){const B=b/N,be=M/N;if(nt(_,B,be,i,N,e.current.maze))return e.current.playerCell}e.current.playerCell={row:S,col:z},u();const P=Math.round(_.row),I=Math.round(_.col),K=Math.round(S),$=Math.round(z);return(K!==P||$!==I)&&h({row:K,col:$}),e.current.playerCell},[o]),p=()=>{l.current=!1,a.current.clear()};return{updatePlayerPos:C,resetMovingState:p}};function nt(t,e,n,o,i,s){const c=t.row+e*i,r=t.col+n*i,l={row:c,col:r},a=[],d=Math.floor(t.row),u=Math.floor(t.col);a.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,C]of h){const p=d+f,_=u+C;s.isValid(p,_)&&a.push({row:p,col:_})}for(const f of a){const C=en(f.row,f.col,s);for(const p of C)if(ot(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 ot(t,e){const{start:n,end:o}=e,i=o.col-n.col,s=o.row-n.row,c=t.col-n.col,r=t.row-n.row,l=i*i+s*s;if(l===0)return Math.sqrt(c*c+r*r);const a=Math.max(0,Math.min(1,(c*i+r*s)/l)),d=n.col+a*i,u=n.row+a*s,h=t.col-d,f=t.row-u;return Math.sqrt(h*h+f*f)}function tn(t,e,n,o,i,s){if(t.row<=e.row-.5||t.row>=e.row+.5||t.col<=e.col-.5||t.col>=e.col+.5||Math.sqrt(Math.pow(t.row-e.row,2)+Math.pow(t.col-e.col,2))>1.5||!n.isValid(e.row,e.col))return!1;if(n.grid[e.row][e.col].walls.bottom){let l=0;if(s&&i){const h=s();l=i/h}else l=(i||3)/100;const a=l*.5,d={start:{row:e.row+.5-a,col:e.col-.5},end:{row:e.row+.5-a,col:e.col+.5}};if(ot(t,d)<=o*1.5)return!0}return!1}function nn(t,e,n,o,i){if(!t||!e.maze)return;const{canvasWidth:s,canvasHeight:c}=n,{cellWidth:r,cellHeight:l}=o,{maze:a,playerCell:d,exitCell:u,foodCells:h,showClue:f,playerPath:C,visitCounts:p}=e,{padding:_,wallWidth:v,wallColor:m,playerColor:y,playerRadius:w,foodColor:k,backgroundColor:T,clueColor:S,exitColor:z,exitWallWidth:b,exitDashArray:M}=i;t.clearRect(0,0,s,c),t.save(),t.fillStyle=T,t.fillRect(0,0,s,c),t.restore(),f&&cn({ctx:t,playerPath:C,visitCounts:p,cellWidth:r,cellHeight:l,padding:_,clueColor:S}),on({ctx:t,maze:a,cellWidth:r,cellHeight:l,padding:_,wallColor:m,wallWidth:v}),sn({ctx:t,maze:a,exitCell:u,cellWidth:r,cellHeight:l,padding:_,exitColor:z,exitWallWidth:b,exitDashArray:M}),ln({ctx:t,foodCells:h,cellWidth:r,cellHeight:l,padding:_,foodColor:k}),rn({ctx:t,playerCell:d,playerRadius:w,cellWidth:r,cellHeight:l,padding:_,playerColor:y})}function on({ctx:t,maze:e,cellWidth:n,cellHeight:o,padding:i,wallColor:s,wallWidth:c}){t.save(),t.strokeStyle=s,t.lineWidth=c,t.lineCap="round",t.beginPath(),un(e,n,o,i).forEach(l=>{t.moveTo(l.x1,l.y1),t.lineTo(l.x2,l.y2)}),t.stroke(),t.restore()}function rn({ctx:t,playerCell:e,playerRadius:n,cellWidth:o,cellHeight:i,padding:s,playerColor:c}){const{x:r,y:l}=ce(e.row,e.col,o,i,s),a=Math.min(o,i)*Math.min(n,.5);t.save(),t.fillStyle=c,t.beginPath(),t.arc(r,l,a,0,Math.PI*2),t.fill(),t.restore()}function sn({ctx:t,maze:e,exitCell:n,cellWidth:o,cellHeight:i,padding:s,exitColor:c,exitWallWidth:r,exitDashArray:l=[8,12]}){const{row:a,col:d}=n;if(!e.isValid(a,d))return;const u=e.grid[a][d],h=s+d*o,f=s+a*i;t.save(),t.globalCompositeOperation="destination-out",t.lineWidth=r,t.lineCap="round",t.beginPath(),u.walls.bottom&&(t.moveTo(h,f+i),t.lineTo(h+o,f+i)),t.stroke(),t.globalCompositeOperation="source-over",t.strokeStyle=c,t.lineWidth=r,t.setLineDash(l),t.beginPath(),u.walls.bottom&&(t.moveTo(h,f+i),t.lineTo(h+o,f+i)),t.stroke(),t.restore()}function ln({ctx:t,foodCells:e,cellWidth:n,cellHeight:o,padding:i,foodColor:s}){t.fillStyle=s;const c=Math.min(n,o)*.25;e.forEach(r=>{const{x:l,y:a}=ce(r.row,r.col,n,o,i);an(t,l,a,c*1.2,5,c*.6)})}function an(t,e,n,o,i,s){t.save(),t.beginPath();for(let c=0;c<i*2;c++){const r=c%2===0?o:s,l=Math.PI*c/i;t.lineTo(e+r*Math.sin(l),n+r*Math.cos(l))}t.closePath(),t.fill(),t.restore()}function cn({ctx:t,playerPath:e,visitCounts:n,cellWidth:o,cellHeight:i,padding:s,clueColor:c}){if(!(!e||e.length<2||!n)){t.save();for(let r=1;r<e.length;r++){const l=e[r-1],a=e[r],d=`${l.row},${l.col}-${a.row},${a.col}`,u=`${a.row},${a.col}-${l.row},${l.col}`,h=(n[d]||0)+(n[u]||0),f=Math.min(.2+h*.1,.9),C=Math.max(3,o*.1)+h*.5;try{t.strokeStyle=c.replace(")",`, ${f})`).replace("rgb(","rgba(")}catch{t.strokeStyle=`rgba(255, 0, 0, ${f})`}t.lineWidth=C,t.lineCap="round",t.lineJoin="round";const{x:p,y:_}=ce(l.row,l.col,o,i,s),{x:v,y:m}=ce(a.row,a.col,o,i,s);t.beginPath(),t.moveTo(p,_),t.lineTo(v,m),t.stroke()}t.restore()}}function un(t,e,n,o){const i=[];for(let s=0;s<t.rows;s++)for(let c=0;c<t.cols;c++){const r=t.grid[s][c],l=o+c*e,a=o+s*n;r.walls.top&&i.push({x1:l,y1:a,x2:l+e,y2:a}),r.walls.right&&i.push({x1:l+e,y1:a,x2:l+e,y2:a+n}),r.walls.bottom&&i.push({x1:l,y1:a+n,x2:l+e,y2:a+n}),r.walls.left&&i.push({x1:l,y1:a,x2:l,y2:a+n})}return i}function ce(t,e,n,o,i){return{x:i+e*n+n/2,y:i+t*o+o/2}}function dn(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 hn{constructor(e,n){this.row=e,this.col=n}visited=!1;walls={top:!0,right:!0,bottom:!0,left:!0}}class fn{rows;cols;grid;seed;random;constructor(e,n,o,i,s={row:0,col:0}){this.rows=e,this.cols=n,this.seed=i??Math.floor(Math.random()*1e6),this.random=dn(this.seed),this.grid=this.initializeGrid(),this.generate(o,s)}initializeGrid(){const e=[];for(let n=0;n<this.rows;n++){e[n]=[];for(let o=0;o<this.cols;o++)e[n][o]=new hn(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 c=e+s.r,r=n+s.c;this.isValid(c,r)&&o.push({row:c,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],c=this.grid[o][i];e===o+1?(s.walls.top=!1,c.walls.bottom=!1):e===o-1?(s.walls.bottom=!1,c.walls.top=!1):n===i+1?(s.walls.left=!1,c.walls.right=!1):n===i-1&&(s.walls.right=!1,c.walls.left=!1)}generate(e,n={row:0,col:0}){switch(e){case"backtracking":this.generateWithBacktracking();break;case"prims":this.generateWithPrims();break;default:throw new Error(`Unknown maze generation method: ${e}`)}this.addOpenings(n)}generateWithBacktracking(){const e=[],n=this.randomNumber(this.rows),o=this.randomNumber(this.cols);let i={row:n,col:o};for(this.grid[n][o].visited=!0,e.push(i);e.length>0;){i=e[e.length-1];const{row:s,col:c}=i,r=this.getUnvisitedNeighbors(s,c);if(r.length>0){const l=this.randomPick(r),{row:a,col:d}=l;this.removeWall(s,c,a,d),this.grid[a][d].visited=!0,e.push(l)}else e.pop()}}generateWithPrims(){const e=[],n=(s,c)=>{const r=this.getNeighbors(s,c);for(const l of r)!this.grid[l.row][l.col].visited&&!e.some(a=>a.row===l.row&&a.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),c=e[s],{row:r,col:l}=c,a=this.getVisitedNeighbors(r,l);if(a.length>0){const d=this.randomPick(a);this.removeWall(r,l,d.row,d.col),this.grid[r][l].visited=!0,n(r,l)}e.splice(s,1)}}addOpenings(e){this.grid[e.row][e.col].walls.top=!1}randomNumber(e){return Math.floor(this.random()*e)}randomPick(e){return e[Math.floor(this.random()*e.length)]}}const _n=(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},mn=t=>t===1?2:t>=2&&t<=5?3:t>=6&&t<=11?4:t>=12&&t<=15?5:6,vn=(t,e)=>{if(!e)return console.error(`Cannot find Level ${t}'s config.`),null;const{size:n,seed:o,method:i,entry:s,exit:c}=e,r=n,l=n,a=s||{row:0,col:0},d=c||{row:r-1,col:l-1},u=new fn(r,l,i,o,s),h=mn(t),f=[];for(let C=0;C<h;C++){let p;do p={row:Math.floor(u.random()*r),col:Math.floor(u.random()*l)};while(p.row===a.row&&p.col===a.col||p.row===d.row&&p.col===d.col||!_n(u,p.row,p.col)||f.some(_=>_.row===p.row&&_.col===p.col));f.push(p)}return{isGameActive:!0,levelTransitioning:!1,maze:u,playerCell:a,exitCell:d,foodCells:f,playerAtExit:!1,foodCollected:0,totalFoodCount:h,showClue:!1,playerPath:[a],visitCounts:{[`${a.row},${a.col}`]:1}}};function gn(){const{setGamePlayState:t,gamePlayStateRef:e,gameProgress:n,config:o}=q(),i=D(null),s=D(null),c=D(null),{i18n:r,levelConfig:l,renderConfig:a}=o,d=X(l),u=D(d.getLevelConfig(n.currentLevel));x(()=>{i.current&&R.attachTo(i.current)},[]);const h=D(),f=Jt(c,()=>{h.current?.()}),C=Zt(c);x(()=>{u.current=d.getLevelConfig(n.currentLevel)},[n.currentLevel]);const p=()=>{const y=vn(n.currentLevel,u.current);y&&t(w=>({...w,...y}))};x(()=>{p()},[n.currentLevel]);const _=()=>{p()},{updatePlayerPos:v,resetMovingState:m}=Qt({containerRef:s,gamePlayStateRef:e,setGamePlayState:t,playerRadius:a.playerRadius,moveSpeed:a.gridMoveSpeed,exitWallWidth:u.current?.exitWallWidth||a?.exitWallWidth,getCellSizeInPixels:()=>C.current.cellWidth,onFoodCollected:()=>{const y=e.current.totalFoodCount-e.current.foodCollected-1;y>0?R.show(r.foodCollectedToast.replace("%NUM%",y.toString()),"success",3e3):R.show(r.allFoodCollectedToast,"success")}});return x(()=>{m()},[n.currentLevel,m]),x(()=>{let y,w=!document.hidden;const k=()=>{const z=c.current?.getContext("2d"),b=e.current;if(!(w&&b?.isGameActive&&z&&b?.maze)){y=requestAnimationFrame(k);return}v(),T(),y=requestAnimationFrame(k)},T=()=>{const z=c.current?.getContext("2d"),b=e.current;if(z&&b?.maze){const M=u.current?.wallWidth||a?.wallWidth,N=u.current?.exitColor||a?.exitColor,P=u.current?.exitWallWidth||a?.exitWallWidth,I=u.current?.exitDashArray||a?.exitDashArray;nn(z,b,f.current,C.current,{...a,wallWidth:M,exitColor:N,exitWallWidth:P,exitDashArray:I})}};h.current=T;const S=z=>{const b=w;w=!document.hidden&&document.visibilityState==="visible"&&(!z||z.type!=="blur"),!b&&w?e.current?.levelTransitioning===!1&&t({...e.current,isGameActive:!0}):b&&!w&&t({...e.current,isGameActive:!1})};return document.addEventListener("visibilitychange",S),window.addEventListener("blur",S),window.addEventListener("focus",S),y=requestAnimationFrame(k),()=>{cancelAnimationFrame(y),document.removeEventListener("visibilitychange",S),window.removeEventListener("blur",S),window.removeEventListener("focus",S)}},[]),x(()=>{R.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:c,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 rt=[[{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"}]],ue={lcPrefix:"maze-",i18n:{reset:"Reset",resetTip:"Reset all game data and highest score.",confirmReset:"Confirm Reset",confirmResetMessage:"Are you sure you want to reset the game? All progress will be lost.",cancel:"Cancel",close:"Close",confirm:"Confirm",resetDoneToast:"Game reset! Starting from Level 1...",confirmClue:"Confirm to turn on clue?",confirmClueMessage:"Are you sure you want to turn on clue? Your will lose 1 ★.",level:"Level",tier:"Tier",settings:"Settings",clueOn:"Clue: ON",clueOff:"Clue: OFF",foodCollectedToast:"Food collected! %NUM% remaining.",allFoodCollectedToast:"All food collected! Head to the exit.",congratulations:"Congratulations!",findYourExit:"Find your exit!",withoutClue:"Without clue!",withClue:"You used the clue!",collectAllStars:"Collect all stars!",notCollectAllStars:"Not collect all stars.",nextLevel:"Next Level ➤",retry:"Retry",levelComplete:"Level Complete",starsCollected:"Stars Collected",avgStarPerLevel:"Avg. Stars per Level",levelCompleteToast:"Level completed! 🎉",tierUnlockedToast:"Tier %TIER% unlocked! 🎉",levelGoToast:"Level %LEVEL% - Go!",levelRestartToast:"Level restarted",allLevelsCompleted:"You completed all levels!",continueMessage:"You haven't collected all stars. You can click 'Continue' button to collect all stars.",continue:"Continue",cluePathEnabled:"Clue Path Enabled",cluePathDisabled:"Clue Path Disabled",useArrowKeyTips:"Use arrow keys to navigate the maze. Press'C' to toggle path clue."},renderConfig:{gridMoveSpeed:.03,padding:10,wallWidth:2,wallColor:"#000000",foodColor:"#4CAF50",clueColor:"rgb(255,0,0)",backgroundColor:"#ffffff",playerColor:"#4CAF50",playerRadius:.2,exitColor:"#F44336",exitWallWidth:4,exitDashArray:[8,12]},levelConfig:rt};function pn({config:t={}}){const e={...ue.i18n,...t.i18n||{}},n={...ue.renderConfig,...t.renderConfig||{}},o=t.levelConfig||rt,i={...ue,...t,i18n:e,levelConfig:o,renderConfig:n};return g(yt,{config:i,children:g(gn,{})})}const wn={root:"https://unpkg.com/@roudanio/maze@0.1.3/dist/",...ue};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=`
2
2
  height: 30px;
3
3
  width: 100%;
4
4
  border: solid 2px #999;