micro-lottie-react
Version:
The smallest React Lottie player. 15KB. Zero deps. Supports .lottie files.
2 lines (1 loc) • 45.7 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).MicroLottieReact={},t.React)}(this,function(t,e){"use strict";var r,i={exports:{}},n={};var s,o={};"production"===process.env.NODE_ENV?i.exports=function(){if(r)return n;r=1;var t=e,i=Symbol.for("react.element"),s=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,a=t.u.ReactCurrentOwner,c={key:!0,ref:!0,l:!0,m:!0};function h(t,e,r){var n,s={},h=null,u=null;for(n in void 0!==r&&(h=""+r),void 0!==e.key&&(h=""+e.key),void 0!==e.ref&&(u=e.ref),e)o.call(e,n)&&!c.hasOwnProperty(n)&&(s[n]=e[n]);if(t&&t.defaultProps)for(n in e=t.defaultProps)void 0===s[n]&&(s[n]=e[n]);return{$$typeof:i,type:t,key:h,ref:u,props:s,S:a.current}}return n.Fragment=s,n.jsx=h,n.jsxs=h,n}():i.exports=(s||(s=1,"production"!==process.env.NODE_ENV&&function(){var t,r=e,i=Symbol.for("react.element"),n=Symbol.for("react.portal"),s=Symbol.for("react.fragment"),a=Symbol.for("react.strict_mode"),c=Symbol.for("react.profiler"),h=Symbol.for("react.provider"),u=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),f=Symbol.for("react.suspense"),p=Symbol.for("react.suspense_list"),d=Symbol.for("react.memo"),y=Symbol.for("react.lazy"),m=Symbol.for("react.offscreen"),v=Symbol.iterator,w=r.u;function b(t){for(var e=arguments.length,r=new Array(e>1?e-1:0),i=1;i<e;i++)r[i-1]=arguments[i];!function(t,e,r){var i=w.ReactDebugCurrentFrame.getStackAddendum();""!==i&&(e+="%s",r=r.concat([i]));var n=r.map(function(t){return String(t)});n.unshift("Warning: "+e),Function.prototype.apply.call(console[t],console,n)}("error",t,r)}function g(t){return t.displayName||"Context"}function S(t){if(null==t)return null;if("number"==typeof t.tag&&b("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof t)return t.displayName||t.name||null;if("string"==typeof t)return t;switch(t){case s:return"Fragment";case n:return"Portal";case c:return"Profiler";case a:return"StrictMode";case f:return"Suspense";case p:return"SuspenseList"}if("object"==typeof t)switch(t.$$typeof){case u:return g(t)+".Consumer";case h:return g(t.M)+".Provider";case l:return function(t,e,r){var i=t.displayName;if(i)return i;var n=e.displayName||e.name||"";return""!==n?r+"("+n+")":r}(t,t.render,"ForwardRef");case d:var e=t.displayName||null;return null!==e?e:S(t.type)||"Memo";case y:var r=t,i=r.j,o=r.$;try{return S(o(i))}catch(t){return null}}return null}t=Symbol.for("react.module.reference");var k,M,j,$,E,F,T,O=Object.assign,A=0;function P(){}P.F=!0;var L,x=w.ReactCurrentDispatcher;function C(t,e,r){if(void 0===L)try{throw Error()}catch(t){var i=t.stack.trim().match(/\n( *(at )?)/);L=i&&i[1]||""}return"\n"+L+t}var R,I=!1,_="function"==typeof WeakMap?WeakMap:Map;function D(t,e){if(!t||I)return"";var r,i=R.get(t);if(void 0!==i)return i;I=!0;var n,s=Error.prepareStackTrace;Error.prepareStackTrace=void 0,n=x.current,x.current=null,function(){if(0===A){k=console.log,M=console.info,j=console.warn,$=console.error,E=console.group,F=console.groupCollapsed,T=console.groupEnd;var t={configurable:!0,enumerable:!0,value:P,writable:!0};Object.defineProperties(console,{info:t,log:t,warn:t,error:t,group:t,groupCollapsed:t,groupEnd:t})}A++}();try{if(e){var o=function(){throw Error()};if(Object.defineProperty(o.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(o,[])}catch(t){r=t}Reflect.construct(t,[],o)}else{try{o.call()}catch(t){r=t}t.call(o.prototype)}}else{try{throw Error()}catch(t){r=t}t()}}catch(e){if(e&&r&&"string"==typeof e.stack){for(var a=e.stack.split("\n"),c=r.stack.split("\n"),h=a.length-1,u=c.length-1;h>=1&&u>=0&&a[h]!==c[u];)u--;for(;h>=1&&u>=0;h--,u--)if(a[h]!==c[u]){if(1!==h||1!==u)do{if(h--,--u<0||a[h]!==c[u]){var l="\n"+a[h].replace(" at new "," at ");return t.displayName&&l.includes("<anonymous>")&&(l=l.replace("<anonymous>",t.displayName)),"function"==typeof t&&R.set(t,l),l}}while(h>=1&&u>=0);break}}}finally{I=!1,x.current=n,function(){if(0===--A){var t={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:O({},t,{value:k}),info:O({},t,{value:M}),warn:O({},t,{value:j}),error:O({},t,{value:$}),group:O({},t,{value:E}),groupCollapsed:O({},t,{value:F}),groupEnd:O({},t,{value:T})})}A<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=s}var f=t?t.displayName||t.name:"",p=f?C(f):"";return"function"==typeof t&&R.set(t,p),p}function N(t,e,r){if(null==t)return"";if("function"==typeof t)return D(t,!(!(i=t.prototype)||!i.isReactComponent));var i;if("string"==typeof t)return C(t);switch(t){case f:return C("Suspense");case p:return C("SuspenseList")}if("object"==typeof t)switch(t.$$typeof){case l:return D(t.render,!1);case d:return N(t.type,e,r);case y:var n=t,s=n.j,o=n.$;try{return N(o(s),e,r)}catch(t){}}return""}R=new _;var z=Object.prototype.hasOwnProperty,J={},q=w.ReactDebugCurrentFrame;function U(t){if(t){var e=t.S,r=N(t.type,t.T,e?e.type:null);q.setExtraStackFrame(r)}else q.setExtraStackFrame(null)}var V=Array.isArray;function B(t){return V(t)}function G(t){return""+t}function W(t){if(function(t){try{return G(t),!1}catch(t){return!0}}(t))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(t){return"function"==typeof Symbol&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object"}(t)),G(t)}var K,Y,H=w.ReactCurrentOwner,X={key:!0,ref:!0,l:!0,m:!0};function Z(t,e,r,n,s){var o,a={},c=null,h=null;for(o in void 0!==r&&(W(r),c=""+r),function(t){if(z.call(t,"key")){var e=Object.getOwnPropertyDescriptor(t,"key").get;if(e&&e.isReactWarning)return!1}return void 0!==t.key}(e)&&(W(e.key),c=""+e.key),function(t){if(z.call(t,"ref")){var e=Object.getOwnPropertyDescriptor(t,"ref").get;if(e&&e.isReactWarning)return!1}return void 0!==t.ref}(e)&&(h=e.ref,function(t){"string"==typeof t.ref&&H.current}(e)),e)z.call(e,o)&&!X.hasOwnProperty(o)&&(a[o]=e[o]);if(t&&t.defaultProps){var u=t.defaultProps;for(o in u)void 0===a[o]&&(a[o]=u[o])}if(c||h){var l="function"==typeof t?t.displayName||t.name||"Unknown":t;c&&function(t,e){var r=function(){K||(K=!0,b("%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)",e))};r.isReactWarning=!0,Object.defineProperty(t,"key",{get:r,configurable:!0})}(a,l),h&&function(t,e){var r=function(){Y||(Y=!0,b("%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)",e))};r.isReactWarning=!0,Object.defineProperty(t,"ref",{get:r,configurable:!0})}(a,l)}return function(t,e,r,n,s,o,a){var c={$$typeof:i,type:t,key:e,ref:r,props:a,S:o,O:{}};return Object.defineProperty(c.O,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(c,"A",{configurable:!1,enumerable:!1,writable:!1,value:n}),Object.defineProperty(c,"T",{configurable:!1,enumerable:!1,writable:!1,value:s}),Object.freeze&&(Object.freeze(c.props),Object.freeze(c)),c}(t,c,h,s,n,H.current,a)}var Q,tt=w.ReactCurrentOwner,et=w.ReactDebugCurrentFrame;function rt(t){if(t){var e=t.S,r=N(t.type,t.T,e?e.type:null);et.setExtraStackFrame(r)}else et.setExtraStackFrame(null)}function it(t){return"object"==typeof t&&null!==t&&t.$$typeof===i}function nt(){if(tt.current){var t=S(tt.current.type);if(t)return"\n\nCheck the render method of `"+t+"`."}return""}Q=!1;var st={};function ot(t,e){if(t.O&&!t.O.validated&&null==t.key){t.O.validated=!0;var r=function(t){var e=nt();if(!e){var r="string"==typeof t?t:t.displayName||t.name;r&&(e="\n\nCheck the top-level render call using <"+r+">.")}return e}(e);if(!st[r]){st[r]=!0;var i="";t&&t.S&&t.S!==tt.current&&(i=" It was passed a child from "+S(t.S.type)+"."),rt(t),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',r,i),rt(null)}}}function at(t,e){if("object"==typeof t)if(B(t))for(var r=0;r<t.length;r++){var i=t[r];it(i)&&ot(i,e)}else if(it(t))t.O&&(t.O.validated=!0);else if(t){var n=function(t){if(null===t||"object"!=typeof t)return null;var e=v&&t[v]||t["@@iterator"];return"function"==typeof e?e:null}(t);if("function"==typeof n&&n!==t.entries)for(var s,o=n.call(t);!(s=o.next()).done;)it(s.value)&&ot(s.value,e)}}function ct(t){var e,r=t.type;if(null!=r&&"string"!=typeof r){if("function"==typeof r)e=r.propTypes;else{if("object"!=typeof r||r.$$typeof!==l&&r.$$typeof!==d)return;e=r.propTypes}if(e){var i=S(r);!function(t,e,r,i,n){var s=Function.call.bind(z);for(var o in t)if(s(t,o)){var a=void 0;try{if("function"!=typeof t[o]){var c=Error((i||"React class")+": "+r+" type `"+o+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof t[o]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw c.name="Invariant Violation",c}a=t[o](e,o,i,r,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(t){a=t}!a||a instanceof Error||(U(n),b("%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).",i||"React class",r,o,typeof a),U(null)),a instanceof Error&&!(a.message in J)&&(J[a.message]=!0,U(n),b("Failed %s type: %s",r,a.message),U(null))}}(e,t.props,"prop",i,t)}else void 0===r.PropTypes||Q||(Q=!0,b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",S(r)||"Unknown"));"function"!=typeof r.getDefaultProps||r.getDefaultProps.isReactClassApproved||b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var ht={};function ut(e,r,n,o,v,w){var g=function(e){return"string"==typeof e||"function"==typeof e||e===s||e===c||e===a||e===f||e===p||e===m||"object"==typeof e&&null!==e&&(e.$$typeof===y||e.$$typeof===d||e.$$typeof===h||e.$$typeof===u||e.$$typeof===l||e.$$typeof===t||void 0!==e.getModuleId)}(e);if(!g){var k,M="";(void 0===e||"object"==typeof e&&null!==e&&0===Object.keys(e).length)&&(M+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."),M+=nt(),null===e?k="null":B(e)?k="array":void 0!==e&&e.$$typeof===i?(k="<"+(S(e.type)||"Unknown")+" />",M=" Did you accidentally export a JSX literal instead of a component?"):k=typeof e,b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",k,M)}var j=Z(e,r,n,v,w);if(null==j)return j;if(g){var $=r.children;if(void 0!==$)if(o)if(B($)){for(var E=0;E<$.length;E++)at($[E],e);Object.freeze&&Object.freeze($)}else b("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 at($,e)}if(z.call(r,"key")){var F=S(e),T=Object.keys(r).filter(function(t){return"key"!==t}),O=T.length>0?"{key: someKey, "+T.join(": ..., ")+": ...}":"{key: someKey}";ht[F+O]||(b('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',O,F,T.length>0?"{"+T.join(": ..., ")+": ...}":"{}",F),ht[F+O]=!0)}return e===s?function(t){for(var e=Object.keys(t.props),r=0;r<e.length;r++){var i=e[r];if("children"!==i&&"key"!==i){rt(t),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",i),rt(null);break}}null!==t.ref&&(rt(t),b("Invalid attribute `ref` supplied to `React.Fragment`."),rt(null))}(j):ct(j),j}var lt=function(t,e,r){return ut(t,e,r,!1)},ft=function(t,e,r){return ut(t,e,r,!0)};o.Fragment=s,o.jsx=lt,o.jsxs=ft}()),o);var a=i.exports;class c{static async load(t,e={}){const r=this.getCacheKey(t,e);if(!1!==e.cache&&this.cache.has(r))return this.cache.get(r);const i=this.performLoad(t,{url:t,method:"GET",timeout:this.DEFAULT_TIMEOUT,retry:this.DEFAULT_RETRY,cache:!0,...e});return!1!==e.cache&&this.cache.set(r,i),i}static async loadFromSource(t){const e=performance.now();if("string"==typeof t)return this.isUrl(t)?this.load(t):{data:t,format:"json",size:t.length,loadTime:performance.now()-e};if(t instanceof ArrayBuffer)return{data:t,format:"lottie",size:t.byteLength,loadTime:performance.now()-e};if("object"==typeof t){const r=JSON.stringify(t);return{data:r,format:"json",size:r.length,loadTime:performance.now()-e}}throw new Error("Unsupported source type")}static async preload(t,e={}){const r=t.map(t=>this.load(t,e));return Promise.all(r)}static clearCache(){this.cache.clear()}static getCacheInfo(){return{size:this.cache.size,keys:Array.from(this.cache.keys())}}static removeCacheItem(t,e={}){const r=this.getCacheKey(t,e);return this.cache.delete(r)}static async performLoad(t,e){const r=performance.now();let i=null;const n=e.retry||this.DEFAULT_RETRY;for(let s=0;s<n;s++)try{const i=await this.fetchWithTimeout(t,e);if(!i.ok)throw new Error(`HTTP ${i.status}: ${i.statusText}`);const n=this.detectFormat(t,i);let s,o;return"lottie"===n?(s=await i.arrayBuffer(),o=s.byteLength):(s=await i.text(),o=s.length),{data:s,format:n,size:o,loadTime:performance.now()-r}}catch(t){if(i=t,this.isNonRetryableError(t))break;s<n-1&&await this.delay(100*Math.pow(2,s))}throw i||new Error("Failed to load animation")}static async fetchWithTimeout(t,e){const r=new AbortController,i=setTimeout(()=>r.abort(),e.timeout);try{const n=await fetch(t,{method:e.method,headers:e.headers,signal:r.signal});return clearTimeout(i),n}catch(t){if(clearTimeout(i),t instanceof Error&&"AbortError"===t.name)throw new Error(`Request timeout after ${e.timeout}ms`);throw t}}static detectFormat(t,e){const r=t.toLowerCase();if(r.endsWith(".lottie"))return"lottie";if(r.endsWith(".json"))return"json";const i=e.headers.get("content-type")||"";return i.includes("application/json")?"json":i.includes("application/octet-stream")||i.includes("application/zip")?"lottie":"json"}static isUrl(t){try{return new URL(t),!0}catch(e){return t.startsWith("/")||t.startsWith("./")||t.startsWith("../")}}static isNonRetryableError(t){const e=t.message.toLowerCase();return e.includes("404")||e.includes("403")||e.includes("401")||e.includes("syntax error")||e.includes("invalid json")}static getCacheKey(t,e){const r={method:e.method||"GET",headers:e.headers||{}};return`${t}:${JSON.stringify(r)}`}static delay(t){return new Promise(e=>setTimeout(e,t))}static validateAnimationData(t,e){try{if("json"===e){const e=JSON.parse(t);return this.isValidLottieJson(e)}return this.isValidLottieFile(t)}catch(t){return!1}}static isValidLottieJson(t){return"object"==typeof t&&null!==t&&"string"==typeof t.v&&"number"==typeof t.w&&"number"==typeof t.h&&Array.isArray(t.layers)}static isValidLottieFile(t){if(t.byteLength<4)return!1;const e=new Uint8Array(t.slice(0,4)),r=new Uint8Array([80,75,3,4]);return e.every((t,e)=>t===r[e])}static formatFileSize(t){const e=["B","KB","MB","GB"];let r=t,i=0;for(;r>=1024&&i<e.length-1;)r/=1024,i++;return`${r.toFixed(1)} ${e[i]}`}static estimateComplexity(t){if("string"==typeof t)try{t=JSON.parse(t)}catch(t){return"low"}if(!t||!Array.isArray(t.layers))return"low";const e=t.layers.length,r=t.layers.reduce((t,e)=>t+(e.shapes?e.shapes.length:0),0);return e<5&&r<10?"low":e<20&&r<50?"medium":"high"}static optimizeForPerformance(t){if("string"==typeof t)try{t=JSON.parse(t)}catch(e){return t}const e=JSON.parse(JSON.stringify(t));if(e.assets){const t=new Set,r=e=>{e.forEach(e=>{e.refId&&t.add(e.refId),e.layers&&r(e.layers)})};r(e.layers),e.assets=e.assets.filter(e=>t.has(e.id))}return this.roundNumbers(e,2),e}static roundNumbers(t,e=2){if("number"==typeof t)return Math.round(t*Math.pow(10,e))/Math.pow(10,e);Array.isArray(t)?t.forEach((r,i)=>{"number"==typeof r?t[i]=Math.round(r*Math.pow(10,e))/Math.pow(10,e):"object"==typeof r&&null!==r&&this.roundNumbers(r,e)}):"object"==typeof t&&null!==t&&Object.keys(t).forEach(r=>{"number"==typeof t[r]?t[r]=Math.round(t[r]*Math.pow(10,e))/Math.pow(10,e):"object"==typeof t[r]&&this.roundNumbers(t[r],e)})}}c.cache=new Map,c.DEFAULT_TIMEOUT=1e4,c.DEFAULT_RETRY=3;class h{static async parse(t){try{let e;return e="lottie"===t.format||this.isLottieFormat(t.data)?await this.parseLottieFile(t.data):this.parseJSON(t.data),{data:e,duration:this.calculateDuration(e),frameRate:e.fr||30,totalFrames:e.op-e.ip||0,width:e.w||512,height:e.h||512}}catch(t){const e=t instanceof Error?t.message:"Unknown error";throw new Error(`Failed to parse Lottie animation: ${e}`)}}static isLottieFormat(t){if(!(t&&t instanceof ArrayBuffer))return!1;const e=new Uint8Array(t.slice(0,4));return this.arrayEquals(e,this.LOTTIE_MAGIC)}static async parseLottieFile(t){if(t.byteLength>this.MAX_FILE_SIZE)throw new Error("File too large");const e=new DataView(t),r=this.findCentralDirectory(e);if(-1===r)throw new Error("Invalid .lottie file format");const i=this.extractAnimationJson(e,r);return JSON.parse(i)}static parseJSON(t){try{const e=JSON.parse(t);return this.validateLottieData(e),e}catch(t){const e=t instanceof Error?t.message:"Unknown error";throw new Error(`Invalid JSON format: ${e}`)}}static findCentralDirectory(t){for(let e=t.byteLength-22;e>=0;e--)if(101010256===t.getUint32(e,!0)){return t.getUint32(e+16,!0)}return-1}static extractAnimationJson(t,e){if(33639248!==t.getUint32(e,!0))throw new Error("Invalid central directory");const r=t.getUint16(e+28,!0);if(!this.readString(t,e+46,r).includes("animation.json"))throw new Error("animation.json not found in .lottie file");const i=t.getUint32(e+42,!0),n=t.getUint32(e+20,!0),s=i+30+t.getUint16(i+26,!0)+t.getUint16(i+28,!0);return this.readString(t,s,n)}static readString(t,e,r){const i=new Uint8Array(t.buffer,e,r);return(new TextDecoder).decode(i)}static validateLottieData(t){if(!t||"object"!=typeof t)throw new Error("Invalid Lottie data structure");const e=["v","w","h","layers"];for(const r of e)if(!(r in t))throw new Error(`Missing required field: ${r}`);if(!Array.isArray(t.layers))throw new Error("Layers must be an array");if("number"!=typeof t.w||"number"!=typeof t.h)throw new Error("Width and height must be numbers")}static calculateDuration(t){const e=t.fr||30;return((t.op||0)-(t.ip||0))/e*1e3}static arrayEquals(t,e){if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(t[r]!==e[r])return!1;return!0}static optimize(t){const e=JSON.parse(JSON.stringify(t));return this.removeUnusedAssets(e),this.simplifyPaths(e),this.roundNumbers(e),e}static removeUnusedAssets(t){if(!t.assets||!Array.isArray(t.assets))return;const e=new Set,r=t=>{t.forEach(t=>{t.refId&&e.add(t.refId),t.layers&&r(t.layers)})};r(t.layers),t.assets=t.assets.filter(t=>e.has(t.id))}static simplifyPaths(t){const e=t=>{t.shapes&&t.shapes.forEach(t=>{t.it&&this.simplifyShapeItems(t.it)}),t.layers&&t.layers.forEach(e)};t.layers.forEach(e)}static simplifyShapeItems(t){t.forEach(t=>{if("sh"===t.ty&&t.ks&&t.ks.k&&t.ks.k.v){const e=t.ks.k.v;e.length>100&&(t.ks.k.v=this.reducePathComplexity(e))}})}static reducePathComplexity(t){if(t.length<=3)return t;const e=[t[0]];for(let r=1;r<t.length-1;r++){const i=t[r-1],n=t[r],s=t[r+1];this.pointToLineDistance(n,i,s)>.5&&e.push(n)}return e.push(t[t.length-1]),e}static pointToLineDistance(t,e,r){const[i,n]=t,[s,o]=e,[a,c]=r,h=i-s,u=n-o,l=a-s,f=c-o,p=h*l+u*f,d=l*l+f*f;if(0===d)return Math.sqrt(h*h+u*u);const y=p/d,m=i-(y<0?s:y>1?a:s+y*l),v=n-(y<0?o:y>1?c:o+y*f);return Math.sqrt(m*m+v*v)}static roundNumbers(t,e=3){if("number"==typeof t)return Math.round(t*Math.pow(10,e))/Math.pow(10,e);Array.isArray(t)?t.forEach((r,i)=>{"number"==typeof r?t[i]=Math.round(r*Math.pow(10,e))/Math.pow(10,e):"object"==typeof r&&this.roundNumbers(r,e)}):"object"==typeof t&&null!==t&&Object.keys(t).forEach(r=>{"number"==typeof t[r]?t[r]=Math.round(t[r]*Math.pow(10,e))/Math.pow(10,e):"object"==typeof t[r]&&this.roundNumbers(t[r],e)})}}h.LOTTIE_MAGIC=new Uint8Array([80,75,3,4]),h.MAX_FILE_SIZE=52428800;class u{constructor(t,e){if(this.currentFrame=0,this.scaleFactor=1,this.isDestroyed=!1,this.animationData=e,this.canvas=document.createElement("canvas"),this.ctx=this.canvas.getContext("2d"),!this.ctx)throw new Error("Canvas 2D context not supported");this.setupCanvas(t),this.transformMatrix=new DOMMatrix}setupCanvas(t){const{w:e,h:r}=this.animationData;this.canvas.width=e,this.canvas.height=r,this.canvas.style.width="100%",this.canvas.style.height="100%",this.canvas.style.display="block";const i=window.devicePixelRatio||1;this.scaleFactor=i,this.canvas.width=e*i,this.canvas.height=r*i,this.ctx.scale(i,i),this.ctx.imageSmoothingEnabled=!0,this.ctx.imageSmoothingQuality="high",t.appendChild(this.canvas)}render(t){if(!this.isDestroyed){this.currentFrame=t,this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.save();try{this.renderLayers(this.animationData.layers,t)}catch(t){}finally{this.ctx.restore()}}}renderLayers(t,e){const r=[...t].sort((t,e)=>t.ind-e.ind);for(const t of r)this.isLayerVisible(t,e)&&this.renderLayer(t,e)}isLayerVisible(t,e){return e>=t.ip&&e<t.op}renderLayer(t,e){this.ctx.save();try{this.applyTransform(t.ks,e);const r=this.getAnimatedValue(t.ks.o,e);switch(void 0!==r&&(this.ctx.globalAlpha*=r/100),t.ty){case 4:this.renderShapeLayer(t,e);break;case 0:this.renderPrecompLayer(t,e);break;case 1:this.renderSolidLayer(t,e);break;case 2:this.renderImageLayer(t,e);break;case 5:this.renderTextLayer(t,e)}}finally{this.ctx.restore()}}applyTransform(t,e){const r=this.getAnimatedValue(t.a,e)||[0,0],i=this.getAnimatedValue(t.p,e)||[0,0],n=this.getAnimatedValue(t.s,e)||[100,100],s=this.getAnimatedValue(t.r,e)||0;this.ctx.translate(i[0],i[1]),this.ctx.rotate(s*Math.PI/180),this.ctx.scale(n[0]/100,n[1]/100),this.ctx.translate(-r[0],-r[1])}renderShapeLayer(t,e){if(t.shapes)for(const r of t.shapes)this.renderShape(r,e)}renderShape(t,e){if(!t.hd){this.ctx.save();try{switch(t.ty){case"gr":this.renderShapeGroup(t,e);break;case"rc":this.renderRectangle(t,e);break;case"el":this.renderEllipse(t,e);break;case"sh":this.renderPath(t,e);break;case"fl":this.applyFill(t,e);break;case"st":this.applyStroke(t,e);break;case"tr":this.applyShapeTransform(t,e)}}finally{this.ctx.restore()}}}renderShapeGroup(t,e){if(t.it)for(const r of t.it)this.renderShape(r,e)}renderRectangle(t,e){const r=this.getAnimatedValue(t.s,e)||[100,100],i=this.getAnimatedValue(t.p,e)||[0,0],n=this.getAnimatedValue(t.r,e)||0,[s,o]=r,[a,c]=i;this.ctx.beginPath(),n>0?this.ctx.roundRect(a-s/2,c-o/2,s,o,n):this.ctx.rect(a-s/2,c-o/2,s,o)}renderEllipse(t,e){const r=this.getAnimatedValue(t.s,e)||[100,100],i=this.getAnimatedValue(t.p,e)||[0,0],[n,s]=r,[o,a]=i;this.ctx.beginPath(),this.ctx.ellipse(o,a,n/2,s/2,0,0,2*Math.PI)}renderPath(t,e){const r=this.getAnimatedValue(t.pt,e);if(!r||!r.v)return;const i=r.v,n=r.i||[],s=r.o||[],o=r.c||!1;if(this.ctx.beginPath(),i.length>0){this.ctx.moveTo(i[0][0],i[0][1]);for(let t=1;t<i.length;t++){const e=i[t-1],r=i[t],o=s[t-1]||[0,0],a=n[t]||[0,0];this.ctx.bezierCurveTo(e[0]+o[0],e[1]+o[1],r[0]+a[0],r[1]+a[1],r[0],r[1])}if(o&&i.length>2){const t=i[i.length-1],e=i[0],r=s[i.length-1]||[0,0],o=n[0]||[0,0];this.ctx.bezierCurveTo(t[0]+r[0],t[1]+r[1],e[0]+o[0],e[1]+o[1],e[0],e[1]),this.ctx.closePath()}}}applyFill(t,e){const r=this.getAnimatedValue(t.c,e),i=this.getAnimatedValue(t.o,e);if(r){const[t,e,n]=r.map(t=>Math.round(255*t)),s=i?i/100:1;this.ctx.fillStyle=`rgba(${t}, ${e}, ${n}, ${s})`,this.ctx.fill()}}applyStroke(t,e){const r=this.getAnimatedValue(t.c,e),i=this.getAnimatedValue(t.o,e),n=this.getAnimatedValue(t.w,e);if(r&&n){const[e,s,o]=r.map(t=>Math.round(255*t)),a=i?i/100:1;this.ctx.strokeStyle=`rgba(${e}, ${s}, ${o}, ${a})`,this.ctx.lineWidth=n,this.ctx.lineCap=this.getLineCap(t.lc),this.ctx.lineJoin=this.getLineJoin(t.lj),t.ml&&(this.ctx.miterLimit=t.ml),this.ctx.stroke()}}applyShapeTransform(t,e){const r=this.getAnimatedValue(t.p,e)||[0,0],i=this.getAnimatedValue(t.s,e)||[100,100],n=this.getAnimatedValue(t.r,e)||0;this.ctx.translate(r[0],r[1]),this.ctx.rotate(n*Math.PI/180),this.ctx.scale(i[0]/100,i[1]/100)}renderPrecompLayer(t,e){var r;const i=null===(r=this.animationData.assets)||void 0===r?void 0:r.find(e=>e.id===t.refId);i&&i.layers&&this.renderLayers(i.layers,e)}renderSolidLayer(t,e){this.ctx.fillStyle="#000000",this.ctx.fillRect(0,0,t.w||100,t.h||100)}renderImageLayer(t,e){}renderTextLayer(t,e){}getAnimatedValue(t,e){if(!t)return;if(!t.a)return t.k;const r=t.k;if(!Array.isArray(r))return r;let i=r[0],n=r[r.length-1];for(let t=0;t<r.length-1;t++)if(e>=r[t].t&&e<r[t+1].t){i=r[t],n=r[t+1];break}const s=(e-i.t)/(n.t-i.t);return this.interpolateValue(i.s,n.s,Math.max(0,Math.min(1,s)))}interpolateValue(t,e,r){return"number"==typeof t&&"number"==typeof e?t+(e-t)*r:Array.isArray(t)&&Array.isArray(e)?t.map((t,i)=>{const n=e[i]||t;return"number"==typeof t?t+(n-t)*r:t}):r<.5?t:e}getLineCap(t){switch(t){case 1:default:return"butt";case 2:return"round";case 3:return"square"}}getLineJoin(t){switch(t){case 1:default:return"miter";case 2:return"round";case 3:return"bevel"}}resize(){if(this.isDestroyed)return;const t=this.canvas.parentElement;if(!t)return;const e=t.getBoundingClientRect(),r=window.devicePixelRatio||1;this.canvas.width=e.width*r,this.canvas.height=e.height*r,this.ctx.scale(r,r),this.render(this.currentFrame)}destroy(){this.isDestroyed=!0,this.canvas.parentElement&&this.canvas.parentElement.removeChild(this.canvas)}getCanvas(){return this.canvas}}class l{constructor(t,e){this.currentFrame=0,this.layerElements=new Map,this.isDestroyed=!1,this.container=t,this.animationData=e,this.setupSVG(),this.createLayerElements()}setupSVG(){const{w:t,h:e}=this.animationData;this.svg=document.createElementNS("http://www.w3.org/2000/svg","svg"),this.svg.setAttribute("viewBox",`0 0 ${t} ${e}`),this.svg.setAttribute("width","100%"),this.svg.setAttribute("height","100%"),this.svg.style.display="block",this.container.appendChild(this.svg)}createLayerElements(){const t=[...this.animationData.layers].sort((t,e)=>t.ind-e.ind);for(const e of t){const t=this.createLayerGroup(e);this.layerElements.set(e.ind,t),this.svg.appendChild(t)}}createLayerGroup(t){const e=document.createElementNS("http://www.w3.org/2000/svg","g");return e.setAttribute("data-layer-index",t.ind.toString()),e.setAttribute("data-layer-name",t.nm||""),e}render(t){if(!this.isDestroyed){this.currentFrame=t;for(const e of this.animationData.layers)this.updateLayer(e,t)}}updateLayer(t,e){const r=this.layerElements.get(t.ind);if(!r)return;const i=e>=t.ip&&e<t.op;if(r.style.display=i?"block":"none",!i)return;const n=this.getTransformString(t.ks,e);r.setAttribute("transform",n);const s=this.getAnimatedValue(t.ks.o,e);switch(void 0!==s&&r.setAttribute("opacity",(s/100).toString()),t.ty){case 4:this.updateShapeLayer(t,r,e);break;case 0:this.updatePrecompLayer(t,r,e);break;case 1:this.updateSolidLayer(t,r,e);break;case 2:this.updateImageLayer(t,r,e);break;case 5:this.updateTextLayer(t,r,e)}}getTransformString(t,e){const r=[],i=this.getAnimatedValue(t.a,e)||[0,0],n=this.getAnimatedValue(t.p,e)||[0,0],s=this.getAnimatedValue(t.s,e)||[100,100],o=this.getAnimatedValue(t.r,e)||0;return 0===n[0]&&0===n[1]||r.push(`translate(${n[0]}, ${n[1]})`),0!==o&&r.push(`rotate(${o})`),100===s[0]&&100===s[1]||r.push(`scale(${s[0]/100}, ${s[1]/100})`),0===i[0]&&0===i[1]||r.push(`translate(${-i[0]}, ${-i[1]})`),r.join(" ")}updateShapeLayer(t,e,r){if(t.shapes){e.innerHTML="";for(const i of t.shapes){const t=this.createShapeElement(i,r);t&&e.appendChild(t)}}}createShapeElement(t,e){if(t.hd)return null;switch(t.ty){case"gr":return this.createShapeGroup(t,e);case"rc":return this.createRectangle(t,e);case"el":return this.createEllipse(t,e);case"sh":return this.createPath(t,e);default:return null}}createShapeGroup(t,e){if(!t.it)return null;const r=document.createElementNS("http://www.w3.org/2000/svg","g"),i=[];let n=null,s=null,o=null,a=null;for(const r of t.it)switch(r.ty){case"sh":case"rc":case"el":{const t=this.createShapeElement(r,e);t&&i.push(t);break}case"fl":n=this.getFillStyle(r,e);break;case"st":{const t=this.getStrokeStyle(r,e);s=t.style,o=t.width;break}case"tr":a=this.getShapeTransformString(r,e)}for(const t of i)n?t.setAttribute("fill",n):t.setAttribute("fill","none"),s&&o&&(t.setAttribute("stroke",s),t.setAttribute("stroke-width",o.toString()));a&&r.setAttribute("transform",a);for(const t of i)r.appendChild(t);return r}createRectangle(t,e){const r=document.createElementNS("http://www.w3.org/2000/svg","rect"),i=this.getAnimatedValue(t.s,e)||[100,100],n=this.getAnimatedValue(t.p,e)||[0,0],s=this.getAnimatedValue(t.r,e)||0,[o,a]=i,[c,h]=n;return r.setAttribute("x",(c-o/2).toString()),r.setAttribute("y",(h-a/2).toString()),r.setAttribute("width",o.toString()),r.setAttribute("height",a.toString()),s>0&&(r.setAttribute("rx",s.toString()),r.setAttribute("ry",s.toString())),r}createEllipse(t,e){const r=document.createElementNS("http://www.w3.org/2000/svg","ellipse"),i=this.getAnimatedValue(t.s,e)||[100,100],n=this.getAnimatedValue(t.p,e)||[0,0],[s,o]=i,[a,c]=n;return r.setAttribute("cx",a.toString()),r.setAttribute("cy",c.toString()),r.setAttribute("rx",(s/2).toString()),r.setAttribute("ry",(o/2).toString()),r}createPath(t,e){const r=document.createElementNS("http://www.w3.org/2000/svg","path"),i=this.getAnimatedValue(t.pt,e);if(i&&i.v){const t=this.buildPathString(i);r.setAttribute("d",t)}return r}buildPathString(t){const e=t.v||[],r=t.i||[],i=t.o||[],n=t.c||!1;if(0===e.length)return"";const s=[];s.push(`M ${e[0][0]} ${e[0][1]}`);for(let t=1;t<e.length;t++){const n=e[t-1],o=e[t],a=i[t-1]||[0,0],c=r[t]||[0,0],h=n[0]+a[0],u=n[1]+a[1],l=o[0]+c[0],f=o[1]+c[1];s.push(`C ${h} ${u} ${l} ${f} ${o[0]} ${o[1]}`)}if(n&&e.length>2){const t=e[e.length-1],n=e[0],o=i[e.length-1]||[0,0],a=r[0]||[0,0],c=t[0]+o[0],h=t[1]+o[1],u=n[0]+a[0],l=n[1]+a[1];s.push(`C ${c} ${h} ${u} ${l} ${n[0]} ${n[1]}`),s.push("Z")}return s.join(" ")}getFillStyle(t,e){const r=this.getAnimatedValue(t.c,e),i=this.getAnimatedValue(t.o,e);if(!r)return null;const[n,s,o]=r.map(t=>Math.round(255*t));return`rgba(${n}, ${s}, ${o}, ${i?i/100:1})`}getStrokeStyle(t,e){const r=this.getAnimatedValue(t.c,e),i=this.getAnimatedValue(t.o,e),n=this.getAnimatedValue(t.w,e);if(!r||!n)return{style:null,width:null};const[s,o,a]=r.map(t=>Math.round(255*t));return{style:`rgba(${s}, ${o}, ${a}, ${i?i/100:1})`,width:n}}getShapeTransformString(t,e){const r=[],i=this.getAnimatedValue(t.p,e)||[0,0],n=this.getAnimatedValue(t.s,e)||[100,100],s=this.getAnimatedValue(t.r,e)||0;return 0===i[0]&&0===i[1]||r.push(`translate(${i[0]}, ${i[1]})`),0!==s&&r.push(`rotate(${s})`),100===n[0]&&100===n[1]||r.push(`scale(${n[0]/100}, ${n[1]/100})`),r.join(" ")}updatePrecompLayer(t,e,r){var i;const n=null===(i=this.animationData.assets)||void 0===i?void 0:i.find(e=>e.id===t.refId);n&&n.layers}updateSolidLayer(t,e,r){e.innerHTML="";const i=document.createElementNS("http://www.w3.org/2000/svg","rect");i.setAttribute("x","0"),i.setAttribute("y","0"),i.setAttribute("width",(t.w||100).toString()),i.setAttribute("height",(t.h||100).toString()),i.setAttribute("fill","#000000"),e.appendChild(i)}updateImageLayer(t,e,r){}updateTextLayer(t,e,r){}getAnimatedValue(t,e){if(!t)return;if(!t.a)return t.k;const r=t.k;if(!Array.isArray(r))return r;let i=r[0],n=r[r.length-1];for(let t=0;t<r.length-1;t++)if(e>=r[t].t&&e<r[t+1].t){i=r[t],n=r[t+1];break}const s=(e-i.t)/(n.t-i.t);return this.interpolateValue(i.s,n.s,Math.max(0,Math.min(1,s)))}interpolateValue(t,e,r){return"number"==typeof t&&"number"==typeof e?t+(e-t)*r:Array.isArray(t)&&Array.isArray(e)?t.map((t,i)=>{const n=e[i]||t;return"number"==typeof t?t+(n-t)*r:t}):r<.5?t:e}resize(){}destroy(){this.isDestroyed=!0,this.layerElements.clear(),this.svg.parentElement&&this.svg.parentElement.removeChild(this.svg)}getSVG(){return this.svg}}class f{constructor(t){this.currentFrame=0,this.P=!1,this.L=!1,this.C=!0,this.direction=1,this.speed=1,this.loop=!0,this.autoplay=!0,this.useSubFrames=!1,this.segments=null,this.animationId=null,this.lastFrameTime=0,this.eventListeners=new Map,this.animationData=t.animationData,this.loop=t.loop,this.autoplay=t.autoplay,this.frameRate=this.animationData.fr||30,this.inPoint=this.animationData.ip||0,this.outPoint=this.animationData.op||60,this.totalFrames=this.outPoint-this.inPoint,this.frameInterval=1e3/this.frameRate,"svg"===t.renderer?this.renderer=new l(t.container,this.animationData):this.renderer=new u(t.container,this.animationData),this.currentFrame=this.inPoint,this.autoplay?this.play():this.renderFrame()}play(){this.P||(this.P=!0,this.L=!1,this.C=!1,this.lastFrameTime=performance.now(),this.startAnimation(),this.dispatchEvent("complete"))}pause(){this.P&&(this.P=!1,this.L=!0,this.animationId&&(cancelAnimationFrame(this.animationId),this.animationId=null),this.dispatchEvent("complete"))}stop(){this.P=!1,this.L=!1,this.C=!0,this.animationId&&(cancelAnimationFrame(this.animationId),this.animationId=null),this.currentFrame=this.inPoint,this.renderFrame(),this.dispatchEvent("complete")}seek(t){const e=Math.max(0,Math.min(1,t)),r=this.segments?this.segments[0]:this.inPoint,i=(this.segments?this.segments[1]:this.outPoint)-r;this.currentFrame=r+i*e,this.renderFrame(),this.dispatchEvent("enterFrame")}goToAndPlay(t){this.currentFrame=Math.max(this.inPoint,Math.min(this.outPoint,t)),this.renderFrame(),this.play()}goToAndStop(t){this.currentFrame=Math.max(this.inPoint,Math.min(this.outPoint,t)),this.renderFrame(),this.pause()}playSegments(t,e=!1){this.segments=[Math.max(this.inPoint,t[0]),Math.min(this.outPoint,t[1])],!e&&this.P||(this.currentFrame=this.segments[0],this.play())}setSpeed(t){this.speed=Math.max(.1,Math.min(5,t))}setDirection(t){this.direction=t}setSubframe(t){this.useSubFrames=t}resize(){this.renderer.resize()}destroy(){this.stop(),this.renderer.destroy(),this.eventListeners.clear(),this.dispatchEvent("destroy")}addEventListener(t,e){this.eventListeners.has(t)||this.eventListeners.set(t,[]),this.eventListeners.get(t).push(e)}removeEventListener(t,e){const r=this.eventListeners.get(t);if(r){const t=r.indexOf(e);t>-1&&r.splice(t,1)}}getCurrentFrame(){return this.currentFrame}getTotalFrames(){return this.totalFrames}getFrameRate(){return this.frameRate}getDuration(){return this.totalFrames/this.frameRate*1e3}getProgress(){const t=this.segments?this.segments[0]:this.inPoint,e=(this.segments?this.segments[1]:this.outPoint)-t;return 0===e?0:(this.currentFrame-t)/e}isPlaying(){return this.P}isPaused(){return this.L}isStopped(){return this.C}startAnimation(){const t=e=>{if(!this.P)return;const r=e-this.lastFrameTime,i=this.frameInterval/this.speed;r>=i&&(this.updateFrame(),this.renderFrame(),this.lastFrameTime=e-r%i),this.animationId=requestAnimationFrame(t)};this.animationId=requestAnimationFrame(t)}updateFrame(){const t=this.segments?this.segments[0]:this.inPoint,e=this.segments?this.segments[1]:this.outPoint;this.useSubFrames?this.currentFrame+=this.direction*this.speed:this.currentFrame+=this.direction,this.direction>0&&this.currentFrame>=e?this.loop?(this.currentFrame=t,this.dispatchEvent("loopComplete")):(this.currentFrame=e-1,this.pause(),this.dispatchEvent("complete")):this.direction<0&&this.currentFrame<=t&&(this.loop?(this.currentFrame=e-1,this.dispatchEvent("loopComplete")):(this.currentFrame=t,this.pause(),this.dispatchEvent("complete"))),this.dispatchEvent("enterFrame")}renderFrame(){try{this.renderer.render(this.currentFrame)}catch(t){this.dispatchEvent("error",{error:t})}}dispatchEvent(t,e){const r=this.eventListeners.get(t);if(!r)return;const i={type:t,currentTime:this.currentFrame,totalTime:this.totalFrames,direction:this.direction,...e};r.forEach(t=>{try{t(i)}catch(t){}})}getAnimationData(){return this.animationData}isLoaded(){return!!this.animationData}getRendererType(){return this.renderer instanceof u?"canvas":"svg"}setLoop(t){this.loop=t}getLoop(){return this.loop}getSpeed(){return this.speed}getDirection(){return this.direction}getSegments(){return this.segments}clearSegments(){this.segments=null}getInPoint(){return this.inPoint}getOutPoint(){return this.outPoint}}class p{constructor(){this.performanceClass=null}static getInstance(){return p.instance||(p.instance=new p),p.instance}async detectPerformance(){if(this.performanceClass)return this.performanceClass;const t=(await this.testRenderPerformance()+this.getDeviceScore())/2;return this.performanceClass=t>=.8?"high":t>=.5?"medium":"low",this.performanceClass}async testRenderPerformance(){return new Promise(t=>{const e=document.createElement("canvas");e.width=300,e.height=300;const r=e.getContext("2d"),i=performance.now();let n=0;const s=()=>{if(r.clearRect(0,0,300,300),r.fillStyle=`hsl(${10*n}, 50%, 50%)`,r.fillRect(n%300,50,50,50),n++,performance.now()-i<100)requestAnimationFrame(s);else{const e=n/.1,r=Math.min(e/60,1);t(r)}};requestAnimationFrame(s)})}getDeviceScore(){let t=.5;if("hardwareConcurrency"in navigator){const e=navigator.hardwareConcurrency;t+=Math.min(e/8,.3)}if("memory"in performance){const e=performance.memory.jsHeapSizeLimit/1024/1024;t+=Math.min(e/1024,.2)}const e=window.devicePixelRatio||1;return e<=1?t+=.1:e>=3&&(t-=.1),Math.max(0,Math.min(1,t))}isMobile(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}supportsHardwareAcceleration(){const t=document.createElement("canvas");return!!(t.getContext("webgl")||t.getContext("experimental-webgl"))}getRecommendedSettings(){const t=this.performanceClass||"medium",e=this.isMobile();switch(t){case"high":return{renderer:"canvas",quality:"high",maxFps:60,enableSubFrames:!0};case"medium":return{renderer:"canvas",quality:"medium",maxFps:e?30:45,enableSubFrames:!1};default:return{renderer:"svg",quality:"low",maxFps:24,enableSubFrames:!1}}}}class d{static debounce(t,e){let r;return(...i)=>{clearTimeout(r),r=setTimeout(()=>t(...i),e)}}static throttle(t,e){let r;return(...i)=>{r||(t(...i),r=!0,setTimeout(()=>r=!1,e))}}static requestIdleCallback(t,e=5e3){return"requestIdleCallback"in window?window.requestIdleCallback(t,{timeout:e}):setTimeout(t,16)}static cancelIdleCallback(t){"cancelIdleCallback"in window?window.cancelIdleCallback(t):clearTimeout(t)}static prefersReducedMotion(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}static isInPowerSaveMode(){const t=performance.now();let e=0;return new Promise(r=>{const i=()=>{if(e++,performance.now()-t<100)requestAnimationFrame(i);else{r(e/.1<30)}};requestAnimationFrame(i)})}}const y=e.forwardRef(({src:t,autoplay:r=!0,loop:i=!0,renderer:n="canvas",speed:s=1,direction:o=1,segments:u,style:l,className:y,onComplete:m,onProgress:v,onError:w,onLoad:b,preserveAspectRatio:g="xMidYMid meet",rendererSettings:S={}},k)=>{const M=e.useRef(null),j=e.useRef(null),[$,E]=e.useState(!1),[F,T]=e.useState(null),[O,A]=e.useState(!1);e.useImperativeHandle(k,()=>({play:()=>{var t;return null===(t=j.current)||void 0===t?void 0:t.play()},pause:()=>{var t;return null===(t=j.current)||void 0===t?void 0:t.pause()},stop:()=>{var t;return null===(t=j.current)||void 0===t?void 0:t.stop()},seek:t=>{var e;return null===(e=j.current)||void 0===e?void 0:e.seek(t)},getCurrentFrame:()=>{var t;return(null===(t=j.current)||void 0===t?void 0:t.getCurrentFrame())||0},getTotalFrames:()=>{var t;return(null===(t=j.current)||void 0===t?void 0:t.getTotalFrames())||0},getProgress:()=>{var t;return(null===(t=j.current)||void 0===t?void 0:t.getProgress())||0},isPlaying:()=>{var t;return(null===(t=j.current)||void 0===t?void 0:t.isPlaying())||!1},isPaused:()=>{var t;return(null===(t=j.current)||void 0===t?void 0:t.isPaused())||!1},isStopped:()=>{var t;return(null===(t=j.current)||void 0===t?void 0:t.isStopped())||!0}}),[]),e.useEffect(()=>{if(!M.current)return;const t=new IntersectionObserver(([e])=>{e.isIntersecting&&(A(!0),t.disconnect())},{rootMargin:"50px",threshold:.1});return t.observe(M.current),()=>t.disconnect()},[]),e.useEffect(()=>{if(!O||!M.current)return;let e=!1;return(async()=>{try{T(null);const a=await c.loadFromSource(t);if(e)return;const l=await h.parse({data:a.data,format:a.format});if(e)return;const d=p.getInstance(),y=await d.detectPerformance(),w=d.getRecommendedSettings(),g="low"===y?w.renderer:n,k=new f({container:M.current,renderer:g,loop:i,autoplay:r,animationData:l.data,rendererSettings:S});if(e)return void k.destroy();k.setSpeed(s),k.setDirection(o),u&&k.playSegments(u),m&&k.addEventListener("complete",m),v&&k.addEventListener("enterFrame",()=>{v(k.getProgress())}),j.current=k,E(!0),b&&b()}catch(t){if(!e){const e=t instanceof Error?t:new Error("Failed to load animation");T(e),w&&w(e)}}})(),()=>{e=!0,j.current&&(j.current.destroy(),j.current=null)}},[O,t,r,i,n,S,b,w]),e.useEffect(()=>{j.current&&j.current.setSpeed(s)},[s]),e.useEffect(()=>{j.current&&j.current.setDirection(o)},[o]),e.useEffect(()=>{j.current&&(u?j.current.playSegments(u):j.current.clearSegments())},[u]),e.useEffect(()=>{const t=d.debounce(()=>{j.current&&j.current.resize()},100);return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[]),e.useEffect(()=>{const t=()=>{j.current&&(document.hidden?j.current.isPlaying()&&j.current.pause():r&&j.current.isPaused()&&j.current.play())};return document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)},[r]),e.useEffect(()=>{d.prefersReducedMotion()&&j.current&&j.current.pause()},[]);const P={display:"block",width:"100%",height:"100%",overflow:"hidden",...l};return F?a.jsx("div",{ref:M,className:y,style:P,role:"img","aria-label":"Animation failed to load",children:a.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",height:"100%",color:"#999",fontSize:"14px",textAlign:"center"},children:"Failed to load animation"})}):!$&&O?a.jsx("div",{ref:M,className:y,style:P,role:"img","aria-label":"Animation loading",children:a.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",height:"100%",color:"#999",fontSize:"14px"},children:"Loading animation..."})}):a.jsx("div",{ref:M,className:y,style:P,role:"img","aria-label":"Lottie animation"})});y.displayName="LottiePlayer",t.LottiePlayer=y,t.default=y,t.useLottie=function(t){const{container:r,src:i,renderer:n="canvas",autoplay:s=!0,loop:o=!0,speed:a=1,direction:u=1,segments:l,onComplete:y,onProgress:m,onError:v,onLoad:w,rendererSettings:b={}}=t,g=e.useRef(null),[S,k]=e.useState(!1),[M,j]=e.useState(!1),[$,E]=e.useState(!1),[F,T]=e.useState(!0),[O,A]=e.useState(0),[P,L]=e.useState(0),[x,C]=e.useState(0),[R,I]=e.useState(0),[_,D]=e.useState(30),[N,z]=e.useState(null),[J,q]=e.useState(null);e.useEffect(()=>{if(!r.current||!i)return;let t=!1;return(async()=>{try{q(null);const e=await c.loadFromSource(i);if(t)return;const d=await h.parse({data:e.data,format:e.format});if(t)return;const v=p.getInstance(),S=await v.detectPerformance(),M=v.getRecommendedSettings(),$="low"===S?M.renderer:n,F=new f({container:r.current,renderer:$,loop:o,autoplay:s,animationData:d.data,rendererSettings:b});if(t)return void F.destroy();F.setSpeed(a),F.setDirection(u),l&&F.playSegments(l),F.addEventListener("complete",()=>{j(!1),E(!1),T(!0),y&&y()}),F.addEventListener("enterFrame",()=>{const t=F.getCurrentFrame(),e=F.getProgress();L(t),A(e),m&&m(e)}),g.current=F,z(d.data),C(F.getTotalFrames()),I(F.getDuration()),D(F.getFrameRate()),k(!0),j(F.isPlaying()),E(F.isPaused()),T(F.isStopped()),w&&w()}catch(e){if(!t){const t=e instanceof Error?e:new Error("Failed to load animation");q(t),v&&v(t)}}})(),()=>{t=!0,g.current&&(g.current.destroy(),g.current=null)}},[r,i,n,s,o,b,w,v]),e.useEffect(()=>{g.current&&g.current.setSpeed(a)},[a]),e.useEffect(()=>{g.current&&g.current.setDirection(u)},[u]),e.useEffect(()=>{g.current&&(l?g.current.playSegments(l):g.current.clearSegments())},[l]);const U=e.useCallback(()=>{g.current&&(g.current.play(),j(!0),E(!1),T(!1))},[]),V=e.useCallback(()=>{g.current&&(g.current.pause(),j(!1),E(!0),T(!1))},[]),B=e.useCallback(()=>{g.current&&(g.current.stop(),j(!1),E(!1),T(!0),A(0),L(0))},[]),G=e.useCallback(t=>{if(g.current){const e=Math.max(0,Math.min(1,t));g.current.seek(e),A(e);const r=Math.round(e*x);L(r)}},[x]),W=e.useCallback(t=>{g.current&&g.current.setSpeed(t)},[]),K=e.useCallback(t=>{g.current&&g.current.setDirection(t)},[]),Y=e.useCallback(t=>{if(g.current){g.current.goToAndPlay(t),j(!0),E(!1),T(!1);A(x>0?t/x:0),L(t)}},[x]),H=e.useCallback(t=>{if(g.current){g.current.goToAndStop(t),j(!1),E(!0),T(!1);A(x>0?t/x:0),L(t)}},[x]),X=e.useCallback((t,e=!1)=>{g.current&&(g.current.playSegments(t,e),j(!0),E(!1),T(!1))},[]),Z=e.useCallback(t=>{g.current&&g.current.setSubframe(t)},[]);return e.useEffect(()=>{const t=d.debounce(()=>{g.current&&g.current.resize()},100);return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[]),{play:U,pause:V,stop:B,seek:G,setSpeed:W,setDirection:K,goToAndPlay:Y,goToAndStop:H,playSegments:X,setSubframe:Z,isPlaying:M,isPaused:$,isStopped:F,progress:O,currentFrame:P,totalFrames:x,duration:R,frameRate:_,animationData:N,isLoaded:S,error:J}},Object.defineProperty(t,"R",{value:!0})});