@coledon/advanced-tictactoe
Version:
Advanced TicTacToe React component with AI opponents, animations, and multiple game modes. Perfect for 404 pages, hidden games, or entertainment features.
32 lines (29 loc) • 144 kB
JavaScript
(function(J,b){typeof exports=="object"&&typeof module<"u"?b(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],b):(J=typeof globalThis<"u"?globalThis:J||self,b(J.AdvancedTicTacToe={},J.React))})(this,function(J,b){"use strict";function $r(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const s=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,s.get?s:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const Xn=$r(b);var Ut={exports:{}},He={};/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var Yn;function Gr(){if(Yn)return He;Yn=1;var e=b,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,i=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function r(a,l,c){var u,f={},d=null,m=null;c!==void 0&&(d=""+c),l.key!==void 0&&(d=""+l.key),l.ref!==void 0&&(m=l.ref);for(u in l)s.call(l,u)&&!o.hasOwnProperty(u)&&(f[u]=l[u]);if(a&&a.defaultProps)for(u in l=a.defaultProps,l)f[u]===void 0&&(f[u]=l[u]);return{$$typeof:t,type:a,key:d,ref:m,props:f,_owner:i.current}}return He.Fragment=n,He.jsx=r,He.jsxs=r,He}var Xe={};/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var Kn;function zr(){return Kn||(Kn=1,process.env.NODE_ENV!=="production"&&function(){var e=b,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),s=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),o=Symbol.for("react.profiler"),r=Symbol.for("react.provider"),a=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),c=Symbol.for("react.suspense"),u=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),d=Symbol.for("react.lazy"),m=Symbol.for("react.offscreen"),g=Symbol.iterator,v="@@iterator";function S(h){if(h===null||typeof h!="object")return null;var y=g&&h[g]||h[v];return typeof y=="function"?y:null}var T=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function w(h){{for(var y=arguments.length,P=new Array(y>1?y-1:0),V=1;V<y;V++)P[V-1]=arguments[V];x("error",h,P)}}function x(h,y,P){{var V=T.ReactDebugCurrentFrame,O=V.getStackAddendum();O!==""&&(y+="%s",P=P.concat([O]));var _=P.map(function(L){return String(L)});_.unshift("Warning: "+y),Function.prototype.apply.call(console[h],console,_)}}var M=!1,j=!1,$=!1,F=!1,D=!1,C;C=Symbol.for("react.module.reference");function R(h){return!!(typeof h=="string"||typeof h=="function"||h===s||h===o||D||h===i||h===c||h===u||F||h===m||M||j||$||typeof h=="object"&&h!==null&&(h.$$typeof===d||h.$$typeof===f||h.$$typeof===r||h.$$typeof===a||h.$$typeof===l||h.$$typeof===C||h.getModuleId!==void 0))}function X(h,y,P){var V=h.displayName;if(V)return V;var O=y.displayName||y.name||"";return O!==""?P+"("+O+")":P}function k(h){return h.displayName||"Context"}function G(h){if(h==null)return null;if(typeof h.tag=="number"&&w("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof h=="function")return h.displayName||h.name||null;if(typeof h=="string")return h;switch(h){case s:return"Fragment";case n:return"Portal";case o:return"Profiler";case i:return"StrictMode";case c:return"Suspense";case u:return"SuspenseList"}if(typeof h=="object")switch(h.$$typeof){case a:var y=h;return k(y)+".Consumer";case r:var P=h;return k(P._context)+".Provider";case l:return X(h,h.render,"ForwardRef");case f:var V=h.displayName||null;return V!==null?V:G(h.type)||"Memo";case d:{var O=h,_=O._payload,L=O._init;try{return G(L(_))}catch{return null}}}return null}var N=Object.assign,B=0,I,q,le,ge,dt,W,Ae;function ht(){}ht.__reactDisabledLog=!0;function Ft(){{if(B===0){I=console.log,q=console.info,le=console.warn,ge=console.error,dt=console.group,W=console.groupCollapsed,Ae=console.groupEnd;var h={configurable:!0,enumerable:!0,value:ht,writable:!0};Object.defineProperties(console,{info:h,log:h,warn:h,error:h,group:h,groupCollapsed:h,groupEnd:h})}B++}}function It(){{if(B--,B===0){var h={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:N({},h,{value:I}),info:N({},h,{value:q}),warn:N({},h,{value:le}),error:N({},h,{value:ge}),group:N({},h,{value:dt}),groupCollapsed:N({},h,{value:W}),groupEnd:N({},h,{value:Ae})})}B<0&&w("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ye=T.ReactCurrentDispatcher,Ue;function $e(h,y,P){{if(Ue===void 0)try{throw Error()}catch(O){var V=O.stack.trim().match(/\n( *(at )?)/);Ue=V&&V[1]||""}return`
`+Ue+h}}var Le=!1,ve;{var xe=typeof WeakMap=="function"?WeakMap:Map;ve=new xe}function _n(h,y){if(!h||Le)return"";{var P=ve.get(h);if(P!==void 0)return P}var V;Le=!0;var O=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var _;_=ye.current,ye.current=null,Ft();try{if(y){var L=function(){throw Error()};if(Object.defineProperty(L.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(L,[])}catch(ie){V=ie}Reflect.construct(h,[],L)}else{try{L.call()}catch(ie){V=ie}h.call(L.prototype)}}else{try{throw Error()}catch(ie){V=ie}h()}}catch(ie){if(ie&&V&&typeof ie.stack=="string"){for(var E=ie.stack.split(`
`),te=V.stack.split(`
`),Y=E.length-1,Z=te.length-1;Y>=1&&Z>=0&&E[Y]!==te[Z];)Z--;for(;Y>=1&&Z>=0;Y--,Z--)if(E[Y]!==te[Z]){if(Y!==1||Z!==1)do if(Y--,Z--,Z<0||E[Y]!==te[Z]){var ce=`
`+E[Y].replace(" at new "," at ");return h.displayName&&ce.includes("<anonymous>")&&(ce=ce.replace("<anonymous>",h.displayName)),typeof h=="function"&&ve.set(h,ce),ce}while(Y>=1&&Z>=0);break}}}finally{Le=!1,ye.current=_,It(),Error.prepareStackTrace=O}var ze=h?h.displayName||h.name:"",Oe=ze?$e(ze):"";return typeof h=="function"&&ve.set(h,Oe),Oe}function ou(h,y,P){return _n(h,!1)}function au(h){var y=h.prototype;return!!(y&&y.isReactComponent)}function _t(h,y,P){if(h==null)return"";if(typeof h=="function")return _n(h,au(h));if(typeof h=="string")return $e(h);switch(h){case c:return $e("Suspense");case u:return $e("SuspenseList")}if(typeof h=="object")switch(h.$$typeof){case l:return ou(h.render);case f:return _t(h.type,y,P);case d:{var V=h,O=V._payload,_=V._init;try{return _t(_(O),y,P)}catch{}}}return""}var mt=Object.prototype.hasOwnProperty,kr={},Dr=T.ReactDebugCurrentFrame;function Wt(h){if(h){var y=h._owner,P=_t(h.type,h._source,y?y.type:null);Dr.setExtraStackFrame(P)}else Dr.setExtraStackFrame(null)}function lu(h,y,P,V,O){{var _=Function.call.bind(mt);for(var L in h)if(_(h,L)){var E=void 0;try{if(typeof h[L]!="function"){var te=Error((V||"React class")+": "+P+" type `"+L+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof h[L]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw te.name="Invariant Violation",te}E=h[L](y,L,V,P,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(Y){E=Y}E&&!(E instanceof Error)&&(Wt(O),w("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",V||"React class",P,L,typeof E),Wt(null)),E instanceof Error&&!(E.message in kr)&&(kr[E.message]=!0,Wt(O),w("Failed %s type: %s",P,E.message),Wt(null))}}}var cu=Array.isArray;function Wn(h){return cu(h)}function uu(h){{var y=typeof Symbol=="function"&&Symbol.toStringTag,P=y&&h[Symbol.toStringTag]||h.constructor.name||"Object";return P}}function fu(h){try{return Er(h),!1}catch{return!0}}function Er(h){return""+h}function Nr(h){if(fu(h))return w("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",uu(h)),Er(h)}var pt=T.ReactCurrentOwner,du={key:!0,ref:!0,__self:!0,__source:!0},Lr,Or,Un;Un={};function hu(h){if(mt.call(h,"ref")){var y=Object.getOwnPropertyDescriptor(h,"ref").get;if(y&&y.isReactWarning)return!1}return h.ref!==void 0}function mu(h){if(mt.call(h,"key")){var y=Object.getOwnPropertyDescriptor(h,"key").get;if(y&&y.isReactWarning)return!1}return h.key!==void 0}function pu(h,y){if(typeof h.ref=="string"&&pt.current&&y&&pt.current.stateNode!==y){var P=G(pt.current.type);Un[P]||(w('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',G(pt.current.type),h.ref),Un[P]=!0)}}function gu(h,y){{var P=function(){Lr||(Lr=!0,w("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",y))};P.isReactWarning=!0,Object.defineProperty(h,"key",{get:P,configurable:!0})}}function yu(h,y){{var P=function(){Or||(Or=!0,w("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",y))};P.isReactWarning=!0,Object.defineProperty(h,"ref",{get:P,configurable:!0})}}var vu=function(h,y,P,V,O,_,L){var E={$$typeof:t,type:h,key:y,ref:P,props:L,_owner:_};return E._store={},Object.defineProperty(E._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(E,"_self",{configurable:!1,enumerable:!1,writable:!1,value:V}),Object.defineProperty(E,"_source",{configurable:!1,enumerable:!1,writable:!1,value:O}),Object.freeze&&(Object.freeze(E.props),Object.freeze(E)),E};function xu(h,y,P,V,O){{var _,L={},E=null,te=null;P!==void 0&&(Nr(P),E=""+P),mu(y)&&(Nr(y.key),E=""+y.key),hu(y)&&(te=y.ref,pu(y,O));for(_ in y)mt.call(y,_)&&!du.hasOwnProperty(_)&&(L[_]=y[_]);if(h&&h.defaultProps){var Y=h.defaultProps;for(_ in Y)L[_]===void 0&&(L[_]=Y[_])}if(E||te){var Z=typeof h=="function"?h.displayName||h.name||"Unknown":h;E&&gu(L,Z),te&&yu(L,Z)}return vu(h,E,te,O,V,pt.current,L)}}var $n=T.ReactCurrentOwner,Rr=T.ReactDebugCurrentFrame;function Ge(h){if(h){var y=h._owner,P=_t(h.type,h._source,y?y.type:null);Rr.setExtraStackFrame(P)}else Rr.setExtraStackFrame(null)}var Gn;Gn=!1;function zn(h){return typeof h=="object"&&h!==null&&h.$$typeof===t}function Br(){{if($n.current){var h=G($n.current.type);if(h)return`
Check the render method of \``+h+"`."}return""}}function bu(h){{if(h!==void 0){var y=h.fileName.replace(/^.*[\\\/]/,""),P=h.lineNumber;return`
Check your code at `+y+":"+P+"."}return""}}var Fr={};function wu(h){{var y=Br();if(!y){var P=typeof h=="string"?h:h.displayName||h.name;P&&(y=`
Check the top-level render call using <`+P+">.")}return y}}function Ir(h,y){{if(!h._store||h._store.validated||h.key!=null)return;h._store.validated=!0;var P=wu(y);if(Fr[P])return;Fr[P]=!0;var V="";h&&h._owner&&h._owner!==$n.current&&(V=" It was passed a child from "+G(h._owner.type)+"."),Ge(h),w('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',P,V),Ge(null)}}function _r(h,y){{if(typeof h!="object")return;if(Wn(h))for(var P=0;P<h.length;P++){var V=h[P];zn(V)&&Ir(V,y)}else if(zn(h))h._store&&(h._store.validated=!0);else if(h){var O=S(h);if(typeof O=="function"&&O!==h.entries)for(var _=O.call(h),L;!(L=_.next()).done;)zn(L.value)&&Ir(L.value,y)}}}function Pu(h){{var y=h.type;if(y==null||typeof y=="string")return;var P;if(typeof y=="function")P=y.propTypes;else if(typeof y=="object"&&(y.$$typeof===l||y.$$typeof===f))P=y.propTypes;else return;if(P){var V=G(y);lu(P,h.props,"prop",V,h)}else if(y.PropTypes!==void 0&&!Gn){Gn=!0;var O=G(y);w("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",O||"Unknown")}typeof y.getDefaultProps=="function"&&!y.getDefaultProps.isReactClassApproved&&w("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Tu(h){{for(var y=Object.keys(h.props),P=0;P<y.length;P++){var V=y[P];if(V!=="children"&&V!=="key"){Ge(h),w("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",V),Ge(null);break}}h.ref!==null&&(Ge(h),w("Invalid attribute `ref` supplied to `React.Fragment`."),Ge(null))}}var Wr={};function Ur(h,y,P,V,O,_){{var L=R(h);if(!L){var E="";(h===void 0||typeof h=="object"&&h!==null&&Object.keys(h).length===0)&&(E+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var te=bu(O);te?E+=te:E+=Br();var Y;h===null?Y="null":Wn(h)?Y="array":h!==void 0&&h.$$typeof===t?(Y="<"+(G(h.type)||"Unknown")+" />",E=" Did you accidentally export a JSX literal instead of a component?"):Y=typeof h,w("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",Y,E)}var Z=xu(h,y,P,O,_);if(Z==null)return Z;if(L){var ce=y.children;if(ce!==void 0)if(V)if(Wn(ce)){for(var ze=0;ze<ce.length;ze++)_r(ce[ze],h);Object.freeze&&Object.freeze(ce)}else w("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else _r(ce,h)}if(mt.call(y,"key")){var Oe=G(h),ie=Object.keys(y).filter(function(ju){return ju!=="key"}),Hn=ie.length>0?"{key: someKey, "+ie.join(": ..., ")+": ...}":"{key: someKey}";if(!Wr[Oe+Hn]){var Vu=ie.length>0?"{"+ie.join(": ..., ")+": ...}":"{}";w(`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`,Hn,Oe,Vu,Oe),Wr[Oe+Hn]=!0}}return h===s?Tu(Z):Pu(Z),Z}}function Su(h,y,P){return Ur(h,y,P,!0)}function Cu(h,y,P){return Ur(h,y,P,!1)}var Mu=Cu,Au=Su;Xe.Fragment=s,Xe.jsx=Mu,Xe.jsxs=Au}()),Xe}process.env.NODE_ENV==="production"?Ut.exports=Gr():Ut.exports=zr();var p=Ut.exports;const Ye={theme:"dark",soundEnabled:!0,musicEnabled:!1,animationsEnabled:!0,difficulty:"medium",boardSize:3,timeLimit:void 0,firstMoveAdvantage:!1,showMoveHints:!1},Hr={MIN_BOARD_SIZE:3,MAX_BOARD_SIZE:5,MIN_PLAYERS:2,MAX_PLAYERS:2,WIN_CONDITION_LENGTH:{3:3,4:4,5:4},MAX_MOVES:{3:9,4:16,5:25}};class $t{constructor(t=3){this.boardSize=t,this.winLength=Hr.WIN_CONDITION_LENGTH[t]}createEmptyBoard(){return Array(this.boardSize).fill(null).map(()=>Array(this.boardSize).fill(null))}isValidPosition(t){const{row:n,col:s}=t;return n>=0&&n<this.boardSize&&s>=0&&s<this.boardSize}isValidMove(t,n){if(!this.isValidPosition(n))return!1;const{row:s,col:i}=n;return t[s][i]===null}makeMove(t,n,s){if(!this.isValidMove(t,n))throw new Error("Invalid move");const i=t.map(o=>[...o]);return i[n.row][n.col]=s,i}isBoardFull(t){return t.every(n=>n.every(s=>s!==null))}getEmptyPositions(t){const n=[];for(let s=0;s<this.boardSize;s++)for(let i=0;i<this.boardSize;i++)t[s][i]===null&&n.push({row:s,col:i});return n}checkWin(t){for(let n=0;n<this.boardSize;n++){const s=this.checkLine(t,{row:n,col:0},{row:0,col:1},"row");if(s)return s}for(let n=0;n<this.boardSize;n++){const s=this.checkLine(t,{row:0,col:n},{row:1,col:0},"column");if(s)return s}for(let n=0;n<=this.boardSize-this.winLength;n++){const s=this.checkLine(t,{row:0,col:n},{row:1,col:1},"diagonal");if(s)return s;if(n>0){const i=this.checkLine(t,{row:n,col:0},{row:1,col:1},"diagonal");if(i)return i}}for(let n=0;n<=this.boardSize-this.winLength;n++){const s=this.checkLine(t,{row:0,col:this.boardSize-1-n},{row:1,col:-1},"diagonal");if(s)return s;if(n>0){const i=this.checkLine(t,{row:n,col:this.boardSize-1},{row:1,col:-1},"diagonal");if(i)return i}}return null}checkLine(t,n,s,i){let o=0,r=null;const a=[];let l=n.row,c=n.col;for(;this.isValidPosition({row:l,col:c});){const u=t[l][c];if(u===null?(o=0,r=null,a.length=0):u===r?(o++,a.push({row:l,col:c})):(r=u,o=1,a.length=0,a.push({row:l,col:c})),o>=this.winLength&&r)return{player:r,positions:a.slice(-this.winLength),type:i};l+=s.row,c+=s.col}return null}evaluateBoard(t,n){const s=this.checkWin(t);return s?s.player===n?10:-10:this.isBoardFull(t)?0:this.evaluatePosition(t,n)}evaluatePosition(t,n){let s=0;const i=n==="X"?"O":"X";if(s+=this.evaluateAllLines(t,n,1),s-=this.evaluateAllLines(t,i,1),this.boardSize>=3){const o=Math.floor(this.boardSize/2);t[o][o]===n?s+=.3:t[o][o]===i&&(s-=.3)}return s}evaluateAllLines(t,n,s){let i=0;for(let o=0;o<this.boardSize;o++)i+=this.evaluateLine(t,{row:o,col:0},{row:0,col:1},n)*s;for(let o=0;o<this.boardSize;o++)i+=this.evaluateLine(t,{row:0,col:o},{row:1,col:0},n)*s;for(let o=0;o<=this.boardSize-this.winLength;o++)i+=this.evaluateLine(t,{row:0,col:o},{row:1,col:1},n)*s,o>0&&(i+=this.evaluateLine(t,{row:o,col:0},{row:1,col:1},n)*s),i+=this.evaluateLine(t,{row:0,col:this.boardSize-1-o},{row:1,col:-1},n)*s,o>0&&(i+=this.evaluateLine(t,{row:o,col:this.boardSize-1},{row:1,col:-1},n)*s);return i}evaluateLine(t,n,s,i){let o=0,r=0,a=0,l=0;const c=i==="X"?"O":"X";let u=n.row,f=n.col,d=0;for(;this.isValidPosition({row:u,col:f})&&d<this.winLength;){const m=t[u][f];m===i?r++:m===c?l++:a++,u+=s.row,f+=s.col,d++}return l>0?0:(r===this.winLength-1&&a===1?o=5:r===this.winLength-2&&a===2?o=2:r>0&&(o=1),o)}cloneBoard(t){return t.map(n=>[...n])}positionToString(t){return`${t.row},${t.col}`}stringToPosition(t){const[n,s]=t.split(",").map(Number);return{row:n,col:s}}boardToString(t){return t.map(n=>n.map(s=>s||"_").join("")).join("")}getOpponentPlayer(t){return t==="X"?"O":"X"}getMoveScore(t,n,s){const{row:i,col:o}=n;let r=0;const a=Math.floor(this.boardSize/2),l=Math.abs(i-a)+Math.abs(o-a);return r+=(this.boardSize-l)*.1,this.boardSize===3&&(i===0||i===2)&&(o===0||o===2)&&(r+=.2),r}getSortedMoves(t,n){return this.getEmptyPositions(t).sort((i,o)=>{const r=this.getMoveScore(t,i,n);return this.getMoveScore(t,o,n)-r})}}class qn{constructor(t=3,n="medium",s="O"){this.engine=new $t(t),this.difficulty=n,this.player=s,this.state={isThinking:!1,lastMove:null,moveCount:0,thinkingTime:0}}async makeMove(t){this.state.isThinking=!0;const n=Date.now();try{const s=this.getThinkingDelay();await this.delay(s);let i;switch(this.difficulty){case"easy":i=this.makeEasyMove(t);break;case"medium":i=this.makeMediumMove(t);break;case"hard":i=this.makeHardMove(t);break;default:i=this.makeMediumMove(t)}return this.state.thinkingTime=Date.now()-n,this.state.lastMove=i,this.state.moveCount++,i}finally{this.state.isThinking=!1}}makeEasyMove(t){const n=this.getAvailableMoves(t);if(Math.random()>.5){const s=this.findWinningMove(t)||this.findBlockingMove(t);if(s)return s}return n[Math.floor(Math.random()*n.length)]}makeMediumMove(t){const n=this.findWinningMove(t);if(n)return n;const s=this.findBlockingMove(t);return s||this.findStrategicMove(t)}makeHardMove(t){const n=this.findWinningMove(t);if(n)return n;const s=this.findBlockingMove(t);return s||this.findOptimalMove(t)}findWinningMove(t){const n=this.getAvailableMoves(t);for(const s of n){const i=this.engine.makeMove(t,s,this.player);if(this.engine.checkWin(i))return s}return null}findBlockingMove(t){const n=this.getAvailableMoves(t),s=this.getOpponent();for(const i of n){const o=this.engine.makeMove(t,i,s);if(this.engine.checkWin(o))return i}return null}findStrategicMove(t){const n=this.getAvailableMoves(t),s=t.length,i=Math.floor(s/2),o={row:i,col:i};if(this.isMoveAvailable(t,o))return o;const r=[{row:0,col:0},{row:0,col:s-1},{row:s-1,col:0},{row:s-1,col:s-1}];for(const a of r)if(this.isMoveAvailable(t,a))return a;return n[0]}findOptimalMove(t){const n=this.getAvailableMoves(t);let s=n[0],i=-1/0;for(const o of n){const r=this.engine.makeMove(t,o,this.player),a=this.minimax(r,5,!1);a>i&&(i=a,s=o)}return s}minimax(t,n,s){const i=this.engine.checkWin(t);if(i)return i.player===this.player?10-n:n-10;if(this.engine.isBoardFull(t)||n===0)return 0;const o=this.getAvailableMoves(t);if(s){let r=-1/0;for(const a of o){const l=this.engine.makeMove(t,a,this.player),c=this.minimax(l,n-1,!1);r=Math.max(r,c)}return r}else{let r=1/0;for(const a of o){const l=this.engine.makeMove(t,a,this.getOpponent()),c=this.minimax(l,n-1,!0);r=Math.min(r,c)}return r}}getAvailableMoves(t){const n=[];for(let s=0;s<t.length;s++)for(let i=0;i<t[s].length;i++)t[s][i]===null&&n.push({row:s,col:i});return n}isMoveAvailable(t,n){return t[n.row][n.col]===null}getOpponent(){return this.player==="X"?"O":"X"}getThinkingDelay(){switch(this.difficulty){case"easy":return 300+Math.random()*500;case"medium":return 500+Math.random()*700;case"hard":return 800+Math.random()*1e3;default:return 500}}delay(t){return new Promise(n=>setTimeout(n,t))}getState(){return{...this.state}}setDifficulty(t){this.difficulty=t}reset(){this.state={isThinking:!1,lastMove:null,moveCount:0,thinkingTime:0}}}const Ke=(e,t,n=365)=>{const s=new Date;s.setTime(s.getTime()+n*24*60*60*1e3),document.cookie=`${e}=${t};expires=${s.toUTCString()};path=/`},qe=e=>{const t=e+"=",n=document.cookie.split(";");for(let s=0;s<n.length;s++){let i=n[s];for(;i.charAt(0)===" ";)i=i.substring(1,i.length);if(i.indexOf(t)===0)return i.substring(t.length,i.length)}return null},Zn=()=>{const[e,t]=b.useState("menu"),[n]=b.useState(()=>new $t(3)),[s,i]=b.useState(null),[o,r]=b.useState(!1),a=b.useCallback(()=>({name:qe("playerName")||"Player",gamesPlayed:parseInt(qe("gamesPlayed")||"0"),wins:parseInt(qe("wins")||"0"),winStreak:parseInt(qe("winStreak")||"0"),draws:parseInt(qe("draws")||"0")}),[]),[l,c]=b.useState(a),u=b.useCallback(C=>{Ke("playerName",C.name),Ke("gamesPlayed",C.gamesPlayed.toString()),Ke("wins",C.wins.toString()),Ke("winStreak",C.winStreak.toString()),Ke("draws",C.draws.toString())},[]),f=b.useCallback(()=>({board:n.createEmptyBoard(),currentPlayer:"X",gameMode:"twoPlayer",status:"waiting",winner:null,winCondition:null,moveHistory:[],startTime:Date.now(),settings:Ye,players:{X:{id:"player1",name:l.name,stats:{gamesPlayed:0,wins:0,losses:0,draws:0,winStreak:0,longestWinStreak:0,totalMoves:0,averageMovesPerGame:0,fastestWin:0},achievements:[],preferences:Ye},O:{id:"player2",name:"Player 2",stats:{gamesPlayed:0,wins:0,losses:0,draws:0,winStreak:0,longestWinStreak:0,totalMoves:0,averageMovesPerGame:0,fastestWin:0},achievements:[],preferences:Ye}},scores:{X:0,O:0},round:1}),[n,l.name]),[d,m]=b.useState(f),g=b.useCallback((C,R)=>{c(X=>{const k={...X};return k.gamesPlayed++,C==="X"?(k.wins++,k.winStreak++):(C===null&&k.draws++,k.winStreak=0),u(k),k})},[u]),v=b.useCallback(C=>{c(R=>{const X={...R,name:C};return u(X),X}),m(R=>({...R,players:{...R.players,X:{...R.players.X,name:C}}}))},[u]),S=b.useCallback(()=>{t("menu")},[]),T=b.useCallback((C,R)=>{const X={...Ye,...R};if(C==="singlePlayer"){const k=new qn(X.boardSize,X.difficulty,"O");i(k)}else i(null);m(k=>({...f(),gameMode:C,settings:X,status:"playing",players:{...k.players,X:{...k.players.X,name:l.name},O:C==="singlePlayer"?{...k.players.O,name:"AI Player"}:k.players.O}})),t("game")},[f,l.name]),w=b.useCallback(async C=>{if(d.status!=="playing"||o)return!1;try{if(!n.isValidMove(d.board,C))return!1;const R=n.makeMove(d.board,C,d.currentPlayer),X={position:C,player:d.currentPlayer,timestamp:Date.now(),moveNumber:d.moveHistory.length+1},k=n.checkWin(R),G=n.isBoardFull(R);let N=d.status,B=null;k?(N="finished",B=k.player):G&&(N="finished",B=null);const I=n.getOpponentPlayer(d.currentPlayer);if(m(q=>({...q,board:R,currentPlayer:I,moveHistory:[...q.moveHistory,X],status:N,winner:B,winCondition:k,endTime:N==="finished"?Date.now():void 0})),N==="finished"){const q=Date.now()-d.startTime;g(B,q),B&&m(le=>({...le,scores:{...le.scores,[B]:le.scores[B]+1}}))}return!0}catch(R){return console.error("Move failed:",R),!1}},[d,n,o,g]),x=b.useCallback(async()=>{if(!(!s||d.status!=="playing"||d.currentPlayer!=="O"||o)){r(!0);try{const C=await s.makeMove(d.board);if(n.isValidMove(d.board,C)){const R=n.makeMove(d.board,C,"O"),X={position:C,player:"O",timestamp:Date.now(),moveNumber:d.moveHistory.length+1},k=n.checkWin(R),G=n.isBoardFull(R);let N=d.status,B=null;if(k?(N="finished",B=k.player):G&&(N="finished",B=null),m(I=>({...I,board:R,currentPlayer:"X",moveHistory:[...I.moveHistory,X],status:N,winner:B,winCondition:k,endTime:N==="finished"?Date.now():void 0})),N==="finished"){const I=Date.now()-d.startTime;g(B,I),B&&m(q=>({...q,scores:{...q.scores,[B]:q.scores[B]+1}}))}}}catch(C){console.error("AI move failed:",C)}finally{r(!1)}}},[s,d,n,o,g]);b.useEffect(()=>{if(d.gameMode==="singlePlayer"&&d.currentPlayer==="O"&&d.status==="playing"&&!o){const C=setTimeout(x,500);return()=>clearTimeout(C)}},[d.currentPlayer,d.status,d.gameMode,o,x]);const M=b.useCallback(()=>{m(C=>({...f(),gameMode:C.gameMode,settings:C.settings,players:C.players,scores:C.scores,round:C.round+1,status:"playing"})),r(!1)},[f]),j=b.useCallback(()=>d.status==="playing"||d.status==="paused",[d.status]),$=b.useCallback(()=>d.gameMode==="singlePlayer"&&d.currentPlayer==="O"&&d.status==="playing",[d]),F=b.useCallback(()=>{if(!d.startTime)return 0;const C=d.endTime||Date.now();return Math.floor((C-d.startTime)/1e3)},[d]),D=b.useCallback(()=>l,[l]);return{gameState:d,currentView:e,aiPlayer:s,engine:n,playerData:l,setCurrentView:t,showMenu:S,startNewGame:T,updatePlayerName:v,makeMove:w,resetGame:M,isGameActive:j,isAITurn:$,getGameDuration:F,getTotalStats:D}},Jn=b.createContext(void 0),Qn=({children:e})=>{const t=Zn();return p.jsx(Jn.Provider,{value:t,children:e})},es=()=>{const e=b.useContext(Jn);if(e===void 0)throw new Error("useGame must be used within a GameProvider");return e},Gt=({onStartGame:e,playerName:t,onPlayerNameChange:n,totalStats:s})=>{const[i,o]=b.useState("medium"),[r,a]=b.useState(t),[l,c]=b.useState(!1);b.useEffect(()=>{a(t),c(!1)},[t]);const u=m=>{a(m),c(m.trim()!==t)},f=()=>{r.trim()&&r.trim()!==t&&(n(r.trim()),c(!1))},d=m=>{m.key==="Enter"&&f()};return p.jsx("div",{className:"min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100 flex items-center justify-center p-4",children:p.jsxs("div",{className:"max-w-md w-full bg-white rounded-2xl shadow-2xl p-8",children:[p.jsxs("div",{className:"text-center mb-8",children:[p.jsx("h1",{className:"text-4xl font-bold text-gray-800 mb-2",children:"Advanced Tic-Tac-Toe"}),p.jsx("p",{className:"text-gray-600",children:"Challenge the AI or play with friends"})]}),p.jsxs("div",{className:"mb-8",children:[p.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Player Name"}),p.jsxs("div",{className:"flex gap-2",children:[p.jsx("input",{type:"text",value:r,onChange:m=>u(m.target.value),onKeyPress:d,onBlur:f,className:"flex-1 px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent",placeholder:"Enter your name",maxLength:20}),l&&p.jsx("button",{onClick:f,className:"px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition-colors",children:"Save"})]})]}),p.jsxs("div",{className:"mb-8 p-4 bg-gray-50 rounded-lg",children:[p.jsx("h3",{className:"font-semibold text-gray-800 mb-3",children:"Your Stats"}),p.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[p.jsxs("div",{className:"text-center",children:[p.jsx("p",{className:"text-2xl font-bold text-blue-600",children:s.gamesPlayed}),p.jsx("p",{className:"text-gray-600",children:"Games Played"})]}),p.jsxs("div",{className:"text-center",children:[p.jsx("p",{className:"text-2xl font-bold text-green-600",children:s.wins}),p.jsx("p",{className:"text-gray-600",children:"Wins"})]}),p.jsxs("div",{className:"text-center",children:[p.jsx("p",{className:"text-2xl font-bold text-yellow-600",children:s.draws}),p.jsx("p",{className:"text-gray-600",children:"Draws"})]}),p.jsxs("div",{className:"text-center",children:[p.jsx("p",{className:"text-2xl font-bold text-purple-600",children:s.winStreak}),p.jsx("p",{className:"text-gray-600",children:"Win Streak"})]})]})]}),p.jsxs("div",{className:"mb-6",children:[p.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-3",children:"AI Difficulty"}),p.jsx("div",{className:"grid grid-cols-3 gap-2",children:["easy","medium","hard"].map(m=>p.jsx("button",{onClick:()=>o(m),className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors ${i===m?"bg-blue-500 text-white":"bg-gray-200 text-gray-700 hover:bg-gray-300"}`,children:m.charAt(0).toUpperCase()+m.slice(1)},m))})]}),p.jsxs("div",{className:"space-y-3",children:[p.jsxs("button",{onClick:()=>e("singlePlayer",{difficulty:i}),className:"w-full bg-blue-500 hover:bg-blue-600 text-white font-medium py-3 px-6 rounded-lg transition-colors duration-200 flex items-center justify-center gap-2",children:[p.jsx("span",{children:"🤖"}),"Play vs AI (",i,")"]}),p.jsxs("button",{onClick:()=>e("twoPlayer"),className:"w-full bg-green-500 hover:bg-green-600 text-white font-medium py-3 px-6 rounded-lg transition-colors duration-200 flex items-center justify-center gap-2",children:[p.jsx("span",{children:"👥"}),"Play with Friend"]})]}),p.jsx("div",{className:"mt-8 text-center text-xs text-gray-500",children:"Your progress is automatically saved"})]})})},ts=b.createContext({transformPagePoint:e=>e,isStatic:!1,reducedMotion:"never"}),gt=b.createContext({}),zt=b.createContext(null),yt=typeof document<"u",Xr=yt?b.useLayoutEffect:b.useEffect,ns=b.createContext({strict:!1}),Ht=e=>e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),ss="data-"+Ht("framerAppearId");function Yr(e,t,n,s){const{visualElement:i}=b.useContext(gt),o=b.useContext(ns),r=b.useContext(zt),a=b.useContext(ts).reducedMotion,l=b.useRef();s=s||o.renderer,!l.current&&s&&(l.current=s(e,{visualState:t,parent:i,props:n,presenceContext:r,blockInitialAnimation:r?r.initial===!1:!1,reducedMotionConfig:a}));const c=l.current;b.useInsertionEffect(()=>{c&&c.update(n,r)});const u=b.useRef(!!(n[ss]&&!window.HandoffComplete));return Xr(()=>{c&&(c.render(),u.current&&c.animationState&&c.animationState.animateChanges())}),b.useEffect(()=>{c&&(c.updateFeatures(),!u.current&&c.animationState&&c.animationState.animateChanges(),u.current&&(u.current=!1,window.HandoffComplete=!0))}),c}function Re(e){return e&&typeof e=="object"&&Object.prototype.hasOwnProperty.call(e,"current")}function Kr(e,t,n){return b.useCallback(s=>{s&&e.mount&&e.mount(s),t&&(s?t.mount(s):t.unmount()),n&&(typeof n=="function"?n(s):Re(n)&&(n.current=s))},[t])}function Ze(e){return typeof e=="string"||Array.isArray(e)}function vt(e){return e!==null&&typeof e=="object"&&typeof e.start=="function"}const Xt=["animate","whileInView","whileFocus","whileHover","whileTap","whileDrag","exit"],Yt=["initial",...Xt];function xt(e){return vt(e.animate)||Yt.some(t=>Ze(e[t]))}function is(e){return!!(xt(e)||e.variants)}function qr(e,t){if(xt(e)){const{initial:n,animate:s}=e;return{initial:n===!1||Ze(n)?n:void 0,animate:Ze(s)?s:void 0}}return e.inherit!==!1?t:{}}function Zr(e){const{initial:t,animate:n}=qr(e,b.useContext(gt));return b.useMemo(()=>({initial:t,animate:n}),[rs(t),rs(n)])}function rs(e){return Array.isArray(e)?e.join(" "):e}const os={animation:["animate","variants","whileHover","whileTap","exit","whileInView","whileFocus","whileDrag"],exit:["exit"],drag:["drag","dragControls"],focus:["whileFocus"],hover:["whileHover","onHoverStart","onHoverEnd"],tap:["whileTap","onTap","onTapStart","onTapCancel"],pan:["onPan","onPanStart","onPanSessionStart","onPanEnd"],inView:["whileInView","onViewportEnter","onViewportLeave"],layout:["layout","layoutId"]},Je={};for(const e in os)Je[e]={isEnabled:t=>os[e].some(n=>!!t[n])};function Jr(e){for(const t in e)Je[t]={...Je[t],...e[t]}}const as=b.createContext({}),ls=b.createContext({}),Qr=Symbol.for("motionComponentSymbol");function eo({preloadedFeatures:e,createVisualElement:t,useRender:n,useVisualState:s,Component:i}){e&&Jr(e);function o(a,l){let c;const u={...b.useContext(ts),...a,layoutId:to(a)},{isStatic:f}=u,d=Zr(a),m=s(a,f);if(!f&&yt){d.visualElement=Yr(i,m,u,t);const g=b.useContext(ls),v=b.useContext(ns).strict;d.visualElement&&(c=d.visualElement.loadFeatures(u,v,e,g))}return Xn.createElement(gt.Provider,{value:d},c&&d.visualElement?Xn.createElement(c,{visualElement:d.visualElement,...u}):null,n(i,a,Kr(m,d.visualElement,l),m,f,d.visualElement))}const r=b.forwardRef(o);return r[Qr]=i,r}function to({layoutId:e}){const t=b.useContext(as).id;return t&&e!==void 0?t+"-"+e:e}function no(e){function t(s,i={}){return eo(e(s,i))}if(typeof Proxy>"u")return t;const n=new Map;return new Proxy(t,{get:(s,i)=>(n.has(i)||n.set(i,t(i)),n.get(i))})}const so=["animate","circle","defs","desc","ellipse","g","image","line","filter","marker","mask","metadata","path","pattern","polygon","polyline","rect","stop","switch","symbol","svg","text","tspan","use","view"];function Kt(e){return typeof e!="string"||e.includes("-")?!1:!!(so.indexOf(e)>-1||/[A-Z]/.test(e))}const bt={};function io(e){Object.assign(bt,e)}const Qe=["transformPerspective","x","y","z","translateX","translateY","translateZ","scale","scaleX","scaleY","rotate","rotateX","rotateY","rotateZ","skew","skewX","skewY"],Ve=new Set(Qe);function cs(e,{layout:t,layoutId:n}){return Ve.has(e)||e.startsWith("origin")||(t||n!==void 0)&&(!!bt[e]||e==="opacity")}const ne=e=>!!(e&&e.getVelocity),ro={x:"translateX",y:"translateY",z:"translateZ",transformPerspective:"perspective"},oo=Qe.length;function ao(e,{enableHardwareAcceleration:t=!0,allowTransformNone:n=!0},s,i){let o="";for(let r=0;r<oo;r++){const a=Qe[r];if(e[a]!==void 0){const l=ro[a]||a;o+=`${l}(${e[a]}) `}}return t&&!e.z&&(o+="translateZ(0)"),o=o.trim(),i?o=i(e,s?"":o):n&&s&&(o="none"),o}const us=e=>t=>typeof t=="string"&&t.startsWith(e),fs=us("--"),qt=us("var(--"),lo=/var\s*\(\s*--[\w-]+(\s*,\s*(?:(?:[^)(]|\((?:[^)(]+|\([^)(]*\))*\))*)+)?\s*\)/g,co=(e,t)=>t&&typeof e=="number"?t.transform(e):e,be=(e,t,n)=>Math.min(Math.max(n,e),t),je={test:e=>typeof e=="number",parse:parseFloat,transform:e=>e},et={...je,transform:e=>be(0,1,e)},wt={...je,default:1},tt=e=>Math.round(e*1e5)/1e5,Pt=/(-)?([\d]*\.?[\d])+/g,ds=/(#[0-9a-f]{3,8}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2}(-?[\d\.]+%?)\s*[\,\/]?\s*[\d\.]*%?\))/gi,uo=/^(#[0-9a-f]{3,8}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2}(-?[\d\.]+%?)\s*[\,\/]?\s*[\d\.]*%?\))$/i;function nt(e){return typeof e=="string"}const st=e=>({test:t=>nt(t)&&t.endsWith(e)&&t.split(" ").length===1,parse:parseFloat,transform:t=>`${t}${e}`}),we=st("deg"),fe=st("%"),A=st("px"),fo=st("vh"),ho=st("vw"),hs={...fe,parse:e=>fe.parse(e)/100,transform:e=>fe.transform(e*100)},ms={...je,transform:Math.round},ps={borderWidth:A,borderTopWidth:A,borderRightWidth:A,borderBottomWidth:A,borderLeftWidth:A,borderRadius:A,radius:A,borderTopLeftRadius:A,borderTopRightRadius:A,borderBottomRightRadius:A,borderBottomLeftRadius:A,width:A,maxWidth:A,height:A,maxHeight:A,size:A,top:A,right:A,bottom:A,left:A,padding:A,paddingTop:A,paddingRight:A,paddingBottom:A,paddingLeft:A,margin:A,marginTop:A,marginRight:A,marginBottom:A,marginLeft:A,rotate:we,rotateX:we,rotateY:we,rotateZ:we,scale:wt,scaleX:wt,scaleY:wt,scaleZ:wt,skew:we,skewX:we,skewY:we,distance:A,translateX:A,translateY:A,translateZ:A,x:A,y:A,z:A,perspective:A,transformPerspective:A,opacity:et,originX:hs,originY:hs,originZ:A,zIndex:ms,fillOpacity:et,strokeOpacity:et,numOctaves:ms};function Zt(e,t,n,s){const{style:i,vars:o,transform:r,transformOrigin:a}=e;let l=!1,c=!1,u=!0;for(const f in t){const d=t[f];if(fs(f)){o[f]=d;continue}const m=ps[f],g=co(d,m);if(Ve.has(f)){if(l=!0,r[f]=g,!u)continue;d!==(m.default||0)&&(u=!1)}else f.startsWith("origin")?(c=!0,a[f]=g):i[f]=g}if(t.transform||(l||s?i.transform=ao(e.transform,n,u,s):i.transform&&(i.transform="none")),c){const{originX:f="50%",originY:d="50%",originZ:m=0}=a;i.transformOrigin=`${f} ${d} ${m}`}}const Jt=()=>({style:{},transform:{},transformOrigin:{},vars:{}});function gs(e,t,n){for(const s in t)!ne(t[s])&&!cs(s,n)&&(e[s]=t[s])}function mo({transformTemplate:e},t,n){return b.useMemo(()=>{const s=Jt();return Zt(s,t,{enableHardwareAcceleration:!n},e),Object.assign({},s.vars,s.style)},[t])}function po(e,t,n){const s=e.style||{},i={};return gs(i,s,e),Object.assign(i,mo(e,t,n)),e.transformValues?e.transformValues(i):i}function go(e,t,n){const s={},i=po(e,t,n);return e.drag&&e.dragListener!==!1&&(s.draggable=!1,i.userSelect=i.WebkitUserSelect=i.WebkitTouchCallout="none",i.touchAction=e.drag===!0?"none":`pan-${e.drag==="x"?"y":"x"}`),e.tabIndex===void 0&&(e.onTap||e.onTapStart||e.whileTap)&&(s.tabIndex=0),s.style=i,s}const yo=new Set(["animate","exit","variants","initial","style","values","variants","transition","transformTemplate","transformValues","custom","inherit","onBeforeLayoutMeasure","onAnimationStart","onAnimationComplete","onUpdate","onDragStart","onDrag","onDragEnd","onMeasureDragConstraints","onDirectionLock","onDragTransitionEnd","_dragX","_dragY","onHoverStart","onHoverEnd","onViewportEnter","onViewportLeave","globalTapTarget","ignoreStrict","viewport"]);function Tt(e){return e.startsWith("while")||e.startsWith("drag")&&e!=="draggable"||e.startsWith("layout")||e.startsWith("onTap")||e.startsWith("onPan")||e.startsWith("onLayout")||yo.has(e)}let ys=e=>!Tt(e);function vo(e){e&&(ys=t=>t.startsWith("on")?!Tt(t):e(t))}try{vo(require("@emotion/is-prop-valid").default)}catch{}function xo(e,t,n){const s={};for(const i in e)i==="values"&&typeof e.values=="object"||(ys(i)||n===!0&&Tt(i)||!t&&!Tt(i)||e.draggable&&i.startsWith("onDrag"))&&(s[i]=e[i]);return s}function vs(e,t,n){return typeof e=="string"?e:A.transform(t+n*e)}function bo(e,t,n){const s=vs(t,e.x,e.width),i=vs(n,e.y,e.height);return`${s} ${i}`}const wo={offset:"stroke-dashoffset",array:"stroke-dasharray"},Po={offset:"strokeDashoffset",array:"strokeDasharray"};function To(e,t,n=1,s=0,i=!0){e.pathLength=1;const o=i?wo:Po;e[o.offset]=A.transform(-s);const r=A.transform(t),a=A.transform(n);e[o.array]=`${r} ${a}`}function Qt(e,{attrX:t,attrY:n,attrScale:s,originX:i,originY:o,pathLength:r,pathSpacing:a=1,pathOffset:l=0,...c},u,f,d){if(Zt(e,c,u,d),f){e.style.viewBox&&(e.attrs.viewBox=e.style.viewBox);return}e.attrs=e.style,e.style={};const{attrs:m,style:g,dimensions:v}=e;m.transform&&(v&&(g.transform=m.transform),delete m.transform),v&&(i!==void 0||o!==void 0||g.transform)&&(g.transformOrigin=bo(v,i!==void 0?i:.5,o!==void 0?o:.5)),t!==void 0&&(m.x=t),n!==void 0&&(m.y=n),s!==void 0&&(m.scale=s),r!==void 0&&To(m,r,a,l,!1)}const xs=()=>({...Jt(),attrs:{}}),en=e=>typeof e=="string"&&e.toLowerCase()==="svg";function So(e,t,n,s){const i=b.useMemo(()=>{const o=xs();return Qt(o,t,{enableHardwareAcceleration:!1},en(s),e.transformTemplate),{...o.attrs,style:{...o.style}}},[t]);if(e.style){const o={};gs(o,e.style,e),i.style={...o,...i.style}}return i}function Co(e=!1){return(n,s,i,{latestValues:o},r)=>{const l=(Kt(n)?So:go)(s,o,r,n),u={...xo(s,typeof n=="string",e),...l,ref:i},{children:f}=s,d=b.useMemo(()=>ne(f)?f.get():f,[f]);return b.createElement(n,{...u,children:d})}}function bs(e,{style:t,vars:n},s,i){Object.assign(e.style,t,i&&i.getProjectionStyles(s));for(const o in n)e.style.setProperty(o,n[o])}const ws=new Set(["baseFrequency","diffuseConstant","kernelMatrix","kernelUnitLength","keySplines","keyTimes","limitingConeAngle","markerHeight","markerWidth","numOctaves","targetX","targetY","surfaceScale","specularConstant","specularExponent","stdDeviation","tableValues","viewBox","gradientTransform","pathLength","startOffset","textLength","lengthAdjust"]);function Ps(e,t,n,s){bs(e,t,void 0,s);for(const i in t.attrs)e.setAttribute(ws.has(i)?i:Ht(i),t.attrs[i])}function tn(e,t){const{style:n}=e,s={};for(const i in n)(ne(n[i])||t.style&&ne(t.style[i])||cs(i,e))&&(s[i]=n[i]);return s}function Ts(e,t){const n=tn(e,t);for(const s in e)if(ne(e[s])||ne(t[s])){const i=Qe.indexOf(s)!==-1?"attr"+s.charAt(0).toUpperCase()+s.substring(1):s;n[i]=e[s]}return n}function nn(e,t,n,s={},i={}){return typeof t=="function"&&(t=t(n!==void 0?n:e.custom,s,i)),typeof t=="string"&&(t=e.variants&&e.variants[t]),typeof t=="function"&&(t=t(n!==void 0?n:e.custom,s,i)),t}function Mo(e){const t=b.useRef(null);return t.current===null&&(t.current=e()),t.current}const St=e=>Array.isArray(e),Ao=e=>!!(e&&typeof e=="object"&&e.mix&&e.toValue),Vo=e=>St(e)?e[e.length-1]||0:e;function Ct(e){const t=ne(e)?e.get():e;return Ao(t)?t.toValue():t}function jo({scrapeMotionValuesFromProps:e,createRenderState:t,onMount:n},s,i,o){const r={latestValues:ko(s,i,o,e),renderState:t()};return n&&(r.mount=a=>n(s,a,r)),r}const Ss=e=>(t,n)=>{const s=b.useContext(gt),i=b.useContext(zt),o=()=>jo(e,t,s,i);return n?o():Mo(o)};function ko(e,t,n,s){const i={},o=s(e,{});for(const d in o)i[d]=Ct(o[d]);let{initial:r,animate:a}=e;const l=xt(e),c=is(e);t&&c&&!l&&e.inherit!==!1&&(r===void 0&&(r=t.initial),a===void 0&&(a=t.animate));let u=n?n.initial===!1:!1;u=u||r===!1;const f=u?a:r;return f&&typeof f!="boolean"&&!vt(f)&&(Array.isArray(f)?f:[f]).forEach(m=>{const g=nn(e,m);if(!g)return;const{transitionEnd:v,transition:S,...T}=g;for(const w in T){let x=T[w];if(Array.isArray(x)){const M=u?x.length-1:0;x=x[M]}x!==null&&(i[w]=x)}for(const w in v)i[w]=v[w]}),i}const H=e=>e;class Cs{constructor(){this.order=[],this.scheduled=new Set}add(t){if(!this.scheduled.has(t))return this.scheduled.add(t),this.order.push(t),!0}remove(t){const n=this.order.indexOf(t);n!==-1&&(this.order.splice(n,1),this.scheduled.delete(t))}clear(){this.order.length=0,this.scheduled.clear()}}function Do(e){let t=new Cs,n=new Cs,s=0,i=!1,o=!1;const r=new WeakSet,a={schedule:(l,c=!1,u=!1)=>{const f=u&&i,d=f?t:n;return c&&r.add(l),d.add(l)&&f&&i&&(s=t.order.length),l},cancel:l=>{n.remove(l),r.delete(l)},process:l=>{if(i){o=!0;return}if(i=!0,[t,n]=[n,t],n.clear(),s=t.order.length,s)for(let c=0;c<s;c++){const u=t.order[c];u(l),r.has(u)&&(a.schedule(u),e())}i=!1,o&&(o=!1,a.process(l))}};return a}const Mt=["prepare","read","update","preRender","render","postRender"],Eo=40;function No(e,t){let n=!1,s=!0;const i={delta:0,timestamp:0,isProcessing:!1},o=Mt.reduce((f,d)=>(f[d]=Do(()=>n=!0),f),{}),r=f=>o[f].process(i),a=()=>{const f=performance.now();n=!1,i.delta=s?1e3/60:Math.max(Math.min(f-i.timestamp,Eo),1),i.timestamp=f,i.isProcessing=!0,Mt.forEach(r),i.isProcessing=!1,n&&t&&(s=!1,e(a))},l=()=>{n=!0,s=!0,i.isProcessing||e(a)};return{schedule:Mt.reduce((f,d)=>{const m=o[d];return f[d]=(g,v=!1,S=!1)=>(n||l(),m.schedule(g,v,S)),f},{}),cancel:f=>Mt.forEach(d=>o[d].cancel(f)),state:i,steps:o}}const{schedule:U,cancel:de,state:Q,steps:sn}=No(typeof requestAnimationFrame<"u"?requestAnimationFrame:H,!0),Lo={useVisualState:Ss({scrapeMotionValuesFromProps:Ts,createRenderState:xs,onMount:(e,t,{renderState:n,latestValues:s})=>{U.read(()=>{try{n.dimensions=typeof t.getBBox=="function"?t.getBBox():t.getBoundingClientRect()}catch{n.dimensions={x:0,y:0,width:0,height:0}}}),U.render(()=>{Qt(n,s,{enableHardwareAcceleration:!1},en(t.tagName),e.transformTemplate),Ps(t,n)})}})},Oo={useVisualState:Ss({scrapeMotionValuesFromProps:tn,createRenderState:Jt})};function Ro(e,{forwardMotionProps:t=!1},n,s){return{...Kt(e)?Lo:Oo,preloadedFeatures:n,useRender:Co(t),createVisualElement:s,Component:e}}function he(e,t,n,s={passive:!0}){return e.addEventListener(t,n,s),()=>e.removeEventListener(t,n)}const Ms=e=>e.pointerType==="mouse"?typeof e.button!="number"||e.button<=0:e.isPrimary!==!1;function At(e,t="page"){return{point:{x:e[t+"X"],y:e[t+"Y"]}}}const Bo=e=>t=>Ms(t)&&e(t,At(t));function me(e,t,n,s){return he(e,t,Bo(n),s)}const Fo=(e,t)=>n=>t(e(n)),Pe=(...e)=>e.reduce(Fo);function As(e){let t=null;return()=>{const n=()=>{t=null};return t===null?(t=e,n):!1}}const Vs=As("dragHorizontal"),js=As("dragVertical");function ks(e){let t=!1;if(e==="y")t=js();else if(e==="x")t=Vs();else{const n=Vs(),s=js();n&&s?t=()=>{n(),s()}:(n&&n(),s&&s())}return t}function Ds(){const e=ks(!0);return e?(e(),!1):!0}class Te{constructor(t){this.isMounted=!1,this.node=t}update(){}}function Es(e,t){const n="pointer"+(t?"enter":"leave"),s="onHover"+(t?"Start":"End"),i=(o,r)=>{if(o.pointerType==="touch"||Ds())return;const a=e.getProps();e.animationState&&a.whileHover&&e.animationState.setActive("whileHover",t),a[s]&&U.update(()=>a[s](o,r))};return me(e.current,n,i,{passive:!e.getProps()[s]})}class Io extends Te{mount(){this.unmount=Pe(Es(this.node,!0),Es(this.node,!1))}unmount(){}}class _o extends Te{constructor(){super(...arguments),this.isActive=!1}onFocus(){let t=!1;try{t=this.node.current.matches(":focus-visible")}catch{t=!0}!t||!this.node.animationState||(this.node.animationState.setActive("whileFocus",!0),this.isActive=!0)}onBlur(){!this.isActive||!this.node.animationState||(this.node.animationState.setActive("whileFocus",!1),this.isActive=!1)}mount(){this.unmount=Pe(he(this.node.current,"focus",()=>this.onFocus()),he(this.node.current,"blur",()=>this.onBlur()))}unmount(){}}const Ns=(e,t)=>t?e===t?!0:Ns(e,t.parentElement):!1;function rn(e,t){if(!t)return;const n=new PointerEvent("pointer"+e);t(n,At(n))}class Wo extends Te{constructor(){super(...arguments),this.removeStartListeners=H,this.removeEndListeners=H,this.removeAccessibleListeners=H,this.startPointerPress=(t,n)=>{if(this.isPressing)return;this.removeEndListeners();const s=this.node.getProps(),o=me(window,"pointerup",(a,l)=>{if(!this.checkPressEnd())return;const{onTap:c,onTapCancel:u,globalTapTarget:f}=this.node.getProps();U.update(()=>{!f&&!Ns(this.node.current,a.target)?u&&u(a,l):c&&c(a,l)})},{passive:!(s.onTap||s.onPointerUp)}),r=me(window,"pointercancel",(a,l)=>this.cancelPress(a,l),{passive:!(s.onTapCancel||s.onPointerCancel)});this.removeEndListeners=Pe(o,r),this.startPress(t,n)},this.startAccessiblePress=()=>{const t=o=>{if(o.key!=="Enter"||this.isPressing)return;const r=a=>{a.key!=="Enter"||!this.checkPressEnd()||rn("up",(l,c)=>{const{onTap:u}=this.node.getProps();u&&U.update(()=>u(l,c))})};this.removeEndListeners(),this.removeEndListeners=he(this.node.current,"keyup",r),rn("down",(a,l)=>{this.startPress(a,l)})},n=he(this.node.current,"keydown",t),s=()=>{this.isPressing&&rn("cancel",(o,r)=>this.cancelPress(o,r))},i=he(this.node.current,"blur",s);this.removeAccessibleListeners=Pe(n,i)}}startPress(t,n){this.isPressing=!0;const{onTapStart:s,whileTap:i}=this.node.getProps();i&&this.node.animationState&&this.node.animationState.setActive("whileTap",!0),s&&U.update(()=>s(t,n))}checkPressEnd(){return this.removeEndListeners(),this.isPressing=!1,this.node.getProps().whileTap&&this.node.animationState&&this.node.animationState.setActive("whileTap",!1),!Ds()}cancelPress(t,n){if(!this.checkPressEnd())return;const{onTapCancel:s}=this.node.getProps();s&&U.update(()=>s(t,n))}mount(){const t=this.node.getProps(),n=me(t.globalTapTarget?window:this.node.current,"pointerdown",this.startPointerPress,{passive:!(t.onTapStart||t.onPointerStart)}),s=he(this.node.current,"focus",this.startAccessiblePress);this.removeStartListeners=Pe(n,s)}unmount(){this.removeStartListeners(),this.removeEndListeners(),this.removeAccessibleListeners()}}const on=new WeakMap,an=new WeakMap,Uo=e=>{const t=on.get(e.target);t&&t(e)},$o=e=>{e.forEach(Uo)};function Go({root:e,...t}){const n=e||document;an.has(n)||an.set(n,{});const s=an.get(n),i=JSON.stringify(t);return s[i]||(s[i]=new IntersectionObserver($o,{root:e,...t})),s[i]}function zo(e,t,n){const s=Go(t);return on.set(e,n),s.observe(e),()=>{on.delete(e),s.unobserve(e)}}const Ho={some:0,all:1};class Xo extends Te{constructor(){super(...arguments),this.hasEnteredView=!1,this.isInView=!1}startObserver(){this.unmount();const{viewport:t={}}=this.node.getProps(),{root:n,margin:s,amount:i="some",once:o}=t,r={root:n?n.current:void 0,rootMargin:s,threshold:typeof i=="number"?i:Ho[i]},a=l=>{const{isIntersecting:c}=l;if(this.isInView===c||(this.isInView=c,o&&!c&&this.hasEnteredView))return;c&&(this.hasEnteredView=!0),this.node.animationState&&this.node.animationState.setActive("whileInView",c);const{onViewportEnter:u,onViewportLeave:f}=this.node.getProps(),d=c?u:f;d&&d(l)};return zo(this.node.current,r,a)}mount(){this.startObserver()}update(){if(typeof IntersectionObserver>"u")return;const{props:t,prevProps:n}=this.node;["amount","margin","root"].some(Yo(t,n))&&this.startObserver()}unmount(){}}function Yo({viewport:e={}},{viewport:t={}}={}){return n=>e[n]!==t[n]}const Ko={inView:{Feature:Xo},tap:{Feature:Wo},focus:{Feature:_o},hover:{Feature:Io}};function Ls(e,t){if(!Array.isArray(t))return!1;const n=t.length;if(n!==e.length)return!1;for(let s=0;s<n;s++)if(t[s]!==e[s])return!1;return!0}function qo(e){const t={};return e.values.forEach((n,s)=>t[s]=n.get()),t}function Zo(e){const t={};return e.values.forEach((n,s)=>t[s]=n.getVelocity()),t}function Vt(e,t,n){const s=e.getProps();return nn(s,t,n!==void 0?n:s.custom,qo(e),Zo(e))}let it=H,ue=H;process.env.NODE_ENV!=="production"&&(it=(e,t)=>{!e&&typeof console<"u"&&console.warn(t)},ue=(e,t)=>{if(!e)throw new Error(t)});const Se=e=>e*1e3,pe=e=>e/1e3,Jo={current:!1},Os=e=>Array.isArray(e)&&typeof e[0]=="number";function Rs(e){return!!(!e||typeof e=="string"&&Bs[e]||Os(e)||Array.isArray(e)&&e.every(Rs))}const rt=([e,t,n,s])=>`cubic-bezier(${e}, ${t}, ${n}, ${s})`,Bs={linear:"linear",ease:"ease",easeIn:"ease-in",easeOut:"ease-out",easeInOut:"ease-in-out",circIn:rt([0,.65,.55,1]),circOut:rt([.55,0,1,.45]),backIn:rt([.31,.01,.66,-.59]),backOut:rt([.33,1.53,.69,.99])};function Fs(e){if(e)return Os(e)?rt(e):Array.isArray(e)?e.map(Fs):Bs[e]}function Qo(e,t,n,{delay:s=0,duration:i,repeat:o=0,repeatType:r="loop",ease:a,times:l}={}){const c={[t]:n};l&&(c.offset=l);const u=Fs(a);return Array.isArray(u